Forums

Unfortunately no one can be told what FluxBB is - you have to see it for yourself.

You are not logged in.

#1 2009-08-31 07:56:34

OJM
Member
Registered: 2009-07-29
Posts: 9

Email Global Plus - Ignore Bans

Hi,

I have the Email Global Plus installed, which allows me to send emails to all members.

Unfortunately, it only looks at the 'subscribed' flag in the database, and not at the 'bans' list, so it emails all my banned users which creates a lot of bounce backs as you can imagine.

Would someone be so kind as to have a look at the code and implement the changes I need to make so it a) ignores users on the ban list for the members count in the preview screen, and b) ignores users on the ban list when the email is sent.

Thank you!

Oli

<?php
/***********************************************************************

  Copyright (C) 2005  Terrell Russell (punbb@terrellrussell.com)
  
  Copyright (C) 2006  FoxMaSk (foxmask@punbb.fr)

  This file is part of PunBB.

  PunBB is free software; you can redistribute it and/or modify it
  under the terms of the GNU General Public License as published
  by the Free Software Foundation; either version 2 of the License,
  or (at your option) any later version.

  PunBB is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  MA  02111-1307  USA

************************************************************************/


/*********************************************************************** 
18 Mai 2006 - Author FoxMask -  AP_Email_Global_Plus v 1.0

Adapted plugin AP_Email_Global.php Terrell Russell

This plugin allows you to send mass mails to a group of users 
and adds the group administrator to 'blame' reception of mass mail.

************************************************************************/


// Make sure no one attempts to run this script "directly"
if (!defined('PUN'))
    exit;

// Tell admin_loader.php that this is indeed a plugin and that it is loaded
define('PUN_PLUGIN_LOADED', 1);



// --------------------------------------------------------------------

// Confirm Page

if (isset($_POST['confirm']))
{
    // Make sure message body was entered
    if (trim($_POST['message_body']) == '')
        message('You haven\'t written your message!');

    // Make sure message subject was entered
    if (trim($_POST['message_subject']) == '')
        message('You haven\'t written a subject!');

    // Display the admin navigation menu
    generate_admin_menu($plugin);
    
    $preview_message_body = nl2br(pun_htmlspecialchars($_POST['message_body']));
    
    if (! is_numeric($_POST['group_id']) ) message('tsss tsss tsss!!!');
    
    // sent to all groups except guest and unverified users
    if ($_POST['group_id'] == '0' ) 
        $sql = "SELECT count(*) AS usercount
                FROM ".$db->prefix."users
                WHERE group_id <> '3' AND subscribed = '1' ORDER BY username";
    else 
    // sent to a particular group
        $sql = "SELECT count(*) AS usercount
                FROM ".$db->prefix."users
                WHERE group_id = '".$_POST['group_id']."'" .
               "ORDER BY username";
                
    $result = $db->query($sql) or error('Can not find the number of users in the database', __FILE__, __LINE__, $db->error());
       $row = $db->fetch_assoc($result);

?>
    <div id="exampleplugin" class="blockform">
        <h2><span>Global Email Plus - Confirmation</span></h2>
        <div class="box">
            <div class="inbox">
                <p>Confirm your message before sending.<br /><br />For any corrections, <a href="javascript: history.go(-1)">Go Back</a>.</p>
            </div>
        </div>

        <h2 class="block2"><span>Confirmation of your Message</span></h2>
        <div class="box">
            <form id="broadcastemail" method="post" action="<?php echo $_SERVER['REQUEST_URI'] ?>">
                <div class="inform">
                    <input type="hidden" name="message_subject" value="<?php echo pun_htmlspecialchars($_POST['message_subject']) ?>" />
                    <input type="hidden" name="message_body" value="<?php echo pun_htmlspecialchars($_POST['message_body']) ?>" />
                    <input type="hidden" name="group_id" value="<?php echo $_POST['group_id']; ?>"/>
                    <fieldset>
                        <legend>Receipents</legend>
                        <div class="infldset">
                            [ <strong><?php echo $row['usercount'] ?></strong> ] members will receive this message (Administrator included).
                        </div>
                    </fieldset>
                </div>
                <div class="inform">
                    <fieldset>
                        <legend>Content of your message</legend>
                        <div class="infldset">
                            <table class="aligntop" cellspacing="0">
                                <tr>
                                    <th scope="row">Subject</th>
                                    <td>
                                        <?php echo pun_htmlspecialchars($_POST['message_subject']) ?>
                                    </td>
                                </tr>
                                <tr>
                                    <th scope="row">Your message</th>
                                    <td>
                                        <?php echo $preview_message_body ?>
                                    </td>
                                </tr>
                            </table>
                            <div class="fsetsubmit"><input type="submit" name="send_message" value="Confirm - Send" tabindex="3" /></div>
                            <p class="topspace">Press submit only once!!.</p>
                        </div>
                    </fieldset>
                </div>
            </form>
        </div>
    </div>
<?php

}

