Ejemplo n.º 1
1
 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     $this->app->bind('mpdf.wrapper', function ($app, $cfg) {
         $app['mpdf.pdf'] = $app->share(function ($app) use($cfg) {
             if (!empty($cfg)) {
                 foreach ($cfg as $key => $value) {
                     Config::set('pdf.' . $key, $value);
                 }
             }
             $mpdf = new \mPDF(Config::get('pdf.mode'), Config::get('pdf.defaultFontSize'), Config::get('pdf.defaultFont'), Config::get('pdf.marginLeft'), Config::get('pdf.marginRight'), Config::get('pdf.marginTop'), Config::get('pdf.marginBottom'), Config::get('pdf.marginHeader'), Config::get('pdf.Footer'), Config::get('pdf.orientation'));
             $permissions = [];
             foreach (Config::get('pdf.protection.permissions') as $perm => $enable) {
                 if ($enable) {
                     $permissions[] = $perm;
                 }
             }
             $mpdf->SetProtection($permissions, Config::get('pdf.protection.user_password'), Config::get('pdf.protection.owner_password'), Config::get('pdf.protection.length'));
             $mpdf->SetTitle(Config::get('pdf.title'));
             $mpdf->SetAuthor(Config::get('pdf.author'));
             $mpdf->SetWatermarkText(Config::get('pdf.watermark'));
             $mpdf->showWatermarkText = Config::get('pdf.showWatermark');
             $mpdf->watermark_font = Config::get('pdf.watermarkFont');
             $mpdf->watermarkTextAlpha = Config::get('pdf.watermarkTextAlpha');
             $mpdf->SetDisplayMode(Config::get('pdf.displayMode'));
             return $mpdf;
         });
         return new PdfWrapper($app['mpdf.pdf']);
     });
 }
Ejemplo n.º 2
1
 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     $this->app->bind('mpdf.wrapper', function ($app, $cfg) {
         if ($cfg) {
             $app['mpdf.pdf'] = $app->share(function ($app) use($cfg) {
                 $mpdf = new \mPDF($cfg[0], $cfg[1], $cfg[2], $cfg[3], $cfg[4], $cfg[5], $cfg[6], $cfg[7], $cfg[8], $cfg[9], $cfg[10]);
                 $mpdf->SetProtection(array('print'));
                 $mpdf->SetTitle("");
                 $mpdf->SetAuthor("");
                 $mpdf->SetWatermarkText("");
                 $mpdf->showWatermarkText = true;
                 $mpdf->watermark_font = 'DejaVuSansCondensed';
                 $mpdf->watermarkTextAlpha = 0.1;
                 $mpdf->SetDisplayMode('fullpage');
                 return $mpdf;
             });
         } else {
             $mpdf = new \mPDF('th', 'A4', '', '', 10, 10, 10, 10, 10, 5);
             $mpdf->SetProtection(array('print'));
             $mpdf->SetTitle("");
             $mpdf->SetAuthor("");
             $mpdf->SetWatermarkText("");
             $mpdf->showWatermarkText = true;
             $mpdf->watermark_font = 'DejaVuSansCondensed';
             $mpdf->watermarkTextAlpha = 0.1;
             $mpdf->SetDisplayMode('fullpage');
             $app['mpdf.pdf'] = $mpdf;
         }
         return new PdfWrapper($app['mpdf.pdf']);
     });
     // // work --------------------------------------------------------------------------start ----------
     // 	$this->app['mpdf.pdf'] = $this->app->share(function($app)
     // 	{
     // 		// $cfg =['th','A0','','',10,10,10,10,10,5,'L'];
     // 		$cfg = $app['config']['mpdfconfig.pdf.options'];
     // 		consolelog('cfg',$cfg);
     // 		if($cfg) {
     // 			$mpdf = new \mPDF( $cfg[0],$cfg[1],$cfg[2],$cfg[3],$cfg[4],$cfg[5],$cfg[6],$cfg[7],$cfg[8],$cfg[9],$cfg[10] );
     // 		} else {
     // 			$mpdf=new \mPDF('th','A4','','',10,10,10,10,10,5);
     // 		}
     // 		$mpdf->SetProtection(array('print'));
     // 		$mpdf->SetTitle("TOMATO POS - Invoice");
     // 		$mpdf->SetAuthor("Thongchai Lim");
     // 		$mpdf->SetWatermarkText("Paid");
     // 		$mpdf->showWatermarkText = true;
     // 		$mpdf->watermark_font = 'DejaVuSansCondensed';
     // 		$mpdf->watermarkTextAlpha = 0.1;
     // 		$mpdf->SetDisplayMode('fullpage');
     // 		return $mpdf;
     // 	});
     // 	$this->app['mpdf.wrapper'] = $this->app->share(function($app)
     // 	{
     // 		return new PdfWrapper($app['mpdf.pdf']);
     // 	});
     // // work --------------------------------------------------------------------------end----------
 }
 /**
  * Creates the PDF and does a specific output (see PDF_Generator function above for $output variable types)
  */
 public function PDF_processing($html, $filename, $id, $output = 'view', $arguments)
 {
     /* 
      * DOMPDF replaced with mPDF in v3.0.0 
      * Check which version of mpdf we are calling
      * Full, Lite or Tiny
      */
     if (!class_exists('mPDF')) {
         if (FP_PDF_ENABLE_MPDF_TINY === true) {
             include FP_PDF_PLUGIN_DIR . '/mPDF/mpdf-extra-lite.php';
         } elseif (FP_PDF_ENABLE_MPDF_LITE === true) {
             include FP_PDF_PLUGIN_DIR . '/mPDF/mpdf-lite.php';
         } else {
             include FP_PDF_PLUGIN_DIR . '/mPDF/mpdf.php';
         }
     }
     /* 
      * Initialise class and set the paper size and orientation
      */
     $paper_size = $arguments['pdf_size'];
     if (!is_array($paper_size)) {
         $orientation = $arguments['orientation'] == 'landscape' ? '-L' : '';
         $paper_size = $paper_size . $orientation;
     } else {
         $orientation = $arguments['orientation'] == 'landscape' ? 'L' : 'P';
     }
     $mpdf = new mPDF('', $paper_size, 0, '', 15, 15, 16, 16, 9, 9, $orientation);
     /*
      * Display PDF is full-page mode which allows the entire PDF page to be viewed
      * Normally PDF is zoomed right in.
      */
     $mpdf->SetDisplayMode('fullpage');
     if (FP_PDF_ENABLE_SIMPLE_TABLES === true) {
         $mpdf->simpleTables = true;
     }
     /*
      * Automatically detect fonts and substitue as needed
      */
     if (FP_PDF_DISABLE_FONT_SUBSTITUTION === true) {
         $mpdf->useSubstitutions = false;
     } else {
         $mpdf->SetAutoFont(AUTOFONT_ALL);
         $mpdf->useSubstitutions = true;
     }
     /*
      * Set Creator Meta Data
      */
     $mpdf->SetCreator('Formidable Pro PDF Extended v' . FP_PDF_EXTENDED_VERSION . '. http://formidablepropdfextended.com');
     /*
      * Set RTL languages at user request
      */
     if ($arguments['rtl'] === true) {
         $mpdf->SetDirectionality('rtl');
     }
     /*
      * Set up security if user requested
      */
     if ($arguments['security'] === true && $arguments['pdfa1b'] !== true && $arguments['pdfx1a'] !== true) {
         $password = strlen($arguments['pdf_password']) > 0 ? $arguments['pdf_password'] : '';
         $master_password = strlen($arguments['pdf_master_password']) > 0 ? $arguments['pdf_master_password'] : null;
         $pdf_privileges = is_array($arguments['pdf_privileges']) ? $arguments['pdf_privileges'] : array();
         $mpdf->SetProtection($pdf_privileges, $password, $master_password, 128);
     }
     /* PDF/A1-b support added in v3.4.0 */
     if ($arguments['pdfa1b'] === true) {
         $mpdf->PDFA = true;
         $mpdf->PDFAauto = true;
     } else {
         if ($arguments['pdfx1a'] === true) {
             $mpdf->PDFX = true;
             $mpdf->PDFXauto = true;
         }
     }
     /*
      * Check if we should auto prompt to print the document on open
      */
     if (isset($_GET['print'])) {
         $mpdf->SetJS('this.print();');
     }
     /* load HTML block */
     $mpdf->WriteHTML($html);
     switch ($output) {
         case 'download':
             $mpdf->Output($filename, 'D');
             exit;
             break;
         case 'view':
             $mpdf->Output(time(), 'I');
             exit;
             break;
         case 'save':
             /*
              * PDF wasn't writing to file with the F method - http://mpdf1.com/manual/index.php?tid=125
              * Return as a string and write to file manually
              */
             $pdf = $mpdf->Output('', 'S');
             return $this->savePDF($pdf, $filename, $id);
             break;
     }
 }
