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
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
* $Source$
*/
/* Inspire de PDF_Label
@ -64,7 +61,7 @@
\author Laurent Passebecq
\author Rodolphe Quiedville
\author Jean Louis Bergamo.
\version $Revision$
\version $Id$
*/
require_once(FPDFI_PATH.'fpdi_protection.php');
@ -74,7 +71,6 @@ require_once(FPDFI_PATH.'fpdi_protection.php');
\class PDF_card
\brief Classe afin d'éditer au format PDF des étiquettes au format Avery ou personnalisé
*/
class PDF_card extends FPDF {
// Propriétés privées
@ -96,8 +92,8 @@ class PDF_card extends FPDF {
var $_COUNTY = 1;
var $_First = 1;
// Listing of labels size
var $_Avery_Labels = array (
// Listing of labels size
var $_Avery_Labels = array (
'5160'=>array('name'=>'5160',
'paper-size'=>'letter',
'metric'=>'mm',
@ -209,47 +205,22 @@ class PDF_card extends FPDF {
'logo1'=>'logo1.jpg',
'logo2'=>'logo2.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'];
$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']);
}
function PDF_card ($format, $posX=1, $posY=1, $unit='mm') {
if (is_array($format)) {
/**
* Constructor
*
* @param unknown_type $format Avery format of label paper. For example 5160, 5161, 5162, 5163, 5164, 8600, L7163
* @param unknown_type $posX
* @param unknown_type $posY
* @param unknown_type $unit
* @return PDF_card
*/
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
$Tformat = $format;
} else {
@ -271,6 +242,7 @@ class PDF_card extends FPDF {
$this->_Set_Format($Tformat);
}
//Méthode qui permet de modifier la taille des caractères
// Cela modiera aussi l'espace entre chaque ligne
function Set_Char_Size($pt) {
@ -281,6 +253,7 @@ class PDF_card extends FPDF {
}
}
// On imprime une étiqette
function Add_PDF_card($texte,$header='',$footer='') {
// 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)
{
$this->SetLineWidth($epaisseur);
@ -389,5 +363,43 @@ class PDF_card extends FPDF {
//$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
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
* $Source$
*/
/**
\file htdocs/adherents/cartes/carte.php
\ingroup adherent
\brief Page de creation d'une carte PDF
\version $Revision$
\version $Id$
*/
require("./pre.inc.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
$patterns = array (
@ -50,6 +47,7 @@ $patterns = array (
'/%ID%/',
'/%ANNEE%/'
);
/*
*-------------------------------------------------
* Pour créer l'objet on a 2 moyens :
@ -108,7 +106,9 @@ if ($result)
// 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(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++;
}

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 "</td>\n";
print '<td>';
if ($obj->type == 'yesno')
if ($obj->name == 'ADHERENT_ETIQUETTE_TYPE')
{
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>';
// List of possible labels. Values must exists in
// file htdocs/adherents/PDF_Card.class.php
require_once(DOL_DOCUMENT_ROOT.'/adherents/cartes/PDF_card.class.php');
$pdfcard=new PDF_card('5160',1,1,'mm');
$arrayoflabels=array_keys($pdfcard->_Avery_Labels);
$form->select_array('constvalue',$arrayoflabels,$obj->value);
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>';
if ($obj->type == 'yesno')
{
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 '<a href="adherent.php?name='.$const.'&action=unset">'.img_delete().'</a>';