NEW MODULE FROM MOODLE.COM - DATABASE !
Finally, we have an early version good enough for everyone to
start banging on to help us polish it up and find bugs.
Please take a look and file bugs in the bug tracker under "Database module".
We urgently need
- new icons for existing field types
- testing on PostgreSQL install
Coming soon (?):
- Many more field types: calculation, checkbox, relation, date, datetime,
time, email, group, list, user, number, richtext
(Please let us know if you are interested in developing any of these)
- A way to save and restore "presets", which are field/template sets
- Backup/Restore support
- Groups Support
- RSS support
Many thanks to Yu for all the hard work under my whip.
2005-12-02 07:50:26 +00:00
|
|
|
<?php // $Id$
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// //
|
|
|
|
// NOTICE OF COPYRIGHT //
|
|
|
|
// //
|
|
|
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
|
|
|
// http://moodle.org //
|
|
|
|
// //
|
|
|
|
// Copyright (C) 2005 Moodle Pty Ltd http://moodle.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 //
|
|
|
|
// //
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2008-05-31 00:30:00 +00:00
|
|
|
// Some constants
|
2006-03-22 08:07:26 +00:00
|
|
|
define ('DATA_MAX_ENTRIES', 50);
|
|
|
|
define ('DATA_PERPAGE_SINGLE', 1);
|
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 11:51:50 +00:00
|
|
|
define ('DATA_FIRSTNAME', -1);
|
|
|
|
define ('DATA_LASTNAME', -2);
|
2008-04-19 20:48:48 +00:00
|
|
|
define ('DATA_APPROVED', -3);
|
2008-04-21 14:17:02 +00:00
|
|
|
define ('DATA_TIMEADDED', 0);
|
|
|
|
define ('DATA_TIMEMODIFIED', -4);
|
2008-04-16 11:51:50 +00:00
|
|
|
|
2008-05-31 09:51:48 +00:00
|
|
|
class data_field_base { // Base class for Database Field Types (see field/*/field.class.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
|
|
|
|
2008-05-31 09:51:48 +00:00
|
|
|
var $type = 'unknown'; // Subclasses must override the type with their name
|
|
|
|
var $data = NULL; // The database object that this field belongs to
|
|
|
|
var $field = NULL; // The field object itself, if we know it
|
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-05-31 09:51:48 +00:00
|
|
|
var $iconwidth = 16; // Width of the icon for this fieldtype
|
|
|
|
var $iconheight = 16; // Width of the icon for this fieldtype
|
2006-03-22 08:07:26 +00:00
|
|
|
|
|
|
|
|
2008-05-31 00:30:00 +00:00
|
|
|
// Constructor function
|
2006-03-22 08:07:26 +00:00
|
|
|
function data_field_base($field=0, $data=0) { // Field or data or both, each can be id or object
|
|
|
|
|
|
|
|
if (empty($field) && empty($data)) {
|
2008-04-13 22:22:57 +00:00
|
|
|
error('Programmer error: You must specify field and/or data when defining field class. ');
|
2006-03-22 08:07:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($field)) {
|
|
|
|
if (is_object($field)) {
|
|
|
|
$this->field = $field; // Programmer knows what they are doing, we hope
|
|
|
|
} else if (!$this->field = get_record('data_fields','id',$field)) {
|
2008-04-13 22:22:57 +00:00
|
|
|
error('Bad field ID encountered: '.$field);
|
2006-03-22 08:07:26 +00:00
|
|
|
}
|
|
|
|
if (empty($data)) {
|
|
|
|
if (!$this->data = get_record('data','id',$this->field->dataid)) {
|
2008-04-13 22:22:57 +00:00
|
|
|
error('Bad data ID encountered in field data');
|
2006-03-22 08:07:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($this->data)) { // We need to define this properly
|
|
|
|
if (!empty($data)) {
|
|
|
|
if (is_object($data)) {
|
|
|
|
$this->data = $data; // Programmer knows what they are doing, we hope
|
|
|
|
} else if (!$this->data = get_record('data','id',$data)) {
|
2008-04-13 22:22:57 +00:00
|
|
|
error('Bad data ID encountered: '.$data);
|
2006-03-22 08:07:26 +00:00
|
|
|
}
|
|
|
|
} else { // No way to define it!
|
2008-04-13 22:22:57 +00:00
|
|
|
error('Data id or object must be provided to field class');
|
2006-03-22 08:07:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($this->field)) { // We need to define some default values
|
|
|
|
$this->define_default_field();
|
|
|
|
}
|
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-22 08:07:26 +00:00
|
|
|
|
2006-11-09 19:44:20 +00:00
|
|
|
|
2008-05-31 00:30:00 +00:00
|
|
|
// This field just sets up a default field object
|
2006-03-22 08:07:26 +00:00
|
|
|
function define_default_field() {
|
|
|
|
if (empty($this->data->id)) {
|
|
|
|
notify('Programmer error: dataid not defined in field class');
|
|
|
|
}
|
|
|
|
$this->field = new object;
|
|
|
|
$this->field->id = 0;
|
|
|
|
$this->field->dataid = $this->data->id;
|
|
|
|
$this->field->type = $this->type;
|
|
|
|
$this->field->param1 = '';
|
|
|
|
$this->field->param2 = '';
|
|
|
|
$this->field->param3 = '';
|
|
|
|
$this->field->name = '';
|
|
|
|
$this->field->description = '';
|
|
|
|
|
|
|
|
return true;
|
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-22 08:07:26 +00:00
|
|
|
|
2008-05-31 00:30:00 +00:00
|
|
|
// Set up the field object according to data in an object. Now is the time to clean it!
|
2006-03-22 08:07:26 +00:00
|
|
|
function define_field($data) {
|
|
|
|
$this->field->type = $this->type;
|
|
|
|
$this->field->dataid = $this->data->id;
|
|
|
|
|
|
|
|
$this->field->name = trim($data->name);
|
|
|
|
$this->field->description = trim($data->description);
|
|
|
|
|
|
|
|
if (isset($data->param1)) {
|
|
|
|
$this->field->param1 = trim($data->param1);
|
|
|
|
}
|
|
|
|
if (isset($data->param2)) {
|
2006-03-23 03:48:58 +00:00
|
|
|
$this->field->param2 = trim($data->param2);
|
2006-03-22 08:07:26 +00:00
|
|
|
}
|
|
|
|
if (isset($data->param3)) {
|
|
|
|
$this->field->param3 = trim($data->param3);
|
|
|
|
}
|
|
|
|
if (isset($data->param4)) {
|
|
|
|
$this->field->param4 = trim($data->param4);
|
|
|
|
}
|
|
|
|
if (isset($data->param5)) {
|
|
|
|
$this->field->param5 = trim($data->param5);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
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-11-09 19:44:20 +00:00
|
|
|
|
2008-05-31 00:30:00 +00:00
|
|
|
// Insert a new field in the database
|
|
|
|
// We assume the field object is already defined as $this->field
|
2006-03-22 08:07:26 +00:00
|
|
|
function insert_field() {
|
|
|
|
if (empty($this->field)) {
|
|
|
|
notify('Programmer error: Field has not been defined yet! See define_field()');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$this->field->id = insert_record('data_fields',$this->field)){
|
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
|
|
|
notify('Insertion of new field failed!');
|
2006-03-22 08:07:26 +00:00
|
|
|
return 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
|
|
|
}
|
2006-03-22 08:07:26 +00:00
|
|
|
return true;
|
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-22 08:07:26 +00:00
|
|
|
|
2008-05-31 00:30:00 +00:00
|
|
|
// Update a field in the database
|
2006-03-22 08:07:26 +00:00
|
|
|
function update_field() {
|
|
|
|
if (!update_record('data_fields', $this->field)) {
|
|
|
|
notify('updating of new field failed!');
|
|
|
|
return 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
|
|
|
}
|
2006-03-22 08:07:26 +00:00
|
|
|
return true;
|
|
|
|
}
|
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-05-31 00:30:00 +00:00
|
|
|
// Delete a field completely
|
2006-03-22 08:07:26 +00:00
|
|
|
function delete_field() {
|
|
|
|
if (!empty($this->field->id)) {
|
|
|
|
delete_records('data_fields', 'id', $this->field->id);
|
|
|
|
$this->delete_content();
|
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-22 08:07:26 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-05-31 00:30:00 +00:00
|
|
|
// Print the relevant form element in the ADD template for this field
|
2006-03-22 08:07:26 +00:00
|
|
|
function display_add_field($recordid=0){
|
|
|
|
if ($recordid){
|
|
|
|
$content = get_field('data_content', 'content', 'fieldid', $this->field->id, 'recordid', $recordid);
|
|
|
|
} else {
|
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
|
|
|
$content = '';
|
|
|
|
}
|
2006-11-09 19:44:20 +00:00
|
|
|
|
2006-12-12 20:10:32 +00:00
|
|
|
$str = '<div title="'.s($this->field->description).'">';
|
2006-03-22 08:07:26 +00:00
|
|
|
$str .= '<input style="width:300px;" type="text" name="field_'.$this->field->id.'" id="field_'.$this->field->id.'" value="'.s($content).'" />';
|
2006-02-09 04:44:56 +00:00
|
|
|
$str .= '</div>';
|
2006-03-22 08:07:26 +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
|
|
|
return $str;
|
|
|
|
}
|
|
|
|
|
2008-05-31 00:30:00 +00:00
|
|
|
// Print the relevant form element to define the attributes for this field
|
|
|
|
// viewable by teachers only.
|
2006-03-22 08:07:26 +00:00
|
|
|
function display_edit_field() {
|
2008-06-05 19:26:57 +00:00
|
|
|
global $CFG, $DB;
|
2006-03-22 08:07:26 +00:00
|
|
|
|
|
|
|
if (empty($this->field)) { // No field has been defined yet, try and make one
|
|
|
|
$this->define_default_field();
|
NEW MODULE FROM MOODLE.COM - DATABASE !
Finally, we have an early version good enough for everyone to
start banging on to help us polish it up and find bugs.
Please take a look and file bugs in the bug tracker under "Database module".
We urgently need
- new icons for existing field types
- testing on PostgreSQL install
Coming soon (?):
- Many more field types: calculation, checkbox, relation, date, datetime,
time, email, group, list, user, number, richtext
(Please let us know if you are interested in developing any of these)
- A way to save and restore "presets", which are field/template sets
- Backup/Restore support
- Groups Support
- RSS support
Many thanks to Yu for all the hard work under my whip.
2005-12-02 07:50:26 +00:00
|
|
|
}
|
|
|
|
print_simple_box_start('center','80%');
|
2006-03-22 08:07:26 +00:00
|
|
|
|
2007-01-04 21:32:36 +00:00
|
|
|
echo '<form id="editfield" action="'.$CFG->wwwroot.'/mod/data/field.php" method="post">'."\n";
|
2006-03-22 08:07:26 +00:00
|
|
|
echo '<input type="hidden" name="d" value="'.$this->data->id.'" />'."\n";
|
|
|
|
if (empty($this->field->id)) {
|
|
|
|
echo '<input type="hidden" name="mode" value="add" />'."\n";
|
|
|
|
$savebutton = get_string('add');
|
|
|
|
} else {
|
|
|
|
echo '<input type="hidden" name="fid" value="'.$this->field->id.'" />'."\n";
|
|
|
|
echo '<input type="hidden" name="mode" value="update" />'."\n";
|
|
|
|
$savebutton = get_string('savechanges');
|
|
|
|
}
|
|
|
|
echo '<input type="hidden" name="type" value="'.$this->type.'" />'."\n";
|
|
|
|
echo '<input name="sesskey" value="'.sesskey().'" type="hidden" />'."\n";
|
2006-11-09 19:44:20 +00:00
|
|
|
|
2006-03-22 08:07:26 +00:00
|
|
|
print_heading($this->name());
|
|
|
|
|
NEW MODULE FROM MOODLE.COM - DATABASE !
Finally, we have an early version good enough for everyone to
start banging on to help us polish it up and find bugs.
Please take a look and file bugs in the bug tracker under "Database module".
We urgently need
- new icons for existing field types
- testing on PostgreSQL install
Coming soon (?):
- Many more field types: calculation, checkbox, relation, date, datetime,
time, email, group, list, user, number, richtext
(Please let us know if you are interested in developing any of these)
- A way to save and restore "presets", which are field/template sets
- Backup/Restore support
- Groups Support
- RSS support
Many thanks to Yu for all the hard work under my whip.
2005-12-02 07:50:26 +00:00
|
|
|
require_once($CFG->dirroot.'/mod/data/field/'.$this->type.'/mod.html');
|
2006-03-22 08:07:26 +00:00
|
|
|
|
|
|
|
echo '<div align="center">';
|
|
|
|
echo '<input type="submit" value="'.$savebutton.'" />'."\n";
|
2006-03-25 14:00:54 +00:00
|
|
|
echo '<input type="submit" name="cancel" value="'.get_string('cancel').'" />'."\n";
|
2006-12-12 23:34:55 +00:00
|
|
|
echo '</div>';
|
2006-03-22 08:07:26 +00:00
|
|
|
|
|
|
|
echo '</form>';
|
|
|
|
|
NEW MODULE FROM MOODLE.COM - DATABASE !
Finally, we have an early version good enough for everyone to
start banging on to help us polish it up and find bugs.
Please take a look and file bugs in the bug tracker under "Database module".
We urgently need
- new icons for existing field types
- testing on PostgreSQL install
Coming soon (?):
- Many more field types: calculation, checkbox, relation, date, datetime,
time, email, group, list, user, number, richtext
(Please let us know if you are interested in developing any of these)
- A way to save and restore "presets", which are field/template sets
- Backup/Restore support
- Groups Support
- RSS support
Many thanks to Yu for all the hard work under my whip.
2005-12-02 07:50:26 +00:00
|
|
|
print_simple_box_end();
|
|
|
|
}
|
2006-11-09 19:44:20 +00:00
|
|
|
|
2008-05-31 00:30:00 +00:00
|
|
|
// Display the content of the field in browse mode
|
2006-03-22 08:07:26 +00:00
|
|
|
function display_browse_field($recordid, $template) {
|
|
|
|
if ($content = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) {
|
2006-11-09 19:44:20 +00:00
|
|
|
if (isset($content->content)) {
|
2006-12-12 20:10:32 +00:00
|
|
|
$options = new object();
|
2006-03-26 15:54:41 +00:00
|
|
|
if ($this->field->param1 == '1') { // We are autolinking this field, so disable linking within us
|
|
|
|
//$content->content = '<span class="nolink">'.$content->content.'</span>';
|
|
|
|
//$content->content1 = FORMAT_HTML;
|
|
|
|
$options->filter=false;
|
|
|
|
}
|
2006-02-03 10:42:14 +00:00
|
|
|
$options->para = false;
|
|
|
|
$str = format_text($content->content, $content->content1, $options);
|
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
|
|
|
} else {
|
|
|
|
$str = '';
|
|
|
|
}
|
|
|
|
return $str;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2006-11-09 19:44:20 +00:00
|
|
|
|
2008-05-31 00:30:00 +00:00
|
|
|
// Update the content of one data field in the data_content table
|
2006-03-22 08:07:26 +00:00
|
|
|
function update_content($recordid, $value, $name=''){
|
2006-12-12 20:10:32 +00:00
|
|
|
$content = new object();
|
2006-03-22 08:07:26 +00:00
|
|
|
$content->fieldid = $this->field->id;
|
2006-02-02 06:28:17 +00:00
|
|
|
$content->recordid = $recordid;
|
|
|
|
$content->content = clean_param($value, PARAM_NOTAGS);
|
2006-03-22 08:07:26 +00:00
|
|
|
|
|
|
|
if ($oldcontent = get_record('data_content','fieldid', $this->field->id, 'recordid', $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
|
|
|
$content->id = $oldcontent->id;
|
2006-03-22 08:07:26 +00:00
|
|
|
return update_record('data_content', $content);
|
|
|
|
} else {
|
|
|
|
return insert_record('data_content', $content);
|
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-22 08:07:26 +00:00
|
|
|
}
|
2006-11-09 19:44:20 +00:00
|
|
|
|
2008-05-31 00:30:00 +00:00
|
|
|
// Delete all content associated with the field
|
2006-03-22 08:07:26 +00:00
|
|
|
function delete_content($recordid=0) {
|
|
|
|
|
|
|
|
$this->delete_content_files($recordid);
|
2006-11-09 19:44:20 +00:00
|
|
|
|
2006-03-22 08:07:26 +00:00
|
|
|
if ($recordid) {
|
|
|
|
return delete_records('data_content', 'fieldid', $this->field->id, 'recordid', $recordid);
|
|
|
|
} else {
|
|
|
|
return delete_records('data_content', 'fieldid', $this->field->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-03-22 08:07:26 +00:00
|
|
|
|
2008-05-31 00:30:00 +00:00
|
|
|
// Deletes any files associated with this field
|
2006-03-22 08:07:26 +00:00
|
|
|
function delete_content_files($recordid='') {
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
require_once($CFG->libdir.'/filelib.php');
|
|
|
|
|
|
|
|
$dir = $CFG->dataroot.'/'.$this->data->course.'/'.$CFG->moddata.'/data/'.$this->data->id.'/'.$this->field->id;
|
|
|
|
if ($recordid) {
|
|
|
|
$dir .= '/'.$recordid;
|
|
|
|
}
|
|
|
|
|
|
|
|
return fulldelete($dir);
|
|
|
|
}
|
2006-11-09 19:44:20 +00:00
|
|
|
|
2006-03-22 08:07:26 +00:00
|
|
|
|
2008-05-31 00:30:00 +00:00
|
|
|
// Check if a field from an add form is empty
|
2006-02-06 09:13:37 +00:00
|
|
|
function notemptyfield($value, $name) {
|
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
|
|
|
return !empty($value);
|
|
|
|
}
|
2006-11-09 19:44:20 +00:00
|
|
|
|
2008-05-31 00:30:00 +00:00
|
|
|
// Just in case a field needs to print something before the whole form
|
2006-03-22 08:07:26 +00:00
|
|
|
function print_before_form() {
|
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-22 08:07:26 +00:00
|
|
|
|
2008-05-31 00:30:00 +00:00
|
|
|
// Just in case a field needs to print something after the whole form
|
2006-01-31 03:58:42 +00:00
|
|
|
function print_after_form() {
|
|
|
|
}
|
2006-11-09 19:44:20 +00:00
|
|
|
|
|
|
|
|
2008-05-31 00:30:00 +00:00
|
|
|
// Returns the sortable field for the content. By default, it's just content
|
|
|
|
// but for some plugins, it could be content 1 - content4
|
2006-02-03 08:11:36 +00:00
|
|
|
function get_sort_field() {
|
|
|
|
return 'content';
|
|
|
|
}
|
2006-03-22 08:07:26 +00:00
|
|
|
|
2008-05-31 00:30:00 +00:00
|
|
|
// Returns the SQL needed to refer to the column. Some fields may need to CAST() etc.
|
2006-04-05 01:38:06 +00:00
|
|
|
function get_sort_sql($fieldname) {
|
|
|
|
return $fieldname;
|
|
|
|
}
|
|
|
|
|
2008-05-31 00:30:00 +00:00
|
|
|
// Returns the name/type of the field
|
|
|
|
function name() {
|
2006-03-22 08:07:26 +00:00
|
|
|
return get_string('name'.$this->type, 'data');
|
|
|
|
}
|
2006-11-09 19:44:20 +00:00
|
|
|
|
2008-05-31 00:30:00 +00:00
|
|
|
// Prints the respective type icon
|
2006-03-22 08:07:26 +00:00
|
|
|
function image() {
|
|
|
|
global $CFG;
|
|
|
|
|
2006-03-24 02:44:05 +00:00
|
|
|
$str = '<a href="field.php?d='.$this->data->id.'&fid='.$this->field->id.'&mode=display&sesskey='.sesskey().'">';
|
2006-03-22 08:07:26 +00:00
|
|
|
$str .= '<img src="'.$CFG->modpixpath.'/data/field/'.$this->type.'/icon.gif" ';
|
2007-01-08 01:09:54 +00:00
|
|
|
$str .= 'height="'.$this->iconheight.'" width="'.$this->iconwidth.'" alt="'.$this->type.'" title="'.$this->type.'" /></a>';
|
2006-03-22 08:07:26 +00:00
|
|
|
return $str;
|
|
|
|
}
|
|
|
|
|
2008-05-31 00:30:00 +00:00
|
|
|
// Per default, it is assumed that fields support text exporting. Override this (return false) on fields not supporting text exporting.
|
|
|
|
function text_export_supported() {
|
|
|
|
return true;
|
|
|
|
}
|
2006-11-09 19:44:20 +00:00
|
|
|
|
2008-05-31 00:30:00 +00:00
|
|
|
// Per default, return the record's text value only from the "content" field. Override this in fields class if necesarry.
|
|
|
|
function export_text_value($record) {
|
|
|
|
if ($this->text_export_supported()) {
|
|
|
|
return $record->content;
|
|
|
|
}
|
|
|
|
}
|
2006-03-22 08:07:26 +00:00
|
|
|
|
2008-05-31 00:30:00 +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-23 10:01:21 +00:00
|
|
|
/* Given a template and a dataid, generate a default case template *
|
|
|
|
* input @param template - addtemplate, singletemplate, listtempalte, rsstemplate*
|
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
|
|
|
* @param dataid *
|
|
|
|
* output null *
|
|
|
|
*****************************************************************************/
|
2006-03-25 14:57:36 +00:00
|
|
|
function data_generate_default_template(&$data, $template, $recordid=0, $form=false, $update=true) {
|
2006-03-23 10:01:21 +00:00
|
|
|
|
2006-04-11 13:00:13 +00:00
|
|
|
if (!$data && !$template) {
|
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
|
|
|
return false;
|
|
|
|
}
|
2006-12-11 08:55:40 +00:00
|
|
|
if ($template == 'csstemplate' or $template == 'jstemplate' ) {
|
2006-06-02 04:29:11 +00:00
|
|
|
return '';
|
|
|
|
}
|
2006-11-09 19:44:20 +00:00
|
|
|
|
2008-05-31 00:30:00 +00:00
|
|
|
// get all the fields for that database
|
2006-03-24 14:34:00 +00:00
|
|
|
if ($fields = get_records('data_fields', 'dataid', $data->id, 'id')) {
|
2006-11-09 19:44:20 +00:00
|
|
|
|
2007-01-08 01:38:42 +00:00
|
|
|
$str = '<div class="defaulttemplate">';
|
2006-12-12 23:34:55 +00:00
|
|
|
$str .= '<table cellpadding="5">';
|
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-24 02:09:15 +00:00
|
|
|
foreach ($fields as $field) {
|
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-01-19 08:51:34 +00:00
|
|
|
$str .= '<tr><td valign="top" align="right">';
|
2007-01-05 02:38:09 +00:00
|
|
|
// Yu: commenting this out, the id was wrong and will fix later
|
|
|
|
//if ($template == 'addtemplate') {
|
|
|
|
//$str .= '<label';
|
|
|
|
//if (!in_array($field->type, array('picture', 'checkbox', 'date', 'latlong', 'radiobutton'))) {
|
|
|
|
// $str .= ' for="[['.$field->name.'#id]]"';
|
|
|
|
//}
|
|
|
|
//$str .= '>'.$field->name.'</label>';
|
|
|
|
|
|
|
|
//} else {
|
2006-12-12 23:34:55 +00:00
|
|
|
$str .= $field->name.': ';
|
2007-01-05 02:38:09 +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
|
|
|
$str .= '</td>';
|
|
|
|
|
|
|
|
$str .='<td>';
|
2008-05-31 00:30:00 +00:00
|
|
|
if ($form) { // Print forms instead of data
|
2006-03-23 10:01:21 +00:00
|
|
|
$fieldobj = data_get_field($field, $data);
|
|
|
|
$str .= $fieldobj->display_add_field($recordid);
|
|
|
|
|
2008-05-31 00:30:00 +00:00
|
|
|
} else { // Just print the tag
|
2006-03-23 10:01:21 +00:00
|
|
|
$str .= '[['.$field->name.']]';
|
|
|
|
}
|
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
|
|
|
$str .= '</td></tr>';
|
2006-11-09 19:44:20 +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-12-13 21:02:01 +00:00
|
|
|
if ($template == 'listtemplate') {
|
2006-12-12 23:34:55 +00:00
|
|
|
$str .= '<tr><td align="center" colspan="2">##edit## ##more## ##delete## ##approve##</td></tr>';
|
2006-12-13 21:02:01 +00:00
|
|
|
} else if ($template == 'singletemplate') {
|
|
|
|
$str .= '<tr><td align="center" colspan="2">##edit## ##delete## ##approve##</td></tr>';
|
2008-04-16 11:51:50 +00:00
|
|
|
} else if ($template == 'asearchtemplate') {
|
|
|
|
$str .= '<tr><td valign="top" align="right">'.get_string('authorfirstname', 'data').': </td><td>##firstname##</td></tr>';
|
|
|
|
$str .= '<tr><td valign="top" align="right">'.get_string('authorlastname', 'data').': </td><td>##lastname##</td></tr>';
|
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-01-19 08:51:34 +00:00
|
|
|
$str .= '</table>';
|
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
|
|
|
$str .= '</div>';
|
|
|
|
|
2006-03-23 10:01:21 +00:00
|
|
|
if ($template == 'listtemplate'){
|
2006-03-27 04:02:48 +00:00
|
|
|
$str .= '<hr />';
|
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-02-06 09:13:37 +00:00
|
|
|
|
2006-03-23 10:01:21 +00:00
|
|
|
if ($update) {
|
2006-12-13 20:26:11 +00:00
|
|
|
$newdata = new object();
|
2006-03-23 10:01:21 +00:00
|
|
|
$newdata->id = $data->id;
|
2006-03-24 02:09:15 +00:00
|
|
|
$newdata->{$template} = $str;
|
2006-03-23 10:01:21 +00:00
|
|
|
if (!update_record('data', $newdata)) {
|
|
|
|
notify('Error updating template');
|
2006-03-25 14:57:36 +00:00
|
|
|
} else {
|
|
|
|
$data->{$template} = $str;
|
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-23 10:01:21 +00:00
|
|
|
|
|
|
|
return $str;
|
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-02-06 09:13:37 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* Search for a field name and replaces it with another one in all the *
|
|
|
|
* form templates. Set $newfieldname as '' if you want to delete the *
|
|
|
|
* field from the form. *
|
|
|
|
***********************************************************************/
|
2006-03-22 08:07:26 +00:00
|
|
|
function data_replace_field_in_templates($data, $searchfieldname, $newfieldname) {
|
2006-02-06 09:13:37 +00:00
|
|
|
if (!empty($newfieldname)) {
|
|
|
|
$prestring = '[[';
|
|
|
|
$poststring = ']]';
|
2006-12-12 20:10:32 +00:00
|
|
|
$idpart = '#id';
|
2006-02-27 04:13:03 +00:00
|
|
|
|
|
|
|
} else {
|
2006-02-06 09:13:37 +00:00
|
|
|
$prestring = '';
|
|
|
|
$poststring = '';
|
2006-12-12 20:10:32 +00:00
|
|
|
$idpart = '';
|
2006-02-06 09:13:37 +00:00
|
|
|
}
|
2006-11-09 19:44:20 +00:00
|
|
|
|
2006-12-12 20:10:32 +00:00
|
|
|
$newdata = new object();
|
2006-02-27 04:13:03 +00:00
|
|
|
$newdata->id = $data->id;
|
2006-12-12 20:10:32 +00:00
|
|
|
$newdata->singletemplate = addslashes(str_ireplace('[['.$searchfieldname.']]',
|
2006-02-27 04:13:03 +00:00
|
|
|
$prestring.$newfieldname.$poststring, $data->singletemplate));
|
2006-11-09 19:44:20 +00:00
|
|
|
|
2006-12-12 20:10:32 +00:00
|
|
|
$newdata->listtemplate = addslashes(str_ireplace('[['.$searchfieldname.']]',
|
2006-02-27 04:13:03 +00:00
|
|
|
$prestring.$newfieldname.$poststring, $data->listtemplate));
|
2006-11-09 19:44:20 +00:00
|
|
|
|
2006-12-12 20:10:32 +00:00
|
|
|
$newdata->addtemplate = addslashes(str_ireplace('[['.$searchfieldname.']]',
|
2006-02-27 04:13:03 +00:00
|
|
|
$prestring.$newfieldname.$poststring, $data->addtemplate));
|
2006-11-09 19:44:20 +00:00
|
|
|
|
2006-12-12 20:10:32 +00:00
|
|
|
$newdata->addtemplate = addslashes(str_ireplace('[['.$searchfieldname.'#id]]',
|
|
|
|
$prestring.$newfieldname.$idpart.$poststring, $data->addtemplate));
|
|
|
|
|
|
|
|
$newdata->rsstemplate = addslashes(str_ireplace('[['.$searchfieldname.']]',
|
2006-02-27 04:13:03 +00:00
|
|
|
$prestring.$newfieldname.$poststring, $data->rsstemplate));
|
2006-11-09 19:44:20 +00:00
|
|
|
|
2006-02-27 04:13:03 +00:00
|
|
|
return update_record('data', $newdata);
|
2006-02-06 09:13:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************************
|
|
|
|
* Appends a new field at the end of the form template. *
|
|
|
|
********************************************************/
|
2006-03-22 08:07:26 +00:00
|
|
|
function data_append_new_field_to_templates($data, $newfieldname) {
|
|
|
|
|
2006-12-12 20:10:32 +00:00
|
|
|
$newdata = new object();
|
2006-03-22 08:07:26 +00:00
|
|
|
$newdata->id = $data->id;
|
2006-03-22 08:32:54 +00:00
|
|
|
$change = false;
|
2006-03-22 08:07:26 +00:00
|
|
|
|
2006-02-06 09:13:37 +00:00
|
|
|
if (!empty($data->singletemplate)) {
|
2006-03-22 08:07:26 +00:00
|
|
|
$newdata->singletemplate = addslashes($data->singletemplate.' [[' . $newfieldname .']]');
|
2006-03-22 08:32:54 +00:00
|
|
|
$change = true;
|
2006-03-22 08:07:26 +00:00
|
|
|
}
|
|
|
|
if (!empty($data->addtemplate)) {
|
|
|
|
$newdata->addtemplate = addslashes($data->addtemplate.' [[' . $newfieldname . ']]');
|
2006-03-22 08:32:54 +00:00
|
|
|
$change = true;
|
2006-02-06 09:13:37 +00:00
|
|
|
}
|
|
|
|
if (!empty($data->rsstemplate)) {
|
2006-03-22 08:07:26 +00:00
|
|
|
$newdata->rsstemplate = addslashes($data->singletemplate.' [[' . $newfieldname . ']]');
|
2006-03-22 08:32:54 +00:00
|
|
|
$change = true;
|
|
|
|
}
|
|
|
|
if ($change) {
|
|
|
|
update_record('data', $newdata);
|
2006-02-06 09:13:37 +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-22 08:07:26 +00:00
|
|
|
* given a field name *
|
|
|
|
* this function creates an instance of the particular subfield class *
|
|
|
|
************************************************************************/
|
|
|
|
function data_get_field_from_name($name, $data){
|
|
|
|
$field = get_record('data_fields','name',$name);
|
|
|
|
|
|
|
|
if ($field) {
|
|
|
|
return data_get_field($field, $data);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* given a field 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
|
|
|
* this function creates an instance of the particular subfield class *
|
|
|
|
************************************************************************/
|
2006-03-22 08:07:26 +00:00
|
|
|
function data_get_field_from_id($fieldid, $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
|
|
|
$field = get_record('data_fields','id',$fieldid);
|
|
|
|
|
2006-03-22 08:07:26 +00:00
|
|
|
if ($field) {
|
|
|
|
return data_get_field($field, $data);
|
2006-02-06 05:31:52 +00:00
|
|
|
} else {
|
2006-02-06 05:36:34 +00:00
|
|
|
return 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-22 08:07:26 +00:00
|
|
|
/************************************************************************
|
|
|
|
* given a field id *
|
|
|
|
* this function creates an instance of the particular subfield class *
|
|
|
|
************************************************************************/
|
|
|
|
function data_get_field_new($type, $data) {
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
require_once($CFG->dirroot.'/mod/data/field/'.$type.'/field.class.php');
|
|
|
|
$newfield = 'data_field_'.$type;
|
|
|
|
$newfield = new $newfield(0, $data);
|
|
|
|
return $newfield;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
/************************************************************************
|
|
|
|
* returns a subclass field object given a record of the field, used to *
|
|
|
|
* invoke plugin methods *
|
|
|
|
* input: $param $field - record from db *
|
|
|
|
************************************************************************/
|
2006-03-22 08:07:26 +00:00
|
|
|
function data_get_field($field, $data) {
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
if ($field) {
|
NEW MODULE FROM MOODLE.COM - DATABASE !
Finally, we have an early version good enough for everyone to
start banging on to help us polish it up and find bugs.
Please take a look and file bugs in the bug tracker under "Database module".
We urgently need
- new icons for existing field types
- testing on PostgreSQL install
Coming soon (?):
- Many more field types: calculation, checkbox, relation, date, datetime,
time, email, group, list, user, number, richtext
(Please let us know if you are interested in developing any of these)
- A way to save and restore "presets", which are field/template sets
- Backup/Restore support
- Groups Support
- RSS support
Many thanks to Yu for all the hard work under my whip.
2005-12-02 07:50:26 +00:00
|
|
|
require_once('field/'.$field->type.'/field.class.php');
|
|
|
|
$newfield = 'data_field_'.$field->type;
|
2006-03-22 08:07:26 +00:00
|
|
|
$newfield = new $newfield($field, $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
|
|
|
return $newfield;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* given record id, returns true if the record belongs to the current user *
|
|
|
|
* input @param $rid - record id *
|
|
|
|
* output bool *
|
|
|
|
***************************************************************************/
|
|
|
|
function data_isowner($rid){
|
|
|
|
global $USER;
|
|
|
|
|
|
|
|
if (empty($USER->id)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($record = get_record('data_records','id',$rid)) {
|
|
|
|
return ($record->userid == $USER->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* has a user reached the max number of entries? *
|
|
|
|
* input object $data *
|
|
|
|
* output bool *
|
|
|
|
***********************************************************************/
|
|
|
|
function data_atmaxentries($data){
|
|
|
|
if (!$data->maxentries){
|
|
|
|
return false;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
return (data_numentries($data) >= $data->maxentries);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* returns the number of entries already made by this user *
|
|
|
|
* input @param object $data *
|
|
|
|
* uses global $CFG, $USER *
|
|
|
|
* output int *
|
|
|
|
**********************************************************************/
|
|
|
|
function data_numentries($data){
|
|
|
|
global $USER;
|
|
|
|
global $CFG;
|
|
|
|
$sql = 'SELECT COUNT(*) FROM '.$CFG->prefix.'data_records WHERE dataid='.$data->id.' AND userid='.$USER->id;
|
|
|
|
return count_records_sql($sql);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************
|
|
|
|
* function that takes in a dataid and adds a record *
|
|
|
|
* this is used everytime an add template is submitted *
|
|
|
|
* input @param int $dataid, $groupid *
|
|
|
|
* output bool *
|
|
|
|
****************************************************************/
|
2006-03-22 08:07:26 +00:00
|
|
|
function data_add_record($data, $groupid=0){
|
|
|
|
global $USER;
|
2006-11-09 19:44:20 +00:00
|
|
|
|
2006-12-06 20:17:58 +00:00
|
|
|
$cm = get_coursemodule_from_instance('data', $data->id);
|
2006-08-08 05:13:06 +00:00
|
|
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
2006-03-22 08:07:26 +00:00
|
|
|
|
2006-12-12 20:10:32 +00:00
|
|
|
$record = new object();
|
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
|
|
|
$record->userid = $USER->id;
|
2006-03-22 08:07:26 +00:00
|
|
|
$record->dataid = $data->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
|
|
|
$record->groupid = $groupid;
|
2006-03-22 08:07:26 +00:00
|
|
|
$record->timecreated = $record->timemodified = time();
|
2006-08-14 05:55:40 +00:00
|
|
|
if (has_capability('mod/data:approve', $context)) {
|
2006-02-06 05:24:02 +00:00
|
|
|
$record->approved = 1;
|
|
|
|
} else {
|
|
|
|
$record->approved = 0;
|
|
|
|
}
|
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
|
|
|
return insert_record('data_records',$record);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* check the multple existence any tag in a template *
|
|
|
|
* input @param string *
|
|
|
|
* output true-valid, false-invalid *
|
|
|
|
* check to see if there are 2 or more of the same tag being used. *
|
|
|
|
* input @param int $dataid, *
|
|
|
|
* @param string $template *
|
|
|
|
* output bool *
|
|
|
|
*******************************************************************/
|
|
|
|
function data_tags_check($dataid, $template){
|
2008-05-31 00:30:00 +00:00
|
|
|
// first get all the possible tags
|
2006-03-29 08:49:28 +00:00
|
|
|
$fields = get_records('data_fields','dataid',$dataid);
|
2008-05-31 00:30:00 +00:00
|
|
|
// then we generate strings to replace
|
|
|
|
$tagsok = true; // let's be optimistic
|
2006-03-29 08:49:28 +00:00
|
|
|
foreach ($fields as $field){
|
2006-03-23 10:01:21 +00:00
|
|
|
$pattern="/\[\[".$field->name."\]\]/i";
|
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 (preg_match_all($pattern, $template, $dummy)>1){
|
|
|
|
$tagsok = false;
|
2006-03-23 10:01:21 +00:00
|
|
|
notify ('[['.$field->name.']] - '.get_string('multipletags','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-05-31 00:30:00 +00:00
|
|
|
// else return true
|
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
|
|
|
return $tagsok;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* Adds an instance of a data *
|
|
|
|
************************************************************************/
|
|
|
|
function data_add_instance($data) {
|
2008-06-01 21:36:11 +00:00
|
|
|
global $CFG, $DB;
|
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-09-24 13:58:54 +00:00
|
|
|
if (empty($data->assessed)) {
|
|
|
|
$data->assessed = 0;
|
2006-02-08 04:58:21 +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
|
|
|
$data->timemodified = time();
|
|
|
|
|
2008-06-01 21:36:11 +00:00
|
|
|
if (! $data->id = $DB->insert_record('data', $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
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-06-05 22:58:37 +00:00
|
|
|
data_grade_item_update($data);
|
2007-06-03 19:36:20 +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
|
|
|
return $data->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* updates an instance of a data *
|
|
|
|
************************************************************************/
|
|
|
|
function data_update_instance($data) {
|
2008-06-01 21:36:11 +00:00
|
|
|
global $CFG, $DB;
|
2006-11-09 19:44:20 +00:00
|
|
|
|
2007-06-03 19:36:20 +00:00
|
|
|
$data->timemodified = time();
|
|
|
|
$data->id = $data->instance;
|
2006-11-09 19:44:20 +00:00
|
|
|
|
2006-09-24 13:58:54 +00:00
|
|
|
if (empty($data->assessed)) {
|
|
|
|
$data->assessed = 0;
|
2006-02-08 04:56:44 +00:00
|
|
|
}
|
2006-11-09 19:44:20 +00:00
|
|
|
|
2008-04-24 17:11:40 +00:00
|
|
|
if (empty($data->notification)) {
|
|
|
|
$data->notification = 0;
|
|
|
|
}
|
|
|
|
|
2008-06-01 21:36:11 +00:00
|
|
|
if (! $DB->update_record('data', $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
|
|
|
return false;
|
|
|
|
}
|
2007-06-03 19:36:20 +00:00
|
|
|
|
|
|
|
data_grade_item_update($data);
|
|
|
|
|
|
|
|
return true;
|
2006-11-09 19:44:20 +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
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* deletes an instance of a data *
|
|
|
|
************************************************************************/
|
2008-05-31 00:30:00 +00:00
|
|
|
function data_delete_instance($id) { // takes the dataid
|
2008-06-01 21:36:11 +00:00
|
|
|
global $CFG, $DB;
|
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-01 21:36:11 +00:00
|
|
|
if (! $data = $DB->get_record('data', array('id'=>$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
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-05-31 00:30:00 +00:00
|
|
|
// Delete all the associated information
|
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
|
|
|
|
|
|
|
// get all the records in this data
|
2008-06-01 21:36:11 +00:00
|
|
|
$sql = 'SELECT c.* FROM {data_records} r LEFT JOIN {data_content} c ON c.recordid = r.id WHERE r.dataid =?';
|
2006-11-09 19:44:20 +00:00
|
|
|
|
2008-06-01 21:36:11 +00:00
|
|
|
if ($contents = $DB->get_records_sql($sql, array($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
|
|
|
|
|
|
|
foreach($contents as $content){
|
2006-11-09 19:44:20 +00:00
|
|
|
|
2008-06-01 21:36:11 +00:00
|
|
|
$field = $DB->get_record('data_fields', array('id'=>$content->fieldid));
|
2006-03-22 08:07:26 +00:00
|
|
|
if ($g = data_get_field($field, $data)){
|
|
|
|
$g->delete_content_files($id, $content->recordid, $content->content);
|
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
|
|
|
}
|
|
|
|
//delete the content itself
|
2008-06-01 21:36:11 +00:00
|
|
|
$DB->delete_records('data_content', array('id'=>$content->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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// delete all the records and fields
|
2008-06-01 21:36:11 +00:00
|
|
|
$DB->delete_records('data_records', array('dataid'=>$id));
|
|
|
|
$DB->delete_records('data_fields', array('dataid'=>$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
|
|
|
|
|
|
|
// Delete the instance itself
|
|
|
|
|
2008-06-01 21:36:11 +00:00
|
|
|
$result = $DB->delete_records('data', array('id'=>$id));
|
2007-06-03 19:36:20 +00:00
|
|
|
|
2007-07-08 14:58:23 +00:00
|
|
|
data_grade_item_delete($data);
|
2007-06-03 19:36:20 +00:00
|
|
|
|
|
|
|
return $result;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* returns a summary of data activity of this user *
|
|
|
|
************************************************************************/
|
|
|
|
function data_user_outline($course, $user, $mod, $data) {
|
2006-04-07 07:02:53 +00:00
|
|
|
global $CFG;
|
|
|
|
if ($countrecords = count_records('data_records', 'dataid', $data->id, 'userid', $user->id)) {
|
2006-12-12 20:10:32 +00:00
|
|
|
$result = new object();
|
2006-04-07 07:02:53 +00:00
|
|
|
$result->info = get_string('numrecords', 'data', $countrecords);
|
2006-11-09 19:44:20 +00:00
|
|
|
$lastrecord = get_record_sql('SELECT id,timemodified FROM '.$CFG->prefix.'data_records
|
|
|
|
WHERE dataid = '.$data->id.' AND userid = '.$user->id.'
|
2006-04-07 07:02:53 +00:00
|
|
|
ORDER BY timemodified DESC', true);
|
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
|
|
|
$result->time = $lastrecord->timemodified;
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* Prints all the records uploaded by this user *
|
|
|
|
************************************************************************/
|
|
|
|
function data_user_complete($course, $user, $mod, $data) {
|
2006-11-09 19:44:20 +00:00
|
|
|
if ($records = get_records_select('data_records', 'dataid = '.$data->id.' AND userid = '.$user->id,
|
2006-04-07 07:02:53 +00:00
|
|
|
'timemodified DESC')) {
|
2006-03-29 08:49:28 +00:00
|
|
|
data_print_template('singletemplate', $records, $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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-03 19:36:20 +00:00
|
|
|
/**
|
|
|
|
* Return grade for given user or all users.
|
|
|
|
*
|
|
|
|
* @param int $dataid id of data
|
|
|
|
* @param int $userid optional user id, 0 means all users
|
|
|
|
* @return array array of grades, false if none
|
|
|
|
*/
|
2007-06-05 22:58:37 +00:00
|
|
|
function data_get_user_grades($data, $userid=0) {
|
2007-06-03 19:36:20 +00:00
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
$user = $userid ? "AND u.id = $userid" : "";
|
|
|
|
|
2007-06-20 23:06:29 +00:00
|
|
|
$sql = "SELECT u.id, u.id AS userid, avg(drt.rating) AS rawgrade
|
2007-06-03 19:36:20 +00:00
|
|
|
FROM {$CFG->prefix}user u, {$CFG->prefix}data_records dr,
|
|
|
|
{$CFG->prefix}data_ratings drt
|
|
|
|
WHERE u.id = dr.userid AND dr.id = drt.recordid
|
2007-06-05 22:58:37 +00:00
|
|
|
AND drt.userid != u.id AND dr.dataid = $data->id
|
2007-06-03 19:36:20 +00:00
|
|
|
$user
|
|
|
|
GROUP BY u.id";
|
|
|
|
|
|
|
|
return get_records_sql($sql);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update grades by firing grade_updated event
|
|
|
|
*
|
2007-06-05 22:58:37 +00:00
|
|
|
* @param object $data null means all databases
|
2007-06-03 19:36:20 +00:00
|
|
|
* @param int $userid specific user only, 0 mean all
|
|
|
|
*/
|
2007-06-05 22:58:37 +00:00
|
|
|
function data_update_grades($data=null, $userid=0, $nullifnone=true) {
|
2007-06-03 19:36:20 +00:00
|
|
|
global $CFG;
|
2007-06-05 22:58:37 +00:00
|
|
|
if (!function_exists('grade_update')) { //workaround for buggy PHP versions
|
|
|
|
require_once($CFG->libdir.'/gradelib.php');
|
|
|
|
}
|
2007-06-03 19:36:20 +00:00
|
|
|
|
2007-06-05 22:58:37 +00:00
|
|
|
if ($data != null) {
|
|
|
|
if ($grades = data_get_user_grades($data, $userid)) {
|
2007-12-25 20:51:23 +00:00
|
|
|
data_grade_item_update($data, $grades);
|
2007-06-03 19:36:20 +00:00
|
|
|
|
|
|
|
} else if ($userid and $nullifnone) {
|
2007-06-05 22:58:37 +00:00
|
|
|
$grade = new object();
|
2007-08-10 21:01:46 +00:00
|
|
|
$grade->userid = $userid;
|
2007-06-20 23:06:29 +00:00
|
|
|
$grade->rawgrade = NULL;
|
2007-12-25 20:51:23 +00:00
|
|
|
data_grade_item_update($data, $grade);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
data_grade_item_update($data);
|
2007-06-03 19:36:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$sql = "SELECT d.*, cm.idnumber as cmidnumber
|
|
|
|
FROM {$CFG->prefix}data d, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m
|
|
|
|
WHERE m.name='data' AND m.id=cm.module AND cm.instance=d.id";
|
|
|
|
if ($rs = get_recordset_sql($sql)) {
|
2007-10-10 12:19:27 +00:00
|
|
|
while ($data = rs_fetch_next_record($rs)) {
|
|
|
|
if ($data->assessed) {
|
|
|
|
data_update_grades($data, 0, false);
|
2007-12-25 20:51:23 +00:00
|
|
|
} else {
|
|
|
|
data_grade_item_update($data);
|
2007-06-03 19:36:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
rs_close($rs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-06-05 22:58:37 +00:00
|
|
|
* Update/create grade item for given data
|
2007-06-03 19:36:20 +00:00
|
|
|
*
|
|
|
|
* @param object $data object with extra cmidnumber
|
2007-11-29 14:43:04 +00:00
|
|
|
* @param mixed optional array/object of grade(s); 'reset' means reset grades in gradebook
|
2007-06-03 19:36:20 +00:00
|
|
|
* @return object grade_item
|
|
|
|
*/
|
2007-11-29 14:43:04 +00:00
|
|
|
function data_grade_item_update($data, $grades=NULL) {
|
2007-06-05 22:58:37 +00:00
|
|
|
global $CFG;
|
|
|
|
if (!function_exists('grade_update')) { //workaround for buggy PHP versions
|
|
|
|
require_once($CFG->libdir.'/gradelib.php');
|
2007-06-03 19:36:20 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 10:52:59 +00:00
|
|
|
$params = array('itemname'=>$data->name, 'idnumber'=>$data->cmidnumber);
|
2007-06-03 19:36:20 +00:00
|
|
|
|
|
|
|
if (!$data->assessed or $data->scale == 0) {
|
2007-06-05 22:58:37 +00:00
|
|
|
$params['gradetype'] = GRADE_TYPE_NONE;
|
2007-06-03 19:36:20 +00:00
|
|
|
|
|
|
|
} else if ($data->scale > 0) {
|
|
|
|
$params['gradetype'] = GRADE_TYPE_VALUE;
|
|
|
|
$params['grademax'] = $data->scale;
|
|
|
|
$params['grademin'] = 0;
|
|
|
|
|
|
|
|
} else if ($data->scale < 0) {
|
|
|
|
$params['gradetype'] = GRADE_TYPE_SCALE;
|
|
|
|
$params['scaleid'] = -$data->scale;
|
|
|
|
}
|
|
|
|
|
2007-11-29 14:43:04 +00:00
|
|
|
if ($grades === 'reset') {
|
|
|
|
$params['reset'] = true;
|
|
|
|
$grades = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return grade_update('mod/data', $data->course, 'mod', 'data', $data->id, 0, $grades, $params);
|
2007-06-03 19:36:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete grade item for given data
|
|
|
|
*
|
|
|
|
* @param object $data object
|
|
|
|
* @return object grade_item
|
|
|
|
*/
|
|
|
|
function data_grade_item_delete($data) {
|
2007-06-05 22:58:37 +00:00
|
|
|
global $CFG;
|
|
|
|
require_once($CFG->libdir.'/gradelib.php');
|
|
|
|
|
2007-06-06 23:04:24 +00:00
|
|
|
return grade_update('mod/data', $data->course, 'mod', 'data', $data->id, 0, NULL, array('deleted'=>1));
|
2007-06-03 19:36:20 +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
|
|
|
/************************************************************************
|
|
|
|
* returns a list of participants of this database *
|
|
|
|
************************************************************************/
|
|
|
|
function data_get_participants($dataid) {
|
2008-05-31 00:30:00 +00:00
|
|
|
// Returns the users with data in one data
|
|
|
|
// (users with records in data_records, data_comments and data_ratings)
|
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
|
|
|
global $CFG;
|
|
|
|
|
2006-05-23 22:33:01 +00:00
|
|
|
$records = get_records_sql("SELECT DISTINCT u.id, u.id
|
|
|
|
FROM {$CFG->prefix}user u,
|
|
|
|
{$CFG->prefix}data_records r
|
|
|
|
WHERE r.dataid = '$dataid'
|
|
|
|
AND u.id = r.userid");
|
|
|
|
|
|
|
|
$comments = get_records_sql("SELECT DISTINCT u.id, u.id
|
|
|
|
FROM {$CFG->prefix}user u,
|
|
|
|
{$CFG->prefix}data_records r,
|
|
|
|
{$CFG->prefix}data_comments c
|
|
|
|
WHERE r.dataid = '$dataid'
|
2006-11-09 19:44:20 +00:00
|
|
|
AND u.id = r.userid
|
2006-05-23 22:33:01 +00:00
|
|
|
AND r.id = c.recordid");
|
|
|
|
|
|
|
|
$ratings = get_records_sql("SELECT DISTINCT u.id, u.id
|
|
|
|
FROM {$CFG->prefix}user u,
|
|
|
|
{$CFG->prefix}data_records r,
|
|
|
|
{$CFG->prefix}data_ratings a
|
|
|
|
WHERE r.dataid = '$dataid'
|
2006-11-09 19:44:20 +00:00
|
|
|
AND u.id = r.userid
|
2006-05-23 22:33:01 +00:00
|
|
|
AND r.id = a.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
|
|
|
$participants = array();
|
2006-11-09 19:44:20 +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 ($records){
|
|
|
|
foreach ($records as $record) {
|
|
|
|
$participants[$record->id] = $record;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($comments){
|
|
|
|
foreach ($comments as $comment) {
|
|
|
|
$participants[$comment->id] = $comment;
|
|
|
|
}
|
|
|
|
}
|
2006-05-23 22:33:01 +00:00
|
|
|
if ($ratings){
|
|
|
|
foreach ($ratings as $rating) {
|
|
|
|
$participants[$rating->id] = $rating;
|
|
|
|
}
|
|
|
|
}
|
2006-11-09 19:44:20 +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
|
|
|
return $participants;
|
|
|
|
}
|
|
|
|
|
2008-05-31 00:30:00 +00:00
|
|
|
// junk functions
|
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
|
|
|
/************************************************************************
|
|
|
|
* takes a list of records, the current data, a search string, *
|
|
|
|
* and mode to display prints the translated template *
|
|
|
|
* input @param array $records *
|
|
|
|
* @param object $data *
|
|
|
|
* @param string $search *
|
2006-02-06 02:49:46 +00:00
|
|
|
* @param string $template *
|
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
|
|
|
* output null *
|
|
|
|
************************************************************************/
|
2006-04-05 01:38:06 +00:00
|
|
|
function data_print_template($template, $records, $data, $search='',$page=0, $return=false) {
|
2006-03-29 08:49:28 +00:00
|
|
|
global $CFG;
|
|
|
|
|
2006-12-06 20:17:58 +00:00
|
|
|
$cm = get_coursemodule_from_instance('data', $data->id);
|
2006-08-09 13:45:49 +00:00
|
|
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
2006-08-08 05:13:06 +00:00
|
|
|
|
2006-03-29 08:49:28 +00:00
|
|
|
static $fields = NULL;
|
|
|
|
static $isteacher;
|
2006-04-07 07:02:53 +00:00
|
|
|
static $dataid = NULL;
|
|
|
|
|
|
|
|
if (empty($dataid)) {
|
|
|
|
$dataid = $data->id;
|
|
|
|
} else if ($dataid != $data->id) {
|
|
|
|
$fields = NULL;
|
|
|
|
}
|
2006-03-29 08:49:28 +00:00
|
|
|
|
|
|
|
if (empty($fields)) {
|
|
|
|
$fieldrecords = get_records('data_fields','dataid', $data->id);
|
|
|
|
foreach ($fieldrecords as $fieldrecord) {
|
|
|
|
$fields[]= data_get_field($fieldrecord, $data);
|
|
|
|
}
|
2006-08-30 08:43:17 +00:00
|
|
|
$isteacher = has_capability('mod/data:managetemplates', $context);
|
2006-03-29 08:49:28 +00:00
|
|
|
}
|
|
|
|
|
2006-04-05 01:38:06 +00:00
|
|
|
if (empty($records)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-05-31 09:51:48 +00:00
|
|
|
foreach ($records as $record) { // Might be just one for the single template
|
2006-02-03 08:11:36 +00:00
|
|
|
|
2008-05-31 00:30:00 +00:00
|
|
|
// Replacing tags
|
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
|
|
|
$patterns = array();
|
|
|
|
$replacement = array();
|
|
|
|
|
2008-05-31 00:30:00 +00:00
|
|
|
// Then we generate strings to replace for normal tags
|
2006-03-29 08:49:28 +00:00
|
|
|
foreach ($fields as $field) {
|
2006-12-08 22:29:11 +00:00
|
|
|
$patterns[]='[['.$field->field->name.']]';
|
2006-03-23 10:01:21 +00:00
|
|
|
$replacement[] = highlight($search, $field->display_browse_field($record->id, $template));
|
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-02-03 08:11:36 +00:00
|
|
|
|
2008-05-31 00:30:00 +00:00
|
|
|
// Replacing special tags (##Edit##, ##Delete##, ##More##)
|
2006-12-12 23:34:55 +00:00
|
|
|
$patterns[]='##edit##';
|
|
|
|
$patterns[]='##delete##';
|
2008-04-17 08:11:23 +00:00
|
|
|
if (has_capability('mod/data:manageentries', $context) or data_isowner($record->id)) {
|
2006-04-05 01:38:06 +00:00
|
|
|
$replacement[] = '<a href="'.$CFG->wwwroot.'/mod/data/edit.php?d='
|
2007-01-08 09:14:05 +00:00
|
|
|
.$data->id.'&rid='.$record->id.'&sesskey='.sesskey().'"><img src="'.$CFG->pixpath.'/t/edit.gif" class="iconsmall" alt="'.get_string('edit').'" title="'.get_string('edit').'" /></a>';
|
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
|
|
|
$replacement[] = '<a href="'.$CFG->wwwroot.'/mod/data/view.php?d='
|
2007-01-08 09:14:05 +00:00
|
|
|
.$data->id.'&delete='.$record->id.'&sesskey='.sesskey().'"><img src="'.$CFG->pixpath.'/t/delete.gif" class="iconsmall" alt="'.get_string('delete').'" title="'.get_string('delete').'" /></a>';
|
2008-04-17 08:11:23 +00:00
|
|
|
} else {
|
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
|
|
|
$replacement[] = '';
|
2008-04-19 15:33:06 +00:00
|
|
|
$replacement[] = '';
|
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-12-12 23:34:55 +00:00
|
|
|
$patterns[]='##more##';
|
2007-01-08 09:14:05 +00:00
|
|
|
$replacement[] = '<a href="'.$CFG->wwwroot.'/mod/data/view.php?d='.$data->id.'&rid='.$record->id.'"><img src="'.$CFG->pixpath.'/i/search.gif" class="iconsmall" alt="'.get_string('more', 'data').'" title="'.get_string('more', 'data').'" /></a>';
|
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-12-12 23:34:55 +00:00
|
|
|
$patterns[]='##moreurl##';
|
2006-03-29 08:49:28 +00:00
|
|
|
$replacement[] = $CFG->wwwroot.'/mod/data/view.php?d='.$data->id.'&rid='.$record->id;
|
2006-03-26 05:03:10 +00:00
|
|
|
|
2006-12-12 23:34:55 +00:00
|
|
|
$patterns[]='##user##';
|
2006-04-05 01:38:06 +00:00
|
|
|
$replacement[] = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$record->userid.
|
|
|
|
'&course='.$data->course.'">'.fullname($record).'</a>';
|
2008-04-11 02:34:11 +00:00
|
|
|
|
|
|
|
$patterns[] = '##timeadded##';
|
2008-04-11 03:13:54 +00:00
|
|
|
$replacement[] = userdate($record->timecreated);
|
2008-04-11 02:34:11 +00:00
|
|
|
|
|
|
|
$patterns[] = '##timemodified##';
|
2008-04-11 03:13:54 +00:00
|
|
|
$replacement [] = userdate($record->timemodified);
|
2006-03-26 05:03:10 +00:00
|
|
|
|
2006-12-12 23:34:55 +00:00
|
|
|
$patterns[]='##approve##';
|
2006-08-14 05:55:40 +00:00
|
|
|
if (has_capability('mod/data:approve', $context) && ($data->approval) && (!$record->approved)){
|
2008-04-22 13:35:51 +00:00
|
|
|
$replacement[] = '<span class="approve"><a href="'.$CFG->wwwroot.'/mod/data/view.php?d='.$data->id.'&approve='.$record->id.'&sesskey='.sesskey().'"><img src="'.$CFG->pixpath.'/i/approve.gif" class="icon" alt="'.get_string('approve').'" /></a></span>';
|
2006-03-26 05:03:10 +00:00
|
|
|
} else {
|
2006-02-06 05:24:02 +00:00
|
|
|
$replacement[] = '';
|
|
|
|
}
|
2006-11-09 19:44:20 +00:00
|
|
|
|
2006-12-12 23:34:55 +00:00
|
|
|
$patterns[]='##comments##';
|
2006-02-14 03:17:21 +00:00
|
|
|
if (($template == 'listtemplate') && ($data->comments)) {
|
|
|
|
$comments = count_records('data_comments','recordid',$record->id);
|
2006-04-05 01:40:24 +00:00
|
|
|
$replacement[] = '<a href="view.php?rid='.$record->id.'#comments">'.get_string('commentsn','data', $comments).'</a>';
|
2006-02-14 03:17:21 +00:00
|
|
|
} else {
|
|
|
|
$replacement[] = '';
|
|
|
|
}
|
2006-02-06 05:24:02 +00:00
|
|
|
|
2008-05-31 00:30:00 +00:00
|
|
|
// actual replacement of the tags
|
2006-12-08 22:29:11 +00:00
|
|
|
$newtext = str_ireplace($patterns, $replacement, $data->{$template});
|
2006-12-11 09:35:27 +00:00
|
|
|
|
2008-05-31 00:30:00 +00:00
|
|
|
// no more html formatting and filtering - see MDL-6635
|
2006-12-17 21:48:51 +00:00
|
|
|
if ($return) {
|
|
|
|
return $newtext;
|
|
|
|
} else {
|
|
|
|
echo $newtext;
|
|
|
|
|
|
|
|
// hack alert - return is always false in singletemplate anyway ;-)
|
|
|
|
/**********************************
|
|
|
|
* Printing Ratings Form *
|
|
|
|
*********************************/
|
|
|
|
if ($template == 'singletemplate') { //prints ratings options
|
|
|
|
data_print_ratings($data, $record);
|
|
|
|
}
|
2006-12-28 15:43:47 +00:00
|
|
|
|
2006-12-17 21:48:51 +00:00
|
|
|
/**********************************
|
|
|
|
* Printing Ratings Form *
|
|
|
|
*********************************/
|
|
|
|
if (($template == 'singletemplate') && ($data->comments)) { //prints ratings options
|
2006-12-28 15:43:47 +00:00
|
|
|
|
2006-12-17 21:48:51 +00:00
|
|
|
data_print_comments($data, $record, $page);
|
|
|
|
}
|
2006-02-14 03:17:21 +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-02-13 07:57:54 +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
|
|
|
/************************************************************************
|
|
|
|
* function that takes in the current data, number of items per page, *
|
|
|
|
* a search string and prints a preference box in view.php *
|
2007-02-26 06:56:05 +00:00
|
|
|
* *
|
|
|
|
* This preference box prints a searchable advanced search template if *
|
2007-02-28 06:23:25 +00:00
|
|
|
* a) A template is defined *
|
|
|
|
* b) The advanced search checkbox is checked. *
|
|
|
|
* *
|
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
|
|
|
* input @param object $data *
|
|
|
|
* @param int $perpage *
|
|
|
|
* @param string $search *
|
|
|
|
* output null *
|
|
|
|
************************************************************************/
|
2007-02-26 06:56:05 +00:00
|
|
|
function data_print_preference_form($data, $perpage, $search, $sort='', $order='ASC', $search_array = '', $advanced = 0, $mode= ''){
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
$cm = get_coursemodule_from_instance('data', $data->id);
|
|
|
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
|
|
|
echo '<br /><div class="datapreferences">';
|
2007-01-04 21:32:36 +00:00
|
|
|
echo '<form id="options" action="view.php" method="get">';
|
2007-02-26 06:56:05 +00:00
|
|
|
echo '<div>';
|
2006-03-26 05:03:10 +00:00
|
|
|
echo '<input type="hidden" name="d" value="'.$data->id.'" />';
|
2007-02-26 06:56:05 +00:00
|
|
|
if ($mode =='asearch') {
|
|
|
|
$advanced = 1;
|
|
|
|
echo '<input type="hidden" name="mode" value="list" />';
|
|
|
|
}
|
2006-12-13 09:22:47 +00:00
|
|
|
echo '<label for="pref_perpage">'.get_string('pagesize','data').'</label> ';
|
2006-12-13 09:38:46 +00:00
|
|
|
$pagesizes = array(2=>2,3=>3,4=>4,5=>5,6=>6,7=>7,8=>8,9=>9,10=>10,15=>15,
|
2006-02-06 05:24:02 +00:00
|
|
|
20=>20,30=>30,40=>40,50=>50,100=>100,200=>200,300=>300,400=>400,500=>500,1000=>1000);
|
2006-12-13 09:38:46 +00:00
|
|
|
choose_from_menu($pagesizes, 'perpage', $perpage, '', '', '0', false, false, 0, 'pref_perpage');
|
2007-02-26 06:56:05 +00:00
|
|
|
echo '<div id="reg_search" style="display: ';
|
|
|
|
if ($advanced) {
|
|
|
|
echo 'none';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
echo 'inline';
|
|
|
|
}
|
|
|
|
echo ';" > <label for="pref_search">'.get_string('search').'</label> <input type="text" size="16" name="search" id= "pref_search" value="'.s($search).'" /></div>';
|
2006-12-13 09:22:47 +00:00
|
|
|
echo ' <label for="pref_sortby">'.get_string('sortby').'</label> ';
|
2008-05-31 00:30:00 +00:00
|
|
|
// foreach field, print the option
|
2008-04-21 14:17:02 +00:00
|
|
|
echo '<select name="sort" id="pref_sortby">';
|
|
|
|
if ($fields = get_records('data_fields','dataid',$data->id, 'name')) {
|
|
|
|
echo '<optgroup label="'.get_string('fields', 'data').'">';
|
|
|
|
foreach ($fields as $field) {
|
|
|
|
if ($field->id == $sort) {
|
|
|
|
echo '<option value="'.$field->id.'" selected="selected">'.$field->name.'</option>';
|
|
|
|
} else {
|
|
|
|
echo '<option value="'.$field->id.'">'.$field->name.'</option>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
echo '</optgroup>';
|
2008-04-16 11:51:50 +00:00
|
|
|
}
|
2008-04-21 14:17:02 +00:00
|
|
|
$options = array();
|
|
|
|
$options[DATA_TIMEADDED] = get_string('timeadded', 'data');
|
|
|
|
$options[DATA_TIMEMODIFIED] = get_string('timemodified', 'data');
|
|
|
|
$options[DATA_FIRSTNAME] = get_string('authorfirstname', 'data');
|
|
|
|
$options[DATA_LASTNAME] = get_string('authorlastname', 'data');
|
2008-04-19 20:48:48 +00:00
|
|
|
if ($data->approval and has_capability('mod/data:approve', $context)) {
|
|
|
|
$options[DATA_APPROVED] = get_string('approved', 'data');
|
|
|
|
}
|
2008-04-21 14:17:02 +00:00
|
|
|
echo '<optgroup label="'.get_string('other', 'data').'">';
|
2008-04-16 11:51:50 +00:00
|
|
|
foreach ($options as $key => $name) {
|
|
|
|
if ($key == $sort) {
|
|
|
|
echo '<option value="'.$key.'" selected="selected">'.$name.'</option>';
|
2006-02-03 08:11:36 +00:00
|
|
|
} else {
|
2008-04-16 11:51:50 +00:00
|
|
|
echo '<option value="'.$key.'">'.$name.'</option>';
|
2006-02-03 08:11:36 +00:00
|
|
|
}
|
|
|
|
}
|
2008-04-21 14:17:02 +00:00
|
|
|
echo '</optgroup>';
|
2006-02-03 08:11:36 +00:00
|
|
|
echo '</select>';
|
2006-12-13 09:22:47 +00:00
|
|
|
echo '<label for="pref_order" class="accesshide">'.get_string('order').'</label>';
|
|
|
|
echo '<select id="pref_order" name="order">';
|
2006-03-26 15:54:41 +00:00
|
|
|
if ($order == 'ASC') {
|
2006-02-20 02:15:45 +00:00
|
|
|
echo '<option value="ASC" selected="selected">'.get_string('ascending','data').'</option>';
|
2006-02-03 08:11:36 +00:00
|
|
|
} else {
|
|
|
|
echo '<option value="ASC">'.get_string('ascending','data').'</option>';
|
|
|
|
}
|
2006-03-26 15:54:41 +00:00
|
|
|
if ($order == 'DESC') {
|
2006-02-20 02:15:45 +00:00
|
|
|
echo '<option value="DESC" selected="selected">'.get_string('descending','data').'</option>';
|
2006-02-03 08:11:36 +00:00
|
|
|
} else {
|
|
|
|
echo '<option value="DESC">'.get_string('descending','data').'</option>';
|
|
|
|
}
|
2006-02-20 02:15:45 +00:00
|
|
|
echo '</select>';
|
2007-02-28 06:23:25 +00:00
|
|
|
|
2007-02-26 06:56:05 +00:00
|
|
|
if ($advanced) {
|
|
|
|
$checked = ' checked="checked" ';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$checked = '';
|
|
|
|
}
|
|
|
|
print '
|
2007-02-28 06:23:25 +00:00
|
|
|
|
2007-02-26 06:56:05 +00:00
|
|
|
<script type="text/javascript">
|
|
|
|
//<![CDATA[
|
|
|
|
<!-- Start
|
|
|
|
// javascript for hiding/displaying advanced search form
|
|
|
|
|
|
|
|
function showHideAdvSearch(checked) {
|
|
|
|
var divs = document.getElementsByTagName(\'div\');
|
|
|
|
for(i=0;i<divs.length;i++) {
|
|
|
|
if(divs[i].id.match(\'data_adv_form\')) {
|
|
|
|
if(checked) {
|
|
|
|
divs[i].style.display = \'inline\';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
divs[i].style.display = \'none\';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (divs[i].id.match(\'reg_search\')) {
|
|
|
|
if (!checked) {
|
|
|
|
divs[i].style.display = \'inline\';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
divs[i].style.display = \'none\';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// End -->
|
|
|
|
//]]>
|
|
|
|
</script>';
|
2008-04-16 13:54:01 +00:00
|
|
|
echo ' <input type="hidden" name="advanced" value="0" />';
|
2008-04-16 11:51:50 +00:00
|
|
|
echo ' <input type="checkbox" id="advancedcheckbox" name="advanced" value="1" '.$checked.' onchange="showHideAdvSearch(this.checked);" /><label for="advancedcheckbox">'.get_string('advancedsearch', 'data').'</label>';
|
2007-02-26 06:56:05 +00:00
|
|
|
echo ' <input type="submit" value="'.get_string('savesettings','data').'" />';
|
|
|
|
|
|
|
|
echo '<br />';
|
2007-02-28 06:23:25 +00:00
|
|
|
echo '<div class="dataadvancedsearch" id="data_adv_form" style="display: ';
|
|
|
|
|
2007-02-26 06:56:05 +00:00
|
|
|
if ($advanced) {
|
|
|
|
echo 'inline';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
echo 'none';
|
|
|
|
}
|
2007-02-28 06:23:25 +00:00
|
|
|
echo ';margin-left:auto;margin-right:auto;" >';
|
2007-02-26 06:56:05 +00:00
|
|
|
echo '<table class="boxaligncenter">';
|
|
|
|
|
|
|
|
// print ASC or DESC
|
|
|
|
echo '<tr><td colspan="2"> </td></tr>';
|
|
|
|
$i = 0;
|
|
|
|
|
|
|
|
// Determine if we are printing all fields for advanced search, or the template for advanced search
|
|
|
|
// If a template is not defined, use the deafault template and display all fields.
|
|
|
|
if(empty($data->asearchtemplate)) {
|
|
|
|
data_generate_default_template($data, 'asearchtemplate');
|
|
|
|
}
|
|
|
|
|
|
|
|
static $fields = NULL;
|
|
|
|
static $isteacher;
|
|
|
|
static $dataid = NULL;
|
|
|
|
|
|
|
|
if (empty($dataid)) {
|
|
|
|
$dataid = $data->id;
|
|
|
|
} else if ($dataid != $data->id) {
|
|
|
|
$fields = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($fields)) {
|
|
|
|
$fieldrecords = get_records('data_fields','dataid', $data->id);
|
|
|
|
foreach ($fieldrecords as $fieldrecord) {
|
|
|
|
$fields[]= data_get_field($fieldrecord, $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
$isteacher = has_capability('mod/data:managetemplates', $context);
|
|
|
|
}
|
|
|
|
|
2008-05-31 00:30:00 +00:00
|
|
|
// Replacing tags
|
2007-02-26 06:56:05 +00:00
|
|
|
$patterns = array();
|
|
|
|
$replacement = array();
|
|
|
|
|
2008-05-31 00:30:00 +00:00
|
|
|
// Then we generate strings to replace for normal tags
|
2007-02-26 06:56:05 +00:00
|
|
|
foreach ($fields as $field) {
|
2008-05-24 11:09:42 +00:00
|
|
|
$fieldname = $field->field->name;
|
|
|
|
$fieldname = preg_quote($fieldname, '/');
|
|
|
|
$patterns[] = "/\[\[$fieldname\]\]/i";
|
2008-04-16 11:51:50 +00:00
|
|
|
$searchfield = data_get_field_from_id($field->field->id, $data);
|
2007-02-26 06:56:05 +00:00
|
|
|
if (!empty($search_array[$field->field->id]->data)) {
|
|
|
|
$replacement[] = $searchfield->display_search_field($search_array[$field->field->id]->data);
|
|
|
|
} else {
|
|
|
|
$replacement[] = $searchfield->display_search_field();
|
|
|
|
}
|
|
|
|
}
|
2008-04-16 11:51:50 +00:00
|
|
|
$fn = !empty($search_array[DATA_FIRSTNAME]->data) ? $search_array[DATA_FIRSTNAME]->data : '';
|
|
|
|
$ln = !empty($search_array[DATA_LASTNAME]->data) ? $search_array[DATA_LASTNAME]->data : '';
|
|
|
|
$patterns[] = '/##firstname##/';
|
2008-04-19 16:44:08 +00:00
|
|
|
$replacement[] = '<input type="text" size="16" name="u_fn" value="'.$fn.'" />';
|
2008-04-16 11:51:50 +00:00
|
|
|
$patterns[] = '/##lastname##/';
|
2008-04-19 16:44:08 +00:00
|
|
|
$replacement[] = '<input type="text" size="16" name="u_ln" value="'.$ln.'" />';
|
2008-04-16 11:51:50 +00:00
|
|
|
|
2008-05-31 09:51:48 +00:00
|
|
|
// actual replacement of the tags
|
2007-02-26 06:56:05 +00:00
|
|
|
$newtext = preg_replace($patterns, $replacement, $data->asearchtemplate);
|
2008-04-16 11:51:50 +00:00
|
|
|
|
2007-08-20 14:04:10 +00:00
|
|
|
$options = new object();
|
2007-02-26 06:56:05 +00:00
|
|
|
$options->para=false;
|
|
|
|
$options->noclean=true;
|
|
|
|
echo '<tr><td>';
|
|
|
|
echo format_text($newtext, FORMAT_HTML, $options);
|
|
|
|
echo '</td></tr>';
|
|
|
|
|
2008-04-19 15:33:06 +00:00
|
|
|
echo '<tr><td colspan="4" style="text-align: center;"><br/><input type="submit" value="'.get_string('savesettings','data').'" /><input type="submit" name="resetadv" value="'.get_string('resetsettings','data').'" /></td></tr>';
|
2007-02-26 06:56:05 +00:00
|
|
|
echo '</table>';
|
2006-03-26 15:54:41 +00:00
|
|
|
echo '</div>';
|
2007-02-26 06:56:05 +00:00
|
|
|
echo '</div>';
|
|
|
|
echo '</form>';
|
2008-05-31 00:30:00 +00:00
|
|
|
echo '</div>';
|
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-01-31 03:58:42 +00:00
|
|
|
|
2006-02-14 03:17:21 +00:00
|
|
|
function data_print_ratings($data, $record) {
|
2006-03-29 08:49:28 +00:00
|
|
|
global $USER;
|
|
|
|
|
2006-12-06 20:17:58 +00:00
|
|
|
$cm = get_coursemodule_from_instance('data', $data->id);
|
2006-08-09 13:45:49 +00:00
|
|
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
2006-11-09 19:44:20 +00:00
|
|
|
|
2007-02-26 06:56:05 +00:00
|
|
|
if ($data->assessed and !empty($USER->id) and (has_capability('mod/data:rate', $context) or has_capability('mod/data:viewrating', $context) or data_isowner($record->id))) {
|
2006-12-07 20:06:11 +00:00
|
|
|
if ($ratingsscale = make_grades_menu($data->scale)) {
|
|
|
|
$ratingsmenuused = false;
|
2006-02-14 03:17:21 +00:00
|
|
|
|
2007-01-05 02:38:09 +00:00
|
|
|
echo '<div class="ratings" style="text-align:center">';
|
2007-01-04 21:32:36 +00:00
|
|
|
echo '<form id="form" method="post" action="rate.php">';
|
2007-06-03 19:36:20 +00:00
|
|
|
echo '<input type="hidden" name="dataid" value="'.$data->id.'" />';
|
2006-12-07 20:06:11 +00:00
|
|
|
|
|
|
|
if (has_capability('mod/data:rate', $context) and !data_isowner($record->id)) {
|
|
|
|
data_print_ratings_mean($record->id, $ratingsscale, has_capability('mod/data:viewrating', $context));
|
|
|
|
echo ' ';
|
|
|
|
data_print_rating_menu($record->id, $USER->id, $ratingsscale);
|
|
|
|
$ratingsmenuused = true;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
data_print_ratings_mean($record->id, $ratingsscale, true);
|
|
|
|
}
|
2006-02-14 03:17:21 +00:00
|
|
|
|
2006-12-07 20:06:11 +00:00
|
|
|
if ($data->scale < 0) {
|
|
|
|
if ($scale = get_record('scale', 'id', abs($data->scale))) {
|
|
|
|
print_scale_menu_helpbutton($data->course, $scale );
|
2006-02-14 03:17:21 +00:00
|
|
|
}
|
|
|
|
}
|
2006-12-07 20:06:11 +00:00
|
|
|
|
|
|
|
if ($ratingsmenuused) {
|
|
|
|
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
|
|
|
|
echo '<input type="submit" value="'.get_string('sendinratings', 'data').'" />';
|
|
|
|
}
|
|
|
|
echo '</form>';
|
|
|
|
echo '</div>';
|
2006-02-14 03:17:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function data_print_ratings_mean($recordid, $scale, $link=true) {
|
2008-05-31 00:30:00 +00:00
|
|
|
// Print the multiple ratings on a post given to the current user by others.
|
|
|
|
// Scale is an array of ratings
|
2006-02-14 03:17:21 +00:00
|
|
|
|
|
|
|
static $strrate;
|
|
|
|
|
|
|
|
$mean = data_get_ratings_mean($recordid, $scale);
|
|
|
|
|
|
|
|
if ($mean !== "") {
|
|
|
|
|
|
|
|
if (empty($strratings)) {
|
2006-02-15 06:38:32 +00:00
|
|
|
$strratings = get_string("ratings", "data");
|
2006-02-14 03:17:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
echo "$strratings: ";
|
|
|
|
if ($link) {
|
|
|
|
link_to_popup_window ("/mod/data/report.php?id=$recordid", "ratings", $mean, 400, 600);
|
|
|
|
} else {
|
|
|
|
echo "$mean ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function data_get_ratings_mean($recordid, $scale, $ratings=NULL) {
|
2008-05-31 00:30:00 +00:00
|
|
|
// Return the mean rating of a post given to the current user by others.
|
|
|
|
// Scale is an array of possible ratings in the scale
|
|
|
|
// Ratings is an optional simple array of actual ratings (just integers)
|
2006-02-14 03:17:21 +00:00
|
|
|
|
|
|
|
if (!$ratings) {
|
|
|
|
$ratings = array();
|
|
|
|
if ($rates = get_records("data_ratings", "recordid", $recordid)) {
|
|
|
|
foreach ($rates as $rate) {
|
|
|
|
$ratings[] = $rate->rating;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$count = count($ratings);
|
|
|
|
|
|
|
|
if ($count == 0) {
|
|
|
|
return "";
|
|
|
|
|
|
|
|
} else if ($count == 1) {
|
|
|
|
return $scale[$ratings[0]];
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$total = 0;
|
|
|
|
foreach ($ratings as $rating) {
|
|
|
|
$total += $rating;
|
|
|
|
}
|
|
|
|
$mean = round( ((float)$total/(float)$count) + 0.001); // Little fudge factor so that 0.5 goes UP
|
|
|
|
|
|
|
|
if (isset($scale[$mean])) {
|
|
|
|
return $scale[$mean]." ($count)";
|
|
|
|
} else {
|
|
|
|
return "$mean ($count)"; // Should never happen, hopefully
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function data_print_rating_menu($recordid, $userid, $scale) {
|
2008-05-31 00:30:00 +00:00
|
|
|
// Print the menu of ratings as part of a larger form.
|
|
|
|
// If the post has already been - set that value.
|
|
|
|
// Scale is an array of ratings
|
2006-02-14 03:17:21 +00:00
|
|
|
|
|
|
|
static $strrate;
|
|
|
|
|
|
|
|
if (!$rating = get_record("data_ratings", "userid", $userid, "recordid", $recordid)) {
|
2007-06-03 19:36:20 +00:00
|
|
|
$rating->rating = -999;
|
2006-02-14 03:17:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($strrate)) {
|
2006-02-15 06:38:32 +00:00
|
|
|
$strrate = get_string("rate", "data");
|
2006-02-14 03:17:21 +00:00
|
|
|
}
|
|
|
|
|
2007-06-03 19:36:20 +00:00
|
|
|
choose_from_menu($scale, $recordid, $rating->rating, "$strrate...", '', -999);
|
2006-02-14 03:17:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function data_get_ratings($recordid, $sort="u.firstname ASC") {
|
2008-05-31 00:30:00 +00:00
|
|
|
// Returns a list of ratings for a particular post - sorted.
|
2006-02-14 03:17:21 +00:00
|
|
|
global $CFG;
|
|
|
|
return get_records_sql("SELECT u.*, r.rating
|
|
|
|
FROM {$CFG->prefix}data_ratings r,
|
|
|
|
{$CFG->prefix}user u
|
|
|
|
WHERE r.recordid = $recordid
|
|
|
|
AND r.userid = u.id
|
|
|
|
ORDER BY $sort");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-31 00:30:00 +00:00
|
|
|
// prints all comments + a text box for adding additional comment
|
2006-12-13 23:09:34 +00:00
|
|
|
function data_print_comments($data, $record, $page=0, $mform=false) {
|
2006-03-29 17:36:20 +00:00
|
|
|
|
2006-04-15 02:41:27 +00:00
|
|
|
global $CFG;
|
|
|
|
|
2006-04-05 01:38:06 +00:00
|
|
|
echo '<a name="comments"></a>';
|
|
|
|
|
2006-02-14 03:17:21 +00:00
|
|
|
if ($comments = get_records('data_comments','recordid',$record->id)) {
|
|
|
|
foreach ($comments as $comment) {
|
2006-03-29 17:36:20 +00:00
|
|
|
data_print_comment($data, $comment, $page);
|
2006-02-14 03:17:21 +00:00
|
|
|
}
|
2006-12-13 23:09:34 +00:00
|
|
|
echo '<br />';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isloggedin() or isguest()) {
|
|
|
|
return;
|
2006-02-14 03:17:21 +00:00
|
|
|
}
|
2006-11-09 19:44:20 +00:00
|
|
|
|
2006-12-13 23:09:34 +00:00
|
|
|
$editor = optional_param('addcomment', 0, PARAM_BOOL);
|
2006-11-09 19:44:20 +00:00
|
|
|
|
2006-12-13 23:09:34 +00:00
|
|
|
if (!$mform and !$editor) {
|
2007-01-05 02:38:09 +00:00
|
|
|
echo '<div class="newcomment" style="text-align:center">';
|
2006-12-13 23:09:34 +00:00
|
|
|
echo '<a href="view.php?d='.$data->id.'&page='.$page.'&mode=single&addcomment=1">'.get_string('addcomment', 'data').'</a>';
|
|
|
|
echo '</div>';
|
|
|
|
} else {
|
|
|
|
if (!$mform) {
|
|
|
|
require_once('comment_form.php');
|
2006-12-28 15:43:47 +00:00
|
|
|
$mform = new mod_data_comment_form('comment.php');
|
2007-01-12 18:52:09 +00:00
|
|
|
$mform->set_data(array('mode'=>'add', 'page'=>$page, 'rid'=>$record->id));
|
2006-12-13 23:09:34 +00:00
|
|
|
}
|
2007-01-05 02:38:09 +00:00
|
|
|
echo '<div class="newcomment" style="text-align:center">';
|
2006-12-13 23:09:34 +00:00
|
|
|
$mform->display();
|
|
|
|
echo '</div>';
|
2006-04-11 12:32:23 +00:00
|
|
|
}
|
2006-02-14 03:17:21 +00:00
|
|
|
}
|
|
|
|
|
2008-05-31 00:30:00 +00:00
|
|
|
// prints a single comment entry
|
2006-03-29 17:36:20 +00:00
|
|
|
function data_print_comment($data, $comment, $page=0) {
|
2006-02-14 03:17:21 +00:00
|
|
|
|
2006-03-29 08:49:28 +00:00
|
|
|
global $USER, $CFG;
|
2006-11-09 19:44:20 +00:00
|
|
|
|
2006-12-06 20:17:58 +00:00
|
|
|
$cm = get_coursemodule_from_instance('data', $data->id);
|
2006-08-09 13:45:49 +00:00
|
|
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
2006-11-09 19:44:20 +00:00
|
|
|
|
2006-08-09 13:45:49 +00:00
|
|
|
$stredit = get_string('edit');
|
2006-02-14 03:17:21 +00:00
|
|
|
$strdelete = get_string('delete');
|
|
|
|
|
|
|
|
$user = get_record('user','id',$comment->userid);
|
|
|
|
|
2006-04-05 08:19:09 +00:00
|
|
|
echo '<table cellspacing="0" align="center" width="50%" class="datacomment forumpost">';
|
2006-02-14 03:17:21 +00:00
|
|
|
|
|
|
|
echo '<tr class="header"><td class="picture left">';
|
2008-02-13 17:03:25 +00:00
|
|
|
print_user_picture($user, $data->course, $user->picture);
|
2006-02-14 03:17:21 +00:00
|
|
|
echo '</td>';
|
|
|
|
|
2006-02-27 02:13:48 +00:00
|
|
|
echo '<td class="topic starter" align="left"><div class="author">';
|
2006-10-27 07:50:28 +00:00
|
|
|
$fullname = fullname($user, has_capability('moodle/site:viewfullnames', $context));
|
|
|
|
$by = new object();
|
2006-02-27 02:13:48 +00:00
|
|
|
$by->name = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.
|
2006-03-29 08:49:28 +00:00
|
|
|
$user->id.'&course='.$data->course.'">'.$fullname.'</a>';
|
2006-02-27 02:13:48 +00:00
|
|
|
$by->date = userdate($comment->modified);
|
|
|
|
print_string('bynameondate', 'data', $by);
|
2006-02-14 03:17:21 +00:00
|
|
|
echo '</div></td></tr>';
|
|
|
|
|
|
|
|
echo '<tr><td class="left side">';
|
2007-08-20 14:04:10 +00:00
|
|
|
if ($groups = groups_get_all_groups($data->course, $comment->userid, $cm->groupingid)) {
|
2006-07-03 21:11:17 +00:00
|
|
|
print_group_picture($groups, $data->course, false, false, true);
|
2006-02-14 03:17:21 +00:00
|
|
|
} else {
|
|
|
|
echo ' ';
|
|
|
|
}
|
|
|
|
|
2008-05-31 00:30:00 +00:00
|
|
|
// Actual content
|
2006-02-14 03:17:21 +00:00
|
|
|
|
2006-02-20 05:50:45 +00:00
|
|
|
echo '</td><td class="content" align="left">'."\n";
|
2006-02-14 03:17:21 +00:00
|
|
|
|
|
|
|
// Print whole message
|
2006-12-13 23:09:34 +00:00
|
|
|
echo format_text($comment->content, $comment->format);
|
2006-02-14 03:17:21 +00:00
|
|
|
|
2008-05-31 00:30:00 +00:00
|
|
|
// Commands
|
2006-02-14 03:17:21 +00:00
|
|
|
|
|
|
|
echo '<div class="commands">';
|
2006-08-14 05:55:40 +00:00
|
|
|
if (data_isowner($comment->recordid) or has_capability('mod/data:managecomments', $context)) {
|
2006-03-29 17:36:20 +00:00
|
|
|
echo '<a href="'.$CFG->wwwroot.'/mod/data/comment.php?rid='.$comment->recordid.'&mode=edit&commentid='.$comment->id.'&page='.$page.'">'.$stredit.'</a>';
|
|
|
|
echo '| <a href="'.$CFG->wwwroot.'/mod/data/comment.php?rid='.$comment->recordid.'&mode=delete&commentid='.$comment->id.'&page='.$page.'">'.$strdelete.'</a>';
|
2006-02-14 03:17:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
echo '</div>';
|
|
|
|
|
2006-04-05 08:19:09 +00:00
|
|
|
echo '</td></tr></table>'."\n\n";
|
2006-02-14 03:17:21 +00:00
|
|
|
}
|
2006-03-09 06:26:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
// For Participantion Reports
|
|
|
|
function data_get_view_actions() {
|
|
|
|
return array('view');
|
|
|
|
}
|
|
|
|
|
|
|
|
function data_get_post_actions() {
|
|
|
|
return array('add','update','record delete');
|
|
|
|
}
|
|
|
|
|
2006-03-22 08:07:26 +00:00
|
|
|
function data_fieldname_exists($name, $dataid, $fieldid=0) {
|
|
|
|
global $CFG;
|
|
|
|
|
2006-09-26 05:08:18 +00:00
|
|
|
$LIKE = sql_ilike();
|
2006-11-09 19:44:20 +00:00
|
|
|
if ($fieldid) {
|
|
|
|
return record_exists_sql("SELECT * from {$CFG->prefix}data_fields df
|
2006-09-26 05:08:18 +00:00
|
|
|
WHERE df.name $LIKE '$name' AND df.dataid = $dataid
|
2006-03-27 06:19:34 +00:00
|
|
|
AND ((df.id < $fieldid) OR (df.id > $fieldid))");
|
2006-03-22 08:07:26 +00:00
|
|
|
} else {
|
2006-11-09 19:44:20 +00:00
|
|
|
return record_exists_sql("SELECT * from {$CFG->prefix}data_fields df
|
2006-09-26 05:08:18 +00:00
|
|
|
WHERE df.name $LIKE '$name' AND df.dataid = $dataid");
|
2006-03-22 08:07:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function data_convert_arrays_to_strings(&$fieldinput) {
|
|
|
|
foreach ($fieldinput as $key => $val) {
|
|
|
|
if (is_array($val)) {
|
|
|
|
$str = '';
|
|
|
|
foreach ($val as $inner) {
|
|
|
|
$str .= $inner . ',';
|
|
|
|
}
|
|
|
|
$str = substr($str, 0, -1);
|
|
|
|
|
|
|
|
$fieldinput->$key = $str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-15 08:42:06 +00:00
|
|
|
|
2006-09-20 16:57:01 +00:00
|
|
|
/**
|
|
|
|
* Converts a database (module instance) to use the Roles System
|
|
|
|
* @param $data - a data object with the same attributes as a record
|
|
|
|
* from the data database table
|
|
|
|
* @param $datamodid - the id of the data module, from the modules table
|
|
|
|
* @param $teacherroles - array of roles that have moodle/legacy:teacher
|
|
|
|
* @param $studentroles - array of roles that have moodle/legacy:student
|
|
|
|
* @param $guestroles - array of roles that have moodle/legacy:guest
|
|
|
|
* @param $cmid - the course_module id for this data instance
|
|
|
|
* @return boolean - data module was converted or not
|
|
|
|
*/
|
|
|
|
function data_convert_to_roles($data, $teacherroles=array(), $studentroles=array(), $cmid=NULL) {
|
2006-11-09 19:44:20 +00:00
|
|
|
|
2006-09-20 16:57:01 +00:00
|
|
|
global $CFG;
|
2006-11-09 19:44:20 +00:00
|
|
|
|
2006-09-20 16:57:01 +00:00
|
|
|
if (!isset($data->participants) && !isset($data->assesspublic)
|
|
|
|
&& !isset($data->groupmode)) {
|
|
|
|
// We assume that this database has already been converted to use the
|
|
|
|
// Roles System. above fields get dropped the data module has been
|
|
|
|
// upgraded to use Roles.
|
|
|
|
return false;
|
|
|
|
}
|
2006-11-09 19:44:20 +00:00
|
|
|
|
2006-09-20 16:57:01 +00:00
|
|
|
if (empty($cmid)) {
|
|
|
|
// We were not given the course_module id. Try to find it.
|
2006-09-20 17:46:20 +00:00
|
|
|
if (!$cm = get_coursemodule_from_instance('data', $data->id)) {
|
|
|
|
notify('Could not get the course module for the data');
|
2006-09-20 16:57:01 +00:00
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
$cmid = $cm->id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$context = get_context_instance(CONTEXT_MODULE, $cmid);
|
2006-11-09 19:44:20 +00:00
|
|
|
|
|
|
|
|
2006-09-20 16:57:01 +00:00
|
|
|
// $data->participants:
|
|
|
|
// 1 - Only teachers can add entries
|
|
|
|
// 3 - Teachers and students can add entries
|
|
|
|
switch ($data->participants) {
|
|
|
|
case 1:
|
|
|
|
foreach ($studentroles as $studentrole) {
|
|
|
|
assign_capability('mod/data:writeentry', CAP_PREVENT, $studentrole->id, $context->id);
|
|
|
|
}
|
|
|
|
foreach ($teacherroles as $teacherrole) {
|
|
|
|
assign_capability('mod/data:writeentry', CAP_ALLOW, $teacherrole->id, $context->id);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
foreach ($studentroles as $studentrole) {
|
|
|
|
assign_capability('mod/data:writeentry', CAP_ALLOW, $studentrole->id, $context->id);
|
|
|
|
}
|
|
|
|
foreach ($teacherroles as $teacherrole) {
|
|
|
|
assign_capability('mod/data:writeentry', CAP_ALLOW, $teacherrole->id, $context->id);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2006-11-09 19:44:20 +00:00
|
|
|
|
2006-09-20 16:57:01 +00:00
|
|
|
// $data->assessed:
|
|
|
|
// 2 - Only teachers can rate posts
|
|
|
|
// 1 - Everyone can rate posts
|
|
|
|
// 0 - No one can rate posts
|
|
|
|
switch ($data->assessed) {
|
|
|
|
case 0:
|
|
|
|
foreach ($studentroles as $studentrole) {
|
|
|
|
assign_capability('mod/data:rate', CAP_PREVENT, $studentrole->id, $context->id);
|
|
|
|
}
|
|
|
|
foreach ($teacherroles as $teacherrole) {
|
|
|
|
assign_capability('mod/data:rate', CAP_PREVENT, $teacherrole->id, $context->id);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
foreach ($studentroles as $studentrole) {
|
|
|
|
assign_capability('mod/data:rate', CAP_ALLOW, $studentrole->id, $context->id);
|
|
|
|
}
|
|
|
|
foreach ($teacherroles as $teacherrole) {
|
|
|
|
assign_capability('mod/data:rate', CAP_ALLOW, $teacherrole->id, $context->id);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
foreach ($studentroles as $studentrole) {
|
|
|
|
assign_capability('mod/data:rate', CAP_PREVENT, $studentrole->id, $context->id);
|
|
|
|
}
|
|
|
|
foreach ($teacherroles as $teacherrole) {
|
|
|
|
assign_capability('mod/data:rate', CAP_ALLOW, $teacherrole->id, $context->id);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2006-11-09 19:44:20 +00:00
|
|
|
|
2006-09-20 16:57:01 +00:00
|
|
|
// $data->assesspublic:
|
|
|
|
// 0 - Students can only see their own ratings
|
|
|
|
// 1 - Students can see everyone's ratings
|
|
|
|
switch ($data->assesspublic) {
|
|
|
|
case 0:
|
|
|
|
foreach ($studentroles as $studentrole) {
|
|
|
|
assign_capability('mod/data:viewrating', CAP_PREVENT, $studentrole->id, $context->id);
|
|
|
|
}
|
|
|
|
foreach ($teacherroles as $teacherrole) {
|
|
|
|
assign_capability('mod/data:viewrating', CAP_ALLOW, $teacherrole->id, $context->id);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
foreach ($studentroles as $studentrole) {
|
|
|
|
assign_capability('mod/data:viewrating', CAP_ALLOW, $studentrole->id, $context->id);
|
|
|
|
}
|
|
|
|
foreach ($teacherroles as $teacherrole) {
|
|
|
|
assign_capability('mod/data:viewrating', CAP_ALLOW, $teacherrole->id, $context->id);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($cm)) {
|
|
|
|
$cm = get_record('course_modules', 'id', $cmid);
|
|
|
|
}
|
2006-11-09 19:44:20 +00:00
|
|
|
|
2006-09-20 16:57:01 +00:00
|
|
|
switch ($cm->groupmode) {
|
2007-08-20 14:04:10 +00:00
|
|
|
case NOGROUPS:
|
2006-09-20 16:57:01 +00:00
|
|
|
break;
|
2007-08-20 14:04:10 +00:00
|
|
|
case SEPARATEGROUPS:
|
2006-09-20 16:57:01 +00:00
|
|
|
foreach ($studentroles as $studentrole) {
|
|
|
|
assign_capability('moodle/site:accessallgroups', CAP_PREVENT, $studentrole->id, $context->id);
|
|
|
|
}
|
|
|
|
foreach ($teacherroles as $teacherrole) {
|
|
|
|
assign_capability('moodle/site:accessallgroups', CAP_ALLOW, $teacherrole->id, $context->id);
|
|
|
|
}
|
|
|
|
break;
|
2007-08-20 14:04:10 +00:00
|
|
|
case VISIBLEGROUPS:
|
2006-09-20 16:57:01 +00:00
|
|
|
foreach ($studentroles as $studentrole) {
|
|
|
|
assign_capability('moodle/site:accessallgroups', CAP_ALLOW, $studentrole->id, $context->id);
|
|
|
|
}
|
|
|
|
foreach ($teacherroles as $teacherrole) {
|
|
|
|
assign_capability('moodle/site:accessallgroups', CAP_ALLOW, $teacherrole->id, $context->id);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-11-09 19:44:20 +00:00
|
|
|
/*
|
2006-10-02 17:24:54 +00:00
|
|
|
* Returns the best name to show for a preset
|
|
|
|
*/
|
|
|
|
function data_preset_name($shortname, $path) {
|
|
|
|
|
2008-05-31 09:51:48 +00:00
|
|
|
// We are looking inside the preset itself as a first choice, but also in normal data directory
|
2007-08-21 03:38:45 +00:00
|
|
|
$string = get_string('modulename', 'datapreset_'.$shortname);
|
2006-10-02 17:24:54 +00:00
|
|
|
|
|
|
|
if (substr($string, 0, 1) == '[') {
|
|
|
|
return $shortname;
|
|
|
|
} else {
|
|
|
|
return $string;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-09 19:44:20 +00:00
|
|
|
/*
|
2006-10-02 17:24:54 +00:00
|
|
|
* Returns an array of all the available presets
|
|
|
|
*/
|
|
|
|
function data_get_available_presets($context) {
|
|
|
|
global $CFG, $USER;
|
|
|
|
|
|
|
|
$presets = array();
|
2006-11-09 19:44:20 +00:00
|
|
|
|
2006-10-02 17:24:54 +00:00
|
|
|
if ($dirs = get_list_of_plugins('mod/data/preset')) {
|
|
|
|
foreach ($dirs as $dir) {
|
|
|
|
$fulldir = $CFG->dirroot.'/mod/data/preset/'.$dir;
|
|
|
|
|
|
|
|
if (is_directory_a_preset($fulldir)) {
|
|
|
|
$preset = new object;
|
|
|
|
$preset->path = $fulldir;
|
|
|
|
$preset->userid = 0;
|
|
|
|
$preset->shortname = $dir;
|
|
|
|
$preset->name = data_preset_name($dir, $fulldir);
|
|
|
|
if (file_exists($fulldir.'/screenshot.jpg')) {
|
|
|
|
$preset->screenshot = $CFG->wwwroot.'/mod/data/preset/'.$dir.'/screenshot.jpg';
|
|
|
|
} else if (file_exists($fulldir.'/screenshot.png')) {
|
|
|
|
$preset->screenshot = $CFG->wwwroot.'/mod/data/preset/'.$dir.'/screenshot.png';
|
|
|
|
} else if (file_exists($fulldir.'/screenshot.gif')) {
|
|
|
|
$preset->screenshot = $CFG->wwwroot.'/mod/data/preset/'.$dir.'/screenshot.gif';
|
|
|
|
}
|
|
|
|
$presets[] = $preset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($userids = get_list_of_plugins('data/preset', '', $CFG->dataroot)) {
|
|
|
|
foreach ($userids as $userid) {
|
|
|
|
$fulldir = $CFG->dataroot.'/data/preset/'.$userid;
|
|
|
|
|
|
|
|
if ($userid == 0 || $USER->id == $userid || has_capability('mod/data:viewalluserpresets', $context)) {
|
|
|
|
|
|
|
|
if ($dirs = get_list_of_plugins('data/preset/'.$userid, '', $CFG->dataroot)) {
|
|
|
|
foreach ($dirs as $dir) {
|
|
|
|
$fulldir = $CFG->dataroot.'/data/preset/'.$userid.'/'.$dir;
|
|
|
|
|
|
|
|
if (is_directory_a_preset($fulldir)) {
|
|
|
|
$preset = new object;
|
|
|
|
$preset->path = $fulldir;
|
|
|
|
$preset->userid = $userid;
|
|
|
|
$preset->shortname = $dir;
|
|
|
|
$preset->name = data_preset_name($dir, $fulldir);
|
|
|
|
if (file_exists($fulldir.'/screenshot.jpg')) {
|
|
|
|
$preset->screenshot = $CFG->wwwroot.'/mod/data/preset/'.$dir.'/screenshot.jpg';
|
|
|
|
} else if (file_exists($fulldir.'/screenshot.png')) {
|
|
|
|
$preset->screenshot = $CFG->wwwroot.'/mod/data/preset/'.$dir.'/screenshot.png';
|
|
|
|
} else if (file_exists($fulldir.'/screenshot.gif')) {
|
|
|
|
$preset->screenshot = $CFG->wwwroot.'/mod/data/preset/'.$dir.'/screenshot.gif';
|
|
|
|
}
|
|
|
|
$presets[] = $preset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $presets;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function data_print_header($course, $cm, $data, $currenttab='') {
|
|
|
|
|
|
|
|
global $CFG, $displaynoticegood, $displaynoticebad;
|
|
|
|
|
2007-10-12 15:55:49 +00:00
|
|
|
$navigation = build_navigation('', $cm);
|
2007-04-16 21:05:21 +00:00
|
|
|
print_header_simple($data->name, '', $navigation,
|
2006-11-09 19:44:20 +00:00
|
|
|
'', '', true, update_module_button($cm->id, $course->id, get_string('modulename', 'data')),
|
2006-10-02 17:24:54 +00:00
|
|
|
navmenu($course, $cm));
|
|
|
|
|
|
|
|
print_heading(format_string($data->name));
|
|
|
|
|
2008-05-31 00:30:00 +00:00
|
|
|
// Groups needed for Add entry tab
|
2007-08-20 14:04:10 +00:00
|
|
|
$currentgroup = groups_get_activity_group($cm);
|
2007-08-20 21:16:43 +00:00
|
|
|
$groupmode = groups_get_activity_groupmode($cm);
|
2006-12-10 20:16:03 +00:00
|
|
|
|
2008-05-31 09:51:48 +00:00
|
|
|
// Print the tabs
|
2006-10-02 17:24:54 +00:00
|
|
|
|
|
|
|
if ($currenttab) {
|
2007-09-24 17:20:08 +00:00
|
|
|
include('tabs.php');
|
2006-10-02 17:24:54 +00:00
|
|
|
}
|
|
|
|
|
2008-05-31 00:30:00 +00:00
|
|
|
// Print any notices
|
2006-10-02 17:24:54 +00:00
|
|
|
|
|
|
|
if (!empty($displaynoticegood)) {
|
|
|
|
notify($displaynoticegood, 'notifysuccess'); // good (usually green)
|
|
|
|
} else if (!empty($displaynoticebad)) {
|
|
|
|
notify($displaynoticebad); // bad (usuually red)
|
|
|
|
}
|
|
|
|
}
|
2006-09-20 16:57:01 +00:00
|
|
|
|
2007-06-03 19:36:20 +00:00
|
|
|
function data_user_can_add_entry($data, $currentgroup, $groupmode) {
|
2006-12-10 20:16:03 +00:00
|
|
|
global $USER;
|
|
|
|
|
|
|
|
if (!$cm = get_coursemodule_from_instance('data', $data->id)) {
|
2008-04-13 22:22:57 +00:00
|
|
|
error('Course Module ID was incorrect');
|
2006-12-10 20:16:03 +00:00
|
|
|
}
|
|
|
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
|
|
|
|
|
|
|
if (!has_capability('mod/data:writeentry', $context) and !has_capability('mod/data:manageentries',$context)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-06-03 19:36:20 +00:00
|
|
|
if (!$groupmode or has_capability('moodle/site:accessallgroups', $context)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-12-10 20:16:03 +00:00
|
|
|
if ($currentgroup) {
|
2007-08-15 20:21:01 +00:00
|
|
|
return groups_is_member($currentgroup);
|
2006-12-10 20:16:03 +00:00
|
|
|
} else {
|
|
|
|
//else it might be group 0 in visible mode
|
|
|
|
if ($groupmode == VISIBLEGROUPS){
|
|
|
|
return true;
|
2007-06-03 19:36:20 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
2006-12-10 20:16:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-26 22:04:43 +00:00
|
|
|
|
|
|
|
function is_directory_a_preset($directory) {
|
|
|
|
$directory = rtrim($directory, '/\\') . '/';
|
2008-04-20 09:29:57 +00:00
|
|
|
$status = file_exists($directory.'singletemplate.html') &&
|
|
|
|
file_exists($directory.'listtemplate.html') &&
|
|
|
|
file_exists($directory.'listtemplateheader.html') &&
|
|
|
|
file_exists($directory.'listtemplatefooter.html') &&
|
|
|
|
file_exists($directory.'addtemplate.html') &&
|
|
|
|
file_exists($directory.'rsstemplate.html') &&
|
|
|
|
file_exists($directory.'rsstitletemplate.html') &&
|
|
|
|
file_exists($directory.'csstemplate.css') &&
|
|
|
|
file_exists($directory.'jstemplate.js') &&
|
|
|
|
file_exists($directory.'preset.xml');
|
|
|
|
|
|
|
|
return $status;
|
2007-04-26 22:04:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function clean_preset($folder) {
|
2008-04-20 09:29:57 +00:00
|
|
|
$status = @unlink($folder.'/singletemplate.html') &&
|
|
|
|
@unlink($folder.'/listtemplate.html') &&
|
|
|
|
@unlink($folder.'/listtemplateheader.html') &&
|
|
|
|
@unlink($folder.'/listtemplatefooter.html') &&
|
|
|
|
@unlink($folder.'/addtemplate.html') &&
|
|
|
|
@unlink($folder.'/rsstemplate.html') &&
|
|
|
|
@unlink($folder.'/rsstitletemplate.html') &&
|
|
|
|
@unlink($folder.'/csstemplate.css') &&
|
|
|
|
@unlink($folder.'/jstemplate.js') &&
|
|
|
|
@unlink($folder.'/preset.xml');
|
|
|
|
|
|
|
|
// optional
|
|
|
|
@unlink($folder.'/asearchtemplate.html');
|
|
|
|
|
|
|
|
return $status;
|
2007-04-26 22:04:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function data_presets_export($course, $cm, $data) {
|
|
|
|
global $CFG;
|
2007-08-20 10:52:59 +00:00
|
|
|
|
2007-04-26 22:04:43 +00:00
|
|
|
/* Info Collected. Now need to make files in moodledata/temp */
|
|
|
|
$tempfolder = $CFG->dataroot.'/temp';
|
|
|
|
$singletemplate = fopen($tempfolder.'/singletemplate.html', 'w');
|
|
|
|
$listtemplate = fopen($tempfolder.'/listtemplate.html', 'w');
|
|
|
|
$listtemplateheader = fopen($tempfolder.'/listtemplateheader.html', 'w');
|
|
|
|
$listtemplatefooter = fopen($tempfolder.'/listtemplatefooter.html', 'w');
|
|
|
|
$addtemplate = fopen($tempfolder.'/addtemplate.html', 'w');
|
|
|
|
$rsstemplate = fopen($tempfolder.'/rsstemplate.html', 'w');
|
|
|
|
$rsstitletemplate = fopen($tempfolder.'/rsstitletemplate.html', 'w');
|
|
|
|
$csstemplate = fopen($tempfolder.'/csstemplate.css', 'w');
|
|
|
|
$jstemplate = fopen($tempfolder.'/jstemplate.js', 'w');
|
2008-04-20 09:29:57 +00:00
|
|
|
$asearchtemplate = fopen($tempfolder.'/asearchtemplate.html', 'w');
|
2007-04-26 22:04:43 +00:00
|
|
|
|
|
|
|
fwrite($singletemplate, $data->singletemplate);
|
|
|
|
fwrite($listtemplate, $data->listtemplate);
|
|
|
|
fwrite($listtemplateheader, $data->listtemplateheader);
|
|
|
|
fwrite($listtemplatefooter, $data->listtemplatefooter);
|
|
|
|
fwrite($addtemplate, $data->addtemplate);
|
|
|
|
fwrite($rsstemplate, $data->rsstemplate);
|
|
|
|
fwrite($rsstitletemplate, $data->rsstitletemplate);
|
|
|
|
fwrite($csstemplate, $data->csstemplate);
|
|
|
|
fwrite($jstemplate, $data->jstemplate);
|
2008-04-20 09:29:57 +00:00
|
|
|
fwrite($asearchtemplate, $data->asearchtemplate);
|
2007-04-26 22:04:43 +00:00
|
|
|
|
|
|
|
fclose($singletemplate);
|
|
|
|
fclose($listtemplate);
|
|
|
|
fclose($listtemplateheader);
|
|
|
|
fclose($listtemplatefooter);
|
|
|
|
fclose($addtemplate);
|
|
|
|
fclose($rsstemplate);
|
|
|
|
fclose($rsstitletemplate);
|
|
|
|
fclose($csstemplate);
|
|
|
|
fclose($jstemplate);
|
2008-04-20 09:29:57 +00:00
|
|
|
fclose($asearchtemplate);
|
2007-04-26 22:04:43 +00:00
|
|
|
|
|
|
|
/* All the display data is now done. Now assemble preset.xml */
|
|
|
|
$presetfile = fopen($tempfolder.'/preset.xml', 'w');
|
|
|
|
$presetxml = "<preset>\n\n";
|
|
|
|
|
2008-04-20 19:22:06 +00:00
|
|
|
// raw settings are not preprocessed during saving of presets
|
|
|
|
$raw_settings = array('intro', 'comments', 'requiredentries', 'requiredentriestoview',
|
|
|
|
'maxentries', 'rssarticles', 'approval', 'defaultsortdir');
|
2007-04-26 22:04:43 +00:00
|
|
|
|
|
|
|
$presetxml .= "<settings>\n";
|
2008-04-20 19:22:06 +00:00
|
|
|
// first settings that do not require any conversion
|
|
|
|
foreach ($raw_settings as $setting) {
|
2008-04-18 02:12:30 +00:00
|
|
|
$presetxml .= "<$setting>".htmlspecialchars($data->$setting)."</$setting>\n";
|
2007-04-26 22:04:43 +00:00
|
|
|
}
|
2008-04-20 19:22:06 +00:00
|
|
|
|
|
|
|
// now specific settings
|
|
|
|
if ($data->defaultsort > 0 and $sortfield = data_get_field_from_id($data->defaultsort, $data)) {
|
|
|
|
$presetxml .= "<defaultsort>".htmlspecialchars($sortfield->field->name)."</defaultsort>\n";
|
|
|
|
} else {
|
|
|
|
$presetxml .= "<defaultsort>0</defaultsort>\n";
|
|
|
|
}
|
|
|
|
// note: grading settings are not exported intentionally
|
2007-04-26 22:04:43 +00:00
|
|
|
$presetxml .= "</settings>\n\n";
|
|
|
|
|
2008-05-31 09:51:48 +00:00
|
|
|
// Now for the fields. Grab all that are non-empty
|
|
|
|
$fields = get_records('data_fields', 'dataid', $data->id);
|
|
|
|
ksort($fields);
|
2007-04-26 22:04:43 +00:00
|
|
|
if (!empty($fields)) {
|
|
|
|
foreach ($fields as $field) {
|
|
|
|
$presetxml .= "<field>\n";
|
|
|
|
foreach ($field as $key => $value) {
|
|
|
|
if ($value != '' && $key != 'id' && $key != 'dataid') {
|
2008-04-18 02:12:30 +00:00
|
|
|
$presetxml .= "<$key>".htmlspecialchars($value)."</$key>\n";
|
2007-04-26 22:04:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$presetxml .= "</field>\n\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$presetxml .= "</preset>";
|
|
|
|
fwrite($presetfile, $presetxml);
|
|
|
|
fclose($presetfile);
|
|
|
|
|
|
|
|
/* Check all is well */
|
|
|
|
if (!is_directory_a_preset($tempfolder)) {
|
2008-04-13 22:22:57 +00:00
|
|
|
error("Not all files generated!");
|
2007-04-26 22:04:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$filelist = array(
|
2008-05-31 09:51:48 +00:00
|
|
|
'singletemplate.html',
|
|
|
|
'listtemplate.html',
|
|
|
|
'listtemplateheader.html',
|
|
|
|
'listtemplatefooter.html',
|
|
|
|
'addtemplate.html',
|
|
|
|
'rsstemplate.html',
|
|
|
|
'rsstitletemplate.html',
|
|
|
|
'csstemplate.css',
|
|
|
|
'jstemplate.js',
|
|
|
|
'preset.xml',
|
|
|
|
'asearchtemplate.html'
|
|
|
|
);
|
2007-04-26 22:04:43 +00:00
|
|
|
|
|
|
|
foreach ($filelist as $key => $file) {
|
|
|
|
$filelist[$key] = $tempfolder.'/'.$filelist[$key];
|
|
|
|
}
|
|
|
|
|
|
|
|
@unlink($tempfolder.'/export.zip');
|
|
|
|
$status = zip_files($filelist, $tempfolder.'/export.zip');
|
|
|
|
|
|
|
|
/* made the zip... now return the filename for storage.*/
|
|
|
|
return $tempfolder.'/export.zip';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PresetImporter {
|
|
|
|
function PresetImporter($course, $cm, $data, $userid, $shortname) {
|
|
|
|
global $CFG;
|
|
|
|
$this->course = $course;
|
|
|
|
$this->cm = $cm;
|
|
|
|
$this->data = $data;
|
|
|
|
$this->userid = $userid;
|
|
|
|
$this->shortname = $shortname;
|
|
|
|
$this->folder = data_preset_path($course, $userid, $shortname);
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_settings() {
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
if (!is_directory_a_preset($this->folder)) {
|
2008-04-13 22:22:57 +00:00
|
|
|
error("$this->userid/$this->shortname Not a preset");
|
2007-04-26 22:04:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Grab XML */
|
|
|
|
$presetxml = file_get_contents($this->folder.'/preset.xml');
|
2008-04-11 03:59:41 +00:00
|
|
|
$parsedxml = xmlize($presetxml, 0);
|
2007-04-26 22:04:43 +00:00
|
|
|
|
2008-04-20 19:22:06 +00:00
|
|
|
$allowed_settings = array('intro', 'comments', 'requiredentries', 'requiredentriestoview',
|
|
|
|
'maxentries', 'rssarticles', 'approval', 'defaultsortdir', 'defaultsort');
|
|
|
|
|
2007-04-26 22:04:43 +00:00
|
|
|
/* First, do settings. Put in user friendly array. */
|
|
|
|
$settingsarray = $parsedxml['preset']['#']['settings'][0]['#'];
|
|
|
|
$settings = new StdClass();
|
|
|
|
|
|
|
|
foreach ($settingsarray as $setting => $value) {
|
2008-04-13 23:02:31 +00:00
|
|
|
if (!is_array($value)) {
|
|
|
|
continue;
|
|
|
|
}
|
2008-04-20 19:22:06 +00:00
|
|
|
if (!in_array($setting, $allowed_settings)) {
|
|
|
|
// unsupported setting
|
|
|
|
continue;
|
|
|
|
}
|
2007-04-26 22:04:43 +00:00
|
|
|
$settings->$setting = $value[0]['#'];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now work out fields to user friendly array */
|
|
|
|
$fieldsarray = $parsedxml['preset']['#']['field'];
|
|
|
|
$fields = array();
|
|
|
|
foreach ($fieldsarray as $field) {
|
2008-04-13 23:02:31 +00:00
|
|
|
if (!is_array($field)) {
|
|
|
|
continue;
|
|
|
|
}
|
2007-04-26 22:04:43 +00:00
|
|
|
$f = new StdClass();
|
|
|
|
foreach ($field['#'] as $param => $value) {
|
2008-04-13 23:02:31 +00:00
|
|
|
if (!is_array($value)) {
|
|
|
|
continue;
|
|
|
|
}
|
2008-04-18 02:12:30 +00:00
|
|
|
$f->$param = addslashes($value[0]['#']);
|
2007-04-26 22:04:43 +00:00
|
|
|
}
|
|
|
|
$f->dataid = $this->data->id;
|
|
|
|
$f->type = clean_param($f->type, PARAM_ALPHA);
|
|
|
|
$fields[] = $f;
|
|
|
|
}
|
|
|
|
/* Now add the HTML templates to the settings array so we can update d */
|
|
|
|
$settings->singletemplate = file_get_contents($this->folder."/singletemplate.html");
|
|
|
|
$settings->listtemplate = file_get_contents($this->folder."/listtemplate.html");
|
|
|
|
$settings->listtemplateheader = file_get_contents($this->folder."/listtemplateheader.html");
|
|
|
|
$settings->listtemplatefooter = file_get_contents($this->folder."/listtemplatefooter.html");
|
|
|
|
$settings->addtemplate = file_get_contents($this->folder."/addtemplate.html");
|
|
|
|
$settings->rsstemplate = file_get_contents($this->folder."/rsstemplate.html");
|
|
|
|
$settings->rsstitletemplate = file_get_contents($this->folder."/rsstitletemplate.html");
|
|
|
|
$settings->csstemplate = file_get_contents($this->folder."/csstemplate.css");
|
|
|
|
$settings->jstemplate = file_get_contents($this->folder."/jstemplate.js");
|
|
|
|
|
2008-04-20 09:29:57 +00:00
|
|
|
//optional
|
|
|
|
if (file_exists($this->folder."/asearchtemplate.html")) {
|
|
|
|
$settings->asearchtemplate = file_get_contents($this->folder."/asearchtemplate.html");
|
|
|
|
} else {
|
2008-05-31 09:51:48 +00:00
|
|
|
$settings->asearchtemplate = NULL;
|
2008-04-20 09:29:57 +00:00
|
|
|
}
|
|
|
|
|
2007-04-26 22:04:43 +00:00
|
|
|
$settings->instance = $this->data->id;
|
|
|
|
|
|
|
|
/* Now we look at the current structure (if any) to work out whether we need to clear db
|
|
|
|
or save the data */
|
2008-04-20 19:22:06 +00:00
|
|
|
if (!$currentfields = get_records('data_fields', 'dataid', $this->data->id)) {
|
|
|
|
$currentfields = array();
|
|
|
|
}
|
2007-04-26 22:04:43 +00:00
|
|
|
|
|
|
|
return array($settings, $fields, $currentfields);
|
|
|
|
}
|
|
|
|
|
|
|
|
function import_options() {
|
|
|
|
if (!confirm_sesskey()) {
|
2008-04-13 22:22:57 +00:00
|
|
|
error("Sesskey Invalid");
|
2007-04-26 22:04:43 +00:00
|
|
|
}
|
2006-12-10 20:16:03 +00:00
|
|
|
|
2007-04-26 22:04:43 +00:00
|
|
|
$strblank = get_string('blank', 'data');
|
|
|
|
$strcontinue = get_string('continue');
|
|
|
|
$strwarning = get_string('mappingwarning', 'data');
|
|
|
|
$strfieldmappings = get_string('fieldmappings', 'data');
|
|
|
|
$strnew = get_string('new');
|
|
|
|
|
|
|
|
$sesskey = sesskey();
|
|
|
|
|
|
|
|
list($settings, $newfields, $currentfields) = $this->get_settings();
|
|
|
|
|
2008-04-20 10:09:28 +00:00
|
|
|
echo '<div class="presetmapping"><form action="preset.php" method="post">';
|
|
|
|
echo '<div>';
|
2007-04-26 22:04:43 +00:00
|
|
|
echo '<input type="hidden" name="action" value="finishimport" />';
|
|
|
|
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
|
|
|
|
echo '<input type="hidden" name="d" value="'.$this->data->id.'" />';
|
|
|
|
echo '<input type="hidden" name="fullname" value="'.$this->userid.'/'.$this->shortname.'" />';
|
|
|
|
|
|
|
|
if (!empty($currentfields) && !empty($newfields)) {
|
|
|
|
echo "<h3>$strfieldmappings ";
|
2008-01-24 11:00:14 +00:00
|
|
|
helpbutton('fieldmappings', $strfieldmappings, 'data');
|
2007-04-26 22:04:43 +00:00
|
|
|
echo '</h3><table>';
|
|
|
|
|
|
|
|
foreach ($newfields as $nid => $newfield) {
|
|
|
|
echo "<tr><td><label for=\"id_$newfield->name\">$newfield->name</label></td>";
|
|
|
|
echo '<td><select name="field_'.$nid.'" id="id_'.$newfield->name.'">';
|
|
|
|
|
|
|
|
$selected = false;
|
|
|
|
foreach ($currentfields as $cid => $currentfield) {
|
|
|
|
if ($currentfield->type == $newfield->type) {
|
|
|
|
if ($currentfield->name == $newfield->name) {
|
|
|
|
echo '<option value="'.$cid.'" selected="selected">'.$currentfield->name.'</option>';
|
|
|
|
$selected=true;
|
|
|
|
}
|
|
|
|
else {
|
2008-04-13 22:22:57 +00:00
|
|
|
echo '<option value="'.$cid.'">'.$currentfield->name.'</option>';
|
2007-04-26 22:04:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($selected)
|
|
|
|
echo '<option value="-1">-</option>';
|
|
|
|
else
|
|
|
|
echo '<option value="-1" selected="selected">-</option>';
|
|
|
|
echo '</select></td></tr>';
|
|
|
|
}
|
|
|
|
echo '</table>';
|
|
|
|
echo "<p>$strwarning</p>";
|
2008-04-20 10:09:28 +00:00
|
|
|
|
|
|
|
} else if (empty($newfields)) {
|
2008-04-13 22:22:57 +00:00
|
|
|
error("New preset has no defined fields!");
|
2007-04-26 22:04:43 +00:00
|
|
|
}
|
2008-04-20 10:09:28 +00:00
|
|
|
|
|
|
|
echo '<div class="overwritesettings"><label for="overwritesettings">'.get_string('overwritesettings', 'data').'</label>';
|
|
|
|
echo '<input id="overwritesettings" name="overwritesettings" type="checkbox" /></label></div>';
|
|
|
|
|
|
|
|
echo '<input class="button" type="submit" value="'.$strcontinue.'" /></div></form></div>';
|
2007-04-26 22:04:43 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function import() {
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
list($settings, $newfields, $currentfields) = $this->get_settings();
|
|
|
|
$preservedfields = array();
|
|
|
|
|
2008-04-20 10:09:28 +00:00
|
|
|
$overwritesettings = optional_param('overwritesettings', 0, PARAM_BOOL);
|
|
|
|
|
2007-04-26 22:04:43 +00:00
|
|
|
/* Maps fields and makes new ones */
|
|
|
|
if (!empty($newfields)) {
|
|
|
|
/* We require an injective mapping, and need to know what to protect */
|
|
|
|
foreach ($newfields as $nid => $newfield) {
|
|
|
|
$cid = optional_param("field_$nid", -1, PARAM_INT);
|
|
|
|
if ($cid == -1) continue;
|
|
|
|
|
2008-04-13 22:22:57 +00:00
|
|
|
if (array_key_exists($cid, $preservedfields)) error("Not an injective map");
|
2007-04-26 22:04:43 +00:00
|
|
|
else $preservedfields[$cid] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($newfields as $nid => $newfield) {
|
|
|
|
$cid = optional_param("field_$nid", -1, PARAM_INT);
|
|
|
|
|
|
|
|
/* A mapping. Just need to change field params. Data kept. */
|
|
|
|
if ($cid != -1 and isset($currentfields[$cid])) {
|
|
|
|
$fieldobject = data_get_field_from_id($currentfields[$cid]->id, $this->data);
|
|
|
|
foreach ($newfield as $param => $value) {
|
|
|
|
if ($param != "id") {
|
|
|
|
$fieldobject->field->$param = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unset($fieldobject->field->similarfield);
|
|
|
|
$fieldobject->update_field();
|
|
|
|
unset($fieldobject);
|
|
|
|
}
|
|
|
|
/* Make a new field */
|
|
|
|
else {
|
|
|
|
include_once("field/$newfield->type/field.class.php");
|
|
|
|
|
|
|
|
if (!isset($newfield->description)) {
|
|
|
|
$newfield->description = '';
|
|
|
|
}
|
|
|
|
$classname = 'data_field_'.$newfield->type;
|
|
|
|
$fieldclass = new $classname($newfield, $this->data);
|
|
|
|
$fieldclass->insert_field();
|
|
|
|
unset($fieldclass);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get rid of all old unused data */
|
|
|
|
if (!empty($preservedfields)) {
|
|
|
|
foreach ($currentfields as $cid => $currentfield) {
|
|
|
|
if (!array_key_exists($cid, $preservedfields)) {
|
|
|
|
/* Data not used anymore so wipe! */
|
|
|
|
print "Deleting field $currentfield->name<br />";
|
|
|
|
|
|
|
|
$id = $currentfield->id;
|
|
|
|
//Why delete existing data records and related comments/ratings??
|
|
|
|
/*
|
|
|
|
if ($content = get_records('data_content', 'fieldid', $id)) {
|
|
|
|
foreach ($content as $item) {
|
|
|
|
delete_records('data_ratings', 'recordid', $item->recordid);
|
|
|
|
delete_records('data_comments', 'recordid', $item->recordid);
|
|
|
|
delete_records('data_records', 'id', $item->recordid);
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
delete_records('data_content', 'fieldid', $id);
|
|
|
|
delete_records('data_fields', 'id', $id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-31 00:30:00 +00:00
|
|
|
// handle special settings here
|
2008-04-20 19:22:06 +00:00
|
|
|
if (!empty($settings->defaultsort)) {
|
|
|
|
if (is_numeric($settings->defaultsort)) {
|
2008-05-31 09:51:48 +00:00
|
|
|
// old broken value
|
2008-04-20 19:22:06 +00:00
|
|
|
$settings->defaultsort = 0;
|
|
|
|
} else {
|
|
|
|
$settings->defaultsort = (int)get_field('data_fields', 'id', 'dataid', $this->data->id, 'name', addslashes($settings->defaultsort));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$settings->defaultsort = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// do we want to overwrite all current database settings?
|
2008-04-20 10:09:28 +00:00
|
|
|
if ($overwritesettings) {
|
2008-04-20 19:22:06 +00:00
|
|
|
// all supported settings
|
2008-04-20 10:09:28 +00:00
|
|
|
$overwrite = array_keys((array)$settings);
|
|
|
|
} else {
|
2008-04-20 19:22:06 +00:00
|
|
|
// only templates and sorting
|
2008-04-20 10:09:28 +00:00
|
|
|
$overwrite = array('singletemplate', 'listtemplate', 'listtemplateheader', 'listtemplatefooter',
|
|
|
|
'addtemplate', 'rsstemplate', 'rsstitletemplate', 'csstemplate', 'jstemplate',
|
2008-04-20 19:22:06 +00:00
|
|
|
'asearchtemplate', 'defaultsortdir', 'defaultsort');
|
2008-04-20 10:09:28 +00:00
|
|
|
}
|
|
|
|
|
2008-04-20 19:22:06 +00:00
|
|
|
// now overwrite current data settings
|
2007-08-20 10:52:59 +00:00
|
|
|
foreach ($this->data as $prop=>$unused) {
|
2008-04-20 10:09:28 +00:00
|
|
|
if (in_array($prop, $overwrite)) {
|
2007-12-05 06:13:17 +00:00
|
|
|
$this->data->$prop = $settings->$prop;
|
2007-08-20 10:52:59 +00:00
|
|
|
}
|
|
|
|
}
|
2007-12-05 06:13:17 +00:00
|
|
|
|
2007-08-20 10:52:59 +00:00
|
|
|
data_update_instance(addslashes_object($this->data));
|
2007-04-26 22:04:43 +00:00
|
|
|
|
2008-04-20 19:22:06 +00:00
|
|
|
if (strstr($this->folder, '/temp/')) {
|
|
|
|
// Removes the temporary files
|
|
|
|
clean_preset($this->folder);
|
|
|
|
}
|
|
|
|
|
2007-04-26 22:04:43 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function data_preset_path($course, $userid, $shortname) {
|
|
|
|
global $USER, $CFG;
|
|
|
|
|
|
|
|
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
|
|
|
|
|
|
|
$userid = (int)$userid;
|
|
|
|
|
|
|
|
if ($userid > 0 && ($userid == $USER->id || has_capability('mod/data:viewalluserpresets', $context))) {
|
|
|
|
return $CFG->dataroot.'/data/preset/'.$userid.'/'.$shortname;
|
|
|
|
} else if ($userid == 0) {
|
|
|
|
return $CFG->dirroot.'/mod/data/preset/'.$shortname;
|
|
|
|
} else if ($userid < 0) {
|
|
|
|
return $CFG->dataroot.'/temp/data/'.-$userid.'/'.$shortname;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'Does it disturb you that this code will never run?';
|
|
|
|
}
|
2007-11-29 14:43:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of the function for printing the form elements that control
|
|
|
|
* whether the course reset functionality affects the data.
|
|
|
|
* @param $mform form passed by reference
|
|
|
|
*/
|
|
|
|
function data_reset_course_form_definition(&$mform) {
|
|
|
|
$mform->addElement('header', 'dataheader', get_string('modulenameplural', 'data'));
|
|
|
|
$mform->addElement('checkbox', 'reset_data', get_string('deleteallentries','data'));
|
|
|
|
|
|
|
|
$mform->addElement('checkbox', 'reset_data_notenrolled', get_string('deletenotenrolled', 'data'));
|
|
|
|
$mform->disabledIf('reset_data_notenrolled', 'reset_data', 'checked');
|
|
|
|
|
|
|
|
$mform->addElement('checkbox', 'reset_data_ratings', get_string('deleteallratings'));
|
|
|
|
$mform->disabledIf('reset_data_ratings', 'reset_data', 'checked');
|
|
|
|
|
|
|
|
$mform->addElement('checkbox', 'reset_data_comments', get_string('deleteallcomments'));
|
|
|
|
$mform->disabledIf('reset_data_comments', 'reset_data', 'checked');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Course reset form defaults.
|
|
|
|
*/
|
|
|
|
function data_reset_course_form_defaults($course) {
|
|
|
|
return array('reset_data'=>0, 'reset_data_ratings'=>1, 'reset_data_comments'=>1, 'reset_data_notenrolled'=>0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes all grades from gradebook
|
|
|
|
* @param int $courseid
|
|
|
|
* @param string optional type
|
|
|
|
*/
|
|
|
|
function data_reset_gradebook($courseid, $type='') {
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
$sql = "SELECT d.*, cm.idnumber as cmidnumber, d.course as courseid
|
|
|
|
FROM {$CFG->prefix}data d, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m
|
|
|
|
WHERE m.name='data' AND m.id=cm.module AND cm.instance=d.id AND d.course=$courseid";
|
|
|
|
|
|
|
|
if ($datas = get_records_sql($sql)) {
|
|
|
|
foreach ($datas as $data) {
|
|
|
|
data_grade_item_update($data, 'reset');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Actual implementation of the rest coures functionality, delete all the
|
|
|
|
* data responses for course $data->courseid.
|
|
|
|
* @param $data the data submitted from the reset course.
|
|
|
|
* @return array status array
|
|
|
|
*/
|
|
|
|
function data_reset_userdata($data) {
|
|
|
|
global $CFG;
|
|
|
|
require_once($CFG->libdir.'/filelib.php');
|
|
|
|
|
|
|
|
$componentstr = get_string('modulenameplural', 'data');
|
|
|
|
$status = array();
|
|
|
|
|
|
|
|
$allrecordssql = "SELECT r.id
|
|
|
|
FROM {$CFG->prefix}data_records r
|
|
|
|
INNER JOIN {$CFG->prefix}data d ON r.dataid = d.id
|
|
|
|
WHERE d.course = {$data->courseid}";
|
|
|
|
|
|
|
|
$alldatassql = "SELECT d.id
|
|
|
|
FROM {$CFG->prefix}data d
|
|
|
|
WHERE d.course={$data->courseid}";
|
|
|
|
|
|
|
|
// delete entries if requested
|
|
|
|
if (!empty($data->reset_data)) {
|
|
|
|
delete_records_select('data_ratings', "recordid IN ($allrecordssql)");
|
|
|
|
delete_records_select('data_comments', "recordid IN ($allrecordssql)");
|
|
|
|
delete_records_select('data_content', "recordid IN ($allrecordssql)");
|
|
|
|
delete_records_select('data_records', "dataid IN ($alldatassql)");
|
|
|
|
|
|
|
|
if ($datas = get_records_sql($alldatassql)) {
|
|
|
|
foreach ($datas as $dataid=>$unused) {
|
|
|
|
fulldelete("$CFG->dataroot/$data->courseid/moddata/data/$dataid");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($data->reset_gradebook_grades)) {
|
|
|
|
// remove all grades from gradebook
|
|
|
|
data_reset_gradebook($data->courseid);
|
|
|
|
}
|
|
|
|
$status[] = array('component'=>$componentstr, 'item'=>get_string('deleteallentries', 'data'), 'error'=>false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove entries by users not enrolled into course
|
|
|
|
if (!empty($data->reset_data_notenrolled)) {
|
|
|
|
$recordssql = "SELECT r.id, r.userid, r.dataid, u.id AS userexists, u.deleted AS userdeleted
|
|
|
|
FROM {$CFG->prefix}data_records r
|
|
|
|
INNER JOIN {$CFG->prefix}data d ON r.dataid = d.id
|
|
|
|
LEFT OUTER JOIN {$CFG->prefix}user u ON r.userid = u.id
|
|
|
|
WHERE d.course = {$data->courseid} AND r.userid > 0";
|
|
|
|
|
|
|
|
$course_context = get_context_instance(CONTEXT_COURSE, $data->courseid);
|
|
|
|
$notenrolled = array();
|
|
|
|
$fields = array();
|
|
|
|
if ($rs = get_recordset_sql($recordssql)) {
|
|
|
|
while ($record = rs_fetch_next_record($rs)) {
|
|
|
|
if (array_key_exists($record->userid, $notenrolled) or !$record->userexists or $record->userdeleted
|
|
|
|
or !has_capability('moodle/course:view', $course_context , $record->userid)) {
|
|
|
|
delete_records('data_ratings', 'recordid', $record->id);
|
|
|
|
delete_records('data_comments', 'recordid', $record->id);
|
|
|
|
delete_records('data_content', 'recordid', $record->id);
|
|
|
|
delete_records('data_records', 'id', $record->id);
|
|
|
|
// HACK: this is ugly - the recordid should be before the fieldid!
|
|
|
|
if (!array_key_exists($record->dataid, $fields)) {
|
|
|
|
if ($fs = get_records('data_fields', 'dataid', $record->dataid)) {
|
|
|
|
$fields[$record->dataid] = array_keys($fs);
|
|
|
|
} else {
|
|
|
|
$fields[$record->dataid] = array();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach($fields[$record->dataid] as $fieldid) {
|
|
|
|
fulldelete("$CFG->dataroot/$data->courseid/moddata/data/$record->dataid/$fieldid/$record->id");
|
|
|
|
}
|
|
|
|
$notenrolled[$record->userid] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rs_close($rs);
|
|
|
|
$status[] = array('component'=>$componentstr, 'item'=>get_string('deletenotenrolled', 'data'), 'error'=>false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove all ratings
|
|
|
|
if (!empty($data->reset_data_ratings)) {
|
|
|
|
delete_records_select('data_ratings', "recordid IN ($allrecordssql)");
|
|
|
|
|
|
|
|
if (empty($data->reset_gradebook_grades)) {
|
|
|
|
// remove all grades from gradebook
|
|
|
|
data_reset_gradebook($data->courseid);
|
|
|
|
}
|
|
|
|
|
|
|
|
$status[] = array('component'=>$componentstr, 'item'=>get_string('deleteallratings'), 'error'=>false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove all comments
|
|
|
|
if (!empty($data->reset_data_comments)) {
|
|
|
|
delete_records_select('data_comments', "recordid IN ($allrecordssql)");
|
|
|
|
$status[] = array('component'=>$componentstr, 'item'=>get_string('deleteallcomments'), 'error'=>false);
|
|
|
|
}
|
|
|
|
|
2008-05-31 00:30:00 +00:00
|
|
|
// updating dates - shift may be negative too
|
2007-11-29 14:43:04 +00:00
|
|
|
if ($data->timeshift) {
|
|
|
|
shift_course_mod_dates('data', array('timeavailablefrom', 'timeavailableto', 'timeviewfrom', 'timeviewto'), $data->timeshift, $data->courseid);
|
|
|
|
$status[] = array('component'=>$componentstr, 'item'=>get_string('datechanged'), 'error'=>false);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $status;
|
|
|
|
}
|
2006-10-02 17:24:54 +00:00
|
|
|
?>
|