00001 <?php
00002
00007 class PriceAlarm_Send extends oxAdminList
00008 {
00014 protected $_iDefEdit = 1;
00022 public function render()
00023 {
00024 $myConfig = $this->getConfig();
00025 $oDB = oxDb::getDb();
00026
00027 parent::render();
00028
00029 ini_set("session.gc_maxlifetime", 36000);
00030
00031 $iStart = oxConfig::getParameter( "iStart");
00032 $iAllCnt = oxConfig::getParameter( "iAllCnt");
00033
00034 $sSelect = "select oxpricealarm.oxid, oxpricealarm.oxemail, oxpricealarm.oxartid, oxpricealarm.oxprice from oxpricealarm, oxarticles where oxarticles.oxid = oxpricealarm.oxartid and oxpricealarm.oxsended = '0000-00-00 00:00:00'";
00035 if (isset($iStart))
00036 $rs = $oDB->SelectLimit( $sSelect, $myConfig->getConfigParam( 'iCntofMails' ), $iStart);
00037 else
00038 $rs = $oDB->Execute( $sSelect);
00039
00040 $iAllCnt_counting=0;
00041
00042 if ($rs != false && $rs->recordCount() > 0) {
00043 while (!$rs->EOF) {
00044 $oArticle = oxNew("oxarticle" );
00045 $oArticle->load($rs->fields[2]);
00046 if ($oArticle->getPrice()->getBruttoPrice() <= $rs->fields[3]) {
00047 $this->sendeMail( $rs->fields[1], $rs->fields[2], $rs->fields[0], $rs->fields[3]);
00048 $iAllCnt_counting++;
00049 }
00050 $rs->moveNext();
00051 }
00052 }
00053 if ( !isset( $iStart)) {
00054
00055 $iStart = 0;
00056 $iAllCnt = $iAllCnt_counting;
00057 }
00058
00059
00060
00061 $iStart += $myConfig->getConfigParam( 'iCntofMails' );
00062
00063 $this->_aViewData["iStart"] = $iStart;
00064 $this->_aViewData["iAllCnt"] = $iAllCnt;
00065 $this->_aViewData["actlang"] = oxLang::getInstance()->getBaseLanguage();
00066
00067
00068 if ( $iStart < $iAllCnt)
00069 $sPage = "pricealarm_send.tpl";
00070 else
00071 $sPage = "pricealarm_done.tpl";
00072
00073 return $sPage;
00074 }
00075
00081 protected function _setupNavigation( $sId )
00082 {
00083 parent::_setupNavigation( 'pricealarm_list' );
00084 }
00085
00096 public function sendeMail( $sEMail, $sProductID, $sPricealarmID, $sBidPrice)
00097 {
00098 $myConfig = $this->getConfig();
00099 $oPricealarm = oxNew( "oxpricealarm" );
00100 $oPricealarm->load( $sPricealarmID);
00101
00102
00103 $oShop = oxNew( "oxshop" );
00104
00105 $oShop->load( $oPricealarm->oxpricealarm__oxshopid->value);
00106 $oShop = $this->addGlobalParams( $oShop);
00107
00108 $oArticle = oxNew( "oxarticle" );
00109 $oArticle->load( $sProductID);
00110
00111 if ( $oArticle->oxarticles__oxparentid->value && !$oArticle->oxarticles__oxtitle->value) {
00112 $oParent = oxNew( "oxarticle" );
00113 $oParent->load($oArticle->oxarticles__oxparentid->value);
00114 $oArticle->oxarticles__oxtitle->setValue($oParent->oxarticles__oxtitle->value." ".$oArticle->oxarticles__oxvarselect->value);
00115 }
00116
00117 $oDefCurr = $myConfig->getActShopCurrencyObject();
00118
00119 $oAlarm = oxNew( "oxpricealarm" );
00120 $oAlarm->load( $sPricealarmID);
00121
00122 $oThisCurr = $myConfig->getCurrencyObject( $oAlarm->oxpricealarm__oxcurrency->value);
00123
00124 if ( !$oThisCurr ) {
00125 $oThisCurr = $oDefCurr;
00126 $oAlarm->oxpricealarm__oxcurrency->setValue($oDefCurr->name);
00127 }
00128
00129
00130
00131 $oLang = oxLang::getInstance();
00132 $oArticle->oxarticles__oxprice->setValue($oArticle->getPrice()->getBruttoPrice() * $oThisCurr->rate);
00133 $oArticle->fprice = $oLang->formatCurrency( $oArticle->oxarticles__oxprice->value, $oThisCurr);
00134 $oAlarm->fpricealarmprice = $oLang->formatCurrency( $oAlarm->oxpricealarm__oxprice->value, $oThisCurr);
00135
00136 $oxEMail = oxNew( "oxemail" );
00137 $oxEMail->From = $oShop->oxshops__oxorderemail->value;
00138 $oxEMail->FromName = $oShop->oxshops__oxname->getRawValue();
00139 $oxEMail->Host = $oShop->oxshops__oxsmtp->value;
00140 $oxEMail->SetSMTP( $oShop);
00141 $oxEMail->WordWrap = 100;
00142
00143
00144 $smarty = oxUtilsView::getInstance()->getSmarty();
00145 $smarty->assign( "shop", $oShop );
00146 $smarty->assign( "product", $oArticle );
00147 $smarty->assign( "bidprice", $oLang->formatCurrency($sBidPrice, $oThisCurr) );
00148 $smarty->assign( "currency", $oThisCurr );
00149 $smarty->assign( "shopImageDir", $myConfig->getImageUrl( false , false ) );
00150
00151 $iLang = @$oAlarm->oxpricealarm__oxlang->value;
00152 if (!$iLang)
00153 $iLang = 0;
00154
00155 $old_iLang = $oLang->getTplLanguage();
00156 $oLang->setTplLanguage( $iLang );
00157
00158 $oxEMail->Body = $smarty->fetch( "email_pricealarm_customer.tpl");
00159 $oxEMail->Subject = $oShop->oxshops__oxname->getRawValue();
00160 $oxEMail->AddAddress( $sEMail, $sEMail );
00161 $oxEMail->AddReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue());
00162 $blSuccess = $oxEMail->send();
00163
00164 $oLang->setTplLanguage( $old_iLang );
00165
00166 if ( $blSuccess) {
00167 $timeout = time();
00168 $now = date("Y-m-d H:i:s", $timeout);
00169 $oAlarm->oxpricealarm__oxsended->setValue($now);
00170 $oAlarm->save();
00171 }
00172
00173 }
00174 }