[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm lonhelpmenu.pm

raeburn raeburn at source.lon-capa.org
Sun Dec 29 19:34:50 EST 2013


raeburn		Mon Dec 30 00:34:50 2013 EDT

  Modified files:              
    /loncom/interface	loncommon.pm lonhelpmenu.pm 
  Log:
  - Set DOCTYPE of DTD HTML 4.01 Frameset for frameset.
  - Self-closing <meta>, <link> tags not validated for DTD HTML 4.01 Frameset.
  - When displaying help menu where "stayonpage" is true, make page look more
    like the rest of LON-CAPA by providing primary menu items.
  - "Help" item not a link when primary menu items displayed for help menu.
  - Add drop down items for Course Coordination and Authoring manuals to
    help menu, where "stayonpage" is true, for users who need them.
  - Use domain configuration when checking whether a support e-mail address
    is set for "Ask Helpdesk", in place of previous check of lonSupportEMail
    perlvar.
  - xhtml for help menu frame to satisfy w3c validation.
  
  
-------------- next part --------------
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1167 loncom/interface/loncommon.pm:1.1168
--- loncom/interface/loncommon.pm:1.1167	Wed Dec 25 20:43:46 2013
+++ loncom/interface/loncommon.pm	Mon Dec 30 00:34:49 2013
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.1167 2013/12/25 20:43:46 raeburn Exp $
+# $Id: loncommon.pm,v 1.1168 2013/12/30 00:34:49 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1380,16 +1380,21 @@
     $text = &mt($text);
     my $stay_on_page = 1;
 
-    my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
-	                     : "javascript:helpMenu('open')";
-    my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
-
+    my ($link,$banner_link);
+    unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
+        $link = ($stay_on_page) ? "javascript:helpMenu('display')"
+	                         : "javascript:helpMenu('open')";
+        $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
+    }
     my $title = &mt('Get help');
-
-    return <<"END";
+    if ($link) {
+        return <<"END";
 $banner_link
 <a href="$link" title="$title">$text</a>
 END
+    } else {
+        return ' '.$text.' ';
+    }
 }
 
 sub help_menu_js {
@@ -1406,7 +1411,7 @@
 					'js_ready'    => 1,
                                         'use_absolute' => $httphost,
 					'add_entries' => {
-					    'border' => '0',
+					    'border' => '0', 
 					    'rows'   => "110,*",},});
     my $end_page =
         &Apache::loncommon::end_page({'frameset' => 1,
@@ -1436,9 +1441,10 @@
     return;
 }
 function writeHelp(caller) {
-    caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" />\\n<frame name="bodyframe" src="$details_link" />\\n$end_page')
-    caller.document.close()
-    caller.focus()
+    caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
+    caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
+    caller.document.close();
+    caller.focus();
 }
 // END LON-CAPA Internal -->
 // ]]>
@@ -5223,6 +5229,9 @@
         $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
 
         #don't show menus for public users
+        if ($args->{'no_secondary_menu'}) {
+            return $bodytag;
+        }
         if (!$public){
             $bodytag .= Apache::lonmenu::secondary_menu($httphost);
             $bodytag .= Apache::lonmenu::serverform();
@@ -7330,7 +7339,11 @@
     }
     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
     $result .= '<title> LON-CAPA '.$title.'</title>'
-	.'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
+	.'<link rel="stylesheet" type="text/css" href="'.$url.'"';
+    if (!$args->{'frameset'}) {
+        $result .= ' /';
+    }
+    $result .= '>' 
         .$inhibitprint
 	.$head_extra;
     if ($env{'browser.mobile'}) {
@@ -7356,8 +7369,12 @@
     my $headerstring='';
     if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
         ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
-	$headerstring.=
-	    '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'."\n";
+        $headerstring.=
+            '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
+        if (!$args->{'frameset'}) {
+	    $headerstring.= ' /';
+        }
+	$headerstring .= '>'."\n";
     }
     return $headerstring;
 }
@@ -7449,6 +7466,7 @@
 =cut
 
 sub xml_begin {
+    my ($is_frameset) = @_;
     my $output='';
 
     if ($env{'browser.mathml'}) {
@@ -7460,9 +7478,12 @@
 	    .'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">'
             .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" ' 
 	    .'xmlns="http://www.w3.org/1999/xhtml">';
+    } elsif ($is_frameset) {
+        $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
+                '<html>'."\n";
     } else {
-	$output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n"
-           .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
+	$output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
+                '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
     }
     return $output;
 }
