Subversion Repositories ALCASAR

Rev

Details | Last modification | View Log

Rev Author Line No. Line
1088 stephane 1
<?php
2
 
3
require_once('../lib/fpdf/fpdf.php');
4
/*
5
TODO :
6
- réécriture au format PHP5
7
- Ajout d'une fonction pour le choix des logos à ajouter
8
- Meilleur calcule du découpage de la page lors de l"utilisation de format de papier plus atypique
9
- Ajout des commentaires au format PHPDoc
10
- Intégration au package Alcasar for alcasar V3.
11
*/
12
 
13
/**
14
 * Alcasar
15
 *
16
 * class for Alcasar web interface
17
 *
18
 * @package		Alcasar
19
 * @author		Alcasar Dev Team (steweb57)
20
 * @copyright	Copyright (c) 2013 , www.alcasar.net
21
 * @license		GPL V3
22
 * @link		http://www.alcasar.net
23
 * @version		0.1
24
 */
25
 
26
class ticketsPDF extends FPDF
27
{
28
	/****************************************************************
29
	*																*
30
	*					Private properties							*
31
	*																*
32
	*****************************************************************/
33
	var $_COUNTX	= 0;		// Current x ticket position
34
	var $_COUNTY	= 1;		// Current y ticket position
35
	//var $_image		= array();	// Images to add to each ticket	
36
	var $_title;				// Title text for each ticket
37
	var $_footer;				// Footer text for each ticket
38
	var $_X;					// Number of tickets horizontally
39
	var $_Y;					// Number of tickets vertically
40
	var $_width;				// Ticket width
41
	var $_height;				// Ticket height
42
	var $_margin	= 5;		// Margin
43
	var $_padding	= 5;		// Padding
44
 
45
	/**
46
	* Constructor method : <b>ticketsPDF(int x,int y)</b>
47
	*
48
	* <p>Create the class instance</p>
49
	*
50
	* @access public
51
	* @param int $x, $y
52
	* @return void
53
	*/
54
	function ticketsPDF($x = 1, $y = 1) {
55
 
56
		// For the moment, only "P", "mm", "A4" format
57
		parent::FPDF('P', 'mm', 'A4');
58
		$this->AddPage();
59
		/*
60
		$x = number of tickets horizontally
61
		$y = number of tickets vertically
62
		*/
63
		$this->_X = $x;
64
		$this->_Y = $y;
65
 
66
		$this->_width = (int)((210 - ($this->_margin*2))/$this->_X);
67
		$this->_height = (int)((297 - ($this->_margin*2))/$this->_Y);
68
	}
69
 
70
	/****************************************************************
71
	*																*
72
	*					Private methods								*
73
	*																*
74
	*****************************************************************/
75
	function _ticketHeader()
76
	{
77
		$currentX = $this->_margin + (($this->_COUNTX - 1) * $this->_width ) + $this->_padding;
78
		$currentY = $this->_margin + (($this->_COUNTY - 1) * $this->_height ) + $this->_padding;
79
		$this->SetXY($currentX, $currentY);
80
 
81
		$this->SetFont('Arial','B',9);
82
		$this->SetTextColor(250,1,10);
83
		$this->Cell($this->_width-10,10,$this->_title,0,1,'C');
84
	}
85
	function _ticketFooter()
86
	{
87
		$currentX = $this->_margin + (($this->_COUNTX - 1) * $this->_width ) + $this->_padding;
88
		$currentY = (($this->_COUNTY) * $this->_height) - 5;
89
		$this->SetXY($currentX, $currentY);
90
 
91
		$this->SetTextColor(0);
92
		$this->SetFont('Arial','',9);
93
		$this->Cell($this->_width-10,10,$this->_footer,0,0,'C');
94
	}
95
	function _addTicketsImages()
96
	{
97
		// Add Alcasar Logo
98
		$currentX = $this->_margin + (($this->_COUNTX - 1) * $this->_width ) + $this->_padding;
99
		$currentY = $this->_margin + (($this->_COUNTY - 1) * $this->_height ) + $this->_padding;
100
		$this->Image('../../../images/logo-alcasar.png',$currentX,$currentY,20);
101
		// Add other logo
102
		$currentX = $this->_margin + (($this->_COUNTX) * $this->_width ) - $this->_padding - 15;
103
		$this->Image('../../../images/organisme.png',$currentX,$currentY,15);
104
 
105
	}
106
	//fonction arc de cercle
107
	function _Arc($x1, $y1, $x2, $y2, $x3, $y3)
108
	{
109
		$h = $this->h;
110
		$this->_out(sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $x1*$this->k, ($h-$y1)*$this->k,
111
			$x2*$this->k, ($h-$y2)*$this->k, $x3*$this->k, ($h-$y3)*$this->k));
112
	}
113
	// gestion automatique du format UFT8
114
	function _cleanUTF8($txt='')
115
	{
116
		if (mb_detect_encoding($txt)=="UTF-8")
117
		{
118
			//exit(utf8_decode($txt));
119
			return utf8_decode($txt);
120
		} else {
121
 
122
			//exit($txt);
123
			return $txt;
124
		}
125
	}
126
	/****************************************************************
127
	*																*
128
	*					Public methods								*
129
	*																*
130
	*****************************************************************/	
131
 
132
	//fonction rectangle
133
	//Rectangle : x, y : coin supérieur gauche du rectangle.w, h : largeur et hauteur. r : rayon des coins arrondis.
134
	//style : comme celui de Rect() : F, D (défaut), FD ou DF. 
