forked from mdjnelson/moodle-mod_certificate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
104 lines (85 loc) · 3.33 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
<?PHP // $Id: index.php
/// This page lists all the instances of certificate in a particular course
require_once('../../config.php');
require_once('lib.php');
global $DB;
$id = required_param('id', PARAM_INT); // Course Module ID
if (! $course = $DB->get_record('course', array('id'=> $id))) {
print_error('Course ID is incorrect');
}
require_course_login($course);
$PAGE->set_pagelayout('incourse');
add_to_log($course->id, 'certificate', 'view all', 'index.php?id='.$course->id, '');
/// Get all required strings
$strcertificates = get_string('modulenameplural', 'certificate');
$strcertificate = get_string('modulename', 'certificate');
/// Print the header
$PAGE->set_url('/mod/certificate/index.php', array('id'=>$course->id));
$PAGE->navbar->add($strcertificates);
$PAGE->set_title($strcertificates);
$PAGE->set_heading($course->fullname);
echo $OUTPUT->header();
/// Get all the appropriate data
if (! $certificates = get_all_instances_in_course('certificate', $course)) {
notice('There are no certificates', "../../course/view.php?id=$course->id");
die;
}
$usesections = course_format_uses_sections($course->format);
if ($usesections) {
$sections = get_all_sections($course->id);
}
/// Print the list of instances
$timenow = time();
$strname = get_string("name");
$strsectionname = get_string('sectionname', 'format_'.$course->format);
$strissued = get_string('issued', 'certificate');
$table = new html_table();
if ($usesections) {
$table->head = array ($strsectionname, $strname, $strissued);
} else {
$table->head = array ($strname, $strissued);
}
$currentsection = "";
foreach ($certificates as $certificate) {
if (!$certificate->visible) {
//Show dimmed if the mod is hidden
$link = "<a class=\"dimmed\" href=\"view.php?id=$certificate->coursemodule\">$certificate->name</a>";
} else {
//Show normal if the mod is visible
$link = "<a href=\"view.php?id=$certificate->coursemodule\">$certificate->name</a>";
}
$printsection = "";
if ($certificate->section !== $currentsection) {
if ($certificate->section) {
$printsection = $certificate->section;
}
if ($currentsection !== "") {
$table->data[] = 'hr';
}
$currentsection = $certificate->section;
}
$sql = 'SELECT MAX(timecreated) AS latest FROM {certificate_issues} '.
'WHERE userid = '.$USER->id.' and certificateid = '.$certificate->id.'';
if ($record = $DB->get_record_sql($sql)) {
$latest = $record->latest;
}
$certrecord = $DB->get_record('certificate_issues', array('certificateid'=>$certificate->id, 'userid'=>$USER->id, 'timecreated'=>$latest));
if($certrecord) {
if($certrecord->certdate > 0) {
$issued = userdate($certrecord->certdate);
} else {
$issued = get_string('notreceived', 'certificate');
}
} else {
$issued = get_string('notreceived', 'certificate');
}
if ($course->format == 'weeks' or $course->format == 'topics') {
$table->data[] = array ($certificate->section, $link, $issued);
} else {
$table->data[] = array ($link, $issued);
}
}
echo '<br />';
echo html_writer::table($table);
/// Finish the page
echo $OUTPUT->footer();