Ignore:
Timestamp:
Dec 20, 2004, 1:30:36 PM (20 years ago)
Author:
plg
Message:
  • new table user_forbidden {user_id,need_update,forbidden_categories} and deletion of field users.forbidden_categories
  • new function calculate_permissions to update table user_forbidden when needed
  • simplification of include/user.inc.php
  • in footer of each page, use "-" instead of "::" to separate page information
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/user.inc.php

    r647 r648  
    2626// +-----------------------------------------------------------------------+
    2727
    28 // retrieving user informations
    29 // $infos array is used to know the fields to retrieve in the table "users"
    30 // Each field becomes an information of the array $user.
    31 // Example :
    32 //            status --> $user['status']
    33 $infos = array('id','username','mail_address','nb_image_line','nb_line_page',
    34                'status','language','maxwidth','maxheight','expand',
    35                'show_nb_comments','recent_period','template',
    36                'forbidden_categories');
    37 
    38 $query_user = 'SELECT * FROM '.USERS_TABLE;
    39 $query_done = false;
    40 $user['is_the_guest'] = false;
     28// retrieving connected user informations
    4129
    4230if (isset($_COOKIE['id']))
     
    8068    else
    8169    {
    82       $query_user .= ' WHERE id = '.$row['user_id'];
    83       $query_done = true;
     70      $user['id'] = $row['user_id'];
     71      $user['is_the_guest'] = false;
    8472    }
    8573  }
    8674}
    87 if (!$query_done)
     75if (!isset($user['id']))
    8876{
    89   $query_user .= ' WHERE id = 2';
     77  $user['id'] = 2;
    9078  $user['is_the_guest'] = true;
    9179}
    92 $query_user .= ';';
    93 $row = mysql_fetch_array(pwg_query($query_user));
    9480
    95 // affectation of each value retrieved in the users table into a variable
    96 // of the array $user.
    97 foreach ($infos as $info) {
    98   if (isset($row[$info]))
     81$query = '
     82SELECT u.*, uf.*
     83  FROM '.USERS_TABLE.' AS u LEFT JOIN '.USER_FORBIDDEN_TABLE.' AS uf
     84    ON id = user_id
     85  WHERE u.id = '.$user['id'].'
     86;';
     87$row = mysql_fetch_array(pwg_query($query));
     88
     89// affectation of each value retrieved in the users table into a variable of
     90// the array $user.
     91foreach ($row as $key => $value)
     92{
     93  if (!is_numeric($key))
    9994  {
    10095    // If the field is true or false, the variable is transformed into a
    10196    // boolean value.
    102     if ($row[$info] == 'true' or $row[$info] == 'false')
    103       $user[$info] = get_boolean($row[$info]);
     97    if ($value == 'true' or $value == 'false')
     98    {
     99      $user[$key] = get_boolean($value);
     100    }
    104101    else
    105       $user[$info] = $row[$info];   
     102    {
     103      $user[$key] = $value;
     104    }
    106105  }
    107   else
    108   {
    109     $user[$info] = '';
    110   }
     106}
     107
     108// if no information were found about user in user_forbidden table OR the
     109// forbidden categories must be updated
     110if (!isset($user['need_update'])
     111    or !is_bool($user['need_update'])
     112    or $user['need_update'] == true)
     113{
     114  $user['forbidden_categories'] = calculate_permissions($user['id']);
     115}
     116
     117// forbidden_categories is a must be empty, at least
     118if (!isset($user['forbidden_categories']))
     119{
     120  $user['forbidden_categories'] = '';
    111121}
    112122
     
    121131if ($user['status'] == 'admin')
    122132{
    123   $isadmin =true;
     133  $isadmin = true;
    124134}
    125135// calculation of the number of picture to display per page
    126136$user['nb_image_page'] = $user['nb_image_line'] * $user['nb_line_page'];
     137
    127138init_userprefs($user);
    128139?>
Note: See TracChangeset for help on using the changeset viewer.