forked from mudrd8mz/moodle-mod_stampcoll
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
110 lines (91 loc) · 3.79 KB
/
index.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
<?php // $Id$
require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
require_once(dirname(__FILE__).'/lib.php');
$id = required_param('id', PARAM_INT); // course
if (! $course = get_record('course', 'id', $id)) {
error('Course ID is incorrect');
}
require_course_login($course);
add_to_log($course->id, 'stampcoll', 'view all', 'index.php?id=$course->id', '');
$strstamps = get_string('modulenameplural', 'stampcoll');
$navigation = build_navigation($strstamps);
print_header_simple($strstamps, '',
$navigation, '', '', true, '', navmenu($course));
if (! $stampcolls = get_all_instances_in_course('stampcoll', $course)) {
notice('There are no stamp collections', '../../course/view.php?id='.$course->id);
}
if ($course->format == 'weeks') {
$table->head = array (get_string('week'), get_string('name'), get_string('numberofstamps', 'stampcoll'));
$table->align = array ('center', 'left', 'center');
} else if ($course->format == 'topics') {
$table->head = array (get_string('topic'), get_string('name'), get_string('numberofstamps', 'stampcoll'));
$table->align = array ('center', 'left', 'center');
} else {
$table->head = array (get_string('name'), get_string('numberofstamps', 'stampcoll') );
$table->align = array ('left', 'left');
}
$currentsection = '';
foreach ($stampcolls as $stampcoll) {
if (! $cm = get_coursemodule_from_instance('stampcoll', $stampcoll->id)) {
error('Course Module ID was incorrect');
}
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
include(dirname(__FILE__).'/caps.php');
if (! $cap_viewsomestamps) {
$count_mystamps = get_string('notallowedtoviewstamps', 'stampcoll');
} else {
if (! $allstamps = stampcoll_get_stamps($stampcoll->id)) {
$allstamps = array();
}
$count_totalstamps = count($allstamps);
$count_mystamps = 0;
foreach ($allstamps as $s) {
if ($s->userid == $USER->id) {
$count_mystamps++;
}
}
unset($allstamps);
unset($s);
}
$printsection = '';
if ($stampcoll->section !== $currentsection) {
if ($stampcoll->section) {
$printsection = $stampcoll->section;
}
if ($currentsection !== '') {
$table->data[] = 'hr';
}
$currentsection = $stampcoll->section;
}
//Calculate the href
if (!$stampcoll->visible) {
//Show dimmed if the mod is hidden
$tt_href = '<a class="dimmed" href="view.php?id='.$stampcoll->coursemodule.'">';
$tt_href .= format_string($stampcoll->name, true);
$tt_href .= '</a>';
} else {
//Show normal if the mod is visible
$tt_href = '<a href="view.php?id='.$stampcoll->coursemodule.'">';
$tt_href .= format_string($stampcoll->name, true);
$tt_href .= '</a>';
}
if (! $cap_viewsomestamps) {
$aa = get_string('notallowedtoviewstamps', 'stampcoll');
} else {
$aa = '';
if ($cap_viewownstamps) {
$aa .= $count_mystamps;
}
if ($cap_viewotherstamps) {
$aa .= ' ('. ($count_totalstamps - $count_mystamps) .')';
}
}
if ($course->format == 'weeks' || $course->format == 'topics') {
$table->data[] = array ($printsection, $tt_href, $aa);
} else {
$table->data[] = array ($tt_href, $aa);
}
}
print_table($table);
print_footer($course);
?>