X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fedit%2Fprocess%2Fcust_main_attach.cgi;h=09c18adcb77ff44afa765fd4eac10121c3571195;hb=dcc698164f1f2b43a32b5503716fc7329c203714;hp=51eead07607b1049cff378aa6bd30fbce5576836;hpb=283ea2b5137ae3ec36882b492e6de024b0ce6027;p=freeside.git diff --git a/httemplate/edit/process/cust_main_attach.cgi b/httemplate/edit/process/cust_main_attach.cgi index 51eead076..09c18adcb 100644 --- a/httemplate/edit/process/cust_main_attach.cgi +++ b/httemplate/edit/process/cust_main_attach.cgi @@ -4,6 +4,7 @@ %} else { % my $act = 'added'; % $act = 'updated' if ($attachnum); +% $act = 'purged' if($attachnum and $purge); % $act = 'undeleted' if($attachnum and $undelete); % $act = 'deleted' if($attachnum and $delete); <% header('Attachment ' . $act ) %> @@ -23,18 +24,21 @@ $cgi->param('attachnum') =~ /^(\d*)$/ or die "Illegal attachnum: ". $cgi->param('attachnum'); my $attachnum = $1; -my $otaker = $FS::CurrentUser::CurrentUser->name; -$otaker = $FS::CurrentUser::CurrentUser->username - if ($otaker eq "User, Legacy"); +my $filename = $cgi->param('file'); +# strip directory names; thanks, IE7 +$filename =~ s!.*[\/\\]!!; + +my $curuser = $FS::CurrentUser::CurrentUser; my $delete = $cgi->param('delete'); my $undelete = $cgi->param('undelete'); +my $purge = $cgi->param('purge'); my $new = new FS::cust_attachment ( { attachnum => $attachnum, custnum => $custnum, _date => time, - otaker => $otaker, + usernum => $curuser->usernum, disabled => '', }); my $old; @@ -44,11 +48,14 @@ if($attachnum) { if(!$old) { $error = "Attachnum '$attachnum' not found"; } + elsif($purge) { # do nothing + } else { map { $new->$_($old->$_) } ('_date', 'otaker', 'body', 'disabled'); - $new->filename($cgi->param('filename') || $old->filename); + $new->filename($filename || $old->filename); $new->mime_type($cgi->param('mime_type') || $old->mime_type); + $new->title($cgi->param('title')); if($delete and not $old->disabled) { $new->disabled(time); } @@ -59,10 +66,11 @@ if($attachnum) { } else { # This is a new attachment, so require a file. - my $filename = $cgi->param('file'); if($filename) { $new->filename($filename); - $new->mime_type($cgi->uploadInfo($filename)->{'Content-Type'}); + # use the original filename here, not the stripped form + $new->mime_type($cgi->uploadInfo($cgi->param('file'))->{'Content-Type'}); + $new->title($cgi->param('title')); local $/; my $fh = $cgi->upload('file'); @@ -72,12 +80,19 @@ else { # This is a new attachment, so require a file. $error = 'No file uploaded'; } } -my $user = $FS::CurrentUser::CurrentUser; +my $action = 'Add'; +$action = 'Edit' if $attachnum; +$action = 'Delete' if $attachnum and $delete; +$action = 'Undelete' if $attachnum and $undelete; +$action = 'Purge' if $attachnum and $purge; -$error = 'access denied' unless $user->access_right(($old ? 'Edit' : 'Add') . ' attachment'); +$error = 'access denied' unless $curuser->access_right($action . ' attachment'); if(!$error) { - if($old) { + if($old and $old->disabled and $purge) { + $error = $old->delete; + } + elsif($old) { $error = $new->replace($old); } else {