--- loncom/interface/loncommon.pm 2006/09/05 20:42:18 1.449 +++ loncom/interface/loncommon.pm 2006/11/23 00:04:09 1.473 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common routines # -# $Id: loncommon.pm,v 1.449 2006/09/05 20:42:18 albertel Exp $ +# $Id: loncommon.pm,v 1.473 2006/11/23 00:04:09 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -257,7 +257,7 @@ of the element the selection from the se sub browser_and_searcher_javascript { my ($mode)=@_; if (!defined($mode)) { $mode='edit'; } - my $resurl=&lastresurl(); + my $resurl=&escape_single(&lastresurl()); return < -1) { + var domid = getIndexByName(formid,udom); + if (domid > -1) { + if (document.forms[formid].elements[domid].type == 'select-one') { + domainfilter=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value; + } + if (document.forms[formid].elements[domid].type == 'hidden') { + domainfilter=document.forms[formid].elements[domid].value; + } + } } - var domainfilter='$domainfilter'; if (domainfilter != null) { if (domainfilter != '') { url += 'domainfilter='+domainfilter+'&'; @@ -408,11 +415,18 @@ sub coursebrowser_javascript { url += 'form=' + formname + '&cnumelement='+uname+ '&cdomelement='+udom+ '&cnameelement='+desc; - if (extra_element !=null && extra_element != '' && formname == 'rolechoice') { - url += '&roleelement='+extra_element; - if (domainfilter == null || domainfilter == '') { - url += '&domainfilter='+extra_element; + if (extra_element !=null && extra_element != '') { + if (formname == 'rolechoice') { + url += '&roleelement='+extra_element; + if (domainfilter == null || domainfilter == '') { + url += '&domainfilter='+extra_element; + } } + else { + if (formname == 'portform') { + url += '&setroles='+extra_element; + } + } } if (multflag !=null && multflag != '') { url += '&multiple='+multflag; @@ -435,10 +449,70 @@ sub coursebrowser_javascript { stdeditbrowser = open(url,title,options,'1'); stdeditbrowser.focus(); } - + + function getFormIdByName(formname) { + for (var i=0;i'.$link.''; + ($target?' target="$target"':'').' title="'.&mt("View this user's personal page").'">'.$link.''; } # ------------------------------------------------------------ Syllabus Wrapper @@ -2353,7 +2448,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 +2691,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 +2737,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 +2949,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 +2963,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); @@ -3169,8 +3268,8 @@ sub standard_css { my $mono = 'monospace'; my $data_table_head = $tabbg; my $data_table_light = '#EEEEEE'; - my $data_table_dark = '#DDD'; - my $data_table_darker = '#CCC'; + my $data_table_dark = '#DDDDDD'; + my $data_table_darker = '#CCCCCC'; my $data_table_highlight = '#FFFF00'; my $mail_new = '#FFBB77'; my $mail_new_hover = '#DD9955'; @@ -3199,16 +3298,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; @@ -3248,6 +3354,9 @@ table#LC_title_bar td.LC_title_bar_who { font: small $sans; text-align: right; } +span.LC_metadata { + font-family: $sans; +} span.LC_title_bar_title { font: bold x-large $sans; } @@ -3369,13 +3478,54 @@ table.LC_aboutme_port tr.LC_even_row td table.LC_data_table tr.LC_data_table_highlight td { background-color: $data_table_darker; } -table.LC_data_table tr.LC_empty_row td { +table.LC_data_table tr.LC_empty_row td, +table.LC_whatsnew 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 { + padding: 4ex +} + + +table.LC_whatsnew { +} + +table.LC_whatsnew tr th, +table.LC_whatsnew tr.LC_info_row td { + background-color: #CCC; + font-weight: bold; + font-size: small; + text-align: right; +} +table.LC_whatsnew tr td { + background-color: #FFF; + font-size: small; + text-align: right; +} +table.LC_whatsnew tr td.LC_first_item { + text-align: left; +} + +table.LC_whatsnew tr.LC_odd_row td { + background-color: #EEE; +} + +table.LC_createuser { +} + +table.LC_createuser tr.LC_section_row td { + font-size: smaller; +} + +table.LC_createuser tr.LC_info_row td { + background-color: #CCC; + font-weight: bold; + text-align: center; +} table.LC_calendar { border: 1px solid #000000; @@ -3475,7 +3625,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 { @@ -3690,6 +3841,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 @@ -3702,6 +3855,7 @@ sub headtag { my $domain = $args->{'domain'} || &determinedomain(); my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain); my $url = join(':',$env{'user.name'},$env{'user.domain'}, + $Apache::lonnet::perlvar{'lonVersion'}, #time(), $env{'environment.color.timestamp'}, $function,$domain,$bgcolor); @@ -3710,9 +3864,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); } @@ -3736,8 +3892,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; @@ -3881,6 +4037,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 @@ -3890,7 +4048,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}; } @@ -3916,7 +4075,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); } } @@ -4056,6 +4216,13 @@ sub simple_error_page { $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'; + $css_class = (join(' ',$css_class,$add_class)); + return ''."\n";; + } sub end_data_table_row { return ''."\n";; @@ -4458,6 +4625,96 @@ sub get_user_info { return; } +############################################### + +=pod + +=item * &get_user_quota() + +Retrieves quota assigned for storage of portfolio files for a user + +Incoming parameters: +1. user's username +2. user's domain + +Returns: +1. Disk quota (in Mb) assigned to student. + +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. + +=cut + +############################################### + + +sub get_user_quota { + my ($uname,$udom) = @_; + my $quota; + if (!defined($udom)) { + $udom = $env{'user.domain'}; + } + if (!defined($uname)) { + $uname = $env{'user.name'}; + } + if (($udom eq '' || $uname eq '') || + ($udom eq 'public') && ($uname eq 'public')) { + $quota = 0; + } else { + if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) { + $quota = $env{'environment.portfolioquota'}; + } else { + my %userenv = &Apache::lonnet::dump('environment',$udom,$uname); + my ($tmp) = keys(%userenv); + if ($tmp !~ /^(con_lost|error|no_such_host)/i) { + $quota = $userenv{'portfolioquota'}; + } else { + undef(%userenv); + } + } + if ($quota eq '') { + $quota = &default_quota($udom); + } + } + return $quota; +} + +############################################### + +=pod + +=item * &default_quota() + +Retrieves default quota assigned for storage of user portfolio files + +Incoming parameters: +1. domain + +Returns: +1. Default disk quota (in Mb) for user portfolios in the domain. + +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). + +=cut + +############################################### + + +sub default_quota { + my ($udom) = @_; + my %defaults = &Apache::lonnet::get_dom('configuration', + ['portfolioquota'],$udom); + if ($defaults{'portfolioquota'} ne '') { + return $defaults{'portfolioquota'}; + } else { + return '20'; + } +} + sub get_secgrprole_info { my ($cdom,$cnum,$needroles,$type) = @_; my %sections_count = &get_sections($cdom,$cnum); @@ -4632,7 +4889,7 @@ sub get_env_multiple { =pod -=back +=back =head1 CSV Upload/Handling functions @@ -5925,15 +6182,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(); @@ -5966,6 +6214,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