Copyright (C) 2005 James Grant Copyright (C) 2007 David Grant This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ require_once("common.inc.php"); require_once("user.inc.php"); user_auth_required(); // find out if this user actually is in this conference $query = "SELECT COUNT(*) FROM users WHERE conferences_id = {$_SESSION['conferences_id']}" . " AND accounts_id = " . $_SESSION['accounts_id']; $data = mysql_fetch_array(mysql_query($query)); if($data[0] == 0){ // They're not actually connected to this conference, let's hook 'em up $u = user_create($_SESSION['accounts_id'], $_SESSION['conferences_id']); $_SESSION['users_id'] = $u['id']; } $u = user_load($_SESSION['users_id']); if(array_key_exists('action', $_GET)){ switch($_GET['action']){ case 'register': $role = $_POST['role']; $result = account_add_role($u['accounts_id'], $roles[$role]['id'], $_SESSION['conferences_id'], $_POST['password']); echo $result; // register_new_role(); break; case 'draw_roles': draw_roles(); break; case 'remove': $role = $_GET['role']; /* Like delete, only we're only deleting a role, not the whole account */ happy_("{$roles[$role]['name']} role successfully removed."); echo i18n("Removed"); user_remove_role($u, $role); exit; case 'activate': $role = $_GET['role']; if(!array_key_exists($role, $u['roles'])) { /* Hand crafting URLs? */ echo "HALT: can't activate a role the user doesn't have"; exit; } $u['roles'][$role]['active'] = 'yes'; user_save($u); happy_("{$roles[$role]['name']} role for %1 successfully activated",array($config['FAIRYEAR'])); echo i18n("Active"); exit; 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; default: break; } exit; } send_header("Main Page", array()); // throw in our javascript functions ?>

"; //only display the named greeting if we have their name echo i18n("Hello %1",array($_SESSION['name'])); echo "

This is a placeholder for the main user page until all the specific user-role pages are removed. For now, here's what you can do:

"; draw_roles(); echo "
"; echo i18n('Other Options and Things To Do').':
'; echo ''; send_footer(); function draw_roles(){ // get a list of all roles that this user can potentially sign up for global $u, $config; $rlist = array(); $q = mysql_query("SELECT * FROM roles"); $available = array(); $registered = array(); while($row = mysql_fetch_assoc($q)){ $roleid = $row['type']; $idx = $roleid . "_registration_type"; if(array_key_exists($idx, $config)){ // this is a role that can potentially be registered for if(is_array($u['roles']) && array_key_exists($row['type'], $u['roles'])){ $registered[$row['type']] = $row['name']; }else{ $available[$row['type']] = $row['name']; } } } echo '
'; if(count($registered) > 0){ $rowNumber = 0; echo "

" . i18n("You are currently registered for the following roles") . ":

"; echo '
'; echo ""; foreach($registered as $role => $title){ echo ''; echo ""; if($u['roles'][$role]['active'] == 'yes') { $cs = i18n('Active'); $cl = 'happy'; $a = 'disabled="disabled"'; $d = ''; } else { $cs = i18n('Deactivated'); $cl = 'notice'; $a = ''; $d = 'disabled="disabled"'; } ?> "; } echo "
" . i18n($title) . "
"; } if(count($available) > 0){ echo "

" . i18n("The following roles are available") . ":

"; $rowNumber = 0; echo ""; foreach($available as $type => $title){ echo ''; echo ""; } echo "
$title"; draw_signup_form($type); echo "
"; } echo "
"; } function draw_signup_form($type){ global $config; global $roles; switch($type) { case 'volunteer': $reg_open = user_volunteer_registration_status(); $reg_mode = $config['volunteer_registration_type']; // $reg_single_password = $config['volunteer_registration_singlepassword']; // $password_expiry_days = $config['volunteer_password_expiry_days']; // $welcome_email = "volunteer_welcome"; break; /*case 'committee': $reg_open = 'notpermitted'; $reg_mode = 'closed'; $reg_single_password = ''; $password_expiry_days = 0; $welcome_email = false; break; */ case 'judge': $reg_open = user_judge_registration_status(); $reg_mode = $config['judge_registration_type']; // $reg_single_password = $config['judge_registration_singlepassword']; // $password_expiry_days = $config['judges_password_expiry_days']; // $welcome_email = "judge_welcome"; break; /* case 'student': $reg_open = 'closed'; // $reg_mode = $config['judge_registration_type']; // $reg_single_password = $config['judge_registration_singlepassword']; $password_expiry_days = 0; $welcome_email = "register_students_welcome"; break; */ default: echo "Not handled"; return; } if($reg_open == 'open'){ switch($reg_mode){ case 'open': echo "\"$reg_mode\" registration is not yet handled"; break; case 'singlepassword': echo '

'; echo i18n("{$roles[$type]['name']} Registration is protected by a password. You must know the {$roles[$type]['name']} Registration Password in order to create an account. Please contact the committee to obtain the password if you wish to register."); echo "

"; echo i18n("{$roles[$type]['name']} Password").":"; echo ""; echo "

"; break; case 'schoolpassword': echo "\"$reg_mode\" registration is not yet handled"; break; case 'invite': output_page_text("register_{$type}_invite"); break; case 'openorinvite': echo "\"$reg_mode\" registration is not yet handled"; break; default: echo "Unhandled registration mode: $reg_mode"; } }else{ echo i18n("{$roles[$type]['name']} registration is not open"); } } function register_new_role(){ global $config, $roles, $u; $password = $_POST['password']; $uid = $_SESSION['users_id']; $roleId = $_POST['role']; $typekey = $roleId . '_registration_type'; $accounts_id = $u['accounts_id']; if(array_key_exists($typekey, $config)){ $regtype = $config[$typekey]; }else{ return false; } // see if the registration is allowed for this role with the information provided $canRegister = true; $role = $_POST['role']; switch($regtype){ case 'open': case 'openorinvite': // ok, we can allow these break; case 'singlepassword': if($password != $config[$role . '_registration_singlepassword']){ $canRegister = false; } break; case 'schoolpassword': // FIXME: not yet implemented. // this is only used for students, who are not yet registered through the "user" system $canRegister = false; break; case 'invite': $canRegister = false; break; default: // echo "[\$regtype = \"$regtype\"]"; $canRegister = false; } if(!$canRegister) return false; // ok, they meet the conditions to register for this role // see if they're already registered for it $role_index = $roles[$role]['id']; $query = "SELECT COUNT(*) FROM user_roles WHERE users_id = $uid AND roles_id=$role_index"; echo $query; $results = mysql_fetch_array(mysql_query($query)); if($results[0] != 0){ return false; } if(user_add_role($u, $role, $password)){ $_SESSION['roles'][] = $role; user_save($u); return true; }else{ return false; } }