3e5a8cee3978e5ae01a40056f00c974387e6c178
[freeside.git] / httemplate / view / cust_main.cgi
1 <% include('/elements/header.html', {
2              'title' => "Customer View: ". $cust_main->name,
3              'nobr'  => 1,
4           })
5 %>
6 <BR>
7
8 <% include('/elements/menubar.html',
9              { 'newstyle' => 1,
10                'selected' => $viewname{$view},
11                'url_base' => $cgi->url. "?custnum=$custnum;show=",
12              },
13              %views,
14           )
15 %>
16 <BR>
17
18 <% include('/elements/init_overlib.html') %>
19
20 <SCRIPT TYPE="text/javascript">
21 function areyousure(href, message) {
22   if (confirm(message) == true)
23     window.location.href = href;
24 }
25 </SCRIPT>
26
27 % if ( $view eq 'basics' || $view eq 'jumbo' ) {
28
29 % if ( $curuser->access_right('Edit customer') ) { 
30   <A HREF="<% $p %>edit/cust_main.cgi?<% $custnum %>">Edit this customer</A> | 
31 % } 
32
33 % if ( $curuser->access_right('Cancel customer')
34 %        && $cust_main->ncancelled_pkgs
35 %      ) {
36
37   <% include( '/elements/popup_link-cust_main.html',
38               { 'action'      => $p. 'misc/cancel_cust.html',
39                 'label'       => 'Cancel&nbsp;this&nbsp;customer',
40                 'actionlabel' => 'Confirm Cancellation',
41                 'color'       => '#ff0000',
42                 'cust_main'   => $cust_main,
43               }
44             )
45   %> | 
46
47 % }
48
49 % if ( $conf->exists('deletecustomers')
50 %        && $curuser->access_right('Delete customer')
51 %      ) {
52   <A HREF="<% $p %>misc/delete-customer.cgi?<% $custnum%>">Delete this customer</A> | 
53 % } 
54
55 % unless ( $conf->exists('disable_customer_referrals') ) { 
56   <A HREF="<% $p %>edit/cust_main.cgi?referral_custnum=<% $custnum %>">Refer a new customer</A> | 
57   <A HREF="<% $p %>search/cust_main.cgi?referral_custnum=<% $custnum %>">View this customer's referrals</A>
58 % } 
59
60 <BR><BR>
61
62 % if (    $curuser->access_right('Billing event reports') 
63 %      || $curuser->access_right('View customer billing events')
64 %    ) {
65
66   <A HREF="<% $p %>search/cust_event.html?custnum=<% $custnum %>">View billing events for this customer</A>
67   <BR><BR>
68
69 % }
70
71 %my $signupurl = $conf->config('signupurl');
72 %if ( $signupurl ) {
73   This customer's signup URL: <A HREF="<% $signupurl %>?ref=<% $custnum %>"><% $signupurl %>?ref=<% $custnum %></A><BR><BR>
74 % } 
75
76
77 <A NAME="cust_main"></A>
78 <TABLE BORDER=0>
79 <TR>
80   <TD VALIGN="top">
81     <% include('cust_main/contacts.html', $cust_main ) %>
82   </TD>
83   <TD VALIGN="top" STYLE="padding-left: 54px">
84     <% include('cust_main/misc.html', $cust_main ) %>
85 % if ( $conf->config('payby-default') ne 'HIDE' ) { 
86
87       <BR>
88       <% include('cust_main/billing.html', $cust_main ) %>
89 % } 
90
91   </TD>
92 </TR>
93 </TABLE>
94
95 % }
96
97 % if ( $view eq 'notes' || $view eq 'jumbo' ) {
98
99 %if ( $cust_main->comments =~ /[^\s\n\r]/ ) {
100 <BR>
101 Comments
102 <% ntable("#cccccc") %><TR><TD><% ntable("#cccccc",2) %>
103 <TR>
104   <TD BGCOLOR="#ffffff">
105     <PRE><% encode_entities($cust_main->comments) %></PRE>
106   </TD>
107 </TR>
108 </TABLE></TABLE>
109 <BR><BR>
110 % }
111 <A NAME="notes">
112 % my $notecount = scalar($cust_main->notes());
113 % if ( ! $conf->exists('cust_main-disable_notes') || $notecount) {
114
115 %   unless ( $view eq 'notes' && $cust_main->comments !~ /[^\s\n\r]/ ) {
116       <BR>
117       <A NAME="cust_main_note"><FONT SIZE="+2">Notes</FONT></A><BR>
118 %   }
119
120 %   if ( $curuser->access_right('Add customer note') &&
121 %        ! $conf->exists('cust_main-disable_notes')
122 %      ) {
123
124   <% include( '/elements/popup_link-cust_main.html',
125                 'label'       => 'Add customer note',
126                 'action'      => $p. 'edit/cust_main_note.cgi',
127                 'actionlabel' => 'Enter customer note',
128                 'cust_main'   => $cust_main,
129                 'width'       => 616,
130                 'height'      => 408,
131             )
132   %>
133
134 %   }
135
136 <BR>
137
138 <% include('cust_main/notes.html', 'custnum' => $cust_main->custnum ) %>
139
140 % }
141 <BR>
142
143 % if(! $conf->config('disable_cust_attachment') 
144 %  and $curuser->access_right('Add attachment')) {
145 <% include( '/elements/popup_link-cust_main.html',
146               'label'       => 'Attach file',
147               'action'      => $p.'edit/cust_main_attach.cgi',
148               'actionlabel' => 'Upload file',
149               'cust_main'   => $cust_main,
150               'width'       => 616,
151               'height'      => 408,
152           )
153 %>
154 % }
155 <% include('cust_main/attachments.html', 'custnum' => $cust_main->custnum ) %>
156 % if($cgi->param('show_deleted')) {
157 <A HREF="<% $p.'view/cust_main.cgi?custnum=' . $cust_main->custnum .
158            ($view ? ";show=$view" : '') . '#notes' 
159            %>"><I>(Show active attachments)</I></A>
160 % }
161 % elsif($curuser->access_right('View deleted attachments')) {
162 <A HREF="<% $p.'view/cust_main.cgi?custnum=' . $cust_main->custnum .
163            ($view ? ";show=$view" : '') . ';show_deleted=1#notes'
164            %>"><I>(Show deleted attachments)</I></A>
165 % }
166 <BR>
167
168 % }
169
170 % if ( $view eq 'jumbo' ) {
171     <BR><BR>
172     <A NAME="tickets"><FONT SIZE="+2">Tickets</FONT></A><BR>
173 % }
174
175 % if ( $view eq 'tickets' || $view eq 'jumbo' ) {
176
177 % if ( $conf->config('ticket_system') ) { 
178   <% include('cust_main/tickets.html', $cust_main ) %>
179 % } 
180   <BR><BR>
181
182 % }
183
184 % if ( $view eq 'jumbo' ) { #XXX enable me && $curuser->access_right('View customer packages') { 
185
186   <A NAME="cust_pkg"><FONT SIZE="+2">Packages</FONT></A><BR>
187 % }
188
189 % if ( $view eq 'packages' || $view eq 'jumbo' ) {
190
191 % #XXX enable me# if ( $curuser->access_right('View customer packages') { 
192 <% include('cust_main/packages.html', $cust_main ) %>
193 % #}
194
195 % }
196
197 % if ( $view eq 'jumbo' ) {
198     <BR><BR>
199     <A NAME="history"><FONT SIZE="+2">Payment History</FONT></A><BR>
200 % }
201
202 % if ( $view eq 'payment_history' || $view eq 'jumbo' ) {
203
204 % if ( $conf->config('payby-default') ne 'HIDE' ) { 
205   <% include('cust_main/payment_history.html', $cust_main ) %>
206 % } 
207
208 % }
209
210 % if ( $view eq 'change_history' ) { #  || $view eq 'jumbo'      
211 <% include('cust_main/change_history.html', $cust_main ) %>      
212 % }
213
214 <% include('/elements/footer.html') %>
215 <%init>
216
217 my $curuser = $FS::CurrentUser::CurrentUser;
218
219 die "access denied"
220   unless $curuser->access_right('View customer');
221
222 my $conf = new FS::Conf;
223
224 my $custnum;
225 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
226   $custnum = $1;
227 } else {
228   die "No customer specified (bad URL)!" unless $cgi->keywords;
229   my($query) = $cgi->keywords; # needs parens with my, ->keywords returns array
230   $query =~ /^(\d+)$/;
231   $custnum = $1;
232 }
233
234 my $cust_main = qsearchs( {
235   'table'     => 'cust_main',
236   'hashref'   => { 'custnum' => $custnum },
237   'extra_sql' => ' AND '. $curuser->agentnums_sql,
238 });
239 die "Customer not found!" unless $cust_main;
240
241 #false laziness w/pref/pref.html and Conf.pm (cust_main-default_view)
242 tie my %views, 'Tie::IxHash',
243        'Basics'           => 'basics',
244        'Notes'            => 'notes', #notes and files?
245 ;
246 $views{'Tickets'}         =  'tickets'
247                                if $conf->config('ticket_system');
248 $views{'Packages'}        =  'packages';
249 $views{'Payment History'} =  'payment_history'
250                                unless $conf->config('payby-default' eq 'HIDE');
251 $views{'Change History'}  =  'change_history'
252   if $curuser->access_right('View customer history');
253 $views{'Jumbo'}           =  'jumbo';
254
255 my %viewname = reverse %views;
256
257 my $view =  $cgi->param('show') || $curuser->default_customer_view;
258
259 </%init>