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

Generated on Wed May 13 13:25:50 2009 for OXID eShop CE by  doxygen 1.5.5