--- loncom/interface/loncommon.pm 2007/01/20 22:04:57 1.502 +++ loncom/interface/loncommon.pm 2007/11/06 19:02:57 1.610 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common routines # -# $Id: loncommon.pm,v 1.502 2007/01/20 22:04:57 raeburn Exp $ +# $Id: loncommon.pm,v 1.610 2007/11/06 19:02:57 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -68,8 +68,12 @@ use Apache::lontexconvert(); use Apache::lonclonecourse(); use LONCAPA qw(:DEFAULT :match); +# ---------------------------------------------- Designs +use vars qw(%defaultdesign); + my $readit; + ## ## Global Variables ## @@ -82,10 +86,6 @@ my %scprtag; my %fe; my %fd; my %fm; my %category_extensions; -# ---------------------------------------------- Designs - -my %designhash; - # ---------------------------------------------- Thesaurus variables # # %Keywords: @@ -151,30 +151,18 @@ BEGIN { } } -# -------------------------------------------------------------- domain designs - - my $filename; +# -------------------------------------------------------------- default domain designs my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors'; - opendir(DIR,$designdir); - while ($filename=readdir(DIR)) { - if ($filename!~/\.tab$/) { next; } - my ($domain)=($filename=~/^($match_domain)\./); - { - my $designfile = $designdir.'/'.$filename; - if ( open (my $fh,"<$designfile") ) { - while (my $line = <$fh>) { - next if ($line =~ /^\#/); - chomp($line); - my ($key,$val)=(split(/\=/,$line)); - if ($val) { $designhash{$domain.'.'.$key}=$val; } - } - close($fh); - } - } - + my $designfile = $designdir.'/default.tab'; + if ( open (my $fh,"<$designfile") ) { + while (my $line = <$fh>) { + next if ($line =~ /^\#/); + chomp($line); + my ($key,$val)=(split(/\=/,$line)); + if ($val) { $defaultdesign{$key}=$val; } + } + close($fh); } - closedir(DIR); - # ------------------------------------------------------------- file categories { @@ -346,10 +334,12 @@ sub studentbrowser_javascript { return (<<'ENDSTDBRW'); +RESIZE + +} + +=pod + +=back + =head1 Excel and CSV file utility routines =over 4 @@ -1224,7 +1359,7 @@ sub create_workbook { =item * create_text_file -Create a file to write to and eventually make available to the usre. +Create a file to write to and eventually make available to the user. If file creation fails, outputs an error message on the request object and return undefs. @@ -1265,41 +1400,19 @@ sub create_text_file { ## Home server \n"; + ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom; + if ($showdomdesc) { + if ($dom ne '') { + my $domdesc = &Apache::lonnet::domain($dom,'description'); + if ($domdesc ne '') { + $selectdomain .= ' ('.$domdesc.')'; + } + } + } + $selectdomain .= "\n"; } $selectdomain.=""; return $selectdomain; @@ -1474,53 +1602,73 @@ sub select_dom_form { =pod -=item * get_library_servers($domain) +=item * home_server_form_item($domain,$name,$defaultflag) -Returns a hash which contains keys like '103l3' and values like -'kirk.lite.msu.edu'. All of the keys will be for machines in the -given $domain. +input: 4 arguments (two required, two optional) - + $domain - domain of new user + $name - name of form element + $default - Value of 'default' causes a default item to be first + option, and selected by default. + $hide - Value of 'hide' causes hiding of the name of the server, + if 1 server found, or default, if 0 found. +output: returns 2 items: +(a) form element which contains either: + (i) + form item if there are multiple library servers in $domain, or + (ii) an form item + if there is only one library server in $domain. -=cut +(b) number of library servers found. -#------------------------------------------- -sub get_library_servers { - my $domain = shift; - my %library_servers; - foreach my $hostid (keys(%Apache::lonnet::libserv)) { - if ($Apache::lonnet::hostdom{$hostid} eq $domain) { - $library_servers{$hostid} = $Apache::lonnet::hostname{$hostid}; - } - } - return %library_servers; -} - -#------------------------------------------- - -=pod - -=item * home_server_option_list($domain) - -returns a string which contains an '."\n"; + } + foreach my $hostid (sort(keys(%servers))) { + $result.= '\n"; + } + $result .= ''."\n"; + } elsif ($numlib == 1) { + my $hostid; + foreach my $item (keys(%servers)) { + $hostid = $item; + } + $result .= ''; + if (!$hide) { + $result .= $hostid.' '.$servers{$hostid}; + } + $result .= "\n"; + } elsif ($default) { + $result .= ''; + if (!$hide) { + $result .= &mt('default'); + } + $result .= "\n"; } - return $result; + return ($result,$numlib); } =pod -=back +=back =cut @@ -1668,19 +1816,16 @@ END } my $radioval = "'nochange'"; - if (exists($in{'curr_authtype'}) && - defined($in{'curr_authtype'}) && - $in{'curr_authtype'} ne '') { - $radioval = "'$in{'curr_authtype'}arg'"; + if (defined($in{'curr_authtype'})) { + if ($in{'curr_authtype'} ne '') { + $radioval = "'".$in{'curr_authtype'}."arg'"; + } } my $argfield = 'null'; - if ( grep/^mode$/,(keys %in) ) { + if (defined($in{'mode'})) { if ($in{'mode'} eq 'modifycourse') { - if ( grep/^curr_authtype$/,(keys %in) ) { - $radioval = "'$in{'curr_authtype'}'"; - } - if ( grep/^curr_autharg$/,(keys %in) ) { - unless ($in{'curr_autharg'} eq '') { + if (defined($in{'curr_autharg'})) { + if ($in{'curr_autharg'} ne '') { $argfield = "'$in{'curr_autharg'}'"; } } @@ -1763,79 +1908,170 @@ sub authform_nochange{ kerb_def_dom => 'MSU.EDU', @_, ); - my $result = ''; + } return $result; } -sub authform_kerberos{ +sub authform_kerberos { my %in = ( formname => 'document.cu', kerb_def_dom => 'MSU.EDU', kerb_def_auth => 'krb4', @_, ); - my ($check4,$check5,$krbarg); + my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype, + $autharg,$jscall); + my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'}); if ($in{'kerb_def_auth'} eq 'krb5') { - $check5 = " checked=\"on\""; + $check5 = ' checked="on"'; } else { - $check4 = " checked=\"on\""; + $check4 = ' checked="on"'; } $krbarg = $in{'kerb_def_dom'}; - - my $krbcheck = ""; - if ( grep/^curr_authtype$/,(keys %in) ) { - if ($in{'curr_authtype'} =~ m/^krb/) { - $krbcheck = " checked=\"on\""; - if ( grep/^curr_autharg$/,(keys %in) ) { + if (defined($in{'curr_authtype'})) { + if ($in{'curr_authtype'} eq 'krb') { + $krbcheck = ' checked="on"'; + if (defined($in{'curr_kerb_ver'})) { + if ($in{'curr_krb_ver'} eq '5') { + $check5 = ' checked="on"'; + $check4 = ''; + } else { + $check4 = ' checked="on"'; + $check5 = ''; + } + } + if (defined($in{'curr_autharg'})) { $krbarg = $in{'curr_autharg'}; } + if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) { + if (defined($in{'curr_autharg'})) { + $result = + &mt('Currently Kerberos authenticated with domain [_1] Version [_2].', + $in{'curr_autharg'},$krbver); + } else { + $result = + &mt('Currently Kerberos authenticated, Version [_1].',$krbver); + } + return $result; + } + } + } else { + if ($authnum == 1) { + $authtype = ''; } } - - my $jscall = "javascript:changed_radio('krb',$in{'formname'});"; - my $result .= &mt + if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) { + return; + } elsif ($authtype eq '') { + if (defined($in{'mode'})) { + if ($in{'mode'} eq 'modifycourse') { + if ($authnum == 1) { + $authtype = ''; + } + } + } + } + $jscall = "javascript:changed_radio('krb',$in{'formname'});"; + if ($authtype eq '') { + $authtype = ''; + } + if (($can_assign{'krb4'} && $can_assign{'krb5'}) || + ($can_assign{'krb4'} && !$can_assign{'krb5'} && + $in{'curr_authtype'} eq 'krb5') || + (!$can_assign{'krb4'} && $can_assign{'krb5'} && + $in{'curr_authtype'} eq 'krb4')) { + $result .= &mt ('[_1] Kerberos authenticated with domain [_2] '. '[_3] Version 4 [_4] Version 5 [_5]', - ''); return $result; } +sub get_assignable_auth { + my ($dom) = @_; + if ($dom eq '') { + $dom = $env{'request.role.domain'}; + } + my %can_assign = ( + krb4 => 1, + krb5 => 1, + int => 1, + loc => 1, + ); + my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom); + if (ref($domconfig{'usercreation'}) eq 'HASH') { + if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') { + my $authhash = $domconfig{'usercreation'}{'authtypes'}; + my $context; + if ($env{'request.role'} =~ /^au/) { + $context = 'author'; + } elsif ($env{'request.role'} =~ /^dc/) { + $context = 'domain'; + } elsif ($env{'request.course.id'}) { + $context = 'course'; + } + if ($context) { + if (ref($authhash->{$context}) eq 'HASH') { + %can_assign = %{$authhash->{$context}}; + } + } + } + } + my $authnum = 0; + foreach my $key (keys(%can_assign)) { + if ($can_assign{$key}) { + $authnum ++; + } + } + if ($can_assign{'krb4'} && $can_assign{'krb5'}) { + $authnum --; + } + return ($authnum,%can_assign); +} + ############################################################### ## Get Authentication Defaults for Domain ## ############################################################### @@ -1910,7 +2244,9 @@ If target_domain is not found in domain. #------------------------------------------- sub get_auth_defaults { my $domain=shift; - return ($Apache::lonnet::domain_auth_def{$domain},$Apache::lonnet::domain_auth_arg_def{$domain}); + return (&Apache::lonnet::domain($domain,'auth_def'), + &Apache::lonnet::domain($domain,'auth_arg_def')); + } ############################################################### ## End Get Authentication Defaults for Domain ## @@ -2005,7 +2341,7 @@ sub initialize_keywords { # Remove special values from %Keywords. foreach my $value ('total.count','average.count') { delete($Keywords{$value}) if (exists($Keywords{$value})); - } + } return 1; } @@ -2105,6 +2441,7 @@ if $first is set to 'lastname' then it r ############################################################### sub plainname { my ($uname,$udom,$first)=@_; + return if (!defined($uname) || !defined($udom)); my %names=&getnames($uname,$udom); my $name=&Apache::lonnet::format_name($names{'firstname'}, $names{'middlename'}, @@ -2136,6 +2473,7 @@ if the user does not sub nickname { my ($uname,$udom)=@_; + return if (!defined($uname) || !defined($udom)); my %names=&getnames($uname,$udom); my $name=$names{'nickname'}; if ($name) { @@ -2151,6 +2489,7 @@ sub nickname { sub getnames { my ($uname,$udom)=@_; + return if (!defined($uname) || !defined($udom)); if ($udom eq 'public' && $uname eq 'public') { return ('lastname' => &mt('Public')); } @@ -2167,6 +2506,19 @@ sub getnames { } } +# -------------------------------------------------------------------- getemails +=pod + +=item * getemails($uname,$udom) + +Gets a user's email information and returns it as a hash with keys: +notification, critnotification, permanentemail + +For notification and critnotification, values are comma-separated lists +of e-mail address(es); for permanentemail, value is a single e-mail address. + +=cut + sub getemails { my ($uname,$udom)=@_; if ($udom eq 'public' && $uname eq 'public') { @@ -2188,6 +2540,15 @@ sub getemails { } } +sub flush_email_cache { + my ($uname,$udom)=@_; + if (!$udom) { $udom =$env{'user.domain'}; } + if (!$uname) { $uname=$env{'user.name'}; } + return if ($udom eq 'public' && $uname eq 'public'); + my $id=$uname.':'.$udom; + &Apache::lonnet::devalidate_cache_new('emailscache',$id); +} + # ------------------------------------------------------------------ Screenname =pod @@ -2261,11 +2622,25 @@ sub track_student_link { $target = ''; } if ($start) { $link.='&start='.$start; } - + $title = &mt($title); + $linktext = &mt($linktext); return qq{$linktext}. &help_open_topic('View_recent_activity'); } +# ===================================================== Display a student photo + + +sub student_image_tag { + my ($domain,$user)=@_; + my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg'); + if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) { + return ''; + } else { + return ''; + } +} + =pod =back @@ -2477,36 +2852,66 @@ sub preferred_languages { @languages=(@languages, split(/\s*(\,|\;|\:)\s*/,$env{'environment.languages'})); } - my $browser=(split(/\;/,$ENV{'HTTP_ACCEPT_LANGUAGE'}))[0]; + my $browser=$ENV{'HTTP_ACCEPT_LANGUAGE'}; if ($browser) { - @languages=(@languages,split(/\s*(\,|\;|\:)\s*/,$browser)); + my @browser = + map { (split(/\s*;\s*/,$_))[0] } (split(/\s*,\s*/,$browser)); + push(@languages,@browser); } - if ($Apache::lonnet::domain_lang_def{$env{'user.domain'}}) { + if (&Apache::lonnet::domain($env{'user.domain'},'lang_def')) { @languages=(@languages, - $Apache::lonnet::domain_lang_def{$env{'user.domain'}}); + &Apache::lonnet::domain($env{'user.domain'}, + 'lang_def')); } - if ($Apache::lonnet::domain_lang_def{$env{'request.role.domain'}}) { + if (&Apache::lonnet::domain($env{'request.role.domain'},'lang_def')) { @languages=(@languages, - $Apache::lonnet::domain_lang_def{$env{'request.role.domain'}}); + &Apache::lonnet::domain($env{'request.role.domain'}, + 'lang_def')); } - if ($Apache::lonnet::domain_lang_def{ - $Apache::lonnet::perlvar{'lonDefDomain'}}) { + if (&Apache::lonnet::domain($Apache::lonnet::perlvar{'lonDefDomain'}, + 'lang_def')) { @languages=(@languages, - $Apache::lonnet::domain_lang_def{ - $Apache::lonnet::perlvar{'lonDefDomain'}}); + &Apache::lonnet::domain($Apache::lonnet::perlvar{'lonDefDomain'}, + 'lang_def')); } # turn "en-ca" into "en-ca,en" my @genlanguages; foreach my $lang (@languages) { unless ($lang=~/\w/) { next; } - push (@genlanguages,$lang); + push(@genlanguages,$lang); if ($lang=~/(\-|\_)/) { push(@genlanguages,(split(/(\-|\_)/,$lang))[0]); } } + #uniqueify the languages list + my %count; + @genlanguages = map { $count{$_}++ == 0 ? $_ : () } @genlanguages; return @genlanguages; } +sub languages { + my ($possible_langs) = @_; + my @preferred_langs = &preferred_languages(); + if (!ref($possible_langs)) { + if( wantarray ) { + return @preferred_langs; + } else { + return $preferred_langs[0]; + } + } + my %possibilities = map { $_ => 1 } (@$possible_langs); + my @preferred_possibilities; + foreach my $preferred_lang (@preferred_langs) { + if (exists($possibilities{$preferred_lang})) { + push(@preferred_possibilities, $preferred_lang); + } + } + if( wantarray ) { + return @preferred_possibilities; + } + return $preferred_possibilities[0]; +} + ############################################################### ## Student Answer Attempts ## ############################################################### @@ -2561,14 +2966,14 @@ sub get_previous_attempt { $lasthash{$key}=$returnhash{$version.':'.$key}; } } - $prevattempts='
'; - $prevattempts.=''; + $prevattempts=&start_data_table().&start_data_table_header_row(); + $prevattempts.=''; foreach my $key (sort(keys(%lasthash))) { my ($ign,@parts) = split(/\./,$key); if ($#parts > 0) { my $data=$parts[-1]; pop(@parts); - $prevattempts.=''; + $prevattempts.=''; } else { if ($#parts == 0) { $prevattempts.=''; @@ -2577,41 +2982,53 @@ sub get_previous_attempt { } } } + $prevattempts.=&end_data_table_header_row(); if ($getattempt eq '') { for ($version=1;$version<=$returnhash{'version'};$version++) { - $prevattempts.=''; + $prevattempts.=&start_data_table_row(). + ''; foreach my $key (sort(keys(%lasthash))) { - my $value; - if ($key =~ /timestamp/) { - $value=scalar(localtime($returnhash{$version.':'.$key})); - } else { - $value=$returnhash{$version.':'.$key}; - } - $prevattempts.=''; + my $value = &format_previous_attempt_value($key, + $returnhash{$version.':'.$key}); + $prevattempts.=''; } + $prevattempts.=&end_data_table_row(); } } - $prevattempts.=''; + $prevattempts.=&start_data_table_row().''; foreach my $key (sort(keys(%lasthash))) { - my $value; - if ($key =~ /timestamp/) { - $value=scalar(localtime($lasthash{$key})); - } else { - $value=$lasthash{$key}; - } - $value=&unescape($value); + my $value = &format_previous_attempt_value($key,$lasthash{$key}); if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)} $prevattempts.=''; } - $prevattempts.='
History'.&mt('History').'Part '.join('.',@parts).'
'.$data.' 
'.&mt('Part ').join('.',@parts).'
'.$data.' 
'.$parts[0].'
Transaction '.$version.''.&mt('Transaction [_1]',$version).''.&unescape($value).' '.$value.' 
Current'.&mt('Current').''.$value.' 
'; + $prevattempts.= &end_data_table_row().&end_data_table(); } else { - $prevattempts='Nothing submitted - no attempts.'; + $prevattempts= + &start_data_table().&start_data_table_row(). + ''.&mt('Nothing submitted - no attempts.').''. + &end_data_table_row().&end_data_table(); } } else { - $prevattempts='No data.'; + $prevattempts= + &start_data_table().&start_data_table_row(). + ''.&mt('No data.').''. + &end_data_table_row().&end_data_table(); } } +sub format_previous_attempt_value { + my ($key,$value) = @_; + if ($key =~ /timestamp/) { + $value = &Apache::lonlocal::locallocaltime($value); + } elsif (ref($value) eq 'ARRAY') { + $value = '('.join(', ', @{ $value }).')'; + } else { + $value = &unescape($value); + } + return $value; +} + + sub relative_to_absolute { my ($url,$output)=@_; my $parser=HTML::TokeParser->new(\$output); @@ -2699,7 +3116,6 @@ sub get_student_answers { $moreenv{'grade_target'}='answer'; %moreenv=(%form,%moreenv); $feedurl = &Apache::lonnet::clutter($feedurl); - &Apache::lonenc::check_encrypt(\$feedurl); my $userview=&Apache::lonnet::ssi($feedurl,%moreenv); return $userview; } @@ -2771,9 +3187,9 @@ sub pprmlink { if (!$symb) { $symb=&Apache::lonnet::symbread(); } $symb=&escape($symb); if ($target) { $target="target=\"$target\""; } - return ''.$text.''; + return ''.$text.''; } ############################################## @@ -2950,7 +3366,7 @@ sub blockcheck { } my $no_ownblock = 0; my $no_userblock = 0; - if ($otheruser) { + if ($otheruser && $activity ne 'com') { # Check if current user has 'evb' priv for this if (defined($own_courses{$course})) { foreach my $sec (keys(%{$own_courses{$course}})) { @@ -3203,7 +3619,7 @@ Returns: Determines which domain should ############################################### sub determinedomain { my $domain=shift; - if (! $domain) { + if (! $domain) { # Determine domain if we have not been given one $domain = $Apache::lonnet::perlvar{'lonDefDomain'}; if ($env{'user.domain'}) { $domain=$env{'user.domain'}; } @@ -3214,6 +3630,60 @@ sub determinedomain { return $domain; } ############################################### + +sub devalidate_domconfig_cache { + my ($udom)=@_; + &Apache::lonnet::devalidate_cache_new('domainconfig',$udom); +} + +# ---------------------- Get domain configuration for a domain +sub get_domainconf { + my ($udom) = @_; + my $cachetime=1800; + my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom); + if (defined($cached)) { return %{$result}; } + + my %domconfig = &Apache::lonnet::get_dom('configuration', + ['login','rolecolors'],$udom); + my %designhash; + if (keys(%domconfig) > 0) { + if (ref($domconfig{'login'}) eq 'HASH') { + foreach my $key (keys(%{$domconfig{'login'}})) { + $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key}; + } + } + if (ref($domconfig{'rolecolors'}) eq 'HASH') { + foreach my $role (keys(%{$domconfig{'rolecolors'}})) { + if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') { + foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) { + $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item}; + } + } + } + } + } else { + my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors'; + my $designfile = $designdir.'/'.$udom.'.tab'; + if (-e $designfile) { + if ( open (my $fh,"<$designfile") ) { + while (my $line = <$fh>) { + next if ($line =~ /^\#/); + chomp($line); + my ($key,$val)=(split(/\=/,$line)); + if ($val) { $designhash{$udom.'.'.$key}=$val; } + } + close($fh); + } + } + if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') { + $designhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif"; + } + } + &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash, + $cachetime); + return %designhash; +} + =pod =item * &domainlogo() @@ -3227,13 +3697,21 @@ If the domain logo does not exist, a des ############################################### sub domainlogo { - my $domain = &determinedomain(shift); - # See if there is a logo - if (-e '/home/httpd/html/adm/lonDomLogos/'.$domain.'.gif') { - my $logo=&lonhttpdurl("/adm/lonDomLogos/$domain.gif"); - return ''.$domain.''; - } elsif(exists($Apache::lonnet::domaindescription{$domain})) { - return $Apache::lonnet::domaindescription{$domain}; + my $domain = &determinedomain(shift); + my %designhash = &get_domainconf($domain); + # See if there is a logo + if ($designhash{$domain.'.login.domlogo'} ne '') { + my $imgsrc = $designhash{$domain.'.login.domlogo'}; + if ($imgsrc =~ m{^/(adm|res)/}) { + if ($imgsrc =~ m{^/res/}) { + my $local_name = &Apache::lonnet::filelocation('',$imgsrc); + &Apache::lonnet::repcopy($local_name); + } + $imgsrc = &lonhttpdurl($imgsrc); + } + return ''.$domain.''; + } elsif (defined(&Apache::lonnet::domain($domain,'description'))) { + return &Apache::lonnet::domain($domain,'description'); } else { return ''; } @@ -3269,11 +3747,24 @@ sub designparm { return $env{'environment.color.'.$which}; } $domain=&determinedomain($domain); - if (exists($designhash{$domain.'.'.$which})) { - return $designhash{$domain.'.'.$which}; + my %domdesign = &get_domainconf($domain); + my $output; + if ($domdesign{$domain.'.'.$which} ne '') { + $output = $domdesign{$domain.'.'.$which}; } else { - return $designhash{'default.'.$which}; + $output = $defaultdesign{$which}; + } + if (($which =~ /^(student|coordinator|author|admin)\.img$/) || + ($which =~ /login\.(img|logo|domlogo)/)) { + if ($output =~ m{^/(adm|res)/}) { + if ($output =~ m{^/res/}) { + my $local_name = &Apache::lonnet::filelocation('',$output); + &Apache::lonnet::repcopy($local_name); + } + $output = &lonhttpdurl($output); + } } + return $output; } ############################################### @@ -3283,7 +3774,7 @@ sub designparm { =back -=head1 HTTP Helpers +=head1 HTML Helpers =over 4 @@ -3324,6 +3815,9 @@ Inputs: =item * $args, optional argument valid values are no_auto_mt_title -> prevents &mt()ing the title arg + inherit_jsmath -> when creating popup window in a page, + should it have jsmath forced on by the + current page =back @@ -3372,19 +3866,14 @@ sub bodytag { if (!$realm) { $realm=' '; } # Set messages my $messages=&domainlogo($domain); -# Port for miniserver - my $lonhttpdPort=$Apache::lonnet::perlvar{'lonhttpdPort'}; - if (!defined($lonhttpdPort)) { $lonhttpdPort='8080'; } my $extra_body_attr = &make_attr_string($forcereg,\%design); # construct main body tag my $bodytag = "". - &Apache::lontexconvert::init_math_support(); + &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'}); - if ($bodyonly - || ($env{'request.state'} eq 'construct' - && $env{'environment.remote'} ne 'off' )) { + if ($bodyonly) { return $bodytag; } elsif ($env{'browser.interface'} eq 'textual') { # Accessibility @@ -3492,8 +3981,11 @@ ENDROLE # Top frame rendering, Remote is up # - my $upperleft=''.$function.''; + my $imgsrc = $img; + if ($img =~ /^\/adm/) { + $imgsrc = &lonhttpdurl($img); + } + my $upperleft=''.$function.''; # Explicit link to get inline menu my $menu= ($no_inline_link?'' @@ -3576,20 +4068,12 @@ sub make_attr_string { =pod -=back - -=head1 HTML Helpers - -=over 4 - =item * &endbodytag() Returns a uniform footer for LON-CAPA web pages. Inputs: none -=back - =cut sub endbodytag { @@ -3606,8 +4090,6 @@ sub endbodytag { =pod -=over 4 - =item * &standard_css() Returns a style sheet @@ -3618,8 +4100,6 @@ Inputs: (all optional) function -> force usage of a specific rolish color scheme bgcolor -> override the default page bgcolor -=back - =cut sub standard_css { @@ -3637,7 +4117,7 @@ sub standard_css { my $vlink = &designparm($function.'.vlink', $domain); my $link = &designparm($function.'.link', $domain); - my $sans = 'Arial,Helvetica,sans-serif'; + my $sans = 'Verdana,Arial,Helvetica,sans-serif'; my $mono = 'monospace'; my $data_table_head = $tabbg; my $data_table_light = '#EEEEEE'; @@ -3655,19 +4135,29 @@ sub standard_css { my $table_header = '#DDDDDD'; my $feedback_link_bg = '#BBBBBB'; - my $border = ($env{'browser.type'} eq 'explorer') ? '0px 2px 0px 2px' - : '0px 3px 0px 4px'; + my $border = ($env{'browser.type'} eq 'explorer' || + $env{'browser.type'} eq 'safari' ) ? '0px 2px 0px 2px' + : '0px 3px 0px 4px'; + return < td, table.LC_aboutme_port tr td { background-color: $data_table_light; padding: 2px; } -table.LC_data_table tr.LC_even_row td, +table.LC_data_table tr.LC_even_row > td, table.LC_aboutme_port tr.LC_even_row td { background-color: $data_table_dark; } @@ -3853,36 +4433,51 @@ table.LC_data_table tr.LC_data_table_hig background-color: $data_table_darker; } table.LC_data_table tr.LC_empty_row td, -table.LC_whatsnew tr.LC_empty_row td { +table.LC_nested tr.LC_empty_row td { background-color: #FFFFFF; font-weight: bold; font-style: italic; text-align: center; padding: 8px; } -table.LC_whatsnew tr.LC_empty_row td { +table.LC_nested tr.LC_empty_row td { padding: 4ex } -table.LC_whatsnew { +table.LC_nested_outer tr th { + font-weight: bold; + background-color: $data_table_head; + font-size: smaller; + border-bottom: 1px solid #000000; +} +table.LC_nested_outer tr td.LC_subheader { + background-color: $data_table_head; + font-weight: bold; + font-size: small; + border-bottom: 1px solid #000000; + text-align: right; } - -table.LC_whatsnew tr th, -table.LC_whatsnew tr.LC_info_row td { +table.LC_nested tr.LC_info_row td { background-color: #CCC; font-weight: bold; font-size: small; - text-align: right; + text-align: center; } -table.LC_whatsnew tr td { +table.LC_nested tr.LC_info_row td.LC_left_item, +table.LC_nested_outer tr th.LC_left_item { + text-align: left; +} +table.LC_nested td { background-color: #FFF; font-size: small; - text-align: right; } -table.LC_whatsnew tr td.LC_first_item { - text-align: left; +table.LC_nested_outer tr th.LC_right_item, +table.LC_nested tr.LC_info_row td.LC_right_item, +table.LC_nested tr.LC_odd_row td.LC_right_item, +table.LC_nested tr td.LC_right_item { + text-align: right; } -table.LC_whatsnew tr.LC_odd_row td { +table.LC_nested tr.LC_odd_row td { background-color: #EEE; } @@ -4099,9 +4694,7 @@ table#LC_helpmenu_links a:hover { border: 1px solid #8888FF; background: #CCCCFF; } - table.LC_pick_box { - width: 100%; border-collapse: separate; background: white; border: 1px solid black; @@ -4114,6 +4707,14 @@ table.LC_pick_box td.LC_pick_box_title { width: 184px; padding: 8px; } +table.LC_pick_box td.LC_pick_box_value { + text-align: left; + padding: 8px; +} +table.LC_pick_box td.LC_pick_box_select { + text-align: left; + padding: 8px; +} table.LC_pick_box td.LC_pick_box_separator { padding: 0px; height: 1px; @@ -4122,7 +4723,48 @@ table.LC_pick_box td.LC_pick_box_separat table.LC_pick_box td.LC_pick_box_submit { text-align: right; } - +table.LC_pick_box td.LC_evenrow_value { + text-align: left; + padding: 8px; + background-color: $data_table_light; +} +table.LC_pick_box td.LC_oddrow_value { + text-align: left; + padding: 8px; + background-color: $data_table_light; +} +table.LC_helpform_receipt { + width: 620px; + border-collapse: separate; + background: white; + border: 1px solid black; + border-spacing: 1px; +} +table.LC_helpform_receipt td.LC_pick_box_title { + background: $tabbg; + font-weight: bold; + text-align: right; + width: 184px; + padding: 8px; +} +table.LC_helpform_receipt td.LC_evenrow_value { + text-align: left; + padding: 8px; + background-color: $data_table_light; +} +table.LC_helpform_receipt td.LC_oddrow_value { + text-align: left; + padding: 8px; + background-color: $data_table_light; +} +table.LC_helpform_receipt td.LC_pick_box_separator { + padding: 0px; + height: 1px; + background: black; +} +span.LC_helpform_receipt_cat { + font-weight: bold; +} table.LC_group_priv_box { background: white; border: 1px solid black; @@ -4190,21 +4832,323 @@ table.LC_descriptive_input td.LC_descrip text-align: right; font-weight: bold; } -table.LC_feedback_link { - background: $feedback_link_bg; +div.LC_feedback_link { + background: white; + width: 100%; } span.LC_feedback_link { - background: $feedback_link_bg; - font-size: larger; + background: $feedback_link_bg; + font-size: larger; +} +span.LC_message_link { + background: $feedback_link_bg; + font-size: larger; + position: absolute; + right: 1em; +} + +table.LC_prior_tries { + border: 1px solid #000000; + border-collapse: separate; + border-spacing: 1px; +} + +table.LC_prior_tries td { + padding: 2px; +} + +.LC_answer_correct { + background: #AAFFAA; + color: black; +} +.LC_answer_charged_try { + background: #FFAAAA ! important; + color: black; +} +.LC_answer_not_charged_try, +.LC_answer_no_grade, +.LC_answer_late { + background: #FFFFAA; + color: black; +} +.LC_answer_previous { + background: #AAAAFF; + color: black; +} +.LC_answer_no_message { + background: #FFFFFF; + color: black; +} +.LC_answer_unknown { + background: orange; + color: black; +} + + +span.LC_prior_numerical, +span.LC_prior_string, +span.LC_prior_custom, +span.LC_prior_reaction, +span.LC_prior_math { + font-family: monospace; + white-space: pre; +} + +span.LC_prior_string { + font-family: monospace; + white-space: pre; +} + +table.LC_prior_option { + width: 100%; + border-collapse: collapse; +} +table.LC_prior_rank, table.LC_prior_match { + border-collapse: collapse; +} +table.LC_prior_option tr td, +table.LC_prior_rank tr td, +table.LC_prior_match tr td { + border: 1px solid #000000; +} + +span.LC_nobreak { + white-space: nowrap; +} + +span.LC_cusr_emph { + font-style: italic; } +table.LC_docs_documents { + background: #BBBBBB; + border-width: 0px; + border-collapse: collapse; +} + +table.LC_docs_documents td.LC_docs_document { + border: 2px solid black; + padding: 4px; +} + +.LC_docs_course_commands div { + float: left; + border: 4px solid #AAAAAA; + padding: 4px; + background: #DDDDCC; +} + +.LC_docs_entry_move { + border: 0px; + border-collapse: collapse; +} + +.LC_docs_entry_move td { + border: 2px solid #BBBBBB; + background: #DDDDDD; +} + +.LC_docs_editor td.LC_docs_entry_commands { + background: #DDDDDD; + font-size: x-small; +} +.LC_docs_copy { + color: #000099; +} +.LC_docs_cut { + color: #550044; +} +.LC_docs_rename { + color: #009900; +} +.LC_docs_remove { + color: #990000; +} + +.LC_docs_reinit_warn, +.LC_docs_ext_edit { + font-size: x-small; +} + +.LC_docs_editor td.LC_docs_entry_title, +.LC_docs_editor td.LC_docs_entry_icon { + background: #FFFFBB; +} +.LC_docs_editor td.LC_docs_entry_parameter { + background: #BBBBFF; + font-size: x-small; + white-space: nowrap; +} + +table.LC_docs_adddocs td, +table.LC_docs_adddocs th { + border: 1px solid #BBBBBB; + padding: 4px; + background: #DDDDDD; +} + +table.LC_sty_begin { + background: #BBFFBB; +} +table.LC_sty_end { + background: #FFBBBB; +} + +table.LC_double_column { + border-width: 0px; + border-collapse: collapse; + width: 100%; + padding: 2px; +} + +table.LC_double_column tr td.LC_left_col { + top: 2px; + left: 2px; + width: 47%; + vertical-align: top; +} + +table.LC_double_column tr td.LC_right_col { + top: 2px; + right: 2px; + width: 47%; + vertical-align: top; +} + +span.LC_role_level { + font-weight: bold; +} + +div.LC_left_float { + float: left; + padding-right: 5%; + padding-bottom: 4px; +} + +div.LC_clear_float_header { + padding-bottom: 2px; +} + +div.LC_clear_float_footer { + padding-top: 10px; + clear: both; +} + + +div.LC_grade_select_mode { + float: left; + font-family: $sans; +} +div.LC_grade_select_mode div div { + margin: 5px; +} +div.LC_grade_select_mode_selector { + margin: 5px; + float: left; +} +div.LC_grade_select_mode_selector_header { + font: bold medium $sans; +} +div.LC_grade_select_mode_type { + clear: left; +} + +div.LC_grade_show_user { + margin-top: 20px; + border: 1px solid black; +} +div.LC_grade_user_name { + background: #DDDDEE; + border-bottom: 1px solid black; + font: bold large $sans; +} +div.LC_grade_show_user_odd_row div.LC_grade_user_name { + background: #DDEEDD; +} + +div.LC_grade_show_problem, +div.LC_grade_submissions, +div.LC_grade_message_center, +div.LC_grade_info_links, +div.LC_grade_assign { + margin: 5px; + width: 99%; + background: #FFFFFF; +} +div.LC_grade_show_problem_header, +div.LC_grade_submissions_header, +div.LC_grade_message_center_header, +div.LC_grade_assign_header { + font: bold large $sans; +} +div.LC_grade_show_problem_problem, +div.LC_grade_submissions_body, +div.LC_grade_message_center_body, +div.LC_grade_assign_body { + border: 1px solid black; + width: 99%; + background: #FFFFFF; +} +span.LC_grade_check_note { + font: normal medium $sans; + display: inline; + position: absolute; + right: 1em; +} + + +div.LC_edit_problem_header { + font: normal medium $sans; + margin: 2px; +} +div.LC_edit_problem_header, +div.LC_edit_problem_header div, +div.LC_edit_problem_editxml_header, +div.LC_edit_problem_editxml_header div { + margin-top: 5px; +} +div.LC_edit_problem_header_edit_row { + background: $tabbg; + padding: 3px; + margin-bottom: 5px; +} +div.LC_edit_problem_header_title { + font: larger bold $sans; + background: $tabbg; + padding: 3px; +} +table.LC_edit_problem_header_title { + font: larger bold $sans; + width: 100%; + border-color: $pgbg; + border-style: solid; + border-width: $border; + + background: $tabbg; + border-collapse: collapse; + padding: 0px +} + +div.LC_edit_problem_discards { + float: left; + padding-bottom: 5px; +} +div.LC_edit_problem_saves { + float: right; + padding-bottom: 5px; +} +hr.LC_edit_problem_divide { + clear: both; + color: $tabbg; + background-color: $tabbg; + height: 3px; + border: 0px; +} END } =pod -=over 4 - =item * &headtag() Returns a uniform footer for LON-CAPA web pages. @@ -4228,8 +5172,6 @@ Inputs: $title - optional title for the no_auto_mt_title -> prevent &mt()ing the title arg -=back - =cut sub headtag { @@ -4285,16 +5227,12 @@ ADDMETA =pod -=over 4 - =item * &font_settings() Returns neccessary to set the proper encoding Inputs: none -=back - =cut sub font_settings { @@ -4311,22 +5249,20 @@ sub font_settings { =pod -=over 4 - =item * &xml_begin() Returns the needed doctype and Inputs: none -=back - =cut sub xml_begin { my $output=''; - &Apache::lonhtmlcommon::init_htmlareafields(); + if ($env{'internal.start_page'}==1) { + &Apache::lonhtmlcommon::init_htmlareafields(); + } if ($env{'browser.mathml'}) { $output='' @@ -4345,16 +5281,12 @@ sub xml_begin { =pod -=over 4 - =item * &endheadtag() Returns a uniform for LON-CAPA web pages. Inputs: none -=back - =cut sub endheadtag { @@ -4363,8 +5295,6 @@ sub endheadtag { =pod -=over 4 - =item * &head() Returns a uniform complete .. section for LON-CAPA web pages. @@ -4372,8 +5302,6 @@ Returns a uniform complete .. -=back - =cut sub head { @@ -4383,8 +5311,6 @@ sub head { =pod -=over 4 - =item * &start_page() Returns a complete .. section for LON-CAPA web pages. @@ -4423,7 +5349,9 @@ Inputs: $title - optional title for the no_auto_mt_title -> prevent &mt()ing the title arg -=back + inherit_jsmath -> when creating popup window in a page, + should it have jsmath forced on by the + current page =cut @@ -4476,8 +5404,6 @@ sub start_page { =pod -=over 4 - =item * &head() Returns a complete section for LON-CAPA web pages. @@ -4585,30 +5511,30 @@ sub simple_error_page { } { - my $row_count; + my @row_count; sub start_data_table { my ($add_class) = @_; my $css_class = (join(' ','LC_data_table',$add_class)); - undef($row_count); + unshift(@row_count,0); return ''."\n"; } sub end_data_table { - undef($row_count); + shift(@row_count); return '
'."\n";; } sub start_data_table_row { my ($add_class) = @_; - $row_count++; - my $css_class = ($row_count % 2)?'':'LC_even_row'; + $row_count[0]++; + my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row'; $css_class = (join(' ',$css_class,$add_class)); return ''."\n";; } sub continue_data_table_row { my ($add_class) = @_; - my $css_class = ($row_count % 2)?'':'LC_even_row'; + my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row'; $css_class = (join(' ',$css_class,$add_class)); return ''."\n";; } @@ -4618,7 +5544,7 @@ sub simple_error_page { } sub start_data_table_empty_row { - $row_count++; + $row_count[0]++; return ''."\n";; } @@ -4635,10 +5561,61 @@ sub simple_error_page { } } +=pod + +=item * &inhibit_menu_check($arg) + +Checks for a inhibitmenu state and generates output to preserve it + +Inputs: $arg - can be any of + - undef - in which case the return value is a string + to add into arguments list of a uri + - 'input' - in which case the return value is a HTML +
field of type hidden to + preserve the value + - a url - in which case the return value is the url with + the neccesary cgi args added to preserve the + inhibitmenu state + - a ref to a url - no return value, but the string is + updated to include the neccessary cgi + args to preserve the inhibitmenu state + +=cut + +sub inhibit_menu_check { + my ($arg) = @_; + &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']); + if ($arg eq 'input') { + if ($env{'form.inhibitmenu'}) { + return ''; + } else { + return + } + } + if ($env{'form.inhibitmenu'}) { + if (ref($arg)) { + $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'}; + } elsif ($arg eq '') { + $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'}; + } else { + $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'}; + } + } + if (!ref($arg)) { + return $arg; + } +} + ############################################### =pod +=back + +=head1 User Information Routines + +=over 4 + =item * &get_users_function() Used by &bodytag to determine the current users primary role. @@ -4666,7 +5643,7 @@ sub get_users_function { =pod -=item * &check_user_status +=item * &check_user_status() Determines current status of supplied role for a specific user. Roles can be active, previous or future. @@ -4839,12 +5816,15 @@ previous, future, or all. 5. reference to array of section restrictions (optional) 6. reference to results object (hash of hashes). 7. reference to optional userdata hash -Keys of top level hash are roles. +8. reference to optional statushash +Keys of top level results hash are roles. Keys of inner hashes are username:domain, with values set to access type. Optional userdata hash returns an array with arguments in the same order as loncoursedata::get_classlist() for student data. +Optional statushash returns + Entries for end, start, section and status are blank because of the possibility of multiple values for non-student roles. @@ -4853,7 +5833,7 @@ of the possibility of multiple values fo ############################################### sub get_course_users { - my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata) = @_; + my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash) = @_; my %idx = (); my %seclists; @@ -4870,9 +5850,11 @@ sub get_course_users { my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum); my $now = time; foreach my $student (keys(%{$classlist})) { + my $status; my $match = 0; my $secmatch = 0; my $section = $$classlist{$student}[$idx{section}]; + my $status = $$classlist{$student}[$idx{status}]; if ($section eq '') { $section = 'none'; } @@ -4892,7 +5874,6 @@ sub get_course_users { next; } } - push(@{$seclists{$student}},$section); if (defined($$types{'active'})) { if ($$classlist{$student}[$idx{status}] eq 'Active') { push(@{$$users{st}{$student}},'active'); @@ -4900,25 +5881,35 @@ sub get_course_users { } } if (defined($$types{'previous'})) { - if ($$classlist{$student}[$idx{end}] <= $now) { + if ($$classlist{$student}[$idx{status}] eq 'Expired') { push(@{$$users{st}{$student}},'previous'); $match = 1; } } if (defined($$types{'future'})) { - if (($$classlist{$student}[$idx{start}] > $now) && ($$classlist{$student}[$idx{end}] > $now) || ($$classlist{$student}[$idx{end}] == 0) || ($$classlist{$student}[$idx{end}] eq '')) { + if ($$classlist{$student}[$idx{status}] eq 'Future') { push(@{$$users{st}{$student}},'future'); $match = 1; } } - if ($match && ref($userdata) eq 'HASH') { - $$userdata{$student} = $$classlist{$student}; + if ($match) { + push(@{$seclists{$student}},$section); + if (ref($userdata) eq 'HASH') { + $$userdata{$student} = $$classlist{$student}; + } + if (ref($statushash) eq 'HASH') { + $statushash->{$student}{'st'}{$section} = $status; + } } } } if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) { my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum); my $now = time; + my %displaystatus = ( previous => 'Expired', + active => 'Active', + future => 'Future', + ); foreach my $person (sort(keys(%coursepersonnel))) { my $match = 0; my $secmatch = 0; @@ -4952,7 +5943,7 @@ sub get_course_users { $usec = 'none'; } if ($uname ne '' && $udom ne '') { - if ($end < $now) { + if ($end > 0 && $end < $now) { $status = 'previous'; } elsif ($start > $now) { $status = 'future'; @@ -4974,6 +5965,9 @@ sub get_course_users { if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) { push(@{$seclists{$uname.':'.$udom}},$usec); } + if (ref($statushash) eq 'HASH') { + $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status}; + } } } } @@ -4983,15 +5977,25 @@ sub get_course_users { my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum); if ( defined($csettings{'internal.courseowner'}) ) { my $owner = $csettings{'internal.courseowner'}; - if ($owner !~ /^[^:]+:[^:]+$/) { - $owner = $owner.':'.$cdom; + next if ($owner eq ''); + my ($ownername,$ownerdom); + if ($owner =~ /^([^:]+):([^:]+)$/) { + $ownername = $1; + $ownerdom = $2; + } else { + $ownername = $owner; + $ownerdom = $cdom; + $owner = $ownername.':'.$ownerdom; } @{$$users{'ow'}{$owner}} = 'any'; if (defined($userdata) && - !exists($$userdata{$owner.':'.$cdom})) { - &get_user_info($cdom,$owner,\%idx,$userdata); - if (!grep(/^none$/,@{$seclists{$owner.':'.$cdom}})) { - push(@{$seclists{$owner.':'.$cdom}},'none'); + !exists($$userdata{$owner})) { + &get_user_info($ownerdom,$ownername,\%idx,$userdata); + if (!grep(/^none$/,@{$seclists{$owner}})) { + push(@{$seclists{$owner}},'none'); + } + if (ref($statushash) eq 'HASH') { + $statushash->{$owner}{'ow'}{'none'} = 'Any'; } } } @@ -5011,6 +6015,8 @@ sub get_user_info { &plainname($uname,$udom,'lastname'); $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname; $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom; + my %idhash = &Apache::lonnet::idrget($udom,($uname)); + $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname}; return; } @@ -5027,11 +6033,18 @@ Incoming parameters: 2. user's domain Returns: -1. Disk quota (in Mb) assigned to student. +1. Disk quota (in Mb) assigned to student. +2. (Optional) Type of setting: custom or default + (individually assigned or default for user's + institutional status). +3. (Optional) - User's institutional status (e.g., faculty, staff + or student - types as defined in localenroll::inst_usertypes + for user's domain, which determines default quota for user. +4. (Optional) - Default quota which would apply to the user. If a value has been stored in the user's environment, -it will return that, otherwise it returns the default -for users in the domain. +it will return that, otherwise it returns the maximal default +defined for the user's instituional status(es) in the domain. =cut @@ -5040,7 +6053,7 @@ for users in the domain. sub get_user_quota { my ($uname,$udom) = @_; - my $quota; + my ($quota,$quotatype,$settingstatus,$defquota); if (!defined($udom)) { $udom = $env{'user.domain'}; } @@ -5050,23 +6063,38 @@ sub get_user_quota { if (($udom eq '' || $uname eq '') || ($udom eq 'public') && ($uname eq 'public')) { $quota = 0; + $quotatype = 'default'; + $defquota = 0; } else { + my $inststatus; if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) { $quota = $env{'environment.portfolioquota'}; + $inststatus = $env{'environment.inststatus'}; } else { - my %userenv = &Apache::lonnet::dump('environment',$udom,$uname); + my %userenv = + &Apache::lonnet::get('environment',['portfolioquota', + 'inststatus'],$udom,$uname); my ($tmp) = keys(%userenv); if ($tmp !~ /^(con_lost|error|no_such_host)/i) { $quota = $userenv{'portfolioquota'}; + $inststatus = $userenv{'inststatus'}; } else { undef(%userenv); } } + ($defquota,$settingstatus) = &default_quota($udom,$inststatus); if ($quota eq '') { - $quota = &default_quota($udom); + $quota = $defquota; + $quotatype = 'default'; + } else { + $quotatype = 'custom'; } } - return $quota; + if (wantarray) { + return ($quota,$quotatype,$settingstatus,$defquota); + } else { + return $quota; + } } ############################################### @@ -5075,32 +6103,68 @@ sub get_user_quota { =item * &default_quota() -Retrieves default quota assigned for storage of user portfolio files +Retrieves default quota assigned for storage of user portfolio files, +given an (optional) user's institutional status. Incoming parameters: 1. domain +2. (Optional) institutional status(es). This is a : separated list of + status types (e.g., faculty, staff, student etc.) + which apply to the user for whom the default is being retrieved. + If the institutional status string in undefined, the domain + default quota will be returned. Returns: 1. Default disk quota (in Mb) for user portfolios in the domain. +2. (Optional) institutional type which determined the value of the + default quota. If a value has been stored in the domain's configuration db, it will return that, otherwise it returns 20 (for backwards compatibility with domains which have not set up a configuration db file; the original statically defined portfolio quota was 20 Mb). +If the user's status includes multiple types (e.g., staff and student), +the largest default quota which applies to the user determines the +default quota returned. + =cut ############################################### sub default_quota { - my ($udom) = @_; - my %defaults = &Apache::lonnet::get_dom('configuration', - ['portfolioquota'],$udom); - if ($defaults{'portfolioquota'} ne '') { - return $defaults{'portfolioquota'}; + my ($udom,$inststatus) = @_; + my ($defquota,$settingstatus); + my %quotahash = &Apache::lonnet::get_dom('configuration', + ['quota'],$udom); + if (ref($quotahash{'quota'}) eq 'HASH') { + if ($inststatus ne '') { + my @statuses = split(/:/,$inststatus); + foreach my $item (@statuses) { + if ($quotahash{'quota'}{$item} ne '') { + if ($defquota eq '') { + $defquota = $quotahash{'quota'}{$item}; + $settingstatus = $item; + } elsif ($quotahash{'quota'}{$item} > $defquota) { + $defquota = $quotahash{'quota'}{$item}; + $settingstatus = $item; + } + } + } + } + if ($defquota eq '') { + $defquota = $quotahash{'quota'}{'default'}; + $settingstatus = 'default'; + } + } else { + $settingstatus = 'default'; + $defquota = 20; + } + if (wantarray) { + return ($defquota,$settingstatus); } else { - return '20'; + return $defquota; } } @@ -5141,8 +6205,291 @@ sub get_secgrprole_info { return (\@sections,\@groups,$allroles,$rolehash,$accesshash); } +sub user_picker { + my ($dom,$srch,$forcenewuser,$caller) = @_; + my $currdom = $dom; + my %curr_selected = ( + srchin => 'dom', + srchby => 'lastname', + ); + my $srchterm; + if (ref($srch) eq 'HASH') { + if ($srch->{'srchby'} ne '') { + $curr_selected{'srchby'} = $srch->{'srchby'}; + } + if ($srch->{'srchin'} ne '') { + $curr_selected{'srchin'} = $srch->{'srchin'}; + } + if ($srch->{'srchtype'} ne '') { + $curr_selected{'srchtype'} = $srch->{'srchtype'}; + } + if ($srch->{'srchdomain'} ne '') { + $currdom = $srch->{'srchdomain'}; + } + $srchterm = $srch->{'srchterm'}; + } + my %lt=&Apache::lonlocal::texthash( + 'usr' => 'Search criteria', + 'doma' => 'Domain/institution to search', + 'uname' => 'username', + 'lastname' => 'last name', + 'lastfirst' => 'last name, first name', + 'crs' => 'in this course', + 'dom' => 'in selected LON-CAPA domain', + 'alc' => 'all LON-CAPA', + 'instd' => 'in institutional directory for selected domain', + 'exact' => 'is', + 'contains' => 'contains', + 'begins' => 'begins with', + 'youm' => "You must include some text to search for.", + 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.", + 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.", + 'yomc' => "You must choose a domain when using an institutional directory search.", + 'ymcd' => "You must choose a domain when using a domain search.", + 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.", + 'whse' => "When searching by last,first you must include at least one character in the first name.", + 'thfo' => "The following need to be corrected before the search can be run:", + ); + my $domform = &select_dom_form($currdom,'srchdomain',1,1); + my $srchinsel = ' \n"; + + my $srchbysel = ' \n"; + + my $srchtypesel = ' \n"; + + my ($newuserscript,$new_user_create); + + if ($forcenewuser) { + if (ref($srch) eq 'HASH') { + if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) { + $new_user_create = '

