--- loncom/interface/loncommon.pm 2006/06/26 22:06:19 1.398 +++ loncom/interface/loncommon.pm 2006/07/04 22:02:14 1.420 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common routines # -# $Id: loncommon.pm,v 1.398 2006/06/26 22:06:19 albertel Exp $ +# $Id: loncommon.pm,v 1.420 2006/07/04 22:02:14 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -707,7 +707,7 @@ sub helpLatexCheatsheet { } sub help_open_menu { - my ($color,$topic,$component_help,$function,$faq,$bug,$stayOnPage,$width,$height,$text) = @_; + my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text) = @_; $text = "" if (not defined $text); $stayOnPage = 0 if (not defined $stayOnPage); if ($env{'browser.interface'} eq 'textual' || @@ -721,8 +721,7 @@ sub help_open_menu { my $origurl = $ENV{'REQUEST_URI'}; $origurl=~s|^/~|/priv/|; my $timestamp = time; - foreach my $datum (\$color,\$function,\$topic,\$component_help,\$faq, - \$bug,\$origurl) { + foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) { $$datum = &escape($$datum); } if (!$stayOnPage) { @@ -730,8 +729,8 @@ sub help_open_menu { } else { $link = "javascript:helpMenu('display')"; } - my $banner_link = "/adm/helpmenu?page=banner&function=$function&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage"; - my $details_link = "/adm/helpmenu?page=body&function=$function&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp"; + my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage"; + my $details_link = "/adm/helpmenu?page=body&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp"; my $template; if ($text ne "") { $template .= @@ -2726,16 +2725,8 @@ Returns: value of designparamter $which =cut -sub designparm { - my ($which,$domain)=@_; - my $result = &designparm_real(@_); - &Apache::lonnet::logthis(" $which $domain reulted in $result"); - return $result; -} - - ############################################## -sub designparm_real { +sub designparm { my ($which,$domain)=@_; if ($env{'browser.blackwhite'} eq 'on') { if ($which=~/\.(font|alink|vlink|link)$/) { @@ -2805,7 +2796,6 @@ Inputs: =item * $no_inline_link, if true and in remote mode, don't show the 'Switch To Inline Menu' link - =back Returns: A uniform header for LON-CAPA web pages. @@ -2876,15 +2866,12 @@ sub bodytag { return $bodytag; } - + my $name = &plainname($env{'user.name'},$env{'user.domain'}); my $roleinfo=(<
- $env{'environment.firstname'} - $env{'environment.middlename'} - $env{'environment.lastname'} - $env{'environment.generation'} + $name  
@@ -2935,7 +2922,7 @@ ENDROLE $lastitem = $thisdisfn; } $titleinfo = - &Apache::loncommon::help_open_menu('','','','',3,'Authoring'). + &Apache::loncommon::help_open_menu('','',3,'Authoring'). 'Construction Space: '. '
' @@ -3156,10 +3143,11 @@ table#LC_top_nav, table#LC_menubuttons { width: 100%; background: $pgbg; border: 2px; - border-collapse: seperate; + border-collapse: separate; + padding: 0px; } -table#LC_title_bar, table#LC_breadcrumbs, table#LC_nav_location, +table#LC_title_bar, table.LC_breadcrumbs, table#LC_nav_location, table#LC_title_bar.LC_with_remote { width: 100%; border-color: $pgbg; @@ -3169,10 +3157,19 @@ table#LC_title_bar.LC_with_remote { background: $pgbg; font-family: $sans; border-collapse: collapse; + padding: 0px; +} + +table.LC_docs_path { + width: 100%; + border: 0; + background: $pgbg; + font-family: $sans; + border-collapse: collapse; + padding: 0px; } table#LC_title_bar td { - padding: 3px; background: $tabbg; } table#LC_title_bar td.LC_title_bar_who { @@ -3182,7 +3179,7 @@ table#LC_title_bar td.LC_title_bar_who { text-align: right; } span.LC_title_bar_title { - font: bold xx-large $sans; + font: bold x-large $sans; } table#LC_title_bar td.LC_title_bar_domain_logo { background: $sidebg; @@ -3208,6 +3205,7 @@ table#LC_menubuttons img, table#LC_menub table#LC_top_nav td { background: $tabbg; border: 0px; + font-size: small; } table#LC_top_nav td a, div#LC_top_nav a { color: $font; @@ -3216,14 +3214,21 @@ table#LC_top_nav td a, div#LC_top_nav a table#LC_top_nav td.LC_top_nav_logo { background: $tabbg; text-align: right; + white-space: nowrap; + font-weight: bold; +} +table#LC_top_nav td.LC_top_nav_logo img { + margin-left: 0.2em; + vertical-align: bottom; } -table#LC_breadcrumbs td { +table.LC_breadcrumbs td, table.LC_docs_path td { background: $tabbg; color: $font; font-family: $sans; font-size: smaller; } -table#LC_breadcrumbs td.LC_breadcrumb_component { +table.LC_breadcrumbs td.LC_breadcrumbs_component, +table.LC_docs_path td.LC_docs_path_component { background: $tabbg; color: $font; font-family: $sans; @@ -3258,7 +3263,7 @@ td.LC_menubuttons_img { table.LC_data_table, table.LC_mail_list { border: 1px solid #000000; - border-collapse: seperate; + border-collapse: separate; } table.LC_data_table tr th, table.LC_calendar tr th, table.LC_mail_list tr th { font-weight: bold; @@ -3442,6 +3447,8 @@ table#LC_helpmenu_links { table#LC_helpmenu_links tr td { padding: 1px; background: $tabbg; + text-align: center; + font-weight: bold; } table#LC_helpmenu_links a:link, table#LC_helpmenu_links a:visited, @@ -3454,6 +3461,19 @@ table#LC_helpmenu_links a:hover { color: $vlink; } +.LC_chrt_popup_exists { + border: 1px solid #339933; + margin: -1px; +} +.LC_chrt_popup_up { + border: 1px solid yellow; + margin: -1px; +} +.LC_chrt_popup { + border: 1px solid #8888FF; + background: #CCCCFF; +} + END } @@ -3470,8 +3490,10 @@ Inputs: $title - optional title for the $args - optional arguments force_register - if is true call registerurl so the remote is informed - redirect -> array ref of seconds before redirect occurs - url to redirect to + redirect -> array ref of + 1- seconds before redirect occurs + 2- url to redirect to + 3- whether the side effect should occur (side effect of setting $env{'internal.head.redirect'} to the url redirected too) @@ -3490,15 +3512,15 @@ sub headtag { my $function = $args->{'function'} || &get_users_function(); my $domain = $args->{'domain'} || &determinedomain(); my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain); - my $url = join(':',$env{'user.name'},$env{'user.domain'},time(), - #$env{'environment.color.timestamp'}, + my $url = join(':',$env{'user.name'},$env{'user.domain'}, + #time(), + $env{'environment.color.timestamp'}, $function,$domain,$bgcolor); $url = '/adm/css/'.&escape($url).'.css'; my $result = ''. - ''. &font_settings(). &Apache::lonhtmlcommon::htmlareaheaders(); @@ -3507,9 +3529,11 @@ sub headtag { } if (ref($args->{'redirect'})) { - my ($time,$url) = @{$args->{'redirect'}}; + my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}}; $url = &Apache::lonenc::check_encrypt($url); - $env{'internal.head.redirect'} = $url; + if (!$inhibit_continue) { + $env{'internal.head.redirect'} = $url; + } $result.=< @@ -3519,7 +3543,9 @@ ADDMETA $title = 'The LearningOnline Network with CAPA'; } - $result .= ' LON-CAPA '.&mt($title).''.$head_extra; + $result .= ' LON-CAPA '.&mt($title).'' + .'' + .$head_extra; return $result; } @@ -3611,6 +3637,7 @@ Returns a uniform complete .. + =back =cut @@ -3724,7 +3751,6 @@ Inputs: $args - additional optio a html attribute frameset -> if true will start with a rather than -=back =cut @@ -3849,9 +3875,7 @@ sub simple_error_page { =pod -=over 4 - -=item get_users_function +=item * &get_users_function() Used by &bodytag to determine the current users primary role. Returns either 'student','coordinator','admin', or 'author'. @@ -3878,7 +3902,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. @@ -3893,33 +3917,35 @@ role status: active, previous or future. =cut sub check_user_status { - my ($udom,$uname,$cdom,$crs,$role,$secgrp) = @_; + my ($udom,$uname,$cdom,$crs,$role,$sec) = @_; my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname); my @uroles = keys %userinfo; my $srchstr; my $active_chk = 'none'; + my $now = time; if (@uroles > 0) { - if (($role eq 'cc') || ($secgrp eq '') || (!defined($secgrp))) { + if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) { $srchstr = '/'.$cdom.'/'.$crs.'_'.$role; } else { - $srchstr = '/'.$cdom.'/'.$crs.'/'.$secgrp.'_'.$role; } - if (grep/^$srchstr$/,@uroles) { + $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role; + } + if (grep/^\Q$srchstr\E$/,@uroles) { my $role_end = 0; my $role_start = 0; $active_chk = 'active'; - if ($userinfo{$srchstr} =~ m/^($role)_(\d+)/) { - $role_end = $2; - if ($userinfo{$srchstr} =~ m/^($role)_($role_end)_(\d+)$/) { - $role_start = $3; + if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) { + $role_end = $1; + if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) { + $role_start = $1; } } if ($role_start > 0) { - if (time < $role_start) { + if ($now < $role_start) { $active_chk = 'future'; } } if ($role_end > 0) { - if (time > $role_end) { + if ($now > $role_end) { $active_chk = 'previous'; } } @@ -3932,24 +3958,32 @@ sub check_user_status { =pod -=item get_sections +=item * &get_sections() Determines all the sections for a course including sections with students and sections containing other roles. -Incoming parameters: domain, course number, -reference to array containing roles for which sections should -be gathered (optional). If the third argument is undefined, -sections are gathered for any role. +Incoming parameters: + +1. domain +2. course number +3. reference to array containing roles for which sections should +be gathered (optional). +4. reference to array containing status types for which sections +should be gathered (optional). + +If the third argument is undefined, sections are gathered for any role. +If the fourth argument is undefined, sections are gathered for any status. +Permissible values are 'active' or 'future' or 'previous'. Returns section hash (keys are section IDs, values are number of users in each section), subject to the -optional roles filter. +optional roles filter, optional status filter =cut ############################################### sub get_sections { - my ($cdom,$cnum,$possible_roles) = @_; + my ($cdom,$cnum,$possible_roles,$possible_status) = @_; if (!defined($cdom) || !defined($cnum)) { my $cid = $env{'request.course.id'}; @@ -3960,16 +3994,32 @@ sub get_sections { } my %sectioncount; + my $now = time; if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) { my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum); my $sec_index = &Apache::loncoursedata::CL_SECTION(); my $status_index = &Apache::loncoursedata::CL_STATUS(); + my $start_index = &Apache::loncoursedata::CL_START(); + my $end_index = &Apache::loncoursedata::CL_END(); + my $status; while (my ($student,$data) = each(%$classlist)) { - my ($section,$status) = ($data->[$sec_index], - $data->[$status_index]); - unless ($section eq '-1' || $section =~ /^\s*$/) { - $sectioncount{$section}++; + my ($section,$stu_status,$start,$end) = ($data->[$sec_index], + $data->[$status_index], + $data->[$start_index], + $data->[$end_index]); + if ($stu_status eq 'Active') { + $status = 'active'; + } elsif ($end < $now) { + $status = 'previous'; + } elsif ($start > $now) { + $status = 'future'; + } + if ($section ne '-1' && $section !~ /^\s*$/) { + if ((!defined($possible_status)) || (($status ne '') && + (grep/^\Q$status\E$/,@{$possible_status}))) { + $sectioncount{$section}++; + } } } } @@ -3978,14 +4028,31 @@ sub get_sections { if ($user !~ /^(\w{2})/) { next; } my ($role) = ($user =~ /^(\w{2})/); if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; } - my $section; + my ($section,$status); if ($role eq 'cr' && $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) { $section=$1; } if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; } if (!defined($section) || $section eq '-1') { next; } - $sectioncount{$section}++; + my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/); + if ($end == -1 && $start == -1) { + next; #deleted role + } + if (!defined($possible_status)) { + $sectioncount{$section}++; + } else { + if ((!$end || $end >= $now) && (!$start || $start <= $now)) { + $status = 'active'; + } elsif ($end < $now) { + $status = 'future'; + } elsif ($start > $now) { + $status = 'previous'; + } + if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) { + $sectioncount{$section}++; + } + } } return %sectioncount; } @@ -3993,9 +4060,9 @@ sub get_sections { ############################################### =pod - -=item get_course_users - + +=item * &get_course_users() + Retrieves usernames:domains for users in the specified course with specific role(s), and access status. @@ -4018,12 +4085,13 @@ Entries for end, start, section and stat of the possibility of multiple values for non-student roles. =cut - + ############################################### - + sub get_course_users { my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata) = @_; my %idx = (); + my %seclists; $idx{udom} = &Apache::loncoursedata::CL_SDOM(); $idx{uname} = &Apache::loncoursedata::CL_SNAME(); @@ -4039,12 +4107,28 @@ sub get_course_users { my $now = time; foreach my $student (keys(%{$classlist})) { my $match = 0; + my $secmatch = 0; + my $section = $$classlist{$student}[$idx{section}]; + if ($section eq '') { + $section = 'none'; + } if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) { - unless(grep(/^\Q$$classlist{$student}[$idx{section}]\E$/, - @{$sections})) { - next; + if (grep(/^all$/,@{$sections})) { + $secmatch = 1; + } elsif ($$classlist{$student}[$idx{section}] eq '') { + if (grep(/^none$/,@{$sections})) { + $secmatch = 1; + } + } else { + if (grep(/^\Q$section\E$/,@{$sections})) { + $secmatch = 1; + } } - } + if (!$secmatch) { + next; + } + } + push(@{$seclists{$student}},$section); if (defined($$types{'active'})) { if ($$classlist{$student}[$idx{status}] eq 'Active') { push(@{$$users{st}{$student}},'active'); @@ -4063,36 +4147,57 @@ sub get_course_users { $match = 1; } } - if ($match && defined($userdata)) { + if ($match && ref($userdata) eq 'HASH') { $$userdata{$student} = $$classlist{$student}; } } } - if ((@{$roles} > 0) && (@{$roles} ne "st")) { + if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) { my @coursepersonnel = &Apache::lonnet::getkeys('nohist_userroles',$cdom,$cnum); foreach my $person (@coursepersonnel) { my $match = 0; - my ($role,$user) = ($person =~ /^([^:]*):([^:]+:[^:]+)/); + my $secmatch = 0; + my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/); $user =~ s/:$//; if (($role) && (grep(/^\Q$role\E$/,@{$roles}))) { - my ($uname,$udom,$usec) = split(/:/,$user); - if ($usec ne '' && (ref($sections) eq 'ARRAY') && - @{$sections} > 0) { - unless(grep(/^\Q$usec\E$/,@{$sections})) { - next; - } + my ($uname,$udom) = split(/:/,$user); + if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) { + if (grep(/^all$/,@{$sections})) { + $secmatch = 1; + } elsif ($usec eq '') { + if (grep(/^none$/,@{$sections})) { + $secmatch = 1; + } + } else { + if (grep(/^\Q$usec\E$/,@{$sections})) { + $secmatch = 1; + } + } + if (!$secmatch) { + next; + } + } + if ($usec eq '') { + $usec = 'none'; } if ($uname ne '' && $udom ne '') { - my $status = &check_user_status($udom,$uname,$cdom,$cnum,$role); + my $status = &check_user_status($udom,$uname,$cdom,$cnum,$role, + $usec); foreach my $type (keys(%{$types})) { if ($status eq $type) { - @{$$users{$role}{$user}} = $type; + if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) { + push(@{$$users{$role}{$user}},$type); + } $match = 1; } } - if ($match && defined($userdata) && - !exists($$userdata{$uname.':'.$udom})) { - &get_user_info($udom,$uname,\%idx,$userdata); + if (($match) && (ref($userdata) eq 'HASH')) { + if (!exists($$userdata{$uname.':'.$udom})) { + &get_user_info($udom,$uname,\%idx,$userdata); + } + if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) { + push(@{$seclists{$uname.':'.$udom}},$usec); + } } } } @@ -4106,10 +4211,17 @@ sub get_course_users { 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'); + } } } } } + foreach my $user (keys(%seclists)) { + @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}}); + $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}}); + } } return; } @@ -5180,13 +5292,22 @@ sub course_type { if (!defined($cid)) { $cid = $env{'request.course.id'}; } - if (defined($env{'course.'.$cid.'type'})) { - return $env{'course.'.$cid.'type'}; + if (defined($env{'course.'.$cid.'.type'})) { + return $env{'course.'.$cid.'.type'}; } else { return 'Course'; } } +sub group_term { + my $crstype = &course_type(); + my %names = ( + 'Course' => 'group', + 'Group' => 'team', + ); + return $names{$crstype}; +} + sub icon { my ($file)=@_; my $curfext = (split(/\./,$file))[-1];