discount_main.php

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

Generated by  doxygen 1.6.2