tagging as ATutor 1.5.4-release
[atutor.git] / admin / admin_email.php
1 <?php
2 /************************************************************************/
3 /* ATutor                                                                                                                               */
4 /************************************************************************/
5 /* Copyright (c) 2002-2006 by Greg Gay, Joel Kronenberg & Heidi Hazelton*/
6 /* Adaptive Technology Resource Centre / University of Toronto                  */
7 /* http://atutor.ca                                                                                                             */
8 /*                                                                                                                                              */
9 /* This program is free software. You can redistribute it and/or                */
10 /* modify it under the terms of the GNU General Public License                  */
11 /* as published by the Free Software Foundation.                                                */
12 /************************************************************************/
13 // $Id$
14
15 define('AT_INCLUDE_PATH', '../include/');
16 require (AT_INCLUDE_PATH.'vitals.inc.php');
17 admin_authenticate(AT_ADMIN_PRIV_USERS);
18
19 if ($_POST['cancel']) {
20         $msg->addFeedback('CANCELLED');
21
22         header('Location: users.php#feedback');
23         exit;
24 } else if ($_POST['submit']) {
25         $missing_fields = array();
26
27         $_POST['subject'] = trim($_POST['subject']);
28         $_POST['body'] = trim($_POST['body']);
29
30         if (($_POST['to'] == '') || ($_POST['to'] == 0)) {
31                 $missing_fields[] = _AT('to');
32         }
33
34         if ($_POST['subject'] == '') {
35                 $missing_fields[] = _AT('subject');
36         }
37
38         if ($_POST['body'] == '') {
39                 $missing_fields[] = _AT('body');
40         }
41
42         if ($missing_fields) {
43                 $missing_fields = implode(', ', $missing_fields);
44                 $msg->addError(array('EMPTY_FIELDS', $missing_fields));
45         }
46         if (!$msg->containsErrors()) {
47                 if ($_POST['to'] == 1) {
48                         // choose all instructors
49                         $sql    = "SELECT * FROM ".TABLE_PREFIX."members WHERE status = ".AT_STATUS_INSTRUCTOR;
50                 } else if ($_POST['to'] == 2) {
51                         // choose all students
52                         $sql    = "SELECT * FROM ".TABLE_PREFIX."members WHERE status = ".AT_STATUS_STUDENT;
53                 } else {
54                         // choose all members
55                         $sql    = "SELECT * FROM ".TABLE_PREFIX."members WHERE status = ".AT_STATUS_INSTRUCTOR." OR status = ".AT_STATUS_STUDENT;
56                 }
57                 
58                 $result = mysql_query($sql,$db);
59
60                 require(AT_INCLUDE_PATH . 'classes/phpmailer/atutormailer.class.php');
61
62                 $mail = new ATutorMailer;
63
64                 while ($row = mysql_fetch_assoc($result)) {
65                         $mail->AddBCC($row['email']);
66                 }
67
68
69                 $mail->From     = $_config['contact_email'];
70                 $mail->FromName = $_config['site_name'];
71                 $mail->AddAddress($_config['contact_email']);
72                 $mail->Subject = $stripslashes($_POST['subject']);
73                 $mail->Body    = $stripslashes($_POST['body']);
74
75                 if(!$mail->Send()) {
76                    //echo 'There was an error sending the message';
77                    $msg->printErrors('SENDING_ERROR');
78                    exit;
79                 }
80                 unset($mail);
81
82                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
83                 header('Location: users.php');
84                 exit;
85         }
86 }
87
88 $title = _AT('admin_email');
89
90 $onload = 'document.form.subject.focus();';
91
92 require(AT_INCLUDE_PATH.'header.inc.php');
93
94 $sql    = "SELECT COUNT(*) AS cnt FROM ".TABLE_PREFIX."members ORDER BY login";
95 $result = mysql_query($sql,$db);
96 $row    = mysql_fetch_array($result);
97 if ($row['cnt'] == 0) {
98         $msg->printErrors('NO_MEMBERS');
99         require(AT_INCLUDE_PATH.'footer.inc.php');
100         exit;
101 }
102
103 ?>
104 <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="form">
105 <input type="hidden" name="admin" value="admin" />
106
107 <div class="input-form">
108         <div class="row">
109                 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><?php echo  _AT('to'); ?><br />
110                 <input type="radio" name="to" value="3" checked="checked" id="all" /><label for="all"><?php echo _AT('all_users'); ?></label>  
111           <input type="radio" name="to" value="1" id="inst" <?php if ($_POST['to'] == AT_STATUS_INSTRUCTOR) { echo 'checked="checked"'; } ?> /><label for="inst"><?php echo  _AT('instructors'); ?></label>
112           <input type="radio" name="to" value="2" id="stud" <?php if ($_POST['to'] == AT_STATUS_STUDENT) { echo 'checked="checked"'; } ?> /><label for="stud"><?php echo  _AT('students'); ?></label>
113         </div>
114
115         <div class="row">
116                 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="subject"><?php echo _AT('subject'); ?></label><br />
117                 <input type="text" name="subject" size="40" id="subject" value="<?php echo $_POST['subject']; ?>" />
118         </div>
119
120         <div class="row">
121                 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="body"><?php echo _AT('body'); ?></label><br />
122                 <textarea cols="55" rows="18" name="body" id="body"><?php echo $_POST['body']; ?></textarea>
123         </div>
124
125         <div class="row buttons">
126                 <input type="submit" name="submit" value="<?php echo _AT('send'); ?>" accesskey="s" /> 
127                 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
128         </div>
129 </div>
130 </form>
131
132 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>