Reverting changes in MDL-18542 (some more to do in fields, but this should

un-break it). Checkbox error still extant.
This commit is contained in:
thepurpleblob
2009-03-23 21:22:52 +00:00
parent 654e003982
commit 0791d2fbb5
5 changed files with 42 additions and 87 deletions
+35 -46
View File
@@ -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 '</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>';
@@ -328,7 +317,7 @@
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>';
+4 -8
View File
@@ -53,14 +53,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;
@@ -88,11 +81,14 @@ class data_field_date extends data_field_base {
}
function update_content($recordid, $value, $name='') {
$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;
-6
View File
@@ -70,12 +70,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.'" />';
}
-6
View File
@@ -68,12 +68,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;
$lats = get_records_sql_menu('SELECT id, content from '.$CFG->prefix.'data_content WHERE fieldid='.$this->field->id.' GROUP BY content ORDER BY content');
+3 -21
View File
@@ -166,11 +166,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>';
@@ -178,14 +173,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() {
@@ -355,11 +342,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 = get_records('data_fields', 'dataid', $data->id, 'id')) {
@@ -386,7 +368,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.']]';
}
@@ -1336,7 +1318,7 @@ function data_print_comments($data, $record, $page=0, $mform=false) {
$editor = optional_param('addcomment', 0, PARAM_BOOL);
if (!$mform and !$editor) {
echo '<div class="newcomment" style="text-align:center">';
echo '<a href="view.php?d='.$data->id.'&amp;rid='.$record->id.'&amp;mode=single&amp;addcomment=1">'.get_string('addcomment', 'data').'</a>';
echo '<a href="view.php?d='.$data->id.'&amp;page='.$page.'&amp;mode=single&amp;addcomment=1">'.get_string('addcomment', 'data').'</a>';
echo '</div>';
} else {
if (!$mform) {
@@ -1853,7 +1835,7 @@ class PresetImporter {
} else if (empty($newfields)) {
error("New preset has no defined fields!");
}
echo '<div class="overwritesettings"><label for="overwritesettings">'.get_string('overwritesettings', 'data');
echo '<div class="overwritesettings"><label for="overwritesettings">'.get_string('overwritesettings', 'data').'</label>';
echo '<input id="overwritesettings" name="overwritesettings" type="checkbox" /></label></div>';
echo '<input class="button" type="submit" value="'.$strcontinue.'" /></div></form></div>';
}