Fix saving active/deactive roles

Fix the session roles when roles are modified and only put 'active' ones into the session roles array
This commit is contained in:
james 2010-10-14 20:31:10 +00:00
parent ba793ac8e0
commit 241618c74f
5 changed files with 31 additions and 39 deletions

View File

@ -273,12 +273,6 @@ if(array_key_exists('users_id', $_SESSION)) {
if(in_array('sponsor', $_SESSION['roles'])) {
// echo "<li><a href=\"{$config['SFIABDIRECTORY']}/sponsor_main.php\">".i18n("Sponsor Home").'</a></li>';
}
/* FIXME: setting the schoolid should move to the user_login routine, so we can just test for
* the presence of the school/teacher/principal role here */
if($_SESSION['schoolid'] && $_SESSION['schoolaccesscode']) {
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/schoolaccess.php\">".i18n("School Home").'</a></li>';
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/schoolaccess.php?action=logout\">".i18n("Logout").'</a></li>';
}
if(in_array('student', $_SESSION['roles'])) {
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/register_participants_main.php\">".i18n("Participant Home").'</a></li>';
}

View File

@ -80,6 +80,8 @@ $possibledates['sciencefair'] = array('fairdate' => array() ,
$possibledates['scienceolympics'] = array('fairdate' => array() ,
'regopen' => array(),
'regclose' => array(),
'judgeregopen' => array(),
'judgeregclose' => array(),
'postparticipants' => array(),
'postwinners' => array());

View File

@ -1,9 +1,9 @@
.tableedit select {
font-size: 1.0em;
font-size: 1.2em;
}
.tableedit input {
font-size: 1.0em;
font-size: 1.2em;
}
.tableview * .happy {

View File

@ -173,7 +173,9 @@ function user_load($users_id, $accounts_id = false)
$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();
//if it hasnt been parsed/converted yet
if(!is_array($u['languages']))
$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 */
@ -188,7 +190,9 @@ function user_load($users_id, $accounts_id = false)
}
break;
case 'volunteer':
$u['languages'] = (strlen($u['languages']) > 0) ? unserialize($u['languages']) : array();
//if it hasnt been parsed/converted yet
if(!is_array($u['languages']))
$u['languages'] = (strlen($u['languages']) > 0) ? unserialize($u['languages']) : array();
$should_be_arrays = array('languages');
break;
@ -263,19 +267,12 @@ function user_save(&$u)
return -1;
}
// Update all roles
// Update 'active' status for all roles
$new_roles = array_keys($u['roles']);
/*
foreach($new_roles as $r) {
if($u['roles'][$r] != $u['orig']['roles'][$r]) {
// $u['roles'][$r] has changed from original, update it
mysql_query("UPDATE user_roles SET active='{$u['roles'][$r]['active']}',
complete='{$u['roles'][$r]['complete']}'
WHERE id='{$u['roles'][$r]['id']}'");
echo mysql_error();
}
mysql_query("UPDATE user_roles SET active='{$u['roles'][$r]['active']}' WHERE roles_id='{$u['roles'][$r]['roles_id']}' AND users_id='{$u['id']}'");
echo mysql_error();
}
*/
$fields = array('salutation','firstname','lastname',
'phonehome','phonework','phonecell','fax','organization',
@ -769,10 +766,6 @@ function user_judge_registration_status()
if($now < $config['dates']['judgeregopen']) return "notopenyet";
if($now > $config['dates']['judgeregclose']) return "closed";
}
if(array_key_exists('regopen', $config['dates'])){
if($now < $config['dates']['regopen']) return "notopenyet";
if($now > $config['dates']['regclose']) return "closed";
}
return "open";
}
@ -913,6 +906,13 @@ function try_login($user, $pass)
/* Login successful */
return $r['id'];
}
function updateSessionRoles($u) {
$_SESSION['roles']=array();
foreach($u['roles'] AS $r=>$rd) {
if($rd['active']=="yes")
$_SESSION['roles'][]=$r;
}
}
function user_conference_load($accounts_id,$conferences_id) {
global $config;
@ -941,8 +941,7 @@ function user_conference_load($accounts_id,$conferences_id) {
$_SESSION['name']="{$u['firstname']} {$u['lastname']}";
$_SESSION['users_id']=$u['id'];
$_SESSION['roles']=array_keys($u['roles']);
updateSessionRoles();
/* Load the password expiry for each user role, and
* find the longest expiry, which is the one we'll use
* for this user to determine if the passwd has

View File

@ -4,7 +4,7 @@
SFIAB Website: http://www.sfiab.ca
Copyright (C) 2005 Sci-Tech Ontario Inc <info@scitechontario.org>
Copyright (C) 2005 James Grant <james@lightbox.org>
Copyright (C) 2005-2010 James Grant <james@lightbox.org>
Copyright (C) 2007 David Grant <dave@lightbox.org>
This program is free software; you can redistribute it and/or
@ -37,20 +37,18 @@ if($data[0] == 0){
}
$u = user_load($_SESSION['users_id']);
if(array_key_exists('action', $_GET)){
if($u && array_key_exists('action', $_GET)){
switch($_GET['action']){
case 'draw_roles':
draw_roles();
break;
case 'register':
$role = $_POST['role'];
$result = account_add_role($u['accounts_id'], $roles[$role]['id'], $_SESSION['conferences_id'], $_POST['password']);
if($result == 'ok'){
// $u['roles'][$role] = array('active' =>'yes', 'complete' => 'no');
$_SESSION['roles'][] = $role;
// error_($result);
}
break;
case 'draw_roles':
draw_roles();
break;
case 'remove':
$role = $_GET['role'];
@ -60,7 +58,7 @@ if(array_key_exists('action', $_GET)){
}else{
error_(i18n("Unable to remove role."));
}
exit;
break;
case 'activate':
$role = $_GET['role'];
@ -73,25 +71,24 @@ if(array_key_exists('action', $_GET)){
user_save($u);
happy_("{$roles[$role]['name']} role for %1 successfully activated",array($config['FAIRYEAR']));
echo i18n("Active");
exit;
break;
case 'deactivate':
$role = $_GET['role'];
if(!array_key_exists($role, $u['roles'])) {
/* Hand crafting URLs? */
echo "HALT: can't deactivate a role the user doesn't have";
exit;
}
$u['roles'][$role]['active'] = 'no';
user_save($u);
happy_("{$roles[$role]['name']} role for %1 successfully deactivated",array($config['FAIRYEAR']));
echo i18n("Deactivated");
exit;
break;
default:
break;
}
updateSessionRoles($u);
exit;
}