Optimize "Customer has a referring customer" condition, RT#74452
[freeside.git] / httemplate / edit / cust_main_attach.cgi
1 <% include('/elements/header-popup.html', "$action File Attachment") %>
2
3 <% include('/elements/error.html') %>
4
5 <FORM NAME="attach_edit" ACTION="<% popurl(1) %>process/cust_main_attach.cgi" METHOD=POST ENCTYPE="multipart/form-data">
6 <INPUT TYPE="hidden" NAME="custnum" VALUE="<% $custnum %>">
7 <INPUT TYPE="hidden" NAME="attachnum" VALUE="<% $attachnum %>">
8
9 % if(defined $attach) {
10 %   if($curuser->access_right("Download attachment")) {
11 <A HREF="<% $p.'view/attachment.html?'.$attachnum %>">Download this file</A><BR>
12 %   }
13 % }
14
15 <BR>
16 <TABLE BGCOLOR="#cccccc" CELLSPACING=0>
17
18 % if ( defined $attach ) {
19 <TR><TD> Filename </TD>
20 <TD><INPUT TYPE="text" NAME="file" SIZE=40 MAXLENGTH=255 VALUE="<% $cgi->param('file') || $attach->filename |h %>"<% $disabled %>></TD></TR>
21 <TR><TD> Description </TD>
22 <TD><INPUT TYPE="text" NAME="title" SIZE=40 MAXLENGTH=80 VALUE="<% $cgi->param('title') || $attach->title |h %>"<% $disabled %></TD></TR>
23 <TR><TD> MIME type </TD>
24 <TD><INPUT TYPE="text" NAME="mime_type" SIZE=40 VALUE="<% $cgi->param('mime_type') || $attach->mime_type |h %>"<% $disabled %></TD></TR>
25 <TR><TD> Size </TD><TD><% $attach->size %></TD></TR>
26 % }
27 % else { # !defined $attach
28 <TR><TD> Filename </TD><TD><INPUT TYPE="file" SIZE=24 NAME="file"></TD></TR>
29 <TR><TD> Description </TD><TD><INPUT TYPE="text" NAME="title" SIZE=40 MAXLENGTH=80></TD></TR>
30 % }
31 </TABLE>
32 <BR>
33 % if(! $disabled) {
34 <INPUT TYPE="submit" NAME="submit" 
35     VALUE="<% $attachnum ? emt("Apply changes") : emt("Upload File") %>">
36 % }
37 % if(defined $attach and $curuser->access_right('Delete attachment')) {
38 <BR>
39 <INPUT TYPE="submit" NAME="delete" value="Delete File" 
40 onclick="return(confirm('Delete this file?'));">
41 % }
42
43 </FORM>
44 </BODY>
45 </HTML>
46
47 <%init>
48
49 my $curuser = $FS::CurrentUser::CurrentUser;
50
51 my $attachnum = '';
52 my $attach;
53
54 if ( $cgi->param('attachnum') =~ /^(\d+)$/ ) {
55   $attachnum = $1;
56   die "illegal query ". $cgi->keywords unless $attachnum;
57   $attach = qsearchs('cust_attachment', { 'attachnum' => $attachnum });
58   die "no such attachment: ". $attachnum unless $attach;
59 }
60
61 my $action = $attachnum ? 'Edit' : 'Add';
62
63 my $disabled='';
64 if(! $curuser->access_right("$action attachment")) {
65   $disabled = ' disabled="disabled"';
66 }
67
68 $cgi->param('custnum') =~ /^(\d+)$/ or die "illegal custnum";
69 my $custnum = $1;
70
71 </%init>
72