Ignore:
Timestamp:
Dec 23, 2004, 3:59:37 PM (19 years ago)
Author:
gweltas
Message:
  • User permissions template migration
  • Categories inheritence has not yet been done
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/user_perm.php

    r642 r655  
    3030  die ("Hacking attempt!");
    3131}
    32 
    3332include_once( PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php' );
    3433
    35 //
    36 // Username search
    37 //
    38 function username_search($search_match)
     34$userdata = array();
     35if ( isset( $_POST['submituser'] ) )
    3936{
    40   global $db, $board_config, $template, $lang, $images, $theme, $phpEx, $phpbb_root_path;
    41   global $starttime, $gen_simple_header;
     37  $userdata = getuserdata($_POST['username']);
     38}
     39elseif (isset($_POST['falsify']) || isset($_POST['trueify']))
     40{
     41  $userdata = getuserdata(intval($_POST['userid']));
     42  // cleaning the user_access table for this user
     43  if (isset($_POST['cat_true']) && count($_POST['cat_true']) > 0)
     44  {
     45    foreach ($_POST['cat_true'] as $auth_cat)
     46        {
     47          $query = 'DELETE FROM '.USER_ACCESS_TABLE;
     48      $query.= ' WHERE user_id = '.$userdata['id'];
     49      $query.= ' AND cat_id='.$auth_cat.';';
     50      pwg_query ( $query );
     51        }
     52  }
    4253 
    43   $gen_simple_header = TRUE;
    44 
    45   $username_list = '';
    46   if ( !empty($search_match) )
     54  if (isset($_POST['cat_false']) && count($_POST['cat_false']) > 0)
    4755  {
    48     $username_search = preg_replace('/\*/', '%', trim(strip_tags($search_match)));
    49 
    50     $sql = "SELECT username
    51       FROM " . USERS_TABLE . "
    52       WHERE username LIKE '" . str_replace("\'", "''", $username_search) . "'
    53       ORDER BY username";
    54     if ( !($result = $db->sql_query($sql)) )
    55     {
    56       message_die(GENERAL_ERROR, 'Could not obtain search results', '', __LINE__, __FILE__, $sql);
    57     }
    58 
    59     if ( $row = $db->sql_fetchrow($result) )
    60     {
    61       do
    62       {
    63         $username_list .= '<option value="' . $row['username'] . '">' . $row['username'] . '</option>';
    64       }
    65       while ( $row = $db->sql_fetchrow($result) );
    66     }
    67     else
    68     {
    69       $username_list .= '<option>' . $lang['No_match']. '</option>';
    70     }
    71     $db->sql_freeresult($result);
     56    foreach ($_POST['cat_false'] as $auth_cat)
     57        {
     58          $query = 'INSERT INTO '.USER_ACCESS_TABLE;
     59      $query.= ' (user_id,cat_id) VALUES';
     60      $query.= ' ('.$userdata['id'].','.$auth_cat.')';
     61      $query.= ';';
     62      pwg_query ( $query );
     63        }
    7264  }
    73 
    74   $page_title = $lang['Search'];
    75   include($phpbb_root_path . 'includes/page_header.'.$phpEx);
    76 
    77   $template->set_filenames(array(
    78     'search_user_body' => 'search_username.tpl')
    79   );
    80 
    81   $template->assign_vars(array(
    82     'USERNAME' => ( !empty($search_match) ) ? strip_tags($search_match) : '',
    83 
    84     'L_CLOSE_WINDOW' => $lang['Close_window'],
    85     'L_SEARCH_USERNAME' => $lang['Find_username'],
    86     'L_UPDATE_USERNAME' => $lang['Select_username'],
    87     'L_SELECT' => $lang['Select'],
    88     'L_SEARCH' => $lang['Search'],
    89     'L_SEARCH_EXPLAIN' => $lang['search_explain'],
    90     'L_CLOSE_WINDOW' => $lang['Close_window'],
    91 
    92     'S_USERNAME_OPTIONS' => $username_list,
    93     'S_SEARCH_ACTION' => append_sid("search.$phpEx?mode=searchuser"))
    94   );
    95 
    96   if ( $username_list != '' )
    97   {
    98     $template->assign_block_vars('switch_select_name', array());
    99   }
    100 
    101   $template->pparse('search_user_body');
    102 
    103   include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
    104 
    105   return;
    10665}
    10766
    108 if  (isset($HTTP_POST_VARS['username']) || isset( $_POST['submit'] ))
     67//----------------------------------------------------- template initialization
     68
     69if ( empty($userdata))
    10970{
    110 //----------------------------------------------------- template initialization
    111 $template->set_filenames( array('user'=>'admin/user_perm.tpl') );
     71  $template->set_filenames( array('user'=>'admin/user_perm.tpl') );
     72  $template->assign_vars(array(
     73    'L_SELECT_USERNAME'=>$lang['Select_username'],
     74    'L_LOOKUP_USER'=>$lang['Look_up_user'],
     75    'L_FIND_USERNAME'=>$lang['Find_username'],
     76    'L_AUTH_USER'=>$lang['permuser_only_private'],
     77    'L_SUBMIT'=>$lang['submit'],
    11278
    113 $error = array();
    114 $tpl = array( 'permuser_authorized','permuser_forbidden','submit',
    115               'permuser_parent_forbidden','permuser_info_message',
    116               'adduser_info_back','permuser_only_private' );
    117 //--------------------------------------------------------------------- updates
    118 if ( isset( $_POST['submit'] ) )
    119 {
    120   // cleaning the user_access table for this user
    121   $query = 'DELETE FROM '.PREFIX_TABLE.'user_access';
    122   $query.= ' WHERE user_id = '.$_GET['user_id'];
    123   $query.= ';';
    124   pwg_query( $query );
    125   // selecting all private categories
    126   $query = 'SELECT id';
    127   $query.= ' FROM '.PREFIX_TABLE.'categories';
    128   $query.= " WHERE status = 'private'";
    129   $query.= ';';
    130   $result = pwg_query( $query );
    131   while ( $row = mysql_fetch_array( $result ) )
    132   {
    133     $radioname = 'access-'.$row['id'];
    134     if ( $_POST[$radioname] == 0 )
    135     {
    136       $query = 'INSERT INTO '.PREFIX_TABLE.'user_access';
    137       $query.= ' (user_id,cat_id) VALUES';
    138       $query.= ' ('.$_GET['user_id'].','.$row['id'].')';
    139       $query.= ';';
    140       pwg_query ( $query );
    141     }
    142   }
    143   check_favorites( $_GET['user_id'] );
    144   synchronize_user( $_GET['user_id'] );
    145   $vtp->addSession( $sub, 'confirmation' );
    146   $url = './admin.php?page=user_list';
    147   $vtp->setVar( $sub, 'confirmation.back_url', add_session_id( $url ) );
    148   $vtp->closeSession( $sub, 'confirmation' );
     79    'F_SEARCH_USER_ACTION' => add_session_id(PHPWG_ROOT_PATH.'admin.php?page=user_perm'),
     80    'U_SEARCH_USER' => add_session_id(PHPWG_ROOT_PATH.'admin/search.php')
     81    ));
    14982}
    150 //---------------------------------------------------------------- form display
    151 
    152 $restrictions = get_user_restrictions( $_GET['user_id'], $page['user_status'],
    153                                   false, false );
    154 $action = './admin.php?page=user_perm&amp;user_id='.$_GET['user_id'];
    155 $vtp->setVar( $sub, 'action', add_session_id( $action ) );
    156 // Association of group_ids with group_names -> caching informations
    157 $query = 'SELECT id,name';
    158 $query.= ' FROM '.PREFIX_TABLE.'groups';
    159 $query.= ';';
    160 $result = pwg_query( $query );
    161 $groups = array();
    162 while ( $row = mysql_fetch_array( $result ) )
    163 {
    164   $groups[$row['id']] = $row['name'];
    165 }
    166 // Listing of groups the user belongs to
    167 $query = 'SELECT ug.group_id as groupid';
    168 $query.= ' FROM '.PREFIX_TABLE.'user_group as ug';
    169 $query.= ' WHERE user_id = '.$_GET['user_id'];
    170 $query.= ';';
    171 $result = pwg_query( $query );
    172 $usergroups = array();
    173 while ( $row = mysql_fetch_array( $result ) )
    174 {
    175   array_push( $usergroups, $row['groupid'] );
    176 }
    177 // only private categories are listed
    178 $query = 'SELECT id';
    179 $query.= ' FROM '.PREFIX_TABLE.'categories';
    180 $query.= " WHERE status = 'private'";
    181 $query.= ';';
    182 $result = pwg_query( $query );
    183 while ( $row = mysql_fetch_array( $result ) )
    184 {
    185   $vtp->addSession( $sub, 'category' );
    186   $vtp->setVar( $sub, 'category.id', $row['id'] );
    187   // we have to know whether the user is authorized to access this
    188   // category. The category can be accessible for this user thanks to his
    189   // personnal access rights OR thanks to the access rights of a group he
    190   // belongs to.
    191   // 1. group access :
    192   //    retrieving all authorized groups for this category and for this user
    193   $query = 'SELECT ga.group_id as groupid';
    194   $query.= ' FROM '.PREFIX_TABLE.'group_access as ga';
    195   $query.= ', '.PREFIX_TABLE.'user_group as ug';
    196   $query.= ' WHERE ga.group_id = ug.group_id';
    197   $query.= ' AND ug.user_id = '.$_GET['user_id'];
    198   $query.= ' AND cat_id = '.$row['id'];
    199   $query.= ';';
    200   $subresult = pwg_query( $query );
    201   $authorized_groups = array();
    202   while ( $subrow = mysql_fetch_array( $subresult ) )
    203   {
    204     array_push( $authorized_groups, $subrow['groupid'] );
    205   }
    206   // 2. personnal access
    207   $is_user_allowed = is_user_allowed( $row['id'], $restrictions );
    208   // link to the category permission management
    209   $url = './admin.php?page=cat_perm&amp;cat_id='.$row['id'];
    210   $vtp->setVar( $sub, 'category.cat_perm_link', add_session_id( $url ) );
    211   // color of the category : green if the user is allowed by himself or
    212   // thanks to a group he belongs to
    213   if ( $is_user_allowed == 0 or count( $authorized_groups ) > 0 )
    214   {
    215     $vtp->setVar( $sub, 'category.color', 'green' );
    216   }
    217   else
    218   {
    219     $vtp->setVar( $sub, 'category.color', 'red' );
    220   }
    221   // category name
    222   $cat_infos = get_cat_info( $row['id'] );
    223   $name = get_cat_display_name($cat_infos['name']);
    224   $vtp->setVar( $sub, 'category.name', $name );
    225   // usergroups
    226   if ( count( $usergroups ) > 0 )
    227   {
    228     $vtp->addSession( $sub, 'usergroups' );
    229     foreach ( $usergroups as $i => $usergroup ) {
    230       $vtp->addSession( $sub, 'usergroup' );
    231       $vtp->setVar( $sub, 'usergroup.name', $groups[$usergroup] );
    232       $url = './admin.php?page=group_perm&amp;group_id='.$usergroup;
    233       $vtp->setVar( $sub, 'usergroup.url', add_session_id( $url ) );
    234       if ( in_array( $usergroup, $authorized_groups ) )
    235       {
    236         $vtp->setVar( $sub, 'usergroup.color', 'green' );
    237       }
    238       else
    239       {
    240         $vtp->setVar( $sub, 'usergroup.color', 'red' );
    241       }
    242       if ( $i < count( $usergroups ) - 1 )
    243       {
    244         $vtp->setVar( $sub, 'usergroup.separation', ',' );
    245       }
    246       $vtp->closeSession( $sub, 'usergroup' );
    247     }
    248     $vtp->closeSession( $sub, 'usergroups' );
    249   }
    250   // any subcat forbidden for this user ?
    251   if ( $is_user_allowed == 2 )
    252   {
    253     $vtp->addSession( $sub, 'parent_forbidden' );
    254     $vtp->closeSession( $sub, 'parent_forbidden' );
    255   }
    256   // personnal forbidden or authorized access ?
    257   if ( $is_user_allowed == 0 )
    258   {
    259     $vtp->setVar( $sub, 'category.authorized_checked', ' checked="checked"' );
    260   }
    261   else
    262   {
    263     $vtp->setVar( $sub, 'category.forbidden_checked', ' checked="checked"' );
    264   }
    265   $vtp->closeSession( $sub, 'category' );
    266 }
    267 //----------------------------------------------------------- default code
    26883else
    26984{
    270 $sub = $vtp->Open( '../template/'.$user['template'].'/admin/user_select_body.vtp' );
    271 $tpl = array( 'Look_up_user', 'Find_username', 'Select_username' );
    272 templatize_array( $tpl, 'lang', $sub );
    273   $vtp->addSession( $sub, 'user' );
    274   $vtp->setVarTab( $sub, array(
    275       'user.S_USER_ACTION' => append_sid("./admin.php?page=user_search"),
    276     'user.U_SEARCH_USER' => append_sid("./search.php"))
    277     );
    278   $vtp->closeSession( $sub, 'user' );
     85  $cat_url = '<a href="'.add_session_id(PHPWG_ROOT_PATH.'admin.php?page=cat_options&section=status');
     86  $cat_url .= '">'.$lang['permuser_info_link'].'</a>';
     87  $template->set_filenames( array('user'=>'admin/cat_options.tpl') );
     88  $template->assign_vars(array(
     89    'L_RESET'=>$lang['reset'],
     90    'L_CAT_OPTIONS_TRUE'=>$lang['authorized'],
     91    'L_CAT_OPTIONS_FALSE'=>$lang['forbidden'],
     92    'L_CAT_OPTIONS_INFO'=>$lang['permuser_info'].'&nbsp;'.$cat_url,
     93       
     94        'HIDDEN_NAME'=> 'userid',
     95        'HIDDEN_VALUE'=>$userdata['id'],
     96    'F_ACTION' => add_session_id(PHPWG_ROOT_PATH.'admin.php?page=user_perm'),
     97    ));
     98
     99
     100  // only private categories are listed
     101  $query_true = 'SELECT id,name,uppercats,global_rank FROM '.CATEGORIES_TABLE;
     102  $query_true.= ' LEFT JOIN '.USER_ACCESS_TABLE.' as u';
     103  $query_true.= ' ON u.cat_id=id';
     104  $query_true.= ' WHERE status = \'private\' AND u.user_id='.$userdata['id'].';';
     105  $result = pwg_query($query_true);
     106  $categorie_true = array();
     107  while (!empty($result) && $row = mysql_fetch_array($result))
     108  {
     109    array_push($categorie_true, $row);
     110  }
     111 
     112  $query = 'SELECT id,name,uppercats,global_rank FROM '.CATEGORIES_TABLE;
     113  $query.= ' WHERE status = \'private\'';
     114  $result = pwg_query($query);
     115  $categorie_false = array();
     116  while ($row = mysql_fetch_array($result))
     117  {
     118    if (!in_array($row,$categorie_true))
     119          array_push($categorie_false, $row);
     120  }
     121  usort($categorie_true, 'global_rank_compare');
     122  usort($categorie_false, 'global_rank_compare');
     123  display_select_categories($categorie_true, array(), 'category_option_true', true);
     124  display_select_categories($categorie_false, array(), 'category_option_false', true);
    279125}
     126
    280127//----------------------------------------------------------- sending html code
    281 $vtp->Parse( $handle , 'sub', $sub );
     128$template->assign_var_from_handle('ADMIN_CONTENT', 'user');
    282129?>
Note: See TracChangeset for help on using the changeset viewer.