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

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.4     ! gci         5: # $Id: londocsgci.pm,v 1.3 2009/11/27 23:48:25 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.3       gci        53: my %mandatory;
1.1       gci        54: 
                     55: sub setdefaults {
                     56:    $path='/res/gci/gci';
                     57:    $version='GCIv2-1-1';
                     58:    $reqnum=15;
                     59:    @allprobs=('01','02','03','04','05','06','07',
                     60:               '08','10',
                     61:               '09',
                     62:               '11','12','13','14','15','16','17',
                     63:               '18','69',
                     64:               '19','20',
                     65:               '21','22','23','24','25','26','27','28','29','30',
                     66:               '31','32','33','34','35','36','37','38',
                     67:               '39A','39B',
                     68:               '40',
                     69:               '41','42','43','44','45','46','47','48','49','50',
                     70:               '51',
                     71:               '52','57',
                     72:               '53','54','55','56','58',
                     73:               '60',
                     74:               '61','62','63','64','65','66','67','68','70',
                     75:               '71',
                     76:               '2004_73');
                     77: 
                     78:    @categories=('M1','M2','M3','M4',
                     79:                 'A','B','C','D','E','F','G','H','I','J','K');
                     80:    %probcat =('01' => 'M1','02' => 'M2','03' => 'A' ,'04' => 'A' ,'05' => ''  ,'06' => 'A' ,'07' => 'B' ,'08' => 'B' ,'09' => 'B' ,'10' => 'C' ,
                     81:               '11' => ''  ,'12' => 'C' ,'13' => 'C' ,'14' => 'C' ,'15' => 'C' ,'16' => 'C' ,'17' => 'C' ,'18' => 'D' ,'19' => 'D' ,'20' => 'D' ,
                     82:               '21' => 'D' ,'22' => 'D' ,'23' => 'D' ,'24' => 'D' ,'25' => 'D' ,'26' => 'E' ,'27' => 'E' ,'28' => 'E' ,'29' => ''  ,'30' => 'E' ,
                     83:               '31' => ''  ,'32' => 'F' ,'33' => 'F' ,'34' => 'F' ,'35' => 'F' ,'36' => 'F' ,'37' => 'M3','38' => 'G' ,
                     84:               '39A'=> 'G' ,'39B'=> 'G' ,
                     85:               '40' => 'G' ,
                     86:               '41' => 'G' ,'42' => 'G' ,'43' => 'G' ,'44' => 'G' ,'45' => 'G' ,'46' => 'G' ,'47' => 'H' ,'48' => 'H' ,'49' => 'H' ,'50' => 'H' ,
                     87:               '51' => 'H' ,'52' => 'H' ,'53' => 'H' ,'54' => 'I' ,'55' => 'I' ,'56' => 'I' ,'57' => 'I' ,'58' => 'I' ,
                     88:               '60' => 'I' ,
                     89:               '61' => 'I' ,'62' => 'I' ,'63' => 'J' ,'64' => 'J' ,'65' => 'J' ,'66' => 'K' ,'67' => 'K' ,'68' => 'K' ,'69' => 'K' ,'70' => 'K' ,
                     90:               '71' => 'K' ,
                     91:               '2004_73' => 'M4');
1.3       gci        92:    %mandatory=('01' => 1 ,'02' => 1,'37' => 1,'2004_73' => 1);
1.1       gci        93:    %prereqs=('10' => '08', '57' => '52', '69' => '18');
                     94:    @defchosen=('01','02','03','07','12','18','26','32','37','38','47','54','63','66','2004_73');
                     95: }
                     96: 
                     97: sub checkvalid {
                     98:    my %covered=();
                     99:    my %chosenproblems=();
                    100:    my @errors=();
                    101:    my $num=$#chosen+1;
                    102:    if ($num<$reqnum) {
                    103:       push(@errors,&mt('Test requires at least [_1] items, but has only [_2].',$reqnum,$num)); 
                    104:    }
                    105:    foreach my $item (@chosen) {
                    106:       $chosenproblems{$item}=1;
                    107:       $covered{$probcat{$item}}=1;
                    108:    }
                    109:    foreach my $cat (@categories) {
                    110:       unless ($covered{$cat}) {
1.3       gci       111:          push(@errors,&mt('Bin [_1] not covered.',$cat));
1.1       gci       112:       }
                    113:    }
                    114:    foreach my $item (@chosen) {
                    115:        if ($prereqs{$item}) {
                    116:           unless ($chosenproblems{$prereqs{$item}}) {
                    117:              push(@errors,&mt('Problem [_1] requires problem [_2].',$item,$prereqs{$item}));
                    118:           }
                    119:        }
                    120:    }
                    121:    return @errors;
                    122: }
                    123: 
                    124: sub fullurl {
                    125:    my ($item)=@_;
                    126:    unless ($item=~/\_/) { $item='_'.$item; }
                    127:    return $path.'/'.$version.'/GCI'.$item.'.problem';
                    128: }
                    129: 
