This commit was generated by cvs2svn to compensate for changes in r8593,
[freeside.git] / httemplate / browse / cust_attachment.html
1 <% include( 'elements/browse.html',
2                  'title'       => 'Attachments',
3                  'menubar'     => '',
4                  'name'        => ($disabled ? 'deleted' : '') .' attachments',
5                  'html_init'   => include('/elements/init_overlib.html') .
6                     ($curuser->access_right('View deleted attachments') ? (
7                     selflink('Show '.($disabled ? 'active' : 'deleted'),
8                              show_deleted => (1-$disabled))) : ''),
9                  'html_form'   => 
10                     qq!<FORM NAME="attachForm" ACTION="$p/misc/cust_attachment.cgi" METHOD="POST">
11                     <INPUT TYPE="hidden" NAME="orderby" VALUE="$orderby">
12                     <INPUT TYPE="hidden" NAME="show_deleted" VALUE="$disabled">!
13                     , 
14                  'query'       => { 'table'     => 'cust_attachment',
15                                     'hashref'   => $hashref,
16                                     'extra_sql' => 'ORDER BY '.$orderby,
17                                   },
18                  'count_query' => $count_query,
19                  'header' => [ selflink('#',orderby => 'attachnum'),
20                                selflink('Customer',orderby => 'custnum'),
21                                selflink('Date',orderby => '_date'),
22                                selflink('Filename',orderby => 'filename'),
23                                selflink('Size',orderby => 'length(body)'),
24                                selflink('Uploaded by',orderby => 'otaker'),
25                                selflink('Description',orderby => 'title'),
26                                '', # checkbox column
27                              ],
28                  'fields' => [
29                                'attachnum',
30                                $sub_cust,
31                                $sub_date,
32                                'filename',
33                                $sub_size,
34                                'otaker',
35                                'title',
36                                $sub_checkbox,
37                              ],
38                  'links' => [ '',
39                               [ $p.'view/cust_main.cgi?', 'custnum' ],
40                             ],
41                  'link_onclicks' => [
42                               '',
43                               '',
44                               '',
45                               $sub_edit_link,
46                               ],
47
48                  #'links' =>  [
49                  #              '',
50                  #              '',
51                  #              '',
52                  #              '',
53                  #              '',
54                  #              '', #$acct_link,
55                  #              '',
56                 'html_foot' => $sub_foot,
57              )
58
59 %>
60
61
62 <%init>
63
64 my $curuser = $FS::CurrentUser::CurrentUser;
65 die "access denied" if !$curuser->access-right('View attachments');
66
67 my $conf = new FS::Conf;
68
69 my $noactions = 1;
70 my $areboxes = 0;
71
72 my $disabled = 0;
73
74 if($cgi->param('show_deleted')) {
75   if ($curuser->access_right('View deleted attachments')) {
76     $disabled = 1;
77     if ($curuser->access_right('Purge attachment') or
78         $curuser->access_right('Undelete attachment')) {
79       $noactions = 0;
80     }
81   }
82   else {
83     die "access denied";
84   }
85 }
86 else {
87   if ($curuser->access_right('Delete attachment')) {
88     $noactions = 0;
89   }
90 }
91
92 my $hashref = $disabled ? 
93   { disabled => { op => '>', value => 0 } } :
94   { disabled => '' };
95
96 my $count_query = 'SELECT COUNT(*) FROM cust_attachment WHERE '. ($disabled ?
97   'disabled > 0' : 'disabled IS NULL');
98
99 my $orderby = $cgi->param('orderby') || 'custnum';
100
101 my $sub_cust = sub {
102   my $c = qsearchs('cust_main', { custnum => shift->custnum } );
103   return $c ? $c->name : '<FONT COLOR="red"><B>(not found)</B></FONT>';
104 };
105
106 my $sub_date = sub {
107   time2str("%b %o, %Y", shift->_date);
108 };
109
110 my $sub_size = sub {
111   my $size = shift->size;
112   return $size if $size < 1024;
113   return int($size/1024).'K' if $size < 1048576;
114   return int($size/1048576).'M';
115 };
116
117 my $sub_checkbox = sub {
118   return '' if $noactions;
119   my $attach = shift;
120   my $attachnum = $attach->attachnum;
121   $areboxes = 1;
122   return qq!<INPUT NAME="attachnum$attachnum" TYPE="checkbox" VALUE="1">!;
123 };
124
125 my $sub_edit_link = sub {
126   my $attach = shift;
127   my $attachnum = $attach->attachnum;
128   my $custnum = $attach->custnum;
129   return include('/elements/popup_link_onclick.html',
130            action => popurl(2).'edit/cust_main_attach.cgi?'.
131                      "custnum=$custnum;attachnum=$attachnum",
132            actionlabel => 'Edit attachment properties',
133            width  => 510,
134            height => 315,
135            frame  => 'top',
136            );
137 };
138
139 sub selflink {
140   my $label = shift;
141   my %new_param = @_;
142   my $param = $cgi->Vars;
143   my %old_param = %$param;
144   @{$param}{keys(%new_param)} = values(%new_param);
145   my $link = '<a href="'.$cgi->self_url.'">'.$label.'</a>';
146   %$param = %old_param;
147   return $link;
148 }
149
150 sub confirm {
151   my $action = shift;
152   my $onclick = "return(confirm('$action all selected files?'))";
153   return qq!onclick="$onclick"!;
154 }
155
156 my $sub_foot = sub {
157   return '' if ($noactions or !$areboxes);
158   my $foot = 
159 '<BR><INPUT TYPE="button" VALUE="Select all" onClick="setAll(true)">
160 <INPUT TYPE="button" VALUE="Unselect all" onClick="setAll(false)">';
161   if ($disabled) {
162     if ($curuser->access_right('Undelete attachment')) {
163       $foot .= '<BR><INPUT TYPE="submit" NAME="action" VALUE="Undelete selected">';
164     }
165     if ($curuser->access_right('Purge attachment')) {
166       $foot .= '<BR><INPUT TYPE="submit" NAME="action" VALUE="Purge selected" '.confirm('Purge').'>';
167     }
168   }
169   else {
170     $foot .= '<BR><INPUT TYPE="submit" NAME="action" VALUE="Delete selected" '.confirm('Delete').'>';
171   }
172   $foot .= 
173 '<SCRIPT TYPE="text/javascript">
174   function setAll(setTo) { 
175     theForm = document.attachForm;
176     for (i=0,n=theForm.elements.length;i<n;i++)
177       if (theForm.elements[i].name.indexOf("attachnum") != -1)
178         theForm.elements[i].checked = setTo;
179   }
180 </SCRIPT>';
181   return $foot;
182 };
183
184 </%init>