This commit was generated by cvs2svn to compensate for changes in r8690,
[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 $otaker = $FS::CurrentUser::CurrentUser->name;
22 $otaker = $FS::CurrentUser::CurrentUser->username
23   if ($otaker eq "User, Legacy");
24
25 my $new = new FS::cust_main_note ( {
26   notenum  => $notenum,
27   custnum  => $custnum,
28   _date    => time,
29   otaker   => $otaker,
30   comments =>  $cgi->param('comment'),
31 } );
32
33 my $error;
34 if ($notenum) {
35
36   die "access denied"
37     unless $FS::CurrentUser::CurrentUser->access_right('Edit customer note');
38
39   my $old  = qsearchs('cust_main_note', { 'notenum' => $notenum });
40   $error = "No such note: $notenum" unless $old;
41   unless ($error) {
42     map { $new->$_($old->$_) } ('_date', 'otaker');
43     $error = $new->replace($old);
44   }
45
46 } else {
47
48   die "access denied"
49     unless $FS::CurrentUser::CurrentUser->access_right('Add customer note');
50
51   $error = $new->insert;
52 }
53
54 </%init>