don't link to deleted attachments if there aren't any
[freeside.git] / httemplate / view / cust_main / notes.html
index c1a33b0..c02af38 100755 (executable)
@@ -1,74 +1,67 @@
-%
-% my $conf = new FS::Conf;
-%
-% $cgi->param('custnum') =~ /^(\d+)$/
-%   or die "No customer specified (bad URL)!";
-% my $custnum = $1;
-%
-% my $cust_main = qsearchs('cust_main', {'custnum' => $custnum} );
-% die "Custimer not found!" unless $cust_main;
-%
-% my (@notes) = $cust_main->notes();
-% if ( scalar(@notes) ) { 
+% # Customer comments
+% if ( $cust_main->comments =~ /[^\s\n\r]/ ) {
+<BR><% mt('Comments') |h %>
+<% ntable("#cccccc") %><TR><TD><% ntable("#cccccc",2) %>
+<TR>
+  <TD BGCOLOR="#ffffff">
+    <PRE><% encode_entities($cust_main->comments) %></PRE>
+  </TD>
+</TR>
+</TABLE></TABLE>
+<BR><BR>
+% }
 
-<STYLE TYPE="text/css">
+% # Notes, if any
+<A NAME="notes">
+% my $notecount = scalar($cust_main->notes(0));
+% if ( ! $conf->exists('cust_main-disable_notes') || $notecount) {
 
-body { background: #e8e8e8 }
-.inv table { border: none }
-.inv TH { border: none }
-.inv TD { border: none }
+% # actually display notes
+<& notes/notes.html, 'cust_main' => $cust_main &>
+<BR>
+% } # end of notes
 
-</STYLE>
+% # Attachments
+% # XXX at some point move all of this into notes/attachments.html
+% if( $curuser->access_right('View attachments') ) {
+% # List attachments
+<& notes/attachments.html, 'cust_main' => $cust_main &>
+%   if ($cgi->param('show_deleted')) {
+<A HREF="<% $p.'view/cust_main.cgi?custnum=' . $cust_main->custnum .
+           ($view ? ";show=$view" : '') . '#notes' 
+           %>"><I>(<% mt('Show active attachments') |h %>)</I></A>
+%   } elsif ( $curuser->access_right('View deleted attachments')
+%               && FS::Record->scalar_sql(
+%                    'SELECT 1 FROM cust_attachment WHERE custnum = ? '.
+%                      ' AND disabled IS NOT NULL AND disabled > 0 LIMIT 1',
+%                    $custnum )
+%           )
+%   {
+<A HREF="<% $p.'view/cust_main.cgi?custnum=' . $cust_main->custnum .
+           ($view ? ";show=$view" : '') . ';show_deleted=1#notes'
+           %>"><I>(<% mt('Show deleted attachments') |h %>)</I></A>
+%   }
+% }
 
-<TABLE CLASS="inv" CELLSPACING=0 CELLPADDING=0 BORDER=0 >
+<BR>
+% if ( $curuser->access_right('View email logs')
+%      and FS::cust_msg->count("custnum = $custnum")) {
+<BR>
+<& notes/email.html, 'cust_main' => $cust_main &>
+<BR>
+% }
+<%init>
 
-%#<% include('/elements/table-grid.html') %>
-%   my $bgcolor1 = '#eeeeee';
-%   my $bgcolor2 = '#ffffff';
-%   my $bgcolor = '';
-%
-%   foreach my $note (@notes) {
-%
-%   if ( $bgcolor eq $bgcolor1 ) {
-%     $bgcolor = $bgcolor2;
-%   } else {
-%     $bgcolor = $bgcolor1;
-%   }
-%
-%
+use HTML::Defang;
 
-<TR>
-  <% note_datestr($note,$conf,$bgcolor) %>
-  <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
-    &nbsp;<%$note->otaker%>&nbsp;
-  </TD>
-  <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
-    &nbsp;<%$note->comments%>
-  </TD>
-</TR>
+my $conf = new FS::Conf;
+my $curuser = $FS::CurrentUser::CurrentUser;
 
-% } #end display notes
+my(%opt) = @_;
 
-</TABLE>
-% } else { 
+my $cust_main = $opt{'cust_main'};
+my $custnum = $cust_main->custnum;
 
-<BR>
-% } 
-%
-%#subroutines
-%
-%sub note_datestr {
-% my($note, $conf, $bgcolor) = @_ or return '';
-% my $format=qq{<TD class="inv" bgcolor="$bgcolor" align="left"><B>%b</B></TD>}.
-%            qq{<TD class="inv" bgcolor="$bgcolor" align="right"><B>&nbsp;%o,</B></TD>}.
-%            qq{<TD class="inv" bgcolor="$bgcolor" align="right"><B>&nbsp;%Y&nbsp;</B></TD>};
-% $format .= qq{<TD class="inv" bgcolor="$bgcolor" ALIGN="right"><B>&nbsp;%l</TD>}.
-%            qq{<TD class="inv" bgcolor="$bgcolor" ALIGN="center"><B>:</B></TD>}.
-%            qq{<TD class="inv" bgcolor="$bgcolor" ALIGN="left"><B>%M</B></TD>}.
-%            qq{<TD class="inv" bgcolor="$bgcolor" ALIGN="left"><B>&nbsp;%P&nbsp;</B></TD>}
-%     if $conf->exists('cust_main_note-display_times');
-%   ( my $strip = time2str($format, $note->_date) ) =~ s/ (\d)/$1/g;
-%   $strip;
-% }
-%
+my $view =  $cgi->param('show') || $curuser->default_customer_view;
 
+</%init>