From 9db042fc10465ba96c282230d169046022ea20ed Mon Sep 17 00:00:00 2001 From: jacob Date: Fri, 1 Oct 2010 18:47:28 +0000 Subject: [PATCH] Modifications on editing users --- user.inc.php | 22 ++++++++++++++++++++-- user_edit.php | 40 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/user.inc.php b/user.inc.php index b4f216e..c1a5754 100644 --- a/user.inc.php +++ b/user.inc.php @@ -491,8 +491,27 @@ function user_create($accounts_id, $conferences_id=0) exit; } + $fields = array( + 'accounts_id' => $accounts_id, + 'conferences_id' => $conferences_id, + ); + + /* Get old user data if available */ + $results = mysql_fetch_assoc(mysql_query("SELECT * FROM users WHERE accounts_id = '$accounts_id' ORDER BY id DESC LIMIT 1")); + if(is_array($results)){ + $skipfields = array('id', 'created', 'lastlogin', 'year', 'accounts_id', 'conferences_id', 'deleted', 'deleteddatetime'); + foreach($results as $fname => $value){ + if(!in_array($fname, $skipfields) && $value != null){ + $fields[$fname] = $value; + } + } + } + /* Create the user */ - mysql_query("INSERT INTO users(`accounts_id`,`conferences_id`) VALUES('$accounts_id','$conferences_id')"); + $fieldList = array_keys($fields); + $query = "INSERT INTO users(`created`, `" . implode('`,`', $fieldList) . "`) VALUES(NOW(), '" . implode("','", $fields) . "')"; + + mysql_query($query); $id = mysql_insert_id(); /* Return a loaded user with no roles */ @@ -501,7 +520,6 @@ function user_create($accounts_id, $conferences_id=0) - /* Perform some checks. Make sure the person is logged in, and that their * password hasn't expired (the password_expired var is set in the login page) */ diff --git a/user_edit.php b/user_edit.php index 68f9a73..eef18b7 100644 --- a/user_edit.php +++ b/user_edit.php @@ -33,6 +33,44 @@ if($edit_id != $_SESSION['users_id']) 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 + $result = mysql_fetch_assoc(mysql_query("SELECT accounts_id FROM users WHERE id=$edit_id")); + $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']; + $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']); + $edit_id = $u['id']; + } +}else{ + $joinConference = false; + if($edit_id == ''){ + // the account in question does not have a users record + $joinConference = true; + }else{ + $query = "SELECT COUNT(*) FROM users WHERE conferences_id = {$_SESSION['conferences_id']} AND "; + $query .= "id = $edit_id"; + $data = mysql_fetch_array(mysql_query($query)); + if($data[0] == 0){ + // the user exists, but they are not linked to this conference + $joinConference = true; + } + } + + if($joinConference){ + send_header(i18n("User Editor").": {$u['name']}"); + echo '' . i18n('Join this conferenece') . ''; + exit; + } +} + $tabs = array( 'fairinfo' => array( 'label' => 'Fair Information', 'types' => array('fair'), @@ -312,7 +350,7 @@ function user_update_tab_status(tabkey,newstatus) $(".status_overall").addClass('happy'); } } - +