Fix 129 update user inc to avoid collisions in functions names

This commit is contained in:
james 2009-10-22 16:14:29 +00:00
parent 233ee6ca95
commit ed863286cd

View File

@ -29,7 +29,7 @@ $user_what = array('student'=>'Participant', 'judge' => 'Judge',
'committee'=>'Committee Member','volunteer' => 'Volunteer', 'committee'=>'Committee Member','volunteer' => 'Volunteer',
'fair'=>'Science Fair','sponsor' => 'Sponsor Contact'); 'fair'=>'Science Fair','sponsor' => 'Sponsor Contact');
function user_valid_type($type) function db129_user_valid_type($type)
{ {
global $user_types; global $user_types;
if(is_array($type)) { if(is_array($type)) {
@ -44,7 +44,7 @@ function user_valid_type($type)
/* Duplicate of common.inc.php:generatePassword, which will be deleted /* Duplicate of common.inc.php:generatePassword, which will be deleted
* eventually when ALL users are handled through this file */ * eventually when ALL users are handled through this file */
function user_generate_password($pwlen=8) function db129_user_generate_password($pwlen=8)
{ {
//these are good characters that are not easily confused with other characters :) //these are good characters that are not easily confused with other characters :)
$available="ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz23456789"; $available="ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz23456789";
@ -60,7 +60,7 @@ function user_generate_password($pwlen=8)
/* Separate user_load_type functions, these could make additional database /* Separate user_load_type functions, these could make additional database
* calls if required */ * calls if required */
function user_load_fair(&$u) function db129_user_load_fair(&$u)
{ {
$u['fair_active'] = ($u['fair_active'] == 'yes') ? 'yes' : 'no'; $u['fair_active'] = ($u['fair_active'] == 'yes') ? 'yes' : 'no';
$u['fair_complete'] = ($u['fair_complete'] == 'yes') ? 'yes' : 'no'; $u['fair_complete'] = ($u['fair_complete'] == 'yes') ? 'yes' : 'no';
@ -69,13 +69,13 @@ function user_load_fair(&$u)
return true; return true;
} }
function user_load_student(&$u) function db129_user_load_student(&$u)
{ {
// $u['student_active'] = ($u['student_active'] == 'yes') ? 'yes' : 'no'; // $u['student_active'] = ($u['student_active'] == 'yes') ? 'yes' : 'no';
// $u['student_complete'] = ($u['student_complete'] == 'yes') ? 'yes' : 'no'; // $u['student_complete'] = ($u['student_complete'] == 'yes') ? 'yes' : 'no';
return false; return false;
} }
function user_load_judge(&$u) function db129_user_load_judge(&$u)
{ {
$u['judge_active'] = ($u['judge_active'] == 'yes') ? 'yes' : 'no'; $u['judge_active'] = ($u['judge_active'] == 'yes') ? 'yes' : 'no';
$u['judge_complete'] = ($u['judge_complete'] == 'yes') ? 'yes' : 'no'; $u['judge_complete'] = ($u['judge_complete'] == 'yes') ? 'yes' : 'no';
@ -101,7 +101,7 @@ function user_load_judge(&$u)
return true; return true;
} }
function user_load_committee(&$u) function db129_user_load_committee(&$u)
{ {
$u['committee_active'] = $u['committee_active']; $u['committee_active'] = $u['committee_active'];
$u['emailprivate'] = $u['emailprivate']; $u['emailprivate'] = $u['emailprivate'];
@ -113,14 +113,14 @@ function user_load_committee(&$u)
return true; return true;
} }
function user_load_volunteer(&$u) function db129_user_load_volunteer(&$u)
{ {
$u['volunteer_active'] = ($u['volunteer_active'] == 'yes') ? 'yes' : 'no'; $u['volunteer_active'] = ($u['volunteer_active'] == 'yes') ? 'yes' : 'no';
$u['volunteer_complete'] = ($u['volunteer_complete'] == 'yes') ? 'yes' : 'no'; $u['volunteer_complete'] = ($u['volunteer_complete'] == 'yes') ? 'yes' : 'no';
return true; return true;
} }
function user_load_sponsor($u) function db129_user_load_sponsor($u)
{ {
$u['sponsors_id'] = intval($u['sponsors_id']); $u['sponsors_id'] = intval($u['sponsors_id']);
$u['sponsor_complete'] = ($u['sponsor_complete'] == 'yes') ? 'yes' : 'no'; $u['sponsor_complete'] = ($u['sponsor_complete'] == 'yes') ? 'yes' : 'no';
@ -128,7 +128,7 @@ function user_load_sponsor($u)
return true; return true;
} }
function user_load($user, $uid = false) function db129_user_load($user, $uid = false)
{ {
/* 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
@ -180,9 +180,9 @@ function user_load($user, $uid = false)
foreach($ret['types'] as $t) { foreach($ret['types'] as $t) {
/* These all pass $ret by reference, and can modify /* These all pass $ret by reference, and can modify
* $ret */ * $ret */
$r = call_user_func("user_load_$t", &$ret); $r = call_user_func("db129_user_load_$t", &$ret);
if($r != true) { if($r != true) {
echo "user_load_$t returned false!\n"; echo "db129_user_load_$t returned false!\n";
return false; return false;
} }
@ -210,12 +210,12 @@ function user_load($user, $uid = false)
return $ret; return $ret;
} }
function user_load_by_uid($uid) function db129_user_load_by_uid($uid)
{ {
return user_load(0, $uid); return db129_user_load(0, $uid);
} }
function user_set_password($id, $password = NULL) function db129_user_set_password($id, $password = NULL)
{ {
/* pass $u by reference so we can update it */ /* pass $u by reference so we can update it */
$save_old = false; $save_old = false;
@ -223,7 +223,7 @@ function user_set_password($id, $password = NULL)
$q = mysql_query("SELECT passwordset FROM users WHERE id='$id'"); $q = mysql_query("SELECT passwordset FROM users WHERE id='$id'");
$u = mysql_fetch_assoc($q); $u = mysql_fetch_assoc($q);
/* Generate a new password */ /* Generate a new password */
$password = user_generate_password(12); $password = db129_user_generate_password(12);
/* save the old password only if it's not an auto-generated one */ /* save the old password only if it's not an auto-generated one */
if($u['passwordset'] != '0000-00-00') $save_old = true; if($u['passwordset'] != '0000-00-00') $save_old = true;
/* Expire the password */ /* Expire the password */
@ -245,7 +245,7 @@ function user_set_password($id, $password = NULL)
return $password; return $password;
} }
function user_save_type_list($u, $db, $fields) function db129_user_save_type_list($u, $db, $fields)
{ {
//echo "<pre>"; //echo "<pre>";
// print_r($u); // print_r($u);
@ -280,47 +280,47 @@ function user_save_type_list($u, $db, $fields)
} }
} }
function user_save_volunteer($u) function db129_user_save_volunteer($u)
{ {
$fields = array('volunteer_active','volunteer_complete'); $fields = array('volunteer_active','volunteer_complete');
user_save_type_list($u, 'users_volunteer', $fields); db129_user_save_type_list($u, 'users_volunteer', $fields);
} }
function user_save_committee($u) function db129_user_save_committee($u)
{ {
$fields = array('committee_active','emailprivate','ord','displayemail','access_admin', $fields = array('committee_active','emailprivate','ord','displayemail','access_admin',
'access_config','access_super'); 'access_config','access_super');
user_save_type_list($u, 'users_committee', $fields); db129_user_save_type_list($u, 'users_committee', $fields);
} }
function user_save_judge($u) function db129_user_save_judge($u)
{ {
$fields = array('judge_active','judge_complete','years_school','years_regional','years_national', $fields = array('judge_active','judge_complete','years_school','years_regional','years_national',
'willing_chair','special_award_only', 'willing_chair','special_award_only',
'cat_prefs','div_prefs','divsub_prefs', 'cat_prefs','div_prefs','divsub_prefs',
'expertise_other','languages', 'highest_psd'); 'expertise_other','languages', 'highest_psd');
user_save_type_list($u, 'users_judge', $fields); db129_user_save_type_list($u, 'users_judge', $fields);
} }
function user_save_student($u) function db129_user_save_student($u)
{ {
// $fields = array('student_active','student_complete'); // $fields = array('student_active','student_complete');
// user_save_type_list($u, 'users_student', $fields); // user_save_type_list($u, 'users_student', $fields);
} }
function user_save_fair($u) function db129_user_save_fair($u)
{ {
$fields = array('fair_active','fairs_id'); $fields = array('fair_active','fairs_id');
user_save_type_list($u, 'users_fair', $fields); db129_user_save_type_list($u, 'users_fair', $fields);
} }
function user_save_sponsor($u) function db129_user_save_sponsor($u)
{ {
$fields = array('sponsors_id','sponsor_active','sponsor_complete','primary','position','notes'); $fields = array('sponsors_id','sponsor_active','sponsor_complete','primary','position','notes');
user_save_type_list($u, 'users_sponsor', $fields); db129_user_save_type_list($u, 'users_sponsor', $fields);
} }
function user_save($u) function db129_user_save($u)
{ {
$fields = array('salutation','firstname','lastname','username', $fields = array('salutation','firstname','lastname','username',
'email', 'email',
@ -352,26 +352,26 @@ function user_save($u)
/* Save the password if it changed */ /* Save the password if it changed */
if($u['password'] != $u['orig']['password']) if($u['password'] != $u['orig']['password'])
user_set_password($u['id'], $u['password']); db129_user_set_password($u['id'], $u['password']);
foreach($u['types'] as $t) { foreach($u['types'] as $t) {
call_user_func("user_save_$t", $u); call_user_func("db129_user_save_$t", $u);
} }
} }
/* Delete functions. These mark a user as deleted, and delete references to other /* Delete functions. These mark a user as deleted, and delete references to other
* tables */ * tables */
function user_delete_committee($u) function db129_user_delete_committee($u)
{ {
mysql_query("DELETE FROM committees_link WHERE users_uid='{$u['uid']}'"); mysql_query("DELETE FROM committees_link WHERE users_uid='{$u['uid']}'");
} }
function user_delete_volunteer($u) function db129_user_delete_volunteer($u)
{ {
} }
function user_delete_judge($u) function db129_user_delete_judge($u)
{ {
global $config; global $config;
$id = $u['id']; $id = $u['id'];
@ -379,24 +379,24 @@ function user_delete_judge($u)
mysql_query("DELETE FROM judges_specialawards_sel WHERE users_id='$id'"); mysql_query("DELETE FROM judges_specialawards_sel WHERE users_id='$id'");
} }
function user_delete_fair($u) function db129_user_delete_fair($u)
{ {
} }
function user_delete_student($u) function db129_user_delete_student($u)
{ {
} }
function user_delete_sponsor($u) function db129_user_delete_sponsor($u)
{ {
} }
function user_delete($u, $type=false) function db129_user_delete($u, $type=false)
{ {
$finish_delete = false; $finish_delete = false;
if(!is_array($u)) { if(!is_array($u)) {
$u = user_load($u); $u = db129_user_load($u);
} }
if($type != false) { if($type != false) {
if(!in_array($type, $u['types'])) { if(!in_array($type, $u['types'])) {
@ -416,10 +416,10 @@ function user_delete($u, $type=false)
} else { } else {
$finish_delete = true; $finish_delete = true;
} }
call_user_func("user_delete_$type", $u); call_user_func("db129_user_delete_$type", $u);
} else { } else {
/* Delete the whole user */ /* Delete the whole user */
foreach($u['types'] as $t) call_user_func("user_delete_$t", $u); foreach($u['types'] as $t) call_user_func("db129_user_delete_$t", $u);
$finish_delete = true; $finish_delete = true;
} }
if($finish_delete == true) { if($finish_delete == true) {
@ -432,12 +432,12 @@ function user_delete($u, $type=false)
* database. This action cannot be undone. We prefer the committee to use the * database. This action cannot be undone. We prefer the committee to use the
* "delete" functions, which simply mark the account as "deleted". */ * "delete" functions, which simply mark the account as "deleted". */
function user_purge($u, $type=false) function db129_user_purge($u, $type=false)
{ {
$finish_purge = false; $finish_purge = false;
if(!is_array($u)) { if(!is_array($u)) {
$u = user_load($u); $u = db129_user_load($u);
} }
if($type != false) { if($type != false) {
if(!in_array($type, $u['types'])) { if(!in_array($type, $u['types'])) {
@ -459,13 +459,13 @@ function user_purge($u, $type=false)
} }
/* Call the delete func to deal with table linking, then completely wipe /* Call the delete func to deal with table linking, then completely wipe
* out the entry */ * out the entry */
call_user_func("user_delete_$type", $u); call_user_func("db129_user_delete_$type", $u);
// call_user_func("user_purge_$type", $u); // call_user_func("user_purge_$type", $u);
mysql_query("DELETE FROM users_$type WHERE users_id='{$u['id']}'"); mysql_query("DELETE FROM users_$type WHERE users_id='{$u['id']}'");
} else { } else {
/* Delete the whole user */ /* Delete the whole user */
foreach($u['types'] as $t) { foreach($u['types'] as $t) {
call_user_func("user_delete_$t", $u); call_user_func("db129_user_delete_$t", $u);
// call_user_func("user_purge_$t", $u); // call_user_func("user_purge_$t", $u);
mysql_query("DELETE FROM users_$t WHERE users_id='{$u['id']}'"); mysql_query("DELETE FROM users_$t WHERE users_id='{$u['id']}'");
} }
@ -478,7 +478,7 @@ function user_purge($u, $type=false)
/* Duplicate a row in the users table, or any one of the users_* tables. */ /* Duplicate a row in the users table, or any one of the users_* tables. */
function user_dupe_row($db, $key, $val, $newval) function db129_user_dupe_row($db, $key, $val, $newval)
{ {
global $config; global $config;
$nullfields = array('deleteddatetime'); /* Fields that can be null */ $nullfields = array('deleteddatetime'); /* Fields that can be null */
@ -511,7 +511,7 @@ function user_dupe_row($db, $key, $val, $newval)
return $id; return $id;
} }
/* Used by the login scripts to copy one user from one year to another */ /* Used by the login scripts to copy one user from one year to another */
function user_dupe($u, $new_year) function db129_user_dupe($u, $new_year)
{ {
/* Dupe a user if: /* Dupe a user if:
* - They don't exist in the current year * - They don't exist in the current year
@ -533,14 +533,14 @@ function user_dupe($u, $new_year)
exit; exit;
} }
$id = user_dupe_row('users', 'id', $u['id'], NULL); $id = db129_user_dupe_row('users', 'id', $u['id'], NULL);
$q = mysql_query("UPDATE users SET year='$new_year' WHERE id='$id'"); $q = mysql_query("UPDATE users SET year='$new_year' WHERE id='$id'");
/* Load the new user */ /* Load the new user */
$u2 = user_load($id); $u2 = db129_user_load($id);
foreach($u2['types'] as $t) { foreach($u2['types'] as $t) {
user_dupe_row("users_$t", 'users_id', $u['id'], $id); db129_user_dupe_row("users_$t", 'users_id', $u['id'], $id);
} }
/* Return the ID of the new user */ /* Return the ID of the new user */
return $id; return $id;
@ -549,7 +549,7 @@ function user_dupe($u, $new_year)
/* Returns true if loaded user ($u) is allowed to add role type $type to their /* Returns true if loaded user ($u) is allowed to add role type $type to their
* profile. THis is intended as a last-stop mechanism, preventing, for example * profile. THis is intended as a last-stop mechanism, preventing, for example
* a student from co-existing with any other account type. */ * a student from co-existing with any other account type. */
function user_add_role_allowed($type, $u) function db129_user_add_role_allowed($type, $u)
{ {
/* For example, a committee member can add a volunteer or judge role to /* For example, a committee member can add a volunteer or judge role to
* their account. */ * their account. */
@ -568,7 +568,7 @@ function user_add_role_allowed($type, $u)
return false; return false;
} }
function user_create($type, $username, $u = NULL) function db129_user_create($type, $username, $u = NULL)
{ {
global $config; global $config;
if(!is_array($u)) { if(!is_array($u)) {
@ -577,12 +577,12 @@ function user_create($type, $username, $u = NULL)
echo mysql_error(); echo mysql_error();
$uid = mysql_insert_id(); $uid = mysql_insert_id();
mysql_query("UPDATE users SET uid='$uid' WHERE id='$uid'"); mysql_query("UPDATE users SET uid='$uid' WHERE id='$uid'");
user_set_password($uid, NULL); db129_user_set_password($uid, NULL);
} else { } else {
/* The user has been specified and already exists, /* The user has been specified and already exists,
* just add a role */ * just add a role */
$uid = $u['id']; $uid = $u['id'];
if(!user_add_role_allowed($type, $u)) { if(!db129_user_add_role_allowed($type, $u)) {
/* If we get in here, someone is hand crafting URLs */ /* If we get in here, someone is hand crafting URLs */
echo "HALT: invalid role add specified for operation."; echo "HALT: invalid role add specified for operation.";
exit; exit;
@ -611,11 +611,11 @@ function user_create($type, $username, $u = NULL)
mysql_query("INSERT INTO users_sponsor(`users_id`) VALUES ('$uid')"); mysql_query("INSERT INTO users_sponsor(`users_id`) VALUES ('$uid')");
break; break;
} }
return user_load($uid); return db129_user_load($uid);
} }
function user_valid_user($user) function db129_user_valid_user($user)
{ {
/* Find any character that doesn't match the valid username characters /* Find any character that doesn't match the valid username characters
* (^ inverts the matching remember */ * (^ inverts the matching remember */
@ -625,7 +625,7 @@ function user_valid_user($user)
return ($x == 1) ? false : true; return ($x == 1) ? false : true;
} }
function user_valid_password($pass) function db129_user_valid_password($pass)
{ {
/* Same as user, but allow more characters */ /* Same as user, but allow more characters */
$x = preg_match('[^a-zA-Z0-9 ~!@#$%^&*()-_=+|;:,<.>/?]',$pass); $x = preg_match('[^a-zA-Z0-9 ~!@#$%^&*()-_=+|;:,<.>/?]',$pass);
@ -639,7 +639,7 @@ function user_valid_password($pass)
} }
/* A more strict version of isEmailAddress() */ /* A more strict version of isEmailAddress() */
function user_valid_email($str) function db129_user_valid_email($str)
{ {
if(eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$', $str)) if(eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$', $str))
return true; return true;
@ -650,7 +650,7 @@ function user_valid_email($str)
/* Perform some checks. Make sure the person is logged in, and that their /* Perform some checks. Make sure the person is logged in, and that their
* password hasn't expired (the password_expired var is set in the login page) * password hasn't expired (the password_expired var is set in the login page)
*/ */
function user_auth_required($type, $access='') function db129_user_auth_required($type, $access='')
{ {
global $config; global $config;
if(!isset($_SESSION['users_type'])) { if(!isset($_SESSION['users_type'])) {
@ -686,7 +686,7 @@ function user_auth_required($type, $access='')
} }
function user_volunteer_registration_status() function db129_user_volunteer_registration_status()
{ {
global $config; global $config;
// $now = date('Y-m-d H:i:s'); // $now = date('Y-m-d H:i:s');
@ -695,7 +695,7 @@ function user_volunteer_registration_status()
return "open"; return "open";
} }
function user_judge_registration_status() function db129_user_judge_registration_status()
{ {
global $config; global $config;
$now = date('Y-m-d H:i:s'); $now = date('Y-m-d H:i:s');
@ -721,7 +721,7 @@ $user_personal_fields_map = array(
'province' => array('province'), 'province' => array('province'),
'firstaid' => array('firstaid','cpr')); 'firstaid' => array('firstaid','cpr'));
function user_personal_fields($type) function db129_user_personal_fields($type)
{ {
global $config, $user_personal_fields_map; global $config, $user_personal_fields_map;
$ret = array('firstname','lastname','email'); $ret = array('firstname','lastname','email');
@ -735,7 +735,7 @@ function user_personal_fields($type)
return $ret; return $ret;
} }
function user_personal_required_fields($type) function db129_user_personal_required_fields($type)
{ {
global $config, $user_personal_fields_map; global $config, $user_personal_fields_map;
$ret = array('firstname','lastname','email'); $ret = array('firstname','lastname','email');
@ -753,12 +753,12 @@ function user_personal_required_fields($type)
return $ret; return $ret;
} }
function user_personal_info_status(&$u) function db129_user_personal_info_status(&$u)
{ {
$required = array(); $required = array();
foreach($u['types'] as $t) { foreach($u['types'] as $t) {
$required = array_merge($required, $required = array_merge($required,
user_personal_required_fields($t)); db129_user_personal_required_fields($t));
} }
foreach($required as $r) { foreach($required as $r) {
$val = trim($u[$r]); $val = trim($u[$r]);
@ -769,13 +769,13 @@ function user_personal_info_status(&$u)
return 'incomplete'; return 'incomplete';
} }
} }
/* FIXME: somehow call the $type _status_update() function to update /* FIXME: somehow call the $type _status_update() function db129_to update
* the individual $type _complete entry? */ * the individual $type _complete entry? */
return 'complete'; return 'complete';
} }
/* user_{$type}_login() is called with a full $u loaded */ /* user_{$type}_login() is called with a full $u loaded */
function user_committee_login($u) function db129_user_committee_login($u)
{ {
/* Double check, make sure the user is of this type */ /* Double check, make sure the user is of this type */
if(!in_array('committee', $u['types'])) { if(!in_array('committee', $u['types'])) {
@ -788,7 +788,7 @@ function user_committee_login($u)
$_SESSION['access_super'] = $u['access_super'];// == 'yes') ? true : false; $_SESSION['access_super'] = $u['access_super'];// == 'yes') ? true : false;
} }
function user_fair_login($u) function db129_user_fair_login($u)
{ {
/* Double check, make sure the user is of this type */ /* Double check, make sure the user is of this type */
if(!in_array('fair', $u['types'])) { if(!in_array('fair', $u['types'])) {