Annotation of loncom/interface/lonhelpmenu.pm, revision 1.43

1.1       raeburn     1: # The LearningOnline Network with CAPA
                      2: # generate frame-based help system
                      3: #
1.43    ! raeburn     4: # $Id: lonhelpmenu.pm,v 1.42 2013/08/08 14:31:54 raeburn Exp $
1.37      bisitz      5: #
1.1       raeburn     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();
1.18      raeburn    35: use Apache::lonlocal;
1.20      albertel   36: use Apache::lonnet;
1.25      www        37: use lib '/home/httpd/lib/perl/';
                     38: use LONCAPA;
1.1       raeburn    39: 
1.2       albertel   40: sub handler {
                     41:     my ($r) = @_;
1.29      albertel   42:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['page','faq','bug','topic','component_help','origurl','stayonpage']);
1.2       albertel   43:     &Apache::loncommon::content_type($r,'text/html');
1.1       raeburn    44:     $r->send_http_header;
                     45: 
                     46:     if ($r->header_only) {
                     47:         return OK;
                     48:     }
1.20      albertel   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'};
1.1       raeburn    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'};
1.42      raeburn    60:     $bugurl .= 'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.$origurl;
1.1       raeburn    61:     if ($bug) {
1.42      raeburn    62:         $bugurl .= '&component='.$bug;
1.1       raeburn    63:     }
                     64:     my $faqbaseurl = $Apache::lonnet::perlvar{'FAQHost'};
1.43    ! raeburn    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);
1.20      albertel   76:     if ($env{'form.page'} eq 'banner') {
1.29      albertel   77:         &display_help_banner($r,$faq,$bug,$topic,$component_url,$origurl,$bugurl,$faqbaseurl,$requestmail,$stayOnPage);
1.20      albertel   78:     } elsif ($env{'form.page'} eq 'body') {
1.43    ! raeburn    79:         &display_help_mainpage($r,$faq,$bug,$topic,$component_url,$origurl,$bugurl,$faqbaseurl,$requestmail,$stayOnPage);
1.1       raeburn    80:     }
                     81:     return OK;
                     82: }
                     83: 
                     84: sub display_help_banner {
1.29      albertel   85:     my ($r,$faq,$bug,$topic,$component_url,$origurl,$bugurl,$faqbaseurl,$requestmail,$stayOnPage) = @_;
1.14      albertel   86:     my $location=&Apache::loncommon::lonhttpdurl("/adm");
1.38      jms        87:     my $dom = $env{'request.role.domain'};
1.17      raeburn    88:     my $scripttag = '';
1.43    ! raeburn    89:     if ($requestmail) {
1.25      www        90:         my $displayurl = &escape($origurl);
1.17      raeburn    91:         $scripttag = (<<"SCRIPT_ONE");
1.43    ! raeburn    92: <script type="text/javascript">
1.42      raeburn    93: // <![CDATA[
1.17      raeburn    94: function gohelpdesk() {
                     95:     var actiontype = null;
                     96:     try {
                     97:         actiontype = parent.bodyframe.document.logproblem.action.value;
                     98:     }
                     99:     catch(error) {
1.29      albertel  100:         parent.bodyframe.location = "/adm/support?origurl=$displayurl";
1.17      raeburn   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:         }
1.29      albertel  115:         parent.bodyframe.location = "/adm/support?origurl=$displayurl";
1.17      raeburn   116:         return;
                    117:     }
                    118: }
1.43    ! raeburn   119: 
1.17      raeburn   120: SCRIPT_ONE
                    121:         $scripttag .= (<<'SCRIPT_TWO');
                    122: function validmail(field) {
                    123:     var str = field.value;
                    124:     if (window.RegExp) {
                    125:         var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
1.22      albertel  126:         var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$"; //"
1.17      raeburn   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:     {
1.8       raeburn   136: 
1.17      raeburn   137:         if(str.indexOf("@") >= 0) {
                    138:             return true;
                    139:         }
                    140:         return false;
                    141:     }
                    142: }
1.43    ! raeburn   143: 
1.42      raeburn   144: // ]]>
1.17      raeburn   145: </script>
                    146: SCRIPT_TWO
                    147:     }
1.22      albertel  148: 
1.43    ! raeburn   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: }
1.27      albertel  165: 
1.43    ! raeburn   166: sub helpmenu_items {
        !           167:     my ($dom,$faq,$bug,$topic,$component_url,$origurl,$bugurl,$faqbaseurl,$requestmail,$stayOnPage) = @_;
        !           168:     my $location=&Apache::loncommon::lonhttpdurl("/adm");
1.31      albertel  169:     my $general_help = &Apache::loncommon::general_help();
1.43    ! raeburn   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/course.manual.access.hlp','Authoring','author'],
        !           245:                                           ],
        !           246:                            manuals_pdf => [
        !           247:                                             ['/adm/help/course.manual.pdf','Course Coordination','course'],
        !           248:                                             ['/adm/help/course.manual.pdf','Authoring','author'],
        !           249:                                           ],
        !           250:                        );
        !           251:     my @order = ('general');
