File:
[LON-CAPA] /
loncom /
homework /
lonsimpleproblemedit.pm
Revision
1.23:
download - view:
text,
annotated -
select for diffs
Thu Jun 11 16:48:28 2009 UTC (15 years, 2 months ago) by
bisitz
Branches:
MAIN
CVS tags:
bz5969,
bz2851,
HEAD,
BZ5971-printing-apage
Functionslist:
- Moved sub routines from lontemplate.pm to lonhtmlcommon.pm to allow wider access
- Renamed sub routine names:
- start_functionslist -> start_funclist
- item_functionslist -> add_item_funclist
- end_functionslist -> end_funclist
- Added line breaks for HTML source code
- Added pod documentation to sub routines
- Adjusted sub routine calls
Changes related to modification of LON-CAPA screen header:
- Moved functionslists into new standard screen header "head_subbox"
Other changes:
- Got rid of special style for fieldset legend; adjusted texts
(lonmsgdisplay.pm, loncommon.pm, de.pm, zh.pm)
- Added warning/info style to warning/info message for weboutput
and corrected tex output for "No page information provided" message
(lonsimplepage.pm)
- Optimized floating for functions/actions
(lonmsgdisplay.pm)
1: # The LearningOnline Network
2: # Simple Problem Parameter Setting "Editor"
3: #
4: # $Id: lonsimpleproblemedit.pm,v 1.23 2009/06/11 16:48:28 bisitz 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::lonsimpleproblemedit;
30:
31: use strict;
32: use Apache::Constants qw(:common :http);
33: use Apache::loncommon;
34: use Apache::lonnet;
35: use Apache::lonlocal;
36: use Apache::lonnavmaps;
37: use lib '/home/httpd/lib/perl/';
38: use LONCAPA;
39:
40:
41: my %qparms;
42: my $prefix;
43: my $qtype;
44:
45: sub evaloptionhash {
46: my $options=shift;
47: $options=~s/^\(\'//;
48: $options=~s/\'\)$//;
49: my %returnhash=();
50: foreach (split(/\'\,\'/,$options)) {
51: $returnhash{$_}=$_;
52: }
53: return %returnhash;
54: }
55:
56: sub rawrendering {
57: my ($symb)=@_;
58: my %data=('show_errors'=>'on',
59: 'simple_edit_button' => 'off',
60: 'devalidatecourseresdata'=>'on');
61: return &Apache::loncommon::get_student_view($symb,time,time,
62: $env{'request.course.id'},
63: 'web',\%data);
64: }
65:
66: sub questiontext {
67: my $text=$qparms{$prefix.'questiontext'};
68: my $qt=&mt('Question Text');
69: my $spell_link=
70: &Apache::lonhtmlcommon::spelllink('simpleedit','questiontext');
71: return (<<ENDQUESTION);
72: <table bgcolor="#dddd22" cellspacing="4" cellpadding="2" style="width:100%">
73: <tr><td><b>$qt</b><br />
74: <textarea style="width:100%" name="questiontext" cols="80" rows="8">$text</textarea>
75: <br />$spell_link
76: </td></tr>
77: </table>
78: <br />
79: ENDQUESTION
80: }
81:
82: sub hint {
83: my $text=$qparms{$prefix.'hinttext'};
84: my $ht=&mt('Hint Text');
85: my $spell_link=
86: &Apache::lonhtmlcommon::spelllink('simpleedit','hinttext');
87: return (<<ENDHINT);
88: <table bgcolor="#accacc" cellspacing="4" cellpadding="2">
89: <tr><td><b>$ht</b><br />
90: <textarea style="width:100%" name="hinttext" cols="80" rows="4">$text</textarea>
91: <br />$spell_link
92: </td></tr>
93: </table>
94: <br />
95: ENDHINT
96: }
97:
98: sub foil {
99: my $number=shift;
100: my %values='';
101: if ($qtype eq 'radio') {
102: %values=('true' => 'True', 'false' => 'False');
103: } elsif ($qtype eq 'option') {
104: %values=&evaloptionhash($qparms{$prefix.'options'});
105: }
106: $values{'unused'}='Not shown, not used';
107: my $value=$qparms{$prefix.'value'.$number};
108: unless (defined($value)) { $value='unused'; }
109: unless ($values{$value}) { $value='unused'; }
110: my $position=$qparms{$prefix.'position'.$number};
111: my %positions=('random' => 'Random position',
112: 'top' => 'Show always at top position',
113: 'bottom' => 'Show always at bottom position');
114: unless (defined($position)) { $position='random'; }
115: unless ($positions{$position}) {
116: $position='random';
117: }
118: my $selectvalue=&Apache::loncommon::select_form
119: ($value,'value'.$number,%values);
120: my $selectposition=&Apache::loncommon::select_form
121: ($position,'position'.$number,%positions);
122: my $text=$qparms{$prefix.'text'.$number};
123: my %lt=&Apache::lonlocal::texthash('foil' => 'Foil',
124: 'value' => 'Value',
125: 'pos' => 'Position',
126: 'text' => 'Text');
127:
128: my $spell_link=
129: &Apache::lonhtmlcommon::spelllink('simpleedit',"text$number");
130: return (<<ENDFOIL);
131: <table bgcolor="#dd55ff" cellspacing="4" cellpadding="2">
132: <tr><td colspan="2"><b>$lt{'foil'}</b></td></tr>
133: <tr><td>$lt{'value'}: $selectvalue</td><td>$lt{'pos'}: $selectposition</td></tr>
134: <tr><td colspan="2">$lt{'text'}:<br />
135: <textarea style="width:100%" name="text$number" cols="80" rows="4">$text</textarea>
136: <br />$spell_link
137: </td></tr>
138: </table>
139: <br />
140: ENDFOIL
141: }
142:
143: sub get_parent_uri {
144: my ($cur_symb)=@_;
145: my $navmap = Apache::lonnavmaps::navmap->new();
146: if (defined($navmap)) {
147: my $it = $navmap->getIterator(undef, undef, undef, 1);
148: while ( my $res=$it->next()) {
149: if (ref($res) && $res->symb() eq $cur_symb) { last; }
150: }
151: my ($src,$symb,$anchor)=&Apache::lonnavmaps::getLinkForResource($it->getStack());
152: if (defined($anchor)) { $anchor='#'.$anchor; }
153: return $src.'?symb='.&escape($symb).$anchor;
154: }
155: return;
156: }
157:
158: sub handler {
159: my $r = shift;
160:
161: if ($r->header_only) {
162: &Apache::loncommon::content_type($r,'text/html');
163: $r->send_http_header;
164: return OK;
165: }
166:
167: # -------------------------------------------------------------------- Allowed?
168: unless (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
169: return HTTP_NOT_ACCEPTABLE;
170: }
171: # ----------------------------------------------------------------- Send header
172: &Apache::loncommon::content_type($r,'text/html');
173: $r->send_http_header;
174: # ----------------------------------------------------- Figure out where we are
175: my $uri=$r->uri;
176: $uri=~s/\/smpedit$//;
177: my $symb=&Apache::lonnet::symbread();
178:
179: # ------------------------------------------------ Prefix for everything stored
180: $prefix=$env{'request.course.id'}.'.'.$symb.'.0.';
181: # ---------------------------------------------------------- Anything to store?
182:
183: if (($symb) && (defined($env{'form.questiontype'}))) {
184: my %storecontent=();
185: undef %storecontent;
186: if ($env{'form.questiontype'} eq 'option') {
187: my %curoptions=&evaloptionhash($env{'form.options'});
188: if ($env{'form.delopt'}) {
189: delete $curoptions{$env{'form.delopt'}};
190: }
191: if ($env{'form.newopt'}) {
192: $env{'form.newopt'}=~s/\'/\\\'/g;
193: $curoptions{$env{'form.newopt'}}=$env{'form.newopt'};
194: }
195: $env{'form.options'}="('".join("','",keys %curoptions)."')";
196: }
197: $env{'form.hiddenparts'}='!'.$env{'form.questiontype'};
198: foreach (keys %env) {
199: if ($_=~/^form\.(\w+)$/) {
200: my $parm=$1;
201: $storecontent{$prefix.$parm}=$env{'form.'.$parm};
202: $storecontent{$prefix.$parm}=~s/^\s+//s;
203: $storecontent{$prefix.$parm}=~s/\s+$//s;
204: }
205: }
206: my $reply=&Apache::lonnet::cput
207: ('resourcedata',\%storecontent,
208: $env{'course.'.$env{'request.course.id'}.'.domain'},
209: $env{'course.'.$env{'request.course.id'}.'.num'});
210:
211: }
212: # ------------------------------------------------------------------- Read Data
213:
214: %qparms=&Apache::lonnet::dump('resourcedata',
215: $env{'course.'.$env{'request.course.id'}.'.domain'},
216: $env{'course.'.$env{'request.course.id'}.'.num'},
217: $env{'request.course.id'}.'.'.$symb);
218:
219: # ------------------------------------------------------------ Print the screen
220: my $spell_header=&Apache::lonhtmlcommon::spellheader();
221: $r->print(&Apache::loncommon::start_page('Simple Problem Editor',
222: $spell_header));
223: if ($symb) {
224: $r->print('<h1>'.&Apache::lonnet::gettitle($symb).'</h1>');
225: my $displaylink = &get_parent_uri($symb);
226: if ($displaylink ne '') {
227: my $functions=&Apache::lonhtmlcommon::start_funclist()
228: .&Apache::lonhtmlcommon::add_item_funclist(
229: '<a href="'.$displaylink.'">'
230: .&mt('Student View').'</a>')
231: .&Apache::lonhtmlcommon::end_funclist();
232: $r->print(&Apache::loncommon::head_subbox($functions));
233: } else {
234: $r->print('<p class="LC_error">'
235: .&mt('An error occurred retrieving the link to this problem.')
236: .'<br />'
237: .&mt('You may need to [_1]re-select the course[_2] and then return to this resource to view it.'
238: ,'<a href="/adm/roles">','</a>')
239: .'</p>'
240: );
241: }
242: $r->print('<p class="LC_warning">'
243: .&mt('Note: it can take up to 10 minutes for changes to take effect for all users.')
244: .&Apache::loncommon::help_open_topic('Caching')
245: .'</p>'
246: );
247:
248: $r->print('<table border="2" bgcolor="#FFFFFF" width="100%"><tr><td>'.
249: &rawrendering($symb).
250: '</td></tr></table><br />');
251: $r->print('<form name="simpleedit" method="post">');
252: # Question Type
253: my %questiontypes=('radio' =>
254: '1 out of N multiple choice (radio button)',
255: 'option' => 'Option response',
256: 'string' => 'Short string response',
257: 'essay' => 'Essay, open end');
258: $qtype=$qparms{$prefix.'questiontype'};
259: unless (defined($qtype)) { $qtype='radio'; }
260: unless ($questiontypes{$qtype}) { $qtype='radio'; }
261: $r->print('<b>'.&mt('Question Type').
262: ': '.&Apache::loncommon::select_form
263: ($qtype,'questiontype',%questiontypes).
264: '</b><br /><input type="submit" value="'.&mt('Save and Edit').
265: '" /><p> </p>');
266: # Question Text
267: $r->print(&questiontext());
268: # Radio, Option ===
269: if (($qtype eq 'radio') || ($qtype eq 'option')) {
270: # Response
271: my $maxfoils=$qparms{$prefix.'maxfoils'};
272: unless (defined($maxfoils)) { $maxfoils=10; }
273: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
274: if ($maxfoils<=0) { $maxfoils=10; }
275: my %randomizes=('yes' => 'Display foils in random order',
276: 'no' => 'Display foils in order given');
277: my $randomize=$qparms{$prefix.'randomize'};
278: unless (defined($randomize)) { $randomize='yes'; }
279: unless ($randomizes{$randomize}) { $randomize='yes'; }
280: $r->print(
281: '<table bgcolor="#00ee44" cellspacing="4" cellpadding="2">'.
282: '<tr><td>'.&mt('Max number of foils displayed').
283: ': <input type="text" size="3" name="maxfoils" value="'.$maxfoils.'" /> '.
284: &Apache::loncommon::select_form
285: ($randomize,'randomize',%randomizes).
286: '</td></tr><tr><td bgcolor="#AAAAAA">');
287: # Option Response: Options
288: if ($qtype eq 'option') {
289: my $options=$qparms{$prefix.'options'};
290: unless (defined($options)) { $options="('true','false')"; }
291: my %optionshash=&evaloptionhash($options);
292: $r->print(
293: '<table bgcolor="#ffcc22" cellspacing="4" cellpadding="2">'.
294: '<tr><td><input type="hidden" name="options" value="'.
295: $options.'" />'.&mt('Add new option').': '.
296: '<input type="text" name="newopt" size="15" />'.
297: &mt('Delete an option').': '.
298: &Apache::loncommon::select_form('','delopt',('' => '',%optionshash)).
299: '</td></tr><tr><td>');
300: }
301: # Foils
302: for (my $i=1;$i<=10;$i++) {
303: $r->print(&foil($i));
304: }
305: # End Options
306: if ($qtype eq 'option') {
307: $r->print('</td></tr></table>');
308: }
309:
310: # End Response
311: $r->print('</td></tr></table><br />');
312: # Hint
313: $r->print(&hint());
314: }
315: if ($qtype eq 'string') {
316: my %stringtypes=(
317: 'cs' => 'Case sensitive',
318: 'ci' => 'Case Insensitive',
319: 'mc' => 'Multiple Choice, Order of characters unchecked');
320: my $stringanswer=$qparms{$prefix.'stringanswer'};
321: unless (defined($stringanswer)) { $stringanswer=''; }
322: my $stringtype=$qparms{$prefix.'stringtype'};
323: unless (defined($stringtype)) { $stringtype='cs'; }
324: unless ($stringtypes{$stringtype}) { $stringtype='cs'; }
325: $r->print(
326: '<table bgcolor="#00ee44" cellspacing="4" cellpadding="2">'.
327: '<tr><td>'.&mt('Correct answer').': <input type="text" size="20" name="stringanswer" value="'.$stringanswer.'" /> '.
328: &Apache::loncommon::select_form
329: ($stringtype,'stringtype',%stringtypes).
330: '</td></tr></table><br />');
331: # Hint
332: $r->print(&hint());
333: }
334: # Store Button
335: $r->print(
336: '<input type="submit" value="'.&mt('Save and Edit').'" /></form>');
337: } else {
338: $r->print(&mt('Could not identify problem.'));
339: }
340: $r->print(&Apache::loncommon::end_page());
341: return OK;
342: }
343:
344: 1;
345: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>