<?
/* 
   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("../common.inc.php");
 require_once("../user.inc.php");
 user_auth_required('committee', 'admin');


$tabs = array('personal' => array(
			'name' => 'Personal',
			'types' => array('student','judge','committee','volunteer','sponsor'),
			'file' => '../user_personal.php',
			),
		'roles' => array(
			'name' => 'Roles/Account',
			'types' => array('student','judge','committee','volunteer','sponsor'),
			'file' => '../user_activate.php',
			),		
		'judgeother' => array(
			'name' => 'Judge Other',
			'types' => array('judge'),
			'file' => '../judge_other.php',
			),
		'judgeexpertise' => array(
			'name' => 'Expertise',
			'types' => array('judge'),
			'file' => '../judge_expertise.php',
			),
		'judgesa' => array(
			'name' => 'Special Awards',
			'types' => array('judge'),
			'file' => '../judge_special_awards.php',
			),
		'volunteerpos' => array(
			'name' => 'Volunteer Positions',
			'types' => array('volunteer'),
			'file' => '../volunteer_position.php',
			),

		);

$selected = $_GET['tab'];
if(!array_key_exists($selected, $tabs)) $selected = 'personal';

if(array_key_exists('username',$_GET)) {
	$username = $_GET['username'];
	$type = $_GET['type'];
	$un = mysql_escape_string($username);
	$q = mysql_query("SELECT id,MAX(year),deleted FROM users WHERE username='$un'");
	$r = mysql_fetch_object($q);
	if($r->deleted == 'no') {
		echo "Username already exists.";
		exit;
	}
	$u = user_create($type, $username);
	$u['email'] = $username;
	user_save($u);
	$id = $u['id'];
} else {
	$id = $_GET['id'];
}

$u = user_load($id);
send_popup_header(i18n("User Editor").": {$u['name']}");

?>
<link rel="stylesheet" type="text/css" href="<?=$config['SFIABDIRECTORY']?>/htabs.css" />
<?

echo '<ul id="htabs">';
foreach($tabs as $k=>$t) {
	$i = array_intersect($t['types'], $u['types']);
	if(count($i) == 0) continue;
	$sel = ($selected == $k) ? 'htabsel' : '';
	$href = "$PHP_SELF?id=$id&tab=$k";
	echo "<li class=\"$sel\"><a href=\"$href\">".i18n($t['name'])."</a></li>";
}
echo '</ul>';

$t = $tabs[$selected];

/* Setup some things */
$_SESSION['embed'] = true;
$_SESSION['embed_submit_url'] = "{$_SERVER['PHP_SELF']}?id=$id&tab=$selected";
$_SESSION['embed_edit_id'] = $id;

echo '<div id="htabmain">';
include("{$t['file']}");
echo '</div>';

unset($_SESSION['embed']);
unset($_SESSION['embed_edit_id']);
unset($_SESSION['embed_submit_url']);

$icon_path = $config['SFIABDIRECTORY']."/images/16/";
$icon_exitension = $config['icon_extension'];


	send_popup_footer();
?>
