--- loncom/interface/loncommon.pm 2006/05/01 19:07:16 1.357 +++ loncom/interface/loncommon.pm 2006/05/11 19:04:31 1.369 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common routines # -# $Id: loncommon.pm,v 1.357 2006/05/01 19:07:16 albertel Exp $ +# $Id: loncommon.pm,v 1.369 2006/05/11 19:04:31 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -64,6 +64,7 @@ use HTML::Entities; use Apache::lonhtmlcommon(); use Apache::loncoursedata(); use Apache::lontexconvert(); +use LONCAPA; my $readit; @@ -709,7 +710,7 @@ sub help_open_menu { my $timestamp = time; foreach my $datum (\$color,\$function,\$topic,\$component_help,\$faq, \$bug,\$origurl) { - $$datum = &Apache::lonnet::escape($$datum); + $$datum = &escape($$datum); } if (!$stayOnPage) { $link = "javascript:helpMenu('open')"; @@ -775,7 +776,7 @@ ENDTEMPLATE $width,$height).' '.$template; } else { my $help_text; - $help_text=&Apache::lonnet::unescape($topic); + $help_text=&unescape($topic); $template=''; + $prevattempts.=''; } } } @@ -2406,7 +2408,7 @@ sub get_previous_attempt { } else { $value=$lasthash{$key}; } - $value=&Apache::lonnet::unescape($value); + $value=&unescape($value); if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)} $prevattempts.=''; } @@ -2528,7 +2530,7 @@ sub submlink { if (!$symb) { $symb=$cursymb; } } if (!$symb) { $symb=&Apache::lonnet::symbread(); } - $symb=&Apache::lonnet::escape($symb); + $symb=&escape($symb); if ($target) { $target="target=\"$target\""; } return '". + &Apache::lontexconvert::init_math_support(); - my $upperleft=''.$function.''; if ($bodyonly || ($env{'request.state'} eq 'construct' && $env{'environment.remote'} ne 'off' )) { @@ -2842,75 +2839,92 @@ END $bodytag.='

LON-CAPA: '.$title.'

