diff --git a/mod/data/edit.php b/mod/data/edit.php index 65ac035d8d4..215f9a3508b 100755 --- a/mod/data/edit.php +++ b/mod/data/edit.php @@ -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) { @@ -139,10 +138,13 @@ } include('tabs.php'); + /// Process incoming data for adding/updating records if ($datarecord = data_submitted($CFG->wwwroot.'/mod/data/edit.php') and confirm_sesskey()) { + $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 @@ -159,16 +161,15 @@ /// 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); + } } } @@ -195,19 +196,19 @@ $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')); } @@ -223,18 +224,18 @@ } //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); + 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); + } } - if ($field) { - $field->update_content($recordid, $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')); @@ -246,8 +247,6 @@ } } // End of form processing - - /// Print the browsing interface $patterns = array(); //tags to replace @@ -271,9 +270,6 @@ if ($data->addtemplate){ $possiblefields = get_records('data_fields','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); @@ -281,7 +277,6 @@ $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}); @@ -299,12 +294,6 @@ } echo ''; print_simple_box_end(); - - // add list of fields to form (MDL-18542) - foreach ($data->fieldids as $fieldid) { - echo "\n"; - } - echo ''; @@ -328,7 +317,7 @@ helpbutton('importcsv', get_string('csvimport', 'data'), 'data', true, false); echo '