MDL-11082 Improved groups upgrade performance 1.8x -> 1.9; thanks Eloy for telling...
[moodle-pu.git] / mod / data / index.php
blobd069bc2001fe3dc756f47fffdf16e5abe3b2dd36
1 <?php // $Id$
2 ///////////////////////////////////////////////////////////////////////////
3 // //
4 // NOTICE OF COPYRIGHT //
5 // //
6 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
7 // http://moodle.org //
8 // //
9 // Copyright (C) 1990-onwards Moodle Pty Ltd http://moodle.com //
10 // //
11 // This program is free software; you can redistribute it and/or modify //
12 // it under the terms of the GNU General Public License as published by //
13 // the Free Software Foundation; either version 2 of the License, or //
14 // (at your option) any later version. //
15 // //
16 // This program is distributed in the hope that it will be useful, //
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
19 // GNU General Public License for more details: //
20 // //
21 // http://www.gnu.org/copyleft/gpl.html //
22 // //
23 ///////////////////////////////////////////////////////////////////////////
25 require_once("../../config.php");
26 require_once("lib.php");
28 $id = required_param('id', PARAM_INT); // course
30 if (! $course = get_record("course", "id", $id)) {
31 error("Course ID is incorrect");
34 require_course_login($course);
36 $context = get_context_instance(CONTEXT_COURSE, $course->id);
38 add_to_log($course->id, "data", "view all", "index.php?id=$course->id", "");
40 $strweek = get_string('week');
41 $strtopic = get_string('topic');
42 $strname = get_string('name');
43 $strdata = get_string('modulename','data');
45 $navlinks = array();
46 $navlinks[] = array('name' => $strdata, 'link' => "index.php?id=$course->id", 'type' => 'activity');
47 $navigation = build_navigation($navlinks);
49 print_header_simple($strdata, '', $navigation, '', '', true, "", navmenu($course));
51 if (! $datas = get_all_instances_in_course("data", $course)) {
52 notice("There are no databases", "$CFG->wwwroot/course/view.php?id=$course->id");
55 $timenow = time();
56 $strname = get_string('name');
57 $strweek = get_string('week');
58 $strtopic = get_string('topic');
59 $strdescription = get_string("description");
60 $strentries = get_string('entries', 'data');
61 $strnumnotapproved = get_string('numnotapproved', 'data');
63 if ($course->format == 'weeks') {
64 $table->head = array ($strweek, $strname, $strdescription, $strentries, $strnumnotapproved);
65 $table->align = array ('center', 'center', 'center', 'center', 'center');
66 } else if ($course->format == 'topics') {
67 $table->head = array ($strtopic, $strname, $strdescription, $strentries, $strnumnotapproved);
68 $table->align = array ('center', 'center', 'center', 'center', 'center');
69 } else {
70 $table->head = array ($strname, $strdescription, $strentries, $strnumnotapproved);
71 $table->align = array ('center', 'center', 'center', 'center');
74 $rss = (!empty($CFG->enablerssfeeds) && !empty($CFG->data_enablerssfeeds));
76 if ($rss) {
77 require_once($CFG->libdir."/rsslib.php");
78 array_push($table->head, 'RSS');
79 array_push($table->align, 'center');
82 $currentsection = "";
84 foreach ($datas as $data) {
86 $printsection = "";
88 //Calculate the href
89 if (!$data->visible) {
90 //Show dimmed if the mod is hidden
91 $link = "<a class=\"dimmed\" href=\"view.php?id=$data->coursemodule\">".format_string($data->name,true)."</a>";
92 } else {
93 //Show normal if the mod is visible
94 $link = "<a href=\"view.php?id=$data->coursemodule\">".format_string($data->name,true)."</a>";
97 $numrecords = count_records_sql('SELECT COUNT(r.id) FROM '.$CFG->prefix.
98 'data_records r WHERE r.dataid ='.$data->id);
100 if ($data->approval == 1) {
101 $numunapprovedrecords = count_records_sql('SELECT COUNT(r.id) FROM '.$CFG->prefix.
102 'data_records r WHERE r.dataid ='.$data->id.
103 ' AND r.approved <> 1');
104 } else {
105 $numunapprovedrecords = '-';
108 $rsslink = '';
109 if ($rss && $data->rssarticles > 0) {
110 $rsslink = rss_get_link($course->id, $USER->id, 'data', $data->id, 'RSS');
113 if ($course->format == 'weeks' or $course->format == 'topics') {
114 if ($data->section !== $currentsection) {
115 if ($data->section) {
116 $printsection = $data->section;
118 if ($currentsection !== '') {
119 $table->data[] = 'hr';
121 $currentsection = $data->section;
123 $row = array ($printsection, $link, $data->intro, $numrecords, $numunapprovedrecords);
125 } else {
126 $row = array ($link, $data->intro, $numrecords, $numunapprovedrecords);
129 if ($rss) {
130 array_push($row, $rsslink);
133 $table->data[] = $row;
136 echo "<br />";
137 print_table($table);
138 print_footer($course);