// --------------------------------------------------------------------

// Send the Message

else if (isset($_POST['send_message']))
{

    require_once PUN_ROOT.'include/email.php';
    @set_time_limit(0);

    // Display the admin navigation menu
    generate_admin_menu($plugin);
                
    if (! is_numeric($_POST['group_id']) ) message ('tsss tsss tsss!!!');
    
    // sent to all groups except guest and unverified users
    if ($_POST['group_id'] == '0' ) 
        $sql = "SELECT username, email
                FROM ".$db->prefix."users
                WHERE group_id <> '3' AND subscribed = '1' ORDER BY username";
    
    // sending only the group administrator
    elseif ($_POST['group_id'] == '1' ) 
    
        $sql = "SELECT username, email
                FROM ".$db->prefix."users
                WHERE group_id = '1'" .
            " ORDER BY username";
            
    else 
    // sent to a particular group + group administrator
        $sql = "SELECT username, email
                FROM ".$db->prefix."users
                WHERE group_id = '".$_POST['group_id']."' or group_id = '1'" .
            " ORDER BY username";
            
    $result = $db->query($sql) or error('Can not find users in the database', __FILE__, __LINE__, $db->error());
       while($row = $db->fetch_assoc($result))
       {
           $addresses[$row['username']] = $row['email'];
       }

    $usercount = count($addresses);
    
    $mail_subject   = pun_htmlspecialchars($_POST['message_subject']);
    $mail_message   = pun_htmlspecialchars($_POST['message_body']);

    foreach ($addresses as $recipientname => $recipientemail)
    {
    
        $mail_to        = $recipientemail;

        pun_mail($mail_to, $mail_subject, $mail_message);
    }


    
?>
    <div class="block">
        <h2><span>Globla Email Plus - Message Sent</span></h2>
        <div class="box">
            <div class="inbox">
                <p>Your message was sent to  [ <strong><?php echo $usercount ?></strong> ] members.</p>
                <p>The administrator was included</p>
                <p>You will receive a copy of your message soon</p>
            </div>
        </div>
    </div>
<?php

}

// --------------------------------------------------------------------

// Display the Main Page

else
{
    // Display the admin navigation menu
    generate_admin_menu($plugin);

?>
    <div id="exampleplugin" class="blockform">
        <h2><span>Globla Email Plus</span></h2>
        <div class="box">
            <div class="inbox">
                <p>This plugin allows the administrator to send a message to all the users of a forum or of a specific group.</p>
                <p>A confirmation page will be displayed after you click "Continue to the Confirmation Page"</p>
            </div>
        </div>

        <h2 class="block2"><span>Write a Message</span></h2>
        <div class="box">
            <form id="broadcastemail" method="post" action="<?php echo $_SERVER['REQUEST_URI'] ?>">
                <div class="inform">
                    <fieldset>
                        <legend>Content of the message</legend>
                        <div class="infldset">
                            <table class="aligntop" cellspacing="0">
                                <tr>
                                    <th scope="row">Group</th>
                                    <td>
                                        <select name="group_id">
                                            <option value="0" select="selected">Everyone</option>
                                        <?php 
                                        // we do not take the guest
                                        $sql_group = "SELECT * FROM ".$db->prefix."groups WHERE g_id <> '3' ORDER BY g_id";
                                        $result_group = $db->query($sql_group) or error('can find a list of user groups',__FILE__, __LINE__, $db->error()); 
                                        while ($row_group = $db->fetch_assoc($result_group)) {
                                        ?>
                                            <option value="<?php echo $row_group['g_id']; ?>"><?php echo $row_group['g_title']; ?></option>
                                        <?php } ?>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <th scope="row">Subject</th>
                                    <td>
                                        <input type="text" name="message_subject" size="50" tabindex="1" />
                                    </td>
                                </tr>
                                <tr>
                                    <th scope="row">The message</th>
                                    <td>
                                        <textarea name="message_body" rows="14" cols="48" tabindex="2"></textarea>
                                    </td>
                                </tr>
                            </table>
                            <div class="fsetsubmit"><input type="submit" name="confirm" value="Continue to the Confirmation Page" tabindex="3" /></div>
                        </div>
                    </fieldset>
                </div>
            </form>
        </div>
    </div>
<?php

}

// --------------------------------------------------------------------

// Note that the script just ends here. The footer will be included by admin_loader.php.

Offline

#2 2009-08-31 08:24:37

Reines
Administrator
From: Scotland
Registered: 2008-05-11
Posts: 3,197
Website

Re: Email Global Plus - Ignore Bans

Give this a try, it should work, but I haven't tested it at all:

