eb588b22 |
1 | <?php |
1515a89e |
2 | |
eb588b22 |
3 | require_once('../../config.php'); |
4 | require_once('lib.php'); |
1515a89e |
5 | |
eb588b22 |
6 | $id = required_param('id', PARAM_INT); // course |
1515a89e |
7 | |
a6855934 |
8 | $PAGE->set_url('/mod/chat/index.php', array('id'=>$id)); |
eb588b22 |
9 | |
10 | if (! $course = $DB->get_record('course', array('id'=>$id))) { |
11 | print_error('invalidcourseid'); |
12 | } |
1515a89e |
13 | |
eb588b22 |
14 | require_course_login($course); |
191b267b |
15 | $PAGE->set_pagelayout('incourse'); |
1515a89e |
16 | |
eb588b22 |
17 | add_to_log($course->id, 'chat', 'view all', "index.php?id=$course->id", ''); |
1515a89e |
18 | |
19 | |
20 | /// Get all required strings |
21 | |
eb588b22 |
22 | $strchats = get_string('modulenameplural', 'chat'); |
23 | $strchat = get_string('modulename', 'chat'); |
1515a89e |
24 | |
25 | |
26 | /// Print the header |
eb588b22 |
27 | $PAGE->navbar->add($strchats); |
28 | $PAGE->set_title($strchats); |
29 | echo $OUTPUT->header(); |
1515a89e |
30 | |
31 | /// Get all the appropriate data |
32 | |
eb588b22 |
33 | if (! $chats = get_all_instances_in_course('chat', $course)) { |
34 | notice(get_string('thereareno', 'moodle', $strchats), "../../course/view.php?id=$course->id"); |
35 | die(); |
36 | } |
1515a89e |
37 | |
38 | /// Print the list of instances (your module will probably extend this) |
39 | |
eb588b22 |
40 | $timenow = time(); |
41 | $strname = get_string('name'); |
42 | $strweek = get_string('week'); |
43 | $strtopic = get_string('topic'); |
44 | |
45 | $table = new html_table(); |
46 | |
47 | if ($course->format == 'weeks') { |
48 | $table->head = array ($strweek, $strname); |
49 | $table->align = array ('center', 'left'); |
50 | } else if ($course->format == 'topics') { |
51 | $table->head = array ($strtopic, $strname); |
52 | $table->align = array ('center', 'left', 'left', 'left'); |
53 | } else { |
54 | $table->head = array ($strname); |
55 | $table->align = array ('left', 'left', 'left'); |
56 | } |
57 | |
58 | $currentsection = ''; |
59 | foreach ($chats as $chat) { |
60 | if (!$chat->visible) { |
61 | //Show dimmed if the mod is hidden |
62 | $link = "<a class=\"dimmed\" href=\"view.php?id=$chat->coursemodule\">".format_string($chat->name,true)."</a>"; |
1515a89e |
63 | } else { |
eb588b22 |
64 | //Show normal if the mod is visible |
65 | $link = "<a href=\"view.php?id=$chat->coursemodule\">".format_string($chat->name,true)."</a>"; |
1515a89e |
66 | } |
eb588b22 |
67 | $printsection = ''; |
68 | if ($chat->section !== $currentsection) { |
69 | if ($chat->section) { |
70 | $printsection = $chat->section; |
93285301 |
71 | } |
eb588b22 |
72 | if ($currentsection !== '') { |
73 | $table->data[] = 'hr'; |
1515a89e |
74 | } |
eb588b22 |
75 | $currentsection = $chat->section; |
76 | } |
77 | if ($course->format == 'weeks' or $course->format == 'topics') { |
78 | $table->data[] = array ($printsection, $link); |
79 | } else { |
80 | $table->data[] = array ($link); |
1515a89e |
81 | } |
eb588b22 |
82 | } |
1515a89e |
83 | |
eb588b22 |
84 | echo '<br />'; |
1515a89e |
85 | |
16be8974 |
86 | echo html_writer::table($table); |
1515a89e |
87 | |
88 | /// Finish the page |
89 | |
eb588b22 |
90 | echo $OUTPUT->footer(); |
1515a89e |
91 | |
e7521559 |
92 | |