PageRenderTime 40ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/usuarios_insertar.php

#
PHP | 188 lines | 178 code | 9 blank | 1 comment | 11 complexity | 3bdba4c9f4f376a5e9b9e2c92a41b0d6 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. include_once("software.php");
  3. include_once("clases/acceso_a_opcion.php");
  4. $tabla='';
  5. $_utiles = new utiles();
  6. $titulo_seccion= "Insertar Usuario";
  7. $id_op = 1;
  8. $_acceso_a_opcion = new acceso_a_opcion();
  9. $_acceso_a_opcion->acceso_opcion($id_op);
  10. if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  11. //validar si existe usuario nuevo
  12. $colname_ValidarUsuario = "-1";
  13. if (isset($_GET['Usuario'])) {
  14. $colname_ValidarUsuario = (get_magic_quotes_gpc()) ? $_GET['Usuario'] : addslashes($_GET['Usuario']);
  15. }
  16. mysql_select_db(DB_NAME, CONEXION);
  17. $query_ValidarUsuario = sprintf("SELECT Usuario FROM `Usuario` WHERE Usuario = '%s'", $colname_ValidarUsuario);
  18. $ValidarUsuario = mysql_query($query_ValidarUsuario, CONEXION) or trigger_error(mysql_error(),E_USER_ERROR);
  19. $row_ValidarUsuario = mysql_fetch_assoc($ValidarUsuario);
  20. $totalRows_ValidarUsuario = mysql_num_rows($ValidarUsuario);
  21. mysql_free_result($ValidarUsuario);
  22. if ($totalRows_ValidarUsuario > 0) {
  23. ?>
  24. <script language="javascript">
  25. alert("Ya existe un usuario con ese nombre!");
  26. </script>
  27. <?php
  28. }
  29. else {
  30. $insertSQL = sprintf("INSERT INTO Usuario (Usuario, Password, nombre1, nombre2, apellido1, apellido2, email, idSexo, idNivel) VALUES (%s, '%s', %s, %s, %s, %s, %s, %s, %s)",
  31. $_utiles->GetSQLValueString($_POST['Usuario'], "text_upper"),
  32. md5($_utiles->GetSQLValueString($_POST['Password'], "text_upper")),
  33. $_utiles->GetSQLValueString($_POST['nombre1'], "text_upper"),
  34. $_utiles->GetSQLValueString($_POST['nombre2'], "text_upper"),
  35. $_utiles->GetSQLValueString($_POST['apellido1'], "text_upper"),
  36. $_utiles->GetSQLValueString($_POST['apellido2'], "text_upper"),
  37. $_utiles->GetSQLValueString($_POST['email'], "text"),
  38. $_utiles->GetSQLValueString($_POST['idSexo'], "text"),
  39. $_utiles->GetSQLValueString($_POST['nivel'], "int"));
  40. $_utiles->bitacora('Usuario',$_POST['Usuario'],'insertar');
  41. mysql_select_db(DB_NAME, CONEXION);
  42. $Result1 = mysql_query($insertSQL, CONEXION) or trigger_error(mysql_error(),E_USER_ERROR);
  43. $insertGoTo = "usuarios.php";
  44. if (isset($_SERVER['QUERY_STRING'])) {
  45. $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
  46. $insertGoTo .= $_SERVER['QUERY_STRING'];
  47. }
  48. header(sprintf("Location: %s", $insertGoTo));
  49. }
  50. }
  51. mysql_select_db(DB_NAME, CONEXION);
  52. $query_Rsdepartamento = "SELECT * FROM Nivel";
  53. $Rsdepartamento = mysql_query($query_Rsdepartamento, CONEXION) or trigger_error(mysql_error(),E_USER_ERROR);
  54. $row_Rsdepartamento = mysql_fetch_assoc($Rsdepartamento);
  55. $totalRows_Rsdepartamento = mysql_num_rows($Rsdepartamento);
  56. mysql_select_db(DB_NAME, CONEXION);
  57. $query_RsSexo = "SELECT * FROM Sexo";
  58. $RsSexo = mysql_query($query_RsSexo, CONEXION) or trigger_error(mysql_error(),E_USER_ERROR);
  59. $row_RsSexo = mysql_fetch_assoc($RsSexo);
  60. $totalRows_RsSexo = mysql_num_rows($RsSexo);
  61. ?>
  62. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  63. <html>
  64. <head>
  65. <?php include_once ("inc_head_adm.php");
  66. ?>
  67. <title><?php echo $titulo_seccion;
  68. ?></title>
  69. </head>
  70. <body onLoad="load_functions();" marginwidth="5px" marginheight="4px" leftmargin="0" topmargin="4px" bgcolor="#f0f0f0">
  71. <?php include_once ("inc_top_adm.php");
  72. ?>
  73. <iframe src="iframe.htm" id="iframeOculto" name="iframeOculto"
  74. style="width:0px; height:0px; border: 0px"></iframe>
  75. <form action="<?php echo EDIT_FORM_ACTION;
  76. ?>" method="post" name="form1"
  77. onSubmit="MM_validateForm('Usuario','','R','nombre1','','R','apellido1','','R','email','','RisEmail','Password','','R','Repetir_Password','','R');return document.MM_returnValue">
  78. <table width="98%" align="center" class="tabla">
  79. <tr valign="baseline" class="tr2">
  80. <td colspan="2" align="left" nowrap>Datos del Usuario</td>
  81. </tr>
  82. <tr valign="baseline" class="tr1">
  83. <td width="50%" align="left" nowrap>Usuario:</td>
  84. <td width="50%"><input name="Usuario" type="text" class="input_login"
  85. value='' size="32" id="Usurio"
  86. onBlur="validar_username(this.value,'Usuario');"></td>
  87. </tr>
  88. <tr valign="baseline" class="tr1">
  89. <td width="50%" align="left" nowrap>Primer Nombre:</td>
  90. <td width="50%"><input name="nombre1" type="text" class="input_text"
  91. value='' size="32"></td>
  92. </tr>
  93. <tr valign="baseline" class="tr1">
  94. <td width="50%" align="left" nowrap>Segundo Nombre:</td>
  95. <td width="50%"><input name="nombre2" type="text" class="input_text"
  96. value='' size="32"></td>
  97. </tr>
  98. <tr valign="baseline" class="tr1">
  99. <td width="50%" align="left" nowrap>Primer Apellido:</td>
  100. <td width="50%"><input name="apellido1" type="text" class="input_text"
  101. value='' size="32"></td>
  102. </tr>
  103. <tr valign="baseline" class="tr1">
  104. <td width="50%" align="left" nowrap>Segundo Apellido:</td>
  105. <td width="50%"><input name="apellido2" type="text" class="input_text"
  106. value='' size="32"></td>
  107. </tr>
  108. <tr valign="baseline" class="tr1">
  109. <td width="50%" align="left" nowrap>ContraseƱa:</td>
  110. <td width="50%"><input name="Password" type="password"
  111. class="input_login" value='' size="32"></td>
  112. </tr>
  113. <tr valign="baseline" class="tr1">
  114. <td width="50%" align="left" nowrap>Repetir ContraseƱa:</td>
  115. <td width="50%"><input name="Repetir_Password" type="password"
  116. class="input_login" id="Repetir_Password" value='' size="32"></td>
  117. </tr>
  118. <tr valign="baseline" class="tr1">
  119. <td width="50%" align="left" nowrap>Email:</td>
  120. <td width="50%"><input name="email" type="text" class="input_text"
  121. value='' size="32"></td>
  122. </tr>
  123. <tr align="left" valign="baseline" class="tr2">
  124. <td colspan="2" nowrap class="tr2">Sexo de la Persona:</td>
  125. </tr>
  126. <tr align="left" valign="baseline" class="tr1">
  127. <td colspan="2" nowrap class="tr1"><select
  128. name="idSexo" id="idSexo">
  129. <?php
  130. do {
  131. ?>
  132. <option value="<?php echo $row_RsSexo['idSexo']?>"><?php echo $row_RsSexo['Sexo']?></option>
  133. <?php
  134. }
  135. while ($row_RsSexo = mysql_fetch_assoc($RsSexo));
  136. $rows = mysql_num_rows($RsSexo);
  137. if($rows > 0) {
  138. mysql_data_seek($RsSexo, 0);
  139. $row_RsSexo = mysql_fetch_assoc($RsSexo);
  140. }
  141. mysql_free_result($RsSexo);
  142. ?>
  143. </select></td></tr>
  144. <tr align="left" valign="baseline" class="tr2">
  145. <td colspan="2" nowrap class="tr2">Nivel de Acceso</td>
  146. </tr>
  147. <tr align="left" valign="baseline" class="tr1">
  148. <td colspan="2" nowrap class="tr1"><select
  149. name="nivel" id="nivel">
  150. <?php
  151. do {
  152. ?>
  153. <option value="<?php echo $row_Rsdepartamento['idNivel']?>"><?php echo $row_Rsdepartamento['Nivel']?></option>
  154. <?php
  155. }
  156. while ($row_Rsdepartamento = mysql_fetch_assoc($Rsdepartamento));
  157. $rows = mysql_num_rows($Rsdepartamento);
  158. if($rows > 0) {
  159. mysql_data_seek($Rsdepartamento, 0);
  160. $row_Rsdepartamento = mysql_fetch_assoc($Rsdepartamento);
  161. }
  162. mysql_free_result($Rsdepartamento);
  163. ?>
  164. </select></td></tr>
  165. <tr valign="baseline" class="tr3">
  166. <td colspan="2" align="right" nowrap>&nbsp;</td>
  167. </tr>
  168. <tr valign="baseline" class="tr3">
  169. <td width="50%" align="right" nowrap>&nbsp;</td>
  170. <td width="50%"><input type="submit" class="input_submit"
  171. value="Insertar Registro"></td>
  172. </tr>
  173. </table>
  174. <input type="hidden" name="MM_insert" value="form1"></form>
  175. <p>&nbsp;</p>
  176. <?php include_once ("inc_bottom_adm.php");
  177. ?>
  178. </body>
  179. </html>