1.21      www       252:     if ($component_url) {
1.43    ! raeburn   253:         push(@order,'component');
        !           254:     }
        !           255:     if ($requestmail) {
        !           256:         push(@order,'helpdesk');
        !           257:     }
        !           258:     if ($env{'user.adv'} && $faq) {
        !           259:         push(@order,'faq');
1.1       raeburn   260:     }
1.43    ! raeburn   261:     if (($env{'user.adv'}) && (($helpconfig{'helpsettings'}{'submitbugs'} eq '1') || ($helpconfig{'helpsettings'}{'submitbugs'} eq ''))) {
        !           262:         push(@order,'bugs');
1.1       raeburn   263:     }
1.8       raeburn   264:     if ($stayOnPage) {
1.43    ! raeburn   265:         push(@order,('manuals_web','manuals_pdf','lastloc'));
1.8       raeburn   266:     } else {
1.43    ! raeburn   267:         push(@order,'close');
1.8       raeburn   268:     }
1.43    ! raeburn   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;
1.1       raeburn   366: }
                    367: 
                    368: sub display_help_mainpage {
1.43    ! raeburn   369:     my ($r,$faq,$bug,$topic,$component_url,$origurl,$bugurl,$faqbaseurl,$requestmail,$stayOnPage) = @_;
1.22      albertel  370: 
1.8       raeburn   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:     );
1.22      albertel  386: 
1.43    ! raeburn   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:     } 
1.30      www       397:     $r->print('<b>'.$lt{'chen'});
1.43    ! raeburn   398:     if ($requestmail) {
1.8       raeburn   399:         $r->print(', '.$lt{'orto'});
1.1       raeburn   400:     } else {
                    401:         $r->print(".");
                    402:     }
1.30      www       403:     $r->print('</b>');
1.1       raeburn   404:     if ($topic) {
1.20      albertel  405:         if ( ($component_url) || ($env{'user.adv'}) ) {
1.1       raeburn   406:             if ($component_url) {
                    407:                 $r->print("
                    408:           <ul>
1.8       raeburn   409:            <li><a href=\"$component_url\">$lt{'vthp'} $topic</a></li>
1.1       raeburn   410:           </ul>
1.8       raeburn   411:           <p>$lt{'disp'}</p>
1.1       raeburn   412:                 ");
                    413:             }
                    414:         }
                    415:     }
1.43    ! raeburn   416:     if ($requestmail) {
1.1       raeburn   417:         $r->print("
                    418:           <ul>
1.29      albertel  419:            <li><a href=\"/adm/support?origurl=".&escape($origurl)."\">$lt{'cont'}</a></li>
1.1       raeburn   420:           </ul>
1.18      raeburn   421:           <p>$lt{'suhr'}");
1.20      albertel  422:          unless ($env{'user.adv'}) {
1.40      raeburn   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>')); 
1.18      raeburn   428:          }
                    429:          $r->print("</p>");
1.1       raeburn   430:     }
1.20      albertel  431:     if ($faqbaseurl && $env{'user.adv'}) {
1.1       raeburn   432:         if (!defined($faq) ||$faq eq '') {
                    433:             $faq = '1';
                    434:         }
                    435:         $r->print("
1.11      raeburn   436:           <ul>
1.8       raeburn   437:            <li><a href=\"$faqbaseurl/fom/cache/$faq.html\">$lt{'faqo'}</a></li>
1.1       raeburn   438:           </ul>
1.8       raeburn   439:           <p>$lt{'tfaq'}</p>
1.1       raeburn   440:         ");
                    441:     }
1.20      albertel  442:     if ($bugurl && $env{'user.adv'}) {
1.1       raeburn   443:         $bugurl .= '?'.$bug;
                    444:         $r->print("
                    445:           <ul>
1.8       raeburn   446:            <li><a href=\"$bugurl\">$lt{'lbug'}</a></li>
1.1       raeburn   447:           </ul>
1.8       raeburn   448:           <p>$lt{'crea'} $lt{'suim'}</p>
1.1       raeburn   449:         ");
                    450:     }
1.43    ! raeburn   451:     if ($stayOnPage) {
        !           452:         $r->print('</div>');
        !           453:     }
1.22      albertel  454:     $r->print(&Apache::loncommon::end_page());
1.1       raeburn   455: }
                    456: 
                    457: 1;

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