File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.369.2.83.2.3: download - view: text, annotated - select for diffs
Mon May 30 15:40:15 2022 UTC (2 years ago) by raeburn
Branches: version_2_11_4_msu
Diff to branchpoint 1.369.2.83: preferred, unified
- For 2.11.4 (modified)
  Fix typos in 1.369.2.83.2.2

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

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