2010-06-15 18:14:01 +00:00
|
|
|
<?php
|
|
|
|
require_once('common.inc.php');
|
|
|
|
require_once('user.inc.php');
|
|
|
|
|
|
|
|
if($_SESSION['schoolid'] && $_SESSION['schoolaccesscode'] && $conference['type'] == 'scienceolympics'){
|
2010-06-16 15:16:25 +00:00
|
|
|
|
|
|
|
if($_GET['action'] == 'new'){
|
|
|
|
$results = process_newRecord($_POST['firstName'], $_POST['lastName'], $_POST['email']);
|
|
|
|
if($results !== true){
|
|
|
|
echo "<script type=\"text/javascript\">var savedRecord = false;</script>";
|
|
|
|
error_($results);
|
|
|
|
}else{
|
|
|
|
echo "<script type=\"text/javascript\">var savedRecord = true;</script>";
|
|
|
|
}
|
|
|
|
}else if($_GET['action'] == 'delete'){
|
|
|
|
if(!delete_record($_POST['uid'])){
|
|
|
|
echo "<script type=\"text/javascript\">var deletedRecord = false;</script>";
|
|
|
|
error_("Unable to delete record");
|
|
|
|
}else{
|
|
|
|
echo "<script type=\"text/javascript\">var deletedRecord = true;</script>";
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
$title = i18n("Manage Students");
|
|
|
|
send_header($title, array("School Access" => "schoolaccess.php"));
|
|
|
|
draw_javascript();
|
|
|
|
draw_list();
|
|
|
|
send_footer();
|
|
|
|
}
|
2010-06-15 18:14:01 +00:00
|
|
|
}else{
|
|
|
|
header('Location: schoolaccess.php');
|
|
|
|
}
|
|
|
|
|
2010-06-16 15:16:25 +00:00
|
|
|
// 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){
|
|
|
|
$firstName = trim($firstName);
|
|
|
|
$lastName = trim($lastName);
|
|
|
|
$email = trim($email);
|
|
|
|
|
|
|
|
// 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($email != null){
|
|
|
|
$user = user_load_by_email($email);
|
|
|
|
}else{
|
|
|
|
$user = false;
|
|
|
|
}
|
|
|
|
if($user != false){
|
|
|
|
// we're modifying an existing user
|
|
|
|
}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");
|
|
|
|
}else{
|
|
|
|
// we'll use the e-mail address provided
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$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 . ')">×</span>';
|
|
|
|
echo "</td>";
|
|
|
|
echo "<td>$firstName</td>";
|
|
|
|
echo "<td>$lastName</td>";
|
|
|
|
echo "<td>$email</td>";
|
|
|
|
echo "<td></td></tr>";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// delete the record for the specified user id. Returns true on succes, false on failure
|
|
|
|
function delete_record($uid){
|
|
|
|
// WRITE ME
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function draw_javascript(){
|
|
|
|
?>
|
|
|
|
<script type="text/javascript">
|
|
|
|
var awaiting_ajax = false; // used to prevent the same record from being submitted multiple times
|
|
|
|
|
|
|
|
function deleteRecord(uid){
|
|
|
|
var params;
|
|
|
|
if(awaiting_ajax) return false;
|
|
|
|
awaiting_ajax = true;
|
|
|
|
|
|
|
|
params = [{ 'name' : 'uid', 'value' : uid }];
|
|
|
|
|
|
|
|
$("#debug").load("schoolstudents.php?action=delete", params, function(response){
|
|
|
|
if(deletedRecord){
|
|
|
|
$('#' + uid).remove();
|
|
|
|
}
|
|
|
|
awaiting_ajax = false;
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function addNewRecord(){
|
|
|
|
var params;
|
|
|
|
var firstName = $('#newFirstName').val();
|
|
|
|
var lastName = $('#newLastName').val();
|
|
|
|
var email = $('#newEmail').val();
|
|
|
|
|
|
|
|
if(firstName == '' || lastName == ''){
|
|
|
|
notice_create('error', '<?=i18n('First and last names are required fields'); ?>', 5000);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if(awaiting_ajax) return false;
|
|
|
|
awaiting_ajax = true;
|
|
|
|
|
|
|
|
params = [
|
|
|
|
{ 'name' : 'firstName', 'value': firstName },
|
|
|
|
{ 'name' : 'lastName', 'value': lastName },
|
|
|
|
{ 'name' : 'email', 'value': email }
|
|
|
|
];
|
|
|
|
|
|
|
|
$("#debug").load("schoolstudents.php?action=new", params, function(response){
|
|
|
|
if(savedRecord){
|
|
|
|
$('#studentList > tbody:last').append(response);
|
|
|
|
$('#newFirstName').select();
|
|
|
|
$('#newFirstName').attr({ value: '' });
|
|
|
|
$('#newLastName').attr({ value: '' });
|
|
|
|
$('#newEmail').attr({ value: '' });
|
|
|
|
}
|
|
|
|
awaiting_ajax = false;
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
|
2010-06-15 18:14:01 +00:00
|
|
|
// draw an editable list of all students for this school in the users_stunt table
|
|
|
|
function draw_list(){
|
2010-06-16 15:16:25 +00:00
|
|
|
?>
|
2010-06-15 18:14:01 +00:00
|
|
|
|
2010-06-16 15:16:25 +00:00
|
|
|
<table id="studentList" class="summarytable">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th></th>
|
|
|
|
<th><?=i18n("First Name");?></th>
|
|
|
|
<th><?=i18n("Last Name");?></th>
|
|
|
|
<th><?=i18n("Email Address");?></th>
|
|
|
|
<th></th>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<th><?=i18n("New:")?></th>
|
|
|
|
<th><input type="text" id="newFirstName"></input></th>
|
|
|
|
<th><input type="text" id="newLastName"></input></th>
|
|
|
|
<th><input type="text" id="newEmail"></input></th>
|
|
|
|
<th><button name="newRecord" onclick="addNewRecord()"><?=i18n("Add")?></button></th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<?php
|
|
|
|
// $query = 'SELECT * FROM users_students WHERE schools_id = ';
|
|
|
|
// $query .= $_SESSION['schoolid'];
|
|
|
|
// $recordList =
|
2010-06-15 18:14:01 +00:00
|
|
|
|
2010-06-16 15:16:25 +00:00
|
|
|
?>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
|
|
|
|
<?php
|
2010-06-15 18:14:01 +00:00
|
|
|
}
|