One of the advantages of osTicket after comparing to another ticketing system is the ability to clasify the tickets based on its department and its help topic. For those of you who implement osTicket for such company which has several departments, which is each department has several help topics, you need to filter the related help topic based on the department that selected by your customer or client. Since the help topic is the part of department, then the ticket will be able being sent to the right topic and also to the related department. This modification will add the department selection in the open or new ticket form at the client side. When the particular department selected by client, then at the Help Topic directive will automatically display all help topics belong to the selected department.
-
Open your \include\client\open.inc.php file, and find this code:
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
<tr> <th>Help Topic:</th> <td> <select name="topicId"> <option value="" selected >Select One</option> <? $services= db_query('SELECT topic_id,topic FROM '.TOPIC_TABLE.' WHERE isactive=1 ORDER BY topic'); while (list($topicId,$topic) = db_fetch_row($services)){ $selected = ($info['topicId']==$topicId)?'selected':''; ?> <option value="<?=$topicId?>"<?=$selected?>><?=$topic?></option> <? }?> <option value="0" >General Inquiry</option> </select> <font class="error">* <?=$errors['topicId']?></font> </td> </tr>then replace with this following code:
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
<tr> <th>Department:</th> <td> <select name="deptId" onChange="getTopic('findtopic.php?topic_id='+this.value)"> <option value="" selected >Select Department</option> <? $services= db_query('SELECT dept_id,dept_name FROM '.DEPT_TABLE.' ORDER BY dept_name'); while (list($deptId,$dept) = db_fetch_row($services)){ $selected = ($info['deptId']==$deptId)?'selected':''; ?> <option value="<?=$deptId?>"<?=$selected?>><?=$dept?></option> <? }?> </select> <font class="error"><b>*</b> <?=$errors['deptId']?></font> </td> </tr> <tr> <th>Help Topic:</th> <td> <div id="topicdiv"> <select name="topicId"> <option value="" selected >Select Help Topic</option> <? if ($info["deptId"]=='' || is_null($info["deptId"])) { $info["deptId"]='0'; } $services= db_query('SELECT topic_id,topic FROM '.TOPIC_TABLE.' WHERE isactive=1 AND dept_id = '.$info["deptId"].' ORDER BY topic'); while (list($topicId,$topic) = db_fetch_row($services)){ $selected = ($info['topicId']==$topicId)?'selected':''; ?> <option value="<?=$topicId?>"<?=$selected?>><?=$topic?></option> <? }?> <!-- <option value="0" >General Inquiry</option> --> </select> <font class="error">* <?=$errors['topicId']?></font> </div> </td> </tr>Find again this code:
137
</form>
after that line, please insert this following code:
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
<script> function getXMLHTTP() { //fuction to return the xml http object var xmlhttp=false; try{ xmlhttp=new XMLHttpRequest(); } catch(e) { try{ xmlhttp= new ActiveXObject("Microsoft.XMLHTTP"); } catch(e){ try{ xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e1){ xmlhttp=false; } } } return xmlhttp; } function getTopic(strURL) { var req = getXMLHTTP(); // fuction to get xmlhttp object if (req) { req.onreadystatechange = function() { if (req.readyState == 4) { //data is retrieved from server if (req.status == 200) { // which reprents ok status document.getElementById('topicdiv').innerHTML=req.responseText; } else { alert("There was a problem while using XMLHTTP:\n"); } } } req.open("GET", strURL, true); //open url using get method req.send(null); } } </script>
-
Create a new file named findtopic.php, then put it to the root directory of your osTicket. Copy-paste this following code into that file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
<?php /* File : findtopic.php */ /* Purpose: This file will help you to display the help topic */ /* automatically based on the selected department */ /* in the open or new ticket form at the client side */ /* Author : Masino Sinaga, http://www.openscriptsolution.com */ /* Created: December 2, 2009 */ require_once('main.inc.php'); if(!defined('INCLUDE_DIR')) die('Fatal Error'); define('CLIENTINC_DIR',INCLUDE_DIR.'client/'); define('OSTCLIENTINC',TRUE); //make includes happy $topic_id=$_GET['topic_id']; $query="SELECT topic_id,topic FROM ".TOPIC_TABLE." WHERE isactive=1 AND dept_id = ".$topic_id." ORDER BY topic"; $result=db_query($query); ?> <select name="topicId"> <option value="">Select Help Topic</option> <?php while (list($topicId,$topic) = db_fetch_row($result)){ ?> <option value="<?php echo $topicId; ?>"><? echo $topic; ?></option> <?php } ?> </select>
-
Open your open.php file, and find this code:
22
$_POST['deptId']=$_POST['emailId']=0; //Just Making sure we don't accept crap...only topicId is expected.
then replace with this following code:
22
// $_POST['deptId']=$_POST['emailId']=0; //Just Making sure we don't accept crap...only topicId is expected. -
Open your \include\class.ticket.php file, and find this code:
1051
if(strcasecmp($origin,'web')==0) { //Help topic only applicable on web tickets.
after that line, please insert this following code:
1052
$fields['deptId'] = array('type'=>'int', 'required'=>1, 'error'=>'Dept. required');
Find again this code:
1151
if(isset($var['topicId']) && !$var['deptId']) { //Ticket created via web by user
then replace with this following code:
1151
if(isset($var['topicId']) && $var['deptId']) { //Ticket created via web by user

There was a problem while using XMLHTTP message error came out…
Why this happened?
Tq..
What was the error message you got?
Hello Masino,
this works great, thanks!
But when I login as Staff / Admin and want to open a new ticket it doesn’t work.
In the “Help Topic” there are the topics for all departments
I looked at the “newticket.inc.php” but I don’t know how to adjust this.
Any suggestion?
Best regards
Hello masino,
Awesome tutorial, but im trying to get it to work with a theme i have installed that requires me to change:
//define(‘CLIENTINC_DIR’,INCLUDE_DIR.’client/’);
to
define(‘CLIENTINC_DIR’,'client/’);
and the theme is stored in the client/ folder in the osTicket root
what do i need to change to get it to work?
theme URL is here: http://xux.in/blog/post/osticket-theme-1-6-rc4/
Any help would be awesome thanks
I keep getting the XMLHTTP error pop-up.
If I okay it and move on anyway, it doesn’t populate the second drop-down.
If I fill in everything else and click submit – it fails, but the second drop-down is populated.
It’s as if it fails until after POST
Have checked and double checked the code, the only thing changing it from stock is the added LDAP mod to populate name & email.
Any ideas?
Hi, how can we use this in all New Ticket forms? not only for client ?
Also do you have something similar for Groups vs Departments? I mean, when a user create a ticket that user only can see the department allow by his/her group.
Hope you can help us
Hi
Thanks for the awesome mods.
Your last instruction did not work for me.
I found this below instead
and replaced it with
This seemed to work as expected for me.
Thanks
Peter
Your last instruction did not work for me.
In my code I found this below instead
if(isset($var['topicId']) { //Ticket created via web by user/or staff
also the above comment from Peter also did not helped me out in this scenario.
Please reply
Sorry for the missing last parenthese that Peter wrote above. I have just fixed it so it should be like this:
and replaced it with this following code:
Please see and re-apply again the last instruction above. Hope it helps.
Hey
It worked now… (It worked on 1.6ST)
Thanks ..