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