Diff for /loncom/interface/loncommon.pm between versions 1.255 and 1.256

version 1.255, 2005/03/10 00:21:48 version 1.256, 2005/03/18 00:18:40
Line 835  ENDTEMPLATE Line 835  ENDTEMPLATE
   
 =pod  =pod
   
   =item * change_content_javascript():
   
   This and the next function allow you to create small sections of an
   otherwise static HTML page that you can update on the fly with
   Javascript, even in Netscape 4.
   
   The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
   must be written to the HTML page once. It will prove the Javascript
   function "change(name, content)". Calling the change function with the
   name of the section 
   you want to update, matching the name passed to C<changable_area>, and
   the new content you want to put in there, will put the content into
   that area.
   
   B<Note>: Netscape 4 only reserves enough space for the changable area
   to contain room for the original contents. You need to "make space"
   for whatever changes you wish to make, and be B<sure> to check your
   code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
   it's adequate for updating a one-line status display, but little more.
   This script will set the space to 100% width, so you only need to
   worry about height in Netscape 4.
   
   Modern browsers are much less limiting, and if you can commit to the
   user not using Netscape 4, this feature may be used freely with
   pretty much any HTML.
   
   =cut
   
   sub change_content_javascript {
       # If we're on Netscape 4, we need to use Layer-based code
       if ($ENV{'browser.type'} eq 'netscape' &&
    $ENV{'browser.version'} =~ /^4\./) {
    return (<<NETSCAPE4);
    function change(name, content) {
       doc = document.layers[name+"___escape"].layers[0].document;
       doc.open();
       doc.write(content);
       doc.close();
    }
   NETSCAPE4
       } else {
    # Otherwise, we need to use semi-standards-compliant code
    # (technically, "innerHTML" isn't standard but the equivalent
    # is really scary, and every useful browser supports it
    return (<<DOMBASED);
    function change(name, content) {
       element = document.getElementById(name);
       element.innerHTML = content;
    }
   DOMBASED
       }
   }
   
   =pod
   
   =item * changable_area($name, $origContent):
   
   This provides a "changable area" that can be modified on the fly via
   the Javascript code provided in C<change_content_javascript>. $name is
   the name you will use to reference the area later; do not repeat the
   same name on a given HTML page more then once. $origContent is what
   the area will originally contain, which can be left blank.
   
   =cut
   
   sub changable_area {
       my ($name, $origContent) = @_;
   
       if ($ENV{'browser.type'} eq 'netscape' &&
    $ENV{'browser.version'} =~ /^4\./) {
    # If this is netscape 4, we need to use the Layer tag
    return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
       } else {
    return "<span id='$name'>$origContent</span>";
       }
   }
   
   =pod
   
   =back
   
   =head1 Excel and CSV file utility routines
   
   =over 4
   
   =cut
   
   ###############################################################
   ###############################################################
   
   =pod
   
 =item * csv_translate($text)   =item * csv_translate($text) 
   
 Translate $text to allow it to be output as a 'comma separated values'   Translate $text to allow it to be output as a 'comma separated values' 
Line 851  sub csv_translate { Line 943  sub csv_translate {
     return $text;      return $text;
 }  }
   
   
 ###############################################################  ###############################################################
 ###############################################################  ###############################################################
   
Line 875  Currently supported formats: Line 966  Currently supported formats:
   
 =item h3  =item h3
   
   =item h4
   
   =item i
   
 =item date  =item date
   
 =back  =back
Line 909  sub define_excel_formats { Line 1004  sub define_excel_formats {
   
 =pod  =pod
   
 =item &create_workbook  =item * create_workbook
   
 Create an Excel worksheet.  If it fails, output message on the  Create an Excel worksheet.  If it fails, output message on the
 request object and return undefs.  request object and return undefs.
Line 952  sub create_workbook { Line 1047  sub create_workbook {
   
 =pod  =pod
   
 =item * change_content_javascript():  =item * create_text_file
   
 This and the next function allow you to create small sections of an  Create a file to write to and eventually make available to the usre.
 otherwise static HTML page that you can update on the fly with  If file creation fails, outputs an error message on the request object and 
 Javascript, even in Netscape 4.  return undefs.
   
 The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)  
 must be written to the HTML page once. It will prove the Javascript  
 function "change(name, content)". Calling the change function with the  
 name of the section   
 you want to update, matching the name passed to C<changable_area>, and  
 the new content you want to put in there, will put the content into  
 that area.  
   
 B<Note>: Netscape 4 only reserves enough space for the changable area  Inputs: Apache request object, and file suffix
 to contain room for the original contents. You need to "make space"  
 for whatever changes you wish to make, and be B<sure> to check your  
 code in Netscape 4. This feature in Netscape 4 is B<not> powerful;  
 it's adequate for updating a one-line status display, but little more.  
 This script will set the space to 100% width, so you only need to  
 worry about height in Netscape 4.  
   
 Modern browsers are much less limiting, and if you can commit to the  Returns (undef) on failure, 
 user not using Netscape 4, this feature may be used freely with      Filehandle and filename on success.
 pretty much any HTML.  
   
 =cut  =cut
   
 sub change_content_javascript {  ###############################################################
     # If we're on Netscape 4, we need to use Layer-based code  ###############################################################
     if ($ENV{'browser.type'} eq 'netscape' &&  sub create_text_file {
  $ENV{'browser.version'} =~ /^4\./) {      my ($r,$suffix) = @_;
  return (<<NETSCAPE4);      if (! defined($suffix)) { $suffix = 'txt'; };
  function change(name, content) {      my $fh;
     doc = document.layers[name+"___escape"].layers[0].document;      my $filename = '/prtspool/'.
     doc.open();          $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
     doc.write(content);          time.'_'.rand(1000000000).'.'.$suffix;
     doc.close();      $fh = Apache::File->new('>/home/httpd'.$filename);
  }      if (! defined($fh)) {
 NETSCAPE4          $r->log_error("Couldn't open $filename for output $!");
     } else {          $r->print("Problems occured in creating the output file.  ".
  # Otherwise, we need to use semi-standards-compliant code                    "This error has been logged.  ".
  # (technically, "innerHTML" isn't standard but the equivalent                    "Please alert your LON-CAPA administrator.");
  # is really scary, and every useful browser supports it  
  return (<<DOMBASED);  
  function change(name, content) {  
     element = document.getElementById(name);  
     element.innerHTML = content;  
  }  
 DOMBASED  
     }      }
       return ($fh,$filename)
 }  }
   
 =pod  
   
 =item * changable_area($name, $origContent):  =pod 
   
 This provides a "changable area" that can be modified on the fly via  
 the Javascript code provided in C<change_content_javascript>. $name is  
 the name you will use to reference the area later; do not repeat the  
 same name on a given HTML page more then once. $origContent is what  
 the area will originally contain, which can be left blank.  
   
 =cut  
   
 sub changable_area {  
     my ($name, $origContent) = @_;  
   
     if ($ENV{'browser.type'} eq 'netscape' &&  
  $ENV{'browser.version'} =~ /^4\./) {  
  # If this is netscape 4, we need to use the Layer tag  
  return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";  
     } else {  
  return "<span id='$name'>$origContent</span>";  
     }  
 }  
   
 =pod  
   
 =back  =back
   

Removed from v.1.255  
changed lines
  Added in v.1.256


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>