[31534] | 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'); |
---|
[31542] | 40 | if (isset($_GET['ucfiduser'])) { |
---|
| 41 | $tabsheet->add('edit_user', l10n('User').' '.$_GET['ucfusername'], UCF_ADMIN . '-edit_user'); |
---|
| 42 | } |
---|
[31534] | 43 | $tabsheet->select($page['tab']); |
---|
| 44 | $tabsheet->assign(); |
---|
| 45 | |
---|
| 46 | switch ($page['tab']) { |
---|
| 47 | case 'define_custom': |
---|
| 48 | $admin_base_url = UCF_ADMIN . '-define_custom'; |
---|
| 49 | $template->assign( |
---|
| 50 | 'addinfotemplate', array( |
---|
[31542] | 51 | 'toto' => l10n('toto'), |
---|
[31534] | 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_HIDE' => $admin_base_url . '&hide=' . $user_custom_fields['id_ucf'], |
---|
| 74 | 'U_SHOW' => $admin_base_url . '&show=' . $user_custom_fields['id_ucf'], |
---|
| 75 | 'U_ADMINONLYHIDE' => $admin_base_url . '&adminonlyh=' . $user_custom_fields['id_ucf'], |
---|
| 76 | 'U_ADMINONLYSHOW' => $admin_base_url . '&adminonlys=' . $user_custom_fields['id_ucf'], |
---|
| 77 | 'U_OBLIGATORYHIDE' => $admin_base_url . '&obligatoryh=' . $user_custom_fields['id_ucf'], |
---|
| 78 | 'U_OBLIGATORYSHOW' => $admin_base_url . '&obligatorys=' . $user_custom_fields['id_ucf'], |
---|
| 79 | ); |
---|
| 80 | if($user_custom_fields['id_ucf']==1){ |
---|
| 81 | $items['UCFWORDING'] = l10n('Username'); |
---|
| 82 | $items['UCFOBLO'] = 0; |
---|
| 83 | }else if($user_custom_fields['id_ucf']==2){ |
---|
| 84 | $items['UCFWORDING'] = l10n('Password'); |
---|
| 85 | $items['UCFOBLO'] = 0; |
---|
| 86 | }else if($user_custom_fields['id_ucf']==3){ |
---|
| 87 | $items['UCFWORDING'] = l10n('Email address'); |
---|
| 88 | $items['UCFOBLO'] = 1; |
---|
| 89 | }else if($user_custom_fields['id_ucf']==4){ |
---|
| 90 | $items['UCFWORDING'] = l10n('Send my connection settings by email'); |
---|
| 91 | $items['UCFOBLO'] = 1; |
---|
| 92 | }else{ |
---|
| 93 | $items['UCFWORDING'] = trigger_change('AP_render_content',$user_custom_fields['wording']); |
---|
[31542] | 94 | $items['UCFWORDING2'] = $user_custom_fields['wording']; |
---|
[31534] | 95 | $items['UCFOBLO'] = 1; |
---|
| 96 | } |
---|
| 97 | $template->append('user_custom_fields', $items); |
---|
| 98 | } |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | if (isset($_POST['submitManualOrderInfo'])){ |
---|
| 102 | |
---|
| 103 | asort($_POST['infoOrd'], SORT_NUMERIC); |
---|
| 104 | |
---|
| 105 | $data = array(); |
---|
| 106 | foreach ($_POST['infoOrd'] as $id =>$val){ |
---|
| 107 | |
---|
| 108 | $data[] = array('id_ucf' => $id, 'order_ucf' => $val+1); |
---|
| 109 | } |
---|
| 110 | $fields = array('primary' => array('id_ucf'), 'update' => array('order_ucf')); |
---|
| 111 | mass_updates(UCF_TABLE, $fields, $data); |
---|
| 112 | |
---|
[31542] | 113 | $page['infos'][] = l10n('Custom fields manual order was saved'); |
---|
[31534] | 114 | redirect($admin_base_url); |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | if (isset($_POST['submitUCF'])) { |
---|
| 118 | if(!isset($_POST['inseractive'])){ |
---|
| 119 | $active = 1; |
---|
| 120 | }else{ |
---|
| 121 | $active = 0; |
---|
| 122 | } |
---|
| 123 | if(!isset($_POST['adminonly'])){ |
---|
| 124 | $adminonly = 0; |
---|
| 125 | }else{ |
---|
| 126 | $adminonly = 1; |
---|
| 127 | } |
---|
| 128 | if(!isset($_POST['obligatory'])){ |
---|
| 129 | $obligatory = 0; |
---|
| 130 | }else{ |
---|
| 131 | $obligatory = 1; |
---|
| 132 | } |
---|
| 133 | if ($_POST['invisibleID'] == 0) { |
---|
| 134 | $result = pwg_query('SELECT MAX(order_ucf) FROM '. UCF_TABLE ); |
---|
| 135 | $row = pwg_db_fetch_assoc($result); |
---|
| 136 | $or = ($row['MAX(order_ucf)'] + 1); |
---|
| 137 | |
---|
| 138 | $q = ' |
---|
| 139 | INSERT INTO ' . $prefixeTable . 'user_custom_fields(wording,order_ucf,active,edit,adminonly,obligatory)VALUES ("' . $_POST['inserwording'] . '","' . $or . '","' . $active . '",1,'.$adminonly.','.$obligatory.');'; |
---|
| 140 | pwg_query($q); |
---|
| 141 | $_SESSION['page_infos'] = array(l10n('Custom fields add')); |
---|
| 142 | } else { |
---|
| 143 | $q = ' |
---|
| 144 | UPDATE ' . $prefixeTable . 'user_custom_fields' |
---|
| 145 | . ' set wording ="' . $_POST['inserwording'] . '" ' |
---|
| 146 | . ' ,active=' . $active |
---|
| 147 | . ' ,adminonly=' . $adminonly |
---|
| 148 | . ' ,obligatory=' . $obligatory |
---|
| 149 | . ' WHERE id_ucf=' . $_POST['invisibleID'] . ';'; |
---|
| 150 | pwg_query($q); |
---|
| 151 | $_SESSION['page_infos'] = array(l10n('Custom fields update')); |
---|
| 152 | } |
---|
| 153 | redirect($admin_base_url); |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | if (isset($_GET['delete'])) { |
---|
| 157 | check_input_parameter('delete', $_GET, false, PATTERN_ID); |
---|
| 158 | $query = 'DELETE FROM ' . UCF_TABLE . ' WHERE id_ucf = ' . $_GET['delete'] . ';'; |
---|
| 159 | pwg_query($query); |
---|
| 160 | $query = 'DELETE FROM ' . UCFD_TABLE . ' WHERE id_ucf = ' . $_GET['delete'] . ';'; |
---|
| 161 | pwg_query($query); |
---|
| 162 | |
---|
| 163 | $_SESSION['page_infos'] = array(l10n('Custom fields delete')); |
---|
| 164 | redirect($admin_base_url); |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | if (isset($_GET['hide'])) { |
---|
| 168 | check_input_parameter('hide', $_GET, false, PATTERN_ID); |
---|
[31541] | 169 | $query = 'UPDATE ' . UCF_TABLE . ' SET active = 0 , obligatory = 0 WHERE id_ucf=' . $_GET['hide'] . ';'; |
---|
[31534] | 170 | pwg_query($query); |
---|
| 171 | } |
---|
| 172 | |
---|
| 173 | if (isset($_GET['show'])) { |
---|
| 174 | check_input_parameter('show', $_GET, false, PATTERN_ID); |
---|
| 175 | $query = 'UPDATE ' . UCF_TABLE . ' SET active = 1 WHERE id_ucf=' . $_GET['show'] . ';'; |
---|
| 176 | pwg_query($query); |
---|
| 177 | } |
---|
| 178 | |
---|
| 179 | if (isset($_GET['adminonlyh'])) { |
---|
| 180 | check_input_parameter('adminonlyh', $_GET, false, PATTERN_ID); |
---|
| 181 | $query = 'UPDATE ' . UCF_TABLE . ' SET adminonly = 1 WHERE id_ucf=' . $_GET['adminonlyh'] . ';'; |
---|
| 182 | pwg_query($query); |
---|
| 183 | } |
---|
| 184 | if (isset($_GET['adminonlys'])) { |
---|
| 185 | check_input_parameter('adminonlys', $_GET, false, PATTERN_ID); |
---|
| 186 | $query = 'UPDATE ' . UCF_TABLE . ' SET adminonly = 0 WHERE id_ucf=' . $_GET['adminonlys'] . ';'; |
---|
| 187 | pwg_query($query); |
---|
| 188 | } |
---|
| 189 | if (isset($_GET['obligatoryh'])) { |
---|
| 190 | check_input_parameter('obligatoryh', $_GET, false, PATTERN_ID); |
---|
| 191 | if($_GET['obligatoryh']==3){ |
---|
| 192 | conf_update_param('obligatory_user_mail_address', true); |
---|
| 193 | } |
---|
| 194 | $query = 'UPDATE ' . UCF_TABLE . ' SET obligatory = 1 WHERE id_ucf=' . $_GET['obligatoryh'] . ';'; |
---|
| 195 | pwg_query($query); |
---|
| 196 | } |
---|
| 197 | if (isset($_GET['obligatorys'])) { |
---|
| 198 | check_input_parameter('obligatorys', $_GET, false, PATTERN_ID); |
---|
| 199 | if($_GET['obligatorys']==3){ |
---|
| 200 | conf_update_param('obligatory_user_mail_address', false); |
---|
| 201 | } |
---|
| 202 | $query = 'UPDATE ' . UCF_TABLE . ' SET obligatory = 0 WHERE id_ucf=' . $_GET['obligatorys'] . ';'; |
---|
| 203 | pwg_query($query); |
---|
| 204 | } |
---|
[31542] | 205 | break; |
---|
| 206 | case 'edit_user': |
---|
| 207 | if (isset($_GET['ucfiduser']) and isset($_GET['ucfusername'])) { |
---|
| 208 | check_input_parameter('ucfiduser', $_GET, false, PATTERN_ID); |
---|
| 209 | $PAED = pwg_db_fetch_assoc(pwg_query("SELECT state FROM " . PLUGINS_TABLE . " WHERE id = 'ExtendedDescription';")); |
---|
| 210 | if($PAED['state'] == 'active'){ |
---|
| 211 | add_event_handler('AP_render_content', 'get_user_language_desc'); |
---|
| 212 | $template->assign('useED',1); |
---|
| 213 | }else{ |
---|
| 214 | $template->assign('useED',0); |
---|
| 215 | } |
---|
| 216 | $template->assign( |
---|
| 217 | 'editusertemplate', array( |
---|
| 218 | 'toto' => l10n('toto'), |
---|
| 219 | )); |
---|
| 220 | $tab_user_custom_fields_adminlist=tab_user_custom_fields_adminlist(); |
---|
| 221 | $template->assign('UCF_USERNAME',$_GET['ucfusername']); |
---|
| 222 | $template->assign('UCF_USERID',$_GET['ucfiduser']); |
---|
| 223 | while ($info_users = pwg_db_fetch_assoc($tab_user_custom_fields_adminlist)) { |
---|
| 224 | |
---|
| 225 | $d=data_info_user($_GET['ucfiduser'],$info_users['id_ucf']); |
---|
| 226 | $row = pwg_db_fetch_assoc($d); |
---|
| 227 | $items = array( |
---|
| 228 | 'UCFID' => $info_users['id_ucf'], |
---|
| 229 | 'UCFWORDING' => trigger_change('AP_render_content', $info_users['wording']), |
---|
| 230 | 'UCFOBLIGATORY' => $info_users['obligatory'], |
---|
| 231 | 'UCFADMINONLY' => $info_users['adminonly'], |
---|
| 232 | 'UCFDATA' => $row['data'], |
---|
| 233 | ); |
---|
| 234 | $template->append('tab_user_custom_fields_adminlist', $items); |
---|
| 235 | } |
---|
| 236 | }else{ |
---|
| 237 | redirect(UCF_ADMIN . '-define_custom'); |
---|
| 238 | } |
---|
| 239 | |
---|
| 240 | if (isset($_POST['submitUCFa'])) { |
---|
| 241 | foreach ($_POST['data'] AS $id_ucf => $data) { |
---|
| 242 | $q = 'SELECT 1 FROM ' . UCFD_TABLE . ' WHERE id_user=' . $_POST['invisibleUSERID'] . ' AND id_ucf=' . $id_ucf; |
---|
| 243 | $test = pwg_query($q); |
---|
| 244 | $row = pwg_db_fetch_assoc($test); |
---|
| 245 | if (count($row) > 0){ |
---|
| 246 | if ($data != ''){ |
---|
| 247 | $query = 'UPDATE ' . UCFD_TABLE . ' SET data="' . $data . '" WHERE id_user=' . $_POST['invisibleUSERID'] . ' AND id_ucf=' . $id_ucf; |
---|
| 248 | pwg_query($query); |
---|
| 249 | }else{ |
---|
| 250 | $query = 'DELETE FROM ' . UCFD_TABLE . ' WHERE id_user=' . $_POST['invisibleUSERID'] . ' AND id_ucf=' . $id_ucf; |
---|
| 251 | pwg_query($query); |
---|
| 252 | } |
---|
| 253 | }else if ($data != ''){ |
---|
| 254 | $query = 'INSERT ' . UCFD_TABLE . '(id_user,id_ucf,data) VALUES (' . $_POST['invisibleUSERID'] . ',' . $id_ucf . ',"' . $data . '");'; |
---|
| 255 | pwg_query($query); |
---|
| 256 | } |
---|
| 257 | } |
---|
| 258 | $_SESSION['page_infos'] = array(l10n('Data custom fields update')); |
---|
| 259 | redirect(get_root_url().'admin.php?page=user_list'); |
---|
| 260 | } |
---|
| 261 | |
---|
| 262 | break; |
---|
[31534] | 263 | } |
---|
| 264 | |
---|
| 265 | |
---|
| 266 | $template->set_filenames(array('plugin_admin_content' => dirname(__FILE__) . '/admin.tpl')); |
---|
| 267 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
| 268 | ?> |
---|