Need some help on modifying the trouble ticket system.
I am in need of adding the ability for operators with ME privileges to delete file attachments on tickets.
I have been able to generate a link (a href) when there is an attachment on a ticket.
I have added a new sub routine to TTXFile.pm for deletion of one file.
Here is what I have code wise, and I'll show the error/issue I am getting/having. Any help is appreciated!
In ticket.html -->function delfile(FID){
if (confirm("[%Please confirm file attachment deletion%]")) {
msg = document.newticket.problem.value;
window.location.href = "(%ENV_SCRIPT_NAME%)?cmd=delfile&fid="+FID;
}
}
In TTXTicket.pm --> for (my $i=1; $i < 10; ++$i) {
if ($header{"FILE$i"} ne undef) {
if ($firstfile) {
$body .= '<br class=sm><br class=sm>[%Files%]:<br>'."\n";
$firstfile = 0;
}
$header{"FILE$i"} =~ s/CGIURL/$ENV{SCRIPT_NAME}/;
$body .= $header{"FILE$i"} . "<br>\n";
if($header{"FILE$i"} =~ /(fid=\d*-\d*-\d*-\d*)/i){
$fid = substr($1, 4);
}
$body .= "<a href='".$cfg->get('scriptname')."?cmd=delfile&fid=".$fid."' onclick='return delfile(".$fid.")'>delete attachment</a><br>\n"; #added by BJR --> this will be file attachment link for deletion!
}
}
In ttx.cgi -->#File Attachment Deletion
delfile => { action => 'TTXFile::delfile', access => 1, noheader => 1 },
In TTXFile.pm -->sub delfile {
my $fid = shift.'.dat';
my $dir = TTXData::get('CONFIG')->get('basedir').'/files';
if(($fid !~ /(\d*-\d*-\d*-\d*).dat/) || (!open(F, "$dir/$fid"))) {
fatalerror("File not found: ".$fid);
}else{
unlink "$dir/$fid";
}
}
The error appears to come when passing the file id from the javascript function (found in ticket.html --see above) into the sub routine delfile (found in TTXFile --see above).
When I run it directly (ie:
http://ticketsystem/ttx.cgi?cmd=delfile&fid=1881-1312380452-1-380644 ) I receive:
Fatal Error: File not found: TTXConfig=HASH(0x1c23290).datNow, if I manually define the $fid (in TTXFile.pm) as: my $fid = 1881-1312380452-1-380644 (instead of: my $fid = shift.'.dat'; -->as found above);
The file will delete with no problem.
I have one more issue that pertains to this, but one at a time I suppose.
Any insight would be greatly appreciated!!
Thanks,
Brandon