tieneAcceso()){
header("Location: ".$pag."?error=3");
exit();
}
unset($objValida);
if(!isset($_SESSION["periodo_id"]) || $_SESSION["periodo_id"] ==""){
echo "Necesitas seleccionar un periodo.";
exit();
}
//$usr = filter_input(INPUT_POST, "id", FILTER_SANITIZE_NUMBER_INT);//limpia texto
$usr = $_SESSION["usuario_id"];
//Obtiene horario del usuario
/*$stmt = $pdo->prepare('Select * from fs_mihorario(:usr, :per, 3)');//Obtiene todo el calendario
$stmt->bindParam(":usr", $_SESSION["usuario_id"]);
$stmt->bindParam(":per", $_SESSION["periodo_id"]);
if(!$stmt->execute()){
//$t = $stmt->errorInfo();
echo "Ocurrió un error al obtener los horarios ";
exit();
}*/
if(isset($_POST["fecha"]) && $_POST["fecha"] != ""){
$filter_fecha = fechaGuion(trim(filter_input(INPUT_POST, "fecha", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto
}
if(!isset($filter_fecha)){
$stmt = $pdo->prepare('Select * from fs_mihorario(:usr, :per, 3)');//Obtiene todo el calendario
$stmt->bindParam(":per", $_SESSION["periodo_id"]);
}else{
$stmt = $pdo->prepare('Select * from fs_mihorariofull(:usr, :fecha, 3)');//Obtiene todo el calendario
$stmt->bindParam(":fecha", $filter_fecha);
}
$stmt->bindParam(":usr", $_SESSION["usuario_id"]);
if($stmt->execute())
$horario_rs = $stmt->fetchAll();
/*$horaMin = horaMin($horario_rs, "Hora_inicio");
$horaMax = horaMax($horario_rs, "Hora_final");*/
$horaMin = HORA_INICIO.":00";
$horaMax = HORA_FINAL.":00";
$stmt->closeCursor();
//---
$stmt = $pdo->prepare('Select * from fs_dia(NULL)');
if(!$stmt->execute()){
echo "Error al obtener los días";
exit();
}
$dias_rs = $stmt->fetchAll();
$stmt->closeCursor();
//---
$stmt = $pdo->prepare('Select * from fs_usuario(:usr)');
$stmt->bindParam(":usr", $usr);
if(!$stmt->execute()){
echo "Error al obtener los datos del usuario";
exit();
}
$usr_rs = $stmt->fetch();
$stmt->closeCursor();
$nombre_usr = $usr_rs["Usuario_apellidos"]." ".$usr_rs["Usuario_nombre"];
unset($usr_rs);
//---
$stmt = $pdo->prepare('Select * from fs_superiorusuario(:usr, NULL)');
$stmt->bindParam(":usr", $usr);
//$stmt->bindParam(":puesto", $puesto_id);
if(!$stmt->execute()){
echo "Error al obtener los datos del usuario superior";
exit();
}
$usr_rs = $stmt->fetch();
$stmt->closeCursor();
$nombreSup_usr = $usr_rs["Usuario_apellidos"]." ".$usr_rs["Usuario_nombre"];
unset($usr_rs);
//Obtiene 2 corrreos
$stmt = $pdo->prepare('Select * from fs_contacto(:id, 3 , NULL) ORDER BY "PerfilContacto_id"');//3 correo, Null todos
$stmt->bindParam(":id", $usr);
if(!$stmt->execute()){
echo "Error al obtener los datos del correo";
exit();
}else{
$contacto_rs = $stmt->fetchAll();
$correos = array();
$c_i = 0;
$c_j = 0;
for($c_j=0; $c_j< count($contacto_rs); $c_j++ ){
if( strpos($contacto_rs[$c_j]["Contacto_valor"], "lasalle.mx") !== false || strpos($contacto_rs[$c_j]["Contacto_valor"], "lasallistas.org.mx") !== false ){
$correos[] = $contacto_rs[$c_j]["Contacto_valor"];
$c_i++;
}
}
$datos["correo1"] = "";
$datos["correo2"] = "";
if($c_i>0){
$datos["correo1"] = $correos[0];
}
if($c_i>1){
$datos["correo2"] = $correos[1];
}
}
$stmt->closeCursor(); // cierra conexion de resultado
//-----
$defaultConfig = (new Mpdf\Config\ConfigVariables())->getDefaults();
$fontDirs = $defaultConfig['fontDir'];
$defaultFontConfig = (new Mpdf\Config\FontVariables())->getDefaults();
$fontData = $defaultFontConfig['fontdata'];
$mpdf = new \Mpdf\Mpdf([
'mode' => 'utf-8',
'format' => [215, 279],
'orientation' => 'P',
'fontDir' => array_merge($fontDirs, [
__DIR__ . '/../../fonts/indivisaFont/ttf',
]),
'fontdata' => $fontData + [
'indivisa-display' => [
'R' => 'IndivisaDisplaySans-Regular.ttf',
],
'indivisa-title' => [
'R' => 'IndivisaDisplaySerif-RegularItalic.ttf',
],
'indivisa-text' => [
'R' => 'IndivisaTextSans-Regular.ttf',
]
],
'default_font' => 'indivisa-text',
]);
//$mpdf->SetDisplayMode('fullpage');
$stylesheet = "";
//echo $stylesheet;
$xtpl = new XTemplate('../tpl/mihorario_reporte.tpl.html');
$xtpl->assign("NOMBRE", $nombre_usr);
if($datos["correo1"] != ""){
$xtpl->assign("CORREO", $datos["correo1"]);
$xtpl->parse("main.datos.correo");
}
if($datos["correo2"] != ""){
$xtpl->assign("CORREO", $datos["correo2"]);
$xtpl->parse("main.datos.correo");
}
$xtpl->assign("PUESTO", "");
$xtpl->assign("AREA", "");
$xtpl->assign("SUPERIOR", $nombreSup_usr);
$xtpl->assign("HOY", date("d/m/Y"));
$xtpl->assign("PERIODO", $_SESSION["periodo_desc"]);
$xtpl->parse("main.datos");
foreach($dias_rs as $dia){
$xtpl->assign("DIA", $dia["Dia_desc"]);
$xtpl->parse("main.header");
}
$rs_i = 0;
$spacerArr = array(1=>0,0,0,0,0,0);
$total_tipo = array(1=>0,0,0);
//$horas_dif = intval(date('H', strtotime($horaMax))) - intval(date('H', strtotime($horaMin)));
for($h = date('H', strtotime($horaMin)); $h < date('H', strtotime($horaMax)); $h++){
$xtpl->assign("HORA", date('H', strtotime($h.":00")));
$xtpl->assign("FRACCIONES", FRACCION_HORA);
$xtpl->parse("main.hora_row.hora");
for($f = 0; $f < FRACCION_HORA; $f++){
foreach($dias_rs as $dia){
if($rs_i < count($horario_rs) && date('H:i', strtotime($horario_rs[$rs_i]["Hora_inicio"])) == date('H:i', strtotime($h.":".($f * (60/FRACCION_HORA)))) && $horario_rs[$rs_i]["Dia_id"] == $dia["Dia_id"]){
$size = $horario_rs[$rs_i]["Duracion"]/(60/FRACCION_HORA);
$spacerArr[$dia["Dia_id"]] = $size -1;
$xtpl->assign("DURACION_SIZE", $size);
$xtpl->assign("COLOR", $horario_rs[$rs_i]["TipoHorario_color"]);
$xtpl->assign("TIPO", $horario_rs[$rs_i]["TipoHorario_desc"]);
$total_tipo[$horario_rs[$rs_i]["TipoHorario_id"]]+= $horario_rs[$rs_i]["Duracion"]/60;
$xtpl->assign("HORA_I", date('H:i', strtotime($horario_rs[$rs_i]["Hora_inicio"])));
$xtpl->assign("HORA_F", date('H:i', strtotime($horario_rs[$rs_i]["Hora_final"])));
$xtpl->parse("main.hora_row.td.td_mihorario.hora");
$salon = "";
do{
if($horario_rs[$rs_i]["Salon_desc"] != "") $salon = "Salón: ".$horario_rs[$rs_i]["Salon_desc"];
else if($horario_rs[$rs_i]["Materia_desc"] != "") $salon = "Pendiente";
$xtpl->assign("MATERIA", $horario_rs[$rs_i]["Materia_desc"]);
$xtpl->assign("GRUPO", $horario_rs[$rs_i]["Grupo_desc"]." ".$horario_rs[$rs_i]["Carrera_prefijo"]);
if($horario_rs[$rs_i]["Materia_desc"] != "")
$xtpl->parse("main.hora_row.td.td_mihorario.texto");
$rs_i++;
}while($rs_i < count($horario_rs) && date('H:i', strtotime($horario_rs[$rs_i-1]["Hora_inicio"])) == date('H:i', strtotime($horario_rs[$rs_i]["Hora_inicio"])) && $horario_rs[$rs_i]["Dia_id"] == $dia["Dia_id"]);
$xtpl->assign("SALON", $salon);
$xtpl->parse("main.hora_row.td.td_mihorario");
}else{
if(!isset($spacerArr[$dia["Dia_id"]]) || $spacerArr[$dia["Dia_id"]] == 0)
$xtpl->parse("main.hora_row.td.td_vacio");
else
$spacerArr[$dia["Dia_id"]]--;
}
$xtpl->parse("main.hora_row.td");
}
$xtpl->parse("main.hora_row");
}
}
$xtpl->parse("main.logo");
$stmt = $pdo->prepare('Select * from fs_tipohorario(NULL, NULL)');
$stmt->execute();
$tipo_rs = $stmt->fetchAll();
$stmt->closeCursor();
foreach($tipo_rs as $tipo){
$xtpl->assign("COLOR", $tipo["TipoHorario_color"]);
$xtpl->assign("DESC", $tipo["TipoHorario_desc"]);
$xtpl->assign("TOTAL", $total_tipo[$tipo["TipoHorario_id"]]);
$xtpl->parse("main.tipo_row");
}
$xtpl->assign("COLOR", '#fff');
$xtpl->assign("DESC", "Total de horas");
$xtpl->assign("TOTAL", $total_tipo[1]+$total_tipo[2]+$total_tipo[3]);
$xtpl->parse("main.tipo_row");
$xtpl->parse("main");
//$xtpl->out("main"); exit();
$mpdf->WriteHTML($stylesheet);
if(!isset($errorDesc))
$mpdf->WriteHTML($xtpl->text("main"));
else
$mpdf->WriteHTML($errorDesc);
$mpdf->Output("horariousuario.pdf", 'I');
?>