File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.488: download - view: text, annotated - select for diffs
Fri Apr 27 20:14:16 2018 UTC (6 years ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Return to Authoring Space or Resource Space after changing user preferences
  for ad hoc co-author role for DCs, and use of CodeMirror.

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

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