[LON-CAPA-cvs] cvs: loncom /interface lonprintout.pm lonwizard.pm

bowersj2 lon-capa-cvs@mail.lon-capa.org
Thu, 27 Feb 2003 21:01:09 -0000


bowersj2		Thu Feb 27 16:01:09 2003 EDT

  Modified files:              
    /loncom/interface	lonwizard.pm lonprintout.pm 
  Log:
  Better student selecter. Still not perfect; need to work out
  how to select by section. (Probably going to go with adding
  it to the form value after login and dom.)
  
  
Index: loncom/interface/lonwizard.pm
diff -u loncom/interface/lonwizard.pm:1.13 loncom/interface/lonwizard.pm:1.14
--- loncom/interface/lonwizard.pm:1.13	Thu Feb 27 14:42:59 2003
+++ loncom/interface/lonwizard.pm	Thu Feb 27 16:01:09 2003
@@ -522,14 +522,14 @@
     my $var = shift;
     my $wizard = $self->{WIZARD};
 
-    my $formvalue = $ENV{'form.' . $var};
+    my $formvalue = $ENV{'form.' . $formname};
     if ($formvalue) {
         # Must extract values from $wizard->{DATA} directly, as there
         # may be more then one.
         my @values;
         for my $formparam (split (/&/, $wizard->{DATA})) {
             my ($name, $value) = split(/=/, $formparam);
-            if ($name ne $var) {
+            if ($name ne $formname) {
                 next;
             }
             $value =~ tr/+/ /;
@@ -719,15 +719,9 @@
     my $choices = $self->{CHOICE_HASH};
     my @keys = keys (%$choices);
 
-    my $multichoice = '';
-    if ($self->{MULTICHOICE}) {
-        $multichoice = 'multichoice="true" ';
-    }
-
     my $type = "radio";
     if ($self->{MULTICHOICE}) { $type = 'checkbox'; }
-    foreach (@keys)
-    {
+    foreach (@keys) {
         
         $result .= "<input type='$type' name='" .
             $self->{VAR_NAME} . '.forminput' .
@@ -736,8 +730,7 @@
             . "\"/> " . HTML::Entities::encode($_) . "<br />\n";
     }
 
-    if (defined $self->{MESSAGE_AFTER})
-    {
+    if (defined $self->{MESSAGE_AFTER}) {
 	$result .= '<br /><br />' . $self->{MESSAGE_AFTER};
     }
 
@@ -749,7 +742,11 @@
     my $wizard = $self->{WIZARD};
     my $formvalue = $ENV{'form.' . $self->{VAR_NAME} . '.forminput'};
     if ($formvalue) {
-        # Value already stored by Wizard
+        if ($self->{MULTICHOICE}) {
+            $self->process_multiple_choices($self->{VAR_NAME}.'.forminput',
+                                            $self->{VAR_NAME});
+        }
+        # For non-multichoice, value already stored by Wizard
         $wizard->changeState($self->{NEXT_STATE});
     } else {
         $self->{ERROR_MSG} = "Can't continue the wizard because you must make"
@@ -1450,27 +1447,106 @@
 package Apache::lonwizard::choose_student;
 
 no strict;
-@ISA = ("Apache::lonwizard::choice_state");
+@ISA = ("Apache::lonwizard::state");
 use strict;
 
 sub new {
     my $proto = shift;
     my $class = ref($proto) || $proto;
-    my $self = bless $proto->SUPER::new(shift, shift, shift, shift,
-                                        shift, shift, shift, undef, shift);
+    my $self = bless $proto->SUPER::new(shift, shift, shift);
+
+    $self->{MESSAGE_BEFORE} = shift;
+    $self->{NEXT_STATE} = shift;
+    $self->{VAR_NAME} = shift;
+    $self->{MULTICHOICE} = shift;
+
     return $self;
 }
 
-sub determineChoices {
-    my %choices;
+sub render {
+    my $self = shift;
+    my $result = '';
+    my $var = $self->{VAR_NAME};
+    my $buttons = '';
 
-    my $classlist = Apache::loncoursedata::get_classlist();
-    foreach (keys %$classlist) {
-        $choices{$classlist->{$_}->[6]} = $_;
+    if ($self->{MULTICHOICE}) {
+        $result = <<SCRIPT;
+<script>
+    function checkall(value) {
+	for (i=0; i<document.forms.wizform.elements.length; i++) {
+            document.forms.wizform.elements[i].checked=value;
+        }
     }
-    
-    return \%choices;
+</script>
+SCRIPT
+        $buttons = <<BUTTONS;
+<input type="button" onclick="checkall(true)" value="Select All" />
+<input type="button" onclick="checkall(false)" value="Unselect All" />
+<br />
+BUTTONS
+    }
+
+    if (defined $self->{ERROR_MSG}) {
+        $result .= '<font color="#FF0000">' . $self->{ERROR_MSG} . '</font><br /><br />';
+    }
+
+    if (defined $self->{MESSAGE_BEFORE}) {
+        $result .= $self->{MESSAGE_BEFORE} . '<br /><br />';
+    }
+
+    $result .= $buttons;
+
+    my $choices = &Apache::loncoursedata::get_classlist();
+
+    my @keys = keys %{$choices};
+    # Sort by: Section, name
+   
+    @keys = sort {
+        if ($choices->{$a}->[3] ne $choices->{$b}->[3]) {
+            return $choices->{$a}->[3] cmp $choices->{$b}->[3];
+        }
+        return $choices->{$a}->[6] cmp $choices->{$b}->[6];
+    } @keys;
+
+    my $type = 'radio';
+    if ($self->{MULTICHOICE}) { $type = 'checkbox'; }
+    $result .= "<table cellspacing='2' cellpadding='2' border='0'>\n";
+    $result .= "<tr><td></td><td align='center'><b>Student Name</b></td>".
+        "<td align='center'><b>Section</b></td></tr>";
+
+    foreach (@keys) {
+        $result .= "<tr><td><input type='$type' name='" .
+            $self->{VAR_NAME} . '.forminput' .
+            "' value='" . HTML::Entities::encode($_)
+            . "' /></td><td>" . HTML::Entities::encode($choices->{$_}->[6])
+            . "</td><td align='center'>" 
+            . HTML::Entities::encode($choices->{$_}->[5])
+            . "</td></tr>\n";
+    }
+
+    $result .= "</table>\n\n";
+    $result .= $buttons;
+
+    return $result;
 }
+
+sub postprocess {
+    my $self = shift;
+    my $wizard = $self->{WIZARD};
+    my $formvalue = $ENV{'form.' . $self->{VAR_NAME} . '.forminput'};
+    if ($formvalue) {
+        if ($self->{MULTICHOICE}) {
+            $self->process_multiple_choices($self->{VAR_NAME}.'.forminput',
+                                            $self->{VAR_NAME});
+        }
+        $wizard->changeState($self->{NEXT_STATE});
+    } else {
+        $self->{ERROR_MSG} = "Can't continue the wizard because you must make"
+            . ' a selection to continue.';
+    }
+    return 1;
+}
+
 
 1;
 
Index: loncom/interface/lonprintout.pm
diff -u loncom/interface/lonprintout.pm:1.121 loncom/interface/lonprintout.pm:1.122
--- loncom/interface/lonprintout.pm:1.121	Thu Feb 27 14:41:40 2003
+++ loncom/interface/lonprintout.pm	Thu Feb 27 16:01:09 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Printout
 #
-# $Id: lonprintout.pm,v 1.121 2003/02/27 19:41:40 bowersj2 Exp $
+# $Id: lonprintout.pm,v 1.122 2003/02/27 21:01:09 bowersj2 Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1355,7 +1355,7 @@
     if (($ENV{'request.role'}=~m/^cc\./ or $ENV{'request.role'}=~m/^in\./ or $ENV{'request.role'}=~m/^ta\./) and ($ENV{'form.postdata'}=~/\/res\//)) { 
         push @{$printChoices}, ['all_problems', '<b>All problems</b> in course (may take a lot of time)', 'CHOOSE_FORMAT'];
         push @{$printChoices}, ['problems_for_students', "Problems from <b>$sequenceTitle</b> for selected students", 'CHOOSE_STUDENTS'];
-        Apache::lonwizard::choose_student->new($wizard, "CHOOSE_STUDENTS", "Choose Students", "Select the students you wish to print the problems for:", '', 'CHOOSE_FORMAT', 'STUDENTS', 1);
+        Apache::lonwizard::choose_student->new($wizard, "CHOOSE_STUDENTS", "Choose Students", "Select the students you wish to print the problems for:", 'CHOOSE_FORMAT', 'STUDENTS', 1);
     }
 
     # FIXME: That RE should come from a library somewhere.
@@ -1420,20 +1420,6 @@
     $self->{VAR_NAME} = shift;
     $self->{NEXT_STATE} = shift;
     return $self;
-}
-
-sub postprocess {
-    my $self = shift;
-    my $wizard = $self->{WIZARD};
-
-    # We have to manually collect the value and store it in the 
-    # wizard variable
-    my $result = $ENV{'form.' . $self->{VAR_NAME} . '.layout'} . '|';
-    $result .= $ENV{'form.' . $self->{VAR_NAME} . '.cols'} . '|';
-    $result .= $ENV{'form.' . $self->{VAR_NAME} . '.paper'};
-    
-    $wizard->setVar($self->{VAR_NAME}, $result);
-    $wizard->changeState($self->{NEXT_STATE});
 }
 
 sub render {