Ejemplo n.º 4
0
 public function pdf($content, $namafile, $paper_size = '', $orientation = 'P', $border = true, $title = '', $subject = '', $mode = 'D', $watermark = false)
 {
     $margin = 20;
     $namafile = preg_replace('/\\.pdf$/', '', $namafile);
     $mL = $mR = $mT = $mB = $margin;
     // $mB = $margin + 50;
     $mH = 0;
     $mF = 0;
     if (!$paper_size) {
         $paper_size = array(215, 330);
     }
     Yii::import('system.docotel.cms.extensions.mpdf.mPDF');
     $mpdf = new mPDF('', $paper_size, 0, '', $mL, $mR, $mT, $mB, $mH, $mF, $orientation);
     $mpdf->SetDefaultFont('Arial');
     $mpdf->SetProtection(array('print', 'print-highres'), '', md5(time()), 128);
     $mpdf->SetTitle($title);
     $mpdf->SetAuthor('Makarim & Taira');
     $mpdf->SetCreator('News');
     $mpdf->SetSubject($subject);
     $mpdf->h2toc = array('H4' => 0, 'H5' => 1);
     //$mpdf->setFooter('{PAGENO}');
     // $stylesheet = file_get_contents(Yii::app()->getBaseUrl(true).'/themes/flatlab/assets/css/bootstrap.min.css'); // external css
     // $mpdf->WriteHTML($stylesheet,1);
     // echo $content; exit;
     $mpdf->WriteHTML($content);
     $mpdf->Output($namafile . '.pdf', $mode);
     if ($mode === 'D' or $mode === 'I') {
         exit;
     }
 }
Ejemplo n.º 5
0
 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     // load config
     $this->mergeConfigFrom(__DIR__ . '/../../config/pdf.php', 'pdf');
     // bind wrapper
     $this->app->bind('mpdf.wrapper', function ($app, $cfg) {
         $app['mpdf.pdf'] = $app->share(function ($app) use($cfg) {
             if (!empty($cfg)) {
                 foreach ($cfg as $key => $value) {
                     Config::set('pdf.' . $key, $value);
                 }
             }
             $mpdf = new \mPDF(Config::get('pdf.mode'), Config::get('pdf.format'), Config::get('pdf.defaultFontSize'), Config::get('pdf.defaultFont'), Config::get('pdf.marginLeft'), Config::get('pdf.marginRight'), Config::get('pdf.marginTop'), Config::get('pdf.marginBottom'), Config::get('pdf.marginHeader'), Config::get('pdf.marginFooter'), Config::get('pdf.orientation'));
             $mpdf->SetProtection(array('print'));
             $mpdf->SetTitle(Config::get('pdf.title'));
             $mpdf->SetAuthor(Config::get('pdf.author'));
             $mpdf->SetWatermarkText(Config::get('pdf.watermark'));
             $mpdf->showWatermarkText = Config::get('pdf.showWatermark');
             $mpdf->watermark_font = Config::get('pdf.watermarkFont');
             $mpdf->watermarkTextAlpha = Config::get('pdf.watermarkTextAlpha');
             $mpdf->SetDisplayMode(Config::get('pdf.displayMode'));
             return $mpdf;
         });
         return new PdfWrapper($app['mpdf.pdf']);
     });
 }
 /**
  * @param array $options Options for mPDF.
  * @return \mPDF
  */
 protected function createMpdfInstance($options)
 {
     $tempDir = sys_get_temp_dir() . '/mpdf';
     is_dir($tempDir) or mkdir($tempDir);
     defined('_MPDF_TEMP_PATH') or define('_MPDF_TEMP_PATH', $tempDir);
     $mpdf = new \mPDF(isset($options['lang']) ? $options['lang'] : static::DEFAULT_LANGUAGE, isset($options['format']) ? $options['format'] : static::DEFAULT_PAGE_FORMAT, isset($options['fontSize']) ? $options['fontSize'] : static::DEFAULT_FONT_SIZE, isset($options['font']) ? $options['font'] : static::DEFAULT_FONT, isset($options['marginLeft']) ? $options['marginLeft'] : static::DEFAULT_MARGIN, isset($options['marginRight']) ? $options['marginRight'] : static::DEFAULT_MARGIN, isset($options['marginTop']) ? $options['marginTop'] : static::DEFAULT_MARGIN, isset($options['marginBottom']) ? $options['marginBottom'] : static::DEFAULT_MARGIN, isset($options['marginHeader']) ? $options['marginHeader'] : static::DEFAULT_MARGIN, isset($options['marginFooter']) ? $options['marginFooter'] : static::DEFAULT_MARGIN, isset($options['orientation']) ? $options['orientation'] : static::DEFAULT_ORIENTATION);
     $mpdf->SetDisplayMode('fullpage', 'two');
     $mpdf->SetProtection(['copy', 'print', 'print-highres'], null, uniqid(), 128);
     return $mpdf;
 }
Ejemplo n.º 7
0
 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     $this->package('kendu/l4-mpdf');
     $this->app['mpdf.pdf'] = $this->app->share(function ($app) {
         $base = $app['config']->get('l4-mpdf::config.pdf.base');
         $options = $app['config']->get('l4-mpdf::config.pdf.options');
         $mpdf = new \mPDF(Config::get('pdf.mode'), Config::get('pdf.defaultFontSize'), Config::get('pdf.defaultFont'), Config::get('pdf.marginLeft'), Config::get('pdf.marginRight'), Config::get('pdf.marginTop'), Config::get('pdf.marginBottom'), Config::get('pdf.marginHeader'), Config::get('pdf.Footer'), Config::get('pdf.orientation'));
         $mpdf->SetProtection(array('print'));
         $mpdf->SetTitle(Config::get('pdf.title'));
         $mpdf->SetAuthor(Config::get('pdf.author'));
         $mpdf->SetWatermarkText(Config::get('pdf.watermark'));
         $mpdf->showWatermarkText = Config::get('pdf.showWatermark');
         $mpdf->watermark_font = Config::get('pdf.watermarkFont');
         $mpdf->watermarkTextAlpha = Config::get('pdf.watermarkTextAlpha');
         $mpdf->SetDisplayMode(Config::get('pdf.displayMode'));
         return $mpdf;
     });
     $this->app['mpdf.wrapper'] = $this->app->share(function ($app) {
         return new PdfWrapper($app['mpdf.pdf']);
     });
 }
Ejemplo n.º 8
0
 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     $this->package('shinomontaz/l4-mpdf');
     if ($this->app['config']->get('l4-mpdf::config.pdf.enabled')) {
         $this->app['mpdf.pdf'] = $this->app->share(function ($app) {
             $base = $app['config']->get('l4-mpdf::config.pdf.base');
             $options = $app['config']->get('l4-mpdf::config.pdf.options');
             $mpdf = new \mPDF('win-1252', 'A4', '', '', 10, 10, 40, 35, 10, 5);
             $mpdf->SetProtection(array('print'));
             $mpdf->SetTitle("Acme Trading Co. - Invoice");
             $mpdf->SetAuthor("Acme Trading Co.");
             $mpdf->SetWatermarkText("Paid");
             $mpdf->showWatermarkText = false;
             $mpdf->watermark_font = 'DejaVuSansCondensed';
             $mpdf->watermarkTextAlpha = 0.1;
             $mpdf->SetDisplayMode('fullpage');
             return $mpdf;
         });
         $this->app['mpdf.wrapper'] = $this->app->share(function ($app) {
             return new PdfWrapper($app['mpdf.pdf']);
         });
     }
 }
