Have you ever wanted a trash can for each attachment on a ticket post? Here it is! This will work for systems storing attachments in the filesystem or the database.
You will need to modify the following two files:
modules\tickets\staff_viewticket.php
modules\tickets\staff_ticketactions.php
INSTALLATION INSTRUCTIONS:
Find the following section of code in the
staff_viewticket.php file. It should be near the end of the file. Replace the commented out echo statement with the four echo statements inside the "modified by" comments. This code creates the trash can icon and link to the delete attachment action.
PHP Code:
foreach ($val["attachments"] as $atkey=>$atval)
{
$extension = getFileExtension($atval["filename"]);
$mimedata = $mimelist[$extension];
if (!empty($mimedata[1]))
{
$icon = $mimedata[1];
} else {
$icon = "mimeico_blank.gif";
}
//BEGIN DELETE TICKET ATTACHMENT CODE MODIFICATIONS
echo '<table width="100%"><tr>';
echo '<td><a href="index.php?_m=tickets&_a=ticketactions&ticketid='. intval($_ticket["ticketid"]) .'&action=attachment&attachmentid='. intval($atval["attachmentid"]) .'" target="_blank"><img src="'. $_SWIFT["themepath"] . $icon .'" border="0" align="absmiddle" /> '. $atval["filename"] .'</a> ('. formattedSize($atval["filesize"]) .')'.'</td>';
echo '<td align="right"><a href="index.php?_m=tickets&_a=ticketactions&ticketid='. intval($_ticket["ticketid"]) .'&action=delattachment&attachmentid='. intval($atval["attachmentid"]) .'"><img src="'. $_SWIFT["themepath"] . "icon_delete.gif" .'" border="0" align="middle"/></a></td>';
echo '</tr></table>';
//echo '<span class="smalltext"><a href="index.php?_m=tickets&_a=ticketactions&ticketid='. intval($_ticket["ticketid"]) .'&action=attachment&attachmentid='. intval($atval["attachmentid"]) .'" target="_blank"><img src="'. $_SWIFT["themepath"] . $icon .'" border="0" align="absmiddle" /> '. $atval["filename"] .'</a> ('. formattedSize($atval["filesize"]) .')<br /></span>'.SWIFT_CRLF;
//END DELETE TICKET ATTACHMENT CODE MODIFICATION
}
The next file is the
staff_ticketactions.php file. Just drop the notated code below at the end of the file
between the last } and the %>, and that's it!
PHP Code:
//BEGIN DELETE TICKET ATTACHMENT CODE MODIFICATION
/**
* ###############################################
* DELETE ATTACHMENT
* ###############################################
*/
else if ($_GET["action"] == "delattachment") {
$_ticketobj =& new TicketMain($_REQUEST["ticketid"], true);
if (!$_ticketobj->ticket)
{
echo $_SWIFT["language"]["errorticketaccess"];
exit;
}
if ($_SWIFT["staff"]["tdeletepost"] != "0")
{
if (!empty($_GET["attachmentid"]))
{
// Are we using the filesytem or the database for storage?
$dbCore->query("SELECT `data` FROM `". TABLE_PREFIX ."settings` WHERE `vkey` = 'tickets_attachtype';");
$dbCore->nextRecord();
$AttachmentType = $dbCore->Record["data"];
if ($AttachmentType == 2) // This means we are using the filesystem
{
// Get filename
$dbCore->query("SELECT `storefilename` FROM `". TABLE_PREFIX ."attachments` WHERE `attachmentid` = '".intval($_GET["attachmentid"])."';");
$dbCore->nextRecord();
$StoreFilename = $dbCore->Record["storefilename"];
// Delete the file
unlink("./files/".$StoreFilename);
}
// Clean up the database
$dbCore->query("DELETE FROM `". TABLE_PREFIX ."attachments` WHERE `attachmentid` = '". intval($_GET["attachmentid"]) ."';"); // Delete attachment entry
$dbCore->query("DELETE * FROM `". TABLE_PREFIX ."attachmentchunks` WHERE `attachmentid` = '". intval($_GET["attachmentid"]) ."';"); // Delete attachment contents (if using database for storage; otherwise this does nothing)
// Clear hasattachments ticket indicator if there are no more attachments
$count = $dbCore->queryFetch("SELECT COUNT(*) AS count FROM `". TABLE_PREFIX ."attachments` WHERE `ticketid`= '". intval($_ticketobj->ticket["ticketid"]) ."';");
if(empty($count["count"]))
{
$dbCore->query("UPDATE `". TABLE_PREFIX ."tickets` SET `hasattachments` = '0' WHERE `ticketid` = '". intval($_ticketobj->ticket["ticketid"]) ."';"); // Delete attachment entry
}
}
header("location: index.php?_m=tickets&_a=viewticket&ticketid=". intval($_ticketobj->ticket["ticketid"]) ."&atdelconfirm=1");
}else {
header("location: index.php?_m=tickets&_a=viewticket&ticketid=". intval($_ticketobj->ticket["ticketid"]));
}
exit;
}
//END DELETE TICKET ATTACHMENT CODE MODIFICATION
NOTE: Added code modification by jcasares to remove "hasattachments" flag on tickets and clean up notification code