pricealarm_main.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class PriceAlarm_Main extends oxAdminDetails
00009 {
00010 
00018     public function render()
00019     {
00020         $myConfig = $this->getConfig();
00021 
00022         // #1140 R - price must be checked from the object.
00023         $sSql = "select oxarticles.oxid, oxpricealarm.oxprice from oxpricealarm, oxarticles " .
00024                 "where oxarticles.oxid = oxpricealarm.oxartid and oxpricealarm.oxsended = '000-00-00 00:00:00'";
00025         $rs = oxDb::getDb()->Execute($sSql);
00026         $iAllCnt = 0;
00027 
00028         if ($rs != false && $rs->recordCount() > 0) {
00029             while (!$rs->EOF) {
00030                 $oArticle = oxNew("oxarticle");
00031                 $oArticle->load($rs->fields[0]);
00032                 if ($oArticle->getPrice()->getBruttoPrice() <= $rs->fields[1]) {
00033                     $iAllCnt++;
00034                 }
00035                 $rs->moveNext();
00036             }
00037         }
00038         $this->_aViewData['iAllCnt'] = $iAllCnt;
00039 
00040         $soxId = $this->_aViewData["oxid"] = $this->getEditObjectId();
00041         if ($soxId != "-1" && isset($soxId)) {
00042             // load object
00043             $oPricealarm = oxNew("oxpricealarm");
00044             $oPricealarm->load($soxId);
00045 
00046             // customer info
00047             $oUser = null;
00048             if ($oPricealarm->oxpricealarm__oxuserid->value) {
00049                 $oUser = oxNew("oxuser");
00050                 $oUser->load($oPricealarm->oxpricealarm__oxuserid->value);
00051                 $oPricealarm->oUser = $oUser;
00052             }
00053 
00054             //
00055             $oShop = oxNew("oxshop");
00056             $oShop->load($myConfig->getShopId());
00057             $oShop = $this->addGlobalParams($oShop);
00058 
00059             if (!($iLang = $oPricealarm->oxpricealarm__oxlang->value)) {
00060                 $iLang = 0;
00061             }
00062 
00063             $oLang = oxRegistry::getLang();
00064             $aLanguages = $oLang->getLanguageNames();
00065             $this->_aViewData["edit_lang"] = $aLanguages[$iLang];
00066             // rendering mail message text
00067             $oLetter = new stdClass();
00068             $aParams = oxRegistry::getConfig()->getRequestParameter("editval");
00069             if (isset($aParams['oxpricealarm__oxlongdesc']) && $aParams['oxpricealarm__oxlongdesc']) {
00070                 $oLetter->oxpricealarm__oxlongdesc = new oxField(stripslashes($aParams['oxpricealarm__oxlongdesc']), oxField::T_RAW);
00071             } else {
00072                 /*
00073                                 $smarty = oxRegistry::get("oxUtilsView")->getSmarty();
00074                                 $smarty->assign( "shop", $oShop );
00075                                 $smarty->assign( "product", $oPricealarm->getArticle() );
00076                                 $smarty->assign( "bidprice", $oPricealarm->getFProposedPrice());
00077                                 $smarty->assign( "currency", $oPricealarm->getPriceAlarmCurrency() );
00078                                 $smarty->assign( "currency", $oPricealarm->getPriceAlarmCurrency() );
00079                 */
00080 
00081 
00082                 $oEmail = oxNew("oxEmail");
00083                 $sDesc = $oEmail->sendPricealarmToCustomer($oPricealarm->oxpricealarm__oxemail->value, $oPricealarm, null, true);
00084 
00085                 $iOldLang = $oLang->getTplLanguage();
00086                 $oLang->setTplLanguage($iLang);
00087                 $oLetter->oxpricealarm__oxlongdesc = new oxField($sDesc, oxField::T_RAW);
00088                 $oLang->setTplLanguage($iOldLang);
00089             }
00090 
00091             $this->_aViewData["editor"] = $this->_generateTextEditor("100%", 300, $oLetter, "oxpricealarm__oxlongdesc", "details.tpl.css");
00092             $this->_aViewData["edit"] = $oPricealarm;
00093             $this->_aViewData["actshop"] = $myConfig->getShopId();
00094         }
00095 
00096         parent::render();
00097 
00098         return "pricealarm_main.tpl";
00099     }
00100 
00104     public function send()
00105     {
00106         $blError = true;
00107 
00108         // error
00109         if (($sOxid = $this->getEditObjectId())) {
00110             $oPricealarm = oxNew("oxpricealarm");
00111             $oPricealarm->load($sOxid);
00112 
00113             $aParams = oxRegistry::getConfig()->getRequestParameter("editval");
00114             $sMailBody = isset($aParams['oxpricealarm__oxlongdesc']) ? stripslashes($aParams['oxpricealarm__oxlongdesc']) : '';
00115             if ($sMailBody) {
00116                 $sMailBody = oxRegistry::get("oxUtilsView")->parseThroughSmarty($sMailBody, $oPricealarm->getId());
00117             }
00118 
00119             $sRecipient = $oPricealarm->oxpricealarm__oxemail->value;
00120 
00121             $oEmail = oxNew('oxemail');
00122             $blSuccess = (int) $oEmail->sendPricealarmToCustomer($sRecipient, $oPricealarm, $sMailBody);
00123 
00124             // setting result message
00125             if ($blSuccess) {
00126                 $oPricealarm->oxpricealarm__oxsended->setValue(date("Y-m-d H:i:s"));
00127                 $oPricealarm->save();
00128                 $blError = false;
00129             }
00130         }
00131 
00132         if (!$blError) {
00133             $this->_aViewData["mail_succ"] = 1;
00134         } else {
00135             $this->_aViewData["mail_err"] = 1;
00136         }
00137     }
00138 }