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