<?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();

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

//check for administrative rights
if (allow_access(Administrators) != "yes")
{
	include ('../check_login.php');
	exit;
}

//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>Modificar 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">
	<h1>Modificación del usuario '<?php echo $_GET[username]; ?>'</h1>
    <br/>

<?php 
if ($_GET[username] != "")
{
	//build and issue the query
	$sql ="SELECT * FROM $table_name WHERE username = '$_GET[username]'";
	$result = @mysql_query($sql,$connection) or die(mysql_error());

	while ($sql = mysql_fetch_object($result)) 
	{
		$m_first = $sql -> firstname;
		$m_last = $sql -> lastname;	
		$g_1	 = $sql -> group1;
		$g_2	 = $sql -> group2;
		$g_3	 = $sql -> group3;			
		$chng	 = $sql -> pchange;
		$m_email = $sql -> email;
		$direct = $sql -> redirect;	
	}
?>
    <form method="POST" action="<?php echo 'modifyuser.php?username='.$_GET[username];?>">
      <table width="100%">
        <tr>
          <td width="200px">Nombre:</td>
          <td><input type="text" name="mod_first" size="20" value="<?php echo $m_first; ?>"></td>
        </tr>
        <tr>
          <td width="200px">Apellidos:</td>
          <td><input type="text" name="mod_last" size="20" value="<?php echo $m_last; ?>"></td>
        </tr>
        <tr>
          <td width="200px">Contraseña:</td>
          <td><input type="text" name="mod_pass" size="20" value="*******"></td>
        </tr>
        <tr>
          <td width="200px">E-Mail:</td>
          <td><input type="text" name="mod_email" size="50" value="<?php echo $m_email; ?>"></td>
        </tr>
        <?php 
			if ($_GET[username] != $_SESSION[user_name]) {        
		?>
        <tr>
          <td width="200px">Grupo:</td>
          <td><select size="1" name="mod_group1">
              <?php
				echo "<option>$g_1</option>";
				$i = 0;
				while ($i < $num_groups)
				{
					echo "<option value=\"$group_array[$i]\">$group_array[$i]</option>";
					$i++;
				}
 			  ?>
            </select></td>
        </tr>
        <tr>
          <td width="200px">&nbsp;</td>
          <td><select size="1" name="mod_group2">
              <?php
				echo "<option>$g_2</option>";
				$i = 0;
				while ($i < $num_groups)
				{
					echo "<option value=\"$group_array[$i]\">$group_array[$i]</option>";
					$i++;
				}
			  ?>
            </select></td>
        </tr>
        <tr>
          <td width="200px">&nbsp;</td>
          <td><select size="1" name="mod_group3">
              <?php
				echo "<option>$g_3</option>";
				$i = 0;
				while ($i < $num_groups)
				{
					echo "<option value=\"$group_array[$i]\">$group_array[$i]</option>";
					$i++;
				}
			  ?>
            </select></td>
        </tr>
        <tr>
          <td width="200px">Redirigir a:</td>
          <td><input type="text" name="mod_redirect" size="50" value="<?php echo $direct; ?>"></td>
        </tr>        
        <!--<tr>
          <td width="200px">Obligar a cambiar la contraseña en el siguiente inicio de sesión:</td>
          <td><select size="1" name="mod_chng">
              <option value="0" selected>No</option>
              <option value="1">Si</option>
            </select></td>
        </tr>-->
        <?php } ?>
        <tr>
          <td width="200px"><input type="submit" value="Guardar"></td>
          <td>&nbsp;</td>
        </tr>
      </table>
      </td>
      </tr>
      <tr>
    </form>
<?php 
	}
	else {
		echo "<p>No se ha encontrado el usuario $_GET[username]</p>";
	}
?>
  </div>
  <div id="footer"> </div>
</div>
</body>
</html>