00001 <?php
00002
00009 class Article_Main extends oxAdminDetails
00010 {
00016 protected $_sSavedId = null;
00017
00024 public function render()
00025 {
00026 $myConfig = $this->getConfig();
00027 parent::render();
00028
00029 $this->_aViewData['edit'] = $oArticle = oxNew( 'oxarticle' );
00030
00031 $soxId = oxConfig::getParameter( "oxid" );
00032 $svoxId = oxConfig::getParameter( "voxid" );
00033 $soxparentId = oxConfig::getParameter( "oxparentid" );
00034
00035
00036 if ( isset( $svoxId ) && $svoxId == "-1" && isset($soxparentId) && $soxparentId && $soxparentId != "-1") {
00037 $oParentArticle = oxNew( "oxarticle");
00038 $oParentArticle->load( $soxparentId);
00039 $this->_aViewData["parentarticle"] = $oParentArticle;
00040 $this->_aViewData["oxparentid"] = $soxparentId;
00041
00042 $this->_aViewData["oxid"] = $soxId = "-1";
00043 }
00044
00045
00046 if ( $this->_sSavedId ) {
00047 $this->_aViewData["oxid"] = $soxId = $this->_sSavedId;;
00048
00049
00050 $this->_aViewData["updatelist"] = "1";
00051 }
00052
00053 if ( $soxId && $soxId != "-1") {
00054
00055
00056 $oArticle->loadInLang( $this->_iEditLang, $soxId );
00057
00058
00059
00060 $oOtherLang = $oArticle->getAvailableInLangs();
00061 if (!isset($oOtherLang[$this->_iEditLang])) {
00062
00063 $oArticle->loadInLang( key($oOtherLang), $soxId );
00064 }
00065
00066
00067 if ( $oArticle->oxarticles__oxparentid->value) {
00068 $oParentArticle = oxNew( "oxarticle");
00069 $oParentArticle->load( $oArticle->oxarticles__oxparentid->value);
00070 $this->_aViewData["parentarticle"] = $oParentArticle;
00071 $this->_aViewData["oxparentid"] = $oArticle->oxarticles__oxparentid->value;
00072 $this->_aViewData["issubvariant"] = 1;
00073 }
00074
00075
00076 $this->_formJumpList($oArticle, $oParentArticle );
00077
00078
00079 $oArticle->tags = $oArticle->getTags();
00080
00081 $aLang = array_diff (oxLang::getInstance()->getLanguageNames(), $oOtherLang);
00082 if ( count( $aLang))
00083 $this->_aViewData["posslang"] = $aLang;
00084
00085 foreach ( $oOtherLang as $id => $language) {
00086 $oLang= new oxStdClass();
00087 $oLang->sLangDesc = $language;
00088 $oLang->selected = ($id == $this->_iEditLang);
00089 $this->_aViewData["otherlang"][$id] = clone $oLang;
00090 }
00091 }
00092
00093 $this->_aViewData["editor"] = $this->_generateTextEditor( "100%", 300, $oArticle, "oxarticles__oxlongdesc", "details.tpl.css");
00094 $this->_aViewData["blUseTimeCheck"] = $myConfig->getConfigParam( 'blUseTimeCheck' );
00095
00096 return "article_main.tpl";
00097 }
00098
00104 public function save()
00105 {
00106 $myConfig = $this->getConfig();
00107 $myUtilsCount = oxUtilsCount::getInstance();
00108
00109 $soxId = oxConfig::getParameter( "oxid" );
00110 $aParams = oxConfig::getParameter( "editval" );
00111
00112
00113
00114 if ( !isset( $aParams['oxarticles__oxactive']))
00115 $aParams['oxarticles__oxactive'] = 0;
00116
00117
00118 $aParams = $this->addDefaultValues( $aParams);
00119
00120
00121 if ($aParams['oxarticles__oxvat'] === '')
00122 $aParams['oxarticles__oxvat'] = null;
00123
00124
00125 $soxparentId = oxConfig::getParameter( "oxparentid");
00126 if ( isset( $soxparentId) && $soxparentId && $soxparentId != "-1")
00127 $aParams['oxarticles__oxparentid'] = $soxparentId;
00128 else
00129 unset( $aParams['oxarticles__oxparentid']);
00130
00131 $oArticle = oxNew( "oxarticle");
00132
00133 $oArticle->setLanguage($this->_iEditLang);
00134 if ( $soxId != "-1")
00135 $oArticle->loadInLang( $this->_iEditLang, $soxId);
00136 else {
00137 $aParams['oxarticles__oxid'] = null;
00138 $aParams['oxarticles__oxissearch'] = 1;
00139 $aParams['oxarticles__oxstockflag'] = 1;
00140
00141 $sShopID = oxSession::getVar( "actshop");
00142 $aParams['oxarticles__oxshopid'] = $sShopID;
00143 }
00144
00145
00146 if ( isset( $aParams['oxarticles__oxartnum']) && strlen($aParams['oxarticles__oxartnum']) > 0 &&
00147 $myConfig->getConfigParam( 'blWarnOnSameArtNums' ) &&
00148 $oArticle->oxarticles__oxartnum->value != $aParams['oxarticles__oxartnum']
00149 ) {
00150 $sSelect = "select oxid from ".$oArticle->getCoreTableName();
00151 $sSelect .= " where oxartnum = '".$aParams['oxarticles__oxartnum']."'";
00152 $sSelect .= " and oxid != '".$aParams['oxarticles__oxid']."'";
00153 if ($oArticle->assignRecord( $sSelect ))
00154 $this->_aViewData["errorsavingatricle"] = 1;
00155 }
00156
00157
00158 if ( isset($aParams["oxarticles__oxprice"]) && $aParams["oxarticles__oxprice"] != $oArticle->oxarticles__oxprice->value) {
00159 $this->resetCounter( "priceCatArticle", $oArticle->oxarticles__oxprice->value );
00160 }
00161
00162 $aResetIds = array();
00163 if ( $aParams['oxarticles__oxactive'] != $oArticle->oxarticles__oxactive->value) {
00164
00165 $sQ = "select oxcatnid from oxobject2category where oxobjectid = '".$oArticle->oxarticles__oxid->value."'";
00166 $rs = oxDb::getDb()->Execute($sQ);
00167 if ( $rs !== false && $rs->recordCount() > 0 ) {
00168 while (!$rs->EOF) {
00169 $this->resetCounter( "catArticle", $rs->fields[0] );
00170 $rs->moveNext();
00171 }
00172 }
00173
00174
00175 $aResetIds['vendor'][$oArticle->oxarticles__oxvendorid->value] = 1;
00176 $aResetIds['manufacturer'][$oArticle->oxarticles__oxmanufacturerid->value] = 1;
00177 }
00178
00179
00180 if ( isset( $aParams["oxarticles__oxvendorid"] ) && $aParams["oxarticles__oxvendorid"] != $oArticle->oxarticles__oxvendorid->value ) {
00181 $aResetIds['vendor'][$aParams['oxarticles__oxvendorid']] = 1;
00182 $aResetIds['vendor'][$oArticle->oxarticles__oxvendorid->value] = 1;
00183 }
00184
00185
00186 if ( isset($aParams["oxarticles__oxmanufacturerid"]) && $aParams["oxarticles__oxmanufacturerid"] != $oArticle->oxarticles__oxmanufacturerid->value) {
00187 $aResetIds['manufacturer'][$aParams['oxarticles__oxmanufacturerid']] = 1;
00188 $aResetIds['manufacturer'][$oArticle->oxarticles__oxmanufacturerid->value] = 1;
00189 }
00190
00191
00192 $this->_resetCounts( $aResetIds );
00193
00194 $oArticle->setLanguage(0);
00195
00196 $oArticle->assign( $aParams);
00197 $oArticle->setLanguage($this->_iEditLang);
00198
00199 $oArticle = oxUtilsFile::getInstance()->processFiles( $oArticle );
00200
00201 $oArticle->save();
00202
00203
00204 if ( $soxId == "-1") {
00205 $this->_sSavedId = $oArticle->getId();
00206
00207 $sFastCat = oxConfig::getParameter( "art_category");
00208
00209 if ( $sFastCat != "-1") {
00210 $oNew = oxNew( "oxbase");
00211 $oNew->init( "oxobject2category" );
00212 $oNew->oxobject2category__oxtime = new oxField(time());
00213 $oNew->oxobject2category__oxobjectid = new oxField($oArticle->getId());
00214 $oNew->oxobject2category__oxcatnid = new oxField($sFastCat);
00215
00216 $oNew->save();
00217
00218
00219 $this->resetCounter( "catArticle", $sFastCat );
00220 }
00221 }
00222
00223
00224 $this->_aViewData["updatelist"] = "1";
00225
00226
00227 $sTags = $aParams['tags'];
00228 if (!trim($sTags))
00229 $sTags = $oArticle->oxarticles__oxsearchkeys->value;
00230 $oArticle->saveTags($sTags);
00231 }
00232
00243 public function copyArticle( $sOldId = null, $sNewId = null, $sParentId = null )
00244 {
00245 $myConfig = $this->getConfig();
00246
00247 $sOldId = $sOldId?$sOldId:oxConfig::getParameter( 'oxid' );
00248 $sNewId = $sNewId?$sNewId:oxUtilsObject::getInstance()->generateUID();
00249
00250 $oArticle = oxNew( 'oxbase' );
00251 $oArticle->init( 'oxarticles' );
00252 if ( $oArticle->load( $sOldId ) ) {
00253
00254 if ( $myConfig->getConfigParam( 'blDisableDublArtOnCopy' ) ) {
00255 $oArticle->oxarticles__oxactive->setValue(0);
00256 $oArticle->oxarticles__oxactivefrom->setValue(0);
00257 $oArticle->oxarticles__oxactiveto->setValue(0);
00258 }
00259
00260
00261 if ( $sParentId ) {
00262 $oArticle->oxarticles__oxparentid->setValue($sParentId);
00263 }
00264
00265 $oArticle->setId( $sNewId );
00266 $oArticle->save();
00267
00268
00269 $this->_copyCategories( $sOldId, $sNewId );
00270
00271
00272 $this->_copyAttributes( $sOldId, $sNewId );
00273
00274
00275 $this->_copySelectlists( $sOldId, $sNewId );
00276
00277
00278 $this->_copyCrossseling( $sOldId, $sNewId );
00279
00280
00281 $this->_copyAccessoires( $sOldId, $sNewId );
00282
00283
00284 $this->_copyStaffelpreis( $sOldId, $sNewId );
00285
00286
00287 $this->_copyArtExtends( $sOldId, $sNewId);
00288
00289
00290 $aResetIds['vendor'][$oArticle->oxarticles__oxvendorid->value] = 1;
00291 $aResetIds['manufacturer'][$oArticle->oxarticles__oxmanufacturerid->value] = 1;
00292 $this->_resetCounts( $aResetIds );
00293
00294
00295 $myUtilsObject = oxUtilsObject::getInstance();
00296
00297
00298 $sQ = "select oxid from oxarticles where oxparentid = '{$sOldId}'";
00299 $rs = oxDb::getDb()->execute($sQ);
00300 if ( $rs !== false && $rs->recordCount() > 0) {
00301 while ( !$rs->EOF ) {
00302 $this->copyArticle( $rs->fields[0], $myUtilsObject->generateUID(), $sNewId );
00303 $rs->moveNext();
00304 }
00305 }
00306
00307
00308 if ( !$sParentId ) {
00309
00310 $this->_sSavedId = $oArticle->getId();
00311
00312
00313 if ( $myConfig->getConfigParam( 'blWarnOnSameArtNums' ) &&
00314 $oArticle->oxarticles__oxartnum->value && oxConfig::getParameter( 'fnc' ) == 'copyArticle' ) {
00315 $sSelect = "select oxid from ".$oArticle->getCoreTableName()."
00316 where oxartnum = '{$oArticle->oxarticles__oxartnum->value}'and oxid != '{$sNewId}'";
00317
00318 if ( $oArticle->assignRecord( $sSelect ) ) {
00319 $this->_aViewData["errorsavingatricle"] = 1;
00320 }
00321 }
00322 }
00323 }
00324 }
00325
00334 protected function _copyCategories( $sOldID, $sNewID )
00335 {
00336 $myConfig = $this->getConfig();
00337 $myUtils = oxUtils::getInstance();
00338 $oActShop = $myConfig->getActiveShop();
00339 $myUtilsCount = oxUtilsCount::getInstance();
00340 $myUtilsObject = oxUtilsObject::getInstance();
00341 $oDb = oxDb::getDb();
00342
00343 $sO2CView = getViewName('oxobject2category');
00344 $sQ = "select oxcatnid from $sO2CView where oxobjectid = '$sOldID'";
00345 $rs = $oDb->execute($sQ);
00346 if ($rs !== false && $rs->recordCount() > 0) {
00347 while (!$rs->EOF) {
00348 $sUID = $myUtilsObject->generateUID();
00349 $sCatID = $rs->fields[0];
00350
00351 $oDb->execute("insert into oxobject2category (oxid, oxobjectid, oxcatnid) VALUES ('$sUID', '$sNewID', '$sCatID') ");
00352 $rs->moveNext();
00353
00354
00355 $this->resetCounter( "catArticle", $sCatID );
00356 }
00357 }
00358 }
00359
00368 protected function _copyAttributes( $sOldID, $sNewID )
00369 {
00370 $myUtilsObject = oxUtilsObject::getInstance();
00371 $sQ = "select oxid from oxobject2attribute where oxobjectid = '$sOldID'";
00372 $rs = oxDb::getDb()->Execute($sQ);
00373 if ($rs !== false && $rs->recordCount() > 0) {
00374 while (!$rs->EOF) {
00375
00376 $oAttr = oxNew( "oxbase");
00377 $oAttr->init( "oxobject2attribute" );
00378 $oAttr->load( $rs->fields[0]);
00379 $oAttr->setId( $myUtilsObject->generateUID() );
00380 $oAttr->oxobject2attribute__oxobjectid->setValue($sNewID);
00381 $oAttr->save();
00382 $rs->moveNext();
00383 }
00384 }
00385 }
00386
00395 protected function _copySelectlists( $sOldID, $sNewID)
00396 {
00397 $myUtilsObject = oxUtilsObject::getInstance();
00398 $oDb = oxDb::getDb();
00399
00400 $sQ = "select oxselnid from oxobject2selectlist where oxobjectid = '$sOldID'";
00401 $rs = $oDb->Execute($sQ);
00402
00403 if ($rs !== false && $rs->recordCount() > 0) {
00404 while (!$rs->EOF) {
00405 $sUID = $myUtilsObject->generateUID();
00406 $sID = $rs->fields[0];
00407 $oDb->Execute("insert into oxobject2selectlist (oxid, oxobjectid, oxselnid) VALUES ('$sUID', '$sNewID', '$sID') ");
00408 $rs->moveNext();
00409 }
00410 }
00411 }
00412
00421 protected function _copyCrossseling( $sOldID, $sNewID )
00422 {
00423 $myUtilsObject = oxUtilsObject::getInstance();
00424 $oDb = oxDb::getDb();
00425
00426 $sQ = "select oxobjectid from oxobject2article where oxarticlenid = '$sOldID'";
00427 $rs = $oDb->Execute($sQ);
00428 if ($rs !== false && $rs->recordCount() > 0) {
00429 while (!$rs->EOF) {
00430 $sUID = $myUtilsObject->generateUID();
00431 $sID = $rs->fields[0];
00432 $oDb->Execute("insert into oxobject2article (oxid, oxobjectid, oxarticlenid) VALUES ('$sUID', '$sID', '$sNewID') ");
00433 $rs->moveNext();
00434 }
00435 }
00436 }
00437
00446 protected function _copyAccessoires( $sOldID, $sNewID )
00447 {
00448 $myUtilsObject = oxUtilsObject::getInstance();
00449 $oDb = oxDb::getDb();
00450
00451 $sQ = "select oxobjectid from oxaccessoire2article where oxarticlenid= '$sOldID'";
00452 $rs = $oDb->Execute($sQ);
00453 if ($rs !== false && $rs->recordCount() > 0) {
00454 while (!$rs->EOF) {
00455 $sUID = $myUtilsObject->generateUID();
00456 $sID = $rs->fields[0];
00457 $oDb->Execute("insert into oxaccessoire2article (oxid, oxobjectid, oxarticlenid) VALUES ('$sUID', '$sID', '$sNewID') ");
00458 $rs->moveNext();
00459 }
00460 }
00461 }
00462
00471 protected function _copyStaffelpreis( $sOldID, $sNewID )
00472 {
00473 $myConfig = $this->getConfig();
00474 $sShopID = $myConfig->getShopID();
00475 $oPriceList = oxNew("oxlist");
00476 $oPriceList->init( "oxbase", "oxprice2article");
00477 $sQ = "select * from oxprice2article where oxartid = '$sOldID' and oxshopid = '$sShopID' and (oxamount > 0 or oxamountto > 0) order by oxamount ";
00478 $oPriceList->selectString($sQ);
00479 if ($oPriceList->count()) {
00480 foreach ($oPriceList as $oItem) {
00481 $oItem->oxprice2article__oxid->setValue($oItem->setId());
00482 $oItem->oxprice2article__oxartid->setValue($sNewID);
00483 $oItem->save();
00484 }
00485 }
00486 }
00487
00496 protected function _copyArtExtends( $sOldID, $sNewID)
00497 {
00498 $oExt = oxNew( "oxbase");
00499 $oExt->init( "oxartextends" );
00500 $oExt->load( $sOldID);
00501 $oExt->setId( $sNewID );
00502 $oExt->save();
00503 }
00504
00505
00511 public function saveinnlang()
00512 {
00513 $myConfig = $this->getConfig();
00514 $myUtilsCount = oxUtilsCount::getInstance();
00515
00516 $soxId = oxConfig::getParameter( "oxid" );
00517 $aParams = oxConfig::getParameter( "editval" );
00518
00519
00520 if ( !isset( $aParams['oxarticles__oxactive'] ) ) {
00521 $aParams['oxarticles__oxactive'] = 0;
00522 }
00523
00524
00525 $aParams = $this->addDefaultValues( $aParams);
00526
00527
00528 if ($aParams['oxarticles__oxvat'] === '')
00529 $aParams['oxarticles__oxvat'] = null;
00530
00531
00532 $soxparentId = oxConfig::getParameter( "oxparentid");
00533 if ( isset( $soxparentId) && $soxparentId && $soxparentId != "-1")
00534 $aParams['oxarticles__oxparentid'] = $soxparentId;
00535
00536 $oArticle = oxNew( "oxarticle");
00537 $oArticle->setLanguage($this->_iEditLang);
00538
00539 if ( $soxId != "-1")
00540 $oArticle->load( $soxId);
00541 else {
00542 $aParams['oxarticles__oxid'] = null;
00543
00544 $sShopID = oxSession::getVar( "actshop");
00545 $aParams['oxarticles__oxshopid'] = $sShopID;
00546 }
00547
00548
00549 if ( isset($aParams["oxarticles__oxprice"]) && $aParams["oxarticles__oxprice"] != $oArticle->oxarticles__oxprice->value) {
00550 $this->resetCounter( "priceCatArticle", $oArticle->oxarticles__oxprice->value );
00551 }
00552
00553 $aResetIds = array();
00554
00555 if ( $aParams['oxarticles__oxactive'] != $oArticle->oxarticles__oxactive->value) {
00556
00557 $sQ = "select oxcatnid from oxobject2category where oxobjectid = '".$oArticle->oxarticles__oxid->value."'";
00558 $rs = oxDb::getDb()->Execute($sQ);
00559 if ($rs !== false && $rs->recordCount() > 0)
00560 while (!$rs->EOF) {
00561 $this->resetCounter( "catArticle", $rs->fields[0] );
00562 $rs->moveNext();
00563 }
00564
00565 $aResetIds['vendor'][$oArticle->oxarticles__oxvendorid->value] = 1;
00566 $aResetIds['manufacturer'][$oArticle->oxarticles__oxmanufacturerid->value] = 1;
00567 }
00568
00569
00570 if ( isset($aParams['oxarticles__oxvendorid']) && $aParams['oxarticles__oxvendorid'] != $oArticle->oxarticles__oxvendorid->value) {
00571 $aResetIds['vendor'][$aParams['oxarticles__oxvendorid']] = 1;
00572 $aResetIds['vendor'][$oArticle->oxarticles__oxvendorid->value] = 1;
00573 }
00574
00575
00576 if ( isset($aParams['oxarticles__oxmanufacturerid']) && $aParams['oxarticles__oxmanufacturerid'] != $oArticle->oxarticles__oxmanufacturerid->value ) {
00577 $aResetIds['manufacturer'][$aParams['oxarticles__oxmanufacturerid']] = 1;
00578 $aResetIds['manufacturer'][$oArticle->oxarticles__oxmanufacturerid->value] = 1;
00579 }
00580
00581 $this->_resetCounts( $aResetIds );
00582
00583
00584
00585
00586 $oArticle->setLanguage(0);
00587 $oArticle->assign( $aParams);
00588
00589
00590 $sNewLanguage = oxConfig::getParameter( "new_lang");
00591 $oArticle->setLanguage( $sNewLanguage);
00592 $oArticle->save();
00593
00594
00595 oxSession::setVar( "new_lang", $sNewLanguage );
00596
00597
00598 if ( $soxId == "-1" )
00599 $this->_sSavedId = $oArticle->getId();
00600 }
00601
00610 public function addDefaultValues( $aParams )
00611 {
00612 return $aParams;
00613 }
00614
00623 protected function _formJumpList( $oArticle, $oParentArticle )
00624 {
00625 $aJumpList = array();
00626
00627 if ( isset( $oParentArticle ) ) {
00628 $aJumpList[] = array( $oParentArticle->oxarticles__oxid->value, $this->_getTitle( $oParentArticle ) );
00629 $oParentVariants = $oParentArticle->getAdminVariants( oxConfig::getParameter( "editlanguage" ) );
00630 if ( $oParentVariants->count()) {
00631 foreach ( $oParentVariants as $oVar) {
00632 $aJumpList[] = array( $oVar->oxarticles__oxid->value, " - ".$this->_getTitle( $oVar ) );
00633 if ( $oVar->oxarticles__oxid->value == $oArticle->oxarticles__oxid->value ) {
00634 $oVariants = $oArticle->getAdminVariants(oxConfig::getParameter( "editlanguage"));
00635 if ( $oVariants->count() ) {
00636 foreach ( $oVariants as $oVVar) {
00637 $aJumpList[] = array( $oVVar->oxarticles__oxid->value, " -- ".$this->_getTitle( $oVVar));
00638 }
00639 }
00640 }
00641 }
00642 }
00643 } else {
00644 $aJumpList[] = array( $oArticle->oxarticles__oxid->value, $this->_getTitle( $oArticle));
00645
00646 $oVariants = $oArticle->getAdminVariants(oxConfig::getParameter( "editlanguage"));
00647 if ( $oVariants && $oVariants->count())
00648 foreach ($oVariants as $oVar) {
00649 $aJumpList[] = array( $oVar->oxarticles__oxid->value, " - ".$this->_getTitle( $oVar));
00650 }
00651 }
00652 if ( count($aJumpList) > 1)
00653 $this->_aViewData["thisvariantlist"] = $aJumpList;
00654 }
00655
00663 protected function _getTitle( $oObj )
00664 {
00665 $sTitle = $oObj->oxarticles__oxtitle->value;
00666 if ( !strlen( $sTitle ) ) {
00667 $sTitle = $oObj->oxarticles__oxvarselect->value;
00668 }
00669
00670 return $sTitle;
00671 }
00672
00678 public function getCategoryList()
00679 {
00680 $oCatTree = oxNew( "oxCategoryList");
00681 $oCatTree->buildList( $this->getConfig()->getConfigParam( 'bl_perfLoadCatTree' ) );
00682 return $oCatTree;
00683 }
00684
00690 public function getVendorList()
00691 {
00692 $oVendorlist = oxNew( "oxvendorlist" );
00693 $oVendorlist->loadVendorList();
00694
00695 return $oVendorlist;
00696 }
00697
00703 public function getManufacturerList()
00704 {
00705 $oManufacturerList = oxNew( "oxmanufacturerlist" );
00706 $oManufacturerList->loadManufacturerList();
00707
00708 return $oManufacturerList;
00709 }
00710 }