eb421eb3735a20ab54cd1401133491144fcc2154
[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 %sticky_color = ( '#eeeeee' => '#ffff66',
38 %                      '#ffffff' => '#ffffb8',
39 %                    );
40 %
41 % my $bgcolor = '';
42 % my $last_classnum = -1;
43 % my $skipheader = 0;
44 % my %classes = ();
45 %
46 % foreach my $note (@notes) {
47 %
48 %   if ( $bgcolor eq $bgcolor1 ) {
49 %     $bgcolor = $bgcolor2;
50 %   } else {
51 %     $bgcolor = $bgcolor1;
52 %   }
53 %
54 %   my $pop = popurl(3);
55 %   my $notenum = $note->notenum;
56 %   my $onclick = include( '/elements/popup_link_onclick.html',
57 %                            'action'      => popurl(2).
58 %                                             'edit/cust_main_note.cgi'.
59 %                                             "?custnum=$custnum".
60 %                                             ";notenum=$notenum",
61 %                            'actionlabel' => emt('Edit customer note'),
62 %                            'width'       => 616,
63 %                            'height'      => 575,
64 %                            'frame'       => 'top',
65 %                        );
66 %   my $clickjs = qq!onclick="$onclick"!;
67 %
68 %   my $edit = '';
69 %   if ($curuser->access_right('Edit customer note') ) {
70 %     my $delete_url = $fsurl.'misc/delete-note.html?'.$notenum;
71 %     $edit = qq! <A HREF="javascript:void(0);" $clickjs>(!.emt('edit').')</A>'.
72 %             qq! <A HREF="$delete_url" !.
73 %             qq! onclick="return confirm('Delete this note?')">!.
74 %             '('.emt('delete').')</A>';
75 %   }
76 %
77 % if ( $last_classnum != $note->classnum && !$skipheader ) {
78 % my $tmp_classnum = $note->classnum ? $note->classnum : 0;
79 % $classes{$tmp_classnum} = $note->classname ne '' ? $note->classname 
80 %                                                    : emt('Other');
81 % if ( $last_classnum != -1 ) {
82     </TABLE>
83   </DIV>
84 % }
85 % my $display = ($tmp_classnum == 0 || !$conf->exists('note-classes') 
86 %                                   || $conf->config('note-classes') < 2) 
87 %                                                           ? 'block' : 'none';
88         <DIV    id="notes_<% $tmp_classnum %>"
89                 style="display:<% $display %>"
90         >
91         <& /elements/table-grid.html &>
92         <THEAD>
93         <TR>
94             <TH CLASS="grid" BGCOLOR="#cccccc"><% mt('Date') |h %></TH>
95 %   if ( $conf->exists('cust_main_note-display_times') ) {
96             <TH CLASS="grid" BGCOLOR="#cccccc"><% mt('Time') |h %></TH>
97 %   }
98             <TH CLASS="grid" BGCOLOR="#cccccc"><% mt('Employee') |h %></TH>
99 %   if ($conf->exists('note-classes') && $conf->config('note-classes') == 1) {
100             <TH CLASS="grid" BGCOLOR="#cccccc"><% mt('Class') |h %></TH>
101 %   }
102             <TH CLASS="grid" BGCOLOR="#cccccc"><% mt('Note') |h %></TH>
103 %   if ($curuser->access_right('Edit customer note') ) {
104             <TH CLASS="grid" BGCOLOR="#cccccc">&nbsp;</TH>
105 %   }
106         </TR>
107         </THEAD>
108 % $skipheader = (!$conf->exists('note-classes') || $conf->config('note-classes') < 2);
109 % $last_classnum = $note->classnum;
110 % }
111
112 % my $color = $note->sticky ? $sticky_color{$bgcolor} : $bgcolor;
113
114     <TR>
115       <% note_datestr($note,$conf,$color) %>
116       <TD CLASS="grid" BGCOLOR="<% $color %>">
117         &nbsp;<% $note->usernum ? $note->access_user->name : $note->otaker %>
118       </TD>
119 % if ($conf->exists('note-classes') && $conf->config('note-classes') == 1) {
120       <TD CLASS="grid" BGCOLOR="<% $color %>">
121         <% $note->classname %>   
122       </TD>
123 % }
124       <TD CLASS="grid" BGCOLOR="<% $color %>">
125         <% $note->comments | defang %>
126       </TD>
127 % if($edit) {
128       <TD CLASS="grid" BGCOLOR="<% $color %>"><% $edit %></TD>
129 % }
130     </TR>
131
132 % } #end display notes
133
134 </TABLE>
135 </DIV>
136
137 % if ( $conf->exists('note-classes') && $conf->config('note-classes') == 2 ) {
138 %       my($classnum,$classname);
139 <% mt('Show notes of class:') |h %> &nbsp; 
140 %       foreach my $classnum ( sort { $b <=> $a } (keys %classes) ) {
141             <A  id="notes_tablink_<% $classnum %>"
142                 HREF="javascript:display_notes_classnum(<% $classnum %>)"
143                 style="font-weight: <% $classnum == 0 ? 'bold' : 'normal' %>"
144             ><% $classes{$classnum} %></A>
145 %       }
146     <BR>
147 % }
148
149 % }
150 <%init>
151
152 use HTML::Defang;
153
154 my $conf = new FS::Conf;
155 my $curuser = $FS::CurrentUser::CurrentUser;
156
157 my(%opt) = @_;
158
159 my $cust_main = $opt{'cust_main'};
160 my $custnum = $cust_main->custnum;
161
162 my (@notes) = $cust_main->notes($conf->exists('note-classes') && $conf->config('note-classes') == 2);
163
164 #subroutines
165
166 sub note_datestr {
167   my($note, $conf, $bgcolor) = @_ or return '';
168   my $td = qq{<TD CLASS="grid" BGCOLOR="$bgcolor" ALIGN="right">};
169   my $format = "$td%b&nbsp;%o,&nbsp;%Y</TD>";
170   $format .= "$td%l:%M%P</TD>"
171     if $conf->exists('cust_main_note-display_times');
172   ( my $strip = time2str($format, $note->_date) ) =~ s/ (\d)/$1/g;
173   $strip;
174 }
175
176 </%init>