<?php
/***********************************************************************

  Copyright (C) 2005  Terrell Russell (punbb@terrellrussell.com)
  
  Copyright (C) 2006  FoxMaSk (foxmask@punbb.fr)

  This file is part of PunBB.

  PunBB is free software; you can redistribute it and/or modify it
  under the terms of the GNU General Public License as published
  by the Free Software Foundation; either version 2 of the License,
  or (at your option) any later version.

  PunBB is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  MA  02111-1307  USA

************************************************************************/


/*********************************************************************** 
18 Mai 2006 - Author FoxMask -  AP_Email_Global_Plus v 1.0

Adapted plugin AP_Email_Global.php Terrell Russell

This plugin allows you to send mass mails to a group of users 
and adds the group administrator to 'blame' reception of mass mail.

************************************************************************/


// Make sure no one attempts to run this script "directly"
if (!defined('PUN'))
    exit;

// Tell admin_loader.php that this is indeed a plugin and that it is loaded
define('PUN_PLUGIN_LOADED', 1);



// --------------------------------------------------------------------

// Confirm Page

if (isset($_POST['confirm']))
{
    // Make sure message body was entered
    if (trim($_POST['message_body']) == '')
        message('You haven\'t written your message!');

    // Make sure message subject was entered
    if (trim($_POST['message_subject']) == '')
        message('You haven\'t written a subject!');

    // Display the admin navigation menu
    generate_admin_menu($plugin);
    
    $preview_message_body = nl2br(pun_htmlspecialchars($_POST['message_body']));
    
    if (! is_numeric($_POST['group_id']) ) message('tsss tsss tsss!!!');
    
    // sent to all groups except guest and unverified users
    if ($_POST['group_id'] == '0' ) 
        $sql = "SELECT count(u.id) AS usercount
                FROM ".$db->prefix."users AS u
                LEFT JOIN ".$db->prefix."bans AS b ON b.username = u.username
                WHERE u.group_id <> '3' AND u.subscribed = '1' AND b.id IS NULL
                ORDER BY u.username";
    else 
    // sent to a particular group
        $sql = "SELECT count(*) AS usercount
                FROM ".$db->prefix."users AS u
                LEFT JOIN ".$db->prefix."bans AS b ON b.username = u.username
                WHERE u.group_id = '".$_POST['group_id']."'  AND b.id IS NULL
        ORDER BY u.username";
                
    $result = $db->query($sql) or error('Can not find the number of users in the database', __FILE__, __LINE__, $db->error());
       $row = $db->fetch_assoc($result);

?>
    <div id="exampleplugin" class="blockform">
        <h2><span>Global Email Plus - Confirmation</span></h2>
        <div class="box">
            <div class="inbox">
                <p>Confirm your message before sending.<br /><br />For any corrections, <a href="javascript: history.go(-1)">Go Back</a>.</p>
            </div>
        </div>

        <h2 class="block2"><span>Confirmation of your Message</span></h2>
        <div class="box">
            <form id="broadcastemail" method="post" action="<?php echo $_SERVER['REQUEST_URI'] ?>">
                <div class="inform">
                    <input type="hidden" name="message_subject" value="<?php echo pun_htmlspecialchars($_POST['message_subject']) ?>" />
                    <input type="hidden" name="message_body" value="<?php echo pun_htmlspecialchars($_POST['message_body']) ?>" />
                    <input type="hidden" name="group_id" value="<?php echo $_POST['group_id']; ?>"/>
                    <fieldset>
                        <legend>Receipents</legend>
                        <div class="infldset">
                            [ <strong><?php echo $row['usercount'] ?></strong> ] members will receive this message (Administrator included).
                        </div>
                    </fieldset>
                </div>
                <div class="inform">
                    <fieldset>
                        <legend>Content of your message</legend>
                        <div class="infldset">
                            <table class="aligntop" cellspacing="0">
                                <tr>
                                    <th scope="row">Subject</th>
                                    <td>
                                        <?php echo pun_htmlspecialchars($_POST['message_subject']) ?>
                                    </td>
                                </tr>
                                <tr>
                                    <th scope="row">Your message</th>
                                    <td>
                                        <?php echo $preview_message_body ?>
                                    </td>
                                </tr>
                            </table>
                            <div class="fsetsubmit"><input type="submit" name="send_message" value="Confirm - Send" tabindex="3" /></div>
                            <p class="topspace">Press submit only once!!.</p>
                        </div>
                    </fieldset>
                </div>
            </form>
        </div>
    </div>
<?php

}

// --------------------------------------------------------------------

// Send the Message

