90 lines
4.0 KiB
PHP
90 lines
4.0 KiB
PHP
<?php
|
|
require_once('../include/phpmailer/PHPMailerAutoload.php');
|
|
require_once "../class/mailer.php";
|
|
class MandaCorreos{
|
|
public const COORDINADOR = 1;
|
|
public const SUPERVISOR = 2;
|
|
public const JEFE = 4;
|
|
public const PROFESOR = 8;
|
|
private const ENVIO_CORREOS = true;
|
|
private const PRUEBAS = false;
|
|
|
|
/* tipo es un acumulador de las banderas */
|
|
public static function enviarCorreo($db, $asunto, $texto, $facultad, $tipo, $prof_id = NULL){
|
|
$to="";
|
|
$correos=[];
|
|
if($_ENV['DB_NAME'] == "paad_pruebas" || self::PRUEBAS){
|
|
$to = "alejandro.lara@lasalle.mx";
|
|
}else{
|
|
if($tipo & self::COORDINADOR){
|
|
$correos_rs = $db->query("SELECT DISTINCT coor.usuario_correo FROM usuario coor
|
|
where rol_id = 9 and facultad_id = :fac
|
|
and coor.usuario_correo is not null and coor.usuario_correo != ''",
|
|
[':fac' => $facultad]
|
|
);
|
|
//print_r($correos_rs);
|
|
foreach($correos_rs as $correo){
|
|
array_push($correos, $correo["usuario_correo"]);
|
|
}
|
|
unset($correos_rs);
|
|
}
|
|
if($tipo & self::SUPERVISOR){
|
|
/*$correosSup_rs = $db->querySingle("SELECT DISTINCT sup.usuario_correo
|
|
FROM horario_supervisor hs
|
|
inner join usuario sup on sup.usuario_id =hs.usuario_id
|
|
where :id_fac = ANY(hs.facultad_id_array)
|
|
and sup.usuario_correo is not null and sup.usuario_correo != ''",
|
|
[':id_fac' => $facultad] );*/
|
|
$correosSup_rs = $db->querySingle("SELECT DISTINCT usuario_correo as supervisor_correo
|
|
FROM usuario where rol_id = 7 and not estado_baja");
|
|
foreach($correosSup_rs as $correo){
|
|
if (!empty($correo["usuario_correo"]))
|
|
array_push($correos, $correo["usuario_correo"]);
|
|
}
|
|
unset($correosSup_rs);
|
|
}
|
|
if($tipo & self::JEFE){
|
|
$correosJefe_rs = $db->querySingle("SELECT DISTINCT jefe.usuario_correo
|
|
FROM usuario jefe
|
|
where :id_fac = ANY(jefe.facultad_id_array) AND rol_id = 11
|
|
and jefe.usuario_correo is not null and jefe.usuario_correo != ''",
|
|
[':id_fac' => $facultad] );
|
|
foreach($correosJefe_rs as $correo){
|
|
if(!empty($correo["usuario_correo"]))
|
|
array_push($correos, $correo["usuario_correo"]);
|
|
}
|
|
unset($correosJefe_rs);
|
|
}
|
|
if($tipo & self::PROFESOR && $prof_id != NULL){
|
|
$correosProf_rs = $db->querySingle("SELECT DISTINCT prof.usuario_correo
|
|
FROM horario_profesor hs
|
|
inner join usuario prof on prof.usuario_id =hs.usuario_id
|
|
where :id_fac = ANY(hs.facultad_id_array) and prof.usuario_id = :id_prof
|
|
and prof.usuario_correo is not null and prof.usuario_correo != ''",
|
|
[':id_prof'=>$prof_id, ':id_fac' => $facultad] );
|
|
foreach($correosProf_rs as $correo){
|
|
if(!empty($correo["usuario_correo"]))
|
|
array_push($correos, $correo["usuario_correo"]);
|
|
}
|
|
unset($correosProf_rs);
|
|
}
|
|
$to .= join(",", $correos);
|
|
}
|
|
|
|
if($to!= "" && self::ENVIO_CORREOS){
|
|
//crear plantilla
|
|
$texto = '<body >
|
|
<img src="https://paad.lci.ulsa.mx/imagenes/logo_lasalle.png" alt="La Salle" style="margin-bottom:60px">
|
|
'.$texto.'
|
|
</body>';
|
|
|
|
if($_ENV['DB_NAME'] == "paad_pruebas" || self::PRUEBAS){
|
|
$asunto = "PRUEBAS-".$asunto;
|
|
}
|
|
return Mailer::enviarCorreo($to, $asunto, $texto, true);
|
|
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
?>
|