File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.469: download - view: text, annotated - select for diffs
Sat Feb 25 19:43:16 2017 UTC (7 years, 2 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Accommodate case where Syllabus is included in Main Content, so $resurl is
  extracted from symb.

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

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