Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / httemplate / view / cust_main.cgi
1 <& /elements/header.html, {
2              'title' => $title,
3              'head'  => $head,
4              'nobr'  => 1,
5           }
6 &>
7 <BR>
8 % my @part_tag = $cust_main->part_tag;
9 % if ( $conf->config('cust_tag-location') eq 'top' && @part_tag ) {
10 <TABLE STYLE="margin-bottom:8px" CELLSPACING=2>
11 %   foreach my $part_tag ( @part_tag ) {
12 <TR>
13   <TD>
14       <FONT SIZE="+1"
15             <% length($part_tag->tagcolor)
16                  ? 'STYLE="background-color:#'.$part_tag->tagcolor.'"'
17                  : ''
18       %>><% $part_tag->tagname.': '. $part_tag->tagdesc |h %></FONT>
19   </TD>
20 </TR>
21 %   }
22 </TABLE>
23 % }
24
25 <& /elements/menubar.html,
26              { 'newstyle' => 1,
27                'selected' => $viewname{$view},
28                'url_base' => $cgi->url. "?custnum=$custnum;show=",
29              },
30              %views,
31 &>
32 <DIV CLASS="fstabcontainer">
33
34 <& /elements/init_overlib.html &>
35
36 <SCRIPT TYPE="text/javascript">
37 function areyousure(href, message) {
38   if (confirm(message) == true)
39     window.location.href = href;
40 }
41 </SCRIPT>
42
43 % if ( $view eq 'basics' || $view eq 'jumbo' ) {
44
45 % if ( $curuser->access_right('Edit customer') ) { 
46   <A HREF="<% $p %>edit/cust_main.cgi?<% $custnum %>"><% mt('Edit this customer') |h %></A> | 
47 % } 
48
49 % if ( $curuser->access_right('Suspend customer')
50 %        && scalar($cust_main->unsuspended_pkgs)
51 %      ) {
52   <& /elements/popup_link-cust_main.html,
53               { 'action'      => $p. 'misc/suspend_cust.html',
54                 'label'       => emt('Suspend this customer'),
55                 'actionlabel' => emt('Confirm Suspension'),
56                 'color'       => '#ff9900',
57                 'cust_main'   => $cust_main,
58                 'width'       => 616, #make room for reasons
59                 'height'      => 366,
60               }
61   &> | 
62 % }
63
64 % if ( $curuser->access_right('Unsuspend customer')
65 %        && scalar($cust_main->suspended_pkgs)
66 %      ) {
67   <& /elements/popup_link-cust_main.html,
68               { 'action'      => $p. 'misc/unsuspend_cust.html',
69                 'label'       => emt('Unsuspend this customer'),
70                 'actionlabel' => emt('Confirm Unsuspension'),
71                 #'color'       => '#ff9900',
72                 'cust_main'   => $cust_main,
73                 #'width'       => 616, #make room for reasons
74                 #'height'      => 366,
75               }
76   &> | 
77 % }
78
79 % if ( $curuser->access_right('Cancel customer')
80 %        && scalar($cust_main->ncancelled_pkgs)
81 %      ) {
82   <& /elements/popup_link-cust_main.html,
83               { 'action'      => $p. 'misc/cancel_cust.html',
84                 'label'       => emt('Cancel this customer'),
85                 'actionlabel' => emt('Confirm Cancellation'),
86                 'color'       => '#ff0000',
87                 'cust_main'   => $cust_main,
88                 'width'       => 616, #make room for reasons
89                 'height'      => 366,
90               }
91   &> | 
92 % }
93
94 % if (     $curuser->access_right('Merge customer')
95 %      and (    scalar($cust_main->ncancelled_pkgs)
96 %            || $conf->exists('deletecustomers')
97 %          )
98 %    )
99 % {
100   <& /elements/popup_link-cust_main.html,
101               { 'action'      => $p. 'misc/merge_cust.html',
102                 'label'       => emt('Merge this customer'),
103                 'actionlabel' => emt('Merge customer'),
104                 'cust_main'   => $cust_main,
105                 'width'       => 569,
106                 'height'      => 210,
107               }
108   &> | 
109 % } 
110
111 % if ( $conf->exists('deletecustomers')
112 %        && $curuser->access_right('Delete customer')
113 %      ) {
114   <A HREF="<% $p %>misc/delete-customer.cgi?<% $custnum%>"><% mt('Delete this customer') |h %></A> | 
115 % } 
116
117 % unless ( $conf->exists('disable_customer_referrals') ) { 
118   <A HREF="<% $p %>edit/cust_main.cgi?referral_custnum=<% $custnum %>"><% mt('Refer a new customer') |h %></A> | 
119   <A HREF="<% $p %>search/cust_main.cgi?referral_custnum=<% $custnum %>"><% mt('View this customer\'s referrals') |h %></A>
120 % } 
121
122 <BR><BR>
123
124 % my $br = 0;
125 % if (    $curuser->access_right('Billing event reports') 
126 %      || $curuser->access_right('View customer billing events')
127 %    ) {
128 % $br=1;
129   <A HREF="<% $p %>search/cust_event.html?custnum=<% $custnum %>"><% mt('View billing events for this customer') |h %></A>
130 % }
131
132 % my $email_link = ($cust_main->invoicing_list_emailonly) && 
133 %   include('/elements/email-link.html',
134 %            'table' => 'cust_main', 
135 %            'search_hash' => { 'custnum' => $custnum },
136 %            'label' => 'Email a notice to this customer',
137 % );
138 % if ( $email_link and $br ) {
139  | 
140 % }
141 <% $email_link || '' %>
142
143 % if ( $conf->config('cust_main-external_links') ) {
144     <% $br++ ? ' | ' : '' %>
145 %   my @links = split(/\n/, $conf->config('cust_main-external_links'));
146 %   foreach my $link (@links) {
147 %     $link =~ /^\s*(\S+)\s+(.*?)(\s*\(([^\)]*)\))?$/ or next;
148 %     my($url, $label, $alt) = ($1, $2, $4);
149       <A HREF="<% $url.$custnum %>" ALT="<% $alt |h %>"><% $label |h %></A>
150 %   }
151 % }
152
153 % if ( $br ) {
154   <BR><BR>
155 % }
156 </%doc>
157
158 %my $signupurl = $conf->config('signupurl');
159 %if ( $signupurl ) {
160   <% mt('This customer\'s signup URL:') |h %>
161   <A HREF="<% $signupurl %>?ref=<% $custnum %>"><% $signupurl %>?ref=<% $custnum %></A>
162   <BR><BR>
163 % } 
164
165 %if ( $conf->exists('maestro-status_test') ) {
166   <A HREF="<% $p %>misc/maestro-customer_status-test.html?<% $custnum %>"><% mt('Test maestro status') |h %></A>
167   <BR><BR>
168 % } 
169
170 <A NAME="cust_main"></A>
171 <TABLE BORDER=0>
172 <TR>
173   <TD VALIGN="top">
174     <& cust_main/contacts.html, $cust_main &>
175   </TD>
176   <TD VALIGN="top" STYLE="padding-left: 54px">
177     <& cust_main/misc.html, $cust_main &>
178 % if ( $conf->config('payby-default') ne 'HIDE' ) { 
179       <BR><& cust_main/billing.html, $cust_main &>
180 % } 
181
182   </TD>
183 </TR>
184 <TR>
185   <TD COLSPAN = 2>
186     <& cust_main/contacts_new.html, $cust_main &>
187   </TD>
188 </TR>
189 </TABLE>
190
191 % }
192
193 % if ( $view eq 'notes' || $view eq 'jumbo' ) {
194
195 %if ( $cust_main->comments =~ /[^\s\n\r]/ ) {
196 <BR><% mt('Comments') |h %> 
197 <% ntable("#cccccc") %><TR><TD><% ntable("#cccccc",2) %>
198 <TR>
199   <TD BGCOLOR="#ffffff">
200     <PRE><% encode_entities($cust_main->comments) %></PRE>
201   </TD>
202 </TR>
203 </TABLE></TABLE>
204 <BR><BR>
205 % }
206 <A NAME="notes">
207 % my $notecount = scalar($cust_main->notes(0));
208 % if ( ! $conf->exists('cust_main-disable_notes') || $notecount) {
209
210 %   unless ( $view eq 'notes' && $cust_main->comments !~ /[^\s\n\r]/ ) {
211       <BR>
212       <A NAME="cust_main_note"><FONT SIZE="+2"><% mt('Notes') |h %></FONT></A><BR>
213 %   }
214
215 %   if ( $curuser->access_right('Add customer note') &&
216 %        ! $conf->exists('cust_main-disable_notes')
217 %      ) {
218
219   <& /elements/popup_link-cust_main.html,
220                 'label'       => emt('Add customer note'),
221                 'action'      => $p. 'edit/cust_main_note.cgi',
222                 'actionlabel' => emt('Enter customer note'),
223                 'cust_main'   => $cust_main,
224                 'width'       => 616,
225                 'height'      => 538, #575
226   &>
227
228 %   }
229
230 <BR>
231
232 <& cust_main/notes.html, 'custnum' => $cust_main->custnum &>
233
234 % }
235 <BR>
236
237 % if(! $conf->config('disable_cust_attachment') 
238 %  and $curuser->access_right('Add attachment')) {
239 <& /elements/popup_link-cust_main.html,
240               'label'       => emt('Attach file'),
241               'action'      => $p.'edit/cust_main_attach.cgi',
242               'actionlabel' => emt('Upload file'),
243               'cust_main'   => $cust_main,
244               'width'       => 480,
245               'height'      => 296,
246 &>
247 % }
248 % if( $curuser->access_right('View attachments') ) {
249 <& cust_main/attachments.html, 'custnum' => $cust_main->custnum &>
250 %   if ($cgi->param('show_deleted')) {
251 <A HREF="<% $p.'view/cust_main.cgi?custnum=' . $cust_main->custnum .
252            ($view ? ";show=$view" : '') . '#notes' 
253            %>"><I>(<% mt('Show active attachments') |h %>)</I></A>
254 %   }
255 % elsif($curuser->access_right('View deleted attachments')) {
256 <A HREF="<% $p.'view/cust_main.cgi?custnum=' . $cust_main->custnum .
257            ($view ? ";show=$view" : '') . ';show_deleted=1#notes'
258            %>"><I>(<% mt('Show deleted attachments') |h %>)</I></A>
259 %   }
260 % }
261 <BR>
262
263 % }
264
265 % if ( $view eq 'jumbo' ) {
266     <BR>
267 % }
268 <BR>
269
270 % if ( $view eq 'tickets' || $view eq 'jumbo' ) {
271
272 % if ( $conf->config('ticket_system') ) { 
273   <& cust_main/tickets.html, $cust_main &>
274 % } 
275   <BR><BR>
276
277 % }
278
279 % if ( $view eq 'jumbo' ) { #XXX enable me && $curuser->access_right('View customer packages') { 
280
281   <A NAME="cust_pkg"><FONT SIZE="+2"><% mt('Packages') |h %></FONT></A><BR>
282 % }
283
284 % if ( $view eq 'packages' || $view eq 'jumbo' ) {
285
286 % #XXX enable me# if ( $curuser->access_right('View customer packages') { 
287 <& cust_main/packages.html, $cust_main &>
288 % #}
289
290 % }
291
292 % if ( $view eq 'jumbo' ) {
293     <BR><BR>
294     <A NAME="history"><FONT SIZE="+2"><% mt('Payment History') |h %></FONT></A>
295     <BR>
296 % }
297
298 % if ( $view eq 'payment_history' || $view eq 'jumbo' ) {
299
300 % if ( $conf->config('payby-default') ne 'HIDE' ) { 
301   <& cust_main/payment_history.html, $cust_main &>
302 % } 
303
304 % }
305
306 % if ( $view eq 'change_history' ) { #  || $view eq 'jumbo'      
307 <& cust_main/change_history.html, $cust_main &>          
308 % }
309
310 % if ( $view eq 'custom' ) { 
311 %   if ( $conf->config('cust_main-custom_link') ) {
312 <& cust_main/custom.html, $cust_main &>
313 %   } elsif ( $conf->config('cust_main-custom_content') ) {
314       <& cust_main/custom_content.html, $cust_main &>
315 %   #} else {
316 %   #  warn "custom view without cust_main-custom_link or -custom_content?";
317 %   }
318 % }
319
320 </DIV>
321 <& /elements/footer.html &>
322 <%init>
323
324 my $curuser = $FS::CurrentUser::CurrentUser;
325
326 die "access denied"
327   unless $curuser->access_right('View customer');
328
329 my $conf = new FS::Conf;
330
331 my $custnum;
332 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
333   $custnum = $1;
334 } else {
335   die "No customer specified (bad URL)!" unless $cgi->keywords;
336   my($query) = $cgi->keywords; # needs parens with my, ->keywords returns array
337   $query =~ /^(\d+)$/;
338   $custnum = $1;
339 }
340
341 my $cust_main = qsearchs( {
342   'table'     => 'cust_main',
343   'hashref'   => { 'custnum' => $custnum },
344   'extra_sql' => ' AND '. $curuser->agentnums_sql,
345 });
346 die "Customer not found!" unless $cust_main;
347
348 my $title = $cust_main->name;
349 $title = '('. $cust_main->display_custnum. ") $title"
350   if $conf->exists('cust_main-title-display_custnum');
351 $title = mt("Customer:")." ".$title;
352
353 #false laziness w/pref/pref.html and Conf.pm (cust_main-default_view)
354 tie my %views, 'Tie::IxHash',
355        emt('Basics')       => 'basics',
356        emt('Notes')        => 'notes', #notes and files?
357 ;
358 $views{emt('Tickets')}     =  'tickets'
359                                if $conf->config('ticket_system');
360 $views{emt('Packages')}    =  'packages';
361 $views{emt('Payment History')} =  'payment_history'
362                                unless $conf->config('payby-default' eq 'HIDE');
363 $views{emt('Change History')}  =  'change_history'
364   if $curuser->access_right('View customer history');
365 $views{$conf->config('cust_main-custom_title') || emt('Custom')} =  'custom'
366   if $conf->config('cust_main-custom_link')
367   || $conf->config('cust_main-custom_content');
368 $views{emt('Jumbo')}           =  'jumbo';
369
370 my %viewname = reverse %views;
371
372 my $view =  $cgi->param('show') || $curuser->default_customer_view;
373
374 my $ie_compat = $conf->config('ie-compatibility_mode');
375 my $head = '';
376 if ( $ie_compat ) {
377   $head = qq(<meta http-equiv="X-UA-Compatible" content="IE=$ie_compat" />);
378 }
379
380 </%init>