File:  [LON-CAPA] / rat / lonratparms.pm
Revision 1.23: download - view: text, annotated - select for diffs
Thu Apr 7 06:56:27 2005 UTC (19 years ago) by albertel
Branches: MAIN
CVS tags: version_2_1_X, version_2_1_3, version_2_1_2, version_2_1_1, version_2_1_0, version_2_0_X, version_2_0_99_1, version_2_0_2, version_2_0_1, version_2_0_0, version_1_99_3, version_1_99_2, version_1_99_1_tmcc, version_1_99_1, version_1_99_0_tmcc, version_1_99_0, HEAD
- ENV -> env

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

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