newsletter_send.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class Newsletter_Send extends oxAdminList
00008 {
00016     public function render()
00017     {
00018         $myConfig  = $this->getConfig();
00019         parent::render();
00020 
00021         $iStart = oxConfig::getParameter( "iStart");
00022         $iUser  = oxConfig::getParameter( "user");
00023         $sID      = oxConfig::getParameter( "id");
00024 
00025         $oNewsletter = oxNew( "oxNewsLetter" );
00026         $oNewsletter->load( $sID );
00027         $oNewsletterGroups = $oNewsletter->getGroups();
00028 
00029         // #493A - fetching cached newsletter info
00030         $oCachedNewsletter = oxSession::getVar("_oNewsletter");
00031         if ( isset($oCachedNewsletter)) {
00032             //checking if cached session id is the same as current user session id
00033             if ($oCachedNewsletter->sID != $sID)
00034                 oxSession::deleteVar("_oNewsletter");
00035             else {
00036                 // setting cached values
00037                 $iStart = $oCachedNewsletter->iStart;
00038                 $iUser  = $oCachedNewsletter->iUser;
00039                 $sID    = $oCachedNewsletter->sID;
00040             }
00041         } else {
00042             // setting initial values
00043             $oCachedNewsletter = new oxStdClass();
00044             $oCachedNewsletter->iStart = $iStart;
00045             $oCachedNewsletter->iUser  = $iUser;
00046             $oCachedNewsletter->sID    = $sID;
00047         }
00048 
00049         // send emails....
00050         $oDB = oxDb::getDb();
00051         $sSelectGroups =  " ( oxobject2group.oxgroupsid in ( ";
00052         $blSep = false;
00053         foreach ( $oNewsletterGroups as $sInGroup) {
00054             $sSearchKey = $sInGroup->oxgroups__oxid->value;
00055             if ( $blSep)
00056                 $sSelectGroups .= ",";
00057             $sSelectGroups .= "'$sSearchKey'";
00058             $blSep = true;
00059         }
00060         $sSelectGroups .= ") )";
00061         // no group selected
00062         if ( !$blSep)
00063             $sSelectGroups = " oxobject2group.oxobjectid is null ";
00064 
00065         $sSelect = "select oxnewssubscribed.oxuserid, oxnewssubscribed.oxemail, oxnewssubscribed.oxsal, oxnewssubscribed.oxfname, oxnewssubscribed.oxlname from oxnewssubscribed left join oxobject2group on oxobject2group.oxobjectid = oxnewssubscribed.oxuserid where ( oxobject2group.oxshopid = '".$myConfig->getShopID()."' or oxobject2group.oxshopid is null ) and $sSelectGroups and oxnewssubscribed.oxdboptin = 1 and (not (oxnewssubscribed.oxemailfailed = '1')) and (not(oxnewssubscribed.oxemailfailed = \"1\")) group by oxnewssubscribed.oxemail";
00066 
00067         $rs = $oDB->selectLimit( $sSelect, $myConfig->getConfigParam( 'iCntofMails' ), $iStart);
00068 
00069         ini_set("session.gc_maxlifetime", 36000);
00070 
00071         if ($rs != false && $rs->recordCount() > 0) {
00072             while (!$rs->EOF) {
00073                 $sUserID = $rs->fields[0];
00074 
00075                 // must check if such user is in DB
00076                 if( !$oDB->getOne("select oxid from oxuser where oxid = '$sUserID'"))
00077                     $sUserID = null;
00078 
00079                 // #559
00080                 if ( !isset( $sUserID) || !$sUserID) {
00081                      // there is no user object so we fake one
00082                     $oUser = oxNew( "oxuser" );
00083                     $oUser->oxuser__oxusername = new oxField($rs->fields[1]);
00084                     $oUser->oxuser__oxsal      = new oxField($rs->fields[2]);
00085                     $oUser->oxuser__oxfname    = new oxField($rs->fields[3]);
00086                     $oUser->oxuser__oxlname    = new oxField($rs->fields[4]);
00087                     $oNewsletter->prepare( $oUser, $myConfig->getConfigParam( 'bl_perfLoadAktion' ) );
00088                 }
00089                 else
00090                     $oNewsletter->prepare( $sUserID, $myConfig->getConfigParam( 'bl_perfLoadAktion' ) );
00091 
00092                 if ( $oNewsletter->send() ) {
00093                      // add user history
00094                     $oRemark = oxNew( "oxremark" );
00095                     $oRemark->oxremark__oxtext     = new oxField($oNewsletter->sPlainText);
00096                     $oRemark->oxremark__oxparentid = new oxField($sUserID);
00097                     $sShopID = oxSession::getVar( "actshop");
00098                     $sShopID = oxSession::setVar( "keepalive", "yes");
00099                     $oRemark->oxremark__oxshopid   = new oxField($sShopID);
00100                     $oRemark->save();
00101                 } else
00102                     echo( "problem sending to : ".$rs->fields[1]."<br>");
00103 
00104 
00105                    $rs->moveNext();
00106             }
00107         }
00108 
00109         // adavance mail pointer and set parameter
00110         $iStart += $myConfig->getConfigParam( 'iCntofMails' );
00111 
00112         // #493A - setting new values
00113         $oCachedNewsletter->iStart = $iStart;
00114         $oCachedNewsletter->iUser  = $iUser;
00115         $oCachedNewsletter->sID    = $sID;
00116 
00117         $this->_aViewData["iStart"]     =  $iStart;
00118         $this->_aViewData["user"]     =  $iUser;
00119         $this->_aViewData["id"]         =  $sID;
00120 
00121 
00122         // end ?
00123         if ( $iStart < $iUser) {
00124                $sPage = "newsletter_send.tpl";
00125             // #493A - saving changes
00126             oxSession::setVar("_oNewsletter", $oCachedNewsletter);
00127         } else {
00128                $sPage = "newsletter_done.tpl";
00129             // #493A - deleting cache variable
00130             oxSession::deleteVar("_oNewsletter");
00131         }
00132 
00133         return $sPage;
00134     }
00135 
00136     /*
00137      * Overrides parent method to pass referred id
00138      *
00139      * @param string $sId class name
00140      */
00141     protected function _setupNavigation( $sId )
00142     {
00143         parent::_setupNavigation( 'newsletter_list' );
00144     }
00145 }

Generated on Wed May 13 13:25:50 2009 for OXID eShop CE by  doxygen 1.5.5