Implement data privacy provider.
[moodle-mod_attendance.git] / tempusers.php
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 * Temporary user management.
19 *
20 * @package mod_attendance
21 * @copyright 2013 Davo Smith, Synergy Learning
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25 require_once(dirname(__FILE__).'/../../config.php');
26 global $CFG, $DB, $OUTPUT, $PAGE, $COURSE;
27 require_once($CFG->dirroot.'/mod/attendance/locallib.php');
28 require_once($CFG->dirroot.'/mod/attendance/temp_form.php');
29
30 $id = required_param('id', PARAM_INT);
31
32 $cm = get_coursemodule_from_id('attendance', $id, 0, false, MUST_EXIST);
33 $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
34 $att = $DB->get_record('attendance', array('id' => $cm->instance), '*', MUST_EXIST);
35
36 $att = new mod_attendance_structure($att, $cm, $course);
37 $PAGE->set_url($att->url_managetemp());
38
39 require_login($course, true, $cm);
40 $context = context_module::instance($cm->id);
41 require_capability('mod/attendance:managetemporaryusers', $context);
42
43 $PAGE->set_title($course->shortname.": ".$att->name.' - '.get_string('tempusers', 'attendance'));
44 $PAGE->set_heading($course->fullname);
45 $PAGE->set_cacheable(true);
46 $PAGE->navbar->add(get_string('tempusers', 'attendance'));
47
48 $output = $PAGE->get_renderer('mod_attendance');
49 $tabs = new attendance_tabs($att, attendance_tabs::TAB_TEMPORARYUSERS);
50
51 $formdata = (object)array(
52 'id' => $cm->id,
53 );
54 $mform = new temp_form();
55 $mform->set_data($formdata);
56
57 if ($data = $mform->get_data()) {
58 // Create temp user in main user table.
59 $user = new stdClass();
60 $user->auth = 'manual';
61 $user->confirmed = 1;
62 $user->deleted = 1;
63 $user->email = time().'@attendance.danmarsden.com';
64 $user->username = time().'@attendance.danmarsden.com';
65 $user->idnumber = 'tempghost';
66 $user->mnethostid = $CFG->mnet_localhost_id;
67 $studentid = $DB->insert_record('user', $user);
68
69 // Create the temporary user record.
70 $newtempuser = new stdClass();
71 $newtempuser->fullname = $data->tname;
72 $newtempuser->courseid = $COURSE->id;
73 $newtempuser->email = $data->temail;
74 $newtempuser->created = time();
75 $newtempuser->studentid = $studentid;
76 $DB->insert_record('attendance_tempusers', $newtempuser);
77
78 redirect($att->url_managetemp());
79 }
80
81 // Output starts here.
82 echo $output->header();
83 echo $output->heading(get_string('tempusers', 'attendance').' : '.format_string($course->fullname));
84 echo $output->render($tabs);
85 $mform->display();
86
87 $tempusers = $DB->get_records('attendance_tempusers', array('courseid' => $course->id), 'fullname, email');
88
89 echo '<div>';
90 echo '<p style="margin-left:10%;">'.get_string('tempuserslist', 'attendance').'</p>';
91 if ($tempusers) {
92 attendance_print_tempusers($tempusers, $att);
93 }
94 echo '</div>';
95 echo $output->footer($course);
96
97 /**
98 * Print list of users.
99 *
100 * @param stdClass $tempusers
101 * @param mod_attendance_structure $att
102 */
103 function attendance_print_tempusers($tempusers, mod_attendance_structure $att) {
104 echo '<p></p>';
105 echo '<table border="1" bordercolor="#EEEEEE" style="background-color:#fff" cellpadding="2" align="center"'.
106 'width="80%" summary="'.get_string('temptable', 'attendance').'"><tr>';
107 echo '<th class="header">'.get_string('tusername', 'attendance').'</th>';
108 echo '<th class="header">'.get_string('tuseremail', 'attendance').'</th>';
109 echo '<th class="header">'.get_string('tcreated', 'attendance').'</th>';
110 echo '<th class="header">'.get_string('tactions', 'attendance').'</th>';
111 echo '</tr>';
112
113 $even = false; // Used to colour rows.
114 foreach ($tempusers as $tempuser) {
115 if ($even) {
116 echo '<tr style="background-color: #FCFCFC">';
117 } else {
118 echo '<tr>';
119 }
120 $even = !$even;
121 echo '<td>'.format_string($tempuser->fullname).'</td>';
122 echo '<td>'.format_string($tempuser->email).'</td>';
123 echo '<td>'.userdate($tempuser->created, get_string('strftimedatetime')).'</td>';
124 $params = array('userid' => $tempuser->id);
125 $editlink = html_writer::link($att->url_tempedit($params), get_string('edituser', 'attendance'));
126 $deletelink = html_writer::link($att->url_tempdelete($params), get_string('deleteuser', 'attendance'));
127 $mergelink = html_writer::link($att->url_tempmerge($params), get_string('mergeuser', 'attendance'));
128 echo '<td>'.$editlink.' | '.$deletelink.' | '.$mergelink.'</td>';
129 echo '</tr>';
130 }
131 echo '</table>';
132 }
133
134