File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.534: download - view: text, annotated - select for diffs
Fri Jul 14 00:54:13 2023 UTC (10 months, 3 weeks ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- "Copy" absent from Functions menu for required default.rights file present
  at top level of Course Authoring Space.

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

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