source: extensions/manage_properties_photos/admin.php @ 32151

Last change on this file since 32151 was 32151, checked in by ddtddt, 4 years ago

[manage_properties_photos]

File size: 19.9 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Manage Properties Photos plugin for Piwigo by TEMMII                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2007-2020 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
35
36$template->assign(array(
37  'ADD_PROP_PHOTO_PATH'=> get_root_url() . ADD_PROP_PHOTO_PATH,
38  ));
39
40
41if (!isset($_GET['tab']))
42    $page['tab'] = 'define_properties';
43else
44    $page['tab'] = $_GET['tab'];
45
46
47if ($page['tab'] != 'iap') {
48    $tabsheet = new tabsheet();
49    $tabsheet->add('addip', l10n('Property'), ADD_PROP_PHOTO_ADMIN . '-define_properties');
50        $tabsheet->add('config', l10n('Configuration'), ADD_PROP_PHOTO_ADMIN . '-config');
51    $tabsheet->select($page['tab']);
52    $tabsheet->assign();
53} else if ($_GET['tab'] == 'iap') {
54
55    $page['active_menu'] = get_active_menu('photo'); // force oppening "Photos" menu block
56
57    /* Basic checks */
58    check_status(ACCESS_ADMINISTRATOR);
59
60    check_input_parameter('image_id', $_GET, false, PATTERN_ID);
61    $id_img = $_GET['image_id'];
62    $admin_photo_base_url = get_root_url() . 'admin.php?page=photo-' . $_GET['image_id'];
63
64    $page['tab'] = 'iap';
65
66    $tabsheet = new tabsheet();
67    $tabsheet->set_id('photo');
68    $tabsheet->select('iap');
69    $tabsheet->assign();
70
71    $template->assign(
72            'gestionD', array(
73        'A' => 'a'
74    ));
75   
76        if (isset($pwg_loaded_plugins['ExtendedDescription'])){
77        add_event_handler('AP_render_content', 'get_user_language_desc');
78                $template->assign('useED',1);
79    }else{
80        $template->assign('useED',0);
81    }
82
83    $tab_add_info_one_photo = tab_add_info_by_photo($_GET['image_id']);
84    if (pwg_db_num_rows($tab_add_info_one_photo)) {
85        while ($info_photos = pwg_db_fetch_assoc($tab_add_info_one_photo)) {
86                        if($info_photos['Typ']==2){
87                                $d = data_info_photosdate($id_img, $info_photos['id_prop_pho']);
88                                $row = pwg_db_fetch_assoc($d);
89
90                                $items = array(
91                                        'IDPHO' => $_GET['image_id'],
92                                        'IDINFOPHO' => $info_photos['id_prop_pho'],
93                                        'AIPWORDING' => trigger_change('AP_render_content',$info_photos['wording']),
94                                        'AIPDATA' => $row['datadate'],
95                                        'AIPTYP' => $info_photos['Typ'],
96                                );
97                                if($info_photos['wording']=="**delpho**"){
98                                        $items['AIPWORDING'] =l10n('Delete photo');
99                                }
100                        }else{
101                                $d = data_info_photos($id_img, $info_photos['id_prop_pho']);
102                                $row = pwg_db_fetch_assoc($d);
103
104                                $items = array(
105                                        'IDPHO' => $_GET['image_id'],
106                                        'IDINFOPHO' => $info_photos['id_prop_pho'],
107                                        'AIPWORDING' => trigger_change('AP_render_content',$info_photos['wording']),
108                                        'AIPDATA' => $row['data'],
109                                        'AIPTYP' => $info_photos['Typ'],
110                                );
111                                if($info_photos['Typ']==4||$info_photos['Typ']==5){
112                                        $items['AIPSELECT']=unserialize($info_photos['dataprop']);
113                                        foreach ($items['AIPSELECT'] as $key => $dataselect){
114                                                $items['AIPSELECTTRANS'][] = trigger_change('AP_render_content',$dataselect);
115                                        }
116                                }
117                        }
118            $template->append('info_photos', $items);
119        }
120    }
121
122    if (isset($_POST['submitaddinfoimg'])) {
123        foreach ($_POST['data'] AS $id_prop_pho => $data) {
124            $q = 'SELECT 1 FROM ' . ADD_PROP_PHOTO_DATA_TABLE . ' WHERE id_img=' . $id_img . ' AND id_prop_pho=' . $id_prop_pho;
125            $test = pwg_query($q);
126            $row = pwg_db_fetch_assoc($test);
127            if (count($row) > 0) {
128                if ($data != '') {
129                    $query = 'UPDATE ' . $prefixeTable . 'add_properties_photos_data SET data="' . $data . '" WHERE id_img=' . $id_img . ' AND id_prop_pho=' . $id_prop_pho;
130                    pwg_query($query);
131                } else {
132                    $query = 'DELETE FROM ' . $prefixeTable . 'add_properties_photos_data WHERE id_img=' . $id_img . ' AND id_prop_pho=' . $id_prop_pho;
133                    pwg_query($query);
134                }
135            } else if ($data != '') {
136                $query = 'INSERT ' . $prefixeTable . 'add_properties_photos_data(id_img,id_prop_pho,data) VALUES (' . $id_img . ',' . $id_prop_pho . ',"' . $data . '");';
137                pwg_query($query);
138            }   
139        }
140                        foreach ($_POST['datadate'] AS $id_prop_pho => $data) {
141            $q = 'SELECT 1 FROM ' . ADD_PROP_PHOTO_DATADATE_TABLE . ' WHERE id_img=' . $id_img . ' AND id_prop_pho=' . $id_prop_pho;
142            $test = pwg_query($q);
143            $row = pwg_db_fetch_assoc($test);
144            if (count($row) > 0) {
145                if ($data != '') {
146                    $query = 'UPDATE ' . $prefixeTable . 'add_properties_photos_datadate SET datadate="' . $data . '" WHERE id_img=' . $id_img . ' AND id_prop_pho=' . $id_prop_pho;
147                    pwg_query($query);
148                } else {
149                    $query = 'DELETE FROM ' . $prefixeTable . 'add_properties_photos_datadate WHERE id_img=' . $id_img . ' AND id_prop_pho=' . $id_prop_pho;
150                    pwg_query($query);
151                }
152            } else if ($data != '') {
153                $query = 'INSERT ' . $prefixeTable . 'add_properties_photos_datadate(id_img,id_prop_pho,datadate) VALUES (' . $id_img . ',' . $id_prop_pho . ',"' . $data . '");';
154                pwg_query($query);
155            }   
156        }
157        $redirect_url = ADD_PROP_PHOTO_ADMIN . '-iap&amp;image_id=' . $id_img;
158        $_SESSION['page_infos'] = array(l10n('Properties update'));
159        redirect($redirect_url);
160    }
161}
162
163switch ($page['tab']) {
164    case 'define_properties':
165        $admin_base_url = ADD_PROP_PHOTO_ADMIN . '-define_properties';
166        $template->assign(
167            'addinfotemplate', array(
168                                'addinfo' => l10n('addinfo'),
169                ));
170                $maxfields = (isset($conf['mpp_max_fields'])) ? $conf['mpp_max_fields'] : '5';
171        $template->assign('MPPMAXFIELD',$maxfields);
172               
173    if (isset($pwg_loaded_plugins['ExtendedDescription'])){
174        add_event_handler('AP_render_content', 'get_user_language_desc');
175                $template->assign('useED',1);
176    }else{
177        $template->assign('useED',0);
178    }
179       
180        $admin_base_url = ADD_PROP_PHOTO_ADMIN . '-define_properties';
181        $tab_info_photos = tab_info_photos();
182
183        if (pwg_db_num_rows($tab_info_photos)) {
184            while ($info_photos = pwg_db_fetch_assoc($tab_info_photos)) {
185                                $items = array(
186                    'IDINFOPHO' => $info_photos['id_prop_pho'],
187                    'AIPORDER' => $info_photos['orderprop'],
188                    'AIPACTIVE' => $info_photos['active'],
189                    'AIPEDIT' => $info_photos['edit'],
190                    'U_HIDE' => $admin_base_url . '&amp;hide=' . $info_photos['id_prop_pho'],
191                    'U_SHOW' => $admin_base_url . '&amp;show=' . $info_photos['id_prop_pho']
192                                );
193                if($info_photos['id_prop_pho']==1){
194                                    $items['AIPWORDING'] = l10n('Author');
195                }else if($info_photos['id_prop_pho']==2){
196                                        $items['AIPWORDING'] = l10n('Created on');
197                }else if($info_photos['id_prop_pho']==3){
198                    $items['AIPWORDING'] = l10n('Posted on');
199                }else if($info_photos['id_prop_pho']==4){
200                    $items['AIPWORDING'] = l10n('Dimensions');
201                }else if($info_photos['id_prop_pho']==5){
202                    $items['AIPWORDING'] = l10n('File');
203                }else if($info_photos['id_prop_pho']==6){
204                    $items['AIPWORDING'] = l10n('Filesize');
205                }else if($info_photos['id_prop_pho']==7){
206                    $items['AIPWORDING'] = l10n('Tags');
207                }else if($info_photos['id_prop_pho']==8){
208                    $items['AIPWORDING'] = l10n('Albums');
209                }else if($info_photos['id_prop_pho']==9){
210                    $items['AIPWORDING'] = l10n('Visits');
211                }else if($info_photos['id_prop_pho']==10){
212                                        $items['AIPWORDING'] = l10n('Average');
213                }else if($info_photos['id_prop_pho']==11){
214                    $items['AIPWORDING'] = l10n('Who can see this photo?');
215                }else{
216                                        if($info_photos['dataprop']=="DeletePhoto" and $info_photos['wording'] ="**delpho**"){
217                                                $items['AIPWORDING'] = l10n('Delete photo');
218                                        }else{
219                                                $items['AIPWORDING'] = trigger_change('AP_render_content',$info_photos['wording']);     
220                                        }
221                    $items['AIPWORDING2'] =  $info_photos['wording'];
222                                        $items['U_DELETE'] =  $admin_base_url . '&amp;delete=' . $info_photos['id_prop_pho'];
223                                        $items['AIPTYP'] =  $info_photos['Typ'];
224                                        if($info_photos['Typ']==4||$info_photos['Typ']==5){
225                                                        $items['AIPDATAPROP'] =  json_encode(unserialize($info_photos['dataprop']));
226                                        }
227                                        if($info_photos['Typ']==3||$info_photos['Typ']==6){
228                                                        $items['AIPDATAPROP'] =  $info_photos['dataprop'];
229                                        }                                       
230                }       
231                $template->append('info_photos', $items);
232            }
233                       
234                        $idexifone = pwg_db_fetch_assoc(pwg_query("SELECT MIN(id) as id FROM " . IMAGES_TABLE .";"));
235                        $idexif = (isset($conf['mpp_idexif'])) ? $conf['mpp_idexif'] : $idexifone['id'];
236                        $filename = pwg_db_fetch_assoc(pwg_query("SELECT path FROM " . IMAGES_TABLE . " WHERE id = '".$idexif."';"));
237                  if(empty($filename['path'])){
238                          $_SESSION['page_errors'] = array(l10n('reference photo id doesn\'t exist please update'));
239                  }else if(exif_imagetype($filename['path']) != IMAGETYPE_JPEG and exif_imagetype($filename['path']) != IMAGETYPE_TIFF_II and exif_imagetype($filename['path']) != IMAGETYPE_TIFF_MM){
240                          $_SESSION['page_errors'] = array(l10n('reference photo type doesn\'t use metadata please update')); 
241                  }else{       
242                        $exif = exif_read_data($filename['path']);
243                                foreach ($exif as $key => $section){
244                                        if(is_array($section)){
245                                                $i=0;
246                                        foreach ($section as $name => $value){
247                                                if($i==0){
248                                                        $items['RM_AFF'] = $key;
249                                                }else{
250                                                        $items['RM_AFF'] = '';
251                                                }
252                                                $items['RM_SECTION'] = $key;
253                                                $items['RM_KEY'] = $name;
254                                                $template->append('rm_exif', $items);
255                                                $i++;
256                                        }
257                                }else{
258                                        $items['RM_SECTION'] = '1';
259                                        $items['RM_KEY'] = $key;
260                                        $items['RM_VALUE'] = $section;
261                                        $template->append('rm_exif', $items);
262                                }
263                        }
264                        $iptc_result = array();
265                        $imginfo = array();
266                        getimagesize($filename['path'], $imginfo);
267                        if (isset ($imginfo['APP13'])){
268                         $iptc = iptcparse($imginfo['APP13']);
269                          if (is_array($iptc)){
270                                foreach (array_keys($iptc) as $iptc_key){
271                                        if (isset($iptc[$iptc_key][0])){
272                                                $iptc_result[$iptc_key] = $value;
273                                        }
274                                }
275                          }
276                          $keys = array_keys($iptc_result);
277                          sort($keys);
278                          foreach ($keys as $key){
279                                $items['RM_KEY'] = $key;
280                                $template->append('rm_iptc', $items);
281                          }
282                        }
283                  }
284        }
285       
286        if (isset($_POST['submitManualOrderInfo'])){
287           
288            asort($_POST['infoOrd'], SORT_NUMERIC);
289           
290            $data = array();
291            foreach ($_POST['infoOrd'] as $id =>$val){
292           
293            $data[] = array('id_prop_pho' => $id, 'orderprop' => $val+1);
294            }
295            $fields = array('primary' => array('id_prop_pho'), 'update' => array('orderprop'));
296            mass_updates(ADD_PROP_PHOTO_TABLE, $fields, $data);
297
298          $page['infos'][] = l10n('Properties manual order was saved');
299          redirect($admin_base_url);
300        }
301
302        if (isset($_POST['submitaddAIP'])) {
303                        if ($_POST['inserwording'] == '') {
304                        $_SESSION['page_errors'] = array(l10n('Wording isn\'t empty'));
305                        redirect($admin_base_url);
306                        }
307                        if ($_POST['typ'] == '4'||$_POST['typ'] == '5') {
308                        $select= serialize($_POST['mytext']);
309                        }
310                        if ($_POST['typ'] == '3') {
311                                if($_POST['selectexif']==''){
312                                        $_SESSION['page_errors'] = array(l10n('exif field can\'t be empty'));
313                                        redirect($admin_base_url);
314                                }
315                        $select= $_POST['selectexif'];
316                        }
317                        if ($_POST['typ'] == '6') {
318                                if($_POST['selectiptc']==''){
319                                        $_SESSION['page_errors'] = array(l10n('IPTC field can\'t be empty'));
320                                        redirect($admin_base_url);
321                                }
322                        $select= $_POST['selectiptc'];
323                        }
324            if (!isset($_POST['inseractive'])) {
325                $_POST['inseractive'] = 0;
326            }
327            if ($_POST['invisibleID'] == 0) {
328                $result = pwg_query('SELECT MAX(orderprop) FROM '. ADD_PROP_PHOTO_TABLE );
329                $row = pwg_db_fetch_assoc($result);
330                $or = ($row['MAX(orderprop)'] + 1);
331                                        if ($_POST['typ'] == '4'||$_POST['typ'] == '3'||$_POST['typ'] == '5'||$_POST['typ'] == '6') {
332                                                $q = 'INSERT INTO ' . $prefixeTable . 'add_properties_photos(wording,orderprop,active,edit,Typ,dataprop)VALUES ("' . $_POST['inserwording'] . '","' . $or . '","' . $_POST['inseractive'] . '",1,"' . $_POST['typ'] . '",\''. $select .'\');';
333                                                pwg_query($q);
334                                        }else{
335                                                $q = 'INSERT INTO ' . $prefixeTable . 'add_properties_photos(wording,orderprop,active,edit,Typ)VALUES ("' . $_POST['inserwording'] . '","' . $or . '","' . $_POST['inseractive'] . '",1,"' . $_POST['typ'] . '");';
336                                                pwg_query($q);
337                                        }
338                $_SESSION['page_infos'] = array(l10n('Property photo add'));
339            } else {
340                                        if ($_POST['typ'] == '4'||$_POST['typ'] == '3'||$_POST['typ'] == '5'||$_POST['typ'] == '6') {
341                                          $q = '
342                                          UPDATE ' . $prefixeTable . 'add_properties_photos'
343                        . ' set wording ="' . $_POST['inserwording'] . '" '
344                        . ' ,active =' . $_POST['inseractive']
345                                                . ' ,Typ =' . $_POST['typ']
346                                                . ' ,dataprop =\'' . $select . '\' '
347                        . ' WHERE id_prop_pho=' . $_POST['invisibleID'] . ';';
348                                        }else{
349                                          $q = '
350                                          UPDATE ' . $prefixeTable . 'add_properties_photos'
351                        . ' set wording ="' . $_POST['inserwording'] . '" '
352                        . ' ,active=' . $_POST['inseractive']
353                                                . ' ,Typ =' . $_POST['typ']
354                        . ' WHERE id_prop_pho=' . $_POST['invisibleID'] . ';';
355                                        }
356                pwg_query($q);
357                $_SESSION['page_infos'] = array(l10n('Property photo update'));
358            }
359            redirect($admin_base_url);
360        }
361
362        if (isset($_GET['delete'])) {
363            check_input_parameter('delete', $_GET, false, PATTERN_ID);
364            $query = 'DELETE FROM ' . ADD_PROP_PHOTO_TABLE . ' WHERE id_prop_pho = ' . $_GET['delete'] . ';';
365            pwg_query($query);
366            $query = 'DELETE FROM ' . ADD_PROP_PHOTO_DATA_TABLE . ' WHERE id_prop_pho = ' . $_GET['delete'] . ';';
367            pwg_query($query);
368                        $query = 'DELETE FROM ' . ADD_PROP_PHOTO_DATADATE_TABLE . ' WHERE id_prop_pho = ' . $_GET['delete'] . ';';
369            pwg_query($query);
370
371            $_SESSION['page_infos'] = array(l10n('Property delete'));
372            redirect($admin_base_url);
373        }
374       
375        if (isset($_GET['hide'])) {
376            check_input_parameter('hide', $_GET, false, PATTERN_ID);
377            $query = 'UPDATE ' . ADD_PROP_PHOTO_TABLE . ' SET active = 1 WHERE id_prop_pho=' . $_GET['hide'] . ';';
378            pwg_query($query);
379        }
380       
381        if (isset($_GET['show'])) {
382            check_input_parameter('show', $_GET, false, PATTERN_ID);
383            $query = 'UPDATE ' . ADD_PROP_PHOTO_TABLE . ' SET active = 0 WHERE id_prop_pho=' . $_GET['show'] . ';';
384            pwg_query($query);
385        }
386
387        break;
388                case 'config':
389                $maxfields = (isset($conf['mpp_max_fields'])) ? $conf['mpp_max_fields'] : '5';
390        $template->assign('MPPMAXFIELD',$maxfields);
391                $idexif = (isset($conf['mpp_idexif'])) ? $conf['mpp_idexif'] : '';
392        $template->assign('MPPIDEXIF',$idexif);
393        $admin_base_url = ADD_PROP_PHOTO_ADMIN . '-config';
394                        $template->assign(
395                                'mppconfig', array(
396                                        'a' => 'a',
397                        ));
398                               
399                $delpho = pwg_db_fetch_assoc(pwg_query('SELECT dataprop FROM ' . ADD_PROP_PHOTO_TABLE.' WHERE dataprop="DeletePhoto";'));
400                if(empty($delpho)){
401                        $template->assign(
402                                'mppconfig', array(
403                                        'ADDPHOAC' => 'actiondelphoadd',
404                        ));
405                }
406                if (isset($_POST['submitadddelpho'])){
407                        $result = pwg_query('SELECT MAX(orderprop) FROM '. ADD_PROP_PHOTO_TABLE );
408                        $row = pwg_db_fetch_assoc($result);
409                        $or = ($row['MAX(orderprop)'] + 1);
410                        $q = 'INSERT INTO ' . $prefixeTable . 'add_properties_photos(wording,orderprop,active,edit,Typ,dataprop)VALUES ("**delpho**","' . $or . '","1",1,"2","DeletePhoto");';
411                        pwg_query($q);
412                        $_SESSION['page_infos'] = array(l10n('Information data registered in database'));
413                        redirect(ADD_PROP_PHOTO_ADMIN . '-config');
414                }
415                if (isset($_POST['submitremovedelpho'])){
416                        $iddelpho = pwg_db_fetch_assoc(pwg_query('SELECT id_prop_pho FROM '. ADD_PROP_PHOTO_TABLE.' where dataprop="DeletePhoto";'));
417                        pwg_query('DELETE FROM ' . ADD_PROP_PHOTO_TABLE . ' where dataprop ="DeletePhoto";');
418                        $query = 'DELETE FROM ' . ADD_PROP_PHOTO_DATADATE_TABLE . ' WHERE id_prop_pho = ' . $iddelpho['id_prop_pho'] . ';';
419            pwg_query($query);
420                        $_SESSION['page_infos'] = array(l10n('Information data registered in database'));
421                        redirect(ADD_PROP_PHOTO_ADMIN . '-config');
422                }
423                $descpho = pwg_db_fetch_assoc(pwg_query('SELECT dataprop FROM ' . ADD_PROP_PHOTO_TABLE.' WHERE dataprop="movedescription";'));
424                if(empty($descpho)){
425                        $vars['MOVEDESC']='actionmovedesc';
426                        $template->append('mppconfig', $vars, true);
427                }
428                if (isset($_POST['submitmovedesc'])){
429                        $result = pwg_query('SELECT MAX(orderprop) FROM '. ADD_PROP_PHOTO_TABLE );
430                        $row = pwg_db_fetch_assoc($result);
431                        $or = ($row['MAX(orderprop)'] + 1);
432                        $q = 'INSERT INTO ' . $prefixeTable . 'add_properties_photos(wording,orderprop,active,edit,Typ,dataprop)VALUES ("Description","' . $or . '","0",0,"1","movedescription");';
433                        pwg_query($q);
434                        $_SESSION['page_infos'] = array(l10n('Information data registered in database'));
435                        redirect(ADD_PROP_PHOTO_ADMIN . '-config');
436                }
437                if (isset($_POST['submitdefaultdesc'])){
438                        pwg_query('DELETE FROM ' . ADD_PROP_PHOTO_TABLE . ' where dataprop ="movedescription";');
439                        $_SESSION['page_infos'] = array(l10n('Information data registered in database'));
440                        redirect(ADD_PROP_PHOTO_ADMIN . '-config');
441                }
442                if (isset($_POST['submitmppoption'])){
443                        conf_update_param('mpp_max_fields', $_POST['mppmaxfield']);
444                        conf_update_param('mpp_idexif', $_POST['mppitidexif']);
445                        $_SESSION['page_infos'] = array(l10n('Information data registered in database'));
446                        redirect(ADD_PROP_PHOTO_ADMIN . '-config');
447                }
448                break;
449 }
450
451
452$template->set_filenames(array('plugin_admin_content' => dirname(__FILE__) . '/admin/admin.tpl'));
453$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
454?>
Note: See TracBrowser for help on using the repository browser.