--- loncom/interface/loncommon.pm 2007/08/30 16:03:29 1.573 +++ loncom/interface/loncommon.pm 2008/03/06 21:42:51 1.645 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common routines # -# $Id: loncommon.pm,v 1.573 2007/08/30 16:03:29 raeburn Exp $ +# $Id: loncommon.pm,v 1.645 2008/03/06 21:42:51 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -78,6 +78,58 @@ my $readit; ## Global Variables ## + +# ----------------------------------------------- SSI with retries: +# + +=pod + +=head1 Server Side incliude with retries: + +=over 4 + +=item * ssi_with_retries(resource, retries form) + +Performs an ssi with some number of retries. Retries continue either +until the result is ok or until the retry count supplied by the +caller is exhausted. + +Inputs: +resource - Identifies the resource to insert. +retries - Count of the number of retries allowed. +form - Hash that identifies the rendering options. + +Returns: +content - The content of the response. If retries were exhausted this is empty. +response - The response from the last attempt (which may or may not have been successful. + +=cut + +sub ssi_with_retries { + my ($resource, $retries, %form) = @_; + + + my $ok = 0; # True if we got a good response. + my $content; + my $response; + + # Try to get the ssi done. within the retries count: + + do { + ($content, $response) = &Apache::lonnet::ssi($resource, %form); + $ok = $response->is_success; + $retries--; + } while (!$ok && ($retries > 0)); + + if (!$ok) { + $content = ''; # On error return an empty content. + } + return ($content, $response); + +} + + + # ----------------------------------------------- Filetypes/Languages/Copyright my %language; my %supported_language; @@ -257,6 +309,7 @@ sub browser_and_searcher_javascript { } url += 'catalogmode=interactive&'; url += 'mode=$mode&'; + url += 'inhibitmenu=yes&'; url += 'form=' + formname + '&'; if (only != null) { url += 'only=' + only + '&'; @@ -367,7 +420,7 @@ sub selectstudent_link { return ''; } return "".&mt('Select User').""; + '","'.$udomele.'");'."'>".&mt('Select User').""; } if ($env{'request.role'}=~/^(au|dc|su)/) { return " menus. The select menus will be linked in that changing the value of the first menu will result in new values being placed in the second menu. The values in the select menu will appear in alphabetical -order. +order unless a defined order is provided. linked_select_forms takes the following ordered inputs: @@ -562,6 +618,8 @@ linked_select_forms takes the following =item * $hashref, a reference to a hash containing the data for the menus. +=item * $menuorder, the order of values in the first menu + =back Below is an example of such a hash. Only the 'text', 'default', and @@ -578,7 +636,8 @@ $menu{$choice1}->{'select2'}. B2 => "Choice B2", B3 => "Choice B3", B4 => "Choice B4" - } + }, + order => ['B4','B3','B1','B2'], }, A2 => { text =>"Choice A2" , default => "C2", @@ -586,7 +645,8 @@ $menu{$choice1}->{'select2'}. C1 => "Choice C1", C2 => "Choice C2", C3 => "Choice C3" - } + }, + order => ['C2','C1','C3'], }, A3 => { text =>"Choice A3" , default => "D6", @@ -598,7 +658,8 @@ $menu{$choice1}->{'select2'}. D5 => "Choice D5", D6 => "Choice D6", D7 => "Choice D7" - } + }, + order => ['D4','D3','D2','D1','D7','D6','D5'], } ); @@ -610,7 +671,8 @@ sub linked_select_forms { $firstdefault, $firstselectname, $secondselectname, - $hashref + $hashref, + $menuorder, ) = @_; my $second = "document.$formname.$secondselectname"; my $first = "document.$formname.$firstselectname"; @@ -624,8 +686,11 @@ sub linked_select_forms { $result.="select2data.d_$s1 = new Object();\n"; $result.="select2data.d_$s1.def = new String('". $hashref->{$s1}->{'default'}."');\n"; - $result.="select2data.d_$s1.values = new Array("; + $result.="select2data.d_$s1.values = new Array("; my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } )); + if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') { + @s2values = @{$hashref->{$s1}->{'order'}}; + } $result.="\"@s2values\");\n"; $result.="select2data.d_$s1.texts = new Array("; my @s2texts; @@ -663,7 +728,11 @@ function select1_changed() { END # output the initial values for the selection lists $result .= "\n"; my $seconddefault = $hashref->{$firstdefault}->{'default'}; - foreach my $value (sort(keys(%select2))) { + + my @secondorder = sort(keys(%select2)); + if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') { + @secondorder = @{$hashref->{$firstdefault}->{'order'}}; + } + foreach my $value (@secondorder) { $result.="