<?php
/***********************************************************************
Copyright (C) 2007 guardian34 (punbb@fmguy.com)
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
************************************************************************/
// 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);
// Load the language files
require_once PUN_ROOT.'lang/'.$pun_user['language'].'/pms.php';
require_once PUN_ROOT.'lang/'.$pun_user['language'].'/post.php';
if (isset($_POST['send']))
{
$group = intval($_POST['group']);
$subject = pun_trim($_POST['subject']);
$message = pun_linebreaks(pun_trim($_POST['message']));
$hide_smilies = (isset($_POST['hide_smilies'])) ? 1 : 0;
// Check group
if ($group < 0 || $group == 3)
message('You didn\'t specify a valid group!');
// Check subject
if ($subject == '')
message($lang_post['No subject']);
else if (pun_strlen($subject) > 70)
message($lang_post['Too long subject']);
// Check message
if ($message == '')
message($lang_post['No message']);
else if (strlen($message) > 65535)
message($lang_post['Too long message']);
// Validate BBCode syntax
if ($pun_config['p_message_bbcode'] == '1' && strpos($message, '[') !== false && strpos($message, ']') !== false)
{
require PUN_ROOT.'include/parser.php';
$message = preparse_bbcode($message, $errors);
}
if (isset($errors))
message($errors[0]);
// Get group members
$where_sql = ($group != 0) ? 'group_id='.$group : 'id!=1';
$result = $db->query('SELECT id, username FROM '.$db->prefix.'users WHERE '.$where_sql) or error('Unable to fetch group members', __FILE__, __LINE__, $db->error());
if ($db->num_rows($result) == 0)
message('No members found for group '.$group.'.');
// Save a copy of the message for the sender
if(isset($_POST['save_message']))
{
$db->query('INSERT INTO '.$db->prefix.'messages (owner, subject, message, sender, sender_id, sender_ip, smileys, showed, status, posted) VALUES(
\''.$pun_user['id'].'\',
\''.$db->escape($subject).'\',
\''.$db->escape($message).'\',
\''.$db->escape($user).'\',
\''.$pun_user['id'].'\',
\''.get_remote_address().'\',
\''.$hide_smilies.'\',
\'1\',
\'1\',
\''.time().'\'
)') or error('Unable to save message', __FILE__, __LINE__, $db->error());
}
// Send messages
while ($cur_user = $db->fetch_assoc($result))
{
$db->query('INSERT INTO '.$db->prefix.'messages (owner, subject, message, sender, sender_id, sender_ip, smileys, showed, status, posted) VALUES(
\''.$cur_user['id'].'\',
\''.$db->escape($subject).'\',
\''.$db->escape($message).'\',
\''.$db->escape($pun_user['username']).'\',
\''.$pun_user['id'].'\',
\''.get_remote_address().'\',
\''.$hide_smilies.'\',
\'0\',
\'0\',
\''.time().'\'
)') or error('Unable to send message', __FILE__, __LINE__, $db->error());
}
redirect($_SERVER['REQUEST_URI'], 'Private messages sent');
}
// Display the admin navigation menu
generate_admin_menu($plugin);
?>
<div class="block">
<h2><span>Mass Private Message - v1.0</span></h2>
<div class="box">
<div class="inbox">
<form method="post" action="<?php echo $_SERVER['REQUEST_URI'] ?>">
<p>This plugin "sends" private messages to a group of users. (<em>Note:</em> Private message mod is required.)</p>
</form>
</div>
</div>
</div>
<div class="blockform">
<h2 class="block2"><span>Mass Private Message</span></h2>
<div class="box">
<form method="post" action="<?php echo $_SERVER['REQUEST_URI'] ?>">
<div class="inform">
<fieldset>
<legend>Message</legend>
<div class="infldset">
<label><strong><?php echo $lang_pms['Send to'] ?></strong><br />
<select name="group">
<option value="0" selected="selected">** All Users</option>
<?php
// Get admin and moderator groups
$result = $db->query('SELECT g_id, g_title FROM '.$db->prefix.'groups WHERE g_id<'.PUN_GUEST.' ORDER BY g_id') or error('Unable to fetch user group list', __FILE__, __LINE__, $db->error());
while ($cur_group = $db->fetch_assoc($result))
echo "\t\t\t\t\t\t\t\t\t".'<option value="'.$cur_group['g_id'].'">'.pun_htmlspecialchars($cur_group['g_title']).'</option>'."\n";
// Get other groups
$result = $db->query('SELECT g_id, g_title FROM '.$db->prefix.'groups WHERE g_id>'.PUN_GUEST.' ORDER BY g_title') or error('Unable to fetch user group list', __FILE__, __LINE__, $db->error());
while ($cur_group = $db->fetch_assoc($result))
echo "\t\t\t\t\t\t\t\t\t".'<option value="'.$cur_group['g_id'].'">'.pun_htmlspecialchars($cur_group['g_title']).'</option>'."\n";
?> </select><br />
</label>
<label><strong><?php echo $lang_common['Subject'] ?></strong><br />
<input class="longinput" type="text" name="subject" value="" size="80" maxlength="70" style="width: 100%;" /><br /></label>
<?php //require PUN_ROOT.'mod_easy_bbcode.php' ?>
<label><strong><?php echo $lang_common['Message'] ?></strong><br />
<textarea name="message" rows="18" cols="95" style="width: 100%;"></textarea></label>
<ul class="bblinks">
<li><a href="help.php#bbcode" onclick="window.open(this.href); return false;"><?php echo $lang_common['BBCode'] ?></a>: <?php echo ($pun_config['p_message_bbcode'] == '1') ? $lang_common['on'] : $lang_common['off']; ?></li>
<li><a href="help.php#img" onclick="window.open(this.href); return false;"><?php echo $lang_common['img tag'] ?></a>: <?php echo ($pun_config['p_message_img_tag'] == '1') ? $lang_common['on'] : $lang_common['off']; ?></li>
<li><a href="help.php#smilies" onclick="window.open(this.href); return false;"><?php echo $lang_common['Smilies'] ?></a>: <?php echo ($pun_config['o_smilies'] == '1') ? $lang_common['on'] : $lang_common['off']; ?></li>
</ul>
</div>
</fieldset>
</div>
<?php
$checkboxes = array();
if ($pun_config['o_smilies'] == '1')
$checkboxes[] = '<label><input type="checkbox" name="hide_smilies" value="1" />'.$lang_post['Hide smilies'];
$checkboxes[] = '<label><input type="checkbox" name="save_message" value="1" />'.$lang_pms['Save message'];
if (!empty($checkboxes))
{
?> <div class="inform">
<fieldset>
<legend>Options</legend>
<div class="infldset">
<div class="infldset">
<div class="rbox">
<?php echo implode('<br /></label>'."\n\t\t\t\t", $checkboxes).'<br /></label>'."\n" ?>
</div>
</div>
</div>
</fieldset>
</div>
<?php
}
?> <p class="submitend"><input type="submit" name="send" value="<?php echo $lang_pms['Send'] ?>" /></p>
</form>
</div>
</div>