Assigning Staff from Ticket List in osTicket v1.6 RC5

One of the nice MODs on osTicket Discussion Forum is [ADD ON] Assign user from ticket list. This MOD will make you easier to assign the tickets simply from the ticket list page, and only admin and manager are able to do this task. Besides that, each time a ticket assigned to a staff, that staff will get an alert via email. Since there were two members on the forum asking the question whether this MOD working on v1.6 RC5, then I tried to implement it on that version, and everything worked fine. So this modification is for you.

  1. Open your \include\staff\tickets.inc.php file, and then at the first line in that file above, add this following code:

    <script type="text/javascript">
    function changeAssignee(ticketID)
    {
    	var obj = "staff_select"+ticketID;
    	var sel = document.getElementById(obj);
    	var assignee = sel.options[sel.selectedIndex].value;
    	
    	var url = "index.php?update=staff&staffid="+assignee+"&ticket_id="+ticketID;
    	
    	window.location.href = url;
    }
    </script>
    
  2. Still in the same file above, find again this code:

    if(!defined('OSTSCPINC') || !@$thisuser->isStaff()) die('Access Denied');
    
    //Get ready for some deep shit..(I admit..this could be done better...but the shit just works... so shutup for now).
    

    after the last line of that code, please insert this following code:

    // assign the user from the drop down list if one has been selected
    if(isset($_GET['update']) && $_GET['update'] == "staff")
    {
        $thisStaff = $_GET['staffid'];
        $ticketToUpdate = $_GET['ticket_id'];
        $tt = new Ticket($ticketToUpdate);
        $staffMessage = "You have been assigned a ticket.";
        $tt->assignStaff($thisStaff,$staffMessage);
    }  
    
  3. Still in the same file above, find again this code:

                <th width="180" >From</th>
            </tr>
    

    then replace it with this following code:

                <th width="180" >From</th>
                <?php if($thisuser->isadmin() || $thisuser->isManager()){ ?> 
                <th width="180" >Assign...</th>
                <?php } ?>
            </tr>
    
  4. Still in the same file above, find again this code:

                    <td nowrap><?=Format::truncate($row['name'],22,strpos($row['name'],'@'))?>&nbsp;</td>
                </tr>
    

    then replace it with this following code:

                    <td nowrap><?=Format::truncate($row['name'],22,strpos($row['name'],'@'))?>&nbsp;</td>
                    <?php if($thisuser->isadmin() || $thisuser->isManager()){ ?>
                    <td nowrap>
                      <!-- staff select added by me -->
                      <?php
                      $thisTicket = new Ticket($row['ticket_id']);
                      ?>                    
                      <select id="staff_select<? echo $row['ticket_id'];?>" onchange="changeAssignee(<? echo $row['ticket_id'] ?>);">
                       <option <?if($row['staff_id'] == 0){?>SELECTED<?}?> value="0">Assign...</option>
                       <?php
                         $possibleAssignees = $thisTicket->getPossibleAssignees($row['staff_id']);
                       ?>
                     </select>
                    </td>                
                    <?php } ?>
                </tr>
    
  5. Open your \include\class.ticket.php file, and find this code:

    }
    ?>
    

    then replace it with this following code:

      function getPossibleAssignees($currentStaffID)
      {
         $sql = "SELECT staff_id, CONCAT(firstname,' ',lastname) as name from ".STAFF_TABLE;
         $query = db_query($sql);
         $i=0;
         while($row = db_fetch_array($query))
         {
              $id = $row['staff_id'];
          $name = $row['name'];
                  
          if($currentStaffID == $id)
          {
               $option = "<option value=\"".$id."\" SELECTED>".$name."</option>";               
           } else {
               $option = "<option value=\"".$id."\">".$name."</option>";           
                }
       
             echo $option;
          }
      }  
    }
    ?>
    

Enjoy the results! :)

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>