Changeset 650


Ignore:
Timestamp:
Dec 20, 2004, 8:26:43 PM (19 years ago)
Author:
plg
Message:
  • replacement of PREFIX_TABLE constant in delete_user function
  • deletion of $isadmin variable, replaced by constant IN_ADMIN
  • small refactoring
  • in include/common.inc.php, deletion of useless part "Obtain and encode users IP" and corresponding functions encode_ip and decode_ip
  • definition of $confdefault_language deleted from include/config.inc.php : it is already present in database table config
  • function init_userprefs deleted (useless), all its content moved to include/user.inc.php
  • admin.lang.php and faq.lang.php are loaded only if current user is in administrative section
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/functions.php

    r647 r650  
    331331//     - all sessions linked to this user
    332332//     - all categories informations linked to this user
    333 function delete_user( $user_id )
     333function delete_user($user_id)
    334334{
    335335  // destruction of the access linked to the user
    336   $query = 'DELETE FROM '.PREFIX_TABLE.'user_access';
    337   $query.= ' WHERE user_id = '.$user_id;
    338   $query.= ';';
    339   pwg_query( $query );
     336  $query = '
     337DELETE FROM '.USER_ACCESS_TABLE.'
     338  WHERE user_id = '.$user_id.'
     339;';
     340  pwg_query($query);
    340341
    341342  // destruction of the group links for this user
    342   $query = 'DELETE FROM '.PREFIX_TABLE.'user_group';
    343   $query.= ' WHERE user_id = '.$user_id;
    344   $query.= ';';
    345   pwg_query( $query );
     343  $query = '
     344DELETE FROM '.USER_GROUP_TABLE.'
     345  WHERE user_id = '.$user_id.'
     346;';
     347  pwg_query($query);
    346348
    347349  // destruction of the favorites associated with the user
    348   $query = 'DELETE FROM '.PREFIX_TABLE.'favorites';
    349   $query.= ' WHERE user_id = '.$user_id;
    350   $query.= ';';
    351   pwg_query( $query );
     350  $query = '
     351DELETE FROM '.FAVORITES_TABLE.'
     352  WHERE user_id = '.$user_id.'
     353;';
     354  pwg_query($query);
    352355
    353356  // destruction of the sessions linked with the user
    354   $query = 'DELETE FROM '.PREFIX_TABLE.'sessions';
    355   $query.= ' WHERE user_id = '.$user_id;
    356   $query.= ';';
    357   pwg_query( $query );
     357  $query = '
     358DELETE FROM '.SESSIONS_TABLE.'
     359  WHERE user_id = '.$user_id.'
     360;';
     361  pwg_query($query);
    358362
    359363  // destruction of the user
    360   $query = 'DELETE FROM '.USERS_TABLE;
    361   $query.= ' WHERE id = '.$user_id;
    362   $query.= ';';
    363   pwg_query( $query );
     364  $query = '
     365DELETE FROM '.USERS_TABLE.'
     366  WHERE id = '.$user_id.'
     367;';
     368  pwg_query($query);
    364369}
    365370
  • trunk/admin/include/isadmin.inc.php

    r593 r650  
    2828include( PHPWG_ROOT_PATH.'admin/include/functions.php' );
    2929
    30 $isadmin = true;
    31 if ( $user['status'] != 'admin' )
     30if ($user['status'] != 'admin')
    3231{
    3332  echo '<div style="text-align:center;">'.$lang['access_forbiden'].'<br />';
  • trunk/include/common.inc.php

    r593 r650  
    2626// +-----------------------------------------------------------------------+
    2727
    28 if( !defined("PHPWG_ROOT_PATH") )
     28if (!defined('PHPWG_ROOT_PATH'))
    2929{
    30         die ("Hacking attempt!");
     30  die('Hacking attempt!');
    3131}
    3232// determine the initial instant to indicate the generation time of this page
     
    115115
    116116include(PHPWG_ROOT_PATH .'include/mysql.inc.php');
    117 if( !defined("PHPWG_INSTALLED") )
     117if (!defined('PHPWG_INSTALLED'))
    118118{
    119   header( 'Location: install.php' );
     119  header('Location: install.php');
    120120  exit;
    121121}
     
    126126include(PHPWG_ROOT_PATH . 'include/template.php');
    127127
    128 //
    129128// Database connection
    130 //
    131 
    132129mysql_connect( $dbhost, $dbuser, $dbpasswd )
    133130or die ( "Could not connect to database server" );
     
    135132or die ( "Could not connect to database" );
    136133       
    137 //
    138 // Obtain and encode users IP
    139 //
    140 if ( getenv( 'HTTP_X_FORWARDED_FOR' ) != '' )
    141 {
    142   $client_ip = ( !empty($_SERVER['REMOTE_ADDR']) ) ?
    143     $_SERVER['REMOTE_ADDR'] : ( ( !empty($_ENV['REMOTE_ADDR']) ) ? $_ENV['REMOTE_ADDR'] : $REMOTE_ADDR );
    144 
    145   if ( preg_match("/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/",
    146                   getenv('HTTP_X_FORWARDED_FOR'), $ip_list) )
    147   {
    148     $private_ip = array( '/^0\./'
    149                          ,'/^127\.0\.0\.1/'
    150                          ,'/^192\.168\..*/'
    151                          ,'/^172\.16\..*/'
    152                          ,'/^10.\.*/'
    153                          ,'/^224.\.*/'
    154                          ,'/^240.\.*/'
    155       );
    156     $client_ip = preg_replace($private_ip, $client_ip, $ip_list[1]);
    157   }
    158 }
    159 else
    160 {
    161   $client_ip = ( !empty($_SERVER['REMOTE_ADDR']) ) ?
    162     $_SERVER['REMOTE_ADDR'] : ( ( !empty($_ENV['REMOTE_ADDR']) ) ? $_ENV['REMOTE_ADDR'] : $REMOTE_ADDR );
    163 }
    164 $user_ip = encode_ip($client_ip);
    165 
    166134//
    167135// Setup gallery wide options, if this fails then we output a CRITICAL_ERROR
     
    172140 FROM '.CONFIG_TABLE.'
    173141;';
    174 if( !( $result = pwg_query( $query ) ) )
     142if (!($result = pwg_query($query)))
    175143{
    176144  die("Could not query config information");
     
    195163}
    196164
    197 //---------------
    198 // A partir d'ici il faudra dispatcher le code dans d'autres fichiers
    199 //---------------
    200 
    201 include(PHPWG_ROOT_PATH . 'include/user.inc.php');
     165include(PHPWG_ROOT_PATH.'include/user.inc.php');
    202166
    203167// displaying the username in the language of the connected user, instead of
    204168// "guest" as you can find in the database
    205 if ( $user['is_the_guest'] ) $user['username'] = $lang['guest'];
    206 define('PREFIX_TABLE', $table_prefix);
     169if ($user['is_the_guest'])
     170{
     171  $user['username'] = $lang['guest'];
     172}
    207173?>
  • trunk/include/config.inc.php

    r647 r650  
    159159$conf['info_nb_elements_page'] = 5;
    160160
    161 // default_language : language used if language set in user database is not
    162 // available
    163 $conf['default_language'] = 'en_UK.iso-8859-1';
    164 
    165161// show_queries : for debug purpose, show queries and execution times
    166162$conf['show_queries'] = false;
  • trunk/include/functions_user.inc.php

    r648 r650  
    172172}
    173173
    174 //
    175 // Initialise user settings on page load
    176 function init_userprefs($userdata)
    177 {
    178   global $conf, $template, $lang, $lang_info;
    179  
    180   $language = (!empty($userdata['language']) && !$userdata['is_the_guest'] )?$userdata['language']:$conf['default_language'];
    181 
    182   if (!empty($userdata['template']) and !$userdata['is_the_guest'])
    183   {
    184     $template = $userdata['template'];
    185   }
    186   else
    187   {
    188     $template = $conf['default_template'];
    189   }
    190 
    191   if ( !file_exists(@realpath(PHPWG_ROOT_PATH . 'language/' . $language . '/common.lang.php')) )
    192   {
    193     $language = $conf['default_language'];
    194   }
    195   include_once(PHPWG_ROOT_PATH . 'language/' . $language . '/common.lang.php');
    196  
    197  
    198   if ($userdata['status'] == 'admin')
    199   {
    200     if ( !file_exists(@realpath(PHPWG_ROOT_PATH . 'language/' . $language. '/admin.lang.php')) )
    201     {
    202       $language = $conf['default_language'];
    203     }
    204   include_once(PHPWG_ROOT_PATH . 'language/' . $language . '/admin.lang.php');
    205   include_once(PHPWG_ROOT_PATH . 'language/' . $language . '/faq.lang.php');
    206   }
    207 
    208   $template = setup_style($template);
    209   return;
    210 }
    211 
    212174function setup_style($style)
    213175{
     
    216178  $template = new Template(PHPWG_ROOT_PATH . $template_path . $template_name);
    217179  return $template;
    218 }
    219 
    220 function encode_ip($dotquad_ip)
    221 {
    222   $ip_sep = explode('.', $dotquad_ip);
    223   return sprintf('%02x%02x%02x%02x', $ip_sep[0], $ip_sep[1], $ip_sep[2], $ip_sep[3]);
    224 }
    225 
    226 function decode_ip($int_ip)
    227 {
    228   $hexipbang = explode('.', chunk_split($int_ip, 2, '.'));
    229   return hexdec($hexipbang[0]). '.' . hexdec($hexipbang[1]) . '.' . hexdec($hexipbang[2]) . '.' . hexdec($hexipbang[3]);
    230180}
    231181
  • trunk/include/user.inc.php

    r648 r650  
    128128}
    129129
    130 $isadmin = false;
    131 if ($user['status'] == 'admin')
    132 {
    133   $isadmin = true;
    134 }
    135130// calculation of the number of picture to display per page
    136131$user['nb_image_page'] = $user['nb_image_line'] * $user['nb_line_page'];
    137132
    138 init_userprefs($user);
     133if (empty($user['language'])
     134    or !file_exists(PHPWG_ROOT_PATH.'language/'.
     135                    $user['language'].'/common.lang.php'))
     136{
     137  $user['language'] = $conf['default_language'];
     138}
     139include_once(PHPWG_ROOT_PATH.'language/'.$user['language'].'/common.lang.php');
     140
     141// only if we are in the administration section
     142if (defined('IN_ADMIN') and IN_ADMIN)
     143{
     144  $langdir = PHPWG_ROOT_PATH.'language/'.$user['language'];
     145  if (!file_exists($langdir.'/admin.lang.php'))
     146  {
     147    $langdir = PHPWG_ROOT_PATH.'language/'.$conf['default_language'];
     148  }
     149  include_once($langdir.'/admin.lang.php');
     150  include_once($langdir.'/faq.lang.php');
     151}
     152
     153if (empty($user['template']))
     154{
     155  $user['template'] = $conf['default_template'];
     156}
     157$template = setup_style($user['template']);
    139158?>
Note: See TracChangeset for help on using the changeset viewer.