pricealarm_main.php

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