2005-01-24 18:00:03 +00:00
< ?
/*
This file is part of the 'Science Fair In A Box' project
SFIAB Website : http :// www . sfiab . ca
Copyright ( C ) 2005 Sci - Tech Ontario Inc < info @ scitechontario . org >
Copyright ( C ) 2005 James Grant < james @ lightbox . org >
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 .
*/
?>
2004-12-20 16:35:15 +00:00
< ?
require ( " ../common.inc.php " );
2007-11-21 17:04:35 +00:00
require_once ( " ../user.inc.php " );
2010-07-13 03:30:23 +00:00
user_auth_required ( 'config' );
2004-12-20 16:35:15 +00:00
2007-11-19 00:33:38 +00:00
if ( $_GET [ 'action' ] == " edit " || $_GET [ 'action' ] == " new " ) {
send_header (( $_GET [ 'action' ] == " edit " ) ? " Edit Division " : " New Division " ,
array ( 'Committee Main' => 'committee_main.php' ,
'SFIAB Configuration' => 'config/index.php' ,
2008-08-22 20:34:38 +00:00
'Project Divisions' => 'config/divisions.php' ),
" project_divisions " );
2007-11-19 00:33:38 +00:00
} else {
send_header ( " Project Divisions " ,
array ( 'Committee Main' => 'committee_main.php' ,
2008-08-22 20:34:38 +00:00
'SFIAB Configuration' => 'config/index.php' ),
" project_divisions " );
2007-11-19 00:33:38 +00:00
}
2010-10-05 19:43:30 +00:00
if ( $_POST [ 'action' ] == " edit " ) {
if ( $_POST [ 'id' ] && $_POST [ 'division' ] ) {
$q = mysql_query ( " SELECT id FROM projectdivisions WHERE id=' " . $_POST [ 'id' ] . " ' AND conferences_id=' " . $conference [ 'id' ] . " ' " );
if ( mysql_num_rows ( $q ) && $_POST [ 'saveid' ] != $_POST [ 'id' ]) {
2006-01-19 17:15:07 +00:00
echo error ( i18n ( " Division ID %1 already exists " , array ( $_POST [ 'id' ]), array ( " division ID " )));
2004-12-20 17:03:48 +00:00
}
2010-10-05 19:43:30 +00:00
else {
2004-12-20 17:03:48 +00:00
mysql_query ( " UPDATE projectdivisions SET " .
2010-10-05 19:43:30 +00:00
" id=' " . intval ( $_POST [ 'id' ]) . " ', " .
" division=' " . mysql_real_escape_string ( $_POST [ 'division' ]) . " ', " .
" division_shortform=' " . mysql_real_escape_string ( $_POST [ 'division_shortform' ]) . " ' " .
" WHERE id=' " . intval ( $_POST [ 'saveid' ]) . " ' AND conferences_id=' { $conference [ 'id' ] } ' " );
2006-02-01 16:29:08 +00:00
//###### Feature Specific - filtering divisions by category
if ( $config [ 'filterdivisionbycategory' ] == " yes " ){
2010-10-05 19:43:30 +00:00
mysql_query ( " DELETE FROM projectcategoriesdivisions_link WHERE projectdivisions_id=' " . intval ( $_POST [ 'saveid' ]) . " ' AND conferences_id=' " . $conference [ 'id' ] . " ' " );
2006-02-01 16:29:08 +00:00
2010-10-05 19:43:30 +00:00
if ( is_array ( $_POST [ 'divcat' ])) {
foreach ( $_POST [ 'divcat' ] as $tempcat ) {
mysql_query ( " INSERT INTO projectcategoriesdivisions_link (projectdivisions_id,projectcategories_id,conferences_id) VALUES ( " .
2006-02-01 16:29:08 +00:00
" ' " . $_POST [ 'id' ] . " ', " .
" ' " . $tempcat . " ', " .
2010-10-05 19:43:30 +00:00
" ' " . $conference [ 'id' ] . " ') " );
2006-02-06 17:22:25 +00:00
}
2006-02-01 16:29:08 +00:00
}
}
//###########
2004-12-20 17:03:48 +00:00
echo happy ( i18n ( " Division successfully saved " ));
}
}
2010-10-05 19:43:30 +00:00
else {
2004-12-20 17:03:48 +00:00
echo error ( i18n ( " All fields are required " ));
}
}
2010-10-05 19:43:30 +00:00
if ( $_POST [ 'action' ] == " new " ) {
2011-01-28 18:22:18 +00:00
if ( $_POST [ 'id' ] && $_POST [ 'division' ]) {
$q = mysql_query ( " SELECT id FROM projectdivisions WHERE id=' " . intval ( $_POST [ 'id' ]) . " ' AND conferences_id=' " . $conference [ 'id' ] . " ' " );
2010-10-05 19:43:30 +00:00
if ( mysql_num_rows ( $q )) {
2006-01-19 17:15:07 +00:00
echo error ( i18n ( " Division ID %1 already exists " , array ( $_POST [ 'id' ]), array ( " division ID " )));
2004-12-20 17:03:48 +00:00
}
2010-10-05 19:43:30 +00:00
else {
mysql_query ( " INSERT INTO projectdivisions (id,division,division_shortform,conferences_id) VALUES ( " .
" ' " . intval ( $_POST [ 'id' ]) . " ', " .
" ' " . mysql_real_escape_string ( $_POST [ 'division' ]) . " ', " .
" ' " . mysql_real_escape_string ( $_POST [ 'division_shortform' ]) . " ', " .
" ' " . $conference [ 'id' ] . " ') " );
2006-02-01 16:29:08 +00:00
//###### Feature Specific - filtering divisions by category
if ( $config [ 'filterdivisionbycategory' ] == " yes " ){
foreach ( $_POST [ 'divcat' ] as $tempcat ){
2010-10-05 19:43:30 +00:00
mysql_query ( " INSERT INTO projectcategoriesdivisions_link (projectdivisions_id,projectcategories_id,conferences_id) VALUES ( " .
" ' " . intval ( $tempcat ) . " ', " .
" ' " . $conference [ 'id' ] . " ') " );
2006-02-01 16:29:08 +00:00
}
}
//#######
2004-12-20 17:03:48 +00:00
echo happy ( i18n ( " Division successfully added " ));
}
}
2010-10-05 19:43:30 +00:00
else {
2004-12-20 17:03:48 +00:00
echo error ( i18n ( " All fields are required " ));
}
}
2010-10-05 19:43:30 +00:00
if ( $_GET [ 'action' ] == " remove " && $_GET [ 'remove' ]) {
2006-02-01 16:29:08 +00:00
//###### Feature Specific - filtering divisions by category - not conditional, cause even if they have the filtering turned off..if any links
//for this division exist they should be deleted
2010-10-05 19:43:30 +00:00
mysql_query ( " DELETE FROM projectcategoriesdivisions_link WHERE projectdivisions_id=' " . intval ( $_GET [ 'remove' ]) . " ' AND conferences_id=' " . $conference [ 'id' ] . " ' " );
mysql_query ( " DELETE FROM projectdivisions WHERE id=' " . intval ( $_GET [ 'remove' ]) . " ' AND conferences_id=' " . $conference [ 'id' ] . " ' " );
2004-12-20 17:03:48 +00:00
echo happy ( i18n ( " Division successfully removed " ));
2004-12-20 16:35:15 +00:00
}
echo " <form method= \" post \" action= \" " . $_SERVER [ 'PHP_SELF' ] . " \" > " ;
2004-12-20 18:31:42 +00:00
2004-12-20 17:03:48 +00:00
if ( ! ( $_GET [ 'action' ] == " edit " || $_GET [ 'action' ] == " new " ) )
echo " <a href= \" " . $_SERVER [ 'PHP_SELF' ] . " ?action=new \" > " . i18n ( " Add new division " ) . " </a> \n " ;
2004-12-20 16:35:15 +00:00
echo " <table class= \" summarytable \" > " ;
echo " <tr> " ;
2004-12-20 17:03:48 +00:00
echo " <th> " . i18n ( " Division ID " ) . " </th> \n " ;
echo " <th> " . i18n ( " Division Name " ) . " </th> \n " ;
2005-01-13 23:59:22 +00:00
echo " <th> " . i18n ( " Short Form " ) . " </th> \n " ;
2006-02-01 16:29:08 +00:00
//###### Feature Specific - filtering divisions by category
if ( $config [ 'filterdivisionbycategory' ] == " yes " )
echo " <th> " . i18n ( " Categories " ) . " </th> \n " ;
//#####
2004-12-20 16:35:15 +00:00
echo " <th> " . i18n ( " Actions " ) . " </th> \n " ;
echo " </tr> " ;
2004-12-20 17:03:48 +00:00
2010-10-05 19:43:30 +00:00
if ( $_GET [ 'action' ] == " edit " || $_GET [ 'action' ] == " new " ) {
2004-12-20 17:03:48 +00:00
echo " <input type= \" hidden \" name= \" action \" value= \" " . $_GET [ 'action' ] . " \" > \n " ;
2010-10-05 19:43:30 +00:00
if ( $_GET [ 'action' ] == " edit " ) {
2004-12-20 17:03:48 +00:00
echo " <input type= \" hidden \" name= \" saveid \" value= \" " . $_GET [ 'edit' ] . " \" > \n " ;
2010-10-05 19:43:30 +00:00
$q = mysql_query ( " SELECT * FROM projectdivisions WHERE id=' " . $_GET [ 'edit' ] . " ' AND conferences_id=' " . $conference [ 'id' ] . " ' " );
2004-12-20 17:03:48 +00:00
$divisionr = mysql_fetch_object ( $q );
$buttontext = " Save " ;
}
2010-10-05 19:43:30 +00:00
else if ( $_GET [ 'action' ] == " new " ) {
2004-12-20 17:03:48 +00:00
$buttontext = " Add " ;
}
echo " <tr> " ;
2005-01-13 23:59:22 +00:00
echo " <td><input type= \" text \" size= \" 3 \" name= \" id \" value= \" $divisionr->id\ " /></ td > " ;
2010-10-05 20:18:32 +00:00
echo " <td><input type= \" text \" size= \" 40 \" name= \" division \" value= \" " . htmlentities ( $divisionr -> division ) . " \" /></td> " ;
echo " <td align= \" center \" ><input type= \" text \" size= \" 5 \" name= \" division_shortform \" value= \" " . htmlentities ( $divisionr -> division_shortform ) . " \" /></td> " ;
2006-02-01 16:29:08 +00:00
//###### Feature Specific - filtering divisions by category
if ( $config [ 'filterdivisionbycategory' ] == " yes " ){
echo " <td> " ;
2010-10-05 19:43:30 +00:00
$q = mysql_query ( " SELECT * FROM projectcategories WHERE conferences_id=' " . $conference [ 'id' ] . " ' ORDER BY mingrade " );
2006-02-01 16:29:08 +00:00
while ( $categoryr = mysql_fetch_object ( $q )){
2010-10-05 19:43:30 +00:00
$query = " SELECT * FROM projectcategoriesdivisions_link WHERE projectdivisions_id= " . $divisionr -> id . " AND projectcategories_id= " . $categoryr -> id . " AND conferences_id=' " . $conference [ 'id' ] . " ' " ;
2006-02-01 16:29:08 +00:00
$t = mysql_query ( $query );
if ( $t && mysql_num_rows ( $t ) > 0 )
2006-02-01 16:32:41 +00:00
echo " <nobr><input type= \" checkbox \" name= \" divcat[] \" value= \" $categoryr->id\ " checked = \ " checked \" /> $categoryr->category </nobr><br/> " ;
2006-02-01 16:29:08 +00:00
else
2006-02-01 16:32:41 +00:00
echo " <nobr><input type= \" checkbox \" name= \" divcat[] \" value= \" $categoryr->id\ " /> $categoryr -> category </ nobr >< br /> " ;
2006-02-01 16:29:08 +00:00
}
echo " </td> " ;
}
2005-01-13 23:59:22 +00:00
echo " <td><input type= \" submit \" value= \" " . i18n ( $buttontext ) . " \" /></td> " ;
2004-12-20 16:35:15 +00:00
echo " </tr> " ;
}
2010-10-05 19:43:30 +00:00
else {
$q = mysql_query ( " SELECT * FROM projectdivisions WHERE conferences_id=' " . $conference [ 'id' ] . " ' ORDER BY id " );
2004-12-20 17:03:48 +00:00
while ( $r = mysql_fetch_object ( $q ))
{
echo " <tr> " ;
echo " <td> $r->id </td> " ;
2006-01-19 17:15:07 +00:00
echo " <td> " . i18n ( $r -> division ) . " </td> " ;
2005-01-13 23:59:22 +00:00
echo " <td align= \" center \" > $r->division_shortform </td> " ;
2006-02-01 16:29:08 +00:00
//###### Feature Specific - filtering divisions by category
if ( $config [ 'filterdivisionbycategory' ] == " yes " ){
$c = mysql_query ( " SELECT category FROM projectcategoriesdivisions_link, projectcategories
WHERE projectcategoriesdivisions_link . projectcategories_id = projectcategories . id
AND projectdivisions_id = '$r->id'
2010-10-05 19:43:30 +00:00
AND projectcategoriesdivisions_link . conferences_id = '".$conference[' id ']."'
AND projectcategories . conferences_id = '".$conference[' id ']."'
2006-02-01 16:29:08 +00:00
ORDER BY projectcategories . mingrade " );
2006-02-01 16:39:48 +00:00
echo mysql_error ();
2006-02-01 16:29:08 +00:00
if ( ! $c ){
$tempcat = " " ;
} else {
$tempcat = " " ;
while ( $categoryr = mysql_fetch_object ( $c )){
$tempcat .= " , " . $categoryr -> category ;
}
$tempcat = substr ( $tempcat , 1 );
}
echo " <td> { $tempcat } </td> " ;
}
//############
2004-12-20 17:03:48 +00:00
echo " <td> " ;
2005-01-25 17:00:23 +00:00
echo " <a title= \" Edit \" href= \" " . $_SERVER [ 'PHP_SELF' ] . " ?action=edit&edit= $r->id\ " >< img src = \ " " . $config [ 'SFIABDIRECTORY' ] . " /images/16/edit. " . $config [ 'icon_extension' ] . " \" border=0></a> " ;
2004-12-20 17:03:48 +00:00
echo " " ;
2005-01-25 17:00:23 +00:00
echo " <a title= \" Remove \" onClick= \" return confirmClick('Are you sure you want to remove this division?'); \" href= \" " . $_SERVER [ 'PHP_SELF' ] . " ?action=remove&remove= $r->id\ " >< img src = \ " " . $config [ 'SFIABDIRECTORY' ] . " /images/16/button_cancel. " . $config [ 'icon_extension' ] . " \" border=0></a> " ;
2004-12-20 17:03:48 +00:00
echo " </td> " ;
echo " </tr> " ;
}
}
2004-12-20 16:35:15 +00:00
echo " </table> " ;
echo " </form> " ;
2005-01-21 17:30:28 +00:00
echo i18n ( " You should assign the 'Division ID's in numerical order, starting with 1. This Division ID is used to generate the project number " );
2004-12-20 16:35:15 +00:00
send_footer ();
?>