-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathalert.php
143 lines (122 loc) · 4.71 KB
/
alert.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Script to send alert for inappropriate posts, or show form for it.
* @package mod
* @subpackage forumng
* @copyright 2011 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once('../../config.php');
require_once('mod_forumng.php');
$postid = required_param('p', PARAM_INT);
$cloneid = optional_param('clone', 0, PARAM_INT);
$rurl = optional_param('rurl', 0, PARAM_TEXT);
$pageparams = array('p'=>$postid);
if ($cloneid) {
$pageparams['clone'] = $cloneid;
}
$post = mod_forumng_post::get_from_id($postid, $cloneid);
$discussion = $post->get_discussion();
$d = $discussion->get_id();
$forum = $post->get_forum();
$forumngid = $forum->get_id();
$course = $forum->get_course();
// Check permission
$post->require_view();
if (!$post->can_alert($whynot)) {
throw new moodle_exception($whynot, 'forumng');
}
// Set up page
$pagename = get_string('alert_pagename', 'forumng');
$url = new moodle_url('/mod/forumng/alert.php', $pageparams);
$out = $discussion->init_page($url, $pagename);
// Create the alert form
require_once('alert_form.php');
$customdata = (object)array(
'forumname' => $forum->get_name(),
'discussionid' => $d,
'postid' => $postid,
'cloneid' => $cloneid,
'email' => $USER->email,
'username' => $USER->username,
'ip' => getremoteaddr(),
'fullname' => fullname($USER, true),
'coursename' => $course->shortname,
'url' => $CFG->wwwroot . '/mod/forumng/discuss.php?' .
$discussion->get_link_params(mod_forumng::PARAM_PLAIN) . '#p'.$postid,
'rurl' => $rurl
);
$mform = new mod_forumng_alert_form('alert.php', $customdata);
// If cancelled, return to the post
if ($mform->is_cancelled()) {
redirect('discuss.php?' . $discussion->get_link_params(mod_forumng::PARAM_PLAIN) .
'#p' . $postid);
}
// If the alert form has been submitted successfully, send the email.
if ($fromform = $mform->get_data()) {
$alltext = get_string('alert_emailpreface', 'forumng', $customdata)."\n\n";
// Print the reasons for reporting
$alltext .= get_string('alert_reasons', 'forumng', $customdata)."\n";
if (!empty($fromform->alert_condition1)) {
$alltext .= '* '.get_string('alert_condition1', 'forumng')."\n";
}
if (!empty($fromform->alert_condition2)) {
$alltext .= '* '.get_string('alert_condition2', 'forumng')."\n";
}
if (!empty($fromform->alert_condition3)) {
$alltext .= '* '.get_string('alert_condition3', 'forumng')."\n";
}
if (!empty($fromform->alert_condition4)) {
$alltext .= '* '.get_string('alert_condition4', 'forumng')."\n";
}
if (!empty($fromform->alert_condition5)) {
$alltext .= '* '.get_string('alert_condition5', 'forumng')."\n";
}
if (!empty($fromform->alert_condition6)) {
$alltext .= '* '.get_string('alert_condition6', 'forumng')."\n";
}
if (!empty($fromform->alert_conditionmore)) {
$alltext .= "\n".$fromform->alert_conditionmore."\n";
}
$recipients = $forum->get_reportingemails();
foreach ($recipients as $forumemail) {
// Send out email.
$fakeuser = (object)array(
'email' => $forumemail,
'mailformat' => 1,
'id' => -1
);
$from = $USER;
$subject = get_string('alert_emailsubject', 'forumng', $customdata);
$alltext .= get_string('alert_emailappendix', 'forumng' );
if (!email_to_user($fakeuser, $from, $subject, $alltext)) {
throw new moodle_exception('error_sendalert', 'forumng', $url, $fakeuser->email);
}
}
// Log it after senting out
$post->log('report post');
print $out->header();
print $out->box(get_string('alert_feedback', 'forumng'));
$redirecturl = empty($rurl) ? 'discuss.php?' .
$discussion->get_link_params(mod_forumng::PARAM_HTML) . '#p' . $postid : $rurl;
print $out->continue_button($redirecturl);
} else {
// Show the alert form.
print $out->header();
print $mform->display();
}
print $out->footer();