Annotation of rat/lonratparms.pm, revision 1.15

1.1       www         1: # The LearningOnline Network with CAPA
                      2: # Set parameters inside of the RAT
                      3: #
1.15    ! matthew     4: # $Id: lonratparms.pm,v 1.14 2003/02/25 21:49:45 albertel Exp $
1.8       www         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: #
1.1       www        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: #
1.7       www        40: # 03/03/01,06/15,06/25,06/26,06/30,07/02,07/03,07/04 Gerd Kortemeyer
1.9       matthew    41: # 03/11/02 Matthew Hall
1.1       www        42: #
                     43: package Apache::lonratparms;
                     44: 
                     45: use strict;
                     46: use Apache::Constants qw(:common);
1.15    ! matthew    47: use Apache::lonhtmlcommon();
1.1       www        48: 
                     49: sub handler {
                     50:     my $r = shift;
                     51:     $r->content_type('text/html');
                     52:     $r->send_http_header;
                     53:     return OK if $r->header_only;
                     54: 
1.2       www        55: # Get query string for limited number of parameters
                     56: 
1.10      stredwic   57:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.11      www        58:                                             ['url','parms','resid']);
1.2       www        59: 
                     60: # ------------------------------------------------------------------- Read file
                     61: 
                     62:   my $uri=$ENV{'form.url'}.'.meta';
1.3       www        63:   
                     64:   my %content;
                     65:   my %type;
1.5       www        66:   my %display;
1.3       www        67:   my %value;
                     68:   
1.9       matthew    69:   foreach (split(/\,/,&Apache::lonnet::metadata($uri,'keys'))) {
1.4       www        70:       if ($_=~/^parameter\_/) {
                     71:          $content{$_}=&Apache::lonnet::metadata($uri,$_);
1.5       www        72:          $type{$_}=&Apache::lonnet::metadata($uri,$_.'.type');
                     73:          $display{$_}=&Apache::lonnet::metadata($uri,$_.'.display');
1.4       www        74:       }
1.9       matthew    75:   }
1.2       www        76: 
1.12      www        77: # -------------------------------------- Additional parms for certain resources
                     78: 
                     79:     if ($uri=~/\.(sequence|page)\.meta$/) {
                     80:         $content{'parameter_randompick'}='';
                     81:         $type{'parameter_randompick'}='int_pos';
                     82: 	$display{'parameter_randompick'}='Randomly pick number of resources';
1.13      www        83:         
                     84:         $content{'parameter_randompickseed'}='';
                     85:         $type{'parameter_randompickseed'}='int_pos';
                     86: 	$display{'parameter_randompickseed'}=
                     87:  'Random seed for randomly picking number of resources (optional, only set if you know what you are doing)';
1.12      www        88:     } else {
                     89:         $content{'parameter_mapalias'}='';
                     90:         $type{'parameter_mapalias'}='string';
                     91: 	$display{'parameter_mapalias'}='Resource alias name for conditions';
1.14      albertel   92:     }
                     93:     if ($uri=~/\.(problem|exam|quiz|assess|survey|form|library)\.meta$/) {
                     94: 	$content{'parameter_hiddenparts'}='';
                     95:         $type{'parameter_hiddenparts'}='string';
                     96: 	$display{'parameter_hiddenparts'}=
                     97: 	    'A comma separted list of Part Ids to not display.';
1.12      www        98:     }
1.3       www        99: # ---------------------------------------------------------- Current Parameters
1.2       www       100: 
1.9       matthew   101:   foreach (split(/\:/,$ENV{'form.parms'})) {
1.3       www       102:       my ($ptype,$pname,$pvalue)=split(/\_\_\_/,$_);
1.5       www       103:       unless ($type{$pname}) { $type{$pname}=$ptype; }
1.3       www       104:       $value{$pname}=$pvalue;
1.9       matthew   105:   } 
1.3       www       106:   
                    107: # --------------------------------------------------- Print input screen header
1.15    ! matthew   108:     my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.3       www       109:     $r->print(<<ENDHEADER);
1.1       www       110: <html>
                    111: <head>
                    112: <title>The LearningOnline Network with CAPA</title>
1.3       www       113: <script language="JavaScript">
1.7       www       114: 
                    115:     function pclose() {
                    116:         parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
                    117:                  "height=350,width=350,scrollbars=no,menubar=no");
                    118:         parmwin.close();
                    119:     }
                    120: 
1.15    ! matthew   121:     $pjump_def
1.7       www       122: 
                    123:     function stpr() {
                    124:         eval("document.parameters."+document.parameters.pres_marker.value+
                    125:             ".value=document.parameters.pres_value.value");
                    126:         pclose();
                    127:     }
                    128: 
                    129: 
1.3       www       130: function setparms() {
                    131: ENDHEADER
1.6       www       132:     $r->print('var colon=""; opener.objparms['.$ENV{'form.resid'}.']="";');
1.3       www       133:     map {
                    134:        $r->print("\nif (document.parameters.def_".$_.
1.5       www       135:        '.checked) { opener.objparms['.$ENV{'form.resid'}.
1.6       www       136:        ']+=colon+"'.$type{$_}.
                    137:        '___'.$_.'___"+document.parameters.'.$_.'.value; colon=":"; }'); 
1.3       www       138:     } keys %content;
                    139:     $r->print(<<ENDDOCUMENT);
1.6       www       140:     opener.save();
1.3       www       141:     window.close();
                    142: }
                    143: </script>
1.1       www       144: </head>
                    145: <body bgcolor="#FFFFFF">
1.2       www       146: <h1>Set Resource Parameters in Map</h1>
1.4       www       147: <form action="javascript:setparms();" method="post" name="parameters">
1.7       www       148: <input type="hidden" value='' name="pres_value">
                    149: <input type="hidden" value='' name="pres_type">
                    150: <input type="hidden" value='' name="pres_marker">
1.4       www       151: <table border=2>
                    152: <tr><th>Parameter</th><th>Default</th><th>Value</th><th>Set?</th></tr>
1.1       www       153: ENDDOCUMENT
1.9       matthew   154:     foreach (keys(%content)) {
1.5       www       155:         my $cur=$content{$_};
1.9       matthew   156:         # Should if(defined($value{$_})) be if(exists($value{$_})) ?
1.5       www       157:         if (defined($value{$_})) { $cur=$value{$_}; };
1.9       matthew   158:         $r->print(<<"END");
                    159: <tr><td><b>$display{$_}</b><br><tt>$_</tt></td>
                    160: <td>&nbsp;$content{$_}</td>
                    161: <td><input type="text" size="10" name="$_" value="$cur">&nbsp;
                    162: <a href='javascript:pjump("$type{$_}","$display{$_}",document.parameters.$_.value,"$_","parameters.pres","stpr");'>Enter</a></td>
                    163: <td><input type="checkbox" name="def_$_" 
                    164: END
1.6       www       165:         if ($value{$_}) { $r->print(' checked'); }
                    166:         $r->print('></td></tr>');
1.9       matthew   167:     }
1.3       www       168:     $r->print(
                    169:         '</table><br><input type="submit" value="Set"></form></body></html>');
1.1       www       170:     return OK;
                    171: } 
                    172: 
                    173: 1;
                    174: __END__
1.7       www       175: 

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