MDL-14129, fix incorrect print_error() call
[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)) {
5a2a5331 47 print_error('Course Module ID was incorrect');
3d4b223a 48 }
49 if (! $course = get_record('course', 'id', $cm->course)) {
5a2a5331 50 print_error('Course is misconfigured');
3d4b223a 51 }
52 if (! $data = get_record('data', 'id', $cm->instance)) {
5a2a5331 53 print_error('Course module is incorrect');
3d4b223a 54 }
3d45b8e5 55 $record = NULL;
3d4b223a 56
3d45b8e5 57 } else if ($rid) {
58 if (! $record = get_record('data_records', 'id', $rid)) {
5a2a5331 59 print_error('Record ID is incorrect');
3d45b8e5 60 }
61 if (! $data = get_record('data', 'id', $record->dataid)) {
5a2a5331 62 print_error('Data ID is incorrect');
3d45b8e5 63 }
64 if (! $course = get_record('course', 'id', $data->course)) {
5a2a5331 65 print_error('Course is misconfigured');
3d45b8e5 66 }
67 if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) {
5a2a5331 68 print_error('Course Module ID was incorrect');
3d45b8e5 69 }
70 } else { // We must have $d
3d4b223a 71 if (! $data = get_record('data', 'id', $d)) {
5a2a5331 72 print_error('Data ID is incorrect');
3d4b223a 73 }
74 if (! $course = get_record('course', 'id', $data->course)) {
5a2a5331 75 print_error('Course is misconfigured');
3d4b223a 76 }
77 if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) {
5a2a5331 78 print_error('Course Module ID was incorrect');
3d4b223a 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 }
87518137 330
331 // Check the number of entries required against the number of entries already made (doesn't apply to teachers)
332 $requiredentries_allowed = true;
333 $numentries = data_numentries($data);
334 if ($data->requiredentries > 0 && $numentries < $data->requiredentries && !has_capability('mod/data:manageentries', $context)) {
013a8774 335 $data->entriesleft = $data->requiredentries - $numentries;
336 $strentrieslefttoadd = get_string('entrieslefttoadd', 'data', $data);
87518137 337 notify($strentrieslefttoadd);
338 $requiredentries_allowed = false;
339 }
3d4b223a 340
7900ecb0 341 /// We need to examine the whole dataset to produce the correct paging
33819735 342
7900ecb0 343 if ((!has_capability('mod/data:managetemplates', $context)) && ($data->approval)) {
344 if (isloggedin()) {
345 $approveselect = ' AND (r.approved=1 OR r.userid='.$USER->id.') ';
346 } else {
347 $approveselect = ' AND r.approved=1 ';
348 }
4431d2e0 349 } else {
7900ecb0 350 $approveselect = ' ';
4431d2e0 351 }
3d4b223a 352
7900ecb0 353 if ($currentgroup) {
354 $groupselect = " AND (r.groupid = '$currentgroup' OR r.groupid = 0)";
64452eb4 355 } else {
7900ecb0 356 $groupselect = ' ';
64452eb4 357 }
3d45b8e5 358
7900ecb0 359 /// Find the field we are sorting on
360 if ($sort and $sortfield = data_get_field_from_id($sort, $data)) {
361
362 $sortcontent = $sortfield->get_sort_field();
363 $sortcontentfull = $sortfield->get_sort_sql('c.'.$sortcontent);
87518137 364
b99b25ea 365 $what = ' DISTINCT r.id, r.approved, r.userid, u.firstname, u.lastname, c.'.$sortcontent.', '.$sortcontentfull.' AS _order ';
7900ecb0 366 $count = ' COUNT(DISTINCT c.recordid) ';
367 $tables = $CFG->prefix.'data_content c,'.$CFG->prefix.'data_records r,'.$CFG->prefix.'data_content c1, '.$CFG->prefix.'user u ';
368 $where = 'WHERE c.recordid = r.id
369 AND c.fieldid = '.$sort.'
370 AND r.dataid = '.$data->id.'
371 AND r.userid = u.id
372 AND c1.recordid = r.id ';
b99b25ea 373 $sortorder = ' ORDER BY _order '.$order.' , r.id ASC ';
7900ecb0 374 $searchselect = '';
375
87518137 376 // If requiredentries is not reached, only show current user's entries
377 if (!$requiredentries_allowed) {
378 $where .= ' AND u.id = ' . $USER->id;
379 }
380
7900ecb0 381 if (!empty($advanced)) { //If advanced box is checked.
382 foreach($search_array as $key => $val) { //what does $search_array hold?
383 $tables .= ', '.$CFG->prefix.'data_content c'.$key.' ';
384 $where .= ' AND c'.$key.'.recordid = r.id';
385 $searchselect .= ' AND ('.$val->sql.') ';
386 }
387 }
388 elseif ($search) {
c8c765c0 389 $searchselect = ' AND (c1.content ' . sql_ilike() . " '%$search%') "; //Be case-insensitive
7900ecb0 390 } else {
391 $searchselect = ' ';
392 }
393 } else if ($search) {
394 $what = ' DISTINCT r.id, r.approved, r.userid, u.firstname, u.lastname ';
395 $count = ' COUNT(DISTINCT c.recordid) ';
396 $tables = $CFG->prefix.'data_content c,'.$CFG->prefix.'data_records r, '.$CFG->prefix.'user u ';
397 $where = 'WHERE c.recordid = r.id
398 AND r.userid = u.id
399 AND r.dataid = '.$data->id;
400 $sortorder = ' ORDER BY r.id ASC ';
401 $searchselect = '';
402
87518137 403 // If requiredentries is not reached, only show current user's entries
404 if (!$requiredentries_allowed) {
405 $where .= ' AND u.id = ' . $USER->id;
406 }
407
7900ecb0 408 if (!empty($advanced)) { //Advanced search box again.
409 foreach($search_array as $key => $val) {
410 $tables .= ', '.$CFG->prefix.'data_content c'.$key.' ';
411 $where .= ' AND c'.$key.'.recordid = r.id ';
412 $searchselect .= ' AND ('.$val->sql.') ';
413 }
414 }
415 else {
c8c765c0 416 $searchselect = ' AND (c.content ' . sql_ilike() . " '%$search%') "; //Be case-insensitive
7900ecb0 417 }
3d45b8e5 418
7900ecb0 419
420 } else {
c95034f2 421 $what = ' DISTINCT r.id, r.approved, r.timecreated, r.timemodified, r.userid, u.firstname, u.lastname ';
7900ecb0 422 $count = ' COUNT(r.id) ';
423 $tables = $CFG->prefix.'data_records r, '.$CFG->prefix.'user u ';
424 $where = 'WHERE r.dataid = '.$data->id. ' AND r.userid = u.id ';
425 $sortorder = ' ORDER BY r.timecreated '.$order. ' ';
426 $searchselect = ' ';
87518137 427
428 // If requiredentries is not reached, only show current user's entries
429 if (!$requiredentries_allowed) {
430 $where .= ' AND u.id = ' . $USER->id;
431 }
7900ecb0 432 }
3d4b223a 433
64452eb4 434
7900ecb0 435 /// To actually fetch the records
3d45b8e5 436
7900ecb0 437 $fromsql = ' FROM '.$tables.$where.$groupselect.$approveselect.$searchselect;
aab98aaf 438
7900ecb0 439 $sqlselect = 'SELECT '.$what.$fromsql.$sortorder;
3d45b8e5 440
7900ecb0 441 $sqlcount = 'SELECT '.$count.$fromsql; // Total number of records
3d45b8e5 442
7900ecb0 443 /// Work out the paging numbers
3d45b8e5 444
7900ecb0 445 $totalcount = count_records_sql($sqlcount);
3d4b223a 446
7900ecb0 447 if ($record) { // We need to just show one, so where is it in context?
448 $nowperpage = 1;
449 $mode = 'single';
de89899b 450
7900ecb0 451 # Following code needs testing to make it work
452 # if ($sort) { // We need to search by that field
453 # if ($content = get_field('data_content', 'content', 'recordid', $record->id, 'fieldid', $sort)) {
454 # $content = addslashes($content);
455 # if ($order == 'ASC') {
456 # $lessthan = " AND $sortcontentfull < '$content'
457 # OR ($sortcontentfull = '$content' AND r.id < '$record->id') ";
458 # } else {
459 # $lessthan = " AND $sortcontentfull > '$content'
460 # OR ($sortcontentfull = '$content' AND r.id < '$record->id') ";
461 # }
462 # } else { // Failed to find data (shouldn't happen), so fall back to something easy
463 # $lessthan = " r.id < '$record->id' ";
464 # }
465 # } else {
466 # $lessthan = " r.id < '$record->id' ";
467 # }
468 # $sqlindex = 'SELECT COUNT(DISTINCT c.recordid) '.$fromsql.$lessthan.$sortorder;
469 # $page = count_records_sql($sqlindex);
64452eb4 470
499ed215 471
7900ecb0 472 $allrecords = get_records_sql($sqlselect); // Kludgey but accurate at least!
473 $page = 0;
474 foreach ($allrecords as $key => $allrecord) {
475 if ($key == $record->id) {
476 break;
477 }
478 $page++;
3d45b8e5 479 }
3d45b8e5 480
7900ecb0 481 } else if ($mode == 'single') { // We rely on ambient $page settings
482 $nowperpage = 1;
3d45b8e5 483
7900ecb0 484 } else {
485 $nowperpage = $perpage;
486 }
3d45b8e5 487
7900ecb0 488 /// Get the actual records
489
490 $records = get_records_sql($sqlselect, $page * $nowperpage, $nowperpage);
3d45b8e5 491
7900ecb0 492 if (empty($records)) { // Nothing to show!
493 if ($record) { // Something was requested so try to show that at least (bug 5132)
494 if (has_capability('mod/data:manageentries', $context) || empty($data->approval) ||
495 $record->approved || (isloggedin() && $record->userid == $USER->id)) {
496 if (!$currentgroup || $record->groupid == $currentgroup || $record->groupid == 0) {
497 $records[] = $record;
498 }
3dec563c 499 }
500 }
7900ecb0 501 if ($records) { // OK, we can show this one
502 data_print_template('singletemplate', $records, $data, $search, $page);
503 } else if ($search){
504 notify(get_string('nomatch','data'));
505 } else {
506 notify(get_string('norecords','data'));
507 }
cf3e199b 508
7900ecb0 509 } else { // We have some records to print
68c88622 510
7900ecb0 511 if ($mode == 'single') { // Single template
512 $baseurl = 'view.php?d='.$data->id.'&amp;mode=single&amp;';
3d4b223a 513
7900ecb0 514 print_paging_bar($totalcount, $page, $nowperpage, $baseurl, $pagevar='page');
3d45b8e5 515
7900ecb0 516 if (empty($data->singletemplate)){
517 notify(get_string('nosingletemplate','data'));
518 data_generate_default_template($data, 'singletemplate', 0, false, false);
519 }
3d4b223a 520
7900ecb0 521 data_print_template('singletemplate', $records, $data, $search, $page);
3d45b8e5 522
7900ecb0 523 print_paging_bar($totalcount, $page, $nowperpage, $baseurl, $pagevar='page');
3d45b8e5 524
7900ecb0 525 } else { // List template
526 $baseurl = 'view.php?d='.$data->id.'&amp;';
527 //send the advanced flag through the URL so it is remembered while paging.
528 $baseurl .= 'advanced='.$advanced.'&amp;';
529 //pass variable to allow determining whether or not we are paging through results.
530 $baseurl .= 'paging='.$paging.'&amp;';
3d45b8e5 531
7900ecb0 532 print_paging_bar($totalcount, $page, $nowperpage, $baseurl, $pagevar='page');
3d45b8e5 533
7900ecb0 534 if (empty($data->listtemplate)){
535 notify(get_string('nolisttemplate','data'));
536 data_generate_default_template($data, 'listtemplate', 0, false, false);
537 }
538 echo $data->listtemplateheader;
539 data_print_template('listtemplate', $records, $data, $search, $page);
540 echo $data->listtemplatefooter;
541
542 print_paging_bar($totalcount, $page, $nowperpage, $baseurl, $pagevar='page');
3d45b8e5 543 }
3d45b8e5 544
3d45b8e5 545 }
7900ecb0 546 }
547
548 $search = trim($search);
549 if (empty($records)) {
550 $records = array();
f852d652 551 }
552
7900ecb0 553 //Advanced search form doesn't make sense for single (redirects list view)
450a87c5 554 if ($records || $search || $page || $mode == 'asearch' && $mode != 'single') {
7900ecb0 555 data_print_preference_form($data, $perpage, $search, $sort, $order, $search_array, $advanced, $mode);
64452eb4 556 }
3d4b223a 557
236d839f 558/// If we have blocks, then print the left side here
559 if (!empty($CFG->showblocksonmodpages)) {
9f7f1a74 560 print_container_end();
236d839f 561 echo '</td>'; // Middle column
562 if ((blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $PAGE->user_is_editing())) {
563 echo '<td style="width: '.$blocks_preferred_width.'px;" id="right-column">';
9f7f1a74 564 print_container_start();
236d839f 565 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
9f7f1a74 566 print_container_end();
236d839f 567 echo '</td>';
568 }
78e02af9 569 echo '</tr></table>';
236d839f 570 }
571
3d45b8e5 572 print_footer($course);
0997e51a 573?>