--- loncom/interface/loncommon.pm 2006/09/12 22:13:05 1.453 +++ loncom/interface/loncommon.pm 2006/11/01 22:22:31 1.467 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common routines # -# $Id: loncommon.pm,v 1.453 2006/09/12 22:13:05 albertel Exp $ +# $Id: loncommon.pm,v 1.467 2006/11/01 22:22:31 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -2067,6 +2067,27 @@ sub getnames { } } +sub getemails { + my ($uname,$udom)=@_; + if ($udom eq 'public' && $uname eq 'public') { + return; + } + if (!$udom) { $udom=$env{'user.domain'}; } + if (!$uname) { $uname=$env{'user.name'}; } + my $id=$uname.':'.$udom; + my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id); + if ($cached) { + return %{$names}; + } else { + my %loadnames=&Apache::lonnet::get('environment', + ['notification','critnotification', + 'permanentemail'], + $udom,$uname); + &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames); + return %loadnames; + } +} + # ------------------------------------------------------------------ Screenname =pod @@ -2111,7 +2132,7 @@ sub aboutmewrapper { return; } return ''.$link.''; + ($target?' target="$target"':'').' title="'.&mt("View this user's personal page").'">'.$link.''; } # ------------------------------------------------------------ Syllabus Wrapper @@ -2353,7 +2374,8 @@ sub preferred_languages { $env{'course.'.$env{'request.course.id'}.'.languages'})); } if ($env{'environment.languages'}) { - @languages=split(/\s*(\,|\;|\:)\s*/,$env{'environment.languages'}); + @languages=(@languages, + split(/\s*(\,|\;|\:)\s*/,$env{'environment.languages'})); } my $browser=(split(/\;/,$ENV{'HTTP_ACCEPT_LANGUAGE'}))[0]; if ($browser) { @@ -2595,7 +2617,7 @@ sub submlink { my ($text,$uname,$udom,$symb,$target)=@_; if (!($uname && $udom)) { (my $cursymb, my $courseid,$udom,$uname)= - &Apache::lonxml::whichuser($symb); + &Apache::lonnet::whichuser($symb); if (!$symb) { $symb=$cursymb; } } if (!$symb) { $symb=&Apache::lonnet::symbread(); } @@ -2641,7 +2663,7 @@ sub pprmlink { my ($text,$uname,$udom,$symb,$target)=@_; if (!($uname && $udom)) { (my $cursymb, my $courseid,$udom,$uname)= - &Apache::lonxml::whichuser($symb); + &Apache::lonnet::whichuser($symb); if (!$symb) { $symb=$cursymb; } } if (!$symb) { $symb=&Apache::lonnet::symbread(); } @@ -2853,6 +2875,9 @@ Inputs: =item * $no_inline_link, if true and in remote mode, don't show the 'Switch To Inline Menu' link +=item * $args, optional argument valid values are + no_auto_mt_title -> prevents &mt()ing the title arg + =back Returns: A uniform header for LON-CAPA web pages. @@ -2864,9 +2889,9 @@ other decorations will be returned. sub bodytag { my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,$customtitle, - $notopbar,$bgcolor,$notitle,$no_inline_link)=@_; + $notopbar,$bgcolor,$notitle,$no_inline_link,$args)=@_; - $title=&mt($title); + if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); } $function = &get_users_function() if (!$function); my $img = &designparm($function.'.img',$domain); @@ -3199,16 +3224,23 @@ form, .inline { display: inline; } color: red; font-size: larger; } -.LC_warning { +.LC_warning, +.LC_diff_removed { color: red; } -.LC_success { +.LC_success, +.LC_diff_added { color: green; } .LC_icon { border: 0px; } +table.LC_pastsubmission { + border: 1px solid black; + margin: 2px; +} + table#LC_top_nav, table#LC_menubuttons { width: 100%; background: $pgbg; @@ -3377,6 +3409,10 @@ table.LC_whatsnew tr.LC_empty_row td { text-align: center; padding: 8px; } +table.LC_whatsnew tr.LC_empty_row td { + padding: 4ex +} + table.LC_whatsnew { } @@ -3499,7 +3535,8 @@ table#LC_browser tr.LC_browser_file_unpu table#LC_browser tr.LC_browser_file_obsolete { background: #AAAAAA; } -table#LC_browser tr.LC_browser_file_modified { +table#LC_browser tr.LC_browser_file_modified, +table#LC_browser tr.LC_browser_file_metamodified { background: #FFFF77; } table#LC_browser tr.LC_browser_folder { @@ -3714,6 +3751,8 @@ Inputs: $title - optional title for the domain function -> force usage of a specific rolish color scheme bgcolor -> override the default page bgcolor + no_auto_mt_title + -> prevent &mt()ing the title arg =back @@ -3726,8 +3765,8 @@ sub headtag { my $domain = $args->{'domain'} || &determinedomain(); my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain); my $url = join(':',$env{'user.name'},$env{'user.domain'}, - #time(), $Apache::lonnet::perlvar{'lonVersion'}, + #time(), $env{'environment.color.timestamp'}, $function,$domain,$bgcolor); @@ -3735,9 +3774,11 @@ sub headtag { my $result = ''. - &font_settings(). - &Apache::lonhtmlcommon::htmlareaheaders(); + &font_settings(); + if (!$args->{'frameset'}) { + $result .= &Apache::lonhtmlcommon::htmlareaheaders(); + } if ($args->{'force_register'}) { $result .= &Apache::lonmenu::registerurl(1); } @@ -3761,8 +3802,8 @@ ADDMETA if (!defined($title)) { $title = 'The LearningOnline Network with CAPA'; } - - $result .= ' LON-CAPA '.&mt($title).'' + if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); } + $result .= ' LON-CAPA '.$title.'' .'' .$head_extra; return $result; @@ -3906,6 +3947,8 @@ Inputs: $title - optional title for the no_inline_link -> if true and in remote mode, don't show the 'Switch To Inline Menu' link + no_auto_mt_title -> prevent &mt()ing the title arg + =back =cut @@ -3915,7 +3958,8 @@ sub start_page { #&Apache::lonnet::logthis("start_page ".join(':',caller(0))); my %head_args; foreach my $arg ('redirect','force_register','domain','function', - 'bgcolor','frameset','no_nav_bar','only_body') { + 'bgcolor','frameset','no_nav_bar','only_body', + 'no_auto_mt_title') { if (defined($args->{$arg})) { $head_args{$arg} = $args->{$arg}; } @@ -3941,7 +3985,8 @@ sub start_page { $args->{'only_body'}, $args->{'domain'}, $args->{'force_register'}, $args->{'body_title'}, $args->{'no_nav_bar'}, $args->{'bgcolor'}, - $args->{'no_title'}, $args->{'no_inline_link'}); + $args->{'no_title'}, $args->{'no_inline_link'}, + $args); } } @@ -4657,7 +4702,7 @@ sub get_env_multiple { =pod -=back +=back =head1 CSV Upload/Handling functions @@ -5950,15 +5995,6 @@ sub lonhttpdurl { return 'http://'.$ENV{'SERVER_NAME'}.':'.$lonhttpd_port.$url; } -sub absolute_url { - my ($host_name) = @_; - my $protocol = ($ENV{'SERVER_PORT'} == 443?'https://':'http://'); - if ($host_name eq '') { - $host_name = $ENV{'SERVER_NAME'}; - } - return $protocol.$host_name; -} - sub connection_aborted { my ($r)=@_; $r->print(" ");$r->rflush(); @@ -5991,6 +6027,171 @@ sub escape_url { my $lastitem = &escape(pop(@urlslices)); return join('/',@urlslices).'/'.$lastitem; } + +# -------------------------------------------------------- Initliaze user login +sub init_user_environment { + my ($r, $username, $domain, $authhost, $form, $args) = @_; + my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'}; + + my $public=($username eq 'public' && $domain eq 'public'); + +# See if old ID present, if so, remove + + my ($filename,$cookie,$userroles); + my $now=time; + + if ($public) { + my $max_public=100; + my $oldest; + my $oldest_time=0; + for(my $next=1;$next<=$max_public;$next++) { + if (-e $lonids."/publicuser_$next.id") { + my $mtime=(stat($lonids."/publicuser_$next.id"))[9]; + if ($mtime<$oldest_time || !$oldest_time) { + $oldest_time=$mtime; + $oldest=$next; + } + } else { + $cookie="publicuser_$next"; + last; + } + } + if (!$cookie) { $cookie="publicuser_$oldest"; } + } else { + # if this isn't a robot, kill any existing non-robot sessions + if (!$args->{'robot'}) { + opendir(DIR,$lonids); + while ($filename=readdir(DIR)) { + if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) { + unlink($lonids.'/'.$filename); + } + } + closedir(DIR); + } +# Give them a new cookie + my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'} + : $now); + $cookie="$username\_$id\_$domain\_$authhost"; + +# Initialize roles + + $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost); + } +# ------------------------------------ Check browser type and MathML capability + + my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml, + $clientunicode,$clientos) = &decode_user_agent($r); + +# -------------------------------------- Any accessibility options to remember? + if (($form->{'interface'}) && ($form->{'remember'} eq 'true')) { + foreach my $option ('imagesuppress','appletsuppress', + 'embedsuppress','fontenhance','blackwhite') { + if ($form->{$option} eq 'true') { + &Apache::lonnet::put('environment',{$option => 'on'}, + $domain,$username); + } else { + &Apache::lonnet::del('environment',[$option], + $domain,$username); + } + } + } +# ------------------------------------------------------------- Get environment + + my %userenv = &Apache::lonnet::dump('environment',$domain,$username); + my ($tmp) = keys(%userenv); + if ($tmp !~ /^(con_lost|error|no_such_host)/i) { + # default remote control to off + if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; } + } else { + undef(%userenv); + } + if (($userenv{'interface'}) && (!$form->{'interface'})) { + $form->{'interface'}=$userenv{'interface'}; + } + $env{'environment.remote'}=$userenv{'remote'}; + if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; } + +# --------------- Do not trust query string to be put directly into environment + foreach my $option ('imagesuppress','appletsuppress', + 'embedsuppress','fontenhance','blackwhite', + 'interface','localpath','localres') { + $form->{$option}=~s/[\n\r\=]//gs; + } +# --------------------------------------------------------- Write first profile + + { + my %initial_env = + ("user.name" => $username, + "user.domain" => $domain, + "user.home" => $authhost, + "browser.type" => $clientbrowser, + "browser.version" => $clientversion, + "browser.mathml" => $clientmathml, + "browser.unicode" => $clientunicode, + "browser.os" => $clientos, + "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'}, + "request.course.fn" => '', + "request.course.uri" => '', + "request.course.sec" => '', + "request.role" => 'cm', + "request.role.adv" => $env{'user.adv'}, + "request.host" => $ENV{'REMOTE_ADDR'},); + + if ($form->{'localpath'}) { + $initial_env{"browser.localpath"} = $form->{'localpath'}; + $initial_env{"browser.localres"} = $form->{'localres'}; + } + + if ($public) { + $initial_env{"environment.remote"} = "off"; + } + if ($form->{'interface'}) { + $form->{'interface'}=~s/\W//gs; + $initial_env{"browser.interface"} = $form->{'interface'}; + $env{'browser.interface'}=$form->{'interface'}; + foreach my $option ('imagesuppress','appletsuppress', + 'embedsuppress','fontenhance','blackwhite') { + if (($form->{$option} eq 'true') || + ($userenv{$option} eq 'on')) { + $initial_env{"browser.$option"} = "on"; + } + } + } + + $env{'user.environment'} = "$lonids/$cookie.id"; + + if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id", + &GDBM_WRCREAT(),0640)) { + &_add_to_env(\%disk_env,\%initial_env); + &_add_to_env(\%disk_env,\%userenv,'environment.'); + &_add_to_env(\%disk_env,$userroles); + if (ref($args->{'extra_env'})) { + &_add_to_env(\%disk_env,$args->{'extra_env'}); + } + untie(%disk_env); + } else { + &Apache::lonnet::logthis("WARNING: ". + 'Could not create environment storage in lonauth: '.$!.''); + return 'error: '.$!; + } + } + $env{'request.role'}='cm'; + $env{'request.role.adv'}=$env{'user.adv'}; + $env{'browser.type'}=$clientbrowser; + + return $cookie; + +} + +sub _add_to_env { + my ($idf,$env_data,$prefix) = @_; + while (my ($key,$value) = each(%$env_data)) { + $idf->{$prefix.$key} = $value; + $env{$prefix.$key} = $value; + } +} + + =pod =back