File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.542: download - view: text, annotated - select for diffs
Sun Nov 19 21:28:17 2023 UTC (6 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Available editors in Authoring Space: value set for specific author can
  override domain default.
- Daxe editor page includes "collapsed" standard inline LON-CAPA menus
  (primary, secondary, and Functions). Icons at top left to toggle
  expansion or collapse.

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

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