manda_correo.php 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 usuario jefe
  45. where :id_fac = ANY(jefe.facultad_id_array) AND rol_id = 11
  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. return Mailer::enviarCorreo($to, $asunto, $texto, true);
  77. }
  78. return true;
  79. }
  80. }
  81. ?>