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

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

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