-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview.php
More file actions
161 lines (143 loc) · 5.95 KB
/
view.php
File metadata and controls
161 lines (143 loc) · 5.95 KB
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
<?php // $Id: view.php,v 1.4 2006/08/28 16:41:20 mark-nielsen Exp $
/**
* This page prints a particular instance of electalive
*
* @author Mark Nielsen, others, Chris Egle
* @version $Id:
* @package electalive
**/
require_once("../../config.php");
require_once("lib.php");
global $DB;
$id = optional_param('id', 0, PARAM_INT); // Course Module ID, or
$a = optional_param('a', 0, PARAM_INT); // electalive ID
if ($id) {
if (! $cm = get_coursemodule_from_id('electalive', $id)) {
print_error('invalidcoursemodule');
}
if (! $course = $DB->get_record("course", array("id" => $cm->course))) {
print_error('coursemisconf');
}
if (! $electalive = $DB->get_record("electalive", array("id" => $cm->instance))) {
print_error('invalidcoursemodule');
}
} else {
if (! $electalive = $DB->get_record("electalive", array("id"=> $a))) {
print_error('invalidcoursemodule');
}
if (! $course = $DB->get_record("course", array("id" => $electalive->course))) {
print_error('coursemisconf');
}
if (! $cm = get_coursemodule_from_instance("electalive", $electalive->id, $course->id)) {
print_error('invalidcoursemodule');
}
}
// Check login and get context.
require_login($course, false, $cm);
$context = context_module::instance($cm->id);
require_capability('mod/electalive:view', $context);
// Log this request.
$params = array(
'objectid' => $electalive->id,
'context' => $context
);
$event = \mod_electalive\event\course_module_viewed::create($params);
$event->trigger();
// Initialize $PAGE, print headers
if ($course->category) {
$navigation = "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->";
} else {
$navigation = '';
}
$strelectalives = get_string("modulenameplural", "electalive");
$strelectalive = get_string("modulename", "electalive");
$PAGE->set_url('/mod/electalive/view.php', array('id' => $cm->id));
$PAGE->set_context($context);
$pagetitle = $course->shortname.': '.$electalive->name;
$PAGE->set_title($pagetitle);
$PAGE->set_heading($course->fullname);
$PAGE->set_cacheable(true);
$PAGE->set_button(update_module_button($cm->id, $course->id, $strelectalive));
echo $OUTPUT->header();
echo $OUTPUT->heading(format_text($electalive->name));
// Print the main part of the page
if (!empty($electalive->intro)) {
echo $OUTPUT->box(format_module_intro('electalive', $electalive, $cm->id), 'generalbox', 'intro');
}
$t = time();
//get earlyopen, moderatorearlyopen from instance
$earlyopen = $electalive->earlyopen*60; //time in seconds to open the classroom before the start time
$moderatorearlyopen = $electalive->moderatorearlyopen*60; // time in seconds to open the classroom before the start time for instructors and teachers
$text = get_string('meetingon', 'electalive');
// set open time for those with moderator privileges
if (electalive_getAccountType($cm->id) > 500){
$moderatormeetingopen = $electalive->meetingtime - $moderatorearlyopen;
}
// set open time for everyone else
$meetingopen = $electalive->meetingtime - $earlyopen;
$meetingtimeend = $electalive->meetingtimeend;
$randomtime = rand(1,75); // distribute the load for the server
$refreshtime = $meetingtimeend - $t + $randomtime;
$maxrefresh = 15120; // 4.2 hours - greater than the maximum session time for Moodle - so the page refresh doesn't keep someone logged in inadvertantly
$button = electalive_buildURLString($electalive->roomid, $cm->id);
$moderatoropennotice='';
if (isset($moderatormeetingopen) && $meetingopen > $t) {
if ($moderatormeetingopen > $t) {
$text = get_string('meetingnotstarted', 'electalive');
$button = '';
$moderatoropennotice = get_string('moderatoropennotice', 'electalive',userdate($moderatormeetingopen));
// no random timing for instructors
$refreshtime = $moderatormeetingopen - $t;
} else {
//$regularopening = userdate($meetingopen);
$text = get_string('moderatoronlystarted', 'electalive',userdate($meetingopen));
}
} else {
if ($meetingopen > $t) {
$text = get_string('meetingnotstarted', 'electalive');
$button = '';
$refreshtime = $meetingopen - $t + $randomtime;
}
}
// limit refresh time to maxrefresh
if ($refreshtime > $maxrefresh) {
$refreshtime = $maxrefresh;
}
// set refreshtime to 0 if the session is already over
if ($t > $meetingtimeend) {
$text = get_string('meetingover', 'electalive');
$button = '';
//$refreshtime = $maxrefresh + $randomtime;
$refreshtime = 0;
}
// convert to microseconds
$refreshtime = $refreshtime*1000;
?>
<table class="table table-striped table-bordered">
<tbody>
<tr>
<td><?php print_string('meetingopens', 'electalive'); ?></td>
<td><b><?php echo userdate($meetingopen); ?></b><?php echo $moderatoropennotice; ?></td>
</tr>
<tr>
<td><?php print_string('meetingtime', 'electalive'); ?></td>
<td><b><?php echo userdate($electalive->meetingtime); ?></b></td>
</tr>
<tr>
<td><?php print_string('meetingends', 'electalive');?></td>
<td><b><?php echo userdate($electalive->meetingtimeend); ?></b></td>
</tr>
</tbody>
</table>
<?php
echo '<div style="padding:30px 0">'.$text.'</div>';
echo $button;
update_module_button($cm->id, $course->id, $strelectalive);
// skip setting the page to reload if the refreshtime is 0
if ($refreshtime > 0){
echo '<script type="text/javascript">
var electalive_t = setTimeout(function(){window.location.reload()},'.$refreshtime.' )
</script>';
}
echo $OUTPUT->footer();
?>