135
	function RoundedRect($x, $y, $w, $h, $r, $style = '')
136
	{
137
		$k = $this->k;
138
		$hp = $this->h;
139
		if($style=='F')
140
			$op='f';
141
		elseif($style=='FD' or $style=='DF')
142
			$op='B';
143
		else
144
			$op='S';
145
		$MyArc = 4/3 * (sqrt(2) - 1);
146
		$this->_out(sprintf('%.2F %.2F m',($x+$r)*$k,($hp-$y)*$k ));
147
		$xc = $x+$w-$r ;
148
		$yc = $y+$r;
149
		$this->_out(sprintf('%.2F %.2F l', $xc*$k,($hp-$y)*$k ));
150
 
151
		$this->_Arc($xc + $r*$MyArc, $yc - $r, $xc + $r, $yc - $r*$MyArc, $xc + $r, $yc);
152
		$xc = $x+$w-$r ;
153
		$yc = $y+$h-$r;
154
		$this->_out(sprintf('%.2F %.2F l',($x+$w)*$k,($hp-$yc)*$k));
155
		$this->_Arc($xc + $r, $yc + $r*$MyArc, $xc + $r*$MyArc, $yc + $r, $xc, $yc + $r);
156
		$xc = $x+$r ;
157
		$yc = $y+$h-$r;
158
		$this->_out(sprintf('%.2F %.2F l',$xc*$k,($hp-($y+$h))*$k));
159
		$this->_Arc($xc - $r*$MyArc, $yc + $r, $xc - $r, $yc + $r*$MyArc, $xc - $r, $yc);
160
		$xc = $x+$r ;
161
		$yc = $y+$r;
162
		$this->_out(sprintf('%.2F %.2F l',($x)*$k,($hp-$yc)*$k ));
163
		$this->_Arc($xc - $r, $yc - $r*$MyArc, $xc - $r*$MyArc, $yc - $r, $xc, $yc - $r);
164
		$this->_out($op);
165
	}
166
 
167
	function newTickets()
168
	{
169
		$this->_COUNTX++;
170
		if ($this->_COUNTX > $this->_X) {
171
			// Row full, we start a new one
172
			$this->_COUNTX=1;
173
			$this->_COUNTY++;
174
			if ($this->_COUNTY > $this->_Y) {
175
				// End of page reached, we start a new one
176
				$this->_COUNTY=1;
177
				$this->AddPage();
178
			}
179
		}
180
 
181
		$this->_ticketHeader();	
182
		$this->_ticketFooter();
183
 
184
		$currentX = $this->_margin + (($this->_COUNTX - 1) * $this->_width ) + $this->_padding;
185
		$currentY = $this->_margin + (($this->_COUNTY - 1) * $this->_height ) + $this->_padding;
186
		$this->SetXY($currentX, $currentY+10);
187
 
188
		//création du cadre arrondi qui entoure le ticket d'impression
189
		//x, y : coin supérieur gauche du rectangle.w, h : largeur et hauteur. r : rayon des coins arrondis.
190
		//style : comme celui de Rect() : F, D (défaut), FD ou DF. 
191
		$RoundedRectX = (($this->_COUNTX - 1) * ($this->_width))+($this->_width/6);
192
		$this->RoundedRect($RoundedRectX, $currentY+10, ($this->_width-($this->_width/4)), $this->_height/2, 3.5, 'D');
193
 
194
		$this->_addTicketsImages();
195
	}
196
	function addInfos($title, $value)
197
	{
198
		$currentX = $this->_margin + (($this->_COUNTX - 1) * $this->_width ) + $this->_padding;
199
		$this->SetX($currentX);
200
 
201
		$this->SetTextColor(0);
202
		$this->SetFont('Arial','',9);
203
		$this->Cell(($this->_width/2)-5,5,$title,0,0,'R');
204
		$this->SetFont('Arial','B',9);
205
		$this->Cell(($this->_width/2)-5,5,$value,0,1,'L');
206
	}
207
	function addComment($txt, $align = "J")
208
	{
209
		$currentX = $this->_margin + (($this->_COUNTX - 1) * $this->_width ) + $this->_padding;
210
		$this->SetX($currentX);
211
 
212
		$this->SetTextColor(0);
213
		$this->SetFont('Arial','',8);
214
 
215
		//$this->Cell($this->_width-10,5,$txt,0,1,$align);
216
		$this->MultiCell($this->_width - $this->_padding - 5, 5, $txt, 0, $align);
217
	}
218
	function setTicketsTitle($txt)
219
	{
220
		$this->_title = $txt;
221
	}
222
	function setTicketsFooter($txt)
223
	{
224
		$this->_footer = $txt;
225
	}
226
	function AcceptPageBreak()
227
	{
228
		return false;
229
	}
230
	function Cell($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link='')
231
	{
232
		$txt = $this->_cleanUTF8($txt);
233
		parent::Cell($w, $h, $txt, $border, $ln, $align, $fill, $link);
234
	}
235
	/*
236
	//For futur use
237
	function addTicketsImage($file, $x, $y, $w)
238
	{
239
		$this->_image[] = array('file'=>$file, 'x'=>$x, 'y'=>$y, 'w'=>$w);
240
	}
241
	*/
242
 
243
	/*
244
	Function Ln($h=null)
245
	{
246
		parent::Ln($h);
247
 
248
		$currentX = $this->_margin + (($this->_COUNTX - 1) * $this->_width ) + $this->_padding;
249
		$this->SetX($currentX);
250
	}
251
	*/
252
}
253
?>