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              'title_noescape' => $title_noescape,
4              'head'  => $head,
5              'nobr'  => 1,
6           }
7 &>
8
9 % my @part_tag = $cust_main->part_tag;
10 % if ( $conf->config('cust_tag-location') eq 'top' && @part_tag ) {
11 <TABLE STYLE="margin-bottom:8px" CELLSPACING=2>
12 %   foreach my $part_tag ( @part_tag ) {
13 <TR>
14   <TD>
15       <FONT SIZE="+1"
16             <% length($part_tag->tagcolor)
17                  ? 'STYLE="background-color:#'.$part_tag->tagcolor.'"'
18                  : ''
19       %>><% $part_tag->tagname.': '. $part_tag->tagdesc |h %></FONT>
20   </TD>
21 </TR>
22 %   }
23 </TABLE>
24 % }
25
26 <& cust_main/menu.html, cust_main => $cust_main, show => $view &>
27 <BR>
28
29 <DIV CLASS="fstabcontainer">
30
31 <& /elements/init_overlib.html &>
32
33 <SCRIPT TYPE="text/javascript">
34 function areyousure(href, message) {
35   if (confirm(message) == true)
36     window.location.href = href;
37 }
38 function areyousure_popup(message, action, actionlabel) {
39   if (confirm(message) == true) {
40 <% include('/elements/popup_link_onclick.html',
41      'js_action' => 'action',
42      'js_actionlabel' => 'actionlabel',
43    ) %>
44   }
45 }
46 </SCRIPT>
47
48 <br>
49
50 % ###
51 % # Basics
52 % ###
53
54 % if ( $view eq 'basics' ) {
55
56 % my $br = 0;
57 % if ( $curuser->access_right('Order customer package') && $conf->exists('cust_main-enable_order_package') ) {
58   | <& /elements/order_pkg_link.html, 'cust_main'=>$cust_main &>
59 % }
60
61 % if ( $conf->config('cust_main-external_links') ) {
62     <% $br++ ? ' | ' : '' %>
63 %   my @links = split(/\n/, $conf->config('cust_main-external_links'));
64 %   foreach my $link (@links) {
65 %     $link =~ /^\s*(\S+)\s+(.*?)(\s*\(([^\)]*)\))?$/ or next;
66 %     my($url, $label, $alt) = ($1, $2, $4);
67       <A HREF="<% $url.$custnum %>" ALT="<% $alt |h %>"><% $label |h %></A>
68 %   }
69 % }
70
71 % if ( $br ) {
72   <BR><BR>
73 % }
74
75 %my $signupurl = $conf->config('signupurl');
76 %if ( $signupurl ) {
77   <% mt('This customer\'s signup URL:') |h %>
78   <A HREF="<% $signupurl %>?ref=<% $custnum %>"><% $signupurl %>?ref=<% $custnum %></A>
79   <BR><BR>
80 % } 
81
82 <TABLE BORDER=0>
83 <TR>
84   <TD VALIGN="top">
85     <& cust_main/contacts.html, $cust_main &>
86     <BR>
87     <& cust_main/misc.html, $cust_main &>
88   </TD>
89   <TD VALIGN="top" STYLE="padding-left: 54px">
90     <& cust_main/billing.html, $cust_main &>
91     <BR>
92     <& cust_main/cust_payby.html, $cust_main &>
93   </TD>
94 </TR>
95 <TR>
96   <TD COLSPAN = 2>
97     <& cust_main/contacts_new.html, $cust_main &>
98   </TD>
99 </TR>
100 </TABLE>
101 <BR>
102
103 % }
104
105
106 % ###
107 % # Notes
108 % ###
109 % if ( $view eq 'notes' ) {
110   <& cust_main/notes.html, 'cust_main' => $cust_main &>
111   <BR>
112 % }
113
114
115 % ###
116 % # Tickets
117 % ###
118
119 % if ( $view eq 'tickets' ) {
120
121 % if ( $conf->config('ticket_system') ) { 
122   <& cust_main/tickets.html, $cust_main &>
123 % } 
124   <BR>
125
126 % }
127
128 % ###
129 % # Appointments
130 % ###
131
132 % if ( $view eq 'appointments' ) {
133
134 % if ( $conf->config('ticket_system')
135 %        && $curuser->access_right('View appointments') ) { 
136   <& cust_main/appointments.html, $cust_main &>
137 % } 
138   <BR>
139
140 % }
141
142
143 % ###
144 % # Quotations
145 % ###
146
147 % if ( $view eq 'quotations' ) {
148
149 %   if ( $curuser->access_right('Generate quotation') ) { 
150       <& cust_main/quotations.html, $cust_main &>
151 %   }
152
153 % }
154
155
156 % ###
157 % # Packages
158 % ###
159
160 % if ( $view eq 'packages' ) {
161
162 % #XXX enable me# if ( $curuser->access_right('View customer packages') { 
163 <& cust_main/packages.html, $cust_main &>
164 % #}
165 <BR>
166
167 % }
168
169
170 % ###
171 % # Payment History
172 % ###
173
174 % if ( $view eq 'payment_history' ) {
175
176 <& cust_main/payment_history.html, $cust_main &>
177 <BR>
178
179 % }
180
181
182 % ###
183 % # Change History
184 % ###
185
186 % if ( $view eq 'change_history' ) {
187 <& cust_main/change_history.html, $cust_main &>
188 <BR>
189 % }
190
191 % if ( $view eq 'custom' ) { 
192 %   if ( $conf->config('cust_main-custom_link') ) {
193 <& cust_main/custom.html, $cust_main &>
194 %   } elsif ( $conf->config('cust_main-custom_content') ) {
195       <& cust_main/custom_content.html, $cust_main &>
196 %   #} else {
197 %   #  warn "custom view without cust_main-custom_link or -custom_content?";
198 %   }
199 % }
200
201 </DIV>
202 <& /elements/footer.html &>
203 <%init>
204
205 my $curuser = $FS::CurrentUser::CurrentUser;
206
207 die "access denied"
208   unless $curuser->access_right('View customer');
209
210 my $conf = new FS::Conf;
211
212 my $custnum;
213 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
214   $custnum = $1;
215 } else {
216   die "No customer specified (bad URL)!" unless $cgi->keywords;
217   my($query) = $cgi->keywords; # needs parens with my, ->keywords returns array
218   $query =~ /^(\d+)$/;
219   $custnum = $1;
220   $cgi->delete('keywords');
221   $cgi->param('custnum', $1);
222 }
223
224 my $cust_main = qsearchs( {
225   'table'     => 'cust_main',
226   'hashref'   => { 'custnum' => $custnum },
227   'extra_sql' => ' AND '. $curuser->agentnums_sql,
228 });
229 die "Customer not found!" unless $cust_main;
230
231 my $title = mt("Customer").' #'. $cust_main->display_custnum. ': '.
232             encode_entities($cust_main->name);
233
234 if ( $curuser->num_agents ) {
235   $title = encode_entities($cust_main->agent->agent). " $title";
236 }
237
238 my $status = $cust_main->status_label;
239 $status .= ' (Cancelled)' if $cust_main->is_status_delay_cancel;
240 my $title_noescape = $title. ' (<B><FONT COLOR="#'. $cust_main->statuscolor. '">'. $status.  '</FONT></B>)';
241 $title .= " ($status)";
242
243 #false laziness w/pref/pref.html and Conf.pm (cust_main-default_view)
244 tie my %views, 'Tie::IxHash',
245        emt('Basics')           => 'basics',
246        emt('Notes')            => 'notes', #notes and files?
247 ;
248 if ( $conf->config('ticket_system') ) {
249   $views{emt('Tickets')}       =  'tickets';
250   $views{emt('Appointments')}  =  'appointments'
251     if $curuser->access_right('View appointments');
252 }
253 $views{emt('Quotations')}      =  'quotations';
254 $views{emt('Packages')}        =  'packages';
255 $views{emt('Payment History')} =  'payment_history';
256 $views{emt('Change History')}  =  'change_history'
257   if $curuser->access_right('View customer history');
258 $views{$conf->config('cust_main-custom_title') || emt('Custom')} =  'custom'
259   if $conf->config('cust_main-custom_link')
260   || $conf->config('cust_main-custom_content');
261
262 my %viewname = reverse %views;
263
264 my $view =  $cgi->param('show') || $curuser->default_customer_view;
265 $view = 'basics' if $view eq 'jumbo';
266
267 my $ie_compat = $conf->config('ie-compatibility_mode');
268 my $head = '';
269 if ( $ie_compat ) {
270   $head = qq(<meta http-equiv="X-UA-Compatible" content="IE=$ie_compat" />);
271 }
272
273 </%init>