science-ation/user_edit.php
2010-08-19 22:56:35 +00:00

316 lines
8.3 KiB
PHP

<?
/*
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');
require_once('user.inc.php');
require_once('user_edit.inc.php');
require_once('judge.inc.php');
$edit_id = isset($_GET['users_id']) ? intval($_GET['users_id']) : $_SESSION['users_id'];
if($edit_id != $_SESSION['users_id'])
user_auth_required('admin');
else
user_auth_required();
$tabs = array( 'fairinfo' => array(
'label' => 'Fair Information',
'types' => array('fair'),
'file' => 'fair_info.php',
),
'fairstatsgathering' => array(
'label' => 'Fair Stats Gathering',
'types' => array('fair'),
'file' => 'fair_stats_select.php',
),
'personal' => array(
'label' => 'Personal',
'name' => 'Personal Information',
'types' => array('student','judge','committee','volunteer','sponsor','fair'),
'file' => 'user_personal.php',
'status_func' => 'user_personal_info_status',
),
'organization' => array(
'label' => 'Organization',
'name' => 'Organization Information',
'types' => array('judge','volunteer','sponsor'),
'file' => 'user_organization.php',
'status_func' => 'user_organization_status',
),
'judge' => array(
'label' => 'Judge',
'types' => array('judge'),
'file' => 'judge_other.php',
'status_func' => 'judge_status_other',
),
'judgeexpertise' => array(
'label' => 'Expertise',
'types' => array('judge'),
'file' => 'judge_expertise.php',
'disabled' => true,
),
'judgeavailability' => array(
'label' => 'Time Avail.',
'types' => array('judge'),
'file' => 'judge_availability.php',
'disabled' => true,
),
'judgesa' => array(
'label' => 'Special Awards',
'types' => array('judge'),
'file' => 'judge_special_awards.php',
'disabled' => true,
),
'volunteerpos' => array(
'label' => 'Volunteer Positions',
'types' => array('volunteer'),
'file' => 'volunteer_position.php',
'disabled' => true,
),
'fairstats' => array(
'label' => 'Fair Statistics and Information',
'types' => array('fair'),
'file' => 'fair_stats.php',
'disabled' => true,
),
'account' => array(
'label' => 'Account/Login',
'name' => 'Change Username/Email/Password',
'types' => array('student','judge','committee','volunteer','sponsor','fair'),
'file' => 'user_account.php',
'status_func' => false,
),
'roles' => array(
'label' => 'Roles',
'name' => 'Add/Remove Roles',
'types' => array('student','judge','committee','volunteer','sponsor','fair'),
'file' => 'user_roles.php',
'status_func' => false,
),
);
$u = user_load($edit_id);
$types = array_keys($u['roles']);
$selected = $_GET['tab'];
if(!array_key_exists($selected, $tabs)) {
if(in_array('fair', $types) )
$selected = 'fairinfo';
else
$selected = 'personal';
}
$fields = array();
$required = array();
foreach(array_keys($u['roles']) as $r) {
$fields = array_merge($fields, user_fields_enabled($r));
$required = array_merge($required, user_fields_required($r));
}
/* Disable some of the tabs */
if($config['judges_availability_enable'] != 'yes') $tabs['judgeavailability']['disabled'] = true;
$a = array_intersect(array('organization','phonework','fax'), $fields);
if(count($a) == 0) {
/* No organization stuff is enabled */
$tabs['organization']['disabled'] = true;
}
send_header(i18n("User Editor").": {$u['name']}");
/* Setup tabs */
echo '<div id="tabs">';
echo '<ul>';
/* Always show a registration summary */
echo '<li><a href="#user_summary">'.i18n('Registration Summary').'</a></li>';
$index = 1;
$selected_index = 0;
/* Show all other enabled tabs */
foreach($tabs as $k=>$t) {
/* Make sure the tab is enabled */
if($t['disabled'] == true) continue;
/* Make sure the user has the right type to see the tab */
$i = array_intersect($t['types'], $types);
if(count($i) == 0) {
/* Turn off the tab, so in future iterations of the tabs
* list we only ahve to check enabled */
$tabs[$k]['disabled'] = true;
continue;
}
$tabs[$k]['index'] = $index;
$tabs_key[$index] = $k;
if($k == $selected) $selected_index = $index;
$index++;
/* Show the tab */
$href = "{$t['file']}?id=$id";
echo "<li><a href=\"$href\"><span>".i18n($t['label'])."</span></a></li>";
}
?>
</ul>
<div id="user_summary">
<h4><?=i18n("Registration Summary")?></h4>
<br/>
<table border="0" cellpadding="2">
<?
foreach($tabs as $k=>$t) {
/* Enabled has been modified now for this user */
if($t['disabled'] == true) continue;
if($t['status_func'] == false) {
/* No status func, skip in the "todo list" */
continue;
}
/* Get the status */
if(is_callable($t['status_func'])) {
$s = call_user_func($t['status_func'], $u);
$tabs[$k]['status'] = ($s == 'complete') ? 'complete' : 'incomplete';
} else {
$tabs[$k]['status'] = 'incomplete';
}
/* Link to switch to the tab */
$n = ($t['name'] != '') ? $t['name'] : $t['label'];
?>
<tr>
<td><a href="#" onclick="return linkto_click(<?=$t['index']?>);"><?=i18n($n)?></a></td>
<td><span class="status_<?=$k?>"></span></td>
</tr>
<?
}
?>
<tr><td colspan="2"><hr /></td></tr>
<tr> <td><?=i18n('Overall Status')?></td>
<td><span class="status_overall"></span></td>
</tr>
</table>
<br />
<br />
<b>Other Options and Things To Do:</b><br />
<ul>
<?
foreach($tabs as $k=>$t) {
/* Enabled has been modified now for this user */
if($t['disabled'] == true) continue;
if($t['status_func'] != false) {
/* Now we want all the other links not part of the status */
continue;
}
/* Link to switch to the tab */
$n = ($t['name'] != '') ? $t['name'] : $t['label'];
?>
<li><a href="#" onclick="return linkto_click(<?=$t['index']?>);"><?=i18n($n)?></a></li>
<?
}
?>
</ul>
</div>
</div>
<script type="text/javascript">
var stat = new Array();
<?
/* An array of all tabs and current status for each one */
foreach($tabs as $k=>$t) {
/* Enabled has been modified now for this user */
if($t['disabled'] == true) continue;
if($t['index'] != 1) echo ", ";
echo "stat['$k'] = '{$t['status']}'\n";
}
?>
$(document).ready(function() {
$("#tabs").tabs({
// selected: <?=$selected_index?>
});
/* Update each tab for complete/incomplete */
for(var key in stat) {
user_update_tab_status(key);
}
});
function linkto_click(index)
{
$("#tabs").tabs('select', index);
return false;
}
function user_update_tab_status(tabkey,newstatus)
{
// var curr_tab = $("#tabs").tabs('option', 'selected');
if(!newstatus) {
/* Keep the status the same if not specified */
newstatus = stat[tabkey];
}
if(newstatus!='complete') {
$(".status_"+tabkey).html('<?=i18n("Incomplete")?>');
$(".status_"+tabkey).removeClass('happy');
$(".status_"+tabkey).addClass('error');
} else {
$(".status_"+tabkey).html('<?=i18n("Complete")?>');
$(".status_"+tabkey).removeClass('error');
$(".status_"+tabkey).addClass('happy');
}
stat[tabkey] = newstatus;
/* See if the user is overall complete, server-side this is done, but the
* server never sends back the overall result to the client, and doesn't need to
* because we can easily figure it out (assuming the complete/incomplete status
* of each tab doesn't get out of sync) */
var overall = 'complete';
for(var key in stat) {
if(stat[key] != 'complete') {
overall = 'incomplete';
}
}
if(overall!='complete') {
$(".status_overall").html('<?=i18n("Incomplete")?>');
$(".status_overall").removeClass('happy');
$(".status_overall").addClass('error');
} else {
$(".status_overall").html('<?=i18n("Complete")?>');
$(".status_overall").removeClass('error');
$(".status_overall").addClass('happy');
}
}
</script>
<?
send_footer();
?>