forked from science-ation/science-ation
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:
parent
ba793ac8e0
commit
241618c74f
@ -273,12 +273,6 @@ if(array_key_exists('users_id', $_SESSION)) {
|
|||||||
if(in_array('sponsor', $_SESSION['roles'])) {
|
if(in_array('sponsor', $_SESSION['roles'])) {
|
||||||
// echo "<li><a href=\"{$config['SFIABDIRECTORY']}/sponsor_main.php\">".i18n("Sponsor Home").'</a></li>';
|
// 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'])) {
|
if(in_array('student', $_SESSION['roles'])) {
|
||||||
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/register_participants_main.php\">".i18n("Participant Home").'</a></li>';
|
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/register_participants_main.php\">".i18n("Participant Home").'</a></li>';
|
||||||
}
|
}
|
||||||
|
@ -80,6 +80,8 @@ $possibledates['sciencefair'] = array('fairdate' => array() ,
|
|||||||
$possibledates['scienceolympics'] = array('fairdate' => array() ,
|
$possibledates['scienceolympics'] = array('fairdate' => array() ,
|
||||||
'regopen' => array(),
|
'regopen' => array(),
|
||||||
'regclose' => array(),
|
'regclose' => array(),
|
||||||
|
'judgeregopen' => array(),
|
||||||
|
'judgeregclose' => array(),
|
||||||
'postparticipants' => array(),
|
'postparticipants' => array(),
|
||||||
'postwinners' => array());
|
'postwinners' => array());
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
.tableedit select {
|
.tableedit select {
|
||||||
font-size: 1.0em;
|
font-size: 1.2em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tableedit input {
|
.tableedit input {
|
||||||
font-size: 1.0em;
|
font-size: 1.2em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tableview * .happy {
|
.tableview * .happy {
|
||||||
|
29
user.inc.php
29
user.inc.php
@ -173,6 +173,8 @@ function user_load($users_id, $accounts_id = false)
|
|||||||
$u['div_prefs'] = (strlen($u['div_prefs']) > 0) ? unserialize($u['div_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['divsub_prefs'] = (strlen($u['divsub_prefs']) > 0) ? unserialize($u['divsub_prefs']) : array();
|
||||||
// $u['expertise_other'] = $u['expertise_other'];
|
// $u['expertise_other'] = $u['expertise_other'];
|
||||||
|
//if it hasnt been parsed/converted yet
|
||||||
|
if(!is_array($u['languages']))
|
||||||
$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'];
|
// $u['highest_psd'] = $u['highest_psd'];
|
||||||
|
|
||||||
@ -188,6 +190,8 @@ function user_load($users_id, $accounts_id = false)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'volunteer':
|
case 'volunteer':
|
||||||
|
//if it hasnt been parsed/converted yet
|
||||||
|
if(!is_array($u['languages']))
|
||||||
$u['languages'] = (strlen($u['languages']) > 0) ? unserialize($u['languages']) : array();
|
$u['languages'] = (strlen($u['languages']) > 0) ? unserialize($u['languages']) : array();
|
||||||
$should_be_arrays = array('languages');
|
$should_be_arrays = array('languages');
|
||||||
break;
|
break;
|
||||||
@ -263,19 +267,12 @@ function user_save(&$u)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update all roles
|
// Update 'active' status for all roles
|
||||||
$new_roles = array_keys($u['roles']);
|
$new_roles = array_keys($u['roles']);
|
||||||
/*
|
|
||||||
foreach($new_roles as $r) {
|
foreach($new_roles as $r) {
|
||||||
if($u['roles'][$r] != $u['orig']['roles'][$r]) {
|
mysql_query("UPDATE user_roles SET active='{$u['roles'][$r]['active']}' WHERE roles_id='{$u['roles'][$r]['roles_id']}' AND users_id='{$u['id']}'");
|
||||||
// $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();
|
echo mysql_error();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
$fields = array('salutation','firstname','lastname',
|
$fields = array('salutation','firstname','lastname',
|
||||||
'phonehome','phonework','phonecell','fax','organization',
|
'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']['judgeregopen']) return "notopenyet";
|
||||||
if($now > $config['dates']['judgeregclose']) return "closed";
|
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";
|
return "open";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -913,6 +906,13 @@ function try_login($user, $pass)
|
|||||||
/* Login successful */
|
/* Login successful */
|
||||||
return $r['id'];
|
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) {
|
function user_conference_load($accounts_id,$conferences_id) {
|
||||||
global $config;
|
global $config;
|
||||||
@ -941,8 +941,7 @@ function user_conference_load($accounts_id,$conferences_id) {
|
|||||||
|
|
||||||
$_SESSION['name']="{$u['firstname']} {$u['lastname']}";
|
$_SESSION['name']="{$u['firstname']} {$u['lastname']}";
|
||||||
$_SESSION['users_id']=$u['id'];
|
$_SESSION['users_id']=$u['id'];
|
||||||
$_SESSION['roles']=array_keys($u['roles']);
|
updateSessionRoles();
|
||||||
|
|
||||||
/* Load the password expiry for each user role, and
|
/* Load the password expiry for each user role, and
|
||||||
* find the longest expiry, which is the one we'll use
|
* find the longest expiry, which is the one we'll use
|
||||||
* for this user to determine if the passwd has
|
* for this user to determine if the passwd has
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
SFIAB Website: http://www.sfiab.ca
|
SFIAB Website: http://www.sfiab.ca
|
||||||
|
|
||||||
Copyright (C) 2005 Sci-Tech Ontario Inc <info@scitechontario.org>
|
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>
|
Copyright (C) 2007 David Grant <dave@lightbox.org>
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
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']);
|
$u = user_load($_SESSION['users_id']);
|
||||||
if(array_key_exists('action', $_GET)){
|
if($u && array_key_exists('action', $_GET)){
|
||||||
switch($_GET['action']){
|
switch($_GET['action']){
|
||||||
|
case 'draw_roles':
|
||||||
|
draw_roles();
|
||||||
|
break;
|
||||||
|
|
||||||
case 'register':
|
case 'register':
|
||||||
$role = $_POST['role'];
|
$role = $_POST['role'];
|
||||||
$result = account_add_role($u['accounts_id'], $roles[$role]['id'], $_SESSION['conferences_id'], $_POST['password']);
|
$result = account_add_role($u['accounts_id'], $roles[$role]['id'], $_SESSION['conferences_id'], $_POST['password']);
|
||||||
if($result == 'ok'){
|
if($result == 'ok'){
|
||||||
// $u['roles'][$role] = array('active' =>'yes', 'complete' => 'no');
|
|
||||||
$_SESSION['roles'][] = $role;
|
|
||||||
// error_($result);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'draw_roles':
|
|
||||||
draw_roles();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'remove':
|
case 'remove':
|
||||||
$role = $_GET['role'];
|
$role = $_GET['role'];
|
||||||
@ -60,7 +58,7 @@ if(array_key_exists('action', $_GET)){
|
|||||||
}else{
|
}else{
|
||||||
error_(i18n("Unable to remove role."));
|
error_(i18n("Unable to remove role."));
|
||||||
}
|
}
|
||||||
exit;
|
break;
|
||||||
|
|
||||||
case 'activate':
|
case 'activate':
|
||||||
$role = $_GET['role'];
|
$role = $_GET['role'];
|
||||||
@ -73,25 +71,24 @@ if(array_key_exists('action', $_GET)){
|
|||||||
user_save($u);
|
user_save($u);
|
||||||
happy_("{$roles[$role]['name']} role for %1 successfully activated",array($config['FAIRYEAR']));
|
happy_("{$roles[$role]['name']} role for %1 successfully activated",array($config['FAIRYEAR']));
|
||||||
echo i18n("Active");
|
echo i18n("Active");
|
||||||
exit;
|
break;
|
||||||
|
|
||||||
case 'deactivate':
|
case 'deactivate':
|
||||||
$role = $_GET['role'];
|
$role = $_GET['role'];
|
||||||
if(!array_key_exists($role, $u['roles'])) {
|
if(!array_key_exists($role, $u['roles'])) {
|
||||||
/* Hand crafting URLs? */
|
/* Hand crafting URLs? */
|
||||||
echo "HALT: can't deactivate a role the user doesn't have";
|
echo "HALT: can't deactivate a role the user doesn't have";
|
||||||
exit;
|
|
||||||
}
|
}
|
||||||
$u['roles'][$role]['active'] = 'no';
|
$u['roles'][$role]['active'] = 'no';
|
||||||
user_save($u);
|
user_save($u);
|
||||||
happy_("{$roles[$role]['name']} role for %1 successfully deactivated",array($config['FAIRYEAR']));
|
happy_("{$roles[$role]['name']} role for %1 successfully deactivated",array($config['FAIRYEAR']));
|
||||||
echo i18n("Deactivated");
|
echo i18n("Deactivated");
|
||||||
exit;
|
break;
|
||||||
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
updateSessionRoles($u);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user