tieneAcceso()){ header("Location: ".$pag."?error=1"); exit(); } unset($objValida); if(!isset($_POST["tipo"]) || !isset($_POST["evento"]) || !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(); } $sist = CONSTANCIA; $tipo_id = filter_input(INPUT_POST, "tipo", FILTER_SANITIZE_NUMBER_INT);//limpia texto $evento = trim(filter_input(INPUT_POST, "evento", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))); $motivo = trim(filter_input(INPUT_POST, "motivo", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))); $participantes = $_POST["participantes"];//array $desc = $_POST["desc"]; //filter_input(INPUT_POST, "desc", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)); $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"]; $hay_marca = false; //hay archivo? if(!empty($_FILES['archivo']['name'])){ $archivo = $_FILES['archivo']['name']; // Check file size if ($_FILES["archivo"]["size"] > 500 * 1024) {//en bytes header("Location:".$pag."error=4"); exit(); } $dot_arr = explode('.', $archivo); $ext = end($dot_arr); unset($dot_arr); $target_logo = "logo_".$sist."_".date("dmyhis").".".$ext; } $firmasArr = array(); try { $pdo->beginTransaction(); for($i=0; $i < $numFirmas; $i++){ $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"] /*mb_convert_case(mb_strtolower($firma_rs["ConstanciaFirma_nombre"]), MB_CASE_TITLE, "UTF-8")*/, "puesto"=>$puesto[$i], "firma"=> $firma_rs["ConstanciaFirma_imagen"], "lleva_firma"=>$lleva_firma[$i]/*($lleva_firma[$i]===1)?true:false*/ ); $hay_marca = $hay_marca || (isset($firmasArr[$i]["lleva_firma"]) && $firmasArr[$i]["lleva_firma"]==1); } $stmt = $pdo->prepare('Select * from fs_constancialogtipo(:id)'); $stmt->bindParam(":id", $tipo_id); if(!$stmt->execute()){ header("Location:".$pag."?error=2"); //print_r($stmt->errorInfo()); exit(); } $tipo_rs = $stmt->fetch(); $stmt->closeCursor(); $tipo = $tipo_rs["ConstanciaLogTipo_desc"]; $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/".$tipo."s_".fechaGuion($fecha)."_".date("his").".zip"; if ($zip->open($zip_filename, ZipArchive::CREATE)!==TRUE) { $pdo->rollBack(); exit("cannot open <$zip_filename>\n"); } if($hay_marca==1){ //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,'UTF-8') . ' ' . fechaGuion($fecha) . ' | '; //No acepta caracteres especiales generaMarcaDeAgua($marca, "zip/"); } $header = '
'; if(isset($target_logo)){ $target_dir = "../img/logos/"; if(file_exists($target_dir.$target_logo)){ unlink($target_dir.$target_logo); } if (!move_uploaded_file($_FILES["archivo"]["tmp_name"], $target_dir.$target_logo)) { $pdo->rollBack(); header("Location:".$pag."?error=5"); exit(); } $header .= ''; } $header .= '
'; //Footer $footer = ""; $num = 1; foreach($participantes as $part){ //$nombre = mb_convert_case(mb_strtolower($part), MB_CASE_TITLE, "UTF-8"); $nombre = $part; $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", $tipo); $xtpl->assign("NOMBRE", $nombre); $xtpl->assign("TEXTO", $desc); $xtpl->parse("main"); if(isset($target_logo)) $footer = generaFooter($pdo, $sist, $pag, $fecha, $numFirmas, $firmasArr, $nombre, $motivo, $tipo_id, $evento, $desc, date('y'), $target_logo); else $footer = generaFooter($pdo, $sist, $pag, $fecha, $numFirmas, $firmasArr, $nombre, $motivo, $tipo_id, $evento, $desc, date('y'), NULL); /*echo $stylesheet; echo $header; echo $xtpl->text("main"); echo $footer; exit();*/ $mpdf->SHYlang = 'es'; $mpdf-> SetTitle($tipo . '-' . $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("nombramientos.pdf", 'I');exit();// $mpdf->Output($tmp_folder."/".$tipo."_".$num.".pdf", 'F'); $zip->addFile( $tmp_folder."/".$tipo."_".$num.".pdf", $tipo."s_".fechaGuion($fecha)."/".$tipo."_".$nombre.".pdf" ); $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); } catch(PDOException $e) { $pdo->rollBack(); header("Location:".$pag."?error=2"); //print_r($e); } 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; } ?>