Ignore:
Timestamp:
Jan 8, 2013, 12:32:56 AM (11 years ago)
Author:
julien1311
Message:

[piwecard] various improvements

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/Piwecard/admin/admin_manage.php

    r19956 r19968  
    44global $template, $page;
    55 
    6 $me = get_plugin_data($plugin_id);
     6$piwecard = get_plugin_data($plugin_id);
    77
    8  $template->set_filenames(
    9                 array('plugin_admin_content' => ECARD_ROOT.'/admin/template/admin_manage.tpl',
    10                           'double_select' => 'double_select.tpl'
    11                         ) );
     8$template->set_filenames(array(
     9        'plugin_admin_content'  => ECARD_ROOT.'/admin/template/admin_manage.tpl',
     10        'double_select'                 => 'double_select.tpl'
     11));
    1212
     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}
    1319
    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 
     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']).'");';
    3623        $result = pwg_query($query);
    3724        $categories = array();
    38         if (!empty($result))
    39         {
    40                 while ($row = mysql_fetch_assoc($result))
     25
     26        if (!empty($result)) {
     27                while ($row = pwg_db_fetch_assoc($result))
    4128                        array_push($categories, $row);                 
    4229        }
    4330        usort($categories, 'global_rank_compare');
    4431
    45         if (!empty($result))
    46         {
    47                 foreach ($categories as $cat)
    48                 {
    49                         array_push($me->my_config['cats'], $cat['id']);
     32        if (!empty($result)) {
     33                foreach ($categories as $cat) {
     34                        array_push($piwecard->my_config['cats'], $cat['id']);
    5035                }
    5136        }
    52 
    53         $me->save_config();
     37        $piwecard->save_config();
    5438}
    55                        
    5639
    5740if (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();
     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();
    6749        array_push($page['infos'], l10n('ecard_admin_saveOK'));
    68        
    6950}
    70 
    71 
    7251
    7352// Groups selection
    7453$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  
     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()))));
    7956}
    80 
    81 
    8257       
    8358// Test double select wall categories
    8459// 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))
     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))
    9565                array_push($categories, $row);
    9666}
     
    9868
    9969$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        
     70if (!empty($result)) {
     71        foreach ($categories as $cat) {
     72        $tpl[$cat['id']] = get_cat_display_name_cache($cat['uppercats'], null, false);
    10873        }
    10974}
     
    11176$template->assign( 'category_option_false_selected', array());
    11277
    113 
    114 
    115 
    11678// 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 
     79$query = 'SELECT id, name, uppercats, global_rank FROM '.CATEGORIES_TABLE.' WHERE id IN ("'.implode('","', $piwecard->my_config['cats']).'");';
    12380$result = pwg_query($query);
    124   $categories = array();
     81$categories = array();
    12582if (!empty($result))
    12683{
    127         while ($row = mysql_fetch_assoc($result))
     84        while ($row = pwg_db_fetch_assoc($result))
    12885                array_push($categories, $row);
    12986}
    13087usort($categories, 'global_rank_compare');
    13188$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        
     89if (!empty($result)) {
     90        foreach ($categories as $cat) {
     91        $tpl2[$cat['id']] = get_cat_display_name_cache($cat['uppercats'], null, false);
    14092        }
    14193}
     
    14395$template->assign( 'category_option_true_selected', array());
    14496
    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 
     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"' : ''));
    149100
    150101$template->assign(Array(
     
    154105));
    155106
    156 
    157 
    158107$template->assign_var_from_handle('DOUBLE_SELECT', 'double_select');
    159108$template->assign_var_from_handle( 'ADMIN_CONTENT', 'plugin_admin_content');
    160109
     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'].'"';
    161122
     123                if (in_array($group['id'], $selecteds)) {
     124                  $output.= ' checked="checked"';
     125                }
    162126
    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.=
     127                $output.= '><label>&nbsp;'. $group['name'].'</label>\n';
     128        }
     129        $output.= '</div>';
    179130
    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       .'&nbsp;'. $group['name']
    193       .'</label>'
    194       ."\n"
    195       ;
    196   }
    197   $output.= '</div>';
    198 
    199   return $output;
     131        return $output;
    200132}
    201133
     134function get_all_groups() {
     135        $query = 'SELECT id, name FROM '.GROUPS_TABLE.' ORDER BY name ASC;';
     136        $result = pwg_query($query);
    202137
     138        $groups = array();
     139        while ($row = pwg_db_fetch_assoc($result)) {
     140                array_push($groups, $row);
     141        }
     142        uasort($groups, 'name_compare');
    203143
    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;
     144        return $groups;
    221145}
    222 
    223 
    224146?>
Note: See TracChangeset for help on using the changeset viewer.