File:  [LON-CAPA] / rat / lonratparms.pm
Revision 1.22: download - view: text, annotated - select for diffs
Sat Apr 24 14:23:27 2004 UTC (20 years ago) by www
Branches: MAIN
CVS tags: version_1_3_X, version_1_3_3, version_1_3_2, version_1_3_1, version_1_3_0, version_1_2_X, version_1_2_99_1, version_1_2_99_0, version_1_2_1, version_1_2_0, version_1_1_99_5, version_1_1_99_4, version_1_1_99_3, version_1_1_99_2, version_1_1_99_1, version_1_1_99_0, HEAD
Inside-RAT parameters need to override stored parameters.

    1: # The LearningOnline Network with CAPA
    2: # Set parameters inside of the RAT
    3: #
    4: # $Id: lonratparms.pm,v 1.22 2004/04/24 14:23:27 www 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: 
   29: package Apache::lonratparms;
   30: 
   31: use strict;
   32: use Apache::Constants qw(:common);
   33: use Apache::lonhtmlcommon();
   34: use Apache::lonlocal;
   35: 
   36: sub handler {
   37:     my $r = shift;
   38:     &Apache::loncommon::content_type($r,'text/html');
   39:     $r->send_http_header;
   40:     return OK if $r->header_only;
   41: 
   42: # Get query string for limited number of parameters
   43: 
   44:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
   45:                                             ['url','parms','resid']);
   46: 
   47: # ------------------------------------------------------------------- Read file
   48: 
   49:   my $uri=$ENV{'form.url'}.'.meta';
   50:   
   51:   my %content;
   52:   my %type;
   53:   my %display;
   54:   my %value;
   55:   
   56: # ---------------------------------------------------------- Current Parameters
   57: 
   58:   foreach (split(/\,/,&Apache::lonnet::metadata($uri,'keys'))) {
   59:       if ($_=~/^parameter\_/) {
   60:          $content{$_}=&Apache::lonnet::metadata($uri,$_);
   61:          $type{$_}=&Apache::lonnet::metadata($uri,$_.'.type');
   62:          $display{$_}=&Apache::lonnet::metadata($uri,$_.'.display');
   63:       }
   64:   }
   65: 
   66:   foreach (split(/\:/,$ENV{'form.parms'})) {
   67:       my ($ptype,$pname,$pvalue)=split(/\_\_\_/,$_);
   68:       unless ($pname) { next; }
   69:       unless ($type{$pname}) { $type{$pname}=$ptype; }
   70:       $value{$pname}=$pvalue;
   71:       $content{$pname}=$pvalue;
   72:       $type{$pname}=$ptype;
   73:       $display{$pname}=&mt('Custom Parameter');
   74:   } 
   75:   
   76: # --------------------------------------------------- Print input screen header
   77:     my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
   78:     my $bodytag=&Apache::loncommon::bodytag('Set Resource Parameters in Map');
   79:     my %lt=&Apache::lonlocal::texthash('pa' => 'Parameter',
   80: 			               'de' => 'Default',
   81: 				       'va' => 'Value',
   82: 				       'se' => 'Set');
   83:  
   84:     $r->print(<<ENDHEADER);
   85: <html>
   86: <head>
   87: <title>The LearningOnline Network with CAPA</title>
   88: <script language="JavaScript">
   89: 
   90:     function pclose() {
   91:         parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
   92:                  "height=350,width=350,scrollbars=no,menubar=no");
   93:         parmwin.close();
   94:     }
   95: 
   96:     $pjump_def
   97: 
   98:     function stpr() {
   99:         eval("document.parameters."+document.parameters.pres_marker.value+
  100:             ".value=document.parameters.pres_value.value");
  101:         pclose();
  102:     }
  103: 
  104: 
  105: function setparms() {
  106: ENDHEADER
  107:     $r->print('var colon=""; opener.objparms['.$ENV{'form.resid'}.']="";');
  108:     map {
  109:        $r->print("\nif (document.parameters.def_".$_.
  110:        '.checked) { opener.objparms['.$ENV{'form.resid'}.
  111:        ']+=colon+"'.$type{$_}.
  112:        '___'.$_.'___"+document.parameters.'.$_.'.value; colon=":"; }'); 
  113:     } keys %content;
  114:     $r->print(<<ENDDOCUMENT);
  115:     opener.save();
  116:     window.close();
  117: }
  118: </script>
  119: </head>
  120: $bodytag
  121: <form action="javascript:setparms();" method="post" name="parameters">
  122: <input type="hidden" value='' name="pres_value">
  123: <input type="hidden" value='' name="pres_type">
  124: <input type="hidden" value='' name="pres_marker">
  125: <table border=2>
  126: <tr><th>$lt{'pa'}</th><th>$lt{'de'}</th><th>$lt{'va'}</th><th>$lt{'se'}?</th></tr>
  127: ENDDOCUMENT
  128: ###    %display=&Apache::lonlocal::texthash(%display);
  129:     my $enter=&mt('Enter');
  130:     foreach (sort(keys(%content))) {
  131:         my $cur=$content{$_};
  132:         # Should if(defined($value{$_})) be if(exists($value{$_})) ?
  133:         if (defined($value{$_})) { $cur=$value{$_}; };
  134:         $r->print(<<"END");
  135: <tr><td><b>$display{$_}</b><br><tt>$_</tt></td>
  136: <td>&nbsp;$content{$_}</td>
  137: <td><input type="text" size="10" name="$_" value="$cur">&nbsp;
  138: <a href='javascript:pjump("$type{$_}","$display{$_}",document.parameters.$_.value,"$_","parameters.pres","stpr");'>$enter</a></td>
  139: <td><input type="checkbox" name="def_$_" 
  140: END
  141:         if ($value{$_}) { $r->print(' checked'); }
  142:         $r->print('></td></tr>');
  143:     }
  144:     $r->print(
  145:         '</table><br><input type="submit" value="'.&mt('Set').'"></form></body></html>');
  146:     return OK;
  147: } 
  148: 
  149: 1;
  150: __END__
  151: 

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