/usuarios_insertar.php
PHP | 188 lines | 178 code | 9 blank | 1 comment | 11 complexity | 3bdba4c9f4f376a5e9b9e2c92a41b0d6 MD5 | raw file
Possible License(s): LGPL-2.1
- <?php
- include_once("software.php");
- include_once("clases/acceso_a_opcion.php");
- $tabla='';
- $_utiles = new utiles();
- $titulo_seccion= "Insertar Usuario";
- $id_op = 1;
- $_acceso_a_opcion = new acceso_a_opcion();
- $_acceso_a_opcion->acceso_opcion($id_op);
- if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
- //validar si existe usuario nuevo
- $colname_ValidarUsuario = "-1";
- if (isset($_GET['Usuario'])) {
- $colname_ValidarUsuario = (get_magic_quotes_gpc()) ? $_GET['Usuario'] : addslashes($_GET['Usuario']);
- }
- mysql_select_db(DB_NAME, CONEXION);
- $query_ValidarUsuario = sprintf("SELECT Usuario FROM `Usuario` WHERE Usuario = '%s'", $colname_ValidarUsuario);
- $ValidarUsuario = mysql_query($query_ValidarUsuario, CONEXION) or trigger_error(mysql_error(),E_USER_ERROR);
- $row_ValidarUsuario = mysql_fetch_assoc($ValidarUsuario);
- $totalRows_ValidarUsuario = mysql_num_rows($ValidarUsuario);
- mysql_free_result($ValidarUsuario);
- if ($totalRows_ValidarUsuario > 0) {
- ?>
- <script language="javascript">
- alert("Ya existe un usuario con ese nombre!");
- </script>
- <?php
- }
- else {
- $insertSQL = sprintf("INSERT INTO Usuario (Usuario, Password, nombre1, nombre2, apellido1, apellido2, email, idSexo, idNivel) VALUES (%s, '%s', %s, %s, %s, %s, %s, %s, %s)",
- $_utiles->GetSQLValueString($_POST['Usuario'], "text_upper"),
- md5($_utiles->GetSQLValueString($_POST['Password'], "text_upper")),
- $_utiles->GetSQLValueString($_POST['nombre1'], "text_upper"),
- $_utiles->GetSQLValueString($_POST['nombre2'], "text_upper"),
- $_utiles->GetSQLValueString($_POST['apellido1'], "text_upper"),
- $_utiles->GetSQLValueString($_POST['apellido2'], "text_upper"),
- $_utiles->GetSQLValueString($_POST['email'], "text"),
- $_utiles->GetSQLValueString($_POST['idSexo'], "text"),
- $_utiles->GetSQLValueString($_POST['nivel'], "int"));
- $_utiles->bitacora('Usuario',$_POST['Usuario'],'insertar');
- mysql_select_db(DB_NAME, CONEXION);
- $Result1 = mysql_query($insertSQL, CONEXION) or trigger_error(mysql_error(),E_USER_ERROR);
- $insertGoTo = "usuarios.php";
- if (isset($_SERVER['QUERY_STRING'])) {
- $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
- $insertGoTo .= $_SERVER['QUERY_STRING'];
- }
- header(sprintf("Location: %s", $insertGoTo));
- }
- }
- mysql_select_db(DB_NAME, CONEXION);
- $query_Rsdepartamento = "SELECT * FROM Nivel";
- $Rsdepartamento = mysql_query($query_Rsdepartamento, CONEXION) or trigger_error(mysql_error(),E_USER_ERROR);
- $row_Rsdepartamento = mysql_fetch_assoc($Rsdepartamento);
- $totalRows_Rsdepartamento = mysql_num_rows($Rsdepartamento);
- mysql_select_db(DB_NAME, CONEXION);
- $query_RsSexo = "SELECT * FROM Sexo";
- $RsSexo = mysql_query($query_RsSexo, CONEXION) or trigger_error(mysql_error(),E_USER_ERROR);
- $row_RsSexo = mysql_fetch_assoc($RsSexo);
- $totalRows_RsSexo = mysql_num_rows($RsSexo);
- ?>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <?php include_once ("inc_head_adm.php");
- ?>
- <title><?php echo $titulo_seccion;
- ?></title>
- </head>
- <body onLoad="load_functions();" marginwidth="5px" marginheight="4px" leftmargin="0" topmargin="4px" bgcolor="#f0f0f0">
- <?php include_once ("inc_top_adm.php");
- ?>
- <iframe src="iframe.htm" id="iframeOculto" name="iframeOculto"
- style="width:0px; height:0px; border: 0px"></iframe>
- <form action="<?php echo EDIT_FORM_ACTION;
- ?>" method="post" name="form1"
- onSubmit="MM_validateForm('Usuario','','R','nombre1','','R','apellido1','','R','email','','RisEmail','Password','','R','Repetir_Password','','R');return document.MM_returnValue">
- <table width="98%" align="center" class="tabla">
- <tr valign="baseline" class="tr2">
- <td colspan="2" align="left" nowrap>Datos del Usuario</td>
- </tr>
- <tr valign="baseline" class="tr1">
- <td width="50%" align="left" nowrap>Usuario:</td>
- <td width="50%"><input name="Usuario" type="text" class="input_login"
- value='' size="32" id="Usurio"
- onBlur="validar_username(this.value,'Usuario');"></td>
- </tr>
- <tr valign="baseline" class="tr1">
- <td width="50%" align="left" nowrap>Primer Nombre:</td>
- <td width="50%"><input name="nombre1" type="text" class="input_text"
- value='' size="32"></td>
- </tr>
- <tr valign="baseline" class="tr1">
- <td width="50%" align="left" nowrap>Segundo Nombre:</td>
- <td width="50%"><input name="nombre2" type="text" class="input_text"
- value='' size="32"></td>
- </tr>
- <tr valign="baseline" class="tr1">
- <td width="50%" align="left" nowrap>Primer Apellido:</td>
- <td width="50%"><input name="apellido1" type="text" class="input_text"
- value='' size="32"></td>
- </tr>
- <tr valign="baseline" class="tr1">
- <td width="50%" align="left" nowrap>Segundo Apellido:</td>
- <td width="50%"><input name="apellido2" type="text" class="input_text"
- value='' size="32"></td>
- </tr>
- <tr valign="baseline" class="tr1">
- <td width="50%" align="left" nowrap>ContraseƱa:</td>
- <td width="50%"><input name="Password" type="password"
- class="input_login" value='' size="32"></td>
- </tr>
- <tr valign="baseline" class="tr1">
- <td width="50%" align="left" nowrap>Repetir ContraseƱa:</td>
- <td width="50%"><input name="Repetir_Password" type="password"
- class="input_login" id="Repetir_Password" value='' size="32"></td>
- </tr>
- <tr valign="baseline" class="tr1">
- <td width="50%" align="left" nowrap>Email:</td>
- <td width="50%"><input name="email" type="text" class="input_text"
- value='' size="32"></td>
- </tr>
- <tr align="left" valign="baseline" class="tr2">
- <td colspan="2" nowrap class="tr2">Sexo de la Persona:</td>
- </tr>
- <tr align="left" valign="baseline" class="tr1">
- <td colspan="2" nowrap class="tr1"><select
- name="idSexo" id="idSexo">
- <?php
- do {
- ?>
- <option value="<?php echo $row_RsSexo['idSexo']?>"><?php echo $row_RsSexo['Sexo']?></option>
- <?php
- }
- while ($row_RsSexo = mysql_fetch_assoc($RsSexo));
- $rows = mysql_num_rows($RsSexo);
- if($rows > 0) {
- mysql_data_seek($RsSexo, 0);
- $row_RsSexo = mysql_fetch_assoc($RsSexo);
- }
- mysql_free_result($RsSexo);
- ?>
- </select></td></tr>
- <tr align="left" valign="baseline" class="tr2">
- <td colspan="2" nowrap class="tr2">Nivel de Acceso</td>
- </tr>
- <tr align="left" valign="baseline" class="tr1">
- <td colspan="2" nowrap class="tr1"><select
- name="nivel" id="nivel">
- <?php
- do {
- ?>
- <option value="<?php echo $row_Rsdepartamento['idNivel']?>"><?php echo $row_Rsdepartamento['Nivel']?></option>
- <?php
- }
- while ($row_Rsdepartamento = mysql_fetch_assoc($Rsdepartamento));
- $rows = mysql_num_rows($Rsdepartamento);
- if($rows > 0) {
- mysql_data_seek($Rsdepartamento, 0);
- $row_Rsdepartamento = mysql_fetch_assoc($Rsdepartamento);
- }
- mysql_free_result($Rsdepartamento);
- ?>
- </select></td></tr>
- <tr valign="baseline" class="tr3">
- <td colspan="2" align="right" nowrap> </td>
- </tr>
- <tr valign="baseline" class="tr3">
- <td width="50%" align="right" nowrap> </td>
- <td width="50%"><input type="submit" class="input_submit"
- value="Insertar Registro"></td>
- </tr>
- </table>
- <input type="hidden" name="MM_insert" value="form1"></form>
- <p> </p>
- <?php include_once ("inc_bottom_adm.php");
- ?>
- </body>
- </html>