else if (isset($_POST['send_message']))
{

    require_once PUN_ROOT.'include/email.php';
    @set_time_limit(0);

    // Display the admin navigation menu
    generate_admin_menu($plugin);
                
    if (! is_numeric($_POST['group_id']) ) message ('tsss tsss tsss!!!');
    
    // sent to all groups except guest and unverified users
    if ($_POST['group_id'] == '0' ) 
        $sql = "SELECT u.username, u.email
                FROM ".$db->prefix."users AS u
                LEFT JOIN ".$db->prefix."bans AS b ON b.username = u.username
                WHERE u.group_id <> '3' AND u.subscribed = '1' AND b.id IS NULL
                ORDER BY u.username";
    
    // sending only the group administrator
    elseif ($_POST['group_id'] == '1' ) 
    
        $sql = "SELECT u.username, u.email
                FROM ".$db->prefix."users AS u
                LEFT JOIN ".$db->prefix."bans AS b ON b.username = u.username
                WHERE u.group_id = '1' AND b.id IS NULL
        ORDER BY u.username";
            
    else 
    // sent to a particular group + group administrator
        $sql = "SELECT u.username, u.email
                FROM ".$db->prefix."users AS u
                LEFT JOIN ".$db->prefix."bans AS b ON b.username = u.username
                WHERE u.group_id = '".$_POST['group_id']."' or u.group_id = '1' AND b.id IS NULL
        ORDER BY u.username";
            
    $result = $db->query($sql) or error('Can not find users in the database', __FILE__, __LINE__, $db->error());
       while($row = $db->fetch_assoc($result))
       {
           $addresses[$row['username']] = $row['email'];
       }

    $usercount = count($addresses);
    
    $mail_subject   = pun_htmlspecialchars($_POST['message_subject']);
    $mail_message   = pun_htmlspecialchars($_POST['message_body']);

    foreach ($addresses as $recipientname => $recipientemail)
    {
    
        $mail_to        = $recipientemail;

        pun_mail($mail_to, $mail_subject, $mail_message);
    }


    
?>
    <div class="block">
        <h2><span>Globla Email Plus - Message Sent</span></h2>
        <div class="box">
            <div class="inbox">
                <p>Your message was sent to  [ <strong><?php echo $usercount ?></strong> ] members.</p>
                <p>The administrator was included</p>
                <p>You will receive a copy of your message soon</p>
            </div>
        </div>
    </div>
<?php

}

// --------------------------------------------------------------------

// Display the Main Page

else
{
    // Display the admin navigation menu
    generate_admin_menu($plugin);

?>
    <div id="exampleplugin" class="blockform">
        <h2><span>Globla Email Plus</span></h2>
        <div class="box">
            <div class="inbox">
                <p>This plugin allows the administrator to send a message to all the users of a forum or of a specific group.</p>
                <p>A confirmation page will be displayed after you click "Continue to the Confirmation Page"</p>
            </div>
        </div>

        <h2 class="block2"><span>Write a Message</span></h2>
        <div class="box">
            <form id="broadcastemail" method="post" action="<?php echo $_SERVER['REQUEST_URI'] ?>">
                <div class="inform">
                    <fieldset>
                        <legend>Content of the message</legend>
                        <div class="infldset">
                            <table class="aligntop" cellspacing="0">
                                <tr>
                                    <th scope="row">Group</th>
                                    <td>
                                        <select name="group_id">
                                            <option value="0" select="selected">Everyone</option>
                                        <?php 
                                        // we do not take the guest
                                        $sql_group = "SELECT * FROM ".$db->prefix."groups WHERE g_id <> '3' ORDER BY g_id";
                                        $result_group = $db->query($sql_group) or error('can find a list of user groups',__FILE__, __LINE__, $db->error()); 
                                        while ($row_group = $db->fetch_assoc($result_group)) {
                                        ?>
                                            <option value="<?php echo $row_group['g_id']; ?>"><?php echo $row_group['g_title']; ?></option>
                                        <?php } ?>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <th scope="row">Subject</th>
                                    <td>
                                        <input type="text" name="message_subject" size="50" tabindex="1" />
                                    </td>
                                </tr>
                                <tr>
                                    <th scope="row">The message</th>
                                    <td>
                                        <textarea name="message_body" rows="14" cols="48" tabindex="2"></textarea>
                                    </td>
                                </tr>
                            </table>
                            <div class="fsetsubmit"><input type="submit" name="confirm" value="Continue to the Confirmation Page" tabindex="3" /></div>
                        </div>
                    </fieldset>
                </div>
            </form>
        </div>
    </div>
<?php

}

// --------------------------------------------------------------------

// Note that the script just ends here. The footer will be included by admin_loader.php.

Offline

#3 2009-08-31 09:00:06

OJM
Member
Registered: 2009-07-29
Posts: 9

Re: Email Global Plus - Ignore Bans

Looks good to me - just sent an email and it seemed to count the right amount!

Cheers mate, appreciated!

Offline

#4 2010-01-08 04:12:56

twohawks
Member
From: Stateline, NV USA
Registered: 2008-05-11
Posts: 135

Re: Email Global Plus - Ignore Bans

