1,11 → 1,19 |
<?php |
|
/** |
* @category PHP |
* @package jrest |
* @author Raphaël Droz <raphael@tela-botania.org> |
* @copyright 2013 Tela-Botanica |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt> |
*/ |
|
// Include the main TCPDF library (search for installation path). |
date_default_timezone_set("Europe/Paris"); |
require_once('tcpdf_config.php'); |
require_once('tcpdf/tcpdf.php'); |
|
//set_time_limit(6); |
Class GenerateurPDF { |
|
public $pdf; |
205,54 → 213,97 |
|
// 3ème paramètre = '' equivalent à $this->pdf->getX() |
// 4ème paramètre = '' equivalent à $this->pdf->getY() |
|
// référentiel |
$this->pdf->writeHTMLCell($w = $width, '', '', '', |
$html = '<strong>Référentiel</strong> : ' . $obs['nom_referentiel'], |
$border = 'LTR', $ln = 1, $fill = false, $reset = true, $align = 'L', $autopadding = true); |
|
// famille |
$this->pdf->writeHTMLCell($w = $width - 20, '', '', '', |
$this->pdf->writeHTMLCell($w = $width, '', '', '', |
$html = '<strong>Famille</strong> : ' . $obs['famille'], |
$border = 'LT', $ln = 0, $fill = false, $reset = true, $align = 'L', $autopadding = true); |
$border = 'LR', $ln = 1, $fill = false, $reset = true, $align = 'L', $autopadding = true); |
|
|
// taxon |
$nom = $obs['nom_ret']; |
if($obs['certitude'] && stripos($obs['certitude'], 'certain') === false) { |
$nom .= ' ' . $obs['certitude']; |
} |
$this->pdf->writeHTMLCell($w = $width, $lh * 3.5, '', '', |
//$html = '<strong>Espèce</strong> : ' . self::elude('Espèce : ', $obs['nom_ret'], 2), |
$html = $this->elude('<strong>Taxon</strong> : ' . $nom, 3), |
$border = 'LR', $ln = 1, $fill = false, $reset = true, $align = 'L', $autopadding = true); |
|
// collecteur |
// TODO: pseudo |
$limite_nom = 26; |
$prenom = $obs['prenom_utilisateur']; |
if(mb_strlen($prenom . ' ' . $obs['nom_utilisateur'], 'UTF-8') > $limite_nom) { |
$prenom = mb_substr($prenom, 0, 26 - mb_strlen($obs['nom_utilisateur'], 'UTF-8') - 1 /* espace */ - 1 /* … */, 'UTF-8') . '…'; |
//var_dump($prenom);die; |
} |
$this->pdf->writeHTMLCell($w = $width - 25, '', '', '', |
$html = '<strong>Collecteur</strong> : ' . $prenom . ' ' . $obs['nom_utilisateur'], |
$border = 'L', $ln = 0, $fill = false, $reset = true, $align = 'L', $autopadding = true); |
|
// N°: TODO: writeHTMLCell() semble bugger |
$this->pdf->Cell($w = 20, '', |
$this->pdf->Cell($w = 25, '', |
$txt = 'N° : ' . $obs['id_observation'], //. sprintf("%04d", $obs['ordre']) |
$border = 'TR', $ln = 1, $align = 'L', $fill = false, $link = false, $stretch = 1, $ignore_min_height = false, $calign = 'T', $valign = 'M'); |
/*$this->pdf->writeHTMLCell($w = 20, '', '', '', |
$border = 'R', $ln = 1, $align = 'R', $fill = false, $link = false, $stretch = 1, $ignore_min_height = false, $calign = 'T', $valign = 'M'); |
/*$this->pdf->writeHTMLCell($w = 30, '', '', '', |
$html = '<strong>N°</strong> : ' . $obs['id_observation'], //. sprintf("%04d", $obs['ordre']), |
$border = 'TR', $ln = 1, $fill = true, $reset = true, $align = 'R', $autopadding = true);*/ |
$border = 'R', $ln = 1, $fill = true, $reset = true, $align = 'L', $autopadding = true);*/ |
|
// espece |
$this->pdf->writeHTMLCell($w = $width, $lh * 2.5, '', '', |
//$html = '<strong>Espèce</strong> : ' . self::elude('Espèce : ', $obs['nom_ret'], 2), |
$html = $this->elude('<strong>Espèce</strong> : ' . $obs['nom_ret'], 2), |
$border = 'RL', $ln = 1, $fill = false, $reset = true, $align = 'L', $autopadding = true); |
// localité |
// TODO: département |
// TEST: Corse (2A, 2B) |
$info_dep = "<strong>Localité</strong> : %s"; |
$donnees_dep = array($obs['zone_geo']); |
if($obs['ce_zone_geo']) { |
$info_dep .= " (%s)"; |
if(strpos($obs['ce_zone_geo'], 'INSEE') !== false) $donnees_dep[] = preg_replace('/^[^\d]*(\d\d).*/', '\1', $obs['ce_zone_geo']); |
else $donnees_dep[] = $obs['ce_zone_geo']; |
} |
|
// collecteur |
$this->pdf->writeHTMLCell($w = $width, '', '', '', |
$html = '<strong>Collecteur</strong> : ' . $obs['prenom_utilisateur'] . ' ' . $obs['nom_utilisateur'], |
$border = 'RL', $ln = 1, $fill = false, $reset = true, $align = 'L', $autopadding = true); |
|
// localité |
$info_loc = "%s, %s"; |
$donnees_loc = array($obs['lieudit'], $obs['station']); |
if($obs['milieu']) { |
$info_loc .= " [%s]"; |
$donnees_loc[] = $obs['milieu']; |
} |
$this->pdf->writeHTMLCell($w = $width, $lh * 3.5, '', '', |
//$html = "<strong>Localité</strong> : " . |
//self::elude('Localité : ', sprintf("%s (%s)\n%s, %s [%s]", $obs['zone_geo'], $obs['ce_zone_geo'], $obs['lieudit'], $obs['station'], $obs['milieu'] ), 3), |
// $html = self::elude(sprintf("<strong>Localité</strong> : %s (%s)\n%s, %s [%s]", $obs['zone_geo'], $obs['ce_zone_geo'], $obs['lieudit'], $obs['station'], $obs['milieu']), 3), |
$html = $this->elude(sprintf("<strong>Localité</strong> : %s (%s)", $obs['zone_geo'], $obs['ce_zone_geo']), 2) . "\n" . |
$this->elude(sprintf("%s, %s [%s]", $obs['lieudit'], $obs['station'], $obs['milieu']), 2), |
$border = 'RL', $ln = 1, $fill = false, $reset = true, $align = 'L', $autopadding = true); |
$html = $this->elude(vsprintf($info_dep, $donnees_dep), 2) . "\n" . |
$this->elude(vsprintf($info_loc, $donnees_loc), 2), |
$border = 'LR', $ln = 1, $fill = false, $reset = true, $align = 'L', $autopadding = true); |
|
// lon/lat |
// lon/lat/alt |
$info_geo = ''; |
$donnees = array(); |
if($obs['latitude'] && $obs['longitude']) { |
$info_geo .= "%.5f N / %.5f E"; |
array_push($donnees, $obs['latitude'], $obs['longitude']); |
} |
if($obs['altitude']) { |
$info_geo .= ", %dm"; |
array_push($donnees, $obs['altitude']); |
} |
$this->pdf->writeHTMLCell($w = $width, '', '', '', |
$html = sprintf("<strong>Latitude / Longitude</strong> : %s / %s", $obs['latitude'], $obs['longitude']), |
$border = 'RL', $ln = 1, $fill = false, $reset = true, $align = 'L', $autopadding = true); |
$html = vsprintf("<strong>Lat. / Lon. , Alt.</strong> : " . $info_geo, $donnees), |
$border = 'LR', $ln = 1, $fill = false, $reset = true, $align = 'L', $autopadding = true); |
|
// commentaire |
$this->pdf->writeHTMLCell($w = $width, $lh * 4.5, '', '', |
//$html = '<strong>Observation</strong> : ' . self::elude('Observation : ', $obs['commentaire']), |
$html = self::elude('<strong>Observation</strong> : ' . $obs['commentaire'], 4), |
$border = 'RL', $ln = 1, $fill = false, $reset = true, $align = 'L', $autopadding = true); |
$border = 'LR', $ln = 1, $fill = false, $reset = true, $align = 'L', $autopadding = true); |
|
// date |
$this->pdf->writeHTMLCell($w = $width, '', '', '', |
$html = '<strong>Date</strong> : ' . strftime("%d/%m/%Y", strtotime($obs['date_observation'])), |
$html = '<strong>Date de récolte</strong> : ' . strftime("%d/%m/%Y", strtotime($obs['date_observation'])), |
$border = 'LBR', $ln = 1, $fill = false, $reset = true, $align = 'R', $autopadding = true); |
|
} |
298,7 → 349,7 |
function elude_bis($intitule, $commentaire, $lignes = 3) { |
// TODO: GetLineWidth, GetCharWidth() |
$limite = $lignes /* lignes */ * 43 /* caractères */ - strlen($intitule); |
if(mb_strlen($commentaire) < $limite) return $commentaire; |
if(mb_strlen($commentaire, 'UTF-8') < $limite) return $commentaire; |
return mb_substr($commentaire, 0, $limite - 2) . '…'; |
} |
|