forked from science-ation/science-ation
Added conferences_id to the so_teams table and updated corresponding code accordingly
Partially implemented student manager under school dashboard for science olypmics
This commit is contained in:
parent
7ca5edc2a1
commit
7e749f0295
@ -1 +1 @@
|
||||
184
|
||||
185
|
||||
|
16
db/db.update.185.sql
Normal file
16
db/db.update.185.sql
Normal file
@ -0,0 +1,16 @@
|
||||
CREATE TABLE `users_student` (
|
||||
`users_uid` INT NOT NULL ,
|
||||
`schools_id` INT NOT NULL ,
|
||||
`students_active` ENUM( 'yes', 'no' ) NULL ,
|
||||
`students_complete` ENUM( 'yes', 'no' ) NULL ,
|
||||
`grade` INT NULL ,
|
||||
PRIMARY KEY ( `users_uid` )
|
||||
) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci;
|
||||
|
||||
CREATE TABLE `users_conferences_link` (
|
||||
`users_uid` INT NOT NULL ,
|
||||
`conferences_id` INT NOT NULL ,
|
||||
PRIMARY KEY ( `users_uid` , `conferences_id` )
|
||||
) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci;
|
||||
|
||||
ALTER TABLE `so_teams` ADD `conferences_id` INT NOT NULL AFTER `id`;
|
@ -3,15 +3,165 @@ require_once('common.inc.php');
|
||||
require_once('user.inc.php');
|
||||
|
||||
if($_SESSION['schoolid'] && $_SESSION['schoolaccesscode'] && $conference['type'] == 'scienceolympics'){
|
||||
$title = i18n("Manage Students");
|
||||
send_header($title, array("School Access" => "schoolaccess.php"));
|
||||
draw_list();
|
||||
|
||||
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();
|
||||
}
|
||||
}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){
|
||||
$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
|
||||
}
|
||||
|
||||
// draw an editable list of all students for this school in the users_stunt table
|
||||
function draw_list(){
|
||||
?>
|
||||
|
||||
<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 =
|
||||
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
@ -1,12 +1,11 @@
|
||||
<?php
|
||||
require_once('common.inc.php');
|
||||
require_once('user.inc.php');
|
||||
|
||||
if($_SESSION['schoolid'] && $_SESSION['schoolaccesscode'] && $conference['type'] == 'scienceolympics'){
|
||||
switch($_GET['action']){
|
||||
case 'saveNew':
|
||||
$teamName = mysql_real_escape_string($_POST['teamname']);
|
||||
$query = 'INSERT INTO so_teams (schools_id, name) VALUES (' . $_SESSION['schoolid'] . ', "' . $teamName . '")';
|
||||
$query = 'INSERT INTO so_teams (schools_id, conferences_id, name) VALUES (' . $_SESSION['schoolid'] . ', "' . $conference['id'] . ', "' . $teamName . '")';
|
||||
$success = mysql_query($query);
|
||||
draw_page();
|
||||
break;
|
||||
@ -69,6 +68,7 @@ if($_SESSION['schoolid'] && $_SESSION['schoolaccesscode'] && $conference['type']
|
||||
}
|
||||
|
||||
function draw_page(){
|
||||
global $conference;
|
||||
$title = i18n("Manage Teams");
|
||||
send_header($title, array("School Access" => "schoolaccess.php"));
|
||||
?>
|
||||
@ -89,7 +89,7 @@ function draw_page(){
|
||||
function saveData(teamId){
|
||||
var data = $("#editTeam_" + teamId).serializeArray();
|
||||
|
||||
$("#debug").load("schoolteams.php?action=save&", data, function(){
|
||||
$("#debug").load("schoolteams.php?action=save", data, function(){
|
||||
if(newname != undefined){
|
||||
newname = '<span class="ui-icon ui-icon-triangle-1-e"></span><a href="#" tabindex="-1">' + newname + '</a>';
|
||||
$('#teamHeader_' + teamId).html(newname);
|
||||
@ -99,8 +99,8 @@ function draw_page(){
|
||||
</script>
|
||||
<?php
|
||||
echo '<div id="teamaccordion" style="width:40em; visibility:hidden;">';
|
||||
$teamList = mysql_query("SELECT * FROM so_teams WHERE schools_id = " . $_SESSION['schoolid']);
|
||||
while($team = mysql_fetch_array($teamList)){
|
||||
$teamList = mysql_query("SELECT * FROM so_teams WHERE schools_id = " . $_SESSION['schoolid'] . " AND conferences_id = " . $conference['id']);
|
||||
while($teamList && $team = mysql_fetch_array($teamList)){
|
||||
echo '<h3 id="teamHeader_' . $team['id'] . '"><a href="#">' . $team['name'] . "</a></h3>\n";
|
||||
echo '<div id="team_' . $team['id'] . '">' . "\n";
|
||||
echo '<form id="editTeam_' . $team['id'] . '" onsubmit="return false;">';
|
||||
|
Loading…
Reference in New Issue
Block a user