var success = false;"; error_($results); }else{ echo ""; } break; case 'update': $results = alter_record($_POST['recordId'], $_POST['firstName'], $_POST['lastName'], $_POST['email']); if($results !== true){ echo ""; error_($results); }else{ echo ""; } break; case 'delete': if(!delete_record($_POST['uid'])){ echo ""; error_("Unable to delete record"); }else{ echo ""; } break; default: $title = i18n("Manage Students"); send_header($title, array("School Home" => "schoolaccess.php")); draw_javascript(); draw_list(); send_footer(); } }else{ header('Location: schoolaccess.php'); } // alter an existing user record. returns true on success, error message on failure function alter_record($uid, $firstName, $lastName, $email){ global $conference; $returnval = true; $firstName = trim($firstName); $lastName = trim($lastName); $email = strtolower(trim($email)); $user = user_load(null, $uid); if($user){ $user['firstname'] = $firstName; $user['lastname'] = $lastName; $user['email'] = $email; user_save($user); echo user_row($uid, $user['username'], $firstName, $lastName, $email); }else{ $returnval = "User not found"; } return $returnval; } // create a new record with the given first name last name and e-mail address // return true on success, error message on failure function process_newRecord($firstName, $lastName, $email){ global $conference; $firstName = trim($firstName); $lastName = trim($lastName); $email = strtolower(trim($email)); $uid = null; // make sure we are actually given a first and last name if(strlen($firstName) == 0 || strlen($lastName) == 0){ return "First and last names are required fields"; } // if they have an e-mail address, make sure it's not already in use if($email){ $account = account_load_by_username($email); }else{ $account = false; } if(!$account) { if($email) { $username=$email; } else { // generate a user name $nameBase = substr(strtolower($firstName), 0, 1) . strtolower($lastName); $suffix = ''; do{ $q = mysql_fetch_array(mysql_query('SELECT COUNT(*) AS tally FROM accounts WHERE username="' . ($nameBase . $suffix) . '";')); if($q['tally'] > 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 $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); return true; } // generate the table row for thisa given record function user_row($uid, $username, $firstName, $lastName, $email){ $rval = "
=i18n("Username");?> | =i18n("First Name");?> | =i18n("Last Name");?> | =i18n("Email Address / Username");?> (Leave blank to auto-generate) |
|
---|---|---|---|---|
=i18n("New:")?> |