File:  [LON-CAPA] / loncom / interface / lonhelpmenu.pm
Revision 1.44: download - view: text, annotated - select for diffs
Sun Jan 5 21:33:58 2014 UTC (10 years, 4 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_11_1, version_2_11_0_RC3, version_2_11_0_RC2, version_2_11_0, HEAD
- Fix the URLs for the authoring manual.

    1: # The LearningOnline Network with CAPA
    2: # generate frame-based help system
    3: #
    4: # $Id: lonhelpmenu.pm,v 1.44 2014/01/05 21:33:58 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: 
   40: sub handler {
   41:     my ($r) = @_;
   42:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['page','faq','bug','topic','component_help','origurl','stayonpage']);
   43:     &Apache::loncommon::content_type($r,'text/html');
   44:     $r->send_http_header;
   45: 
   46:     if ($r->header_only) {
   47:         return OK;
   48:     }
   49:     my $faq = $env{'form.faq'};
   50:     my $bug = $env{'form.bug'};
   51:     my $topic = $env{'form.topic'};
   52:     my $component_help = $env{'form.component_help'};
   53:     my $origurl = $env{'form.origurl'};
   54:     my $stayOnPage = $env{'form.stayonpage'};
   55:     my $component_url = $component_help;
   56:     if ($component_url) {
   57:         $component_url = '/adm/help/'.$component_url.'.hlp';
   58:     }
   59:     my $bugurl = $Apache::lonnet::perlvar{'BugzillaHost'};
   60:     $bugurl .= 'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.$origurl;
   61:     if ($bug) {
   62:         $bugurl .= '&component='.$bug;
   63:     }
   64:     my $faqbaseurl = $Apache::lonnet::perlvar{'FAQHost'};
   65:     my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
   66:     my $defdom;
   67:     if ($env{'request.course.id'}) {
   68:         $defdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
   69:     } elsif ($env{'request.role.domain'}) {
   70:         $defdom = $env{'request.role.domain'};
   71:     } else {
   72:         $defdom = &Apache::lonnet::default_login_domain();
   73:     }
   74:     my $requestmail = &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
   75:                                                                $defdom,$origmail);
   76:     if ($env{'form.page'} eq 'banner') {
   77:         &display_help_banner($r,$faq,$bug,$topic,$component_url,$origurl,$bugurl,$faqbaseurl,$requestmail,$stayOnPage);
   78:     } elsif ($env{'form.page'} eq 'body') {
   79:         &display_help_mainpage($r,$faq,$bug,$topic,$component_url,$origurl,$bugurl,$faqbaseurl,$requestmail,$stayOnPage);
   80:     }
   81:     return OK;
   82: }
   83: 
   84: sub display_help_banner {
   85:     my ($r,$faq,$bug,$topic,$component_url,$origurl,$bugurl,$faqbaseurl,$requestmail,$stayOnPage) = @_;
   86:     my $location=&Apache::loncommon::lonhttpdurl("/adm");
   87:     my $dom = $env{'request.role.domain'};
   88:     my $scripttag = '';
   89:     if ($requestmail) {
   90:         my $displayurl = &escape($origurl);
   91:         $scripttag = (<<"SCRIPT_ONE");
   92: <script type="text/javascript">
   93: // <![CDATA[
   94: function gohelpdesk() {
   95:     var actiontype = null;
   96:     try {
   97:         actiontype = parent.bodyframe.document.logproblem.action.value;
   98:     }
   99:     catch(error) {
  100:         parent.bodyframe.location = "/adm/support?origurl=$displayurl";
  101:         return;
  102:     }
  103:     if (actiontype) {
  104:         var loc = parent.bodyframe.location.href;
  105:         if (loc.indexOf("/adm/support") > -1) {
  106:             if (parent.bodyframe.document.logproblem.action.value == "process") {
  107:                 if (validmail(parent.bodyframe.document.logproblem.email) == false) {
  108:                     alert("The e-mail address you entered: "+parent.bodyframe.document.logproblem.email.value+" is not a valid e-mail address.");
  109:                     return;
  110:                 }
  111:                 parent.bodyframe.document.logproblem.submit();
  112:                 return;
  113:             }
  114:         }
  115:         parent.bodyframe.location = "/adm/support?origurl=$displayurl";
  116:         return;
  117:     }
  118: }
  119: 
  120: SCRIPT_ONE
  121:         $scripttag .= (<<'SCRIPT_TWO');
  122: function validmail(field) {
  123:     var str = field.value;
  124:     if (window.RegExp) {
  125:         var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
  126:         var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$"; //"
  127:         var reg1 = new RegExp(reg1str);
  128:         var reg2 = new RegExp(reg2str);
  129:         if (!reg1.test(str) && reg2.test(str)) {
  130:             return true;
  131:         }
  132:         return false;
  133:     }
  134:     else
  135:     {
  136: 
  137:         if(str.indexOf("@") >= 0) {
  138:             return true;
  139:         }
  140:         return false;
  141:     }
  142: }
  143: 
  144: // ]]>
  145: </script>
  146: SCRIPT_TWO
  147:     }
  148: 
  149:     if ($stayOnPage) {
  150: 	$r->print(&Apache::loncommon::start_page('Help',$scripttag,
  151: 					         {'no_secondary_menu' => 1,}));
  152:     } else {
  153:         $r->print(&Apache::loncommon::start_page('Help',$scripttag,
  154:                                                  {'only_body' => 1,}));
  155:     }
  156:     my $menu = &helpmenu_items($dom,$faq,$bug,$topic,$component_url,$origurl,$bugurl,$faqbaseurl,$requestmail,$stayOnPage);
  157:     if ($menu) {
  158:         $r->print("<ul id=\"LC_secondary_menu\">$menu</ul>");
  159:     }
  160:     if ($stayOnPage && $env{'user.adv'}) {
  161:         $r->print('<br />');
  162:     } 
  163:     $r->print(&Apache::loncommon::end_page());
  164: }
  165: 
  166: sub helpmenu_items {
  167:     my ($dom,$faq,$bug,$topic,$component_url,$origurl,$bugurl,$faqbaseurl,$requestmail,$stayOnPage) = @_;
  168:     my $location=&Apache::loncommon::lonhttpdurl("/adm");
  169:     my $general_help = &Apache::loncommon::general_help();
  170:     my %helpconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$dom);
  171:     my %lt = &Apache::lonlocal::texthash(
  172:                                             general       => 'General help',
  173:                                             component     => 'Topic help',
  174:                                             faq           => 'FAQ',
  175:                                             helpdesk      => 'Ask helpdesk',
  176:                                             bugs          => 'Report a bug',
  177:                                             manuals_web   => 'Online manuals',
  178:                                             manuals_pdf   => 'Printable manuals',
  179:                                             lastloc       => 'Go back',
  180:                                             close         => 'Close',
  181:                                          );
  182:     my %items = (
  183:                     general => {
  184:                                  href => '/adm/help/'.$general_help.'.hlp',
  185:                                  img  => $location.'/help/help.png',
  186:                                  alt  => $lt{'general'},
  187:                                  text => $lt{'general'},
  188:                                },
  189:                     component => {
  190:                                    href => $component_url,
  191:                                    img  => $location.'/help/help.png',
  192:                                    alt  => $lt{'component'},
  193:                                    text => $topic,
  194:                                  },
  195:                     faq      => {
  196:                                    href => $faqbaseurl.'fom/cache/'.$faq.'.html',
  197:                                    img  => $location.'/lonMisc/smallFAQ.gif',
  198:                                    alt  => $lt{'faq'},
  199:                                    text => $lt{'faq'},                                   
  200:                                  },
  201:                     helpdesk => {
  202:                                    href    => '#',
  203:                                    onclick => 'gohelpdesk()',
  204:                                    img  => $location.'/lonIcons/helpdesk.gif',    
  205:                                    alt  => $lt{'helpdesk'},
  206:                                    text => $lt{'helpdesk'},
  207:                                 },
  208:                     bugs     => {
  209:                                    href => $bugurl,
  210:                                    img  => $location.'/lonMisc/smallBug.gif', 
  211:                                    alt  => $lt{'bugs'},
  212:                                    text => $lt{'bugs'},
  213:                                 },
  214:                     manuals_web  => {
  215:                                        href => '',
  216:                                        img  => $location.'/lonIcons/html.gif',
  217:                                        alt  => $lt{'manuals_web'},
  218:                                        text => $lt{'manuals_web'},
  219:                                     },
  220:                     manuals_pdf  => {
  221:                                        href => '',
  222:                                        img  => $location.'/lonIcons/pdf.gif',
  223:                                        alt  => $lt{'manuals_pdf'},
  224:                                        text => $lt{'manuals_pdf'},
  225:                                     },
  226:                     lastloc  => {
  227:                                    href   => $origurl,
  228:                                    img    => '/res/adm/pages/tolastloc.png',
  229:                                    alt    => $lt{'lastloc'},
  230:                                    text   => $lt{'lastloc'},
  231:                                    target => '_top',
  232:                                 },
  233:                     close    => {
  234:                                    href   => 'javascript:window.close()',
  235:                                    img    => $location.'/lonIcons/close.gif',
  236:                                    alt    => $lt{'close'},
  237:                                    text   => $lt{'close'},
  238:                                    target => '_top',
  239:                                 },
  240:     );
  241:     my %help_submenu = (
  242:                            manuals_web => [
  243:                                             ['/adm/help/course.manual.access.hlp','Course Coordination','course'],
  244:                                             ['/adm/help/author.manual.access.hlp','Authoring','author'],
  245:                                           ],
  246:                            manuals_pdf => [
  247:                                             ['/adm/help/course.manual.pdf','Course Coordination','course'],
  248:                                             ['/adm/help/author.manual.pdf','Authoring','author'],
  249:                                           ],
  250:                        );
  251:     my @order = ('general');
  252:     if ($component_url) {
  253:         push(@order,'component');
  254:     }
  255:     if ($requestmail) {
  256:         push(@order,'helpdesk');
  257:     }
  258:     if ($env{'user.adv'} && $faq) {
  259:         push(@order,'faq');
  260:     }
  261:     if (($env{'user.adv'}) && (($helpconfig{'helpsettings'}{'submitbugs'} eq '1') || ($helpconfig{'helpsettings'}{'submitbugs'} eq ''))) {
  262:         push(@order,'bugs');
  263:     }
  264:     if ($stayOnPage) {
  265:         push(@order,('manuals_web','manuals_pdf','lastloc'));
  266:     } else {
  267:         push(@order,'close');
  268:     }
  269:     my $menu;
  270:     foreach my $title (@order) {
  271:         my $menuitem = $items{$title};
  272:         next unless (ref($menuitem) eq 'HASH');
  273:         if (defined($help_submenu{$title})) {
  274:             my ($link,$target);
  275:             if ($menuitem->{href} ne '') {
  276:                 $link = $menuitem->{href};
  277:                 $target = 'bodyframe';
  278:             } else {
  279:                 $link = '#';
  280:             }
  281:             my @helpsub;
  282:             if (ref($help_submenu{$title}) eq 'ARRAY') {
  283:                 foreach my $item (@{$help_submenu{$title}}) {
  284:                     if (ref($item) eq 'ARRAY') {
  285:                         if (($item->[2] eq 'course') || ($item->[2] eq 'author')) {
  286:                             next unless($env{'user.adv'});
  287:                         }
  288:                         push(@helpsub,$item);
  289:                     }
  290:                 }
  291:                 if (@helpsub > 0) {
  292:                     my $img;
  293:                     if ($menuitem->{img}) {
  294:                         $img = '<img class="LC_noBorder" style="vertical-align:top" src="'.$menuitem->{img}.'" alt="'.$menuitem->{alt}.'" />';
  295:                     }
  296:                     $menu .= &create_submenu($link,$img,$target,$menuitem->{text},\@helpsub,1);
  297:                 } elsif ($link ne '#') {
  298:                     $menu .= '<li><a href="'.$link.'" target="'.$target.'">'.$menuitem->{text}.'</a></li>';
  299:                 }
  300:             }
  301:         } else {
  302:             $menu .= &build_menuitem($menuitem);
  303:         }
  304:     }
  305:     return $menu;
  306: }
  307: 
  308: sub build_menuitem {
  309:     my ($menuitem) = @_;
  310:     return '' unless(ref($menuitem) eq 'HASH');
  311:     my $link;
  312:     if ($menuitem->{img}) {
  313:         $link = '<img style="vertical-align:top" class="LC_noBorder" src="'.$menuitem->{img}.'" alt="'.$menuitem->{alt}.'" />&nbsp;';
  314:     }
  315:     if ($menuitem->{text}) {
  316:         $link .= $menuitem->{text};
  317:     }
  318:     my $target;
  319:     if ($menuitem->{target}) {
  320:         $target = $menuitem->{target};
  321:     } else {
  322:         $target = 'bodyframe';
  323:     }
  324:     my $onclick;
  325:     if ($menuitem->{onclick}) {
  326:         $onclick = ' onclick="'.$menuitem->{onclick}.';return false"';
  327:     }
  328:     return '<li><a href="'.$menuitem->{href}.'" target="'.$target.'"'.$onclick.'>'.$link.'</a></li>',
  329: }
  330: 
  331: sub create_submenu {
  332:     my ($link,$img,$target,$title,$submenu,$translate) = @_;
  333:     return unless (ref($submenu) eq 'ARRAY');
  334:     my $disptarget;
  335:     if ($target ne '') {
  336:         $disptarget = ' target="'.$target.'"';
  337:     }
  338:     my $menu = '<li class="LC_hoverable">'.$img.
  339:                '<a href="'.$link.'"'.$disptarget.'>'.
  340:                '<span class="LC_nobreak">'.$title.
  341:                '<span class="LC_fontsize_small" style="font-weight:normal;">'.
  342:                ' &#9660;</span></span></a>'.
  343:                '<ul>';
  344:     my $count = 0;
  345:     my $numsub = scalar(@{$submenu});
  346:     foreach my $item (@{$submenu}) {
  347:         $count ++;
  348:         if (ref($item) eq 'ARRAY') {
  349:             my $href = $item->[0];
  350:             my $borderbot;
  351:             if ($count == $numsub) {
  352:                 $borderbot = 'border-bottom:1px solid black;';
  353:             }
  354:             $menu .= '<li style="margin:0;padding:0;'.
  355:                      $borderbot.'"><a href="'.$href.'" target="bodyframe">';
  356:             if ($translate) {
  357:                 $menu .= &mt($item->[1]);
  358:             } else {
  359:                 $menu .= $item->[1];
  360:             }
  361:             $menu .= '</a></li>';
  362:         }
  363:     }
  364:     $menu .= '</ul></li>';
  365:     return $menu;
  366: }
  367: 
  368: sub display_help_mainpage {
  369:     my ($r,$faq,$bug,$topic,$component_url,$origurl,$bugurl,$faqbaseurl,$requestmail,$stayOnPage) = @_;
  370: 
  371:     my %lt =&Apache::lonlocal::texthash(
  372:         'topp' => 'Topic Page',
  373:         'chen' => 'Choose an entry below to go directly to a relevant help page',
  374:         'orto' => 'or to submit a help request to the LON-CAPA support staff at your institution.',
  375:         'vthp' => 'Visit the help page for ',
  376:         'disp' => 'Display the page in the inline help system that covers this topic.',
  377:         '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.',
  378:         'cont' => 'Contact the LON-CAPA support team',
  379:         'suhr' => 'Submit a help request to the team responsible for LON-CAPA support at this institution.',
  380:         'faqo' => 'FAQ-O-Matic Help system',
  381:         '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.',
  382:         'lbug' => 'LON-CAPA Bugzilla bug/feature request tracking system',
  383:         '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.',
  384:         'suim' => ' Suggested improvements may include additional functionality, improved usability, or changes to wording used in LON-CAPA pages, including the embedded help system.'
  385:     );
  386: 
  387:     if ($stayOnPage) {
  388: 	$r->print(&Apache::loncommon::start_page('Help Content',undef,
  389: 				                 {'no_secondary_menu' => 1,}));
  390:     } else {
  391:         $r->print(&Apache::loncommon::start_page('Help Content',undef,
  392:                                                  {'only_body' => 1,}));
  393:     }
  394:     if ($stayOnPage) {
  395:         $r->print('<div>');
  396:     } 
  397:     $r->print('<b>'.$lt{'chen'});
  398:     if ($requestmail) {
  399:         $r->print(', '.$lt{'orto'});
  400:     } else {
  401:         $r->print(".");
  402:     }
  403:     $r->print('</b>');
  404:     if ($topic) {
  405:         if ( ($component_url) || ($env{'user.adv'}) ) {
  406:             if ($component_url) {
  407:                 $r->print("
  408:           <ul>
  409:            <li><a href=\"$component_url\">$lt{'vthp'} $topic</a></li>
  410:           </ul>
  411:           <p>$lt{'disp'}</p>
  412:                 ");
  413:             }
  414:         }
  415:     }
  416:     if ($requestmail) {
  417:         $r->print("
  418:           <ul>
  419:            <li><a href=\"/adm/support?origurl=".&escape($origurl)."\">$lt{'cont'}</a></li>
  420:           </ul>
  421:           <p>$lt{'suhr'}");
  422:          unless ($env{'user.adv'}) {
  423:              $r->print('<br />'.
  424:                        &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.'). 
  425:                        ' '.
  426:                        &mt('This can be done by clicking the [_1]Communicate[_2] link or the "Send Feedback" link when viewing a content page.',
  427:                           '<a href="/adm/communicate" target="_top">','</a>')); 
  428:          }
  429:          $r->print("</p>");
  430:     }
  431:     if ($faqbaseurl && $env{'user.adv'}) {
  432:         if (!defined($faq) ||$faq eq '') {
  433:             $faq = '1';
  434:         }
  435:         $r->print("
  436:           <ul>
  437:            <li><a href=\"$faqbaseurl/fom/cache/$faq.html\">$lt{'faqo'}</a></li>
  438:           </ul>
  439:           <p>$lt{'tfaq'}</p>
  440:         ");
  441:     }
  442:     if ($bugurl && $env{'user.adv'}) {
  443:         $bugurl .= '?'.$bug;
  444:         $r->print("
  445:           <ul>
  446:            <li><a href=\"$bugurl\">$lt{'lbug'}</a></li>
  447:           </ul>
  448:           <p>$lt{'crea'} $lt{'suim'}</p>
  449:         ");
  450:     }
  451:     if ($stayOnPage) {
  452:         $r->print('</div>');
  453:     }
  454:     $r->print(&Apache::loncommon::end_page());
  455: }
  456: 
  457: 1;

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