Various cleanups

This commit is contained in:
moodler 2006-03-22 14:31:32 +00:00
parent 6c74c1da70
commit f0497d6ff0
3 changed files with 55 additions and 65 deletions

View file

@ -27,10 +27,11 @@
require_login(); require_login();
$mode ='addtemplate'; //define the mode for this page, only 1 mode available
$id = optional_param('id', 0, PARAM_INT); // course module id $id = optional_param('id', 0, PARAM_INT); // course module id
$d = optional_param('d', 0, PARAM_INT); // database id $d = optional_param('d', 0, PARAM_INT); // database id
$rid = optional_param('rid', 0, PARAM_INT); //record id $rid = optional_param('rid', 0, PARAM_INT); //record id
$import = optional_param('import', 0, PARAM_INT); // show import form
$mode ='addtemplate'; //define the mode for this page, only 1 mode available
if ($id) { if ($id) {
if (! $cm = get_record('course_modules', 'id', $id)) { if (! $cm = get_record('course_modules', 'id', $id)) {
@ -255,36 +256,40 @@
/// Upload records section. Only for teachers and the admin. /// Upload records section. Only for teachers and the admin.
if (isteacher($course->id)) { if (isteacher($course->id)) {
echo "\n\n"; if ($import) {
print_simple_box_start('center','80%'); print_simple_box_start('center','80%');
print_heading(get_string('uploadrecords', 'data'), '', 3); print_heading(get_string('uploadrecords', 'data'), '', 3);
$maxuploadsize = get_max_upload_file_size(); $maxuploadsize = get_max_upload_file_size();
echo '<div align="center">'; echo '<div align="center">';
echo '<form enctype="multipart/form-data" action="import.php" method="post">'; echo '<form enctype="multipart/form-data" action="import.php" method="post">';
echo '<input type="hidden" name="MAX_FILE_SIZE" value="'.$maxuploadsize.'">'; echo '<input type="hidden" name="MAX_FILE_SIZE" value="'.$maxuploadsize.'">';
echo '<input name="d" value="'.$data->id.'" type="hidden" />'; echo '<input name="d" value="'.$data->id.'" type="hidden" />';
echo '<input name="sesskey" value="'.sesskey().'" type="hidden" />'; echo '<input name="sesskey" value="'.sesskey().'" type="hidden" />';
echo '<table align="center" cellspacing="0" cellpadding="2" border="0">'; echo '<table align="center" cellspacing="0" cellpadding="2" border="0">';
echo '<tr>'; echo '<tr>';
echo '<td align="right">'.get_string('csvfile', 'data').'</td>'; echo '<td align="right">'.get_string('csvfile', 'data').':</td>';
echo '<td><input type="file" name="recordsfile" size="30">'; echo '<td><input type="file" name="recordsfile" size="30">';
helpbutton('', get_string('csvimporthelptitle', 'data'), 'data', true, false, helpbutton('importcvs', get_string('csvimport', 'data'), 'data', true, false);
get_string('csvimporthelptext', 'data'), false); echo '</td><tr>';
echo '</td><tr>'; echo '<td align="right">'.get_string('fielddelimiter', 'data').':</td>';
echo '<td align="right">'.get_string('fielddelimiter', 'data').'</td>'; echo '<td><input type="text" name="fielddelimiter" size="6">';
echo '<td><input type="text" name="fielddelimiter" size="6">'; echo get_string('defaultfielddelimiter', 'data').'</td>';
echo get_string('defaultfielddelimiter', 'data').'</td>'; echo '</tr>';
echo '</tr>'; echo '<td align="right">'.get_string('fieldenclosure', 'data').':</td>';
echo '<td align="right">'.get_string('fieldenclosure', 'data').'</td>'; echo '<td><input type="text" name="fieldenclosure" size="6">';
echo '<td><input type="text" name="fieldenclosure" size="6">'; echo get_string('defaultfieldenclosure', 'data').'</td>';
echo get_string('defaultfieldenclosure', 'data').'</td>'; echo '</tr>';
echo '</tr>'; echo '</table>';
echo '</table>'; echo '<input type="submit" value="'.get_string('uploadfile', 'data').'">';
echo '<input type="submit" value="'.get_string('uploadfile', 'data').'">'; echo '</form>';
echo '</form>'; echo '</div>';
echo '</div>'; print_simple_box_end();
print_simple_box_end(); } else {
echo '<div align="center">';
echo '<a href="add.php?d='.$data->id.'&amp;import=1">'.get_string('uploadrecords', 'data').'</a>';
echo '</div>';
}
} }

View file

@ -212,6 +212,7 @@ class data_field_base { /// Base class for Database Field Types (see field/*
/// Display the content of the field in browse mode /// Display the content of the field in browse mode
function display_browse_field($recordid, $template) { function display_browse_field($recordid, $template) {
if ($content = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) { if ($content = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) {
print_object($content);
if (isset($content->content)) { if (isset($content->content)) {
$options->para = false; $options->para = false;
$str = format_text($content->content, $content->content1, $options); $str = format_text($content->content, $content->content1, $options);

View file

@ -165,44 +165,28 @@
/*************************** /***************************
* code to delete a record * * code to delete a record *
***************************/ ***************************/
if (($delete = optional_param('delete',0,PARAM_INT)) && confirm_sesskey()){ if (($delete = optional_param('delete',0,PARAM_INT)) && confirm_sesskey()) {
if (isteacheredit($course) or data_isowner($delete)){ if (isteacheredit($course) or data_isowner($delete)){
if ($confirm = optional_param('confirm',0,PARAM_INT)){ if ($confirm = optional_param('confirm',0,PARAM_INT)) {
//find all contents in this record? if ($contents = get_records('data_content','recordid', $delete)) {
if ($contents = get_records('data_content','recordid',$delete)){ foreach ($contents as $content) { // Delete files or whatever else this field allows
if ($field = data_get_field_from_id($content->fieldid, $data)) { // Might not be there
//for each content, delete the file associated $field->delete_content($content->recordid);
foreach ($contents as $content){
$field = get_record('data_fields','id',$content->fieldid);
if ($g = data_get_field($field, $data)){ //it is possible that the field is deleted by teacher
$g->delete_content($data->id, $delete, $content->content);
} }
} }
delete_records('data_records','id',$delete);
delete_records('data_content','recordid',$delete);
add_to_log($course->id, 'data', 'record delete', "view.php?id=$cm->id", $data->id, $cm->id);
notify (get_string('recorddeleted','data'));
} }
} delete_records('data_content','recordid',$delete);
else { //prints annoying confirmation dialogue delete_records('data_records','id',$delete);
$field = get_record('data_records','id',$delete);
print_simple_box_start('center', '60%'); add_to_log($course->id, 'data', 'record delete', "view.php?id=$cm->id", $data->id, $cm->id);
echo '<div align="center">';
echo '<form action = "view.php?d='.$data->id.'&amp;delete='.$delete.'" method="post">'; notify(get_string('recorddeleted','data'));
//add sesskey
echo get_string('confirmdeleterecord','data'); } else { // Print a confirmation page
echo '<p />'; notice_yesno(get_string('confirmdeleterecord','data'),
echo '<input type="hidden" value="'.sesskey().'" name="sesskey">'; 'view.php?d='.$data->id.'&amp;delete='.$delete.'&amp;confirm=1&amp;sesskey='.sesskey(),
echo '<input type="submit" value="'.get_string('ok').'"> '; 'view.php?d='.$data->id);
echo '<input type="hidden" name="confirm" value="1">';
echo '<input type="button" value="'.get_string('cancel').'" onclick="javascript:history.go(-1);" />';
echo '</form>';
echo '</div>';
print_simple_box_end();
echo '</td></tr></table>';
print_footer($course); print_footer($course);
exit; exit;
} }