source: extensions/manage_properties_photos/admin.php @ 31937

Last change on this file since 31937 was 31409, checked in by ddtddt, 8 years ago

[extensions] - manage_properties_photos

File size: 16.6 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Manage Properties Photos plugin for Piwigo                            |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2014-2016 ddtddt               http://temmii.com/piwigo/ |
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
22if (!defined('PHPWG_ROOT_PATH'))
23    die('Hacking attempt!');
24global $template, $conf, $user;
25include_once(PHPWG_ROOT_PATH . 'admin/include/tabsheet.class.php');
26load_language('plugin.lang', ADD_PROP_PHOTO_PATH);
27$my_base_url = get_admin_plugin_menu_link(__FILE__);
28
29// +-----------------------------------------------------------------------+
30// | Check Access and exit when user status is not ok                      |
31// +-----------------------------------------------------------------------+
32check_status(ACCESS_ADMINISTRATOR);
33
34//-------------------------------------------------------- sections definitions
35if (!isset($_GET['tab']))
36    $page['tab'] = 'define_properties';
37else
38    $page['tab'] = $_GET['tab'];
39
40
41if ($page['tab'] != 'iap') {
42    $tabsheet = new tabsheet();
43    $tabsheet->add('addip', l10n('Property'), ADD_PROP_PHOTO_ADMIN . '-define_properties');
44    $tabsheet->select($page['tab']);
45    $tabsheet->assign();
46} else if ($_GET['tab'] == 'iap') {
47
48    $page['active_menu'] = get_active_menu('photo'); // force oppening "Photos" menu block
49
50    /* Basic checks */
51    check_status(ACCESS_ADMINISTRATOR);
52
53    check_input_parameter('image_id', $_GET, false, PATTERN_ID);
54    $id_img = $_GET['image_id'];
55    $admin_photo_base_url = get_root_url() . 'admin.php?page=photo-' . $_GET['image_id'];
56
57    $page['tab'] = 'iap';
58
59    $tabsheet = new tabsheet();
60    $tabsheet->set_id('photo');
61    $tabsheet->select('iap');
62    $tabsheet->assign();
63
64    $template->assign(
65            'gestionD', array(
66        'A' => 'a'
67    ));
68   
69    $PAED = pwg_db_fetch_assoc(pwg_query("SELECT state FROM " . PLUGINS_TABLE . " WHERE id = 'ExtendedDescription';"));
70    if($PAED['state'] == 'active'){
71        add_event_handler('AP_render_content', 'get_user_language_desc');
72                $template->assign('useED',1);
73    }else{
74        $template->assign('useED',0);
75    }
76
77    $tab_add_info_one_photo = tab_add_info_by_photo($_GET['image_id']);
78    if (pwg_db_num_rows($tab_add_info_one_photo)) {
79        while ($info_photos = pwg_db_fetch_assoc($tab_add_info_one_photo)) {
80
81            $d = data_info_photos($id_img, $info_photos['id_prop_pho']);
82            $row = pwg_db_fetch_assoc($d);
83
84            $items = array(
85                'IDPHO' => $_GET['image_id'],
86                'IDINFOPHO' => $info_photos['id_prop_pho'],
87                'AIPWORDING' => trigger_change('AP_render_content',$info_photos['wording']),
88                'AIPDATA' => $row['data'],
89            );
90
91            $template->append('info_photos', $items);
92        }
93    }
94
95    if (isset($_POST['submitaddinfoimg'])) {
96        foreach ($_POST['data'] AS $id_prop_pho => $data) {
97            $q = 'SELECT 1 FROM ' . ADD_PROP_PHOTO_DATA_TABLE . ' WHERE id_img=' . $id_img . ' AND id_prop_pho=' . $id_prop_pho;
98            $test = pwg_query($q);
99            $row = pwg_db_fetch_assoc($test);
100            if (count($row) > 0) {
101                if ($data != '') {
102                    $query = 'UPDATE ' . $prefixeTable . 'add_properties_photos_data SET data="' . $data . '" WHERE id_img=' . $id_img . ' AND id_prop_pho=' . $id_prop_pho;
103                    pwg_query($query);
104                } else {
105                    $query = 'DELETE FROM ' . $prefixeTable . 'add_properties_photos_data WHERE id_img=' . $id_img . ' AND id_prop_pho=' . $id_prop_pho;
106                    pwg_query($query);
107                }
108            } else if ($data != '') {
109                $query = 'INSERT ' . $prefixeTable . 'add_properties_photos_data(id_img,id_prop_pho,data) VALUES (' . $id_img . ',' . $id_prop_pho . ',"' . $data . '");';
110                pwg_query($query);
111            }
112           
113        }
114        $redirect_url = ADD_PROP_PHOTO_ADMIN . '-iap&amp;image_id=' . $id_img;
115        $_SESSION['page_infos'] = array(l10n('Properties update'));
116        redirect($redirect_url);
117    }
118}
119
120switch ($page['tab']) {
121    case 'define_properties':
122        $admin_base_url = ADD_PROP_PHOTO_ADMIN . '-define_properties';
123        $template->assign(
124                'addinfotemplate', array(
125            'addinfo' => l10n('addinfo'),
126       ));
127       
128    $PAED = pwg_db_fetch_assoc(pwg_query("SELECT state FROM " . PLUGINS_TABLE . " WHERE id = 'ExtendedDescription';"));
129    if($PAED['state'] == 'active'){
130        add_event_handler('AP_render_content', 'get_user_language_desc');
131                $template->assign('useED',1);
132    }else{
133        $template->assign('useED',0);
134    }
135       
136        $admin_base_url = ADD_PROP_PHOTO_ADMIN . '-define_properties';
137        $tab_info_photos = tab_info_photos();
138
139        if (pwg_db_num_rows($tab_info_photos)) {
140            while ($info_photos = pwg_db_fetch_assoc($tab_info_photos)) {
141                if($info_photos['id_prop_pho']==1){
142                    $items = array(
143                        'IDINFOPHO' => $info_photos['id_prop_pho'],
144                        'AIPWORDING' => l10n('Author'),
145                        'AIPORDER' => $info_photos['orderprop'],
146                        'AIPACTIVE' => $info_photos['active'],
147                        'AIPEDIT' => $info_photos['edit'],
148                        'U_HIDE' => $admin_base_url . '&amp;hide=' . $info_photos['id_prop_pho'],
149                        'U_SHOW' => $admin_base_url . '&amp;show=' . $info_photos['id_prop_pho'],
150                    );
151                }else if($info_photos['id_prop_pho']==2){
152                    $items = array(
153                        'IDINFOPHO' => $info_photos['id_prop_pho'],
154                        'AIPWORDING' => l10n('Created on'),
155                        'AIPORDER' => $info_photos['orderprop'],
156                        'AIPACTIVE' => $info_photos['active'],
157                        'AIPEDIT' => $info_photos['edit'],
158                        'U_HIDE' => $admin_base_url . '&amp;hide=' . $info_photos['id_prop_pho'],
159                        'U_SHOW' => $admin_base_url . '&amp;show=' . $info_photos['id_prop_pho'],
160                    );
161                }else if($info_photos['id_prop_pho']==3){
162                    $items = array(
163                        'IDINFOPHO' => $info_photos['id_prop_pho'],
164                        'AIPWORDING' => l10n('Posted on'),
165                        'AIPORDER' => $info_photos['orderprop'],
166                        'AIPACTIVE' => $info_photos['active'],
167                        'AIPEDIT' => $info_photos['edit'],
168                        'U_HIDE' => $admin_base_url . '&amp;hide=' . $info_photos['id_prop_pho'],
169                        'U_SHOW' => $admin_base_url . '&amp;show=' . $info_photos['id_prop_pho'],
170                    );
171                }else if($info_photos['id_prop_pho']==4){
172                    $items = array(
173                        'IDINFOPHO' => $info_photos['id_prop_pho'],
174                        'AIPWORDING' => l10n('Dimensions'),
175                        'AIPORDER' => $info_photos['orderprop'],
176                        'AIPACTIVE' => $info_photos['active'],
177                        'AIPEDIT' => $info_photos['edit'],
178                        'U_HIDE' => $admin_base_url . '&amp;hide=' . $info_photos['id_prop_pho'],
179                        'U_SHOW' => $admin_base_url . '&amp;show=' . $info_photos['id_prop_pho'],
180                    );
181                }else if($info_photos['id_prop_pho']==5){
182                    $items = array(
183                        'IDINFOPHO' => $info_photos['id_prop_pho'],
184                        'AIPWORDING' => l10n('File'),
185                        'AIPORDER' => $info_photos['orderprop'],
186                        'AIPACTIVE' => $info_photos['active'],
187                        'AIPEDIT' => $info_photos['edit'],
188                        'U_HIDE' => $admin_base_url . '&amp;hide=' . $info_photos['id_prop_pho'],
189                        'U_SHOW' => $admin_base_url . '&amp;show=' . $info_photos['id_prop_pho'],
190                    );
191                }else if($info_photos['id_prop_pho']==6){
192                    $items = array(
193                        'IDINFOPHO' => $info_photos['id_prop_pho'],
194                        'AIPWORDING' => l10n('Filesize'),
195                        'AIPORDER' => $info_photos['orderprop'],
196                        'AIPACTIVE' => $info_photos['active'],
197                        'AIPEDIT' => $info_photos['edit'],
198                        'U_HIDE' => $admin_base_url . '&amp;hide=' . $info_photos['id_prop_pho'],
199                        'U_SHOW' => $admin_base_url . '&amp;show=' . $info_photos['id_prop_pho'],
200                    );
201                }else if($info_photos['id_prop_pho']==7){
202                    $items = array(
203                        'IDINFOPHO' => $info_photos['id_prop_pho'],
204                        'AIPWORDING' => l10n('Tags'),
205                        'AIPORDER' => $info_photos['orderprop'],
206                        'AIPACTIVE' => $info_photos['active'],
207                        'AIPEDIT' => $info_photos['edit'],
208                        'U_HIDE' => $admin_base_url . '&amp;hide=' . $info_photos['id_prop_pho'],
209                        'U_SHOW' => $admin_base_url . '&amp;show=' . $info_photos['id_prop_pho'],
210                    );
211                }else if($info_photos['id_prop_pho']==8){
212                    $items = array(
213                        'IDINFOPHO' => $info_photos['id_prop_pho'],
214                        'AIPWORDING' => l10n('Albums'),
215                        'AIPORDER' => $info_photos['orderprop'],
216                        'AIPACTIVE' => $info_photos['active'],
217                        'AIPEDIT' => $info_photos['edit'],
218                        'U_HIDE' => $admin_base_url . '&amp;hide=' . $info_photos['id_prop_pho'],
219                        'U_SHOW' => $admin_base_url . '&amp;show=' . $info_photos['id_prop_pho'],
220                    );
221                }else if($info_photos['id_prop_pho']==9){
222                    $items = array(
223                        'IDINFOPHO' => $info_photos['id_prop_pho'],
224                        'AIPWORDING' => l10n('Visits'),
225                        'AIPORDER' => $info_photos['orderprop'],
226                        'AIPACTIVE' => $info_photos['active'],
227                        'AIPEDIT' => $info_photos['edit'],
228                        'U_HIDE' => $admin_base_url . '&amp;hide=' . $info_photos['id_prop_pho'],
229                        'U_SHOW' => $admin_base_url . '&amp;show=' . $info_photos['id_prop_pho'],
230                    );
231                }else if($info_photos['id_prop_pho']==10){
232                    $items = array(
233                        'IDINFOPHO' => $info_photos['id_prop_pho'],
234                        'AIPWORDING' => l10n('Average'),
235                        'AIPORDER' => $info_photos['orderprop'],
236                        'AIPACTIVE' => $info_photos['active'],
237                        'AIPEDIT' => $info_photos['edit'],
238                        'U_HIDE' => $admin_base_url . '&amp;hide=' . $info_photos['id_prop_pho'],
239                        'U_SHOW' => $admin_base_url . '&amp;show=' . $info_photos['id_prop_pho'],
240                    );
241                }else if($info_photos['id_prop_pho']==11){
242                    $items = array(
243                        'IDINFOPHO' => $info_photos['id_prop_pho'],
244                        'AIPWORDING' => l10n('Who can see this photo?'),
245                        'AIPORDER' => $info_photos['orderprop'],
246                        'AIPACTIVE' => $info_photos['active'],
247                        'AIPEDIT' => $info_photos['edit'],
248                        'U_HIDE' => $admin_base_url . '&amp;hide=' . $info_photos['id_prop_pho'],
249                        'U_SHOW' => $admin_base_url . '&amp;show=' . $info_photos['id_prop_pho'],
250                    );
251                }else{
252                    $items = array(
253                        'IDINFOPHO' => $info_photos['id_prop_pho'],
254                        'AIPWORDING' => trigger_change('AP_render_content',$info_photos['wording']),
255                        'AIPWORDING2' => $info_photos['wording'],
256                        'AIPORDER' => $info_photos['orderprop'],
257                        'AIPACTIVE' => $info_photos['active'],
258                        'AIPEDIT' => $info_photos['edit'],
259                        'U_DELETE' => $admin_base_url . '&amp;delete=' . $info_photos['id_prop_pho'],
260                        'U_HIDE' => $admin_base_url . '&amp;hide=' . $info_photos['id_prop_pho'],
261                        'U_SHOW' => $admin_base_url . '&amp;show=' . $info_photos['id_prop_pho'],
262                    );
263                }       
264                $template->append('info_photos', $items);
265            }
266        }
267       
268        if (isset($_POST['submitManualOrderInfo'])){
269           
270            asort($_POST['infoOrd'], SORT_NUMERIC);
271           
272            $data = array();
273            foreach ($_POST['infoOrd'] as $id =>$val){
274           
275            $data[] = array('id_prop_pho' => $id, 'orderprop' => $val+1);
276            }
277            $fields = array('primary' => array('id_prop_pho'), 'update' => array('orderprop'));
278            mass_updates(ADD_PROP_PHOTO_TABLE, $fields, $data);
279
280          $page['infos'][] = l10n('Properties manual order was saved');
281          redirect($admin_base_url);
282        }
283
284        if (isset($_POST['submitaddAIP'])) {
285            if (!isset($_POST['inseractive'])) {
286                $_POST['inseractive'] = 0;
287            }
288            if ($_POST['invisibleID'] == 0) {
289                $result = pwg_query('SELECT MAX(orderprop) FROM '. ADD_PROP_PHOTO_TABLE );
290                $row = pwg_db_fetch_assoc($result);
291                $or = ($row['MAX(orderprop)'] + 1);
292
293                $q = '
294                INSERT INTO ' . $prefixeTable . 'add_properties_photos(wording,orderprop,active,edit)VALUES ("' . $_POST['inserwording'] . '","' . $or . '","' . $_POST['inseractive'] . '",1);';
295                pwg_query($q);
296                $_SESSION['page_infos'] = array(l10n('Property photo add'));
297            } else {
298                $q = '
299                UPDATE ' . $prefixeTable . 'add_properties_photos'
300                        . ' set wording ="' . $_POST['inserwording'] . '" '
301                        . ' ,active=' . $_POST['inseractive']
302                        . ' WHERE id_prop_pho=' . $_POST['invisibleID'] . ';';
303                pwg_query($q);
304                $_SESSION['page_infos'] = array(l10n('Property photo update'));
305            }
306            redirect($admin_base_url);
307        }
308
309        if (isset($_GET['delete'])) {
310            check_input_parameter('delete', $_GET, false, PATTERN_ID);
311            $query = 'DELETE FROM ' . ADD_PROP_PHOTO_TABLE . ' WHERE id_prop_pho = ' . $_GET['delete'] . ';';
312            pwg_query($query);
313            $query = 'DELETE FROM ' . ADD_PROP_PHOTO_DATA_TABLE . ' WHERE id_prop_pho = ' . $_GET['delete'] . ';';
314            pwg_query($query);
315
316            $_SESSION['page_infos'] = array(l10n('Property delete'));
317            redirect($admin_base_url);
318        }
319       
320        if (isset($_GET['hide'])) {
321            check_input_parameter('hide', $_GET, false, PATTERN_ID);
322            $query = 'UPDATE ' . ADD_PROP_PHOTO_TABLE . ' SET active = 1 WHERE id_prop_pho=' . $_GET['hide'] . ';';
323            pwg_query($query);
324        }
325       
326        if (isset($_GET['show'])) {
327            check_input_parameter('show', $_GET, false, PATTERN_ID);
328            $query = 'UPDATE ' . ADD_PROP_PHOTO_TABLE . ' SET active = 0 WHERE id_prop_pho=' . $_GET['show'] . ';';
329            pwg_query($query);
330        }
331
332        break;
333 }
334
335
336$template->set_filenames(array('plugin_admin_content' => dirname(__FILE__) . '/admin/admin.tpl'));
337$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
338?>
Note: See TracBrowser for help on using the repository browser.