Ask not what osTicket community can do for you - ask what you can do for osTicket community

Go Back   osTicket Forums > osTicket 1.6 (Latest Release) > Mods and Customizations

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 09-09-2009, 05:10 PM
TheMadHatter TheMadHatter is offline
Junior Member
 
Join Date: Sep 2009
Posts: 4
Post [ADD ON] Assign user from ticket list

Hey everyone,

So I'm new here. Just stumbled upon osTicket the other day and have an add-on I've done that hopefully some others can put to use. I'm sure it's probably not the best or most efficient way to do it but it gets the job done. So if you'd like to be able to assign a staff user to a ticket from the list of tickets, here's how I did it.

First... I added the column header to the table in tickets.inc.php:

/include/staff/tickets.inc.php -- around line 412 (my line numbers are probably kinda high)
HTML Code:
<th width="180" >Assign...</th>
Then I added the cell in the body of the table:
/include/staff/tickets.inc.php -- around line 479
PHP Code:
<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>
Then I added a new function to class.ticket.php that is used in the code above:

/include/class.ticket.php -- at the end of the class
PHP 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;
      }

So it's not the cleanest function in the world. I typically hate writing to the document within the function but hey, I was in a hurry at the time.

Then I added a the javascript used when the new select box is changed. Back to tickets.inc.php!:

/include/staff/tickets.inc.php -- very beginning of document, line 1!
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>
Finally, we add code to actually change the assignee. Still in tickets.inc.php:

/include/staff/tickets.inc.php -- right after the first line of PHP code... line 17 for me, line 3 by default.
PHP 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);
    
$tt->setStaffId($thisStaff);

That's that... when you're all said in done you should look like (please ignore all the spam, still haven't gotten my filters perfected):



Oh yea... I also made the content holder in the /scp/ directory larger. I did that by modifying /scp/css/main.css

/scp/css/main.css -- about line 62 only thing I've changed are the widths
Code:
#container {
  width:1000px;
  text-align: left;
  margin:5px auto 0 auto;
  background:url(../images/pagebg.jpg) top left repeat-x #fff;
  border:1px solid #ccc;
  border-bottom:none;
  padding-bottom: 20px;
}

#footer {
   width:990px;
   _width:860px;
   padding:2px 5px 2px 5px;
   border:1px solid #ccc;
   border-top:1px solid #666;
   background:#ececec;
   text-align:center;
   margin:0 auto 0 auto;
}

Have fun!
Reply With Quote
  #2  
Old 09-10-2009, 02:10 PM
Skeyelab Skeyelab is offline
Member
 
Join Date: Aug 2009
Posts: 32
Default

Hey, can we make this so only managers/admins can see this column?
Reply With Quote
  #3  
Old 09-10-2009, 02:25 PM
TheMadHatter TheMadHatter is offline
Junior Member
 
Join Date: Sep 2009
Posts: 4
Default update

To make it so that only admins or managers can see the final column I modified the column headers and the column cell itself to be enclosed in a condition.

/include/staff/tickets.inc.php -- my line 412
PHP Code:
<?php if($thisuser->isadmin() || $thisuser->isManager()){ ?>
<th width="180" >Assign...</th>
<?php ?>
/include/staff/tickets.inc.php -- my line 481
PHP Code:
<?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 ?>
Reply With Quote
  #4  
Old 09-10-2009, 02:45 PM
Skeyelab Skeyelab is offline
Member
 
Join Date: Aug 2009
Posts: 32
Default

Great,

does this still send emails to the assignee when it is assigned?
Reply With Quote
  #5  
Old 09-10-2009, 02:46 PM
Skeyelab Skeyelab is offline
Member
 
Join Date: Aug 2009
Posts: 32
Default

yes it does.

(thanks me)
Reply With Quote
  #6  
Old 09-10-2009, 03:14 PM
TheMadHatter TheMadHatter is offline
Junior Member
 
Join Date: Sep 2009
Posts: 4
Default

Quote:
Originally Posted by Skeyelab View Post
Great,

does this still send emails to the assignee when it is assigned?
I'm pretty sure it doesn't. I was going to add that next...
Reply With Quote
  #7  
Old 09-10-2009, 03:27 PM
TheMadHatter TheMadHatter is offline
Junior Member
 
Join Date: Sep 2009
Posts: 4
Default

Updated to send emails when the user is assigned to a ticket --

I had to redo just a small bit of code located at my line 18 in tickets.inc.php

/include/staff/tickets.inc.php -- my line 18 (immediately after the first line of original code in the file)
PHP 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);

As you can see, I replaced the setStaffId() function with the assignStaff function. That with the message for the staff sends an email to the staff who the ticket has been assigned.
Reply With Quote
  #8  
Old 09-11-2009, 07:28 AM
harvy harvy is offline
Junior Member
 
Join Date: Aug 2009
Posts: 1
Default

Quote:
Originally Posted by TheMadHatter View Post
Hey everyone,

So I'm new here. Just stumbled upon osTicket the other day and have an add-on I've done that hopefully some others can put to use. I'm sure it's probably not the best or most efficient way to do it but it gets the job done. So if you'd like to be able to assign a staff user to a ticket from the list of tickets, here's how I did it.

First... I added the column header to the table in tickets.inc.php:

/include/staff/tickets.inc.php -- around line 412 (my line numbers are probably kinda high)
TheMadHatter,

Thanks for your hard work but can you please just post whole tickets.inc.php and class.ticket.php files as the line numbers you've given don't match what so ever? Maybe it's also compatibility issue. Is that working with RC5?

Cheers!
Reply With Quote
  #9  
Old 09-23-2009, 08:49 AM
mianos mianos is offline
Junior Member
 
Join Date: Sep 2009
Posts: 2
Default

interested in this too!!

is it working with RC5?
Reply With Quote
  #10  
Old 11-12-2009, 12:47 PM
masino_sinaga masino_sinaga is offline
Senior Member
 
Join Date: Apr 2009
Location: Jakarta, Indonesia
Posts: 571
Send a message via Yahoo to masino_sinaga
Lightbulb Yes, it is.

I have proved it in 1.6 RC5. Please follow this link.
Hope it helps you.

Sincerely,
Masino Sinaga
Reply With Quote


Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 10:19 AM.