--- loncom/interface/loncommon.pm 2006/04/11 20:00:44 1.331 +++ loncom/interface/loncommon.pm 2006/04/20 02:01:30 1.343 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common routines # -# $Id: loncommon.pm,v 1.331 2006/04/11 20:00:44 albertel Exp $ +# $Id: loncommon.pm,v 1.343 2006/04/20 02:01:30 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -61,6 +61,8 @@ use POSIX qw(strftime mktime); use Apache::lonmenu(); use Apache::lonlocal; use HTML::Entities; +use Apache::lonhtmlcommon(); +use Apache::loncoursedata(); my $readit; @@ -2751,7 +2753,10 @@ Inputs: =item * $notopbar, if true, keep the 'what is this' info but remove the navigational links -=item * $bgcolor, used to override the bg coor on a webpage to a specific value +=item * $bgcolor, used to override the bgcolor on a webpage to a specific value + +=item * $notitle, if true keep the nav controls, but remove the title bar + =back @@ -2764,22 +2769,25 @@ other decorations will be returned. sub bodytag { my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,$customtitle, - $notopbar,$bgcolor)=@_; + $notopbar,$bgcolor,$notitle)=@_; + $title=&mt($title); + $function = &get_users_function() if (!$function); - my $img=&designparm($function.'.img',$domain); - my $pgbg= $bgcolor || &designparm($function.'.pgbg',$domain); - my $tabbg=&designparm($function.'.tabbg',$domain); - my $font=&designparm($function.'.font',$domain); - my $link=&designparm($function.'.link',$domain); - my $alink=&designparm($function.'.alink',$domain); - my $vlink=&designparm($function.'.vlink',$domain); - my $sidebg=&designparm($function.'.sidebg',$domain); -# Accessibility font enhance - my $addstyle=''; - if ($env{'browser.fontenhance'} eq 'on') { - $addstyle=' font-size: x-large;'; - } + my $img = &designparm($function.'.img',$domain); + my $tabbg = &designparm($function.'.tabbg',$domain); + my $font = &designparm($function.'.font',$domain); + my $sidebg = &designparm($function.'.sidebg',$domain); + my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain); + + my %design = ( 'style' => 'margin-top: 0px', + 'bgcolor' => $pgbg, + 'text' => $font, + 'alink' => &designparm($function.'.alink',$domain), + 'vlink' => &designparm($function.'.vlink',$domain), + 'link' => &designparm($function.'.link',$domain),); + @$addentries{keys(%design)} = @design{keys(%design)}; + # role and realm my ($role,$realm) =&Apache::lonnet::plaintext((split(/\./,$env{'request.role'}))[0]); @@ -2799,31 +2807,25 @@ sub bodytag { # construct main body tag my $bodytag = < -h1, h2, h3, th { font-family: Arial, Helvetica, sans-serif } -a:focus { color: red; background: yellow } -table.thinborder { border-collapse: collapse; } -table.thinborder tr th, table.thinborder tr td { border-style: solid; border-width: 1px} -form, .inline { display: inline; } -.center { text-align: center; } -.filename {font-family: monospace;} - - + END $bodytag .= &Apache::lontexconvert::init_math_support(); my $upperleft=''.$function.''; - if ($bodyonly) { + if ($bodyonly + || ($env{'request.state'} eq 'construct' + && $env{'environment.remote'} ne 'off' )) { return $bodytag; } elsif ($env{'browser.interface'} eq 'textual') { # Accessibility - return $bodytag.&Apache::lonmenu::menubuttons($forcereg,'web', - $forcereg). - '

LON-CAPA: '.$title.'

'; + $bodytag.=&Apache::lonmenu::menubuttons($forcereg,$forcereg); + if (!$notitle) { + $bodytag.='

LON-CAPA: '.$title.'