'; } return $bodytag; - } elsif ($env{'environment.remote'} eq 'off') { -# No Remote - my $roleinfo=(< - + } + + + + my $roleinfo=(< +
$env{'environment.firstname'} $env{'environment.middlename'} $env{'environment.lastname'} $env{'environment.generation'} -   -
-$role  -
-$realm  +   +
+
+$role  +
+
+$realm  +
ENDROLE - my $titleinfo = ''.$title.''; - if ($customtitle) { - $titleinfo = $customtitle; - } + my $titleinfo = ''.$title.''; + if ($customtitle) { + $titleinfo = $customtitle; + } + # + # Extra info if you are the DC + my $dc_info = ''; + if ($env{'user.adv'} && exists($env{'user.role.dc./'. + $env{'course.'.$env{'request.course.id'}. + '.domain'}.'/'})) { + my $cid = $env{'request.course.id'}; + $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'}; + $dc_info = '('.$dc_info.')'; + } + + if ($env{'environment.remote'} eq 'off') { + # No Remote if ($env{'request.state'} eq 'construct') { + $forcereg=1; + } + + if (!$customtitle && $env{'request.state'} eq 'construct') { + # this is for resources; directories have customtitle, and crumbs + # and select recent are created in lonpubdir.pm my ($uname,$thisdisfn)= ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|); my $formaction='/priv/'.$uname.'/'.$thisdisfn; $formaction=~s/\/+/\//g; - unless ($customtitle) { #this is for resources; directories have customtitle, and crumbs and select recent are created in lonpubdir.pm - my $parentpath = ''; - my $lastitem = ''; - if ($thisdisfn =~ m-(.+/)([^/]*)$-) { - $parentpath = $1; - $lastitem = $2; - } else { - $lastitem = $thisdisfn; - } - $titleinfo = &Apache::loncommon::help_open_menu('','','','',3,'Authoring'). - 'Construction Space: '. - '
' - .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."$lastitem
" - .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()') - .'' - .&Apache::lonmenu::constspaceform(); - } - $forcereg=1; + my $parentpath = ''; + my $lastitem = ''; + if ($thisdisfn =~ m-(.+/)([^/]*)$-) { + $parentpath = $1; + $lastitem = $2; + } else { + $lastitem = $thisdisfn; + } + $titleinfo = + &Apache::loncommon::help_open_menu('','','','',3,'Authoring'). + 'Construction Space: '. + '
' + .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."$lastitem
" + .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()') + .'' + .&Apache::lonmenu::constspaceform(); } + my $titletable; if (!$notitle) { $titletable = - '
'. &help_open_topic($component_help,$help_text,$stayOnPage, $width,$height).''.$template. @@ -803,7 +804,7 @@ sub help_open_bug { my $link=''; my $template=''; my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='. - &Apache::lonnet::escape($ENV{'REQUEST_URI'}).'&component='.$topic; + &escape($ENV{'REQUEST_URI'}).'&component='.$topic; if (!$stayOnPage) { $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))"; @@ -2024,10 +2025,11 @@ sub screenname { # ------------------------------------------------------------- Message Wrapper sub messagewrapper { - my ($link,$username,$domain)=@_; + my ($link,$username,$domain,$subject,$text)=@_; return ''.$link.''; } # --------------------------------------------------------------- Notes Wrapper @@ -2394,7 +2396,7 @@ sub get_previous_attempt { } else { $value=$returnhash{$version.':'.$key}; } - $prevattempts.=''.&Apache::lonnet::unescape($value).' '.&unescape($value).' '.$value.' 
'. - ''.$roleinfo.'
'. - $titleinfo.'
'; + ''. + "".$roleinfo. + '
$titleinfo $dc_info
'; } - if ($env{'request.state'} eq 'construct') { - if ($notopbar) { - $bodytag .= $titletable; - } else { + if ($notopbar) { + $bodytag .= $titletable; + } else { + if ($env{'request.state'} eq 'construct') { $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg, $titletable); - } - } else { - if ($notopbar) { - $bodytag .= $titletable; } else { $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg). - $titletable; + $titletable; } } return $bodytag; @@ -2919,50 +2933,26 @@ ENDROLE # # Top frame rendering, Remote is up # - my $titleinfo = ' '.$title.''; - if ($customtitle) { - $titleinfo = $customtitle; - } - # - # Extra info if you are the DC - my $dc_info = ''; - if ($env{'user.adv'} && exists($env{'user.role.dc./'. - $env{'course.'.$env{'request.course.id'}. - '.domain'}.'/'})) { - my $cid = $env{'request.course.id'}; - $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'}; - $dc_info = '('.$dc_info.')'; - } + + my $upperleft=''.$function.''; + # Explicit link to get inline menu - my $menu='
 
