manda_correo.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. class MandaCorreos{
  3. public static const COORDINADOR = 1;
  4. public static const SUPERVISOR = 2;
  5. public static const JEFE = 4;
  6. public static const PROFESOR = 8;
  7. private const ENVIO_CORREOS = true;
  8. private const PRUEBAS = false;
  9. /* tipo es un acumulador de las banderas */
  10. public static function enviarCorreo($db, $asunto, $texto, $facultad, $tipo, $prof_id = NULL){
  11. $to="";
  12. $correos=[];
  13. if($_ENV['DB_NAME'] == "paad_pruebas" || self::PRUEBAS){
  14. $to = "alejandro.lara@lasalle.mx";
  15. }else{
  16. if($tipo & self::COORDINADOR){
  17. $correos_rs = $db->querySingle("SELECT DISTINCT coor.usuario_correo FROM usuario coor
  18. where rol_id = 9 and facultad_id = :fac
  19. and coor.usuario_correo is not null and coor.usuario_correo != ''",
  20. [':fac' => $facultad]
  21. );
  22. foreach($correos_rs as $correo){
  23. array_push($correos, $correo["usuario_correo"]);
  24. }
  25. unset($correos_rs);
  26. }
  27. if($tipo & self::SUPERVISOR){
  28. $correosSup_rs = $db->querySingle("SELECT DISTINCT sup.usuario_correo
  29. FROM horario_supervisor hs
  30. inner join usuario sup on sup.usuario_id =hs.usuario_id
  31. where :id_fac = ANY(hs.facultad_id_array)
  32. and sup.usuario_correo is not null and sup.usuario_correo != ''",
  33. [':id_fac' => $facultad] );
  34. foreach($correosSup_rs as $correo){
  35. array_push($correos, $correo["usuario_correo"]);
  36. }
  37. unset($correosSup_rs);
  38. }
  39. if($tipo & self::JEFE){
  40. $correosJefe_rs = $db->querySingle("SELECT DISTINCT jefe.usuario_correo
  41. FROM horario_jefe_carrera hs
  42. inner join usuario jefe on jefe.usuario_id =hs.usuario_id
  43. where :id_fac = ANY(hs.facultad_id_array)
  44. and jefe.usuario_correo is not null and jefe.usuario_correo != ''",
  45. [':id_fac' => $facultad] );
  46. foreach($correosJefe_rs as $correo){
  47. array_push($correos, $correo["usuario_correo"]);
  48. }
  49. unset($correosJefe_rs);
  50. }
  51. if($tipo & self::PROFESOR && $prof_id != NULL){
  52. $correosProf_rs = $db->querySingle("SELECT DISTINCT prof.usuario_correo
  53. FROM horario_profesor hs
  54. inner join usuario prof on prof.usuario_id =hs.usuario_id
  55. where :id_fac = ANY(hs.facultad_id_array) and prof.usuario_id = :id_prof
  56. and prof.usuario_correo is not null and prof.usuario_correo != ''",
  57. [':id_prof'=>$prof_id, ':id_fac' => $facultad] );
  58. foreach($correosProf_rs as $correo){
  59. array_push($correos, $correo["usuario_correo"]);
  60. }
  61. unset($correosProf_rs);
  62. }
  63. $to .= join(",", $correos);
  64. }
  65. if($to!= "" && self::ENVIO_CORREOS){
  66. //crear plantilla
  67. $texto = '<body >
  68. <img src="https://paad.lci.ulsa.mx/imagenes/logo_lasalle.png" alt="La Salle" style="margin-bottom:60px">
  69. '.$texto.'
  70. </body>';
  71. require_once('../include/phpmailer/PHPMailerAutoload.php');
  72. if($_ENV['DB_NAME'] == "paad_pruebas" || self::PRUEBAS){
  73. $asunto = "PRUEBAS-".$asunto;
  74. }
  75. Mailer::enviarCorreo($to, $asunto, $texto, true);
  76. }
  77. }
  78. }
  79. ?>