/
updateSession.php
196 lines (159 loc) · 6.9 KB
/
updateSession.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<?php // $Id: updateSession.php,v 1.3 2006/02/02 09:28:06 dlnsk Exp $
// Modified by Fumi.Iseki 2007/03/19
// 2013/04/05
/*
授業情報の更新
*/
require_once('../../config.php');
require_once($CFG->libdir.'/blocklib.php');
require_once(dirname(__FILE__).'/locallib.php');
$courseid = required_param('course', PARAM_INTEGER);
$attsid = required_param('attsid', PARAM_INTEGER);
$classid = optional_param('class', 0, PARAM_INTEGER);
$action = optional_param('action', '', PARAM_ALPHA);
$submit = optional_param('submit', '', PARAM_TEXT);
if (($formdata = data_submitted()) and !confirm_sesskey()) {
print_error('invalidsesskey');
}
$urlparams['course'] = $courseid;
$urlparams['attsid'] = $attsid;
if ($classid) $urlparams['class'] = $classid;
if ($action) $urlparams['action'] = $action;
$PAGE->set_url('/blocks/autoattend/updateSession.php', $urlparams);
$wwwBlock = $CFG->wwwroot.'/blocks/autoattend';
$wwwMyURL = $wwwBlock.'/updateSession.php';
$back2URL = $wwwBlock.'/index.php';
if (!empty($submit) && $submit==get_string('return', 'block_autoattend')) {
redirect($wwwBlock.'/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);
$isteacher = jbxl_is_teacher($USER->id, $context);
if (!$isteacher) {
print_error('notaccessnoteacher', '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');
}
// Print Header
if ($course->category) {
$title = get_string('updatesessioninfo','block_autoattend').' '.get_string('autoattend','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();
if ($action=='update') {
$newday = required_param('newday', PARAM_INTEGER);
$newmonth = required_param('newmonth', PARAM_INTEGER);
$newyear = required_param('newyear', PARAM_INTEGER);
$method = required_param('newmethod', PARAM_ALPHA);
$shour = required_param('newshour', PARAM_INTEGER);
$smin = required_param('newsmin', PARAM_INTEGER);
$dhour = required_param('newdhour', PARAM_INTEGER);
$dmin = required_param('newdmin', PARAM_INTEGER);
$lmin = required_param('newlmin', PARAM_INTEGER);
$allowip = required_param('allowip', PARAM_TEXT);
$desc = required_param('desc', PARAM_TEXT);
$attendkey = optional_param('attendkey', '', PARAM_ALPHA);
$randomkey = optional_param('randomkey', '', PARAM_INTEGER);
$summertime = optional_param('newsummer', 3, PARAM_INTEGER);
$denysameip = optional_param('denysameip', 0, PARAM_INTEGER);
if (empty($denysameip)) $denysameip = '0';
$summertime = $summertime - 3; // $summer = array(1=>-2,-1,0,1,2); in html/updateSession.html
$starttime = $shour*ONE_HOUR_TIME + $smin*ONE_MIN_TIME - $TIME_OFFSET - $summertime*ONE_HOUR_TIME;
$endtime = $starttime + ($dhour-1)*ONE_HOUR_TIME + ($dmin-1)*MIN_INTVL_TIME*ONE_MIN_TIME;
$latetime = ($lmin - 1)*MIN_INTVL_TIME*ONE_MIN_TIME;
$newdate = mktime(0, 0, 0, $newmonth, $newday, $newyear);
$times = $endtime - $starttime;
if($times <= 0) {
print_error('wrongtimesselected', 'block_autoattend', $wwwMyURL.'?course='.$course->id.'&class='.$classid.'&attsid='.$attsid);
}
$strtm = $newdate + $starttime;
$endtm = $newdate + $endtime;
$where = array('courseid'=>$course->id, 'sessdate'=>$newdate, 'starttime'=>$strtm, 'classid'=>$classid);
$count = $DB->count_records('autoattend_sessions', $where);
if ($count!=0 and ($newdate!=$att->sessdate or $strtm!=$att->starttime or $classid!=$att->classid)) { //duplicate session exists
print_error('sessionalreadyexists', 'block_autoattend', $wwwMyURL.'?course='.$course->id.'&class='.$classid.'&attsid='.$attsid);
}
else {
$ntime = time();
$state = $att->state;
if ($att->state!='C') $state = 'N';
// if ($ntime < $strtm) $state = 'N';
// else if ($ntime>=$strtm and $ntime<=$endtm) $state = 'O';
// else $state = 'O'; // ここでは Close 処理しない
// $prvstate = $att->state;
// $prvmethod = $att->method;
$att->sessdate = $newdate;
$att->classid = $classid;
$att->timemodified = time();
$att->method = $method;
$att->state = $state;
$att->starttime = $strtm;
$att->endtime = $endtm;
$att->summertime = $summertime;
$att->latetime = $latetime;
$att->allowip = $allowip;
$att->denysameip = $denysameip;
$att->description = $desc;
$att->attendkey = '';
if ($att->method=='S') {
if ($randomkey) {
$att->attendkey = jbxl_randstr(5, true);
}
else {
$att->attendkey = $attendkey;
}
}
$result = $DB->update_record('autoattend_sessions', $att);
if ($result) {
//$loginfo = 'id='.$attsid.',method='.$method.',state='.$state;
//$event = autoattend_get_event($context, 'upsesstion', $urlparams);
//jbxl_add_to_log($event);
}
else {
print_error('sessionupdateerror', 'block_autoattend', $wwwMyURL.'?course='.$course->id.'&class='.$classid.'&attsid='.$attsid);
}
//
autoattend_update_session($course->id, $attsid);
}
//
redirect($back2URL.'?course='.$course->id.'&class='.$classid.'&attsid='.$attsid, get_string('sessionupdated', 'block_autoattend'), 1);
}
//
$acheck = '';
$scheck = '';
$mcheck = '';
if ($att->method=='A') $acheck = 'checked="checked"';
else if ($att->method=='S') $scheck = 'checked="checked"';
else if ($att->method=='M') $mcheck = 'checked="checked"';
$late_time = (int)($att->latetime/ONE_MIN_TIME);
$late_order = (int)($late_time/5) + 1;
//
$currenttab = 'update';
include('tabs.php');
//
$use_summertime = autoattend_use_summertime($course->id);
$summertime = autoattend_get_summertime($att->id, $use_summertime)*ONE_HOUR_TIME;
$classes = autoattend_get_session_classes($course->id);
//
$date_name1 = get_string('date_1st_name', 'block_autoattend');
$date_name2 = get_string('date_2nd_name', 'block_autoattend');
$date_name3 = get_string('date_3rd_name', 'block_autoattend');
include('html/updateSession.html');
echo $OUTPUT->footer($course);