Guest User

Untitled

a guest
Oct 30th, 2018
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.26 KB | None | 0 0
  1. <?php
  2. //Archivo de conexion
  3. include_once("connection.php");
  4. $sql = "SELECT * FROM `reservacdt` limit 10 ";
  5. $queryRecords = mysqli_query($conn, $sql) or die("Error al buscar");
  6. ?>
  7. <!DOCTYPE html>
  8. <html lang="en">
  9. <head>
  10. <meta charset="UTF-8">
  11. <script type="text/javascript" src="jquery-1.11.1.min.js"></script> <!-- Se comunica con jquery para editar la tabla -->
  12. <link rel="stylesheet" href="estilosclase.css"> <!-- El css de la pagina, mas que todo el de la tabla -->
  13. </head>
  14.  
  15. <body>
  16. <!-- Refresca la pagina -->
  17. <br></br>
  18. <div style="text-align: center;"><a href="cdtclase.php">Haga click para refrescar</a></div>
  19.  
  20. <!-- Tabla con los datos de la base de datos -->
  21. <div class="container" style="padding:50px 250px;">
  22. <h1>Clases actuales en el sistema (Centro de tecnología):</h1>
  23. <h2>Haga click en un campo para editarlo (La fecha de inscripción no es editable)</h2>
  24. <div id="msg" class="alert"></div> <!-- Da las alertas en connection -->
  25. <table id="employee_grid" name="employee_grid" class="table table-condensed table-hover table-striped bootgrid-table" width="60%" cellspacing="0">
  26. <thead>
  27. <tr>
  28. <th>Nombre</th>
  29. <th>Materia</th>
  30. <th>Fecha de inicio</th>
  31. <th>Hora que empieza</th>
  32. <th>Hora que termina</th>
  33. <th>Número de maquinas a usar</th>
  34. <th>Fecha de inscripción</th>
  35. <th>Borrar</th>
  36. </tr>
  37. </thead>
  38. <tbody id="_editable_table"> <!-- Usando los datos en connection, se imprimen los datos de uno en uno -->
  39. <?php foreach($queryRecords as $res) :?>
  40. <tr data-row-id="<?php echo $res['id'];?>">
  41. <td class="editable-col" contenteditable="true" colcdt='0' oldVal ="<?php echo $res['nombre'];?>"><?php echo $res['nombre'];?></td>
  42. <td class="editable-col" contenteditable="true" colcdt='1' oldVal ="<?php echo $res['materia'];?>"><?php echo $res['materia'];?></td>
  43. <td class="editable-col" contenteditable="true" colcdt='2' oldVal ="<?php echo $res['fecha'];?>"><?php echo $res['fecha'];?></td>
  44. <td class="editable-col" contenteditable="true" colcdt='3' oldVal ="<?php echo $res['fechaemp'];?>"><?php echo $res['fechaemp'];?></td>
  45. <td class="editable-col" contenteditable="true" colcdt='4' oldVal ="<?php echo $res['fechater'];?>"><?php echo $res['fechater'];?></td>
  46. <td class="editable-col" contenteditable="true" colcdt='5' oldVal ="<?php echo $res['numero'];?>"><?php echo $res['numero'];?></td>
  47. <td class="editable-col" contenteditable="false" colcdt='6' oldVal ="<?php echo $res['fechainscripcion'];?>"><?php echo $res['fechainscripcion'];?></td>
  48. <td><button type="button" name="delete_btn" colcdt='7' oldVal="'.$res["id"].'" class="btn btn-xs btn-danger btn_delete">x</button></td></tr>
  49. <?php endforeach;?>
  50. </tbody>
  51. </table>
  52. </div>
  53.  
  54. <div id="boton2" style="text-align: center;"> <!-- Muestra la forma de buscar datos -->
  55. <button onclick="myFunction2()" id="busca">Mostrar el buscador</button>
  56.  
  57. <div id="buscador" name="buscador">
  58. <form method="POST" action="cdtbuscar.php" style="padding:50px 250px;">
  59. <h3>Buscar usando el nombre del profesor o su materia</h3>
  60. <input type="text" placeholder="Escriba el nombre del profesor o su materia" name="niet" id="niet">
  61. <input type="submit" id="input buscar" name="input buscar">
  62. </form>
  63. </div>
  64.  
  65. <div id="boton1" style="text-align: center;"> <!-- Muestra la forma de borrar datos -->
  66. <button onclick="myFunction1()" id="borra">Mostrar forma de borrar datos</button>
  67. </div>
  68.  
  69. <div id="borrador"> <!-- La forma de borrar datos -->
  70. <form method="POST" action="cdtclaseborrar.php" style="padding:50px 250px;">
  71.  
  72. <h1>Escriba el nombre del profesor para borrar su clase o escriba una fecha de inscripción para borrar la clase correspondiente</h1>
  73. <input type="text" placeholder="Escriba el nombre del profesor o la fecha de inscripcion para borrar la clase" name="nombreprofe" id ="nombreprofe"></input>
  74. <div id="input submit" style="text-align: center;;"><input type="submit" id="submit" name="submit" class="floated" value="Borrar clase"></input></div>
  75. <br></br>
  76. </form>
  77. </div>
  78.  
  79. </body>
  80. </html>
  81. <script type="text/javascript">
  82.  
  83. function myFunction1() { <!-- Muestra el formulario de borrar filas -->
  84. var x = document.getElementById("borrador");
  85. var audio = new Audio('audio/mouse.mp3');
  86. audio.play();
  87. if (confirm("Esta seguro? Si borra la fila, se borrara en la base de datos")) {
  88. if (x.style.display === "block") {
  89. x.style.display = "none";
  90. document.getElementById("borra").value="Mostrar forma de borrar datos";
  91.  
  92. } else {
  93. x.style.display = "block";
  94. document.getElementById("borra").value="Quitar formulario";
  95. }
  96.  
  97. } else {
  98. x.style.display = "none";
  99. }
  100.  
  101. }
  102.  
  103. function myFunction2() { <!-- Muestra el formulario de busqueda de filas -->
  104. var z = document.getElementById("buscador");
  105. var audio = new Audio('audio/mouse.mp3');
  106. audio.play();
  107. if (z.style.display === "block") {
  108. z.style.display = "none";
  109. document.getElementById("busca").value="Mostrar forma de buscar datos";
  110. } else {
  111. z.style.display = "block";
  112. document.getElementById("busca").value="Quitar formulario";
  113. }
  114. }
  115.  
  116. $(document).ready(function(){ <!-- Permite editar la tabla en si -->
  117. $('td.editable-col').on('focusout', function() {
  118. data = {};
  119. data['val'] = $(this).text();
  120. data['id'] = $(this).parent('tr').attr('data-row-id');
  121. data['cdtclase'] = $(this).attr('colcdt');
  122. if($(this).attr('oldVal') === data['val'])
  123. return false;
  124.  
  125. $.ajax({
  126.  
  127. type: "POST",
  128. url: "servercdt.php", <!-- Se conecta a este archivo php que contiene alertas y la coneccion -->
  129. cache:false,
  130. data: data,
  131. dataType: "json",
  132. success: function(response)
  133. {
  134. //$("#loading").hide();
  135. if(!response.error) {
  136. $("#msg").removeClass('alert-danger');
  137. $("#msg").addClass('alert-success').html(response.msg);
  138. } else {
  139. $("#msg").removeClass('alert-success');
  140. $("#msg").addClass('alert-danger').html(response.msg);
  141. }
  142. }
  143. });
  144. });
  145. });
  146.  
  147. //Arreglar esto
  148. $(document).on('click', '.btn_delete', function(){
  149. data = {};
  150. data['val'] = $(this).text();
  151. data['id'] = $(this).parent('tr').attr('data-row-id');
  152. data['cdtclase'] = $(this).attr('colcdt');
  153. if($(this).attr('oldVal') === data['val'])
  154. return false;
  155. if(confirm("Seguro?"))
  156. {
  157. $.ajax({
  158. url:"deletecdt.php",
  159. method:"POST",
  160. data:data,
  161. dataType:"json",
  162. success:function(data){
  163. alert(data);
  164. }
  165. });
  166. }
  167. });
  168.  
  169. </script>
  170.  
  171. <?php
  172.  
  173. include_once("connection.php");
  174.  
  175. //define cdtclase of column
  176. $columns = array(
  177. 0 =>'nombre',
  178. 1 => 'materia',
  179. 2 => 'fecha',
  180. 3 => 'fechaemp',
  181. 4 => 'fechater',
  182. 5 => 'numero',
  183. 6 => 'fechainscripcion'
  184. );
  185. $error = false;
  186. $colVal = '';
  187. $colcdt = $rowId = 0;
  188.  
  189. if(isset($_POST)){
  190. if(isset($_POST['val']) && !empty($_POST['val']) && !$error) {
  191. $colVal = $_POST['val'];
  192. $error = false;
  193.  
  194. } else {
  195. $error = true;
  196. }
  197. if(isset($_POST['cdtclase']) && $_POST['cdtclase'] >= 0 && !$error) {
  198. $colcdt = $_POST['cdtclase'];
  199. $error = false;
  200. } else {
  201. $error = true;
  202. }
  203. if(isset($_POST['id']) && $_POST['id'] > 0 && !$error) {
  204. $rowId = $_POST['id'];
  205. $error = false;
  206. } else {
  207. $error = true;
  208. }
  209.  
  210. if(!$error) {
  211. $sql = "DELETE FROM reservacdt SET ".$columns[$colcdt]." = '".$colVal."' WHERE id='".$rowId."'";
  212. $status = mysqli_query($conn, $sql) or die("database error:". mysqli_error($conn));
  213. $msg = array('error' => $error, 'msg' => 'Se actualizaron los datos, recargue la pagina para poder verlo');
  214. } else {
  215. $msg = array('error' => $error, 'msg' => 'Hubo un problema actualizando los datos');
  216. }
  217. }
  218. ?>
  219.  
  220. <?php
  221. /* Database connection start */
  222. $servername = "localhost";
  223. $username = "root";
  224. $password = "";
  225. $dbname = "prueba";
  226.  
  227. $conn = mysqli_connect($servername, $username, $password, $dbname) or die("Connection failed: " . mysqli_connect_error());
  228.  
  229. /* check connection */
  230. if (mysqli_connect_errno()) {
  231. printf("Connect failed: %sn", mysqli_connect_error());
  232. exit();
  233. }
  234.  
  235. ?>
Add Comment
Please, Sign In to add comment