2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * Temporary user management.
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
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');
30 $id = required_param('id', PARAM_INT
);
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
);
36 $att = new mod_attendance_structure($att, $cm, $course);
37 $PAGE->set_url($att->url_managetemp());
39 require_login($course, true
, $cm);
40 $context = context_module
::instance($cm->id
);
41 require_capability('mod/attendance:managetemporaryusers', $context);
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'));
48 $output = $PAGE->get_renderer('mod_attendance');
49 $tabs = new attendance_tabs($att, attendance_tabs
::TAB_TEMPORARYUSERS
);
51 $formdata = (object)array(
54 $mform = new temp_form();
55 $mform->set_data($formdata);
57 if ($data = $mform->get_data()) {
58 // Create temp user in main user table.
59 $user = new stdClass();
60 $user->auth
= 'manual';
63 $user->email
= time().'@ghost.user.de';
64 $user->username
= time().'@ghost.user.de';
65 $user->idnumber
= 'tempghost';
66 $user->mnethostid
= $CFG->mnet_localhost_id
;
67 $studentid = $DB->insert_record('user', $user);
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);
78 redirect($att->url_managetemp());
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);
87 $tempusers = $DB->get_records('attendance_tempusers', array('courseid' => $course->id
), 'fullname, email');
90 echo '<p style="margin-left:10%;">'.get_string('tempuserslist', 'attendance').'</p>';
92 print_tempusers($tempusers, $att);
95 echo $output->footer($course);
97 function print_tempusers($tempusers, mod_attendance_structure
$att) {
99 echo '<table border="1" bordercolor="#EEEEEE" style="background-color:#fff" cellpadding="2" align="center"'.
100 'width="80%" summary="'.get_string('temptable', 'attendance').'"><tr>';
101 echo '<th class="header">'.get_string('tusername', 'attendance').'</th>';
102 echo '<th class="header">'.get_string('tuseremail', 'attendance').'</th>';
103 echo '<th class="header">'.get_string('tcreated', 'attendance').'</th>';
104 echo '<th class="header">'.get_string('tactions', 'attendance').'</th>';
107 $even = false
; // Used to colour rows.
108 foreach ($tempusers as $tempuser) {
110 echo '<tr style="background-color: #FCFCFC">';
115 echo '<td>'.format_string($tempuser->fullname
).'</td>';
116 echo '<td>'.format_string($tempuser->email
).'</td>';
117 echo '<td>'.userdate($tempuser->created
, get_string('strftimedatetime')).'</td>';
118 $params = array('userid' => $tempuser->id
);
119 $editlink = html_writer
::link($att->url_tempedit($params), get_string('edituser', 'attendance'));
120 $deletelink = html_writer
::link($att->url_tempdelete($params), get_string('deleteuser', 'attendance'));
121 $mergelink = html_writer
::link($att->url_tempmerge($params), get_string('mergeuser', 'attendance'));
122 echo '<td>'.$editlink.' | '.$deletelink.' | '.$mergelink.'</td>';