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
58 % if ( $conf->config('cust_main-external_links') ) {
59     <% $br++ ? ' | ' : '' %>
60 %   my @links = split(/\n/, $conf->config('cust_main-external_links'));
61 %   foreach my $link (@links) {
62 %     $link =~ /^\s*(\S+)\s+(.*?)(\s*\(([^\)]*)\))?$/ or next;
63 %     my($url, $label, $alt) = ($1, $2, $4);
64       <A HREF="<% $url.$custnum %>" ALT="<% $alt |h %>"><% $label |h %></A>
65 %   }
66 % }
67
68 % if ( $br ) {
69   <BR><BR>
70 % }
71
72 %my $signupurl = $conf->config('signupurl');
73 %if ( $signupurl ) {
74   <% mt('This customer\'s signup URL:') |h %>
75   <A HREF="<% $signupurl %>?ref=<% $custnum %>"><% $signupurl %>?ref=<% $custnum %></A>
76   <BR><BR>
77 % } 
78
79 <TABLE BORDER=0>
80 <TR>
81   <TD VALIGN="top">
82     <& cust_main/contacts.html, $cust_main &>
83     <BR>
84     <& cust_main/misc.html, $cust_main &>
85   </TD>
86   <TD VALIGN="top" STYLE="padding-left: 54px">
87     <& cust_main/billing.html, $cust_main &>
88     <BR>
89     <& cust_main/cust_payby.html, $cust_main &>
90   </TD>
91 </TR>
92 <TR>
93   <TD COLSPAN = 2>
94     <& cust_main/contacts_new.html, $cust_main &>
95   </TD>
96 </TR>
97 </TABLE>
98 <BR>
99
100 % }
101
102
103 % ###
104 % # Notes
105 % ###
106 % if ( $view eq 'notes' ) {
107   <& cust_main/notes.html, 'cust_main' => $cust_main &>
108   <BR>
109 % }
110
111
112 % ###
113 % # Tickets
114 % ###
115
116 % if ( $view eq 'tickets' ) {
117
118 % if ( $conf->config('ticket_system') ) { 
119   <& cust_main/tickets.html, $cust_main &>
120 % } 
121   <BR>
122
123 % }
124
125 % ###
126 % # Appointments
127 % ###
128
129 % if ( $view eq 'appointments' ) {
130
131 % if ( $conf->config('ticket_system')
132 %        && $curuser->access_right('View appointments') ) { 
133   <& cust_main/appointments.html, $cust_main &>
134 % } 
135   <BR>
136
137 % }
138
139
140 % ###
141 % # Quotations
142 % ###
143
144 % if ( $view eq 'quotations' ) {
145
146 %   if ( $curuser->access_right('Generate quotation') ) { 
147       <& cust_main/quotations.html, $cust_main &>
148 %   }
149
150 % }
151
152
153 % ###
154 % # Packages
155 % ###
156
157 % if ( $view eq 'packages' ) {
158
159 % #XXX enable me# if ( $curuser->access_right('View customer packages') { 
160 <& cust_main/packages.html, $cust_main &>
161 % #}
162 <BR>
163
164 % }
165
166
167 % ###
168 % # Payment History
169 % ###
170
171 % if ( $view eq 'payment_history' ) {
172
173 <& cust_main/payment_history.html, $cust_main &>
174 <BR>
175
176 % }
177
178
179 % ###
180 % # Change History
181 % ###
182
183 % if ( $view eq 'change_history' ) {
184 <& cust_main/change_history.html, $cust_main &>
185 <BR>
186 % }
187
188 % if ( $view eq 'custom' ) { 
189 %   if ( $conf->config('cust_main-custom_link') ) {
190 <& cust_main/custom.html, $cust_main &>
191 %   } elsif ( $conf->config('cust_main-custom_content') ) {
192       <& cust_main/custom_content.html, $cust_main &>
193 %   #} else {
194 %   #  warn "custom view without cust_main-custom_link or -custom_content?";
195 %   }
196 % }
197
198 </DIV>
199 <& /elements/footer.html &>
200 <%init>
201
202 my $curuser = $FS::CurrentUser::CurrentUser;
203
204 die "access denied"
205   unless $curuser->access_right('View customer');
206
207 my $conf = new FS::Conf;
208
209 my $custnum;
210 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
211   $custnum = $1;
212 } else {
213   die "No customer specified (bad URL)!" unless $cgi->keywords;
214   my($query) = $cgi->keywords; # needs parens with my, ->keywords returns array
215   $query =~ /^(\d+)$/;
216   $custnum = $1;
217   $cgi->delete('keywords');
218   $cgi->param('custnum', $1);
219 }
220
221 my $cust_main = qsearchs( {
222   'table'     => 'cust_main',
223   'hashref'   => { 'custnum' => $custnum },
224   'extra_sql' => ' AND '. $curuser->agentnums_sql,
225 });
226 die "Customer not found!" unless $cust_main;
227
228 my $title = mt("Customer").' #'. $cust_main->display_custnum. ': ';
229 my $title_noescape = $title. encode_entities($cust_main->name);
230 $title .= $cust_main->name;
231
232 if ( $curuser->num_agents ) {
233   $title_noescape =
234     encode_entities($cust_main->agent->agent). " $title_noescape";
235   $title = $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 $title_noescape .= ' (<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
266 if ($view eq 'last') {
267   # something took us away from the page and is now bouncing back
268   $view = get_page_pref('last_view', $custnum);
269 } else {
270   # remember which view is open so we _can_ bounce back
271   set_page_pref('last_view', $custnum, $view);
272 }
273
274 $view = 'basics' if $view eq 'jumbo';
275
276 my $ie_compat = $conf->config('ie-compatibility_mode');
277 my $head = '';
278 if ( $ie_compat ) {
279   $head = qq(<meta http-equiv="X-UA-Compatible" content="IE=$ie_compat" />);
280 }
281
282 </%init>