AP_Email_Global_Plus  REDO -- INCLUDES OPTIONAL INTEGRATION FOR MULTIGROUPS plus other improvements and tweaks.
Email Global Plus (<<--for the search engine)
=============================================
Thank you for posting that, Reines!

For anyone interested I have just finished reworking this mod for one of our sites.
It has significant changes, including integration for use if you have the MULTIGROUPS MOD installed ;^)
Code is posted below.

Here are the changes (from my notes):
- allow listing of recipient names for preview (not paginated, so if you have thousands of users prepare to wait - or disable this
- make sure users pulled for "everyone" excludes any users not having read permissions or permissions for viewing the user list
- edited to allow use with the MULTIGROUPS mod
- distilled redundant queries down (non-repetitive)
- Sends copy to administrators [tweak]. Also Includes a note in the message as to who sent it ;^)
- exclude banned users [tweaked]
- Works with or without multigroup mod installed

Obviously some of the changes are simply adjustments to what was there, however, you will notice a lot of rewriting of the code.

Here you go...

<?php
/***********************************************************************

  Copyright (C) 2005  Terrell Russell (punbb@terrellrussell.com)
  
  Copyright (C) 2006  FoxMaSk (foxmask@punbb.fr)

  This file is part of PunBB.

  PunBB is free software; you can redistribute it and/or modify it
  under the terms of the GNU General Public License as published
  by the Free Software Foundation; either version 2 of the License,
  or (at your option) any later version.

  PunBB is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  MA  02111-1307  USA

************************************************************************/


/*********************************************************************** 
18 Mai 2006 - Author FoxMask -  AP_Email_Global_Plus v 1.0

Adapted plugin AP_Email_Global.php Terrell Russell

This plugin allows you to send mass mails to a group of users 
and adds the group administrator to 'blame' reception of mass mail.

************************************************************************/


/*********************************************************************** 
TWOHAWKS EDITED  Jan 07, 2010      based on AP_Email_Global_Plus_GoodDebugVer02a.php
 - allow listing of recipient names for preview (not paginated, so if you have thousands of users prepare to wait - or disable this
 - make sure users pulled for "everyone" excludes any users not having read permissions or permissions for viewing the user list
 - edited to allow use with the multigroups mod
 - distilled redundant queries down (non-repetitive)
 - Sends copy to administrators. Also Includes a note in the message as to who sent it ;^)
 - Work with or without multigroup mod installed
************************************************************************/


// Make sure no one attempts to run this script "directly"
if (!defined('PUN'))
    exit;

// Tell admin_loader.php that this is indeed a plugin and that it is loaded
define('PUN_PLUGIN_LOADED', 1);

// Courtesy php at deboom dot biz from the php manual for print_r
// Converts print_r output back to an array 
// This could also be (ab)used to convert a object into a array..
function object2array($printr) {                   
        $newarray = array();       
        $a[0] = &$newarray;       
        if (preg_match_all('/^\s+\[(\w+).*\] => (.*)\n/m', $printr, $match)) {                       
            foreach ($match[0] as $key => $value) {   
                (int)$tabs = substr_count(substr($value, 0, strpos($value, "[")), "        ");               
                if ($match[2][$key] == 'Array' || substr($match[2][$key], -6) == 'Object') {                   
                    $a[$tabs+1] = &$a[$tabs][$match[1][$key]];
                }                           
                else {
                    $a[$tabs][$match[1][$key]] = $match[2][$key];                   
                }
            }
        }   
        return $newarray;   
    }


// --------------------------------------------------------------------

// Confirm Page

