[LON-CAPA-cvs] cvs: modules /gci londocsgci.pm

gci gci@source.lon-capa.org
Fri, 27 Nov 2009 23:48:25 -0000


gci		Fri Nov 27 23:48:25 2009 EDT

  Modified files:              
    /modules/gci	londocsgci.pm 
  Log:
  Mandatory problems cannot be deselected
  Categories -> Bins
  Different work flow
  
  
Index: modules/gci/londocsgci.pm
diff -u modules/gci/londocsgci.pm:1.2 modules/gci/londocsgci.pm:1.3
--- modules/gci/londocsgci.pm:1.2	Sat Oct  3 03:11:30 2009
+++ modules/gci/londocsgci.pm	Fri Nov 27 23:48:25 2009
@@ -2,7 +2,7 @@
 # Custom Edit Course Routines for Assembly of Valid Concept Tests from
 # Geoscience Concept Inventory. 
 #
-# $Id: londocsgci.pm,v 1.2 2009/10/03 03:11:30 gci Exp $
+# $Id: londocsgci.pm,v 1.3 2009/11/27 23:48:25 gci Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -50,6 +50,7 @@
 my %prereqs;
 my @defchosen;
 my @chosen;
+my %mandatory;
 
 sub setdefaults {
    $path='/res/gci/gci';
@@ -88,6 +89,7 @@
               '61' => 'I' ,'62' => 'I' ,'63' => 'J' ,'64' => 'J' ,'65' => 'J' ,'66' => 'K' ,'67' => 'K' ,'68' => 'K' ,'69' => 'K' ,'70' => 'K' ,
               '71' => 'K' ,
               '2004_73' => 'M4');
+   %mandatory=('01' => 1 ,'02' => 1,'37' => 1,'2004_73' => 1);
    %prereqs=('10' => '08', '57' => '52', '69' => '18');
    @defchosen=('01','02','03','07','12','18','26','32','37','38','47','54','63','66','2004_73');
 }
@@ -106,7 +108,7 @@
    }
    foreach my $cat (@categories) {
       unless ($covered{$cat}) {
-         push(@errors,&mt('Category [_1] not covered.',$cat));
+         push(@errors,&mt('Bin [_1] not covered.',$cat));
       }
    }
    foreach my $item (@chosen) {
@@ -125,7 +127,7 @@
    return $path.'/'.$version.'/GCI'.$item.'.problem';
 }
 
-sub listresources {
+sub validcheck {
    my ($r)=@_;
    my @errors=&checkvalid();
    if ($#errors>-1) {
@@ -134,22 +136,50 @@
          $r->print('<li>'.$message.'</li>');
       }
       $r->print('</ul></p>');
+      return 0;
+   }
+   return 1;
+}
+
+sub listresources {
+   my ($r)=@_;
+   if ((!&validcheck($r)) || ($env{'form.editmyown'})) {
+      &editor($r);
+   } else {
+      $r->print('<p><form name="choices" method="post">');
+      $r->print('<input type="submit" name="editmyown" value="'.&mt('Create Your Own Test').'" />');
+      $r->print('</form></p><p><form name="defaulting" method="post">');
+      $r->print('<input type="hidden" name="phase" value="storemap" />');
+      foreach my $item (@defchosen) {
+         $r->print('<input type="hidden" name="item'.$item.'" value="checked"');
+      }
+      $r->print('<input type="submit" name="defchosen" value="'.&mt('Let WebCenter Create a Test for You').'" />');
+      $r->print('</form><p>');
    }
+}
+
+sub editor {
+   my ($r)=@_;
    my %chosen=();
    foreach my $item (@chosen) {
       $chosen{$item}=1;
    }
    $r->print('<form name="selecteditems" method="post" action="/adm/coursedocs">');
-   $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>'); 
+   $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>');
+   $r->print('<p>'.&mt('Tests should have at least one item from each bin and [_1] items total.',$reqnum).'</p>'); 
    $r->print(&Apache::loncommon::start_data_table().
              &Apache::loncommon::start_data_table_header_row().
-             '<th>'.&mt('Select').'</th><th>'.&mt('Problem').'</th><th>'.&mt('Category').'</th><th>'.&mt('Preview').'</th>'.
+             '<th>'.&mt('Select').'</th><th>'.&mt('Problem').'</th><th>'.&mt('Bin').'</th><th>'.&mt('Preview').'</th>'.
              &Apache::loncommon::end_data_table_header_row());
    foreach my $item (@allprobs) {
       $r->print(&Apache::loncommon::start_data_table_row());
       $r->print('<td><font size="+3">');
-      $r->print('<input type="checkbox" name="item'.$item.'"');
-      if ($chosen{$item}) { $r->print(' checked="checked"'); }
+      if ($mandatory{$item}) {
+         $r->print('<input type="hidden" name="item'.$item.'" value="checked"');
+      } else {
+         $r->print('<input type="checkbox" name="item'.$item.'"');
+         if ($chosen{$item}) { $r->print(' checked="checked"'); }
+      }
       $r->print(' /></font></td>');
       $r->print('<td><font size="+3">'.$item.'</font></td><td><font size="+3">'.$probcat{$item}.'</font></td>');
       my $output=&Apache::lonindexer::showpreview(&fullurl($item));
@@ -220,12 +250,14 @@
    if ($#errors>1) { return; }
    &chosen_to_map();
    &storemap_gci();
-   unless ($#errors>-1) {
-      $r->print('<p>'.&mt('You have successfully assembled a valid test.').
+   if ($env{'form.phase'} eq 'storemap') {
+      unless ($#errors>-1) {
+         $r->print('<p>'.&mt('You have successfully assembled a valid test.').
                 '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
                 '<input type="hidden" name="orgurl" value="/adm/navmaps" /><input type="hidden" name="selectrole" value="1" />'.
                 '<input type="hidden" name="'.$env{'request.role'}.'" value="1" /><input type="submit" value="'.
                  &mt('Activate Current Test').'" /></form></p>');
+      }
    }
 }