1.3       gci       130: sub validcheck {
1.1       gci       131:    my ($r)=@_;
                    132:    my @errors=&checkvalid();
                    133:    if ($#errors>-1) {
                    134:       $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>');
                    135:       foreach my $message (@errors) {
                    136:          $r->print('<li>'.$message.'</li>');
                    137:       }
                    138:       $r->print('</ul></p>');
1.3       gci       139:       return 0;
                    140:    }
                    141:    return 1;
                    142: }
                    143: 
                    144: sub listresources {
                    145:    my ($r)=@_;
                    146:    if ((!&validcheck($r)) || ($env{'form.editmyown'})) {
                    147:       &editor($r);
                    148:    } else {
                    149:       $r->print('<p><form name="choices" method="post">');
                    150:       $r->print('<input type="submit" name="editmyown" value="'.&mt('Create Your Own Test').'" />');
                    151:       $r->print('</form></p><p><form name="defaulting" method="post">');
                    152:       $r->print('<input type="hidden" name="phase" value="storemap" />');
                    153:       foreach my $item (@defchosen) {
                    154:          $r->print('<input type="hidden" name="item'.$item.'" value="checked"');
                    155:       }
                    156:       $r->print('<input type="submit" name="defchosen" value="'.&mt('Let WebCenter Create a Test for You').'" />');
                    157:       $r->print('</form><p>');
1.1       gci       158:    }
1.3       gci       159: }
                    160: 
                    161: sub editor {
                    162:    my ($r)=@_;
1.1       gci       163:    my %chosen=();
                    164:    foreach my $item (@chosen) {
                    165:       $chosen{$item}=1;
                    166:    }
1.4     ! gci       167:    &Apache::lonnet::appenv({'request.gcicontext' => 'buildtest'});
1.2       gci       168:    $r->print('<form name="selecteditems" method="post" action="/adm/coursedocs">');
1.3       gci       169:    $r->print('<p>'.&mt('You may select test items from the list below and then press "Store Problem Selection" at the bottom of the screen.').'</p>');
                    170:    $r->print('<p>'.&mt('Tests should have at least one item from each bin and [_1] items total.',$reqnum).'</p>'); 
1.1       gci       171:    $r->print(&Apache::loncommon::start_data_table().
                    172:              &Apache::loncommon::start_data_table_header_row().
1.3       gci       173:              '<th>'.&mt('Select').'</th><th>'.&mt('Problem').'</th><th>'.&mt('Bin').'</th><th>'.&mt('Preview').'</th>'.
1.1       gci       174:              &Apache::loncommon::end_data_table_header_row());
                    175:    foreach my $item (@allprobs) {
                    176:       $r->print(&Apache::loncommon::start_data_table_row());
                    177:       $r->print('<td><font size="+3">');
1.3       gci       178:       if ($mandatory{$item}) {
                    179:          $r->print('<input type="hidden" name="item'.$item.'" value="checked"');
                    180:       } else {
                    181:          $r->print('<input type="checkbox" name="item'.$item.'"');
                    182:          if ($chosen{$item}) { $r->print(' checked="checked"'); }
                    183:       }
1.1       gci       184:       $r->print(' /></font></td>');
                    185:       $r->print('<td><font size="+3">'.$item.'</font></td><td><font size="+3">'.$probcat{$item}.'</font></td>');
                    186:       my $output=&Apache::lonindexer::showpreview(&fullurl($item));
                    187:       $r->print('<td> '.($output eq '' ? '&nbsp;':$output)." </td>\n");
                    188: 
                    189:       $r->print( &Apache::loncommon::end_data_table_row());
                    190:    }
                    191:    $r->print(&Apache::loncommon::end_data_table());
                    192:    $r->print('<input type="hidden" name="phase" value="storemap" />');
                    193:    $r->print('<input type="submit" value="'.&mt('Store Problem Selection').'" /></form>');
1.4     ! gci       194:    &Apache::lonnet::delenv('request.gcicontext');
1.1       gci       195: }
                    196: 
                    197: sub evaluate {
                    198:    if ($env{'form.phase'} eq 'storemap') {
                    199:       @chosen=();
                    200:       foreach my $item (@allprobs) {
                    201:          if ($env{'form.item'.$item}) {
                    202:             push(@chosen,$item);
                    203:          }
                    204:       }
                    205:    }
                    206: }
                    207: 
                    208: sub mapread_gci {
                    209:     my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
                    210:     my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
                    211:     return
                    212:       &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/default.sequence');
                    213: }
                    214: 
                    215: sub storemap_gci {
                    216:     my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
                    217:     my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
                    218:     my ($outtext,$errtext)=
                    219:       &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/default.sequence',1);
                    220:     if ($errtext) { return ($errtext,2); }
                    221:     return ($errtext,0);
                    222: }
                    223: 
                    224: sub chosen_to_map {
                    225:    my %chosenproblems=();
                    226:    foreach my $item (@chosen) {
                    227:       $chosenproblems{$item}=1;
                    228:    }
                    229:    @LONCAPA::map::order=();
                    230:    @LONCAPA::map::resources=();
                    231:    for (my $idx=0;$idx<=$#allprobs;$idx++) {
                    232:        my $residx=$idx+1;
                    233:        if ($chosenproblems{$allprobs[$idx]}) {
                    234:           push(@LONCAPA::map::order,$residx);
                    235:           my $url  = &LONCAPA::map::qtunescape(&fullurl($allprobs[$idx]));
                    236: 	  my $name = &LONCAPA::map::qtunescape('Problem '.$allprobs[$idx]);
                    237: 	  $LONCAPA::map::resources[$residx]=join(':', ($name, $url, 'false', 'normal', 'res'));
                    238:        }
                    239:     }
                    240: }
                    241: 
                    242: sub map_to_chosen {
                    243:     @chosen=();
                    244:     foreach my $idx (@LONCAPA::map::order) {
                    245:        push(@chosen,$allprobs[$idx-1]);
                    246:     }
                    247: }
                    248: 
                    249: sub store {
                    250:    my ($r)=@_;
                    251:    my @errors=&checkvalid();
                    252:    if ($#errors>1) { return; }
                    253:    &chosen_to_map();
                    254:    &storemap_gci();
1.3       gci       255:    if ($env{'form.phase'} eq 'storemap') {
                    256:       unless ($#errors>-1) {
                    257:          $r->print('<p>'.&mt('You have successfully assembled a valid test.').
1.1       gci       258:                 '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
                    259:                 '<input type="hidden" name="orgurl" value="/adm/navmaps" /><input type="hidden" name="selectrole" value="1" />'.
                    260:                 '<input type="hidden" name="'.$env{'request.role'}.'" value="1" /><input type="submit" value="'.
                    261:                  &mt('Activate Current Test').'" /></form></p>');
1.3       gci       262:       }
1.1       gci       263:    }
                    264: }
                    265: 
                    266: sub load {
                    267:    &mapread_gci();
                    268:    &map_to_chosen();
                    269:    my @errors=&checkvalid();
                    270:    if ($#errors>1) { @chosen=@defchosen; }
                    271: }
                    272: 
                    273: } #end scope variables
                    274: 
                    275: 1;
                    276: __END__
                    277: 

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