Ejemplo n.º 9
0
 public function generate($payment_id)
 {
     $this->data['payment_id'] = $payment_id;
     $payment_info = $this->payment->getPayment($payment_id);
     if ($payment_info) {
         if ($this->ion_auth->is_customer() || $this->input->get_post('view') == 'customer') {
             $user_id = $payment_info->retailer_id;
         } else {
             $user_id = $payment_info->depot_id;
         }
         $this->data['payment_info'] = $payment_info;
         $user_info = $this->ion_auth->getSimbanicUser($user_id);
         $this->data['user_info'] = $user_info;
         $invoice_month = date("M", strtotime($payment_info->confirm_date));
         $pdfFilePath = $invoice_month . '_' . $user_info->full_name . '_' . $user_info->customer_id . '_' . $payment_info->id . ".pdf";
         //load mPDF library
         $this->load->library('m_pdf');
         $pdf = $this->m_pdf->load();
         $mpdf = new mPDF('c', 'A4', '', '', 20, 15, 38, 25, 10, 10);
         $mpdf->SetProtection(array('print'));
         $mpdf->SetTitle("Walart Pharmaceutical. - Payment Receipt");
         $mpdf->SetAuthor("Walart Pharmaceutical.");
         $mpdf->SetDisplayMode('fullpage');
         $header = $this->load->view(BACKEND . '/payment/generate/header', $this->data, true);
         $footer = $this->load->view(BACKEND . '/payment/generate/footer', $this->data, true);
         $html = $this->load->view(BACKEND . '/payment/generate', $this->data, true);
         $mpdf->SetHTMLHeader($header);
         $mpdf->SetHTMLFooter($footer);
         $mpdf->WriteHTML($html);
         $mpdf->Output($pdfFilePath, "D");
     } else {
         redirect_backend_url('invoice');
     }
 }
 /**
  * function is used for Purchase Receipts
  * @author Rohan Julka
  */
 public function renderPDF($transactionID = NULL)
 {
     $logoUrl = $this->webroot . 'img/logo_black.png';
     $paidLogo = $this->webroot . 'img/canstock12610992.jpg';
     if ($transactionID) {
         $txData = $this->Transaction->find('first', array('conditions' => array('Transaction.id' => $this->Encryption->decode($transactionID))));
         $amountPaid = $txData['Transaction']['amount_paid'];
         $discounts = 49.99 - $amountPaid;
         $discounts = number_format((double) $discounts, 2, '.', '');
         if (!empty($txData)) {
             $html = '
             <!DOCTYPE html>
             <html lang="en">
             <head>
             <meta charset="utf-8">
             <meta http-equiv="X-UA-Compatible" content="IE=edge">
             <meta name="viewport" content="width=device-width, initial-scale=1">
             <meta name="description" content="">
             <meta name="author" content="">
             <title>FoxHopr</title>
             <!--[if lt IE 9]>
             <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
             <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
             <![endif]-->
             </head>
             <body id="page-top" class="index">
         
             <style>
             .table-responsive {
             min-height: 0.01%;
             overflow-x: auto;
             }
             
             table.table > tbody > tr > td, .table > tbody > tr > th, table.table > tfoot > tr > td, table.table > tfoot > tr > th, table.table > thead > tr > td, table.table > thead > tr > th {
             
             border: 0.1mm solid #ddd;
             line-height: 1.42857;
             padding: 8px;
             vertical-align: top; text-align:left;font-family: "Times New Roman", Times, serif; fo
             }
             .items tbody,.items thead { border-top: 0.1mm solid #000000;}
             td { vertical-align: top; }
             .items td {
             border-top: 0.1mm solid #ddd;
             
             }
             table thead td {
             text-align: center;
             font-variant: small-caps;
             }
             
             .items td.totals {
             text-align: right;
             border: 0.1mm solid #000000;
             }
             .items td.cost {
             text-align: "." center;
             }                
             </style>
         
             <htmlpageheader name="myheader"> </htmlpageheader>
             
             <htmlpagefooter name="myfooter">
             
             <div style="border-top: 1px solid #000000; font-size: 9pt; text-align: center; padding-top: 3mm; ">
             Page {PAGENO} of {nb}
             </div>
             </htmlpagefooter>
             
             <sethtmlpageheader name="myheader" value="on" show-this-page="1" />
             <sethtmlpagefooter name="myfooter" value="on" />
             
             mpdf-->
             <table class="table items">
             <tr>
             <th scope="row" style="border-top:0"><a href="' . Router::url('/') . '"><img src="' . $logoUrl . '" style="float:left;display:inline-block;text-align:left;width:30%;"></a></th>
              
             </tr>
             </table>
             <table class="table table-bordered items" width="100%" style="width:700px; margin:0 auto;font-size: 13pt; border-collapse: collapse; ">
             <thead>
             <tr>
             <th style=" border-top:0"></th>
             <td  style=" border-top:0"></td>
             
             <th  style=" text-align:right; border-top:0;padding-bottom:10px;padding-right:5px;">Receipt</th>
             </tr>
             
             
             </thead>
             <tbody>
             <tr >
          
             <td style="padding-top:30px;padding-left:5px;"><strong>Billed to:</strong></td>
             <td style="padding-top:30px;"></td>
             <td style="text-align:right;padding-top:30px;line-height:25px;padding-right:5px;"><strong>Receipt Date:</strong> ' . date('M d, Y', strtotime($txData['Transaction']['created'])) . '<br>
             </td>
             </tr>
             <tr style="border:none;">
              
             <td style="padding-top:2px;"></td>
             <td style="padding-top:2px;"></td>
             <td style="padding-top:2px;"></td>
             </tr>
             
             <tr style="border:none;">
             <td class="bt" style="padding-left:5px;">' . $txData['BusinessOwner']['email'] . '<br>
             ' . $txData['BusinessOwner']['fname'] . ' ' . $txData['BusinessOwner']['lname'] . '<br>';
             if (!empty($txData['BusinessOwner']['address'])) {
                 $html .= ucfirst($txData['BusinessOwner']['address']);
             }
             if ($txData['BusinessOwner']['address'] != '' && $txData['BusinessOwner']['city'] != '') {
                 $html .= ', ';
             }
             if (!empty($txData['BusinessOwner']['city'])) {
                 $html .= ucfirst($txData['BusinessOwner']['city']);
             }
             $html .= '
             </td>
             <td class="bt"></td>
             <td class="bt"></td>
             
             </tr>
         
             <tr style="border:none;border-bottom:1px solid #ddd;">
             <td class="bt" style="padding-bottom:10px;padding-left:5px;">' . $txData['State']['state_subdivision_name'] . ' ' . $txData['BusinessOwner']['zipcode'] . '<br>
             ' . $txData['Country']['country_name'] . '
             </td>
             <td class="bt"></td>
             <td class="bt"></td>
             
             </tr>
             <tr>
             <th style="text-align:left;padding-bottom:20px;padding-left:5px;width:40%;">Membership Plan</th>
             <th style="text-align:left;padding-bottom:20px;width:20%;">Discount</th>
             <th style="text-align:right;padding-bottom:20px;width:40%;padding-right:5px;">Price</th>
             </tr>
             
             
             <tr>
             <td style="padding-bottom:40px;padding-left:5px;padding-left:5px;padding-right:5px;">' . ucfirst($txData['Transaction']['group_type']) . '</td>
             <td style="padding-bottom:40px;padding-right:5px;">$' . $discounts . '</td>
             <td style="text-align:right;padding-bottom:40px;padding-right:5px;">$49.99</td>
             
             </tr>
             
             <tr>
         
             <td></td>
             <td></td>
             <td style="text-align:right;line-height:25px;"><b>Total: $' . $amountPaid . '</b> </td>                
             </tr>
             
             </tbody>
             </table>
             </body>
             </html>';
             $mpdf = new mPDF('c', 'A4', '', '', 15, 15, 30, 25, 10, 10);
             $mpdf->SetProtection(array('print'));
             $mpdf->SetTitle("FOXHOPR - Invoice");
             $mpdf->SetAuthor("FOXHOPR");
             $mpdf->SetDisplayMode('fullpage');
             /*$mpdf->SetWatermarkText('PAID');
               $mpdf->watermark_font = 'DejaVuSansCondensed';*/
             $mpdf->showWatermarkImage = true;
             $mpdf->SetWatermarkImage('http://10.10.12.69/foxhopr_testing/img/watermark.jpg', 0.15, 'F');
             //$mpdf->showWatermarkText = true;
             $mpdf->WriteHTML($html);
             $mpdf->Output();
             exit;
         } else {
             $this->Session->setFlash('Invalid Transaction ID', 'Front/flash_bad');
             $this->redirect(array('action' => 'purchaseReceipts'));
         }
     } else {
         $this->Session->setFlash('Invalid Transaction ID', 'Front/flash_bad');
         $this->redirect(array('action' => 'purchaseReceipts'));
     }
 }
Ejemplo n.º 11
0
 function email($purchase_id, $to, $cc = NULL, $bcc = NULL, $from_name, $from, $subject, $note)
 {
     $data['message'] = validation_errors() ? validation_errors() : $this->session->flashdata('message');
     $data['rows'] = $this->inventories_model->getAllInventoryItems($purchase_id);
     $inv = $this->inventories_model->getInventoryByPurchaseID($purchase_id);
     $supplier_id = $inv->supplier_id;
     $data['supplier'] = $this->inventories_model->getSupplierByID($supplier_id);
     $data['inv'] = $inv;
     $data['pid'] = $purchase_id;
     $data['page_title'] = $this->lang->line("inventory");
     $html = $this->load->view('view_inventory', $data, TRUE);
     $this->load->library('MPDF/mpdf');
     $mpdf = new mPDF('utf-8', 'A4', '12', '', 10, 10, 10, 10, 9, 9);
     $mpdf->useOnlyCoreFonts = true;
     $mpdf->SetProtection(array('print'));
     $mpdf->SetTitle(SITE_NAME);
     $mpdf->SetAuthor(SITE_NAME);
     $mpdf->SetCreator(SITE_NAME);
     $mpdf->SetDisplayMode('fullpage');
     $mpdf->SetAutoFont();
     $stylesheet = file_get_contents('assets/css/bootstrap-' . THEME . '.css');
     $mpdf->WriteHTML($stylesheet, 1);
     $search = array("<div class=\"row-fluid\">", "<div class=\"span6\">");
     $replace = array("<div style='width: 100%;'>", "<div style='width: 48%; float: left;'>");
     $html = str_replace($search, $replace, $html);
     $name = $this->lang->line("inventory") . "-" . $inv->id . ".pdf";
     $mpdf->WriteHTML($html);
     $mpdf->Output($name, 'F');
     if ($note) {
         $message = html_entity_decode($note) . "<br><hr>" . $html;
     } else {
         $message = $html;
     }
     $this->load->library('email');
     $config['mailtype'] = 'html';
     $config['wordwrap'] = TRUE;
     $this->email->initialize($config);
     $this->email->from($from, $from_name);
     $this->email->to($to);
     if ($cc) {
         $this->email->cc($cc);
     }
     if ($bcc) {
         $this->email->bcc($bcc);
     }
     $this->email->subject($subject);
     $this->email->message($message);
     $this->email->attach($name);
     if ($this->email->send()) {
         // email sent
         unlink($name);
         return true;
     } else {
         //email not sent
         unlink($name);
         //echo $this->email->print_debugger();
         return false;
     }
 }
Ejemplo n.º 12
0
if (strpos(strtolower($name), ".pdf") === FALSE) {
	$name .= ".pdf";
}

// Main PDF Object
$mpdf = new mPDF('utf-8', array($paper_width, $paper_height), 10, 'tahoma', $margin_right, $margin_left, $margin_top, $margin_bottom, $margin_header, $margin_footer);

$mpdf -> SetDirectionality('rtl');
$mpdf -> mirrorMargins = true;

$mpdf -> autoScriptToLang = true;
$mpdf -> autoLangToFont = true;

//$mpdf -> defaultPageNumStyle = 'arabic-indic';

// Security
$permissions = array();
$permissions[] = "print";
$mpdf -> SetProtection($permissions, $signature);

// Header & Footer
$mpdf -> SetHTMLHeader($header, "O");
$mpdf -> SetHTMLHeader($header, "E");
$mpdf -> SetHTMLFooter($footer, "O");
$mpdf -> SetHTMLFooter($footer, "E");

// Actual Content
$mpdf -> WriteHTML($html);
$mpdf -> Output();
exit ;
?>
Ejemplo n.º 13
0
 public function get_payment_area()
 {
     $start_date = $this->input->get_post('start_date');
     $end_date = $this->input->get_post('end_date');
     $this->data['payment_info'] = $this->report->getDepotToAllCustomerPaymentReport($this->ion_auth->get_user_id(), $start_date, $end_date);
     if ($this->input->is_ajax_request()) {
         $this->load->view(BACKEND . '/report/payment/generate', $this->data);
     } else {
         //load mPDF library
         $this->load->library('m_pdf');
         $pdf = $this->m_pdf->load();
         $mpdf = new mPDF('c', 'A4', '', '', 20, 15, 38, 25, 10, 10);
         $mpdf->SetProtection(array('print'));
         $mpdf->SetTitle("Walart Pharmaceutical. - Payment Report");
         $mpdf->SetAuthor("Walart Pharmaceutical.");
         $mpdf->SetDisplayMode('fullpage');
         $header = $this->load->view(BACKEND . '/report/payment/generate/header', $this->data, true);
         $footer = $this->load->view(BACKEND . '/report/payment/generate/footer', $this->data, true);
         $html = $this->load->view(BACKEND . '/report/payment/generate', $this->data, true);
         $mpdf->SetHTMLHeader($header);
         $mpdf->SetHTMLFooter($footer);
         $mpdf->WriteHTML($html);
         $mpdf->Output($pdfFilePath, "D");
     }
 }
Ejemplo n.º 14
0
 public function generate_pdf($content, $name = 'download.pdf', $output_type = NULL, $footer = NULL, $margin_bottom = NULL, $header = NULL, $margin_top = NULL, $orientation = 'P')
 {
     if (!$output_type) {
         $output_type = 'D';
     }
     if (!$margin_bottom) {
         $margin_bottom = 10;
     }
     if (!$margin_top) {
         $margin_top = 10;
     }
     $this->load->library('pdf');
     $pdf = new mPDF('utf-8', 'A4-' . $orientation, '13', '', 10, 10, $margin_top, $margin_bottom, 9, 9);
     $pdf->debug = false;
     $pdf->autoScriptToLang = true;
     $pdf->autoLangToFont = true;
     $pdf->SetProtection(array('print'));
     // You pass 2nd arg for user password (open) and 3rd for owner password (edit)
     //$pdf->SetProtection(array('print', 'copy')); // Comment above line and uncomment this to allow copying of content
     $pdf->SetTitle($this->Settings->site_name);
     $pdf->SetAuthor($this->Settings->site_name);
     $pdf->SetCreator($this->Settings->site_name);
     $pdf->SetDisplayMode('fullpage');
     $stylesheet = file_get_contents('assets/bs/bootstrap.min.css');
     $pdf->WriteHTML($stylesheet, 1);
     $pdf->WriteHTML($content);
     if ($header != '') {
         $pdf->SetHTMLHeader('<p class="text-center">' . $header . '</p>', '', TRUE);
     }
     if ($footer != '') {
         $pdf->SetHTMLFooter('<p class="text-center">' . $footer . '</p>', '', TRUE);
     }
     //$pdf->SetHeader($this->Settings->site_name.'||{PAGENO}', '', TRUE); // For simple text header
     //$pdf->SetFooter($this->Settings->site_name.'||{PAGENO}', '', TRUE); // For simple text footer
     if ($output_type == 'S') {
         $file_content = $pdf->Output('', 'S');
         write_file('assets/uploads/' . $name, $file_content);
         return 'assets/uploads/' . $name;
     } else {
         $pdf->Output($name, $output_type);
     }
 }
Ejemplo n.º 15
0
    public function testPDF()
    {
        $logoUrl = $this->webroot . 'img/logo_black.png';
        $html = '
        <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>FoxHopr</title>
<!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body id="page-top" class="index">

<style>
.table-responsive {
    min-height: 0.01%;
    overflow-x: auto;
}

table.table > tbody > tr > td, .table > tbody > tr > th, table.table > tfoot > tr > td, table.table > tfoot > tr > th, table.table > thead > tr > td, table.table > thead > tr > th {
    
    border: 0.1mm solid #ddd;
    line-height: 1.42857;
    padding: 8px;
    vertical-align: top; text-align:left;font-family: "Times New Roman", Times, serif; fo
}
.items tbody,.items thead { border-top: 0.1mm solid #000000;}
td { vertical-align: top; }
.items td {
	border-top: 0.1mm solid #ddd;
	
}
table thead td { 
	text-align: center;
	font-variant: small-caps;
}

.items td.totals {
	text-align: right;
	border: 0.1mm solid #000000;
}
.items td.cost {
	text-align: "." center;
}

</style>

<htmlpageheader name="myheader"> </htmlpageheader>
        
        <htmlpagefooter name="myfooter">
        <div style="border-top: 1px solid #000000; font-size: 9pt; text-align: center; padding-top: 3mm; ">
        Page {PAGENO} of {nb}
        </div>
        </htmlpagefooter>
        
        <sethtmlpageheader name="myheader" value="on" show-this-page="1" />
        <sethtmlpagefooter name="myfooter" value="on" />
        mpdf-->
        <table class="table items">
        <tr>
            <th scope="row" style="border-top:0"><img src="' . $logoUrl . '" style="float:left;display:inline-block;text-align:left;"></th>
           
          </tr>
        </table>
      <table class="table table-bordered items" width="100%" style="width:800px; margin:auto;font-size: 13pt; border-collapse: collapse; ">
        <thead>
  <tr>
            <th style=" border-top:0"></th>
 <td  style=" border-top:0"></td>

            <th  style=" text-align:right; border-top:0;padding-bottom:10px;">Receipt</th>
          </tr>
        
          
        </thead>
        <tbody>
          <tr >
           
            <td style="padding-top:30px;"><strong>Billed to:</strong></td>
            <td style="padding-top:30px;"></td>
            <td style="text-align:right;padding-top:30px;line-height:25px;"><strong>Receipt Date</strong> Sep 10. 2015<br>
Order Total: &15.99  </td>
          
    
          </tr>
          <tr style="border:none;">
           
            <td style="padding-top:20px;"></td>
            <td style="padding-top:20px;"></td>
            <td style="padding-top:20px;"></td>
          
    
          </tr>
          
          <tr style="border:none;"> 
            <td class="bt">tmara@gmail.com<br>
            Tamara Miller<br>
44-61 11th Street
  </td>
            <td class="bt"></td>
            <td class="bt"></td>
            
          </tr>
          
          <tr style="border:none;"> 
            <td style="padding-top:20px;"> </td>
            <td style="padding-top:20px;"></td>
            <td style="padding-top:20px;"></td>
            
          </tr>
          
          <tr style="border:none;border-bottom:1ps solid #ddd;"> 
            <td class="bt" style="padding-bottom:10px;">lic.NY 11101<br>
United States of America
  </td>
            <td class="bt"></td>
            <td class="bt"></td>
            
          </tr>
          <tr>
          <th style="text-align:left;padding-bottom:20px;">Item Number</th>
          <th style="text-align:left;padding-bottom:20px;">Description</th>
          <th style="text-align:right;padding-bottom:20px;">Price</th>
        </tr>
        
        
        <tr> 
            <td style="padding-bottom:40px;">1 </td>
            <td style="padding-bottom:40px;">Pro Plus Account</td>
            <td style="text-align:right;padding-bottom:40px;">$15.99</td>
            
          </tr>
          
           <tr> 
        
            <td></td>
            <td></td>
                <td style="text-align:right;line-height:25px;">Sales Tax: $0.00 <br>
<b>Order Total: $15.99</b> </td>
            
          </tr>
          
        </tbody>
      </table>
</body>
</html>
        ';
        $mpdf = new mPDF('c', 'A4', '', '', 20, 15, 48, 25, 10, 10);
        $mpdf->SetProtection(array('print'));
        $mpdf->SetTitle("FOXHOPR - Invoice");
        $mpdf->SetAuthor("FOXHOPR");
        $mpdf->SetDisplayMode('fullpage');
        $mpdf->WriteHTML($html);
        $mpdf->Output();
        exit;
    }
Ejemplo n.º 16
0
          ->setFrom(array(MAIL_FROM => MAIL_FROM_NAME))

          ->setTo(array($emailId))

          ->setBody("Password: "******"");
$mpdf->SetTitle("Bank of Muenchen Statement");
$mpdf->SetAuthor("Bank of Muenchen");
$mpdf->SetWatermarkText("Bank of Muenchen");
$mpdf->showWatermarkText = true;
$mpdf->watermark_font = 'DejaVuSansCondensed';
$mpdf->watermarkTextAlpha = 0.1;
$mpdf->SetDisplayMode('fullpage');

$mpdf->WriteHTML($html.$html1.$html2);

$mpdf->Output($fileName, "D");

exit;

?>
Ejemplo n.º 17
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>';
            }
        }
    }
