--- loncom/interface/Attic/lonwizard.pm 2002/08/09 14:48:31 1.1 +++ loncom/interface/Attic/lonwizard.pm 2003/02/14 00:41:50 1.9 @@ -5,6 +5,7 @@ package Apache::lonwizard; use Apache::Constants qw(:common :http); use Apache::loncommon; +use Apache::lonnet; =head1 lonwizard - HTML "Wizard" framework for LON-CAPA @@ -90,9 +91,9 @@ sub new { =over 2 -=item B(title): Returns a new instance of the given wizard type. "title" is the human-readable name of the wizard. A new wizard always starts on the B state name. +=item * B(title): Returns a new instance of the given wizard type. "title" is the human-readable name of the wizard. A new wizard always starts on the B state name. -=item B(varList): Call this function to declare the var names you want the wizard to maintain for you. The wizard will automatically output the hidden form fields and parse the values for you on the next call. +=item * B(varList): Call this function to declare the var names you want the wizard to maintain for you. The wizard will automatically output the hidden form fields and parse the values for you on the next call. This is a bulk declaration. =over 2 @@ -102,6 +103,13 @@ sub new { =cut +# Sometimes the wizard writer will want to use the result of the previous +# state to change the text of the next state. In order to do that, it +# has to be done during the declaration of the states, or it won't be +# available. Therefore, basic form processing must occur before the +# actual display routine is called and the actual pre-process is called, +# or it won't be available. +# This also factors common code out of the preprocess calls. sub declareVars { my $self = shift; my $varlist = shift; @@ -118,6 +126,12 @@ sub declareVars { { $self->{VARS}->{$element} = $ENV{$envname}; } + + # If there's an incoming form submission, use that + $envname = "form." . $element . ".forminput"; + if (defined ($ENV{$envname})) { + $self->{VARS}->{$element} = $ENV{$envname}; + } } } @@ -127,7 +141,6 @@ sub declareVars { sub _saveVars { my $self = shift; my $result = ""; - print $self->{VARS}{VAR1}; foreach my $varname (keys %{$self->{VARS}}) { $result .= 'preprocess(); # Phase 3: While the current state is different from the previous state, @@ -215,43 +234,56 @@ sub display { # Phase 4: Display. my $stateTitle = $state->title(); + my $bodytag = &Apache::loncommon::bodytag("$self->{TITLE}",'',''); $result .= < - LON-CAPA Wizard: $self->{NAME} + LON-CAPA Wizard: $self->{TITLE} - -

LON-CAPA Wizard: $self->{TITLE}

- -

$stateTitle

- -
+ $bodytag +HEADER + if (!$state->overrideForm()) { $result.=""; } + $result .= < +

$stateTitle

HEADER - $result .= $self->_saveVars(); + if (!$state->overrideForm()) { + $result .= $self->_saveVars(); + } $result .= $state->render() . "

 

"; - if ($self->{STATE} ne $self->{START_STATE}) - { - $result .= '  '; - } - if ($self->{DONE}) - { - my $returnPage = $self->{RETURN_PAGE}; - $result .= "End Wizard"; - } - else - { - $result .= ''; + if (!$state->overrideForm()) { + $result .= '
'; + if ($self->{STATE} ne $self->{START_STATE}) + { + #$result .= '  '; + } + if ($self->{DONE}) + { + my $returnPage = $self->{RETURN_PAGE}; + $result .= "End Wizard"; + } + else + { + $result .= ' + + FOOTER + + return $result; } =pod @@ -284,12 +316,33 @@ sub getVars { =cut +# This may look trivial, but it's here as a hook for possible later processing sub setVar { my $self = shift; my $key = shift; my $val = shift; $self->{VARS}{$key} = $val; - print "set $key to $val
"; +} + +=pod + +=item B(): Returns a string representing the current state of the wizard, suitable for use directly as part of a query string. (See resource_state for an example.) + +=cut + +sub queryStringVars { + my $self = shift; + + my @queryString = (); + + for my $varname (keys %{$self->{VARS}}) { + push @queryString, Apache::lonnet::escape($varname) . "=" . + Apache::lonnet::escape($self->{VARS}{$varname}); + } + push @queryString, 'CURRENT_STATE=' . Apache::lonnet::escape($self->{STATE}); + push @queryString, 'RETURN_PAGE=' . Apache::lonnet::escape($self->{RETURN_PAGE}); + + return join '&', @queryString; } =pod @@ -304,15 +357,70 @@ sub handler { my $r = shift; Apache::loncommon::get_unprocessed_cgi($ENV{QUERY_STRING}); - - my $mes = "Using this wizard, you can
  • change the due date of an assignment
  • change the due date for a whole map of assignments
  • change the due date for just one person
"; - my $wizard = Apache::lonwizard->new("Test Wizard"); + if ($r->header_only) { + if ($ENV{'browser.mathml'}) { + $r->content_type('text/xml'); + } else { + $r->content_type('text/html'); + } + $r->send_http_header; + return OK; + } + + # Send header, don't cache this page + if ($ENV{'browser.mathml'}) { + $r->content_type('text/xml'); + } else { + $r->content_type('text/html'); + } + &Apache::loncommon::no_cache($r); + $r->send_http_header; + $r->rflush(); + + my $mes = <This wizard will allow you to set open, due, and answer dates for problems. You will be asked to select a problem, what kind of date you want to set, and for whom the date should be effective.

+ +

After the wizard is done, you will be shown where in the advanced interface you would have gone to change the parameter you have chosen, so in the future you can do it directly.

- my $mesState = Apache::lonwizard::message_state->new($wizard, "START", "Welcome to the Assignment Parameter Wizard", $mes, "NEXT"); - my $mesState2 = Apache::lonwizard::choice_state->new($wizard, "NEXT", "Fucking the Cow", "How should the cow be fucked?", "Wow, with so many wonderful choices, how will you choose!?!", "START", "VAR1", {'standing & dildoated','standing & didldoated', 'rotten','rotten', 'sitting','sitting'}); - $wizard->declareVars( ["VAR1", "VAR2", "VAR3"] ); +

Press Next -> to begin, or select <- Previous to go back to the previous screen.

+WIZBEGIN + my $wizard = Apache::lonwizard->new("Course Parameter Wizard"); + $wizard->declareVars(['ACTION_TYPE', 'GRANULARITY', 'TARGETS', 'PARM_DATE', 'RESOURCE_ID', 'USER_NAME', 'SECTION_NAME']); + my %dateTypeHash = ('open_date' => "opening date", + 'due_date' => "due date", + 'answer_date' => "answer date"); + my %levelTypeHash = ('whole_course' => "all problems in the course", + 'map' => 'the selected folder', + 'resource' => 'the selected problem'); + + Apache::lonwizard::message_state->new($wizard, "START", "Welcome to the Assignment Parameter Wizard", $mes, "CHOOSE_LEVEL"); + Apache::lonwizard::switch_state->new($wizard, "CHOOSE_LEVEL", "Which Problem or Problems?", "GRANULARITY", [ + ["whole_course", "Every problem in the course", "CHOOSE_ACTION"], + ["map", "Every problem in a particular folder", "CHOOSE_FOLDER"], + ["resource", "One particular problem", "CHOOSE_RESOURCE"]], + "Which problems do you wish to change a date for?"); + Apache::lonwizard::resource_choice->new($wizard, "CHOOSE_FOLDER", "Select Folder", "Select the folder you wish to set the date for:", "", "CHOOSE_ACTION", "RESOURCE_ID", sub {my $res = shift; return $res->is_map();}); + Apache::lonwizard::resource_choice->new($wizard, "CHOOSE_RESOURCE", "Select Resource", "", "", "CHOOSE_ACTION", "RESOURCE_ID", sub {my $res = shift; return $res->is_map() || $res->is_problem();}, sub {my $res = shift; return $res->is_problem(); }); + my $levelType = $levelTypeHash{$wizard->{VARS}->{GRANULARITY}}; + Apache::lonwizard::switch_state->new($wizard, "CHOOSE_ACTION", "Parameter Type", "ACTION_TYPE", [ + ["open_date", "Set an open date", "CHOOSE_DATE"], + ["due_date", "Set a due date", "CHOOSE_DATE"], + ["answer_date", "Set an answer open date", "CHOOSE_DATE" ] ], + "What parameters do you want to set for $levelType?"); + my $dateType = $dateTypeHash{$wizard->{VARS}->{ACTION_TYPE}}; + Apache::lonwizard::date_state->new($wizard, "CHOOSE_DATE", "Set Date", "PARM_DATE", "CHOOSE_STUDENT_LEVEL", "What should the $dateType be set to?"); + Apache::lonwizard::switch_state->new($wizard, "CHOOSE_STUDENT_LEVEL", "Students Affected", "TARGETS", [ + ["course", ". . . for all students in the course", "FINISH"], + ["section", ". . . for a particular section", "CHOOSE_SECTION"], + ["student", ". . . for an individual student", "CHOOSE_STUDENT"]], + "Set $dateType of $levelType for. . ."); + + Apache::lonwizard::choose_section->new($wizard, "CHOOSE_SECTION", "Select Section", "Please select the section you wish to set the $dateType for:", "", "FINISH", "SECTION_NAME"); + Apache::lonwizard::choose_student->new($wizard, "CHOOSE_STUDENT", "Select Student", "Please select the student you wish to set the $dateType for:", "", "FINISH", "USER_NAME"); + Apache::lonwizard::parmwizfinal->new($wizard, "FINISH", "Confirm Selection"); + $r->print($wizard->display()); return OK; @@ -328,6 +436,12 @@ A "lonwizstate" object represents a lonw Several pre-prepared child classes are include in lonwizard. If you create a new wizard type, be sure to add it to lonwizard.pm so others can use it too. +It is importent to remember when constructing states that the user may use the "Previous" button to go back and revisit a state previously filled out. Thus, states should consult the wizard variables they are intended to set to see if the user has already selected something, and when displaying themselves should reselect the same values, such that the user paging from the end to the beginning, back to the end, will not change any settings. + +None of the pre-packaged states correctly handle there being B input, as the wizard does not currently have any protection against errors in the states themselves. (The closest thing you can do is set the wizard to be done and display an error message, which should be adequate.) + +By default, the wizard framework will take form elements of the form {VAR_NAME}.forminput and automatically insert the contents of that form element into the wizard variable {VAR_NAME}. You only need to use postprocess to do something fancy if that is not sufficient, for instance, processing a multi-element selection. (See resource choice for an example of that.) + =head2 lonwizstate methods These methods should be overridden in derived states, except B which may be sufficient. @@ -392,6 +506,12 @@ sub postprocess { return 1; } +# If this is 1, the wizard assumes the state will override the +# wizard's form, useful for some final states +sub overrideForm { + return 0; +} + 1; =pod @@ -408,7 +528,7 @@ message_state is a state the simply disp =over 4 -=item overridden method B(parentLonWizReference, stateName, message, nextState): Two new parameters "message" will be the HTML message displayed to the user, and "nextState" is the name of the next state. +=item overridden method B(parentLonWizReference, stateName, stateTitle, message, nextState): Two new parameters "message" will be the HTML message displayed to the user, and "nextState" is the name of the next state. =back @@ -424,6 +544,7 @@ sub new { my $proto = shift; my $class = ref($proto) || $proto; + # This cute looking statement correctly handles subclassing my $self = bless $proto->SUPER::new(shift, shift, shift); $self->{MESSAGE} = shift; @@ -451,19 +572,6 @@ no strict; @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); - - $self->{MESSAGE_BEFORE} = shift; - $self->{MESSAGE_AFTER} = shift; - $self->{NEXT_STATE} = shift; - $self->{VAR_NAME} = shift; - $self->{CHOICE_HASH} = shift; - $self->{NO_CHOICES} = 0; -} - =pod =head2 Class: choice_state @@ -476,27 +584,47 @@ If there is only one choice, the state w =item overridden method B(parentLonWizReference, stateName, stateTitle, messageBefore, messageAfter, nextState, varName, choiceHash): messageBefore is the HTML text that will be displayed before the choice display, messageAfter will display after. Keys will be sorted according to human name. nextState is the state to proceed to after the choice. varName is the name of the wizard var to store the computer_name answer in. choiceHash is the hash described above. It is optional because you may override it. +=back + =cut +sub new { + my $proto = shift; + my $class = ref($proto) || $proto; + my $self = bless $proto->SUPER::new(shift, shift, shift); + + $self->{MESSAGE_BEFORE} = shift; + $self->{MESSAGE_AFTER} = shift; + $self->{NEXT_STATE} = shift; + $self->{VAR_NAME} = shift; + $self->{CHOICE_HASH} = shift; + $self->{NO_CHOICES} = 0; + + return $self; +} + sub preprocess { my $self = shift; - my %choices = %{$self->{CHOICE_HASH}}; - my %wizvars = %{$self->{WIZARD}->getVars()}; + my $choices = $self->{CHOICE_HASH}; + if (!defined($self->{CHOICE_HASH})) { + $choices = $self->{CHOICE_HASH} = $self->determineChoices(); + } + my $wizvars = $self->{WIZARD}->getVars(); - my @keys = keys(%choices); + my @keys = keys(%$choices); @keys = sort @keys; if (scalar(@keys) == 0) { # No choices... so prepare to display error message and cancel further execution. $self->{NO_CHOICES} = 1; - $self->{WIZARD}->setDone(); + $self->{WIZARD}->{DONE} = 1; return; } if (scalar(@keys) == 1) { # If there is only one choice, pick it and move on. - $wizvars{$self->{VAR_NAME}} = $choices{$keys[0]}; + $wizvars->{$self->{VAR_NAME}} = $choices->{$keys[0]}; $self->{WIZARD}->changeState($self->{NEXT_STATE}); return; } @@ -514,33 +642,46 @@ sub render { my $self = shift; my $result = ""; my $var = $self->{VAR_NAME}; - my %choices = %{$self->{CHOICE_HASH}}; - if (!defined ($self->{CHOICE_HASH})) - { - $self->determineChoices(); + if (defined $self->{ERROR_MSG}) { + $result .= '' . $self->{ERROR_MSG} . '

'; } - my %choices = %{$self->{CHOICE_HASH}}; - my @keys = keys (%choices); + if (defined $self->{MESSAGE_BEFORE}) + { + $result .= $self->{MESSAGE_BEFORE} . '

'; + } - $result .= "\n"; foreach (@keys) { - $result .= "\n"; } - $result .= "\n\n"; + + if (defined $self->{MESSAGE_AFTER}) + { + $result .= '

' . $self->{MESSAGE_AFTER}; + } + return $result; } sub postprocess { my $self = shift; my $wizard = $self->{WIZARD}; - $wizard->setVar($self->{VAR_NAME}, $ENV{"form." . $self->{VAR_NAME} . ".forminput"}); - $wizard->changeState($self->{NEXT_STATE}); + my $formvalue = $ENV{'form.' . $self->{VAR_NAME} . '.forminput'}; + if ($formvalue) { + # Value already stored by Wizard + $wizard->changeState($self->{NEXT_STATE}); + } else { + $self->{ERROR_MSG} = "Can't continue the wizard because you must make" + . ' a selection to continue.'; + } return 1; } @@ -550,3 +691,610 @@ no strict; @ISA = ("Apache::lonwizard::state"); use strict; +=pod + +=head2 Class; switch_state + +Switch state provides the ability to present the user with several radio-button choices. The state can store the user response in a wizard variable, and can also send the user to a different state for each selection, which is the intended primary purpose. + +Each choice may have arbitrary HTML associated with it, which will be used as the label. The first choice will be selected by default. + +=over 4 + +=item overridden method B(parentLonWizReference, stateName, stateTitle, varName, choiceList, messageBefore, messageAfter): varName is the name of the wizard variable the state will set with the choice made. choiceHash is list reference of a list of list references to three element lists, where the first element is what the wizard var varName will be set to, the second is the HTML that will be displayed for that choice, and the third is the destination state. messageBefore is an optional HTML string that will be placed before the message, messageAfter an optional HTML string that will be placed before. + +An example of a legit choiceList: C + +=back + +=cut + +sub new { + my $proto = shift; + my $class = ref($proto) || $proto; + my $self = bless $proto->SUPER::new(shift, shift, shift); + + $self->{VAR_NAME} = shift; + $self->{CHOICE_LIST} = shift; + $self->{MESSAGE_BEFORE} = shift; + $self->{MESSAGE_AFTER} = shift; + + return $self; +} + +# Don't need a preprocess step; we assume we know the choices + +sub render { + my $self = shift; + my $result = ""; + my $var = $self->{VAR_NAME}; + my @choices = @{$self->{CHOICE_LIST}}; + my $curVal = $self->{WIZARD}->{VARS}->{$var}; + + $result .= $self->{MESSAGE_BEFORE} if (defined $self->{MESSAGE_BEFORE}); + + if (!$curVal) { + $curVal = $self->{CHOICE_LIST}->[0]->[0]; # top is default + } + + $result .= "\n\n"; + + foreach my $choice (@choices) + { + my $value = $choice->[0]; + my $text = $choice->[1]; + + $result .= "\n\n\n\n\n\n"; + } + + $result .= "
 "; + $result .= "$text
\n\n"; + + $result .= $self->{MESSAGE_AFTER} if (defined $self->{MESSAGE_AFTER}); + + return $result; +} + +sub postprocess { + # Value already stored by wizard + my $self = shift; + my $wizard = $self->{WIZARD}; + my $chosenValue = $ENV{"form." . $self->{VAR_NAME} . '.forminput'}; + + foreach my $choice (@{$self->{CHOICE_LIST}}) + { + if ($choice->[0] eq $chosenValue) + { + $wizard->changeState($choice->[2]); + } + } +} + +# If there is only one choice, make it and move on +sub preprocess { + my $self = shift; + my $choiceList = $self->{CHOICE_LIST}; + my $wizard = $self->{WIZARD}; + + if (scalar(@{$choiceList}) == 1) + { + my $choice = $choiceList->[0]; + my $chosenVal = $choice->[0]; + my $nextState = $choice->[2]; + + $wizard->setVar($self->{VAR_NAME}, $chosenVal) + if (defined ($self->{VAR_NAME})); + $wizard->changeState($nextState); + } +} + +1; + +package Apache::lonwizard::date_state; + +use Time::localtime; +use Time::Local; +use Time::tm; + +no strict; +@ISA = ("Apache::lonwizard::state"); +use strict; + +my @months = ("January", "February", "March", "April", "May", "June", "July", + "August", "September", "October", "November", "December"); + +=pod + +=head2 Class: date_state + +Date state provides a state for selecting a date/time, as seen in the course parmset wizard.. You can choose to display date entry if that's what you need. + +=over 4 + +=item overriddent method B(parentLonWizReference, stateName, stateTitle, varName, nextState, messageBefore, messageAfter, displayJustDate): varName is where the date/time will be stored as seconds since the epoch. messageBefore and messageAfter as other states. displayJustDate is a flag defaulting to false that if true, will only display the date selection (defaulting to midnight on that date). Otherwise, minutes and hours will be shown. + +=back + +=cut + +sub new { + my $proto = shift; + my $class = ref($proto) || $proto; + my $self = bless $proto->SUPER::new(shift, shift, shift); + + $self->{VAR_NAME} = shift; + $self->{NEXT_STATE} = shift; + $self->{MESSAGE_BEFORE} = shift; + $self->{MESSAGE_AFTER} = shift; + $self->{DISPLAY_JUST_DATE} = shift; + if (!defined($self->{DISPLAY_JUST_DATE})) {$self->{DISPLAY_JUST_DATE} = 0;} + return $self; +} + +sub render { + my $self = shift; + my $result = ""; + my $var = $self->{VAR_NAME}; + my $name = $self->{NAME}; + my $wizvars = $self->{WIZARD}->getVars(); + + my $date; + + # Pick default date: Now, or previous choice + if (defined ($wizvars->{$var}) && $wizvars->{$var} ne "") + { + $date = localtime($wizvars->{$var}); + } + else + { + $date = localtime(); + } + + if (defined $self->{ERROR_MSG}) { + $result .= '' . $self->{ERROR_MSG} . '

'; + } + + if (defined ($self->{MESSAGE_BEFORE})) { + $result .= $self->{MESSAGE_BEFORE}; + $result .= "

\n\n"; + } + + # Month + my $i; + $result .= "\n"; + + # Day + $result .= ",\n"; + + # Year + $result .= ",\n"; + + # Display Hours and Minutes if they are called for + if (!$self->{DISPLAY_JUST_DATE}) { + # Build hour + $result .= " :\n"; + + $result .= "\n"; + } + + if (defined ($self->{MESSAGE_AFTER})) { + $result .= "

" . $self->{MESSAGE_AFTER}; + } + + return $result; +} + +# Stick the date stored into the chosen variable. +sub postprocess { + my $self = shift; + my $wizard = $self->{WIZARD}; + + my $month = $ENV{'form.' . $self->{VAR_NAME} . 'month'}; + my $day = $ENV{'form.' . $self->{VAR_NAME} . 'day'}; + my $year = $ENV{'form.' . $self->{VAR_NAME} . 'year'}; + my $min = 0; + my $hour = 0; + if (!$self->{DISPLAY_JUST_DATE}) { + $min = $ENV{'form.' . $self->{VAR_NAME} . 'minute'}; + $hour = $ENV{'form.' . $self->{VAR_NAME} . 'hour'}; + } + + my $chosenDate = Time::Local::timelocal(0, $min, $hour, $day, $month, $year); + # Check to make sure that the date was not automatically co-erced into a + # valid date, as we want to flag that as an error + # This happens for "Feb. 31", for instance, which is coerced to March 2 or + # 3, depending on if it's a leapyear + my $checkDate = localtime($chosenDate); + + if ($checkDate->mon != $month || $checkDate->mday != $day || + $checkDate->year + 1900 != $year) { + $self->{ERROR_MSG} = "Can't use " . $months[$month] . " $day, $year as a " + . "date because it doesn't exist. Please enter a valid date."; + return; + } + + $wizard->setVar($self->{VAR_NAME}, $chosenDate); + + $wizard->changeState($self->{NEXT_STATE}); +} + +1; + +package Apache::lonwizard::parmwizfinal; + +# This is the final state for the parmwizard. It is not generally useful, +# so it is not perldoc'ed. It does it's own processing. + +no strict; +@ISA = ('Apache::lonwizard::state'); +use strict; + +use Time::localtime; + +sub new { + my $proto = shift; + my $class = ref($proto) || $proto; + my $self = bless $proto->SUPER::new(shift, shift, shift); + + # No other variables because it gets it all from the wizard. +} + +# Renders a form that, when submitted, will form the input to lonparmset.pm +sub render { + my $self = shift; + my $wizard = $self->{WIZARD}; + my $wizvars = $wizard->{VARS}; + + # FIXME: Unify my designators with the standard ones + my %dateTypeHash = ('open_date' => "Opening Date", + 'due_date' => "Due Date", + 'answer_date' => "Answer Date"); + my %parmTypeHash = ('open_date' => "0_opendate", + 'due_date' => "0_duedate", + 'answer_date' => "0_answerdate"); + + my $result = "
\n"; + $result .= '

Confirm that this information is correct, then click "Finish Wizard" to complete setting the parameter.

    '; + my $affectedResourceId = ""; + my $parm_name = $parmTypeHash{$wizvars->{ACTION_TYPE}}; + my $level = ""; + + # Print the type of manipulation: + $result .= '
  • Setting the ' . $dateTypeHash{$wizvars->{ACTION_TYPE}} + . "
  • \n"; + if ($wizvars->{ACTION_TYPE} eq 'due_date' || + $wizvars->{ACTION_TYPE} eq 'answer_date') { + # for due dates, we default to "date end" type entries + $result .= "\n"; + $result .= "\n"; + $result .= "\n"; + } elsif ($wizvars->{ACTION_TYPE} eq 'open_date') { + $result .= "\n"; + $result .= "\n"; + $result .= "\n"; + } + + # Print the granularity, depending on the action + if ($wizvars->{GRANULARITY} eq 'whole_course') { + $result .= '
  • for all resources in the course
  • '; + $level = 9; # general course, see lonparmset.pm perldoc + $affectedResourceId = "0.0"; + } elsif ($wizvars->{GRANULARITY} eq 'map') { + my $navmap = Apache::lonnavmaps::navmap->new( + $ENV{"request.course.fn"}.".db", + $ENV{"request.course.fn"}."_parms.db", 0, 0); + my $res = $navmap->getById($wizvars->{RESOURCE_ID}); + my $title = $res->compTitle(); + $navmap->untieHashes(); + $result .= "
  • for the map named $title
  • "; + $level = 8; + $affectedResourceId = $wizvars->{RESOURCE_ID}; + } else { + my $navmap = Apache::lonnavmaps::navmap->new( + $ENV{"request.course.fn"}.".db", + $ENV{"request.course.fn"}."_parms.db", 0, 0); + my $res = $navmap->getById($wizvars->{RESOURCE_ID}); + my $title = $res->compTitle(); + $navmap->untieHashes(); + $result .= "
  • for the resource named $title
  • "; + $level = 7; + $affectedResourceId = $wizvars->{RESOURCE_ID}; + } + + # Print targets + if ($wizvars->{TARGETS} eq 'course') { + $result .= '
  • for all students in course
  • '; + } elsif ($wizvars->{TARGETS} eq 'section') { + my $section = $wizvars->{SECTION_NAME}; + $result .= "
  • for section $section
  • "; + $level -= 3; + $result .= "\n"; + } else { + # FIXME: This is probably wasteful! + my $classlist = Apache::loncoursedata::get_classlist(); + my $name = $classlist->{$wizvars->{USER_NAME}}->[6]; + $result .= "
  • for $name
  • "; + $level -= 6; + my ($uname, $udom) = split /:/, $wizvars->{USER_NAME}; + $result .= "\n"; + $result .= "\n"; + } + + # Print value + $result .= "
  • to " . ctime($wizvars->{PARM_DATE}) . " (" . + Apache::lonnavmaps::timeToHumanString($wizvars->{PARM_DATE}) + . ")
  • \n"; + + # print pres_marker + $result .= "\n\n"; + + $result .= "

    \n"; + + return $result; +} + +sub overrideForm { + return 1; +} + +1; + +package Apache::lonwizard::resource_choice; + +=pod + +=head2 Class: resource_choice + +folder_choice gives the user an opportunity to select one resource from the current course, and will stick the ID of that choice (#.#) into the desired variable. + +Note this state will not automatically advance if there is only one choice, because it might confuse the user in this case. + +=over 4 + +=item overriddent method B(parentLonWizReference, stateName, stateTitle, messageBefore, messageAfter, nextState, varName, filterFunction, choiceFunction, multichoice): messageBefore and messageAfter appear before and after the state choice, respectively. nextState is the state to proceed to after the choice. varName is the wizard variable to store the choice in. + +filterFunction is a function reference that receives the current resource as an argument, and returns 1 if it should be displayed, and 0 if it should not be displayed. By default, the class will use sub {return 1;}, which will show all resources. choiceFunction is a reference to a function that receives the resource object as a parameter and returns 1 if it should be a *selectable choice*, and 0 if not. By default, this is the same as the filterFunction, which means all displayed choices will be choosable. See parm wizard for an example of this in the resource selection routines. + +multichoice specifies whether the state should provide radio buttons, allowing the user one choice, or checkboxes, allowing the user multiple choices, and automatically including some convenience buttons the user can choose (like "Check All" and "Uncheck All"), implemented with Javascript. Defaults to false, allow just one choice. + +=back + +=cut + +no strict; +@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); + + $self->{MESSAGE_BEFORE} = shift; + $self->{MESSAGE_AFTER} = shift; + $self->{NEXT_STATE} = shift; + $self->{VAR_NAME} = shift; + $self->{FILTER_FUNC} = shift; + if (!defined($self->{FILTER_FUNC})) { + $self->{FILTER_FUNC} = sub {return 1;}; + } + $self->{CHOICE_FUNC} = shift; + if (!defined($self->{CHOICE_FUNC})) { + $self->{CHOICE_FUNC} = $self->{FILTER_FUNC}; + } + $self->{MULTICHOICE} = shift; + if (!defined($self->{MULTICHOICE})) { + $self->{MULTICHOICE} = 0; + } +} + +sub postprocess { + my $self = shift; + my $wizard = $self->{WIZARD}; + + # If we were just manipulating a folder, do not proceed to the + # next state + if ($ENV{'form.folderManip'}) { + return; + } + + if (!$ENV{'form.' . $self->{VAR_NAME} . '.forminput'}) { + $self->{ERROR_MSG} = "Can't continue wizard because you must ". + "select a resource."; + return; + } + + + # Value stored by wizard framework + + $wizard->changeState($self->{NEXT_STATE}); +} + +sub render { + my $self = shift; + my $wizard = $self->{WIZARD}; + my $result = ""; + my $var = $self->{VAR_NAME}; + my $curVal = $self->{WIZARD}->{VARS}->{$var}; + my $vals = {}; + if ($curVal =~ /,/) { # multiple choices + foreach (split /,/, $curVal) { + $vals->{$_} = 1; + } + } else { + $vals->{$curVal} = 1; + } + + if (defined $self->{ERROR_MSG}) { + $result .= '' . $self->{ERROR_MSG} . '

    '; + } + + $result .= $self->{MESSAGE_BEFORE} . '

    ' + if (defined $self->{MESSAGE_BEFORE}); + + my $filterFunc = $self->{FILTER_FUNC}; + my $choiceFunc = $self->{CHOICE_FUNC}; + + # Create the composite function that renders the column on the nav map + my $renderColFunc = sub { + my ($resource, $part, $params) = @_; + + if (!&$choiceFunc($resource)) { + return '
'; + } else { + my $col = ""; + return $col; + } + }; + + $result .= + &Apache::lonnavmaps::render( { 'cols' => [$renderColFunc, + Apache::lonnavmaps::resource()], + 'showParts' => 0, + 'queryString' => $wizard->queryStringVars() . '&folderManip=1', + 'url' => '/adm/wizard', + 'filterFunc' => $filterFunc } ); + + $result .= $self->{MESSAGE_AFTER} if (defined $self->{MESSAGE_AFTER}); + + return $result; +} + +1; + +package Apache::lonwizard::choose_student; + +no strict; +@ISA = ("Apache::lonwizard::choice_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); + return $self; +} + +sub determineChoices { + my %choices; + + my $classlist = Apache::loncoursedata::get_classlist(); + foreach (keys %$classlist) { + $choices{$classlist->{$_}->[6]} = $_; + } + + return \%choices; +} + +1; + +package Apache::lonwizard::choose_section; + +no strict; +@ISA = ("Apache::lonwizard::choice_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); + return $self; +} + +sub determineChoices { + my %choices; + + my $classlist = Apache::loncoursedata::get_classlist(); + foreach (keys %$classlist) { + my $sectionName = $classlist->{$_}->[5]; + if (!$sectionName) { + $choices{"No section assigned"} = ""; + } else { + $choices{$sectionName} = $sectionName; + } + } + + return \%choices; +} + +1; +
 {$resource->{ID}}) { + $col .= "checked "; + } + $col .= "value='" . $resource->{ID} . "' />