2254df489b37f164ac202844e32685818a168954
[freeside.git] / httemplate / view / cust_main.cgi
1 <& /elements/header-cust_main.html, view=>$view, cust_main=>$cust_main &>
2
3 % ###
4 % # Basics
5 % ###
6
7 % if ( $view eq 'basics' ) {
8
9 % my $br = 0;
10
11 % if ( $conf->config('cust_main-external_links') ) {
12     <% $br++ ? ' | ' : '' %>
13 %   my @links = split(/\n/, $conf->config('cust_main-external_links'));
14 %   foreach my $link (@links) {
15 %     $link =~ /^\s*(\S+)\s+(.*?)(\s*\(([^\)]*)\))?$/ or next;
16 %     my($url, $label, $alt) = ($1, $2, $4);
17       <A HREF="<% $url.$custnum %>" ALT="<% $alt |h %>"><% $label |h %></A>
18 %   }
19 % }
20
21 % if ( $br ) {
22   <BR><BR>
23 % }
24
25 %my $signupurl = $conf->config('signupurl');
26 %if ( $signupurl ) {
27   <% mt('This customer\'s signup URL:') |h %>
28   <A HREF="<% $signupurl %>?ref=<% $custnum %>"><% $signupurl %>?ref=<% $custnum %></A>
29   <BR><BR>
30 % } 
31
32 <TABLE BORDER=0>
33 <TR>
34   <TD VALIGN="top">
35     <& cust_main/contacts.html, $cust_main &>
36     <BR>
37     <& cust_main/misc.html, $cust_main &>
38   </TD>
39   <TD VALIGN="top" STYLE="padding-left: 54px">
40     <& cust_main/billing.html, $cust_main &>
41     <BR>
42     <& cust_main/cust_payby.html, $cust_main &>
43   </TD>
44 </TR>
45 <TR>
46   <TD COLSPAN = 2>
47     <& cust_main/contacts_new.html, $cust_main &>
48   </TD>
49 </TR>
50 </TABLE>
51 <BR>
52
53 % }
54
55
56 % ###
57 % # Notes
58 % ###
59 % if ( $view eq 'notes' ) {
60   <& cust_main/notes.html, 'cust_main' => $cust_main &>
61   <BR>
62 % }
63
64
65 % ###
66 % # Tickets
67 % ###
68
69 % if ( $view eq 'tickets' ) {
70
71 % if ( $conf->config('ticket_system') ) { 
72   <& cust_main/tickets.html, $cust_main &>
73 % } 
74   <BR>
75
76 % }
77
78 % ###
79 % # Appointments
80 % ###
81
82 % if ( $view eq 'appointments' ) {
83
84 % if ( $conf->config('ticket_system')
85 %        && $curuser->access_right('View appointments') ) { 
86   <& cust_main/appointments.html, $cust_main &>
87 % } 
88   <BR>
89
90 % }
91
92
93 % ###
94 % # Quotations
95 % ###
96
97 % if ( $view eq 'quotations' ) {
98
99 %   if ( $curuser->access_right('Generate quotation') ) { 
100       <& cust_main/quotations.html, $cust_main &>
101 %   }
102
103 % }
104
105
106 % ###
107 % # Packages
108 % ###
109
110 % if ( $view eq 'packages' ) {
111
112 % #XXX enable me# if ( $curuser->access_right('View customer packages') { 
113 <& cust_main/packages.html, $cust_main &>
114 % #}
115 <BR>
116
117 % }
118
119
120 % ###
121 % # Payment History
122 % ###
123
124 % if ( $view eq 'payment_history' ) {
125
126 <& cust_main/payment_history.html, $cust_main &>
127 <BR>
128
129 % }
130
131
132 % ###
133 % # Change History
134 % ###
135
136 % if ( $view eq 'change_history' ) {
137 <& cust_main/change_history.html, $cust_main &>
138 <BR>
139 % }
140
141 % if ( $view eq 'custom' ) { 
142 %   if ( $conf->config('cust_main-custom_link') ) {
143 <& cust_main/custom.html, $cust_main &>
144 %   } elsif ( $conf->config('cust_main-custom_content') ) {
145       <& cust_main/custom_content.html, $cust_main &>
146 %   #} else {
147 %   #  warn "custom view without cust_main-custom_link or -custom_content?";
148 %   }
149 % }
150
151 </DIV>
152 <& /elements/footer.html &>
153 <%init>
154
155 my $curuser = $FS::CurrentUser::CurrentUser;
156
157 die "access denied"
158   unless $curuser->access_right('View customer');
159
160 my $conf = new FS::Conf;
161
162 my $custnum;
163 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
164   $custnum = $1;
165 } else {
166   die "No customer specified (bad URL)!" unless $cgi->keywords;
167   my($query) = $cgi->keywords; # needs parens with my, ->keywords returns array
168   $query =~ /^(\d+)$/;
169   $custnum = $1;
170   $cgi->delete('keywords');
171   $cgi->param('custnum', $1);
172 }
173
174 my $cust_main = qsearchs( {
175   'table'     => 'cust_main',
176   'hashref'   => { 'custnum' => $custnum },
177   'extra_sql' => ' AND '. $curuser->agentnums_sql,
178 });
179 die "Customer not found!" unless $cust_main;
180
181 #false laziness w/pref/pref.html and Conf.pm (cust_main-default_view)
182 tie my %views, 'Tie::IxHash',
183        emt('Basics')           => 'basics',
184        emt('Notes')            => 'notes', #notes and files?
185 ;
186 if ( $conf->config('ticket_system') ) {
187   $views{emt('Tickets')}       =  'tickets';
188   $views{emt('Appointments')}  =  'appointments'
189     if $curuser->access_right('View appointments');
190 }
191 $views{emt('Quotations')}      =  'quotations';
192 $views{emt('Packages')}        =  'packages';
193 $views{emt('Payment History')} =  'payment_history';
194 $views{emt('Change History')}  =  'change_history'
195   if $curuser->access_right('View customer history');
196 $views{$conf->config('cust_main-custom_title') || emt('Custom')} =  'custom'
197   if $conf->config('cust_main-custom_link')
198   || $conf->config('cust_main-custom_content');
199
200 my %viewname = reverse %views;
201
202 my $view =  $cgi->param('show') || $curuser->default_customer_view;
203
204 if ($view eq 'last') {
205   # something took us away from the page and is now bouncing back
206   $view = get_page_pref('last_view', $custnum);
207 } else {
208   # remember which view is open so we _can_ bounce back
209   set_page_pref('last_view', $custnum, $view);
210 }
211
212 $view = 'basics' if $view eq 'jumbo';
213
214 </%init>