From 7e749f0295c9482079a06ac039849375d2203629 Mon Sep 17 00:00:00 2001 From: jacob Date: Wed, 16 Jun 2010 15:16:25 +0000 Subject: [PATCH] Added conferences_id to the so_teams table and updated corresponding code accordingly Partially implemented student manager under school dashboard for science olypmics --- db/db.code.version.txt | 2 +- db/db.update.185.sql | 16 +++++ schoolstudents.php | 156 ++++++++++++++++++++++++++++++++++++++++- schoolteams.php | 10 +-- 4 files changed, 175 insertions(+), 9 deletions(-) create mode 100644 db/db.update.185.sql diff --git a/db/db.code.version.txt b/db/db.code.version.txt index dc37bbd..725a5ba 100644 --- a/db/db.code.version.txt +++ b/db/db.code.version.txt @@ -1 +1 @@ -184 +185 diff --git a/db/db.update.185.sql b/db/db.update.185.sql new file mode 100644 index 0000000..03e96fd --- /dev/null +++ b/db/db.update.185.sql @@ -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`; diff --git a/schoolstudents.php b/schoolstudents.php index 2e53c39..da4c77d 100644 --- a/schoolstudents.php +++ b/schoolstudents.php @@ -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 ""; + 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 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 ""; + echo '×'; + echo ""; + echo "$firstName"; + echo "$lastName"; + echo "$email"; + echo ""; + 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(){ +?> + + + + + + + + + + + + + + + + + + + + + + +
+ + "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 = '' + newname + ''; $('#teamHeader_' + teamId).html(newname); @@ -99,8 +99,8 @@ function draw_page(){ '; - $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 '

' . $team['name'] . "

\n"; echo '
' . "\n"; echo '
';