pricealarm_send.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class PriceAlarm_Send extends oxAdminList
00008 {
00009 
00015     protected $_iDefEdit = 1;
00016 
00024     public function render()
00025     {
00026         parent::render();
00027 
00028         $myConfig = $this->getConfig();
00029         $oDB = oxDb::getDb(oxDb::FETCH_MODE_ASSOC);
00030 
00031         ini_set("session.gc_maxlifetime", 36000);
00032 
00033         $iStart = oxRegistry::getConfig()->getRequestParameter("iStart");
00034         $iAllCnt = oxRegistry::getConfig()->getRequestParameter("iAllCnt");
00035         // #1140 R
00036         $sSelect = "select oxpricealarm.oxid, oxpricealarm.oxemail, oxpricealarm.oxartid, oxpricealarm.oxprice " .
00037                    "from oxpricealarm, oxarticles where oxarticles.oxid = oxpricealarm.oxartid " .
00038                    "and oxpricealarm.oxsended = '0000-00-00 00:00:00'";
00039         if (isset($iStart)) {
00040             $rs = $oDB->SelectLimit($sSelect, $myConfig->getConfigParam('iCntofMails'), $iStart);
00041         } else {
00042             $rs = $oDB->Execute($sSelect);
00043         }
00044 
00045         $iAllCntTmp = 0;
00046 
00047         if ($rs != false && $rs->recordCount() > 0) {
00048             while (!$rs->EOF) {
00049                 $oArticle = oxNew("oxarticle");
00050                 $oArticle->load($rs->fields['oxid']);
00051                 if ($oArticle->getPrice()->getBruttoPrice() <= $rs->fields['oxprice']) {
00052                     $this->sendeMail(
00053                         $rs->fields['oxemail'],
00054                         $rs->fields['oxartid'],
00055                         $rs->fields['oxid'],
00056                         $rs->fields['oxprice']
00057                     );
00058                     $iAllCntTmp++;
00059                 }
00060                 $rs->moveNext();
00061             }
00062         }
00063         if (!isset($iStart)) {
00064             // first call
00065             $iStart = 0;
00066             $iAllCnt = $iAllCntTmp;
00067         }
00068 
00069 
00070         // adavance mail pointer and set parameter
00071         $iStart += $myConfig->getConfigParam('iCntofMails');
00072 
00073         $this->_aViewData["iStart"] = $iStart;
00074         $this->_aViewData["iAllCnt"] = $iAllCnt;
00075         $this->_aViewData["actlang"] = oxRegistry::getLang()->getBaseLanguage();
00076 
00077         // end ?
00078         if ($iStart < $iAllCnt) {
00079             $sPage = "pricealarm_send.tpl";
00080         } else {
00081             $sPage = "pricealarm_done.tpl";
00082         }
00083 
00084         return $sPage;
00085     }
00086 
00092     protected function _setupNavigation($sId)
00093     {
00094         parent::_setupNavigation('pricealarm_list');
00095     }
00096 
00105     public function sendeMail($sEMail, $sProductID, $sPricealarmID, $sBidPrice)
00106     {
00107         $myConfig = $this->getConfig();
00108         $oAlarm = oxNew("oxpricealarm");
00109         $oAlarm->load($sPricealarmID);
00110 
00111         $oLang = oxRegistry::getLang();
00112         $iLang = (int) $oAlarm->oxpricealarm__oxlang->value;
00113 
00114         $iOldLangId = $oLang->getTplLanguage();
00115         $oLang->setTplLanguage($iLang);
00116 
00117         $oEmail = oxNew('oxemail');
00118         $blSuccess = (int) $oEmail->sendPricealarmToCustomer($sEMail, $oAlarm);
00119 
00120         $oLang->setTplLanguage($iOldLangId);
00121 
00122         if ($blSuccess) {
00123             $oAlarm->oxpricealarm__oxsended = new oxField(date("Y-m-d H:i:s"));
00124             $oAlarm->save();
00125         }
00126 
00127     }
00128 }