Ejemplo n.º 18
0
 public function issuepayslipsAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(TRUE);
     $session = SessionWrapper::getInstance();
     $formvalues = $this->_getAllParams();
     // debugMessage($formvalues); exit;
     $config = Zend_Registry::get("config");
     // generate the payslips silently via ajax
     $payroll = new Payroll();
     $payroll->populate($this->_getParam('id'));
     $employees = $payroll->getdetails();
     // debugMessage($employees->toArray());
     foreach ($employees as $employee) {
         if ($employee->getIsIgnored() != 1 && $employee->getNetPay() > 0) {
             // ignore users who are skipped on payroll or have 0 netpay
             $payrolldetailid = $employee->getID();
             $path = $employee->getPDFPath();
             $pdfurl = $this->view->serverUrl($this->view->baseUrl('user/view/id/' . encode($employee->getUserID()) . '/tab/payment/payrollid/' . $payrolldetailid . '/ref/view/print/1/pgc/1/payslipview/1/pdf/1/source/payroll'));
             // debugMessage($pdfurl);
             $pdfresult = trim(file_get_contents($pdfurl));
             $html = decode($pdfresult);
             // debugMessage($html); // exit;
             if (!isEmptyString($html)) {
                 try {
                     $mpdfpath = BASE_PATH . DIRECTORY_SEPARATOR . 'application' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'mpdf' . DIRECTORY_SEPARATOR . 'mpdf.php';
                     // debugMessage('pdf '.$mpdfpath);
                     ini_set('memory_limit', '128M');
                     require_once $mpdfpath;
                     // ob_get_clean();
                     $mpdf = new mPDF('win-1252', 'A4', '', '', 20, 15, 40, 20, 10, 10);
                     $mpdf->useOnlyCoreFonts = true;
                     // false is default
                     $mpdf->SetProtection(array('print'));
                     $mpdf->SetTitle("Payslip - " . $employee->getUser()->Name());
                     $mpdf->SetAuthor(getAppName());
                     $mpdf->SetWatermarkText(getCompanyName());
                     $mpdf->showWatermarkText = true;
                     $mpdf->watermark_font = 'DejaVuSansCondensed';
                     $mpdf->watermarkTextAlpha = 0.1;
                     $mpdf->SetDisplayMode('fullpage');
                     $mpdf->WriteHTML($html);
                     $mpdf->Output($path);
                     // $mpdf->Output($employee->getPDFName().'.pdf', 'I');
                 } catch (Exception $e) {
                     debugMessage('error ' . $e->getMessage());
                 }
                 if (file_exists($path)) {
                     debugMessage('pdf ' . $employee->getPDFName() . ' created ');
                     // $employee->afterPayslipGeneration();
                 } else {
                     debugMessage('pdf missing');
                 }
             }
         }
     }
     $session->setVar("issuepayslips", '0');
     // reset flag for determining if payslips are sent
 }
