1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | User Custom Fields plugin for Piwigo | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 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 | |
---|
22 | if (!defined('PHPWG_ROOT_PATH')) |
---|
23 | die('Hacking attempt!'); |
---|
24 | global $template, $conf, $user; |
---|
25 | include_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 | // +-----------------------------------------------------------------------+ |
---|
31 | check_status(ACCESS_ADMINISTRATOR); |
---|
32 | |
---|
33 | //-------------------------------------------------------- sections definitions |
---|
34 | if (!isset($_GET['tab'])) |
---|
35 | $page['tab'] = 'define_custom'; |
---|
36 | else |
---|
37 | $page['tab'] = $_GET['tab']; |
---|
38 | $tabsheet = new tabsheet(); |
---|
39 | $tabsheet->add('ucf', l10n('User custom fields'), UCF_ADMIN . '-define_custom'); |
---|
40 | $tabsheet->select($page['tab']); |
---|
41 | $tabsheet->assign(); |
---|
42 | |
---|
43 | switch ($page['tab']) { |
---|
44 | case 'define_custom': |
---|
45 | $admin_base_url = UCF_ADMIN . '-define_custom'; |
---|
46 | $template->assign( |
---|
47 | 'addinfotemplate', array( |
---|
48 | 'addinfo' => l10n('addinfo'), |
---|
49 | )); |
---|
50 | |
---|
51 | $PAED = pwg_db_fetch_assoc(pwg_query("SELECT state FROM " . PLUGINS_TABLE . " WHERE id = 'ExtendedDescription';")); |
---|
52 | if($PAED['state'] == 'active'){ |
---|
53 | add_event_handler('AP_render_content', 'get_user_language_desc'); |
---|
54 | $template->assign('useED',1); |
---|
55 | }else{ |
---|
56 | $template->assign('useED',0); |
---|
57 | } |
---|
58 | |
---|
59 | $tab_user_custom_fields = tab_user_custom_fields(); |
---|
60 | |
---|
61 | if (pwg_db_num_rows($tab_user_custom_fields)) { |
---|
62 | while ($user_custom_fields = pwg_db_fetch_assoc($tab_user_custom_fields)) { |
---|
63 | $items = array( |
---|
64 | 'IDUCF' => $user_custom_fields['id_ucf'], |
---|
65 | 'UCFORDER' => $user_custom_fields['order_ucf'], |
---|
66 | 'UCFACTIVE' => $user_custom_fields['active'], |
---|
67 | 'UCFEDIT' => $user_custom_fields['edit'], |
---|
68 | 'UCFADMINONLY' => $user_custom_fields['adminonly'], |
---|
69 | 'UCFOBLIGATORY' => $user_custom_fields['obligatory'], |
---|
70 | 'U_HIDE' => $admin_base_url . '&hide=' . $user_custom_fields['id_ucf'], |
---|
71 | 'U_SHOW' => $admin_base_url . '&show=' . $user_custom_fields['id_ucf'], |
---|
72 | 'U_ADMINONLYHIDE' => $admin_base_url . '&adminonlyh=' . $user_custom_fields['id_ucf'], |
---|
73 | 'U_ADMINONLYSHOW' => $admin_base_url . '&adminonlys=' . $user_custom_fields['id_ucf'], |
---|
74 | 'U_OBLIGATORYHIDE' => $admin_base_url . '&obligatoryh=' . $user_custom_fields['id_ucf'], |
---|
75 | 'U_OBLIGATORYSHOW' => $admin_base_url . '&obligatorys=' . $user_custom_fields['id_ucf'], |
---|
76 | ); |
---|
77 | if($user_custom_fields['id_ucf']==1){ |
---|
78 | $items['UCFWORDING'] = l10n('Username'); |
---|
79 | $items['UCFOBLO'] = 0; |
---|
80 | }else if($user_custom_fields['id_ucf']==2){ |
---|
81 | $items['UCFWORDING'] = l10n('Password'); |
---|
82 | $items['UCFOBLO'] = 0; |
---|
83 | }else if($user_custom_fields['id_ucf']==3){ |
---|
84 | $items['UCFWORDING'] = l10n('Email address'); |
---|
85 | $items['UCFOBLO'] = 1; |
---|
86 | }else if($user_custom_fields['id_ucf']==4){ |
---|
87 | $items['UCFWORDING'] = l10n('Send my connection settings by email'); |
---|
88 | $items['UCFOBLO'] = 1; |
---|
89 | }else{ |
---|
90 | $items['UCFWORDING'] = trigger_change('AP_render_content',$user_custom_fields['wording']); |
---|
91 | $items['UCFOBLO'] = 1; |
---|
92 | } |
---|
93 | $template->append('user_custom_fields', $items); |
---|
94 | } |
---|
95 | } |
---|
96 | |
---|
97 | if (isset($_POST['submitManualOrderInfo'])){ |
---|
98 | |
---|
99 | asort($_POST['infoOrd'], SORT_NUMERIC); |
---|
100 | |
---|
101 | $data = array(); |
---|
102 | foreach ($_POST['infoOrd'] as $id =>$val){ |
---|
103 | |
---|
104 | $data[] = array('id_ucf' => $id, 'order_ucf' => $val+1); |
---|
105 | } |
---|
106 | $fields = array('primary' => array('id_ucf'), 'update' => array('order_ucf')); |
---|
107 | mass_updates(UCF_TABLE, $fields, $data); |
---|
108 | |
---|
109 | $page['infos'][] = l10n('Properties manual order was saved'); |
---|
110 | redirect($admin_base_url); |
---|
111 | } |
---|
112 | |
---|
113 | if (isset($_POST['submitUCF'])) { |
---|
114 | if(!isset($_POST['inseractive'])){ |
---|
115 | $active = 1; |
---|
116 | }else{ |
---|
117 | $active = 0; |
---|
118 | } |
---|
119 | if(!isset($_POST['adminonly'])){ |
---|
120 | $adminonly = 0; |
---|
121 | }else{ |
---|
122 | $adminonly = 1; |
---|
123 | } |
---|
124 | if(!isset($_POST['obligatory'])){ |
---|
125 | $obligatory = 0; |
---|
126 | }else{ |
---|
127 | $obligatory = 1; |
---|
128 | } |
---|
129 | if ($_POST['invisibleID'] == 0) { |
---|
130 | $result = pwg_query('SELECT MAX(order_ucf) FROM '. UCF_TABLE ); |
---|
131 | $row = pwg_db_fetch_assoc($result); |
---|
132 | $or = ($row['MAX(order_ucf)'] + 1); |
---|
133 | |
---|
134 | $q = ' |
---|
135 | INSERT INTO ' . $prefixeTable . 'user_custom_fields(wording,order_ucf,active,edit,adminonly,obligatory)VALUES ("' . $_POST['inserwording'] . '","' . $or . '","' . $active . '",1,'.$adminonly.','.$obligatory.');'; |
---|
136 | pwg_query($q); |
---|
137 | $_SESSION['page_infos'] = array(l10n('Custom fields add')); |
---|
138 | } else { |
---|
139 | $q = ' |
---|
140 | UPDATE ' . $prefixeTable . 'user_custom_fields' |
---|
141 | . ' set wording ="' . $_POST['inserwording'] . '" ' |
---|
142 | . ' ,active=' . $active |
---|
143 | . ' ,adminonly=' . $adminonly |
---|
144 | . ' ,obligatory=' . $obligatory |
---|
145 | . ' WHERE id_ucf=' . $_POST['invisibleID'] . ';'; |
---|
146 | pwg_query($q); |
---|
147 | $_SESSION['page_infos'] = array(l10n('Custom fields update')); |
---|
148 | } |
---|
149 | redirect($admin_base_url); |
---|
150 | } |
---|
151 | |
---|
152 | if (isset($_GET['delete'])) { |
---|
153 | check_input_parameter('delete', $_GET, false, PATTERN_ID); |
---|
154 | $query = 'DELETE FROM ' . UCF_TABLE . ' WHERE id_ucf = ' . $_GET['delete'] . ';'; |
---|
155 | pwg_query($query); |
---|
156 | $query = 'DELETE FROM ' . UCFD_TABLE . ' WHERE id_ucf = ' . $_GET['delete'] . ';'; |
---|
157 | pwg_query($query); |
---|
158 | |
---|
159 | $_SESSION['page_infos'] = array(l10n('Custom fields delete')); |
---|
160 | redirect($admin_base_url); |
---|
161 | } |
---|
162 | |
---|
163 | if (isset($_GET['hide'])) { |
---|
164 | check_input_parameter('hide', $_GET, false, PATTERN_ID); |
---|
165 | $query = 'UPDATE ' . UCF_TABLE . ' SET active = 0 WHERE id_ucf=' . $_GET['hide'] . ';'; |
---|
166 | pwg_query($query); |
---|
167 | } |
---|
168 | |
---|
169 | if (isset($_GET['show'])) { |
---|
170 | check_input_parameter('show', $_GET, false, PATTERN_ID); |
---|
171 | $query = 'UPDATE ' . UCF_TABLE . ' SET active = 1 WHERE id_ucf=' . $_GET['show'] . ';'; |
---|
172 | pwg_query($query); |
---|
173 | } |
---|
174 | |
---|
175 | if (isset($_GET['adminonlyh'])) { |
---|
176 | check_input_parameter('adminonlyh', $_GET, false, PATTERN_ID); |
---|
177 | $query = 'UPDATE ' . UCF_TABLE . ' SET adminonly = 1 WHERE id_ucf=' . $_GET['adminonlyh'] . ';'; |
---|
178 | pwg_query($query); |
---|
179 | } |
---|
180 | if (isset($_GET['adminonlys'])) { |
---|
181 | check_input_parameter('adminonlys', $_GET, false, PATTERN_ID); |
---|
182 | $query = 'UPDATE ' . UCF_TABLE . ' SET adminonly = 0 WHERE id_ucf=' . $_GET['adminonlys'] . ';'; |
---|
183 | pwg_query($query); |
---|
184 | } |
---|
185 | if (isset($_GET['obligatoryh'])) { |
---|
186 | check_input_parameter('obligatoryh', $_GET, false, PATTERN_ID); |
---|
187 | if($_GET['obligatoryh']==3){ |
---|
188 | conf_update_param('obligatory_user_mail_address', true); |
---|
189 | } |
---|
190 | $query = 'UPDATE ' . UCF_TABLE . ' SET obligatory = 1 WHERE id_ucf=' . $_GET['obligatoryh'] . ';'; |
---|
191 | pwg_query($query); |
---|
192 | } |
---|
193 | if (isset($_GET['obligatorys'])) { |
---|
194 | check_input_parameter('obligatorys', $_GET, false, PATTERN_ID); |
---|
195 | if($_GET['obligatorys']==3){ |
---|
196 | conf_update_param('obligatory_user_mail_address', false); |
---|
197 | } |
---|
198 | $query = 'UPDATE ' . UCF_TABLE . ' SET obligatory = 0 WHERE id_ucf=' . $_GET['obligatorys'] . ';'; |
---|
199 | pwg_query($query); |
---|
200 | } |
---|
201 | break; |
---|
202 | } |
---|
203 | |
---|
204 | |
---|
205 | $template->set_filenames(array('plugin_admin_content' => dirname(__FILE__) . '/admin.tpl')); |
---|
206 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
207 | ?> |
---|