File:  [LON-CAPA] / loncom / interface / lonhelpmenu.pm
Revision 1.50: download - view: text, annotated - select for diffs
Thu Feb 20 03:05:34 2025 UTC (39 hours, 12 minutes ago) by raeburn
Branches: MAIN
CVS tags: version_2_12_X, HEAD
- WCAG 2 compliance.

    1: # The LearningOnline Network with CAPA
    2: # generate frame-based help system
    3: #
    4: # $Id: lonhelpmenu.pm,v 1.50 2025/02/20 03:05:34 raeburn Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: 
   29: package Apache::lonhelpmenu;
   30: 
   31: use strict;
   32: use lib qw(/home/httpd/lib/perl);
   33: use Apache::Constants qw(:common);
   34: use Apache::loncommon();
   35: use Apache::lonlocal;
   36: use Apache::lonnet;
   37: use lib '/home/httpd/lib/perl/';
   38: use LONCAPA;
   39: use HTML::Entities();
   40: 
   41: sub handler {
   42:     my ($r) = @_;
   43:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['page','faq','bug','topic','component_help','origurl','stayonpage']);
   44:     &Apache::loncommon::content_type($r,'text/html');
   45:     $r->send_http_header;
   46: 
   47:     if ($r->header_only) {
   48:         return OK;
   49:     }
   50:     my $faq = $env{'form.faq'};
   51:     my $bug = $env{'form.bug'};
   52:     my $topic = $env{'form.topic'};
   53:     my $component_help = $env{'form.component_help'};
   54:     my $origurl = $env{'form.origurl'};
   55:     my $stayOnPage = $env{'form.stayonpage'};
   56:     my $component_url = $component_help;
   57:     if ($component_url) {
   58:         $component_url = '/adm/help/'.$component_url.'.hlp';
   59:     }
   60:     my $bugurl = $Apache::lonnet::perlvar{'BugzillaHost'};
   61:     $bugurl .= 'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.$origurl;
   62:     if ($bug) {
   63:         $bugurl .= '&component='.$bug;
   64:     }
   65:     my $faqbaseurl = $Apache::lonnet::perlvar{'FAQHost'};
   66:     my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
   67:     $origurl = &unescape($origurl);
   68:     my $defdom;
   69:     if ($env{'request.course.id'}) {
   70:         $defdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
   71:     } elsif ($env{'request.role.domain'}) {
   72:         $defdom = $env{'request.role.domain'};
   73:     } else {
   74:         $defdom = &Apache::lonnet::default_login_domain();
   75:     }
   76:     my $requestmail = &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
   77:                                                                $defdom,$origmail);
   78:     if ($env{'form.page'} eq 'banner') {
   79:         &display_help_banner($r,$faq,$bug,$topic,$component_url,$origurl,$bugurl,$faqbaseurl,$requestmail,$stayOnPage);
   80:     } elsif ($env{'form.page'} eq 'body') {
   81:         &display_help_mainpage($r,$faq,$bug,$topic,$component_url,$origurl,$bugurl,$faqbaseurl,$requestmail,$stayOnPage);
   82:     }
   83:     return OK;
   84: }
   85: 
   86: sub display_help_banner {
   87:     my ($r,$faq,$bug,$topic,$component_url,$origurl,$bugurl,$faqbaseurl,$requestmail,$stayOnPage) = @_;
   88:     my $dom = $env{'request.role.domain'};
   89:     my $scripttag = '';
   90:     if ($requestmail) {
   91:         my $displayurl = &escape($origurl);
   92:         $scripttag = (<<"SCRIPT_ONE");
   93: <script type="text/javascript">
   94: // <![CDATA[
   95: function gohelpdesk() {
   96:     var actiontype = null;
   97:     try {
   98:         actiontype = parent.bodyframe.document.logproblem.action.value;
   99:     }
  100:     catch(error) {
  101:         parent.bodyframe.location = "/adm/support?origurl=$displayurl";
  102:         return;
  103:     }
  104:     if (actiontype) {
  105:         var loc = parent.bodyframe.location.href;
  106:         if (loc.indexOf("/adm/support") > -1) {
  107:             if (parent.bodyframe.document.logproblem.action.value == "process") {
  108:                 if (validmail(parent.bodyframe.document.logproblem.email) == false) {
  109:                     alert("The e-mail address you entered: "+parent.bodyframe.document.logproblem.email.value+" is not a valid e-mail address.");
  110:                     return;
  111:                 }
  112:                 parent.bodyframe.document.logproblem.submit();
  113:                 return;
  114:             }
  115:         }
  116:         parent.bodyframe.location = "/adm/support?origurl=$displayurl";
  117:         return;
  118:     }
  119: }
  120: 
  121: SCRIPT_ONE
  122:         $scripttag .= (<<'SCRIPT_TWO');
  123: function validmail(field) {
  124:     var str = field.value;
  125:     if (window.RegExp) {
  126:         var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
  127:         var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$"; //"
  128:         var reg1 = new RegExp(reg1str);
  129:         var reg2 = new RegExp(reg2str);
  130:         if (!reg1.test(str) && reg2.test(str)) {
  131:             return true;
  132:         }
  133:         return false;
  134:     }
  135:     else
  136:     {
  137: 
  138:         if(str.indexOf("@") >= 0) {
  139:             return true;
  140:         }
  141:         return false;
  142:     }
  143: }
  144: 
  145: // ]]>
  146: </script>
  147: SCRIPT_TWO
  148:     }
  149: 
  150:     if ($stayOnPage) {
  151: 	$r->print(&Apache::loncommon::start_page('Help',$scripttag,
  152: 					         {'no_secondary_menu' => 1,}));
  153:     } else {
  154:         $r->print(&Apache::loncommon::start_page('Help',$scripttag,
  155:                                                  {'only_body' => 1,}));
  156:     }
  157:     my $menu = &helpmenu_items($dom,$faq,$bug,$topic,$component_url,$origurl,$bugurl,$faqbaseurl,$requestmail,$stayOnPage);
  158:     $r->print('<div class="LC_landmark" role="main">'."\n");
  159:     if ($menu) {
  160:         $r->print("<ul id=\"LC_secondary_menu\">$menu</ul>");
  161:     }
  162:     if ($stayOnPage && $env{'user.adv'}) {
  163:         $r->print('<br />');
  164:     } 
  165:     $r->print('</div>'.&Apache::loncommon::end_page());
  166: }
  167: 
  168: sub helpmenu_items {
  169:     my ($dom,$faq,$bug,$topic,$component_url,$origurl,$bugurl,$faqbaseurl,$requestmail,$stayOnPage) = @_;
  170:     my $location=&Apache::loncommon::lonhttpdurl("/adm");
  171:     my $general_help = &Apache::loncommon::general_help();
  172:     my %helpconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$dom);
  173:     my %lt = &Apache::lonlocal::texthash(
  174:                                             general       => 'General help',
  175:                                             component     => 'Topic help',
  176:                                             faq           => 'FAQ',
  177:                                             helpdesk      => 'Ask helpdesk',
  178:                                             bugs          => 'Report a bug',
  179:                                             manuals_web   => 'Online manuals',
  180:                                             manuals_pdf   => 'Printable manuals',
  181:                                             lastloc       => 'Go back',
  182:                                             close         => 'Close',
  183:                                          );
  184:     my %alt = &Apache::lonlocal::texthash(
  185:                                              general     => 'Intro help icon',
  186:                                              component   => 'Topic icon',
  187:                                              faq         => 'FAQ icon',
  188:                                              helpdesk    => 'Helpdesk form icon',
  189:                                              bugs        => 'Bug reporting icon',
  190:                                              manuals_web => 'HTML manuals icon',
  191:                                              manuals_pdf => 'PDF manuals icon',
  192:                                              lastloc     => 'Return icon',
  193:                                              close       => 'Close help icon',
  194:                                            );
  195:     my ($target,$bugs_target);
  196:     if ((($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) ||
  197:         (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self'))) {
  198:         $target = '_parent';
  199:         $bugs_target = '_blank';
  200:     } else {
  201:         $target = '_top';
  202:         $bugs_target = '_top';
  203:     }
  204:     my %items = (
  205:                     general => {
  206:                                  href => '/adm/help/'.$general_help.'.hlp',
  207:                                  img  => $location.'/help/help.png',
  208:                                  alt  => $alt{'general'},
  209:                                  text => $lt{'general'},
  210:                                },
  211:                     component => {
  212:                                    href => $component_url,
  213:                                    img  => $location.'/help/help.png',
  214:                                    alt  => $alt{'component'},
  215:                                    text => $topic,
  216:                                  },
  217:                     faq      => {
  218:                                    href => $faqbaseurl.'fom/cache/'.$faq.'.html',
  219:                                    img  => $location.'/lonMisc/smallFAQ.gif',
  220:                                    alt  => $alt{'faq'},
  221:                                    text => $lt{'faq'},                                   
  222:                                  },
  223:                     helpdesk => {
  224:                                    href    => '#',
  225:                                    onclick => 'gohelpdesk()',
  226:                                    img  => $location.'/lonIcons/helpdesk.gif',    
  227:                                    alt  => $alt{'helpdesk'},
  228:                                    text => $lt{'helpdesk'},
  229:                                 },
  230:                     bugs     => {
  231:                                    href => $bugurl,
  232:                                    img  => $location.'/lonMisc/smallBug.gif', 
  233:                                    alt  => $alt{'bugs'},
  234:                                    text => $lt{'bugs'},
  235:                                    target => $bugs_target,
  236:                                 },
  237:                     manuals_web  => {
  238:                                        href => '',
  239:                                        img  => $location.'/lonIcons/html.gif',
  240:                                        alt  => $alt{'manuals_web'},
  241:                                        text => $lt{'manuals_web'},
  242:                                     },
  243:                     manuals_pdf  => {
  244:                                        href => '',
  245:                                        img  => $location.'/lonIcons/pdf.gif',
  246:                                        alt  => $alt{'manuals_pdf'},
  247:                                        text => $lt{'manuals_pdf'},
  248:                                     },
  249:                     lastloc  => {
  250:                                    href   => &HTML::Entities::encode($origurl,'"&<>'),
  251:                                    img    => '/res/adm/pages/tolastloc.png',
  252:                                    alt    => $alt{'lastloc'},
  253:                                    text   => $lt{'lastloc'},
  254:                                    target => $target,
  255:                                 },
  256:                     close    => {
  257:                                    href   => 'javascript:window.close()',
  258:                                    img    => $location.'/lonIcons/close.gif',
  259:                                    alt    => $alt{'close'},
  260:                                    text   => $lt{'close'},
  261:                                    target => $target,
  262:                                 },
  263:     );
  264:     my %help_submenu = (
  265:                            manuals_web => [
  266:                                             ['/adm/help/course.manual.access.hlp','Course Coordination','course'],
  267:                                             ['/adm/help/author.manual.access.hlp','Authoring','author'],
  268:                                           ],
  269:                            manuals_pdf => [
  270:                                             ['/adm/help/course.manual.pdf','Course Coordination','course'],
  271:                                             ['/adm/help/author.manual.pdf','Authoring','author'],
  272:                                           ],
  273:                        );
  274:     my @order = ('general');
  275:     if ($component_url) {
  276:         push(@order,'component');
  277:     }
  278:     if ($requestmail) {
  279:         push(@order,'helpdesk');
  280:     }
  281:     if ($env{'user.adv'} && $faq) {
  282:         push(@order,'faq');
  283:     }
  284:     if (($env{'user.adv'}) && (($helpconfig{'helpsettings'}{'submitbugs'} eq '1') || ($helpconfig{'helpsettings'}{'submitbugs'} eq ''))) {
  285:         push(@order,'bugs');
  286:     }
  287:     if ($stayOnPage) {
  288:         push(@order,('manuals_web','manuals_pdf','lastloc'));
  289:     } else {
  290:         push(@order,'close');
  291:     }
  292:     my $menu;
  293:     foreach my $title (@order) {
  294:         my $menuitem = $items{$title};
  295:         next unless (ref($menuitem) eq 'HASH');
  296:         if (defined($help_submenu{$title})) {
  297:             my ($link,$target);
  298:             if ($menuitem->{href} ne '') {
  299:                 $link = $menuitem->{href};
  300:                 $target = 'bodyframe';
  301:             } else {
  302:                 $link = '#';
  303:             }
  304:             my @helpsub;
  305:             if (ref($help_submenu{$title}) eq 'ARRAY') {
  306:                 foreach my $item (@{$help_submenu{$title}}) {
  307:                     if (ref($item) eq 'ARRAY') {
  308:                         if (($item->[2] eq 'course') || ($item->[2] eq 'author')) {
  309:                             next unless($env{'user.adv'});
  310:                         }
  311:                         push(@helpsub,$item);
  312:                     }
  313:                 }
  314:                 if (@helpsub > 0) {
  315:                     my $img;
  316:                     if ($menuitem->{img}) {
  317:                         $img = '<img class="LC_noBorder" style="vertical-align:top" src="'.$menuitem->{img}.'" alt="'.$menuitem->{alt}.'" />';
  318:                     }
  319:                     $menu .= &create_submenu($link,$img,$target,$menuitem->{text},\@helpsub,1);
  320:                 } elsif ($link ne '#') {
  321:                     $menu .= '<li><a href="'.$link.'" target="'.$target.'">'.$menuitem->{text}.'</a></li>';
  322:                 }
  323:             }
  324:         } else {
  325:             $menu .= &build_menuitem($menuitem);
  326:         }
  327:     }
  328:     return $menu;
  329: }
  330: 
  331: sub build_menuitem {
  332:     my ($menuitem) = @_;
  333:     return '' unless(ref($menuitem) eq 'HASH');
  334:     my $link;
  335:     if ($menuitem->{img}) {
  336:         $link = '<img style="vertical-align:top" class="LC_noBorder" src="'.$menuitem->{img}.'" alt="'.$menuitem->{alt}.'" />&nbsp;';
  337:     }
  338:     if ($menuitem->{text}) {
  339:         $link .= $menuitem->{text};
  340:     }
  341:     my $target;
  342:     if ($menuitem->{target}) {
  343:         $target = $menuitem->{target};
  344:     } else {
  345:         $target = 'bodyframe';
  346:     }
  347:     my $onclick;
  348:     if ($menuitem->{onclick}) {
  349:         $onclick = ' onclick="'.$menuitem->{onclick}.';return false"';
  350:     }
  351:     return '<li><a href="'.$menuitem->{href}.'" target="'.$target.'"'.$onclick.'>'.$link.'</a></li>',
  352: }
  353: 
  354: sub create_submenu {
  355:     my ($link,$img,$target,$title,$submenu,$translate) = @_;
  356:     return unless (ref($submenu) eq 'ARRAY');
  357:     my $disptarget;
  358:     if ($target ne '') {
  359:         $disptarget = ' target="'.$target.'"';
  360:     }
  361:     my $menu = '<li class="LC_hoverable">'.$img.
  362:                '<a href="'.$link.'"'.$disptarget.'>'.
  363:                '<span class="LC_nobreak">'.$title.
  364:                '<span class="LC_fontsize_medium" style="font-weight:normal;">'.
  365:                ' &#9660;</span></span></a>'.
  366:                '<ul>';
  367:     my $count = 0;
  368:     my $numsub = scalar(@{$submenu});
  369:     foreach my $item (@{$submenu}) {
  370:         $count ++;
  371:         if (ref($item) eq 'ARRAY') {
  372:             my $href = $item->[0];
  373:             my $borderbot;
  374:             if ($count == $numsub) {
  375:                 $borderbot = 'border-bottom:1px solid black;';
  376:             }
  377:             $menu .= '<li style="margin:0;padding:0;'.
  378:                      $borderbot.'"><a href="'.$href.'" target="bodyframe">';
  379:             if ($translate) {
  380:                 $menu .= &mt($item->[1]);
  381:             } else {
  382:                 $menu .= $item->[1];
  383:             }
  384:             $menu .= '</a></li>';
  385:         }
  386:     }
  387:     $menu .= '</ul></li>';
  388:     return $menu;
  389: }
  390: 
  391: sub display_help_mainpage {
  392:     my ($r,$faq,$bug,$topic,$component_url,$origurl,$bugurl,$faqbaseurl,$requestmail,$stayOnPage) = @_;
  393: 
  394:     my %lt =&Apache::lonlocal::texthash(
  395:         'topp' => 'Topic Page',
  396:         'chen' => 'Choose an entry below to go directly to a relevant help page',
  397:         'orto' => 'or to submit a help request to the LON-CAPA support staff at your institution.',
  398:         'vthp' => 'Visit the help page for ',
  399:         'disp' => 'Display the page in the inline help system that covers this topic.',
  400:         'crac' => 'Create an account for yourself in the LON-CAPA Bugzilla tracking system, if you wish to report bugs you have encountered in the LON-CAPA software, or if you have suggestions for improvements in LON-CAPA.',
  401:         'cont' => 'Contact the LON-CAPA support team',
  402:         'suhr' => 'Submit a help request to the team responsible for LON-CAPA support at this institution.',
  403:         'faqo' => 'FAQ-O-Matic Help system',
  404:         'tfaq' => 'The FAQ-O-Matic is a compendium of answers provided to common questions asked by users of LON-CAPA over the past couple of years.',
  405:         'lbug' => 'LON-CAPA Bugzilla bug/feature request tracking system',
  406:         'crea' => 'Create an account for yourself in the LON-CAPA Bugzilla tracking system, if you wish to report bugs you have encountered in the LON-CAPA software,or if you have suggestions for improvements in LON-CAPA.',
  407:         'suim' => ' Suggested improvements may include additional functionality, improved usability, or changes to wording used in LON-CAPA pages, including the embedded help system.'
  408:     );
  409: 
  410:     if ($stayOnPage) {
  411: 	$r->print(&Apache::loncommon::start_page('Help Content',undef,
  412: 				                 {'no_secondary_menu' => 1,}));
  413:     } else {
  414:         $r->print(&Apache::loncommon::start_page('Help Content',undef,
  415:                                                  {'only_body' => 1,}));
  416:     }
  417:     my $target = '_top';
  418:     if ((($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) ||
  419:         (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self'))) {
  420:         $target = '_parent';
  421:     }
  422:     if ($stayOnPage) {
  423:         $r->print('<div>');
  424:     }
  425:     $r->print('<b>'.$lt{'chen'});
  426:     if ($requestmail) {
  427:         $r->print(', '.$lt{'orto'});
  428:     } else {
  429:         $r->print(".");
  430:     }
  431:     $r->print('</b>');
  432:     if ($topic) {
  433:         if ( ($component_url) || ($env{'user.adv'}) ) {
  434:             if ($component_url) {
  435:                 $r->print("
  436:           <ul>
  437:            <li><a href=\"$component_url\">$lt{'vthp'} $topic</a></li>
  438:           </ul>
  439:           <p>$lt{'disp'}</p>
  440:                 ");
  441:             }
  442:         }
  443:     }
  444:     if ($requestmail) {
  445:         $r->print("
  446:           <ul>
  447:            <li><a href=\"/adm/support?origurl=".&escape($origurl)."\">$lt{'cont'}</a></li>
  448:           </ul>
  449:           <p>$lt{'suhr'}");
  450:          unless ($env{'user.adv'}) {
  451:              $r->print('<br />'.
  452:                        &mt('[_1]Note[_2]: questions about course content should not be directed to the support team, but instead should be sent to the course instructor.'). 
  453:                        ' '.
  454:                        &mt('This can be done by clicking the [_1]Communicate[_2] link or the "Send Feedback" link when viewing a content page.',
  455:                           '<a href="/adm/communicate" target="'.$target.'">','</a>')); 
  456:          }
  457:          $r->print("</p>");
  458:     }
  459:     if ($faqbaseurl && $env{'user.adv'}) {
  460:         if (!defined($faq) ||$faq eq '') {
  461:             $faq = '1';
  462:         }
  463:         $r->print("
  464:           <ul>
  465:            <li><a href=\"$faqbaseurl/fom/cache/$faq.html\">$lt{'faqo'}</a></li>
  466:           </ul>
  467:           <p>$lt{'tfaq'}</p>
  468:         ");
  469:     }
  470:     if ($bugurl && $env{'user.adv'}) {
  471:         $bugurl .= '?'.$bug;
  472:         $r->print("
  473:           <ul>
  474:            <li><a href=\"$bugurl\">$lt{'lbug'}</a></li>
  475:           </ul>
  476:           <p>$lt{'crea'} $lt{'suim'}</p>
  477:         ");
  478:     }
  479:     if ($stayOnPage) {
  480:         $r->print('</div>');
  481:     }
  482:     $r->print(&Apache::loncommon::end_page());
  483: }
  484: 
  485: 1;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>