File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.369.2.56: download - view: text, annotated - select for diffs
Wed Aug 10 04:10:03 2016 UTC (7 years, 9 months ago) by raeburn
Branches: version_2_11_X
- For 2.11
  - Backport 1.436

    1: # The LearningOnline Network with CAPA
    2: # Routines to control the menu
    3: #
    4: # $Id: lonmenu.pm,v 1.369.2.56 2016/08/10 04:10: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: 
   30: =head1 NAME
   31: 
   32: Apache::lonmenu
   33: 
   34: =head1 SYNOPSIS
   35: 
   36: Loads contents of /home/httpd/lonTabs/mydesk.tab, 
   37: used to generate inline menu, and Main Menu page. 
   38: 
   39: This is part of the LearningOnline Network with CAPA project
   40: described at http://www.lon-capa.org.
   41: 
   42: =head1 GLOBAL VARIABLES
   43: 
   44: =over
   45: 
   46: =item @desklines
   47: 
   48: Each element of this array contains a line of mydesk.tab that doesn't start with
   49: cat, prim or scnd. 
   50: It gets filled in the BEGIN block of this module.
   51: 
   52: =item %category_names
   53: 
   54: The keys of this hash are the abbreviations used in mydesk.tab in those lines that 
   55: start with cat, the values are strings representing titles. 
   56: It gets filled in the BEGIN block of this module.
   57: 
   58: =item %category_members
   59: 
   60: TODO 
   61: 
   62: =item %category_positions
   63: 
   64: The keys of this hash are the abbreviations used in mydesk.tab in those lines that
   65: start with cat, its values are position vectors (column, row). 
   66: It gets filled in the BEGIN block of this module.
   67: 
   68: =item $readdesk
   69: 
   70: Indicates that mydesk.tab has been read. 
   71: It is set to 'done' in the BEGIN block of this module.
   72: 
   73: =item @primary_menu
   74: 
   75: The elements of this array reference arrays that are made up of the components
   76: of those lines of mydesk.tab that start with prim:.
   77: It is used by primary_menu() to generate the corresponding menu.
   78: It gets filled in the BEGIN block of this module.
   79: 
   80: =item %primary_sub_menu
   81: 
   82: The keys of this hash reference are the names of items in the primary_menu array 
   83: which have sub-menus.  For each key, the corresponding value is a reference to
   84: an array containing components extracted from lines in mydesk.tab which begin
   85: with primsub:.
   86: This hash, which is used by primary_menu to generate sub-menus, is populated in
   87: the BEGIN block.
   88: 
   89: =item @secondary_menu
   90: 
   91: The elements of this array reference arrays that are made up of the components
   92: of those lines of mydesk.tab that start with scnd.
   93: It is used by secondary_menu() to generate the corresponding menu.
   94: It gets filled in the BEGIN block of this module.
   95: 
   96: =back
   97: 
   98: =head1 SUBROUTINES
   99: 
  100: =over
  101: 
  102: =item prep_menuitems(\@menuitem)
  103: 
  104: This routine wraps a menuitem in proper HTML. It is used by primary_menu() and 
  105: secondary_menu().
  106: 
  107: =item primary_menu()
  108: 
  109: This routine evaluates @primary_menu and returns a two item array, 
  110: with the array elements containing XHTML for the left and right sides of 
  111: the menu that contains the following links: About, Message, Roles, Help, Logout 
  112: @primary_menu is filled within the BEGIN block of this module with 
  113: entries from mydesk.tab
  114: 
  115: =item secondary_menu()
  116: 
  117: Same as primary_menu() but operates on @secondary_menu.
  118: 
  119: =item create_submenu()
  120: 
  121: Creates XHTML for unordered list of sub-menu items which belong to a
  122: particular top-level menu item. Uses hover pseudo class in css to display
  123: dropdown list when mouse hovers over top-level item. Support for IE6
  124: (no hover psuedo class) via LC_hoverable class for <li> tag for top-
  125: level item, which employs jQuery to handle behavior on mouseover.
  126: 
  127: Inputs: 4 - (a) link and (b) target for anchor href in top level item,
  128:             (c) title for text wrapped by anchor tag in top level item.
  129:             (d) reference to array of arrays of sub-menu items.
  130: 
  131: =item innerregister()
  132: 
  133: This gets called in order to register a URL in the body of the document
  134: 
  135: =item loadevents()
  136: 
  137: =item unloadevents()
  138: 
  139: =item startupremote()
  140: 
  141: =item setflags()
  142: 
  143: =item maincall()
  144: 
  145: =item load_remote_msg()
  146: 
  147: =item get_menu_name()
  148: 
  149: =item reopenmenu()
  150: 
  151: =item open()
  152: 
  153: Open the menu
  154: 
  155: =item clear()
  156: 
  157: =item switch()
  158: 
  159: Switch a button or create a link
  160: Switch acts on the javascript that is executed when a button is clicked.  
  161: The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
  162: 
  163: =item secondlevel()
  164: 
  165: =item openmenu()
  166: 
  167: =item inlinemenu()
  168: 
  169: =item rawconfig()
  170: 
  171: =item utilityfunctions()
  172: 
  173: Output from this routine is a number of javascript functions called by
  174: items in the inline menu, and in some cases items in the Main Menu page. 
  175: 
  176: =item serverform()
  177: 
  178: =item constspaceform()
  179: 
  180: =item get_nav_status()
  181: 
  182: =item hidden_button_check()
  183: 
  184: =item roles_selector()
  185: 
  186: =item jump_to_role()
  187: 
  188: =back
  189: 
  190: =cut
  191: 
  192: package Apache::lonmenu;
  193: 
  194: use strict;
  195: use Apache::lonnet;
  196: use Apache::lonhtmlcommon();
  197: use Apache::loncommon();
  198: use Apache::lonenc();
  199: use Apache::lonlocal;
  200: use Apache::lonmsg();
  201: use LONCAPA qw(:DEFAULT :match);
  202: use HTML::Entities();
  203: use Apache::lonwishlist();
  204: 
  205: use vars qw(@desklines %category_names %category_members %category_positions 
  206:             $readdesk @primary_menu %primary_submenu @secondary_menu %secondary_submenu);
  207: 
  208: my @inlineremote;
  209: 
  210: sub prep_menuitem {
  211:     my ($menuitem) = @_;
  212:     return '' unless(ref($menuitem) eq 'ARRAY');
  213:     my $link;
  214:     if ($$menuitem[1]) { # graphical Link
  215:         $link = "<img class=\"LC_noBorder\""
  216:               . " src=\"" . &Apache::loncommon::lonhttpdurl($$menuitem[1]) . "\"" 
  217:               . " alt=\"" . &mt($$menuitem[2]) . "\" />";
  218:     } else {             # textual Link
  219:         $link = &mt($$menuitem[3]);
  220:     }
  221:     return '<li><a' 
  222:            # highlighting for new messages
  223:            . ( $$menuitem[4] eq 'newmsg' ? ' class="LC_new_message"' : '') 
  224:            . qq| href="$$menuitem[0]" target="_top">$link</a></li>|;
  225: }
  226: 
  227: # primary_menu() evaluates @primary_menu and returns a two item array,
  228: # with the array elements containing XHTML for the left and right sides of 
  229: # the menu that contains the following links:
  230: # Personal, About, Message, Roles, Help, Logout
  231: # @primary_menu is filled within the BEGIN block of this module with 
  232: # entries from mydesk.tab
  233: sub primary_menu {
  234:     my %menu;
  235:     # each element of @primary contains following array:
  236:     # (link url, icon path, alt text, link text, condition, position)
  237:     my $public;
  238:     if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
  239:         || (($env{'user.name'} eq '') && ($env{'user.domain'} eq ''))) {
  240:         $public = 1;
  241:     }
  242:     foreach my $menuitem (@primary_menu) {
  243:         # evaluate conditions 
  244:         next if    ref($menuitem)       ne 'ARRAY';    #
  245:         next if    $$menuitem[4]        eq 'nonewmsg'  # show links depending on
  246:                 && &Apache::lonmsg::mynewmail();       # whether a new msg 
  247:         next if    $$menuitem[4]        eq 'newmsg'    # arrived or not
  248:                 && !&Apache::lonmsg::mynewmail();      # 
  249:         next if    $$menuitem[4]        !~ /public/    ##we've a public user,
  250:                 && $public;                            ##who should not see all
  251:                                                        ##links
  252:         next if    $$menuitem[4]        eq 'onlypublic'# hide links which are 
  253:                 && !$public;                           # only visible to public
  254:                                                        # users
  255:         next if    $$menuitem[4]        eq 'roles'     ##show links depending on
  256:                 && &Apache::loncommon::show_course();  ##term 'Courses' or 
  257:         next if    $$menuitem[4]        eq 'courses'   ##'Roles' wanted
  258:                 && !&Apache::loncommon::show_course(); ##
  259:         
  260:         my $title = $menuitem->[3];
  261:         my $position = $menuitem->[5];
  262:         if ($position eq '') {
  263:             $position = 'right';
  264:         }
  265:         if (defined($primary_submenu{$title})) {
  266:             my ($link,$target);
  267:             if ($menuitem->[0] ne '') {
  268:                 $link = $menuitem->[0];
  269:                 $target = '_top';
  270:             } else {
  271:                 $link = '#';
  272:             }
  273:             my @primsub;
  274:             if (ref($primary_submenu{$title}) eq 'ARRAY') {
  275:                 foreach my $item (@{$primary_submenu{$title}}) {
  276:                     next if (($item->[2] eq 'wishlist') && (!$env{'user.adv'})); 
  277:                     next if ((($item->[2] eq 'portfolio') || 
  278:                              ($item->[2] eq 'blog')) && 
  279:                              (!&Apache::lonnet::usertools_access('','',$item->[2],
  280:                                                            undef,'tools')));
  281:                     push(@primsub,$item);
  282:                 }
  283:                 if (@primsub > 0) {
  284:                     $menu{$position} .= &create_submenu($link,$target,$title,\@primsub,1);
  285:                 } elsif ($link) {
  286:                     $menu{$position} .= '<li><a href="'.$link.'" target="'.$target.'">'.&mt($title).'</a></li>';
  287:                 }
  288:             }
  289:         } elsif ($$menuitem[3] eq 'Help') { # special treatment for helplink
  290:             if ($public) {
  291:                 my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
  292:                 my $defdom = &Apache::lonnet::default_login_domain();
  293:                 my $to = &Apache::loncommon::build_recipient_list(undef,
  294:                                                                   'helpdeskmail',
  295:                                                                   $defdom,$origmail);
  296:                 if ($to ne '') {
  297:                     $menu{$position} .= &prep_menuitem($menuitem); 
  298:                 }
  299:             } else {
  300:                 $menu{$position} .= '<li>'.&Apache::loncommon::top_nav_help('Help').'</li>';
  301:             }
  302:         } else {
  303:             $menu{$position} .= prep_menuitem($menuitem);
  304:         }
  305:     }
  306:     my @output = ('','');
  307:     if ($menu{'left'} ne '') {
  308:         $output[0] = "<ol class=\"LC_primary_menu LC_floatleft\">$menu{'left'}</ol>";
  309:     }
  310:     if ($menu{'right'} ne '') {
  311:         $output[1] = "<ol class=\"LC_primary_menu LC_floatright LC_right\">$menu{'right'}</ol>";
  312:     }
  313:     return @output;
  314: }
  315: 
  316: #returns hashref {user=>'',dom=>''} containing:
  317: #   own name, domain if user is au
  318: #   name, domain of parent author if user is ca or aa
  319: #empty return if user is not an author or not on homeserver
  320: #
  321: #TODO this should probably be moved somewhere more central
  322: #since it can be used by different parts of the system
  323: sub getauthor{
  324:     return unless $env{'request.role'}=~/^(ca|aa|au)/; #nothing to do if user isn't some kind of author
  325: 
  326:                         #co- or assistent author?
  327:     my ($dom, $user) = ($env{'request.role'} =~ /^(?:ca|aa)\.\/($match_domain)\/($match_username)$/)
  328:                        ? ($1, $2) #domain, username of the parent author
  329:                        : @env{ ('request.role.domain', 'user.name') }; #own domain, username
  330: 
  331:     # current server == home server?
  332:     my $home =  &Apache::lonnet::homeserver($user,$dom);
  333:     foreach (&Apache::lonnet::current_machine_ids()){
  334:         return {user => $user, dom => $dom} if $_ eq $home;
  335:     }
  336: 
  337:     # if wrong server
  338:     return;
  339: }
  340: 
  341: sub secondary_menu {
  342:     my ($httphost) = @_;
  343:     my $menu;
  344: 
  345:     my $crstype = &Apache::loncommon::course_type();
  346:     my $crs_sec = $env{'request.course.id'} . ($env{'request.course.sec'} 
  347:                                                ? "/$env{'request.course.sec'}"
  348:                                                : '');
  349:     my $canedit       = &Apache::lonnet::allowed('mdc', $env{'request.course.id'});
  350:     my $canviewroster = $env{'course.'.$env{'request.course.id'}.'.student_classlist_view'};
  351:     if ($canviewroster eq 'disabled') {
  352:         undef($canviewroster);
  353:     }
  354:     my $canviewgrps   = &Apache::lonnet::allowed('vcg', $crs_sec);
  355:     my $canmodifyuser = &Apache::lonnet::allowed('cst', $crs_sec);
  356:     my $canviewwnew   = &Apache::lonnet::allowed('whn', $crs_sec);
  357:     my $canmodpara    = &Apache::lonnet::allowed('opa', $crs_sec);
  358:     my $canvgr        = &Apache::lonnet::allowed('vgr', $crs_sec);
  359:     my $canmgr        = &Apache::lonnet::allowed('mgr', $crs_sec);
  360:     my $author        = &getauthor();
  361: 
  362:     my ($cdom,$cnum,$showsyllabus,$showfeeds,$showresv);
  363:     if ($env{'request.course.id'}) {
  364:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  365:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
  366:         unless ($canedit) {
  367:             unless (&Apache::lonnet::is_on_map("public/$cdom/$cnum/syllabus")) {
  368:                 if (($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'}) ||
  369:                     ($env{'course.'.$env{'request.course.id'}.'.uploadedsyllabus'}) ||
  370:                     ($env{'course.'.$env{'request.course.id'}.'.updatedsyllabus'}) ||
  371:                     ($env{'request.course.syllabustime'})) {
  372:                     $showsyllabus = 1;
  373:                 }
  374:             }
  375:             if ($env{'request.course.feeds'}) {
  376:                 $showfeeds = 1;
  377:             }
  378:         }
  379:         unless ($canmgr) {
  380:             my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
  381:             if (keys(%slots) > 0) {
  382:                 $showresv = 1;
  383:             }
  384:         }
  385:     }
  386: 
  387:     my ($canmodifycoauthor);
  388:     if ($env{'request.role'} eq "au./$env{'user.domain'}/") {
  389:         my $extent = "$env{'user.domain'}/$env{'user.name'}";
  390:         if ((&Apache::lonnet::allowed('cca',$extent)) ||
  391:             (&Apache::lonnet::allowed('caa',$extent))) {
  392:             $canmodifycoauthor = 1;
  393:         }
  394:     }
  395: 
  396:     my %groups = &Apache::lonnet::get_active_groups(
  397:                      $env{'user.domain'}, $env{'user.name'},
  398:                      $env{'course.' . $env{'request.course.id'} . '.domain'},
  399:                      $env{'course.' . $env{'request.course.id'} . '.num'});
  400: 
  401:     my ($roleswitcher_js,$roleswitcher_form);
  402: 
  403:     foreach my $menuitem (@secondary_menu) {
  404:         # evaluate conditions 
  405:         next if    ref($menuitem)  ne 'ARRAY';
  406:         next if    $$menuitem[4]   ne 'always'
  407:                 && ($$menuitem[4]  ne 'author' && $$menuitem[4] ne 'cca')
  408:                 && !$env{'request.course.id'};
  409:         next if    $$menuitem[4]   =~ /^mdc/
  410:                 && !$canedit;
  411:         next if    $$menuitem[4]  eq 'mdcCourse'
  412:                 && ($crstype eq 'Community');
  413:         next if    $$menuitem[4]  eq 'mdcCommunity'
  414:                 && ($crstype eq 'Course');
  415:         next if    $$menuitem[4]  eq 'nvgr'
  416:                 && $canvgr;
  417:         next if    $$menuitem[4]  eq 'vgr'
  418:                 && !$canvgr;
  419:         next if    $$menuitem[4]   eq 'cst'
  420:                 && !$canmodifyuser;
  421:         next if    $$menuitem[4]   eq 'ncst'
  422:                 && ($canmodifyuser || !$canviewroster);
  423:         next if    $$menuitem[4]   eq 'mgr'
  424:                 && !$canmgr;
  425:         next if    $$menuitem[4]   eq 'showresv'
  426:                 && !$showresv;
  427:         next if    $$menuitem[4]   eq 'whn'
  428:                 && !$canviewwnew;
  429:         next if    $$menuitem[4]   eq 'opa'
  430:                 && !$canmodpara;
  431:         next if    $$menuitem[4]   eq 'nvcg'
  432:                 && ($canviewgrps || !%groups);
  433:         next if    $$menuitem[4]   eq 'showsyllabus'
  434:                 && !$showsyllabus;
  435:         next if    $$menuitem[4]   eq 'showfeeds'
  436:                 && !$showfeeds;
  437:         next if    $$menuitem[4]    eq 'author'
  438:                 && !$author;
  439:         next if    $$menuitem[4]    eq 'cca'
  440:                 && !$canmodifycoauthor;
  441: 
  442:         my $title = $menuitem->[3];
  443:         if (defined($secondary_submenu{$title})) {
  444:             my ($link,$target);
  445:             if ($menuitem->[0] ne '') {
  446:                 $link = $menuitem->[0];
  447:                 $target = '_top';
  448:             } else {
  449:                 $link = '#';
  450:             }
  451:             my @scndsub;
  452:             if (ref($secondary_submenu{$title}) eq 'ARRAY') {
  453:                 foreach my $item (@{$secondary_submenu{$title}}) {
  454:                     if (ref($item) eq 'ARRAY') {
  455:                         next if ($item->[2] eq 'vgr' && !$canvgr);
  456:                         next if ($item->[2] eq 'opa' && !$canmodpara);
  457:                         next if ($item->[2] eq 'cst' && !$canmodifyuser);
  458:                         next if ($item->[2] eq 'mgr' && !$canmgr);
  459:                         next if ($item->[2] eq 'vcg' && !$canviewgrps);
  460:                         next if ($item->[2] eq 'mdc' && !$canedit);
  461:                         push(@scndsub,$item); 
  462:                     }
  463:                 }
  464:                 if (@scndsub > 0) {
  465:                     $menu .= &create_submenu($link,$target,$title,\@scndsub,1);
  466:                 } elsif ($link ne '#') {
  467:                     $menu .= '<li><a href="'.$link.'" target="'.$target.'">'.&mt($title).'</a></li>';
  468:                 }
  469:             }
  470:         } elsif ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) {
  471:             # special treatment for role selector
  472:             ($roleswitcher_js,$roleswitcher_form,my $switcher) =
  473:                 &roles_selector(
  474:                         $env{'course.' . $env{'request.course.id'} . '.domain'},
  475:                         $env{'course.' . $env{'request.course.id'} . '.num'},
  476:                         $httphost
  477:                 );
  478:             $menu .= $switcher;
  479:         } else {
  480:             if ($$menuitem[3] eq 'Syllabus' && $env{'request.course.id'}) {
  481:                 my $url = $$menuitem[0];
  482:                 $url =~ s{\[cdom\]/\[cnum\]}{$cdom/$cnum};
  483:                 if (&Apache::lonnet::is_on_map($url)) {
  484:                     unless ($$menuitem[0] =~ /\?register=1/) {
  485:                         $$menuitem[0] .= '?register=1';
  486:                     }
  487:                 } else {
  488:                     $$menuitem[0] =~ s{\?register=1}{};
  489:                 }
  490:             }
  491:             $menu .= &prep_menuitem(\@$menuitem);
  492:         }
  493:     }
  494:     if ($menu =~ /\[url\].*\[symb\]/) {
  495:         my $escurl  = &escape( &Apache::lonenc::check_encrypt(
  496:                              $env{'request.noversionuri'}));
  497: 
  498:         my $escsymb = &escape( &Apache::lonenc::check_encrypt(
  499:                              $env{'request.symb'})); 
  500: 
  501:         if (    $env{'request.state'} eq 'construct'
  502:             and (   $env{'request.noversionuri'} eq '' 
  503:                  || !defined($env{'request.noversionuri'}))) 
  504:         {
  505:             my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
  506:             ($escurl = $env{'request.filename'}) =~ s{^\Q$londocroot\E}{};
  507:             $escurl  = &escape($escurl);
  508:         }    
  509:         $menu =~ s/\[url\]/$escurl/g;
  510:         $menu =~ s/\[symb\]/$escsymb/g;
  511:     }
  512:     $menu =~ s/\[uname\]/$$author{user}/g;
  513:     $menu =~ s/\[udom\]/$$author{dom}/g;
  514:     if ($env{'request.course.id'}) {  
  515:         $menu =~ s/\[cnum\]/$cnum/g;
  516:         $menu =~ s/\[cdom\]/$cdom/g;
  517:     }
  518:     if ($menu) {
  519:         $menu = "<ul id=\"LC_secondary_menu\">$menu</ul>";
  520:     }
  521:     if ($roleswitcher_form) {
  522:         $menu .= "\n$roleswitcher_js\n$roleswitcher_form";
  523:     }
  524:     return $menu;
  525: }
  526: 
  527: sub create_submenu {
  528:     my ($link,$target,$title,$submenu,$translate) = @_;
  529:     return unless (ref($submenu) eq 'ARRAY');
  530:     my $disptarget;
  531:     if ($target ne '') {
  532:         $disptarget = ' target="'.$target.'"';
  533:     }
  534:     my $name;
  535:     if ($title eq 'Personal') {
  536:         if ($env{'user.name'} && $env{'user.domain'}) {
  537:             $name = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'});
  538:         } else {
  539:             $name = &mt($title);
  540:         }
  541:     } else {
  542:         $name = &mt($title);
  543:     }
  544:     my $menu = '<li class="LC_hoverable">'.
  545:                '<a href="'.$link.'"'.$disptarget.'>'.
  546:                '<span class="LC_nobreak">'.$name.
  547:                '<span class="LC_fontsize_small" style="font-weight:normal;">'.
  548:                ' &#9660;</span></span></a>'.
  549:                '<ul>';
  550:     my $count = 0;
  551:     my $numsub = scalar(@{$submenu});
  552:     foreach my $item (@{$submenu}) {
  553:         $count ++;
  554:         if (ref($item) eq 'ARRAY') {
  555:             my $href = $item->[0];
  556:             if ($href =~ /(aboutme|rss\.html)$/) {
  557:                 next unless (($env{'user.name'} ne '') && ($env{'user.domain'} ne ''));
  558:                 $href =~ s/\[domain\]/$env{'user.domain'}/g;
  559:                 $href =~ s/\[user\]/$env{'user.name'}/g;
  560:             }
  561:             my $borderbot;
  562:             if ($count == $numsub) {
  563:                 $borderbot = 'border-bottom:1px solid black;';
  564:             }
  565:             unless (($href eq '') || ($href =~ /^\#/)) {
  566:                 $target = ' target="_top"';
  567:             }
  568:             $menu .= '<li style="margin:0;padding:0;'.
  569:                      $borderbot.'"><a href="'.$href.'"'.$target.'>';
  570:             if ($translate) {
  571:                 $menu .= &mt($item->[1]);
  572:             } else {
  573:                 $menu .= $item->[1];
  574:             }
  575:             $menu .= '</a></li>';
  576:         }
  577:     }
  578:     $menu .= '</ul></li>';
  579:     return $menu;
  580: }
  581: 
  582: sub registerurl {
  583:     my ($forcereg) = @_;
  584:     my $result = '';
  585:     if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
  586:     my $force_title='';
  587:     if ($env{'request.state'} eq 'construct') {
  588:         $force_title=&Apache::lonxml::display_title();
  589:     }
  590:     if (($env{'environment.remote'} ne 'on') ||
  591:         ((($env{'request.publicaccess'}) ||
  592:          (!&Apache::lonnet::is_on_map(
  593:            &unescape($env{'request.noversionuri'})))) &&
  594:         (!$forcereg))) {
  595:         return
  596:         $result
  597:        .'<script type="text/javascript">'."\n"
  598:        .'// <![CDATA['."\n"
  599:        .'function LONCAPAreg(){;} function LONCAPAstale(){}'."\n"
  600:        .'// ]]>'."\n"
  601:        .'</script>'
  602:        .$force_title;
  603:     }
  604: # Graphical display after login only
  605:     if ($env{'request.registered'} && !$forcereg) { return ''; }
  606:     $result.=&innerregister($forcereg);
  607:     return $result.$force_title;
  608: }
  609: 
  610: sub innerregister {
  611:     my ($forcereg,$bread_crumbs,$group) = @_;
  612:     my $const_space = ($env{'request.state'} eq 'construct');
  613:     my $is_const_dir = 0;
  614: 
  615:     if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
  616: 
  617:     $env{'request.registered'} = 1;
  618: 
  619:     my $noremote = ($env{'environment.remote'} ne 'on');
  620: 
  621:     undef(@inlineremote);
  622: 
  623:     my $reopen=&Apache::lonmenu::reopenmenu();
  624: 
  625:     my $newmail='';
  626: 
  627:     if (&Apache::lonmsg::newmail() && !$noremote) {
  628:         # We have new mail and remote is up
  629:         $newmail= 'swmenu.setstatus("you have","messages");';
  630:     }
  631: 
  632:     my ($mapurl,$resurl);
  633: 
  634:     if ($env{'request.course.id'}) {
  635:         if ($env{'request.symb'}) {
  636:             ($mapurl, my $rid, $resurl) = &Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
  637:             my $coursetitle = $env{'course.'.$env{'request.course.id'}.'.description'};
  638: 
  639:             my $maptitle = &Apache::lonnet::gettitle($mapurl);
  640:             my $restitle = &Apache::lonnet::gettitle(&Apache::lonnet::symbread());
  641: 
  642: 
  643: #SD
  644: #course_type only Course and Community?
  645: #
  646:             my @crumbs;
  647:             unless (($forcereg) && 
  648:                     ($env{'request.noversionuri'} eq '/adm/navmaps') &&
  649:                     ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'})) {
  650:                 @crumbs = ({text  => Apache::loncommon::course_type() 
  651:                                     . ' Contents', 
  652:                             href  => "Javascript:gopost('/adm/navmaps','')"});
  653:             }
  654:             if ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) { 
  655:                 push(@crumbs, {text  => '...',
  656:                                no_mt => 1});
  657:             }
  658: 
  659:             push @crumbs, {text => $maptitle, no_mt => 1} if ($maptitle 
  660:                                                        && $maptitle ne 'default.sequence' 
  661:                                                        && $maptitle ne $coursetitle);
  662: 
  663:             push @crumbs, {text => $restitle, no_mt => 1} if $restitle;
  664:             my @tools;
  665:             if ($env{'request.filename'} =~ /\.page$/) {
  666:                 my %breadcrumb_tools = &Apache::lonhtmlcommon::current_breadcrumb_tools();
  667:                 if (ref($breadcrumb_tools{'tools'}) eq 'ARRAY') {
  668:                     @tools = @{$breadcrumb_tools{'tools'}};
  669:                 }
  670:             }
  671:             &Apache::lonhtmlcommon::clear_breadcrumbs();
  672:             &Apache::lonhtmlcommon::add_breadcrumb(@crumbs);
  673:             if (@tools) {
  674:                 &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',@tools);
  675:             }
  676:         } else {
  677:             $resurl = $env{'request.noversionuri'};
  678:             my $courseurl = &Apache::lonnet::courseid_to_courseurl($env{'request.course.id'});
  679:             my $crstype = &Apache::loncommon::course_type();
  680:             my $title = &mt('View Resource');
  681:             if ($resurl =~ m{^\Q/uploaded$courseurl/supplemental/\E(default|\d+)/}) {
  682:                 &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folderpath','title']);
  683:                 &Apache::lonhtmlcommon::clear_breadcrumbs();
  684:                 if ($env{'form.title'}) {
  685:                     $title = $env{'form.title'};
  686:                 }
  687:                 my $trail;
  688:                 if ($env{'form.folderpath'}) {
  689:                     &prepare_functions($resurl,$forcereg,$group,undef,undef,1);
  690:                     ($trail) =
  691:                         &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
  692:                 } else {
  693:                     &Apache::lonhtmlcommon::add_breadcrumb(
  694:                     {text  => "Supplemental $crstype Content",
  695:                      href  => "javascript:gopost('/adm/supplemental','')"});
  696:                     $title = &mt('View Resource');
  697:                     ($trail) =
  698:                         &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
  699:                 }
  700:                 return $trail;
  701:             } elsif ($resurl =~ m{^\Q/uploaded$courseurl/portfolio/syllabus/}) {
  702:                 &Apache::lonhtmlcommon::clear_breadcrumbs();
  703:                 &prepare_functions('/public'.$courseurl."/syllabus",
  704:                                    $forcereg,$group,undef,undef,1);
  705:                 $title = &mt('Syllabus File');
  706:                 my ($trail) =
  707:                     &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
  708:                 return $trail;
  709:             }
  710:             unless ($env{'request.state'} eq 'construct') {
  711:                 &Apache::lonhtmlcommon::clear_breadcrumbs();
  712:                 &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
  713:             }
  714:         }
  715:     } elsif (! $const_space){
  716:         #a situation when we're looking at a resource outside of context of a 
  717:         #course or construction space (e.g. with cumulative rights)
  718:         &Apache::lonhtmlcommon::clear_breadcrumbs();
  719:         unless ($env{'request.noversionuri'} =~ m{^/adm/$match_domain/$match_username/aboutme$}) {
  720:             &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
  721:         }
  722:     }
  723:     my $timesync   = ( $noremote ? '' : 'swmenu.syncclock(1000*'.time.');' );
  724: # =============================================================================
  725: # ============================ This is for URLs that actually can be registered
  726:     if ( ($env{'request.noversionuri'}!~m{^/(res/)*adm/})
  727:                        || ($forcereg)) {
  728: 
  729:         my %swtext;
  730:         if ($noremote) {
  731:             %swtext = &get_inline_text();
  732:         } else {
  733:             %swtext = &get_rc_text();
  734:         }
  735:         my $hwkadd='';
  736: 
  737:         my ($cdom,$cnum,%perms,$cfile,$switchserver,$home,$forceedit,
  738:             $forceview,$editbutton);
  739:         if (($resurl =~ m{^/adm/($match_domain)/($match_username)/aboutme$}) ||
  740:             ($env{'request.role'} !~/^(aa|ca|au)/)) {
  741:             if (($env{'environment.remote'} eq 'on') && ($env{'request.symb'})) {
  742:                 &Apache::lonhtmlcommon::clear_breadcrumbs();
  743:             }
  744:             $editbutton = &prepare_functions($resurl,$forcereg,$group);
  745:         }
  746:         if ($editbutton eq '') {
  747:             $editbutton = &clear(6,1);
  748:         }
  749: 
  750: #
  751: # This applies in course context
  752: #
  753:         if ($env{'request.course.id'}) {
  754:             $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
  755:             $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  756:             $perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
  757:             my @privs;
  758:             if ($env{'request.symb'} ne '') {
  759:                 if ($env{'request.filename'}=~/$LONCAPA::assess_re/) {
  760:                     push(@privs,('mgr','vgr'));
  761:                 }
  762:                 push(@privs,'opa');
  763:             }
  764:             foreach my $priv (@privs) {
  765:                 $perms{$priv} = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
  766:                 if (!$perms{$priv} && $env{'request.course.sec'} ne '') {
  767:                     $perms{$priv} =
  768:                         &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
  769:                 }
  770:             }
  771: #
  772: # Determine whether or not to show Grades and Submissions buttons
  773: #
  774:             if ($env{'request.symb'} ne '' &&
  775:                 $env{'request.filename'}=~/$LONCAPA::assess_re/) {
  776:                 if ($perms{'mgr'}) {
  777:                     $hwkadd.= &switch('','',7,2,'pgrd.png','Content Grades',
  778:                                       'grades[_4]',
  779:                                       "gocmd('/adm/grades','gradingmenu')",
  780:                                       'Content Grades');
  781:                 } elsif ($perms{'vgr'}) {
  782:                     $hwkadd .= &switch('','',7,2,'subm.png','Content Submissions',
  783:                                        'missions[_1]',
  784:                                        "gocmd('/adm/grades','submission')",
  785:                                        'Content Submissions');
  786:                 }
  787:             }
  788:             if (($env{'request.symb'} ne '') && ($perms{'opa'})) {
  789:                 $hwkadd .= &switch('','',7,3,'pparm.png','Content Settings',
  790:                                    'parms[_2]',"gocmd('/adm/parmset','set')",
  791:                                    'Content Settings');
  792:             }
  793: # End grades/submissions check
  794: 
  795: #
  796: # This applies to items inside a folder/page modifiable in the course.
  797: #
  798:             if (($env{'request.symb'}=~/^uploaded/) && ($perms{'mdc'})) {
  799:                 my $text = 'Edit Folder';
  800:                 if (($mapurl =~ /\.page$/) ||
  801:                     ($env{'request.symb'}=~
  802:                          m{uploaded/$cdom/$cnum/default_\d+\.page$}))  {
  803:                     $text = 'Edit Page';
  804:                 }
  805:                 $hwkadd .= &switch('','',7,4,'docs-22x22.png',$text,'parms[_2]',
  806:                                    "gocmd('/adm/coursedocs','direct')",
  807:                                    'Folder/Page Content');
  808:             }
  809: # End modifiable folder/page container check
  810:         }
  811: # End course context
  812: 
  813: # Prepare the rest of the buttons
  814:         my ($menuitems,$got_prt,$got_wishlist,$cstritems);
  815:         if ($const_space) {
  816: #
  817: # We are in construction space
  818: #
  819: 
  820:             my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
  821: 	    my ($udom,$uname,$thisdisfn) =
  822: 		($env{'request.filename'}=~m{^\Q$londocroot/priv/\E([^/]+)/([^/]+)/(.*)$});
  823:             my $currdir = '/priv/'.$udom.'/'.$uname.'/'.$thisdisfn;
  824:             if ($currdir =~ m-/$-) {
  825:                 $is_const_dir = 1;
  826:                 if ($thisdisfn eq '') {
  827:                     $is_const_dir = 2;
  828:                 }
  829:             } else {
  830:                 $currdir =~ s|[^/]+$||;
  831: 		my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn);
  832: 		my $esc_currdir = &Apache::loncommon::escape_single($currdir);
  833: #
  834: # Probably should be in mydesk.tab
  835: #
  836:                 $menuitems=(<<ENDMENUITEMS);
  837: s&6&1&list.png&Directory&dir[_1]&golist('$esc_currdir')&List current directory
  838: s&6&2&rtrv.png&Retrieve&version[_1]&gocstr('/adm/retrieve','/priv/$udom/$uname/$cleandisfn')&Retrieve old version
  839: s&6&3&pub.png&Publish&resource[_3]&gocstr('/adm/publish','/priv/$udom/$uname/$cleandisfn')&Publish this resource
  840: s&7&1&del.png&Delete&resource[_2]&gocstr('/adm/cfile?action=delete','/priv/$udom/$uname/$cleandisfn')&Delete this resource
  841: s&7&2&prt.png&Print&printout[_1]&gocstr('/adm/printout','/priv/$udom/$uname/$cleandisfn')&Prepare a printable document
  842: ENDMENUITEMS
  843:                 unless ($noremote) {
  844:                     $cstritems = $menuitems;
  845:                     undef($menuitems);
  846:                 }
  847:             }
  848:             if (ref($bread_crumbs) eq 'ARRAY') {
  849:                 &Apache::lonhtmlcommon::clear_breadcrumbs();
  850:                 foreach my $crumb (@{$bread_crumbs}){
  851:                      &Apache::lonhtmlcommon::add_breadcrumb($crumb);
  852:                 }
  853:             }
  854:         } elsif ( defined($env{'request.course.id'}) && 
  855: 		 $env{'request.symb'} ne '' ) {
  856: #
  857: # We are in a course and looking at a registered URL
  858: # Should probably be in mydesk.tab
  859: #
  860: 
  861: 	    $menuitems=(<<ENDMENUITEMS);
  862: c&3&1
  863: s&2&1&back.png&$swtext{'back'}&&gopost('/adm/flip','back:'+currentURL)&Previous content resource&&1
  864: s&2&3&forw.png&$swtext{'forw'}&&gopost('/adm/flip','forward:'+currentURL)&Next content resource&&3
  865: c&6&3
  866: c&8&1
  867: c&8&2
  868: s&8&3&prt.png&$swtext{'prt'}&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
  869: ENDMENUITEMS
  870:             $got_prt = 1;
  871:             if (($env{'user.adv'}) && ($env{'request.uri'} =~ /^\/res/)
  872:                 && (!$env{'request.enc'})) {
  873:                 # wishlist is only available for users with access to resource-pool
  874:                 # and links can only be set for resources within the resource-pool
  875:                 $menuitems .= (<<ENDMENUITEMS);
  876: s&9&1&alnk.png&$swtext{'alnk'}&linkstor[_1]&set_wishlistlink('',currentURL)&Save a link for this resource in my personal Stored Links repository&&1
  877: ENDMENUITEMS
  878:                 $got_wishlist = 1;
  879:             }
  880: 
  881: my $currentURL = &Apache::loncommon::get_symb();
  882: my ($symb_old,$symb_old_enc) = &Apache::loncommon::clean_symb($currentURL);
  883: my $annotation = &Apache::loncommon::get_annotation($symb_old,$symb_old_enc);
  884: $menuitems.="s&9&3&";
  885: if(length($annotation) > 0){
  886: 	$menuitems.="anot2.png";
  887: }else{
  888: 	$menuitems.="anot.png";
  889: }
  890: $menuitems.="&$swtext{'anot'}&tations[_1]&annotate()&";
  891: $menuitems.="Make notes and annotations about this resource&&1\n";
  892: my $is_mobile;
  893: if ($env{'browser.mobile'}) {
  894:     $is_mobile = 1;
  895: }
  896: 
  897:             unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|viewclasslist|portfolio)(\?|$)/) {
  898: 		if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/}) && ($env{'request.noversionuri'} !~ m{^/uploaded/$match_domain/$match_courseid/docs/})) {
  899: 		    $menuitems.=(<<ENDREALRES);
  900: s&6&3&catalog.png&$swtext{'catalog'}&info[_1]&catalog_info('$is_mobile')&Show Metadata
  901: ENDREALRES
  902:                 }
  903:                 unless (($env{'request.noversionuri'} =~ m{^/uploaded/$match_domain/$match_courseid/docs/}) ||
  904:                         ($env{'request.noversionuri'} =~ m{^\Q/adm/wrapper/\E(ext|uploaded)/})) { 
  905: 	            $menuitems.=(<<ENDREALRES);
  906: s&8&1&eval.png&$swtext{'eval'}&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
  907: ENDREALRES
  908:                 }
  909:                 unless ($env{'request.noversionuri'} =~ m{^\Q/adm/wrapper/\E(ext|uploaded)/}) {
  910:                     $menuitems.=(<<ENDREALRES);
  911: s&8&2&fdbk.png&$swtext{'fdbk'}&discuss[_1]&gopost('/adm/feedback',currentURL,1)&Provide feedback messages or contribute to the course discussion about this resource
  912: ENDREALRES
  913:                 }
  914: 	    }
  915:         }
  916: 	if ($env{'request.uri'} =~ /^\/res/) {
  917:             unless ($got_prt) {
  918: 	        $menuitems .= (<<ENDMENUITEMS);
  919: s&8&3&prt.png&$swtext{'prt'}&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
  920: ENDMENUITEMS
  921:                 $got_prt = 1;
  922:             }
  923:             unless ($got_wishlist) {
  924:                 if (($env{'user.adv'}) && (!$env{'request.enc'})) {
  925:                     # wishlist is only available for users with access to resource-pool
  926:                     $menuitems .= (<<ENDMENUITEMS);
  927: s&9&1&alnk.png&$swtext{'alnk'}&linkstor[_1]&set_wishlistlink('',currentURL)&Save a link for this resource in your personal Stored Links repository&&1
  928: ENDMENUITEMS
  929:                     $got_wishlist = 1;
  930:                 }
  931:             }
  932: 	}
  933:         unless ($got_prt) {
  934:             $menuitems .= (<<ENDMENUITEMS);
  935: c&8&3
  936: ENDMENUITEMS
  937:         }
  938:         unless ($got_wishlist) {
  939:             $menuitems .= (<<ENDMENUITEMS);
  940: c&9&1
  941: ENDMENUITEMS
  942:         }
  943:         my $buttons='';
  944:         foreach (split(/\n/,$menuitems)) {
  945: 	    my ($command,@rest)=split(/\&/,$_);
  946:             my $idx=10*$rest[0]+$rest[1];
  947:             if (&hidden_button_check() eq 'yes') {
  948:                 if ($idx == 21 ||$idx == 23) {
  949:                     $buttons.=&switch('','',@rest);
  950:                 } else {
  951:                     $buttons.=&clear(@rest);
  952:                 }
  953:             } else {  
  954:                 if ($command eq 's') {
  955: 	            $buttons.=&switch('','',@rest);
  956:                 } else {
  957:                     $buttons.=&clear(@rest);
  958:                 }
  959:             }
  960:         }
  961:         if ($noremote) {
  962: 	    my $addremote=0;
  963: 	    foreach (@inlineremote) { if ($_ ne '') { $addremote=1; last;} }
  964:             if ($addremote) {
  965: 
  966:                 &Apache::lonhtmlcommon::clear_breadcrumb_tools();
  967: 
  968:                 &Apache::lonhtmlcommon::add_breadcrumb_tool(
  969:                     'navigation', @inlineremote[21,23]);
  970: 
  971:                 my $countdown;
  972:                 if ($env{'request.filename'} =~ /\.page$/) {
  973:                     my %breadcrumb_tools = &Apache::lonhtmlcommon::current_breadcrumb_tools();
  974:                     if (ref($breadcrumb_tools{'tools'}) eq 'ARRAY') {
  975:                         $countdown = $breadcrumb_tools{'tools'}[0];
  976:                     }
  977:                 } else {
  978:                     $countdown = &countdown_timer();
  979:                 }
  980:                 if (&hidden_button_check() eq 'yes') {
  981:                     if ($countdown) {
  982:                         &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$countdown);
  983:                     }
  984:                 } else {
  985:                     my @tools = @inlineremote[93,91,81,82,83];
  986:                     if ($countdown) {
  987:                         unshift(@tools,$countdown);
  988:                     }
  989:                     &Apache::lonhtmlcommon::add_breadcrumb_tool(
  990:                         'tools',@tools);
  991: 
  992:                     #publish button in construction space
  993:                     if ($env{'request.state'} eq 'construct'){
  994:                         &Apache::lonhtmlcommon::add_breadcrumb_tool(
  995:                             'advtools', $inlineremote[63]);
  996:                     } else {
  997:                         &Apache::lonhtmlcommon::add_breadcrumb_tool(
  998:                             'tools', $inlineremote[63]);
  999:                     }
 1000:                     &advtools_crumbs(@inlineremote);
 1001:                 }
 1002:             }
 1003:             my ($topic_help,$topic_help_text);
 1004:             if ($is_const_dir == 2) {
 1005:                 if ((($ENV{'SERVER_PORT'} == 443) ||
 1006:                      ($Apache::lonnet::protocol{$Apache::lonnet::perlvar{'lonHostID'}} eq 'https')) &&
 1007:                      (&Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},'webdav'))) {
 1008:                     $topic_help = 'Authoring_WebDAV,Authoring_WebDAV_Mac_10v6,Authoring_WebDAV_Mac_10v10,'.
 1009:                                  'Authoring_WebDAV_Windows_v7,Authoring_WebDAV_Linux_Centos';
 1010:                     $topic_help_text = 'About WebDAV access';
 1011:                 }
 1012:             }
 1013:             return   &Apache::lonhtmlcommon::scripttag('', 'start')
 1014:                    . &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0,'','','','',$topic_help,$topic_help_text)
 1015:                    . &Apache::lonhtmlcommon::scripttag('', 'end');
 1016: 
 1017:         } else {
 1018:             my $cstrcrumbs;
 1019:             if ($const_space) {
 1020:                 foreach (split(/\n/,$cstritems)) {
 1021:                     my ($command,@rest)=split(/\&/,$_);
 1022:                     my $idx=10*$rest[0]+$rest[1];
 1023:                     &switch('','',@rest);
 1024:                 }
 1025:                 &Apache::lonhtmlcommon::add_breadcrumb_tool('advtools',
 1026:                                                             @inlineremote[63,61,71,72]);
 1027: 
 1028:                 $cstrcrumbs = &Apache::lonhtmlcommon::scripttag('', 'start')
 1029:                              .&Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
 1030:                              .&Apache::lonhtmlcommon::scripttag('', 'end');
 1031:             }
 1032:             my $requri=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
 1033:             $requri=&Apache::lonenc::check_encrypt(&unescape($requri));
 1034:             my $cursymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
 1035:             my $navstatus=&get_nav_status();
 1036:             my $clearcstr;
 1037: 
 1038:             if ($env{'user.adv'}) { $clearcstr='clearbut(6,1)'; }
 1039:             return <<ENDREGTHIS;
 1040: 
 1041: <script type="text/javascript">
 1042: // <![CDATA[
 1043: // BEGIN LON-CAPA Internal
 1044: var swmenu=null;
 1045: 
 1046:     function LONCAPAreg() {
 1047:           swmenu=$reopen;
 1048:           swmenu.clearTimeout(swmenu.menucltim);
 1049:           $timesync
 1050:           $newmail
 1051:           $buttons
 1052:           swmenu.currentURL="$requri";
 1053:           swmenu.reloadURL=swmenu.currentURL+window.location.search;
 1054:           swmenu.currentSymb="$cursymb";
 1055:           swmenu.reloadSymb="$cursymb";
 1056:           swmenu.currentStale=0;
 1057:           $navstatus
 1058:           $hwkadd
 1059:           $editbutton
 1060:     }
 1061: 
 1062:     function LONCAPAstale() {
 1063:           swmenu=$reopen
 1064:           swmenu.currentStale=1;
 1065:           if (swmenu.reloadURL!='' && swmenu.reloadURL!= null) {
 1066:              swmenu.switchbutton
 1067:              (3,1,'reload.gif','return','location','go(reloadURL)','Return to the last known location in the course sequence');
 1068:           }
 1069:           swmenu.clearbut(7,2);
 1070:           swmenu.clearbut(7,3);
 1071:           swmenu.menucltim=swmenu.setTimeout(
 1072:  'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+
 1073:  'clearbut(9,1);clearbut(9,3);clearbut(6,3);$clearcstr',
 1074:                           2000);
 1075:       }
 1076: 
 1077: // END LON-CAPA Internal
 1078: // ]]>
 1079: </script>
 1080: 
 1081: $cstrcrumbs
 1082: ENDREGTHIS
 1083:         }
 1084:     } else {
 1085:        unless ($noremote) {
 1086: # Not registered, graphical
 1087:            return (<<ENDDONOTREGTHIS);
 1088: 
 1089: <script type="text/javascript">
 1090: // <![CDATA[
 1091: // BEGIN LON-CAPA Internal
 1092: var swmenu=null;
 1093: 
 1094:     function LONCAPAreg() {
 1095:           swmenu=$reopen
 1096:           $timesync
 1097:           swmenu.currentStale=1;
 1098:           swmenu.clearbut(2,1);
 1099:           swmenu.clearbut(2,3);
 1100:           swmenu.clearbut(8,1);
 1101:           swmenu.clearbut(8,2);
 1102:           swmenu.clearbut(8,3);
 1103:           swmenu.clearbut(9,1);
 1104:           if (swmenu.currentURL) {
 1105:              swmenu.switchbutton
 1106:               (3,1,'reload.gif','return','location','go(currentURL)');
 1107:           } else {
 1108:               swmenu.clearbut(3,1);
 1109:           }
 1110:     }
 1111: 
 1112:     function LONCAPAstale() {
 1113:     }
 1114: 
 1115: // END LON-CAPA Internal
 1116: // ]]>
 1117: </script>
 1118: ENDDONOTREGTHIS
 1119: 
 1120:         }
 1121:         return '';
 1122:     }
 1123: }
 1124: 
 1125: sub get_inline_text {
 1126:     my %text = (
 1127:                  pgrd     => 'Content Grades',
 1128:                  subm     => 'Content Submissions',
 1129:                  pparm    => 'Content Settings',
 1130:                  docs     => 'Folder/Page Content',
 1131:                  pcstr    => 'Edit',
 1132:                  prt      => 'Print',
 1133:                  alnk     => 'Stored Links',
 1134:                  anot     => 'Notes',
 1135:                  catalog  => 'Info',
 1136:                  eval     => 'Evaluate',
 1137:                  fdbk     => 'Feedback',
 1138:     );
 1139:     return %text;
 1140: }
 1141: 
 1142: sub get_rc_text {
 1143:     my %text = (
 1144:                    pgrd    => 'problem[_1]',
 1145:                    subm    => 'view sub-[_1]',
 1146:                    pparm   => 'problem[_2]',
 1147:                    pcstr   => 'edit[_1]',
 1148:                    prt     => 'prepare[_1]',
 1149:                    back    => 'backward[_1]',
 1150:                    forw    => 'forward[_1]',
 1151:                    alnk    => 'add to[_1]',
 1152:                    anot    => 'anno-[_1]',
 1153:                    catalog => 'catalog[_2]',
 1154:                    eval    => 'evaluate[_1]',
 1155:                    fdbk    => 'feedback[_1]',
 1156:     );
 1157:     return %text;
 1158: }
 1159: 
 1160: sub loadevents() {
 1161:     if ($env{'request.state'} eq 'construct' ||
 1162:         $env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
 1163:     return 'LONCAPAreg();';
 1164: }
 1165: 
 1166: sub unloadevents() {
 1167:     if ($env{'request.state'} eq 'construct' ||
 1168:         $env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
 1169:     return 'LONCAPAstale();';
 1170: }
 1171: 
 1172: sub startupremote {
 1173:     my ($lowerurl)=@_;
 1174:     unless ($env{'environment.remote'} eq 'on') {
 1175:         return ('<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.$lowerurl.'" />');
 1176:     }
 1177: #
 1178: # The Remote actually gets launched!
 1179: #
 1180:     my $configmenu=&rawconfig();
 1181:     my $esclowerurl=&escape($lowerurl);
 1182:     my $message=&mt('"Waiting for Remote Control window to load: "+[_1]','waited');
 1183:     return(<<ENDREMOTESTARTUP);
 1184: <script type="text/javascript">
 1185: // <![CDATA[
 1186: var timestart;
 1187: function wheelswitch() {
 1188:     if (typeof(document.wheel) != 'undefined') {
 1189:         if (typeof(document.wheel.spin) != 'undefined') {
 1190:             var date=new Date();
 1191:             var waited=Math.round(30-((date.getTime()-timestart)/1000));
 1192:             document.wheel.spin.value=$message;
 1193:         }
 1194:     }
 1195:    if (window.status=='|') {
 1196:       window.status='/';
 1197:    } else {
 1198:       if (window.status=='/') {
 1199:          window.status='-';
 1200:       } else {
 1201:          if (window.status=='-') {
 1202:             window.status='\\\\';
 1203:          } else {
 1204:             if (window.status=='\\\\') { window.status='|'; }
 1205:          }
 1206:       }
 1207:    }
 1208: }
 1209: 
 1210: // ---------------------------------------------------------- The wait function
 1211: var canceltim;
 1212: function wait() {
 1213:    if ((menuloaded==1) || (tim==1)) {
 1214:       window.status='Done.';
 1215:       if (tim==0) {
 1216:          clearTimeout(canceltim);
 1217:          $configmenu
 1218:          window.location='$lowerurl';
 1219:       } else {
 1220:           window.location='/adm/remote?action=collapse&url=$esclowerurl';
 1221:       }
 1222:    } else {
 1223:       wheelswitch();
 1224:       setTimeout('wait();',200);
 1225:    }
 1226: }
 1227: 
 1228: function main() {
 1229:    canceltim=setTimeout('tim=1;',30000);
 1230:    window.status='-';
 1231:    var date=new Date();
 1232:    timestart=date.getTime();
 1233:    wait();
 1234: }
 1235: 
 1236: // ]]>
 1237: </script>
 1238: ENDREMOTESTARTUP
 1239: }
 1240: 
 1241: sub setflags() {
 1242:     return(<<ENDSETFLAGS);
 1243: <script type="text/javascript">
 1244: // <![CDATA[
 1245:     menuloaded=0;
 1246:     tim=0;
 1247: // ]]>
 1248: </script>
 1249: ENDSETFLAGS
 1250: }
 1251: 
 1252: sub maincall() {
 1253:     unless ($env{'environment.remote'} eq 'on') { return ''; }
 1254:     return(<<ENDMAINCALL);
 1255: <script type="text/javascript">
 1256: // <![CDATA[
 1257:     main();
 1258: // ]]>
 1259: </script>
 1260: ENDMAINCALL
 1261: }
 1262: 
 1263: sub load_remote_msg {
 1264:     my ($lowerurl)=@_;
 1265: 
 1266:     unless ($env{'environment.remote'} eq 'on') { return ''; }
 1267: 
 1268:     my $esclowerurl=&escape($lowerurl);
 1269:     my $link=&mt('[_1]Continue[_2] on in Inline Menu mode'
 1270:                 ,'<a href="/adm/remote?action=collapse&amp;url='.$esclowerurl.'">'
 1271:                 ,'</a>');
 1272:     return(<<ENDREMOTEFORM);
 1273: <p>
 1274: <form name="wheel">
 1275: <input name="spin" type="text" size="60" />
 1276: </form>
 1277: </p>
 1278: <p>$link</p>
 1279: ENDREMOTEFORM
 1280: }
 1281: 
 1282: sub get_menu_name {
 1283:     my $hostid = $Apache::lonnet::perlvar{'lonHostID'};
 1284:     $hostid =~ s/\W//g;
 1285:     return 'LCmenu'.$hostid;
 1286: }
 1287: 
 1288: 
 1289: sub reopenmenu {
 1290:    unless ($env{'environment.remote'} eq 'on') { return ''; }
 1291:    my $menuname = &get_menu_name();
 1292:    my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
 1293:    return('window.open('.$nothing.',"'.$menuname.'","",false);');
 1294: }
 1295: 
 1296: 
 1297: sub open {
 1298:     my $returnval='';
 1299:     unless ($env{'environment.remote'} eq 'on') {
 1300:         return
 1301:         '<script type="text/javascript">'."\n"
 1302:        .'// <![CDATA['."\n"
 1303:        .'self.name="loncapaclient";'."\n"
 1304:        .'// ]]>'."\n"
 1305:        .'</script>';
 1306:     }
 1307:     my $menuname = &get_menu_name();
 1308: 
 1309: #    unless (shift eq 'unix') {
 1310: # resizing does not work on linux because of virtual desktop sizes
 1311: #       $returnval.=(<<ENDRESIZE);
 1312: #if (window.screen) {
 1313: #    self.resizeTo(screen.availWidth-215,screen.availHeight-55);
 1314: #    self.moveTo(190,15);
 1315: #}
 1316: #ENDRESIZE
 1317: #    }
 1318:     $returnval=(<<ENDOPEN);
 1319: // <![CDATA[
 1320: window.status='Opening LON-CAPA Remote Control';
 1321: var menu=window.open("/res/adm/pages/menu.html?inhibitmenu=yes","$menuname",
 1322: "height=375,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5");
 1323: self.name='loncapaclient';
 1324: // ]]>
 1325: ENDOPEN
 1326:     return '<script type="text/javascript">'.$returnval.'</script>';
 1327: }
 1328: 
 1329: sub get_editbutton {
 1330:     my ($cfile,$home,$switchserver,$forceedit,$forceview,$forcereg) = @_;
 1331:     my $jscall;
 1332:     if (($forceview) && ($env{'form.todocs'})) {
 1333:         my ($folderpath,$command);
 1334:         if ($env{'request.symb'}) {
 1335:             $folderpath = &Apache::loncommon::symb_to_docspath($env{'request.symb'});
 1336:         } elsif ($env{'form.folderpath'} =~ /^supplemental/) {
 1337:             $folderpath = $env{'form.folderpath'};
 1338:             $command = '&forcesupplement=1';
 1339:         }
 1340:         $folderpath = &escape(&HTML::Entities::encode(&escape($folderpath),'<>&"'));
 1341:         $jscall = "go('/adm/coursedocs?folderpath=$folderpath$command')";
 1342:     } else {
 1343:         $jscall = &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,$switchserver,
 1344:                                                 $forceedit,$forcereg,$env{'request.symb'},
 1345:                                                 &escape($env{'form.folderpath'}),
 1346:                                                 &escape($env{'form.title'}),$env{'form.idx'},
 1347:                                                 &escape($env{'form.suppurl'},$env{'form.todocs'}));
 1348:     }
 1349:     if ($jscall) {
 1350:         my $icon = 'pcstr.png';
 1351:         my $label = 'Edit';
 1352:         if ($forceview) {
 1353:             $icon = 'tolastloc.png';
 1354:             $label = 'Exit Editing';
 1355:         }
 1356:         my $infunc = 1;
 1357:         my $clearbutton;
 1358:         if ($env{'environment.remote'} eq 'on') {
 1359:             if ($cfile =~ m{^/priv/}) {
 1360:                 undef($infunc);
 1361:                 $label = 'edit';
 1362:             } else {
 1363:                 $clearbutton = 1;
 1364:             }
 1365:         }
 1366:         my $editor = &switch('','',6,1,$icon,$label,'resource[_2]',
 1367:                              $jscall,"Edit this resource",'','',$infunc);
 1368:         if ($infunc) {
 1369:             return 1;
 1370:         } elsif ($clearbutton) {
 1371:             return &clear(6,1);
 1372:         } else {
 1373:             return $editor;
 1374:         }
 1375:     }
 1376:     return;
 1377: }
 1378: 
 1379: sub prepare_functions {
 1380:     my ($resurl,$forcereg,$group,$bread_crumbs,$advtools,$docscrumbs,$forbodytag) = @_;
 1381:     unless ($env{'request.registered'}) {
 1382:         undef(@inlineremote);
 1383:     }
 1384:     my ($cdom,$cnum,%perms,$cfile,$switchserver,$home,$forceedit,
 1385:         $forceview);
 1386: 
 1387:     if ($env{'request.course.id'}) {
 1388:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
 1389:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 1390:         $perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
 1391:     }
 1392: 
 1393:     my $editbutton = '';
 1394: #
 1395: # Determine whether or not to display 'Edit' icon/button
 1396: #
 1397:     if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
 1398:         my $file=&Apache::lonnet::declutter($env{'request.filename'});
 1399:         ($cfile,$home,$switchserver,$forceedit,$forceview) =
 1400:             &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
 1401:                 &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
 1402:         if (($cfile) && ($home ne '') && ($home ne 'no_host')) {
 1403:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
 1404:                                           $forceedit,$forceview,$forcereg);
 1405:         }
 1406:     } elsif ((!$env{'request.course.id'}) &&
 1407:              ($env{'user.author'}) && ($env{'request.filename'}) &&
 1408:              ($env{'request.role'} !~/^(aa|ca|au)/)) {
 1409: #
 1410: # Currently do not have the role of author or co-author.
 1411: # Do we have authoring privileges for the resource?
 1412: #
 1413:         my $file=&Apache::lonnet::declutter($env{'request.filename'});
 1414:         ($cfile,$home,$switchserver,$forceedit,$forceview) =
 1415:             &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
 1416:                 &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
 1417:         if (($cfile) && ($home ne '') && ($home ne 'no_host')) {
 1418:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
 1419:                                           $forceedit,$forceview,$forcereg);
 1420:         }
 1421:     } elsif ($env{'request.course.id'}) {
 1422: #
 1423: # This applies in course context
 1424: #
 1425:         if (($perms{'mdc'}) &&
 1426:             (($resurl eq "/public/$cdom/$cnum/syllabus") ||
 1427:             ($resurl =~ m{^/uploaded/$cdom/$cnum/portfolio/syllabus/}))) {
 1428:             $cfile = $resurl;
 1429:             $home = &Apache::lonnet::homeserver($cnum,$cdom);
 1430:             if ($env{'form.forceedit'}) {
 1431:                 $forceview = 1;
 1432:             } else {
 1433:                 $forceedit = 1;
 1434:             }
 1435:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
 1436:                                           $forceedit,$forceview,$forcereg);
 1437:         } elsif (($resurl eq '/adm/extresedit') &&
 1438:                  (($env{'form.symb'}) || ($env{'form.folderpath'}))) {
 1439:             ($cfile,$home,$switchserver,$forceedit,$forceview) =
 1440:             &Apache::lonnet::can_edit_resource($resurl,$cnum,$cdom,$resurl,
 1441:                                                $env{'form.symb'});
 1442:             if ($cfile ne '') {
 1443:                 $editbutton = &get_editbutton($cfile,$home,$switchserver,
 1444:                                               $forceedit,$forceview,$forcereg,
 1445:                                               $env{'form.title'},$env{'form.suppurl'});
 1446:             }
 1447:         } elsif (($resurl =~ m{^/?adm/viewclasslist$}) &&
 1448:                  (&Apache::lonnet::allowed('opa',$env{'request.course.id'}))) {
 1449:             ($cfile,$home,$switchserver,$forceedit,$forceview) =
 1450:             &Apache::lonnet::can_edit_resource($resurl,$cnum,$cdom,$resurl,
 1451:                                                $env{'form.symb'});
 1452:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
 1453:                                           $forceedit,$forceview,$forcereg);
 1454:         } elsif (($resurl !~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) &&
 1455:                  ($resurl ne '/cgi-bin/printout.pl')) {
 1456:             if ($env{'request.filename'}) {
 1457:                 my $file=&Apache::lonnet::declutter($env{'request.filename'});
 1458:                 ($cfile,$home,$switchserver,$forceedit,$forceview) =
 1459:                     &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
 1460:                         &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
 1461:                 if ($cfile ne '') {
 1462:                     $editbutton = &get_editbutton($cfile,$home,$switchserver,
 1463:                                                   $forceedit,$forceview,$forcereg);
 1464:                 }
 1465:             }
 1466:         }
 1467:     }
 1468: # End determination of 'Edit' icon/button display
 1469: 
 1470:     if ($env{'request.course.id'}) {
 1471: # This applies to about me page for users in a course
 1472:         if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
 1473:             my ($sdom,$sname) = ($1,$2);
 1474:             unless (&Apache::lonnet::is_course($sdom,$sname)) {
 1475:                 &switch('','',6,4,'mail-message-new-22x22.png','Message to user',
 1476:                         '',
 1477:                         "go('/adm/email?compose=individual&amp;recname=$sname&amp;recdom=$sdom')",
 1478:                             'Send message to specific user','','',1);
 1479:             }
 1480:             my $hideprivileged = 1;
 1481:             if (&Apache::lonnet::in_course($sdom,$sname,$cdom,$cnum,undef,
 1482:                                            $hideprivileged)) {
 1483:                 foreach my $priv ('vsa','vgr','srm') {
 1484:                     $perms{$priv} = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
 1485:                     if (!$perms{$priv} && $env{'request.course.sec'} ne '') {
 1486:                         $perms{$priv} =
 1487:                             &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
 1488:                     }
 1489:                 }
 1490:                 if ($perms{'vsa'}) {
 1491:                     &switch('','',6,5,'trck-22x22.png','Activity',
 1492:                             '',
 1493:                             "go('/adm/trackstudent?selected_student=$sname:$sdom')",
 1494:                             'View recent activity by this person','','',1);
 1495:                 }
 1496:                 if ($perms{'vgr'}) {
 1497:                     &switch('','',6,6,'rsrv-22x22.png','Reservations',
 1498:                             '',
 1499:                             "go('/adm/slotrequest?command=showresv&amp;origin=aboutme&amp;uname=$sname&amp;udom=$sdom')",
 1500:                             'Slot reservation history','','',1);
 1501:                 }
 1502:                 if ($perms{'srm'}) {
 1503:                     &switch('','',6,7,'contact-new-22x22.png','Records',
 1504:                             '',
 1505:                             "go('/adm/email?recordftf=retrieve&amp;recname=$sname&amp;recdom=$sdom')",
 1506:                             'Add records','','',1);
 1507:                 }
 1508:             }
 1509:         }
 1510:         if (($env{'form.folderpath'} =~ /^supplemental/) &&
 1511:             (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) &&
 1512:             (($resurl =~ m{^/adm/wrapper/ext/}) ||
 1513:              ($resurl =~ m{^/uploaded/$cdom/$cnum/supplemental/}) ||
 1514:              ($resurl eq '/adm/supplemental') ||
 1515:              ($resurl =~ m{^/public/$cdom/$cnum/syllabus$}) ||
 1516:              ($resurl =~ m{^/adm/$match_domain/$match_username/aboutme$}))) {
 1517:             my @folders=split('&',$env{'form.folderpath'});
 1518:             if ((@folders > 2) || ($resurl ne '/adm/supplemental')) {
 1519:                 my $esc_path=&escape(&HTML::Entities::encode(&escape($env{'form.folderpath'}),'<>&"'));
 1520:                 &switch('','',7,4,'docs-22x22.png','Edit Folder','parms[_2]',
 1521:                         "location.href='/adm/coursedocs?command=direct&amp;forcesupplement=1&amp;supppath=$esc_path'",
 1522:                         'Folder/Page Content','','',1);
 1523:             }
 1524:         }
 1525:     }
 1526: 
 1527: # End checking for items for about me page for users in a course
 1528:     if ($docscrumbs) {
 1529:         &Apache::lonhtmlcommon::clear_breadcrumb_tools();
 1530:         &advtools_crumbs(@inlineremote);
 1531:         return $editbutton;
 1532:     } elsif (($env{'request.registered'}) && (!ref($forbodytag))) {
 1533:         return $editbutton;
 1534:     } else {
 1535:         if (ref($bread_crumbs) eq 'ARRAY') {
 1536:             if (@inlineremote > 0) {
 1537:                 if (ref($advtools) eq 'ARRAY') {
 1538:                     @{$advtools} = @inlineremote;
 1539:                 }
 1540:             }
 1541:             return;
 1542:         } elsif (@inlineremote > 0) {
 1543:             &Apache::lonhtmlcommon::clear_breadcrumb_tools();
 1544:             &advtools_crumbs(@inlineremote);
 1545:             if (ref($forbodytag)) {
 1546:                 $$forbodytag =
 1547:                     &Apache::lonhtmlcommon::scripttag('', 'start')
 1548:                    .&Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
 1549:                    .&Apache::lonhtmlcommon::scripttag('', 'end');
 1550:             }
 1551:             return;
 1552:         }
 1553:     }
 1554: }
 1555: 
 1556: sub advtools_crumbs {
 1557:     my @funcs = @_;
 1558:     if ($env{'request.noversionuri'} =~ m{^/adm/$match_domain/$match_username/aboutme$}) {
 1559:         &Apache::lonhtmlcommon::add_breadcrumb_tool(
 1560:             'advtools', @funcs[61,64,65,66,67,74]);
 1561:     } elsif ($env{'request.noversionuri'} !~ m{^/adm/(navmaps|viewclasslist)(\?|$)}) {
 1562:         &Apache::lonhtmlcommon::add_breadcrumb_tool(
 1563:             'advtools', @funcs[61,71,72,73,74,92]);
 1564:     } elsif ($env{'request.noversionuri'} eq '/adm/viewclasslist') {
 1565:         &Apache::lonhtmlcommon::add_breadcrumb_tool(
 1566:             'advtools', $funcs[61]);
 1567:     }
 1568: }
 1569: 
 1570: # ================================================================== Raw Config
 1571: 
 1572: sub clear {
 1573:     my ($row,$col)=@_;
 1574:     if ($env{'environment.remote'} eq 'on') {
 1575:        if (($row<1) || ($row>13)) { return ''; }
 1576:        return "\n".qq(window.status+='.';swmenu.clearbut($row,$col););
 1577:     } else {
 1578:         $inlineremote[10*$row+$col]='';
 1579:         return '';
 1580:     }
 1581: }
 1582: 
 1583: # ============================================ Switch a button or create a link
 1584: # Switch acts on the javascript that is executed when a button is clicked.  
 1585: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
 1586: 
 1587: sub switch {
 1588:     my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak,$infunc)=@_;
 1589:     $act=~s/\$uname/$uname/g;
 1590:     $act=~s/\$udom/$udom/g;
 1591:     $top=&mt($top);
 1592:     $bot=&mt($bot);
 1593:     $desc=&mt($desc);
 1594:     my $idx=10*$row+$col;
 1595:     $category_members{$cat}.=':'.$idx;
 1596: 
 1597:     if (($env{'environment.remote'} eq 'on') && (!$infunc)) {
 1598:         if (($row<1) || ($row>13)) { return ''; }
 1599:         if ($env{'request.state'} eq 'construct') {
 1600:             my $text = $top.' '.$bot;
 1601:             $text=~s/\s*\-\s*//gs;
 1602:             my $pic = '<img alt="'.$text.'" src="'.
 1603:                       &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
 1604:                       '" align="'.($nobreak==3?'right':'left').'" class="LC_icon" />';
 1605:            $inlineremote[$idx] =
 1606:                '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.
 1607:                $pic.'<span class="LC_menubuttons_inline_text">'.$top.'&nbsp;</span></a>';
 1608:         }
 1609: # Remote
 1610:         $img=~s/\.png$/\.gif/;
 1611:         return "\n".
 1612:  qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
 1613:     }
 1614: 
 1615: # Inline Menu
 1616:     if ($nobreak==2) { return ''; }
 1617:     my $text=$top.' '.$bot;
 1618:     $text=~s/\s*\-\s*//gs;
 1619: 
 1620:     my $pic=
 1621: 	   '<img alt="'.$text.'" src="'.
 1622: 	   &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
 1623: 	   '" align="'.($nobreak==3?'right':'left').'" class="LC_icon" />';
 1624:     if ($env{'browser.interface'} eq 'faketextual') {
 1625: # Main Menu
 1626: 	   if ($nobreak==3) {
 1627: 	       $inlineremote[$idx]="\n".
 1628: 		   '<td class="LC_menubuttons_text" align="right">'.$text.
 1629: 		   '</td><td align="left">'.
 1630: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
 1631: 	   } elsif ($nobreak) {
 1632: 	       $inlineremote[$idx]="\n<tr>".
 1633: 		   '<td align="left">'.
 1634: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td>
 1635:                     <td class="LC_menubuttons_text" align="left"><a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$text.'</span></a></td>';
 1636: 	   } else {
 1637: 	       $inlineremote[$idx]="\n<tr>".
 1638: 		   '<td align="left">'.
 1639: 		   '<a href="javascript:'.$act.';">'.$pic.
 1640: 		   '</a></td><td class="LC_menubuttons_text" colspan="3">'.
 1641: 		   '<a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$desc.'</span></a></td></tr>';
 1642: 	   }
 1643:     } else {
 1644: # Inline Menu
 1645:         my @tools = (93,91,81,82,83);
 1646:         unless ($env{'request.state'} eq 'construct') {
 1647:             push(@tools,63);
 1648:         }
 1649:         if (($env{'environment.icons'} eq 'iconsonly') &&
 1650:             (grep(/^$idx$/,@tools))) {
 1651:             $inlineremote[$idx] =
 1652:         '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.'</a>';
 1653:         } else {
 1654:             $inlineremote[$idx] =
 1655:        '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.
 1656:        '<span class="LC_menubuttons_inline_text">'.$top.'&nbsp;</span></a>';
 1657:         }
 1658:     }
 1659:     return '';
 1660: }
 1661: 
 1662: sub secondlevel {
 1663:     my $output='';
 1664:     my 
 1665:     ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_;
 1666:     if ($prt eq 'any') {
 1667: 	   $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1668:     } elsif ($prt=~/^r(\w+)/) {
 1669:         if ($rol eq $1) {
 1670:            $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1671:         }
 1672:     }
 1673:     return $output;
 1674: }
 1675: 
 1676: sub openmenu {
 1677:     my $menuname = &get_menu_name();
 1678:     unless ($env{'environment.remote'} eq 'on') { return ''; }
 1679:     my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
 1680:     return "window.open(".$nothing.",'".$menuname."');";
 1681: }
 1682: 
 1683: sub inlinemenu {
 1684:     undef(@inlineremote);
 1685:     undef(%category_members);
 1686: # calling rawconfig with "1" will evaluate mydesk.tab, even if there is no active remote control
 1687:     &rawconfig(1);
 1688:     my $output='<table><tr>';
 1689:     for (my $col=1; $col<=2; $col++) {
 1690:         $output.='<td class="LC_mainmenu_col_fieldset">';
 1691:         for (my $row=1; $row<=8; $row++) {
 1692:             foreach my $cat (keys(%category_members)) {
 1693:                if ($category_positions{$cat} ne "$col,$row") { next; }
 1694:                #$output.='<table><tr><td colspan="4" class="LC_menubuttons_category">'.&mt($category_names{$cat}).'</td></tr>';
 1695:                $output.='<div class="LC_Box LC_400Box">';
 1696: 	       $output.='<h3 class="LC_hcell">'.&mt($category_names{$cat}).'</h3>';
 1697:                $output.='<table>';
 1698:                my %active=();
 1699:                foreach my $menu_item (split(/\:/,$category_members{$cat})) {
 1700:                   if ($inlineremote[$menu_item]) {
 1701:                      $active{$menu_item}=1;
 1702:                   }
 1703:                }  
 1704:                foreach my $item (sort(keys(%active))) {
 1705:                   $output.=$inlineremote[$item];
 1706:                }
 1707:                $output.='</table>';
 1708:                $output.='</div>';
 1709:             }
 1710:          }
 1711:          $output.="</td>";
 1712:     }
 1713:     $output.="</tr></table>";
 1714:     return $output;
 1715: }
 1716: 
 1717: sub rawconfig {
 1718: #
 1719: # This evaluates mydesk.tab
 1720: # Need to add more positions and more privileges to deal with all
 1721: # menu items.
 1722: #
 1723:     my $textualoverride=shift;
 1724:     my $output='';
 1725:     if ($env{'environment.remote'} eq 'on') {
 1726:        $output.=
 1727:  "window.status='Opening Remote Control';var swmenu=".&openmenu().
 1728: "\nwindow.status='Configuring Remote Control ';";
 1729:     } else {
 1730:         unless ($textualoverride) { return ''; }
 1731:     }
 1732:     my $uname=$env{'user.name'};
 1733:     my $udom=$env{'user.domain'};
 1734:     my $adv=$env{'user.adv'};
 1735:     my $show_course=&Apache::loncommon::show_course();
 1736:     my $author=$env{'user.author'};
 1737:     my $crs='';
 1738:     my $crstype='';
 1739:     if ($env{'request.course.id'}) {
 1740:        $crs='/'.$env{'request.course.id'};
 1741:        if ($env{'request.course.sec'}) {
 1742: 	   $crs.='_'.$env{'request.course.sec'};
 1743:        }
 1744:        $crs=~s/\_/\//g;
 1745:        $crstype = &Apache::loncommon::course_type();
 1746:     }
 1747:     my $pub=($env{'request.state'} eq 'published');
 1748:     my $con=($env{'request.state'} eq 'construct');
 1749:     my $rol=$env{'request.role'};
 1750:     my $requested_domain;
 1751:     if ($rol) {
 1752:        $requested_domain = $env{'request.role.domain'};
 1753:     }
 1754:     foreach my $line (@desklines) {
 1755:         my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
 1756:         $prt=~s/\$uname/$uname/g;
 1757:         $prt=~s/\$udom/$udom/g;
 1758:         if ($prt =~ /\$crs/) {
 1759:             next unless ($env{'request.course.id'});
 1760:             next if ($crstype eq 'Community');
 1761:             $prt=~s/\$crs/$crs/g;
 1762:         } elsif ($prt =~ /\$cmty/) {
 1763:             next unless ($env{'request.course.id'});
 1764:             next if ($crstype ne 'Community');
 1765:             $prt=~s/\$cmty/$crs/g;
 1766:         }
 1767:         if ($prt =~ m/\$requested_domain/) {
 1768:             if ((!$requested_domain) && ($pro eq 'pbre') && ($env{'user.adv'})) {
 1769:                 $prt=~s/\$requested_domain/$env{'user.domain'}/g;
 1770:             } else {
 1771:                 $prt=~s/\$requested_domain/$requested_domain/g;
 1772:             }
 1773:         }
 1774:         if ($category_names{$cat}!~/\w/) { $cat='oth'; }
 1775:         if ($pro eq 'clear') {
 1776: 	    $output.=&clear($row,$col);
 1777:         } elsif ($pro eq 'any') {
 1778:                $output.=&secondlevel(
 1779: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1780: 	} elsif ($pro eq 'smp') {
 1781:             unless ($adv) {
 1782:                $output.=&secondlevel(
 1783:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1784:             }
 1785:         } elsif ($pro eq 'adv') {
 1786:             if ($adv) {
 1787:                $output.=&secondlevel(
 1788: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1789:             }
 1790: 	} elsif ($pro eq 'shc') {
 1791:             if ($show_course) {
 1792:                $output.=&secondlevel(
 1793:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1794:             }
 1795:         } elsif ($pro eq 'nsc') {
 1796:             if (!$show_course) {
 1797:                $output.=&secondlevel(
 1798: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1799:             }
 1800:         } elsif (($pro=~/^p(\w+)/) && ($prt)) {
 1801:             my $priv = $1;
 1802:             if ($priv =~ /^mdc(Course|Community)/) {
 1803:                 if ($crstype eq $1) {
 1804:                     $priv = 'mdc';
 1805:                 } else {
 1806:                     next;
 1807:                 }
 1808:             }
 1809:             if ((($priv eq 'bre') && (&Apache::lonnet::allowed($priv,$prt) eq 'F')) ||
 1810:                 (($priv ne 'bre') && (&Apache::lonnet::allowed($priv,$prt)))) {
 1811:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1812:             }
 1813:         } elsif ($pro eq 'course')  {
 1814:             if (($env{'request.course.fn'}) && ($crstype ne 'Community')) {
 1815:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1816: 	    }
 1817:         } elsif ($pro eq 'community')  {
 1818:             if (($env{'request.course.fn'}) && ($crstype eq 'Community')) {
 1819:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1820:             }
 1821:         } elsif ($pro =~ /^courseenv_(.*)$/) {
 1822:             my $key = $1;
 1823:             if ($crstype ne 'Community') {
 1824:                 my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
 1825:                 if ($key eq 'canuse_pdfforms') {
 1826:                     if ($env{'request.course.id'} && $coursepref eq '') {
 1827:                         my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
 1828:                         $coursepref = $domdefs{'canuse_pdfforms'};
 1829:                     }
 1830:                 }
 1831:                 if ($coursepref) { 
 1832:                     $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1833:                 }
 1834:             }
 1835:         } elsif ($pro =~ /^communityenv_(.*)$/) {
 1836:             my $key = $1;
 1837:             if ($crstype eq 'Community') {
 1838:                 my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
 1839:                 if ($key eq 'canuse_pdfforms') {
 1840:                     if ($env{'request.course.id'} && $coursepref eq '') {
 1841:                         my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
 1842:                         $coursepref = $domdefs{'canuse_pdfforms'};
 1843:                     }
 1844:                 }
 1845:                 if ($coursepref) { 
 1846:                     $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1847:                 }
 1848:             }
 1849:         } elsif ($pro =~ /^course_(.*)$/) {
 1850:             # Check for permissions inside of a course
 1851:             if (($env{'request.course.id'}) && ($crstype ne 'Community') && 
 1852:                 (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
 1853:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
 1854:                  )) {
 1855:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1856: 	    }
 1857:         } elsif ($pro =~ /^community_(.*)$/) {
 1858:             # Check for permissions inside of a community
 1859:             if (($env{'request.course.id'}) && ($crstype eq 'Community') &&   
 1860:                 (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
 1861:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
 1862:                  )) {
 1863:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1864:             }
 1865:         } elsif ($pro eq 'author') {
 1866:             if ($author) {
 1867:                 if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
 1868:                     (($prt eq 'raa') && ($env{'request.role'}=~/^aa/)) || 
 1869:                     (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
 1870:                     # Check that we are on the correct machine
 1871:                     my $cadom=$requested_domain;
 1872:                     my $caname=$env{'user.name'};
 1873:                     if (($prt eq 'rca') || ($prt eq 'raa')) {
 1874: 		       ($cadom,$caname)=
 1875:                                ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
 1876:                     }                       
 1877:                     $act =~ s/\$caname/$caname/g;
 1878:                     $act =~ s/\$cadom/$cadom/g;
 1879:                     my $home = &Apache::lonnet::homeserver($caname,$cadom);
 1880: 		    my $allowed=0;
 1881: 		    my @ids=&Apache::lonnet::current_machine_ids();
 1882: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
 1883: 		    if ($allowed) {
 1884:                         $output.=&switch($caname,$cadom,
 1885:                                         $row,$col,$img,$top,$bot,$act,$desc,$cat);
 1886:                     }
 1887:                 }
 1888:             }
 1889:         } elsif ($pro eq 'tools') {
 1890:             my @tools = ('aboutme','blog','portfolio');
 1891:             if (grep(/^\Q$prt\E$/,@tools)) {
 1892:                 if (!&Apache::lonnet::usertools_access($env{'user.name'},
 1893:                                                        $env{'user.domain'},
 1894:                                                        $prt,undef,'tools')) {
 1895:                     $output.=&clear($row,$col);
 1896:                     next;
 1897:                 }
 1898:             } elsif (($prt eq 'reqcrsnsc') || ($prt eq 'reqcrsshc')) {
 1899:                 if (($prt eq 'reqcrsnsc') && ($show_course))   {
 1900:                     next;
 1901:                 }
 1902:                 if (($prt eq 'reqcrsshc') && (!$show_course)) {
 1903:                     next;
 1904:                 }
 1905:                 my $showreqcrs = &check_for_rcrs();
 1906:                 if (!$showreqcrs) {
 1907:                     $output.=&clear($row,$col);
 1908:                     next;
 1909:                 }
 1910:             }
 1911:             $prt='any';
 1912:             $output.=&secondlevel(
 1913:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1914:         }
 1915:     }
 1916:     if ($env{'environment.remote'} eq 'on') {
 1917:         $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
 1918:         if (&Apache::lonmsg::newmail()) {
 1919:             $output.='swmenu.setstatus("you have","messages");';
 1920:         }
 1921:     }
 1922:     return $output;
 1923: }
 1924: 
 1925: sub check_for_rcrs {
 1926:     my $showreqcrs = 0;
 1927:     my @reqtypes = ('official','unofficial','community','textbook');
 1928:     foreach my $type (@reqtypes) {
 1929:         if (&Apache::lonnet::usertools_access($env{'user.name'},
 1930:                                               $env{'user.domain'},
 1931:                                               $type,undef,'requestcourses')) {
 1932:             $showreqcrs = 1;
 1933:             last;
 1934:         }
 1935:     }
 1936:     if (!$showreqcrs) {
 1937:         foreach my $type (@reqtypes) {
 1938:             if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
 1939:                 $showreqcrs = 1;
 1940:                 last;
 1941:             }
 1942:         }
 1943:     }
 1944:     return $showreqcrs;
 1945: }
 1946: 
 1947: # ======================================================================= Close
 1948: 
 1949: sub close {
 1950:     unless ($env{'environment.remote'} eq 'on') { return ''; }
 1951:     my $menuname = &get_menu_name();
 1952:     return(<<ENDCLOSE);
 1953: <script type="text/javascript">
 1954: // <![CDATA[
 1955: window.status='Accessing Remote Control';
 1956: menu=window.open("/adm/rat/empty.html","$menuname",
 1957:                  "height=350,width=150,scrollbars=no,menubar=no");
 1958: window.status='Disabling Remote Control';
 1959: menu.active=0;
 1960: menu.autologout=0;
 1961: window.status='Closing Remote Control';
 1962: menu.close();
 1963: window.status='Done.';
 1964: // ]]>
 1965: </script>
 1966: ENDCLOSE
 1967: }
 1968: 
 1969: sub dc_popup_js {
 1970:     my %lt = &Apache::lonlocal::texthash(
 1971:                                           more => '(More ...)',
 1972:                                           less => '(Less ...)',
 1973:                                         );
 1974:     return <<"END";
 1975: 
 1976: function showCourseID() {
 1977:     document.getElementById('dccid').style.display='block';
 1978:     document.getElementById('dccid').style.textAlign='left';
 1979:     document.getElementById('dccid').style.textFace='normal';
 1980:     document.getElementById('dccidtext').innerHTML ='<a href="javascript:hideCourseID();" class="LC_menubuttons_link">$lt{'less'}</a>';
 1981:     return;
 1982: }
 1983: 
 1984: function hideCourseID() {
 1985:     document.getElementById('dccid').style.display='none';
 1986:     document.getElementById('dccidtext').innerHTML ='<a href="javascript:showCourseID()" class="LC_menubuttons_link">$lt{'more'}</a>';
 1987:     return;
 1988: }
 1989: 
 1990: END
 1991: 
 1992: }
 1993: 
 1994: sub countdown_toggle_js {
 1995:     return <<"END";
 1996: 
 1997: function toggleCountdown() {
 1998:     var countdownid = document.getElementById('duedatecountdown');
 1999:     var currstyle = countdownid.style.display;
 2000:     if (currstyle == 'inline') {
 2001:         countdownid.style.display = 'none';
 2002:         document.getElementById('ddcountcollapse').innerHTML='';
 2003:         document.getElementById('ddcountexpand').innerHTML='&#9668;&nbsp;';
 2004:     } else {
 2005:         countdownid.style.display = 'inline';
 2006:         document.getElementById('ddcountcollapse').innerHTML='&#9658;&nbsp;';
 2007:         document.getElementById('ddcountexpand').innerHTML='';
 2008:     }
 2009:     return;
 2010: }
 2011: 
 2012: END
 2013: }
 2014: 
 2015: sub utilityfunctions {
 2016:     my ($httphost) = @_;
 2017:     my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
 2018:     if ($currenturl =~ m{^/adm/wrapper/ext/}
 2019:         && $env{'request.external.querystring'} ) {
 2020:             $currenturl .= ($currenturl=~/\?/)?'&':'?'.$env{'request.external.querystring'};
 2021:     }
 2022:     $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
 2023:     
 2024:     my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
 2025: 
 2026:     my $dc_popup_cid;
 2027:     if ($env{'user.adv'} && exists($env{'user.role.dc./'.
 2028:                         $env{'course.'.$env{'request.course.id'}.
 2029:                                  '.domain'}.'/'})) {
 2030:         $dc_popup_cid = &dc_popup_js();
 2031:     }
 2032: 
 2033:     my $start_page_annotate = 
 2034:         &Apache::loncommon::start_page('Annotator',undef,
 2035: 				       {'only_body' => 1,
 2036: 					'js_ready'  => 1,
 2037: 					'bgcolor'   => '#BBBBBB',
 2038: 					'add_entries' => {
 2039: 					    'onload' => 'javascript:document.goannotate.submit();'}});
 2040: 
 2041:     my $end_page_annotate = 
 2042:         &Apache::loncommon::end_page({'js_ready' => 1});
 2043: 
 2044:     my $jumptores = &Apache::lonhtmlcommon::javascript_jumpto_resource();
 2045: 
 2046:     my $esc_url=&escape($currenturl);
 2047:     my $esc_symb=&escape($currentsymb);
 2048: 
 2049:     my $countdown = &countdown_toggle_js();
 2050: 
 2051:     my $hostvar = '
 2052: function setLCHost() {
 2053:     var lcHostname="";
 2054: ';
 2055:     if ($httphost =~ m{^https?\://}) {
 2056:         $hostvar .= '    var lcServer="'.$httphost.'";'."\n".
 2057:                     '    var hostReg = /^https?:\/\/([^\/]+)$/i;'."\n".
 2058:                     '    var match = hostReg.exec(lcServer);'."\n".
 2059:                     '    if (match.length) {'."\n".
 2060:                     '        if (match[1] == location.hostname) {'."\n".
 2061:                     '            lcHostname=lcServer;'."\n".
 2062:                     '        }'."\n".
 2063:                     '    }'."\n";
 2064:     }
 2065: 
 2066:     $hostvar .= '    return lcHostname;'."\n".
 2067: '}'."\n";
 2068: 
 2069: return (<<ENDUTILITY)
 2070:     $hostvar
 2071:     var currentURL=unescape("$esc_url");
 2072:     var reloadURL=unescape("$esc_url");
 2073:     var currentSymb=unescape("$esc_symb");
 2074: 
 2075: $dc_popup_cid
 2076: 
 2077: function go(url) {
 2078:    if (url!='' && url!= null) {
 2079:        currentURL = null;
 2080:        currentSymb= null;
 2081:        var lcHostname = setLCHost();
 2082:        window.location.href=lcHostname+url;
 2083:    }
 2084: }
 2085: 
 2086: $jumptores
 2087: 
 2088: function gopost(url,postdata) {
 2089:    if (url!='') {
 2090:       var lcHostname = setLCHost();
 2091:       this.document.server.action=lcHostname+url;
 2092:       this.document.server.postdata.value=postdata;
 2093:       this.document.server.command.value='';
 2094:       this.document.server.url.value='';
 2095:       this.document.server.symb.value='';
 2096:       this.document.server.submit();
 2097:    }
 2098: }
 2099: 
 2100: function gocmd(url,cmd) {
 2101:    if (url!='') {
 2102:       var lcHostname = setLCHost();
 2103:       this.document.server.action=lcHostname+url;
 2104:       this.document.server.postdata.value='';
 2105:       this.document.server.command.value=cmd;
 2106:       this.document.server.url.value=currentURL;
 2107:       this.document.server.symb.value=currentSymb;
 2108:       this.document.server.submit();
 2109:    }
 2110: }
 2111: 
 2112: function gocstr(url,filename) {
 2113:     if (url == '/adm/cfile?action=delete') {
 2114:         this.document.cstrdelete.filename.value = filename
 2115:         this.document.cstrdelete.submit();
 2116:         return;
 2117:     }
 2118:     if (url == '/adm/printout') {
 2119:         this.document.cstrprint.postdata.value = filename
 2120:         this.document.cstrprint.curseed.value = 0;
 2121:         this.document.cstrprint.problemtype.value = 0;
 2122:         if (this.document.lonhomework) {
 2123:             if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
 2124:                 this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
 2125:             }
 2126:             if (this.document.lonhomework.problemtype) {
 2127: 		if (this.document.lonhomework.problemtype.value) {
 2128: 		    this.document.cstrprint.problemtype.value = 
 2129: 			this.document.lonhomework.problemtype.value;
 2130: 		} else if (this.document.lonhomework.problemtype.options) {
 2131: 		    for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
 2132: 			if (this.document.lonhomework.problemtype.options[i].selected) {
 2133: 			    if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') { 
 2134: 				this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
 2135: 				}
 2136: 			}
 2137: 		    }
 2138: 		}
 2139: 	    }
 2140: 	}
 2141:         this.document.cstrprint.submit();
 2142:         return;
 2143:     }
 2144:     if (url !='') {
 2145:         this.document.constspace.filename.value = filename;
 2146:         this.document.constspace.action = url;
 2147:         this.document.constspace.submit();
 2148:     }
 2149: }
 2150: 
 2151: function golist(url) {
 2152:    if (url!='' && url!= null) {
 2153:        currentURL = null;
 2154:        currentSymb= null;
 2155:        var lcHostname = setLCHost();
 2156:        top.location.href=lcHostname+url;
 2157:    }
 2158: }
 2159: 
 2160: 
 2161: 
 2162: function catalog_info(isMobile) {
 2163:     if (isMobile == 1) {
 2164:         openMyModal(window.location.pathname+'.meta?modal=1',500,400,'yes');
 2165:     } else {
 2166:         loncatinfo=window.open(window.location.pathname+'.meta',"LONcatInfo",'height=500,width=400,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
 2167:     }
 2168: }
 2169: 
 2170: function chat_win() {
 2171:    var lcHostname = setLCHost();
 2172:    lonchat=window.open(lcHostname+'/res/adm/pages/chatroom.html',"LONchat",'height=320,width=480,resizable=yes,location=no,menubar=no,toolbar=no');
 2173: }
 2174: 
 2175: function group_chat(group) {
 2176:    var lcHostname = setLCHost();
 2177:    var url = lcHostname+'/adm/groupchat?group='+group;
 2178:    var winName = 'LONchat_'+group;
 2179:    grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
 2180: }
 2181: 
 2182: function annotate() {
 2183:    w_Annotator_flag=1;
 2184:    annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
 2185:    annotator.document.write(
 2186:    '$start_page_annotate'
 2187:   +"<form name='goannotate' target='Annotator' method='post' "
 2188:   +"action='/adm/annotations'>"
 2189:   +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />"
 2190:   +"<\\/form>"
 2191:   +'$end_page_annotate');
 2192:    annotator.document.close();
 2193: }
 2194: 
 2195: function open_StoredLinks_Import(rat) {
 2196:    var newWin;
 2197:    var lcHostname = setLCHost();
 2198:    if (rat) {
 2199:        newWin = window.open(lcHostname+'/adm/wishlist?inhibitmenu=yes&mode=import&rat='+rat,
 2200:                             'wishlistImport','scrollbars=1,resizable=1,menubar=0');
 2201:    }
 2202:    else {
 2203:        newWin = window.open(lcHostname+'/adm/wishlist?inhibitmenu=yes&mode=import',
 2204:                             'wishlistImport','scrollbars=1,resizable=1,menubar=0');
 2205:    }
 2206:    newWin.focus();
 2207: }
 2208: 
 2209: (function (\$) {
 2210:   \$(document).ready(function () {
 2211:     \$.single=function(a){return function(b){a[0]=b;return a}}(\$([1]));
 2212:     /*\@cc_on
 2213:       if (!window.XMLHttpRequest) {
 2214:         \$('.LC_hoverable').each(function () {
 2215:           this.attachEvent('onmouseenter', function (evt) { \$.single(evt.srcElement).addClass('hover'); });
 2216:           this.attachEvent('onmouseleave', function (evt) { \$.single(evt.srcElement).removeClass('hover'); });
 2217:         });
 2218:       }
 2219:     \@*/
 2220:   });
 2221: }(jQuery));
 2222: 
 2223: $countdown
 2224: 
 2225: ENDUTILITY
 2226: }
 2227: 
 2228: sub serverform {
 2229:     return(<<ENDSERVERFORM);
 2230: <form name="server" action="/adm/logout" method="post" target="_top">
 2231: <input type="hidden" name="postdata" value="none" />
 2232: <input type="hidden" name="command" value="none" />
 2233: <input type="hidden" name="url" value="none" />
 2234: <input type="hidden" name="symb" value="none" />
 2235: </form>
 2236: ENDSERVERFORM
 2237: }
 2238: 
 2239: sub constspaceform {
 2240:     return(<<ENDCONSTSPACEFORM);
 2241: <form name="constspace" action="/adm/logout" method="post" target="_top">
 2242: <input type="hidden" name="filename" value="" />
 2243: </form>
 2244: <form name="cstrdelete" action="/adm/cfile" method="post" target="_top">
 2245: <input type="hidden" name="action" value="delete" /> 
 2246: <input type="hidden" name="filename" value="" />
 2247: </form>
 2248: <form name="cstrprint" action="/adm/printout" target="_parent" method="post">
 2249: <input type="hidden" name="postdata" value="" />
 2250: <input type="hidden" name="curseed" value="" />
 2251: <input type="hidden" name="problemtype" value="" />
 2252: </form>
 2253: 
 2254: ENDCONSTSPACEFORM
 2255: }
 2256: 
 2257: sub get_nav_status {
 2258:     my $navstatus="swmenu.w_loncapanav_flag=";
 2259:     if ($env{'environment.remotenavmap'} eq 'on') {
 2260:         $navstatus.="1";
 2261:     } else {
 2262:         $navstatus.="-1";
 2263:     }
 2264:     return $navstatus;
 2265: }
 2266: 
 2267: sub hidden_button_check {
 2268:     if ( $env{'request.course.id'} eq ''
 2269:          || $env{'request.role.adv'} ) {
 2270: 
 2271:         return;
 2272:     }
 2273:     my $buttonshide = &Apache::lonnet::EXT('resource.0.buttonshide');
 2274:     return $buttonshide; 
 2275: }
 2276: 
 2277: sub roles_selector {
 2278:     my ($cdom,$cnum,$httphost) = @_;
 2279:     my $crstype = &Apache::loncommon::course_type();
 2280:     my $now = time;
 2281:     my (%courseroles,%seccount,%courseprivs);
 2282:     my $is_cc;
 2283:     my ($js,$form,$switcher,$switchtext);
 2284:     my $ccrole;
 2285:     if ($crstype eq 'Community') {
 2286:         $ccrole = 'co';
 2287:     } else {
 2288:         $ccrole = 'cc';
 2289:     }
 2290:     my ($priv,$gotsymb,$destsymb);
 2291:     my $destinationurl = $ENV{'REQUEST_URI'};
 2292:     if ($destinationurl =~ /\?symb=/) {
 2293:         $gotsymb = 1;
 2294:     } elsif ($destinationurl =~ m{^/enc/}) {
 2295:         my $plainurl = &Apache::lonenc::unencrypted($destinationurl);
 2296:         if ($plainurl =~ /\?symb=/) {
 2297:             $gotsymb = 1;
 2298:         }
 2299:     }
 2300:     unless ($gotsymb) {
 2301:         $destsymb = &Apache::lonnet::symbread();
 2302:         if ($destsymb ne '') {
 2303:             $destsymb = &Apache::lonenc::check_encrypt($destsymb);
 2304:         }
 2305:     }
 2306:     my $reqprivs = &required_privs();
 2307:     if (ref($reqprivs) eq 'HASH') {
 2308:         my $destination = $destinationurl;
 2309:         $destination =~ s/(\?.*)$//;
 2310:         if (exists($reqprivs->{$destination})) {
 2311:             $priv = $reqprivs->{$destination};
 2312:         }
 2313:     }
 2314:     if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
 2315:         my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
 2316:         
 2317:         if ((($start) && ($start<0)) || 
 2318:             (($end) && ($end<$now))  ||
 2319:             (($start) && ($now<$start))) {
 2320:             $is_cc = 0;
 2321:         } else {
 2322:             $is_cc = 1;
 2323:         }
 2324:     }
 2325:     if ($is_cc) {
 2326:         &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs,$priv);
 2327:     } else {
 2328:         my %gotnosection;
 2329:         foreach my $item (keys(%env)) {
 2330:             if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
 2331:                 my $role = $1;
 2332:                 my $sec = $2;
 2333:                 next if ($role eq 'gr');
 2334:                 my ($start,$end) = split(/\./,$env{$item});
 2335:                 next if (($start && $start > $now) || ($end && $end < $now));
 2336:                 if ($sec eq '') {
 2337:                     if (!$gotnosection{$role}) {
 2338:                         $seccount{$role} ++;
 2339:                         $gotnosection{$role} = 1;
 2340:                     }
 2341:                 }
 2342:                 if ($priv ne '') {
 2343:                     my $cnumsec = $cnum;
 2344:                     if ($sec ne '') {
 2345:                         $cnumsec .= "/$sec";
 2346:                     }
 2347:                     $courseprivs{"$role./$cdom/$cnumsec./"} =
 2348:                         $env{"user.priv.$role./$cdom/$cnumsec./"};
 2349:                     $courseprivs{"$role./$cdom/$cnumsec./$cdom/"} =
 2350:                         $env{"user.priv.$role./$cdom/$cnumsec./$cdom/"};
 2351:                     $courseprivs{"$role./$cdom/$cnumsec./$cdom/$cnumsec"} =
 2352:                         $env{"user.priv.$role./$cdom/$cnumsec./$cdom/$cnumsec"};
 2353:                 }
 2354:                 if (ref($courseroles{$role}) eq 'ARRAY') {
 2355:                     if ($sec ne '') {
 2356:                         if (!grep(/^\Q$sec\E$/,@{$courseroles{$role}})) {
 2357:                             push(@{$courseroles{$role}},$sec);
 2358:                             $seccount{$role} ++;
 2359:                         }
 2360:                     }
 2361:                 } else {
 2362:                     @{$courseroles{$role}} = ();
 2363:                     if ($sec ne '') {
 2364:                         $seccount{$role} ++;
 2365:                         push(@{$courseroles{$role}},$sec);
 2366:                     }
 2367:                 }
 2368:             }
 2369:         }
 2370:     }
 2371:     $switchtext = 'Switch role'; # do not translate here
 2372:     my @roles_order = ($ccrole,'in','ta','ep','ad','st');
 2373:     my $numdiffsec;
 2374:     if (keys(%seccount) == 1) {
 2375:         foreach my $key (keys(%seccount)) {
 2376:             $numdiffsec = $seccount{$key};
 2377:         }
 2378:     }
 2379:     if ((keys(%seccount) > 1) || ($numdiffsec > 1)) {
 2380:         my @submenu;
 2381:         $js = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles,\%courseprivs,$priv);
 2382:         $form = 
 2383:             '<form name="rolechooser" method="post" action="'.$httphost.'/adm/roles">'."\n".
 2384:             '  <input type="hidden" name="destinationurl" value="'.
 2385:             &HTML::Entities::encode($destinationurl).'" />'."\n".
 2386:             '  <input type="hidden" name="gotorole" value="1" />'."\n".
 2387:             '  <input type="hidden" name="selectrole" value="" />'."\n".
 2388:             '  <input type="hidden" name="switchrole" value="" />'."\n";
 2389:         if ($destsymb ne '') {
 2390:             $form .= '   <input type="hidden" name="destsymb" value="'.
 2391:                          &HTML::Entities::encode($destsymb).'" />'."\n";
 2392:         }
 2393:         $form .= '</form>'."\n";
 2394:         foreach my $role (@roles_order) {
 2395:             my $include;
 2396:             if (defined($courseroles{$role})) {
 2397:                 if ($env{'request.role'} =~ m{^\Q$role\E}) {
 2398:                     if ($seccount{$role} > 1) {
 2399:                         $include = 1;
 2400:                     }
 2401:                 } else {
 2402:                     $include = 1;
 2403:                 }
 2404:             }
 2405:             if ($include) {
 2406:                 push(@submenu,['javascript:adhocRole('."'$role'".')',
 2407:                                &Apache::lonnet::plaintext($role,$crstype)]);
 2408:             }
 2409:         }
 2410:         foreach my $role (sort(keys(%courseroles))) {
 2411:             if ($role =~ /^cr/) {
 2412:                 my $include;
 2413:                 if ($env{'request.role'} =~ m{^\Q$role\E}) {
 2414:                     if ($seccount{$role} > 1) {
 2415:                         $include = 1;
 2416:                     }
 2417:                 } else {
 2418:                     $include = 1;
 2419:                 }
 2420:                 if ($include) {
 2421:                     push(@submenu,['javascript:adhocRole('."'$role'".')',
 2422:                                    &Apache::lonnet::plaintext($role)]);
 2423:                 }
 2424:             }
 2425:         }
 2426:         if (@submenu > 0) {
 2427:             $switcher = &create_submenu('','',$switchtext,\@submenu);
 2428:         }
 2429:     }
 2430:     return ($js,$form,$switcher);
 2431: }
 2432: 
 2433: sub get_all_courseroles {
 2434:     my ($cdom,$cnum,$courseroles,$seccount,$courseprivs) = @_;
 2435:     unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH') &&
 2436:             (ref($courseprivs) eq 'HASH')) {
 2437:         return;
 2438:     }
 2439:     my ($result,$cached) = 
 2440:         &Apache::lonnet::is_cached_new('getcourseroles',$cdom.'_'.$cnum);
 2441:     if (defined($cached)) {
 2442:         if (ref($result) eq 'HASH') {
 2443:             if ((ref($result->{'roles'}) eq 'HASH') && 
 2444:                 (ref($result->{'seccount'}) eq 'HASH') && 
 2445:                 (ref($result->{'privs'}) eq 'HASH')) {
 2446:                 %{$courseroles} = %{$result->{'roles'}};
 2447:                 %{$seccount} = %{$result->{'seccount'}};
 2448:                 %{$courseprivs} = %{$result->{'privs'}};
 2449:                 return;
 2450:             }
 2451:         }
 2452:     }
 2453:     my %gotnosection;
 2454:     my %adv_roles =
 2455:          &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
 2456:     foreach my $role (keys(%adv_roles)) {
 2457:         my ($urole,$usec) = split(/:/,$role);
 2458:         if (!$gotnosection{$urole}) {
 2459:             $seccount->{$urole} ++;
 2460:             $gotnosection{$urole} = 1;
 2461:         }
 2462:         if (ref($courseroles->{$urole}) eq 'ARRAY') {
 2463:             if ($usec ne '') {
 2464:                 if (!grep(/^Q$usec\E$/,@{$courseroles->{$urole}})) {
 2465:                     push(@{$courseroles->{$urole}},$usec);
 2466:                     $seccount->{$urole} ++;
 2467:                 }
 2468:             }
 2469:         } else {
 2470:             @{$courseroles->{$urole}} = ();
 2471:             if ($usec ne '') {
 2472:                 $seccount->{$urole} ++;
 2473:                 push(@{$courseroles->{$urole}},$usec);
 2474:             }
 2475:         }
 2476:         my $area = '/'.$cdom.'/'.$cnum;
 2477:         if ($usec ne '') {
 2478:             $area .= '/'.$usec;
 2479:         }
 2480:         if ($role =~ /^cr\//) {
 2481:             &Apache::lonnet::custom_roleprivs($courseprivs,$urole,$cdom,$cnum,$urole.'.'.$area,$area);
 2482:         } else {
 2483:             &Apache::lonnet::standard_roleprivs($courseprivs,$urole,$cdom,$urole.'.'.$area,$cnum,$area);
 2484:         }
 2485:     }
 2486:     my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum,['st']);
 2487:     @{$courseroles->{'st'}} = ();
 2488:     &Apache::lonnet::standard_roleprivs($courseprivs,'st',$cdom,"st./$cdom/$cnum",$cnum,"/$cdom/$cnum");
 2489:     if (keys(%sections_count) > 0) {
 2490:         push(@{$courseroles->{'st'}},keys(%sections_count));
 2491:         $seccount->{'st'} = scalar(keys(%sections_count));
 2492:     }
 2493:     $seccount->{'st'} ++; # Increment for a section-less student role.
 2494:     my $rolehash = {
 2495:                      'roles'    => $courseroles,
 2496:                      'seccount' => $seccount,
 2497:                      'privs'    => $courseprivs,
 2498:                    };
 2499:     &Apache::lonnet::do_cache_new('getcourseroles',$cdom.'_'.$cnum,$rolehash);
 2500:     return;
 2501: }
 2502: 
 2503: sub jump_to_role {
 2504:     my ($cdom,$cnum,$seccount,$courseroles,$courseprivs,$priv) = @_;
 2505:     my %lt = &Apache::lonlocal::texthash(
 2506:                 this => 'This role has section(s) associated with it.',
 2507:                 ente => 'Enter a specific section.',
 2508:                 orlb => 'Enter a specific section, or leave blank for no section.',
 2509:                 avai => 'Available sections are:',
 2510:                 youe => 'You entered an invalid section choice:',
 2511:                 plst => 'Please try again.',
 2512:                 role => 'The role you selected is not permitted to view the current page.',
 2513:                 swit => 'Switch role, but display Main Menu page instead?',
 2514:     );
 2515:     my $js;
 2516:     if (ref($courseroles) eq 'HASH') {
 2517:         $js = '    var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n". 
 2518:               '    var numsec = new Array();'."\n".
 2519:               '    var rolesections = new Array();'."\n".
 2520:               '    var rolenames = new Array();'."\n".
 2521:               '    var roleseclist = new Array();'."\n";
 2522:         my @items = keys(%{$courseroles});
 2523:         for (my $i=0; $i<@items; $i++) {
 2524:             $js .= '    rolenames['.$i.'] = "'.$items[$i].'";'."\n";
 2525:             my ($secs,$secstr);
 2526:             if (ref($courseroles->{$items[$i]}) eq 'ARRAY') {
 2527:                 my @sections = sort { $a <=> $b } @{$courseroles->{$items[$i]}};
 2528:                 $secs = join('","',@sections);
 2529:                 $secstr = join(', ',@sections);
 2530:             }
 2531:             $js .= '    rolesections['.$i.'] = new Array("'.$secs.'");'."\n".
 2532:                    '    roleseclist['.$i.'] = "'.$secstr.'";'."\n".
 2533:                    '    numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n";
 2534:         }
 2535:     }
 2536:     my $checkroles = 0;
 2537:     if ($priv && ref($courseprivs) eq 'HASH') {
 2538:         my (%disallowed,%allowed,@disallow);
 2539:         foreach my $role (sort(keys(%{$courseprivs}))) {
 2540:             my $trole;
 2541:             if ($role =~ m{^(.+?)\Q./$cdom/$cnum\E}) {
 2542:                 $trole = $1;
 2543:             }
 2544:             if (($trole ne '') && ($trole ne 'cm')) {
 2545:                 if ($courseprivs->{$role} =~ /\Q:$priv\E($|:|\&\w+)/) {
 2546:                     $allowed{$trole} = 1;
 2547:                 } else {
 2548:                     $disallowed{$trole} = 1;
 2549:                 }
 2550:             }
 2551:         }
 2552:         foreach my $trole (keys(%disallowed)) {
 2553:             unless ($allowed{$trole}) {
 2554:                 push(@disallow,$trole);
 2555:             }
 2556:         }
 2557:         if (@disallow > 0) {
 2558:             $checkroles = 1;
 2559:             $js .= "    var disallow = new Array('".join("','",@disallow)."');\n".
 2560:                    "    var rolecheck = 1;\n";
 2561:         }
 2562:     }
 2563:     if (!$checkroles) {
 2564:         $js .=  "    var disallow = new Array();\n".
 2565:                 "    rolecheck = 0;\n";
 2566:     }
 2567:     return <<"END";
 2568: <script type="text/javascript">
 2569: //<![CDATA[
 2570: function adhocRole(newrole) {
 2571:     $js
 2572:     if (newrole == '') {
 2573:         return;
 2574:     } 
 2575:     var fullrole = newrole+'./$cdom/$cnum';
 2576:     var selidx = '';
 2577:     for (var i=0; i<rolenames.length; i++) {
 2578:         if (rolenames[i] == newrole) {
 2579:             selidx = i;
 2580:         }
 2581:     }
 2582:     if (rolecheck > 0) {
 2583:         for (var i=0; i<disallow.length; i++) {
 2584:             if (disallow[i] == newrole) {
 2585:                 if (confirm("$lt{'role'}\\n$lt{'swit'}")) {
 2586:                     document.rolechooser.destinationurl.value = '/adm/menu';
 2587:                 } else {
 2588:                     return;
 2589:                 }
 2590:             }
 2591:         }
 2592:     }
 2593:     var secok = 1;
 2594:     var secchoice = '';
 2595:     if (selidx >= 0) {
 2596:         if (numsec[selidx] > 1) {
 2597:             secok = 0;
 2598:             var numrolesec = rolesections[selidx].length;
 2599:             var msgidx = numsec[selidx] - numrolesec;
 2600:             secchoice = prompt("$lt{'this'} "+secpick[msgidx]+"\\n$lt{'avai'} "+roleseclist[selidx],"");
 2601:             if (secchoice == '') {
 2602:                 if (msgidx > 0) {
 2603:                     secok = 1;
 2604:                 }
 2605:             } else {
 2606:                 for (var j=0; j<rolesections[selidx].length; j++) {
 2607:                     if (rolesections[selidx][j] == secchoice) {
 2608:                         secok = 1;
 2609:                     }
 2610:                 }
 2611:             }
 2612:         } else {
 2613:             if (rolesections[selidx].length == 1) {
 2614:                 secchoice = rolesections[selidx][0];
 2615:             }
 2616:         }
 2617:     }
 2618:     if (secok == 1) {
 2619:         if (secchoice != '') {
 2620:             fullrole += '/'+secchoice;
 2621:         }
 2622:     } else {
 2623:         document.rolechooser.elements[roleitem].selectedIndex = 0;
 2624:         if (secchoice != null) {
 2625:             alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}");
 2626:         }
 2627:         return;
 2628:     }
 2629:     if (fullrole == "$env{'request.role'}") {
 2630:         return;
 2631:     }
 2632:     itemid = retrieveIndex('gotorole');
 2633:     if (itemid != -1) {
 2634:         document.rolechooser.elements[itemid].name = fullrole;
 2635:     }
 2636:     document.rolechooser.switchrole.value = fullrole;
 2637:     document.rolechooser.selectrole.value = '1';
 2638:     document.rolechooser.submit();
 2639:     return;
 2640: }
 2641: 
 2642: function retrieveIndex(item) {
 2643:     for (var i=0;i<document.rolechooser.elements.length;i++) {
 2644:         if (document.rolechooser.elements[i].name == item) {
 2645:             return i;
 2646:         }
 2647:     }
 2648:     return -1;
 2649: }
 2650: // ]]>
 2651: </script>
 2652: END
 2653: }
 2654: 
 2655: sub required_privs {
 2656:     my $privs =  {
 2657:              '/adm/parmset'      => 'opa',
 2658:              '/adm/courseprefs'  => 'opa',
 2659:              '/adm/whatsnew'     => 'whn',
 2660:              '/adm/populate'     => 'cst',
 2661:              '/adm/trackstudent' => 'vsa',
 2662:              '/adm/statistics'   => 'vgr',
 2663:              '/adm/setblock'     => 'dcm',
 2664:              '/adm/coursedocs'   => 'mdc',
 2665:            };
 2666:     unless ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'spreadsheet') {
 2667:         $privs->{'/adm/classcalc'}   = 'vgr',
 2668:         $privs->{'/adm/assesscalc'}  = 'vgr',
 2669:         $privs->{'/adm/studentcalc'} = 'vgr';
 2670:     }
 2671:     return $privs;
 2672: }
 2673: 
 2674: sub countdown_timer {
 2675:     if (($env{'request.course.id'}) && ($env{'request.symb'} ne '') &&
 2676:         ($env{'request.filename'}=~/$LONCAPA::assess_re/)) {
 2677:         my ($type,$hastimeleft,$slothastime);
 2678:         my $now = time;
 2679:         if ($env{'request.filename'} =~ /\.task$/) {
 2680:             $type = 'Task';
 2681:         } else {
 2682:             $type = 'problem';
 2683:         }
 2684:         my ($status,$accessmsg,$slot_name,$slot) =
 2685:             &Apache::lonhomework::check_slot_access('0',$type);
 2686:         if ($slot_name ne '') {
 2687:             if (ref($slot) eq 'HASH') {
 2688:                 if (($slot->{'starttime'} < $now) &&
 2689:                     ($slot->{'endtime'} > $now)) {
 2690:                     $slothastime = 1;
 2691:                 }
 2692:             }
 2693:         }
 2694:         if ($status ne 'CAN_ANSWER') {
 2695:             return;
 2696:         }
 2697:         my $duedate = &Apache::lonnet::EXT("resource.0.duedate");
 2698:         my @interval=&Apache::lonnet::EXT("resource.0.interval");
 2699:         if (@interval > 1) {
 2700:             my $first_access=&Apache::lonnet::get_first_access($interval[1]);
 2701:             if ($first_access > 0) {
 2702:                 if ($first_access+$interval[0] > time) {
 2703:                     $hastimeleft = 1;
 2704:                 }
 2705:             }
 2706:         }
 2707:         if (($duedate && $duedate > time) ||
 2708:             (!$duedate && $hastimeleft) ||
 2709:             ($slot_name ne '' && $slothastime)) {
 2710:             my ($collapse,$expand,$alttxt,$title,$currdisp);
 2711:             if ((@interval > 1 && $hastimeleft) ||
 2712:                 ($type eq 'Task' && $slothastime)) {
 2713:                 $currdisp = 'inline';
 2714:                 $collapse = '&#9658;&nbsp;';
 2715:             } else {
 2716:                 $currdisp = 'none';
 2717:                 $expand = '&#9668;&nbsp;';
 2718:             }
 2719:             unless ($env{'environment.icons'} eq 'iconsonly') {
 2720:                 $alttxt = &mt('Timer');
 2721:                 $title = $alttxt.'&nbsp;';
 2722:             }
 2723:             my $desc = &mt('Countdown to due date/time');
 2724:             return <<END;
 2725: 
 2726: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
 2727: <span id="ddcountcollapse" class="LC_menubuttons_inline_text">
 2728: $collapse
 2729: </span></a>
 2730: <span id="duedatecountdown" class="LC_menubuttons_inline_text" style="display: $currdisp;"></span>
 2731: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
 2732: <span id="ddcountexpand" class="LC_menubuttons_inline_text" >$expand</span>
 2733: <img src="/res/adm/pages/timer.png" title="$desc" class="LC_icon" alt="$alttxt" /><span class="LC_menubuttons_inline_text">$title</span></a>
 2734: END
 2735:         }
 2736:     }
 2737:     return;
 2738: }
 2739: 
 2740: # ================================================================ Main Program
 2741: 
 2742: BEGIN {
 2743:     if (! defined($readdesk)) {
 2744:         {
 2745:             my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
 2746:             if ( CORE::open( my $config,"<$tabfile") ) {
 2747:                 while (my $configline=<$config>) {
 2748:                     $configline=(split(/\#/,$configline))[0];
 2749:                     $configline=~s/^\s+//;
 2750:                     chomp($configline);
 2751:                     if ($configline=~/^cat\:/) {
 2752:                         my @entries=split(/\:/,$configline);
 2753:                         $category_positions{$entries[2]}=$entries[1];
 2754:                         $category_names{$entries[2]}=$entries[3];
 2755:                     } elsif ($configline=~/^prim\:/) {
 2756:                         my @entries = (split(/\:/, $configline))[1..6];
 2757:                         push(@primary_menu,\@entries);
 2758:                     } elsif ($configline=~/^primsub\:/) {
 2759:                         my ($parent,@entries) = (split(/\:/, $configline))[1..4];
 2760:                         push(@{$primary_submenu{$parent}},\@entries);
 2761:                     } elsif ($configline=~/^scnd\:/) {
 2762:                         my @entries = (split(/\:/, $configline))[1..5];
 2763:                         push(@secondary_menu,\@entries);
 2764:                     } elsif ($configline=~/^scndsub\:/) {
 2765:                         my ($parent,@entries) = (split(/\:/, $configline))[1..4];
 2766:                         push(@{$secondary_submenu{$parent}},\@entries);
 2767:                     } elsif ($configline) {
 2768:                         push(@desklines,$configline);
 2769:                     }
 2770:                 }
 2771:                 CORE::close($config);
 2772:             }
 2773:         }
 2774:         $readdesk='done';
 2775:     }
 2776: }
 2777: 
 2778: 1;
 2779: __END__
 2780: 

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