diff --git a/user.inc.php b/user.inc.php
index 10c5920..f8aa686 100644
--- a/user.inc.php
+++ b/user.inc.php
@@ -245,30 +245,11 @@ function user_save(&$u)
return -1;
}
- /* Add any new roles */
- $orig_roles = array_keys($u['orig']['roles']);
+ // Update all roles
$new_roles = array_keys($u['roles']);
-
- /* Delete any removed roles */
- $removed = array_diff($orig_roles, $new_roles);
- foreach($removed as $r) {
- mysql_query("DELETE FROM user_roles WHERE users_id='{$u['id']}' AND roles_id='{$roles[$r]['id']}'");
- }
-
- /* Update all roles */
foreach($new_roles as $r) {
- if(!in_array($r, $orig_roles)) {
- /* Role is new */
- if(!user_add_role_allowed($u, $r)) {
- echo "HALT: user can't add this role";
- exit;
- }
- mysql_query("INSERT INTO user_roles(accounts_id,users_id,roles_id,active,complete)
- VALUES('{$u['accounts_id']}','{$u['id']}','{$roles[$r]['id']}','no','no')");
- echo mysql_error();
-
- } else if($u['roles'][$r] != $u['orig']['roles'][$r]) {
- /* $u['roles'][$r] has changed from original, update it */
+ 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']}'");
@@ -276,7 +257,6 @@ function user_save(&$u)
}
}
-
$fields = array('salutation','firstname','lastname',
'phonehome','phonework','phonecell','fax','organization',
'address','address2','city','province','postalcode','sex',
@@ -359,8 +339,9 @@ function user_remove_role(&$u, $role)
/* Delete the role */
unset($u['roles'][$role]);
+ mysql_query("DELETE FROM user_roles WHERE roles_id={$role['id']} AND users_id='$id'");
- /* Save this user (takes care of removing entries from the user_roles db) */
+ /* Save this user */
user_save($u);
}
@@ -510,19 +491,61 @@ function user_add_role_allowed(&$u, $role)
return true;
}
-function user_add_role(&$u, $role)
+function user_add_role(&$u, $role, $password = null)
{
+ global $config, $roles;
if(!user_add_role_allowed($u, $role)) {
/* If we get in here, someone is hand crafting URLs */
echo "HALT: invalid role add specified for operation.";
exit;
}
- /* Add the role */
- $u['roles'][$role] = array('active' =>'yes',
- 'complete' => 'no');
- /* Save it now so the DB gets updated */
- user_save($u);
+ // ensure that this role can indeed be added
+ $valid = false;
+ if(array_key_exists($role . '_registration_type', $config)){
+ switch($config[$role . '_registration_type']){
+ case 'open':
+ $valid = true;
+ break;
+ case 'singlepassword':
+ if($password == $config[$role . '_registration_singlepassword']){
+ $valid = true;
+ }
+ break;
+ case 'schoolpassword':
+ if($pasword != null){
+ $schoolId = $u['schools_id'];
+ $schoolDat = mysql_fetch_assoc(mysql_query("SELECT registration_password FROM schools WHERE id=$schoolId"));
+ if($password == $schoolDat['registration_password']) $valid = true;
+ }
+ break;
+ case 'invite':
+ //$valid = false;
+ break;
+ case 'openorinvite':
+ $valid = true;
+ break;
+ }
+ }
+
+ if($valid){
+ // ok, the conditions are met, make sure they don't already have this role
+ $check = mysql_fetch_assoc(mysql_query("SELECT COUNT(*) AS tally FROM user_roles WHERE users_id = {$u['id']} AND roles_id={$roles[$role]['id']}"));
+ if($check['tally'] == 0){
+
+ $q = "INSERT INTO user_roles (accounts_id, users_id, roles_id, active, complete) VALUES(";
+ $q .= $u['accounts_id'];
+ $q .= ", " . $u['id'];
+ $q .= ", " . $roles[$role]['id'];
+ $q .= ", 'yes', 'no');";
+ if(mysql_query($q)){
+ $u['roles'][$role] = array('active' =>'yes', 'complete' => 'no');
+ }else{
+ $error = mysql_error();
+ }
+
+ }
+ }
}
function user_create($accounts_id, $conferences_id=0)
diff --git a/user_edit.php b/user_edit.php
index eef18b7..edb25ab 100644
--- a/user_edit.php
+++ b/user_edit.php
@@ -36,12 +36,21 @@ else
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
- $result = mysql_fetch_assoc(mysql_query("SELECT accounts_id FROM users WHERE id=$edit_id"));
- $edit_accounts_id = $result['accounts_id'];
-
+ if($edit_id == null){
+ // this will happen if they have no user record
+ $edit_accounts_id = $_SESSION['accounts_id'];
+ }else{
+ $q = mysql_query("SELECT accounts_id FROM users WHERE id=$edit_id");
+ if(!$q){
+ echo mysql_error();
+ exit();
+ }
+ $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 = " . $_SESSION['accounts_id'];
+ . " AND accounts_id = " . $edit_accounts_id;
$data = mysql_fetch_array(mysql_query($query));
if($data[0] == 0){
diff --git a/user_main.php b/user_main.php
index f6dee54..62f7c2a 100644
--- a/user_main.php
+++ b/user_main.php
@@ -25,7 +25,6 @@
require_once("common.inc.php");
require_once("user.inc.php");
-
user_auth_required();
@@ -42,12 +41,39 @@
echo "
";
echo "
";
-echo "