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         if ( $sOxId != "-1" && isset( $sOxId)) {
00034             // load object
00035             $oDiscount = oxNew( "oxdiscount" );
00036             $oDiscount->loadInLang( $this->_iEditLang, $sOxId );
00037 
00038             $oOtherLang = $oDiscount->getAvailableInLangs();
00039             if (!isset($oOtherLang[$this->_iEditLang])) {
00040                 // echo "language entry doesn't exist! using: ".key($oOtherLang);
00041                 $oDiscount->loadInLang( key( $oOtherLang ), $sOxId );
00042             }
00043 
00044             $this->_aViewData["edit"] =  $oDiscount;
00045 
00046 
00047             // remove already created languages
00048             $aLang = array_diff ( oxLang::getInstance()->getLanguageNames(), $oOtherLang );
00049 
00050             if ( count( $aLang ) ) {
00051                 $this->_aViewData["posslang"] = $aLang;
00052             }
00053 
00054             foreach ( $oOtherLang as $id => $language) {
00055                 $oLang= new oxStdClass();
00056                 $oLang->sLangDesc = $language;
00057                 $oLang->selected = ($id == $this->_iEditLang);
00058                 $this->_aViewData["otherlang"][$id] = clone $oLang;
00059             }
00060         }
00061 
00062         if ( ( $iAoc = oxConfig::getParameter("aoc") ) ) {
00063             $aColumns = array();
00064             if ( $iAoc == "1" ) {
00065                 include_once 'inc/'.strtolower(__CLASS__).'.inc.php';
00066                 $this->_aViewData['oxajax'] = $aColumns;
00067                 return "popups/discount_main.tpl";
00068             } elseif ( $iAoc == "2" ) {
00069                 // generating category tree for artikel choose select list
00070                 $this->_getCategoryTree( "artcattree", null );
00071 
00072                 include_once 'inc/discount_item.inc.php';
00073                 $this->_aViewData['oxajax'] = $aColumns;
00074                 return "popups/discount_item.tpl";
00075             }
00076         }
00077         return "discount_main.tpl";
00078     }
00079 
00085     public function getItemDiscountProductTitle()
00086     {
00087         $sTitle = false;
00088         $sOxId = oxConfig::getParameter( "oxid");
00089         if ( $sOxId != "-1" && isset( $sOxId)) {
00090             $sViewName = getViewName( "oxarticles" );
00091 
00092             $sLang = oxLang::getInstance()->getLanguageTag($this->_iEditLang);
00093 
00094             $oDb = oxDb::getDb();
00095             $sQ = "select concat( $sViewName.oxartnum, ' ', $sViewName.oxtitle$sLang ) from oxdiscount
00096                    left join $sViewName on $sViewName.oxid=oxdiscount.oxitmartid
00097                    where oxdiscount.oxitmartid != '' and oxdiscount.oxid=" . $oDb->quote( $sOxId );
00098             $sTitle = $oDb->getOne( $sQ );
00099         }
00100 
00101         return $sTitle ? $sTitle : " -- ";
00102     }
00103 
00109     public function save()
00110     {
00111 
00112         $sOxId      = oxConfig::getParameter( "oxid");
00113         $aParams    = oxConfig::getParameter( "editval");
00114 
00115             // shopid
00116             $sShopID = oxSession::getVar( "actshop");
00117             $aParams['oxdiscount__oxshopid'] = $sShopID;
00118         $oAttr = oxNew( "oxdiscount" );
00119         if ( $sOxId != "-1")
00120             $oAttr->load( $sOxId );
00121         else
00122             $aParams['oxdiscount__oxid'] = null;
00123 
00124         // checkbox handling
00125         if ( !isset( $aParams['oxdiscount__oxactive']))
00126             $aParams['oxdiscount__oxactive'] = 0;
00127 
00128 
00129         //$aParams = $oAttr->ConvertNameArray2Idx( $aParams);
00130         $oAttr->setLanguage(0);
00131         $oAttr->assign( $aParams );
00132         $oAttr->setLanguage($this->_iEditLang);
00133         $oAttr = oxUtilsFile::getInstance()->processFiles( $oAttr );
00134         $oAttr->save();
00135         $this->_aViewData["updatelist"] = "1";
00136 
00137         // set oxid if inserted
00138         if ( $sOxId == "-1")
00139             oxSession::setVar( "saved_oxid", $oAttr->oxdiscount__oxid->value );
00140     }
00141 
00147     public function saveinnlang()
00148     {
00149 
00150         $sOxId      = oxConfig::getParameter( "oxid");
00151         $aParams    = oxConfig::getParameter( "editval");
00152 
00153             // shopid
00154             $sShopID = oxSession::getVar( "actshop");
00155             $aParams['oxdiscount__oxshopid'] = $sShopID;
00156         $oAttr = oxNew( "oxdiscount" );
00157         if ( $sOxId != "-1")
00158             $oAttr->load( $sOxId);
00159         else
00160             $aParams['oxdiscount__oxid'] = null;
00161         // checkbox handling
00162         if ( !isset( $aParams['oxdiscount__oxactive']))
00163             $aParams['oxdiscount__oxactive'] = 0;
00164 
00165 
00166         //$aParams = $oAttr->ConvertNameArray2Idx( $aParams);
00167         $oAttr->setLanguage(0);
00168         $oAttr->assign( $aParams);
00169         $oAttr->setLanguage($this->_iEditLang);
00170         $oAttr = oxUtilsFile::getInstance()->processFiles( $oAttr );
00171         $oAttr->save();
00172         $this->_aViewData["updatelist"] = "1";
00173 
00174         // set oxid if inserted
00175         if ( $sOxId == "-1")
00176             oxSession::setVar( "saved_oxid", $oAttr->oxdiscount__oxid->value );
00177     }
00178 }