- 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.
This commit is contained in:
dave 2009-02-03 08:19:15 +00:00
parent 8b430bd63f
commit 94d0e5022a
2 changed files with 49 additions and 46 deletions

View File

@ -22,68 +22,54 @@
*/ */
?> ?>
<? <?
require("common.inc.php"); require_once('common.inc.php');
require_once('user.inc.php');
send_header("Committee List", null, "committee_management"); send_header("Committee List", null, "committee_management");
echo "<table>"; echo "<table>";
$q=mysql_query("SELECT * FROM committees ORDER BY ord,name"); $q=mysql_query("SELECT * FROM committees ORDER BY ord,name");
while($r=mysql_fetch_object($q)) while($r=mysql_fetch_object($q)) {
{ $q2=mysql_query("SELECT * FROM committees_link
$q2=mysql_query("SELECT LEFT JOIN users ON users.id = committees_link.users_id
users.id, WHERE committees_id='{$r->id}' ORDER BY ord,users.lastname");
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");
//if there's nobody in this committee, then just skip it and go on to the next one. //if there's nobody in this committee, then just skip it and go on to the next one.
if(mysql_num_rows($q2)==0) if(mysql_num_rows($q2)==0)
continue; continue;
echo "<tr>"; echo "<tr>";
echo "<td colspan=\"3\"><h3>$r->name</h3>"; echo "<td colspan=\"3\"><h3>{$r->name}</h3>";
echo "</td></tr>\n"; echo "</td></tr>\n";
echo mysql_error(); 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']; $output=$config['committee_publiclayout'];
$name=$r2->firstname.' '.$r2->lastname; $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); $output=str_replace("title",$r2->title,$output);
//make sure we do emailprivate before email so we dont match the wrong thing //make sure we do emailprivate before email so we dont match the wrong thing
if($r2->emailprivate && $r2->displayemail=='yes') if($u['emailprivate'] && $u['displayemail']=='yes') {
{ list($b,$a)=split("@",$u['emailprivate']);
list($b,$a)=split("@",$r2->emailprivate);
$output=str_replace("emailprivate","<script language=\"javascript\" type=\"text/javascript\">em('$b','$a')</script>",$output); $output=str_replace("emailprivate","<script language=\"javascript\" type=\"text/javascript\">em('$b','$a')</script>",$output);
} } else
else $output=str_replace("emailprivate","",$output);
$output=str_replace("emailprivate","",$output);
if($r2->email && $r2->displayemail=='yes') if($u['email'] && $u['displayemail']=='yes') {
{ list($b,$a)=split("@",$u['email']);
list($b,$a)=split("@",$r2->email);
$output=str_replace("email","<script language=\"javascript\" type=\"text/javascript\">em('$b','$a')</script>",$output); $output=str_replace("email","<script language=\"javascript\" type=\"text/javascript\">em('$b','$a')</script>",$output);
} } else
else
$output=str_replace("email","",$output); $output=str_replace("email","",$output);
$output=str_replace("phonehome",$r2->phonehome,$output); $output=str_replace("phonehome",$u['phonehome'],$output);
$output=str_replace("phonework",$r2->phonework,$output); $output=str_replace("phonework",$u['->phonework'],$output);
$output=str_replace("phonecell",$r2->phonecell,$output); $output=str_replace("phonecell",$u['->phonecell'],$output);
$output=str_replace("fax",$r2->fax,$output); $output=str_replace("fax",$u['fax'],$output);
echo $output; echo $output;

View File

@ -127,10 +127,8 @@ function user_load_sponsor($u)
return true; 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 /* 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 * from the users table then loading only the specific types the user
* has.. go figure. */ * 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_judge` ON `users_judge`.`users_id`=`users`.`id`
LEFT JOIN `users_volunteer` ON `users_volunteer`.`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_fair` ON `users_fair`.`users_id`=`users`.`id`
LEFT JOIN `users_sponsor` ON `users_sponsor`.`users_id`=`users`.`id` LEFT JOIN `users_sponsor` ON `users_sponsor`.`users_id`=`users`.`id`
WHERE `users`.`id`='$id' WHERE ";
AND `users`.`deleted`='no' "; 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); $q=mysql_query($query);
if(mysql_num_rows($q)!=1) { if(mysql_num_rows($q)!=1) {
@ -150,9 +154,18 @@ function user_load($user)
} }
$ret = mysql_fetch_assoc($q); $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? */ /* Do we need to do number conversions? */
$ret['id'] = intval($ret['id']); $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 */ /* Turn the type into an array, because there could be more than one */
$ts = explode(',', $ret['types']); $ts = explode(',', $ret['types']);
@ -191,10 +204,14 @@ function user_load($user)
print_r($ret); print_r($ret);
echo "</pre>"; echo "</pre>";
*/ */
return $ret; return $ret;
} }
function user_load_by_uid($uid)
{
return user_load(0, $uid);
}
function user_set_password($id, $password = NULL) function user_set_password($id, $password = NULL)
{ {
/* pass $u by reference so we can update it */ /* pass $u by reference so we can update it */