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