PageRenderTime 47ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/BD/sitio-atonaltzin/modificar_cuota.php

https://github.com/astrocumbia/UTM
PHP | 105 lines | 88 code | 13 blank | 4 comment | 14 complexity | 5848dcf245825f398181ac40d9e2c0db 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. $origen = $_POST['origen'];
  17. $destino = $_POST['destino'];
  18. $precio = floatval( $_POST['precio'] );
  19. $ID = $_POST['ID'];
  20. if( $origen == "" ){
  21. echo '
  22. <div class="alert alert-danger col-lg-offset-1 col-md-7">
  23. <span class="glyphicon glyphicon-remove-circle"></span>
  24. Ocurrio un error al modificar, el campo origen estaba vacio.
  25. </div>
  26. ';
  27. return;
  28. }
  29. if( $destino == "" ){
  30. echo '
  31. <div class="alert alert-danger col-lg-offset-1 col-md-7">
  32. <span class="glyphicon glyphicon-remove-circle"></span>
  33. Ocurrio un error al modificar, el campo destino estaba vacio.
  34. </div>
  35. ';
  36. return;
  37. }
  38. if( $precio == "" ){
  39. echo '
  40. <div class="alert alert-danger col-lg-offset-1 col-md-10">
  41. <span class="glyphicon glyphicon-remove-circle"></span>
  42. Ocurrio un error al modificar, el campo precio estaba vacio o contiene caracteres extraños.
  43. </div>
  44. ';
  45. return;
  46. }
  47. if( $origen == $destino ){
  48. echo '
  49. <div class="alert alert-danger col-lg-offset-1 col-md-7">
  50. <span class="glyphicon glyphicon-remove-circle"></span>
  51. Ocurrio un error al modificar, destino es igual a origen.
  52. </div>
  53. ';
  54. return;
  55. }
  56. $GLOBALS["CONEXION"] = mysql_connect( $GLOBALS["servidor"], $GLOBALS["usuario"], $GLOBALS["password"] ) or die(mysql_error() );
  57. mysql_select_db( $GLOBALS["basedatos"], $GLOBALS["CONEXION"] );
  58. /* valida que tengan diferente username */
  59. $myquery = "select * from CUOTA where descripcion like '$origen-$destino' AND id_cuota=$ID;";
  60. $resultados = mysql_query( $myquery, $GLOBALS["CONEXION"]) or die ( mysql_error() );
  61. if( mysql_num_rows( $resultados ) != 1 ){
  62. $myquery = "select * from CUOTA where descripcion like '$origen-$destino';";
  63. $resultados = mysql_query( $myquery, $GLOBALS["CONEXION"]) or die ( mysql_error() );
  64. if( mysql_num_rows( $resultados ) > 0 ){
  65. echo '
  66. <div class="alert alert-danger col-lg-offset-1 col-md-7">
  67. <span class="glyphicon glyphicon-remove-circle"></span>
  68. Ocurrio un error, la cuota '.$origen.'-'.$destino.' esta en uso.
  69. </div>
  70. ';
  71. return;
  72. }
  73. }
  74. $myquery = "UPDATE CUOTA SET precio=$precio, descripcion='$origen-$destino' WHERE id_cuota=$ID;";
  75. $resultados = mysql_query( $myquery, $GLOBALS["CONEXION"]) or die ( mysql_error() );
  76. if( mysql_query( $myquery, $GLOBALS["CONEXION"]) or die ( mysql_error() ) ){
  77. echo '
  78. <div class="alert alert-warning col-lg-offset-1 col-md-7">
  79. <span class="glyphicon glyphicon-warning-sign"></span>
  80. Se ha modificado la cuota '.$origen.'-'.$destino.'.
  81. </div>
  82. ';
  83. }
  84. else{
  85. echo '
  86. <div class="alert alert-danger col-lg-offset-1 col-md-7">
  87. <span class="glyphicon glyphicon-remove-circle"></span>
  88. Ocurrio un error al modificar la cuota '.$origen.'-'.$destino.'.
  89. </div>
  90. ';
  91. }
  92. ?>