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 %            # || we start supporting payment info merge again in some way
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 % unless ( $conf->exists('disable_customer_referrals') ) { 
112   <A HREF="<% $p %>edit/cust_main.cgi?referral_custnum=<% $custnum %>"><% mt('Refer a new customer') |h %></A> | 
113   <A HREF="<% $p %>search/cust_main.cgi?referral_custnum=<% $custnum %>"><% mt('View this customer\'s referrals') |h %></A>
114 % } 
115
116 <BR><BR>
117
118 % my $br = 0;
119 % if (    $curuser->access_right('Billing event reports') 
120 %      || $curuser->access_right('View customer billing events')
121 %    ) {
122 % $br=1;
123   <A HREF="<% $p %>search/cust_event.html?custnum=<% $custnum %>"><% mt('View billing events for this customer') |h %></A>
124 % }
125
126 % my $email_link = ($cust_main->invoicing_list_emailonly) && 
127 %   include('/elements/email-link.html',
128 %            'table' => 'cust_main', 
129 %            'search_hash' => { 'custnum' => $custnum },
130 %            'label' => 'Email a notice to this customer',
131 % );
132 % if ( $email_link and $br ) {
133  | 
134 % }
135 <% $email_link || '' %>
136
137 % if ( $conf->config('cust_main-external_links') ) {
138     <% $br++ ? ' | ' : '' %>
139 %   my @links = split(/\n/, $conf->config('cust_main-external_links'));
140 %   foreach my $link (@links) {
141 %     $link =~ /^\s*(\S+)\s+(.*?)(\s*\(([^\)]*)\))?$/ or next;
142 %     my($url, $label, $alt) = ($1, $2, $4);
143       <A HREF="<% $url.$custnum %>" ALT="<% $alt |h %>"><% $label |h %></A>
144 %   }
145 % }
146
147 % if ( $br ) {
148   <BR><BR>
149 % }
150
151 %my $signupurl = $conf->config('signupurl');
152 %if ( $signupurl ) {
153   <% mt('This customer\'s signup URL:') |h %>
154   <A HREF="<% $signupurl %>?ref=<% $custnum %>"><% $signupurl %>?ref=<% $custnum %></A>
155   <BR><BR>
156 % } 
157
158 <A NAME="cust_main"></A>
159 <TABLE BORDER=0>
160 <TR>
161   <TD VALIGN="top">
162     <& cust_main/contacts.html, $cust_main &>
163   </TD>
164   <TD VALIGN="top" STYLE="padding-left: 54px">
165     <& cust_main/misc.html, $cust_main &>
166 % if ( $conf->config('payby-default') ne 'HIDE' ) { 
167       <BR><& cust_main/billing.html, $cust_main &>
168 % } 
169
170   </TD>
171 </TR>
172 <TR>
173   <TD COLSPAN = 2>
174     <& cust_main/contacts_new.html, $cust_main &>
175   </TD>
176 </TR>
177 </TABLE>
178
179 % }
180
181 % if ( $view eq 'notes' || $view eq 'jumbo' ) {
182
183 %if ( $cust_main->comments =~ /[^\s\n\r]/ ) {
184 <BR><% mt('Comments') |h %> 
185 <% ntable("#cccccc") %><TR><TD><% ntable("#cccccc",2) %>
186 <TR>
187   <TD BGCOLOR="#ffffff">
188     <PRE><% encode_entities($cust_main->comments) %></PRE>
189   </TD>
190 </TR>
191 </TABLE></TABLE>
192 <BR><BR>
193 % }
194 <A NAME="notes">
195 % my $notecount = scalar($cust_main->notes(0));
196 % if ( ! $conf->exists('cust_main-disable_notes') || $notecount) {
197
198 %   unless ( $view eq 'notes' && $cust_main->comments !~ /[^\s\n\r]/ ) {
199       <BR>
200       <A NAME="cust_main_note"><FONT SIZE="+2"><% mt('Notes') |h %></FONT></A><BR>
201 %   }
202
203 %   if ( $curuser->access_right('Add customer note') &&
204 %        ! $conf->exists('cust_main-disable_notes')
205 %      ) {
206
207   <& /elements/popup_link-cust_main.html,
208                 'label'       => emt('Add customer note'),
209                 'action'      => $p. 'edit/cust_main_note.cgi',
210                 'actionlabel' => emt('Enter customer note'),
211                 'cust_main'   => $cust_main,
212                 'width'       => 616,
213                 'height'      => 538, #575
214   &>
215
216 %   }
217
218 <BR>
219
220 <& cust_main/notes.html, 'custnum' => $cust_main->custnum &>
221
222 % }
223 <BR>
224
225 % if(! $conf->config('disable_cust_attachment') 
226 %  and $curuser->access_right('Add attachment')) {
227 <& /elements/popup_link-cust_main.html,
228               'label'       => emt('Attach file'),
229               'action'      => $p.'edit/cust_main_attach.cgi',
230               'actionlabel' => emt('Upload file'),
231               'cust_main'   => $cust_main,
232               'width'       => 480,
233               'height'      => 296,
234 &>
235 % }
236 % if( $curuser->access_right('View attachments') ) {
237 <& cust_main/attachments.html, 'custnum' => $cust_main->custnum &>
238 %   if ($cgi->param('show_deleted')) {
239 <A HREF="<% $p.'view/cust_main.cgi?custnum=' . $cust_main->custnum .
240            ($view ? ";show=$view" : '') . '#notes' 
241            %>"><I>(<% mt('Show active attachments') |h %>)</I></A>
242 %   }
243 % elsif($curuser->access_right('View deleted attachments')) {
244 <A HREF="<% $p.'view/cust_main.cgi?custnum=' . $cust_main->custnum .
245            ($view ? ";show=$view" : '') . ';show_deleted=1#notes'
246            %>"><I>(<% mt('Show deleted attachments') |h %>)</I></A>
247 %   }
248 % }
249 <BR>
250
251 % }
252
253 % if ( $view eq 'jumbo' ) {
254     <BR>
255 % }
256 <BR>
257
258 % if ( $view eq 'tickets' || $view eq 'jumbo' ) {
259
260 % if ( $conf->config('ticket_system') ) { 
261   <& cust_main/tickets.html, $cust_main &>
262 % } 
263   <BR><BR>
264
265 % }
266
267 % if ( $view eq 'jumbo' ) { #XXX enable me && $curuser->access_right('View customer packages') { 
268
269   <A NAME="cust_pkg"><FONT SIZE="+2"><% mt('Packages') |h %></FONT></A><BR>
270 % }
271
272 % if ( $view eq 'packages' || $view eq 'jumbo' ) {
273
274 % #XXX enable me# if ( $curuser->access_right('View customer packages') { 
275 <& cust_main/packages.html, $cust_main &>
276 % #}
277
278 % }
279
280 % if ( $view eq 'jumbo' ) {
281     <BR><BR>
282     <A NAME="history"><FONT SIZE="+2"><% mt('Payment History') |h %></FONT></A>
283     <BR>
284 % }
285
286 % if ( $view eq 'payment_history' || $view eq 'jumbo' ) {
287
288 % if ( $conf->config('payby-default') ne 'HIDE' ) { 
289   <& cust_main/payment_history.html, $cust_main &>
290 % } 
291
292 % }
293
294 % if ( $view eq 'change_history' ) { #  || $view eq 'jumbo'      
295 <& cust_main/change_history.html, $cust_main &>          
296 % }
297
298 % if ( $view eq 'custom' ) { 
299 %   if ( $conf->config('cust_main-custom_link') ) {
300 <& cust_main/custom.html, $cust_main &>
301 %   } elsif ( $conf->config('cust_main-custom_content') ) {
302       <& cust_main/custom_content.html, $cust_main &>
303 %   #} else {
304 %   #  warn "custom view without cust_main-custom_link or -custom_content?";
305 %   }
306 % }
307
308 </DIV>
309 <& /elements/footer.html &>
310 <%init>
311
312 my $curuser = $FS::CurrentUser::CurrentUser;
313
314 die "access denied"
315   unless $curuser->access_right('View customer');
316
317 my $conf = new FS::Conf;
318
319 my $custnum;
320 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
321   $custnum = $1;
322 } else {
323   die "No customer specified (bad URL)!" unless $cgi->keywords;
324   my($query) = $cgi->keywords; # needs parens with my, ->keywords returns array
325   $query =~ /^(\d+)$/;
326   $custnum = $1;
327 }
328
329 my $cust_main = qsearchs( {
330   'table'     => 'cust_main',
331   'hashref'   => { 'custnum' => $custnum },
332   'extra_sql' => ' AND '. $curuser->agentnums_sql,
333 });
334 die "Customer not found!" unless $cust_main;
335
336 my $title = $cust_main->name;
337 $title = '('. $cust_main->display_custnum. ") $title"
338   if $conf->exists('cust_main-title-display_custnum');
339 $title = mt("Customer:")." ".$title;
340
341 #false laziness w/pref/pref.html and Conf.pm (cust_main-default_view)
342 tie my %views, 'Tie::IxHash',
343        emt('Basics')       => 'basics',
344        emt('Notes')        => 'notes', #notes and files?
345 ;
346 $views{emt('Tickets')}     =  'tickets'
347                                if $conf->config('ticket_system');
348 $views{emt('Packages')}    =  'packages';
349 $views{emt('Payment History')} =  'payment_history'
350                                unless $conf->config('payby-default' eq 'HIDE');
351 $views{emt('Change History')}  =  'change_history'
352   if $curuser->access_right('View customer history');
353 $views{$conf->config('cust_main-custom_title') || emt('Custom')} =  'custom'
354   if $conf->config('cust_main-custom_link')
355   || $conf->config('cust_main-custom_content');
356 $views{emt('Jumbo')}           =  'jumbo';
357
358 my %viewname = reverse %views;
359
360 my $view =  $cgi->param('show') || $curuser->default_customer_view;
361
362 my $ie_compat = $conf->config('ie-compatibility_mode');
363 my $head = '';
364 if ( $ie_compat ) {
365   $head = qq(<meta http-equiv="X-UA-Compatible" content="IE=$ie_compat" />);
366 }
367
368 </%init>