course)) { error('Course is misconfigured'); } if (! $data = get_record('data', 'id', $cm->instance)) { error('Course module is incorrect'); } } else { if (! $data = get_record('data', 'id', $d)) { error('Data ID is incorrect'); } if (! $course = get_record('course', 'id', $data->course)) { error('Course is misconfigured'); } if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) { error('Course Module ID was incorrect'); } } if (!isteacheredit($course->id)){ error(get_string('noaccess','data')); } $strdata = get_string('modulenameplural','data'); print_header_simple($data->name, '', "$strdata -> $data->name", '', '', true, '', navmenu($course, $cm)); print_heading(format_string($data->name)); /************************************ * Data Processing * ***********************************/ switch ($mode){ case 'add': ///add a new field if (confirm_sesskey() and $fieldinput = data_submitted($CFG->wwwroot.'/mod/data/fields.php')){ /// Only store this new field if it doesn't already exist. if (data_fieldname_exists($fieldinput->name, $data->id)) { $displaynotice = get_string('invalidfieldname','data'); } else { /// Check for arrays and convert to a comma-delimited string data_convert_arrays_to_strings($fieldinput); /// Create a field object to collect and store the data safely $type = required_param('type', PARAM_FILE); $field = data_get_field_new($type, $data); $field->define_field($fieldinput); $field->insert_field(); /// Update some templates data_append_new_field_to_templates($data, $field->field->name); add_to_log($course->id, 'data', 'fields add', "fields.php?d=$data->id&mode=display&fid=$fid", $fid, $cm->id); $displaynotice = get_string('fieldadded','data'); } } break; case 'update': ///update a field if (confirm_sesskey() and $fieldinput = data_submitted($CFG->wwwroot.'/mod/data/fields.php')){ $fieldinput->name = optional_param('name','',PARAM_NOTAGS); if (data_fieldname_exists($fieldinput->name, $data->id, $fid)) { $displaynotice = get_string('invalidfieldname','data'); } else { /// Check for arrays and convert to a comma-delimited string data_convert_arrays_to_strings($fieldinput); /// Create a field object to collect and store the data safely $field = data_get_field_from_id($fid, $data); $oldfieldname = $field->field->name; $field->update_field($fieldinput); /// Update the templates. data_replace_field_in_templates($data, $oldfieldname, $field->field->name); add_to_log($course->id, 'data', 'fields update', "fields.php?d=$data->id&mode=display&fid=$fid", $fid, $cm->id); $displaynotice = get_string('fieldupdated','data'); } } break; case 'delete': // Delete a field if (confirm_sesskey()){ if ($confirm = optional_param('confirm', 0, PARAM_INT)) { // Delete the field completely $field = data_get_field_from_id($fid, $data); $field->delete_field(); // Update the templates. data_replace_field_in_templates($data, $field->field->name, ''); add_to_log($course->id, 'data', 'fields delete', "fields.php?d=$data->id", $field->field->name, $cm->id); $displaynotice = get_string('fielddeleted', 'data'); } else { // Print confirmation message. $field = data_get_field_from_id($fid, $data); print_simple_box_start('center', '60%'); echo '
| '.get_string('action','data'). ' | '.get_string('fieldname','data'). ' | '.get_string('type','data').' |
| ';
echo '';
echo ' | ';
/// Print Fieldname Column
echo ''; echo ''.$field->field->name.''; echo ' | '; /// Print Type Column echo ''; echo $field->image(); //print type icon echo ' |