libdir.'/blocklib.php'); require_once("$CFG->libdir/rsslib.php"); require_once('pagelib.php'); if (!empty($THEME->customcorners)) { require_once($CFG->dirroot.'/lib/custom_corners_lib.php'); } /// One of these is necessary! $id = optional_param('id', 0, PARAM_INT); // course module id $d = optional_param('d', 0, PARAM_INT); // database id $rid = optional_param('rid', 0, PARAM_INT); //record id $mode = optional_param('mode', '', PARAM_ALPHA); // Force the browse mode ('single') $edit = optional_param('edit', -1, PARAM_BOOL); $page = optional_param('page', 0, PARAM_INT); /// These can be added to perform an action on a record $approve = optional_param('approve', 0, PARAM_INT); //approval recordid $delete = optional_param('delete', 0, PARAM_INT); //delete recordid if ($id) { if (! $cm = get_coursemodule_from_id('data', $id)) { error('Course Module ID was incorrect'); } if (! $course = get_record('course', 'id', $cm->course)) { error('Course is misconfigured'); } if (! $data = get_record('data', 'id', $cm->instance)) { error('Course module is incorrect'); } $record = NULL; } else if ($rid) { if (! $record = get_record('data_records', 'id', $rid)) { error('Record ID is incorrect'); } if (! $data = get_record('data', 'id', $record->dataid)) { error('Data ID is incorrect'); } if (! $course = get_record('course', 'id', $data->course)) { error('Course is misconfigured'); } if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) { error('Course Module ID was incorrect'); } } else { // We must have $d if (! $data = get_record('data', 'id', $d)) { error('Data ID is incorrect'); } if (! $course = get_record('course', 'id', $data->course)) { error('Course is misconfigured'); } if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) { error('Course Module ID was incorrect'); } $record = NULL; } require_course_login($course, true, $cm); $context = get_context_instance(CONTEXT_MODULE, $cm->id); require_capability('mod/data:viewentry', $context); /// If it's hidden then it's don't show anything. :) if (empty($cm->visible) and !has_capability('mod/data:managetemplates', $context)) { $navigation = build_navigation('', $cm); print_header_simple(format_string($data->name), "", $navigation, "", "", true, '', navmenu($course, $cm)); notice(get_string("activityiscurrentlyhidden")); } /// If we have an empty Database then redirect because this page is useless without data if (has_capability('mod/data:managetemplates', $context)) { if (!record_exists('data_fields','dataid',$data->id)) { // Brand new database! redirect($CFG->wwwroot.'/mod/data/field.php?d='.$data->id); // Redirect to field entry } } /// Check further parameters that set browsing preferences if (!isset($SESSION->dataprefs)) { $SESSION->dataprefs = array(); } if (!isset($SESSION->dataprefs[$data->id])) { $SESSION->dataprefs[$data->id] = array(); $SESSION->dataprefs[$data->id]['search'] = ''; $SESSION->dataprefs[$data->id]['search_array'] = array(); $SESSION->dataprefs[$data->id]['sort'] = $data->defaultsort; $SESSION->dataprefs[$data->id]['advanced'] = 0; $SESSION->dataprefs[$data->id]['order'] = ($data->defaultsortdir == 0) ? 'ASC' : 'DESC'; } $advanced = optional_param('advanced', $SESSION->dataprefs[$data->id]['advanced'], PARAM_INT); $search_array = $SESSION->dataprefs[$data->id]['search_array']; if (!empty($advanced)) { $search = ''; $fields = get_records('data_fields', 'dataid', $data->id); //Added to ammend paging error. This error would occur when attempting to go from one page of advanced //search results to another. All fields were reset in the page transfer, and there was no way of determining //whether or not the user reset them. This would cause a blank search to execute whenever the user attempted //to see any page of results past the first. //This fix works as follows: //$paging flag is set to false when page 0 of the advanced search results is viewed for the first time. //Viewing any page of results after page 0 passes the false $paging flag though the URL (see line 523) and the //execution falls through to the second condition below, allowing paging to be set to true. //Paging remains true and keeps getting passed though the URL until a new search is performed //(even if page 0 is revisited). //A false $paging flag generates advanced search results based on the fields input by the user. //A true $paging flag generates davanced search results from the $SESSION global. //(See lines 147-158) $paging = optional_param('paging', NULL, PARAM_BOOL); if($page == 0 && !isset($paging)) { $paging = false; } else { $paging = true; } if (!empty($fields)) { foreach($fields as $field) { $searchfield = data_get_field_from_id($field->id, $data); //Get field data to build search sql with. If paging is false, get from user. //If paging is true, get data from $search_array which is obtained from the $SESSION (see line 116). if(!$paging) { $val = $searchfield->parse_search_field(); } else { //Set value from session if there is a value @ the required index. if(isset($search_array[$field->id])) { $val = $search_array[$field->id]->data; } else { //If there is not an entry @ the required index, set value to blank. $val = ''; } } if (!empty($val)) { $search_array[$field->id] = new stdClass; $search_array[$field->id]->sql = $searchfield->generate_sql('c'.$field->id, $val); $search_array[$field->id]->data = $val; $search .= ' '.$val; } else { if (isset($search_array[$field->id])) { // clear it out unset($search_array[$field->id]); } } } } $SESSION->dataprefs[$data->id]['search_array'] = $search_array; // Make it sticky } else { $search = optional_param('search', $SESSION->dataprefs[$data->id]['search'], PARAM_NOTAGS); //Paging variable not used for standard search. Set it to null. $paging = NULL; } $textlib = textlib_get_instance(); if ($textlib->strlen($search) < 2) { $search = ''; } $SESSION->dataprefs[$data->id]['search'] = $search; // Make it sticky $sort = optional_param('sort', $SESSION->dataprefs[$data->id]['sort'], PARAM_INT); $SESSION->dataprefs[$data->id]['sort'] = $sort; // Make it sticky $order = (optional_param('order', $SESSION->dataprefs[$data->id]['order'], PARAM_ALPHA) == 'ASC') ? 'ASC': 'DESC'; $SESSION->dataprefs[$data->id]['order'] = $order; // Make it sticky $oldperpage = get_user_preferences('data_perpage_'.$data->id, 10); $perpage = optional_param('perpage', $oldperpage, PARAM_INT); if ($perpage < 2) { $perpage = 2; } if ($perpage != $oldperpage) { set_user_preference('data_perpage_'.$data->id, $perpage); } add_to_log($course->id, 'data', 'view', "view.php?id=$cm->id", $data->id, $cm->id); // Initialize $PAGE, compute blocks $PAGE = page_create_instance($data->id); $pageblocks = blocks_setup($PAGE); $blocks_preferred_width = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), 210); if (($edit != -1) and $PAGE->user_allowed_editing()) { $USER->editing = $edit; } /// RSS and CSS and JS meta $meta = ''; if (!empty($CFG->enablerssfeeds) && !empty($CFG->data_enablerssfeeds) && $data->rssarticles > 0) { $rsspath = rss_get_url($course->id, $USER->id, 'data', $data->id); $meta .= 'shortname) .': %fullname%" href="'.$rsspath.'" />'; } if ($data->csstemplate) { $meta .= ' '; } if ($data->jstemplate) { $meta .= ''; } /// Print the page header $PAGE->print_header($course->shortname.': %fullname%', '', $meta); /// If we have blocks, then print the left side here if (!empty($CFG->showblocksonmodpages)) { echo '
'; if (!empty($THEME->customcorners)) print_custom_corners_start(); blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT); if (!empty($THEME->customcorners)) print_custom_corners_end(); echo ' | '; } echo '';
if (!empty($THEME->customcorners)) print_custom_corners_start();
}
/// Check to see if groups are being used here
$returnurl = 'view.php?d='.$data->id.'&search='.s($search).'&sort='.s($sort).'&order='.s($order).'&';
groups_print_activity_menu($cm, $returnurl);
$currentgroup = groups_get_activity_group($cm);
$groupmode = groups_get_activity_groupmode($cm);
print_heading(format_string($data->name));
// Do we need to show a link to the RSS feed for the records?
if (!empty($CFG->enablerssfeeds) && !empty($CFG->data_enablerssfeeds) && $data->rssarticles > 0) {
echo ' ';
rss_print_link($course->id, $USER->id, 'data', $data->id, get_string('rsstype'));
echo ' ';
echo '';
}
if ($data->intro and empty($page) and empty($record) and $mode != 'single') {
print_box(format_text($data->intro), 'generalbox', 'intro');
}
/// Delete any requested records
if ($delete && confirm_sesskey() && (has_capability('mod/data:manageentries', $context) or data_isowner($delete))) {
if ($confirm = optional_param('confirm',0,PARAM_INT)) {
if ($deleterecord = get_record('data_records', 'id', $delete)) { // Need to check this is valid
if ($deleterecord->dataid == $data->id) { // Must be from this database
if ($contents = get_records('data_content','recordid', $deleterecord->id)) {
foreach ($contents as $content) { // Delete files or whatever else this field allows
if ($field = data_get_field_from_id($content->fieldid, $data)) { // Might not be there
$field->delete_content($content->recordid);
}
}
}
delete_records('data_content','recordid', $deleterecord->id);
delete_records('data_records','id', $deleterecord->id);
add_to_log($course->id, 'data', 'record delete', "view.php?id=$cm->id", $data->id, $cm->id);
notify(get_string('recorddeleted','data'), 'notifysuccess');
}
}
} else { // Print a confirmation page
if ($deleterecord = get_record('data_records', 'id', $delete)) { // Need to check this is valid
if ($deleterecord->dataid == $data->id) { // Must be from this database
notice_yesno(get_string('confirmdeleterecord','data'),
'view.php?d='.$data->id.'&delete='.$delete.'&confirm=1&sesskey='.sesskey(),
'view.php?d='.$data->id);
$records[] = $deleterecord;
echo data_print_template('singletemplate', $records, $data, '', 0, true);
print_footer($course);
exit;
}
}
}
}
/// Print the tabs
if ($record or $mode == 'single') {
$currenttab = 'single';
} elseif($mode == 'asearch') {
$currenttab = 'asearch';
}
else {
$currenttab = 'list';
}
include('tabs.php');
if ($mode != 'asearch') {
/// Approve any requested records
if ($approve && confirm_sesskey() && has_capability('mod/data:approve', $context)) {
if ($approverecord = get_record('data_records', 'id', $approve)) { // Need to check this is valid
if ($approverecord->dataid == $data->id) { // Must be from this database
$newrecord->id = $approverecord->id;
$newrecord->approved = 1;
if (update_record('data_records', $newrecord)) {
notify(get_string('recordapproved','data'), 'notifysuccess');
}
}
}
}
// If not teacher, check whether user has sufficient records to view
if (!has_capability('mod/data:managetemplates', $context) and data_numentries($data) < $data->requiredentriestoview){
notify (($data->requiredentriestoview - data_numentries($data)).' '.get_string('insufficiententries','data'));
echo ' |