NEW MODULE FROM MOODLE.COM - DATABASE !
Finally, we have an early version good enough for everyone to
start banging on to help us polish it up and find bugs.
Please take a look and file bugs in the bug tracker under "Database module".
We urgently need
- new icons for existing field types
- testing on PostgreSQL install
Coming soon (?):
- Many more field types: calculation, checkbox, relation, date, datetime,
time, email, group, list, user, number, richtext
(Please let us know if you are interested in developing any of these)
- A way to save and restore "presets", which are field/template sets
- Backup/Restore support
- Groups Support
- RSS support
Many thanks to Yu for all the hard work under my whip.
2005-12-02 07:50:26 +00:00
|
|
|
<?php // $Id$
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// //
|
|
|
|
// NOTICE OF COPYRIGHT //
|
|
|
|
// //
|
|
|
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
|
|
|
// http://moodle.org //
|
|
|
|
// //
|
|
|
|
// Copyright (C) 2005 Martin Dougiamas http://dougiamas.com //
|
|
|
|
// //
|
|
|
|
// This program is free software; you can redistribute it and/or modify //
|
|
|
|
// it under the terms of the GNU General Public License as published by //
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or //
|
|
|
|
// (at your option) any later version. //
|
|
|
|
// //
|
|
|
|
// This program is distributed in the hope that it will be useful, //
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
|
|
|
// GNU General Public License for more details: //
|
|
|
|
// //
|
|
|
|
// http://www.gnu.org/copyleft/gpl.html //
|
|
|
|
// //
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
require_once('../../config.php');
|
|
|
|
require_once('lib.php');
|
|
|
|
require_once($CFG->libdir.'/blocklib.php');
|
2006-02-13 07:57:54 +00:00
|
|
|
require_once("$CFG->libdir/rsslib.php");
|
NEW MODULE FROM MOODLE.COM - DATABASE !
Finally, we have an early version good enough for everyone to
start banging on to help us polish it up and find bugs.
Please take a look and file bugs in the bug tracker under "Database module".
We urgently need
- new icons for existing field types
- testing on PostgreSQL install
Coming soon (?):
- Many more field types: calculation, checkbox, relation, date, datetime,
time, email, group, list, user, number, richtext
(Please let us know if you are interested in developing any of these)
- A way to save and restore "presets", which are field/template sets
- Backup/Restore support
- Groups Support
- RSS support
Many thanks to Yu for all the hard work under my whip.
2005-12-02 07:50:26 +00:00
|
|
|
|
|
|
|
require_once('pagelib.php');
|
2007-11-23 16:49:51 +00:00
|
|
|
|
2006-03-29 08:49:28 +00:00
|
|
|
/// One of these is necessary!
|
NEW MODULE FROM MOODLE.COM - DATABASE !
Finally, we have an early version good enough for everyone to
start banging on to help us polish it up and find bugs.
Please take a look and file bugs in the bug tracker under "Database module".
We urgently need
- new icons for existing field types
- testing on PostgreSQL install
Coming soon (?):
- Many more field types: calculation, checkbox, relation, date, datetime,
time, email, group, list, user, number, richtext
(Please let us know if you are interested in developing any of these)
- A way to save and restore "presets", which are field/template sets
- Backup/Restore support
- Groups Support
- RSS support
Many thanks to Yu for all the hard work under my whip.
2005-12-02 07:50:26 +00:00
|
|
|
$id = optional_param('id', 0, PARAM_INT); // course module id
|
|
|
|
$d = optional_param('d', 0, PARAM_INT); // database id
|
2006-03-29 08:49:28 +00:00
|
|
|
$rid = optional_param('rid', 0, PARAM_INT); //record id
|
|
|
|
|
|
|
|
$mode = optional_param('mode', '', PARAM_ALPHA); // Force the browse mode ('single')
|
|
|
|
|
2006-04-23 20:58:06 +00:00
|
|
|
$edit = optional_param('edit', -1, PARAM_BOOL);
|
2007-02-26 06:56:05 +00:00
|
|
|
$page = optional_param('page', 0, PARAM_INT);
|
2006-03-29 08:49:28 +00:00
|
|
|
/// These can be added to perform an action on a record
|
2006-03-26 05:03:10 +00:00
|
|
|
$approve = optional_param('approve', 0, PARAM_INT); //approval recordid
|
|
|
|
$delete = optional_param('delete', 0, PARAM_INT); //delete recordid
|
2006-12-13 20:26:11 +00:00
|
|
|
|
NEW MODULE FROM MOODLE.COM - DATABASE !
Finally, we have an early version good enough for everyone to
start banging on to help us polish it up and find bugs.
Please take a look and file bugs in the bug tracker under "Database module".
We urgently need
- new icons for existing field types
- testing on PostgreSQL install
Coming soon (?):
- Many more field types: calculation, checkbox, relation, date, datetime,
time, email, group, list, user, number, richtext
(Please let us know if you are interested in developing any of these)
- A way to save and restore "presets", which are field/template sets
- Backup/Restore support
- Groups Support
- RSS support
Many thanks to Yu for all the hard work under my whip.
2005-12-02 07:50:26 +00:00
|
|
|
if ($id) {
|
2006-08-08 22:09:55 +00:00
|
|
|
if (! $cm = get_coursemodule_from_id('data', $id)) {
|
2008-04-16 11:51:50 +00:00
|
|
|
error('Course Module ID was incorrect');
|
NEW MODULE FROM MOODLE.COM - DATABASE !
Finally, we have an early version good enough for everyone to
start banging on to help us polish it up and find bugs.
Please take a look and file bugs in the bug tracker under "Database module".
We urgently need
- new icons for existing field types
- testing on PostgreSQL install
Coming soon (?):
- Many more field types: calculation, checkbox, relation, date, datetime,
time, email, group, list, user, number, richtext
(Please let us know if you are interested in developing any of these)
- A way to save and restore "presets", which are field/template sets
- Backup/Restore support
- Groups Support
- RSS support
Many thanks to Yu for all the hard work under my whip.
2005-12-02 07:50:26 +00:00
|
|
|
}
|
|
|
|
if (! $course = get_record('course', 'id', $cm->course)) {
|
2008-04-16 11:51:50 +00:00
|
|
|
error('Course is misconfigured');
|
NEW MODULE FROM MOODLE.COM - DATABASE !
Finally, we have an early version good enough for everyone to
start banging on to help us polish it up and find bugs.
Please take a look and file bugs in the bug tracker under "Database module".
We urgently need
- new icons for existing field types
- testing on PostgreSQL install
Coming soon (?):
- Many more field types: calculation, checkbox, relation, date, datetime,
time, email, group, list, user, number, richtext
(Please let us know if you are interested in developing any of these)
- A way to save and restore "presets", which are field/template sets
- Backup/Restore support
- Groups Support
- RSS support
Many thanks to Yu for all the hard work under my whip.
2005-12-02 07:50:26 +00:00
|
|
|
}
|
|
|
|
if (! $data = get_record('data', 'id', $cm->instance)) {
|
2008-04-16 11:51:50 +00:00
|
|
|
error('Course module is incorrect');
|
NEW MODULE FROM MOODLE.COM - DATABASE !
Finally, we have an early version good enough for everyone to
start banging on to help us polish it up and find bugs.
Please take a look and file bugs in the bug tracker under "Database module".
We urgently need
- new icons for existing field types
- testing on PostgreSQL install
Coming soon (?):
- Many more field types: calculation, checkbox, relation, date, datetime,
time, email, group, list, user, number, richtext
(Please let us know if you are interested in developing any of these)
- A way to save and restore "presets", which are field/template sets
- Backup/Restore support
- Groups Support
- RSS support
Many thanks to Yu for all the hard work under my whip.
2005-12-02 07:50:26 +00:00
|
|
|
}
|
2006-03-29 08:49:28 +00:00
|
|
|
$record = NULL;
|
NEW MODULE FROM MOODLE.COM - DATABASE !
Finally, we have an early version good enough for everyone to
start banging on to help us polish it up and find bugs.
Please take a look and file bugs in the bug tracker under "Database module".
We urgently need
- new icons for existing field types
- testing on PostgreSQL install
Coming soon (?):
- Many more field types: calculation, checkbox, relation, date, datetime,
time, email, group, list, user, number, richtext
(Please let us know if you are interested in developing any of these)
- A way to save and restore "presets", which are field/template sets
- Backup/Restore support
- Groups Support
- RSS support
Many thanks to Yu for all the hard work under my whip.
2005-12-02 07:50:26 +00:00
|
|
|
|
2006-03-29 08:49:28 +00:00
|
|
|
} else if ($rid) {
|
|
|
|
if (! $record = get_record('data_records', 'id', $rid)) {
|
2008-04-16 11:51:50 +00:00
|
|
|
error('Record ID is incorrect');
|
2006-03-29 08:49:28 +00:00
|
|
|
}
|
|
|
|
if (! $data = get_record('data', 'id', $record->dataid)) {
|
2008-04-16 11:51:50 +00:00
|
|
|
error('Data ID is incorrect');
|
2006-03-29 08:49:28 +00:00
|
|
|
}
|
|
|
|
if (! $course = get_record('course', 'id', $data->course)) {
|
2008-04-16 11:51:50 +00:00
|
|
|
error('Course is misconfigured');
|
2006-03-29 08:49:28 +00:00
|
|
|
}
|
|
|
|
if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) {
|
2008-04-16 11:51:50 +00:00
|
|
|
error('Course Module ID was incorrect');
|
2006-03-29 08:49:28 +00:00
|
|
|
}
|
|
|
|
} else { // We must have $d
|
NEW MODULE FROM MOODLE.COM - DATABASE !
Finally, we have an early version good enough for everyone to
start banging on to help us polish it up and find bugs.
Please take a look and file bugs in the bug tracker under "Database module".
We urgently need
- new icons for existing field types
- testing on PostgreSQL install
Coming soon (?):
- Many more field types: calculation, checkbox, relation, date, datetime,
time, email, group, list, user, number, richtext
(Please let us know if you are interested in developing any of these)
- A way to save and restore "presets", which are field/template sets
- Backup/Restore support
- Groups Support
- RSS support
Many thanks to Yu for all the hard work under my whip.
2005-12-02 07:50:26 +00:00
|
|
|
if (! $data = get_record('data', 'id', $d)) {
|
2008-04-16 11:51:50 +00:00
|
|
|
error('Data ID is incorrect');
|
NEW MODULE FROM MOODLE.COM - DATABASE !
Finally, we have an early version good enough for everyone to
start banging on to help us polish it up and find bugs.
Please take a look and file bugs in the bug tracker under "Database module".
We urgently need
- new icons for existing field types
- testing on PostgreSQL install
Coming soon (?):
- Many more field types: calculation, checkbox, relation, date, datetime,
time, email, group, list, user, number, richtext
(Please let us know if you are interested in developing any of these)
- A way to save and restore "presets", which are field/template sets
- Backup/Restore support
- Groups Support
- RSS support
Many thanks to Yu for all the hard work under my whip.
2005-12-02 07:50:26 +00:00
|
|
|
}
|
|
|
|
if (! $course = get_record('course', 'id', $data->course)) {
|
2008-04-16 11:51:50 +00:00
|
|
|
error('Course is misconfigured');
|
NEW MODULE FROM MOODLE.COM - DATABASE !
Finally, we have an early version good enough for everyone to
start banging on to help us polish it up and find bugs.
Please take a look and file bugs in the bug tracker under "Database module".
We urgently need
- new icons for existing field types
- testing on PostgreSQL install
Coming soon (?):
- Many more field types: calculation, checkbox, relation, date, datetime,
time, email, group, list, user, number, richtext
(Please let us know if you are interested in developing any of these)
- A way to save and restore "presets", which are field/template sets
- Backup/Restore support
- Groups Support
- RSS support
Many thanks to Yu for all the hard work under my whip.
2005-12-02 07:50:26 +00:00
|
|
|
}
|
|
|
|
if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) {
|
2008-04-16 11:51:50 +00:00
|
|
|
error('Course Module ID was incorrect');
|
NEW MODULE FROM MOODLE.COM - DATABASE !
Finally, we have an early version good enough for everyone to
start banging on to help us polish it up and find bugs.
Please take a look and file bugs in the bug tracker under "Database module".
We urgently need
- new icons for existing field types
- testing on PostgreSQL install
Coming soon (?):
- Many more field types: calculation, checkbox, relation, date, datetime,
time, email, group, list, user, number, richtext
(Please let us know if you are interested in developing any of these)
- A way to save and restore "presets", which are field/template sets
- Backup/Restore support
- Groups Support
- RSS support
Many thanks to Yu for all the hard work under my whip.
2005-12-02 07:50:26 +00:00
|
|
|
}
|
2006-03-29 08:49:28 +00:00
|
|
|
$record = NULL;
|
NEW MODULE FROM MOODLE.COM - DATABASE !
Finally, we have an early version good enough for everyone to
start banging on to help us polish it up and find bugs.
Please take a look and file bugs in the bug tracker under "Database module".
We urgently need
- new icons for existing field types
- testing on PostgreSQL install
Coming soon (?):
- Many more field types: calculation, checkbox, relation, date, datetime,
time, email, group, list, user, number, richtext
(Please let us know if you are interested in developing any of these)
- A way to save and restore "presets", which are field/template sets
- Backup/Restore support
- Groups Support
- RSS support
Many thanks to Yu for all the hard work under my whip.
2005-12-02 07:50:26 +00:00
|
|
|
}
|
|
|
|
|
2006-03-27 04:13:32 +00:00
|
|
|
require_course_login($course, true, $cm);
|
2006-12-13 20:26:11 +00:00
|
|
|
|
2006-08-09 13:45:49 +00:00
|
|
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
2006-09-18 13:46:09 +00:00
|
|
|
require_capability('mod/data:viewentry', $context);
|
2006-03-30 04:37:16 +00:00
|
|
|
|
2006-03-29 08:49:28 +00:00
|
|
|
/// If we have an empty Database then redirect because this page is useless without data
|
2006-08-14 05:55:40 +00:00
|
|
|
if (has_capability('mod/data:managetemplates', $context)) {
|
2006-03-22 08:32:54 +00:00
|
|
|
if (!record_exists('data_fields','dataid',$data->id)) { // Brand new database!
|
2006-03-24 02:44:05 +00:00
|
|
|
redirect($CFG->wwwroot.'/mod/data/field.php?d='.$data->id); // Redirect to field entry
|
NEW MODULE FROM MOODLE.COM - DATABASE !
Finally, we have an early version good enough for everyone to
start banging on to help us polish it up and find bugs.
Please take a look and file bugs in the bug tracker under "Database module".
We urgently need
- new icons for existing field types
- testing on PostgreSQL install
Coming soon (?):
- Many more field types: calculation, checkbox, relation, date, datetime,
time, email, group, list, user, number, richtext
(Please let us know if you are interested in developing any of these)
- A way to save and restore "presets", which are field/template sets
- Backup/Restore support
- Groups Support
- RSS support
Many thanks to Yu for all the hard work under my whip.
2005-12-02 07:50:26 +00:00
|
|
|
}
|
|
|
|
}
|
2006-03-27 08:42:25 +00:00
|
|
|
|
2006-03-29 08:49:28 +00:00
|
|
|
|
|
|
|
/// Check further parameters that set browsing preferences
|
|
|
|
if (!isset($SESSION->dataprefs)) {
|
|
|
|
$SESSION->dataprefs = array();
|
2006-03-27 08:42:25 +00:00
|
|
|
}
|
2006-03-29 08:49:28 +00:00
|
|
|
if (!isset($SESSION->dataprefs[$data->id])) {
|
|
|
|
$SESSION->dataprefs[$data->id] = array();
|
|
|
|
$SESSION->dataprefs[$data->id]['search'] = '';
|
2007-02-26 06:56:05 +00:00
|
|
|
$SESSION->dataprefs[$data->id]['search_array'] = array();
|
2006-03-29 08:49:28 +00:00
|
|
|
$SESSION->dataprefs[$data->id]['sort'] = $data->defaultsort;
|
2007-02-26 06:56:05 +00:00
|
|
|
$SESSION->dataprefs[$data->id]['advanced'] = 0;
|
2006-03-29 08:49:28 +00:00
|
|
|
$SESSION->dataprefs[$data->id]['order'] = ($data->defaultsortdir == 0) ? 'ASC' : 'DESC';
|
NEW MODULE FROM MOODLE.COM - DATABASE !
Finally, we have an early version good enough for everyone to
start banging on to help us polish it up and find bugs.
Please take a look and file bugs in the bug tracker under "Database module".
We urgently need
- new icons for existing field types
- testing on PostgreSQL install
Coming soon (?):
- Many more field types: calculation, checkbox, relation, date, datetime,
time, email, group, list, user, number, richtext
(Please let us know if you are interested in developing any of these)
- A way to save and restore "presets", which are field/template sets
- Backup/Restore support
- Groups Support
- RSS support
Many thanks to Yu for all the hard work under my whip.
2005-12-02 07:50:26 +00:00
|
|
|
}
|
2008-04-16 13:54:01 +00:00
|
|
|
|
2008-04-19 15:33:06 +00:00
|
|
|
// 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");
|
|
|
|
}
|
|
|
|
|
2008-04-16 13:54:01 +00:00
|
|
|
$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();
|
|
|
|
}
|
2008-04-16 14:09:15 +00:00
|
|
|
$SESSION->dataprefs[$data->id]['advanced'] = $advanced;
|
2008-04-16 13:54:01 +00:00
|
|
|
}
|
|
|
|
|
2007-02-26 06:56:05 +00:00
|
|
|
$search_array = $SESSION->dataprefs[$data->id]['search_array'];
|
2008-04-19 15:33:06 +00:00
|
|
|
|
2007-02-26 06:56:05 +00:00
|
|
|
if (!empty($advanced)) {
|
|
|
|
$search = '';
|
2008-04-16 13:32:14 +00:00
|
|
|
$vals = array();
|
2007-02-26 06:56:05 +00:00
|
|
|
$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;
|
|
|
|
}
|
2008-04-16 11:51:50 +00:00
|
|
|
if (!empty($fields)) {
|
2007-02-26 06:56:05 +00:00
|
|
|
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();
|
2008-04-16 11:51:50 +00:00
|
|
|
} else {
|
2007-02-26 06:56:05 +00:00
|
|
|
//Set value from session if there is a value @ the required index.
|
2008-04-16 11:51:50 +00:00
|
|
|
if (isset($search_array[$field->id])) {
|
2007-02-26 06:56:05 +00:00
|
|
|
$val = $search_array[$field->id]->data;
|
2008-04-16 11:51:50 +00:00
|
|
|
} else { //If there is not an entry @ the required index, set value to blank.
|
2007-02-26 06:56:05 +00:00
|
|
|
$val = '';
|
|
|
|
}
|
|
|
|
}
|
2008-04-16 11:51:50 +00:00
|
|
|
if (!empty($val)) {
|
|
|
|
$search_array[$field->id] = new object();
|
|
|
|
$search_array[$field->id]->sql = $searchfield->generate_sql('c'.$field->id, $val);
|
|
|
|
$search_array[$field->id]->data = $val;
|
2008-04-16 13:32:14 +00:00
|
|
|
$vals[] = $val;
|
2008-04-16 11:51:50 +00:00
|
|
|
} else {
|
|
|
|
// clear it out
|
|
|
|
unset($search_array[$field->id]);
|
2007-02-26 06:56:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-04-16 11:51:50 +00:00
|
|
|
|
|
|
|
if (!$paging) {
|
|
|
|
// name searching
|
|
|
|
$fn = optional_param('u_fn', '', PARAM_NOTAGS);
|
|
|
|
$ln = optional_param('u_ln', '', PARAM_NOTAGS);
|
|
|
|
} else {
|
2008-04-16 13:54:01 +00:00
|
|
|
$fn = isset($search_array[DATA_FIRSTNAME]) ? $search_array[DATA_FIRSTNAME]->data : '';
|
|
|
|
$ln = isset($search_array[DATA_LASTNAME]) ? $search_array[DATA_LASTNAME]->data : '';
|
2008-04-16 11:51:50 +00:00
|
|
|
}
|
|
|
|
if (!empty($fn)) {
|
|
|
|
$search_array[DATA_FIRSTNAME] = new object();
|
|
|
|
$search_array[DATA_FIRSTNAME]->sql = '';
|
|
|
|
$search_array[DATA_FIRSTNAME]->field = 'u.firstname';
|
|
|
|
$search_array[DATA_FIRSTNAME]->data = $fn;
|
2008-04-16 13:32:14 +00:00
|
|
|
$vals[] = $fn;
|
2008-04-16 11:51:50 +00:00
|
|
|
} else {
|
|
|
|
unset($search_array[DATA_FIRSTNAME]);
|
|
|
|
}
|
|
|
|
if (!empty($ln)) {
|
|
|
|
$search_array[DATA_LASTNAME] = new object();
|
|
|
|
$search_array[DATA_LASTNAME]->sql = '';
|
|
|
|
$search_array[DATA_LASTNAME]->field = 'u.lastname';
|
|
|
|
$search_array[DATA_LASTNAME]->data = $ln;
|
2008-04-16 13:32:14 +00:00
|
|
|
$vals[] = $ln;
|
2008-04-16 11:51:50 +00:00
|
|
|
} else {
|
|
|
|
unset($search_array[DATA_LASTNAME]);
|
|
|
|
}
|
|
|
|
|
2007-02-26 06:56:05 +00:00
|
|
|
$SESSION->dataprefs[$data->id]['search_array'] = $search_array; // Make it sticky
|
2008-04-16 11:51:50 +00:00
|
|
|
|
2008-04-16 13:32:14 +00:00
|
|
|
// in case we want to switch to simple search later - there might be multiple values there ;-)
|
|
|
|
if ($vals) {
|
|
|
|
$val = reset($vals);
|
|
|
|
if (is_string($val)) {
|
|
|
|
$search = $val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-16 11:51:50 +00:00
|
|
|
} else {
|
2007-02-26 06:56:05 +00:00
|
|
|
$search = optional_param('search', $SESSION->dataprefs[$data->id]['search'], PARAM_NOTAGS);
|
|
|
|
//Paging variable not used for standard search. Set it to null.
|
|
|
|
$paging = NULL;
|
|
|
|
}
|
|
|
|
|
2007-09-16 18:49:41 +00:00
|
|
|
$textlib = textlib_get_instance();
|
2006-12-13 09:38:46 +00:00
|
|
|
if ($textlib->strlen($search) < 2) {
|
|
|
|
$search = '';
|
|
|
|
}
|
2006-03-29 08:49:28 +00:00
|
|
|
$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);
|
|
|
|
}
|
|
|
|
|
NEW MODULE FROM MOODLE.COM - DATABASE !
Finally, we have an early version good enough for everyone to
start banging on to help us polish it up and find bugs.
Please take a look and file bugs in the bug tracker under "Database module".
We urgently need
- new icons for existing field types
- testing on PostgreSQL install
Coming soon (?):
- Many more field types: calculation, checkbox, relation, date, datetime,
time, email, group, list, user, number, richtext
(Please let us know if you are interested in developing any of these)
- A way to save and restore "presets", which are field/template sets
- Backup/Restore support
- Groups Support
- RSS support
Many thanks to Yu for all the hard work under my whip.
2005-12-02 07:50:26 +00:00
|
|
|
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);
|
|
|
|
|
2006-04-23 20:58:06 +00:00
|
|
|
if (($edit != -1) and $PAGE->user_allowed_editing()) {
|
|
|
|
$USER->editing = $edit;
|
NEW MODULE FROM MOODLE.COM - DATABASE !
Finally, we have an early version good enough for everyone to
start banging on to help us polish it up and find bugs.
Please take a look and file bugs in the bug tracker under "Database module".
We urgently need
- new icons for existing field types
- testing on PostgreSQL install
Coming soon (?):
- Many more field types: calculation, checkbox, relation, date, datetime,
time, email, group, list, user, number, richtext
(Please let us know if you are interested in developing any of these)
- A way to save and restore "presets", which are field/template sets
- Backup/Restore support
- Groups Support
- RSS support
Many thanks to Yu for all the hard work under my whip.
2005-12-02 07:50:26 +00:00
|
|
|
}
|
|
|
|
|
2006-08-17 09:27:51 +00:00
|
|
|
/// RSS and CSS and JS meta
|
2006-03-29 18:29:16 +00:00
|
|
|
$meta = '';
|
2006-04-05 01:38:06 +00:00
|
|
|
if (!empty($CFG->enablerssfeeds) && !empty($CFG->data_enablerssfeeds) && $data->rssarticles > 0) {
|
2006-03-03 08:06:50 +00:00
|
|
|
$rsspath = rss_get_url($course->id, $USER->id, 'data', $data->id);
|
2006-03-29 18:29:16 +00:00
|
|
|
$meta .= '<link rel="alternate" type="application/rss+xml" ';
|
2007-02-28 06:25:22 +00:00
|
|
|
$meta .= 'title ="'. format_string($course->shortname) .': %fullname%" href="'.$rsspath.'" />';
|
2006-03-29 18:29:16 +00:00
|
|
|
}
|
|
|
|
if ($data->csstemplate) {
|
|
|
|
$meta .= '<link rel="stylesheet" type="text/css" href="'.$CFG->wwwroot.'/mod/data/css.php?d='.$data->id.'" /> ';
|
2006-03-03 08:06:50 +00:00
|
|
|
}
|
2006-08-17 09:27:51 +00:00
|
|
|
if ($data->jstemplate) {
|
|
|
|
$meta .= '<script type="text/javascript" src="'.$CFG->wwwroot.'/mod/data/js.php?d='.$data->id.'"></script>';
|
|
|
|
}
|
|
|
|
|
2006-12-13 20:26:11 +00:00
|
|
|
|
2006-03-03 08:06:50 +00:00
|
|
|
/// Print the page header
|
2006-03-29 18:29:16 +00:00
|
|
|
$PAGE->print_header($course->shortname.': %fullname%', '', $meta);
|
2006-12-13 20:26:11 +00:00
|
|
|
|
NEW MODULE FROM MOODLE.COM - DATABASE !
Finally, we have an early version good enough for everyone to
start banging on to help us polish it up and find bugs.
Please take a look and file bugs in the bug tracker under "Database module".
We urgently need
- new icons for existing field types
- testing on PostgreSQL install
Coming soon (?):
- Many more field types: calculation, checkbox, relation, date, datetime,
time, email, group, list, user, number, richtext
(Please let us know if you are interested in developing any of these)
- A way to save and restore "presets", which are field/template sets
- Backup/Restore support
- Groups Support
- RSS support
Many thanks to Yu for all the hard work under my whip.
2005-12-02 07:50:26 +00:00
|
|
|
|
2006-04-05 08:19:09 +00:00
|
|
|
/// If we have blocks, then print the left side here
|
|
|
|
if (!empty($CFG->showblocksonmodpages)) {
|
|
|
|
echo '<table id="layout-table"><tr>';
|
|
|
|
if ((blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $PAGE->user_is_editing())) {
|
|
|
|
echo '<td style="width: '.$blocks_preferred_width.'px;" id="left-column">';
|
2007-11-23 16:49:51 +00:00
|
|
|
print_container_start();
|
2006-04-05 08:19:09 +00:00
|
|
|
blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
|
2007-11-23 16:49:51 +00:00
|
|
|
print_container_end();
|
2006-04-05 08:19:09 +00:00
|
|
|
echo '</td>';
|
|
|
|
}
|
|
|
|
echo '<td id="middle-column">';
|
2007-11-23 16:49:51 +00:00
|
|
|
print_container_start();
|
NEW MODULE FROM MOODLE.COM - DATABASE !
Finally, we have an early version good enough for everyone to
start banging on to help us polish it up and find bugs.
Please take a look and file bugs in the bug tracker under "Database module".
We urgently need
- new icons for existing field types
- testing on PostgreSQL install
Coming soon (?):
- Many more field types: calculation, checkbox, relation, date, datetime,
time, email, group, list, user, number, richtext
(Please let us know if you are interested in developing any of these)
- A way to save and restore "presets", which are field/template sets
- Backup/Restore support
- Groups Support
- RSS support
Many thanks to Yu for all the hard work under my whip.
2005-12-02 07:50:26 +00:00
|
|
|
}
|
|
|
|
|
2007-07-05 04:40:48 +00:00
|
|
|
/// Check to see if groups are being used here
|
2007-08-20 10:52:59 +00:00
|
|
|
$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);
|
2007-07-05 04:40:48 +00:00
|
|
|
|
NEW MODULE FROM MOODLE.COM - DATABASE !
Finally, we have an early version good enough for everyone to
start banging on to help us polish it up and find bugs.
Please take a look and file bugs in the bug tracker under "Database module".
We urgently need
- new icons for existing field types
- testing on PostgreSQL install
Coming soon (?):
- Many more field types: calculation, checkbox, relation, date, datetime,
time, email, group, list, user, number, richtext
(Please let us know if you are interested in developing any of these)
- A way to save and restore "presets", which are field/template sets
- Backup/Restore support
- Groups Support
- RSS support
Many thanks to Yu for all the hard work under my whip.
2005-12-02 07:50:26 +00:00
|
|
|
print_heading(format_string($data->name));
|
2006-12-13 20:26:11 +00:00
|
|
|
|
2006-02-13 07:57:54 +00:00
|
|
|
// Do we need to show a link to the RSS feed for the records?
|
2006-04-05 01:38:06 +00:00
|
|
|
if (!empty($CFG->enablerssfeeds) && !empty($CFG->data_enablerssfeeds) && $data->rssarticles > 0) {
|
2006-02-13 07:57:54 +00:00
|
|
|
echo '<div style="float:right;">';
|
2006-03-22 08:32:54 +00:00
|
|
|
rss_print_link($course->id, $USER->id, 'data', $data->id, get_string('rsstype'));
|
2006-02-13 07:57:54 +00:00
|
|
|
echo '</div>';
|
|
|
|
echo '<div style="clear:both;"></div>';
|
|
|
|
}
|
2006-12-13 20:26:11 +00:00
|
|
|
|
2006-04-15 06:02:21 +00:00
|
|
|
if ($data->intro and empty($page) and empty($record) and $mode != 'single') {
|
2007-01-11 08:06:15 +00:00
|
|
|
print_box(format_text($data->intro), 'generalbox', 'intro');
|
2006-02-06 04:17:30 +00:00
|
|
|
}
|
|
|
|
|
2006-03-26 05:03:10 +00:00
|
|
|
/// Delete any requested records
|
|
|
|
|
2008-04-17 08:11:23 +00:00
|
|
|
if ($delete && confirm_sesskey() && (has_capability('mod/data:manageentries', $context) or data_isowner($delete))) {
|
2006-03-29 08:49:28 +00:00
|
|
|
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);
|
|
|
|
}
|
NEW MODULE FROM MOODLE.COM - DATABASE !
Finally, we have an early version good enough for everyone to
start banging on to help us polish it up and find bugs.
Please take a look and file bugs in the bug tracker under "Database module".
We urgently need
- new icons for existing field types
- testing on PostgreSQL install
Coming soon (?):
- Many more field types: calculation, checkbox, relation, date, datetime,
time, email, group, list, user, number, richtext
(Please let us know if you are interested in developing any of these)
- A way to save and restore "presets", which are field/template sets
- Backup/Restore support
- Groups Support
- RSS support
Many thanks to Yu for all the hard work under my whip.
2005-12-02 07:50:26 +00:00
|
|
|
}
|
|
|
|
}
|
2006-03-29 08:49:28 +00:00
|
|
|
delete_records('data_content','recordid', $deleterecord->id);
|
|
|
|
delete_records('data_records','id', $deleterecord->id);
|
2006-03-22 14:31:32 +00:00
|
|
|
|
2006-03-29 08:49:28 +00:00
|
|
|
add_to_log($course->id, 'data', 'record delete', "view.php?id=$cm->id", $data->id, $cm->id);
|
2006-03-22 14:31:32 +00:00
|
|
|
|
2006-03-29 08:49:28 +00:00
|
|
|
notify(get_string('recorddeleted','data'), 'notifysuccess');
|
|
|
|
}
|
NEW MODULE FROM MOODLE.COM - DATABASE !
Finally, we have an early version good enough for everyone to
start banging on to help us polish it up and find bugs.
Please take a look and file bugs in the bug tracker under "Database module".
We urgently need
- new icons for existing field types
- testing on PostgreSQL install
Coming soon (?):
- Many more field types: calculation, checkbox, relation, date, datetime,
time, email, group, list, user, number, richtext
(Please let us know if you are interested in developing any of these)
- A way to save and restore "presets", which are field/template sets
- Backup/Restore support
- Groups Support
- RSS support
Many thanks to Yu for all the hard work under my whip.
2005-12-02 07:50:26 +00:00
|
|
|
}
|
2006-03-29 08:49:28 +00:00
|
|
|
|
|
|
|
} else { // Print a confirmation page
|
2006-04-05 01:38:06 +00:00
|
|
|
if ($deleterecord = get_record('data_records', 'id', $delete)) { // Need to check this is valid
|
|
|
|
if ($deleterecord->dataid == $data->id) { // Must be from this database
|
2006-12-13 20:26:11 +00:00
|
|
|
notice_yesno(get_string('confirmdeleterecord','data'),
|
2006-04-05 01:38:06 +00:00
|
|
|
'view.php?d='.$data->id.'&delete='.$delete.'&confirm=1&sesskey='.sesskey(),
|
|
|
|
'view.php?d='.$data->id);
|
2006-03-29 08:49:28 +00:00
|
|
|
|
2006-04-05 01:38:06 +00:00
|
|
|
$records[] = $deleterecord;
|
2006-04-15 02:41:27 +00:00
|
|
|
echo data_print_template('singletemplate', $records, $data, '', 0, true);
|
2006-04-05 01:38:06 +00:00
|
|
|
|
|
|
|
print_footer($course);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Print the tabs
|
|
|
|
|
|
|
|
if ($record or $mode == 'single') {
|
|
|
|
$currenttab = 'single';
|
2007-02-26 06:56:05 +00:00
|
|
|
} elseif($mode == 'asearch') {
|
|
|
|
$currenttab = 'asearch';
|
|
|
|
}
|
|
|
|
else {
|
2006-04-05 01:38:06 +00:00
|
|
|
$currenttab = 'list';
|
|
|
|
}
|
2006-12-13 20:26:11 +00:00
|
|
|
include('tabs.php');
|
2006-04-05 01:38:06 +00:00
|
|
|
|
2008-04-19 15:33:06 +00:00
|
|
|
if ($mode == 'asearch') {
|
|
|
|
$maxcount = 0;
|
|
|
|
|
|
|
|
} else {
|
2007-02-26 06:56:05 +00:00
|
|
|
/// Approve any requested records
|
2006-04-05 01:38:06 +00:00
|
|
|
|
2008-04-19 20:48:48 +00:00
|
|
|
$approvecap = has_capability('mod/data:approve', $context);
|
|
|
|
|
|
|
|
if ($approve && confirm_sesskey() && $approvecap) {
|
2007-02-26 06:56:05 +00:00
|
|
|
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');
|
|
|
|
}
|
2006-04-05 01:38:06 +00:00
|
|
|
}
|
|
|
|
}
|
NEW MODULE FROM MOODLE.COM - DATABASE !
Finally, we have an early version good enough for everyone to
start banging on to help us polish it up and find bugs.
Please take a look and file bugs in the bug tracker under "Database module".
We urgently need
- new icons for existing field types
- testing on PostgreSQL install
Coming soon (?):
- Many more field types: calculation, checkbox, relation, date, datetime,
time, email, group, list, user, number, richtext
(Please let us know if you are interested in developing any of these)
- A way to save and restore "presets", which are field/template sets
- Backup/Restore support
- Groups Support
- RSS support
Many thanks to Yu for all the hard work under my whip.
2005-12-02 07:50:26 +00:00
|
|
|
}
|
2008-02-12 16:04:57 +00:00
|
|
|
|
2008-04-19 15:33:06 +00:00
|
|
|
// Check the number of entries required against the number of entries already made (doesn't apply to teachers)
|
|
|
|
$requiredentries_allowed = true;
|
|
|
|
$numentries = data_numentries($data);
|
|
|
|
if ($data->requiredentries > 0 && $numentries < $data->requiredentries && !has_capability('mod/data:manageentries', $context)) {
|
|
|
|
$data->entriesleft = $data->requiredentries - $numentries;
|
|
|
|
$strentrieslefttoadd = get_string('entrieslefttoadd', 'data', $data);
|
|
|
|
notify($strentrieslefttoadd);
|
|
|
|
$requiredentries_allowed = false;
|
|
|
|
}
|
NEW MODULE FROM MOODLE.COM - DATABASE !
Finally, we have an early version good enough for everyone to
start banging on to help us polish it up and find bugs.
Please take a look and file bugs in the bug tracker under "Database module".
We urgently need
- new icons for existing field types
- testing on PostgreSQL install
Coming soon (?):
- Many more field types: calculation, checkbox, relation, date, datetime,
time, email, group, list, user, number, richtext
(Please let us know if you are interested in developing any of these)
- A way to save and restore "presets", which are field/template sets
- Backup/Restore support
- Groups Support
- RSS support
Many thanks to Yu for all the hard work under my whip.
2005-12-02 07:50:26 +00:00
|
|
|
|
2008-04-19 20:48:48 +00:00
|
|
|
/// setup group and approve restrictions
|
|
|
|
if (!$approvecap && $data->approval) {
|
2007-02-26 06:56:05 +00:00
|
|
|
if (isloggedin()) {
|
|
|
|
$approveselect = ' AND (r.approved=1 OR r.userid='.$USER->id.') ';
|
|
|
|
} else {
|
|
|
|
$approveselect = ' AND r.approved=1 ';
|
|
|
|
}
|
2006-03-27 09:50:23 +00:00
|
|
|
} else {
|
2007-02-26 06:56:05 +00:00
|
|
|
$approveselect = ' ';
|
2006-03-27 09:50:23 +00:00
|
|
|
}
|
NEW MODULE FROM MOODLE.COM - DATABASE !
Finally, we have an early version good enough for everyone to
start banging on to help us polish it up and find bugs.
Please take a look and file bugs in the bug tracker under "Database module".
We urgently need
- new icons for existing field types
- testing on PostgreSQL install
Coming soon (?):
- Many more field types: calculation, checkbox, relation, date, datetime,
time, email, group, list, user, number, richtext
(Please let us know if you are interested in developing any of these)
- A way to save and restore "presets", which are field/template sets
- Backup/Restore support
- Groups Support
- RSS support
Many thanks to Yu for all the hard work under my whip.
2005-12-02 07:50:26 +00:00
|
|
|
|
2007-02-26 06:56:05 +00:00
|
|
|
if ($currentgroup) {
|
|
|
|
$groupselect = " AND (r.groupid = '$currentgroup' OR r.groupid = 0)";
|
2006-04-05 01:38:06 +00:00
|
|
|
} else {
|
2007-02-26 06:56:05 +00:00
|
|
|
$groupselect = ' ';
|
2006-04-05 01:38:06 +00:00
|
|
|
}
|
2006-03-29 08:49:28 +00:00
|
|
|
|
2008-04-16 18:57:15 +00:00
|
|
|
$ilike = sql_ilike(); //Be case-insensitive
|
|
|
|
|
2007-02-26 06:56:05 +00:00
|
|
|
/// Find the field we are sorting on
|
2008-04-19 20:48:48 +00:00
|
|
|
if ($sort <= 0) {
|
|
|
|
|
|
|
|
switch ($sort) {
|
|
|
|
case DATA_LASTNAME:
|
|
|
|
$ordering = "u.lastname $order, u.firstname $order";
|
|
|
|
break;
|
|
|
|
case DATA_FIRSTNAME:
|
|
|
|
$ordering = "u.firstname $order, u.lastname $order";
|
|
|
|
break;
|
|
|
|
case DATA_APPROVED:
|
|
|
|
$ordering = "r.approved $order, r.timecreated $order";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$ordering = "r.timecreated $order";
|
2008-04-16 11:51:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$what = ' DISTINCT r.id, r.approved, r.timecreated, r.timemodified, r.userid, u.firstname, u.lastname';
|
|
|
|
$count = ' COUNT(DISTINCT c.recordid) ';
|
|
|
|
$tables = $CFG->prefix.'data_content c,'.$CFG->prefix.'data_records r,'.$CFG->prefix.'data_content cs, '.$CFG->prefix.'user u ';
|
|
|
|
$where = 'WHERE c.recordid = r.id
|
|
|
|
AND r.dataid = '.$data->id.'
|
|
|
|
AND r.userid = u.id
|
|
|
|
AND cs.recordid = r.id ';
|
|
|
|
$sortorder = ' ORDER BY '.$ordering.', r.id ASC ';
|
|
|
|
$searchselect = '';
|
|
|
|
|
|
|
|
// If requiredentries is not reached, only show current user's entries
|
|
|
|
if (!$requiredentries_allowed) {
|
|
|
|
$where .= ' AND u.id = ' . $USER->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($advanced)) { //If advanced box is checked.
|
|
|
|
foreach($search_array as $key => $val) { //what does $search_array hold?
|
|
|
|
if ($key == DATA_FIRSTNAME or $key == DATA_LASTNAME) {
|
2008-04-16 18:57:15 +00:00
|
|
|
$searchselect .= " AND $val->field $ilike '%{$val->data}%'";
|
2008-04-16 11:51:50 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$tables .= ', '.$CFG->prefix.'data_content c'.$key.' ';
|
|
|
|
$where .= ' AND c'.$key.'.recordid = r.id';
|
|
|
|
$searchselect .= ' AND ('.$val->sql.') ';
|
|
|
|
}
|
|
|
|
} else if ($search) {
|
|
|
|
$searchselect = " AND (cs.content $ilike '%$search%' OR u.firstname $ilike '%$search%' OR u.lastname $ilike '%$search%' ) ";
|
|
|
|
} else {
|
|
|
|
$searchselect = ' ';
|
|
|
|
}
|
|
|
|
|
2008-04-16 15:08:03 +00:00
|
|
|
} else if ($sort > 0 and $sortfield = data_get_field_from_id($sort, $data)) {
|
2007-02-26 06:56:05 +00:00
|
|
|
|
|
|
|
$sortcontent = $sortfield->get_sort_field();
|
|
|
|
$sortcontentfull = $sortfield->get_sort_sql('c.'.$sortcontent);
|
2008-04-16 11:51:50 +00:00
|
|
|
|
|
|
|
$what = ' DISTINCT r.id, r.approved, r.timecreated, r.timemodified, r.userid, u.firstname, u.lastname, c.'.$sortcontent.', '.$sortcontentfull.' AS _order ';
|
2007-02-26 06:56:05 +00:00
|
|
|
$count = ' COUNT(DISTINCT c.recordid) ';
|
2008-04-16 11:51:50 +00:00
|
|
|
$tables = $CFG->prefix.'data_content c,'.$CFG->prefix.'data_records r,'.$CFG->prefix.'data_content cs, '.$CFG->prefix.'user u ';
|
2007-02-26 06:56:05 +00:00
|
|
|
$where = 'WHERE c.recordid = r.id
|
|
|
|
AND c.fieldid = '.$sort.'
|
|
|
|
AND r.dataid = '.$data->id.'
|
|
|
|
AND r.userid = u.id
|
2008-04-16 11:51:50 +00:00
|
|
|
AND cs.recordid = r.id ';
|
2007-04-18 02:11:09 +00:00
|
|
|
$sortorder = ' ORDER BY _order '.$order.' , r.id ASC ';
|
2007-02-26 06:56:05 +00:00
|
|
|
$searchselect = '';
|
2008-04-16 11:51:50 +00:00
|
|
|
|
2008-02-12 16:04:57 +00:00
|
|
|
// If requiredentries is not reached, only show current user's entries
|
|
|
|
if (!$requiredentries_allowed) {
|
|
|
|
$where .= ' AND u.id = ' . $USER->id;
|
|
|
|
}
|
2008-04-16 11:51:50 +00:00
|
|
|
|
|
|
|
if (!empty($advanced)) { //If advanced box is checked.
|
|
|
|
foreach($search_array as $key => $val) { //what does $search_array hold?
|
|
|
|
if ($key == DATA_FIRSTNAME or $key == DATA_LASTNAME) {
|
2008-04-16 18:57:15 +00:00
|
|
|
$searchselect .= " AND $val->field $ilike '%{$val->data}%'";
|
2008-04-16 11:51:50 +00:00
|
|
|
continue;
|
|
|
|
}
|
2007-02-26 06:56:05 +00:00
|
|
|
$tables .= ', '.$CFG->prefix.'data_content c'.$key.' ';
|
|
|
|
$where .= ' AND c'.$key.'.recordid = r.id';
|
|
|
|
$searchselect .= ' AND ('.$val->sql.') ';
|
|
|
|
}
|
2008-04-16 11:51:50 +00:00
|
|
|
} else if ($search) {
|
|
|
|
$searchselect = " AND (cs.content $ilike '%$search%' OR u.firstname $ilike '%$search%' OR u.lastname $ilike '%$search%' ) ";
|
2007-02-26 06:56:05 +00:00
|
|
|
} else {
|
|
|
|
$searchselect = ' ';
|
2008-04-16 11:51:50 +00:00
|
|
|
}
|
|
|
|
|
2007-02-26 06:56:05 +00:00
|
|
|
} else if ($search) {
|
2008-04-16 11:51:50 +00:00
|
|
|
$what = ' DISTINCT r.id, r.approved, r.timecreated, r.timemodified, r.userid, u.firstname, u.lastname ';
|
2007-02-26 06:56:05 +00:00
|
|
|
$count = ' COUNT(DISTINCT c.recordid) ';
|
|
|
|
$tables = $CFG->prefix.'data_content c,'.$CFG->prefix.'data_records r, '.$CFG->prefix.'user u ';
|
|
|
|
$where = 'WHERE c.recordid = r.id
|
|
|
|
AND r.userid = u.id
|
|
|
|
AND r.dataid = '.$data->id;
|
|
|
|
$sortorder = ' ORDER BY r.id ASC ';
|
|
|
|
$searchselect = '';
|
2008-04-16 11:51:50 +00:00
|
|
|
|
2008-02-12 16:04:57 +00:00
|
|
|
// If requiredentries is not reached, only show current user's entries
|
|
|
|
if (!$requiredentries_allowed) {
|
|
|
|
$where .= ' AND u.id = ' . $USER->id;
|
|
|
|
}
|
2008-04-16 11:51:50 +00:00
|
|
|
|
2007-02-26 06:56:05 +00:00
|
|
|
if (!empty($advanced)) { //Advanced search box again.
|
|
|
|
foreach($search_array as $key => $val) {
|
2008-04-16 11:51:50 +00:00
|
|
|
if ($key == DATA_FIRSTNAME or $key == DATA_LASTNAME) {
|
2008-04-16 18:57:15 +00:00
|
|
|
$searchselect .= " AND $val->field $ilike '%{$val->data}%'";
|
2008-04-16 11:51:50 +00:00
|
|
|
continue;
|
|
|
|
}
|
2007-02-26 06:56:05 +00:00
|
|
|
$tables .= ', '.$CFG->prefix.'data_content c'.$key.' ';
|
|
|
|
$where .= ' AND c'.$key.'.recordid = r.id ';
|
|
|
|
$searchselect .= ' AND ('.$val->sql.') ';
|
|
|
|
}
|
2008-04-16 11:51:50 +00:00
|
|
|
} else {
|
|
|
|
$searchselect = " AND (c.content $ilike '%$search%' OR u.firstname $ilike '%$search%' OR u.lastname $ilike '%$search%' ) ";
|
2007-02-26 06:56:05 +00:00
|
|
|
}
|
2006-03-29 08:49:28 +00:00
|
|
|
|
2008-04-16 11:51:50 +00:00
|
|
|
|
2007-02-26 06:56:05 +00:00
|
|
|
} else {
|
2008-04-11 02:34:11 +00:00
|
|
|
$what = ' DISTINCT r.id, r.approved, r.timecreated, r.timemodified, r.userid, u.firstname, u.lastname ';
|
2007-02-26 06:56:05 +00:00
|
|
|
$count = ' COUNT(r.id) ';
|
|
|
|
$tables = $CFG->prefix.'data_records r, '.$CFG->prefix.'user u ';
|
|
|
|
$where = 'WHERE r.dataid = '.$data->id. ' AND r.userid = u.id ';
|
|
|
|
$sortorder = ' ORDER BY r.timecreated '.$order. ' ';
|
|
|
|
$searchselect = ' ';
|
2008-04-16 11:51:50 +00:00
|
|
|
|
2008-02-12 16:04:57 +00:00
|
|
|
// If requiredentries is not reached, only show current user's entries
|
|
|
|
if (!$requiredentries_allowed) {
|
|
|
|
$where .= ' AND u.id = ' . $USER->id;
|
|
|
|
}
|
2007-02-26 06:56:05 +00:00
|
|
|
}
|
NEW MODULE FROM MOODLE.COM - DATABASE !
Finally, we have an early version good enough for everyone to
start banging on to help us polish it up and find bugs.
Please take a look and file bugs in the bug tracker under "Database module".
We urgently need
- new icons for existing field types
- testing on PostgreSQL install
Coming soon (?):
- Many more field types: calculation, checkbox, relation, date, datetime,
time, email, group, list, user, number, richtext
(Please let us know if you are interested in developing any of these)
- A way to save and restore "presets", which are field/template sets
- Backup/Restore support
- Groups Support
- RSS support
Many thanks to Yu for all the hard work under my whip.
2005-12-02 07:50:26 +00:00
|
|
|
|
2006-04-05 01:38:06 +00:00
|
|
|
|
2007-02-26 06:56:05 +00:00
|
|
|
/// To actually fetch the records
|
2006-03-29 08:49:28 +00:00
|
|
|
|
2008-04-19 15:33:06 +00:00
|
|
|
$fromsql = "FROM $tables $where $groupselect $approveselect $searchselect";
|
|
|
|
$sqlselect = "SELECT $what $fromsql $sortorder";
|
|
|
|
$sqlcount = "SELECT $count $fromsql"; // Total number of records when searching
|
2008-04-19 21:02:10 +00:00
|
|
|
$sqlrids = "SELECT tmp.id FROM ($sqlselect) tmp";
|
2008-04-19 15:33:06 +00:00
|
|
|
$sqlmax = "SELECT $count FROM $tables $where $groupselect $approveselect"; // number of all recoirds user may see
|
2006-03-29 08:49:28 +00:00
|
|
|
|
2008-04-19 15:33:06 +00:00
|
|
|
/// Work out the paging numbers and counts
|
2006-03-29 08:49:28 +00:00
|
|
|
|
2007-02-26 06:56:05 +00:00
|
|
|
$totalcount = count_records_sql($sqlcount);
|
2008-04-19 15:33:06 +00:00
|
|
|
if (empty($searchselect)) {
|
|
|
|
$maxcount = $totalcount;
|
|
|
|
} else {
|
|
|
|
$maxcount = count_records_sql($sqlmax);
|
|
|
|
}
|
NEW MODULE FROM MOODLE.COM - DATABASE !
Finally, we have an early version good enough for everyone to
start banging on to help us polish it up and find bugs.
Please take a look and file bugs in the bug tracker under "Database module".
We urgently need
- new icons for existing field types
- testing on PostgreSQL install
Coming soon (?):
- Many more field types: calculation, checkbox, relation, date, datetime,
time, email, group, list, user, number, richtext
(Please let us know if you are interested in developing any of these)
- A way to save and restore "presets", which are field/template sets
- Backup/Restore support
- Groups Support
- RSS support
Many thanks to Yu for all the hard work under my whip.
2005-12-02 07:50:26 +00:00
|
|
|
|
2007-02-26 06:56:05 +00:00
|
|
|
if ($record) { // We need to just show one, so where is it in context?
|
|
|
|
$nowperpage = 1;
|
|
|
|
$mode = 'single';
|
2006-04-13 01:34:26 +00:00
|
|
|
|
2007-02-26 06:56:05 +00:00
|
|
|
$page = 0;
|
2008-04-19 21:02:10 +00:00
|
|
|
if ($allrecordids = get_records_sql($sqlrids)) {
|
|
|
|
$allrecordids = array_keys($allrecordids);
|
|
|
|
$page = (int)array_search($record->id, $allrecordids);
|
|
|
|
unset($allrecordids);
|
2006-03-29 08:49:28 +00:00
|
|
|
}
|
|
|
|
|
2007-02-26 06:56:05 +00:00
|
|
|
} else if ($mode == 'single') { // We rely on ambient $page settings
|
|
|
|
$nowperpage = 1;
|
2006-03-29 08:49:28 +00:00
|
|
|
|
2007-02-26 06:56:05 +00:00
|
|
|
} else {
|
|
|
|
$nowperpage = $perpage;
|
|
|
|
}
|
2006-03-29 08:49:28 +00:00
|
|
|
|
2007-02-26 06:56:05 +00:00
|
|
|
/// Get the actual records
|
|
|
|
|
2008-04-19 15:33:06 +00:00
|
|
|
if (!$records = get_records_sql($sqlselect, $page * $nowperpage, $nowperpage)) {
|
|
|
|
// Nothing to show!
|
2007-02-26 06:56:05 +00:00
|
|
|
if ($record) { // Something was requested so try to show that at least (bug 5132)
|
|
|
|
if (has_capability('mod/data:manageentries', $context) || empty($data->approval) ||
|
|
|
|
$record->approved || (isloggedin() && $record->userid == $USER->id)) {
|
|
|
|
if (!$currentgroup || $record->groupid == $currentgroup || $record->groupid == 0) {
|
2008-04-19 15:33:06 +00:00
|
|
|
// OK, we can show this one
|
|
|
|
$records = array($record->id => $record);
|
|
|
|
$totalcount = 1;
|
2007-02-26 06:56:05 +00:00
|
|
|
}
|
2006-04-08 16:33:16 +00:00
|
|
|
}
|
|
|
|
}
|
2008-04-19 15:33:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($records)) {
|
|
|
|
if ($maxcount){
|
|
|
|
$a = new object();
|
|
|
|
$a->max = $maxcount;
|
|
|
|
$a->reseturl = "view.php?id=$cm->id&mode=$mode&search=&advanced=0";
|
|
|
|
notify(get_string('foundnorecords','data', $a));
|
2007-02-26 06:56:05 +00:00
|
|
|
} else {
|
|
|
|
notify(get_string('norecords','data'));
|
|
|
|
}
|
2006-02-03 08:11:36 +00:00
|
|
|
|
2008-04-19 15:33:06 +00:00
|
|
|
} else { // We have some records to print
|
|
|
|
|
|
|
|
if ($maxcount != $totalcount) {
|
|
|
|
$a = new object();
|
|
|
|
$a->num = $totalcount;
|
|
|
|
$a->max = $maxcount;
|
|
|
|
$a->reseturl = "view.php?id=$cm->id&mode=$mode&search=&advanced=0";
|
|
|
|
notify(get_string('foundrecords', 'data', $a), 'notifysuccess');
|
|
|
|
}
|
2005-12-05 08:56:48 +00:00
|
|
|
|
2007-02-26 06:56:05 +00:00
|
|
|
if ($mode == 'single') { // Single template
|
|
|
|
$baseurl = 'view.php?d='.$data->id.'&mode=single&';
|
NEW MODULE FROM MOODLE.COM - DATABASE !
Finally, we have an early version good enough for everyone to
start banging on to help us polish it up and find bugs.
Please take a look and file bugs in the bug tracker under "Database module".
We urgently need
- new icons for existing field types
- testing on PostgreSQL install
Coming soon (?):
- Many more field types: calculation, checkbox, relation, date, datetime,
time, email, group, list, user, number, richtext
(Please let us know if you are interested in developing any of these)
- A way to save and restore "presets", which are field/template sets
- Backup/Restore support
- Groups Support
- RSS support
Many thanks to Yu for all the hard work under my whip.
2005-12-02 07:50:26 +00:00
|
|
|
|
2007-02-26 06:56:05 +00:00
|
|
|
print_paging_bar($totalcount, $page, $nowperpage, $baseurl, $pagevar='page');
|
2006-03-29 08:49:28 +00:00
|
|
|
|
2007-02-26 06:56:05 +00:00
|
|
|
if (empty($data->singletemplate)){
|
|
|
|
notify(get_string('nosingletemplate','data'));
|
|
|
|
data_generate_default_template($data, 'singletemplate', 0, false, false);
|
|
|
|
}
|
NEW MODULE FROM MOODLE.COM - DATABASE !
Finally, we have an early version good enough for everyone to
start banging on to help us polish it up and find bugs.
Please take a look and file bugs in the bug tracker under "Database module".
We urgently need
- new icons for existing field types
- testing on PostgreSQL install
Coming soon (?):
- Many more field types: calculation, checkbox, relation, date, datetime,
time, email, group, list, user, number, richtext
(Please let us know if you are interested in developing any of these)
- A way to save and restore "presets", which are field/template sets
- Backup/Restore support
- Groups Support
- RSS support
Many thanks to Yu for all the hard work under my whip.
2005-12-02 07:50:26 +00:00
|
|
|
|
2007-02-26 06:56:05 +00:00
|
|
|
data_print_template('singletemplate', $records, $data, $search, $page);
|
2006-03-29 08:49:28 +00:00
|
|
|
|
2007-02-26 06:56:05 +00:00
|
|
|
print_paging_bar($totalcount, $page, $nowperpage, $baseurl, $pagevar='page');
|
2006-03-29 08:49:28 +00:00
|
|
|
|
2007-02-26 06:56:05 +00:00
|
|
|
} else { // List template
|
|
|
|
$baseurl = 'view.php?d='.$data->id.'&';
|
|
|
|
//send the advanced flag through the URL so it is remembered while paging.
|
|
|
|
$baseurl .= 'advanced='.$advanced.'&';
|
|
|
|
//pass variable to allow determining whether or not we are paging through results.
|
|
|
|
$baseurl .= 'paging='.$paging.'&';
|
2006-03-29 08:49:28 +00:00
|
|
|
|
2007-02-26 06:56:05 +00:00
|
|
|
print_paging_bar($totalcount, $page, $nowperpage, $baseurl, $pagevar='page');
|
2006-03-29 08:49:28 +00:00
|
|
|
|
2007-02-26 06:56:05 +00:00
|
|
|
if (empty($data->listtemplate)){
|
|
|
|
notify(get_string('nolisttemplate','data'));
|
|
|
|
data_generate_default_template($data, 'listtemplate', 0, false, false);
|
|
|
|
}
|
|
|
|
echo $data->listtemplateheader;
|
|
|
|
data_print_template('listtemplate', $records, $data, $search, $page);
|
|
|
|
echo $data->listtemplatefooter;
|
|
|
|
|
|
|
|
print_paging_bar($totalcount, $page, $nowperpage, $baseurl, $pagevar='page');
|
2006-03-29 08:49:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2007-02-26 06:56:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$search = trim($search);
|
|
|
|
if (empty($records)) {
|
|
|
|
$records = array();
|
2006-04-13 10:41:12 +00:00
|
|
|
}
|
|
|
|
|
2007-02-26 06:56:05 +00:00
|
|
|
//Advanced search form doesn't make sense for single (redirects list view)
|
2008-04-19 15:33:06 +00:00
|
|
|
if (($maxcount || $mode == 'asearch') && $mode != 'single') {
|
2007-02-26 06:56:05 +00:00
|
|
|
data_print_preference_form($data, $perpage, $search, $sort, $order, $search_array, $advanced, $mode);
|
2006-04-05 01:38:06 +00:00
|
|
|
}
|
NEW MODULE FROM MOODLE.COM - DATABASE !
Finally, we have an early version good enough for everyone to
start banging on to help us polish it up and find bugs.
Please take a look and file bugs in the bug tracker under "Database module".
We urgently need
- new icons for existing field types
- testing on PostgreSQL install
Coming soon (?):
- Many more field types: calculation, checkbox, relation, date, datetime,
time, email, group, list, user, number, richtext
(Please let us know if you are interested in developing any of these)
- A way to save and restore "presets", which are field/template sets
- Backup/Restore support
- Groups Support
- RSS support
Many thanks to Yu for all the hard work under my whip.
2005-12-02 07:50:26 +00:00
|
|
|
|
2006-04-05 08:19:09 +00:00
|
|
|
/// If we have blocks, then print the left side here
|
|
|
|
if (!empty($CFG->showblocksonmodpages)) {
|
2007-11-23 16:49:51 +00:00
|
|
|
print_container_end();
|
2006-04-05 08:19:09 +00:00
|
|
|
echo '</td>'; // Middle column
|
|
|
|
if ((blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $PAGE->user_is_editing())) {
|
|
|
|
echo '<td style="width: '.$blocks_preferred_width.'px;" id="right-column">';
|
2007-11-23 16:49:51 +00:00
|
|
|
print_container_start();
|
2006-04-05 08:19:09 +00:00
|
|
|
blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
|
2007-11-23 16:49:51 +00:00
|
|
|
print_container_end();
|
2006-04-05 08:19:09 +00:00
|
|
|
echo '</td>';
|
|
|
|
}
|
2007-03-05 05:04:02 +00:00
|
|
|
echo '</tr></table>';
|
2006-04-05 08:19:09 +00:00
|
|
|
}
|
|
|
|
|
2006-03-29 08:49:28 +00:00
|
|
|
print_footer($course);
|
2006-03-22 08:07:26 +00:00
|
|
|
?>
|