aboutsummaryrefslogtreecommitdiffstats
path: root/admin/include/functions_upload.inc.php
diff options
context:
space:
mode:
authorpatdenice <patdenice@piwigo.org>2011-04-23 08:51:53 +0000
committerpatdenice <patdenice@piwigo.org>2011-04-23 08:51:53 +0000
commit6597975404e82f5d5d4234afd70d4002db222824 (patch)
tree8305cdb40bdbfe15d09f05b0c6592c4b5dfdb98a /admin/include/functions_upload.inc.php
parentef00110fe75a3036908602d3f4c8e54df43dd72d (diff)
Create a function to save upload form settings.
git-svn-id: http://piwigo.org/svn/trunk@10589 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r--admin/include/functions_upload.inc.php82
1 files changed, 82 insertions, 0 deletions
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