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 18:31:42 +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' );
2007-11-19 00:33:38 +00:00
if ( $_GET [ 'action' ] == " edit " || $_GET [ 'action' ] == " new " ) {
send_header (( $_GET [ 'action' ] == " edit " ) ? " Edit Sub-Division " : " New Sub-Division " ,
array ( 'Committee Main' => 'committee_main.php' ,
'SFIAB Configuration' => 'config/index.php' ,
2008-08-22 20:34:38 +00:00
'Project Sub-Divisions' => 'config/subdivisions.php' ),
" project_sub_divisions " );
2007-11-19 00:33:38 +00:00
} else {
send_header ( " Project Sub-Divisions " ,
array ( 'Committee Main' => 'committee_main.php' ,
2008-08-22 20:34:38 +00:00
'SFIAB Configuration' => 'config/index.php' ),
" project_sub_divisions " );
2007-11-19 00:33:38 +00:00
}
2004-12-20 18:31:42 +00:00
2010-10-05 19:43:30 +00:00
if ( $_POST [ 'action' ] == " edit " ) {
if ( $_POST [ 'id' ] && $_POST [ 'projectdivisions_id' ] && $_POST [ 'subdivision' ] ) {
$q = mysql_query ( " SELECT id FROM projectsubdivisions WHERE id=' " . intval ( $_POST [ 'id' ]) . " ' AND conferences_id=' " . $conference [ 'id' ] . " ' " );
if ( mysql_num_rows ( $q ) && $_POST [ 'saveid' ] != $_POST [ 'id' ]) {
2004-12-20 18:31:42 +00:00
echo error ( i18n ( " Sub-Division ID %1 already exists " , array ( $_POST [ 'id' ])));
}
2010-10-05 19:43:30 +00:00
else {
2004-12-20 18:31:42 +00:00
mysql_query ( " UPDATE projectsubdivisions SET " .
2010-10-05 19:43:30 +00:00
" id=' " . intval ( $_POST [ 'id' ]) . " ', " .
2004-12-20 18:31:42 +00:00
" projectdivisions_id=' " . $_POST [ 'projectdivisions_id' ] . " ', " .
2010-10-05 19:43:30 +00:00
" subdivision=' " . mysql_real_escape_string ( $_POST [ 'subdivision' ]) . " ' " .
" WHERE id=' " . intval ( $_POST [ 'saveid' ]) . " ' " );
2004-12-20 18:31:42 +00:00
echo happy ( i18n ( " Sub-Division successfully saved " ));
}
}
2010-10-05 19:43:30 +00:00
else {
2004-12-20 18:31:42 +00:00
echo error ( i18n ( " All fields are required " ));
}
}
2010-10-05 19:43:30 +00:00
if ( $_POST [ 'action' ] == " new " ) {
if ( $_POST [ 'projectdivisions_id' ] && $_POST [ 'subdivision' ]) {
if ( ! $_POST [ 'id' ]) {
2004-12-20 18:31:42 +00:00
$idq = mysql_query ( " SELECT MAX(id) AS id FROM projectsubdivisions " );
$idr = mysql_fetch_object ( $idq );
$newid = $idr -> id + 1 ;
}
else
$newid = $_POST [ 'id' ];
2010-10-05 19:43:30 +00:00
$q = mysql_query ( " SELECT id FROM projectsubdivisions WHERE id=' $newid ' AND conferences_id=' " . $conference [ 'id' ] . " ' " );
if ( mysql_num_rows ( $q )) {
2004-12-20 18:31:42 +00:00
echo error ( i18n ( " Sub-Division ID %1 already exists " , array ( $newid )));
}
2010-10-05 19:43:30 +00:00
else {
mysql_query ( " INSERT INTO projectsubdivisions (id,projectdivisions_id,subdivision,conferences_id) VALUES ( " .
2004-12-20 18:31:42 +00:00
" ' $newid ', " .
2010-10-05 19:43:30 +00:00
" ' " . intval ( $_POST [ 'projectdivisions_id' ]) . " ', " .
" ' " . mysql_real_escape_string ( $_POST [ 'subdivision' ]) . " ', " .
" ' " . $conference [ 'id' ] . " ') " );
2004-12-20 18:31:42 +00:00
echo happy ( i18n ( " Sub-Division successfully added " ));
}
}
2010-10-05 19:43:30 +00:00
else {
2004-12-20 18:31:42 +00:00
echo error ( i18n ( " All fields except ID are required " ));
}
}
2010-10-05 19:43:30 +00:00
if ( $_GET [ 'action' ] == " remove " && $_GET [ 'remove' ]) {
mysql_query ( " DELETE FROM projectsubdivisions WHERE id=' " . intval ( $_GET [ 'remove' ]) . " ' " );
2004-12-20 18:31:42 +00:00
echo happy ( i18n ( " Sub-Division successfully removed " ));
}
echo " <form method= \" post \" action= \" " . $_SERVER [ 'PHP_SELF' ] . " \" > " ;
if ( ! ( $_GET [ 'action' ] == " edit " || $_GET [ 'action' ] == " new " ) )
echo " <a href= \" " . $_SERVER [ 'PHP_SELF' ] . " ?action=new \" > " . i18n ( " Add new sub-division " ) . " </a> \n " ;
echo " <table class= \" summarytable \" > " ;
echo " <tr> " ;
echo " <th> " . i18n ( " Parent Division " ) . " </th> \n " ;
echo " <th> " . i18n ( " ID " ) . " </th> \n " ;
echo " <th> " . i18n ( " Sub-Division " ) . " </th> \n " ;
echo " <th> " . i18n ( " Actions " ) . " </th> \n " ;
echo " </tr> " ;
2010-10-05 19:43:30 +00:00
if ( $_GET [ 'action' ] == " edit " || $_GET [ 'action' ] == " new " ) {
2004-12-20 18:31:42 +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 18:31:42 +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 projectsubdivisions WHERE id=' " . $_GET [ 'edit' ] . " ' AND conferences_id=' " . $conference [ 'id' ] . " ' " );
2004-12-20 18:31:42 +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 18:31:42 +00:00
$buttontext = " Add " ;
}
echo " <tr> " ;
echo " <td> " ;
echo " <select name= \" projectdivisions_id \" > " ;
2010-10-05 19:43:30 +00:00
$dq = mysql_query ( " SELECT * FROM projectdivisions WHERE conferences_id=' " . $conference [ 'id' ] . " ' ORDER BY division " );
while ( $dr = mysql_fetch_object ( $dq )) {
2004-12-20 18:31:42 +00:00
if ( $dr -> id == $divisionr -> projectdivisions_id ) $sel = " selected= \" selected \" " ; else $sel = " " ;
echo " <option $sel value= \" $dr->id\ " > $dr -> division </ option > \n " ;
}
echo " </select> " ;
echo " </td> " ;
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= \" 30 \" name= \" subdivision \" value= \" " . htmlentities ( $divisionr -> subdivision ) . " \" ></td> " ;
2004-12-20 18:31:42 +00:00
echo " <td><input type= \" submit \" value= \" " . i18n ( $buttontext ) . " \" ></td> " ;
echo " </tr> " ;
}
else
{
$q = mysql_query ( " SELECT projectsubdivisions.id,
projectsubdivisions . projectdivisions_id ,
projectsubdivisions . subdivision ,
projectdivisions . division
FROM
projectsubdivisions ,
projectdivisions
WHERE
2010-10-05 19:43:30 +00:00
projectsubdivisions . conferences_id = '".$conference[' id ']."'
AND projectdivisions . conferences_id = '".$conference[' id ']."'
2004-12-20 18:31:42 +00:00
AND projectsubdivisions . projectdivisions_id = projectdivisions . id
ORDER BY
division , subdivision " );
echo mysql_error ();
2010-10-05 19:43:30 +00:00
while ( $r = mysql_fetch_object ( $q )) {
2004-12-20 18:31:42 +00:00
echo " <tr> " ;
echo " <td> $r->division </td> " ;
2004-12-20 18:54:41 +00:00
echo " <td> $r->id </td> " ;
2004-12-20 18:31:42 +00:00
echo " <td> $r->subdivision </td> " ;
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 18:31:42 +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 18:31:42 +00:00
echo " </td> " ;
echo " </tr> " ;
}
}
echo " </table> " ;
if ( $_GET [ 'action' ] == " new " )
echo " " . i18n ( " Leave ID field blank to auto-assign next available ID " );
echo " </form> " ;
send_footer ();
?>