1: # The LearningOnline Network with CAPA
2: # Set parameters inside of the RAT
3: #
4: # $Id: lonratparms.pm,v 1.25 2008/11/11 16:40:38 jms 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: =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:
57: package Apache::lonratparms;
58:
59: use strict;
60: use Apache::Constants qw(:common);
61: use Apache::lonhtmlcommon();
62: use Apache::lonlocal;
63: use Apache::lonnet;
64:
65: sub handler {
66: my $r = shift;
67: &Apache::loncommon::content_type($r,'text/html');
68: $r->send_http_header;
69: return OK if $r->header_only;
70:
71: # Get query string for limited number of parameters
72:
73: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
74: ['url','parms','resid']);
75:
76: # ------------------------------------------------------------------- Read file
77:
78: my $uri=$env{'form.url'}.'.meta';
79:
80: my %content;
81: my %type;
82: my %display;
83: my %value;
84:
85: # ---------------------------------------------------------- Current Parameters
86:
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:
95: foreach (split(/\:/,$env{'form.parms'})) {
96: my ($ptype,$pname,$pvalue)=split(/\_\_\_/,$_);
97: unless ($pname) { next; }
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: }
104:
105: # --------------------------------------------------- Print input screen header
106: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
107:
108: my %lt=&Apache::lonlocal::texthash('pa' => 'Parameter',
109: 'de' => 'Default',
110: 'va' => 'Value',
111: 'se' => 'Set');
112: my $js = (<<ENDHEADER);
113: <script type="text/javascript">
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:
121: $pjump_def
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:
130: function setparms() {
131: ENDHEADER
132: $js .= 'var colon=""; opener.objparms['.$env{'form.resid'}.']="";';
133: foreach my $key (keys(%content)) {
134: $js .= "\nif (document.parameters.def_".$key.
135: '.checked) { opener.objparms['.$env{'form.resid'}.
136: ']+=colon+"'.$type{$key}.
137: '___'.$key.'___"+document.parameters.'.$key.'.value; colon=":"; }';
138: }
139: $js .= '
140: opener.save();
141: window.close();
142: }
143: </script>
144: ';
145: my $start_page =
146: &Apache::loncommon::start_page('Set Resource Parameters in Map',$js);
147:
148: $r->print(<<ENDDOCUMENT);
149: $start_page
150: <form action="javascript:setparms();" method="post" name="parameters">
151: <input type="hidden" value='' name="pres_value">
152: <input type="hidden" value='' name="pres_type">
153: <input type="hidden" value='' name="pres_marker">
154: <table border=2>
155: <tr><th>$lt{'pa'}</th><th>$lt{'de'}</th><th>$lt{'va'}</th><th>$lt{'se'}?</th></tr>
156: ENDDOCUMENT
157:
158: ### %display=&Apache::lonlocal::texthash(%display);
159: my $enter=&mt('Enter');
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}; };
164: $r->print(<<"END");
165: <tr><td><b>$display{$key}</b><br><tt>$key</tt></td>
166: <td> $content{$key}</td>
167: <td><input type="text" size="10" name="$key" value="$cur">
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"
170: END
171: if ($value{$key}) { $r->print(' checked'); }
172: $r->print('></td></tr>');
173: }
174: $r->print('</table><br />
175: <input type="submit" value="'.&mt('Set').'"></form>'.
176: &Apache::loncommon::end_page());
177: return OK;
178: }
179:
180: 1;
181: __END__
182:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>