--- loncom/interface/loncommon.pm 2003/09/11 22:37:54 1.116 +++ loncom/interface/loncommon.pm 2003/10/09 22:07:08 1.127 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common routines # -# $Id: loncommon.pm,v 1.116 2003/09/11 22:37:54 albertel Exp $ +# $Id: loncommon.pm,v 1.127 2003/10/09 22:07:08 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -68,6 +68,8 @@ use POSIX qw(strftime mktime); use Apache::Constants qw(:common :http :methods); use Apache::lonmsg(); use Apache::lonmenu(); +use Apache::lonlocal; + my $readit; =pod @@ -78,6 +80,7 @@ my $readit; # ----------------------------------------------- Filetypes/Languages/Copyright my %language; +my %supported_language; my %cprtag; my %fe; my %fd; my %category_extensions; @@ -144,8 +147,11 @@ BEGIN { while (<$fh>) { next if /^\#/; chomp; - my ($key,$two,$country,$three,$enc,$val)=(split(/\t/,$_)); + my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$_)); $language{$key}=$val.' - '.$enc; + if ($sup) { + $supported_language{$key}=$sup; + } } } } @@ -346,11 +352,11 @@ sub selectstudent_link { return ''; } return "Select User"; + '","'.$udomele.'");'."'>".&mt('Select User').""; } if ($ENV{'request.role'}=~/^(au|dc|su)/) { return "Select User"; + '","'.$udomele.'",1);'."'>".&mt('Select User').""; } return ''; } @@ -382,7 +388,7 @@ ENDSTDBRW sub selectcourse_link { my ($form,$unameele,$udomele)=@_; return "Select Course"; + '","'.$udomele.'");'."'>".&mt('Select Course').""; } =pod @@ -514,7 +520,7 @@ END foreach my $value (sort(keys(%$hashref))) { $result.=" \n"; } $result .= "\n"; my %select2 = %{$hashref->{$firstdefault}->{'select2'}}; @@ -524,7 +530,7 @@ END foreach my $value (sort(keys(%select2))) { $result.=" \n"; + ">".&mt($hash{$_})."\n"; } $selectform.=""; return $selectform; @@ -1503,7 +1509,10 @@ returns description of a specified langu =cut sub languagedescription { - return $language{shift(@_)}; + my $code=shift; + return ($supported_language{$code}?'* ':''). + $language{$code}. + ($supported_language{$code}?' ('.&mt('interface available').')':''); } =pod @@ -1611,16 +1620,8 @@ sub fileextensions { sub display_languages { my %languages=(); - if ($ENV{'environment.languages'}) { - foreach (split(/\s*(\,|\;|\:)\s*/,$ENV{'environment.languages'})) { - $languages{$_}=1; - } - } - if ($ENV{'course.'.$ENV{'request.course.id'}.'.languages'}) { - foreach (split(/\s*(\,|\;|\:)\s*/, - $ENV{'course.'.$ENV{'request.course.id'}.'.languages'})) { - $languages{$_}=1; - } + foreach (&preferred_languages()) { + $languages{$_}=1; } &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']); if ($ENV{'form.displaylanguage'}) { @@ -1631,6 +1632,45 @@ sub display_languages { return %languages; } +sub preferred_languages { + my @languages=(); + if ($ENV{'environment.languages'}) { + @languages=split(/\s*(\,|\;|\:)\s*/,$ENV{'environment.languages'}); + } + if ($ENV{'course.'.$ENV{'request.course.id'}.'.languages'}) { + @languages=(@languages,split(/\s*(\,|\;|\:)\s*/, + $ENV{'course.'.$ENV{'request.course.id'}.'.languages'})); + } + my $browser=(split(/\;/,$ENV{'HTTP_ACCEPT_LANGUAGE'}))[0]; + if ($browser) { + @languages=(@languages,split(/\s*(\,|\;|\:)\s*/,$browser)); + } + if ($Apache::lonnet::domain_lang_def{$ENV{'user.domain'}}) { + @languages=(@languages, + $Apache::lonnet::domain_lang_def{$ENV{'user.domain'}}); + } + if ($Apache::lonnet::domain_lang_def{$ENV{'request.role.domain'}}) { + @languages=(@languages, + $Apache::lonnet::domain_lang_def{$ENV{'request.role.domain'}}); + } + if ($Apache::lonnet::domain_lang_def{ + $Apache::lonnet::perlvar{'lonDefDomain'}}) { + @languages=(@languages, + $Apache::lonnet::domain_lang_def{ + $Apache::lonnet::perlvar{'lonDefDomain'}}); + } +# turn "en-ca" into "en-ca,en" + my @genlanguages; + foreach (@languages) { + unless ($_=~/\w/) { next; } + push (@genlanguages,$_); + if ($_=~/(\-|\_)/) { + push (@genlanguages,(split(/(\-|\_)/,$_))[0]); + } + } + return @genlanguages; +} + ############################################################### ## Student Answer Attempts ## ############################################################### @@ -2059,6 +2099,7 @@ other decorations will be returned. sub bodytag { my ($title,$function,$addentries,$bodyonly,$domain,$forcereg)=@_; + $title=&mt($title); unless ($function) { $function='student'; if ($ENV{'request.role'}=~/^(cc|in|ta|ep)/) { @@ -2287,6 +2328,14 @@ sub no_cache { #$r->header_out("Expires" => $date); } +sub content_type { + my ($r,$type,$charset) = @_; + unless ($charset) { + $charset=&Apache::lonlocal::current_encoding; + } + $r->content_type($type.($charset?'; charset='.$charset:'')); +} + =pod =item * add_to_env($name,$value) @@ -2610,6 +2659,60 @@ sub check_if_partid_hidden { return undef; } +############################################################ +############################################################ + +=pod + +=item DrawGraph + +Returns a link to cgi-bin/graph + +=cut + +############################################################ +############################################################ +sub DrawGraph { + my ($Title,$xlabel,$ylabel,$Max,$values1,$values2)=@_; + # + my $identifier = time.'_'.int(rand(1000)); + if (! defined($values1) || ref($values1) ne 'ARRAY') { + return ''; + } + # + $Title = '' if (! defined($Title)); + $xlabel = '' if (! defined($xlabel)); + $ylabel = '' if (! defined($ylabel)); + $Title = &Apache::lonnet::escape($Title); + $xlabel = &Apache::lonnet::escape($xlabel); + $ylabel = &Apache::lonnet::escape($ylabel); + # + my $data1 = join(',', @$values1); + my $data2; + if (defined($values2)) { + $data2 = join(',', @$values2); + } + # + my $NumBars = scalar(@$values1); + $Max = 1 if ($Max < 1); + if ( int($Max) < $Max ) { + $Max++; + $Max = int($Max); + } + # + &Apache::lonnet::appenv($identifier.'.title' => $Title, + $identifier.'.xlabel' => $xlabel, + $identifier.'.ylabel' => $ylabel, + $identifier.'.Max' => $Max, + $identifier.'.NumBars' => $NumBars, + $identifier.'.data1' => $data1, + $identifier.'.data2' => $data2); + return ''; +} + +############################################################ +############################################################ + =pod =back