Crear solicitudes y envío de correos
This commit is contained in:
84
class/manda_correo.php
Normal file
84
class/manda_correo.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
class MandaCorreos{
|
||||
public static const COORDINADOR = 1;
|
||||
public static const SUPERVISOR = 2;
|
||||
public static const JEFE = 4;
|
||||
public static 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->querySingle("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]
|
||||
);
|
||||
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] );
|
||||
foreach($correosSup_rs as $correo){
|
||||
array_push($correos, $correo["usuario_correo"]);
|
||||
}
|
||||
unset($correosSup_rs);
|
||||
}
|
||||
if($tipo & self::JEFE){
|
||||
$correosJefe_rs = $db->querySingle("SELECT DISTINCT jefe.usuario_correo
|
||||
FROM horario_jefe_carrera hs
|
||||
inner join usuario jefe on jefe.usuario_id =hs.usuario_id
|
||||
where :id_fac = ANY(hs.facultad_id_array)
|
||||
and jefe.usuario_correo is not null and jefe.usuario_correo != ''",
|
||||
[':id_fac' => $facultad] );
|
||||
foreach($correosJefe_rs as $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){
|
||||
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>';
|
||||
|
||||
require_once('../include/phpmailer/PHPMailerAutoload.php');
|
||||
if($_ENV['DB_NAME'] == "paad_pruebas" || self::PRUEBAS){
|
||||
$asunto = "PRUEBAS-".$asunto;
|
||||
}
|
||||
Mailer::enviarCorreo($to, $asunto, $texto, true);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user