2009-11-01 14:55:15 +00:00
< ? 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
///////////////////////////////////////////////////////////////////////////
// //
// 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 //
// //
///////////////////////////////////////////////////////////////////////////
2016-02-26 17:47:58 +11:00
require_once ( __DIR__ . '/../../config.php' );
2009-05-06 09:26:46 +00:00
require_once ( $CFG -> dirroot . '/mod/data/lib.php' );
require_once ( $CFG -> libdir . '/rsslib.php' );
2009-05-08 09:00:41 +00:00
require_once ( $CFG -> libdir . '/completionlib.php' );
2007-11-23 16:49:51 +00:00
2006-03-29 08:49:28 +00:00
/// One of these is necessary!
2008-10-24 20:17:10 +00:00
$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
2006-03-29 08:49:28 +00:00
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
2013-08-08 19:15:11 +01:00
$disapprove = optional_param ( 'disapprove' , 0 , PARAM_INT ); // disapproval recordid
2006-03-26 05:03:10 +00:00
$delete = optional_param ( 'delete' , 0 , PARAM_INT ); //delete recordid
2013-07-22 16:19:08 +08:00
$multidelete = optional_param_array ( 'delcheck' , null , PARAM_INT );
$serialdelete = optional_param ( 'serialdelete' , null , PARAM_RAW );
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-06-25 14:52:39 +00:00
print_error ( 'invalidcoursemodule' );
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-06-06 07:36:17 +00:00
if ( ! $course = $DB -> get_record ( 'course' , array ( 'id' => $cm -> course ))) {
2008-06-25 14:52:39 +00:00
print_error ( 'coursemisconf' );
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-06-06 07:36:17 +00:00
if ( ! $data = $DB -> get_record ( 'data' , array ( 'id' => $cm -> instance ))) {
2008-06-25 14:52:39 +00:00
print_error ( 'invalidcoursemodule' );
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 ) {
2008-06-06 07:36:17 +00:00
if ( ! $record = $DB -> get_record ( 'data_records' , array ( 'id' => $rid ))) {
2008-06-25 14:52:39 +00:00
print_error ( 'invalidrecord' , 'data' );
2006-03-29 08:49:28 +00:00
}
2008-06-06 07:36:17 +00:00
if ( ! $data = $DB -> get_record ( 'data' , array ( 'id' => $record -> dataid ))) {
2008-06-25 14:52:39 +00:00
print_error ( 'invalidid' , 'data' );
2006-03-29 08:49:28 +00:00
}
2008-06-06 07:36:17 +00:00
if ( ! $course = $DB -> get_record ( 'course' , array ( 'id' => $data -> course ))) {
2008-06-25 14:52:39 +00:00
print_error ( 'coursemisconf' );
2006-03-29 08:49:28 +00:00
}
if ( ! $cm = get_coursemodule_from_instance ( 'data' , $data -> id , $course -> id )) {
2008-06-25 14:52:39 +00:00
print_error ( 'invalidcoursemodule' );
2006-03-29 08:49:28 +00:00
}
} else { // We must have $d
2008-06-06 07:36:17 +00:00
if ( ! $data = $DB -> get_record ( 'data' , array ( 'id' => $d ))) {
2008-06-25 14:52:39 +00:00
print_error ( 'invalidid' , 'data' );
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-06-06 07:36:17 +00:00
if ( ! $course = $DB -> get_record ( 'course' , array ( 'id' => $data -> course ))) {
2008-06-25 14:52:39 +00:00
print_error ( 'coursemisconf' );
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-06-25 14:52:39 +00:00
print_error ( 'invalidcoursemodule' );
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
2010-03-15 07:59:28 +00:00
require_once ( $CFG -> dirroot . '/comment/lib.php' );
comment :: init ();
2009-11-18 06:00:48 +00:00
2012-07-26 13:57:56 +08:00
$context = context_module :: instance ( $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 )) {
2008-06-06 07:36:17 +00:00
if ( ! $DB -> record_exists ( 'data_fields' , array ( '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 ();
2008-06-06 07:36:17 +00:00
$fields = $DB -> get_records ( 'data_fields' , array ( 'dataid' => $data -> id ));
2008-09-14 08:22:44 +00:00
2007-02-26 06:56:05 +00:00
//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).
2008-09-14 08:22:44 +00:00
//A false $paging flag generates advanced search results based on the fields input by the user.
2007-02-26 06:56:05 +00:00
//A true $paging flag generates davanced search results from the $SESSION global.
2008-09-14 08:22:44 +00:00
2007-02-26 06:56:05 +00:00
$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 ) {
2009-03-25 01:49:52 +00:00
$searchfield = data_get_field_from_id ( $field -> id , $data );
2007-02-26 06:56:05 +00:00
//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 )) {
2010-09-21 08:37:36 +00:00
$search_array [ $field -> id ] = new stdClass ();
2008-06-06 08:39:44 +00:00
list ( $search_array [ $field -> id ] -> sql , $search_array [ $field -> id ] -> params ) = $searchfield -> generate_sql ( 'c' . $field -> id , $val );
2008-04-16 11:51:50 +00:00
$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 )) {
2010-09-21 08:37:36 +00:00
$search_array [ DATA_FIRSTNAME ] = new stdClass ();
2008-06-06 08:39:44 +00:00
$search_array [ DATA_FIRSTNAME ] -> sql = '' ;
$search_array [ DATA_FIRSTNAME ] -> params = array ();
$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 )) {
2010-09-21 08:37:36 +00:00
$search_array [ DATA_LASTNAME ] = new stdClass ();
2008-06-06 08:39:44 +00:00
$search_array [ DATA_LASTNAME ] -> sql = '' ;
2010-10-12 06:46:55 +00:00
$search_array [ DATA_LASTNAME ] -> params = array ();
2008-06-06 08:39:44 +00:00
$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 ;
}
2008-10-24 20:17:10 +00:00
// Disable search filters if $filter is not true:
2008-11-18 00:10:13 +00:00
if ( ! $filter ) {
$search = '' ;
}
2008-10-24 20:17:10 +00:00
2013-08-06 20:58:28 +02:00
if ( core_text :: strlen ( $search ) < 2 ) {
2006-12-13 09:38:46 +00:00
$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 );
}
2014-02-09 14:45:47 -08:00
$params = array (
'context' => $context ,
'objectid' => $data -> id
);
$event = \mod_data\event\course_module_viewed :: create ( $params );
2014-02-25 11:43:13 +08:00
$event -> add_record_snapshot ( 'course_modules' , $cm );
$event -> add_record_snapshot ( 'course' , $course );
2014-02-09 14:45:47 -08:00
$event -> add_record_snapshot ( 'data' , $data );
$event -> trigger ();
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
2010-12-05 18:36:44 +00:00
$urlparams = array ( 'd' => $data -> id );
if ( $record ) {
$urlparams [ 'rid' ] = $record -> id ;
}
if ( $page ) {
$urlparams [ 'page' ] = $page ;
}
if ( $mode ) {
$urlparams [ 'mode' ] = $mode ;
}
if ( $filter ) {
$urlparams [ 'filter' ] = $filter ;
}
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
// Initialize $PAGE, compute blocks
2010-12-05 18:36:44 +00:00
$PAGE -> set_url ( '/mod/data/view.php' , $urlparams );
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-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
}
2012-07-26 13:57:56 +08:00
$courseshortname = format_string ( $course -> shortname , true , array ( 'context' => context_course :: instance ( $course -> id )));
2011-09-07 11:46:28 +12: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 ) {
2013-03-08 14:12:16 +08:00
$rsstitle = $courseshortname . ': ' . format_string ( $data -> name );
2010-07-21 02:11:53 +00:00
rss_add_http_header ( $context , 'mod_data' , $data , $rsstitle );
2006-03-29 18:29:16 +00:00
}
if ( $data -> csstemplate ) {
2010-01-18 20:02:13 +00:00
$PAGE -> requires -> css ( '/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 ) {
2010-02-06 14:09:33 +00:00
$PAGE -> requires -> js ( '/mod/data/js.php?d=' . $data -> id , true );
2006-08-17 09:27:51 +00:00
}
2011-04-06 18:05:43 +01:00
// Mark as viewed
$completion = new completion_info ( $course );
$completion -> set_module_viewed ( $cm );
2006-03-03 08:06:50 +00:00
/// Print the page header
2009-05-06 09:29:05 +00:00
// Note: MDL-19010 there will be further changes to printing header and blocks.
// The code will be much nicer than this eventually.
2011-09-07 11:46:28 +12:00
$title = $courseshortname . ': ' . format_string ( $data -> name );
2009-05-06 09:26:46 +00:00
2010-08-06 06:20:28 +00:00
if ( $PAGE -> user_allowed_editing ()) {
2012-10-29 12:18:06 +08:00
// 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' );
}
$url = new moodle_url ( $CFG -> wwwroot . '/mod/data/view.php' , array ( 'id' => $cm -> id , 'edit' => $urlediting ));
$PAGE -> set_button ( $OUTPUT -> single_button ( $url , $strediting ));
2009-05-06 09:26:46 +00:00
}
2006-12-13 20:26:11 +00:00
2009-09-11 03:14:42 +00:00
if ( $mode == 'asearch' ) {
$PAGE -> navbar -> add ( get_string ( 'search' ));
}
2016-10-25 17:22:57 +08:00
$PAGE -> force_settings_menu ();
2009-09-07 05:43:15 +00:00
$PAGE -> set_title ( $title );
$PAGE -> set_heading ( $course -> fullname );
2010-09-03 18:01:25 +00:00
2009-09-07 05:43:15 +00:00
echo $OUTPUT -> header ();
2009-11-01 14:55:15 +00:00
2014-10-29 13:52:29 +08:00
// 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 );
2007-08-20 10:52:59 +00:00
$groupmode = groups_get_activity_groupmode ( $cm );
2013-07-22 16:19:08 +08:00
$canmanageentries = has_capability ( 'mod/data:manageentries' , $context );
2012-10-02 15:52:00 +08:00
// If a student is not part of a group and seperate groups is enabled, we don't
// want them seeing all records.
2013-07-22 16:19:08 +08:00
if ( $currentgroup == 0 && $groupmode == 1 && ! $canmanageentries ) {
2012-10-02 15:52:00 +08:00
$canviewallrecords = false ;
} else {
$canviewallrecords = true ;
}
2007-07-05 04:40:48 +00:00
2010-07-22 06:29:14 +00:00
// detect entries not approved yet and show hint instead of not found error
2013-07-22 16:19:08 +08:00
if ( $record and $data -> approval and ! $record -> approved and $record -> userid != $USER -> id and ! $canmanageentries ) {
2009-09-27 18:08:27 +00:00
if ( ! $currentgroup or $record -> groupid == $currentgroup or $record -> groupid == 0 ) {
print_error ( 'notapproved' , 'data' );
}
}
2013-08-22 12:03:23 +07:00
echo $OUTPUT -> heading ( format_string ( $data -> name ), 2 );
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?
2010-05-13 08:44:35 +00:00
//this links has been Settings (database activity administration) block
/* if ( ! empty ( $CFG -> enablerssfeeds ) && ! empty ( $CFG -> data_enablerssfeeds ) && $data -> rssarticles > 0 ) {
2006-02-13 07:57:54 +00:00
echo '<div style="float:right;">' ;
2010-07-19 10:57:52 +00:00
rss_print_link ( $context -> id , $USER -> id , 'mod_data' , $data -> id , get_string ( 'rsstype' ));
2006-02-13 07:57:54 +00:00
echo '</div>' ;
echo '<div style="clear:both;"></div>' ;
2010-05-13 08:44:35 +00:00
} */
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' ) {
2010-09-21 08:37:36 +00:00
$options = new stdClass ();
2008-04-21 13:26:08 +00:00
$options -> noclean = true ;
2006-02-06 04:17:30 +00:00
}
2013-04-19 15:16:27 +08:00
echo $OUTPUT -> box ( format_module_intro ( 'data' , $data , $cm -> id ), 'generalbox' , 'intro' );
2013-09-10 13:02:35 +12:00
2013-08-22 12:03:23 +07:00
$returnurl = $CFG -> wwwroot . '/mod/data/view.php?d=' . $data -> id . '&search=' . s ( $search ) . '&sort=' . s ( $sort ) . '&order=' . s ( $order ) . '&' ;
groups_print_activity_menu ( $cm , $returnurl );
2006-02-06 04:17:30 +00:00
2006-03-26 05:03:10 +00:00
/// Delete any requested records
2015-06-25 17:10:34 +02:00
if ( $delete && confirm_sesskey () && ( data_user_can_manage_entry ( $delete , $data , $context ))) {
2006-03-29 08:49:28 +00:00
if ( $confirm = optional_param ( 'confirm' , 0 , PARAM_INT )) {
2013-07-22 16:19:08 +08:00
if ( data_delete_record ( $delete , $data , $course -> id , $cm -> id )) {
echo $OUTPUT -> notification ( 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
2015-01-05 09:38:17 +08:00
$allnamefields = user_picture :: fields ( 'u' );
// Remove the id from the string. This already exists in the sql statement.
$allnamefields = str_replace ( 'u.id,' , '' , $allnamefields );
2013-11-11 16:10:30 +08:00
$dbparams = array ( $delete );
if ( $deleterecord = $DB -> get_record_sql ( " SELECT dr.*, $allnamefields
FROM { data_records } dr
2013-11-12 12:04:11 +08:00
JOIN { user } u ON dr . userid = u . id
2013-11-11 16:10:30 +08:00
WHERE dr . id = ? " , $dbparams , MUST_EXIST)) { // Need to check this is valid.
2006-04-05 01:38:06 +00:00
if ( $deleterecord -> dataid == $data -> id ) { // Must be from this database
2010-07-22 06:29:14 +00:00
$deletebutton = new single_button ( new moodle_url ( '/mod/data/view.php?d=' . $data -> id . '&delete=' . $delete . '&confirm=1' ), get_string ( 'delete' ), 'post' );
2009-08-20 08:43:34 +00:00
echo $OUTPUT -> confirm ( get_string ( 'confirmdeleterecord' , 'data' ),
2010-07-22 06:29:14 +00:00
$deletebutton , '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
2009-08-06 14:14:39 +00:00
echo $OUTPUT -> footer ();
2006-04-05 01:38:06 +00:00
exit ;
}
}
}
}
2013-07-22 16:19:08 +08:00
// Multi-delete.
if ( $serialdelete ) {
$multidelete = json_decode ( $serialdelete );
}
if ( $multidelete && confirm_sesskey () && $canmanageentries ) {
if ( $confirm = optional_param ( 'confirm' , 0 , PARAM_INT )) {
foreach ( $multidelete as $value ) {
data_delete_record ( $value , $data , $course -> id , $cm -> id );
}
} else {
$validrecords = array ();
$recordids = array ();
foreach ( $multidelete as $value ) {
2015-01-05 09:38:17 +08:00
$allnamefields = user_picture :: fields ( 'u' );
// Remove the id from the string. This already exists in the sql statement.
$allnamefields = str_replace ( 'u.id,' , '' , $allnamefields );
$dbparams = array ( 'id' => $value );
if ( $deleterecord = $DB -> get_record_sql ( " SELECT dr.*, $allnamefields
FROM { data_records } dr
JOIN { user } u ON dr . userid = u . id
WHERE dr . id = ? " , $dbparams )) { // Need to check this is valid.
if ( $deleterecord -> dataid == $data -> id ) { // Must be from this database.
2013-07-22 16:19:08 +08:00
$validrecords [] = $deleterecord ;
$recordids [] = $deleterecord -> id ;
}
}
}
$serialiseddata = json_encode ( $recordids );
$submitactions = array ( 'd' => $data -> id , 'sesskey' => sesskey (), 'confirm' => '1' , 'serialdelete' => $serialiseddata );
$action = new moodle_url ( '/mod/data/view.php' , $submitactions );
$cancelurl = new moodle_url ( '/mod/data/view.php' , array ( 'd' => $data -> id ));
$deletebutton = new single_button ( $action , get_string ( 'delete' ));
echo $OUTPUT -> confirm ( get_string ( 'confirmdeleterecords' , 'data' ), $deletebutton , $cancelurl );
echo data_print_template ( 'listtemplate' , $validrecords , $data , '' , 0 , false );
echo $OUTPUT -> footer ();
exit ;
}
}
2010-07-29 03:26:02 +00:00
//if data activity closed dont let students in
2010-07-30 07:51:51 +00:00
$showactivity = true ;
2013-07-22 16:19:08 +08:00
if ( ! $canmanageentries ) {
2010-07-29 03:26:02 +00:00
$timenow = time ();
if ( ! empty ( $data -> timeavailablefrom ) && $data -> timeavailablefrom > $timenow ) {
2010-07-30 07:51:51 +00:00
echo $OUTPUT -> notification ( get_string ( 'notopenyet' , 'data' , userdate ( $data -> timeavailablefrom )));
$showactivity = false ;
2010-07-29 03:26:02 +00:00
} else if ( ! empty ( $data -> timeavailableto ) && $timenow > $data -> timeavailableto ) {
2010-07-30 07:51:51 +00:00
echo $OUTPUT -> notification ( get_string ( 'expired' , 'data' , userdate ( $data -> timeavailableto )));
$showactivity = false ;
2010-07-29 03:26:02 +00:00
}
}
2006-04-05 01:38:06 +00:00
2010-07-30 07:51:51 +00:00
if ( $showactivity ) {
// Print the tabs
2006-04-05 01:38:06 +00:00
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 ;
2015-01-19 14:35:36 +08:00
data_print_preference_form ( $data , $perpage , $search , $sort , $order , $search_array , $advanced , $mode );
2008-09-14 08:22:44 +00:00
2008-04-19 15:33:06 +00:00
} else {
2013-08-08 19:15:11 +01:00
// Approve or disapprove any requested records
2008-06-06 08:39:44 +00:00
$params = array (); // named params array
2006-04-05 01:38:06 +00:00
2008-09-14 08:22:44 +00:00
$approvecap = has_capability ( 'mod/data:approve' , $context );
2008-04-19 20:48:48 +00:00
2013-08-08 19:15:11 +01:00
if (( $approve || $disapprove ) && confirm_sesskey () && $approvecap ) {
$newapproved = $approve ? 1 : 0 ;
$recordid = $newapproved ? $approve : $disapprove ;
if ( $approverecord = $DB -> get_record ( 'data_records' , array ( 'id' => $recordid ))) { // Need to check this is valid
2007-02-26 06:56:05 +00:00
if ( $approverecord -> dataid == $data -> id ) { // Must be from this database
2010-09-21 08:37:36 +00:00
$newrecord = new stdClass ();
2007-02-26 06:56:05 +00:00
$newrecord -> id = $approverecord -> id ;
2013-08-08 19:15:11 +01:00
$newrecord -> approved = $newapproved ;
2010-09-03 18:01:25 +00:00
$DB -> update_record ( 'data_records' , $newrecord );
2013-08-08 19:15:11 +01:00
$msgkey = $newapproved ? 'recordapproved' : 'recorddisapproved' ;
echo $OUTPUT -> notification ( get_string ( $msgkey , '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-09-14 08:22:44 +00:00
2008-11-21 07:19:00 +00:00
$numentries = data_numentries ( $data );
/// Check the number of entries required against the number of entries already made (doesn't apply to teachers)
2013-07-22 16:19:08 +08:00
if ( $data -> requiredentries > 0 && $numentries < $data -> requiredentries && ! $canmanageentries ) {
2008-04-19 15:33:06 +00:00
$data -> entriesleft = $data -> requiredentries - $numentries ;
$strentrieslefttoadd = get_string ( 'entrieslefttoadd' , 'data' , $data );
2009-08-18 05:13:51 +00:00
echo $OUTPUT -> notification ( $strentrieslefttoadd );
2008-11-21 07:19:00 +00:00
}
/// Check the number of entries required before to view other participant's entries against the number of entries already made (doesn't apply to teachers)
$requiredentries_allowed = true ;
2013-07-22 16:19:08 +08:00
if ( $data -> requiredentriestoview > 0 && $numentries < $data -> requiredentriestoview && ! $canmanageentries ) {
2008-11-21 07:19:00 +00:00
$data -> entrieslefttoview = $data -> requiredentriestoview - $numentries ;
$strentrieslefttoaddtoview = get_string ( 'entrieslefttoaddtoview' , 'data' , $data );
2009-08-18 05:13:51 +00:00
echo $OUTPUT -> notification ( $strentrieslefttoaddtoview );
2008-04-19 15:33:06 +00:00
$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
2012-11-07 19:43:42 +01:00
// Initialise the first group of params for advanced searches.
$initialparams = array ();
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 ()) {
2008-06-06 08:39:44 +00:00
$approveselect = ' AND (r.approved=1 OR r.userid=:myid1) ' ;
$params [ 'myid1' ] = $USER -> id ;
2012-11-07 19:43:42 +01:00
$initialparams [ 'myid1' ] = $params [ 'myid1' ];
2007-02-26 06:56:05 +00:00
} 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 ) {
2008-06-06 08:39:44 +00:00
$groupselect = " AND (r.groupid = :currentgroup OR r.groupid = 0) " ;
$params [ 'currentgroup' ] = $currentgroup ;
2012-11-07 19:43:42 +01:00
$initialparams [ 'currentgroup' ] = $params [ 'currentgroup' ];
2006-04-05 01:38:06 +00:00
} else {
2012-10-02 15:52:00 +08:00
if ( $canviewallrecords ) {
$groupselect = ' ' ;
} else {
// If separate groups are enabled and the user isn't in a group or
// a teacher, manager, admin etc, then just show them entries for 'All participants'.
$groupselect = " AND r.groupid = 0 " ;
}
2006-04-05 01:38:06 +00:00
}
2006-03-29 08:49:28 +00:00
2009-06-04 10:31:12 +00:00
// Init some variables to be used by advanced search
$advsearchselect = '' ;
$advwhere = '' ;
$advtables = '' ;
$advparams = array ();
2012-11-07 19:43:42 +01:00
// This is used for the initial reduction of advanced search results with required entries.
$entrysql = '' ;
2015-01-05 09:38:17 +08:00
$namefields = user_picture :: fields ( 'u' );
// Remove the id from the string. This already exists in the sql statement.
$namefields = str_replace ( 'u.id,' , '' , $namefields );
2009-06-04 10:31:12 +00:00
2007-02-26 06:56:05 +00:00
/// Find the field we are sorting on
2008-04-21 14:17:02 +00:00
if ( $sort <= 0 or ! $sortfield = data_get_field_from_id ( $sort , $data )) {
2008-04-19 20:48:48 +00:00
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 ;
2008-04-21 14:17:02 +00:00
case DATA_TIMEMODIFIED :
$ordering = " r.timemodified $order " ;
break ;
case DATA_TIMEADDED :
2008-04-19 20:48:48 +00:00
default :
2008-04-21 14:17:02 +00:00
$sort = 0 ;
2008-04-19 20:48:48 +00:00
$ordering = " r.timecreated $order " ;
2008-04-16 11:51:50 +00:00
}
2013-04-24 10:12:42 +08:00
$what = ' DISTINCT r.id, r.approved, r.timecreated, r.timemodified, r.userid, ' . $namefields ;
2008-04-16 11:51:50 +00:00
$count = ' COUNT(DISTINCT c.recordid) ' ;
2012-10-29 14:13:43 +08:00
$tables = '{data_content} c,{data_records} r, {user} u ' ;
2008-04-16 11:51:50 +00:00
$where = ' WHERE c . recordid = r . id
2008-06-06 08:39:44 +00:00
AND r . dataid = : dataid
2012-10-29 14:13:43 +08:00
AND r . userid = u . id ' ;
2008-06-06 08:39:44 +00:00
$params [ 'dataid' ] = $data -> id ;
2014-04-22 22:44:51 +09:30
$sortorder = " ORDER BY $ordering , r.id $order " ;
2008-04-16 11:51:50 +00:00
$searchselect = '' ;
// If requiredentries is not reached, only show current user's entries
if ( ! $requiredentries_allowed ) {
2008-06-06 08:39:44 +00:00
$where .= ' AND u.id = :myid2 ' ;
2012-11-07 19:43:42 +01:00
$entrysql = ' AND r.userid = :myid3 ' ;
2008-06-06 08:39:44 +00:00
$params [ 'myid2' ] = $USER -> id ;
2012-11-07 19:43:42 +01:00
$initialparams [ 'myid3' ] = $params [ 'myid2' ];
2008-04-16 11:51:50 +00:00
}
if ( ! empty ( $advanced )) { //If advanced box is checked.
2008-06-06 08:39:44 +00:00
$i = 0 ;
2008-04-16 11:51:50 +00:00
foreach ( $search_array as $key => $val ) { //what does $search_array hold?
if ( $key == DATA_FIRSTNAME or $key == DATA_LASTNAME ) {
2008-06-06 08:39:44 +00:00
$i ++ ;
2010-09-04 14:08:03 +00:00
$searchselect .= " AND " . $DB -> sql_like ( $val -> field , " :search_flname_ $i " , false );
2008-06-06 08:39:44 +00:00
$params [ 'search_flname_' . $i ] = " % $val->data % " ;
2008-04-16 11:51:50 +00:00
continue ;
}
2009-06-04 10:31:12 +00:00
$advtables .= ', {data_content} c' . $key . ' ' ;
$advwhere .= ' AND c' . $key . '.recordid = r.id' ;
$advsearchselect .= ' AND (' . $val -> sql . ') ' ;
$advparams = array_merge ( $advparams , $val -> params );
2008-04-16 11:51:50 +00:00
}
} else if ( $search ) {
2013-04-24 10:12:42 +08:00
$searchselect = " AND ( " . $DB -> sql_like ( 'c.content' , ':search1' , false ) . "
OR " . $DB->sql_like ('u.firstname', ':search2', false). "
OR " . $DB->sql_like ('u.lastname', ':search3', false). " ) " ;
2008-06-06 08:39:44 +00:00
$params [ 'search1' ] = " % $search % " ;
$params [ 'search2' ] = " % $search % " ;
$params [ 'search3' ] = " % $search % " ;
2008-04-16 11:51:50 +00:00
} else {
$searchselect = ' ' ;
}
2008-04-21 14:17:02 +00:00
} else {
2007-02-26 06:56:05 +00:00
2010-11-17 21:18:53 +00:00
$sortcontent = $DB -> sql_compare_text ( 'c.' . $sortfield -> get_sort_field ());
$sortcontentfull = $sortfield -> get_sort_sql ( $sortcontent );
2008-04-16 11:51:50 +00:00
2013-04-24 10:12:42 +08:00
$what = ' DISTINCT r.id, r.approved, r.timecreated, r.timemodified, r.userid, ' . $namefields . ' ,
' . $sortcontentfull . ' AS sortorder ' ;
2007-02-26 06:56:05 +00:00
$count = ' COUNT(DISTINCT c.recordid) ' ;
2012-10-29 14:13:43 +08:00
$tables = '{data_content} c, {data_records} r, {user} u ' ;
2007-02-26 06:56:05 +00:00
$where = ' WHERE c . recordid = r . id
2008-06-06 08:39:44 +00:00
AND r . dataid = : dataid
2012-10-29 14:13:43 +08:00
AND r . userid = u . id ' ;
2012-11-07 19:43:42 +01:00
if ( ! $advanced ) {
$where .= 'AND c.fieldid = :sort' ;
}
2008-06-06 08:39:44 +00:00
$params [ 'dataid' ] = $data -> id ;
$params [ 'sort' ] = $sort ;
2012-05-18 16:39:53 +08:00
$sortorder = ' ORDER BY sortorder ' . $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 ) {
2012-11-07 19:43:42 +01:00
$where .= ' AND u.id = :myid2' ;
$entrysql = ' AND r.userid = :myid3' ;
2008-06-06 08:39:44 +00:00
$params [ 'myid2' ] = $USER -> id ;
2012-11-07 19:43:42 +01:00
$initialparams [ 'myid3' ] = $params [ 'myid2' ];
2008-02-12 16:04:57 +00:00
}
2011-12-13 10:45:48 +08:00
$i = 0 ;
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-06-06 08:39:44 +00:00
$i ++ ;
2010-09-04 14:08:03 +00:00
$searchselect .= " AND " . $DB -> sql_like ( $val -> field , " :search_flname_ $i " , false );
2008-06-06 08:39:44 +00:00
$params [ 'search_flname_' . $i ] = " % $val->data % " ;
2008-04-16 11:51:50 +00:00
continue ;
}
2009-06-04 10:31:12 +00:00
$advtables .= ', {data_content} c' . $key . ' ' ;
$advwhere .= ' AND c' . $key . '.recordid = r.id AND c' . $key . '.fieldid = ' . $key ;
$advsearchselect .= ' AND (' . $val -> sql . ') ' ;
$advparams = array_merge ( $advparams , $val -> params );
2007-02-26 06:56:05 +00:00
}
2008-04-16 11:51:50 +00:00
} else if ( $search ) {
2012-10-29 14:13:43 +08:00
$searchselect = " AND ( " . $DB -> sql_like ( 'c.content' , ':search1' , false ) . " OR " . $DB -> sql_like ( 'u.firstname' , ':search2' , false ) . " OR " . $DB -> sql_like ( 'u.lastname' , ':search3' , false ) . " ) " ;
2008-06-06 08:39:44 +00:00
$params [ 'search1' ] = " % $search % " ;
$params [ 'search2' ] = " % $search % " ;
$params [ 'search3' ] = " % $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
}
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
/// To actually fetch the records
2006-03-29 08:49:28 +00:00
2009-06-04 10:31:12 +00:00
$fromsql = " FROM $tables $advtables $where $advwhere $groupselect $approveselect $searchselect $advsearchselect " ;
$allparams = array_merge ( $params , $advparams );
2006-03-29 08:49:28 +00:00
2012-10-02 15:52:00 +08:00
// Provide initial sql statements and parameters to reduce the number of total records.
2012-11-07 19:43:42 +01:00
$initialselect = $groupselect . $approveselect . $entrysql ;
2012-10-02 15:52:00 +08:00
2012-11-07 19:43:42 +01:00
$recordids = data_get_all_recordids ( $data -> id , $initialselect , $initialparams );
2011-12-13 10:45:48 +08:00
$newrecordids = data_get_advance_search_ids ( $recordids , $search_array , $data -> id );
2012-05-08 09:21:24 +08:00
$totalcount = count ( $newrecordids );
2012-11-07 19:43:42 +01:00
$selectdata = $where . $groupselect . $approveselect ;
2011-12-13 10:45:48 +08:00
if ( ! empty ( $advanced )) {
$advancedsearchsql = data_get_advanced_search_sql ( $sort , $data , $newrecordids , $selectdata , $sortorder );
$sqlselect = $advancedsearchsql [ 'sql' ];
$allparams = array_merge ( $allparams , $advancedsearchsql [ 'params' ]);
} else {
$sqlselect = " SELECT $what $fromsql $sortorder " ;
}
2006-03-29 08:49:28 +00:00
2011-12-13 10:45:48 +08:00
/// Work out the paging numbers and counts
2009-06-04 10:31:12 +00:00
if ( empty ( $searchselect ) && empty ( $advsearchselect )) {
2008-04-19 15:33:06 +00:00
$maxcount = $totalcount ;
} else {
2011-12-13 10:45:48 +08:00
$maxcount = count ( $recordids );
2008-04-19 15:33: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
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' ;
2012-06-14 14:55:08 +08:00
$page = 0 ;
// TODO MDL-33797 - Reduce this or consider redesigning the paging system.
if ( $allrecordids = $DB -> get_fieldset_sql ( $sqlselect , $allparams )) {
$page = ( int ) array_search ( $record -> id , $allrecordids );
unset ( $allrecordids );
}
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
2015-01-19 14:35:36 +08:00
// Advanced search form doesn't make sense for single (redirects list view).
if ( $maxcount && $mode != 'single' ) {
data_print_preference_form ( $data , $perpage , $search , $sort , $order , $search_array , $advanced , $mode );
}
2007-02-26 06:56:05 +00:00
/// Get the actual records
2008-09-14 08:22:44 +00:00
2009-06-04 10:31:12 +00:00
if ( ! $records = $DB -> get_records_sql ( $sqlselect , $allparams , $page * $nowperpage , $nowperpage )) {
2008-04-19 15:33:06 +00:00
// 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)
2013-07-22 16:19:08 +08:00
if ( $canmanageentries || empty ( $data -> approval ) ||
2007-02-26 06:56:05 +00:00
$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 ){
2010-09-21 08:37:36 +00:00
$a = new stdClass ();
2008-04-19 15:33:06 +00:00
$a -> max = $maxcount ;
$a -> reseturl = " view.php?id= $cm->id &mode= $mode &search=&advanced=0 " ;
2009-08-18 05:13:51 +00:00
echo $OUTPUT -> notification ( get_string ( 'foundnorecords' , 'data' , $a ));
2007-02-26 06:56:05 +00:00
} else {
2009-08-18 05:13:51 +00:00
echo $OUTPUT -> notification ( get_string ( 'norecords' , 'data' ));
2007-02-26 06:56:05 +00:00
}
2006-02-03 08:11:36 +00:00
2015-01-29 10:26:41 +08:00
} else {
// We have some records to print.
$url = new moodle_url ( '/mod/data/view.php' , array ( 'd' => $data -> id , 'sesskey' => sesskey ()));
echo html_writer :: start_tag ( 'form' , array ( 'action' => $url , 'method' => 'post' ));
2008-04-19 15:33:06 +00:00
if ( $maxcount != $totalcount ) {
2010-09-21 08:37:36 +00:00
$a = new stdClass ();
2008-04-19 15:33:06 +00:00
$a -> num = $totalcount ;
$a -> max = $maxcount ;
$a -> reseturl = " view.php?id= $cm->id &mode= $mode &search=&advanced=0 " ;
2009-08-18 05:13:51 +00:00
echo $OUTPUT -> notification ( get_string ( 'foundrecords' , 'data' , $a ), 'notifysuccess' );
2008-04-19 15:33:06 +00:00
}
2005-12-05 08:56:48 +00:00
2011-08-16 17:08:47 +08:00
if ( $mode == 'single' ) { // Single template
$baseurl = 'view.php?d=' . $data -> id . '&mode=single&' ;
2009-03-25 01:49:52 +00:00
if ( ! empty ( $search )) {
2011-08-16 17:08:47 +08:00
$baseurl .= 'filter=1&' ;
}
if ( ! empty ( $page )) {
$baseurl .= 'page=' . $page ;
2009-03-25 01:49:52 +00:00
}
2010-02-17 16:59:41 +00:00
echo $OUTPUT -> paging_bar ( $totalcount , $page , $nowperpage , $baseurl );
2006-03-29 08:49:28 +00:00
2007-02-26 06:56:05 +00:00
if ( empty ( $data -> singletemplate )){
2009-08-18 05:13:51 +00:00
echo $OUTPUT -> notification ( get_string ( 'nosingletemplate' , 'data' ));
2007-02-26 06:56:05 +00:00
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
2010-04-23 09:44:19 +00:00
//data_print_template() only adds ratings for singletemplate which is why we're attaching them here
//attach ratings to data records
require_once ( $CFG -> dirroot . '/rating/lib.php' );
2011-05-11 13:32:36 +08:00
if ( $data -> assessed != RATING_AGGREGATE_NONE ) {
$ratingoptions = new stdClass ;
2011-02-04 17:30:51 +01:00
$ratingoptions -> context = $context ;
2011-04-01 17:20:33 +08:00
$ratingoptions -> component = 'mod_data' ;
2011-05-11 13:32:36 +08:00
$ratingoptions -> ratingarea = 'entry' ;
2010-05-03 02:31:22 +00:00
$ratingoptions -> items = $records ;
$ratingoptions -> aggregate = $data -> assessed ; //the aggregation method
$ratingoptions -> scaleid = $data -> scale ;
$ratingoptions -> userid = $USER -> id ;
$ratingoptions -> returnurl = $CFG -> wwwroot . '/mod/data/' . $baseurl ;
$ratingoptions -> assesstimestart = $data -> assesstimestart ;
$ratingoptions -> assesstimefinish = $data -> assesstimefinish ;
$rm = new rating_manager ();
$records = $rm -> get_ratings ( $ratingoptions );
}
2010-04-23 09:44:19 +00:00
2014-08-20 16:03:55 +01:00
data_print_template ( 'singletemplate' , $records , $data , $search , $page , false , new moodle_url ( $baseurl ));
2006-03-29 08:49:28 +00:00
2010-02-17 16:59:41 +00:00
echo $OUTPUT -> paging_bar ( $totalcount , $page , $nowperpage , $baseurl );
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 . '&' ;
2009-03-25 01:49:52 +00:00
if ( ! empty ( $search )) {
$baseurl .= 'filter=1&' ;
}
2007-02-26 06:56:05 +00:00
//pass variable to allow determining whether or not we are paging through results.
$baseurl .= 'paging=' . $paging . '&' ;
2006-03-29 08:49:28 +00:00
2010-02-17 16:59:41 +00:00
echo $OUTPUT -> paging_bar ( $totalcount , $page , $nowperpage , $baseurl );
2006-03-29 08:49:28 +00:00
2007-02-26 06:56:05 +00:00
if ( empty ( $data -> listtemplate )){
2009-08-18 05:13:51 +00:00
echo $OUTPUT -> notification ( get_string ( 'nolisttemplate' , 'data' ));
2007-02-26 06:56:05 +00:00
data_generate_default_template ( $data , 'listtemplate' , 0 , false , false );
}
echo $data -> listtemplateheader ;
2014-08-20 16:03:55 +01:00
data_print_template ( 'listtemplate' , $records , $data , $search , $page , false , new moodle_url ( $baseurl ));
2007-02-26 06:56:05 +00:00
echo $data -> listtemplatefooter ;
2010-02-17 16:59:41 +00:00
echo $OUTPUT -> paging_bar ( $totalcount , $page , $nowperpage , $baseurl );
2006-03-29 08:49:28 +00:00
}
2015-01-29 10:26:41 +08:00
if ( $mode != 'single' && $canmanageentries ) {
echo html_writer :: empty_tag ( 'input' , array (
'type' => 'button' ,
'id' => 'checkall' ,
'value' => get_string ( 'selectall' ),
2016-11-03 17:03:03 +08:00
'class' => 'btn btn-secondary m-r-1'
2015-01-29 10:26:41 +08:00
));
echo html_writer :: empty_tag ( 'input' , array (
'type' => 'button' ,
'id' => 'checknone' ,
'value' => get_string ( 'deselectall' ),
2016-11-03 17:03:03 +08:00
'class' => 'btn btn-secondary m-r-1'
2015-01-29 10:26:41 +08:00
));
echo html_writer :: empty_tag ( 'input' , array (
'class' => 'form-submit' ,
'type' => 'submit' ,
'value' => get_string ( 'deleteselected' ),
2016-11-03 17:03:03 +08:00
'class' => 'btn btn-secondary m-r-1'
2015-01-29 10:26:41 +08:00
));
$module = array ( 'name' => 'mod_data' , 'fullpath' => '/mod/data/module.js' );
$PAGE -> requires -> js_init_call ( 'M.mod_data.init_view' , null , false , $module );
}
echo html_writer :: end_tag ( 'form' );
2006-03-29 08:49:28 +00:00
}
2007-02-26 06:56:05 +00:00
}
2008-09-14 08:22:44 +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
}
2014-12-22 11:49:02 +08:00
// Check to see if we can export records to a portfolio. This is for exporting all records, not just the ones in the search.
2012-11-30 09:57:45 +08:00
if ( $mode == '' && ! empty ( $CFG -> enableportfolios ) && ! empty ( $records )) {
2014-12-22 11:49:02 +08:00
$canexport = false ;
// Exportallentries and exportentry are basically the same capability.
if ( has_capability ( 'mod/data:exportallentries' , $context ) || has_capability ( 'mod/data:exportentry' , $context )) {
$canexport = true ;
} else if ( has_capability ( 'mod/data:exportownentry' , $context ) &&
$DB -> record_exists ( 'data_records' , array ( 'userid' => $USER -> id ))) {
$canexport = true ;
}
if ( $canexport ) {
require_once ( $CFG -> libdir . '/portfoliolib.php' );
$button = new portfolio_add_button ();
$button -> set_callback_options ( 'data_portfolio_caller' , array ( 'id' => $cm -> id ), 'mod_data' );
if ( data_portfolio_caller :: has_files ( $data )) {
$button -> set_formats ( array ( PORTFOLIO_FORMAT_RICHHTML , PORTFOLIO_FORMAT_LEAP2A )); // No plain html for us.
}
echo $button -> to_html ( PORTFOLIO_ADD_FULL_FORM );
2010-05-02 18:01:19 +00:00
}
}
2010-07-30 07:51:51 +00:00
}
2009-07-09 07:35:03 +00:00
2010-07-30 07:51:51 +00:00
echo $OUTPUT -> footer ();