action_profesores_insert.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. $ruta = "../";
  3. require_once "../include/bd_pdo.php";
  4. $id = trim(filter_input(INPUT_POST, "id", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));
  5. if(isset($_POST["dlfacultad"]))
  6. $facultad = trim(filter_input(INPUT_POST, "dlfacultad", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));
  7. else
  8. $facultad = trim(filter_input(INPUT_POST, "mfacultad", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));
  9. $clave = trim(filter_input(INPUT_POST, "mclave", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));
  10. $grado = trim(filter_input(INPUT_POST, "grado", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));
  11. $nombre = trim(filter_input(INPUT_POST, "nombre", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));
  12. $grado = mb_strtoupper($grado);
  13. if(!empty($grado)){
  14. if(!ctype_space($grado)){
  15. if($grado[strlen($grado)-1] != '.')
  16. $grado.='.';
  17. }
  18. else{
  19. $grado="";
  20. }
  21. }
  22. $fs_profesores = query(//revisar si existe la clave del profesor
  23. "SELECT * FROM fs_profesor WHERE clave = :clave",
  24. array(":clave" => $_POST["mclave"]),
  25. true
  26. );
  27. if(!$fs_profesores){//hay que crearlo desde 0 (profesor) y agregarlo a su facultad(facultad_profesor)
  28. $profesor_id = query(
  29. "SELECT public.fi_profesor(
  30. :nombre,
  31. :clave,
  32. :facultad,
  33. null,
  34. :grado
  35. )",
  36. array(":nombre" => mb_strtoupper($nombre), ":clave" => $clave, ":facultad" => $facultad, ":grado" => $grado),
  37. true
  38. );
  39. header("Location: ../profesores.php");
  40. exit();
  41. }
  42. else{//el profesor ya existe
  43. $profac = query(
  44. "SELECT * FROM facultad_profesor WHERE facultad_id = :facultad AND profesor_id = :profesor",
  45. array(":facultad" => $facultad, ":profesor" => $fs_profesores["id"]),
  46. true
  47. );
  48. if(!$profac){//agregarlo a la facultad (facultad_profesor)
  49. query(
  50. "SELECT fi_facultad_profesor(
  51. :facultad,
  52. :profesor
  53. )",
  54. array(":facultad" => $facultad, ":profesor" => $fs_profesores["id"]),
  55. true
  56. );
  57. header("Location: ../profesores.php");
  58. exit();
  59. }
  60. else{//regresar error (ya existe este profesor en esta facultad)
  61. //print_r($profac);
  62. if(!$profac['fp_activo']){
  63. query(
  64. "SELECT fu_estado_facultad_profesor(:idprofesor, :idfacultad, :estado)",
  65. array(":idprofesor" => $fs_profesores["id"], ":idfacultad" => $facultad, ":estado" => true),
  66. true
  67. );
  68. header("Location: ../profesores.php");
  69. exit();
  70. }
  71. header("Location: ../profesores.php?error=1");
  72. #exit();
  73. }
  74. }
  75. ?>