editable notes
authorjeff <jeff>
Fri, 27 Oct 2006 17:01:31 +0000 (17:01 +0000)
committerjeff <jeff>
Fri, 27 Oct 2006 17:01:31 +0000 (17:01 +0000)
FS/FS/AccessRight.pm
httemplate/edit/cust_main_note.cgi
httemplate/edit/process/cust_main_note.cgi
httemplate/elements/overlibmws_crossframe.js [new file with mode: 0644]
httemplate/view/cust_main/notes.html

index 64c4f6b..5370e22 100644 (file)
@@ -93,6 +93,7 @@ assigned to users and/or groups.
   'Complimentary customer', #aka users-allow_comp 
   'Delete customer', #aka. deletecustomers #Enable customer deletions. Be very careful! Deleting a customer will remove all traces that this customer ever existed! It should probably only be used when auditing a legacy database. Normally, you cancel all of a customers' packages if they cancel service.
   'Add customer note',
+  'Edit customer note',
 
 ###
 # customer package rights
index 468ef00..303895b 100755 (executable)
@@ -1,4 +1,4 @@
-<% include('/elements/header-popup.html', 'Add Customer Note') %>
+<% include('/elements/header-popup.html', "$action Customer Note") %>
 
 % if ( $cgi->param('error') ) { 
   <FONT SIZE="+1" COLOR="#ff0000">Error: <% $cgi->param('error') %></FONT>
@@ -7,6 +7,7 @@
 
 <FORM ACTION="<% popurl(1) %>process/cust_main_note.cgi" METHOD=POST>
 <INPUT TYPE="hidden" NAME="custnum" VALUE="<% $custnum %>">
+<INPUT TYPE="hidden" NAME="notenum" VALUE="<% $notenum %>">
 
 
 <BR><BR>
 </TEXTAREA>
 
 <BR><BR>
-<INPUT TYPE="submit" VALUE="Add note">
+<INPUT TYPE="submit" VALUE="<% $notenum ? "Apply Changes" : "Add Note" %>">
 
 </FORM>
 </BODY>
 </HTML>
 
 <%init>
-my($custnum, $comment); 
+my($custnum, $comment, $notenum, $action); 
 $comment = '';
 
 if ( $cgi->param('error') ) {
   $comment     = $cgi->param('comment');
+}elsif ($cgi->param('notenum')) {
+  $cgi->param('notenum') =~ /^(\d+)$/;
+  $notenum = $1;
+  die "illegal query ". $cgi->keywords unless $notenum;
+  my $note = qsearchs('cust_main_note', { 'notenum' => $notenum });
+  die "no such note: ". $notenum unless $note;
+  $comment = $note->comments;
 }
+
+$cgi->param('notenum') =~ /^(\d+)$/;
+$notenum = $1;
+
 $cgi->param('custnum') =~ /^(\d+)$/;
 $custnum     = $1;
 
 die "illegal query ". $cgi->keywords unless $custnum;
 
+$action = $notenum ? 'Edit' : 'Add';
+
 </%init>
 
index d9251f0..b94d227 100755 (executable)
@@ -4,18 +4,33 @@
 %  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 = $new->insert;
+%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);
@@ -23,7 +38,7 @@
 %}
 %
 %    
-<% header('Note added') %>
+<% header('Note ' . ($notenum ? 'updated' : 'added') ) %>
     <SCRIPT TYPE="text/javascript">
       window.top.location.reload();
     </SCRIPT>
diff --git a/httemplate/elements/overlibmws_crossframe.js b/httemplate/elements/overlibmws_crossframe.js
new file mode 100644 (file)
index 0000000..6b21c42
--- /dev/null
@@ -0,0 +1,44 @@
+/*\r
+ overlibmws_crossframe.js plug-in module - Copyright Foteos Macrides 2003-2006\r
+   For support of FRAME.\r
+   Initial: August 3, 2003 - Last Revised: November 2, 2004\r
+ See the Change History and Command Reference for overlibmws via:\r
+\r
+       http://www.macridesweb.com/oltest/\r
+\r
+ Published under an open source license: http://www.macridesweb.com/oltest/license.html\r
+*/\r
+\r
+OLloaded=0;\r
+OLregCmds('frame');\r
+\r
+function OLparseCrossframe(pf,i,ar){\r
+var k=i,v;\r
+if(k<ar.length){\r
+if(ar[k]==FRAME){v=ar[++k];if(pf=='ol_')ol_frame=v;else OLoptFRAME(v);return k;}}\r
+return -1;\r
+}\r
+\r
+function OLgetFrameRef(thisFrame,ofrm){\r
+var i,v,retVal='';for(i=0;i<thisFrame.length;i++){if((((thisFrame[i].length>0)))&&(((OLns4))||\r
+((OLie4)&&(v=thisFrame[i].document.all.tags('iframe'))!=null&&v.length==0)||\r
+((OLns6)&&(v=thisFrame[i].document.getElementsByTagName('iframe'))!=null&&v.length==0))){\r
+retVal=OLgetFrameRef(thisFrame[i],ofrm);if(retVal=='')continue;}\r
+else if(thisFrame[i]!=ofrm)continue;retVal='['+i+']'+retVal;break;}\r
+return retVal;\r
+}\r
+\r
+function OLoptFRAME(frm){\r
+o3_frame=OLmkLyr('overDiv',frm)?frm:self;if(o3_frame!=self){\r
+var l,tFrm=OLgetFrameRef(top.frames,o3_frame),sFrm=OLgetFrameRef(top.frames,ol_frame);\r
+if(sFrm.length==tFrm.length) {l=tFrm.lastIndexOf('[');if(l){\r
+while(sFrm.substring(0,l)!=tFrm.substring(0,l))l=tFrm.lastIndexOf('[',l-1);\r
+tFrm=tFrm.substr(l);sFrm=sFrm.substr(l);}}var i,k,cnt=0,p='',str=tFrm;\r
+while((k=str.lastIndexOf('['))!= -1){cnt++;str=str.substring(0,k);}\r
+for(i=0;i<cnt;i++)p=p+'parent.';OLfnRef=p+'frames'+sFrm+'.';}\r
+}\r
+\r
+OLregCmdLineFunc(OLparseCrossframe);\r
+\r
+OLcrossframePI=1;\r
+OLloaded=1;\r
index c1a33b0..75bf30e 100755 (executable)
@@ -1,5 +1,6 @@
 %
 % my $conf = new FS::Conf;
