From c56d266a587bb48bbb14f41aff5bd84cb97b5c62 Mon Sep 17 00:00:00 2001 From: Sam Hemelryk Date: Thu, 10 May 2012 17:31:24 +1200 Subject: [PATCH] MDL-31763 mod_data: Fixed array iteration reference issue --- mod/data/lang/en/data.php | 1 + mod/data/preset.php | 16 +++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/mod/data/lang/en/data.php b/mod/data/lang/en/data.php index 9603c6c6d98..64a5618ef51 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 08cde854f35..bd3142839fc 100644 --- a/mod/data/preset.php +++ b/mod/data/preset.php @@ -78,6 +78,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)); @@ -145,12 +148,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'); + } } } @@ -199,7 +205,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'); }