_aLoopIDs(); } function iCurrentLoopID() { global $webyep_oCurrentLoop; if ($webyep_oCurrentLoop != od_nil && $webyep_oCurrentLoop->iElementsLeft > 0) return $webyep_oCurrentLoop->iLoopID; else return 0; } function setCurrentLoopID($i) // used by WYDocument to 'simulate" loop ID for editors { global $webyep_oCurrentLoop; // as we store the loopID in an instance, we need an instance... if (!$webyep_oCurrentLoop) $webyep_oCurrentLoop = new WYLoopElement(""); $webyep_oCurrentLoop->iLoopID = $i; } // instance functions function WYLoopElement($sN) { global $goApp; parent::WYElement($sN, false); $this->sEditorPageName = ""; $this->setVersion(WY_LOOP_VERSION); if (!isset($this->dContent[WY_DK_LOOPIDARRAY])) $this->dContent[WY_DK_LOOPIDARRAY] = array(1); else if (!count($this->dContent[WY_DK_LOOPIDARRAY])) $this->dContent[WY_DK_LOOPIDARRAY] = array(1); if (!isset($this->dContent[WY_DK_DISABLEDLOOPIDARRAY])) $this->dContent[WY_DK_DISABLEDLOOPIDARRAY] = array(); $this->iLoopID = 0; $this->iEditedID = false; $this->iLoopIDJustDeleted = 0; if ($goApp->bEditMode) $this->dispatchEditAction(); $this->iElementsLeft = count($this->_aLoopIDs()); } function bUseLoopID() { return false; } function sFieldNameForFile() { $s = parent::sFieldNameForFile(); $s = "lo-" . $s; return $s; } function _aLoopIDs() { global $goApp; if ($goApp->bEditMode) return $this->dContent[WY_DK_LOOPIDARRAY]; else { $a = $this->dContent[WY_DK_LOOPIDARRAY]; $aDis = $this->_aDisabledLoopIDs(); return array_diff($a, $aDis); } } function _setLoopIDs($a) { $this->dContent[WY_DK_LOOPIDARRAY] = $a; } function _aDisabledLoopIDs() { return $this->dContent[WY_DK_DISABLEDLOOPIDARRAY]; } function _setDisabledLoopIDs($a) { $this->dContent[WY_DK_DISABLEDLOOPIDARRAY] = $a; } function loopStart($bShowControls = true) { global $goApp; if ($bShowControls) $this->showEditButtons(); $goApp->outputWarningPanels(); // give App a chance to say something } function iDeletedLoopInstance() { return $this->iLoopIDJustDeleted; } function bIDIsDisabled($iID) { $a = $this->_aDisabledLoopIDs(); return in_array($iID, $a); } function disableLoopID($iID) { $a = $this->_aDisabledLoopIDs(); if (!in_array($iID, $a)) $a[] = $iID; $this->_setDisabledLoopIDs($a); } function enableLoopID($iID) { $a = $this->_aDisabledLoopIDs(); if (in_array($iID, $a)) array_splice($a , array_search($iID, $a), 1); $this->_setDisabledLoopIDs($a); } function showAnchor() { echo ""; } function showEditButtons() { global $goApp; if ($goApp->bEditMode) { if ($this->iEditedID == $this->iLoopID) $this->showAnchor(); $oURL = od_clone(WYURL::oCurrentURL()); $oLink = od_nil; $oImg = od_nil; $oImgURL = od_clone($goApp->oImageURL); $dEditQuery = WYEditor::dQueryForElement($this); $aLoopIDs = $this->_aLoopIDs(); $iCount = count($aLoopIDs); $dEditQuery[WY_QK_LOOP_ID] = $this->iCurrentLoopID(); $goApp->setActionInQuery($dEditQuery, WY_QV_LOOP_ADD); $oURL->setQuery(array_merge($oURL->dQuery, $dEditQuery)); $oURL->sAnchor = "WEBYEP_CURRENT_LOOP_ITEM"; $oLink = new WYLink($oURL, WYTS("LoopAddButton")); $oImgURL->addComponent("add-button.gif"); $oImg = new WYImage($oImgURL); $oImg->setAttribute("style", "border: none"); $oImg->setAttribute("alt", WYTS("LoopAddButton")); $oLink->setInnerHTML($oImg->sDisplay()); $oLink->setAttribute("class", "WebYepLoopAddButton"); echo $oLink->sDisplay(); if ($iCount > 1) { $dEditQuery = $oURL->dQuery; $goApp->setActionInQuery($dEditQuery, WY_QV_LOOP_REMOVE); $oURL->setQuery($dEditQuery); $oLink = new WYLink($oURL, WYTS("LoopRemoveButton")); $oImgURL->removeLastComponent(); $oImgURL->addComponent("remove-button.gif"); $oImg = new WYImage($oImgURL); $oImg->setAttribute("style", "border: none"); $oImg->setAttribute("alt", WYTS("LoopRemoveButton")); $oLink->setInnerHTML($oImg->sDisplay()); $oLink->setAttribute("onclick", "return confirm(\"" . WYTS("LoopRemoveConfirm") . "\");"); $oLink->setAttribute("class", "WebYepLoopRemoveButton"); echo $oLink->sDisplay(); $oLink->removeAttribute("onclick"); $goApp->setActionInQuery($dEditQuery, WY_QV_LOOP_UP); $oURL->setQuery($dEditQuery); $oLink = new WYLink($oURL, WYTS("LoopUpButton")); $oImgURL->removeLastComponent(); $oImgURL->addComponent("up-button.gif"); $oImg = new WYImage($oImgURL); $oImg->setAttribute("style", "border: none"); $oImg->setAttribute("alt", WYTS("LoopUpButton")); $oLink->setInnerHTML($oImg->sDisplay()); $oLink->setAttribute("class", "WebYepLoopUpButton"); echo $oLink->sDisplay(); $goApp->setActionInQuery($dEditQuery, WY_QV_LOOP_DOWN); $oURL->setQuery($dEditQuery); $oLink = new WYLink($oURL, WYTS("LoopDownButton")); $oImgURL->removeLastComponent(); $oImgURL->addComponent("down-button.gif"); $oImg = new WYImage($oImgURL); $oImg->setAttribute("style", "border: none"); $oImg->setAttribute("alt", WYTS("LoopDownButton")); $oLink->setInnerHTML($oImg->sDisplay()); $oLink->setAttribute("class", "WebYepLoopDownButton"); echo $oLink->sDisplay(); } if ($this->bIDIsDisabled($this->iCurrentLoopID())) { $goApp->setActionInQuery($dEditQuery, WY_QV_LOOP_ENABLE); $oURL->setQuery($dEditQuery); $oLink = new WYLink($oURL, WYTS("LoopEnableButton")); $oImgURL->removeLastComponent(); $oImgURL->addComponent("enable-button.gif"); $oImg = new WYImage($oImgURL); $oImg->setAttribute("style", "border: none"); $oImg->setAttribute("alt", WYTS("LoopEnableButton")); $oLink->setInnerHTML($oImg->sDisplay()); $oLink->setAttribute("class", "WebYepLoopEnabledButton"); echo $oLink->sDisplay(); } else { $goApp->setActionInQuery($dEditQuery, WY_QV_LOOP_DISABLE); $oURL->setQuery($dEditQuery); $oLink = new WYLink($oURL, WYTS("LoopDisableButton")); $oImgURL->removeLastComponent(); $oImgURL->addComponent("disable-button.gif"); $oImg = new WYImage($oImgURL); $oImg->setAttribute("style", "border: none"); $oImg->setAttribute("alt", WYTS("LoopDisableButton")); $oLink->setInnerHTML($oImg->sDisplay()); $oLink->setAttribute("class", "WebYepLoopEnabledButton"); echo $oLink->sDisplay(); } } } function loopEnd() { global $webyep_oCurrentLoop; $this->iElementsLeft--; if ($this->iElementsLeft <= 0) $webyep_oCurrentLoop = od_nil; } function dispatchEditAction() { global $goApp; $sAction = $goApp->sCurrentAction(); $sFieldName = $goApp->sFormFieldValue(WY_QK_EDITOR_FIELDNAME, ""); $iLoopID = (int)$goApp->sFormFieldValue(WY_QK_LOOP_ID, 0); $aLoopIDs = $this->_aLoopIDs(); $iCount = count($aLoopIDs); $iNewID = 0; $iPos = 0; $bChanged = false; if ($sFieldName != $this->sName) return; if ($sAction == WY_QV_LOOP_ADD) { if ($iCount) { $iNewID = max($aLoopIDs) + 1; $this->iEditedID = $iNewID; $iPos = array_search($iLoopID, $aLoopIDs); if ($iPos !== false) { // should be in there, but who knows... $iPos++; if ($iPos >= $iCount) $aLoopIDs[] = $iNewID; else webyep_array_insert($aLoopIDs, $iPos, $iNewID); } else $aLoopIDs[] = $iNewID; } else $aLoopIDs = array(1); $this->enableLoopID($iNewID); $bChanged = true; } else if ($sAction == WY_QV_LOOP_REMOVE) { if ($iCount > 1) { $iPos = array_search($iLoopID, $aLoopIDs); if ($iPos !== false) { array_splice($aLoopIDs, $iPos, 1); $this->enableLoopID($iLoopID); } if (isset($aLoopIDs[$iPos])) $this->iEditedID = $aLoopIDs[$iPos]; else if (isset($aLoopIDs[$iPos-1])) $this->iEditedID = $aLoopIDs[$iPos-1]; $bChanged = true; } $this->iLoopIDJustDeleted = $iLoopID; } else if ($sAction == WY_QV_LOOP_UP) { $this->iEditedID = $iLoopID; $iPos = array_search($iLoopID, $aLoopIDs); if ($iCount > 1 && $iPos !== false && $iPos > 0) { array_splice($aLoopIDs, $iPos, 1); webyep_array_insert($aLoopIDs, $iPos - 1, $iLoopID); $bChanged = true; } } else if ($sAction == WY_QV_LOOP_DOWN) { $this->iEditedID = $iLoopID; $iPos = array_search($iLoopID, $aLoopIDs); if ($iCount > 1 && $iPos !== false && $iPos < ($iCount - 1)) { array_splice($aLoopIDs, $iPos, 1); webyep_array_insert($aLoopIDs, $iPos + 1, $iLoopID); $bChanged = true; } } else if ($sAction == WY_QV_LOOP_DISABLE) { $this->iEditedID = $iLoopID; $this->disableLoopID($iLoopID); $bChanged = true; } else if ($sAction == WY_QV_LOOP_ENABLE) { $this->iEditedID = $iLoopID; $this->enableLoopID($iLoopID); $bChanged = true; } if ($bChanged) { $this->_setLoopIDs($aLoopIDs); $this->save(); } } function sDisplay() { return ""; } } ?>