From 0997e51afed2e36f6e5d5e707c560ec5b6368019 Mon Sep 17 00:00:00 2001 From: moodler Date: Wed, 22 Mar 2006 08:07:26 +0000 Subject: [PATCH] Lots and lots and lots of cleanup for the data module code, mostly to do with how the field classes worked. Now it should be even easier for developers. No changes for users. :-P The changes are not well tested yet! --- mod/data/add.php | 130 +++--- mod/data/field/checkbox/field.class.php | 141 ++---- mod/data/field/checkbox/mod.html | 24 +- mod/data/field/file/field.class.php | 265 +++-------- mod/data/field/file/mod.html | 22 +- mod/data/field/menu/field.class.php | 84 +--- mod/data/field/menu/mod.html | 24 +- mod/data/field/multimenu/field.class.php | 129 ++---- mod/data/field/multimenu/mod.html | 24 +- mod/data/field/picture/field.class.php | 143 ++---- mod/data/field/picture/mod.html | 32 +- mod/data/field/radiobutton/field.class.php | 80 +--- mod/data/field/radiobutton/mod.html | 24 +- mod/data/field/text/field.class.php | 12 +- mod/data/field/text/mod.html | 24 +- mod/data/field/textarea/field.class.php | 172 ++----- mod/data/field/textarea/mod.html | 26 +- mod/data/field/url/field.class.php | 150 ++---- mod/data/field/url/mod.html | 22 +- mod/data/fields.php | 210 ++++----- mod/data/import.php | 4 +- mod/data/lib.php | 505 +++++++++++++-------- mod/data/mod.html | 8 +- mod/data/tabs.php | 4 +- mod/data/view.php | 12 +- 25 files changed, 828 insertions(+), 1443 deletions(-) diff --git a/mod/data/add.php b/mod/data/add.php index e5df9525ec6..470fe8b2424 100755 --- a/mod/data/add.php +++ b/mod/data/add.php @@ -56,14 +56,14 @@ } 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? @@ -83,6 +83,7 @@ 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 { @@ -109,27 +110,34 @@ ********************************************/ $entrysaved = false; //flag for displaying entry saved msg - if ($datarecord = data_submitted($CFG->wwwroot.'/mod/data/add.php') and confirm_sesskey()) { - //if rid is present, we are in updating mode - if ($rid){ + $ignorenames = array('MAX_FILE_SIZE','sesskey','d','rid'); // strings to be ignored in input data - //set flag to unapproved after each edit + if ($datarecord = data_submitted($CFG->wwwroot.'/mod/data/add.php') and confirm_sesskey()) { + + 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); } } } @@ -138,63 +146,59 @@ 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 && $recordid = data_add_record($data->id, $currentgroup)){ //add instance to data_record - $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; - 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); - } - } - $entrysaved = true; - } - if ($emptyform){ //nothing gets written to database notify(get_string('emptyaddform','data')); } - - if ($entrysaved) { + + 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); + foreach ($fields as $field) { + $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 (!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); + } + } + } + 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 '

'; - } - + } // 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! =) @@ -227,10 +231,10 @@ $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); } diff --git a/mod/data/field/checkbox/field.class.php b/mod/data/field/checkbox/field.class.php index 9f87baab9eb..81f8f76a01d 100755 --- a/mod/data/field/checkbox/field.class.php +++ b/mod/data/field/checkbox/field.class.php @@ -1,4 +1,4 @@ -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; - } + $content = array(); - - if ($rid) { - $dbcontent = get_record('data_content', 'fieldid', $id, 'recordid', $rid); - if (isset($dbcontent->content)) { - $content = $content->content; - $content = explode('##', $content); - } + + if ($recordid) { + $content = get_field('data_content', 'content', 'fieldid', $this->field->id, 'recordid', $recordid); + $content = explode('##', $content); } - $str = ''; - /* - if ($field->description) { - $str .= ''.$field->description.' '; - } - */ - $str .= '

'; + + $str = '
'; foreach (explode("\n", $field->param1) as $checkbox) { $checkbox = ltrim(rtrim($checkbox)); @@ -84,10 +49,8 @@ class data_field_checkbox extends data_field_base { $str .= 'value="' . $checkbox . '" '; if (array_search($checkbox, $content) !== false) { - // Selected by user. $str .= 'checked />'; - } - else { + } else { $str .= '/>'; } $str .= $checkbox . '
'; @@ -96,46 +59,36 @@ class data_field_checkbox extends data_field_base { 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); + return update_record('data_content', $content); + } else { + return insert_record('data_content', $content); } } - + function display_browse_field($recordid, $template) { + + if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)){ + $contentArr = array(); + if (!empty($content->content)) { + $contentArr = explode('##', $content->content); + } + $str = ''; + foreach ($contentArr as $line) { + $str .= $line . "
\n"; + } + return $str; + } + return false; + } + function format_data_field_checkbox_content($content) { if (!is_array($content)) { $str = $content; @@ -149,25 +102,5 @@ class data_field_checkbox extends data_field_base { $str = clean_param($str, PARAM_NOTAGS); return $str; } - - - function display_browse_field($fieldid, $recordid, $template) { - global $CFG, $USER, $course; - - $field = get_record('data_fields', 'id', $fieldid); - - if ($content = get_record('data_content', 'fieldid', $fieldid, 'recordid', $recordid)){ - $contentArr = array(); - if (!empty($content->content)) { - $contentArr = explode('##', $content->content); - } - $str = ''; - foreach ($contentArr as $line) { - $str .= $line . "
\n"; - } - return $str; - } - return false; - } } -?> \ No newline at end of file +?> diff --git a/mod/data/field/checkbox/mod.html b/mod/data/field/checkbox/mod.html index 0b73e09a783..bdd691cb3fe 100755 --- a/mod/data/field/checkbox/mod.html +++ b/mod/data/field/checkbox/mod.html @@ -1,32 +1,14 @@ -
- - - - + - + - - - - - +
- - - - - name()); ?> -
:
:
:
  - - -
