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

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

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