source-class-TCPDFEX

It appears that you are using AdBlocking software. The cost of running this website is covered by advertisements. If you like it please feel free to a small amount of money to secure the future of this website.
Overview

Classes

Interfaces

Exceptions

Functions

  1: <?php
  2: //============================================================+
  3: // File name   : tcpdfex.php
  4: // Begin       : 2010-12-06
  5: // Last Update : 2014-04-15
  6: // Author      : Nicola Asuni - Tecnick.com LTD - www.tecnick.com - info@tecnick.com
  7: // License     : http://www.tecnick.com/pagefiles/tcpdf/LICENSE.TXT GNU-LGPLv3 + YOU CAN'T REMOVE ANY TCPDF COPYRIGHT NOTICE OR LINK FROM THE GENERATED PDF DOCUMENTS.
  8: // -------------------------------------------------------------------
  9: // Copyright (C) 2002-2014 Nicola Asuni - Tecnick.com LTD
 10: //
 11: // This file is part of TCPDF software library.
 12: //
 13: // TCPDF is free software: you can redistribute it and/or modify it
 14: // under the terms of the GNU Lesser General Public License as
 15: // published by the Free Software Foundation, either version 3 of the
 16: // License, or (at your option) any later version. Additionally,
 17: // YOU CAN'T REMOVE ANY TCPDF COPYRIGHT NOTICE OR LINK FROM THE
 18: // GENERATED PDF DOCUMENTS.
 19: //
 20: // TCPDF is distributed in the hope that it will be useful, but
 21: // WITHOUT ANY WARRANTY; without even the implied warranty of
 22: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 23: // See the GNU Lesser General Public License for more details.
 24: //
 25: // You should have received a copy of the License
 26: // along with TCPDF. If not, see
 27: // <http://www.tecnick.com/pagefiles/tcpdf/LICENSE.TXT>.
 28: //
 29: // See LICENSE.TXT file for more information.
 30: // -------------------------------------------------------------------
 31: //
 32: // Description : This is a PHP class for generating PDF documents without
 33: //               requiring external extensions.
 34: //============================================================+
 35: 
 36: /**
 37:  * @file
 38:  * This is an extension of the TCPDF class for creating PDF document.
 39:  * This extension allows you to define custom Header and Footer for PDF documents.
 40:  * @package com.tecnick.tcpdf
 41:  * @author Nicola Asuni
 42:  */
 43: 
 44: require(dirname(__FILE__).'/../tcpdf/tcpdf.php');
 45: 
 46: /**
 47:  * @class TCPDFEX
 48:  * This is an extension of the TCPDF class for creating PDF document.
 49:  * This extension allows you to define custom Header and Footer for PDF documents.
 50:  * @package com.tecnick.tcpdf
 51:  * @author Nicola Asuni - info@tecnick.com
 52:  */
 53: class TCPDFEX extends TCPDF
 54: {
 55: 
 56:     /**
 57:      * URL link that points back to TCExam website.
 58:      * @protected
 59:      */
 60:     protected $tcexam_backlink = '';
 61: 
 62:     /**
 63:      *
 64:      * @protected
 65:      */
 66:     protected $tce_cell_height_ratio;
 67: 
 68:     /**
 69:      *
 70:      * @protected
 71:      */
 72:     protected $tce_page_width;
 73: 
 74:     /**
 75:      *
 76:      * @protected
 77:      */
 78:     protected $tce_data_cell_height;
 79: 
 80:     /**
 81:      *
 82:      * @protected
 83:      */
 84:     protected $tce_main_cell_height;
 85: 
 86:     /**
 87:      * This is the class constructor.
 88:      * It allows to set up the page format, the orientation and the measure unit used in all the methods (except for the font sizes).
 89:      * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul><li>P or Portrait (default)</li><li>L or Landscape</li><li>'' (empty string) for automatic orientation</li></ul>
 90:      * @param $unit (string) User measure unit. Possible values are:<ul><li>pt: point</li><li>mm: millimeter (default)</li><li>cm: centimeter</li><li>in: inch</li></ul><br />A point equals 1/72 of inch, that is to say about 0.35 mm (an inch being 2.54 cm). This is a very common unit in typography; font sizes are expressed in that unit.
 91:      * @param $format (mixed) The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() or an array of parameters specified at setPageFormat().
 92:      * @param $unicode (boolean) TRUE means that the input text is unicode (default = true)
 93:      * @param $encoding (string) Charset encoding; default is UTF-8.
 94:      * @param $diskcache (boolean) If TRUE reduce the RAM memory usage by caching temporary data on filesystem (slower).
 95:      * @param $pdfa (boolean) If TRUE set the document to PDF/A mode.
 96:      * @public
 97:      * @see getPageSizeFromFormat(), setPageFormat()
 98:      */
 99:     public function __construct($orientation = 'P', $unit = 'mm', $format = 'A4', $unicode = true, $encoding = 'UTF-8', $diskcache = false, $pdfa = false)
100:     {
101:         parent::__construct();
102:         // calculate some sizes
103:         $this->tce_cell_height_ratio = (K_CELL_HEIGHT_RATIO + 0.1);
104:         $this->tce_page_width = ($this->getPageWidth() - PDF_MARGIN_LEFT - PDF_MARGIN_RIGHT);
105:         $this->tce_data_cell_height = round(($this->tce_cell_height_ratio * PDF_FONT_SIZE_DATA) / $this->getScaleFactor(), 2);
106:         $this->tce_main_cell_height = round(($this->tce_cell_height_ratio * PDF_FONT_SIZE_MAIN) / $this->getScaleFactor(), 2);
107:     }
108: 
109:     /**
110:      * Set an URL link that points back to TCExam website (this will be printed as QR-Code on header).
111:      * @param $link URL link.
112:      * @public
113:      */
114:     public function setTCExamBackLink($link)
115:     {
116:         $this->tcexam_backlink = $link;
117:     }
118: 
119:     /**
120:      * This method is used to render the page header and overrides the original Header() method on TCPDF.
121:      * @public
122:      */
123:     public function Header()
124:     {
125:         if ($this->header_xobjid === false) {
126:             // start a new XObject Template
127:             $this->header_xobjid = $this->startTemplate($this->w, $this->tMargin);
128:             $headerfont = $this->getHeaderFont();
129:             $headerdata = $this->getHeaderData();
130:             $this->y = $this->header_margin;
131:             if ($this->rtl) {
132:                 $this->x = $this->w - $this->original_rMargin;
133:             } else {
134:                 $this->x = $this->original_lMargin;
135:             }
136:             if (($headerdata['logo']) and ($headerdata['logo'] != K_BLANK_IMAGE)) {
137:                 $imgtype = TCPDF_IMAGES::getImageFileType(K_PATH_IMAGES.$headerdata['logo']);
138:                 if (($imgtype == 'eps') or ($imgtype == 'ai')) {
139:                     $this->ImageEps(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
140:                 } elseif ($imgtype == 'svg') {
141:                     $this->ImageSVG(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
142:                 } else {
143:                     $this->Image(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
144:                 }
145:                 $imgy = $this->getImageRBY();
146:             } else {
147:                 $imgy = $this->y;
148:             }
149:             $cell_height = round(($this->cell_height_ratio * $headerfont[2]) / $this->k, 2);
150:             // set starting margin for text data cell
151:             if ($this->getRTL()) {
152:                 $header_x = $this->original_rMargin + ($headerdata['logo_width'] * 1.1);
153:             } else {
154:                 $header_x = $this->original_lMargin + ($headerdata['logo_width'] * 1.1);
155:             }
156:             $cw = $this->w - $this->original_lMargin - $this->original_rMargin - ($headerdata['logo_width'] * 1.1);
157:             $this->SetTextColor(0, 0, 0);
158:             // header title
159:             $this->SetFont($headerfont[0], 'B', $headerfont[2] + 1);
160:             $this->SetX($header_x);
161:             $this->Cell($cw, $cell_height, $headerdata['title'], 0, 1, '', 0, '', 0);
162:             // header string
163:             $this->SetFont($headerfont[0], $headerfont[1], $headerfont[2]);
164:             $this->SetX($header_x);
165:             $this->MultiCell($cw, $cell_height, $headerdata['string'], 0, '', 0, 1, '', '', true, 0, false);
166:             // print an ending header line
167:             $this->SetLineStyle(array('width' => 0.85 / $this->k, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
168:             if (!empty($this->tcexam_backlink)) {
169:                 // set style for barcode
170:                 $style = array(
171:                     'border' => false,
172:                     'vpadding' => 0,
173:                     'hpadding' => 0,
174:                     'fgcolor' => array(0,0,0),
175:                     'bgcolor' => false,
176:                     'module_width' => 1,
177:                     'module_height' => 1
178:                 );
179:                 // QRCODE
180:                 $w = (PDF_MARGIN_TOP - PDF_MARGIN_HEADER - (5.7 / $this->k));
181:                 $y = (PDF_MARGIN_HEADER);
182:                 if ($this->rtl) {
183:                     $x = PDF_MARGIN_LEFT + $w;
184:                 } else {
185:                     $x = $this->w - PDF_MARGIN_RIGHT - $w;
186:                 }
187:                 // write QR-Code on header
188:                 $this->write2DBarcode($this->tcexam_backlink, 'QRCODE,L', $x, $y, $w, $w, $style, 'N');
189:             }
190:             $this->SetY((2.835 / $this->k) + max($imgy, $this->y));
191:             if ($this->rtl) {
192:                 $this->SetX($this->original_rMargin);
193:             } else {
194:                 $this->SetX($this->original_lMargin);
195:             }
196:             $this->Cell(($this->w - $this->original_lMargin - $this->original_rMargin), 0, '', 'T', 0, 'C');
197:             $this->endTemplate();
198:         }
199:         // print header template
200:         $x = 0;
201:         $dx = 0;
202:         if ($this->booklet and (($this->page % 2) == 0)) {
203:             // adjust margins for booklet mode
204:             $dx = ($this->original_lMargin - $this->original_rMargin);
205:         }
206:         if ($this->rtl) {
207:             $x = $this->w + $dx;
208:         } else {
209:             $x = 0 + $dx;
210:         }
211:         $this->printTemplate($this->header_xobjid, $x, 0, 0, 0, '', '', false);
212:     }
213: 
214:     /**
215:      * This method is used to render the page footer and overrides the original Footer() method on TCPDF.
216:      * @public
217:      */
218:     public function Footer()
219:     {
220:         parent::Footer();
221:     }
222: 
223:     /**
224:      * Print question stats.
225:      * @param $stats (array) data to print
226:      * @param $display_mode (int) display mode: 0 = disabled; 1 = minimum; 2 = module; 3 = subject; 4 = question; 5 = answer.
227:      * @public
228:      */
229:     public function printQuestionStats($stats, $display_mode = 2)
230:     {
231: 
232:         if ($display_mode < 2) {
233:             return;
234:         }
235:         
236:         require_once('../config/tce_config.php');
237:         require_once('../../shared/code/tce_functions_tcecode.php');
238:         global $l;
239: 
240:         $tce_data_cell_width = round($this->tce_page_width / 9, 2);
241:         $tce_data_cell_width_third = round($tce_data_cell_width / 3, 2);
242:         $tce_data_cell_width_half = round($tce_data_cell_width / 2, 2);
243: 
244:         if (empty($stats)) {
245:             return;
246:         }
247: 
248:         $numberfont = 'courier';
249:         $fontdatasize = PDF_FONT_SIZE_DATA - 1;
250: 
251:         $this->SetFillColor(204, 204, 204);
252:         $this->SetLineWidth(0.1);
253:         $this->SetDrawColor(0, 0, 0);
254: 
255:         $this->SetFont(PDF_FONT_NAME_DATA, 'B', (PDF_FONT_SIZE_DATA + 1));
256: 
257:         $title = $l['w_statistics'].' ['.$l['w_all'].' + '.$l['w_module'].'';
258:         if ($display_mode > 2) {
259:             $title .= ' + '.$l['w_subject'].'';
260:             if ($display_mode > 3) {
261:                 $title .= ' + '.$l['w_question'].'';
262:                 if ($display_mode > 4) {
263:                     $title .= ' + '.$l['w_answer'].'';
264:                 }
265:             }
266:         }
267:         $title .= ']';
268:         $this->Cell(0, $this->tce_data_cell_height, $title, 'T', 1, 'C', 0);
269:         $this->Ln(1);
270: 
271:         $this->SetFont(PDF_FONT_NAME_DATA, 'B', PDF_FONT_SIZE_DATA);
272: 
273:         // print table headings
274:         $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, '#', 1, 0, 'C', 1);
275:         $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $l['w_recurrence'], 1, 0, 'C', true, '', 1);
276:         $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $l['w_score'], 1, 0, 'C', true, '', 1);
277:         $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $l['w_answer_time'], 1, 0, 'C', true, '', 1);
278:         $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $l['w_answers_right_th'], 1, 0, 'C', true, '', 1);
279:         $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $l['w_answers_wrong_th'], 1, 0, 'C', true, '', 1);
280:         $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $l['w_questions_unanswered_th'], 1, 0, 'C', true, '', 1);
281:         $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $l['w_questions_undisplayed_th'], 1, 0, 'C', true, '', 1);
282:         $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $l['w_questions_unrated_th'], 1, 1, 'C', true, '', 1);
283:         $this->Ln(2);
284: 
285:         // print table rows
286:         $this->SetFillColor(255, 238, 238);
287:         $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $l['w_all'], 1, 0, 'L', true, '', 1);
288:         $this->SetFont($numberfont, 'B', $fontdatasize);
289:         $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $stats['recurrence'].' '.F_formatPdfPercentage($stats['recurrence_perc'], false), 1, 0, 'R', true);
290:         $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, number_format($stats['average_score'], 3, '.', '').' '.F_formatPdfPercentage($stats['average_score_perc'], false), 1, 0, 'R', true);
291:         $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, date('i:s', $stats['average_time']), 1, 0, 'R', true);
292:         $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $stats['right'].' '.F_formatPdfPercentage($stats['right_perc'], false), 1, 0, 'R', true);
293:         $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $stats['wrong'].' '.F_formatPdfPercentage($stats['wrong_perc'], false), 1, 0, 'R', true);
294:         $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $stats['unanswered'].' '.F_formatPdfPercentage($stats['unanswered_perc'], false), 1, 0, 'R', true);
295:         $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $stats['undisplayed'].' '.F_formatPdfPercentage($stats['undisplayed_perc'], false), 1, 0, 'R', true);
296:         $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $stats['unrated'].' '.F_formatPdfPercentage($stats['unrated_perc'], false), 1, 1, 'R', true);
297: 
298:         $this->Ln(1);
299: 
300:         $num_module = 0;
301:         foreach ($stats['module'] as $module) {
302:             $num_module++;
303: 
304:             $this->SetFillColor(221, 238, 255);
305:             $this->SetFont($numberfont, 'B', $fontdatasize);
306:             $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, 'M'.$num_module, 1, 0, 'L', true, '', 1);
307:             $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $module['recurrence'].' '.F_formatPdfPercentage($module['recurrence_perc'], false), 1, 0, 'R', true);
308:             $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, number_format($module['average_score'], 3, '.', '').' '.F_formatPdfPercentage($module['average_score_perc'], false), 1, 0, 'R', true);
309:             $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, date('i:s', $module['average_time']), 1, 0, 'R', true);
310:             $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $module['right'].' '.F_formatPdfPercentage($module['right_perc'], false), 1, 0, 'R', true);
311:             $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $module['wrong'].' '.F_formatPdfPercentage($module['wrong_perc'], false), 1, 0, 'R', true);
312:             $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $module['unanswered'].' '.F_formatPdfPercentage($module['unanswered_perc'], false), 1, 0, 'R', true);
313:             $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $module['undisplayed'].' '.F_formatPdfPercentage($module['undisplayed_perc'], false), 1, 0, 'R', true);
314:             $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $module['unrated'].' '.F_formatPdfPercentage($module['unrated_perc'], false), 1, 1, 'R', true);
315:             $this->SetFont(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA);
316:             $this->writeHTMLCell(0, $this->tce_data_cell_height, (PDF_MARGIN_LEFT + (2 * $tce_data_cell_width_third)), $this->GetY(), F_decode_tcecode($module['name']), 1, 1);
317: 
318:             if ($display_mode > 2) {
319:                 $num_subject = 0;
320:                 foreach ($module['subject'] as $subject) {
321:                     $num_subject++;
322: 
323:                     $this->SetFillColor(221, 255, 221);
324:                     $this->SetFont($numberfont, 'B', $fontdatasize);
325:                     $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, 'M'.$num_module.'S'.$num_subject, 1, 0, 'L', true, '', 1);
326:                     $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $subject['recurrence'].' '.F_formatPdfPercentage($subject['recurrence_perc'], false), 1, 0, 'R', true);
327:                     $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, number_format($subject['average_score'], 3, '.', '').' '.F_formatPdfPercentage($subject['average_score_perc'], false), 1, 0, 'R', true);
328:                     $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, date('i:s', $subject['average_time']), 1, 0, 'R', true);
329:                     $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $subject['right'].' '.F_formatPdfPercentage($subject['right_perc'], false), 1, 0, 'R', true);
330:                     $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $subject['wrong'].' '.F_formatPdfPercentage($subject['wrong_perc'], false), 1, 0, 'R', true);
331:                     $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $subject['unanswered'].' '.F_formatPdfPercentage($subject['unanswered_perc'], false), 1, 0, 'R', true);
332:                     $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $subject['undisplayed'].' '.F_formatPdfPercentage($subject['undisplayed_perc'], false), 1, 0, 'R', true);
333:                     $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $subject['unrated'].' '.F_formatPdfPercentage($subject['unrated_perc'], false), 1, 1, 'R', true);
334:                     $this->SetFont(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA);
335:                     $this->writeHTMLCell(0, $this->tce_data_cell_height, (PDF_MARGIN_LEFT + (2 * $tce_data_cell_width_third)), $this->GetY(), F_decode_tcecode($subject['name']), 1, 1);
336: 
337:                     if ($display_mode > 3) {
338:                         $num_question = 0;
339:                         foreach ($subject['question'] as $question) {
340:                             $num_question++;
341: 
342:                             $this->SetFillColor(255, 250, 205);
343:                             $this->SetFont($numberfont, 'B', $fontdatasize);
344:                             $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, 'M'.$num_module.'S'.$num_subject.'Q'.$num_question, 1, 0, 'L', true, '', 1);
345:                             $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $question['recurrence'].' '.F_formatPdfPercentage($question['recurrence_perc'], false), 1, 0, 'R', true);
346:                             $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, number_format($question['average_score'], 3, '.', '').' '.F_formatPdfPercentage($question['average_score_perc'], false), 1, 0, 'R', true);
347:                             $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, date('i:s', $question['average_time']), 1, 0, 'R', true);
348:                             $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $question['right'].' '.F_formatPdfPercentage($question['right_perc'], false), 1, 0, 'R', true);
349:                             $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $question['wrong'].' '.F_formatPdfPercentage($question['wrong_perc'], false), 1, 0, 'R', true);
350:                             $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $question['unanswered'].' '.F_formatPdfPercentage($question['unanswered_perc'], false), 1, 0, 'R', true);
351:                             $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $question['undisplayed'].' '.F_formatPdfPercentage($question['undisplayed_perc'], false), 1, 0, 'R', true);
352:                             $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $question['unrated'].' '.F_formatPdfPercentage($question['unrated_perc'], false), 1, 1, 'R', true);
353:                             $this->SetFont(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA);
354:                             $this->writeHTMLCell(0, $this->tce_data_cell_height, (PDF_MARGIN_LEFT + (2 * $tce_data_cell_width_third)), $this->GetY(), F_decode_tcecode($question['description']), 1, 1);
355: 
356:                             if ($display_mode > 4) {
357:                                 $num_answer = 0;
358:                                 foreach ($question['answer'] as $answer) {
359:                                     $num_answer++;
360: 
361:                                     $this->SetFont($numberfont, 'B', $fontdatasize);
362:                                     $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, 'M'.$num_module.'S'.$num_subject.'Q'.$num_question.'A'.$num_answer, 1, 0, 'L', 0, '', 1);
363:                                     $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $answer['recurrence'].' '.F_formatPdfPercentage($answer['recurrence_perc'], false), 1, 0, 'R', 0);
364:                                     $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, '', 1, 0, 'R', 0);
365:                                     $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, '', 1, 0, 'R', 0);
366:                                     $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $answer['right'].' '.F_formatPdfPercentage($answer['right_perc'], false), 1, 0, 'R', 0);
367:                                     $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $answer['wrong'].' '.F_formatPdfPercentage($answer['wrong_perc'], false), 1, 0, 'R', 0);
368:                                     $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $answer['unanswered'].' '.F_formatPdfPercentage($answer['unanswered_perc'], false), 1, 0, 'R', 0);
369:                                     $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, '', 1, 0, 'R', 0);
370:                                     $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, '', 1, 1, 'R', 0);
371:                                     $this->SetFont(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA);
372:                                     $this->writeHTMLCell(0, $this->tce_data_cell_height, (PDF_MARGIN_LEFT + (2 * $tce_data_cell_width_third)), $this->GetY(), F_decode_tcecode($answer['description']), 1, 1);
373:                                 } // end for answer
374:                             }
375:                         } // end for question
376:                     }
377:                 } // end for subject
378:             }
379:         } // end for module
380:     }
381: 
382:     /**
383:      * Print SVG graph
384:      * @param $svgdata (string) String containing SVG data to print.
385:      * @public
386:      */
387:     public function printSVGStatsGraph($svgdata)
388:     {
389:         require_once('../config/tce_config.php');
390:         require_once('../../shared/code/tce_functions_svg_graph.php');
391:         global $l;
392:         // display svg graph
393:         if (preg_match_all('/[x]/', $svgdata, $match) > 1) {
394:             $this->SetFont(PDF_FONT_NAME_DATA, 'B', PDF_FONT_SIZE_DATA);
395:             // legend
396:             $legend = '<span style="background-color:#ff0000;color:#ffffff;">&nbsp;'.$l['w_score'].'&nbsp;</span> <span style="background-color:#0000ff;color:#ffffff;">&nbsp;'.$l['w_answers_right'].'&nbsp;</span> / <span style="background-color:#dddddd;color:#000000;">&nbsp;'.$l['w_tests'].'&nbsp;</span></div>';
397:             $this->writeHTML($legend, true, false, true, false, 'C');
398:             $this->SetFont(PDF_FONT_NAME_DATA, '', 6);
399:             $w = $this->tce_page_width * $this->imgscale * $this->k;
400:             $h = round($this->tce_page_width * 9 / 16);
401:             $svg = F_getSVGGraphCode(substr($svgdata, 1), $w, $h);
402:             if (isset($svg[0]) and ($svg[0] == '<')) {
403:                 $this->ImageSVG('@'.$svg, '', '', $this->tce_page_width, 0, '', 'N', 'C', 0, false);
404:             }
405:         }
406:     }
407: 
408:     /**
409:     * Print test stats table
410:     * @param $data (array) Array containing test statistics.
411:     * @param $pubmode (boolean) If true filter the results for the public interface.
412:     * @param $stats (int) 2 = full stats; 1 = user stats; 0 = disabled stats;
413:     */
414:     public function printTestResultStat($data, $pubmode = false, $stats = 2)
415:     {
416:         require_once('../config/tce_config.php');
417:         global $l;
418:         // add a bookmark
419:         $this->Bookmark($l['w_results']);
420:         if ($l['a_meta_dir'] == 'rtl') {
421:             $tdalignr = 'L';
422:             $tdalign = 'R';
423:         } else {
424:             $tdalignr = 'R';
425:             $tdalign = 'L';
426:         }
427: 
428:         if ($pubmode) {
429:             $num_column = 11;
430:         } else {
431:             $num_column = 14;
432:         }
433:         if ($stats < 1) {
434:             $num_column -= 5;
435:         }
436:         $tce_data_cell_width = round($this->tce_page_width / $num_column, 2);
437:         $tce_data_cell_width_third = round($tce_data_cell_width / 3, 2);
438:         $tce_data_cell_width_half = round($tce_data_cell_width / 2, 2);
439: 
440:         $numberfont = 'courier';
441:         $fontdatasize = PDF_FONT_SIZE_DATA - 1;
442: 
443:         $this->SetFillColor(204, 204, 204);
444:         $this->SetLineWidth(0.1);
445:         $this->SetDrawColor(0, 0, 0);
446: 
447:         $this->SetFont(PDF_FONT_NAME_DATA, 'B', PDF_FONT_SIZE_DATA);
448: 
449: 
450:         // print table headings
451:         $this->Cell($tce_data_cell_width_third, $this->tce_data_cell_height, '#', 1, 0, 'C', 1);
452:         $this->Cell(5 * $tce_data_cell_width_third, $this->tce_data_cell_height, $l['w_time_begin'], 1, 0, 'C', true, '', 1);
453:         $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $l['w_time'], 1, 0, 'C', true, '', 1);
454:         $this->Cell(4 * $tce_data_cell_width_third, $this->tce_data_cell_height, $l['w_test'], 1, 0, 'C', true, '', 1);
455:         if (!$pubmode) {
456:             $this->Cell((3 * $tce_data_cell_width), $this->tce_data_cell_height, $l['w_user'].' - '.$l['w_lastname'].', '.$l['w_firstname'], 1, 0, 'C', true, '', 1);
457:         }
458:         $this->Cell(5 * $tce_data_cell_width_third, $this->tce_data_cell_height, $l['w_score'], 1, 0, 'C', true, '', 1);
459:         if ($stats > 0) {
460:             $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $l['w_answers_right_th'], 1, 0, 'C', true, '', 1);
461:             $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $l['w_answers_wrong_th'], 1, 0, 'C', true, '', 1);
462:             $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $l['w_questions_unanswered_th'], 1, 0, 'C', true, '', 1);
463:             $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $l['w_questions_undisplayed_th'], 1, 0, 'C', true, '', 1);
464:             $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $l['w_questions_unrated_th'], 1, 0, 'C', true, '', 1);
465:         }
466:         $this->Ln();
467:         $this->Ln(2);
468: 
469:         $this->SetFont($numberfont, '', $fontdatasize);
470: 
471:         foreach ($data['testuser'] as $tu) {
472:             $this->Cell($tce_data_cell_width_third, $this->tce_data_cell_height, $tu['num'], 1, 0, 'R', 0);
473:             $this->Cell(5 * $tce_data_cell_width_third, $this->tce_data_cell_height, $tu['testuser_creation_time'], 1, 0, 'R', 0, '', 1);
474:             $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $tu['time_diff'], 1, 0, 'R', 0, '', 1);
475:             $this->SetFont(PDF_FONT_NAME_DATA, '', $fontdatasize);
476:             $this->Cell(4 * $tce_data_cell_width_third, $this->tce_data_cell_height, $tu['test']['test_name'], 1, 0, $tdalign, 0, '', 1);
477:             if (!$pubmode) {
478:                 $this->Cell((3 * $tce_data_cell_width), $this->tce_data_cell_height, $tu['user_name'].' - '.$tu['user_lastname'].', '.$tu['user_firstname'], 1, 0, $tdalign, 0, '', 1);
479:             }
480:             $this->SetFont($numberfont, '', $fontdatasize);
481:             if ($tu['passmsg']) {
482:                 $this->SetFillColor(221, 255, 221);
483:                 $this->SetFont($numberfont, 'B', $fontdatasize);
484:             } else {
485:                 $this->SetFillColor(255, 238, 238);
486:             }
487:             $this->Cell(5 * $tce_data_cell_width_third, $this->tce_data_cell_height, $tu['total_score'].' '.F_formatPdfPercentage($tu['total_score_perc'], false), 1, 0, 'R', true, '', 1);
488:             if ($stats > 0) {
489:                 $this->SetFont($numberfont, '', $fontdatasize);
490:                 $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $tu['right'].' '.F_formatPdfPercentage($tu['right_perc'], false), 1, 0, 'R', 0, '', 1);
491:                 $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $tu['wrong'].' '.F_formatPdfPercentage($tu['wrong_perc'], false), 1, 0, 'R', 0, '', 1);
492:                 $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $tu['unanswered'].' '.F_formatPdfPercentage($tu['unanswered_perc'], false), 1, 0, 'R', 0, '', 1);
493:                 $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $tu['undisplayed'].' '.F_formatPdfPercentage($tu['undisplayed_perc'], false), 1, 0, 'R', 0, '', 1);
494:                 $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $tu['unrated'].' '.F_formatPdfPercentage($tu['unrated_perc'], false), 1, 0, 'R', 0, '', 1);
495:             }
496:             $this->Ln();
497:         }
498:         $this->SetFont(PDF_FONT_NAME_DATA, 'B', $fontdatasize);
499:         if ($data['passed_perc'] > 50) {
500:             $this->SetFillColor(221, 255, 221);
501:         } else {
502:             $this->SetFillColor(255, 238, 238);
503:         }
504:         $this->Cell(0, $this->tce_data_cell_height, $l['w_passed'].': '.$data['passed'].' '.F_formatPdfPercentage($data['passed_perc'], false), 1, 1, 'L', true, '', 1);
505:         // print statistics
506:         $printstat = array('mean', 'median', 'mode', 'standard_deviation', 'skewness', 'kurtosi');
507:         $noperc = array('skewness', 'kurtosi');
508:         foreach ($data['statistics'] as $row => $col) {
509:             if (in_array($row, $printstat)) {
510:                 $this->SetFont(PDF_FONT_NAME_DATA, 'B', $fontdatasize);
511:                 if ($pubmode) {
512:                     $this->Cell((4 * $tce_data_cell_width) + $tce_data_cell_width_third, $this->tce_data_cell_height, $l['w_'.$row], 1, 0, $tdalignr, 0, '', 1);
513:                 } else {
514:                     $this->Cell((7 * $tce_data_cell_width) + $tce_data_cell_width_third, $this->tce_data_cell_height, $l['w_'.$row], 1, 0, $tdalignr, 0, '', 1);
515:                 }
516:                 $this->SetFont($numberfont, '', $fontdatasize);
517:                 if (in_array($row, $noperc)) {
518:                     $this->Cell(5 * $tce_data_cell_width_third, $this->tce_data_cell_height, F_formatFloat($col['score_perc']), 1, 0, 'R', 0, '', 1);
519:                     if ($stats > 0) {
520:                         $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, F_formatFloat($col['right_perc']), 1, 0, 'R', 0, '', 1);
521:                         $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, F_formatFloat($col['wrong_perc']), 1, 0, 'R', 0, '', 1);
522:                         $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, F_formatFloat($col['unanswered_perc']), 1, 0, 'R', 0, '', 1);
523:                         $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, F_formatFloat($col['undisplayed_perc']), 1, 0, 'R', 0, '', 1);
524:                         $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, F_formatFloat($col['unrated_perc']), 1, 0, 'R', 0, '', 1);
525:                     }
526:                     $this->Ln();
527:                 } else {
528:                     $this->Cell(5 * $tce_data_cell_width_third, $this->tce_data_cell_height, round($col['score_perc']).'%', 1, 0, 'R', 0, '', 1);
529:                     if ($stats > 0) {
530:                         $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, round($col['right_perc']).'%', 1, 0, 'R', 0, '', 1);
531:                         $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, round($col['wrong_perc']).'%', 1, 0, 'R', 0, '', 1);
532:                         $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, round($col['unanswered_perc']).'%', 1, 0, 'R', 0, '', 1);
533:                         $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, round($col['undisplayed_perc']).'%', 1, 0, 'R', 0, '', 1);
534:                         $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, round($col['unrated_perc']).'%', 1, 0, 'R', 0, '', 1);
535:                     }
536:                     $this->Ln();
537:                 }
538:             }
539:         }
540:     }
541: 
542:     /**
543:     * Print testuser data
544:     * @param $data (array) Array containing test statistics.
545:     * @param $onlytext (boolean) If true print only text questions.
546:     */
547:     function printTestUserInfo($data, $onlytext = false)
548:     {
549:         require_once('../config/tce_config.php');
550:         global $l;
551: 
552:         $this->SetFillColor(204, 204, 204);
553:         $this->SetLineWidth(0.1);
554:         $this->SetDrawColor(0, 0, 0);
555: 
556:         if ($l['a_meta_dir'] == 'rtl') {
557:             $dirlabel = 'L';
558:             $dirvalue = 'R';
559:         } else {
560:             $dirlabel = 'R';
561:             $dirvalue = 'L';
562:         }
563: 
564:         // add a bookmark
565:         $this->Bookmark($data['user_lastname'].' '.$data['user_firstname'].' ('.$data['user_name'].'), '.$data['total_score'].' '.F_formatPdfPercentage($data['total_score_perc'], false), 0, 0);
566: 
567:         // --- display test info ---
568: 
569:         $info_cell_width = round($this->tce_page_width / 4, 2);
570: 
571:         $boxStartY = $this->GetY(); // store current Y position
572: 
573:         // test name
574:         $this->SetFont(PDF_FONT_NAME_DATA, 'B', PDF_FONT_SIZE_DATA * HEAD_MAGNIFICATION);
575:         $this->Cell($this->tce_page_width, $this->tce_data_cell_height * HEAD_MAGNIFICATION, $l['w_test'].': '.$data['test']['test_name'], 1, 1, '', 1);
576: 
577:         $this->SetFont(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA);
578: 
579:         $infoStartY = $this->GetY() + 2; // store current Y position
580:         $this->SetY($infoStartY);
581: 
582:         $column_names_width = round($info_cell_width * 0.75, 2);
583: 
584:         $this->Cell($column_names_width, $this->tce_data_cell_height, $l['w_lastname'].': ', 0, 0, $dirlabel, 0, '', 1);
585:         $this->Cell($info_cell_width, $this->tce_data_cell_height, $data['user_lastname'], 0, 1, $dirvalue, 0, '', 1);
586: 
587:         $this->Cell($column_names_width, $this->tce_data_cell_height, $l['w_firstname'].': ', 0, 0, $dirlabel, 0, '', 1);
588:         $this->Cell($info_cell_width, $this->tce_data_cell_height, $data['user_firstname'], 0, 1, $dirvalue, 0, '', 1);
589: 
590:         $this->Cell($column_names_width, $this->tce_data_cell_height, $l['w_user'].': ', 0, 0, $dirlabel, 0, '', 1);
591:         $this->Cell($info_cell_width, $this->tce_data_cell_height, $data['user_name'], 0, 1, $dirvalue, 0, '', 1);
592: 
593:         // test start time
594:         $this->Cell($column_names_width, $this->tce_data_cell_height, $l['w_time_begin'].': ', 0, 0, $dirlabel, 0, '', 1);
595:         $this->Cell($info_cell_width, $this->tce_data_cell_height, $data['test']['user_test_start_time'], 0, 1, $dirvalue, 0, '', 1);
596: 
597:         // test end time
598:         $this->Cell($column_names_width, $this->tce_data_cell_height, $l['w_time_end'].': ', 0, 0, $dirlabel, 0, '', 1);
599:         $this->Cell($info_cell_width, $this->tce_data_cell_height, $data['test']['user_test_end_time'], 0, 1, $dirvalue, 0, '', 1);
600: 
601:         // test duration
602:         //$this->Cell($column_names_width, $this->tce_data_cell_height, $l['w_test_time'].' ['.$l['w_minutes'].']: ', 0, 0, $dirlabel, 0, '', 1);
603:         //$this->Cell($info_cell_width, $this->tce_data_cell_height, $data['test']['test_duration_time'], 0, 1, $dirvalue, 0, '', 1);
604: 
605:         if (!isset($data['test']['user_test_end_time']) or ($data['test']['user_test_end_time'] <= 0) or (strtotime($data['test']['user_test_end_time']) < strtotime($data['test']['user_test_start_time']))) {
606:             $time_diff = $data['test']['test_duration_time'] * 60;
607:         } else {
608:             $time_diff = strtotime($data['test']['user_test_end_time']) - strtotime($data['test']['user_test_start_time']); //sec
609:         }
610:         $time_diff = gmdate('H:i:s', $time_diff);
611:         // elapsed time (time difference)
612:         $this->Cell($column_names_width, $this->tce_data_cell_height, $l['w_time'].': ', 0, 0, $dirlabel, 0);
613:         $this->Cell($info_cell_width, $this->tce_data_cell_height, $time_diff, 0, 1, $dirvalue, 0);
614: 
615:         //$this->Cell($column_names_width, $this->tce_data_cell_height, $l['w_ip_range'].': ', 0, 0, $dirlabel, 0, '', 1);
616:         //$this->Cell($info_cell_width, $this->tce_data_cell_height, $data['test']['test_ip_range'], 0, 1, $dirvalue, 0, '', 1);
617: 
618:         //$this->Cell($column_names_width, $this->tce_data_cell_height, $l['w_score_right'].': ', 0, 0, $dirlabel, 0, '', 1);
619:         //$this->Cell($info_cell_width, $this->tce_data_cell_height, $data['test']['test_score_right'], 0, 1, $dirvalue, 0, '', 1);
620: 
621:         //$this->Cell($column_names_width, $this->tce_data_cell_height, $l['w_score_wrong'].': ', 0, 0, $dirlabel, 0, '', 1);
622:         //$this->Cell($info_cell_width, $this->tce_data_cell_height, $data['test']['test_score_wrong'], 0, 1, $dirvalue, 0, '', 1);
623: 
624:         //$this->Cell($column_names_width, $this->tce_data_cell_height, $l['w_score_unanswered'].': ', 0, 0, $dirlabel, 0, '', 1);
625:         //$this->Cell($info_cell_width, $this->tce_data_cell_height, $data['test']['test_score_unanswered'], 0, 1, $dirvalue, 0, '', 1);
626: 
627:         // max score
628:         //$this->Cell($column_names_width, $this->tce_data_cell_height, $l['w_max_score'].': ', 0, 0, $dirlabel, 0, '', 1);
629:         //$this->Cell($info_cell_width, $this->tce_data_cell_height, $data['test']['test_max_score'], 0, 1, $dirvalue, 0, '', 1);
630: 
631:         $passmsg = '';
632:         if ($data['test']['test_score_threshold'] > 0) {
633:             $this->Cell($column_names_width, $this->tce_data_cell_height, $l['w_test_score_threshold'].': ', 0, 0, $dirlabel, 0, '', 1);
634:             $this->Cell($info_cell_width, $this->tce_data_cell_height, $data['test']['test_score_threshold'], 0, 1, $dirvalue, 0, '', 1);
635:             if ($data['total_score'] >= $data['test']['test_score_threshold']) {
636:                 $passmsg = ' - '.$l['w_passed'];
637:             } else {
638:                 $passmsg = ' - '.$l['w_not_passed'];
639:             }
640:         }
641: 
642:         $this->Cell($column_names_width, $this->tce_data_cell_height, $l['w_answers_right'].': ', 0, 0, $dirlabel, 0, '', 1);
643:         $this->Cell($info_cell_width, $this->tce_data_cell_height, $data['right'].' '.F_formatPdfPercentage($data['right_perc'], false), 0, 1, $dirvalue, 0, '', 1);
644: 
645:         $this->Cell($column_names_width, $this->tce_data_cell_height, $l['w_answers_wrong'].': ', 0, 0, $dirlabel, 0, '', 1);
646:         $this->Cell($info_cell_width, $this->tce_data_cell_height, $data['wrong'].' '.F_formatPdfPercentage($data['wrong_perc'], false), 0, 1, $dirvalue, 0, '', 1);
647: 
648:         $this->Cell($column_names_width, $this->tce_data_cell_height, $l['w_questions_unanswered'].': ', 0, 0, $dirlabel, 0, '', 1);
649:         $this->Cell($info_cell_width, $this->tce_data_cell_height, $data['unanswered'].' '.F_formatPdfPercentage($data['unanswered_perc'], false), 0, 1, $dirvalue, 0, '', 1);
650: 
651:         $this->Cell($column_names_width, $this->tce_data_cell_height, $l['w_questions_undisplayed'].': ', 0, 0, $dirlabel, 0, '', 1);
652:         $this->Cell($info_cell_width, $this->tce_data_cell_height, $data['undisplayed'].' '.F_formatPdfPercentage($data['undisplayed_perc'], false), 0, 1, $dirvalue, 0, '', 1);
653: 
654:         $this->SetFont(PDF_FONT_NAME_DATA, 'B', PDF_FONT_SIZE_DATA);
655:         $this->Cell($column_names_width, $this->tce_data_cell_height, $l['w_score'].': ', 0, 0, $dirlabel, 0, '', 1);
656:         $this->Cell($info_cell_width, $this->tce_data_cell_height, $data['total_score'].' / '.$data['test']['test_max_score'].' '.F_formatPdfPercentage($data['total_score_perc'], false).$passmsg, 0, 1, $dirvalue, 0, '', 1);
657: 
658:         $this->SetFont(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA);
659: 
660: 
661: 
662:         $boxEndY = $this->GetY();
663: 
664:         $this->SetFont(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA);
665: 
666:         // test description
667:         $this->writeHTMLCell(0, ($boxEndY - $infoStartY + 4), (PDF_MARGIN_LEFT + ($info_cell_width * 2)), $infoStartY - 2, $data['test']['test_description'], 1, 0);
668: 
669:         $boxEndY = max($boxEndY, $this->GetY());
670: 
671:         // print box around test info
672:         $this->SetY($boxStartY);
673:         $this->Cell($this->tce_page_width, ($boxEndY - $boxStartY + 2), '', 1, 1, 'C', 0, '', 1);
674:         $this->SetY($boxEndY - 1);
675:         // --- end test info ---
676: 
677:         // print user's comments
678:         if (!empty($data['test']['user_comment'])) {
679:             $this->Cell($this->tce_page_width, $this->tce_data_cell_height, '', 0, 1, '', 0);
680:             $this->writeHTMLCell($this->tce_page_width, $this->tce_data_cell_height, '', '', '<b>'.$l['w_comment'].'</b>:<br />'.$data['test']['user_comment'], 1, 1);
681:         }
682: 
683:         $this->Ln(4);
684: 
685:         $this->printUserTestDetails($data, $onlytext);
686:     }
687: 
688:     /**
689:     * print test details for the selected user
690:     * @param $data (array) Testuser data array.
691:     * @param $onlytext (boolean) If true print only text questions.
692:     */
693:     public function printUserTestDetails($data, $onlytext = false)
694:     {
695:         require_once('../config/tce_config.php');
696:         require_once('../../shared/code/tce_functions_test_stats.php');
697:         require_once('../../shared/code/tce_functions_tcecode.php');
698:         global $db, $l;
699:         $testuser_id = intval($data['id']);
700:         $qtype = array('S', 'M', 'T', 'O'); // question types
701: 
702:         $num_column = 7;
703:         $tce_data_cell_width = round($this->tce_page_width / $num_column, 2);
704:         $tce_data_cell_width_third = round($tce_data_cell_width / 3, 2);
705:         $tce_data_cell_width_half = round($tce_data_cell_width / 2, 2);
706: 
707:         $numberfont = 'courier';
708: 
709:         // display user questions
710:         $sql = 'SELECT *
711:             FROM '.K_TABLE_QUESTIONS.', '.K_TABLE_TESTS_LOGS.', '.K_TABLE_SUBJECTS.', '.K_TABLE_MODULES.'
712:             WHERE question_id=testlog_question_id
713:                 AND testlog_testuser_id='.$testuser_id.'
714:                 AND question_subject_id=subject_id
715:                 AND subject_module_id=module_id';
716:         if ($onlytext) {
717:             // display only TEXT questions
718:             $sql .= ' AND question_type=3';
719:         }
720:         $sql .= ' ORDER BY testlog_id';
721:         if ($r = F_db_query($sql, $db)) {
722:             $this->SetFont(PDF_FONT_NAME_DATA, 'B', PDF_FONT_SIZE_DATA);
723: 
724:             $this->Cell($tce_data_cell_width_third, $this->tce_data_cell_height, '#', 1, 0, 'C', 1);
725:             $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $l['w_score'], 1, 0, 'C', 1);
726:             $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $l['w_ip'], 1, 0, 'C', 1);
727:             $this->Cell($tce_data_cell_width + $tce_data_cell_width_third, $this->tce_data_cell_height, $l['w_start'].' ['.$l['w_time_hhmmss'].']', 1, 0, 'C', 1);
728:             $this->Cell($tce_data_cell_width + $tce_data_cell_width_third, $this->tce_data_cell_height, $l['w_end'].' ['.$l['w_time_hhmmss'].']', 1, 0, 'C', 1);
729:             $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $l['w_time'].' ['.$l['w_time_mmss'].']', 1, 0, 'C', 1);
730:             $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $l['w_reaction'].' [sec]', 1, 1, 'C', 1);
731:             $this->Ln($this->tce_data_cell_height);
732: 
733:             // print table rows
734: 
735:             $this->SetFont(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA);
736:             $itemcount = 1;
737: 
738:             while ($m = F_db_fetch_array($r)) {
739:                 $this->Cell($tce_data_cell_width_third, $this->tce_data_cell_height, $itemcount.' '.$qtype[($m['question_type']-1)], 1, 0, 'R', 0);
740:                 $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $m['testlog_score'], 1, 0, 'C', 0);
741:                 $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, getIpAsString($m['testlog_user_ip']), 1, 0, 'C', 0);
742:                 if (isset($m['testlog_display_time']) and (strlen($m['testlog_display_time']) > 0)) {
743:                     $display_time =  substr($m['testlog_display_time'], 11, 8);
744:                 } else {
745:                     $display_time =  '--:--:--';
746:                 }
747:                 if (isset($m['testlog_change_time']) and (strlen($m['testlog_change_time']) > 0)) {
748:                     $change_time = substr($m['testlog_change_time'], 11, 8);
749:                 } else {
750:                     $change_time = '--:--:--';
751:                 }
752:                 if (isset($m['testlog_display_time']) and isset($m['testlog_change_time'])) {
753:                     $diff_time = date('i:s', (strtotime($m['testlog_change_time']) - strtotime($m['testlog_display_time'])));
754:                 } else {
755:                     $diff_time = '--:--';
756:                 }
757:                 if (isset($m['testlog_reaction_time']) and (strlen($m['testlog_reaction_time']) > 0)) {
758:                     $reaction_time =  ($m['testlog_reaction_time'] / 1000);
759:                 } else {
760:                     $reaction_time =  '';
761:                 }
762:                 $this->Cell($tce_data_cell_width + $tce_data_cell_width_third, $this->tce_data_cell_height, $display_time, 1, 0, 'C', 0);
763:                 $this->Cell($tce_data_cell_width + $tce_data_cell_width_third, $this->tce_data_cell_height, $change_time, 1, 0, 'C', 0);
764:                 $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $diff_time, 1, 0, 'C', 0);
765:                 $this->Cell($tce_data_cell_width, $this->tce_data_cell_height, $reaction_time, 1, 1, 'C', 0);
766: 
767:                 $this->writeHTMLCell(0, $this->tce_data_cell_height, (PDF_MARGIN_LEFT + $tce_data_cell_width_third), $this->GetY(), F_decode_tcecode($m['question_description']), 1, 1);
768:                 if (K_ENABLE_QUESTION_EXPLANATION and !empty($m['question_explanation'])) {
769:                     $this->Cell($tce_data_cell_width_third, $this->tce_data_cell_height, '', 0, 0, 'C', 0);
770:                     $this->SetFont('', 'BIU');
771:                     $this->Cell(0, $this->tce_data_cell_height, $l['w_explanation'], 'LTR', 1, '', 0, '', 0);
772:                     $this->SetFont('', '');
773:                     $this->writeHTMLCell(0, $this->tce_data_cell_height, (PDF_MARGIN_LEFT + $tce_data_cell_width_third), $this->GetY(), F_decode_tcecode($m['question_explanation']), 'LRB', 1, '', '');
774:                 }
775: 
776:                 if ($m['question_type'] == 3) {
777:                     // free-text question - print user text answer
778:                     $this->writeHTMLCell(0, $this->tce_data_cell_height, (PDF_MARGIN_LEFT + (2 * $tce_data_cell_width_third)), $this->GetY(), F_decode_tcecode($m['testlog_answer_text']), 1, 1);
779:                 } else {
780:                     // display each answer option
781:                     $sqla = 'SELECT * FROM '.K_TABLE_LOG_ANSWER.', '.K_TABLE_ANSWERS.' WHERE logansw_answer_id=answer_id AND logansw_testlog_id='.$m['testlog_id'].' ORDER BY logansw_order';
782:                     if ($ra = F_db_query($sqla, $db)) {
783:                         $idx = 0; // count items
784:                         while ($ma = F_db_fetch_array($ra)) {
785:                             $posfill = 0;
786:                             $idx++;
787:                             $this->Cell($tce_data_cell_width_third, $this->tce_data_cell_height, '', 0, 0, 'C', 0);
788:                             if ($m['question_type'] == 4) {
789:                                 if ($ma['logansw_position'] > 0) {
790:                                     if ($ma['logansw_position'] == $ma['answer_position']) {
791:                                         $posfill = 1;
792:                                         $this->Cell($tce_data_cell_width_third, $this->tce_data_cell_height, $ma['logansw_position'], 1, 0, 'C', 1);
793:                                     } else {
794:                                         $this->Cell($tce_data_cell_width_third, $this->tce_data_cell_height, $ma['logansw_position'], 1, 0, 'C', 0);
795:                                     }
796:                                 } else {
797:                                     $this->Cell($tce_data_cell_width_third, $this->tce_data_cell_height, ' ', 1, 0, 'C', 0);
798:                                 }
799:                             } elseif ($ma['logansw_selected'] > 0) {
800:                                 // selected
801:                                 if (F_getBoolean($ma['answer_isright'])) {
802:                                     $this->Cell($tce_data_cell_width_third, $this->tce_data_cell_height, '+', 1, 0, 'C', 1);
803:                                 } else {
804:                                     $this->Cell($tce_data_cell_width_third, $this->tce_data_cell_height, '-', 1, 0, 'C', 1);
805:                                 }
806:                             } elseif ($m['question_type'] == 1) {
807:                                 // MCSA
808:                                 $this->Cell($tce_data_cell_width_third, $this->tce_data_cell_height, ' ', 1, 0, 'C', 0);
809:                             } else {
810:                                 if ($ma['logansw_selected'] == 0) {
811:                                     // unselected
812:                                     if (F_getBoolean($ma['answer_isright'])) {
813:                                         $this->Cell($tce_data_cell_width_third, $this->tce_data_cell_height, '-', 1, 0, 'C', 0);
814:                                     } else {
815:                                         $this->Cell($tce_data_cell_width_third, $this->tce_data_cell_height, '+', 1, 0, 'C', 0);
816:                                     }
817:                                 } else {
818:                                     // no answer
819:                                     $this->Cell($tce_data_cell_width_third, $this->tce_data_cell_height, ' ', 1, 0, 'C', 0);
820:                                 }
821:                             }
822:                             if ($m['question_type'] == 4) {
823:                                     $this->Cell($tce_data_cell_width_third, $this->tce_data_cell_height, $ma['answer_position'], 1, 0, 'C', $posfill);
824:                             } elseif (F_getBoolean($ma['answer_isright'])) {
825:                                 $this->Cell($tce_data_cell_width_third, $this->tce_data_cell_height, $idx, 1, 0, 'C', 1);
826:                             } else {
827:                                 $this->Cell($tce_data_cell_width_third, $this->tce_data_cell_height, $idx, 1, 0, 'C', 0);
828:                             }
829:                             $this->writeHTMLCell(0, $this->tce_data_cell_height, (PDF_MARGIN_LEFT + $tce_data_cell_width), $this->GetY(), F_decode_tcecode($ma['answer_description']), 'LRTB', 1);
830:                             if (K_ENABLE_ANSWER_EXPLANATION and !empty($ma['answer_explanation'])) {
831:                                 $this->Cell((3 * $tce_data_cell_width_third), $this->tce_data_cell_height, '', 0, 0, 'C', 0);
832:                                 $this->SetFont('', 'BIU');
833:                                 $this->Cell(0, $this->tce_data_cell_height, $l['w_explanation'], 'LTR', 1, '', 0, '', 0);
834:                                 $this->SetFont('', '');
835:                                 $this->writeHTMLCell(0, $this->tce_data_cell_height, (PDF_MARGIN_LEFT + (3 * $tce_data_cell_width_third)), $this->GetY(), F_decode_tcecode($ma['answer_explanation']), 'LRB', 1, '', '');
836:                             }
837:                         }
838:                     } else {
839:                         F_display_db_error();
840:                     }
841:                 } // end multiple answers
842:                 if (strlen($m['testlog_comment']) > 0) {
843:                     // teacher / supervisor comment
844:                     $this->SetTextColor(255, 0, 0);
845:                     $this->writeHTMLCell(0, $this->tce_data_cell_height, (PDF_MARGIN_LEFT + (2 * $tce_data_cell_width_third)), $this->GetY(), F_decode_tcecode($m['testlog_comment']), 'LRTB', 1);
846:                     $this->SetTextColor(0, 0, 0);
847:                 }
848:                 $this->Ln($this->tce_data_cell_height);
849:                 $itemcount++;
850:             }
851:         } else {
852:             F_display_db_error();
853:         }
854:         $stats = F_getTestStat($data['test']['test_id'], 0, $data['user_id'], 0, 0, $data['id']);
855:         $this->printQuestionStats($stats['qstats'], 1);
856:     }
857: } // END OF TCPDFEX CLASS
858: 
859: //============================================================+
860: // END OF FILE
861: //============================================================+
862: 
 

© 2004-2018 – Nicola Asuni - Tecnick.com - All rights reserved.
about - disclaimer - privacy