]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-18542:
authorthepurpleblob <thepurpleblob>
Tue, 24 Mar 2009 10:52:50 +0000 (10:52 +0000)
committerthepurpleblob <thepurpleblob>
Tue, 24 Mar 2009 10:52:50 +0000 (10:52 +0000)
Reverting various checkins related to this bug.
PLUS... proper 1 line fix included (merged from STABLE19)

mod/data/edit.php
mod/data/field/checkbox/field.class.php
mod/data/field/date/field.class.php
mod/data/field/file/field.class.php
mod/data/field/latlong/field.class.php
mod/data/field/textarea/field.class.php
mod/data/lib.php

index d7646a167682b28f21a001c6afaca57b0591c338..84609ff288ba76a23c0b3f84d1b95231192784ff 100755 (executable)
@@ -31,7 +31,6 @@
     $rid   = optional_param('rid', 0, PARAM_INT);    //record id
     $import   = optional_param('import', 0, PARAM_INT);    // show import form
     $cancel   = optional_param('cancel', '');    // cancel an add
-    $fieldids = optional_param('fieldids',''); // ids of fields being edited
     $mode ='addtemplate';    //define the mode for this page, only 1 mode available
 
     if ($id) {
     }
     include('tabs.php');
 
+
 /// Process incoming data for adding/updating records
 
     if ($datarecord = data_submitted() and confirm_sesskey()) {
 
+        $ignorenames = array('MAX_FILE_SIZE','sesskey','d','rid','saveandview','cancel');  // strings to be ignored in input data
+
+        $ignorenames = array('MAX_FILE_SIZE','sesskey','d','rid','saveandview','cancel');  // strings to be ignored in input data
+
+        $ignorenames = array('MAX_FILE_SIZE','sesskey','d','rid','saveandview','cancel');  // strings to be ignored in input data
+
         if ($rid) {                                          /// Update some records
 
             /// All student edits are marked unapproved by default
 
             /// Update all content
             $field = NULL;
-            foreach ($fieldids as $fieldid) {
-                $bits = explode('_',$fieldid);
-                $justid = $bits[0];
-                $name = "field_$fieldid";
-                $value = optional_param( $name,'' );
-                if (empty($field->field) || ($justid != $field->field->id)) {  // Try to reuse classes
-                    $field = data_get_field_from_id($fieldid, $data);
-                }
-                if ($field) {
-                    $field->update_content($rid, $value, $name);
+            foreach ($datarecord as $name => $value) {
+                if (!in_array($name, $ignorenames)) {
+                    $namearr = explode('_',$name);  // Second one is the field id
+                    if (empty($field->field) || ($namearr[1] != $field->field->id)) {  // Try to reuse classes
+                        $field = data_get_field_from_id($namearr[1], $data);
+                    }
+                    if ($field) {
+                        $field->update_content($rid, $value, $name);
+                    }
                 }
             }
 
 
             $emptyform = true;      // assume the worst
 
-            foreach ($fieldids as $fieldid) {
-                $bits = explode('_',$fieldid);
-                $justid = $bits[0];
-                $name = "field_$fieldid";
-                $value = optional_param( $name,'' );
-                if (empty($field->field) || ($justid != $field->field->id)) {  // Try to reuse classes
-                    $field = data_get_field_from_id($fieldid, $data);
-                }
-                if ($field->notemptyfield($value, $name)) {
-                    $emptyform = false;
-                    break;             // if anything has content, this form is not empty, so stop now!
+            foreach ($datarecord as $name => $value) {
+                if (!in_array($name, $ignorenames)) {
+                    $namearr = explode('_', $name);  // Second one is the field id
+                    if (empty($field->field) || ($namearr[1] != $field->field->id)) {  // Try to reuse classes
+                        $field = data_get_field_from_id($namearr[1], $data);
+                    }
+                    if ($field->notemptyfield($value, $name)) {
+                        $emptyform = false;
+                        break;             // if anything has content, this form is not empty, so stop now!
+                    }
                 }
             }
+
             if ($emptyform){    //nothing gets written to database
                 notify(get_string('emptyaddform','data'));
             }
                 }
 
                 //for each field in the add form, add it to the data_content.
-                foreach ($fieldids as $fieldid) {
-                    $bits = explode('_',$fieldid);
-                    $justid = $bits[0];
-                    $name = "field_$fieldid";
-                    $value = optional_param( $name,'' );
-                    if (empty($field->field) || ($justid != $field->field->id)) {  // Try to reuse classes
-                        $field = data_get_field_from_id($fieldid, $data);
-                    }
-                    if ($field) {
-                        $field->update_content($recordid, $value, $name);
+                foreach ($datarecord as $name => $value){
+                    if (!in_array($name, $ignorenames)) {
+                        $namearr = explode('_', $name);  // Second one is the field id
+                        if (empty($field->field) || ($namearr[1] != $field->field->id)) {  // Try to reuse classes
+                            $field = data_get_field_from_id($namearr[1], $data);
+                        }
+                        if ($field) {
+                            $field->update_content($recordid, $value, $name);
+                        }
                     }
-                }  
+                }
+
                 add_to_log($course->id, 'data', 'add', "view.php?d=$data->id&amp;rid=$recordid", $data->id, $cm->id);
 
                 notify(get_string('entrysaved','data'));
         }
     }  // End of form processing
 
-
-
     /// Print the browsing interface
 
     $patterns = array();    //tags to replace
     if ($data->addtemplate){
         $possiblefields = $DB->get_records('data_fields', array('dataid'=>$data->id), 'id');
 
-        // keep a record of the fields used on the form
-        $data->fieldids = array();
-
         ///then we generate strings to replace
         foreach ($possiblefields as $eachfield){
             $field = data_get_field($eachfield, $data);
             $replacements[] = $field->display_add_field($rid);
             $patterns[]="[[".$field->field->name."#id]]";
             $replacements[] = 'field_'.$field->field->id;
-            $field->list_add_field( $data->fieldids );
         }
         $newtext = str_ireplace($patterns, $replacements, $data->{$mode});
 
     }
     echo '</div>';
     print_simple_box_end();
-
-    // add list of fields to form (MDL-18542)
-    foreach ($data->fieldids as $fieldid) {
-        echo "<input type=\"hidden\" name=\"fieldids[]\" value=\"$fieldid\" />\n";
-    }
-
     echo '</div></form>';
 
 
             helpbutton('importcsv', get_string('csvimport', 'data'), 'data', true, false);
             echo '</td><tr>';
             echo '<td align="right">'.get_string('fielddelimiter', 'data').':</td>';
-            echo '<td><input type="text" name="fielddelimiter" size="6" value=","/>';
+            echo '<td><input type="text" name="fielddelimiter" size="6" />';
             echo get_string('defaultfielddelimiter', 'data').'</td>';
             echo '</tr>';
             echo '<td align="right">'.get_string('fieldenclosure', 'data').':</td>';
index fb49d84584c9f58d88f6c4d75e2951cdfc223a33..a58fa80f2f77372e0ab933799e40c0ee553e5f83 100755 (executable)
@@ -45,6 +45,7 @@ class data_field_checkbox extends data_field_base {
             if ($checkbox === '') {
                 continue; // skip empty lines
             }
+            $str .= '<input type="hidden" name="field_' . $this->field->id . '[]" value="" />';
             $str .= '<input type="checkbox" id="field_'.$this->field->id.'_'.$i.'" name="field_' . $this->field->id . '[]" ';
             $str .= 'value="' . s($checkbox) . '" ';
 
index c90b2d4a75b5986de24dbad9da521569074d7a73..6d7297cd1193c45c50791cf90a42c84766c684e6 100755 (executable)
@@ -50,14 +50,7 @@ class data_field_date extends data_field_base {
 
         return $str;
     }
-
-    function list_add_field(&$fields) {
-        $fields[] = $this->field->id.'_day';
-        $fields[] = $this->field->id.'_month';
-        $fields[] = $this->field->id.'_year';
-        return true;
-    }
-
+    
     //Enable the following three functions once core API issues have been addressed.
     function display_search_field($value=0) {
         return false;
@@ -89,9 +82,11 @@ class data_field_date extends data_field_base {
 
         $names = explode('_',$name);
         $name = $names[2];          // day month or year
+
         $this->$name = $value;
 
         if ($this->day and $this->month and $this->year) {  // All of them have been collected now
+
             $content = new object;
             $content->fieldid = $this->field->id;
             $content->recordid = $recordid;
index 8711872d0a3c00732e402bb4c14430163cd61777..bb58c0c79914255b67e9af5ad2d26147cc72177f 100755 (executable)
@@ -67,12 +67,6 @@ class data_field_file extends data_field_base {
         return $str;
     }
 
-    function list_add_field(&$fields) {
-        $fields[] = $this->field->id.'_filename';
-        $fields[] = $this->field->id.'_file';
-        return true;
-    } 
-
     function display_search_field($value = '') {
         return '<input type="text" size="16" name="f_'.$this->field->id.'" value="'.$value.'" />';
     }
index 81c047c5f8d68557e93227cd2e001bf07b536e30..87ed62a7d40d1f27c3689ebaddc830e1a43f6068 100755 (executable)
@@ -65,12 +65,6 @@ class data_field_latlong extends data_field_base {
         return $str;
     }
 
-    function list_add_field( &$fields ) {
-        $fields[] = $this->field->id.'_0';
-        $fields[] = $this->field->id.'_1';
-        return true;
-    }
-
     function display_search_field($value = '') {
         global $CFG, $DB;
         $lats = $DB->get_records_sql_menu('SELECT id, content FROM {data_content} WHERE fieldid=? GROUP BY content ORDER BY content', array($this->field->id));
index dbd10c9f409e8dc6c3e55b4d92ed07daa25da9df..a2a11d6a7315ba2edcf36e784cdcfb8d7a5b86cc 100755 (executable)
@@ -63,12 +63,6 @@ class data_field_textarea extends data_field_base {
         $str .= '</div>';
         return $str;
     }
-
-    function list_add_field(&$fields) {
-        $fields[] = $this->field->id;
-        $fields[] = $this->field->id.'_content1';
-        return true; 
-    }
     
     
     function display_search_field($value = '') {
index c875b8c9f5dc6a7ed3b05f7228be57d8e1d38c04..eb7835e78993adf37e188e056e5e98c187ce6f4c 100755 (executable)
@@ -193,11 +193,6 @@ class data_field_base {     // Base class for Database Field Types (see field/*/
             $content = '';
         }
 
-        // beware get_field returns false for new, empty records MDL-18567
-        if ($content===false) {
-            $content='';
-        }
-
         $str = '<div title="'.s($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>';
@@ -205,14 +200,6 @@ class data_field_base {     // Base class for Database Field Types (see field/*/
         return $str;
     }
 
-
-// add the field ids to an existing array to track added form fields
-// override if anything with multiple fields (e.g. date)
-    function list_add_field( &$fields ) {
-        $fields[] = $this->field->id;
-        return true;
-    }
-
 // Print the relevant form element to define the attributes for this field
 // viewable by teachers only.
     function display_edit_field() {
@@ -384,11 +371,6 @@ function data_generate_default_template(&$data, $template, $recordid=0, $form=fa
         return '';
     }
 
-    // store generated field ids (if form)
-    if ($form) {
-        $data->fieldids = array();
-    }
-
     // get all the fields for that database
     if ($fields = $DB->get_records('data_fields', array('dataid'=>$data->id), 'id')) {
 
@@ -415,7 +397,7 @@ function data_generate_default_template(&$data, $template, $recordid=0, $form=fa
             if ($form) {   // Print forms instead of data
                 $fieldobj = data_get_field($field, $data);
                 $str .= $fieldobj->display_add_field($recordid);
-                $fieldobj->list_add_field( $data->fieldids );
+
             } else {           // Just print the tag
                 $str .= '[['.$field->name.']]';
             }