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 (oxRegistry::getLang()->getLanguageNames(), $oOtherLang);
00068 if ( count( $aLang))
00069 $this->_aViewData["posslang"] = $aLang;
00070
00071 foreach ( $oOtherLang as $id => $language) {
00072 $oLang= new stdClass();
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->getLongDescription();
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 $aParams = $this->addDefaultValues( $aParams );
00120
00121
00122 if (isset($aParams['oxarticles__oxvat']) && $aParams['oxarticles__oxvat'] === '') {
00123 $aParams['oxarticles__oxvat'] = null;
00124 }
00125
00126
00127 $soxparentId = oxConfig::getParameter( "oxparentid");
00128 if ( isset( $soxparentId) && $soxparentId && $soxparentId != "-1") {
00129 $aParams['oxarticles__oxparentid'] = $soxparentId;
00130 } else {
00131 unset( $aParams['oxarticles__oxparentid']);
00132 }
00133
00134 $oArticle = oxNew( "oxarticle");
00135 $oArticle->setLanguage($this->_iEditLang);
00136
00137 if ( $soxId != "-1") {
00138 $oArticle->loadInLang( $this->_iEditLang, $soxId);
00139 } else {
00140 $aParams['oxarticles__oxid'] = null;
00141 $aParams['oxarticles__oxissearch'] = 1;
00142 $aParams['oxarticles__oxstockflag'] = 1;
00143
00144 $aParams['oxarticles__oxshopid'] = oxSession::getVar( "actshop");
00145
00146 if (!isset($aParams['oxarticles__oxactive'])) {
00147 $aParams['oxarticles__oxactive'] = 0;
00148 }
00149 }
00150
00151
00152 if ( isset( $aParams['oxarticles__oxartnum']) && strlen($aParams['oxarticles__oxartnum']) > 0 &&
00153 $myConfig->getConfigParam( 'blWarnOnSameArtNums' ) &&
00154 $oArticle->oxarticles__oxartnum->value != $aParams['oxarticles__oxartnum']
00155 ) {
00156 $sSelect = "select oxid from ".getViewName( 'oxarticles' );
00157 $sSelect .= " where oxartnum = '".$aParams['oxarticles__oxartnum']."'";
00158 $sSelect .= " and oxid != '".$aParams['oxarticles__oxid']."'";
00159 if ($oArticle->assignRecord( $sSelect ))
00160 $this->_aViewData["errorsavingatricle"] = 1;
00161 }
00162
00163
00164 if ( isset($aParams["oxarticles__oxprice"]) && $aParams["oxarticles__oxprice"] != $oArticle->oxarticles__oxprice->value) {
00165 $this->resetCounter( "priceCatArticle", $oArticle->oxarticles__oxprice->value );
00166 }
00167
00168 $aResetIds = array();
00169 if ( isset($aParams['oxarticles__oxactive']) && $aParams['oxarticles__oxactive'] != $oArticle->oxarticles__oxactive->value) {
00170 $oDb = oxDb::getDb();
00171
00172 $sQ = "select oxcatnid from oxobject2category where oxobjectid = ".$oDb->quote( $oArticle->oxarticles__oxid->value );
00173 $oRs = $oDb->execute($sQ);
00174 if ( $oRs !== false && $oRs->recordCount() > 0 ) {
00175 while (!$oRs->EOF) {
00176 $this->resetCounter( "catArticle", $oRs->fields[0] );
00177 $oRs->moveNext();
00178 }
00179 }
00180
00181
00182 $aResetIds['vendor'][$oArticle->oxarticles__oxvendorid->value] = 1;
00183 $aResetIds['manufacturer'][$oArticle->oxarticles__oxmanufacturerid->value] = 1;
00184 }
00185
00186
00187 if ( isset($aParams['oxarticles__oxvendorid']) && $aParams['oxarticles__oxvendorid'] != $oArticle->oxarticles__oxvendorid->value) {
00188 $aResetIds['vendor'][$aParams['oxarticles__oxvendorid']] = 1;
00189 $aResetIds['vendor'][$oArticle->oxarticles__oxvendorid->value] = 1;
00190 }
00191
00192
00193 if ( isset($aParams['oxarticles__oxmanufacturerid']) && $aParams['oxarticles__oxmanufacturerid'] != $oArticle->oxarticles__oxmanufacturerid->value ) {
00194 $aResetIds['manufacturer'][$aParams['oxarticles__oxmanufacturerid']] = 1;
00195 $aResetIds['manufacturer'][$oArticle->oxarticles__oxmanufacturerid->value] = 1;
00196 }
00197
00198
00199 $this->_resetCounts( $aResetIds );
00200
00201 $oArticle->setLanguage(0);
00202
00203
00204 if (isset($aParams['oxarticles__oxtitle'])) {
00205 $aParams['oxarticles__oxtitle'] = trim( $aParams['oxarticles__oxtitle'] );
00206 }
00207
00208 $oArticle->assign( $aParams );
00209 $oArticle->setArticleLongDesc( $this->_processLongDesc( $aParams['oxarticles__oxlongdesc'] ) );
00210 $oArticle->setLanguage($this->_iEditLang);
00211 $oArticle = oxRegistry::get("oxUtilsFile")->processFiles( $oArticle );
00212 $oArticle->save();
00213
00214
00215 if ( $soxId == "-1") {
00216 $sFastCat = oxConfig::getParameter( "art_category");
00217 if ( $sFastCat != "-1") {
00218 $this->addToCategory($sFastCat, $oArticle->getId());
00219 }
00220 }
00221
00222 if (isset($aParams['tags'])) {
00223
00224 $sTags = $aParams['tags'];
00225 if (!trim($sTags)) {
00226 $sTags = $oArticle->oxarticles__oxsearchkeys->value;
00227 }
00228 $oArticle->saveTags($sTags);
00229 }
00230
00231 $this->setEditObjectId( $oArticle->getId() );
00232 }
00233
00241 protected function _processLongDesc( $sValue )
00242 {
00243
00244
00245 $sValue = str_replace( '&nbsp;', ' ', $sValue );
00246 $sValue = str_replace( '&', '&', $sValue );
00247 $sValue = str_replace( '"', '"', $sValue );
00248 $sValue = str_replace( '&lang=', '&lang=', $sValue);
00249
00250 return $sValue;
00251 }
00252
00261 public function addToCategory($sCatID, $sOXID)
00262 {
00263 $myConfig = $this->getConfig();
00264
00265 $oNew = oxNew( "oxbase");
00266 $oNew->init( "oxobject2category" );
00267 $oNew->oxobject2category__oxtime = new oxField( 0 );
00268 $oNew->oxobject2category__oxobjectid = new oxField( $sOXID );
00269 $oNew->oxobject2category__oxcatnid = new oxField( $sCatID );
00270
00271 $oNew->save();
00272
00273
00274 $this->resetCounter( "catArticle", $sCatID );
00275 }
00276
00286 public function copyArticle( $sOldId = null, $sNewId = null, $sParentId = null )
00287 {
00288 $myConfig = $this->getConfig();
00289
00290 $sOldId = $sOldId ? $sOldId : $this->getEditObjectId();
00291 $sNewId = $sNewId ? $sNewId : oxUtilsObject::getInstance()->generateUID();
00292
00293 $oArticle = oxNew( 'oxbase' );
00294 $oArticle->init( 'oxarticles' );
00295 if ( $oArticle->load( $sOldId ) ) {
00296
00297 if ( $myConfig->getConfigParam( 'blDisableDublArtOnCopy' ) ) {
00298 $oArticle->oxarticles__oxactive->setValue( 0 );
00299 $oArticle->oxarticles__oxactivefrom->setValue( 0 );
00300 $oArticle->oxarticles__oxactiveto->setValue( 0 );
00301 }
00302
00303
00304 if ( $sParentId ) {
00305 $oArticle->oxarticles__oxparentid->setValue( $sParentId );
00306 }
00307
00308
00309 $iNow = date( 'Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime() );
00310 $oArticle->oxarticles__oxinsert = new oxField( $iNow );
00311 $oArticle->oxarticles__oxtimestamp = new oxField( $iNow );
00312
00313
00314 $oArticle->oxarticles__oxrating = new oxField( 0 );
00315 $oArticle->oxarticles__oxratingcnt = new oxField( 0 );
00316
00317 $oArticle->setId( $sNewId );
00318 $oArticle->save();
00319
00320
00321 $this->_copyCategories( $sOldId, $sNewId );
00322
00323
00324 $this->_copyAttributes( $sOldId, $sNewId );
00325
00326
00327 $this->_copySelectlists( $sOldId, $sNewId );
00328
00329
00330 $this->_copyCrossseling( $sOldId, $sNewId );
00331
00332
00333 $this->_copyAccessoires( $sOldId, $sNewId );
00334
00335
00336 $this->_copyStaffelpreis( $sOldId, $sNewId );
00337
00338
00339 $this->_copyArtExtends( $sOldId, $sNewId);
00340
00341
00342 $this->_copyFiles( $sOldId, $sNewId );
00343
00344
00345 $aResetIds['vendor'][$oArticle->oxarticles__oxvendorid->value] = 1;
00346 $aResetIds['manufacturer'][$oArticle->oxarticles__oxmanufacturerid->value] = 1;
00347 $this->_resetCounts( $aResetIds );
00348
00349
00350 $myUtilsObject = oxUtilsObject::getInstance();
00351 $oDb = oxDb::getDb();
00352
00353
00354 $sQ = "select oxid from oxarticles where oxparentid = ".$oDb->quote( $sOldId );
00355 $oRs = $oDb->execute( $sQ );
00356 if ( $oRs !== false && $oRs->recordCount() > 0) {
00357 while ( !$oRs->EOF ) {
00358 $this->copyArticle( $oRs->fields[0], $myUtilsObject->generateUid(), $sNewId );
00359 $oRs->moveNext();
00360 }
00361 }
00362
00363
00364 if ( !$sParentId ) {
00365
00366 $this->setEditObjectId( $oArticle->getId() );
00367
00368
00369 if ( $myConfig->getConfigParam( 'blWarnOnSameArtNums' ) &&
00370 $oArticle->oxarticles__oxartnum->value && oxConfig::getParameter( 'fnc' ) == 'copyArticle' ) {
00371 $sSelect = "select oxid from ".$oArticle->getCoreTableName()."
00372 where oxartnum = ".$oDb->quote( $oArticle->oxarticles__oxartnum->value )." and oxid != ".$oDb->quote( $sNewId );
00373
00374 if ( $oArticle->assignRecord( $sSelect ) ) {
00375 $this->_aViewData["errorsavingatricle"] = 1;
00376 }
00377 }
00378 }
00379 }
00380 }
00381
00390 protected function _copyCategories( $sOldId, $sNewId )
00391 {
00392 $myUtilsObject = oxUtilsObject::getInstance();
00393 $oShopMetaData = oxRegistry::get("oxShopMetaData");
00394 $oDb = oxDb::getDb();
00395
00396
00397 $sO2CView = getViewName( 'oxobject2category' );
00398 $sQ = "select oxcatnid, oxtime from {$sO2CView} where oxobjectid = ".$oDb->quote( $sOldId );
00399 $oRs = $oDb->execute( $sQ );
00400 if ( $oRs !== false && $oRs->recordCount() > 0 ) {
00401 while ( !$oRs->EOF ) {
00402 $sUid = $myUtilsObject->generateUid();
00403 $sCatId = $oRs->fields[0];
00404 $sTime = $oRs->fields[1];
00405
00406
00407 $oDb->execute("insert into oxobject2category (oxid, oxobjectid, oxcatnid, oxtime) VALUES (".$oDb->quote( $sUid ).", ".$oDb->quote( $sNewId ).", ".$oDb->quote( $sCatId ).", ".$oDb->quote( $sTime ).") ");
00408
00409 $oRs->moveNext();
00410
00411
00412 $this->resetCounter( "catArticle", $sCatId );
00413 }
00414 }
00415 }
00416
00425 protected function _copyAttributes( $sOldId, $sNewId )
00426 {
00427 $myUtilsObject = oxUtilsObject::getInstance();
00428 $oDb = oxDb::getDb();
00429
00430 $sQ = "select oxid from oxobject2attribute where oxobjectid = ".$oDb->quote( $sOldId );
00431 $oRs = $oDb->execute($sQ);
00432 if ( $oRs !== false && $oRs->recordCount() > 0 ) {
00433 while ( !$oRs->EOF ) {
00434
00435 $oAttr = oxNew( "oxbase" );
00436 $oAttr->init( "oxobject2attribute" );
00437 $oAttr->load( $oRs->fields[0] );
00438 $oAttr->setId( $myUtilsObject->generateUID() );
00439 $oAttr->oxobject2attribute__oxobjectid->setValue( $sNewId );
00440 $oAttr->save();
00441 $oRs->moveNext();
00442 }
00443 }
00444 }
00445
00454 protected function _copyFiles( $sOldId, $sNewId )
00455 {
00456 $myUtilsObject = oxUtilsObject::getInstance();
00457 $oDb = oxDb::getDb( oxDB::FETCH_MODE_ASSOC );
00458
00459 $sQ = "SELECT * FROM `oxfiles` WHERE `oxartid` = ".$oDb->quote( $sOldId );
00460 $oRs = $oDb->execute($sQ);
00461 if ( $oRs !== false && $oRs->recordCount() > 0 ) {
00462 while ( !$oRs->EOF ) {
00463
00464 $oFile = oxNew( "oxfile" );
00465 $oFile->setId( $myUtilsObject->generateUID() );
00466 $oFile->oxfiles__oxartid = new oxField( $sNewId );
00467 $oFile->oxfiles__oxfilename = new oxField( $oRs->fields['OXFILENAME'] );
00468 $oFile->oxfiles__oxfilesize = new oxField( $oRs->fields['OXFILESIZE'] );
00469 $oFile->oxfiles__oxstorehash = new oxField( $oRs->fields['OXSTOREHASH'] );
00470 $oFile->oxfiles__oxpurchasedonly = new oxField( $oRs->fields['OXPURCHASEDONLY'] );
00471 $oFile->save();
00472 $oRs->moveNext();
00473 }
00474 }
00475 }
00476
00485 protected function _copySelectlists( $sOldId, $sNewId )
00486 {
00487 $myUtilsObject = oxUtilsObject::getInstance();
00488 $oDb = oxDb::getDb();
00489
00490 $sQ = "select oxselnid from oxobject2selectlist where oxobjectid = ".$oDb->quote( $sOldId );
00491 $oRs = $oDb->execute( $sQ );
00492 if ( $oRs !== false && $oRs->recordCount() > 0 ) {
00493 while ( !$oRs->EOF ) {
00494 $sUid = $myUtilsObject->generateUID();
00495 $sId = $oRs->fields[0];
00496 $oDb->execute( "insert into oxobject2selectlist (oxid, oxobjectid, oxselnid) VALUES (".$oDb->quote( $sUid ).", ".$oDb->quote( $sNewId ).", ".$oDb->quote( $sId ).") " );
00497 $oRs->moveNext();
00498 }
00499 }
00500 }
00501
00510 protected function _copyCrossseling( $sOldId, $sNewId )
00511 {
00512 $myUtilsObject = oxUtilsObject::getInstance();
00513 $oDb = oxDb::getDb();
00514
00515 $sQ = "select oxobjectid from oxobject2article where oxarticlenid = ".$oDb->quote( $sOldId );
00516 $oRs = $oDb->execute( $sQ );
00517 if ( $oRs !== false && $oRs->recordCount() > 0 ) {
00518 while ( !$oRs->EOF ) {
00519 $sUid = $myUtilsObject->generateUID();
00520 $sId = $oRs->fields[0];
00521 $oDb->execute("insert into oxobject2article (oxid, oxobjectid, oxarticlenid) VALUES (".$oDb->quote( $sUid ).", ".$oDb->quote( $sId ).", ".$oDb->quote( $sNewId )." ) ");
00522 $oRs->moveNext();
00523 }
00524 }
00525 }
00526
00535 protected function _copyAccessoires( $sOldId, $sNewId )
00536 {
00537 $myUtilsObject = oxUtilsObject::getInstance();
00538 $oDb = oxDb::getDb();
00539
00540 $sQ = "select oxobjectid from oxaccessoire2article where oxarticlenid= ".$oDb->quote( $sOldId );
00541 $oRs = $oDb->execute( $sQ );
00542 if ( $oRs !== false && $oRs->recordCount() > 0 ) {
00543 while ( !$oRs->EOF ) {
00544 $sUId = $myUtilsObject->generateUid();
00545 $sId = $oRs->fields[0];
00546 $oDb->execute( "insert into oxaccessoire2article (oxid, oxobjectid, oxarticlenid) VALUES (".$oDb->quote( $sUId ).", ".$oDb->quote( $sId ).", ".$oDb->quote( $sNewId ).") " );
00547 $oRs->moveNext();
00548 }
00549 }
00550 }
00551
00560 protected function _copyStaffelpreis( $sOldId, $sNewId )
00561 {
00562 $sShopId = $this->getConfig()->getShopId();
00563 $oPriceList = oxNew( "oxlist" );
00564 $oPriceList->init( "oxbase", "oxprice2article" );
00565 $sQ = "select * from oxprice2article where oxartid = '$sOldId' and oxshopid = '$sShopId' and (oxamount > 0 or oxamountto > 0) order by oxamount ";
00566 $oPriceList->selectString( $sQ );
00567 if ( $oPriceList->count() ) {
00568 foreach ( $oPriceList as $oItem ) {
00569 $oItem->oxprice2article__oxid->setValue( $oItem->setId() );
00570 $oItem->oxprice2article__oxartid->setValue( $sNewId );
00571 $oItem->save();
00572 }
00573 }
00574 }
00575
00584 protected function _copyArtExtends( $sOldId, $sNewId)
00585 {
00586 $oExt = oxNew( "oxbase");
00587 $oExt->init( "oxartextends" );
00588 $oExt->load( $sOldId );
00589 $oExt->setId( $sNewId );
00590 $oExt->save();
00591 }
00592
00593
00599 public function saveinnlang()
00600 {
00601 $this->save();
00602 }
00603
00612 public function addDefaultValues( $aParams )
00613 {
00614 return $aParams;
00615 }
00616
00625 protected function _formJumpList( $oArticle, $oParentArticle )
00626 {
00627 $aJumpList = array();
00628
00629 if ( isset( $oParentArticle ) ) {
00630 $aJumpList[] = array( $oParentArticle->oxarticles__oxid->value, $this->_getTitle( $oParentArticle ) );
00631 $oParentVariants = $oParentArticle->getAdminVariants( oxConfig::getParameter( "editlanguage" ) );
00632 if ( $oParentVariants->count()) {
00633 foreach ( $oParentVariants as $oVar) {
00634 $aJumpList[] = array( $oVar->oxarticles__oxid->value, " - ".$this->_getTitle( $oVar ) );
00635 if ( $oVar->oxarticles__oxid->value == $oArticle->oxarticles__oxid->value ) {
00636 $oVariants = $oArticle->getAdminVariants(oxConfig::getParameter( "editlanguage"));
00637 if ( $oVariants->count() ) {
00638 foreach ( $oVariants as $oVVar) {
00639 $aJumpList[] = array( $oVVar->oxarticles__oxid->value, " -- ".$this->_getTitle( $oVVar));
00640 }
00641 }
00642 }
00643 }
00644 }
00645 } else {
00646 $aJumpList[] = array( $oArticle->oxarticles__oxid->value, $this->_getTitle( $oArticle));
00647
00648 $oVariants = $oArticle->getAdminVariants(oxConfig::getParameter( "editlanguage"));
00649 if ( $oVariants && $oVariants->count())
00650 foreach ($oVariants as $oVar) {
00651 $aJumpList[] = array( $oVar->oxarticles__oxid->value, " - ".$this->_getTitle( $oVar));
00652 }
00653 }
00654 if ( count($aJumpList) > 1)
00655 $this->_aViewData["thisvariantlist"] = $aJumpList;
00656 }
00657
00665 protected function _getTitle( $oObj )
00666 {
00667 $sTitle = $oObj->oxarticles__oxtitle->value;
00668 if ( !strlen( $sTitle ) ) {
00669 $sTitle = $oObj->oxarticles__oxvarselect->value;
00670 }
00671
00672 return $sTitle;
00673 }
00674
00680 public function getCategoryList()
00681 {
00682 $oCatTree = oxNew( "oxCategoryList");
00683 $oCatTree->buildList( $this->getConfig()->getConfigParam( 'bl_perfLoadCatTree' ) );
00684 return $oCatTree;
00685 }
00686
00692 public function getVendorList()
00693 {
00694 $oVendorlist = oxNew( "oxvendorlist" );
00695 $oVendorlist->loadVendorList();
00696
00697 return $oVendorlist;
00698 }
00699
00705 public function getManufacturerList()
00706 {
00707 $oManufacturerList = oxNew( "oxmanufacturerlist" );
00708 $oManufacturerList->loadManufacturerList();
00709
00710 return $oManufacturerList;
00711 }
00712 }