'; + } + return $bodytag; } elsif ($env{'environment.remote'} eq 'off') { # No Remote my $roleinfo=(<'. ''. $titleinfo.''.$roleinfo.''; - if ($env{'request.state'} eq 'construct') { + } + if ($env{'request.state'} eq 'construct') { if ($notopbar) { $bodytag .= $titletable; } else { - $bodytag .= &Apache::lonmenu::menubuttons($forcereg,'web',$forcereg,$titletable); + $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg, + $titletable); } } else { if ($notopbar) { $bodytag .= $titletable; } else { - $bodytag .= &Apache::lonmenu::menubuttons($forcereg,'web',$forcereg). + $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg). $titletable; } } @@ -2913,6 +2920,9 @@ ENDROLE # Explicit link to get inline menu my $menu='
 '.&mt('Switch to Inline Menu Mode').''; # + if ($notitle) { + return $bodytag; + } return(< @@ -2951,11 +2961,44 @@ sub make_attr_string { } if ($register) { - $attr_ref->{'onload'} = &Apache::lonmenu::loadevents(). - $attr_ref->{'onload'}; - $attr_ref->{'onunload'} = &Apache::lonmenu::unloadevents(). - $attr_ref->{'onunload'}; + my ($on_load,$on_unload); + foreach my $key (keys(%{$attr_ref})) { + if (lc($key) eq 'onload') { + $on_load.=$attr_ref->{$key}.';'; + delete($attr_ref->{$key}); + + } elsif (lc($key) eq 'onunload') { + $on_unload.=$attr_ref->{$key}.';'; + delete($attr_ref->{$key}); + } + } + $attr_ref->{'onload'} = + &Apache::lonmenu::loadevents(). $on_load; + $attr_ref->{'onunload'}= + &Apache::lonmenu::unloadevents().$on_unload; + } + +# Accessibility font enhance + if ($env{'browser.fontenhance'} eq 'on') { + my $style; + foreach my $key (keys(%{$attr_ref})) { + if (lc($key) eq 'style') { + $style.=$attr_ref->{$key}.';'; + delete($attr_ref->{$key}); + } + } + $attr_ref->{'style'}=$style.'; font-size: x-large;'; } + + if ($env{'browser.blackwhite'} eq 'on') { + delete($attr_ref->{'font'}); + delete($attr_ref->{'link'}); + delete($attr_ref->{'alink'}); + delete($attr_ref->{'vlink'}); + delete($attr_ref->{'bgcolor'}); + delete($attr_ref->{'background'}); + } + my $attr_string; foreach my $attr (keys(%$attr_ref)) { $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" '; @@ -2997,6 +3040,20 @@ sub endbodytag { return $endbodytag; } +sub standard_css { + return < +h1, h2, h3, th { font-family: Arial, Helvetica, sans-serif } +a:focus { color: red; background: yellow } +table.thinborder { border-collapse: collapse; } +table.thinborder tr th, table.thinborder tr td { border-style: solid; border-width: 1px} +form, .inline { display: inline; } +.center { text-align: center; } +.filename {font-family: monospace;} + +END +} + =pod =over 4 @@ -3010,7 +3067,6 @@ 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 (side effect of setting @@ -3025,7 +3081,8 @@ sub headtag { my $result = ''. - &Apache::lonxml::fontsettings(). + &standard_css(). + &font_settings(). &Apache::lonhtmlcommon::htmlareaheaders(); if ($args->{'force_register'}) { @@ -3053,6 +3110,66 @@ ADDMETA =over 4 +=item * &font_settings() + +Returns neccessary to set the proper encoding + +Inputs: none + +=back + +=cut + +sub font_settings { + my $headerstring=''; + if (($env{'browser.os'} eq 'mac') && (!$env{'browser.mathml'})) { + $headerstring.= + ''; + } elsif (!$env{'browser.mathml'} && $env{'browser.unicode'}) { + $headerstring.= + ''; + } + return $headerstring; +} + +=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{'browser.mathml'}) { + $output='' + #.''."\n" +# .'] >' + .'' + .''; + } else { + $output=''; + } + return $output; +} + +=pod + +=over 4 + =item * &endheadtag() Returns a uniform for LON-CAPA web pages. @@ -3118,6 +3235,11 @@ Inputs: $title - optional title for the is not auto translated like the $title is frameset -> if true will start with a rather than + no_title -> if true the title bar won't be shown + skip_phases -> hash ref of + head -> skip the generation + body -> skip all generation + =back =cut @@ -3133,21 +3255,29 @@ sub start_page { } $env{'internal.start_page'}++; - my $result = - &Apache::lonxml::xmlbegin(). - &headtag($title,$head_extra,\%head_args).&endheadtag(); - if ($args->{'frameset'}) { - my $attr_string = &make_attr_string($args->{'force_register'}, - $args->{'add_entries'}); - $result .= "\n\n"; - } else { - $result .= - &bodytag($title, - $args->{'function'}, $args->{'add_entries'}, - $args->{'only_body'}, $args->{'domain'}, - $args->{'force_register'}, $args->{'body_title'}, - $args->{'no_nav_bar'}, $args->{'bgcolor'}); + my $result; + if (! exists($args->{'skip_phases'}{'head'}) ) { + $result.= + &xml_begin(). + &headtag($title,$head_extra,\%head_args).&endheadtag(); + } + + if (! exists($args->{'skip_phases'}{'body'}) ) { + if ($args->{'frameset'}) { + my $attr_string = &make_attr_string($args->{'force_register'}, + $args->{'add_entries'}); + $result .= "\n\n"; + } else { + $result .= + &bodytag($title, + $args->{'function'}, $args->{'add_entries'}, + $args->{'only_body'}, $args->{'domain'}, + $args->{'force_register'}, $args->{'body_title'}, + $args->{'no_nav_bar'}, $args->{'bgcolor'}, + $args->{'no_title'}); + } } + if ($args->{'js_ready'}) { $result = &js_ready($result); } @@ -3182,6 +3312,15 @@ sub end_page { #&Apache::lonnet::logthis("end_page ".join(':',caller(0))); $env{'internal.end_page'}++; my $result; + if ($args->{'discussion'}) { + my ($target,$parser); + if (ref($args->{'discussion'})) { + ($target,$parser) =($args->{'discussion'}{'target'}, + $args->{'discussion'}{'parser'}); + } + $result .= &Apache::lonxml::xmlend($target,$parser); + } + if ($args->{'frameset'}) { $result .= ''; } else { @@ -3192,9 +3331,11 @@ sub end_page { if ($args->{'js_ready'}) { $result = &js_ready($result); } + if ($args->{'html_encode'}) { $result = &html_encode($result); } + return $result; } @@ -3671,92 +3812,6 @@ sub get_user_info { return; } -############################################### - -sub get_posted_cgi { - my $r=shift; - - my $buffer; - if ($r->header_in('Content-length')) { - $r->read($buffer,$r->header_in('Content-length'),0); - } - unless ($buffer=~/^(\-+\w+)\s+Content\-Disposition\:\s*form\-data/si) { - my @pairs=split(/&/,$buffer); - my $pair; - foreach $pair (@pairs) { - my ($name,$value) = split(/=/,$pair); - $value =~ tr/+/ /; - $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; - $name =~ tr/+/ /; - $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; - &add_to_env("form.$name",$value); - } - } else { - my $contentsep=$1; - my @lines = split (/\n/,$buffer); - my $name=''; - my $value=''; - my $fname=''; - my $fmime=''; - my $i; - for ($i=0;$i<=$#lines;$i++) { - if ($lines[$i]=~/^$contentsep/) { - if ($name) { - chomp($value); - if ($fname) { - $env{"form.$name.filename"}=$fname; - $env{"form.$name.mimetype"}=$fmime; - } else { - $value=~s/\s+$//s; - } - &add_to_env("form.$name",$value); - } - if ($i<$#lines) { - $i++; - $lines[$i]=~ - /Content\-Disposition\:\s*form\-data\;\s*name\=\"([^\"]+)\"/i; - $name=$1; - $value=''; - if ($lines[$i]=~/filename\=\"([^\"]+)\"/i) { - $fname=$1; - if - ($lines[$i+1]=~/Content\-Type\:\s*([\w\-\/]+)/i) { - $fmime=$1; - $i++; - } else { - $fmime=''; - } - } else { - $fname=''; - $fmime=''; - } - $i++; - } - } else { - $value.=$lines[$i]."\n"; - } - } - } -# -# Digested POSTed values -# -# Remember the way this was originally done (GET or POST) -# - $env{'request.method'}=$ENV{'REQUEST_METHOD'}; -# -# There may also be stuff in the query string -# Tell subsequent handlers that this was GET, not POST, so they can access query string. -# Also, unset POSTed content length to cover all tracks. -# - -# This does not work, because M_GET is not defined (if it's defined, it is just 0). -# Commenting out for now ... not sure if harm is done. -# $r->method_number(M_GET); - - $r->method('GET'); - $r->headers_in->unset('Content-length'); -} - =pod =item * get_unprocessed_cgi($query,$possible_names)