File:  [LON-CAPA] / rat / lonratparms.pm
Revision 1.9: download - view: text, annotated - select for diffs
Mon Mar 11 19:54:31 2002 UTC (22 years, 1 month ago) by matthew
Branches: MAIN
CVS tags: stable_2002_april, HEAD
map to foreach, minor misc cleanups.

    1: # The LearningOnline Network with CAPA
    2: # Set parameters inside of the RAT
    3: #
    4: # $Id: lonratparms.pm,v 1.9 2002/03/11 19:54:31 matthew Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: # (Search Catalog
   29: #
   30: # (Internal Server Error Handler
   31: #
   32: # (Login Screen
   33: # 5/21/99,5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14,
   34: # 1/14/00,5/29,5/30,6/1,6/29,7/1,11/9 Gerd Kortemeyer)
   35: #
   36: # 3/1/1 Gerd Kortemeyer)
   37: #
   38: # 3/1 Gerd Kortemeyer)
   39: #
   40: # 03/03/01,06/15,06/25,06/26,06/30,07/02,07/03,07/04 Gerd Kortemeyer
   41: # 03/11/02 Matthew Hall
   42: #
   43: package Apache::lonratparms;
   44: 
   45: use strict;
   46: use Apache::Constants qw(:common);
   47: 
   48: sub handler {
   49:     my $r = shift;
   50:     $r->content_type('text/html');
   51:     $r->send_http_header;
   52:     return OK if $r->header_only;
   53: 
   54: # Get query string for limited number of parameters
   55: 
   56:     foreach (split(/&/,$ENV{'QUERY_STRING'})) {
   57:        my ($name, $value) = split(/=/,$_);
   58:        $value =~ tr/+/ /;
   59:        $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
   60:        if (($name eq 'url') || ($name eq 'parms') || 
   61:            ($name eq 'resid')) {
   62:            unless ($ENV{'form.'.$name}) {
   63:               $ENV{'form.'.$name}=$value;
   64: 	   }
   65:        }
   66:     }
   67: 
   68: 
   69: # ------------------------------------------------------------------- Read file
   70: 
   71:   my $uri=$ENV{'form.url'}.'.meta';
   72:   
   73:   my %content;
   74:   my %type;
   75:   my %display;
   76:   my %value;
   77:   
   78:   foreach (split(/\,/,&Apache::lonnet::metadata($uri,'keys'))) {
   79:       if ($_=~/^parameter\_/) {
   80:          $content{$_}=&Apache::lonnet::metadata($uri,$_);
   81:          $type{$_}=&Apache::lonnet::metadata($uri,$_.'.type');
   82:          $display{$_}=&Apache::lonnet::metadata($uri,$_.'.display');
   83:       }
   84:   }
   85: 
   86: # ---------------------------------------------------------- Current Parameters
   87: 
   88:   foreach (split(/\:/,$ENV{'form.parms'})) {
   89:       my ($ptype,$pname,$pvalue)=split(/\_\_\_/,$_);
   90:       unless ($type{$pname}) { $type{$pname}=$ptype; }
   91:       $value{$pname}=$pvalue;
   92:   } 
   93:   
   94: # --------------------------------------------------- Print input screen header
   95:     $r->print(<<ENDHEADER);
   96: <html>
   97: <head>
   98: <title>The LearningOnline Network with CAPA</title>
   99: <script language="JavaScript">
  100: 
  101:     function pclose() {
  102:         parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
  103:                  "height=350,width=350,scrollbars=no,menubar=no");
  104:         parmwin.close();
  105:     }
  106: 
  107:     function pjump(type,dis,value,marker,ret,call) {
  108:         parmwin=window.open("/adm/rat/parameter.html?type="+escape(type)
  109:                  +"&value="+escape(value)+"&marker="+escape(marker)
  110:                  +"&return="+escape(ret)
  111:                  +"&call="+escape(call)+"&name="+escape(dis),"LONCAPAparms",
  112:                  "height=350,width=350,scrollbars=no,menubar=no");
  113: 
  114:     }
  115: 
  116:     function stpr() {
  117:         eval("document.parameters."+document.parameters.pres_marker.value+
  118:             ".value=document.parameters.pres_value.value");
  119:         pclose();
  120:     }
  121: 
  122: 
  123: function setparms() {
  124: ENDHEADER
  125:     $r->print('var colon=""; opener.objparms['.$ENV{'form.resid'}.']="";');
  126:     map {
  127:        $r->print("\nif (document.parameters.def_".$_.
  128:        '.checked) { opener.objparms['.$ENV{'form.resid'}.
  129:        ']+=colon+"'.$type{$_}.
  130:        '___'.$_.'___"+document.parameters.'.$_.'.value; colon=":"; }'); 
  131:     } keys %content;
  132:     $r->print(<<ENDDOCUMENT);
  133:     opener.save();
  134:     window.close();
  135: }
  136: </script>
  137: </head>
  138: <body bgcolor="#FFFFFF">
  139: <h1>Set Resource Parameters in Map</h1>
  140: <form action="javascript:setparms();" method="post" name="parameters">
  141: <input type="hidden" value='' name="pres_value">
  142: <input type="hidden" value='' name="pres_type">
  143: <input type="hidden" value='' name="pres_marker">
  144: <table border=2>
  145: <tr><th>Parameter</th><th>Default</th><th>Value</th><th>Set?</th></tr>
  146: ENDDOCUMENT
  147:     foreach (keys(%content)) {
  148:         my $cur=$content{$_};
  149:         # Should if(defined($value{$_})) be if(exists($value{$_})) ?
  150:         if (defined($value{$_})) { $cur=$value{$_}; };
  151:         $r->print(<<"END");
  152: <tr><td><b>$display{$_}</b><br><tt>$_</tt></td>
  153: <td>&nbsp;$content{$_}</td>
  154: <td><input type="text" size="10" name="$_" value="$cur">&nbsp;
  155: <a href='javascript:pjump("$type{$_}","$display{$_}",document.parameters.$_.value,"$_","parameters.pres","stpr");'>Enter</a></td>
  156: <td><input type="checkbox" name="def_$_" 
  157: END
  158:         if ($value{$_}) { $r->print(' checked'); }
  159:         $r->print('></td></tr>');
  160:     }
  161:     $r->print(
  162:         '</table><br><input type="submit" value="Set"></form></body></html>');
  163:     return OK;
  164: } 
  165: 
  166: 1;
  167: __END__
  168: 

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