manda_correo.php 3.7 KB

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