cust_attachment improvement, RT#4964 and #6225
[freeside.git] / httemplate / view / cust_main.cgi
1 <% include('/elements/header.html', {
2              'title' => "Customer View: ". $cust_main->name,
3              'nobr'  => 1,
4           })
5 %>
6 <BR>
7
8 <% include('/elements/menubar.html',
9              { 'newstyle' => 1,
10                'selected' => $viewname{$view},
11                'url_base' => $cgi->url. "?custnum=$custnum;show=",
12              },
13              %views,
14           )
15 %>
16 <BR>
17
18 <% include('/elements/init_overlib.html') %>
19
20 <SCRIPT TYPE="text/javascript">
21 function areyousure(href, message) {
22   if (confirm(message) == true)
23     window.location.href = href;
24 }
25 </SCRIPT>
26
27 % if ( $view eq 'basics' || $view eq 'jumbo' ) {
28
29 % if ( $curuser->access_right('Edit customer') ) { 
30   <A HREF="<% $p %>edit/cust_main.cgi?<% $custnum %>">Edit this customer</A> | 
31 % } 
32
33 % if ( $curuser->access_right('Cancel customer')
34 %        && $cust_main->ncancelled_pkgs
35 %      ) {
36
37   <% include( '/elements/popup_link-cust_main.html',
38               { 'action'      => $p. 'misc/cancel_cust.html',
39                 'label'       => 'Cancel&nbsp;this&nbsp;customer',
40                 'actionlabel' => 'Confirm Cancellation',
41                 'color'       => '#ff0000',
42                 'cust_main'   => $cust_main,
43                 'width'       => 616, #make room for reasons
44               }
45             )
46   %> | 
47
48 % }
49
50 % if ( $conf->exists('deletecustomers')
51 %        && $curuser->access_right('Delete customer')
52 %      ) {
53   <A HREF="<% $p %>misc/delete-customer.cgi?<% $custnum%>">Delete this customer</A> | 
54 % } 
55
56 % unless ( $conf->exists('disable_customer_referrals') ) { 
57   <A HREF="<% $p %>edit/cust_main.cgi?referral_custnum=<% $custnum %>">Refer a new customer</A> | 
58   <A HREF="<% $p %>search/cust_main.cgi?referral_custnum=<% $custnum %>">View this customer's referrals</A>
59 % } 
60
61 <BR><BR>
62
63 % if (    $curuser->access_right('Billing event reports') 
64 %      || $curuser->access_right('View customer billing events')
65 %    ) {
66
67   <A HREF="<% $p %>search/cust_event.html?custnum=<% $custnum %>">View billing events for this customer</A>
68   <BR><BR>
69
70 % }
71
72 %my $signupurl = $conf->config('signupurl');
73 %if ( $signupurl ) {
74   This customer's signup URL: <A HREF="<% $signupurl %>?ref=<% $custnum %>"><% $signupurl %>?ref=<% $custnum %></A><BR><BR>
75 % } 
76
77
78 <A NAME="cust_main"></A>
79 <TABLE BORDER=0>
80 <TR>
81   <TD VALIGN="top">
82     <% include('cust_main/contacts.html', $cust_main ) %>
83   </TD>
84   <TD VALIGN="top" STYLE="padding-left: 54px">
85     <% include('cust_main/misc.html', $cust_main ) %>
86 % if ( $conf->config('payby-default') ne 'HIDE' ) { 
87
88       <BR>
89       <% include('cust_main/billing.html', $cust_main ) %>
90 % } 
91
92   </TD>
93 </TR>
94 </TABLE>
95
96 % }
97
98 % if ( $view eq 'notes' || $view eq 'jumbo' ) {
99
100 %if ( $cust_main->comments =~ /[^\s\n\r]/ ) {
101 <BR>
102 Comments
103 <% ntable("#cccccc") %><TR><TD><% ntable("#cccccc",2) %>
104 <TR>
105   <TD BGCOLOR="#ffffff">
106     <PRE><% encode_entities($cust_main->comments) %></PRE>
107   </TD>
108 </TR>
109 </TABLE></TABLE>
110 <BR><BR>
111 % }
112 <A NAME="notes">
113 % my $notecount = scalar($cust_main->notes());
114 % if ( ! $conf->exists('cust_main-disable_notes') || $notecount) {
115
116 %   unless ( $view eq 'notes' && $cust_main->comments !~ /[^\s\n\r]/ ) {
117       <BR>
118       <A NAME="cust_main_note"><FONT SIZE="+2">Notes</FONT></A><BR>
119 %   }
120
121 %   if ( $curuser->access_right('Add customer note') &&
122 %        ! $conf->exists('cust_main-disable_notes')
123 %      ) {
124
125   <% include( '/elements/popup_link-cust_main.html',
126                 'label'       => 'Add customer note',
127                 'action'      => $p. 'edit/cust_main_note.cgi',
128                 'actionlabel' => 'Enter customer note',
129                 'cust_main'   => $cust_main,
130                 'width'       => 616,
131                 'height'      => 408,
132             )
133   %>
134
135 %   }
136
137 <BR>
138
139 <% include('cust_main/notes.html', 'custnum' => $cust_main->custnum ) %>
140
141 % }
142 <BR>
143
144 % if(! $conf->config('disable_cust_attachment') 
145 %  and $curuser->access_right('Add attachment')) {
146 <% include( '/elements/popup_link-cust_main.html',
147               'label'       => 'Attach file',
148               'action'      => $p.'edit/cust_main_attach.cgi',
149               'actionlabel' => 'Upload file',
150               'cust_main'   => $cust_main,
151               'width'       => 480,
152               'height'      => 296,
153           )
154 %>
155 % }
156 <% include('cust_main/attachments.html', 'custnum' => $cust_main->custnum ) %>
157 % if($cgi->param('show_deleted')) {
158 <A HREF="<% $p.'view/cust_main.cgi?custnum=' . $cust_main->custnum .
159            ($view ? ";show=$view" : '') . '#notes' 
160            %>"><I>(Show active attachments)</I></A>
161 % }
162 % elsif($curuser->access_right('View deleted attachments')) {
163 <A HREF="<% $p.'view/cust_main.cgi?custnum=' . $cust_main->custnum .
164            ($view ? ";show=$view" : '') . ';show_deleted=1#notes'
165            %>"><I>(Show deleted attachments)</I></A>
166 % }
167 <BR>
168
169 % }
170
171 % if ( $view eq 'jumbo' ) {
172     <BR><BR>
173     <A NAME="tickets"><FONT SIZE="+2">Tickets</FONT></A><BR>
174 % }
175
176 % if ( $view eq 'tickets' || $view eq 'jumbo' ) {
177
178 % if ( $conf->config('ticket_system') ) { 
179   <% include('cust_main/tickets.html', $cust_main ) %>
180 % } 
181   <BR><BR>
182
183 % }
184
185 % if ( $view eq 'jumbo' ) { #XXX enable me && $curuser->access_right('View customer packages') { 
186
187   <A NAME="cust_pkg"><FONT SIZE="+2">Packages</FONT></A><BR>
188 % }
189
190 % if ( $view eq 'packages' || $view eq 'jumbo' ) {
191
192 % #XXX enable me# if ( $curuser->access_right('View customer packages') { 
193 <% include('cust_main/packages.html', $cust_main ) %>
194 % #}
195
196 % }
197
198 % if ( $view eq 'jumbo' ) {
199     <BR><BR>
200     <A NAME="history"><FONT SIZE="+2">Payment History</FONT></A><BR>
201 % }
202
203 % if ( $view eq 'payment_history' || $view eq 'jumbo' ) {
204
205 % if ( $conf->config('payby-default') ne 'HIDE' ) { 
206   <% include('cust_main/payment_history.html', $cust_main ) %>
207 % } 
208
209 % }
210
211 % if ( $view eq 'change_history' ) { #  || $view eq 'jumbo'      
212 <% include('cust_main/change_history.html', $cust_main ) %>      
213 % }
214
215 <% include('/elements/footer.html') %>
216 <%init>
217
218 my $curuser = $FS::CurrentUser::CurrentUser;
219
220 die "access denied"
221   unless $curuser->access_right('View customer');
222
223 my $conf = new FS::Conf;
224
225 my $custnum;
226 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
227   $custnum = $1;
228 } else {
229   die "No customer specified (bad URL)!" unless $cgi->keywords;
230   my($query) = $cgi->keywords; # needs parens with my, ->keywords returns array
231   $query =~ /^(\d+)$/;
232   $custnum = $1;
233 }
234
235 my $cust_main = qsearchs( {
236   'table'     => 'cust_main',
237   'hashref'   => { 'custnum' => $custnum },
238   'extra_sql' => ' AND '. $curuser->agentnums_sql,
239 });
240 die "Customer not found!" unless $cust_main;
241
242 #false laziness w/pref/pref.html and Conf.pm (cust_main-default_view)
243 tie my %views, 'Tie::IxHash',
244        'Basics'           => 'basics',
245        'Notes'            => 'notes', #notes and files?
246 ;
247 $views{'Tickets'}         =  'tickets'
248                                if $conf->config('ticket_system');
249 $views{'Packages'}        =  'packages';
250 $views{'Payment History'} =  'payment_history'
251                                unless $conf->config('payby-default' eq 'HIDE');
252 $views{'Change History'}  =  'change_history'
253   if $curuser->access_right('View customer history');
254 $views{'Jumbo'}           =  'jumbo';
255
256 my %viewname = reverse %views;
257
258 my $view =  $cgi->param('show') || $curuser->default_customer_view;
259
260 </%init>