}
if (isteacher($course->id)) {
- if (!count_records('data_fields','dataid',$data->id)) { // Brand new database!
+ if (!record_exists('data_fields','dataid',$data->id)) { // Brand new database!
redirect($CFG->wwwroot.'/mod/data/fields.php?d='.$data->id); // Redirect to field entry
}
}
///checking for participants
- if ((!isteacher($course->id)) && $data->participants == PARTICIPANTS_T) {
- error ('students are not allowed to participate in this activity');
+ if ((!isteacher($course->id)) && $data->participants == DATA_TEACHERS_ONLY) {
+ error (get_string('noaccess','data'));
}
if ($rid){ //editting a record, do you have access to edit this?
print_heading(format_string($data->name));
/// Check to see if groups are being used here
+
if ($groupmode = groupmode($course, $cm)) { // Groups are being used
$currentgroup = setup_and_print_groups($course, $groupmode, 'add.php?d='.$data->id.'&sesskey='.sesskey().'&');
} else {
********************************************/
$entrysaved = false; //flag for displaying entry saved msg
+ $ignorenames = array('MAX_FILE_SIZE','sesskey','d','rid'); // strings to be ignored in input data
+
if ($datarecord = data_submitted($CFG->wwwroot.'/mod/data/add.php') and confirm_sesskey()) {
- //if rid is present, we are in updating mode
- if ($rid){
- //set flag to unapproved after each edit
+ if ($rid) { /// Update some records
+
+ /// All student edits are marked unapproved by default
$record = get_record('data_records','id',$rid);
- if (isteacher($course->id)) {
+ if (!isteacher($course->id)) {
$record->approved = 1;
} else {
$record->approved = 0;
}
$record->groupid = $currentgroup;
+ $record->timemodified = time();
update_record('data_records',$record);
- foreach ($datarecord as $name=>$value){
- //this creates a new field subclass object
- if ($name != 'MAX_FILE_SIZE' && $name != 'sesskey' and $name!='d' and $name!='rid'){
- if (($currentfield = data_get_field_from_name($name)) !== false) {
- //use native subclass method to store field data
- $currentfield->update_data_content($currentfield->id, $rid, $value, $name);
+ /// Update all content
+ $field = NULL;
+ foreach ($datarecord as $name => $value) {
+ if (!in_array($name, $ignorenames)) {
+ $namearr = explode('_',$name); // Second one is the field id
+ if (isset($field->field->id) && $namestring[1] != $field->field->id) { // Try to reuse classes
+ $field = data_get_field_from_id($namestring[1], $data);
+ }
+ if ($field) {
+ $field->update_content($rid, $value, $name);
}
}
}
redirect($CFG->wwwroot.'/mod/data/view.php?d='.$data->id);
- } else { //we are adding a new record
+ } else { /// Add some new records
///Empty form checking - you can't submit an empty form!
- $emptyform = true; //a bad beginning
- $defaults = array(); //this is a list of strings to be ignored in empty check
-
- foreach ($datarecord as $name => $value){ //check to see if everything is empty
- if ($name != 'MAX_FILE_SIZE' and $name != 'sesskey' and $name!='d' and $name!='rid'){
- //call native method to check validity
- $currentfield = data_get_field_from_name($name);
- if ($currentfield->notemptyfield($value, $name)){
- $emptyform = false; //if anything is valid, this form is not empty!
+ $emptyform = true; // assume the worst
+
+ foreach ($datarecord as $name => $value) {
+ if (!in_array($name, $ignorenames)) {
+ $namearr = explode('_', $name); // Second one is the field id
+ if (isset($field->field->id) && $namestring[1] != $field->field->id) { // Try to reuse classes
+ $field = data_get_field_from_id($namestring[1], $data);
+ }
+ if ($field->notemptyfield($value, $name)) {
+ $emptyform = false;
+ break; // if anything has content, this form is not empty, so stop now!
}
}
- } ///End of Empty form checking
+ }
+ if ($emptyform){ //nothing gets written to database
+ notify(get_string('emptyaddform','data'));
+ }
- if (!$emptyform && $recordid = data_add_record($data->id, $currentgroup)){ //add instance to data_record
+ if (!$emptyform && $recordid = data_add_record($data, $currentgroup)) { //add instance to data_record
+
+ /// Insert a whole lot of empty records to make sure we have them
$fields = get_records('data_fields','dataid',$data->id);
-
- //do a manual round of inserting, to make sure even empty conentes get stored
foreach ($fields as $field) {
- $content ->recordid = $recordid;
- $content ->fieldid = $field->id;
+ $content->recordid = $recordid;
+ $content->fieldid = $field->id;
insert_record('data_content',$content);
}
+
//for each field in the add form, add it to the data_content.
foreach ($datarecord as $name => $value){
- if ($name != 'MAX_FILE_SIZE' && $name != 'sesskey' and $name!='d' and $name!='rid'){ //hack to skip these inputs
- $currentfield = data_get_field_from_name($name);
- //use native subclass method to sore field data
- $currentfield->update_data_content($currentfield->id, $recordid, $value, $name);
+ if (!in_array($name, $ignorenames)) {
+ $namearr = explode('_',$name); // Second one is the field id
+ if (isset($field->field->id) && $namestring[1] != $field->field->id) { // Try to reuse classes
+ $field = data_get_field_from_id($namestring[1], $data);
+ }
+ if ($field) {
+ $field->update_content($rid, $value, $name);
+ }
}
}
- $entrysaved = true;
- }
-
- if ($emptyform){ //nothing gets written to database
- notify(get_string('emptyaddform','data'));
- }
-
- if ($entrysaved) {
+
add_to_log($course->id, 'data', 'add', "view.php?d=$data->id&rid=$recordid", $data->id, $cm->id);
+
+ notify(get_string('entrysaved','data'));
}
}
- }
-/**************************
- * End of form processing *
- **************************/
-
-/// Print entry saved msg, if any
- if (!empty($entrysaved)){
- notify (get_string('entrysaved','data'));
- echo '<p />';
- }
-
+ } // End of form processing
+
///Check if maximum number of entry as specified by this database is reached
///Of course, you can't be stopped if you are an editting teacher! =)
$possiblefields = get_records('data_fields','dataid',$data->id);
///then we generate strings to replace
- foreach ($possiblefields as $cfield){
- $patterns[]="/\[\[".$cfield->name."\]\]/i";
- $g = data_get_field($cfield);
- $replacements[] = $g->display_add_field($cfield->id, $rid);
+ foreach ($possiblefields as $eachfield){
+ $field = data_get_field($eachfield, $data);
+ $patterns[]="/\[\[".$field->field->name."\]\]/i";
+ $replacements[] = $field->display_add_field($rid);
unset($g);
}
-<?php ///Class file for textarea field, extends base_field
+<?php // $Id$
///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.org //
// //
-// Copyright (C) 2005 Martin Dougiamas http://dougiamas.com //
+// Copyright (C) 1999-onwards 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 //
// //
///////////////////////////////////////////////////////////////////////////
-/// Please refer to lib.php for method comments
-
class data_field_checkbox extends data_field_base {
var $type = 'checkbox';
- var $id;
-
-
- function data_field_checkbox($fid=0){
- parent::data_field_base($fid);
- }
-
- /***********************************************
- * Saves the field into the database *
- ***********************************************/
- function insert_field($dataid, $type='checkbox', $name, $desc='', $options='') {
- $newfield = new object;
- $newfield->dataid = $dataid;
- $newfield->type = $type;
- $newfield->name = $name;
- $newfield->description = $desc;
- $newfield->param1 = $options;
-
- if (!insert_record('data_fields', $newfield)) {
- notify('Insertion of new field failed!');
- }
+ function data_field_checkbox($field=0, $data=0) {
+ parent::data_field_base($field, $data);
}
- /***********************************************
- * Prints the form element in the add template *
- ***********************************************/
- function display_add_field($id, $rid=0) {
+ function display_add_field($recordid=0) {
global $CFG;
- if (!$field = get_record('data_fields', 'id', $id)){
- notify('That is not a valid field id!');
- exit;
- }
+
$content = array();
-
- if ($rid) {
- $dbcontent = get_record('data_content', 'fieldid', $id, 'recordid', $rid);
- if (isset($dbcontent->content)) {
- $content = $content->content;
- $content = explode('##', $content);
- }
- }
- $str = '';
- /*
- if ($field->description) {
- $str .= '<img src="'.$CFG->pixpath.'/help.gif" alt="'.$field->description.'" title="'.$field->description.'" /> ';
+
+ if ($recordid) {
+ $content = get_field('data_content', 'content', 'fieldid', $this->field->id, 'recordid', $recordid);
+ $content = explode('##', $content);
}
- */
- $str .= '<div title="'.$field->description.'">';
+
+ $str = '<div title="'.$field->description.'">';
foreach (explode("\n", $field->param1) as $checkbox) {
$checkbox = ltrim(rtrim($checkbox));
$str .= 'value="' . $checkbox . '" ';
if (array_search($checkbox, $content) !== false) {
- // Selected by user.
$str .= 'checked />';
- }
- else {
+ } else {
$str .= '/>';
}
$str .= $checkbox . '<br />';
return $str;
}
-
- function display_edit_field($id, $mode=0) {
- parent::display_edit_field($id, $mode);
- }
-
-
- function update($fieldobject) {
- $fieldobject->param2 = trim($fieldobject->param1);
-
- if (!update_record('data_fields',$fieldobject)){
- notify ('upate failed');
- }
- }
-
-
- function store_data_content($fieldid, $recordid, $value) {
+ function update_content($recordid, $value, $name='') {
$content = new object;
- $content->fieldid = $fieldid;
+ $content->fieldid = $this->field->id;
$content->recordid = $recordid;
$content->content = $this->format_data_field_checkbox_content($value);
- insert_record('data_content', $content);
- }
-
-
- function update_data_content($fieldid, $recordid, $value) {
- $content = new object;
- $content->fieldid = $fieldid;
- $content->recordid = $recordid;
- $content->content = $this->format_data_field_checkbox_content($value);
-
- if ($oldcontent = get_record('data_content', 'fieldid', $fieldid, 'recordid', $recordid)) {
+
+ if (!$oldcontent = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) {
$content->id = $oldcontent->id;
- update_record('data_content', $content);
- }
- else {
- $this->store_data_content($fieldid, $recordid, $value);
- }
- }
-
-
- function format_data_field_checkbox_content($content) {
- if (!is_array($content)) {
- $str = $content;
+ return update_record('data_content', $content);
} else {
- $str = '';
- foreach ($content as $val) {
- $str .= $val . '##';
- }
- $str = substr($str, 0, -2);
+ return insert_record('data_content', $content);
}
- $str = clean_param($str, PARAM_NOTAGS);
- return $str;
}
-
- function display_browse_field($fieldid, $recordid, $template) {
- global $CFG, $USER, $course;
+ function display_browse_field($recordid, $template) {
- $field = get_record('data_fields', 'id', $fieldid);
-
- if ($content = get_record('data_content', 'fieldid', $fieldid, 'recordid', $recordid)){
+ if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)){
$contentArr = array();
if (!empty($content->content)) {
$contentArr = explode('##', $content->content);
}
return false;
}
+
+ function format_data_field_checkbox_content($content) {
+ if (!is_array($content)) {
+ $str = $content;
+ } else {
+ $str = '';
+ foreach ($content as $val) {
+ $str .= $val . '##';
+ }
+ $str = substr($str, 0, -2);
+ }
+ $str = clean_param($str, PARAM_NOTAGS);
+ return $str;
+ }
}
-?>
\ No newline at end of file
+?>
-<form name="fieldsubform" action="<?php echo $CFG->wwwroot; ?>/mod/data/fields.php?d=<?php echo ($field->dataid); ?>" method="post">
<table width="100%">
- <tr>
- <td colspan="2">
- <input type="hidden" name="fid" value="<?php echo ($field->id); ?>" />
- <input type="hidden" name="mode" value="<?php if ($newfield) {echo 'add';} else {echo 'update';} ?>" />
- <input type="hidden" name="type" value="<?php echo $this->type; ?>" />
- <input name="sesskey" value="<?php echo sesskey(); ?>" type="hidden" />
- <?php echo ($this->name()); ?>
- </td>
- </tr>
<tr>
<td><?php echo get_string('fieldname', 'data'); ?>:</td>
- <td><input style="width:300px;" type="text" name="name" id="name" value="<?php echo($field->name); ?>" /></td>
+ <td><input style="width:300px;" type="text" name="name" id="name" value="<?php echo($this->field->name); ?>" /></td>
</tr>
<tr>
<td><?php echo get_string('fielddescription', 'data'); ?>:</td>
- <td><input style="width:300px;" type="text" name="description" id="description" value="<?php echo($field->description); ?>" /></td>
+ <td><input style="width:300px;" type="text" name="description" id="description" value="<?php echo($this->field->description); ?>" /></td>
</tr>
<tr>
<td valign="top"><?php echo get_string('fieldoptions', 'data'); ?>:</td>
- <td><textarea style="width:300px; height:150px;" name="param1" id="param1" cols="80" rows="10"><?php if($field->param1) {echo $field->param1;} ?></textarea></td>
- </tr>
- <tr>
- <td> </td>
- <td>
- <input type="submit" value="<?php if ($newfield) {echo get_string('add');} else {echo get_string('save','data');} ?>" />
- <input type="submit" value="<?php echo get_string('cancel'); ?>" onclick="document.fieldsubform.mode.value='void';" />
- </td>
+ <td><textarea style="width:300px; height:150px;" name="param1" id="param1" cols="80" rows="10"><?php if($this->field->param1) {echo $this->field->param1;} ?></textarea></td>
</tr>
</table>
-</form>
-<?php ///Class file for text field, extends field_picture
+<?php // $Id$
///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.org //
// //
-// Copyright (C) 2005 Martin Dougiamas http://dougiamas.com //
+// Copyright (C) 1999-onwards 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 //
// //
///////////////////////////////////////////////////////////////////////////
-/// Please refer to lib.php for method comments
-global $CFG;
-
-//load base class
-require_once($CFG->dirroot.'/mod/data/lib.php');
-
-class data_field_file extends data_field_base {// extends
+class data_field_file extends data_field_base {
- function data_field_file($fid=0){
- parent::data_field_base($fid);
- }
-
- /* the content field is store as this
- * content = a ## b where a is the filename,
- * b is the display file name
- */
-
var $type = 'file';
- var $id;
- function insert_field($dataid, $type='file', $name, $des) {
- $newfield = new object;
- $newfield->dataid = $dataid;
- $newfield->type = $type;
- $newfield->name = $name;
- $newfield->description = $des;
- if (!insert_record('data_fields',$newfield)){
- notify('Insertion of new field failed!');
- }
+ function data_field_file($field=0, $data=0) {
+ parent::data_field_base($field, $data);
}
- function display_add_field($id, $rid=0){
- global $CFG, $course;
- if (!$field = get_record('data_fields','id',$id)){
- notify("that is not a valid field id!");
- exit;
- }
-
- if ($rid){
+ function display_add_field($recordid=0) {
+ global $CFG;
- $datacontent = get_record('data_content','fieldid',$id,'recordid',$rid);
- if (isset($datacontent->content)){
- $content = $datacontent->content;
- $contents[0] = $datacontent->content;
- $contents[1] = $datacontent->content1;
- }else {
- $contents = array();
- $contents[0]='';
- $contents[1]='';
+ if ($recordid){
+ if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) {
+ $contents[0] = $content->content;
+ $contents[1] = $content->content1;
+ } else {
+ $contents[0] = '';
+ $contents[1] = '';
}
- $src = empty($contents[0])? '':$contents[0];
- $name = empty($contents[1])? $src:$contents[1];
- $displayname = empty($contents[1])? '':$contents[1];
+ $src = empty($contents[0]) ? '' : $contents[0];
+ $name = empty($contents[1]) ? $src : $contents[1];
+ $displayname = empty($contents[1]) ? '' : $contents[1];
+
+ $path = $this->data->course.'/'.$CFG->moddata.'/data/'.$this->data->id.'/'.$this->field->id.'/'.$recordid;
if ($CFG->slasharguments) {
- $source = $CFG->wwwroot.'/file.php/'.$course->id.'/'.$CFG->moddata.'/data/'.$field->dataid.'/'.$field->id.'/'.$rid;
+ $source = $CFG->wwwroot.'/file.php/'.$path;
} else {
- $source = $CFG->wwwroot.'/file.php?file=/'.$course->id.'/'.$CFG->moddata.'/data/'.$field->dataid.'/'.$field->id.'/'.$rid;
+ $source = $CFG->wwwroot.'/file.php?file=/'.$path;
}
- }
- else {
- $displayname = '';
- $name = '';
+ } else {
$src = '';
+ $name = '';
+ $displayname = '';
$source = '';
}
-
- $str = '';
- /*
- if ($field->description){
- $str .= '<img src="'.$CFG->pixpath.'/help.gif" alt="'.$field->description.'" title="'.$field->description.'"> ';
- }
- */
- $str .= '<div title="' . $field->description . '">';
- $str .= '<input type="hidden" name ="field_'.$field->id.'_0" value="fakevalue" />';
- $str .= get_string('file','data'). ': <input type="file" name ="field_'.$field->id.'" id="field_'.$field->id.'" title="'.$field->description.'" /><br />';
+
+ $str = '<div title="' . $this->field->description . '">';
+ $str .= '<input type="hidden" name ="field_'.$this->field->id.'_0" value="fakevalue" />';
+ $str .= get_string('file','data'). ': <input type="file" name ="field_'.$this->field->id.'" id="field_'.
+ $this->field->id.'" title="'.$this->field->description.'" /><br />';
$str .= get_string('optionalfilename','data').': <input type="text" name="field_'
- .$field->id.'_1" id="field_'.$field->id.'_1" value="'.$displayname.'" /><br />';
- $str .= '<input type="hidden" name="MAX_FILE_SIZE" value="'.$field->param3.'" />';
+ .$this->field->id.'_1" id="field_'.$this->field->id.'_1" value="'.$displayname.'" /><br />';
+ $str .= '<input type="hidden" name="MAX_FILE_SIZE" value="'.$this->field->param3.'" />';
$str .= '</div>';
- //print icon
- if ($rid and isset($content)){
+ if ($recordid and isset($content)){ // Print icon
require_once($CFG->libdir.'/filelib.php');
$icon = mimeinfo('icon', $src);
$str .= '<img src="'.$CFG->pixpath.'/f/'.$icon.'" height="16" width="16" alt="'.$icon.'" /> '.
return $str;
}
- function display_edit_field($id, $mode=0){
- parent::display_edit_field($id, $mode);
- }
-
- function display_browse_field($fieldid, $recordid, $template) {
+ function display_browse_field($recordid, $template) {
- global $CFG, $USER;
+ global $CFG;
- $field = get_record('data_fields', 'id', $fieldid);
- $data = get_record('data', 'id', $field->dataid);
-
- if ($content = get_record('data_content', 'fieldid', $fieldid, 'recordid', $recordid)){
+ if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)){
$contents[0] = $content->content;
$contents[1] = $content->content1;
$src = empty($contents[0])? '':$contents[0];
$name = empty($contents[1])? $src:$contents[1];
-
-
+
+ $path = $this->data->course.'/'.$CFG->moddata.'/data/'.$this->data->id.'/'.$this->field->id.'/'.$recordid;
+
if ($CFG->slasharguments) {
- $source = $CFG->wwwroot.'/file.php/'.$data->course.'/'.$CFG->moddata.'/data/'.$field->dataid.'/'.$field->id.'/'.$recordid;
+ $source = $CFG->wwwroot.'/file.php/'.$path;
} else {
- $source = $CFG->wwwroot.'/file.php?file=/'.$data->course.'/'.$CFG->moddata.'/data/'.$field->dataid.'/'.$field->id.'/'.$recordid;
+ $source = $CFG->wwwroot.'/file.php?file=/'.$path;
}
-
- $width = $field->param1 ? ' width = "'.$field->param1.'" ':' ';
- $height = $field->param2 ? ' height = "'.$field->param2.'" ':' ';
+
+ $width = $this->field->param1 ? ' width = "'.$this->field->param1.'" ':' ';
+ $height = $this->field->param2 ? ' height = "'.$this->field->param2.'" ':' ';
require_once($CFG->libdir.'/filelib.php');
$icon = mimeinfo('icon', $src);
}
- function update($fieldobject){
- if (!update_record('data_fields',$fieldobject)){
- notify ('upate failed');
- }
- }
+/// content = a ## b where a is the filename, b is the display file name
+ function update_content($recordid, $value, $name) {
+ global $CFG;
- function store_data_content($fieldid, $recordid, $value, $name=''){
- global $CFG, $course;
+ if (!$oldcontent = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) {
+ /// Quickly make one now!
+ $oldcontent = new object;
+ $oldcontent->fieldid = $this->field->id;
+ $oldcontent->recordid = $recordid;
+ if ($oldcontent->id = insert_record('data_content', $oldcontent)) {
+ error('Could not make an empty record!');
+ }
+ }
$content = new object;
- $content->fieldid = $fieldid;
- $content->recordid = $recordid;
-
- $field = get_record('data_fields','id',$fieldid);
+ $content->id = $oldcontent->id;
$names = explode('_',$name);
- switch ($names[2]){
+ switch ($names[2]) {
case 0: //file just uploaded
+ $course = get_course('course', 'id', $this->data->course);
+
$filename = $_FILES[$names[0].'_'.$names[1]];
$filename = $filename['name'];
- $dir = $course->id.'/'.$CFG->moddata.'/data/'.$field->dataid.'/'.$field->id.'/'.$recordid;
-
- /************ FILE MANAGER HERE ***************/
- require_once('../../lib/uploadlib.php');
-
- $um = new upload_manager($names[0].'_'.$names[1],true,false,$course,false,$field->param3);
- if ($um->process_file_uploads($dir)) { //write to content
- $newfile_name = $um->get_new_filename();
- $content->content = $newfile_name;
- insert_record('data_content',$content);
+ $dir = $course->id.'/'.$CFG->moddata.'/data/'.$this->data->id.'/'.$this->field->id.'/'.$recordid;
+
+ //only use the manager if file is present, to avoid "are you sure you selected a file to upload" msg
+ if ($filename){
+ require_once($CFG->libdir.'/uploadlib.php');
+ $um = new upload_manager($names[0].'_'.$names[1],true,false,$course,false,$this->field->param3);
+ if ($um->process_file_uploads($dir)) {
+ $newfile_name = $um->get_new_filename();
+ $content->content = $newfile_name;
+ update_record('data_content',$content);
+ }
}
break;
+
case 1: //only changing alt tag
- if ($oldcontent = get_record('data_content','fieldid', $fieldid, 'recordid', $recordid)){
- $content->id = $oldcontent ->id;
- $content->content1 = clean_param($value, PARAM_NOTAGS);
- update_record('data_content',$content);
- }
+ $content->content1 = clean_param($value, PARAM_NOTAGS);
+ update_record('data_content', $content);
break;
+
default:
break;
- } //close switch
- }
-
- function update_data_content($fieldid, $recordid, $value, $name){
- //if data_content already exit, we update
- global $CFG,$course;
- if ($oldcontent = get_record('data_content','fieldid', $fieldid, 'recordid', $recordid)){
-
- $content = new object;
- $content->fieldid = $fieldid;
- $content->recordid = $recordid;
- $content->id = $oldcontent->id;
- $names = explode('_',$name);
-
- $field = get_record('data_fields','id',$fieldid);
-
- switch ($names[2]){
- case 0: //file just uploaded
- $filename = $_FILES[$names[0].'_'.$names[1]];
- $filename = $filename['name'];
-
- $dir = $course->id.'/'.$CFG->moddata.'/data/'.$field->dataid.'/'.$field->id.'/'.$recordid;
-
- //only use the manager if file is present, to avoid "are you sure you selected a file to upload" msg
- if ($filename){
- /************ FILE MANAGER HERE ***************/
- require_once('../../lib/uploadlib.php');
- $um = new upload_manager($names[0].'_'.$names[1],true,false,$course,false,$field->param3);
- if ($um->process_file_uploads($dir)) {
- //write to content
- $newfile_name = $um->get_new_filename();
- $content->content = $newfile_name;
- $content->content1 = $oldcontent->content1;
- update_record('data_content',$content);
- }
- }
- break;
- case 1: //only changing alt tag
- $content->content = $oldcontent->content;
- $content->content1 = clean_param($value, PARAM_NOTAGS);
- update_record('data_content', $content);
- break;
- default:
- break;
- } //close switch
- }
- else { //make 1 if there isn't one already
- $this->store_data_content($fieldid, $recordid, $value, $name);
}
}
return false;
}
- function delete_data_contents() {
- // Delete the content files first.
- $sql = 'SELECT dc.content AS content, '.
- 'df.dataid AS dataid, '.
- 'dc.recordid AS recordid '.
- 'FROM data_fields AS df, '.
- 'data_content AS dc '.
- "WHERE df.id = {$this->id} ".
- "AND dc.fieldid = {$this->id}";
-
- if (!$results = get_records_sql($sql)) {
- return false;
- }
- foreach ($results as $result) {
- $this->delete_data_content_files($result->dataid, $result->recordid, $result->content);
- }
-
- // Then delete the data_content records.
- return delete_records('data_content', 'fieldid', $this->id);
- }
-
- function delete_data_content_files($dataid, $recordid, $content){
- global $CFG, $course;
- $filepath = $CFG->dataroot.'/'.$course->id.'/'.$CFG->moddata.'/data/'.$dataid.'/'.$this->id.'/'.$recordid;
- @unlink($filepath . '/' . $content);
- @rmdir($filepath);
- notify (get_string('file', 'data') . ' ' . $content . ' ' . get_string('deleted', 'data'));
- }
-
}
?>
-<form name="fieldsubform" action="<?php echo $CFG->wwwroot; ?>/mod/data/fields.php?d=<?php echo ($field->dataid); ?>" method="post">
<table width="100%">
- <tr>
- <td colspan="2">
- <?php echo ($this->name()); ?>
- </td>
- </tr>
<tr>
<td>
<?php echo get_string('fieldname', 'data'); ?>:
</td>
<td>
- <input style="width:300px;" type="text" name="name" id="name" value = "<?php echo($field->name); ?>" />
+ <input style="width:300px;" type="text" name="name" id="name" value = "<?php echo($this->field->name); ?>" />
</td>
</tr>
<tr>
<td>
- <?php echo get_string('fielddescription', 'data'); ?>:</td><td><input style="width:300px;" type="text" name="description" id="description" value = "<?php echo ($field->description);?>" />
+ <?php echo get_string('fielddescription', 'data'); ?>:</td><td><input style="width:300px;" type="text" name="description" id="description" value = "<?php echo ($this->field->description);?>" />
</td>
</tr>
- <tr>
- <td>
- <input type="submit" value="<?php if ($newfield) {echo get_string('add');} else {echo get_string('save','data');} ?>" />
- <input type="hidden" name="fid" value="<?php echo ($field->id); ?>" />
- <input type="hidden" name="mode" value="<?php if ($newfield) {echo 'add';} else {echo 'update';} ?>" />
- <input type="hidden" name="type" value="<?php echo $this->type; ?>" />
- <input type="submit" value="<?php echo get_string('cancel'); ?>" onclick="document.fieldsubform.mode.value='void';" />
- <input name="sesskey" value="<?php echo sesskey(); ?>" type="hidden" />
- </td>
- </tr>
</table>
-</form>
-
-<?php
+<?php // $Id$
///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.org //
// //
-// Copyright (C) 2005 Martin Dougiamas http://dougiamas.com //
+// Copyright (C) 1999-onwards 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 //
// //
///////////////////////////////////////////////////////////////////////////
-/// Please refer to lib.php for method comments
-
-global $CFG;
-
-require_once($CFG->dirroot.'/mod/data/lib.php');
-
class data_field_menu extends data_field_base {
- function data_field_menu($fid=0){
- parent::data_field_base($fid);
- }
-
var $type = 'menu';
- var $id; //field id
- function insert_field($dataid, $type='menu', $name, $des='') {
- $newfield = new object;
- $newfield->dataid = $dataid;
- $newfield->type = $type;
- $newfield->name = $name;
- $newfield->description = $des;
- if (!insert_record('data_fields',$newfield)) {
- notify('Insertion of new field failed!');
- }
+ function data_field_menu($field=0, $data=0) {
+ parent::data_field_base($field, $data);
}
- function display_add_field($id, $rid=0) {
- global $CFG;
- if (!$field = get_record('data_fields','id',$id)) {
- notify("that is not a valid field id!");
- exit;
- }
- $content = '';
-
- //look for that record and pull it out
- if ($rid) {
- $datacontent = get_record('data_content','fieldid',$id,'recordid',$rid);
- if (isset($datacontent->content)) {
- $content = $datacontent->content;
- }
- }
+ function display_add_field($recordid=0) {
- $str = '<div title="'.$field->description.'"><table><tr><td>';
- /*
- if ($field->description) {
- $str .= '<img src="'.$CFG->pixpath.'/help.gif" alt="'.$field->description.'" title="'.$field->description.'"> ';
+ if ($recordid){
+ $content = get_field('data_content', 'content', 'fieldid', $this->field->id, 'recordid', $recordid);
+ $content = trim($content);
+ } else {
+ $content = '';
}
- */
+
+ $str = '<div title="'.$this->field->description.'"><table><tr><td>';
$str .= get_string('menu','data').': </td><td>';
-
- $str .= '<select name="field_'.$field->id.'" id="field_'.$field->id.'">';
- $str .= '<option value="">' . get_string('menuchoose', 'data') . '</option>';
-
- foreach (explode("\n",$field->param1) as $option) {
- if (trim($content) == trim($option)) { // If selected
- $str.='<option value="'.ltrim(rtrim($option)).'" selected="selected">'.ltrim(rtrim($option)).'</option>';
- } else {
- $str.='<option value="'.ltrim(rtrim($option)).'">'.ltrim(rtrim($option)).'</option>';
- }
+
+ foreach (explode("\n",$this->field->param1) as $option) {
+ $option = trim($option);
+ $options[$option] = $option;
}
- $str .= '</select></td></tr></table></div>';
- return $str;
- }
+ $str .= choose_from_menu($options, 'field_'.$this->field->id, $content,
+ get_string('menuchoose', 'data'), '', '', true, false);
- function display_edit_field($id, $mode=0) {
- parent::display_edit_field($id, $mode);
- }
+ $str .= '</td></tr></table></div>';
- function update($fieldobject) {
- $fieldobject->param1 = trim($fieldobject->param1);
- if (!update_record('data_fields',$fieldobject)){
- notify ('upate failed');
- }
+ return $str;
}
+
}
?>
-<form name="fieldsubform" action="<?php echo $CFG->wwwroot; ?>/mod/data/fields.php?d=<?php echo ($field->dataid); ?>" method="post">
<table width="100%">
- <tr>
- <td colspan="2">
- <input type="hidden" name="fid" value="<?php echo ($field->id); ?>" />
- <input type="hidden" name="mode" value="<?php if ($newfield) {echo 'add';} else {echo 'update';} ?>" />
- <input type="hidden" name="type" value="<?php echo $this->type; ?>" />
- <input name="sesskey" value="<?php echo sesskey(); ?>" type="hidden" />
- <?php echo ($this->name()); ?>
- </td>
- </tr>
<tr>
<td><?php echo get_string('fieldname', 'data'); ?>:</td>
- <td><input style="width:300px;" type="text" name="name" id="name" value = "<?php echo($field->name); ?>" /></td>
+ <td><input style="width:300px;" type="text" name="name" id="name" value = "<?php echo($this->field->name); ?>" /></td>
</tr>
<tr>
<td><?php echo get_string('fielddescription', 'data'); ?>:</td>
- <td><input style="width:300px;" type="text" name="description" id="description" value = "<?php echo ($field->description);?>" /></td>
+ <td><input style="width:300px;" type="text" name="description" id="description" value = "<?php echo ($this->field->description);?>" /></td>
</tr>
<tr>
<td valign="top"><?php echo get_string('fieldoptions', 'data'); ?>:</td>
- <td><textarea style="width:300px; height:150px;" name="param1" id="param1" cols="80" rows="10"><?php if($field->param1) {echo $field->param1;} ?></textarea></td>
- </tr>
- <tr>
- <td> </td>
- <td>
- <input type="submit" value="<?php if ($newfield) {echo get_string('add');} else {echo get_string('save','data');} ?>" />
- <input type="submit" value="<?php echo get_string('cancel'); ?>" onclick="document.fieldsubform.mode.value='void';" />
- </td>
+ <td><textarea style="width:300px; height:150px;" name="param1" id="param1" cols="80" rows="10"><?php if($this->field->param1) {echo $this->field->param1;} ?></textarea></td>
</tr>
</table>
-</form>
-<?php ///Class file for textarea field, extends base_field
+<?php // $Id$
///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.org //
// //
-// Copyright (C) 2005 Martin Dougiamas http://dougiamas.com //
+// Copyright (C) 1999-onwards 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 //
// //
///////////////////////////////////////////////////////////////////////////
-/// Please refer to lib.php for method comments
-
class data_field_multimenu extends data_field_base {
var $type = 'multimenu';
- var $id;
-
-
- function data_field_multimenu($fid=0){
- parent::data_field_base($fid);
- }
-
- /***********************************************
- * Saves the field into the database *
- ***********************************************/
- function insert_field($dataid, $type='multimenu', $name, $desc='', $options='') {
- $newfield = new object;
- $newfield->dataid = $dataid;
- $newfield->type = $type;
- $newfield->name = $name;
- $newfield->description = $desc;
- $newfield->param1 = $options;
-
- if (!insert_record('data_fields', $newfield)) {
- notify('Insertion of new field failed!');
- }
+ function data_field_multimenu($field=0, $data=0) {
+ parent::data_field_base($field, $data);
}
- /***********************************************
- * Prints the form element in the add template *
- ***********************************************/
- function display_add_field($id, $rid=0) {
- global $CFG;
- if (!$field = get_record('data_fields', 'id', $id)){
- notify('That is not a valid field id!');
- exit;
- }
- $content = array();
-
- if ($rid) {
- $dbcontent = get_record('data_content', 'fieldid', $id, 'recordid', $rid);
- if (isset($dbcontent->content)) {
- $content = $dbcontent->content;
- $content = explode('##', $content);
- }
- }
- $str = '';
- /*
- if ($field->description) {
- $str .= '<img src="'.$CFG->pixpath.'/help.gif" alt="'.$field->description.'" title="'.$field->description.'" /> ';
+ function display_add_field($recordid=0) {
+
+ if ($recordid){
+ $content = get_field('data_content', 'content', 'fieldid', $this->field->id, 'recordid', $recordid);
+ $content = explode('##', $content);
+ } else {
+ $content = array();
}
- */
- $str .= '<div title="'.$field->description.'">';
- $str .= '<select name="field_' . $field->id . '[]" id="field_' . $field->id . '" multiple="multiple">';
+
+ $str = '<div title="'.$this->field->description.'">';
+ $str .= '<select name="field_' . $this->field->id . '[]" id="field_' . $this->field->id . '" multiple="multiple">';
- foreach (explode("\n",$field->param1) as $option) {
- $option = ltrim(rtrim($option));
+ foreach (explode("\n",$this->field->param1) as $option) {
+ $option = trim($option);
$str .= '<option value="' . $option . '"';
if (array_search($option, $content) !== false) {
// Selected by user.
$str .= ' selected >';
- }
- else {
+ } else {
$str .= '>';
}
$str .= $option . '</option>';
return $str;
}
-
- function display_edit_field($id, $mode=0) {
- parent::display_edit_field($id, $mode);
- }
-
-
-
- function update($fieldobject) {
- $fieldobject->param2 = trim($fieldobject->param1);
-
- if (!update_record('data_fields',$fieldobject)){
- notify ('upate failed');
- }
- }
-
-
- function store_data_content($fieldid, $recordid, $value) {
- $content = new object;
- $content->fieldid = $fieldid;
- $content->recordid = $recordid;
- $content->content = $this->format_data_field_multimenu_content($value);
- insert_record('data_content', $content);
- }
-
-
- function update_data_content($fieldid, $recordid, $value) {
+ function update_content($recordid, $value, $name='') {
$content = new object;
- $content->fieldid = $fieldid;
+ $content->fieldid = $this->field->id;
$content->recordid = $recordid;
$content->content = $this->format_data_field_multimenu_content($value);
-
- if ($oldcontent = get_record('data_content', 'fieldid', $fieldid, 'recordid', $recordid)) {
+
+ if (!$oldcontent = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) {
$content->id = $oldcontent->id;
- update_record('data_content', $content);
- }
- else {
- $this->store_data_content($fieldid, $recordid, $value);
+ return update_record('data_content', $content);
+ } else {
+ return insert_record('data_content', $content);
}
}
-
function format_data_field_multimenu_content($content) {
if (!is_array($content)) {
$str = $content;
}
- function display_browse_field($fieldid, $recordid, $template) {
- global $CFG, $USER, $course;
-
- $field = get_record('data_fields', 'id', $fieldid);
+ function display_browse_field($recordid, $template) {
- if ($content = get_record('data_content', 'fieldid', $fieldid, 'recordid', $recordid)){
+ if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)){
$contentArr = array();
if (!empty($content->content)) {
$contentArr = explode('##', $content->content);
return false;
}
}
-?>
\ No newline at end of file
+?>
-<form name="fieldsubform" action="<?php echo $CFG->wwwroot; ?>/mod/data/fields.php?d=<?php echo ($field->dataid); ?>" method="post">
<table width="100%">
- <tr>
- <td colspan="2">
- <input type="hidden" name="fid" value="<?php echo ($field->id); ?>" />
- <input type="hidden" name="mode" value="<?php if ($newfield) {echo 'add';} else {echo 'update';} ?>" />
- <input type="hidden" name="type" value="<?php echo $this->type; ?>" />
- <input name="sesskey" value="<?php echo sesskey(); ?>" type="hidden" />
- <?php echo ($this->name()); ?>
- </td>
- </tr>
<tr>
<td><?php echo get_string('fieldname', 'data'); ?>:</td>
- <td><input style="width:300px;" type="text" name="name" id="name" value="<?php echo($field->name); ?>" /></td>
+ <td><input style="width:300px;" type="text" name="name" id="name" value="<?php echo($this->field->name); ?>" /></td>
</tr>
<tr>
<td><?php echo get_string('fielddescription', 'data'); ?>:</td>
- <td><input style="width:300px;" type="text" name="description" id="description" value="<?php echo($field->description); ?>" /></td>
+ <td><input style="width:300px;" type="text" name="description" id="description" value="<?php echo($this->field->description); ?>" /></td>
</tr>
<tr>
<td valign="top"><?php echo get_string('fieldoptions', 'data'); ?></td>
- <td><textarea style="width:300px; height:150px;" name="param1" id="param1" cols="80" rows="10"><?php if($field->param1) {echo $field->param1;} ?></textarea></td>
- </tr>
- <tr>
- <td> </td>
- <td>
- <input type="submit" value="<?php if ($newfield) {echo get_string('add');} else {echo get_string('save','data');} ?>" />
- <input type="submit" value="<?php echo get_string('cancel'); ?>" onclick="document.fieldsubform.mode.value='void';" />
- </td>
+ <td><textarea style="width:300px; height:150px;" name="param1" id="param1" cols="80" rows="10"><?php if($this->field->param1) {echo $this->field->param1;} ?></textarea></td>
</tr>
</table>
-</form>
-<?php
+<?php // $Id$
///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.org //
// //
-// Copyright (C) 2005 Martin Dougiamas http://dougiamas.com //
+// Copyright (C) 1999-onwards 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 //
// //
///////////////////////////////////////////////////////////////////////////
-/// Please refer to lib.php for method comments
+require_once($CFG->dirroot.'/mod/data/field/file/field.class.php'); // Base class is 'file'
-global $CFG;
+class data_field_picture extends data_field_file {
-//load base class
-require_once($CFG->dirroot.'/mod/data/field/file/field.class.php');
+ var $type = 'picture';
-class data_field_picture extends data_field_file {// extends
+ var $previewwidth = 50;
+ var $previewheight = 50;
- /* the content field is store as this
- * content = a ## b where a is the filename,
- * b is the alt tag text
- */
- function data_field_picture($fid=0){
- parent::data_field_base($fid);
+ function data_field_picture($field=0, $data=0) {
+ parent::data_field_base($field, $data);
}
- var $type = 'picture';
- var $id;
-
- function insert_field($dataid, $type='picture', $name, $des, $width='', $height='', $maxsize='',
- $widthlist='', $heightlist=''){
- $newfield = new object;
- $newfield->dataid = $dataid;
- $newfield->type = $type;
- $newfield->name = $name;
- $newfield->description = $des;
- $newfield->param1 = $width;
- $newfield->param2 = $height;
- $newfield->param3 = $maxsize;
- $newfield->param4 = $widthlist;
- $newfield->param5 = $heightlist;
- if (!insert_record('data_fields',$newfield)){
- notify('Insertion of new field failed!');
- }
- }
+ function display_add_field($recordid=0){
+ global $CFG;
- function display_add_field($id, $rid=0){
- global $CFG, $course;
- if (!$field = get_record('data_fields','id',$id)){
- notify("that is not a valid field id!");
- exit;
- }
+ $filepath = '';
+ $description = '';
- if ($rid){
- $datacontent = get_record('data_content','fieldid',$id,'recordid',$rid);
- if (isset($datacontent->content)){
- $content = $datacontent->content;
- $contents[0] = $datacontent->content;
- $contents[1] = $datacontent->content1;
- }else {
- $contents = array();
- $contents[0]='';
- $contents[1]='';
+ if ($recordid){
+ if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) {
+ $filename = $content->content;
+ $description = $content->content1;
}
- $des = empty($contents[1])? '':$contents[1];
+
+ $path = $this->data->course.'/'.$CFG->moddata.'/data/'.$this->data->id.'/'.$this->field->id.'/'.$recordid;
+
if ($CFG->slasharguments) {
- $source = $CFG->wwwroot.'/file.php/'.$course->id.'/'.$CFG->moddata.'/data/'.$field->dataid.'/'.$field->id.'/'.$rid;
+ $filepath = $CFG->wwwroot.'/file.php/'.$path.'/'.$filename;
} else {
- $source = $CFG->wwwroot.'/file.php?file=/'.$course->id.'/'.$CFG->moddata.'/data/'.$field->dataid.'/'.$field->id.'/'.$rid;
+ $filepath = $CFG->wwwroot.'/file.php?file=/'.$path.'/'.$filename;
}
}
- else {
- $des = '';
- }
$str = '';
- /*
- if ($field->description){
- $str .= '<img src="'.$CFG->pixpath.'/help.gif" alt="'.$field->description.'" title="'.$field->description.'"> ';
- }
- */
- $str .= '<div title="'.$field->description.'">';
- $str .= '<input type="hidden" name ="field_'.$field->id.'_0" id="field_'.$field->id.'_0" value="fakevalue" />';
- $str .= get_string('picture','data'). ': <input type="file" name ="field_'.$field->id.'" id="field_'.$field->id.'" /><br />';
+ $str .= '<div title="'.$this->field->description.'">';
+ $str .= '<input type="hidden" name ="field_'.$this->field->id.'_0" id="field_'.$this->field->id.'_0" value="fakevalue" />';
+ $str .= get_string('picture','data'). ': <input type="file" name ="field_'.$this->field->id.'" id="field_'.$this->field->id.'" /><br />';
$str .= get_string('optionaldescription','data') .': <input type="text" name="field_'
- .$field->id.'_1" id="field_'.$field->id.'_1" value="'.$des.'" /><br />';
- $str .= '<input type="hidden" name="MAX_FILE_SIZE" value="'.$field->param3.'" />';
- if ($rid and $contents[0]){
- $str .= '<img width="50" height="50" src="'.$source.'/'.$contents[0].'">';
+ .$this->field->id.'_1" id="field_'.$this->field->id.'_1" value="'.$description.'" /><br />';
+ $str .= '<input type="hidden" name="MAX_FILE_SIZE" value="'.$this->field->param3.'" />';
+ if ($filepath){
+ $str .= '<img width="'.$this->previewwidth.'" height="'.$this->previewheight.'" src="'.$filepath.'" />';
}
$str .= '</div>';
return $str;
}
- function display_edit_field($id, $mode=0){
- parent::display_edit_field($id, $mode);
- }
-
- function display_browse_field($fieldid, $recordid, $template) {
- global $CFG, $USER;
+ function display_browse_field($recordid, $template) {
+ global $CFG;
- $field = get_record('data_fields', 'id', $fieldid);
- $data = get_record('data', 'id', $field->dataid);
-
- if ($content = get_record('data_content', 'fieldid', $fieldid, 'recordid', $recordid)){
+ if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)){
if (isset($content->content)){
$contents[0] = $content->content;
$contents[1] = $content->content1;
$title = empty($contents[1])? '':$contents[1];
$src = empty($contents[0])? '':$contents[0];
+ $path = $this->data->course.'/'.$CFG->moddata.'/data/'.$this->data->id.'/'.$this->field->id.'/'.$recordid;
+
if ($CFG->slasharguments) {
- $source = $CFG->wwwroot.'/file.php/'.$data->course.'/'.$CFG->moddata.'/data/'.$field->dataid.'/'.$field->id.'/'.$recordid;
+ $source = $CFG->wwwroot.'/file.php/'.$path;
} else {
- $source = $CFG->wwwroot.'/file.php?file=/'.$data->course.'/'.$CFG->moddata.'/data/'.$field->dataid.'/'.$field->id.'/'.$recordid;
+ $source = $CFG->wwwroot.'/file.php?file=/'.$path;
}
if ($template == 'listtemplate') {
- $width = $field->param4 ? ' width="'.$field->param4.'" ':' ';
- $height = $field->param5 ? ' height="'.$field->param5.'" ':' ';
- $str = '<a href="view.php?d='.$field->dataid.'&rid='.$recordid.'"><img '.$width.$height.' src="'.$source.'/'.$src.'" alt="'.$alt.'" title="'.$title.'" border="0" /></a>';
+ $width = $this->field->param4 ? ' width="'.$this->field->param4.'" ' : ' ';
+ $height = $this->field->param5 ? ' height="'.$this->field->param5.'" ' : ' ';
+ $str = '<a href="view.php?d='.$this->field->dataid.'&rid='.$recordid.'"><img '.
+ $width.$height.' src="'.$source.'/'.$src.'" alt="'.$alt.'" title="'.$title.'" border="0" /></a>';
} else {
- $width = $field->param1 ? ' width="'.$field->param1.'" ':' ';
- $height = $field->param2 ? ' height="'.$field->param2.'" ':' ';
+ $width = $this->field->param1 ? ' width="'.$this->field->param1.'" ':' ';
+ $height = $this->field->param2 ? ' height="'.$this->field->param2.'" ':' ';
$str = '<img '.$width.$height.' src="'.$source.'/'.$src.'" alt="'.$alt.'" title="'.$title.'" />';
}
return $str;
return false;
}
- function update($fieldobject){
- parent::update($fieldobject);
- }
-
- function store_data_content($fieldid, $recordid, $value, $name=''){
- parent::store_data_content($fieldid, $recordid, $value, $name);
- }
-
- function update_data_content($fieldid, $recordid, $value, $name){
- parent::update_data_content($fieldid, $recordid, $value, $name);
- }
-
- function notemptyfield($value, $name){
- return (parent::notemptyfield($value, $name));
- }
-
}
?>
-<form name="fieldsubform" action="<?php echo $CFG->wwwroot; ?>/mod/data/fields.php?d=<?php echo ($field->dataid); ?>" method="post">
<table width="100%">
- <tr>
- <td colspan="2">
- <?php echo ($this->name()); ?>
- </td>
- </tr>
<tr>
<td>
- <?php echo get_string('fieldname', 'data');?>:</td><td><input style="width:300px;" type="text" name="name" id="name" value = "<?php echo($field->name); ?>" />
+ <?php echo get_string('fieldname', 'data');?>:</td><td><input style="width:300px;" type="text" name="name" id="name" value = "<?php echo($this->field->name); ?>" />
</td>
</tr>
<tr>
<?php echo get_string('fielddescription', 'data');?>:
</td>
<td>
- <input style="width:300px;" type="text" name="description" id="description" value = "<?php echo ($field->description);?>" />
+ <input style="width:300px;" type="text" name="description" id="description" value = "<?php echo ($this->field->description);?>" />
</td>
</tr>
<tr>
<?php echo get_string('fieldwidthsingleview', 'data');?>:
</td>
<td>
- <input style="width:70px;" type="text" name="param1" id="param1" value = "<?php if (!empty($field->param1)) echo $field->param1; ?>" />
+ <input style="width:70px;" type="text" name="param1" id="param1" value = "<?php if (!empty($this->field->param1)) echo $this->field->param1; ?>" />
</td>
</tr>
<tr>
<?php echo get_string('fieldheightsingleview', 'data');?>:
</td>
<td>
- <input style="width:70px;" type="text" name="param2" id="param2" value = "<?php if (!empty($field->param2)) echo $field->param2; ?>" />
+ <input style="width:70px;" type="text" name="param2" id="param2" value = "<?php if (!empty($this->field->param2)) echo $this->field->param2; ?>" />
</td>
</tr>
<tr>
<td>
- <?php echo get_string('fieldwidthlistview', 'data');?>:</td><td><input style="width:70px;" type="text" name="param4" id="param4" value = "<?php if (!empty($field->param4)) echo $field->param4; ?>" />
+ <?php echo get_string('fieldwidthlistview', 'data');?>:</td><td><input style="width:70px;" type="text" name="param4" id="param4" value = "<?php if (!empty($this->field->param4)) echo $this->field->param4; ?>" />
</td>
</tr>
<tr>
<?php echo get_string('fieldheightlistview', 'data');?>:
</td>
<td>
- <input style="width:70px;" type="text" name="param5" id="param5" value = "<?php if (!empty($field->param5)) echo $field->param5; ?>" />
+ <input style="width:70px;" type="text" name="param5" id="param5" value = "<?php if (!empty($this->field->param5)) echo $this->field->param5; ?>" />
</td>
</tr>
<tr>
</td>
<td>
<?php
+ $course->maxbytes = get_field('course', 'maxbytes', 'id', $this->data->course);
$choices = get_max_upload_sizes($CFG->maxbytes, $course->maxbytes);
- choose_from_menu ($choices, "param3", $field->param3, "");
+ choose_from_menu ($choices, "param3", $this->field->param3, "");
?>
</td>
</tr>
- <tr>
- <td> </td>
- <td>
- <input type="submit" value="<?php if ($newfield) {echo get_string('add');} else {echo get_string('save','data');} ?>" />
- <input type="hidden" name="fid" value="<?php echo ($field->id); ?>" />
- <input type="hidden" name="mode" value="<?php if ($newfield) {echo 'add';} else {echo 'update';} ?>" />
- <input type="hidden" name="type" value="<?php echo $this->type; ?>" />
- <input type="submit" value="<?php echo get_string('cancel'); ?>" onclick="document.fieldsubform.mode.value='void';" />
- <input name="sesskey" value="<?php echo sesskey(); ?>" type="hidden" />
- </td>
</tr>
</table>
-</form>
-<?php ///Class file for textarea field, extends base_field
+<?php // $Id$
///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.org //
// //
-// Copyright (C) 2005 Martin Dougiamas http://dougiamas.com //
+// Copyright (C) 1999-onwards 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 //
// //
///////////////////////////////////////////////////////////////////////////
-/// Please refer to lib.php for method comments
-
class data_field_radiobutton extends data_field_base {
var $type = 'radiobutton';
- var $id;
-
- function data_field_radiobutton($fid=0){
- parent::data_field_base($fid);
+ function data_field_radiobutton($field=0, $data=0) {
+ parent::data_field_base($field, $data);
}
- /***********************************************
- * Saves the field into the database *
- ***********************************************/
- function insert_field($dataid, $type='radiobutton', $name, $desc='', $options='') {
- $newfield = new object;
- $newfield->dataid = $dataid;
- $newfield->type = $type;
- $newfield->name = $name;
- $newfield->description = $desc;
- $newfield->param1 = $options;
-
- if (!insert_record('data_fields', $newfield)) {
- notify('Insertion of new field failed!');
- }
- }
-
-
- /***********************************************
- * Prints the form element in the add template *
- ***********************************************/
- function display_add_field($id, $rid=0) {
+ function display_add_field($recordid=0) {
global $CFG;
- if (!$field = get_record('data_fields', 'id', $id)){
- notify('That is not a valid field id!');
- exit;
- }
- if ($rid) {
- $content = get_record('data_content', 'fieldid', $id, 'recordid', $rid);
- if (isset($content->content)) {
- $content = $content->content;
- }
- }
- else {
+
+ if ($recordid){
+ $content = trim(get_field('data_content', 'content', 'fieldid', $this->field->id, 'recordid', $recordid));
+ } else {
$content = '';
}
- $str = '';
- /*
- if ($field->description) {
- $str .= '<img src="'.$CFG->pixpath.'/help.gif" alt="'.$field->description.'" title="'.$field->description.'" /> ';
- }
- */
- $str .= '<div title="'.$field->description.'">';
+
+ $str = '<div title="'.$this->field->description.'">';
- foreach (explode("\n",$field->param1) as $radio) {
- $radio = ltrim(rtrim($radio));
- $str .= '<input type="radio" name="field_' . $field->id . '" ';
+ foreach (explode("\n",$this->field->param1) as $radio) {
+ $radio = trim($radio);
+ $str .= '<input type="radio" name="field_' . $this->field->id . '" ';
$str .= 'value="' . $radio . '" ';
if ($content == $radio) {
// Selected by user.
$str .= 'checked />';
- }
- else {
+ } else {
$str .= '/>';
}
return $str;
}
-
- function display_edit_field($id, $mode=0) {
- parent::display_edit_field($id, $mode);
- }
-
-
- function update($fieldobject) {
- $fieldobject->param1 = trim($fieldobject->param1);
-
- if (!update_record('data_fields',$fieldobject)){
- notify ('upate failed');
- }
- }
}
?>
-<form name="fieldsubform" action="<?php echo $CFG->wwwroot; ?>/mod/data/fields.php?d=<?php echo ($field->dataid); ?>" method="post">
<table width="100%">
- <tr>
- <td colspan="2">
- <input type="hidden" name="fid" value="<?php echo ($field->id); ?>" />
- <input type="hidden" name="mode" value="<?php if ($newfield) {echo 'add';} else {echo 'update';} ?>" />
- <input type="hidden" name="type" value="<?php echo $this->type; ?>" />
- <input name="sesskey" value="<?php echo sesskey(); ?>" type="hidden" />
- <?php echo ($this->name()); ?>
- </td>
- </tr>
<tr>
<td><?php echo get_string('fieldname', 'data'); ?>:</td>
- <td><input style="width:300px;" type="text" name="name" id="name" value="<?php echo($field->name); ?>" /></td>
+ <td><input style="width:300px;" type="text" name="name" id="name" value="<?php echo($this->field->name); ?>" /></td>
</tr>
<tr>
<td><?php echo get_string('fielddescription', 'data'); ?>:</td>
- <td><input style="width:300px;" type="text" name="description" id="description" value="<?php echo($field->description); ?>" /></td>
+ <td><input style="width:300px;" type="text" name="description" id="description" value="<?php echo($this->field->description); ?>" /></td>
</tr>
<tr>
<td valign="top"><?php echo get_string('fieldoptions', 'data'); ?>:</td>
- <td><textarea style="width:300px; height:150px;" name="param1" id="param1" cols="80" rows="10"><?php if($field->param1) {echo $field->param1;} ?></textarea></td>
- </tr>
- <tr>
- <td> </td>
- <td>
- <input type="submit" value="<?php if ($newfield) {echo get_string('add');} else {echo get_string('save','data');} ?>" />
- <input type="submit" value="<?php echo get_string('cancel'); ?>" onclick="document.fieldsubform.mode.value='void';" />
- </td>
+ <td><textarea style="width:300px; height:150px;" name="param1" id="param1" cols="80" rows="10"><?php if($this->field->param1) {echo $this->field->param1;} ?></textarea></td>
</tr>
</table>
-</form>
-<?php ///Class file for textarea field, extends base_field
+<?php // $Id$
///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.org //
// //
-// Copyright (C) 2005 Martin Dougiamas http://dougiamas.com //
+// Copyright (C) 1999-onwards 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 //
// //
///////////////////////////////////////////////////////////////////////////
-/// Please refer to lib.php for method comments
-
class data_field_text extends data_field_base {
var $type = 'text';
- var $id;
- function get_sort_field() {
- return parent::get_sort_field();
+ function data_field_text($field=0, $data=0) {
+ parent::data_field_base($field, $data);
}
}
+
?>
-<form name="fieldsubform" action="<?php echo $CFG->wwwroot; ?>/mod/data/fields.php?d=<?php echo ($field->dataid); ?>" method="post">
<table width="100%">
- <tr>
- <td colspan="2">
- <input type="hidden" name="fid" value="<?php echo ($field->id); ?>" />
- <input type="hidden" name="mode" value="<?php if ($newfield) {echo 'add';} else {echo 'update';} ?>" />
- <input type="hidden" name="type" value="<?php echo $this->type; ?>" />
- <input name="sesskey" value="<?php echo sesskey(); ?>" type="hidden" />
- <?php echo ($this->name()); ?>
- </td>
- </tr>
<tr>
<td><?php echo get_string('fieldname', 'data'); ?>:</td>
- <td><input style="width:300px;" type="text" name="name" id="name" value="<?php echo($field->name); ?>" /></td>
+ <td><input style="width:300px;" type="text" name="name" id="name" value="<?php echo($this->field->name); ?>" /></td>
</tr>
<tr>
<td><?php echo get_string('fielddescription', 'data'); ?>:</td>
- <td><input style="width:300px;" type="text" name="description" id="description" value="<?php echo($field->description); ?>" /></td>
+ <td><input style="width:300px;" type="text" name="description" id="description" value="<?php echo($this->field->description); ?>" /></td>
</tr>
<tr>
<td><?php echo get_string('fieldallowautolink', 'data'); ?>:</td>
- <td><input type="checkbox" name="param1" id="param1" <?php if($field->param1) {echo 'checked="checked"';} ?> value="1" /></td>
- </tr>
- <tr>
- <td> </td>
- <td>
- <input type="submit" value="<?php if ($newfield) {echo get_string('add');} else {echo get_string('save','data');} ?>" />
- <input type="submit" value="<?php echo get_string('cancel'); ?>" onclick="document.fieldsubform.mode.value='void';" />
- </td>
+ <td><input type="checkbox" name="param1" id="param1" <?php if($this->field->param1) {echo 'checked="checked"';} ?> value="1" /></td>
</tr>
</table>
-</form>
-<?php ///Class file for textarea field, extends base_field
+<?php // $Id$
///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.org //
// //
-// Copyright (C) 2005 Martin Dougiamas http://dougiamas.com //
+// Copyright (C) 1999-onwards 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 //
// //
///////////////////////////////////////////////////////////////////////////
-/// Please refer to lib.php for method comments
-
class data_field_textarea extends data_field_base {
var $type = 'textarea';
- var $id;
-
-
- function data_field_textarea($fid=0){
- parent::data_field_base($fid);
- }
-
- /***********************************************
- * Saves the field into the database *
- ***********************************************/
- function insert_field($dataid, $type='textarea', $name, $desc='', $width='', $height='') {
- $newfield = new object;
- $newfield->dataid = $dataid;
- $newfield->type = $type;
- $newfield->name = $name;
- $newfield->description = $desc;
- $newfield->param1 = $width;
- $newfield->param2 = $height;
-
- if (!insert_record('data_fields', $newfield)) {
- notify('Insertion of new field failed!');
- }
+ function data_field_textarea($field=0, $data=0) {
+ parent::data_field_base($field, $data);
}
- /***********************************************
- * Prints the form element in the add template *
- ***********************************************/
- function display_add_field($id, $rid=0) {
+ function display_add_field($recordid=0) {
global $CFG;
- if (!$field = get_record('data_fields', 'id', $id)){
- notify('That is not a valid field id!');
- exit;
- }
- if ($rid) {
- $dataContent = get_record('data_content', 'fieldid', $id, 'recordid', $rid);
- $content = $dataContent->content;
- }
- else {
- $content = '';
+
+ if ($recordid){
+ $content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid);
+ $text = $content->content;
+ $format = $content->content1;
+ } else {
+ $text = '';
+ $format = '';
}
- $str = '';
- /*
- if ($field->description) {
- $str .= '<img src="'.$CFG->pixpath.'/help.gif" alt="'.$field->description.'" title="'.$field->description.'" /> ';
- }*/
- $str .= '<div title="'.$field->description.'">';
+
+ $str = '<div title="'.$thisfield->description.'">';
if (can_use_richtext_editor()) {
// Show a rich text html editor.
- $str .= helpbutton("richtext", get_string("helprichtext"), "moodle", true, true, '', true);
- $str .= data_field_textarea::gen_textarea(true, 'field_' . $field->id, $field->param2, $field->param3, $content);
- $str .= '<input type="hidden" name="field_' . $field->id . '_content1' . '" value="' . FORMAT_HTML . '" />';
- }
- else {
+ $str .= helpbutton("richtext", get_string("helprichtext"), 'moodle', true, true, '', true);
+ $str .= $this->gen_textarea(true, $text);
+ $str .= '<input type="hidden" name="field_' . $this->field->id . '_content1' . '" value="' . FORMAT_HTML . '" />';
+
+ } else {
// Show a normal textarea. Also let the user specify the format to be used.
- $str .= data_field_textarea::gen_textarea(false, 'field_' . $field->id, $field->param2, $field->param3, $content);
+ $str .= $this->gen_textarea(false, $text);
+
// Get the available text formats for this field.
$formatsForField = format_text_menu();
$str .= '<br />';
- if (empty($dataContent->content1)) {
- $str .= choose_from_menu($formatsForField, 'field_' . $field->id . '_content1', '', 'choose', '', '', true);
- }
- else {
- $str .= choose_from_menu($formatsForField, 'field_' . $field->id . '_content1', $dataContent->content1, 'choose', '', '', true);
- }
- $str .= helpbutton("textformat", get_string("helpformatting"), 'moodle', true, false, '', true);
+ $str .= choose_from_menu($formatsForField, 'field_' . $this->field->id .
+ '_content1', $format, 'choose', '', '', true);
+
+ $str .= helpbutton('textformat', get_string('helpformatting'), 'moodle', true, false, '', true);
}
$str .= '</div>';
return $str;
}
- function gen_textarea($usehtmleditor, $name, $cols=65, $rows=10, $value='') {
- global $CFG, $course;
-
- return print_textarea($usehtmleditor, $rows, $cols, '', '', $name, $value, '', true);
+ function gen_textarea($usehtmleditor, $text='') {
+ return print_textarea($usehtmleditor, $this->field->param3, $this->field->param2,
+ '', '', 'field_'.$this->field->id, $text, '', true);
}
function print_after_form() {
if (can_use_richtext_editor()) {
- use_html_editor('field_' . $this->id);
+ use_html_editor('field_' . $this->field->id);
}
}
- function display_edit_field($id, $mode=0) {
- parent::display_edit_field($id, $mode);
- }
-
-
- function update($fieldobject) {
- $fieldobject->param1 = trim($fieldobject->param1);
- $fieldobject->param2 = trim($fieldobject->param2);
-
- if (!update_record('data_fields',$fieldobject)){
- notify ('upate failed');
- }
- }
-
-
- /************************************
- * store content of this field type *
- ************************************/
- function store_data_content($fieldid, $recordid, $value, $name=''){
- if ($value) {
- $content = new object;
- $content->fieldid = $fieldid;
- $content->recordid = $recordid;
-
- if ($oldcontent = get_record('data_content','fieldid', $fieldid, 'recordid', $recordid)) {
- // This belongs to an existing data_content.
- $content->id = $oldcontent->id;
- $nameParts = explode('_', $name);
- $column = $nameParts[count($nameParts) - 1]; // Format is field_<fieldid>_content[1 to 4]
-
- $content->$column = clean_param($value, PARAM_INT);
- update_record('data_content', $content);
- }
- else {
- // First (and maybe only) data content for this field for this record.
- $content->content = clean_param($value, PARAM_CLEANHTML);
- insert_record('data_content', $content);
- }
+ function update_content($recordid, $value, $name='') {
+ $content = new object;
+ $content->fieldid = $this->field->id;
+ $content->recordid = $recordid;
+ $content->content = $this->format_data_field_multimenu_content($value);
+
+ $names = explode('_', $name);
+ if (!empty($names[2])) {
+ $content->$names[2] = clean_param($value, PARAM_NOTAGS); // content[1-4]
+ } else {
+ $content->content = clean_param($value, PARAM_NOTAGS);
}
- }
-
-
- /*************************************
- * update content of this field type *
- *************************************/
- function update_data_content($fieldid, $recordid, $value, $name=''){
- // If data_content already exists, we update.
- if ($oldcontent = get_record('data_content', 'fieldid', $fieldid, 'recordid', $recordid)){
- $content = new object;
- $content->fieldid = $fieldid;
- $content->recordid = $recordid;
-
- $nameParts = explode('_', $name);
- if (!empty($nameParts[2])) {
- $content->$nameParts[2] = clean_param($value, PARAM_NOTAGS);
- }
- else {
- $content->content = clean_param($value, PARAM_NOTAGS);
- }
+
+ if (!$oldcontent = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) {
$content->id = $oldcontent->id;
- update_record('data_content', $content);
- }
- else { //make 1 if there isn't one already
- $this->store_data_content($fieldid, $recordid, $value, $name='');
+ return update_record('data_content', $content);
+ } else {
+ return insert_record('data_content', $content);
}
}
}
-<form name="fieldsubform" action="<?php echo $CFG->wwwroot; ?>/mod/data/fields.php?d=<?php echo ($field->dataid); ?>" method="post">
<table width="100%">
- <tr>
- <td colspan="2">
- <input type="hidden" name="fid" value="<?php echo ($field->id); ?>" />
- <input type="hidden" name="mode" value="<?php if ($newfield) {echo 'add';} else {echo 'update';} ?>" />
- <input type="hidden" name="type" value="<?php echo $this->type; ?>" />
- <input name="sesskey" value="<?php echo sesskey(); ?>" type="hidden" />
- <?php echo ($this->name()); ?>
- </td>
- </tr>
<tr>
<td><?php echo get_string('fieldname', 'data'); ?>:</td>
- <td><input style="width:300px;" type="text" name="name" id="name" value="<?php echo($field->name); ?>" /></td>
+ <td><input style="width:300px;" type="text" name="name" id="name" value="<?php echo($this->field->name); ?>" /></td>
</tr>
<tr>
<td><?php echo get_string('fielddescription', 'data'); ?>:</td>
- <td><input style="width:300px;" type="text" name="description" id="description" value="<?php echo($field->description); ?>" /></td>
+ <td><input style="width:300px;" type="text" name="description" id="description" value="<?php echo($this->field->description); ?>" /></td>
</tr>
<tr>
<td><?php echo get_string('fieldwidth', 'data'); ?>:</td>
- <td><input style="width:50px;" type="text" name="param2" id="width" value="<?php echo($field->param2); ?>" /> columns</td>
+ <td><input style="width:50px;" type="text" name="param2" id="width" value="<?php echo($this->field->param2); ?>" /> columns</td>
</tr>
<tr>
<td><?php echo get_string('fieldheight', 'data'); ?>:</td>
- <td><input style="width:50px;" type="text" name="param3" id="height" value="<?php echo($field->param3); ?>" /> rows</td>
- </tr>
- <tr>
- <td> </td>
- <td>
- <input type="submit" value="<?php if ($newfield) {echo get_string('add');} else {echo get_string('save','data');} ?>" />
- <input type="submit" value="<?php echo get_string('cancel'); ?>" onclick="document.fieldsubform.mode.value='void';" />
- </td>
+ <td><input style="width:50px;" type="text" name="param3" id="height" value="<?php echo($this->field->param3); ?>" /> rows</td>
</tr>
</table>
-</form>
-<?php
+<?php // $Id$
///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.org //
// //
-// Copyright (C) 2005 Martin Dougiamas http://dougiamas.com //
+// Copyright (C) 1999-onwards 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 //
// //
///////////////////////////////////////////////////////////////////////////
-/// Please refer to lib.php for method comments
-
-global $CFG;
-
-require_once($CFG->dirroot.'/mod/data/lib.php');
-
-class data_field_url extends data_field_base {// extends
-
- function data_field_url($fid=0){
- parent::data_field_base($fid);
- }
+class data_field_url extends data_field_base {
var $type = 'url';
- var $id; //field id
- function insert_field($dataid, $type='text', $name, $des=''){
- $newfield = new object;
- $newfield->dataid = $dataid;
- $newfield->type = $type;
- $newfield->name = $name;
- $newfield->description = $des;
- if (!insert_record('data_fields',$newfield)){
- notify('Insertion of new field failed!');
- }
+ function data_field_text($field=0, $data=0) {
+ parent::data_field_base($field, $data);
}
- function display_add_field($id, $rid=0){
+ function display_add_field($recordid=0){
global $CFG;
- if (!$field = get_record('data_fields','id',$id)){
- notify("that is not a valid field id!");
- exit;
- }
- //look for that record and pull it out
- if ($rid){
- $datacontent = get_record('data_content','fieldid',$id,'recordid',$rid);
- $contents = array();
- if (isset($datacontent->content)){
- $content = $datacontent->content;
- $contents[0] = $datacontent->content;
- $contents[1] = $datacontent->content1;
- }else {
- $contents[0]='';
- $contents[1]='';
+
+ $url = '';
+ $text = '';
+
+ if ($recordid){
+ if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) {
+ $url = $content->content;
+ $text = $content->content1;
}
}
- $url = empty($contents[0])? 'http://':$contents[0];
- $text = empty($contents[1])? '':$contents[1];
+ $url = empty($url) ? 'http://' : $url;
- $str = '<div title="'.$field->description.'">';
+ $str = '<div title="'.$this->field->description.'">';
$str .= '<table><tr><td align="right">';
- /*
- if ($field->description){
- $str .= '<img src="'.$CFG->pixpath.'/help.gif" alt="'.$field->description.'" title="'.$field->description.'"> ';
+ $str .= get_string('url','data').':</td><td><input type="text" name="field_'.$this->field->id.'_0" id="field_'.$this->field->id.'_0" value="'.$url.'" /></td></tr>';
+ if (!empty($this->field->param1)) {
+ $str .= '<tr><td align="right">'.get_string('text','data').':</td><td><input type="text" name="field_'.$this->field->id.'_1" id="field_'.$this->field->id.'_1" value="'.$text.'" /></td></tr>';
}
- */
- $str .= get_string('url','data').':</td><td><input type="text" name="field_'.$field->id.'_0" id="field_'.$field->id.'_0" value="'.$url.'" /></td></tr>';
- $str .= '<tr><td align="right">'.get_string('text','data').':</td><td><input type="text" name="field_'.$field->id.'_1" id="field_'.$field->id.'_1" value="'.$text.'" /></td></tr>';
$str .= '</table>';
$str .= '</div>';
return $str;
}
- function display_edit_field($id, $mode=0){
- parent::display_edit_field($id, $mode);
- }
-
- function display_browse_field($fieldid, $recordid, $template) {
- if ($content = get_record('data_content', 'fieldid', $fieldid, 'recordid', $recordid)){
+ function display_browse_field($recordid, $template) {
+ if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)){
$url = empty($content->content)? '':$content->content;
$text = empty($content->content1)? '':$content->content1;
if (empty($text)){
return '<a href = "'.$url.'">'.$text.'</a>';
}
return false;
-
- }
-
- function update($fieldobject){
- if (!update_record('data_fields',$fieldobject)){
- notify ('upate failed');
- }
}
- function store_data_content($fieldid, $recordid, $value, $name=''){
+ function update_content($recordid, $value, $name='') {
$content = new object;
- $content->fieldid = $fieldid;
+ $content->fieldid = $this->field->id;
$content->recordid = $recordid;
- $content->content = $value;
- $names = explode('_',$name);
+ $content->content = $this->format_data_field_multimenu_content($value);
+
+ $names = explode('_', $name);
switch ($names[2]){
- case 1: //add text
- if ($oldcontent = get_record('data_content','fieldid', $fieldid, 'recordid', $recordid)){
- if ($value){
- $content->id = $oldcontent->id;
- $content->content = $oldcontent->content;
- $content->content1 = clean_param($value, PARAM_NOTAGS);
- update_record('data_content',$content);
- }
- }
- break;
- case 0: //add link
- if ($value){
- $content->content = clean_param($value, PARAM_URL);
- if ($content->content != 'http://' && $content->content != ''){
- insert_record('data_content',$content); //after trim if content is still there
- }
- else {
- notify(get_string('invalidurl','data'));
- }
- } //no point adding if it's empty
- break;
- default:
+ case 0: // update link
+ $content->content = clean_param($value, PARAM_URL);
break;
- }
- }
-
- function update_data_content($fieldid, $recordid, $value, $name){
- //if data_content already exists, we update
- if ($oldcontent = get_record('data_content','fieldid', $fieldid, 'recordid', $recordid)){
- $content = new object;
- $content->fieldid = $fieldid;
- $content->recordid = $recordid;
- $content->id = $oldcontent->id;
-
- $contents[0] = $oldcontent->content;
- $contents[1] = $oldcontent->content1;
- $names = explode('_',$name);
- switch ($names[2]){
- case 1: //add text
- $content->content = $contents[0];
+ case 1: // add text
$content->content1 = clean_param($value, PARAM_NOTAGS);
- update_record('data_content',$content);
- break;
- case 0: //update link
- $content->content = clean_param($value, PARAM_URL);
- $content->content1 = $contents[1];
- update_record('data_content',$content);
break;
default:
break;
- }
}
- else { //make 1 if there isn't one already
- $this->store_data_content($fieldid, $recordid, $value, $name);
+
+ if (!$oldcontent = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) {
+ $content->id = $oldcontent->id;
+ return update_record('data_content', $content);
+ } else {
+ return insert_record('data_content', $content);
}
}
-<form name="fieldsubform" action="<?php echo $CFG->wwwroot; ?>/mod/data/fields.php?d=<?php echo ($field->dataid); ?>" method="post">
<table width="100%">
- <tr>
- <td colspan="2">
- <?php echo ($this->name()); ?>
- </td>
- </tr>
<tr>
<td>
<?php echo get_string('fieldname', 'data'); ?>:
</td>
<td>
- <input style="width:350px;" type="text" name="name" id="name" value = "<?php echo($field->name); ?>" />
+ <input style="width:350px;" type="text" name="name" id="name" value = "<?php echo($this->field->name); ?>" />
</td>
</tr>
<tr>
<?php echo get_string('fielddescription', 'data'); ?>:
</td>
<td>
- <input style="width:350px;" type="text" name="description" id="description" value = "<?php echo ($field->description);?>" />
- </td>
- </tr>
- <tr>
- <td> </td>
- <td>
- <input type="submit" value="<?php if ($newfield) {echo get_string('add');} else {echo get_string('save','data');} ?>" />
- <input type="hidden" name="fid" value="<?php echo ($field->id); ?>" />
- <input type="hidden" name="mode" value="<?php if ($newfield) {echo 'add';} else {echo 'update';} ?>" />
- <input type="hidden" name="type" value="<?php echo $this->type; ?>" />
- <input type="submit" value="<?php echo get_string('cancel'); ?>" onclick="document.fieldsubform.mode.value='void';" />
- <input name="sesskey" value="<?php echo sesskey(); ?>" type="hidden" />
+ <input style="width:350px;" type="text" name="description" id="description" value = "<?php echo ($this->field->description);?>" />
</td>
</tr>
</table>
-</form>
\ No newline at end of file
require_once('../../config.php');
require_once('lib.php');
- require_once($CFG->libdir.'/blocklib.php');
- require_once('pagelib.php');
require_login();
$id = optional_param('id', 0, PARAM_INT); // course module id
//action specifies what action is performed when data is submitted
$mode = optional_param('mode','',PARAM_ALPHA);
- $displayflag = ''; //str to print after an operation,
+ $displaynotice = ''; //str to print after an operation,
if ($id) {
if (! $cm = get_record('course_modules', 'id', $id)) {
$strdata = get_string('modulenameplural','data');
- print_header_simple($data->name, "", "<a href='index.php?id=$course->id'>$strdata</a> -> $data->name", "", "", true, "", navmenu($course, $cm));
+ print_header_simple($data->name, '', "<a href='index.php?id=$course->id'>$strdata</a> -> $data->name",
+ '', '', true, '', navmenu($course, $cm));
print_heading(format_string($data->name));
/************************************
* Data Processing *
***********************************/
- switch($mode){
+ switch ($mode){
case 'add': ///add a new field
- if (confirm_sesskey() and $field = data_submitted($CFG->wwwroot.'/mod/data/fields.php')){
+ if (confirm_sesskey() and $fieldinput = data_submitted($CFG->wwwroot.'/mod/data/fields.php')){
- $sql = 'SELECT * from '.$CFG->prefix.'data_fields WHERE name LIKE "'.$field->name.
- '" AND dataid = '.$data->id;
-
- if ($field->name and !get_record_sql($sql)){
- $field->dataid = $data->id;
-
- // Check for arrays. If we encounter an array, we save the array as a
- // comma-delimited string in the database.
- foreach ($field as $key=>$val) {
- if (is_array($val)) {
- $str = '';
- foreach ($val as $inner) {
- $str .= $inner . ',';
- }
- $str = substr($str, 0, -1);
-
- $field->$key = $str;
- }
- }
- $field->id = insert_record('data_fields', $field);
+ /// Only store this new field if it doesn't already exist.
+ if (data_fieldname_exists($fieldinput->name, $data->id)) {
+
+ $displaynotice = get_string('invalidfieldname','data');
+
+ } else {
- // Add the new field to the form templates.
- data_append_field_in_form($field->dataid, $field->name);
+ /// Check for arrays and convert to a comma-delimited string
+ data_convert_arrays_to_strings($fieldinput);
+
+ /// Create a field object to collect and store the data safely
+ $type = required_param('type', PARAM_FILE);
+ $field = data_get_field_new($type, $data);
+
+ $field->define_field($fieldinput);
+ $field->insert_field();
+
+ /// Update some templates
+ data_append_new_field_to_templates($data, $field->field->name);
- add_to_log($course->id, 'data', 'fields add', "fields.php?d=$data->id&mode=display&fid=$field->id", $field->id, $cm->id);
+ add_to_log($course->id, 'data', 'fields add',
+ "fields.php?d=$data->id&mode=display&fid=$fid", $fid, $cm->id);
- $displayflag = get_string('fieldadded','data');
+ $displaynotice = get_string('fieldadded','data');
}
- else { //no duplicate names allowed in one database!
- $displayflag = get_string('invalidfieldname','data');
+ }
+ break;
+
+
+ case 'update': ///update a field
+ if (confirm_sesskey() and $fieldinput = data_submitted($CFG->wwwroot.'/mod/data/fields.php')){
+
+ $fieldinput->name = optional_param('name','',PARAM_NOTAGS);
+
+ if (data_fieldname_exists($fieldinput->name, $data->id, $fid)) {
+ $displaynotice = get_string('invalidfieldname','data');
+
+ } else {
+ /// Check for arrays and convert to a comma-delimited string
+ data_convert_arrays_to_strings($fieldinput);
+
+ /// Create a field object to collect and store the data safely
+ $field = data_get_field_from_id($fid, $data);
+ $oldfieldname = $field->field->name;
+ $field->update_field($fieldinput);
+
+ /// Update the templates.
+ data_replace_field_in_templates($data, $oldfieldname, $field->field->name);
+
+ add_to_log($course->id, 'data', 'fields update',
+ "fields.php?d=$data->id&mode=display&fid=$fid", $fid, $cm->id);
+
+ $displaynotice = get_string('fieldupdated','data');
}
}
break;
+
case 'delete': // Delete a field
if (confirm_sesskey()){
if ($confirm = optional_param('confirm', 0, PARAM_INT)) {
- // Delete the associated data_contents and files.
- if (!$fieldRecordSet = get_record('data_fields', 'id', $fid)) {
- notify('Field not found');
- exit;
- }
- $field = data_get_field($fieldRecordSet);
- $field->delete_data_contents();
-
- // Update the templates.
- data_replace_field_in_forms($fieldRecordSet->dataid, $fieldRecordSet->name, '');
- // Delete the field.
- delete_records('data_fields', 'id', $fid);
+ // Delete the field completely
+ $field = data_get_field_from_id($fid, $data);
+ $field->delete_field();
- add_to_log($course->id, 'data', 'fields delete', "fields.php?d=$data->id", $fieldRecordSet->name, $cm->id);
+ // Update the templates.
+ data_replace_field_in_templates($data, $field->field->name, '');
- $displayflag = get_string('fielddeleted', 'data');
- }
- else {
+ add_to_log($course->id, 'data', 'fields delete',
+ "fields.php?d=$data->id", $field->field->name, $cm->id);
+
+ $displaynotice = get_string('fielddeleted', 'data');
+
+ } else {
// Print confirmation message.
- $field = get_record('data_fields','id',$fid);
+ $field = data_get_field_from_id($fid, $data);
+
print_simple_box_start('center', '60%');
echo '<div align="center">';
echo '<form action = "fields.php?d='.$data->id.'&mode=delete&fid='.$fid.'" method="post">';
echo '<input name="sesskey" value="'.sesskey().'" type="hidden" />';
echo '<input name="confirm" value="1" type="hidden" />';
- echo '<strong>'.$field->name.'</strong> - '.get_string('confirmdeletefield','data');
- echo '<p />';
+ echo '<strong>'.$field->field->name.'</strong> - '.get_string('confirmdeletefield','data');
+ echo '<p>';
echo '<input type="submit" value="'.get_string('ok').'" /> ';
echo '<input type="button" value="'.get_string('cancel').'" onclick="javascript:history.go(-1);" />';
+ echo '<p>';
echo '</form>';
echo '</div>';
print_simple_box_end();
}
break;
- case 'update': ///update a field
- if (confirm_sesskey() and $field = data_submitted($CFG->wwwroot.'/mod/data/fields.php')){
- $field->id = $fid;
-
- $field->name = optional_param('name','',PARAM_NOTAGS);
- $sql = 'SELECT * from '.$CFG->prefix.'data_fields WHERE name LIKE "'.$field->name.
- '" AND dataid = '.$data->id.' AND ((id < '.$field->id.') OR (id > '.$field->id.'))';
-
- if ($field->name and !get_records_sql($sql)){
- //depends on the type of field, perform native update methods
- $currentfield = get_record('data_fields','id',$fid);
- $g = data_get_field($currentfield);
- $g->update($field);
- unset($g);
-
- // Update the templates.
- data_replace_field_in_forms($currentfield->dataid, $currentfield->name, $field->name);
-
- add_to_log($course->id, 'data', 'fields update', "fields.php?d=$data->id&mode=display&fid=$field->id", $field->id, $cm->id);
-
- $displayflag = get_string('fieldupdated','data');
- }
- else {
- $displayflag = get_string('invalidfieldname','data');
- }
- }
- break;
-
default:
break;
}
}
asort($menufield); //sort in alphabetical order
- notify ($displayflag); //print message, if any
+ notify($displaynotice); //print message, if any
- if (($mode == 'new') && confirm_sesskey() ){ //adding new field
+ if (($mode == 'new') && confirm_sesskey()) { /// Adding a new field
+ $field = data_get_field_new($newtype, $data);
+ $field->display_edit_field();
- require_once('field/'.$newtype.'/field.class.php');
- $f = 'data_field_'.$newtype;
- $g = new $f;
- $g->display_edit_field(0, $data->id);
- unset($f);
- unset($g);
- }
-
- else if ($mode != 'display'){ //display main form - add new, update, delete
+ } else if ($mode == 'display' && confirm_sesskey()) { /// Display/edit existing field
+ $field = data_get_field_from_id($fid, $data);
+ $field->display_edit_field();
+
+ } else { /// Display the main listing of all fields
- //echo '<form name="fieldform" action="fields.php?d='.$data->id.'&" method="POST">';
echo '<form name="fieldform" action="fields.php" method="post">';
echo '<input name="d" type="hidden" value="'.$data->id.'" />';
echo '<input type="hidden" name="mode" value="" />';
echo '<input name="sesskey" value="'.sesskey().'" type="hidden" />';
print_simple_box_start('center','50%');
- ///New fields
echo '<table width="100%"><tr>';
echo '<td>'.get_string('newfield','data').' ';
choose_from_menu($menufield,'fieldmenu','0','choose','fieldform.mode.value=\'new\';fieldform.submit();','0');
helpbutton('fields', get_string('addafield','data'), 'data');
echo '</td></tr>';
- /*******************************************
- * Print List of Fields in Quiz Style *
- *******************************************/
-
- if (!count_records('data_fields','dataid',$data->id)) {
+ if (!record_exists('data_fields','dataid',$data->id)) {
echo '<tr><td colspan="2">'.get_string('nofieldindatabase','data').'</td></tr>'; // nothing in database
- }
- else { //else print quiz style list of fields
-
+
+ } else { //else print quiz style list of fields
echo '<tr><td>';
print_simple_box_start('center','90%');
echo '<table width="100%"><tr><td align="center"><b>'.get_string('action','data').
'</b></td><td><b>'.get_string('fieldname','data').
'</b></td><td align="center"><b>'.get_string('type','data').'</b></td></tr>';
- if ($fields = get_records('data_fields','dataid',$data->id)){
- foreach ($fields as $field) {
+ if ($fff = get_records('data_fields','dataid',$data->id)){
+ foreach ($fff as $ff) {
+ $field = data_get_field($ff, $data);
///Print Action Column
echo '<tr><td align="center">';
- echo '<a href="fields.php?d='.$data->id.'&mode=display&fid='.$field->id.'&sesskey='.sesskey().'">';
+ echo '<a href="fields.php?d='.$data->id.'&mode=display&fid='.$field->field->id.'&sesskey='.sesskey().'">';
echo '<img src="'.$CFG->pixpath.'/t/edit.gif" height="11" width="11" border="0" alt="'.get_string('edit').'" /></a>';
echo ' ';
- echo '<a href="fields.php?d='.$data->id.'&mode=delete&fid='.$field->id.'&sesskey='.sesskey().'">';
+ echo '<a href="fields.php?d='.$data->id.'&mode=delete&fid='.$field->field->id.'&sesskey='.sesskey().'">';
echo '<img src="'.$CFG->pixpath.'/t/delete.gif" height="11" width="11" border="0" alt="'.get_string('delete').'" /></a>';
echo '</td>';
echo '<td>';
echo '<a href="fields.php?mode=display&d='.$data->id;
- echo '&fid='.$field->id.'&sesskey='.sesskey().'">'.$field->name.'</a>';
+ echo '&fid='.$field->field->id.'&sesskey='.sesskey().'">'.$field->field->name.'</a>';
echo '</td>';
///Print Type Column
echo '<td align="center">';
- $g = data_get_field($field);
- echo $g->image($data->id); //print type icon
+ echo $field->image(); //print type icon
echo '</td></tr>';
}
}
print_simple_box_end();
echo '</form>';
- } else { //display native update form
- $currentfield = get_record('data_fields','id',$fid);
- $g = data_get_field($currentfield);
- $g->display_edit_field($currentfield->id);
- unset($g);
}
/// Finish the page
print_footer($course);
-?>
\ No newline at end of file
+?>
}
///checking for participants
- if ((!isteacher($course->id)) && $data->participants ==PARTICIPANTS_T) {
+ if ((!isteacher($course->id)) && $data->participants == DATA_TEACHERS_ONLY) {
error ('students are not allowed to participate in this activity');
}
return $rows;
}
-?>
\ No newline at end of file
+?>
///////////////////////////////////////////////////////////////////////////
/// Some constants
-define ('PARTICIPANTS_T', 1);
-define ('PARTICIPANTS_S', 2);
-define ('PARTICIPANTS_TS', 3);
-define ('DATAMAXENTRIES', 50);
-define ('PERPAGE_SINGLE', 1);
+define ('DATA_TEACHERS_ONLY', 1);
+define ('DATA_STUDENTS_ONLY', 2);
+define ('DATA_TEACHERS_AND_STUDENTS', 3);
+define ('DATA_MAX_ENTRIES', 50);
+define ('DATA_PERPAGE_SINGLE', 1);
-class data_field_base { //base class (text field)
+class data_field_base { /// Base class for Database Field Types (see field/*/field.class.php)
- var $type = 'text'; /// Base class implements "text" field type completely.
- var $id; //field id
+ 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
- //constructor
- function data_field_base($fid=0){
- $this->id = $fid;
+ var $iconwidth = 16; /// Width of the icon for this fieldtype
+ var $iconheight = 16; /// Width of the icon for this fieldtype
+
+
+/// Constructor function
+ function data_field_base($field=0, $data=0) { // Field or data or both, each can be id or object
+
+ if (empty($field) && empty($data)) {
+ error('Programmer error: You must specify field and/or data when defining field class. ');
+ }
+
+ 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)) {
+ error('Bad field ID encountered: '.$field);
+ }
+ if (empty($data)) {
+ if (!$this->data = get_record('data','id',$this->field->dataid)) {
+ error('Bad data ID encountered in field data');
+ }
+ }
+ }
+
+ 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)) {
+ error('Bad data ID encountered: '.$data);
+ }
+ } else { // No way to define it!
+ error('Data id or object must be provided to field class');
+ }
+ }
+
+ if (empty($this->field)) { // We need to define some default values
+ $this->define_default_field();
+ }
}
+
- //returns the name/type of the field
- function name(){
- return get_string('name'.$this->type, 'data');
+/// This field just sets up a default field object
+ 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;
}
-
- //prints the respective type icon
- function image($dataid) {
- global $CFG;
- $str = '<a href="fields.php?d='.$dataid.'&fid='.$this->id.'&mode=display&sesskey='.sesskey().'">';
- $str .= '<img src="'.$CFG->modpixpath.'/data/field/'.$this->type.'/icon.gif" ';
- $str .= 'height="16" width="16" border="0" alt="'.$this->type.'" title="'.$this->type.'" /></a>';
- return $str;
+
+/// Set up the field object according to data in an object. Now is the time to clean it!
+ 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)) {
+ $this->field->param1 = trim($data->param2);
+ }
+ 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;
}
- function insert_field($dataid, $type='text', $name, $des='', $autolink=0){
- $newfield = new object;
- $newfield->dataid = $dataid;
- $newfield->type = $type;
- $newfield->name = $name;
- $newfield->description = $des;
- $newfield->param1 = $autolink;
- if (!insert_record('data_fields',$newfield)){
+/// Insert a new field in the database
+/// We assume the field object is already defined as $this->field
+ 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)){
notify('Insertion of new field failed!');
+ return false;
}
+ return true;
}
- /***********************************************
- * prints the form element in the add template *
- * eg: *
- * Your Name: [ ] *
- ***********************************************/
- function display_add_field($id, $rid=0){
- global $CFG;
- if (!$field = get_record('data_fields','id',$id)){
- notify("that is not a valid field id!");
- exit;
+
+/// Update a field in the database
+ function update_field() {
+ if (!update_record('data_fields', $this->field)) {
+ notify('updating of new field failed!');
+ return false;
}
+ return true;
+ }
- if ($rid){
- $content = get_record('data_content','fieldid',$id,'recordid',$rid);
- if (isset($content->content)){
- $content = $content->content;
- }
+/// Delete a field completely
+ function delete_field() {
+ if (!empty($this->field->id)) {
+ delete_records('data_fields', 'id', $this->field->id);
+ $this->delete_content();
}
- else {
+ return true;
+ }
+
+/// Print the relevant form element in the ADD template for this field
+ function display_add_field($recordid=0){
+ if ($recordid){
+ $content = get_field('data_content', 'content', 'fieldid', $this->field->id, 'recordid', $recordid);
+ } else {
$content = '';
}
- $str = '';
- /*
- if ($field->description){
- $str .= '<img src="'.$CFG->pixpath.'/help.gif" alt="'.$field->description.'" title="'.$field->description.'"> ';
- }
- */
- $str .= '<div title="'.$field->description.'">';
- $str .= '<input style="width:300px;" type="text" name="field_'.$field->id.'" id="field_'.$field->id.'" value="'.$content.'" />';
+ $str = '<div title="'.$this->field->description.'">';
+ $str .= '<input style="width:300px;" type="text" name="field_'.$this->field->id.'" id="field_'.$this->field->id.'" value="'.s($content).'" />';
$str .= '</div>';
+
return $str;
}
- /**********************************************************************
- * prints the field that defines the attributes for editting a field, *
- * only accessible by teachers *
- * eg. *
- * name of the picture: [ ] *
- * size [ ] *
- * width [ ] *
- **********************************************************************/
- function display_edit_field($id, $dataid=0){
- global $CFG, $course;
-
- $newfield = 0;
- if (!$field = get_record('data_fields','id',$id)){
- if ($dataid){ //if is a new field
- $field->dataid = $dataid;
- $newfield = 1;
- $field->id = 0;
- $field->param1 = '';
- $field->param2 = '';
- $field->param3 = '';
- $field->name = '';
- $field->description = '';
- }
- else {
- notify("that is not a valid field id!");
- exit;
- }
+/// Print the relevant form element to define the attributes for this field
+/// viewable by teachers only.
+ function display_edit_field() {
+ global $CFG;
+
+ if (empty($this->field)) { // No field has been defined yet, try and make one
+ $this->define_default_field();
}
print_simple_box_start('center','80%');
+
+ echo '<form name="editfield" action="'.$CFG->wwwroot.'/mod/data/fields.php" method="post">'."\n";
+ 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";
+
+ print_heading($this->name());
+
require_once($CFG->dirroot.'/mod/data/field/'.$this->type.'/mod.html');
+
+ echo '<div align="center">';
+ echo '<input type="submit" value="'.$savebutton.'" />'."\n";
+ echo '<input type="submit" value="'.get_string('cancel').'" '.
+ 'onclick="document.editfield.mode.value=\'void\';" />'."\n";
+ echo '</div">';
+
+ echo '</form>';
+
print_simple_box_end();
}
- /*********************************************************************
- * prints the browse mode content when viewed *
- * eg. *
- * [icon] Word.doc *
- **********************************************************************/
- function display_browse_field($fieldid, $recordid, $template){
- if ($content = get_record('data_content', 'fieldid', $fieldid, 'recordid', $recordid)){
+/// Display the content of the field in browse mode
+ function display_browse_field($recordid, $template) {
+ if ($content = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) {
if (isset($content->content)) {
$options->para = false;
$str = format_text($content->content, $content->content1, $options);
return false;
}
- /****************************
- * updates a field *
- ****************************/
- function update($fieldobject){
- //special thing is checking param1, if not present, set to 0
- $fieldobject->param1 = isset($fieldobject->param1)?$fieldobject->param1:0;
- if (!update_record('data_fields',$fieldobject)){
- notify ('upate failed');
- }
- }
-
- /************************************
- * store content of this field type *
- ************************************/
- function store_data_content($fieldid, $recordid, $value, $name=''){
+/// Update the content of one data field in the data_content table
+ function update_content($recordid, $value, $name=''){
$content = new object;
- $content->fieldid = $fieldid;
+ $content->fieldid = $this->field->id;
$content->recordid = $recordid;
$content->content = clean_param($value, PARAM_NOTAGS);
- insert_record('data_content', $content);
- }
-
- /*************************************
- * update content of this field type *
- *************************************/
- function update_data_content($fieldid, $recordid, $value, $name=''){
- //if data_content already exit, we update
- if ($oldcontent = get_record('data_content','fieldid', $fieldid, 'recordid', $recordid)){
- $content = new object;
- $content->fieldid = $fieldid;
- $content->recordid = $recordid;
- $content->content = clean_param($value, PARAM_NOTAGS);
+
+ if ($oldcontent = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) {
$content->id = $oldcontent->id;
- update_record('data_content',$content);
+ return update_record('data_content', $content);
+ } else {
+ return insert_record('data_content', $content);
}
- else { //make 1 if there isn't one already
- $this->store_data_content($fieldid, $recordid, $value, $name='');
+ }
+
+/// Delete all content associated with the field
+ function delete_content($recordid=0) {
+
+ $this->delete_content_files($recordid);
+
+ if ($recordid) {
+ return delete_records('data_content', 'fieldid', $this->field->id, 'recordid', $recordid);
+ } else {
+ return delete_records('data_content', 'fieldid', $this->field->id);
}
}
+
+/// Deletes any files associated with this field
+ 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);
+ }
- /*************************************************************
- * this function checks if a field from an add form is empty *
- * input $param string $value *
- * $param string $name *
- * output boolean *
- *************************************************************/
+
+/// Check if a field from an add form is empty
function notemptyfield($value, $name) {
return !empty($value);
}
- /*********************************************************************
- * This function deletes all data_contents associated with the field *
- *********************************************************************/
- function delete_data_contents() {
- return delete_records('data_content', 'fieldid', $this->id);
- }
-
- /*************************************************************************
- * This function checks if there's any file associated with this file, *
- * and is uploaded, if so, it deletes it. E.g file or picture type field *
- *************************************************************************/
- function delete_data_content_files($dataid, $recordid, $content) {
- //does nothing
+/// Just in case a field needs to print something before the whole form
+ function print_before_form() {
}
-
-
- /*************************************************************************
- * This function prints anything that the field wants to output after *
- * the html form. This is handy for the javascript rich text editor *
- *************************************************************************/
+
+/// Just in case a field needs to print something after the whole form
function print_after_form() {
- // Overridden as needed in sub classes.
}
- /* returns the sortable field for the content. By default, it's just content
- * but for some plugins, it could be content 1 - content4
- */
+/// Returns the sortable field for the content. By default, it's just content
+/// but for some plugins, it could be content 1 - content4
function get_sort_field() {
return 'content';
}
+
+/// Returns the name/type of the field
+ function name(){
+ return get_string('name'.$this->type, 'data');
+ }
-}//end of class data_field_base
+/// Prints the respective type icon
+ function image() {
+ global $CFG;
+
+ $str = '<a href="fields.php?d='.$this->data->id.'&fid='.$this->field->id.'&mode=display&sesskey='.sesskey().'">';
+ $str .= '<img src="'.$CFG->modpixpath.'/data/field/'.$this->type.'/icon.gif" ';
+ $str .= 'height="'.$this->iconheight.'" width="'.$this->iconwidth.'" border="0" alt="'.$this->type.'" title="'.$this->type.'" /></a>';
+ return $str;
+ }
+
+
+} //end of major class data_field_base
+
-///Field methods
/*****************************************************************************
/* Given a mode and a dataid, generate a default case template *
* input @param mode - addtemplate, singletemplate, listtempalte, rsstemplate*
$str .= '</td>';
$str .='<td valign="top">';
- $g = data_get_field($cfield);
+ $g = data_get_field($cfield, $currentdata);
$str .= $g->display_add_field($cfield->id,$rid);
$str .= '</td>';
$str .= '</tr>';
* form templates. Set $newfieldname as '' if you want to delete the *
* field from the form. *
***********************************************************************/
-function data_replace_field_in_forms($dataid, $searchfieldname, $newfieldname) {
- if (!$data = get_record('data', 'id', $dataid)) {
- // Form does not exist.
- return false;
- }
+function data_replace_field_in_templates($data, $searchfieldname, $newfieldname) {
if (!empty($newfieldname)) {
$prestring = '[[';
$poststring = ']]';
/********************************************************
* Appends a new field at the end of the form template. *
********************************************************/
-function data_append_field_in_form($dataid, $newfieldname) {
- if (!$data = get_record('data', 'id', $dataid)) {
- // Form does not exist.
- return false;
- }
+function data_append_new_field_to_templates($data, $newfieldname) {
+
+ $newdata->id = $data->id;
+
if (!empty($data->singletemplate)) {
- $data->singletemplate .= ' [[' . $newfieldname .']]';
+ $newdata->singletemplate = addslashes($data->singletemplate.' [[' . $newfieldname .']]');
+ }
+ if (!empty($data->addtemplate)) {
+ $newdata->addtemplate = addslashes($data->addtemplate.' [[' . $newfieldname . ']]');
}
if (!empty($data->rsstemplate)) {
- $data->rsstemplate .= ' [[' . $newfieldname . ']]';
+ $newdata->rsstemplate = addslashes($data->singletemplate.' [[' . $newfieldname . ']]');
}
- update_record('data', $data);
+ update_record('data', $newdata);
}
/************************************************************************
- * give a name in the format of field_## where ## is the field id, *
+ * 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 *
* this function creates an instance of the particular subfield class *
************************************************************************/
-function data_get_field_from_name($name){
- $namestring = explode('_',$name);
- $fieldid = $namestring[1];//the one after _ is the id.
+function data_get_field_from_id($fieldid, $data){
$field = get_record('data_fields','id',$fieldid);
- if ($field){
- return data_get_field($field);
+ if ($field) {
+ return data_get_field($field, $data);
} else {
return false;
}
}
+/************************************************************************
+ * 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;
+}
+
/************************************************************************
* returns a subclass field object given a record of the field, used to *
* invoke plugin methods *
* input: $param $field - record from db *
************************************************************************/
-function data_get_field($field){
- if ($field){
-
+function data_get_field($field, $data) {
+ global $CFG;
+
+ if ($field) {
require_once('field/'.$field->type.'/field.class.php');
$newfield = 'data_field_'.$field->type;
- $newfield = new $newfield($field->id);
+ $newfield = new $newfield($field, $data);
return $newfield;
}
}
* input @param int $dataid, $groupid *
* output bool *
****************************************************************/
-function data_add_record($dataid, $groupid=0){
- global $USER, $course;
+function data_add_record($data, $groupid=0){
+ global $USER;
+
$record->userid = $USER->id;
+ $record->dataid = $data->id;
$record->groupid = $groupid;
- $record->dataid = $dataid;
- $record->timecreated = time();
- $record->timemodified = time();
- if (isteacher($course->id)) {
+ $record->timecreated = $record->timemodified = time();
+ if (isteacher($data->course)) {
$record->approved = 1;
} else {
$record->approved = 0;
foreach($contents as $content){
$field = get_record('data_fields','id',$content->fieldid);
- if ($g = data_get_field($field)){
- $g->delete_data_content_files($id, $content->recordid, $content->content);
+ if ($g = data_get_field($field, $data)){
+ $g->delete_content_files($id, $content->recordid, $content->content);
}
//delete the content itself
delete_records('data_content','id', $content->id);
///then we generate strings to replace for normal tags
foreach ($possiblefields as $cfield) {
$patterns[]='/\[\['.$cfield->name.'\]\]/i';
- $g = data_get_field($cfield);
+ $g = data_get_field($cfield, $data);
$replacement[] = highlight($search, $g->display_browse_field($cfield->id, $record->id, $template));
unset($g);
}
return array('add','update','record delete');
}
+function data_fieldname_exists($name, $dataid, $fieldid=0) {
+ global $CFG;
+
+ if ($fieldid) {
+ return record_exists_sql('SELECT * from '.$CFG->prefix.'data_fields
+ WHERE name LIKE "'.$name.'" AND dataid = '.$dataid.'
+ AND ((id < '.$fieldid.') OR (id > '.$fieldid.'))');
+ } else {
+ return record_exists_sql('SELECT * from '.$CFG->prefix.'data_fields
+ WHERE name LIKE "'.$name.'" AND dataid = '.$dataid);
+ }
+}
+
+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;
+ }
+ }
+}
+
+
/*
INSERT INTO prefix_log_display VALUES ('data', 'view', 'data', 'name');
INSERT INTO prefix_log_display VALUES ('data', 'add', 'data', 'name');
INSERT INTO prefix_log_display VALUES ('data', 'templates saved', 'data', 'name');
INSERT INTO prefix_log_display VALUES ('data', 'templates def', 'data', 'name');
*/
-?>
\ No newline at end of file
+?>
$form->schedule = 0;
}
if (!isset($form->participants)) {
- $form->participants = PARTICIPANTS_TS;
+ $form->participants = DATA_TEACHERS_AND_STUDENTS;
}
if (!isset($form->requiredentries)) {
$form->requiredentries = 0;
<?php
$a->teachers = $course->teachers;
$a->students = $course->students;
- $options = array(PARTICIPANTS_T => $a->teachers,
- PARTICIPANTS_TS => get_string('teachersandstudents', 'data', $a));
+ $options = array(DATA_TEACHERS_ONLY => $a->teachers,
+ DATA_TEACHERS_AND_STUDENTS => get_string('teachersandstudents', 'data', $a));
choose_from_menu($options, 'participants', $form->participants, '');
helpbutton('participants', get_string('participants', 'data'), 'data');
?>
<td>
<?php
$countoptions = array();
- for($count=1;$count<=DATAMAXENTRIES;$count++) $countoptions[$count] = $count;
+ for($count=1;$count<=DATA_MAX_ENTRIES;$count++) $countoptions[$count] = $count;
choose_from_menu($countoptions, 'requiredentries', $form->requiredentries, get_string('none'));
helpbutton('requiredentries', get_string('requiredentries', 'data'), 'data');
?>
$row = array();
$row[] = new tabobject('browse', $CFG->wwwroot.'/mod/data/view.php?d='.$data->id, get_string('browse','data'), '', true);
- if (isteacher($course->id) or ($data->participants == PARTICIPANTS_S) or ($data->participants == PARTICIPANTS_TS)){
+ if (isteacher($course->id) or ($data->participants == DATA_STUDENTS_ONLY) or ($data->participants == DATA_TEACHERS_AND_STUDENTS)){
$row[] = new tabobject('add', $CFG->wwwroot.'/mod/data/add.php?d='.$data->id, get_string('add','data'), '', true);
}
if (isteacher($course->id)) {
print_tabs($tabs, $currenttab, $inactive);
-?>
\ No newline at end of file
+?>
foreach ($contents as $content){
$field = get_record('data_fields','id',$content->fieldid);
- if ($g = data_get_field($field)){ //it is possible that the field is deleted by teacher
- $g->delete_data_content_files($data->id, $delete, $content->content);
+ if ($g = data_get_field($field, $data)){ //it is possible that the field is deleted by teacher
+ $g->delete_content($data->id, $delete, $content->content);
}
}
delete_records('data_records','id',$delete);
}
if ($rid){ //set per page to 1, if looking for 1 specific record
- set_user_preference('data_perpage', PERPAGE_SINGLE);
+ set_user_preference('data_perpage', DATA_PERPAGE_SINGLE);
}
/*****************************
if ($sort) { //supports (sort and search)
//first find the field that we are sorting
- $sortfield = data_get_field(get_record('data_fields','id',$sort));
+ $sortfield = data_get_field_from_id($sort, $data);
$sortcontent = $sortfield->get_sort_field();
///SEARCH AND SORT SQL
$sql = 'SELECT DISTINCT c.recordid, c.recordid
}
$limit = $perpage > 1 ? sql_paging_limit($page * $perpage, $perpage)
- : $limit = sql_paging_limit($page, PERPAGE_SINGLE);
+ : $limit = sql_paging_limit($page, DATA_PERPAGE_SINGLE);
$sql = $sql . $limit;
print_footer($course);
-?>
\ No newline at end of file
+?>