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 = $this->_aViewData["oxid"] = $this->getEditObjectId();
00032 $sArticleTable = getViewName('oxarticles');
00033
00034
00035 $this->_aViewData["edit"] = oxNew( "oxselectlist" );
00036
00037 if ( $sOxId != "-1" && isset( $sOxId)) {
00038
00039
00040 $_POST["language"] = $this->_iEditLang;
00041 $sChosenArtCat = $this->_getCategoryTree( "artcattree", $sChosenArtCat, $sOxId);
00042
00043
00044 $oAttr = oxNew( "oxselectlist" );
00045 $oAttr->loadInLang( $this->_iEditLang, $sOxId );
00046
00047 $aFieldList = $oAttr->getFieldList();
00048 if ( is_array( $aFieldList ) ) {
00049 foreach ( $aFieldList as $key => $oField ) {
00050 if ( $oField->priceUnit == '%' ) {
00051 $oField->price = $oField->fprice;
00052 }
00053 }
00054 }
00055
00056 $oOtherLang = $oAttr->getAvailableInLangs();
00057 if (!isset($oOtherLang[$this->_iEditLang])) {
00058
00059 $oAttr->loadInLang( key($oOtherLang), $sOxId );
00060 }
00061 $this->_aViewData["edit"] = $oAttr;
00062
00063
00064
00065 $aLang = array_diff ( oxRegistry::getLang()->getLanguageNames(), $oOtherLang);
00066 if ( count( $aLang))
00067 $this->_aViewData["posslang"] = $aLang;
00068
00069 foreach ( $oOtherLang as $id => $language) {
00070 $oLang = new stdClass();
00071 $oLang->sLangDesc = $language;
00072 $oLang->selected = ($id == $this->_iEditLang);
00073 $this->_aViewData["otherlang"][$id] = clone $oLang;
00074 }
00075
00076 $iErr = oxSession::getVar( "iErrorCode");
00077 if (!$iErr)
00078 $iErr = ERR_SUCCESS;
00079 $this->_aViewData["iErrorCode"] = $iErr;
00080 oxSession::setVar("iErrorCode", ERR_SUCCESS);
00081
00082 }
00083 if ( oxConfig::getParameter("aoc") ) {
00084 $oSelectlistMainAjax = oxNew( 'selectlist_main_ajax' );
00085 $this->_aViewData['oxajax'] = $oSelectlistMainAjax->getColumns();
00086
00087 return "popups/selectlist_main.tpl";
00088 }
00089 return "selectlist_main.tpl";
00090 }
00091
00097 public function save()
00098 {
00099 parent::save();
00100
00101 $sOxId = $this->getEditObjectId();
00102 $aParams = oxConfig::getParameter( "editval");
00103
00104
00105 $sShopID = oxSession::getVar( "actshop");
00106 $aParams['oxselectlist__oxshopid'] = $sShopID;
00107 $oAttr = oxNew( "oxselectlist" );
00108
00109 if ( $sOxId != "-1") {
00110 $oAttr->loadInLang( $this->_iEditLang, $sOxId );
00111 } else {
00112 $aParams['oxselectlist__oxid'] = null;
00113 }
00114
00115
00116
00117 $oAttr->setLanguage(0);
00118 $oAttr->assign( $aParams);
00119
00120
00121 if ( !is_array( $this->aFieldArray)) {
00122 $this->aFieldArray = oxRegistry::getUtils()->assignValuesFromText( $oAttr->oxselectlist__oxvaldesc->getRawValue() );
00123 }
00124
00125 $oAttr->oxselectlist__oxvaldesc = new oxField("", oxField::T_RAW);
00126 foreach ( $this->aFieldArray as $oField) {
00127 $oAttr->oxselectlist__oxvaldesc->setValue( $oAttr->oxselectlist__oxvaldesc->getRawValue() . $oField->name, oxField::T_RAW);
00128 if ( isset( $oField->price) && $oField->price) {
00129 $oAttr->oxselectlist__oxvaldesc->setValue( $oAttr->oxselectlist__oxvaldesc->getRawValue() . "!P!" . trim(str_replace( ",", ".", $oField->price)), oxField::T_RAW);
00130 if ($oField->priceUnit == '%')
00131 $oAttr->oxselectlist__oxvaldesc->setValue( $oAttr->oxselectlist__oxvaldesc->getRawValue() . '%', oxField::T_RAW);
00132 }
00133 $oAttr->oxselectlist__oxvaldesc->setValue( $oAttr->oxselectlist__oxvaldesc->getRawValue() . "__@@", oxField::T_RAW);
00134 }
00135
00136 $oAttr->setLanguage($this->_iEditLang);
00137 $oAttr->save();
00138
00139
00140 $this->setEditObjectId( $oAttr->getId() );
00141 }
00142
00148 public function saveinnlang()
00149 {
00150 $sOxId = $this->getEditObjectId();
00151 $aParams = oxConfig::getParameter( "editval");
00152
00153
00154 $sShopID = oxSession::getVar( "actshop");
00155 $aParams['oxselectlist__oxshopid'] = $sShopID;
00156 $oObj = oxNew( "oxselectlist" );
00157
00158 if ( $sOxId != "-1")
00159 $oObj->loadInLang( $this->_iEditLang, $sOxId );
00160 else
00161 $aParams['oxselectlist__oxid'] = null;
00162
00163
00164 parent::save();
00165
00166
00167 $oObj->setLanguage(0);
00168 $oObj->assign( $aParams);
00169
00170
00171 $oObj->setLanguage( oxConfig::getParameter( "new_lang" ) );
00172 $oObj->save();
00173
00174
00175 $this->setEditObjectId( $oObj->getId() );
00176 }
00177
00183 public function delFields()
00184 {
00185 $oSelectlist = oxNew( "oxselectlist" );
00186 if ( $oSelectlist->loadInLang( $this->_iEditLang, $this->getEditObjectId() ) ) {
00187
00188 $aDelFields = oxConfig::getParameter( "aFields" );
00189 $this->aFieldArray = oxRegistry::getUtils()->assignValuesFromText( $oSelectlist->oxselectlist__oxvaldesc->getRawValue() );
00190
00191 if ( is_array( $aDelFields ) && count( $aDelFields ) ) {
00192 foreach ( $aDelFields as $sDelField ) {
00193 $sDel = $this->parseFieldName( $sDelField );
00194 foreach ( $this->aFieldArray as $sKey => $oField ) {
00195 if ( $oField->name == $sDel ) {
00196 unset( $this->aFieldArray[$sKey]);
00197 break;
00198 }
00199 }
00200 }
00201 $this->save();
00202 }
00203 }
00204 }
00205
00211 public function addField()
00212 {
00213 $oSelectlist = oxNew( "oxselectlist" );
00214 if ( $oSelectlist->loadInLang( $this->_iEditLang, $this->getEditObjectId() ) ) {
00215
00216
00217 $sAddField = oxConfig::getParameter("sAddField");
00218 if ( empty( $sAddField ) ) {
00219 oxSession::setVar( "iErrorCode", ERR_REQUIREDMISSING );
00220 return;
00221 }
00222
00223 $this->aFieldArray = oxRegistry::getUtils()->assignValuesFromText( $oSelectlist->oxselectlist__oxvaldesc->getRawValue() );
00224
00225 $oField = new stdClass();
00226 $oField->name = $sAddField;
00227 $oField->price = oxConfig::getParameter( "sAddFieldPriceMod" );
00228 $oField->priceUnit = oxConfig::getParameter( "sAddFieldPriceModUnit" );
00229
00230 $this->aFieldArray[] = $oField;
00231 if ( $iPos = oxConfig::getParameter( "sAddFieldPos" ) ) {
00232 if ( $this->_rearrangeFields( $oField, $iPos-1 ) ) {
00233 return;
00234 }
00235 }
00236
00237 $this->save();
00238 }
00239 }
00240
00246 public function changeField()
00247 {
00248 $sAddField = oxConfig::getParameter( "sAddField" );
00249 if ( empty( $sAddField ) ) {
00250 oxSession::setVar("iErrorCode", ERR_REQUIREDMISSING );
00251 return;
00252 }
00253
00254 $aChangeFields = oxConfig::getParameter( "aFields" );
00255 if ( is_array( $aChangeFields ) && count( $aChangeFields ) ) {
00256
00257 $oSelectlist = oxNew( "oxselectlist" );
00258 if ( $oSelectlist->loadInLang( $this->_iEditLang, $this->getEditObjectId() ) ) {
00259
00260 $this->aFieldArray = oxRegistry::getUtils()->assignValuesFromText( $oSelectlist->oxselectlist__oxvaldesc->getRawValue() );
00261 $sChangeFieldName = $this->parseFieldName( $aChangeFields[0] );
00262
00263 foreach ( $this->aFieldArray as $sKey => $oField ) {
00264 if ( $oField->name == $sChangeFieldName ) {
00265 $this->aFieldArray[$sKey]->name = $sAddField;
00266 $this->aFieldArray[$sKey]->price = oxConfig::getParameter( "sAddFieldPriceMod" );
00267 $this->aFieldArray[$sKey]->priceUnit = oxConfig::getParameter( "sAddFieldPriceModUnit" );
00268 if ( $iPos = oxConfig::getParameter( "sAddFieldPos" ) ) {
00269 if ( $this->_rearrangeFields( $this->aFieldArray[$sKey], $iPos-1 ) ) {
00270 return;
00271 }
00272 }
00273 break;
00274 }
00275 }
00276 $this->save();
00277 }
00278 }
00279 }
00280
00290 protected function _rearrangeFields( $oField, $iPos )
00291 {
00292 if ( !isset( $this->aFieldArray ) || !is_array( $this->aFieldArray ) ) {
00293 return true;
00294 }
00295
00296 $iFieldCount = count( $this->aFieldArray );
00297 if ( $iPos < 0 || $iPos >= $iFieldCount ) {
00298 oxSession::setVar( "iErrorCode", ERR_POSOUTOFBOUNDS );
00299 return true;
00300 }
00301
00302 $iCurrentPos = -1;
00303 for ( $i = 0; $i < $iFieldCount; $i++ ) {
00304 if ( $this->aFieldArray[$i] == $oField ) {
00305 $iCurrentPos = $i;
00306 break;
00307 }
00308 }
00309
00310 if ( $iCurrentPos == -1 ) {
00311 return true;
00312 }
00313
00314 if ( $iCurrentPos == $iPos ) {
00315 return false;
00316 }
00317
00318 $sField = $this->aFieldArray[$iCurrentPos];
00319 if ( $iCurrentPos < $iPos ) {
00320 for ( $i = $iCurrentPos; $i < $iPos; $i++ ) {
00321 $this->aFieldArray[$i] = $this->aFieldArray[$i+1];
00322 }
00323 $this->aFieldArray[$iPos] = $sField;
00324 return false;
00325 } else {
00326 for ( $i = $iCurrentPos; $i > $iPos; $i-- ) {
00327 $this->aFieldArray[$i] = $this->aFieldArray[$i-1];
00328 }
00329 $this->aFieldArray[$iPos] = $sField;
00330 return false;
00331 }
00332 }
00333
00342 function parseFieldName($sInput)
00343 {
00344 $aInput = explode('__@@', $sInput, 3);
00345 return $aInput[1];
00346 }
00347 }