File:  [LON-CAPA] / loncom / interface / lonhelpmenu.pm
Revision 1.47: download - view: text, annotated - select for diffs
Tue May 24 16:23:03 2022 UTC (2 years, 1 month ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Bug 6907 option to stop deep-linked items escaping iframe context.
  Seventh component (target) added to the deeplink parameter.
  Launch of deep-link (i.e. a tiny URL) sets $env{'request.deeplink.target'}.

    1: # The LearningOnline Network with CAPA
    2: # generate frame-based help system
    3: #
    4: # $Id: lonhelpmenu.pm,v 1.47 2022/05/24 16:23:03 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:     if ($menu) {
  159:         $r->print("<ul id=\"LC_secondary_menu\">$menu</ul>");
  160:     }
  161:     if ($stayOnPage && $env{'user.adv'}) {
  162:         $r->print('<br />');
  163:     } 
  164:     $r->print(&Apache::loncommon::end_page());
  165: }
  166: 
  167: sub helpmenu_items {
  168:     my ($dom,$faq,$bug,$topic,$component_url,$origurl,$bugurl,$faqbaseurl,$requestmail,$stayOnPage) = @_;
  169:     my $location=&Apache::loncommon::lonhttpdurl("/adm");
  170:     my $general_help = &Apache::loncommon::general_help();
  171:     my %helpconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$dom);
  172:     my %lt = &Apache::lonlocal::texthash(
  173:                                             general       => 'General help',
  174:                                             component     => 'Topic help',
  175:                                             faq           => 'FAQ',
  176:                                             helpdesk      => 'Ask helpdesk',
  177:                                             bugs          => 'Report a bug',
  178:                                             manuals_web   => 'Online manuals',
  179:                                             manuals_pdf   => 'Printable manuals',
  180:                                             lastloc       => 'Go back',
  181:                                             close         => 'Close',
  182:                                          );
  183:     my $target = '_top';
  184:     if (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
  185:         $target = '_parent';
  186:     }
  187:     if (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self')) {
  188:         $target = '_parent';
  189:     }
  190:     my %items = (
  191:                     general => {
  192:                                  href => '/adm/help/'.$general_help.'.hlp',
  193:                                  img  => $location.'/help/help.png',
  194:                                  alt  => $lt{'general'},
  195:                                  text => $lt{'general'},
  196:                                },
  197:                     component => {
  198:                                    href => $component_url,
  199:                                    img  => $location.'/help/help.png',
  200:                                    alt  => $lt{'component'},
  201:                                    text => $topic,
  202:                                  },
  203:                     faq      => {
  204:                                    href => $faqbaseurl.'fom/cache/'.$faq.'.html',
  205:                                    img  => $location.'/lonMisc/smallFAQ.gif',
  206:                                    alt  => $lt{'faq'},
  207:                                    text => $lt{'faq'},                                   
  208:                                  },
  209:                     helpdesk => {
  210:                                    href    => '#',
  211:                                    onclick => 'gohelpdesk()',
  212:                                    img  => $location.'/lonIcons/helpdesk.gif',    
  213:                                    alt  => $lt{'helpdesk'},
  214:                                    text => $lt{'helpdesk'},
  215:                                 },
  216:                     bugs     => {
  217:                                    href => $bugurl,
  218:                                    img  => $location.'/lonMisc/smallBug.gif', 
  219:                                    alt  => $lt{'bugs'},
  220:                                    text => $lt{'bugs'},
  221:                                 },
  222:                     manuals_web  => {
  223:                                        href => '',
  224:                                        img  => $location.'/lonIcons/html.gif',
  225:                                        alt  => $lt{'manuals_web'},
  226:                                        text => $lt{'manuals_web'},
  227:                                     },
  228:                     manuals_pdf  => {
  229:                                        href => '',
  230:                                        img  => $location.'/lonIcons/pdf.gif',
  231:                                        alt  => $lt{'manuals_pdf'},
  232:                                        text => $lt{'manuals_pdf'},
  233:                                     },
  234:                     lastloc  => {
  235:                                    href   => &HTML::Entities::encode($origurl,'"&<>'),
  236:                                    img    => '/res/adm/pages/tolastloc.png',
  237:                                    alt    => $lt{'lastloc'},
  238:                                    text   => $lt{'lastloc'},
  239:                                    target => $target,
  240:                                 },
  241:                     close    => {
  242:                                    href   => 'javascript:window.close()',
  243:                                    img    => $location.'/lonIcons/close.gif',
  244:                                    alt    => $lt{'close'},
  245:                                    text   => $lt{'close'},
  246:                                    target => $target,
  247:                                 },
  248:     );
  249:     my %help_submenu = (
  250:                            manuals_web => [
  251:                                             ['/adm/help/course.manual.access.hlp','Course Coordination','course'],
  252:                                             ['/adm/help/author.manual.access.hlp','Authoring','author'],
  253:                                           ],
  254:                            manuals_pdf => [
  255:                                             ['/adm/help/course.manual.pdf','Course Coordination','course'],
  256:                                             ['/adm/help/author.manual.pdf','Authoring','author'],
  257:                                           ],
  258:                        );
  259:     my @order = ('general');
  260:     if ($component_url) {
  261:         push(@order,'component');
  262:     }
  263:     if ($requestmail) {
  264:         push(@order,'helpdesk');
  265:     }
  266:     if ($env{'user.adv'} && $faq) {
  267:         push(@order,'faq');
  268:     }
  269:     if (($env{'user.adv'}) && (($helpconfig{'helpsettings'}{'submitbugs'} eq '1') || ($helpconfig{'helpsettings'}{'submitbugs'} eq ''))) {
  270:         push(@order,'bugs');
  271:     }
  272:     if ($stayOnPage) {
  273:         push(@order,('manuals_web','manuals_pdf','lastloc'));
  274:     } else {
  275:         push(@order,'close');
  276:     }
  277:     my $menu;
  278:     foreach my $title (@order) {
  279:         my $menuitem = $items{$title};
  280:         next unless (ref($menuitem) eq 'HASH');
  281:         if (defined($help_submenu{$title})) {
  282:             my ($link,$target);
  283:             if ($menuitem->{href} ne '') {
  284:                 $link = $menuitem->{href};
  285:                 $target = 'bodyframe';
  286:             } else {
  287:                 $link = '#';
  288:             }
  289:             my @helpsub;
  290:             if (ref($help_submenu{$title}) eq 'ARRAY') {
  291:                 foreach my $item (@{$help_submenu{$title}}) {
  292:                     if (ref($item) eq 'ARRAY') {
  293:                         if (($item->[2] eq 'course') || ($item->[2] eq 'author')) {
  294:                             next unless($env{'user.adv'});
  295:                         }
  296:                         push(@helpsub,$item);
  297:                     }
  298:                 }
  299:                 if (@helpsub > 0) {
  300:                     my $img;
  301:                     if ($menuitem->{img}) {
  302:                         $img = '<img class="LC_noBorder" style="vertical-align:top" src="'.$menuitem->{img}.'" alt="'.$menuitem->{alt}.'" />';
  303:                     }
  304:                     $menu .= &create_submenu($link,$img,$target,$menuitem->{text},\@helpsub,1);
  305:                 } elsif ($link ne '#') {
  306:                     $menu .= '<li><a href="'.$link.'" target="'.$target.'">'.$menuitem->{text}.'</a></li>';
  307:                 }
  308:             }
  309:         } else {
  310:             $menu .= &build_menuitem($menuitem);
  311:         }
  312:     }
  313:     return $menu;
  314: }
  315: 
  316: sub build_menuitem {
  317:     my ($menuitem) = @_;
  318:     return '' unless(ref($menuitem) eq 'HASH');
  319:     my $link;
  320:     if ($menuitem->{img}) {
  321:         $link = '<img style="vertical-align:top" class="LC_noBorder" src="'.$menuitem->{img}.'" alt="'.$menuitem->{alt}.'" />&nbsp;';
  322:     }
  323:     if ($menuitem->{text}) {
  324:         $link .= $menuitem->{text};
  325:     }
  326:     my $target;
  327:     if ($menuitem->{target}) {
  328:         $target = $menuitem->{target};
  329:     } else {
  330:         $target = 'bodyframe';
  331:     }
  332:     my $onclick;
  333:     if ($menuitem->{onclick}) {
  334:         $onclick = ' onclick="'.$menuitem->{onclick}.';return false"';
  335:     }
  336:     return '<li><a href="'.$menuitem->{href}.'" target="'.$target.'"'.$onclick.'>'.$link.'</a></li>',
  337: }
  338: 
  339: sub create_submenu {
  340:     my ($link,$img,$target,$title,$submenu,$translate) = @_;
  341:     return unless (ref($submenu) eq 'ARRAY');
  342:     my $disptarget;
  343:     if ($target ne '') {
  344:         $disptarget = ' target="'.$target.'"';
  345:     }
  346:     my $menu = '<li class="LC_hoverable">'.$img.
  347:                '<a href="'.$link.'"'.$disptarget.'>'.
  348:                '<span class="LC_nobreak">'.$title.
  349:                '<span class="LC_fontsize_small" style="font-weight:normal;">'.
  350:                ' &#9660;</span></span></a>'.
  351:                '<ul>';
  352:     my $count = 0;
  353:     my $numsub = scalar(@{$submenu});
  354:     foreach my $item (@{$submenu}) {
  355:         $count ++;
  356:         if (ref($item) eq 'ARRAY') {
  357:             my $href = $item->[0];
  358:             my $borderbot;
  359:             if ($count == $numsub) {
  360:                 $borderbot = 'border-bottom:1px solid black;';
  361:             }
  362:             $menu .= '<li style="margin:0;padding:0;'.
  363:                      $borderbot.'"><a href="'.$href.'" target="bodyframe">';
  364:             if ($translate) {
  365:                 $menu .= &mt($item->[1]);
  366:             } else {
  367:                 $menu .= $item->[1];
  368:             }
  369:             $menu .= '</a></li>';
  370:         }
  371:     }
  372:     $menu .= '</ul></li>';
  373:     return $menu;
  374: }
  375: 
  376: sub display_help_mainpage {
  377:     my ($r,$faq,$bug,$topic,$component_url,$origurl,$bugurl,$faqbaseurl,$requestmail,$stayOnPage) = @_;
  378: 
  379:     my %lt =&Apache::lonlocal::texthash(
  380:         'topp' => 'Topic Page',
  381:         'chen' => 'Choose an entry below to go directly to a relevant help page',
  382:         'orto' => 'or to submit a help request to the LON-CAPA support staff at your institution.',
  383:         'vthp' => 'Visit the help page for ',
  384:         'disp' => 'Display the page in the inline help system that covers this topic.',
  385:         '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.',
  386:         'cont' => 'Contact the LON-CAPA support team',
  387:         'suhr' => 'Submit a help request to the team responsible for LON-CAPA support at this institution.',
  388:         'faqo' => 'FAQ-O-Matic Help system',
  389:         '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.',
  390:         'lbug' => 'LON-CAPA Bugzilla bug/feature request tracking system',
  391:         '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.',
  392:         'suim' => ' Suggested improvements may include additional functionality, improved usability, or changes to wording used in LON-CAPA pages, including the embedded help system.'
  393:     );
  394: 
  395:     if ($stayOnPage) {
  396: 	$r->print(&Apache::loncommon::start_page('Help Content',undef,
  397: 				                 {'no_secondary_menu' => 1,}));
  398:     } else {
  399:         $r->print(&Apache::loncommon::start_page('Help Content',undef,
  400:                                                  {'only_body' => 1,}));
  401:     }
  402:     my $target = '_top';
  403:     if (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
  404:         $target = '_parent';
  405:     }
  406:     if (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self')) {
  407:         $target = '_parent';
  408:     }
  409:     if ($stayOnPage) {
  410:         $r->print('<div>');
  411:     } 
  412:     $r->print('<b>'.$lt{'chen'});
  413:     if ($requestmail) {
  414:         $r->print(', '.$lt{'orto'});
  415:     } else {
  416:         $r->print(".");
  417:     }
  418:     $r->print('</b>');
  419:     if ($topic) {
  420:         if ( ($component_url) || ($env{'user.adv'}) ) {
  421:             if ($component_url) {
  422:                 $r->print("
  423:           <ul>
  424:            <li><a href=\"$component_url\">$lt{'vthp'} $topic</a></li>
  425:           </ul>
  426:           <p>$lt{'disp'}</p>
  427:                 ");
  428:             }
  429:         }
  430:     }
  431:     if ($requestmail) {
  432:         $r->print("
  433:           <ul>
  434:            <li><a href=\"/adm/support?origurl=".&escape($origurl)."\">$lt{'cont'}</a></li>
  435:           </ul>
  436:           <p>$lt{'suhr'}");
  437:          unless ($env{'user.adv'}) {
  438:              $r->print('<br />'.
  439:                        &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.'). 
  440:                        ' '.
  441:                        &mt('This can be done by clicking the [_1]Communicate[_2] link or the "Send Feedback" link when viewing a content page.',
  442:                           '<a href="/adm/communicate" target="'.$target.'">','</a>')); 
  443:          }
  444:          $r->print("</p>");
  445:     }
  446:     if ($faqbaseurl && $env{'user.adv'}) {
  447:         if (!defined($faq) ||$faq eq '') {
  448:             $faq = '1';
  449:         }
  450:         $r->print("
  451:           <ul>
  452:            <li><a href=\"$faqbaseurl/fom/cache/$faq.html\">$lt{'faqo'}</a></li>
  453:           </ul>
  454:           <p>$lt{'tfaq'}</p>
  455:         ");
  456:     }
  457:     if ($bugurl && $env{'user.adv'}) {
  458:         $bugurl .= '?'.$bug;
  459:         $r->print("
  460:           <ul>
  461:            <li><a href=\"$bugurl\">$lt{'lbug'}</a></li>
  462:           </ul>
  463:           <p>$lt{'crea'} $lt{'suim'}</p>
  464:         ");
  465:     }
  466:     if ($stayOnPage) {
  467:         $r->print('</div>');
  468:     }
  469:     $r->print(&Apache::loncommon::end_page());
  470: }
  471: 
  472: 1;

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