Annotation of modules/gci/londocsgci.pm, revision 1.5

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.5     ! gci         5: # $Id: londocsgci.pm,v 1.4 2009/12/02 18:35:59 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;
                     47: my @categories;
                     48: my @allprobs;
                     49: my %probcat;
                     50: my %prereqs;
                     51: my @defchosen;
                     52: my @chosen;
1.5     ! gci        53: my @mandprobs;
        !            54: my @bins;
        !            55: my @optional;
1.3       gci        56: my %mandatory;
1.5     ! gci        57: my @development;
        !            58: my %developmentitems;
1.1       gci        59: 
                     60: sub setdefaults {
                     61:    $path='/res/gci/gci';
                     62:    $version='GCIv2-1-1';
                     63:    $reqnum=15;
1.5     ! gci        64:    @allprobs=('01','02','37','2004_73','03','04','05','06','07',
1.1       gci        65:               '08','10',
                     66:               '09',
                     67:               '11','12','13','14','15','16','17',
                     68:               '18','69',
                     69:               '19','20',
                     70:               '21','22','23','24','25','26','27','28','29','30',
1.5     ! gci        71:               '31','32','33','34','35','36','38',
1.1       gci        72:               '39A','39B',
                     73:               '40',
                     74:               '41','42','43','44','45','46','47','48','49','50',
                     75:               '51',
                     76:               '52','57',
                     77:               '53','54','55','56','58',
                     78:               '60',
                     79:               '61','62','63','64','65','66','67','68','70',
1.5     ! gci        80:               '71');
        !            81:     @bins = ( ['03','04','06'],
        !            82:               ['07','08','09'],
        !            83:               ['10','12','13','14','15','16','17'],
        !            84:               ['18','19','20','21','22','23','24','25'],
        !            85:               ['26','27','28','30'],
        !            86:               ['32','33','34','35','36'],
        !            87:               ['38','39A','39B','40','41','42','43','44','45','46'],
        !            88:               ['47','48','49','50','51','52','53'],
        !            89:               ['54','55','56','57','58','60','61','62'],
        !            90:               ['63','64','65'],
        !            91:               ['66','67','68','69','70','71']);
        !            92:     @optional = ('05','11','29','31');
1.1       gci        93: 
                     94:    @categories=('M1','M2','M3','M4',
                     95:                 'A','B','C','D','E','F','G','H','I','J','K');
1.5     ! gci        96:    %probcat =('01' => 'M1' ,'02' => 'M2' ,'37' => 'M3' ,'2004_73' => 'M4' ,
        !            97:               '03' => 'A' ,'04' => 'A','05' => ''  ,'06' => 'A' ,'07' => 'B' ,
        !            98:               '08' => 'B' ,'09' => 'B' ,'10' => 'C' ,'11' => ''  ,'12' => 'C' ,
        !            99:               '13' => 'C' ,'14' => 'C' ,'15' => 'C' ,'16' => 'C' ,'17' => 'C' ,'18' => 'D' ,'19' => 'D' ,'20' => 'D' ,
1.1       gci       100:               '21' => 'D' ,'22' => 'D' ,'23' => 'D' ,'24' => 'D' ,'25' => 'D' ,'26' => 'E' ,'27' => 'E' ,'28' => 'E' ,'29' => ''  ,'30' => 'E' ,
1.5     ! gci       101:               '31' => ''  ,'32' => 'F' ,'33' => 'F' ,'34' => 'F' ,'35' => 'F' ,'36' => 'F' ,'38' => 'G' ,
1.1       gci       102:               '39A'=> 'G' ,'39B'=> 'G' ,
                    103:               '40' => 'G' ,
                    104:               '41' => 'G' ,'42' => 'G' ,'43' => 'G' ,'44' => 'G' ,'45' => 'G' ,'46' => 'G' ,'47' => 'H' ,'48' => 'H' ,'49' => 'H' ,'50' => 'H' ,
                    105:               '51' => 'H' ,'52' => 'H' ,'53' => 'H' ,'54' => 'I' ,'55' => 'I' ,'56' => 'I' ,'57' => 'I' ,'58' => 'I' ,
                    106:               '60' => 'I' ,
                    107:               '61' => 'I' ,'62' => 'I' ,'63' => 'J' ,'64' => 'J' ,'65' => 'J' ,'66' => 'K' ,'67' => 'K' ,'68' => 'K' ,'69' => 'K' ,'70' => 'K' ,
1.5     ! gci       108:               '71' => 'K');
        !           109:    %mandatory=('01' => 1 ,'02' => 1,'37' => 1, '2004_73' => 1);
        !           110:    @mandprobs = ('01','02','37','2004_73');
1.1       gci       111:    %prereqs=('10' => '08', '57' => '52', '69' => '18');
                    112:    @defchosen=('01','02','03','07','12','18','26','32','37','38','47','54','63','66','2004_73');
1.5     ! gci       113:    @development = ('100','101','102');
        !           114:    %developmentitems = ('100' => 1, '101' => '1', '102' => '1');
1.1       gci       115: }
                    116: 
                    117: sub checkvalid {
                    118:    my %covered=();
                    119:    my %chosenproblems=();
                    120:    my @errors=();
                    121:    my $num=$#chosen+1;
                    122:    if ($num<$reqnum) {
                    123:       push(@errors,&mt('Test requires at least [_1] items, but has only [_2].',$reqnum,$num)); 
                    124:    }
                    125:    foreach my $item (@chosen) {
                    126:       $chosenproblems{$item}=1;
                    127:       $covered{$probcat{$item}}=1;
                    128:    }
                    129:    foreach my $cat (@categories) {
                    130:       unless ($covered{$cat}) {
1.3       gci       131:          push(@errors,&mt('Bin [_1] not covered.',$cat));
1.1       gci       132:       }
                    133:    }
                    134:    foreach my $item (@chosen) {
                    135:        if ($prereqs{$item}) {
                    136:           unless ($chosenproblems{$prereqs{$item}}) {
                    137:              push(@errors,&mt('Problem [_1] requires problem [_2].',$item,$prereqs{$item}));
                    138:           }
                    139:        }
                    140:    }
                    141:    return @errors;
                    142: }
                    143: 
                    144: sub fullurl {
                    145:    my ($item)=@_;
                    146:    unless ($item=~/\_/) { $item='_'.$item; }
                    147:    return $path.'/'.$version.'/GCI'.$item.'.problem';
                    148: }
                    149: 
