Hesk Enhancements (v2.2)

This page outlines the enhancements I've made to the free Hesk Helpdesk software available from http://www.hesk.com.

Thanks to permission from Klemen, the developer of Hesk, you can now download the hacked files for 2.2 from here. This will allow you to save time and simply download and replace your stock Hesk files, or give you a solid base to apply your own hacks.

Please click here and download the three modified files. Follow the instructions in the readme file for installation information.

Hacked Files Installation Readme

You will need to replace the stock files from a Hesk version 2.2 installation.  You should only replace 
unmodified versions of the files.  If you replace modified versions of the files, or files of a different 
version of Hesk, you will likely break your Hesk installation.  Always back up the original files before 
doing any replacements, or implementing any hacks of your own.

Replace each of the following files from your normal installation with the versions in this archive:
/index.php
/ticket.php
/admin/admin_ticket.php

In order to implement the custom ticket categories, you will need to follow the instructions here 
http://wiki.cornempire.net/hesk/hesk22#setting_up_your_fields

If you have any questions, requests, or problems with this hack, please contact me via my blog at 
http://cornempire.net/tag/hesk/

Category Listing Modifications

Show a Single Problem Type

If you have Help Desk system serving a number of clients, or use it as a contact system, you may want to direct users to a specific problem type to eliminate the possibility of them entering the wrong data somewhere, or getting confused by the interface. Others have written similar code on the Hesk Forums, but this is what I wrote before I found those alternatives.

This is the code that normally loads the categories:

148 |h index.php
hesk_dbConnect();
$sql = 'SELECT * FROM `'.hesk_dbEscape($hesk_settings['db_pfix']).'categories` ORDER BY `cat_order` ASC';
$result = hesk_dbQuery($sql);

With a simple modification, we can add a category URL parameter, and limit what is returned:

148 |h index.php
hesk_dbConnect();
if(isset($_GET['c'])){
        $sql = 'SELECT * FROM `'.hesk_dbEscape($hesk_settings['db_pfix']).'categories` WHERE `id`=' . hesk_dbEscape($_GET['c']) . ' ORDER BY `cat_order` ASC';
}
else{
        $sql = 'SELECT * FROM `'.hesk_dbEscape($hesk_settings['db_pfix']).'categories` ORDER BY `cat_order` ASC';
}
$result = hesk_dbQuery($sql);
|h (Without Line Numbers) index.php |h
hesk_dbConnect();
if(isset($_GET['c'])){
                $sql = 'SELECT * FROM `'.hesk_dbEscape($hesk_settings['db_pfix']).'categories` WHERE `id`=' . hesk_dbEscape($_GET['c']) . ' ORDER BY `cat_order` ASC';
        }
        else{
                $sql = 'SELECT * FROM `'.hesk_dbEscape($hesk_settings['db_pfix']).'categories` ORDER BY `cat_order` ASC';
        }
$result = hesk_dbQuery($sql);

With this modification, you can send users directly to your Hesk Helpdesk and to a specific problem type through a URL like: http://www.yoursite.com/index.php?a=add&c=2 This URL would load category #2 from the DB only. You can get the category ID numbers through the Admin Panel when you create/view your categories.

Custom Fields

Display Custom Fields Dependant on Problem Types

Hesk allows you to insert custom fields into your ticket submissions, but if you are like me, and using this in a multi-project environment, not all fields will apply to all users. As there is no way natively to associate fields to categories, I've developed this little hack to do just that.

  • This modification depends on the modification above for a single problem type display. Please put this into place before you attempt to implement the solution below.
  • This solution also uses Javascript and currently provides no fallback if the user has it disabled. You may want to consider your audience before deploying this solution.
  • This tutorial walks you through the steps using line numbers based on the line numbers as modified by the tutorial. If you skip steps, the numbers may be off, or if you have your own customizations in Hesk, they may also throw off the line numbers. I'll include before and after for reference.

1: Modify The Initial Handler

The first step is to modify the code after the comment:

58|h index.php
/* What should we do? */

And add in a custom handler:

58|h index.php
/* What should we do? */
$action=hesk_input($_REQUEST['a']) or $action='start';
if ($action == 'start') {print_start();}
elseif(!isset($_GET['c'])) {print_add_ticket_start();}
elseif ($action == 'add') {print_add_ticket();}
elseif ($action == 'forgot_tid') {forgot_tid();}
else {hesk_error($hesklang['invalid_action']);}

