1 | <?php |
---|
2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
3 | |
---|
4 | global $template, $page; |
---|
5 | |
---|
6 | $piwecard = get_plugin_data($plugin_id); |
---|
7 | |
---|
8 | $template->set_filenames(array( |
---|
9 | 'plugin_admin_content' => PIWECARD_ROOT.'/admin/template/admin_permissions.tpl', |
---|
10 | 'double_select' => 'double_select.tpl' |
---|
11 | )); |
---|
12 | |
---|
13 | // Switch on right side (=>) |
---|
14 | if (isset($_POST['falsify']) and isset($_POST['cat_true']) and count($_POST['cat_true']) > 0) { |
---|
15 | $piwecard->config['authorized_cats'] = 'selected'; |
---|
16 | |
---|
17 | foreach ($_POST['cat_true'] as $cat) |
---|
18 | unset($piwecard->config['selected_cats'][array_search($cat, $piwecard->config['selected_cats'])]); |
---|
19 | $piwecard->set_config(); |
---|
20 | } |
---|
21 | |
---|
22 | // Switch on left side (<=) |
---|
23 | if (isset($_POST['trueify']) and isset($_POST['cat_false']) and count($_POST['cat_false']) > 0) { |
---|
24 | $query = 'SELECT id, name, uppercats, global_rank FROM '.CATEGORIES_TABLE.' WHERE id IN ("'.implode('","', $_POST['cat_false']).'");'; |
---|
25 | $result = pwg_query($query); |
---|
26 | |
---|
27 | $piwecard->config['authorized_cats'] = 'selected'; |
---|
28 | |
---|
29 | if (!empty($result)) { |
---|
30 | while ($cat = pwg_db_fetch_assoc($result)) |
---|
31 | array_push($piwecard->config['selected_cats'], $cat['id']); |
---|
32 | } |
---|
33 | usort($piwecard->config['selected_cats'], 'global_rank_compare'); |
---|
34 | |
---|
35 | $piwecard->set_config(); |
---|
36 | } |
---|
37 | |
---|
38 | if (isset($_POST['submit'])) { |
---|
39 | $piwecard->config['authorized_cats'] = $_POST['ecard_authorized_cats']; |
---|
40 | $piwecard->set_config(); |
---|
41 | array_push($page['infos'], l10n('Information data registered in database')); |
---|
42 | } |
---|
43 | |
---|
44 | //Populate double_select |
---|
45 | $query = 'SELECT id, name, uppercats, global_rank FROM '.CATEGORIES_TABLE.' WHERE id not IN ("'.implode('","', $piwecard->config['selected_cats']).'");'; |
---|
46 | $result = pwg_query($query); |
---|
47 | $categories = array(); |
---|
48 | if (!empty($result)) { |
---|
49 | while ($row = pwg_db_fetch_assoc($result)) |
---|
50 | array_push($categories, $row); |
---|
51 | } |
---|
52 | usort($categories, 'global_rank_compare'); |
---|
53 | |
---|
54 | $tpl = array(); |
---|
55 | if (!empty($result)) { |
---|
56 | foreach ($categories as $cat) { |
---|
57 | $tpl[$cat['id']] = get_cat_display_name_cache($cat['uppercats'], null, false); |
---|
58 | } |
---|
59 | } |
---|
60 | $template->assign('category_option_false', $tpl); |
---|
61 | $template->assign('category_option_false_selected', array()); |
---|
62 | |
---|
63 | $query = 'SELECT id, name, uppercats, global_rank FROM '.CATEGORIES_TABLE.' WHERE id IN ("'.implode('","', $piwecard->config['selected_cats']).'");'; |
---|
64 | $result = pwg_query($query); |
---|
65 | $categories = array(); |
---|
66 | if (!empty($result)) { |
---|
67 | while ($row = pwg_db_fetch_assoc($result)) |
---|
68 | array_push($categories, $row); |
---|
69 | } |
---|
70 | usort($categories, 'global_rank_compare'); |
---|
71 | |
---|
72 | $tpl2 = array(); |
---|
73 | if (!empty($result)) { |
---|
74 | foreach ($categories as $cat) { |
---|
75 | $tpl2[$cat['id']] = get_cat_display_name_cache($cat['uppercats'], null, false); |
---|
76 | } |
---|
77 | } |
---|
78 | $template->assign('category_option_true', $tpl2); |
---|
79 | $template->assign('category_option_true_selected', array()); |
---|
80 | |
---|
81 | $template->assign('ecard', array( |
---|
82 | 'all_cats_checked' => (($piwecard->config['authorized_cats'] == 'all') ? 'checked="checked"' : ''), |
---|
83 | 'selected_cats_checked' => (($piwecard->config['authorized_cats'] == 'selected') ? 'checked="checked"' : ''), |
---|
84 | 'user_cats_checked' => (($piwecard->config['authorized_cats'] == 'user') ? 'checked="checked"' : ''), |
---|
85 | ) |
---|
86 | ); |
---|
87 | |
---|
88 | $template->assign(array( |
---|
89 | 'F_ACTION' => '', |
---|
90 | 'L_CAT_OPTIONS_TRUE' => l10n('piwecard_selected_cats'), |
---|
91 | 'L_CAT_OPTIONS_FALSE' => l10n('piwecard_non_selected_cats'), |
---|
92 | ) |
---|
93 | ); |
---|
94 | |
---|
95 | $template->assign_var_from_handle('DOUBLE_SELECT', 'double_select'); |
---|
96 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
97 | ?> |
---|