&"').'" onclick="javascript:setSearch(\'1\','.$caller.');" />

'; + } + } + + $newuserscript = <<"ENDSCRIPT"; + +function setSearch(createnew,callingForm) { + if (createnew == 1) { + for (var i=0; i +function validateEntry(callingForm) { + + var checkok = 1; + var srchin; + for (var i=0; i + +$new_user_create + + + + + + + + + + + +
$lt{'doma'}:$domform
$lt{'usr'}:$srchbysel + $srchtypesel + + $srchinsel +
+
+END_BLOCK + + return $output; +} + +sub username_rule_check { + my ($srch,$caller) = @_; + my ($response,@curr_rules,%inst_results,$rulematch); + my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($srch->{'srchdomain'}); + if (ref($srch) eq 'HASH') { + (my $inst_response,%inst_results) = + &Apache::lonnet::get_instuser($srch->{'srchdomain'}, + $srch->{'srchterm'}); + my %domconfig = &Apache::lonnet::get_dom('configuration', + ['usercreation'],$srch->{'srchdomain'}); + if (ref($domconfig{'usercreation'}) eq 'HASH') { + if (ref($domconfig{'usercreation'}{'username_rule'}) eq 'ARRAY') { + @curr_rules = @{$domconfig{'usercreation'}{'username_rule'}}; + } + } + if (@curr_rules > 0) { + my $domdesc = &Apache::lonnet::domain($srch->{'srchdomain'},'description'); + my $instuser_reqd; + my %rule_check = &Apache::lonnet::inst_rulecheck($srch->{'srchdomain'},$srch->{'srchterm'},\@curr_rules); + foreach my $rule (@curr_rules) { + if ($rule_check{$rule}) { + $rulematch = $rule; + if ($inst_response eq 'ok') { + if (keys(%inst_results) == 0) { + if ($caller eq 'new') { + $response = &mt('The username you chose matches the format of usernames defined for [_1], but the user does not exist in the institutional directory.',$domdesc).'
'.&mt("You must choose a username with a different format -- one that will not conflict with 'official' institutional usernames."); + } + } + } + last; + } + } + if ($response) { + if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) { + if (@{$ruleorder} > 0) { + $response .= '
'.&mt('Usernames with the following format(s) may only be used for verified users at [_1]:',$domdesc).'
    '; + foreach my $rule (@{$ruleorder}) { + if (grep(/^\Q$rule\E$/,@curr_rules)) { + if (ref($rules->{$rule}) eq 'HASH') { + $response .= '
  • '.$rules->{$rule}{'name'}.': '. + $rules->{$rule}{'desc'}.'
  • '; + } + } + } + } + $response .= '
'; + } + } + } + } + return ($response,$rulematch,$rules,%inst_results); +} + =pod +=back + +=head1 HTTP Helpers + +=over 4 + =item * get_unprocessed_cgi($query,$possible_names) Modify the %env hash to contain unprocessed CGI form parameters held in @@ -5392,28 +6739,50 @@ sub record_sep { $i++; } } else { - my @allfields; + my $separator=','; if ($env{'form.upfiletype'} eq 'semisv') { - @allfields=split(/;/,$record); - } else { - @allfields=split(/\,/,$record); + $separator=';'; } my $i=0; - my $j; - for ($j=0;$j<=$#allfields;$j++) { - my $field=$allfields[$j]; - if ($field=~/^\s*(\"|\')/) { - my $delimiter=$1; - while (($field!~/$delimiter$/) && ($j<$#allfields)) { - $j++; - $field.=','.$allfields[$j]; - } - $field=~s/^\s*$delimiter//; - $field=~s/$delimiter\s*$//; - } - $components{&takeleft($i)}=$field; - $i++; +# the character we are looking for to indicate the end of a quote or a record + my $looking_for=$separator; +# do not add the characters to the fields + my $ignore=0; +# we just encountered a separator (or the beginning of the record) + my $just_found_separator=1; +# store the field we are working on here + my $field=''; +# work our way through all characters in record + foreach my $character ($record=~/(.)/g) { + if ($character eq $looking_for) { + if ($character ne $separator) { +# Found the end of a quote, again looking for separator + $looking_for=$separator; + $ignore=1; + } else { +# Found a separator, store away what we got + $components{&takeleft($i)}=$field; + $i++; + $just_found_separator=1; + $ignore=0; + $field=''; + } + next; + } +# single or double quotation marks after a separator indicate beginning of a quote +# we are now looking for the end of the quote and need to ignore separators + if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) { + $looking_for=$character; + next; + } +# ignore would be true after we reached the end of a quote + if ($ignore) { next; } + if (($just_found_separator) && ($character=~/\s/)) { next; } + $field.=$character; + $just_found_separator=0; } +# catch the very last entry, since we never encountered the separator + $components{&takeleft($i)}=$field; } return %components; } @@ -5484,20 +6853,21 @@ sub csv_print_samples { my ($r,$records) = @_; my $samples = &get_samples($records,3); - $r->print(&mt('Samples').'
'); + $r->print(&mt('Samples').'
'.&start_data_table(). + &start_data_table_header_row()); foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) { $r->print(''); } - $r->print(''); + $r->print(&end_data_table_header_row()); foreach my $hash (@$samples) { - $r->print(''); + $r->print(&start_data_table_row()); foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) { $r->print(''); } - $r->print(''); + $r->print(&end_data_table_row()); } - $r->print('
'.&mt('Column [_1]',($sample+1)).'
'); if (defined($$hash{$sample})) { $r->print($$hash{$sample}); } $r->print('

'."\n"); + $r->print(&end_data_table().'
'."\n"); } ###################################################### @@ -5522,12 +6892,13 @@ sub csv_print_select_table { my $i=0; my $samples = &get_samples($records,1); $r->print(&mt('Associate columns with student attributes.')."\n". - ''. + &start_data_table().&start_data_table_header_row(). ''. - ''."\n"); + ''. + &end_data_table_header_row()."\n"); foreach my $array_ref (@$d) { my ($value,$display,$defaultcol)=@{ $array_ref }; - $r->print(''); + $r->print(&start_data_table_row().''); $r->print(''."\n"); + $r->print(''.&end_data_table_row()."\n"); $i++; } + $r->print(&end_data_table()); $i--; return $i; } @@ -5566,11 +6938,13 @@ sub csv_samples_select_table { my $i=0; # my $samples = &get_samples($records,3); - $r->print('
'.&mt('Attribute').''.&mt('Column').'
'.&mt('Column').'
'.$display.'
'.$display.'
'); + $r->print(&start_data_table(). + &start_data_table_header_row().''. + &end_data_table_header_row()); foreach my $key (sort(keys(%{ $samples->[0] }))) { - $r->print(''); + $r->print(''.&end_data_table_row()); $i++; } + $r->print(&end_data_table()); $i--; return($i); } @@ -6180,35 +7555,53 @@ sub commit_customrole { } sub commit_standardrole { - my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec) = @_; - my $output; - my $logmsg; + my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_; + my ($output,$logmsg,$linefeed); + if ($context eq 'auto') { + $linefeed = "\n"; + } else { + $linefeed = "
\n"; + } if ($three eq 'st') { - my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec); - if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course')) { + my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end, + $one,$two,$sec,$context); + if (($result =~ /^error/) || ($result eq 'not_in_class') || + ($result eq 'unknown_course')) { $output = "Error: $result\n"; } else { - $output = &mt('Assigning').' '.$three.' in '.$url. + $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url. ($start?', '.&mt('starting').' '.localtime($start):''). - ($end?', '.&mt('ending').' '.localtime($end):''). - ': '.$result.'
'. - &mt('Add to classlist').': ok
'; + ($end?', '.&mt('ending').' '.localtime($end):'').': '; + if ($context eq 'auto') { + $output .= $result.$linefeed.&mt('Add to classlist').': ok'; + } else { + $output .= ''.$result.''.$linefeed. + &mt('Add to classlist').': ok'; + } + $output .= $linefeed; } } else { $output = &mt('Assigning').' '.$three.' in '.$url. ($start?', '.&mt('starting').' '.localtime($start):''). - ($end?', '.&mt('ending').' '.localtime($end):'').': '. - &Apache::lonnet::assignrole( - $udom,$uname,$url,$three,$end,$start). - '
'; + ($end?', '.&mt('ending').' '.localtime($end):'').': '; + my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start); + if ($context eq 'auto') { + $output .= $result.$linefeed; + } else { + $output .= ''.$result.''.$linefeed; + } } return $output; } sub commit_studentrole { - my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec) = @_; - my $linefeed = '
'."\n"; - my $result; + my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_; + my ($result,$linefeed); + if ($context eq 'auto') { + $linefeed = "\n"; + } else { + $linefeed = '
'."\n"; + } if (defined($one) && defined($two)) { my $cid=$one.'_'.$two; my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid); @@ -6254,9 +7647,70 @@ sub commit_studentrole { ############################################################ ############################################################ +sub check_clone { + my ($args,$linefeed) = @_; + my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'}; + my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid); + my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom); + my $clonemsg; + my $can_clone = 0; + + if ($clonehome eq 'no_host') { + $clonemsg = &mt('No new course created.').$linefeed.&mt('A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.',$args->{'clonecourse'}.':'.$args->{'clonedomain'}); + } else { + my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1}); + if ($env{'request.role.domain'} eq $args->{'clonedomain'}) { + $can_clone = 1; + } else { + my %clonehash = &Apache::lonnet::get('environment',['cloners'], + $args->{'clonedomain'},$args->{'clonecourse'}); + my @cloners = split(/,/,$clonehash{'cloners'}); + if (grep(/^\*$/,@cloners)) { + $can_clone = 1; + } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) { + $can_clone = 1; + } else { + my %roleshash = + &Apache::lonnet::get_my_roles($args->{'ccuname'}, + $args->{'ccdomain'}, + 'userroles',['active'],['cc'], + [$args->{'clonedomain'}]); + if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) { + $can_clone = 1; + } else { + $clonemsg = &mt('No new course created.').$linefeed.&mt('The new course could not be cloned from the existing course because the new course owner ([_1]) does not have cloning rights in the existing course ([_2]).',$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}); + } + } + } + } + return ($can_clone, $clonemsg, $cloneid, $clonehome); +} + sub construct_course { - my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname) = @_; + my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_; my $outcome; + my $linefeed = '
'."\n"; + if ($context eq 'auto') { + $linefeed = "\n"; + } + +# +# Are we cloning? +# + my ($can_clone, $clonemsg, $cloneid, $clonehome); + if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) { + ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed); + if ($context ne 'auto') { + if ($clonemsg ne '') { + $clonemsg = ''.$clonemsg.''; + } + } + $outcome .= $clonemsg.$linefeed; + + if (!$can_clone) { + return (0,$outcome); + } + } # # Open course @@ -6277,44 +7731,40 @@ sub construct_course { # Utils::Course. This needs to at least be output as a comment # if anyone ever decides to not show this, and Utils::Course::new # will need to be suitably modified. - $outcome .= &mt('New LON-CAPA [_1] ID: [_2]
',$crstype,$$courseid); + $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed; # # Check if created correctly # ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid); my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom); - $outcome .= &mt('Created on').': '.$crsuhome.'
'; -# -# Are we cloning? + $outcome .= &mt('Created on').': '.$crsuhome.$linefeed; + # - my $cloneid=''; - if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) { - $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'}; - my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid); - my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom); - if ($clonehome eq 'no_host') { - $outcome .= - '
'.&mt('Attempting to clone non-existing [_1]',$crstype).' '.$cloneid.''; - } else { - $outcome .= - '
'.&mt('Cloning [_1] from [_2]',$crstype,$clonehome).''; - my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum); +# Do the cloning +# + if ($can_clone && $cloneid) { + $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome); + if ($context ne 'auto') { + $clonemsg = ''.$clonemsg.''; + } + $outcome .= $clonemsg.$linefeed; + my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum); # Copy all files - &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid); + &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid); # Restore URL - $cenv{'url'}=$oldcenv{'url'}; + $cenv{'url'}=$oldcenv{'url'}; # Restore title - $cenv{'description'}=$oldcenv{'description'}; + $cenv{'description'}=$oldcenv{'description'}; # restore grading mode - if (defined($oldcenv{'grading'})) { - $cenv{'grading'}=$oldcenv{'grading'}; - } -# Mark as cloned - $cenv{'clonedfrom'}=$cloneid; - delete($cenv{'default_enrollment_start_date'}); - delete($cenv{'default_enrollment_end_date'}); + if (defined($oldcenv{'grading'})) { + $cenv{'grading'}=$oldcenv{'grading'}; } +# Mark as cloned + $cenv{'clonedfrom'}=$cloneid; + delete($cenv{'default_enrollment_start_date'}); + delete($cenv{'default_enrollment_end_date'}); } + # # Set environment (will override cloned, if existing) # @@ -6418,11 +7868,24 @@ sub construct_course { 'dnhr' => 'does not have rights to access enrollment in these classes', 'adby' => 'as determined by the policies of your institution on access to official classlists' ); - $outcome .= ''.$lt{'tclb'}.' ('.$cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.' ('.$lt{'adby'}.').
    '."\n"; - foreach (@badclasses) { - $outcome .= "
  • $_
  • \n"; - } - $outcome .= "


\n"; + my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}. + ' ('.$lt{'adby'}.')'; + if ($context eq 'auto') { + $outcome .= $badclass_msg.$linefeed; + $outcome .= '
'.$badclass_msg.$linefeed.'
    '."\n"; + foreach my $item (@badclasses) { + if ($context eq 'auto') { + $outcome .= " - $item\n"; + } else { + $outcome .= "
  • $item
  • \n"; + } + } + if ($context eq 'auto') { + $outcome .= $linefeed; + } else { + $outcome .= "


\n"; + } + } } if ($args->{'no_end_date'}) { $args->{'endaccess'} = 0; @@ -6438,8 +7901,13 @@ sub construct_course { $cenv{'internal.autharg'} = $args->{'autharg'}; if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) { if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') { - $outcome .= ''. - &mt('As you did not include the default Kerberos domain to be used for authentication in this class, the institutional data used by the automated enrollment process must include the Kerberos domain for each new student').'

'; + my $krb_msg = &mt('As you did not include the default Kerberos domain to be used for authentication in this class, the institutional data used by the automated enrollment process must include the Kerberos domain for each new student'); + if ($context eq 'auto') { + $outcome .= $krb_msg; + } else { + $outcome .= ''.$krb_msg.''; + } + $outcome .= $linefeed; } } if (($args->{'ccdomain'}) && ($args->{'ccuname'})) { @@ -6495,8 +7963,8 @@ sub construct_course { # By default, use standard grading if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; } - $outcome .= ('
'.&mt('Setting environment').': '. - &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).'
'); + $outcome .= $linefeed.&mt('Setting environment').': '. + &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed; # # Open all assignments # @@ -6506,7 +7974,7 @@ sub construct_course { $storeunder.'.type' => 'date_start'); $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput - ('resourcedata',\%storecontent,$$crsudom,$$crsunum).'
'; + ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed; } # # Set first page @@ -6533,9 +8001,10 @@ sub construct_course { (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1); if ($errtext) { $fatal=2; } - $outcome .= ($fatal?$errtext:'write ok').'
'; + $outcome .= ($fatal?$errtext:'write ok').$linefeed; } - return $outcome; + + return (1,$outcome); } ############################################################ @@ -6564,7 +8033,7 @@ sub group_term { sub icon { my ($file)=@_; - my $curfext = (split(/\./,$file))[-1]; + my $curfext = lc((split(/\./,$file))[-1]); my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif'; my $embstyle = &Apache::loncommon::fileembstyle($curfext); if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) { @@ -6578,10 +8047,27 @@ sub icon { return &lonhttpdurl($iconname); } -sub lonhttpdurl { - my ($url)=@_; +sub lonhttpd_port { my $lonhttpd_port=$Apache::lonnet::perlvar{'lonhttpdPort'}; if (!defined($lonhttpd_port)) { $lonhttpd_port='8080'; } + # IE doesn't like a secure page getting images from a non-secure + # port (when logging we haven't parsed the browser type so default + # back to secure + if ((!exists($env{'browser.type'}) || $env{'browser.type'} eq 'explorer') + && $ENV{'SERVER_PORT'} == 443) { + return 443; + } + return $lonhttpd_port; + +} + +sub lonhttpdurl { + my ($url)=@_; + + my $lonhttpd_port = &lonhttpd_port(); + if ($lonhttpd_port == 443) { + return 'https://'.$ENV{'SERVER_NAME'}.$url; + } return 'http://'.$ENV{'SERVER_NAME'}.':'.$lonhttpd_port.$url; }
'. - &mt('Field').''.&mt('Samples').'
'. + &mt('Field').''.&mt('Samples').'