00001 <?php
00002
00010 class Article_Extend extends oxAdminDetails
00011 {
00018 public function render()
00019 {
00020 parent::render();
00021
00022 $this->_aViewData['edit'] = $oArticle = oxNew( 'oxarticle' );
00023
00024 $soxId = oxConfig::getParameter( 'oxid' );
00025 $sCatView = getViewName( 'oxcategories' );
00026
00027 $sChosenArtCat = $this->_getCategoryTree( "artcattree", oxConfig::getParameter( "artcat"));
00028
00029
00030 if ( $soxId != "-1" && isset( $soxId ) ) {
00031 $oArticle->loadInLang( $this->_iEditLang, $soxId );
00032
00033
00034
00035 $oOtherLang = $oArticle->getAvailableInLangs();
00036 if (!isset($oOtherLang[$this->_iEditLang])) {
00037
00038 $oArticle->loadInLang( key($oOtherLang), $soxId );
00039 }
00040
00041 foreach ( $oOtherLang as $id => $language) {
00042 $oLang= new oxStdClass();
00043 $oLang->sLangDesc = $language;
00044 $oLang->selected = ($id == $this->_iEditLang);
00045 $this->_aViewData["otherlang"][$id] = clone $oLang;
00046 }
00047
00048
00049 if ( $oArticle->oxarticles__oxparentid->value) {
00050 $oParentArticle = oxNew( 'oxarticle' );
00051 $oParentArticle->load( $oArticle->oxarticles__oxparentid->value);
00052 $this->_aViewData["parentarticle"] = $oParentArticle;
00053 $this->_aViewData["oxparentid"] = $oArticle->oxarticles__oxparentid->value;
00054 }
00055
00056 $sO2CView = getViewName('oxobject2category');
00057 }
00058
00059
00060 $oDB = oxDb::GetDB();
00061 $myConfig = $this->getConfig();
00062 $suffix = ($this->_iEditLang)?"_$this->_iEditLang":"";
00063
00064 $sArticleTable = getViewName( 'oxarticles' );
00065 $sSelect = "select $sArticleTable.oxtitle$suffix, $sArticleTable.oxartnum, $sArticleTable.oxvarselect$suffix from $sArticleTable where 1 ";
00066
00067 $sSelect .= $myConfig->getConfigParam( 'blVariantsSelection' )?'':" and $sArticleTable.oxparentid = '' ";
00068 $sSelect .= " and $sArticleTable.oxid = '".$oArticle->oxarticles__oxbundleid->value."'";
00069
00070 $rs = $oDB->Execute( $sSelect);
00071 if ($rs != false && $rs->RecordCount() > 0) {
00072 while (!$rs->EOF) {
00073 $sArtNum = new oxField($rs->fields[1]);
00074 $sArtTitle = new oxField($rs->fields[0]." ".$rs->fields[2]);
00075 $rs->MoveNext();
00076 }
00077 }
00078 $this->_aViewData['bundle_artnum'] = $sArtNum;
00079 $this->_aViewData['bundle_title'] = $sArtTitle;
00080
00081
00082 $aColumns = array();
00083 $iAoc = oxConfig::getParameter("aoc");
00084 if ( $iAoc == 1 ) {
00085
00086 include_once 'inc/'.strtolower(__CLASS__).'.inc.php';
00087 $this->_aViewData['oxajax'] = $aColumns;
00088
00089 return "popups/article_extend.tpl";
00090 } elseif ( $iAoc == 2 ) {
00091
00092 include_once 'inc/article_bundle.inc.php';
00093 $this->_aViewData['oxajax'] = $aColumns;
00094
00095 return "popups/article_bundle.tpl";
00096 }
00097
00098
00099 $this->_aViewData['aMediaUrls'] = $oArticle->getMediaUrls();
00100
00101 return "article_extend.tpl";
00102 }
00103
00109 public function save()
00110 {
00111
00112 $soxId = oxConfig::getParameter( "oxid");
00113 $aParams = oxConfig::getParameter( "editval");
00114
00115 if ( !isset( $aParams['oxarticles__oxissearch'])) {
00116 $aParams['oxarticles__oxissearch'] = 0;
00117 }
00118 if ( !isset( $aParams['oxarticles__oxblfixedprice'])) {
00119 $aParams['oxarticles__oxblfixedprice'] = 0;
00120 }
00121
00122
00123
00124
00125
00126
00127 $aParams = $this->addDefaultValues( $aParams);
00128
00129 $oArticle = oxNew( "oxarticle" );
00130 $oArticle->loadInLang( $this->_iEditLang, $soxId);
00131
00132 if ( $aParams['oxarticles__oxtprice'] != $oArticle->oxarticles__oxtprice->value && $aParams['oxarticles__oxtprice'] && $aParams['oxarticles__oxtprice'] < $oArticle->oxarticles__oxprice->value) {
00133
00134 $this->_aViewData["errorsavingtprice"] = 1;
00135 }
00136
00137
00138 $oArticle->setLanguage(0);
00139 $oArticle->assign( $aParams);
00140 $oArticle->setLanguage($this->_iEditLang);
00141 $oArticle = oxUtilsFile::getInstance()->processFiles( $oArticle );
00142 $oArticle->save();
00143
00144
00145 $sMediaUrl = oxConfig::getParameter( "mediaUrl");
00146 $sMediaDesc = oxConfig::getParameter( "mediaDesc");
00147 $aMediaFile = $this->getConfig()->getUploadedFile( "mediaFile");
00148
00149 if ($sMediaUrl || $aMediaFile['name'] || $sMediaDesc) {
00150
00151 if ( !$sMediaDesc ) {
00152 oxUtilsView::getInstance()->addErrorToDisplay('EXCEPTION_NODESCRIPTIONADDED');
00153 return;
00154 }
00155
00156 if ( !$sMediaUrl && !$aMediaFile['name'] ) {
00157 oxUtilsView::getInstance()->addErrorToDisplay('EXCEPTION_NOMEDIAADDED');
00158 return;
00159 }
00160
00161 $oMediaUrl = oxNew("oxMediaUrl");
00162 $oMediaUrl->setLanguage( $this->_iEditLang );
00163 $oMediaUrl->oxmediaurls__oxisuploaded = new oxField( 0, oxField::T_RAW);
00164
00165
00166 if ($aMediaFile['name']) {
00167 try {
00168 $sMediaUrl = oxUtilsFile::getInstance()->handleUploadedFile($aMediaFile, 'out/media/');
00169 $oMediaUrl->oxmediaurls__oxisuploaded = new oxField(1, oxField::T_RAW);
00170 } catch (Exception $e) {
00171 oxUtilsView::getInstance()->addErrorToDisplay($e->getMessage());
00172 return;
00173 }
00174 }
00175
00176
00177 $oMediaUrl->oxmediaurls__oxobjectid = new oxField($soxId, oxField::T_RAW);
00178 $oMediaUrl->oxmediaurls__oxurl = new oxField($sMediaUrl, oxField::T_RAW);
00179 $oMediaUrl->oxmediaurls__oxdesc = new oxField(oxConfig::getParameter( "mediaDesc"), oxField::T_RAW);
00180 $oMediaUrl->save();
00181
00182 }
00183 }
00184
00190 public function deletemedia()
00191 {
00192 $soxId = oxConfig::getParameter( "oxid");
00193 $sMediaId = oxConfig::getParameter( "mediaid");
00194 if ($sMediaId && $soxId) {
00195 $oMediaUrl = oxNew("oxMediaUrl");
00196 $oMediaUrl->load($sMediaId);
00197 $oMediaUrl->delete();
00198 }
00199 }
00200
00209 public function addDefaultValues( $aParams)
00210 {
00211 $aParams['oxarticles__oxexturl'] = str_replace( "http://", "", $aParams['oxarticles__oxexturl']);
00212
00213 return $aParams;
00214 }
00215
00221 public function updateMedia()
00222 {
00223 $aMediaUrls = oxConfig::getParameter( 'aMediaUrls' );
00224 if ( is_array( $aMediaUrls ) ) {
00225 foreach ( $aMediaUrls as $sMediaId => $aMediaParams ) {
00226 $oMedia = oxNew("oxMediaUrl");
00227 if ( $oMedia->load( $sMediaId ) ) {
00228 $oMedia->setLanguage(0);
00229 $oMedia->assign( $aMediaParams );
00230 $oMedia->setLanguage( $this->_iEditLang );
00231 $oMedia->save();
00232 }
00233 }
00234 }
00235 }
00236
00237 }