+% my $curuser = $FS::CurrentUser::CurrentUser;
 %
 % $cgi->param('custnum') =~ /^(\d+)$/
 %   or die "No customer specified (bad URL)!";
@@ -20,6 +21,11 @@ body { background: #e8e8e8 }
 
 </STYLE>
 
+<SCRIPT TYPE="text/javascript" SRC="/elements/overlibmws.js"></SCRIPT>
+<SCRIPT TYPE="text/javascript" SRC="/elements/overlibmws_iframe.js"></SCRIPT>
+<SCRIPT TYPE="text/javascript" SRC="/elements/overlibmws_crossframe.js"></SCRIPT>
+<SCRIPT TYPE="text/javascript" SRC="/elements/iframecontentmws.js"></SCRIPT>
+
 <TABLE CLASS="inv" CELLSPACING=0 CELLPADDING=0 BORDER=0 >
 
 %#<% include('/elements/table-grid.html') %>
@@ -35,12 +41,27 @@ body { background: #e8e8e8 }
 %     $bgcolor = $bgcolor1;
 %   }
 %
+%   my $pop = popurl(3);
+%   my $notenum = $note->notenum;
+%   my $clickjs = qq!onclick="overlib( OLiframeContent('${pop}edit/! .
+%                 qq!cust_main_note.cgi?custnum=$custnum&! .
+%                 qq!notenum=$notenum', 616, ! .
+%                 qq!386, 'cust_main_note_popup' ), CAPTION, 'Edit customer ! .
+%                 qq!note', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, ! .
+%                 qq!CLOSECLICK, FRAME, top); return false;"!;
 %
+%   my ($el, $eel);
+%   if ($curuser->access_right('Edit customer note') ) {
+%     $el  = qq!<A HREF="javascript:void(0);" $clickjs>!;
+%     $eel = qq!</A>!;
+%   }else{
+%     $el = $eel = '';
+%   }
 
 <TR>
-  <% note_datestr($note,$conf,$bgcolor) %>
+  <% note_datestr($note,$conf,$bgcolor, $el, $eel) %>
   <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
-    &nbsp;<%$note->otaker%>&nbsp;
+    <% $el %> &nbsp;<%$note->otaker%>&nbsp; <% $eel %>
   </TD>
   <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
     &nbsp;<%$note->comments%>
@@ -58,14 +79,14 @@ body { background: #e8e8e8 }
 %#subroutines
 %
 %sub note_datestr {
-% my($note, $conf, $bgcolor) = @_ or return '';
-% my $format=qq{<TD class="inv" bgcolor="$bgcolor" align="left"><B>%b</B></TD>}.
-%            qq{<TD class="inv" bgcolor="$bgcolor" align="right"><B>&nbsp;%o,</B></TD>}.
-%            qq{<TD class="inv" bgcolor="$bgcolor" align="right"><B>&nbsp;%Y&nbsp;</B></TD>};
-% $format .= qq{<TD class="inv" bgcolor="$bgcolor" ALIGN="right"><B>&nbsp;%l</TD>}.
-%            qq{<TD class="inv" bgcolor="$bgcolor" ALIGN="center"><B>:</B></TD>}.
-%            qq{<TD class="inv" bgcolor="$bgcolor" ALIGN="left"><B>%M</B></TD>}.
-%            qq{<TD class="inv" bgcolor="$bgcolor" ALIGN="left"><B>&nbsp;%P&nbsp;</B></TD>}
+% my($note, $conf, $bgcolor, $el, $eel) = @_ or return '';
+% my $format=qq{<TD class="inv" bgcolor="$bgcolor" align="left">$el<B>%b</B>$eel</TD>}.
+%            qq{<TD class="inv" bgcolor="$bgcolor" align="right">$el<B>&nbsp;%o,</B>$eel</TD>}.
+%            qq{<TD class="inv" bgcolor="$bgcolor" align="right">$el<B>&nbsp;%Y&nbsp;</B>$eel</TD>};
+% $format .= qq{<TD class="inv" bgcolor="$bgcolor" ALIGN="right">$el<B>&nbsp;%l$eel</TD>}.
+%            qq{<TD class="inv" bgcolor="$bgcolor" ALIGN="center">$el<B>:</B>$eel</TD>}.
+%            qq{<TD class="inv" bgcolor="$bgcolor" ALIGN="left">$el<B>%M</B>$eel</TD>}.
+%            qq{<TD class="inv" bgcolor="$bgcolor" ALIGN="left">$el<B>&nbsp;%P&nbsp;</B>$eel</TD>}
 %     if $conf->exists('cust_main_note-display_times');
 %   ( my $strip = time2str($format, $note->_date) ) =~ s/ (\d)/$1/g;
 %   $strip;