Menampilkan Topik Bantuan Berdasarkan Departemen Terpilih pada Form Tiket Baru di Sisi Klien osTicket v1.6 RC5

Salah satu keuntungan dari osTicket setelah membandingkan dengan sistem tiket lainnya adalah kemampuan untuk mengklasifikasikan tiket berdasarkan departemen dan topik bantuannya. Bagi Anda yang mengimplementasikan osTicket untuk perusahaan yang memiliki beberapa departemen, di mana setiap departemen memiliki beberapa topik bantuan masing-masing yang berbeda, Anda perlu menyaring topik bantuan yang terkait dengan departemen yang dipilih oleh pelanggan atau klien Anda. Karena topik bantuan merupakan bagian dari departemen, maka tiket akan dapat dikirim sesuai dengan topik bantuan dan juga sesuai dengan departemen yang terkait yang menangani topik bantuan tadi. Modifikasi berikut akan menambahkan pilihan departemen pada form buka tiket baru di sisi klien. Ketika departemen tertentu dipilih oleh klien maka di combobox Topik Bantuan akan otomatis menampilkan semua topik bantuan milik departemen tadi.

  1. Buka file \include\client\open.inc.php Anda, dan cari kode ini:

    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>
                &nbsp;<font class="error">*&nbsp;<?=$errors['topicId']?></font>
            </td>
        </tr>

    lalu ganti dengan kode berikut ini:

    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>
                &nbsp;<font class="error"><b>*</b>&nbsp;<?=$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>&nbsp;<font class="error">*&nbsp;<?=$errors['topicId']?></font>
                </div>                      
            </td>
        </tr>

    Cari lagi kode ini:

    137
    
    </form>

    setelah baris kode tersebut, tambahkan kode berikut:

    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>
  2. Buat file baru bernama findtopic.php, lalu letakkan di direktori utama dari osTicket Anda. Salin kode berikut ke dalam file tadi:

    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>
  3. Buka file open.php Anda, dan cari kode ini:

    22
    
        $_POST['deptId']=$_POST['emailId']=0; //Just Making sure we don't accept crap...only topicId is expected.

    lalu timpa dengan kode berikut:

    22
    
        // $_POST['deptId']=$_POST['emailId']=0; //Just Making sure we don't accept crap...only topicId is expected.
  4. Buka file \include\class.ticket.php Anda, dan cari kode ini:

    1051
    
            if(strcasecmp($origin,'web')==0) { //Help topic only applicable on web tickets.

    setelah baris kode tadi, tambahkan kode berikut:

    1052
    
                $fields['deptId']   = array('type'=>'int',      'required'=>1, 'error'=>'Dept. required');

    Cari lagi kode ini:

    1151
    
            if(isset($var['topicId']) && !$var['deptId']) { //Ticket created via web by user

    lalu timpa dengan kode berikut:

    1151
    
            if(isset($var['topicId']) && $var['deptId']) { //Ticket created via web by user
Share

959 kali dibacaCetak Artikel Ini Cetak Artikel Ini

Komentar

  1. sfairuz mengatakan:

    There was a problem while using XMLHTTP message error came out…

    Why this happened?

    Tq..

  2. Masino Sinaga mengatakan:

    What was the error message you got?

  3. Grafcom mengatakan:

    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

  4. Cliff mengatakan:

    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

  5. Wes mengatakan:

    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?

  6. Gaby mengatakan:

    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

  7. Peter mengatakan:

    Hi
    Thanks for the awesome mods.

    Your last instruction did not work for me.
    I found this below instead

    if(isset($var['topicId'])) { //Ticket created via web by user/or staff

    and replaced it with

      if(isset($var['topicId']) && $var['deptId']) { //Ticket created via web by user

    This seemed to work as expected for me.
    Thanks
    Peter

  8. fackeid mengatakan:

    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

    • Masino Sinaga mengatakan:

      Sorry for the missing last parenthese that Peter wrote above. I have just fixed it so it should be like this:

      if(isset($var['topicId'])) { //Ticket created via web by user/or staff

      and replaced it with this following code:

              if(isset($var['topicId']) && $var['deptId']) { //Ticket created via web by user

      Please see and re-apply again the last instruction above. Hope it helps.
      ;)

  9. fackeid mengatakan:

    Hey

    It worked now… (It worked on 1.6ST)

    Thanks ..

Utarakan pikiran Anda

*


*