Subversion Repositories ALCASAR

Rev

Rev 949 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 949 Rev 2168
Line 1... Line 1...
1
<?php
1
<?php
-
 
2
/**
2
require('../lib/fpdf/fpdf.php');
3
 * Print credentials of imported users
-
 
4
 *
-
 
5
 * @author    Tom Houdayer
-
 
6
 * @copyright Copyright (C) ALCASAR (http://www.alcasar.net)
-
 
7
 * @license   GPL-3.0
-
 
8
 * @version   $Id: import_file.php 2168 2017-04-18 17:39:54Z tom.houdayer $
-
 
9
 */
3
 
10
 
4
class fichePDF extends FPDF {
11
if ((!isset($_GET['file'])) || (empty($_GET['file']))) {
-
 
12
	exit();
-
 
13
}
5
 
14
 
6
	function Header()
15
$filename = $_GET['file'];
7
	{
-
 
-
 
16
$format   = ((isset($_GET['format'])) ? $_GET['format'] : 'txt');
8
 
17
 
9
	}
-
 
10
	function Footer()
-
 
11
	{
-
 
12
		//Positionnement à 1,5 cm du bas
18
if (($format !== 'txt') && ($format !== 'pdf')) {
13
		$this->SetY(-15);
-
 
14
		//Arial italique 8
-
 
15
		$this->SetFont('Arial','I',8);
-
 
16
		//Couleur du texte en gris
-
 
17
		$this->SetTextColor(128);
-
 
18
		//Numéro de page
-
 
19
		$this->Cell(0,10,'Page '.$this->PageNo(),0,0,'C');
-
 
20
	}
-
 
21
 
-
 
22
	function lirefichier($fichier)
-
 
23
	{
-
 
24
		$this->AddPage();
-
 
25
		//Lecture des lignes du fichier
-
 
26
		$lines = file($fichier);
-
 
27
		$n = 1;
-
 
28
		foreach($lines as $line){
-
 
29
			//Times 12
-
 
30
			$this->SetFont('Times','',10);
-
 
31
			//Sortie du texte justifié
-
 
32
			$this->Cell(0,5,utf8_decode($line));
-
 
33
			$this->Ln();
-
 
34
			++$n;
19
	exit();
35
			if ($n > (50)){ // on affiche 50 ligne par page soit 5 fiches usagers
-
 
36
				$this->AddPage();
-
 
37
				$n = 1;
-
 
38
			}
-
 
39
		}
-
 
40
	}
-
 
41
}
20
}
42
 
21
 
43
function getImportFile($importFileName, $format = "txt"){
-
 
44
	$importFile = "/tmp/$importFileName.pwd";
22
$filePath = '/tmp/'.$filename.'.pwd';
45
	if(is_file($importFile)&&is_readable($importFile)){
23
if ((!is_file($filePath)) || (!is_readable($filePath))) {
46
		if ($format=="txt"){
-
 
47
			//telechargement
-
 
48
			$taille=filesize($importFile);
-
 
49
			header("Content-Type: application/x-download");
-
 
50
			header("Content-Length: $taille");
-
 
51
			header("Content-Disposition: attachment; filename=\"$importFileName.txt\"");
-
 
52
			header("Cache-Control: private, max-age=0, must-revalidate");
-
 
53
			header("Pragma: public");
24
	exit('FILE_NOT_FOUND');
54
			header("Content-Type: application/force-download; filename=\"$importFileName.txt\"");
-
 
55
			ini_set("zlib.output_compression","0");
-
 
56
			readfile($importFile);
-
 
57
			exit();
-
 
58
		}elseif ($format=="pdf"){
-
 
59
			$pdf=new fichePDF();
-
 
60
			$pdf->lirefichier($importFile);
-
 
61
			$pdf->Output($importFileName.".pdf","D");
-
 
62
		}else{
-
 
63
			getImportFile($importFileName,"txt");
-
 
64
		}
-
 
65
	} else {
-
 
66
		return false;
-
 
67
	}
-
 
68
}
25
}
-
 
26
 
-
 
27
if ($format === 'txt') {
-
 
28
	header('Content-Type: application/x-download');
-
 
29
	header('Content-Length: '.filesize($filePath));
-
 
30
	header('Content-Disposition: attachment; filename="'.$filename.'.txt"');
-
 
31
	header('Content-Type: application/force-download; filename="'.$filename.'.txt"');
-
 
32
	header('Cache-Control: private, max-age=0, must-revalidate');
-
 
33
	header('Pragma: public');
69
if (isset($_GET['file']) && $_GET['file']){
34
	ini_set('zlib.output_compression', '0');
-
 
35
	readfile($filePath);
70
	if (isset($_GET['format'])){
36
} else if ($format === 'pdf') {
-
 
37
	// Convert to PDF
-
 
38
	$html  = '<!doctype html><html><head><meta charset="utf-8"></head><body><pre>';
-
 
39
	$html .= file_get_contents($filePath);
-
 
40
	$html .= '</pre></body></html>';
-
 
41
	file_put_contents("$filePath.pdf.html", $html);
-
 
42
 
71
		$format = $_GET['format'];
43
	$command = 'wkhtmltopdf' . ' --quiet --disable-smart-shrinking --footer-font-size 8 --footer-left "ALCASAR" --footer-center "[page] / [toPage]" --footer-right "' . date('Y-m-d H:i:s') . '" ' . escapeshellarg("$filePath.pdf.html") . ' ' . escapeshellarg("$filePath.pdf");
72
	} else {
44
	$output;
73
		$format = "txt";
45
	$exitCode;
-
 
46
	exec($command, $output, $exitCode);
74
	}
47
 
-
 
48
	header('Content-Type: application/pdf');
75
	if (getImportFile($_GET['file'], $format)){
49
	header('Content-Length: '.filesize("$filePath.pdf"));
-
 
50
	header('Content-Disposition: attachment; filename="'.$filename.'.pdf"');
76
		//fichier en cour de téléchargement
51
	header('Cache-Control: private, max-age=0, must-revalidate');
77
	} else {
52
	header('Pragma: public');
78
		echo "erreur 2 ";
53
	readfile("$filePath.pdf");
79
	}
54
 
80
} else {
55
	unlink("$filePath.pdf");
81
	echo "erreur 1 ";
56
	unlink("$filePath.pdf.html");
82
}
57
}
83
?>
-