[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * This file is part of the User section Moodle 19 * 20 * @copyright 1999 Martin Dougiamas http://dougiamas.com 21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 * @package core_user 23 */ 24 25 require_once('../config.php'); 26 require_once($CFG->dirroot.'/message/lib.php'); 27 28 $id = required_param('id', PARAM_INT); 29 $messagebody = optional_param('messagebody', '', PARAM_CLEANHTML); 30 $send = optional_param('send', '', PARAM_BOOL); 31 $preview = optional_param('preview', '', PARAM_BOOL); 32 $edit = optional_param('edit', '', PARAM_BOOL); 33 $returnto = optional_param('returnto', '', PARAM_LOCALURL); 34 $format = optional_param('format', FORMAT_MOODLE, PARAM_INT); 35 $deluser = optional_param('deluser', 0, PARAM_INT); 36 37 $url = new moodle_url('/user/messageselect.php', array('id' => $id)); 38 if ($messagebody !== '') { 39 $url->param('messagebody', $messagebody); 40 } 41 if ($send !== '') { 42 $url->param('send', $send); 43 } 44 if ($preview !== '') { 45 $url->param('preview', $preview); 46 } 47 if ($edit !== '') { 48 $url->param('edit', $edit); 49 } 50 if ($returnto !== '') { 51 $url->param('returnto', $returnto); 52 } 53 if ($format !== FORMAT_MOODLE) { 54 $url->param('format', $format); 55 } 56 if ($deluser !== 0) { 57 $url->param('deluser', $deluser); 58 } 59 $PAGE->set_url($url); 60 61 if (!$course = $DB->get_record('course', array('id' => $id))) { 62 print_error('invalidcourseid'); 63 } 64 65 require_login($course); 66 67 $coursecontext = context_course::instance($id); // Course context. 68 $systemcontext = context_system::instance(); // SYSTEM context. 69 require_capability('moodle/course:bulkmessaging', $coursecontext); 70 71 if (empty($SESSION->emailto)) { 72 $SESSION->emailto = array(); 73 } 74 if (!array_key_exists($id, $SESSION->emailto)) { 75 $SESSION->emailto[$id] = array(); 76 } 77 78 if ($deluser) { 79 if (array_key_exists($id, $SESSION->emailto) && array_key_exists($deluser, $SESSION->emailto[$id])) { 80 unset($SESSION->emailto[$id][$deluser]); 81 } 82 } 83 84 if (empty($SESSION->emailselect[$id]) || $messagebody) { 85 $SESSION->emailselect[$id] = array('messagebody' => $messagebody); 86 } 87 88 $messagebody = $SESSION->emailselect[$id]['messagebody']; 89 90 $count = 0; 91 92 if ($data = data_submitted()) { 93 require_sesskey(); 94 $namefields = get_all_user_name_fields(true); 95 foreach ($data as $k => $v) { 96 if (preg_match('/^(user|teacher)(\d+)$/', $k, $m)) { 97 if (!array_key_exists($m[2], $SESSION->emailto[$id])) { 98 if ($user = $DB->get_record_select('user', "id = ?", array($m[2]), 'id, '. 99 $namefields . ', idnumber, email, mailformat, lastaccess, lang, '. 100 'maildisplay, auth, suspended, deleted, emailstop')) { 101 $SESSION->emailto[$id][$m[2]] = $user; 102 $count++; 103 } 104 } 105 } 106 } 107 } 108 109 if ($course->id == SITEID) { 110 $strtitle = get_string('sitemessage'); 111 $PAGE->set_pagelayout('admin'); 112 } else { 113 $strtitle = get_string('coursemessage'); 114 $PAGE->set_pagelayout('incourse'); 115 } 116 117 $link = null; 118 if (has_capability('moodle/course:viewparticipants', $coursecontext) || 119 has_capability('moodle/site:viewparticipants', $systemcontext)) { 120 $link = new moodle_url("/user/index.php", array('id' => $course->id)); 121 } 122 $PAGE->navbar->add(get_string('participants'), $link); 123 $PAGE->navbar->add($strtitle); 124 $PAGE->set_title($strtitle); 125 $PAGE->set_heading($strtitle); 126 echo $OUTPUT->header(); 127 // If messaging is disabled on site, we can still allow users with capabilities to send emails instead. 128 if (empty($CFG->messaging)) { 129 echo $OUTPUT->notification(get_string('messagingdisabled', 'message')); 130 } 131 132 if ($count) { 133 if ($count == 1) { 134 $heading = get_string('addedrecip', 'moodle', $count); 135 } else { 136 $heading = get_string('addedrecips', 'moodle', $count); 137 } 138 echo $OUTPUT->heading($heading); 139 } 140 141 if (!empty($messagebody) && !$edit && !$deluser && ($preview || $send)) { 142 require_sesskey(); 143 if (count($SESSION->emailto[$id])) { 144 if (!empty($preview)) { 145 echo '<form method="post" action="messageselect.php" style="margin: 0 20px;"> 146 <input type="hidden" name="returnto" value="'.s($returnto).'" /> 147 <input type="hidden" name="id" value="'.$id.'" /> 148 <input type="hidden" name="format" value="'.$format.'" /> 149 <input type="hidden" name="sesskey" value="' . sesskey() . '" /> 150 '; 151 echo "<h3>".get_string('previewhtml')."</h3>"; 152 echo "<div class=\"messagepreview\">\n".format_text($messagebody, $format)."\n</div>\n"; 153 echo '<p align="center"><input type="submit" name="send" value="'.get_string('sendmessage', 'message').'" />'."\n"; 154 echo '<input type="submit" name="edit" value="'.get_string('update').'" /></p>'; 155 echo "\n</form>"; 156 } else if (!empty($send)) { 157 $good = 1; 158 foreach ($SESSION->emailto[$id] as $user) { 159 $good = $good && message_post_message($USER, $user, $messagebody, $format); 160 } 161 if (!empty($good)) { 162 echo $OUTPUT->heading(get_string('messagedselectedusers')); 163 unset($SESSION->emailto[$id]); 164 unset($SESSION->emailselect[$id]); 165 } else { 166 echo $OUTPUT->heading(get_string('messagedselectedusersfailed')); 167 } 168 echo '<p align="center"><a href="index.php?id='.$id.'">'.get_string('backtoparticipants').'</a></p>'; 169 } 170 echo $OUTPUT->footer(); 171 exit; 172 } else { 173 echo $OUTPUT->notification(get_string('nousersyet')); 174 } 175 } 176 177 echo '<p align="center"><a href="'.$returnto.'">'.get_string("keepsearching").'</a>'. 178 ((count($SESSION->emailto[$id])) ? ', '.get_string('usemessageform') : '').'</p>'; 179 180 if ((!empty($send) || !empty($preview) || !empty($edit)) && (empty($messagebody))) { 181 echo $OUTPUT->notification(get_string('allfieldsrequired')); 182 } 183 184 if (count($SESSION->emailto[$id])) { 185 require_sesskey(); 186 require ("message.html"); 187 } 188 189 echo $OUTPUT->footer(); 190 191
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |