summaryrefslogtreecommitdiff
path: root/httemplate/edit/invoice_logo.html
blob: e1c61496ffc07731b62e8c6a4ba387dfa139cc02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<% include("/elements/header.html", "Edit $type2desc{$type} invoice logo",
             menubar(
               'View all invoice templates' => $p.'browse/invoice_template.html'
             )
          )
%>

% if ( $error ) { 
  <FONT SIZE="+1" COLOR="#ff0000">Error: <% $error %></FONT>
  <BR><BR>
% } 

% if ( $cgi->param('msg') ) { 
  <FONT SIZE="+1"><B><% $cgi->param('msg') |h %></B></FONT>
  <BR><BR>
% } 

% if ( $mode eq 'upload' ) {
  <FORM ACTION="invoice_logo.html" METHOD="POST" ENCTYPE="multipart/form-data">
  <INPUT TYPE="hidden" NAME="mode" VALUE="preview">
% } elsif ( $mode eq 'preview' ) {
  <FORM ACTION="process/invoice_logo.html" METHOD="POST">
  <INPUT TYPE="hidden" NAME="preview_session" VALUE="<% $session %>">
% }

<INPUT TYPE="hidden" NAME="type" VALUE="<% $type %>">
<INPUT TYPE="hidden" NAME="name" VALUE="<% $name %>">

<% include('/elements/table-grid.html') %>

<TR>
  <TH CLASS="grid" BGCOLOR="#cccccc">Current logo</TH>
  <TH CLASS="grid" BGCOLOR="#cccccc">New logo preview</TH>
</TR>

<TR>

  <TD CLASS="grid" BGCOLOR="#ffffff">

%   if ( $type eq 'png' ) {

      <IMG SRC="<% $p %>view/logo.cgi?type=png;name=<% $name %>">

%   } elsif ( $type eq 'eps' ) {

     <i>EPS preview not yet supported</i>

%   }

  </TD>

  <TD CLASS="grid" BGCOLOR="#ffffff">

% if ( $mode eq 'upload' ) {

    Upload new logo (.<%uc($type)%> format): <INPUT TYPE="file" NAME="new_logo">
    <BR><INPUT TYPE="submit" NAME="submit" VALUE="Upload">

% } elsif ( $mode eq 'preview' ) {

    <IMG SRC="<% $p %>view/logo.cgi?type=png;preview_session=<% $session %>">

% }

  </TD>


</TR>

</TABLE>

% if ( $mode eq 'preview' ) {
  <BR>
  <INPUT TYPE="submit" NAME="submit" VALUE="Change logo">
% }

</FORM>

<% include("/elements/footer.html") %>

<%once>

my %type2desc = (
  'png'  => 'online',
  'eps'  => 'Print/PDF (typeset)',
);

</%once>
<%init>

die "access denied"
  unless $FS::CurrentUser::CurrentUser->access_right('Configuration');

my $conf = new FS::Conf;

my $type = $cgi->param('type');

$cgi->param('name') =~ /^([^\.\/]*)$/ or die "illegal name";
my $name = $1;

$cgi->param('mode') =~ /^(\w*)$/ or die "illegal mode";
my $mode = $1 || 'upload';

my $error = '';
my $session = '';
if ( $mode eq 'preview' ) {

  my $fh = $cgi->upload('new_logo');

  if ( defined $fh ) {

    local $/;
    my $logo_data = <$fh>;

    $session = int(rand(4294967296)); #XXX
    my $pref = new FS::access_user_pref({
      'usernum'    => $FS::CurrentUser::CurrentUser->usernum,
      'prefname'   => "logo_preview$session",
      'prefvalue'  => encode_base64($logo_data),
      'expiration' => time + 3600, #1h?  1m?
    });
    my $pref_error = $pref->insert;
    if ( $pref_error ) {
      die "FATAL: couldn't set preview cookie: $pref_error\n";
    }

  } else {

    $mode = 'upload';
    $error = 'No file uploaded';

  }

}

</%init>