--- loncom/interface/loncommon.pm 2011/12/27 19:47:02 1.1028.2.2
+++ loncom/interface/loncommon.pm 2011/12/20 23:57:51 1.1041
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.1028.2.2 2011/12/27 19:47:02 foxr Exp $
+# $Id: loncommon.pm,v 1.1041 2011/12/20 23:57:51 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -154,8 +154,6 @@ sub ssi_with_retries {
# ----------------------------------------------- Filetypes/Languages/Copyright
my %language;
my %supported_language;
-my %latex_language; # For choosing hyphenation in
-my %latex_language_bykey; # for choosing hyphenation from metadata
my %cprtag;
my %scprtag;
my %fe; my %fd; my %fm;
@@ -188,15 +186,11 @@ BEGIN {
while (my $line = <$fh>) {
next if ($line=~/^\#/);
chomp($line);
- my ($key,$two,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
+ my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$line));
$language{$key}=$val.' - '.$enc;
if ($sup) {
$supported_language{$key}=$sup;
}
- if ($latex) {
- $latex_language_bykey{$key} = $latex;
- $latex_language{$two} = $latex;
- }
}
close($fh);
}
@@ -1192,7 +1186,7 @@ sub help_open_topic {
my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
$text = "" if (not defined $text);
$stayOnPage = 0 if (not defined $stayOnPage);
- $width = 350 if (not defined $width);
+ $width = 500 if (not defined $width);
$height = 400 if (not defined $height);
my $filename = $topic;
$filename =~ s/ /_/g;
@@ -1203,7 +1197,9 @@ sub help_open_topic {
$topic=~s/\W/\_/g;
if (!$stayOnPage) {
- $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
+ $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
+ } elsif ($stayOnPage eq 'popup') {
+ $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
} else {
$link = "/adm/help/${filename}.hlp";
}
@@ -1236,27 +1232,22 @@ sub help_open_topic {
# This is a quicky function for Latex cheatsheet editing, since it
# appears in at least four places
sub helpLatexCheatsheet {
- my ($topic,$text,$not_author) = @_;
+ my ($topic,$text,$not_author,$stayOnPage) = @_;
my $out;
my $addOther = '';
if ($topic) {
- $addOther = ''.&Apache::loncommon::help_open_topic($topic,&mt($text),
- undef, undef, 600).
- ' ';
+ $addOther = ''.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).' ';
}
$out = '' # Start cheatsheet
.$addOther
.''
- .&Apache::loncommon::help_open_topic('Greek_Symbols',&mt('Greek Symbols'),
- undef,undef,600)
+ .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
.' '
- .&Apache::loncommon::help_open_topic('Other_Symbols',&mt('Other Symbols'),
- undef,undef,600)
+ .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
.'';
unless ($not_author) {
$out .= ' '
- .&Apache::loncommon::help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),
- undef,undef,600)
+ .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
.'';
}
$out .= ''; # End cheatsheet
@@ -3236,29 +3227,11 @@ sub languagedescription {
($supported_language{$code}?' ('.&mt('interface available').')':'');
}
-=pod
-
-=item * &plainlanguagedescription
-
-Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
-and the language character encoding (e.g. ISO) separated by a ' - ' string.
-
-=cut
-
sub plainlanguagedescription {
my $code=shift;
return $language{$code};
}
-=pod
-
-=item * &supportedlanguagecode
-
-Returns the supported language code (e.g. sptutf maps to pt) given a language
-code.
-
-=cut
-
sub supportedlanguagecode {
my $code=shift;
return $supported_language{$code};
@@ -3266,35 +3239,6 @@ sub supportedlanguagecode {
=pod
-=item * &latexlanguage()
-
-Given a language key code returns the correspondnig language to use
-to select the correct hyphenation on LaTeX printouts. This is undef if there
-is no supported hyphenation for the language code.
-
-=cut
-
-sub latexlanguage {
- my $code = shift;
- return $latex_language{$code};
-}
-
-=pod
-
-=item * &latexhyphenation()
-
-Same as above but what's supplied is the language as it might be stored
-in the metadata.
-
-=cut
-
-sub latexhyphenation {
- my $key = shift;
- return $latex_language_bykey{$key};
-}
-
-=pod
-
=item * ©rightids()
returns list of all copyrights
@@ -5577,6 +5521,11 @@ span.LC_current_location {
background: $pgbg;
}
+span.LC_current_nav_location {
+ font-weight:bold;
+ background: $sidebg;
+}
+
span.LC_parm_menu_item {
font-size: larger;
}
@@ -6682,6 +6631,53 @@ ul.LC_funclist li {
display: none;
}
+.LCmodal-overlay {
+ position:fixed;
+ top:0;
+ right:0;
+ bottom:0;
+ left:0;
+ height:100%;
+ width:100%;
+ margin:0;
+ padding:0;
+ background:#999;
+ opacity:.75;
+ filter: alpha(opacity=75);
+ -moz-opacity: 0.75;
+ z-index:101;
+}
+
+* html .LCmodal-overlay {
+ position: absolute;
+ height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
+}
+
+.LCmodal-window {
+ position:fixed;
+ top:50%;
+ left:50%;
+ margin:0;
+ padding:0;
+ z-index:102;
+ }
+
+* html .LCmodal-window {
+ position:absolute;
+}
+
+.LCclose-window {
+ position:absolute;
+ width:32px;
+ height:32px;
+ right:8px;
+ top:8px;
+ background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
+ text-indent:-99999px;
+ overflow:hidden;
+ cursor:pointer;
+}
+
END
}
@@ -6740,8 +6736,24 @@ sub headtag {
&& !$args->{'only_body'}
&& !$args->{'frameset'}) {
$result .= &help_menu_js();
+ $result.=&modal_window();
+ $result.=&togglebox_script();
+ $result.=&wishlist_window();
+ $result.=&LCprogressbarUpdate_script();
+ } else {
+ if ($args->{'add_modal'}) {
+ $result.=&modal_window();
+ }
+ if ($args->{'add_wishlist'}) {
+ $result.=&wishlist_window();
+ }
+ if ($args->{'add_togglebox'}) {
+ $result.=&togglebox_script();
+ }
+ if ($args->{'add_progressbar'}) {
+ $result.=&LCprogressbarUpdate_script();
+ }
}
-
if (ref($args->{'redirect'})) {
my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
$url = &Apache::lonenc::check_encrypt($url);
@@ -6866,32 +6878,12 @@ $args - additional optional args support
sub start_page {
my ($title,$head_extra,$args) = @_;
#&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
-#SD
-#I don't see why we copy certain elements of %$args to %head_args
-#head args is passed to headtag() and this routine only reads those
-#keys that are needed. There doesn't happen any writes or any processing
-#of other keys.
-#proposal: just pass $args to headtag instead of \%head_args and delete
-#marked lines
-#<- MARK
- my %head_args;
- foreach my $arg ('redirect','force_register','domain','function',
- 'bgcolor','frameset','no_nav_bar','only_body',
- 'no_auto_mt_title') {
- if (defined($args->{$arg})) {
- $head_args{$arg} = $args->{$arg};
- }
- }
-#MARK ->
$env{'internal.start_page'}++;
my $result;
if (! exists($args->{'skip_phases'}{'head'}) ) {
- $result .=
- &xml_begin() . &headtag($title,$head_extra,\%head_args);
-#replace prev line by
-# &xml_begin() . &headtag($title, $head_extra, $args);
+ $result .= &xml_begin() . &headtag($title, $head_extra, $args);
}
if (! exists($args->{'skip_phases'}{'body'}) ) {
@@ -6957,7 +6949,6 @@ sub end_page {
}
$result .= &Apache::lonxml::xmlend($target,$parser);
}
-
if ($args->{'frameset'}) {
$result .= '';
} else {
@@ -6976,6 +6967,254 @@ sub end_page {
return $result;
}
+sub wishlist_window {
+ return(<<'ENDWISHLIST');
+
+ENDWISHLIST
+}
+
+sub modal_window {
+ return(<<'ENDMODAL');
+
+ENDMODAL
+}
+
+sub modal_link {
+ my ($link,$linktext,$width,$height,$target,$scrolling)=@_;
+ unless ($width) { $width=480; }
+ unless ($height) { $height=400; }
+ unless ($scrolling) { $scrolling='yes'; }
+ return ''.
+ $linktext.'';
+}
+
+sub modal_adhoc_script {
+ my ($funcname,$width,$height,$content)=@_;
+ return (<
+//
+
+ENDADHOC
+}
+
+sub modal_adhoc_inner {
+ my ($funcname,$width,$height,$content)=@_;
+ my $innerwidth=$width-20;
+ $content=&js_ready(
+ &start_page('Dialog',undef,{'only_body'=>1,'add_progressbar'=>1,'bgcolor'=>'#FFFFFF'}).
+ &start_scrollbox($width.'px',$innerwidth.'px',$height.'px').
+ $content.
+ &end_scrollbox().
+ &end_page()
+ );
+ return &modal_adhoc_script($funcname,$width,$height,$content);
+}
+
+sub modal_adhoc_window {
+ my ($funcname,$width,$height,$content,$linktext)=@_;
+ return &modal_adhoc_inner($funcname,$width,$height,$content).
+ "".$linktext."";
+}
+
+sub modal_adhoc_launch {
+ my ($funcname,$width,$height,$content)=@_;
+ return &modal_adhoc_inner($funcname,$width,$height,$content).(<
+//
+
+ENDLAUNCH
+}
+
+sub modal_adhoc_close {
+ return (<
+//
+
+ENDCLOSE
+}
+
+sub togglebox_script {
+ return(<
+//
+
+ENDTOGGLE
+}
+
+sub start_togglebox {
+ my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
+ unless ($heading) { $heading=''; } else { $heading.=' '; }
+ unless ($showtext) { $showtext=&mt('show'); }
+ unless ($hidetext) { $hidetext=&mt('hide'); }
+ unless ($headerbg) { $headerbg='#FFFFFF'; }
+ return &start_data_table().
+ &start_data_table_header_row().
+ ''.$heading.
+ '['.$showtext.'] | '.
+ &end_data_table_header_row().
+ '';
+}
+
+sub end_togglebox {
+ return ' |
'.&end_data_table();
+}
+
+sub LCprogressbar_script {
+ return(<
+//
+
+ENDPROGRESS
+}
+
+sub LCprogressbarUpdate_script {
+ return(<
+.ui-progressbar { position:relative; }
+.pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
+
+
+ENDPROGRESSUPDATE
+}
+
+sub LCprogressbar {
+ my ($r,$mode)=(@_);
+ my $starting=&mt('Starting');
+ my $content=(<
+
+ $starting
+
+
+ENDPROGBAR
+ $content.=&LCprogressbar_script();
+ if ($mode eq 'popup') {
+ $r->print(&modal_adhoc_launch('LCprogwin',500,50,$content));
+ } else {
+ $r->print($content);
+ }
+ $r->rflush();
+}
+
+sub LCprogressbarUpdate {
+ my ($r,$val,$text,$mode)=@_;
+ unless ($val) { $val=0; }
+ if ($val<0) { $val=0; }
+ if ($val>100) { $val=0; }
+ unless ($text) { $text=$val.'%'; }
+ my $function='';
+ if ($mode eq 'popup') { $function='modalWindow.'; }
+ $function.='LCupdateProgress';
+ $text=&js_ready($text);
+ $r->print(<
+//
+
+ENDUPDATE
+ $r->rflush();
+}
+
sub html_encode {
my ($result) = @_;
@@ -7034,7 +7273,7 @@ sub start_scrollbox {
}
sub end_scrollbox {
- return '';
+ return '';
}
sub simple_error_page {
@@ -8313,7 +8552,8 @@ sub get_standard_codeitems {
=item * sorted_slots()
-Sorts an array of slot names in order of slot start time (earliest first).
+Sorts an array of slot names in order of an optional sort key,
+default sort is by slot start time (earliest first).
Inputs:
@@ -8323,15 +8563,16 @@ slotsarr - Reference to array of unsort
slots - Reference to hash of hash, where outer hash keys are slot names.
+sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
+
=back
Returns:
=over 4
-sorted - An array of slot names sorted by the start time of the slot.
-
-=back
+sorted - An array of slot names sorted by a specified sort key
+ (default sort key is start time of the slot).
=back
@@ -8339,13 +8580,16 @@ sorted - An array of slot names sorted
sub sorted_slots {
- my ($slotsarr,$slots) = @_;
+ my ($slotsarr,$slots,$sortkey) = @_;
+ if ($sortkey eq '') {
+ $sortkey = 'starttime';
+ }
my @sorted;
if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
@sorted =
sort {
if (ref($slots->{$a}) && ref($slots->{$b})) {
- return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
+ return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
}
if (ref($slots->{$a})) { return -1;}
if (ref($slots->{$b})) { return 1;}
@@ -8355,6 +8599,131 @@ sub sorted_slots {
return @sorted;
}
+=pod
+
+=item * get_future_slots()
+
+Inputs:
+
+=over 4
+
+cnum - course number
+
+cdom - course domain
+
+now - current UNIX time
+
+symb - optional symb
+
+=back
+
+Returns:
+
+=over 4
+
+sorted_reservable - ref to array of student_schedulable slots currently
+ reservable, ordered by end date of reservation period.
+
+reservable_now - ref to hash of student_schedulable slots currently
+ reservable.
+
+ Keys in inner hash are:
+ (a) symb: either blank or symb to which slot use is restricted.
+ (b) endreserve: end date of reservation period.
+
+sorted_future - ref to array of student_schedulable slots reservable in
+ the future, ordered by start date of reservation period.
+
+future_reservable - ref to hash of student_schedulable slots reservable
+ in the future.
+
+ Keys in inner hash are:
+ (a) symb: either blank or symb to which slot use is restricted.
+ (b) startreserve: start date of reservation period.
+
+=back
+
+=cut
+
+sub get_future_slots {
+ my ($cnum,$cdom,$now,$symb) = @_;
+ my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
+ my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
+ foreach my $slot (keys(%slots)) {
+ next unless($slots{$slot}->{'type'} eq 'schedulable_student');
+ if ($symb) {
+ next if (($slots{$slot}->{'symb'} ne '') &&
+ ($slots{$slot}->{'symb'} ne $symb));
+ }
+ if (($slots{$slot}->{'starttime'} > $now) &&
+ ($slots{$slot}->{'endtime'} > $now)) {
+ if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
+ my $userallowed = 0;
+ if ($slots{$slot}->{'allowedsections'}) {
+ my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
+ if (!defined($env{'request.role.sec'})
+ && grep(/^No section assigned$/,@allowed_sec)) {
+ $userallowed=1;
+ } else {
+ if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
+ $userallowed=1;
+ }
+ }
+ unless ($userallowed) {
+ if (defined($env{'request.course.groups'})) {
+ my @groups = split(/:/,$env{'request.course.groups'});
+ foreach my $group (@groups) {
+ if (grep(/^\Q$group\E$/,@allowed_sec)) {
+ $userallowed=1;
+ last;
+ }
+ }
+ }
+ }
+ }
+ if ($slots{$slot}->{'allowedusers'}) {
+ my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
+ my $user = $env{'user.name'}.':'.$env{'user.domain'};
+ if (grep(/^\Q$user\E$/,@allowed_users)) {
+ $userallowed = 1;
+ }
+ }
+ next unless($userallowed);
+ }
+ my $startreserve = $slots{$slot}->{'startreserve'};
+ my $endreserve = $slots{$slot}->{'endreserve'};
+ my $symb = $slots{$slot}->{'symb'};
+ if (($startreserve < $now) &&
+ (!$endreserve || $endreserve > $now)) {
+ my $lastres = $endreserve;
+ if (!$lastres) {
+ $lastres = $slots{$slot}->{'starttime'};
+ }
+ $reservable_now{$slot} = {
+ symb => $symb,
+ endreserve => $lastres
+ };
+ } elsif (($startreserve > $now) &&
+ (!$endreserve || $endreserve > $startreserve)) {
+ $future_reservable{$slot} = {
+ symb => $symb,
+ startreserve => $startreserve
+ };
+ }
+ }
+ }
+ my @unsorted_reservable = keys(%reservable_now);
+ if (@unsorted_reservable > 0) {
+ @sorted_reservable =
+ &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
+ }
+ my @unsorted_future = keys(%future_reservable);
+ if (@unsorted_future > 0) {
+ @sorted_future =
+ &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
+ }
+ return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
+}
=pod