3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class Ticket { protected $db; protected $setting; public $tickets; public $anwsers; function __construct($db,$setting) { $this->db = $db; $this->setting = $setting; } public function checkTicket($ref, $email) { if($result = $this->db->query("SELECT id FROM verk_tick_tickets WHERE ref='".$this->db->real_escape_string($ref)."' AND email='".$this->db->real_escape_string($email)."'")) { if($result->num_rows == 1) { return true; } else { return false; } $result->free(); } else { return false; } } public function getTicketID($ref, $email) { if($result = $this->db->query("SELECT id FROM verk_tick_tickets WHERE ref='".$this->db->real_escape_string($ref)."' AND email='".$this->db->real_escape_string($email)."'")) { if($result->num_rows == 1) { $resp = $result->fetch_array(); return $resp['id']; } else { return false; } $result->free(); } else { return false; } } public function getTicketVar($id,$var) { if($result = $this->db->query("SELECT ".$this->db->real_escape_string($var)." FROM verk_tick_tickets WHERE id='".$this->db->real_escape_string($id)."'")) { if($result->num_rows == 1) { $resp = $result->fetch_array(); return $resp[$var]; } else { return false; } $result->free(); } else { return false; } } public function getTicket($ref,$email) { if($result = $this->db->query("SELECT * FROM verk_tick_tickets WHERE ref='".$this->db->real_escape_string($ref)."' AND email='".$this->db->real_escape_string($email)."'")) { if($result->num_rows == 1) { return $result->fetch_array(); } else { return false; } $result->free(); } else { return false; } } public function getOpenTickets() { if($result = $this->db->query("SELECT * FROM verk_tick_tickets WHERE status='open' OR status='client' OR status='admin'")) { if($result->num_rows > 0) { $return = array(); while($row = $result->fetch_assoc()) { $return[] = $row; } $this->tickets = $return; return true; } else { return false; } $result->free(); } else { return false; } } public function searchTickets($search) { if($result = $this->db->query("SELECT * FROM verk_tick_tickets WHERE ref LIKE '%".$this->db->real_escape_string($search)."%' OR name LIKE '%".$this->db->real_escape_string($search)."%' OR email LIKE '%".$this->db->real_escape_string($search)."%' OR subject LIKE '%".$this->db->real_escape_string($search)."%'")) { if($result->num_rows > 0) { $return = array(); while($a = $result->fetch_assoc()) { $return[] = $a; } $this->tickets = $return; return $result->num_rows; } else { return 0; } $result->free(); } else { return 0; } } public function getTicketAnwsers($ref,$email) { if($this->checkTicket($ref,$email)) { $id = $this->getTicketID($ref,$email); if($result = $this->db->query("SELECT * FROM verk_tick_tickets_anwsers WHERE ticket_id='".$this->db->real_escape_string($id)."'")) { if($result->num_rows > 0) { $return = array(); while($row = $result->fetch_assoc()) { $return[] = $row; } $this->anwsers = $return; return true; } else { return '<div class="alert alert-info">Nog geen berichten...</div>'; } $result->free(); } else { return 'Database error: ('.$this->db->errno.') '.$this->db->error; } } else { return '<div class="alert alert-error">Geen ticket gevonden!</div>'; } } public function closeTicket($ref,$email) { if($result = $this->db->query("SELECT * FROM verk_tick_tickets WHERE ref='".$this->db->real_escape_string($ref)."' AND email='".$this->db->real_escape_string($email)."'")) { if($result->num_rows == 1) { if($this->db->query("UPDATE verk_tick_tickets SET status='closed' WHERE ref='".$this->db->real_escape_string($ref)."' AND email='".$this->db->real_escape_string($email)."'")) { return true; } else { return 'Database error: ('.$this->db->errno.') '.$this->db->error; } } else { return 'Ticket error: Geent ticket gevonden.'; } $result->free(); } else { return 'Database error: ('.$this->db->errno.') '.$this->db->error; } } public function createTicket($sex,$name,$email,$subject,$message) { if(strlen($subject) == 0) { $subject = '(Geen onderwerp)'; } $ref = random(4).'-'.random(4).'-'.random(3); if($this->db->query("INSERT INTO verk_tick_tickets (ref,sex,name,email,subject,message,ip,time,updated) VALUES ( '".$this->db->real_escape_string($ref)."', '".$this->db->real_escape_string($sex)."', '".$this->db->real_escape_string($name)."', '".$this->db->real_escape_string($email)."', '".$this->db->real_escape_string($subject)."', '".$this->db->real_escape_string($message)."', '".$this->db->real_escape_string($_SERVER['REMOTE_ADDR'])."', '".$this->db->real_escape_string(time())."', '".$this->db->real_escape_string(time())."' )")) { $replaceVars = array( '{%REF%}' => htmlentities($ref,ENT_QUOTES,'UTF-8'), '{%NAME%}' => htmlentities($name,ENT_QUOTES,'UTF-8'), '{%EMAIL%}' => htmlentities($email,ENT_QUOTES,'UTF-8'), '{%SUBJECT%}' => htmlentities($subject,ENT_QUOTES,'UTF-8'), '{%TICKET_URL%}' => $this->setting['url'].'view-ticket?email='.$email.'&ref='.$ref, '{%TICKET_ADMIN_URL%}' => $this->setting['url'].'ticket-admin/view-ticket?email='.$email.'&ref='.$ref, '{%MESSAGE%}' => nl2br(htmlentities($message,ENT_QUOTES,'UTF-8')) ); if(emailX($name, $email, '[#'.$ref.'] '.$subject.' - '.$this->setting['name'], replaceVars(nl2br($this->setting['new_ticket_email']), $replaceVars)) && emailX($this->setting['name'], $this->setting['notification_email'], '[#'.$ref.'] '.$subject.' - '.$this->setting['name'], replaceVars(nl2br($this->setting['new_ticket_admin_email']), $replaceVars))) { return 'OK|'.$ref.'|'.$subject; } else { return 'ERROR|Er kon geen e-mail verstuurd worden.'; } } else { return 'ERROR|Database error: ('.$this->db->errno.') '.$this->db->error; } } public function addAnwser($ticket_id,$message,$admin_id=0) { if($result = $this->db->query("SELECT name,email,ref,subject FROM verk_tick_tickets WHERE id='".$this->db->real_escape_string($ticket_id)."' AND status <> 'closed'")) { if($result->num_rows == 1) { $ticket = $result->fetch_array(); if($admin_id == 0) { $status = 'admin'; } else { $status = 'client'; } if($this->db->query("INSERT INTO verk_tick_tickets_anwsers (ticket_id,admin_id,message,time,ip) VALUES ( '".$this->db->real_escape_string($ticket_id)."', '".$this->db->real_escape_string($admin_id)."', '".$this->db->real_escape_string($message)."', '".$this->db->real_escape_string(time())."', '".$this->db->real_escape_string($_SERVER['REMOTE_ADDR'])."' )")) { if($this->db->query("UPDATE verk_tick_tickets SET status='".$this->db->real_escape_string($status)."',updated='".$this->db->real_escape_string(time())."' WHERE id='".$this->db->real_escape_string($ticket_id)."'")) { if($admin_id == 0) { emailX($this->setting['name'], $this->setting['notification_email'], 'RE: [#'.$ticket['ref'].'] '.$ticket['subject'].' - '.$this->setting['name'], 'Antwoord hierop toegevoegd!'); } else { emailX($ticket['name'], $ticket['email'], 'RE: [#'.$ticket['ref'].'] '.$ticket['subject'].' - '.$this->setting['name'], 'Antwoord hierop toegevoegd!'); } return 'OK'; } else { return 'ERROR|Database error: ('.$this->db->errno.') '.$this->db->error; } } else { return 'ERROR|Database error: ('.$this->db->errno.') '.$this->db->error; } } else { return 'ERROR|Geen ticket gevonden of ticket is al gesloten'; } $result->free(); } else { return 'ERROR|Database error: ('.$this->db->errno.') '.$this->db->error; } } public function getStatusHTML($status) { switch($status) { case 'open': return '<div class="label label-success">Open</div>'; break; case 'admin': return '<div class="label label-warning">Wachtend op antwoord van support</div>'; break; case 'client': return '<div class="label label-warning">Wachtend op antwoord van client</div>'; break; case 'closed': return '<div class="label label-important">Gesloten</div>'; break; default: return '<div class="label">Onbekend</div>'; } } public function getStatusSex($sex) { switch($sex) { case 1: return 'Man'; break; case 2: return 'Vrouw'; break; case 3: return 'Bedrijf / Organisatie'; break; default: return 'Onbekend'; } } } ?>
Output for 5.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0