3 require_once('../config.php');
4 require_once($CFG->dirroot
.'/message/lib.php');
6 $id = required_param('id',PARAM_INT
);
7 $messagebody = optional_param('messagebody','',PARAM_CLEANHTML
);
8 $send = optional_param('send','',PARAM_ALPHA
);
9 $returnto = optional_param('returnto','',PARAM_LOCALURL
);
10 $preview = optional_param('preview','',PARAM_ALPHA
);
11 $format = optional_param('format',FORMAT_MOODLE
,PARAM_INT
);
12 $edit = optional_param('edit','',PARAM_ALPHA
);
13 $deluser = optional_param('deluser',0,PARAM_INT
);
15 if (!$course = get_record('course','id',$id)) {
16 error("Invalid course id");
20 require_capability('moodle/site:readallmessages', get_context_instance(CONTEXT_COURSE
, $id));
22 if (empty($SESSION->emailto
)) {
23 $SESSION->emailto
= array();
25 if (!array_key_exists($id,$SESSION->emailto
)) {
26 $SESSION->emailto
[$id] = array();
30 if (array_key_exists($id,$SESSION->emailto
) && array_key_exists($deluser,$SESSION->emailto
[$id])) {
31 unset($SESSION->emailto
[$id][$deluser]);
35 if (empty($SESSION->emailselect
[$id]) ||
$messagebody) {
36 $SESSION->emailselect
[$id] = array('messagebody' => $messagebody);
39 $messagebody = $SESSION->emailselect
[$id]['messagebody'];
43 foreach ($_POST as $k => $v) {
44 if (preg_match('/^(user|teacher)(\d+)$/',$k,$m)) {
45 if (!array_key_exists($m[2],$SESSION->emailto
[$id])) {
46 if ($user = get_record_select('user','id = '.$m[2],'id,firstname,lastname,idnumber,email,emailstop,mailformat,lastaccess')) {
47 $SESSION->emailto
[$id][$m[2]] = $user;
48 $SESSION->emailto
[$id][$m[2]]->teacher
= ($m[1] == 'teacher');
55 $strtitle = get_string('coursemessage');
57 if (empty($messagebody)) {
58 $formstart = "theform.messagebody";
63 print_header($strtitle,$strtitle,"<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A> -> <a href=\"index.php?id=$course->id\">".get_string("participants")."</a> -> ".$strtitle,$formstart);
68 $heading = get_string('addedrecip','moodle',$count);
70 $heading = get_string('addedrecips','moodle',$count);
72 print_heading($heading);
75 if (!empty($messagebody) && !$edit && !$deluser && ($preview ||
$send)) {
76 if (count($SESSION->emailto
[$id])) {
78 echo '<form method="post" action="messageselect.php" style="margin: 0 20px;">
79 <input type="hidden" name="returnto" value="'.stripslashes($returnto).'" />
80 <input type="hidden" name="id" value="'.$id.'" />
81 <input type="hidden" name="format" value="'.$format.'" />
83 echo "<h3>".get_string('previewhtml')."</h3><div class=\"messagepreview\">\n".format_text(stripslashes($messagebody),$format)."\n</div>";
84 echo "\n<p align=\"center\"><input type=\"submit\" name=\"send\" value=\"Send\" /> <input type=\"submit\" name=\"edit\" value=\"Edit\" /></p>\n</form>";
88 foreach ($SESSION->emailto
[$id] as $user) {
89 $good = $good && message_post_message($USER,$user,addslashes($messagebody),$format,'direct');
91 $teachers[] = $user->id
;
95 print_heading(get_string('messagedselectedusers'));
96 unset($SESSION->emailto
[$id]);
97 unset($SESSION->emailselect
[$id]);
99 print_heading(get_string('messagedselectedusersfailed'));
101 echo '<p align="center"><a href="index.php?id='.$id.'">'.get_string('backtoparticipants').'</a></p>';
106 notify(get_string('nousersyet'));
110 echo '<p align="center"><a href="'.$returnto.'">'.get_string("keepsearching").'</a>'.((count($SESSION->emailto
[$id])) ?
', '.get_string('usemessageform') : '').'</p>';
112 if ((!empty($send) ||
!empty($preview) ||
!empty($edit)) && (empty($messagebody))) {
113 notify(get_string('allfieldsrequired'));
116 if (count($SESSION->emailto
[$id])) {
117 $usehtmleditor = can_use_richtext_editor();
118 require("message.html");
119 if ($usehtmleditor) {
120 use_html_editor("messagebody");