From 39f53e416880730bd7e2d42adcfbe4646f8275eb Mon Sep 17 00:00:00 2001
From: jacob
Date: Mon, 29 Nov 2010 22:54:12 +0000
Subject: [PATCH] Added teacher abillity to add/remove students Updated the
user_save to output more meaningful errors Updates on 'questions' and
'pagetext' tables to change the 0 conference ID to -1, matching the -1 year
---
account.inc.php | 6 +-
api.php | 12 +-
db/db.code.version.txt | 2 +-
db/db.update.226.sql | 2 +
invitestudents.php | 352 +++++++++++++++++++++++++++++++++++++++++
user.inc.php | 10 +-
6 files changed, 365 insertions(+), 19 deletions(-)
create mode 100644 db/db.update.226.sql
create mode 100644 invitestudents.php
diff --git a/account.inc.php b/account.inc.php
index 98a459c5..eb9eeaec 100644
--- a/account.inc.php
+++ b/account.inc.php
@@ -136,19 +136,19 @@ function account_create($username,$password=NULL)
/* Sanity check username */
if(!account_valid_user($username)) {
- return -1;
+ return i18n("Invalid user name \"%1\"", array($username));
}
/* Make sure the user doesn't exist */
$us = mysql_real_escape_string($username);
$q = mysql_query("SELECT * FROM accounts WHERE username='$us'");
if(mysql_num_rows($q)) {
- return -2;
+ return i18n("The username \"%1\" is already in use", array($username));
}
//if the password is set, make sure its valid, if its null, thats OK, it'll get generated and set by account_set_password
if($password && !account_valid_password($password)) {
- return -3;
+ return i18n("Invalid password");
}
/* Create the account */
diff --git a/api.php b/api.php
index f3fa54d5..46038bc0 100644
--- a/api.php
+++ b/api.php
@@ -261,15 +261,9 @@ switch($request[0]) {
$account=account_load($a['id']);
$ret['status']="ok";
$ret['account']=$account;
- }
- else {
- $ret['status']="error";
- switch($a) {
- case -1: $ret['error']="invalid username"; break;
- case -2: $ret['error']="username already exists"; break;
- case -3: $ret['error']="invalid password"; break;
- default: $ret['error']="unknown account creation error"; break;
- }
+ }else{
+ $ret['status'] = "error";
+ $ret['error'] = $a;
}
} else {
$ret['status']="error";
diff --git a/db/db.code.version.txt b/db/db.code.version.txt
index 188ccfe5..f4146713 100644
--- a/db/db.code.version.txt
+++ b/db/db.code.version.txt
@@ -1 +1 @@
-225
+226
diff --git a/db/db.update.226.sql b/db/db.update.226.sql
new file mode 100644
index 00000000..7d545b09
--- /dev/null
+++ b/db/db.update.226.sql
@@ -0,0 +1,2 @@
+UPDATE `questions` SET conferences_id = -1 WHERE `year` = -1 AND conferences_id = 0;
+UPDATE `pagetext` SET conferences_id = -1 WHERE `year` = -1 AND conferences_id = 0;
diff --git a/invitestudents.php b/invitestudents.php
new file mode 100644
index 00000000..976cbc91
--- /dev/null
+++ b/invitestudents.php
@@ -0,0 +1,352 @@
+
+
+" . i18n("Invalid school ID") . "
";
+ return;
+ }
+
+ switch($config['participant_registration_type']){
+ case "schoolpassword":
+ echo "".i18n("Participant Registration Password")."
";
+
+ echo "" . i18n("In order for your school's students to register for the fair, they will need to know your specific school registration password") . "
";
+ echo "" . i18n("Registration Password: %1",array($school->registration_password)) . "
";
+ break;
+ case "invite": case "openorinvite":
+ draw_invitation_form($school);
+ break;
+ case "open":
+ echo "" . i18n("Registration for this conference is open.") . "
";
+ break;
+ default:
+ echo $config['participant_registration_type'];
+ }
+}
+
+function draw_invitation_form($school){
+ global $config, $conference;
+ $q=mysql_query("SELECT (NOW()>'".$config['dates']['regopen']."' AND NOW()<'".$config['dates']['regclose']."') AS datecheck");
+ $datecheck=mysql_fetch_object($q);
+
+
+/*
+ $query = "
+ SELECT
+ JOIN user_roles ON user_roles.users_id = users.id
+ JOIN roles ON roles.id = user_roles.roles_id
+ WHERE roles.`type` = 'participant'
+*/
+/* $q=mysql_query("SELECT students.*,
+ registrations.num,
+ registrations.emailcontact
+ FROM
+ students,
+ registrations
+ WHERE
+ students.schools_id='".$school->id."'
+ AND students.conferences_id='".$conference['id']."'
+ AND students.registrations_id=registrations.id
+ ORDER BY
+ lastname,
+ firstname");
+*/
+ $currentinvited= 'FIXME';//mysql_num_rows($q);
+
+ if($datecheck!=0)
+ {
+ echo i18n("In order for your school's students to register for the fair, you will need to invite them to register. Simply enter their email address below to invite them to register. Important: for group projects, only add one of the participants, that participant will then add the other group member(s) to the project");
+ echo "
";
+ echo "
";
+ $okaygrades=array();
+ if($config['participant_registration_type']=="invite")
+ {
+ if($school->projectlimitper=="total")
+ {
+ if($school->projectlimit){
+ echo i18n("You have invited %1 of %2 total projects for your school",array($currentinvited, $school->projectlimit));
+ if($currenteinvited < $school->projectlimit){
+ for($a=$config['mingrade'];$a<=$config['maxgrade'];$a++)
+ $okaygrades[]=$a;
+ }
+ }
+ else{
+ echo i18n("You have invited %1 project(s) for your school",array($currentinvited, $school->projectlimit));
+ for($a=$config['mingrade'];$a<=$config['maxgrade'];$a++)
+ $okaygrades[]=$a;
+
+ }
+ }
+ else if($school->projectlimitper=="agecategory")
+ {
+ echo "
";
+ $catq=mysql_query("SELECT * FROM projectcategories WHERE conferences_id='".$conference['id']."' ORDER BY id");
+ while($catr=mysql_fetch_object($catq)){
+
+ $q2=mysql_query("SELECT COUNT(students.id) AS num
+ FROM
+ students,
+ registrations
+ WHERE
+ students.schools_id='".$school->id."'
+ AND students.grade>='$catr->mingrade'
+ AND students.grade<='$catr->maxgrade'
+ AND students.conferences_id='".$conference['id']."'
+ AND students.registrations_id=registrations.id
+ ");
+ echo mysql_error();
+ $r2=mysql_fetch_object($q2);
+ $currentinvited = $r2->num;
+
+ if($currentinvited < $school->projectlimit || $school->projectlimit==0){
+ for($a=$catr->mingrade;$a<=$catr->maxgrade;$a++)
+ $okaygrades[]=$a;
+ }
+
+ echo i18n("You have invited %1 of %2 total projects for for the %3 age category",array($currentinvited,$school->projectlimit,i18n($catr->category)));
+ echo "
";
+
+ }
+ }
+ else
+ {
+ //hmm projectlimitper has not been set
+ //so we have no limits, anyone can register or they can add as many as they want.
+ for($x=$config['mingrade']; $x<=$config['maxgrade']; $x++)
+ $okaygrades[]=$x;
+ }
+ }
+ else
+ {
+ // this could be an else if $config['participant_registration_type']=="openorinvite" )
+ //because openorinvite is the only other option
+
+ //so we have no limits, anyone can register or they can add as many as they want.
+ //you cannot enforce limits when the system is 'open' because anyone can choose any school
+ //and if its openorinvite then whatever happens in the inviter still morepeople can be added
+ //by themselves, so there's no point in having limits.
+ for($x=$config['mingrade']; $x<=$config['maxgrade']; $x++)
+ $okaygrades[]=$x;
+
+ }
+ echo "
";
+
+ if(count($okaygrades))
+ {
+
+ echo "";
+ }
+ else
+ {
+ echo notice(i18n("You have invited the maximum number of participants for your school"));
+
+ }
+ }
+ echo "
";
+
+ echo "".i18n("Invited participants from your school")."
";
+ echo "";
+ draw_student_list($school->id);
+ echo "
";
+}
+
+function getStudents($schoolId){
+ $result = array();
+ $query = mysql_query("
+ SELECT users.id, users.firstname, users.lastname, accounts.username, users.grade
+ FROM users
+ JOIN accounts ON users.accounts_id = accounts.id
+ WHERE users.id IN (
+ SELECT users_id FROM user_roles
+ JOIN roles ON roles.id = user_roles.roles_id
+ WHERE roles.`type` = 'participant'
+ )
+ AND schools_id = {$schoolId}
+ ");
+
+ while($row = mysql_fetch_assoc($query)){
+ $result[] = $row;
+ }
+ return $result;
+}
+
+function draw_student_list($schoolId){
+ global $config;
+ $studentList = getStudents($schoolId);
+ if(count($studentList) > 0){
+ echo "";
+ echo "".i18n("Last Name")." | ".i18n("First Name")." | ";
+ echo "".i18n("Username")." | ";
+ echo "".i18n("Grade")." | ";
+ echo "".i18n("Registration Number")." | ";
+ echo "".i18n("Actions")." |
";
+ foreach($studentList as $student){
+ echo "";
+ echo "{$student['lastname']} | ";
+ echo "{$student['firstname']} | ";
+ echo "{$student['username']} | ";
+ echo "{$student['grade']} | ";
+ echo " | "; // FIXME this should be the registration number
+ echo " | ";
+ echo "
";
+ }
+ echo "
";
+ }else{
+ echo i18n("You have not yet invited any participants from your school");
+ }
+}
diff --git a/user.inc.php b/user.inc.php
index fb8ff38b..58baf1a0 100644
--- a/user.inc.php
+++ b/user.inc.php
@@ -653,7 +653,6 @@ function user_save(&$u)
$fields_for_role['sponsor'] = array('sponsors_id','primary','position');
$fields_for_role['teacher'] = array();
$fields_for_role['volunteer'] = array('languages');
-
/* Merge fields as necessary, build a big list of fields to save */
foreach($new_roles as $r) {
if(!array_key_exists($r, $fields_for_role)) continue;
@@ -1001,6 +1000,9 @@ function user_add_role(&$u, $role, $password = null){
$_SESSION['roles'][] = $role;
}
+ // also, update the user:
+ $u = user_load($u['id']);
+
}
return $result;
}
@@ -1507,11 +1509,7 @@ function user_invite($username, $password, $email, $roles_id){
// all fields have been passed in, let's go ahead and create the account/user/role
$newAccount = account_create($username, $password);
if(!is_array($newAccount)){
- switch($newAccount){
- case -1: $returnval = "Invalid username"; break;
- case -2: $returnval = "Username already in use"; break;
- case -3: $returnval = "Invalid password"; break;
- }
+ $returnval = $newAccount;
}
}