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
44 % ###
45 % # Basics
46 % ###
47
48 % if ( $view eq 'basics' || $view eq 'jumbo' ) {
49
50 % if ( $curuser->access_right('Edit customer') ) { 
51   <A HREF="<% $p %>edit/cust_main.cgi?<% $custnum %>"><% mt('Edit this customer') |h %></A> | 
52 % } 
53
54 % if ( $curuser->access_right('Suspend customer')
55 %        && scalar($cust_main->unsuspended_pkgs)
56 %      ) {
57   <& /elements/popup_link-cust_main.html,
58               { 'action'      => $p. 'misc/suspend_cust.html',
59                 'label'       => emt('Suspend this customer'),
60                 'actionlabel' => emt('Confirm Suspension'),
61                 'color'       => '#ff9900',
62                 'cust_main'   => $cust_main,
63                 'width'       => 768, #make room for reasons
64                 'height'      => 450, 
65               }
66   &> | 
67 % }
68
69 % if ( $curuser->access_right('Unsuspend customer')
70 %        && scalar($cust_main->suspended_pkgs)
71 %      ) {
72   <& /elements/popup_link-cust_main.html,
73               { 'action'      => $p. 'misc/unsuspend_cust.html',
74                 'label'       => emt('Unsuspend this customer'),
75                 'actionlabel' => emt('Confirm Unsuspension'),
76                 #'color'       => '#ff9900',
77                 'cust_main'   => $cust_main,
78                 #'width'       => 616, #make room for reasons
79                 #'height'      => 366,
80               }
81   &> | 
82 % }
83
84 % if ( $curuser->access_right('Cancel customer')
85 %        && scalar($cust_main->ncancelled_pkgs)
86 %      ) {
87   <& /elements/popup_link-cust_main.html,
88               { 'action'      => $p. 'misc/cancel_cust.html',
89                 'label'       => emt('Cancel this customer'),
90                 'actionlabel' => emt('Confirm Cancellation'),
91                 'color'       => '#ff0000',
92                 'cust_main'   => $cust_main,
93                 'width'       => 616, #make room for reasons
94                 'height'      => 410,
95               }
96   &> | 
97 % }
98
99 % if (     $curuser->access_right('Merge customer')
100 %      and (    scalar($cust_main->ncancelled_pkgs)
101 %            # || we start supporting payment info merge again in some way
102 %          )
103 %    )
104 % {
105   <& /elements/popup_link-cust_main.html,
106               { 'action'      => $p. 'misc/merge_cust.html',
107                 'label'       => emt('Merge this customer'),
108                 'actionlabel' => emt('Merge customer'),
109                 'cust_main'   => $cust_main,
110                 'width'       => 569,
111                 'height'      => 210,
112               }
113   &> | 
114 % } 
115
116 % unless ( $conf->exists('disable_customer_referrals') ) { 
117   <A HREF="<% $p %>edit/cust_main.cgi?referral_custnum=<% $custnum %>"><% mt('Refer a new customer') |h %></A> | 
118   <A HREF="<% $p %>search/cust_main.cgi?referral_custnum=<% $custnum %>"><% mt('View this customer\'s referrals') |h %></A>
119 % } 
120
121 <BR><BR>
122
123 % my $br = 0;
124 % if (    $curuser->access_right('Billing event reports') 
125 %      || $curuser->access_right('View customer billing events')
126 %    ) {
127 % $br=1;
128   <A HREF="<% $p %>search/cust_event.html?custnum=<% $custnum %>"><% mt('View billing events for this customer') |h %></A>
129 % }
130
131 % my $email_link = ($cust_main->invoicing_list_emailonly) && 
132 %   include('/elements/email-link.html',
133 %            'table'               => 'cust_main', 
134 %            'search_hash'         => { 'custnum' => $custnum },
135 %            'agent_virt_agentnum' => $cust_main->agentnum,
136 %            'label'               => 'Email a notice to this customer',
137 % );
138 % if ( $email_link and $br ) {
139  | 
140 % }
141 <% $email_link || '' %>
142
143 % if ( $curuser->access_right('Order customer package') && $conf->exists('cust_main-enable_order_package') ) {
144   | <& /elements/order_pkg_link.html, 'cust_main'=>$cust_main &>
145 % }
146
147 % if ( $conf->config('cust_main-external_links') ) {
148     <% $br++ ? ' | ' : '' %>
149 %   my @links = split(/\n/, $conf->config('cust_main-external_links'));
150 %   foreach my $link (@links) {
151 %     $link =~ /^\s*(\S+)\s+(.*?)(\s*\(([^\)]*)\))?$/ or next;
152 %     my($url, $label, $alt) = ($1, $2, $4);
153       <A HREF="<% $url.$custnum %>" ALT="<% $alt |h %>"><% $label |h %></A>
154 %   }
155 % }
156
157 % if ( $br ) {
158   <BR><BR>
159 % }
160
161 %my $signupurl = $conf->config('signupurl');
162 %if ( $signupurl ) {
163   <% mt('This customer\'s signup URL:') |h %>
164   <A HREF="<% $signupurl %>?ref=<% $custnum %>"><% $signupurl %>?ref=<% $custnum %></A>
165   <BR><BR>
166 % } 
167
168 <A NAME="cust_main"></A>
169 <TABLE BORDER=0>
170 <TR>
171   <TD VALIGN="top">
172     <& cust_main/contacts.html, $cust_main &>
173   </TD>
174   <TD VALIGN="top" STYLE="padding-left: 54px">
175     <& cust_main/misc.html, $cust_main &>
176 % if ( $conf->config('payby-default') ne 'HIDE' ) { 
177       <BR><& cust_main/billing.html, $cust_main &>
178 % } 
179
180   </TD>
181 </TR>
182 <TR>
183   <TD COLSPAN = 2>
184     <& cust_main/contacts_new.html, $cust_main &>
185   </TD>
186 </TR>
187 </TABLE>
188
189 % }
190
191
192 % ###
193 % # Notes
194 % ###
195
196 % if ( $view eq 'notes' || $view eq 'jumbo' ) {
197
198 <& cust_main/notes.html, 'cust_main' => $cust_main &>
199
200 % }
201
202 % if ( $view eq 'jumbo' ) {
203     <BR>
204 % }
205
206 <BR>
207
208
209 % ###
210 % # Tickets
211 % ###
212
213 % if ( $view eq 'tickets' || $view eq 'jumbo' ) {
214
215 % if ( $conf->config('ticket_system') ) { 
216   <& cust_main/tickets.html, $cust_main &>
217 % } 
218   <BR><BR>
219
220 % }
221
222 % ###
223 % # Appointments
224 % ###
225
226 % if ( $view eq 'appointments' || $view eq 'jumbo' ) {
227
228 % if ( $conf->config('ticket_system')
229 %        && $curuser->access_right('View appointments') ) { 
230   <& cust_main/appointments.html, $cust_main &>
231 % } 
232   <BR><BR>
233
234 % }
235
236
237 % ###
238 % # Quotations
239 % ###
240
241 % if ( $view eq 'jumbo' && $curuser->access_right('Generate quotation') ) { 
242   <A NAME="quotation"><FONT SIZE="+2"><% mt('Quotations') |h %></FONT></A><BR>
243 % }
244
245 % if ( $view eq 'quotations' || $view eq 'jumbo' ) {
246
247 %   if ( $curuser->access_right('Generate quotation') ) { 
248       <& cust_main/quotations.html, $cust_main &>
249 %   }
250
251 % }
252
253
254 % ###
255 % # Packages
256 % ###
257
258 % if ( $view eq 'jumbo' ) { #XXX enable me && $curuser->access_right('View customer packages') { 
259
260   <A NAME="cust_pkg"><FONT SIZE="+2"><% mt('Packages') |h %></FONT></A><BR>
261 % }
262
263 % if ( $view eq 'packages' || $view eq 'jumbo' ) {
264
265 % #XXX enable me# if ( $curuser->access_right('View customer packages') { 
266 <& cust_main/packages.html, $cust_main &>
267 % #}
268
269 % }
270
271
272 % ###
273 % # Payment History
274 % ###
275
276 % if ( $view eq 'jumbo' ) {
277     <BR><BR>
278     <A NAME="history"><FONT SIZE="+2"><% mt('Payment History') |h %></FONT></A>
279     <BR>
280 % }
281
282 % if ( $view eq 'payment_history' || $view eq 'jumbo' ) {
283
284 % if ( $conf->config('payby-default') ne 'HIDE' ) { 
285   <& cust_main/payment_history.html, $cust_main &>
286 % } 
287
288 % }
289
290
291 % ###
292 % # Change History
293 % ###
294
295 % if ( $view eq 'change_history' ) { #  || $view eq 'jumbo'      
296 <& cust_main/change_history.html, $cust_main &>          
297 % }
298
299 % if ( $view eq 'custom' ) { 
300 %   if ( $conf->config('cust_main-custom_link') ) {
301 <& cust_main/custom.html, $cust_main &>
302 %   } elsif ( $conf->config('cust_main-custom_content') ) {
303       <& cust_main/custom_content.html, $cust_main &>
304 %   #} else {
305 %   #  warn "custom view without cust_main-custom_link or -custom_content?";
306 %   }
307 % }
308
309 </DIV>
310 <& /elements/footer.html &>
311 <%init>
312
313 my $curuser = $FS::CurrentUser::CurrentUser;
314
315 die "access denied"
316   unless $curuser->access_right('View customer');
317
318 my $conf = new FS::Conf;
319
320 my $custnum;
321 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
322   $custnum = $1;
323 } else {
324   die "No customer specified (bad URL)!" unless $cgi->keywords;
325   my($query) = $cgi->keywords; # needs parens with my, ->keywords returns array
326   $query =~ /^(\d+)$/;
327   $custnum = $1;
328   $cgi->param('custnum', $1);
329 }
330
331 my $cust_main = qsearchs( {
332   'table'     => 'cust_main',
333   'hashref'   => { 'custnum' => $custnum },
334   'extra_sql' => ' AND '. $curuser->agentnums_sql,
335 });
336 die "Customer not found!" unless $cust_main;
337
338 my $title = $cust_main->name;
339 $title = '('. $cust_main->display_custnum. ") $title"
340   if $conf->exists('cust_main-title-display_custnum');
341 $title = mt("Customer:")." ".$title;
342
343 #false laziness w/pref/pref.html and Conf.pm (cust_main-default_view)
344 tie my %views, 'Tie::IxHash',
345        emt('Basics')           => 'basics',
346        emt('Notes')            => 'notes', #notes and files?
347 ;
348 if ( $conf->config('ticket_system') ) {
349   $views{emt('Tickets')}       =  'tickets';
350   $views{emt('Appointments')}  =  'appointments'
351     if $curuser->access_right('View appointments');
352 }
353 $views{emt('Quotations')}      =  'quotations';
354 $views{emt('Packages')}        =  'packages';
355 $views{emt('Payment History')} =  'payment_history'
356                                unless $conf->config('payby-default' eq 'HIDE');
357 $views{emt('Change History')}  =  'change_history'
358   if $curuser->access_right('View customer history');
359 $views{$conf->config('cust_main-custom_title') || emt('Custom')} =  'custom'
360   if $conf->config('cust_main-custom_link')
361   || $conf->config('cust_main-custom_content');
362 $views{emt('Jumbo')}           =  'jumbo';
363
364 my %viewname = reverse %views;
365
366 my $view =  $cgi->param('show') || $curuser->default_customer_view;
367
368 my $ie_compat = $conf->config('ie-compatibility_mode');
369 my $head = '';
370 if ( $ie_compat ) {
371   $head = qq(<meta http-equiv="X-UA-Compatible" content="IE=$ie_compat" />);
372 }
373
374 </%init>