if (isset($_POST['confirm']))
{
    // Make sure message body was entered
    if (trim($_POST['message_body']) == '')
        message('You haven\'t written your message!');

    // Make sure message subject was entered
    if (trim($_POST['message_subject']) == '')
        message('You haven\'t written a subject!');

    // Display the admin navigation menu
    generate_admin_menu($plugin);
    
    $preview_message_body = nl2br(pun_htmlspecialchars($_POST['message_body']));
    
    if (! is_numeric($_POST['group_id']) ) message('tsss tsss tsss!!!');

    $mgrpsarr = array();
    $mgrpscount = 0;
    $mgrpscounttl = 0;

    //check if multigroup mod is installed
    if (false === $db->query("SELECT membergroupids FROM ".$db->prefix."users limit 0"))
    {
        $umemgrpid = "";  //the column does not exist
    } else {
        $umemgrpid = ", u.membergroupids";  //the column exists
    }

    // sent to all groups except guest and unverified users ("Everyone" selected in list)
        $sql = "SELECT u.username, u.email".$umemgrpid.", g_title
                FROM ".$db->prefix."users AS u
                LEFT JOIN ".$db->prefix."bans AS b ON b.username = u.username
                LEFT JOIN ".$db->prefix."groups AS g ON g.g_id = u.group_id
                WHERE u.group_id <> '3' AND b.id IS NULL
                AND  g.g_read_board = 1
                ORDER BY u.username";
    // sent to a particular group
        $sql2 = "SELECT u.username, u.email
                FROM ".$db->prefix."users AS u
                LEFT JOIN ".$db->prefix."bans AS b ON b.username = u.username
                WHERE (u.group_id = '".$_POST['group_id']."' or u.group_id = '1') AND b.id IS NULL
                ORDER BY u.username";

    // main query - always used  (selection is everyone or a particular group)
    $result = $db->query($sql) or error('Can not find the number of users in the database', __FILE__, __LINE__, $db->error());
    //query for if particular group selected 
    $result2 = $db->query($sql2) or error('Can not find the number of users in the database', __FILE__, __LINE__, $db->error());

    // for main query - always used (selection is everyone or a particular group)
    while($row = $db->fetch_assoc($result))
    {
        if ($_POST['group_id'] == '0' )
        {
            $usernames[] = $row['username'];
            $addresses[$row['username']] = $row['email'];
        }

        //if the selection was aparticular group, check second query
        //only gets iterated once, so doesn't really need to be inside this while statement - located here for debug ease
        while($row2 = $db->fetch_assoc($result2))
        {
            if ($_POST['group_id'] !=0 )
            {
                $usernames[] = $row2['username'];
                $addresses[$row2['username']] = $row2['email'];
            }
        }

        $mgrps = split(',', $row['membergroupids']);
        foreach($mgrps as $mgrp) {

            // DEBUG: for check-counting of all multigroup memberships 
            if (($mgrp != NULL) && ($_POST['group_id'] !=0)) 
                $mgrpscounttl = $mgrpscounttl+1;

            if (($mgrp != NULL) && ($_POST['group_id'] !=0) && ($mgrp == $_POST['group_id'])) 
            {   
                if (!in_array($mgrp,$mgrpsarr))
                {
                    if((int)$mgrp !=0) 
                    {
                        //For the current row, iterate the database
                        $result3 = $db->query('SELECT u.username, u.email, g_id, g_user_title
                            FROM '.$db->prefix.'users AS u
                            LEFT JOIN '.$db->prefix.'groups AS g ON g.g_id = '.$mgrp.'
                            LEFT JOIN '.$db->prefix.'bans AS b ON b.username = u.username
                            WHERE FIND_IN_SET('.$mgrp.', membergroupids)
                            AND u.group_id <> 3
                            AND b.id IS NULL
                            AND  g.g_read_board = 1
                            ') or error('Unable to fetch user list', __FILE__, __LINE__, $db->error());
                        while($row3 = $db->fetch_assoc($result3)) 
                        {
                            $mgrpsarr[$row['membergroupids']] = $mgrp;
                            if (!in_array($row3['username'],$usernames)) 
                            {
                                $usernames[] = $row3['username'];
                                $addresses[$row3['username']] = $row3['email'];
                            }
                            $mgrpscount++;   //tracking count of viable multigroup members var
                        }
                    }
                }
            }  // End Main IF in For Each
        }   // End ForEach iteration
    } //End While

    $usercount = count($usernames);
?>
    <div id="exampleplugin" class="blockform">
        <h2><span>Global Email Plus - Confirmation</span></h2>
        <div class="box">
            <div class="inbox">
                <p>Confirm your message before sending.<br /><br /><b>For any corrections, <a href="javascript: history.go(-1)">Go Back</a></b>.</p>
            </div>
        </div>

        <h2 class="block2"><span>Confirmation of your Message</span></h2>
        <div class="box">
            <form id="broadcastemail" method="post" action="<?php echo $_SERVER['REQUEST_URI'] ?>">
                <div class="inform">
                    <input type="hidden" name="message_subject" value="<?php echo pun_htmlspecialchars($_POST['message_subject']) ?>" />
                    <input type="hidden" name="message_body" value="<?php echo pun_htmlspecialchars($_POST['message_body']) ?>" />
                    <input type="hidden" name="group_id" value="<?php echo $_POST['group_id']; ?>"/>
                    <input type="hidden" name="usernames[]" value="<?php echo $_POST[print_r($usernames)]; ?>"/>
                    <input type="hidden" name="addresses[]" value="<?php echo $_POST[print_r($addresses)]; ?>"/>
                    <input type="hidden" name="usercount[]" value="<?php echo $_POST[print_r($usercount)]; ?>"/>
                    <fieldset>
                        <legend>Receipents</legend>
                        <div class="infldset">
                            [ <strong><?php echo $usercount ?></strong> ] members will receive this message (Administrators included).
                        </div>
                    </fieldset>
                </div>
                <div class="inform">
                    <fieldset>
                        <legend>Content of your message</legend>
                        <div class="infldset">
                            <table class="aligntop" cellspacing="0">
                                <tr>
                                    <th scope="row">Subject</th>
                                    <td>
                                        <?php echo pun_htmlspecialchars($_POST['message_subject']) ?>
                                    </td>
                                </tr>
                                <tr>
                                    <th scope="row">Your message</th>
                                    <td>
                                        <?php echo $preview_message_body ?>
                                    </td>
                                </tr>
                            </table>
                            <div class="fsetsubmit"><input type="submit" name="send_message" value="Confirm - Send" tabindex="3" /></div>
                            <p class="topspace">Press submit only once!!.</p>
                        </div>
                    </fieldset>
                </div>
                <div class="inform"><!-- remove this div is you have too many users to be listing -->
                    <fieldset>
                        <legend>List of Recipients Selected</legend>
                        <div class="infldset">
                            <table class="aligntop" cellspacing="2">
                                <tr>
                                    <td>
                                    <?php 
                                        $iTD=0;
                                        $iTR=0;
                                        If  (!$usernames) { echo "No recipients selected<br />\n";}
                                        If ($usernames) 
                                        {
                                            foreach ($usernames as $recipientname)
                                            {
                                                $iTD=$iTD+1;
                                                $iTR=$iTR+1;
                                                echo $recipientname."<br />\n";

                                                //FOLLOWING SETS SHOULD BE MULITPLES OF EACH OTHER 
                                                If ($iTD==25)  //SET TO MUMBER TO LIST PER COLUMN/CELL
                                                {?>
                                        </td>   <?php
                                                    $iTD=0;  //reset for new column

                                                    If ($iTR==125)  //SET TO MAX MUMBER OF COLUMN. Inserts following TR if/when needed
                                                    {?>
                                    </tr>
                                    <tr>  <?php            $iTR=0;  //reset for new row
                                                    } ?>

                                        <td>  <?php
                                                }
                                            }
                                        } ?>
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </fieldset>
                </div>
            </form>
        </div>
    </div>
<?php

}

// --------------------------------------------------------------------

// Send the Message

else if (isset($_POST['send_message']))
{

    require_once PUN_ROOT.'include/email.php';
    @set_time_limit(0);

    // Display the admin navigation menu
    generate_admin_menu($plugin);

    if (! is_numeric($_POST['group_id']) ) message ('tsss tsss tsss!!!');


    //Collest Variables from Confirm Page
    // get Usernames Array  (HTH-may not be needed after debugging)
    if (isset($_POST['usernames'])) 
    {
        $usernames = $_POST['usernames'];
        //break return value out of the post array -- it will be a string (post always delivers a string)
        foreach ($usernames as $username)
        {
            $usernames = $username;
        }
        //convert the print_r string value back to an array
        $usernames = object2array($usernames);
    }

    // get Addresses Array
    if (isset($_POST['addresses'])) 
    {
        $addresses = $_POST['addresses'];
        //break return value out of the post array -- it will be a string (post always delivers a string)
        foreach ($addresses as $address)
        {
            $addresses = $address;
        }
        //convert the print_r string value back to an array
        $addresses = object2array($addresses);
    }

    // get UserCount Array
    if (isset($_POST['usercount'])) 
    {
        $usercount = $_POST['usercount'];
        foreach ($usercount as $usercounti)
        {
            $usercount = $usercounti;
        }
    }

    //create tag for the current logged in user to place into the email message (to tag it with their ident)
    $addendsender = "<br />\n<br />\n<br />\n The sender of this message is ".$pun_user['username']."<br />\n";

// Set up the mailer
    $mail_subject   = pun_htmlspecialchars($_POST['message_subject']);
    $mail_message   = pun_htmlspecialchars($_POST['message_body']);
    $mail_message   = substr_replace($mail_message, $addendsender, -1, 0);
    
    foreach ($addresses as $recipientname => $recipientemail)
    {
        $mail_to        = $recipientemail;
        pun_mail($mail_to, $mail_subject, $mail_message);
    }

    
?>
    <div class="block">
        <h2><span>Globla Email Plus - Message Sent</span></h2>
        <div class="box">
            <div class="inbox">
                <p>Your message was sent to  [ <strong><?php echo $usercount ?></strong> ] members.</p>
                <p>The administrators were included</p>
                <p>You will receive a copy of your message soon</p>
            </div>
        </div>
    </div>
<?php

}

// --------------------------------------------------------------------

// Display the Main Page

else
{
    // Display the admin navigation menu
    generate_admin_menu($plugin);

?>
    <div id="exampleplugin" class="blockform">
        <h2><span>Globla Email Plus</span></h2>
        <div class="box">
            <div class="inbox">
                <p>This plugin allows the administrator to send a message to all the users of a forum or of a specific group.<br />
                   A confirmation page will be displayed after you click "Continue to the Confirmation Page"<br />
                   A copy is sent to all administrators, and the administrator who sent it is noted in the email.</p>
                <p>Multigroups: this version works with the multi-group mod.<br />
                   With the multigroup mod installed it is a simple matter to create a custom group of users to send messages to ;^) 
                </p>
            </div>
        </div>

        <h2 class="block2"><span>Write a Message</span></h2>
        <div class="box">
            <form id="broadcastemail" method="post" action="<?php echo $_SERVER['REQUEST_URI'] ?>">
                <div class="inform">
                    <fieldset>
                        <legend>Content of the message</legend>
                        <div class="infldset">
                            <table class="aligntop" cellspacing="0">
                                <tr>
                                    <th scope="row">Group</th>
                                    <td>
                                        <select name="group_id">
                                            <option value="0" select="selected">Everyone</option>
                                        <?php 
                                        // we do not take the guest
                                        $sql_group = "SELECT * FROM ".$db->prefix."groups WHERE g_id <> '3' ORDER BY g_title";
                                        $result_group = $db->query($sql_group) or error('can find a list of user groups',__FILE__, __LINE__, $db->error()); 
                                        while ($row_group = $db->fetch_assoc($result_group)) {
                                        ?>
                                            <option value="<?php echo $row_group['g_id']; ?>"><?php echo $row_group['g_title']; ?></option>
                                        <?php } ?>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <th scope="row">Subject</th>
                                    <td>
                                        <input type="text" name="message_subject" size="50" tabindex="1" />
                                    </td>
                                </tr>
                                <tr>
                                    <th scope="row">The message</th>
                                    <td>
                                        <textarea name="message_body" rows="25" cols="72" tabindex="2"></textarea>
                                    </td>
                                </tr>
                            </table>
                            <div class="fsetsubmit"><input type="submit" name="confirm" value="Continue to the Confirmation Page" tabindex="3" /></div>
                        </div>
                    </fieldset>
                </div>
            </form>
        </div>
    </div>
<?php

}

