tieneAcceso()){
header("Location: ".$pag."?error=1");
exit();
}
unset($objValida);
if(!isset($_POST["evento"]) || !isset($_POST["doc_id"]) || !isset($_POST["participantes"]) || !isset($_POST["desc"]) || !isset($_POST["fecha"]) || !isset($_POST["num_firmas"], $_POST["firma"], $_POST["puesto"], $_POST["motivo"])){
header("Location: ".$pag."?error=0");
exit();
}
$evento = filter_input(INPUT_POST, "evento", FILTER_SANITIZE_NUMBER_INT);//limpia texto
$part_tipo = filter_input(INPUT_POST, "part_id", FILTER_SANITIZE_NUMBER_INT);//limpia texto
$motivo = "Participante";//trim(filter_input(INPUT_POST, "motivo", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));
$doc_id = filter_input(INPUT_POST, "doc_id", FILTER_SANITIZE_NUMBER_INT);//limpia texto
$doc_desc = trim(filter_input(INPUT_POST, "doc_desc", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));
$participantes = $_POST["participantes"];//array
$desc = $_POST["desc"];
$fecha = trim(filter_input(INPUT_POST, "fecha", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));//limpia texto
$numFirmas = filter_input(INPUT_POST, "num_firmas", FILTER_SANITIZE_NUMBER_INT);//limpia texto
$firma = $_POST["firma"];//array
$lleva_firma = $_POST["lleva_firma"];//array
$puesto = $_POST["puesto"];//array
$firmasArr = array();
try {
$pdo->beginTransaction();
$i = 0;
while($i < $numFirmas){
$stmt = $pdo->prepare('Select * from fs_constanciafirma(:id, NULL )');//firmas
$stmt->bindParam(":id", $firma[$i]);
if(!$stmt->execute()){
$pdo->rollBack();
//header("Location:".$pag."?error=2");
print_r($stmt->errorInfo());
exit();
}
$firma_rs = $stmt->fetch();
$stmt->closeCursor();
$firmasArr[] = array("id"=>$firma_rs["ConstanciaFirma_id"] ,"grado"=>$firma_rs["ConstanciaFirma_grado"] ,
"nombre"=> $firma_rs["ConstanciaFirma_nombre"], "puesto"=>$puesto[$i],
"firma"=> $firma_rs["ConstanciaFirma_imagen"], "lleva_firma"=>($lleva_firma[$i]==1)?true:false
);
$i++;
}
//Datos concurso
$stmt = $pdo->prepare('SELECT * FROM fs_insignia(:per, :id, NULL, NULL, true, true, 0, NULL)');
$stmt->bindParam(":per", $_SESSION["periodo_id"]);
$stmt->bindParam(":id", $evento);
if(!$stmt->execute()){
$pdo->rollBack();
//header("Location:".$pag."?error=2");
print_r($stmt->errorInfo());
exit();
}
$evento_rs = $stmt->fetch();
$stmt->closeCursor();
$evento_marca = $evento_rs["Insignia_titulo"];
$defaultConfig = (new Mpdf\Config\ConfigVariables())->getDefaults();
$fontDirs = $defaultConfig['fontDir'];
$defaultFontConfig = (new Mpdf\Config\FontVariables())->getDefaults();
$fontData = $defaultFontConfig['fontdata'] +
[ 'tipo' => [
'R' => 'IndivisaDisplaySans-Thin.ttf',
]] +
[ 'texto-a' => [
'R' => 'IndivisaTextSans-Light.ttf',
]] +
['indivisa-text' => [
'R' => 'IndivisaTextSans-Regular.ttf',
'B' => 'IndivisaTextSans-Bold.ttf',
'BI' => 'IndivisaTextSans-BoldItalic.ttf',
]];
$stylesheet = "";
//----------- Archivos y zip ---
$tmp_folder = "./zip/pdf_".fechaGuion($fecha);
if (!file_exists($tmp_folder)) {
mkdir($tmp_folder, 0777, true);
}
$zip = new ZipArchive();
$zip_filename = "zip/GEMA_".$motivo."_".fechaGuion($fecha)."_".date("his").".zip";
if ($zip->open($zip_filename, ZipArchive::CREATE)!==TRUE) {
$pdo->rollBack();
exit("cannot open <$zip_filename>\n");
}
//Marca de agua
if (file_exists($_SERVER['DOCUMENT_ROOT']. '/const/export/zip/marca.png')) {
unlink($_SERVER['DOCUMENT_ROOT']. '/const/export/zip/marca.png');
}
$marca = mb_strtoupper($evento_marca,'UTF-8') . ' ' . fechaGuion($fecha). ' | '; //No acepta caracteres especiales
generaMarcaDeAgua($marca, "zip/");
$header = '
';
//Footer
$footer = "";
$num = 1;
foreach($participantes as $part){
$stmt = $pdo->prepare('Select * from "Alumno_view" WHERE "Usuario_id" = :usr');
$stmt->bindParam(":usr", $part);
if(!$stmt->execute()){
$pdo->rollBack();
//header("Location:".$pag."?error=2");
print_r($stmt->errorInfo());
exit();
}
$datos_rs = $stmt->fetch();
$stmt->closeCursor();
$nombre=$datos_rs["Usuario_nombre"]." ".$datos_rs["Usuario_apellidos"];
$mpdf = new \Mpdf\Mpdf([
'mode'=>'utf-8', 'format'=>'Letter',
'margin_header'=> 21, 'margin_top'=>52, 'margin_left'=> 35, 'margin_right'=> 30, 'margin_footer'=>10,
'orientation' => 'P',
'fontDir' => array_merge($fontDirs, [
__DIR__ . '/../../fonts/indivisaFont/ttf',
]),
'fontdata' => $fontData,
'default_font' => 'indivisa-text'
]);
$xtpl = new XTemplate('../tpl/constancia.tpl.html');
$xtpl->assign("TIPO", $doc_desc);
$xtpl->assign("NOMBRE", $nombre);
$xtpl->assign("TEXTO", $desc);
$xtpl->parse("main");
$footer = generaFooter($pdo, $sist, $pag, $fecha, $numFirmas, $firmasArr, $nombre, $motivo, $doc_id, $evento_marca, $desc, $evento);
/*echo $stylesheet;
echo $header;
echo $xtpl->text("main");
echo $footer;
exit();*/
$mpdf->SHYlang = 'es';
$mpdf-> SetTitle($doc_desc . '-' . $nombre);
$mpdf-> SetAuthor('Facultad de Ingeniería. © Universidad La Salle A.C. '.date("y").' Todos los derechos Reservados.');
$mpdf->SetHTMLHeader($header);
$mpdf->WriteHTML($stylesheet);
$mpdf->WriteHTML($xtpl->text("main"));
$mpdf->SetHTMLFooter($footer);
$mpdf->SetProtection(array('print', 'print-highres'), '', md5(time()));
//$mpdf->Output("file.pdf", 'I');exit();//Test imprime en pantalla
$mpdf->Output($tmp_folder."/".$doc_desc."_".$num.".pdf", 'F');
if(!empty($datos_rs["Usuario_claveULSA"]) && $datos_rs["Usuario_claveULSA"] != "")
$zip_innerfilename = $doc_desc."_".$nombre."[".$datos_rs["Usuario_claveULSA"]."].pdf";
else
$zip_innerfilename = $doc_desc."_".$nombre.".pdf";
$zip->addFile(
$tmp_folder."/".$doc_desc."_".$num.".pdf",
$doc_desc."s_".fechaGuion($fecha)."/".$zip_innerfilename
);
$num++;
}//for participante
if($zip->numFiles<=0){
$pdo->rollBack();
echo "Error al guardar en el zip";
$zip->close();
unlink($zip_filename);
exit();
}
$zip->close();
removeFolder($tmp_folder);
header("Content-Type: application/zip");
header("Content-Disposition: attachment; filename=".basename($zip_filename));
header("Pragma: no-cache");
header("Expires: 0");
ob_end_clean();
flush();
readfile($zip_filename);
$pdo->commit();
unlink("zip/marca.png");
//unlink($zip_filename);//Test el archivo se queda para no generar de nuevo
} catch(PDOException $e) {
$pdo->rollBack();
//header("Location:".$pag."?error=2");
print_r($e);
exit();
}
function removeFolder($folderName) {
if (is_dir($folderName))
$folderHandle = opendir($folderName);
if (!$folderHandle)
return false;
while($file = readdir($folderHandle)) {
if ($file != "." && $file != "..") {
if (!is_dir($folderName."/".$file))
unlink($folderName."/".$file);
else
removeFolder($folderName.'/'.$file);
}
}
closedir($folderHandle);
rmdir($folderName);
return true;
}
?>