From 5a96884dd1b126fbe30cc8aad4ee69daa52a91bd Mon Sep 17 00:00:00 2001
From: JediKev <kevin@enhancesoft.com>
Date: Tue, 1 Oct 2019 15:12:46 -0500
Subject: [PATCH] issue: Mbstring Extension Requirement

This addresses an issue reported on the forum where printing a ticket in
v1.12 and above requires `mbstring`. This updates the print call to check
for the `mbstring` extension and if not loaded will fail with a detailed
error `mbstring extension required to print ticket to PDF`.
---
 include/upgrader/prereq.inc.php |  2 +-
 scp/tickets.php                 | 11 ++++++++---
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/include/upgrader/prereq.inc.php b/include/upgrader/prereq.inc.php
index a46dcecaa..9b0bd10cd 100644
--- a/include/upgrader/prereq.inc.php
+++ b/include/upgrader/prereq.inc.php
@@ -17,7 +17,7 @@ if(!defined('OSTSCPINC') || !$thisstaff || !$thisstaff->isAdmin()) die('Access D
                 <li class="<?php echo $upgrader->check_php()?'yes':'no'; ?>">
                 <?php echo sprintf(__('%s or later'), 'PHP v'.SetupWizard::getPHPVersion()); ?> - (<small><b><?php echo PHP_VERSION; ?></b></small>)</li>
                 <li class="<?php echo $upgrader->check_mysql()?'yes':'no'; ?>">
-                <?php echo __('MySQLi extension for PHP'); ?>- (<small><b><?php
+                <?php echo __('MySQLi extension for PHP'); ?> - (<small><b><?php
                     echo extension_loaded('mysqli')?__('module loaded'):__('missing!'); ?></b></small>)</li>
                 <li class="<?php echo $upgrader->check_mysql_version()?'yes':'no'; ?>">
                 <?php echo sprintf(__('%s or later'), 'MySQL v'.SetupWizard::getMySQLVersion()); ?> - (<small><b><?php echo db_version(); ?></b></small>)</li>
diff --git a/scp/tickets.php b/scp/tickets.php
index 4d6793d41..f19942442 100644
--- a/scp/tickets.php
+++ b/scp/tickets.php
@@ -495,9 +495,14 @@ if($ticket) {
             $f->filterFields(function($f) { return !$f->isStorable(); });
             $f->addMissingFields();
         }
-    } elseif($_REQUEST['a'] == 'print' && !$ticket->pdfExport($_REQUEST['psize'], $_REQUEST['notes'], $_REQUEST['events']))
-        $errors['err'] = __('Unable to export the ticket to PDF for print.')
-            .' '.__('Internal error occurred');
+    } elseif($_REQUEST['a'] == 'print')
+        if (!extension_loaded('mbstring'))
+            $errors['err'] = sprintf('%s %s',
+                'mbstring',
+                __('extension required to print ticket to PDF'));
+        elseif (!$ticket->pdfExport($_REQUEST['psize'], $_REQUEST['notes'], $_REQUEST['events']))
+            $errors['err'] = __('Unable to export the ticket to PDF for print.')
+                .' '.__('Internal error occurred');
 } else {
     $inc = 'templates/queue-tickets.tmpl.php';
     if ($_REQUEST['a']=='open' &&
-- 
GitLab