source: extensions/Piwecard/admin/admin_manage.php @ 19968

Last change on this file since 19968 was 19968, checked in by julien1311, 11 years ago

[piwecard] various improvements

  • Property svn:eol-style set to native
File size: 4.5 KB
Line 
1<?php
2if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
3
4global $template, $page;
5 
6$piwecard = get_plugin_data($plugin_id);
7
8$template->set_filenames(array(
9        'plugin_admin_content'  => ECARD_ROOT.'/admin/template/admin_manage.tpl',
10        'double_select'                 => 'double_select.tpl'
11));
12
13// Switch on right side (=>)   
14if (isset($_POST['falsify']) and isset($_POST['cat_true']) and count($_POST['cat_true']) > 0) {
15        foreach ($_POST['cat_true'] as $cat)
16                unset($piwecard->my_config['cats'][array_search($cat, $piwecard->my_config['cats'])]);
17        $piwecard->save_config();
18}
19
20// Switch on left side (<=)
21if (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        $categories = array();
25
26        if (!empty($result)) {
27                while ($row = pwg_db_fetch_assoc($result))
28                        array_push($categories, $row);                 
29        }
30        usort($categories, 'global_rank_compare');
31
32        if (!empty($result)) {
33                foreach ($categories as $cat) {
34                        array_push($piwecard->my_config['cats'], $cat['id']);
35                }
36        }
37        $piwecard->save_config();
38}
39
40if (isset($_POST['submit'])) { 
41        $piwecard->my_config['allcats'] = isset($_POST['allcats']);
42        $piwecard->my_config['user_cat'] = isset($_POST['user_cat']);
43        $piwecard->my_config['recursive'] = isset($_POST['recursiv']);
44        if ($piwecard->my_config['groups'] = isset($_POST['groups']))
45                array_map("mysql_escape_string", $_POST['groups']);
46        else
47                array(); 
48        $piwecard->save_config();
49        array_push($page['infos'], l10n('ecard_admin_saveOK'));
50}
51
52// Groups selection
53$groups = get_all_groups();
54if (!empty($groups)) {
55  $template->assign('group_perm', array('GROUPSELECTION' => get_html_groups_selection($groups, 'groups', (isset($piwecard->my_config['groups']) ? $piwecard->my_config['groups'] : array()))));
56}
57       
58// Test double select wall categories
59// Categories non prises en compte
60$query = 'SELECT id, name, uppercats, global_rank FROM '.CATEGORIES_TABLE.' WHERE id not IN ("'.implode('","', $piwecard->my_config['cats']).'");';
61$result = pwg_query($query);
62$categories = array();
63if (!empty($result)) {
64        while ($row = pwg_db_fetch_assoc($result))
65                array_push($categories, $row);
66}
67usort($categories, 'global_rank_compare');
68
69$tpl = array();
70if (!empty($result)) {
71        foreach ($categories as $cat) {
72        $tpl[$cat['id']] = get_cat_display_name_cache($cat['uppercats'], null, false);
73        }
74}
75$template->assign( 'category_option_false', $tpl);
76$template->assign( 'category_option_false_selected', array());
77
78// Categories prises en compte
79$query = 'SELECT id, name, uppercats, global_rank FROM '.CATEGORIES_TABLE.' WHERE id IN ("'.implode('","', $piwecard->my_config['cats']).'");';
80$result = pwg_query($query);
81$categories = array();
82if (!empty($result))
83{
84        while ($row = pwg_db_fetch_assoc($result))
85                array_push($categories, $row);
86}
87usort($categories, 'global_rank_compare');
88$tpl2 = array();
89if (!empty($result)) {
90        foreach ($categories as $cat) {
91        $tpl2[$cat['id']] = get_cat_display_name_cache($cat['uppercats'], null, false);
92        }
93}
94$template->assign( 'category_option_true', $tpl2);
95$template->assign( 'category_option_true_selected', array());
96
97$template->assign('ECARD_ALLCATS', ($piwecard->my_config['allcats'] ? 'checked="checked"' : ''));
98$template->assign('ECARD_USERCAT', ($piwecard->my_config['user_cat'] ? 'checked="checked"' : ''));
99$template->assign('ECARD_RECURSIV', ($piwecard->my_config['recursive'] ? 'checked="checked"' : ''));
100
101$template->assign(Array(
102        'F_ACTION' => '',
103        'L_CAT_OPTIONS_TRUE' => l10n('To Translate!'),
104        'L_CAT_OPTIONS_FALSE' => l10n('To Translate!'),
105));
106
107$template->assign_var_from_handle('DOUBLE_SELECT', 'double_select');
108$template->assign_var_from_handle( 'ADMIN_CONTENT', 'plugin_admin_content');
109
110function get_html_groups_selection($groups, $fieldname, $selecteds = array()) {
111        global $conf;
112       
113        if (count ($groups) == 0) {
114                return '';
115        }
116       
117        $output = '<div id="'.$fieldname.'">';
118        $id = 1;
119       
120        foreach ($groups as $group) {
121                $output.= '<input type="checkbox" name="'.$fieldname.'[]" id="group_'.$id++.'" value="'.$group['id'].'"';
122
123                if (in_array($group['id'], $selecteds)) {
124                  $output.= ' checked="checked"';
125                }
126
127                $output.= '><label>&nbsp;'. $group['name'].'</label>\n';
128        }
129        $output.= '</div>';
130
131        return $output;
132}
133
134function get_all_groups() {
135        $query = 'SELECT id, name FROM '.GROUPS_TABLE.' ORDER BY name ASC;';
136        $result = pwg_query($query);
137
138        $groups = array();
139        while ($row = pwg_db_fetch_assoc($result)) {
140                array_push($groups, $row);
141        }
142        uasort($groups, 'name_compare');
143
144        return $groups;
145}
146?>
Note: See TracBrowser for help on using the repository browser.