diff --git a/sites/all/modules/contrib/imce/imce.module b/sites/all/modules/contrib/imce/imce.module index f3dc4bf..973fc0e 100644 --- a/sites/all/modules/contrib/imce/imce.module +++ b/sites/all/modules/contrib/imce/imce.module @@ -5,6 +5,11 @@ * Implements the necessary hooks for the file browser to work properly. */ +/** Flag for letting the user decide to replace the existing file with the new one + * or keep the existing file and renaming the uploaded file + */ +define('IMCE_RENAME_REPLACE', 1001); + /** * Implements hook_menu(). */ diff --git a/sites/all/modules/contrib/imce/inc/imce.admin.inc b/sites/all/modules/contrib/imce/inc/imce.admin.inc index d88cd28..86b1f37 100644 --- a/sites/all/modules/contrib/imce/inc/imce.admin.inc +++ b/sites/all/modules/contrib/imce/inc/imce.admin.inc @@ -79,7 +79,8 @@ function imce_admin_form($form, &$form_state) { '#options' => array( FILE_EXISTS_RENAME => t('Keep the existing file renaming the new one'), FILE_EXISTS_ERROR => t('Keep the existing file rejecting the new one'), - FILE_EXISTS_REPLACE => t('Replace the existing file with the new one') + FILE_EXISTS_REPLACE => t('Replace the existing file with the new one'), + IMCE_RENAME_REPLACE => t('Let the user decide wich option to choose') ), ); $form['common']['thumb_method'] = array( diff --git a/sites/all/modules/contrib/imce/inc/imce.page.inc b/sites/all/modules/contrib/imce/inc/imce.page.inc index bcb00b2..6c77004 100644 --- a/sites/all/modules/contrib/imce/inc/imce.page.inc +++ b/sites/all/modules/contrib/imce/inc/imce.page.inc @@ -138,6 +138,20 @@ function imce_upload_form($form, &$form_state, $ref) { '#options' => imce_thumbnail_options($imce['thumbnails']), ); } + $replace = variable_get('imce_settings_replace', FILE_EXISTS_RENAME); + // In case the user can decide, show options + if ($replace == IMCE_RENAME_REPLACE) { + $form['replace'] = array( + '#type' => 'radios', + '#title' => t('Behaviour for existing files'), + '#default_value' => variable_get('imce_settings_replace', FILE_EXISTS_RENAME), + '#options' => array( + FILE_EXISTS_RENAME => t('Keep the existing file renaming the new one'), + FILE_EXISTS_ERROR => t('Keep the existing file rejecting the new one'), + FILE_EXISTS_REPLACE => t('Replace the existing file with the new one'), + ), + ); + } $form['upload'] = array( '#type' => 'submit', '#value' => t('Upload'), @@ -292,6 +306,10 @@ function imce_upload_submit($form, &$form_state) { //save uploaded file. $replace = variable_get('imce_settings_replace', FILE_EXISTS_RENAME); + // Retrieve the user option when the option is set for the user to decide + if ($replace == IMCE_RENAME_REPLACE) { + $replace = $form_state['values']['replace']; + } if ($file = file_save_upload('imce', $validators, $diruri, $replace)) { //core bug #54223.