00001 <?php
00002
00011 class Article_Extend extends oxAdminDetails
00012 {
00019 public function render()
00020 {
00021 parent::render();
00022
00023 $this->_aViewData['edit'] = $oArticle = oxNew( 'oxarticle' );
00024
00025 $soxId = oxConfig::getParameter( 'oxid' );
00026 $sCatView = getViewName( 'oxcategories' );
00027
00028
00029 if ( $soxId != "-1" && isset( $soxId ) ) {
00030 $oArticle->loadInLang( $this->_iEditLang, $soxId );
00031
00032
00033
00034 $oOtherLang = $oArticle->getAvailableInLangs();
00035 if (!isset($oOtherLang[$this->_iEditLang])) {
00036
00037 $oArticle->loadInLang( key($oOtherLang), $soxId );
00038 }
00039
00040 foreach ( $oOtherLang as $id => $language) {
00041 $oLang= new oxStdClass();
00042 $oLang->sLangDesc = $language;
00043 $oLang->selected = ($id == $this->_iEditLang);
00044 $this->_aViewData["otherlang"][$id] = clone $oLang;
00045 }
00046
00047
00048 if ( $oArticle->oxarticles__oxparentid->value) {
00049 $oParentArticle = oxNew( 'oxarticle' );
00050 $oParentArticle->load( $oArticle->oxarticles__oxparentid->value);
00051 $this->_aViewData["parentarticle"] = $oParentArticle;
00052 $this->_aViewData["oxparentid"] = $oArticle->oxarticles__oxparentid->value;
00053 }
00054
00055 $sO2CView = getViewName('oxobject2category');
00056 }
00057
00058 if ( oxConfig::getParameter("aoc") ) {
00059
00060 $aColumns = array();
00061 include_once 'inc/'.strtolower(__CLASS__).'.inc.php';
00062 $this->_aViewData['oxajax'] = $aColumns;
00063
00064 return "popups/article_extend.tpl";
00065 }
00066
00067
00068 $oDB = oxDb::GetDB();
00069 $myConfig = oxConfig::getInstance();
00070 $suffix = ($this->_iEditLang)?"_$this->_iEditLang":"";
00071
00072 $aList = array();
00073
00074 $iArtCnt = $myConfig->getParameter( "iArtCnt");
00075
00076
00077
00078
00079 $oArt = new stdClass();
00080 $oArt->oxarticles__oxid = new oxField("");
00081 $oArt->oxarticles__oxartnum = new oxField("");
00082 $oArt->oxarticles__oxtitle = new oxField(" -- ");
00083 $aList[] = $oArt;
00084
00085
00086 $blHideVariants = !$myConfig->getConfigParam( 'blVariantsSelection' );
00087 $sHideVariants = $blHideVariants?" where oxarticles.oxparentid = '' and ":" where ";
00088
00089 $sHideItself = "oxarticles.oxid != '$soxId' and ";
00090
00091 $sSelect = "select oxarticles.oxid, oxarticles.oxartnum, oxarticles.oxtitle$suffix, oxarticles.oxvarselect$suffix from oxarticles $sHideVariants ";
00092 $sSelect .= "$sHideItself oxarticles.oxshopid = '".$myConfig->getShopId()."' order by oxartnum, oxtitle";
00093 $rs = $oDB->Execute( $sSelect);
00094 if ($rs != false && $rs->RecordCount() > 0) {
00095 while (!$rs->EOF) {
00096 $oArt = new stdClass();
00097 $oArt->oxarticles__oxid = new oxField($rs->fields[0]);
00098 $oArt->oxarticles__oxnid = new oxField($rs->fields[0]);
00099 $oArt->oxarticles__oxartnum = new oxField($rs->fields[1]);
00100 $oArt->oxarticles__oxtitle = new oxField($rs->fields[2]);
00101 if ( !$oArt->oxarticles__oxtitle->value && !$blHideVariants)
00102 $oArt->oxarticles__oxtitle = new oxField($rs->fields[3]);
00103 if( $oArt->oxarticles__oxid->value == $oArticle->oxarticles__oxbundleid->value) {
00104 $oArt->selected = 1;
00105 } else {
00106 $oArt->selected = 0;
00107 }
00108 $aList[] = $oArt;
00109 $rs->MoveNext();
00110 }
00111 }
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122 $this->_aViewData["arttree"] = $aList;
00123
00124
00125 $this->_aViewData['aMediaUrls'] = $oArticle->getMediaUrls();
00126
00127 return "article_extend.tpl";
00128 }
00129
00135 public function save()
00136 {
00137
00138 $soxId = oxConfig::getParameter( "oxid");
00139 $aParams = oxConfig::getParameter( "editval");
00140
00141 if ( !isset( $aParams['oxarticles__oxissearch']))
00142 $aParams['oxarticles__oxissearch'] = 0;
00143 if ( !isset( $aParams['oxarticles__oxblfixedprice']))
00144 $aParams['oxarticles__oxblfixedprice'] = 0;
00145
00146
00147
00148
00149
00150
00151 $aParams = $this->addDefaultValues( $aParams);
00152
00153 $oArticle = oxNew( "oxarticle" );
00154 $oArticle->loadInLang( $this->_iEditLang, $soxId);
00155
00156
00157 $oArticle->setLanguage(0);
00158 $oArticle->assign( $aParams);
00159 $oArticle->setLanguage($this->_iEditLang);
00160 $oArticle = oxUtilsFile::getInstance()->processFiles( $oArticle );
00161 $oArticle->save();
00162
00163
00164 $sMediaUrl = oxConfig::getParameter( "mediaUrl");
00165 $sMediaDesc = oxConfig::getParameter( "mediaDesc");
00166 $aMediaFile = oxConfig::getInstance()->getUploadedFile( "mediaFile");
00167
00168 if ($sMediaUrl || $aMediaFile['name'] || $sMediaDesc) {
00169
00170 if ( !$sMediaDesc ) {
00171 oxUtilsView::getInstance()->addErrorToDisplay(oxLang::getInstance()->translateString('EXCEPTION_NODESCRIPTIONADDED'));
00172 return;
00173 }
00174
00175 if ( !$sMediaUrl && !$aMediaFile['name'] ) {
00176 oxUtilsView::getInstance()->addErrorToDisplay(oxLang::getInstance()->translateString('EXCEPTION_NOMEDIAADDED'));
00177 return;
00178 }
00179
00180 $oMediaUrl = oxNew("oxMediaUrl");
00181 $oMediaUrl->setLanguage( $this->_iEditLang );
00182 $oMediaUrl->oxmediaurls__oxisuploaded = new oxField( 0, oxField::T_RAW);
00183
00184
00185 if ($aMediaFile['name']) {
00186 try {
00187 $sMediaUrl = oxUtilsFile::getInstance()->handleUploadedFile($aMediaFile, 'out/media/');
00188 $oMediaUrl->oxmediaurls__oxisuploaded = new oxField(1, oxField::T_RAW);
00189 } catch (Exception $e) {
00190 oxUtilsView::getInstance()->addErrorToDisplay(oxLang::getInstance()->translateString($e->getMessage()));
00191 return;
00192 }
00193 }
00194
00195
00196 $oMediaUrl->oxmediaurls__oxobjectid = new oxField($soxId, oxField::T_RAW);
00197 $oMediaUrl->oxmediaurls__oxurl = new oxField($sMediaUrl, oxField::T_RAW);
00198 $oMediaUrl->oxmediaurls__oxdesc = new oxField(oxConfig::getParameter( "mediaDesc"), oxField::T_RAW);
00199 $oMediaUrl->save();
00200
00201 }
00202
00203 return $this->autosave();
00204 }
00205
00211 public function deletemedia()
00212 {
00213 $soxId = oxConfig::getParameter( "oxid");
00214 $sMediaId = oxConfig::getParameter( "mediaid");
00215 if ($sMediaId && $soxId) {
00216 $oMediaUrl = oxNew("oxMediaUrl");
00217 $oMediaUrl->load($sMediaId);
00218 $oMediaUrl->delete();
00219 }
00220 }
00221
00230 public function addDefaultValues( $aParams)
00231 {
00232 $aParams['oxarticles__oxexturl'] = str_replace( "http://", "", $aParams['oxarticles__oxexturl']);
00233
00234 return $aParams;
00235 }
00236
00242 public function updateMedia()
00243 {
00244 $aMediaUrls = oxConfig::getParameter( 'aMediaUrls' );
00245 if ( is_array( $aMediaUrls ) ) {
00246 foreach ( $aMediaUrls as $sMediaId => $aMediaParams ) {
00247 $oMedia = oxNew("oxMediaUrl");
00248 if ( $oMedia->load( $sMediaId ) ) {
00249 $oMedia->setLanguage(0);
00250 $oMedia->assign( $aMediaParams );
00251 $oMedia->setLanguage( $this->_iEditLang );
00252 $oMedia->save();
00253 }
00254 }
00255 }
00256 }
00257
00258 }