This commit was generated by cvs2svn to compensate for changes in r9232,
[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                     or !$curuser->access_right('Browse attachments');
67
68 my $conf = new FS::Conf;
69
70 my $noactions = 1;
71 my $areboxes = 0;
72
73 my $disabled = 0;
74
75 if($cgi->param('show_deleted')) {
76   if ($curuser->access_right('View deleted attachments')) {
77     $disabled = 1;
78     if ($curuser->access_right('Purge attachment') or
79         $curuser->access_right('Undelete attachment')) {
80       $noactions = 0;
81     }
82   }
83   else {
84     die "access denied";
85   }
86 }
87 else {
88   if ($curuser->access_right('Delete attachment')) {
89     $noactions = 0;
90   }
91 }
92
93 my $hashref = $disabled ? 
94   { disabled => { op => '>', value => 0 } } :
95   { disabled => '' };
96
97 my $count_query = 'SELECT COUNT(*) FROM cust_attachment WHERE '. ($disabled ?
98   'disabled > 0' : 'disabled IS NULL');
99
100 my $orderby = $cgi->param('orderby') || 'custnum';
101
102 my $sub_cust = sub {
103   my $c = qsearchs('cust_main', { custnum => shift->custnum } );
104   return $c ? $c->name : '<FONT COLOR="red"><B>(not found)</B></FONT>';
105 };
106
107 my $sub_date = sub {
108   time2str("%b %o, %Y", shift->_date);
109 };
110
111 my $sub_size = sub {
112   my $size = shift->size;
113   return $size if $size < 1024;
114   return int($size/1024).'K' if $size < 1048576;
115   return int($size/1048576).'M';
116 };
117
118 my $sub_checkbox = sub {
119   return '' if $noactions;
120   my $attach = shift;
121   my $attachnum = $attach->attachnum;
122   $areboxes = 1;
123   return qq!<INPUT NAME="attachnum$attachnum" TYPE="checkbox" VALUE="1">!;
124 };
125
126 my $sub_edit_link = sub {
127   my $attach = shift;
128   my $attachnum = $attach->attachnum;
129   my $custnum = $attach->custnum;
130   return include('/elements/popup_link_onclick.html',
131            action => popurl(2).'edit/cust_main_attach.cgi?'.
132                      "custnum=$custnum;attachnum=$attachnum",
133            actionlabel => 'Edit attachment properties',
134            width  => 510,
135            height => 315,
136            frame  => 'top',
137            );
138 };
139
140 sub selflink {
141   my $label = shift;
142   my %new_param = @_;
143   my $param = $cgi->Vars;
144   my %old_param = %$param;
145   @{$param}{keys(%new_param)} = values(%new_param);
146   my $link = '<a href="'.$cgi->self_url.'">'.$label.'</a>';
147   %$param = %old_param;
148   return $link;
149 }
150
151 sub confirm {
152   my $action = shift;
153   my $onclick = "return(confirm('$action all selected files?'))";
154   return qq!onclick="$onclick"!;
155 }
156
157 my $sub_foot = sub {
158   return '' if ($noactions or !$areboxes);
159   my $foot = 
160 '<BR><INPUT TYPE="button" VALUE="Select all" onClick="setAll(true)">
161 <INPUT TYPE="button" VALUE="Unselect all" onClick="setAll(false)">';
162   if ($disabled) {
163     if ($curuser->access_right('Undelete attachment')) {
164       $foot .= '<BR><INPUT TYPE="submit" NAME="action" VALUE="Undelete selected">';
165     }
166     if ($curuser->access_right('Purge attachment')) {
167       $foot .= '<BR><INPUT TYPE="submit" NAME="action" VALUE="Purge selected" '.confirm('Purge').'>';
168     }
169   }
170   else {
171     $foot .= '<BR><INPUT TYPE="submit" NAME="action" VALUE="Delete selected" '.confirm('Delete').'>';
172   }
173   $foot .= 
174 '<SCRIPT TYPE="text/javascript">
175   function setAll(setTo) { 
176     theForm = document.attachForm;
177     for (i=0,n=theForm.elements.length;i<n;i++)
178       if (theForm.elements[i].name.indexOf("attachnum") != -1)
179         theForm.elements[i].checked = setTo;
180   }
181 </SCRIPT>';
182   return $foot;
183 };
184
185 </%init>