Annotation of rat/lonratparms.pm, revision 1.25

1.1       www         1: # The LearningOnline Network with CAPA
                      2: # Set parameters inside of the RAT
                      3: #
1.25    ! jms         4: # $Id: lonratparms.pm,v 1.24 2006/04/04 15:32:12 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.25    ! jms        29: =head1 NAME
        !            30: 
        !            31: Apache::lonratparams
        !            32: 
        !            33: =head1 SYNOPSIS
        !            34: 
        !            35: Handler to set resource parameters inside of
        !            36: the RAT based on metadata.
        !            37: 
        !            38: This is part of the LearningOnline Network with CAPA project
        !            39: described at http://www.lon-capa.org.
        !            40: 
        !            41: =head1 HANDLER SUBROUTINE
        !            42: 
        !            43: handler()
        !            44: 
        !            45: =head1 OTHER SUBROUTINES
        !            46: 
        !            47: =over
        !            48: 
        !            49: =item *
        !            50: 
        !            51: none
        !            52: 
        !            53: =back
        !            54: 
        !            55: =cut
        !            56: 
1.1       www        57: package Apache::lonratparms;
                     58: 
                     59: use strict;
                     60: use Apache::Constants qw(:common);
1.15      matthew    61: use Apache::lonhtmlcommon();
1.16      www        62: use Apache::lonlocal;
1.23      albertel   63: use Apache::lonnet;
1.1       www        64: 
                     65: sub handler {
                     66:     my $r = shift;
1.16      www        67:     &Apache::loncommon::content_type($r,'text/html');
1.1       www        68:     $r->send_http_header;
                     69:     return OK if $r->header_only;
                     70: 
1.2       www        71: # Get query string for limited number of parameters
                     72: 
1.10      stredwic   73:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.11      www        74:                                             ['url','parms','resid']);
1.2       www        75: 
                     76: # ------------------------------------------------------------------- Read file
                     77: 
1.23      albertel   78:   my $uri=$env{'form.url'}.'.meta';
1.3       www        79:   
                     80:   my %content;
                     81:   my %type;
1.5       www        82:   my %display;
1.3       www        83:   my %value;
                     84:   
1.20      www        85: # ---------------------------------------------------------- Current Parameters
                     86: 
1.22      www        87:   foreach (split(/\,/,&Apache::lonnet::metadata($uri,'keys'))) {
                     88:       if ($_=~/^parameter\_/) {
                     89:          $content{$_}=&Apache::lonnet::metadata($uri,$_);
                     90:          $type{$_}=&Apache::lonnet::metadata($uri,$_.'.type');
                     91:          $display{$_}=&Apache::lonnet::metadata($uri,$_.'.display');
                     92:       }
                     93:   }
                     94: 
1.23      albertel   95:   foreach (split(/\:/,$env{'form.parms'})) {
1.20      www        96:       my ($ptype,$pname,$pvalue)=split(/\_\_\_/,$_);
1.21      www        97:       unless ($pname) { next; }
1.20      www        98:       unless ($type{$pname}) { $type{$pname}=$ptype; }
                     99:       $value{$pname}=$pvalue;
                    100:       $content{$pname}=$pvalue;
                    101:       $type{$pname}=$ptype;
                    102:       $display{$pname}=&mt('Custom Parameter');
                    103:   } 
1.3       www       104:   
                    105: # --------------------------------------------------- Print input screen header
1.15      matthew   106:     my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.24      albertel  107: 
1.17      www       108:     my %lt=&Apache::lonlocal::texthash('pa' => 'Parameter',
                    109: 			               'de' => 'Default',
                    110: 				       'va' => 'Value',
                    111: 				       'se' => 'Set');
1.24      albertel  112:     my $js = (<<ENDHEADER);
                    113: <script type="text/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.24      albertel  132:     $js .= 'var colon=""; opener.objparms['.$env{'form.resid'}.']="";';
                    133:     foreach my $key (keys(%content)) {
                    134: 	$js .= "\nif (document.parameters.def_".$key.
1.23      albertel  135:        '.checked) { opener.objparms['.$env{'form.resid'}.
1.24      albertel  136:        ']+=colon+"'.$type{$key}.
                    137:        '___'.$key.'___"+document.parameters.'.$key.'.value; colon=":"; }'; 
                    138:     }
                    139:     $js .= '
1.6       www       140:     opener.save();
1.3       www       141:     window.close();
                    142: }
                    143: </script>
1.24      albertel  144: ';
                    145:     my $start_page =
                    146: 	&Apache::loncommon::start_page('Set Resource Parameters in Map',$js);
                    147: 
                    148:     $r->print(<<ENDDOCUMENT);
                    149: $start_page
1.4       www       150: <form action="javascript:setparms();" method="post" name="parameters">
1.7       www       151: <input type="hidden" value='' name="pres_value">
                    152: <input type="hidden" value='' name="pres_type">
                    153: <input type="hidden" value='' name="pres_marker">
1.4       www       154: <table border=2>
1.16      www       155: <tr><th>$lt{'pa'}</th><th>$lt{'de'}</th><th>$lt{'va'}</th><th>$lt{'se'}?</th></tr>
1.1       www       156: ENDDOCUMENT
1.24      albertel  157: 
1.17      www       158: ###    %display=&Apache::lonlocal::texthash(%display);
1.16      www       159:     my $enter=&mt('Enter');
1.24      albertel  160:     foreach my $key (sort(keys(%content))) {
                    161:         my $cur=$content{$key};
                    162:         # Should if(defined($value{$key})) be if(exists($value{$key})) ?
                    163:         if (defined($value{$key})) { $cur=$value{$key}; };
1.9       matthew   164:         $r->print(<<"END");
1.24      albertel  165: <tr><td><b>$display{$key}</b><br><tt>$key</tt></td>
                    166: <td>&nbsp;$content{$key}</td>
                    167: <td><input type="text" size="10" name="$key" value="$cur">&nbsp;
                    168: <a href='javascript:pjump("$type{$key}","$display{$key}",document.parameters.$key.value,"$key","parameters.pres","stpr");'>$enter</a></td>
                    169: <td><input type="checkbox" name="def_$key" 
1.9       matthew   170: END
1.24      albertel  171:         if ($value{$key}) { $r->print(' checked'); }
1.6       www       172:         $r->print('></td></tr>');
1.9       matthew   173:     }
1.24      albertel  174:     $r->print('</table><br />
                    175:                <input type="submit" value="'.&mt('Set').'"></form>'.
                    176: 	      &Apache::loncommon::end_page());
1.1       www       177:     return OK;
                    178: } 
                    179: 
                    180: 1;
                    181: __END__
1.7       www       182: 

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