version 1.125, 2005/10/17 20:21:31
|
version 1.135, 2006/03/19 23:09:20
|
Line 573 sub display {
|
Line 573 sub display {
|
} |
} |
|
|
# Phase 4: Display. |
# Phase 4: Display. |
my $html=&Apache::lonxml::xmlbegin(); |
|
my $stateTitle=&mt($state->title()); |
my $stateTitle=&mt($state->title()); |
my $helperTitle = &mt($self->{TITLE}); |
my $browser_searcher_js = |
my $bodytag = &Apache::loncommon::bodytag($helperTitle,'',''); |
'<script type="text/javascript">'."\n". |
|
&Apache::loncommon::browser_and_searcher_javascript(). |
|
"\n".'</script>'; |
|
|
|
$result .= &Apache::loncommon::start_page($self->{TITLE}, |
|
$browser_searcher_js); |
|
|
my $previous = HTML::Entities::encode(&mt("<- Previous"), '<>&"'); |
my $previous = HTML::Entities::encode(&mt("<- Previous"), '<>&"'); |
my $next = HTML::Entities::encode(&mt("Next ->"), '<>&"'); |
my $next = HTML::Entities::encode(&mt("Next ->"), '<>&"'); |
# FIXME: This should be parameterized, not concatenated - Jeremy |
# FIXME: This should be parameterized, not concatenated - Jeremy |
my $loncapaHelper = &mt("LON-CAPA Helper:"); |
|
|
|
$result .= <<HEADER; |
|
$html |
|
<head> |
|
<title>$loncapaHelper: $helperTitle</title> |
|
</head> |
|
$bodytag |
|
HEADER |
|
if (!$state->overrideForm()) { $result.="<form name='helpform' method='POST'>"; } |
if (!$state->overrideForm()) { $result.="<form name='helpform' method='POST'>"; } |
$result .= <<HEADER; |
$result .= <<HEADER; |
<table border="0" width='100%'><tr><td> |
<table border="0" width='100%'><tr><td> |
Line 651 HEADER
|
Line 649 HEADER
|
</tr> |
</tr> |
</table> |
</table> |
</form> |
</form> |
</body> |
|
</html> |
|
FOOTER |
FOOTER |
|
|
|
$result .= &Apache::loncommon::end_page(); |
# Handle writing out the vars to the file |
# Handle writing out the vars to the file |
my $file = Apache::File->new('>'.$self->{FILENAME}); |
my $file = Apache::File->new('>'.$self->{FILENAME}); |
print $file $self->_varsInFile(); |
print $file $self->_varsInFile(); |
Line 1557 sub render {
|
Line 1554 sub render {
|
my $date; |
my $date; |
|
|
my $time=time; |
my $time=time; |
|
$date = localtime($time); |
|
$date->min(0); |
my ($anytime,$onclick); |
my ($anytime,$onclick); |
|
|
if (defined($self->{DEFAULT_VALUE})) { |
if (defined($self->{DEFAULT_VALUE})) { |
Line 1564 sub render {
|
Line 1563 sub render {
|
die('Error in default value code for variable ' . |
die('Error in default value code for variable ' . |
$self->{'variable'} . ', Perl said: ' . $@) if $@; |
$self->{'variable'} . ', Perl said: ' . $@) if $@; |
$time = &$valueFunc($helper, $self); |
$time = &$valueFunc($helper, $self); |
if (lc($time) eq 'anytime') { $time=time; $anytime=1; } |
if (lc($time) eq 'anytime') { |
|
$anytime=1; |
|
} else { |
|
$date = localtime($time); |
|
} |
|
} else { |
|
|
} |
} |
if ($anytime) { |
if ($anytime) { |
$onclick = "onclick=\"javascript:updateCheck(this.form,'${var}anytime',false)\""; |
$onclick = "onclick=\"javascript:updateCheck(this.form,'${var}anytime',false)\""; |
} |
} |
# Default date: The current hour. |
# Default date: The current hour. |
$date = localtime($time); |
|
$date->min(0); |
|
|
|
if (defined $self->{ERROR_MSG}) { |
if (defined $self->{ERROR_MSG}) { |
$result .= '<font color="#FF0000">' . $self->{ERROR_MSG} . '</font><br /><br />'; |
$result .= '<font color="#FF0000">' . $self->{ERROR_MSG} . '</font><br /><br />'; |
Line 2296 sub render {
|
Line 2299 sub render {
|
} |
} |
} |
} |
} |
} |
|
function checkexpired() { |
|
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=true; |
|
} |
|
} |
|
} |
function uncheckexpired() { |
function uncheckexpired() { |
for (i=0; i<document.forms.helpform.elements.length; i++) { |
for (i=0; i<document.forms.helpform.elements.length; i++) { |
if (document.forms.helpform.elements[i].value.indexOf(':Expired') != -1) { |
if (document.forms.helpform.elements[i].value.indexOf(':Expired') != -1) { |
Line 2364 SCRIPT
|
Line 2374 SCRIPT
|
</table> |
</table> |
<br /> |
<br /> |
BUTTONS |
BUTTONS |
|
$result .= $buttons; |
|
|
} |
} |
|
|
if (defined $self->{ERROR_MSG}) { |
if (defined $self->{ERROR_MSG}) { |
$result .= '<font color="#FF0000">' . $self->{ERROR_MSG} . '</font><br /><br />'; |
$result .= '<font color="#FF0000">' . $self->{ERROR_MSG} . '</font><br /><br />'; |
} |
} |
|
|
|
my %defaultUsers; |
|
if (defined($self->{DEFAULT_VALUE})) { |
|
my $valueFunc = eval($self->{DEFAULT_VALUE}); |
|
die 'Error in default value code for variable ' . |
|
$self->{'variable'} . ', Perl said: ' . $@ if $@; |
|
my @defaultUsers = &$valueFunc($helper, $self); |
|
if (!$self->{'multichoice'} && @defaultUsers) { # only allowed 1 |
|
@defaultUsers = ($defaultUsers[0]); |
|
} |
|
%defaultUsers = map { if ($_) {($_,1) } } @defaultUsers; |
|
delete($defaultUsers{''}); |
|
} |
my $choices = []; |
my $choices = []; |
|
my $expired_students = []; # Will hold expired students. |
|
|
# Load up the non-students, if necessary |
# Load up the non-students, if necessary |
if ($self->{'coursepersonnel'}) { |
if ($self->{'coursepersonnel'}) { |
Line 2408 BUTTONS
|
Line 2433 BUTTONS
|
} |
} |
return $classlist->{$a}->[$fullname] cmp $classlist->{$b}->[$fullname]; |
return $classlist->{$a}->[$fullname] cmp $classlist->{$b}->[$fullname]; |
} @keys; |
} @keys; |
|
# |
|
# now add the fancy section choice... first enumerate the sections: |
|
if ($self->{'multichoice'}) { |
|
my %sections; |
|
for my $key (@keys) { |
|
my $section_name = $classlist->{$key}->[$section]; |
|
if ($section_name ne "") { |
|
$sections{$section_name} = 1; |
|
} |
|
} |
|
# The variable $choice_widget will have the html to make the choice |
|
# selector. |
|
my $size=5; |
|
if (scalar(keys(%sections)) < 5) { |
|
$size=scalar(keys(%sections)); |
|
} |
|
my $choice_widget = '<select multiple name="chosensections" size="'.$size.'">'."\n"; |
|
foreach my $sec (sort {lc($a) cmp lc($b)} (keys(%sections))) { |
|
$choice_widget .= "<option name=\"$sec\">$sec</option>\n"; |
|
} |
|
$choice_widget .= "<option>none</option></select>\n"; |
|
|
|
# Build a table without any borders to contain the section based |
|
# selection: |
|
|
|
my $section_selectors =<<SECTIONSELECT; |
|
<table border="0"> |
|
<tr valign="top"> |
|
<td>For Sections:</td><td>$choice_widget</td> |
|
<td><label><input type="radio" name="personstate" value="Active" checked /> |
|
Current Students</label></td> |
|
<td><label><input type="radio" name="personstate" value="All" /> |
|
All students</label></td> |
|
<td><label><input type="radio" name="personstate" value="Expired" /> |
|
Expired Students</label></td> |
|
</tr> |
|
<tr> |
|
<td><input type="button" value="Select" onclick="checksections(true);" /></td> |
|
<td><input type="button" value="Unselect" onclick="checksections(false);" /></td></tr> |
|
</table> |
|
<br /> |
|
SECTIONSELECT |
|
$result .= $section_selectors; |
|
} |
|
|
# username, fullname, section, type |
# username, fullname, section, type |
for (@keys) { |
for (@keys) { |
# Filter out inactive students if we've set "activeonly" |
|
if (!$self->{'activeonly'} || $classlist->{$_}->[$status] eq |
# We split the active students into the choices array and |
|
# inactive ones into expired_students so that we can put them in 2 separate |
|
# tables. |
|
|
|
if ( $classlist->{$_}->[$status] eq |
'Active') { |
'Active') { |
push @$choices, [$_, $classlist->{$_}->[$fullname], |
push @$choices, [$_, $classlist->{$_}->[$fullname], |
$classlist->{$_}->[$section], |
$classlist->{$_}->[$section], |
$classlist->{$_}->[$status], 'Student']; |
$classlist->{$_}->[$status], 'Student']; |
|
} else { |
|
push @$expired_students, [$_, $classlist->{$_}->[$fullname], |
|
$classlist->{$_}->[$section], |
|
$classlist->{$_}->[$status], 'Student']; |
} |
} |
} |
} |
|
|
Line 2431 BUTTONS
|
Line 2508 BUTTONS
|
"<td align='center'><b>".&mt('Username').":".&mt('Domain')."</b></td></tr>"; |
"<td align='center'><b>".&mt('Username').":".&mt('Domain')."</b></td></tr>"; |
|
|
my $checked = 0; |
my $checked = 0; |
|
# |
|
# Give the active students and staff: |
|
# |
for my $choice (@$choices) { |
for my $choice (@$choices) { |
$result .= "<tr><td><input type='$type' name='" . |
$result .= "<tr><td><input type='$type' name='" . |
$self->{'variable'} . '.forminput' . "'"; |
$self->{'variable'} . '.forminput' . "'"; |
|
|
if (!$self->{'multichoice'} && !$checked) { |
if (%defaultUsers) { |
|
my $user=$choice->[0]; |
|
if (exists($defaultUsers{$user})) { |
|
$result .= " checked='checked' "; |
|
$checked = 1; |
|
} |
|
} elsif (!$self->{'multichoice'} && !$checked) { |
$result .= " checked='checked' "; |
$result .= " checked='checked' "; |
$checked = 1; |
$checked = 1; |
} |
} |
Line 2456 BUTTONS
|
Line 2542 BUTTONS
|
. HTML::Entities::encode($choice->[0],'<>&"') |
. HTML::Entities::encode($choice->[0],'<>&"') |
. "</td></tr>\n"; |
. "</td></tr>\n"; |
} |
} |
|
|
$result .= "</table>\n\n"; |
$result .= "</table>\n\n"; |
$result .= $buttons; |
|
|
# If activeonly is not set then we can also give the expired students: |
# |
# |
# now add the fancy section choice... first enumerate the sections: |
if (!$self->{'activeonly'} && ((scalar @$expired_students) > 0)) { |
if ($self->{'multichoice'}) { |
$result .= "<p>Inactive students: </p>\n"; |
my %sections; |
$result .= <<INACTIVEBUTTONS; |
for my $key (@keys) { |
<table> |
my $section_name = $classlist->{$key}->[$section]; |
<tr> |
if ($section_name ne "") { |
<td><input type="button" value="Select expired" onclick="checkexpired();" /> </td> |
$sections{$section_name} = 1; |
<td><input type="button" value="Unselect expired" onclick="uncheckexpired();" /></td> |
|
</tr> |
|
</table> |
|
INACTIVEBUTTONS |
|
$result .= "<table>\n"; |
|
|
|
for my $choice (@$expired_students) { |
|
$result .= "<tr><td><input type='$type' name='" . |
|
$self->{'variable'} . '.forminput' . "'"; |
|
|
|
if (%defaultUsers) { |
|
my $user=$choice->[0]; |
|
if (exists($defaultUsers{$user})) { |
|
$result .= " checked='checked' "; |
|
$checked = 1; |
} |
} |
|
} elsif (!$self->{'multichoice'} && !$checked) { |
|
$result .= " checked='checked' "; |
|
$checked = 1; |
|
} |
|
$result .= |
|
" value='" . HTML::Entities::encode($choice->[0] . ':' |
|
.$choice->[2] . ':' |
|
.$choice->[1] . ':' |
|
.$choice->[3], "<>&\"'") |
|
. "' /></td><td>" |
|
. HTML::Entities::encode($choice->[1],'<>&"') |
|
. "</td><td align='center'>" |
|
. HTML::Entities::encode($choice->[2],'<>&"') |
|
. "</td>\n<td>" |
|
. HTML::Entities::encode($choice->[3],'<>&"') |
|
. "</td>\n<td>" |
|
. HTML::Entities::encode($choice->[4],'<>&"') |
|
. "</td>\n<td>" |
|
. HTML::Entities::encode($choice->[0],'<>&"') |
|
. "</td></tr>\n"; |
} |
} |
# The variable $choice_widget will have the html to make the choice |
$result .= "</table>\n"; |
# selector. |
|
my $size=5; |
} |
if (scalar(keys(%sections)) < 5) { |
|
$size=scalar(keys(%sections)); |
|
} |
|
my $choice_widget = '<select multiple name="chosensections" size="'.$size.'">'."\n"; |
|
foreach my $sec (sort {lc($a) cmp lc($b)} (keys(%sections))) { |
|
$choice_widget .= "<option name=\"$sec\">$sec</option>\n"; |
|
} |
|
$choice_widget .= "<option>none</option></select>\n"; |
|
|
|
# Build a table without any borders to contain the section based |
|
# selection: |
|
|
|
my $section_selectors =<<SECTIONSELECT; |
|
<table border="0"> |
|
<tr valign="top"> |
|
<td>For Sections:</td><td>$choice_widget</td> |
|
<td><label><input type="radio" name="personstate" value="Active" checked /> |
|
Current Students</label></td> |
|
<td><label><input type="radio" name="personstate" value="All" /> |
|
All students</label></td> |
|
<td><label><input type="radio" name="personstate" value="Expired" /> |
|
Expired Students</label></td> |
|
</tr> |
|
<tr> |
|
<td><input type="button" value="Select" onclick="checksections(true);" /></td> |
|
<td><input type="button" value="Unselect" onclick="checksections(false);" /></td></tr> |
|
</table> |
|
<br /> |
|
SECTIONSELECT |
|
$result .= $section_selectors; |
|
} |
|
return $result; |
return $result; |
} |
} |
|
|
Line 2897 package Apache::lonhelper::section;
|
Line 2989 package Apache::lonhelper::section;
|
<section> allows the user to choose one or more sections from the current |
<section> allows the user to choose one or more sections from the current |
course. |
course. |
|
|
It takes the standard attributes "variable", "multichoice", and |
It takes the standard attributes "variable", "multichoice", |
"nextstate", meaning what they do for most other elements. |
"allowempty" and "nextstate", meaning what they do for most other |
|
elements. |
|
|
|
also takes a boolean 'onlysections' whcih will restrict this to only |
|
have sections and not include groups |
|
|
=cut |
=cut |
|
|
Line 2928 sub start_section {
|
Line 3024 sub start_section {
|
$paramHash->{'variable'} = $token->[2]{'variable'}; |
$paramHash->{'variable'} = $token->[2]{'variable'}; |
$helper->declareVar($paramHash->{'variable'}); |
$helper->declareVar($paramHash->{'variable'}); |
$paramHash->{'multichoice'} = $token->[2]{'multichoice'}; |
$paramHash->{'multichoice'} = $token->[2]{'multichoice'}; |
|
$paramHash->{'allowempty'} = $token->[2]{'allowempty'}; |
if (defined($token->[2]{'nextstate'})) { |
if (defined($token->[2]{'nextstate'})) { |
$paramHash->{NEXTSTATE} = $token->[2]{'nextstate'}; |
$paramHash->{NEXTSTATE} = $token->[2]{'nextstate'}; |
} |
} |
Line 2947 sub start_section {
|
Line 3044 sub start_section {
|
} |
} |
|
|
for my $sectionName (sort(keys(%choices))) { |
for my $sectionName (sort(keys(%choices))) { |
|
push @{$paramHash->{CHOICES}}, [$sectionName, $sectionName]; |
push @{$paramHash->{CHOICES}}, [$sectionName, $sectionName]; |
} |
|
return if ($token->[2]{'onlysections'}); |
|
|
|
# add in groups to the end of the list |
|
my %curr_groups; |
|
if (&Apache::loncommon::coursegroups(\%curr_groups)) { |
|
foreach my $group_name (sort(keys(%curr_groups))) { |
|
push(@{$paramHash->{CHOICES}}, [$group_name, $group_name]); |
|
} |
} |
} |
} |
} |
|
|
Line 2962 sub end_section {
|
Line 3067 sub end_section {
|
} |
} |
1; |
1; |
|
|
|
package Apache::lonhelper::group; |
|
|
|
=pod |
|
|
|
=head2 Element: groupX<group, helper element> |
|
|
|
<group> allows the user to choose one or more groups from the current course. |
|
|
|
It takes the standard attributes "variable", "multichoice", |
|
"allowempty" and "nextstate", meaning what they do for most other |
|
elements. |
|
|
|
=cut |
|
|
|
no strict; |
|
@ISA = ("Apache::lonhelper::choices"); |
|
use strict; |
|
|
|
BEGIN { |
|
&Apache::lonhelper::register('Apache::lonhelper::group', |
|
('group')); |
|
} |
|
|
|
sub new { |
|
my $ref = Apache::lonhelper::choices->new(); |
|
bless($ref); |
|
} |
|
|
|
sub start_group { |
|
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
|
|
|
if ($target ne 'helper') { |
|
return ''; |
|
} |
|
|
|
$paramHash->{CHOICES} = []; |
|
|
|
$paramHash->{'variable'} = $token->[2]{'variable'}; |
|
$helper->declareVar($paramHash->{'variable'}); |
|
$paramHash->{'multichoice'} = $token->[2]{'multichoice'}; |
|
$paramHash->{'allowempty'} = $token->[2]{'allowempty'}; |
|
if (defined($token->[2]{'nextstate'})) { |
|
$paramHash->{NEXTSTATE} = $token->[2]{'nextstate'}; |
|
} |
|
|
|
# Populate the CHOICES element |
|
my %choices; |
|
|
|
my %curr_groups; |
|
if (&Apache::loncommon::coursegroups(\%curr_groups)) { |
|
foreach my $group_name (sort(keys(%curr_groups))) { |
|
push(@{$paramHash->{CHOICES}}, [$group_name, $group_name]); |
|
} |
|
} |
|
} |
|
|
|
sub end_group { |
|
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
|
|
|
if ($target ne 'helper') { |
|
return ''; |
|
} |
|
Apache::lonhelper::group->new(); |
|
} |
|
1; |
|
|
package Apache::lonhelper::string; |
package Apache::lonhelper::string; |
|
|
=pod |
=pod |
Line 3343 sub render {
|
Line 3514 sub render {
|
} |
} |
my $previous = HTML::Entities::encode(&mt("<- Previous"), '<>&"'); |
my $previous = HTML::Entities::encode(&mt("<- Previous"), '<>&"'); |
my $next = HTML::Entities::encode(&mt("Next ->"), '<>&"'); |
my $next = HTML::Entities::encode(&mt("Next ->"), '<>&"'); |
|
my $target = " target='loncapaclient'"; |
|
if (($env{'browser.interface'} eq 'textual') || |
|
($env{'environment.remote'} eq 'off')) { $target=''; } |
$result .= "<center>\n" . |
$result .= "<center>\n" . |
"<form action='".$actionURL."' method='post' target='loncapaclient'>\n" . |
"<form action='".$actionURL."' method='post' $target>\n" . |
"<input type='button' onclick='history.go(-1)' value='$previous' />" . |
"<input type='button' onclick='history.go(-1)' value='$previous' />" . |
"<input type='hidden' name='orgurl' value='$targetURL' />" . |
"<input type='hidden' name='orgurl' value='$targetURL' />" . |
"<input type='hidden' name='selectrole' value='1' />\n" . |
"<input type='hidden' name='selectrole' value='1' />\n" . |
Line 3545 sub render {
|
Line 3719 sub render {
|
$result .= '<li>'.&mt('for section [_1]',"<b>$section</b>").'</li>'; |
$result .= '<li>'.&mt('for section [_1]',"<b>$section</b>").'</li>'; |
$result .= "<input type='hidden' name='csec' value='" . |
$result .= "<input type='hidden' name='csec' value='" . |
HTML::Entities::encode($section,"'<>&\"") . "' />\n"; |
HTML::Entities::encode($section,"'<>&\"") . "' />\n"; |
|
} elsif ($vars->{TARGETS} eq 'group') { |
|
my $group = $vars->{GROUP_NAME}; |
|
$result .= '<li>'.&mt('for group [_1]',"<b>$group</b>").'</li>'; |
|
$result .= "<input type='hidden' name='cgroup' value='" . |
|
HTML::Entities::encode($group,"'<>&\"") . "' />\n"; |
} else { |
} else { |
# FIXME: This is probably wasteful! Store the name! |
# FIXME: This is probably wasteful! Store the name! |
my $classlist = Apache::loncoursedata::get_classlist(); |
my $classlist = Apache::loncoursedata::get_classlist(); |