Show Ticket Only for Current User’s Department in osTicket v1.6 RC5

Have you ever wanted to display the tickets only for current staff user’s department in osTicket? As we know, the current condition in osTicket until version 1.6 RC5 is when a user display the ticket list from staff panel, then he/she can still see all the tickets that belong to another department. By using this modification, now staff limited can only to see the tickets relevant to their department, either from the ticket list and the viewticket page. Well, here is the solution for you.

  1. Open your \include\staff\tickets.inc.php file, and find this code:

    83
    84
    
        //limited depts....user can access tickets assigned to them regardless of the dept.
        $qwhere =' WHERE (ticket.dept_id IN ('.implode(',',$depts).') OR ticket.staff_id='.$thisuser->getId().')';

    then replace with this following code:

    83
    84
    85
    
        //limited depts....user can access tickets assigned to them regardless of the dept.
        //$qwhere =' WHERE (ticket.dept_id IN ('.implode(',',$depts).') OR ticket.staff_id='.$thisuser->getId().')';
        $qwhere =' WHERE (ticket.dept_id = '.$thisuser->getDeptId().' OR ticket.staff_id='.$thisuser->getId().')';
  2. Open your \scp\tickets.php file, and find this code:

    24
    
    $ticket=null; //clean start.

    after that line, please insert this following code:

    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    
    if($id=$_REQUEST['id']?$_REQUEST['id']:$_POST['ticket_id'] && is_numeric($id)) {
      $qselect = 'SELECT ticketID, dept_id, staff_id FROM '.TICKET_TABLE. 
                 ' WHERE ticket_id='.$id.'';
      $rselect = db_query($qselect); 
      if (db_num_rows($rselect) > 0) {
        list($ticketID, $dept_id,$staff_id) = db_fetch_row($rselect);
        if (($dept_id!=$thisuser->getDeptId()) && ($staff_id!=$thisuser->getId()) ) { 
          $errors['err']='The ticket # '.$ticketID.' belongs to another department!';
        }
      }
    }

    Find again this code:

    407
    408
    409
    
    if(!$thisuser->isAdmin()){
        $sql.=' WHERE ticket.dept_id IN('.implode(',',$thisuser->getDepts()).') OR ticket.staff_id='.db_input($thisuser->getId());
    }

    then replace with this following code:

    407
    408
    409
    410
    
    if(!$thisuser->isAdmin()){
        //$sql.=' WHERE ticket.dept_id IN('.implode(',',$thisuser->getDepts()).') OR ticket.staff_id='.db_input($thisuser->getId());
        $sql .=' WHERE (ticket.dept_id = '.$thisuser->getDeptId().' OR ticket.staff_id='.$thisuser->getId().')';
    }

That’s all. Enjoy the result! :-)

Share

659 viewsPrint This Post Print This Post

Comments

  1. Daniel says:

    Hi Masino, i have tested this mod and i have found a problem
    When you log as Admin, and try to access any ticket, i you are not in the “ticket group”, you cant access it
    I’d rather admin has total access to tickcets so i suggest includding the condition
    && (!$thisuser->isAdmin()) in your MOD
    So it wold look like:

    < 0) {
        list($ticketID, $dept_id,$staff_id) = db_fetch_row($rselect);
        if (($dept_id!=$thisuser->getDeptId()) && ($staff_id!=$thisuser->getId()) && (!$thisuser->isAdmin()) ) { 
          $errors['err']='The ticket # '.$ticketID.' belongs to another department!';
        }
      }
    }
    >>

Speak Your Mind

*


*