Choix of label format is in a combo list

This commit is contained in:
Laurent Destailleur 2008-05-04 01:39:08 +00:00
parent 6e8e9e81b3
commit 52cb86b103
3 changed files with 97 additions and 67 deletions

View File

@ -16,9 +16,6 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
* $Source$
*/ */
/* Inspire de PDF_Label /* Inspire de PDF_Label
@ -64,7 +61,7 @@
\author Laurent Passebecq \author Laurent Passebecq
\author Rodolphe Quiedville \author Rodolphe Quiedville
\author Jean Louis Bergamo. \author Jean Louis Bergamo.
\version $Revision$ \version $Id$
*/ */
require_once(FPDFI_PATH.'fpdi_protection.php'); require_once(FPDFI_PATH.'fpdi_protection.php');
@ -74,7 +71,6 @@ require_once(FPDFI_PATH.'fpdi_protection.php');
\class PDF_card \class PDF_card
\brief Classe afin d'éditer au format PDF des étiquettes au format Avery ou personnalisé \brief Classe afin d'éditer au format PDF des étiquettes au format Avery ou personnalisé
*/ */
class PDF_card extends FPDF { class PDF_card extends FPDF {
// Propriétés privées // Propriétés privées
@ -96,8 +92,8 @@ class PDF_card extends FPDF {
var $_COUNTY = 1; var $_COUNTY = 1;
var $_First = 1; var $_First = 1;
// Listing of labels size // Listing of labels size
var $_Avery_Labels = array ( var $_Avery_Labels = array (
'5160'=>array('name'=>'5160', '5160'=>array('name'=>'5160',
'paper-size'=>'letter', 'paper-size'=>'letter',
'metric'=>'mm', 'metric'=>'mm',
@ -211,45 +207,20 @@ class PDF_card extends FPDF {
'fond'=>'fond.jpg') 'fond'=>'fond.jpg')
); );
// convert units (in to mm, mm to in)
// $src and $dest must be 'in' or 'mm'
function _Convert_Metric ($value, $src, $dest) {
if ($src != $dest) {
$tab['in'] = 39.37008;
$tab['mm'] = 1000;
return $value * $tab[$dest] / $tab[$src];
} else {
return $value;
}
}
// Give the height for a char size given.
function _Get_Height_Chars($pt) {
// Tableau de concordance entre la hauteur des caractères et de l'espacement entre les lignes
$_Table_Hauteur_Chars = array(6=>2, 7=>2.5, 8=>3, 9=>4, 10=>5, 11=>6, 12=>7, 13=>8, 14=>9, 15=>10);
if (in_array($pt, array_keys($_Table_Hauteur_Chars))) {
return $_Table_Hauteur_Chars[$pt];
} else {
return 100; // There is a prob..
}
}
function _Set_Format($format) { /**
$this->_Metric = $format['metric']; * Constructor
$this->_Avery_Name = $format['name']; *
$this->_Margin_Left = $this->_Convert_Metric ($format['marginLeft'], $this->_Metric, $this->_Metric_Doc); * @param unknown_type $format Avery format of label paper. For example 5160, 5161, 5162, 5163, 5164, 8600, L7163
$this->_Margin_Top = $this->_Convert_Metric ($format['marginTop'], $this->_Metric, $this->_Metric_Doc); * @param unknown_type $posX
$this->_X_Space = $this->_Convert_Metric ($format['SpaceX'], $this->_Metric, $this->_Metric_Doc); * @param unknown_type $posY
$this->_Y_Space = $this->_Convert_Metric ($format['SpaceY'], $this->_Metric, $this->_Metric_Doc); * @param unknown_type $unit
$this->_X_Number = $format['NX']; * @return PDF_card
$this->_Y_Number = $format['NY']; */
$this->_Width = $this->_Convert_Metric ($format['width'], $this->_Metric, $this->_Metric_Doc); function PDF_card ($format, $posX=1, $posY=1, $unit='mm')
$this->_Height = $this->_Convert_Metric ($format['height'], $this->_Metric, $this->_Metric_Doc); {
$this->Set_Char_Size( $format['font-size']); if (is_array($format)) {
}
function PDF_card ($format, $posX=1, $posY=1, $unit='mm') {
if (is_array($format)) {
// Si c'est un format personnel alors on maj les valeurs // Si c'est un format personnel alors on maj les valeurs
$Tformat = $format; $Tformat = $format;
} else { } else {
@ -271,6 +242,7 @@ class PDF_card extends FPDF {
$this->_Set_Format($Tformat); $this->_Set_Format($Tformat);
} }
//Méthode qui permet de modifier la taille des caractères //Méthode qui permet de modifier la taille des caractères
// Cela modiera aussi l'espace entre chaque ligne // Cela modiera aussi l'espace entre chaque ligne
function Set_Char_Size($pt) { function Set_Char_Size($pt) {
@ -281,6 +253,7 @@ class PDF_card extends FPDF {
} }
} }
// On imprime une étiqette // On imprime une étiqette
function Add_PDF_card($texte,$header='',$footer='') { function Add_PDF_card($texte,$header='',$footer='') {
// We are in a new page, then we must add a page // We are in a new page, then we must add a page
@ -336,6 +309,7 @@ class PDF_card extends FPDF {
} }
} }
function _Pointille($x1=0,$y1=0,$x2=210,$y2=297,$epaisseur=1,$nbPointilles=15) function _Pointille($x1=0,$y1=0,$x2=210,$y2=297,$epaisseur=1,$nbPointilles=15)
{ {
$this->SetLineWidth($epaisseur); $this->SetLineWidth($epaisseur);
@ -389,5 +363,43 @@ class PDF_card extends FPDF {
//$this->Color('#000000'); //$this->Color('#000000');
} }
// convert units (in to mm, mm to in)
// $src and $dest must be 'in' or 'mm'
function _Convert_Metric ($value, $src, $dest) {
if ($src != $dest) {
$tab['in'] = 39.37008;
$tab['mm'] = 1000;
return $value * $tab[$dest] / $tab[$src];
} else {
return $value;
}
}
// Give the height for a char size given.
function _Get_Height_Chars($pt) {
// Tableau de concordance entre la hauteur des caractères et de l'espacement entre les lignes
$_Table_Hauteur_Chars = array(6=>2, 7=>2.5, 8=>3, 9=>4, 10=>5, 11=>6, 12=>7, 13=>8, 14=>9, 15=>10);
if (in_array($pt, array_keys($_Table_Hauteur_Chars))) {
return $_Table_Hauteur_Chars[$pt];
} else {
return 100; // There is a prob..
}
}
function _Set_Format($format) {
$this->_Metric = $format['metric'];
$this->_Avery_Name = $format['name'];
$this->_Margin_Left = $this->_Convert_Metric ($format['marginLeft'], $this->_Metric, $this->_Metric_Doc);
$this->_Margin_Top = $this->_Convert_Metric ($format['marginTop'], $this->_Metric, $this->_Metric_Doc);
$this->_X_Space = $this->_Convert_Metric ($format['SpaceX'], $this->_Metric, $this->_Metric_Doc);
$this->_Y_Space = $this->_Convert_Metric ($format['SpaceY'], $this->_Metric, $this->_Metric_Doc);
$this->_X_Number = $format['NX'];
$this->_Y_Number = $format['NY'];
$this->_Width = $this->_Convert_Metric ($format['width'], $this->_Metric, $this->_Metric_Doc);
$this->_Height = $this->_Convert_Metric ($format['height'], $this->_Metric, $this->_Metric_Doc);
$this->Set_Char_Size( $format['font-size']);
}
} }
?> ?>

View File

@ -16,22 +16,19 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
* $Source$
*/ */
/** /**
\file htdocs/adherents/cartes/carte.php \file htdocs/adherents/cartes/carte.php
\ingroup adherent \ingroup adherent
\brief Page de creation d'une carte PDF \brief Page de creation d'une carte PDF
\version $Revision$ \version $Id$
*/ */
require("./pre.inc.php"); require("./pre.inc.php");
require_once(DOL_DOCUMENT_ROOT."/adherents/adherent.class.php"); require_once(DOL_DOCUMENT_ROOT."/adherents/adherent.class.php");
require_once(DOL_DOCUMENT_ROOT."/adherents/cartes/PDF_card.class.php");
require_once('PDF_card.class.php');
// liste des patterns remplacable dans le texte a imprimer // liste des patterns remplacable dans le texte a imprimer
$patterns = array ( $patterns = array (
@ -50,6 +47,7 @@ $patterns = array (
'/%ID%/', '/%ID%/',
'/%ANNEE%/' '/%ANNEE%/'
); );
/* /*
*------------------------------------------------- *-------------------------------------------------
* Pour créer l'objet on a 2 moyens : * Pour créer l'objet on a 2 moyens :
@ -108,7 +106,9 @@ if ($result)
// imprime le texte specifique sur la carte // imprime le texte specifique sur la carte
//$pdf->Add_PDF_card(sprintf("%s\n%s\n%s\n%s\n%s, %s\n%s", $objp->type." n° ".$objp->rowid,ucfirst(strtolower($objp->prenom))." ".strtoupper($objp->nom),"<".$objp->email.">", ucwords(strtolower($objp->adresse)), $objp->cp, strtoupper($objp->ville), ucfirst(strtolower($objp->pays))),$annee,"Association FreeLUG http://www.freelug.org/"); //$pdf->Add_PDF_card(sprintf("%s\n%s\n%s\n%s\n%s, %s\n%s", $objp->type." n° ".$objp->rowid,ucfirst(strtolower($objp->prenom))." ".strtoupper($objp->nom),"<".$objp->email.">", ucwords(strtolower($objp->adresse)), $objp->cp, strtoupper($objp->ville), ucfirst(strtolower($objp->pays))),$annee,"Association FreeLUG http://www.freelug.org/");
$pdf->Add_PDF_card(preg_replace ($patterns, $replace, ADHERENT_CARD_TEXT),preg_replace ($patterns, $replace, ADHERENT_CARD_HEADER_TEXT),preg_replace ($patterns, $replace, ADHERENT_CARD_FOOTER_TEXT)); $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));
$i++; $i++;
} }

View File

@ -260,28 +260,46 @@ function form_constantes($tableau)
print $langs->trans("Desc".$obj->name) != ("Desc".$obj->name) ? $langs->trans("Desc".$obj->name) : $obj->note; print $langs->trans("Desc".$obj->name) != ("Desc".$obj->name) ? $langs->trans("Desc".$obj->name) : $obj->note;
print "</td>\n"; print "</td>\n";
print '<td>'; if ($obj->name == 'ADHERENT_ETIQUETTE_TYPE')
if ($obj->type == 'yesno')
{ {
print $form->selectyesno('constvalue',$obj->value,1); print '<td>';
print '</td><td>'; // List of possible labels. Values must exists in
$form->select_array('consttype',array('yesno','texte','chaine'),0); // file htdocs/adherents/PDF_Card.class.php
} require_once(DOL_DOCUMENT_ROOT.'/adherents/cartes/PDF_card.class.php');
elseif ($obj->type == 'texte') $pdfcard=new PDF_card('5160',1,1,'mm');
{ $arrayoflabels=array_keys($pdfcard->_Avery_Labels);
print '<textarea class="flat" name="constvalue" cols="35" rows="5" wrap="soft">';
print $obj->value; $form->select_array('constvalue',$arrayoflabels,$obj->value);
print "</textarea>\n";
print '</td><td>'; print '</td><td>';
$form->select_array('consttype',array('yesno','texte','chaine'),1); $form->select_array('consttype',array('yesno','texte','chaine'),1);
} }
else else
{ {
print '<input type="text" class="flat" size="30" name="constvalue" value="'.$obj->value.'">'; print '<td>';
print '</td><td>'; if ($obj->type == 'yesno')
$form->select_array('consttype',array('yesno','texte','chaine'),2); {
print $form->selectyesno('constvalue',$obj->value,1);
print '</td><td>';
$form->select_array('consttype',array('yesno','texte','chaine'),0);
}
elseif ($obj->type == 'texte')
{
print '<textarea class="flat" name="constvalue" cols="35" rows="5" wrap="soft">';
print $obj->value;
print "</textarea>\n";
print '</td><td>';
$form->select_array('consttype',array('yesno','texte','chaine'),1);
}
else
{
print '<input type="text" class="flat" size="30" name="constvalue" value="'.$obj->value.'">';
print '</td><td>';
$form->select_array('consttype',array('yesno','texte','chaine'),2);
}
print '</td>';
} }
print '</td><td align="center">';
print '<td align="center">';
print '<input type="submit" class="button" value="'.$langs->trans("Update").'" name="Button"> &nbsp;'; print '<input type="submit" class="button" value="'.$langs->trans("Update").'" name="Button"> &nbsp;';
// print '<a href="adherent.php?name='.$const.'&action=unset">'.img_delete().'</a>'; // print '<a href="adherent.php?name='.$const.'&action=unset">'.img_delete().'</a>';