~adamzammit/quexml/quexmleasyinstall

20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1
<?php
2
3
/**
4
 * Modify these two lines to point to your TCPDF installation
5
 * Tested with TCPDF 5.8.008 - see http://www.tcpdf.org/
6
 */
29 by azammitdcarf
Cleaned up CSS
7
require_once('/var/lib/tcpdf/config/lang/eng.php');
8
require_once('/var/lib/tcpdf/tcpdf.php');
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
9
10
/**
11
 * A TCPDF based class to produce queXF compatible questionnaire PDF files and banding description XML from queXML
12
 * 
13
 * @author    Adam Zammit <adam.zammit@acspri.org.au>
14
 * @copyright (c) 2010 Australian Consortium for Social and Political Research Incorporated (ACSPRI)
15
 * @since     2010-09-02
16
 * @link      http://www.acspri.org.au/software
17
 * @link      http://quexml.sourceforge.net
18
 * @link      http://quexf.sourceforge.net
19
 */
20
class queXMLPDF extends TCPDF {
21
22
	/**
23
	 * Define an inch in MM
24
	 *
25
	 * @const float Defaults to 25.4
26
	 */
27
	const INCH_IN_MM = 25.4;
28
29
	/**
30
	 * Pixels per inch of exported document
31
	 * 
32
	 * @var int Defaults to 300.
33
	 */
34
	protected $ppi = 300;
35
36
	/**
37
	 * Whether a page break has occured
69 by azammitdcarf
Fix for bug reported upstream here: http://bugs.limesurvey.org/view.php?id=5824
38
	 * Should be a private var but crash occurs on PHP 5.1.6, see Limesurvey Bug 5824
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
39
	 * @var bool
40
	 */
69 by azammitdcarf
Fix for bug reported upstream here: http://bugs.limesurvey.org/view.php?id=5824
41
	protected $pageBreakOccured;
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
42
43
	/**
44
	 * Corner border (the number of mm between the edge of the page and the start of the document)
45
	 * 
46
	 * @var int  Defaults to 15. 
47
	 * @since 2010-09-02
48
	 */
86 by azammitdcarf
Add setters and getters for font size and style
49
	protected $cornerBorder = 14;
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
50
51
	/**
52
	 * The length in MM of a corner line
53
	 * 
54
	 * @var mixed  Defaults to 20. 
55
	 * @since 2010-09-20
56
	 */
57
	protected $cornerLength = 20;
58
59
	/**
60
	 * The width in MM of a corner line
61
	 * 
62
	 * @var mixed  Defaults to 0.5. 
63
	 * @since 2010-09-20
64
	 */
65
	protected $cornerWidth = 0.5;
66
67
68
	/**
69
	 * The TCPDF barcode type
70
	 * 
71
	 * @var bool  Defaults to 'I25'. 
72
	 * @since 2010-09-20
73
	 * @see write1DBarcode
74
	 */
75
	protected $barcodeType = 'I25';
76
77
	/**
78
	 * The x position in MM of the barcode
79
	 * 
80
	 * @var bool  Defaults to 138. 
81
	 * @since 2010-09-20
54 by azammitdcarf
Calculation of barcode position is now a distance from the right hand margin (instead of a fixed position in MM)
82
	 * @deprecated
83
	 * @see $barcodeMarginX
84
	 */
85
	//protected $barcodeX = 138;
86
87
	/**
88
	 * The distance between the right hand page border and
89
	 * the end of the barcode in MM
90
	 * 
91
	 * @var bool  Defaults to 23. 
92
	 * @since 2011-10-25
93
	 */
94
	protected $barcodeMarginX = 23;
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
95
96
	/**
97
	 * Y position of barcode in mm
98
	 * 
99
	 * @var bool  Defaults to 6. 
100
	 * @since 2010-09-20
101
	 */
102
	protected $barcodeY = 6;
103
104
	/**
105
	 * Width of the barcode in mm
106
	 * 
107
	 * @var bool  Defaults to 49. 
108
	 * @since 2010-09-20
109
	 */
110
	protected $barcodeW = 49;
111
112
	/**
113
	 * Height of the barcode in mm
114
	 * 
115
	 * @var bool  Defaults to 6. 
116
	 * @since 2010-09-20
117
	 */
118
	protected $barcodeH = 6;
119
120
	/**
121
	 * The questionnaire ID of this form
122
	 * 
23 by azammitdcarf
Updated variable names
123
	 * @var mixed  Defaults to 1. 
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
124
	 * @since 2010-09-20
125
	 */
23 by azammitdcarf
Updated variable names
126
	protected $questionnaireId = 1;
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
127
128
	/**
129
	 * The length of a the id portion barcode
130
	 * 
131
	 * @var int  Defaults to 6. 
132
	 * @since 2010-09-20
133
	 * @see $pageLength
134
	 */
135
	protected $idLength = 6;
136
137
	/**
138
	 * The length of the page portion of the barcode
139
	 * 
140
	 * @var mixed  Defaults to 2. 
141
	 * @since 2010-09-20
142
	 * @see $idLength
143
	 */
144
	protected $pageLength = 2;
145
146
	/**
147
	 * width of the question title column in MM
148
	 * 
149
	 * @var mixed  Defaults to 14. 
150
	 * @since 2010-09-20
151
	 */
152
	protected $questionTitleWidth = 14;
153
154
	/**
66 by azammitdcarf
Added a skipTo registry - so question titles can be bolded where there is a skip to them
155
	 * The suffix of the question title. i.e. A15. (the . is the suffix)
156
	 * 
157
	 * @var mixed  Defaults to ".". 
158
	 * @since 2012-01-31
159
	 */
160
	protected $questionTitleSuffix = ".";
161
162
	/**
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
163
	 * Width of question text in MM
164
	 * 
165
	 * @var mixed  Defaults to 120. 
166
	 * @since 2010-09-20
63 by azammitdcarf
Replaced $questionTextWidth with $questionTextRightMargin to manage varying page widths better
167
	 * @deprecated
168
	 */
169
	//protected $questionTextWidth = 120;
170
171
	/**
172
	 * Right margin of question text in MM
173
	 * 
174
	 * @var mixed  Defaults to 40. 
175
	 * @since 2012-01-11
176
	 * @see $questionTextWidth
177
	 */
178
	protected $questionTextRightMargin = 40;
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
179
180
	/**
181
	 * Height of the border between questions in MM
182
	 * 
183
	 * @var mixed  Defaults to 1. 
184
	 * @since 2010-09-20
185
	 */
186
	protected $questionBorderBottom = 1;
65 by azammitdcarf
Added a white border around question directive before elements
187
	
188
	/**
189
	 * Border after a help before directive
190
	 * 
191
	 * @var mixed  Defaults to 3. 
192
	 * @since 2012-01-31
193
	 */
194
	protected $helpBeforeBorderBottom = 3;
195
196
	/**
197
	 * Border before a help before directive
198
	 * 
199
	 * @var mixed  Defaults to 3. 
200
	 * @since 2012-01-31
201
	 */
202
	protected $helpBeforeBorderTop = 3;
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
203
204
	/**
205
	 * Width of the skip column area (where skip text is written)
206
	 * 
207
	 * @var string  Defaults to 20. 
208
	 * @since 2010-09-20
209
	 */
210
	protected $skipColumnWidth = 20;
211
212
	/**
213
	 * The default style for the text of the questionnaire
214
	 * 
215
	 * @var string  Defaults to "<style>td.questionHelp {text-align:right; font-style:italic; font-size: 8pt;} td.responseText {text-align:right; margin-right:1mm;} td.responseAboveText {text-align:left;} td.responseLabel {text-align:center; font-size:8pt;} span.sectionTitle {font-size: 18pt} span.sectionDescription {font-size: 14pt}</style>". 
216
	 * @since 2010-09-16
217
	 */
29 by azammitdcarf
Cleaned up CSS
218
	protected $style = "<style>
34 by azammitdcarf
Replaced drawing using HTML tables with TCPDF Multicell to allow for aligning text vertically
219
		td.questionTitle {font-weight:bold; font-size:12pt;}
66 by azammitdcarf
Added a skipTo registry - so question titles can be bolded where there is a skip to them
220
		td.questionTitleSkipTo {font-weight:bold; font-size:16pt;}
31 by azammitdcarf
Fixed CSS bug (weight not style for font bold)
221
		td.questionText {font-weight:bold; font-size:12pt;} 
63 by azammitdcarf
Replaced $questionTextWidth with $questionTextRightMargin to manage varying page widths better
222
		td.questionSpecifier {font-weight:normal; font-size:12pt;} 
56 by azammitdcarf
Fixed typo (from Limesurvey commit 11300)
223
		td.vasLabel {font-weight:bold; font-size:10pt; text-align:center;}
35 by azammitdcarf
Use setDefaultFont function instead of SetFont
224
		td.questionHelp {font-weight:normal; text-align:right; font-style:italic; font-size:8pt;}
225
		td.questionHelpAfter {text-align:center; font-weight:bold; font-size:10pt;}
63 by azammitdcarf
Replaced $questionTextWidth with $questionTextRightMargin to manage varying page widths better
226
		td.questionHelpBefore {text-align:center; font-weight:bold; font-size:12pt;}
35 by azammitdcarf
Use setDefaultFont function instead of SetFont
227
		td.responseAboveText {font-weight:normal; font-style:normal; text-align:left; font-size:12pt;} 
93 by Adam Zammit
Added paginiation improvements and bug fixes from downstream (LimeSurvey) thank you mfaber!
228
		td.matrixResponseGroupLabel {font-weight:normal; font-style:normal; text-align:left; font-size:12pt;}
35 by azammitdcarf
Use setDefaultFont function instead of SetFont
229
		span.sectionTitle {font-size:18pt; font-weight:bold;} 
230
		span.sectionDescription {font-size:14pt; font-weight:bold;} 
231
		div.sectionInfo {font-style:normal; font-size:10pt; text-align:left; font-weight:normal;}
86 by azammitdcarf
Add setters and getters for font size and style
232
		td.questionnaireInfo {font-size:14pt; text-align:center; font-weight:bold;}
29 by azammitdcarf
Cleaned up CSS
233
		</style>";
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
234
235
	/**
236
	 * Width of the area of each single response 
237
	 * 
238
	 * @var string  Defaults to 10. 
239
	 * @since 2010-09-20
60 by azammitdcarf
Made border 14mm instead of 15mm to fit a bit more on to page ($cornerBorder)
240
	 * Height of the area of a single response where displayed horizontally
241
	 * 
242
	 * @var string  Defaults to 10.5. 
243
	 * @since 2011-12-20
244
	 */
88 by Adam Zammit
Allow for contingentQuestions to be specified on subQuestions (for matrix "Other")
245
	protected $singleResponseHorizontalHeight = 11.5;
246
247
	/**
248
	 * The maximum number of lines of text to display
249
	 * in a horizontal single response before adding additional space
250
	 * 
251
	 * @var string  Defaults to 2. 
252
	 * @since 2013-05-02
253
	 * @see $singleResponseHorizontalHeight
254
	 */
255
	protected $singleResponseHorizontalMaxLines = 2;
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
256
257
	/**
258
	 * Height of the are of each single response (includes guiding lines)
259
	 * 
260
	 * @var string  Defaults to 9. 
261
	 * @since 2010-09-20
262
	 */
263
	protected $singleResponseAreaHeight = 9;
264
265
	/**
266
	 * Width of a single response box
267
	 * 
268
	 * @var string  Defaults to 5. 
269
	 * @since 2010-09-20
270
	 */
271
	protected $singleResponseBoxWidth = 5;
272
273
	/**
274
	 * Height of a single response box
275
	 * 
276
	 * @var string  Defaults to 5. 
277
	 * @since 2010-09-20
278
	 */
279
	protected $singleResponseBoxHeight = 5;
280
281
	/**
282
	 * Width of a response boxes border
283
	 * 
284
	 * @var string  Defaults to 0.1. 
285
	 * @since 2010-09-20
286
	 */
38 by azammitdcarf
Updated image line size to make sure lines are printed and not ignored
287
	protected $singleResponseBoxBorder = 0.15;
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
288
289
	/**
290
	 * Length of the "eye guide" for a vertical response box
291
	 * 
292
	 * @var string  Defaults to 1. 
293
	 * @since 2010-09-20
294
	 */
295
	protected $singleResponseBoxLineLength = 1;
296
297
	/**
298
	 * Vertical area taken up by a response box
299
	 * 
300
	 * @var string  Defaults to 15. 
301
	 * @since 2010-09-20
302
	 */
68 by azammitdcarf
Updated to work better with Matrix questions on A4 paper
303
	protected $singleResponseVerticalAreaWidth = 13;
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
304
305
	/**
306
	 * Vertical area taken up by a "small" vertical response area
307
	 * 
308
	 * @var string  Defaults to 9. 
309
	 * @since 2010-09-20
310
	 */
311
	protected $singleResponseVerticalAreaWidthSmall = 9;
312
313
	/**
314
	 * Maximum number of horizontal boxes to display normally before shrinking horizontal area width
315
	 * 
316
	 * @var int  Defaults to 10. 
317
	 * @since 2010-09-08
318
	 */
319
	protected $singleResponseHorizontalMax = 10;
320
321
	/**
86 by azammitdcarf
Add setters and getters for font size and style
322
	 * Allow single choice horizontal arrays to be split over multiple pages/columns
323
	 * 
324
	 * @var array  Defaults to false. 
325
	 * @since 2012-08-10
326
	 */
327
	protected $allowSplittingSingleChoiceHorizontal = false;
328
329
	/**
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
330
	 * The height of an arrow
331
	 * 
332
	 * @var array  Defaults to 3. 
333
	 * @since 2010-09-20
334
	 */
335
	protected $arrowHeight = 3;
336
337
	/**
338
	 * The width of a text response box
339
	 * 
340
	 * @var mixed  Defaults to 6. 
341
	 * @since 2010-09-20
342
	 */
343
	protected $textResponseWidth = 6;
344
345
	/**
74 by azammitdcarf
Typo fix
346
	 * The border width of a text response box
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
347
	 * 
38 by azammitdcarf
Updated image line size to make sure lines are printed and not ignored
348
	 * @var mixed  Defaults to 0.15.  Any less than this may produce printing problems
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
349
	 * @since 2010-09-20
350
	 */
38 by azammitdcarf
Updated image line size to make sure lines are printed and not ignored
351
	protected $textResponseBorder = 0.15;
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
352
353
	/**
354
	 * The height of a text response box
355
	 * 
356
	 * @var mixed  Defaults to 8. 
357
	 * @since 2010-09-20
358
	 */
359
	protected $textResponseHeight = 8;
360
361
	/**
83 by azammitdcarf
Added free response types "codabar" and "i25" to be able to pre-draw filled barcodes a questions (using the defaultValue attribute)
362
	 * The height of a pre-filled response barcode
363
	 * 
364
	 * @var bool  Defaults to 6. 
365
	 * @since 2012-06-22
366
	 */
367
	protected $barcodeResponseHeight = 6;
368
369
	/**
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
370
	 * The maximum number of text responses per line
371
	 * 
372
	 * @var mixed  Defaults to 24. 
373
	 * @since 2010-09-20
54 by azammitdcarf
Calculation of barcode position is now a distance from the right hand margin (instead of a fixed position in MM)
374
         * @deprecated
375
	 * @see $textResponseMarginX
376
	 */
377
	//protected $textResponsesPerLine = 24;
378
379
	/**
380
	 * The left hand margin of text responses to auto calculate responses
381
	 * per line (mm)
382
	 * 
383
	 * @var mixed  Defaults to 13. 
384
	 * @since 2011-10-25
385
	 */
386
	protected $textResponseMarginX = 13;
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
387
388
	/**
389
	 * Maximum number of text responses boxes where the label should appear on the same line
390
	 * 
391
	 * @var mixed  Defaults to 16. 
392
	 * @since 2010-09-20
54 by azammitdcarf
Calculation of barcode position is now a distance from the right hand margin (instead of a fixed position in MM)
393
	 * @deprecated
394
	 * @see $labelTextResponsesSameLineMarginX
395
	 */
396
	//protected $labelTextResponsesSameLine = 16;
397
398
	/**
399
	 * The left hand margin of text responses to auto calculated responses
400
	 * per line where the label should appear on the same line (mm)
401
	 * 
402
	 * @var mixed  Defaults to 62. 
403
	 * @since 2011-10-25
404
	 */
405
	protected $labelTextResponsesSameLineMarginX = 62;
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
406
407
	/**
408
	 * The gap between multi line text responses
409
	 * 
410
	 * @var mixed  Defaults to 1. 
411
	 * @since 2010-09-20
412
	 */
413
	protected $textResponseLineSpacing = 1;
414
415
	/**
416
	 * The vertical gap between subquestions in mm
417
	 * 
418
	 * @var string  Defaults to 2. 
419
	 * @since 2010-09-02
420
	 */
421
	protected $subQuestionLineSpacing = 2;
422
423
	/**
424
	 * The multiplier from long text response width specified to the height in mm
425
	 * 
426
	 * @var mixed  Defaults to 1. 
427
	 * @since 2010-09-20
428
	 */
429
	protected $longTextResponseHeightMultiplier = 1;
430
431
	/**
432
	 * Width of a long text response box
433
	 * 
434
	 * @var mixed  Defaults to 145. 
435
	 * @since 2010-09-20
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
436
	 * @deprecated
437
	 * @see drawLongText() for the new calculation of long text box width
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
438
	 */
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
439
	//protected $longTextResponseWidth = 145;
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
440
441
	/**
442
	 * Default number of characters to store in a long text field
443
	 * 
444
	 * @var int Default is 1024;
445
	 * @since 2010-09-02
446
	 */
447
	protected $longTextStorageWidth = 1024;
448
76 by azammitdcarf
Added column variables
449
	/**
450
	 * The number of columns to display the sections/questions in on each page
451
	 * 
452
	 * @var int  Defaults to 1. 
453
	 * @since 2012-05-30
454
	 */
455
	protected $columns = 1;
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
456
457
	/**
79 by azammitdcarf
Added a divider between columns
458
	 * The width of the border between columns
459
	 * 
460
	 * @var int  Defaults to 1. 
461
	 * @since 2012-05-31
462
	 */
463
	protected $columnBorder = 1;
464
465
	/**
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
466
	 * The layout of the form for importing in to queXF
467
	 *
468
	 * @var array Defaults to empty array
469
	 * @link http://quexf.sourceforge.net/
470
	 */
471
	protected $layout = array();	
472
473
	/**
474
	 * Array to store section information for layout
475
	 * 
476
	 * @var array  Defaults to empty array
477
	 * @since 2010-09-02
478
	 */
479
	protected $section = array();
480
481
	/**
66 by azammitdcarf
Added a skipTo registry - so question titles can be bolded where there is a skip to them
482
	 * An array of key: skip target, value: last originating question 
483
	 * that skips to the target
484
	 * 
485
	 * @var string  Defaults to array(). 
486
	 * @since 2012-01-31
487
	 */
488
	protected $skipToRegistry = array();
489
490
	/**
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
491
	 * Page counter pointer (links to barcode id of page)
492
	 * 
493
	 * @var mixed  Defaults to "". 
494
	 * @since 2010-09-02
495
	 */
496
	protected $layoutCP = "";
497
498
	/**
499
	 * Section counter pointer
500
	 * 
501
	 * @var string  Defaults to 0. 
502
	 * @since 2010-09-02
503
	 */
504
	protected $sectionCP = 0;
505
506
	/**
507
	 * Box group counter pointer
508
	 * 
509
	 * @var bool  Defaults to 0. 
510
	 * @since 2010-09-02
511
	 */
512
	protected $boxGroupCP = 0;
513
514
	/**
515
	 * Box counter pointer
516
	 * 
517
	 * @var int  Defaults to 0. 
518
	 */
519
	protected $boxCP = 0;
520
521
	/**
76 by azammitdcarf
Added column variables
522
	 * Column counter pointer (current column)
523
	 * 
77 by azammitdcarf
Set column pointer default to 0
524
	 * @var mixed  Defaults to 0. 
76 by azammitdcarf
Added column variables
525
	 * @since 2012-05-30
526
	 */
77 by azammitdcarf
Set column pointer default to 0
527
	protected $columnCP = 0;
76 by azammitdcarf
Added column variables
528
529
	/**
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
530
	 * Background colour of a question
531
	 * 
532
	 * @var bool  Defaults to array(220,220,220). 
533
	 * @since 2010-09-15
534
	 */
75 by azammitdcarf
Made output colours|colors greyscale|grayscale
535
	protected $backgroundColourQuestion = array(241);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
536
537
	/**
538
	 * The bacground colour of a section
539
	 * 
540
	 * @var bool  Defaults to array(200,200,200). 
541
	 * @since 2010-09-20
542
	 */
75 by azammitdcarf
Made output colours|colors greyscale|grayscale
543
	protected $backgroundColourSection = array(221);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
544
545
	/**
546
	 * Empty background colour
547
	 * 
548
	 * @var bool  Defaults to array(255,255,255). 
549
	 * @since 2010-09-20
550
	 */
75 by azammitdcarf
Made output colours|colors greyscale|grayscale
551
	protected $backgroundColourEmpty = array(255);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
552
553
	/**
554
	 * The colour of a line/fill
555
	 * 
556
	 * @var mixed  Defaults to array(0,0,0). 
557
	 * @since 2010-09-20
558
	 */
75 by azammitdcarf
Made output colours|colors greyscale|grayscale
559
	protected $lineColour = array(0);
560
561
	/**
562
	 * Text colour in grayscale
563
	 * 
564
	 * @var mixed  Defaults to 0. 
565
	 * @since 2012-04-16
566
	 */
567
	protected $textColour = 0;
568
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
569
570
	/**
571
	 * The text to display before a skip 
572
	 * 
573
	 * @var string  Defaults to "Skip to ". 
574
	 * @since 2010-09-16
575
	 */
576
	protected $skipToText = "Skip to ";
577
578
	/**
579
	 * Should fonts be embedded in the document?
580
	 * 
581
	 * @var mixed  Defaults to true. 
582
	 * @since 2010-09-20
583
	 */
584
	protected $embedFonts = true;
585
586
	/**
587
	 * Height in MM of a VAS response
588
	 * 
589
	 * @var mixed  Defaults to 8. 
590
	 * @since 2010-09-20
591
	 */
592
	protected $vasAreaHeight = 8;
593
594
	/**
595
	 * Width of a VAS line
596
	 * 
597
	 * @var mixed  Defaults to 0.5. 
598
	 * @since 2010-09-20
599
	 */
600
	protected $vasLineWidth = 0.5;
601
602
	/**
82 by azammitdcarf
Added defaultValue attribute to responses to allow for pre-filling
603
	 * The width of a line for the default value
604
	 * 
605
	 * @var double  Defaults to 0.5. 
606
	 * @since 2012-06-14
607
	 */
608
	protected $defaultValueLineWidth = 0.5;
609
610
	/**
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
611
	 * Height of the VAS ending lines in mm
612
	 * 
613
	 * @var mixed  Defaults to 4. 
614
	 * @since 2010-09-20
615
	 */
616
	protected $vasHeight = 4;
617
618
	/**
619
	 * Length of the vas line itself
620
	 * 
621
	 * @var mixed  Defaults to 100. 
622
	 * @since 2010-09-20
623
	 */
624
	protected $vasLength = 100;
625
626
	/**
627
	 * The number of increments stored on a vas line
628
	 * 
629
	 * @var mixed  Defaults to 100. 
630
	 * @since 2010-09-20
631
	 */
632
	protected $vasIncrements = 100;
633
634
	/**
22 by azammitdcarf
Updated test_questionnaire.xml variable names
635
	 * The text to separate parent text and subquestion text
636
	 * 
637
	 * @var string  Defaults to " : ". 
638
	 * @since 2010-09-22
639
	 */
640
	protected $subQuestionTextSeparator = " : ";
641
642
	/**
32 by azammitdcarf
Added support for questionnaireInfo after element
643
	 * The top margin for questionnaireInfo section
644
	 * 
645
	 * @var mixed  Defaults to 5. 
646
	 * @since 2010-10-29
647
	 */
93 by Adam Zammit
Added paginiation improvements and bug fixes from downstream (LimeSurvey) thank you mfaber!
648
	protected $questionnaireInfoMargin = 5;
32 by azammitdcarf
Added support for questionnaireInfo after element
649
650
	/**
34 by azammitdcarf
Replaced drawing using HTML tables with TCPDF Multicell to allow for aligning text vertically
651
	 * Height of a response label
652
	 * 
653
	 * @var resource  Defaults to 10. 
654
	 * @since 2010-11-05
655
	 */
656
	protected $responseLabelHeight = 10;
657
658
	/**
659
	 * Font size for response label
660
	 * 
661
	 * @var resource  Defaults to 8. 
662
	 * @since 2010-11-05
663
	 */
73 by azammitdcarf
Updated font sizes to match default widths a bit better
664
	protected $responseLabelFontSize = 7.5;
665
666
	/**
667
	 * A smaller font size for response labels where otherwise will break the line
668
	 * 
669
	 * @var resource  Defaults to 6. 
670
	 * @since 2012-03-30
671
	 */
672
	protected $responseLabelFontSizeSmall = 6.5;
673
674
	/**
74 by azammitdcarf
Typo fix
675
	 * Reduce the font size of a response label if any words are longer than this
73 by azammitdcarf
Updated font sizes to match default widths a bit better
676
	 * 
677
	 * @var resource  Defaults to 7. 
678
	 * @since 2012-03-30
679
	 */
74 by azammitdcarf
Typo fix
680
	protected $responseLabelSmallWordLength = 7;
34 by azammitdcarf
Replaced drawing using HTML tables with TCPDF Multicell to allow for aligning text vertically
681
	
682
	/**
683
	 * Font size for response text
684
	 * 
685
	 * @var resource  Defaults to 10. 
686
	 * @since 2010-11-05
687
	 */
688
	protected $responseTextFontSize = 10;
689
690
	/**
691
	 * Font size of the skip to text
692
	 * 
693
	 * @var string  Defaults to 8. 
694
	 * @since 2010-11-05
695
	 */
696
	protected $skipToTextFontSize = 8;
697
698
	/**
699
	 * Default font
700
	 * 
701
	 * @var string  Defaults to 'freeserif'. 
702
	 * @since 2010-11-05
703
	 */
704
	protected $defaultFont = 'freeserif';
705
706
	/**
707
	 * Height of a section break in mm
708
	 * 
709
	 * @var string  Defaults to 18. 
710
	 * @since 2010-11-05
711
	 */
712
	protected $sectionHeight = 18;
713
714
	/**
73 by azammitdcarf
Updated font sizes to match default widths a bit better
715
	 * Return the length of the longest word
716
	 * 
717
	 * @param mixed $txt   
718
	 * 
719
	 * @return int Length of longest word
720
	 * @author Adam Zammit <adam.zammit@acspri.org.au>
721
	 * @since  2012-03-30
722
	 */
723
	protected function wordLength($txt)
724
	{
725
		$words = explode(' ', $txt);
726
		$length = 0;
727
		foreach($words as $v)
728
		{
729
			if(strlen($v) > $length)
730
				$length = strlen($v);
731
		}
732
		return $length;
733
	}
734
735
	/**
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
736
	 * Add a box group to the page layout system
737
	 *
738
	 * VALUES(0, 'Temporary');
739
	 * VALUES(1, 'Single choice');
740
	 * VALUES(2, 'Multiple choice');
741
	 * VALUES(3, 'Text');
742
	 * VALUES(4, 'Number');
743
	 * VALUES(5, 'Barcode');
744
	 * VALUES(6, 'Long text');
745
	 * 
746
	 * @param int $type The type of box group for verification purposes
747
	 * @param string $varname The variable name
748
	 * @param string $label   The label for the box group Optional, defaults to "". 
749
	 * @param int $width   The width of this group Optional, defaults to 1. 
750
	 * 
751
	 * @author Adam Zammit <adam.zammit@acspri.org.au>
752
	 * @since  2010-09-02
753
	 */
754
	protected function addBoxGroup($type,$varname,$label = "", $width = 1)
755
	{
756
		$this->boxGroupCP++;
757
		$this->layout[$this->layoutCP]['boxgroup'][$this->boxGroupCP] = 
758
			array(	'type' => $type, 
759
				'width' => $width,
760
				'varname' => $varname,
761
				'sortorder' => $this->boxGroupCP,
762
				'label' => $label,
763
				'groupsection' => $this->sectionCP,
764
				'box' => array());
765
	}
766
72 by azammitdcarf
Create a new box group for each line of text items with identical variable names. Will display better in queXF. Note - queXF should try and concatenate if variable names are the same
767
	/**
768
	 * Add a new box group which is a copy of the previous one (if exists)
769
	 * 
770
	 * @author Adam Zammit <adam.zammit@acspri.org.au>
771
	 * @since  2012-03-26
772
	 */
773
	protected function addBoxGroupCopyPrevious()
774
	{		
775
		if (isset($this->layout[$this->layoutCP]['boxgroup'][$this->boxGroupCP]))
776
		{
777
			$a = $this->layout[$this->layoutCP]['boxgroup'][$this->boxGroupCP];
778
			$this->addBoxGroup($a['type'],$a['varname'],$a['label']);
779
		}
780
	}
781
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
782
783
	/**
784
	 * Add a box to the page layout system
785
	 * 
786
	 * @param int $tlx   Top left X
787
	 * @param int $tly   Top left Y
788
	 * @param int  $brx   Bottom right X
789
	 * @param int  $bry   Bottom right Y
790
	 * @param string $value Optional, defaults to "". 
791
	 * @param string $label Optional, defaults to "". 
792
	 * 
793
	 */
794
	protected function addBox($tlx,$tly,$brx,$bry,$value = "",$label = "")
795
	{
796
		$this->boxCP++;
797
		$this->layout[$this->layoutCP]['boxgroup'][$this->boxGroupCP]['box'][] = 
798
			array(	'tlx' => $this->mm2px($tlx),
799
				'tly' => $this->mm2px($tly),
800
				'brx' => $this->mm2px($brx),
801
				'bry' => $this->mm2px($bry),
802
				'value' => $value,
803
				'label'=> $label,
804
				);
805
806
		//Update the width of the parent boxgroup given its type and this additional box
807
		$type = $this->layout[$this->layoutCP]['boxgroup'][$this->boxGroupCP]['type'];
808
		$count = count($this->layout[$this->layoutCP]['boxgroup'][$this->boxGroupCP]['box']);
809
		$width = $this->layout[$this->layoutCP]['boxgroup'][$this->boxGroupCP]['width'];
810
	
811
		switch($type){
812
			case 1: //Single choice 
813
			case 2: //Multiple choice
814
				if (strlen($value) > $width) $width = strlen($value);
815
				if (strlen($count) > $width) $width = strlen($count);
816
				break;
817
			case 3: //Text
818
			case 4: //Numbers
819
				$width = $count;
820
				break;
821
			case 6: //Longtext
822
				$width = $this->longTextStorageWidth;
823
		}
824
825
		$this->layout[$this->layoutCP]['boxgroup'][$this->boxGroupCP]['width'] = $width;
826
	}
827
828
829
	/**
89 by Adam Zammit
Allow for the specifying of sectionHeight
830
	 * Set the minimum section height
831
	 * 
832
	 * @param int $height The minimum height of a section
833
	 * 
834
	 * @author Adam Zammit <adam.zammit@acspri.org.au>
835
	 * @since  2013-07-30
836
	 */
837
	public function setSectionHeight($height)
838
	{
839
		$height = intval($height);
840
		if ($height < 0) $height = 1;
841
		$this->sectionHeight = $height;
842
	}
843
844
	/**
845
	 * Get the section height
846
	 * 
847
	 * @return The section height
848
	 * @author Adam Zammit <adam.zammit@acspri.org.au>
849
	 * @since  2013-07-30
850
	 */
851
	public function getSectionHeight()
852
	{
853
		return $this->sectionHeight;
854
	}
855
856
	/**
86 by azammitdcarf
Add setters and getters for font size and style
857
	 * Get the response label font sizes (normal and small)
858
	 * 
859
	 * @return array containing the normal font size as the first element and small as second
860
	 * @author Adam Zammit <adam.zammit@acspri.org.au>
861
	 * @since  2013-04-10
862
	 */
863
	public function getResponseLabelFontSize()
864
	{
865
		return array($this->responseLabelFontSize,$this->responseLabelFontSizeSmall);
866
	}
867
868
	/**
869
	 * Set the response label font sizes
870
	 * 
871
	 * @param array $sizes normal font size first then small
872
	 * 
873
	 * @author Adam Zammit <adam.zammit@acspri.org.au>
874
	 * @since  2013-04-10
875
	 */
876
	public function setResponseLabelFontSize($sizes)
877
	{
878
		$this->responseLabelFontSize = intval($sizes[0]);
879
		$this->responseLabelFontSizeSmall = intval($sizes[1]);
880
	}
881
882
	/**
883
	 * Get the response text font size
884
	 * 
885
	 * @return int The response text font size
886
	 * @author Adam Zammit <adam.zammit@acspri.org.au>
887
	 * @since  2013-04-10
888
	 */
889
	public function getResponseTextFontSize()
890
	{
891
		return $this->responseTextFontSize;
892
	}
893
894
	/**
895
	 * Set the response text font size
896
	 * 
897
	 * @param int $size 
898
	 * 
899
	 * @author Adam Zammit <adam.zammit@acspri.org.au>
900
	 * @since  2013-04-10
901
	 */
902
	public function setResponseTextFontSize($size)
903
	{
904
		$this->responseTextFontSize = intval($size);
905
	}
906
907
	/**
908
	 * Get the style without any HTML/etc formatting
909
	 * 
910
	 * @return string The style without HTML or tabs
911
	 * @author Adam Zammit <adam.zammit@acspri.org.au>
912
	 * @since  2013-04-10
913
	 */
914
	public function getStyle()
915
	{
916
		return strip_tags(str_replace("\t","",$this->style));
917
	}
918
919
	/**
920
	 * Set the CSS styling of some questionnaire elements
921
	 * 
922
	 * @param string $style The CSS styling of some questionnire elements
923
	 * 
924
	 * @return none
925
	 * @author Adam Zammit <adam.zammit@acspri.org.au>
926
	 * @since  2013-04-10
927
	 */
928
	public function setStyle($style)
929
	{
930
		$this->style = "<style>" . $style . "</style>";
931
	}
932
933
	/**
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
934
	 * Export the layout as an XML file
935
	 * 
936
	 * @return string The XML layout in queXF Banding XML format
937
	 * @author Adam Zammit <adam.zammit@acspri.org.au>
938
	 * @since  2010-09-20
939
	 */
940
	public function getLayout()
941
	{
21 by azammitdcarf
Replaced manual XML function with DOM (required PHP 5)
942
		$doc = new DomDocument('1.0');
943
		$root = $doc->createElement('queXF');
944
945
		$q = $doc->createElement('questionnaire');
946
947
		$id = $doc->createElement('id');
948
		$value = $doc->createTextNode($this->questionnaireId);
949
		$id->appendChild($value);
950
		$q->appendChild($id);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
951
952
		foreach($this->section as $key => $val)
953
		{
21 by azammitdcarf
Replaced manual XML function with DOM (required PHP 5)
954
			$s = $doc->createElement('section');
955
			$s->setAttribute('id',$key);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
956
			foreach ($val as $sk => $sv)
21 by azammitdcarf
Replaced manual XML function with DOM (required PHP 5)
957
			{
958
				$tmpe = $doc->createElement($sk);
959
				$tmpv = $doc->createTextNode($sv);
960
				$tmpe->appendChild($tmpv);
961
				$s->appendChild($tmpe);
962
			}
963
			$q->appendChild($s);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
964
		}
965
		foreach($this->layout as $key => $val)
966
		{
21 by azammitdcarf
Replaced manual XML function with DOM (required PHP 5)
967
			$p = $doc->createElement('page');
968
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
969
			foreach ($val as $pk => $pv)
21 by azammitdcarf
Replaced manual XML function with DOM (required PHP 5)
970
			{
971
				if ($pk != 'boxgroup')
972
				{	
973
					$tmpe = $doc->createElement($pk);
974
					$tmpv = $doc->createTextNode($pv);
975
					$tmpe->appendChild($tmpv);
976
					$p->appendChild($tmpe);
977
				}
978
			}
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
979
980
			foreach ($val['boxgroup'] as $bg)
981
			{
21 by azammitdcarf
Replaced manual XML function with DOM (required PHP 5)
982
				$bgE = $doc->createElement('boxgroup');
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
983
				foreach ($bg as $pk => $pv)
984
				{
21 by azammitdcarf
Replaced manual XML function with DOM (required PHP 5)
985
					if ($pk == 'groupsection')
986
					{
987
						$gs = $doc->createElement('groupsection');
988
						$gs->setAttribute('idref',$pv);
989
						$bgE->appendChild($gs);
990
					}
991
					else if ($pk != 'box')
992
					{
993
						$tmpe = $doc->createElement($pk);
994
						$tmpv = $doc->createTextNode($pv);
995
						$tmpe->appendChild($tmpv);
996
						$bgE->appendChild($tmpe);
997
					}
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
998
				}
999
1000
				foreach($bg['box'] as $b)
1001
				{
21 by azammitdcarf
Replaced manual XML function with DOM (required PHP 5)
1002
					$bE = $doc->createElement('box');
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1003
					foreach($b as $bk => $bv)
21 by azammitdcarf
Replaced manual XML function with DOM (required PHP 5)
1004
					{
1005
						$tmpe = $doc->createElement($bk);
1006
						$tmpv = $doc->createTextNode($bv);
1007
						$tmpe->appendChild($tmpv);
1008
						$bE->appendChild($tmpe);
1009
					}
1010
					$bgE->appendChild($bE);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1011
				}
21 by azammitdcarf
Replaced manual XML function with DOM (required PHP 5)
1012
				$p->appendChild($bgE);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1013
			}
21 by azammitdcarf
Replaced manual XML function with DOM (required PHP 5)
1014
			$q->appendChild($p);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1015
		}
21 by azammitdcarf
Replaced manual XML function with DOM (required PHP 5)
1016
		$root->appendChild($q);
1017
		$doc->appendChild($root);
1018
		$doc->formatOutput = true; //make it look nice
1019
		return $doc->saveXML();
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1020
	}
1021
1022
	/**
34 by azammitdcarf
Replaced drawing using HTML tables with TCPDF Multicell to allow for aligning text vertically
1023
	 * Set font size and style
1024
	 * 
1025
	 * @param string $size  Optional, defaults to 12
1026
	 * @param string $style Optional, defaults to ''. 
1027
	 * 
1028
	 * @return TODO
1029
	 * @author Adam Zammit <adam.zammit@acspri.org.au>
1030
	 * @since  2010-11-05
1031
	 */
1032
	protected function setDefaultFont($size = 12,$style = '')
1033
	{
1034
		$this->SetFont($this->defaultFont,$style);
1035
		$this->SetFontSize($size);
1036
	}
1037
1038
	/**
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1039
	 * Initialise TCPDF width some default values and embedded fonts
1040
	 * 
1041
	 * @return TODO
1042
	 * @author Adam Zammit <adam.zammit@acspri.org.au>
1043
	 * @since  2010-09-20
1044
	 */
1045
	protected function init()
1046
	{
1047
		if ($this->embedFonts)
1048
		{
1049
			$this->setFontSubsetting(false); //we want full subsetting
1050
			$this->AddFont('freesans','');
1051
			$this->AddFont('freesans','B');
1052
			$this->AddFont('freesans','I');
1053
			$this->AddFont('freesans','BI');
1054
			$this->AddFont('freeserif','');
1055
			$this->AddFont('freeserif','B');
1056
			$this->AddFont('freeserif','I');
1057
			$this->AddFont('freeserif','BI');
1058
			
34 by azammitdcarf
Replaced drawing using HTML tables with TCPDF Multicell to allow for aligning text vertically
1059
			$this->SetFont($this->defaultFont);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1060
		}
1061
		
1062
		// set document information
1063
		$this->SetCreator('queXMLPDF (http://quexml.sourceforge.net)');
1064
		$this->SetAuthor('Adam Zammit <adam.zammit@acspri.org.au>');
1065
		$this->SetTitle('queXML Document');
1066
		$this->SetSubject('queXML');
1067
		$this->SetKeywords('queXML queXF');
75 by azammitdcarf
Made output colours|colors greyscale|grayscale
1068
1069
		//set text colour
1070
		$this->SetTextColor($this->textColour);
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
1071
1072
		//set column pointer
1073
		$this->columnCP = -1;
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1074
	}
1075
1076
	/**
1077
	 * Override of TCPDF Header function to blank
1078
	 * 
1079
	 * @author Adam Zammit <adam.zammit@acspri.org.au>
1080
	 * @since  2010-09-20
1081
	 */
1082
	public function Header(){
1083
	}
1084
1085
	/**
1086
	 * Override of TCPDF Footer function to blank
1087
	 * 
1088
	 * @author Adam Zammit <adam.zammit@acspri.org.au>
1089
	 */
1090
	public function Footer(){
1091
	}
1092
1093
	/**
1094
	 * Set the background wash of the page
1095
	 * 
1096
	 * @param mixed $type Optional, defaults to 'empty'. 
1097
	 * 
1098
	 * @author Adam Zammit <adam.zammit@acspri.org.au>
1099
	 * @since  2010-09-02
1100
	 */
1101
	protected function setBackground($type = 'empty')
1102
	{
1103
		switch ($type) {
1104
			case 'question':
75 by azammitdcarf
Made output colours|colors greyscale|grayscale
1105
				$this->SetFillColor($this->backgroundColourQuestion[0]);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1106
				break;
1107
			case 'section':
75 by azammitdcarf
Made output colours|colors greyscale|grayscale
1108
				$this->SetFillColor($this->backgroundColourSection[0]);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1109
				break;
1110
			case 'empty':
75 by azammitdcarf
Made output colours|colors greyscale|grayscale
1111
				$this->SetFillColor($this->backgroundColourEmpty[0]);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1112
				break;
1113
1114
		}
1115
	}
1116
1117
	/*
1118
	 * The X coordinate of the start of the page proper
1119
	 * 
1120
	 * @return int The X coordinate of the start of the page
1121
	 * @author Adam Zammit <adam.zammit@acspri.org.au>
1122
	 * @since  2010-09-02
1123
	 */
1124
	public function getMainPageX()
1125
	{
1126
		return ($this->cornerBorder + $this->cornerWidth);
1127
	}
1128
1129
	/**
77 by azammitdcarf
Set column pointer default to 0
1130
	 * The X coordinate of the start of the column
1131
	 * 
1132
	 * @return int The X coordinate of the start of the current column
1133
	 * @author Adam Zammit <adam.zammit@acspri.org.au>
1134
	 * @since  2012-05-30
1135
	 */
1136
	public function getColumnX()
1137
	{
79 by azammitdcarf
Added a divider between columns
1138
		$border = 0;
1139
		if ($this->columnCP > 0) 
1140
			$border = $this->columnBorder;
1141
		return $this->getMainPageX() + ($this->columnCP  * ($this->getColumnWidth() + $border)) + $border;
77 by azammitdcarf
Set column pointer default to 0
1142
	}
1143
1144
	/**
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1145
	 * The width of the writeable page
1146
	 * 
1147
	 * @return int The width of the writeable page
1148
	 * @author Adam Zammit <adam.zammit@acspri.org.au>
1149
	 * @since  2010-09-02
1150
	 */
1151
	public function getMainPageWidth()
1152
	{
1153
		return ($this->getPageWidth() - (($this->cornerBorder * 2.0) + ($this->cornerWidth * 2.0)));
1154
	}
1155
1156
	/**
77 by azammitdcarf
Set column pointer default to 0
1157
	 * The width of the writable column
1158
	 * 
1159
	 * @return int The width of the current column
1160
	 * @author Adam Zammit <adam.zammit@acspri.org.au>
1161
	 * @since  2012-05-30
1162
	 */
1163
	public function getColumnWidth()
1164
	{
79 by azammitdcarf
Added a divider between columns
1165
		$border = 0;
1166
		if ($this->columnCP > 0) 
1167
			$border = $this->columnBorder;
1168
		return ((1 / $this->columns) * $this->getMainPageWidth()) - $border;
77 by azammitdcarf
Set column pointer default to 0
1169
	}
1170
1171
	/**
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1172
	 * Draw a horizontal response box with possible eye guides and arrows
1173
	 * 
1174
	 * @param int $x The x position of the box area (top left)
1175
	 * @param int $y The y position of the box area (top left)
1176
	 * @param string $position What position the box is in for the eye guides
1177
	 * @param bool $downarrow Draw a down arrow?
1178
	 * @param bool $rightarrow Draw an arrow to the right?
30 by azammitdcarf
Horizontal box function respects box widths
1179
	 * @param bool $smallwidth Whether or not to use the small width
82 by azammitdcarf
Added defaultValue attribute to responses to allow for pre-filling
1180
	 * @param bool $filled Whether or not to have the box pre-filled
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1181
	 *
1182
	 */
82 by azammitdcarf
Added defaultValue attribute to responses to allow for pre-filling
1183
	protected function drawHorizontalResponseBox($x,$y,$position = 'only',$downarrow = false, $rightarrow = false, $smallwidth = false, $filled =false)
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1184
	{
75 by azammitdcarf
Made output colours|colors greyscale|grayscale
1185
		$this->SetDrawColor($this->lineColour[0]);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1186
		$this->SetLineWidth($this->singleResponseBoxBorder);
1187
1188
		//centre for the line
60 by azammitdcarf
Made border 14mm instead of 15mm to fit a bit more on to page ($cornerBorder)
1189
		$boxmid = ($y + ($this->singleResponseHorizontalHeight / 2.0));
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1190
1191
		//centre on y
60 by azammitdcarf
Made border 14mm instead of 15mm to fit a bit more on to page ($cornerBorder)
1192
		$y = $y + (($this->singleResponseHorizontalHeight - $this->singleResponseBoxHeight) / 2.0);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1193
		
30 by azammitdcarf
Horizontal box function respects box widths
1194
		if ($smallwidth) 
1195
			$areawidth = $this->singleResponseVerticalAreaWidthSmall;
1196
		else		
1197
			$areawidth = $this->singleResponseVerticalAreaWidth;
1198
1199
1200
		$linelength = (($areawidth - $this->singleResponseBoxWidth) / 2.0);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1201
1202
		$this->SetLineStyle(array('dash' => '1'));
1203
1204
		if ($position == 'last' || $position == 'middle') 
1205
		{
1206
			$this->Line($x, $boxmid, $x + $linelength,$boxmid);
1207
		}
1208
		if ($position == 'first' || $position == 'middle')
1209
		{
1210
			$this->Line($x + $linelength + $this->singleResponseBoxWidth, $boxmid, $x + ($linelength * 2) + $this->singleResponseBoxWidth,$boxmid);
1211
		}
1212
1213
		$this->SetLineStyle(array('dash' => '0'));
1214
1215
		$this->Rect($x + $linelength,$y,$this->singleResponseBoxWidth,$this->singleResponseBoxHeight,'DF',array(),$this->backgroundColourEmpty);
82 by azammitdcarf
Added defaultValue attribute to responses to allow for pre-filling
1216
88 by Adam Zammit
Allow for contingentQuestions to be specified on subQuestions (for matrix "Other")
1217
		if ($downarrow)
1218
		{
1219
			$boxmiddle = ($x + ($this->singleResponseBoxWidth / 2.0)) + $linelength;
1220
			$this->SetFillColor($this->lineColour[0]);
1221
			$this->Polygon(array($x + $linelength, $y + $this->singleResponseBoxHeight, $boxmiddle, $y + $this->singleResponseBoxHeight + $this->arrowHeight, $x + $linelength + $this->singleResponseBoxWidth, $y + $this->singleResponseBoxHeight),'DF',array(),$this->lineColour);
1222
			$this->setBackground('empty');	
1223
		}
1224
82 by azammitdcarf
Added defaultValue attribute to responses to allow for pre-filling
1225
		if ($filled)
1226
		{
1227
			//draw a cross
1228
			$this->SetLineWidth($this->defaultValueLineWidth);
1229
			$this->Line($x + $linelength, $y, $x + $linelength + $this->singleResponseBoxWidth, $y + $this->singleResponseBoxHeight);
1230
			$this->Line($x + $linelength + $this->singleResponseBoxWidth, $y, $x + $linelength, $y + $this->singleResponseBoxHeight);
1231
		}
1232
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1233
		$this->setBackground('question');		
1234
		return array($x + $linelength,$y,$x + $linelength + $this->singleResponseBoxWidth, $y + $this->singleResponseBoxHeight); //return the posistion for banding
1235
	}
1236
1237
	/**
1238
	 * Draw a vertical response box with possible eye guides and arrows
1239
	 * 
1240
	 * @param int $x The x position of the box area (top left)
1241
	 * @param int $y The y position of the box area (top left)
1242
	 * @param string $position What position the box is in for the eye guides
1243
	 * @param bool $downarrow Draw a down arrow?
1244
	 * @param bool $rightarrow Draw an arrow to the right?
82 by azammitdcarf
Added defaultValue attribute to responses to allow for pre-filling
1245
	 * @param bool $filled Whether or not to have the box pre-filled
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1246
	 *
1247
	 */
82 by azammitdcarf
Added defaultValue attribute to responses to allow for pre-filling
1248
	protected function drawVerticalResponseBox($x,$y,$position = 'only',$downarrow = false, $rightarrow = false, $filled = false)
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1249
	{
75 by azammitdcarf
Made output colours|colors greyscale|grayscale
1250
		$this->SetDrawColor($this->lineColour[0]);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1251
		$this->SetLineWidth($this->singleResponseBoxBorder);
1252
	
1253
		if (!$downarrow)
1254
		{
67 by azammitdcarf
Centered singe response better (I think)
1255
			$y = $y + (($this->singleResponseAreaHeight - $this->singleResponseBoxHeight) / 2.0);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1256
		}
1257
1258
		$boxmid = ($x + ($this->singleResponseBoxWidth / 2.0));
1259
		if ($position == 'first' || $position == 'middle') 
1260
		{
1261
			$this->Line($boxmid, ($y + $this->singleResponseBoxHeight), $boxmid, ($y + $this->singleResponseBoxHeight + $this->singleResponseBoxLineLength));
1262
		}
1263
		if ($position == 'last' || $position == 'middle')
1264
		{
1265
			$this->Line($boxmid, $y, $boxmid, ($y - $this->singleResponseBoxLineLength));
1266
		}
1267
1268
		if ($downarrow)
1269
		{
75 by azammitdcarf
Made output colours|colors greyscale|grayscale
1270
			$this->SetFillColor($this->lineColour[0]);
1271
			$this->Polygon(array($x, $y + $this->singleResponseBoxHeight, $boxmid, $y + $this->singleResponseBoxHeight + $this->arrowHeight, $x + $this->singleResponseBoxWidth, $y + $this->singleResponseBoxHeight),'DF',array(),$this->lineColour);
1272
			$this->setBackground('empty');	
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1273
		}
1274
1275
		if ($rightarrow !== false)
1276
		{
1277
			//Draw skipto
1278
			$boxymid = ($y + ($this->singleResponseBoxHeight / 2.0));
75 by azammitdcarf
Made output colours|colors greyscale|grayscale
1279
			$this->SetFillColor($this->lineColour[0]);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1280
			$this->Polygon(array($x + $this->singleResponseBoxWidth, $y, $x + $this->singleResponseBoxWidth + $this->arrowHeight, $boxymid, $x + $this->singleResponseBoxWidth, $y + $this->singleResponseBoxHeight),'DF',array(),$this->lineColour);	
75 by azammitdcarf
Made output colours|colors greyscale|grayscale
1281
			$this->setBackground('empty');	
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1282
			//Now draw the text
1283
1284
			//Start at $x + singleResponseboxWidth + arrowHeight, $y - siongleresponseboxlinelength and go to $skipcolumnwidth wide and singleresponseareHeight high
1285
			$this->setBackground('question');		
34 by azammitdcarf
Replaced drawing using HTML tables with TCPDF Multicell to allow for aligning text vertically
1286
			$text =  $this->skipToText . $rightarrow;
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1287
			$ypos = $this->GetY();
34 by azammitdcarf
Replaced drawing using HTML tables with TCPDF Multicell to allow for aligning text vertically
1288
1289
			$this->setDefaultFont($this->skipToTextFontSize,'B');
1290
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
1291
			$this->MultiCell($this->skipColumnWidth,$this->singleResponseBoxHeight,$text,0,'L',false,0,(($this->getColumnWidth() + $this->getColumnX()) - $this->skipColumnWidth),$y,true,0,false,true,$this->singleResponseBoxHeight,'M',true);
34 by azammitdcarf
Replaced drawing using HTML tables with TCPDF Multicell to allow for aligning text vertically
1292
35 by azammitdcarf
Use setDefaultFont function instead of SetFont
1293
			//Reset to non bold as causing problems with TCPDF HTML CSS conversion
1294
			$this->setDefaultFont($this->skipToTextFontSize,'');
34 by azammitdcarf
Replaced drawing using HTML tables with TCPDF Multicell to allow for aligning text vertically
1295
1296
			//$this->writeHTMLCell($this->skipColumnWidth, 0, $this->getPageWidth() - $this->getMainPageX() - $this->skipColumnWidth ,$y, $this->style . $html,0,0,true,true,'C',true);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1297
			$this->SetY($ypos,false);
1298
		}
1299
1300
		$this->Rect($x,$y,$this->singleResponseBoxWidth,$this->singleResponseBoxHeight,'DF',array(),$this->backgroundColourEmpty);
82 by azammitdcarf
Added defaultValue attribute to responses to allow for pre-filling
1301
1302
		if ($filled)
1303
		{
1304
			//draw a cross
1305
			$this->SetLineWidth($this->defaultValueLineWidth);
1306
			$this->Line($x, $y, $x + $this->singleResponseBoxWidth, $y + $this->singleResponseBoxHeight);
1307
			$this->Line($x + $this->singleResponseBoxWidth, $y, $x, $y + $this->singleResponseBoxHeight);
1308
		}
1309
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1310
		$this->setBackground('question');		
1311
		return array($x,$y,$x + $this->singleResponseBoxWidth, $y + $this->singleResponseBoxHeight); //return the posistion for banding
1312
	}
1313
1314
1315
	/**
1316
	 * Return capital letter(s) corresponding to the given number
1317
	 * 
1318
	 * @param integer $number 
1319
	 * 
1320
	 * @return string Letter(s) corresponding to the number
1321
	 * @author Adam Zammit <adam.zammit@acspri.org.au>
1322
	 * @since  2010-09-08
1323
	 */
1324
	public function numberToLetter($number)
1325
	{
1326
		if ($number < 1) $number = 1;
1327
1328
		if ($number > 26)
1329
			return chr((($number - 1) / 26) + 64) . chr((($number - 1) % 26) + 65);
1330
		else
1331
			return chr($number + 64);
1332
	}
1333
1334
1335
	/**
24 by azammitdcarf
Added example file and added get(er) function for questionnaireId
1336
	 * Get the questionnaire id
1337
	 * 
1338
	 * @return int The questionnaire Id
1339
	 * @author Adam Zammit <adam.zammit@acspri.org.au>
1340
	 * @since  2010-09-23
1341
	 */
1342
	public function getQuestionnaireId()
1343
	{
1344
		return $this->questionnaireId;
1345
	}
1346
1347
	/**
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1348
	 * Converts a queXML file to the array format required for the create function
1349
	 * 
1350
	 * @param string $quexml The queXML file
1351
	 *
1352
	 * @return array An array readable by create 
1353
	 * @author Adam Zammit <adam.zammit@acspri.org.au>
1354
	 * @since  2010-09-08
1355
	 * @see create
1356
	 */
1357
	public function createqueXML($quexml)
1358
	{
1359
		$xml = new SimpleXMLElement($quexml);
1360
	
1361
		$q = array();
1362
1363
		$scount = 1;
1364
		$sl = "";
1365
25 by azammitdcarf
Don't need to look for current ID
1366
		$q['id'] = $xml['id'];
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1367
32 by azammitdcarf
Added support for questionnaireInfo after element
1368
		foreach ($xml->questionnaireInfo as $qitmp)
1369
		{
1370
			if ($qitmp->position == 'after')
1371
			{
1372
				if (!isset($q['infoafter']))
1373
					$q['infoafter'] = "";
1374
35 by azammitdcarf
Use setDefaultFont function instead of SetFont
1375
				$q['infoafter'] .= $qitmp->text . "<br/><br/>";
32 by azammitdcarf
Added support for questionnaireInfo after element
1376
			}
41 by azammitdcarf
Added support for questionnaireInfo position=before element
1377
			else if ($qitmp->position == 'before')
1378
			{
1379
				if (!isset($q['infobefore']))
1380
					$q['infobefore'] = "";
1381
1382
				$q['infobefore'] .= $qitmp->text . "<br/><br/>";
1383
			}
32 by azammitdcarf
Added support for questionnaireInfo after element
1384
		}
1385
	
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1386
		foreach($xml->section as $s)
1387
		{
1388
			$stmp = array();
1389
			$sl = $this->numberToLetter($scount);
33 by azammitdcarf
Updated background colour to be lighter and inline with queXML FO
1390
			$stmp['title'] = "Section " . $sl;
46 by azammitdcarf
Updated code to remove noticies from Limesurvey bug: 05090
1391
			$stmp['info'] = "";
47 by azammitdcarf
Made section text always appear
1392
			$stmp['text'] = "";
92 by Adam Zammit
Don't add a newline for sectionInfo unless there is more than one line
1393
			$bfc = 0;	
1394
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1395
			foreach ($s->sectionInfo as $sitmp)
1396
			{
27 by azammitdcarf
Fixed missing references to $this->lineColour
1397
				if ($sitmp->position == 'title')
1398
				{
1399
					$stmp['text'] .= $sitmp->text;
1400
				}
29 by azammitdcarf
Cleaned up CSS
1401
				if ($sitmp->position == 'before' || $sitmp->position == 'during')
1402
				{
92 by Adam Zammit
Don't add a newline for sectionInfo unless there is more than one line
1403
					$stmp['info'] .= $sitmp->text;
1404
1405
					if ($bfc > 0) 
1406
						$stmp['info'] .= "<br/>";
1407
1408
					$bfc++;
29 by azammitdcarf
Cleaned up CSS
1409
				}
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1410
			}
1411
			
1412
			$qcount = 1;
1413
			foreach ($s->question as $qu)
1414
			{
1415
				$qtmp = array();
1416
				$rstmp = array();
1417
				
66 by azammitdcarf
Added a skipTo registry - so question titles can be bolded where there is a skip to them
1418
				$qtmp['title'] = $sl . $qcount . $this->questionTitleSuffix;
90 by Adam Zammit
Allow for hiding of the question title
1419
1420
				if (isset($qu['hidetitle']) && $qu['hidetitle'] == "true") 
1421
					$qtmp['hidetitle'] = "true";
1422
46 by azammitdcarf
Updated code to remove noticies from Limesurvey bug: 05090
1423
				$qtmp['text'] = "";
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1424
1425
				foreach ($qu->text as $ttmp)
27 by azammitdcarf
Fixed missing references to $this->lineColour
1426
				{
33 by azammitdcarf
Updated background colour to be lighter and inline with queXML FO
1427
					//Add a new line if we aren't at the end
1428
					if ($ttmp != end($qu->text)){ $qtmp['text'] .= "<br/>"; } 
1429
					
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1430
					$qtmp['text'] .= $ttmp;
27 by azammitdcarf
Fixed missing references to $this->lineColour
1431
				}
63 by azammitdcarf
Replaced $questionTextWidth with $questionTextRightMargin to manage varying page widths better
1432
			
1433
				foreach ($qu->specifier as $ttmp)
1434
				{
1435
					if (!isset($qtmp['specifier']))
1436
						$qtmp['specifier'] = "";
1437
1438
					$qtmp['specifier'] .= $ttmp;
1439
				}
1440
	
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1441
				foreach ($qu->directive as $ttmp)
27 by azammitdcarf
Fixed missing references to $this->lineColour
1442
				{
64 by azammitdcarf
Limit help text the right spot
1443
					if ($ttmp->administration == 'self' && $ttmp->position == 'during')
27 by azammitdcarf
Fixed missing references to $this->lineColour
1444
					{
1445
						if (!isset($qtmp['helptext']))
1446
							$qtmp['helptext'] = "";
1447
1448
						$qtmp['helptext'] .= $ttmp->text;
1449
					}
29 by azammitdcarf
Cleaned up CSS
1450
					if ($ttmp->administration == 'self' && $ttmp->position == 'after')
1451
					{
1452
						if (!isset($qtmp['helptextafter']))
1453
							$qtmp['helptextafter'] = "";
1454
1455
						$qtmp['helptextafter'] .= $ttmp->text;
1456
					}
63 by azammitdcarf
Replaced $questionTextWidth with $questionTextRightMargin to manage varying page widths better
1457
					if ($ttmp->administration == 'self' && $ttmp->position == 'before')
1458
					{
1459
						if (!isset($qtmp['helptextbefore']))
1460
							$qtmp['helptextbefore'] = "";
1461
1462
						$qtmp['helptextbefore'] .= $ttmp->text;
1463
					}
27 by azammitdcarf
Fixed missing references to $this->lineColour
1464
				}
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1465
1466
				foreach ($qu->subQuestion as $sq)
1467
				{
1468
					$sqtmp = array();
46 by azammitdcarf
Updated code to remove noticies from Limesurvey bug: 05090
1469
					$sqtmp['text'] = "";
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1470
					foreach ($sq->text as $ttmp)
40 by azammitdcarf
Added check to avoid warning
1471
					{
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1472
						$sqtmp['text'] .= $ttmp;
40 by azammitdcarf
Added check to avoid warning
1473
					}
26 by azammitdcarf
Removed current() where not necessary
1474
					$sqtmp['varname'] = $sq['varName'];
82 by azammitdcarf
Added defaultValue attribute to responses to allow for pre-filling
1475
1476
					if (isset($sq['defaultValue'])) 
1477
						$sqtmp['defaultvalue'] = $sq['defaultValue'];
1478
88 by Adam Zammit
Allow for contingentQuestions to be specified on subQuestions (for matrix "Other")
1479
					if (isset($sq->contingentQuestion))
1480
					{
1481
						//Need to handle contingent questions
1482
						$oarr = array();
1483
						$oarr['width'] = current($sq->contingentQuestion->length);
1484
						$oarr['text'] = current($sq->contingentQuestion->text);
1485
91 by root
Added format to contingentQuestion attribute
1486
						$oarr['format'] = 'text';
1487
					
1488
						if (isset($sq->contingentQuestion->format))
1489
							$oarr['format'] = current($sq->contingentQuestion->format);
1490
88 by Adam Zammit
Allow for contingentQuestions to be specified on subQuestions (for matrix "Other")
1491
						if (isset($sq->contingentQuestion['defaultValue'])) 
1492
							$oarr['defaultvalue'] = $sq->contingentQuestion['defaultValue'];
1493
91 by root
Added format to contingentQuestion attribute
1494
						$oarr['varname'] = $sq->contingentQuestion['varName'];
88 by Adam Zammit
Allow for contingentQuestions to be specified on subQuestions (for matrix "Other")
1495
						$sqtmp['other'] = $oarr;
1496
					}	
1497
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1498
					$rstmp['subquestions'][] = $sqtmp;
1499
				}
1500
1501
				foreach ($qu->response as $r)
1502
				{
1503
					$rtmp = array();
26 by azammitdcarf
Removed current() where not necessary
1504
					$rstmp['varname'] = $r['varName'];
82 by azammitdcarf
Added defaultValue attribute to responses to allow for pre-filling
1505
1506
					if (isset($r['defaultValue'])) 
1507
						$rstmp['defaultvalue'] = $r['defaultValue'];
1508
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1509
					if (isset($r->fixed))
1510
					{
1511
						$rtmp['type'] = 'fixed';
1512
						$rtmp['width'] = count($r->fixed->category);
1513
						if ($r->fixed['rotate'] == "true") 
1514
							$rtmp['rotate'] = "true";
89 by Adam Zammit
Allow for the specifying of sectionHeight
1515
						if ($r->fixed['separate'] == "true") 
1516
							$rtmp['separate'] = "true";
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1517
						$ctmp = array();
1518
						foreach ($r->fixed->category as $c)
1519
						{
1520
							$cat = array();
1521
							$cat['text'] = current($c->label);
1522
							$cat['value'] = current($c->value);
66 by azammitdcarf
Added a skipTo registry - so question titles can be bolded where there is a skip to them
1523
							if (isset($c->skipTo))
1524
							{ 
1525
								$cat['skipto'] = current($c->skipTo);
1526
								//save a skip
1527
								$this->skipToRegistry[current($c->skipTo) . $this->questionTitleSuffix] = $qtmp['title'];
1528
							}
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1529
							if (isset($c->contingentQuestion))
1530
							{
1531
								//Need to handle contingent questions
1532
								$oarr = array();
1533
								$oarr['width'] = current($c->contingentQuestion->length);
1534
								$oarr['text'] = current($c->contingentQuestion->text);
82 by azammitdcarf
Added defaultValue attribute to responses to allow for pre-filling
1535
91 by root
Added format to contingentQuestion attribute
1536
								$oarr['format'] = 'text';
1537
								
1538
								if (isset($c->contingentQuestion->format))
1539
									$oarr['format'] = current($c->contingentQuestion->format);
1540
82 by azammitdcarf
Added defaultValue attribute to responses to allow for pre-filling
1541
								if (isset($c->contingentQuestion['defaultValue'])) 
1542
									$oarr['defaultvalue'] = $c->contingentQuestion['defaultValue'];
1543
	
26 by azammitdcarf
Removed current() where not necessary
1544
								$oarr['varname'] = $c->contingentQuestion['varName'];
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1545
								$cat['other'] = $oarr;
1546
							}	
1547
							$ctmp[] = $cat;	
1548
						}
1549
						$rtmp['categories'] = $ctmp;
1550
					}
1551
					else if (isset($r->free))
1552
					{
44 by azammitdcarf
Banding XML will include number only fields where set to integer, number or numeric
1553
						$format = strtolower(trim(current($r->free->format)));
1554
						if ($format == 'longtext')
26 by azammitdcarf
Removed current() where not necessary
1555
							$rtmp['type'] = 'longtext';
44 by azammitdcarf
Banding XML will include number only fields where set to integer, number or numeric
1556
						else if ($format == 'number' || $format == 'numeric' || $format == 'integer')
1557
							$rtmp['type'] = 'number';
83 by azammitdcarf
Added free response types "codabar" and "i25" to be able to pre-draw filled barcodes a questions (using the defaultValue attribute)
1558
						else if ($format == 'i25')
1559
							$rtmp['type'] = 'i25';
1560
						else if ($format == 'codabar')
1561
							$rtmp['type'] = 'codabar';
26 by azammitdcarf
Removed current() where not necessary
1562
						else
1563
							$rtmp['type'] = 'text';
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1564
						$rtmp['width'] = current($r->free->length);
1565
						$rtmp['text'] = current($r->free->label);
1566
					}
1567
					else if (isset($r->vas))
1568
					{
1569
						$rtmp['type'] = 'vas';
48 by azammitdcarf
Added proper support for VAS item. Including labelleft and labelright (required) subitems
1570
						$rtmp['width'] = 100; 
1571
						$rtmp['labelleft'] = current($r->vas->labelleft);
1572
						$rtmp['labelright'] = current($r->vas->labelright);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1573
					}
1574
					$rstmp['response'] = $rtmp;
1575
					$qtmp['responses'][] = $rstmp;
1576
				}
1577
				$stmp['questions'][] = $qtmp;
1578
				$qcount++;
1579
			}
1580
			$q['sections'][] = $stmp;
1581
1582
			$scount++;
1583
		}
1584
		return $q;
1585
	}
1586
1587
	/**
1588
	 * Create a queXML PDF document based on an array
1589
	 * that is structured like a queXML document
1590
	 * 
29 by azammitdcarf
Cleaned up CSS
1591
	 * sections (title, text, info)
1592
	 *	questions (title, text, varname, helptext, helptextafter)
23 by azammitdcarf
Updated variable names
1593
	 *		responses (varname)
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1594
	 *			subquestion (text, varname)
1595
	 *			response (type, width, text, rotate)
1596
	 *				categories (text, value)
1597
	 *
1598
	 * @param array $questionnaire The questionnaire in the array format above
1599
	 */
1600
	public function create($questionnaire)
1601
	{
1602
		$this->init();
1603
		$this->questionnaireId = intval($questionnaire['id']);
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
1604
		$this->newPage(true); //first page
41 by azammitdcarf
Added support for questionnaireInfo position=before element
1605
1606
		//Draw questionnaireInfo before if exists
1607
		if (isset($questionnaire['infobefore']))
1608
		{
61 by azammitdcarf
Functionify the drawInfo procedure and make sure to move to new page if doesn't fit
1609
			$this->drawInfo($questionnaire['infobefore']);
41 by azammitdcarf
Added support for questionnaireInfo position=before element
1610
		}
1611
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1612
		foreach($questionnaire['sections'] as $sk => $sv)
1613
		{
1614
			//link the section title with the first question for pagination purposes
93 by Adam Zammit
Added paginiation improvements and bug fixes from downstream (LimeSurvey) thank you mfaber!
1615
			if (isset($sv['questions'])) 
1616
			{
1617
				$questions = count($sv['questions']);
1618
			}
1619
			else $questions=0; 
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1620
			
1621
			$this->startTransaction();
29 by azammitdcarf
Cleaned up CSS
1622
			$this->addSection($sv['text'],$sv['title'],$sv['info']);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1623
			if ($questions != 0) $this->createQuestion($sv['questions'][0]);
1624
			if ($this->pageBreakOccured)
1625
			{
1626
				$this->pageBreakOccured = false;
1627
				$this->rollBackTransaction(true);
43 by azammitdcarf
Fixed issue where page breaks occuring at the wrong spot
1628
				$this->SetAutoPageBreak(false); //Temporarily set so we don't trigger a page break
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1629
				$this->fillPageBackground();
1630
				$this->newPage();
29 by azammitdcarf
Cleaned up CSS
1631
				$this->addSection($sv['text'],$sv['title'],$sv['info']);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1632
				if ($questions != 0) $this->createQuestion($sv['questions'][0]);
1633
			}
1634
			else
1635
				$this->commitTransaction();
1636
70 by azammitdcarf
Allow for a section with no question to work
1637
			//start from the second question as first is linked to the section (if there is a question in this section)
1638
			if ($questions != 0)
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1639
			{
70 by azammitdcarf
Allow for a section with no question to work
1640
				foreach(array_slice($sv['questions'], 1) as $qk => $qv)
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1641
				{
70 by azammitdcarf
Allow for a section with no question to work
1642
					$this->startTransaction();
1643
					//add question here
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1644
					$this->createQuestion($qv);
70 by azammitdcarf
Allow for a section with no question to work
1645
					if ($this->pageBreakOccured)
1646
					{
1647
						$this->pageBreakOccured = false;
1648
						$this->rollBackTransaction(true);
1649
						$this->SetAutoPageBreak(false); //Temporarily set so we don't trigger a page break
1650
						//now draw a background to the bottom of the page
1651
						$this->fillPageBackground();
1652
				
1653
						$this->newPage();
1654
						//retry question here
1655
						$this->createQuestion($qv);
1656
					}
1657
					else
1658
						$this->commitTransaction();
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1659
				}
1660
			}
1661
		}
32 by azammitdcarf
Added support for questionnaireInfo after element
1662
61 by azammitdcarf
Functionify the drawInfo procedure and make sure to move to new page if doesn't fit
1663
32 by azammitdcarf
Added support for questionnaireInfo after element
1664
		//Draw questionnaireInfo after if exists
1665
		if (isset($questionnaire['infoafter']))
1666
		{
61 by azammitdcarf
Functionify the drawInfo procedure and make sure to move to new page if doesn't fit
1667
			$this->startTransaction();
1668
1669
			$this->drawInfo($questionnaire['infoafter']);
1670
1671
			if ($this->pageBreakOccured)
1672
			{
1673
				$this->pageBreakOccured = false;
1674
				$this->rollBackTransaction(true);
1675
				$this->SetAutoPageBreak(false); //Temporarily set so we don't trigger a page break
1676
				//now draw a background to the bottom of the page
1677
				$this->fillPageBackground();
1678
		
1679
				$this->newPage();
1680
				//retry question here
1681
				$this->drawInfo($questionnaire['infoafter']);
1682
			}
1683
			else
1684
				$this->commitTransaction();
1685
32 by azammitdcarf
Added support for questionnaireInfo after element
1686
		}
1687
1688
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1689
		//fill to the end of the last page
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
1690
		$this->fillLastPageBackground();
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1691
	}
1692
61 by azammitdcarf
Functionify the drawInfo procedure and make sure to move to new page if doesn't fit
1693
1694
	/**
1695
	 * Draw the questionnaire info specified
1696
	 * 
1697
	 * @param string $text The text to draw in info style
1698
	 * @author Adam Zammit <adam.zammit@acspri.org.au>
1699
	 * @since  2011-12-21
1700
	 */
1701
	protected function drawInfo($info)
1702
	{
1703
		$this->setBackground('question');
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
1704
		$this->writeHTMLCell($this->getColumnWidth(), $this->questionnaireInfoMargin, $this->getColumnX(), $this->GetY() - $this->questionBorderBottom, "<div></div>",0,1,true,true);
1705
		$html = "<table><tr><td width=\"" . $this->getColumnWidth() . "mm\" class=\"questionnaireInfo\">{$info}</td><td></td></tr></table>";
1706
		$this->writeHTMLCell($this->getColumnWidth(), 1, $this->getColumnX(), $this->GetY(), $this->style . $html,0,1,true,true);
61 by azammitdcarf
Functionify the drawInfo procedure and make sure to move to new page if doesn't fit
1707
	}
1708
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1709
	/**
1710
	 * Create a question that may have multiple response groups
1711
	 *
63 by azammitdcarf
Replaced $questionTextWidth with $questionTextRightMargin to manage varying page widths better
1712
	 * questions (title, text, specifier, helptext, helptextafter)
23 by azammitdcarf
Updated variable names
1713
	 *	responses (varname)
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1714
	 *		subquestions 
1715
	 *			subquestion(text, varname)
1716
	 *		response (type, width, text, rotate)
1717
	 *			categories 
1718
	 *				category(text, value, skipto, other)
1719
	 *
1720
	 * @param array $question The questions portion of the array
1721
	 * @see create
1722
	 */
1723
	protected function createQuestion($question)
1724
	{
1725
		$help = false;
63 by azammitdcarf
Replaced $questionTextWidth with $questionTextRightMargin to manage varying page widths better
1726
		$specifier = false;
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1727
		if (isset($question['helptext'])) $help = $question['helptext'];
63 by azammitdcarf
Replaced $questionTextWidth with $questionTextRightMargin to manage varying page widths better
1728
		if (isset($question['specifier'])) $specifier = $question['specifier'];
1729
1730
		//If there is some help text for before the question
1731
		if (isset($question['helptextbefore']))
1732
		{
65 by azammitdcarf
Added a white border around question directive before elements
1733
			//Leave a border at the top of the Help Before text
1734
			if ($this->helpBeforeBorderTop > 0) //question border
1735
				$this->SetY($this->GetY() + $this->helpBeforeBorderTop,false); //new line
1736
	
63 by azammitdcarf
Replaced $questionTextWidth with $questionTextRightMargin to manage varying page widths better
1737
			$this->setBackground('question');
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
1738
			$html = "<table><tr><td width=\"" . $this->getColumnWidth() . "mm\" class=\"questionHelpBefore\">{$question['helptextbefore']}</td><td></td></tr></table>";
1739
			$this->writeHTMLCell($this->getColumnWidth(), 1, $this->getColumnX(), $this->GetY(), $this->style . $html,0,1,true,true);
63 by azammitdcarf
Replaced $questionTextWidth with $questionTextRightMargin to manage varying page widths better
1740
65 by azammitdcarf
Added a white border around question directive before elements
1741
			//Leave a border at the bottom of the Help Before text
1742
			if ($this->helpBeforeBorderBottom > 0) //question border
1743
				$this->SetY($this->GetY() + $this->helpBeforeBorderBottom,false); //new line
63 by azammitdcarf
Replaced $questionTextWidth with $questionTextRightMargin to manage varying page widths better
1744
		}
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1745
1746
		//Question header
89 by Adam Zammit
Allow for the specifying of sectionHeight
1747
		$helph = $help;
1748
		//don't display help if separate questions are involved
1749
		if (isset($question['responses'][0]['response']['separate'])) $helph = false;
1750
90 by Adam Zammit
Allow for hiding of the question title
1751
		//hide if requested
1752
		$qtitle = $question['title'];
1753
		if (isset($question['hidetitle']))
1754
			$qtitle = "";
1755
1756
		$this->drawQuestionHead($qtitle, $question['text'],$helph,$specifier);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1757
22 by azammitdcarf
Updated test_questionnaire.xml variable names
1758
		$text = "";
1759
		if (isset($question['text'])) $text = $question['text'];
1760
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1761
		//Loop over response groups and produce questions of various types
93 by Adam Zammit
Added paginiation improvements and bug fixes from downstream (LimeSurvey) thank you mfaber!
1762
		if (isset($question['responses']))
1763
        	{
1764
		//the number of response scales is needed later on to decide on labelling scales in fixed response questions
1765
		$iCountResponseScales=count($question['responses']);
1766
		foreach($question['responses'] as $r)
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1767
		{
23 by azammitdcarf
Updated variable names
1768
			$varname = $r['varname'];	
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1769
1770
			if (isset($r['subquestions']))
1771
			{
1772
				$response = $r['response'];
1773
				$subquestions = $r['subquestions'];
1774
				$type = $response['type'];
1775
44 by azammitdcarf
Banding XML will include number only fields where set to integer, number or numeric
1776
				$bgtype = 3; //box group type temp set to 3 (text)
93 by Adam Zammit
Added paginiation improvements and bug fixes from downstream (LimeSurvey) thank you mfaber!
1777
				
1778
				if (count($question['responses'])>1)
1779
				{
1780
					foreach ($subquestions as $index=>$sv)
1781
					{
1782
						$subquestions[$index]['varname']=$subquestions[$index]['varname'].'_'.$varname;
1783
					}
1784
				}
44 by azammitdcarf
Banding XML will include number only fields where set to integer, number or numeric
1785
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1786
				switch ($type)
1787
				{
1788
					case 'fixed':
1789
						$categories = $response['categories'];
89 by Adam Zammit
Allow for the specifying of sectionHeight
1790
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1791
						if (isset($response['rotate']))
22 by azammitdcarf
Updated test_questionnaire.xml variable names
1792
							$this->drawSingleChoiceVertical($categories,$subquestions,$text);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1793
						else
89 by Adam Zammit
Allow for the specifying of sectionHeight
1794
						{
1795
							if (isset($response['separate']))
1796
							{
1797
								$this->drawSingleChoiceVerticalSeparate($categories,$subquestions,$text,$help);
1798
							}
1799
							else
93 by Adam Zammit
Added paginiation improvements and bug fixes from downstream (LimeSurvey) thank you mfaber!
1800
							{
1801
								// if there is more than one response scale, add a label to scales in the pdf 
1802
								$this->drawSingleChoiceHorizontal($categories,$subquestions,$text,$iCountResponseScales >1? $varname : false);
1803
							}
89 by Adam Zammit
Allow for the specifying of sectionHeight
1804
						}
93 by Adam Zammit
Added paginiation improvements and bug fixes from downstream (LimeSurvey) thank you mfaber!
1805
					
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1806
						break;
1807
					case 'number':
44 by azammitdcarf
Banding XML will include number only fields where set to integer, number or numeric
1808
						$bgtype = 4;
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1809
					case 'currency':
1810
					case 'text':
1811
						if (isset($response['rotate']))
93 by Adam Zammit
Added paginiation improvements and bug fixes from downstream (LimeSurvey) thank you mfaber!
1812
							$this->drawMatrixTextHorizontal($subquestions,$response['width'],$text,$bgtype,$response['text']);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1813
						else
93 by Adam Zammit
Added paginiation improvements and bug fixes from downstream (LimeSurvey) thank you mfaber!
1814
							$this->drawMatrixTextVertical($subquestions,$response['width'],$text,$bgtype,$response['text']);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1815
						break;
1816
					case 'vas':
48 by azammitdcarf
Added proper support for VAS item. Including labelleft and labelright (required) subitems
1817
						$this->drawMatrixVas($subquestions,$text,$response['labelleft'],$response['labelright']);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1818
						break;
83 by azammitdcarf
Added free response types "codabar" and "i25" to be able to pre-draw filled barcodes a questions (using the defaultValue attribute)
1819
					case 'i25':
1820
						$this->drawMatrixBarcode($subquestions, 'I25');
1821
						break;		
1822
					case 'codabar':
1823
						$this->drawMatrixBarcode($subquestions, 'CODABAR');
1824
						break;		
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1825
				}
1826
			}
1827
			else
1828
			{
1829
				$response = $r['response'];
1830
				$type = $response['type'];
1831
82 by azammitdcarf
Added defaultValue attribute to responses to allow for pre-filling
1832
				$defaultvalue = false;
1833
				if (isset($r['defaultvalue']))
1834
					$defaultvalue = $r['defaultvalue'];
1835
23 by azammitdcarf
Updated variable names
1836
				if (isset($response['text']) && !empty($response['text'])) 
22 by azammitdcarf
Updated test_questionnaire.xml variable names
1837
					$rtext = $text .  $this->subQuestionTextSeparator .  $response['text'];
1838
				else
1839
					$rtext = $text;
1840
44 by azammitdcarf
Banding XML will include number only fields where set to integer, number or numeric
1841
				$bgtype = 3; //box group type temp set to 3 (text)
1842
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1843
				switch ($type)
1844
				{
1845
					case 'fixed':
1846
						if (isset($response['rotate']))
82 by azammitdcarf
Added defaultValue attribute to responses to allow for pre-filling
1847
							$this->drawSingleChoiceHorizontal($response['categories'],array(array('text' => '', 'varname' => $varname, 'defaultvalue' => $defaultvalue)),$rtext);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1848
						else
82 by azammitdcarf
Added defaultValue attribute to responses to allow for pre-filling
1849
							$this->drawSingleChoiceVertical($response['categories'],array(array('text' => '', 'varname' => $varname, 'defaultvalue' => $defaultvalue)),$rtext);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1850
						break;
1851
					case 'longtext':
22 by azammitdcarf
Updated test_questionnaire.xml variable names
1852
						$this->addBoxGroup(6,$varname,$rtext);
82 by azammitdcarf
Added defaultValue attribute to responses to allow for pre-filling
1853
						$this->drawLongText($response['width'],$defaultvalue);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1854
						break;
1855
					case 'number':
44 by azammitdcarf
Banding XML will include number only fields where set to integer, number or numeric
1856
						$bgtype = 4;
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1857
					case 'currency':
1858
					case 'text':
44 by azammitdcarf
Banding XML will include number only fields where set to integer, number or numeric
1859
						$this->addBoxGroup($bgtype,$varname,$rtext,$response['width']);	
82 by azammitdcarf
Added defaultValue attribute to responses to allow for pre-filling
1860
						$this->drawText($response['text'],$response['width'],$defaultvalue);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1861
						//Insert a gap here
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
1862
						$this->Rect($this->getColumnX(),$this->GetY(),$this->getColumnWidth(),$this->subQuestionLineSpacing,'F',array(),$this->backgroundColourQuestion);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1863
						$this->SetY($this->GetY() + $this->subQuestionLineSpacing,false);
1864
						break;
1865
					case 'vas':
22 by azammitdcarf
Updated test_questionnaire.xml variable names
1866
						$this->addBoxGroup(1,$varname,$rtext,strlen($this->vasIncrements));
48 by azammitdcarf
Added proper support for VAS item. Including labelleft and labelright (required) subitems
1867
						$this->drawVas("",$response['labelleft'],$response['labelright']);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1868
						break;
83 by azammitdcarf
Added free response types "codabar" and "i25" to be able to pre-draw filled barcodes a questions (using the defaultValue attribute)
1869
					case 'i25':
1870
						$this->drawMatrixBarcode(array(array('text' => $rtext, 'varname' => $varname, 'defaultvalue' => $defaultvalue)),'I25');
1871
						break;		
1872
					case 'codabar':
1873
						$this->drawMatrixBarcode(array(array('text' => $rtext, 'varname' => $varname, 'defaultvalue' => $defaultvalue)),'CODABAR');
1874
						break;		
1875
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1876
				}
1877
			}
1878
		}}
1879
29 by azammitdcarf
Cleaned up CSS
1880
		//If there is some help text for after the question
1881
		if (isset($question['helptextafter']))
1882
		{
1883
			$this->setBackground('question');
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
1884
			$html = "<table><tr><td width=\"" . $this->getColumnWidth() . "mm\" class=\"questionHelpAfter\">{$question['helptextafter']}</td><td></td></tr></table>";
1885
			$this->writeHTMLCell($this->getColumnWidth(), 1, $this->getColumnX(), $this->GetY(), $this->style . $html,0,1,true,true);
29 by azammitdcarf
Cleaned up CSS
1886
1887
		}
1888
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1889
		//Leave a border at the bottom of the question		
1890
		if ($this->questionBorderBottom > 0) //question border
1891
			$this->SetY($this->GetY() + $this->questionBorderBottom,false); //new line
1892
	}
1893
1894
	
1895
1896
	/**
1897
	 * Draw text responses line by line
1898
	 * 
1899
	 * @param array $subquestions The subquestions containing text and varname
1900
	 * @param int $width The width of the text element
22 by azammitdcarf
Updated test_questionnaire.xml variable names
1901
	 * @param string|bool $parenttext The question text of the parent or false if not specified
44 by azammitdcarf
Banding XML will include number only fields where set to integer, number or numeric
1902
	 * @param int $bgtype The box group type (default is 3 - text)
93 by Adam Zammit
Added paginiation improvements and bug fixes from downstream (LimeSurvey) thank you mfaber!
1903
	 * @param string|bool $responsegrouplabel The label for this response group or false if not specified
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1904
	 * 
1905
	 * @author Adam Zammit <adam.zammit@acspri.org.au>
1906
	 * @since  2010-09-02
1907
	 */
93 by Adam Zammit
Added paginiation improvements and bug fixes from downstream (LimeSurvey) thank you mfaber!
1908
	protected function drawMatrixTextVertical($subquestions,$width,$parenttext = false,$bgtype = 3, $responsegrouplabel = false)
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1909
	{
1910
		$c = count($subquestions);
93 by Adam Zammit
Added paginiation improvements and bug fixes from downstream (LimeSurvey) thank you mfaber!
1911
		if ($responsegrouplabel)
1912
		{
1913
			$this->setBackground('question');
1914
			$html = "<table><tr><td width=\"{$this->questionTitleWidth}mm\"></td><td width=\"" . ($this->getColumnWidth() -  $this->skipColumnWidth - $this->questionTitleWidth) . "mm\" class=\"matrixResponseGroupLabel\">$responsegrouplabel:</td><td></td></tr></table>";
1915
			$this->writeHTMLCell($this->getColumnWidth(), 1, $this->getColumnX(), $this->GetY(), $this->style . $html,0,1,true,true);
1916
		}
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1917
		for($i = 0; $i < $c; $i++)
1918
		{
1919
			$s = $subquestions[$i];
22 by azammitdcarf
Updated test_questionnaire.xml variable names
1920
1921
			if ($parenttext == false)
44 by azammitdcarf
Banding XML will include number only fields where set to integer, number or numeric
1922
				$this->addBoxGroup($bgtype,$s['varname'],$s['text'],$width);
22 by azammitdcarf
Updated test_questionnaire.xml variable names
1923
			else				
44 by azammitdcarf
Banding XML will include number only fields where set to integer, number or numeric
1924
				$this->addBoxGroup($bgtype,$s['varname'],$parenttext . $this->subQuestionTextSeparator . $s['text'],$width);
22 by azammitdcarf
Updated test_questionnaire.xml variable names
1925
82 by azammitdcarf
Added defaultValue attribute to responses to allow for pre-filling
1926
			$defaultvalue = false;
1927
			if (isset($s['defaultvalue']))
1928
				$defaultvalue = $s['defaultvalue'];
1929
1930
			$this->drawText($s['text'],$width,$defaultvalue);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1931
		
1932
			$currentY = $this->GetY();
1933
		
1934
			//Insert a gap here
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
1935
			$this->Rect($this->getColumnX(),$this->GetY(),$this->getColumnWidth(),$this->subQuestionLineSpacing,'F',array(),$this->backgroundColourQuestion);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1936
			$this->SetY($currentY + $this->subQuestionLineSpacing,false);
1937
		}
1938
	}
1939
83 by azammitdcarf
Added free response types "codabar" and "i25" to be able to pre-draw filled barcodes a questions (using the defaultValue attribute)
1940
1941
	/**
1942
	 * Draw a barcode as a "question"
1943
	 * 
1944
	 * @param string $subquestions 
1945
	 * @param mixed  $type         
1946
	 * 
1947
	 * @author Adam Zammit <adam.zammit@acspri.org.au>
1948
	 * @since  2012-06-22
1949
	 */
1950
	protected function drawMatrixBarcode($subquestions, $type)
1951
	{
1952
		$c = count($subquestions);
1953
1954
		for ($i = 0; $i < $c; $i++)
1955
		{
1956
			$s = $subquestions[$i];
1957
1958
			$this->addBoxGroup(5,$s['varname'],$s['text'],strlen($s['defaultvalue']));
1959
1960
			$x = $this->getColumnX();
1961
			$y = $this->GetY();
1962
1963
			$html = "<div></div>";
1964
			$this->setBackground('question');
1965
			$this->writeHTMLCell($this->getColumnWidth(), $this->barcodeResponseHeight, $this->getColumnX(), $this->GetY() , $this->style . $html,0,1,true,false);
1966
1967
			//draw the barcode
1968
			$barcodeStyle = array('align' => 'R', 'border' => false, 'padding' => '0', 'bgcolor' => $this->backgroundColourQuestion, 'text' => false, 'stretch' => false);
1969
			$this->write1DBarcode($s['defaultvalue'], $type, $x, $y, $this->getColumnWidth() - $this->skipColumnWidth,$this->barcodeResponseHeight,'', $barcodeStyle, 'B');
1970
1971
			//pointer should now be at the bottom right - but make the box the width of the whole column for better reading
1972
			$this->addBox($x,$y,$this->GetX(),$this->getColumnWidth() + $this->getColumnX());
1973
	
1974
			$currentY = $this->GetY();
1975
		
1976
			//Insert a gap here
1977
			$this->Rect($this->getColumnX(),$this->GetY(),$this->getColumnWidth(),$this->subQuestionLineSpacing,'F',array(),$this->backgroundColourQuestion);
1978
			$this->SetY($currentY + $this->subQuestionLineSpacing,false);
1979
			
1980
		}
1981
1982
	}
1983
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1984
	/**
1985
	 * Draw multiple VAS items
1986
	 * 
1987
	 * @param array $subquestions The subquestions containing text and varname
22 by azammitdcarf
Updated test_questionnaire.xml variable names
1988
	 * @param string|bool $parenttext The question text of the parent or false if not specified
48 by azammitdcarf
Added proper support for VAS item. Including labelleft and labelright (required) subitems
1989
	 * @param string $labelleft The left hand side label
1990
	 * @param string $labelright The right hand side label
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1991
	 * 
1992
	 * @author Adam Zammit <adam.zammit@acspri.org.au>
1993
	 * @since  2010-09-20
1994
	 */
48 by azammitdcarf
Added proper support for VAS item. Including labelleft and labelright (required) subitems
1995
	protected function drawMatrixVas($subquestions,$parenttext = false,$labelleft,$labelright)
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
1996
	{
1997
		$c = count($subquestions);
1998
		
22 by azammitdcarf
Updated test_questionnaire.xml variable names
1999
		$width = strlen($this->vasIncrements);	
2000
48 by azammitdcarf
Added proper support for VAS item. Including labelleft and labelright (required) subitems
2001
		$heading = true;
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2002
		for ($i = 0; $i < $c; $i++)
2003
		{
2004
			$s = $subquestions[$i];
22 by azammitdcarf
Updated test_questionnaire.xml variable names
2005
2006
			if ($parenttext == false)
2007
				$this->addBoxGroup(1,$s['varname'],$s['text'],$width);
2008
			else				
2009
				$this->addBoxGroup(1,$s['varname'],$parenttext . $this->subQuestionTextSeparator . $s['text'],$width);
2010
2011
2012
2013
48 by azammitdcarf
Added proper support for VAS item. Including labelleft and labelright (required) subitems
2014
			$this->drawVas($s['text'],$labelleft,$labelright,$heading);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2015
		
2016
			$currentY = $this->GetY();
2017
		
2018
			//Insert a gap here
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2019
			$this->Rect($this->getColumnX(),$this->GetY(),$this->getColumnWidth(),$this->subQuestionLineSpacing,'F',array(),$this->backgroundColourQuestion);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2020
			$this->SetY($currentY + $this->subQuestionLineSpacing,false);
48 by azammitdcarf
Added proper support for VAS item. Including labelleft and labelright (required) subitems
2021
			
2022
			$heading = false;
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2023
2024
		}
2025
		
2026
	}
2027
2028
2029
	/**
2030
	 * Draw a large empty box for writing in text
2031
	 * 
2032
	 * @param mixed $width   The "width" of the box. This relates to the number of "lines" high
82 by azammitdcarf
Added defaultValue attribute to responses to allow for pre-filling
2033
	 * @param bool|string $defaultvalue The default text to print in the box (if any)
91 by root
Added format to contingentQuestion attribute
2034
         * @param bool|string $text The text to display above the box (if any) 
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2035
	 * 
2036
	 * @author Adam Zammit <adam.zammit@acspri.org.au>
2037
	 * @since  2010-09-02
2038
	 */
91 by root
Added format to contingentQuestion attribute
2039
	protected function drawLongText($width,$defaultvalue = false,$text =false)
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2040
	{
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2041
		//Calculate long text box width as the width of the available column minus the skip column and question title area
2042
		$rwidth = $this->getColumnWidth() - $this->skipColumnWidth - $this->questionTitleWidth;
2043
91 by root
Added format to contingentQuestion attribute
2044
		if ($text !== false && !empty($text))
2045
		{
2046
			$this->setBackground('question');
2047
			$html = "<table><tr><td width=\"{$this->questionTitleWidth}mm\"></td><td width=\"" . ($this->getColumnWidth() -  $this->skipColumnWidth - $this->questionTitleWidth) . "mm\" class=\"responseAboveText\">$text</td><td></td></tr></table>";
2048
			$this->writeHTMLCell($this->getColumnWidth(), 1, $this->getColumnX(), $this->GetY(), $this->style . $html,0,1,true,true);
2049
		}
2050
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2051
		$currentY = $this->GetY();
2052
		$height = $width * $this->longTextResponseHeightMultiplier;
2053
		$html = "<div></div>";
2054
		$this->setBackground('question');
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2055
		$this->writeHTMLCell($this->getColumnWidth(), $height, $this->getColumnX(), $this->GetY(), $this->style . $html,0,1,true,true);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2056
		$this->SetY($currentY,false);
2057
		$this->setBackground('empty');
2058
		$border = array('LTRB' => array('width' => $this->textResponseBorder, 'dash' => 0));
2059
		//Align to skip column on right
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2060
		$this->SetX((($this->getColumnWidth() + $this->getColumnX()) - $this->skipColumnWidth - $rwidth),false);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2061
		//Add to pay layout
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2062
		$this->addBox($this->GetX(),$this->GetY(),$this->GetX() + $rwidth, $this->GetY() + $height);
75 by azammitdcarf
Made output colours|colors greyscale|grayscale
2063
		$this->SetDrawColor($this->lineColour[0]);
82 by azammitdcarf
Added defaultValue attribute to responses to allow for pre-filling
2064
2065
		$text = "";
2066
		if ($defaultvalue !== false)
2067
			$text = $defaultvalue;
2068
2069
		$this->Cell($rwidth,$height,$text,$border,0,'',true,'',0,false,'T','T');
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2070
		$currentY = $currentY + $height;
2071
		$this->SetY($currentY,false);
2072
	}
2073
2074
2075
	/**
2076
	 * Draw a VAS
2077
	 * 
48 by azammitdcarf
Added proper support for VAS item. Including labelleft and labelright (required) subitems
2078
	 * @param string $text The text of this item
2079
	 * @param string $labelleft The left hand side label
2080
	 * @param string $labelright The right hand side label
2081
	 * @param bool $heading Whether to draw a heading or not
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2082
	 * 
2083
	 * @author Adam Zammit <adam.zammit@acspri.org.au>
2084
	 * @since  2010-09-20
2085
	 */
48 by azammitdcarf
Added proper support for VAS item. Including labelleft and labelright (required) subitems
2086
	protected function drawVas($text, $labelleft,$labelright,$heading = true)
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2087
	{
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2088
		$textwidth = $this->getColumnWidth() - $this->skipColumnWidth - ($this->vasLength + ($this->vasLineWidth * 2.0)) - 2;
48 by azammitdcarf
Added proper support for VAS item. Including labelleft and labelright (required) subitems
2089
		$this->setBackground('question');
2090
2091
		if ($heading)
2092
		{
2093
			//draw heading
2094
			$lwidth = 20;
2095
			$slwidth = $textwidth - ($lwidth / 2);
2096
			$gapwidth = ($this->vasLength + ($this->vasLineWidth * 2.0)) - $lwidth;
2097
	
2098
	
2099
			$html = "<table><tr><td width=\"{$slwidth}mm\"></td><td width=\"{$lwidth}mm\" class=\"vasLabel\">$labelleft</td><td width=\"{$gapwidth}mm\"></td><td width=\"{$lwidth}mm\" class=\"vasLabel\">$labelright</td></tr></table>";
2100
	
2101
	
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2102
			$this->writeHTMLCell($this->getColumnWidth(), 0, $this->getColumnX(), $this->GetY(), $this->style . $html,0,1,true,false);
48 by azammitdcarf
Added proper support for VAS item. Including labelleft and labelright (required) subitems
2103
		}
2104
2105
		$currentY = $this->GetY();
2106
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2107
2108
		$html = "<table><tr><td width=\"{$textwidth}mm\" class=\"responseText\">$text</td><td></td></tr></table>";
2109
		
2110
		$textwidth += 2;
2111
2112
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2113
		$this->writeHTMLCell($this->getColumnWidth(), $this->vasAreaHeight, $this->getColumnX(), $this->GetY(), $this->style . $html,0,1,true,false);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2114
2115
		$ncurrentY = $this->GetY();
2116
2117
		$this->SetY($currentY,false);
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2118
		$this->SetX($textwidth + $this->getColumnX(),false); 
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2119
	
2120
		$this->SetLineWidth($this->vasLineWidth);
75 by azammitdcarf
Made output colours|colors greyscale|grayscale
2121
		$this->SetDrawColor($this->lineColour[0]);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2122
	
2123
		//Draw the VAS left vert line
2124
		$ly = (($this->vasAreaHeight - $this->vasHeight) / 2.0) + $currentY;		
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2125
		$lx = $textwidth + $this->getColumnX();
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2126
		$this->Line($lx,$ly,$lx,$ly + $this->vasHeight);
2127
		
2128
		//Right vert line
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2129
		$lx = $textwidth + $this->getColumnX() + $this->vasLength + $this->vasLineWidth;
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2130
		$this->Line($lx,$ly,$lx,$ly + $this->vasHeight);
2131
	
2132
		//Line itself
2133
		$ly = ($this->vasAreaHeight / 2.0) + $currentY;
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2134
		$lx = $textwidth + $this->getColumnX() + ($this->vasLineWidth / 2.0);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2135
		$this->Line($lx,$ly,$lx + $this->vasLength,$ly);
2136
2137
		//Add to layout system
2138
		$bw = ($this->vasLength / $this->vasIncrements);
2139
		$ly = (($this->vasAreaHeight - $this->vasHeight) / 2.0) + $currentY;		
2140
		for ($i = 0; $i < $this->vasIncrements; $i++)
2141
		{
2142
			$this->addBox($lx,$ly,$lx + $bw,$ly + $this->vasHeight, $i + 1, $i + 1);
2143
			$lx += $bw;
2144
		}
2145
2146
		//Go back to the right Y position
2147
		$this->SetY($ncurrentY,false);
2148
	}	
2149
2150
	/**
2151
	 * Draw a text response
2152
	 *
2153
	 * @param string $text The text label if any (can be HTML)
2154
	 * @param int $width The number of boxes to draw
82 by azammitdcarf
Added defaultValue attribute to responses to allow for pre-filling
2155
	 * @param bool|string $defaultvalue The default text to include or false if none
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2156
	 */
82 by azammitdcarf
Added defaultValue attribute to responses to allow for pre-filling
2157
	protected function drawText($text,$width,$defaultvalue = false)
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2158
	{
75 by azammitdcarf
Made output colours|colors greyscale|grayscale
2159
		$this->SetDrawColor($this->lineColour[0]);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2160
54 by azammitdcarf
Calculation of barcode position is now a distance from the right hand margin (instead of a fixed position in MM)
2161
		//calculate text responses per line
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2162
		$textResponsesPerLine = round(($this->getColumnWidth() - $this->skipColumnWidth - $this->textResponseMarginX) / ($this->textResponseWidth + $this->textResponseBorder));
2163
		$labelTextResponsesSameLine = round(($this->getColumnWidth() - $this->skipColumnWidth - $this->labelTextResponsesSameLineMarginX) / ($this->textResponseWidth + $this->textResponseBorder));
54 by azammitdcarf
Calculation of barcode position is now a distance from the right hand margin (instead of a fixed position in MM)
2164
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2165
		//draw boxes - can draw up to $textResponsesPerLine for each line
54 by azammitdcarf
Calculation of barcode position is now a distance from the right hand margin (instead of a fixed position in MM)
2166
		$lines = ceil($width / $textResponsesPerLine);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2167
2168
		//draw the text label on the top of this box
54 by azammitdcarf
Calculation of barcode position is now a distance from the right hand margin (instead of a fixed position in MM)
2169
		if ($width > $labelTextResponsesSameLine && !empty($text))
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2170
		{
2171
			$this->setBackground('question');
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2172
			$html = "<table><tr><td width=\"{$this->questionTitleWidth}mm\"></td><td width=\"" . ($this->getColumnWidth() -  $this->skipColumnWidth - $this->questionTitleWidth) . "mm\" class=\"responseAboveText\">$text</td><td></td></tr></table>";
2173
			$this->writeHTMLCell($this->getColumnWidth(), 1, $this->getColumnX(), $this->GetY(), $this->style . $html,0,1,true,true);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2174
		}
2175
2176
		$currentY = $this->GetY();
2177
82 by azammitdcarf
Added defaultValue attribute to responses to allow for pre-filling
2178
		$startstring = 0;
2179
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2180
		for ($i = 0; $i < $lines; $i++)
2181
		{
2182
			if ($lines == 1) $cells = $width; //one line only
54 by azammitdcarf
Calculation of barcode position is now a distance from the right hand margin (instead of a fixed position in MM)
2183
			else if (($i + 1 == $lines)) $cells = ($width - ($textResponsesPerLine * $i));  //last line
2184
			else $cells = $textResponsesPerLine; //middle line
82 by azammitdcarf
Added defaultValue attribute to responses to allow for pre-filling
2185
	
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2186
72 by azammitdcarf
Create a new box group for each line of text items with identical variable names. Will display better in queXF. Note - queXF should try and concatenate if variable names are the same
2187
			//add another box group if moving on to another line
2188
			if ($i >= 1)
2189
				$this->addBoxGroupCopyPrevious();
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2190
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2191
			$textwidth = ($this->getColumnWidth() - $this->skipColumnWidth) - (($this->textResponseWidth + $this->textResponseBorder ) * $cells);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2192
2193
			//print "textwidth: $textwidth cells: $cells mainpagex: " . $this->getMainPageX() . "<br/>";
34 by azammitdcarf
Replaced drawing using HTML tables with TCPDF Multicell to allow for aligning text vertically
2194
			//First draw a background of height $this->responseLabelHeight
2195
			$html = "<div></div>";
2196
			$this->setBackground('question');
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2197
			$this->writeHTMLCell($this->getColumnWidth(), $this->textResponseHeight, $this->getColumnX(), $this->GetY() , $this->style . $html,0,1,true,false);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2198
54 by azammitdcarf
Calculation of barcode position is now a distance from the right hand margin (instead of a fixed position in MM)
2199
			if ($lines == 1 && $cells <= $labelTextResponsesSameLine && !empty($text))
34 by azammitdcarf
Replaced drawing using HTML tables with TCPDF Multicell to allow for aligning text vertically
2200
			{
35 by azammitdcarf
Use setDefaultFont function instead of SetFont
2201
				$this->setDefaultFont($this->responseTextFontSize);			
34 by azammitdcarf
Replaced drawing using HTML tables with TCPDF Multicell to allow for aligning text vertically
2202
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2203
				$this->MultiCell($textwidth,$this->textResponseHeight,$text,0,'R',false,1,$this->getColumnX(),$currentY,true,0,false,true,$this->textResponseHeight,'M',true);
34 by azammitdcarf
Replaced drawing using HTML tables with TCPDF Multicell to allow for aligning text vertically
2204
2205
2206
				//$html = "<table><tr><td width=\"{$textwidth}mm\" class=\"responseText\">$text</td><td></td></tr></table>";
2207
			}
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2208
			
2209
2210
			$ncurrentY = $this->GetY();
2211
2212
			$this->SetY($currentY,false);
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2213
			$this->SetX($textwidth + $this->getColumnX() + 2,false); //set the X position to the first cell
82 by azammitdcarf
Added defaultValue attribute to responses to allow for pre-filling
2214
		
2215
			$string = false;
2216
			if ($defaultvalue !== false)
2217
				$string = substr($defaultvalue,$startstring,$cells);
2218
	
2219
			$this->drawCells($cells,$string);
2220
2221
			$startstring += $cells;
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2222
2223
			$currentY = $ncurrentY;
2224
2225
			//New line
2226
			$this->SetY($currentY,false); //new line
2227
		
2228
2229
			if (!(($i + 1) == $lines) && $this->textResponseLineSpacing > 0) //if there should be a gap between text responses and not the last
2230
			{
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2231
				$this->SetX($this->getColumnX(),false);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2232
				$this->setBackground('question');
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2233
				$this->Cell($this->getColumnWidth(),$this->textResponseLineSpacing,'','',0,'',true,'',0,false,'T','C');
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2234
				$currentY += $this->textResponseLineSpacing;
2235
				$this->SetY($currentY,false); //new line
2236
			}
2237
			
2238
		}
2239
					
2240
	}
2241
2242
	/**
2243
	 * Draw X number of cells at the current X Y position
2244
	 * 
2245
	 * @param int $cells  The number of text cells to draw
82 by azammitdcarf
Added defaultValue attribute to responses to allow for pre-filling
2246
	 * @param string $string A string to draw if set
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2247
	 * 
2248
	 * @author Adam Zammit <adam.zammit@acspri.org.au>
2249
	 * @since  2010-09-08
2250
	 */
82 by azammitdcarf
Added defaultValue attribute to responses to allow for pre-filling
2251
	protected function drawCells($cells, $string)
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2252
	{
2253
		$this->setBackground('empty');
75 by azammitdcarf
Made output colours|colors greyscale|grayscale
2254
		$this->SetDrawColor($this->lineColour[0]);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2255
2256
		for ($j = 0; $j < $cells; $j++)
2257
		{
2258
			//draw text cells 
2259
			if ($cells == 1) //only
37 by azammitdcarf
Drawing of text cell borders to appear consistent in print form
2260
				$border = array('LTR' => array('width' => $this->textResponseBorder, 'dash' => 0), 'B' => array('width' => ($this->textResponseBorder * 2), 'dash' => 0));
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2261
			else if ($j == 0) //first
37 by azammitdcarf
Drawing of text cell borders to appear consistent in print form
2262
				$border = array('LT' => array('width' => $this->textResponseBorder, 'dash' => 0), 'R' => array('width' => $this->textResponseBorder, 'dash' => 1), 'B' => array('width' => ($this->textResponseBorder * 2), 'dash' => 0));
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2263
			else if (($j + 1) == $cells) //last
37 by azammitdcarf
Drawing of text cell borders to appear consistent in print form
2264
			{
2265
				$border = array('TR' => array('width' => $this->textResponseBorder, 'dash' => 0), 'B' => array('width' => ($this->textResponseBorder * 2), 'dash' => 0));
2266
2267
				//add a border gap
38 by azammitdcarf
Updated image line size to make sure lines are printed and not ignored
2268
				$this->SetX($this->GetX() + ($this->textResponseBorder),false);
37 by azammitdcarf
Drawing of text cell borders to appear consistent in print form
2269
			}
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2270
			else //middle
37 by azammitdcarf
Drawing of text cell borders to appear consistent in print form
2271
			{
2272
				$border = array('T' => array('width' => $this->textResponseBorder, 'dash' => 0), 'R' => array('width' => $this->textResponseBorder, 'dash' => 1), 'B' => array('width' => ($this->textResponseBorder * 2), 'dash' => 0));
2273
				//add a border gap
38 by azammitdcarf
Updated image line size to make sure lines are printed and not ignored
2274
				$this->SetX($this->GetX() + ($this->textResponseBorder),false);
37 by azammitdcarf
Drawing of text cell borders to appear consistent in print form
2275
			}
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2276
2277
			//Add the box to the layout scheme
2278
			$this->addBox($this->GetX(),$this->GetY(),$this->GetX() + $this->textResponseWidth,$this->GetY() + $this->textResponseHeight);
54 by azammitdcarf
Calculation of barcode position is now a distance from the right hand margin (instead of a fixed position in MM)
2279
82 by azammitdcarf
Added defaultValue attribute to responses to allow for pre-filling
2280
			$text = '';
2281
			if (isset($string[$j])) 
2282
				$text = $string[$j];
2283
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2284
			//Draw the box
82 by azammitdcarf
Added defaultValue attribute to responses to allow for pre-filling
2285
			$this->Cell($this->textResponseWidth,$this->textResponseHeight,$text,$border,0,'',true,'',0,false,'T','C');
54 by azammitdcarf
Calculation of barcode position is now a distance from the right hand margin (instead of a fixed position in MM)
2286
	
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2287
		}
37 by azammitdcarf
Drawing of text cell borders to appear consistent in print form
2288
2289
		//add some spacing for the bottom border
2290
		//$this->SetY(($this->GetY() + ($this->textResponseBorder * 2)),false);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2291
	}
2292
2293
	/**
2294
	 * Draw a horizontal table of text boxes
2295
	 * 
2296
	 * @param array $subquestions The subquestions
2297
	 * @param int $width The width
22 by azammitdcarf
Updated test_questionnaire.xml variable names
2298
	 * @param string|bool $parenttext The question text of the parent or false if not specified
44 by azammitdcarf
Banding XML will include number only fields where set to integer, number or numeric
2299
	 * @param int $bgtype The type of the box group (defaults to 3 - text)
93 by Adam Zammit
Added paginiation improvements and bug fixes from downstream (LimeSurvey) thank you mfaber!
2300
	 * @param string|bool $responsegrouplabel The label for this response group or false if not specified
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2301
	 *
2302
	 * @author Adam Zammit <adam.zammit@acspri.org.au>
2303
	 * @since  2010-09-08
2304
	 */
93 by Adam Zammit
Added paginiation improvements and bug fixes from downstream (LimeSurvey) thank you mfaber!
2305
	protected function drawMatrixTextHorizontal($subquestions,$width,$parenttext = false,$bgtype = 3, $responsegrouplabel = false)
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2306
	{
2307
		$total = count($subquestions);
2308
		$currentY = $this->GetY();
2309
2310
		$rwidth = ($width * ($this->textResponseWidth + $this->textResponseBorder + $this->textResponseLineSpacing)); 
2311
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2312
		$textwidth = ($this->getColumnWidth() - $this->skipColumnWidth) - ($rwidth * $total);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2313
2314
		$html = "<table><tr><td width=\"{$textwidth}mm\" class=\"responseText\"></td>";
2315
		foreach ($subquestions as $r)
2316
		{
2317
			$html .= "<td class=\"responseLabel\" width=\"{$rwidth}mm\">{$r['text']}</td>";
2318
		}
2319
		$html .= "<td></td></tr></table>";
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2320
		$this->writeHTMLCell($this->getColumnWidth(), $this->singleResponseAreaHeight, $this->getColumnX(), $this->GetY(), $this->style . $html,0,1,true,true);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2321
		$currentY = $this->GetY();
2322
93 by Adam Zammit
Added paginiation improvements and bug fixes from downstream (LimeSurvey) thank you mfaber!
2323
		$html = "<table><tr><td width=\"{$textwidth}mm\" class=\"matrixResponseGroupLabel\">$responsegrouplabel</td><td></td></tr></table>";
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2324
		$this->writeHTMLCell($this->getColumnWidth(), $this->singleResponseAreaHeight, $this->getColumnX(), $this->GetY(), $this->style . $html,0,1,true,true);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2325
2326
		$ncurrentY = $this->GetY();
2327
2328
		$this->SetY($currentY,false);		
2329
2330
		//Set X position
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2331
		$this->SetX($this->getColumnX() + $textwidth,false);	
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2332
2333
2334
		foreach ($subquestions as $s)
2335
		{
2336
			//Add box group to current layout
22 by azammitdcarf
Updated test_questionnaire.xml variable names
2337
			if ($parenttext == false)
44 by azammitdcarf
Banding XML will include number only fields where set to integer, number or numeric
2338
				$this->addBoxGroup($bgtype,$s['varname'],$s['text']);
22 by azammitdcarf
Updated test_questionnaire.xml variable names
2339
			else				
44 by azammitdcarf
Banding XML will include number only fields where set to integer, number or numeric
2340
				$this->addBoxGroup($bgtype,$s['varname'],$parenttext . $this->subQuestionTextSeparator . $s['text']);
22 by azammitdcarf
Updated test_questionnaire.xml variable names
2341
82 by azammitdcarf
Added defaultValue attribute to responses to allow for pre-filling
2342
			$string = false;
2343
			if (isset($s['defaultvalue'])) 
2344
				$string = substr($defaultvalue,0,$width);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2345
2346
			//Draw the cells
82 by azammitdcarf
Added defaultValue attribute to responses to allow for pre-filling
2347
			$this->drawCells($width,$string);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2348
2349
			//Move X for a gap
2350
			$this->SetX($this->GetX() + $this->textResponseLineSpacing,false);
2351
			$this->SetY($currentY,false);		
2352
		}
2353
2354
		//Move cursor back to the right spot
2355
		$this->SetY($ncurrentY,false);
2356
	}
2357
80 by azammitdcarf
Allow for singleChoiceHorizontal arrays (with subquestions) to be split over multiple pages / columns
2358
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2359
	/**
80 by azammitdcarf
Allow for singleChoiceHorizontal arrays (with subquestions) to be split over multiple pages / columns
2360
	 * Draw the head of a single choice horizontal table of responses
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2361
	 * 
2362
	 * @param array $categories The response categories
93 by Adam Zammit
Added paginiation improvements and bug fixes from downstream (LimeSurvey) thank you mfaber!
2363
	 * @param string|bool $responsegrouplabel The label for this response group or false if not specified
80 by azammitdcarf
Allow for singleChoiceHorizontal arrays (with subquestions) to be split over multiple pages / columns
2364
	 * 
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2365
	 * @author Adam Zammit <adam.zammit@acspri.org.au>
80 by azammitdcarf
Allow for singleChoiceHorizontal arrays (with subquestions) to be split over multiple pages / columns
2366
	 * @since  2012-06-05
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2367
	 */
93 by Adam Zammit
Added paginiation improvements and bug fixes from downstream (LimeSurvey) thank you mfaber!
2368
	protected function drawSingleChoiceHorizontalHead($categories, $responsegrouplabel=false)
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2369
	{
2370
		$total = count($categories);
2371
		$currentY = $this->GetY();
30 by azammitdcarf
Horizontal box function respects box widths
2372
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2373
		if ($total > $this->singleResponseHorizontalMax) //change if too many cats
2374
			$rwidth = $this->singleResponseVerticalAreaWidthSmall;
2375
		else		
2376
			$rwidth = $this->singleResponseVerticalAreaWidth;
2377
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2378
		$textwidth = ($this->getColumnWidth() - $this->skipColumnWidth) - ($rwidth * $total);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2379
93 by Adam Zammit
Added paginiation improvements and bug fixes from downstream (LimeSurvey) thank you mfaber!
2380
		//Draw a label for a group of Questions/Responses (e.g. useful for dual scale matrix questions)        
2381
		if ($responsegrouplabel!=false)
2382
		{
2383
			$this->setBackground('question');
2384
			$this->setDefaultFont();
2385
			$this->MultiCell($textwidth,$this->responseLabelHeight,$responsegrouplabel.':',0,'L',false,0,$this->getColumnX()+$this->questionTitleWidth,$this->GetY(),true,0,false,true,$this->responseLabelHeight,'B',true);
2386
        	}
34 by azammitdcarf
Replaced drawing using HTML tables with TCPDF Multicell to allow for aligning text vertically
2387
2388
		//First draw a background of height $this->responseLabelHeight
2389
		$html = "<div></div>";
2390
		$this->setBackground('question');
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2391
		$this->writeHTMLCell($this->getColumnWidth(), $this->responseLabelHeight, $this->getColumnX(), $currentY , $this->style . $html,0,1,true,true);
34 by azammitdcarf
Replaced drawing using HTML tables with TCPDF Multicell to allow for aligning text vertically
2392
2393
		$this->setDefaultFont($this->responseLabelFontSize);			
2394
2395
		$count = 0;
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2396
		//Draw a Cell for each rwidth from $textwidth + $this->getColumnX(),currentY 
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2397
		foreach ($categories as $r)
2398
		{
34 by azammitdcarf
Replaced drawing using HTML tables with TCPDF Multicell to allow for aligning text vertically
2399
			$y = $currentY;
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2400
			$x = ($textwidth + $this->getColumnX() + ($rwidth * $count));
73 by azammitdcarf
Updated font sizes to match default widths a bit better
2401
			
2402
			// Going to break the line because of long word
2403
			if ($this->wordLength($r['text']) > $this->responseLabelSmallWordLength)
2404
				$this->setDefaultFont($this->responseLabelFontSizeSmall);			
2405
34 by azammitdcarf
Replaced drawing using HTML tables with TCPDF Multicell to allow for aligning text vertically
2406
			$this->MultiCell($rwidth,$this->responseLabelHeight,$r['text'],0,'C',false,0,$x,$y,true,0,false,true,$this->responseLabelHeight,'B',true);
73 by azammitdcarf
Updated font sizes to match default widths a bit better
2407
2408
			//reset font
2409
			if ($this->wordLength($r['text']) > $this->responseLabelSmallWordLength)
2410
				$this->setDefaultFont($this->responseLabelFontSize);			
2411
34 by azammitdcarf
Replaced drawing using HTML tables with TCPDF Multicell to allow for aligning text vertically
2412
			$count++;
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2413
		}
80 by azammitdcarf
Allow for singleChoiceHorizontal arrays (with subquestions) to be split over multiple pages / columns
2414
	}
2415
2416
	/**
2417
	 * Draw a horizontal table of respones including "eye guides"
2418
	 * 
2419
	 * @param array $categories The response categories
2420
	 * @param array $subquestions The subquestions if any 
2421
	 * @param string|bool $parenttext The question text of the parent or false if not specified
93 by Adam Zammit
Added paginiation improvements and bug fixes from downstream (LimeSurvey) thank you mfaber!
2422
	 * @param string|bool $responsegrouplabel The label for this response group or false if not specified
80 by azammitdcarf
Allow for singleChoiceHorizontal arrays (with subquestions) to be split over multiple pages / columns
2423
	 *
2424
	 * @author Adam Zammit <adam.zammit@acspri.org.au>
2425
	 * @since  2010-09-08
2426
	 */
93 by Adam Zammit
Added paginiation improvements and bug fixes from downstream (LimeSurvey) thank you mfaber!
2427
	protected function drawSingleChoiceHorizontal($categories, $subquestions = array(array('text' => '')),$parenttext = false, $responsegrouplabel=false)
80 by azammitdcarf
Allow for singleChoiceHorizontal arrays (with subquestions) to be split over multiple pages / columns
2428
	{
2429
		$total = count($categories);
2430
		$currentY = $this->GetY();
2431
2432
		if ($total > $this->singleResponseHorizontalMax) //change if too many cats
2433
			$rwidth = $this->singleResponseVerticalAreaWidthSmall;
2434
		else		
2435
			$rwidth = $this->singleResponseVerticalAreaWidth;
2436
2437
		$textwidth = ($this->getColumnWidth() - $this->skipColumnWidth) - ($rwidth * $total);
2438
2439
		//draw the header
93 by Adam Zammit
Added paginiation improvements and bug fixes from downstream (LimeSurvey) thank you mfaber!
2440
		$this->drawSingleChoiceHorizontalHead($categories, $responsegrouplabel);
34 by azammitdcarf
Replaced drawing using HTML tables with TCPDF Multicell to allow for aligning text vertically
2441
		$currentY += $this->responseLabelHeight;
2442
93 by Adam Zammit
Added paginiation improvements and bug fixes from downstream (LimeSurvey) thank you mfaber!
2443
		//don't continue if page break already
2444
		if ($this->pageBreakOccured)
2445
			return;
2446
80 by azammitdcarf
Allow for singleChoiceHorizontal arrays (with subquestions) to be split over multiple pages / columns
2447
		for ($i = 0; $i < count($subquestions); $i++)
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2448
		{
93 by Adam Zammit
Added paginiation improvements and bug fixes from downstream (LimeSurvey) thank you mfaber!
2449
			if ($this->allowSplittingSingleChoiceHorizontal && $i == 1) 
2450
				$this->startTransaction(); //start a transaction when one line drawn
2451
			
80 by azammitdcarf
Allow for singleChoiceHorizontal arrays (with subquestions) to be split over multiple pages / columns
2452
			$s = $subquestions[$i];
2453
93 by Adam Zammit
Added paginiation improvements and bug fixes from downstream (LimeSurvey) thank you mfaber!
2454
			//Add box group to current layout
2455
			if ($parenttext == false)
2456
				$this->addBoxGroup(1,$s['varname'],$s['text']);
2457
			else				
2458
				$this->addBoxGroup(1,$s['varname'],$parenttext . $this->subQuestionTextSeparator . $s['text']);
2459
	
2460
			//Draw background
2461
			$html = "<div></div>";
2462
			$this->setBackground('question');
2463
			$this->writeHTMLCell($this->getColumnWidth(), $this->singleResponseHorizontalHeight, $this->getColumnX(), $currentY, $this->style . $html,0,1,true,true);	
2464
			$this->setDefaultFont($this->responseTextFontSize);			
2465
2466
			$newlineheight = $this->singleResponseHorizontalHeight;
2467
			$heightadjust = 0;
2468
2469
			$testcells = $this->getNumLines($s['text'],$textwidth);
2470
2471
			if ($testcells > $this->singleResponseHorizontalMaxLines)
2472
			{
2473
				//more than two lines so need to increase the space between these questions
2474
				$heightadjust = (($this->singleResponseHorizontalHeight / $this->singleResponseHorizontalMaxLines) * ($testcells - $this->singleResponseHorizontalMaxLines));
2475
2476
				$newlineheight = $newlineheight + $heightadjust;
2477
2478
				$this->setBackground('question');
2479
				$this->writeHTMLCell($this->getColumnWidth(), $newlineheight, $this->getColumnX(), $currentY, $this->style . $html,0,1,true,false);	
2480
				$this->setDefaultFont($this->responseTextFontSize);			
2481
2482
				$this->MultiCell($textwidth,$newlineheight,$s['text'],0,'R',false,0,$this->getColumnX(),$currentY,true,0,false,true,$newlineheight,'M',false);
2483
			}
2484
			else
2485
			{
2486
				$this->MultiCell($textwidth,$this->singleResponseHorizontalHeight,$s['text'],0,'R',false,0,$this->getColumnX(),$currentY,true,0,false,true,$this->singleResponseHorizontalHeight,'M',false);
2487
			}
2488
				
2489
				
2490
			$other = false;
2491
			if (isset($s['other']))
2492
				$other = true;
2493
2494
			//Draw the categories horizontally
2495
			$rnum = 1;
2496
			foreach ($categories as $r)
2497
			{
2498
				if ($total == 1) $num = 'only';
2499
				else if ($rnum == 1) $num = 'first';
2500
				else if ($rnum < $total) $num = 'middle';
2501
				else if ($rnum == $total) $num = 'last';
2502
2503
				$bfilled = false;
2504
				if (isset($s['defaultvalue']) && $s['defaultvalue'] !== false && $s['defaultvalue'] == $r['value'])
2505
					$bfilled = true;
2506
	
2507
				$position = $this->drawHorizontalResponseBox(($this->getColumnX() + $textwidth + (($rnum - 1) * $rwidth)),$currentY + ($heightadjust/2), $num,$other,false,($total > $this->singleResponseHorizontalMax),$bfilled);
2508
		
2509
				//Add box to the current layout
2510
				$this->addBox($position[0],$position[1],$position[2],$position[3],$r['value'],$r['text']);
2511
	
2512
				$rnum++;
2513
			}
2514
	
2515
			if (($this->GetY() - $currentY) > $newlineheight)
2516
				$currentY = $this->GetY();
2517
			else
2518
				$currentY = $currentY + $newlineheight;
2519
2520
			$this->SetY($currentY,false);
2521
2522
			if ($other)
2523
				$this->drawOther($s['other']);
2524
2525
			//only allow a page break if defined and we have more than one item already on this page
2526
			if ($this->allowSplittingSingleChoiceHorizontal && $this->pageBreakOccured && $i > 0) 
2527
			{
2528
				$this->pageBreakOccured = false;
2529
				$this->rollBackTransaction(true);
2530
				$this->SetAutoPageBreak(false); //Temporarily set so we don't trigger a page break
2531
				$this->fillPageBackground();
2532
				$this->newPage();
2533
				$this->drawSingleChoiceHorizontalHead($categories, $responsegrouplabel);
2534
							
80 by azammitdcarf
Allow for singleChoiceHorizontal arrays (with subquestions) to be split over multiple pages / columns
2535
				//reset currentY
2536
				$currentY = $this->GetY() + $this->responseLabelHeight;
2537
				
93 by Adam Zammit
Added paginiation improvements and bug fixes from downstream (LimeSurvey) thank you mfaber!
2538
				$i = $i - 1; //go back and draw subquestions on the new page
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2539
			}
2540
			else
80 by azammitdcarf
Allow for singleChoiceHorizontal arrays (with subquestions) to be split over multiple pages / columns
2541
			{
93 by Adam Zammit
Added paginiation improvements and bug fixes from downstream (LimeSurvey) thank you mfaber!
2542
				if ($this->allowSplittingSingleChoiceHorizontal && $i > 0)
2543
				{
2544
				    $this->commitTransaction();
2545
				    $this->startTransaction(); //start a transaction to allow for splitting over pages if necessary
2546
				}
80 by azammitdcarf
Allow for singleChoiceHorizontal arrays (with subquestions) to be split over multiple pages / columns
2547
			}
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2548
		}
2549
	}
2550
89 by Adam Zammit
Allow for the specifying of sectionHeight
2551
	
2552
	/**
2553
	 * Draw vertical questions separately instead of in a matrix
2554
	 * 
2555
	 * @param array $categories An array containing the category text, value, skipto and other
2556
	 * @param array $subquestions An array containing the subquestions if any
2557
	 * @param string|bool $parenttext The question text of the parent or false if not specified
2558
	 * @param string|bool $help Help text if any for the responses
2559
	 * 
2560
	 * @author Adam Zammit <adam.zammit@acspri.org.au>
2561
	 * @since  2013-07-30
2562
	 */
2563
	protected function drawSingleChoiceVerticalSeparate($categories,$subquestions,$parenttext,$help)
2564
	{
2565
		for ($sc = 0; $sc < count($subquestions); $sc++)
2566
		{
2567
			$s = $subquestions[$sc];
2568
2569
			$this->drawQuestionHead("",$this->numberToLetter($sc + 1) . ". " . $s['text'],$help);
2570
			//Don't send it twice
2571
			unset($s['text']);
2572
			$this->drawSingleChoiceVertical($categories,array(array($s)),$this->subQuestionTextSeparator . $s['text']);
2573
		}
2574
	}
2575
2576
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2577
	/**
2578
	 * Draw a vertical table of single choice responses including "eye guides"
2579
	 * 
2580
	 * @param array $categories An array containing the category text, value, skipto and other
2581
	 * @param array $subquestions An array containing the subquestions if any
22 by azammitdcarf
Updated test_questionnaire.xml variable names
2582
	 * @param string|bool $parenttext The question text of the parent or false if not specified
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2583
	 * 
2584
	 * @author Adam Zammit <adam.zammit@acspri.org.au>
2585
	 * @since  2010-09-02
2586
	 */
22 by azammitdcarf
Updated test_questionnaire.xml variable names
2587
	protected function drawSingleChoiceVertical($categories, $subquestions = array(array('text' => '')),$parenttext = false)
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2588
	{
2589
		$currentY = $this->GetY();
2590
		$total = count($subquestions);
2591
73 by azammitdcarf
Updated font sizes to match default widths a bit better
2592
		$rwidth = $this->singleResponseVerticalAreaWidth;
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2593
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2594
		$textwidth = ($this->getColumnWidth() - $this->skipColumnWidth) - ($rwidth * $total);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2595
2596
		if (count($categories) > 1)
2597
		{
29 by azammitdcarf
Cleaned up CSS
2598
			$isempty = true;
34 by azammitdcarf
Replaced drawing using HTML tables with TCPDF Multicell to allow for aligning text vertically
2599
			$count = 0;
2600
2601
			//First draw a background of height $this->responseLabelHeight
2602
			$html = "<div></div>";
2603
			$this->setBackground('question');
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2604
			$this->writeHTMLCell($this->getColumnWidth(), $this->responseLabelHeight, $this->getColumnX(), $currentY , $this->style . $html,0,1,true,true);
34 by azammitdcarf
Replaced drawing using HTML tables with TCPDF Multicell to allow for aligning text vertically
2605
2606
35 by azammitdcarf
Use setDefaultFont function instead of SetFont
2607
			$this->setDefaultFont($this->responseLabelFontSize);			
34 by azammitdcarf
Replaced drawing using HTML tables with TCPDF Multicell to allow for aligning text vertically
2608
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2609
			//Draw a Cell for each rwidth from $textwidth + $this->getColumnX(),currentY 
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2610
			foreach ($subquestions as $r)
2611
			{
34 by azammitdcarf
Replaced drawing using HTML tables with TCPDF Multicell to allow for aligning text vertically
2612
				$y = $currentY;
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2613
				$x = ($textwidth + $this->getColumnX() + ($rwidth * $count));
73 by azammitdcarf
Updated font sizes to match default widths a bit better
2614
2615
				// Going to break the line because of long word
2616
				if ($this->wordLength($r['text']) > $this->responseLabelSmallWordLength)
2617
					$this->setDefaultFont($this->responseLabelFontSizeSmall);			
2618
34 by azammitdcarf
Replaced drawing using HTML tables with TCPDF Multicell to allow for aligning text vertically
2619
				$this->MultiCell($rwidth,$this->responseLabelHeight,$r['text'],0,'C',false,0,$x,$y,true,0,false,true,$this->responseLabelHeight,'B',true);
73 by azammitdcarf
Updated font sizes to match default widths a bit better
2620
				if ($this->wordLength($r['text']) > $this->responseLabelSmallWordLength)
2621
					$this->setDefaultFont($this->responseLabelFontSize);			
2622
	
29 by azammitdcarf
Cleaned up CSS
2623
				if (!empty($r['text'])) $isempty = false;
34 by azammitdcarf
Replaced drawing using HTML tables with TCPDF Multicell to allow for aligning text vertically
2624
				$count++;
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2625
			}
34 by azammitdcarf
Replaced drawing using HTML tables with TCPDF Multicell to allow for aligning text vertically
2626
2627
			if ($isempty)
2628
				$this->SetY($currentY,false);
2629
			else
2630
				$this->SetY($currentY+$this->responseLabelHeight);
2631
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2632
		}
2633
2634
		$currentY = $this->GetY();
2635
		$firstY = $currentY;
2636
2637
		$snum = 0;
2638
		$total = count($categories);
2639
		$ypos = array();
2640
2641
		foreach($subquestions as $s)
2642
		{
2643
			$rnum = 1;
2644
2645
			$this->SetY($firstY, false);
2646
			$currentY = $firstY;
22 by azammitdcarf
Updated test_questionnaire.xml variable names
2647
			
2648
			if ($parenttext == false)
2649
				$this->addBoxGroup(1,$s['varname'],$s['text']);
2650
			else
2651
				$this->addBoxGroup(1,$s['varname'],$parenttext . $this->subQuestionTextSeparator . $s['text']);
2652
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2653
			$x = $this->getColumnX() + $textwidth + ($rwidth * $snum) + ((($rwidth - $this->singleResponseBoxWidth) / 2.0 ));
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2654
2655
			$other = false;
2656
2657
			foreach($categories as $r)
2658
			{
2659
				if ($total == 1) $num = 'only';
2660
				else if ($rnum == 1) $num = 'first';
2661
				else if ($rnum < $total) $num = 'middle';
2662
				else if ($rnum == $total) $num = 'last';
2663
2664
				//add a new line for each response that goes to
2665
				if ($snum == 0)
2666
				{
2667
					//only have to do this once
34 by azammitdcarf
Replaced drawing using HTML tables with TCPDF Multicell to allow for aligning text vertically
2668
					//Draw background
2669
					$html = "<div></div>";
2670
					$this->setBackground('question');
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2671
					$this->writeHTMLCell($this->getColumnWidth(), $this->singleResponseAreaHeight, $this->getColumnX(), $this->GetY(), $this->style . $html,0,1,true,true);	
35 by azammitdcarf
Use setDefaultFont function instead of SetFont
2672
					$this->setDefaultFont($this->responseTextFontSize);			
34 by azammitdcarf
Replaced drawing using HTML tables with TCPDF Multicell to allow for aligning text vertically
2673
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2674
					$this->MultiCell($textwidth,$this->singleResponseAreaHeight,$r['text'],0,'R',false,0,$this->getColumnX(),$currentY,true,0,false,true,$this->singleResponseAreaHeight,'M',true);
34 by azammitdcarf
Replaced drawing using HTML tables with TCPDF Multicell to allow for aligning text vertically
2675
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2676
				}
2677
2678
				$skipto = false;
2679
				$other = false;
2680
2681
				if (isset($r['skipto'])) $skipto = $r['skipto'];
2682
				if (isset($r['other']) && $rnum == $total) $other = $r['other']; //only set for last in set
2683
82 by azammitdcarf
Added defaultValue attribute to responses to allow for pre-filling
2684
				$bfilled = false;
84 by azammitdcarf
Fixed bug: Boxes were being pre-filled where value == 0 due to not checking === false
2685
				if (isset($s['defaultvalue']) && $s['defaultvalue'] !== false && $s['defaultvalue'] == $r['value'])
82 by azammitdcarf
Added defaultValue attribute to responses to allow for pre-filling
2686
					$bfilled = true;
2687
	
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2688
				//Draw the box over the top
82 by azammitdcarf
Added defaultValue attribute to responses to allow for pre-filling
2689
				$position = $this->drawVerticalResponseBox($x,$currentY, $num, $other, $skipto, $bfilled);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2690
2691
				//Add box to the current layout
2692
				$this->addBox($position[0],$position[1],$position[2],$position[3],$r['value'],$r['text']);
2693
2694
				//Store ypos for next round of boxes
2695
				if ($snum == 0)
2696
				{
2697
					if (($this->GetY() - $currentY) > $this->singleResponseAreaHeight)
2698
						$currentY = $this->GetY();
2699
					else
2700
						$currentY = $currentY + $this->singleResponseAreaHeight;
2701
		
2702
					$ypos[$rnum] = $currentY;
2703
				}
2704
				else
2705
					$currentY = $ypos[$rnum];
2706
				
2707
				$this->SetY($currentY,false);
2708
2709
				$rnum++;
2710
			}
2711
2712
			if ($other !== false)
2713
			{
2714
				//Display the "other" variable
88 by Adam Zammit
Allow for contingentQuestions to be specified on subQuestions (for matrix "Other")
2715
				$this->drawOther($other);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2716
			}
2717
2718
			$snum++;
2719
		}
2720
	}
2721
2722
	/**
88 by Adam Zammit
Allow for contingentQuestions to be specified on subQuestions (for matrix "Other")
2723
	 * Draw an "other" box
2724
	 * 
2725
	 * @param array $other An array continaing varname,text,width,defaultvalue
2726
	 * 
2727
	 * @return TODO
2728
	 * @author Adam Zammit <adam.zammit@acspri.org.au>
2729
	 * @since  2013-05-01
2730
	 */
2731
	protected function drawOther($other)
2732
	{
91 by root
Added format to contingentQuestion attribute
2733
		$btid = 3;
2734
2735
		if ($other['format'] == 'longtext')
2736
			$btid = 6;
2737
		
2738
		$this->addBoxGroup($btid,$other['varname'],$other['text'],$other['width']);	
88 by Adam Zammit
Allow for contingentQuestions to be specified on subQuestions (for matrix "Other")
2739
2740
		$defaultvalue = false;
2741
		if (isset($other['defaultvalue']) && $other['defaultvalue'] !== false)
2742
			$defaultvalue = $other['defaultvalue'];
2743
91 by root
Added format to contingentQuestion attribute
2744
		if ($btid == 3)
2745
			$this->drawText($other['text'],$other['width'],$defaultvalue);
2746
		else
2747
			$this->drawLongText($other['width'],$defaultValue,$other['text']);
2748
88 by Adam Zammit
Allow for contingentQuestions to be specified on subQuestions (for matrix "Other")
2749
		//Insert a gap here
2750
		$this->Rect($this->getColumnX(),$this->GetY(),$this->getColumnWidth(),$this->subQuestionLineSpacing,'F',array(),$this->backgroundColourQuestion);
2751
		$this->SetY($this->GetY() + $this->subQuestionLineSpacing,false);
2752
	}
2753
2754
	/**
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2755
	 * Draw the header of a question (question title, text and help text if any)
2756
	 *
2757
	 * @param string $title The question title (number)
2758
	 * @param string $text The question text (can be HTML)
2759
	 * @param string|bool $help The question help text or false if none (can be HTML)
63 by azammitdcarf
Replaced $questionTextWidth with $questionTextRightMargin to manage varying page widths better
2760
	 * @param string|bool $specifier The question specifier text or false if none (can be HTML)
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2761
	 */
63 by azammitdcarf
Replaced $questionTextWidth with $questionTextRightMargin to manage varying page widths better
2762
	protected function drawQuestionHead($title,$text,$help = false,$specifier = false)
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2763
	{
2764
		$this->setBackground('question');
2765
		//Cell for question number (title) and text including a white border at the bottom
66 by azammitdcarf
Added a skipTo registry - so question titles can be bolded where there is a skip to them
2766
		
2767
		$class = "questionTitle";
2768
2769
		//If there is a skip to this question, make the question title bigger
2770
		if (isset($this->skipToRegistry[$title]))
2771
			$class = "questionTitleSkipTo";
2772
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2773
		$html = "<table><tr><td class=\"$class\" width=\"" . $this->questionTitleWidth . "mm\">$title</td><td class=\"questionText\" width=\"" . ($this->getColumnWidth() - $this->questionTextRightMargin - $this->questionTitleWidth) . "mm\">$text</td><td></td></tr>";
63 by azammitdcarf
Replaced $questionTextWidth with $questionTextRightMargin to manage varying page widths better
2774
2775
		if ($specifier !== false)
2776
		{
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2777
			$html .= "<tr><td></td><td></td><td></td></tr><tr><td class=\"$class\" width=\"" . $this->questionTitleWidth . "mm\">&nbsp;</td><td class=\"questionSpecifier\" width=\"" . ($this->getColumnWidth() - $this->questionTextRightMargin - $this->questionTitleWidth) . "mm\">$specifier</td><td></td></tr>";
63 by azammitdcarf
Replaced $questionTextWidth with $questionTextRightMargin to manage varying page widths better
2778
		}
2779
2780
		$html .= "</table>";
2781
		
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2782
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2783
		$this->writeHTMLCell($this->getColumnWidth(), 1, $this->getColumnX(), $this->GetY(), $this->style . $html,0,1,true,true);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2784
2785
		if ($help != false)
2786
		{
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2787
			$html = "<table><tr><td width=\"" . ($this->getColumnWidth() -  $this->skipColumnWidth) . "mm\" class=\"questionHelp\">$help</td><td></td></tr></table>";
2788
			$this->writeHTMLCell($this->getColumnWidth(), 1, $this->getColumnX(), $this->GetY(), $this->style . $html,0,1,true,true);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2789
2790
		}
2791
	}
2792
2793
	/**
2794
	 * Add a new section to the page
2795
	 *
2796
	 * @param string $text The text of the section
2797
	 * @param string $desc The description of this section
29 by azammitdcarf
Cleaned up CSS
2798
	 * @param string $info Information for this section
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2799
	 */
29 by azammitdcarf
Cleaned up CSS
2800
	protected function addSection($desc = 'queXMLPDF Section',$title = false,$info = false)
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2801
	{
2802
		$this->sectionCP++;
2803
2804
		if ($title === false)
2805
			$title = $this->sectionCP;
2806
2807
		$this->section[$this->sectionCP] = array('label' => $desc, 'title' => $title);
2808
35 by azammitdcarf
Use setDefaultFont function instead of SetFont
2809
		$html = "<span class=\"sectionTitle\">$title:</span>&nbsp;<span class=\"sectionDescription\">$desc</span>";
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2810
46 by azammitdcarf
Updated code to remove noticies from Limesurvey bug: 05090
2811
		if ($info && !empty($info))
29 by azammitdcarf
Cleaned up CSS
2812
			$html .= "<div class=\"sectionInfo\">$info</div>";
2813
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2814
		$this->setBackground('section');
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2815
		$this->writeHTMLCell($this->getColumnWidth(),$this->sectionHeight,$this->getColumnX(),$this->getY(),$this->style . $html,array('B' => array('width' => 1, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $this->backgroundColourEmpty)),1,true,true,'');
75 by azammitdcarf
Made output colours|colors greyscale|grayscale
2816
		$this->setBackground('empty');
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2817
	}
2818
2819
	/**
2820
	 * Convert mm to pixels based on the set ppi (dpi)
2821
	 *
2822
	 * @param float $mm Measurement in millimetres
2823
	 * @return int Pixel value as an integer
2824
	 */
2825
	public function mm2px($mm)
2826
	{
2827
		return round($mm * ($this->ppi / self::INCH_IN_MM));
2828
	}
2829
2830
	/**
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2831
	 * Make sure to fill the remaining columns on the last page
2832
	 * 
2833
	 * @author Adam Zammit <adam.zammit@acspri.org.au>
2834
	 * @since  2012-05-31
2835
	 */
2836
	protected function fillLastPageBackground()
2837
	{
2838
		while ($this->columnCP < $this->columns)
2839
		{
2840
			$this->fillPageBackground();
2841
			$this->SetXY($this->getColumnX(),($this->cornerBorder + $this->cornerWidth));
2842
			$this->columnCP++;
2843
		}
2844
	}
2845
2846
	/**
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2847
	 * Draw the background from the current Y position to the bottom of the page
2848
	 * 
2849
	 * @author Adam Zammit <adam.zammit@acspri.org.au>
2850
	 * @since  2010-09-15
2851
	 */
76 by azammitdcarf
Added column variables
2852
	protected function fillPageBackground()
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2853
	{
2854
		$height = $this->getPageHeight() - $this->cornerBorder - $this->GetY() + $this->questionBorderBottom;
2855
		$html = "<div></div>";
2856
		$this->setBackground('question');
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2857
		$this->writeHTMLCell($this->getColumnWidth(), $height, $this->getColumnX(), $this->GetY() - $this->questionBorderBottom, $this->style . $html,0,1,true,true);
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2858
	}
2859
2860
	/**
2861
	 * Create a new queXML PDF page
2862
	 *
2863
	 * Draw the barcode and page corners
2864
	 * 
2865
	 */
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2866
	protected function newPage($init = false) 
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2867
	{
78 by azammitdcarf
New feature: Column display (set $columns to a value greater than 1)
2868
		$this->columnCP++; //increment the column pointer
2869
2870
		if ($init || ($this->columnCP >= $this->columns)) // if it is time for a new page
2871
		{
2872
			$this->AddPage();
2873
2874
			//Set Auto page break to false 
2875
			$this->SetAutoPageBreak(false);
2876
2877
			$this->SetMargins(0,0,0);
2878
			$this->SetHeaderMargin(0);
2879
			$this->SetFooterMargin(0);
2880
	
2881
			//Shortcuts to make the code (a bit) nicer
2882
			$width = $this->getPageWidth();
2883
			$height = $this->getPageHeight();
2884
			$cb = $this->cornerBorder;
2885
			$cl = $this->cornerLength;
2886
	
2887
			$this->SetDrawColor($this->lineColour[0]);
2888
		
2889
			$barcodeStyle = array('border' => false, 'padding' => '0', 'bgcolor' => false, 'text' => false, 'stretch' => true);
2890
			$lineStyle = array('width' => $this->cornerWidth, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0));
2891
			
2892
			//Top left
2893
			$this->Line($cb,$cb,$cb + $cl,$cb,$lineStyle);
2894
			$this->Line($cb,$cb,$cb,$cb + $cl,$lineStyle);
2895
			
2896
			//Top right
2897
			$this->Line($width - $cb,$cb,$width - $cb - $cl,$cb,$lineStyle);
2898
			$this->Line($width - $cb,$cb,$width - $cb,$cb + $cl,$lineStyle);
2899
			
2900
			//Bottom left
2901
			$this->Line($cb,$height - $cb,$cb + $cl,$height - $cb,$lineStyle);
2902
			$this->Line($cb,$height - $cb,$cb,$height - ($cb + $cl),$lineStyle);
2903
			
2904
			//Bottom right
2905
			$this->Line($width - $cb,$height - $cb,$width - $cb - $cl,$height - $cb,$lineStyle);
2906
			$this->Line($width - $cb,$height - $cb,$width - $cb,$height - ($cb + $cl),$lineStyle);
2907
	
2908
			$barcodeValue = substr(str_pad($this->questionnaireId,$this->idLength,"0",STR_PAD_LEFT),0,$this->idLength) . substr(str_pad($this->getPage(),$this->pageLength,"0",STR_PAD_LEFT),0,$this->pageLength);	
2909
	
2910
			//Calc X position of barcode from page width
2911
			$barcodeX = $width - ($this->barcodeMarginX + $this->barcodeW);
2912
	
2913
			$this->write1DBarcode($barcodeValue, $this->barcodeType, $barcodeX, $this->barcodeY, $this->barcodeW, $this->barcodeH,'', $barcodeStyle, 'N');
2914
		
2915
			//Add this page to the layout system
2916
			$b = $this->cornerBorder + ($this->cornerWidth / 2.0); //temp calc for middle of line
2917
			$this->layout[$barcodeValue] = array(	'id' => $barcodeValue,
2918
								'tlx' => $this->mm2px($b),
2919
								'tly' => $this->mm2px($b),
2920
								'trx' => $this->mm2px($width - $b),
2921
								'try' => $this->mm2px($b),
2922
								'brx' => $this->mm2px($width - $b),
2923
								'bry' => $this->mm2px($height - $b),
2924
								'blx' => $this->mm2px($b),
2925
								'bly' => $this->mm2px($height - $b),
2926
								'rotation' => 0,
2927
								'boxgroup' => array()
2928
								);
2929
			$this->layoutCP = $barcodeValue;
2930
	
2931
			$this->SetXY($cb + $this->cornerWidth, $cb + $this->cornerWidth);
2932
	
2933
			$this->setBackground('empty');
2934
2935
			$this->columnCP = 0; //reset column pointer
2936
		}
2937
		else // move to a new column
2938
		{
2939
			$this->SetXY($this->getColumnX(),($this->cornerBorder + $this->cornerWidth));
2940
		}
80 by azammitdcarf
Allow for singleChoiceHorizontal arrays (with subquestions) to be split over multiple pages / columns
2941
		$this->SetAutoPageBreak(true,$this->getMainPageX());
93 by Adam Zammit
Added paginiation improvements and bug fixes from downstream (LimeSurvey) thank you mfaber!
2942
2943
        //after a new page was begun....page should not have already ended
2944
        $this->pageBreakOccured = false;
20 by azammitdcarf
queXMLPDF: A Class based on TCPDF for producing queXML files with an associated banding XML for queXF
2945
	}
2946
2947
	/**
2948
	 * Override of the acceptPageBreak function
2949
	 *
2950
	 * Allow our page handling function to know that a page break has occured
2951
	 *
2952
	 * $return bool Returns false so no page break is automatically issued
2953
	 */
2954
	public function AcceptPageBreak()
2955
	{
2956
		$this->pageBreakOccured = true;
2957
		return FALSE;
2958
	}
2959
}