File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.465: download - view: text, annotated - select for diffs
Mon Jan 2 19:44:06 2017 UTC (7 years, 5 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Ad hoc roles for helpdesk personnel.
  - Domain configuration for:
    - which user(s) with dh role in domain may use each ad hoc role.
      - set by institutional status, or by include specific people, or by
        exclude specific people.
    - assign role description (displayed on Roles page, and at top left of
      page, when role active).
    - assign role order (numerical).
  - Course configuration (available for editing by course owner, and viewing
    by co-owner(s).
    - can override domain defaults for which dh role users can use ad hoc role(s)
      in course.
    - can override domain defaults set for course-level privileges for ad hoc
      role(s).

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

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