2 % $cgi->param('error', $error);
3 <% $cgi->redirect(popurl(2). 'cust_main_attach.cgi?'. $cgi->query_string ) %>
6 % $act = 'updated' if ($attachnum);
7 % $act = 'purged' if($attachnum and $purge);
8 % $act = 'undeleted' if($attachnum and $undelete);
9 % $act = 'deleted' if($attachnum and $delete);
10 <& /elements/popup-topreload.html, mt("Attachment $act") &>
15 $cgi->param('custnum') =~ /^(\d+)$/
16 or die "Illegal custnum: ". $cgi->param('custnum');
19 $cgi->param('attachnum') =~ /^(\d*)$/
20 or die "Illegal attachnum: ". $cgi->param('attachnum');
23 my $filename = $cgi->param('file');
24 # strip directory names; thanks, IE7
25 $filename =~ s!.*[\/\\]!!;
27 my $curuser = $FS::CurrentUser::CurrentUser;
29 my $delete = $cgi->param('delete');
30 my $undelete = $cgi->param('undelete');
31 my $purge = $cgi->param('purge');
33 my $new = new FS::cust_attachment ( {
34 attachnum => $attachnum,
37 usernum => $curuser->usernum,
43 $old = qsearchs('cust_attachment', { attachnum => $attachnum });
45 $error = "Attachnum '$attachnum' not found";
47 elsif($purge) { # do nothing
50 map { $new->$_($old->$_) }
51 ('_date', 'otaker', 'body', 'disabled');
52 $new->filename($filename || $old->filename);
53 $new->mime_type($cgi->param('mime_type') || $old->mime_type);
54 $new->title( scalar($cgi->param('title')) );
55 if($delete and not $old->disabled) {
58 if($undelete and $old->disabled) {
63 else { # This is a new attachment, so require a file.
66 $new->filename($filename);
67 # use the original filename here, not the stripped form
69 $cgi->uploadInfo( scalar($cgi->param('file')) )->{'Content-Type'}
71 $new->title( scalar($cgi->param('title')) );
74 my $fh = $cgi->upload('file');
78 $error = 'No file uploaded';
82 $action = 'Edit' if $attachnum;
83 $action = 'Delete' if $attachnum and $delete;
84 $action = 'Undelete' if $attachnum and $undelete;
85 $action = 'Purge' if $attachnum and $purge;
87 $error = 'access denied' unless $curuser->access_right($action . ' attachment');
90 if($old and $old->disabled and $purge) {
91 $error = $old->delete;
94 $error = $new->replace($old);
97 $error = $new->insert;