aepnat /
simhelpdesk
| 1 | <?php |
||
| 2 | |||
| 3 | date_default_timezone_set('Asia/Jakarta'); |
||
| 4 | class Tickets |
||
| 5 | { |
||
| 6 | private $db; |
||
| 7 | |||
| 8 | public function __construct($database) |
||
| 9 | { |
||
| 10 | $this->db = $database; |
||
| 11 | } |
||
| 12 | |||
| 13 | public function add_ticket($ticketnumber, $sla, $reporteddate, $reportedby, $telp, $email, $problemsummary, $problemdetail, $ticketstatus, $assignee, $documentedby, $pro) |
||
| 14 | { |
||
| 15 | $current = time(); |
||
| 16 | $querystring = 'INSERT INTO `tickets` (`ticketnumber`,`sla`,`reporteddate`, `reportedby`, `telp`, `email`, `problemsummary`,`problemdetail`,`ticketstatus`,`assignee`,`documentedby`,`documenteddate`,`pro`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; |
||
| 17 | $query = $this->db->prepare($querystring); |
||
| 18 | $query->bindValue(1, $ticketnumber); |
||
| 19 | $query->bindValue(2, $sla); |
||
| 20 | $query->bindValue(3, $reporteddate); |
||
| 21 | $query->bindValue(4, $reportedby); |
||
| 22 | $query->bindValue(5, $telp); |
||
| 23 | $query->bindValue(6, $email); |
||
| 24 | $query->bindValue(7, $problemsummary); |
||
| 25 | $query->bindValue(8, $problemdetail); |
||
| 26 | $query->bindValue(9, $ticketstatus); |
||
| 27 | $query->bindValue(10, $assignee); |
||
| 28 | $query->bindValue(11, $documentedby); |
||
| 29 | $query->bindValue(12, $current); |
||
| 30 | $query->bindValue(13, $pro); |
||
| 31 | |||
| 32 | try { |
||
| 33 | $query->execute(); |
||
| 34 | } catch (PDOException $e) { |
||
| 35 | die($e->getMessage()); |
||
|
0 ignored issues
–
show
|
|||
| 36 | } |
||
| 37 | } |
||
| 38 | |||
| 39 | public function update_ticket($id, $sla, $reporteddate, $reportedby, $telp, $email, $problemsummary, $problemdetail, $ticketstatus, $assignee, $assigneddate, $pendingby, $pendingdate, $resolution, $resolvedby, $resolveddate, $closedby, $closeddate, $processby, $processdate, $comment) |
||
| 40 | { |
||
| 41 | $querystring = 'UPDATE `tickets` SET `sla` = ? , `reporteddate` = ? , `reportedby` = ? , `telp` = ? ,`email` = ? , `problemsummary` = ? , `problemdetail` = ? ,`ticketstatus` = ?, `assignee` = ? , `assigneddate` = ?, `pendingby` = ?,`pendingdate` = ?, `resolution` = ? ,`resolvedby` = ?,`resolveddate` = ?,`closedby` = ?,`closeddate` = ?, `processby` = ?, `processdate` = ?, `comment` = ? WHERE `id` = ?'; |
||
| 42 | $query = $this->db->prepare($querystring); |
||
| 43 | $query->bindValue(1, $sla); |
||
| 44 | $query->bindValue(2, $reporteddate); |
||
| 45 | $query->bindValue(3, $reportedby); |
||
| 46 | $query->bindValue(4, $telp); |
||
| 47 | $query->bindValue(5, $email); |
||
| 48 | $query->bindValue(6, $problemsummary); |
||
| 49 | $query->bindValue(7, $problemdetail); |
||
| 50 | $query->bindValue(8, $ticketstatus); |
||
| 51 | $query->bindValue(9, $assignee); |
||
| 52 | $query->bindValue(10, $assigneddate); |
||
| 53 | $query->bindValue(11, $pendingby); |
||
| 54 | $query->bindValue(12, $pendingdate); |
||
| 55 | $query->bindValue(13, $resolution); |
||
| 56 | $query->bindValue(14, $resolvedby); |
||
| 57 | $query->bindValue(15, $resolveddate); |
||
| 58 | $query->bindValue(16, $closedby); |
||
| 59 | $query->bindValue(17, $closeddate); |
||
| 60 | $query->bindValue(18, $processby); |
||
| 61 | $query->bindValue(19, $processdate); |
||
| 62 | $query->bindValue(20, $comment); |
||
| 63 | $query->bindValue(21, $id); |
||
| 64 | |||
| 65 | try { |
||
| 66 | $query->execute(); |
||
| 67 | } catch (PDOException $e) { |
||
| 68 | die($e->getMessage()); |
||
|
0 ignored issues
–
show
|
|||
| 69 | } |
||
| 70 | } |
||
| 71 | |||
| 72 | public function delete($id) |
||
| 73 | { |
||
| 74 | $sql = 'DELETE FROM `tickets` WHERE `id` = ?'; |
||
| 75 | $query = $this->db->prepare($sql); |
||
| 76 | $query->bindValue(1, $id); |
||
| 77 | |||
| 78 | try { |
||
| 79 | $query->execute(); |
||
| 80 | } catch (PDOException $e) { |
||
| 81 | die($e->getMessage()); |
||
|
0 ignored issues
–
show
|
|||
| 82 | } |
||
| 83 | } |
||
| 84 | |||
| 85 | public function ticket_data($id) |
||
| 86 | { |
||
| 87 | $query = $this->db->prepare('SELECT * FROM `tickets` WHERE `id`= ?'); |
||
| 88 | $query->bindValue(1, $id); |
||
| 89 | |||
| 90 | try { |
||
| 91 | $query->execute(); |
||
| 92 | |||
| 93 | return $query->fetch(); |
||
| 94 | } catch (PDOException $e) { |
||
| 95 | die($e->getMessage()); |
||
|
0 ignored issues
–
show
|
|||
| 96 | } |
||
| 97 | } |
||
| 98 | |||
| 99 | public function get_tickets() |
||
| 100 | { |
||
| 101 | $query = $this->db->prepare('SELECT * FROM `tickets` ORDER BY `ticketnumber` DESC'); |
||
| 102 | |||
| 103 | try { |
||
| 104 | $query->execute(); |
||
| 105 | } catch (PDOException $e) { |
||
| 106 | die($e->getMessage()); |
||
|
0 ignored issues
–
show
|
|||
| 107 | } |
||
| 108 | |||
| 109 | return $query->fetchAll(); |
||
| 110 | } |
||
| 111 | |||
| 112 | public function get_pro() |
||
| 113 | { |
||
| 114 | $query = $this->db->prepare('SELECT pro FROM `tickets`'); |
||
| 115 | |||
| 116 | try { |
||
| 117 | $query->execute(); |
||
| 118 | } catch (PDOException $e) { |
||
| 119 | die($e->getMessage()); |
||
|
0 ignored issues
–
show
|
|||
| 120 | } |
||
| 121 | |||
| 122 | return $query->fetchAll(); |
||
| 123 | } |
||
| 124 | |||
| 125 | public function get_opened_tickets() |
||
| 126 | { |
||
| 127 | $query = $this->db->prepare("SELECT * FROM `tickets` WHERE `ticketstatus` <> 'Closed' ORDER BY `ticketnumber` DESC"); |
||
| 128 | |||
| 129 | try { |
||
| 130 | $query->execute(); |
||
| 131 | } catch (PDOException $e) { |
||
| 132 | die($e->getMessage()); |
||
|
0 ignored issues
–
show
|
|||
| 133 | } |
||
| 134 | |||
| 135 | return $query->fetchAll(); |
||
| 136 | } |
||
| 137 | |||
| 138 | public function get_tickets_by_requester($userid) |
||
| 139 | { |
||
| 140 | $query = $this->db->prepare('SELECT * FROM `tickets` WHERE `documentedby`= ? ORDER BY `ticketnumber` DESC'); |
||
| 141 | $query->bindValue(1, $userid); |
||
| 142 | |||
| 143 | try { |
||
| 144 | $query->execute(); |
||
| 145 | } catch (PDOException $e) { |
||
| 146 | die($e->getMessage()); |
||
|
0 ignored issues
–
show
|
|||
| 147 | } |
||
| 148 | |||
| 149 | return $query->fetchAll(); |
||
| 150 | } |
||
| 151 | |||
| 152 | public function get_tickets_by_assignee($userid) |
||
| 153 | { |
||
| 154 | $query = $this->db->prepare('SELECT * FROM `tickets` WHERE `assignee`= ? ORDER BY `ticketnumber` DESC'); |
||
| 155 | $query->bindValue(1, $userid); |
||
| 156 | |||
| 157 | try { |
||
| 158 | $query->execute(); |
||
| 159 | } catch (PDOException $e) { |
||
| 160 | die($e->getMessage()); |
||
|
0 ignored issues
–
show
|
|||
| 161 | } |
||
| 162 | |||
| 163 | return $query->fetchAll(); |
||
| 164 | } |
||
| 165 | |||
| 166 | public function get_tickets_by_resolver($username) |
||
| 167 | { |
||
| 168 | $query = $this->db->prepare('SELECT * FROM `tickets` WHERE `resolvedby`= ? ORDER BY `ticketnumber` DESC'); |
||
| 169 | $query->bindValue(1, $username); |
||
| 170 | |||
| 171 | try { |
||
| 172 | $query->execute(); |
||
| 173 | } catch (PDOException $e) { |
||
| 174 | die($e->getMessage()); |
||
|
0 ignored issues
–
show
|
|||
| 175 | } |
||
| 176 | |||
| 177 | return $query->fetchAll(); |
||
| 178 | } |
||
| 179 | |||
| 180 | public function get_tickets_by_resolver_not_closed($username) |
||
| 181 | { |
||
| 182 | $query = $this->db->prepare('SELECT * FROM `tickets` WHERE `resolvedby`=? and `ticketstatus` <> ? ORDER BY `ticketnumber` DESC'); |
||
| 183 | $query->bindValue(1, $username); |
||
| 184 | $query->bindValue(2, 'Closed'); |
||
| 185 | |||
| 186 | try { |
||
| 187 | $query->execute(); |
||
| 188 | } catch (PDOException $e) { |
||
| 189 | die($e->getMessage()); |
||
|
0 ignored issues
–
show
|
|||
| 190 | } |
||
| 191 | |||
| 192 | return $query->fetchAll(); |
||
| 193 | } |
||
| 194 | |||
| 195 | public function get_tickets_by_status($ticketstatus) |
||
| 196 | { |
||
| 197 | $query = $this->db->prepare('SELECT * FROM `tickets` WHERE `ticketstatus`=? ORDER BY `ticketnumber` DESC'); |
||
| 198 | $query->bindValue(1, $ticketstatus); |
||
| 199 | |||
| 200 | try { |
||
| 201 | $query->execute(); |
||
| 202 | } catch (PDOException $e) { |
||
| 203 | die($e->getMessage()); |
||
|
0 ignored issues
–
show
|
|||
| 204 | } |
||
| 205 | |||
| 206 | return $query->fetchAll(); |
||
| 207 | } |
||
| 208 | |||
| 209 | public function get_tickets_by_date($start_date, $end_date) |
||
| 210 | { |
||
| 211 | $start_date = strtotime($start_date); |
||
| 212 | $end_date = strtotime($end_date); |
||
| 213 | $query = $this->db->prepare('SELECT * FROM `tickets` WHERE `documenteddate` >= ? AND `documenteddate` <= ? ORDER BY `ticketnumber` DESC'); |
||
| 214 | $query->bindValue(1, $start_date); |
||
| 215 | $query->bindValue(2, $end_date); |
||
| 216 | |||
| 217 | try { |
||
| 218 | $query->execute(); |
||
| 219 | } catch (PDOException $e) { |
||
| 220 | die($e->getMessage()); |
||
|
0 ignored issues
–
show
|
|||
| 221 | } |
||
| 222 | |||
| 223 | return $query->fetchAll(); |
||
| 224 | } |
||
| 225 | |||
| 226 | public function search_closed_ticket($fromperiod, $toperiod) |
||
| 227 | { |
||
| 228 | $query = $this->db->prepare("SELECT * FROM `tickets` WHERE `documenteddate` >= ? AND `documenteddate` <= ? AND `ticketstatus` = 'Closed' ORDER BY `documenteddate` DESC"); |
||
| 229 | $query->bindValue(1, $fromperiod); |
||
| 230 | $query->bindValue(2, $toperiod); |
||
| 231 | |||
| 232 | try { |
||
| 233 | $query->execute(); |
||
| 234 | } catch (PDOException $e) { |
||
| 235 | die($e->getMessage()); |
||
|
0 ignored issues
–
show
|
|||
| 236 | } |
||
| 237 | |||
| 238 | return $query->fetchAll(); |
||
| 239 | } |
||
| 240 | |||
| 241 | public function count_tickets_by_status() |
||
| 242 | { |
||
| 243 | $query = $this->db->prepare('SELECT ticketstatus, count(*) as total FROM `tickets` GROUP BY ticketstatus'); |
||
| 244 | |||
| 245 | try { |
||
| 246 | $query->execute(); |
||
| 247 | } catch (PDOException $e) { |
||
| 248 | die($e->getMessage()); |
||
|
0 ignored issues
–
show
|
|||
| 249 | } |
||
| 250 | |||
| 251 | return $query->fetchAll(); |
||
| 252 | } |
||
| 253 | |||
| 254 | public function count_resolved_tickets_by_month() |
||
| 255 | { |
||
| 256 | $sql = "SELECT Month(FROM_UNIXTIME(`documenteddate`)) as Bulan, Count(*) as Total FROM `tickets` WHERE (`ticketstatus`='Resolved' OR `ticketstatus`='Closed') AND FROM_UNIXTIME(`documenteddate`) >= CURDATE() - INTERVAL 1 YEAR GROUP BY Month(FROM_UNIXTIME(`documenteddate`))"; |
||
| 257 | $query = $this->db->prepare($sql); |
||
| 258 | |||
| 259 | try { |
||
| 260 | $query->execute(); |
||
| 261 | } catch (PDOException $e) { |
||
| 262 | die($e->getMessage()); |
||
|
0 ignored issues
–
show
|
|||
| 263 | } |
||
| 264 | |||
| 265 | return $query->fetchAll(); |
||
| 266 | } |
||
| 267 | |||
| 268 | public function count_inprogress_tickets_by_month() |
||
| 269 | { |
||
| 270 | $sql = "SELECT Month(FROM_UNIXTIME(`documenteddate`)) as Bulan, Count(*) as Total FROM `tickets` WHERE (`ticketstatus`='Assigned' OR `ticketstatus`='Pending') AND FROM_UNIXTIME(`documenteddate`) >= CURDATE() - INTERVAL 1 YEAR GROUP BY Month(FROM_UNIXTIME(`documenteddate`))"; |
||
| 271 | $query = $this->db->prepare($sql); |
||
| 272 | |||
| 273 | try { |
||
| 274 | $query->execute(); |
||
| 275 | } catch (PDOException $e) { |
||
| 276 | die($e->getMessage()); |
||
|
0 ignored issues
–
show
|
|||
| 277 | } |
||
| 278 | |||
| 279 | return $query->fetchAll(); |
||
| 280 | } |
||
| 281 | |||
| 282 | public function get_last_ticket() |
||
| 283 | { |
||
| 284 | $query = $this->db->prepare('SELECT * FROM `tickets` ORDER BY id DESC LIMIT 1'); |
||
| 285 | |||
| 286 | try { |
||
| 287 | $query->execute(); |
||
| 288 | |||
| 289 | return $query->fetch(); |
||
| 290 | } catch (PDOException $e) { |
||
| 291 | die($e->getMessage()); |
||
|
0 ignored issues
–
show
|
|||
| 292 | } |
||
| 293 | } |
||
| 294 | |||
| 295 | /* |
||
| 296 | public function notify_assignee($id,$ticketnumber,$email_assignee) |
||
| 297 | { if (substr(php_uname(), 0, 7) == "Windows"){ |
||
| 298 | $cmd = "D:\mowes_portable\www\helpdesk\batch\sendemail.bat"; |
||
| 299 | $WshShell = new COM("WScript.Shell"); |
||
| 300 | $oExec = $WshShell->Run("cmd /C $cmd", 0, false); |
||
| 301 | return $oExec == 0 ? true : false; |
||
| 302 | } |
||
| 303 | else { |
||
| 304 | $cmd = "php /batch/sendemail.bat"; |
||
| 305 | exec($cmd . " > /dev/null &"); |
||
| 306 | } |
||
| 307 | }*/ |
||
| 308 | |||
| 309 | public function log_tickets($id, $sla, $reporteddate, $reportedby, $telp, $email, $problemsummary, $problemdetail, $ticketstatus, $assignee, $assigneddate, $pendingby, $pendingdate, $resolution, $resolvedby, $resolveddate, $closedby, $closeddate, $changes, $changeby, $processby, $processdate, $comment) |
||
| 310 | { |
||
| 311 | $changedate = time(); |
||
| 312 | $querystring = 'INSERT INTO `log_tickets` (`id`,`sla`,`reporteddate`, `reportedby`, `telp`, `email`, `problemsummary`,`problemdetail`,`ticketstatus`,`assignee`,`assigneddate`,`pendingby`,`pendingdate`,`resolution`,`resolvedby`,`resolveddate`,`closedby`,`closeddate`,`changes`,`changeby`,`changedate`,`processby`,`processdate`,`comment`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; |
||
| 313 | $query = $this->db->prepare($querystring); |
||
| 314 | $query->bindValue(1, $id); |
||
| 315 | $query->bindValue(2, $sla); |
||
| 316 | $query->bindValue(3, $reporteddate); |
||
| 317 | $query->bindValue(4, $reportedby); |
||
| 318 | $query->bindValue(5, $telp); |
||
| 319 | $query->bindValue(6, $email); |
||
| 320 | $query->bindValue(7, $problemsummary); |
||
| 321 | $query->bindValue(8, $problemdetail); |
||
| 322 | $query->bindValue(9, $ticketstatus); |
||
| 323 | $query->bindValue(10, $assignee); |
||
| 324 | $query->bindValue(11, $assigneddate); |
||
| 325 | $query->bindValue(12, $pendingby); |
||
| 326 | $query->bindValue(13, $pendingdate); |
||
| 327 | $query->bindValue(14, $resolution); |
||
| 328 | $query->bindValue(15, $resolvedby); |
||
| 329 | $query->bindValue(16, $resolveddate); |
||
| 330 | $query->bindValue(17, $closedby); |
||
| 331 | $query->bindValue(18, $closeddate); |
||
| 332 | $query->bindValue(19, $changes); |
||
| 333 | $query->bindValue(20, $changeby); |
||
| 334 | $query->bindValue(21, $changedate); |
||
| 335 | $query->bindValue(22, $processby); |
||
| 336 | $query->bindValue(23, $processdate); |
||
| 337 | $query->bindValue(24, $comment); |
||
| 338 | |||
| 339 | try { |
||
| 340 | $query->execute(); |
||
| 341 | } catch (PDOException $e) { |
||
| 342 | die($e->getMessage()); |
||
|
0 ignored issues
–
show
|
|||
| 343 | } |
||
| 344 | } |
||
| 345 | |||
| 346 | public function get_audit_trail($id) |
||
| 347 | { |
||
| 348 | $query = $this->db->prepare('SELECT * FROM `log_tickets` WHERE `id`= ? ORDER BY `changedate` DESC'); |
||
| 349 | $query->bindValue(1, $id); |
||
| 350 | |||
| 351 | try { |
||
| 352 | $query->execute(); |
||
| 353 | } catch (PDOException $e) { |
||
| 354 | die($e->getMessage()); |
||
|
0 ignored issues
–
show
|
|||
| 355 | } |
||
| 356 | |||
| 357 | return $query->fetchAll(); |
||
| 358 | } |
||
| 359 | } |
||
| 360 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.