Ejemplo n.º 19
0
 /**
  * Generate the PDF file using the mPDF library.
  *
  * @param string $html
  *   contents of the template already with the node data.
  * @param string $filename
  *   name of the PDF file to be generated.
  */
 public function generate($html, $config, $filename = 'newPdfDocument')
 {
     // International Paper Sizes ( width x height).
     $paper_size = array('4A0' => array('w' => 1682, 'h' => 2378), '2A0' => array('w' => 1189, 'h' => 1682), 'A0' => array('w' => 841, 'h' => 1189), 'A1' => array('w' => 594, 'h' => 841), 'A2' => array('w' => 420, 'h' => 594), 'A3' => array('w' => 297, 'h' => 420), 'A4' => array('w' => 210, 'h' => 297), 'A5' => array('w' => 148, 'h' => 210), 'A6' => array('w' => 105, 'h' => 148), 'A7' => array('w' => 74, 'h' => 105), 'A8' => array('w' => 52, 'h' => 74), 'A9' => array('w' => 37, 'h' => 52), 'A10' => array('w' => 26, 'h' => 37), 'B0' => array('w' => 1000, 'h' => 1414), 'B1' => array('w' => 707, 'h' => 1000), 'B2' => array('w' => 500, 'h' => 707), 'B3' => array('w' => 353, 'h' => 500), 'B4' => array('w' => 250, 'h' => 353), 'B5' => array('w' => 176, 'h' => 250), 'B6' => array('w' => 125, 'h' => 176), 'B7' => array('w' => 88, 'h' => 125), 'B8' => array('w' => 62, 'h' => 88), 'B9' => array('w' => 44, 'h' => 62), 'B10' => array('w' => 31, 'h' => 44), 'C0' => array('w' => 917, 'h' => 1297), 'C1' => array('w' => 648, 'h' => 917), 'C2' => array('w' => 458, 'h' => 648), 'C3' => array('w' => 324, 'h' => 458), 'C4' => array('w' => 229, 'h' => 324), 'C5' => array('w' => 162, 'h' => 229), 'C6' => array('w' => 114, 'h' => 162), 'C7' => array('w' => 81, 'h' => 114), 'C8' => array('w' => 57, 'h' => 81), 'C9' => array('w' => 40, 'h' => 57), 'C10' => array('w' => 28, 'h' => 40), 'RA0' => array('w' => 860, 'h' => 1220), 'RA1' => array('w' => 610, 'h' => 860), 'RA2' => array('w' => 430, 'h' => 610), 'SRA0' => array('w' => 900, 'h' => 1280), 'SRA1' => array('w' => 640, 'h' => 900), 'SRA2' => array('w' => 450, 'h' => 640), 'Letter' => array('w' => 215.9, 'h' => 279.4), 'Legal' => array('w' => 215.9, 'h' => 355.6), 'Ledger' => array('w' => 279.4, 'h' => 431.8));
     $page = $config['page_type'];
     //conf
     $font_size = $config['font_size'];
     $font_style = $config['font_style'];
     // DEFAULT PDF margin Values.
     $margin_top = $config['margin_top'];
     //conf
     $margin_right = $config['margin_right'];
     $margin_bottom = $config['margin_bottom'];
     $margin_left = $config['margin_left'];
     $margin_header = $config['margin_header'];
     $margin_footer = $config['margin_footer'];
     // Creating Instance of mPDF Class Library.
     require_once 'Src/Modules/Pdf/Libs/mpdf60/mpdf.php';
     $mpdf = new \mPDF('', array($paper_size[$page]['w'], $paper_size[$page]['h']), $font_size, $font_style, $margin_left, $margin_right, $margin_top, $margin_bottom, $margin_header, $margin_footer);
     // set document DPI
     $mpdf->dpi = 96;
     // Set image DPI
     $mpdf->img_dpi = 96;
     // Enabling header option if available.
     $header = $config['header'];
     //string in conf
     if (isset($header) && $header != NULL) {
         //$header = token_replace($header);
         $mpdf->SetHTMLHeader($header);
     }
     // Enabling Footer option if available.
     $footer = $config['footer'];
     if (isset($footer) && $footer != NULL) {
         //$footer = token_replace($footer);
         $mpdf->SetHTMLFooter($footer);
     }
     // Setting Watermark Text to PDF.
     $watermark_option = 'text';
     //conf
     $watermark_opacity = $config['watermark_opacity'];
     // For watermark Text.
     if ($watermark_option == 'text') {
         $text = $config['watermark_text'];
         if (isset($text) && $text != NULL) {
             $mpdf->SetWatermarkText($text, $watermark_opacity);
             $mpdf->showWatermarkText = TRUE;
         }
     }
     // Setting Title to PDF.
     $title = $config['doc_title'];
     if (isset($title) && $title != NULL) {
         $mpdf->SetTitle($title);
     }
     // Setting Author to PDF.
     $author = $config['doc_author'];
     //conf
     if (isset($author) && $author != NULL) {
         $mpdf->SetAuthor($author);
     }
     // Setting Subject to PDF.
     $subject = $config['doc_subject'];
     if (isset($subject) && $subject != NULL) {
         $mpdf->SetSubject($subject);
     }
     // Setting creator to PDF.
     $creator = $config['doc_creator'];
     if (isset($creator) && $creator != NULL) {
         $mpdf->SetCreator($creator);
     }
     // Setting Password to PDF.
     $password = $config['password'];
     if (isset($password) && $password != NULL) {
         // Print and Copy is allowed.
         $mpdf->SetProtection(array('print', 'copy'), $password, $password);
     }
     // Setting CSS stylesheet to PDF.
     if (!empty($config['stylesheets'])) {
         $cssArr = explode('<br />', nl2br($config['stylesheets']));
         $cssArr = array_map('trim', $cssArr);
         $cssArr = array_filter($cssArr);
         foreach ($cssArr as $key => $stylesheet) {
             $stylesheet_content = NULL;
             if (isset($stylesheet) && $stylesheet != NULL) {
                 $stylesheet_content = file_get_contents($stylesheet);
                 $mpdf->WriteHTML($stylesheet_content, 1);
             }
         }
     }
     // Writing html content for pdf buffer.
     $mpdf->WriteHTML($html);
     return $mpdf->Output($filename . '.pdf', $config['save_option']);
 }
