newsletter_selection.php

Go to the documentation of this file.
00001 <?php
00002 
00009 class Newsletter_Selection extends oxAdminDetails
00010 {
00018     public function render()
00019     {
00020         parent::render();
00021 
00022         // all newslettergroups
00023         $oGroups = oxNew( "oxlist" );
00024         $oGroups->init( "oxgroups" );
00025         $oGroups->selectString( "select * from oxgroups" );
00026 
00027 
00028         $soxId = oxConfig::getParameter( "oxid");
00029         // check if we right now saved a new entry
00030         $sSavedID = oxConfig::getParameter( "saved_oxid");
00031         if ( ($soxId == "-1" || !isset( $soxId)) && isset( $sSavedID) ) {
00032             $soxId = $sSavedID;
00033             oxSession::deleteVar( "saved_oxid");
00034             $this->_aViewData["oxid"] =  $soxId;
00035             // for reloading upper frame
00036             $this->_aViewData["updatelist"] =  "1";
00037         }
00038 
00039         if ( $soxId != "-1" && isset( $soxId)) {
00040             // load object
00041             $oNewsletter = oxNew( "oxnewsletter" );
00042             $oNewsletter->load( $soxId );
00043             $oNewsletterGroups = $oNewsletter->getGroups();
00044             $this->_aViewData["edit"] =  $oNewsletter;
00045 
00046             // remove already added groups
00047             foreach ( $oNewsletterGroups as $oInGroup ) {
00048                 foreach ( $oGroups as $sKey => $oGroup ) {
00049                     if ( $oGroup->oxgroups__oxid->value == $oInGroup->oxgroups__oxid->value ) {
00050                         // already in, so lets remove it
00051                         $oGroups->offsetUnset( $sKey );
00052                         break;
00053                     }
00054                 }
00055             }
00056 
00057             // get nr. of users in these groups
00058             // we do not use lists here as we dont need this overhead right now
00059             $oDB = oxDb::getDb();
00060             $sSelectGroups =  "  ( oxobject2group.oxgroupsid in ( ";
00061             $blSep = false;
00062             foreach ( $oNewsletterGroups as $sInGroup) {
00063                 $sSearchKey = $sInGroup->oxgroups__oxid->value;
00064                 if ( $blSep)
00065                     $sSelectGroups .= ",";
00066                 $sSelectGroups .= "'$sSearchKey'";
00067                 $blSep = true;
00068             }
00069             $sSelectGroups .= ") ) ";
00070             // no group selected
00071             if ( !$blSep)
00072                 $sSelectGroups = " oxobject2group.oxobjectid is null ";
00073 
00074             $sSelect = "select oxnewssubscribed.oxemail from oxnewssubscribed left join oxobject2group on oxobject2group.oxobjectid = oxnewssubscribed.oxuserid where ( oxobject2group.oxshopid = '".$this->getConfig()->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";
00075 
00076             $rs = $oDB->execute( $sSelect);
00077             $iCnt = 0;
00078             if ($rs != false && $rs->recordCount() > 0) {
00079                 while (!$rs->EOF) {
00080                     $iCnt++;
00081                     $rs->moveNext();
00082                 }
00083             }
00084             $this->_aViewData["user"] =  $iCnt;
00085 
00086 
00087             if ( oxConfig::getParameter("aoc") ) {
00088 
00089                 $aColumns = array();
00090                 include_once 'inc/'.strtolower(__CLASS__).'.inc.php';
00091                 $this->_aViewData['oxajax'] = $aColumns;
00092 
00093                 return "popups/newsletter_selection.tpl";
00094             }
00095         }
00096 
00097         $this->_aViewData["allgroups"] =  $oGroups;
00098 
00099         return "newsletter_selection.tpl";
00100     }
00101 
00107     public function save()
00108     {
00109         $soxId      = oxConfig::getParameter( "oxid");
00110         $aParams    = oxConfig::getParameter( "editval");
00111 
00112         // shopid
00113         $sShopID = oxSession::getVar( "actshop");
00114         $aParams['oxnewsletter__oxshopid'] = $sShopID;
00115 
00116         $oNewsletter = oxNew( "oxNewsLetter" );
00117         if( $soxId != "-1")
00118             $oNewsletter->load( $soxId );
00119         else
00120             $aParams['oxnewsletter__oxid'] = null;
00121         //$aParams = $oNewsletter->ConvertNameArray2Idx( $aParams);
00122         $oNewsletter->assign( $aParams );
00123         $oNewsletter->save();
00124         // set oxid if inserted
00125         if ( $soxId == "-1")
00126             oxSession::setVar( "saved_oxid", $oNewsletter->oxnewsletter__oxid->value);
00127 
00128         return $this->autosave();
00129     }
00130 }

Generated on Thu Dec 4 12:04:55 2008 for OXID eShop CE by  doxygen 1.5.5