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();
$mode ='addtemplate'; //define the mode for this page, only 1 mode available
$id = optional_param('id', 0, PARAM_INT); // course module id
$d = optional_param('d', 0, PARAM_INT); // database 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 (! $cm = get_record('course_modules', 'id', $id)) {
@ -255,36 +256,40 @@
/// Upload records section. Only for teachers and the admin.
if (isteacher($course->id)) {
echo "\n\n";
print_simple_box_start('center','80%');
print_heading(get_string('uploadrecords', 'data'), '', 3);
$maxuploadsize = get_max_upload_file_size();
echo '<div align="center">';
echo '<form enctype="multipart/form-data" action="import.php" method="post">';
echo '<input type="hidden" name="MAX_FILE_SIZE" value="'.$maxuploadsize.'">';
echo '<input name="d" value="'.$data->id.'" type="hidden" />';
echo '<input name="sesskey" value="'.sesskey().'" type="hidden" />';
echo '<table align="center" cellspacing="0" cellpadding="2" border="0">';
echo '<tr>';
echo '<td align="right">'.get_string('csvfile', 'data').'</td>';
echo '<td><input type="file" name="recordsfile" size="30">';
helpbutton('', get_string('csvimporthelptitle', 'data'), 'data', true, false,
get_string('csvimporthelptext', 'data'), false);
echo '</td><tr>';
echo '<td align="right">'.get_string('fielddelimiter', 'data').'</td>';
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>';
echo '<td><input type="text" name="fieldenclosure" size="6">';
echo get_string('defaultfieldenclosure', 'data').'</td>';
echo '</tr>';
echo '</table>';
echo '<input type="submit" value="'.get_string('uploadfile', 'data').'">';
echo '</form>';
echo '</div>';
print_simple_box_end();
if ($import) {
print_simple_box_start('center','80%');
print_heading(get_string('uploadrecords', 'data'), '', 3);
$maxuploadsize = get_max_upload_file_size();
echo '<div align="center">';
echo '<form enctype="multipart/form-data" action="import.php" method="post">';
echo '<input type="hidden" name="MAX_FILE_SIZE" value="'.$maxuploadsize.'">';
echo '<input name="d" value="'.$data->id.'" type="hidden" />';
echo '<input name="sesskey" value="'.sesskey().'" type="hidden" />';
echo '<table align="center" cellspacing="0" cellpadding="2" border="0">';
echo '<tr>';
echo '<td align="right">'.get_string('csvfile', 'data').':</td>';
echo '<td><input type="file" name="recordsfile" size="30">';
helpbutton('importcvs', 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">';
echo get_string('defaultfielddelimiter', 'data').'</td>';
echo '</tr>';
echo '<td align="right">'.get_string('fieldenclosure', 'data').':</td>';
echo '<td><input type="text" name="fieldenclosure" size="6">';
echo get_string('defaultfieldenclosure', 'data').'</td>';
echo '</tr>';
echo '</table>';
echo '<input type="submit" value="'.get_string('uploadfile', 'data').'">';
echo '</form>';
echo '</div>';
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
function display_browse_field($recordid, $template) {
if ($content = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) {
print_object($content);
if (isset($content->content)) {
$options->para = false;
$str = format_text($content->content, $content->content1, $options);

View file

@ -165,44 +165,28 @@
/***************************
* 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 ($confirm = optional_param('confirm',0,PARAM_INT)){
//find all contents in this record?
if ($contents = get_records('data_content','recordid',$delete)){
//for each content, delete the file associated
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);
if ($confirm = optional_param('confirm',0,PARAM_INT)) {
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
$field->delete_content($content->recordid);
}
}
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'));
}
}
else { //prints annoying confirmation dialogue
$field = get_record('data_records','id',$delete);
print_simple_box_start('center', '60%');
echo '<div align="center">';
echo '<form action = "view.php?d='.$data->id.'&amp;delete='.$delete.'" method="post">';
//add sesskey
echo get_string('confirmdeleterecord','data');
echo '<p />';
echo '<input type="hidden" value="'.sesskey().'" name="sesskey">';
echo '<input type="submit" value="'.get_string('ok').'"> ';
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>';
delete_records('data_content','recordid',$delete);
delete_records('data_records','id',$delete);
add_to_log($course->id, 'data', 'record delete', "view.php?id=$cm->id", $data->id, $cm->id);
notify(get_string('recorddeleted','data'));
} else { // Print a confirmation page
notice_yesno(get_string('confirmdeleterecord','data'),
'view.php?d='.$data->id.'&amp;delete='.$delete.'&amp;confirm=1&amp;sesskey='.sesskey(),
'view.php?d='.$data->id);
print_footer($course);
exit;
}