From 241618c74fe533d75303f3039b28f10c9c920756 Mon Sep 17 00:00:00 2001 From: james Date: Thu, 14 Oct 2010 20:31:10 +0000 Subject: [PATCH] Fix saving active/deactive roles Fix the session roles when roles are modified and only put 'active' ones into the session roles array --- common.inc.php | 6 ------ config/dates.php | 2 ++ tableeditor.css | 4 ++-- user.inc.php | 35 +++++++++++++++++------------------ user_main.php | 23 ++++++++++------------- 5 files changed, 31 insertions(+), 39 deletions(-) diff --git a/common.inc.php b/common.inc.php index 66db37f..b4ac115 100644 --- a/common.inc.php +++ b/common.inc.php @@ -273,12 +273,6 @@ if(array_key_exists('users_id', $_SESSION)) { if(in_array('sponsor', $_SESSION['roles'])) { // echo "
  • ".i18n("Sponsor Home").'
  • '; } - /* 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 "
  • ".i18n("School Home").'
  • '; - echo "
  • ".i18n("Logout").'
  • '; - } if(in_array('student', $_SESSION['roles'])) { echo "
  • ".i18n("Participant Home").'
  • '; } diff --git a/config/dates.php b/config/dates.php index be5fe25..b2a76d1 100644 --- a/config/dates.php +++ b/config/dates.php @@ -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()); diff --git a/tableeditor.css b/tableeditor.css index 21c4cda..c1c3f34 100644 --- a/tableeditor.css +++ b/tableeditor.css @@ -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 { diff --git a/user.inc.php b/user.inc.php index 0ce7540..ab0cd75 100644 --- a/user.inc.php +++ b/user.inc.php @@ -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 diff --git a/user_main.php b/user_main.php index 011b3f3..15789c0 100644 --- a/user_main.php +++ b/user_main.php @@ -4,7 +4,7 @@ SFIAB Website: http://www.sfiab.ca Copyright (C) 2005 Sci-Tech Ontario Inc - Copyright (C) 2005 James Grant + Copyright (C) 2005-2010 James Grant Copyright (C) 2007 David Grant 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; }