Proyectos de Subversion Moodle

Rev

Rev 11 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
 * print the single entries
19
 *
20
 * @author Andreas Grabs
21
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
22
 * @package mod_feedback
23
 */
24
 
1441 ariadna 25
use mod_feedback\manager;
26
 
1 efrain 27
require_once("../../config.php");
28
require_once("lib.php");
29
require_once($CFG->libdir.'/tablelib.php');
30
 
31
////////////////////////////////////////////////////////
32
//get the params
33
////////////////////////////////////////////////////////
34
$id = required_param('id', PARAM_INT);
35
$subject = optional_param('subject', '', PARAM_CLEANHTML);
36
$message = optional_param_array('message', '', PARAM_CLEANHTML);
37
$format = optional_param('format', FORMAT_MOODLE, PARAM_INT);
38
$messageuser = optional_param_array('messageuser', false, PARAM_INT);
39
$action = optional_param('action', '', PARAM_ALPHA);
40
$perpage = optional_param('perpage', FEEDBACK_DEFAULT_PAGE_COUNT, PARAM_INT);  // how many per page
41
$showall = optional_param('showall', false, PARAM_INT);  // should we show all users
42
 
43
////////////////////////////////////////////////////////
44
//get the objects
45
////////////////////////////////////////////////////////
46
 
47
if ($message) {
48
    $message = $message['text'];
49
}
50
 
51
list ($course, $cm) = get_course_and_cm_from_cmid($id, 'feedback');
52
if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
53
    throw new \moodle_exception('invalidcoursemodule');
54
}
55
 
56
//this page only can be shown on nonanonymous feedbacks in courses
57
//we should never reach this page
58
if ($feedback->anonymous != FEEDBACK_ANONYMOUS_NO OR $feedback->course == SITEID) {
59
    throw new \moodle_exception('error');
60
}
61
 
62
$url = new moodle_url('/mod/feedback/show_nonrespondents.php', array('id'=>$cm->id));
63
 
64
$PAGE->set_url($url);
65
 
66
$context = context_module::instance($cm->id);
67
 
68
//we need the coursecontext to allow sending of mass mails
69
$coursecontext = context_course::instance($course->id);
70
 
71
require_login($course, true, $cm);
72
 
73
$actionbar = new \mod_feedback\output\responses_action_bar($cm->id, $url);
74
 
75
require_capability('mod/feedback:viewreports', $context);
76
 
11 efrain 77
$currentgroup = groups_get_activity_group($cm, true);
78
$incompleteusers = feedback_get_incomplete_users($cm, $currentgroup);
79
 
1 efrain 80
$canbulkmessaging = has_capability('moodle/course:bulkmessaging', $coursecontext);
11 efrain 81
if ($action == 'sendmessage' && $canbulkmessaging) {
82
    require_sesskey();
83
 
1 efrain 84
    $shortname = format_string($course->shortname,
85
                            true,
86
                            array('context' => $coursecontext));
87
    $strfeedbacks = get_string("modulenameplural", "feedback");
88
 
89
    $htmlmessage = "<body id=\"email\">";
90
 
91
    $link1 = $CFG->wwwroot.'/course/view.php?id='.$course->id;
92
    $link2 = $CFG->wwwroot.'/mod/feedback/index.php?id='.$course->id;
93
    $link3 = $CFG->wwwroot.'/mod/feedback/view.php?id='.$cm->id;
94
 
95
    $htmlmessage .= '<div class="navbar">'.
96
    '<a target="_blank" href="'.$link1.'">'.$shortname.'</a> &raquo; '.
97
    '<a target="_blank" href="'.$link2.'">'.$strfeedbacks.'</a> &raquo; '.
98
    '<a target="_blank" href="'.$link3.'">'.format_string($feedback->name, true).'</a>'.
99
    '</div>';
100
 
101
    $htmlmessage .= $message;
102
    $htmlmessage .= '</body>';
103
 
104
    $good = 1;
105
    if (is_array($messageuser)) {
11 efrain 106
 
107
        // Ensure selected users are part of the "incomplete users" set.
108
        $messageuser = array_intersect($messageuser, $incompleteusers);
109
 
1 efrain 110
        foreach ($messageuser as $userid) {
111
            $senduser = $DB->get_record('user', array('id'=>$userid));
112
            $eventdata = new \core\message\message();
113
            $eventdata->courseid         = $course->id;
114
            $eventdata->name             = 'message';
115
            $eventdata->component        = 'mod_feedback';
116
            $eventdata->userfrom         = $USER;
117
            $eventdata->userto           = $senduser;
118
            $eventdata->subject          = $subject;
119
            $eventdata->fullmessage      = html_to_text($htmlmessage);
120
            $eventdata->fullmessageformat = FORMAT_PLAIN;
121
            $eventdata->fullmessagehtml  = $htmlmessage;
122
            $eventdata->smallmessage     = '';
123
            $eventdata->courseid         = $course->id;
124
            $eventdata->contexturl       = $link3;
125
            $eventdata->contexturlname   = $feedback->name;
126
            $good = $good && message_send($eventdata);
127
        }
128
        if (!empty($good)) {
129
            $msg = $OUTPUT->heading(get_string('messagedselectedusers'));
130
        } else {
131
            $msg = $OUTPUT->heading(get_string('messagedselectedusersfailed'));
132
        }
133
        redirect($url, $msg, 4);
134
        exit;
135
    }
136
}
137
 