1.3       gci       150: sub validcheck {
1.1       gci       151:    my ($r)=@_;
                    152:    my @errors=&checkvalid();
                    153:    if ($#errors>-1) {
                    154:       $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>');
                    155:       foreach my $message (@errors) {
                    156:          $r->print('<li>'.$message.'</li>');
                    157:       }
                    158:       $r->print('</ul></p>');
1.3       gci       159:       return 0;
                    160:    }
                    161:    return 1;
                    162: }
                    163: 
                    164: sub listresources {
1.5     ! gci       165:    my ($r,$context,$cdom,$cnum)=@_;
        !           166:    my $numchosen = scalar(@chosen);
        !           167:    unless ($numchosen > 0) {
        !           168:       $r->print('<h3>'.&mt('Create a Concept Test').'</h3>'.
        !           169:                 '<p>'.&mt('Choose how the test should be built:').'<br />'.
        !           170:                 '<form name="choices" method="post" action="/adm/coursedocs" onsubmit="javascript:setDocsPhase();">'.
        !           171:                 '<label><input type="radio" name="concepttest" value="defchosen" />'.&mt('Have a valid test built automatically by the WebCenter.').'</label><br />'.
        !           172:                 '<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 />'.
        !           173:                 '<input type="hidden" name="phase" value="" />'.
        !           174:                 '<input type="submit" name="choosetest" value="'.&mt('Next').'"></p>');
        !           175:        return;
        !           176:    }
        !           177:    if ((!&validcheck($r)) || ($env{'form.concepttest'} eq 'editmyown')) {
        !           178:       &editor($r,$context,$cdom,$cnum);
1.3       gci       179:    } else {
1.5     ! gci       180:       my $numsub = &get_submissions_count($cdom,$cnum);
        !           181:       unless ($env{'form.phase'} eq 'storemap') {
        !           182:           $r->print('<p>'.&mt('This course contains a valid concept test which includes [quant,_1,question].',$numchosen).'&nbsp;<a href="/adm/navmaps" target="_coursecontents">'.&mt('Display Contents').'</a><br />');
        !           183:       }
        !           184:       if ($numsub > 0) {
        !           185:           $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>');
        !           186:       } else {
        !           187:           $r->print('<fieldset><legend>'.&mt('Modify Test').'</legend>'.
        !           188:                     &mt('Currently no student submissions have been recorded, so you may modify the contents of the Concept Test.').
        !           189:                     '<br /><form name="changetest" method="post" action="/adm/coursedocs">'.
        !           190:                     '<input type="hidden" name="concepttest" value="editmyown" />'.
        !           191:                     '<input type="submit" name="modifytest" value="'.&mt('Edit Concept Test').'" /></form></fieldset></p>');
1.3       gci       192:       }
1.5     ! gci       193:       my ($crsparms,$ineffect,$parmlev) = &current_parms($cdom,$cnum);
        !           194:       my $formname = 'datesform';
        !           195:       my $datebutton = &mt('Save');
        !           196:       my $startform =
        !           197:           &Apache::lonhtmlcommon::date_setter($formname,'opendate',
        !           198:                                               $crsparms->{'opendate'});
        !           199:       my $endform =
        !           200:           &Apache::lonhtmlcommon::date_setter($formname,'duedate',
        !           201:                                                            $crsparms->{'duedate'});
        !           202:       $r->print('<p><fieldset><legend>'.&mt('Test Availability').'</legend>'.
        !           203:                 &mt('Open and close dates for test items for the concept test are currently set as follows:').
        !           204:                 '<br />'.
        !           205:                 '<form name="'.$formname.'" method="post" '.
        !           206:                 'action="/adm/coursedocs">'.
        !           207:                 &Apache::lonhtmlcommon::start_pick_box().
        !           208:                 &Apache::lonhtmlcommon::row_title(&mt('Open date')).
        !           209:                 $startform.
        !           210:                 &Apache::lonhtmlcommon::row_closure().
        !           211:                 &Apache::lonhtmlcommon::row_title(&mt('Close date')).
        !           212:                 $endform.
        !           213:                  &Apache::lonhtmlcommon::end_pick_box().'<br />'. 
        !           214:                 '<input type="hidden" name="phase" value="storeparms" />'.
        !           215:                 '<input type="submit" value="'.$datebutton.'" />'.
        !           216:                 '</form></fieldset></p>');
1.1       gci       217:    }
1.3       gci       218: }
                    219: 
                    220: sub editor {
1.5     ! gci       221:     my ($r,$context,$cdom,$cnum)=@_;
        !           222:     my %chosenitems=();
        !           223:     my $havedev = 0;
        !           224:     foreach my $item (@chosen) {
        !           225:         $chosenitems{$item}=1;
        !           226:     }
        !           227:     my @devitems = &get_development_questions($cdom,$cnum);
        !           228:     &Apache::lonnet::appenv({'request.gcicontext' => 'buildtest'});
        !           229:     $r->print('<form name="selecteditems" method="post" action="/adm/coursedocs"
        !           230:               onsubmit="return validTestCheck()">');
        !           231:     $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 />');
        !           232:     $r->print('<ul>'.
        !           233:               '<li>'.&mt('Tests will contain a minimum of [_1] questions from the GCI 2 Inventory.',"<b>$reqnum</b>").'</li>'.
        !           234:               '<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>'.
        !           235:               '<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>'.
        !           236:               '</ul>');
        !           237:     my $mandleg = &mt('Mandatory Questions');
        !           238:     $r->print(&display_questions(\@mandprobs,'mandatory',$mandleg,\%chosenitems));
        !           239:     for (my $i=0; $i<@bins; $i++) {
        !           240:         my $num = $i+1;
        !           241:         my $legend = &mt('Bin [_1]',$num);
        !           242:         my $catname = 'bin'.$i;
        !           243:         $r->print(&display_questions($bins[$i],$catname,$legend,\%chosenitems));
        !           244:     }
        !           245:     my $optleg = &mt('Optional Questions');
        !           246:     $r->print(&display_questions(\@optional,'optional',$optleg,\%chosenitems));
        !           247:     my $devleg = &mt('Development Questions');
        !           248:     $r->print(&display_questions(\@devitems,'development',$devleg,\%chosenitems));
        !           249:     $r->print('<input type="hidden" name="phase" value="storemap" />'.
        !           250:               '<input type="hidden" name="context" value="'.$context.'" />'.
        !           251:               '<input type="submit" value="'.&mt('Store Problem Selection').'" />'.
        !           252:               '</form>');
        !           253:     &Apache::lonnet::delenv('request.gcicontext');
        !           254: }
        !           255: 
        !           256: sub display_questions {
        !           257:     my ($questions,$catname,$catlegend,$chosenitems) = @_;
        !           258:     return unless((ref($questions) eq 'ARRAY') && (ref($chosenitems) eq 'HASH'));
        !           259:     my $total = 0;
        !           260:     foreach my $item (@{$questions}) {
        !           261:         if ($chosenitems->{$item}) {
        !           262:             $total ++;
        !           263:         }
        !           264:     }
        !           265:     my $fieldid = 'GCI_'.$catname.'_q';
        !           266:     my $titleid = 'GCI_'.$catname.'_t';
        !           267:     my $countid = 'GCI_'.$catname.'_count';
        !           268:     my $output = '<fieldset>';
        !           269:     my %fixed = (
        !           270:         mandatory   => 4,
        !           271:         development => 2, 
        !           272:     );
        !           273:     if (($catname eq 'mandatory') || ($catname eq 'development')) {
        !           274:         $output .= '<legend>'.&mt('[_1] [_2] selected automatically',$catlegend,
        !           275:                    '<input type="text" name="'.$countid.'" size="1" '.
        !           276:                    'value="'.$fixed{$catname}.'" readonly="readonly" />').'</legend>';
        !           277:     } else {
        !           278:         $output .= '<legend>'.&mt('[_1]: currently [_2] selected',$catlegend,
        !           279:                    '<input type="text" name="'.$countid.'" size="1" value="'.
        !           280:                    $total.'" readonly="readonly" />').'</legend>';
        !           281:     }
        !           282:     $output .= '<span id="'.$titleid.'">'.
        !           283:               '<a href="javascript:showQuestions('."'$fieldid','$titleid'".')">'.
        !           284:               &mt('Show').'</a> ...</span><br />'.
        !           285:               '<div id="'.$fieldid.'">'.
        !           286:               &Apache::loncommon::start_data_table().
        !           287:               &Apache::loncommon::start_data_table_header_row();
        !           288:     unless (($catname eq 'development') || ($catname eq 'mandatory')) {
        !           289:         $output .= '<th>'.&mt('Select').'</th>';
        !           290:     }
        !           291:     $output .= '<th>'.&mt('Problem').
        !           292:                '</th><th>'.&mt('Preview').'</th>'.
        !           293:                &Apache::loncommon::end_data_table_header_row();
        !           294:     foreach my $item (@{$questions}) {
        !           295:         my $url = &fullurl($item);
        !           296:         my $title = &Apache::lonnet::metadata($url,'title');
        !           297:         $output .= &Apache::loncommon::start_data_table_row().'<td>';
        !           298:         if (($catname eq 'mandatory') || ($catname eq 'development')) {
        !           299:             $output .= '<input type="hidden" name="item'.$item.'" value="checked" />';
        !           300:         } else {
        !           301:             $output .= '<input type="checkbox" name="item'.$item.'"';
        !           302:             if ($chosenitems->{$item}) { $output .= ' checked="checked"'; }
        !           303:             $output .= 'onclick="javascript:countChecked('."'$catname'".');" />'.
        !           304:                        '<input type="hidden" name="container'.$item.'" value="'.
        !           305:                        $catname.'"></td><td>';
        !           306:         }
        !           307:         $output .= '<b>'.$title.'</b></td>';
        !           308:         my $content=&Apache::lonindexer::showpreview($url);
        !           309:         $output .= '<td> '.($content eq '' ? '&nbsp;':$content).' </td>'."\n".
        !           310:                    &Apache::loncommon::end_data_table_row();
        !           311:     }
        !           312:     $output .= &Apache::loncommon::end_data_table().
        !           313:                '</div></fieldset><br />';
        !           314:     return $output;
        !           315: }
        !           316: 
        !           317: sub get_development_questions {
        !           318:     my ($cdom,$cnum) = @_;
        !           319:     my $cid = $cdom.'_'.$cnum;
        !           320:     my %courseenv = &Apache::lonnet::userenvironment($cdom,$cnum,
        !           321:                         ('internal.courseowner'));
        !           322:     my $seed = $courseenv{'internal.courseowner'};
        !           323:     my $rndseed=&Apache::lonnet::rndseed($seed,$cid,$cdom,$cnum);
        !           324:     &Apache::lonnet::setup_random_from_rndseed($rndseed);
        !           325:     my @devitems = &Math::Random::random_permutation(@development);
        !           326:     return ($devitems[0],$devitems[1]); 
1.1       gci       327: }
                    328: 
                    329: sub evaluate {
                    330:    if ($env{'form.phase'} eq 'storemap') {
                    331:       @chosen=();
                    332:       foreach my $item (@allprobs) {
                    333:          if ($env{'form.item'.$item}) {
                    334:             push(@chosen,$item);
                    335:          }
                    336:       }
                    337:    }
                    338: }
                    339: 
                    340: sub mapread_gci {
                    341:     my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
                    342:     my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
                    343:     return
1.5     ! gci       344:       &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/default_1261144274.sequence');
1.1       gci       345: }
                    346: 
                    347: sub storemap_gci {
1.5     ! gci       348:     my ($coursedom,$coursenum) = @_;
        !           349:     if (($coursedom !~ /^$match_domain$/) || ($coursenum !~ /^$match_courseid$/)) { 
        !           350:         $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
        !           351:         $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
        !           352:     }
        !           353:     return ('unauthorized',2) if (($coursedom eq '') || ($coursedom eq '') ||
        !           354:                    (!&Apache::lonnet::allowed('mdc',$coursedom.'_'.$coursenum)));
1.1       gci       355:     my ($outtext,$errtext)=
1.5     ! gci       356:         &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/default_1261144274.sequence',1);
1.1       gci       357:     if ($errtext) { return ($errtext,2); }
                    358:     return ($errtext,0);
                    359: }
                    360: 
                    361: sub chosen_to_map {
                    362:    my %chosenproblems=();
                    363:    foreach my $item (@chosen) {
                    364:       $chosenproblems{$item}=1;
                    365:    }
                    366:    @LONCAPA::map::order=();
                    367:    @LONCAPA::map::resources=();
1.5     ! gci       368:    my $counter = 0;
1.1       gci       369:    for (my $idx=0;$idx<=$#allprobs;$idx++) {
                    370:        my $residx=$idx+1;
                    371:        if ($chosenproblems{$allprobs[$idx]}) {
                    372:           push(@LONCAPA::map::order,$residx);
1.5     ! gci       373:           $counter ++;
1.1       gci       374:           my $url  = &LONCAPA::map::qtunescape(&fullurl($allprobs[$idx]));
1.5     ! gci       375: 	  my $name = &LONCAPA::map::qtunescape('Problem '.$counter);
1.1       gci       376: 	  $LONCAPA::map::resources[$residx]=join(':', ($name, $url, 'false', 'normal', 'res'));
                    377:        }
                    378:     }
                    379: }
                    380: 
                    381: sub map_to_chosen {
                    382:     @chosen=();
                    383:     foreach my $idx (@LONCAPA::map::order) {
1.5     ! gci       384:        my ($title,$url)=split(':',$LONCAPA::map::resources[$LONCAPA::map::order[$idx]]);
        !           385:        unless ($url eq '') {
        !           386:            push(@chosen,$allprobs[$idx-1]);
        !           387:        }
        !           388:     }
        !           389:     if (($env{'form.concepttest'} eq 'defchosen') || 
        !           390:         ((@chosen == 0) && ($env{'form.concepttest'} eq 'editmyown'))) {
        !           391:         @chosen = @defchosen;
1.1       gci       392:     }
                    393: }
                    394: 
                    395: sub store {
1.5     ! gci       396:    my ($caller,$cdom,$cnum)=@_;
        !           397:    if ($env{'form.concepttest'} eq 'defchosen') {
        !           398:        @chosen = @defchosen;
        !           399:    }
1.1       gci       400:    my @errors=&checkvalid();
1.5     ! gci       401:    if (@errors > 0) {
        !           402:        if (($caller eq 'requestcrs') && ($env{'form.concepttest'} eq 'defchosen')) {
        !           403:            return 'Invalid concept test.';
        !           404:        } else {
        !           405:            return;
        !           406:        }
        !           407:    }
1.1       gci       408:    &chosen_to_map();
1.5     ! gci       409:    my ($err,$errnum) = &storemap_gci($cdom,$cnum);
        !           410:    if ($caller eq 'requestcrs') {
        !           411:        if ($errnum == 0) {
        !           412:            return; 
        !           413:        } else {
        !           414:            return 'An error occurred when storing the concept test';
        !           415:        }
        !           416:    }
1.3       gci       417:    if ($env{'form.phase'} eq 'storemap') {
1.5     ! gci       418:       if ($errnum == 0) {
        !           419:          &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
        !           420:          return '<p>'.&mt('You have successfully assembled a valid test.').'</p>'.
        !           421:                 '<p><a href="/adm/navmaps">'.&mt('Display Table of Contents').
        !           422:                 '</a>'.('&nbsp;' x4).'<a href="/adm/menu">'.&mt('Return to Main Menu').'</a></p>';
        !           423:       } else {
        !           424:           return '<div class="LC_error">'.&mt('An error occurred when storing your concept test: [_1].',$err).'</div>';
1.3       gci       425:       }
1.1       gci       426:    }
1.5     ! gci       427:    return;
1.1       gci       428: }
                    429: 
                    430: sub load {
                    431:    &mapread_gci();
                    432:    &map_to_chosen();
1.5     ! gci       433:    if (@chosen > 0) {
        !           434:        my @errors=&checkvalid();
        !           435:        if ($#errors>1) { @chosen=@defchosen; }
        !           436:    }
        !           437: }
        !           438: 
        !           439: sub current_parms {
        !           440:     my ($cdom,$cnum) = @_;
        !           441:     my $courseopt=&Apache::lonnet::get_courseresdata($cnum,$cdom);
        !           442:     my (%crsparms,%ineffect,%parmlev);
        !           443:     foreach my $item ('opendate','duedate') {
        !           444:         $crsparms{$item} = $courseopt->{$env{'request.course.id'}.'.0.'.$item};
        !           445:         my ($result,@outpar) =
        !           446:             &Apache::lonparmset::parmval('0.'.$item,'0.0',undef,undef,
        !           447:                                          $cdom,undef,undef,$courseopt);
        !           448:         if ($result) {
        !           449:             $ineffect{$item} = $outpar[$result];
        !           450:             $parmlev{$item} = $result;
        !           451:         }
        !           452:     }
        !           453:     return (\%crsparms,\%ineffect,\%parmlev);
        !           454: }
        !           455: 
        !           456: sub store_dates_parms {
        !           457:     my ($cdom,$cnum) = @_;
        !           458:     my $topsymb = '___0___uploaded/'.$cdom.'/'.$cnum.'/default.sequence';
        !           459:     my ($opendate,$duedate) = 
        !           460:         &Apache::lonuserutils::get_dates_from_form('opendate','duedate');
        !           461:     my %dates = (
        !           462:                   opendate => {
        !           463:                                value => $opendate,
        !           464:                                type  => 'date_start',
        !           465:                               },
        !           466:                   duedate => {
        !           467:                                value => $duedate,
        !           468:                                type  => 'date_end',
        !           469:                              },
        !           470:                 );
        !           471:     my %parmresult;
        !           472:     foreach my $date (keys(%dates)) {
        !           473:         $parmresult{$date} =
        !           474:             &Apache::lonparmset::storeparm_by_symb($topsymb,
        !           475:                                    '0_'.$date,14,$dates{$date}{'value'},
        !           476:                                    $dates{$date}{'type'},undef,$cdom);
        !           477:     }
        !           478:     my $output = &mt('Open and Close dates set for test items').'<ul>'.
        !           479:                  '<li>'.&mt('Concept Test Questions open:').' '.
        !           480:                         &Apache::lonlocal::locallocaltime($opendate).'</li>'.
        !           481:                  '<li>'.&mt('Concept Test Questions close:').' '.
        !           482:                         &Apache::lonlocal::locallocaltime($duedate).'</li>'.
        !           483:                  '</ul>';
        !           484:     return $output;
        !           485: }
        !           486: 
        !           487: sub get_submissions_count {
        !           488:     my ($cdom,$cnum) = @_;
        !           489:     my $navmap = Apache::lonnavmaps::navmap->new();
        !           490:     if (!defined($navmap)) {
        !           491:         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>';
        !           492:         return $itemserror;
        !           493:     }
        !           494:     my @allres=$navmap->retrieveResources('/uploaded/'.$cdom.'/'.$cnum.'/default_1261144274.sequence',sub {if ($_[0]->is_problem) { $_[0]->parts();} return 1;});
        !           495:     my (%resourcetracker,$submissioncount);
        !           496:     my %resourcetracker =  &Apache::lonnet::dump('nohist_resourcetracker',
        !           497:                                                  $cdom,$cnum);
        !           498:     foreach my $resource (@allres) {
        !           499:         my $symb = $resource->symb();
        !           500:         my @parts = @{$resource->parts()};
        !           501:         foreach my $part (@parts) {
        !           502:             if ($resource->handgrade($part) eq 'yes') {
        !           503:                 next;
        !           504:             }
        !           505:             if ($resource->is_survey($part)) {
        !           506:                 next;
        !           507:             }
        !           508:             if (exists($resourcetracker{$symb."\0".$part."\0users"})) {
        !           509:                 $submissioncount += $resourcetracker{$symb."\0".$part."\0users"};
        !           510:             }
        !           511:         }
        !           512:     }
        !           513:     return $submissioncount;
        !           514: }
        !           515: 
        !           516: sub builder_javascript {
        !           517:     my %lt = &Apache::lonlocal::texthash(
        !           518:                                           show => 'Show',
        !           519:                                           hide => 'Hide',
        !           520:                                         );
        !           521:     return <<ENDJS;
        !           522: function showQuestions(content,title) {
        !           523:     document.getElementById(content).style.display = "";
        !           524:     document.getElementById(title).innerHTML='<a href="javascript:hideQuestions('+"'"+content+"','"+title+"'"+');">$lt{'hide'}</a> ...';
        !           525:     return;
        !           526: }
        !           527: 
        !           528: function hideQuestions(content,title) {
        !           529:     document.getElementById(content).style.display = "none";
        !           530:     document.getElementById(title).innerHTML='<a href="javascript:showQuestions('+"'"+content+"','"+title+"'"+')">$lt{'show'}</a> ...';
        !           531:     return;
        !           532: }
        !           533: 
        !           534: function setInitialVisibility() {
        !           535:     if (document.getElementById('GCI_mandatory_q') == null) {
        !           536:         return;
        !           537:     }
        !           538:     document.getElementById('GCI_mandatory_q').style.display = "none";
        !           539:     document.getElementById('GCI_bin0_q').style.display = "none";
        !           540:     document.getElementById('GCI_bin1_q').style.display = "none";
        !           541:     document.getElementById('GCI_bin2_q').style.display = "none";
        !           542:     document.getElementById('GCI_bin3_q').style.display = "none";
        !           543:     document.getElementById('GCI_bin4_q').style.display = "none";
        !           544:     document.getElementById('GCI_bin5_q').style.display = "none";
        !           545:     document.getElementById('GCI_bin6_q').style.display = "none";
        !           546:     document.getElementById('GCI_bin7_q').style.display = "none";
        !           547:     document.getElementById('GCI_bin8_q').style.display = "none";
        !           548:     document.getElementById('GCI_bin9_q').style.display = "none";
        !           549:     document.getElementById('GCI_bin10_q').style.display = "none";
        !           550:     document.getElementById('GCI_optional_q').style.display = "none";
        !           551:     document.getElementById('GCI_development_q').style.display = "none";
        !           552: }
        !           553: 
        !           554: function countChecked(binname) {
        !           555:     var count = 0;
        !           556:     for (var i=0; i<document.selecteditems.elements.length; i++) {
        !           557:         if (document.selecteditems.elements[i].type == "hidden") {
        !           558:             if (document.selecteditems.elements[i].value == binname) {
        !           559:                 var itemname = document.selecteditems.elements[i].name;
        !           560:                 var itemnum = itemname.substr(9);
        !           561:                 if (document.selecteditems.elements['item'+itemnum].checked) {
        !           562:                     count ++;
        !           563:                 }
        !           564:             }
        !           565:         }
        !           566:     }
        !           567:     document.selecteditems.elements['GCI_'+binname+'_count'].value = count;
        !           568: }
        !           569: 
        !           570: function validTestCheck() {
        !           571:     var empty = '';
        !           572:     for (var i=0; i<11; i++) {
        !           573:         var binname = 'GCI_bin'+i+'_count';
        !           574:         var j = i+1;
        !           575:         if (document.selecteditems.elements[binname].value < 1) {
        !           576:             empty = empty +' '+j;
        !           577:         }
        !           578:     }
        !           579:     if (empty != "") {
        !           580:         alert("Current test invalid - select at least one item from the following bin(s): "+empty);
        !           581:         return false;
        !           582:     }
        !           583:     return true;
        !           584: }
        !           585: 
        !           586: function setDocsPhase() {
        !           587:     if (document.choices.concepttest.length) {
        !           588:         for (var i=0; i<document.choices.concepttest.length; i++) {
        !           589:             if (document.choices.concepttest[i].checked) {
        !           590:                 if (document.choices.concepttest[i].value == 'defchosen') {
        !           591:                     document.choices.phase.value = 'storemap';
        !           592:                     alert("Setting value for phase to "+document.choices.phase.value);
        !           593: 
        !           594:                 }
        !           595:             }
        !           596:         }
        !           597:     }
        !           598:     return;
        !           599: }
        !           600: 
        !           601: ENDJS
        !           602: 
1.1       gci       603: }
                    604: 
                    605: } #end scope variables
                    606: 
                    607: 1;
                    608: __END__
                    609: 

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