Newer
Older
<?php
/*********************************************************************
class.ticket.php
The most important class! Don't play with fire please.
Peter Rotich <peter@osticket.com>
Copyright (c) 2006-2012 osTicket
http://www.osticket.com
Released under the GNU General Public License WITHOUT ANY WARRANTY.
See LICENSE.TXT for details.
vim: expandtab sw=4 ts=4 sts=4:
**********************************************************************/
include_once(INCLUDE_DIR.'class.staff.php');
include_once(INCLUDE_DIR.'class.client.php');
include_once(INCLUDE_DIR.'class.team.php');
include_once(INCLUDE_DIR.'class.email.php');
include_once(INCLUDE_DIR.'class.dept.php');
include_once(INCLUDE_DIR.'class.topic.php');
include_once(INCLUDE_DIR.'class.lock.php');
include_once(INCLUDE_DIR.'class.file.php');
include_once(INCLUDE_DIR.'class.attachment.php');
include_once(INCLUDE_DIR.'class.banlist.php');
include_once(INCLUDE_DIR.'class.template.php');
include_once(INCLUDE_DIR.'class.priority.php');
class Ticket{
var $id;
var $extid;
var $email;
var $status;
var $created;
var $reopened;
var $updated;
var $lastrespdate;
var $lastmsgdate;
var $duedate;
var $priority;
var $priority_id;
var $fullname;
var $staff_id;
var $team_id;
var $dept_id;
var $topic_id;
var $dept_name;
var $subject;
var $helptopic;
var $overdue;
var $lastMsgId;
var $dept; //Dept obj
var $sla; // SLA obj
var $staff; //Staff obj
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
var $team; //Team obj
var $topic; //Topic obj
var $tlock; //TicketLock obj
function Ticket($id){
$this->id = 0;
$this->load($id);
}
function load($id=0) {
if(!$id && !($id=$this->getId()))
return false;
//TODO: delete helptopic field in ticket table.
$sql='SELECT ticket.*, topic.topic as helptopic, lock_id, dept_name, priority_desc '
.' ,count(attach.attach_id) as attachments '
.' ,count(DISTINCT message.msg_id) as messages '
.' ,count(DISTINCT response.response_id) as responses '
.' ,count(DISTINCT note.note_id) as notes '
.' FROM '.TICKET_TABLE.' ticket '
.' LEFT JOIN '.DEPT_TABLE.' dept ON (ticket.dept_id=dept.dept_id) '
.' LEFT JOIN '.TICKET_PRIORITY_TABLE.' pri ON (ticket.priority_id=pri.priority_id) '
.' LEFT JOIN '.TOPIC_TABLE.' topic ON (ticket.topic_id=topic.topic_id) '
.' LEFT JOIN '.TICKET_LOCK_TABLE.' tlock ON (ticket.ticket_id=tlock.ticket_id AND tlock.expire>NOW()) '
.' LEFT JOIN '.TICKET_ATTACHMENT_TABLE.' attach ON (ticket.ticket_id=attach.ticket_id) '
.' LEFT JOIN '.TICKET_MESSAGE_TABLE.' message ON (ticket.ticket_id=message.ticket_id) '
.' LEFT JOIN '.TICKET_RESPONSE_TABLE.' response ON (ticket.ticket_id=response.ticket_id) '
.' LEFT JOIN '.TICKET_NOTE_TABLE.' note ON (ticket.ticket_id=note.ticket_id ) '
.' WHERE ticket.ticket_id='.db_input($id)
.' GROUP BY ticket.ticket_id';
//echo $sql;
if(!($res=db_query($sql)) || !db_num_rows($res))
return false;
$this->ht=db_fetch_array($res);
$this->id = $this->ht['ticket_id'];
$this->extid = $this->ht['ticketID'];
$this->email = $this->ht['email'];
$this->fullname = $this->ht['name'];
$this->status = $this->ht['status'];
$this->created = $this->ht['created'];
$this->reopened = $this->ht['reopened'];
$this->updated = $this->ht['updated'];
$this->duedate = $this->ht['duedate'];
$this->closed = $this->ht['closed'];
$this->lastmsgdate = $this->ht['lastmessagedate'];
$this->lastrespdate = $this->ht['lastresponsedate'];
$this->lock_id = $this->ht['lock_id'];
$this->priority_id = $this->ht['priority_id'];
$this->priority = $this->ht['priority_desc'];
$this->staff_id = $this->ht['staff_id'];
$this->team_id = $this->ht['team_id'];
$this->dept_id = $this->ht['dept_id'];
$this->dept_name = $this->ht['dept_name'];
$this->sla_id = $this->ht['sla_id'];
$this->topic_id = $this->ht['topic_id'];
$this->helptopic = $this->ht['helptopic'];
$this->subject = $this->ht['subject'];
$this->overdue = $this->ht['isoverdue'];
//Reset the sub classes (initiated ondemand)...good for reloads.
$this->staff = null;
130
131
132
133
134
135
136
137
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
$this->team = null;
$this->dept = null;
$this->sla = null;
$this->tlock = null;
$this->stats = null;
$this->topic = null;
return true;
}
function reload() {
return $this->load();
}
function isOpen() {
return (strcasecmp($this->getStatus(),'Open')==0);
}
function isReopened() {
return ($this->getReopenDate());
}
function isClosed() {
return (strcasecmp($this->getStatus(),'Closed')==0);
}
function isAssigned() {
return ($this->isOpen() && ($this->getStaffId() || $this->getTeamId()));
}
function isOverdue() {
return ($this->overdue);
}
function isAnswered() {
return ($this->ht['isanswered']);
}
function isLocked() {
return ($this->getLockId());
}
function checkStaffAccess($staff) {
if(!is_object($staff) && !($staff=Staff::lookup($staff)))
return false;
return ((!$staff->showAssignedOnly() && $staff->canAccessDept($this->getDeptId()))
|| ($this->getTeamId() && $staff->isTeamMember($this->getTeamId()))
|| $staff->getId()==$this->getStaffId());
}
function checkClientAccess($client) {
global $cfg;
if(!is_object($client) && !($client=Client::lookup($client)))
return false;
if(!strcasecmp($client->getEmail(),$this->getEmail()))
return true;
return ($cfg && $cfg->showRelatedTickets() && $client->getTicketId()==$ticket->getExtId());
}
//Getters
function getId(){
return $this->id;
}
function getExtId(){
return $this->extid;
Loading
Loading full blame...