selectlist_main.php

Go to the documentation of this file.
00001 <?php
00002 
00003 DEFINE("ERR_SUCCESS", 1);
00004 DEFINE("ERR_REQUIREDMISSING", -1);
00005 DEFINE("ERR_POSOUTOFBOUNDS", -2);
00006 
00012 class SelectList_Main extends oxAdminDetails
00013 {
00017      public $aFieldArray = null;
00018 
00026     public function render()
00027     {
00028         $myConfig = $this->getConfig();
00029         parent::render();
00030 
00031 
00032         $sOxId = oxConfig::getParameter( "oxid");
00033         // check if we right now saved a new entry
00034         $sSavedId = oxConfig::getParameter( "saved_oxid");
00035         if ( ($sOxId == "-1" || !isset( $sOxId)) && isset( $sSavedId) ) {
00036             $sOxId = $sSavedId;
00037             oxSession::deleteVar( "saved_oxid");
00038             $this->_aViewData["oxid"] =  $sOxId;
00039             // for reloading upper frame
00040             $this->_aViewData["updatelist"] =  "1";
00041         }
00042 
00043         $sArticleTable = getViewName('oxarticles');
00044 
00045         //create empty edit object
00046         $this->_aViewData["edit"] = oxNew( "oxselectlist" );
00047 
00048         if ( $sOxId != "-1" && isset( $sOxId)) {
00049             // generating category tree for select list
00050             // A. hack - passing language by post as lists uses only language passed by POST/GET/SESSION
00051             $_POST["language"] = $this->_iEditLang;
00052             $sChosenArtCat = $this->_getCategoryTree( "artcattree", $sChosenArtCat, $sOxId);
00053 
00054             // load object
00055             $oAttr = oxNew( "oxselectlist" );
00056             $oAttr->loadInLang( $this->_iEditLang, $sOxId );
00057 
00058             $aFieldList = $oAttr->getFieldList();
00059             if ( is_array( $aFieldList ) ) {
00060                 foreach ( $aFieldList as $key => $oField ) {
00061                     if ( $oField->priceUnit == '%' ) {
00062                         $oField->price = $oField->fprice;
00063                     }
00064                 }
00065             }
00066 
00067             $oOtherLang = $oAttr->getAvailableInLangs();
00068             if (!isset($oOtherLang[$this->_iEditLang])) {
00069                 // echo "language entry doesn't exist! using: ".key($oOtherLang);
00070                 $oAttr->loadInLang( key($oOtherLang), $sOxId );
00071             }
00072             $this->_aViewData["edit"] =  $oAttr;
00073 
00074 
00075             // remove already created languages
00076             $aLang = array_diff ( oxLang::getInstance()->getLanguageNames(), $oOtherLang);
00077             if ( count( $aLang))
00078                 $this->_aViewData["posslang"] = $aLang;
00079 
00080             foreach ( $oOtherLang as $id => $language) {
00081                 $oLang = new oxStdClass();
00082                 $oLang->sLangDesc = $language;
00083                 $oLang->selected = ($id == $this->_iEditLang);
00084                 $this->_aViewData["otherlang"][$id] = clone $oLang;
00085             }
00086 
00087             $iErr = oxConfig::getParameter( "iErrorCode");
00088             if (!$iErr)
00089                 $iErr = ERR_SUCCESS;
00090             $this->_aViewData["iErrorCode"] = $iErr;
00091             oxSession::setVar("iErrorCode", ERR_SUCCESS);
00092 
00093         }
00094         if ( oxConfig::getParameter("aoc") ) {
00095 
00096             $aColumns = array();
00097             include_once 'inc/'.strtolower(__CLASS__).'.inc.php';
00098             $this->_aViewData['oxajax'] = $aColumns;
00099 
00100             return "popups/selectlist_main.tpl";
00101         }
00102         return "selectlist_main.tpl";
00103     }
00104 
00110     public function save()
00111     {
00112 
00113         $sOxId      = oxConfig::getParameter( "oxid");
00114         $aParams    = oxConfig::getParameter( "editval");
00115 
00116             // shopid
00117             $sShopID = oxSession::getVar( "actshop");
00118             $aParams['oxselectlist__oxshopid'] = $sShopID;
00119         $oAttr = oxNew( "oxselectlist" );
00120 
00121         if ( $sOxId != "-1")
00122             $oAttr->loadInLang( $this->_iEditLang, $sOxId );
00123         else
00124             $aParams['oxselectlist__oxid'] = null;
00125 
00126 
00127         //$aParams = $oAttr->ConvertNameArray2Idx( $aParams);
00128         $oAttr->setLanguage(0);
00129         $oAttr->assign( $aParams);
00130 
00131         //#708
00132         if ( !is_array( $this->aFieldArray))
00133                 $this->aFieldArray = oxUtils::getInstance()->assignValuesFromText( $oAttr->oxselectlist__oxvaldesc->value );
00134         // build value
00135         $oAttr->oxselectlist__oxvaldesc = new oxField("");
00136         foreach ( $this->aFieldArray as $oField) {
00137             $oAttr->oxselectlist__oxvaldesc->setValue( $oAttr->oxselectlist__oxvaldesc->value . $oField->name);
00138             if ( isset( $oField->price) && $oField->price) {
00139                 $oAttr->oxselectlist__oxvaldesc->setValue( $oAttr->oxselectlist__oxvaldesc->value . "!P!" . trim(str_replace( ",", ".", $oField->price)));
00140                 if ($oField->priceUnit == '%')
00141                     $oAttr->oxselectlist__oxvaldesc->setValue( $oAttr->oxselectlist__oxvaldesc->value . '%');
00142             }
00143             $oAttr->oxselectlist__oxvaldesc->setValue( $oAttr->oxselectlist__oxvaldesc->value . "__@@");
00144         }
00145 
00146         $oAttr->setLanguage($this->_iEditLang);
00147         $oAttr->save();
00148         $this->_aViewData["updatelist"] = "1";
00149 
00150         // set oxid if inserted
00151         if ( $sOxId == "-1")
00152             oxSession::setVar( "saved_oxid", $oAttr->oxselectlist__oxid->value);
00153 
00154         return $this->autosave();
00155     }
00156 
00162     public function saveinnlang()
00163     {
00164         $sOxId      = oxConfig::getParameter( "oxid");
00165         $aParams    = oxConfig::getParameter( "editval");
00166 
00167             // shopid
00168             $sShopID = oxSession::getVar( "actshop");
00169             $aParams['oxselectlist__oxshopid'] = $sShopID;
00170         $oObj = oxNew( "oxselectlist" );
00171 
00172         if ( $sOxId != "-1")
00173             $oObj->loadInLang( $this->_iEditLang, $sOxId );
00174         else
00175             $aParams['oxselectlist__oxid'] = null;
00176 
00177 
00178         //$aParams = $oObj->ConvertNameArray2Idx( $aParams);
00179         $oObj->setLanguage(0);
00180         $oObj->assign( $aParams);
00181 
00182         // apply new language
00183         $sNewLanguage = oxConfig::getParameter( "new_lang");
00184         $oObj->setLanguage( $sNewLanguage);
00185         $oObj->save();
00186         $this->_aViewData["updatelist"] = "1";
00187 
00188         // set for reload
00189         oxSession::setVar( "new_lang", $sNewLanguage);
00190 
00191         // set oxid if inserted
00192         if ( $sOxId == "-1")
00193             oxSession::setVar( "saved_oxid", $oObj->oxselectlist__oxid->value);
00194     }
00195 
00196 
00202     public function delFields()
00203     {
00204         $sOxId       = oxConfig::getParameter( "oxid");
00205         $oSelectlist = oxNew( "oxselectlist" );
00206         $oSelectlist->loadInLang( $this->_iEditLang, $sOxId );
00207 
00208 
00209         $aDelFields = oxConfig::getParameter("aFields");
00210         $this->aFieldArray = oxUtils::getInstance()->assignValuesFromText( $oSelectlist->oxselectlist__oxvaldesc->value );
00211 
00212         if ( isset( $aDelFields) && count( $aDelFields)) {
00213             foreach ( $aDelFields as $sDelField) {
00214                 foreach ( $this->aFieldArray as $key => $oField) {
00215                     $sDel = $this->parseFieldName($sDelField);
00216                     if ( $oField->name == $sDel) {
00217                         unset(  $this->aFieldArray[$key]);
00218                         break;
00219                     }
00220                 }
00221             }
00222             $this->save();
00223         }
00224     }
00225 
00231     public function addField()
00232     {
00233         $sOxId = oxConfig::getParameter( "oxid");
00234         $oSelectlist = oxNew( "oxselectlist" );
00235         $oSelectlist->loadInLang( $this->_iEditLang, $sOxId );
00236 
00237 
00238         $sAddField = oxConfig::getParameter("sAddField");
00239         if (empty($sAddField)) {
00240             oxSession::setVar("iErrorCode", ERR_REQUIREDMISSING);
00241             return;
00242         }
00243         $this->aFieldArray = oxUtils::getInstance()->assignValuesFromText( $oSelectlist->oxselectlist__oxvaldesc->value );
00244 
00245         $sAddFieldPrice = oxConfig::getParameter("sAddFieldPriceMod");
00246         $sAddFieldPriceUnit = oxConfig::getParameter("sAddFieldPriceModUnit");
00247 
00248         $oField = new stdClass();
00249         $oField->name = $sAddField;
00250         $oField->price = $sAddFieldPrice;
00251         $oField->priceUnit = $sAddFieldPriceUnit;
00252 
00253         $this->aFieldArray[] = $oField;
00254         $pos = oxConfig::getParameter("sAddFieldPos");
00255         if ($pos) {
00256             if ($this->_rearrangeFields($oField, $pos-1))
00257                 return;
00258         }
00259 
00260         $this->save();
00261     }
00262 
00268     public function changeField()
00269     {
00270         $sAddField = oxConfig::getParameter("sAddField");
00271         if (empty($sAddField)) {
00272             oxSession::setVar("iErrorCode", ERR_REQUIREDMISSING);
00273             return;
00274         }
00275 
00276         $sOxId = oxConfig::getParameter( "oxid");
00277         $oSelectlist = oxNew( "oxselectlist" );
00278         $oSelectlist->loadInLang( $this->_iEditLang, $sOxId );
00279 
00280         $aChangeFields = oxConfig::getParameter("aFields");
00281         $this->aFieldArray = oxUtils::getInstance()->assignValuesFromText( $oSelectlist->oxselectlist__oxvaldesc->value );
00282 
00283         if ( isset( $aChangeFields) && count( $aChangeFields)) {
00284             $sChangeFieldName = $this->parseFieldName($aChangeFields[0]);
00285             foreach ( $this->aFieldArray as $key => $oField) {
00286                 if ( $oField->name == $sChangeFieldName) {
00287                     $this->aFieldArray[$key]->name  = $sAddField;
00288                     $this->aFieldArray[$key]->price = oxConfig::getParameter("sAddFieldPriceMod");
00289                     $this->aFieldArray[$key]->priceUnit = oxConfig::getParameter("sAddFieldPriceModUnit");
00290                     $pos = oxConfig::getParameter("sAddFieldPos");
00291                     if ($pos) {
00292                         if ($this->_rearrangeFields($this->aFieldArray[$key], $pos-1))
00293                             return;
00294                     }
00295                     break;
00296                 }
00297             }
00298             $this->save();
00299         }
00300     }
00301 
00311     protected function _rearrangeFields($oField, $pos)
00312     {
00313         if (!isset($this->aFieldArray) || !is_array($this->aFieldArray))
00314            return true;
00315         $iCurrentPos = -1;
00316         $iFieldCount = count($this->aFieldArray);
00317         if ($pos < 0 || $pos >= $iFieldCount) {
00318             oxSession::setVar("iErrorCode", ERR_POSOUTOFBOUNDS);
00319             return true;
00320         }
00321         for ($i=0;$i<$iFieldCount;$i++) {
00322             if ($this->aFieldArray[$i] == $oField) {
00323                 $iCurrentPos = $i;
00324                 break;
00325             }
00326         }
00327         if ($iCurrentPos == -1)
00328             return true;
00329         if ($iCurrentPos == $pos)
00330             return false;
00331 
00332         $field = $this->aFieldArray[$iCurrentPos];
00333         if ($iCurrentPos < $pos) {
00334             for ($i=$iCurrentPos;$i<$pos;$i++)
00335                 $this->aFieldArray[$i] = $this->aFieldArray[$i+1];
00336             $this->aFieldArray[$pos] = $field;
00337             return false;
00338         } else {
00339             for ($i=$iCurrentPos;$i>$pos;$i--)
00340                 $this->aFieldArray[$i] = $this->aFieldArray[$i-1];
00341             $this->aFieldArray[$pos] = $field;
00342             return false;
00343         }
00344     }
00345 
00354     function parseFieldName($sInput)
00355     {
00356         $aInput = explode('__@@', $sInput, 3);
00357         return $aInput[1];
00358     }
00359 }

Generated on Thu Dec 4 12:04:56 2008 for OXID eShop CE by  doxygen 1.5.5