From 94d0e5022aa1b4d43fd707a12679a5b156f75ee6 Mon Sep 17 00:00:00 2001 From: dave Date: Tue, 3 Feb 2009 08:19:15 +0000 Subject: [PATCH] - Add a user_load_by_uid() to load a user by their unique id (users are now cloned for each year); - Fixup the committees.php page to always show the users from the latest year. --- committees.php | 64 ++++++++++++++++++++------------------------------ user.inc.php | 31 ++++++++++++++++++------ 2 files changed, 49 insertions(+), 46 deletions(-) diff --git a/committees.php b/committees.php index a21d17d..ed3baaa 100644 --- a/committees.php +++ b/committees.php @@ -22,68 +22,54 @@ */ ?> "; $q=mysql_query("SELECT * FROM committees ORDER BY ord,name"); - while($r=mysql_fetch_object($q)) - { - $q2=mysql_query("SELECT - users.id, - users.firstname,users.lastname, - users.email, - users_committee.emailprivate, - users_committee.displayemail, - committees_link.title, - committees_link.ord - FROM - users, users_committee, committees_link - WHERE - users_committee.users_id=users.id - AND committees_link.users_id=users.id - AND committees_link.committees_id='$r->id' - ORDER BY - ord,firstname"); - + while($r=mysql_fetch_object($q)) { + $q2=mysql_query("SELECT * FROM committees_link + LEFT JOIN users ON users.id = committees_link.users_id + WHERE committees_id='{$r->id}' ORDER BY ord,users.lastname"); + //if there's nobody in this committee, then just skip it and go on to the next one. if(mysql_num_rows($q2)==0) continue; echo ""; - echo "

$r->name

"; + echo "

{$r->name}

"; echo "\n"; echo mysql_error(); - while($r2=mysql_fetch_object($q2)) - { + while($r2=mysql_fetch_object($q2)) { + + $uid = $r2->users_id; + $u = user_load_by_uid($uid); + $output=$config['committee_publiclayout']; $name=$r2->firstname.' '.$r2->lastname; - $output=str_replace("name",$name,$output); + $output=str_replace("name",$u['name'],$output); $output=str_replace("title",$r2->title,$output); //make sure we do emailprivate before email so we dont match the wrong thing - if($r2->emailprivate && $r2->displayemail=='yes') - { - list($b,$a)=split("@",$r2->emailprivate); + if($u['emailprivate'] && $u['displayemail']=='yes') { + list($b,$a)=split("@",$u['emailprivate']); $output=str_replace("emailprivate","",$output); - } - else - $output=str_replace("emailprivate","",$output); + } else + $output=str_replace("emailprivate","",$output); - if($r2->email && $r2->displayemail=='yes') - { - list($b,$a)=split("@",$r2->email); + if($u['email'] && $u['displayemail']=='yes') { + list($b,$a)=split("@",$u['email']); $output=str_replace("email","",$output); - } - else + } else $output=str_replace("email","",$output); - $output=str_replace("phonehome",$r2->phonehome,$output); - $output=str_replace("phonework",$r2->phonework,$output); - $output=str_replace("phonecell",$r2->phonecell,$output); - $output=str_replace("fax",$r2->fax,$output); + $output=str_replace("phonehome",$u['phonehome'],$output); + $output=str_replace("phonework",$u['->phonework'],$output); + $output=str_replace("phonecell",$u['->phonecell'],$output); + $output=str_replace("fax",$u['fax'],$output); echo $output; diff --git a/user.inc.php b/user.inc.php index 3e4d4b6..6a2c759 100644 --- a/user.inc.php +++ b/user.inc.php @@ -127,10 +127,8 @@ function user_load_sponsor($u) return true; } -function user_load($user) +function user_load($user, $uid = false) { - $id = intval($user); - /* So, it turns out that doing one big load is faster than loading just * from the users table then loading only the specific types the user * has.. go figure. */ @@ -139,9 +137,15 @@ function user_load($user) LEFT JOIN `users_judge` ON `users_judge`.`users_id`=`users`.`id` LEFT JOIN `users_volunteer` ON `users_volunteer`.`users_id`=`users`.`id` LEFT JOIN `users_fair` ON `users_fair`.`users_id`=`users`.`id` - LEFT JOIN `users_sponsor` ON `users_sponsor`.`users_id`=`users`.`id` - WHERE `users`.`id`='$id' - AND `users`.`deleted`='no' "; + LEFT JOIN `users_sponsor` ON `users_sponsor`.`users_id`=`users`.`id` + WHERE "; + if($uid != false) { + $uid = intval($uid); + $query .= "`users`.`uid`='$uid' ORDER BY `users`.`year` DESC LIMIT 1"; + } else { + $id = intval($user); + $query .= " `users`.`id`='$id'"; + } $q=mysql_query($query); if(mysql_num_rows($q)!=1) { @@ -150,9 +154,18 @@ function user_load($user) } $ret = mysql_fetch_assoc($q); + + /* Make sure they're not deleted, we don't want to do this in the query, because loading by $uid would + * simply return the previous year (where deleted=no) */ + if($ret['deleted'] != 'no') { + /* User is deleted */ + return false; + } /* Do we need to do number conversions? */ $ret['id'] = intval($ret['id']); + $ret['uid'] = intval($ret['uid']); + $ret['year'] = intval($ret['year']); /* Turn the type into an array, because there could be more than one */ $ts = explode(',', $ret['types']); @@ -191,10 +204,14 @@ function user_load($user) print_r($ret); echo ""; */ - return $ret; } +function user_load_by_uid($uid) +{ + return user_load(0, $uid); +} + function user_set_password($id, $password = NULL) { /* pass $u by reference so we can update it */