<?php
/****************************************************************************************/
/* ACollab */
/****************************************************************************************/
/* Copyright (c) 2002-2004 Adaptive Technology Resource Centre / University of Toronto */
/* */
/* http://atutor.ca/acollab */
/* */
/* This program is free software. You may 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. */
/* */
/* This program 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 may access the GNU General Public License at: */
/* http://www.opensource.org/licenses/gpl-license.php */
/* */
/* You may contact the Adaptive Technology Resource Centre at */
/* Robarts Library, University of Toronto */
/* 130 St. George Street, Toronto, Ontario, Canada M5S 1A5 */
/* Further contact information is available at http://www.utoronto.ca/atrc/ */
/****************************************************************************************/
/* Programmer: */
/* Joel Kronenberg - ATRC */
/****************************************************************************************/
// $Id: mailing_list.php 374 2005-02-09 16:11:41Z shozubq $
define('AC_INCLUDE_PATH', '../include/');
require(AC_INCLUDE_PATH.'vitals.inc.php');
authenticate(USER_GROUP_ADMIN);
if (isset($_POST['cancel'])) {
Header('Location: index.php');
exit;
}
if (isset($_POST['submit'])) {
$_POST['subject'] = trim($_POST['subject']);
$_POST['body'] = trim($_POST['body']);
if ($_POST['subject'] == '') {
$error[] = E_MSG_SUBJECT_EMPTY;
}
if ($_POST['body'] == '') {
$error[] = E_MSG_BODY_EMPTY;
}
if ($_POST['from_email'] == '') {
$error[] = E_MSG_NO_EMAIL;
}
if (!isset($error)) {
require(AC_INCLUDE_PATH . 'classes/acollabmailer.class.php');
$mail = new ACollabMailer;
if ($_SESSION['status'] == USER_ADMIN) {
$sql = "SELECT M.email FROM ".TABLE_PREFIX."groups_members G LEFT JOIN " . MEMBERS_TABLE_PREFIX . "members M USING (member_id) WHERE G.group_id=$_SESSION[group_id]";
$result = mysql_query($sql, $db);
while ($row = mysql_fetch_assoc($result)) {
$mail->AddBCC($row['email']);
}
$mail->From = ADMIN_EMAIL;
$mail->FromName = SITE_NAME;
$mail->AddAddress(ADMIN_EMAIL);
$mail->Subject = $_POST['subject'];
$mail->Body = $_POST['body'];
if(!$mail->Send()) {
header('Location: index.php?f='.E_MSG_NOT_SENT);
exit;
}
unset($mail);
header('Location: index.php?f='.F_MSG_SENT);
exit;
}
else {
$sql = "SELECT M.email FROM ".TABLE_PREFIX."groups_members G LEFT JOIN " . MEMBERS_TABLE_PREFIX . "members M USING (member_id) WHERE G.member_id<>$_SESSION[member_id] AND G.group_id=$_SESSION[group_id]";
$result = mysql_query($sql, $db);
while ($row = mysql_fetch_assoc($result)) {
$mail->AddBCC($row['email']);
}
$result2 = mysql_query("SELECT email, first_name, last_name FROM ".MEMBERS_TABLE_PREFIX."members WHERE member_id=$_SESSION[member_id]", $db);
$row2 = mysql_fetch_assoc($result2);
$mail->From = $_POST['from_email'];
$mail->FromName = $row2['first_name'] . ' ' . $row2['last_name'];
$mail->AddAddress($row2['email']);
$mail->Subject = $_POST['subject'];
$mail->Body = $_POST['body'];
if(!$mail->Send()) {
header('Location: index.php?f='.E_MSG_NOT_SENT);
exit;
}
unset($mail);
header('Location: index.php?f='.F_MSG_SENT);
exit;
}
}
}
if (authenticate(USER_ADMIN, USER_RETURN_CHECK)) {
$group_info = get_group($_SESSION['group_id']);
$_SECTION[0][0] = _AC('administration');
$_SECTION[0][1] = 'admin/index.php';
$_SECTION[1][0] = _AC('groups');
$_SECTION[1][1] = 'admin/groups.php';
$_SECTION[2][0] = $group_info['title'];
$_SECTION[2][1] = 'group_admin/index.php';
$_SECTION[3][0] = _AC('mailing_list');
$_SECTION[3][1] = 'admin/email.php';
require(AC_INCLUDE_PATH.'admin/header.inc.php');
} else {
$_SECTION[0][0] = _AC('home');
$_SECTION[0][1] = 'home.php';
$_SECTION[1][0] = _AC('administration');
$_SECTION[1][1] = 'group_admin/';
$_SECTION[2][0] = _AC('mailing_list');
$_SECTION[2][1] = 'admin/email.php';
require(AC_INCLUDE_PATH.'header.inc.php');
}
print_popup_help('help_mailing_list');
if (isset($error)) {
print_errors($error);
unset($error);
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form" id="form">
<table border="0" cellspacing="0" cellpadding="2" align="center" class="box2">
<tr>
<th colspan="5" class="box"><h3><?php echo _AC('mailing_list').' '; ?></h3></th>
</tr>
<tr>
<td class="row1"> </td>
<td colspan="3" class="row1"><img src="images/clr.gif" height="1" width="1" alt="" /><br /><?php
echo _AC('denotes_required', '<img src="images/required.gif" height="14" width="14" alt="'._AC('required_field').'" />');
?><br /></td>
<td class="row1"> </td>
</tr>
<tr>
<td class="row1"> </td>
<td class="row1" align="right"><label for="from_email"><b><?php echo _AC('from_email'); ?>:</b></label></td>
<td class="row1"><img src="images/required.gif" height="14" width="14" alt="<?php echo _AC('required_field'); ?>" /></td>
<td class="row1"><input type="text" name="from_email" class="input" size="40" maxlength="100" id="from_email" value="<?php echo $_POST['from_email']; ?>" onfocus="this.className='input highlight'" onblur="this.className='input'" /></td>
<td class="row1"> </td>
</tr>
<tr>
<td class="row1"> </td>
<td class="row1" align="right"><label for="subject"><b><?php echo _AC('subject'); ?>:</b></label></td>
<td class="row1"><img src="images/required.gif" height="14" width="14" alt="<?php echo _AC('required_field'); ?>" /></td>
<td class="row1"><input type="text" name="subject" class="input" size="40" maxlength="100" id="subject" value="<?php echo $_POST['subject']; ?>" onfocus="this.className='input highlight'" onblur="this.className='input'" /></td>
<td class="row1"> </td>
</tr>
<tr>
<td class="row1"> </td>
<td class="row1" align="right" valign="top"><label for="body"><b><?php echo _AC('body'); ?>:</b></label></td>
<td class="row1" valign="top"><img src="images/required.gif" height="14" width="14" alt="<?php echo _AC('required_field'); ?>" class="img" /></td>
<td class="row1"><textarea name="body" id="body" class="input" onfocus="this.className='input highlight'" onblur="this.className='input'" cols="55" rows="15"><?php echo $_POST['body']; ?></textarea></td>
<td class="row1"> </td>
</tr>
<tr>
<td class="row1"> </td>
<td class="row1" colspan="3" align="right"><br /><input type="submit" name="submit" value=" <?php echo _AC('send'); ?> " class="submitY" onfocus="this.className='submitY highlight'" onblur="this.className='submitY'" /> <input type="submit" name="cancel" value="<?php echo _AC('cancel'); ?>" class="submitN" onfocus="this.className='submitN highlight'" onblur="this.className='submitN'" /><br /><br /></td>
<td class="row1"> </td>
</tr>
</table>
</form>
<?php
require(AC_INCLUDE_PATH.'footer.inc.php');
?>