/
semiautoattend.php
172 lines (142 loc) · 5.07 KB
/
semiautoattend.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
// by Fumi.Iseki 2007/03/28
// 2012/04/19
// 2013/04/14
// 2016/01/04
require_once('../../config.php');
require_once(dirname(__FILE__).'/locallib.php');
$courseid = required_param('course', PARAM_INTEGER); // Course id
$attsid = required_param('attsid', PARAM_INTEGER);
$classid = optional_param('class', 0, PARAM_INTEGER);
$checkkey = optional_param('checkkey','', PARAM_ALPHA);
$submit = optional_param('submit','', PARAM_TEXT);
if (($formdata = data_submitted()) and !confirm_sesskey()) {
print_error('invalidsesskey');
}
//
//session_get_instance()->write_close();
$urlparams['course'] = $courseid;
$urlparams['attsid'] = $attsid;
if ($classid) $urlparams['class'] = $classid;
if ($checkkey) $urlparams['checkkey'] = $checkkey;
$PAGE->set_url('/blocks/autoattend/semiautoattend.php', $urlparams);
$wwwBlock = $CFG->wwwroot.'/blocks/autoattend';
$wwwMyURL = $wwwBlock.'/semiautoattend.php';
if (!empty($submit) && $submit==get_string('cancel')) {
redirect('index.php?course='.$courseid.'&class='.$classid);
}
$course = $DB->get_record('course', array('id'=>$courseid));
if (!$course) {
print_error('courseidwrong', 'block_autoattend');
}
require_login($course->id);
$context = jbxl_get_course_context($course->id);
$isguest = isguestuser();
if ($isguest) {
print_error('notaccessguest', 'block_autoattend');
}
$user = $DB->get_record('user', array('id'=>$USER->id));
if (!$user) {
print_error('nosuchuser', 'block_autoattend');
}
$att = $DB->get_record('autoattend_sessions', array('id'=>$attsid));
if (!$att) {
print_error('nosuchsession', 'block_autoattend');
}
$iperrmesg = "";
$keyerrmesg = "";
$submitmesg = "";
$attendkey = $att->attendkey;
// Print Header
if ($course->category) {
$title = get_string('submitattend','block_autoattend').' '.get_string('session','block_autoattend');
}
else {
$title = $course->shortname.': '.get_string('autoattend','block_autoattend');
}
$PAGE->set_title($title);
$PAGE->set_heading($course->fullname);
$PAGE->set_cacheable(true);
$PAGE->set_button(' ');
//$PAGE->set_headingmenu();
echo $OUTPUT->header();
// Cancel !!
if (isset($formdata->cancel)) {
redirect($wwwBlock.'/index.php?course='.$course->id.'&class='.$classid);
}
// Submit!!
if (isset($formdata->submit)) {
if ($att->method!='S' or $att->state!='O') {
print_error('nosuchsession', 'block_autoattend');
}
if (!$stdnt = $DB->get_record('autoattend_students', array('attsid'=>$att->id, 'studentid'=>$user->id))) {
print_error('nosuchuser', 'block_autoattend');
}
if (($checkkey and $attendkey==$checkkey) or $attendkey=='') {
$iperrmesg = '';
if ($att->allowip!='' or $att->denysameip) $iperrmesg = autoattend_check_invalid_semiautoip($att);
if (!$iperrmesg) {
$ntime = time();
$status = 'P';
if ($att->latetime!=0) {
$ctime = $att->starttime + $att->latetime;
if ($ntime > $ctime) $status = 'L';
}
$rec = new stdClass();
$rec->id = $stdnt->id;
$rec->attsid = $att->id;
$rec->studentid = $stdnt->studentid;
$rec->status = $status;
$rec->called = 'S';
$rec->calledby = CALLED_BY_SEMIAUTO;
$rec->calledtime = $ntime;
$rec->sentemail = $stdnt->sentemail;
$rec->remarks = $stdnt->remarks;
$rec->ipaddress = getremoteaddr();
// $status は P か L
$sentemail = false;
if (autoattend_is_email_user($courseid) and !$rec->sentemail) {
$rec->sentemail = 1;
$sentemail = true;
}
$result = $DB->update_record('autoattend_students', $rec);
if ($result) {
if ($sentemail) autoattend_email_user($att, $user, $status, $courseid);
//
$loginfo = SEMIAUTO_SUBMIT_LOG.',id='.$att->id.',user='.$stdnt->studentid.',status='.$rec->status.',ip='.$rec->ipaddress;
$event = autoattend_get_event($context, 'submit', '', $loginfo);
jbxl_add_to_log($event);
redirect($wwwBlock.'/index.php?course='.$course->id.'&class='.$classid, get_string('attendsuccess', 'block_autoattend'), 1);
}
else {
$loginfo = SEMIAUTO_SUBMIT_LOG.',id='.$att->id.',user='.$stdnt->studentid.',DB Error';
$event = autoattend_get_event($context, 'submit', '', $loginfo);
jbxl_add_to_log($event);
redirect($wwwBlock.'/index.php?course='.$course->id.'&class='.$classid, get_string('attenderror', 'block_autoattend'), 5);
}
}
else {
$ipaddr = getremoteaddr();
$loginfo = SEMIAUTO_SUBMIT_LOG.',id='.$att->id.',user='.$stdnt->studentid.',IP Error('.$ipaddr.')';
$event = autoattend_get_event($context, 'submit', '', $loginfo);
jbxl_add_to_log($event);
}
}
//
else {
$loginfo = SEMIAUTO_SUBMIT_LOG.',id='.$att->id.',user='.$stdnt->studentid.',Key Error('.$checkkey.')';
$event = autoattend_get_event($context, 'submit', '', $loginfo);
jbxl_add_to_log($event);
$keyerrmesg = get_string('mismatchkey', 'block_autoattend');
}
}
//
else {
$loginfo = SEMIAUTO_SUBMIT_LOG.',id='.$att->id;
//$event = autoattend_get_event($context, 'submit', '', $loginfo);
//jbxl_add_to_log($event);
}
//// Table
$use_summertime = autoattend_use_summertime($courseid);
include('html/semiautoattend.html');
echo $OUTPUT->footer($course);