manda_correo.php 3.7 KB

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