$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&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>';
$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>';
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() {
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')) {
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.']]';
}