00001 <?php
00002
00010 class Article_Main extends oxAdminDetails
00011 {
00017 protected $_sSavedId = null;
00018
00025 public function render()
00026 {
00027 $myConfig = $this->getConfig();
00028 parent::render();
00029
00030 $this->_aViewData['edit'] = $oArticle = oxNew( 'oxarticle' );
00031
00032 $soxId = oxConfig::getParameter( "oxid" );
00033 $soxparentId = oxConfig::getParameter( "oxparentid" );
00034 $svoxId = oxConfig::getParameter( "voxid" );
00035
00036
00037 if ( isset( $svoxId ) && $svoxId == "-1" && isset($soxparentId) && $soxparentId && $soxparentId != "-1") {
00038 $oParentArticle = oxNew( "oxarticle");
00039 $oParentArticle->load( $soxparentId);
00040 $this->_aViewData["parentarticle"] = $oParentArticle;
00041 $this->_aViewData["oxparentid"] = $soxparentId;
00042
00043 $this->_aViewData["oxid"] = $soxId = "-1";
00044 }
00045
00046
00047 if ( $this->_sSavedId ) {
00048 $soxId = $this->_sSavedId;
00049 $this->_aViewData["oxid"] = $soxId;
00050
00051
00052 $this->_aViewData["updatelist"] = "1";
00053 }
00054
00055 if ( isset( $soxId) && $soxId && $soxId != "-1") {
00056
00057 $oArticle->loadInLang( $this->_iEditLang, $soxId );
00058
00059
00060
00061 $oOtherLang = $oArticle->getAvailableInLangs();
00062 if (!isset($oOtherLang[$this->_iEditLang])) {
00063
00064 $oArticle->loadInLang( key($oOtherLang), $soxId );
00065 }
00066
00067
00068 if ( $oArticle->oxarticles__oxparentid->value) {
00069 $oParentArticle = oxNew( "oxarticle");
00070 $oParentArticle->load( $oArticle->oxarticles__oxparentid->value);
00071 $this->_aViewData["parentarticle"] = $oParentArticle;
00072 $this->_aViewData["oxparentid"] = $oArticle->oxarticles__oxparentid->value;
00073 $this->_aViewData["issubvariant"] = 1;
00074 }
00075
00076
00077 $this->_formJumpList($oArticle, $oParentArticle);
00078
00079
00080 $oArticle->tags = $oArticle->getTags();
00081
00082 $aLang = array_diff (oxLang::getInstance()->getLanguageNames(), $oOtherLang);
00083 if ( count( $aLang))
00084 $this->_aViewData["posslang"] = $aLang;
00085
00086 foreach ( $oOtherLang as $id => $language) {
00087 $oLang= new oxStdClass();
00088 $oLang->sLangDesc = $language;
00089 $oLang->selected = ($id == $this->_iEditLang);
00090 $this->_aViewData["otherlang"][$id] = clone $oLang;
00091 }
00092
00093 } else {
00094
00095
00096
00097 $oCatTree = oxNew( "oxCategoryList");
00098 $oCatTree->buildList($myConfig->getConfigParam( 'bl_perfLoadCatTree' ) );
00099 $this->_aViewData["cattree"] = $oCatTree;
00100 }
00101
00102
00103 $oVendorlist = oxNew( "oxvendorlist" );
00104 $oVendorlist->loadVendorList();
00105 $this->_aViewData['aVendorlist'] = & $oVendorlist;
00106
00107 $this->_aViewData["editor"] = $this->_generateTextEditor( "100%", 300, $oArticle, "oxarticles__oxlongdesc", "details.tpl.css");
00108 $this->_aViewData["blUseTimeCheck"] = $myConfig->getConfigParam( 'blUseTimeCheck' );
00109
00110 return "article_main.tpl";
00111 }
00112
00118 public function save()
00119 {
00120 $myConfig = $this->getConfig();
00121
00122 $soxId = oxConfig::getParameter( "oxid");
00123 $aParams = oxConfig::getParameter( "editval");
00124
00125
00126
00127 if ( !isset( $aParams['oxarticles__oxactive']))
00128 $aParams['oxarticles__oxactive'] = 0;
00129
00130
00131 $aParams = $this->addDefaultValues( $aParams);
00132
00133
00134 if ($aParams['oxarticles__oxvat'] === '')
00135 $aParams['oxarticles__oxvat'] = null;
00136
00137
00138 $soxparentId = oxConfig::getParameter( "oxparentid");
00139 if ( isset( $soxparentId) && $soxparentId && $soxparentId != "-1")
00140 $aParams['oxarticles__oxparentid'] = $soxparentId;
00141 else
00142 unset( $aParams['oxarticles__oxparentid']);
00143
00144 $oArticle = oxNew( "oxarticle");
00145
00146 $oArticle->setLanguage($this->_iEditLang);
00147 if ( $soxId != "-1")
00148 $oArticle->loadInLang( $this->_iEditLang, $soxId);
00149 else {
00150 $aParams['oxarticles__oxid'] = null;
00151 $aParams['oxarticles__oxissearch'] = 1;
00152 $aParams['oxarticles__oxstockflag'] = 1;
00153
00154 $sShopID = oxSession::getVar( "actshop");
00155 $aParams['oxarticles__oxshopid'] = $sShopID;
00156 }
00157
00158
00159 if ( isset( $aParams['oxarticles__oxartnum']) && strlen($aParams['oxarticles__oxartnum']) > 0 &&
00160 $myConfig->getConfigParam( 'blWarnOnSameArtNums' ) &&
00161 $oArticle->oxarticles__oxartnum->value != $aParams['oxarticles__oxartnum']
00162 ) {
00163 $sSelect = "select oxid from ".$oArticle->getCoreTableName();
00164 $sSelect .= " where oxartnum = '".$aParams['oxarticles__oxartnum']."'";
00165 $sSelect .= " and oxid != '".$aParams['oxarticles__oxid']."'";
00166 if ($oArticle->assignRecord( $sSelect ))
00167 $this->_aViewData["errorsavingatricle"] = 1;
00168 }
00169
00170
00171 if ( isset($aParams["oxarticles__oxprice"]) && $aParams["oxarticles__oxprice"] != $oArticle->oxarticles__oxprice->value) {
00172 oxUtilsCount::getInstance()->resetPriceCatArticleCount($oArticle->oxarticles__oxprice->value);
00173 }
00174
00175 if ( $aParams['oxarticles__oxactive'] != $oArticle->oxarticles__oxactive->value) {
00176
00177 $sQ = "select oxcatnid from oxobject2category where oxobjectid = '".$oArticle->oxarticles__oxid->value."'";
00178 $rs = oxDb::getDb()->Execute($sQ);
00179 if ($rs !== false && $rs->recordCount() > 0)
00180 while (!$rs->EOF) {
00181 oxUtilsCount::getInstance()->resetCatArticleCount($rs->fields[0]);
00182 $rs->moveNext();
00183 }
00184
00185 if ( $oArticle->oxarticles__oxvendorid->value) {
00186 oxUtilsCount::getInstance()->resetVendorArticleCount($oArticle->oxarticles__oxvendorid->value);
00187 }
00188 }
00189 if ( isset($aParams["oxarticles__oxvendorid"]) && $aParams["oxarticles__oxvendorid"] != $oArticle->oxarticles__oxvendorid->value) {
00190
00191 if ( $aParams["oxarticles__oxvendorid"]) {
00192 oxUtilsCount::getInstance()->resetVendorArticleCount($aParams["oxarticles__oxvendorid"]);
00193 }
00194
00195 if ( $oArticle->oxarticles__oxvendorid->value) {
00196 oxUtilsCount::getInstance()->resetVendorArticleCount($oArticle->oxarticles__oxvendorid->value);
00197 }
00198 }
00199
00200
00201
00202 $oArticle->setLanguage(0);
00203
00204 $oArticle->assign( $aParams);
00205 $oArticle->setLanguage($this->_iEditLang);
00206
00207 $oArticle = oxUtilsFile::getInstance()->processFiles( $oArticle );
00208
00209 $oArticle->save();
00210
00211
00212 if ( $soxId == "-1") {
00213 $this->_sSavedId = $oArticle->getId();
00214
00215 $sFastCat = oxConfig::getParameter( "art_category");
00216
00217 if ( $sFastCat != "-1") {
00218 $oNew = oxNew( "oxbase");
00219 $oNew->init( "oxobject2category" );
00220 $oNew->oxobject2category__oxtime = new oxField(time());
00221 $oNew->oxobject2category__oxobjectid = new oxField($oArticle->getId());
00222 $oNew->oxobject2category__oxcatnid = new oxField($sFastCat);
00223
00224 $oNew->save();
00225
00226
00227 oxUtilsCount::getInstance()->resetCatArticleCount($sFastCat);
00228 }
00229 }
00230
00231
00232 $this->_aViewData["updatelist"] = "1";
00233
00234
00235 $sTags = $aParams['tags'];
00236 if (!trim($sTags))
00237 $sTags = $oArticle->oxarticles__oxsearchkeys->value;
00238 $oArticle->saveTags($sTags);
00239
00240 return $this->autosave();
00241 }
00242
00253 public function copyArticle( $sOldId = null, $sNewId = null, $sParentId = null )
00254 {
00255 $myConfig = $this->getConfig();
00256
00257 $sOldId = $sOldId?$sOldId:oxConfig::getParameter( 'oxid' );
00258 $sNewId = $sNewId?$sNewId:oxUtilsObject::getInstance()->generateUID();
00259
00260 $oArticle = oxNew( 'oxbase' );
00261 $oArticle->init( 'oxarticles' );
00262 if ( $oArticle->load( $sOldId ) ) {
00263
00264 if ( $myConfig->getConfigParam( 'blDisableDublArtOnCopy' ) ) {
00265 $oArticle->oxarticles__oxactive->setValue(0);
00266 $oArticle->oxarticles__oxactivefrom->setValue(0);
00267 $oArticle->oxarticles__oxactiveto->setValue(0);
00268 }
00269
00270
00271 if ( $sParentId ) {
00272 $oArticle->oxarticles__oxparentid->setValue($sParentId);
00273 }
00274
00275 $oArticle->setId( $sNewId );
00276 $oArticle->save();
00277
00278
00279 $this->_copyCategories( $sOldId, $sNewId );
00280
00281
00282 $this->_copyAttributes( $sOldId, $sNewId );
00283
00284
00285 $this->_copySelectlists( $sOldId, $sNewId );
00286
00287
00288 $this->_copyCrossseling( $sOldId, $sNewId );
00289
00290
00291 $this->_copyAccessoires( $sOldId, $sNewId );
00292
00293
00294 $this->_copyStaffelpreis( $sOldId, $sNewId );
00295
00296
00297 $this->_copyArtExtends( $sOldId, $sNewId);
00298
00299
00300 if ( $oArticle->oxarticles__oxvendorid->value) {
00301 oxUtilsCount::getInstance()->resetVendorArticleCount($oArticle->oxarticles__oxvendorid->value);
00302 }
00303
00304
00305
00306 $sQ = "select oxid from oxarticles where oxparentid = '{$sOldId}'";
00307 $rs = oxDb::getDb()->execute($sQ);
00308 if ( $rs !== false && $rs->recordCount() > 0) {
00309 while ( !$rs->EOF ) {
00310 $this->copyArticle( $rs->fields[0], oxUtilsObject::getInstance()->generateUID(), $sNewId );
00311 $rs->moveNext();
00312 }
00313 }
00314
00315
00316 if ( !$sParentId ) {
00317
00318 $this->_sSavedId = $oArticle->getId();
00319
00320
00321 if ( $myConfig->getConfigParam( 'blWarnOnSameArtNums' ) &&
00322 $oArticle->oxarticles__oxartnum->value && oxConfig::getParameter( 'fnc' ) == 'articleCopy' ) {
00323 $sSelect = "select oxid from ".$oArticle->getCoreTableName()."
00324 where oxartnum = '{$oArticle->oxarticles__oxartnum->value}'and oxid != '{$sNewId}'";
00325
00326 if ( $oArticle->assignRecord( $sSelect ) ) {
00327 $this->_aViewData["errorsavingatricle"] = 1;
00328 }
00329 }
00330 }
00331 }
00332 }
00333
00342 protected function _copyCategories( $sOldID, $sNewID )
00343 {
00344 $myConfig = $this->getConfig();
00345 $sO2CView = getViewName('oxobject2category');
00346 $sQ = "select oxcatnid from $sO2CView where oxobjectid = '$sOldID'";
00347 $rs = oxDb::getDb()->execute($sQ);
00348 if ($rs !== false && $rs->recordCount() > 0) {
00349 while (!$rs->EOF) {
00350 $sUID = oxUtilsObject::getInstance()->generateUID();
00351 $sCatID = $rs->fields[0];
00352
00353 oxDb::getDb()->execute("insert into oxobject2category (oxid, oxobjectid, oxcatnid) VALUES ('$sUID', '$sNewID', '$sCatID') ");
00354 $rs->moveNext();
00355
00356
00357 oxUtilsCount::getInstance()->resetCatArticleCount($sCatID);
00358 }
00359 }
00360 }
00361
00370 protected function _copyAttributes( $sOldID, $sNewID )
00371 {
00372 $sQ = "select oxid from oxobject2attribute where oxobjectid = '$sOldID'";
00373 $rs = oxDb::getDb()->Execute($sQ);
00374 if ($rs !== false && $rs->recordCount() > 0) {
00375 while (!$rs->EOF) {
00376
00377 $oAttr = oxNew( "oxbase");
00378 $oAttr->init( "oxobject2attribute" );
00379 $oAttr->load( $rs->fields[0]);
00380 $oAttr->setId( oxUtilsObject::getInstance()->generateUID() );
00381 $oAttr->oxobject2attribute__oxobjectid->setValue($sNewID);
00382 $oAttr->save();
00383 $rs->moveNext();
00384 }
00385 }
00386 }
00387
00396 protected function _copySelectlists( $sOldID, $sNewID)
00397 {
00398 $sQ = "select oxselnid from oxobject2selectlist where oxobjectid = '$sOldID'";
00399 $rs = oxDb::getDb()->Execute($sQ);
00400 if ($rs !== false && $rs->recordCount() > 0) {
00401 while (!$rs->EOF) {
00402 $sUID = oxUtilsObject::getInstance()->generateUID();
00403 $sID = $rs->fields[0];
00404 oxDb::getDb()->Execute("insert into oxobject2selectlist (oxid, oxobjectid, oxselnid) VALUES ('$sUID', '$sNewID', '$sID') ");
00405 $rs->moveNext();
00406 }
00407 }
00408 }
00409
00418 protected function _copyCrossseling( $sOldID, $sNewID )
00419 {
00420 $sQ = "select oxobjectid from oxobject2article where oxarticlenid = '$sOldID'";
00421 $rs = oxDb::getDb()->Execute($sQ);
00422 if ($rs !== false && $rs->recordCount() > 0) {
00423 while (!$rs->EOF) {
00424 $sUID = oxUtilsObject::getInstance()->generateUID();
00425 $sID = $rs->fields[0];
00426 oxDb::getDb()->Execute("insert into oxobject2article (oxid, oxobjectid, oxarticlenid) VALUES ('$sUID', '$sID', '$sNewID') ");
00427 $rs->moveNext();
00428 }
00429 }
00430 }
00431
00440 protected function _copyAccessoires( $sOldID, $sNewID )
00441 {
00442 $sQ = "select oxobjectid from oxaccessoire2article where oxarticlenid= '$sOldID'";
00443 $rs = oxDb::getDb()->Execute($sQ);
00444 if ($rs !== false && $rs->recordCount() > 0) {
00445 while (!$rs->EOF) {
00446 $sUID = oxUtilsObject::getInstance()->generateUID();
00447 $sID = $rs->fields[0];
00448 oxDb::getDb()->Execute("insert into oxaccessoire2article (oxid, oxobjectid, oxarticlenid) VALUES ('$sUID', '$sID', '$sNewID') ");
00449 $rs->moveNext();
00450 }
00451 }
00452 }
00453
00462 protected function _copyStaffelpreis( $sOldID, $sNewID )
00463 {
00464 $myConfig = $this->getConfig();
00465 $sShopID = $myConfig->getShopID();
00466 $oPriceList = oxNew("oxlist");
00467 $oPriceList->init( "oxbase", "oxprice2article");
00468 $sQ = "select * from oxprice2article where oxartid = '$sOldID' and oxshopid = '$sShopID' and (oxamount > 0 or oxamountto > 0) order by oxamount ";
00469 $oPriceList->selectString($sQ);
00470 if ($oPriceList->count()) {
00471 foreach ($oPriceList as $oItem) {
00472 $oItem->oxprice2article__oxid->setValue($oItem->setId());
00473 $oItem->oxprice2article__oxartid->setValue($sNewID);
00474 $oItem->save();
00475 }
00476 }
00477 }
00478
00487 protected function _copyArtExtends( $sOldID, $sNewID)
00488 {
00489 $oExt = oxNew( "oxbase");
00490 $oExt->init( "oxartextends" );
00491 $oExt->load( $sOldID);
00492 $oExt->setId( $sNewID );
00493 $oExt->save();
00494 }
00495
00496
00502 public function saveinnlang()
00503 {
00504 $myConfig = $this->getConfig();
00505
00506 $soxId = oxConfig::getParameter( "oxid" );
00507 $aParams = oxConfig::getParameter( "editval" );
00508
00509
00510 if ( !isset( $aParams['oxarticles__oxactive'] ) ) {
00511 $aParams['oxarticles__oxactive'] = 0;
00512 }
00513
00514
00515 $aParams = $this->addDefaultValues( $aParams);
00516
00517
00518 if ($aParams['oxarticles__oxvat'] === '')
00519 $aParams['oxarticles__oxvat'] = null;
00520
00521
00522 $soxparentId = oxConfig::getParameter( "oxparentid");
00523 if ( isset( $soxparentId) && $soxparentId && $soxparentId != "-1")
00524 $aParams['oxarticles__oxparentid'] = $soxparentId;
00525
00526 $oArticle = oxNew( "oxarticle");
00527 $oArticle->setLanguage($this->_iEditLang);
00528
00529 if ( $soxId != "-1")
00530 $oArticle->load( $soxId);
00531 else {
00532 $aParams['oxarticles__oxid'] = null;
00533
00534 $sShopID = oxSession::getVar( "actshop");
00535 $aParams['oxarticles__oxshopid'] = $sShopID;
00536 }
00537
00538
00539 if ( isset($aParams["oxarticles__oxprice"]) && $aParams["oxarticles__oxprice"] != $oArticle->oxarticles__oxprice->value) {
00540 oxUtilsCount::getInstance()->resetPriceCatArticleCount($oArticle->oxarticles__oxprice->value);
00541 }
00542 if ( $aParams['oxarticles__oxactive'] != $oArticle->oxarticles__oxactive->value) {
00543
00544 $sQ = "select oxcatnid from oxobject2category where oxobjectid = '".$oArticle->oxarticles__oxid->value."'";
00545 $rs = oxDb::getDb()->Execute($sQ);
00546 if ($rs !== false && $rs->recordCount() > 0)
00547 while (!$rs->EOF) {
00548 oxUtilsCount::getInstance()->resetCatArticleCount($rs->fields[0]);
00549 $rs->moveNext();
00550 }
00551
00552 if ( $oArticle->oxarticles__oxvendorid->value) {
00553 oxUtilsCount::getInstance()->resetVendorArticleCount($oArticle->oxarticles__oxvendorid->value);
00554 }
00555 }
00556 if ( isset($aParams["oxarticles__oxvendorid"]) && $aParams["oxarticles__oxvendorid"] != $oArticle->oxarticles__oxvendorid->value) {
00557
00558 if ( $aParams["oxarticles__oxvendorid"]) {
00559 oxUtilsCount::getInstance()->resetVendorArticleCount($aParams["oxarticles__oxvendorid"]);
00560 }
00561
00562 if ( $oArticle->oxarticles__oxvendorid->value) {
00563 oxUtilsCount::getInstance()->resetVendorArticleCount($oArticle->oxarticles__oxvendorid->value);
00564 }
00565 }
00566
00567
00568
00569
00570 $oArticle->setLanguage(0);
00571 $oArticle->assign( $aParams);
00572
00573
00574 $sNewLanguage = oxConfig::getParameter( "new_lang");
00575 $oArticle->setLanguage( $sNewLanguage);
00576 $oArticle->save();
00577
00578
00579 oxSession::setVar( "new_lang", $sNewLanguage );
00580
00581
00582 if ( $soxId == "-1" )
00583 $this->_sSavedId = $oArticle->getId();
00584 }
00585
00594 public function addDefaultValues( $aParams )
00595 {
00596 return $aParams;
00597 }
00598
00607 protected function _formJumpList( $oArticle, $oParentArticle )
00608 {
00609 $aJumpList = array();
00610
00611 if ( isset( $oParentArticle ) ) {
00612 $aJumpList[] = array( $oParentArticle->oxarticles__oxid->value, $this->_getTitle( $oParentArticle ) );
00613 $oParentVariants = $oParentArticle->getAdminVariants( oxConfig::getParameter( "editlanguage" ) );
00614 if ( $oParentVariants->count()) {
00615 foreach ( $oParentVariants as $oVar) {
00616 $aJumpList[] = array( $oVar->oxarticles__oxid->value, " - ".$this->_getTitle( $oVar ) );
00617 if ( $oVar->oxarticles__oxid->value == $oArticle->oxarticles__oxid->value ) {
00618 $oVariants = $oArticle->getAdminVariants(oxConfig::getParameter( "editlanguage"));
00619 if ( $oVariants->count() ) {
00620 foreach ( $oVariants as $oVVar) {
00621 $aJumpList[] = array( $oVVar->oxarticles__oxid->value, " -- ".$this->_getTitle( $oVVar));
00622 }
00623 }
00624 }
00625 }
00626 }
00627 } else {
00628 $aJumpList[] = array( $oArticle->oxarticles__oxid->value, $this->_getTitle( $oArticle));
00629
00630 $oVariants = $oArticle->getAdminVariants(oxConfig::getParameter( "editlanguage"));
00631 if ( $oVariants && $oVariants->count())
00632 foreach ($oVariants as $oVar) {
00633 $aJumpList[] = array( $oVar->oxarticles__oxid->value, " - ".$this->_getTitle( $oVar));
00634 }
00635 }
00636 if ( count($aJumpList) > 1)
00637 $this->_aViewData["thisvariantlist"] = $aJumpList;
00638 }
00639
00647 protected function _getTitle( $oObj )
00648 {
00649 $sTitle = $oObj->oxarticles__oxtitle->value;
00650 if ( !strlen( $sTitle ) ) {
00651 $sTitle = $oObj->oxarticles__oxvarselect->value;
00652 }
00653
00654 return $sTitle;
00655 }
00656 }