|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00026 require_once('../config.php'); 00027 require_once($CFG->dirroot.'/message/lib.php'); 00028 00029 $id = required_param('id',PARAM_INT); 00030 $messagebody = optional_param('messagebody','',PARAM_CLEANHTML); 00031 $send = optional_param('send','',PARAM_BOOL); 00032 $preview = optional_param('preview','',PARAM_BOOL); 00033 $edit = optional_param('edit','',PARAM_BOOL); 00034 $returnto = optional_param('returnto','',PARAM_LOCALURL); 00035 $format = optional_param('format',FORMAT_MOODLE,PARAM_INT); 00036 $deluser = optional_param('deluser',0,PARAM_INT); 00037 00038 $url = new moodle_url('/user/messageselect.php', array('id'=>$id)); 00039 if ($messagebody !== '') { 00040 $url->param('messagebody', $messagebody); 00041 } 00042 if ($send !== '') { 00043 $url->param('send', $send); 00044 } 00045 if ($preview !== '') { 00046 $url->param('preview', $preview); 00047 } 00048 if ($edit !== '') { 00049 $url->param('edit', $edit); 00050 } 00051 if ($returnto !== '') { 00052 $url->param('returnto', $returnto); 00053 } 00054 if ($format !== FORMAT_MOODLE) { 00055 $url->param('format', $format); 00056 } 00057 if ($deluser !== 0) { 00058 $url->param('deluser', $deluser); 00059 } 00060 $PAGE->set_url($url); 00061 $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); 00062 00063 if (!$course = $DB->get_record('course', array('id'=>$id))) { 00064 print_error('invalidcourseid'); 00065 } 00066 00067 require_login(); 00068 00069 $coursecontext = get_context_instance(CONTEXT_COURSE, $id); // Course context 00070 $systemcontext = get_context_instance(CONTEXT_SYSTEM); // SYSTEM context 00071 require_capability('moodle/course:bulkmessaging', $coursecontext); 00072 00073 if (empty($SESSION->emailto)) { 00074 $SESSION->emailto = array(); 00075 } 00076 if (!array_key_exists($id,$SESSION->emailto)) { 00077 $SESSION->emailto[$id] = array(); 00078 } 00079 00080 if ($deluser) { 00081 if (array_key_exists($id,$SESSION->emailto) && array_key_exists($deluser,$SESSION->emailto[$id])) { 00082 unset($SESSION->emailto[$id][$deluser]); 00083 } 00084 } 00085 00086 if (empty($SESSION->emailselect[$id]) || $messagebody) { 00087 $SESSION->emailselect[$id] = array('messagebody' => $messagebody); 00088 } 00089 00090 $messagebody = $SESSION->emailselect[$id]['messagebody']; 00091 00092 $count = 0; 00093 00094 if ($data = data_submitted()) { 00095 foreach ($data as $k => $v) { 00096 if (preg_match('/^(user|teacher)(\d+)$/',$k,$m)) { 00097 if (!array_key_exists($m[2],$SESSION->emailto[$id])) { 00098 if ($user = $DB->get_record_select('user', "id = ?", array($m[2]), 'id,firstname,lastname,idnumber,email,mailformat,lastaccess, lang, maildisplay')) { 00099 $SESSION->emailto[$id][$m[2]] = $user; 00100 $count++; 00101 } 00102 } 00103 } 00104 } 00105 } 00106 00107 $strtitle = get_string('coursemessage'); 00108 00109 $link = null; 00110 if (has_capability('moodle/course:viewparticipants', $coursecontext) || has_capability('moodle/site:viewparticipants', $systemcontext)) { 00111 $link = new moodle_url("/user/index.php", array('id'=>$course->id)); 00112 } 00113 $PAGE->navbar->add(get_string('participants'), $link); 00114 $PAGE->navbar->add($strtitle); 00115 $PAGE->set_title($strtitle); 00116 $PAGE->set_heading($strtitle); 00117 echo $OUTPUT->header(); 00118 // if messaging is disabled on site, we can still allow users with capabilities to send emails instead 00119 if (empty($CFG->messaging)) { 00120 echo $OUTPUT->notification(get_string('messagingdisabled','message')); 00121 } 00122 00123 if ($count) { 00124 if ($count == 1) { 00125 $heading = get_string('addedrecip','moodle',$count); 00126 } else { 00127 $heading = get_string('addedrecips','moodle',$count); 00128 } 00129 echo $OUTPUT->heading($heading); 00130 } 00131 00132 if (!empty($messagebody) && !$edit && !$deluser && ($preview || $send)) { 00133 if (count($SESSION->emailto[$id])) { 00134 if (!empty($preview)) { 00135 echo '<form method="post" action="messageselect.php" style="margin: 0 20px;"> 00136 <input type="hidden" name="returnto" value="'.s($returnto).'" /> 00137 <input type="hidden" name="id" value="'.$id.'" /> 00138 <input type="hidden" name="format" value="'.$format.'" /> 00139 '; 00140 echo "<h3>".get_string('previewhtml')."</h3><div class=\"messagepreview\">\n".format_text($messagebody,$format)."\n</div>\n"; 00141 echo '<p align="center"><input type="submit" name="send" value="'.get_string('sendmessage', 'message').'" />'."\n"; 00142 echo '<input type="submit" name="edit" value="'.get_string('update').'" /></p>'; 00143 echo "\n</form>"; 00144 } else if (!empty($send)) { 00145 $good = 1; 00146 foreach ($SESSION->emailto[$id] as $user) { 00147 $good = $good && message_post_message($USER,$user,$messagebody,$format); 00148 } 00149 if (!empty($good)) { 00150 echo $OUTPUT->heading(get_string('messagedselectedusers')); 00151 unset($SESSION->emailto[$id]); 00152 unset($SESSION->emailselect[$id]); 00153 } else { 00154 echo $OUTPUT->heading(get_string('messagedselectedusersfailed')); 00155 } 00156 echo '<p align="center"><a href="index.php?id='.$id.'">'.get_string('backtoparticipants').'</a></p>'; 00157 } 00158 echo $OUTPUT->footer(); 00159 exit; 00160 } else { 00161 echo $OUTPUT->notification(get_string('nousersyet')); 00162 } 00163 } 00164 00165 echo '<p align="center"><a href="'.$returnto.'">'.get_string("keepsearching").'</a>'.((count($SESSION->emailto[$id])) ? ', '.get_string('usemessageform') : '').'</p>'; 00166 00167 if ((!empty($send) || !empty($preview) || !empty($edit)) && (empty($messagebody))) { 00168 echo $OUTPUT->notification(get_string('allfieldsrequired')); 00169 } 00170 00171 if (count($SESSION->emailto[$id])) { 00172 $usehtmleditor = can_use_html_editor(); 00173 require("message.html"); 00174 } 00175 00176 echo $OUTPUT->footer(); 00177 00178