Kayako logo
Modifications & Addon Releases Modification guides and addons are posted here to share with the community. Do not post requests in here!

Notices

Reply
 
LinkBack Thread Tools Search this Thread Rating: Thread Rating: 3 votes, 5.00 average. Display Modes
  (#1) Old
jenglish Offline
Member
 
jenglish's Avatar
 
Posts: 39
Join Date: Jan 2007
Location: Tyler, TX
Thumbs up Delete ticket attachments! - 22-10-2008, 09:37 PM

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" />&nbsp;'$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" />&nbsp;'. $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
Attached Images
File Type: png screenshot.png (6.6 KB, 15 views)

Last edited by jenglish; 30-10-2008 at 06:14 PM..
   
Reply With Quote
  (#2) Old
mopa Offline
Member
 
mopa's Avatar
 
Posts: 146
Join Date: May 2007
Location: Denmark
30-10-2008, 02:52 PM

Nice

It works exactly as it should. Nothing much (only a trashcan) but seriously nice to have - THANKS


Kayako: 3.11.01 | PHP: 5.2.3 | MySQL: 5.0.41 | Windows 2003 Server
   
Reply With Quote
  (#3) Old
jcasares Offline
Member
 
jcasares's Avatar
 
Posts: 56
Join Date: Oct 2008
Location: Argentina
30-10-2008, 04:31 PM

What the string $_SWIFT["language"]["atdelconfirm"] should be like?
   
Reply With Quote
  (#4) Old
jenglish Offline
Member
 
jenglish's Avatar
 
Posts: 39
Join Date: Jan 2007
Location: Tyler, TX
30-10-2008, 04:33 PM

I don't believe that it is actually used in this mod. I bet you could comment out that line and not notice a difference. The "confirmation" does not show on this mod. Just a leftover line of code I forgot to clean up.
   
Reply With Quote
  (#5) Old
craigbrass Offline
Senior Member
 
Posts: 5,916
Join Date: Jun 2005
Location: Cumbria, UK
30-10-2008, 04:36 PM

Looking good. Thanks for sharing!


Craig Brass - Kayako Forum Squatter (Note: I am NOT a staff member)

Icon Headquarters - Its Elixir - Web2Messenger
   
Reply With Quote
  (#6) Old
jcasares Offline
Member
 
jcasares's Avatar
 
Posts: 56
Join Date: Oct 2008
Location: Argentina
30-10-2008, 05:39 PM

** CODE Withdrawn **

Last edited by jcasares; 27-11-2008 at 07:33 AM..
   
Reply With Quote
  (#7) Old
jenglish Offline
Member
 
jenglish's Avatar
 
Posts: 39
Join Date: Jan 2007
Location: Tyler, TX
30-10-2008, 05:48 PM

Thanks for the code! Added to the original posting.
   
Reply With Quote
  (#8) Old
jcasares Offline
Member
 
jcasares's Avatar
 
Posts: 56
Join Date: Oct 2008
Location: Argentina
30-10-2008, 06:13 PM

Quote:
Originally Posted by jenglish View Post
** NOTE: We have a heavily modified help desk, and I don't have time to create two stock drop-in files. Please feel free to make these and post them with this thread. **
As I've read here it's forbidden by the license to post files from the software.
   
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete attachments from a ticket reply NC Software Feature Requests 0 02-09-2008 05:06 PM
New Build: 3.10.02 STABLE Ryan Lederman News and Announcements 0 05-03-2007 09:53 PM
eSupport v2.2 RC1 Available in Members Area Varun Shoor Technical Chat 1 17-05-2004 02:28 PM



Powered by vBulletin® Version 3.7.5
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
Help desk software by Kayako.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48