2007-11-17 21:59:59 +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 .
*/
?>
< ?
require_once ( " ../common.inc.php " );
2007-11-21 16:46:19 +00:00
require_once ( " ../user.inc.php " );
2007-11-17 21:59:59 +00:00
require_once ( " ../committee.inc.php " );
user_auth_required ( 'committee' , 'admin' );
2007-11-19 21:45:08 +00:00
if ( $_POST [ 'users_id' ])
$uid = intval ( $_POST [ 'users_id' ]);
2007-11-17 21:59:59 +00:00
/* Some actions we want to redirect to the personal editor, so deal with those first */
if ( $_POST [ 'add_member' ])
{
$u = user_create ( 'committee' );
list ( $u [ 'firstname' ], $u [ 'lastname' ]) = split ( ' ' , $_POST [ 'add_member' ]);
user_save ( $u );
header ( " location: { $config [ 'SFIABDIRECTORY' ] } /user_personal.php?edit= { $u [ 'id' ] } " );
exit ;
}
if ( $_POST [ 'action' ] == 'edit' ) {
2007-11-19 21:45:08 +00:00
header ( " location: { $config [ 'SFIABDIRECTORY' ] } /user_personal.php?edit= $uid " );
2007-11-17 21:59:59 +00:00
exit ;
}
/* Now, start the output for this page */
send_header ( " Committee Management " ,
array ( 'Committee Main' => 'committee_main.php' ,
'Administration' => 'admin/index.php' ));
$_SESSION [ 'last_page' ] = 'committee_management' ;
?>
< script type = " text/javascript " >
<!--
function getElement ( e , f )
{
if ( document . layers )
{
f = ( f ) ? f : self ;
if ( f . document . layers [ e ]) {
return f . document . layers [ e ];
}
for ( W = 0 ; i < f . document . layers . length ; W ++ ) {
return ( getElement ( e , fdocument . layers [ W ]));
}
}
if ( document . all ) {
return document . all [ e ];
}
return document . getElementById ( e );
}
function actionChanged ()
{
if ( document . forms . memberaction . action . selectedIndex == 1 ) //assign
{
getElement ( 'assigndiv' ) . style . display = 'block' ;
}
else // edit or delete
{
getElement ( 'assigndiv' ) . style . display = 'none' ;
}
}
function actionSubmit ()
{
if ( document . forms . memberaction . action . selectedIndex == 0 )
{
alert ( 'You must choose an action' );
return false ;
}
if ( document . forms . memberaction . users_id . selectedIndex == 0 )
{
alert ( 'You must choose a member' );
return false ;
}
if ( document . forms . memberaction . action . selectedIndex == 3 ) //remove
{
return confirmClick ( 'Are you sure you want to completely remove this member?' );
}
return true ;
}
//-->
</ script >
< ?
if ( $_POST [ 'addcommittee' ])
{
//add a new committee
mysql_query ( " INSERT INTO committees (name) VALUES (' " . mysql_escape_string ( $_POST [ 'addcommittee' ]) . " ') " );
echo happy ( i18n ( " Committee successfully added " ));
}
if ( $_POST [ 'committees_id' ] && $_POST [ 'committees_ord' ])
{
//re-order the committees
$x = 0 ;
$ids = $_POST [ 'committees_id' ];
$ords = $_POST [ 'committees_ord' ];
2007-11-20 20:46:05 +00:00
$titles = $_POST [ 'title' ];
$pords = $_POST [ 'order' ];
2007-11-17 21:59:59 +00:00
while ( $ids [ $x ])
{
2007-11-20 20:46:05 +00:00
$cid = intval ( $ids [ $x ]);
mysql_query ( " UPDATE committees SET ord=' " . intval ( $ords [ $x ]) . " ' WHERE id=' $cid ' " );
2007-11-17 21:59:59 +00:00
$x ++ ;
2007-11-20 20:46:05 +00:00
$ctitle = $titles [ $cid ];
$cord = $pords [ $cid ];
2008-01-07 05:38:44 +00:00
/* If the committee has no members , don ' t bother trying to do
* anything */
if ( ! is_array ( $ctitle )) continue ;
2007-11-20 20:46:05 +00:00
foreach ( $ctitle as $uid => $title ) {
$o = intval ( $cord [ $uid ]);
$t = mysql_escape_string ( stripslashes ( $title ));
$u = intval ( $uid );
$q = " UPDATE committees_link SET title=' $t ', ord=' $o '
WHERE committees_id = '$cid' AND users_id = '$u' " ;
mysql_query ( $q );
}
2007-11-17 21:59:59 +00:00
}
2007-11-20 20:46:05 +00:00
echo happy ( i18n ( " Committees successfully saved " ));
2007-11-17 21:59:59 +00:00
}
if ( $_POST [ 'action' ] == " assign " )
{
if ( $_POST [ 'committees_id' ] && $_POST [ 'users_id' ])
{
$cid = intval ( $_POST [ 'committees_id' ]);
2007-11-19 21:45:08 +00:00
$q = mysql_query ( " SELECT * FROM committees_link WHERE committees_id=' $cid ' AND users_id=' $uid ' " );
2007-11-17 21:59:59 +00:00
if ( ! mysql_num_rows ( $q ))
{
2007-11-19 21:45:08 +00:00
mysql_query ( " INSERT INTO committees_link (committees_id,users_id) VALUES (' $cid ',' $uid ') " );
2007-11-17 21:59:59 +00:00
echo happy ( i18n ( " Successfully added member to committee " ));
}
else
echo error ( i18n ( " That member already exists in that committee " ));
}
else
echo error (( " You must choose both a member and a committee " ));
}
if ( $_GET [ 'deletecommittee' ])
{
$del = intval ( $_GET [ 'deletecommittee' ]);
mysql_query ( " DELETE FROM committees WHERE id=' $del ' " );
echo happy ( i18n ( " Committee removed " ));
}
if ( $_POST [ 'action' ] == " remove " )
{
2007-11-19 21:45:08 +00:00
user_delete ( $uid , 'committee' );
mysql_query ( " DELETE FROM committees_link WHERE users_id=' $uid ' " );
2007-11-17 21:59:59 +00:00
echo happy ( i18n ( " Committee member removed " ));
}
if ( $_GET [ 'unlinkmember' ] && $_GET [ 'unlinkcommittee' ])
{
$mem = intval ( $_GET [ 'unlinkmember' ]);
$com = intval ( $_GET [ 'unlinkcommittee' ]);
//unlink the member from the committee
mysql_query ( " DELETE FROM committees_link WHERE users_id=' $mem ' AND committees_id=' $com ' " );
echo happy ( i18n ( " Committee member unlinked from committee " ));
}
/* This seems to be unused ( there would also be an sql error on the INSERT : p ) :
if ( $_POST [ 'add_member_to_committees_id' ])
{
$add = intval ( $_POST [ 'add_member_to_committees_id' ]);
mysql_query ( " INSERT INTO committees_link (committees_id,users_id) VALUES (' $add ') " );
$edit = $_POST [ 'committees_members_id' ];
}
*/
echo " <table> " ;
echo " <tr><td> " ;
echo " <h4> " . i18n ( " Add Committee " ) . " </h4> \n " ;
2007-11-19 21:45:08 +00:00
echo " <form method= \" post \" action= \" committees.php \" > \n " ;
2007-11-17 21:59:59 +00:00
echo " <table> \n " ;
echo " <tr><td> " . i18n ( " Committee Name " ) . " : </td><td><input type= \" text \" size= \" 15 \" name= \" addcommittee \" /></td> " ;
echo " <td><input type= \" submit \" value= \" " . i18n ( " Add " ) . " \" /></td></tr> \n " ;
echo " </table> \n " ;
echo " </form> \n " ;
echo " </td><td width= \" 40 \" > </td><td> " ;
echo " <h4> " . i18n ( " Add Committee Member " ) . " </h4> \n " ;
echo " <form method= \" post \" action= \" committees.php \" > \n " ;
echo " <table> \n " ;
echo " <tr><td> " . i18n ( " Member Name " ) . " : </td><td> " ;
echo " <input type= \" text \" size= \" 15 \" name= \" add_member \" /> \n " ;
echo " </td> \n " ;
echo " <td><input type= \" submit \" value= \" " . i18n ( " Add " ) . " \" /></td></tr> \n " ;
echo " </table> \n " ;
echo " </form> \n " ;
echo " </td></tr> " ;
echo " </table> " ;
echo " <hr /> " ;
echo " <h4> " . i18n ( " Committee Member Management " ) . " </h4> \n " ;
echo " <form name= \" memberaction \" method= \" post \" action= \" committees.php \" onsubmit= \" return actionSubmit() \" > \n " ;
echo " <table> " ;
echo " <tr><td> " ;
echo " <select name= \" action \" onchange= \" javascript:actionChanged() \" > " ;
echo " <option value= \" \" > " . i18n ( " Choose " ) . " </option> \n " ;
echo " <option value= \" assign \" > " . i18n ( " Assign " ) . " </option> \n " ;
echo " <option value= \" edit \" > " . i18n ( " Edit " ) . " </option> \n " ;
echo " <option value= \" remove \" > " . i18n ( " Remove " ) . " </option> \n " ;
echo " </select> " ;
echo " </td><td> " ;
$q = mysql_query ( " SELECT * FROM users WHERE types LIKE '%committee%' ORDER BY firstname " );
echo " <select name= \" users_id \" > " ;
echo " <option value= \" \" > " . i18n ( " Select a Member " ) . " </option> \n " ;
while ( $r = mysql_fetch_object ( $q ))
{
2007-11-29 18:49:34 +00:00
$displayname = $r -> firstname . ' ' . $r -> lastname ;
echo " <option value= \" $r->id\ " > $displayname </ option > \n " ;
2007-11-17 21:59:59 +00:00
}
echo " </select> " ;
echo " </td><td> " ;
//The Assign Div
echo " <div id= \" assigndiv \" > " ;
echo i18n ( " To Committee " ) . " : " ;
$q = mysql_query ( " SELECT * FROM committees ORDER BY ord,name " );
echo " <select name= \" committees_id \" > " ;
echo " <option value= \" \" > " . i18n ( " Select a Committee " ) . " </option> \n " ;
while ( $r = mysql_fetch_object ( $q ))
{
echo " <option value= \" $r->id\ " > $r -> name </ option > \n " ;
}
echo " </select> " ;
echo " </div> " ;
//The Edit or Remove Div
echo " </td><td><input type= \" submit \" value= \" " . i18n ( " Go " ) . " \" /></td></tr> " ;
echo " </table> " ;
echo " </form> " ;
echo " <script language= \" javascript \" type= \" text/javascript \" >actionChanged()</script> " ;
echo " <hr /> " ;
$q = mysql_query ( " SELECT * FROM committees ORDER BY ord,name " );
if ( mysql_num_rows ( $q ))
{
echo " <h4> " . i18n ( " Committees " ) . " </h4> " ;
echo " <form method= \" post \" action= \" committees.php \" > \n " ;
echo " <table> " ;
2007-11-20 20:46:05 +00:00
echo " <tr><td colspan= \" 2 \" ></td><td><b> " . i18n ( 'Title' ) . " </b></td> " ;
echo " <td><b> " . i18n ( 'Order' ) . " </b></td> " ;
echo " <td><b> " . i18n ( " Public Email / Private Email " ) . " </b></td></tr> " ;
2007-11-17 21:59:59 +00:00
while ( $r = mysql_fetch_object ( $q ))
{
echo " <tr> " ;
echo " <td colspan= \" 3 \" > " ;
echo " <input type= \" hidden \" name= \" committees_id[] \" value= \" $r->id\ " /> " ;
2007-11-20 20:46:05 +00:00
echo " <input size= \" 1 \" type= \" text \" name= \" committees_ord[] \" value= \" $r->ord\ " /> " ;
2007-11-17 21:59:59 +00:00
echo " <b> $r->name </b> " ;
$q2 = mysql_query ( " SELECT
users . id ,
users . firstname , users . lastname ,
users . email ,
users_committee . emailprivate ,
committees_link . title ,
committees_link . ord
FROM
users , users_committee , committees_link
WHERE
users_committee . users_id = users . id
AND committees_link . users_id = users . id
AND committees_link . committees_id = '$r->id'
ORDER BY
ord , firstname " );
if ( mysql_num_rows ( $q2 ) == 0 )
{
echo " " ;
echo " <a title= \" Remove Committee \" onclick= \" return confirmClick('Are you sure you want to remove this committee?'); \" href= \" committees.php?deletecommittee= $r->id\ " >< img src = \ " " . $config [ 'SFIABDIRECTORY' ] . " /images/16/button_cancel. " . $config [ 'icon_extension' ] . " \" border= \" 0 \" alt= \" Remove Committee \" /></a> " ;
}
echo " </td></tr> \n " ;
echo mysql_error ();
while ( $r2 = mysql_fetch_object ( $q2 ))
{
echo " <tr><td align= \" right \" > " ;
echo " <a title= \" Edit Member \" href= \" { $config [ 'SFIABDIRECTORY' ] } /user_personal.php?edit= { $r2 -> id } \" ><img src= \" { $config [ 'SFIABDIRECTORY' ] } /images/16/edit. { $config [ 'icon_extension' ] } \" border= \" 0 \" alt= \" Edit \" /></a> " ;
echo " " ;
echo " <a title= \" Unlink Member from Committee \" onclick= \" return confirmClick('Are you sure you want to unlink this member from this committee?'); \" href= \" committees.php?unlinkmember= $r2->id &unlinkcommittee= { $r -> id } \" ><img src= \" { $config [ 'SFIABDIRECTORY' ] } /images/16/undo. { $config [ 'icon_extension' ] } \" border= \" 0 \" alt= \" Unlink \" /></a> " ;
echo " </td> " ;
echo " <td valign= \" top \" > " ;
2007-11-20 20:46:05 +00:00
echo " <b> { $r2 -> firstname } { $r2 -> lastname } </b> " ;
echo " </td><td> " ;
echo " <input type= \" text \" value= \" { $r2 -> title } \" name= \" title[ { $r -> id } ][ { $r2 -> id } ] \" size= \" 15 \" > " ;
echo " </td><td> " ;
echo " <input type= \" text \" value= \" { $r2 -> ord } \" name= \" order[ { $r -> id } ][ { $r2 -> id } ] \" size= \" 2 \" > " ;
2007-11-17 21:59:59 +00:00
echo " </td><td> " ;
if ( $r2 -> email )
{
list ( $b , $a ) = split ( " @ " , $r2 -> email );
echo " <script language= \" javascript \" type= \" text/javascript \" >em(' $b ',' $a ')</script> " ;
}
if ( $r2 -> emailprivate )
{
if ( $r2 -> email ) echo " <b>/</b> " ;
list ( $b , $a ) = split ( " @ " , $r2 -> emailprivate );
echo " <script language= \" javascript \" type= \" text/javascript \" >em(' $b ',' $a ')</script> " ;
}
echo " </td></tr> \n " ;
}
echo " <tr><td colspan= \" 2 \" > </td></tr> \n " ;
}
2007-11-20 20:46:05 +00:00
echo " <tr><td colspan= \" 2 \" ><input type= \" submit \" value= \" " . i18n ( " Save Committee Orders and Titles " ) . " \" /></td></tr> \n " ;
2007-11-17 21:59:59 +00:00
echo " </table> " ;
echo " </form> \n " ;
}
send_footer ();
?>