'.&mt('Switch to Inline Menu Mode').''; + my $menu= ($no_inline_link?'' + :'
'.&mt('Switch to Inline Menu Mode').''); # if ($notitle) { return $bodytag; } return(< - -$upperleft -$messages  + + + - - + +$roleinfo - - -
-$titleinfo $dc_info $menu - - - $env{'environment.firstname'} - $env{'environment.middlename'} - $env{'environment.lastname'} - $env{'environment.generation'} -   -
$titleinfo $dc_info $menu
-$role  -
$realm 
ENDBODY } @@ -3102,7 +3092,6 @@ sub standard_css { my $mail_other_hover = '#669999'; return < h1, h2, h3, th { font-family: $sans } a:focus { color: red; background: yellow } table.thinborder { border-collapse: collapse; } @@ -3122,11 +3111,51 @@ table#LC_top_nav, table#LC_menubuttons, width: 100%; background: $pgbg; border: 0px; - border-spacing: 1px; + border-spacing: 2px 1px; padding: 0px; margin: 0px; border-collapse: separate; } +table#LC_title_bar { + width: 100%; + border: 0; + border-spacing: 0px 1px; + padding: 0px 2px 0px 2px; + background: $pgbg; + font-family: $sans; + border-collapse: collapse; +} +table#LC_title_bar.LC_with_remote { + width: 100%; + border: 0; + border-spacing: 0; + background: $pgbg; + font-family: $sans; + border-collapse: collapse; +} +table#LC_title_bar td { + padding: 3px; + background: $tabbg; +} +table#LC_title_bar td.LC_title_bar_who { + background: $tabbg; + color: $font; + font: medium $sans; + text-align: right; +} +span.LC_title_bar_title { + font: bold xx-large $sans; +} +table#LC_title_bar td.LC_title_bar_domain_logo { + background: $sidebg; + text-align: right; + padding: 0px; +} +table#LC_title_bar td.LC_title_bar_role_logo { + background: $sidebg; + padding: 0px; +} + table#LC_menubuttons_mainmenu { background: $pgbg; border: 0px; @@ -3145,11 +3174,15 @@ table#LC_top_nav td a, div#LC_top_nav a color: $font; font-family: $sans; } +table#LC_top_nav td.LC_top_nav_logo { + background: $tabbg; + text-align: right; +} table#LC_breadcrumbs td { background: $tabbg; color: $font; font-family: $sans; - font-size: smallest; + font-size: smaller; } table#LC_breadcrumbs td.LC_breadcrumb_component { background: $tabbg; @@ -3240,7 +3273,6 @@ table.LC_mail_list tr.LC_mail_other { table.LC_mail_list tr.LC_mail_other:hover { background-color: $mail_other_hover; } - END } @@ -3274,10 +3306,18 @@ Inputs: $title - optional title for the sub headtag { my ($title,$head_extra,$args) = @_; + 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'}, + $env{'environment.color.timestamp'}, + $function,$domain,$bgcolor); + + $url = '/adm/css/'.&escape($url).'.css'; + my $result = ''. - &standard_css($args->{'function'},$args->{'domain'}, - $args->{'bgcolor'}). + ''. &font_settings(). &Apache::lonhtmlcommon::htmlareaheaders(); @@ -3436,6 +3476,9 @@ Inputs: $title - optional title for the head -> skip the generation body -> skip all generation + no_inline_link -> if true and in remote mode, don't show the + 'Switch To Inline Menu' link + =back =cut @@ -3471,7 +3514,7 @@ 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_title'}, $args->{'no_inline_link'}); } } @@ -3612,6 +3655,14 @@ sub simple_error_page { sub end_data_table_row { return ''; } + + sub start_data_table_header_row { + return ''; + } + + sub end_data_table_header_row { + return ''; + } } ############################################### @@ -3717,20 +3768,27 @@ Returns number of sections. ############################################### sub get_sections { - my ($cdom,$cnum,$sectioncount,$possible_roles) = @_; - if (!($cdom && $cnum)) { return 0; } - my $numsections = 0; + my ($cdom,$cnum,$possible_roles) = @_; + if (!defined($cdom) || !defined($cnum)) { + my $cid = $env{'request.course.id'}; + + return if (!defined($cid)); - if (!defined($possible_roles) || (grep/^st$/,@$possible_roles)) { + $cdom = $env{'course.'.$cid.'.domain'}; + $cnum = $env{'course.'.$cid.'.num'}; + } + + my %sectioncount; + + 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(); - while (my ($student,$data) = each %$classlist) { + while (my ($student,$data) = each(%$classlist)) { my ($section,$status) = ($data->[$sec_index], $data->[$status_index]); unless ($section eq '-1' || $section =~ /^\s*$/) { - if (!defined($$sectioncount{$section})) { $numsections++; } - $$sectioncount{$section}++; + $sectioncount{$section}++; } } } @@ -3746,10 +3804,9 @@ sub get_sections { } if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; } if (!defined($section) || $section eq '-1') { next; } - if (!defined($$sectioncount{$section})) { $numsections++; } - $$sectioncount{$section}++; + $sectioncount{$section}++; } - return $numsections; + return %sectioncount; } ############################################### @@ -3786,25 +3843,24 @@ can be sent to &get_group_settings() to ############################################### sub coursegroups { - my ($curr_groups,$cdom,$cnum,$group) = @_; - my $numgroups; + my ($cdom,$cnum,$group) = @_; if (!defined($cdom) || !defined($cnum)) { my $cid = $env{'request.course.id'}; + + return if (!defined($cid)); + $cdom = $env{'course.'.$cid.'.domain'}; $cnum = $env{'course.'.$cid.'.num'}; } - %{$curr_groups} = &Apache::lonnet::get_coursegroups($cdom,$cnum,$group); - my ($tmp) = keys(%{$curr_groups}); - if ($tmp=~/^error:/) { - unless ($tmp eq 'error: 2 tie(GDBM) Failed while attempting dump') { - &logthis('Error retrieving groups: '.$tmp.' in '.$cnum.':'. - $cdom); - } - $numgroups = 0; - } else { - $numgroups = keys(%{$curr_groups}); + my %curr_groups = &Apache::lonnet::get_coursegroups($cdom,$cnum,$group); + my ($tmp) = keys(%curr_groups); + if ($tmp=~/^(con_lost|no_such_host|error: [^2] )/) { + undef(%curr_groups); + &logthis('Error retrieving groups: '.$tmp.' in '.$cnum.':'.$cdom); + } elsif ($tmp=~/^error: 2 /) { + undef(%curr_groups); } - return $numgroups; + return %curr_groups; } ############################################### @@ -3865,7 +3921,7 @@ sub get_group_settings { $content{$tool}{$function} = $value; } } elsif ($entry eq 'groupname') { - $content{$entry}=&Apache::lonnet::unescape($value); + $content{$entry}=&unescape($value); } elsif (($entry eq 'roles') || ($entry eq 'types') || ($entry eq 'sectionpick') || ($entry eq 'defpriv')) { push(@{$content{$entry}},$value); @@ -4052,7 +4108,7 @@ sub get_unprocessed_cgi { # $Apache::lonxml::debug=1; foreach my $pair (split(/&/,$query)) { my ($name, $value) = split(/=/,$pair); - $name = &Apache::lonnet::unescape($name); + $name = &unescape($name); if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) { $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; @@ -4681,9 +4737,9 @@ sub DrawBarGraph { $Title = '' if (! defined($Title)); $xlabel = '' if (! defined($xlabel)); $ylabel = '' if (! defined($ylabel)); - $ValuesHash{$id.'.title'} = &Apache::lonnet::escape($Title); - $ValuesHash{$id.'.xlabel'} = &Apache::lonnet::escape($xlabel); - $ValuesHash{$id.'.ylabel'} = &Apache::lonnet::escape($ylabel); + $ValuesHash{$id.'.title'} = &escape($Title); + $ValuesHash{$id.'.xlabel'} = &escape($xlabel); + $ValuesHash{$id.'.ylabel'} = &escape($ylabel); $ValuesHash{$id.'.y_max_value'} = $Max; $ValuesHash{$id.'.NumBars'} = $NumBars; $ValuesHash{$id.'.NumSets'} = $NumSets; @@ -4763,9 +4819,9 @@ sub DrawXYGraph { $ylabel = '' if (! defined($ylabel)); my %ValuesHash = ( - $id.'.title' => &Apache::lonnet::escape($Title), - $id.'.xlabel' => &Apache::lonnet::escape($xlabel), - $id.'.ylabel' => &Apache::lonnet::escape($ylabel), + $id.'.title' => &escape($Title), + $id.'.xlabel' => &escape($xlabel), + $id.'.ylabel' => &escape($ylabel), $id.'.y_max_value'=> $Max, $id.'.labels' => join(',',@$Xlabels), $id.'.PlotType' => 'XY', @@ -4860,9 +4916,9 @@ sub DrawXYYGraph { $ylabel = '' if (! defined($ylabel)); my %ValuesHash = ( - $id.'.title' => &Apache::lonnet::escape($Title), - $id.'.xlabel' => &Apache::lonnet::escape($xlabel), - $id.'.ylabel' => &Apache::lonnet::escape($ylabel), + $id.'.title' => &escape($Title), + $id.'.xlabel' => &escape($xlabel), + $id.'.ylabel' => &escape($ylabel), $id.'.labels' => join(',',@$Xlabels), $id.'.PlotType' => 'XY', $id.'.NumSets' => 2, @@ -4934,7 +4990,7 @@ Inputs: sub chartlink { my ($linktext, $sname, $sdomain) = @_; my $link = ''.$linktext.''; } @@ -4997,11 +5053,11 @@ sub store_course_settings { if (ref($env{'form.'.$setting})) { $stored_form = join(',', map { - &Apache::lonnet::escape($_); + &escape($_); } sort(@{$env{'form.'.$setting}})); } else { $stored_form = - &Apache::lonnet::escape($env{'form.'.$setting}); + &escape($env{'form.'.$setting}); } # Determine if the array contents are the same. if ($stored_form ne $env{$envname}) { @@ -5035,7 +5091,7 @@ sub restore_course_settings { } elsif ($type eq 'array') { $env{'form.'.$setting} = [ map { - &Apache::lonnet::unescape($_); + &unescape($_); } split(',',$env{$envname}) ]; } @@ -5108,7 +5164,7 @@ sub escape_double { sub escape_url { my ($url) = @_; my @urlslices = split(/\//, $url,-1); - my $lastitem = &Apache::lonnet::escape(pop(@urlslices)); + my $lastitem = &escape(pop(@urlslices)); return join('/',@urlslices).'/'.$lastitem; } =pod