Merge branch 'wip-MDL-41102-m25' of git://github.com/marinaglancy/moodle into MOODLE_...
[moodle.git] / mod / chat / index.php
blob22582dafbdc994b9822c89a51c7a0d79a2572138
1 <?php
3 require_once('../../config.php');
4 require_once('lib.php');
6 $id = required_param('id', PARAM_INT); // course
8 $PAGE->set_url('/mod/chat/index.php', array('id'=>$id));
10 if (! $course = $DB->get_record('course', array('id'=>$id))) {
11 print_error('invalidcourseid');
14 require_course_login($course);
15 $PAGE->set_pagelayout('incourse');
17 add_to_log($course->id, 'chat', 'view all', "index.php?id=$course->id", '');
20 /// Get all required strings
22 $strchats = get_string('modulenameplural', 'chat');
23 $strchat = get_string('modulename', 'chat');
26 /// Print the header
27 $PAGE->navbar->add($strchats);
28 $PAGE->set_title($strchats);
29 $PAGE->set_heading($course->fullname);
30 echo $OUTPUT->header();
32 /// Get all the appropriate data
34 if (! $chats = get_all_instances_in_course('chat', $course)) {
35 notice(get_string('thereareno', 'moodle', $strchats), "../../course/view.php?id=$course->id");
36 die();
39 $usesections = course_format_uses_sections($course->format);
41 /// Print the list of instances (your module will probably extend this)
43 $timenow = time();
44 $strname = get_string('name');
46 $table = new html_table();
48 if ($usesections) {
49 $strsectionname = get_string('sectionname', 'format_'.$course->format);
50 $table->head = array ($strsectionname, $strname);
51 $table->align = array ('center', 'left');
52 } else {
53 $table->head = array ($strname);
54 $table->align = array ('left');
57 $currentsection = '';
58 foreach ($chats as $chat) {
59 if (!$chat->visible) {
60 //Show dimmed if the mod is hidden
61 $link = "<a class=\"dimmed\" href=\"view.php?id=$chat->coursemodule\">".format_string($chat->name,true)."</a>";
62 } else {
63 //Show normal if the mod is visible
64 $link = "<a href=\"view.php?id=$chat->coursemodule\">".format_string($chat->name,true)."</a>";
66 $printsection = '';
67 if ($chat->section !== $currentsection) {
68 if ($chat->section) {
69 $printsection = get_section_name($course, $chat->section);
71 if ($currentsection !== '') {
72 $table->data[] = 'hr';
74 $currentsection = $chat->section;
76 if ($usesections) {
77 $table->data[] = array ($printsection, $link);
78 } else {
79 $table->data[] = array ($link);
83 echo '<br />';
85 echo html_writer::table($table);
87 /// Finish the page
89 echo $OUTPUT->footer();