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

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

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