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