diff --git a/admin/project_editor.php b/admin/project_editor.php
index b3dd1b0..9c3993d 100644
--- a/admin/project_editor.php
+++ b/admin/project_editor.php
@@ -22,134 +22,134 @@
*/
?>
- require("../common.inc.php");
- require_once("../user.inc.php");
- require("../register_participants.inc.php");
+ require_once('../common.inc.php');
+ require_once('../user.inc.php');
+ require_once('../register_participants.inc.php');
user_auth_required('committee', 'admin');
-
- //send the header
- send_header("Project Editor",
- array('Committee Main' => 'committee_main.php',
- 'Administration' => 'admin/index.php',
- 'Participant Registration' => 'admin/registration.php',
- 'Registration List and Statistics' => 'admin/registration_list.php')
- );
- echo "
";
+$registrations_id=intval($_GET['id']);
+$action = $_GET['action'];
- if($_POST['registration_id']) $registration_id=$_POST['registration_id'];
- else if($_GET['registration_id']) $registration_id=$_GET['registration_id'];
+switch($action) {
+case 'project_load':
+ project_load();
+ break;
+case 'project_regenerate_number':
+ /* Save first */
+ project_save();
+ /* Now generate */
+ $q=mysql_query("SELECT id FROM projects WHERE registrations_id='{$registrations_id}' AND year='{$config['FAIRYEAR']}'");
+ $i=mysql_fetch_assoc($q);
+ $id = $i['id'];
- if($_POST['action']=="genprojnum") {
- $id = intval($_POST['id']);
mysql_query("UPDATE projects SET projectnumber=NULL,projectsort=NULL,
projectnumber_seq='0',projectsort_seq='0'
WHERE id='$id'");
echo mysql_error();
- list($pn,$ps,$pns,$pss) = generateProjectNumber($registration_id);
+ list($pn,$ps,$pns,$pss) = generateProjectNumber($registrations_id);
// print("Generated Project Number [$pn]");
mysql_query("UPDATE projects SET projectnumber='$pn',projectsort='$ps',
projectnumber_seq='$pns',projectsort_seq='$pss'
WHERE id='$id'");
- echo mysql_error();
- }
+ happy_("Generated and Saved Project Number: $pn");
+ break;
- if($_POST['action']=="save")
- {
-// {
- //first, lets make sure this project really does belong to them
- $q=mysql_query("SELECT * FROM projects WHERE id='".$_POST['id']."' AND registrations_id='".$registration_id."' AND year='".$config['FAIRYEAR']."'");
- if($projectinfo=mysql_fetch_object($q))
- {
- $summarywords=preg_split("/[\s,]+/",$_POST['summary']);
- $summarywordcount=count($summarywords);
- if($summarywordcount>$config['participant_project_summary_wordmax'])
- $summarycountok=0;
- else
- $summarycountok=1;
+case 'project_save':
+ project_save();
+ break;
+default:
+ break;
+}
- if($config['participant_project_title_charmax'] && strlen(stripslashes($_POST['title']))>$config['participant_project_title_charmax']) //0 for no limit, eg 255 database field limit
- {
- $title=substr(stripslashes($_POST['title']),0,$config['participant_project_title_charmax']);
- echo error(i18n("Project title truncated to %1 characters",array($config['participant_project_title_charmax'])));
- }
- else
- $title=stripslashes($_POST['title']);
+exit;
- mysql_query("UPDATE projects SET ".
- "title='".mysql_escape_string($title)."', ".
- "projectdivisions_id='".$_POST['projectdivisions_id']."', ".
- "language='".mysql_escape_string(stripslashes($_POST['language']))."', ".
- "req_table='".mysql_escape_string(stripslashes($_POST['req_table']))."', ".
- "req_electricity='".mysql_escape_string(stripslashes($_POST['req_electricity']))."', ".
- "req_special='".mysql_escape_string(stripslashes($_POST['req_special']))."', ".
- "summary='".mysql_escape_string(stripslashes($_POST['summary']))."', ".
- "summarycountok='$summarycountok',".
- "projectsort='".mysql_escape_string(stripslashes($_POST['projectsort']))."'".
- "WHERE id='".$_POST['id']."'");
- echo mysql_error();
- echo notice(i18n("Project information successfully updated"));
+function project_save()
+{
+ global $registrations_id, $config;
- //check if they changed the project number
- if($_POST['projectnumber']!=$projectinfo->projectnumber)
- {
- //check if hte new one is available
- $q=mysql_query("SELECT * FROM projects WHERE year='".$config['FAIRYEAR']."' AND projectnumber='".$_POST['projectnumber']."'");
- if(mysql_num_rows($q))
- {
- echo error(i18n("Could not change project number. %1 is already in use",array($_POST['projectnumber'])));
- }
- else
- {
- mysql_query("UPDATE projects SET
- projectnumber='".$_POST['projectnumber']."'
- WHERE id='".$_POST['id']."'");
- echo happy(i18n("Project number successfully changed to %1",array($_POST['projectnumber'])));
- }
- }
- }
- else
- {
- echo error(i18n("Invalid project to update"));
- }
- //}
- }
-
-
- //now lets find out their MAX grade, so we can pre-set the Age Category
- $q=mysql_query("SELECT MAX(grade) AS maxgrade FROM students WHERE registrations_id='".$registration_id."'");
- $gradeinfo=mysql_fetch_object($q);
-
- //now lets grab all the age categories, so we can choose one based on the max grade
- $q=mysql_query("SELECT * FROM projectcategories WHERE year='".$config['FAIRYEAR']."' ORDER BY id");
- while($r=mysql_fetch_object($q))
- {
- //save these in an array, just incase we need them later (FIXME: remove this array if we dont need it)
- $agecategories[$r->id]['category']=$r->category;
- $agecategories[$r->id]['mingrade']=$r->mingrade;
- $agecategories[$r->id]['maxgrade']=$r->maxgrade;
-
- if($gradeinfo->maxgrade >= $r->mingrade && $gradeinfo->maxgrade <= $r->maxgrade)
- {
- $projectcategories_id=$r->id;
+ //first, lets make sure this project really does belong to them
+ $q=mysql_query("SELECT * FROM projects WHERE registrations_id='{$registrations_id}' AND year='{$config['FAIRYEAR']}'");
+ $projectinfo=mysql_fetch_object($q);
+ if(!projectinfo) {
+ echo error(i18n("Invalid project to update"));
}
- }
- //now select their project info
- $q=mysql_query("SELECT * FROM projects WHERE registrations_id='".$registration_id."' AND year='".$config['FAIRYEAR']."'");
- //check if it exists, if we didnt find any record, lets insert one
- $projectinfo=mysql_fetch_object($q);
- //make sure that if they changed their grade on the student page, we update their projectcategories_id accordingly
- if($projectcategories_id && $projectinfo->projectcategories_id!=$projectcategories_id)
- {
- echo notice(i18n("Age category changed, updating to %1",array($agecategories[$projectcategories_id]['category'])));
- mysql_query("UPDATE projects SET projectcategories_id='$projectcategories_id' WHERE id='$projectinfo->id'");
- }
+ $summarywords=preg_split("/[\s,]+/",$_POST['summary']);
+ $summarywordcount=count($summarywords);
+ if($summarywordcount>$config['participant_project_summary_wordmax'])
+ $summarycountok=0;
+ else
+ $summarycountok=1;
+
+ if($config['participant_project_title_charmax'] && strlen(stripslashes($_POST['title']))>$config['participant_project_title_charmax']) { //0 for no limit, eg 255 database field limit
+ $title=substr(stripslashes($_POST['title']),0,$config['participant_project_title_charmax']);
+ error_("Project title truncated to %1 characters",array($config['participant_project_title_charmax']));
+ } else
+ $title=stripslashes($_POST['title']);
+
+ mysql_query("UPDATE projects SET ".
+ "title='".mysql_escape_string($title)."', ".
+ "projectdivisions_id='".$_POST['projectdivisions_id']."', ".
+ "language='".mysql_escape_string(stripslashes($_POST['language']))."', ".
+ "req_table='".mysql_escape_string(stripslashes($_POST['req_table']))."', ".
+ "req_electricity='".mysql_escape_string(stripslashes($_POST['req_electricity']))."', ".
+ "req_special='".mysql_escape_string(stripslashes($_POST['req_special']))."', ".
+ "summary='".mysql_escape_string(stripslashes($_POST['summary']))."', ".
+ "summarycountok='$summarycountok',".
+ "projectsort='".mysql_escape_string(stripslashes($_POST['projectsort']))."'".
+ "WHERE id='".$_POST['id']."'");
+ echo mysql_error();
+ happy_("Project information successfully updated");
+
+ //check if they changed the project number
+ if($_POST['projectnumber']!=$projectinfo->projectnumber) {
+ //check if hte new one is available
+ $q=mysql_query("SELECT * FROM projects WHERE year='".$config['FAIRYEAR']."' AND projectnumber='".$_POST['projectnumber']."'");
+ if(mysql_num_rows($q)) {
+ error_("Could not change project number. %1 is already in use",array($_POST['projectnumber']));
+ } else {
+ mysql_query("UPDATE projects SET
+ projectnumber='".$_POST['projectnumber']."'
+ WHERE id='".$_POST['id']."'");
+ happy_("Project number successfully changed to %1",array($_POST['projectnumber']));
+ }
+ }
+}
+function project_load()
+{
+ global $registrations_id, $config;
-//output the current status
+ //now lets find out their MAX grade, so we can pre-set the Age Category
+ $q=mysql_query("SELECT MAX(grade) AS maxgrade FROM students WHERE registrations_id='".$registrations_id."'");
+ $gradeinfo=mysql_fetch_object($q);
+
+ //now lets grab all the age categories, so we can choose one based on the max grade
+ $q=mysql_query("SELECT * FROM projectcategories WHERE year='".$config['FAIRYEAR']."' ORDER BY id");
+ while($r=mysql_fetch_object($q)) {
+ //save these in an array, just incase we need them later (FIXME: remove this array if we dont need it)
+ $agecategories[$r->id]['category']=$r->category;
+ $agecategories[$r->id]['mingrade']=$r->mingrade;
+ $agecategories[$r->id]['maxgrade']=$r->maxgrade;
+
+ if($gradeinfo->maxgrade >= $r->mingrade && $gradeinfo->maxgrade <= $r->maxgrade)
+ $projectcategories_id=$r->id;
+ }
+
+ //now select their project info
+ $q=mysql_query("SELECT * FROM projects WHERE registrations_id='".$registrations_id."' AND year='".$config['FAIRYEAR']."'");
+ //check if it exists, if we didnt find any record, lets insert one
+ $projectinfo=mysql_fetch_object($q);
+
+ //make sure that if they changed their grade on the student page, we update their projectcategories_id accordingly
+ if($projectcategories_id && $projectinfo->projectcategories_id!=$projectcategories_id) {
+ echo notice(i18n("Age category changed, updating to %1",array($agecategories[$projectcategories_id]['category'])));
+ mysql_query("UPDATE projects SET projectcategories_id='$projectcategories_id' WHERE id='$projectinfo->id'");
+ }
+
+ //output the current status
?>
-if($projectinfo)
-{
- echo "