// --------------------------------------------------------------------

// Note that the script just ends here. The footer will be included by admin_loader.php.

Cheers,
TwoHawks

Last edited by twohawks (2010-01-08 07:13:32)


TwoHawks
Love is the Function.
No Form is the Tool.

Offline

#5 2010-01-08 08:33:09

twohawks
Member
From: Stateline, NV USA
Registered: 2008-05-11
Posts: 135

Re: Email Global Plus - Ignore Bans

FOLLOW-UP... SOME CODER MUSINGS....
Yeah, it could still use a little more cleaning up, and it may not yet be the most efficient approach for this job, but it seems to be working pretty reliably at least.

Most of you experts here already know I am not one... so if you have any insightful critiques *please* comment.

Two major players for me here were...
1. One of the tools I was extremely relieved to find was the FIND_IN_SET sql function... I kinda fly by the seat of my chair and was searching high and low for something to allow for looking inside a field record that is storing a list of values (or array)-(in this case, the secondary-groups users are members of is stored as a concatonated list)
..and do a comparison against any of the lists' elements *on the fly*...

I.e... I have a group number and I wish to see if it exists in the current field value's list for validating the row being currently considered in the query statement execution...
...-->>
  Using IN with IMPLODE on the fieldname does not allow access to the itemized contents of the field-record(s) while operating within the query... this method only lets you test against the first value, not the rest...
