Annotation of loncom/interface/lonmenu.pm, revision 1.369.2.83.2.20

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

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