enable CardFortress in test database, #71513
[freeside.git] / httemplate / edit / invoice_logo.html
1 <% include("/elements/header.html", "Edit $type2desc{$type} invoice logo",
2              menubar(
3                'View all invoice templates' => $p.'browse/invoice_template.html'
4              )
5           )
6 %>
7
8 % if ( $error ) { 
9   <FONT SIZE="+1" COLOR="#ff0000">Error: <% $error %></FONT>
10   <BR><BR>
11 % } 
12
13 % if ( $cgi->param('msg') ) { 
14   <FONT SIZE="+1"><B><% $cgi->param('msg') |h %></B></FONT>
15   <BR><BR>
16 % } 
17
18 % if ( $mode eq 'upload' ) {
19   <FORM ACTION="invoice_logo.html" METHOD="POST" ENCTYPE="multipart/form-data">
20   <INPUT TYPE="hidden" NAME="mode" VALUE="preview">
21 % } elsif ( $mode eq 'preview' ) {
22   <FORM ACTION="process/invoice_logo.html" METHOD="POST">
23   <INPUT TYPE="hidden" NAME="preview_session" VALUE="<% $session %>">
24 % }
25
26 <INPUT TYPE="hidden" NAME="type" VALUE="<% $type %>">
27 <INPUT TYPE="hidden" NAME="name" VALUE="<% $name %>">
28
29 <% include('/elements/table-grid.html') %>
30
31 <TR>
32   <TH CLASS="grid" BGCOLOR="#cccccc">Current logo</TH>
33   <TH CLASS="grid" BGCOLOR="#cccccc">New logo preview</TH>
34 </TR>
35
36 <TR>
37
38   <TD CLASS="grid" BGCOLOR="#ffffff">
39
40 %   if ( $type eq 'png' ) {
41
42       <IMG SRC="<% $p %>view/logo.cgi?type=png;name=<% $name %>">
43
44 %   } elsif ( $type eq 'eps' ) {
45
46      <i>EPS preview not yet supported</i>
47
48 %   }
49
50   </TD>
51
52   <TD CLASS="grid" BGCOLOR="#ffffff">
53
54 % if ( $mode eq 'upload' ) {
55
56     Upload new logo (.<%uc($type)%> format): <INPUT TYPE="file" NAME="new_logo">
57     <BR><INPUT TYPE="submit" NAME="submit" VALUE="Upload">
58
59 % } elsif ( $mode eq 'preview' ) {
60
61     <IMG SRC="<% $p %>view/logo.cgi?type=png;preview_session=<% $session %>">
62
63 % }
64
65   </TD>
66
67
68 </TR>
69
70 </TABLE>
71
72 % if ( $mode eq 'preview' ) {
73   <BR>
74   <INPUT TYPE="submit" NAME="submit" VALUE="Change logo">
75 % }
76
77 </FORM>
78
79 <% include("/elements/footer.html") %>
80
81 <%once>
82
83 my %type2desc = (
84   'png'  => 'online',
85   'eps'  => 'Print/PDF (typeset)',
86 );
87
88 </%once>
89 <%init>
90
91 die "access denied"
92   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
93
94 my $conf = new FS::Conf;
95
96 my $type = $cgi->param('type');
97
98 $cgi->param('name') =~ /^([^\.\/]*)$/ or die "illegal name";
99 my $name = $1;
100
101 $cgi->param('mode') =~ /^(\w*)$/ or die "illegal mode";
102 my $mode = $1 || 'upload';
103
104 my $error = '';
105 my $session = '';
106 if ( $mode eq 'preview' ) {
107
108   my $fh = $cgi->upload('new_logo');
109
110   if ( defined $fh ) {
111
112     local $/;
113     my $logo_data = <$fh>;
114
115     $session = int(rand(4294967296)); #XXX
116     my $pref = new FS::access_user_pref({
117       'usernum'    => $FS::CurrentUser::CurrentUser->usernum,
118       'prefname'   => "logo_preview$session",
119       'prefvalue'  => encode_base64($logo_data),
120       'expiration' => time + 3600, #1h?  1m?
121     });
122     my $pref_error = $pref->insert;
123     if ( $pref_error ) {
124       die "FATAL: couldn't set preview cookie: $pref_error\n";
125     }
126
127   } else {
128
129     $mode = 'upload';
130     $error = 'No file uploaded';
131
132   }
133
134 }
135
136 </%init>