<?php
//prevents caching
header("Expires: Sat, 01 Jan 2000 00:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: post-check=0, pre-check=0",false);
session_cache_limiter();
session_start();

include ('../config.php');
include ('../functions.php');

//make connection to dbase
$connection = @mysql_connect($server, $dbusername, $dbpassword) or die(mysql_error());
$db = @mysql_select_db($db_name,$connection) or die(mysql_error());
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Language" content="es-ES" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Eliminar usuario - La Factoría Verde</title>
    <link rel="stylesheet" type="text/css" href="estilos.css">
</head>
<body>
<div id="layout">
  <div id="header"> <img src="../img/lafactoriaverde.gif" alt="La Factoría Verde" />
    <div style="float: right;">Sesión iniciada como <?php echo $_SESSION[user_name]; ?></div>
	<?php 
        $menu_activo='';
        include('_menu.php'); 
    ?>	
  </div>
  <div id="content">
<?php
//check for authority to view this page
if (allow_access(Administrators) != "yes")
{
	echo "<br/><br/><br/><center><p class='error'>No tienes autorización para esta función.</p></center>";
}

if (isset($_GET['del_user'])) {
	$s_string = $_GET['del_user'];
	$explodeit = explode(" ", "$s_string");
	$c = count($explodeit);
	if ($c > 1) {
		for ($i = 0; $i < $c; $i++) {
			$del_user = $explodeit[$i] . "+";
		}
	}
	else {
		$del_user = $s_string;
	}
}

if (($del_user != $_SESSION[user_name]) && ($del_user != ""))
{
	$sql = "SELECT * FROM $table_name WHERE username = '$del_user'";
	$result = @mysql_query($sql, $connection) or die(mysql_error());
	//get the number of rows in the result set
	$num = mysql_num_rows($result);
	//set session variables if there is a match
	if ($num != 0)
	{
		while ($sql = mysql_fetch_object($result)) 
		{	
			$first		= $sql -> firstname;
			$last		= $sql -> lastname;
			$uname		= $sql -> username;
			$pass		= $sql -> password;
			$gr1		= $sql -> group1;
			$gr2		= $sql -> group2;
			$gr3		= $sql -> group3;
			$change		= $sql -> pchange;
			$e_mail		= $sql -> email;
			$re_direct	= $sql -> redirect;
			$ver_d		= $sql -> verified;
			$last_log	= $sql -> last_login;
			$del_dat	= last_login();
		}

		
		$trash_user = "INSERT INTO trash (firstname, lastname, username, password, group1, group2, group3, pchange, email, redirect, verified, last_login, del_date) VALUES		('$first', '$last', '$uname', '$pass', '$gr1', '$gr2', '$gr3', '$change', '$e_mail', '$re_direct', '$ver_d', '$last_log', '$del_dat')";

		$del = "DELETE FROM $table_name WHERE username = '$del_user'";
		$result = @mysql_query($del,$connection) or die(mysql_error());
		$result1 = @mysql_query($trash_user,$connection) or die(mysql_error());
		$msg .= "El usuario '$del_user' ha sido eliminado.<br/>";
	} else {
		$msg .= "No se encuentra el usuario '$del_user'.<br/>";
	}

	$del_banned = "DELETE FROM banned WHERE no_access = '$del_user'";
	$result = @mysql_query($del_banned,$connection) or die(mysql_error());
	
	echo $msg;
}
?>
	<br/>
    <center>
      <a href="<?php echo "adminpage.php"; ?>">Volver a la lista</a>
    </center>
  </div>
  <div id="footer"> </div>
</div>
</body>
</html>