2009-09-09 00:26:12 +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 >
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-08-08 09:09:49 +00:00
require_once ( 'common.inc.php' );
require_once ( 'user.inc.php' );
require_once ( 'user_edit.inc.php' );
2009-09-09 00:26:12 +00:00
2010-08-08 09:09:49 +00:00
/* Ensure they're logged in as something, anything */
user_auth_required ();
2009-09-09 00:26:12 +00:00
2010-08-08 09:09:49 +00:00
$edit_id = isset ( $_GET [ 'users_id' ]) ? intval ( $_GET [ 'users_id' ]) : $_SESSION [ 'users_id' ];
if ( $edit_id != $_SESSION [ 'users_id' ])
2010-07-13 03:30:25 +00:00
user_auth_required ( 'admin' );
2010-08-08 09:09:49 +00:00
else
user_auth_required ();
$u = user_load ( $edit_id );
2009-09-25 23:23:10 +00:00
2010-08-08 09:09:49 +00:00
/* Validate the incoming role, make sure it is actually a role */
$role = '' ;
if ( $_GET [ 'action' ] != '' ) {
2010-07-13 03:30:25 +00:00
$role = $_GET [ 'role' ];
if ( ! array_key_exists ( $role , $roles )) {
echo " ERROR: not an allowed role. " ;
2009-09-09 00:26:12 +00:00
exit ;
}
2010-07-13 03:30:25 +00:00
/* We ' re not adding a role , but this checks to see if
* the user is allowed to be associated with this role , we don ' t
* want a student to deactivate a committee role , which would
* set the 'active' to 'no' , but would create the 'committee' entry
* in the roles array , making them part of that role suddenly . We
* also check for this case below to prevent it */
if ( ! user_add_role_allowed ( $u , $role )) {
/* If we get in here, someone is hand crafting URLs */
echo " HALT: invalid role to manipulate for this user. " ;
exit ;
}
2010-08-08 09:09:49 +00:00
}
2009-09-09 00:26:12 +00:00
2009-09-25 23:23:10 +00:00
switch ( $_GET [ 'action' ]) {
case 'delete' :
2009-09-09 00:26:12 +00:00
//okay here we go, lets get rid of them completely, since this is what theyve asked for
message_push ( happy ( i18n ( " Account successfully deleted. Goodbye " )));
user_delete ( $u );
2010-08-08 09:09:49 +00:00
header ( 'location: user_login.php?action=logout' );
2009-09-09 00:26:12 +00:00
exit ;
2009-09-25 23:23:10 +00:00
case 'remove' :
2009-09-09 00:26:12 +00:00
/* Like delete, only we're only deleting a role, not the whole account */
2010-07-13 03:30:25 +00:00
happy_ ( " { $roles [ $role ][ 'name' ] } role successfully removed. " );
2010-08-19 22:56:31 +00:00
echo i18n ( " Removed " );
2010-07-13 03:30:25 +00:00
user_delete ( $u , $role );
2009-09-25 23:23:10 +00:00
exit ;
2009-09-09 00:26:12 +00:00
case 'activate' :
2010-07-13 03:30:25 +00:00
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' ;
2009-09-09 00:26:12 +00:00
user_save ( $u );
2010-07-13 03:30:25 +00:00
happy_ ( " { $roles [ $role ][ 'name' ] } role for %1 successfully activated " , array ( $config [ 'FAIRYEAR' ]));
2010-08-19 22:56:31 +00:00
echo i18n ( " Active " );
2009-09-25 23:23:10 +00:00
exit ;
2009-09-09 00:26:12 +00:00
case 'deactivate' :
2010-07-13 03:30:25 +00:00
if ( ! array_key_exists ( $role , $u [ 'roles' ])) {
/* Hand crafting URLs? */
echo " HALT: can't deactivate a role the user doesn't have " ;
exit ;
}
$u [ 'roles' ][ $role ][ 'active' ] = 'no' ;
2009-09-09 00:26:12 +00:00
user_save ( $u );
2010-07-13 03:30:25 +00:00
happy_ ( " { $roles [ $role ][ 'name' ] } role for %1 successfully deactivated " , array ( $config [ 'FAIRYEAR' ]));
2010-08-19 22:56:31 +00:00
echo i18n ( " Deactivated " );
2009-09-25 23:23:10 +00:00
exit ;
2010-10-05 15:04:15 +00:00
case 'add' :
// add the role
// echo 'add role: ' . $role;
user_add_role ( $u , $role , $_GET [ 'password' ]);
exit ;
2009-09-09 00:26:12 +00:00
}
2010-08-08 09:09:49 +00:00
?>
2009-09-09 00:26:12 +00:00
2010-08-08 17:15:17 +00:00
< h4 >< ? = i18n ( " Roles " ) ?> </h4>
2010-08-08 09:09:49 +00:00
< ?
echo '<ul>' ;
echo '<li>' . i18n ( " An <b>Active Role</b> indicates you would like to participate in the %1 %2 as that role (Judge, Volunteer, etc.) " , array ( $config [ 'FAIRYEAR' ], $config [ 'fairname' ]));
echo '</li><li>' . i18n ( " A <b>Deactivated Role</b> indicates you cannot participate in the deactivated roles this year, but would like remain on the mailing lists for future years. You can activate your deactivated role at any time. " );
echo '</li><li>' . i18n ( " The <b>Remove Role</b> button completely deletes the role from your account. You will not receive future emails for the removed role. This action cannot be undone. " );
echo '</ul>' ;
2009-09-25 23:23:10 +00:00
?>
2010-08-08 09:09:49 +00:00
2009-09-25 23:23:10 +00:00
< script type = " text/javascript " >
2010-07-13 03:30:25 +00:00
function activate ( role )
2009-09-25 23:23:10 +00:00
{
2010-08-19 22:56:31 +00:00
$ ( " #rolestatus_ " + role ) . load ( " <?= $config['SFIABDIRECTORY'] ?>/user_roles.php?action=activate&users_id=<?= $u['id'] ?>&role= " + role , $ ( '#rolesform' ) . serializeArray ());
2010-07-13 03:30:25 +00:00
$ ( " #activate_ " + role ) . attr ( 'disabled' , 'disabled' );
$ ( " #deactivate_ " + role ) . removeAttr ( 'disabled' );
$ ( " #remove_ " + role ) . removeAttr ( 'disabled' );
2010-08-19 22:56:31 +00:00
$ ( " #rolestatus_ " + role ) . removeClass ( 'notice' );
$ ( " #rolestatus_ " + role ) . addClass ( 'happy' );
return false ;
2009-09-25 23:23:10 +00:00
}
2010-07-13 03:30:25 +00:00
function deactivate ( role )
2009-09-25 23:23:10 +00:00
{
2010-08-19 22:56:31 +00:00
$ ( " #rolestatus_ " + role ) . load ( " <?= $config['SFIABDIRECTORY'] ?>/user_roles.php?action=deactivate&users_id=<?= $u['id'] ?>&role= " + role , $ ( '#rolesform' ) . serializeArray ());
2010-07-13 03:30:25 +00:00
$ ( " #activate_ " + role ) . removeAttr ( 'disabled' );
$ ( " #deactivate_ " + role ) . attr ( 'disabled' , 'disabled' );
$ ( " #remove_ " + role ) . attr ( 'disabled' , 'disabled' );
2010-08-19 22:56:31 +00:00
$ ( " #rolestatus_ " + role ) . removeClass ( 'happy' );
$ ( " #rolestatus_ " + role ) . addClass ( 'notice' );
return false ;
2009-09-25 23:23:10 +00:00
}
2010-07-13 03:30:25 +00:00
function remove ( role )
2009-09-25 23:23:10 +00:00
{
var con = confirmClick ( " <?=i18n( " Are you sure you want to remove this role from your account ? \\nThis action cannot be undone . " )?> " );
if ( con == true ) {
2010-08-19 22:56:31 +00:00
$ ( " #rolestatus_ " + role ) . load ( " <?= $config['SFIABDIRECTORY'] ?>/user_roles.php?action=remove&users_id=<?= $u['id'] ?>&role= " + role , $ ( '#rolesform' ) . serializeArray ());
2010-07-13 03:30:25 +00:00
$ ( " #activate_ " + role ) . attr ( 'disabled' , 'disabled' );
$ ( " #deactivate_ " + role ) . attr ( 'disabled' , 'disabled' );
$ ( " #remove_ " + role ) . attr ( 'disabled' , 'disabled' );
2010-08-19 22:56:31 +00:00
$ ( " #rolestatus_ " + role ) . removeClass ( 'happy' );
$ ( " #rolestatus_ " + role ) . addClass ( 'notice' );
2009-09-25 23:23:10 +00:00
}
}
2010-08-08 09:09:49 +00:00
2010-10-05 15:04:15 +00:00
// add the specified role to this user at this fair
function addRole ( role ){
$ . get ( 'user_roles.php' , { 'action' : 'add' , 'role' : role , 'password' : $ ( '#password' ) . val ()}, function ( result ){
$ ( '#testoutput' ) . html ( result );
});
}
2009-09-25 23:23:10 +00:00
</ script >
2010-08-08 09:09:49 +00:00
2010-08-19 22:56:31 +00:00
< form class = " editor " id = " rolesform " >
< table width = " 90% " >
2009-09-25 23:23:10 +00:00
< ?
2010-07-13 03:30:25 +00:00
foreach ( array_keys ( $u [ 'roles' ]) as $r ) {
2010-08-19 22:56:31 +00:00
2010-07-13 03:30:25 +00:00
if ( $u [ 'roles' ][ $r ][ 'active' ] == 'yes' ) {
2010-08-19 22:56:31 +00:00
$cs = i18n ( 'Active' );
$cl = 'happy' ;
2009-09-09 00:26:12 +00:00
$a = 'disabled="disabled"' ;
$d = '' ;
} else {
2010-08-19 22:56:31 +00:00
$cs = i18n ( 'Deactivated' );
$cl = 'notice' ;
2009-09-09 00:26:12 +00:00
$a = '' ;
$d = 'disabled="disabled"' ;
}
2009-09-25 23:23:10 +00:00
?>
2010-08-19 22:56:31 +00:00
< tr >
< td >< b >< ? = i18n ( $roles [ $r ][ 'name' ]) ?> </b></td>
< td >< div class = " <?= $cl ?> " id = " rolestatus_<?= $r ?> " >< ? = $cs ?> </div></td>
< td >
< button style = " width: 100px; " id = " activate_<?= $r ?> " < ? = $a ?> onclick="activate('<?=$r?>');return false;" ><?=i18n("Activate")?></button>
< button style = " width: 100px; " id = " deactivate_<?= $r ?> " < ? = $d ?> onclick="deactivate('<?=$r?>');return false;" ><?=i18n("Deactivate")?></button>
< button style = " width: 100px; " id = " remove_<?= $r ?> " < ? = $d ?> onclick="remove('<?=$r?>');return false;" ><?=i18n("Remove")?></button>
</ td ></ tr >
2009-09-25 23:23:10 +00:00
< ?
2010-08-08 09:09:49 +00:00
}
?>
2010-08-19 22:56:31 +00:00
</ table >
2010-08-08 09:09:49 +00:00
</ form >
2009-09-09 00:26:12 +00:00
2010-10-05 15:04:15 +00:00
< ? php
/*
// testing link
if ( ! in_array ( 'judge' , $u [ 'roles' ])){
echo " <div><span style= \" font-weight:bold \" onmouseover= \" this.style.cursor='pointer'; \" onmouseout= \" this.style.cursor='auto'; \" onclick= \" addRole('judge'); \" >Make me a judge</span></div> " ;
echo " <div>Password<input type= \" text \" id= \" password \" ></input></div> " ;
}
*/
?>
2010-08-19 22:56:31 +00:00
< br />< hr />< br />
< ? = i18n ( " The <b>Delete Entire Account</b> button completely deletes your entire account. You will not receive any future email for any roles. It completely removes you from the system. This action cannot be undone. " ) ?>
< br />
2010-08-08 09:09:49 +00:00
< form method = " post " action = " <?= $config['SFIABDIRECTORY'] ?>/user_roles.php?action=delete&users_id=<?= $u['id'] ?> " >
< input style = " width: 300px; " onclick = " return confirmClick('<?=i18n( " Are you sure you want to completely delete your account ? \\nDoing so will remove you from our mailing list for future years and you will never hear from us again . \\nThis action cannot be undone . " )?>'); "
type = " submit " value = " <?=i18n( " Delete Entire Account " )?> " >
</ form >
2010-10-05 15:04:15 +00:00
< div id = " testoutput " ></ div >