File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.528: download - view: text, annotated - select for diffs
Thu Oct 27 20:33:31 2022 UTC (19 months, 1 week ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Sanity checking of value set for $env{'form.folderpath'} before calling
  lonhtmlcommon::docs_breadcrumbs() to create breadcrumbs train when
  displaying resources in Supplemental Content area.

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

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