-
diff --git a/mod/data/field/file/field.class.php b/mod/data/field/file/field.class.php index df07fb00201..61f7bb3ecd0 100755 --- a/mod/data/field/file/field.class.php +++ b/mod/data/field/file/field.class.php @@ -1,4 +1,4 @@ -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; - } + function display_add_field($recordid=0) { + global $CFG; - 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)) { + $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 .= ''.$field->description.' '; - } - */ - $str .= '
'; - $str .= ''; - $str .= get_string('file','data'). ':
'; + + $str = '
'; + $str .= ''; + $str .= get_string('file','data'). ':
'; $str .= get_string('optionalfilename','data').':
'; - $str .= ''; + .$this->field->id.'_1" id="field_'.$this->field->id.'_1" value="'.$displayname.'" />
'; + $str .= ''; $str .= '
'; - //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 .= ''.$icon.' '. @@ -114,33 +78,27 @@ class data_field_file extends data_field_base {// extends return $str; } - function display_edit_field($id, $mode=0){ - parent::display_edit_field($id, $mode); - } + function display_browse_field($recordid, $template) { - function display_browse_field($fieldid, $recordid, $template) { + global $CFG; - global $CFG, $USER; - - $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]; - - - if ($CFG->slasharguments) { - $source = $CFG->wwwroot.'/file.php/'.$data->course.'/'.$CFG->moddata.'/data/'.$field->dataid.'/'.$field->id.'/'.$recordid; - } else { - $source = $CFG->wwwroot.'/file.php?file=/'.$data->course.'/'.$CFG->moddata.'/data/'.$field->dataid.'/'.$field->id.'/'.$recordid; - } - $width = $field->param1 ? ' width = "'.$field->param1.'" ':' '; - $height = $field->param2 ? ' height = "'.$field->param2.'" ':' '; + $path = $this->data->course.'/'.$CFG->moddata.'/data/'.$this->data->id.'/'.$this->field->id.'/'.$recordid; + + if ($CFG->slasharguments) { + $source = $CFG->wwwroot.'/file.php/'.$path; + } else { + $source = $CFG->wwwroot.'/file.php?file=/'.$path; + } + + $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); @@ -152,95 +110,51 @@ class data_field_file extends data_field_base {// extends } - 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; + $dir = $course->id.'/'.$CFG->moddata.'/data/'.$this->data->id.'/'.$this->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); + //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); } } @@ -253,35 +167,6 @@ class data_field_file extends data_field_base {// extends 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')); - } - } ?> diff --git a/mod/data/field/file/mod.html b/mod/data/field/file/mod.html index c116003fcfe..d4b51d5a213 100755 --- a/mod/data/field/file/mod.html +++ b/mod/data/field/file/mod.html @@ -1,33 +1,15 @@ -
- - - - - -
- name()); ?> -
: - +
- : + :
- - - - - - -
-
- diff --git a/mod/data/field/menu/field.class.php b/mod/data/field/menu/field.class.php index 2c739a3a763..709718ac4e4 100755 --- a/mod/data/field/menu/field.class.php +++ b/mod/data/field/menu/field.class.php @@ -1,4 +1,4 @@ -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) { + + if ($recordid){ + $content = get_field('data_content', 'content', 'fieldid', $this->field->id, 'recordid', $recordid); + $content = trim($content); + } else { + $content = ''; } - $str = '
'; - /* - if ($field->description) { - $str .= ''.$field->description.' '; - } - */ + $str = '
'; $str .= get_string('menu','data').': '; - - $str .= '
'; + + $str .= choose_from_menu($options, 'field_'.$this->field->id, $content, + get_string('menuchoose', 'data'), '', '', true, false); + + $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'); - } - } } ?> diff --git a/mod/data/field/menu/mod.html b/mod/data/field/menu/mod.html index bbca8b2bc23..c29f4264c09 100755 --- a/mod/data/field/menu/mod.html +++ b/mod/data/field/menu/mod.html @@ -1,32 +1,14 @@ -
- - - - + - + - - - - - +
- - - - - name()); ?> -
:
:
:
  - - -
-
diff --git a/mod/data/field/multimenu/field.class.php b/mod/data/field/multimenu/field.class.php index df776d3ae7e..328f2dc00e2 100755 --- a/mod/data/field/multimenu/field.class.php +++ b/mod/data/field/multimenu/field.class.php @@ -1,4 +1,4 @@ -dataid = $dataid; - $newfield->type = $type; - $newfield->name = $name; - $newfield->description = $desc; - $newfield->param1 = $options; + if ($recordid){ + $content = get_field('data_content', 'content', 'fieldid', $this->field->id, 'recordid', $recordid); + $content = explode('##', $content); + } else { + $content = array(); + } + + $str = '
'; + $str .= ''; - - foreach (explode("\n",$field->param1) as $option) { - $option = ltrim(rtrim($option)); + foreach (explode("\n",$this->field->param1) as $option) { + $option = trim($option); $str .= '