<?php
define( '_UEXEC', 1 ); 
/************************************************************************
	UebiMiau is a GPL'ed software developed by 
	
	 - Aldoir Ventura - aldoir@users.sourceforge.net
	 - http://uebimiau.sourceforge.net
	
	Fell free to contact, send donations or anything to me :-)
	São Paulo - Brasil
	
	**********************************************
	Version 3.2.0 Upgrades and templates developed by
	 
	 - Todd Henderson - Lead Developer
	 - http://tdah.us
	 - Email: todd@tdah.us
	 
	 - Dave Rodgers - Project Consultant
	 - http://www.manvel.net 
	 - Email: Davenmanvel@inbox.com
	
	Feel free to contact us, send donations or anything to me as well...
	
	Special thanks to the developers at telaen.org, codeworxtech.com, tinymce.moxiecode.com
	without help this project wouldn't be possible 

	**********************************************
	- File:			admin/register.php
	- Developer: 	Todd Henderson / Mods by Laurent (AdNovea)
	- Date:			
	- version:		
	- Description:  Admin users management

*************************************************************************/

	require_once('common.php');

// Add new administrator
	if (isset($_POST['submitBtn']) && ($_POST['submitBtn'] == $admin_bt_register)){
		// Get user input
		$username  = isset($_POST['newuser']) ? $_POST['newuser'] : '';
		$password1 = isset($_POST['password1']) ? $_POST['password1'] : '';
		$password2 = isset($_POST['password2']) ? $_POST['password2'] : '';
        
		// Try to register the user
		$error = registerUser($username,$email,$password1,$password2);
	}
	

// Remove administrator
	if (isset($_POST['submitBtn']) && ($_POST['submitBtn'] == $admin_bt_delete)) {
		$error = removeUser($_POST['username']);
	}
// Log user if needed
	checkUser();

	echo DOC_TYPE."
	<html>
	<head>
		<meta http-equiv=\"Content-Type\" content=\"text/html; charset=$default_char_set\">
		<title>$admin_title</title>
		<link href=\"../themes/$selected_theme/css/admin.css\" rel=\"stylesheet\" type=\"text/css\">
		<script type=\"text/javascript\" src=\"../themes/$selected_theme/js/webmail.js\"></script>	   
	</head>
	
	<body>
		<center>
		<div id=\"main\">
	";
	
	if ((!isset($_POST['submitBtn'])) || ($error != '')) {
		
		echo "
		<div class=\"caption\">$admin_register</div>
		<div id=\"icon\">&nbsp;</div>
			<div id=\"result\" style=\"width: 286px; height: 170px\">
			<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\" name=\"registerform\">
				<input type=\"hidden\" name=\"lid\" value=\"$lid\">
				<input type=\"hidden\" name=\"tid\" value=\"$tid\">
				<table width=\"100%\" class=\"login_table\">
				<tr><td colspan=\"2\" align=\"center\"><small><font color=\"#FF0000\">$admin_reg_user</font></small></td></tr>
				<tr><td width=\"50%\">$admin_username:</td><td> 
				<select  name=\"username\" class=\"username\" onchange=\"javascript:if (this.value == '$admin_add_new') admin_config(0); else admin_config(1);\">
					<option value=\"$admin_add_new\">$admin_add_new</option>";
		echo listUsers();
		echo"
				</select>
				<tr><td>$admin_add_new_name</td><td> <input class=\"text\" id=\"ad_newuser\" name=\"newuser\" type=\"text\" ></td></tr>
				<tr><td>$admin_password</td><td> <input class=\"text\"id=\"ad_password1\" name=\"password1\" type=\"password\"></td></tr>
				<tr><td>$admin_confirm_pwd</td><td> <input id=\"ad_password2\" class=\"text\" name=\"password2\" type=\"password\"></td></tr>
				<tr><td align=\"right\">
					<input class=\"button\" type=\"submit\" id=\"ad_add\" name=\"submitBtn\" value=\"$admin_bt_register\">
					<input class=\"button\" type=\"submit\" id=\"ad_del\" name=\"submitBtn\" value=\"$admin_bt_delete\" style=\"display: none;\"></td>
					<td><input class=\"button\" type=\"button\" value=\"$bt_back\" onclick=\"javascript:location='index.php?lid=$lid&tid=$tid';\">
				</td></tr>
				</table>  
			</form>
		</div>
		";
	}   

    if (isset($_POST['submitBtn'])) {

		echo "
		  <div class=\"caption\">$admin_register_result</div>
		  <div id=\"icon2\">&nbsp;</div>
			<div id=\"result\" style=\"width: 286px; height: 90px\">
			<table width=\"100%\" class=\"login_table\">
			<tr><td align=\"center\"><br>
		";
		
		if ($error == '') {
			echo "$username : $admin_opt_ok<br>
			<br><br>
			<input class=\"button\" type=\"button\" value=\"$admin_bt_continue\" onclick=\"javascript:location='index.php?lid=$lid&tid=$tid';\" tabindex=\"1\">";
		}
		else 
			echo $error;
	
		echo "
			</td></tr>
			</table>
		</div>
		";
    }

	echo "
		</div>
		</center>
	</body>";

?>
