This commit was generated by cvs2svn to compensate for changes in r9232,
[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 <% header('Note ' . ($notenum ? 'updated' : 'added') ) %>
6     <SCRIPT TYPE="text/javascript">
7       window.top.location.reload();
8     </SCRIPT>
9     </BODY></HTML>
10 % }
11 <%init>
12
13 $cgi->param('custnum') =~ /^(\d+)$/
14   or die "Illegal custnum: ". $cgi->param('custnum');
15 my $custnum = $1;
16
17 $cgi->param('notenum') =~ /^(\d*)$/
18   or die "Illegal notenum: ". $cgi->param('notenum');
19 my $notenum = $1;
20
21 my $new = new FS::cust_main_note ( {
22   notenum  => $notenum,
23   custnum  => $custnum,
24   _date    => time,
25   usernum  => $FS::CurrentUser::CurrentUser->usernum,
26   comments => scalar($cgi->param('comment')),
27 } );
28
29 my $error;
30 if ($notenum) {
31
32   die "access denied"
33     unless $FS::CurrentUser::CurrentUser->access_right('Edit customer note');
34
35   my $old  = qsearchs('cust_main_note', { 'notenum' => $notenum });
36   $error = "No such note: $notenum" unless $old;
37   unless ($error) {
38     map { $new->$_($old->$_) } ('_date', 'otaker');
39     $error = $new->replace($old);
40   }
41
42 } else {
43
44   die "access denied"
45     unless $FS::CurrentUser::CurrentUser->access_right('Add customer note');
46
47   $error = $new->insert;
48 }
49
50 </%init>