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 " );
2010-07-13 03:30:17 +00:00
user_auth_required ( 'admin' );
2007-11-17 21:59:59 +00:00
2010-07-14 21:04:50 +00:00
if ( $_POST [ 'accounts_id' ])
$accounts_id = intval ( $_POST [ 'accounts_id' ]);
2009-09-09 00:26:12 +00:00
2007-11-17 21:59:59 +00:00
/* Now, start the output for this page */
2010-09-03 16:59:05 +00:00
send_header ( " Committee Member Management " ,
2007-11-17 21:59:59 +00:00
array ( 'Committee Main' => 'committee_main.php' ,
2008-08-22 20:50:38 +00:00
'Administration' => 'admin/index.php' ),
" committee_management " );
2007-11-17 21:59:59 +00:00
2009-09-09 00:26:12 +00:00
2007-11-17 21:59:59 +00:00
$_SESSION [ 'last_page' ] = 'committee_management' ;
?>
< script type = " text/javascript " >
<!--
2009-09-09 00:26:12 +00:00
function openeditor ( id )
{
2010-12-06 19:33:38 +00:00
window . open ( " user_editor_window.php?users_id= " + id , " UserEditor " , " location=no,menubar=no,directories=no,toolbar=no,width=770,height=500,scrollbars=yes " );
2009-09-09 00:26:12 +00:00
return false ;
}
function neweditor ()
{
var username = document . forms . addmember . add_member . value ;
2009-10-29 17:05:15 +00:00
window . open ( " user_editor_window.php?type=committee&username= " + username , " UserEditor " , " location=no,menubar=no,directories=no,toolbar=no,width=770,height=500,scrollbars=yes " );
2009-09-09 00:26:12 +00:00
document . forms . addmember . add_member . value = " " ;
return false ;
}
2007-11-17 21:59:59 +00:00
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 ;
}
2010-07-14 21:04:50 +00:00
if ( document . forms . memberaction . accounts_id . selectedIndex == 0 )
2007-11-17 21:59:59 +00:00
{
alert ( 'You must choose a member' );
return false ;
}
2009-09-09 00:26:12 +00:00
if ( document . forms . memberaction . action . selectedIndex == 2 ) {
// Edit
2010-07-14 21:04:50 +00:00
var id = document . forms . memberaction . accounts_id . options [ document . forms . memberaction . accounts_id . selectedIndex ];
2009-09-09 00:26:12 +00:00
openeditor ( id . value );
// alert("id="+id.value);
return false ;
}
2007-11-17 21:59:59 +00:00
if ( document . forms . memberaction . action . selectedIndex == 3 ) //remove
{
return confirmClick ( 'Are you sure you want to completely remove this member?' );
}
2009-09-09 00:26:12 +00:00
2007-11-17 21:59:59 +00:00
return true ;
}
//-->
</ script >
< ?
2010-09-03 16:59:05 +00:00
if ( $_POST [ 'committees_id' ]) {
2007-11-17 21:59:59 +00:00
//re-order the committees
$x = 0 ;
$ids = $_POST [ 'committees_id' ];
2007-11-20 20:46:05 +00:00
$titles = $_POST [ 'title' ];
$pords = $_POST [ 'order' ];
2009-10-29 21:02:17 +00:00
while ( $ids [ $x ]) {
2007-11-20 20:46:05 +00:00
$cid = intval ( $ids [ $x ]);
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 ;
2010-01-05 17:59:10 +00:00
// print_r($ctitle);
2008-01-07 05:38:44 +00:00
2010-07-14 21:04:50 +00:00
foreach ( $ctitle as $accounts_id => $title ) {
$o = intval ( $cord [ $accounts_id ]);
2007-11-20 20:46:05 +00:00
$t = mysql_escape_string ( stripslashes ( $title ));
2010-07-14 21:04:50 +00:00
$u = intval ( $accounts_id );
2007-11-20 20:46:05 +00:00
$q = " UPDATE committees_link SET title=' $t ', ord=' $o '
2010-07-14 21:04:50 +00:00
WHERE committees_id = '$cid' AND accounts_id = '$u' " ;
2010-01-05 18:02:24 +00:00
// echo $q;
2007-11-20 20:46:05 +00:00
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 " )
{
2010-07-14 21:04:50 +00:00
if ( $_POST [ 'committees_id' ] && $_POST [ 'accounts_id' ]) {
2007-11-17 21:59:59 +00:00
$cid = intval ( $_POST [ 'committees_id' ]);
2010-07-14 21:04:50 +00:00
$q = mysql_query ( " SELECT * FROM committees_link WHERE committees_id=' $cid ' AND accounts_id=' $accounts_id ' " );
2007-11-17 21:59:59 +00:00
2009-10-29 21:02:17 +00:00
if ( ! mysql_num_rows ( $q )) {
2010-07-14 21:04:50 +00:00
mysql_query ( " INSERT INTO committees_link (committees_id,accounts_id) VALUES (' $cid ',' $accounts_id ') " );
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 " ));
}
2009-10-29 21:02:17 +00:00
if ( $_POST [ 'action' ] == " remove " ) {
2009-09-09 00:26:12 +00:00
/* user_delete takes care of unlinking the user in other tables */
2010-07-14 21:04:50 +00:00
user_delete ( $accounts_id , 'committee' );
2009-09-09 00:26:12 +00:00
echo happy ( i18n ( " Committee member deleted " ));
2007-11-17 21:59:59 +00:00
}
2010-01-04 17:51:55 +00:00
if ( $_GET [ 'unlinkmember' ] && $_GET [ 'unlinkcommittee' ]) {
2007-11-17 21:59:59 +00:00
$mem = intval ( $_GET [ 'unlinkmember' ]);
$com = intval ( $_GET [ 'unlinkcommittee' ]);
//unlink the member from the committee
2010-07-14 21:04:50 +00:00
mysql_query ( " DELETE FROM committees_link WHERE accounts_id=' $mem ' AND committees_id=' $com ' " );
2007-11-17 21:59:59 +00:00
echo happy ( i18n ( " Committee member unlinked from committee " ));
}
2010-12-06 19:33:38 +00:00
echo " <a href= \" committee_committees.php \" >Manage Committees</a><br /> " ;
2007-11-17 21:59:59 +00:00
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> " ;
2010-07-14 21:04:50 +00:00
$q = mysql_query ( " SELECT accounts_id,MAX(year),firstname,lastname,email,deleted FROM users WHERE types LIKE '%committee%' GROUP BY accounts_id ORDER BY firstname " );
echo " <select name= \" accounts_id \" > " ;
2007-11-17 21:59:59 +00:00
echo " <option value= \" \" > " . i18n ( " Select a Member " ) . " </option> \n " ;
while ( $r = mysql_fetch_object ( $q ))
{
2009-09-09 00:26:12 +00:00
if ( $r -> deleted != 'no' ) continue ;
2007-11-29 18:49:34 +00:00
$displayname = $r -> firstname . ' ' . $r -> lastname ;
2010-07-14 21:04:50 +00:00
echo " <option value= \" $r->accounts_id\ " > $displayname ( $r -> email ) </ option > \n " ;
2007-11-17 21:59:59 +00:00
}
echo " </select> " ;
2009-10-29 17:16:47 +00:00
2007-11-17 21:59:59 +00:00
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 " <form method= \" post \" action= \" committees.php \" > \n " ;
echo " <table> " ;
2010-09-03 16:59:05 +00:00
echo " <tr><td colspan= \" 2 \" ></td><th colspan= \" 2 \" > " . i18n ( 'Title within committee / Sort order' ) . " </th> " ;
echo " </tr> " ;
while ( $r = mysql_fetch_object ( $q )) {
2007-11-17 21:59:59 +00:00
echo " <tr> " ;
2010-09-03 16:59:05 +00:00
echo " <td colspan= \" 4 \" > " ;
2007-11-17 21:59:59 +00:00
echo " <input type= \" hidden \" name= \" committees_id[] \" value= \" $r->id\ " /> " ;
2010-09-03 16:59:05 +00:00
// echo "<input size=\"1\" type=\"text\" name=\"committees_ord[]\" value=\"$r->ord\" />";
echo " <b> $r->name </b> " ;
2007-11-17 21:59:59 +00:00
2009-09-09 00:26:12 +00:00
2010-01-04 17:51:55 +00:00
$q2 = mysql_query ( " SELECT
committees_link . title ,
committees_link . ord ,
2010-07-14 21:04:50 +00:00
users . accounts_id ,
2010-01-04 17:51:55 +00:00
MAX ( users . year ) AS my ,
users . lastname
FROM committees_link
2010-07-14 21:04:50 +00:00
JOIN users ON users . accounts_id = committees_link . accounts_id
2009-09-09 00:26:12 +00:00
WHERE committees_id = '{$r->id}'
2010-07-14 21:04:50 +00:00
GROUP BY users . accounts_id
2010-01-04 17:51:55 +00:00
ORDER BY ord ,
users . lastname " );
2009-09-09 00:26:12 +00:00
2007-11-17 21:59:59 +00:00
echo " </td></tr> \n " ;
echo mysql_error ();
2009-09-09 00:26:12 +00:00
while ( $r2 = mysql_fetch_object ( $q2 )) {
2010-07-14 21:04:50 +00:00
$u = user_load_by_accounts_id ( $r2 -> accounts_id );
2007-11-17 21:59:59 +00:00
echo " <tr><td align= \" right \" > " ;
2009-09-09 00:26:12 +00:00
echo " <a title= \" Edit Member \" href= \" # \" onclick= \" openeditor( { $u [ 'id' ] } ) \" ><img src= \" { $config [ 'SFIABDIRECTORY' ] } /images/16/edit. { $config [ 'icon_extension' ] } \" border= \" 0 \" alt= \" Edit \" /></a> " ;
2007-11-17 21:59:59 +00:00
echo " " ;
2010-07-14 21:04:50 +00:00
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= { $u [ 'accounts_id' ] } &unlinkcommittee= { $r -> id } \" ><img src= \" { $config [ 'SFIABDIRECTORY' ] } /images/16/undo. { $config [ 'icon_extension' ] } \" border= \" 0 \" alt= \" Unlink \" /></a> " ;
2007-11-17 21:59:59 +00:00
echo " </td> " ;
echo " <td valign= \" top \" > " ;
2009-09-09 00:26:12 +00:00
echo " <b> { $u [ 'name' ] } </b> " ;
2007-11-20 20:46:05 +00:00
echo " </td><td> " ;
2010-09-03 16:59:05 +00:00
echo " <input type= \" text \" value= \" { $r2 -> title } \" name= \" title[ { $r -> id } ][ { $u [ 'accounts_id' ] } ] \" size= \" 25 \" > " ;
2007-11-20 20:46:05 +00:00
echo " </td><td> " ;
2010-07-14 21:04:50 +00:00
echo " <input type= \" text \" value= \" { $r2 -> ord } \" name= \" order[ { $r -> id } ][ { $u [ 'accounts_id' ] } ] \" size= \" 2 \" > " ;
2007-11-17 21:59:59 +00:00
echo " </td></tr> \n " ;
}
2010-09-03 16:59:05 +00:00
echo " <tr><td colspan= \" 4 \" > </td></tr> \n " ;
2007-11-17 21:59:59 +00:00
}
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 ();
?>