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/header-popup.html, 'Attachment ' . $act &>
11 <SCRIPT TYPE="text/javascript">
19 $cgi->param('custnum') =~ /^(\d+)$/
20 or die "Illegal custnum: ". $cgi->param('custnum');
23 $cgi->param('attachnum') =~ /^(\d*)$/
24 or die "Illegal attachnum: ". $cgi->param('attachnum');
27 my $filename = $cgi->param('file');
28 # strip directory names; thanks, IE7
29 $filename =~ s!.*[\/\\]!!;
31 my $curuser = $FS::CurrentUser::CurrentUser;
33 my $delete = $cgi->param('delete');
34 my $undelete = $cgi->param('undelete');
35 my $purge = $cgi->param('purge');
37 my $new = new FS::cust_attachment ( {
38 attachnum => $attachnum,
41 usernum => $curuser->usernum,
47 $old = qsearchs('cust_attachment', { attachnum => $attachnum });
49 $error = "Attachnum '$attachnum' not found";
51 elsif($purge) { # do nothing
54 map { $new->$_($old->$_) }
55 ('_date', 'otaker', 'body', 'disabled');
56 $new->filename($filename || $old->filename);
57 $new->mime_type($cgi->param('mime_type') || $old->mime_type);
58 $new->title($cgi->param('title'));
59 if($delete and not $old->disabled) {
62 if($undelete and $old->disabled) {
67 else { # This is a new attachment, so require a file.
70 $new->filename($filename);
71 # use the original filename here, not the stripped form
72 $new->mime_type($cgi->uploadInfo($cgi->param('file'))->{'Content-Type'});
73 $new->title($cgi->param('title'));
76 my $fh = $cgi->upload('file');
80 $error = 'No file uploaded';
84 $action = 'Edit' if $attachnum;
85 $action = 'Delete' if $attachnum and $delete;
86 $action = 'Undelete' if $attachnum and $undelete;
87 $action = 'Purge' if $attachnum and $purge;
89 $error = 'access denied' unless $curuser->access_right($action . ' attachment');
92 if($old and $old->disabled and $purge) {
93 $error = $old->delete;
96 $error = $new->replace($old);
99 $error = $new->insert;