forked from science-ation/science-ation
Updated function for getting user info structure. Used it in the user_load function.
This commit is contained in:
parent
a5887bdf96
commit
cee52c6b67
133
user.inc.php
133
user.inc.php
@ -38,7 +38,6 @@ function user_valid_role($role)
|
||||
|
||||
function user_load($users_id, $accounts_id = false)
|
||||
{
|
||||
user_get_fields(array('judge'));
|
||||
/* Load user, join accounts so we also load the email, superuser flag */
|
||||
//hand-code the list here because we dont want all the old stuff that hasnt been removed yet like username/password access_*, etc.
|
||||
if($accounts_id != false) {
|
||||
@ -62,67 +61,12 @@ function user_load($users_id, $accounts_id = false)
|
||||
|
||||
// Get roles, and active/complete status for each role
|
||||
$u['roles'] = array();
|
||||
$fields = array(
|
||||
'id',
|
||||
'accounts_id',
|
||||
'conferences_id',
|
||||
'salutation',
|
||||
'firstname',
|
||||
'lastname',
|
||||
'sex',
|
||||
'phonehome',
|
||||
'phonework',
|
||||
'phonecell',
|
||||
'fax',
|
||||
'organization',
|
||||
'birthdate',
|
||||
'lang',
|
||||
'created',
|
||||
'lastlogin',
|
||||
'address',
|
||||
'address2',
|
||||
'city',
|
||||
'province',
|
||||
'postalcode',
|
||||
'fairs_id'
|
||||
);
|
||||
$query = "SELECT user_roles.roles_id, user_roles.active, user_roles.complete, roles.type,roles.name FROM user_roles LEFT JOIN roles ON roles.id=user_roles.roles_id WHERE user_roles.users_id=$users_id";
|
||||
$q = mysql_query($query);
|
||||
while(($roledata = mysql_fetch_assoc($q))) {
|
||||
$u['roles'][$roledata['type']] = $roledata;
|
||||
|
||||
$fields = array_merge($fields,
|
||||
user_fields_enabled($roledata['type']));
|
||||
$fields = array_merge($fields,
|
||||
user_fields_required($roledata['type']));
|
||||
|
||||
switch($roledata['type']) {
|
||||
case 'committee':
|
||||
$fields = array_merge($fields, array('ord', 'displayemail'));
|
||||
break;
|
||||
|
||||
case 'judge':
|
||||
$fields = array_merge($fields, array(
|
||||
'years_school', 'years_regional', 'years_national', 'willing_chair',
|
||||
'special_award_only', 'cat_prefs', 'div_prefs', 'divsub_prefs',
|
||||
'languages', 'highest_psd'
|
||||
));
|
||||
break;
|
||||
|
||||
case 'sponsor':
|
||||
$fields[] = 'sponsors_id';
|
||||
break;
|
||||
|
||||
case 'volunteer':
|
||||
$fields[] = 'languages';
|
||||
break;
|
||||
|
||||
default:
|
||||
/* Nothing to do for all other roles */
|
||||
break;
|
||||
}
|
||||
}
|
||||
$fields = array_unique($fields);
|
||||
|
||||
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
|
||||
@ -130,6 +74,10 @@ function user_load($users_id, $accounts_id = false)
|
||||
* a new role */
|
||||
}
|
||||
|
||||
// get a list of all fields relevant to this user
|
||||
$fieldDat = user_get_fields(array_keys($u['roles']));
|
||||
$fields = array_unique(array_merge(array_keys($fieldDat), array('id', 'accounts_id', 'conferences_id')));
|
||||
|
||||
// now let's grab the data from the users table
|
||||
$query = "SELECT users." . implode(", users.", $fields) . ", accounts.email";
|
||||
$query .= " FROM users JOIN accounts ON accounts.id=users.accounts_id";
|
||||
@ -231,9 +179,11 @@ function user_load($users_id, $accounts_id = false)
|
||||
$orig = $u;
|
||||
$u['orig'] = $orig;
|
||||
$u['required_fields']=user_all_fields_required(array_keys($u['roles']));
|
||||
|
||||
return $u;
|
||||
}
|
||||
|
||||
|
||||
function user_load_by_accounts_id($accounts_id)
|
||||
{
|
||||
return user_load(0, $accounts_id);
|
||||
@ -311,7 +261,14 @@ function user_get_field_labels(){
|
||||
'willing_chair' => 'Willing to lead a judging team',
|
||||
'special_award_only' => 'Judging only for a special award',
|
||||
'languages' => 'Languages',
|
||||
|
||||
'div_prefs' => 'Division Preferences',
|
||||
'divsub_prefs' => 'Subdivision Preferences',
|
||||
'expertise_other' => 'Other areas of expertise',
|
||||
'highest_psd' => 'Highest post-secondary degree',
|
||||
'primary' => 'Primary Contact',
|
||||
'position' => 'Position',
|
||||
'notes' => 'Notes',
|
||||
'grade' => 'Grade'
|
||||
);
|
||||
}
|
||||
|
||||
@ -335,7 +292,7 @@ function role_field_required($role, $fieldname){
|
||||
|
||||
// accepts either an array of roles (eg. {'judge', 'teacher', 'foo'}), a single one as a string (eg. 'judge'), or a null value (no roles at all)
|
||||
function user_get_fields($userRoles = null){
|
||||
global $roles;
|
||||
global $roles, $conference;
|
||||
|
||||
if($userRoles == null){
|
||||
$userRoles = array();
|
||||
@ -403,10 +360,58 @@ function user_get_fields($userRoles = null){
|
||||
}
|
||||
switch($fieldName){
|
||||
case 'languages':
|
||||
$fields[$fieldName]['type'] = 'multiselect';
|
||||
$fields[$fieldName]['options'] = array();
|
||||
$query = mysql_query("SELECT lang, langname FROM languages WHERE active = 'Y'");
|
||||
while($row = mysql_fetch_assoc($query)){
|
||||
$fields[$fieldName]['options'][$row['lang']] = $row['langname'];
|
||||
}
|
||||
break;
|
||||
case 'cat_prefs':
|
||||
$fields[$fieldName]['description'] = 'Preference levels for judging individual project categories';
|
||||
$fields[$fieldName]['type'] = 'singleselectlist';
|
||||
$fields[$fieldName]['options'] = array(-2 => 'Very Low', -1 => 'Low', 0 => 'Indifferent', 1 => 'Medium', 2 => 'High');
|
||||
$fields[$fieldName]['entries'] = array();
|
||||
$query = mysql_query("SELECT id, category FROM projectcategories WHERE conferences_id = {$conference['id']}");
|
||||
while($row = mysql_fetch_assoc($query)){
|
||||
$fields[$fieldName]['entries'][$row['id']] = $row['category'];
|
||||
}
|
||||
break;
|
||||
case 'div_prefs':
|
||||
$divquery = mysql_query("SELECT * FROM projectdivisions WHERE conferences_id = {$conference['id']}");
|
||||
$fields[$fieldName]['entries'] = array();
|
||||
$fields[$fieldName]['type'] = 'singleselectlist';
|
||||
$fields[$fieldName]['options'] = array(1 => 'Very Little', 2 => 'Little', 3 => 'Average', 4 => 'Knowledgable', 5 => 'Very Knowledgable');
|
||||
while($divdata = mysql_fetch_assoc($divquery)){
|
||||
$divid = $divdata['id'];
|
||||
$fields[$fieldName]['entries'][$divdata['id']] = $divdata['division'];/*
|
||||
$subdivquery = mysql_query("SELECT * FROM projectsubdivisions WHERE conferences_id = {$conference['id']} AND projectdivisions_id = $divid");
|
||||
while($subdivdata = mysql_fetch_assoc($subdivquery)){
|
||||
$divisions[$divdata['division']][$subdivdata['id']] = $subdivdata['subdivision'];
|
||||
}*/
|
||||
}
|
||||
break;
|
||||
case 'divsub_prefs':
|
||||
// cases not yet handled
|
||||
$fields[$fieldName]['entries'] = array();
|
||||
$fields[$fieldName]['description'] = "Preference levels for subdivisions of existing divisions. If a division has subdivisions, they";
|
||||
$fields[$fieldName]['description'] .= " are listed in an array which is stored within the 'entries' array at the index of the division's id.";
|
||||
$fields[$fieldName]['description'] .= " eg. If a division 'foo' has an id of '3' and the subdivisions 'bar1' and 'bar2', then entries[3]";
|
||||
$fields[$fieldName]['description'] .= " will be an array: {0 => 'bar1', 1 => 'bar2'}.";
|
||||
$fields[$fieldName]['type'] = 'singleselectlist';
|
||||
$fields[$fieldName]['options'] = array(1 => 'Very Little', 2 => 'Little', 3 => 'Average', 4 => 'Knowledgable', 5 => 'Very Knowledgable');
|
||||
$divquery = mysql_query("SELECT * FROM projectdivisions WHERE conferences_id = {$conference['id']}");
|
||||
while($divdata = mysql_fetch_assoc($divquery)){
|
||||
$divid = $divdata['id'];
|
||||
// $fields[$fieldName]['entries'][$divdata['id']] = array('division' => $divdata['division']);
|
||||
$subset = array();
|
||||
$subdivquery = mysql_query("SELECT * FROM projectsubdivisions WHERE conferences_id = {$conference['id']} AND projectdivisions_id = $divid");
|
||||
while($subdivdata = mysql_fetch_assoc($subdivquery)){
|
||||
$subset[] = $subdivdata['subdivision'];
|
||||
}
|
||||
if(count($subset)){
|
||||
$fields[$fieldName]['entries'][$divdata['id']] = $subset;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@ -417,7 +422,7 @@ function user_get_fields($userRoles = null){
|
||||
$parts = explode('(', $parts[0]);
|
||||
$fields[$fieldName]['type'] = $parts[0] . ':' . $parts[1];
|
||||
}else if(!strncasecmp($ftype, "enum", 4)){
|
||||
$fields[$fieldName]['type'] = 'enum';
|
||||
$fields[$fieldName]['type'] = 'singleselect';
|
||||
$fields[$fieldName]['options'] = array();
|
||||
$parts = explode("'", $ftype);
|
||||
for($n = 1; $n < count($parts); $n += 2){
|
||||
@ -435,12 +440,6 @@ function user_get_fields($userRoles = null){
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
echo "<pre>";
|
||||
print_r(($userRoles));
|
||||
print_r($fields);
|
||||
echo "</pre>";
|
||||
*/
|
||||
return $fields;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user