manda_correo.php 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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->query("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. //print_r($correos_rs);
  25. foreach($correos_rs as $correo){
  26. array_push($correos, $correo["usuario_correo"]);
  27. }
  28. unset($correos_rs);
  29. }
  30. if($tipo & self::SUPERVISOR){
  31. $correosSup_rs = $db->querySingle("SELECT DISTINCT sup.usuario_correo
  32. FROM horario_supervisor hs
  33. inner join usuario sup on sup.usuario_id =hs.usuario_id
  34. where :id_fac = ANY(hs.facultad_id_array)
  35. and sup.usuario_correo is not null and sup.usuario_correo != ''",
  36. [':id_fac' => $facultad] );
  37. foreach($correosSup_rs as $correo){
  38. array_push($correos, $correo["usuario_correo"]);
  39. }
  40. unset($correosSup_rs);
  41. }
  42. if($tipo & self::JEFE){
  43. $correosJefe_rs = $db->querySingle("SELECT DISTINCT jefe.usuario_correo
  44. FROM horario_jefe_carrera hs
  45. inner join usuario jefe on jefe.usuario_id =hs.usuario_id
  46. where :id_fac = ANY(hs.facultad_id_array)
  47. and jefe.usuario_correo is not null and jefe.usuario_correo != ''",
  48. [':id_fac' => $facultad] );
  49. foreach($correosJefe_rs as $correo){
  50. array_push($correos, $correo["usuario_correo"]);
  51. }
  52. unset($correosJefe_rs);
  53. }
  54. if($tipo & self::PROFESOR && $prof_id != NULL){
  55. $correosProf_rs = $db->querySingle("SELECT DISTINCT prof.usuario_correo
  56. FROM horario_profesor hs
  57. inner join usuario prof on prof.usuario_id =hs.usuario_id
  58. where :id_fac = ANY(hs.facultad_id_array) and prof.usuario_id = :id_prof
  59. and prof.usuario_correo is not null and prof.usuario_correo != ''",
  60. [':id_prof'=>$prof_id, ':id_fac' => $facultad] );
  61. foreach($correosProf_rs as $correo){
  62. array_push($correos, $correo["usuario_correo"]);
  63. }
  64. unset($correosProf_rs);
  65. }
  66. $to .= join(",", $correos);
  67. }
  68. if($to!= "" && self::ENVIO_CORREOS){
  69. //crear plantilla
  70. $texto = '<body >
  71. <img src="https://paad.lci.ulsa.mx/imagenes/logo_lasalle.png" alt="La Salle" style="margin-bottom:60px">
  72. '.$texto.'
  73. </body>';
  74. if($_ENV['DB_NAME'] == "paad_pruebas" || self::PRUEBAS){
  75. $asunto = "PRUEBAS-".$asunto;
  76. }
  77. return Mailer::enviarCorreo($to, $asunto, $texto, true);
  78. }
  79. return true;
  80. }
  81. }
  82. ?>