This is based off of
masino_sinaga mod for 1.6rc5
http://www.openscriptsolution.com/ticket-system/osticket/adding-merge-ticket-feature-into-osticket-v1-6-rc5(http://www.openscriptsolution.com/ticket-system/osticket/adding-merge-ticket-feature-into-osticket-v1-6-rc5)
files involved:
\scp\tickets.php
\include\class.ticket.php
\include\staff\ticket-view.inc.php
It's not pretty for 1.7 but it does work; also tosses a DB error if anyone can figure out how to make it stop tossing that error and to make it look prettier you're more than welcome.
I've left the original code code intact and just added // in the event it's useful but I didn't see a need for it.
\scp\tickets.php
After this section of code
} elseif(!$errors) {
$errors = 'Unable to complete the ticket transfer';
$errors='Correct the error(s) below and try again!';
}
}
break;
Add this:
case 'mergeticket':
if( $ticket->mergeTicket($_POST,
$_POST,
$_POST,
$_POST )){
$title='Merged Tickets';
$msg='Ticket Has Been Sucessfully Merged.';
}else{
$errors=$errors?$errors:'Unable to merge tickets or the ticket has been closed.';
}
break;
\include\class.ticket.php
After this section of code
//Insert Internal Notes
function logNote($title, $note, $poster='SYSTEM', $alert=true) {
$errors = array();
return $this->postNote(
array('title' => $title, 'note' => $note),
$errors,
$poster,
$alert);
}
Add this:
//merge this ticket to another ticket
function mergeTicket($keepticket,$notifycustomer,$email,$status) {
global $cfg;
global $thisstaff;
// update these tables...:
// ost_ticket_attachment
$sql1= 'UPDATE '.TICKET_ATTACHMENT_TABLE.' SET '.
' ticket_id='.db_input(Format:($keepticket)).
' WHERE '.
'ticket_id='.db_input($this->getId());
// ost_ticket_message
$sql2= 'UPDATE '.TICKET_THREAD_TABLE.' SET '.
' ticket_id='.db_input(Format:($keepticket)).
' WHERE '.
'ticket_id='.db_input($this->getId());
// ost_ticket_note
//$sql3= 'UPDATE '.TICKET_NOTE_TABLE.' SET '.
// ' ticket_id='.db_input(Format:($keepticket)).
// ' WHERE '.
// 'ticket_id='.db_input($this->getId());
// ost_ticket_response
//$sql4= 'UPDATE '.TICKET_RESPONSE_TABLE.' SET '.
// ' ticket_id='.db_input(Format:($keepticket)).
// ' WHERE '.
// 'ticket_id='.db_input($this->getId());
// create message on this ticket about merge (ost_ticket_message)
$sql5= 'INSERT INTO '.TICKET_THREAD_TABLE.' SET '.
' ticket_id='.db_input($this->getId()).
', source="Web"'.
', created=NOW()'.
', body=CONCAT("Merged with ticket ",'.
' ( SELECT ticketID FROM '.TICKET_TABLE.' WHERE ticket_id='.db_input(Format:($keepticket)).' ))'.
';';
// close and unassign this ticket (ost_ticket)
$sql6 = 'UPDATE '.TICKET_TABLE.' SET '.
' staff_id = 0'.
', status = "closed"'.
', updated=NOW()'.
', closed=NOW()'.
' WHERE '.
'ticket_id='.db_input($this->getId());
if((db_query($sql1)) && (db_query($sql2)) &&
//(db_query($sql3)) && (db_query($sql4)) &&
(db_query($sql6)) ){
if ( db_query($sql5) && $msgid=db_insert_id() ); { //&& $msgid=db_insert_id($res5)
$sql7= 'INSERT INTO '.TICKET_THREAD_TABLE.' SET '.
//' id='.db_input($msgid).
' ticket_id='.db_input($this->getId()).
', staff_id='.db_input($thisstaff->getId()).
', poster='.db_input($thisstaff->getName()).
', ip_address=""'.
', created=NOW()'.
', body=CONCAT("Ticket closed for merging reason ",'.
' ( SELECT ticketID FROM '.TICKET_TABLE.' WHERE ticket_id='.db_input(Format:($keepticket)).' ))'.
';';
db_query($sql7);
$sqlt = 'SELECT ticketID FROM '.TICKET_TABLE.' WHERE ticket_id='.db_input(Format:($keepticket));
$rest=db_query($sqlt);
if($rest && db_num_rows($rest))
list($ticketID)=db_fetch_row($rest);
$sqlm = 'SELECT id FROM '.TICKET_THREAD_TABLE.' m, '.TICKET_TABLE.' t
WHERE t.ticketID='.$ticketID.' AND m.ticket_id=t.ticket_id ORDER BY id ASC LIMIT 1';
$resm=db_query($sqlm);
if($resm && db_num_rows($resm))
list($msgid)=db_fetch_row($resm);
$sql8= 'INSERT INTO '.TICKET_THREAD_TABLE.' SET '.
//' id='.db_input($msgid).
' ticket_id='.db_input(Format:($keepticket)).
', staff_id='.db_input($thisstaff->getId()).
', poster='.db_input($thisstaff->getName()).
', ip_address=""'.
', created=NOW()'.
', body=CONCAT("Ticket merged from ticket ",'.$this->getExtId().')';
db_query($sql8);
}
if ($notifycustomer && ($status!='closed')) {
$helpdesk_email=$cfg->getDefaultEmail();
$helpdesk_email->send($email,
'Merging Ticket #'.$this->getExtId().' to Ticket #'.$ticketID,
'Your ticket #'.$this->getExtId().' has been merged to ticket #'.$ticketID.'.');
}
return true;
} else {
return false;
}
}
\include\staff\ticket-view.inc.php
After this section of code:
if($thisstaff->canBanEmails()) {
if(!$emailBanned) {?>
<li><a id="ticket-banemail" href="#banemail"><i class="icon-ban-circle"></i> Ban Email (<?php echo $ticket->getEmail(); ?>)</a></li>
<?php
} elseif($unbannable) { ?>
<li><a id="ticket-banemail" href="#unbanemail"><i class="icon-undo"></i> Unban Email (<?php echo $ticket->getEmail(); ?>)</a></li>
<?php
}
}?>
</ul>
</div>
</td>
</tr>
</table>
Add This:
<table class="mergetickets" cellspacing="0" cellpadding="0" width="940" border="0">
<tr>
<td width="50">
<table border="0" cellspacing="" cellpadding="4" width="100%">
<tr>
<th width="100">Merge Ticket?:</th>
<?
$sql = 'SELECT ticket_id, concat(ticketid,": ",subject) AS label FROM '.TICKET_TABLE.' WHERE email='.
'(SELECT email FROM ost_ticket WHERE ticket_id = '.$id.') AND status '.
'= "open" AND ticket_id <> '.$id.' ORDER BY `created` DESC ';
$lookuptickets = db_query($sql);
if (db_num_rows($lookuptickets)) {
?>
<p>
<form action="tickets.php?id=<?=$id?>#mergeticket" name="notes" method="post" enctype="multipart/form-data">
<?php csrf_token(); ?>
<input type="hidden" name="ticket_id" value="<?=$id?>">
<input type="hidden" name="a" value="mergeticket">
<input type="hidden" name="email" value="<?php echo $ticket->getEmail(); ?>">
<input type="hidden" name="status" value="<?php echo $ticket->getStatus(); ?>">
Merge this current ticket into ticket # <select id="keepticket" name="keepticket">
<?php
while (list($ticket_id,$label) = db_fetch_row($lookuptickets)){
?>
<option value="<?=$ticket_id?>"><?=$label?></option>
<?
}?>
</select>
<div><input type="checkbox" value="1" name="notifycustomer" />Send Email to Customer inform the Ticket Merging</div>
<div style="margin-left: 50px; margin-top: 5px; margin-bottom: 10px;border: 0px;" align="left">
<input class="button" type='submit' value='Merge Ticket'/>
<input class="button" type='reset' value='Reset' />
<input class="button" type='button' value='Cancel' onClick="history.go(-1)" />
</div>
<?php } else {
echo "Sorry, this ticket cannot be merged into another since there is no ticket has the same email address with this.";
}
?>
</p>
</form>
</p>
</div>
</tr>
<tr>
</tr>
</table>