var savedRecord = false;"; error_($results); }else{ echo ""; } }else if($_GET['action'] == 'delete'){ if(!delete_record($_POST['uid'])){ echo ""; error_("Unable to delete record"); }else{ echo ""; } }else{ $title = i18n("Manage Students"); send_header($title, array("School Home" => "schoolaccess.php")); draw_javascript(); draw_list(); send_footer(); } }else{ header('Location: schoolaccess.php'); } // 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($email != null){ $user = user_load_by_email($email); }else{ $user = false; } if($user != false){ // we're adding an existing user. First find out if they are in the school we have specified return "e-mail address is already in use"; // $user['firstname'] = $firstName; // $user['lastname'] = $lastName; /* $query = "INSERT INTO users_conferences_link(conferences_id, users_uid) VALUES("; $query .= $conference['id'] . ', ' . $user['uid']; $firstName = $user['firstname']; $lastName = $user['lastname']; */ }else{ // we're creating a new user if(strlen($email) != 0){ if(!isEmailAddress($email)){ // not a valid e-mail address return "Invalid e-mail address"; }else{ // new e-mail address specified. That'll be the username $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 users 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 $user = user_create('student', $username); $user['firstname'] = $firstName; $user['lastname'] = $lastName; if($username == $email) $user['email'] = $email; $user['schools_id'] = $_SESSION['schoolid']; user_save($user); $uid = $user['uid']; } echo user_row($uid, $username, $firstName, $lastName, $email); return true; } function user_row($uid, $username, $firstName, $lastName, $email){ $rval = ""; $rval .= "$username"; $rval .= "$firstName"; $rval .= "$lastName"; $rval .= "$email"; $rval .= ''; $rval .= ""; return $rval; } // delete the record for the specified user id. Returns true on succes, error message on failure function delete_record($uid){ $user = user_load_by_uid($uid); user_delete($user); $user = user_load_by_uid($uid); if($user['deleted'] != 'yes'){ return "Failed to delete user"; } return true; } function draw_javascript(){ ?>