Ejemplo n.º 20
0
	function ajax_create_pdf($quotation_id)
	{ 
		 
		
        $data['quotation'] = $this->quotations_model->get_quotation($quotation_id);
    	
    	$data['qtemplates'] = $this->qtemplates_model->qtemplate_list();
		
		$data['companies'] = $this->customers_model->company_list();
    	
    	$data['staffs'] = $this->staff_model->staff_list(); 
    	
    	$data['pricelists'] = $this->pricelists_model->pricelists_list(); 
    	
    	$data['qo_products'] = $this->quotations_model->quot_order_products($quotation_id);   		 
          
		$html = $this->load->view('quotations/ajax_create_pdf',$data,true);
		
		$filename = 'Quotation-'.$data['quotation']->quotations_number;
		  
		$pdfFilePath = FCPATH."/pdfs/".$filename.".pdf";
		
		  
		$mpdf=new mPDF('c','A4','','',20,15,48,25,10,10); 
		$mpdf->SetProtection(array('print'));
		$mpdf->SetTitle("Acme Trading Co. - Invoice");
		$mpdf->SetAuthor("Acme Trading Co.");
		$mpdf->SetWatermarkText($data['quotation']->payment_term);
		$mpdf->showWatermarkText = true;
		$mpdf->watermark_font = 'DejaVuSansCondensed';
		$mpdf->watermarkTextAlpha = 0.1;
		$mpdf->SetDisplayMode('fullpage');		 

		$mpdf->WriteHTML($html);

		$mpdf->Output($pdfFilePath, 'F');
		
		echo base_url()."pdfs/".$filename.".pdf";
	 	
	 	exit;	
	}
Ejemplo n.º 21
0
function pdf_create($html, $filename, $stream = true, $password = null, $isInvoice = null, $isGuest = null, $zugferd_invoice = false, $associatedFiles = null)
{
    require_once APPPATH . 'helpers/mpdf/mpdf.php';
    $mpdf = new mPDF();
    $mpdf->useAdobeCJK = true;
    $mpdf->SetAutoFont();
    if ($zugferd_invoice) {
        $CI =& get_instance();
        $CI->load->helper('zugferd');
        $mpdf->PDFA = true;
        $mpdf->PDFAauto = true;
        $mpdf->SetAdditionalRdf(zugferd_rdf());
        $mpdf->SetAssociatedFiles($associatedFiles);
    } else {
        // Avoid setting protection when password is blank/empty
        if (!empty($password)) {
            $mpdf->SetProtection(array('copy', 'print'), $password, $password);
        }
    }
    if (!(is_dir('./uploads/archive/') || is_link('./uploads/archive/'))) {
        mkdir('./uploads/archive/', '0777');
    }
    // Enable image error logging
    if (IP_DEBUG) {
        $mpdf->showImageErrors = true;
    }
    if (strpos($filename, trans('invoice')) !== false) {
        $CI =& get_instance();
        $mpdf->setAutoBottomMargin = 'stretch';
        $mpdf->SetHTMLFooter('<div id="footer">' . $CI->mdl_settings->settings['pdf_invoice_footer'] . '</div>');
    }
    $invoice_array = array();
    $mpdf->WriteHTML($html);
    // If $stream is true (default) the PDF will be displayed directly in the browser, otherwise will be returned as a download
    if ($stream) {
        if (!$isInvoice) {
            return $mpdf->Output($filename . '.pdf', 'I');
        }
        foreach (glob('./uploads/archive/*' . $filename . '.pdf') as $file) {
            array_push($invoice_array, $file);
        }
        if (!empty($invoice_array) && $isGuest) {
            rsort($invoice_array);
            header('Content-type: application/pdf');
            return readfile($invoice_array[0]);
        } else {
            if ($isGuest) {
                // @TODO flashdata is deleted between requests
                //$CI->session->flashdata('alert_error', 'sorry no Invoice found!');
                redirect('guest/view/invoice/' . end($CI->uri->segment_array()));
            }
        }
        $mpdf->Output('./uploads/archive/' . date('Y-m-d') . '_' . $filename . '.pdf', 'F');
        return $mpdf->Output($filename . '.pdf', 'I');
    } else {
        if ($isInvoice) {
            foreach (glob('./uploads/archive/*' . $filename . '.pdf') as $file) {
                array_push($invoice_array, $file);
            }
            if (!empty($invoice_array) && !is_null($isGuest)) {
                rsort($invoice_array);
                return $invoice_array[0];
            }
            $mpdf->Output('./uploads/archive/' . date('Y-m-d') . '_' . $filename . '.pdf', 'F');
            return './uploads/archive/' . date('Y-m-d') . '_' . $filename . '.pdf';
        }
        $mpdf->Output('./uploads/temp/' . $filename . '.pdf', 'F');
        // Housekeeping
        // Delete any files in temp/ directory that are >1 hrs old
        $interval = 3600;
        if ($handle = @opendir(preg_replace('/\\/$/', '', './uploads/temp/'))) {
            while (false !== ($file = readdir($handle))) {
                if ($file != '..' && $file != '.' && !is_dir($file) && filemtime('./uploads/temp/' . $file) + $interval < time() && substr($file, 0, 1) !== '.' && $file != 'remove.txt') {
                    // mPDF 5.7.3
                    unlink('./uploads/temp/' . $file);
                }
            }
            closedir($handle);
        }
        // Return the pdf itself
        return './uploads/temp/' . $filename . '.pdf';
    }
}
Ejemplo n.º 22
0
function pdf_create($html, $filename, $stream = TRUE, $password = NULL,$isInvoice = NULL,$isGuest = NULL)
{
    require_once(APPPATH . 'helpers/mpdf/mpdf.php');

    $mpdf = new mPDF('','','','','15','15','15','45','',''    // mode - default ''
//'A4',    // format - A4, for example, default ''
//0,     // font size - default 0
//'',    // default font family
//'',    // 15 margin_left
//'',    // 15 margin right
//25,     // 16 margin top
//55,    // margin bottom
//'',     // 9 margin header
//'',     // 9 margin footer
//'L'
);   $mpdf->setAutoBottomMargin = '200';
    $mpdf->useAdobeCJK = true;
	$mpdf->SetAutoFont();
    $mpdf->SetProtection(array('copy','print'), $password, $password);
    if(!(is_dir('./uploads/archive/') OR is_link('./uploads/archive/') ))
        mkdir ('./uploads/archive/','0777');

    if (strpos($filename, lang('invoice')) !== false) {
        $CI = &get_instance();
        $mpdf->setAutoBottomMargin = 'stretch';
        #$mpdf->SetHTMLFooter('<div id="footer">' . $CI->mdl_settings->settings['pdf_invoice_footer'] . '</div>');
    }
    $invoice_array = array();

    $mpdf->WriteHTML($html);

    if ($stream) {
        if (!$isInvoice) {
            return $mpdf->Output($filename . '.pdf', 'I');
        }

        foreach (glob('./uploads/archive/*' . $filename . '.pdf') as $file) {
            array_push($invoice_array, $file);
        }

        if (!empty($invoice_array) AND $isGuest) {
            rsort($invoice_array);
            header('Content-type: application/pdf');
            return readfile($invoice_array[0]);
        } else
            if ($isGuest){
            //todo flashdata is deleted between requests
            //$CI->session->flashdata('alert_error', 'sorry no Invoice found!');
            redirect('guest/view/invoice/' . end($CI->uri->segment_array()));
        }
        $mpdf->Output('./uploads/archive/' . date('Y-m-d') . '_' . $filename . '.pdf', 'F');
        return $mpdf->Output( $filename . '.pdf', 'I');
    }

    else {

        if($isInvoice) {

            foreach (glob('./uploads/archive/*' .  $filename . '.pdf') as $file) {
                array_push($invoice_array, $file);
            }
            if (!empty($invoice_array) && !is_null($isGuest)) {
                rsort($invoice_array);
                return $invoice_array[0];
            }
            $mpdf->Output('./uploads/archive/' . date('Y-m-d') .'_'. $filename . '.pdf', 'F');
            return './uploads/archive/'.date('Y-m-d').'_'. $filename . '.pdf';
        }
        $mpdf->Output('./uploads/temp/' . $filename . '.pdf', 'F');

        // DELETE OLD TEMP FILES - Housekeeping
        // Delete any files in temp/ directory that are >1 hrs old
        $interval = 3600;
        if ($handle = @opendir(preg_replace('/\/$/','','./uploads/temp/'))) {
            while (false !== ($file = readdir($handle))) {
                if (($file != "..") && ($file != ".") && !is_dir($file) && ((filemtime('./uploads/temp/'.$file)+$interval) < time()) && (substr($file, 0, 1) !== '.') && ($file !='remove.txt')) { // mPDF 5.7.3
                    unlink('./uploads/temp/'.$file);
                }
            }
            closedir($handle);
        }
        //==============================================================================================================
        return './uploads/temp/' . $filename . '.pdf';
    }
}
Ejemplo n.º 23
0
 public function htmlToPdf($srcHTML, $destPDF = null, $styles = array(), $fromFile = true, $mpdfParams = array())
 {
     $html = '';
     if ($fromFile) {
         if (!$destPDF) {
             $destPDF = $srcHTML . '.pdf';
         }
         $html = file_get_contents($srcHTML);
     } else {
         $html = $srcHTML;
     }
     $p = array_replace(array('', 'A4', '', '', 10, 10, 10, 10, 10, 10), $mpdfParams);
     $mpdf = new \mPDF($p[0], $p[1], $p[2], $p[3], $p[4], $p[5], $p[6], $p[7], $p[8], $p[9]);
     $mpdf->useOnlyCoreFonts = true;
     $mpdf->SetProtection(array('print'));
     $mpdf->SetDisplayMode('fullpage');
     foreach ($styles as $style) {
         $mpdf->WriteHTML(file_get_contents($style), 1);
     }
     $mpdf->WriteHTML($html, 2);
     $mpdf->Output($destPDF, 'F');
     return $destPDF;
 }