Line 61 is the new line, and it directs the page to a new function if a category is not selected. As indicated above, this depends on my solution to a single category selection. If you are using another selection method, you will need to either switch to mine, or modify the variable within !isset() to check the variable you have set.

2: Add in Custom Function

Now, you will need to add in a new function. I based it on the print_add_ticket() function but stripped it down to the bare minimum. I've got the entire function below, please copy and paste it into your index.php file on line 72.

|h index.php
function print_add_ticket_start() {
global $hesk_settings, $hesklang;
/* Print header */
$hesk_settings['tmp_title'] = $hesk_settings['hesk_title'] . ' - ' . $hesklang['submit_ticket'];
require_once(HESK_PATH . 'inc/header.inc.php');
?>
 
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="3"><img src="img/headerleftsm.jpg" width="3" height="25" alt="" /></td>
<td class="headersm"><?php hesk_showTopBar($hesklang['submit_ticket']); ?></td>
<td width="3"><img src="img/headerrightsm.jpg" width="3" height="25" alt="" /></td>
</tr>
</table>
 
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr>
<td><span class="smaller"><a href="<?php echo $hesk_settings['site_url']; ?>" class="smaller"><?php echo $hesk_settings['site_title']; ?></a> &gt;
<a href="<?php echo $hesk_settings['hesk_url']; ?>" class="smaller"><?php echo $hesk_settings['hesk_title']; ?></a>
&gt; <?php echo $hesklang['submit_ticket']; ?></span></td>
</tr>
</table>
 
</td>
</tr>
<tr>
<td>
 
	<?php
	    if(isset($_SESSION['HESK_ERROR']))
        {
	?>
	        <div align="center">
	        <table border="0" width="600" id="error" cellspacing="0" cellpadding="3">
		        <tr>
		        	<td align="left" class="error_header">&nbsp;<img src="img/error.gif" style="vertical-align:text-bottom" width="16" height="16" alt="" />&nbsp; <?php echo $hesklang['error']; ?></td>
		        </tr>
		        <tr>
		        	<td align="left" class="error_body"><ul><?php echo $_SESSION['HESK_MESSAGE']; ?></ul></td>
		        </tr>
	        </table>
	        </div>
            <br />
	<?php
	        unset($_SESSION['HESK_ERROR']);
	        unset($_SESSION['HESK_MESSAGE']);
	    }
	?>
 
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
	<td width="7" height="7"><img src="img/roundcornerslt.jpg" width="7" height="7" alt="" /></td>
	<td class="roundcornerstop"></td>
	<td><img src="img/roundcornersrt.jpg" width="7" height="7" alt="" /></td>
</tr>
<tr>
	<td class="roundcornersleft">&nbsp;</td>
	<td>
    <!-- START FORM -->
 
	<p><?php echo $hesklang['use_form_below']; ?>
	<font class="important"> *</font></p>
 
	<form method="post" action="submit_ticket.php" name="form1" enctype="multipart/form-data"
	<?php
	if ($hesk_settings['kb_enable'] && $hesk_settings['kb_recommendanswers'] && $_SESSION['ARTICLES_SUGGESTED'] == false)
	{
		echo 'onsubmit="Javascript: return hesk_suggestKB();"';
	}
	?>
    >
 
	<!-- Contact info -->
 
	<!-- Department and priority -->
	<table border="0" width="100%">
	<tr>
	<td style="text-align:right" width="150"><?php echo $hesklang['category']; ?>: <font class="important">*</font></td>
	<td width="80%"><select name="category" onchange="window.location='index.php?a=add&c=' + this.value;"><option>-- Select --</option>
	<?php
	require(HESK_PATH . 'inc/database.inc.php');
 
	hesk_dbConnect();
	if(isset($_GET['c'])){
		$sql = 'SELECT * FROM `'.hesk_dbEscape($hesk_settings['db_pfix']).'categories` WHERE `id`=' . hesk_dbEscape($_GET['c']) . ' ORDER BY `cat_order` ASC';
	}
	else{
 
		$sql = 'SELECT * FROM `'.hesk_dbEscape($hesk_settings['db_pfix']).'categories` ORDER BY `cat_order` ASC';
	}
	$result = hesk_dbQuery($sql);
	while ($row=hesk_dbFetchAssoc($result))
	{
	    if (isset($_SESSION['c_category']) && $_SESSION['c_category'] == $row['id']) {$selected = ' selected="selected"';}
	    else {$selected = '';}
	    echo '<option value="'.$row['id'].'"'.$selected.'>'.$row['name'].'</option>';
	}
 
	?>
	</select></td>
	</tr>
	</table>
 
	</form>
 
    <!-- END FORM -->
	</td>
	<td class="roundcornersright">&nbsp;</td>
</tr>
<tr>
	<td><img src="img/roundcornerslb.jpg" width="7" height="7" alt="" /></td>
	<td class="roundcornersbottom"></td>
	<td width="7" height="7"><img src="img/roundcornersrb.jpg" width="7" height="7" alt="" /></td>
</tr>
</table>
 
<?php
} // End print_add_ticket_start()