138
////////////////////////////////////////////////////////
139
//get the responses of given user
140
////////////////////////////////////////////////////////
141
 
142
/// Print the page header
143
$PAGE->set_heading($course->fullname);
144
$PAGE->set_title($feedback->name);
145
$PAGE->set_secondary_active_tab('responses');
146
if ($responsesnode = $PAGE->settingsnav->find('responses', navigation_node::TYPE_CUSTOM)) {
147
    $responsesnode->make_active();
148
}
149
$PAGE->activityheader->set_attrs([
150
    'hidecompletion' => true,
151
    'description' => ''
152
]);
153
echo $OUTPUT->header();
154
 
155
/** @var \mod_feedback\output\renderer $renderer */
156
$renderer = $PAGE->get_renderer('mod_feedback');
157
echo $renderer->main_action_bar($actionbar);
1441 ariadna 158
if (!manager::can_see_others_in_groups($cm)) {
159
    // The user is not in a group so show message and exit.
160
    echo $OUTPUT->notification(get_string('notingroup'));
161
    echo $OUTPUT->footer();
162
    exit();
163
}
1 efrain 164
/// Print the main part of the page
165
///////////////////////////////////////////////////////////////////////////
166
///////////////////////////////////////////////////////////////////////////
167
///////////////////////////////////////////////////////////////////////////
168
 
169
////////////////////////////////////////////////////////
170
/// Print the users with no responses
171
////////////////////////////////////////////////////////
172
$groupselect = groups_print_activity_menu($cm, $url->out(), true);
173
 
174
// preparing the table for output
175
$baseurl = new moodle_url('/mod/feedback/show_nonrespondents.php');
176
$baseurl->params(array('id'=>$id, 'showall'=>$showall));
177
 
178
$tablecolumns = array('userpic', 'fullname', 'status');
179
$tableheaders = array(get_string('userpic'), get_string('fullnameuser'), get_string('status'));
180
 
181
if ($canbulkmessaging) {
182
    $tablecolumns[] = 'select';
183
 
184
    // Build the select/deselect all control.
185
    $selectallid = 'selectall-non-respondents';
186
    $mastercheckbox = new \core\output\checkbox_toggleall('feedback-non-respondents', true, [
187
        'id' => $selectallid,
188
        'name' => $selectallid,
189
        'value' => 1,
190
        'label' => get_string('select'),
191
        // Consistent label to prevent the select column from resizing.
192
        'selectall' => get_string('select'),
193
        'deselectall' => get_string('select'),
194
        'labelclasses' => 'm-0',
195
    ]);
196
    $tableheaders[] = $OUTPUT->render($mastercheckbox);
197
}
198
 
199
$table = new flexible_table('feedback-shownonrespondents-'.$course->id);
200
 
201
$table->define_columns($tablecolumns);
202
$table->define_headers($tableheaders);
203
$table->define_baseurl($baseurl);
204
 
205
$table->sortable(true, 'lastname', SORT_DESC);
206
$table->set_attribute('cellspacing', '0');
207
$table->set_attribute('id', 'showentrytable');
208
$table->set_attribute('class', 'generaltable generalbox');
209
$table->set_control_variables(array(
210
            TABLE_VAR_SORT    => 'ssort',
211
            TABLE_VAR_IFIRST  => 'sifirst',
212
            TABLE_VAR_ILAST   => 'silast',
213
            TABLE_VAR_PAGE    => 'spage'
214
            ));
215
 
216
$table->no_sorting('select');
217
$table->no_sorting('status');
218
 
219
$table->setup();
220
 
221
if ($table->get_sql_sort()) {
222
    $sort = $table->get_sql_sort();
223
} else {
224
    $sort = '';
225
}
226
 
