From 052024b6d6131eb105cc5dc9fe4e3721dfe5d461 Mon Sep 17 00:00:00 2001 From: jacob Date: Tue, 5 Oct 2010 21:46:29 +0000 Subject: [PATCH] Updates for letting users register in roles. Incomplete --- user.inc.php | 6 ++ user_edit.php | 4 +- user_main.php | 203 +++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 208 insertions(+), 5 deletions(-) diff --git a/user.inc.php b/user.inc.php index f8aa686..aa51685 100644 --- a/user.inc.php +++ b/user.inc.php @@ -578,6 +578,12 @@ function user_create($accounts_id, $conferences_id=0) } } + /* No data available on the old user records, let's try getting it from the account then */ + $results = mysql_fetch_assoc(mysql_query("SELECT * FROM accounts WHERE id ='$accounts_id'")); + if(is_array($results)){ + $fields['username'] = $results['username']; + } + /* Create the user */ $fieldList = array_keys($fields); $query = "INSERT INTO users(`created`, `" . implode('`,`', $fieldList) . "`) VALUES(NOW(), '" . implode("','", $fields) . "')"; diff --git a/user_edit.php b/user_edit.php index edb25ab..b22d8ee 100644 --- a/user_edit.php +++ b/user_edit.php @@ -34,6 +34,7 @@ else user_auth_required(); if(array_key_exists('join', $_GET)){ + // this is a request to join this conference // get the corresponding account id to go with this user id if($edit_id == null){ @@ -48,14 +49,15 @@ if(array_key_exists('join', $_GET)){ $result = mysql_fetch_assoc($q); $edit_accounts_id = $result['accounts_id']; } + // find out if they're already a member of this conference $query = "SELECT COUNT(*) FROM users WHERE conferences_id = {$_SESSION['conferences_id']}" . " AND accounts_id = " . $edit_accounts_id; $data = mysql_fetch_array(mysql_query($query)); - if($data[0] == 0){ // apparently not - let's go ahead and hook them up $u = user_create($edit_accounts_id, $_SESSION['conferences_id']); + user_save($u); $edit_id = $u['id']; } }else{ diff --git a/user_main.php b/user_main.php index 62f7c2a..2f4012b 100644 --- a/user_main.php +++ b/user_main.php @@ -27,11 +27,48 @@ require_once("user.inc.php"); user_auth_required(); + // grab data for the available role types + $roleDat = array(); + $q = mysql_query("SELECT * FROM roles"); + while($row = mysql_fetch_assoc($q)){ + $roleDat[$row['type']] = array( + 'id' => $row['id'], + 'name' => $row['name'] + ); + } + $u = user_load($_SESSION['users_id']); - send_header("Main Page", array()); +if(array_key_exists('action', $_GET)){ + switch($_GET['action']){ + case 'register': + register_new_role(); + break; + default: + break; + } + exit; +} + + send_header("Main Page", array()); +?> + +%1",array($_SESSION['name'])); echo "
"; @@ -51,7 +88,7 @@ $idx = $roleid . "_registration_type"; if(array_key_exists($idx, $config)){ // this is a role that can potentially be registered for - if(is_array($user['roles']) && array_key_exists($row['type'], $user['roles'])){ + if(is_array($u['roles']) && array_key_exists($row['type'], $u['roles'])){ $registered[$row['type']] = $row['name']; }else{ $available[$row['type']] = $row['name']; @@ -69,10 +106,18 @@ if(count($available) > 0){ echo "

The following roles are available:

"; + $rowNumber = 0; + echo ""; foreach($available as $type => $title){ - echo "$title
"; + echo ''; + echo ""; } - echo "
"; + echo "
$title"; + draw_signup_form($type); + echo "
"; } echo "
"; @@ -85,4 +130,154 @@ echo '
  • '.i18n('To logout, use the "Logout" link in the upper-right of the page').'
  • '; echo ''; +/* +echo "
    ";
    +echo htmlentities(print_r($u, true));
    +echo htmlentities(print_r($config, true));
    +echo "
    "; +*/ + send_footer(); + +function draw_signup_form($type){ + global $config; + global $roleDat; + switch($type) { + case 'volunteer': + // returns "notopenyet", "closed", or "open" + $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("{$roleDat[$type]['name']} Registration is protected by a password. You must know the {$roleDat[$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("{$roleDat[$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("{$roleDat[$type]['name']} registration is not open"); + } +/* + echo "
    \$reg_mode = $reg_mode
    "; + echo "\$reg_open = $reg_open
    "; + echo "
    ";
    +//	print_r($config);
    +	echo "
    "; +*/ + +} + +function register_new_role(){ + global $config, $roleDat, $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 = $roleDat[$role]['id']; + $query = "SELECT COUNT(*) FROM user_roles WHERE users_id = $uid AND roles_id=$role_index"; + $results = mysql_fetch_array(mysql_query($query)); + if($results[0] != 0){ + return false; + } + + // not already regiseterd, let's go ahead and hook 'em up + $query = "INSERT INTO user_roles (accounts_id, users_id, roles_id, active, complete)"; + $query .= " VALUES($accounts_id, $uid, $role_index, 'yes', 'no')"; + echo $query; + return true; + /* + if(mysql_query($query)){ + return true; + }else{ + return false; + } + */ +}