Better way to setup business card PDF genertion.
This commit is contained in:
parent
fc77937d11
commit
e40b8d9602
@ -21,18 +21,14 @@
|
||||
/**
|
||||
* \file htdocs/adherents/cartes/carte.php
|
||||
* \ingroup adherent
|
||||
* \brief Page de creation d'une carte PDF
|
||||
* \brief Page to output members business cards
|
||||
* \version $Id$
|
||||
*/
|
||||
|
||||
require("./pre.inc.php");
|
||||
|
||||
require_once(DOL_DOCUMENT_ROOT.'/lib/pdf.lib.php');
|
||||
require_once(DOL_DOCUMENT_ROOT.'/includes/fpdf/fpdfi/fpdi_protection.php');
|
||||
|
||||
require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/adherents/adherent.class.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/includes/modules/member/PDF_card.class.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/includes/modules/member/cards/modules_cards.php");
|
||||
|
||||
|
||||
// liste des patterns remplacable dans le texte a imprimer
|
||||
@ -48,39 +44,27 @@ $patterns = array (
|
||||
'/%PAYS%/',
|
||||
'/%EMAIL%/',
|
||||
'/%NAISS%/',
|
||||
'/%PHOTO%/',
|
||||
'/%TYPE%/',
|
||||
'/%ID%/',
|
||||
'/%ANNEE%/'
|
||||
);
|
||||
'/%ANNEE%/', // For backward compatibility
|
||||
'/%YEAR%/',
|
||||
'/%MONTH%/',
|
||||
'/%DAY%/'
|
||||
);
|
||||
|
||||
|
||||
$dir = $conf->adherent->dir_temp;
|
||||
$file = $dir . "/tmpcard.pdf";
|
||||
|
||||
if (! file_exists($dir))
|
||||
{
|
||||
if (create_exdir($dir) < 0)
|
||||
{
|
||||
$this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
$pdf = new PDF_card('CARD', 1, 1);
|
||||
|
||||
$pdf->Open();
|
||||
$pdf->AddPage();
|
||||
|
||||
// Choix de l'annee d'impression ou annee courante.
|
||||
if (!isset($annee)){
|
||||
$now = getdate();
|
||||
$annee=$now['year'];
|
||||
}
|
||||
$now = dol_now();
|
||||
$year=dol_print_date($now,'%Y');
|
||||
$month=dol_print_date($now,'%m');
|
||||
$day=dol_print_date($now,'%d');
|
||||
|
||||
|
||||
$arrayofmembers=array();
|
||||
|
||||
// requete en prenant que les adherents a jour de cotisation
|
||||
$sql = "SELECT d.rowid, d.prenom, d.nom, d.login, d.societe, d.datefin,";
|
||||
$sql.= " d.adresse, d.cp, d.ville, d.naiss, d.email, d.photo,";
|
||||
$sql.= " d.adresse, d.cp, d.ville, d.naiss, d.email,";
|
||||
$sql.= " t.libelle as type,";
|
||||
$sql.= " p.libelle as pays";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."adherent_type as t, ".MAIN_DB_PREFIX."adherent as d";
|
||||
@ -112,45 +96,35 @@ if ($result)
|
||||
$objp->pays,
|
||||
$objp->email,
|
||||
$objp->naiss,
|
||||
$objp->photo,
|
||||
$objp->type,
|
||||
$objp->rowid,
|
||||
$annee
|
||||
$year,
|
||||
$year,
|
||||
$month,
|
||||
$day
|
||||
);
|
||||
|
||||
// imprime le texte specifique sur la carte
|
||||
$pdf->Add_PDF_card(preg_replace ($patterns, $replace, $conf->global->ADHERENT_CARD_TEXT),
|
||||
preg_replace ($patterns, $replace, $conf->global->ADHERENT_CARD_HEADER_TEXT),
|
||||
preg_replace ($patterns, $replace, $conf->global->ADHERENT_CARD_FOOTER_TEXT), $langs,
|
||||
preg_replace ($patterns, $replace, $conf->global->ADHERENT_CARD_TEXT_RIGHT));
|
||||
$textleft=preg_replace ($patterns, $replace, $conf->global->ADHERENT_CARD_TEXT);
|
||||
$textheader=preg_replace ($patterns, $replace, $conf->global->ADHERENT_CARD_HEADER_TEXT);
|
||||
$textfooter=preg_replace ($patterns, $replace, $conf->global->ADHERENT_CARD_FOOTER_TEXT);
|
||||
$textright=preg_replace ($patterns, $replace, $conf->global->ADHERENT_CARD_TEXT_RIGHT);
|
||||
|
||||
$arrayofmembers[]=array('textleft'=>$textleft,
|
||||
'textheader'=>$textheader,
|
||||
'textfooter'=>$textfooter,
|
||||
'textright'=>$textright,
|
||||
'id'=>$objp->rowid);
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
// Output to http strem
|
||||
$pdf->Output($file);
|
||||
|
||||
if (! empty($conf->global->MAIN_UMASK))
|
||||
@chmod($file, octdec($conf->global->MAIN_UMASK));
|
||||
|
||||
$db->close();
|
||||
|
||||
clearstatcache();
|
||||
|
||||
$attachment=true;
|
||||
if (! empty($conf->global->MAIN_DISABLE_FORCE_SAVEAS)) $attachment=false;
|
||||
$filename='tmpcards.pdf';
|
||||
$type=dol_mimetype($filename);
|
||||
|
||||
if ($encoding) header('Content-Encoding: '.$encoding);
|
||||
if ($type) header('Content-Type: '.$type);
|
||||
if ($attachment) header('Content-Disposition: attachment; filename="'.$filename.'"');
|
||||
else header('Content-Disposition: inline; filename="'.$filename.'"');
|
||||
|
||||
// Ajout directives pour resoudre bug IE
|
||||
header('Cache-Control: Public, must-revalidate');
|
||||
header('Pragma: public');
|
||||
|
||||
readfile($file);
|
||||
// Build and output PDF
|
||||
$result=members_card_pdf_create($db, $arrayofmembers, '', $outputlangs);
|
||||
if ($result <= 0)
|
||||
{
|
||||
dol_print_error($db,$result);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -226,8 +226,9 @@ print_fiche_titre($langs->trans("MembersCards"),'','');
|
||||
form_constantes($constantes);
|
||||
|
||||
print '*'.$langs->trans("FollowingConstantsWillBeSubstituted").'<br>';
|
||||
print '%DOL_MAIN_URL_ROOT%, %ID%, %PRENOM%, %NOM%, %LOGIN%, %PASSWORD%,';
|
||||
print '%SOCIETE%, %ADRESSE%, %CP%, %VILLE%, %PAYS%, %EMAIL%, %NAISS%, %PHOTO%, %TYPE%,';
|
||||
print '%DOL_MAIN_URL_ROOT%, %ID%, %PRENOM%, %NOM%, %LOGIN%, %PASSWORD%, ';
|
||||
print '%SOCIETE%, %ADRESSE%, %CP%, %VILLE%, %PAYS%, %EMAIL%, %NAISS%, %PHOTO%, %TYPE%, ';
|
||||
print '%YEAR%, %MONTH%, %DAY%, %LOGO%, %PHOTO%';
|
||||
//print '%INFOS%'; Deprecated
|
||||
print '<br>';
|
||||
|
||||
@ -342,7 +343,7 @@ function form_constantes($tableau)
|
||||
}
|
||||
else if ($obj->type == 'texte')
|
||||
{
|
||||
print '<textarea class="flat" name="constvalue" cols="35" rows="5" wrap="soft">';
|
||||
print '<textarea class="flat" name="constvalue" cols="35" rows="5" wrap="soft">'."\n";
|
||||
print $obj->value;
|
||||
print "</textarea>\n";
|
||||
print '</td><td>';
|
||||
|
||||
@ -231,7 +231,7 @@ class pdf_standard {
|
||||
|
||||
|
||||
// On imprime une etiquette
|
||||
function Add_PDF_card(&$pdf,$textleft,$header='',$footer='',$outputlangs,$textright='')
|
||||
function Add_PDF_card(&$pdf,$textleft,$header='',$footer='',$outputlangs,$textright='',$idmember)
|
||||
{
|
||||
global $mysoc,$conf,$langs;
|
||||
|
||||
@ -243,9 +243,11 @@ class pdf_standard {
|
||||
$_PosX = $this->_Margin_Left+($this->_COUNTX*($this->_Width+$this->_X_Space));
|
||||
$_PosY = $this->_Margin_Top+($this->_COUNTY*($this->_Height+$this->_Y_Space));
|
||||
|
||||
// Define logo
|
||||
$logo=$conf->mycompany->dir_output.'/logos/'.$mysoc->logo;
|
||||
if (! is_readable($logo))
|
||||
{
|
||||
$logo='';
|
||||
if (! empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small))
|
||||
{
|
||||
$logo=$conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small;
|
||||
@ -256,23 +258,23 @@ class pdf_standard {
|
||||
}
|
||||
}
|
||||
|
||||
// Define photo
|
||||
$dir=$conf->adherent->dir_output;
|
||||
$file=$idmember.".jpg";
|
||||
$photo=$dir.'/'.$file;
|
||||
if (! is_readable($photo)) $photo='';
|
||||
|
||||
if ($this->_Avery_Name == "CARD")
|
||||
{
|
||||
$this->Tformat=$this->_Avery_Labels["CARD"];
|
||||
//$this->_Pointille($pdf,$_PosX,$_PosY,$_PosX+$this->_Width,$_PosY+$this->_Height,0.3,25);
|
||||
$this->_Croix($pdf,$_PosX,$_PosY,$_PosX+$this->_Width,$_PosY+$this->_Height,0.1,10);
|
||||
if($this->Tformat['fond'] != '' and file_exists($this->Tformat['fond'])){
|
||||
$this->image($this->Tformat['fond'],$_PosX,$_PosY,$this->_Width,$this->_Height);
|
||||
}
|
||||
/*if($this->Tformat['logo1'] != '' and file_exists($this->Tformat['logo1'])){
|
||||
$this->image($this->Tformat['logo1'],$_PosX+$this->_Width-21,$_PosY+1,20,20);
|
||||
}
|
||||
if($this->Tformat['logo2'] != '' and file_exists($this->Tformat['logo2'])){
|
||||
$this->image($this->Tformat['logo2'],$_PosX+$this->_Width-21,$_PosY+25,20,20);
|
||||
}*/
|
||||
|
||||
// Top
|
||||
if ($header!=''){
|
||||
$pdf->SetDrawColor(128,128,128);
|
||||
$pdf->Line($_PosX, $_PosY+$this->_Line_Height+1, $_PosX+$this->_Width, $_PosY+$this->_Line_Height+1);
|
||||
$pdf->SetDrawColor(0,0,0);
|
||||
$pdf->SetXY($_PosX, $_PosY+1);
|
||||
$pdf->Cell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($header),0,1,'C');
|
||||
}
|
||||
@ -280,7 +282,8 @@ class pdf_standard {
|
||||
// Center
|
||||
if ($textright=='') // Only a left part
|
||||
{
|
||||
if ($textleft == '%LOGO%') $this->Image($logo,$_PosX+$this->_Width-21,$_PosY+3+$this->_Line_Height,20);
|
||||
if ($textleft == '%LOGO%' && $logo) $this->Image($logo,$_PosX+2,$_PosY+3+$this->_Line_Height,20);
|
||||
else if ($textleft == '%PHOTO%' && $photo) $this->Image($photo,$_PosX+2,$_PosY+3+$this->_Line_Height,20);
|
||||
else
|
||||
{
|
||||
$pdf->SetXY($_PosX+3, $_PosY+3+$this->_Line_Height);
|
||||
@ -289,30 +292,33 @@ class pdf_standard {
|
||||
}
|
||||
else if ($textleft!='' && $textright!='') //
|
||||
{
|
||||
if ($textleft == '%LOGO%')
|
||||
if ($textleft == '%LOGO%' || $textleft == '%PHOTO%')
|
||||
{
|
||||
$pdf->Image($logo,$_PosX+$this->_Width-21,$_PosY+3+$this->_Line_Height,20);
|
||||
$pdf->SetXY($_PosX+22, $_PosY+3+$this->_Line_Height);
|
||||
$pdf->MultiCell($this->_Width-20, $this->_Line_Height, $outputlangs->convToOutputCharset($textright),0,'R');
|
||||
if ($textleft == '%LOGO%' && $logo) $pdf->Image($logo,$_PosX+2,$_PosY+3+$this->_Line_Height,20);
|
||||
else if ($textleft == '%PHOTO%' && $photo) $pdf->Image($photo,$_PosX+2,$_PosY+3+$this->_Line_Height,20);
|
||||
$pdf->SetXY($_PosX+21, $_PosY+3+$this->_Line_Height);
|
||||
$pdf->MultiCell($this->_Width-22, $this->_Line_Height, $outputlangs->convToOutputCharset($textright),0,'R');
|
||||
}
|
||||
else if ($textright == '%LOGO%')
|
||||
else if ($textright == '%LOGO%' || $textright == '%PHOTO%')
|
||||
{
|
||||
$pdf->Image($logo,$_PosX+$this->_Width-21,$_PosY+3+$this->_Line_Height,20);
|
||||
if ($textright == '%LOGO%' && $logo) $pdf->Image($logo,$_PosX+$this->_Width-21,$_PosY+3+$this->_Line_Height,20);
|
||||
else if ($textright == '%PHOTO%' && $photo) $pdf->Image($photo,$_PosX+$this->_Width-21,$_PosY+3+$this->_Line_Height,20);
|
||||
$pdf->SetXY($_PosX+2, $_PosY+3+$this->_Line_Height);
|
||||
$pdf->MultiCell($this->_Width-22, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft));
|
||||
}
|
||||
else
|
||||
{
|
||||
$pdf->SetXY($_PosX+round($this->_Width/2), $_PosY+3+$this->_Line_Height);
|
||||
$pdf->MultiCell(round($this->_Width/2)-2, $this->_Line_Height, $outputlangs->convToOutputCharset($textright),0,'R');
|
||||
$pdf->SetXY($_PosX+2, $_PosY+3+$this->_Line_Height);
|
||||
$pdf->MultiCell(round($this->_Width/2), $this->_Line_Height, $outputlangs->convToOutputCharset($textleft));
|
||||
$pdf->SetXY($_PosX+round($this->_Width/2), $_PosY+3+$this->_Line_Height);
|
||||
$pdf->MultiCell(round($this->_Width/2)-2, $this->_Line_Height, $outputlangs->convToOutputCharset($textright),0,'R');
|
||||
}
|
||||
|
||||
}
|
||||
else // Only a right part
|
||||
{
|
||||
if ($textright == '%LOGO%') $this->Image($logo,$_PosX+$this->_Width-21,$_PosY+1,20);
|
||||
if ($textright == '%LOGO%' && $logo) $this->Image($logo,$_PosX+$this->_Width-21,$_PosY+1,20);
|
||||
else if ($textright == '%PHOTO%' && $photo) $this->Image($photo,$_PosX+$this->_Width-21,$_PosY+1,20);
|
||||
else
|
||||
{
|
||||
$pdf->SetXY($_PosX+2, $_PosY+3+$this->_Line_Height);
|
||||
@ -323,6 +329,9 @@ class pdf_standard {
|
||||
// Bottom
|
||||
if ($footer!='')
|
||||
{
|
||||
$pdf->SetDrawColor(128,128,128);
|
||||
$pdf->Line($_PosX, $_PosY+$this->_Height-$this->_Line_Height-2, $_PosX+$this->_Width, $_PosY+$this->_Height-$this->_Line_Height-2);
|
||||
$pdf->SetDrawColor(0,0,0);
|
||||
$pdf->SetXY($_PosX, $_PosY+$this->_Height-$this->_Line_Height-1);
|
||||
$pdf->Cell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($footer),0,1,'C');
|
||||
}
|
||||
@ -510,7 +519,7 @@ class pdf_standard {
|
||||
foreach($arrayofmembers as $val)
|
||||
{
|
||||
// imprime le texte specifique sur la carte
|
||||
$this->Add_PDF_card($pdf,$val['textleft'],$val['textheader'],$val['textfooter'],$langs,$val['textright']);
|
||||
$this->Add_PDF_card($pdf,$val['textleft'],$val['textheader'],$val['textfooter'],$langs,$val['textright'],$val['id']);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user