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/misc.html, $cust_main &>
173     <BR><& cust_main/contacts.html, $cust_main &>
174   </TD>
175   <TD VALIGN="top" STYLE="padding-left: 54px">
176     <& cust_main/billing.html, $cust_main &>
177     <BR><& cust_main/cust_payby.html, $cust_main &>
178   </TD>
179 </TR>
180 <TR>
181   <TD COLSPAN = 2>
182     <& cust_main/contacts_new.html, $cust_main &>
183   </TD>
184 </TR>
185 </TABLE>
186
187 % }
188
189
190 % ###
191 % # Notes
192 % ###
193
194 % if ( $view eq 'notes' || $view eq 'jumbo' ) {
195
196 <& cust_main/notes.html, 'cust_main' => $cust_main &>
197
198 % }
199
200 % if ( $view eq 'jumbo' ) {
201     <BR>
202 % }
203
204 <BR>
205
206
207 % ###
208 % # Tickets
209 % ###
210
211 % if ( $view eq 'tickets' || $view eq 'jumbo' ) {
212
213 % if ( $conf->config('ticket_system') ) { 
214   <& cust_main/tickets.html, $cust_main &>
215 % } 
216   <BR><BR>
217
218 % }
219
220 % ###
221 % # Appointments
222 % ###
223
224 % if ( $view eq 'appointments' || $view eq 'jumbo' ) {
225
226 % if ( $conf->config('ticket_system')
227 %        && $curuser->access_right('View appointments') ) { 
228   <& cust_main/appointments.html, $cust_main &>
229 % } 
230   <BR><BR>
231
232 % }
233
234
235 % ###
236 % # Quotations
237 % ###
238
239 % if ( $view eq 'jumbo' && $curuser->access_right('Generate quotation') ) { 
240   <A NAME="quotations"><FONT SIZE="+2"><% mt('Quotations') |h %></FONT></A><BR>
241 % }
242
243 % if ( $view eq 'quotations' || $view eq 'jumbo' ) {
244
245 %   if ( $curuser->access_right('Generate quotation') ) { 
246       <& cust_main/quotations.html, $cust_main &>
247 %   }
248
249 % }
250
251
252 % ###
253 % # Packages
254 % ###
255
256 % if ( $view eq 'jumbo' ) { #XXX enable me && $curuser->access_right('View customer packages') { 
257
258   <A NAME="cust_pkg"><FONT SIZE="+2"><% mt('Packages') |h %></FONT></A><BR>
259 % }
260
261 % if ( $view eq 'packages' || $view eq 'jumbo' ) {
262
263 % #XXX enable me# if ( $curuser->access_right('View customer packages') { 
264 <& cust_main/packages.html, $cust_main &>
265 % #}
266
267 % }
268
269
270 % ###
271 % # Payment History
272 % ###
273
274 % if ( $view eq 'jumbo' ) {
275     <BR><BR>
276     <A NAME="history"><FONT SIZE="+2"><% mt('Payment History') |h %></FONT></A>
277     <BR>
278 % }
279
280 % if ( $view eq 'payment_history' || $view eq 'jumbo' ) {
281
282 <& cust_main/payment_history.html, $cust_main &>
283
284 % }
285
286
287 % ###
288 % # Change History
289 % ###
290
291 % if ( $view eq 'change_history' ) { #  || $view eq 'jumbo'      
292 <& cust_main/change_history.html, $cust_main &>          
293 % }
294
295 % if ( $view eq 'custom' ) { 
296 %   if ( $conf->config('cust_main-custom_link') ) {
297 <& cust_main/custom.html, $cust_main &>
298 %   } elsif ( $conf->config('cust_main-custom_content') ) {
299       <& cust_main/custom_content.html, $cust_main &>
300 %   #} else {
301 %   #  warn "custom view without cust_main-custom_link or -custom_content?";
302 %   }
303 % }
304
305 </DIV>
306 <& /elements/footer.html &>
307 <%init>
308
309 my $curuser = $FS::CurrentUser::CurrentUser;
310
311 die "access denied"
312   unless $curuser->access_right('View customer');
313
314 my $conf = new FS::Conf;
315
316 my $custnum;
317 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
318   $custnum = $1;
319 } else {
320   die "No customer specified (bad URL)!" unless $cgi->keywords;
321   my($query) = $cgi->keywords; # needs parens with my, ->keywords returns array
322   $query =~ /^(\d+)$/;
323   $custnum = $1;
324   $cgi->param('custnum', $1);
325 }
326
327 my $cust_main = qsearchs( {
328   'table'     => 'cust_main',
329   'hashref'   => { 'custnum' => $custnum },
330   'extra_sql' => ' AND '. $curuser->agentnums_sql,
331 });
332 die "Customer not found!" unless $cust_main;
333
334 my $title = $cust_main->name;
335 $title = '('. $cust_main->display_custnum. ") $title"
336   if $conf->exists('cust_main-title-display_custnum');
337 $title = mt("Customer:")." ".$title;
338
339 #false laziness w/pref/pref.html and Conf.pm (cust_main-default_view)
340 tie my %views, 'Tie::IxHash',
341        emt('Basics')           => 'basics',
342        emt('Notes')            => 'notes', #notes and files?
343 ;
344 if ( $conf->config('ticket_system') ) {
345   $views{emt('Tickets')}       =  'tickets';
346   $views{emt('Appointments')}  =  'appointments'
347     if $curuser->access_right('View appointments');
348 }
349 $views{emt('Quotations')}      =  'quotations';
350 $views{emt('Packages')}        =  'packages';
351 $views{emt('Payment History')} =  'payment_history';
352 $views{emt('Change History')}  =  'change_history'
353   if $curuser->access_right('View customer history');
354 $views{$conf->config('cust_main-custom_title') || emt('Custom')} =  'custom'
355   if $conf->config('cust_main-custom_link')
356   || $conf->config('cust_main-custom_content');
357 $views{emt('Jumbo')}           =  'jumbo';
358
359 my %viewname = reverse %views;
360
361 my $view =  $cgi->param('show') || $curuser->default_customer_view;
362
363 my $ie_compat = $conf->config('ie-compatibility_mode');
364 my $head = '';
365 if ( $ie_compat ) {
366   $head = qq(<meta http-equiv="X-UA-Compatible" content="IE=$ie_compat" />);
367 }
368
369 </%init>