RT# 82949 - changes section name from fees to pricing, better opiton
[freeside.git] / httemplate / edit / process / cust_main_note.cgi
1 %if ($error) {
2 %  $cgi->param('error', $error);
3 <% $cgi->redirect(popurl(2). 'cust_main_note.cgi?'. $cgi->query_string ) %>
4 %} else {
5 <& /elements/popup-topreload.html, mt( 'Note '. ($notenum ? 'updated' : 'added') ) &>
6 % }
7 <%init>
8
9 $cgi->param('custnum') =~ /^(\d+)$/
10   or die "Illegal custnum: ". $cgi->param('custnum');
11 my $custnum = $1;
12
13 $cgi->param('notenum') =~ /^(\d*)$/
14   or die "Illegal notenum: ". $cgi->param('notenum');
15 my $notenum = $1;
16
17 $cgi->param('classnum') =~ /^(\d*)$/;
18 my $classnum = $1;
19
20 my $comment = $cgi->param('comment_html') || 
21               join("<br />\n", 
22                 split "(?:\r|\n)+", $cgi->param('comment_plain')
23               );
24
25 my $new = new FS::cust_main_note ( {
26   notenum  => $notenum,
27   custnum  => $custnum,
28   classnum => $classnum ? $classnum : undef,
29   _date    => time,
30   usernum  => $FS::CurrentUser::CurrentUser->usernum,
31   comments => $comment,
32   sticky   => scalar( $cgi->param('sticky') ),
33 } );
34
35 my $error;
36 if ($notenum) {
37
38   die "access denied"
39     unless $FS::CurrentUser::CurrentUser->access_right('Edit customer note');
40
41   my $old  = qsearchs('cust_main_note', { 'notenum' => $notenum });
42   $error = "No such note: $notenum" unless $old;
43   unless ($error) {
44     map { $new->$_($old->$_) } ('_date', 'otaker');
45     $error = $new->replace($old);
46   }
47
48 } else {
49
50   die "access denied"
51     unless $FS::CurrentUser::CurrentUser->access_right('Add customer note');
52
53   $error = $new->insert;
54 }
55
56 </%init>