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('UPLOAD_FORM_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 | |
---|
49 | if (empty($_POST[$field])) |
---|
50 | { |
---|
51 | $value = false; |
---|
52 | } |
---|
53 | else |
---|
54 | { |
---|
55 | $fields[] = 'websize_maxwidth'; |
---|
56 | $fields[] = 'websize_maxheight'; |
---|
57 | $fields[] = 'websize_quality'; |
---|
58 | |
---|
59 | $value = true; |
---|
60 | } |
---|
61 | |
---|
62 | $updates[] = array( |
---|
63 | 'param' => 'upload_form_'.$field, |
---|
64 | 'value' => boolean_to_string($value), |
---|
65 | ); |
---|
66 | $form_values[$field] = $value;; |
---|
67 | |
---|
68 | // and now other fields, processed in a generic way |
---|
69 | $fields[] = 'thumb_maxwidth'; |
---|
70 | $fields[] = 'thumb_maxheight'; |
---|
71 | $fields[] = 'thumb_quality'; |
---|
72 | |
---|
73 | foreach ($fields as $field) |
---|
74 | { |
---|
75 | $value = null; |
---|
76 | if (!empty($_POST[$field])) |
---|
77 | { |
---|
78 | $value = $_POST[$field]; |
---|
79 | } |
---|
80 | $form_values[$field] = $value; |
---|
81 | |
---|
82 | if ($upload_form_config[$field]['can_be_null'] and empty($value)) |
---|
83 | { |
---|
84 | $updates[] = array( |
---|
85 | 'param' => 'upload_form_'.$field, |
---|
86 | 'value' => 'false' |
---|
87 | ); |
---|
88 | } |
---|
89 | else |
---|
90 | { |
---|
91 | $min = $upload_form_config[$field]['min']; |
---|
92 | $max = $upload_form_config[$field]['max']; |
---|
93 | $pattern = $upload_form_config[$field]['pattern']; |
---|
94 | |
---|
95 | if (preg_match($pattern, $value) and $value >= $min and $value <= $max) |
---|
96 | { |
---|
97 | $updates[] = array( |
---|
98 | 'param' => 'upload_form_'.$field, |
---|
99 | 'value' => $value |
---|
100 | ); |
---|
101 | } |
---|
102 | else |
---|
103 | { |
---|
104 | array_push( |
---|
105 | $page['errors'], |
---|
106 | sprintf( |
---|
107 | l10n($upload_form_config[$field]['error_message']), |
---|
108 | $min, |
---|
109 | $max |
---|
110 | ) |
---|
111 | ); |
---|
112 | } |
---|
113 | } |
---|
114 | } |
---|
115 | |
---|
116 | if (count($page['errors']) == 0) |
---|
117 | { |
---|
118 | mass_updates( |
---|
119 | CONFIG_TABLE, |
---|
120 | array( |
---|
121 | 'primary' => array('param'), |
---|
122 | 'update' => array('value') |
---|
123 | ), |
---|
124 | $updates |
---|
125 | ); |
---|
126 | |
---|
127 | array_push( |
---|
128 | $page['infos'], |
---|
129 | l10n('Your configuration settings are saved') |
---|
130 | ); |
---|
131 | } |
---|
132 | } |
---|
133 | |
---|
134 | // +-----------------------------------------------------------------------+ |
---|
135 | // | template init | |
---|
136 | // +-----------------------------------------------------------------------+ |
---|
137 | |
---|
138 | // specific case, "websize_resize" is a checkbox |
---|
139 | $field = 'websize_resize'; |
---|
140 | $form_values[$field] = $form_values[$field] ? 'checked="checked"' : ''; |
---|
141 | |
---|
142 | $template->assign( |
---|
143 | array( |
---|
144 | 'F_ADD_ACTION'=> UPLOAD_FORM_BASE_URL, |
---|
145 | 'plugin_path' => UPLOAD_FORM_PATH, |
---|
146 | 'values' => $form_values |
---|
147 | ) |
---|
148 | ); |
---|
149 | |
---|
150 | |
---|
151 | // +-----------------------------------------------------------------------+ |
---|
152 | // | sending html code | |
---|
153 | // +-----------------------------------------------------------------------+ |
---|
154 | |
---|
155 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
156 | ?> |
---|