00001 <?php
00002
00008 class Newsletter_Selection extends oxAdminDetails
00009 {
00017 public function render()
00018 {
00019 parent::render();
00020
00021
00022 $oGroups = oxNew( "oxlist" );
00023 $oGroups->init( "oxgroups" );
00024 $oGroups->selectString( "select * from oxgroups" );
00025
00026
00027 $soxId = oxConfig::getParameter( "oxid");
00028
00029 $sSavedID = oxConfig::getParameter( "saved_oxid");
00030 if ( ($soxId == "-1" || !isset( $soxId)) && isset( $sSavedID) ) {
00031 $soxId = $sSavedID;
00032 oxSession::deleteVar( "saved_oxid");
00033 $this->_aViewData["oxid"] = $soxId;
00034
00035 $this->_aViewData["updatelist"] = "1";
00036 }
00037
00038 if ( $soxId != "-1" && isset( $soxId)) {
00039
00040 $oNewsletter = oxNew( "oxnewsletter" );
00041 $oNewsletter->load( $soxId );
00042 $oNewsletterGroups = $oNewsletter->getGroups();
00043 $this->_aViewData["edit"] = $oNewsletter;
00044
00045
00046 foreach ( $oNewsletterGroups as $oInGroup ) {
00047 foreach ( $oGroups as $sKey => $oGroup ) {
00048 if ( $oGroup->oxgroups__oxid->value == $oInGroup->oxgroups__oxid->value ) {
00049
00050 $oGroups->offsetUnset( $sKey );
00051 break;
00052 }
00053 }
00054 }
00055
00056
00057
00058 $oDB = oxDb::getDb();
00059 $sSelectGroups = " ( oxobject2group.oxgroupsid in ( ";
00060 $blSep = false;
00061 foreach ( $oNewsletterGroups as $sInGroup) {
00062 $sSearchKey = $sInGroup->oxgroups__oxid->value;
00063 if ( $blSep)
00064 $sSelectGroups .= ",";
00065 $sSelectGroups .= "'$sSearchKey'";
00066 $blSep = true;
00067 }
00068 $sSelectGroups .= ") ) ";
00069
00070 if ( !$blSep)
00071 $sSelectGroups = " oxobject2group.oxobjectid is null ";
00072
00073 $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";
00074
00075 $rs = $oDB->execute( $sSelect);
00076 $iCnt = 0;
00077 if ($rs != false && $rs->recordCount() > 0) {
00078 while (!$rs->EOF) {
00079 $iCnt++;
00080 $rs->moveNext();
00081 }
00082 }
00083 $this->_aViewData["user"] = $iCnt;
00084
00085
00086 if ( oxConfig::getParameter("aoc") ) {
00087
00088 $aColumns = array();
00089 include_once 'inc/'.strtolower(__CLASS__).'.inc.php';
00090 $this->_aViewData['oxajax'] = $aColumns;
00091
00092 return "popups/newsletter_selection.tpl";
00093 }
00094 }
00095
00096 $this->_aViewData["allgroups"] = $oGroups;
00097
00098 return "newsletter_selection.tpl";
00099 }
00100
00106 public function save()
00107 {
00108 $soxId = oxConfig::getParameter( "oxid");
00109 $aParams = oxConfig::getParameter( "editval");
00110
00111
00112 $sShopID = oxSession::getVar( "actshop");
00113 $aParams['oxnewsletter__oxshopid'] = $sShopID;
00114
00115 $oNewsletter = oxNew( "oxNewsLetter" );
00116 if( $soxId != "-1")
00117 $oNewsletter->load( $soxId );
00118 else
00119 $aParams['oxnewsletter__oxid'] = null;
00120
00121 $oNewsletter->assign( $aParams );
00122 $oNewsletter->save();
00123
00124 if ( $soxId == "-1")
00125 oxSession::setVar( "saved_oxid", $oNewsletter->oxnewsletter__oxid->value);
00126 }
00127 }