--- loncom/interface/lonhelper.pm 2004/03/24 22:22:04 1.66 +++ loncom/interface/lonhelper.pm 2004/08/12 07:45:03 1.86 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # .helper XML handler to implement the LON-CAPA helper # -# $Id: lonhelper.pm,v 1.66 2004/03/24 22:22:04 albertel Exp $ +# $Id: lonhelper.pm,v 1.86 2004/08/12 07:45:03 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -263,21 +263,13 @@ sub real_handler { # Send header, don't cache this page - if ($r->header_only) { - if ($ENV{'browser.mathml'}) { - $r->content_type('text/xml; charset=UTF-8'); - } else { - $r->content_type('text/html; charset=UTF-8'); - } - $r->send_http_header; - return OK; - } if ($ENV{'browser.mathml'}) { - $r->content_type('text/xml'); + &Apache::loncommon::content_type($r,'text/xml'); } else { - $r->content_type('text/html'); + &Apache::loncommon::content_type($r,'text/html'); } $r->send_http_header; + return OK if $r->header_only; $r->rflush(); # Discard result, we just want the objects that get created by the @@ -462,11 +454,11 @@ sub _saveVars { my $self = shift; my $result = ""; $result .= '<input type="hidden" name="CURRENT_STATE" value="' . - HTML::Entities::encode($self->{STATE}) . "\" />\n"; + HTML::Entities::encode($self->{STATE},'<>&"') . "\" />\n"; $result .= '<input type="hidden" name="TOKEN" value="' . $self->{TOKEN} . "\" />\n"; $result .= '<input type="hidden" name="RETURN_PAGE" value="' . - HTML::Entities::encode($self->{RETURN_PAGE}) . "\" />\n"; + HTML::Entities::encode($self->{RETURN_PAGE},'<>&"') . "\" />\n"; return $result; } @@ -583,7 +575,7 @@ sub display { } # Phase 4: Display. - my $stateTitle = &mt($state->title()); + my $stateTitle=&mt($state->title()); my $helperTitle = &mt($self->{TITLE}); my $bodytag = &Apache::loncommon::bodytag($helperTitle,'',''); my $previous = HTML::Entities::encode(&mt("<- Previous"), '<>&"'); @@ -998,8 +990,8 @@ sub start_message { return ''; } - $paramHash->{MESSAGE_TEXT} = &Apache::lonxml::get_all_text('/message', - $parser); + $paramHash->{MESSAGE_TEXT} = &mtn(&Apache::lonxml::get_all_text('/message', + $parser)); if (defined($token->[2]{'nextstate'})) { $paramHash->{NEXTSTATE} = $token->[2]{'nextstate'}; @@ -1169,8 +1161,8 @@ sub start_choice { } my $computer = $token->[2]{'computer'}; - my $human = &Apache::lonxml::get_all_text('/choice', - $parser); + my $human = &mt(&Apache::lonxml::get_all_text('/choice', + $parser)); my $nextstate = $token->[2]{'nextstate'}; my $evalFlag = $token->[2]{'eval'}; push @{$paramHash->{CHOICES}}, [$human, $computer, $nextstate, @@ -1206,10 +1198,13 @@ SCRIPT # Only print "select all" and "unselect all" if there are five or # more choices; fewer then that and it looks silly. if ($self->{'multichoice'} && scalar(@{$self->{CHOICES}}) > 4) { + my %lt=&Apache::lonlocal::texthash( + 'sa' => "Select All", + 'ua' => "Unselect All"); $buttons = <<BUTTONS; <br /> -<input type="button" onclick="checkall(true, '$var')" value="Select All" /> -<input type="button" onclick="checkall(false, '$var')" value="Unselect All" /> +<input type="button" onclick="checkall(true, '$var')" value="$lt{'sa'}" /> +<input type="button" onclick="checkall(false, '$var')" value="$lt{'ua'}" /> <br /> BUTTONS } @@ -1264,7 +1259,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 "; @@ -1419,7 +1414,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"; @@ -1893,10 +1888,14 @@ sub render { } </script> SCRIPT + my %lt=&Apache::lonlocal::texthash( + 'sar' => "Select All Resources", + 'uar' => "Unselect All Resources"); + $buttons = <<BUTTONS; <br /> -<input type="button" onclick="checkall(true, '$var')" value="Select All Resources" /> -<input type="button" onclick="checkall(false, '$var')" value="Unselect All Resources" /> +<input type="button" onclick="checkall(true, '$var')" value="$lt{'sar'}" /> +<input type="button" onclick="checkall(false, '$var')" value="$lt{'uar'}" /> <br /> BUTTONS } @@ -1946,7 +1945,7 @@ BUTTONS $checked = 1; } $col .= "value='" . - HTML::Entities::encode(&$valueFunc($resource)) + HTML::Entities::encode(&$valueFunc($resource),'<>&"') . "' /></td>"; return $col; } @@ -2090,7 +2089,9 @@ sub render { for (i=0; i<document.forms.helpform.elements.length; i++) { comp = document.forms.helpform.elements.chksec.value; if (document.forms.helpform.elements[i].value.indexOf(':'+comp+':') != -1) { - document.forms.helpform.elements[i].checked=value; + if (document.forms.helpform.elements[i].value.indexOf(':Active') != -1) { + document.forms.helpform.elements[i].checked=value; + } } } } @@ -2098,22 +2099,36 @@ sub render { for (i=0; i<document.forms.helpform.elements.length; i++) { if (document.forms.helpform.elements[i].value.indexOf(':Active') != -1) { document.forms.helpform.elements[i].checked=true; - } + } + } + } + function uncheckexpired() { + for (i=0; i<document.forms.helpform.elements.length; i++) { + if (document.forms.helpform.elements[i].value.indexOf(':Expired') != -1) { + document.forms.helpform.elements[i].checked=false; + } } } </script> SCRIPT - my $selectAllStudents = &mt('Select All Students'); - my $unselectAllStudents = &mt('Unselect All Students'); + my %lt=&Apache::lonlocal::texthash( + 'ocs' => "Select Only Current Students", + 'ues' => "Unselect Expired Students", + 'sas' => "Select All Students", + 'uas' => "Unselect All Students", + 'sfsg' => "Select Current Students for Section/Group", + 'ufsg' => "Unselect for Section/Group"); + $buttons = <<BUTTONS; <br /> -<input type="button" onclick="checkactive()" value="Select Only Current Students" /> -<input type="button" onclick="checkall(true, '$var')" value="$selectAllStudents" /> -<input type="button" onclick="checkall(false, '$var')" value="$unselectAllStudents" /> -<input type="button" onclick="checksec(true)" value="Select for Section/Group"> +<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="Unselect for Section/Group"> +<input type="button" onclick="checksec(false)" value="$lt{'ufsg'}"> <br /> BUTTONS } @@ -2172,15 +2187,15 @@ BUTTONS } } - my $name = &mt($self->{'coursepersonnel'} ? 'Name' : 'Student Name'); + my $name = $self->{'coursepersonnel'} ? &mt('Name') : &mt('Student Name'); 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>$name</b></td>". "<td align='center'><b>" . &mt('Section') . "</b></td>" . - "<td align='center'><b>Status</b></td>" . - "<td align='center'><b>" . &mt("Role") . "</b></td></tr>" . - "<td align='center'><b>Username:Domain</b></td></tr>"; + "<td align='center'><b>".&mt('Status')."</b></td>" . + "<td align='center'><b>" . &mt("Role") . "</b></td>" . + "<td align='center'><b>".&mt('Username').":".&mt('Domain')."</b></td></tr>"; my $checked = 0; for my $choice (@$choices) { @@ -2192,17 +2207,17 @@ 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]) + . HTML::Entities::encode($choice->[1],'<>&"') . "</td><td align='center'>" - . HTML::Entities::encode($choice->[2]) + . HTML::Entities::encode($choice->[2],'<>&"') . "</td>\n<td>" - . HTML::Entities::encode($choice->[3]) + . HTML::Entities::encode($choice->[3],'<>&"') . "</td>\n<td>" - . HTML::Entities::encode($choice->[4]) + . HTML::Entities::encode($choice->[4],'<>&"') . "</td>\n<td>" - . HTML::Entities::encode($choice->[0]) + . HTML::Entities::encode($choice->[0],'<>&"') . "</td></tr>\n"; } @@ -2403,20 +2418,22 @@ sub render { } </script> SCRIPT - my $selectAllFiles = &mt("Select All Files"); - my $unselectAllFiles = &mt("Unselect All Files"); - $buttons = <<BUTTONS; + my %lt=&Apache::lonlocal::texthash( + 'saf' => "Select All Files", + 'uaf' => "Unselect All Files"); + $buttons = <<BUTTONS; <br /> -<input type="button" onclick="checkall(true, '$var')" value="$selectAllFiles" /> -<input type="button" onclick="checkall(false, '$var')" value="$unselectAllFiles" /> +<input type="button" onclick="checkall(true, '$var')" value="$lt{'saf'}" /> +<input type="button" onclick="checkall(false, '$var')" value="$lt{'uaf'}" /> BUTTONS - my $selectAllPublished = &mt("Select All Published"); - my $unselectAllPublished= &mt("UnselectAllPublished"); + %lt=&Apache::lonlocal::texthash( + 'sap' => "Select All Published", + 'uap' => "Unselect All Published"); if ($helper->{VARS}->{'construction'}) { - $buttons .= <<BUTTONS; -<input type="button" onclick="checkallclass(true, 'Published')" value="$selectAllPublished" /> -<input type="button" onclick="checkallclass(false, 'Published')" value="$unselectAllPublished" /> + $buttons .= <<BUTTONS; +<input type="button" onclick="checkallclass(true, 'Published')" value="$lt{'sap'}" /> +<input type="button" onclick="checkallclass(false, 'Published')" value="$lt{'uap'}" /> <br /> BUTTONS } @@ -2444,7 +2461,7 @@ BUTTONS } # Sort the fileList into order - @fileList = sort @fileList; + @fileList = sort {lc($a) cmp lc($b)} @fileList; $result .= $buttons; @@ -2498,7 +2515,7 @@ BUTTONS } $result .= '<tr><td align="right"' . " bgcolor='$color'>" . "<input $onclick type='$type' name='" . $var - . ".forminput' value='" . HTML::Entities::encode($fileName) . + . ".forminput' value='" . HTML::Entities::encode($fileName,'<>&"'). "'"; if (!$self->{'multichoice'} && $choices == 0) { $result .= ' checked'; @@ -2531,10 +2548,14 @@ sub fileState { my $constructionSpaceDir = shift; my $file = shift; + my ($uname,$udom)=($ENV{'user.name'},$ENV{'user.domain'}); + if ($ENV{'request.role'}=~/^ca\./) { + (undef,$udom,$uname)=split(/\//,$ENV{'request.role'}); + } my $docroot = $Apache::lonnet::perlvar{'lonDocRoot'}; my $subdirpart = $constructionSpaceDir; - $subdirpart =~ s/^\/home\/$ENV{'user.name'}\/public_html//; - my $resdir = $docroot . '/res/' . $ENV{'user.domain'} . '/' . $ENV{'user.name'} . + $subdirpart =~ s/^\/home\/$uname\/public_html//; + my $resdir = $docroot . '/res/' . $udom . '/' . $uname . $subdirpart; my @constructionSpaceFileStat = stat($constructionSpaceDir . '/' . $file); @@ -2663,6 +2684,7 @@ string honors the validation function, i no strict; @ISA = ("Apache::lonhelper::element"); use strict; +use Apache::lonlocal; BEGIN { &Apache::lonhelper::register('Apache::lonhelper::string', @@ -2781,6 +2803,8 @@ be able to call methods on it. =cut +use Apache::lonlocal; + BEGIN { &Apache::lonhelper::register('Apache::lonhelper::general', 'exec', 'condition', 'clause', @@ -3042,6 +3066,7 @@ package Apache::lonhelper::parmwizfinal; no strict; @ISA = ('Apache::lonhelper::element'); use strict; +use Apache::lonlocal; BEGIN { &Apache::lonhelper::register('Apache::lonhelper::parmwizfinal', @@ -3093,7 +3118,7 @@ sub render { # Print the granularity, depending on the action if ($vars->{GRANULARITY} eq 'whole_course') { - $resourceString .= '<li>for <b>all resources in the course</b></li>'; + $resourceString .= '<li>'.&mt('for <b>all resources in the course</b>').'</li>'; $level = 9; # general course, see lonparmset.pm perldoc $affectedResourceId = "0.0"; $symb = 'a'; @@ -3104,7 +3129,7 @@ sub render { my $title = $res->compTitle(); $symb = $res->symb(); $navmap->untieHashes(); - $resourceString .= "<li>for the map named <b>$title</b></li>"; + $resourceString .= '<li>'.&mt('for the map named [_1]',"<b>$title</b>").'</li>'; $level = 8; $affectedResourceId = $vars->{RESOURCE_ID}; $paramlevel = 'map'; @@ -3114,22 +3139,29 @@ sub render { $symb = $res->symb(); my $title = $res->compTitle(); $navmap->untieHashes(); - $resourceString .= "<li>for the resource named <b>$title</b></li>"; + $resourceString .= '<li>'.&mt('for the resource named [_1]',"<b>$title</b>").'</li>'; $level = 7; $affectedResourceId = $vars->{RESOURCE_ID}; $paramlevel = 'full'; } my $result = "<form name='helpform' method='get' action='/adm/parmset#$affectedResourceId&$parm_name&$level'>\n"; - $result .= '<p>Confirm that this information is correct, then click "Finish Helper" to complete setting the parameter.<ul>'; + $result .= '<p>'.&mt('Confirm that this information is correct, then click "Finish Helper" to complete setting the parameter.').'<ul>'; # Print the type of manipulation: - $result .= '<li>Setting the <b>' . $dateTypeHash{$vars->{ACTION_TYPE}} . '</b>'; + my $extra; if ($vars->{ACTION_TYPE} eq 'tries') { - $result .= ' to <b>' . $vars->{TRIES} . '</b>'; + $extra = $vars->{TRIES}; } if ($vars->{ACTION_TYPE} eq 'weight') { - $result .= ' to <b>' . $vars->{WEIGHT} . '</b>'; + $extra = $vars->{WEIGHT}; + } + $result .= "<li>"; + my $what = &mt($dateTypeHash{$vars->{ACTION_TYPE}}); + if ($extra) { + $result .= &mt('Setting the [_1] to [_2]',"<b>$what</b>",$extra); + } else { + $result .= &mt('Setting the [_1]',"<b>$what</b>"); } $result .= "</li>\n"; if ($vars->{ACTION_TYPE} eq 'due_date' || @@ -3160,13 +3192,13 @@ sub render { # Print targets if ($vars->{TARGETS} eq 'course') { - $result .= '<li>for <b>all students in course</b></li>'; + $result .= '<li>'.&mt('for <b>all students in course</b>').'</li>'; } elsif ($vars->{TARGETS} eq 'section') { my $section = $vars->{SECTION_NAME}; - $result .= "<li>for section <b>$section</b></li>"; + $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(); @@ -3174,20 +3206,18 @@ sub render { # Chop off everything after the last colon (section) $username = substr($username, 0, rindex($username, ':')); my $name = $classlist->{$username}->[6]; - $result .= "<li>for <b>$name</b></li>"; + $result .= '<li>'.&mt('for [_1]',"<b>$name</b>").'</li>'; $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 if ($vars->{ACTION_TYPE} ne 'tries' && $vars->{ACTION_TYPE} ne 'weight') { - $result .= "<li>to <b>" . ctime($vars->{PARM_DATE}) . "</b> (" . - Apache::lonnavmaps::timeToHumanString($vars->{PARM_DATE}) - . ")</li>\n"; + $result .= '<li>'.&mt('to [_1] ([_2])',"<b>".ctime($vars->{PARM_DATE})."</b>",Apache::lonnavmaps::timeToHumanString($vars->{PARM_DATE}))."</li>\n"; } # print pres_marker @@ -3200,7 +3230,7 @@ sub render { $result .= "\n<input type='hidden' value='$symb' name='pssymb' />"; $result .= "\n<input type='hidden' value='$paramlevel' name='parmlev' />"; - $result .= "<br /><br /><center><input type='submit' value='Finish Helper' /></center></form>\n"; + $result .= "<br /><br /><center><input type='submit' value='".&mt('Finish Helper')."' /></center></form>\n"; return $result; }