source: extensions/manage_properties_photos/admin.php @ 32013

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

[extensions] - manage_properties_photos

File size: 16.6 KB
RevLine 
[30631]1<?php
[31409]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// +-----------------------------------------------------------------------+
[30631]21
22if (!defined('PHPWG_ROOT_PATH'))
23    die('Hacking attempt!');
24global $template, $conf, $user;
25include_once(PHPWG_ROOT_PATH . 'admin/include/tabsheet.class.php');
[30702]26load_language('plugin.lang', ADD_PROP_PHOTO_PATH);
[30631]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']))
[30702]36    $page['tab'] = 'define_properties';
[30631]37else
38    $page['tab'] = $_GET['tab'];
39
40
41if ($page['tab'] != 'iap') {
42    $tabsheet = new tabsheet();
[30702]43    $tabsheet->add('addip', l10n('Property'), ADD_PROP_PHOTO_ADMIN . '-define_properties');
[30631]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';"));
[30655]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    }
[30631]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
[30702]81            $d = data_info_photos($id_img, $info_photos['id_prop_pho']);
[30631]82            $row = pwg_db_fetch_assoc($d);
83
84            $items = array(
85                'IDPHO' => $_GET['image_id'],
[30702]86                'IDINFOPHO' => $info_photos['id_prop_pho'],
87                'AIPWORDING' => trigger_change('AP_render_content',$info_photos['wording']),
[30631]88                'AIPDATA' => $row['data'],
89            );
90
91            $template->append('info_photos', $items);
92        }
93    }
94
95    if (isset($_POST['submitaddinfoimg'])) {
[30702]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;
[30631]98            $test = pwg_query($q);
99            $row = pwg_db_fetch_assoc($test);
100            if (count($row) > 0) {
101                if ($data != '') {
[30702]102                    $query = 'UPDATE ' . $prefixeTable . 'add_properties_photos_data SET data="' . $data . '" WHERE id_img=' . $id_img . ' AND id_prop_pho=' . $id_prop_pho;
[30631]103                    pwg_query($query);
104                } else {
[30702]105                    $query = 'DELETE FROM ' . $prefixeTable . 'add_properties_photos_data WHERE id_img=' . $id_img . ' AND id_prop_pho=' . $id_prop_pho;
[30631]106                    pwg_query($query);
107                }
108            } else if ($data != '') {
[30702]109                $query = 'INSERT ' . $prefixeTable . 'add_properties_photos_data(id_img,id_prop_pho,data) VALUES (' . $id_img . ',' . $id_prop_pho . ',"' . $data . '");';
[30631]110                pwg_query($query);
111            }
112           
113        }
[30702]114        $redirect_url = ADD_PROP_PHOTO_ADMIN . '-iap&amp;image_id=' . $id_img;
115        $_SESSION['page_infos'] = array(l10n('Properties update'));
[30631]116        redirect($redirect_url);
117    }
118}
119
120switch ($page['tab']) {
[30702]121    case 'define_properties':
122        $admin_base_url = ADD_PROP_PHOTO_ADMIN . '-define_properties';
[30631]123        $template->assign(
124                'addinfotemplate', array(
125            'addinfo' => l10n('addinfo'),
[30702]126       ));
[30631]127       
128    $PAED = pwg_db_fetch_assoc(pwg_query("SELECT state FROM " . PLUGINS_TABLE . " WHERE id = 'ExtendedDescription';"));
[30655]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    }
[30631]135       
[30702]136        $admin_base_url = ADD_PROP_PHOTO_ADMIN . '-define_properties';
[30631]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)) {
[30702]141                if($info_photos['id_prop_pho']==1){
[30631]142                    $items = array(
[30702]143                        'IDINFOPHO' => $info_photos['id_prop_pho'],
144                        'AIPWORDING' => l10n('Author'),
145                        'AIPORDER' => $info_photos['orderprop'],
[30631]146                        'AIPACTIVE' => $info_photos['active'],
147                        'AIPEDIT' => $info_photos['edit'],
[30702]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'],
[30631]150                    );
[30702]151                }else if($info_photos['id_prop_pho']==2){
[30631]152                    $items = array(
[30702]153                        'IDINFOPHO' => $info_photos['id_prop_pho'],
154                        'AIPWORDING' => l10n('Created on'),
155                        'AIPORDER' => $info_photos['orderprop'],
[30631]156                        'AIPACTIVE' => $info_photos['active'],
157                        'AIPEDIT' => $info_photos['edit'],
[30702]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'],
[30631]160                    );
[30702]161                }else if($info_photos['id_prop_pho']==3){
[30631]162                    $items = array(
[30702]163                        'IDINFOPHO' => $info_photos['id_prop_pho'],
164                        'AIPWORDING' => l10n('Posted on'),
165                        'AIPORDER' => $info_photos['orderprop'],
[30631]166                        'AIPACTIVE' => $info_photos['active'],
167                        'AIPEDIT' => $info_photos['edit'],
[30702]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'],
[30631]170                    );
[30702]171                }else if($info_photos['id_prop_pho']==4){
[30631]172                    $items = array(
[30702]173                        'IDINFOPHO' => $info_photos['id_prop_pho'],
174                        'AIPWORDING' => l10n('Dimensions'),
175                        'AIPORDER' => $info_photos['orderprop'],
[30631]176                        'AIPACTIVE' => $info_photos['active'],
177                        'AIPEDIT' => $info_photos['edit'],
[30702]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'],
[30631]180                    );
[30702]181                }else if($info_photos['id_prop_pho']==5){
[30631]182                    $items = array(
[30702]183                        'IDINFOPHO' => $info_photos['id_prop_pho'],
184                        'AIPWORDING' => l10n('File'),
185                        'AIPORDER' => $info_photos['orderprop'],
[30631]186                        'AIPACTIVE' => $info_photos['active'],
187                        'AIPEDIT' => $info_photos['edit'],
[30702]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'],
[30631]190                    );
[30702]191                }else if($info_photos['id_prop_pho']==6){
[30631]192                    $items = array(
[30702]193                        'IDINFOPHO' => $info_photos['id_prop_pho'],
194                        'AIPWORDING' => l10n('Filesize'),
195                        'AIPORDER' => $info_photos['orderprop'],
[30631]196                        'AIPACTIVE' => $info_photos['active'],
197                        'AIPEDIT' => $info_photos['edit'],
[30702]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'],
[30631]200                    );
[30702]201                }else if($info_photos['id_prop_pho']==7){
[30631]202                    $items = array(
[30702]203                        'IDINFOPHO' => $info_photos['id_prop_pho'],
204                        'AIPWORDING' => l10n('Tags'),
205                        'AIPORDER' => $info_photos['orderprop'],
[30631]206                        'AIPACTIVE' => $info_photos['active'],
207                        'AIPEDIT' => $info_photos['edit'],
[30702]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'],
[30631]210                    );
[30702]211                }else if($info_photos['id_prop_pho']==8){
[30631]212                    $items = array(
[30702]213                        'IDINFOPHO' => $info_photos['id_prop_pho'],
214                        'AIPWORDING' => l10n('Albums'),
215                        'AIPORDER' => $info_photos['orderprop'],
[30631]216                        'AIPACTIVE' => $info_photos['active'],
217                        'AIPEDIT' => $info_photos['edit'],
[30702]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'],
[30631]220                    );
[30702]221                }else if($info_photos['id_prop_pho']==9){
[30631]222                    $items = array(
[30702]223                        'IDINFOPHO' => $info_photos['id_prop_pho'],
224                        'AIPWORDING' => l10n('Visits'),
225                        'AIPORDER' => $info_photos['orderprop'],
[30631]226                        'AIPACTIVE' => $info_photos['active'],
227                        'AIPEDIT' => $info_photos['edit'],
[30702]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'],
[30631]230                    );
[30702]231                }else if($info_photos['id_prop_pho']==10){
[30631]232                    $items = array(
[30702]233                        'IDINFOPHO' => $info_photos['id_prop_pho'],
234                        'AIPWORDING' => l10n('Average'),
235                        'AIPORDER' => $info_photos['orderprop'],
[30631]236                        'AIPACTIVE' => $info_photos['active'],
237                        'AIPEDIT' => $info_photos['edit'],
[30702]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'],
[30631]240                    );
[30702]241                }else if($info_photos['id_prop_pho']==11){
[30631]242                    $items = array(
[30702]243                        'IDINFOPHO' => $info_photos['id_prop_pho'],
244                        'AIPWORDING' => l10n('Who can see this photo?'),
245                        'AIPORDER' => $info_photos['orderprop'],
[30631]246                        'AIPACTIVE' => $info_photos['active'],
247                        'AIPEDIT' => $info_photos['edit'],
[30702]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'],
[30631]250                    );
251                }else{
252                    $items = array(
[30702]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'],
[30631]257                        'AIPACTIVE' => $info_photos['active'],
258                        'AIPEDIT' => $info_photos['edit'],
[30702]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'],
[30631]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           
[30702]275            $data[] = array('id_prop_pho' => $id, 'orderprop' => $val+1);
[30631]276            }
[30702]277            $fields = array('primary' => array('id_prop_pho'), 'update' => array('orderprop'));
278            mass_updates(ADD_PROP_PHOTO_TABLE, $fields, $data);
[30631]279
[30702]280          $page['infos'][] = l10n('Properties manual order was saved');
[30631]281          redirect($admin_base_url);
282        }
[30654]283
[30631]284        if (isset($_POST['submitaddAIP'])) {
285            if (!isset($_POST['inseractive'])) {
286                $_POST['inseractive'] = 0;
287            }
288            if ($_POST['invisibleID'] == 0) {
[30702]289                $result = pwg_query('SELECT MAX(orderprop) FROM '. ADD_PROP_PHOTO_TABLE );
[30631]290                $row = pwg_db_fetch_assoc($result);
[30702]291                $or = ($row['MAX(orderprop)'] + 1);
[30631]292
293                $q = '
[30702]294                INSERT INTO ' . $prefixeTable . 'add_properties_photos(wording,orderprop,active,edit)VALUES ("' . $_POST['inserwording'] . '","' . $or . '","' . $_POST['inseractive'] . '",1);';
[30631]295                pwg_query($q);
[30702]296                $_SESSION['page_infos'] = array(l10n('Property photo add'));
[30631]297            } else {
298                $q = '
[30702]299                UPDATE ' . $prefixeTable . 'add_properties_photos'
300                        . ' set wording ="' . $_POST['inserwording'] . '" '
[30631]301                        . ' ,active=' . $_POST['inseractive']
[30702]302                        . ' WHERE id_prop_pho=' . $_POST['invisibleID'] . ';';
[30631]303                pwg_query($q);
[30702]304                $_SESSION['page_infos'] = array(l10n('Property photo update'));
[30631]305            }
306            redirect($admin_base_url);
307        }
308
309        if (isset($_GET['delete'])) {
310            check_input_parameter('delete', $_GET, false, PATTERN_ID);
[30702]311            $query = 'DELETE FROM ' . ADD_PROP_PHOTO_TABLE . ' WHERE id_prop_pho = ' . $_GET['delete'] . ';';
[30631]312            pwg_query($query);
[30702]313            $query = 'DELETE FROM ' . ADD_PROP_PHOTO_DATA_TABLE . ' WHERE id_prop_pho = ' . $_GET['delete'] . ';';
[30639]314            pwg_query($query);
[30631]315
[30702]316            $_SESSION['page_infos'] = array(l10n('Property delete'));
[30631]317            redirect($admin_base_url);
318        }
319       
320        if (isset($_GET['hide'])) {
321            check_input_parameter('hide', $_GET, false, PATTERN_ID);
[30702]322            $query = 'UPDATE ' . ADD_PROP_PHOTO_TABLE . ' SET active = 1 WHERE id_prop_pho=' . $_GET['hide'] . ';';
[30631]323            pwg_query($query);
324        }
325       
326        if (isset($_GET['show'])) {
327            check_input_parameter('show', $_GET, false, PATTERN_ID);
[30702]328            $query = 'UPDATE ' . ADD_PROP_PHOTO_TABLE . ' SET active = 0 WHERE id_prop_pho=' . $_GET['show'] . ';';
[30631]329            pwg_query($query);
330        }
331
332        break;
[30702]333 }
[30631]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.