NOBUG: fixed whitespace
[moodle.git] / mod / chat / index.php
CommitLineData
eb588b22 1<?php
1515a89e 2
eb588b22 3require_once('../../config.php');
4require_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
10if (! $course = $DB->get_record('course', array('id'=>$id))) {
11 print_error('invalidcourseid');
12}
1515a89e 13
eb588b22 14require_course_login($course);
191b267b 15$PAGE->set_pagelayout('incourse');
1515a89e 16
eb588b22 17add_to_log($course->id, 'chat', 'view all', "index.php?id=$course->id", '');
1515a89e 18
19
20/// Get all required strings
21
7487c856 22$strsectionname = get_string('sectionname', 'format_'.$course->format);
eb588b22 23$strchats = get_string('modulenameplural', 'chat');
24$strchat = get_string('modulename', 'chat');
1515a89e 25
26
27/// Print the header
eb588b22 28$PAGE->navbar->add($strchats);
29$PAGE->set_title($strchats);
a9ce6b1f 30$PAGE->set_heading($course->fullname);
eb588b22 31echo $OUTPUT->header();
3eb032d7 32echo $OUTPUT->heading($strchats, 2);
1515a89e 33
34/// Get all the appropriate data
35
eb588b22 36if (! $chats = get_all_instances_in_course('chat', $course)) {
37 notice(get_string('thereareno', 'moodle', $strchats), "../../course/view.php?id=$course->id");
38 die();
39}
1515a89e 40
7487c856 41$usesections = course_format_uses_sections($course->format);
7487c856 42
1515a89e 43/// Print the list of instances (your module will probably extend this)
44
eb588b22 45$timenow = time();
46$strname = get_string('name');
eb588b22 47
48$table = new html_table();
49
7487c856
SH
50if ($usesections) {
51 $table->head = array ($strsectionname, $strname);
eb588b22 52 $table->align = array ('center', 'left');
eb588b22 53} else {
54 $table->head = array ($strname);
7487c856 55 $table->align = array ('left');
eb588b22 56}
57
58$currentsection = '';
59foreach ($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) {
71a56e08 70 $printsection = get_section_name($course, $chat->section);
93285301 71 }
eb588b22 72 if ($currentsection !== '') {
73 $table->data[] = 'hr';
1515a89e 74 }
eb588b22 75 $currentsection = $chat->section;
76 }
e9f80dff 77 if ($usesections) {
eb588b22 78 $table->data[] = array ($printsection, $link);
79 } else {
80 $table->data[] = array ($link);
1515a89e 81 }
eb588b22 82}
1515a89e 83
eb588b22 84echo '<br />';
1515a89e 85
16be8974 86echo html_writer::table($table);
1515a89e 87
88/// Finish the page
89
eb588b22 90echo $OUTPUT->footer();
1515a89e 91
e7521559 92