PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/BD/sitio-atonaltzin/mostrar_tabla_duenos.php

https://github.com/astrocumbia/UTM
PHP | 211 lines | 190 code | 16 blank | 5 comment | 20 complexity | fdddeab6e3b6926d2b5b233d585f5f27 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. @session_start();
  3. /* Verificar que el usuario inicio sesion */
  4. if(!isset($_SESSION['usuario']))
  5. {
  6. echo '<script> location.href = "login.php"; </script>';
  7. exit();
  8. }
  9. /* rechazar si el taquillero intenta entrar localhost/sitio/reportes.php */
  10. if( $_SESSION['puesto']=="Taquillero" ){
  11. echo '<script> location.href = "inicio.php"; </script>';
  12. exit();
  13. }
  14. include("funciones.php");
  15. // print_r( $_POST );
  16. ?>
  17. <!--TABLA PARA RESULTADOS-->
  18. <div class="col-lg-offset-1 table-responsive col-md-10">
  19. <table class="table table-hover" id="tabla_resultados_duenos">
  20. <!--FILA ENCABEZADO -->
  21. <thead>
  22. <tr>
  23. <th bgcolor="#45A0FF"> Identificador </th>
  24. <th bgcolor="#45A0FF"> Nombre </th>
  25. <th > </th>
  26. <th > </th>
  27. <th > </th>
  28. <th > </th>
  29. </tr>
  30. </thead>
  31. <!--CUERPO DE TABLA-->
  32. <tbody>
  33. <?php
  34. /* HACEMOS CONSULTA PARA RELLENAR TABLA */
  35. switch ($_POST['tipo']) {
  36. case 0:
  37. $myquery = "select * from DUENO;";
  38. break;
  39. case 1:{
  40. $campo = $_POST['campo'];
  41. $valor = $_POST['valor'];
  42. if( $valor == "" ){
  43. $myquery = "select * from DUENO;";
  44. break;
  45. }
  46. if( $campo == 1 ){
  47. $id_dueno = intval($valor);
  48. if( $id_dueno == "" ){
  49. $myquery = "select * from DUENO;";
  50. break;
  51. }
  52. $myquery = "select * from DUENO where id_dueno=$valor;";
  53. }
  54. if( $campo == 2 ){
  55. $myquery = "select * from DUENO where nombre like '%$valor%' OR apellido like '%$valor%';";
  56. }
  57. if( $campo == 3 ){
  58. $id_dueno = intval($valor);
  59. if( $id_dueno == "" ){
  60. $myquery = "select * from DUENO;";
  61. break;
  62. }
  63. $myquery = "select * from DUENO, CAMIONETA where id_dueno=DUENO_id_dueno AND id_camioneta=$id_dueno;";
  64. }
  65. if( $campo == 4 ){
  66. $myquery = "select * from DUENO, CAMIONETA where matricula like '$valor' and id_dueno=DUENO_id_dueno;";
  67. }
  68. break;
  69. }
  70. default: break;
  71. }
  72. $GLOBALS["CONEXION"] = mysql_connect( $GLOBALS["servidor"], $GLOBALS["usuario"], $GLOBALS["password"] ) or die(mysql_error() );
  73. mysql_select_db( $GLOBALS["basedatos"], $GLOBALS["CONEXION"] );
  74. $resultados = mysql_query( $myquery, $GLOBALS["CONEXION"]) or die ( mysql_error() );
  75. $rows = mysql_num_rows( $resultados );
  76. for( $i = 0; $i < $rows; $i++ ){
  77. $tupla = mysql_fetch_assoc( $resultados );
  78. $ID = $tupla['id_dueno'];
  79. $nombre = $tupla['nombre'];
  80. $apellido = $tupla['apellido'];
  81. $resultados_ = mysql_query("select * from DUENO, CAMIONETA where id_dueno=DUENO_id_dueno AND id_dueno=$ID;", $GLOBALS["CONEXION"]) or die ( mysql_error() );
  82. $num_camionetas = mysql_num_rows( $resultados_ );
  83. //echo $num_camionetas;
  84. $disabled_mod = "";
  85. $disabled_del = "";
  86. if( $_SESSION['puesto']=="Admin" ){
  87. $disabled_mod = ' disabled="disabled" ';
  88. $disabled_del = ' disabled="disabled" ';
  89. }
  90. if( $num_camionetas > 0 ){
  91. $disabled_del = ' disabled="disabled" ';
  92. }
  93. echo '
  94. <tr class="info">
  95. <td class="info" width="20%" >
  96. '.$ID.'
  97. </td>
  98. <td class="info" width="30%">
  99. '.$nombre.' '.$apellido.'
  100. </td>
  101. <td class="info" width="2%">
  102. <button type="button" data-toggle="modal" data-target="#modal_agregar_dueno" id="boton_agregar_dueno_'.$ID.'">
  103. <span class=" glyphicon glyphicon-plus-sign"></span>
  104. </button>
  105. </td>
  106. <td class="info" width="2%">
  107. <button type="button" data-toggle="modal" data-target="#modal_ver_dueno" id="boton_ver_dueno_'.$ID.'">
  108. <span class="glyphicon glyphicon-eye-open"></span>
  109. </button>
  110. </td>
  111. <td class="info" width="2%">
  112. <button type="button" data-toggle="modal" data-target="#modal_modificar_dueno" id="boton_modificar_dueno_'.$ID.'" '.$disabled_mod.'>
  113. <span class="glyphicon glyphicon-pencil"></span>
  114. </button>
  115. </td>
  116. <td class="info" width="2%">
  117. <button type="button" id="boton_eliminar_dueno_'.$ID.'" '.$disabled_del.'>
  118. <span class="glyphicon glyphicon-remove-sign"></span>
  119. </button>
  120. </td>
  121. </tr>
  122. <script>
  123. /* mostrar modal ver dueno */
  124. $( "#boton_ver_dueno_'.$ID.'" ).mousedown(function() {
  125. // $("#div_modal_ver_dueno").load("ver_dueno.php?ID='.$ID.'&num='.$num_camionetas.'");
  126. $.ajax({
  127. type: "POST",
  128. url: "ver_dueno.php",
  129. data: "ID='.$ID.'&num='.$num_camionetas.'&nombre='.$nombre.'&apellido='.$apellido.'",
  130. success: function(data) {
  131. $("#div_modal_ver_dueno").html(data);
  132. }
  133. });
  134. });
  135. $( "#boton_modificar_dueno_'.$ID.'" ).mousedown(function() {
  136. $.ajax({
  137. type: "POST",
  138. url: "formulario_modificar_dueno.php",
  139. data: "ID='.$ID.'&num='.$num_camionetas.'&nombre='.$nombre.'&apellido='.$apellido.'",
  140. success: function(data) {
  141. $("#div_modificar_dueno_modal").html(data);
  142. }
  143. });
  144. });
  145. $( "#boton_agregar_dueno_'.$ID.'" ).mousedown(function() {
  146. $("#div_modal_agregar_dueno").load("formulario_agregar_dueno.php");
  147. });
  148. $( "#boton_eliminar_dueno_'.$ID.'" ).mousedown(function() {
  149. if( confirm("¿ Desea Eliminar el dueño '.$nombre.' '.$apellido.' ?") ){
  150. var dataString = "ID=+'.$ID.'&nombre='.$nombre.'&apellido='.$apellido.'";
  151. $.ajax({
  152. type: "POST",
  153. url: "eliminar_dueno.php",
  154. data: dataString,
  155. success: function(data) {
  156. $("#alertas_duenos").html(data);
  157. }
  158. });
  159. $.ajax({
  160. type: "POST",
  161. url: "mostrar_tabla_duenos.php",
  162. data: "tipo=0",
  163. success: function(data) {
  164. $("#div_mostrar_tabla_dueno").html(data);
  165. }
  166. });
  167. }
  168. else{
  169. }
  170. });
  171. </script>
  172. ';
  173. }
  174. ?>
  175. </tbody>
  176. </table>
  177. </div>