diff --git a/account.inc.php b/account.inc.php index 7ddb1dd..0401786 100644 --- a/account.inc.php +++ b/account.inc.php @@ -100,12 +100,25 @@ function account_load($id) $id = intval($id); $q = mysql_query("SELECT * FROM accounts WHERE id='$id'"); if(mysql_num_rows($q) == 0) { - echo "No such account $id"; - exit; + return false; } if(mysql_num_rows($q) > 1) { - echo "More than one account returned for $id"; - exit; + return false; + } + + $a = mysql_fetch_assoc($q); + return $a; +} + +function account_load_by_username($username) +{ + $un = mysql_real_escape_string($username); + $q = mysql_query("SELECT * FROM accounts WHERE username='$un'"); + if(mysql_num_rows($q) == 0) { + return false; + } + if(mysql_num_rows($q) > 1) { + return false; } $a = mysql_fetch_assoc($q); @@ -118,7 +131,7 @@ function account_create($username) global $config; /* Sanity check username */ - if(!user_valid_user($username)) { + if(!account_valid_user($username)) { return -1; } diff --git a/db/db.code.version.txt b/db/db.code.version.txt index ad03f7c..485369e 100644 --- a/db/db.code.version.txt +++ b/db/db.code.version.txt @@ -1 +1 @@ -204 +205 diff --git a/db/db.update.205.sql b/db/db.update.205.sql new file mode 100644 index 0000000..ff0adb5 --- /dev/null +++ b/db/db.update.205.sql @@ -0,0 +1,2 @@ +ALTER TABLE `accounts` CHANGE `id` `id` INT( 11 ) NOT NULL AUTO_INCREMENT; +ALTER TABLE `accounts` ADD `created` DATETIME NOT NULL; diff --git a/schoolstudents.php b/schoolstudents.php index 1d7056e..b221a79 100644 --- a/schoolstudents.php +++ b/schoolstudents.php @@ -1,6 +1,7 @@ 0){ if($suffix == '') $suffix = 1; else $suffix++; } }while($q['tally'] > 0); $username = $nameBase . $suffix; - } // now that we have the username we want to use, let's create the user - $user = user_create('student', $username); - $user['firstname'] = $firstName; - $user['lastname'] = $lastName; - $user['active'] = 'yes'; - $user['complete'] = 'yes'; - if($username == $email) - $user['email'] = $email; - $user['schools_id'] = $_SESSION['schoolid']; - user_save($user); + $account=account_create($username); } + //next, we try to load their user record + $user = user_load(0,$account['id']); + if(!$user) { + $user=user_create($account['id']); + } + + user_add_role($user,'student'); + + //we're gonna set teh firstname/lastname too + $user['firstname'] = $firstName; + $user['lastname'] = $lastName; + //and dont forget the school id, because we know what at this point + $user['schools_id'] = $_SESSION['schoolid']; + user_save($user); $uid = $user['uid']; echo user_row($uid, $username, $firstName, $lastName, $email); @@ -131,9 +130,7 @@ function process_newRecord($firstName, $lastName, $email){ // generate the table row for thisa given record function user_row($uid, $username, $firstName, $lastName, $email){ $rval = "