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
00312
00313 $oArticle->oxarticles__oxrating = new oxField( 0 );
00314 $oArticle->oxarticles__oxratingcnt = new oxField( 0 );
00315
00316 $oArticle->setId( $sNewId );
00317 $oArticle->save();
00318
00319
00320 $this->_copyCategories( $sOldId, $sNewId );
00321
00322
00323 $this->_copyAttributes( $sOldId, $sNewId );
00324
00325
00326 $this->_copySelectlists( $sOldId, $sNewId );
00327
00328
00329 $this->_copyCrossseling( $sOldId, $sNewId );
00330
00331
00332 $this->_copyAccessoires( $sOldId, $sNewId );
00333
00334
00335 $this->_copyStaffelpreis( $sOldId, $sNewId );
00336
00337
00338 $this->_copyArtExtends( $sOldId, $sNewId);
00339
00340
00341 $this->_copyFiles( $sOldId, $sNewId );
00342
00343
00344 $aResetIds['vendor'][$oArticle->oxarticles__oxvendorid->value] = 1;
00345 $aResetIds['manufacturer'][$oArticle->oxarticles__oxmanufacturerid->value] = 1;
00346 $this->_resetCounts( $aResetIds );
00347
00348
00349 $myUtilsObject = oxUtilsObject::getInstance();
00350 $oDb = oxDb::getDb();
00351
00352
00353 $sQ = "select oxid from oxarticles where oxparentid = ".$oDb->quote( $sOldId );
00354 $oRs = $oDb->execute( $sQ );
00355 if ( $oRs !== false && $oRs->recordCount() > 0) {
00356 while ( !$oRs->EOF ) {
00357 $this->copyArticle( $oRs->fields[0], $myUtilsObject->generateUid(), $sNewId );
00358 $oRs->moveNext();
00359 }
00360 }
00361
00362
00363 if ( !$sParentId ) {
00364
00365 $this->setEditObjectId( $oArticle->getId() );
00366
00367
00368 if ( $myConfig->getConfigParam( 'blWarnOnSameArtNums' ) &&
00369 $oArticle->oxarticles__oxartnum->value && oxConfig::getParameter( 'fnc' ) == 'copyArticle' ) {
00370 $sSelect = "select oxid from ".$oArticle->getCoreTableName()."
00371 where oxartnum = ".$oDb->quote( $oArticle->oxarticles__oxartnum->value )." and oxid != ".$oDb->quote( $sNewId );
00372
00373 if ( $oArticle->assignRecord( $sSelect ) ) {
00374 $this->_aViewData["errorsavingatricle"] = 1;
00375 }
00376 }
00377 }
00378 }
00379 }
00380
00389 protected function _copyCategories( $sOldId, $sNewId )
00390 {
00391 $myUtilsObject = oxUtilsObject::getInstance();
00392 $oShopMetaData = oxRegistry::get("oxShopMetaData");
00393 $oDb = oxDb::getDb();
00394
00395
00396 $sO2CView = getViewName( 'oxobject2category' );
00397 $sQ = "select oxcatnid, oxtime from {$sO2CView} where oxobjectid = ".$oDb->quote( $sOldId );
00398 $oRs = $oDb->execute( $sQ );
00399 if ( $oRs !== false && $oRs->recordCount() > 0 ) {
00400 while ( !$oRs->EOF ) {
00401 $sUid = $myUtilsObject->generateUid();
00402 $sCatId = $oRs->fields[0];
00403 $sTime = $oRs->fields[1];
00404
00405
00406 $oDb->execute("insert into oxobject2category (oxid, oxobjectid, oxcatnid, oxtime) VALUES (".$oDb->quote( $sUid ).", ".$oDb->quote( $sNewId ).", ".$oDb->quote( $sCatId ).", ".$oDb->quote( $sTime ).") ");
00407
00408 $oRs->moveNext();
00409
00410
00411 $this->resetCounter( "catArticle", $sCatId );
00412 }
00413 }
00414 }
00415
00424 protected function _copyAttributes( $sOldId, $sNewId )
00425 {
00426 $myUtilsObject = oxUtilsObject::getInstance();
00427 $oDb = oxDb::getDb();
00428
00429 $sQ = "select oxid from oxobject2attribute where oxobjectid = ".$oDb->quote( $sOldId );
00430 $oRs = $oDb->execute($sQ);
00431 if ( $oRs !== false && $oRs->recordCount() > 0 ) {
00432 while ( !$oRs->EOF ) {
00433
00434 $oAttr = oxNew( "oxbase" );
00435 $oAttr->init( "oxobject2attribute" );
00436 $oAttr->load( $oRs->fields[0] );
00437 $oAttr->setId( $myUtilsObject->generateUID() );
00438 $oAttr->oxobject2attribute__oxobjectid->setValue( $sNewId );
00439 $oAttr->save();
00440 $oRs->moveNext();
00441 }
00442 }
00443 }
00444
00453 protected function _copyFiles( $sOldId, $sNewId )
00454 {
00455 $myUtilsObject = oxUtilsObject::getInstance();
00456 $oDb = oxDb::getDb( oxDB::FETCH_MODE_ASSOC );
00457
00458 $sQ = "SELECT * FROM `oxfiles` WHERE `oxartid` = ".$oDb->quote( $sOldId );
00459 $oRs = $oDb->execute($sQ);
00460 if ( $oRs !== false && $oRs->recordCount() > 0 ) {
00461 while ( !$oRs->EOF ) {
00462
00463 $oFile = oxNew( "oxfile" );
00464 $oFile->setId( $myUtilsObject->generateUID() );
00465 $oFile->oxfiles__oxartid = new oxField( $sNewId );
00466 $oFile->oxfiles__oxfilename = new oxField( $oRs->fields['OXFILENAME'] );
00467 $oFile->oxfiles__oxfilesize = new oxField( $oRs->fields['OXFILESIZE'] );
00468 $oFile->oxfiles__oxstorehash = new oxField( $oRs->fields['OXSTOREHASH'] );
00469 $oFile->oxfiles__oxpurchasedonly = new oxField( $oRs->fields['OXPURCHASEDONLY'] );
00470 $oFile->save();
00471 $oRs->moveNext();
00472 }
00473 }
00474 }
00475
00484 protected function _copySelectlists( $sOldId, $sNewId )
00485 {
00486 $myUtilsObject = oxUtilsObject::getInstance();
00487 $oDb = oxDb::getDb();
00488
00489 $sQ = "select oxselnid from oxobject2selectlist where oxobjectid = ".$oDb->quote( $sOldId );
00490 $oRs = $oDb->execute( $sQ );
00491 if ( $oRs !== false && $oRs->recordCount() > 0 ) {
00492 while ( !$oRs->EOF ) {
00493 $sUid = $myUtilsObject->generateUID();
00494 $sId = $oRs->fields[0];
00495 $oDb->execute( "insert into oxobject2selectlist (oxid, oxobjectid, oxselnid) VALUES (".$oDb->quote( $sUid ).", ".$oDb->quote( $sNewId ).", ".$oDb->quote( $sId ).") " );
00496 $oRs->moveNext();
00497 }
00498 }
00499 }
00500
00509 protected function _copyCrossseling( $sOldId, $sNewId )
00510 {
00511 $myUtilsObject = oxUtilsObject::getInstance();
00512 $oDb = oxDb::getDb();
00513
00514 $sQ = "select oxobjectid from oxobject2article where oxarticlenid = ".$oDb->quote( $sOldId );
00515 $oRs = $oDb->execute( $sQ );
00516 if ( $oRs !== false && $oRs->recordCount() > 0 ) {
00517 while ( !$oRs->EOF ) {
00518 $sUid = $myUtilsObject->generateUID();
00519 $sId = $oRs->fields[0];
00520 $oDb->execute("insert into oxobject2article (oxid, oxobjectid, oxarticlenid) VALUES (".$oDb->quote( $sUid ).", ".$oDb->quote( $sId ).", ".$oDb->quote( $sNewId )." ) ");
00521 $oRs->moveNext();
00522 }
00523 }
00524 }
00525
00534 protected function _copyAccessoires( $sOldId, $sNewId )
00535 {
00536 $myUtilsObject = oxUtilsObject::getInstance();
00537 $oDb = oxDb::getDb();
00538
00539 $sQ = "select oxobjectid from oxaccessoire2article where oxarticlenid= ".$oDb->quote( $sOldId );
00540 $oRs = $oDb->execute( $sQ );
00541 if ( $oRs !== false && $oRs->recordCount() > 0 ) {
00542 while ( !$oRs->EOF ) {
00543 $sUId = $myUtilsObject->generateUid();
00544 $sId = $oRs->fields[0];
00545 $oDb->execute( "insert into oxaccessoire2article (oxid, oxobjectid, oxarticlenid) VALUES (".$oDb->quote( $sUId ).", ".$oDb->quote( $sId ).", ".$oDb->quote( $sNewId ).") " );
00546 $oRs->moveNext();
00547 }
00548 }
00549 }
00550
00559 protected function _copyStaffelpreis( $sOldId, $sNewId )
00560 {
00561 $sShopId = $this->getConfig()->getShopId();
00562 $oPriceList = oxNew( "oxlist" );
00563 $oPriceList->init( "oxbase", "oxprice2article" );
00564 $sQ = "select * from oxprice2article where oxartid = '$sOldId' and oxshopid = '$sShopId' and (oxamount > 0 or oxamountto > 0) order by oxamount ";
00565 $oPriceList->selectString( $sQ );
00566 if ( $oPriceList->count() ) {
00567 foreach ( $oPriceList as $oItem ) {
00568 $oItem->oxprice2article__oxid->setValue( $oItem->setId() );
00569 $oItem->oxprice2article__oxartid->setValue( $sNewId );
00570 $oItem->save();
00571 }
00572 }
00573 }
00574
00583 protected function _copyArtExtends( $sOldId, $sNewId)
00584 {
00585 $oExt = oxNew( "oxbase");
00586 $oExt->init( "oxartextends" );
00587 $oExt->load( $sOldId );
00588 $oExt->setId( $sNewId );
00589 $oExt->save();
00590 }
00591
00592
00598 public function saveinnlang()
00599 {
00600 $this->save();
00601 }
00602
00611 public function addDefaultValues( $aParams )
00612 {
00613 return $aParams;
00614 }
00615
00624 protected function _formJumpList( $oArticle, $oParentArticle )
00625 {
00626 $aJumpList = array();
00627
00628 if ( isset( $oParentArticle ) ) {
00629 $aJumpList[] = array( $oParentArticle->oxarticles__oxid->value, $this->_getTitle( $oParentArticle ) );
00630 $oParentVariants = $oParentArticle->getAdminVariants( oxConfig::getParameter( "editlanguage" ) );
00631 if ( $oParentVariants->count()) {
00632 foreach ( $oParentVariants as $oVar) {
00633 $aJumpList[] = array( $oVar->oxarticles__oxid->value, " - ".$this->_getTitle( $oVar ) );
00634 if ( $oVar->oxarticles__oxid->value == $oArticle->oxarticles__oxid->value ) {
00635 $oVariants = $oArticle->getAdminVariants(oxConfig::getParameter( "editlanguage"));
00636 if ( $oVariants->count() ) {
00637 foreach ( $oVariants as $oVVar) {
00638 $aJumpList[] = array( $oVVar->oxarticles__oxid->value, " -- ".$this->_getTitle( $oVVar));
00639 }
00640 }
00641 }
00642 }
00643 }
00644 } else {
00645 $aJumpList[] = array( $oArticle->oxarticles__oxid->value, $this->_getTitle( $oArticle));
00646
00647 $oVariants = $oArticle->getAdminVariants(oxConfig::getParameter( "editlanguage"));
00648 if ( $oVariants && $oVariants->count())
00649 foreach ($oVariants as $oVar) {
00650 $aJumpList[] = array( $oVar->oxarticles__oxid->value, " - ".$this->_getTitle( $oVar));
00651 }
00652 }
00653 if ( count($aJumpList) > 1)
00654 $this->_aViewData["thisvariantlist"] = $aJumpList;
00655 }
00656
00664 protected function _getTitle( $oObj )
00665 {
00666 $sTitle = $oObj->oxarticles__oxtitle->value;
00667 if ( !strlen( $sTitle ) ) {
00668 $sTitle = $oObj->oxarticles__oxvarselect->value;
00669 }
00670
00671 return $sTitle;
00672 }
00673
00679 public function getCategoryList()
00680 {
00681 $oCatTree = oxNew( "oxCategoryList");
00682 $oCatTree->buildList( $this->getConfig()->getConfigParam( 'bl_perfLoadCatTree' ) );
00683 return $oCatTree;
00684 }
00685
00691 public function getVendorList()
00692 {
00693 $oVendorlist = oxNew( "oxvendorlist" );
00694 $oVendorlist->loadVendorList();
00695
00696 return $oVendorlist;
00697 }
00698
00704 public function getManufacturerList()
00705 {
00706 $oManufacturerList = oxNew( "oxmanufacturerlist" );
00707 $oManufacturerList->loadManufacturerList();
00708
00709 return $oManufacturerList;
00710 }
00711 }