Updates for managing students

This commit is contained in:
jacob 2010-06-16 21:33:43 +00:00
parent 6ea88362e8
commit 0503030a35
2 changed files with 106 additions and 36 deletions

View File

@ -33,45 +33,91 @@ if($_SESSION['schoolid'] && $_SESSION['schoolaccesscode'] && $conference['type']
// 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 = trim($email);
$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 i18n("First and last names are required fields");
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 modifying an existing user
// 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){
// let's create an e-mail address
}else if(!isEmailAddress($email)){
// not a valid e-mail address
return i18n("Invalid e-mail address");
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{
// we'll use the e-mail address provided
// 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'];
}
$uid = rand() % 100000; // <-- just testing - should be an actual user id
echo "<tr id=\"$uid\"><td>";
echo '<span style="font-size:150%; line-height:66%;font-weight:bold; cursor:pointer; color:#F00;" onclick="deleteRecord(' . $uid . ')">&times;</span>';
echo "</td>";
echo "<td>$firstName</td>";
echo "<td>$lastName</td>";
echo "<td>$email</td>";
echo "<td></td></tr>";
echo user_row($uid, $username, $firstName, $lastName, $email);
return true;
}
// delete the record for the specified user id. Returns true on succes, false on failure
function user_row($uid, $username, $firstName, $lastName, $email){
$rval = "<tr id=\"$uid\">";
$rval .= "<td>$username</td>";
$rval .= "<td>$firstName</td>";
$rval .= "<td>$lastName</td>";
$rval .= "<td>$email</td>";
$rval .= '<td style="text-align:center"><img border="0" src="/sfiab/images/16/button_cancel.png" onclick="deleteRecord(' . $uid . ')"/></td>';
$rval .= "</tr>";
return $rval;
}
// delete the record for the specified user id. Returns true on succes, error message on failure
function delete_record($uid){
// WRITE ME
$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;
}
@ -134,12 +180,13 @@ function draw_javascript(){
// draw an editable list of all students for this school in the users_stunt table
function draw_list(){
global $conference;
?>
<table id="studentList" class="summarytable">
<thead>
<tr>
<th></th>
<th><?=i18n("Username");?></th>
<th><?=i18n("First Name");?></th>
<th><?=i18n("Last Name");?></th>
<th><?=i18n("Email Address");?></th>
@ -155,9 +202,18 @@ function draw_list(){
</thead>
<tbody>
<?php
// $query = 'SELECT * FROM users_students WHERE schools_id = ';
// $query .= $_SESSION['schoolid'];
// $recordList =
$query = 'SELECT * FROM users_student';
$query .= ' JOIN users ON users_student.users_id = users.uid';
$query .= ' JOIN users_conferences_link ucl ON ucl.users_uid = users_student.users_id';
$query .= ' WHERE schools_id = ' . $_SESSION['schoolid'];
$query .= ' AND ucl.conferences_id=' . $conference['id'];
$data = mysql_query($query);
if($data){
while($row = mysql_fetch_array($data)){
$uid = $row['users_uid'];
echo user_row($uid, $row['username'], $row['firstname'], $row['lastname'], $row['email']);
}
}
?>
</tbody>

View File

@ -76,9 +76,12 @@ function user_load_fair(&$u)
function user_load_student(&$u)
{
// $u['student_active'] = ($u['student_active'] == 'yes') ? 'yes' : 'no';
// $u['student_complete'] = ($u['student_complete'] == 'yes') ? 'yes' : 'no';
return false;
$u['student_active'] = ($u['student_active'] == 'yes') ? 'yes' : 'no';
$u['student_complete'] = ($u['student_complete'] == 'yes') ? 'yes' : 'no';
/* echo "<pre>";
print_r($u);
echo "</pre>";
*/ return true;
}
function user_load_judge(&$u)
{
@ -177,7 +180,8 @@ function user_load($user, $uid = false)
LEFT JOIN `users_teacher` ON `users_teacher`.`users_id`=`users`.`id`
LEFT JOIN `users_parent` ON `users_parent`.`users_id`=`users`.`id`
LEFT JOIN `users_mentor` ON `users_mentor`.`users_id`=`users`.`id`
LEFT JOIN `users_alumni` ON `users_alumni`.`users_id`=`users`.`id`
LEFT JOIN `users_alumni` ON `users_alumni`.`users_id`=`users`.`id`
LEFT JOIN `users_student` ON `users_student`.`users_id`=`users`.`id`
WHERE ";
if($uid != false) {
$uid = intval($uid);
@ -381,8 +385,8 @@ function user_save_judge($u)
function user_save_student($u)
{
// $fields = array('student_active','student_complete');
// user_save_type_list($u, 'users_student', $fields);
$fields = array('schools_id', 'student_active','student_complete');
user_save_type_list($u, 'users_student', $fields);
}
function user_save_fair($u)
@ -419,6 +423,8 @@ function user_save_parent($u)
function user_save(&$u)
{
global $conference;
/* Add any new types */
$added = array_diff($u['types'], $u['orig']['types']);
foreach($added as $t) {
@ -451,13 +457,10 @@ function user_save(&$u)
$set .= "$f='$data'";
}
}
// echo "<pre>";
// print_r($u);
// echo "</pre>";
if($set != "") {
$query = "UPDATE users SET $set WHERE id='{$u['id']}'";
mysql_query($query);
// echo "query=[$query]";
echo mysql_error();
}
@ -470,6 +473,17 @@ function user_save(&$u)
call_user_func("user_save_$t", $u);
}
if(is_array($conference) && array_key_exists('id', $conference)){
// first make sure they're not already linked.
$check = mysql_fetch_array(mysql_query("SELECT COUNT(*) as tally FROM users_conferences_link WHERE conferences_id = " . $conference['id'] . " AND users_uid = " . $u['id']));
if($check['tally'] == 0){
$query = "INSERT INTO users_conferences_link(conferences_id, users_uid) VALUES(";
$query .= $conference['id'] . ', ' . $u['id'] . ')';
mysql_query($query);
}
}
/* Should we do this? */
/* Record all the data in orig that we saved */
unset($u['orig']);
@ -725,9 +739,9 @@ function user_create($type, $username, $u = NULL)
VALUES ('$type','$username','0000-00-00', NOW(), '{$config['FAIRYEAR']}', 'no')");
echo mysql_error();
$uid = mysql_insert_id();
if(user_valid_email($username)) {
mysql_query("UPDATE users SET email='$username' WHERE id='$uid'");
}
if(user_valid_email($username)) {
mysql_query("UPDATE users SET email='$username' WHERE id='$uid'");
}
mysql_query("UPDATE users SET uid='$uid' WHERE id='$uid'");
echo mysql_error();
user_set_password($uid, NULL);