Пример #1
8
 *
 * ----------------------------------------------------------------------
 */
$t_display = $this->getVar('t_display');
$va_display_list = $this->getVar('display_list');
$vo_result = $this->getVar('result');
$vn_items_per_page = $this->getVar('current_items_per_page');
$vs_current_sort = $this->getVar('current_sort');
$vn_ratio_pixels_to_excel_height = 0.85;
$vn_ratio_pixels_to_excel_width = 0.135;
$va_supercol_a_to_z = range('A', 'Z');
$vs_supercol = '';
$va_a_to_z = range('A', 'Z');
$workbook = new PHPExcel();
// more accurate (but slower) automatic cell size calculation
PHPExcel_Shared_Font::setAutoSizeMethod(PHPExcel_Shared_Font::AUTOSIZE_METHOD_EXACT);
$o_sheet = $workbook->getActiveSheet();
// mise en forme
$columntitlestyle = array('font' => array('name' => 'Arial', 'size' => 12, 'bold' => true), 'alignment' => array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER, 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER, 'wrap' => true, 'shrinkToFit' => true), 'borders' => array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THICK)));
$cellstyle = array('font' => array('name' => 'Arial', 'size' => 11, 'bold' => false), 'alignment' => array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_LEFT, 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER, 'wrap' => true, 'shrinkToFit' => true), 'borders' => array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN)));
$o_sheet->getDefaultStyle()->applyFromArray($cellstyle);
$o_sheet->setTitle("CollectiveAccess");
$vn_line = 1;
$vs_column = reset($va_a_to_z);
// Column headers
$o_sheet->getRowDimension($vn_line)->setRowHeight(30);
foreach ($va_display_list as $vn_placement_id => $va_info) {
    if ($vs_column) {
        $o_sheet->setCellValue($vs_supercol . $vs_column . $vn_line, $va_info['display']);
        $o_sheet->getStyle($vs_supercol . $vs_column . $vn_line)->applyFromArray($columntitlestyle);
        if (!($vs_column = next($va_a_to_z))) {
Пример #2
1
 /**
  * Calculate widths for auto-size columns
  *
  * @param  boolean  $calculateMergeCells  Calculate merge cell width
  * @return PHPExcel_Worksheet;
  */
 public function calculateColumnWidths($calculateMergeCells = false)
 {
     $autoSizes = array();
     foreach ($this->getColumnDimensions() as $colDimension) {
         if ($colDimension->getAutoSize()) {
             $autoSizes[$colDimension->getColumnIndex()] = -1;
         }
     }
     foreach ($this->getCellCollection() as $cell) {
         if (isset($autoSizes[$cell->getColumn()])) {
             $cellValue = $cell->getCalculatedValue();
             foreach ($this->getMergeCells() as $cells) {
                 if ($cell->isInRange($cells) && !$calculateMergeCells) {
                     $cellValue = '';
                     // do not calculate merge cells
                 }
             }
             $autoSizes[$cell->getColumn()] = max((double) $autoSizes[$cell->getColumn()], (double) PHPExcel_Shared_Font::calculateColumnWidth($this->getParent()->getCellXfByIndex($cell->getXfIndex())->getFont()->getSize(), false, $cellValue, $this->getParent()->getCellXfByIndex($cell->getXfIndex())->getAlignment()->getTextRotation()));
         }
     }
     foreach ($autoSizes as $columnIndex => $width) {
         if ($width == -1) {
             $width = $this->getDefaultColumnDimension()->getWidth();
         }
         $this->getColumnDimension($columnIndex)->setWidth($width);
     }
     return $this;
 }
Пример #3
0
 /**
  * Calculate an (approximate) OpenXML column width, based on font size and text contained
  *
  * @param 	int		$fontSize			Font size (in pixels or points)
  * @param 	bool	$fontSizeInPixels	Is the font size specified in pixels (true) or in points (false) ?
  * @param 	string	$columnText			Text to calculate width
  * @param 	int		$rotation			Rotation angle
  * @return 	int		Column width
  */
 public static function calculateColumnWidth($fontSize = 9, $fontSizeInPixels = false, $columnText = '', $rotation = 0)
 {
     if (!$fontSizeInPixels) {
         // Translate points size to pixel size
         $fontSize = PHPExcel_Shared_Font::fontSizeToPixels($fontSize);
     }
     // If it is rich text, use rich text...
     if ($columnText instanceof PHPExcel_RichText) {
         $columnText = $columnText->getPlainText();
     }
     // Only measure the part before the first newline character
     if (strpos($columnText, "\r") !== false) {
         $columnText = substr($columnText, 0, strpos($columnText, "\r"));
     }
     if (strpos($columnText, "\n") !== false) {
         $columnText = substr($columnText, 0, strpos($columnText, "\n"));
     }
     // Calculate column width
     $columnWidth = (strlen($columnText) * $fontSize + 5) / $fontSize * 256 / 256;
     // Calculate approximate rotated column width
     if ($rotation !== 0) {
         if ($rotation == -165) {
             // stacked text
             $columnWidth = 4;
             // approximation
         } else {
             // rotated text
             $columnWidth = $columnWidth * cos(deg2rad($rotation)) + $fontSize * abs(sin(deg2rad($rotation))) / 5;
             // approximation
         }
     }
     // Return
     return round($columnWidth, 6);
 }
Пример #4
0
 public function __construct(LoggerInterface $logger, PHPExcelFactory $phpExcel)
 {
     parent::__construct($logger);
     $this->phpexcel = $phpExcel;
     $this->handle = $this->phpexcel->createPHPExcelObject();
     \PHPExcel_Shared_Font::setAutoSizeMethod(\PHPExcel_Shared_Font::AUTOSIZE_METHOD_EXACT);
 }
Пример #5
0
 /**
  * Calculate an (approximate) OpenXML column width, based on font size and text contained
  *
  * @param 	int		$fontSize			Font size (in pixels or points)
  * @param 	bool	$fontSizeInPixels	Is the font size specified in pixels (true) or in points (false) ?
  * @param 	string	$columnText			Text to calculate width
  * @return 	int		Column width
  */
 public static function calculateColumnWidth($fontSize = 9, $fontSizeInPixels = false, $columnText = '')
 {
     if (!$fontSizeInPixels) {
         // Translate points size to pixel size
         $fontSize = PHPExcel_Shared_Font::fontSizeToPixels($fontSize);
     }
     // If it is rich text, use rich text...
     if ($columnText instanceof PHPExcel_RichText) {
         $columnText = $columnText->getPlainText();
     }
     // Calculate column width
     return round((strlen($columnText) * $fontSize + 5) / $fontSize * 256 / 256, 6);
 }
Пример #6
0
 function create_excel($data = array(), $category)
 {
     $data['product_details'] = $data;
     $category_name = $this->products_model->get_category_details($category)->category_name;
     //activate worksheet number 1
     $this->excel->setActiveSheetIndex(0);
     //name the worksheet
     $this->excel->getActiveSheet()->setTitle($category_name . '-Product Catalog');
     //set cell A1 content with some text
     $this->excel->getActiveSheet()->setCellValue('A1', $category_name);
     $testArray = ['Product Name', 'Description', 'Price per Unit', 'Color'];
     PHPExcel_Shared_Font::setAutoSizeMethod(PHPExcel_Shared_Font::AUTOSIZE_METHOD_EXACT);
     foreach (range('A', 'D') as $columnID) {
         $this->excel->getActiveSheet()->getColumnDimension($columnID)->setAutoSize(true);
     }
     $this->excel->getActiveSheet()->getStyle("A2:D2")->getFont()->setBold(true);
     //change the font size
     $this->excel->getActiveSheet()->getStyle('A1')->getFont()->setSize(20);
     //make the font become bold
     $this->excel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
     //merge cell A1 until D1
     $this->excel->getActiveSheet()->mergeCells('A1:D1');
     // //set aligment to center for that merged cell (A1 to D1)
     $this->excel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
     $this->excel->getActiveSheet()->fromArray($testArray, NULL, 'A2');
     $product_details = array();
     foreach ($data['product_details'] as $key => $value) {
         $clean_data = array();
         foreach ($value as $k => $v) {
             if ($k == 'product_name' || $k == 'description' || $k == 'price' || $k == 'color') {
                 $clean_data[$k] = $v;
             }
         }
         $product_details[] = $clean_data;
     }
     $this->excel->getActiveSheet()->fromArray($product_details, NULL, 'A3');
     $filename = date("d-m-Y-h:i:s") . '.xls';
     //save our workbook as this file name
     header('Content-Type: application/vnd.ms-excel');
     //mime type
     header('Content-Disposition: attachment;filename="' . $filename . '"');
     //tell browser what's the file name
     header('Cache-Control: max-age=0');
     //no cache
     //save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
     //if you want to save it as .XLSX Excel 2007 format
     $objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');
     //force user to download the Excel file without writing it to server's HD
     $objWriter->save('php://output');
 }
Пример #7
0
 /**
  * Calculate an (approximate) OpenXML column width, based on font size and text contained
  *
  * @param 	int		$fontSize			Font size (in pixels or points)
  * @param 	bool	$fontSizeInPixels	Is the font size specified in pixels (true) or in points (false) ?
  * @param 	string	$columnText			Text to calculate width
  * @return 	int		Column width
  */
 public static function calculateColumnWidth($fontSize = 9, $fontSizeInPixels = false, $columnText = '')
 {
     if (!$fontSizeInPixels) {
         // Translate points size to pixel size
         $fontSize = PHPExcel_Shared_Font::fontSizeToPixels($fontSize);
     }
     // If it is rich text, use rich text...
     if ($columnText instanceof PHPExcel_RichText) {
         $columnText = $columnText->getPlainText();
     }
     // Only measure the part before the first newline character
     if (strpos($columnText, "\r") !== false) {
         $columnText = substr($columnText, 0, strpos($columnText, "\r"));
     }
     if (strpos($columnText, "\n") !== false) {
         $columnText = substr($columnText, 0, strpos($columnText, "\n"));
     }
     // Calculate column width
     return round((strlen($columnText) * $fontSize + 5) / $fontSize * 256 / 256, 6);
 }
Пример #8
0
 /**
  * Get font record data
  *
  * @return string
  */
 public function writeFont()
 {
     $font_outline = 0;
     $font_shadow = 0;
     $icv = $this->colorIndex;
     // Index to color palette
     if ($this->font->getSuperScript()) {
         $sss = 1;
     } elseif ($this->font->getSubScript()) {
         $sss = 2;
     } else {
         $sss = 0;
     }
     $bFamily = 0;
     // Font family
     $bCharSet = PHPExcel_Shared_Font::getCharsetFromFontName($this->font->getName());
     // Character set
     $record = 0x31;
     // Record identifier
     $reserved = 0x0;
     // Reserved
     $grbit = 0x0;
     // Font attributes
     if ($this->font->getItalic()) {
         $grbit |= 0x2;
     }
     if ($this->font->getStrikethrough()) {
         $grbit |= 0x8;
     }
     if ($font_outline) {
         $grbit |= 0x10;
     }
     if ($font_shadow) {
         $grbit |= 0x20;
     }
     $data = pack("vvvvvCCCC", $this->font->getSize() * 20, $grbit, $icv, self::mapBold($this->font->getBold()), $sss, self::mapUnderline($this->font->getUnderline()), $bFamily, $bCharSet, $reserved);
     $data .= PHPExcel_Shared_String::UTF8toBIFF8UnicodeShort($this->font->getName());
     $length = strlen($data);
     $header = pack("vv", $record, $length);
     return $header . $data;
 }
Пример #9
0
 /**
  * Calculate an (approximate) OpenXML column width, based on font size and text contained
  *
  * @param 	int		$fontSize			Font size (in pixels or points)
  * @param 	bool	$fontSizeInPixels	Is the font size specified in pixels (true) or in points (false) ?
  * @param 	string	$columnText			Text to calculate width
  * @param 	int		$rotation			Rotation angle
  * @return 	int		Column width
  */
 public static function calculateColumnWidth($fontSize = 9, $fontSizeInPixels = false, $columnText = '', $rotation = 0)
 {
     if (!$fontSizeInPixels) {
         // Translate points size to pixel size
         $fontSize = PHPExcel_Shared_Font::fontSizeToPixels($fontSize);
     }
     // If it is rich text, use rich text...
     if ($columnText instanceof PHPExcel_RichText) {
         $columnText = $columnText->getPlainText();
     }
     // Only measure the part before the first newline character
     if (strpos($columnText, "\r") !== false) {
         $columnText = substr($columnText, 0, strpos($columnText, "\r"));
     }
     if (strpos($columnText, "\n") !== false) {
         $columnText = substr($columnText, 0, strpos($columnText, "\n"));
     }
     // Calculate column width
     // values 1.025 and 0.584 found via interpolation by inspecting real Excel files with
     // Calibri font. May need further adjustment
     $columnWidth = 1.025 * strlen($columnText) + 0.584;
     // Excel adds some padding
     // Calculate approximate rotated column width
     if ($rotation !== 0) {
         if ($rotation == -165) {
             // stacked text
             $columnWidth = 4;
             // approximation
         } else {
             // rotated text
             $columnWidth = $columnWidth * cos(deg2rad($rotation)) + $fontSize * abs(sin(deg2rad($rotation))) / 5;
             // approximation
         }
     }
     // Return
     return round($columnWidth, 6);
 }
Пример #10
0
 function bearbeiterExportierenExcel(&$bearbeiterDaten)
 {
     $jahr = date('Y');
     $monat = date('m');
     $tag = date('d');
     $sheetname = 'TYPO3_Redakteure' . '_' . $jahr . '_' . $monat . '_' . $tag;
     $dateiname = $sheetname . '.xlsx';
     $spaltenTitel = array('Name', 'E-Mail', 'Seitenbereiche', 'letzter Login');
     $phpExcelService = t3lib_div::makeInstance('tx_phpexcel_service');
     $phpExcel = $phpExcelService->getPHPExcel();
     $phpExcel->getProperties()->setTitle('TYPO3_Redakteure')->setSubject('TYPO3 Redakteure');
     $phpExcel->getActiveSheet()->setTitle('TYPO3 Redakteure');
     $sheet = $phpExcel->getActiveSheet();
     PHPExcel_Shared_Font::setAutoSizeMethod(PHPExcel_Shared_Font::AUTOSIZE_METHOD_EXACT);
     $spalte = 0;
     foreach ($spaltenTitel as $titelText) {
         $objRichText = $phpExcelService->getInstanceOf('PHPExcel_RichText');
         $titel = $objRichText->createTextRun($titelText);
         $titel->getFont()->setSize('12');
         $titel->getFont()->setName('Arial');
         $titel->getFont()->setBold(true);
         $zelle = chr(ord('A') + $spalte) . '1';
         $sheet->setCellValue($zelle, $objRichText);
         $sheet->getStyle($zelle)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
         $spalte++;
     }
     $zeile = 2;
     foreach ($bearbeiterDaten as $daten) {
         $sheet->setCellValueByColumnAndRow(0, $zeile, $this->cleanStringForExport($daten['name']));
         $sheet->setCellValueByColumnAndRow(1, $zeile, $this->cleanStringForExport($daten['email']));
         $sheet->setCellValueByColumnAndRow(2, $zeile, $this->cleanStringForExport($daten['seiten']));
         $sheet->setCellValueByColumnAndRow(3, $zeile, $this->cleanStringForExport($daten['lastLogin']));
         $sheet->getStyle('C' . $zeile)->getAlignment()->setWrapText(true);
         $zeile++;
     }
     $sheet->getDefaultRowDimension()->setRowHeight(-1);
     $sheet->getColumnDimension('A')->setWidth(30);
     $sheet->getColumnDimension('B')->setWidth(30);
     $sheet->getColumnDimension('C')->setWidth(80);
     header("Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
     header('Content-Type: application/vnd.ms-excel');
     header('Content-Disposition: attachment;filename="' . $dateiname . '"');
     /*
     header('Content-Disposition: attachment;filename="' . $dateiname . '"');
     header('Cache-Control: max-age=0');
     */
     $excelWriter = $phpExcelService->getInstanceOf('PHPExcel_Writer_Excel5', $phpExcel);
     $excelWriter->save('php://output');
     exit;
 }
Пример #11
0
 private function ExcelApplyValues($sheet, $rows, $params = [])
 {
     /* Границы таблицы */
     $ramka = array('borders' => array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN)));
     /* Жирный шрифт для шапки таблицы */
     $font = array('font' => array('bold' => true), 'alignment' => array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER));
     foreach ($rows->fields as $col => $attr) {
         $sheet->setCellValueByColumnAndRow($col, 1, $attr->label);
         $sheet->getStyleByColumnAndRow($col, 1)->applyFromArray($ramka);
         $sheet->getStyleByColumnAndRow($col, 1)->applyFromArray($font);
     }
     if (count((array) $rows) > 0) {
         foreach ($rows->values as $i => $row) {
             foreach ($rows->fields as $col => $attr) {
                 if (isset($params['date']) && in_array($attr->fieldname, $params['date']) && $rows->values[$i][$attr->fieldname] !== NULL) {
                     $rows->values[$i][$attr->fieldname] = date('d.m.Y', strtotime($rows->values[$i][$attr->fieldname]));
                 }
                 if (isset($params['case']) && in_array($attr->fieldname, array_keys($params['case']))) {
                     $rows->values[$i][$attr->fieldname] = $params['case'][$attr->fieldname][$rows->values[$i][$attr->fieldname]];
                 }
                 $sheet->getStyleByColumnAndRow($col, $i + 2)->applyFromArray($ramka);
                 if (isset($params['string']) && in_array($attr->fieldname, $params['string'])) {
                     $sheet->getStyleByColumnAndRow($col, $i + 2)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
                     $sheet->setCellValueExplicitByColumnAndRow($col, $i + 2, $rows->values[$i][$attr->fieldname], PHPExcel_Cell_DataType::TYPE_STRING);
                 } else {
                     $sheet->setCellValueByColumnAndRow($col, $i + 2, $rows->values[$i][$attr->fieldname]);
                 }
             }
         }
     }
     $c = count($rows->fields);
     /* Авторазмер колонок Excel */
     PHPExcel_Shared_Font::setAutoSizeMethod(PHPExcel_Shared_Font::AUTOSIZE_METHOD_EXACT);
     foreach (range(0, $c) as $col) {
         $sheet->getColumnDimensionByColumn($col)->setAutoSize(true);
         $sheet->calculateColumnWidths();
         if ($sheet->getColumnDimensionByColumn($col)->getWidth() > 70) {
             $sheet->getColumnDimensionByColumn($col)->setAutoSize(false);
             $sheet->getColumnDimensionByColumn($col)->setWidth(70);
         }
     }
 }
Пример #12
0
 /**
  * Set the path to the folder containing .ttf files. There should be a trailing slash.
  * Typical locations on variout some platforms:
  *    <ul>
  *        <li>C:/Windows/Fonts/</li>
  *        <li>/usr/share/fonts/truetype/</li>
  *        <li>~/.fonts/</li>
  *    </ul>
  *
  * @param string $pValue
  */
 public static function setTrueTypeFontPath($pValue = '')
 {
     self::$trueTypeFontPath = $pValue;
 }
Пример #13
0
    protected function nitro_render_pdf($quizid, $userid, $cm)
    {
        global $CFG, $DB, $PAGE, $OUTPUT, $USER, $SESSION, $CM;
        $PAGE->requires->jquery();
        //disable SUBMIT button after click on this button
        echo '<script>document.getElementById("nitro_submit").disabled=true;</script>';
        //define where is storage WIRIS image
        $WIRIS_URL_IMAGE_SERVICE = $CFG->wwwroot . '/question/type/wq/quizzes/service.php?service=cache&name=';
        //GENERATE HTML FILE? DEFAULT IS FALSE
        $generate_html_file = true;
        $html_contents = '';
        //numbers of parts of the report
        $PROGRESSBAR_PARTS = 9;
        //get information about quiz, if quiz info is empty - quiz doesn't exists
        $info_quiz = $this->nitro_get_quiz($quizid);
        $this->SetBarWidth(0);
        @ob_flush();
        @flush();
        //context
        $context = context_module::instance($cm->id);
        $contexts_array = explode('/', $context->path);
        unset($contexts_array[0], $contexts_array[1]);
        arsort($contexts_array);
        $contexts_array_tmp = '';
        foreach ($contexts_array as $id => $val) {
            $contexts_array_tmp .= '"' . $val . '",';
        }
        $contexts_array = substr($contexts_array_tmp, 0, -1);
        //context end
        //mode note - 1 - error in all answer, 2 - error half answer
        $MODE_NOTE = 2;
        if (isset($_POST['evaluation_nopart']) && $_POST['evaluation_nopart'] == 1) {
            $MODE_NOTE = 1;
        }
        // generate_excel_files
        $GENERATE_EXCEL = false;
        if (isset($_POST['generate_excel_files']) && $_POST['generate_excel_files'] == 1) {
            $GENERATE_EXCEL = true;
        }
        //if info quiz is empty, show error
        if (empty($info_quiz)) {
            print_error('quizdoesntexists', 'quiz_nitroreportpdf', new moodle_url('/mod/quiz/report.php?id=' . $cm->id . '&mode=nitroreportpdf'));
        } else {
            //get info about course
            $info_course = $this->nitro_get_course($info_quiz->course);
            //specifies the number of decimal places. If the quiz that did not specify, the default is the number 4
            $decimalpoints = $info_quiz->decimalpoints >= 0 ? $info_quiz->decimalpoints : 4;
            $questiondecimalpoints = $info_quiz->questiondecimalpoints >= 0 ? $info_quiz->questiondecimalpoints : 2;
            /*
            	quiz array. Specify correct questions & answers.
            */
            $tab_quiz = array();
            if ($GENERATE_EXCEL) {
                $objPHPExcel = new PHPExcel();
                $objPHPExcel->getProperties()->setCategory("Statistic Report for Moodle Quiz")->setCompany("Jarosław Maciejewski")->setCreator("Moodle - Quiz Nitro Report PDF module")->setLastModifiedBy("Moodle - Quiz Nitro Report PDF module")->setTitle("Short statistic of test from Moodle")->setSubject("Short statistic of test from Moodle")->setDescription("Show statistic report from Moodle Quiz")->setKeywords("quiz; report; pdf; statistic;");
            }
            //GENERATE PDF
            $mpdf = new mPDF('times');
            $mpdf->useAdobeCJK = true;
            $stylesheet = file_get_contents($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/style.css');
            $mpdf->WriteHTML($stylesheet, 1);
            $mpdf->setKeywords('egzamin,moodle,jaroslaw,maciejewski');
            $mpdf->setSubject(get_string('exams_on_moodle', 'quiz_nitroreportpdf'));
            $mpdf->setCreator(get_string('moodle', 'quiz_nitroreportpdf'));
            $mpdf->setAuthor('Jarosław Maciejewski');
            $mpdf->SetProtection(array('print', 'print-highres'));
            $mpdf->setTitle(get_string('exam_result', 'quiz_nitroreportpdf'));
            // PDF HEADER
            $mpdf->setHTMLHeader('<span style="font-size: 10pt;">' . get_string('protocol_exam', 'quiz_nitroreportpdf') . ': ' . $info_quiz->name . ' ' . get_string('of_course', 'quiz_nitroreportpdf') . ' ' . $info_course->fullname . '</span><hr />');
            // PDF FOOTER
            $mpdf->setHTMLFooter('<hr />
			<table width="100%" border="0">
				<tr>
					<td style="font-size: 10pt;text-align: center;">' . get_string('page', 'quiz_nitroreportpdf') . ' {PAGENO}/{nb}</td>
					<td style="font-size: 10pt;text-align: right;width: 20%;">{DATE d.m.Y H:i}</td>
				</tr>
			</table>
			<table width="100%" border="0">
				<tr>
					<td style="font-size: 8pt;text-align: center;">' . get_string('gen_npdf', 'quiz_nitroreportpdf') . '</td>
				</tr>
			</table>');
            $mpdf->setAutoTopMargin = 'pad';
            $mpdf->setAutoBottomMargin = 'pad';
            //GENERATOR MESSAGE AND PROGRESSBAR
            ?>
		<link rel="stylesheet" href="<?php 
            echo $CFG->wwwroot . '/mod/quiz/report/nitroreportpdf/css.css';
            ?>
" />
		<div id="nitroreportpdf_text" style="margin-left: auto; margin-right: auto;text-align: center;">
		<br /><br /><br /><br /><b><?php 
            echo get_string('gen_pleasewait', 'quiz_nitroreportpdf');
            ?>
</b></div><br />
		<div id="nitroreportpdf_progress" class="nitroreportpdf_graph" style=" margin-left: auto ; margin-right: auto;">
			<div id="nitroreportpdf_bar" style="width:0%">
				<span id="nitroreportpdf_bar_text">0%</span>
			</div>
		</div>
<?php 
            /*	========================> 				1. COVER	*/
            $this->SetBarWidth(number_format(floor(1 * (100 / $PROGRESSBAR_PARTS)), 2, '.', ''));
            @ob_flush();
            @flush();
            $HTML_COVER = '
			<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
			<div style="letter-spacing: 5px;text-align: center;font-weight: bold;font-size: 20pt;text-transform:uppercase;">' . get_string('protocol_exam', 'quiz_nitroreportpdf') . '</div>
			<br /><br /><br />
			<div style="text-align: center;">
			<table border="0" width="100%">
				<tr>
					<th style="text-align: center;font-size: 14pt;">' . get_string('course', 'quiz_nitroreportpdf') . ': </th>
					<td style="text-align: center;font-size: 14pt;">' . $info_course->fullname . '</td>
				</tr>
				<tr>
					<th style="text-align: center;font-size: 14pt;">' . get_string('exam', 'quiz_nitroreportpdf') . ': </th>
					<td style="text-align: center;font-size: 14pt;">' . $info_quiz->name . '</td>
				</tr>
				<tr>
					<th style="text-align: center;font-size: 14pt;">' . get_string('date', 'quiz_nitroreportpdf') . ': </th>
					<td style="text-align: center;font-size: 14pt;">' . date('d.m.Y, H:i') . '</td>
				</tr>
			</table>
			</div>
			';
            $mpdf->AddPage();
            $mpdf->Bookmark('1. ' . get_string('cover', 'quiz_nitroreportpdf'), 0);
            $mpdf->WriteHTML($HTML_COVER);
            if ($generate_html_file) {
                $html_contents .= $NREQ . '<hr noshade>';
            }
            /*	========================> 				2. Short info about test	*/
            $this->SetBarWidth(number_format(floor(2 * (100 / $PROGRESSBAR_PARTS)), 2, '.', ''));
            @ob_flush();
            @flush();
            $timeopen = '';
            $timeclose = '';
            if (!empty($info_quiz->timeopen) || $info_quiz->timeopen > 0) {
                $timeopen = '<tr>
					<th style="text-align: left;">' . get_string('timeopen', 'quiz_nitroreportpdf') . ':</th>
					<td style="text-align: left;">' . date('d.m.Y H:i', $info_quiz->timeopen) . '</td>
				</tr>';
            }
            if (!empty($info_quiz->timeclose) || $info_quiz->timeclose > 0) {
                $timeclose = '<tr>
					<th style="text-align: left;">' . get_string('timeclose', 'quiz_nitroreportpdf') . ':</th>
					<td style="text-align: left;">' . date('d.m.Y H:i', $info_quiz->timeclose) . '</td>
				</tr>';
            }
            if (!empty($info_quiz->timelimit) || $info_quiz->timelimit > 0) {
                $nitro_convert_time_s = $this->nitro_convert_time($info_quiz->timelimit);
                $timelimit = '<tr>
					<th style="text-align: left;">' . get_string('limittime', 'quiz_nitroreportpdf') . ':</th>
					<td style="text-align: left;">' . $nitro_convert_time_s . '</td>
				</tr>';
            }
            switch ($info_quiz->grademethod) {
                case '2':
                    $grademethod = get_string('avggrade', 'quiz_nitroreportpdf');
                    break;
                case '3':
                    $grademethod = get_string('firstapproach', 'quiz_nitroreportpdf');
                    break;
                case '4':
                    $grademethod = get_string('lastapproach', 'quiz_nitroreportpdf');
                    break;
                default:
                    $grademethod = get_string('highgrade', 'quiz_nitroreportpdf');
                    break;
            }
            $number_question = $DB->count_records_sql('SELECT count(questionid) FROM {quiz_slots} WHERE quizid="' . $quizid . '"');
            $introtest = '----';
            if (!empty($info_quiz->intro)) {
                if ($generate_html_file) {
                    $introtest = $this->files_from_db_img('mod_quiz', 'intro', array('extra_sql' => 'AND contextid IN (' . $contexts_array . ')'), $info_quiz->intro, true);
                } else {
                    $introtest = $this->files_from_db_img('mod_quiz', 'intro', array('extra_sql' => 'AND contextid IN (' . $contexts_array . ')'), $info_quiz->intro);
                }
            }
            //quiz intro if
            $INTROTEST = '<div style="text-align: center;font-weight: bold;font-size:14pt;text-transform:uppercase;">' . get_string('short_info_about_test', 'quiz_nitroreportpdf') . '</div>
			<br /><br />
			 <table border="0" width="100%">
				<tr>
					<th style="text-align: left;width:53%;">' . get_string('nametest', 'quiz_nitroreportpdf') . ':</th>
					<td style="text-align: left;">' . $info_quiz->name . '</td>
				</tr>
				<tr>
					<th style="text-align: left;">' . get_string('namecourse', 'quiz_nitroreportpdf') . ':</th>
					<td style="text-align: left;">' . $info_course->fullname . '</td>
				</tr>
				<tr>
					<th style="text-align: left;">' . get_string('shortcutcourse', 'quiz_nitroreportpdf') . ':</th>
					<td style="text-align: left;">' . $info_course->shortname . '</td>
				</tr>
				<tr>
					<th style="text-align: left;">' . get_string('datecreatecourse', 'quiz_nitroreportpdf') . ':</th>
					<td style="text-align: left;">' . date('d.m.Y H:i', $info_course->timecreated) . '</td>
				</tr>
				<tr>
					<th style="text-align: left;">' . get_string('datemodifycourse', 'quiz_nitroreportpdf') . ':</th>
					<td style="text-align: left;">' . date('d.m.Y H:i', $info_course->timemodified) . '</td>
				</tr>
				' . $timeopen . '
				' . $timeclose . '
				' . $timelimit . '
				<tr>
					<th style="text-align: left;">' . get_string('modegradetest', 'quiz_nitroreportpdf') . ':</th>
					<td style="text-align: left;">' . $grademethod . '</td>
				</tr>
				<tr>
					<th style="text-align: left;">' . get_string('sumpoints', 'quiz_nitroreportpdf') . ':</th>
					<td style="text-align: left;">' . $decimalpoints . '</td>
				</tr>
				<tr>
					<th style="text-align: left;">' . get_string('gradequestion', 'quiz_nitroreportpdf') . ':</th>
					<td style="text-align: left;">' . $questiondecimalpoints . '</td>
				</tr>
				<tr>
					<th style="text-align: left;">' . get_string('maxpoints', 'quiz_nitroreportpdf') . ':</th>
					<td style="text-align: left;">' . number_format($info_quiz->sumgrades, $decimalpoints, ".", "") . '</td>
				</tr>
				<tr>
					<th style="text-align: left;">' . get_string('numquestions', 'quiz_nitroreportpdf') . ':</th>
					<td style="text-align: left;">' . $number_question . '</td>
				</tr>
				<tr>
					<th style="text-align: left;">' . get_string('intrototest', 'quiz_nitroreportpdf') . ':</th>
					<td style="text-align: left;">' . $introtest . '</td>
				</tr>
			</table>
			';
            $mpdf->AddPage();
            $mpdf->Bookmark('2. ' . get_string('short_info_about_test', 'quiz_nitroreportpdf'), 0);
            $mpdf->WriteHTML($INTROTEST);
            if ($generate_html_file) {
                $html_contents .= $INTROTEST . '<hr noshade>';
            }
            /*	========================> 				3. Correct filled test 				*/
            $this->SetBarWidth(number_format(floor(3 * (100 / $PROGRESSBAR_PARTS)), 2, '.', ''));
            @ob_flush();
            @flush();
            $mpdf->AddPage();
            $mpdf->Bookmark('3. ' . get_string('correctfilltest', 'quiz_nitroreportpdf'), 0);
            $CORRECT_FILLED_TEST_INTRO = '<p style="text-align: center;font-weight: bold;font-size:14pt;text-transform:uppercase;">' . get_string('questionandanswer', 'quiz_nitroreportpdf') . '</p><p></p>';
            $mpdf->WriteHTML($CORRECT_FILLED_TEST_INTRO);
            if ($generate_html_file) {
                $html_contents .= $CORRECT_FILLED_TEST_INTRO . '<hr noshade>';
            }
            //get questions from quiz
            $questions = $DB->get_records_sql('SELECT qs.id AS id,qs.maxmark AS q_grade,q.questiontext AS q_text,q.qtype AS q_type,qs.questionid AS q_idq FROM {quiz_slots} qs,{question} q WHERE qs.quizid=' . $quizid . ' AND qs.questionid=q.id AND q.parent=0 ORDER BY qs.questionid ASC');
            $tab_correct_answers = array();
            $nr_question = 1;
            foreach ($questions as $q) {
                $tab_correct_answers[] = number_format($q->q_grade, $questiondecimalpoints, ".", "");
                $mpdf->Bookmark($nr_question . '. ' . get_string('question2', 'quiz_nitroreportpdf'), 1);
                /* question text */
                if ($generate_html_file) {
                    $q_text = $this->files_from_db_img('question', 'questiontext', array('extra_sql' => ' AND itemid="' . $q->q_idq . '"'), $q->q_text, true);
                } else {
                    $q_text = $this->files_from_db_img('question', 'questiontext', array('extra_sql' => ' AND itemid="' . $q->q_idq . '"'), $q->q_text);
                }
                $tab_quiz[$q->q_idq]['qid'] = $q->q_idq;
                $tab_quiz[$q->q_idq]['question'] = $q_text;
                $tab_quiz[$q->q_idq]['type'] = $q->q_type;
                switch ($q->q_type) {
                    case 'truefalse':
                        $truefalse = '0';
                        //get correct answer TRUE OR FALSE on question
                        $question_truefalse_db_true = $DB->get_record_sql('SELECT qa.fraction AS fraction FROM {question_answers} qa, {question_truefalse} qtf WHERE qtf.question="' . $q->q_idq . '" AND qtf.trueanswer=qa.id');
                        //get TRUE in language . this variable is use later.
                        $tf_sql_true = $DB->get_record_sql('SELECT qa.answer AS answer FROM {question_truefalse} qt, {question_answers} qa WHERE qa.question="' . $q->q_idq . '" AND qt.question="' . $q->q_idq . '" AND qt.trueanswer=qa.id');
                        //get FALSE in language . this variable is use later.
                        $tf_sql_false = $DB->get_record_sql('SELECT qa.answer AS answer FROM {question_truefalse} qt, {question_answers} qa WHERE qa.question="' . $q->q_idq . '" AND qt.question="' . $q->q_idq . '" AND qt.falseanswer=qa.id');
                        //if answer has fraction equals more than 1 - its correct answer
                        if ($question_truefalse_db_true->fraction >= 1) {
                            $truefalse = '1';
                        } else {
                            $truefalse = '0';
                        }
                        $NREQ = '<table border="0" style="width:100%;"><tr><td><b>' . $nr_question . '.</b></td><td style="text-align:right;">' . get_string('pluginname', 'qtype_truefalse') . ' (' . number_format($q->q_grade, $questiondecimalpoints, ".", "") . ' ' . get_string('points_short', 'quiz_nitroreportpdf') . ')</td></tr></table><br />' . $q_text . '<br /><u>' . get_string('answer', 'quiz_nitroreportpdf') . ':</u> <span style="color:blue;font-weight: bold;">' . ($truefalse == 0 ? $tf_sql_false->answer : $tf_sql_true->answer) . '</span>';
                        $mpdf->WriteHTML($NREQ);
                        if ($generate_html_file) {
                            $html_contents .= $NREQ;
                        }
                        $tab_quiz[$q->q_idq]['answers'][] = $truefalse;
                        $tab_quiz[$q->q_idq]['points'][] = number_format($q->q_grade, $questiondecimalpoints, ".", "");
                        break;
                    case 'numerical':
                        $numericalA = $DB->get_record_sql('SELECT showunits,unitsleft,unitgradingtype,unitpenalty FROM {question_numerical_options} WHERE question="' . $q->q_idq . '"');
                        $numericalD = $DB->get_record_sql('SELECT id FROM {question_answers} WHERE question="' . $q->q_idq . '" AND fraction>0 ORDER BY id ASC LIMIT 0,1');
                        $numericalB = $DB->get_records_sql('SELECT qa.id AS id,qa.answer AS answer,qn.tolerance AS tolerance,qa.fraction AS fraction FROM {question_answers} qa, {question_numerical} qn WHERE qa.question="' . $q->q_idq . '" AND qa.id=qn.answer AND qa.fraction>0 ORDER BY qa.id ASC');
                        $numericalCC = $DB->get_record_sql('SELECT id FROM {question_numerical_units} WHERE question="' . $q->q_idq . '" ORDER BY id LIMIT 0,1');
                        $numericalC = $DB->get_records_sql('SELECT id,multiplier,unit FROM {question_numerical_units} WHERE question="' . $q->q_idq . '" ORDER BY id');
                        switch ($numericalA->showunits) {
                            case 0:
                            case 1:
                            case 2:
                                $tab_correct = array();
                                foreach ($numericalB as $answers) {
                                    if ($numericalA->unitgradingtype == 1) {
                                        $pkt_unitgradetype = number_format($q->q_grade * $answers->fraction * $numericalA->unitpenalty, $questiondecimalpoints, ".", "");
                                        if ($numericalA->unitpenalty <= 0) {
                                            $pkt_unitgradetype = number_format($q->q_grade * $answers->fraction, $questiondecimalpoints, ".", "");
                                        }
                                    } elseif ($numericalA->unitgradingtype == 2) {
                                        $pkt_unitgradetype = number_format($q->q_grade * $answers->fraction - $numericalA->unitpenalty, $questiondecimalpoints, ".", "");
                                    }
                                    $tab_correct[] = array('answer' => $answers->answer, 'pkt' => $pkt_unitgradetype, 'type' => 'S');
                                    $tab_quiz[$q->q_idq]['answers'][] = $answers->answer;
                                    $tab_quiz[$q->q_idq]['points'][] = $pkt_unitgradetype;
                                    if ($answers->tolerance > 0) {
                                        $a = $answers->answer - $answers->tolerance;
                                        $b = $answers->answer + $answers->tolerance;
                                        $tab_correct[] = array('answer' => $a . ' - ' . $b, 'pkt' => $pkt_unitgradetype, 'type' => 'P');
                                        $tab_quiz[$q->q_idq]['answers'][] = $a . '-' . $b;
                                        $tab_quiz[$q->q_idq]['points'][] = $pkt_unitgradetype;
                                    }
                                    if (count($numericalC) > 0) {
                                        foreach ($numericalC as $units) {
                                            if ($numericalA->unitsleft == 0) {
                                                $tab_correct[] = array('answer' => $answers->answer * $units->multiplier . $units->unit, 'pkt' => number_format($q->q_grade * $answers->fraction, $questiondecimalpoints, ".", ""), 'type' => 'S');
                                                $tab_quiz[$q->q_idq]['answers'][] = $answers->answer * $units->multiplier . '|' . $units->unit;
                                                $tab_quiz[$q->q_idq]['points'][] = number_format($q->q_grade * $answers->fraction, $questiondecimalpoints, ".", "");
                                            } else {
                                                $tab_correct[] = array('answer' => $units->unit . $answers->answer * $units->multiplier, 'pkt' => number_format($q->q_grade * $answers->fraction, $questiondecimalpoints, ".", ""), 'type' => 'S');
                                                $tab_quiz[$q->q_idq]['answers'][] = $units->unit . '|' . $answers->answer * $units->multiplier;
                                                $tab_quiz[$q->q_idq]['points'][] = number_format($q->q_grade * $answers->fraction, $questiondecimalpoints, ".", "");
                                            }
                                            if ($units->id == $numericalCC->id && $answers->tolerance > 0) {
                                                if ($numericalA->unitsleft == 0) {
                                                    $tab_correct[] = array('answer' => $a . ' - ' . $b . $units->unit, 'pkt' => number_format($q->q_grade * $answers->fraction, $questiondecimalpoints, ".", ""), 'type' => 'P');
                                                    $tab_quiz[$q->q_idq]['answers'][] = $a . '-' . $b . '|' . $units->unit;
                                                    $tab_quiz[$q->q_idq]['points'][] = number_format($q->q_grade * $answers->fraction, $questiondecimalpoints, ".", "");
                                                } else {
                                                    $tab_correct[] = array('answer' => $units->unit . $a . ' - ' . $b, 'pkt' => number_format($q->q_grade * $answers->fraction, $questiondecimalpoints, ".", ""), 'type' => 'P');
                                                    $tab_quiz[$q->q_idq]['answers'][] = $units->unit . '|' . $a . '-' . $b;
                                                    $tab_quiz[$q->q_idq]['points'][] = number_format($q->q_grade * $answers->fraction, $questiondecimalpoints, ".", "");
                                                }
                                            }
                                            if ($units->id != $numericalCC->id && $answers->tolerance > 0) {
                                                $tab_correct[] = array('answer' => $a * $units->multiplier . ' - ' . $b * $units->multiplier, 'pkt' => $pkt_unitgradetype, 'type' => 'P');
                                                $tab_quiz[$q->q_idq]['answers'][] = $a * $units->multiplier . '-' . $b * $units->multiplier . '|';
                                                $tab_quiz[$q->q_idq]['points'][] = $pkt_unitgradetype;
                                                if ($numericalA->unitsleft == 0) {
                                                    $tab_correct[] = array('answer' => $a * $units->multiplier . ' - ' . $b * $units->multiplier . $units->unit, 'pkt' => number_format($q->q_grade * $answers->fraction, $questiondecimalpoints, ".", ""), 'type' => 'P');
                                                    $tab_quiz[$q->q_idq]['answers'][] = $a * $units->multiplier . '-' . $b * $units->multiplier . '|' . $units->unit;
                                                    $tab_quiz[$q->q_idq]['points'][] = number_format($q->q_grade * $answers->fraction, $questiondecimalpoints, ".", "");
                                                } else {
                                                    $tab_correct[] = array('answer' => $units->unit . $a * $units->multiplier . ' - ' . $b * $units->multiplier, 'pkt' => number_format($q->q_grade * $answers->fraction, $questiondecimalpoints, ".", ""), 'type' => 'P');
                                                    $tab_quiz[$q->q_idq]['answers'][] = $units->unit . '|' . $a * $units->multiplier . '-' . $b * $units->multiplier;
                                                    $tab_quiz[$q->q_idq]['points'][] = number_format($q->q_grade * $answers->fraction, $questiondecimalpoints, ".", "");
                                                }
                                            }
                                        }
                                    }
                                    // if numericalC end
                                }
                                //foreach answers
                                break;
                            default:
                                foreach ($numericalB as $answers) {
                                    $tab_correct[] = array('answer' => $answers->answer, 'pkt' => number_format($q->q_grade * $answers->fraction, $questiondecimalpoints, ".", ""));
                                    $tab_quiz[$q->q_idq]['answers'][] = $answers->answer;
                                    $tab_quiz[$q->q_idq]['points'][] = number_format($q->q_grade * $answers->fraction, $questiondecimalpoints, ".", "");
                                    if ($answers->tolerance > 0) {
                                        $tab_correct[] = array('answer' => $answers->answer - $answers->tolerance . ' - ' . ($answers->answer + $answers->tolerance), 'pkt' => number_format($q->q_grade * $answers->fraction, $questiondecimalpoints, ".", ""));
                                        $tab_quiz[$q->q_idq]['answers'][] = $answers->answer - $answers->tolerance . '-' . ($answers->answer + $answers->tolerance);
                                        $tab_quiz[$q->q_idq]['points'][] = number_format($q->q_grade * $answers->fraction, $questiondecimalpoints, ".", "");
                                    }
                                }
                                break;
                        }
                        // switch ShowUnits
                        for ($i = 0; $i < count($tab_correct); $i++) {
                            if ($tab_correct[$i]['pkt'] < 0) {
                                $tab_correct[$i]['pkt'] = number_format(0, $questiondecimalpoints, ".", "");
                            }
                        }
                        for ($i = 0; $i < count($tab_quiz[$q->q_idq]['points']); $i++) {
                            if ($tab_quiz[$q->q_idq]['points'] < 0) {
                                $tab_quiz[$q->q_idq]['points'] = number_format(0, $questiondecimalpoints, ".", "");
                            }
                        }
                        foreach ($tab_correct as $id => $tab) {
                            $u_answer[$id] = $tab['answer'];
                            $u_pkt[$id] = $tab['pkt'];
                            $u_type[$id] = $tab['type'];
                        }
                        array_multisort($u_type, SORT_DESC, $u_pkt, SORT_DESC, $u_answer, SORT_STRING, SORT_ASC, $tab_correct);
                        $NREQ = '<table border="0" style="width:100%;"><tr><td><b>' . $nr_question . '.</b></td><td style="text-align: right;">' . get_string('pluginname', 'qtype_numerical') . ' (' . number_format($q->q_grade, $questiondecimalpoints, ".", "") . ' ' . get_string('points_short', 'quiz_nitroreportpdf') . ')</td></tr></table><br />' . $q_text . '<br /><u>' . get_string('answers', 'quiz_nitroreportpdf') . ':</u><br /><br /><table border="0" style="margin-left: 0%; margin-right: 0%;" class="table"><tr><th style="text-transform:capitalize;">' . get_string('points_short', 'quiz_nitroreportpdf') . '.</th><th>' . get_string('answer', 'quiz_nitroreportpdf') . '</th></tr>';
                        $mpdf->WriteHTML($NREQ);
                        if ($generate_html_file) {
                            $html_contents .= $NREQ;
                        }
                        for ($i = 0; $i < count($tab_correct); $i++) {
                            $NREQ = '<tr><td style="text-align: center;">' . $tab_correct[$i]['pkt'] . '</td><td>' . $tab_correct[$i]['answer'] . '</td></tr>';
                            $mpdf->WriteHTML($NREQ);
                            if ($generate_html_file) {
                                $html_contents .= $NREQ;
                            }
                        }
                        $answer2 = '';
                        $l = 1;
                        foreach ($numericalB as $ans0) {
                            $answer2 .= '- ' . get_string('main_answer', 'quiz_nitroreportpdf') . ' ' . $l . ': ' . $ans0->answer . ', ' . get_string('error_deviation', 'quiz_nitroreportpdf') . ':	' . $ans0->tolerance . ', ' . get_string('points_short', 'quiz_nitroreportpdf') . '. ' . number_format($q->q_grade * $ans0->fraction, 2, '.', '') . '<br />';
                            $l++;
                        }
                        $l = 1;
                        foreach ($numericalC as $ans1) {
                            $answer2 .= '- ' . get_string('unit', 'quiz_nitroreportpdf') . ' ' . $l . ': ' . $ans1->unit . ', ' . get_string('multiplier', 'quiz_nitroreportpdf') . ': ' . $ans1->multiplier . '<br />';
                            $l++;
                        }
                        if (in_array($numericalA->showunits, array(0, 1, 2))) {
                            $answer2 .= '- ' . get_string('error_reduction', 'quiz_nitroreportpdf') . ' ' . $numericalA->unitpenalty . ' ' . get_string('points_as_fraction', 'quiz_nitroreportpdf') . ' ';
                            if ($numericalA->unitgradingtype == 1) {
                                $answer2 .= get_string('given_answer', 'quiz_nitroreportpdf');
                            } elseif ($numericalA->unitgradingtype == 2) {
                                $answer2 .= get_string('question2', 'quiz_nitroreportpdf');
                            }
                            $answer2 .= '<br />- ' . get_string('unitafter', 'quiz_nitroreportpdf') . ' ';
                            if ($numericalA->unitsleft == 0) {
                                $answer2 .= get_string('right', 'quiz_nitroreportpdf');
                            } else {
                                $answer2 .= get_string('left', 'quiz_nitroreportpdf');
                            }
                            $answer2 .= ' ' . get_string('numberstr', 'quiz_nitroreportpdf') . '<br />';
                        }
                        $NREQ = '</table><br /><u>' . get_string('othersprops', 'quiz_nitroreportpdf') . ':</u> <br />' . $answer2;
                        $mpdf->WriteHTML($NREQ);
                        if ($generate_html_file) {
                            $html_contents .= $NREQ;
                        }
                        break;
                    case 'gapselect':
                        $question_gapselect = $DB->get_records_sql('SELECT id,answer FROM {question_answers} WHERE question="' . $q->q_idq . '" ORDER BY id ASC');
                        $tab_temp = array();
                        foreach ($question_gapselect as $answers) {
                            $tab_temp[] = $answers->answer;
                        }
                        preg_match_all('/\\[\\[([0-9]+)\\]\\]/', $q_text, $ZN);
                        $tab_quiz[$q->q_idq]['answers'] = $ZN[1];
                        $tab_quiz[$q->q_idq]['choices'] = $tab_temp;
                        for ($i = 0; $i < count($tab_temp); $i++) {
                            $q_text = preg_replace('/\\[\\[' . ($i + 1) . '\\]\\]/', '<span style="color:blue;font-weight: bold;">' . $tab_temp[$i] . '</span>', $q_text);
                        }
                        $NREQ = '<table border="0" style="width:100%;"><tr><td><b>' . $nr_question . '.</b></td><td style="text-align:right;">' . get_string('pluginname', 'qtype_gapselect') . ' (' . number_format($q->q_grade, $questiondecimalpoints, ".", "") . ' ' . get_string('points_short', 'quiz_nitroreportpdf') . ')</td></tr></table><br />' . $q_text;
                        $mpdf->WriteHTML($NREQ);
                        if ($generate_html_file) {
                            $html_contents .= $NREQ;
                        }
                        $tab_quiz[$q->q_idq]['points'][] = number_format($q->q_grade, $questiondecimalpoints, ".", "");
                        break;
                    case 'ddimageortext':
                        $data = null;
                        $bigfile_details = $DB->get_record_sql('SELECT contextid,filepath,filename,filesize,timecreated,timemodified,contenthash FROM {files} WHERE component="qtype_ddimageortext" AND filearea="bgimage" AND itemid="' . $q->q_idq . '" AND mimetype<>"" AND filename<>"."');
                        $filename = hash('sha384', "qtype_ddimageortextbgimage" . $bigfile_details->filesize . $bigfile_details->timecreated . $bigfile_details->timemodified . $bigfile_details->contenthash . $bigfile_details->filepath . $bigfile_details->filename) . '.' . pathinfo($bigfile_details->filename)['extension'];
                        if (!file_exists($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $filename)) {
                            $fs = null;
                            $file_big = null;
                            $fs_big = get_file_storage();
                            $file_big = $fs_big->get_file($bigfile_details->contextid, 'qtype_ddimageortext', 'bgimage', $q->q_idq, $bigfile_details->filepath, $bigfile_details->filename);
                            if ($file_big) {
                                $file_big->copy_content_to($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $filename);
                            }
                            // file
                        }
                        touch($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $filename);
                        $data['ddimageortext_bigfile'] = $filename;
                        $tab_quiz[$q->q_idq]['ddimageortext_bigfile'] = $filename;
                        $tab_text = array();
                        $tab_image = array();
                        $dd_files = $DB->get_records_sql('SELECT id,no,label FROM {qtype_ddimageortext_drags} WHERE questionid="' . $q->q_idq . '" ORDER BY no ASC');
                        $dd_files_ids = array_keys($dd_files);
                        for ($z = 0; $z < count($dd_files_ids); $z++) {
                            $dd_files2 = $DB->get_record_sql('SELECT no,xleft,ytop,choice FROM {qtype_ddimageortext_drops} WHERE questionid="' . $q->q_idq . '" AND no="' . $dd_files[$dd_files_ids[$z]]->no . '" ORDER BY choice ASC');
                            if (isset($dd_files2->no)) {
                                $dd_filesA = $DB->get_record_sql('SELECT f.id AS f_id,f.contextid AS f_contexid,f.filepath AS f_filepath,f.filename AS f_filename,f.filesize AS f_filesize,f.timecreated AS f_timecreated,f.timemodified AS f_timemodified,f.contenthash AS f_contenthash FROM {files} f WHERE f.itemid="' . $dd_files_ids[$z] . '" AND contextid="' . $bigfile_details->contextid . '" AND f.component="qtype_ddimageortext" AND f.filearea="dragimage" AND f.mimetype<>"" AND filename<>"."');
                                $filename = hash('sha384', "qtype_ddimageortextdragimage" . $dd_filesA->f_filesize . $dd_filesA->f_timecreated . $dd_filesA->f_timemodified . $dd_filesA->f_contenthash . $dd_filesA->f_filepath . $dd_filesA->f_filename) . '.' . pathinfo($dd_filesA->f_filename)['extension'];
                                if (!empty($dd_filesA->f_id)) {
                                    if (!file_exists($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $filename)) {
                                        $fs = null;
                                        $mfile = null;
                                        $fs = get_file_storage();
                                        $mfile = $fs->get_file($dd_filesA->f_contexid, 'qtype_ddimageortext', 'dragimage', $dd_files_ids[$z], $dd_filesA->f_filepath, $dd_filesA->f_filename);
                                        if ($mfile) {
                                            $mfile->copy_content_to($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $filename);
                                        }
                                    }
                                    touch($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $filename);
                                    $tab_image[] = array('x' => $dd_files2->xleft, 'y' => $dd_files2->ytop, 'filename' => $filename);
                                    $tab_quiz[$q->q_idq]['answers'][$dd_files[$dd_files_ids[$z]]->no - 1] = array('lab_img' => $filename, 'type' => 'image', 'choice' => $dd_files[$dd_files_ids[$z]]->no, 'x' => $dd_files2->xleft, 'y' => $dd_files2->ytop);
                                } else {
                                    $tab_text[] = array('x' => $dd_files2->xleft, 'y' => $dd_files2->ytop, 'text' => $dd_files[$dd_files_ids[$z]]->label);
                                    $tab_quiz[$q->q_idq]['answers'][$dd_files[$dd_files_ids[$z]]->no - 1] = array('lab_img' => $dd_files[$dd_files_ids[$z]]->label, 'type' => 'text', 'choice' => $dd_files[$dd_files_ids[$z]]->no, 'x' => $dd_files2->xleft, 'y' => $dd_files2->ytop);
                                }
                            } else {
                                $dd_filesA = $DB->get_record_sql('SELECT f.id AS f_id,f.contextid AS f_contexid,f.filepath AS f_filepath,f.filename AS f_filename,f.filesize AS f_filesize,f.timecreated AS f_timecreated,f.timemodified AS f_timemodified,f.contenthash AS f_contenthash FROM FROM {files} f WHERE f.itemid="' . $dd_files_ids[$z] . '" AND contextid="' . $bigfile_details->contextid . '" AND f.component="qtype_ddimageortext" AND f.filearea="dragimage" AND f.mimetype<>"" AND filename<>"."');
                                $filename = hash('sha384', "qtype_ddimageortextdragimage" . $dd_filesA->f_filesize . $dd_filesA->f_timecreated . $dd_filesA->f_timemodified . $dd_filesA->f_contenthash . $dd_filesA->f_filepath . $dd_filesA->f_filename) . '.' . pathinfo($dd_filesA->f_filename)['extension'];
                                if (!empty($dd_filesA->f_id)) {
                                    if (!file_exists($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $filename)) {
                                        $fs = null;
                                        $mfile = null;
                                        $fs = get_file_storage();
                                        $mfile = $fs->get_file($dd_filesA->f_contexid, 'qtype_ddimageortext', 'dragimage', $dd_files_ids[$z], $dd_filesA->f_filepath, $dd_filesA->f_filename);
                                        if ($mfile) {
                                            $mfile->copy_content_to($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $tempfilename);
                                        }
                                    }
                                    touch($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $filename);
                                    $tab_image[] = array('x' => -1000, 'y' => -1000, 'filename' => $tempfilename);
                                    $tab_quiz[$q->q_idq]['answers'][$dd_files[$dd_files_ids[$z]]->no - 1] = array('lab_img' => $tempfilename, 'type' => 'image', 'choice' => $dd_files[$dd_files_ids[$z]]->no, 'x' => -1000, 'y' => -1000);
                                } else {
                                    $tab_text[] = array('x' => -1000, 'y' => -1000, 'text' => $dd_files[$dd_files_ids[$z]]->label);
                                    $tab_quiz[$q->q_idq]['answers'][$dd_files[$dd_files_ids[$z]]->no - 1] = array('lab_img' => $dd_files[$dd_files_ids[$z]]->label, 'type' => 'text', 'choice' => $dd_files[$dd_files_ids[$z]]->no, 'x' => -1000, 'y' => -1000);
                                }
                            }
                            // if exists more some are unused
                        }
                        $data['texts'] = json_encode($tab_text);
                        $data['images'] = json_encode($tab_image);
                        $data['filename'] = '_U' . $userid . '_Q' . $quizid . '_' . strtotime('now') . uniqid() . uniqid() . '.jpg';
                        $ch = curl_init();
                        curl_setopt($ch, CURLOPT_URL, $CFG->wwwroot . '/mod/quiz/report/nitroreportpdf/image.php');
                        curl_setopt($ch, CURLOPT_HEADER, 0);
                        curl_setopt($ch, CURLOPT_POST, 1);
                        curl_setopt($ch, CURLOPT_TIMEOUT, 60);
                        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
                        curl_exec($ch);
                        curl_close($ch);
                        $NREQ = '<table border="0" style="width:100%;"><tr><td><b>' . $nr_question . '.</b></td><td style="text-align:right;">' . get_string('pluginname', 'qtype_ddimageortext') . ' (' . number_format($q->q_grade, $questiondecimalpoints, ".", "") . ' ' . get_string('points_short', 'quiz_nitroreportpdf') . ')</td></tr></table><br />' . $q_text . '<br /><img src="report/nitroreportpdf/cache/' . $data['filename'] . '" />';
                        $mpdf->WriteHTML($NREQ);
                        if ($generate_html_file) {
                            $html_contents .= $NREQ;
                        }
                        $tab_quiz[$q->q_idq]['points'][] = number_format($q->q_grade, $questiondecimalpoints, ".", "");
                        break;
                    case 'multianswer':
                        $question_multianswer = $DB->get_records_sql('SELECT id,questiontext FROM {question} WHERE parent="' . $q->q_idq . '" ORDER BY id ASC');
                        $i = 0;
                        foreach ($question_multianswer as $id => $multianswer) {
                            $getanswer = $this->nitro_get_multianswer_correct_answer($multianswer->questiontext);
                            $tab_quiz[$q->q_idq]['answers'][] = $getanswer;
                            if (count($getanswer['answers']) > 1) {
                                for ($l = 0; $l < count($getanswer['answers']); $l++) {
                                    $points = $getanswer['points'][$l];
                                    if (empty($points)) {
                                        $points = 0;
                                    }
                                    if ($l == $getanswer['correct']) {
                                        $correct_answer .= '<span style="color:blue;font-weight: bold;">' . $getanswer['answers'][$l] . ' (' . $points . ' ' . get_string('points_short', 'quiz_nitroreportpdf') . ')</span>, ';
                                    } else {
                                        $correct_answer .= $getanswer['answers'][$l] . ' (' . $points . ' ' . get_string('points_short', 'quiz_nitroreportpdf') . ')</span>, ';
                                    }
                                }
                                $correct_answer = '[' . substr($correct_answer, 0, -2) . ']';
                            } else {
                                $correct_answer = '<span style="color:blue;font-weight: bold;">' . $getanswer['answers'][0] . ' (' . $points . ' ' . get_string('points_short', 'quiz_nitroreportpdf') . ')</span>';
                            }
                            $q_text = preg_replace('/{#' . $i . '}/', $correct_answer, $q_text);
                            $question_multianswer_resp = $DB->get_records_sql('SELECT id FROM {question_answers} WHERE question="' . $id . '" ORDER BY id ASC');
                            $j = 0;
                            foreach ($question_multianswer_resp as $res) {
                                $tab_quiz[$q->q_idq]['answers'][$i]['answers_id'][$res->id] = $j;
                                $j++;
                            }
                            $i++;
                        }
                        $tab_quiz[$q->q_idq]['question_with_answers'] = $q_text;
                        $tab_quiz[$q->q_idq]['points'][0] = number_format($q->q_grade, $questiondecimalpoints, ".", "");
                        if ($MODE_NOTE == 2) {
                            $points = 0;
                            $i = 0;
                            for ($z = 0; $z < count($tab_quiz[$q->q_idq]['answers']); $z++) {
                                $points += $tab_quiz[$q->q_idq]['answers'][$z]['points'][$tab_quiz[$q->q_idq]['answers'][$z]['correct']];
                            }
                            $tab_quiz[$q->q_idq]['points'][0] = number_format($points, $questiondecimalpoints, ".", "");
                        }
                        $NREQ = '<table border="0" style="width:100%;"><tr><td><b>' . $nr_question . '.</b></td><td style="text-align:right;">' . get_string('pluginname', 'qtype_multianswer') . ' (' . $tab_quiz[$q->q_idq]['points'][0] . ' ' . get_string('points_short', 'quiz_nitroreportpdf') . ')</td></tr></table><br />' . $q_text;
                        $mpdf->WriteHTML($NREQ);
                        if ($generate_html_file) {
                            $html_contents .= $NREQ;
                        }
                        break;
                    case 'ddwtos':
                        $ddwtos_answers = $DB->get_records_sql('SELECT id,answer FROM {question_answers} WHERE question="' . $q->q_idq . '" ORDER BY id ASC');
                        $answer_nb = 1;
                        foreach ($ddwtos_answers as $ddwtos_answers) {
                            $q_text = preg_replace('/\\[\\[' . $answer_nb . '\\]\\]/', '<span style="color:blue;font-weight: bold;">' . $ddwtos_answers->answer . '</span>', $q_text);
                            $tab_quiz[$q->q_idq]['answers'][$answer_nb] = $ddwtos_answers->answer;
                            $answer_nb++;
                        }
                        $NREQ = '<table border="0" style="width:100%;"><tr><td><b>' . $nr_question . '.</b></td><td style="text-align:right;">' . get_string('pluginname', 'qtype_ddwtos') . ' (' . number_format($q->q_grade, $questiondecimalpoints, ".", "") . ' ' . get_string('points_short', 'quiz_nitroreportpdf') . ')</td></tr></table><br />' . $q_text;
                        $mpdf->WriteHTML($NREQ);
                        if ($generate_html_file) {
                            $html_contents .= $NREQ;
                        }
                        $tab_quiz[$q->q_idq]['points'][] = number_format($q->q_grade, $questiondecimalpoints, ".", "");
                        break;
                    case 'match':
                        $match_answers = $DB->get_records_sql('SELECT id,questiontext,answertext FROM {qtype_match_subquestions} WHERE questionid="' . $q->q_idq . '" ORDER BY id ASC');
                        $answers_tab = '';
                        foreach ($match_answers as $match_answers) {
                            if ($generate_html_file) {
                                $question = $this->files_from_db_img('qtype_match', 'subquestion', array('extra_sql' => ' AND itemid="' . $match_answers->id . '" AND contextid IN (' . $contexts_array . ')'), $match_answers->questiontext, true);
                            } else {
                                $question = $this->files_from_db_img('qtype_match', 'subquestion', array('extra_sql' => ' AND itemid="' . $match_answers->id . '" AND contextid IN (' . $contexts_array . ')'), $match_answers->questiontext);
                            }
                            $answer = $match_answers->answertext;
                            $tab_quiz[$q->q_idq]['answers'][$match_answers->id] = array('question' => $question, 'answer' => $answer);
                            $answers_tab .= '<tr><td>' . $question . '</td><td>' . $answer . '</td></tr>';
                        }
                        //if are some file to process
                        $NREQ = '<table border="0" style="width:100%;"><tr><td><b>' . $nr_question . '.</b></td><td style="text-align:right;">' . get_string('pluginname', 'qtype_match') . ' (' . number_format($q->q_grade, $questiondecimalpoints, ".", "") . ' ' . get_string('points_short', 'quiz_nitroreportpdf') . ')</td></tr></table><br />' . $q_text . '<br /><u>' . get_string('answers', 'quiz_nitroreportpdf') . ':</u><br /><br /><table border="1"><tr><th>' . get_string('question2', 'quiz_nitroreportpdf') . '</th><th>' . get_string('answer', 'quiz_nitroreportpdf') . '</th></tr>' . $answers_tab . '</table>';
                        $mpdf->WriteHTML($NREQ);
                        if ($generate_html_file) {
                            $html_contents .= $NREQ;
                        }
                        $tab_quiz[$q->q_idq]['points'][] = number_format($q->q_grade, $questiondecimalpoints, ".", "");
                        break;
                    case 'multichoice':
                        $tab_quiz[$q->q_idq]['points'][] = number_format($q->q_grade, $questiondecimalpoints, ".", "");
                        $answers_db = $DB->get_records_sql('SELECT id,answer,fraction FROM {question_answers} WHERE question="' . $q->q_idq . '"');
                        $multi_tb = $DB->get_record_sql('SELECT single FROM {qtype_multichoice_options} WHERE questionid="' . $q->q_idq . '"');
                        if ($multi_tb->single == 1) {
                            $type_q = get_string('questiontypemultichoiceone', 'quiz_nitroreportpdf');
                        } else {
                            $type_q = get_string('questiontypemultichoicemulti', 'quiz_nitroreportpdf');
                        }
                        $NREQ = '<table border="0" style="width: 100%;"><tr><td><b>' . $nr_question . '.</b></td><td style="text-align: right;">' . $type_q . ' (' . number_format($q->q_grade, $questiondecimalpoints, ".", "") . ' ' . get_string('points_short', 'quiz_nitroreportpdf') . ')</td></tr></table><br />' . $q_text . '<br /><u>' . get_string('answers', 'quiz_nitroreportpdf') . ':</u> <br /><br />';
                        $mpdf->WriteHTML($NREQ);
                        if ($generate_html_file) {
                            $html_contents .= $NREQ;
                        }
                        $nr_answer = 1;
                        foreach ($answers_db as $answer) {
                            if ($generate_html_file) {
                                $answer_txt = $this->files_from_db_img('question', 'answer', array('extra_sql' => ' AND itemid="' . $answer->id . '" AND contextid IN (' . $contexts_array . ')'), $answer->answer, true);
                            } else {
                                $answer_txt = $this->files_from_db_img('question', 'answer', array('extra_sql' => ' AND itemid="' . $answer->id . '" AND contextid IN (' . $contexts_array . ')'), $answer->answer);
                            }
                            $corr = '';
                            $tab_quiz[$q->q_idq]['qanswers'][$answer->id] = 0;
                            if ($multi_tb->single == 1 && $answer->fraction >= 1) {
                                $corr = '<span style="color: blue;"><b>[X]</b></span> ';
                                $tab_quiz[$q->q_idq]['qanswers'][$answer->id] = 1;
                            }
                            if ($multi_tb->single == 0 && $answer->fraction > 0) {
                                $corr = '<span style="color: blue;"><b>[X]</b></span> ';
                                $tab_quiz[$q->q_idq]['qanswers'][$answer->id] = 1;
                            }
                            $NREQ = $corr . '<b>' . $nr_answer . '.</b> ' . $answer_txt;
                            $mpdf->WriteHTML($NREQ);
                            if ($generate_html_file) {
                                $html_contents .= $NREQ;
                            }
                            $tab_quiz[$q->q_idq]['answers'][$answer->id] = $answer_txt;
                            $nr_answer++;
                        }
                        break;
                    case 'ddmatch':
                        $tab_quiz[$q->q_idq]['points'][] = number_format($q->q_grade, $questiondecimalpoints, ".", "");
                        $ddmatch_answers = $DB->get_records_sql('SELECT id,questiontext,answertext FROM {qtype_ddmatch_subquestions} WHERE questionid="' . $q->q_idq . '" ORDER BY id ASC');
                        $answers_tab = '';
                        foreach ($ddmatch_answers as $ddmatch_answers) {
                            if ($generate_html_file) {
                                $answer = $this->files_from_db_img('qtype_ddmatch', 'subanswer', array('extra_sql' => ' AND itemid="' . $ddmatch_answers->id . '" AND contextid IN (' . $contexts_array . ')'), $ddmatch_answers->answertext, true);
                                $question = $this->files_from_db_img('qtype_ddmatch', 'subquestion', array('extra_sql' => ' AND itemid="' . $ddmatch_answers->id . '" AND contextid IN (' . $contexts_array . ')'), $ddmatch_answers->questiontext, true);
                            } else {
                                $answer = $this->files_from_db_img('qtype_ddmatch', 'subanswer', array('extra_sql' => ' AND itemid="' . $ddmatch_answers->id . '" AND contextid IN (' . $contexts_array . ')'), $ddmatch_answers->answertext);
                                $question = $this->files_from_db_img('qtype_ddmatch', 'subquestion', array('extra_sql' => ' AND itemid="' . $ddmatch_answers->id . '" AND contextid IN (' . $contexts_array . ')'), $ddmatch_answers->questiontext);
                            }
                            $tab_quiz[$q->q_idq]['questions'][$ddmatch_answers->id] = $question;
                            $tab_quiz[$q->q_idq]['answers'][$ddmatch_answers->id] = $answer;
                            $answers_tab .= '<tr><td>' . $question . '</td><td>' . $answer . '</td></tr>';
                        }
                        $NREQ = '<table border="0" style="width:100%;"><tr><td><b>' . $nr_question . '.</b></td><td style="text-align:right;">' . get_string('pluginname', 'qtype_ddmatch') . ' (' . number_format($q->q_grade, $questiondecimalpoints, ".", "") . ' ' . get_string('points_short', 'quiz_nitroreportpdf') . ')</td></tr></table><br />' . $q_text . '<br /><u>' . get_string('answers', 'quiz_nitroreportpdf') . ':</u><br /><br /><table border="1" style="margin-left: auto; margin-right: auto;"><tr><th>' . get_string('question2', 'quiz_nitroreportpdf') . '</th><th>' . get_string('answer', 'quiz_nitroreportpdf') . '</th></tr>' . $answers_tab . '</table>';
                        $mpdf->WriteHTML($NREQ);
                        if ($generate_html_file) {
                            $html_contents .= $NREQ;
                        }
                        break;
                    case 'ordering':
                        $tab_quiz[$q->q_idq]['points'][] = number_format($q->q_grade, $questiondecimalpoints, ".", "");
                        $ordering_answers = $DB->get_records_sql('SELECT id,answer FROM {question_answers} WHERE question="' . $q->q_idq . '" ORDER BY fraction ASC');
                        $q_text = $q->q_text . '<br><br>';
                        foreach ($ordering_answers as $ordering_answers) {
                            $q_text .= $ordering_answers->answer . '<br><hr><br>';
                            $tab_quiz[$q->q_idq]['answers'][$ordering_answers->id] = $ordering_answers->answer;
                            $tab_quiz[$q->q_idq]['answers_md5'][md5($ordering_answers->answer)] = $ordering_answers->id;
                        }
                        $q_text = substr($q_text, 0, -12) . '<br><br>' . get_string('options', 'quiz_nitroreportpdf') . ':<br>';
                        $ordering_options = $DB->get_record_sql('SELECT selecttype,selectcount FROM {qtype_ordering_options} WHERE questionid="' . $q->q_idq . '"');
                        switch ($ordering_options->selecttype) {
                            case 0:
                                $q_text .= '- ' . get_string('selecttype', 'qtype_ordering') . ': ' . get_string('selectall', 'qtype_ordering') . '<br>';
                                break;
                            case 1:
                                $q_text .= '- ' . get_string('selecttype', 'qtype_ordering') . ': ' . get_string('selectrandom', 'qtype_ordering') . '<br>';
                                break;
                            case 2:
                                $q_text .= '- ' . get_string('selecttype', 'qtype_ordering') . ': ' . get_string('selectcontiguous', 'qtype_ordering') . '<br>';
                                break;
                        }
                        $q_text .= '- ' . get_string('selectcount', 'qtype_ordering') . ': ';
                        if ($ordering_options->selectcount == 0) {
                            $q_text .= get_string('all', 'quiz_nitroreportpdf') . ' <br>';
                        } else {
                            $q_text .= $ordering_options->selectcount . ' <br>';
                        }
                        $NREQ = '<table border="0" style="width:100%;"><tr><td><b>' . $nr_question . '.</b></td><td style="text-align:right;">' . get_string('pluginname', 'qtype_ordering') . ' (' . number_format($q->q_grade, $questiondecimalpoints, ".", "") . ' ' . get_string('points_short', 'quiz_nitroreportpdf') . ')</td></tr></table><br />' . $q_text;
                        $mpdf->WriteHTML($NREQ);
                        if ($generate_html_file) {
                            $html_contents .= $NREQ;
                        }
                        break;
                    case 'gapfill':
                        $tab_quiz[$q->q_idq]['points'][] = number_format($q->q_grade, $questiondecimalpoints, ".", "");
                        $gapfill_answers = $DB->get_records_sql('SELECT id,answer FROM {question_answers} WHERE question="' . $q->q_idq . '" ORDER BY id ASC');
                        $gapfill_options = $DB->get_records_sql('SELECT question,delimitchars,casesensitive,noduplicates FROM {question_gapfill} WHERE question="' . $q->q_idq . '"');
                        $tab_quiz[$q->q_idq]['options'] = array($gapfill_options[$q->q_idq]->delimitchars, $gapfill_options[$q->q_idq]->casesensitive, $gapfill_options[$q->q_idq]->noduplicates);
                        $q_text = $q->q_text;
                        foreach ($gapfill_answers as $gapfill_answers) {
                            $tab_quiz[$q->q_idq]['answers'][] = $gapfill_answers->answer;
                        }
                        preg_match_all('/\\' . substr($tab_quiz[$q->q_idq]['options'][0], 0, 1) . '(.*)\\' . substr($tab_quiz[$q->q_idq]['options'][0], 1, 1) . '/U', $q_text, $founded);
                        for ($i = 0; $i < count($founded[1]); $i++) {
                            $q_text = preg_replace('/\\' . substr($tab_quiz[$q->q_idq]['options'][0], 0, 1) . $founded[1][$i] . '\\' . substr($tab_quiz[$q->q_idq]['options'][0], 1, 1) . '/', $tab_quiz[$q->q_idq]['answers'][$i], $q_text);
                        }
                        $NREQ = '<table border="0" style="width:100%;"><tr><td><b>' . $nr_question . '.</b></td><td style="text-align:right;">' . get_string('pluginname', 'qtype_gapfill') . ' (' . number_format($q->q_grade, $questiondecimalpoints, ".", "") . ' ' . get_string('points_short', 'quiz_nitroreportpdf') . ')</td></tr></table><br />' . $q_text;
                        $mpdf->WriteHTML($NREQ);
                        if ($generate_html_file) {
                            $html_contents .= $NREQ;
                        }
                        break;
                        // WIRIS QUESTIONS *** WIRIS QUESTIONS *** WIRIS QUESTIONS
                    // WIRIS QUESTIONS *** WIRIS QUESTIONS *** WIRIS QUESTIONS
                    case 'truefalsewiris':
                        $truefalse = '0';
                        //get correct answer TRUE OR FALSE on question
                        $question_truefalse_db_true = $DB->get_record_sql('SELECT qa.fraction AS fraction FROM {question_answers} qa, {question_truefalse} qtf WHERE qtf.question="' . $q->q_idq . '" AND qtf.trueanswer=qa.id');
                        //get TRUE in language . this variable is use later.
                        $tf_sql_true = $DB->get_record_sql('SELECT qa.answer AS answer FROM {question_truefalse} qt, {question_answers} qa WHERE qa.question="' . $q->q_idq . '" AND qt.question="' . $q->q_idq . '" AND qt.trueanswer=qa.id');
                        //get FALSE in language . this variable is use later.
                        $tf_sql_false = $DB->get_record_sql('SELECT qa.answer AS answer FROM {question_truefalse} qt, {question_answers} qa WHERE qa.question="' . $q->q_idq . '" AND qt.question="' . $q->q_idq . '" AND qt.falseanswer=qa.id');
                        //if answer has fraction equals more than 1 - its correct answer
                        if ($question_truefalse_db_true->fraction >= 1) {
                            $truefalse = '1';
                        } else {
                            $truefalse = '0';
                        }
                        $NREQ = '<table border="0" style="width:100%;"><tr><td><b>' . $nr_question . '.</b></td><td style="text-align:right;">WIRIS - ' . get_string('pluginname', 'qtype_truefalsewiris') . ' (' . number_format($q->q_grade, $questiondecimalpoints, ".", "") . ' ' . get_string('points_short', 'quiz_nitroreportpdf') . ')</td></tr></table><br />' . $q_text . '<br /><u>' . get_string('answer', 'quiz_nitroreportpdf') . ':</u> <span style="color:blue;font-weight: bold;">' . ($truefalse == 0 ? $tf_sql_false->answer : $tf_sql_true->answer) . '</span>';
                        $mpdf->WriteHTML($NREQ);
                        if ($generate_html_file) {
                            $html_contents .= $NREQ;
                        }
                        $tab_quiz[$q->q_idq]['answers'][] = $truefalse;
                        $tab_quiz[$q->q_idq]['points'][] = number_format($q->q_grade, $questiondecimalpoints, ".", "");
                        break;
                    case 'matchwiris':
                        $match_answers = $DB->get_records_sql('SELECT id,questiontext,answertext FROM {qtype_match_subquestions} WHERE questionid="' . $q->q_idq . '" ORDER BY id ASC');
                        $answers_tab = '';
                        foreach ($match_answers as $match_answers) {
                            if ($generate_html_file) {
                                $question = $this->files_from_db_img('qtype_match', 'subquestion', array('extra_sql' => ' AND itemid="' . $match_answers->id . '" AND contextid IN (' . $contexts_array . ')'), $match_answers->questiontext, true);
                            } else {
                                $question = $this->files_from_db_img('qtype_match', 'subquestion', array('extra_sql' => ' AND itemid="' . $match_answers->id . '" AND contextid IN (' . $contexts_array . ')'), $match_answers->questiontext);
                            }
                            $answer = $match_answers->answertext;
                            $tab_quiz[$q->q_idq]['answers'][$match_answers->id] = array('question' => $question, 'answer' => $answer);
                            $answers_tab .= '<tr><td>' . $question . '</td><td>' . $answer . '</td></tr>';
                        }
                        //if are some file to process
                        $NREQ = '<table border="0" style="width:100%;"><tr><td><b>' . $nr_question . '.</b></td><td style="text-align:right;">WIRIS - ' . get_string('pluginname', 'qtype_match') . ' (' . number_format($q->q_grade, $questiondecimalpoints, ".", "") . ' ' . get_string('points_short', 'quiz_nitroreportpdf') . ')</td></tr></table><br />' . $q_text . '<br /><u>' . get_string('answers', 'quiz_nitroreportpdf') . ':</u><br /><br /><table border="1"><tr><th>' . get_string('question2', 'quiz_nitroreportpdf') . '</th><th>' . get_string('answer', 'quiz_nitroreportpdf') . '</th></tr>' . $answers_tab . '</table>';
                        $mpdf->WriteHTML($NREQ);
                        if ($generate_html_file) {
                            $html_contents .= $NREQ;
                        }
                        $tab_quiz[$q->q_idq]['points'][] = number_format($q->q_grade, $questiondecimalpoints, ".", "");
                        break;
                    case 'multianswerwiris':
                        $question_multianswer = $DB->get_records_sql('SELECT id,questiontext FROM {question} WHERE parent="' . $q->q_idq . '" ORDER BY id ASC');
                        $i = 0;
                        foreach ($question_multianswer as $id => $multianswer) {
                            $multianswer_questiontext = preg_replace('/\\\\#/', '@@@@@', $multianswer->questiontext);
                            $getanswer = $this->nitro_get_multianswer_correct_answer($multianswer_questiontext);
                            $tab_quiz[$q->q_idq]['answers'][] = $getanswer;
                            if (count($getanswer['answers']) > 1) {
                                for ($l = 0; $l < count($getanswer['answers']); $l++) {
                                    $points = $getanswer['points'][$l];
                                    if (empty($points)) {
                                        $points = 0;
                                    }
                                    if ($l == $getanswer['correct']) {
                                        $correct_answer .= '<span style="color:blue;font-weight: bold;">' . $getanswer['answers'][$l] . ' (' . $points . ' ' . get_string('points_short', 'quiz_nitroreportpdf') . ')</span>, ';
                                    } else {
                                        $correct_answer .= $getanswer['answers'][$l] . ' (' . $points . ' ' . get_string('points_short', 'quiz_nitroreportpdf') . ')</span>, ';
                                    }
                                }
                                $correct_answer = '[' . substr($correct_answer, 0, -2) . ']';
                            } else {
                                $correct_answer = '<span style="color:blue;font-weight: bold;">' . $getanswer['answers'][0] . ' (' . $points . ' ' . get_string('points_short', 'quiz_nitroreportpdf') . ')</span>';
                            }
                            $q_text = preg_replace('/{#' . $i . '}/', $correct_answer, $q_text);
                            $question_multianswer_resp = $DB->get_records_sql('SELECT id FROM {question_answers} WHERE question="' . $id . '" ORDER BY id ASC');
                            $j = 0;
                            foreach ($question_multianswer_resp as $res) {
                                $tab_quiz[$q->q_idq]['answers'][$i]['answers_id'][$res->id] = $j;
                                $j++;
                            }
                            $i++;
                        }
                        $tab_quiz[$q->q_idq]['question_with_answers'] = $q_text;
                        $tab_quiz[$q->q_idq]['points'][0] = number_format($q->q_grade, $questiondecimalpoints, ".", "");
                        if ($MODE_NOTE == 2) {
                            $points = 0;
                            $i = 0;
                            for ($z = 0; $z < count($tab_quiz[$q->q_idq]['answers']); $z++) {
                                $points += $tab_quiz[$q->q_idq]['answers'][$z]['points'][$tab_quiz[$q->q_idq]['answers'][$z]['correct']];
                            }
                            $tab_quiz[$q->q_idq]['points'][0] = number_format($points, $questiondecimalpoints, ".", "");
                        }
                        $NREQ = '<table border="0" style="width:100%;"><tr><td><b>' . $nr_question . '.</b></td><td style="text-align:right;">WIRIS - ' . get_string('pluginname', 'qtype_multianswerwiris') . ' (' . $tab_quiz[$q->q_idq]['points'][0] . ' ' . get_string('points_short', 'quiz_nitroreportpdf') . ')</td></tr></table><br />' . $q_text;
                        $mpdf->WriteHTML($NREQ);
                        if ($generate_html_file) {
                            $html_contents .= $NREQ;
                        }
                        break;
                    case 'multichoicewiris':
                        $tab_quiz[$q->q_idq]['points'][] = number_format($q->q_grade, $questiondecimalpoints, ".", "");
                        $answers_db = $DB->get_records_sql('SELECT id,answer,fraction FROM {question_answers} WHERE question="' . $q->q_idq . '"');
                        $multi_tb = $DB->get_record_sql('SELECT single FROM {qtype_multichoice_options} WHERE questionid="' . $q->q_idq . '"');
                        if ($multi_tb->single == 1) {
                            $type_q = get_string('questiontypemultichoiceone', 'quiz_nitroreportpdf');
                        } else {
                            $type_q = get_string('questiontypemultichoicemulti', 'quiz_nitroreportpdf');
                        }
                        $NREQ = '<table border="0" style="width: 100%;"><tr><td><b>' . $nr_question . '.</b></td><td style="text-align: right;">WIRIS - ' . $type_q . ' (' . number_format($q->q_grade, $questiondecimalpoints, ".", "") . ' ' . get_string('points_short', 'quiz_nitroreportpdf') . ')</td></tr></table><br />' . $q_text . '<br /><u>' . get_string('answers', 'quiz_nitroreportpdf') . ':</u> <br /><br />';
                        $mpdf->WriteHTML($NREQ);
                        if ($generate_html_file) {
                            $html_contents .= $NREQ;
                        }
                        $nr_answer = 1;
                        foreach ($answers_db as $answer) {
                            if ($generate_html_file) {
                                $answer_txt = $this->files_from_db_img('question', 'answer', array('extra_sql' => ' AND itemid="' . $answer->id . '" AND contextid IN (' . $contexts_array . ')'), $answer->answer, true);
                            } else {
                                $answer_txt = $this->files_from_db_img('question', 'answer', array('extra_sql' => ' AND itemid="' . $answer->id . '" AND contextid IN (' . $contexts_array . ')'), $answer->answer);
                            }
                            $corr = '';
                            $tab_quiz[$q->q_idq]['qanswers'][$answer->id] = 0;
                            if ($multi_tb->single == 1 && $answer->fraction >= 1) {
                                $corr = '<span style="color: blue;"><b>[X]</b></span> ';
                                $tab_quiz[$q->q_idq]['qanswers'][$answer->id] = 1;
                            }
                            if ($multi_tb->single == 0 && $answer->fraction > 0) {
                                $corr = '<span style="color: blue;"><b>[X]</b></span> ';
                                $tab_quiz[$q->q_idq]['qanswers'][$answer->id] = 1;
                            }
                            $NREQ = $corr . '<b>' . $nr_answer . '.</b> ' . $answer_txt;
                            $mpdf->WriteHTML($NREQ);
                            if ($generate_html_file) {
                                $html_contents .= $NREQ;
                            }
                            $tab_quiz[$q->q_idq]['answers'][$answer->id] = $answer_txt;
                            $nr_answer++;
                        }
                        break;
                    case 'shortanswerwiris':
                        $question_answer = $DB->get_records_sql('SELECT id,answer,fraction FROM {question_answers} WHERE question="' . $q->q_idq . '" ORDER BY id ASC');
                        $i = 0;
                        foreach ($question_answer as $id => $answer) {
                            $tab_quiz[$q->q_idq]['answers'][$i] = $answer->answer;
                            $tab_quiz[$q->q_idq]['fraction'][$i] = $answer->fraction;
                            $tab_quiz[$q->q_idq]['answers_id'][$id] = $i;
                            $i++;
                        }
                        $tab_quiz[$q->q_idq]['points'][0] = number_format($q->q_grade, $questiondecimalpoints, ".", "");
                        $NREQ = '<table border="0" style="width:100%;"><tr><td><b>' . $nr_question . '.</b></td><td style="text-align:right;">WIRIS - ' . get_string('pluginname', 'qtype_shortanswerwiris') . ' (' . $tab_quiz[$q->q_idq]['points'][0] . ' ' . get_string('points_short', 'quiz_nitroreportpdf') . ')</td></tr></table><br />' . $q_text;
                        $mpdf->WriteHTML($NREQ);
                        if ($generate_html_file) {
                            $html_contents .= $NREQ;
                        }
                        break;
                        // WIRIS QUESTIONS *** WIRIS QUESTIONS *** WIRIS QUESTIONS
                    // WIRIS QUESTIONS *** WIRIS QUESTIONS *** WIRIS QUESTIONS
                    case 'multichoiceset':
                        $answers = $DB->get_records_sql('SELECT id,answer,fraction FROM {question_answers} WHERE question="' . $q->q_idq . '" ORDER BY id ASC');
                        $answers_tab = '';
                        $answers_corr_tab = array();
                        $i = 1;
                        foreach ($answers as $answers) {
                            if ($generate_html_file) {
                                $answer = $this->files_from_db_img('question', 'question', array('extra_sql' => ' AND itemid="' . $answers->id . '" AND contextid IN (' . $contexts_array . ')'), $answers->answer, true);
                            } else {
                                $answer = $this->files_from_db_img('question', 'question', array('extra_sql' => ' AND itemid="' . $answers->id . '" AND contextid IN (' . $contexts_array . ')'), $answers->answer);
                            }
                            $tab_quiz[$q->q_idq]['answers'][$i - 1] = array('answer' => $answer, 'fraction' => $answers->fraction);
                            $tab_quiz[$q->q_idq]['answers_id'][$answers->id] = $i - 1;
                            $answers_tab .= '<b>' . $i . '.</b>';
                            if ($answers->fraction > 0) {
                                $answers_tab .= '<span style="color:blue;font-weight: bold;">[X]</span>';
                                $answers_corr_tab[] = $answers->id;
                            }
                            $answers_tab .= $answer . '<br><br>';
                            $i++;
                        }
                        //if are some file to process
                        $tab_quiz[$q->q_idq]['answers_corr_tab'] = $answers_corr_tab;
                        $NREQ = '<table border="0" style="width:100%;"><tr><td><b>' . $nr_question . '.</b></td><td style="text-align:right;">' . get_string('pluginname', 'qtype_multichoiceset') . ' (' . number_format($q->q_grade, $questiondecimalpoints, ".", "") . ' ' . get_string('points_short', 'quiz_nitroreportpdf') . ')</td></tr></table><br />' . $q_text . '<br /><br />' . $answers_tab . '<br />';
                        $mpdf->WriteHTML($NREQ);
                        if ($generate_html_file) {
                            $html_contents .= $NREQ;
                        }
                        $tab_quiz[$q->q_idq]['points'][] = number_format($q->q_grade, $questiondecimalpoints, ".", "");
                        break;
                    case 'calculatedsimple':
                        $numericalA = $DB->get_record_sql('SELECT showunits,unitsleft,unitgradingtype,unitpenalty FROM {question_numerical_options} WHERE question="' . $q->q_idq . '"');
                        $numericalB = $DB->get_records_sql('SELECT qa.id AS id,qa.answer AS answer, qa.fraction AS fraction, qc.tolerance AS tolerance,qc.tolerancetype AS tolerancetype, qc.correctanswerlength AS correctanswerlength, qc.correctanswerformat AS correctanswerformat FROM {question_answers} qa, {question_calculated} qc WHERE qa.question="' . $q->q_idq . '" AND qa.id=qc.answer AND qa.fraction>0 ORDER BY qa.id ASC');
                        $numericalC = $DB->get_records_sql('SELECT id,multiplier,unit FROM {question_numerical_units} WHERE question="' . $q->q_idq . '" ORDER BY id');
                        $options['showunits'] = $numericalA->showunits;
                        $options['unitsleft'] = $numericalA->unitsleft;
                        $options['unitgradingtype'] = $numericalA->unitgradingtype;
                        $options['unitpenalty'] = $numericalA->unitpenalty;
                        $tab_quiz[$q->q_idq]['options'] = $options;
                        $i = 0;
                        foreach ($numericalB as $answers) {
                            $tab_quiz[$q->q_idq]['answers'][$i]['answer'] = $answers->answer;
                            $tab_quiz[$q->q_idq]['answers'][$i]['fraction'] = $answers->fraction;
                            $tab_quiz[$q->q_idq]['answers'][$i]['tolerance'] = $answers->tolerance;
                            $tab_quiz[$q->q_idq]['answers'][$i]['tolerancetype'] = $answers->tolerancetype;
                            $tab_quiz[$q->q_idq]['answers'][$i]['correctanswerlength'] = $answers->correctanswerlength;
                            $tab_quiz[$q->q_idq]['answers'][$i]['correctanswerformat'] = $answers->correctanswerformat;
                            $tab_quiz[$q->q_idq]['answersid'][$answers->id] = $i;
                            $i++;
                        }
                        $i = 0;
                        foreach ($numericalC as $id => $unit) {
                            $tab_quiz[$q->q_idq]['units'][$i]['unit'] = $unit->answer;
                            $tab_quiz[$q->q_idq]['units'][$i]['multiplier'] = $unit->multiplier;
                            $i++;
                        }
                        $tab_quiz[$q->q_idq]['points'] = number_format($q->q_grade, $questiondecimalpoints, ".", "");
                        $NREQ = '<table border="0" style="width:100%;"><tr><td><b>' . $nr_question . '.</b></td><td style="text-align: right;">' . get_string('pluginname', 'qtype_calculatedsimple') . ' (' . number_format($q->q_grade, $questiondecimalpoints, ".", "") . ' ' . get_string('points_short', 'quiz_nitroreportpdf') . ')</td></tr></table><br />' . $q_text . '<br />';
                        $mpdf->WriteHTML($NREQ);
                        if ($generate_html_file) {
                            $html_contents .= $NREQ;
                        }
                        break;
                    default:
                        $tab_quiz[$q->q_idq]['points'][] = number_format($q->q_grade, $questiondecimalpoints, ".", "");
                        break;
                }
                $NREQ = '<hr noshade style="height:2px;color:black;" />';
                $mpdf->WriteHTML($NREQ);
                if ($generate_html_file) {
                    $html_contents .= $NREQ . '<hr noshade>';
                }
                $nr_question++;
            }
            // question while processing
            /*	4. Points for questions	*/
            $this->SetBarWidth(number_format(floor(4 * (100 / $PROGRESSBAR_PARTS)), 2, '.', ''));
            @ob_flush();
            @flush();
            $mpdf->AddPage();
            $mpdf->Bookmark('4. ' . get_string('pointsforquestion', 'quiz_nitroreportpdf'), 0);
            $NREQ = '<p style="text-align: center;font-weight: bold;font-size:14pt;text-transform:uppercase;">' . get_string('pointsforquestion', 'quiz_nitroreportpdf') . '</p><p></p>';
            $mpdf->WriteHTML($NREQ);
            if ($generate_html_file) {
                $html_contents .= $NREQ;
            }
            for ($i = 0; $i < count($tab_correct_answers); $i++) {
                if ($i % 2 == 1) {
                    $attach_style = ' class="table_td_highlight"';
                }
                $question_and_points .= '<tr' . $attach_style . '><td>' . ($i + 1) . '</td><td style="text-align: right;">' . $tab_correct_answers[$i] . '</td></tr>';
                unset($attach_style);
            }
            $NREQ = '
<table style="margin-left: auto; margin-right: auto;" class="table">
	<tr>
		<th>' . get_string('noquestion', 'quiz_nitroreportpdf') . '</th>
		<th>' . get_string('nopoints', 'quiz_nitroreportpdf') . '</th>
	</tr>
	' . $question_and_points . '
	<tr>
		<td><b>' . get_string('total', 'quiz_nitroreportpdf') . '</b></td>
		<td style="text-align: right;">' . number_format($info_quiz->sumgrades, $questiondecimalpoints, ".", "") . '</td>
	</tr>
</table>';
            $mpdf->WriteHTML($NREQ);
            if ($generate_html_file) {
                $html_contents .= $NREQ . '<hr noshade>';
            }
            if ($GENERATE_EXCEL) {
                $SheetCount = $objPHPExcel->getSheetCount();
                $objPHPExcel->createSheet(NULL, $SheetCount);
                $objPHPExcel->setActiveSheetIndex($SheetCount);
                $objPHPExcel->getActiveSheet()->setTitle(get_string('pointsforquestion', 'quiz_nitroreportpdf'));
                $objPHPExcel->getActiveSheet()->setCellValue('A1', get_string('noquestion', 'quiz_nitroreportpdf'))->setCellValue('B1', get_string('nopoints', 'quiz_nitroreportpdf'));
                $objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(19.83);
                for ($i = 0; $i < count($tab_correct_answers); $i++) {
                    $objPHPExcel->getActiveSheet()->getRowDimension(2 + $i)->setRowHeight(19.83);
                    $objPHPExcel->getActiveSheet()->setCellValue('A' . (2 + $i), $i + 1);
                    $objPHPExcel->getActiveSheet()->setCellValue('B' . (2 + $i), $tab_correct_answers[$i]);
                    $objPHPExcel->getActiveSheet()->getStyle('A' . ($i + 2))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
                    $objPHPExcel->getActiveSheet()->getStyle('B' . ($i + 2))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
                }
                for ($i = 0; $i < count($tab_correct_answers) + 1; $i++) {
                    if ($i % 2 == 0) {
                        $objPHPExcel->getActiveSheet()->getStyle('A' . ($i + 1) . ':B' . ($i + 1))->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
                        $objPHPExcel->getActiveSheet()->getStyle('A' . ($i + 1) . ':B' . ($i + 1))->getFill()->getStartColor()->setRGB('FFFFA1');
                    }
                }
                $objPHPExcel->getActiveSheet()->setCellValue('A' . $i, get_string('sum', 'quiz_nitroreportpdf'));
                $objPHPExcel->getActiveSheet()->setCellValue('B' . $i, number_format($info_quiz->sumgrades, $questiondecimalpoints, ".", ""));
                $objPHPExcel->getActiveSheet()->getRowDimension($i)->setRowHeight(19.83);
                $objPHPExcel->getActiveSheet()->getStyle('A' . $i . ':B' . $i)->getFont()->setBold(true);
                $objPHPExcel->getActiveSheet()->getStyle('A1:B1')->getFont()->setBold(true);
                $objPHPExcel->getActiveSheet()->getStyle('A1:B1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
                $objPHPExcel->getActiveSheet()->getStyle('A1:B1')->getFill()->getStartColor()->setRGB('0057AF');
                $objPHPExcel->getActiveSheet()->getStyle('A1:B1')->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_WHITE);
                $objPHPExcel->getActiveSheet()->getStyle('A1:B' . $i)->getFont()->setSize(14);
                $styleArray = array('borders' => array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array('rgb' => '000000'))));
                $objPHPExcel->getActiveSheet()->getStyle('A1:B' . $i)->applyFromArray($styleArray);
                $objPHPExcel->getActiveSheet()->getStyle('A1:B' . $i)->getAlignment()->setWrapText(false);
                $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setAutoSize(true);
                $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setAutoSize(true);
                $objPHPExcel->getActiveSheet()->getProtection()->setPassword(substr(hash('sha512', rand()), 0, 12));
                $objPHPExcel->getActiveSheet()->getProtection()->setSheet(true);
                $objPHPExcel->getActiveSheet()->getProtection()->setFormatCells(true);
                $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddFooter('&L&D, &T &R &P / &N');
            }
            /*	5. Quiz evaluation		*/
            $this->SetBarWidth(number_format(floor(5 * (100 / $PROGRESSBAR_PARTS)), 2, '.', ''));
            @ob_flush();
            @flush();
            $mpdf->AddPage();
            $mpdf->Bookmark('5. ' . get_string('evaluation', 'quiz_nitroreportpdf'), 0);
            $NREQ = '<p style="text-align: center;font-weight: bold;font-size:14pt;text-transform:uppercase;">' . get_string('evaluation', 'quiz_nitroreportpdf') . '</p>';
            $mpdf->WriteHTML($NREQ);
            if ($generate_html_file) {
                $html_contents .= $NREQ;
            }
            $quiz_feedback_corr = $DB->get_record_sql('SELECT id,maxgrade FROM {quiz_feedback} WHERE quizid="' . $quizid . '" ORDER BY id ASC LIMIT 0,1');
            $quiz_feedback = $DB->get_records_sql('SELECT id,feedbacktext,mingrade,maxgrade FROM {quiz_feedback} WHERE quizid="' . $quizid . '" ORDER BY id ASC');
            $quiz_count = count($quiz_feedback);
            $maxpoints = number_format($info_quiz->sumgrades, 4, ".", "");
            $tab_notes = array();
            $tab_notes2 = array();
            $minus = '0.';
            for ($i = 1; $i < $decimalpoints; $i++) {
                $minus .= '0';
            }
            $minus .= '1';
            $correction = number_format($quiz_feedback_corr->maxgrade / 100 - $minus, 4, '.', '');
            $i = 0;
            if ($quiz_count <= 0) {
                $NREQ = '<p style="text-align: center;">' . get_string('noschemgrade') . '</p>';
                $mpdf->WriteHTML($NREQ);
                if ($generate_html_file) {
                    $html_contents .= $NREQ;
                }
            } else {
                foreach ($quiz_feedback as $feedback) {
                    $feedback_text = $feedback->feedbacktext;
                    $tab_notes[$i]['mingrade_moodle'] = $feedback->mingrade;
                    $tab_notes[$i]['maxgrade_moodle'] = $feedback->maxgrade;
                    $tab_notes[$i]['mingrade_precent'] = number_format($feedback->mingrade / $correction + $minus, $decimalpoints, ".", "");
                    $tab_notes[$i]['maxgrade_precent'] = number_format($feedback->maxgrade / $correction, $decimalpoints, ".", "");
                    $tab_notes[$i]['mingrade_points'] = number_format($tab_notes[$i]['mingrade_precent'] / 100 * $maxpoints, 4, ".", "");
                    $tab_notes[$i]['maxgrade_points'] = number_format($tab_notes[$i]['maxgrade_precent'] / 100 * $maxpoints, 4, ".", "");
                    if ($i == 0) {
                        $tab_notes[$i]['maxgrade_precent'] = number_format(100, $decimalpoints, ".", "");
                        $tab_notes[$i]['maxgrade_points'] = number_format($maxpoints, 4, ".", "");
                    }
                    if ($i == count($quiz_feedback) - 1) {
                        $tab_notes[$i]['mingrade_precent'] = number_format(0, $decimalpoints, ".", "");
                        $tab_notes[$i]['mingrade_points'] = number_format(0, 4, ".", "");
                    }
                    if ($generate_html_file) {
                        $feedback_text = $this->files_from_db_img('mod_quiz', 'feedback', array('extra_sql' => ' AND itemid="' . $feedback->id . '" AND contextid IN (' . $contexts_array . ')'), $feedback_text, true);
                    } else {
                        $feedback_text = $this->files_from_db_img('mod_quiz', 'feedback', array('extra_sql' => ' AND itemid="' . $feedback->id . '" AND contextid IN (' . $contexts_array . ')'), $feedback_text);
                    }
                    $tab_notes[$i]['feedback'] = $feedback_text;
                    $i++;
                }
                // foreach feedback
                $tab_notes2 = $tab_notes;
                for ($i = 0; $i < count($tab_notes); $i++) {
                    if ($i % 2 == 1) {
                        $attach_style = ' class="table_td_highlight"';
                    }
                    $tab_notes_feedback .= '
			<tr' . $attach_style . '>
			<td>' . $tab_notes[$i]['mingrade_precent'] . '</td>
			<td>' . $tab_notes[$i]['maxgrade_precent'] . '</td>
			<td>' . $tab_notes[$i]['mingrade_points'] . '</td>
			<td>' . $tab_notes[$i]['maxgrade_points'] . '</td>
			<td>' . $tab_notes[$i]['feedback'] . '</td>
		</tr>';
                    unset($attach_style);
                }
                $tab_notes = '
	<table style="margin-left: auto; margin-right: auto;" class="table">
		<tr>
			<th colspan="2">' . get_string('percents', 'quiz_nitroreportpdf') . '</th>
			<th colspan="2">' . get_string('points', 'quiz_nitroreportpdf') . '</th>
			<th rowspan="2">' . get_string('grade', 'quiz_nitroreportpdf') . '</th>
		</tr>
		<tr>
			<th>' . get_string('from', 'quiz_nitroreportpdf') . '</th>
			<th>' . get_string('to', 'quiz_nitroreportpdf') . '</th>
			<th>' . get_string('from', 'quiz_nitroreportpdf') . '</th>
			<th>' . get_string('to', 'quiz_nitroreportpdf') . '</th>
		</tr>
		' . $tab_notes_feedback . '
	</table>';
                $mpdf->WriteHTML($tab_notes);
                if ($generate_html_file) {
                    $html_contents .= $tab_notes . '<hr noshade>';
                }
            }
            // $quiz_count if grades = 0
            if ($GENERATE_EXCEL) {
                $SheetCount = $objPHPExcel->getSheetCount();
                $objPHPExcel->createSheet(NULL, $SheetCount);
                $objPHPExcel->setActiveSheetIndex($SheetCount);
                $objPHPExcel->getActiveSheet()->setTitle(get_string('evaluation', 'quiz_nitroreportpdf'));
                $objPHPExcel->getActiveSheet()->setCellValue('A1', get_string('evaluation', 'quiz_nitroreportpdf'))->setCellValue('A2', get_string('percents', 'quiz_nitroreportpdf'))->setCellValue('C2', get_string('points', 'quiz_nitroreportpdf'))->setCellValue('A3', get_string('from', 'quiz_nitroreportpdf'))->setCellValue('B3', get_string('to', 'quiz_nitroreportpdf'))->setCellValue('C3', get_string('from', 'quiz_nitroreportpdf'))->setCellValue('D3', get_string('to', 'quiz_nitroreportpdf'))->setCellValue('E2', get_string('grade', 'quiz_nitroreportpdf'));
                $objPHPExcel->getActiveSheet()->mergeCells('A1:E1')->mergeCells('A2:B2')->mergeCells('C2:D2')->mergeCells('E2:E3');
                $objPHPExcel->getActiveSheet()->getStyle('A1:E3')->getFont()->setBold(true);
                for ($i = 0; $i < count($tab_notes2); $i++) {
                    $objPHPExcel->getActiveSheet()->setCellValue('A' . (4 + $i), $tab_notes2[$i]['mingrade_precent'])->setCellValue('B' . (4 + $i), $tab_notes2[$i]['maxgrade_precent'])->setCellValue('C' . (4 + $i), $tab_notes2[$i]['mingrade_points'])->setCellValue('D' . (4 + $i), $tab_notes2[$i]['maxgrade_points'])->setCellValue('E' . (4 + $i), strip_tags($tab_notes2[$i]['feedback']));
                    if ($i % 2 == 1) {
                        $objPHPExcel->getActiveSheet()->getStyle('A' . (4 + $i) . ':E' . (4 + $i))->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
                        $objPHPExcel->getActiveSheet()->getStyle('A' . (4 + $i) . ':E' . (4 + $i))->getFill()->getStartColor()->setRGB('FFFFA1');
                    }
                    $objPHPExcel->getActiveSheet()->getRowDimension(4 + $i)->setRowHeight(19.83);
                }
                $objPHPExcel->getActiveSheet()->getStyle('A1:E' . (4 + $i))->getFont()->setSize(14);
                $objPHPExcel->getActiveSheet()->getStyle('A1:E' . (4 + $i))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
                $objPHPExcel->getActiveSheet()->getStyle('E2')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
                $objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(19.83);
                $objPHPExcel->getActiveSheet()->getRowDimension(2)->setRowHeight(19.83);
                $objPHPExcel->getActiveSheet()->getRowDimension(3)->setRowHeight(19.83);
                $objPHPExcel->getActiveSheet()->getStyle('A1:E3')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
                $objPHPExcel->getActiveSheet()->getStyle('A1:E3')->getFill()->getStartColor()->setRGB('0057AF');
                $objPHPExcel->getActiveSheet()->getStyle('A1:E3')->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_WHITE);
                PHPExcel_Shared_Font::setAutoSizeMethod(PHPExcel_Shared_Font::AUTOSIZE_METHOD_EXACT);
                $objPHPExcel->getActiveSheet()->getStyle('A1:E' . (4 + $i))->getAlignment()->setWrapText(false);
                $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(-1);
                $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(-1);
                $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(-1);
                $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(-1);
                $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(-1);
                $styleArray = array('borders' => array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array('rgb' => '000000'))));
                $objPHPExcel->getActiveSheet()->getStyle('A1:E8')->applyFromArray($styleArray);
                $objPHPExcel->getActiveSheet()->getProtection()->setPassword(substr(hash('sha512', rand()), 0, 12));
                $objPHPExcel->getActiveSheet()->getProtection()->setSheet(true);
                $objPHPExcel->getActiveSheet()->getProtection()->setFormatCells(true);
                $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddFooter('&L&D, &T &R &P / &N');
            }
            /*	6. Quiz filled by exams		*/
            $this->SetBarWidth(number_format(floor(6 * (100 / $PROGRESSBAR_PARTS)), 2, '.', ''));
            @ob_flush();
            @flush();
            $mpdf->AddPage();
            $mpdf->Bookmark('6. ' . get_string('exam_tests', 'quiz_nitroreportpdf'), 0);
            $NREQ = '<p style="text-align: center;font-weight: bold;font-size:14pt;text-transform:uppercase;">' . get_string('exam_tests', 'quiz_nitroreportpdf') . '</p><p></p>';
            $mpdf->WriteHTML($NREQ);
            if ($generate_html_file) {
                $html_contents .= $NREQ;
            }
            $tab_users = array();
            /*	5. Get users who filled exam		*/
            $quiz_users = $DB->get_records_sql('SELECT DISTINCT(qa.userid) AS userid  FROM {quiz_attempts} qa,{user} u WHERE qa.quiz="' . $quizid . '" AND userid=u.id AND qa.state="finished" ORDER BY u.lastname ASC, u.firstname ASC, u.username ASC');
            if (count($quiz_users) == 0) {
                $progress_user = number_format(floor(7 * (100 / $PROGRESSBAR_PARTS)), 2, '.', '');
            } else {
                $progress_user = number_format(floor(7 * (100 / $PROGRESSBAR_PARTS) / count($quiz_users)), 2, '.', '');
            }
            $user_i = 1;
            foreach ($quiz_users as $users) {
                $this->SetBarWidth($progress_user * $user_i);
                @ob_flush();
                @flush();
                $get_info_user = $this->nitro_get_user($users->userid);
                $mpdf->Bookmark('6.' . $user_i . '. ' . get_string('examined', 'quiz_nitroreportpdf') . ': ' . $get_info_user->firstname . ' ' . $get_info_user->lastname, 1);
                $createaccount = $get_info_user->timecreated > 0 ? date('d.m.Y H:i', $get_info_user->timecreated) : '-----';
                $lastlogin = $get_info_user->lastlogin > 0 ? date('d.m.Y H:i', $get_info_user->lastlogin) : '-----';
                $tab_users[$users->userid]['uid'] = $users->userid;
                $tab_users[$users->userid]['name'] = $get_info_user->firstname;
                $tab_users[$users->userid]['surname'] = $get_info_user->lastname;
                $tab_users[$users->userid]['email'] = $get_info_user->email;
                $tab_users[$users->userid]['username'] = $get_info_user->username;
                $user_photo = $CFG->dirroot . '/mod/quiz/report/nitroreportpdf/nophoto.png';
                if ($get_info_user->picture > 0) {
                    $filex = $DB->get_record_sql('SELECT contextid,itemid,filepath,filename FROM {files} WHERE id="' . $get_info_user->picture . '" AND filename<>"."');
                    $fs = null;
                    $file = null;
                    $fs = get_file_storage();
                    $file = $fs->get_file($filex->contextid, 'user', 'icon', $filex->itemid, $filex->filepath, $filex->filename);
                    $tempfilename = '_U' . $userid . '_Q' . $quizid . '_' . strtotime('now') . uniqid() . uniqid() . $ffile;
                    if ($file) {
                        $file->copy_content_to($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $tempfilename);
                        $user_photo = $CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $tempfilename;
                    }
                    // file
                }
                // photo
                switch ($info_quiz->grademethod) {
                    case '2':
                        $grademethod_sql = $DB->get_records_sql('SELECT uniqueid,timestart,timefinish,sumgrades FROM {quiz_attempts} WHERE quiz="' . $quizid . '" AND userid="' . $users->userid . '" AND state="finished" ORDER BY id ASC');
                        break;
                    case '3':
                        $grademethod_sql = $DB->get_record_sql('SELECT uniqueid,timestart,timefinish,sumgrades FROM {quiz_attempts} WHERE quiz="' . $quizid . '" AND userid="' . $users->userid . '" AND state="finished" ORDER BY id ASC LIMIT 0,1');
                        break;
                    case '4':
                        $grademethod_sql = $DB->get_record_sql('SELECT uniqueid,timestart,timefinish,sumgrades FROM {quiz_attempts} WHERE quiz="' . $quizid . '" AND userid="' . $users->userid . '" AND state="finished" ORDER BY id DESC LIMIT 0,1');
                        break;
                    default:
                        $grademethod_sql = $DB->get_records_sql('SELECT id,sumgrades FROM {quiz_attempts} WHERE quiz="' . $quizid . '" AND userid="' . $users->userid . '" AND state="finished"');
                        $max_id = -1;
                        $max_sumgrades = -1;
                        foreach ($grademethod_sql as $grademethod) {
                            if ($max_id == -1) {
                                $max_id = $grademethod->id;
                                $max_sumgrades = $grademethod->sumgrades;
                            }
                            if ($grademethod->sumgrades >= $max_sumgrades) {
                                $max_id = $grademethod->id;
                                $max_sumgrades = $grademethod->sumgrades;
                            }
                        }
                        $grademethod_sql = $DB->get_record_sql('SELECT uniqueid,timestart,timefinish,sumgrades FROM {quiz_attempts} WHERE id="' . $max_id . '" AND state="finished"');
                        break;
                }
                $NREQ = '<br /><table style="margin-left: auto; margin-right: auto;" class="table">
		<tr>
			<th>' . get_string('name', 'quiz_nitroreportpdf') . ':</th>
			<td>' . $get_info_user->firstname . '</td>
			<td rowspan="8" style="vertical-align: middle;text-align: center;"><img src="' . $user_photo . '" /></td>
		</tr>
		<tr>
			<th>' . get_string('surname', 'quiz_nitroreportpdf') . ':</th>
			<td>' . $get_info_user->lastname . '</td>
		</tr>
		<tr>
			<th>' . get_string('username', 'quiz_nitroreportpdf') . ':</th>
			<td>' . $get_info_user->username . '</td>
		</tr>
		<tr>
			<th>' . get_string('email', 'quiz_nitroreportpdf') . ':</th>
			<td>' . $get_info_user->email . '</td>
		</tr>
		<tr>
			<th>' . get_string('institution', 'quiz_nitroreportpdf') . ':</th>
			<td>' . $get_info_user->institution . '</td>
		</tr>
		<tr>
			<th>' . get_string('department', 'quiz_nitroreportpdf') . ':</th>
			<td>' . $get_info_user->department . '</td>
		</tr>
		<tr>
			<th>' . get_string('accountcreated', 'quiz_nitroreportpdf') . ':</th>
			<td>' . $createaccount . '</td>
		</tr>
		<tr>
			<th>' . get_string('lastlogin', 'quiz_nitroreportpdf') . ':</th>
			<td>' . $lastlogin . '</td>
		</tr>
	</table>
	<br /><br />';
                $mpdf->WriteHTML($NREQ);
                if ($generate_html_file) {
                    $html_contents .= $NREQ;
                }
                $nb_question = 1;
                foreach ($tab_quiz as $tq) {
                    $mpdf->Bookmark('6.1. ' . get_string('question_upper', 'quiz_nitroreportpdf') . ' ' . $nb_question, 2);
                    switch ($tq['type']) {
                        case 'truefalse':
                            $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format(0, $questiondecimalpoints, ".", "");
                            $xxx1 = $DB->get_record_sql('SELECT qasd.id AS id, qasd.value AS value FROM  {question_attempts} qa,{question_attempt_steps} qas, {question_attempt_step_data} qasd WHERE qa.questionusageid="' . $grademethod_sql->uniqueid . '" AND qa.questionid="' . $tq['qid'] . '" AND qas.questionattemptid=qa.id AND qas.sequencenumber="1" AND qas.id=qasd.attemptstepid AND name="answer" ORDER BY qas.id ASC');
                            $tab_users[$users->userid]['answers'][$tq['qid']]['answer'][0] = $xxx1->value;
                            $user_answer = trim($xxx1->value);
                            $answer = '';
                            $answer = $user_answer == 1 ? $tf_sql_true->answer : $tf_sql_false->answer;
                            $anscolor = '';
                            if ($user_answer == "") {
                                $anscolor = '<span style="color:red;font-weight: bold;">' . get_string('noanswer', 'quiz_nitroreportpdf') . '</span>';
                            } elseif ($user_answer == $tq['answers'][0]) {
                                $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format($tq['points'][0], $questiondecimalpoints, ".", "");
                                $tab_users[$users->userid]['answers'][$tq['qid']]['answer'][0] = $user_answer;
                                $anscolor = '<span style="color:blue;font-weight: bold;">' . $answer . '</span>';
                            } else {
                                $anscolor = '<span style="color:red;font-weight: bold;">' . $answer . '</span>';
                            }
                            $NREQ = '<table border="0" style="width:100%;"><tr><td><b>' . $nb_question . '.</b></td><td style="text-align:right;">' . get_string('pluginname', 'qtype_truefalse') . '</td></tr></table><br />' . $tq['question'] . '<br /><u>' . get_string('answered', 'quiz_nitroreportpdf') . ':</u> ' . $anscolor . '<br /><br />
				<table style="margin-left: auto; margin-right: auto;" class="table">
					<tr>
						<th style="font-size: 10pt;">' . get_string('points_available', 'quiz_nitroreportpdf') . '</th>
						<th style="font-size: 10pt;">' . get_string('gained_points', 'quiz_nitroreportpdf') . '</th>
					</tr>
					<tr>
						<td style="text-align: center;font-size: 10pt;">' . $tq['points'][0] . '</td>
						<td style="text-align: center;font-size: 10pt;">' . $tab_users[$users->userid]['attempt'][$tq['qid']] . '</td>
					</tr>
				</table>';
                            $mpdf->WriteHTML($NREQ);
                            if ($generate_html_file) {
                                $html_contents .= $NREQ;
                            }
                            break;
                        case 'numerical':
                            $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format(0, $questiondecimalpoints, ".", "");
                            $xxx1 = $DB->get_records_sql('SELECT qas.id AS id FROM {question_attempts} qa, {question_attempt_steps} qas WHERE qa.questionusageid="' . $grademethod_sql->uniqueid . '" AND qa.questionid="' . $tq['qid'] . '" AND qas.questionattemptid=qa.id AND qas.sequencenumber IN (1) ORDER BY qas.id ASC');
                            $xxx2 = array_keys($xxx1);
                            $xxx_resp = $DB->get_record_sql('SELECT id,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[0] . '" AND name="answer"');
                            preg_match('/([0-9.]+)(.*)/', $xxx_resp->value, $m1);
                            $ans_number = trim($m1[1]);
                            $ans_unit = trim($m1[2]);
                            $ans = $ans_number;
                            $xanso = '<span style="color:red;font-weight: bold;">' . $xxx_resp->value . '</span>';
                            if (!empty($ans_unit)) {
                                $ans .= '|' . $ans_unit;
                            }
                            for ($i = 0; $i < count($tq['answers']); $i++) {
                                if (preg_match('/-/', $tq['answers'][$i])) {
                                    $tq_unit = '';
                                    $tq_range = $tq['answers'][$i];
                                    if (preg_match('/\\|/', $tq['answers'][$i])) {
                                        $tq_unit = substr($tq['answers'][$i], strpos($tq['answers'][$i], '|') + 1);
                                        $tq_range = substr($tq['answers'][$i], 0, -count($tq_unit) - 2);
                                    }
                                    $e = explode('-', $tq_range);
                                    if ($ans_number >= $e[0] && $ans_number <= $e[1] && $ans_unit == $tq_unit) {
                                        $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format($tq['points'][$i], $questiondecimalpoints, ".", "");
                                        $xanso = '<span style="color:blue;font-weight: bold;">' . $xxx_resp->value . '</span>';
                                        break;
                                    }
                                } else {
                                    if ($ans == $tq['answers'][$i]) {
                                        $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format($tq['points'][$i], $questiondecimalpoints, ".", "");
                                        $xanso = '<span style="color:blue;font-weight: bold;">' . $xxx_resp->value . '</span>';
                                        break;
                                    }
                                }
                            }
                            if (empty($xxx_resp->value)) {
                                $xanso = '<span style="color:red;font-weight: bold;">' . get_string('noanswer', 'quiz_nitroreportpdf') . '</span>';
                            }
                            $NREQ = '<table border="0" style="width:100%;"><tr><td><b>' . $nb_question . '.</b></td><td style="text-align:right;">' . get_string('pluginname', 'qtype_numerical') . '</td></tr></table><br />' . $tq['question'] . '<br /><u>' . get_string('answered', 'quiz_nitroreportpdf') . ':</u> ' . $xanso . '</span><br /><br />
				<table style="margin-left: auto; margin-right: auto;" class="table">
					<tr>
						<th style="font-size: 10pt;">' . get_string('points_available', 'quiz_nitroreportpdf') . '</th>
						<th style="font-size: 10pt;">' . get_string('gained_points', 'quiz_nitroreportpdf') . '</th>
					</tr>
					<tr>
						<td style="text-align: center;font-size: 10pt;">' . max($tq['points']) . '</td>
						<td style="text-align: center;font-size: 10pt;">' . $tab_users[$users->userid]['attempt'][$tq['qid']] . '</td>
					</tr>
				</table>';
                            $mpdf->WriteHTML($NREQ);
                            if ($generate_html_file) {
                                $html_contents .= $NREQ;
                            }
                            break;
                        case 'gapselect':
                            $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format(0, $questiondecimalpoints, ".", "");
                            $xxx1 = $DB->get_records_sql('SELECT qas.id AS id FROM {question_attempts} qa, {question_attempt_steps} qas WHERE qa.questionusageid="' . $grademethod_sql->uniqueid . '" AND qa.questionid="' . $tq['qid'] . '" AND qas.questionattemptid=qa.id AND qas.sequencenumber IN (0,1) ORDER BY qas.id ASC');
                            $xxx2 = array_keys($xxx1);
                            $xxx_questions = $DB->get_record_sql('SELECT id,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[0] . '" AND name LIKE "_choiceorder%"');
                            $xxx_answers_orders = $DB->get_records_sql('SELECT id,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[1] . '" AND name LIKE "p%" ORDER BY id ASC');
                            $ttab1 = null;
                            $ttab1 = explode(',', $xxx_questions->value);
                            $question = $tq['question'];
                            $ttab2 = null;
                            foreach ($xxx_answers_orders as $xao) {
                                $ttab2[] = $xao->value;
                            }
                            $selected = 0;
                            for ($z = 0; $z < count($ttab1); $z++) {
                                if ($ttab2[$z] - 1 < 0) {
                                    $question = preg_replace('/\\[\\[' . ($z + 1) . '\\]\\]/', '<span style="color:red;font-weight: bold;">___</span>', $question);
                                } elseif ($ttab1[$ttab2[$z] - 1] == $tq['answers'][$z]) {
                                    $question = preg_replace('/\\[\\[' . ($z + 1) . '\\]\\]/', '<span style="color:blue;font-weight: bold;">' . $tq['choices'][$ttab1[$ttab2[$z] - 1] - 1] . '</span>', $question);
                                    $selected++;
                                } else {
                                    $question = preg_replace('/\\[\\[' . ($z + 1) . '\\]\\]/', '<span style="color:red;font-weight: bold;">' . $tq['choices'][$ttab1[$ttab2[$z] - 1] - 1] . '</span>', $question);
                                }
                            }
                            if ($MODE_NOTE == 1) {
                                if (count(array_diff($tq['answers'], $ttab2)) == 0) {
                                    $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format($tq['points'][0], $questiondecimalpoints, ".", "");
                                }
                            } else {
                                $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format($tq['points'][0] * $selected / count($tq['answers']), $questiondecimalpoints, ".", "");
                            }
                            $NREQ = '
				<table border="0" style="width:100%;"><tr><td><b>' . $nb_question . '.</b></td><td style="text-align:right;">' . get_string('pluginname', 'qtype_gapselect') . '</td></tr></table><br />' . $question . '<br /><br />
				<table style="margin-left: auto; margin-right: auto;" class="table">
				<tr>
				<th style="font-size: 10pt;">' . get_string('points_available', 'quiz_nitroreportpdf') . '</th>
				<th style="font-size: 10pt;">' . get_string('gained_points', 'quiz_nitroreportpdf') . '</th>
				</tr>
				<tr>
				<td style="text-align: center;font-size: 10pt;">' . $tq['points'][0] . '</td>
				<td style="text-align: center;font-size: 10pt;">' . $tab_users[$users->userid]['attempt'][$tq['qid']] . '</td>
				</tr>
				</table>';
                            $mpdf->WriteHTML($NREQ);
                            if ($generate_html_file) {
                                $html_contents .= $NREQ;
                            }
                            break;
                        case 'ddimageortext':
                            $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format(0, $questiondecimalpoints, ".", "");
                            $xxx1 = $DB->get_records_sql('SELECT qas.id AS id FROM {question_attempts} qa, {question_attempt_steps} qas WHERE qa.questionusageid="' . $grademethod_sql->uniqueid . '" AND qa.questionid="' . $tq['qid'] . '" AND qas.questionattemptid=qa.id AND qas.sequencenumber IN (0,1) ORDER BY qas.id ASC');
                            $xxx2 = array_keys($xxx1);
                            $xxx_questions = $DB->get_record_sql('SELECT id,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[0] . '" AND name LIKE "_choiceorder%"');
                            $xxx_answers_orders = $DB->get_records_sql('SELECT id,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[1] . '" AND name LIKE "p%" ORDER BY id ASC');
                            $ttab1 = null;
                            $ttab1 = explode(',', $xxx_questions->value);
                            $question = $tq['question'];
                            $ttab2 = null;
                            $data = null;
                            $tab_text = array();
                            $tab_image = array();
                            $data['ddimageortext_bigfile'] = $tq['ddimageortext_bigfile'];
                            foreach ($xxx_answers_orders as $xao) {
                                $ttab2[] = $xao->value;
                            }
                            $selected = 0;
                            for ($z = 0; $z < count($ttab1); $z++) {
                                if ($ttab2[$z] - 1 < 0) {
                                    $tab_text[] = array('x' => $tq['answers'][$ttab1[$ttab2[$z] - 1] - 1]['x'], 'y' => $tq['answers'][$ttab1[$ttab2[$z] - 1] - 1]['y'], 'text' => 'XXXXX');
                                } elseif ($ttab1[$ttab2[$z] - 1] == $tq['answers'][$z]['choice']) {
                                    if ($tq['answers'][$ttab1[$ttab2[$z] - 1] - 1]['type'] == "text") {
                                        $tab_text[] = array('x' => $tq['answers'][$ttab1[$ttab2[$z] - 1] - 1]['x'], 'y' => $tq['answers'][$ttab1[$ttab2[$z] - 1] - 1]['y'], 'text' => $tq['answers'][$ttab1[$ttab2[$z] - 1] - 1]['lab_img']);
                                    } else {
                                        $tab_image[] = array('x' => $tq['answers'][$ttab1[$ttab2[$z] - 1] - 1]['x'], 'y' => $tq['answers'][$ttab1[$ttab2[$z] - 1] - 1]['y'], 'filename' => $tq['answers'][$ttab1[$ttab2[$z] - 1] - 1]['lab_img']);
                                    }
                                    $selected++;
                                } else {
                                    $tab_text[] = array('x' => $tq['answers'][$ttab1[$ttab2[$z] - 1] - 1]['x'], 'y' => $tq['answers'][$ttab1[$ttab2[$z] - 1] - 1]['y'], 'text' => 'XXXXX');
                                }
                            }
                            if ($MODE_NOTE == 1) {
                                if (count(array_diff($tq['answers'], $ttab2)) == 0) {
                                    $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format($tq['points'][0], $questiondecimalpoints, ".", "");
                                }
                            } else {
                                $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format($tq['points'][0] * $selected / count($tq['answers']), $questiondecimalpoints, ".", "");
                            }
                            $data['texts'] = json_encode($tab_text);
                            $data['images'] = json_encode($tab_image);
                            $data['filename'] = '_U' . $userid . '_Q' . $quizid . '_' . strtotime('now') . uniqid() . uniqid() . '.jpg';
                            $ch = curl_init();
                            curl_setopt($ch, CURLOPT_URL, $CFG->wwwroot . '/mod/quiz/report/nitroreportpdf/image.php');
                            curl_setopt($ch, CURLOPT_HEADER, 0);
                            curl_setopt($ch, CURLOPT_POST, 1);
                            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
                            curl_setopt($ch, CURLOPT_TIMEOUT, 60);
                            curl_exec($ch);
                            curl_close($ch);
                            $NREQ = '
				<table border="0" style="width:100%;"><tr><td><b>' . $nb_question . '.</b></td><td style="text-align:right;">' . get_string('pluginname', 'qtype_ddimageortext') . '</td></tr></table><br />' . $tq['question'] . '<br /><img src="report/nitroreportpdf/cache/' . $data['filename'] . '" /><br /><br />
				<table style="margin-left: auto; margin-right: auto;" class="table">
				<tr>
					<th style="font-size: 10pt;">' . get_string('points_available', 'quiz_nitroreportpdf') . '</th>
					<th style="font-size: 10pt;">' . get_string('gained_points', 'quiz_nitroreportpdf') . '</th>
				</tr>
				<tr>
					<td style="text-align: center;font-size: 10pt;">' . $tq['points'][0] . '</td>
					<td style="text-align: center;font-size: 10pt;">' . $tab_users[$users->userid]['attempt'][$tq['qid']] . '</td>
				</tr>
				</table>';
                            $mpdf->WriteHTML($NREQ);
                            if ($generate_html_file) {
                                $html_contents .= $NREQ;
                            }
                            break;
                        case 'multichoice':
                            $tab_users[$users->userid]['attempt'][$tq['qid']] = 0;
                            $multi_tb = $DB->get_record_sql('SELECT single FROM {qtype_multichoice_options} WHERE questionid="' . $tq['qid'] . '"');
                            $xxx1 = $DB->get_records_sql('SELECT qas.id AS id FROM {question_attempts} qa, {question_attempt_steps} qas WHERE qa.questionusageid="' . $grademethod_sql->uniqueid . '" AND qa.questionid="' . $tq['qid'] . '" AND qas.questionattemptid=qa.id AND qas.sequencenumber IN (0,1) ORDER BY qas.id ASC');
                            $xxx2 = array_keys($xxx1);
                            $xxx3_tab_bin = array();
                            $count_corrected = 0;
                            foreach ($tq['qanswers'] as $id => $a) {
                                if ($a == 1) {
                                    $count_corrected++;
                                }
                            }
                            if ($multi_tb->single == 1) {
                                $questiontypemultichoice = get_string('questiontypemultichoiceone', 'quiz_nitroreportpdf');
                                $xxx3 = $DB->get_record_sql('SELECT id,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[0] . '" AND name="_order"');
                                $xxx4 = $DB->get_record_sql('SELECT id,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[1] . '" AND name="answer"');
                                $xxx3_u = $xxx3->value;
                                ///contains user's answers in binary format . this table must be sorting by id
                                $xxx3_tab = explode(',', $xxx3_u);
                                if (!is_object($xxx4)) {
                                    $xxx4 = new StdClass();
                                    $xxx4->id = -1;
                                    $xxx4->value = -1;
                                }
                                for ($z = 0; $z < count($xxx3_tab); $z++) {
                                    //specify place in options
                                    if ($z == $xxx4->value) {
                                        $xxx3_tab_bin[$xxx3_tab[$z]] = 1;
                                    } else {
                                        $xxx3_tab_bin[$xxx3_tab[$z]] = 0;
                                    }
                                }
                                if (!isset($xxx4->value)) {
                                    $xxx4->value = -1;
                                }
                                for ($z = 0; $z < count($xxx3_tab); $z++) {
                                    //specify place in options
                                    if ($z == $xxx4->value) {
                                        $xxx3_tab_bin[$xxx3_tab[$z]] = 1;
                                    } else {
                                        $xxx3_tab_bin[$xxx3_tab[$z]] = 0;
                                    }
                                }
                                $xxx3_tab_bin_ids = $this->quick_sort(array_keys($xxx3_tab_bin));
                                $xxx3_tab_bin2 = array();
                                for ($z = 0; $z < count($xxx3_tab_bin_ids); $z++) {
                                    $xxx3_tab_bin2[$xxx3_tab_bin_ids[$z]] = $xxx3_tab_bin[$xxx3_tab_bin_ids[$z]];
                                }
                                $xxx3_tab_bin = $xxx3_tab_bin2;
                                $corrected = 0;
                                $user_asked = '';
                                $odp = 0;
                                foreach ($xxx3_tab_bin as $id => $bin) {
                                    $multiple = $bin * $tq[qanswers][$id];
                                    if ($multiple == 1) {
                                        $corrected++;
                                    }
                                    if ($bin == 1 && $bin != $tq[qanswers][$id]) {
                                        $user_asked .= '<span style="color: red;"><b>[X]</b></span> ';
                                    } elseif ($bin == 1 && $bin == $tq[qanswers][$id]) {
                                        $user_asked .= '<span style="color: blue;"><b>[X]</b></span> ';
                                    }
                                    $user_asked .= '<b>' . chr(65 + $odp) . ".</b> &nbsp;";
                                    $user_asked .= $tq[answers][$id] . '<br />';
                                    $odp++;
                                }
                                $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format($tq['points'][0] * $corrected / $count_corrected, $questiondecimalpoints, ".", "");
                            } elseif ($multi_tb->single == 0 && count($xxx2) > 0) {
                                $questiontypemultichoice = get_string('questiontypemultichoicemulti', 'quiz_nitroreportpdf');
                                $xxx3 = $DB->get_record_sql('SELECT id,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[0] . '" AND name="_order"');
                                $xxx4 = $DB->get_records_sql('SELECT id,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[1] . '" AND name LIKE "choice%" ORDER BY name ASC');
                                $xxx3_u = $xxx3->value;
                                $xxx3_tab = explode(',', $xxx3_u);
                                $xxx4_tab_bin = array();
                                $xxx4_ids = array_keys($xxx4);
                                for ($z = 0; $z < count($xxx4_ids); $z++) {
                                    $xxx4_tab_bin[] = $xxx4[$xxx4_ids[$z]]->value;
                                }
                                $xxx4_tab_bin_temp = array();
                                if (count($xxx4) == 0) {
                                    for ($y = 0; $y < count($tq['qanswers']); $y++) {
                                        $xxx4_tab_bin[] = 0;
                                    }
                                }
                                for ($z = 0; $z < count($xxx3_tab); $z++) {
                                    $xxx4_tab_bin_temp[$xxx3_tab[$z]] = $xxx4_tab_bin[$z];
                                }
                                $xxx4_tab_bin_temp_ids = $this->quick_sort(array_keys($xxx4_tab_bin_temp));
                                $xxx4_tab_bin_temp2 = array();
                                for ($z = 0; $z < count($xxx4_tab_bin_temp_ids); $z++) {
                                    $xxx4_tab_bin_temp2[$xxx4_tab_bin_temp_ids[$z]] = $xxx4_tab_bin_temp[$xxx4_tab_bin_temp_ids[$z]];
                                }
                                $xxx3_tab_bin = $xxx4_tab_bin_temp2;
                                unset($xxx4_tab_bin_temp2);
                                $corrected = 0;
                                $user_asked = '';
                                $odp = 0;
                                foreach ($xxx3_tab_bin as $id => $bin) {
                                    $multiple = $bin * $tq[qanswers][$id];
                                    if ($multiple == 1) {
                                        $corrected++;
                                    }
                                    if ($bin == 1 && $bin != $tq[qanswers][$id]) {
                                        $user_asked .= '<span style="color: red;"><b>[X]</b></span> ';
                                    } elseif ($bin == 1 && $bin == $tq[qanswers][$id]) {
                                        $user_asked .= '<span style="color: blue;"><b>[X]</b></span> ';
                                    }
                                    $user_asked .= '<b>' . chr(65 + $odp) . ".</b> &nbsp;";
                                    $user_asked .= $tq[answers][$id] . '<br />';
                                    $odp++;
                                }
                            }
                            if ($MODE_NOTE == 1) {
                                if ($corrected == $count_corrected) {
                                    $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format($tq['points'][0], $questiondecimalpoints, ".", "");
                                }
                            } else {
                                $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format($tq['points'][0] * $corrected / $count_corrected, $questiondecimalpoints, ".", "");
                            }
                            $NREQ = '<table border="0" style="width:100%;"><tr><td><b>' . $nb_question . '.</b></td><td style="text-align:right;">' . $questiontypemultichoice . '</td></tr></table><br />' . $tq['question'] . '<br /><br />' . $user_asked . '<br />
				<table style="margin-left: auto; margin-right: auto;" class="table">
				<tr>
				<th style="font-size: 10pt;">' . get_string('points_available', 'quiz_nitroreportpdf') . '</th>
				<th style="font-size: 10pt;">' . get_string('gained_points', 'quiz_nitroreportpdf') . '</th>
				</tr>
				<tr>
				<td style="text-align: center;font-size: 10pt;">' . $tq['points'][0] . '</td>
				<td style="text-align: center;font-size: 10pt;">' . $tab_users[$users->userid]['attempt'][$tq['qid']] . '</td>
				</tr>
				</table>';
                            $mpdf->WriteHTML($NREQ);
                            if ($generate_html_file) {
                                $html_contents .= $NREQ;
                            }
                            break;
                        case 'multianswer':
                            $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format(0, $questiondecimalpoints, ".", "");
                            $points = 0;
                            $question = $tq['question'];
                            $xxx1 = $DB->get_records_sql('SELECT qas.id AS id FROM {question_attempts} qa, {question_attempt_steps} qas WHERE qa.questionusageid="' . $grademethod_sql->uniqueid . '" AND qa.questionid="' . $tq['qid'] . '" AND qas.questionattemptid=qa.id AND qas.sequencenumber IN (0,1) ORDER BY qas.id ASC');
                            $xxx2 = array_keys($xxx1);
                            $xxx_questions = $DB->get_records_sql('SELECT id,name,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[0] . '" AND name LIKE "_sub%_order"');
                            foreach ($xxx_questions as $id => $questions) {
                                preg_match('/_sub(.*)_order/', $questions->name, $number_question_db);
                                $number_question_db = $number_question_db[1];
                                $xxx_resp_exist = $DB->get_record_sql('SELECT count(*) as how FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[1] . '" AND name="sub' . $number_question_db . '_answer"');
                                if ($xxx_resp_exist->how > 0) {
                                    $xxx_resp = $DB->get_record_sql('SELECT id,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[1] . '" AND name="sub' . $number_question_db . '_answer"');
                                    $ttab1 = null;
                                    $ttab1 = explode(',', $questions->value);
                                    $index = $ttab1[$xxx_resp->value];
                                    $index2 = $tq['answers'][$number_question_db - 1]['answers_id'][$index];
                                    if ($index2 == $tq['answers'][$number_question_db - 1]['correct']) {
                                        $question = preg_replace('/\\{#' . $number_question_db . '\\}/', '<span style="color:green;font-weight: bold;">' . $tq['answers'][$number_question_db - 1]['answers'][$index2] . '</span>', $question);
                                        $points += $tq['answers'][$number_question_db - 1]['points'][$index2];
                                    } else {
                                        $question = preg_replace('/\\{#' . $number_question_db . '\\}/', '<span style="color:red;font-weight: bold;">' . $tq['answers'][$number_question_db - 1]['answers'][$index2] . '</span>', $question);
                                        $points += $tq['answers'][$number_question_db - 1]['points'][$index2];
                                    }
                                } else {
                                    $question = preg_replace('/\\{#' . $number_question_db . '\\}/', '<span style="color:red;font-weight: bold;">___</span>', $question);
                                }
                            }
                            preg_match_all('/\\{#([0-9]+)\\}/', $question, $rest);
                            if (count($rest[1]) > 0) {
                                for ($i = 0; $i < count($rest[1]); $i++) {
                                    $xxx_resp = $DB->get_record_sql('SELECT id,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[1] . '" AND name="sub' . $rest[1][$i] . '_answer"');
                                    for ($j = 0; $j < count($tq['answers'][$rest[1][$i] - 1]['answers']); $j++) {
                                        if ($tq['answers'][$rest[1][$i] - 1]['type'][$j] == 'range') {
                                            $ex = explode('-', $tq['answers'][$rest[1][$i] - 1]['answers'][$j]);
                                            if ($xxx_resp->value >= $ex[0] && $xxx_resp->value <= $ex[1]) {
                                                $points += $tq['answers'][$rest[1][$i] - 1]['points'][$j];
                                                if ($tq['answers'][$rest[1][$i] - 1]['points'][$j] == 0) {
                                                    $question = preg_replace('/\\{#' . $rest[1][$i] . '\\}/', '<span style="color:red;font-weight: bold;">' . $xxx_resp->value . '</span>', $question);
                                                    break;
                                                } else {
                                                    $question = preg_replace('/\\{#' . $rest[1][$i] . '\\}/', '<span style="color:blue;font-weight: bold;">' . $xxx_resp->value . '</span>', $question);
                                                    break;
                                                }
                                            } else {
                                                $question = preg_replace('/\\{#' . $rest[1][$i] . '\\}/', '<span style="color:red;font-weight: bold;">' . $xxx_resp->value . '</span>', $question);
                                            }
                                        } else {
                                            $points += $tq['answers'][$rest[1][$i] - 1]['points'][$j];
                                            if ($xxx_resp->value == $tq['answers'][$rest[1][$i] - 1]['answers'][$j]) {
                                                $question = preg_replace('/\\{#' . $rest[1][$i] . '\\}/', '<span style="color:green;font-weight: bold;">' . $xxx_resp->value . '</span>', $question);
                                                break;
                                            } else {
                                                $question = preg_replace('/\\{#' . $rest[1][$i] . '\\}/', '<span style="color:red;font-weight: bold;">' . $xxx_resp->value . '</span>', $question);
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                            $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format($points, $questiondecimalpoints, ".", "");
                            $NREQ = '
				<table border="0" style="width:100%;"><tr><td><b>' . $nb_question . '.</b></td><td style="text-align:right;">' . get_string('pluginname', 'qtype_multianswer') . '</td></tr></table><br />' . $question . '<br /><br />
				<table style="margin-left: auto; margin-right: auto;" class="table">
					<tr>
						<th style="font-size: 10pt;">' . get_string('points_available', 'quiz_nitroreportpdf') . '</th>
						<th style="font-size: 10pt;">' . get_string('gained_points', 'quiz_nitroreportpdf') . '</th>
					</tr>
					<tr>
						<td style="text-align: center;font-size: 10pt;">' . $tq['points'][0] . '</td>
						<td style="text-align: center;font-size: 10pt;">' . $tab_users[$users->userid]['attempt'][$tq['qid']] . '</td>
					</tr>
				</table>';
                            $mpdf->WriteHTML($NREQ);
                            if ($generate_html_file) {
                                $html_contents .= $NREQ;
                            }
                            break;
                        case 'ddwtos':
                            $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format(0, $questiondecimalpoints, ".", "");
                            $question = $tq['question'];
                            $xxx1 = $DB->get_records_sql('SELECT qas.id AS id FROM {question_attempts} qa, {question_attempt_steps} qas WHERE qa.questionusageid="' . $grademethod_sql->uniqueid . '" AND qa.questionid="' . $tq['qid'] . '" AND qas.questionattemptid=qa.id AND qas.sequencenumber IN (0,1) ORDER BY qas.id ASC');
                            $xxx2 = array_keys($xxx1);
                            $xxx_questions = $DB->get_record_sql('SELECT id,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[0] . '" AND name LIKE "_choiceorder%"');
                            $xxx_answers_orders = $DB->get_records_sql('SELECT id,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[1] . '" AND name LIKE "p%" ORDER BY id ASC');
                            $ttab1 = null;
                            $ttab1 = explode(',', $xxx_questions->value);
                            $question = $tq['question'];
                            $ttab2 = null;
                            foreach ($xxx_answers_orders as $xao) {
                                $ttab2[] = $xao->value;
                            }
                            $selected = 0;
                            for ($z = 0; $z < count($ttab2); $z++) {
                                if ($ttab2[$z] <= 0) {
                                    $question = preg_replace('/\\[\\[' . ($z + 1) . '\\]\\]/', '<span style="color:red;font-weight: bold;">___</span>', $question);
                                } else {
                                    if ($tq['answers'][$z + 1] == $tq['answers'][$ttab1[$ttab2[$z] - 1]]) {
                                        $question = preg_replace('/\\[\\[' . ($z + 1) . '\\]\\]/', '<span style="color:blue;font-weight: bold;">' . $tq['answers'][$ttab1[$ttab2[$z] - 1]] . '</span>', $question);
                                        $selected++;
                                    } else {
                                        $question = preg_replace('/\\[\\[' . ($z + 1) . '\\]\\]/', '<span style="color:red;font-weight: bold;">' . $tq['answers'][$ttab1[$ttab2[$z] - 1]] . '</span>', $question);
                                    }
                                }
                            }
                            if ($MODE_NOTE == 1) {
                                if ($selected == count($tq['answers'])) {
                                    $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format($tq['points'][0], $questiondecimalpoints, ".", "");
                                }
                            } else {
                                $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format($tq['points'][0] * $selected / count($tq['answers']), $questiondecimalpoints, ".", "");
                            }
                            $NREQ = '
				<table border="0" style="width:100%;"><tr><td><b>' . $nb_question . '.</b></td><td style="text-align:right;">' . get_string('pluginname', 'qtype_ddwtos') . '</td></tr></table><br />' . $question . '<br /><br />
				<table style="margin-left: auto; margin-right: auto;" class="table">
				<tr>
				<th style="font-size: 10pt;">' . get_string('points_available', 'quiz_nitroreportpdf') . '</th>
				<th style="font-size: 10pt;">' . get_string('gained_points', 'quiz_nitroreportpdf') . '</th>
				</tr>
				<tr>
				<td style="text-align: center;font-size: 10pt;">' . $tq['points'][0] . '</td>
				<td style="text-align: center;font-size: 10pt;">' . $tab_users[$users->userid]['attempt'][$tq['qid']] . '</td>
				</tr>
				</table>';
                            $mpdf->WriteHTML($NREQ);
                            if ($generate_html_file) {
                                $html_contents .= $NREQ;
                            }
                            break;
                        case 'match':
                            $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format(0, $questiondecimalpoints, ".", "");
                            $xxx1 = $DB->get_records_sql('SELECT qas.id AS id FROM {question_attempts} qa, {question_attempt_steps} qas WHERE qa.questionusageid="' . $grademethod_sql->uniqueid . '" AND qa.questionid="' . $tq['qid'] . '" AND qas.questionattemptid=qa.id AND qas.sequencenumber IN (0,1) ORDER BY qas.id ASC');
                            $xxx2 = array_keys($xxx1);
                            $db_quest_order = $DB->get_record_sql('SELECT id,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[0] . '" AND name="_stemorder"');
                            $db_answ_order = $DB->get_record_sql('SELECT id,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[0] . '" AND name="_choiceorder"');
                            $db_answ_order2 = $DB->get_records_sql('SELECT id,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[1] . '" AND name LIKE "sub%"');
                            $selected = 0;
                            $question = '';
                            $question .= '<table style="border-bottom:1px solid black;border-left:1px solid black;border-right:1px solid black;" cellspacing="0" cellpadding="0">';
                            $db_quest_order_id = explode(',', $db_quest_order->value);
                            $db_answ_order_id = explode(',', $db_answ_order->value);
                            $db_answ_order_id_order = array();
                            foreach ($db_answ_order2 as $id => $low) {
                                $db_answ_order_id_order[] = $low->value;
                            }
                            for ($p = 0; $p < count($db_quest_order_id); $p++) {
                                $question .= '<tr><td style="border-right:1px solid black;border-top:1px solid black;padding:5px;">' . $tq['answers'][$db_quest_order_id[$p]]['question'] . '</td>';
                                $idorder = $db_answ_order_id_order[$p];
                                if ($idorder == 0) {
                                    $question .= '<td style="color:blue;font-weight: bold;border-top:1px solid black;padding:5px;">&nbsp;&nbsp;&nbsp;</td>';
                                } else {
                                    if ($db_quest_order_id[$p] == $db_answ_order_id[$idorder - 1]) {
                                        $selected++;
                                        $question .= '<td style="color:blue;font-weight: bold;border-top:1px solid black;padding:5px;">' . $tq['answers'][$db_answ_order_id[$idorder - 1]]['answer'] . '</td>';
                                    } else {
                                        $question .= '<td style="color:red;font-weight: bold;border-top:1px solid black;padding:5px;">' . $tq['answers'][$db_answ_order_id[$idorder - 1]]['answer'] . '</td>';
                                    }
                                }
                                $question .= '</tr>';
                            }
                            $question .= '</table>';
                            if ($MODE_NOTE == 1) {
                                for ($p = 0; $p < count($db_quest_order_id); $p++) {
                                    $selected2 = 0;
                                    $idorder = $db_answ_order_id_order[$p];
                                    if ($db_quest_order_id[$p] == $db_answ_order_id[$idorder - 1]) {
                                        $selected2++;
                                    }
                                }
                                if ($selected2 == count($db_answ_order_id)) {
                                    $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format($tq['points'][0], $questiondecimalpoints, ".", "");
                                }
                            } else {
                                $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format($tq['points'][0] * $selected / count($db_answ_order_id), $questiondecimalpoints, ".", "");
                            }
                            $NREQ = '<table border="0" style="width:100%;"><tr><td><b>' . $nb_question . '.</b></td><td style="text-align:right;">' . get_string('pluginname', 'qtype_match') . '</td></tr></table><br />' . $question . '<br /><br />
				<table style="margin-left: auto; margin-right: auto;" class="table">
				<tr>
				<th style="font-size: 10pt;">' . get_string('points_available', 'quiz_nitroreportpdf') . '</th>
				<th style="font-size: 10pt;">' . get_string('gained_points', 'quiz_nitroreportpdf') . '</th>
				</tr>
				<tr>
				<td style="text-align: center;font-size: 10pt;">' . $tq['points'][0] . '</td>
				<td style="text-align: center;font-size: 10pt;">' . $tab_users[$users->userid]['attempt'][$tq['qid']] . '</td>
				</tr>
				</table>';
                            $mpdf->WriteHTML($NREQ);
                            if ($generate_html_file) {
                                $html_contents .= $NREQ;
                            }
                            break;
                        case 'ddmatch':
                            $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format(0, $questiondecimalpoints, ".", "");
                            $xxx1 = $DB->get_records_sql('SELECT qas.id AS id FROM {question_attempts} qa, {question_attempt_steps} qas WHERE qa.questionusageid="' . $grademethod_sql->uniqueid . '" AND qa.questionid="' . $tq['qid'] . '" AND qas.questionattemptid=qa.id AND qas.sequencenumber IN (0,1) ORDER BY qas.id ASC');
                            $xxx2 = array_keys($xxx1);
                            $xxx_questions = $DB->get_record_sql('SELECT id,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[0] . '" AND name="_stemorder"');
                            $xxx_answers = $DB->get_record_sql('SELECT id,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[0] . '" AND name="_choiceorder"');
                            $xxx_answers_orders = $DB->get_records_sql('SELECT id,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[1] . '" AND name LIKE "sub%"');
                            $tab_questions_answers = array();
                            $tab_questions_answers1 = array();
                            $ttab1 = null;
                            $ttab1 = explode(',', $xxx_questions->value);
                            $ttab2 = null;
                            $ttab2 = explode(',', $xxx_answers->value);
                            $ttab3 = null;
                            foreach ($xxx_answers_orders as $id => $orders) {
                                $ttab3[] = $ttab2[$orders->value - 1];
                            }
                            for ($i = 0; $i < count($ttab1); $i++) {
                                $tab_questions_answers[$ttab1[$i]] = $ttab3[$i];
                            }
                            $tab_questions_answers_keys = $this->quick_sort(array_keys($tab_questions_answers));
                            for ($i = 0; $i < count($tab_questions_answers_keys); $i++) {
                                $tab_questions_answers1[$tab_questions_answers_keys[$i]] = $tab_questions_answers[$tab_questions_answers_keys[$i]];
                            }
                            $tab_questions_answers = $tab_questions_answers1;
                            /* ID question = ID answer = OK. */
                            $corrected = 0;
                            foreach ($tab_questions_answers as $id => $answer) {
                                if ($id == $answer) {
                                    $corrected++;
                                }
                            }
                            if ($MODE_NOTE == 1) {
                                if (count($tab_questions_answers) == $corrected) {
                                    $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format($tq['points'][0], $questiondecimalpoints, ".", "");
                                }
                            } else {
                                $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format($tq['points'][0] * $corrected / count($tab_questions_answers), $questiondecimalpoints, ".", "");
                            }
                            $answer = '<table border="1" style="margin-left: auto; margin-right: auto;"><tr><th>' . get_string('question2', 'quiz_nitroreportpdf') . '</th><th>' . get_string('answer', 'quiz_nitroreportpdf') . '</th><th>' . get_string('corrected_question', 'quiz_nitroreportpdf') . '</th></tr>';
                            foreach ($tab_questions_answers as $id => $ans) {
                                if ($id == $ans) {
                                    $answer .= '<tr><td>' . $tq['questions'][$id] . '</td><td>' . $tq['answers'][$ans] . '</td><td style="text-align: center;">' . get_string('yes', 'quiz_nitroreportpdf') . '</td></tr>';
                                } else {
                                    $answer .= '<tr><td>' . $tq['questions'][$id] . '</td><td>' . $tq['answers'][$ans] . '</td><td style="text-align: center;">' . get_string('no', 'quiz_nitroreportpdf') . '</td></tr>';
                                }
                            }
                            $answer .= '</table>';
                            $NREQ = '<table border="0" style="width:100%;"><tr><td><b>' . $nb_question . '.</b></td><td style="text-align:right;">' . get_string('pluginname', 'qtype_ddmatch') . '</td></tr></table><br />' . $tq['question'] . '<br /><br />' . $answer . '<br /><br /><table style="margin-left: auto; margin-right: auto;" class="table"><tr><th style="font-size: 10pt;">' . get_string('points_available', 'quiz_nitroreportpdf') . '</th><th style="font-size: 10pt;">' . get_string('gained_points', 'quiz_nitroreportpdf') . '</th></tr><tr><td style="text-align: center;font-size: 10pt;">' . $tq['points'][0] . '</td><td style="text-align: center;font-size: 10pt;">' . $tab_users[$users->userid]['attempt'][$tq['qid']] . '</td></tr></table>';
                            $mpdf->WriteHTML($NREQ);
                            if ($generate_html_file) {
                                $html_contents .= $NREQ;
                            }
                            break;
                        case 'ordering':
                            $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format(0, $questiondecimalpoints, ".", "");
                            $xxx1 = $DB->get_records_sql('SELECT qas.id AS id FROM {question_attempts} qa, {question_attempt_steps} qas WHERE qa.questionusageid="' . $grademethod_sql->uniqueid . '" AND qa.questionid="' . $tq['qid'] . '" AND qas.questionattemptid=qa.id AND qas.sequencenumber IN (0,1) ORDER BY qas.id ASC');
                            $xxx2 = array_keys($xxx1);
                            $db_quest_order = $DB->get_record_sql('SELECT id,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[0] . '" AND name="_correctresponse"');
                            $db_answ_order = $DB->get_record_sql('SELECT id,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[1] . '" AND name="response_' . $tq['qid'] . '"');
                            $db_answ_order = preg_replace('/ordering_item_/', '', $db_answ_order->value);
                            $db_answ_order = explode(',', $db_answ_order);
                            $ttab1 = null;
                            $ttab1 = explode(',', $db_quest_order->value);
                            $ttab2 = null;
                            for ($i = 0; $i < count($db_answ_order); $i++) {
                                $ttab2[] = $tq['answers_md5'][$db_answ_order[$i]];
                            }
                            $selected = 0;
                            $question = $tq['question'] . '<br><br>';
                            for ($i = 0; $i < count($ttab2); $i++) {
                                if ($ttab1[$i] == $ttab2[$i]) {
                                    $question .= '<span style="color:blue;font-weight: bold;">' . $tq['answers'][$ttab2[$i]] . '</span><br><hr><br>';
                                    $selected++;
                                } else {
                                    $question .= '<span style="color:red;font-weight: bold;">' . $tq['answers'][$ttab2[$i]] . '</span><br><hr><br>';
                                }
                            }
                            $question = substr($question, 0, -12);
                            if ($MODE_NOTE == 1) {
                                $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format($tq['points'][0], $questiondecimalpoints, ".", "");
                            } else {
                                $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format($tq['points'][0] * $selected / count($ttab1), $questiondecimalpoints, ".", "");
                            }
                            $NREQ = '<table border="0" style="width:100%;"><tr><td><b>' . $nb_question . '.</b></td><td style="text-align:right;">' . get_string('pluginname', 'qtype_ordering') . '</td></tr></table><br />' . $question . '<br /><br />
				<table style="margin-left: auto; margin-right: auto;" class="table">
				<tr>
				<th style="font-size: 10pt;">' . get_string('points_available', 'quiz_nitroreportpdf') . '</th>
				<th style="font-size: 10pt;">' . get_string('gained_points', 'quiz_nitroreportpdf') . '</th>
				</tr>
				<tr>
				<td style="text-align: center;font-size: 10pt;">' . $tq['points'][0] . '</td>
				<td style="text-align: center;font-size: 10pt;">' . $tab_users[$users->userid]['attempt'][$tq['qid']] . '</td>
				</tr>
				</table>';
                            $mpdf->WriteHTML($NREQ);
                            if ($generate_html_file) {
                                $html_contents .= $NREQ;
                            }
                            break;
                        case 'gapfill':
                            $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format(0, $questiondecimalpoints, ".", "");
                            $xxx1 = $DB->get_records_sql('SELECT qas.id AS id FROM {question_attempts} qa, {question_attempt_steps} qas WHERE qa.questionusageid="' . $grademethod_sql->uniqueid . '" AND qa.questionid="' . $tq['qid'] . '" AND qas.questionattemptid=qa.id AND qas.sequencenumber IN (1) ORDER BY qas.id ASC');
                            $xxx2 = array_keys($xxx1);
                            $db_answ_order = $DB->get_records_sql('SELECT id,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[0] . '" AND name LIKE "p%"');
                            $ttab2 = null;
                            foreach ($db_answ_order as $db_answ_order) {
                                $ttab2[] = $db_answ_order->value;
                            }
                            $question = $tq['question'];
                            $selected = 0;
                            preg_match_all('/\\' . substr($tab_quiz[$q->q_idq]['options'][0], 0, 1) . '(.*)\\' . substr($tab_quiz[$q->q_idq]['options'][0], 1, 1) . '/U', $tq['question'], $founded);
                            for ($i = 0; $i < count($tq['answers']); $i++) {
                                if ($tq['answers'][$i] == $ttab2[$i]) {
                                    $question = preg_replace('/\\' . substr($tab_quiz[$q->q_idq]['options'][0], 0, 1) . $founded[1][$i] . '\\' . substr($tab_quiz[$q->q_idq]['options'][0], 1, 1) . '/', '<span style="color:blue;font-weight: bold;">' . $ttab2[$i] . '</span>', $question);
                                    $selected++;
                                } else {
                                    $question = preg_replace('/\\' . substr($tab_quiz[$q->q_idq]['options'][0], 0, 1) . $founded[1][$i] . '\\' . substr($tab_quiz[$q->q_idq]['options'][0], 1, 1) . '/', '<span style="color:red;font-weight: bold;">' . $ttab2[$i] . '</span>', $question);
                                }
                            }
                            if ($MODE_NOTE == 1) {
                                $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format($tq['points'][0], $questiondecimalpoints, ".", "");
                            } else {
                                $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format($tq['points'][0] * $selected / count($tq['answers']), $questiondecimalpoints, ".", "");
                            }
                            $NREQ = '<table border="0" style="width:100%;"><tr><td><b>' . $nb_question . '.</b></td><td style="text-align:right;">' . get_string('pluginname', 'qtype_gapfill') . '</td></tr></table><br />' . $question . '<br /><br />
				<table style="margin-left: auto; margin-right: auto;" class="table">
				<tr>
				<th style="font-size: 10pt;">' . get_string('points_available', 'quiz_nitroreportpdf') . '</th>
				<th style="font-size: 10pt;">' . get_string('gained_points', 'quiz_nitroreportpdf') . '</th>
				</tr>
				<tr>
				<td style="text-align: center;font-size: 10pt;">' . $tq['points'][0] . '</td>
				<td style="text-align: center;font-size: 10pt;">' . $tab_users[$users->userid]['attempt'][$tq['qid']] . '</td>
				</tr>
				</table>';
                            $mpdf->WriteHTML($NREQ);
                            if ($generate_html_file) {
                                $html_contents .= $NREQ;
                            }
                            break;
                            // WIRIS QUESTIONS *** WIRIS QUESTIONS *** WIRIS QUESTIONS
                        // WIRIS QUESTIONS *** WIRIS QUESTIONS *** WIRIS QUESTIONS
                        case 'truefalsewiris':
                            $question = $tq['question'];
                            $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format(0, $questiondecimalpoints, ".", "");
                            $xxx1 = $DB->get_records_sql('SELECT qas.id AS id FROM {question_attempts} qa, {question_attempt_steps} qas WHERE qa.questionusageid="' . $grademethod_sql->uniqueid . '" AND qa.questionid="' . $tq['qid'] . '" AND qas.questionattemptid=qa.id AND qas.sequencenumber IN (0,1) ORDER BY qas.id ASC');
                            $xxx2 = array_keys($xxx1);
                            $db_answ = $DB->get_record_sql('SELECT id,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[0] . '" AND name="_qi"');
                            $db_answ2 = $DB->get_record_sql('SELECT id,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[1] . '" AND name="answer"');
                            $db_answ = $db_answ->value;
                            $db_answ2 = $db_answ2->value;
                            preg_match_all('/#([a-zA-Z0-9\\-\\.]+)/', $tq['question'], $pl);
                            $pl = $pl[1];
                            for ($i = 0; $i < count($pl); $i++) {
                                preg_match('/<variable name="' . $pl[$i] . '" type="(.*)">(.*)<\\/variable>/U', $db_answ, $pl2);
                                switch ($pl2[1]) {
                                    case 'mathml':
                                        $var = $pl2[2];
                                        $var = preg_replace('/<!\\[CDATA\\[/', '', $var);
                                        $var = preg_replace('/\\]\\]>/', '', $var);
                                        $question = preg_replace('/#' . $pl[$i] . '/', $var, $question);
                                        break;
                                    case 'imageref':
                                        $var = $WIRIS_URL_IMAGE_SERVICE . $pl2[2];
                                        $file_md5 = 'wiris_' . md5($var) . '.png';
                                        if (file_exists($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5)) {
                                            touch($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5);
                                        } else {
                                            $ch = curl_init();
                                            curl_setopt($ch, CURLOPT_URL, $var);
                                            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                                            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                                            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
                                            curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
                                            curl_setopt($ch, CURLOPT_TIMEOUT, 600);
                                            $req = curl_exec($ch);
                                            curl_close($ch);
                                            file_put_contents($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5, $req);
                                        }
                                        $question = preg_replace('/#' . $pl[$i] . '/', '<img src="' . $CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5 . '">', $question);
                                        touch($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5);
                                        break;
                                }
                            }
                            $anscolor = '';
                            if ($tq['answers'][0] == 0) {
                                $answer = 'True';
                            } else {
                                $answer = 'False';
                            }
                            if ($db_answ2 == "") {
                                $anscolor = '<span style="color:red;font-weight: bold;">' . get_string('noanswer', 'quiz_nitroreportpdf') . '</span>';
                            } elseif ($db_answ2 == $tq['answers'][0]) {
                                $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format($tq['points'][0], $questiondecimalpoints, ".", "");
                                $tab_users[$users->userid]['answers'][$tq['qid']]['answer'][0] = $db_answ2;
                                $anscolor = '<span style="color:blue;font-weight: bold;">' . $answer . '</span>';
                            } else {
                                $anscolor = '<span style="color:red;font-weight: bold;">' . $answer . '</span>';
                            }
                            $NREQ = '<table border="0" style="width:100%;"><tr><td><b>' . $nb_question . '.</b></td><td style="text-align:right;">WIRIS - ' . get_string('pluginname', 'qtype_truefalsewiris') . '</td></tr></table><br />' . $question . '<br /><u>' . get_string('answered', 'quiz_nitroreportpdf') . ':</u> ' . $anscolor . '<br /><br />
				<table style="margin-left: auto; margin-right: auto;" class="table">
				<tr>
				<th style="font-size: 10pt;">' . get_string('points_available', 'quiz_nitroreportpdf') . '</th>
				<th style="font-size: 10pt;">' . get_string('gained_points', 'quiz_nitroreportpdf') . '</th>
				</tr>
				<tr>
				<td style="text-align: center;font-size: 10pt;">' . $tq['points'][0] . '</td>
				<td style="text-align: center;font-size: 10pt;">' . $tab_users[$users->userid]['attempt'][$tq['qid']] . '</td>
				</tr>
				</table>';
                            //write to HTML FILE
                            //PDF
                            preg_match_all('/<math.*>(.*)<\\/math>/U', $NREQ, $math);
                            $math = $math[0];
                            for ($i = 0; $i < count($math); $i++) {
                                $req = $this->latexmlfunctions('mathml2image', urlencode($math[$i]));
                                if ($req != "@500") {
                                    $NREQ = preg_replace('/<math.*>.*<\\/math>/U', '<img src="' . $req . '">', $NREQ);
                                } else {
                                    $req = $this->latexmlfunctions('mathml2latex', urlencode($math[$i]));
                                    if ($req != "@500") {
                                        $req = $this->latexmlfunctions('latex2image', urlencode($req));
                                        if ($req != "@500") {
                                            $NREQ = preg_replace('/<math.*>.*<\\/math>/U', '<img src="' . $req . '">', $NREQ);
                                        }
                                    }
                                }
                            }
                            $mpdf->WriteHTML($NREQ);
                            if ($generate_html_file) {
                                $html_contents .= $NREQ;
                            }
                            break;
                        case 'matchwiris':
                            $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format(0, $questiondecimalpoints, ".", "");
                            $xxx1 = $DB->get_records_sql('SELECT qas.id AS id FROM {question_attempts} qa, {question_attempt_steps} qas WHERE qa.questionusageid="' . $grademethod_sql->uniqueid . '" AND qa.questionid="' . $tq['qid'] . '" AND qas.questionattemptid=qa.id AND qas.sequencenumber IN (0,1) ORDER BY qas.id ASC');
                            $xxx2 = array_keys($xxx1);
                            $db_quest_order = $DB->get_record_sql('SELECT id,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[0] . '" AND name="_stemorder"');
                            $db_answ_order = $DB->get_record_sql('SELECT id,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[0] . '" AND name="_choiceorder"');
                            $db_answ_order2 = $DB->get_records_sql('SELECT id,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[1] . '" AND name LIKE "sub%"');
                            $db_answ = $DB->get_record_sql('SELECT id,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[0] . '" AND name="_qi"');
                            $db_answ = $db_answ->value;
                            //question
                            $question = $tq['question'];
                            preg_match_all('/#([a-zA-Z0-9\\-\\.]+)/', $tq['question'], $pl);
                            $pl = $pl[1];
                            for ($i = 0; $i < count($pl); $i++) {
                                preg_match('/<variable name="' . $pl[$i] . '" type="(.*)">(.*)<\\/variable>/U', $db_answ, $pl2);
                                switch ($pl2[1]) {
                                    case 'mathml':
                                        $var = $pl2[2];
                                        $var = preg_replace('/<!\\[CDATA\\[/', '', $var);
                                        $var = preg_replace('/\\]\\]>/', '', $var);
                                        $question = preg_replace('/#' . $pl[$i] . '/', $var, $question);
                                        break;
                                    case 'imageref':
                                        $var = $WIRIS_URL_IMAGE_SERVICE . $pl2[2];
                                        $file_md5 = 'wiris_' . md5($var) . '.png';
                                        if (file_exists($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5)) {
                                            touch($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5);
                                        } else {
                                            $ch = curl_init();
                                            curl_setopt($ch, CURLOPT_URL, $var);
                                            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                                            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                                            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
                                            curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
                                            curl_setopt($ch, CURLOPT_TIMEOUT, 600);
                                            $req = curl_exec($ch);
                                            curl_close($ch);
                                            file_put_contents($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5, $req);
                                        }
                                        $question = preg_replace('/#' . $pl[$i] . '/', '<img src="' . $CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5 . '">', $question);
                                        touch($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5);
                                        break;
                                }
                            }
                            $answers = '';
                            $copy_answers = $tq['answers'];
                            foreach ($copy_answers as $ID => $ANS) {
                                $an = $ANS['answer'];
                                $qs = $ANS['question'];
                                //QS
                                preg_match_all('/#([a-zA-Z0-9\\-\\.]+)/', $qs, $plX);
                                $plX = $plX[1];
                                for ($i = 0; $i < count($plX); $i++) {
                                    preg_match('/<variable name="' . $plX[$i] . '" type="(.*)">(.*)<\\/variable>/U', $db_answ, $pl2X);
                                    switch ($pl2X[1]) {
                                        case 'mathml':
                                            $varX = $pl2X[2];
                                            $varX = preg_replace('/<!\\[CDATA\\[/', '', $varX);
                                            $varX = preg_replace('/\\]\\]>/', '', $varX);
                                            $qs = preg_replace('/#' . $plX[$i] . '/', $varX, $qs);
                                            break;
                                        case 'imageref':
                                            $varX = $WIRIS_URL_IMAGE_SERVICE . $pl2X[2];
                                            $file_md5 = 'wiris_' . md5($varX) . '.png';
                                            if (file_exists($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5)) {
                                                touch($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5);
                                            } else {
                                                $ch = curl_init();
                                                curl_setopt($ch, CURLOPT_URL, $varX);
                                                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                                                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                                                curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
                                                curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
                                                curl_setopt($ch, CURLOPT_TIMEOUT, 600);
                                                $req = curl_exec($ch);
                                                curl_close($ch);
                                                file_put_contents($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5, $req);
                                            }
                                            $qs = preg_replace('/#' . $pl[$i] . '/', '<img src="' . $CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5 . '">', $qs);
                                            touch($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5);
                                            break;
                                    }
                                }
                                //AN
                                preg_match_all('/#([a-zA-Z0-9\\-\\.]+)/', $an, $plX);
                                $plX = $plX[1];
                                for ($i = 0; $i < count($plX); $i++) {
                                    preg_match('/<variable name="' . $plX[$i] . '" type="(.*)">(.*)<\\/variable>/U', $db_answ, $pl2X);
                                    switch ($pl2X[1]) {
                                        case 'mathml':
                                            $varX = $pl2X[2];
                                            $varX = preg_replace('/<!\\[CDATA\\[/', '', $varX);
                                            $varX = preg_replace('/\\]\\]>/', '', $varX);
                                            $an = preg_replace('/#' . $plX[$i] . '/', $varX, $an);
                                            break;
                                        case 'imageref':
                                            $varX = $WIRIS_URL_IMAGE_SERVICE . $pl2X[2];
                                            $file_md5 = 'wiris_' . md5($varX) . '.png';
                                            if (file_exists($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5)) {
                                                touch($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5);
                                            } else {
                                                $ch = curl_init();
                                                curl_setopt($ch, CURLOPT_URL, $varX);
                                                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                                                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                                                curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
                                                curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
                                                curl_setopt($ch, CURLOPT_TIMEOUT, 600);
                                                $req = curl_exec($ch);
                                                curl_close($ch);
                                                file_put_contents($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5, $req);
                                            }
                                            $an = preg_replace('/#' . $pl[$i] . '/', '<img src="' . $CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5 . '">', $an);
                                            touch($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5);
                                            break;
                                    }
                                }
                                $copy_answers[$ID]['question'] = $qs;
                                $copy_answers[$ID]['answer'] = $an;
                            }
                            $selected = 0;
                            $answers .= '<table style="border-bottom:1px solid black;border-left:1px solid black;border-right:1px solid black;" cellspacing="0" cellpadding="0">';
                            $db_quest_order_id = explode(',', $db_quest_order->value);
                            $db_answ_order_id = explode(',', $db_answ_order->value);
                            $db_answ_order_id_order = array();
                            foreach ($db_answ_order2 as $id => $low) {
                                $db_answ_order_id_order[] = $low->value;
                            }
                            for ($p = 0; $p < count($db_quest_order_id); $p++) {
                                $answers .= '<tr><td style="border-right:1px solid black;border-top:1px solid black;padding:5px;">' . $copy_answers[$db_quest_order_id[$p]]['question'] . '</td>';
                                $idorder = $db_answ_order_id_order[$p];
                                if ($idorder == 0) {
                                    $answers .= '<td style="color:blue;font-weight: bold;border-top:1px solid black;padding:5px;">&nbsp;&nbsp;&nbsp;</td>';
                                } else {
                                    if ($db_quest_order_id[$p] == $db_answ_order_id[$idorder - 1]) {
                                        $selected++;
                                        $answers .= '<td style="color:blue;font-weight: bold;border-top:1px solid black;padding:5px;">' . $copy_answers[$db_answ_order_id[$idorder - 1]]['answer'] . '</td>';
                                    } else {
                                        $answers .= '<td style="color:red;font-weight: bold;border-top:1px solid black;padding:5px;">' . $copy_answers[$db_answ_order_id[$idorder - 1]]['answer'] . '</td>';
                                    }
                                }
                                $answers .= '</tr>';
                            }
                            $answers .= '</table>';
                            if ($MODE_NOTE == 1) {
                                for ($p = 0; $p < count($db_quest_order_id); $p++) {
                                    $selected2 = 0;
                                    $idorder = $db_answ_order_id_order[$p];
                                    if ($db_quest_order_id[$p] == $db_answ_order_id[$idorder - 1]) {
                                        $selected2++;
                                    }
                                }
                                if ($selected2 == count($db_answ_order_id)) {
                                    $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format($tq['points'][0], $questiondecimalpoints, ".", "");
                                }
                            } else {
                                $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format($tq['points'][0] * $selected / count($db_answ_order_id), $questiondecimalpoints, ".", "");
                            }
                            $NREQ = '<table border="0" style="width:100%;"><tr><td><b>' . $nb_question . '.</b></td><td style="text-align:right;">WIRIS - ' . get_string('pluginname', 'qtype_matchwiris') . '</td></tr></table><br />' . $question . '<br /><br />' . $answers . '<br /><br />
				<table style="margin-left: auto; margin-right: auto;" class="table">
				<tr>
				<th style="font-size: 10pt;">' . get_string('points_available', 'quiz_nitroreportpdf') . '</th>
				<th style="font-size: 10pt;">' . get_string('gained_points', 'quiz_nitroreportpdf') . '</th>
				</tr>
				<tr>
				<td style="text-align: center;font-size: 10pt;">' . $tq['points'][0] . '</td>
				<td style="text-align: center;font-size: 10pt;">' . $tab_users[$users->userid]['attempt'][$tq['qid']] . '</td>
				</tr>
				</table>';
                            //write to HTML FILE
                            //PDF
                            preg_match_all('/<math.*>(.*)<\\/math>/U', $NREQ, $math);
                            $math = $math[0];
                            for ($i = 0; $i < count($math); $i++) {
                                $req = $this->latexmlfunctions('mathml2image', urlencode($math[$i]));
                                if ($req != "@500") {
                                    $NREQ = preg_replace('/<math.*>.*<\\/math>/U', '<img src="' . $req . '">', $NREQ);
                                } else {
                                    $req = $this->latexmlfunctions('mathml2latex', urlencode($math[$i]));
                                    if ($req != "@500") {
                                        $req = $this->latexmlfunctions('latex2image', urlencode($req));
                                        if ($req != "@500") {
                                            $NREQ = preg_replace('/<math.*>.*<\\/math>/U', '<img src="' . $req . '">', $NREQ);
                                        }
                                    }
                                }
                            }
                            $mpdf->WriteHTML($NREQ);
                            if ($generate_html_file) {
                                $html_contents .= $NREQ;
                            }
                            break;
                        case 'multianswerwiris':
                            $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format(0, $questiondecimalpoints, ".", "");
                            $points = 0;
                            $question = $tq['question'];
                            $xxx1 = $DB->get_records_sql('SELECT qas.id AS id FROM {question_attempts} qa, {question_attempt_steps} qas WHERE qa.questionusageid="' . $grademethod_sql->uniqueid . '" AND qa.questionid="' . $tq['qid'] . '" AND qas.questionattemptid=qa.id AND qas.sequencenumber IN (0,1) ORDER BY qas.id ASC');
                            $xxx2 = array_keys($xxx1);
                            $xxx_questions = $DB->get_records_sql('SELECT id,name,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[0] . '" AND name LIKE "_sub%_order"');
                            $db_answ = $DB->get_record_sql('SELECT id,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[0] . '" AND name="_qi"');
                            $db_answ = $db_answ->value;
                            //WIRIS CHANGE!
                            $copy_answers = $tq['answers'];
                            for ($z = 0; $z < count($copy_answers); $z++) {
                                for ($x = 0; $x < count($copy_answers[$i]['answers']); $x++) {
                                    $an = $copy_answers[$z]['answers'][$x];
                                    //AN
                                    preg_match_all('/@@@@@([a-zA-Z0-9\\-\\.]+)/', $an, $plX);
                                    $plX = $plX[1];
                                    for ($i = 0; $i < count($plX); $i++) {
                                        preg_match('/<variable name="' . $plX[$i] . '" type="(.*)">(.*)<\\/variable>/U', $db_answ, $pl2X);
                                        switch ($pl2X[1]) {
                                            case 'mathml':
                                                $varX = $pl2X[2];
                                                $varX = preg_replace('/<!\\[CDATA\\[/', '', $varX);
                                                $varX = preg_replace('/\\]\\]>/', '', $varX);
                                                $an = preg_replace('/@@@@@' . $plX[$i] . '/', $varX, $an);
                                                break;
                                            case 'imageref':
                                                $varX = $WIRIS_URL_IMAGE_SERVICE . $pl2X[2];
                                                $file_md5 = 'wiris_' . md5($varX) . '.png';
                                                if (file_exists($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5)) {
                                                    touch($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5);
                                                } else {
                                                    $ch = curl_init();
                                                    curl_setopt($ch, CURLOPT_URL, $varX);
                                                    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                                                    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                                                    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
                                                    curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
                                                    curl_setopt($ch, CURLOPT_TIMEOUT, 600);
                                                    $req = curl_exec($ch);
                                                    curl_close($ch);
                                                    file_put_contents($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5, $req);
                                                }
                                                $an = preg_replace('/@@@@@' . $plX[$i] . '/', '<img src="' . $CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5 . '">', $an);
                                                touch($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5);
                                                break;
                                        }
                                    }
                                    $copy_answers[$z]['answers'][$x] = $an;
                                }
                            }
                            ////////////////////WIRIS CHANGE!
                            foreach ($xxx_questions as $id => $questions) {
                                preg_match('/_sub(.*)_order/', $questions->name, $number_question_db);
                                $number_question_db = $number_question_db[1];
                                $xxx_resp_exist = $DB->get_record_sql('SELECT count(*) as how FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[1] . '" AND name="sub' . $number_question_db . '_answer"');
                                if ($xxx_resp_exist->how > 0) {
                                    $xxx_resp = $DB->get_record_sql('SELECT id,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[1] . '" AND name="sub' . $number_question_db . '_answer"');
                                    $ttab1 = null;
                                    $ttab1 = explode(',', $questions->value);
                                    $index = $ttab1[$xxx_resp->value];
                                    if ($index < 0 || empty($index)) {
                                        $question = preg_replace('/\\{#' . $number_question_db . '\\}/', '<span style="color:red;font-weight: bold;">___</span>', $question);
                                    } else {
                                        $index2 = $copy_answers[$number_question_db - 1]['answers_id'][$index];
                                        if ($copy_answers[$number_question_db - 1]['correct'] == $index2) {
                                            $points += $copy_answers[$number_question_db - 1]['points'][$index2];
                                        }
                                        $question = preg_replace('/\\{#' . $number_question_db . '\\}/', '<span style="color:red;font-weight: bold;">' . $copy_answers[$number_question_db - 1]['answers'][$index2] . '</span>', $question);
                                    }
                                }
                            }
                            preg_match_all('/\\{#([0-9]+)\\}/', $question, $rest);
                            if (count($rest[1]) > 0) {
                                for ($i = 0; $i < count($rest[1]); $i++) {
                                    $xxx_resp = $DB->get_record_sql('SELECT id,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[1] . '" AND name="sub' . $rest[1][$i] . '_answer"');
                                    $xxx_resp = $xxx_resp->value;
                                    if ($copy_answers[$rest[1][$i] - 1]['typewiris'][0] == 'shortanswer') {
                                        $xxx_correct_c = $DB->get_record_sql('SELECT count(*) as how FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[0] . '" AND name="_sub' . $rest[1][$i] . '_matching_answer"');
                                        if ($xxx_correct_c->how == 0) {
                                            $question = preg_replace('/\\{#' . $rest[1][$i] . '\\}/', '<span style="color:red;font-weight: bold;">___</span>', $question);
                                        } else {
                                            $xxx_correct = $DB->get_record_sql('SELECT id,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[0] . '" AND name="_sub' . $rest[1][$i] . '_matching_answer"');
                                            $xxx_correct = $xxx_correct->value;
                                            $myanswer = $xxx_resp;
                                            $correctanswer = $copy_answers[$rest[1][$i] - 1]['answers'][$copy_answers[$rest[1][$i] - 1]['answers_id'][$xxx_correct]];
                                            require_once $CFG->dirroot . '/question/type/wq/quizzes/quizzes.php';
                                            $builder = com_wiris_quizzes_api_QuizzesBuilder::getInstance();
                                            $request = $builder->newEvalRequest($correctanswer, $myanswer, null, null);
                                            $service = $builder->getQuizzesService();
                                            $response = $service->execute($request);
                                            $instance = $builder->newQuestionInstance();
                                            $instance->update($response);
                                            $correct = $instance->isAnswerCorrect(0);
                                            if ($correct == 1) {
                                                $points = $copy_answers[$rest[1][$i] - 1]['points'][$copy_answers[$rest[1][$i] - 1]['answers_id'][$xxx_correct]];
                                                $question = preg_replace('/\\{#' . $rest[1][$i] . '\\}/', '<span style="color:blue;font-weight: bold;">\\$' . $myanswer . '\\$</span>', $question);
                                            } else {
                                                $question = preg_replace('/\\{#' . $rest[1][$i] . '\\}/', '<span style="color:red;font-weight: bold;">\\$' . $myanswer . '\\$</span>', $question);
                                            }
                                        }
                                    } elseif ($copy_answers[$rest[1][$i] - 1]['typewiris'][0] == 'numerical') {
                                        for ($j = 0; $j < count($copy_answers[$rest[1][$i] - 1]['answers']); $j++) {
                                            if ($copy_answers[$rest[1][$i] - 1]['type'][$j] == 'range') {
                                                $ex = explode('-', $copy_answers[$rest[1][$i] - 1]['answers'][$j]);
                                                if ($xxx_resp->value >= $ex[0] && $xxx_resp->value <= $ex[1]) {
                                                    if ($copy_answers[$rest[1][$i] - 1]['points'][$j] == 0) {
                                                        $question = preg_replace('/\\{#' . $rest[1][$i] . '\\}/', '<span style="color:red;font-weight: bold;">' . $xxx_resp->value . '</span>', $question);
                                                        break;
                                                    } else {
                                                        $points += $copy_answers[$rest[1][$i] - 1]['points'][$j];
                                                        $question = preg_replace('/\\{#' . $rest[1][$i] . '\\}/', '<span style="color:blue;font-weight: bold;">' . $xxx_resp->value . '</span>', $question);
                                                        break;
                                                    }
                                                } else {
                                                    $question = preg_replace('/\\{#' . $rest[1][$i] . '\\}/', '<span style="color:red;font-weight: bold;">' . $xxx_resp->value . '</span>', $question);
                                                }
                                            } else {
                                                if ($xxx_resp->value == $copy_answers[$rest[1][$i] - 1]['answers'][$j]) {
                                                    $question = preg_replace('/\\{#' . $rest[1][$i] . '\\}/', '<span style="color:green;font-weight: bold;">' . $xxx_resp->value . '</span>', $question);
                                                    $points += $copy_answers[$rest[1][$i] - 1]['points'][$j];
                                                    break;
                                                } else {
                                                    $question = preg_replace('/\\{#' . $rest[1][$i] . '\\}/', '<span style="color:red;font-weight: bold;">' . $xxx_resp->value . '</span>', $question);
                                                    break;
                                                }
                                            }
                                        }
                                    } elseif ($copy_answers[$rest[1][$i] - 1]['typewiris'][0] == 'multichoice') {
                                        $xxx_resp_exist = $DB->get_record_sql('SELECT count(*) as how FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[1] . '" AND name="sub' . $rest[1][$i] . '_answer"');
                                        if ($xxx_resp_exist->how > 0) {
                                            $ttab1 = null;
                                            $ttab1 = explode(',', $questions->value);
                                            $index = $ttab1[$xxx_resp->value];
                                            if ($index < 0 || empty($index)) {
                                                $question = preg_replace('/\\{#' . $rest[1][$i] . '\\}/', '<span style="color:red;font-weight: bold;">___</span>', $question);
                                            } else {
                                                $index2 = $copy_answers[$rest[1][$i] - 1]['answers_id'][$index];
                                                if ($copy_answers[$rest[1][$i] - 1]['correct'] == $index2) {
                                                    $points += $copy_answers[$rest[1][$i] - 1]['points'][$index2];
                                                }
                                                $question = preg_replace('/\\{#' . $rest[1][$i] . '\\}/', '<span style="color:red;font-weight: bold;">' . $copy_answers[$rest[1][$i] - 1]['answers'][$index2] . '</span>', $question);
                                            }
                                        }
                                    }
                                }
                            }
                            /////QUESTION
                            preg_match_all('/#([a-zA-Z0-9\\-\\.]+)/', $question, $plX);
                            $plX = $plX[1];
                            for ($i = 0; $i < count($plX); $i++) {
                                preg_match('/<variable name="' . $plX[$i] . '" type="(.*)">(.*)<\\/variable>/U', $db_answ, $pl2X);
                                switch ($pl2X[1]) {
                                    case 'mathml':
                                        $varX = $pl2X[2];
                                        $varX = preg_replace('/<!\\[CDATA\\[/', '', $varX);
                                        $varX = preg_replace('/\\]\\]>/', '', $varX);
                                        $question = preg_replace('/#' . $plX[$i] . '/', $varX, $question);
                                        break;
                                    case 'imageref':
                                        $varX = $WIRIS_URL_IMAGE_SERVICE . $pl2X[2];
                                        $file_md5 = 'wiris_' . md5($varX) . '.png';
                                        if (file_exists($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5)) {
                                            touch($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5);
                                        } else {
                                            $ch = curl_init();
                                            curl_setopt($ch, CURLOPT_URL, $varX);
                                            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                                            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                                            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
                                            curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
                                            curl_setopt($ch, CURLOPT_TIMEOUT, 600);
                                            $req = curl_exec($ch);
                                            curl_close($ch);
                                            file_put_contents($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5, $req);
                                        }
                                        $question = preg_replace('/#' . $pl[$i] . '/', '<img src="' . $CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5 . '">', $question);
                                        touch($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5);
                                        break;
                                }
                            }
                            $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format($points, $questiondecimalpoints, ".", "");
                            $NREQ = '
				<table border="0" style="width:100%;"><tr><td><b>' . $nb_question . '.</b></td><td style="text-align:right;">WIRIS - ' . get_string('pluginname', 'qtype_multianswerwiris') . '</td></tr></table><br />' . $question . '<br /><br />
				<table style="margin-left: auto; margin-right: auto;" class="table">
				<tr>
				<th style="font-size: 10pt;">' . get_string('points_available', 'quiz_nitroreportpdf') . '</th>
				<th style="font-size: 10pt;">' . get_string('gained_points', 'quiz_nitroreportpdf') . '</th>
				</tr>
				<tr>
				<td style="text-align: center;font-size: 10pt;">' . $tq['points'][0] . '</td>
				<td style="text-align: center;font-size: 10pt;">' . $tab_users[$users->userid]['attempt'][$tq['qid']] . '</td>
				</tr>
				</table>';
                            //WRITE TO HTML
                            //PDF
                            preg_match_all('/<math.*>(.*)<\\/math>/U', $NREQ, $math);
                            $math = $math[0];
                            for ($i = 0; $i < count($math); $i++) {
                                $req = $this->latexmlfunctions('mathml2image', urlencode($math[$i]));
                                if ($req != "@500") {
                                    $NREQ = preg_replace('/<math.*>.*<\\/math>/U', '<img src="' . $req . '">', $NREQ);
                                } else {
                                    $req = $this->latexmlfunctions('mathml2latex', urlencode($math[$i]));
                                    if ($req != "@500") {
                                        $req = $this->latexmlfunctions('latex2image', urlencode($req));
                                        if ($req != "@500") {
                                            $NREQ = preg_replace('/<math.*>.*<\\/math>/U', '<img src="' . $req . '">', $NREQ);
                                        }
                                    }
                                }
                            }
                            preg_match_all('/\\$(.*)\\$/U', $NREQ, $math);
                            $math = $math[1];
                            for ($i = 0; $i < count($math); $i++) {
                                $req = $this->latexmlfunctions('latex2image', urlencode($math[$i]));
                                if ($req != "@500") {
                                    $NREQ = preg_replace('/<math.*>.*<\\/math>/U', '<img src="' . $req . '">', $NREQ);
                                }
                            }
                            $mpdf->WriteHTML($NREQ);
                            if ($generate_html_file) {
                                $html_contents .= $NREQ;
                            }
                            break;
                        case 'multichoicewiris':
                            $question = $tq['question'];
                            $tab_users[$users->userid]['attempt'][$tq['qid']] = 0;
                            $multi_tb = $DB->get_record_sql('SELECT single FROM {qtype_multichoice_options} WHERE questionid="' . $tq['qid'] . '"');
                            $xxx1 = $DB->get_records_sql('SELECT qas.id AS id FROM {question_attempts} qa, {question_attempt_steps} qas WHERE qa.questionusageid="' . $grademethod_sql->uniqueid . '" AND qa.questionid="' . $tq['qid'] . '" AND qas.questionattemptid=qa.id AND qas.sequencenumber IN (0,1) ORDER BY qas.id ASC');
                            $xxx2 = array_keys($xxx1);
                            $db_answ = $DB->get_record_sql('SELECT id,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[0] . '" AND name="_qi"');
                            $db_answ = $db_answ->value;
                            //QUESTION
                            preg_match_all('/#([a-zA-Z0-9\\-\\.]+)/', $question, $pl);
                            $pl = $pl[1];
                            for ($i = 0; $i < count($pl); $i++) {
                                preg_match('/<variable name="' . $pl[$i] . '" type="(.*)">(.*)<\\/variable>/U', $db_answ, $pl2);
                                switch ($pl2[1]) {
                                    case 'mathml':
                                        $var = $pl2[2];
                                        $var = preg_replace('/<!\\[CDATA\\[/', '', $var);
                                        $var = preg_replace('/\\]\\]>/', '', $var);
                                        $question = preg_replace('/#' . $pl[$i] . '/', $var, $question);
                                        break;
                                    case 'imageref':
                                        $var = $WIRIS_URL_IMAGE_SERVICE . $pl2[2];
                                        $file_md5 = 'wiris_' . md5($var) . '.png';
                                        if (file_exists($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5)) {
                                            touch($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5);
                                        } else {
                                            $ch = curl_init();
                                            curl_setopt($ch, CURLOPT_URL, $var);
                                            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                                            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                                            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
                                            curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
                                            curl_setopt($ch, CURLOPT_TIMEOUT, 600);
                                            $req = curl_exec($ch);
                                            curl_close($ch);
                                            file_put_contents($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5, $req);
                                        }
                                        $question = preg_replace('/#' . $pl[$i] . '/', '<img src="' . $CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5 . '">', $question);
                                        touch($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5);
                                        break;
                                }
                            }
                            //ANSWERS
                            $answers = $tq['answers'];
                            foreach ($answers as $ID => $ans) {
                                $ansX = $ans;
                                preg_match_all('/#([a-zA-Z0-9\\-\\.]+)/', $ansX, $pl);
                                $pl = $pl[1];
                                for ($i = 0; $i < count($pl); $i++) {
                                    preg_match('/<variable name="' . $pl[$i] . '" type="(.*)">(.*)<\\/variable>/U', $db_answ, $pl2);
                                    switch ($pl2[1]) {
                                        case 'mathml':
                                            $var = $pl2[2];
                                            $var = preg_replace('/<!\\[CDATA\\[/', '', $var);
                                            $var = preg_replace('/\\]\\]>/', '', $var);
                                            $ansX = preg_replace('/#' . $pl[$i] . '/', $var, $ansX);
                                            break;
                                        case 'imageref':
                                            $var = $WIRIS_URL_IMAGE_SERVICE . $pl2[2];
                                            $file_md5 = 'wiris_' . md5($var) . '.png';
                                            if (file_exists($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5)) {
                                                touch($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5);
                                            } else {
                                                $ch = curl_init();
                                                curl_setopt($ch, CURLOPT_URL, $var);
                                                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                                                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                                                curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
                                                curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
                                                curl_setopt($ch, CURLOPT_TIMEOUT, 600);
                                                $req = curl_exec($ch);
                                                curl_close($ch);
                                                file_put_contents($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5, $req);
                                            }
                                            $ansX = preg_replace('/#' . $pl[$i] . '/', '<img src="' . $CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5 . '">', $ansX);
                                            touch($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5);
                                            break;
                                    }
                                }
                                $answers[$ID] = $ansX;
                            }
                            $xxx3_tab_bin = array();
                            $count_corrected = 0;
                            foreach ($tq['qanswers'] as $id => $a) {
                                if ($a == 1) {
                                    $count_corrected++;
                                }
                            }
                            if ($multi_tb->single == 1) {
                                $questiontypemultichoice = get_string('questiontypemultichoiceone', 'quiz_nitroreportpdf');
                                $xxx3 = $DB->get_record_sql('SELECT id,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[0] . '" AND name="_order"');
                                $xxx4 = $DB->get_record_sql('SELECT id,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[1] . '" AND name="answer"');
                                $xxx3_u = $xxx3->value;
                                ///contains user's answers in binary format . this table must be sorting by id
                                $xxx3_tab = explode(',', $xxx3_u);
                                if (!is_object($xxx4)) {
                                    $xxx4 = new StdClass();
                                    $xxx4->id = -1;
                                    $xxx4->value = -1;
                                }
                                for ($z = 0; $z < count($xxx3_tab); $z++) {
                                    //specify place in options
                                    if ($z == $xxx4->value) {
                                        $xxx3_tab_bin[$xxx3_tab[$z]] = 1;
                                    } else {
                                        $xxx3_tab_bin[$xxx3_tab[$z]] = 0;
                                    }
                                }
                                if (!isset($xxx4->value)) {
                                    $xxx4->value = -1;
                                }
                                for ($z = 0; $z < count($xxx3_tab); $z++) {
                                    //specify place in options
                                    if ($z == $xxx4->value) {
                                        $xxx3_tab_bin[$xxx3_tab[$z]] = 1;
                                    } else {
                                        $xxx3_tab_bin[$xxx3_tab[$z]] = 0;
                                    }
                                }
                                $xxx3_tab_bin_ids = $this->quick_sort(array_keys($xxx3_tab_bin));
                                $xxx3_tab_bin2 = array();
                                for ($z = 0; $z < count($xxx3_tab_bin_ids); $z++) {
                                    $xxx3_tab_bin2[$xxx3_tab_bin_ids[$z]] = $xxx3_tab_bin[$xxx3_tab_bin_ids[$z]];
                                }
                                $xxx3_tab_bin = $xxx3_tab_bin2;
                                $corrected = 0;
                                $user_asked = '';
                                $odp = 0;
                                foreach ($xxx3_tab_bin as $id => $bin) {
                                    $multiple = $bin * $tq[qanswers][$id];
                                    if ($multiple == 1) {
                                        $corrected++;
                                    }
                                    if ($bin == 1 && $bin != $tq[qanswers][$id]) {
                                        $user_asked .= '<span style="color: red;"><b>[X]</b></span> ';
                                    } elseif ($bin == 1 && $bin == $tq[qanswers][$id]) {
                                        $user_asked .= '<span style="color: blue;"><b>[X]</b></span> ';
                                    }
                                    $user_asked .= '<b>' . chr(65 + $odp) . ".</b> &nbsp;";
                                    $user_asked .= $answers[$id] . '<br />';
                                    $odp++;
                                }
                                $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format($tq['points'][0] * $corrected / $count_corrected, $questiondecimalpoints, ".", "");
                            } elseif ($multi_tb->single == 0 && count($xxx2) > 0) {
                                $questiontypemultichoice = get_string('questiontypemultichoicemulti', 'quiz_nitroreportpdf');
                                $xxx3 = $DB->get_record_sql('SELECT id,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[0] . '" AND name="_order"');
                                $xxx4 = $DB->get_records_sql('SELECT id,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[1] . '" AND name LIKE "choice%" ORDER BY name ASC');
                                $xxx3_u = $xxx3->value;
                                $xxx3_tab = explode(',', $xxx3_u);
                                $xxx4_tab_bin = array();
                                $xxx4_ids = array_keys($xxx4);
                                for ($z = 0; $z < count($xxx4_ids); $z++) {
                                    $xxx4_tab_bin[] = $xxx4[$xxx4_ids[$z]]->value;
                                }
                                $xxx4_tab_bin_temp = array();
                                if (count($xxx4) == 0) {
                                    for ($y = 0; $y < count($tq['qanswers']); $y++) {
                                        $xxx4_tab_bin[] = 0;
                                    }
                                }
                                for ($z = 0; $z < count($xxx3_tab); $z++) {
                                    $xxx4_tab_bin_temp[$xxx3_tab[$z]] = $xxx4_tab_bin[$z];
                                }
                                $xxx4_tab_bin_temp_ids = $this->quick_sort(array_keys($xxx4_tab_bin_temp));
                                $xxx4_tab_bin_temp2 = array();
                                for ($z = 0; $z < count($xxx4_tab_bin_temp_ids); $z++) {
                                    $xxx4_tab_bin_temp2[$xxx4_tab_bin_temp_ids[$z]] = $xxx4_tab_bin_temp[$xxx4_tab_bin_temp_ids[$z]];
                                }
                                $xxx3_tab_bin = $xxx4_tab_bin_temp2;
                                unset($xxx4_tab_bin_temp2);
                                $corrected = 0;
                                $user_asked = '';
                                $odp = 0;
                                foreach ($xxx3_tab_bin as $id => $bin) {
                                    $multiple = $bin * $tq[qanswers][$id];
                                    if ($multiple == 1) {
                                        $corrected++;
                                    }
                                    if ($bin == 1 && $bin != $tq[qanswers][$id]) {
                                        $user_asked .= '<span style="color: red;"><b>[X]</b></span> ';
                                    } elseif ($bin == 1 && $bin == $tq[qanswers][$id]) {
                                        $user_asked .= '<span style="color: blue;"><b>[X]</b></span> ';
                                    }
                                    $user_asked .= '<b>' . chr(65 + $odp) . ".</b> &nbsp;";
                                    $user_asked .= $answers[$id] . '<br />';
                                    $odp++;
                                }
                            }
                            if ($MODE_NOTE == 1) {
                                if ($corrected == $count_corrected) {
                                    $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format($tq['points'][0], $questiondecimalpoints, ".", "");
                                }
                            } else {
                                $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format($tq['points'][0] * $corrected / $count_corrected, $questiondecimalpoints, ".", "");
                            }
                            $NREQ = '<table border="0" style="width:100%;"><tr><td><b>' . $nb_question . '.</b></td><td style="text-align:right;">' . $questiontypemultichoice . '</td></tr></table><br />' . $question . '<br /><br />' . $user_asked . '<br />
				<table style="margin-left: auto; margin-right: auto;" class="table">
				<tr>
				<th style="font-size: 10pt;">' . get_string('points_available', 'quiz_nitroreportpdf') . '</th>
				<th style="font-size: 10pt;">' . get_string('gained_points', 'quiz_nitroreportpdf') . '</th>
				</tr>
				<tr>
				<td style="text-align: center;font-size: 10pt;">' . $tq['points'][0] . '</td>
				<td style="text-align: center;font-size: 10pt;">' . $tab_users[$users->userid]['attempt'][$tq['qid']] . '</td>
				</tr>
				</table>';
                            //WRITE TO HTML
                            //WRITE TO PDF
                            preg_match_all('/<math.*>(.*)<\\/math>/U', $NREQ, $math);
                            $math = $math[0];
                            for ($i = 0; $i < count($math); $i++) {
                                $req = $this->latexmlfunctions('mathml2image', urlencode($math[$i]));
                                if ($req != "@500") {
                                    $NREQ = preg_replace('/<math.*>.*<\\/math>/U', '<img src="' . $req . '">', $NREQ);
                                } else {
                                    $req = $this->latexmlfunctions('mathml2latex', urlencode($math[$i]));
                                    if ($req != "@500") {
                                        $req = $this->latexmlfunctions('latex2image', urlencode($req));
                                        if ($req != "@500") {
                                            $NREQ = preg_replace('/<math.*>.*<\\/math>/U', '<img src="' . $req . '">', $NREQ);
                                        }
                                    }
                                }
                            }
                            $mpdf->WriteHTML($NREQ);
                            if ($generate_html_file) {
                                $html_contents .= $NREQ;
                            }
                            break;
                        case 'shortanswerwiris':
                            $question = $tq['question'];
                            $tab_users[$users->userid]['attempt'][$tq['qid']] = 0;
                            $multi_tb = $DB->get_record_sql('SELECT single FROM {qtype_multichoice_options} WHERE questionid="' . $tq['qid'] . '"');
                            $xxx1 = $DB->get_records_sql('SELECT qas.id AS id FROM {question_attempts} qa, {question_attempt_steps} qas WHERE qa.questionusageid="' . $grademethod_sql->uniqueid . '" AND qa.questionid="' . $tq['qid'] . '" AND qas.questionattemptid=qa.id AND qas.sequencenumber IN (0,1) ORDER BY qas.id ASC');
                            $xxx2 = array_keys($xxx1);
                            $db_answ = $DB->get_record_sql('SELECT id,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[0] . '" AND name="_qi"');
                            $db_answ = $db_answ->value;
                            $db_answer = $DB->get_record_sql('SELECT id,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[1] . '" AND name="answer"');
                            $db_answer = $db_answer->value;
                            $copy_answers = $tq['answers'];
                            foreach ($copy_answers as $ID => $ANS) {
                                $an = $ANS;
                                preg_match_all('/#([a-zA-Z0-9\\-\\.]+)/', $an, $plX);
                                $plX = $plX[1];
                                for ($i = 0; $i < count($plX); $i++) {
                                    preg_match('/<variable name="' . $plX[$i] . '" type="(.*)">(.*)<\\/variable>/U', $db_answ, $pl2X);
                                    switch ($pl2X[1]) {
                                        case 'mathml':
                                            $varX = $pl2X[2];
                                            $varX = preg_replace('/<!\\[CDATA\\[/', '', $varX);
                                            $varX = preg_replace('/\\]\\]>/', '', $varX);
                                            $an = preg_replace('/#' . $plX[$i] . '/', $varX, $an);
                                            break;
                                        case 'imageref':
                                            $varX = $WIRIS_URL_IMAGE_SERVICE . $pl2X[2];
                                            $file_md5 = 'wiris_' . md5($varX) . '.png';
                                            if (file_exists($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5)) {
                                                touch($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5);
                                            } else {
                                                $ch = curl_init();
                                                curl_setopt($ch, CURLOPT_URL, $varX);
                                                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                                                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                                                curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
                                                curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
                                                curl_setopt($ch, CURLOPT_TIMEOUT, 600);
                                                $req = curl_exec($ch);
                                                curl_close($ch);
                                                file_put_contents($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5, $req);
                                            }
                                            $an = preg_replace('/#' . $pl[$i] . '/', '<img src="' . $CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5 . '">', $an);
                                            touch($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $file_md5);
                                            break;
                                    }
                                }
                                $copy_answers[$ID] = $an;
                            }
                            $answer = '<span style="color:red;font-weight: bold;">' . $db_answer . '</span>';
                            require_once $CFG->dirroot . '/question/type/wq/quizzes/quizzes.php';
                            for ($i = 0; $i < count($copy_answers); $i++) {
                                $builder = com_wiris_quizzes_api_QuizzesBuilder::getInstance();
                                $request = $builder->newEvalRequest($copy_answers[$i], $db_answer, null, null);
                                $service = $builder->getQuizzesService();
                                $response = $service->execute($request);
                                $instance = $builder->newQuestionInstance();
                                $instance->update($response);
                                $correct = $instance->isAnswerCorrect(0);
                                if ($correct == 1) {
                                    $tab_users[$users->userid]['attempt'][$tq['qid']] = $tq['fraction'][$i] * $tq['points'][0];
                                    $answer = '<span style="color:blue;font-weight: bold;">' . $db_answer . '</span>';
                                    break;
                                }
                            }
                            $NREQ = '<table border="0" style="width:100%;"><tr><td><b>' . $nb_question . '.</b></td><td style="text-align:right;">' . get_string('pluginname', 'qtype_shortanswerwiris') . '</td></tr></table><br />' . $question . '<br /><br />
				Odpowiedź: ' . $answer . '
				<br /><br />
				<table style="margin-left: auto; margin-right: auto;" class="table">
				<tr>
				<th style="font-size: 10pt;">' . get_string('points_available', 'quiz_nitroreportpdf') . '</th>
				<th style="font-size: 10pt;">' . get_string('gained_points', 'quiz_nitroreportpdf') . '</th>
				</tr>
				<tr>
				<td style="text-align: center;font-size: 10pt;">' . $tq['points'][0] . '</td>
				<td style="text-align: center;font-size: 10pt;">' . $tab_users[$users->userid]['attempt'][$tq['qid']] . '</td>
				</tr>
				</table>';
                            //WRITE TO HTML
                            //WRITE TO PDF
                            preg_match_all('/<math.*>(.*)<\\/math>/U', $NREQ, $math);
                            $math = $math[0];
                            for ($i = 0; $i < count($math); $i++) {
                                $req = $this->latexmlfunctions('mathml2image', urlencode($math[$i]));
                                if ($req != "@500") {
                                    $NREQ = preg_replace('/<math.*>.*<\\/math>/U', '<img src="' . $req . '">', $NREQ);
                                } else {
                                    $req = $this->latexmlfunctions('mathml2latex', urlencode($math[$i]));
                                    if ($req != "@500") {
                                        $req = $this->latexmlfunctions('latex2image', urlencode($req));
                                        if ($req != "@500") {
                                            $NREQ = preg_replace('/<math.*>.*<\\/math>/U', '<img src="' . $req . '">', $NREQ);
                                        }
                                    }
                                }
                            }
                            $mpdf->WriteHTML($NREQ);
                            if ($generate_html_file) {
                                $html_contents .= $NREQ;
                            }
                            break;
                            // WIRIS QUESTIONS *** WIRIS QUESTIONS *** WIRIS QUESTIONS
                        // WIRIS QUESTIONS *** WIRIS QUESTIONS *** WIRIS QUESTIONS
                        case 'multichoiceset':
                            $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format(0, $questiondecimalpoints, ".", "");
                            $question = $tq['question'] . '<br><br>';
                            $xxx1 = $DB->get_records_sql('SELECT qas.id AS id FROM {question_attempts} qa, {question_attempt_steps} qas WHERE qa.questionusageid="' . $grademethod_sql->uniqueid . '" AND qa.questionid="' . $tq['qid'] . '" AND qas.questionattemptid=qa.id AND qas.sequencenumber IN (0,1) ORDER BY qas.id ASC');
                            $xxx2 = array_keys($xxx1);
                            $db_q = $DB->get_record_sql('SELECT id,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[0] . '" AND name="_order"');
                            $db_q = $db_q->value;
                            $db_answ = $DB->get_records_sql('SELECT id,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[1] . '" AND name LIKE "choice%"');
                            $ttab1 = null;
                            $ttab1 = explode(',', $db_q);
                            $ttab2 = null;
                            $correct = false;
                            foreach ($db_answ as $id => $val) {
                                $ttab2[] = $val;
                            }
                            $answer = '';
                            for ($i = 0; $i < count($ttab2); $i++) {
                                $answer .= $i + 1 . '. ';
                                if ($ttab2[$i]->value > 0) {
                                    if (in_array($ttab1[$i], $tq['answers_corr_tab'])) {
                                        $answer .= '<span style="color:blue;font-weight: bold;">[X]</span> ';
                                        $correct = true;
                                    }
                                } else {
                                    $correct = false;
                                }
                                $answer .= $tq['answers'][$tq['answers_id'][$ttab1[$i]]]['answer'];
                            }
                            if ($correct) {
                                $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format($tq['points'][0], $questiondecimalpoints, ".", "");
                            }
                            $NREQ = '<table border="0" style="width:100%;"><tr><td><b>' . $nb_question . '.</b></td><td style="text-align:right;">' . get_string('pluginname', 'qtype_multichoiceset') . '</td></tr></table><br />' . $question . ' ' . $answer . '<br /><br />
				<table style="margin-left: auto; margin-right: auto;" class="table">
				<tr>
				<th style="font-size: 10pt;">' . get_string('points_available', 'quiz_nitroreportpdf') . '</th>
				<th style="font-size: 10pt;">' . get_string('gained_points', 'quiz_nitroreportpdf') . '</th>
				</tr>
				<tr>
				<td style="text-align: center;font-size: 10pt;">' . $tq['points'][0] . '</td>
				<td style="text-align: center;font-size: 10pt;">' . $tab_users[$users->userid]['attempt'][$tq['qid']] . '</td>
				</tr>
				</table>';
                            $mpdf->WriteHTML($NREQ);
                            if ($generate_html_file) {
                                $html_contents .= $NREQ;
                            }
                            break;
                        case 'calculatedsimple':
                            $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format(0, $questiondecimalpoints, ".", "");
                            $xxx1 = $DB->get_records_sql('SELECT qas.id AS id FROM {question_attempts} qa, {question_attempt_steps} qas WHERE qa.questionusageid="' . $grademethod_sql->uniqueid . '" AND qa.questionid="' . $tq['qid'] . '" AND qas.questionattemptid=qa.id AND qas.sequencenumber IN (0,1) ORDER BY qas.id ASC');
                            $xxx2 = array_keys($xxx1);
                            $db_vars = $DB->get_records_sql('SELECT id,name,value FROM {question_attempt_step_data} WHERE attemptstepid="' . $xxx2[0] . '" AND name LIKE "_var_%"');
                            $variables = array();
                            foreach ($db_vars as $ID => $obj) {
                                $variables[substr($obj->name, 5)] = $obj->value;
                            }
                            $question = $tq['question'];
                            foreach ($db_vars as $ID => $obj) {
                                $question = preg_replace('/\\{' . substr($obj->name, 5) . '\\}/', $obj->value, $question);
                            }
                            $question .= '<br><br><u>Odpowiedź:</u> ';
                            $quiz_details_sql = $DB->get_records_sql('SELECT questionid,rightanswer,responsesummary FROM {question_attempts} WHERE questionusageid="' . $grademethod_sql->uniqueid . '" AND questionid="' . $tq['qid'] . '"');
                            $quiz_details_sql = $quiz_details_sql[$tq['qid']];
                            $corrrect = $quiz_details_sql->rightanswer;
                            $resp = $quiz_details_sql->responsesummary;
                            if ($corrrect == $resp) {
                                $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format($tq['points'][0], $questiondecimalpoints, ".", "");
                                $question .= '<span style="color:blue;font-weight: bold;">' . $resp . '</span>';
                            } else {
                                $question .= '<span style="color:red;font-weight: bold;">' . $resp . '</span>';
                            }
                            $NREQ = '<table border="0" style="width:100%;"><tr><td><b>' . $nb_question . '.</b></td><td style="text-align:right;">' . get_string('pluginname', 'qtype_calculatedsimple') . '</td></tr></table><br />' . $question . '<br /><br />
				<table style="margin-left: auto; margin-right: auto;" class="table">
				<tr>
				<th style="font-size: 10pt;">' . get_string('points_available', 'quiz_nitroreportpdf') . '</th>
				<th style="font-size: 10pt;">' . get_string('gained_points', 'quiz_nitroreportpdf') . '</th>
				</tr>
				<tr>
				<td style="text-align: center;font-size: 10pt;">' . $tq['points'][0] . '</td>
				<td style="text-align: center;font-size: 10pt;">' . $tab_users[$users->userid]['attempt'][$tq['qid']] . '</td>
				</tr>
				</table>';
                            $mpdf->WriteHTML($NREQ);
                            if ($generate_html_file) {
                                $html_contents .= $NREQ;
                            }
                            break;
                        default:
                            $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format(0, $questiondecimalpoints, ".", "");
                            $gradedpartial = $DB->get_record_sql('SELECT count(qas.fraction) AS fraction FROM {question_attempts} qa, {question_attempt_steps} qas WHERE qa.questionusageid="' . $grademethod_sql->uniqueid . '" AND qa.questionid="' . $tq['qid'] . '" AND qas.questionattemptid=qa.id AND qas.state = "gradedpartial" ORDER BY qas.sequencenumber DESC LIMIT 0,1');
                            if ($gradedpartial->fraction) {
                                $gradedpartial = $DB->get_record_sql('SELECT qas.fraction AS fraction FROM {question_attempts} qa, {question_attempt_steps} qas WHERE qa.questionusageid="' . $grademethod_sql->uniqueid . '" AND qa.questionid="' . $tq['qid'] . '" AND qas.questionattemptid=qa.id AND qas.state = "gradedpartial" ORDER BY qas.sequencenumber DESC LIMIT 0,1');
                                $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format($tq['points'][0] * $gradedpartial->fraction, $questiondecimalpoints, ".", "");
                            }
                            break;
                    }
                    $mangrpartial = $DB->get_record_sql('SELECT count(qas.fraction) AS fraction FROM {question_attempts} qa, {question_attempt_steps} qas WHERE qa.questionusageid="' . $grademethod_sql->uniqueid . '" AND qa.questionid="' . $tq['qid'] . '" AND qas.questionattemptid=qa.id AND qas.state = "mangrpartial" ORDER BY qas.sequencenumber DESC LIMIT 0,1');
                    if ($mangrpartial->fraction) {
                        $mangrpartial = $DB->get_record_sql('SELECT qas.fraction AS fraction FROM {question_attempts} qa, {question_attempt_steps} qas WHERE qa.questionusageid="' . $grademethod_sql->uniqueid . '" AND qa.questionid="' . $tq['qid'] . '" AND qas.questionattemptid=qa.id AND qas.state = "mangrpartial" ORDER BY qas.sequencenumber DESC LIMIT 0,1');
                        $tab_users[$users->userid]['attempt'][$tq['qid']] = number_format($tq['points'][0] * $mangrpartial->fraction, $questiondecimalpoints, ".", "");
                    }
                    if ($nr_question - 1 > $nb_question) {
                        $NREQ = '<hr noshade style="height:1px;color:black;" />';
                        $mpdf->WriteHTML($NREQ);
                        if ($generate_html_file) {
                            $html_contents .= $NREQ;
                        }
                    }
                    $nb_question++;
                }
                $NREQ = '<hr noshade style="height:5px;color:black;" />';
                $mpdf->WriteHTML($NREQ);
                if ($generate_html_file) {
                    $html_contents .= $NREQ . '<hr noshade>';
                }
                $user_i++;
            }
            ///////////////////////////////////////////////////////////
            $this->SetBarWidth(number_format(floor(8 * (100 / $PROGRESSBAR_PARTS)), 2, '.', ''));
            @ob_flush();
            @flush();
            $mpdf->AddPage();
            $mpdf->Bookmark('7. ' . get_string('statisticalanalysis', 'quiz_nitroreportpdf'), 0);
            $NREQ = '<p style="text-align: center;font-weight: bold;font-size:14pt;text-transform:uppercase;">' . get_string('statisticalanalysis', 'quiz_nitroreportpdf') . '</p><p></p>';
            $mpdf->WriteHTML($NREQ);
            if ($generate_html_file) {
                $html_contents .= $NREQ;
            }
            $tab_points = array();
            $tab_userids = array_keys($tab_users);
            $tab_quizids = array_keys($tab_quiz);
            for ($i = 0; $i < count($tab_userids); $i++) {
                $sum = 0;
                $tab_users[$tab_userids[$i]]['sum_points'] = 0;
                for ($j = 0; $j < count($tab_quizids); $j++) {
                    $sum = $sum + $tab_users[$tab_userids[$i]]['attempt'][$tab_quizids[$j]];
                    $tab_points[$j][] = $tab_users[$tab_userids[$i]]['attempt'][$tab_quizids[$j]];
                }
                $tab_users[$tab_userids[$i]]['sum_points'] = $sum;
            }
            $NREQ = '
<table style="margin-left: auto; margin-right: auto;" repeat_header="1" class="table">
	<tr>
		<th colspan="3">&nbsp;</th>
		<th colspan="2">' . get_string('number_of_points', 'quiz_nitroreportpdf') . '</th>
	</tr>
	<tr>
		<th>' . get_string('question2', 'quiz_nitroreportpdf') . '</th>
		<th>' . get_string('max_points', 'quiz_nitroreportpdf') . '</th>
		<th>' . get_string('average', 'quiz_nitroreportpdf') . '</th>
		<th>' . get_string('min', 'quiz_nitroreportpdf') . '</th>
		<th>' . get_string('max', 'quiz_nitroreportpdf') . '</th>
	</tr>
';
            $mpdf->WriteHTML($NREQ);
            if ($generate_html_file) {
                $html_contents .= $NREQ;
            }
            for ($i = 0; $i < count($tab_points); $i++) {
                $tab_avg = array_sum($tab_points[$i]) / count($tab_points[$i]);
                if ($i % 2 == 1) {
                    $attach_style = ' class="table_td_highlight"';
                }
                $NREQ = '
	<tr>
		<td' . $attach_style . '>' . ($i + 1) . '.</td>
		<td' . $attach_style . '>' . max($tab_quiz[$tab_quizids[$i]]['points']) . '</td>
		<td' . $attach_style . '>' . number_format($tab_avg, $decimalpoints, '.', '') . '</td>
		<td' . $attach_style . '>' . min($tab_points[$i]) . '</td>
		<td' . $attach_style . '>' . max($tab_points[$i]) . '</td>
	</tr>
	';
                $mpdf->WriteHTML($NREQ);
                if ($generate_html_file) {
                    $html_contents .= $NREQ;
                }
                unset($attach_style);
            }
            $NREQ = '</table>';
            $mpdf->WriteHTML($NREQ);
            if ($generate_html_file) {
                $html_contents .= $NREQ . '<hr noshade>';
            }
            if ($GENERATE_EXCEL) {
                $SheetCount = $objPHPExcel->getSheetCount();
                $objPHPExcel->createSheet(NULL, $SheetCount);
                $objPHPExcel->setActiveSheetIndex($SheetCount);
                $objPHPExcel->getActiveSheet()->setTitle(get_string('statisticalanalysis', 'quiz_nitroreportpdf'));
                $objPHPExcel->getActiveSheet()->setCellValue('A1', get_string('question2', 'quiz_nitroreportpdf'))->setCellValue('B1', get_string('max_points', 'quiz_nitroreportpdf'))->setCellValue('C1', get_string('average', 'quiz_nitroreportpdf'))->setCellValue('D2', get_string('min', 'quiz_nitroreportpdf'))->setCellValue('E2', get_string('max', 'quiz_nitroreportpdf'))->setCellValue('D1', get_string('number_of_points', 'quiz_nitroreportpdf'));
                $objPHPExcel->getActiveSheet()->mergeCells('A1:A2');
                $objPHPExcel->getActiveSheet()->mergeCells('B1:B2');
                $objPHPExcel->getActiveSheet()->mergeCells('C1:C2');
                $objPHPExcel->getActiveSheet()->mergeCells('D1:E1');
                for ($i = 0; $i < count($tab_points); $i++) {
                    $tab_avg = array_sum($tab_points[$i]) / count($tab_points[$i]);
                    $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 3), $i + 1)->setCellValue('B' . ($i + 3), max($tab_quiz[$tab_quizids[$i]]['points']))->setCellValue('C' . ($i + 3), number_format($tab_avg, $decimalpoints, '.', ''))->setCellValue('D' . ($i + 3), min($tab_points[$i]))->setCellValue('E' . ($i + 3), max($tab_points[$i]));
                }
                for ($i = 1; $i <= count($tab_points) + 2; $i++) {
                    if ($i % 2 == 0) {
                        $objPHPExcel->getActiveSheet()->getStyle('A' . $i . ':E' . $i)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
                        $objPHPExcel->getActiveSheet()->getStyle('A' . $i . ':E' . $i)->getFill()->getStartColor()->setRGB('FFFFA1');
                    }
                }
                $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
                $objPHPExcel->getActiveSheet()->getStyle('B1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
                $objPHPExcel->getActiveSheet()->getStyle('C1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
                $objPHPExcel->getActiveSheet()->getStyle('D1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
                $objPHPExcel->getActiveSheet()->getStyle('E1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
                $objPHPExcel->getActiveSheet()->getStyle('D2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
                $objPHPExcel->getActiveSheet()->getStyle('E2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
                $objPHPExcel->getActiveSheet()->getStyle('A1:E2')->getFont()->setBold(true);
                $objPHPExcel->getActiveSheet()->getStyle('A1:E' . ($i + 2))->getFont()->setSize(14);
                for ($i = 0; $i < count($tab_points) + 3; $i++) {
                    $objPHPExcel->getActiveSheet()->getRowDimension($i)->setRowHeight(19.83);
                    $objPHPExcel->getActiveSheet()->getStyle('A' . ($i + 3))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
                    $objPHPExcel->getActiveSheet()->getStyle('B' . ($i + 3))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
                    $objPHPExcel->getActiveSheet()->getStyle('C' . ($i + 3))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
                    $objPHPExcel->getActiveSheet()->getStyle('D' . ($i + 3))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
                    $objPHPExcel->getActiveSheet()->getStyle('E' . ($i + 3))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
                }
                $styleArray = array('borders' => array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array('rgb' => '000000'))));
                $objPHPExcel->getActiveSheet()->getStyle('A1:E' . ($i - 1))->applyFromArray($styleArray);
                $objPHPExcel->getActiveSheet()->getStyle('A1:E2')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
                $objPHPExcel->getActiveSheet()->getStyle('A1:E2')->getFill()->getStartColor()->setRGB('0057AF');
                $objPHPExcel->getActiveSheet()->getStyle('A1:E2')->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_WHITE);
                $objPHPExcel->getActiveSheet()->getStyle('A1:C1')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
                $objPHPExcel->getActiveSheet()->getStyle('A1:B10')->getAlignment()->setWrapText(false);
                PHPExcel_Shared_Font::setAutoSizeMethod(PHPExcel_Shared_Font::AUTOSIZE_METHOD_EXACT);
                $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(17);
                $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
                $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(17);
                $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(17);
                $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(17);
                $objPHPExcel->getActiveSheet()->getProtection()->setPassword(substr(hash('sha512', rand()), 0, 12));
                $objPHPExcel->getActiveSheet()->getProtection()->setSheet(true);
                $objPHPExcel->getActiveSheet()->getProtection()->setFormatCells(true);
                $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddFooter('&L&D, &T &R &P / &N');
            }
            /*8. SUMMARY*/
            $this->SetBarWidth(number_format(floor(9 * (100 / $PROGRESSBAR_PARTS)), 2, '.', ''));
            @ob_flush();
            @flush();
            $mpdf->AddPage();
            $mpdf->Bookmark('8. ' . get_string('summary', 'quiz_nitroreportpdf'), 0);
            for ($i = 0; $i < count($tab_userids); $i++) {
                //grade
                if (count($tab_notes2) == 0) {
                    $tab_users[$tab_userids[$i]]['feedback'] = '';
                } else {
                    $tab_users[$tab_userids[$i]]['precent'] = number_format($tab_users[$tab_userids[$i]]['sum_points'] / $info_quiz->sumgrades * 100, $decimalpoints, ".", "");
                    for ($j = 0; $j < count($tab_notes2); $j++) {
                        if ($tab_users[$tab_userids[$i]]['sum_points'] >= $tab_notes2[$j]['mingrade_points'] && $tab_notes2[$j]['maxgrade_points'] >= $tab_users[$tab_userids[$i]]['sum_points']) {
                            $tab_users[$tab_userids[$i]]['feedback'] = $tab_notes2[$j]['feedback'];
                            break;
                        }
                    }
                }
                //avg points
                $tab_users[$tab_userids[$i]]['avg'] = number_format($tab_users[$tab_userids[$i]]['sum_points'] / count($tab_quizids), 2, '.', '');
                //variance
                $war = 0;
                for ($j = 0; $j < count($tab_quizids); $j++) {
                    $war += pow($tab_users[$tab_userids[$i]]['attempt'][$tab_quizids[$j]] - $avg[$tab_userids[$i]], 2);
                }
                $war /= count($tab_quizids);
                $war = number_format($war, 4, '.', '');
                $tab_users[$tab_userids[$i]]['war'] = $war;
                //odch
                $tab_users[$tab_userids[$i]]['odch'] = number_format(sqrt($war), 4, '.', '');
            }
            // users for
            $NREQ = '<table border="0" style="overflow:visible" repeat_header="1" class="table">';
            $mpdf->WriteHTML($NREQ);
            if ($generate_html_file) {
                $html_contents .= $NREQ;
            }
            $NREQ = '<tr><th>' . get_string('on', 'quiz_nitroreportpdf') . '</th>';
            $mpdf->WriteHTML($NREQ);
            if ($generate_html_file) {
                $html_contents .= $NREQ;
            }
            for ($i = 0; $i < count($tab_userids); $i++) {
                $NREQ = '<th>' . ($i + 1) . '.</th>';
                $mpdf->WriteHTML($NREQ);
                if ($generate_html_file) {
                    $html_contents .= $NREQ;
                }
            }
            $NREQ = '</tr>';
            $mpdf->WriteHTML($NREQ);
            if ($generate_html_file) {
                $html_contents .= $NREQ;
            }
            $NREQ = '<tr><th>' . get_string('surname', 'quiz_nitroreportpdf') . '</th>';
            $mpdf->WriteHTML($NREQ);
            if ($generate_html_file) {
                $html_contents .= $NREQ;
            }
            for ($i = 0; $i < count($tab_userids); $i++) {
                $NREQ = '<td>' . $tab_users[$tab_userids[$i]]['surname'] . '</td>';
                $mpdf->WriteHTML($NREQ);
                if ($generate_html_file) {
                    $html_contents .= $NREQ;
                }
            }
            $NREQ = '</tr>';
            $mpdf->WriteHTML($NREQ);
            if ($generate_html_file) {
                $html_contents .= $NREQ;
            }
            $NREQ = '<tr><th>' . get_string('name', 'quiz_nitroreportpdf') . '</th>';
            $mpdf->WriteHTML($NREQ);
            if ($generate_html_file) {
                $html_contents .= $NREQ;
            }
            for ($i = 0; $i < count($tab_userids); $i++) {
                $NREQ = '<td class="table_td_highlight">' . $tab_users[$tab_userids[$i]]['name'] . '</td>';
                $mpdf->WriteHTML($NREQ);
                if ($generate_html_file) {
                    $html_contents .= $NREQ;
                }
            }
            $NREQ = '</tr>';
            $mpdf->WriteHTML($NREQ);
            if ($generate_html_file) {
                $html_contents .= $NREQ;
            }
            $NREQ = '<tr><th>' . get_string('username', 'quiz_nitroreportpdf') . '</th>';
            $mpdf->WriteHTML($NREQ);
            if ($generate_html_file) {
                $html_contents .= $NREQ;
            }
            for ($i = 0; $i < count($tab_userids); $i++) {
                $NREQ = '<td>' . $tab_users[$tab_userids[$i]]['username'] . '</td>';
                $mpdf->WriteHTML($NREQ);
                if ($generate_html_file) {
                    $html_contents .= $NREQ;
                }
            }
            $NREQ = '</tr>';
            $mpdf->WriteHTML($NREQ);
            if ($generate_html_file) {
                $html_contents .= $NREQ;
            }
            $NREQ = '<tr><th>' . get_string('email', 'quiz_nitroreportpdf') . '</th>';
            $mpdf->WriteHTML($NREQ);
            if ($generate_html_file) {
                $html_contents .= $NREQ;
            }
            for ($i = 0; $i < count($tab_userids); $i++) {
                $NREQ = '<td class="table_td_highlight">' . $tab_users[$tab_userids[$i]]['email'] . '</td>';
                $mpdf->WriteHTML($NREQ);
                if ($generate_html_file) {
                    $html_contents .= $NREQ;
                }
            }
            $NREQ = '</tr>';
            $mpdf->WriteHTML($NREQ);
            if ($generate_html_file) {
                $html_contents .= $NREQ;
            }
            if ($_POST['show_question_summary'] == 1) {
                for ($i = 0; $i < count($tab_quizids); $i++) {
                    $NREQ = '<tr>';
                    $mpdf->WriteHTML($NREQ);
                    if ($generate_html_file) {
                        $html_contents .= $NREQ;
                    }
                    $NREQ = '<th>' . get_string('question2', 'quiz_nitroreportpdf') . ' ' . ($i + 1) . '.</th>';
                    $mpdf->WriteHTML($NREQ);
                    if ($generate_html_file) {
                        $html_contents .= $NREQ;
                    }
                    for ($j = 0; $j < count($tab_userids); $j++) {
                        if ($invertcolorstyle) {
                            $attach_style = ' class="table_td_highlight"';
                        }
                        $NREQ = '<td' . $attach_style . '>' . $tab_users[$tab_userids[$j]]['attempt'][$tab_quizids[$i]] . '</td>';
                        $mpdf->WriteHTML($NREQ);
                        if ($generate_html_file) {
                            $html_contents .= $NREQ;
                        }
                    }
                    $NREQ = '</tr>';
                    $mpdf->WriteHTML($NREQ);
                    if ($generate_html_file) {
                        $html_contents .= $NREQ;
                    }
                    $invertcolorstyle = !$invertcolorstyle;
                    unset($attach_style);
                }
            }
            $NREQ = '<tr><th>' . get_string('sum_points2', 'quiz_nitroreportpdf') . '</th>';
            $mpdf->WriteHTML($NREQ);
            if ($generate_html_file) {
                $html_contents .= $NREQ;
            }
            for ($i = 0; $i < count($tab_users); $i++) {
                if ($invertcolorstyle) {
                    $attach_style = ' class="table_td_highlight"';
                }
                $NREQ = '<td' . $attach_style . '>' . $tab_users[$tab_userids[$i]]['sum_points'] . '</td>';
                $mpdf->WriteHTML($NREQ);
                if ($generate_html_file) {
                    $html_contents .= $NREQ;
                }
            }
            $NREQ = '</tr>';
            $mpdf->WriteHTML($NREQ);
            if ($generate_html_file) {
                $html_contents .= $NREQ;
            }
            $invertcolorstyle = !$invertcolorstyle;
            unset($attach_style);
            $NREQ = '<tr><th>' . get_string('points_precent', 'quiz_nitroreportpdf') . '</th>';
            $mpdf->WriteHTML($NREQ);
            if ($generate_html_file) {
                $html_contents .= $NREQ;
            }
            for ($i = 0; $i < count($tab_users); $i++) {
                if ($invertcolorstyle) {
                    $attach_style = ' class="table_td_highlight"';
                }
                $NREQ = '<td' . $attach_style . '>' . $tab_users[$tab_userids[$i]]['precent'] . '</td>';
                $mpdf->WriteHTML($NREQ);
                if ($generate_html_file) {
                    $html_contents .= $NREQ;
                }
            }
            $NREQ = '</tr>';
            $mpdf->WriteHTML($NREQ);
            if ($generate_html_file) {
                $html_contents .= $NREQ;
            }
            $invertcolorstyle = !$invertcolorstyle;
            unset($attach_style);
            $NREQ = '<tr><th>' . get_string('points_avg', 'quiz_nitroreportpdf') . '</th>';
            $mpdf->WriteHTML($NREQ);
            if ($generate_html_file) {
                $html_contents .= $NREQ;
            }
            for ($i = 0; $i < count($tab_users); $i++) {
                if ($invertcolorstyle) {
                    $attach_style = ' class="table_td_highlight"';
                }
                $NREQ = '<td' . $attach_style . '>' . $tab_users[$tab_userids[$i]]['avg'] . '</td>';
                $mpdf->WriteHTML($NREQ);
                if ($generate_html_file) {
                    $html_contents .= $NREQ;
                }
            }
            $NREQ = '</tr>';
            $mpdf->WriteHTML($NREQ);
            if ($generate_html_file) {
                $html_contents .= $NREQ;
            }
            $invertcolorstyle = !$invertcolorstyle;
            unset($attach_style);
            $NREQ = '<tr><th>' . get_string('variance_points', 'quiz_nitroreportpdf') . '</th>';
            $mpdf->WriteHTML($NREQ);
            if ($generate_html_file) {
                $html_contents .= $NREQ;
            }
            for ($i = 0; $i < count($tab_users); $i++) {
                if ($invertcolorstyle) {
                    $attach_style = ' class="table_td_highlight"';
                }
                $NREQ = '<td' . $attach_style . '>' . $tab_users[$tab_userids[$i]]['war'] . '</td>';
                $mpdf->WriteHTML($NREQ);
                if ($generate_html_file) {
                    $html_contents .= $NREQ;
                }
            }
            $NREQ = '</tr>';
            $mpdf->WriteHTML($NREQ);
            if ($generate_html_file) {
                $html_contents .= $NREQ;
            }
            $invertcolorstyle = !$invertcolorstyle;
            unset($attach_style);
            $NREQ = '<tr><th>' . get_string('standdeviationpoints', 'quiz_nitroreportpdf') . '</th>';
            $mpdf->WriteHTML($NREQ);
            if ($generate_html_file) {
                $html_contents .= $NREQ;
            }
            for ($i = 0; $i < count($tab_users); $i++) {
                if ($invertcolorstyle) {
                    $attach_style = ' class="table_td_highlight"';
                }
                $NREQ = '<td' . $attach_style . '>' . $tab_users[$tab_userids[$i]]['odch'] . '</td>';
                $mpdf->WriteHTML($NREQ);
                if ($generate_html_file) {
                    $html_contents .= $NREQ;
                }
            }
            $NREQ = '</tr>';
            $mpdf->WriteHTML($NREQ);
            if ($generate_html_file) {
                $html_contents .= $NREQ;
            }
            $invertcolorstyle = !$invertcolorstyle;
            unset($attach_style);
            $NREQ = '<tr><th>' . get_string('min_points', 'quiz_nitroreportpdf') . '</th>';
            $mpdf->WriteHTML($NREQ);
            if ($generate_html_file) {
                $html_contents .= $NREQ;
            }
            for ($j = 0; $j < count($tab_userids); $j++) {
                if ($invertcolorstyle) {
                    $attach_style = ' class="table_td_highlight"';
                }
                $NREQ = '<td' . $attach_style . '>' . min($tab_users[$tab_userids[$j]]['attempt']) . '</td>';
                $mpdf->WriteHTML($NREQ);
                if ($generate_html_file) {
                    $html_contents .= $NREQ;
                }
            }
            $NREQ = '</tr>';
            $mpdf->WriteHTML($NREQ);
            if ($generate_html_file) {
                $html_contents .= $NREQ;
            }
            $invertcolorstyle = !$invertcolorstyle;
            unset($attach_style);
            $NREQ = '<tr><th>' . get_string('max_points', 'quiz_nitroreportpdf') . '</th>';
            $mpdf->WriteHTML($NREQ);
            if ($generate_html_file) {
                $html_contents .= $NREQ;
            }
            for ($j = 0; $j < count($tab_userids); $j++) {
                if ($invertcolorstyle) {
                    $attach_style = ' class="table_td_highlight"';
                }
                $NREQ = '<td' . $attach_style . '>' . max($tab_users[$tab_userids[$j]]['attempt']) . '</td>';
                $mpdf->WriteHTML($NREQ);
                if ($generate_html_file) {
                    $html_contents .= $NREQ;
                }
            }
            $NREQ = '</tr>';
            $mpdf->WriteHTML($NREQ);
            if ($generate_html_file) {
                $html_contents .= $NREQ;
            }
            $invertcolorstyle = !$invertcolorstyle;
            unset($attach_style);
            $NREQ = '<tr><th style="text-transform:capitalize;">' . get_string('grade', 'quiz_nitroreportpdf') . '</th>';
            $mpdf->WriteHTML($NREQ);
            if ($generate_html_file) {
                $html_contents .= $NREQ;
            }
            for ($j = 0; $j < count($tab_userids); $j++) {
                if ($invertcolorstyle) {
                    $attach_style = ' class="table_td_highlight"';
                }
                $NREQ = '<td' . $attach_style . '>' . $tab_users[$tab_userids[$j]]['feedback'] . '</td>';
                $mpdf->WriteHTML($NREQ);
                if ($generate_html_file) {
                    $html_contents .= $NREQ;
                }
            }
            $NREQ = '</tr>';
            $mpdf->WriteHTML($NREQ);
            if ($generate_html_file) {
                $html_contents .= $NREQ;
            }
            $invertcolorstyle = !$invertcolorstyle;
            unset($attach_style);
            $NREQ = '<tr><th>' . get_string('notes', 'quiz_nitroreportpdf') . '</th>';
            $mpdf->WriteHTML($NREQ);
            if ($generate_html_file) {
                $html_contents .= $NREQ;
            }
            for ($j = 0; $j < count($tab_userids); $j++) {
                if ($invertcolorstyle) {
                    $attach_style = ' class="table_td_highlight"';
                }
                $NREQ = '<td' . $attach_style . ' style="width:100px;height:50px;">&nbsp;</td>';
                $mpdf->WriteHTML($NREQ);
                if ($generate_html_file) {
                    $html_contents .= $NREQ;
                }
            }
            $NREQ = '</tr>';
            $mpdf->WriteHTML($NREQ);
            if ($generate_html_file) {
                $html_contents .= $NREQ;
            }
            $NREQ = '</table>';
            $mpdf->WriteHTML($NREQ);
            if ($generate_html_file) {
                $html_contents .= $NREQ;
            }
            $invertcolorstyle = !$invertcolorstyle;
            unset($attach_style);
            if ($GENERATE_EXCEL) {
                $SheetCount = $objPHPExcel->getSheetCount();
                $objPHPExcel->createSheet(NULL, $SheetCount);
                $objPHPExcel->setActiveSheetIndex($SheetCount);
                $objPHPExcel->getActiveSheet()->setTitle(get_string('summary_sort_a_z', 'quiz_nitroreportpdf'));
                $objPHPExcel->getActiveSheet()->setCellValue('A1', get_string('on', 'quiz_nitroreportpdf'))->setCellValue('B1', get_string('surname', 'quiz_nitroreportpdf'))->setCellValue('C1', get_string('name', 'quiz_nitroreportpdf'))->setCellValue('D1', get_string('username', 'quiz_nitroreportpdf'))->setCellValue('E1', get_string('email', 'quiz_nitroreportpdf'));
                for ($i = 0; $i < count($tab_userids); $i++) {
                    $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $i + 1)->setCellValue('B' . ($i + 2), $tab_users[$tab_userids[$i]]['surname'])->setCellValue('C' . ($i + 2), $tab_users[$tab_userids[$i]]['name'])->setCellValue('D' . ($i + 2), $tab_users[$tab_userids[$i]]['username'])->setCellValue('E' . ($i + 2), $tab_users[$tab_userids[$i]]['email']);
                    for ($j = 0; $j < count($tab_quizids); $j++) {
                        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(5 + $j, 1, get_string('question2', 'quiz_nitroreportpdf') . ' ' . ($j + 1));
                        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(5 + $j, 2 + $i, $tab_users[$tab_userids[$i]]['attempt'][$tab_quizids[$j]]);
                        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn(5 + $j)->setOutlineLevel(1)->setVisible(false)->setCollapsed(true);
                    }
                }
                $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(5 + $j, 1, get_string('sum_points2', 'quiz_nitroreportpdf'))->setCellValueByColumnAndRow(6 + $j, 1, get_string('points_precent', 'quiz_nitroreportpdf'))->setCellValueByColumnAndRow(7 + $j, 1, get_string('points_avg', 'quiz_nitroreportpdf'))->setCellValueByColumnAndRow(8 + $j, 1, get_string('variance_points', 'quiz_nitroreportpdf'))->setCellValueByColumnAndRow(9 + $j, 1, get_string('standdeviationpoints', 'quiz_nitroreportpdf'))->setCellValueByColumnAndRow(10 + $j, 1, get_string('min_points', 'quiz_nitroreportpdf'))->setCellValueByColumnAndRow(11 + $j, 1, get_string('max_points', 'quiz_nitroreportpdf'))->setCellValueByColumnAndRow(12 + $j, 1, get_string('grade', 'quiz_nitroreportpdf'))->setCellValueByColumnAndRow(13 + $j, 1, get_string('notes', 'quiz_nitroreportpdf'));
                for ($i = 0; $i < count($tab_userids); $i++) {
                    $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(5 + $j, $i + 2, $tab_users[$tab_userids[$i]]['sum_points'])->setCellValueByColumnAndRow(6 + $j, $i + 2, $tab_users[$tab_userids[$i]]['precent'])->setCellValueByColumnAndRow(7 + $j, $i + 2, $tab_users[$tab_userids[$i]]['avg'])->setCellValueByColumnAndRow(8 + $j, $i + 2, $tab_users[$tab_userids[$i]]['war'])->setCellValueByColumnAndRow(9 + $j, $i + 2, $tab_users[$tab_userids[$i]]['odch'])->setCellValueByColumnAndRow(10 + $j, $i + 2, min($tab_users[$tab_userids[$i]]['attempt']))->setCellValueByColumnAndRow(11 + $j, $i + 2, max($tab_users[$tab_userids[$i]]['attempt']))->setCellValueByColumnAndRow(12 + $j, $i + 2, strip_tags($tab_users[$tab_userids[$i]]['feedback']));
                }
                $styleArray = array('borders' => array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array('rgb' => '000000'))));
                for ($y = 0; $y < 14 + $j; $y++) {
                    for ($x = 1; $x <= count($tab_userids) + 1; $x++) {
                        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($y, $x)->getFont()->setSize(14);
                        $objPHPExcel->getActiveSheet()->getRowDimension($x)->setRowHeight(19.83);
                        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($y, $x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
                        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($y, $x)->applyFromArray($styleArray);
                        if ($x > 1) {
                            $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(13 + $j, $x)->getProtection()->setLocked(PHPExcel_Style_Protection::PROTECTION_UNPROTECTED);
                        }
                        if ($x % 2 == 1) {
                            $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($y, $x)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
                            $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($y, $x)->getFill()->getStartColor()->setRGB('FFFFA1');
                        }
                    }
                    $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($y, 1)->getFont()->setBold(true);
                    $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($y)->setAutoSize(true);
                    $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($y, 1)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
                    $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($y, 1)->getFill()->getStartColor()->setRGB('0057AF');
                    $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($y, 1)->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_WHITE);
                }
                $objPHPExcel->getActiveSheet()->freezePane('A2');
                $objPHPExcel->getActiveSheet()->getProtection()->setPassword(substr(hash('sha512', rand()), 0, 12));
                $objPHPExcel->getActiveSheet()->getProtection()->setSheet(true);
                $objPHPExcel->getActiveSheet()->getProtection()->setFormatCells(true);
                $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddFooter('&L&D, &T &R &P / &N');
                /*		SORT BY PRECENT		*/
                $SheetCount = $objPHPExcel->getSheetCount();
                $objPHPExcel->createSheet(NULL, $SheetCount);
                $objPHPExcel->setActiveSheetIndex($SheetCount);
                $objPHPExcel->getActiveSheet()->setTitle(get_string('summary_sort_precents', 'quiz_nitroreportpdf'));
                $objPHPExcel->getActiveSheet()->setCellValue('A1', get_string('on', 'quiz_nitroreportpdf'))->setCellValue('B1', get_string('surname', 'quiz_nitroreportpdf'))->setCellValue('C1', get_string('name', 'quiz_nitroreportpdf'))->setCellValue('D1', get_string('username', 'quiz_nitroreportpdf'))->setCellValue('E1', get_string('sum_points2', 'quiz_nitroreportpdf'))->setCellValue('F1', get_string('points_precent', 'quiz_nitroreportpdf'))->setCellValue('G1', get_string('points_avg', 'quiz_nitroreportpdf'))->setCellValue('H1', get_string('min_points', 'quiz_nitroreportpdf'))->setCellValue('I1', get_string('max_points', 'quiz_nitroreportpdf'))->setCellValue('J1', get_string('grade', 'quiz_nitroreportpdf'));
                $objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(19.83);
                $tab_userids_temp = $tab_userids;
                if (count($tab_userids_temp) > 1) {
                    $bubble_end = true;
                    while ($bubble_end) {
                        $bubble_end = false;
                        for ($y = 0; $y < count($tab_userids_temp) - 1; $y++) {
                            if ($tab_users[$tab_userids_temp[$y + 1]]['precent'] > $tab_users[$tab_userids_temp[$y]]['precent']) {
                                $temp = $tab_userids_temp[$y];
                                $tab_userids_temp[$y] = $tab_userids_temp[$y + 1];
                                $tab_userids_temp[$y + 1] = $temp;
                                $bubble_end = true;
                            }
                        }
                    }
                }
                for ($i = 0; $i < count($tab_userids_temp); $i++) {
                    $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $i + 1)->setCellValue('B' . ($i + 2), $tab_users[$tab_userids_temp[$i]]['surname'])->setCellValue('C' . ($i + 2), $tab_users[$tab_userids_temp[$i]]['name'])->setCellValue('D' . ($i + 2), $tab_users[$tab_userids_temp[$i]]['username'])->setCellValue('E' . ($i + 2), $tab_users[$tab_userids_temp[$i]]['sum_points'])->setCellValue('G' . ($i + 2), $tab_users[$tab_userids_temp[$i]]['precent'])->setCellValue('F' . ($i + 2), $tab_users[$tab_userids_temp[$i]]['avg'])->setCellValue('H' . ($i + 2), min($tab_users[$tab_userids_temp[$i]]['attempt']))->setCellValue('I' . ($i + 2), max($tab_users[$tab_userids_temp[$i]]['attempt']))->setCellValue('J' . ($i + 2), strip_tags($tab_users[$tab_userids_temp[$i]]['feedback']));
                    $objPHPExcel->getActiveSheet()->getRowDimension($i + 2)->setRowHeight(19.83);
                    if ($i % 2 == 1) {
                        $objPHPExcel->getActiveSheet()->getStyle('A' . ($i + 2))->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
                        $objPHPExcel->getActiveSheet()->getStyle('A' . ($i + 2))->getFill()->getStartColor()->setRGB('FFFFA1');
                        $objPHPExcel->getActiveSheet()->getStyle('B' . ($i + 2))->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
                        $objPHPExcel->getActiveSheet()->getStyle('B' . ($i + 2))->getFill()->getStartColor()->setRGB('FFFFA1');
                        $objPHPExcel->getActiveSheet()->getStyle('C' . ($i + 2))->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
                        $objPHPExcel->getActiveSheet()->getStyle('C' . ($i + 2))->getFill()->getStartColor()->setRGB('FFFFA1');
                        $objPHPExcel->getActiveSheet()->getStyle('D' . ($i + 2))->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
                        $objPHPExcel->getActiveSheet()->getStyle('D' . ($i + 2))->getFill()->getStartColor()->setRGB('FFFFA1');
                        $objPHPExcel->getActiveSheet()->getStyle('E' . ($i + 2))->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
                        $objPHPExcel->getActiveSheet()->getStyle('E' . ($i + 2))->getFill()->getStartColor()->setRGB('FFFFA1');
                        $objPHPExcel->getActiveSheet()->getStyle('F' . ($i + 2))->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
                        $objPHPExcel->getActiveSheet()->getStyle('F' . ($i + 2))->getFill()->getStartColor()->setRGB('FFFFA1');
                        $objPHPExcel->getActiveSheet()->getStyle('G' . ($i + 2))->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
                        $objPHPExcel->getActiveSheet()->getStyle('G' . ($i + 2))->getFill()->getStartColor()->setRGB('FFFFA1');
                        $objPHPExcel->getActiveSheet()->getStyle('H' . ($i + 2))->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
                        $objPHPExcel->getActiveSheet()->getStyle('H' . ($i + 2))->getFill()->getStartColor()->setRGB('FFFFA1');
                        $objPHPExcel->getActiveSheet()->getStyle('I' . ($i + 2))->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
                        $objPHPExcel->getActiveSheet()->getStyle('I' . ($i + 2))->getFill()->getStartColor()->setRGB('FFFFA1');
                        $objPHPExcel->getActiveSheet()->getStyle('J' . ($i + 2))->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
                        $objPHPExcel->getActiveSheet()->getStyle('J' . ($i + 2))->getFill()->getStartColor()->setRGB('FFFFA1');
                    }
                }
                $objPHPExcel->getActiveSheet()->freezePane('A2');
                $styleArray = array('borders' => array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array('rgb' => '000000'))));
                $objPHPExcel->getActiveSheet()->getStyle('A1:J' . ($i + 1))->applyFromArray($styleArray);
                $objPHPExcel->getActiveSheet()->getStyle('A1:J' . ($i + 1))->getFont()->setSize(14);
                $objPHPExcel->getActiveSheet()->getStyle('A1:J' . ($i + 1))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
                $objPHPExcel->getActiveSheet()->getStyle('A1:J1')->getFont()->setBold(true);
                $objPHPExcel->getActiveSheet()->getStyle('A1:J1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
                $objPHPExcel->getActiveSheet()->getStyle('A1:J1')->getFill()->getStartColor()->setRGB('0057AF');
                $objPHPExcel->getActiveSheet()->getStyle('A1:J1')->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_WHITE);
                $this->AutoWidthColumn($objPHPExcel->getActiveSheet(), 0, 9, $i + 1);
                $objPHPExcel->getActiveSheet()->getProtection()->setPassword(substr(hash('sha512', rand()), 0, 12));
                $objPHPExcel->getActiveSheet()->getProtection()->setSheet(true);
                $objPHPExcel->getActiveSheet()->getProtection()->setFormatCells(true);
                $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddFooter('&L&D, &T &R &P / &N');
                /*		SHORT INFO TO PRINT	*/
                $SheetCount = $objPHPExcel->getSheetCount();
                $objPHPExcel->createSheet(NULL, $SheetCount);
                $objPHPExcel->setActiveSheetIndex($SheetCount);
                $objPHPExcel->getActiveSheet()->setTitle(get_string('short_summary', 'quiz_nitroreportpdf'));
                $objPHPExcel->getActiveSheet()->setCellValue('A1', get_string('on', 'quiz_nitroreportpdf'))->setCellValue('B1', get_string('surname', 'quiz_nitroreportpdf'))->setCellValue('C1', get_string('name', 'quiz_nitroreportpdf'))->setCellValue('D1', get_string('username', 'quiz_nitroreportpdf'))->setCellValue('E1', get_string('sum_points2', 'quiz_nitroreportpdf'))->setCellValue('F1', get_string('points_precent', 'quiz_nitroreportpdf'))->setCellValue('G1', get_string('points_avg', 'quiz_nitroreportpdf'))->setCellValue('H1', get_string('min_points', 'quiz_nitroreportpdf'))->setCellValue('I1', get_string('max_points', 'quiz_nitroreportpdf'))->setCellValue('J1', get_string('grade', 'quiz_nitroreportpdf'))->setCellValue('K1', get_string('notes', 'quiz_nitroreportpdf'));
                $objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(19.83);
                for ($i = 0; $i < count($tab_userids); $i++) {
                    $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $i + 1)->setCellValue('B' . ($i + 2), $tab_users[$tab_userids[$i]]['surname'])->setCellValue('C' . ($i + 2), $tab_users[$tab_userids[$i]]['name'])->setCellValue('D' . ($i + 2), $tab_users[$tab_userids[$i]]['username'])->setCellValue('E' . ($i + 2), $tab_users[$tab_userids[$i]]['sum_points'])->setCellValue('G' . ($i + 2), $tab_users[$tab_userids[$i]]['precent'])->setCellValue('F' . ($i + 2), $tab_users[$tab_userids[$i]]['avg'])->setCellValue('H' . ($i + 2), min($tab_users[$tab_userids[$i]]['attempt']))->setCellValue('I' . ($i + 2), max($tab_users[$tab_userids[$i]]['attempt']))->setCellValue('J' . ($i + 2), strip_tags($tab_users[$tab_userids[$i]]['feedback']));
                    $objPHPExcel->getActiveSheet()->getRowDimension($i + 2)->setRowHeight(19.83);
                    if ($i % 2 == 1) {
                        $objPHPExcel->getActiveSheet()->getStyle('A' . ($i + 2))->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
                        $objPHPExcel->getActiveSheet()->getStyle('A' . ($i + 2))->getFill()->getStartColor()->setRGB('FFFFA1');
                        $objPHPExcel->getActiveSheet()->getStyle('B' . ($i + 2))->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
                        $objPHPExcel->getActiveSheet()->getStyle('B' . ($i + 2))->getFill()->getStartColor()->setRGB('FFFFA1');
                        $objPHPExcel->getActiveSheet()->getStyle('C' . ($i + 2))->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
                        $objPHPExcel->getActiveSheet()->getStyle('C' . ($i + 2))->getFill()->getStartColor()->setRGB('FFFFA1');
                        $objPHPExcel->getActiveSheet()->getStyle('D' . ($i + 2))->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
                        $objPHPExcel->getActiveSheet()->getStyle('D' . ($i + 2))->getFill()->getStartColor()->setRGB('FFFFA1');
                        $objPHPExcel->getActiveSheet()->getStyle('E' . ($i + 2))->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
                        $objPHPExcel->getActiveSheet()->getStyle('E' . ($i + 2))->getFill()->getStartColor()->setRGB('FFFFA1');
                        $objPHPExcel->getActiveSheet()->getStyle('F' . ($i + 2))->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
                        $objPHPExcel->getActiveSheet()->getStyle('F' . ($i + 2))->getFill()->getStartColor()->setRGB('FFFFA1');
                        $objPHPExcel->getActiveSheet()->getStyle('G' . ($i + 2))->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
                        $objPHPExcel->getActiveSheet()->getStyle('G' . ($i + 2))->getFill()->getStartColor()->setRGB('FFFFA1');
                        $objPHPExcel->getActiveSheet()->getStyle('H' . ($i + 2))->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
                        $objPHPExcel->getActiveSheet()->getStyle('H' . ($i + 2))->getFill()->getStartColor()->setRGB('FFFFA1');
                        $objPHPExcel->getActiveSheet()->getStyle('I' . ($i + 2))->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
                        $objPHPExcel->getActiveSheet()->getStyle('I' . ($i + 2))->getFill()->getStartColor()->setRGB('FFFFA1');
                        $objPHPExcel->getActiveSheet()->getStyle('J' . ($i + 2))->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
                        $objPHPExcel->getActiveSheet()->getStyle('J' . ($i + 2))->getFill()->getStartColor()->setRGB('FFFFA1');
                        $objPHPExcel->getActiveSheet()->getStyle('K' . ($i + 2))->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
                        $objPHPExcel->getActiveSheet()->getStyle('K' . ($i + 2))->getFill()->getStartColor()->setRGB('FFFFA1');
                    }
                }
                $objPHPExcel->getActiveSheet()->freezePane('A2');
                $styleArray = array('borders' => array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array('rgb' => '000000'))));
                $objPHPExcel->getActiveSheet()->getStyle('A1:K' . ($i + 1))->applyFromArray($styleArray);
                $objPHPExcel->getActiveSheet()->getStyle('A1:K' . ($i + 1))->getFont()->setSize(14);
                $objPHPExcel->getActiveSheet()->getStyle('A1:K' . ($i + 1))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
                $objPHPExcel->getActiveSheet()->getStyle('A1:K1')->getFont()->setBold(true);
                $objPHPExcel->getActiveSheet()->getStyle('A1:K1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
                $objPHPExcel->getActiveSheet()->getStyle('A1:K1')->getFill()->getStartColor()->setRGB('0057AF');
                $objPHPExcel->getActiveSheet()->getStyle('A1:K1')->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_WHITE);
                $objPHPExcel->getActiveSheet()->getStyle('A1:K' . ($i + 1))->getAlignment()->setWrapText(false);
                $this->AutoWidthColumn($objPHPExcel->getActiveSheet(), 0, 9, $i + 1);
                $objPHPExcel->getActiveSheet()->getProtection()->setPassword(substr(hash('sha512', rand()), 0, 12));
                $objPHPExcel->getActiveSheet()->getProtection()->setSheet(true);
                $objPHPExcel->getActiveSheet()->getProtection()->setFormatCells(true);
                $objPHPExcel->getActiveSheet()->getStyle('K2:K' . ($i + 1))->getProtection()->setLocked(PHPExcel_Style_Protection::PROTECTION_UNPROTECTED);
                $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddFooter('&L&D, &T &R &P / &N');
            }
            // ADD DECLARATION PAGE
            if (get_config('quiz_nitroreportpdf', 'declaration') == 'DECLARATION_MUSTBE' || $_POST['declaration'] == 1) {
                $mpdf->AddPage();
                $mpdf->Bookmark(get_string('declaration_dontaccess', 'quiz_nitroreportpdf'), 0);
                $NREQ = '
	<p style="margin-left: auto; margin-right: auto;text-transform:uppercase;"><h2>' . get_string('declaration_dontaccess', 'quiz_nitroreportpdf') . '</h2></p>
	<br />
	<p style="text-align: justify;">' . get_string('declaration_dontaccess_desc', 'quiz_nitroreportpdf') . '</p>
	<br /><br />
	' . get_string('declaration_authorrights', 'quiz_nitroreportpdf') . ':<br />
	' . get_config('quiz_nitroreportpdf', 'contact') . '
	<br />
	' . get_string('wwwmoodleplatform', 'quiz_nitroreportpdf') . ': ' . $CFG->wwwroot . '
	<br /><br />
	' . get_string('declaration_accessexclude', 'quiz_nitroreportpdf') . '.';
                $mpdf->WriteHTML($NREQ);
                if ($generate_html_file) {
                    $html_contents .= $NREQ;
                }
            }
            echo '<script>document.getElementById(\'nitroreportpdf_text\').style.display = \'none\';</script>';
            echo '<script>document.getElementById(\'nitroreportpdf_progress\').style.display = \'none\';</script>';
            echo '<script>document.getElementById("nitro_submit").disabled=false;</script>';
            $pdffile = preg_replace(array('/\\\\/', '/\\//', '/\\:/', '/\\*/', '/\\?/', '/\\"/', '/\\</', '/\\>/', '/\\|/', "/\t/", "/\\s/"), '', $info_quiz->name . '_' . $info_course->fullname . '_' . date('d-m-Y-H-i-s'));
            $mpdf->Output($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $pdffile . '.pdf', 'F');
            $fs = get_file_storage();
            $context = context_user::instance($USER->id);
            $fs->create_directory($context->id, 'user', 'private', 0, '/NRPDF_Reports/', $USER->id);
            $fs->create_file_from_pathname(array('contextid' => $context->id, 'component' => 'user', 'filearea' => 'private', 'itemid' => 0, 'filepath' => '/NRPDF_Reports/', 'filename' => $pdffile . '.pdf', 'timecreated' => time(), 'timemodified' => time(), 'userid' => $USER->id), $CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $pdffile . '.pdf');
            if ($GENERATE_EXCEL) {
                $objPHPExcel->getSheet(0)->setSheetState(PHPExcel_Worksheet::SHEETSTATE_HIDDEN);
                $objPHPExcel->setActiveSheetIndex($objPHPExcel->getSheetCount() - 1);
                $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
                $objWriter->save($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $pdffile . '.xlsx');
                $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
                $objWriter->save($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $pdffile . '.xls');
                $fs->create_file_from_pathname(array('contextid' => $context->id, 'component' => 'user', 'filearea' => 'private', 'itemid' => 0, 'filepath' => '/NRPDF_Reports/', 'filename' => $pdffile . '.xlsx', 'timecreated' => time(), 'timemodified' => time(), 'userid' => $USER->id), $CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $pdffile . '.xlsx');
                $fs->create_file_from_pathname(array('contextid' => $context->id, 'component' => 'user', 'filearea' => 'private', 'itemid' => 0, 'filepath' => '/NRPDF_Reports/', 'filename' => $pdffile . '.xls', 'timecreated' => time(), 'timemodified' => time(), 'userid' => $USER->id), $CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $pdffile . '.xls');
            }
            /////////////////////////////////////////////////////////
            //GENERATE ZIP
            if ($_POST['generate_zip']) {
                $isoffline = false;
                if ($_POST['zip_type'] == "offline") {
                    if (file_exists($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/nrpdf_prepack.zip')) {
                        $isoffline = true;
                    }
                }
                $zip = new ZipArchive();
                $towrite = '<meta charset="utf-8">';
                if (!$isoffline) {
                    $towrite .= '<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
		<script src="http://nitro2010.github.io/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
		<link href="http://vjs.zencdn.net/4.12/video-js.css" rel="stylesheet">
		<script src="http://vjs.zencdn.net/4.12/video.js"></script>
		<link href="http://nitro2010.github.io/video-js/video-js.css" rel="stylesheet">
		<script src="http://nitro2010.github.io/video-js/video.js"></script>
		<script src="http://nitro2010.github.io/video-js/vjs.youtube.js"></script>
		<script src="http://nitro2010.github.io/video-js/vjs.vimeo.js"></script>
		<script src="http://nitro2010.github.io/video-js/vjs.dailymotion.js"></script>
		<script src="http://nitro2010.github.io/video-js/media.soundcloud.js"></script>
		<script>
			videojs.options.flash.swf = "http://nitro2010.github.io/video-js/video-js.swf"
		</script>
		<script type="text/javascript" src="http://nitro2010.github.io/bgp/bpgdec8.js"></script>
		<script type="text/javascript" src="http://nitro2010.github.io/bgp/bpgdec.js"></script>
		<script type="text/javascript" src="http://nitro2010.github.io/bgp/bpgdec8a.js"></script>';
                    $name = md5(uniqid());
                    $zip->open($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $name . '.zip', ZIPARCHIVE::CREATE);
                } else {
                    $towrite = '<script type="text/javascript" src="js/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
		<script type="text/javascript" src="js/video-js/video-js.css"></script>
		<script type="text/javascript" src="js/video-js/video.js"></script>
		<script type="text/javascript" src="js/video-js/vjs.youtube.js"></script>
		<script type="text/javascript" src="js/video-js/vjs.vimeo.js"></script>
		<script type="text/javascript" src="js/video-js/vjs.dailymotion.js"></script>
		<script type="text/javascript" src="js/video-js/media.soundcloud.js"></script>
		<script>
			videojs.options.flash.swf = "js/video-js/video-js.swf"
		</script>
		<script type="text/javascript" src="js/bpg/bpgdec8.js"></script>
		<script type="text/javascript" src="js/bpg/bpgdec.js"></script>
		<script type="text/javascript" src="js/bpg/bpgdec8a.js"></script>';
                    $name = md5(uniqid());
                    copy($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/nrpdf_prepack.zip', $CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $name . '.zip');
                    $zip->open($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $name . '.zip');
                }
                $towrite .= $html_contents;
                $zip->addEmptyDir('files');
                $audio[] = array('ext' => 'mp3', 'type' => 'audio/mp3');
                $audio[] = array('ext' => 'webm', 'type' => 'audio/webm');
                $audio[] = array('ext' => 'ogg', 'type' => 'audio/ogg');
                $audio[] = array('ext' => 'wav', 'type' => 'audio/wave');
                $video[] = array('ext' => 'webm', 'type' => 'video/webm');
                $video[] = array('ext' => 'ogg', 'type' => 'video/ogg');
                $video[] = array('ext' => 'mp4', 'type' => 'video/mp4');
                $image = array('png', 'jpg', 'gif', 'bpg');
                for ($a = 0; $a < count($audio); $a++) {
                    preg_match_all('/<a.*".*\\/mod\\/quiz\\/report\\/nitroreportpdf\\/cache\\/(.*).' . $audio[$a]['ext'] . '".*<\\/a>/Ui', $towrite, $found);
                    for ($i = 0; $i < count($found[0]); $i++) {
                        $zip->addFile($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $found[1][$i] . '.' . $audio[$a]['ext'], 'files/' . pathinfo($found[1][$i])['filename'] . '.' . $audio[$a]['ext']);
                        $towrite = str_replace($found[0][$i], '<audio id="' . uniqid() . '" class="video-js vjs-default-skin" controls preload="auto" width="640" height="264"> <source src="files/' . pathinfo($found[1][$i])['filename'] . '.' . $audio[$a]['ext'] . '"  type="' . $audio[$a]['type'] . '" /></audio>', $towrite);
                    }
                    preg_match_all('/<.*".*\\/mod\\/quiz\\/report\\/nitroreportpdf\\/cache\\/(.*).' . $audio[$a]['ext'] . '".*>/Ui', $towrite, $found);
                    for ($i = 0; $i < count($found[0]); $i++) {
                        $zip->addFile($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $found[1][$i] . '.' . $audio[$a]['ext'], 'files/' . pathinfo($found[1][$i])['filename'] . '.' . $audio[$a]['ext']);
                        $towrite = str_replace($found[0][$i], '<audio id="' . uniqid() . '"  class="video-js vjs-default-skin" controls preload="auto" width="640" height="264"> <source src="files/' . pathinfo($found[1][$i])['filename'] . '.' . $audio[$a]['ext'] . '"  type="' . $audio[$a]['type'] . '" /></audio>', $towrite);
                    }
                }
                for ($a = 0; $a < count($video); $a++) {
                    preg_match_all('/<a.*".*\\/mod\\/quiz\\/report\\/nitroreportpdf\\/cache\\/(.*).' . $video[$a]['ext'] . '".*<\\/a>/Ui', $towrite, $found);
                    for ($i = 0; $i < count($found[0]); $i++) {
                        $zip->addFile($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $found[1][$i] . '.' . $video[$a]['ext'], 'files/' . pathinfo($found[1][$i])['filename'] . '.' . $video[$a]['ext']);
                        $towrite = str_replace($found[0][$i], '<video id="' . uniqid() . '"   class="video-js vjs-default-skin" controls preload="auto" width="320" height="264"> <source src="files/' . pathinfo($found[1][$i])['filename'] . '.' . $video[$a]['ext'] . '"  type="' . $video[$a]['type'] . '" /></video>', $towrite);
                    }
                    preg_match_all('/<.*".*\\/mod\\/quiz\\/report\\/nitroreportpdf\\/cache\\/(.*).' . $video[$a]['ext'] . '".*>/Ui', $towrite, $found);
                    for ($i = 0; $i < count($found[0]); $i++) {
                        $zip->addFile($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $found[1][$i] . '.' . $video[$a]['ext'], 'files/' . pathinfo($found[1][$i])['filename'] . '.' . $video[$a]['ext']);
                        $towrite = str_replace($found[0][$i], '<video id="' . uniqid() . '"   class="video-js vjs-default-skin" controls preload="auto" width="320" height="264"> <source src="files/' . pathinfo($found[1][$i])['filename'] . '.' . $video[$a]['ext'] . '"  type="' . $video[$a]['type'] . '" /></video>', $towrite);
                    }
                }
                for ($a = 0; $a < count($image); $a++) {
                    preg_match_all('/<img.*".*\\/mod\\/quiz\\/report\\/nitroreportpdf\\/cache\\/(.*).' . $image[$a] . '".*>/Ui', $towrite, $found);
                    for ($i = 0; $i < count($found[0]); $i++) {
                        $zip->addFile($CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $found[1][$i] . '.' . $image[$a], 'files/' . pathinfo($found[1][$i])['filename'] . '.' . $image[$a]);
                        $towrite = str_replace($found[0][$i], '<img src="files/' . pathinfo($found[1][$i])['filename'] . '.' . $image[$a] . '" />', $towrite);
                    }
                }
                //YT
                preg_match_all('/<a.*".*(youtu\\.be|youtube).*".*<\\/a>/Ui', $towrite, $found);
                for ($a = 0; $a < count($found); $a++) {
                    $f = $found[0][$a];
                    preg_match('/<a.*"(.*)".*<\\/a>/Ui', $f, $found2);
                    $towrite = str_replace($found2[0], '<video id="' . uniqid() . '" src="" class="video-js vjs-default-skin" controls preload="auto" width="640" height="360" data-setup=\'{ "techOrder": ["youtube"], "src": "' . $found2[1] . '" }\'></video>', $towrite);
                }
                //VIMEO
                preg_match_all('/<a.*".*(vimeo).*".*<\\/a>/Ui', $towrite, $found);
                for ($a = 0; $a < count($found); $a++) {
                    $f = $found[0][$a];
                    preg_match('/<a.*"(.*)".*<\\/a>/Ui', $f, $found2);
                    $towrite = str_replace($found2[0], '<video id="' . uniqid() . '" src="" class="video-js vjs-default-skin" controls preload="auto" width="640" height="360" data-setup=\'{ "techOrder": ["vimeo"], "src": "' . $found2[1] . '" }\'></video>', $towrite);
                }
                //dailymotion
                preg_match_all('/<a.*".*(dailymotion).*".*<\\/a>/Ui', $towrite, $found);
                for ($a = 0; $a < count($found); $a++) {
                    $f = $found[0][$a];
                    preg_match('/<a.*"(.*)".*<\\/a>/Ui', $f, $found2);
                    $towrite = str_replace($found2[0], '<video id="' . uniqid() . '" src="" class="video-js vjs-default-skin" controls preload="auto" width="640" height="360" data-setup=\'{ "techOrder": ["dailymotion"], "src": "' . $found2[1] . '" }\'></video>', $towrite);
                }
                //soundcloud
                preg_match_all('/<a.*".*(soundcloud).*".*<\\/a>/Ui', $towrite, $found);
                for ($a = 0; $a < count($found); $a++) {
                    $f = $found[0][$a];
                    preg_match('/<a.*"(.*)".*<\\/a>/Ui', $f, $found2);
                    $towrite = str_replace($found2[0], '<video id="' . uniqid() . '" src="" class="video-js vjs-default-skin" controls preload="auto" width="640" height="360" data-setup=\'{ "techOrder": ["soundcloud"], "src": "' . $found2[1] . '" }\'></video>', $towrite);
                }
                //add index.html
                $zip->addFromString('index.html', $towrite);
                $zip->close();
                $fs->create_file_from_pathname(array('contextid' => $context->id, 'component' => 'user', 'filearea' => 'private', 'itemid' => 0, 'filepath' => '/NRPDF_Reports/', 'filename' => $pdffile . '.zip', 'timecreated' => time(), 'timemodified' => time(), 'userid' => $USER->id), $CFG->dirroot . '/mod/quiz/report/nitroreportpdf/cache/' . $name . '.zip');
            }
            /////////////////////////////////////////////////////////
            echo '<br /><br /><br />' . get_string('files_are_generated', 'quiz_nitroreportpdf') . '! <a href="' . $CFG->wwwroot . '/user/files.php" target="_blank">' . get_string('ucandownloadfromprivatearea', 'quiz_nitroreportpdf') . '.</a><br />';
            $tab_quiz_sum = 0;
            foreach ($tab_quiz as $id => $ext) {
                $tab_quiz_sum += max($ext['points']);
            }
            $tab_quiz_sum = number_format($tab_quiz_sum, 4, '.', '');
            if ($maxpoints != $tab_quiz_sum) {
                echo '<br /><br /><br /><span style="color:red;\\">' . get_string('warning1', 'quiz_nitroreportpdf') . '</span>';
            }
        }
    }
Пример #14
0
 private static function ExcelApplyValues($sheet, $rows, $params = [])
 {
     /* Границы таблицы */
     $ramka = array('borders' => array('allborders' => array('style' => \PHPExcel_Style_Border::BORDER_THIN)));
     /* Жирный шрифт для шапки таблицы */
     $font = array('font' => array('bold' => true), 'alignment' => array('horizontal' => \PHPExcel_Style_Alignment::HORIZONTAL_CENTER));
     $Matlog = new Matlog();
     $Employeelog = new Employeelog();
     $Traflog = new Traflog();
     $attributeslabels = array_merge($Matlog->attributeLabels(), $Employeelog->attributeLabels(), $Traflog->attributeLabels());
     if (count($rows) > 0) {
         $col = 0;
         foreach (array_keys($rows[0]) as $attr) {
             if (!in_array($attr, ['idmatlog', 'idemployeelog'])) {
                 $sheet->setCellValueByColumnAndRow($col, 1, $attributeslabels[$attr]);
                 $sheet->getStyleByColumnAndRow($col, 1)->applyFromArray($ramka);
                 $sheet->getStyleByColumnAndRow($col, 1)->applyFromArray($font);
                 $col++;
             }
         }
     }
     if (count($rows) > 0) {
         foreach ($rows as $i => $row) {
             $col = 0;
             foreach ($row as $attr => $value) {
                 if (!in_array($attr, ['idmatlog', 'idemployeelog'])) {
                     if (isset($params['date']) && in_array($attr, $params['date']) && $value !== NULL) {
                         $rows[$i][$attr] = date('d.m.Y', strtotime($value));
                     }
                     if (isset($params['datetime']) && in_array($attr, $params['datetime']) && $value !== NULL) {
                         $rows[$i][$attr] = date('d.m.Y H:i:s', strtotime($value));
                     }
                     if (isset($params['case']) && in_array($attr, array_keys($params['case']))) {
                         $rows[$i][$attr] = $params['case'][$attr][$value];
                     }
                     $sheet->getStyleByColumnAndRow($col, $i + 2)->applyFromArray($ramka);
                     if (isset($params['string']) && in_array($attr, $params['string'])) {
                         $sheet->getStyleByColumnAndRow($col, $i + 2)->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
                         $sheet->setCellValueExplicitByColumnAndRow($col, $i + 2, $rows[$i][$attr], \PHPExcel_Cell_DataType::TYPE_STRING);
                     } else {
                         $sheet->setCellValueByColumnAndRow($col, $i + 2, $rows[$i][$attr]);
                     }
                     $col++;
                 }
             }
         }
     }
     if (count($rows) > 0) {
         $c = count(array_keys($rows[0]));
         // ??????????????????
         /* Авторазмер колонок Excel */
         \PHPExcel_Shared_Font::setAutoSizeMethod(\PHPExcel_Shared_Font::AUTOSIZE_METHOD_EXACT);
         foreach (range(0, $c) as $col) {
             $sheet->getColumnDimensionByColumn($col)->setAutoSize(true);
             $sheet->calculateColumnWidths();
             if ($sheet->getColumnDimensionByColumn($col)->getWidth() > 70) {
                 $sheet->getColumnDimensionByColumn($col)->setAutoSize(false);
                 $sheet->getColumnDimensionByColumn($col)->setWidth(70);
             }
         }
     }
 }
Пример #15
0
 /**
  * Add data to the beginning of the workbook (note the reverse order)
  * and to the end of the workbook.
  *
  * @access public
  * @see PHPExcel_Writer_Excel5_Workbook::storeWorkbook()
  */
 function close()
 {
     $_phpSheet = $this->_phpSheet;
     $num_sheets = $_phpSheet->getParent()->getSheetCount();
     // Write BOF record
     $this->_storeBof(0x10);
     // Write PRINTHEADERS
     $this->_writePrintHeaders();
     // Write PRINTGRIDLINES
     $this->_writePrintGridlines();
     // Write GRIDSET
     $this->_writeGridset();
     // Calculate column widths
     $_phpSheet->calculateColumnWidths();
     // Column dimensions
     if (($defaultWidth = $_phpSheet->getDefaultColumnDimension()->getWidth()) < 0) {
         $defaultWidth = PHPExcel_Shared_Font::getDefaultColumnWidthByFont($_phpSheet->getParent()->getDefaultStyle()->getFont());
     }
     $columnDimensions = $_phpSheet->getColumnDimensions();
     $maxCol = $this->_lastColumnIndex - 1;
     for ($i = 0; $i <= $maxCol; ++$i) {
         $hidden = 0;
         $level = 0;
         $xfIndex = 15;
         // there are 15 cell style Xfs
         $width = $defaultWidth;
         $columnLetter = PHPExcel_Cell::stringFromColumnIndex($i);
         if (isset($columnDimensions[$columnLetter])) {
             $columnDimension = $columnDimensions[$columnLetter];
             if ($columnDimension->getWidth() >= 0) {
                 $width = $columnDimension->getWidth();
             }
             $hidden = $columnDimension->getVisible() ? 0 : 1;
             $level = $columnDimension->getOutlineLevel();
             $xfIndex = $columnDimension->getXfIndex() + 15;
             // there are 15 cell style Xfs
         }
         // Components of _colinfo:
         // $firstcol first column on the range
         // $lastcol  last column on the range
         // $width	width to set
         // $xfIndex  The optional cell style Xf index to apply to the columns
         // $hidden   The optional hidden atribute
         // $level	The optional outline level
         $this->_colinfo[] = array($i, $i, $width, $xfIndex, $hidden, $level);
     }
     // Write GUTS
     $this->_writeGuts();
     // Write DEFAULTROWHEIGHT
     $this->_writeDefaultRowHeight();
     // Write WSBOOL
     $this->_writeWsbool();
     // Write horizontal and vertical page breaks
     $this->_writeBreaks();
     // Write page header
     $this->_writeHeader();
     // Write page footer
     $this->_writeFooter();
     // Write page horizontal centering
     $this->_writeHcenter();
     // Write page vertical centering
     $this->_writeVcenter();
     // Write left margin
     $this->_writeMarginLeft();
     // Write right margin
     $this->_writeMarginRight();
     // Write top margin
     $this->_writeMarginTop();
     // Write bottom margin
     $this->_writeMarginBottom();
     // Write page setup
     $this->_writeSetup();
     // Write sheet protection
     $this->_writeProtect();
     // Write SCENPROTECT
     $this->_writeScenProtect();
     // Write OBJECTPROTECT
     $this->_writeObjectProtect();
     // Write sheet password
     $this->_writePassword();
     // Write DEFCOLWIDTH record
     $this->_writeDefcol();
     // Write the COLINFO records if they exist
     if (!empty($this->_colinfo)) {
         $colcount = count($this->_colinfo);
         for ($i = 0; $i < $colcount; ++$i) {
             $this->_writeColinfo($this->_colinfo[$i]);
         }
     }
     $autoFilterRange = $_phpSheet->getAutoFilter()->getRange();
     if (!empty($autoFilterRange)) {
         // Write AUTOFILTERINFO
         $this->_writeAutoFilterInfo();
     }
     // Write sheet dimensions
     $this->_writeDimensions();
     // Row dimensions
     foreach ($_phpSheet->getRowDimensions() as $rowDimension) {
         $xfIndex = $rowDimension->getXfIndex() + 15;
         // there are 15 cellXfs
         $this->_writeRow($rowDimension->getRowIndex() - 1, $rowDimension->getRowHeight(), $xfIndex, $rowDimension->getVisible() ? '0' : '1', $rowDimension->getOutlineLevel());
     }
     // Write Cells
     foreach ($_phpSheet->getCellCollection() as $cellID) {
         $cell = $_phpSheet->getCell($cellID);
         $row = $cell->getRow() - 1;
         $column = PHPExcel_Cell::columnIndexFromString($cell->getColumn()) - 1;
         // Don't break Excel!
         //			if ($row + 1 > 65536 or $column + 1 > 256) {
         if ($row > 65535 || $column > 255) {
             break;
         }
         // Write cell value
         $xfIndex = $cell->getXfIndex() + 15;
         // there are 15 cell style Xfs
         $cVal = $cell->getValue();
         if ($cVal instanceof PHPExcel_RichText) {
             // $this->_writeString($row, $column, $cVal->getPlainText(), $xfIndex);
             $arrcRun = array();
             $str_len = PHPExcel_Shared_String::CountCharacters($cVal->getPlainText(), 'UTF-8');
             $str_pos = 0;
             $elements = $cVal->getRichTextElements();
             foreach ($elements as $element) {
                 // FONT Index
                 if ($element instanceof PHPExcel_RichText_Run) {
                     $str_fontidx = $this->_fntHashIndex[$element->getFont()->getHashCode()];
                 } else {
                     $str_fontidx = 0;
                 }
                 $arrcRun[] = array('strlen' => $str_pos, 'fontidx' => $str_fontidx);
                 // Position FROM
                 $str_pos += PHPExcel_Shared_String::CountCharacters($element->getText(), 'UTF-8');
             }
             $this->_writeRichTextString($row, $column, $cVal->getPlainText(), $xfIndex, $arrcRun);
         } else {
             switch ($cell->getDatatype()) {
                 case PHPExcel_Cell_DataType::TYPE_STRING:
                 case PHPExcel_Cell_DataType::TYPE_NULL:
                     if ($cVal === '' || $cVal === null) {
                         $this->_writeBlank($row, $column, $xfIndex);
                     } else {
                         $this->_writeString($row, $column, $cVal, $xfIndex);
                     }
                     break;
                 case PHPExcel_Cell_DataType::TYPE_NUMERIC:
                     $this->_writeNumber($row, $column, $cVal, $xfIndex);
                     break;
                 case PHPExcel_Cell_DataType::TYPE_FORMULA:
                     $calculatedValue = $this->_preCalculateFormulas ? $cell->getCalculatedValue() : null;
                     $this->_writeFormula($row, $column, $cVal, $xfIndex, $calculatedValue);
                     break;
                 case PHPExcel_Cell_DataType::TYPE_BOOL:
                     $this->_writeBoolErr($row, $column, $cVal, 0, $xfIndex);
                     break;
                 case PHPExcel_Cell_DataType::TYPE_ERROR:
                     $this->_writeBoolErr($row, $column, self::_mapErrorCode($cVal), 1, $xfIndex);
                     break;
             }
         }
     }
     // Append
     $this->_writeMsoDrawing();
     // Write WINDOW2 record
     $this->_writeWindow2();
     // Write PLV record
     $this->_writePageLayoutView();
     // Write ZOOM record
     $this->_writeZoom();
     if ($_phpSheet->getFreezePane()) {
         $this->_writePanes();
     }
     // Write SELECTION record
     $this->_writeSelection();
     // Write MergedCellsTable Record
     $this->_writeMergedCells();
     // Hyperlinks
     foreach ($_phpSheet->getHyperLinkCollection() as $coordinate => $hyperlink) {
         list($column, $row) = PHPExcel_Cell::coordinateFromString($coordinate);
         $url = $hyperlink->getUrl();
         if (strpos($url, 'sheet://') !== false) {
             // internal to current workbook
             $url = str_replace('sheet://', 'internal:', $url);
         } else {
             if (preg_match('/^(http:|https:|ftp:|mailto:)/', $url)) {
                 // URL
                 // $url = $url;
             } else {
                 // external (local file)
                 $url = 'external:' . $url;
             }
         }
         $this->_writeUrl($row - 1, PHPExcel_Cell::columnIndexFromString($column) - 1, $url);
     }
     $this->_writeDataValidity();
     $this->_writeSheetLayout();
     // Write SHEETPROTECTION record
     $this->_writeSheetProtection();
     $this->_writeRangeProtection();
     $arrConditionalStyles = $_phpSheet->getConditionalStylesCollection();
     if (!empty($arrConditionalStyles)) {
         $arrConditional = array();
         // @todo CFRule & CFHeader
         // Write CFHEADER record
         $this->_writeCFHeader();
         // Write ConditionalFormattingTable records
         foreach ($arrConditionalStyles as $cellCoordinate => $conditionalStyles) {
             foreach ($conditionalStyles as $conditional) {
                 if ($conditional->getConditionType() == PHPExcel_Style_Conditional::CONDITION_EXPRESSION || $conditional->getConditionType() == PHPExcel_Style_Conditional::CONDITION_CELLIS) {
                     if (!in_array($conditional->getHashCode(), $arrConditional)) {
                         $arrConditional[] = $conditional->getHashCode();
                         // Write CFRULE record
                         $this->_writeCFRule($conditional);
                     }
                 }
             }
         }
     }
     $this->_storeEof();
 }
Пример #16
0
 /**
  * Build CSS styles
  *
  * @param	boolean	$generateSurroundingHTML	Generate surrounding HTML style? (html { })
  * @return	array
  * @throws	PHPExcel_Writer_Exception
  */
 public function buildCSS($generateSurroundingHTML = true)
 {
     // PHPExcel object known?
     if (is_null($this->_phpExcel)) {
         throw new PHPExcel_Writer_Exception('Internal PHPExcel object not set to an instance of an object.');
     }
     // Cached?
     if (!is_null($this->_cssStyles)) {
         return $this->_cssStyles;
     }
     // Ensure that spans have been calculated
     if (!$this->_spansAreCalculated) {
         $this->_calculateSpans();
     }
     // Construct CSS
     $css = array();
     // Start styles
     if ($generateSurroundingHTML) {
         // html { }
         $css['html']['font-family'] = 'Calibri, Arial, Helvetica, sans-serif';
         $css['html']['font-size'] = '11pt';
         $css['html']['background-color'] = 'white';
     }
     // table { }
     $css['table']['border-collapse'] = 'collapse';
     if (!$this->_isPdf) {
         $css['table']['page-break-after'] = 'always';
     }
     // .gridlines td { }
     $css['.gridlines td']['border'] = '1px dotted black';
     // .b {}
     $css['.b']['text-align'] = 'center';
     // BOOL
     // .e {}
     $css['.e']['text-align'] = 'center';
     // ERROR
     // .f {}
     $css['.f']['text-align'] = 'right';
     // FORMULA
     // .inlineStr {}
     $css['.inlineStr']['text-align'] = 'left';
     // INLINE
     // .n {}
     $css['.n']['text-align'] = 'right';
     // NUMERIC
     // .s {}
     $css['.s']['text-align'] = 'left';
     // STRING
     // Calculate cell style hashes
     foreach ($this->_phpExcel->getCellXfCollection() as $index => $style) {
         $css['td.style' . $index] = $this->_createCSSStyle($style);
     }
     // Fetch sheets
     $sheets = array();
     if (is_null($this->_sheetIndex)) {
         $sheets = $this->_phpExcel->getAllSheets();
     } else {
         $sheets[] = $this->_phpExcel->getSheet($this->_sheetIndex);
     }
     // Build styles per sheet
     foreach ($sheets as $sheet) {
         // Calculate hash code
         $sheetIndex = $sheet->getParent()->getIndex($sheet);
         // Build styles
         // Calculate column widths
         $sheet->calculateColumnWidths();
         // col elements, initialize
         $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($sheet->getHighestColumn()) - 1;
         $column = -1;
         while ($column++ < $highestColumnIndex) {
             $this->_columnWidths[$sheetIndex][$column] = 42;
             // approximation
             $css['table.sheet' . $sheetIndex . ' col.col' . $column]['width'] = '42pt';
         }
         // col elements, loop through columnDimensions and set width
         foreach ($sheet->getColumnDimensions() as $columnDimension) {
             if (($width = PHPExcel_Shared_Drawing::cellDimensionToPixels($columnDimension->getWidth(), $this->_defaultFont)) >= 0) {
                 $width = PHPExcel_Shared_Drawing::pixelsToPoints($width);
                 $column = PHPExcel_Cell::columnIndexFromString($columnDimension->getColumnIndex()) - 1;
                 $this->_columnWidths[$sheetIndex][$column] = $width;
                 $css['table.sheet' . $sheetIndex . ' col.col' . $column]['width'] = $width . 'pt';
                 if ($columnDimension->getVisible() === false) {
                     $css['table.sheet' . $sheetIndex . ' col.col' . $column]['visibility'] = 'collapse';
                     $css['table.sheet' . $sheetIndex . ' col.col' . $column]['*display'] = 'none';
                     // target IE6+7
                 }
             }
         }
         // Default row height
         $rowDimension = $sheet->getDefaultRowDimension();
         // table.sheetN tr { }
         $css['table.sheet' . $sheetIndex . ' tr'] = array();
         if ($rowDimension->getRowHeight() == -1) {
             $pt_height = PHPExcel_Shared_Font::getDefaultRowHeightByFont($this->_phpExcel->getDefaultStyle()->getFont());
         } else {
             $pt_height = $rowDimension->getRowHeight();
         }
         $css['table.sheet' . $sheetIndex . ' tr']['height'] = $pt_height . 'pt';
         if ($rowDimension->getVisible() === false) {
             $css['table.sheet' . $sheetIndex . ' tr']['display'] = 'none';
             $css['table.sheet' . $sheetIndex . ' tr']['visibility'] = 'hidden';
         }
         // Calculate row heights
         foreach ($sheet->getRowDimensions() as $rowDimension) {
             $row = $rowDimension->getRowIndex() - 1;
             // table.sheetN tr.rowYYYYYY { }
             $css['table.sheet' . $sheetIndex . ' tr.row' . $row] = array();
             if ($rowDimension->getRowHeight() == -1) {
                 $pt_height = PHPExcel_Shared_Font::getDefaultRowHeightByFont($this->_phpExcel->getDefaultStyle()->getFont());
             } else {
                 $pt_height = $rowDimension->getRowHeight();
             }
             $css['table.sheet' . $sheetIndex . ' tr.row' . $row]['height'] = $pt_height . 'pt';
             if ($rowDimension->getVisible() === false) {
                 $css['table.sheet' . $sheetIndex . ' tr.row' . $row]['display'] = 'none';
                 $css['table.sheet' . $sheetIndex . ' tr.row' . $row]['visibility'] = 'hidden';
             }
         }
     }
     // Cache
     if (is_null($this->_cssStyles)) {
         $this->_cssStyles = $css;
     }
     // Return
     return $css;
 }
Пример #17
0
 /**
  * Convert the height of a cell from user's units to pixels. By interpolation
  * the relationship is: y = 4/3x. If the height hasn't been set by the user we
  * use the default value. If the row is hidden we use a value of zero.
  *
  * @param PHPExcel_Worksheet $sheet The sheet
  * @param integer $row The row index (1-based)
  * @return integer The width in pixels
  */
 public static function sizeRow($sheet, $row = 1)
 {
     // default font of the workbook
     $font = $sheet->getParent()->getDefaultStyle()->getFont();
     $rowDimensions = $sheet->getRowDimensions();
     // first find the true row height in pixels (uncollapsed and unhidden)
     if (isset($rowDimensions[$row]) and $rowDimensions[$row]->getRowHeight() != -1) {
         // then we have a row dimension
         $rowDimension = $rowDimensions[$row];
         $rowHeight = $rowDimension->getRowHeight();
         $pixelRowHeight = (int) ceil(4 * $rowHeight / 3);
         // here we assume Arial 10
     } else {
         if ($sheet->getDefaultRowDimension()->getRowHeight() != -1) {
             // then we have a default row dimension with explicit height
             $defaultRowDimension = $sheet->getDefaultRowDimension();
             $rowHeight = $defaultRowDimension->getRowHeight();
             $pixelRowHeight = PHPExcel_Shared_Drawing::pointsToPixels($rowHeight);
         } else {
             // we don't even have any default row dimension. Height depends on default font
             $pointRowHeight = PHPExcel_Shared_Font::getDefaultRowHeightByFont($font);
             $pixelRowHeight = PHPExcel_Shared_Font::fontSizeToPixels($pointRowHeight);
         }
     }
     // now find the effective row height in pixels
     if (isset($rowDimensions[$row]) and !$rowDimensions[$row]->getVisible()) {
         $effectivePixelRowHeight = 0;
     } else {
         $effectivePixelRowHeight = $pixelRowHeight;
     }
     return $effectivePixelRowHeight;
 }
Пример #18
0
 /**
  * Calculate widths for auto-size columns
  *
  * @param  boolean  $calculateMergeCells  Calculate merge cell width
  * @return PHPExcel_Worksheet;
  */
 public function calculateColumnWidths($calculateMergeCells = false)
 {
     // initialize $autoSizes array
     $autoSizes = array();
     foreach ($this->getColumnDimensions() as $colDimension) {
         if ($colDimension->getAutoSize()) {
             $autoSizes[$colDimension->getColumnIndex()] = -1;
         }
     }
     // There is only something to do if there are some auto-size columns
     if (!empty($autoSizes)) {
         foreach ($this->getCellCollection(false) as $cell) {
             if (isset($autoSizes[$cell->getColumn()])) {
                 // Is merge cell?
                 $isMergeCell = false;
                 foreach ($this->getMergeCells() as $cells) {
                     if ($cell->isInRange($cells) && !$calculateMergeCells) {
                         $isMergeCell = true;
                         // do not calculate merge cells
                         break;
                     }
                 }
                 // Determine width
                 if (!$isMergeCell) {
                     // Calculated value
                     $cellValue = $cell->getCalculatedValue();
                     // To formatted string
                     $cellValue = PHPExcel_Style_NumberFormat::toFormattedString($cellValue, $this->getParent()->getCellXfByIndex($cell->getXfIndex())->getNumberFormat()->getFormatCode());
                     $autoSizes[$cell->getColumn()] = max((double) $autoSizes[$cell->getColumn()], (double) PHPExcel_Shared_Font::calculateColumnWidth($this->getParent()->getCellXfByIndex($cell->getXfIndex())->getFont(), $cellValue, $this->getParent()->getCellXfByIndex($cell->getXfIndex())->getAlignment()->getTextRotation(), $this->getDefaultStyle()->getFont()));
                 }
             }
         }
         // adjust column widths
         foreach ($autoSizes as $columnIndex => $width) {
             if ($width == -1) {
                 $width = $this->getDefaultColumnDimension()->getWidth();
             }
             $this->getColumnDimension($columnIndex)->setWidth($width);
         }
     }
     return $this;
 }
Пример #19
0
 protected function exportExcel($props)
 {
     $props = array_merge(array('title' => '', 'subtitle' => '', 'headers' => null, 'data' => null), $props);
     if ($props['subtitle']) {
         $props['title'] .= ' - ' . $props['subtitle'];
     }
     PHPExcel_Shared_Font::setAutoSizeMethod(PHPExcel_Shared_Font::AUTOSIZE_METHOD_EXACT);
     $logoPath = 'images/logo_academy.png';
     $props['doc'] = array_merge(array('title' => 'Carus', 'subject' => 'Reporte', 'description' => 'Reporte de sistema', 'keywords' => 'Reporte', 'category' => 'Reporte'), isset($props['doc']) && is_array($props['doc']) ? $props['doc'] : array());
     $title = preg_replace('/([^a-z0-9áéíóúàèìòùâêîôûñ\\-_ ]+)/i', '', isset($props['title']) ? $props['title'] : $props['doc']['title']);
     if (strlen($title) > 30) {
         $title = substr($title, 0, strripos($title, " ", 30 - strlen($title)));
     }
     $objPHPExcel = new PHPExcel();
     $objPHPExcel->getProperties()->setCreator("Imagen Digital")->setLastModifiedBy("Imagen Digital")->setTitle($props['doc']['title'])->setSubject($props['doc']['subject'])->setDescription($props['doc']['description'])->setKeywords($props['doc']['keywords'])->setCategory($props['doc']['category']);
     $objPHPExcel->setActiveSheetIndex(0);
     $objPHPExcel->getDefaultStyle()->getFont()->setName('Verdana')->setSize(8)->setColor(new PHPExcel_Style_Color('FF333333'));
     $sheet = $objPHPExcel->getActiveSheet();
     // Set page orientation, size, Print Area and Fit To Pages
     $objPageSetup = new PHPExcel_Worksheet_PageSetup();
     $objPageSetup->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER);
     $objPageSetup->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE);
     $objPageSetup->setFitToWidth(1);
     $sheet->setPageSetup($objPageSetup);
     $sheet->setTitle($title);
     $sheet->getDefaultStyle()->applyFromArray(array('alignment' => array('wrap' => false)));
     $objDrawing = new PHPExcel_Worksheet_Drawing();
     $objDrawing->setWorksheet($sheet);
     $objDrawing->setName("logo");
     $objDrawing->setDescription("Carus");
     $objDrawing->setPath($logoPath);
     $objDrawing->setCoordinates('A1');
     $objDrawing->setWidth(148);
     $objDrawing->setHeight(30);
     $sheet->getRowDimension(1)->setRowHeight(20);
     $styleTitle = array('font' => array('bold' => true, 'color' => array('rgb' => 'FFFFFFFF'), 'size' => 8, 'name' => 'Verdana'), 'fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('argb' => 'FF333333')), 'borders' => array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array('argb' => 'FF333333'))), 'alignment' => array('wrap' => false, 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER, 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER));
     $styleText = array('borders' => array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array('argb' => 'FF0B7C98'))), 'alignment' => array('vertical' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER));
     $col = 0;
     $fil = 3;
     $colMax = 0;
     $sheet->setCellValueByColumnAndRow($col, $fil, $title);
     $sheet->getStyleByColumnAndRow($col, $fil)->applyFromArray($styleTitle);
     $fil++;
     foreach ($props['headers'] as $value) {
         $sheet->setCellValueByColumnAndRow($col, $fil, $value);
         $sheet->getStyleByColumnAndRow($col, $fil)->applyFromArray($styleTitle);
         $col++;
     }
     $colMax = max($colMax, $col);
     $fil++;
     foreach ($props['data'] as $row) {
         $col = 0;
         foreach ($props['headers'] as $key => $value) {
             $sheet->setCellValueByColumnAndRow($col, $fil, $row[$value]);
             $sheet->getStyleByColumnAndRow($col, $fil)->applyFromArray($styleText);
             $col++;
         }
         $fil++;
     }
     $colMax = max($colMax, $col);
     $sheet->mergeCellsByColumnAndRow(0, 1, $colMax - 1, 1);
     $sheet->mergeCellsByColumnAndRow(0, 3, $colMax - 1, 3);
     for ($c = 0; $c < $colMax; $c++) {
         $sheet->getColumnDimensionByColumn($c)->setAutoSize(true);
         $calculatedWidth = $sheet->getColumnDimensionByColumn($c)->getWidth();
         $sheet->getColumnDimensionByColumn($c)->setAutoSize(false);
         $sheet->getColumnDimensionByColumn($c)->setWidth(max((int) $calculatedWidth * 1.05, 12));
     }
     $sheet->calculateColumnWidths();
     header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
     //header('Content-Type: application/vnd.ms-excel');
     header('Content-Disposition: attachment;filename="' . $title . '.xlsx"');
     header('Cache-Control: max-age=0');
     // If you're serving to IE 9, then the following may be needed
     header('Cache-Control: max-age=1');
     // If you're serving to IE over SSL, then the following may be needed
     header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
     // Date in the past
     header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
     // always modified
     header('Cache-Control: cache, must-revalidate');
     // HTTP/1.1
     header('Pragma: public');
     // HTTP/1.0
     $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
     //$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'HTML');
     $objWriter->save('php://output');
     exit;
 }
Пример #20
0
function smamo_excel_export($priv)
{
    $response = array();
    /** Error reporting */
    error_reporting(E_ALL);
    ini_set('display_errors', FALSE);
    ini_set('display_startup_errors', FALSE);
    date_default_timezone_set('Europe/Copenhagen');
    define('EOL', PHP_SAPI == 'cli' ? PHP_EOL : '<br />');
    /** Include PHPExcel */
    require_once get_template_directory() . '/functions/admin/phpexcel/PHPExcel.php';
    // Create new PHPExcel object
    $objPHPExcel = new PHPExcel();
    $titleTimeFormat = date_i18n('d-m-Y-H-i');
    // Set document properties
    //echo date('H:i:s') , " Set document properties" , EOL;
    $objPHPExcel->getProperties()->setCreator("FSTA Serveren")->setLastModifiedBy("FSTA Serveren")->setTitle("Deltagerliste-" . $titleTimeFormat)->setSubject("Deltagerliste oprettet " . $titleTimeFormat)->setDescription("Deltagerliste oprettet " . $titleTimeFormat)->setKeywords("")->setCategory("");
    // Get posts
    $i = 1;
    $oldI = 1;
    $args = array('posts_per_page' => -1, 'offset' => 0, 'category' => isset($_POST['cat']) ? wp_strip_all_tags($_POST['cat']) : '', 'orderby' => 'post_date', 'order' => 'ASC', 'post_type' => isset($_POST['post_type']) ? wp_strip_all_tags($_POST['post_type']) : 'post', 'post_status' => isset($_POST['post_status']) ? wp_strip_all_tags($_POST['post_status']) : 'publish', 'suppress_filters' => true);
    $myposts = get_posts($args);
    if (isset($_POST['post_type']) && $_POST['post_type'] === 'medlem' && $priv === true) {
        require_once get_template_directory() . '/functions/ajax/excel/medlem.php';
    } else {
        if (isset($_POST['post_type']) && $_POST['post_type'] === 'medlem') {
            require_once get_template_directory() . '/functions/ajax/excel/nopriv-medlem.php';
        } else {
            if (isset($_POST['post_type']) && $_POST['post_type'] === 'tilmelding') {
                require get_template_directory() . '/functions/ajax/excel/tilmelding.php';
            } else {
                $response['file'] = get_bloginfo('url');
                wp_die(json_encode($response));
            }
        }
    }
    // Rename worksheet
    $objPHPExcel->getActiveSheet()->setTitle($list_type_name['upper'] . '-' . $titleTimeFormat);
    // Set active sheet index to the first sheet, so Excel opens this as the first sheet
    $objPHPExcel->setActiveSheetIndex(0);
    PHPExcel_Shared_Font::setAutoSizeMethod(PHPExcel_Shared_Font::AUTOSIZE_METHOD_EXACT);
    foreach (range('B', 'Q') as $columnID) {
        $objPHPExcel->getActiveSheet()->getColumnDimension($columnID)->setAutoSize(true);
    }
    // Save Excel 95 file
    $callStartTime = microtime(true);
    $save_file_to = str_replace(__FILE__, $list_type_name['lower'] . '-' . $titleTimeFormat . '.xls', __FILE__);
    $exports_path = '/wp-content/exports/' . $save_file_to;
    $full_path = ABSPATH . $exports_path;
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
    $objWriter->save($full_path);
    $callEndTime = microtime(true);
    $callTime = $callEndTime - $callStartTime;
    // Echo Gemt sti
    $response['file'] = get_bloginfo('url') . $exports_path;
    if (is_user_logged_in()) {
        $response['user'] = get_currentuserinfo();
    }
    echo json_encode($response);
    exit;
}
Пример #21
0
 /**
  * Add data to the beginning of the workbook (note the reverse order)
  * and to the end of the workbook.
  *
  * @access public
  * @see PHPExcel_Writer_Excel5_Workbook::storeWorkbook()
  */
 function close()
 {
     $num_sheets = count($this->_phpSheet->getParent()->getAllSheets());
     // Write BOF record
     $this->_storeBof(0x10);
     // Write PRINTHEADERS
     $this->_writePrintHeaders();
     // Write PRINTGRIDLINES
     $this->_writePrintGridlines();
     // Write GRIDSET
     $this->_writeGridset();
     // Calculate column widths
     $this->_phpSheet->calculateColumnWidths();
     // Column dimensions
     $columnDimensions = $this->_phpSheet->getColumnDimensions();
     for ($i = 0; $i < 256; ++$i) {
         $hidden = 0;
         $level = 0;
         $xfIndex = 15;
         // there are 15 cell style Xfs
         if ($this->_phpSheet->getDefaultColumnDimension()->getWidth() >= 0) {
             $width = $this->_phpSheet->getDefaultColumnDimension()->getWidth();
         } else {
             $width = PHPExcel_Shared_Font::getDefaultColumnWidthByFont($this->_phpSheet->getParent()->getDefaultStyle()->getFont());
         }
         $columnLetter = PHPExcel_Cell::stringFromColumnIndex($i);
         if (isset($columnDimensions[$columnLetter])) {
             $columnDimension = $columnDimensions[$columnLetter];
             if ($columnDimension->getWidth() >= 0) {
                 $width = $columnDimension->getWidth();
             }
             $hidden = $columnDimension->getVisible() ? 0 : 1;
             $level = $columnDimension->getOutlineLevel();
             $xfIndex = $columnDimension->getXfIndex() + 15;
             // there are 15 cell style Xfs
         }
         // Components of _colinfo:
         // $firstcol first column on the range
         // $lastcol  last column on the range
         // $width	width to set
         // $xfIndex  The optional cell style Xf index to apply to the columns
         // $hidden   The optional hidden atribute
         // $level	The optional outline level
         $this->_colinfo[] = array($i, $i, $width, $xfIndex, $hidden, $level);
     }
     // Write GUTS
     $this->_writeGuts();
     // Write DEFAULTROWHEIGHT
     if ($this->_BIFF_version == 0x600) {
         $this->_writeDefaultRowHeight();
     }
     // Write WSBOOL
     $this->_writeWsbool();
     // Write horizontal and vertical page breaks
     $this->_writeBreaks();
     // Write page header
     $this->_writeHeader();
     // Write page footer
     $this->_writeFooter();
     // Write page horizontal centering
     $this->_writeHcenter();
     // Write page vertical centering
     $this->_writeVcenter();
     // Write left margin
     $this->_writeMarginLeft();
     // Write right margin
     $this->_writeMarginRight();
     // Write top margin
     $this->_writeMarginTop();
     // Write bottom margin
     $this->_writeMarginBottom();
     // Write page setup
     $this->_writeSetup();
     // Write sheet protection
     $this->_writeProtect();
     // Write SCENPROTECT
     $this->_writeScenProtect();
     // Write OBJECTPROTECT
     $this->_writeObjectProtect();
     // Write sheet password
     $this->_writePassword();
     // Write DEFCOLWIDTH record
     $this->_writeDefcol();
     // Write the COLINFO records if they exist
     if (!empty($this->_colinfo)) {
         $colcount = count($this->_colinfo);
         for ($i = 0; $i < $colcount; ++$i) {
             $this->_writeColinfo($this->_colinfo[$i]);
         }
     }
     // Write EXTERNCOUNT of external references
     if ($this->_BIFF_version == 0x500) {
         $this->_writeExterncount($num_sheets);
     }
     // Write EXTERNSHEET references
     if ($this->_BIFF_version == 0x500) {
         for ($i = 0; $i < $num_sheets; ++$i) {
             $this->_writeExternsheet($this->_phpSheet->getParent()->getSheet($i)->getTitle());
         }
     }
     // Write sheet dimensions
     $this->_writeDimensions();
     // Row dimensions
     foreach ($this->_phpSheet->getRowDimensions() as $rowDimension) {
         $xfIndex = $rowDimension->getXfIndex() + 15;
         // there are 15 cellXfs
         $this->_writeRow($rowDimension->getRowIndex() - 1, $rowDimension->getRowHeight(), $xfIndex, $rowDimension->getVisible() ? '0' : '1', $rowDimension->getOutlineLevel());
     }
     // Write Cells
     foreach ($this->_phpSheet->getCellCollection() as $cellID) {
         $cell = $this->_phpSheet->getCell($cellID);
         $row = $cell->getRow() - 1;
         $column = PHPExcel_Cell::columnIndexFromString($cell->getColumn()) - 1;
         // Don't break Excel!
         if ($row + 1 > 65536 or $column + 1 > 256) {
             break;
         }
         // Write cell value
         $xfIndex = $cell->getXfIndex() + 15;
         // there are 15 cell style Xfs
         if ($cell->getValue() instanceof PHPExcel_RichText) {
             $this->_writeString($row, $column, $cell->getValue()->getPlainText(), $xfIndex);
         } else {
             switch ($cell->getDatatype()) {
                 case PHPExcel_Cell_DataType::TYPE_STRING:
                     if ($cell->getValue() === '' or $cell->getValue() === null) {
                         $this->_writeBlank($row, $column, $xfIndex);
                     } else {
                         $this->_writeString($row, $column, $cell->getValue(), $xfIndex);
                     }
                     break;
                 case PHPExcel_Cell_DataType::TYPE_FORMULA:
                     $calculatedValue = $this->_preCalculateFormulas ? $cell->getCalculatedValue() : null;
                     $this->_writeFormula($row, $column, $cell->getValue(), $xfIndex, $calculatedValue);
                     break;
                 case PHPExcel_Cell_DataType::TYPE_BOOL:
                     $this->_writeBoolErr($row, $column, $cell->getValue(), 0, $xfIndex);
                     break;
                 case PHPExcel_Cell_DataType::TYPE_ERROR:
                     $this->_writeBoolErr($row, $column, $this->_mapErrorCode($cell->getValue()), 1, $xfIndex);
                     break;
                 case PHPExcel_Cell_DataType::TYPE_NUMERIC:
                     $this->_writeNumber($row, $column, $cell->getValue(), $xfIndex);
                     break;
             }
         }
     }
     // Append
     if ($this->_BIFF_version == 0x600) {
         $this->_writeMsoDrawing();
     }
     $this->_writeWindow2();
     $this->_writeZoom();
     if ($this->_phpSheet->getFreezePane()) {
         $this->_writePanes();
     }
     $this->_writeSelection();
     $this->_writeMergedCells();
     // Hyperlinks
     if ($this->_BIFF_version == 0x600) {
         foreach ($this->_phpSheet->getHyperLinkCollection() as $coordinate => $hyperlink) {
             list($column, $row) = PHPExcel_Cell::coordinateFromString($coordinate);
             $url = $hyperlink->getUrl();
             if (strpos($url, 'sheet://') !== false) {
                 // internal to current workbook
                 $url = str_replace('sheet://', 'internal:', $url);
             } else {
                 if (preg_match('/^(http:|https:|ftp:|mailto:)/', $url)) {
                     // URL
                     // $url = $url;
                 } else {
                     // external (local file)
                     $url = 'external:' . $url;
                 }
             }
             $this->_writeUrl($row - 1, PHPExcel_Cell::columnIndexFromString($column) - 1, $url);
         }
     }
     if ($this->_BIFF_version == 0x600) {
         $this->_writeDataValidity();
         $this->_writeSheetLayout();
         $this->_writeSheetProtection();
         $this->_writeRangeProtection();
     }
     $this->_storeEof();
 }
 public function exportTerminPlan(&$terminKalender)
 {
     $dateiname = 'termine_gesundheitstag.xls';
     $phpExcelService = t3lib_div::makeInstance('tx_phpexcel_service');
     $phpExcel = $phpExcelService->getPHPExcel();
     $title = 'Anmeldungen - Gesundheitstag 2015';
     $phpExcel->getProperties()->setTitle($title)->setSubject($title);
     PHPExcel_Shared_Font::setAutoSizeMethod(PHPExcel_Shared_Font::AUTOSIZE_METHOD_EXACT);
     // das erste worksheet anwaehlen
     $sheet = $phpExcel->getActiveSheet();
     $sheet->setTitle('Anmeldungen2015');
     $zeile = 1;
     foreach ($terminKalender as $veranstaltungsDaten) {
         $titelEintrag = $veranstaltungsDaten['title'] . ' - (Raum ' . $veranstaltungsDaten['raum'] . ')';
         $objRichText = new PHPExcel_RichText();
         $cellTitle = $objRichText->createTextRun($titelEintrag);
         $cellTitle->getFont()->setSize('14');
         $cellTitle->getFont()->setName('Arial');
         $sheet->setCellValueByColumnAndRow(0, $zeile, $objRichText);
         $zelle = 'A' . $zeile;
         $zellRaum = 'A' . $zeile . ':B' . $zeile;
         $sheet->mergeCells($zellRaum);
         $sheet->getStyle($zelle)->getAlignment()->setWrapText(true);
         $sheet->getRowDimension($zeile)->setRowHeight(40);
         $zeile++;
         $objRichText = new PHPExcel_RichText();
         $cellTitle = $objRichText->createTextRun('Uhrzeit');
         $cellTitle->getFont()->setSize('12');
         $cellTitle->getFont()->setName('Arial');
         $sheet->setCellValueByColumnAndRow(0, $zeile, $objRichText);
         $zelle = 'A' . $zeile;
         $sheet->getStyle($zelle)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
         $sheet->getStyle($zelle)->getAlignment()->setWrapText(true);
         $objRichText = new PHPExcel_RichText();
         $cellTitle = $objRichText->createTextRun('Person');
         $cellTitle->getFont()->setSize('12');
         $cellTitle->getFont()->setName('Arial');
         $sheet->setCellValueByColumnAndRow(1, $zeile, $objRichText);
         $zelle = 'B' . $zeile;
         $sheet->getStyle($zelle)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
         $zelle = 'A' . $zeile;
         $sheet->getStyle($zelle)->getAlignment()->setWrapText(true);
         $sheet->getRowDimension($zeile)->setRowHeight(40);
         $zeile++;
         foreach ($veranstaltungsDaten['belegung'] as $terminDaten) {
             $sheet->setCellValueByColumnAndRow(0, $zeile, $terminDaten['zeit']);
             $zelle = 'A' . $zeile;
             $sheet->getStyle($zelle)->getAlignment()->setWrapText(true);
             $zelle = 'B' . $zeile;
             $sheet->setCellValueByColumnAndRow(1, $zeile, $terminDaten['user']);
             $sheet->getStyle($zelle)->getAlignment()->setWrapText(true);
             $zeile++;
         }
     }
     $sheet->getColumnDimension('A')->setWidth(15);
     $sheet->getColumnDimension('B')->setWidth(80);
     header('Content-Type: application/vnd.ms-excel');
     header('Content-Disposition: attachment;filename="' . $dateiname . '"');
     header('Cache-Control: max-age=0');
     $excelWriter = $phpExcelService->getInstanceOf('PHPExcel_Writer_Excel2007', $phpExcel);
     $excelWriter->save('php://output');
     exit;
 }
 protected function datenExportierenMentees($monat = 1, $jahr = 2013)
 {
     $startTstamp = mktime(0, 0, 0, $monat, 1, $jahr);
     $felder = array();
     $seite = PID_MENTEES;
     $exportListe = $this->exportFelder['MENTEES'];
     $where = 'deleted=0 AND hidden=0 AND pid=' . $seite . ' AND tstamp>=' . $startTstamp;
     $where = 'deleted=0 AND hidden=0 AND pid=' . $seite;
     $abfrageFelder = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'tx_powermail_mails', $where, '', 'uid');
     $eintraege = array();
     while ($daten = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($abfrageFelder)) {
         $eintraege[] = $daten[uid];
         foreach ($exportListe as $feldId => $feldTitel) {
             $wert = $this->gibFormularFeldwert($daten[uid], $feldId, 'AAA');
             $zeile[] = '"' . iconv('UTF-8', 'CP1252', $wert) . '"';
         }
     }
     if (count($eintraege) == 0) {
         return '<br/><div style="padding-left: 20px;"><span class="error">Momentan sind keine Anmeldungen für Mentees vorhanden!</span></div><br />';
     }
     $exportTitle = 'Anmeldungen Mentees';
     $workbook = t3lib_div::makeInstance('PHPExcel');
     $workbook->getProperties()->setTitle($exportTitle)->setSubject($exportTitle);
     PHPExcel_Shared_Font::setAutoSizeMethod(PHPExcel_Shared_Font::AUTOSIZE_METHOD_EXACT);
     $sheet = $workbook->getActiveSheet();
     $sheet->setTitle('Anmeldungen Mentees');
     $spalte = 0;
     $anzSpalten = count($exportListe);
     foreach ($exportListe as $feldId => $feldTitel) {
         $feldTitel = trim(str_replace(':', '', $feldTitel));
         $sheet->setCellValueByColumnAndRow($spalte, 1, $feldTitel);
         $spalte++;
     }
     for ($zeile = 0; $zeile < count($eintraege); $zeile++) {
         $spalte = 0;
         foreach ($exportListe as $feldId => $feldTitel) {
             $wert = $this->gibFormularFeldwert($eintraege[$zeile], $feldId);
             $sheet->setCellValueByColumnAndRow($spalte, $zeile + 2, $wert);
             $spalte++;
         }
     }
     for ($spalte = 0; $spalte < $anzSpalten; $spalte++) {
         $sheet->getColumnDimension(chr(ord('A') + $spalte))->setAutoSize(true);
         //			$sheet->getColumnDimension(chr(ord('A')+ $spalte))->setWidth(50);
     }
     $dateiname = 'anmeldedaten_export_mentees.xls';
     header('Content-Type: application/vnd.ms-excel');
     header('Content-Disposition: attachment;filename="' . $dateiname . '"');
     header('Cache-Control: max-age=0');
     $objWriter = PHPExcel_IOFactory::createWriter($workbook, 'Excel5');
     $objWriter->save('php://output');
     exit;
 }
Пример #24
0
 /**
  * Calculate widths for auto-size columns
  * 
  * @param  boolean  $calculateMergeCells  Calculate merge cell width
  */
 public function calculateColumnWidths($calculateMergeCells = false)
 {
     $autoSizes = array();
     foreach ($this->getColumnDimensions() as $colDimension) {
         if ($colDimension->getAutoSize()) {
             $autoSizes[$colDimension->getColumnIndex()] = -1;
         }
     }
     foreach ($this->getCellCollection() as $cell) {
         if (isset($autoSizes[$cell->getColumn()])) {
             $cellValue = $cell->getCalculatedValue();
             foreach ($this->getMergeCells() as $cells) {
                 if ($cell->isInRange($cells) && !$calculateMergeCells) {
                     $cellValue = '';
                     // do not calculate merge cells
                 }
             }
             $autoSizes[$cell->getColumn()] = max((double) $autoSizes[$cell->getColumn()], (double) PHPExcel_Shared_Font::calculateColumnWidth($this->getStyle($cell->getCoordinate())->getFont()->getSize(), false, $cellValue));
         }
     }
     foreach ($autoSizes as $columnIndex => $width) {
         $this->getColumnDimension($columnIndex)->setWidth($width);
     }
 }
Пример #25
0
 private function createXLSDate()
 {
     include_once APPPATH . 'third_party/PHPExcel/PHPExcel.php';
     $objPHPExcel = new PHPExcel();
     // Set document properties
     $objPHPExcel->getProperties()->setCreator("Inmediative")->setLastModifiedBy("Inmediative")->setTitle($this->config->item('client', 'app'))->setSubject($this->config->item('client', 'app'))->setDescription($this->config->item('client', 'app'))->setKeywords($this->config->item('client', 'app'))->setCategory("Result file");
     $alphabet = range('A', 'Z');
     // Add some data
     $fields = array('DESTINATARIO DEL ENVÍO', 'DIRECCION', 'CIUDAD', 'REGION/ESTADO', 'C.P.', 'PAIS', 'TELEFONO', 'EMAIL', 'PESO', 'TRACK', 'Lista de productos', 'CODIGO', 'FECHA', 'DNI/CIF/ ID NUMBER/UE VAT', 'CLIENTE', 'DIRECCION COMPLETA', 'BASE 4%', 'IVA 4%', 'BASE 10%', 'IVA 10%', 'BASE 21%', 'IVA 21%', 'TOTAL', 'GASTOS ENVIO', 'CATEGORÍA');
     $dd = date('Y-m-d', strtotime('-1 week'));
     $sql = "select id_cart from cart where id_state = 3 AND modified > '{$dd}' order by modified";
     $result = $this->db->query($sql)->result();
     $k = 2;
     $sheet = $objPHPExcel->setActiveSheetIndex(0);
     foreach ($fields as $ke => $value) {
         $sheet->setCellValue($alphabet[$ke] . '1', $value);
     }
     foreach ($result as $row) {
         $idc = $row->id_cart;
         $fdata = $this->Cart->DataCart($idc);
         $cdata = $this->Cart->DataCartComplete($idc);
         $cartItems = $this->Cart->ListItems($idc);
         if (!$fdata || !$cdata) {
             die('NO XLS');
         }
         $itemInvoice = $this->Data->GetCountry($fdata['id_country']);
         $type = 'iva_ind';
         if ($fdata['type'] == 'company') {
             $type = 'iva_emp';
         }
         if ($fdata['id_region']) {
             $ret = $this->Data->GetRegion($fdata['id_region'], $fdata['id_country']);
             if ($ret) {
                 $itemInvoice = $ret;
             }
         }
         $key = 0;
         $productsArr = array();
         $catArr = array();
         foreach ($cartItems as $c) {
             $productsArr[] = $c->title . ($c->size ? " {$c->size}" : "") . ' x' . $c->items;
             $catArr[] = strtoupper($c->category);
         }
         $products = implode(', ', $productsArr);
         $categories = implode(', ', $catArr);
         $dateTimeZone = new DateTimeZone('Europe/Madrid');
         $dateTime = new DateTime();
         $dateTime->setTimestamp(mysql_to_unix($cdata->modified));
         $dateTime->setTimeZone($dateTimeZone);
         $code = $cdata->invoice_code . str_pad($cdata->code, 4, "0", STR_PAD_LEFT);
         $sheet = $objPHPExcel->setActiveSheetIndex(0);
         if ($fdata['dname']) {
             $sheet->setCellValue($alphabet[$key++] . $k, $fdata['dname'] . ' ' . $fdata['dlastname']);
             $sheet->setCellValue($alphabet[$key++] . $k, $fdata['daddress']);
             $sheet->setCellValue($alphabet[$key++] . $k, $fdata['dcity']);
             $sheet->setCellValue($alphabet[$key++] . $k, $fdata['dprovince']);
             $sheet->setCellValue($alphabet[$key++] . $k, ' ' . $fdata['dcp']);
             $sheet->setCellValue($alphabet[$key++] . $k, $fdata['country2_name']);
             $sheet->setCellValue($alphabet[$key++] . $k, $fdata['dphone']);
         } else {
             $sheet->setCellValue($alphabet[$key++] . $k, $fdata['name'] . ' ' . $fdata['lastname']);
             $sheet->setCellValue($alphabet[$key++] . $k, $fdata['address']);
             $sheet->setCellValue($alphabet[$key++] . $k, $fdata['city']);
             $sheet->setCellValue($alphabet[$key++] . $k, $fdata['province']);
             $sheet->setCellValue($alphabet[$key++] . $k, ' ' . $fdata['cp']);
             $sheet->setCellValue($alphabet[$key++] . $k, $fdata['country_name']);
             $sheet->setCellValue($alphabet[$key++] . $k, $fdata['phone']);
         }
         $sheet->setCellValue($alphabet[$key++] . $k, $fdata['mail']);
         $sheet->setCellValue($alphabet[$key++] . $k, '');
         $sheet->setCellValue($alphabet[$key++] . $k, '');
         $sheet->setCellValue($alphabet[$key++] . $k, $products);
         $sheet->setCellValue($alphabet[$key++] . $k, $code);
         $sheet->setCellValue($alphabet[$key++] . $k, $dateTime->format('d/m/Y H:i:s'));
         $sheet->setCellValue($alphabet[$key++] . $k, $fdata['taxid'] ? $fdata['taxid'] : $fdata['vat']);
         $sheet->setCellValue($alphabet[$key++] . $k, $fdata['name'] . ' ' . $fdata['lastname']);
         $sheet->setCellValue($alphabet[$key++] . $k, $fdata['address'] . ', ' . $fdata['city'] . ', ' . $fdata['province'] . ', ' . $fdata['cp'] . ', ' . $fdata['country_name']);
         if ($itemInvoice && round($itemInvoice->{$type})) {
             $sheet->setCellValue($alphabet[$key++] . $k, prep_costd($cdata->tax4t - $cdata->tax4, true, false));
             $sheet->setCellValue($alphabet[$key++] . $k, prep_costd($cdata->tax4, true, false));
             $sheet->setCellValue($alphabet[$key++] . $k, prep_costd($cdata->tax10t - $cdata->tax10, true, false));
             $sheet->setCellValue($alphabet[$key++] . $k, prep_costd($cdata->tax10, true, false));
             $sheet->setCellValue($alphabet[$key++] . $k, prep_costd($cdata->tax21t - $cdata->tax21, true, false));
             $sheet->setCellValue($alphabet[$key++] . $k, prep_costd($cdata->tax21, true, false));
         } else {
             $sheet->setCellValue($alphabet[$key++] . $k, '');
             $sheet->setCellValue($alphabet[$key++] . $k, '');
             $sheet->setCellValue($alphabet[$key++] . $k, '');
             $sheet->setCellValue($alphabet[$key++] . $k, '');
             $sheet->setCellValue($alphabet[$key++] . $k, '');
             $sheet->setCellValue($alphabet[$key++] . $k, '');
         }
         $sheet->setCellValue($alphabet[$key++] . $k, prep_costd($cdata->total, true, false));
         $sheet->setCellValue($alphabet[$key++] . $k, prep_costd($cdata->shipping_notax, true, false));
         $sheet->setCellValue($alphabet[$key++] . $k, $categories);
         $k++;
     }
     PHPExcel_Shared_Font::setAutoSizeMethod(PHPExcel_Shared_Font::AUTOSIZE_METHOD_EXACT);
     $objPHPExcel->setActiveSheetIndex(0);
     foreach (range('A', $objPHPExcel->getActiveSheet()->getHighestDataColumn()) as $col) {
         $objPHPExcel->getActiveSheet()->getColumnDimension($col)->setAutoSize(true);
     }
     /*
     		// Redirect output to a client’s web browser (Excel5)
     		header('Content-Type: application/vnd.ms-excel');
     		header('Content-Disposition: attachment;filename="List.xls"');
     		header('Cache-Control: max-age=0');
     		// If you're serving to IE 9, then the following may be needed
     		header('Cache-Control: max-age=1');
     		// If you're serving to IE over SSL, then the following may be needed
     		header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
     		header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
     		header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
     		header ('Pragma: public'); // HTTP/1.0*/
     header('Content-Type: application/vnd.ms-excel');
     header('Content-Disposition: attachment;filename="Pedidos.xls"');
     header('Cache-Control: max-age=0');
     // If you're serving to IE 9, then the following may be needed
     header('Cache-Control: max-age=1');
     // If you're serving to IE over SSL, then the following may be needed
     header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
     // Date in the past
     header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
     // always modified
     header('Cache-Control: cache, must-revalidate');
     // HTTP/1.1
     header('Pragma: public');
     // HTTP/1.0
     $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
     $objWriter->save('php://output');
 }
Пример #26
0
 /**
  * Calculate widths for auto-size columns
  *
  * @param  boolean  $calculateMergeCells  Calculate merge cell width
  * @return PHPExcel_Worksheet;
  */
 public function calculateColumnWidths($calculateMergeCells = false)
 {
     // initialize $autoSizes array
     $autoSizes = array();
     foreach ($this->getColumnDimensions() as $colDimension) {
         if ($colDimension->getAutoSize()) {
             $autoSizes[$colDimension->getColumnIndex()] = -1;
         }
     }
     // There is only something to do if there are some auto-size columns
     if (!empty($autoSizes)) {
         // build list of cells references that participate in a merge
         $isMergeCell = array();
         foreach ($this->getMergeCells() as $cells) {
             foreach (PHPExcel_Cell::extractAllCellReferencesInRange($cells) as $cellReference) {
                 $isMergeCell[$cellReference] = true;
             }
         }
         // loop through all cells in the worksheet
         foreach ($this->getCellCollection(false) as $cellID) {
             $cell = $this->getCell($cellID);
             if (isset($autoSizes[$this->_cellCollection->getCurrentColumn()])) {
                 // Determine width if cell does not participate in a merge
                 if (!isset($isMergeCell[$this->_cellCollection->getCurrentAddress()])) {
                     // Calculated value
                     // To formatted string
                     $cellValue = PHPExcel_Style_NumberFormat::toFormattedString($cell->getCalculatedValue(), $this->getParent()->getCellXfByIndex($cell->getXfIndex())->getNumberFormat()->getFormatCode());
                     $autoSizes[$this->_cellCollection->getCurrentColumn()] = max((double) $autoSizes[$this->_cellCollection->getCurrentColumn()], (double) PHPExcel_Shared_Font::calculateColumnWidth($this->getParent()->getCellXfByIndex($cell->getXfIndex())->getFont(), $cellValue, $this->getParent()->getCellXfByIndex($cell->getXfIndex())->getAlignment()->getTextRotation(), $this->getDefaultStyle()->getFont()));
                 }
             }
         }
         // adjust column widths
         foreach ($autoSizes as $columnIndex => $width) {
             if ($width == -1) {
                 $width = $this->getDefaultColumnDimension()->getWidth();
             }
             $this->getColumnDimension($columnIndex)->setWidth($width);
         }
     }
     return $this;
 }
Пример #27
0
 //
 $xlWS->setSelectedCells('A1');
 // List of generated files
 $files = array();
 if (ExportFileFormat::isExcel()) {
     $files[] = $filename = $base_filename . '.xlsx';
     PHPExcel_Shared_Font::setAutoSizeMethod(PHPExcel_Shared_Font::AUTOSIZE_METHOD_EXACT);
     save($xl, $filename, 'PHPExcel_Writer_Excel2007');
 }
 if (ExportFileFormat::isPDF()) {
     $files[] = $filename = $base_filename . '.pdf';
     // PDF output relies on ShowGridlines and not PrintGridlines
     $xlWS->setShowGridlines(false);
     // With 'exact' autosize method, columns are too narrow, causing cell
     // contents (e.g. phone numbers) to wrap
     PHPExcel_Shared_Font::setAutoSizeMethod(PHPExcel_Shared_Font::AUTOSIZE_METHOD_APPROX);
     save($xl, $filename, 'PHPExcel_Writer_PDF');
 }
 // ------------------------------------------------------------------------
 // Send e-mail
 //
 if ($opt['send'] || $opt['debug']) {
     if ($send_email) {
         $recipients = array('to' => array_unique($recipients), 'bcc' => array_column($profs, 'email'));
         echo '  ';
         send_email($classe_fullname, $recipients, MAIL_BODY_SEND_CLASSLIST, $files, 'info@apecove.ch,APECOVE');
     }
     if (!$opt['keep']) {
         foreach ($files as $filename) {
             unlink($filename);
         }
Пример #28
0
	private static function toCSSArray($style) {
		$style = str_replace("\r", "", $style);
		$style = str_replace("\n", "", $style);

		$temp = explode(';', $style);

		$style = array();
		foreach ($temp as $item) {
			$item = explode(':', $item);

			if (strpos($item[1], 'px') !== false) {
				$item[1] = str_replace('px', '', $item[1]);
			}
			if (strpos($item[1], 'pt') !== false) {
				$item[1] = str_replace('pt', '', $item[1]);
				$item[1] = PHPExcel_Shared_Font::fontSizeToPixels($item[1]);
			}
			if (strpos($item[1], 'in') !== false) {
				$item[1] = str_replace('in', '', $item[1]);
				$item[1] = PHPExcel_Shared_Font::inchSizeToPixels($item[1]);
			}
			if (strpos($item[1], 'cm') !== false) {
				$item[1] = str_replace('cm', '', $item[1]);
				$item[1] = PHPExcel_Shared_Font::centimeterSizeToPixels($item[1]);
			}

			$style[$item[0]] = $item[1];
		}

		return $style;
	}
Пример #29
0
 /**
  * Calculate widths for auto-size columns
  */
 public function calculateColumnWidths()
 {
     $autoSizes = array();
     foreach ($this->getColumnDimensions() as $colDimension) {
         if ($colDimension->getAutoSize()) {
             $autoSizes[$colDimension->getColumnIndex()] = -1;
         }
     }
     foreach ($this->getCellCollection() as $cell) {
         if (isset($autoSizes[$cell->getColumn()])) {
             $autoSizes[$cell->getColumn()] = max($autoSizes[$cell->getColumn()], PHPExcel_Shared_Font::calculateColumnWidth($this->getStyle($cell->getCoordinate())->getFont()->getSize(), false, $cell->getCalculatedValue()));
         }
     }
     foreach ($autoSizes as $columnIndex => $width) {
         $this->getColumnDimension($columnIndex)->setWidth($width);
     }
 }