From d3da2883ce9ed16549fcdf6e47b2675b16705a0d 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 7c3c8cc7277..4c48c11e84a 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 f49cfde3b5b..bcc285c8f10 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'); }