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 //
// //
///////////////////////////////////////////////////////////////////////////
2009-05-06 09:26:46 +00:00
require_once ( dirname ( __FILE__ ) . '/../../config.php' );
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
$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-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
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 )) {
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 )) {
$search_array [ $field -> id ] = new object ();
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 )) {
$search_array [ DATA_FIRSTNAME ] = new object ();
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 )) {
$search_array [ DATA_LASTNAME ] = new object ();
2008-06-06 08:39:44 +00:00
$search_array [ DATA_LASTNAME ] -> sql = '' ;
$search_array [ DATA_FIRSTNAME ] -> params = array ();
$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
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
2010-01-16 15:39:56 +00:00
$PAGE -> set_url ( '/mod/data/view.php' , array ( 'id' => $cm -> id ));
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
}
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 ) {
2010-05-13 08:44:35 +00:00
$rsstitle = format_string ( $course -> shortname ) . ': %fullname%' ;
rss_add_http_header ( $context , '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
}
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.
2009-05-06 09:26:46 +00:00
$title = $course -> shortname . ': ' . format_string ( $data -> name );
if ( $PAGE -> user_allowed_editing () && ! empty ( $CFG -> showblocksonmodpages )) {
2010-02-11 13:27:02 +00:00
$buttons = '<table><tr><td><form method="get" action="view.php"><div>' .
2009-05-06 09:26:46 +00:00
'<input type="hidden" name="id" value="' . $cm -> id . '" />' .
'<input type="hidden" name="edit" value="' . ( $PAGE -> user_is_editing () ? 'off' : 'on' ) . '" />' .
2009-12-23 01:57:55 +00:00
'<input type="submit" value="' . get_string ( $PAGE -> user_is_editing () ? 'blockseditoff' : 'blocksediton' ) . '" /></div></form></td></tr></table>' ;
$PAGE -> set_button ( $buttons );
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' ));
}
2009-09-07 05:43:15 +00:00
$PAGE -> set_title ( $title );
$PAGE -> set_heading ( $course -> fullname );
2009-12-23 01:57:55 +00:00
2009-09-07 05:43:15 +00:00
echo $OUTPUT -> header ();
2009-11-01 14:55:15 +00:00
2007-07-05 04:40:48 +00:00
/// Check to see if groups are being used here
2009-11-30 17:12:48 +00:00
$returnurl = $CFG -> wwwroot . '/mod/data/view.php?d=' . $data -> id . '&search=' . s ( $search ) . '&sort=' . s ( $sort ) . '&order=' . s ( $order ) . '&' ;
2007-08-20 10:52:59 +00:00
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
2009-09-27 18:08:27 +00:00
// deletect entries not approved yet and show hint instead of not found error
if ( $record and $data -> approval and ! $record -> approved and $record -> userid != $USER -> id and ! has_capability ( 'mod/data:manageentries' , $context )) {
if ( ! $currentgroup or $record -> groupid == $currentgroup or $record -> groupid == 0 ) {
print_error ( 'notapproved' , 'data' );
}
}
2009-08-06 08:21:01 +00:00
echo $OUTPUT -> 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?
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-05-02 11:43:57 +00:00
rss_print_link ( $context -> 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>' ;
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' ) {
2008-04-21 13:26:08 +00:00
$options = new object ();
$options -> noclean = true ;
2009-08-10 04:59:09 +00:00
echo $OUTPUT -> box ( format_module_intro ( 'data' , $data , $cm -> id ), '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 )) {
2008-06-06 07:36:17 +00:00
if ( $deleterecord = $DB -> get_record ( 'data_records' , array ( 'id' => $delete ))) { // Need to check this is valid
2006-03-29 08:49:28 +00:00
if ( $deleterecord -> dataid == $data -> id ) { // Must be from this database
2008-06-06 07:36:17 +00:00
if ( $contents = $DB -> get_records ( 'data_content' , array ( 'recordid' => $deleterecord -> id ))) {
2006-03-29 08:49:28 +00:00
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
}
}
2008-06-06 07:36:17 +00:00
$DB -> delete_records ( 'data_content' , array ( 'recordid' => $deleterecord -> id ));
$DB -> delete_records ( 'data_records' , array ( '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
2009-08-18 05:13:51 +00:00
echo $OUTPUT -> notification ( get_string ( 'recorddeleted' , 'data' ), 'notifysuccess' );
2006-03-29 08:49:28 +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-03-29 08:49:28 +00:00
} else { // Print a confirmation page
2008-06-06 07:36:17 +00:00
if ( $deleterecord = $DB -> get_record ( 'data_records' , array ( 'id' => $delete ))) { // Need to check this is valid
2006-04-05 01:38:06 +00:00
if ( $deleterecord -> dataid == $data -> id ) { // Must be from this database
2009-08-20 08:43:34 +00:00
echo $OUTPUT -> confirm ( get_string ( 'confirmdeleterecord' , 'data' ),
'view.php?d=' . $data -> id . '&delete=' . $delete . '&confirm=1' ,
2006-04-05 01:38:06 +00:00
'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 ;
}
}
}
}
/// 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 ;
2008-09-14 08:22:44 +00:00
2008-04-19 15:33:06 +00:00
} else {
2007-02-26 06:56:05 +00:00
/// Approve 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
if ( $approve && confirm_sesskey () && $approvecap ) {
2008-06-06 07:36:17 +00:00
if ( $approverecord = $DB -> get_record ( 'data_records' , array ( 'id' => $approve ))) { // Need to check this is valid
2007-02-26 06:56:05 +00:00
if ( $approverecord -> dataid == $data -> id ) { // Must be from this database
$newrecord -> id = $approverecord -> id ;
$newrecord -> approved = 1 ;
2008-06-06 07:36:17 +00:00
if ( $DB -> update_record ( 'data_records' , $newrecord )) {
2009-08-18 05:13:51 +00:00
echo $OUTPUT -> notification ( get_string ( 'recordapproved' , 'data' ), 'notifysuccess' );
2007-02-26 06:56:05 +00:00
}
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)
2008-04-19 15:33:06 +00:00
if ( $data -> requiredentries > 0 && $numentries < $data -> requiredentries && ! has_capability ( 'mod/data:manageentries' , $context )) {
$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 ;
if ( $data -> requiredentriestoview > 0 && $numentries < $data -> requiredentriestoview && ! has_capability ( 'mod/data:manageentries' , $context )) {
$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
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 ;
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 ;
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-06-09 19:48:24 +00:00
$ilike = $DB -> sql_ilike (); //Be case-insensitive
2008-04-16 18:57:15 +00:00
2009-06-04 10:31:12 +00:00
// Init some variables to be used by advanced search
$advsearchselect = '' ;
$advwhere = '' ;
$advtables = '' ;
$advparams = array ();
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
}
$what = ' DISTINCT r.id, r.approved, r.timecreated, r.timemodified, r.userid, u.firstname, u.lastname' ;
$count = ' COUNT(DISTINCT c.recordid) ' ;
2008-06-06 08:39:44 +00:00
$tables = '{data_content} c,{data_records} r, {data_content} cs, {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
2008-04-16 11:51:50 +00:00
AND r . userid = u . id
AND cs . recordid = r . id ' ;
2008-06-06 08:39:44 +00:00
$params [ 'dataid' ] = $data -> id ;
2008-04-16 11:51:50 +00:00
$sortorder = ' ORDER BY ' . $ordering . ', r.id ASC ' ;
$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 ' ;
$params [ 'myid2' ] = $USER -> id ;
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 ++ ;
$searchselect .= " AND $val->field $ilike :search_flname_ $i " ;
$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 ) {
2008-06-06 08:39:44 +00:00
$searchselect = " AND (cs.content $ilike :search1 OR u.firstname $ilike :search2 OR u.lastname $ilike :search3 ) " ;
$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
$sortcontent = $sortfield -> get_sort_field ();
$sortcontentfull = $sortfield -> get_sort_sql ( 'c.' . $sortcontent );
2008-04-16 11:51:50 +00:00
2009-05-06 17:25:26 +00:00
$what = ' DISTINCT r.id, r.approved, r.timecreated, r.timemodified, r.userid, u.firstname, u.lastname, ' . $DB -> sql_compare_text ( $sortcontentfull ) . ' AS _order ' ;
2007-02-26 06:56:05 +00:00
$count = ' COUNT(DISTINCT c.recordid) ' ;
2008-06-06 08:39:44 +00:00
$tables = '{data_content} c, {data_records} r, {data_content} cs, {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 c . fieldid = : sort
AND r . dataid = : dataid
2007-02-26 06:56:05 +00:00
AND r . userid = u . id
2008-04-16 11:51:50 +00:00
AND cs . recordid = r . id ' ;
2008-06-06 08:39:44 +00:00
$params [ 'dataid' ] = $data -> id ;
$params [ 'sort' ] = $sort ;
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-06-06 08:39:44 +00:00
$params [ 'myid2' ] = $USER -> id ;
2008-02-12 16:04:57 +00:00
}
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 ++ ;
$searchselect .= " AND $val->field $ilike :search_flname_ $i " ;
$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 ) {
2008-06-06 08:39:44 +00:00
$searchselect = " AND (cs.content $ilike :search1 OR u.firstname $ilike :search2 OR u.lastname $ilike :search3 ) " ;
$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 " ;
2008-04-19 15:33:06 +00:00
$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
2009-06-04 10:31:12 +00:00
$allparams = array_merge ( $params , $advparams );
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
2009-06-04 10:31:12 +00:00
$totalcount = $DB -> count_records_sql ( $sqlcount , $allparams );
if ( empty ( $searchselect ) && empty ( $advsearchselect )) {
2008-04-19 15:33:06 +00:00
$maxcount = $totalcount ;
} else {
2008-06-06 08:39:44 +00:00
$maxcount = $DB -> count_records_sql ( $sqlmax , $params );
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' ;
2006-04-13 01:34:26 +00:00
2007-02-26 06:56:05 +00:00
$page = 0 ;
2009-06-04 10:31:12 +00:00
if ( $allrecordids = $DB -> get_records_sql ( $sqlrids , $allparams )) {
2008-04-19 21:02:10 +00:00
$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-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)
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 " ;
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
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 " ;
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
2007-02-26 06:56:05 +00:00
if ( $mode == 'single' ) { // Single template
2008-10-24 20:17:10 +00:00
$baseurl = 'view.php?d=' . $data -> id . '&mode=single&' ;
2009-03-25 01:49:52 +00:00
if ( ! empty ( $search )) {
$baseurl .= 'filter=1&' ;
}
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' );
2010-05-03 02:31:22 +00:00
if ( $data -> assessed != RATING_AGGREGATE_NONE ) {
$ratingoptions = new stdclass ();
$ratingoptions -> context = $cm -> context ;
$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 ;
$ratingoptions -> plugintype = 'mod' ;
$ratingoptions -> pluginname = 'data' ;
$rm = new rating_manager ();
$records = $rm -> get_ratings ( $ratingoptions );
}
2010-04-23 09:44:19 +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
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 ;
data_print_template ( 'listtemplate' , $records , $data , $search , $page );
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
}
}
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
}
2010-05-02 18:01:19 +00:00
if ( $mode == '' && $CFG -> enableportfolios ) {
require_once ( $CFG -> libdir . '/portfoliolib.php' );
$button = new portfolio_add_button ();
$button -> set_callback_options ( 'data_portfolio_caller' , array ( 'id' => $cm -> id ), '/mod/data/locallib.php' );
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 );
}
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
2008-07-29 17:22:47 +00:00
/// Mark as viewed
$completion = new completion_info ( $course );
$completion -> set_module_viewed ( $cm );
2009-07-09 07:35:03 +00:00
2009-08-06 14:14:39 +00:00
echo $OUTPUT -> footer ();
2009-11-01 14:55:15 +00:00