From cb52af4f476463b415117695f06f21bae56c8b3c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 2 Sep 2013 02:14:16 +0200 Subject: [PATCH] Qual: Make code more generic --- htdocs/adherents/cartes/carte.php | 5 +-- .../modules/member/doc/pdf_standard.class.php | 37 ++++++++++++------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/htdocs/adherents/cartes/carte.php b/htdocs/adherents/cartes/carte.php index e60a76bd936..ab964100c04 100644 --- a/htdocs/adherents/cartes/carte.php +++ b/htdocs/adherents/cartes/carte.php @@ -107,8 +107,7 @@ if ((! empty($foruserid) || ! empty($foruserlogin) || ! empty($mode)) && ! $mesg '%MONTH%'=>$month, '%DAY%'=>$day, '%DOL_MAIN_URL_ROOT%'=>DOL_MAIN_URL_ROOT, - '%SERVER%'=>"http://".$_SERVER["SERVER_NAME"]."/", - '%SOCIETE%'=>$objp->company + '%SERVER%'=>"http://".$_SERVER["SERVER_NAME"]."/" ); complete_substitutions_array($substitutionarray, $langs); @@ -204,7 +203,7 @@ if ((! empty($foruserid) || ! empty($foruserlogin) || ! empty($mode)) && ! $mesg dol_print_error($db); } - if (! $mesg) + if (! $mesg) { $db->close(); exit; diff --git a/htdocs/core/modules/member/doc/pdf_standard.class.php b/htdocs/core/modules/member/doc/pdf_standard.class.php index 8789c246307..0b0214196d0 100644 --- a/htdocs/core/modules/member/doc/pdf_standard.class.php +++ b/htdocs/core/modules/member/doc/pdf_standard.class.php @@ -122,10 +122,10 @@ class pdf_standard * @param Translate $outputlangs Output langs * @param string $textright Text right * @param int $idmember Id member - * @param string $photomember Photo member + * @param string $photo Photo member * @return void */ - function Add_PDF_card(&$pdf,$textleft,$header,$footer,$outputlangs,$textright='',$idmember=0,$photomember='') + function Add_PDF_card(&$pdf,$textleft,$header,$footer,$outputlangs,$textright='',$idmember=0,$photo='') { global $mysoc,$conf,$langs; @@ -154,9 +154,9 @@ class pdf_standard // Define photo $dir=$conf->adherent->dir_output; - $file=get_exdir($idmember,2).'photos/'.$photomember; + $file=get_exdir($idmember,2).'photos/'.$photo; $photo=$dir.'/'.$file; - if (empty($photomember) || ! is_readable($photo)) $photo=''; + if (empty($photo) || ! is_readable($photo)) $photo=''; // Define background image $backgroundimage=''; @@ -408,12 +408,13 @@ class pdf_standard /** * Function to build PDF on disk, then output on HTTP strem. * - * @param array $arrayofmembers Array of members informations + * @param array $arrayofrecords Array of record informations (array('textleft'=>,'textheader'=>, ...'id'=>,'photo'=>) * @param Translate $outputlangs Lang object for output language * @param string $srctemplatepath Full path of source filename for generator using a template file + * @param string $mode Tell if doc module is called for 'member, ... * @return int 1=OK, 0=KO */ - function write_file($arrayofmembers,$outputlangs,$srctemplatepath) + function write_file($arrayofrecords,$outputlangs,$srctemplatepath,$mode='member') { global $user,$conf,$langs,$mysoc,$_Avery_Labels; @@ -433,9 +434,20 @@ class pdf_standard $outputlangs->load("members"); $outputlangs->load("admin"); + if (empty($mode) || $mode == 'member') + { + $title=$outputlangs->transnoentities('MembersCards'); + $keywords=$outputlangs->transnoentities('MembersCards')." ".$outputlangs->transnoentities("Foundation")." ".$outputlangs->convToOutputCharset($mysoc->name); + $outputdir=$conf->adherent->dir_temp; + } + else + { + dol_print_error('','Bad value for $mode'); + return -1; + } - $dir = (empty($outputdir)?$conf->adherent->dir_temp:$outputdir); - $filename='tmp_cards.pdf'; + $dir = $outputdir; + $filename = 'tmp_cards.pdf'; $file = $dir."/".$filename; if (! file_exists($dir)) @@ -456,11 +468,11 @@ class pdf_standard } $pdf->SetFont(pdf_getPDFFont($outputlangs)); - $pdf->SetTitle($outputlangs->transnoentities('MembersCards')); - $pdf->SetSubject($outputlangs->transnoentities("MembersCards")); + $pdf->SetTitle($title); + $pdf->SetSubject($title); $pdf->SetCreator("Dolibarr ".DOL_VERSION); $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs))); - $pdf->SetKeyWords($outputlangs->transnoentities('MembersCards')." ".$outputlangs->transnoentities("Foundation")." ".$outputlangs->convToOutputCharset($mysoc->name)); + $pdf->SetKeyWords($keywords); if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false); $pdf->SetMargins(0,0); @@ -482,7 +494,7 @@ class pdf_standard // Add each record - foreach($arrayofmembers as $val) + foreach($arrayofrecords as $val) { // imprime le texte specifique sur la carte $this->Add_PDF_card($pdf,$val['textleft'],$val['textheader'],$val['textfooter'],$langs,$val['textright'],$val['id'],$val['photo']); @@ -499,7 +511,6 @@ class pdf_standard @chmod($file, octdec($conf->global->MAIN_UMASK)); - // Output to http stream clearstatcache();