Adding a New Field to tickets – osTicket Forums

Adding a New Field to tickets – osTicket Forums.

Adding a New Field to tickets


There have been a lot of questions about how to add a new field to the ticket and rightly so, the more info a user can provide the better. For our purposes we wanted to add a Company field so we knew exactly who we were dealing with.

We added the field successfully and this thread explains the process. As a favor, can someone help us with adding that new field to the “tickets.inc.php” page?!?! It would be greatly appreciated. We’d like to be able to see Company in that table as a column where you see the ticket id, date, department, priority etc.

To add a new field there are 6 places you have to go to accomplish your goal.

  1. MySQL Database: manually add a field to ost_Ticket
  2. support/include/class.ticket.php
  3. support/include/client/open.inc.php
  4. support/include/client/viewticket.inc.php
  5. include/staff/viewticket.inc.php
  6. include/staff/newticket.inc.php

2.) class.ticket.php
Add your variable here:

PHP Code:
class Ticket{

var

$id;
var
$extid;
var
$email;
var
$status;
var
$created;
var
$updated;
var
$priority;

and here: like so ($this->newvar=$row[‘newvar’]

PHP Code:
if(($res=db_query($sql)) && db_num_rows($res)):
$row=db_fetch_array($res);
$this->id =$row['ticket_id'];
$this->extid =$row['ticketID'];
$this->email =$row['email'];
$this->fullname =$row['name'];

and here:

PHP Code:
//GET
function getId(){
return
$this->id;
}

function

getExtId(){
return
$this->extid;
}

function

getEmail(){
return
$this->email;
}

function

getNewvar(){
return
$this->newvar;
}

and here:

PHP Code:
function create($var,&$errors,$origin,$autorespond=true,$alertstaff=true) {
global
$cfg,$thisclient,$_FILES;

$id=0;
$fields=array();
$fields['newvar']     = array('type'=>'string', 'required'=>1, 'error'=>'newvar required');

and finally:

PHP Code:
$extId=Ticket::genExtRandID();
$sql= 'INSERT INTO '.TICKET_TABLE.' SET created=NOW() '.
',ticketID='.db_input($extId).
',dept_id='.db_input($deptId).
',priority_id='.db_input($priorityId).
',email='.db_input($var['email']).
',name='.db_input(Format::striptags($var['name'])).
',newvar='.db_input(Format::striptags($var['newvar'])).
3.) open.inc.php Copy info from other the other fields, just make sure the new field php scripts are different.

4.) viewticket.inc.php Repeat Step 3

5.) staff/viewticket.inc.php Repeat Step 4

4.) staff/newticket.inc.php Repeat Step 5

I was able to successfully add a new field to my ticket. I tested it in the client side and the staff side(w/o mod) and it works great!

/* Add New Fields Modification
* Author: James Williams
* osTicket v1.6 RC4
* Date: 07-22-08
* Ref: http://www.osticket.com/forums/showthread.php?t=873
*/

DB Table: ost_ticket
Field Type Collation Attributes Null
location text latin1_general_ci No


+ADD include\client\open.inc.php between subject and intersection

Code:
<tr>
        <th valign="top">Location, Address, or Intersection:</th>
        <td>
            <? if($errors['location']) {?> <font class="error"><b>&nbsp;<?=$errors['location']?></b></font><br/><?}?>
            <textarea name="location" cols="35" rows="3" wrap="soft" style="width:85%"><?=$info['location']?></textarea></td>
    </tr>

+ADD include\class.ticket.php

PHP Code:
var $location; // mod080722_new_ticket_field

+ADD include\class.ticket.php

PHP Code:
$this->location =$row['location']; // Mod080722_new_ticket_field

+ADD include\class.ticket.php

PHP Code:
// mod080722_new_ticket_field
function getLocation() {
return
$this->row['location'];
}

+ADD include\class.ticket.php

PHP Code:
$fields['location']        = array('type'=>'text', 'required'=>0, 'error'=>'Provide a location, address, or directions'); //mod080722_new_ticket_field

+ADD include\class.ticket.php

PHP Code:

//We are ready son...hold on to the rails.
$extId=Ticket::genExtRandID();
$sql= 'INSERT INTO '.TICKET_TABLE.' SET created=NOW() '.
',ticketID='.db_input($extId).
',dept_id='.db_input($deptId).
',priority_id='.db_input($priorityId).
',email='.db_input($var['email']).
',name='.db_input(Format::striptags($var['name'])).
',subject='.db_input(Format::striptags($var['subject'])).
',location='.db_input(Format::striptags($var['location'])). // mod080722_new_ticket_field
',phone='.db_input($var['phone']).
',ip_address='.db_input($ipaddress).
',source='.db_input($source);

Bad Behavior has blocked 194 access attempts in the last 7 days.