File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.546: download - view: text, annotated - select for diffs
Mon Jan 1 01:22:24 2024 UTC (5 months, 1 week ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Fix typo in 1.543

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

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