Go to the documentation of this file.00001 <?php
00002
00007 class Newsletter_Send extends oxAdminList
00008 {
00014 protected $_aMailErrors = array();
00015
00023 public function render()
00024 {
00025 $myConfig = $this->getConfig();
00026 parent::render();
00027
00028 $iStart = (int) oxConfig::getParameter( "iStart" );
00029 $iUser = oxConfig::getParameter( "user" );
00030 $sID = oxConfig::getParameter( "id" );
00031
00032 $oNewsletter = oxNew( "oxNewsLetter" );
00033 $oNewsletter->load( $sID );
00034 $oNewsletterGroups = $oNewsletter->getGroups();
00035
00036
00037 $oCachedNewsletter = oxSession::getVar( "_oNewsletter" );
00038 if ( isset( $oCachedNewsletter ) ) {
00039
00040 if ( $oCachedNewsletter->sID != $sID ) {
00041 oxSession::deleteVar( "_oNewsletter" );
00042 } else {
00043
00044 $iStart = $oCachedNewsletter->iStart;
00045 $iUser = $oCachedNewsletter->iUser;
00046 $sID = $oCachedNewsletter->sID;
00047 }
00048 } else {
00049
00050 $oCachedNewsletter = new oxStdClass();
00051 $oCachedNewsletter->iStart = $iStart;
00052 $oCachedNewsletter->iUser = $iUser;
00053 $oCachedNewsletter->sID = $sID;
00054 }
00055
00056
00057 $oDB = oxDb::getDb();
00058 $sSelectGroups = " ( oxobject2group.oxgroupsid in ( ";
00059 $blSep = false;
00060 foreach ( $oNewsletterGroups as $sInGroup ) {
00061 $sSearchKey = $sInGroup->oxgroups__oxid->value;
00062 if ( $blSep ) {
00063 $sSelectGroups .= ",";
00064 }
00065 $sSelectGroups .= $oDB->quote( $sSearchKey );
00066 $blSep = true;
00067 }
00068 $sSelectGroups .= ") )";
00069
00070
00071 if ( !$blSep ) {
00072 $sSelectGroups = " oxobject2group.oxobjectid is null ";
00073 }
00074
00075 $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')) group by oxnewssubscribed.oxemail";
00076 $rs = $oDB->selectLimit( $sSelect, $myConfig->getConfigParam( 'iCntofMails' ), $iStart );
00077 ini_set( "session.gc_maxlifetime", 36000 );
00078
00079 if ( $rs != false && $rs->recordCount() > 0 ) {
00080
00081 $sShopID = oxSession::getVar( "actshop");
00082 $blLoadAction = $myConfig->getConfigParam( 'bl_perfLoadAktion' );
00083
00084 while ( !$rs->EOF ) {
00085 $sUserID = $rs->fields[0];
00086
00087
00088 if ( !$oDB->getOne( "select oxid from oxuser where oxid = '$sUserID'" ) ) {
00089 $sUserID = null;
00090 }
00091
00092
00093 if ( !isset( $sUserID ) || !$sUserID ) {
00094
00095 $oUser = oxNew( "oxuser" );
00096 $oUser->oxuser__oxusername = new oxField( $rs->fields[1] );
00097 $oUser->oxuser__oxsal = new oxField( $rs->fields[2] );
00098 $oUser->oxuser__oxfname = new oxField( $rs->fields[3] );
00099 $oUser->oxuser__oxlname = new oxField( $rs->fields[4] );
00100 $oNewsletter->prepare( $oUser, $blLoadAction );
00101 } else {
00102 $oNewsletter->prepare( $sUserID, $blLoadAction );
00103 }
00104
00105 if ( $oNewsletter->send() ) {
00106
00107 $oRemark = oxNew( "oxremark" );
00108 $oRemark->oxremark__oxtext = new oxField( $oNewsletter->getPlainText() );
00109 $oRemark->oxremark__oxparentid = new oxField( $sUserID );
00110 $oRemark->oxremark__oxshopid = new oxField( $sShopID );
00111 $oRemark->oxremark__oxtype = new oxField( "n" );
00112 $oRemark->save();
00113 oxSession::setVar( "keepalive", "yes");
00114 } else {
00115 $this->_aMailErrors[] = "problem sending to : ".$rs->fields[1]."<br>";
00116 }
00117
00118 $rs->moveNext();
00119 }
00120 }
00121
00122
00123 $iStart += $myConfig->getConfigParam( 'iCntofMails' );
00124
00125
00126 $oCachedNewsletter->iStart = $iStart;
00127 $oCachedNewsletter->iUser = $iUser;
00128 $oCachedNewsletter->sID = $sID;
00129
00130 $this->_aViewData["iStart"] = $iStart;
00131 $this->_aViewData["user"] = $iUser;
00132 $this->_aViewData["id"] = $sID;
00133
00134
00135 if ( $iStart < $iUser) {
00136 $sPage = "newsletter_send.tpl";
00137
00138 oxSession::setVar( "_oNewsletter", $oCachedNewsletter );
00139 } else {
00140 $sPage = "newsletter_done.tpl";
00141
00142 oxSession::deleteVar( "_oNewsletter" );
00143 }
00144
00145 return $sPage;
00146 }
00147
00153 public function getMailErrors()
00154 {
00155 return $this->_aMailErrors;
00156 }
00157
00165 protected function _setupNavigation( $sId )
00166 {
00167 parent::_setupNavigation( 'newsletter_list' );
00168 }
00169 }