In the header section - Delete action to unlink tickets
<?php
// Delete-Action before the rest of the page is loaded
if (isset($_POST['link_ticket_id']) && hesk_token_check('POST')) {
$linked_tickets = explode(",", $ticket['linkedids']);
$link_ticket_id = $_POST['link_ticket_id'];
// Check if posted ID is the ID of this ticket itself
if ($link_ticket_id == $ticket['id']) {
//Message: Ticket is this ticket itself
hesk_process_messages("Angegeben Ticket-ID ist dieses Ticket selbst.",$_SERVER['PHP_SELF']);
}
// Check if posted ID is allready linked
elseif (!in_array($link_ticket_id, $linked_tickets)) {
$res_linking_ticket1 = hesk_dbQuery("SELECT * FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."tickets` WHERE `id`='".intval($link_ticket_id)."'");
// Check if posted ID exists
if (hesk_dbNumRows($res_linking_ticket1) != 1) {
// Message: Ticket-ID does not exists:
hesk_process_messages("Angegebene Ticket-ID " . $link_ticket_id . " existiert nicht.",$_SERVER['PHP_SELF']);
}
else {
// Ticket exists so linkedids-field must be altered:
$linking_ticket1 = hesk_dbFetchAssoc($res_linking_ticket1);
$custom_field_links1 = $linking_ticket1['linkedids'].$ticket['id'].',';
$res_linking_ticket1 = hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."tickets` SET `linkedids`='".$custom_field_links1."' WHERE `id`='".intval($link_ticket_id)."'");
// Writing posted ID to the Ticket
$res_linking_ticket2 = hesk_dbQuery("SELECT * FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."tickets` WHERE `id`='".intval($ticket['id'])."'");
$linking_ticket2 = hesk_dbFetchAssoc($res_linking_ticket2);
$custom_field_links2 = $linking_ticket2['linkedids'].$link_ticket_id.',';
$res_linking_ticket2 = hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."tickets` SET `linkedids`='".$custom_field_links2."' WHERE `id`='".intval($ticket['id'])."'");
array_push($linked_tickets, $link_ticket_id);
// Message: Ticket was linked:
hesk_process_messages("Ticket " . $link_ticket_id . " wurde verknüpft.",$_SERVER['PHP_SELF'],'SUCCESS');
}
}
// Ticket iss allready linked:
else {
// Message: Ticket allready linked
hesk_process_messages("Tickets sind bereits verknüpft.",$_SERVER['PHP_SELF']);
}
}
if (isset($_GET['del_link']) && hesk_token_check('POST') && $can_delete) {
// Linking should be deleted.
$del_link = $_GET['del_link'];
$res_del_from_linked_ticket = hesk_dbQuery("SELECT * FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."tickets` WHERE `id`='".intval($del_link)."'");
$del_from_linked_ticket = hesk_dbFetchAssoc($res_del_from_linked_ticket);
// Ticket-ID will be deleted in the linked Ticket, also the automaticly inserted ','
$del_string_from_linked_ticket = str_replace($ticket['id'].',', "", $del_from_linked_ticket['linkedids']);
$res_del_from_linked_ticket = hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."tickets` SET `linkedids`='".$del_string_from_linked_ticket."' WHERE `id`='".intval($del_link)."'");
// Ticket-Link will be deleted:
$res_del_linked_ticket = hesk_dbQuery("SELECT * FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."tickets` WHERE `id`='".intval($ticket['id'])."'");
$del_linked_ticket = hesk_dbFetchAssoc($res_del_linked_ticket);
$del_string_linked_ticket = str_replace($del_link.',', "", $del_linked_ticket['linkedids']);
$res_del_linked_ticket = hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."tickets` SET `linkedids`='".$del_string_linked_ticket."' WHERE `id`='".intval($ticket['id'])."'");
//Message: Ticket has been deleted:
hesk_process_messages("Ticket-Verlink wurde gelöscht.",$_SERVER['PHP_SELF'],'SUCCESS');
exit();
}
?>
<section class="params--block ticketlinks accordion">
<h4 class="accordion-title">
<span>Linked Tickets</span>
<svg class="icon icon-chevron-down">
<use xlink:href="<?php echo HESK_PATH; ?>img/sprite.svg#icon-chevron-down"></use>
</svg>
</h4>
<div class="accordion-body">
<?php
// $ticket['linkedids']; --> new table-column linkedids in the table tickets
// here all linked tickets are seperated with a ",". So to explode in an array:
$linked_tickets = explode(",", $ticket['linkedids']);
// Checking if there are any tickets linked to be displayed
if ($ticket['linkedids'] != "" OR $link_ticket_id != "") {
foreach ($linked_tickets as $seperated_linked_tickets) {
// Checking if the link was deleted recently, so it should not be displayed anymore
if (isset($del_link) && $del_link == $seperated_linked_tickets) {
// span: Link to display was deleted
echo '
<div class="row">
<span>Verlinkung zu '.$del_link.' entfernt<span>
</div>';
}
// Display all linked tickets and the Option to delete
else {
$res_linked_ticket = hesk_dbQuery("SELECT * FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."tickets` WHERE `id`='".intval($seperated_linked_tickets)."'");
$linked_ticket = hesk_dbFetchAssoc($res_linked_ticket);
$linked_ticket_trackid = $linked_ticket['trackid'];
$linked_ticket_subject = $linked_ticket['subject'];
if ($linked_ticket_trackid != "") {
echo '
<div class="row">
<div style="width: 100%; height: 25px; overflow: hidden;">';
// The option to delete linked tickets is only displayed for those how can delete tickets or have admin-rights
if ($can_delete) {
// warning: Should the link be deleted?
$warnung = "Soll die Verlinkung wirklich entfernt werden?";
echo '<div style="width:16px; float:right;">
<a class="tooltip" href="admin_ticket.php?track='.$trackingID.'&Refresh='.mt_rand(10000,99999).'&del_link='.$seperated_linked_tickets.'&token='.hesk_token_echo(0).'" onclick="return hesk_confirmExecute(\''.hesk_makeJsString($warnung).'\');" title="Verknüpfung entfernen.">
<svg class="icon icon-delete">
<use xlink:href="'.HESK_PATH.'img/sprite.svg#icon-delete"></use>
</svg>
</a>
</div>';
}
// Checking if the user has the right to see the linked ticket, if not there won't be a link provided
if (hesk_okCategory($linked_ticket['category'], 0)) {
echo '<a href="?track='.$linked_ticket_trackid.'" class="tooltip" title="$hesklang['subject']: '.$linked_ticket_subject.'">'.$seperated_linked_tickets.' '.$linked_ticket_subject.'</a>';
}
else {
// title: no right to see this ticket
echo '<span class="tooltip" title="Keine Berechtigung zur Einsicht von</br>$hesklang['subject']: '.$linked_ticket_subject.'">'.$seperated_linked_tickets.' '.$linked_ticket_subject.'</span>';
}
echo '</div>
</div>';
}
}
}
}
// There haven't been tickets linked yet
else {
echo '
<div class="row">
<span>-<span>
</div>';
}
// At last the ability to link tickets (this could be restricted to specific user-rights like the display of the href-link above)
?>
<div class="row">
<div class="title"><?php echo $hesklang['seqid']; ?>:</div>
<div class="value">
<form action="?track=<?php echo $trackingID;?>" method="post">
<input type="number" name="link_ticket_id" style="width: 70px;" />
<input type="hidden" name="track" value="<?php echo $trackingID; ?>">
<input type="hidden" name="token" value="<?php if (hesk_token_echo() == "") {hesk_token_echo(0);} else {hesk_token_echo();} ?>" />
<input type="submit" name="verknüpfen" value="verknüpfen" style="background-color:white; border: 0px; text-decoration:underline; margin: 4px 2px; color:blue;" />
</form>
</div>
</div>
</div>
</section>
Preview: