Annotation of modules/gci/londocsgci.pm, revision 1.8
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.8 ! gci 5: # $Id: londocsgci.pm,v 1.7 2009/12/25 00:49:35 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.8 ! gci 118: @development = ('001','002','003','004','005','006','007','008','009','010','011','012','013','014');
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);
185: unless ($numchosen > 0) {
186: $r->print('<h3>'.&mt('Create a Concept Test').'</h3>'.
187: '<p>'.&mt('Choose how the test should be built:').'<br />'.
188: '<form name="choices" method="post" action="/adm/coursedocs" onsubmit="javascript:setDocsPhase();">'.
189: '<label><input type="radio" name="concepttest" value="defchosen" />'.&mt('Have a valid test built automatically by the WebCenter.').'</label><br />'.
190: '<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 />'.
191: '<input type="hidden" name="phase" value="" />'.
192: '<input type="submit" name="choosetest" value="'.&mt('Next').'"></p>');
193: return;
194: }
195: if ((!&validcheck($r)) || ($env{'form.concepttest'} eq 'editmyown')) {
196: &editor($r,$context,$cdom,$cnum);
1.3 gci 197: } else {
1.5 gci 198: my $numsub = &get_submissions_count($cdom,$cnum);
199: unless ($env{'form.phase'} eq 'storemap') {
200: $r->print('<p>'.&mt('This course contains a valid concept test which includes [quant,_1,question].',$numchosen).' <a href="/adm/navmaps" target="_coursecontents">'.&mt('Display Contents').'</a><br />');
201: }
202: if ($numsub > 0) {
203: $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>');
204: } else {
205: $r->print('<fieldset><legend>'.&mt('Modify Test').'</legend>'.
206: &mt('Currently no student submissions have been recorded, so you may modify the contents of the Concept Test.').
207: '<br /><form name="changetest" method="post" action="/adm/coursedocs">'.
208: '<input type="hidden" name="concepttest" value="editmyown" />'.
209: '<input type="submit" name="modifytest" value="'.&mt('Edit Concept Test').'" /></form></fieldset></p>');
1.3 gci 210: }
1.5 gci 211: my ($crsparms,$ineffect,$parmlev) = ¤t_parms($cdom,$cnum);
212: my $formname = 'datesform';
213: my $datebutton = &mt('Save');
214: my $startform =
215: &Apache::lonhtmlcommon::date_setter($formname,'opendate',
216: $crsparms->{'opendate'});
217: my $endform =
218: &Apache::lonhtmlcommon::date_setter($formname,'duedate',
219: $crsparms->{'duedate'});
220: $r->print('<p><fieldset><legend>'.&mt('Test Availability').'</legend>'.
221: &mt('Open and close dates for test items for the concept test are currently set as follows:').
222: '<br />'.
223: '<form name="'.$formname.'" method="post" '.
224: 'action="/adm/coursedocs">'.
225: &Apache::lonhtmlcommon::start_pick_box().
226: &Apache::lonhtmlcommon::row_title(&mt('Open date')).
227: $startform.
1.6 gci 228: &Apache::lonhtmlcommon::row_closure(1).
1.5 gci 229: &Apache::lonhtmlcommon::row_title(&mt('Close date')).
230: $endform.
231: &Apache::lonhtmlcommon::end_pick_box().'<br />'.
232: '<input type="hidden" name="phase" value="storeparms" />'.
233: '<input type="submit" value="'.$datebutton.'" />'.
234: '</form></fieldset></p>');
1.1 gci 235: }
1.3 gci 236: }
237:
238: sub editor {
1.5 gci 239: my ($r,$context,$cdom,$cnum)=@_;
240: my %chosenitems=();
241: my $havedev = 0;
242: foreach my $item (@chosen) {
243: $chosenitems{$item}=1;
244: }
245: my @devitems = &get_development_questions($cdom,$cnum);
246: &Apache::lonnet::appenv({'request.gcicontext' => 'buildtest'});
247: $r->print('<form name="selecteditems" method="post" action="/adm/coursedocs"
248: onsubmit="return validTestCheck()">');
249: $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 />');
250: $r->print('<ul>'.
251: '<li>'.&mt('Tests will contain a minimum of [_1] questions from the GCI 2 Inventory.',"<b>$reqnum</b>").'</li>'.
252: '<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>'.
253: '<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>'.
254: '</ul>');
255: my $mandleg = &mt('Mandatory Questions');
256: $r->print(&display_questions(\@mandprobs,'mandatory',$mandleg,\%chosenitems));
257: for (my $i=0; $i<@bins; $i++) {
258: my $num = $i+1;
259: my $legend = &mt('Bin [_1]',$num);
260: my $catname = 'bin'.$i;
261: $r->print(&display_questions($bins[$i],$catname,$legend,\%chosenitems));
262: }
263: my $optleg = &mt('Optional Questions');
264: $r->print(&display_questions(\@optional,'optional',$optleg,\%chosenitems));
265: my $devleg = &mt('Development Questions');
266: $r->print(&display_questions(\@devitems,'development',$devleg,\%chosenitems));
267: $r->print('<input type="hidden" name="phase" value="storemap" />'.
268: '<input type="hidden" name="context" value="'.$context.'" />'.
269: '<input type="submit" value="'.&mt('Store Problem Selection').'" />'.
270: '</form>');
271: &Apache::lonnet::delenv('request.gcicontext');
272: }
273:
274: sub display_questions {
275: my ($questions,$catname,$catlegend,$chosenitems) = @_;
276: return unless((ref($questions) eq 'ARRAY') && (ref($chosenitems) eq 'HASH'));
277: my $total = 0;
278: foreach my $item (@{$questions}) {
279: if ($chosenitems->{$item}) {
280: $total ++;
281: }
282: }
283: my $fieldid = 'GCI_'.$catname.'_q';
284: my $titleid = 'GCI_'.$catname.'_t';
285: my $countid = 'GCI_'.$catname.'_count';
286: my $output = '<fieldset>';
287: my %fixed = (
288: mandatory => 4,
289: development => 2,
290: );
291: if (($catname eq 'mandatory') || ($catname eq 'development')) {
292: $output .= '<legend>'.&mt('[_1] [_2] selected automatically',$catlegend,
293: '<input type="text" name="'.$countid.'" size="1" '.
294: 'value="'.$fixed{$catname}.'" readonly="readonly" />').'</legend>';
295: } else {
296: $output .= '<legend>'.&mt('[_1]: currently [_2] selected',$catlegend,
297: '<input type="text" name="'.$countid.'" size="1" value="'.
298: $total.'" readonly="readonly" />').'</legend>';
299: }
300: $output .= '<span id="'.$titleid.'">'.
301: '<a href="javascript:showQuestions('."'$fieldid','$titleid'".')">'.
302: &mt('Show').'</a> ...</span><br />'.
303: '<div id="'.$fieldid.'">'.
304: &Apache::loncommon::start_data_table().
305: &Apache::loncommon::start_data_table_header_row();
306: unless (($catname eq 'development') || ($catname eq 'mandatory')) {
307: $output .= '<th>'.&mt('Select').'</th>';
308: }
309: $output .= '<th>'.&mt('Problem').
310: '</th><th>'.&mt('Preview').'</th>'.
311: &Apache::loncommon::end_data_table_header_row();
312: foreach my $item (@{$questions}) {
1.8 ! gci 313: my $url = &fullurl($item,$catname);
1.5 gci 314: my $title = &Apache::lonnet::metadata($url,'title');
315: $output .= &Apache::loncommon::start_data_table_row().'<td>';
1.8 ! gci 316: if ($catname eq 'mandatory') {
1.5 gci 317: $output .= '<input type="hidden" name="item'.$item.'" value="checked" />';
1.8 ! gci 318: } elsif ($catname eq 'development') {
! 319: $output .= '<input type="hidden" name="pilot'.$item.'" value="checked" />';
1.5 gci 320: } else {
321: $output .= '<input type="checkbox" name="item'.$item.'"';
322: if ($chosenitems->{$item}) { $output .= ' checked="checked"'; }
1.6 gci 323: $output .= ' onclick="countChecked('."'$catname'".');';
324: my $binname;
325: if ($prereqs{$item}) {
326: for (my $i=0; $i<@bincats; $i++) {
327: if ($bincats[$i] eq $probcat{$prereqs{$item}}) {
328: $binname = 'bin'.$i;
329: last;
330: }
331: }
332: $output .= 'checkPrereqs('."'dep','$item','$prereqs{$item}','$binname'".');';
333: } elsif ($revreqs{$item}) {
334: for (my $i=0; $i<@bincats; $i++) {
335: if ($bincats[$i] eq $probcat{$item}) {
336: $binname = 'bin'.$i;
337: last;
338: }
339: }
340: $output .= 'checkPrereqs('."'pre','$revreqs{$item}','$item','$binname'".');';
341: }
342: $output .= '" />'.
1.5 gci 343: '<input type="hidden" name="container'.$item.'" value="'.
344: $catname.'"></td><td>';
345: }
346: $output .= '<b>'.$title.'</b></td>';
347: my $content=&Apache::lonindexer::showpreview($url);
348: $output .= '<td> '.($content eq '' ? ' ':$content).' </td>'."\n".
349: &Apache::loncommon::end_data_table_row();
350: }
351: $output .= &Apache::loncommon::end_data_table().
352: '</div></fieldset><br />';
353: return $output;
354: }
355:
356: sub get_development_questions {
357: my ($cdom,$cnum) = @_;
358: my $cid = $cdom.'_'.$cnum;
359: my %courseenv = &Apache::lonnet::userenvironment($cdom,$cnum,
360: ('internal.courseowner'));
361: my $seed = $courseenv{'internal.courseowner'};
362: my $rndseed=&Apache::lonnet::rndseed($seed,$cid,$cdom,$cnum);
363: &Apache::lonnet::setup_random_from_rndseed($rndseed);
364: my @devitems = &Math::Random::random_permutation(@development);
365: return ($devitems[0],$devitems[1]);
1.1 gci 366: }
367:
368: sub evaluate {
369: if ($env{'form.phase'} eq 'storemap') {
370: @chosen=();
371: foreach my $item (@allprobs) {
372: if ($env{'form.item'.$item}) {
373: push(@chosen,$item);
374: }
375: }
376: }
377: }
378:
379: sub mapread_gci {
380: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
381: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
382: return
1.5 gci 383: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/default_1261144274.sequence');
1.1 gci 384: }
385:
386: sub storemap_gci {
1.5 gci 387: my ($coursedom,$coursenum) = @_;
388: if (($coursedom !~ /^$match_domain$/) || ($coursenum !~ /^$match_courseid$/)) {
389: $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
390: $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
391: }
392: return ('unauthorized',2) if (($coursedom eq '') || ($coursedom eq '') ||
393: (!&Apache::lonnet::allowed('mdc',$coursedom.'_'.$coursenum)));
1.1 gci 394: my ($outtext,$errtext)=
1.5 gci 395: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/default_1261144274.sequence',1);
1.1 gci 396: if ($errtext) { return ($errtext,2); }
397: return ($errtext,0);
398: }
399:
400: sub chosen_to_map {
401: my %chosenproblems=();
402: foreach my $item (@chosen) {
403: $chosenproblems{$item}=1;
404: }
405: @LONCAPA::map::order=();
406: @LONCAPA::map::resources=();
1.5 gci 407: my $counter = 0;
1.8 ! gci 408: my $residx;
1.1 gci 409: for (my $idx=0;$idx<=$#allprobs;$idx++) {
1.8 ! gci 410: $residx=$idx+1;
1.1 gci 411: if ($chosenproblems{$allprobs[$idx]}) {
1.6 gci 412: my $url = &LONCAPA::map::qtunescape(&fullurl($allprobs[$idx]));
413: if (($revreqs{$allprobs[$idx]}) &&
414: ($chosenproblems{$revreqs{$allprobs[$idx]}})) {
1.7 gci 415: my $probnum = '_'.$allprobs[$idx].'_'.$revreqs{$allprobs[$idx]};
1.6 gci 416: $url = &LONCAPA::map::qtunescape(&fullurl($probnum));
417: } elsif ($prereqs{$allprobs[$idx]}) {
418: next;
419: }
1.1 gci 420: push(@LONCAPA::map::order,$residx);
1.5 gci 421: $counter ++;
422: my $name = &LONCAPA::map::qtunescape('Problem '.$counter);
1.1 gci 423: $LONCAPA::map::resources[$residx]=join(':', ($name, $url, 'false', 'normal', 'res'));
424: }
425: }
1.8 ! gci 426: foreach my $devitem (@development) {
! 427: if ($env{'form.pilot'.$devitem}) {
! 428: my $url = &LONCAPA::map::qtunescape(&fullurl($devitem,'development'));
! 429: $residx ++;
! 430: push(@LONCAPA::map::order,$residx);
! 431: $counter ++;
! 432: my $name = &LONCAPA::map::qtunescape('Problem '.$counter);
! 433: $LONCAPA::map::resources[$residx]=join(':', ($name, $url, 'false', 'normal', 'res'));
! 434: }
! 435: }
1.1 gci 436: }
437:
438: sub map_to_chosen {
439: @chosen=();
440: foreach my $idx (@LONCAPA::map::order) {
1.6 gci 441: my ($title,$url)=split(':',$LONCAPA::map::resources[$idx]);
442: my $item;
1.5 gci 443: unless ($url eq '') {
1.6 gci 444: $item = &item_from_url($url);
445: if (($item =~ /^(\d+)_(\d+)$/) && ($prereqs{$2} eq $1)) {
446: push(@chosen,($1,$2));
447: } else {
448: push(@chosen,$item);
449: }
1.5 gci 450: }
451: }
452: if (($env{'form.concepttest'} eq 'defchosen') ||
453: ((@chosen == 0) && ($env{'form.concepttest'} eq 'editmyown'))) {
454: @chosen = @defchosen;
1.1 gci 455: }
456: }
457:
458: sub store {
1.5 gci 459: my ($caller,$cdom,$cnum)=@_;
460: if ($env{'form.concepttest'} eq 'defchosen') {
461: @chosen = @defchosen;
462: }
1.1 gci 463: my @errors=&checkvalid();
1.5 gci 464: if (@errors > 0) {
465: if (($caller eq 'requestcrs') && ($env{'form.concepttest'} eq 'defchosen')) {
1.6 gci 466: return &mt('Invalid concept test.');
1.5 gci 467: } else {
1.6 gci 468: my $errormsg = '<span class="LC_warning">'.&mt('Invalid concept test:');
469: if (@errors > 1) {
470: $errormsg .= '<ul><li>'.join('</li><li>',@errors).'</li></ul>';
471: } else {
472: $errormsg .= '<br />'.$errors[0];
473: }
474: $errormsg .= '</span>';
475: return $errormsg;
1.5 gci 476: }
477: }
1.1 gci 478: &chosen_to_map();
1.5 gci 479: my ($err,$errnum) = &storemap_gci($cdom,$cnum);
480: if ($caller eq 'requestcrs') {
481: if ($errnum == 0) {
482: return;
483: } else {
484: return 'An error occurred when storing the concept test';
485: }
486: }
1.3 gci 487: if ($env{'form.phase'} eq 'storemap') {
1.5 gci 488: if ($errnum == 0) {
489: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
490: return '<p>'.&mt('You have successfully assembled a valid test.').'</p>'.
491: '<p><a href="/adm/navmaps">'.&mt('Display Table of Contents').
492: '</a>'.(' ' x4).'<a href="/adm/menu">'.&mt('Return to Main Menu').'</a></p>';
493: } else {
494: return '<div class="LC_error">'.&mt('An error occurred when storing your concept test: [_1].',$err).'</div>';
1.3 gci 495: }
1.1 gci 496: }
1.5 gci 497: return;
1.1 gci 498: }
499:
500: sub load {
501: &mapread_gci();
502: &map_to_chosen();
1.5 gci 503: if (@chosen > 0) {
504: my @errors=&checkvalid();
505: if ($#errors>1) { @chosen=@defchosen; }
506: }
507: }
508:
509: sub current_parms {
510: my ($cdom,$cnum) = @_;
511: my $courseopt=&Apache::lonnet::get_courseresdata($cnum,$cdom);
512: my (%crsparms,%ineffect,%parmlev);
513: foreach my $item ('opendate','duedate') {
514: $crsparms{$item} = $courseopt->{$env{'request.course.id'}.'.0.'.$item};
515: my ($result,@outpar) =
516: &Apache::lonparmset::parmval('0.'.$item,'0.0',undef,undef,
517: $cdom,undef,undef,$courseopt);
518: if ($result) {
519: $ineffect{$item} = $outpar[$result];
520: $parmlev{$item} = $result;
521: }
522: }
523: return (\%crsparms,\%ineffect,\%parmlev);
524: }
525:
526: sub store_dates_parms {
527: my ($cdom,$cnum) = @_;
528: my $topsymb = '___0___uploaded/'.$cdom.'/'.$cnum.'/default.sequence';
529: my ($opendate,$duedate) =
530: &Apache::lonuserutils::get_dates_from_form('opendate','duedate');
531: my %dates = (
532: opendate => {
533: value => $opendate,
534: type => 'date_start',
535: },
536: duedate => {
537: value => $duedate,
538: type => 'date_end',
539: },
540: );
541: my %parmresult;
542: foreach my $date (keys(%dates)) {
543: $parmresult{$date} =
544: &Apache::lonparmset::storeparm_by_symb($topsymb,
545: '0_'.$date,14,$dates{$date}{'value'},
546: $dates{$date}{'type'},undef,$cdom);
547: }
548: my $output = &mt('Open and Close dates set for test items').'<ul>'.
549: '<li>'.&mt('Concept Test Questions open:').' '.
550: &Apache::lonlocal::locallocaltime($opendate).'</li>'.
551: '<li>'.&mt('Concept Test Questions close:').' '.
552: &Apache::lonlocal::locallocaltime($duedate).'</li>'.
553: '</ul>';
554: return $output;
555: }
556:
557: sub get_submissions_count {
558: my ($cdom,$cnum) = @_;
559: my $navmap = Apache::lonnavmaps::navmap->new();
560: if (!defined($navmap)) {
561: 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>';
562: return $itemserror;
563: }
564: my @allres=$navmap->retrieveResources('/uploaded/'.$cdom.'/'.$cnum.'/default_1261144274.sequence',sub {if ($_[0]->is_problem) { $_[0]->parts();} return 1;});
565: my (%resourcetracker,$submissioncount);
566: my %resourcetracker = &Apache::lonnet::dump('nohist_resourcetracker',
567: $cdom,$cnum);
568: foreach my $resource (@allres) {
569: my $symb = $resource->symb();
570: my @parts = @{$resource->parts()};
571: foreach my $part (@parts) {
572: if ($resource->handgrade($part) eq 'yes') {
573: next;
574: }
575: if ($resource->is_survey($part)) {
576: next;
577: }
578: if (exists($resourcetracker{$symb."\0".$part."\0users"})) {
579: $submissioncount += $resourcetracker{$symb."\0".$part."\0users"};
580: }
581: }
582: }
583: return $submissioncount;
584: }
585:
586: sub builder_javascript {
587: my %lt = &Apache::lonlocal::texthash(
588: show => 'Show',
589: hide => 'Hide',
590: );
1.6 gci 591: my $prereqjs = "
592: function checkPrereqs(caller,item,prereq,binname) {
593: var changedPrereq = 0;
594: if (document.selecteditems.elements['item'+item].checked == false) {
595: return;
596: } else {
597: if (!document.selecteditems.elements['item'+prereq].checked) {
598: document.selecteditems.elements['item'+prereq].checked = true;
599: changedPrereq = 1;
600: countChecked(binname);
601: }
602: }
603: ";
604:
605: my ($hasdep,$prereq,$hasdeptitle,$prereqtitle) = ('','','','');
606: foreach my $item (sort(keys(%prereqs))) {
607: $hasdep .= "'$item',";
608: $prereq .= "'$prereqs{$item}',";
609: my $url = &fullurl($item);
610: $hasdeptitle .= "'".&Apache::lonnet::metadata($url,'title')."',";
611: my $purl = &fullurl($prereqs{$item});
612: $prereqtitle .= "'".&Apache::lonnet::metadata($purl,'title')."',";
613: }
614: $hasdep =~ s/,$//;
615: $prereq =~ s/,$//;
616: $hasdeptitle =~ s/,$//;
617: $prereqtitle =~ s/,$//;
618:
619: $prereqjs .= <<"ENDFN";
620:
621: var hasDeps = Array($hasdep);
622: var preReqs = Array($prereq);
623: var hasDepTitles = Array($hasdeptitle);
624: var preReqTitles = Array($prereqtitle);
625: for (var i=0; i<hasDeps.length; i++) {
626: if (hasDeps[i] == item) {
627: var msg = hasDepTitles[i]+' question has a prerequisite: '+preReqTitles[i]+'.\\nThe two questions will appear together in a composite question.';
628: if (changedPrereq == 1) {
629: msg = msg+'\\n\\nAs the prerequisite was not checked, inclusion of '+hasDepTitles[i]+' has now caused '+preReqTitles[i]+' to also be checked automatically.';
630: }
631: if (caller == 'pre') {
632: 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.'
633: }
634: alert(msg);
635: break;
636: }
637: }
638: return;
639: }
640:
641: ENDFN
642:
1.5 gci 643: return <<ENDJS;
644: function showQuestions(content,title) {
645: document.getElementById(content).style.display = "";
646: document.getElementById(title).innerHTML='<a href="javascript:hideQuestions('+"'"+content+"','"+title+"'"+');">$lt{'hide'}</a> ...';
647: return;
648: }
649:
650: function hideQuestions(content,title) {
651: document.getElementById(content).style.display = "none";
652: document.getElementById(title).innerHTML='<a href="javascript:showQuestions('+"'"+content+"','"+title+"'"+')">$lt{'show'}</a> ...';
653: return;
654: }
655:
656: function setInitialVisibility() {
657: if (document.getElementById('GCI_mandatory_q') == null) {
658: return;
659: }
660: document.getElementById('GCI_mandatory_q').style.display = "none";
661: document.getElementById('GCI_bin0_q').style.display = "none";
662: document.getElementById('GCI_bin1_q').style.display = "none";
663: document.getElementById('GCI_bin2_q').style.display = "none";
664: document.getElementById('GCI_bin3_q').style.display = "none";
665: document.getElementById('GCI_bin4_q').style.display = "none";
666: document.getElementById('GCI_bin5_q').style.display = "none";
667: document.getElementById('GCI_bin6_q').style.display = "none";
668: document.getElementById('GCI_bin7_q').style.display = "none";
669: document.getElementById('GCI_bin8_q').style.display = "none";
670: document.getElementById('GCI_bin9_q').style.display = "none";
671: document.getElementById('GCI_bin10_q').style.display = "none";
672: document.getElementById('GCI_optional_q').style.display = "none";
673: document.getElementById('GCI_development_q').style.display = "none";
674: }
675:
676: function countChecked(binname) {
677: var count = 0;
678: for (var i=0; i<document.selecteditems.elements.length; i++) {
679: if (document.selecteditems.elements[i].type == "hidden") {
680: if (document.selecteditems.elements[i].value == binname) {
681: var itemname = document.selecteditems.elements[i].name;
682: var itemnum = itemname.substr(9);
683: if (document.selecteditems.elements['item'+itemnum].checked) {
684: count ++;
685: }
686: }
687: }
688: }
689: document.selecteditems.elements['GCI_'+binname+'_count'].value = count;
690: }
691:
692: function validTestCheck() {
693: var empty = '';
694: for (var i=0; i<11; i++) {
695: var binname = 'GCI_bin'+i+'_count';
696: var j = i+1;
697: if (document.selecteditems.elements[binname].value < 1) {
698: empty = empty +' '+j;
699: }
700: }
701: if (empty != "") {
702: alert("Current test invalid - select at least one item from the following bin(s): "+empty);
703: return false;
704: }
705: return true;
706: }
707:
708: function setDocsPhase() {
709: if (document.choices.concepttest.length) {
710: for (var i=0; i<document.choices.concepttest.length; i++) {
711: if (document.choices.concepttest[i].checked) {
712: if (document.choices.concepttest[i].value == 'defchosen') {
713: document.choices.phase.value = 'storemap';
714: alert("Setting value for phase to "+document.choices.phase.value);
715:
716: }
717: }
718: }
719: }
720: return;
721: }
722:
1.6 gci 723: $prereqjs
724:
1.5 gci 725: ENDJS
726:
1.1 gci 727: }
728:
729: } #end scope variables
730:
731: 1;
732: __END__
733:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>