Go to the documentation of this file.00001 <?php
00002
00010 class Article_Extend extends oxAdminDetails
00011 {
00012
00018 protected $_aUnitsArray = null;
00019
00026 public function render()
00027 {
00028 parent::render();
00029
00030 $this->_aViewData['edit'] = $oArticle = oxNew('oxArticle');
00031
00032 $soxId = $this->getEditObjectId();
00033
00034 $this->_createCategoryTree("artcattree");
00035
00036
00037 if ($soxId != "-1" && isset($soxId)) {
00038
00039 $oArticle->loadInLang($this->_iEditLang, $soxId);
00040
00041
00042
00043 $oOtherLang = $oArticle->getAvailableInLangs();
00044 if (!isset($oOtherLang[$this->_iEditLang])) {
00045 $oArticle->loadInLang(key($oOtherLang), $soxId);
00046 }
00047
00048 foreach ($oOtherLang as $id => $language) {
00049 $oLang = new stdClass();
00050 $oLang->sLangDesc = $language;
00051 $oLang->selected = ($id == $this->_iEditLang);
00052 $this->_aViewData["otherlang"][$id] = clone $oLang;
00053 }
00054
00055
00056 if ($oArticle->oxarticles__oxparentid->value) {
00057 $oParentArticle = oxNew('oxArticle');
00058 $oParentArticle->load($oArticle->oxarticles__oxparentid->value);
00059 $this->_aViewData["parentarticle"] = $oParentArticle;
00060 $this->_aViewData["oxparentid"] = $oArticle->oxarticles__oxparentid->value;
00061 }
00062 }
00063
00064
00065 $oDB = oxDb::getDB();
00066 $myConfig = $this->getConfig();
00067
00068 $sArticleTable = getViewName('oxarticles', $this->_iEditLang);
00069 $sSelect = "select {$sArticleTable}.oxtitle, {$sArticleTable}.oxartnum, {$sArticleTable}.oxvarselect " .
00070 "from {$sArticleTable} where 1 ";
00071
00072 $blVariantsSelectionParameter = $myConfig->getConfigParam('blVariantsSelection');
00073 $sBundleIdField = 'oxarticles__oxbundleid';
00074 $sSelect .= $blVariantsSelectionParameter ? '' : " and {$sArticleTable}.oxparentid = '' ";
00075 $sSelect .= " and {$sArticleTable}.oxid = " . $oDB->quote($oArticle->$sBundleIdField->value);
00076
00077 $rs = $oDB->Execute($sSelect);
00078 if ($rs != false && $rs->RecordCount() > 0) {
00079 while (!$rs->EOF) {
00080 $sArtNum = new oxField($rs->fields[1]);
00081 $sArtTitle = new oxField($rs->fields[0] . " " . $rs->fields[2]);
00082 $rs->MoveNext();
00083 }
00084 }
00085 $this->_aViewData['bundle_artnum'] = $sArtNum;
00086 $this->_aViewData['bundle_title'] = $sArtTitle;
00087
00088
00089 $iAoc = $this->getConfig()->getRequestParameter("aoc");
00090 if ($iAoc == 1) {
00091 $oArticleExtendAjax = oxNew('article_extend_ajax');
00092 $this->_aViewData['oxajax'] = $oArticleExtendAjax->getColumns();
00093
00094 return "popups/article_extend.tpl";
00095 } elseif ($iAoc == 2) {
00096 $oArticleBundleAjax = oxNew('article_bundle_ajax');
00097 $this->_aViewData['oxajax'] = $oArticleBundleAjax->getColumns();
00098
00099 return "popups/article_bundle.tpl";
00100 }
00101
00102
00103 $this->_aViewData['aMediaUrls'] = $oArticle->getMediaUrls();
00104
00105 return "article_extend.tpl";
00106 }
00107
00113 public function save()
00114 {
00115 parent::save();
00116
00117 $aMyFile = $this->getConfig()->getUploadedFile("myfile");
00118 $aMediaFile = $this->getConfig()->getUploadedFile("mediaFile");
00119 if (is_array($aMyFile['name']) && reset($aMyFile['name']) || $aMediaFile['name']) {
00120 $myConfig = $this->getConfig();
00121 if ($myConfig->isDemoShop()) {
00122 $oEx = oxNew("oxExceptionToDisplay");
00123 $oEx->setMessage('ARTICLE_EXTEND_UPLOADISDISABLED');
00124 oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx, false);
00125
00126 return;
00127 }
00128 }
00129
00130 $soxId = $this->getEditObjectId();
00131 $aParams = oxRegistry::getConfig()->getRequestParameter("editval");
00132
00133 if (!isset($aParams['oxarticles__oxissearch'])) {
00134 $aParams['oxarticles__oxissearch'] = 0;
00135 }
00136 if (!isset($aParams['oxarticles__oxblfixedprice'])) {
00137 $aParams['oxarticles__oxblfixedprice'] = 0;
00138 }
00139
00140
00141
00142
00143
00144
00145 $aParams = $this->addDefaultValues($aParams);
00146
00147 $oArticle = oxNew("oxarticle");
00148 $oArticle->loadInLang($this->_iEditLang, $soxId);
00149 $sTPriceField = 'oxarticles__oxtprice';
00150 $sPriceField = 'oxarticles__oxprice';
00151 $dTPrice = $aParams['oxarticles__oxtprice'];
00152 if ($dTPrice && $dTPrice != $oArticle->$sTPriceField->value && $dTPrice <= $oArticle->$sPriceField->value) {
00153 $this->_aViewData["errorsavingtprice"] = 1;
00154 }
00155
00156 $oArticle->setLanguage(0);
00157 $oArticle->assign($aParams);
00158 $oArticle->setLanguage($this->_iEditLang);
00159 $oArticle = oxRegistry::get("oxUtilsFile")->processFiles($oArticle);
00160 $oArticle->save();
00161
00162
00163 $sMediaUrl = $this->getConfig()->getRequestParameter("mediaUrl");
00164 $sMediaDesc = $this->getConfig()->getRequestParameter("mediaDesc");
00165
00166 if (($sMediaUrl && $sMediaUrl != 'http://') || $aMediaFile['name'] || $sMediaDesc) {
00167
00168 if (!$sMediaDesc) {
00169 return oxRegistry::get("oxUtilsView")->addErrorToDisplay('EXCEPTION_NODESCRIPTIONADDED');
00170 }
00171
00172 if ((!$sMediaUrl || $sMediaUrl == 'http://') && !$aMediaFile['name']) {
00173 return oxRegistry::get("oxUtilsView")->addErrorToDisplay('EXCEPTION_NOMEDIAADDED');
00174 }
00175
00176 $oMediaUrl = oxNew("oxMediaUrl");
00177 $oMediaUrl->setLanguage($this->_iEditLang);
00178 $oMediaUrl->oxmediaurls__oxisuploaded = new oxField(0, oxField::T_RAW);
00179
00180
00181 if ($aMediaFile['name']) {
00182 try {
00183 $sMediaUrl = oxRegistry::get("oxUtilsFile")->processFile('mediaFile', 'out/media/');
00184 $oMediaUrl->oxmediaurls__oxisuploaded = new oxField(1, oxField::T_RAW);
00185 } catch (Exception $e) {
00186 return oxRegistry::get("oxUtilsView")->addErrorToDisplay($e->getMessage());
00187 }
00188 }
00189
00190
00191 $oMediaUrl->oxmediaurls__oxobjectid = new oxField($soxId, oxField::T_RAW);
00192 $oMediaUrl->oxmediaurls__oxurl = new oxField($sMediaUrl, oxField::T_RAW);
00193 $oMediaUrl->oxmediaurls__oxdesc = new oxField($sMediaDesc, oxField::T_RAW);
00194 $oMediaUrl->save();
00195 }
00196
00197
00198 oxNew("oxArticleList")->renewPriceUpdateTime();
00199 }
00200
00204 public function deletemedia()
00205 {
00206 $soxId = $this->getEditObjectId();
00207 $sMediaId = $this->getConfig()->getRequestParameter("mediaid");
00208 if ($sMediaId && $soxId) {
00209 $oMediaUrl = oxNew("oxMediaUrl");
00210 $oMediaUrl->load($sMediaId);
00211 $oMediaUrl->delete();
00212 }
00213 }
00214
00223 public function addDefaultValues($aParams)
00224 {
00225 $aParams['oxarticles__oxexturl'] = str_replace("http://", "", $aParams['oxarticles__oxexturl']);
00226
00227 return $aParams;
00228 }
00229
00233 public function updateMedia()
00234 {
00235 $aMediaUrls = $this->getConfig()->getRequestParameter('aMediaUrls');
00236 if (is_array($aMediaUrls)) {
00237 foreach ($aMediaUrls as $sMediaId => $aMediaParams) {
00238 $oMedia = oxNew("oxMediaUrl");
00239 if ($oMedia->load($sMediaId)) {
00240 $oMedia->setLanguage(0);
00241 $oMedia->assign($aMediaParams);
00242 $oMedia->setLanguage($this->_iEditLang);
00243 $oMedia->save();
00244 }
00245 }
00246 }
00247 }
00248
00254 public function getUnitsArray()
00255 {
00256 if ($this->_aUnitsArray === null) {
00257 $this->_aUnitsArray = oxRegistry::getLang()->getSimilarByKey("_UNIT_", $this->_iEditLang, false);
00258 }
00259
00260 return $this->_aUnitsArray;
00261 }
00262 }