3: Modify print_add_ticket()

Now comes the hard part. Modifying the print_add_ticket function to handle our custom fields. Make sure you don't skip/leave out any part of this, as it may cause the whole page to fail to load/function correctly.

On line 284, add a link that can take users back to another Category if needed:

276|h index.php
	while ($row=hesk_dbFetchAssoc($result))
	{
	    if (isset($_SESSION['c_category']) && $_SESSION['c_category'] == $row['id']) {$selected = ' selected="selected"';}
	    else {$selected = '';}
	    echo '<option value="'.$row['id'].'"'.$selected.'>'.$row['name'].'</option>';
	}
 
	?>
	</select> <a href="index.php?a=add">Select Another Category</a></td>
	</tr>

Now, we will need to go into the custom fields loop and do a check for the fields we want to show. This bit of code looks at the name of each field, splits on the _ and checks to see if the category ID matches the one specified in the URL. For this reason, you cannot use _ in the name of a field any more. You can specify multiple category ids be separating them with commas.

So, on line 312, the first loop starts. Add the code in line 314 to 317.

306|h index.php
	<!-- START CUSTOM BEFORE -->
	<?php
	/* custom fields BEFORE comments */
 
	$print_table = 0;
 
	foreach ($hesk_settings['custom_fields'] as $k=>$v)
	{
		$catsforcustom = explode('_',$v['name']);
		$catsforcustom = explode(',',$catsforcustom[0]);
		if(!in_array($_GET['c'],$catsforcustom)){continue;}
		if ($v['use'] && $v['place']==0)

The code basically tells the script to not print custom fields if the category ID isn't specified before the name.

Deeper in the function we need to modify the printed name of the custom field, otherwise it will print the numbers before the name. Add lines 347 and 348 below.

343|h index.php
            else
            {
            	$k_value  = '';
            }
 
		$temp = explode('_',$v['name']);
		$v['name'] = $temp[1];
	        switch ($v['type'])
	        {
	        	/* Radio box */

Now we need to make the same two changes to the custom fields that are set to display after the Message box. Add lines 519 - 521.

512|h index.php
	<!-- START CUSTOM AFTER -->
	<?php
	/* custom fields AFTER comments */
	$print_table = 0;
 
	foreach ($hesk_settings['custom_fields'] as $k=>$v)
	{
		$catsforcustom = explode('_',$v['name']);
		$catsforcustom = explode(',',$catsforcustom[0]);
		if(!in_array($_GET['c'],$catsforcustom)){continue;}
		if ($v['use'] && $v['place'])
		{

And lines 551 - 552.

547|h index.php
            else
            {
            	$k_value  = '';
            }
 
		$temp = explode('_',$v['name']);
		$v['name'] = $temp[1];
	        switch ($v['type'])
	        {
	        	/* Radio box */

4: Modify ticket.php

You will now need to modify ticket.php to filter out unneeded custom fields, and to lop off the catids at the start. This will affect the clients view of the ticket to not include unnecessary fields. Only a few changes needed here, same as the custom field loops in the index.php file. Add lines 272 to 274, 282 and 283, 308 to 310, 318 and 319.

266|h ticket.php
		/* custom fields before message */
		$print_table = 0;
		$myclass = ' class="tickettd"';
 
		foreach ($hesk_settings['custom_fields'] as $k=>$v)
		{
			$catsforcustom = explode('_',$v['name']);
			$catsforcustom = explode(',',$catsforcustom[0]);
			if(!in_array($ticket['category'],$catsforcustom)){continue;}
			if ($v['use'] && $v['place']==0)
		    {
		    	if ($print_table == 0)
		        {
		        	echo '<table border="0" cellspacing="1" cellpadding="2">';
		        	$print_table = 1;
		        }
				$temp = explode('_',$v['name']);
				$v['name'] = $temp[1];
		        echo '
				<tr>
				<td valign="top" '.$myclass.'>'.$v['name'].':</td>
				<td valign="top" '.$myclass.'>'.$ticket[$k].'</td>
				</tr>
		        ';
		    }
		}
		if ($print_table)
		{
			echo '</table>';
		}
		?>
 
		<p><b><?php echo $hesklang['message']; ?>:</b></p>
		<p><?php echo $ticket['message']; ?><br />&nbsp;</p>
 
		<?php
		/* custom fields after message */
		$print_table = 0;
		$myclass = 'class="tickettd"';
 
		foreach ($hesk_settings['custom_fields'] as $k=>$v)
		{
			$catsforcustom = explode('_',$v['name']);
			$catsforcustom = explode(',',$catsforcustom[0]);
			if(!in_array($ticket['category'],$catsforcustom)){continue;}
			if ($v['use'] && $v['place'])
		    {
		    	if ($print_table == 0)
		        {
		        	echo '<table border="0" cellspacing="1" cellpadding="2">';
		        	$print_table = 1;
		        }
				$temp = explode('_',$v['name']);
				$v['name'] = $temp[1];
		        echo '
				<tr>
				<td valign="top" '.$myclass.'>'.$v['name'].':</td>
				<td valign="top" '.$myclass.'>'.$ticket[$k].'</td>
				</tr>
		        ';
		    }
		}
		if ($print_table)
		{
			echo '</table>';
		}

(Optional) 5. Modify admin_ticket.php

Optionally you can choose to customize the admin_ticket.php file. This will cause the custom fields to appear to administrators and helpdesk staff as they appear to end users.

You will need to make the following changes to the admin_ticket.php file. Line numbers are displayed assuming the additions are done in this order.

Add lines 603 to 605, 613 and 614, 638 to 640, 648 and 649:

596|h admin_ticket.php
			<?php
			/* custom fields before message */
			$print_table = 0;
			$myclass = ' class="tickettd"';
 
			foreach ($hesk_settings['custom_fields'] as $k=>$v)
			{
				$catsforcustom = explode('_',$v['name']);
				$catsforcustom = explode(',',$catsforcustom[0]);
				if(!in_array($ticket['category'],$catsforcustom)){continue;}
				if ($v['use'] && $v['place']==0)
			    {
			    	if ($print_table == 0)
			        {
			        	echo '<table border="0" cellspacing="1" cellpadding="2">';
			        	$print_table = 1;
			        }
					$temp = explode('_',$v['name']);
					$v['name'] = $temp[1];
			        echo '
					<tr>
					<td valign="top" '.$myclass.'>'.$v['name'].':</td>
					<td valign="top" '.$myclass.'>'.$ticket[$k].'</td>
					</tr>
			        ';
			    }
			}
			if ($print_table)
			{
				echo '</table>';
			}
			?>
 
			<p><b><?php echo $hesklang['message']; ?>:</b></p>
			<p><?php echo $ticket['message']; ?><br />&nbsp;</p>
 
			<?php
			/* custom fields after message */
			$print_table = 0;
 
			foreach ($hesk_settings['custom_fields'] as $k=>$v)
			{
				$catsforcustom = explode('_',$v['name']);
				$catsforcustom = explode(',',$catsforcustom[0]);
				if(!in_array($ticket['category'],$catsforcustom)){continue;}
				if ($v['use'] && $v['place'])
			    {
			    	if ($print_table == 0)
			        {
			        	echo '<table border="0" cellspacing="1" cellpadding="2">';
			        	$print_table = 1;
			        }
					$temp = explode('_',$v['name']);
					$v['name'] = $temp[1];
			        echo '
					<tr>
					<td valign="top" '.$myclass.'>'.$v['name'].':</td>
					<td valign="top" '.$myclass.'>'.$ticket[$k].'</td>
					</tr>
			        ';
			    }
			}
			if ($print_table)
			{
				echo '</table>';
			}
			?>

Setting Up Your Fields

When you enter your custom fields, you will now need to prefix each field with the id number of the category it should appear for. So, if you want some fields to appear for Category 5, and one to appear for both 3 and 5, you will enter them like this:

You can get the category ids by visiting the Categories menu in the Admin screen. Hover your mouse over the move/delete buttons, and the URL that appears will contain the catid= of the category.

Concluding Thoughts

Now, that is all you will need to do. Save your file and upload it to your site, and you now have custom fields for problem types. Make sure you test this before you deploy it, as it may negate some other functionality you were using.

hesk/hesk22.txt · Last modified: 2013/12/07 20:59 by cornmaster
CC Attribution-Noncommercial-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0