1 | <?php |
---|
2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
3 | |
---|
4 | global $template, $page, $conf; |
---|
5 | |
---|
6 | $piwecard = get_plugin_data($plugin_id); |
---|
7 | |
---|
8 | // +-----------------------------------------------------------------------+ |
---|
9 | // | form submission | |
---|
10 | // +-----------------------------------------------------------------------+ |
---|
11 | // Switch on right side (=>) |
---|
12 | if (isset($_POST['falsify']) and isset($_POST['cat_true']) and count($_POST['cat_true']) > 0) { |
---|
13 | $piwecard->config['authorized_cats'] = 'selected'; |
---|
14 | |
---|
15 | foreach ($_POST['cat_true'] as $cat) |
---|
16 | unset($piwecard->config['selected_cats'][array_search($cat, $piwecard->config['selected_cats'])]); |
---|
17 | $piwecard->set_config(); |
---|
18 | } |
---|
19 | |
---|
20 | // Switch on left side (<=) |
---|
21 | if (isset($_POST['trueify']) and isset($_POST['cat_false']) and count($_POST['cat_false']) > 0) { |
---|
22 | $query = 'SELECT id, name, uppercats, global_rank FROM '.CATEGORIES_TABLE.' WHERE id IN ("'.implode('","', $_POST['cat_false']).'");'; |
---|
23 | $result = pwg_query($query); |
---|
24 | |
---|
25 | $piwecard->config['authorized_cats'] = 'selected'; |
---|
26 | |
---|
27 | if (!empty($result)) { |
---|
28 | while ($cat = pwg_db_fetch_assoc($result)) |
---|
29 | array_push($piwecard->config['selected_cats'], $cat['id']); |
---|
30 | } |
---|
31 | usort($piwecard->config['selected_cats'], 'global_rank_compare'); |
---|
32 | |
---|
33 | $piwecard->set_config(); |
---|
34 | } |
---|
35 | |
---|
36 | if (isset($_POST['submit'])) { |
---|
37 | $piwecard->config['authorized_cats'] = $_POST['ecard_authorized_cats']; |
---|
38 | if ($_POST['ecard_authorized_cats'] == 'user') |
---|
39 | $piwecard->config['user_cats_case_sensitive'] = ((isset($_POST['ecard_user_cats_case_sensitive']) && $_POST['ecard_user_cats_case_sensitive'] == '1') ? true : false); |
---|
40 | $piwecard->config['authorized_groups_users'] = $_POST['ecard_authorized_groups_users']; |
---|
41 | if ($_POST['ecard_authorized_groups_users'] == 'granted' OR $_POST['ecard_authorized_groups_users'] == 'denied') { |
---|
42 | $piwecard->config['selected_groups'] = (isset($_POST['groups']) ? $_POST['groups'] : array()); |
---|
43 | $piwecard->config['selected_users'] = (isset($_POST['users']) ? $_POST['users'] : array()); |
---|
44 | } |
---|
45 | $piwecard->set_config(); |
---|
46 | array_push($page['infos'], l10n('Information data registered in database')); |
---|
47 | } |
---|
48 | |
---|
49 | // +-----------------------------------------------------------------------+ |
---|
50 | // | template initialization | |
---|
51 | // +-----------------------------------------------------------------------+ |
---|
52 | |
---|
53 | $template->set_filenames(array( |
---|
54 | 'plugin_admin_content' => PIWECARD_ROOT.'/admin/template/admin_permissions.tpl', |
---|
55 | 'double_select' => 'double_select.tpl' |
---|
56 | )); |
---|
57 | $template->assign('ecard', array( |
---|
58 | 'all_cats_checked' => (($piwecard->config['authorized_cats'] == 'all') ? 'checked="checked"' : ''), |
---|
59 | 'selected_cats_checked' => (($piwecard->config['authorized_cats'] == 'selected') ? 'checked="checked"' : ''), |
---|
60 | 'user_cats_checked' => (($piwecard->config['authorized_cats'] == 'user') ? 'checked="checked"' : ''), |
---|
61 | 'user_cats_case_sensitive' => (($piwecard->config['user_cats_case_sensitive']) ? 'checked="checked"' : ''), |
---|
62 | 'all_groups_users_checked' => (($piwecard->config['authorized_groups_users'] == 'all') ? 'checked="checked"' : ''), |
---|
63 | 'granted_groups_users_checked' => (($piwecard->config['authorized_groups_users'] == 'granted') ? 'checked="checked"' : ''), |
---|
64 | 'denied_groups_users_checked' => (($piwecard->config['authorized_groups_users'] == 'denied') ? 'checked="checked"' : ''), |
---|
65 | ) |
---|
66 | ); |
---|
67 | $template->assign(array( |
---|
68 | 'F_ACTION' => '', |
---|
69 | 'L_CAT_OPTIONS_TRUE' => l10n('piwecard_selected_cats'), |
---|
70 | 'L_CAT_OPTIONS_FALSE' => l10n('piwecard_non_selected_cats'), |
---|
71 | ) |
---|
72 | ); |
---|
73 | |
---|
74 | // +-----------------------------------------------------------------------+ |
---|
75 | // | form construction | |
---|
76 | // +-----------------------------------------------------------------------+ |
---|
77 | //Populate double_select |
---|
78 | $query = 'SELECT id, name, uppercats, global_rank FROM '.CATEGORIES_TABLE.' WHERE id not IN ("'.implode('","', $piwecard->config['selected_cats']).'");'; |
---|
79 | $result = pwg_query($query); |
---|
80 | $categories = array(); |
---|
81 | if (!empty($result)) { |
---|
82 | while ($row = pwg_db_fetch_assoc($result)) |
---|
83 | array_push($categories, $row); |
---|
84 | } |
---|
85 | usort($categories, 'global_rank_compare'); |
---|
86 | |
---|
87 | $tpl = array(); |
---|
88 | if (!empty($result)) { |
---|
89 | foreach ($categories as $cat) { |
---|
90 | $tpl_false[$cat['id']] = get_cat_display_name_cache($cat['uppercats'], null, false); |
---|
91 | } |
---|
92 | } |
---|
93 | $template->assign('category_option_false', $tpl_false); |
---|
94 | $template->assign('category_option_false_selected', array()); |
---|
95 | |
---|
96 | $query = 'SELECT id, name, uppercats, global_rank FROM '.CATEGORIES_TABLE.' WHERE id IN ("'.implode('","', $piwecard->config['selected_cats']).'");'; |
---|
97 | $result = pwg_query($query); |
---|
98 | $categories = array(); |
---|
99 | if (!empty($result)) { |
---|
100 | while ($row = pwg_db_fetch_assoc($result)) |
---|
101 | array_push($categories, $row); |
---|
102 | } |
---|
103 | usort($categories, 'global_rank_compare'); |
---|
104 | |
---|
105 | $tpl_true = array(); |
---|
106 | if (!empty($result)) { |
---|
107 | foreach ($categories as $cat) { |
---|
108 | $tpl_true[$cat['id']] = get_cat_display_name_cache($cat['uppercats'], null, false); |
---|
109 | } |
---|
110 | } |
---|
111 | $template->assign('category_option_true', $tpl_true); |
---|
112 | $template->assign('category_option_true_selected', array()); |
---|
113 | |
---|
114 | //Populate Groups and Users |
---|
115 | //Groups |
---|
116 | $groups = array(); |
---|
117 | $query = 'SELECT id, name FROM '.GROUPS_TABLE.' ORDER BY name ASC;'; |
---|
118 | $groups = simple_hash_from_query($query, 'id', 'name'); |
---|
119 | $template->assign('groups', $groups); |
---|
120 | |
---|
121 | //Selected groups |
---|
122 | $selected_groups = $piwecard->config['selected_groups']; |
---|
123 | $template->assign('piwecard_selected_groups', $selected_groups); |
---|
124 | |
---|
125 | //Users |
---|
126 | $users = array(); |
---|
127 | $query = 'SELECT '.$conf['user_fields']['id'].' AS id, '.$conf['user_fields']['username'].' AS username FROM '.USERS_TABLE.';'; |
---|
128 | $users = simple_hash_from_query($query, 'id', 'username'); |
---|
129 | $template->assign('users', $users); |
---|
130 | |
---|
131 | //Selected users |
---|
132 | $selected_users = $piwecard->config['selected_users']; |
---|
133 | $template->assign('piwecard_selected_users', $selected_users); |
---|
134 | |
---|
135 | if (count($selected_groups) > 0) { |
---|
136 | $selected_groups_ids = array(); |
---|
137 | $query = 'SELECT user_id, group_id FROM '.USER_GROUP_TABLE.' WHERE group_id IN ('.implode(',', $selected_groups).');'; |
---|
138 | $result = pwg_query($query); |
---|
139 | while ($row = pwg_db_fetch_assoc($result)) { |
---|
140 | if (!isset($selected_groups_ids[$row['group_id']])) { |
---|
141 | $selected_groups_ids[$row['group_id']] = array(); |
---|
142 | } |
---|
143 | array_push($selected_groups_ids[$row['group_id']], $row['user_id']); |
---|
144 | } |
---|
145 | $user_selected_by_group_ids = array(); |
---|
146 | foreach ($selected_groups_ids as $group_users) { |
---|
147 | $user_selected_by_group_ids = array_merge($user_selected_by_group_ids, $group_users); |
---|
148 | } |
---|
149 | $user_selected_by_group_ids = array_unique($user_selected_by_group_ids); |
---|
150 | $user_selected_indirect_ids = array_diff($user_selected_by_group_ids, $selected_users); |
---|
151 | |
---|
152 | $template->assign('nb_users_selected_indirect', count($user_selected_indirect_ids)); |
---|
153 | $template->assign('nb_users_selected_indirect_style', array( |
---|
154 | 'granted' => (($piwecard->config['authorized_groups_users'] == 'granted') ? '' : 'style="display: none"'), |
---|
155 | 'denied' => (($piwecard->config['authorized_groups_users'] == 'denied') ? '' : 'style="display: none"'), |
---|
156 | ) |
---|
157 | ); |
---|
158 | |
---|
159 | foreach ($selected_groups_ids as $group_id => $group_users) { |
---|
160 | $group_usernames = array(); |
---|
161 | foreach ($group_users as $user_id) { |
---|
162 | if (in_array($user_id, $user_selected_indirect_ids)) { |
---|
163 | array_push($group_usernames, $users[$user_id]); |
---|
164 | } |
---|
165 | } |
---|
166 | |
---|
167 | $template->append('user_selected_indirect_groups', array( |
---|
168 | 'group_name' => $groups[$group_id], |
---|
169 | 'group_users' => implode(', ', $group_usernames), |
---|
170 | ) |
---|
171 | ); |
---|
172 | } |
---|
173 | } |
---|
174 | |
---|
175 | // +-----------------------------------------------------------------------+ |
---|
176 | // | sending html code | |
---|
177 | // +-----------------------------------------------------------------------+ |
---|
178 | |
---|
179 | $template->assign_var_from_handle('DOUBLE_SELECT', 'double_select'); |
---|
180 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|