aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--admin/batch_manager_global.php49
-rw-r--r--admin/include/functions_upload.inc.php82
-rw-r--r--admin/photos_add_settings.php68
3 files changed, 90 insertions, 109 deletions
diff --git a/admin/batch_manager_global.php b/admin/batch_manager_global.php
index 40628d0d7..d00101b9c 100644
--- a/admin/batch_manager_global.php
+++ b/admin/batch_manager_global.php
@@ -433,56 +433,15 @@ SELECT id, path
if (!empty($update_fields))
{
- // Update configuration
+ // Update upload configuration
$updates = array();
foreach ($update_fields as $field)
{
- if (is_bool($upload_form_config[$field]['default']))
- {
- $value = isset($_POST[$field]);
-
- $updates[] = array(
- 'param' => 'upload_form_'.$field,
- 'value' => boolean_to_string($value)
- );
- }
- else
- {
- $value = null;
- if (!empty($_POST[$field]))
- {
- $value = $_POST[$field];
- }
-
- if (preg_match($upload_form_config[$field]['pattern'], $value)
- and $value >= $upload_form_config[$field]['min']
- and $value <= $upload_form_config[$field]['max'])
- {
- $conf['upload_form_'.$field] = $value;
- $updates[] = array(
- 'param' => 'upload_form_'.$field,
- 'value' => $value
- );
- }
- else
- {
- $updates = null;
- break;
- }
- }
+ $value = !empty($_POST[$field]) ? $_POST[$field] : null;
$form_values[$field] = $value;
+ $updates[$field] = $value;
}
- if (!empty($updates))
- {
- mass_updates(
- CONFIG_TABLE,
- array(
- 'primary' => array('param'),
- 'update' => array('value')
- ),
- $updates
- );
- }
+ save_upload_form_config($updates);
$template->delete_compiled_templates();
}
diff --git a/admin/include/functions_upload.inc.php b/admin/include/functions_upload.inc.php
index aa25e5219..4fe8ce76b 100644
--- a/admin/include/functions_upload.inc.php
+++ b/admin/include/functions_upload.inc.php
@@ -178,6 +178,88 @@ function prepare_upload_configuration()
}
}
+function save_upload_form_config($data, &$errors=array())
+{
+ if (!is_array($data) or empty($data))
+ {
+ return false;
+ }
+
+ $upload_form_config = get_upload_form_config();
+ $updates = array();
+
+ foreach ($data as $field => $value)
+ {
+ if (!isset($upload_form_config[$field]))
+ {
+ continue;
+ }
+ if (is_bool($upload_form_config[$field]['default']))
+ {
+ if (isset($value))
+ {
+ $value = true;
+ }
+ else
+ {
+ $value = false;
+ }
+
+ $updates[] = array(
+ 'param' => 'upload_form_'.$field,
+ 'value' => boolean_to_string($value)
+ );
+ }
+ elseif ($upload_form_config[$field]['can_be_null'] and empty($value))
+ {
+ $updates[] = array(
+ 'param' => 'upload_form_'.$field,
+ 'value' => 'false'
+ );
+ }
+ else
+ {
+ $min = $upload_form_config[$field]['min'];
+ $max = $upload_form_config[$field]['max'];
+ $pattern = $upload_form_config[$field]['pattern'];
+
+ if (preg_match($pattern, $value) and $value >= $min and $value <= $max)
+ {
+ $updates[] = array(
+ 'param' => 'upload_form_'.$field,
+ 'value' => $value
+ );
+ }
+ else
+ {
+ array_push(
+ $errors,
+ sprintf(
+ $upload_form_config[$field]['error_message'],
+ $min,
+ $max
+ )
+ );
+ }
+ }
+ }
+
+ if (count($errors) == 0)
+ {
+ mass_updates(
+ CONFIG_TABLE,
+ array(
+ 'primary' => array('param'),
+ 'update' => array('value')
+ ),
+ $updates
+ );
+ return true;
+ }
+
+ return false;
+}
+
function add_uploaded_file($source_filepath, $original_filename=null, $categories=null, $level=null, $image_id=null)
{
// Here is the plan
diff --git a/admin/photos_add_settings.php b/admin/photos_add_settings.php
index fd0db4c90..968b4a870 100644
--- a/admin/photos_add_settings.php
+++ b/admin/photos_add_settings.php
@@ -80,75 +80,15 @@ if (isset($_POST['submit']))
foreach ($fields as $field)
{
- $value = null;
- if (!empty($_POST[$field]))
- {
- $value = $_POST[$field];
- }
-
- if (is_bool($upload_form_config[$field]['default']))
- {
- if (isset($value))
- {
- $value = true;
- }
- else
- {
- $value = false;
- }
-
- $updates[] = array(
- 'param' => 'upload_form_'.$field,
- 'value' => boolean_to_string($value)
- );
- }
- elseif ($upload_form_config[$field]['can_be_null'] and empty($value))
- {
- $updates[] = array(
- 'param' => 'upload_form_'.$field,
- 'value' => 'false'
- );
- }
- else
- {
- $min = $upload_form_config[$field]['min'];
- $max = $upload_form_config[$field]['max'];
- $pattern = $upload_form_config[$field]['pattern'];
-
- if (preg_match($pattern, $value) and $value >= $min and $value <= $max)
- {
- $updates[] = array(
- 'param' => 'upload_form_'.$field,
- 'value' => $value
- );
- }
- else
- {
- array_push(
- $page['errors'],
- sprintf(
- $upload_form_config[$field]['error_message'],
- $min,
- $max
- )
- );
- }
- }
-
+ $value = !empty($_POST[$field]) ? $_POST[$field] : null;
$form_values[$field] = $value;
+ $updates[$field] = $value;
}
+ save_upload_form_config($updates, $page['errors']);
+
if (count($page['errors']) == 0)
{
- mass_updates(
- CONFIG_TABLE,
- array(
- 'primary' => array('param'),
- 'update' => array('value')
- ),
- $updates
- );
-
array_push(
$page['infos'],
l10n('Your configuration settings are saved')