--- loncom/interface/lonhelper.pm 2004/09/24 19:49:12 1.87 +++ loncom/interface/lonhelper.pm 2005/01/10 12:15:23 1.92 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # .helper XML handler to implement the LON-CAPA helper # -# $Id: lonhelper.pm,v 1.87 2004/09/24 19:49:12 matthew Exp $ +# $Id: lonhelper.pm,v 1.92 2005/01/10 12:15:23 foxr Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1267,7 +1267,7 @@ BUTTONS $result .= "<tr>\n<td width='20'> </td>\n"; $result .= "<td valign='top'><input type='$type' name='$var.forminput'" . "' value='" . - HTML::Entities::encode($choice->[1],'<>&"') + HTML::Entities::encode($choice->[1],"<>&\"'") . "'"; if ($checkedChoices{$choice->[1]}) { $result .= " checked "; @@ -1424,7 +1424,7 @@ sub render { $result .= "<select name='${var}.forminput'>\n"; foreach my $choice (@{$self->{CHOICES}}) { $result .= "<option value='" . - HTML::Entities::encode($choice->[1],'<>&"') + HTML::Entities::encode($choice->[1],"<>&\"'") . "'"; if ($checkedChoices{$choice->[1]}) { $result .= " selected"; @@ -1760,7 +1760,7 @@ BEGIN { &Apache::lonhelper::register('Apache::lonhelper::resource', ('resource', 'filterfunc', 'choicefunc', 'valuefunc', - 'mapurl')); + 'mapurl','option')); } sub new { @@ -1865,6 +1865,42 @@ sub start_mapurl { sub end_mapurl { return ''; } + +sub start_option { + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; + if (!defined($paramHash->{OPTION_TEXTS})) { + $paramHash->{OPTION_TEXTS} = [ ]; + $paramHash->{OPTION_VARS} = [ ]; + + } + # OPTION_TEXTS is a list of the text attribute + # values used to create column headings. + # OPTION_VARS is a list of the variable names, used to create the checkbox + # inputs. + # We're ok with empty elements. as place holders + # Although the 'variable' element should really exist. + # + + my $option_texts = $paramHash->{OPTION_TEXTS}; + my $option_vars = $paramHash->{OPTION_VARS}; + push(@$option_texts, $token->[2]{'text'}); + push(@$option_vars, $token->[2]{'variable'}); + + # Need to create and declare the option variables as well to make them + # persistent. + # + my $varname = $token->[2]{'variable'}; + $helper->declareVar($varname); + + + return ''; +} + +sub end_option { + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; + return ''; +} + # A note, in case I don't get to this before I leave. # If someone complains about the "Back" button returning them # to the previous folder state, instead of returning them to @@ -1916,10 +1952,13 @@ BUTTONS $result .= $buttons; - my $filterFunc = $self->{FILTER_FUNC}; - my $choiceFunc = $self->{CHOICE_FUNC}; - my $valueFunc = $self->{VALUE_FUNC}; - my $multichoice = $self->{'multichoice'}; + my $filterFunc = $self->{FILTER_FUNC}; + my $choiceFunc = $self->{CHOICE_FUNC}; + my $valueFunc = $self->{VALUE_FUNC}; + my $multichoice = $self->{'multichoice'}; + my $option_vars = $self->{OPTION_VARS}; + my $option_texts = $self->{OPTION_TEXTS}; + my $headings_done = 0; # Evaluate the map url as needed my $mapUrl; @@ -1937,15 +1976,40 @@ BUTTONS my $checked = 0; my $renderColFunc = sub { my ($resource, $part, $params) = @_; + my $result = ""; + + if(!$headings_done) { + if ($option_texts) { + foreach my $text (@$option_texts) { + $result .= "<th>$text</th>"; + } + } + $result .= "<th>Select</th>"; + $result .= "</tr><tr>"; # Close off the extra row and start a new one. + $headings_done = 1; + } my $inputType; if ($multichoice) { $inputType = 'checkbox'; } else {$inputType = 'radio'; } if (!&$choiceFunc($resource)) { - return '<td> </td>'; + $result .= '<td> </td>'; + return $result; } else { - my $col = "<td><input type='$inputType' name='${var}.forminput' "; + my $col = ""; + my $resource_name = + HTML::Entities::encode(&$valueFunc($resource),"<>&\"'"); + if($option_vars) { + foreach my $option_var (@$option_vars) { + $col .= + "<td align='center'><input type='checkbox' name ='$option_var". + ".forminput' value='". + $resource_name . "' /> </td>"; + } + } + + $col .= "<td align='center'><input type='$inputType' name='${var}.forminput' "; if (!$checked && !$multichoice) { $col .= "checked "; $checked = 1; @@ -1954,10 +2018,8 @@ BUTTONS $col .= "checked "; $checked = 1; } - $col .= "value='" . - HTML::Entities::encode(&$valueFunc($resource),'<>&"') - . "' /></td>"; - return $col; + $col .= "value='" . $resource_name . "' /></td>"; + return $result.$col; } }; @@ -2132,13 +2194,25 @@ SCRIPT $buttons = <<BUTTONS; <br /> -<input type="button" onclick="checkactive()" value="$lt{'ocs'}" /> -<input type="button" onclick="uncheckexpired()" value="$lt{'ues'}" /><br /> -<input type="button" onclick="checkall(true, '$var')" value="$lt{'sas'}" /> -<input type="button" onclick="checkall(false, '$var')" value="$lt{'uas'}" /><br /> -<input type="button" onclick="checksec(true)" value="$lt{'sfsg'}"> -<input type="text" size="5" name="chksec"> -<input type="button" onclick="checksec(false)" value="$lt{'ufsg'}"> +<table> + <tr> + + <td><input type="button" onclick="checkactive()" value="$lt{'ocs'}" /></td> + <td><input type="button" onclick="uncheckexpired()" value="$lt{'ues'}" /><br /></td> + </tr> + <tr> + <td><input type="button" onclick="checkall(true, '$var')" value="$lt{'sas'}" /></td> + <td> <input type="button" onclick="checkall(false, '$var')" value="$lt{'uas'}" /><br /></td> + </tr> + <tr> + <td><input type="button" onclick="checksec(true)" value="$lt{'sfsg'}"></td> + <td><input type="text" size="5" name="chksec"> </td> + </tr> + <tr> + <td><input type="button" onclick="checksec(false)" value="$lt{'ufsg'}"></td> + <td></td> + </tr> +</table> <br /> BUTTONS } @@ -2217,7 +2291,10 @@ BUTTONS $checked = 1; } $result .= - " value='" . HTML::Entities::encode($choice->[0] . ':' . $choice->[2] . ':' . $choice->[1] . ':' . $choice->[3],'<>&"') + " value='" . HTML::Entities::encode($choice->[0] . ':' + .$choice->[2] . ':' + .$choice->[1] . ':' + .$choice->[3], "<>&\"'") . "' /></td><td>" . HTML::Entities::encode($choice->[1],'<>&"') . "</td><td align='center'>" @@ -2533,7 +2610,7 @@ BUTTONS my $id = &new_id(); $result .= '<tr><td align="right"' . " bgcolor='$color'>" . "<input $onclick type='$type' name='" . $var - . ".forminput' ".qq{id="$id"}." value='" . HTML::Entities::encode($fileName,'<>&"'). + . ".forminput' ".qq{id="$id"}." value='" . HTML::Entities::encode($fileName,"<>&\"'"). "'"; if (!$self->{'multichoice'} && $choices == 0) { $result .= ' checked'; @@ -3147,7 +3224,6 @@ sub render { my $res = $navmap->getByMapPc($vars->{RESOURCE_ID}); my $title = $res->compTitle(); $symb = $res->symb(); - $navmap->untieHashes(); $resourceString .= '<li>'.&mt('for the map named [_1]',"<b>$title</b>").'</li>'; $level = 8; $affectedResourceId = $vars->{RESOURCE_ID}; @@ -3157,7 +3233,6 @@ sub render { my $res = $navmap->getById($vars->{RESOURCE_ID}); $symb = $res->symb(); my $title = $res->compTitle(); - $navmap->untieHashes(); $resourceString .= '<li>'.&mt('for the resource named [_1]',"<b>$title</b>").'</li>'; $level = 7; $affectedResourceId = $vars->{RESOURCE_ID}; @@ -3217,7 +3292,7 @@ sub render { $result .= '<li>'.&mt('for section [_1]',"<b>$section</b>").'</li>'; $level -= 3; $result .= "<input type='hidden' name='csec' value='" . - HTML::Entities::encode($section,'<>&"') . "' />\n"; + HTML::Entities::encode($section,"'<>&\"") . "' />\n"; } else { # FIXME: This is probably wasteful! Store the name! my $classlist = Apache::loncoursedata::get_classlist(); @@ -3229,9 +3304,9 @@ sub render { $level -= 6; my ($uname, $udom) = split /:/, $vars->{USER_NAME}; $result .= "<input type='hidden' name='uname' value='". - HTML::Entities::encode($uname,'<>&"') . "' />\n"; + HTML::Entities::encode($uname,"'<>&\"") . "' />\n"; $result .= "<input type='hidden' name='udom' value='". - HTML::Entities::encode($udom,'<>&"') . "' />\n"; + HTML::Entities::encode($udom,"'<>&\"") . "' />\n"; } # Print value