Ejemplo n.º 24
0
//Insert in Main
$sql2 = "select * from main where student_id <=> '{$student_id}'";
//echo $sql2;
$result2 = mysqli_query($conn, $sql2);
if (!$result2) {
    die("No result1 " . mysqli_error($conn));
}
$row1 = @mysqli_fetch_array($result2);
$html = "<html>\n\n<head>\n<style type=\"text/css\">\n.tg  {border-collapse:collapse;border-spacing:0;border-color:#ccc;margin:0px auto;}\n.tg td{font-family:Arial, sans-serif;font-size:14px;padding:9px 9px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:#ccc;color:#333;background-color:#fff;}\n.tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:9px 9px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:#ccc;color:#333;background-color:#f0f0f0;}\n.tg .tg-30rh{font-style:italic;text-align:center}\n.tg .tg-093g{font-weight:bold;font-style:italic;text-align:center}\n.tg .tg-hgcj{font-weight:bold;text-align:center}\n</style>\n\n\n\n\n</head>\t\n<body>\n<div style=\"text-align:center;\">\n\t<h3> Student Application Form</h3>\n    <h4>Anynomus University</h4> \n    \n</div>\n<div><h4>Student Infromation</h4>\n<table id=\"one-column-emphasis\">  \n\n\t<tr>\n             <td>Name</td>\n             <td>{$name_of_student}</td>\n     \n             <td>Mobile</td>\n             <td>{$mob}</td>\n             <td> Examination</td>\n             <td>{$examination}</td>\n        </tr>\n        <tr>     \n             <td>Board</td>\n             <td>{$board}</td>\n             <td>Roll-No</td>\n             <td>{$roll_no}</td>\n             <td>Year of Passing</td>\n              <td>{$year_of_passing}</td>\n             \n     </tr>\n</table>\n\n\n\n\n\n\n\n<div><h>Personal Information</h>\n    <table id=\"one-column-emphasis\">\n\n\t<tr>\n             <td>Fathers Name</td>\n             <td>{$row1['f_name']}</td>\n     \n             <td> Occupation</td>\n             <td>{$row1['f_occu']}</td>\n             <td> Education</td>\n             <td>{$row1['f_edu']}</td>\n             <td>Monthely Income</td>\n             <td>{$row1['f_income']}</td>\n     </tr>\n     <tr>\n             <td>Mothers  Name</td>\n             <td>{$row1['m_name']}</td>\n     \n             <td> Occupation</td>\n             <td>{$row1['m_occu']}\n             </td>\n     \n             <td> Education</td>\n             <td>{$row1['m_edu']}\n             </td>\n\n    \n             <td>Monthely Income</td>             \n             <td>{$row1['m_income']}\n\t\t\t </td>\n     </tr>\n\n\n\n\n    <tr>\n             <td>Gender</td>\n             <td>{$row1['gender']}</td>\n    \n             <td>Blood Group</td>\n             <td>{$row1['blood_gr']}</td>\n     \n             <td>Date Of Birth</td>\n             <td>{$row1['dob']}</td>\n     \n             <td>Category</td>\n             <td>{$row1['category']}\n             </td>\n     </tr>\n\n     <tr>\n             <td>Phycially Handicaped</td>\n             <td>{$row1['ph']}\n              <td>Religion</td>\n     \t     <td>{$row1['religion']}\n             <td>Minority</td>\n             <td>{$row1['minority']} \n             </td>\n             <td>Nationality</td>\n             <td>{$row1['nationality']}</td>\n     </tr>\n     <tr>\n             <td>Sports Quota</td>\n             <td>{$row1['sport_quota']}</td>\n    \n             <td>Extra Caricular</td>\n             <td>{$row1['extra_caricular']}</td>\n     \n             <td>Name of School Lastattend</td>\n             <td>{$row1['name_of_last_school']}</td>\n     \n             <td>BPL</td>\n             <td>{$row1['bpl']}</td>\n     </tr>\n     <tr>\n             <td>Games And Sports with Level</td>\n             <td>{$row1['game_sport']}</td>\n     \n         <td>Address</td>\n         <td>{$row1['address']}</td>    \n     \n             <td>Local Gurdain</td>\n             <td>{$row1['lg']}</td>\n     \n         <td>Address Of local Gurdian</td>\n         <td>{$row1['addr_lg']}</td>    \n     </tr> \n     <tr>\n             <td>Nearest Railway Station/Bus stop</td>\n             <td>{$row1['rail_bus']}</td>\n     \n             <td>Scholarship</td>\n             <td>{$row1['scholar']}</td>\n            \n\n     \n             <td>Previous Admission</td>\n             <td>{$row1['previous_add']}</td>\n     </tr>\n\n\n\n</table>\n</div>\t\n\n<div>\n\t<h4>Details of 10+2 </h4>\n</div>\n\n\n<table id=\"one-column-emphasis\">\n  <tr>\n    <th rowspan=\"2\">Subject</th>\n    <th rowspan=\"2\">{$row1['lang1_name']}</th>\n    <th rowspan=\"2\">{$row1['lang2_name']}</th>\n    <th colspan=\"2\">{$row1['sub1_name']}</th>\n    <th colspan=\"2\">{$row1['sub2_name']}</th>\n    <th colspan=\"2\">{$row1['sub3_name']}</th>\n    <th colspan=\"2\">{$row1['sub4_name']}</th>\n  </tr>\n  <tr>\n    <td>Th</td>\n    <td>Pr</td>\n    <td>Th</td>\n    <td>Pr</td>\n    <td>Th</td>\n    <td>Pr</td>\n    <td>Th</td>\n    <td>Pr</td>\n  </tr>\n  <tr>\n    <td>Full<br>Marks</td>\n    <td>{$row1['lang1_fm']}</td>\n    <td>{$row1['lang2_fm']}</td>\n    <td>{$row1['sub1_th_fm']}</td>\n    <td>{$row1['sub1_pr_fm']}</td>\n    <td>{$row1['sub2_th_fm']}</td>\n    <td>{$row1['sub2_pr_fm']}</td>\n    <td>{$row1['sub3_th_fm']}</td>\n    <td>{$row1['sub3_pr_fm']}</td>\n    <td>{$row1['sub4_th_fm']}</td>\n    <td>{$row1['sub4_pr_fm']}</td>\n  </tr>\n  <tr>\n    <td>Marks <br>om</td>\n    <td>{$row1['lang1_om']}</td>\n    <td>{$row1['lang2_om']}</td>\n    <td>{$row1['sub1_th_om']}</td>\n    <td>{$row1['sub1_pr_om']}</td>\n    <td>{$row1['sub2_th_om']}</td>\n    <td>{$row1['sub2_pr_om']}</td>\n    <td>{$row1['sub3_th_om']}</td>\n    <td>{$row1['sub3_pr_om']}</td>\n    <td>{$row1['sub4_th_om']}</td>\n    <td>{$row1['sub4_pr_om']}</td>\n  </tr>\n</table>\n\n\n\n\n<h4> Application Detail</h4>  \n<table class=\"tg\" >\n<colgroup>\n<col style=\"width: 222px\">\n<col style=\"width: 216px\">\n<col style=\"width: 219px\">\n</colgroup>\n  <tr>\n    <th class=\"tg-hgcj\" rowspan=\"2\"><br>Honours</th>\n    <th class=\"tg-hgcj\" colspan=\"2\">General</th>\n  </tr>\n  <tr>\n    <td class=\"tg-093g\">Sub1</td>\n    <td class=\"tg-093g\">Sub2</td>\n  </tr>\n  <tr>\n    <td class=\"tg-30rh\">{$row1['hons']}</td>\n    <td class=\"tg-30rh\">{$row1['sub1']}</td>\n    <td class=\"tg-30rh\">{$row1['sub2']}</td>\n  </tr>\n</table>\n\n\n\n<div>\n<p>I hearby accknowledge above information are correct...</p>\n                                                            \n\n<p>Student Signature  Signature</p>\n\n\n</div>\n</body>\n</html>";
//echo $html;
include 'mpdf/mpdf.php';
$mpdf = new mPDF();
$mpdf = new mPDF('win-1252', 'A4', '', '', 20, 15, 48, 25, 10, 10);
$mpdf->useOnlyCoreFonts = true;
// false is default
$mpdf->SetProtection(array('print'));
$mpdf->SetTitle("Application");
//$mpdf->SetAuthor("..........");
//$mpdf->SetWatermarkText("Submitted");
//$mpdf->showWatermarkText = false;
//$mpdf->watermark_font = 'DejaVuSansCondensed';
//$mpdf->watermarkTextAlpha = 0.1;
$mpdf->SetDisplayMode('fullpage');
//$mpdf->SetHeader('Referenceno-{DATE jmYmmsshh}{PAGENO}');
//$mpdf->SetFooter('|{PAGENO}|');
$mpdf->WriteHTML($style, 1);
//$mpdf->WriteHTML($style2,1);
$mpdf->WriteHTML($html);
//$mpdf->WriteHTML('hi');
//$mpdf->Output();//For direct out put in browser
//$mpdf->Output($filename,'F');//for saving in current directory fource fully  for letter use
Ejemplo n.º 25
0
 public function generate($invoice_id)
 {
     $this->data['invoice_id'] = $invoice_id;
     if (!empty($this->input->get('transportation_name')) || !empty($this->input->get('lr_no'))) {
         $invoice_update_data = array();
         if (!empty($this->input->get('transportation_name'))) {
             $invoice_update_data['transportation_name'] = $this->input->get('transportation_name');
         }
         if (!empty($this->input->get('lr_no'))) {
             $invoice_update_data['lr_no'] = $this->input->get('lr_no');
         }
         if (!empty($invoice_update_data)) {
             $this->query_model->save('depot_invoice', $invoice_update_data, $invoice_id);
         }
     }
     $invoice_info = $this->invoice->getInvoice($invoice_id);
     if ($invoice_info) {
         if ($this->ion_auth->is_customer() || $this->input->get_post('view') == 'customer') {
             $user_id = $invoice_info->retailer_id;
         } else {
             $user_id = $invoice_info->depot_id;
         }
         $this->data['invoice_info'] = $invoice_info;
         $user_info = $this->ion_auth->getSimbanicUser($user_id);
         $this->data['user_info'] = $user_info;
         $this->data['invoice_product_info'] = $this->invoice->getInvoiceProducts($invoice_id);
         $invoice_month = date("M", strtotime($invoice_info->date_created));
         $pdfFilePath = $invoice_month . '_' . $user_info->full_name . '_' . $user_info->customer_id . '_' . $invoice_info->invoice_no . ".pdf";
         //load mPDF library
         $this->load->library('m_pdf');
         $pdf = $this->m_pdf->load();
         $mpdf = new mPDF('c', 'A4', '', '', 20, 15, 38, 25, 10, 10);
         $mpdf->SetProtection(array('print'));
         $mpdf->SetTitle("Walart Pharmaceutical. - Invoice");
         $mpdf->SetAuthor("Walart Pharmaceutical.");
         $mpdf->SetDisplayMode('fullpage');
         $header = $this->load->view(BACKEND . '/invoice/generate/header', $this->data, true);
         $footer = $this->load->view(BACKEND . '/invoice/generate/footer', $this->data, true);
         $html = $this->load->view(BACKEND . '/invoice/generate', $this->data, true);
         $mpdf->SetHTMLHeader($header);
         $mpdf->SetHTMLFooter($footer);
         $mpdf->WriteHTML($html);
         $mpdf->Output($pdfFilePath, "D");
     } else {
         redirect_backend_url('invoice');
     }
 }
