diff --git a/include/api.tickets.php b/include/api.tickets.php index daa7ffe431a17d43d39227347f4b3efc0ac8053b..fb12e623c03328eada3e02bfddba0178c39860c9 100644 --- a/include/api.tickets.php +++ b/include/api.tickets.php @@ -97,7 +97,7 @@ class TicketApiController extends ApiController { if(!$ticket) return $this->exerr(500, "Unable to create new ticket: unknown error"); - $this->response(201, $ticket->getExtId()); + $this->response(201, $ticket->getNumber()); } /* private helper functions */ diff --git a/include/class.auth.php b/include/class.auth.php index 14e96e29f9df43aec6fdd88812b421ff50211caf..8746c5b23d21f13f5036497611fbcd7e559cf381 100644 --- a/include/class.auth.php +++ b/include/class.auth.php @@ -634,7 +634,7 @@ class AuthTokenAuthentication extends UserAuthenticationBackend { } // Support old ticket based tokens. elseif ($_GET['t'] && $_GET['e'] && $_GET['a']) { - if (($ticket = Ticket::lookupByExtId($_GET['t'], $_GET['e'])) + if (($ticket = Ticket::lookupByNumber($_GET['t'], $_GET['e'])) // Using old ticket auth code algo - hardcoded here because it // will be removed in ticket class in the upcoming rewrite && !strcasecmp($_GET['a'], md5($ticket->getId() . $_GET['e'] . SECRET_SALT)) diff --git a/include/class.thread.php b/include/class.thread.php index d93f8e289b5f6e3befd4555426a4e0067c4de63e..6fa0d9c13cc74e85dd8e57dce0c4f90411c1166f 100644 --- a/include/class.thread.php +++ b/include/class.thread.php @@ -816,7 +816,7 @@ Class ThreadEntry { && $mailinfo['email'] && preg_match("/#(?:[\p{L}-]+)?([0-9]{1,10})/u", $subject, $match) //Lookup by ticket number - && ($ticket = Ticket::lookupByExtId((int)$match[1])) + && ($ticket = Ticket::lookupByNumber((int)$match[1])) //Lookup the user using the email address && ($user = User::lookup(array('emails__address' => $mailinfo['email'])))) { //We have a valid ticket and user diff --git a/include/class.ticket.php b/include/class.ticket.php index e637743a4fb3b3d91fdef1ab3ed60f04695d0072..5351de08c0c011b21ac582cf2a09224895aa3681 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -188,10 +188,6 @@ class Ticket { return $this->id; } - function getExtId() { - return $this->getNumber(); - } - function getNumber() { return $this->number; } @@ -1820,7 +1816,7 @@ class Ticket { function pdfExport($psize='Letter', $notes=false) { require_once(INCLUDE_DIR.'class.pdf.php'); $pdf = new Ticket2PDF($this, $psize, $notes); - $name='Ticket-'.$this->getExtId().'.pdf'; + $name='Ticket-'.$this->getNumber().'.pdf'; $pdf->Output($name, 'I'); //Remember what the user selected - for autoselect on the next print. $_SESSION['PAPER_SIZE'] = $psize; @@ -1919,15 +1915,15 @@ class Ticket { /*============== Static functions. Use Ticket::function(params); =============nolint*/ - function getIdByExtId($extId, $email=null) { + function getIdByNumber($number, $email=null) { - if(!$extId || !is_numeric($extId)) + if(!$number) return 0; $sql ='SELECT ticket.ticket_id FROM '.TICKET_TABLE.' ticket ' .' LEFT JOIN '.USER_TABLE.' user ON user.id = ticket.user_id' .' LEFT JOIN '.USER_EMAIL_TABLE.' email ON user.id = email.user_id' - .' WHERE ticket.`number`='.db_input($extId); + .' WHERE ticket.`number`='.db_input($number); if($email) $sql .= ' AND email.address = '.db_input($email); @@ -1949,20 +1945,20 @@ class Ticket { ?$ticket:null; } - function lookupByExtId($id, $email=null) { - return self::lookup(self:: getIdByExtId($id, $email)); + function lookupByNumber($number, $email=null) { + return self::lookup(self:: getIdByNumber($number, $email)); } - function genExtRandID() { - global $cfg; + function genRandTicketNumber($len = EXT_TICKET_ID_LEN) { - //We can allow collissions...extId and email must be unique ...so same id with diff emails is ok.. - // But for clarity...we are going to make sure it is unique. - $id=Misc::randNumber(EXT_TICKET_ID_LEN); - if(db_num_rows(db_query('SELECT ticket_id FROM '.TICKET_TABLE.' WHERE `number`='.db_input($id)))) - return Ticket::genExtRandID(); + //We can allow collissions...number and email must be unique ...so + // same number with diff emails is ok.. But for clarity...we are going to make sure it is unique. + $number = Misc::randNumber($len); + if(db_num_rows(db_query('SELECT ticket_id FROM '.TICKET_TABLE.' + WHERE `number`='.db_input($number)))) + return Ticket::genRandTicketNumber($len); - return $id; + return $number; } function getIdByMessageId($mid, $email) { @@ -2249,11 +2245,11 @@ class Ticket { $ipaddress=$vars['ip']?$vars['ip']:$_SERVER['REMOTE_ADDR']; //We are ready son...hold on to the rails. - $extId=Ticket::genExtRandID(); + $number = Ticket::genRandTicketNumber(); $sql='INSERT INTO '.TICKET_TABLE.' SET created=NOW() ' .' ,lastmessage= NOW()' .' ,user_id='.db_input($user->id) - .' ,`number`='.db_input($extId) + .' ,`number`='.db_input($number) .' ,dept_id='.db_input($deptId) .' ,topic_id='.db_input($topicId) .' ,ip_address='.db_input($ipaddress) @@ -2271,8 +2267,8 @@ class Ticket { if(!$cfg->useRandomIds()) { //Sequential ticket number support really..really suck arse. - $extId=$id; //To make things really easy we are going to use autoincrement ticket_id. - db_query('UPDATE '.TICKET_TABLE.' SET `number`='.db_input($extId).' WHERE ticket_id='.$id.' LIMIT 1'); + //To make things really easy we are going to use autoincrement ticket_id. + db_query('UPDATE '.TICKET_TABLE.' SET `number`='.db_input($id).' WHERE ticket_id='.$id.' LIMIT 1'); //TODO: RETHING what happens if this fails?? [At the moment on failure random ID is used...making stuff usable] } diff --git a/include/client/view.inc.php b/include/client/view.inc.php index bcd64b4ae7589582d79b159b205f619248e4ecc1..c36eaec96dd81d06804a5cd44d26fc986a6d2737 100644 --- a/include/client/view.inc.php +++ b/include/client/view.inc.php @@ -124,7 +124,7 @@ if($ticket->getThreadCount() && ($thread=$ticket->getClientThread())) { <?php }elseif($warn) { ?> <div id="msg_warning"><?php echo $warn; ?></div> <?php } ?> -<form id="reply" action="tickets.php?id=<?php echo $ticket->getExtId(); ?>#reply" name="reply" method="post" enctype="multipart/form-data"> +<form id="reply" action="tickets.php?id=<?php echo $ticket->getId(); ?>#reply" name="reply" method="post" enctype="multipart/form-data"> <?php csrf_token(); ?> <h2>Post a Reply</h2> <input type="hidden" name="id" value="<?php echo $ticket->getId(); ?>"> @@ -143,7 +143,7 @@ if($ticket->getThreadCount() && ($thread=$ticket->getClientThread())) { <br/> <textarea name="message" id="message" cols="50" rows="9" wrap="soft" data-draft-namespace="ticket.client" - data-draft-object-id="<?php echo $ticket->getExtId(); ?>" + data-draft-object-id="<?php echo $ticket->getId(); ?>" class="richtext ifhtml draft"><?php echo $info['message']; ?></textarea> </td> </tr> diff --git a/include/staff/ticket-edit.inc.php b/include/staff/ticket-edit.inc.php index cddb2ee3c6b36f248110fb85833cdb87760b9b9a..e60f275c2633c237a51f91eeab1b048bf0abf980 100644 --- a/include/staff/ticket-edit.inc.php +++ b/include/staff/ticket-edit.inc.php @@ -11,7 +11,7 @@ if ($_POST) <input type="hidden" name="do" value="update"> <input type="hidden" name="a" value="edit"> <input type="hidden" name="id" value="<?php echo $ticket->getId(); ?>"> - <h2>Update Ticket #<?php echo $ticket->getExtId(); ?></h2> + <h2>Update Ticket #<?php echo $ticket->getNumber(); ?></h2> <table class="form_table" width="940" border="0" cellspacing="0" cellpadding="2"> <tbody> <tr> diff --git a/include/staff/ticket-view.inc.php b/include/staff/ticket-view.inc.php index edaa2131e42c86643dd73e7a8346a660bb57c7a3..a9b1c8edf41bb9f0169008239dd1b56599d84b05 100644 --- a/include/staff/ticket-view.inc.php +++ b/include/staff/ticket-view.inc.php @@ -41,7 +41,8 @@ if($ticket->isOverdue()) <table width="940" cellpadding="2" cellspacing="0" border="0"> <tr> <td width="50%" class="has_bottom_border"> - <h2><a href="tickets.php?id=<?php echo $ticket->getId(); ?>" title="Reload"><i class="icon-refresh"></i> Ticket #<?php echo $ticket->getExtId(); ?></a></h2> + <h2><a href="tickets.php?id=<?php echo $ticket->getId(); ?>" + title="Reload"><i class="icon-refresh"></i> Ticket #<?php echo $ticket->getNumber(); ?></a></h2> </td> <td width="50%" class="right_align has_bottom_border"> <?php diff --git a/open.php b/open.php index f027bb1bca2851907ede5589051d989cdec8fed9..4cb7684a8167b7cd5a3c07f67d876b83c313cb4d 100644 --- a/open.php +++ b/open.php @@ -53,11 +53,9 @@ if($_POST): } //Logged in...simply view the newly created ticket. if($thisclient && $thisclient->isValid()) { - if(!$cfg->showRelatedTickets()) - $_SESSION['_client']['key']= $ticket->getExtId(); //Resetting login Key to the current ticket! session_write_close(); session_regenerate_id(); - @header('Location: tickets.php?id='.$ticket->getExtId()); + @header('Location: tickets.php?id='.$ticket->getId()); } }else{ $errors['err']=$errors['err']?$errors['err']:'Unable to create a ticket. Please correct errors below and try again!'; diff --git a/scp/tickets.php b/scp/tickets.php index f28ac8e3e31a1677cceede9c867e49e204473b83..dd7dd0cd924aac00bda229407ee13318f120de33 100644 --- a/scp/tickets.php +++ b/scp/tickets.php @@ -222,7 +222,7 @@ if($_POST && !$errors): } elseif($ticket->isClosed()) { $errors['err'] = 'Ticket is already closed!'; } elseif($ticket->close()) { - $msg='Ticket #'.$ticket->getExtId().' status set to CLOSED'; + $msg='Ticket #'.$ticket->getNumber().' status set to CLOSED'; //Log internal note if($_POST['ticket_status_notes']) $note = $_POST['ticket_status_notes']; diff --git a/tickets.php b/tickets.php index 78d185579af45cdd361e9b57b0d8c9ad53c65d2b..7c49a74d34611ff7f7f4b6fd0aeda80c31fcce0f 100644 --- a/tickets.php +++ b/tickets.php @@ -54,7 +54,7 @@ if($_POST && is_object($ticket) && $ticket->getId()): $msg='Message Posted Successfully'; // Cleanup drafts for the ticket. If not closed, only clean // for this staff. Else clean all drafts for the ticket. - Draft::deleteForNamespace('ticket.client.' . $ticket->getExtId()); + Draft::deleteForNamespace('ticket.client.' . $ticket->getId()); } else { $errors['err']='Unable to post the message. Try again'; }