@@ -7529,7 +7550,7 @@
     my ($result, at advtools);
 
     if (! exists($args->{'skip_phases'}{'head'}) ) {
-        $result .= &xml_begin() . &headtag($title, $head_extra, $args);
+        $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
     }
     
     if (! exists($args->{'skip_phases'}{'body'}) ) {
Index: loncom/interface/lonhelpmenu.pm
diff -u loncom/interface/lonhelpmenu.pm:1.42 loncom/interface/lonhelpmenu.pm:1.43
--- loncom/interface/lonhelpmenu.pm:1.42	Thu Aug  8 14:31:54 2013
+++ loncom/interface/lonhelpmenu.pm	Mon Dec 30 00:34:49 2013
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # generate frame-based help system
 #
-# $Id: lonhelpmenu.pm,v 1.42 2013/08/08 14:31:54 raeburn Exp $
+# $Id: lonhelpmenu.pm,v 1.43 2013/12/30 00:34:49 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -62,11 +62,21 @@
         $bugurl .= '&component='.$bug;
     }
     my $faqbaseurl = $Apache::lonnet::perlvar{'FAQHost'};
-    my $requestmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
+    my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
+    my $defdom;
+    if ($env{'request.course.id'}) {
+        $defdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+    } elsif ($env{'request.role.domain'}) {
+        $defdom = $env{'request.role.domain'};
+    } else {
+        $defdom = &Apache::lonnet::default_login_domain();
+    }
+    my $requestmail = &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
+                                                               $defdom,$origmail);
     if ($env{'form.page'} eq 'banner') {
         &display_help_banner($r,$faq,$bug,$topic,$component_url,$origurl,$bugurl,$faqbaseurl,$requestmail,$stayOnPage);
     } elsif ($env{'form.page'} eq 'body') {
-        &display_help_mainpage($r,$faq,$bug,$topic,$component_url,$origurl,$bugurl,$faqbaseurl,$requestmail);
+        &display_help_mainpage($r,$faq,$bug,$topic,$component_url,$origurl,$bugurl,$faqbaseurl,$requestmail,$stayOnPage);
     }
     return OK;
 }
@@ -75,12 +85,11 @@
     my ($r,$faq,$bug,$topic,$component_url,$origurl,$bugurl,$faqbaseurl,$requestmail,$stayOnPage) = @_;
     my $location=&Apache::loncommon::lonhttpdurl("/adm");
     my $dom = $env{'request.role.domain'};
-    my %helpconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$dom);
     my $scripttag = '';
-    if ($requestmail =~ m/^[^\@]+\@[^\@]+$/) {
+    if ($requestmail) {
         my $displayurl = &escape($origurl);
         $scripttag = (<<"SCRIPT_ONE");
-<script>
+<script type="text/javascript">
 // <![CDATA[
 function gohelpdesk() {
     var actiontype = null;
@@ -107,6 +116,7 @@
         return;
     }
 }
+
 SCRIPT_ONE
         $scripttag .= (<<'SCRIPT_TWO');
 function validmail(field) {
@@ -130,79 +140,233 @@
         return false;
     }
 }
+
 // ]]>
 </script>
 SCRIPT_TWO
     }
 
-    my %body_layout = 
-	('rightmargin'  => "0",
-	 'leftmargin'   => "0",
-	 'marginwidth'  => "0",
-	 'topmargin'    => "1",
-	 'marginheight' => "1");
-    my $start_page = 
-	&Apache::loncommon::start_page('Help',$scripttag,
-					{'only_body'   => 1,});
-    $r->print($start_page);
-
-    my $width = ($stayOnPage) ? '95%' : '600';
-    $r->print('<table id="LC_helpmenu" width="'.$width.'">');
+    if ($stayOnPage) {
+	$r->print(&Apache::loncommon::start_page('Help',$scripttag,
+					         {'no_secondary_menu' => 1,}));
+    } else {
+        $r->print(&Apache::loncommon::start_page('Help',$scripttag,
+                                                 {'only_body' => 1,}));
+    }
+    my $menu = &helpmenu_items($dom,$faq,$bug,$topic,$component_url,$origurl,$bugurl,$faqbaseurl,$requestmail,$stayOnPage);
+    if ($menu) {
+        $r->print("<ul id=\"LC_secondary_menu\">$menu</ul>");
+    }
+    if ($stayOnPage && $env{'user.adv'}) {
+        $r->print('<br />');
+    } 
+    $r->print(&Apache::loncommon::end_page());
+}
 
