Annotation of modules/gci/londocsgci.pm, revision 1.15
1.1 gci 1: # The LearningOnline Network
2: # Custom Edit Course Routines for Assembly of Valid Concept Tests from
3: # Geoscience Concept Inventory.
4: #
1.15 ! gci 5: # $Id: londocsgci.pm,v 1.14 2010/11/09 01:19:04 gci Exp $
1.1 gci 6: #
7: # Copyright Michigan State University Board of Trustees
8: #
9: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
10: #
11: # LON-CAPA is free software; you can redistribute it and/or modify
12: # it under the terms of the GNU General Public License as published by
13: # the Free Software Foundation; either version 2 of the License, or
14: # (at your option) any later version.
15: #
16: # LON-CAPA is distributed in the hope that it will be useful,
17: # but WITHOUT ANY WARRANTY; without even the implied warranty of
18: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19: # GNU General Public License for more details.
20: #
21: # You should have received a copy of the GNU General Public License
22: # along with LON-CAPA; if not, write to the Free Software
23: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24: #
25: # /home/httpd/html/adm/gpl.txt
26: #
27: # http://www.lon-capa.org/
28: #
29:
30:
31: package Apache::londocsgci;
32:
33: use strict;
34:
35: use Apache::lonnet;
36: use Apache::loncommon;
37: use LONCAPA::map();
38: use Apache::lonindexer;
39: use Apache::lonlocal;
40: use LONCAPA qw(:DEFAULT :match);
41:
42: { #scope variables
43:
44: my $path;
45: my $version;
46: my $reqnum;
1.6 gci 47: my @mandcats;
48: my @bincats;
1.1 gci 49: my @categories;
50: my @allprobs;
51: my %probcat;
52: my %prereqs;
1.6 gci 53: my %revreqs;
1.1 gci 54: my @defchosen;
55: my @chosen;
1.5 gci 56: my @mandprobs;
57: my @bins;
58: my @optional;
1.3 gci 59: my %mandatory;
1.5 gci 60: my @development;
1.1 gci 61:
62: sub setdefaults {
63: $path='/res/gci/gci';
64: $version='GCIv2-1-1';
65: $reqnum=15;
1.5 gci 66: @allprobs=('01','02','37','2004_73','03','04','05','06','07',
1.1 gci 67: '08','10',
68: '09',
69: '11','12','13','14','15','16','17',
70: '18','69',
71: '19','20',
72: '21','22','23','24','25','26','27','28','29','30',
1.5 gci 73: '31','32','33','34','35','36','38',
1.1 gci 74: '39A','39B',
75: '40',
76: '41','42','43','44','45','46','47','48','49','50',
77: '51',
78: '52','57',
79: '53','54','55','56','58',
80: '60',
81: '61','62','63','64','65','66','67','68','70',
1.5 gci 82: '71');
83: @bins = ( ['03','04','06'],
84: ['07','08','09'],
85: ['10','12','13','14','15','16','17'],
86: ['18','19','20','21','22','23','24','25'],
87: ['26','27','28','30'],
88: ['32','33','34','35','36'],
89: ['38','39A','39B','40','41','42','43','44','45','46'],
90: ['47','48','49','50','51','52','53'],
91: ['54','55','56','57','58','60','61','62'],
92: ['63','64','65'],
93: ['66','67','68','69','70','71']);
94: @optional = ('05','11','29','31');
1.6 gci 95: @mandcats = ('M1','M2','M3','M4');
96: @bincats = ('A','B','C','D','E','F','G','H','I','J','K');
97: @categories=(@mandcats,@bincats);
98: %probcat =('01' => 'M1' ,'02' => 'M2' ,'37' => 'M3' ,'2004_73' => 'M4' ,
1.5 gci 99: '03' => 'A' ,'04' => 'A','05' => '' ,'06' => 'A' ,'07' => 'B' ,
100: '08' => 'B' ,'09' => 'B' ,'10' => 'C' ,'11' => '' ,'12' => 'C' ,
101: '13' => 'C' ,'14' => 'C' ,'15' => 'C' ,'16' => 'C' ,'17' => 'C' ,'18' => 'D' ,'19' => 'D' ,'20' => 'D' ,
1.1 gci 102: '21' => 'D' ,'22' => 'D' ,'23' => 'D' ,'24' => 'D' ,'25' => 'D' ,'26' => 'E' ,'27' => 'E' ,'28' => 'E' ,'29' => '' ,'30' => 'E' ,
1.5 gci 103: '31' => '' ,'32' => 'F' ,'33' => 'F' ,'34' => 'F' ,'35' => 'F' ,'36' => 'F' ,'38' => 'G' ,
1.1 gci 104: '39A'=> 'G' ,'39B'=> 'G' ,
105: '40' => 'G' ,
106: '41' => 'G' ,'42' => 'G' ,'43' => 'G' ,'44' => 'G' ,'45' => 'G' ,'46' => 'G' ,'47' => 'H' ,'48' => 'H' ,'49' => 'H' ,'50' => 'H' ,
107: '51' => 'H' ,'52' => 'H' ,'53' => 'H' ,'54' => 'I' ,'55' => 'I' ,'56' => 'I' ,'57' => 'I' ,'58' => 'I' ,
108: '60' => 'I' ,
109: '61' => 'I' ,'62' => 'I' ,'63' => 'J' ,'64' => 'J' ,'65' => 'J' ,'66' => 'K' ,'67' => 'K' ,'68' => 'K' ,'69' => 'K' ,'70' => 'K' ,
1.5 gci 110: '71' => 'K');
1.6 gci 111: %mandatory=('01' => 1 ,'02' => 1,'37' => 1, '2004_73' => 1);
112: @mandprobs = ('01','02','37','2004_73');
113: %prereqs=('10' => '08', '57' => '52', '69' => '18');
114: foreach my $item (keys(%prereqs)) {
115: $revreqs{$prereqs{$item}} = $item;
116: }
117: @defchosen=('01','02','03','07','12','18','26','32','37','38','47','54','63','66','2004_73');
1.15 ! gci 118: @development = ('001','002','003','004','005','006','007','008','009','010','011','012','013','014','015','016','017','018','019','020','021','022','023','024','025','026','027');
1.1 gci 119: }
120:
121: sub checkvalid {
122: my %covered=();
123: my %chosenproblems=();
124: my @errors=();
125: my $num=$#chosen+1;
126: if ($num<$reqnum) {
127: push(@errors,&mt('Test requires at least [_1] items, but has only [_2].',$reqnum,$num));
128: }
129: foreach my $item (@chosen) {
130: $chosenproblems{$item}=1;
131: $covered{$probcat{$item}}=1;
132: }
133: foreach my $cat (@categories) {
134: unless ($covered{$cat}) {
1.3 gci 135: push(@errors,&mt('Bin [_1] not covered.',$cat));
1.1 gci 136: }
137: }
138: foreach my $item (@chosen) {
139: if ($prereqs{$item}) {
140: unless ($chosenproblems{$prereqs{$item}}) {
1.6 gci 141: my $url = &fullurl($item);
142: my $title = &Apache::lonnet::metadata($url,'title');
143: my $prerequrl = &fullurl($prereqs{$item});
144: my $prereqtitle = &Apache::lonnet::metadata($prerequrl,'title');
145: push(@errors,&mt('[_1] requires [_2].',"'$title'","'$prereqtitle'"));
1.1 gci 146: }
147: }
148: }
149: return @errors;
150: }
151:
152: sub fullurl {
1.8 gci 153: my ($item,$catname)=@_;
1.7 gci 154: unless ($item=~/\_/) { $item='_'.$item; }
1.8 gci 155: if ($catname eq 'development') {
156: return $path.'/pilot/pilot'.$item.'.problem';
157: }
1.1 gci 158: return $path.'/'.$version.'/GCI'.$item.'.problem';
159: }
160:
1.6 gci 161: sub item_from_url {
162: my ($url)=@_;
1.7 gci 163: if ($url =~ m{\Q$path\E/\Q$version\E/GCI_?([^.]+)\.problem$}) {
1.6 gci 164: return $1;
165: }
166: }
167:
1.3 gci 168: sub validcheck {
1.1 gci 169: my ($r)=@_;
170: my @errors=&checkvalid();
171: if ($#errors>-1) {
172: $r->print('<span class="LC_error">'.&mt('Your test is not yet valid.').'</span><p>'.&mt('The following issues must be addressed before you can use the test:').'<ul>');
173: foreach my $message (@errors) {
174: $r->print('<li>'.$message.'</li>');
175: }
176: $r->print('</ul></p>');
1.3 gci 177: return 0;
178: }
179: return 1;
180: }
181:
182: sub listresources {
1.5 gci 183: my ($r,$context,$cdom,$cnum)=@_;
184: my $numchosen = scalar(@chosen);
1.9 gci 185: my $multipart = 0;
186: my $composites;
187: if ($numchosen > 0) {
188: foreach my $key (keys(%prereqs)) {
189: if (grep(/^\Q$key\E/,@chosen)) {
190: $multipart ++;
191: $numchosen --;
192: }
193: }
194: if ($multipart) {
195: $composites = &mt(' (of which [quant,_1,is a combination question,are combination questions] in which students select both an answer, and the reasoning used).',$multipart).'<br />';
196: } else {
197: $composites = '. ';
198: }
199: }
1.5 gci 200: unless ($numchosen > 0) {
201: $r->print('<h3>'.&mt('Create a Concept Test').'</h3>'.
202: '<p>'.&mt('Choose how the test should be built:').'<br />'.
203: '<form name="choices" method="post" action="/adm/coursedocs" onsubmit="javascript:setDocsPhase();">'.
204: '<label><input type="radio" name="concepttest" value="defchosen" />'.&mt('Have a valid test built automatically by the WebCenter.').'</label><br />'.
205: '<label><input type="radio" name="concepttest" value="editmyown" checked="checked" />'.&mt('Make your own selection of questions from the Geoscience Concept Inventory.').'</label><br /><br />'.
206: '<input type="hidden" name="phase" value="" />'.
207: '<input type="submit" name="choosetest" value="'.&mt('Next').'"></p>');
208: return;
209: }
210: if ((!&validcheck($r)) || ($env{'form.concepttest'} eq 'editmyown')) {
211: &editor($r,$context,$cdom,$cnum);
1.3 gci 212: } else {
1.5 gci 213: my $numsub = &get_submissions_count($cdom,$cnum);
214: unless ($env{'form.phase'} eq 'storemap') {
1.9 gci 215: $r->print('<p>'.&mt('This course contains a valid concept test which includes [quant,_1,question]',$numchosen).$composites.'<a href="/adm/navmaps" target="_coursecontents">'.&mt('Display Contents').'</a><br />');
1.5 gci 216: }
217: if ($numsub > 0) {
218: $r->print(&mt('As there are existing student submissions, modification of the [_1]contents[_2] of the Concept Test will result in loss of student performance data, and is [_3]not[_4] permitted.','<i>','</i>','<b>','</b>').'<br />'.&mt('Modification of open and close dates [_1]is[_2] permitted.','<b>','</b>').'</p>');
219: } else {
220: $r->print('<fieldset><legend>'.&mt('Modify Test').'</legend>'.
221: &mt('Currently no student submissions have been recorded, so you may modify the contents of the Concept Test.').
222: '<br /><form name="changetest" method="post" action="/adm/coursedocs">'.
223: '<input type="hidden" name="concepttest" value="editmyown" />'.
224: '<input type="submit" name="modifytest" value="'.&mt('Edit Concept Test').'" /></form></fieldset></p>');
1.3 gci 225: }
1.5 gci 226: my ($crsparms,$ineffect,$parmlev) = ¤t_parms($cdom,$cnum);
227: my $formname = 'datesform';
228: my $datebutton = &mt('Save');
229: my $startform =
230: &Apache::lonhtmlcommon::date_setter($formname,'opendate',
231: $crsparms->{'opendate'});
232: my $endform =
233: &Apache::lonhtmlcommon::date_setter($formname,'duedate',
234: $crsparms->{'duedate'});
235: $r->print('<p><fieldset><legend>'.&mt('Test Availability').'</legend>'.
236: &mt('Open and close dates for test items for the concept test are currently set as follows:').
237: '<br />'.
238: '<form name="'.$formname.'" method="post" '.
239: 'action="/adm/coursedocs">'.
240: &Apache::lonhtmlcommon::start_pick_box().
241: &Apache::lonhtmlcommon::row_title(&mt('Open date')).
242: $startform.
1.6 gci 243: &Apache::lonhtmlcommon::row_closure(1).
1.5 gci 244: &Apache::lonhtmlcommon::row_title(&mt('Close date')).
245: $endform.
1.10 gci 246: &Apache::lonhtmlcommon::row_closure(1).
247: &Apache::lonhtmlcommon::end_pick_box().'<br />'.
1.5 gci 248: '<input type="hidden" name="phase" value="storeparms" />'.
249: '<input type="submit" value="'.$datebutton.'" />'.
250: '</form></fieldset></p>');
1.1 gci 251: }
1.3 gci 252: }
253:
254: sub editor {
1.5 gci 255: my ($r,$context,$cdom,$cnum)=@_;
256: my %chosenitems=();
257: my $havedev = 0;
258: foreach my $item (@chosen) {
259: $chosenitems{$item}=1;
260: }
261: my @devitems = &get_development_questions($cdom,$cnum);
262: &Apache::lonnet::appenv({'request.gcicontext' => 'buildtest'});
263: $r->print('<form name="selecteditems" method="post" action="/adm/coursedocs"
264: onsubmit="return validTestCheck()">');
265: $r->print(&mt('Select test items from the numbered bins below and then press [_1]"Store Problem Selection"[_2] at the bottom of the page.','<i>','</i>').'<br />');
266: $r->print('<ul>'.
267: '<li>'.&mt('Tests will contain a minimum of [_1] questions from the GCI 2 Inventory.',"<b>$reqnum</b>").'</li>'.
268: '<li>'.&mt('Tests must contain [_1]four[_2] mandatory questions and at least one item from each of [_1]eleven[_2] other bins.','<b>','</b>').'</li>'.
269: '<li>'.&mt('All tests conclude with [_1]two[_2] questions selected by the system (at random) from a pool of development questions being piloted by the GCI team.','<b>','</b>').'</li>'.
270: '</ul>');
271: my $mandleg = &mt('Mandatory Questions');
272: $r->print(&display_questions(\@mandprobs,'mandatory',$mandleg,\%chosenitems));
273: for (my $i=0; $i<@bins; $i++) {
274: my $num = $i+1;
275: my $legend = &mt('Bin [_1]',$num);
276: my $catname = 'bin'.$i;
277: $r->print(&display_questions($bins[$i],$catname,$legend,\%chosenitems));
278: }
279: my $optleg = &mt('Optional Questions');
280: $r->print(&display_questions(\@optional,'optional',$optleg,\%chosenitems));
281: my $devleg = &mt('Development Questions');
282: $r->print(&display_questions(\@devitems,'development',$devleg,\%chosenitems));
283: $r->print('<input type="hidden" name="phase" value="storemap" />'.
284: '<input type="hidden" name="context" value="'.$context.'" />'.
1.14 gci 285: '<input type="hidden" name="concepttest" value="'.$env{'form.concepttest'}.'" />'.
1.5 gci 286: '<input type="submit" value="'.&mt('Store Problem Selection').'" />'.
287: '</form>');
288: &Apache::lonnet::delenv('request.gcicontext');
289: }
290:
291: sub display_questions {
292: my ($questions,$catname,$catlegend,$chosenitems) = @_;
293: return unless((ref($questions) eq 'ARRAY') && (ref($chosenitems) eq 'HASH'));
294: my $total = 0;
295: foreach my $item (@{$questions}) {
296: if ($chosenitems->{$item}) {
297: $total ++;
298: }
299: }
300: my $fieldid = 'GCI_'.$catname.'_q';
301: my $titleid = 'GCI_'.$catname.'_t';
302: my $countid = 'GCI_'.$catname.'_count';
303: my $output = '<fieldset>';
304: my %fixed = (
305: mandatory => 4,
306: development => 2,
307: );
308: if (($catname eq 'mandatory') || ($catname eq 'development')) {
309: $output .= '<legend>'.&mt('[_1] [_2] selected automatically',$catlegend,
310: '<input type="text" name="'.$countid.'" size="1" '.
311: 'value="'.$fixed{$catname}.'" readonly="readonly" />').'</legend>';
312: } else {
313: $output .= '<legend>'.&mt('[_1]: currently [_2] selected',$catlegend,
1.10 gci 314: '<input type="text" name="'.$countid.'" id="'.$countid.'" size="1" value="'.
1.5 gci 315: $total.'" readonly="readonly" />').'</legend>';
316: }
317: $output .= '<span id="'.$titleid.'">'.
318: '<a href="javascript:showQuestions('."'$fieldid','$titleid'".')">'.
319: &mt('Show').'</a> ...</span><br />'.
1.13 gci 320: '<div id="'.$fieldid.'" style="display: none">'.
1.5 gci 321: &Apache::loncommon::start_data_table().
322: &Apache::loncommon::start_data_table_header_row();
323: unless (($catname eq 'development') || ($catname eq 'mandatory')) {
324: $output .= '<th>'.&mt('Select').'</th>';
325: }
326: $output .= '<th>'.&mt('Problem').
327: '</th><th>'.&mt('Preview').'</th>'.
328: &Apache::loncommon::end_data_table_header_row();
329: foreach my $item (@{$questions}) {
1.8 gci 330: my $url = &fullurl($item,$catname);
1.5 gci 331: my $title = &Apache::lonnet::metadata($url,'title');
332: $output .= &Apache::loncommon::start_data_table_row().'<td>';
1.8 gci 333: if ($catname eq 'mandatory') {
1.5 gci 334: $output .= '<input type="hidden" name="item'.$item.'" value="checked" />';
1.8 gci 335: } elsif ($catname eq 'development') {
336: $output .= '<input type="hidden" name="pilot'.$item.'" value="checked" />';
1.5 gci 337: } else {
1.10 gci 338: $output .= '<input type="checkbox" name="item'.$item.'" id="item'.$item.'"';
1.5 gci 339: if ($chosenitems->{$item}) { $output .= ' checked="checked"'; }
1.6 gci 340: $output .= ' onclick="countChecked('."'$catname'".');';
341: my $binname;
342: if ($prereqs{$item}) {
343: for (my $i=0; $i<@bincats; $i++) {
344: if ($bincats[$i] eq $probcat{$prereqs{$item}}) {
345: $binname = 'bin'.$i;
346: last;
347: }
348: }
349: $output .= 'checkPrereqs('."'dep','$item','$prereqs{$item}','$binname'".');';
350: } elsif ($revreqs{$item}) {
351: for (my $i=0; $i<@bincats; $i++) {
352: if ($bincats[$i] eq $probcat{$item}) {
353: $binname = 'bin'.$i;
354: last;
355: }
356: }
357: $output .= 'checkPrereqs('."'pre','$revreqs{$item}','$item','$binname'".');';
358: }
359: $output .= '" />'.
1.5 gci 360: '<input type="hidden" name="container'.$item.'" value="'.
361: $catname.'"></td><td>';
362: }
363: $output .= '<b>'.$title.'</b></td>';
364: my $content=&Apache::lonindexer::showpreview($url);
1.12 gci 365: my $startformtag = '<form name="lonhomework" enctype="multipart/form-data" method="post" action="'.$url.'?inhibitmenu=yes" >';
366: my $endtag = '<table><tr><td><input onmouseup="javascript:setSubmittedPart';
367: $content =~ s/^\Q$startformtag\E//;
368: $content =~ s/\Q$endtag\E.+$//s;
1.5 gci 369: $output .= '<td> '.($content eq '' ? ' ':$content).' </td>'."\n".
370: &Apache::loncommon::end_data_table_row();
371: }
372: $output .= &Apache::loncommon::end_data_table().
373: '</div></fieldset><br />';
374: return $output;
375: }
376:
377: sub get_development_questions {
378: my ($cdom,$cnum) = @_;
379: my $cid = $cdom.'_'.$cnum;
380: my %courseenv = &Apache::lonnet::userenvironment($cdom,$cnum,
381: ('internal.courseowner'));
382: my $seed = $courseenv{'internal.courseowner'};
383: my $rndseed=&Apache::lonnet::rndseed($seed,$cid,$cdom,$cnum);
384: &Apache::lonnet::setup_random_from_rndseed($rndseed);
385: my @devitems = &Math::Random::random_permutation(@development);
386: return ($devitems[0],$devitems[1]);
1.1 gci 387: }
388:
389: sub evaluate {
390: if ($env{'form.phase'} eq 'storemap') {
391: @chosen=();
392: foreach my $item (@allprobs) {
393: if ($env{'form.item'.$item}) {
394: push(@chosen,$item);
395: }
396: }
397: }
398: }
399:
400: sub mapread_gci {
401: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
402: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
403: return
1.5 gci 404: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/default_1261144274.sequence');
1.1 gci 405: }
406:
407: sub storemap_gci {
1.5 gci 408: my ($coursedom,$coursenum) = @_;
409: if (($coursedom !~ /^$match_domain$/) || ($coursenum !~ /^$match_courseid$/)) {
410: $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
411: $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
412: }
413: return ('unauthorized',2) if (($coursedom eq '') || ($coursedom eq '') ||
414: (!&Apache::lonnet::allowed('mdc',$coursedom.'_'.$coursenum)));
1.1 gci 415: my ($outtext,$errtext)=
1.5 gci 416: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/default_1261144274.sequence',1);
1.1 gci 417: if ($errtext) { return ($errtext,2); }
418: return ($errtext,0);
419: }
420:
421: sub chosen_to_map {
422: my %chosenproblems=();
423: foreach my $item (@chosen) {
424: $chosenproblems{$item}=1;
425: }
426: @LONCAPA::map::order=();
427: @LONCAPA::map::resources=();
1.5 gci 428: my $counter = 0;
1.8 gci 429: my $residx;
1.1 gci 430: for (my $idx=0;$idx<=$#allprobs;$idx++) {
1.8 gci 431: $residx=$idx+1;
1.1 gci 432: if ($chosenproblems{$allprobs[$idx]}) {
1.6 gci 433: my $url = &LONCAPA::map::qtunescape(&fullurl($allprobs[$idx]));
434: if (($revreqs{$allprobs[$idx]}) &&
435: ($chosenproblems{$revreqs{$allprobs[$idx]}})) {
1.7 gci 436: my $probnum = '_'.$allprobs[$idx].'_'.$revreqs{$allprobs[$idx]};
1.6 gci 437: $url = &LONCAPA::map::qtunescape(&fullurl($probnum));
438: } elsif ($prereqs{$allprobs[$idx]}) {
439: next;
440: }
1.1 gci 441: push(@LONCAPA::map::order,$residx);
1.5 gci 442: $counter ++;
443: my $name = &LONCAPA::map::qtunescape('Problem '.$counter);
1.1 gci 444: $LONCAPA::map::resources[$residx]=join(':', ($name, $url, 'false', 'normal', 'res'));
445: }
446: }
1.8 gci 447: foreach my $devitem (@development) {
448: if ($env{'form.pilot'.$devitem}) {
449: my $url = &LONCAPA::map::qtunescape(&fullurl($devitem,'development'));
450: $residx ++;
451: push(@LONCAPA::map::order,$residx);
452: $counter ++;
453: my $name = &LONCAPA::map::qtunescape('Problem '.$counter);
454: $LONCAPA::map::resources[$residx]=join(':', ($name, $url, 'false', 'normal', 'res'));
455: }
456: }
1.1 gci 457: }
458:
459: sub map_to_chosen {
460: @chosen=();
461: foreach my $idx (@LONCAPA::map::order) {
1.6 gci 462: my ($title,$url)=split(':',$LONCAPA::map::resources[$idx]);
463: my $item;
1.5 gci 464: unless ($url eq '') {
1.6 gci 465: $item = &item_from_url($url);
466: if (($item =~ /^(\d+)_(\d+)$/) && ($prereqs{$2} eq $1)) {
467: push(@chosen,($1,$2));
468: } else {
469: push(@chosen,$item);
470: }
1.5 gci 471: }
472: }
473: if (($env{'form.concepttest'} eq 'defchosen') ||
474: ((@chosen == 0) && ($env{'form.concepttest'} eq 'editmyown'))) {
475: @chosen = @defchosen;
1.1 gci 476: }
477: }
478:
479: sub store {
1.5 gci 480: my ($caller,$cdom,$cnum)=@_;
481: if ($env{'form.concepttest'} eq 'defchosen') {
482: @chosen = @defchosen;
483: }
1.1 gci 484: my @errors=&checkvalid();
1.5 gci 485: if (@errors > 0) {
486: if (($caller eq 'requestcrs') && ($env{'form.concepttest'} eq 'defchosen')) {
1.6 gci 487: return &mt('Invalid concept test.');
1.5 gci 488: } else {
1.6 gci 489: my $errormsg = '<span class="LC_warning">'.&mt('Invalid concept test:');
490: if (@errors > 1) {
491: $errormsg .= '<ul><li>'.join('</li><li>',@errors).'</li></ul>';
492: } else {
493: $errormsg .= '<br />'.$errors[0];
494: }
495: $errormsg .= '</span>';
496: return $errormsg;
1.5 gci 497: }
498: }
1.1 gci 499: &chosen_to_map();
1.5 gci 500: my ($err,$errnum) = &storemap_gci($cdom,$cnum);
501: if ($caller eq 'requestcrs') {
502: if ($errnum == 0) {
503: return;
504: } else {
505: return 'An error occurred when storing the concept test';
506: }
507: }
1.3 gci 508: if ($env{'form.phase'} eq 'storemap') {
1.5 gci 509: if ($errnum == 0) {
510: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
511: return '<p>'.&mt('You have successfully assembled a valid test.').'</p>'.
512: '<p><a href="/adm/navmaps">'.&mt('Display Table of Contents').
513: '</a>'.(' ' x4).'<a href="/adm/menu">'.&mt('Return to Main Menu').'</a></p>';
514: } else {
515: return '<div class="LC_error">'.&mt('An error occurred when storing your concept test: [_1].',$err).'</div>';
1.3 gci 516: }
1.1 gci 517: }
1.5 gci 518: return;
1.1 gci 519: }
520:
521: sub load {
522: &mapread_gci();
523: &map_to_chosen();
1.5 gci 524: if (@chosen > 0) {
525: my @errors=&checkvalid();
526: if ($#errors>1) { @chosen=@defchosen; }
527: }
528: }
529:
530: sub current_parms {
531: my ($cdom,$cnum) = @_;
532: my $courseopt=&Apache::lonnet::get_courseresdata($cnum,$cdom);
533: my (%crsparms,%ineffect,%parmlev);
534: foreach my $item ('opendate','duedate') {
535: $crsparms{$item} = $courseopt->{$env{'request.course.id'}.'.0.'.$item};
536: my ($result,@outpar) =
537: &Apache::lonparmset::parmval('0.'.$item,'0.0',undef,undef,
538: $cdom,undef,undef,$courseopt);
539: if ($result) {
540: $ineffect{$item} = $outpar[$result];
541: $parmlev{$item} = $result;
542: }
543: }
544: return (\%crsparms,\%ineffect,\%parmlev);
545: }
546:
547: sub store_dates_parms {
548: my ($cdom,$cnum) = @_;
549: my $topsymb = '___0___uploaded/'.$cdom.'/'.$cnum.'/default.sequence';
550: my ($opendate,$duedate) =
551: &Apache::lonuserutils::get_dates_from_form('opendate','duedate');
552: my %dates = (
553: opendate => {
554: value => $opendate,
555: type => 'date_start',
556: },
557: duedate => {
558: value => $duedate,
559: type => 'date_end',
560: },
561: );
562: my %parmresult;
563: foreach my $date (keys(%dates)) {
564: $parmresult{$date} =
565: &Apache::lonparmset::storeparm_by_symb($topsymb,
566: '0_'.$date,14,$dates{$date}{'value'},
567: $dates{$date}{'type'},undef,$cdom);
568: }
569: my $output = &mt('Open and Close dates set for test items').'<ul>'.
570: '<li>'.&mt('Concept Test Questions open:').' '.
571: &Apache::lonlocal::locallocaltime($opendate).'</li>'.
572: '<li>'.&mt('Concept Test Questions close:').' '.
573: &Apache::lonlocal::locallocaltime($duedate).'</li>'.
574: '</ul>';
575: return $output;
576: }
577:
578: sub get_submissions_count {
579: my ($cdom,$cnum) = @_;
580: my $navmap = Apache::lonnavmaps::navmap->new();
581: if (!defined($navmap)) {
582: my $itemserror = '<span class="LC_warning">'.&mt('An error occurred retrieving information about the course.').'<br />'.&mt('It is recommended that you [_1]re-select the course[_2].','<a href="/adm/roles">','</a>').'</span>';
583: return $itemserror;
584: }
585: my @allres=$navmap->retrieveResources('/uploaded/'.$cdom.'/'.$cnum.'/default_1261144274.sequence',sub {if ($_[0]->is_problem) { $_[0]->parts();} return 1;});
586: my (%resourcetracker,$submissioncount);
587: my %resourcetracker = &Apache::lonnet::dump('nohist_resourcetracker',
588: $cdom,$cnum);
589: foreach my $resource (@allres) {
590: my $symb = $resource->symb();
591: my @parts = @{$resource->parts()};
592: foreach my $part (@parts) {
593: if ($resource->handgrade($part) eq 'yes') {
594: next;
595: }
596: if ($resource->is_survey($part)) {
597: next;
598: }
599: if (exists($resourcetracker{$symb."\0".$part."\0users"})) {
600: $submissioncount += $resourcetracker{$symb."\0".$part."\0users"};
601: }
602: }
603: }
604: return $submissioncount;
605: }
606:
607: sub builder_javascript {
608: my %lt = &Apache::lonlocal::texthash(
609: show => 'Show',
610: hide => 'Hide',
611: );
1.6 gci 612: my $prereqjs = "
613: function checkPrereqs(caller,item,prereq,binname) {
614: var changedPrereq = 0;
1.10 gci 615: element = document.getElementById('item'+item);
616: if (element.checked == false) {
1.6 gci 617: return;
618: } else {
1.10 gci 619: prereqelement = document.getElementById('item'+prereq);
620: if (!prereqelement.checked) {
621: prereqelement.checked = true;
1.6 gci 622: changedPrereq = 1;
623: countChecked(binname);
624: }
625: }
626: ";
627:
628: my ($hasdep,$prereq,$hasdeptitle,$prereqtitle) = ('','','','');
629: foreach my $item (sort(keys(%prereqs))) {
630: $hasdep .= "'$item',";
631: $prereq .= "'$prereqs{$item}',";
632: my $url = &fullurl($item);
633: $hasdeptitle .= "'".&Apache::lonnet::metadata($url,'title')."',";
634: my $purl = &fullurl($prereqs{$item});
635: $prereqtitle .= "'".&Apache::lonnet::metadata($purl,'title')."',";
636: }
637: $hasdep =~ s/,$//;
638: $prereq =~ s/,$//;
639: $hasdeptitle =~ s/,$//;
640: $prereqtitle =~ s/,$//;
641:
642: $prereqjs .= <<"ENDFN";
643:
644: var hasDeps = Array($hasdep);
645: var preReqs = Array($prereq);
646: var hasDepTitles = Array($hasdeptitle);
647: var preReqTitles = Array($prereqtitle);
648: for (var i=0; i<hasDeps.length; i++) {
649: if (hasDeps[i] == item) {
650: var msg = hasDepTitles[i]+' question has a prerequisite: '+preReqTitles[i]+'.\\nThe two questions will appear together in a composite question.';
651: if (changedPrereq == 1) {
652: msg = msg+'\\n\\nAs the prerequisite was not checked, inclusion of '+hasDepTitles[i]+' has now caused '+preReqTitles[i]+' to also be checked automatically.';
653: }
654: if (caller == 'pre') {
655: msg = msg +'\\n\\nIf you do not wish to include '+preReqTitles[i]+' you will first need to uncheck '+hasDepTitles[i]+', then uncheck '+preReqTitles[i]+' again.'
656: }
657: alert(msg);
658: break;
659: }
660: }
661: return;
662: }
663:
664: ENDFN
665:
1.5 gci 666: return <<ENDJS;
667: function showQuestions(content,title) {
668: document.getElementById(content).style.display = "";
669: document.getElementById(title).innerHTML='<a href="javascript:hideQuestions('+"'"+content+"','"+title+"'"+');">$lt{'hide'}</a> ...';
670: return;
671: }
672:
673: function hideQuestions(content,title) {
674: document.getElementById(content).style.display = "none";
675: document.getElementById(title).innerHTML='<a href="javascript:showQuestions('+"'"+content+"','"+title+"'"+')">$lt{'show'}</a> ...';
676: return;
677: }
678:
679: function countChecked(binname) {
680: var count = 0;
681: for (var i=0; i<document.selecteditems.elements.length; i++) {
682: if (document.selecteditems.elements[i].type == "hidden") {
683: if (document.selecteditems.elements[i].value == binname) {
684: var itemname = document.selecteditems.elements[i].name;
685: var itemnum = itemname.substr(9);
1.10 gci 686: element = document.getElementById('item'+itemnum);
687: if (element.checked) {
1.5 gci 688: count ++;
689: }
690: }
691: }
692: }
1.10 gci 693: countelement = document.getElementById('GCI_'+binname+'_count');
694: countelement.value = count;
1.5 gci 695: }
696:
697: function validTestCheck() {
698: var empty = '';
699: for (var i=0; i<11; i++) {
700: var binname = 'GCI_bin'+i+'_count';
701: var j = i+1;
1.10 gci 702: countelement = document.getElementById(binname);
703: if (countelement.value < 1) {
1.5 gci 704: empty = empty +' '+j;
705: }
706: }
707: if (empty != "") {
708: alert("Current test invalid - select at least one item from the following bin(s): "+empty);
709: return false;
710: }
711: return true;
712: }
713:
714: function setDocsPhase() {
715: if (document.choices.concepttest.length) {
716: for (var i=0; i<document.choices.concepttest.length; i++) {
717: if (document.choices.concepttest[i].checked) {
718: if (document.choices.concepttest[i].value == 'defchosen') {
719: document.choices.phase.value = 'storemap';
720: }
721: }
722: }
723: }
724: return;
725: }
726:
1.6 gci 727: $prereqjs
728:
1.5 gci 729: ENDJS
730:
1.1 gci 731: }
732:
733: } #end scope variables
734:
735: 1;
736: __END__
737:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>