[5089] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[8728] | 3 | // | Piwigo - a PHP based photo gallery | |
---|
[5089] | 4 | // +-----------------------------------------------------------------------+ |
---|
| 5 | // | Copyright(C) 2010 Pierrick LE GALL http://piwigo.org | |
---|
| 6 | // +-----------------------------------------------------------------------+ |
---|
| 7 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 8 | // | it under the terms of the GNU General Public License as published by | |
---|
| 9 | // | the Free Software Foundation | |
---|
| 10 | // | | |
---|
| 11 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 12 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 13 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 14 | // | General Public License for more details. | |
---|
| 15 | // | | |
---|
| 16 | // | You should have received a copy of the GNU General Public License | |
---|
| 17 | // | along with this program; if not, write to the Free Software | |
---|
| 18 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 19 | // | USA. | |
---|
| 20 | // +-----------------------------------------------------------------------+ |
---|
| 21 | |
---|
| 22 | if (!defined('PHOTOS_ADD_BASE_URL')) |
---|
| 23 | { |
---|
| 24 | die ("Hacking attempt!"); |
---|
| 25 | } |
---|
| 26 | |
---|
| 27 | // by default, the form values are the current configuration |
---|
| 28 | // we may overwrite them with the current form values |
---|
| 29 | $form_values = array(); |
---|
| 30 | |
---|
| 31 | foreach ($upload_form_config as $param_shortname => $param) |
---|
| 32 | { |
---|
| 33 | $param_name = 'upload_form_'.$param_shortname; |
---|
| 34 | $form_values[$param_shortname] = $conf[$param_name]; |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | // +-----------------------------------------------------------------------+ |
---|
| 38 | // | process form | |
---|
| 39 | // +-----------------------------------------------------------------------+ |
---|
| 40 | |
---|
| 41 | if (isset($_POST['submit'])) |
---|
| 42 | { |
---|
| 43 | $updates = array(); |
---|
| 44 | |
---|
| 45 | // let's care about the specific checkbox that disable/enable other |
---|
| 46 | // settings |
---|
| 47 | $field = 'websize_resize'; |
---|
[8227] | 48 | $fields[] = $field; |
---|
[5089] | 49 | |
---|
[8227] | 50 | if (!empty($_POST[$field])) |
---|
[5089] | 51 | { |
---|
| 52 | $fields[] = 'websize_maxwidth'; |
---|
| 53 | $fields[] = 'websize_maxheight'; |
---|
| 54 | $fields[] = 'websize_quality'; |
---|
[8227] | 55 | } |
---|
[5089] | 56 | |
---|
[8227] | 57 | // hd_keep |
---|
| 58 | $field = 'hd_keep'; |
---|
| 59 | $fields[] = $field; |
---|
| 60 | |
---|
| 61 | if (!empty($_POST[$field])) |
---|
| 62 | { |
---|
| 63 | $field = 'hd_resize'; |
---|
| 64 | $fields[] = $field; |
---|
| 65 | |
---|
| 66 | if (!empty($_POST[$field])) |
---|
| 67 | { |
---|
| 68 | $fields[] = 'hd_maxwidth'; |
---|
| 69 | $fields[] = 'hd_maxheight'; |
---|
| 70 | $fields[] = 'hd_quality'; |
---|
| 71 | } |
---|
[5089] | 72 | } |
---|
| 73 | |
---|
| 74 | // and now other fields, processed in a generic way |
---|
| 75 | $fields[] = 'thumb_maxwidth'; |
---|
| 76 | $fields[] = 'thumb_maxheight'; |
---|
| 77 | $fields[] = 'thumb_quality'; |
---|
[10552] | 78 | $fields[] = 'thumb_crop'; |
---|
| 79 | $fields[] = 'thumb_follow_orientation'; |
---|
| 80 | |
---|
[5089] | 81 | foreach ($fields as $field) |
---|
| 82 | { |
---|
| 83 | $value = null; |
---|
| 84 | if (!empty($_POST[$field])) |
---|
| 85 | { |
---|
| 86 | $value = $_POST[$field]; |
---|
| 87 | } |
---|
| 88 | |
---|
[8227] | 89 | if (is_bool($upload_form_config[$field]['default'])) |
---|
[5089] | 90 | { |
---|
[8227] | 91 | if (isset($value)) |
---|
| 92 | { |
---|
| 93 | $value = true; |
---|
| 94 | } |
---|
| 95 | else |
---|
| 96 | { |
---|
| 97 | $value = false; |
---|
| 98 | } |
---|
| 99 | |
---|
[5089] | 100 | $updates[] = array( |
---|
| 101 | 'param' => 'upload_form_'.$field, |
---|
[8227] | 102 | 'value' => boolean_to_string($value) |
---|
| 103 | ); |
---|
| 104 | } |
---|
| 105 | elseif ($upload_form_config[$field]['can_be_null'] and empty($value)) |
---|
| 106 | { |
---|
| 107 | $updates[] = array( |
---|
| 108 | 'param' => 'upload_form_'.$field, |
---|
[5089] | 109 | 'value' => 'false' |
---|
| 110 | ); |
---|
| 111 | } |
---|
| 112 | else |
---|
| 113 | { |
---|
| 114 | $min = $upload_form_config[$field]['min']; |
---|
| 115 | $max = $upload_form_config[$field]['max']; |
---|
| 116 | $pattern = $upload_form_config[$field]['pattern']; |
---|
| 117 | |
---|
| 118 | if (preg_match($pattern, $value) and $value >= $min and $value <= $max) |
---|
| 119 | { |
---|
| 120 | $updates[] = array( |
---|
| 121 | 'param' => 'upload_form_'.$field, |
---|
| 122 | 'value' => $value |
---|
| 123 | ); |
---|
| 124 | } |
---|
| 125 | else |
---|
| 126 | { |
---|
| 127 | array_push( |
---|
| 128 | $page['errors'], |
---|
| 129 | sprintf( |
---|
[5285] | 130 | $upload_form_config[$field]['error_message'], |
---|
[5089] | 131 | $min, |
---|
| 132 | $max |
---|
| 133 | ) |
---|
| 134 | ); |
---|
| 135 | } |
---|
| 136 | } |
---|
[8227] | 137 | |
---|
| 138 | $form_values[$field] = $value; |
---|
[5089] | 139 | } |
---|
| 140 | |
---|
| 141 | if (count($page['errors']) == 0) |
---|
| 142 | { |
---|
| 143 | mass_updates( |
---|
| 144 | CONFIG_TABLE, |
---|
| 145 | array( |
---|
| 146 | 'primary' => array('param'), |
---|
| 147 | 'update' => array('value') |
---|
| 148 | ), |
---|
| 149 | $updates |
---|
| 150 | ); |
---|
| 151 | |
---|
| 152 | array_push( |
---|
| 153 | $page['infos'], |
---|
| 154 | l10n('Your configuration settings are saved') |
---|
| 155 | ); |
---|
| 156 | } |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | // +-----------------------------------------------------------------------+ |
---|
| 160 | // | template init | |
---|
| 161 | // +-----------------------------------------------------------------------+ |
---|
| 162 | |
---|
[8227] | 163 | foreach (array_keys($upload_form_config) as $field) |
---|
| 164 | { |
---|
| 165 | if (is_bool($upload_form_config[$field]['default'])) |
---|
| 166 | { |
---|
| 167 | $form_values[$field] = $form_values[$field] ? 'checked="checked"' : ''; |
---|
| 168 | } |
---|
| 169 | } |
---|
[5089] | 170 | |
---|
| 171 | $template->assign( |
---|
| 172 | array( |
---|
| 173 | 'F_ADD_ACTION'=> PHOTOS_ADD_BASE_URL, |
---|
[8227] | 174 | 'MANAGE_HD' => is_imagick(), |
---|
[5089] | 175 | 'values' => $form_values |
---|
| 176 | ) |
---|
| 177 | ); |
---|
| 178 | |
---|
| 179 | |
---|
| 180 | // +-----------------------------------------------------------------------+ |
---|
| 181 | // | sending html code | |
---|
| 182 | // +-----------------------------------------------------------------------+ |
---|
| 183 | |
---|
[5960] | 184 | $template->assign_var_from_handle('ADMIN_CONTENT', 'photos_add'); |
---|
[5089] | 185 | ?> |
---|