Fix user loading

This commit is contained in:
dave 2010-08-19 22:56:33 +00:00
parent 7b454e322a
commit 9f3dc6c9dc

View File

@ -57,24 +57,24 @@ function user_load($users_id, $accounts_id = false)
}
/* Load the user */
$ret = mysql_fetch_assoc($q);
$u = mysql_fetch_assoc($q);
/* Sanitize before using these in mysql queries */
$ret['id'] = intval($ret['id']);
$ret['accounts_id'] = intval($ret['accounts_id']);
$ret['year'] = intval($ret['year']);
$u['id'] = intval($u['id']);
$u['accounts_id'] = intval($u['accounts_id']);
$u['year'] = intval($u['year']);
/* Get roles, and active/complete status for each role */
$query = "SELECT user_roles.*,roles.type,roles.name FROM user_roles LEFT JOIN roles ON roles.id=user_roles.roles_id WHERE user_roles.users_id={$ret['id']}";
$query = "SELECT user_roles.*,roles.type,roles.name FROM user_roles LEFT JOIN roles ON roles.id=user_roles.roles_id WHERE user_roles.users_id={$u['id']}";
$q = mysql_query($query);
$ret['roles'] = array();
$u['roles'] = array();
while(($roledata = mysql_fetch_assoc($q))) {
$ret['roles'][$roledata['type']] = $roledata;
$u['roles'][$roledata['type']] = $roledata;
}
if(count($ret['roles']) == 0) {
if(count($u['roles']) == 0) {
/* No roles, that's ok actually, the previous logic here was that
* a user without roles is deleted.. but.. this could happen for
* new users, or if someone deletes all their roles before adding
@ -82,26 +82,26 @@ function user_load($users_id, $accounts_id = false)
}
/* Convenience */
$ret['name'] = ($ret['firstname'] ? "{$ret['firstname']} " : '').$ret['lastname'];
$u['name'] = ($u['firstname'] ? "{$u['firstname']} " : '').$u['lastname'];
/* Email recipient for "to" field on emails */
if( ($ret['firstname'] || $ret['lastname']) && $ret['email']) {
if( ($u['firstname'] || $u['lastname']) && $u['email']) {
//use their full name if we have it
//if the name contains anything non-standard, we need to quote it.
if(eregi("[^a-z0-9 ]",$ret['name']))
$ret['emailrecipient']="\"{$ret['name']}\" <{$ret['email']}>";
if(eregi("[^a-z0-9 ]",$u['name']))
$u['emailrecipient']="\"{$u['name']}\" <{$u['email']}>";
else
$ret['emailrecipient']="{$ret['name']} <{$ret['email']}>";
$u['emailrecipient']="{$u['name']} <{$u['email']}>";
}
else if($ret['email']) {
else if($u['email']) {
//otherwise, just their email address
$ret['emailrecipient']=$ret['email'];
$u['emailrecipient']=$u['email'];
}
else {
$ret['emailrecipient']="";
$u['emailrecipient']="";
}
foreach(array_keys($ret['roles']) as $r) {
foreach(array_keys($u['roles']) as $r) {
/* Do the load routines inline, the explosion of user roles
* means it's just silly to have a different function for each
* one. If we get one that has a crazy amount of stuff to do,
@ -119,11 +119,11 @@ function user_load($users_id, $accounts_id = false)
$u['years_national'] = intval($u['years_national']);
$u['willing_chair'] = ($u['willing_chair'] == 'yes') ? 'yes' : 'no';
$u['special_award_only'] = ($u['special_award_only'] == 'yes') ? 'yes' : 'no';
$u['cat_prefs'] = strlen($u['cat_prefs'] > 0) ? unserialize($u['cat_prefs']) : array();
$u['div_prefs'] = strlen($u['div_prefs'] > 0) ? unserialize($u['div_prefs']) : array();
$u['divsub_prefs'] = strlen($u['divsub_prefs'] > 0) ? unserialize($u['divsub_prefs']) : array();
$u['cat_prefs'] = (strlen($u['cat_prefs']) > 0) ? unserialize($u['cat_prefs']) : array();
$u['div_prefs'] = (strlen($u['div_prefs']) > 0) ? unserialize($u['div_prefs']) : array();
$u['divsub_prefs'] = (strlen($u['divsub_prefs']) > 0) ? unserialize($u['divsub_prefs']) : array();
// $u['expertise_other'] = $u['expertise_other'];
$u['languages'] = strlen($u['languages'] > 0) ? unserialize($u['languages']) : array();
$u['languages'] = (strlen($u['languages']) > 0) ? unserialize($u['languages']) : array();
// $u['highest_psd'] = $u['highest_psd'];
/* Sanity check the arrays, make sure they are arrays */
@ -149,11 +149,11 @@ function user_load($users_id, $accounts_id = false)
}
/* Do this assignment without recursion :) */
unset($ret['orig']);
$orig = $ret;
$ret['orig'] = $orig;
unset($u['orig']);
$orig = $u;
$u['orig'] = $orig;
return $ret;
return $u;
}
function user_load_by_accounts_id($accounts_id)