2010-10-07 22:02:45 +00:00
< ? php
2010-07-13 03:30:11 +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 >
2010-10-14 20:31:10 +00:00
Copyright ( C ) 2005 - 2010 James Grant < james @ lightbox . org >
2010-07-13 03:30:11 +00:00
Copyright ( C ) 2007 David Grant < dave @ 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 .
*/
2010-10-06 17:05:54 +00:00
require_once ( " common.inc.php " );
require_once ( " user.inc.php " );
user_auth_required ();
2010-11-10 23:05:24 +00:00
/*
2010-10-07 22:02:45 +00:00
// find out if this user actually is in this conference
2010-11-01 15:24:59 +00:00
$query = " SELECT COUNT(*) FROM users WHERE conferences_id = { $conference [ 'id' ] } "
2010-10-07 22:02:45 +00:00
. " AND accounts_id = " . $_SESSION [ 'accounts_id' ];
$data = mysql_fetch_array ( mysql_query ( $query ));
if ( $data [ 0 ] == 0 ){
// They're not actually connected to this conference, let's hook 'em up
$u = user_create ( $_SESSION [ 'accounts_id' ], $_SESSION [ 'conferences_id' ]);
$_SESSION [ 'users_id' ] = $u [ 'id' ];
2010-10-06 17:05:54 +00:00
}
2010-11-10 23:05:24 +00:00
*/
2010-10-06 17:05:54 +00:00
$u = user_load ( $_SESSION [ 'users_id' ]);
2010-10-14 20:31:10 +00:00
if ( $u && array_key_exists ( 'action' , $_GET )){
2010-10-05 21:46:29 +00:00
switch ( $_GET [ 'action' ]){
2010-10-14 20:31:10 +00:00
case 'draw_roles' :
draw_roles ();
break ;
2010-10-05 21:46:29 +00:00
case 'register' :
2010-10-07 22:02:45 +00:00
$role = $_POST [ 'role' ];
$result = account_add_role ( $u [ 'accounts_id' ], $roles [ $role ][ 'id' ], $_SESSION [ 'conferences_id' ], $_POST [ 'password' ]);
2010-10-08 20:28:56 +00:00
if ( $result == 'ok' ){
2010-10-08 16:07:07 +00:00
}
2010-10-05 21:46:29 +00:00
break ;
2010-10-06 17:05:54 +00:00
case 'remove' :
$role = $_GET [ 'role' ];
2010-10-08 16:07:07 +00:00
$result = account_remove_role ( $u [ 'accounts_id' ], $roles [ $role ][ 'id' ], $_SESSION [ 'conferences_id' ]);
if ( $result == 'ok' ){
happy_ ( i18n ( " Role successfully removed. " ));
} else {
error_ ( i18n ( " Unable to remove role. " ));
}
2010-10-14 20:31:10 +00:00
break ;
2010-10-06 17:05:54 +00:00
case 'activate' :
$role = $_GET [ 'role' ];
if ( ! array_key_exists ( $role , $u [ 'roles' ])) {
/* Hand crafting URLs? */
echo " HALT: can't activate a role the user doesn't have " ;
exit ;
}
$u [ 'roles' ][ $role ][ 'active' ] = 'yes' ;
user_save ( $u );
2010-11-02 20:35:47 +00:00
happy_ ( " { $roles [ $role ][ 'name' ] } role for %1 successfully activated " , array ( $conference [ 'name' ]));
2010-10-06 17:05:54 +00:00
echo i18n ( " Active " );
2010-10-14 20:31:10 +00:00
break ;
2010-10-06 17:05:54 +00:00
case 'deactivate' :
$role = $_GET [ 'role' ];
if ( ! array_key_exists ( $role , $u [ 'roles' ])) {
/* Hand crafting URLs? */
echo " HALT: can't deactivate a role the user doesn't have " ;
}
$u [ 'roles' ][ $role ][ 'active' ] = 'no' ;
user_save ( $u );
2010-11-02 20:35:47 +00:00
happy_ ( " { $roles [ $role ][ 'name' ] } role for %1 successfully deactivated " , array ( $conference [ 'name' ]));
2010-10-06 17:05:54 +00:00
echo i18n ( " Deactivated " );
2010-10-14 20:31:10 +00:00
break ;
2010-10-06 17:05:54 +00:00
2010-10-05 21:46:29 +00:00
default :
break ;
}
2010-10-14 20:31:10 +00:00
updateSessionRoles ( $u );
2010-10-05 21:46:29 +00:00
exit ;
}
2010-07-13 03:30:11 +00:00
2010-10-05 21:46:29 +00:00
2010-10-06 17:05:54 +00:00
send_header ( " Main Page " , array ());
// throw in our javascript functions
2010-10-05 21:46:29 +00:00
?>
< script type = " text/javascript " >
function register ( role ){
$ . post ( 'user_main.php?action=register' ,
{
'role' : role ,
'password' : $ ( '#' + role + '_password' ) . val ()
},
function ( result ){
2010-10-06 17:05:54 +00:00
$ ( '#roles' ) . load ( 'user_main.php?action=draw_roles' );
2010-10-05 21:46:29 +00:00
}
);
}
2010-10-06 17:05:54 +00:00
function activate ( role ){
$ ( " #rolestatus_ " + role ) . load ( " <?= $config['SFIABDIRECTORY'] ?>/user_main.php?action=activate&users_id=<?= $u['id'] ?>&role= " + role , $ ( '#rolesform' ) . serializeArray ());
$ ( " #activate_ " + role ) . attr ( 'disabled' , 'disabled' );
$ ( " #deactivate_ " + role ) . removeAttr ( 'disabled' );
$ ( " #remove_ " + role ) . removeAttr ( 'disabled' );
$ ( " #rolestatus_ " + role ) . removeClass ( 'notice' );
$ ( " #rolestatus_ " + role ) . addClass ( 'happy' );
return false ;
}
function deactivate ( role ){
$ ( " #rolestatus_ " + role ) . load ( " <?= $config['SFIABDIRECTORY'] ?>/user_main.php?action=deactivate&users_id=<?= $u['id'] ?>&role= " + role , $ ( '#rolesform' ) . serializeArray ());
$ ( " #activate_ " + role ) . removeAttr ( 'disabled' );
$ ( " #deactivate_ " + role ) . attr ( 'disabled' , 'disabled' );
$ ( " #remove_ " + role ) . attr ( 'disabled' , 'disabled' );
$ ( " #rolestatus_ " + role ) . removeClass ( 'happy' );
$ ( " #rolestatus_ " + role ) . addClass ( 'notice' );
return false ;
}
function remove ( role ){
var con = confirmClick ( " <?=i18n( " Are you sure you want to remove this role from your account ? \\nThis action cannot be undone . " )?> " );
if ( con == true ) {
$ . get ( " <?= $config['SFIABDIRECTORY'] ?>/user_main.php?action=remove&users_id=<?= $u['id'] ?>&role= " + role , function (){
$ ( '#roles' ) . load ( 'user_main.php?action=draw_roles' );
});
}
}
2010-10-05 21:46:29 +00:00
</ script >
< ? php
2010-10-06 17:05:54 +00:00
// draw the main body of the page
2010-07-13 03:30:11 +00:00
2010-10-06 17:05:54 +00:00
//only display the named greeting if we have their name
2010-10-14 19:42:20 +00:00
echo i18n ( " Hello %1 " , array ( $_SESSION [ 'name' ]));
2011-03-02 05:25:00 +00:00
echo " <br /> " ;
echo " Please review your roles below and if correct, continue to your <a href= \" user_edit.php \" >Account Profile</a> " ;
2010-10-06 17:05:54 +00:00
echo " <br /> " ;
2010-10-14 19:42:20 +00:00
echo " <br /> " ;
draw_roles ();
2010-10-06 17:05:54 +00:00
send_footer ();
function draw_roles (){
// get a list of all roles that this user can potentially sign up for
global $u , $config ;
$rlist = array ();
$q = mysql_query ( " SELECT * FROM roles " );
$available = array ();
$registered = array ();
while ( $row = mysql_fetch_assoc ( $q )){
$roleid = $row [ 'type' ];
2011-03-03 05:36:36 +00:00
if ( $config [ $roleid . '_enable' ] != " no " ) {
$idx = $roleid . " _registration_type " ;
if ( array_key_exists ( $idx , $config )){
// this is a role that can potentially be registered for
if ( is_array ( $u [ 'roles' ]) && array_key_exists ( $row [ 'type' ], $u [ 'roles' ])){
$registered [ $row [ 'type' ]] = $row [ 'name' ];
} else {
$available [ $row [ 'type' ]] = $row [ 'name' ];
}
2010-10-06 17:05:54 +00:00
}
}
}
2010-10-05 21:46:29 +00:00
2010-10-06 17:05:54 +00:00
echo '<div id="roles">' ;
if ( count ( $registered ) > 0 ){
$rowNumber = 0 ;
2010-10-14 19:42:20 +00:00
echo " <h3> " . i18n ( " You are currently registered for the following roles " ) . " :</h3> " ;
2010-10-06 17:05:54 +00:00
echo '<form class="editor" id="rolesform">' ;
echo " <table class= \" summarytable \" style= \" width:95%;margin-bottom:1em \" > " ;
foreach ( $registered as $role => $title ){
echo '<tr class="' ;
if (( $rowNumber ++ ) % 2 ) echo 'odd' ;
else echo 'even' ;
echo '">' ;
echo " <td style= \" width:10em \" ><strong> " . i18n ( $title ) . " </strong></td> " ;
if ( $u [ 'roles' ][ $role ][ 'active' ] == 'yes' ) {
$cs = i18n ( 'Active' );
$cl = 'happy' ;
$a = 'disabled="disabled"' ;
$d = '' ;
} else {
$cs = i18n ( 'Deactivated' );
$cl = 'notice' ;
$a = '' ;
$d = 'disabled="disabled"' ;
}
?>
< td >< div class = " <?= $cl ?> " id = " rolestatus_<?= $role ?> " >< ? = $cs ?> </div></td>
< td >
< button style = " width: 100px; " id = " activate_<?= $role ?> " < ? = $a ?> onclick="activate('<?=$role?>');return false;" ><?=i18n("Activate")?></button>
< button style = " width: 100px; " id = " deactivate_<?= $role ?> " < ? = $d ?> onclick="deactivate('<?=$role?>');return false;" ><?=i18n("Deactivate")?></button>
< button style = " width: 100px; " id = " remove_<?= $role ?> " < ? = $d ?> onclick="remove('<?=$role?>');return false;" ><?=i18n("Remove")?></button>
2010-10-13 21:01:01 +00:00
2010-10-06 17:05:54 +00:00
</ td >
< ? php
echo " </tr> " ;
}
echo " </table></form> " ;
}
if ( count ( $available ) > 0 ){
2010-10-14 19:42:20 +00:00
echo " <h3> " . i18n ( " The following roles are available " ) . " :</h3> " ;
2010-10-06 17:05:54 +00:00
$rowNumber = 0 ;
echo " <table class= \" summarytable \" style= \" width:95% \" > " ;
foreach ( $available as $type => $title ){
echo '<tr class="' ;
if (( $rowNumber ++ ) % 2 ) echo 'odd' ;
else echo 'even' ;
echo '">' ;
echo " <td style= \" width:10em \" ><strong> $title </strong></td><td> " ;
draw_signup_form ( $type );
echo " </td></tr> " ;
}
echo " </table> " ;
}
echo " </div> " ;
}
2010-10-05 21:46:29 +00:00
function draw_signup_form ( $type ){
global $config ;
2010-10-07 22:02:45 +00:00
global $roles ;
2010-10-05 21:46:29 +00:00
switch ( $type ) {
case 'volunteer' :
$reg_open = user_volunteer_registration_status ();
$reg_mode = $config [ 'volunteer_registration_type' ];
// $reg_single_password = $config['volunteer_registration_singlepassword'];
// $password_expiry_days = $config['volunteer_password_expiry_days'];
// $welcome_email = "volunteer_welcome";
break ;
/* case 'committee' :
$reg_open = 'notpermitted' ;
$reg_mode = 'closed' ;
$reg_single_password = '' ;
$password_expiry_days = 0 ;
$welcome_email = false ;
break ;
*/
2010-10-14 17:51:56 +00:00
case 'teacher' :
$reg_open = user_teacher_registration_status ();
$reg_mode = $config [ 'teacher_registration_type' ];
break ;
2010-10-05 21:46:29 +00:00
case 'judge' :
$reg_open = user_judge_registration_status ();
$reg_mode = $config [ 'judge_registration_type' ];
// $reg_single_password = $config['judge_registration_singlepassword'];
// $password_expiry_days = $config['judges_password_expiry_days'];
// $welcome_email = "judge_welcome";
break ;
2010-11-26 16:50:17 +00:00
case 'participant' :
$reg_open = user_participant_registration_status ();
$reg_mode = $config [ 'participant_registration_type' ];
// $reg_open = 'closed';
// $reg_mode = $config['judge_registration_type'];
// $reg_single_password = $config['judge_registration_singlepassword'];
// $password_expiry_days = 0;
// $welcome_email = "register_students_welcome";
2010-10-05 21:46:29 +00:00
break ;
default :
2010-10-14 17:51:56 +00:00
echo " Role type ' $type ' is not handled " ;
2010-10-05 21:46:29 +00:00
return ;
}
if ( $reg_open == 'open' ){
switch ( $reg_mode ){
case 'open' :
2010-11-26 16:50:17 +00:00
case 'openorinvite' :
2010-10-14 17:51:56 +00:00
echo '<p>' . i18n ( " Registration is open. Please click the 'Register' button if you wish to register. " );
echo " <button onclick= \" register(' " . $type . " '); \" > " . i18n ( 'Register' ) . " </button> " ;
echo '</p>' ;
2010-10-05 21:46:29 +00:00
break ;
case 'singlepassword' :
echo '<p>' ;
2010-10-13 21:01:01 +00:00
echo i18n ( " { $roles [ $type ][ 'name' ] } Registration is protected by a password. You must know the <b> { $roles [ $type ][ 'name' ] } Registration Password</b> in order to register for this role. Please contact the committee to obtain the password if you wish to register. " );
2010-10-05 21:46:29 +00:00
echo " </p><p> " ;
2010-10-07 22:02:45 +00:00
echo i18n ( " { $roles [ $type ][ 'name' ] } Password " ) . " :<input type= \" password \" size= \" 20 \" id= \" { $type } _password \" /> " ;
2010-10-14 17:51:56 +00:00
echo " <button onclick= \" register(' " . $type . " '); \" > " . i18n ( 'Register' ) . " </button> " ;
2010-10-05 21:46:29 +00:00
echo " </p> " ;
break ;
case 'schoolpassword' :
echo " \" $reg_mode\ " registration is not yet handled " ;
break ;
case 'invite' :
2011-03-03 05:03:44 +00:00
echo i18n ( " Registration is by invite only " );
2010-10-05 21:46:29 +00:00
output_page_text ( " register_ { $type } _invite " );
break ;
default :
echo " Unhandled registration mode: $reg_mode " ;
}
} else {
2010-10-07 22:02:45 +00:00
echo i18n ( " { $roles [ $type ][ 'name' ] } registration is not open " );
2010-10-05 21:46:29 +00:00
}
}