Location: PHPKode > projects > PhpProjectMaster > www/inc/user.php
<?php
/* 
 User related functions
 (c) 2004-2007 by "Oleg Savchuk" <hide@address.com>

 part of phpProjectMaster project
 http://phpprojmaster.sourceforge.net

 The contents of this file are subject to the GNU GENERAL PUBLIC LICENSE
 http://www.gnu.org/copyleft/gpl.html
*/

 require_once "sitelib.php";
 require_once "form_utils.php";

 $BEMAIL_FILE="$site_templ/emails/email_broadcast.txt";

# get_user
# check_access
# accesslevel2name
# get_select_accesslevel

# get_userinfo
# get_user_autopwd

# get_user_phrasectr

function get_user($item_id){
 $sql="select * from users where u_id=".dbq($item_id);
 return db_row($sql);
}

function get_user_name($item_id){
 $row=get_user($item_id);
 return $row['fname'].' '.$row['lname'];
}

################### return href to HASH with common logged user info
function get_userinfo(){
 global $SITE_VERSION;
 return array(
   'logged_u_id'         => $_SESSION['u_id'],
   'logged_access_level' => $_SESSION['access_level'],
   'logged_access_name'  => $_SESSION['access_name'],
   'logged_user_fname'   => $_SESSION['fname'],
   'logged_user_lname'   => $_SESSION['lname'],
   'external_wiki_link'  => $_SESSION['external_wiki_link'],
   'site_version'        => $SITE_VERSION,
 );
}

################ return autogenerated password according to param
# level 20 - A-Z a-z 0-9
# level 10 -  A-Z 0-9
# level other - 0-9
function get_user_autopwd($pwd_level=5){
 $len=0;

 $Achars=array();
 for($i=ord("A");$i<=ord("Z");$i++) $Achars[]=chr($i);
 $achars=array();
 for($i=ord("a");$i<=ord("z");$i++) $achars[]=chr($i);
 $dchars=array();
 for($i=ord("0");$i<=ord("9");$i++) $dchars[]=chr($i);

 if ($pwd_level==20){
    $len=8;
    $chars=array_merge($Achars, $achars, $dchars);
 } elseif ($pwd_level==10) {
    $len=6;
    $chars=array_merge($Achars, $dchars);
 } else {
    $len=5;
    $chars=$dchars;
 }

 for($i=0;$i<$len;$i++) $result.=$chars[rand(0,count($chars))];
 return $result;
}

#############
function delete_user($item_id){
 db_query("update users set status=127 where u_id=$item_id");
}



#################
function check_access($access_level){
 global $BADACCESS_URL;

# logger($_SESSION[_session_id]);
 if (!$_SESSION['u_id'] || $_SESSION['access_level']<$access_level){
    logger("check_access BAD:".$_SESSION['u_id']." = ".$_SESSION['access_level']." = ".$_SESSION['access_name']);
    do_redirect($BADACCESS_URL);
    exit;
 }
}

################### should be in DB for easy edit by user
$ACCESSLEVELNAME=array(
 '0' => 'User',
 '100'=> 'Site Administrator'
);
$ACCESSLEVEL=array(0,100);

function accesslevel2name($access_level=0){
 global $ACCESSLEVELNAME;

# $sql="select cname
#   from access_level
#  where access_level=$access_level
#           and status<>127
# ";
#
# $sth=db_query($sql);
#
# $row=mysql_fetch_row($sth);
# return $row[0];
 return $ACCESSLEVELNAME[ $access_level ];
}

###################
function get_select_accesslevel($sel, $max=101, $min=0){
 global $ACCESSLEVEL, $ACCESSLEVELNAME;

 $res;
# $sql="select access_level, cname
#    from access_level
#   where access_level<$max
#     and access_level>=$min
#     and status<>127
#    order by access_level
# ";
#
# return get_combo_select_sql($sql,$sel);

 for($i=0;$i<count($ACCESSLEVEL);$i++){
     if ($max<=$ACCESSLEVEL[$i] or $min>$ACCESSLEVEL[$i]) continue;
     if ($ACCESSLEVEL[$i]==$sel){
        $res.="<option selected value=\"$ACCESSLEVEL[$i]\">".$ACCESSLEVELNAME[ $ACCESSLEVEL[$i] ];
     } else {
        $res.="<option value=\"$ACCESSLEVEL[$i]\">".$ACCESSLEVELNAME[ "".$ACCESSLEVEL[$i] ];
     }
 }

 return $res;
}


?>
Return current item: PhpProjectMaster