diff --git a/mod/data/lang/en/data.php b/mod/data/lang/en/data.php index 000b29d2275..d4029d8dd79 100644 --- a/mod/data/lang/en/data.php +++ b/mod/data/lang/en/data.php @@ -54,6 +54,7 @@ $string['cancel'] = 'Cancel'; $string['cannotaccesspresentsother'] = 'You are not allowed to access presets from other users'; $string['cannotadd'] = 'Can not add entries!'; $string['cannotdeletepreset'] = 'Error deleting a preset!'; +$string['cannotoverwritepreset'] = 'Error overwriting preset'; $string['cannotunziptopreset'] = 'Cannot unzip to the preset directory'; $string['columns'] = 'columns'; $string['comment'] = 'Comment'; diff --git a/mod/data/preset.php b/mod/data/preset.php index 2ea5662eb33..7eeb04d9260 100644 --- a/mod/data/preset.php +++ b/mod/data/preset.php @@ -79,6 +79,9 @@ foreach ($presets as &$preset) { $preset->description .= html_writer::link($delurl, $delicon); } } +// This is required because its currently bound to the last element in the array. +// If someone were to inadvently use it again and this call were not here +unset($preset); $form_importexisting = new data_existing_preset_form(null, array('presets'=>$presets)); $form_importexisting->set_data(array('d' => $data->id)); @@ -146,12 +149,15 @@ if (optional_param('sesskey', false, PARAM_BOOL) && confirm_sesskey()) { foreach ($presets as $preset) { if ($preset->name == $formdata->name) { $selectedpreset = $preset; + break; } } - if (data_user_can_delete_preset($context, $selectedpreset)) { - data_delete_site_preset($formdata->name); - } else { - print_error('cannotdeletepreset', 'data'); + if (isset($selectedpreset->name)) { + if (data_user_can_delete_preset($context, $selectedpreset)) { + data_delete_site_preset($formdata->name); + } else { + print_error('cannotoverwritepreset', 'data'); + } } } @@ -200,7 +206,7 @@ if (optional_param('sesskey', false, PARAM_BOOL) && confirm_sesskey()) { $selectedpreset = $preset; } } - if (!data_user_can_delete_preset($context, $selectedpreset)) { + if (!isset($selectedpreset->shortname) || !data_user_can_delete_preset($context, $selectedpreset)) { print_error('invalidrequest'); }