11 efrain 227
$matchcount = count($incompleteusers);
1 efrain 228
$table->initialbars(false);
229
 
230
if ($showall) {
231
    $startpage = false;
232
    $pagecount = false;
233
} else {
234
    $table->pagesize($perpage, $matchcount);
235
    $startpage = $table->get_page_start();
236
    $pagecount = $table->get_page_size();
237
}
238
 
239
// Return students record including if they started or not the feedback.
11 efrain 240
$students = feedback_get_incomplete_users($cm, $currentgroup, $sort, $startpage, $pagecount, true);
1 efrain 241
//####### viewreports-start
242
//print the list of students
243
echo $OUTPUT->heading(get_string('non_respondents_students', 'feedback', $matchcount), 4);
244
echo isset($groupselect) ? $groupselect : '';
245
echo '<div class="clearer"></div>';
246
 
247
if (empty($students)) {
248
    echo $OUTPUT->notification(get_string('noexistingparticipants', 'enrol'));
249
} else {
250
 
251
    if ($canbulkmessaging) {
252
        echo '<form class="mform" action="show_nonrespondents.php" method="post" id="feedback_sendmessageform">';
253
    }
254
 
255
    foreach ($students as $student) {
256
        //userpicture and link to the profilepage
257
        $profileurl = $CFG->wwwroot.'/user/view.php?id='.$student->id.'&amp;course='.$course->id;
258
        $profilelink = '<strong><a href="'.$profileurl.'">'.fullname($student).'</a></strong>';
259
        $data = array($OUTPUT->user_picture($student, array('courseid' => $course->id)), $profilelink);
260
 
261
        if ($student->feedbackstarted) {
262
            $data[] = get_string('started', 'feedback');
263
        } else {
264
            $data[] = get_string('not_started', 'feedback');
265
        }
266
 
267
        //selections to bulk messaging
268
        if ($canbulkmessaging) {
269
            $checkbox = new \core\output\checkbox_toggleall('feedback-non-respondents', false, [
270
                'id' => 'messageuser-' . $student->id,
271
                'name' => 'messageuser[]',
1441 ariadna 272
                'classes' => 'me-1',
1 efrain 273
                'value' => $student->id,
274
                'label' => get_string('includeuserinrecipientslist', 'mod_feedback', fullname($student)),
275
                'labelclasses' => 'accesshide',
276
            ]);
277
            $data[] = $OUTPUT->render($checkbox);
278
        }
279
        $table->add_data($data);
280
    }
281
    $table->print_html();
282
 
283
    $allurl = new moodle_url($baseurl);
284
 
285
    if ($showall) {
286
        $allurl->param('showall', 0);
287
        echo $OUTPUT->container(html_writer::link($allurl, get_string('showperpage', '', FEEDBACK_DEFAULT_PAGE_COUNT)),
288
                                    array(), 'showall');
289
 
290
    } else if ($matchcount > 0 && $perpage < $matchcount) {
291
        $allurl->param('showall', 1);
292
        echo $OUTPUT->container(html_writer::link($allurl, get_string('showall', '', $matchcount)), array(), 'showall');
293
    }
294
    if ($canbulkmessaging) {
295
        echo '<fieldset class="clearfix">';
296
        echo '<legend class="ftoggler">'.get_string('send_message', 'feedback').'</legend>';
297
        echo '<div>';
298
        echo '<label for="feedback_subject">'.get_string('subject', 'feedback').'&nbsp;</label>';
299
        echo '<input type="text" id="feedback_subject" size="50" maxlength="255" name="subject" value="'.s($subject).'" />';
300
        echo '</div>';
301
        echo $OUTPUT->print_textarea('message', 'edit-message', $message, 15, 25);
302
        print_string('formathtml');
303
        echo '<input type="hidden" name="format" value="'.FORMAT_HTML.'" />';
304
        echo '<br /><div class="buttons">';
305
        echo '<input type="submit" name="send_message" value="'.get_string('send', 'feedback').'" class="btn btn-secondary" />';
306
        echo '</div>';
307
        echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
308
        echo '<input type="hidden" name="action" value="sendmessage" />';
309
        echo '<input type="hidden" name="id" value="'.$id.'" />';
310
        echo '</fieldset>';
311
        echo '</form>';
312
    }
313
}
314
 
315
/// Finish the page
316
///////////////////////////////////////////////////////////////////////////
317
///////////////////////////////////////////////////////////////////////////
318
///////////////////////////////////////////////////////////////////////////
319
 
320
echo $OUTPUT->footer();
321