1 | <?php |
---|
2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
3 | |
---|
4 | global $template, $page; |
---|
5 | |
---|
6 | $me = get_plugin_data($plugin_id); |
---|
7 | |
---|
8 | $template->set_filenames( |
---|
9 | array('plugin_admin_content' => ECARD_ROOT.'/admin/template/admin_manage.tpl', |
---|
10 | 'double_select' => 'double_select.tpl' |
---|
11 | ) ); |
---|
12 | |
---|
13 | |
---|
14 | |
---|
15 | |
---|
16 | // Switch on right side (=> ) |
---|
17 | if ( isset($_POST['falsify']) and !is_adviser() |
---|
18 | and isset($_POST['cat_true']) and count($_POST['cat_true']) > 0) |
---|
19 | { |
---|
20 | foreach ($_POST['cat_true'] as $cat) |
---|
21 | unset($me->my_config['cats'][array_search($cat,$me->my_config['cats'])]); |
---|
22 | |
---|
23 | $me->save_config(); |
---|
24 | |
---|
25 | } |
---|
26 | // Switch on left side ( <=) |
---|
27 | if ( isset($_POST['trueify']) and !is_adviser() |
---|
28 | and isset($_POST['cat_false']) and count($_POST['cat_false']) > 0) |
---|
29 | { |
---|
30 | |
---|
31 | $query = ' |
---|
32 | SELECT id, name, uppercats, global_rank |
---|
33 | FROM '.CATEGORIES_TABLE. |
---|
34 | ' WHERE id IN ("'.implode('","', $_POST['cat_false']).'");'; |
---|
35 | |
---|
36 | $result = pwg_query($query); |
---|
37 | $categories = array(); |
---|
38 | if (!empty($result)) |
---|
39 | { |
---|
40 | while ($row = mysql_fetch_assoc($result)) |
---|
41 | array_push($categories, $row); |
---|
42 | } |
---|
43 | usort($categories, 'global_rank_compare'); |
---|
44 | |
---|
45 | if (!empty($result)) |
---|
46 | { |
---|
47 | foreach ($categories as $cat) |
---|
48 | { |
---|
49 | array_push($me->my_config['cats'], $cat['id']); |
---|
50 | } |
---|
51 | } |
---|
52 | |
---|
53 | $me->save_config(); |
---|
54 | } |
---|
55 | |
---|
56 | |
---|
57 | if (isset($_POST['submit'])) { |
---|
58 | |
---|
59 | $me->my_config['allcats'] = isset($_POST['allcats']); |
---|
60 | $me->my_config['user_cat'] = isset($_POST['user_cat']); |
---|
61 | $me->my_config['recursive'] = isset($_POST['recursiv']); |
---|
62 | $me->my_config['groups'] = isset($_POST['groups']) ? |
---|
63 | array_map("mysql_escape_string", $_POST['groups']) : |
---|
64 | array(); |
---|
65 | |
---|
66 | $me->save_config(); |
---|
67 | array_push($page['infos'], l10n('ecard_admin_saveOK')); |
---|
68 | |
---|
69 | } |
---|
70 | |
---|
71 | |
---|
72 | |
---|
73 | // Groups selection |
---|
74 | $groups = get_all_groups(); |
---|
75 | if (!empty($groups)) |
---|
76 | { |
---|
77 | $template->assign('group_perm', array('GROUPSELECTION' => get_html_groups_selection($groups, 'groups', (isset($me->my_config['groups']) ? $me->my_config['groups'] : array())))); |
---|
78 | |
---|
79 | } |
---|
80 | |
---|
81 | |
---|
82 | |
---|
83 | // Test double select wall categories |
---|
84 | // Categories non prises en compte |
---|
85 | $query = ' |
---|
86 | SELECT id, name, uppercats, global_rank |
---|
87 | FROM '.CATEGORIES_TABLE. |
---|
88 | ' WHERE id not IN ("'.implode('","', $me->my_config['cats']).'");'; |
---|
89 | |
---|
90 | $result = pwg_query($query); |
---|
91 | $categories = array(); |
---|
92 | if (!empty($result)) |
---|
93 | { |
---|
94 | while ($row = mysql_fetch_assoc($result)) |
---|
95 | array_push($categories, $row); |
---|
96 | } |
---|
97 | usort($categories, 'global_rank_compare'); |
---|
98 | |
---|
99 | $tpl = array(); |
---|
100 | if (!empty($result)) |
---|
101 | { |
---|
102 | foreach ($categories as $cat) |
---|
103 | { |
---|
104 | $tpl[$cat['id']] = get_cat_display_name_cache($cat['uppercats'], |
---|
105 | null, |
---|
106 | false); |
---|
107 | |
---|
108 | } |
---|
109 | } |
---|
110 | $template->assign( 'category_option_false', $tpl); |
---|
111 | $template->assign( 'category_option_false_selected', array()); |
---|
112 | |
---|
113 | |
---|
114 | |
---|
115 | |
---|
116 | // Categories prises en compte |
---|
117 | |
---|
118 | $query = ' |
---|
119 | SELECT id, name, uppercats, global_rank |
---|
120 | FROM '.CATEGORIES_TABLE. |
---|
121 | ' WHERE id IN ("'.implode('","', $me->my_config['cats']).'");'; |
---|
122 | |
---|
123 | $result = pwg_query($query); |
---|
124 | $categories = array(); |
---|
125 | if (!empty($result)) |
---|
126 | { |
---|
127 | while ($row = mysql_fetch_assoc($result)) |
---|
128 | array_push($categories, $row); |
---|
129 | } |
---|
130 | usort($categories, 'global_rank_compare'); |
---|
131 | $tpl2 = array(); |
---|
132 | if (!empty($result)) |
---|
133 | { |
---|
134 | foreach ($categories as $cat) |
---|
135 | { |
---|
136 | $tpl2[$cat['id']] = get_cat_display_name_cache($cat['uppercats'], |
---|
137 | null, |
---|
138 | false); |
---|
139 | |
---|
140 | } |
---|
141 | } |
---|
142 | $template->assign( 'category_option_true', $tpl2); |
---|
143 | $template->assign( 'category_option_true_selected', array()); |
---|
144 | |
---|
145 | $template->assign('ECARD_ALLCATS', ($me->my_config['allcats'] ? 'checked="checked"' : '')); |
---|
146 | $template->assign('ECARD_USERCAT', ($me->my_config['user_cat'] ? 'checked="checked"' : '')); |
---|
147 | $template->assign('ECARD_RECURSIV', ($me->my_config['recursive'] ? 'checked="checked"' : '')); |
---|
148 | |
---|
149 | |
---|
150 | $template->assign(Array( |
---|
151 | 'F_ACTION' => '', |
---|
152 | 'L_CAT_OPTIONS_TRUE' => l10n('SelectedCat'), |
---|
153 | 'L_CAT_OPTIONS_FALSE' => l10n('NonSelectedCat'), |
---|
154 | )); |
---|
155 | |
---|
156 | |
---|
157 | |
---|
158 | $template->assign_var_from_handle('DOUBLE_SELECT', 'double_select'); |
---|
159 | $template->assign_var_from_handle( 'ADMIN_CONTENT', 'plugin_admin_content'); |
---|
160 | |
---|
161 | |
---|
162 | |
---|
163 | function get_html_groups_selection( |
---|
164 | $groups, |
---|
165 | $fieldname, |
---|
166 | $selecteds = array() |
---|
167 | ) |
---|
168 | { |
---|
169 | global $conf; |
---|
170 | if (count ($groups) == 0 ) |
---|
171 | { |
---|
172 | return ''; |
---|
173 | } |
---|
174 | $output = '<div id="'.$fieldname.'">'; |
---|
175 | $id = 1; |
---|
176 | foreach ($groups as $group) |
---|
177 | { |
---|
178 | $output.= |
---|
179 | |
---|
180 | '<input type="checkbox" name="'.$fieldname.'[]"' |
---|
181 | .' id="group_'.$id++.'"' |
---|
182 | .' value="'.$group['id'].'"' |
---|
183 | ; |
---|
184 | |
---|
185 | if (in_array($group['id'], $selecteds)) |
---|
186 | { |
---|
187 | $output.= ' checked="checked"'; |
---|
188 | } |
---|
189 | |
---|
190 | $output.= |
---|
191 | '><label>' |
---|
192 | .' '. $group['name'] |
---|
193 | .'</label>' |
---|
194 | ."\n" |
---|
195 | ; |
---|
196 | } |
---|
197 | $output.= '</div>'; |
---|
198 | |
---|
199 | return $output; |
---|
200 | } |
---|
201 | |
---|
202 | |
---|
203 | |
---|
204 | function get_all_groups() |
---|
205 | { |
---|
206 | $query = ' |
---|
207 | SELECT id, name |
---|
208 | FROM '.GROUPS_TABLE.' |
---|
209 | ORDER BY name ASC |
---|
210 | ;'; |
---|
211 | $result = pwg_query($query); |
---|
212 | |
---|
213 | $groups = array(); |
---|
214 | while ($row = mysql_fetch_assoc($result)) |
---|
215 | { |
---|
216 | array_push($groups, $row); |
---|
217 | } |
---|
218 | |
---|
219 | uasort($groups, 'name_compare'); |
---|
220 | return $groups; |
---|
221 | } |
---|
222 | |
---|
223 | |
---|
224 | ?> |
---|