source: extensions/user_custom_fields/admin.php @ 31928

Last change on this file since 31928 was 31846, checked in by ddtddt, 7 years ago

[extensions] - user_custom_fields -

File size: 15.2 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | User Custom Fields plugin for Piwigo                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2016-2017 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, $prefixeTable;
25include_once(PHPWG_ROOT_PATH . 'admin/include/tabsheet.class.php');
26$my_base_url = get_admin_plugin_menu_link(__FILE__);
27
28// +-----------------------------------------------------------------------+
29// | Check Access and exit when user status is not ok                      |
30// +-----------------------------------------------------------------------+
31check_status(ACCESS_ADMINISTRATOR);
32
33//-------------------------------------------------------- sections definitions
34if (!isset($_GET['tab']))
35  $page['tab'] = 'define_custom';
36else
37  $page['tab'] = $_GET['tab'];
38  $tabsheet = new tabsheet();
39  $tabsheet->add('ucf', l10n('User custom fields'), UCF_ADMIN . '-define_custom');
40  if (isset($_GET['ucfiduser'])) {
41    $tabsheet->add('edit_user', l10n('User').' '.$_GET['ucfusername'], UCF_ADMIN . '-edit_user');
42  }
43  $tabsheet->select($page['tab']);
44  $tabsheet->assign();
45
46switch ($page['tab']) {
47  case 'define_custom':
48        $admin_base_url = UCF_ADMIN . '-define_custom';
49        $template->assign(
50                'addinfotemplate', array(
51                'toto' => l10n('toto'),
52        ));
53       
54    $PAED = pwg_db_fetch_assoc(pwg_query("SELECT state FROM " . PLUGINS_TABLE . " WHERE id = 'ExtendedDescription';"));
55    if($PAED['state'] == 'active'){
56      add_event_handler('AP_render_content', 'get_user_language_desc');
57      $template->assign('useED',1);
58    }else{
59      $template->assign('useED',0);
60    }
61       
62    $tab_user_custom_fields = tab_user_custom_fields();
63
64        if (pwg_db_num_rows($tab_user_custom_fields)) {
65            while ($user_custom_fields = pwg_db_fetch_assoc($tab_user_custom_fields)) {
66                    $items = array(
67                        'IDUCF' => $user_custom_fields['id_ucf'],
68                        'UCFORDER' => $user_custom_fields['order_ucf'],
69                        'UCFACTIVE' => $user_custom_fields['active'],
70                        'UCFEDIT' => $user_custom_fields['edit'],
71                                                'UCFADMINONLY' => $user_custom_fields['adminonly'],
72                                                'UCFOBLIGATORY' => $user_custom_fields['obligatory'],
73                                                'U_DELETE' => $admin_base_url . '&amp;delete=' . $user_custom_fields['id_ucf'],
74                        'U_HIDE' => $admin_base_url . '&amp;hide=' . $user_custom_fields['id_ucf'],
75                        'U_SHOW' => $admin_base_url . '&amp;show=' . $user_custom_fields['id_ucf'],
76                                                'U_ADMINONLYHIDE' => $admin_base_url . '&amp;adminonlyh=' . $user_custom_fields['id_ucf'],
77                        'U_ADMINONLYSHOW' => $admin_base_url . '&amp;adminonlys=' . $user_custom_fields['id_ucf'],
78                                                'U_OBLIGATORYHIDE' => $admin_base_url . '&amp;obligatoryh=' . $user_custom_fields['id_ucf'],
79                        'U_OBLIGATORYSHOW' => $admin_base_url . '&amp;obligatorys=' . $user_custom_fields['id_ucf'],
80                    );
81                if($user_custom_fields['id_ucf']==1){
82                    $items['UCFWORDING'] = l10n('Username');
83                                        $items['UCFOBLO'] = 0;
84                }else if($user_custom_fields['id_ucf']==2){
85                                    $items['UCFWORDING'] = l10n('Password');
86                                        $items['UCFOBLO'] = 0;
87                }else if($user_custom_fields['id_ucf']==3){
88                                    $items['UCFWORDING'] = l10n('Email address');
89                                        $items['UCFOBLO'] = 1;
90                                }else if($user_custom_fields['id_ucf']==4){
91                                    $items['UCFWORDING'] = l10n('Send my connection settings by email');
92                                        $items['UCFOBLO'] = 1;
93                }else{
94                                    $items['UCFWORDING'] = trigger_change('AP_render_content',$user_custom_fields['wording']);
95                                        $items['UCFWORDING2'] = $user_custom_fields['wording'];
96                                        $items['UCFOBLO'] = 1;
97                }       
98                $template->append('user_custom_fields', $items);
99            }
100        }
101       
102        if (isset($_POST['submitManualOrderInfo'])){
103           
104            asort($_POST['infoOrd'], SORT_NUMERIC);
105           
106            $data = array();
107            foreach ($_POST['infoOrd'] as $id =>$val){
108           
109            $data[] = array('id_ucf' => $id, 'order_ucf' => $val+1);
110            }
111            $fields = array('primary' => array('id_ucf'), 'update' => array('order_ucf'));
112            mass_updates(UCF_TABLE, $fields, $data);
113
114          $page['infos'][] = l10n('Custom fields manual order was saved');
115          redirect($admin_base_url);
116        }
117
118        if (isset($_POST['submitUCF'])) {
119            if(!isset($_POST['inseractive'])){
120                $active = 1;
121            }else{
122                            $active = 0;
123                        }
124                        if(!isset($_POST['adminonly'])){
125                $adminonly = 0;
126            }else{
127                            $adminonly = 1;
128                        }
129                        if(!isset($_POST['obligatory'])){
130                $obligatory = 0;
131            }else{
132                            $obligatory = 1;
133                        }
134            if ($_POST['invisibleID'] == 0) {
135                $result = pwg_query('SELECT MAX(order_ucf) FROM '. UCF_TABLE );
136                $row = pwg_db_fetch_assoc($result);
137                $or = ($row['MAX(order_ucf)'] + 1);
138
139                $q = '
140                INSERT INTO ' . $prefixeTable . 'user_custom_fields(wording,order_ucf,active,edit,adminonly,obligatory)VALUES ("' . $_POST['inserwording'] . '","' . $or . '","' . $active . '",1,'.$adminonly.','.$obligatory.');';
141                pwg_query($q);
142                $_SESSION['page_infos'] = array(l10n('Custom fields add'));
143            } else {
144                $q = '
145                UPDATE ' . $prefixeTable . 'user_custom_fields'
146                        . ' set wording ="' . $_POST['inserwording'] . '" '
147                        . ' ,active=' . $active
148                                                . ' ,adminonly=' . $adminonly
149                                                . ' ,obligatory=' . $obligatory
150                        . ' WHERE id_ucf=' . $_POST['invisibleID'] . ';';
151                pwg_query($q);
152                $_SESSION['page_infos'] = array(l10n('Custom fields update'));
153            }
154            redirect($admin_base_url);
155        }
156
157        if (isset($_GET['delete'])) {
158            check_input_parameter('delete', $_GET, false, PATTERN_ID);
159            $query = 'DELETE FROM ' . UCF_TABLE . ' WHERE id_ucf = ' . $_GET['delete'] . ';';
160            pwg_query($query);
161            $query = 'DELETE FROM ' . UCFD_TABLE . ' WHERE id_ucf = ' . $_GET['delete'] . ';';
162            pwg_query($query);
163
164            $_SESSION['page_infos'] = array(l10n('Custom fields delete'));
165            redirect($admin_base_url);
166        }
167       
168        if (isset($_GET['hide'])) {
169            check_input_parameter('hide', $_GET, false, PATTERN_ID);
170            $query = 'UPDATE ' . UCF_TABLE . ' SET active = 0 , obligatory = 0 WHERE id_ucf=' . $_GET['hide'] . ';';
171            pwg_query($query);
172        }
173       
174        if (isset($_GET['show'])) {
175            check_input_parameter('show', $_GET, false, PATTERN_ID);
176            $query = 'UPDATE ' . UCF_TABLE . ' SET active = 1 WHERE id_ucf=' . $_GET['show'] . ';';
177            pwg_query($query);
178        }
179
180                if (isset($_GET['adminonlyh'])) {
181            check_input_parameter('adminonlyh', $_GET, false, PATTERN_ID);
182            $query = 'UPDATE ' . UCF_TABLE . ' SET adminonly = 1 WHERE id_ucf=' . $_GET['adminonlyh'] . ';';
183            pwg_query($query);
184        }
185                if (isset($_GET['adminonlys'])) {
186            check_input_parameter('adminonlys', $_GET, false, PATTERN_ID);
187            $query = 'UPDATE ' . UCF_TABLE . ' SET adminonly = 0 WHERE id_ucf=' . $_GET['adminonlys'] . ';';
188            pwg_query($query);
189        }
190                if (isset($_GET['obligatoryh'])) {
191            check_input_parameter('obligatoryh', $_GET, false, PATTERN_ID);
192                        if($_GET['obligatoryh']==3){
193                                conf_update_param('obligatory_user_mail_address', true);
194                        }
195            $query = 'UPDATE ' . UCF_TABLE . ' SET obligatory = 1 WHERE id_ucf=' . $_GET['obligatoryh'] . ';';
196            pwg_query($query);
197                }
198                if (isset($_GET['obligatorys'])) {
199            check_input_parameter('obligatorys', $_GET, false, PATTERN_ID);
200            if($_GET['obligatorys']==3){
201                                conf_update_param('obligatory_user_mail_address', false);
202                        }
203                        $query = 'UPDATE ' . UCF_TABLE . ' SET obligatory = 0 WHERE id_ucf=' . $_GET['obligatorys'] . ';';
204            pwg_query($query);
205                }
206        /*Import information *AA */
207        $exp = pwg_db_fetch_assoc(pwg_query("SELECT state FROM " . PLUGINS_TABLE . " WHERE id = 'AddInfousers';"));
208        if($exp['state']=='active'){
209                $template->assign(
210                        'gestImp',
211                                array(
212                                 'yep'=>l10n('yep'),
213                ));
214        }
215                if (isset($_POST['submitimport'])){
216
217        $iducf=pwg_db_fetch_assoc(pwg_query('SELECT id_ucf FROM ' . UCF_TABLE . ' ORDER BY id_ucf DESC LIMIT 1;'));     
218       
219       
220        $iducf=$iducf['id_ucf'];
221        $iducf1=$iducf+1;$iducf2=$iducf+2;$iducf3=$iducf+3;$iducf4=$iducf+4;$iducf5=$iducf+5;$iducf6=$iducf+6;$iducf7=$iducf+7;
222        $q = 'INSERT INTO ' . $prefixeTable . 'user_custom_fields(id_ucf,wording,order_ucf,active,edit,adminonly,obligatory)VALUES ('.$iducf1.',"infos1",'.$iducf1.',1,1,0,1);';
223    pwg_query($q);
224        $q = 'INSERT INTO ' . $prefixeTable . 'user_custom_fields(id_ucf,wording,order_ucf,active,edit,adminonly,obligatory)VALUES ('.$iducf2.',"infos2",'.$iducf2.',1,1,0,1);';
225    pwg_query($q);
226        $q = 'INSERT INTO ' . $prefixeTable . 'user_custom_fields(id_ucf,wording,order_ucf,active,edit,adminonly,obligatory)VALUES ('.$iducf3.',"infos3",'.$iducf3.',1,1,0,1);';
227    pwg_query($q);
228        $q = 'INSERT INTO ' . $prefixeTable . 'user_custom_fields(id_ucf,wording,order_ucf,active,edit,adminonly,obligatory)VALUES ('.$iducf4.',"infos4",'.$iducf4.',1,1,0,1);';
229    pwg_query($q);
230        $q = 'INSERT INTO ' . $prefixeTable . 'user_custom_fields(id_ucf,wording,order_ucf,active,edit,adminonly,obligatory)VALUES ('.$iducf5.',"infos5",'.$iducf5.',1,1,0,1);';
231    pwg_query($q);
232        $q = 'INSERT INTO ' . $prefixeTable . 'user_custom_fields(id_ucf,wording,order_ucf,active,edit,adminonly,obligatory)VALUES ('.$iducf6.',"infos6",'.$iducf6.',1,1,0,1);';
233    pwg_query($q);
234        $q = 'INSERT INTO ' . $prefixeTable . 'user_custom_fields(id_ucf,wording,order_ucf,active,edit,adminonly,obligatory)VALUES ('.$iducf7.',"infos7",'.$iducf7.',1,1,0,1);';
235    pwg_query($q);
236       
237       
238        $query = 'SELECT * FROM '. $prefixeTable . 'addinfo_users;';
239        $result = pwg_query($query);
240        if (pwg_db_num_rows($result)) {
241                while ($info = pwg_db_fetch_assoc($result)){
242                        $q = 'INSERT INTO ' . $prefixeTable . 'user_custom_fields_data(id_user,id_ucf,data)VALUES ('.$info['id'].','.$iducf1.',"'.htmlspecialchars($info['info1']).'");';
243                        pwg_query($q);
244                        $q = 'INSERT INTO ' . $prefixeTable . 'user_custom_fields_data(id_user,id_ucf,data)VALUES ('.$info['id'].','.$iducf2.',"'.htmlspecialchars($info['info2']).'");';
245                        pwg_query($q);
246                        $q = 'INSERT INTO ' . $prefixeTable . 'user_custom_fields_data(id_user,id_ucf,data)VALUES ('.$info['id'].','.$iducf3.',"'.htmlspecialchars($info['info3']).'");';
247                        pwg_query($q);
248                        $q = 'INSERT INTO ' . $prefixeTable . 'user_custom_fields_data(id_user,id_ucf,data)VALUES ('.$info['id'].','.$iducf4.',"'.htmlspecialchars($info['info4']).'");';
249                        pwg_query($q);
250                        $q = 'INSERT INTO ' . $prefixeTable . 'user_custom_fields_data(id_user,id_ucf,data)VALUES ('.$info['id'].','.$iducf5.',"'.htmlspecialchars($info['info5']).'");';
251                        pwg_query($q);
252                        $q = 'INSERT INTO ' . $prefixeTable . 'user_custom_fields_data(id_user,id_ucf,data)VALUES ('.$info['id'].','.$iducf6.',"'.htmlspecialchars($info['info6']).'");';
253                        pwg_query($q);
254                        $q = 'INSERT INTO ' . $prefixeTable . 'user_custom_fields_data(id_user,id_ucf,data)VALUES ('.$info['id'].','.$iducf7.',"'.htmlspecialchars($info['info7']).'");';
255                        pwg_query($q);
256
257                }
258        }
259        pwg_query( 'UPDATE ' . PLUGINS_TABLE . ' SET state="inactive" WHERE id="AddInfousers"');
260        $_SESSION['page_infos'] = array(l10n('Import was successful'));
261        redirect($admin_base_url);
262        } 
263        /*End *AA */
264  break;
265  case 'edit_user':
266    if (isset($_GET['ucfiduser']) and isset($_GET['ucfusername'])) {
267      check_input_parameter('ucfiduser', $_GET, false, PATTERN_ID);
268          $PAED = pwg_db_fetch_assoc(pwg_query("SELECT state FROM " . PLUGINS_TABLE . " WHERE id = 'ExtendedDescription';"));
269                if($PAED['state'] == 'active'){
270                  add_event_handler('AP_render_content', 'get_user_language_desc');
271                  $template->assign('useED',1);
272                }else{
273                  $template->assign('useED',0);
274                }
275          $template->assign(
276                'editusertemplate', array(
277                'toto' => l10n('toto'),
278          ));
279          $tab_user_custom_fields_adminlist=tab_user_custom_fields_adminlist();
280      $template->assign('UCF_USERNAME',$_GET['ucfusername']);
281          $template->assign('UCF_USERID',$_GET['ucfiduser']);
282          while ($info_users = pwg_db_fetch_assoc($tab_user_custom_fields_adminlist)) {
283               
284                $d=data_info_user($_GET['ucfiduser'],$info_users['id_ucf']);
285                $row = pwg_db_fetch_assoc($d);
286                $items = array(
287                        'UCFID' => $info_users['id_ucf'],
288                        'UCFWORDING' => trigger_change('AP_render_content', $info_users['wording']),
289                        'UCFOBLIGATORY' => $info_users['obligatory'],
290                        'UCFADMINONLY' => $info_users['adminonly'],
291                        'UCFDATA' => $row['data'],
292                );
293                $template->append('tab_user_custom_fields_adminlist', $items);
294          }
295    }else{
296        redirect(UCF_ADMIN . '-define_custom');
297        }
298       
299  if (isset($_POST['submitUCFa'])) {
300   foreach ($_POST['data'] AS $id_ucf => $data) {
301        $q = 'SELECT 1 FROM ' . UCFD_TABLE . ' WHERE id_user=' . $_POST['invisibleUSERID'] . ' AND id_ucf=' . $id_ucf;
302        $test = pwg_query($q);
303        $row = pwg_db_fetch_assoc($test);
304        if (count($row) > 0){
305          if ($data != ''){
306                $query = 'UPDATE ' . UCFD_TABLE . ' SET data="' . $data . '" WHERE id_user=' . $_POST['invisibleUSERID'] . ' AND id_ucf=' . $id_ucf;
307                pwg_query($query);
308          }else{
309                $query = 'DELETE FROM ' . UCFD_TABLE . ' WHERE id_user=' . $_POST['invisibleUSERID'] . ' AND id_ucf=' . $id_ucf;
310                pwg_query($query);
311          }
312        }else if ($data != ''){
313                $query = 'INSERT ' . UCFD_TABLE . '(id_user,id_ucf,data) VALUES (' . $_POST['invisibleUSERID'] . ',' . $id_ucf . ',"' . $data . '");';
314                pwg_query($query);
315        }
316   }
317  $_SESSION['page_infos'] = array(l10n('Data custom fields update'));
318  redirect(get_root_url().'admin.php?page=user_list');
319  }
320       
321  break;
322 }
323
324
325$template->set_filenames(array('plugin_admin_content' => dirname(__FILE__) . '/admin.tpl'));
326$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
327?>
Note: See TracBrowser for help on using the repository browser.