MDL-13440 fixed typo; merging from 1.9
[moodle.git] / mod / data / view.php
CommitLineData
3d4b223a 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) 2005 Martin Dougiamas http://dougiamas.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///////////////////////////////////////////////////////////////////////////
24
25 require_once('../../config.php');
26 require_once('lib.php');
27 require_once($CFG->libdir.'/blocklib.php');
a593aeee 28 require_once("$CFG->libdir/rsslib.php");
3d4b223a 29
3d4b223a 30 require_once('pagelib.php');
9f7f1a74 31
3d45b8e5 32/// One of these is necessary!
3d4b223a 33 $id = optional_param('id', 0, PARAM_INT); // course module id
34 $d = optional_param('d', 0, PARAM_INT); // database id
3d45b8e5 35 $rid = optional_param('rid', 0, PARAM_INT); //record id
36
37 $mode = optional_param('mode', '', PARAM_ALPHA); // Force the browse mode ('single')
38
d2b23346 39 $edit = optional_param('edit', -1, PARAM_BOOL);
7900ecb0 40 $page = optional_param('page', 0, PARAM_INT);
3d45b8e5 41/// These can be added to perform an action on a record
473dd288 42 $approve = optional_param('approve', 0, PARAM_INT); //approval recordid
43 $delete = optional_param('delete', 0, PARAM_INT); //delete recordid
aab98aaf 44
3d4b223a 45 if ($id) {
f9d5371b 46 if (! $cm = get_coursemodule_from_id('data', $id)) {
3d4b223a 47 error('Course Module ID was incorrect');
48 }
49 if (! $course = get_record('course', 'id', $cm->course)) {
50 error('Course is misconfigured');
51 }
52 if (! $data = get_record('data', 'id', $cm->instance)) {
53 error('Course module is incorrect');
54 }
3d45b8e5 55 $record = NULL;
3d4b223a 56
3d45b8e5 57 } else if ($rid) {
58 if (! $record = get_record('data_records', 'id', $rid)) {
59 error('Record ID is incorrect');
60 }
61 if (! $data = get_record('data', 'id', $record->dataid)) {
62 error('Data ID is incorrect');
63 }
64 if (! $course = get_record('course', 'id', $data->course)) {
65 error('Course is misconfigured');
66 }
67 if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) {
68 error('Course Module ID was incorrect');
69 }
70 } else { // We must have $d
3d4b223a 71 if (! $data = get_record('data', 'id', $d)) {
72 error('Data ID is incorrect');
73 }
74 if (! $course = get_record('course', 'id', $data->course)) {
75 error('Course is misconfigured');
76 }
77 if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) {
78 error('Course Module ID was incorrect');
79 }
3d45b8e5 80 $record = NULL;
3d4b223a 81 }
82
7ddda9db 83 require_course_login($course, true, $cm);
aab98aaf 84
dabfd0ed 85 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
20821a12 86 require_capability('mod/data:viewentry', $context);
3d1c33ef 87
3d45b8e5 88/// If we have an empty Database then redirect because this page is useless without data
0468976c 89 if (has_capability('mod/data:managetemplates', $context)) {
ed69c723 90 if (!record_exists('data_fields','dataid',$data->id)) { // Brand new database!
5bac6d10 91 redirect($CFG->wwwroot.'/mod/data/field.php?d='.$data->id); // Redirect to field entry
3d4b223a 92 }
93 }
e0279f63 94
3d45b8e5 95
96/// Check further parameters that set browsing preferences
97 if (!isset($SESSION->dataprefs)) {
98 $SESSION->dataprefs = array();
e0279f63 99 }
3d45b8e5 100 if (!isset($SESSION->dataprefs[$data->id])) {
101 $SESSION->dataprefs[$data->id] = array();
102 $SESSION->dataprefs[$data->id]['search'] = '';
7900ecb0 103 $SESSION->dataprefs[$data->id]['search_array'] = array();
3d45b8e5 104 $SESSION->dataprefs[$data->id]['sort'] = $data->defaultsort;
7900ecb0 105 $SESSION->dataprefs[$data->id]['advanced'] = 0;
3d45b8e5 106 $SESSION->dataprefs[$data->id]['order'] = ($data->defaultsortdir == 0) ? 'ASC' : 'DESC';
3d4b223a 107 }
7900ecb0 108 $advanced = optional_param('advanced', $SESSION->dataprefs[$data->id]['advanced'], PARAM_INT);
109 $search_array = $SESSION->dataprefs[$data->id]['search_array'];
110
111 if (!empty($advanced)) {
112 $search = '';
113 $fields = get_records('data_fields', 'dataid', $data->id);
114
115 //Added to ammend paging error. This error would occur when attempting to go from one page of advanced
116 //search results to another. All fields were reset in the page transfer, and there was no way of determining
117 //whether or not the user reset them. This would cause a blank search to execute whenever the user attempted
118 //to see any page of results past the first.
119 //This fix works as follows:
120 //$paging flag is set to false when page 0 of the advanced search results is viewed for the first time.
121 //Viewing any page of results after page 0 passes the false $paging flag though the URL (see line 523) and the
122 //execution falls through to the second condition below, allowing paging to be set to true.
123 //Paging remains true and keeps getting passed though the URL until a new search is performed
124 //(even if page 0 is revisited).
125 //A false $paging flag generates advanced search results based on the fields input by the user.
126 //A true $paging flag generates davanced search results from the $SESSION global.
127 //(See lines 147-158)
128
129 $paging = optional_param('paging', NULL, PARAM_BOOL);
130 if($page == 0 && !isset($paging)) {
131 $paging = false;
132 }
133 else {
134 $paging = true;
135 }
136 if (!empty($fields)) {
137 foreach($fields as $field) {
138 $searchfield = data_get_field_from_id($field->id, $data);
139 //Get field data to build search sql with. If paging is false, get from user.
140 //If paging is true, get data from $search_array which is obtained from the $SESSION (see line 116).
141 if(!$paging) {
142 $val = $searchfield->parse_search_field();
143 }
144 else {
145 //Set value from session if there is a value @ the required index.
146 if(isset($search_array[$field->id])) {
147 $val = $search_array[$field->id]->data;
148 }
149 else { //If there is not an entry @ the required index, set value to blank.
150 $val = '';
151 }
152 }
153 if (!empty($val)) {
154 $search_array[$field->id] = new stdClass;
155 $search_array[$field->id]->sql = $searchfield->generate_sql('c'.$field->id, $val);
156 $search_array[$field->id]->data = $val;
157 $search .= ' '.$val;
158 }
159 else {
160 if (isset($search_array[$field->id])) {
161 // clear it out
162 unset($search_array[$field->id]);
163 }
164 }
165 }
166 }
167 $SESSION->dataprefs[$data->id]['search_array'] = $search_array; // Make it sticky
168 }
169 else {
170 $search = optional_param('search', $SESSION->dataprefs[$data->id]['search'], PARAM_NOTAGS);
171 //Paging variable not used for standard search. Set it to null.
172 $paging = NULL;
173 }
174
8e1ec6be 175 $textlib = textlib_get_instance();
76a2fd82 176 if ($textlib->strlen($search) < 2) {
177 $search = '';
178 }
3d45b8e5 179 $SESSION->dataprefs[$data->id]['search'] = $search; // Make it sticky
180
181 $sort = optional_param('sort', $SESSION->dataprefs[$data->id]['sort'], PARAM_INT);
182 $SESSION->dataprefs[$data->id]['sort'] = $sort; // Make it sticky
183
184 $order = (optional_param('order', $SESSION->dataprefs[$data->id]['order'], PARAM_ALPHA) == 'ASC') ? 'ASC': 'DESC';
185 $SESSION->dataprefs[$data->id]['order'] = $order; // Make it sticky
186
187
188 $oldperpage = get_user_preferences('data_perpage_'.$data->id, 10);
189 $perpage = optional_param('perpage', $oldperpage, PARAM_INT);
190
191 if ($perpage < 2) {
192 $perpage = 2;
193 }
194 if ($perpage != $oldperpage) {
195 set_user_preference('data_perpage_'.$data->id, $perpage);
196 }
197
3d4b223a 198 add_to_log($course->id, 'data', 'view', "view.php?id=$cm->id", $data->id, $cm->id);
199
200
201// Initialize $PAGE, compute blocks
202 $PAGE = page_create_instance($data->id);
203 $pageblocks = blocks_setup($PAGE);
204 $blocks_preferred_width = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), 210);
205
d2b23346 206 if (($edit != -1) and $PAGE->user_allowed_editing()) {
207 $USER->editing = $edit;
3d4b223a 208 }
3d4b223a 209
b0100852 210/// RSS and CSS and JS meta
68635e6f 211 $meta = '';
64452eb4 212 if (!empty($CFG->enablerssfeeds) && !empty($CFG->data_enablerssfeeds) && $data->rssarticles > 0) {
c853304e 213 $rsspath = rss_get_url($course->id, $USER->id, 'data', $data->id);
68635e6f 214 $meta .= '<link rel="alternate" type="application/rss+xml" ';
6ba65fa0 215 $meta .= 'title ="'. format_string($course->shortname) .': %fullname%" href="'.$rsspath.'" />';
68635e6f 216 }
217 if ($data->csstemplate) {
218 $meta .= '<link rel="stylesheet" type="text/css" href="'.$CFG->wwwroot.'/mod/data/css.php?d='.$data->id.'" /> ';
c853304e 219 }
b0100852 220 if ($data->jstemplate) {
221 $meta .= '<script type="text/javascript" src="'.$CFG->wwwroot.'/mod/data/js.php?d='.$data->id.'"></script>';
222 }
223
aab98aaf 224
c853304e 225/// Print the page header
68635e6f 226 $PAGE->print_header($course->shortname.': %fullname%', '', $meta);
aab98aaf 227
3d4b223a 228
236d839f 229/// If we have blocks, then print the left side here
230 if (!empty($CFG->showblocksonmodpages)) {
231 echo '<table id="layout-table"><tr>';
232 if ((blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $PAGE->user_is_editing())) {
233 echo '<td style="width: '.$blocks_preferred_width.'px;" id="left-column">';
9f7f1a74 234 print_container_start();
236d839f 235 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
9f7f1a74 236 print_container_end();
236d839f 237 echo '</td>';
238 }
239 echo '<td id="middle-column">';
9f7f1a74 240 print_container_start();
3d4b223a 241 }
242
3b27b0fe 243/// Check to see if groups are being used here
13534ef7
ML
244 $returnurl = 'view.php?d='.$data->id.'&amp;search='.s($search).'&amp;sort='.s($sort).'&amp;order='.s($order).'&amp;';
245 groups_print_activity_menu($cm, $returnurl);
246 $currentgroup = groups_get_activity_group($cm);
247 $groupmode = groups_get_activity_groupmode($cm);
3b27b0fe 248
3d4b223a 249 print_heading(format_string($data->name));
aab98aaf 250
a593aeee 251 // Do we need to show a link to the RSS feed for the records?
64452eb4 252 if (!empty($CFG->enablerssfeeds) && !empty($CFG->data_enablerssfeeds) && $data->rssarticles > 0) {
a593aeee 253 echo '<div style="float:right;">';
ed69c723 254 rss_print_link($course->id, $USER->id, 'data', $data->id, get_string('rsstype'));
a593aeee 255 echo '</div>';
256 echo '<div style="clear:both;"></div>';
257 }
aab98aaf 258
9e08cf6e 259 if ($data->intro and empty($page) and empty($record) and $mode != 'single') {
c1afef80 260 print_box(format_text($data->intro), 'generalbox', 'intro');
56135f6b 261 }
262
473dd288 263/// Delete any requested records
264
0468976c 265 if ($delete && confirm_sesskey() && (has_capability('mod/data:manageentries', $context) or data_isowner($delete))) {
3d45b8e5 266 if ($confirm = optional_param('confirm',0,PARAM_INT)) {
267 if ($deleterecord = get_record('data_records', 'id', $delete)) { // Need to check this is valid
268 if ($deleterecord->dataid == $data->id) { // Must be from this database
269 if ($contents = get_records('data_content','recordid', $deleterecord->id)) {
270 foreach ($contents as $content) { // Delete files or whatever else this field allows
271 if ($field = data_get_field_from_id($content->fieldid, $data)) { // Might not be there
272 $field->delete_content($content->recordid);
273 }
3d4b223a 274 }
275 }
3d45b8e5 276 delete_records('data_content','recordid', $deleterecord->id);
277 delete_records('data_records','id', $deleterecord->id);
f0497d6f 278
3d45b8e5 279 add_to_log($course->id, 'data', 'record delete', "view.php?id=$cm->id", $data->id, $cm->id);
f0497d6f 280
3d45b8e5 281 notify(get_string('recorddeleted','data'), 'notifysuccess');
282 }
3d4b223a 283 }
3d45b8e5 284
285 } else { // Print a confirmation page
64452eb4 286 if ($deleterecord = get_record('data_records', 'id', $delete)) { // Need to check this is valid
287 if ($deleterecord->dataid == $data->id) { // Must be from this database
aab98aaf 288 notice_yesno(get_string('confirmdeleterecord','data'),
64452eb4 289 'view.php?d='.$data->id.'&amp;delete='.$delete.'&amp;confirm=1&amp;sesskey='.sesskey(),
290 'view.php?d='.$data->id);
3d45b8e5 291
64452eb4 292 $records[] = $deleterecord;
3f9672d3 293 echo data_print_template('singletemplate', $records, $data, '', 0, true);
64452eb4 294
295 print_footer($course);
296 exit;
297 }
298 }
299 }
300 }
301
302
303
304/// Print the tabs
305
306 if ($record or $mode == 'single') {
307 $currenttab = 'single';
7900ecb0 308 } elseif($mode == 'asearch') {
309 $currenttab = 'asearch';
310 }
311 else {
64452eb4 312 $currenttab = 'list';
313 }
aab98aaf 314 include('tabs.php');
64452eb4 315
7900ecb0 316 if ($mode != 'asearch') {
317 /// Approve any requested records
64452eb4 318
7900ecb0 319 if ($approve && confirm_sesskey() && has_capability('mod/data:approve', $context)) {
320 if ($approverecord = get_record('data_records', 'id', $approve)) { // Need to check this is valid
321 if ($approverecord->dataid == $data->id) { // Must be from this database
322 $newrecord->id = $approverecord->id;
323 $newrecord->approved = 1;
324 if (update_record('data_records', $newrecord)) {
325 notify(get_string('recordapproved','data'), 'notifysuccess');
326 }
64452eb4 327 }
328 }
3d4b223a 329 }
3d4b223a 330
7900ecb0 331 // If not teacher, check whether user has sufficient records to view
332 if (!has_capability('mod/data:managetemplates', $context) and data_numentries($data) < $data->requiredentriestoview){
333 notify (($data->requiredentriestoview - data_numentries($data)).'&nbsp;'.get_string('insufficiententries','data'));
334 echo '</td></tr></table>';
335 print_footer($course);
336 exit;
337 }
3d4b223a 338
3d4b223a 339
7900ecb0 340 /// We need to examine the whole dataset to produce the correct paging
33819735 341
7900ecb0 342 if ((!has_capability('mod/data:managetemplates', $context)) && ($data->approval)) {
343 if (isloggedin()) {
344 $approveselect = ' AND (r.approved=1 OR r.userid='.$USER->id.') ';
345 } else {
346 $approveselect = ' AND r.approved=1 ';
347 }
4431d2e0 348 } else {
7900ecb0 349 $approveselect = ' ';
4431d2e0 350 }
3d4b223a 351
7900ecb0 352 if ($currentgroup) {
353 $groupselect = " AND (r.groupid = '$currentgroup' OR r.groupid = 0)";
64452eb4 354 } else {
7900ecb0 355 $groupselect = ' ';
64452eb4 356 }
3d45b8e5 357
7900ecb0 358 /// Find the field we are sorting on
359 if ($sort and $sortfield = data_get_field_from_id($sort, $data)) {
360
361 $sortcontent = $sortfield->get_sort_field();
362 $sortcontentfull = $sortfield->get_sort_sql('c.'.$sortcontent);
363
b99b25ea 364 $what = ' DISTINCT r.id, r.approved, r.userid, u.firstname, u.lastname, c.'.$sortcontent.', '.$sortcontentfull.' AS _order ';
7900ecb0 365 $count = ' COUNT(DISTINCT c.recordid) ';
366 $tables = $CFG->prefix.'data_content c,'.$CFG->prefix.'data_records r,'.$CFG->prefix.'data_content c1, '.$CFG->prefix.'user u ';
367 $where = 'WHERE c.recordid = r.id
368 AND c.fieldid = '.$sort.'
369 AND r.dataid = '.$data->id.'
370 AND r.userid = u.id
371 AND c1.recordid = r.id ';
b99b25ea 372 $sortorder = ' ORDER BY _order '.$order.' , r.id ASC ';
7900ecb0 373 $searchselect = '';
374
375 if (!empty($advanced)) { //If advanced box is checked.
376 foreach($search_array as $key => $val) { //what does $search_array hold?
377 $tables .= ', '.$CFG->prefix.'data_content c'.$key.' ';
378 $where .= ' AND c'.$key.'.recordid = r.id';
379 $searchselect .= ' AND ('.$val->sql.') ';
380 }
381 }
382 elseif ($search) {
c8c765c0 383 $searchselect = ' AND (c1.content ' . sql_ilike() . " '%$search%') "; //Be case-insensitive
7900ecb0 384 } else {
385 $searchselect = ' ';
386 }
387 } else if ($search) {
388 $what = ' DISTINCT r.id, r.approved, r.userid, u.firstname, u.lastname ';
389 $count = ' COUNT(DISTINCT c.recordid) ';
390 $tables = $CFG->prefix.'data_content c,'.$CFG->prefix.'data_records r, '.$CFG->prefix.'user u ';
391 $where = 'WHERE c.recordid = r.id
392 AND r.userid = u.id
393 AND r.dataid = '.$data->id;
394 $sortorder = ' ORDER BY r.id ASC ';
395 $searchselect = '';
396
397 if (!empty($advanced)) { //Advanced search box again.
398 foreach($search_array as $key => $val) {
399 $tables .= ', '.$CFG->prefix.'data_content c'.$key.' ';
400 $where .= ' AND c'.$key.'.recordid = r.id ';
401 $searchselect .= ' AND ('.$val->sql.') ';
402 }
403 }
404 else {
c8c765c0 405 $searchselect = ' AND (c.content ' . sql_ilike() . " '%$search%') "; //Be case-insensitive
7900ecb0 406 }
3d45b8e5 407
7900ecb0 408
409 } else {
410 $what = ' DISTINCT r.id, r.approved, r.timecreated, r.userid, u.firstname, u.lastname ';
411 $count = ' COUNT(r.id) ';
412 $tables = $CFG->prefix.'data_records r, '.$CFG->prefix.'user u ';
413 $where = 'WHERE r.dataid = '.$data->id. ' AND r.userid = u.id ';
414 $sortorder = ' ORDER BY r.timecreated '.$order. ' ';
415 $searchselect = ' ';
416 }
3d4b223a 417
64452eb4 418
7900ecb0 419 /// To actually fetch the records
3d45b8e5 420
7900ecb0 421 $fromsql = ' FROM '.$tables.$where.$groupselect.$approveselect.$searchselect;
aab98aaf 422
7900ecb0 423 $sqlselect = 'SELECT '.$what.$fromsql.$sortorder;
3d45b8e5 424
7900ecb0 425 $sqlcount = 'SELECT '.$count.$fromsql; // Total number of records
3d45b8e5 426
7900ecb0 427 /// Work out the paging numbers
3d45b8e5 428
7900ecb0 429 $totalcount = count_records_sql($sqlcount);
3d4b223a 430
7900ecb0 431 if ($record) { // We need to just show one, so where is it in context?
432 $nowperpage = 1;
433 $mode = 'single';
de89899b 434
7900ecb0 435 # Following code needs testing to make it work
436 # if ($sort) { // We need to search by that field
437 # if ($content = get_field('data_content', 'content', 'recordid', $record->id, 'fieldid', $sort)) {
438 # $content = addslashes($content);
439 # if ($order == 'ASC') {
440 # $lessthan = " AND $sortcontentfull < '$content'
441 # OR ($sortcontentfull = '$content' AND r.id < '$record->id') ";
442 # } else {
443 # $lessthan = " AND $sortcontentfull > '$content'
444 # OR ($sortcontentfull = '$content' AND r.id < '$record->id') ";
445 # }
446 # } else { // Failed to find data (shouldn't happen), so fall back to something easy
447 # $lessthan = " r.id < '$record->id' ";
448 # }
449 # } else {
450 # $lessthan = " r.id < '$record->id' ";
451 # }
452 # $sqlindex = 'SELECT COUNT(DISTINCT c.recordid) '.$fromsql.$lessthan.$sortorder;
453 # $page = count_records_sql($sqlindex);
64452eb4 454
499ed215 455
7900ecb0 456 $allrecords = get_records_sql($sqlselect); // Kludgey but accurate at least!
457 $page = 0;
458 foreach ($allrecords as $key => $allrecord) {
459 if ($key == $record->id) {
460 break;
461 }
462 $page++;
3d45b8e5 463 }
3d45b8e5 464
7900ecb0 465 } else if ($mode == 'single') { // We rely on ambient $page settings
466 $nowperpage = 1;
3d45b8e5 467
7900ecb0 468 } else {
469 $nowperpage = $perpage;
470 }
3d45b8e5 471
7900ecb0 472 /// Get the actual records
473
474 $records = get_records_sql($sqlselect, $page * $nowperpage, $nowperpage);
3d45b8e5 475
7900ecb0 476 if (empty($records)) { // Nothing to show!
477 if ($record) { // Something was requested so try to show that at least (bug 5132)
478 if (has_capability('mod/data:manageentries', $context) || empty($data->approval) ||
479 $record->approved || (isloggedin() && $record->userid == $USER->id)) {
480 if (!$currentgroup || $record->groupid == $currentgroup || $record->groupid == 0) {
481 $records[] = $record;
482 }
3dec563c 483 }
484 }
7900ecb0 485 if ($records) { // OK, we can show this one
486 data_print_template('singletemplate', $records, $data, $search, $page);
487 } else if ($search){
488 notify(get_string('nomatch','data'));
489 } else {
490 notify(get_string('norecords','data'));
491 }
cf3e199b 492
7900ecb0 493 } else { // We have some records to print
68c88622 494
7900ecb0 495 if ($mode == 'single') { // Single template
496 $baseurl = 'view.php?d='.$data->id.'&amp;mode=single&amp;';
3d4b223a 497
7900ecb0 498 print_paging_bar($totalcount, $page, $nowperpage, $baseurl, $pagevar='page');
3d45b8e5 499
7900ecb0 500 if (empty($data->singletemplate)){
501 notify(get_string('nosingletemplate','data'));
502 data_generate_default_template($data, 'singletemplate', 0, false, false);
503 }
3d4b223a 504
7900ecb0 505 data_print_template('singletemplate', $records, $data, $search, $page);
3d45b8e5 506
7900ecb0 507 print_paging_bar($totalcount, $page, $nowperpage, $baseurl, $pagevar='page');
3d45b8e5 508
7900ecb0 509 } else { // List template
510 $baseurl = 'view.php?d='.$data->id.'&amp;';
511 //send the advanced flag through the URL so it is remembered while paging.
512 $baseurl .= 'advanced='.$advanced.'&amp;';
513 //pass variable to allow determining whether or not we are paging through results.
514 $baseurl .= 'paging='.$paging.'&amp;';
3d45b8e5 515
7900ecb0 516 print_paging_bar($totalcount, $page, $nowperpage, $baseurl, $pagevar='page');
3d45b8e5 517
7900ecb0 518 if (empty($data->listtemplate)){
519 notify(get_string('nolisttemplate','data'));
520 data_generate_default_template($data, 'listtemplate', 0, false, false);
521 }
522 echo $data->listtemplateheader;
523 data_print_template('listtemplate', $records, $data, $search, $page);
524 echo $data->listtemplatefooter;
525
526 print_paging_bar($totalcount, $page, $nowperpage, $baseurl, $pagevar='page');
3d45b8e5 527 }
3d45b8e5 528
3d45b8e5 529 }
7900ecb0 530 }
531
532 $search = trim($search);
533 if (empty($records)) {
534 $records = array();
f852d652 535 }
536
7900ecb0 537 //Advanced search form doesn't make sense for single (redirects list view)
450a87c5 538 if ($records || $search || $page || $mode == 'asearch' && $mode != 'single') {
7900ecb0 539 data_print_preference_form($data, $perpage, $search, $sort, $order, $search_array, $advanced, $mode);
64452eb4 540 }
3d4b223a 541
236d839f 542/// If we have blocks, then print the left side here
543 if (!empty($CFG->showblocksonmodpages)) {
9f7f1a74 544 print_container_end();
236d839f 545 echo '</td>'; // Middle column
546 if ((blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $PAGE->user_is_editing())) {
547 echo '<td style="width: '.$blocks_preferred_width.'px;" id="right-column">';
9f7f1a74 548 print_container_start();
236d839f 549 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
9f7f1a74 550 print_container_end();
236d839f 551 echo '</td>';
552 }
78e02af9 553 echo '</tr></table>';
236d839f 554 }
555
3d45b8e5 556 print_footer($course);
0997e51a 557?>