00001 <?php
00002
00009 class Article_Main extends oxAdminDetails
00010 {
00017 public function render()
00018 {
00019 $myConfig = $this->getConfig();
00020 parent::render();
00021
00022 $this->_aViewData['edit'] = $oArticle = oxNew( 'oxarticle' );
00023
00024 $soxId = $this->getEditObjectId();
00025 $svoxId = oxConfig::getParameter( "voxid" );
00026 $soxparentId = oxConfig::getParameter( "oxparentid" );
00027
00028
00029 if ( isset( $svoxId ) && $svoxId == "-1" && isset($soxparentId) && $soxparentId && $soxparentId != "-1") {
00030 $oParentArticle = oxNew( "oxarticle");
00031 $oParentArticle->load( $soxparentId);
00032 $this->_aViewData["parentarticle"] = $oParentArticle;
00033 $this->_aViewData["oxparentid"] = $soxparentId;
00034
00035 $this->_aViewData["oxid"] = $soxId = "-1";
00036 }
00037
00038 if ( $soxId && $soxId != "-1") {
00039
00040
00041 $oArticle->loadInLang( $this->_iEditLang, $soxId );
00042
00043
00044
00045 $oOtherLang = $oArticle->getAvailableInLangs();
00046 if (!isset($oOtherLang[$this->_iEditLang])) {
00047
00048 $oArticle->loadInLang( key($oOtherLang), $soxId );
00049 }
00050
00051
00052 if ( $oArticle->oxarticles__oxparentid->value) {
00053 $oParentArticle = oxNew( "oxarticle");
00054 $oParentArticle->load( $oArticle->oxarticles__oxparentid->value);
00055 $this->_aViewData["parentarticle"] = $oParentArticle;
00056 $this->_aViewData["oxparentid"] = $oArticle->oxarticles__oxparentid->value;
00057 $this->_aViewData["issubvariant"] = 1;
00058 }
00059
00060
00061 $this->_formJumpList($oArticle, $oParentArticle );
00062
00063
00064 $oTagCloud = oxNew("oxTagCloud");
00065 $oArticle->tags = $oTagCloud->getTagTitle($oArticle->getTags());
00066
00067 $aLang = array_diff (oxLang::getInstance()->getLanguageNames(), $oOtherLang);
00068 if ( count( $aLang))
00069 $this->_aViewData["posslang"] = $aLang;
00070
00071 foreach ( $oOtherLang as $id => $language) {
00072 $oLang= new oxStdClass();
00073 $oLang->sLangDesc = $language;
00074 $oLang->selected = ($id == $this->_iEditLang);
00075 $this->_aViewData["otherlang"][$id] = clone $oLang;
00076 }
00077 }
00078
00079 $this->_aViewData["editor"] = $this->_generateTextEditor( "100%", 300, $oArticle, "oxarticles__oxlongdesc", "details.tpl.css");
00080 $this->_aViewData["blUseTimeCheck"] = $myConfig->getConfigParam( 'blUseTimeCheck' );
00081
00082 return "article_main.tpl";
00083 }
00084
00093 protected function _getEditValue( $oObject, $sField )
00094 {
00095 $sEditObjectValue = '';
00096 if ( $oObject ) {
00097 $oDescField = $oObject->getArticleLongDesc();
00098 $sEditObjectValue = $this->_processEditValue( $oDescField->getRawValue() );
00099 $oDescField = new oxField( $sEditObjectValue, oxField::T_RAW );
00100 }
00101
00102 return $sEditObjectValue;
00103 }
00104
00110 public function save()
00111 {
00112 parent::save();
00113
00114 $myConfig = $this->getConfig();
00115 $soxId = $this->getEditObjectId();
00116 $aParams = oxConfig::getParameter( "editval" );
00117
00118
00119 if ( !isset( $aParams['oxarticles__oxactive'] ) ) {
00120 $aParams['oxarticles__oxactive'] = 0;
00121 }
00122
00123
00124 $aParams = $this->addDefaultValues( $aParams );
00125
00126
00127 if ($aParams['oxarticles__oxvat'] === '') {
00128 $aParams['oxarticles__oxvat'] = null;
00129 }
00130
00131
00132 $soxparentId = oxConfig::getParameter( "oxparentid");
00133 if ( isset( $soxparentId) && $soxparentId && $soxparentId != "-1") {
00134 $aParams['oxarticles__oxparentid'] = $soxparentId;
00135 } else {
00136 unset( $aParams['oxarticles__oxparentid']);
00137 }
00138
00139 $oArticle = oxNew( "oxarticle");
00140 $oArticle->setLanguage($this->_iEditLang);
00141
00142 if ( $soxId != "-1") {
00143 $oArticle->loadInLang( $this->_iEditLang, $soxId);
00144 } else {
00145 $aParams['oxarticles__oxid'] = null;
00146 $aParams['oxarticles__oxissearch'] = 1;
00147 $aParams['oxarticles__oxstockflag'] = 1;
00148
00149 $aParams['oxarticles__oxshopid'] = oxSession::getVar( "actshop");
00150 }
00151
00152
00153 if ( isset( $aParams['oxarticles__oxartnum']) && strlen($aParams['oxarticles__oxartnum']) > 0 &&
00154 $myConfig->getConfigParam( 'blWarnOnSameArtNums' ) &&
00155 $oArticle->oxarticles__oxartnum->value != $aParams['oxarticles__oxartnum']
00156 ) {
00157 $sSelect = "select oxid from ".getViewName( 'oxarticles' );
00158 $sSelect .= " where oxartnum = '".$aParams['oxarticles__oxartnum']."'";
00159 $sSelect .= " and oxid != '".$aParams['oxarticles__oxid']."'";
00160 if ($oArticle->assignRecord( $sSelect ))
00161 $this->_aViewData["errorsavingatricle"] = 1;
00162 }
00163
00164
00165 if ( isset($aParams["oxarticles__oxprice"]) && $aParams["oxarticles__oxprice"] != $oArticle->oxarticles__oxprice->value) {
00166 $this->resetCounter( "priceCatArticle", $oArticle->oxarticles__oxprice->value );
00167 }
00168
00169 $aResetIds = array();
00170 if ( $aParams['oxarticles__oxactive'] != $oArticle->oxarticles__oxactive->value) {
00171 $oDb = oxDb::getDb();
00172
00173 $sQ = "select oxcatnid from oxobject2category where oxobjectid = ".$oDb->quote( $oArticle->oxarticles__oxid->value );
00174 $oRs = $oDb->execute($sQ);
00175 if ( $oRs !== false && $oRs->recordCount() > 0 ) {
00176 while (!$oRs->EOF) {
00177 $this->resetCounter( "catArticle", $oRs->fields[0] );
00178 $oRs->moveNext();
00179 }
00180 }
00181
00182
00183 $aResetIds['vendor'][$oArticle->oxarticles__oxvendorid->value] = 1;
00184 $aResetIds['manufacturer'][$oArticle->oxarticles__oxmanufacturerid->value] = 1;
00185 }
00186
00187
00188 if ( isset($aParams['oxarticles__oxvendorid']) && $aParams['oxarticles__oxvendorid'] != $oArticle->oxarticles__oxvendorid->value) {
00189 $aResetIds['vendor'][$aParams['oxarticles__oxvendorid']] = 1;
00190 $aResetIds['vendor'][$oArticle->oxarticles__oxvendorid->value] = 1;
00191 }
00192
00193
00194 if ( isset($aParams['oxarticles__oxmanufacturerid']) && $aParams['oxarticles__oxmanufacturerid'] != $oArticle->oxarticles__oxmanufacturerid->value ) {
00195 $aResetIds['manufacturer'][$aParams['oxarticles__oxmanufacturerid']] = 1;
00196 $aResetIds['manufacturer'][$oArticle->oxarticles__oxmanufacturerid->value] = 1;
00197 }
00198
00199
00200 $this->_resetCounts( $aResetIds );
00201
00202 $oArticle->setLanguage(0);
00203
00204
00205 $aParams['oxarticles__oxtitle'] = trim( $aParams['oxarticles__oxtitle'] );
00206
00207 $oArticle->assign( $aParams );
00208 $oArticle->setArticleLongDesc( $this->_processLongDesc( $aParams['oxarticles__oxlongdesc'] ) );
00209 $oArticle->setLanguage($this->_iEditLang);
00210 $oArticle = oxUtilsFile::getInstance()->processFiles( $oArticle );
00211 $oArticle->save();
00212
00213
00214 if ( $soxId == "-1") {
00215 $sFastCat = oxConfig::getParameter( "art_category");
00216 if ( $sFastCat != "-1") {
00217 $this->addToCategory($sFastCat, $oArticle->getId());
00218 }
00219 }
00220
00221
00222 $sTags = $aParams['tags'];
00223 if (!trim($sTags)) {
00224 $sTags = $oArticle->oxarticles__oxsearchkeys->value;
00225 }
00226 $oArticle->saveTags($sTags);
00227 $this->setEditObjectId( $oArticle->getId() );
00228 }
00229
00237 protected function _processLongDesc( $sValue )
00238 {
00239
00240
00241 $sValue = str_replace( '&nbsp;', ' ', $sValue );
00242 $sValue = str_replace( '&', '&', $sValue );
00243 $sValue = str_replace( '"', '"', $sValue );
00244 $sValue = str_replace( '&lang=', '&lang=', $sValue);
00245
00246 return $sValue;
00247 }
00248
00257 public function addToCategory($sCatID, $sOXID)
00258 {
00259 $myConfig = $this->getConfig();
00260
00261 $oNew = oxNew( "oxbase");
00262 $oNew->init( "oxobject2category" );
00263 $oNew->oxobject2category__oxtime = new oxField( 0 );
00264 $oNew->oxobject2category__oxobjectid = new oxField( $sOXID );
00265 $oNew->oxobject2category__oxcatnid = new oxField( $sCatID );
00266
00267 $oNew->save();
00268
00269
00270 $this->resetCounter( "catArticle", $sCatID );
00271 }
00272
00282 public function copyArticle( $sOldId = null, $sNewId = null, $sParentId = null )
00283 {
00284 $myConfig = $this->getConfig();
00285
00286 $sOldId = $sOldId ? $sOldId : $this->getEditObjectId();
00287 $sNewId = $sNewId ? $sNewId : oxUtilsObject::getInstance()->generateUID();
00288
00289 $oArticle = oxNew( 'oxbase' );
00290 $oArticle->init( 'oxarticles' );
00291 if ( $oArticle->load( $sOldId ) ) {
00292
00293 if ( $myConfig->getConfigParam( 'blDisableDublArtOnCopy' ) ) {
00294 $oArticle->oxarticles__oxactive->setValue( 0 );
00295 $oArticle->oxarticles__oxactivefrom->setValue( 0 );
00296 $oArticle->oxarticles__oxactiveto->setValue( 0 );
00297 }
00298
00299
00300 if ( $sParentId ) {
00301 $oArticle->oxarticles__oxparentid->setValue( $sParentId );
00302 }
00303
00304
00305 $iNow = date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime() );
00306 $oArticle->oxarticles__oxinsert = new oxField( $iNow );
00307 $oArticle->oxarticles__oxtimestamp = new oxField( $iNow );
00308
00309
00310 $oArticle->oxarticles__oxrating = new oxField( 0 );
00311 $oArticle->oxarticles__oxratingcnt = new oxField( 0 );
00312
00313 $oArticle->setId( $sNewId );
00314 $oArticle->save();
00315
00316
00317 $this->_copyCategories( $sOldId, $sNewId );
00318
00319
00320 $this->_copyAttributes( $sOldId, $sNewId );
00321
00322
00323 $this->_copySelectlists( $sOldId, $sNewId );
00324
00325
00326 $this->_copyCrossseling( $sOldId, $sNewId );
00327
00328
00329 $this->_copyAccessoires( $sOldId, $sNewId );
00330
00331
00332 $this->_copyStaffelpreis( $sOldId, $sNewId );
00333
00334
00335 $this->_copyArtExtends( $sOldId, $sNewId);
00336
00337
00338 $aResetIds['vendor'][$oArticle->oxarticles__oxvendorid->value] = 1;
00339 $aResetIds['manufacturer'][$oArticle->oxarticles__oxmanufacturerid->value] = 1;
00340 $this->_resetCounts( $aResetIds );
00341
00342
00343 $myUtilsObject = oxUtilsObject::getInstance();
00344 $oDb = oxDb::getDb();
00345
00346
00347 $sQ = "select oxid from oxarticles where oxparentid = ".$oDb->quote( $sOldId );
00348 $oRs = $oDb->execute( $sQ );
00349 if ( $oRs !== false && $oRs->recordCount() > 0) {
00350 while ( !$oRs->EOF ) {
00351 $this->copyArticle( $oRs->fields[0], $myUtilsObject->generateUid(), $sNewId );
00352 $oRs->moveNext();
00353 }
00354 }
00355
00356
00357 if ( !$sParentId ) {
00358
00359 $this->setEditObjectId( $oArticle->getId() );
00360
00361
00362 if ( $myConfig->getConfigParam( 'blWarnOnSameArtNums' ) &&
00363 $oArticle->oxarticles__oxartnum->value && oxConfig::getParameter( 'fnc' ) == 'copyArticle' ) {
00364 $sSelect = "select oxid from ".$oArticle->getCoreTableName()."
00365 where oxartnum = ".$oDb->quote( $oArticle->oxarticles__oxartnum->value )." and oxid != ".$oDb->quote( $sNewId );
00366
00367 if ( $oArticle->assignRecord( $sSelect ) ) {
00368 $this->_aViewData["errorsavingatricle"] = 1;
00369 }
00370 }
00371 }
00372 }
00373 }
00374
00383 protected function _copyCategories( $sOldId, $sNewId )
00384 {
00385 $myUtilsObject = oxUtilsObject::getInstance();
00386 $oDb = oxDb::getDb();
00387
00388
00389 $sO2CView = getViewName( 'oxobject2category' );
00390 $sQ = "select oxcatnid, oxtime from {$sO2CView} where oxobjectid = ".$oDb->quote( $sOldId );
00391 $oRs = $oDb->execute( $sQ );
00392 if ( $oRs !== false && $oRs->recordCount() > 0 ) {
00393 while ( !$oRs->EOF ) {
00394 $sUid = $myUtilsObject->generateUid();
00395 $sCatId = $oRs->fields[0];
00396 $sTime = $oRs->fields[1];
00397
00398
00399 $oDb->execute("insert into oxobject2category (oxid, oxobjectid, oxcatnid, oxtime) VALUES (".$oDb->quote( $sUid ).", ".$oDb->quote( $sNewId ).", ".$oDb->quote( $sCatId ).", ".$oDb->quote( $sTime ).") ");
00400
00401 $oRs->moveNext();
00402
00403
00404 $this->resetCounter( "catArticle", $sCatId );
00405 }
00406 }
00407 }
00408
00417 protected function _copyAttributes( $sOldId, $sNewId )
00418 {
00419 $myUtilsObject = oxUtilsObject::getInstance();
00420 $oDb = oxDb::getDb();
00421
00422 $sQ = "select oxid from oxobject2attribute where oxobjectid = ".$oDb->quote( $sOldId );
00423 $oRs = $oDb->execute($sQ);
00424 if ( $oRs !== false && $oRs->recordCount() > 0 ) {
00425 while ( !$oRs->EOF ) {
00426
00427 $oAttr = oxNew( "oxbase" );
00428 $oAttr->init( "oxobject2attribute" );
00429 $oAttr->load( $oRs->fields[0] );
00430 $oAttr->setId( $myUtilsObject->generateUID() );
00431 $oAttr->oxobject2attribute__oxobjectid->setValue( $sNewId );
00432 $oAttr->save();
00433 $oRs->moveNext();
00434 }
00435 }
00436 }
00437
00446 protected function _copySelectlists( $sOldId, $sNewId )
00447 {
00448 $myUtilsObject = oxUtilsObject::getInstance();
00449 $oDb = oxDb::getDb();
00450
00451 $sQ = "select oxselnid from oxobject2selectlist where oxobjectid = ".$oDb->quote( $sOldId );
00452 $oRs = $oDb->execute( $sQ );
00453 if ( $oRs !== false && $oRs->recordCount() > 0 ) {
00454 while ( !$oRs->EOF ) {
00455 $sUid = $myUtilsObject->generateUID();
00456 $sId = $oRs->fields[0];
00457 $oDb->execute( "insert into oxobject2selectlist (oxid, oxobjectid, oxselnid) VALUES (".$oDb->quote( $sUid ).", ".$oDb->quote( $sNewId ).", ".$oDb->quote( $sId ).") " );
00458 $oRs->moveNext();
00459 }
00460 }
00461 }
00462
00471 protected function _copyCrossseling( $sOldId, $sNewId )
00472 {
00473 $myUtilsObject = oxUtilsObject::getInstance();
00474 $oDb = oxDb::getDb();
00475
00476 $sQ = "select oxobjectid from oxobject2article where oxarticlenid = ".$oDb->quote( $sOldId );
00477 $oRs = $oDb->execute( $sQ );
00478 if ( $oRs !== false && $oRs->recordCount() > 0 ) {
00479 while ( !$oRs->EOF ) {
00480 $sUid = $myUtilsObject->generateUID();
00481 $sId = $oRs->fields[0];
00482 $oDb->execute("insert into oxobject2article (oxid, oxobjectid, oxarticlenid) VALUES (".$oDb->quote( $sUid ).", ".$oDb->quote( $sId ).", ".$oDb->quote( $sNewId )." ) ");
00483 $oRs->moveNext();
00484 }
00485 }
00486 }
00487
00496 protected function _copyAccessoires( $sOldId, $sNewId )
00497 {
00498 $myUtilsObject = oxUtilsObject::getInstance();
00499 $oDb = oxDb::getDb();
00500
00501 $sQ = "select oxobjectid from oxaccessoire2article where oxarticlenid= ".$oDb->quote( $sOldId );
00502 $oRs = $oDb->execute( $sQ );
00503 if ( $oRs !== false && $oRs->recordCount() > 0 ) {
00504 while ( !$oRs->EOF ) {
00505 $sUId = $myUtilsObject->generateUid();
00506 $sId = $oRs->fields[0];
00507 $oDb->execute( "insert into oxaccessoire2article (oxid, oxobjectid, oxarticlenid) VALUES (".$oDb->quote( $sUId ).", ".$oDb->quote( $sId ).", ".$oDb->quote( $sNewId ).") " );
00508 $oRs->moveNext();
00509 }
00510 }
00511 }
00512
00521 protected function _copyStaffelpreis( $sOldId, $sNewId )
00522 {
00523 $sShopId = $this->getConfig()->getShopId();
00524 $oPriceList = oxNew( "oxlist" );
00525 $oPriceList->init( "oxbase", "oxprice2article" );
00526 $sQ = "select * from oxprice2article where oxartid = '$sOldId' and oxshopid = '$sShopId' and (oxamount > 0 or oxamountto > 0) order by oxamount ";
00527 $oPriceList->selectString( $sQ );
00528 if ( $oPriceList->count() ) {
00529 foreach ( $oPriceList as $oItem ) {
00530 $oItem->oxprice2article__oxid->setValue( $oItem->setId() );
00531 $oItem->oxprice2article__oxartid->setValue( $sNewId );
00532 $oItem->save();
00533 }
00534 }
00535 }
00536
00545 protected function _copyArtExtends( $sOldId, $sNewId)
00546 {
00547 $oExt = oxNew( "oxbase");
00548 $oExt->init( "oxartextends" );
00549 $oExt->load( $sOldId );
00550 $oExt->setId( $sNewId );
00551 $oExt->save();
00552 }
00553
00554
00560 public function saveinnlang()
00561 {
00562 $this->save();
00563 }
00564
00573 public function addDefaultValues( $aParams )
00574 {
00575 return $aParams;
00576 }
00577
00586 protected function _formJumpList( $oArticle, $oParentArticle )
00587 {
00588 $aJumpList = array();
00589
00590 if ( isset( $oParentArticle ) ) {
00591 $aJumpList[] = array( $oParentArticle->oxarticles__oxid->value, $this->_getTitle( $oParentArticle ) );
00592 $oParentVariants = $oParentArticle->getAdminVariants( oxConfig::getParameter( "editlanguage" ) );
00593 if ( $oParentVariants->count()) {
00594 foreach ( $oParentVariants as $oVar) {
00595 $aJumpList[] = array( $oVar->oxarticles__oxid->value, " - ".$this->_getTitle( $oVar ) );
00596 if ( $oVar->oxarticles__oxid->value == $oArticle->oxarticles__oxid->value ) {
00597 $oVariants = $oArticle->getAdminVariants(oxConfig::getParameter( "editlanguage"));
00598 if ( $oVariants->count() ) {
00599 foreach ( $oVariants as $oVVar) {
00600 $aJumpList[] = array( $oVVar->oxarticles__oxid->value, " -- ".$this->_getTitle( $oVVar));
00601 }
00602 }
00603 }
00604 }
00605 }
00606 } else {
00607 $aJumpList[] = array( $oArticle->oxarticles__oxid->value, $this->_getTitle( $oArticle));
00608
00609 $oVariants = $oArticle->getAdminVariants(oxConfig::getParameter( "editlanguage"));
00610 if ( $oVariants && $oVariants->count())
00611 foreach ($oVariants as $oVar) {
00612 $aJumpList[] = array( $oVar->oxarticles__oxid->value, " - ".$this->_getTitle( $oVar));
00613 }
00614 }
00615 if ( count($aJumpList) > 1)
00616 $this->_aViewData["thisvariantlist"] = $aJumpList;
00617 }
00618
00626 protected function _getTitle( $oObj )
00627 {
00628 $sTitle = $oObj->oxarticles__oxtitle->value;
00629 if ( !strlen( $sTitle ) ) {
00630 $sTitle = $oObj->oxarticles__oxvarselect->value;
00631 }
00632
00633 return $sTitle;
00634 }
00635
00641 public function getCategoryList()
00642 {
00643 $oCatTree = oxNew( "oxCategoryList");
00644 $oCatTree->buildList( $this->getConfig()->getConfigParam( 'bl_perfLoadCatTree' ) );
00645 return $oCatTree;
00646 }
00647
00653 public function getVendorList()
00654 {
00655 $oVendorlist = oxNew( "oxvendorlist" );
00656 $oVendorlist->loadVendorList();
00657
00658 return $oVendorlist;
00659 }
00660
00666 public function getManufacturerList()
00667 {
00668 $oManufacturerList = oxNew( "oxmanufacturerlist" );
00669 $oManufacturerList->loadManufacturerList();
00670
00671 return $oManufacturerList;
00672 }
00673 }