1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based picture gallery | |
---|
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'; |
---|
48 | $fields[] = $field; |
---|
49 | |
---|
50 | if (!empty($_POST[$field])) |
---|
51 | { |
---|
52 | $fields[] = 'websize_maxwidth'; |
---|
53 | $fields[] = 'websize_maxheight'; |
---|
54 | $fields[] = 'websize_quality'; |
---|
55 | } |
---|
56 | |
---|
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 | } |
---|
72 | } |
---|
73 | |
---|
74 | // and now other fields, processed in a generic way |
---|
75 | $fields[] = 'thumb_maxwidth'; |
---|
76 | $fields[] = 'thumb_maxheight'; |
---|
77 | $fields[] = 'thumb_quality'; |
---|
78 | |
---|
79 | foreach ($fields as $field) |
---|
80 | { |
---|
81 | $value = null; |
---|
82 | if (!empty($_POST[$field])) |
---|
83 | { |
---|
84 | $value = $_POST[$field]; |
---|
85 | } |
---|
86 | |
---|
87 | if (is_bool($upload_form_config[$field]['default'])) |
---|
88 | { |
---|
89 | if (isset($value)) |
---|
90 | { |
---|
91 | $value = true; |
---|
92 | } |
---|
93 | else |
---|
94 | { |
---|
95 | $value = false; |
---|
96 | } |
---|
97 | |
---|
98 | $updates[] = array( |
---|
99 | 'param' => 'upload_form_'.$field, |
---|
100 | 'value' => boolean_to_string($value) |
---|
101 | ); |
---|
102 | } |
---|
103 | elseif ($upload_form_config[$field]['can_be_null'] and empty($value)) |
---|
104 | { |
---|
105 | $updates[] = array( |
---|
106 | 'param' => 'upload_form_'.$field, |
---|
107 | 'value' => 'false' |
---|
108 | ); |
---|
109 | } |
---|
110 | else |
---|
111 | { |
---|
112 | $min = $upload_form_config[$field]['min']; |
---|
113 | $max = $upload_form_config[$field]['max']; |
---|
114 | $pattern = $upload_form_config[$field]['pattern']; |
---|
115 | |
---|
116 | if (preg_match($pattern, $value) and $value >= $min and $value <= $max) |
---|
117 | { |
---|
118 | $updates[] = array( |
---|
119 | 'param' => 'upload_form_'.$field, |
---|
120 | 'value' => $value |
---|
121 | ); |
---|
122 | } |
---|
123 | else |
---|
124 | { |
---|
125 | array_push( |
---|
126 | $page['errors'], |
---|
127 | sprintf( |
---|
128 | $upload_form_config[$field]['error_message'], |
---|
129 | $min, |
---|
130 | $max |
---|
131 | ) |
---|
132 | ); |
---|
133 | } |
---|
134 | } |
---|
135 | |
---|
136 | $form_values[$field] = $value; |
---|
137 | } |
---|
138 | |
---|
139 | if (count($page['errors']) == 0) |
---|
140 | { |
---|
141 | mass_updates( |
---|
142 | CONFIG_TABLE, |
---|
143 | array( |
---|
144 | 'primary' => array('param'), |
---|
145 | 'update' => array('value') |
---|
146 | ), |
---|
147 | $updates |
---|
148 | ); |
---|
149 | |
---|
150 | array_push( |
---|
151 | $page['infos'], |
---|
152 | l10n('Your configuration settings are saved') |
---|
153 | ); |
---|
154 | } |
---|
155 | } |
---|
156 | |
---|
157 | // +-----------------------------------------------------------------------+ |
---|
158 | // | template init | |
---|
159 | // +-----------------------------------------------------------------------+ |
---|
160 | |
---|
161 | foreach (array_keys($upload_form_config) as $field) |
---|
162 | { |
---|
163 | if (is_bool($upload_form_config[$field]['default'])) |
---|
164 | { |
---|
165 | $form_values[$field] = $form_values[$field] ? 'checked="checked"' : ''; |
---|
166 | } |
---|
167 | } |
---|
168 | |
---|
169 | $template->assign( |
---|
170 | array( |
---|
171 | 'F_ADD_ACTION'=> PHOTOS_ADD_BASE_URL, |
---|
172 | 'MANAGE_HD' => is_imagick(), |
---|
173 | 'values' => $form_values |
---|
174 | ) |
---|
175 | ); |
---|
176 | |
---|
177 | |
---|
178 | // +-----------------------------------------------------------------------+ |
---|
179 | // | sending html code | |
---|
180 | // +-----------------------------------------------------------------------+ |
---|
181 | |
---|
182 | $template->assign_var_from_handle('ADMIN_CONTENT', 'photos_add'); |
---|
183 | ?> |
---|