Changeset 648


Ignore:
Timestamp:
Dec 20, 2004, 1:30:36 PM (19 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
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/constants.php

    r593 r648  
    5858define('IMAGE_METADATA_TABLE', $table_prefix.'image_metadata');
    5959define('RATE_TABLE', $table_prefix.'rate');
     60define('USER_FORBIDDEN_TABLE', $table_prefix.'user_forbidden');
    6061?>
  • trunk/include/functions_user.inc.php

    r647 r648  
    277277  }
    278278}
     279
     280/**
     281 * update table user_forbidden for the given user
     282 *
     283 * table user_forbidden contains calculated data. Calculation is based on
     284 * private categories minus categories authorized to the groups the user
     285 * belongs to minus the categories directly authorized to the user
     286 *
     287 * @param int user_id
     288 * @return string forbidden_categories
     289 */
     290function calculate_permissions($user_id)
     291{
     292  $private_array = array();
     293  $authorized_array = array();
     294
     295  $query = '
     296SELECT id
     297  FROM '.CATEGORIES_TABLE.'
     298  WHERE status = \'private\'
     299;';
     300  $result = pwg_query($query);
     301  while ($row = mysql_fetch_array($result))
     302  {
     303    array_push($private_array, $row['id']);
     304  }
     305 
     306  // retrieve category ids directly authorized to the user
     307  $query = '
     308SELECT cat_id
     309  FROM '.USER_ACCESS_TABLE.'
     310  WHERE user_id = '.$user_id.'
     311;';
     312  $result = pwg_query($query);
     313  while ($row = mysql_fetch_array($result))
     314  {
     315    array_push($authorized_array, $row['cat_id']);
     316  }
     317
     318  // retrieve category ids authorized to the groups the user belongs to
     319  $query = '
     320SELECT cat_id
     321  FROM '.USER_GROUP_TABLE.' AS ug INNER JOIN '.GROUP_ACCESS_TABLE.' AS ga
     322    ON ug.group_id = ga.group_id
     323  WHERE ug.user_id = '.$user_id.'
     324;';
     325  $result = pwg_query($query);
     326  while ($row = mysql_fetch_array($result))
     327  {
     328    array_push($authorized_array, $row['cat_id']);
     329  }
     330
     331  // uniquify ids : some private categories might be authorized for the
     332  // groups and for the user
     333  $authorized_array = array_unique($authorized_array);
     334
     335  // only unauthorized private categories are forbidden
     336  $forbidden_array = array_diff($private_array, $authorized_array);
     337
     338  $query = '
     339DELETE FROM '.USER_FORBIDDEN_TABLE.'
     340  WHERE user_id = '.$user_id.'
     341;';
     342  pwg_query($query);
     343
     344  $forbidden_categories = implode(',', $forbidden_array);
     345 
     346  $query = '
     347INSERT INTO '.USER_FORBIDDEN_TABLE.'
     348  (user_id,need_update,forbidden_categories)
     349  VALUES
     350  ('.$user_id.',\'false\',\''.$forbidden_categories.'\')
     351;';
     352  pwg_query($query);
     353 
     354  return $forbidden_categories;
     355}
    279356?>
  • 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?>
  • trunk/install/dbscheme.txt

    r647 r648  
    1313table:sites
    1414table:user_access
     15table:user_forbidden
    1516table:user_group
    1617table:users
     
    8485column:user_id                   table:user_access    type:smallint                 nullable:N length:5   signed:N
    8586column:cat_id                    table:user_access    type:smallint                 nullable:N length:5   signed:N
     87column:user_id                   table:user_forbidden type:smallint                 nullable:N length:5   signed:N
     88column:need_update               table:user_forbidden type:enum('true','false')     nullable:N
     89column:forbidden_categories      table:user_forbidden type:text                     nullable:Y
    8690column:user_id                   table:user_group     type:smallint                 nullable:N length:5   signed:N
    8791column:group_id                  table:user_group     type:smallint                 nullable:N length:5   signed:N
     
    100104column:recent_period             table:users          type:tinyint                  nullable:N length:3   signed:N
    101105column:template                  table:users          type:varchar                  nullable:N length:255 binary:N
    102 column:forbidden_categories      table:users          type:text                     nullable:Y
    103106column:id                        table:waiting        type:int                      nullable:N length:10  signed:N
    104107column:storage_category_id       table:waiting        type:smallint                 nullable:N length:5   signed:N
     
    128131PK:user_access_pk    table:user_access    column:user_id
    129132PK:user_access_pk    table:user_access    column:cat_id
     133PK:user_forbidden_pk table:user_forbidden column:user_id
    130134PK:user_group_pk     table:user_group     column:group_id
    131135PK:user_group_pk     table:user_group     column:user_id
  • trunk/install/phpwebgallery_structure.sql

    r647 r648  
    199199
    200200--
     201-- Table structure for table 'phpwebgallery_user_forbidden'
     202--
     203
     204DROP TABLE IF EXISTS phpwebgallery_user_forbidden;
     205CREATE TABLE phpwebgallery_user_forbidden (
     206  user_id smallint(5) unsigned NOT NULL default '0',
     207  need_update enum('true','false') NOT NULL default 'true',
     208  forbidden_categories text,
     209  PRIMARY KEY  (user_id)
     210) TYPE=MyISAM;
     211
     212--
    201213-- Table structure for table 'phpwebgallery_user_group'
    202214--
     
    229241  recent_period tinyint(3) unsigned NOT NULL default '7',
    230242  template varchar(255) NOT NULL default 'default',
    231   forbidden_categories text,
    232243  PRIMARY KEY  (id),
    233244  UNIQUE KEY users_ui1 (username)
  • trunk/picture.php

    r642 r648  
    417417}
    418418
    419 $picture_size = get_picture_size( $original_width, $original_height,
    420                                   $user['maxwidth'], $user['maxheight'] );
     419$picture_size = get_picture_size($original_width, $original_height,
     420                                 @$user['maxwidth'], @$user['maxheight']);
    421421
    422422// metadata
  • trunk/template/default/footer.tpl

    r531 r648  
    11 <div class="copyright">
    22 <!-- BEGIN debug -->
    3  {L_GEN_TIME} {TIME} ::
     3 {L_GEN_TIME} {TIME} -
    44 <!-- END debug -->
    55
     
    99
    1010  Powered by <a href="http://www.phpwebgallery.net" class="back">PhpWebGallery</a>
    11   {VERSION} ::
     11  {VERSION} -
    1212
    1313  {L_SEND_MAIL}
Note: See TracChangeset for help on using the changeset viewer.