+sub helpmenu_items {
+    my ($dom,$faq,$bug,$topic,$component_url,$origurl,$bugurl,$faqbaseurl,$requestmail,$stayOnPage) = @_;
+    my $location=&Apache::loncommon::lonhttpdurl("/adm");
     my $general_help = &Apache::loncommon::general_help();
-    $r->print('
-  <tr>
-   <td width="5" height="50"> </td>
-   <td>
-    <fieldset><legend><img src="'.$location.'/lonIcons/minilogo.gif" height="20" width="29" alt="('.&mt('LON-CAPA help/support').')" />  '.&mt('LON-CAPA help/support').'</legend>
- <table id="LC_helpmenu_links">
-   <tr>
-	<td><span class="LC_nobreak"><a href="/adm/help/'.$general_help.'.hlp" target="bodyframe">
-		  <img src="'.$location.'/help/help.png" border="0" alt="('.&mt('General help').')" /> '.&mt('General Help').'</a> </span></td>');
+    my %helpconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$dom);
+    my %lt = &Apache::lonlocal::texthash(
+                                            general       => 'General help',
+                                            component     => 'Topic help',
+                                            faq           => 'FAQ',
+                                            helpdesk      => 'Ask helpdesk',
+                                            bugs          => 'Report a bug',
+                                            manuals_web   => 'Online manuals',
+                                            manuals_pdf   => 'Printable manuals',
+                                            lastloc       => 'Go back',
+                                            close         => 'Close',
+                                         );
+    my %items = (
+                    general => {
+                                 href => '/adm/help/'.$general_help.'.hlp',
+                                 img  => $location.'/help/help.png',
+                                 alt  => $lt{'general'},
+                                 text => $lt{'general'},
+                               },
+                    component => {
+                                   href => $component_url,
+                                   img  => $location.'/help/help.png',
+                                   alt  => $lt{'component'},
+                                   text => $topic,
+                                 },
+                    faq      => {
+                                   href => $faqbaseurl.'fom/cache/'.$faq.'.html',
+                                   img  => $location.'/lonMisc/smallFAQ.gif',
+                                   alt  => $lt{'faq'},
+                                   text => $lt{'faq'},                                   
+                                 },
+                    helpdesk => {
+                                   href    => '#',
+                                   onclick => 'gohelpdesk()',
+                                   img  => $location.'/lonIcons/helpdesk.gif',    
+                                   alt  => $lt{'helpdesk'},
+                                   text => $lt{'helpdesk'},
+                                },
+                    bugs     => {
+                                   href => $bugurl,
+                                   img  => $location.'/lonMisc/smallBug.gif', 
+                                   alt  => $lt{'bugs'},
+                                   text => $lt{'bugs'},
+                                },
+                    manuals_web  => {
+                                       href => '',
+                                       img  => $location.'/lonIcons/html.gif',
+                                       alt  => $lt{'manuals_web'},
+                                       text => $lt{'manuals_web'},
+                                    },
+                    manuals_pdf  => {
+                                       href => '',
+                                       img  => $location.'/lonIcons/pdf.gif',
+                                       alt  => $lt{'manuals_pdf'},
+                                       text => $lt{'manuals_pdf'},
+                                    },
+                    lastloc  => {
+                                   href   => $origurl,
+                                   img    => '/res/adm/pages/tolastloc.png',
+                                   alt    => $lt{'lastloc'},
+                                   text   => $lt{'lastloc'},
+                                   target => '_top',
+                                },
+                    close    => {
+                                   href   => 'javascript:window.close()',
+                                   img    => $location.'/lonIcons/close.gif',
+                                   alt    => $lt{'close'},
+                                   text   => $lt{'close'},
+                                   target => '_top',
+                                },
+    );
+    my %help_submenu = (
+                           manuals_web => [
+                                            ['/adm/help/course.manual.access.hlp','Course Coordination','course'],
+                                            ['/adm/help/course.manual.access.hlp','Authoring','author'],
+                                          ],
+                           manuals_pdf => [
+                                            ['/adm/help/course.manual.pdf','Course Coordination','course'],
+                                            ['/adm/help/course.manual.pdf','Authoring','author'],
+                                          ],
+                       );
+    my @order = ('general');
     if ($component_url) {
-	$r->print("<td><span class=\"LC_nobreak\"><a href=\"$component_url\" target=\"bodyframe\">".
-		  '<img src="'.$location.'/help/help.png" border="0" alt="('.&mt('Topic help').')" /> '.$topic.'</a> </span></td>');
+        push(@order,'component');
+    }
+    if ($requestmail) {
+        push(@order,'helpdesk');
+    }
+    if ($env{'user.adv'} && $faq) {
+        push(@order,'faq');
     }
-    if ($requestmail =~ m/^[^\@]+\@[^\@]+$/) {
-        $r->print('
-            <td><span class="LC_nobreak"> <a href="javascript:gohelpdesk()"><img src="'.$location.'/lonIcons/helpdesk.gif" border="0" alt="('.&mt('Ask helpdesk').')" /> '.&mt('Ask helpdesk').'</a> </span></td>');
-    }
-    if ($faq && $env{'user.adv'}) {
-        $r->print('
-             <td><span class="LC_nobreak"> <a href="'.$faqbaseurl.'/fom/cache/'.$faq.'.html" target="bodyframe"><img src="'.$location.'/lonMisc/smallFAQ.gif" border="0" alt="('.&mt('FAQ').')" /> '.&mt('FAQ').'</a> </span>
-            </td>');
-    }
-    if ($env{'user.adv'}) {
-    	if ($helpconfig{'helpsettings'}{'submitbugs'} eq '1' ||
-    		$helpconfig{'helpsettings'}{'submitbugs'} eq '' ) {
-        	$r->print('
-            	<td><span class="LC_nobreak"> <b><a href="'.$bugurl.'" target="bodyframe"><img src="'.$location.'/lonMisc/smallBug.gif" border="0" alt="('.&mt('Report a bug').')" /> '.&mt('Report a bug').'</a> </b></span></td>');
-		}
+    if (($env{'user.adv'}) && (($helpconfig{'helpsettings'}{'submitbugs'} eq '1') || ($helpconfig{'helpsettings'}{'submitbugs'} eq ''))) {
+        push(@order,'bugs');
     }
     if ($stayOnPage) {
-        $r->print('
-            <td><span class="LC_nobreak"> <a href="'.$origurl.'" target="_top"><img src="'.$location.'/lonIcons/move_up.gif" border="0" alt="('.&mt('Return to last location').')" /> '.&mt('Return to last location').'</a> </span></td>');
+        push(@order,('manuals_web','manuals_pdf','lastloc'));
     } else {
-        $r->print('
-            <td><span class="LC_nobreak"> <a href="javascript:window.close()" target="_top"><img src="$location/lonIcons/closepage.gif" border="0" alt="('.&mt('Close window').')" /> '.&mt('Close').'</a> </span></td>');
+        push(@order,'close');
     }
-    $r->print(<<END);
-  </tr>
- </table>
-</fieldset>
-  </td>
-  <td width='100%'> </td>
- </tr>
- <tr>
-  <td colspan='3' height='5'> </td>
- </tr>
-</table>
-END
-    $r->print(&Apache::loncommon::end_page());
+    my $menu;
+    foreach my $title (@order) {
+        my $menuitem = $items{$title};
+        next unless (ref($menuitem) eq 'HASH');
+        if (defined($help_submenu{$title})) {
+            my ($link,$target);
+            if ($menuitem->{href} ne '') {
+                $link = $menuitem->{href};
+                $target = 'bodyframe';
+            } else {
+                $link = '#';
+            }
+            my @helpsub;
+            if (ref($help_submenu{$title}) eq 'ARRAY') {
+                foreach my $item (@{$help_submenu{$title}}) {
+                    if (ref($item) eq 'ARRAY') {
+                        if (($item->[2] eq 'course') || ($item->[2] eq 'author')) {
+                            next unless($env{'user.adv'});
+                        }
+                        push(@helpsub,$item);
+                    }
+                }
+                if (@helpsub > 0) {
+                    my $img;
+                    if ($menuitem->{img}) {
+                        $img = '<img class="LC_noBorder" style="vertical-align:top" src="'.$menuitem->{img}.'" alt="'.$menuitem->{alt}.'" />';
+                    }
+                    $menu .= &create_submenu($link,$img,$target,$menuitem->{text},\@helpsub,1);
+                } elsif ($link ne '#') {
+                    $menu .= '<li><a href="'.$link.'" target="'.$target.'">'.$menuitem->{text}.'</a></li>';
+                }
+            }
+        } else {
+            $menu .= &build_menuitem($menuitem);
+        }
+    }
+    return $menu;
+}
+
+sub build_menuitem {
+    my ($menuitem) = @_;
+    return '' unless(ref($menuitem) eq 'HASH');
+    my $link;
+    if ($menuitem->{img}) {
+        $link = '<img style="vertical-align:top" class="LC_noBorder" src="'.$menuitem->{img}.'" alt="'.$menuitem->{alt}.'" /> ';
+    }
+    if ($menuitem->{text}) {
+        $link .= $menuitem->{text};
+    }
+    my $target;
+    if ($menuitem->{target}) {
+        $target = $menuitem->{target};
+    } else {
+        $target = 'bodyframe';
+    }
+    my $onclick;
+    if ($menuitem->{onclick}) {
+        $onclick = ' onclick="'.$menuitem->{onclick}.';return false"';
+    }
+    return '<li><a href="'.$menuitem->{href}.'" target="'.$target.'"'.$onclick.'>'.$link.'</a></li>',
+}
+
+sub create_submenu {
+    my ($link,$img,$target,$title,$submenu,$translate) = @_;
+    return unless (ref($submenu) eq 'ARRAY');
+    my $disptarget;
+    if ($target ne '') {
+        $disptarget = ' target="'.$target.'"';
+    }
+    my $menu = '<li class="LC_hoverable">'.$img.
+               '<a href="'.$link.'"'.$disptarget.'>'.
+               '<span class="LC_nobreak">'.$title.
+               '<span class="LC_fontsize_small" style="font-weight:normal;">'.
+               ' ▼</span></span></a>'.
+               '<ul>';
+    my $count = 0;
+    my $numsub = scalar(@{$submenu});
+    foreach my $item (@{$submenu}) {
+        $count ++;
+        if (ref($item) eq 'ARRAY') {
+            my $href = $item->[0];
+            my $borderbot;
+            if ($count == $numsub) {
+                $borderbot = 'border-bottom:1px solid black;';
+            }
+            $menu .= '<li style="margin:0;padding:0;'.
+                     $borderbot.'"><a href="'.$href.'" target="bodyframe">';
+            if ($translate) {
+                $menu .= &mt($item->[1]);
+            } else {
+                $menu .= $item->[1];
+            }
+            $menu .= '</a></li>';
+        }
+    }
+    $menu .= '</ul></li>';
+    return $menu;
 }
 
 sub display_help_mainpage {
-    my ($r,$faq,$bug,$topic,$component_url,$origurl,$bugurl,$faqbaseurl,$requestmail) = @_;
+    my ($r,$faq,$bug,$topic,$component_url,$origurl,$bugurl,$faqbaseurl,$requestmail,$stayOnPage) = @_;
 
     my %lt =&Apache::lonlocal::texthash(
         'topp' => 'Topic Page',
@@ -220,16 +384,18 @@
         'suim' => ' Suggested improvements may include additional functionality, improved usability, or changes to wording used in LON-CAPA pages, including the embedded help system.'
     );
 
-    my %body_layout = 
-	('topmargin'    => "0",
-	 'marginheight' => "0");
-    my $start_page =
-	&Apache::loncommon::start_page('Help Content',undef,
-				       {'add_entries' => \%body_layout,
-					'only_body'   => 1,});
-    $r->print($start_page);
+    if ($stayOnPage) {
+	$r->print(&Apache::loncommon::start_page('Help Content',undef,
+				                 {'no_secondary_menu' => 1,}));
+    } else {
+        $r->print(&Apache::loncommon::start_page('Help Content',undef,
+                                                 {'only_body' => 1,}));
+    }
+    if ($stayOnPage) {
+        $r->print('<div>');
+    } 
     $r->print('<b>'.$lt{'chen'});
-    if ($requestmail =~ m/^[^\@]+\@[^\@]+$/) {
+    if ($requestmail) {
         $r->print(', '.$lt{'orto'});
     } else {
         $r->print(".");
@@ -247,7 +413,7 @@
             }
         }
     }
-    if ($requestmail =~ m/^[^\@]+\@[^\@]+$/) {
+    if ($requestmail) {
         $r->print("
           <ul>
            <li><a href=\"/adm/support?origurl=".&escape($origurl)."\">$lt{'cont'}</a></li>
@@ -282,6 +448,9 @@
           <p>$lt{'crea'} $lt{'suim'}</p>
         ");
     }
+    if ($stayOnPage) {
+        $r->print('</div>');
+    }
     $r->print(&Apache::loncommon::end_page());
 }
 


More information about the LON-CAPA-cvs mailing list