File:  [LON-CAPA] / modules / gci / londocsgci.pm
Revision 1.9: download - view: text, annotated - select for diffs
Tue Jan 5 23:54:31 2010 UTC (14 years, 3 months ago) by gci
Branches: MAIN
CVS tags: HEAD
- Customization for GCI_3.
  - Question count displayed allows for two-part problems (i.e., questions with prerequisites displayed as "composite" two-part problems).

    1: # The LearningOnline Network
    2: # Custom Edit Course Routines for Assembly of Valid Concept Tests from
    3: # Geoscience Concept Inventory. 
    4: #
    5: # $Id: londocsgci.pm,v 1.9 2010/01/05 23:54:31 gci Exp $
    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;
   47: my @mandcats;
   48: my @bincats;
   49: my @categories;
   50: my @allprobs;
   51: my %probcat;
   52: my %prereqs;
   53: my %revreqs;
   54: my @defchosen;
   55: my @chosen;
   56: my @mandprobs;
   57: my @bins;
   58: my @optional;
   59: my %mandatory;
   60: my @development;
   61: 
   62: sub setdefaults {
   63:    $path='/res/gci/gci';
   64:    $version='GCIv2-1-1';
   65:    $reqnum=15;
   66:    @allprobs=('01','02','37','2004_73','03','04','05','06','07',
   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',
   73:               '31','32','33','34','35','36','38',
   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',
   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');
   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' ,
   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' ,
  102:               '21' => 'D' ,'22' => 'D' ,'23' => 'D' ,'24' => 'D' ,'25' => 'D' ,'26' => 'E' ,'27' => 'E' ,'28' => 'E' ,'29' => ''  ,'30' => 'E' ,
  103:               '31' => ''  ,'32' => 'F' ,'33' => 'F' ,'34' => 'F' ,'35' => 'F' ,'36' => 'F' ,'38' => 'G' ,
  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' ,
  110:               '71' => 'K');
  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');
  118:     @development = ('001','002','003','004','005','006','007','008','009','010','011','012','013','014');
  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}) {
  135:          push(@errors,&mt('Bin [_1] not covered.',$cat));
  136:       }
  137:    }
  138:    foreach my $item (@chosen) {
  139:        if ($prereqs{$item}) {
  140:           unless ($chosenproblems{$prereqs{$item}}) {
  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'"));
  146:           }
  147:        }
  148:    }
  149:    return @errors;
  150: }
  151: 
  152: sub fullurl {
  153:    my ($item,$catname)=@_;
  154:    unless ($item=~/\_/) { $item='_'.$item; }
  155:    if ($catname eq 'development') {
  156:        return $path.'/pilot/pilot'.$item.'.problem';
  157:    }
  158:    return $path.'/'.$version.'/GCI'.$item.'.problem';
  159: }
  160: 
  161: sub item_from_url {
  162:     my ($url)=@_;
  163:     if ($url =~ m{\Q$path\E/\Q$version\E/GCI_?([^.]+)\.problem$}) {
  164:         return $1;
  165:     }
  166: }
  167: 
  168: sub validcheck {
  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>');
  177:       return 0;
  178:    }
  179:    return 1;
  180: }
  181: 
  182: sub listresources {
  183:    my ($r,$context,$cdom,$cnum)=@_;
  184:    my $numchosen = scalar(@chosen);
  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 = '.&nbsp;';
  198:        }
  199:    }
  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);
  212:    } else {
  213:       my $numsub = &get_submissions_count($cdom,$cnum);
  214:       unless ($env{'form.phase'} eq 'storemap') {
  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 />');
  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>');
  225:       }
  226:       my ($crsparms,$ineffect,$parmlev) = &current_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.
  243:                 &Apache::lonhtmlcommon::row_closure(1).
  244:                 &Apache::lonhtmlcommon::row_title(&mt('Close date')).
  245:                 $endform.
  246:                  &Apache::lonhtmlcommon::end_pick_box().'<br />'. 
  247:                 '<input type="hidden" name="phase" value="storeparms" />'.
  248:                 '<input type="submit" value="'.$datebutton.'" />'.
  249:                 '</form></fieldset></p>');
  250:    }
  251: }
  252: 
  253: sub editor {
  254:     my ($r,$context,$cdom,$cnum)=@_;
  255:     my %chosenitems=();
  256:     my $havedev = 0;
  257:     foreach my $item (@chosen) {
  258:         $chosenitems{$item}=1;
  259:     }
  260:     my @devitems = &get_development_questions($cdom,$cnum);
  261:     &Apache::lonnet::appenv({'request.gcicontext' => 'buildtest'});
  262:     $r->print('<form name="selecteditems" method="post" action="/adm/coursedocs"
  263:               onsubmit="return validTestCheck()">');
  264:     $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 />');
  265:     $r->print('<ul>'.
  266:               '<li>'.&mt('Tests will contain a minimum of [_1] questions from the GCI 2 Inventory.',"<b>$reqnum</b>").'</li>'.
  267:               '<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>'.
  268:               '<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>'.
  269:               '</ul>');
  270:     my $mandleg = &mt('Mandatory Questions');
  271:     $r->print(&display_questions(\@mandprobs,'mandatory',$mandleg,\%chosenitems));
  272:     for (my $i=0; $i<@bins; $i++) {
  273:         my $num = $i+1;
  274:         my $legend = &mt('Bin [_1]',$num);
  275:         my $catname = 'bin'.$i;
  276:         $r->print(&display_questions($bins[$i],$catname,$legend,\%chosenitems));
  277:     }
  278:     my $optleg = &mt('Optional Questions');
  279:     $r->print(&display_questions(\@optional,'optional',$optleg,\%chosenitems));
  280:     my $devleg = &mt('Development Questions');
  281:     $r->print(&display_questions(\@devitems,'development',$devleg,\%chosenitems));
  282:     $r->print('<input type="hidden" name="phase" value="storemap" />'.
  283:               '<input type="hidden" name="context" value="'.$context.'" />'.
  284:               '<input type="submit" value="'.&mt('Store Problem Selection').'" />'.
  285:               '</form>');
  286:     &Apache::lonnet::delenv('request.gcicontext');
  287: }
  288: 
  289: sub display_questions {
  290:     my ($questions,$catname,$catlegend,$chosenitems) = @_;
  291:     return unless((ref($questions) eq 'ARRAY') && (ref($chosenitems) eq 'HASH'));
  292:     my $total = 0;
  293:     foreach my $item (@{$questions}) {
  294:         if ($chosenitems->{$item}) {
  295:             $total ++;
  296:         }
  297:     }
  298:     my $fieldid = 'GCI_'.$catname.'_q';
  299:     my $titleid = 'GCI_'.$catname.'_t';
  300:     my $countid = 'GCI_'.$catname.'_count';
  301:     my $output = '<fieldset>';
  302:     my %fixed = (
  303:         mandatory   => 4,
  304:         development => 2, 
  305:     );
  306:     if (($catname eq 'mandatory') || ($catname eq 'development')) {
  307:         $output .= '<legend>'.&mt('[_1] [_2] selected automatically',$catlegend,
  308:                    '<input type="text" name="'.$countid.'" size="1" '.
  309:                    'value="'.$fixed{$catname}.'" readonly="readonly" />').'</legend>';
  310:     } else {
  311:         $output .= '<legend>'.&mt('[_1]: currently [_2] selected',$catlegend,
  312:                    '<input type="text" name="'.$countid.'" size="1" value="'.
  313:                    $total.'" readonly="readonly" />').'</legend>';
  314:     }
  315:     $output .= '<span id="'.$titleid.'">'.
  316:               '<a href="javascript:showQuestions('."'$fieldid','$titleid'".')">'.
  317:               &mt('Show').'</a> ...</span><br />'.
  318:               '<div id="'.$fieldid.'">'.
  319:               &Apache::loncommon::start_data_table().
  320:               &Apache::loncommon::start_data_table_header_row();
  321:     unless (($catname eq 'development') || ($catname eq 'mandatory')) {
  322:         $output .= '<th>'.&mt('Select').'</th>';
  323:     }
  324:     $output .= '<th>'.&mt('Problem').
  325:                '</th><th>'.&mt('Preview').'</th>'.
  326:                &Apache::loncommon::end_data_table_header_row();
  327:     foreach my $item (@{$questions}) {
  328:         my $url = &fullurl($item,$catname);
  329:         my $title = &Apache::lonnet::metadata($url,'title');
  330:         $output .= &Apache::loncommon::start_data_table_row().'<td>';
  331:         if ($catname eq 'mandatory') {
  332:             $output .= '<input type="hidden" name="item'.$item.'" value="checked" />';
  333:         } elsif ($catname eq 'development') {
  334:             $output .= '<input type="hidden" name="pilot'.$item.'" value="checked" />';
  335:         } else {
  336:             $output .= '<input type="checkbox" name="item'.$item.'"';
  337:             if ($chosenitems->{$item}) { $output .= ' checked="checked"'; }
  338:             $output .= ' onclick="countChecked('."'$catname'".');';
  339:             my $binname;
  340:             if ($prereqs{$item}) {
  341:                 for (my $i=0; $i<@bincats; $i++) {
  342:                     if ($bincats[$i] eq $probcat{$prereqs{$item}}) {
  343:                         $binname = 'bin'.$i; 
  344:                         last;
  345:                     }
  346:                 }
  347:                 $output .= 'checkPrereqs('."'dep','$item','$prereqs{$item}','$binname'".');';
  348:             } elsif ($revreqs{$item}) {
  349:                 for (my $i=0; $i<@bincats; $i++) {
  350:                     if ($bincats[$i] eq $probcat{$item}) {
  351:                         $binname = 'bin'.$i;
  352:                         last;
  353:                     }
  354:                 }
  355:                 $output .= 'checkPrereqs('."'pre','$revreqs{$item}','$item','$binname'".');';
  356:             }
  357:             $output .= '" />'.
  358:                        '<input type="hidden" name="container'.$item.'" value="'.
  359:                        $catname.'"></td><td>';
  360:         }
  361:         $output .= '<b>'.$title.'</b></td>';
  362:         my $content=&Apache::lonindexer::showpreview($url);
  363:         $output .= '<td> '.($content eq '' ? '&nbsp;':$content).' </td>'."\n".
  364:                    &Apache::loncommon::end_data_table_row();
  365:     }
  366:     $output .= &Apache::loncommon::end_data_table().
  367:                '</div></fieldset><br />';
  368:     return $output;
  369: }
  370: 
  371: sub get_development_questions {
  372:     my ($cdom,$cnum) = @_;
  373:     my $cid = $cdom.'_'.$cnum;
  374:     my %courseenv = &Apache::lonnet::userenvironment($cdom,$cnum,
  375:                         ('internal.courseowner'));
  376:     my $seed = $courseenv{'internal.courseowner'};
  377:     my $rndseed=&Apache::lonnet::rndseed($seed,$cid,$cdom,$cnum);
  378:     &Apache::lonnet::setup_random_from_rndseed($rndseed);
  379:     my @devitems = &Math::Random::random_permutation(@development);
  380:     return ($devitems[0],$devitems[1]); 
  381: }
  382: 
  383: sub evaluate {
  384:    if ($env{'form.phase'} eq 'storemap') {
  385:       @chosen=();
  386:       foreach my $item (@allprobs) {
  387:          if ($env{'form.item'.$item}) {
  388:             push(@chosen,$item);
  389:          }
  390:       }
  391:    }
  392: }
  393: 
  394: sub mapread_gci {
  395:     my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
  396:     my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
  397:     return
  398:       &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/default_1261144274.sequence');
  399: }
  400: 
  401: sub storemap_gci {
  402:     my ($coursedom,$coursenum) = @_;
  403:     if (($coursedom !~ /^$match_domain$/) || ($coursenum !~ /^$match_courseid$/)) { 
  404:         $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
  405:         $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
  406:     }
  407:     return ('unauthorized',2) if (($coursedom eq '') || ($coursedom eq '') ||
  408:                    (!&Apache::lonnet::allowed('mdc',$coursedom.'_'.$coursenum)));
  409:     my ($outtext,$errtext)=
  410:         &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/default_1261144274.sequence',1);
  411:     if ($errtext) { return ($errtext,2); }
  412:     return ($errtext,0);
  413: }
  414: 
  415: sub chosen_to_map {
  416:    my %chosenproblems=();
  417:    foreach my $item (@chosen) {
  418:       $chosenproblems{$item}=1;
  419:    }
  420:    @LONCAPA::map::order=();
  421:    @LONCAPA::map::resources=();
  422:    my $counter = 0;
  423:    my $residx;
  424:    for (my $idx=0;$idx<=$#allprobs;$idx++) {
  425:        $residx=$idx+1;
  426:        if ($chosenproblems{$allprobs[$idx]}) {
  427:           my $url  = &LONCAPA::map::qtunescape(&fullurl($allprobs[$idx]));
  428:           if (($revreqs{$allprobs[$idx]}) && 
  429:               ($chosenproblems{$revreqs{$allprobs[$idx]}})) {
  430:               my $probnum = '_'.$allprobs[$idx].'_'.$revreqs{$allprobs[$idx]};
  431:               $url = &LONCAPA::map::qtunescape(&fullurl($probnum));
  432:           } elsif ($prereqs{$allprobs[$idx]}) {
  433:               next;
  434:           }
  435:           push(@LONCAPA::map::order,$residx);
  436:           $counter ++;
  437: 	  my $name = &LONCAPA::map::qtunescape('Problem '.$counter);
  438: 	  $LONCAPA::map::resources[$residx]=join(':', ($name, $url, 'false', 'normal', 'res'));
  439:        }
  440:     }
  441:     foreach my $devitem (@development) {
  442:         if ($env{'form.pilot'.$devitem}) {
  443:             my $url = &LONCAPA::map::qtunescape(&fullurl($devitem,'development'));
  444:             $residx ++;
  445:             push(@LONCAPA::map::order,$residx);
  446:             $counter ++;
  447:             my $name = &LONCAPA::map::qtunescape('Problem '.$counter);
  448:             $LONCAPA::map::resources[$residx]=join(':', ($name, $url, 'false', 'normal', 'res'));
  449:         }
  450:     }
  451: }
  452: 
  453: sub map_to_chosen {
  454:     @chosen=();
  455:     foreach my $idx (@LONCAPA::map::order) {
  456:        my ($title,$url)=split(':',$LONCAPA::map::resources[$idx]);
  457:        my $item;
  458:        unless ($url eq '') {
  459:            $item = &item_from_url($url);
  460:            if (($item =~ /^(\d+)_(\d+)$/) && ($prereqs{$2} eq $1)) {
  461:                push(@chosen,($1,$2));
  462:            } else {
  463:                push(@chosen,$item);
  464:            }
  465:        }
  466:     }
  467:     if (($env{'form.concepttest'} eq 'defchosen') || 
  468:         ((@chosen == 0) && ($env{'form.concepttest'} eq 'editmyown'))) {
  469:         @chosen = @defchosen;
  470:     }
  471: }
  472: 
  473: sub store {
  474:    my ($caller,$cdom,$cnum)=@_;
  475:    if ($env{'form.concepttest'} eq 'defchosen') {
  476:        @chosen = @defchosen;
  477:    }
  478:    my @errors=&checkvalid();
  479:    if (@errors > 0) {
  480:        if (($caller eq 'requestcrs') && ($env{'form.concepttest'} eq 'defchosen')) {
  481:            return &mt('Invalid concept test.');
  482:        } else {
  483:            my $errormsg = '<span class="LC_warning">'.&mt('Invalid concept test:');
  484:            if (@errors > 1) {
  485:                $errormsg .= '<ul><li>'.join('</li><li>',@errors).'</li></ul>';
  486:            } else {
  487:                $errormsg .= '<br />'.$errors[0];
  488:            }
  489:            $errormsg .= '</span>';
  490:            return $errormsg;
  491:        }
  492:    }
  493:    &chosen_to_map();
  494:    my ($err,$errnum) = &storemap_gci($cdom,$cnum);
  495:    if ($caller eq 'requestcrs') {
  496:        if ($errnum == 0) {
  497:            return; 
  498:        } else {
  499:            return 'An error occurred when storing the concept test';
  500:        }
  501:    }
  502:    if ($env{'form.phase'} eq 'storemap') {
  503:       if ($errnum == 0) {
  504:          &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
  505:          return '<p>'.&mt('You have successfully assembled a valid test.').'</p>'.
  506:                 '<p><a href="/adm/navmaps">'.&mt('Display Table of Contents').
  507:                 '</a>'.('&nbsp;' x4).'<a href="/adm/menu">'.&mt('Return to Main Menu').'</a></p>';
  508:       } else {
  509:           return '<div class="LC_error">'.&mt('An error occurred when storing your concept test: [_1].',$err).'</div>';
  510:       }
  511:    }
  512:    return;
  513: }
  514: 
  515: sub load {
  516:    &mapread_gci();
  517:    &map_to_chosen();
  518:    if (@chosen > 0) {
  519:        my @errors=&checkvalid();
  520:        if ($#errors>1) { @chosen=@defchosen; }
  521:    }
  522: }
  523: 
  524: sub current_parms {
  525:     my ($cdom,$cnum) = @_;
  526:     my $courseopt=&Apache::lonnet::get_courseresdata($cnum,$cdom);
  527:     my (%crsparms,%ineffect,%parmlev);
  528:     foreach my $item ('opendate','duedate') {
  529:         $crsparms{$item} = $courseopt->{$env{'request.course.id'}.'.0.'.$item};
  530:         my ($result,@outpar) =
  531:             &Apache::lonparmset::parmval('0.'.$item,'0.0',undef,undef,
  532:                                          $cdom,undef,undef,$courseopt);
  533:         if ($result) {
  534:             $ineffect{$item} = $outpar[$result];
  535:             $parmlev{$item} = $result;
  536:         }
  537:     }
  538:     return (\%crsparms,\%ineffect,\%parmlev);
  539: }
  540: 
  541: sub store_dates_parms {
  542:     my ($cdom,$cnum) = @_;
  543:     my $topsymb = '___0___uploaded/'.$cdom.'/'.$cnum.'/default.sequence';
  544:     my ($opendate,$duedate) = 
  545:         &Apache::lonuserutils::get_dates_from_form('opendate','duedate');
  546:     my %dates = (
  547:                   opendate => {
  548:                                value => $opendate,
  549:                                type  => 'date_start',
  550:                               },
  551:                   duedate => {
  552:                                value => $duedate,
  553:                                type  => 'date_end',
  554:                              },
  555:                 );
  556:     my %parmresult;
  557:     foreach my $date (keys(%dates)) {
  558:         $parmresult{$date} =
  559:             &Apache::lonparmset::storeparm_by_symb($topsymb,
  560:                                    '0_'.$date,14,$dates{$date}{'value'},
  561:                                    $dates{$date}{'type'},undef,$cdom);
  562:     }
  563:     my $output = &mt('Open and Close dates set for test items').'<ul>'.
  564:                  '<li>'.&mt('Concept Test Questions open:').' '.
  565:                         &Apache::lonlocal::locallocaltime($opendate).'</li>'.
  566:                  '<li>'.&mt('Concept Test Questions close:').' '.
  567:                         &Apache::lonlocal::locallocaltime($duedate).'</li>'.
  568:                  '</ul>';
  569:     return $output;
  570: }
  571: 
  572: sub get_submissions_count {
  573:     my ($cdom,$cnum) = @_;
  574:     my $navmap = Apache::lonnavmaps::navmap->new();
  575:     if (!defined($navmap)) {
  576:         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>';
  577:         return $itemserror;
  578:     }
  579:     my @allres=$navmap->retrieveResources('/uploaded/'.$cdom.'/'.$cnum.'/default_1261144274.sequence',sub {if ($_[0]->is_problem) { $_[0]->parts();} return 1;});
  580:     my (%resourcetracker,$submissioncount);
  581:     my %resourcetracker =  &Apache::lonnet::dump('nohist_resourcetracker',
  582:                                                  $cdom,$cnum);
  583:     foreach my $resource (@allres) {
  584:         my $symb = $resource->symb();
  585:         my @parts = @{$resource->parts()};
  586:         foreach my $part (@parts) {
  587:             if ($resource->handgrade($part) eq 'yes') {
  588:                 next;
  589:             }
  590:             if ($resource->is_survey($part)) {
  591:                 next;
  592:             }
  593:             if (exists($resourcetracker{$symb."\0".$part."\0users"})) {
  594:                 $submissioncount += $resourcetracker{$symb."\0".$part."\0users"};
  595:             }
  596:         }
  597:     }
  598:     return $submissioncount;
  599: }
  600: 
  601: sub builder_javascript {
  602:     my %lt = &Apache::lonlocal::texthash(
  603:                                           show => 'Show',
  604:                                           hide => 'Hide',
  605:                                         );
  606:     my $prereqjs = "
  607: function checkPrereqs(caller,item,prereq,binname) {
  608:     var changedPrereq = 0;
  609:     if (document.selecteditems.elements['item'+item].checked == false) {
  610:         return;
  611:     } else {
  612:         if (!document.selecteditems.elements['item'+prereq].checked) {
  613:             document.selecteditems.elements['item'+prereq].checked = true;
  614:             changedPrereq = 1;
  615:             countChecked(binname);
  616:         }
  617:     }
  618: ";
  619:     
  620:     my ($hasdep,$prereq,$hasdeptitle,$prereqtitle) = ('','','','');
  621:     foreach my $item (sort(keys(%prereqs))) {
  622:         $hasdep .= "'$item',";
  623:         $prereq .= "'$prereqs{$item}',";
  624:         my $url = &fullurl($item);
  625:         $hasdeptitle .= "'".&Apache::lonnet::metadata($url,'title')."',";
  626:         my $purl = &fullurl($prereqs{$item});
  627:         $prereqtitle .= "'".&Apache::lonnet::metadata($purl,'title')."',";
  628:     }
  629:     $hasdep =~ s/,$//;
  630:     $prereq =~ s/,$//;
  631:     $hasdeptitle =~ s/,$//;
  632:     $prereqtitle =~ s/,$//;
  633: 
  634:     $prereqjs .= <<"ENDFN";
  635: 
  636:     var hasDeps = Array($hasdep);
  637:     var preReqs = Array($prereq);
  638:     var hasDepTitles = Array($hasdeptitle);
  639:     var preReqTitles = Array($prereqtitle);
  640:     for (var i=0; i<hasDeps.length; i++) {
  641:         if (hasDeps[i] == item) {
  642:             var msg = hasDepTitles[i]+' question has a prerequisite: '+preReqTitles[i]+'.\\nThe two questions will appear together in a composite question.';
  643:             if (changedPrereq == 1) {
  644:                 msg = msg+'\\n\\nAs the prerequisite was not checked, inclusion of '+hasDepTitles[i]+' has now caused '+preReqTitles[i]+' to also be checked automatically.';
  645:             }
  646:             if (caller == 'pre') {
  647:                 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.'
  648:             }
  649:             alert(msg);
  650:             break;
  651:         }
  652:     }
  653:     return;
  654: }
  655: 
  656: ENDFN
  657: 
  658:     return <<ENDJS;
  659: function showQuestions(content,title) {
  660:     document.getElementById(content).style.display = "";
  661:     document.getElementById(title).innerHTML='<a href="javascript:hideQuestions('+"'"+content+"','"+title+"'"+');">$lt{'hide'}</a> ...';
  662:     return;
  663: }
  664: 
  665: function hideQuestions(content,title) {
  666:     document.getElementById(content).style.display = "none";
  667:     document.getElementById(title).innerHTML='<a href="javascript:showQuestions('+"'"+content+"','"+title+"'"+')">$lt{'show'}</a> ...';
  668:     return;
  669: }
  670: 
  671: function setInitialVisibility() {
  672:     if (document.getElementById('GCI_mandatory_q') == null) {
  673:         return;
  674:     }
  675:     document.getElementById('GCI_mandatory_q').style.display = "none";
  676:     document.getElementById('GCI_bin0_q').style.display = "none";
  677:     document.getElementById('GCI_bin1_q').style.display = "none";
  678:     document.getElementById('GCI_bin2_q').style.display = "none";
  679:     document.getElementById('GCI_bin3_q').style.display = "none";
  680:     document.getElementById('GCI_bin4_q').style.display = "none";
  681:     document.getElementById('GCI_bin5_q').style.display = "none";
  682:     document.getElementById('GCI_bin6_q').style.display = "none";
  683:     document.getElementById('GCI_bin7_q').style.display = "none";
  684:     document.getElementById('GCI_bin8_q').style.display = "none";
  685:     document.getElementById('GCI_bin9_q').style.display = "none";
  686:     document.getElementById('GCI_bin10_q').style.display = "none";
  687:     document.getElementById('GCI_optional_q').style.display = "none";
  688:     document.getElementById('GCI_development_q').style.display = "none";
  689: }
  690: 
  691: function countChecked(binname) {
  692:     var count = 0;
  693:     for (var i=0; i<document.selecteditems.elements.length; i++) {
  694:         if (document.selecteditems.elements[i].type == "hidden") {
  695:             if (document.selecteditems.elements[i].value == binname) {
  696:                 var itemname = document.selecteditems.elements[i].name;
  697:                 var itemnum = itemname.substr(9);
  698:                 if (document.selecteditems.elements['item'+itemnum].checked) {
  699:                     count ++;
  700:                 }
  701:             }
  702:         }
  703:     }
  704:     document.selecteditems.elements['GCI_'+binname+'_count'].value = count;
  705: }
  706: 
  707: function validTestCheck() {
  708:     var empty = '';
  709:     for (var i=0; i<11; i++) {
  710:         var binname = 'GCI_bin'+i+'_count';
  711:         var j = i+1;
  712:         if (document.selecteditems.elements[binname].value < 1) {
  713:             empty = empty +' '+j;
  714:         }
  715:     }
  716:     if (empty != "") {
  717:         alert("Current test invalid - select at least one item from the following bin(s): "+empty);
  718:         return false;
  719:     }
  720:     return true;
  721: }
  722: 
  723: function setDocsPhase() {
  724:     if (document.choices.concepttest.length) {
  725:         for (var i=0; i<document.choices.concepttest.length; i++) {
  726:             if (document.choices.concepttest[i].checked) {
  727:                 if (document.choices.concepttest[i].value == 'defchosen') {
  728:                     document.choices.phase.value = 'storemap';
  729:                     alert("Setting value for phase to "+document.choices.phase.value);
  730: 
  731:                 }
  732:             }
  733:         }
  734:     }
  735:     return;
  736: }
  737: 
  738: $prereqjs
  739: 
  740: ENDJS
  741: 
  742: }
  743: 
  744: } #end scope variables
  745: 
  746: 1;
  747: __END__
  748: 

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