2 % $cgi->param('error', $error);
3 <% $cgi->redirect(popurl(2). 'cust_main_attach.cgi?'. $cgi->query_string ) %>
6 % $act = 'updated' if ($attachnum);
7 % $act = 'undeleted' if($attachnum and $undelete);
8 % $act = 'deleted' if($attachnum and $delete);
9 <% header('Attachment ' . $act ) %>
10 <SCRIPT TYPE="text/javascript">
11 window.top.location.reload();
18 $cgi->param('custnum') =~ /^(\d+)$/
19 or die "Illegal custnum: ". $cgi->param('custnum');
22 $cgi->param('attachnum') =~ /^(\d*)$/
23 or die "Illegal attachnum: ". $cgi->param('attachnum');
26 my $otaker = $FS::CurrentUser::CurrentUser->name;
27 $otaker = $FS::CurrentUser::CurrentUser->username
28 if ($otaker eq "User, Legacy");
30 my $delete = $cgi->param('delete');
31 my $undelete = $cgi->param('undelete');
33 my $new = new FS::cust_attachment ( {
34 attachnum => $attachnum,
43 $old = qsearchs('cust_attachment', { attachnum => $attachnum });
45 $error = "Attachnum '$attachnum' not found";
48 map { $new->$_($old->$_) }
49 ('_date', 'otaker', 'body', 'disabled');
50 $new->filename($cgi->param('filename') || $old->filename);
51 $new->mime_type($cgi->param('mime_type') || $old->mime_type);
52 if($delete and not $old->disabled) {
55 if($undelete and $old->disabled) {
60 else { # This is a new attachment, so require a file.
62 my $filename = $cgi->param('file');
64 $new->filename($filename);
65 $new->mime_type($cgi->uploadInfo($filename)->{'Content-Type'});
68 my $fh = $cgi->upload('file');
72 $error = 'No file uploaded';
75 my $user = $FS::CurrentUser::CurrentUser;
77 $error = 'access denied' unless $user->access_right(($old ? 'Edit' : 'Add') . ' attachment');
81 $error = $new->replace($old);
84 $error = $new->insert;