...and serialize tricks seems a tad messy and complicated...
**but FIND_IN_SET does allow you test against any value in the current fieldrecord, and its very simple and clean ! 
I was just about to let go of the notion this could even be done when I spotted this in my last search.

That function saved having to run another nested query for managing the job - which I really didn't desire.

---------------------
2. Second thing that came in handy was using $_POST to pass array values, which eliminated having to run same/similar queries over again (redundantly). 
In order to do this there are three simple steps...
- pass the arrays from the original results as print_r string values via $_POST array,
- retrieve each string out of the relevant $_POST array using for-each (takes a single pass),
- convert the print_r string value back to an array

In the code I formulated I did this the long way... it is worth noting that there is a method I did not spend time learning where you can evidently do this for all your array variables you wish to pass off... together in one fell swoop (in both the pass and the retrieval), so this is definitely something worth learning more about (for me anyway ;^).

I have no idea if there are any security issues exposed using that method, but considering its a post method I really think not... if someone has the proper insight on that please speak up.

--------
3. Also, I used a variable for conditionally allowing use/nonuse of the multigroup mod... not anything unfamiliar to folks here, but still worth noting.  That saved any headaches of requiring different versions, or needing any customization based on type of deployment ;^)

All righty then.  That's about it for now.
Thought it worth dumping those thoughts here if for nothing else than decent reference/reminder when revisiting this project.

Cheers,

Last edited by twohawks (2010-01-08 08:41:49)


TwoHawks
Love is the Function.
No Form is the Tool.

Offline

Board footer

Powered by FluxBB