X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fedit%2Fprocess%2Fcust_main_note.cgi;h=1fd136723c953395fd84f91cbf29ae4c188fcd23;hb=2756019bdb10fe144debfc8d6436468a89954eb3;hp=8b9105bd87ec6ea0d2e5f2209fc8d698315e4d6d;hpb=88a07a3c2aac1fff33bd1f400ee5c0672ce716a0;p=freeside.git

diff --git a/httemplate/edit/process/cust_main_note.cgi b/httemplate/edit/process/cust_main_note.cgi
index 8b9105bd8..1fd136723 100755
--- a/httemplate/edit/process/cust_main_note.cgi
+++ b/httemplate/edit/process/cust_main_note.cgi
@@ -1,52 +1,56 @@
-%
-%
-%$cgi->param('custnum') =~ /^(\d+)$/
-%  or die "Illegal custnum: ". $cgi->param('custnum');
-%my $custnum = $1;
-%
-%$cgi->param('notenum') =~ /^(\d*)$/
-%  or die "Illegal notenum: ". $cgi->param('notenum');
-%my $notenum = $1;
-%
-%my $otaker = $FS::CurrentUser::CurrentUser->name;
-%$otaker = $FS::CurrentUser::CurrentUser->username
-%  if ($otaker eq "User, Legacy");
-%
-%my $new = new FS::cust_main_note ( {
-%  notenum  => $notenum,
-%  custnum  => $custnum,
-%  _date    => time,
-%  otaker   => $otaker,
-%  comments =>  $cgi->param('comment'),
-%} );
-%
-%my $error;
-%if ($notenum){
-%  my $old  = qsearchs('cust_main_note', { 'notenum' => $notenum });
-%  $error = "No such note: $notenum" unless $old;
-%  unless($error){
-%    map { $new->$_($old->$_) } ('_date', 'otaker');
-%    $error = $new->replace($old);
-%  }
-%}else{
-%  $error = $new->insert;
-%}
-%
 %if ($error) {
 %  $cgi->param('error', $error);
-%  print $cgi->redirect(popurl(2). 'cust_main_note.cgi?'. $cgi->query_string );
-%}
-%
-%    
-<% header('Note ' . ($notenum ? 'updated' : 'added') ) %>
-    <SCRIPT TYPE="text/javascript">
-      parent.cust_main_notes.location.reload();
-      try{parent.cust_main_notes.cClick()}
-      catch(err){}
-      try{parent.cClick()}
-      catch(err){}
-    </SCRIPT>
-    </BODY></HTML>
-%
-%
+<% $cgi->redirect(popurl(2). 'cust_main_note.cgi?'. $cgi->query_string ) %>
+%} else {
+<& /elements/popup-topreload.html, mt( 'Note '. ($notenum ? 'updated' : 'added') ) &>
+% }
+<%init>
 
+$cgi->param('custnum') =~ /^(\d+)$/
+  or die "Illegal custnum: ". $cgi->param('custnum');
+my $custnum = $1;
+
+$cgi->param('notenum') =~ /^(\d*)$/
+  or die "Illegal notenum: ". $cgi->param('notenum');
+my $notenum = $1;
+
+$cgi->param('classnum') =~ /^(\d*)$/;
+my $classnum = $1;
+
+my $comment = $cgi->param('comment_html') || 
+              join("<br />\n", 
+                split "(?:\r|\n)+", $cgi->param('comment_plain')
+              );
+
+my $new = new FS::cust_main_note ( {
+  notenum  => $notenum,
+  custnum  => $custnum,
+  classnum => $classnum ? $classnum : undef,
+  _date    => time,
+  usernum  => $FS::CurrentUser::CurrentUser->usernum,
+  comments => $comment,
+  sticky   => scalar( $cgi->param('sticky') ),
+} );
+
+my $error;
+if ($notenum) {
+
+  die "access denied"
+    unless $FS::CurrentUser::CurrentUser->access_right('Edit customer note');
+
+  my $old  = qsearchs('cust_main_note', { 'notenum' => $notenum });
+  $error = "No such note: $notenum" unless $old;
+  unless ($error) {
+    map { $new->$_($old->$_) } ('_date', 'otaker');
+    $error = $new->replace($old);
+  }
+
+} else {
+
+  die "access denied"
+    unless $FS::CurrentUser::CurrentUser->access_right('Add customer note');
+
+  $error = $new->insert;
+}
+
+</%init>