2006-12-15 18:45:06 +00:00
< ?
/*
This file is part of the 'Science Fair In A Box' project
SFIAB Website : http :// www . sfiab . ca
2006-12-15 19:51:32 +00:00
Copyright ( C ) 2005 - 2006 Sci - Tech Ontario Inc < info @ scitechontario . org >
Copyright ( C ) 2005 - 2006 James Grant < james @ lightbox . org >
2006-12-15 18:45:06 +00:00
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 .
*/
?>
< ?
require ( " ../common.inc.php " );
2007-11-21 17:02:09 +00:00
require_once ( " ../user.inc.php " );
2007-03-04 20:28:51 +00:00
require ( " ../register_participants.inc.php " );
2007-11-18 23:50:23 +00:00
user_auth_required ( 'committee' , 'admin' );
2006-12-15 18:45:06 +00:00
//send the header
2007-11-18 23:50:23 +00:00
send_header ( " Project Editor " ,
array ( 'Committee Main' => 'committee_main.php' ,
'Administration' => 'admin/index.php' ,
2007-12-06 17:38:29 +00:00
'Participant Registration' => 'admin/registration.php' ,
2007-11-18 23:50:23 +00:00
'Registration List and Statistics' => 'admin/registration_list.php' )
);
2006-12-15 18:45:06 +00:00
echo " <br /> " ;
if ( $_POST [ 'registration_id' ]) $registration_id = $_POST [ 'registration_id' ];
else if ( $_GET [ 'registration_id' ]) $registration_id = $_GET [ 'registration_id' ];
2007-03-04 20:28:51 +00:00
if ( $_POST [ 'action' ] == " genprojnum " ) {
2007-12-29 08:46:40 +00:00
$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 );
2007-03-04 20:28:51 +00:00
// print("Generated Project Number [$pn]");
2007-12-29 08:46:40 +00:00
mysql_query ( " UPDATE projects SET projectnumber=' $pn ',projectsort=' $ps ',
projectnumber_seq = '$pns' , projectsort_seq = '$pss'
WHERE id = '$id' " );
echo mysql_error ();
2007-03-04 20:28:51 +00:00
}
2006-12-15 18:45:06 +00:00
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 ;
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' ]);
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' ])) . " ', " .
2008-04-02 17:27:10 +00:00
" summarycountok=' $summarycountok ', " .
" projectsort=' " . mysql_escape_string ( stripslashes ( $_POST [ 'projectsort' ])) . " ' " .
2006-12-15 18:45:06 +00:00
" WHERE id=' " . $_POST [ 'id' ] . " ' " );
echo mysql_error ();
echo notice ( i18n ( " 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 ))
{
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 ;
}
}
//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 ' " );
}
//output the current status
?>
< script language = " javascript " type = " text/javascript " >
function countwords ()
{
var wordmax =< ? = $config [ 'participant_project_summary_wordmax' ]; ?> ;
var summaryobj = document . getElementById ( 'summary' );
var wordcountobj = document . getElementById ( 'wordcount' );
var wordcountmessageobj = document . getElementById ( 'wordcountmessage' );
var wordarray = summaryobj . value . replace ( / \s +/ g , " " ) . split ( " " );
var wordcount = wordarray . length ;
if ( wordcount > wordmax )
wordcountmessageobj . className = " incomplete " ;
else
wordcountmessageobj . className = " complete " ;
wordcountobj . innerHTML = wordcount ;
}
</ script >
< ?
if ( $projectinfo )
{
echo " <form name= \" projectform \" method= \" post \" action= \" project_editor.php \" > \n " ;
echo " <input type= \" hidden \" name= \" action \" value= \" save \" > \n " ;
echo " <input type= \" hidden \" name= \" id \" value= \" $projectinfo->id\ " > \n " ;
echo " <input type= \" hidden \" name= \" registration_id \" value= \" $registration_id\ " > \n " ;
echo " <table> \n " ;
2007-04-03 21:07:44 +00:00
echo " <tr><td> " . i18n ( " Project Title " ) . " : </td><td><input type= \" text \" name= \" title \" size= \" 50 \" value= \" " . htmlspecialchars ( $projectinfo -> title ) . " \" /> " . REQUIREDFIELD ;
2006-12-15 18:45:06 +00:00
if ( $config [ 'participant_project_title_charmax' ])
echo i18n ( " (Max %1 characters) " , array ( $config [ 'participant_project_title_charmax' ]));
echo " </td></tr> \n " ;
echo " <tr><td> " . i18n ( " Project Number " ) . " : </td><td><input type= \" text \" name= \" projectnumber \" size= \" 10 \" value= \" $projectinfo->projectnumber\ " /> " ;
2008-04-02 17:27:10 +00:00
echo " <tr><td> " . i18n ( " Project Sort " ) . " : </td><td><input type= \" text \" name= \" projectsort \" size= \" 10 \" value= \" $projectinfo->projectsort\ " /> " ;
2006-12-15 18:45:06 +00:00
echo " <tr><td> " . i18n ( " Age Category " ) . " : </td><td> " ;
echo i18n ( $agecategories [ $projectcategories_id ][ 'category' ]);
echo " ( " . i18n ( " Grades %1-%2 " , array ( $agecategories [ $projectcategories_id ][ 'mingrade' ], $agecategories [ $projectcategories_id ][ 'maxgrade' ])) . " ) " ;
echo " </td></tr> " ;
echo " <tr><td> " . i18n ( " Division " ) . " : </td><td> " ;
//###### Feature Specific - filtering divisions by category
if ( $config [ 'filterdivisionbycategory' ] == " yes " ){
$q = mysql_query ( " 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 " );
echo mysql_error ();
//###
} else
$q = mysql_query ( " SELECT * FROM projectdivisions WHERE year=' " . $config [ 'FAIRYEAR' ] . " ' ORDER BY division " );
echo " <select name= \" projectdivisions_id \" > " ;
echo " <option value= \" \" > " . i18n ( " Select a division " ) . " </option> \n " ;
while ( $r = mysql_fetch_object ( $q ))
{
if ( $r -> id == $projectinfo -> projectdivisions_id ) $sel = " selected= \" selected \" " ; else $sel = " " ;
echo " <option $sel value= \" $r->id\ " > " .htmlspecialchars(i18n( $r->division )). " </ option > \n " ;
}
echo " </select> " . REQUIREDFIELD ;
if ( $config [ 'usedivisionselector' ] == " yes " )
{
?>
< script language = " javascript " type = " text/javascript " >
function openDivSelWindow ()
{
divselwin = window . open ( 'register_participants_project_divisionselector.php' , 'divsel' , 'width=500,height=220,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no' )
if ( divselwin . opener == null ) divselwin . opener = self ;
return false ;
}
</ script >
< ?
}
echo " <br /> " ;
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 " </td></tr> " ;
echo " <tr><td> " . i18n ( " Language " ) . " : </td><td> " ;
echo " <select name= \" language \" > \n " ;
if ( $projectinfo -> language )
$currentlang = $projectinfo -> language ;
else
$currentlang = $_SESSION [ 'lang' ];
foreach ( $config [ 'languages' ] AS $key => $val )
{
if ( $currentlang == $key ) $selected = " selected= \" selected \" " ; else $selected = " " ;
echo " <option $selected value= \" $key\ " > $val </ option > " ;
}
echo " </select> " . REQUIREDFIELD ;
echo " </td></tr> " ;
echo " <tr><td> " . i18n ( " Requirements " ) . " : </td><td> " ;
echo " <table> " ;
2007-01-02 20:33:16 +00:00
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 " <input type= \" hidden \" name= \" req_table \" value= \" yes \" /> " ;
}
else
{
echo " <tr> " ;
echo " <td> " . i18n ( " Table " ) . REQUIREDFIELD . " </td> " ;
if ( $projectinfo -> req_table == " yes " ) $check = " checked= \" checked \" " ; else $check = " " ;
echo " <td><input $check type= \" radio \" name= \" req_table \" value= \" yes \" />Yes</td> " ;
echo " <td width= \" 20 \" > </td> " ;
if ( $projectinfo -> req_table == " no " ) $check = " checked= \" checked \" " ; else $check = " " ;
echo " <td><input $check type= \" radio \" name= \" req_table \" value= \" no \" />No</td> " ;
echo " </tr> " ;
}
2006-12-15 18:45:06 +00:00
2007-01-02 20:33:16 +00:00
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 " <input type= \" hidden \" name= \" req_electricity \" value= \" yes \" /> " ;
}
else
{
echo " <tr> " ;
echo " <td> " . i18n ( " Electricity " ) . REQUIREDFIELD . " </td> " ;
if ( $projectinfo -> req_electricity == " yes " ) $check = " checked= \" checked \" " ; else $check = " " ;
echo " <td><input $check type= \" radio \" name= \" req_electricity \" value= \" yes \" />Yes</td> " ;
echo " <td width= \" 20 \" > </td> " ;
if ( $projectinfo -> req_electricity == " no " ) $check = " checked= \" checked \" " ; else $check = " " ;
echo " <td><input $check type= \" radio \" name= \" req_electricity \" value= \" no \" />No</td> " ;
echo " </tr> " ;
}
2006-12-15 18:45:06 +00:00
echo " <tr> " ;
echo " <td> " . i18n ( " Special " ) . " </td> " ;
echo " <td colspan= \" 3 \" ><input type= \" text \" name= \" req_special \" value= \" $projectinfo->req_special\ " /></ td > " ;
echo " </tr> " ;
echo " </table> " ;
echo " </td></tr> " ;
echo " <tr><td> " . i18n ( " Summary " ) . " : </td><td><textarea onchange='countwords()' onkeypress='countwords()' cols= \" 60 \" rows= \" 12 \" id= \" summary \" name= \" summary \" > " . htmlspecialchars ( $projectinfo -> summary ) . " </textarea> " . REQUIREDFIELD . " <br /> " ;
$summarywords = preg_split ( " /[ \ s,]+/ " , $projectinfo -> summary );
$summarywordcount = count ( $summarywords );
if ( $summarywordcount > $config [ 'participant_project_summary_wordmax' ])
echo " <div id= \" wordcountmessage \" class= \" incomplete \" > " ;
else
echo " <div id= \" wordcountmessage \" class= \" complete \" > " ;
echo " <span id= \" wordcount \" > $summarywordcount </span>/ " ;
echo i18n ( " %1 words maximum " , array ( $config [ 'participant_project_summary_wordmax' ]));
echo " </div> " ;
echo " </td></tr> " ;
echo " </table> " ;
echo " <input type= \" submit \" value= \" " . i18n ( " Save Project Information " ) . " \" /> \n " ;
echo " </form> " ;
2007-03-04 20:28:51 +00:00
echo ( " <br /><br /><h3> " . i18n ( " Other Actions " ) . " </h3><br /> " );
echo " <form name= \" projectform \" method= \" post \" action= \" project_editor.php \" > \n " ;
echo " <input type= \" hidden \" name= \" action \" value= \" genprojnum \" > \n " ;
echo " <input type= \" hidden \" name= \" id \" value= \" $projectinfo->id\ " > \n " ;
echo " <input type= \" hidden \" name= \" registration_id \" value= \" $registration_id\ " > \n " ;
echo " <input type= \" submit \" value= \" " . i18n ( " Re-Generate Project Number " ) . " \" /> \n " ;
echo " </form> " ;
2006-12-15 18:45:06 +00:00
}
else
{
echo error ( i18n ( " Invalid project to edit " ));
}
send_footer ();
?>