Annotation of rat/lonratparms.pm, revision 1.20

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

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