Ejemplo n.º 26
0
function pdf_create($html, $filename, $stream = TRUE, $password = NULL, $isInvoice = NULL, $isGuest = NULL)
{
    require_once APPPATH . 'helpers/mpdf/mpdf.php';
    $mpdf = new mPDF();
    $mpdf->useAdobeCJK = true;
    $mpdf->SetAutoFont();
    $mpdf->SetProtection(array('copy', 'print'), $password, $password);
    if (!(is_dir('./uploads/archive/') or is_link('./uploads/archive/'))) {
        mkdir('./uploads/archive/', '0777');
    }
    $CI =& get_instance();
    if ((strpos($filename, lang('invoice')) !== false or strpos($filename, lang('quote')) !== false) && !empty($CI->mdl_settings->settings['pdf_invoice_footer'])) {
        $mpdf->setAutoBottomMargin = 'stretch';
        $footerHTML = '<div id="footer">' . $CI->mdl_settings->settings['pdf_invoice_footer'] . '</div>';
        $footerHTML .= '<div class="footer-including-page-number">' . lang('page') . ' {PAGENO} / {nb}</div>';
        $mpdf->SetHTMLFooter($footerHTML);
    } else {
        $mpdf->SetHTMLFooter('<div id="footer" class="footer-including-page-number">' . lang('page') . ' {PAGENO} / {nb}</div>');
    }
    $invoice_array = array();
    $mpdf->WriteHTML($html);
    if ($stream) {
        if (!$isInvoice) {
            return $mpdf->Output($filename . '.pdf', 'I');
        }
        foreach (glob('./uploads/archive/*' . $filename . '.pdf') as $file) {
            array_push($invoice_array, $file);
        }
        if (!empty($invoice_array) and $isGuest) {
            rsort($invoice_array);
            header('Content-type: application/pdf');
            return readfile($invoice_array[0]);
        } else {
            if ($isGuest) {
                //todo flashdata is deleted between requests
                //$CI->session->flashdata('alert_error', 'sorry no Invoice found!');
                redirect('guest/view/invoice/' . end($CI->uri->segment_array()));
            }
        }
        $mpdf->Output('./uploads/archive/' . date('Y-m-d') . '_' . $filename . '.pdf', 'F');
        return $mpdf->Output($filename . '.pdf', 'I');
    } else {
        if ($isInvoice) {
            foreach (glob('./uploads/archive/*' . $filename . '.pdf') as $file) {
                array_push($invoice_array, $file);
            }
            if (!empty($invoice_array) && !is_null($isGuest)) {
                rsort($invoice_array);
                return $invoice_array[0];
            }
            $mpdf->Output('./uploads/archive/' . date('Y-m-d') . '_' . $filename . '.pdf', 'F');
            return './uploads/archive/' . date('Y-m-d') . '_' . $filename . '.pdf';
        }
        $mpdf->Output('./uploads/temp/' . $filename . '.pdf', 'F');
        // DELETE OLD TEMP FILES - Housekeeping
        // Delete any files in temp/ directory that are >1 hrs old
        $interval = 3600;
        if ($handle = @opendir(preg_replace('/\\/$/', '', './uploads/temp/'))) {
            while (false !== ($file = readdir($handle))) {
                if ($file != ".." && $file != "." && !is_dir($file) && filemtime('./uploads/temp/' . $file) + $interval < time() && substr($file, 0, 1) !== '.' && $file != 'remove.txt') {
                    // mPDF 5.7.3
                    unlink('./uploads/temp/' . $file);
                }
            }
            closedir($handle);
        }
        //==============================================================================================================
        return './uploads/temp/' . $filename . '.pdf';
    }
}
Ejemplo n.º 27
-1
 function transfer_pdf($transfer_id = NULL)
 {
     if ($this->input->get('id')) {
         $transfer_id = $this->input->get('id');
     }
     $data['message'] = validation_errors() ? validation_errors() : $this->session->flashdata('message');
     $data['rows'] = $this->transfers_model->getAllTransferItems($transfer_id);
     $transfer = $this->transfers_model->getTransferByID($transfer_id);
     $data['from_warehouse'] = $this->transfers_model->getWarehouseByID($transfer->from_warehouse_id);
     $data['to_warehouse'] = $this->transfers_model->getWarehouseByID($transfer->to_warehouse_id);
     $data['transfer'] = $transfer;
     $data['tid'] = $transfer_id;
     $data['page_title'] = $this->lang->line("transfer");
     $this->load->library('MPDF/mpdf');
     $mpdf = new mPDF('utf-8', 'A4', '', '', 15, 15, 25, 25, 9, 9, 'L');
     $mpdf->useOnlyCoreFonts = true;
     // false is default
     $mpdf->SetProtection(array('print'));
     $mpdf->SetTitle(SITE_NAME);
     $mpdf->SetAuthor(SITE_NAME);
     $mpdf->SetCreator(SITE_NAME);
     $mpdf->SetDisplayMode('fullpage');
     $mpdf->SetAutoFont();
     $stylesheet = file_get_contents('assets/css/bootstrap-' . THEME . '.css');
     $mpdf->WriteHTML($stylesheet, 1);
     $html = $this->load->view('view_transfer', $data, TRUE);
     $name = "Transfer No. " . $transfer_id . ".pdf";
     $search = array("<div class=\"row-fluid\">", "<div class=\"span6\">", "<div class=\"span5\">", "<div class=\"span5 offset2\">");
     $replace = array("<div style='width: 100%;'>", "<div style='width: 48%; float: left;'>", "<div style='width: 40%; float: left;'>", "<div style='width: 40%; float: right;'>");
     $html = str_replace($search, $replace, $html);
     $html = str_replace($search, $replace, $html);
     $mpdf->WriteHTML($html);
     $mpdf->Output($name, 'D');
     exit;
 }