discount_main.php

Go to the documentation of this file.
00001 <?php
00002 
00009 class Discount_Main extends oxAdminDetails
00010 {
00017     public function render()
00018     {
00019         $myConfig = $this->getConfig();
00020         parent::render();
00021 
00022         $sOxId = oxConfig::getParameter( "oxid");
00023         // check if we right now saved a new entry
00024         $sSavedID = oxConfig::getParameter( "saved_oxid");
00025         if ( ($sOxId == "-1" || !isset( $sOxId)) && isset( $sSavedID) ) {
00026             $sOxId = $sSavedID;
00027             //$myConfig->delParameter( "saved_oxid");
00028             oxSession::deleteVar( "saved_oxid");
00029             $this->_aViewData["oxid"] =  $sOxId;
00030             // for reloading upper frame
00031             $this->_aViewData["updatelist"] =  "1";
00032         }
00033 
00034         $sITMDisp = "none";
00035 
00036         if ( $sOxId != "-1" && isset( $sOxId)) {
00037             // load object
00038             $oDiscount = oxNew( "oxdiscount" );
00039             $oDiscount->loadInLang( $this->_iEditLang, $sOxId );
00040 
00041             $oOtherLang = $oDiscount->getAvailableInLangs();
00042             if (!isset($oOtherLang[$this->_iEditLang])) {
00043                 // echo "language entry doesn't exist! using: ".key($oOtherLang);
00044                 $oDiscount->loadInLang( key($oOtherLang), $sOxId );
00045             }
00046 
00047             $this->_aViewData["edit"] =  $oDiscount;
00048 
00049 
00050             // remove already created languages
00051             $aLang = array_diff ( oxLang::getInstance()->getLanguageNames(), $oOtherLang );
00052 
00053             if ( count( $aLang))
00054                 $this->_aViewData["posslang"] = $aLang;
00055 
00056             foreach ( $oOtherLang as $id => $language) {
00057                 $oLang= new oxStdClass();
00058                 $oLang->sLangDesc = $language;
00059                 $oLang->selected = ($id == $this->_iEditLang);
00060                 $this->_aViewData["otherlang"][$id] = clone $oLang;
00061             }
00062 
00063             if ( $oDiscount->oxdiscount__oxaddsumtype->value == "itm")
00064                 $sITMDisp = "";
00065 
00066             // ITM load articles from chosen categorie
00067             $sITMChosenArtCat = oxConfig::getParameter( "itmartcat");
00068             $this->_aViewData["itmarttree"] = $this->_loadArticleList( $oDiscount->oxdiscount__oxitmartid->value, $sITMChosenArtCat);
00069             // generating category tree for artikel choose select list
00070             $this->_getCategoryTree( "artcattree", $sITMChosenArtCat);
00071         }
00072 
00073         // ITM display ?
00074         $this->_aViewData["itm_disp"]  =  $sITMDisp;
00075 
00076         if ( oxConfig::getParameter("aoc") ) {
00077 
00078             $aColumns = array();
00079             include_once 'inc/'.strtolower(__CLASS__).'.inc.php';
00080             $this->_aViewData['oxajax'] = $aColumns;
00081 
00082             return "popups/discount_main.tpl";
00083         }
00084         return "discount_main.tpl";
00085     }
00086 
00092     public function save()
00093     {
00094 
00095         $sOxId      = oxConfig::getParameter( "oxid");
00096         $aParams    = oxConfig::getParameter( "editval");
00097 
00098             // shopid
00099             $sShopID = oxSession::getVar( "actshop");
00100             $aParams['oxdiscount__oxshopid'] = $sShopID;
00101         $oAttr = oxNew( "oxdiscount" );
00102         if ( $sOxId != "-1")
00103             $oAttr->load( $sOxId );
00104         else
00105             $aParams['oxdiscount__oxid'] = null;
00106 
00107         // checkbox handling
00108         if ( !isset( $aParams['oxdiscount__oxactive']))
00109             $aParams['oxdiscount__oxactive'] = 0;
00110 
00111 
00112         //$aParams = $oAttr->ConvertNameArray2Idx( $aParams);
00113         $oAttr->setLanguage(0);
00114         $oAttr->assign( $aParams );
00115         $oAttr->setLanguage($this->_iEditLang);
00116         $oAttr = oxUtilsFile::getInstance()->processFiles( $oAttr );
00117         $oAttr->save();
00118         $this->_aViewData["updatelist"] = "1";
00119 
00120         // set oxid if inserted
00121         if ( $sOxId == "-1")
00122             oxSession::setVar( "saved_oxid", $oAttr->oxdiscount__oxid->value );
00123 
00124         return $this->autosave();
00125     }
00126 
00132     public function saveinnlang()
00133     {
00134 
00135         $sOxId      = oxConfig::getParameter( "oxid");
00136         $aParams    = oxConfig::getParameter( "editval");
00137 
00138             // shopid
00139             $sShopID = oxSession::getVar( "actshop");
00140             $aParams['oxdiscount__oxshopid'] = $sShopID;
00141         $oAttr = oxNew( "oxdiscount" );
00142         if ( $sOxId != "-1")
00143             $oAttr->load( $sOxId);
00144         else
00145             $aParams['oxdiscount__oxid'] = null;
00146         // checkbox handling
00147         if ( !isset( $aParams['oxdiscount__oxactive']))
00148             $aParams['oxdiscount__oxactive'] = 0;
00149 
00150 
00151         //$aParams = $oAttr->ConvertNameArray2Idx( $aParams);
00152         $oAttr->setLanguage(0);
00153         $oAttr->assign( $aParams);
00154         $oAttr->setLanguage($this->_iEditLang);
00155         $oAttr = oxUtilsFile::getInstance()->processFiles( $oAttr );
00156         $oAttr->save();
00157         $this->_aViewData["updatelist"] = "1";
00158 
00159         // set oxid if inserted
00160         if ( $sOxId == "-1")
00161             oxSession::setVar( "saved_oxid", $oAttr->oxdiscount__oxid->value );
00162 
00163         return $this->autosave();
00164     }
00165 
00174     protected function _loadArticleList( $sItmartid, $sITMChosenArtCat)
00175     {
00176         $sArticleTable = getViewName("oxarticles");
00177         $sO2CView = getViewName('oxobject2category');
00178         $sSuffix = oxLang::getInstance()->getLanguageTag();
00179         $sSelect = "select $sArticleTable.oxid, $sArticleTable.oxartnum, $sArticleTable.oxtitle$sSuffix from $sArticleTable ";
00180         if ( !isset( $sITMChosenArtCat) || !$sITMChosenArtCat || $sITMChosenArtCat == "oxrootid") {
00181             $sSelect .= "where $sArticleTable.oxid = '".$sItmartid."' ";
00182         } elseif ( $sITMChosenArtCat != "-1" && $sITMChosenArtCat != "oxrootid") {
00183             $oArticle = oxNew( 'oxarticle' );
00184             $sSelect .= "left join $sO2CView as oxobject2category on $sArticleTable.oxid=oxobject2category.oxobjectid where oxobject2category.oxcatnid = '$sITMChosenArtCat' and ".$oArticle->getSqlActiveSnippet()." order by oxobject2category.oxpos";
00185         } else {
00186             $sSelect .= "left join $sO2CView as oxobject2category on $sArticleTable.oxid=oxobject2category.oxobjectid where oxobject2category.oxcatnid is null AND $sArticleTable.oxparentid = '' ";
00187         }
00188         // We do NOT use Shop Framework here as we do have to much overhead
00189         // this list can be up to 1000 entries
00190         $oDB = oxDb::getDb();
00191         $aList = array();
00192         $oArt = new stdClass();
00193         $oArt->oxarticles__oxid     = new oxField("");
00194         $oArt->oxarticles__oxartnum = new oxField("");
00195         $oArt->oxarticles__oxtitle  = new oxField(" -- ");
00196         $aList[] = $oArt;
00197         $rs = $oDB->selectLimit( $sSelect, 1000, 0);
00198         if ($rs != false && $rs->recordCount() > 0) {
00199             while (!$rs->EOF) {
00200                 $oArt = new stdClass(); // #663
00201                 $oArt->oxarticles__oxid     = new oxField($rs->fields[0]);
00202                 $oArt->oxarticles__oxnid    = new oxField($rs->fields[0]);
00203                 $oArt->oxarticles__oxartnum = new oxField($rs->fields[1]);
00204                 $oArt->oxarticles__oxtitle  = new oxField($rs->fields[2]);
00205                 if ( $oArt->oxarticles__oxid == $sItmartid)
00206                     $oArt->selected = 1;
00207                 else
00208                     $oArt->selected = 0;
00209                 $aList[] = $oArt;
00210                 $rs->moveNext();
00211             }
00212         }
00213 
00214         return $aList;
00215     }
00216 }

Generated on Thu Dec 4 12:04:55 2008 for OXID eShop CE by  doxygen 1.5.5