. /** * This file is part of the Database module for Moodle * * @copyright 2005 Martin Dougiamas http://dougiamas.com * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @package mod_data */ use mod_data\manager; require_once(__DIR__ . '/../../config.php'); require_once($CFG->dirroot . '/mod/data/locallib.php'); require_once($CFG->libdir . '/rsslib.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') $filter = optional_param('filter', 0, PARAM_BOOL); // search filter will only be applied when $filter is true $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 $disapprove = optional_param('disapprove', 0, PARAM_INT); // disapproval recordid $delete = optional_param('delete', 0, PARAM_INT); //delete recordid $multidelete = optional_param_array('delcheck', null, PARAM_INT); $serialdelete = optional_param('serialdelete', null, PARAM_RAW); $confirm = optional_param('confirm', 0, PARAM_INT); $record = null; if ($id) { list($course, $cm) = get_course_and_cm_from_cmid($id, manager::MODULE); $manager = manager::create_from_coursemodule($cm); } else if ($rid) { $record = $DB->get_record('data_records', ['id' => $rid], '*', MUST_EXIST); $manager = manager::create_from_data_record($record); $cm = $manager->get_coursemodule(); $course = get_course($cm->course); } else { // We must have $d. $data = $DB->get_record('data', ['id' => $d], '*', MUST_EXIST); $manager = manager::create_from_instance($data); $cm = $manager->get_coursemodule(); $course = get_course($cm->course); } $data = $manager->get_instance(); $context = $manager->get_context(); require_login($course, true, $cm); require_once($CFG->dirroot . '/comment/lib.php'); comment::init(); require_capability('mod/data:viewentry', $context); /// 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'; } // reset advanced form if (!is_null(optional_param('resetadv', null, PARAM_RAW))) { $SESSION->dataprefs[$data->id]['search_array'] = array(); // we need the redirect to cleanup the form state properly redirect("view.php?id=$cm->id&mode=$mode&search=&advanced=1"); } $advanced = optional_param('advanced', -1, PARAM_INT); if ($advanced == -1) { $advanced = $SESSION->dataprefs[$data->id]['advanced']; } else { if (!$advanced) { // explicitly switched to normal mode - discard all advanced search settings $SESSION->dataprefs[$data->id]['search_array'] = array(); } $SESSION->dataprefs[$data->id]['advanced'] = $advanced; } $search_array = $SESSION->dataprefs[$data->id]['search_array']; if (!empty($advanced)) { $search = ''; //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. $paging = optional_param('paging', NULL, PARAM_BOOL); if($page == 0 && !isset($paging)) { $paging = false; } else { $paging = true; } // Now build the advanced search array. list($search_array, $search) = data_build_search_array($data, $paging, $search_array); $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; } // Disable search filters if $filter is not true: if (! $filter) { $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); } // Trigger module viewed event and completion. $manager->set_module_viewed($course); $urlparams = array('d' => $data->id); if ($record) { $urlparams['rid'] = $record->id; } if ($mode) { $urlparams['mode'] = $mode; } if ($page) { $urlparams['page'] = $page; } if ($filter) { $urlparams['filter'] = $filter; } $pageurl = new moodle_url('/mod/data/view.php', $urlparams); // Initialize $PAGE, compute blocks. $PAGE->set_url($pageurl); if (($edit != -1) and $PAGE->user_allowed_editing()) { $USER->editing = $edit; } $courseshortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id))); /// RSS and CSS and JS meta $meta = ''; if (!empty($CFG->enablerssfeeds) && !empty($CFG->data_enablerssfeeds) && $data->rssarticles > 0) { $rsstitle = $courseshortname . ': ' . format_string($data->name); rss_add_http_header($context, 'mod_data', $data, $rsstitle); } if ($data->csstemplate) { $PAGE->requires->css('/mod/data/css.php?d='.$data->id); } if ($data->jstemplate) { $PAGE->requires->js('/mod/data/js.php?d='.$data->id, true); } /// Print the page header // Note: MDL-19010 there will be further changes to printing header and blocks. // The code will be much nicer than this eventually. if ($PAGE->user_allowed_editing() && !$PAGE->theme->haseditswitch) { // Change URL parameter and block display string value depending on whether editing is enabled or not if ($PAGE->user_is_editing()) { $urlediting = 'off'; $strediting = get_string('blockseditoff'); } else { $urlediting = 'on'; $strediting = get_string('blocksediton'); } $editurl = new moodle_url($CFG->wwwroot.'/mod/data/view.php', ['id' => $cm->id, 'edit' => $urlediting]); $PAGE->set_button($OUTPUT->single_button($editurl, $strediting)); } if ($mode == 'asearch') { $PAGE->navbar->add(get_string('search')); } $PAGE->add_body_class('mediumwidth'); $titleparts = [ format_string($data->name), format_string($course->fullname), ]; if (!empty(trim($search))) { // Indicate search results on page title when searching. array_unshift($titleparts, get_string('searchresults', 'data', s($search))); } else if (!empty($delete) && empty($confirm)) { // Displaying the delete confirmation page. array_unshift($titleparts, get_string('deleteentry', 'data')); } else if ($record !== null || $mode == 'single') { // Indicate on the page tile if the user is viewing this page on single view mode. array_unshift($titleparts, get_string('single', 'data')); } $PAGE->set_title(implode(moodle_page::TITLE_SEPARATOR, $titleparts)); $PAGE->set_heading($course->fullname); $PAGE->force_settings_menu(true); if ($delete && confirm_sesskey() && (data_user_can_manage_entry($delete, $data, $context))) { $PAGE->activityheader->disable(); } // Check to see if groups are being used here. // We need the most up to date current group value. Make sure it is updated at this point. $currentgroup = groups_get_activity_group($cm, true); $groupmode = groups_get_activity_groupmode($cm); $canmanageentries = has_capability('mod/data:manageentries', $context); echo $OUTPUT->header(); if (!$manager->has_fields()) { // It's a brand-new database. There are no fields. $renderer = $manager->get_renderer(); echo $renderer->render_database_zero_state($manager); echo $OUTPUT->footer(); // Don't check the rest of the options. There is no field, there is nothing else to work with. exit; } // Detect entries not approved yet and show hint instead of not found error. if ($record and !data_can_view_record($data, $record, $currentgroup, $canmanageentries)) { throw new \moodle_exception('notapprovederror', 'data'); } // Do we need to show a link to the RSS feed for the records? //this links has been Settings (database activity administration) block /*if (!empty($CFG->enablerssfeeds) && !empty($CFG->data_enablerssfeeds) && $data->rssarticles > 0) { echo '