Copyright (C) 2005-2006 James Grant This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // This file was modified Jan of 2014 by Richard Sin // Project type has been added and can be toggled by configuration. // Feedback box also has been added for flagging purposes ?> prepare("SELECT * FROM projects WHERE registrations_id='$registrations_id' AND year='{$config['FAIRYEAR']}' AND fairs_id=$fairs_id"); $q->execute(); if($q->rowCount()!= 1) { echo "permission denied."; exit; } /* Ok, they have permission */ } } switch($action) { case 'project_load': project_load(); break; case 'project_regenerate_number': /* Save first */ project_save(); /* Now generate */ $q=$pdo->prepare("SELECT id FROM projects WHERE registrations_id='{$registrations_id}' AND year='{$config['FAIRYEAR']}'"); $q->execute(); $i=$q->fetch(PDO::FETCH_ASSOC);; $id = $i['id']; $pdo->prepare("UPDATE projects SET projectnumber=NULL,projectsort=NULL, projectnumber_seq='0',projectsort_seq='0' WHERE id='$id'"); $pdo->execute(); echo $pdo->errorInfo(); list($pn,$ps,$pns,$pss) = generateProjectNumber($registrations_id); // print("Generated Project Number [$pn]"); $pdo->prepare("UPDATE projects SET projectnumber='$pn',projectsort='$ps', projectnumber_seq='$pns',projectsort_seq='$pss' WHERE id='$id'"); $pdo->execute(); happy_("Generated and Saved Project Number: $pn"); break; case 'project_save': project_save(); break; default: break; } exit; function project_save() { global $registrations_id, $config; //first, lets make sure this project really does belong to them $q=$pdo->prepare("SELECT * FROM projects WHERE registrations_id='{$registrations_id}' AND year='{$config['FAIRYEAR']}'"); $q->execute(); $projectinfo = $q->fetch(PDO::FETCH_OBJ); if(!projectinfo) { echo error(i18n("Invalid project to update")); } $summarywords=preg_split("/[\s,]+/",$_POST['summary']); $summarywordcount=count($summarywords); if($summarywordcount>$config['participant_project_summary_wordmax']) $summarycountok=0; else $summarycountok=1; //check if it is flagged then update it if(empty($_POST['feedback'])) { $stmt = $pdo->prepare("UPDATE projects SET ". "flagged='0'". "WHERE id='".intval($_POST['id'])."'"); $stmt->execute(); } else { $stmt = $pdo->prepare("UPDATE projects SET ". "flagged='1'". "WHERE id='".intval($_POST['id'])."'"); $stmt->execute(); } echo $pdo->errorInfo(); happy_("Flagging process successfully updated"); 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']); $stmt = $pdo->prepare("UPDATE projects SET ". "title='".iconv("UTF-8","ISO-8859-1//TRANSLIT",$title)."', ". "projectdivisions_id='".intval($_POST['projectdivisions_id']."', ". "projecttype='".stripslashes($_POST['projecttype'])."', ". "language='".stripslashes($_POST['language'])."', ". "req_table='".stripslashes($_POST['req_table'])."', ". "req_electricity='".stripslashes($_POST['req_electricity'])."', ". "req_special='".iconv("UTF-8","ISO-8859-1//TRANSLIT",stripslashes($_POST['req_special']))."', ". "human_participants='".stripslashes($_POST['human_participants'])."', ". "animal_participants='".stripslashes($_POST['animal_participants'])."', ". "summary='".iconv("UTF-8","ISO-8859-1//TRANSLIT",stripslashes($_POST['summary']))."', ". "summarycountok='$summarycountok',". "feedback='".iconv("UTF-8","ISO-8859-1//TRANSLIT",stripslashes($_POST['feedback']))."', ". "projectsort='".stripslashes($_POST['projectsort'])."'". "WHERE id='".intval($_POST['id']))."'"); echo $pdo->errorInfo(); 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=$pdo->prepare("SELECT * FROM projects WHERE year='".$config['FAIRYEAR']."' AND projectnumber='".$_POST['projectnumber']."'"); $q->execute(); if($q->rowCount()) { error_("Could not change project number. %1 is already in use",array($_POST['projectnumber'])); } else { $stmt = $pdo->prepare("UPDATE projects SET projectnumber='".$_POST['projectnumber']."' WHERE id='".$_POST['id']."'"); $stmt->execute(); happy_("Project number successfully changed to %1",array($_POST['projectnumber'])); } } } function project_load() { global $registrations_id, $config; //now lets find out their MAX grade, so we can pre-set the Age Category $q=$pdo->prepare("SELECT MAX(grade) AS maxgrade FROM students WHERE registrations_id='".$registrations_id."'"); $q->execute(); $gradeinfo=$q->fetch(PDO::FETCH_OBJ); //now lets grab all the age categories, so we can choose one based on the max grade $q=$pdo->prepare("SELECT * FROM projectcategories WHERE year='".$config['FAIRYEAR']."' ORDER BY id"); $q->execute(); while($r=$q->fetch(PDO::FETCH_OBJ)) { //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=$pdo->prepare("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 $q->execute(); $projectinfo=$q->fetch(PDO::FETCH_OBJ); if(!$projectinfo) { $stmt = $pdo->prepare("INSERT INTO projects (registrations_id,projectcategories_id,year) VALUES ('".$registrations_id."','$projectcategories_id','".$config['FAIRYEAR']."')"); //and then pull it back out $stmt->execute(); $q=$pdo->prepare("SELECT * FROM projects WHERE registrations_id='".$registrations_id."' AND year='".$config['FAIRYEAR']."'"); $q->execute(); $projectinfo=$q->fetch(PDO::FETCH_OBJ); } //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']))); $stmt = $pdo->prepare("UPDATE projects SET projectcategories_id='$projectcategories_id' WHERE id='$projectinfo->id'"); $stmt->execute(); } //output the current status ?>
prepare("SELECT * FROM projecttypes ORDER BY type"); $q->execute(); echo ""; } ?> "; echo ""; echo ""; echo "
: " />
: " />
:
".i18n("Project Type").": "; echo "".REQUIREDFIELD."
: ()
: prepare("SELECT projectdivisions.* FROM projectdivisions,projectcategoriesdivisions_link WHERE projectdivisions.id=projectdivisions_id AND projectcategories_id=".$projectcategories_id." AND projectdivisions.year='".$config['FAIRYEAR']."' AND projectcategoriesdivisions_link.year='".$config['FAIRYEAR']."' ORDER BY division"); $q->execute(); echo $pdo->errorInfo(); //### } else $q=$pdo->prepare("SELECT * FROM projectdivisions WHERE year='".$config['FAIRYEAR']."' ORDER BY division"); $q->execute(); echo "".REQUIREDFIELD; if($config['usedivisionselector']=="yes") { ?> "; echo i18n("WARNING! If you change the division you must manually change the project number too! It will NOT be assigned a new number automatically"); echo "
".i18n("Language").": "; echo "".REQUIREDFIELD; echo "
".i18n("Requirements").": "; echo ""; if($config['participant_project_table']=="no") { //if we arent asking them if they want a table or not, then we set it to 'yes' assuming everyone will get a table echo " "; } else { echo ""; echo " "; if($projectinfo->req_table=="yes") $check="checked=\"checked\""; else $check=""; echo " "; echo " "; if($projectinfo->req_table=="no") $check="checked=\"checked\""; else $check=""; echo " "; echo ""; } if($config['participant_project_electricity']=="no") { //if we arent asking them if they want electricity or not, then we set it to 'yes' assuming everyone will get electricity echo " "; } else { echo ""; echo " "; if($projectinfo->req_electricity=="yes") $check="checked=\"checked\""; else $check=""; echo " "; echo " "; if($projectinfo->req_electricity=="no") $check="checked=\"checked\""; else $check=""; echo " "; echo ""; } echo ""; echo " "; echo " "; echo ""; echo "
".i18n("Table").REQUIREDFIELD."Yes No
".i18n("Electricity").REQUIREDFIELD."Yes No
".i18n("Special")."req_special\" />
"; if($config['ethics_questions']=="yes") // If we have set ethics questions to yes then ask the ethics questions! { echo "
".i18n("Ethics Questions").":"; echo ""; echo ""; echo " "; if($projectinfo->human_participants=="yes") $check="checked=\"checked\""; else $check=""; echo " "; echo " "; if($projectinfo->human_participants=="no") $check="checked=\"checked\""; else $check=""; echo " "; echo ""; echo ""; echo " "; if($projectinfo->animal_participants=="yes") $check="checked=\"checked\""; else $check=""; echo " "; echo " "; if($projectinfo->animal_participants=="no") $check="checked=\"checked\""; else $check=""; echo " "; echo ""; echo "
".i18n("My project involves human participants").REQUIREDFIELD."Yes No
".i18n("My project involves animals").REQUIREDFIELD."Yes No
"; } echo "
".i18n("Summary").": ".REQUIREDFIELD."
"; $summarywords=preg_split("/[\s,]+/",$projectinfo->summary); $summarywordcount=count($summarywords); if($summarywordcount>$config['participant_project_summary_wordmax']) echo "
"; else echo "
"; echo "$summarywordcount/"; echo i18n("%1 words maximum",array($config['participant_project_summary_wordmax'])); echo "
"; echo"
".i18n("Feedback").":
"; ?>
" />