6a7a06a025b1bfc4dc2b83a7a223daa206a3c5d9
[freeside.git] / httemplate / view / cust_main / notes / notes.html
1 % if ( scalar(@notes) ) {
2
3 <SCRIPT TYPE="text/javascript">
4
5     function display_notes_classnum(classnum){
6         document.getElementById('notes_'+classnum).style.display = 'block';
7         document.getElementById('notes_tablink_'+classnum).style.fontWeight = 'bold';
8
9         var divs = document.getElementsByTagName("div");
10         var i;
11         for(i=0; i < divs.length; i++){
12             var d = divs[i];
13             if(d.id.length > 6 && d.id.substring(0,6) == 'notes_') {
14                 if(divs[i].id != 'notes_'+classnum) {
15                     divs[i].style.display = 'none';
16                 }
17             }
18         }
19         
20         var as = document.getElementsByTagName("a");
21         for(i=0; i < as.length; i++){
22             var a = as[i];
23             if(a.id.length > 14 && a.id.substring(0,14) == 'notes_tablink_') {
24                 if(as[i].id != 'notes_tablink_'+classnum) {
25                     as[i].style.fontWeight = 'normal';
26                 }
27             }
28         }
29     }
30
31 </SCRIPT>
32
33   <& /elements/init_overlib.html &>
34
35 % my $bgcolor1 = '#eeeeee';
36 % my $bgcolor2 = '#ffffff';
37 % my $bgcolor = '';
38 % my $last_classnum = -1;
39 % my $skipheader = 0;
40 % my %classes = ();
41 %
42 % foreach my $note (@notes) {
43 %
44 %   if ( $bgcolor eq $bgcolor1 ) {
45 %     $bgcolor = $bgcolor2;
46 %   } else {
47 %     $bgcolor = $bgcolor1;
48 %   }
49 %
50 %   my $pop = popurl(3);
51 %   my $notenum = $note->notenum;
52 %   my $onclick = include( '/elements/popup_link_onclick.html',
53 %                            'action'      => popurl(2).
54 %                                             'edit/cust_main_note.cgi'.
55 %                                             "?custnum=$custnum".
56 %                                             ";notenum=$notenum",
57 %                            'actionlabel' => emt('Edit customer note'),
58 %                            'width'       => 616,
59 %                            'height'      => 538, #575
60 %                            'frame'       => 'top',
61 %                        );
62 %   my $clickjs = qq!onclick="$onclick"!;
63 %
64 %   my $edit = '';
65 %   if ($curuser->access_right('Edit customer note') ) {
66 %     my $delete_url = $fsurl.'misc/delete-note.html?'.$notenum;
67 %     $edit = qq! <A HREF="javascript:void(0);" $clickjs>(!.emt('edit').')</A>'.
68 %             qq! <A HREF="$delete_url" !.
69 %             qq! onclick="return confirm('Delete this note?')">!.
70 %             '('.emt('delete').')</A>';
71 %   }
72 %
73 % if ( $last_classnum != $note->classnum && !$skipheader ) {
74 % my $tmp_classnum = $note->classnum ? $note->classnum : 0;
75 % $classes{$tmp_classnum} = $note->classname ne '' ? $note->classname 
76 %                                                    : emt('Other');
77 % if ( $last_classnum != -1 ) {
78     </TABLE>
79   </DIV>
80 % }
81 % my $display = ($tmp_classnum == 0 || !$conf->exists('note-classes') 
82 %                                   || $conf->config('note-classes') < 2) 
83 %                                                           ? 'block' : 'none';
84         <DIV    id="notes_<% $tmp_classnum %>"
85                 style="display:<% $display %>"
86         >
87         <& /elements/table-grid.html &>
88         <TR>
89             <TH CLASS="grid" BGCOLOR="#cccccc"><% mt('Date') |h %></TH>
90 %   if ( $conf->exists('cust_main_note-display_times') ) {
91             <TH CLASS="grid" BGCOLOR="#cccccc"><% mt('Time') |h %></TH>
92 %   }
93             <TH CLASS="grid" BGCOLOR="#cccccc"><% mt('Person') |h %></TH>
94 %   if ($conf->exists('note-classes') && $conf->config('note-classes') == 1) {
95             <TH CLASS="grid" BGCOLOR="#cccccc"><% mt('Class') |h %></TH>
96 %   }
97             <TH CLASS="grid" BGCOLOR="#cccccc"><% mt('Note') |h %></TH>
98 %   if ($curuser->access_right('Edit customer note') ) {
99             <TH CLASS="grid" BGCOLOR="#cccccc">&nbsp;</TH>
100 %   }
101         </TR>
102 % $skipheader = (!$conf->exists('note-classes') || $conf->config('note-classes') < 2);
103 % $last_classnum = $note->classnum;
104 % }
105
106     <TR>
107       <% note_datestr($note,$conf,$bgcolor) %>
108       <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
109         &nbsp;<% $note->usernum ? $note->access_user->name : $note->otaker %>
110       </TD>
111 % if ($conf->exists('note-classes') && $conf->config('note-classes') == 1) {
112       <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
113         <% $note->classname %>   
114       </TD>
115 % }
116       <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
117         <% $note->comments | defang %>
118       </TD>
119 % if($edit) {
120       <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"><% $edit %></TD>
121 % }
122     </TR>
123
124 % } #end display notes
125
126 </TABLE>
127 </DIV>
128
129 % if ( $conf->exists('note-classes') && $conf->config('note-classes') == 2 ) {
130 %       my($classnum,$classname);
131 <% mt('Show notes of class:') |h %> &nbsp; 
132 %       foreach my $classnum ( sort { $b <=> $a } (keys %classes) ) {
133             <A  id="notes_tablink_<% $classnum %>"
134                 HREF="javascript:display_notes_classnum(<% $classnum %>)"
135                 style="font-weight: <% $classnum == 0 ? 'bold' : 'normal' %>"
136             ><% $classes{$classnum} %></A>
137 %       }
138     <BR>
139 % }
140
141 % }
142 <%init>
143
144 use HTML::Defang;
145
146 my $conf = new FS::Conf;
147 my $curuser = $FS::CurrentUser::CurrentUser;
148
149 my(%opt) = @_;
150
151 my $cust_main = $opt{'cust_main'};
152 my $custnum = $cust_main->custnum;
153
154 my (@notes) = $cust_main->notes($conf->exists('note-classes') && $conf->config('note-classes') == 2);
155
156 #subroutines
157
158 sub note_datestr {
159   my($note, $conf, $bgcolor) = @_ or return '';
160   my $td = qq{<TD CLASS="grid" BGCOLOR="$bgcolor" ALIGN="right">};
161   my $format = "$td%b&nbsp;%o,&nbsp;%Y</TD>";
162   $format .= "$td%l:%M%P</TD>"
163     if $conf->exists('cust_main_note-display_times');
164   ( my $strip = time2str($format, $note->_date) ) =~ s/ (\d)/$1/g;
165   $strip;
166 }
167
168 </%init>