File: /home/ednermusika/ednergranados.com/admin/usuario_altas.php
<?php require_once('../Connections/con_edner.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO usuario (usu_consecutivo, usu_correo, usu_nombre, usu_contrasena, usu_rol, usu_tipo, usu_activo) VALUES (%s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['usu_consecutivo'], "int"),
GetSQLValueString($_POST['usu_correo'], "text"),
GetSQLValueString($_POST['usu_nombre'], "text"),
GetSQLValueString($_POST['usu_contrasena'], "text"),
GetSQLValueString($_POST['usu_rol'], "text"),
GetSQLValueString($_POST['usu_tipo'], "text"),
GetSQLValueString($_POST['usu_activo'], "int"));
mysql_select_db($database_con_edner, $con_edner);
$Result1 = mysql_query($insertSQL, $con_edner) or die(mysql_error());
$insertGoTo = "inicio.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
mysql_select_db($database_con_edner, $con_edner);
$query_MAXIMO = "SELECT IFNULL(MAX(usu_consecutivo),0)+1 as MAXIMO FROM usuario";
$MAXIMO = mysql_query($query_MAXIMO, $con_edner) or die(mysql_error());
$row_MAXIMO = mysql_fetch_assoc($MAXIMO);
$totalRows_MAXIMO = mysql_num_rows($MAXIMO);
mysql_select_db($database_con_edner, $con_edner);
$query_usuarios = "SELECT usu_consecutivo, usu_correo, usu_nombre, usu_contrasena, usu_rol, usu_tipo, CASE usu_activo WHEN 1 THEN 'SI' WHEN 0 THEN 'NO' END as usu_activo FROM usuario";
$usuarios = mysql_query($query_usuarios, $con_edner) or die(mysql_error());
$row_usuarios = mysql_fetch_assoc($usuarios);
$totalRows_usuarios = mysql_num_rows($usuarios);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/admin.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript">
<!--
function MM_callJS(jsStr) { //v2.0
return eval(jsStr)
}
//-->
</script>
<title>Usuarios (Altas)</title>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><h1>Usuarios</h1></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td><a href="usuario_admin.php" class="ligas_menu_interiores">« Regresar »</a></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
</tr>
<tr>
<td><hr class="hr_principal" /></td>
</tr>
</table>
<blockquote>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
<table width="500">
<tr valign="baseline">
<td colspan="2" nowrap="nowrap"><h3>Nuevo Usuario</h3></td>
</tr>
<tr valign="baseline">
<td width="148" nowrap="nowrap"><h6> </h6></td>
<td width="340"><input type="hidden" name="usu_consecutivo" value="<?php echo $row_MAXIMO['MAXIMO']; ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap"><h4>Clave o correo:</h4></td>
<td><input name="usu_correo" type="text" value="" size="40" maxlength="100" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap"><h4>Nombre completo:</h4></td>
<td><input name="usu_nombre" type="text" value="" size="40" maxlength="100" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap"><h4>Contraseña:</h4></td>
<td><input name="usu_contrasena" type="text" value="" size="30" maxlength="20" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap"><h4>Rol:</h4></td>
<td><select name="usu_rol" id="usu_rol">
<option value="0">Seleccione una opción...</option>
<option value="ADMINISTRADOR">ADMINISTRADOR</option>
</select> </td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap"><h4> </h4></td>
<td><input type="hidden" name="usu_tipo" value="1" size="32" />
<input type="hidden" name="usu_activo" value="1" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap"><h6> </h6></td>
<td><input name="guardar" type="button" class="boton_panel" id="guardar" onclick="MM_callJS('f_enviar();')" value="Guardar" /> <input name="limpiar" type="reset" class="boton_panel" id="limpiar" value="Limpiar" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1" />
</form>
<p> </p>
</blockquote>
</body>
</html>
<script type="text/javascript">
function f_validar ( )
{
var retorno = true;
with ( document.form1 )
{
if ( usu_correo.value == '' )
{
alert ( 'Por favor proporcione el correo del usuario' );
usu_correo.focus ( );
retorno = false;
}
else if ( usu_nombre.value == '' )
{
alert ( 'Por favor proporcione el nombre del usuario' );
usu_nombre.focus ( );
retorno = false;
}
else if ( usu_contrasena.value == '' )
{
alert ( 'Por favor proporcione la contraseƱa del usuario' );
usu_contrasena.focus ( );
retorno = false;
}
else if ( usu_rol.value == '0' )
{
alert ( 'Por favor proporcione el rol del usuario' );
usu_rol.focus ( );
retorno = false;
}
return retorno
}
}
function f_enviar()
{
with (document.form1)
{
if ( f_validar ( ) )
{
submit ( );
}
}
}
</script>
<?php
mysql_free_result($MAXIMO);
mysql_free_result($usuarios);
?>