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

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.4 2022/07/08 16:08:05 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.83.2.  (raeburn 1608:):         my $shownsymb;
                   1609:):         if ($env{'request.symb'}) {
                   1610:):             $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
                   1611:):         }
1.369.2.27  raeburn  1612:         $jscall = &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,$switchserver,
1.369.2.83.2.  (raeburn 1613:):                                                 $forceedit,$forcereg,$env{'request.symb'},$shownsymb,
1.369.2.27  raeburn  1614:                                                 &escape($env{'form.folderpath'}),
1.369.2.75  raeburn  1615:                                                 &escape($env{'form.title'}),$hostname,
                   1616:                                                 $env{'form.idx'},&escape($env{'form.suppurl'}),
                   1617:                                                 $env{'form.todocs'},$suppanchor);
1.369.2.27  raeburn  1618:     }
1.369.2.26  raeburn  1619:     if ($jscall) {
                   1620:         my $icon = 'pcstr.png';
                   1621:         my $label = 'Edit';
                   1622:         if ($forceview) {
                   1623:             $icon = 'tolastloc.png';
                   1624:             $label = 'Exit Editing';
                   1625:         }
1.369.2.37  raeburn  1626:         my $infunc = 1;
                   1627:         my $clearbutton;
                   1628:         if ($env{'environment.remote'} eq 'on') {
                   1629:             if ($cfile =~ m{^/priv/}) {
                   1630:                 undef($infunc);
                   1631:                 $label = 'edit';
                   1632:             } else {
                   1633:                 $clearbutton = 1;
                   1634:             }
                   1635:         }
                   1636:         my $editor = &switch('','',6,1,$icon,$label,'resource[_2]',
                   1637:                              $jscall,"Edit this resource",'','',$infunc);
                   1638:         if ($infunc) {
                   1639:             return 1;
                   1640:         } elsif ($clearbutton) {
                   1641:             return &clear(6,1);
                   1642:         } else {
                   1643:             return $editor;
                   1644:         }
1.369.2.26  raeburn  1645:     }
                   1646:     return;
                   1647: }
                   1648: 
                   1649: sub prepare_functions {
1.369.2.75  raeburn  1650:     my ($resurl,$forcereg,$group,$bread_crumbs,$advtools,$docscrumbs,$hostname,$forbodytag) = @_;
1.369.2.26  raeburn  1651:     unless ($env{'request.registered'}) {
                   1652:         undef(@inlineremote);
                   1653:     }
                   1654:     my ($cdom,$cnum,%perms,$cfile,$switchserver,$home,$forceedit,
                   1655:         $forceview);
                   1656: 
                   1657:     if ($env{'request.course.id'}) {
                   1658:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                   1659:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   1660:         $perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
                   1661:     }
                   1662: 
                   1663:     my $editbutton = '';
1.369.2.73  raeburn  1664:     my $viewsrcbutton = '';
1.369.2.83  raeburn  1665:     my $clientip = &Apache::lonnet::get_requestor_ip();
1.369.2.26  raeburn  1666: #
1.369.2.73  raeburn  1667: # Determine whether or not to display 'Edit' or 'View Source' icon/button
1.369.2.26  raeburn  1668: #
                   1669:     if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
1.369.2.83  raeburn  1670:         my $blocked = &Apache::loncommon::blocking_status('about',$clientip,$2,$1);
1.369.2.26  raeburn  1671:         my $file=&Apache::lonnet::declutter($env{'request.filename'});
1.369.2.27  raeburn  1672:         ($cfile,$home,$switchserver,$forceedit,$forceview) =
                   1673:             &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
                   1674:                 &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
1.369.2.83  raeburn  1675:         if (($cfile) && ($home ne '') && ($home ne 'no_host') && (!$blocked)) {
1.369.2.27  raeburn  1676:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
1.369.2.26  raeburn  1677:                                           $forceedit,$forceview,$forcereg);
                   1678:         }
1.369.2.27  raeburn  1679:     } elsif ((!$env{'request.course.id'}) &&
1.369.2.26  raeburn  1680:              ($env{'user.author'}) && ($env{'request.filename'}) &&
                   1681:              ($env{'request.role'} !~/^(aa|ca|au)/)) {
                   1682: #
                   1683: # Currently do not have the role of author or co-author.
                   1684: # Do we have authoring privileges for the resource?
                   1685: #
                   1686:         my $file=&Apache::lonnet::declutter($env{'request.filename'});
                   1687:         ($cfile,$home,$switchserver,$forceedit,$forceview) =
                   1688:             &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
                   1689:                 &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
                   1690:         if (($cfile) && ($home ne '') && ($home ne 'no_host')) {
                   1691:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
                   1692:                                           $forceedit,$forceview,$forcereg);
                   1693:         }
                   1694:     } elsif ($env{'request.course.id'}) {
                   1695: #
                   1696: # This applies in course context
                   1697: #
1.369.2.39  raeburn  1698:         if (($perms{'mdc'}) &&
1.369.2.70  raeburn  1699:             (($resurl =~ m{^/?public/$cdom/$cnum/syllabus}) ||
1.369.2.78  raeburn  1700:             ($resurl =~ m{^/?uploaded/$cdom/$cnum/portfolio/syllabus/}) || 
                   1701:             (($resurl =~ m{^/?uploaded/$cdom/$cnum/default_\d+\.sequence$}) && ($env{'form.navmap'})))) {
1.369.2.71  raeburn  1702:             if ($resurl =~ m{^/}) {
                   1703:                 $cfile = $resurl;
                   1704:             } else {
                   1705:                 $cfile = "/$resurl";
                   1706:             }
1.369.2.39  raeburn  1707:             $home = &Apache::lonnet::homeserver($cnum,$cdom);
                   1708:             if ($env{'form.forceedit'}) {
                   1709:                 $forceview = 1;
1.369.2.26  raeburn  1710:             } else {
1.369.2.39  raeburn  1711:                 $forceedit = 1;
1.369.2.26  raeburn  1712:             }
1.369.2.78  raeburn  1713:             if ($cfile =~ m{^/uploaded/$cdom/$cnum/default_\d+\.sequence$}) {
                   1714:                 my $text = 'Edit Folder';
                   1715:                 &switch('','',7,4,'docs-22x22.png','Edit Folder','parms[_2]',
                   1716:                         "gocmd('/adm/coursedocs','direct')",
                   1717:                         'Folder/Page Content');
                   1718:                 $editbutton = 1;
                   1719:             } else {
                   1720:                 $editbutton = &get_editbutton($cfile,$home,$switchserver,
                   1721:                                               $forceedit,$forceview,$forcereg,
                   1722:                                               $hostname);
                   1723:             }
1.369.2.27  raeburn  1724:         } elsif (($resurl eq '/adm/extresedit') &&
                   1725:                  (($env{'form.symb'}) || ($env{'form.folderpath'}))) {
                   1726:             ($cfile,$home,$switchserver,$forceedit,$forceview) =
                   1727:             &Apache::lonnet::can_edit_resource($resurl,$cnum,$cdom,$resurl,
                   1728:                                                $env{'form.symb'});
                   1729:             if ($cfile ne '') {
                   1730:                 $editbutton = &get_editbutton($cfile,$home,$switchserver,
                   1731:                                               $forceedit,$forceview,$forcereg,
                   1732:                                               $env{'form.title'},$env{'form.suppurl'});
                   1733:             }
1.369.2.32  raeburn  1734:         } elsif (($resurl =~ m{^/?adm/viewclasslist$}) &&
                   1735:                  (&Apache::lonnet::allowed('opa',$env{'request.course.id'}))) {
                   1736:             ($cfile,$home,$switchserver,$forceedit,$forceview) =
                   1737:             &Apache::lonnet::can_edit_resource($resurl,$cnum,$cdom,$resurl,
                   1738:                                                $env{'form.symb'});
                   1739:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
                   1740:                                           $forceedit,$forceview,$forcereg);
1.369.2.31  raeburn  1741:         } elsif (($resurl !~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) &&
                   1742:                  ($resurl ne '/cgi-bin/printout.pl')) {
1.369.2.26  raeburn  1743:             if ($env{'request.filename'}) {
                   1744:                 my $file=&Apache::lonnet::declutter($env{'request.filename'});
                   1745:                 ($cfile,$home,$switchserver,$forceedit,$forceview) =
                   1746:                     &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
                   1747:                         &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
                   1748:                 if ($cfile ne '') {
                   1749:                     $editbutton = &get_editbutton($cfile,$home,$switchserver,
                   1750:                                                   $forceedit,$forceview,$forcereg);
                   1751:                 }
1.369.2.73  raeburn  1752:                 if ((($cfile eq '') || (!$editbutton)) &&
                   1753:                     ($resurl =~ /$LONCAPA::assess_re/)) {
                   1754:                     my $showurl = &Apache::lonnet::clutter($resurl);
1.369.2.80  raeburn  1755:                     my $crs_sec = $env{'request.course.id'} . (($env{'request.course.sec'} ne '')
                   1756:                                                               ? "/$env{'request.course.sec'}"
                   1757:                                                               : '');
1.369.2.73  raeburn  1758:                     if ((&Apache::lonnet::allowed('cre','/')) &&
                   1759:                         (&Apache::lonnet::metadata($resurl,'sourceavail') eq 'open')) {
                   1760:                         $viewsrcbutton = 1;
1.369.2.80  raeburn  1761:                     } elsif (&Apache::lonnet::allowed('vxc',$crs_sec)) {
1.369.2.73  raeburn  1762:                         if ($showurl =~ m{^\Q/res/$cdom/\E($match_username)/}) {
                   1763:                             my $auname = $1;
                   1764:                             if (($env{'request.course.adhocsrcaccess'} ne '') &&
                   1765:                                 (grep(/^\Q$auname\E$/,split(/,/,$env{'request.course.adhocsrcaccess'})))) {
                   1766:                                 $viewsrcbutton = 1;
                   1767:                             } elsif ((&Apache::lonnet::metadata($resurl,'sourceavail') eq 'open') &&
1.369.2.80  raeburn  1768:                                      (&Apache::lonnet::allowed('bre',$crs_sec))) {
1.369.2.73  raeburn  1769:                                 $viewsrcbutton = 1;
                   1770:                             }
                   1771:                         }
                   1772:                     }
                   1773:                     if ($viewsrcbutton) {
                   1774:                         &switch('','',6,1,'pcstr.png','View Source','resource[_2]','open_source()',
                   1775:                                 'View source code');
                   1776:                     }
                   1777:                 }
1.369.2.26  raeburn  1778:             }
                   1779:         }
                   1780:     }
                   1781: # End determination of 'Edit' icon/button display
                   1782: 
                   1783:     if ($env{'request.course.id'}) {
1.369.2.27  raeburn  1784: # This applies to about me page for users in a course
1.369.2.29  raeburn  1785:         if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
1.369.2.26  raeburn  1786:             my ($sdom,$sname) = ($1,$2);
                   1787:             unless (&Apache::lonnet::is_course($sdom,$sname)) {
1.369.2.83  raeburn  1788:                 my $blocked = &Apache::loncommon::blocking_status('about',$clientip,$sname,$sdom);
                   1789:                 unless ($blocked) {
                   1790:                     &switch('','',6,4,'mail-message-new-22x22.png','Message to user',
                   1791:                             '',
                   1792:                             "go('/adm/email?compose=individual&amp;recname=$sname&amp;recdom=$sdom')",
                   1793:                                 'Send message to specific user','','',1);
                   1794:                 }
1.369.2.26  raeburn  1795:             }
1.369.2.27  raeburn  1796:             my $hideprivileged = 1;
                   1797:             if (&Apache::lonnet::in_course($sdom,$sname,$cdom,$cnum,undef,
                   1798:                                            $hideprivileged)) {
1.369.2.26  raeburn  1799:                 foreach my $priv ('vsa','vgr','srm') {
                   1800:                     $perms{$priv} = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
                   1801:                     if (!$perms{$priv} && $env{'request.course.sec'} ne '') {
                   1802:                         $perms{$priv} =
                   1803:                             &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
                   1804:                     }
                   1805:                 }
                   1806:                 if ($perms{'vsa'}) {
                   1807:                     &switch('','',6,5,'trck-22x22.png','Activity',
                   1808:                             '',
                   1809:                             "go('/adm/trackstudent?selected_student=$sname:$sdom')",
1.369.2.37  raeburn  1810:                             'View recent activity by this person','','',1);
1.369.2.26  raeburn  1811:                 }
                   1812:                 if ($perms{'vgr'}) {
                   1813:                     &switch('','',6,6,'rsrv-22x22.png','Reservations',
                   1814:                             '',
1.369.2.42  raeburn  1815:                             "go('/adm/slotrequest?command=showresv&amp;origin=aboutme&amp;uname=$sname&amp;udom=$sdom')",
1.369.2.37  raeburn  1816:                             'Slot reservation history','','',1);
1.369.2.26  raeburn  1817:                 }
                   1818:                 if ($perms{'srm'}) {
                   1819:                     &switch('','',6,7,'contact-new-22x22.png','Records',
                   1820:                             '',
1.369.2.42  raeburn  1821:                             "go('/adm/email?recordftf=retrieve&amp;recname=$sname&amp;recdom=$sdom')",
1.369.2.37  raeburn  1822:                             'Add records','','',1);
1.369.2.26  raeburn  1823:                 }
                   1824:             }
1.369.2.27  raeburn  1825:         }
                   1826:         if (($env{'form.folderpath'} =~ /^supplemental/) &&
                   1827:             (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) &&
                   1828:             (($resurl =~ m{^/adm/wrapper/ext/}) ||
1.369.2.83.2.  (raeburn 1829:):              ($resurl =~ m{^/adm/$cdom/$cnum/\d+/ext\.tool$}) ||
1.369.2.27  raeburn  1830:              ($resurl =~ m{^/uploaded/$cdom/$cnum/supplemental/}) ||
                   1831:              ($resurl eq '/adm/supplemental') ||
                   1832:              ($resurl =~ m{^/public/$cdom/$cnum/syllabus$}) ||
                   1833:              ($resurl =~ m{^/adm/$match_domain/$match_username/aboutme$}))) {
                   1834:             my @folders=split('&',$env{'form.folderpath'});
                   1835:             if ((@folders > 2) || ($resurl ne '/adm/supplemental')) {
1.369.2.64  raeburn  1836:                 my $suppanchor;
                   1837:                 if ($resurl =~ m{^/adm/wrapper/ext/}) {
                   1838:                     $suppanchor = $env{'form.anchor'};
                   1839:                 }
1.369.2.27  raeburn  1840:                 my $esc_path=&escape(&HTML::Entities::encode(&escape($env{'form.folderpath'}),'<>&"'));
1.369.2.75  raeburn  1841:                 my $link = '/adm/coursedocs?command=direct&amp;forcesupplement=1&amp;supppath='.
                   1842:                            "$esc_path&amp;anchor=$suppanchor";
                   1843:                 if ($env{'request.use_absolute'} ne '') {
                   1844:                     $link = $env{'request.use_absolute'}.$link;
                   1845:                 }
1.369.2.27  raeburn  1846:                 &switch('','',7,4,'docs-22x22.png','Edit Folder','parms[_2]',
1.369.2.75  raeburn  1847:                         "location.href='$link'",'Folder/Page Content');
1.369.2.27  raeburn  1848:             }
1.369.2.26  raeburn  1849:         }
                   1850:     }
                   1851: 
                   1852: # End checking for items for about me page for users in a course
1.369.2.27  raeburn  1853:     if ($docscrumbs) {
                   1854:         &Apache::lonhtmlcommon::clear_breadcrumb_tools();
                   1855:         &advtools_crumbs(@inlineremote);
                   1856:         return $editbutton;
1.369.2.37  raeburn  1857:     } elsif (($env{'request.registered'}) && (!ref($forbodytag))) {
1.369.2.79  raeburn  1858:         return $editbutton || $viewsrcbutton;
1.369.2.26  raeburn  1859:     } else {
                   1860:         if (ref($bread_crumbs) eq 'ARRAY') {
                   1861:             if (@inlineremote > 0) {
                   1862:                 if (ref($advtools) eq 'ARRAY') {
                   1863:                     @{$advtools} = @inlineremote;
                   1864:                 }
                   1865:             }
                   1866:             return;
                   1867:         } elsif (@inlineremote > 0) {
                   1868:             &Apache::lonhtmlcommon::clear_breadcrumb_tools();
                   1869:             &advtools_crumbs(@inlineremote);
1.369.2.37  raeburn  1870:             if (ref($forbodytag)) {
                   1871:                 $$forbodytag =
                   1872:                     &Apache::lonhtmlcommon::scripttag('', 'start')
                   1873:                    .&Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
                   1874:                    .&Apache::lonhtmlcommon::scripttag('', 'end');
                   1875:             }
                   1876:             return;
1.369.2.26  raeburn  1877:         }
                   1878:     }
                   1879: }
                   1880: 
                   1881: sub advtools_crumbs {
                   1882:     my @funcs = @_;
                   1883:     if ($env{'request.noversionuri'} =~ m{^/adm/$match_domain/$match_username/aboutme$}) {
                   1884:         &Apache::lonhtmlcommon::add_breadcrumb_tool(
                   1885:             'advtools', @funcs[61,64,65,66,67,74]);
                   1886:     } elsif ($env{'request.noversionuri'} !~ m{^/adm/(navmaps|viewclasslist)(\?|$)}) {
                   1887:         &Apache::lonhtmlcommon::add_breadcrumb_tool(
                   1888:             'advtools', @funcs[61,71,72,73,74,92]);
1.369.2.27  raeburn  1889:     } elsif ($env{'request.noversionuri'} eq '/adm/viewclasslist') {
                   1890:         &Apache::lonhtmlcommon::add_breadcrumb_tool(
1.369.2.33  raeburn  1891:             'advtools', $funcs[61]);
1.369.2.26  raeburn  1892:     }
                   1893: }
1.369.2.1  raeburn  1894: 
1.2       www      1895: # ================================================================== Raw Config
                   1896: 
1.3       www      1897: sub clear {
                   1898:     my ($row,$col)=@_;
1.369.2.17  raeburn  1899:     if ($env{'environment.remote'} eq 'on') {
                   1900:        if (($row<1) || ($row>13)) { return ''; }
                   1901:        return "\n".qq(window.status+='.';swmenu.clearbut($row,$col););
                   1902:     } else {
                   1903:         $inlineremote[10*$row+$col]='';
                   1904:         return '';
                   1905:     }
1.3       www      1906: }
                   1907: 
1.40      www      1908: # ============================================ Switch a button or create a link
1.25      matthew  1909: # Switch acts on the javascript that is executed when a button is clicked.  
                   1910: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
1.40      www      1911: 
1.2       www      1912: sub switch {
1.369.2.37  raeburn  1913:     my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak,$infunc)=@_;
1.2       www      1914:     $act=~s/\$uname/$uname/g;
                   1915:     $act=~s/\$udom/$udom/g;
1.88      www      1916:     $top=&mt($top);
                   1917:     $bot=&mt($bot);
                   1918:     $desc=&mt($desc);
1.209     www      1919:     my $idx=10*$row+$col;
                   1920:     $category_members{$cat}.=':'.$idx;
                   1921: 
1.369.2.37  raeburn  1922:     if (($env{'environment.remote'} eq 'on') && (!$infunc)) {
1.369.2.17  raeburn  1923:         if (($row<1) || ($row>13)) { return ''; }
1.369.2.21  raeburn  1924:         if ($env{'request.state'} eq 'construct') {
                   1925:             my $text = $top.' '.$bot;
                   1926:             $text=~s/\s*\-\s*//gs;
                   1927:             my $pic = '<img alt="'.$text.'" src="'.
                   1928:                       &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
                   1929:                       '" align="'.($nobreak==3?'right':'left').'" class="LC_icon" />';
                   1930:            $inlineremote[$idx] =
                   1931:                '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.
                   1932:                $pic.'<span class="LC_menubuttons_inline_text">'.$top.'&nbsp;</span></a>';
                   1933:         }
1.369.2.17  raeburn  1934: # Remote
                   1935:         $img=~s/\.png$/\.gif/;
                   1936:         return "\n".
                   1937:  qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
                   1938:     }
                   1939: 
1.320     droeschl 1940: # Inline Menu
1.317     droeschl 1941:     if ($nobreak==2) { return ''; }
                   1942:     my $text=$top.' '.$bot;
                   1943:     $text=~s/\s*\-\s*//gs;
1.105     www      1944: 
1.317     droeschl 1945:     my $pic=
1.225     albertel 1946: 	   '<img alt="'.$text.'" src="'.
                   1947: 	   &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
1.303     droeschl 1948: 	   '" align="'.($nobreak==3?'right':'left').'" class="LC_icon" />';
1.317     droeschl 1949:     if ($env{'browser.interface'} eq 'faketextual') {
1.274     www      1950: # Main Menu
1.103     www      1951: 	   if ($nobreak==3) {
1.209     www      1952: 	       $inlineremote[$idx]="\n".
1.177     albertel 1953: 		   '<td class="LC_menubuttons_text" align="right">'.$text.
1.247     harmsja  1954: 		   '</td><td align="left">'.
1.103     www      1955: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
                   1956: 	   } elsif ($nobreak) {
1.209     www      1957: 	       $inlineremote[$idx]="\n<tr>".
1.247     harmsja  1958: 		   '<td align="left">'.
1.177     albertel 1959: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td>
1.215     www      1960:                     <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      1961: 	   } else {
1.209     www      1962: 	       $inlineremote[$idx]="\n<tr>".
1.247     harmsja  1963: 		   '<td align="left">'.
1.103     www      1964: 		   '<a href="javascript:'.$act.';">'.$pic.
1.177     albertel 1965: 		   '</a></td><td class="LC_menubuttons_text" colspan="3">'.
1.215     www      1966: 		   '<a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$desc.'</span></a></td></tr>';
1.103     www      1967: 	   }
1.317     droeschl 1968:     } else {
1.103     www      1969: # Inline Menu
1.369.2.10  raeburn  1970:         my @tools = (93,91,81,82,83);
                   1971:         unless ($env{'request.state'} eq 'construct') {
                   1972:             push(@tools,63);
                   1973:         }
                   1974:         if (($env{'environment.icons'} eq 'iconsonly') &&
                   1975:             (grep(/^$idx$/,@tools))) {
                   1976:             $inlineremote[$idx] =
                   1977:         '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.'</a>';
                   1978:         } else {
                   1979:             $inlineremote[$idx] =
1.317     droeschl 1980:        '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.
1.344     www      1981:        '<span class="LC_menubuttons_inline_text">'.$top.'&nbsp;</span></a>';
1.369.2.10  raeburn  1982:         }
1.317     droeschl 1983:     }
1.56      www      1984:     return '';
1.2       www      1985: }
                   1986: 
                   1987: sub secondlevel {
                   1988:     my $output='';
                   1989:     my 
1.209     www      1990:     ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_;
1.2       www      1991:     if ($prt eq 'any') {
1.209     www      1992: 	   $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1993:     } elsif ($prt=~/^r(\w+)/) {
                   1994:         if ($rol eq $1) {
1.209     www      1995:            $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1996:         }
                   1997:     }
                   1998:     return $output;
                   1999: }
                   2000: 
1.369.2.17  raeburn  2001: sub openmenu {
                   2002:     my $menuname = &get_menu_name();
                   2003:     unless ($env{'environment.remote'} eq 'on') { return ''; }
                   2004:     my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
                   2005:     return "window.open(".$nothing.",'".$menuname."');";
                   2006: }
                   2007: 
1.56      www      2008: sub inlinemenu {
1.210     albertel 2009:     undef(@inlineremote);
                   2010:     undef(%category_members);
1.275     www      2011: # calling rawconfig with "1" will evaluate mydesk.tab, even if there is no active remote control
1.56      www      2012:     &rawconfig(1);
1.309     bisitz   2013:     my $output='<table><tr>';
1.209     www      2014:     for (my $col=1; $col<=2; $col++) {
1.241     riegler  2015:         $output.='<td class="LC_mainmenu_col_fieldset">';
1.209     www      2016:         for (my $row=1; $row<=8; $row++) {
                   2017:             foreach my $cat (keys(%category_members)) {
                   2018:                if ($category_positions{$cat} ne "$col,$row") { next; }
1.247     harmsja  2019:                #$output.='<table><tr><td colspan="4" class="LC_menubuttons_category">'.&mt($category_names{$cat}).'</td></tr>';
1.309     bisitz   2020:                $output.='<div class="LC_Box LC_400Box">';
                   2021: 	       $output.='<h3 class="LC_hcell">'.&mt($category_names{$cat}).'</h3>';
1.247     harmsja  2022:                $output.='<table>';
1.240     riegler  2023:                my %active=();
                   2024:                foreach my $menu_item (split(/\:/,$category_members{$cat})) {
                   2025:                   if ($inlineremote[$menu_item]) {
                   2026:                      $active{$menu_item}=1;
                   2027:                   }
                   2028:                }  
                   2029:                foreach my $item (sort(keys(%active))) {
                   2030:                   $output.=$inlineremote[$item];
                   2031:                }
                   2032:                $output.='</table>';
1.245     harmsja  2033:                $output.='</div>';
1.240     riegler  2034:             }
                   2035:          }
                   2036:          $output.="</td>";
                   2037:     }
                   2038:     $output.="</tr></table>";
                   2039:     return $output;
                   2040: }
                   2041: 
1.2       www      2042: sub rawconfig {
1.274     www      2043: #
                   2044: # This evaluates mydesk.tab
                   2045: # Need to add more positions and more privileges to deal with all
                   2046: # menu items.
                   2047: #
1.34      www      2048:     my $textualoverride=shift;
                   2049:     my $output='';
1.369.2.17  raeburn  2050:     if ($env{'environment.remote'} eq 'on') {
                   2051:        $output.=
                   2052:  "window.status='Opening Remote Control';var swmenu=".&openmenu().
                   2053: "\nwindow.status='Configuring Remote Control ';";
                   2054:     } else {
                   2055:         unless ($textualoverride) { return ''; }
                   2056:     }
1.152     albertel 2057:     my $uname=$env{'user.name'};
                   2058:     my $udom=$env{'user.domain'};
                   2059:     my $adv=$env{'user.adv'};
1.266     raeburn  2060:     my $show_course=&Apache::loncommon::show_course();
1.152     albertel 2061:     my $author=$env{'user.author'};
1.5       www      2062:     my $crs='';
1.295     raeburn  2063:     my $crstype='';
1.152     albertel 2064:     if ($env{'request.course.id'}) {
                   2065:        $crs='/'.$env{'request.course.id'};
                   2066:        if ($env{'request.course.sec'}) {
                   2067: 	   $crs.='_'.$env{'request.course.sec'};
1.7       www      2068:        }
1.8       www      2069:        $crs=~s/\_/\//g;
1.295     raeburn  2070:        $crstype = &Apache::loncommon::course_type();
1.5       www      2071:     }
1.152     albertel 2072:     my $pub=($env{'request.state'} eq 'published');
                   2073:     my $con=($env{'request.state'} eq 'construct');
                   2074:     my $rol=$env{'request.role'};
1.369.2.51  raeburn  2075:     my $requested_domain;
                   2076:     if ($rol) {
                   2077:        $requested_domain = $env{'request.role.domain'};
                   2078:     }
1.184     raeburn  2079:     foreach my $line (@desklines) {
1.209     www      2080:         my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
1.3       www      2081:         $prt=~s/\$uname/$uname/g;
                   2082:         $prt=~s/\$udom/$udom/g;
1.295     raeburn  2083:         if ($prt =~ /\$crs/) {
                   2084:             next unless ($env{'request.course.id'});
                   2085:             next if ($crstype eq 'Community');
                   2086:             $prt=~s/\$crs/$crs/g;
                   2087:         } elsif ($prt =~ /\$cmty/) {
                   2088:             next unless ($env{'request.course.id'});
                   2089:             next if ($crstype ne 'Community');
                   2090:             $prt=~s/\$cmty/$crs/g;
                   2091:         }
1.369.2.51  raeburn  2092:         if ($prt =~ m/\$requested_domain/) {
                   2093:             if ((!$requested_domain) && ($pro eq 'pbre') && ($env{'user.adv'})) {
                   2094:                 $prt=~s/\$requested_domain/$env{'user.domain'}/g;
                   2095:             } else {
                   2096:                 $prt=~s/\$requested_domain/$requested_domain/g;
                   2097:             }
                   2098:         }
1.211     www      2099:         if ($category_names{$cat}!~/\w/) { $cat='oth'; }
1.3       www      2100:         if ($pro eq 'clear') {
1.4       www      2101: 	    $output.=&clear($row,$col);
1.3       www      2102:         } elsif ($pro eq 'any') {
1.2       www      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: 	} elsif ($pro eq 'smp') {
                   2106:             unless ($adv) {
                   2107:                $output.=&secondlevel(
1.209     www      2108:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2       www      2109:             }
                   2110:         } elsif ($pro eq 'adv') {
                   2111:             if ($adv) {
                   2112:                $output.=&secondlevel(
1.209     www      2113: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2       www      2114:             }
1.231     albertel 2115: 	} elsif ($pro eq 'shc') {
                   2116:             if ($show_course) {
                   2117:                $output.=&secondlevel(
                   2118:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
                   2119:             }
                   2120:         } elsif ($pro eq 'nsc') {
                   2121:             if (!$show_course) {
                   2122:                $output.=&secondlevel(
                   2123: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
                   2124:             }
1.81      matthew  2125:         } elsif (($pro=~/^p(\w+)/) && ($prt)) {
1.295     raeburn  2126:             my $priv = $1;
                   2127:             if ($priv =~ /^mdc(Course|Community)/) {
                   2128:                 if ($crstype eq $1) {
                   2129:                     $priv = 'mdc';
                   2130:                 } else {
                   2131:                     next;
                   2132:                 }
                   2133:             }
1.369.2.51  raeburn  2134:             if ((($priv eq 'bre') && (&Apache::lonnet::allowed($priv,$prt) eq 'F')) ||
                   2135:                 (($priv ne 'bre') && (&Apache::lonnet::allowed($priv,$prt)))) {
                   2136:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.4       www      2137:             }
1.295     raeburn  2138:         } elsif ($pro eq 'course')  {
                   2139:             if (($env{'request.course.fn'}) && ($crstype ne 'Community')) {
1.209     www      2140:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.81      matthew  2141: 	    }
1.295     raeburn  2142:         } elsif ($pro eq 'community')  {
                   2143:             if (($env{'request.course.fn'}) && ($crstype eq 'Community')) {
                   2144:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
                   2145:             }
1.124     matthew  2146:         } elsif ($pro =~ /^courseenv_(.*)$/) {
                   2147:             my $key = $1;
1.307     raeburn  2148:             if ($crstype ne 'Community') {
                   2149:                 my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
                   2150:                 if ($key eq 'canuse_pdfforms') {
                   2151:                     if ($env{'request.course.id'} && $coursepref eq '') {
                   2152:                         my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
                   2153:                         $coursepref = $domdefs{'canuse_pdfforms'};
                   2154:                     }
                   2155:                 }
                   2156:                 if ($coursepref) { 
                   2157:                     $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
                   2158:                 }
1.295     raeburn  2159:             }
                   2160:         } elsif ($pro =~ /^communityenv_(.*)$/) {
                   2161:             my $key = $1;
1.307     raeburn  2162:             if ($crstype eq 'Community') {
                   2163:                 my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
                   2164:                 if ($key eq 'canuse_pdfforms') {
                   2165:                     if ($env{'request.course.id'} && $coursepref eq '') {
                   2166:                         my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
                   2167:                         $coursepref = $domdefs{'canuse_pdfforms'};
                   2168:                     }
                   2169:                 }
                   2170:                 if ($coursepref) { 
                   2171:                     $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
                   2172:                 }
1.124     matthew  2173:             }
1.81      matthew  2174:         } elsif ($pro =~ /^course_(.*)$/) {
                   2175:             # Check for permissions inside of a course
1.295     raeburn  2176:             if (($env{'request.course.id'}) && ($crstype ne 'Community') && 
1.152     albertel 2177:                 (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
                   2178:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
1.81      matthew  2179:                  )) {
1.209     www      2180:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.26      www      2181: 	    }
1.295     raeburn  2182:         } elsif ($pro =~ /^community_(.*)$/) {
                   2183:             # Check for permissions inside of a community
                   2184:             if (($env{'request.course.id'}) && ($crstype eq 'Community') &&   
                   2185:                 (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
                   2186:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
                   2187:                  )) {
                   2188:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
                   2189:             }
1.4       www      2190:         } elsif ($pro eq 'author') {
                   2191:             if ($author) {
1.152     albertel 2192:                 if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
1.234     raeburn  2193:                     (($prt eq 'raa') && ($env{'request.role'}=~/^aa/)) || 
1.152     albertel 2194:                     (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
1.19      matthew  2195:                     # Check that we are on the correct machine
1.29      matthew  2196:                     my $cadom=$requested_domain;
1.152     albertel 2197:                     my $caname=$env{'user.name'};
1.234     raeburn  2198:                     if (($prt eq 'rca') || ($prt eq 'raa')) {
1.29      matthew  2199: 		       ($cadom,$caname)=
1.206     albertel 2200:                                ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.29      matthew  2201:                     }                       
                   2202:                     $act =~ s/\$caname/$caname/g;
1.353     www      2203:                     $act =~ s/\$cadom/$cadom/g;
1.19      matthew  2204:                     my $home = &Apache::lonnet::homeserver($caname,$cadom);
1.109     albertel 2205: 		    my $allowed=0;
                   2206: 		    my @ids=&Apache::lonnet::current_machine_ids();
                   2207: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                   2208: 		    if ($allowed) {
1.209     www      2209:                         $output.=&switch($caname,$cadom,
                   2210:                                         $row,$col,$img,$top,$bot,$act,$desc,$cat);
1.19      matthew  2211:                     }
1.6       www      2212:                 }
1.2       www      2213:             }
1.248     raeburn  2214:         } elsif ($pro eq 'tools') {
                   2215:             my @tools = ('aboutme','blog','portfolio');
                   2216:             if (grep(/^\Q$prt\E$/,@tools)) {
1.249     raeburn  2217:                 if (!&Apache::lonnet::usertools_access($env{'user.name'},
1.251     raeburn  2218:                                                        $env{'user.domain'},
                   2219:                                                        $prt,undef,'tools')) {
                   2220:                     $output.=&clear($row,$col);
                   2221:                     next;
                   2222:                 }
1.278     raeburn  2223:             } elsif (($prt eq 'reqcrsnsc') || ($prt eq 'reqcrsshc')) {
                   2224:                 if (($prt eq 'reqcrsnsc') && ($show_course))   {
                   2225:                     next;
                   2226:                 }
                   2227:                 if (($prt eq 'reqcrsshc') && (!$show_course)) {
                   2228:                     next;
                   2229:                 }
1.279     raeburn  2230:                 my $showreqcrs = &check_for_rcrs();
1.251     raeburn  2231:                 if (!$showreqcrs) {
1.248     raeburn  2232:                     $output.=&clear($row,$col);
                   2233:                     next;
                   2234:                 }
                   2235:             }
                   2236:             $prt='any';
                   2237:             $output.=&secondlevel(
                   2238:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2       www      2239:         }
1.13      harris41 2240:     }
1.369.2.17  raeburn  2241:     if ($env{'environment.remote'} eq 'on') {
                   2242:         $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
                   2243:         if (&Apache::lonmsg::newmail()) {
                   2244:             $output.='swmenu.setstatus("you have","messages");';
                   2245:         }
                   2246:     }
1.2       www      2247:     return $output;
                   2248: }
                   2249: 
1.279     raeburn  2250: sub check_for_rcrs {
                   2251:     my $showreqcrs = 0;
1.369.2.49  raeburn  2252:     my @reqtypes = ('official','unofficial','community','textbook');
1.280     raeburn  2253:     foreach my $type (@reqtypes) {
1.279     raeburn  2254:         if (&Apache::lonnet::usertools_access($env{'user.name'},
                   2255:                                               $env{'user.domain'},
                   2256:                                               $type,undef,'requestcourses')) {
                   2257:             $showreqcrs = 1;
                   2258:             last;
                   2259:         }
                   2260:     }
1.280     raeburn  2261:     if (!$showreqcrs) {
                   2262:         foreach my $type (@reqtypes) {
                   2263:             if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
                   2264:                 $showreqcrs = 1;
                   2265:                 last;
                   2266:             }
                   2267:         }
                   2268:     }
1.279     raeburn  2269:     return $showreqcrs;
                   2270: }
                   2271: 
1.369.2.1  raeburn  2272: # ======================================================================= Close
                   2273: 
                   2274: sub close {
1.369.2.17  raeburn  2275:     unless ($env{'environment.remote'} eq 'on') { return ''; }
1.369.2.1  raeburn  2276:     my $menuname = &get_menu_name();
                   2277:     return(<<ENDCLOSE);
                   2278: <script type="text/javascript">
                   2279: // <![CDATA[
                   2280: window.status='Accessing Remote Control';
                   2281: menu=window.open("/adm/rat/empty.html","$menuname",
                   2282:                  "height=350,width=150,scrollbars=no,menubar=no");
                   2283: window.status='Disabling Remote Control';
                   2284: menu.active=0;
                   2285: menu.autologout=0;
                   2286: window.status='Closing Remote Control';
                   2287: menu.close();
                   2288: window.status='Done.';
                   2289: // ]]>
                   2290: </script>
                   2291: ENDCLOSE
                   2292: }
                   2293: 
1.306     raeburn  2294: sub dc_popup_js {
                   2295:     my %lt = &Apache::lonlocal::texthash(
                   2296:                                           more => '(More ...)',
                   2297:                                           less => '(Less ...)',
                   2298:                                         );
                   2299:     return <<"END";
                   2300: 
                   2301: function showCourseID() {
                   2302:     document.getElementById('dccid').style.display='block';
                   2303:     document.getElementById('dccid').style.textAlign='left';
1.307     raeburn  2304:     document.getElementById('dccid').style.textFace='normal';
1.369     raeburn  2305:     document.getElementById('dccidtext').innerHTML ='<a href="javascript:hideCourseID();" class="LC_menubuttons_link">$lt{'less'}</a>';
1.306     raeburn  2306:     return;
                   2307: }
                   2308: 
                   2309: function hideCourseID() {
                   2310:     document.getElementById('dccid').style.display='none';
1.369     raeburn  2311:     document.getElementById('dccidtext').innerHTML ='<a href="javascript:showCourseID()" class="LC_menubuttons_link">$lt{'more'}</a>';
1.306     raeburn  2312:     return;
                   2313: }
                   2314: 
                   2315: END
                   2316: 
                   2317: }
                   2318: 
1.369.2.10  raeburn  2319: sub countdown_toggle_js {
                   2320:     return <<"END";
                   2321: 
                   2322: function toggleCountdown() {
                   2323:     var countdownid = document.getElementById('duedatecountdown');
                   2324:     var currstyle = countdownid.style.display;
                   2325:     if (currstyle == 'inline') {
                   2326:         countdownid.style.display = 'none';
                   2327:         document.getElementById('ddcountcollapse').innerHTML='';
                   2328:         document.getElementById('ddcountexpand').innerHTML='&#9668;&nbsp;';
                   2329:     } else {
                   2330:         countdownid.style.display = 'inline';
                   2331:         document.getElementById('ddcountcollapse').innerHTML='&#9658;&nbsp;';
                   2332:         document.getElementById('ddcountexpand').innerHTML='';
                   2333:     }
                   2334:     return;
                   2335: }
                   2336: 
                   2337: END
                   2338: }
                   2339: 
1.369.2.83.2.  (raeburn 2340:): # This creates a "done button" for timed events.  The confirmation box is a jQuery
                   2341:): # dialog widget. If the interval parameter requires a proctor key for the timed
                   2342:): # event to be marked done, there will also be a textbox where that can be entered.
                   2343:): # Clicking OK will set the value of LC_interval_done to 'true', and, if needed will
                   2344:): # set the value of LC_interval_done_proctorpass to the text entered in that box,
                   2345:): # and submit the corresponding form.
                   2346:): #
                   2347:): # The &zero_time() routine in lonhomework.pm is called when a page is rendered if
                   2348:): # LC_interval_done is true.
                   2349:): #
                   2350:): sub done_button_js {
                   2351:):     my ($type,$width,$height,$proctor,$donebuttontext) = @_;
                   2352:):     return unless (($type eq 'map') || ($type eq 'resource'));
                   2353:):     my %lt = &Apache::lonlocal::texthash(
                   2354:):                  title    => 'WARNING!',
                   2355:):                  preamble => 'You are trying to end this timed event early.',
                   2356:):                  map      => 'Confirming that you are done will cause the time to expire and prevent you from changing any answers in the current folder.',
                   2357:):                  resource => 'Confirming that you are done will cause the time to expire for this question, and prevent you from changing your answer(s).',
                   2358:):                  okdone   => 'Click "OK" if you are completely finished.',
                   2359:):                  cancel   => 'Click "Cancel" to continue working.',
                   2360:):                  proctor  => 'Ask a proctor to enter the key, then click "OK" if you are completely finished.',
                   2361:):                  ok       => 'OK',
                   2362:):                  exit     => 'Cancel',
                   2363:):                  key      => 'Key:',
                   2364:):                  nokey    => 'A proctor key is required',
                   2365:):     );
                   2366:):     my $shownsymb = &HTML::Entities::encode(&Apache::lonenc::check_encrypt($env{'request.symb'}));
                   2367:):     my $navmap = Apache::lonnavmaps::navmap->new();
                   2368:):     my ($missing,$tried) = (0,0);
                   2369:):     if (ref($navmap)) {
                   2370:):         my @resources=();
                   2371:):         if ($type eq 'map') {
                   2372:):             my ($mapurl,$rid,$resurl)=&Apache::lonnet::decode_symb($env{'request.symb'});
                   2373:):             if ($env{'request.symb'} =~ /\.page$/) {
                   2374:):                 @resources=$navmap->retrieveResources($resurl,sub { $_[0]->is_problem() });
                   2375:):             } else {
                   2376:):                 @resources=$navmap->retrieveResources($mapurl,sub { $_[0]->is_problem() });
                   2377:):             }
                   2378:):         } else {
                   2379:):             my $res = $navmap->getBySymb($env{'request.symb'});
                   2380:):             if (ref($res)) {
                   2381:):                 if ($res->is_problem()) {
                   2382:):                     push(@resources,$res);
                   2383:):                 }
                   2384:):             }
                   2385:):         }
                   2386:):         foreach my $res (@resources) {
                   2387:):             if (ref($res->parts()) eq 'ARRAY') {
                   2388:):                 foreach my $part (@{$res->parts()}) {
                   2389:):                     if (!$res->tries($part)) {
                   2390:):                         $missing++;
                   2391:):                     } else {
                   2392:):                         $tried++;
                   2393:):                     }
                   2394:):                 }
                   2395:):             }
                   2396:):         }
                   2397:):     }
                   2398:):     if ($missing) {
                   2399:):         $lt{'miss'} .= '<p class="LC_error">';
                   2400:):         if ($type eq 'map') {
                   2401:):             $lt{'miss'} .= &mt('Submissions are missing for [quant,_1,question part,question parts] in this folder.',$missing);
                   2402:):         } else {
                   2403:):             $lt{'miss'} .= &mt('Submissions are missing for [quant,_1,part] in this question.',$missing);
                   2404:):         }
                   2405:):         if ($missing > 1) {
                   2406:):             $lt{'miss'} .= ' '.&mt('If you confirm you are done you will be unable to submit answers for them.').'</span>';
                   2407:):         } else {
                   2408:):             $lt{'miss'} .= ' '.&mt('If you confirm you are done you will be unable to submit an answer for it.').'</p>';
                   2409:):         }
                   2410:):     }
                   2411:):     $donebuttontext = &HTML::Entities::encode($donebuttontext,'<>&"');
                   2412:):     if ($proctor) {
                   2413:):         if ($height !~ /^\d+$/) {
                   2414:):             $height = 400;
                   2415:):             if ($missing) {
                   2416:):                 $height += 60;
                   2417:):             }
                   2418:):         }
                   2419:):         if ($width !~ /^\d+$/) {
                   2420:):             $width = 400;
                   2421:):             if ($missing) {
                   2422:):                 $width += 60;
                   2423:):             }
                   2424:):         }
                   2425:):         return <<END;
                   2426:): <form method="post" name="LCdoneButton" action="">
                   2427:):     <input type="hidden" name="LC_interval_done" value="" />
                   2428:):     <input type="hidden" name="LC_interval_done_proctorpass" value="" />
                   2429:):     <input type="hidden" name="symb" value="$shownsymb" />
                   2430:):     <button id="LC_done-confirm-opener" type="button">$donebuttontext</button>
                   2431:): </form>
                   2432:): 
                   2433:): <div id="LC_done-confirm" title="$lt{'title'}">
                   2434:):   <p>$lt{'preamble'} $lt{$type}</p>
                   2435:):   $lt{'miss'}
                   2436:):   <p>$lt{'proctor'}</p>
                   2437:):   <form name="LCdoneButtonProctor" action="">
                   2438:):     <label>$lt{'key'}<input type="password" name="LC_interval_done_proctorkey" value="" /></label>
                   2439:):     <input type="submit" tabindex="-1" style="position:absolute; top:-1000px" />
                   2440:):   </form>
                   2441:):   <p>$lt{'cancel'}</p>
                   2442:): </div>
                   2443:): 
                   2444:): <script type="text/javascript">
                   2445:): // <![CDATA[
                   2446:):     \$( "#LC_done-confirm" ).dialog({ autoOpen: false });
                   2447:):     \$( "#LC_done-confirm-opener" ).on("click", function() {
                   2448:):         \$( "#LC_done-confirm" ).dialog("open");
                   2449:):         \$( "#LC_done-confirm" ).dialog({
                   2450:):             height: $height,
                   2451:):             width: $width,
                   2452:):             modal: true,
                   2453:):             resizable: false,
                   2454:):             buttons: [
                   2455:):                 {
                   2456:):                     text: "$lt{'ok'}",
                   2457:):                     click: function() {
                   2458:):                         var proctorkey = \$( '[name="LC_interval_done_proctorkey"]' )[0].value;
                   2459:):                         if ((proctorkey == '') || (proctorkey == null)) {
                   2460:):                             alert("$lt{'nokey'}");
                   2461:):                         } else {
                   2462:):                             \$( '[name="LC_interval_done"]' )[0].value = 'true';
                   2463:):                             \$( '[name="LC_interval_done_proctorpass"]' )[0].value = proctorkey;
                   2464:):                             \$( '[name="LCdoneButton"]' )[0].submit();
                   2465:):                         }
                   2466:):                     },
                   2467:):                 },
                   2468:):                 {
                   2469:):                     text: "$lt{'exit'}",
                   2470:):                     click: function() {
                   2471:):                         \$("#LC_done-confirm").dialog( "close" );
                   2472:):                     }
                   2473:):                 }
                   2474:):             ],
                   2475:):             close: function() {
                   2476:):                 \$( '[name="LC_interval_done_proctorkey"]' )[0].value = '';
                   2477:):             }
                   2478:):         });
                   2479:):         \$( "#LC_done-confirm" ).find( "form" ).on( "submit", function( event ) {
                   2480:):             event.preventDefault();
                   2481:):             \$( '[name="LC_interval_done"]' )[0].value = 'true';
                   2482:):             \$( '[name="LC_interval_done_proctorpass"]' )[0].value = \$( '[name="LC_interval_done_proctorkey"]' )[0].value;
                   2483:):             \$( '[name="LCdoneButton"]' )[0].submit();
                   2484:):         });
                   2485:): });
                   2486:): 
                   2487:): // ]]>
                   2488:): </script>
                   2489:): 
                   2490:): END
                   2491:):     } else {
                   2492:):         if ($height !~ /^\d+$/) {
                   2493:):             $height = 320;
                   2494:):             if ($missing) {
                   2495:):                 $height += 60;
                   2496:):             }
                   2497:):         }
                   2498:):         if ($width !~ /^\d+$/) {
                   2499:):             $width = 320;
                   2500:):             if ($missing) {
                   2501:):                 $width += 60;
                   2502:):             }
                   2503:):         }
                   2504:):         if ($missing) {
                   2505:):             $lt{'miss'} = '</p>'.$lt{'miss'}.'<p>';
                   2506:):         }
                   2507:):         return <<END;
                   2508:): 
                   2509:): <form method="post" name="LCdoneButton" action="">
                   2510:):     <input type="hidden" name="LC_interval_done" value="" />
                   2511:):     <input type="hidden" name="symb" value="$shownsymb" />
                   2512:):     <button id="LC_done-confirm-opener" type="button">$donebuttontext</button>
                   2513:): </form>
                   2514:): 
                   2515:): <div id="LC_done-confirm" title="$lt{'title'}">
                   2516:):     <p>$lt{'preamble'} $lt{$type} $lt{'miss'} $lt{'okdone'} $lt{'cancel'}</p>
                   2517:): </div>
                   2518:): 
                   2519:): <script type="text/javascript">
                   2520:): // <![CDATA[
                   2521:): \$( "#LC_done-confirm" ).dialog({ autoOpen: false });
                   2522:): \$( "#LC_done-confirm-opener" ).click(function() {
                   2523:):     \$( "#LC_done-confirm" ).dialog( "open" );
                   2524:):     \$( "#LC_done-confirm" ).dialog({
                   2525:):       resizable: false,
                   2526:):       height: $height,
                   2527:):       width: $width,
                   2528:):       modal: true,
                   2529:):       buttons: [
                   2530:):                  {
                   2531:):                     text: "$lt{'ok'}",
                   2532:):                     click: function() {
                   2533:):                         \$( this ).dialog( "close" );
                   2534:):                         \$( '[name="LC_interval_done"]' )[0].value = 'true';
                   2535:):                         \$( '[name="LCdoneButton"]' )[0].submit();
                   2536:):                     },
                   2537:):                  },
                   2538:):                  {
                   2539:):                      text: "$lt{'exit'}",
                   2540:):                      click: function() {
                   2541:):                          \$( this ).dialog( "close" );
                   2542:):                      },
                   2543:):                   },
                   2544:):                ],
                   2545:):        });
                   2546:): });
                   2547:): // ]]>
                   2548:): </script>
                   2549:): 
                   2550:): END
                   2551:):     }
                   2552:): }
                   2553:): 
1.42      www      2554: sub utilityfunctions {
1.369.2.47  raeburn  2555:     my ($httphost) = @_;
1.152     albertel 2556:     my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
1.369.2.75  raeburn  2557:     my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
                   2558:     if ($currenturl =~ m{^/adm/wrapper/ext/}) {
                   2559:         if ($env{'request.external.querystring'}) {
1.293     raeburn  2560:             $currenturl .= ($currenturl=~/\?/)?'&':'?'.$env{'request.external.querystring'};
1.369.2.75  raeburn  2561:         }
                   2562:         my ($anchor) = ($env{'request.symb'} =~ /(\#[^\#]+)$/);
                   2563:         if (($anchor) && ($currenturl !~ /\Q$anchor\E$/)) {
                   2564:             $currenturl .= $1;
                   2565:         }
1.293     raeburn  2566:     }
1.183     www      2567:     $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
1.125     albertel 2568:     
1.306     raeburn  2569:     my $dc_popup_cid;
                   2570:     if ($env{'user.adv'} && exists($env{'user.role.dc./'.
                   2571:                         $env{'course.'.$env{'request.course.id'}.
                   2572:                                  '.domain'}.'/'})) {
                   2573:         $dc_popup_cid = &dc_popup_js();
                   2574:     }
                   2575: 
1.175     albertel 2576:     my $start_page_annotate = 
                   2577:         &Apache::loncommon::start_page('Annotator',undef,
                   2578: 				       {'only_body' => 1,
                   2579: 					'js_ready'  => 1,
                   2580: 					'bgcolor'   => '#BBBBBB',
                   2581: 					'add_entries' => {
                   2582: 					    'onload' => 'javascript:document.goannotate.submit();'}});
                   2583: 
1.205     albertel 2584:     my $end_page_annotate = 
                   2585:         &Apache::loncommon::end_page({'js_ready' => 1});
                   2586: 
1.369.2.26  raeburn  2587:     my $jumptores = &Apache::lonhtmlcommon::javascript_jumpto_resource();
1.336     raeburn  2588: 
1.368     www      2589:     my $esc_url=&escape($currenturl);
                   2590:     my $esc_symb=&escape($currentsymb);
1.332     wenzelju 2591: 
1.369.2.10  raeburn  2592:     my $countdown = &countdown_toggle_js();
                   2593: 
1.369.2.83.2.  (raeburn 2594:):     my $deeplinktarget;
                   2595:):     if ($env{'request.deeplink.login'}) {
                   2596:):         $deeplinktarget = $env{'request.deeplink.target'};
                   2597:):     }
                   2598:): 
1.369.2.75  raeburn  2599:     my $annotateurl = '/adm/annotation';
                   2600:     if ($httphost) {
                   2601:         $annotateurl = '/adm/annotations';
                   2602:     }
1.369.2.53  raeburn  2603:     my $hostvar = '
                   2604: function setLCHost() {
                   2605:     var lcHostname="";
                   2606: ';
                   2607:     if ($httphost =~ m{^https?\://}) {
                   2608:         $hostvar .= '    var lcServer="'.$httphost.'";'."\n".
                   2609:                     '    var hostReg = /^https?:\/\/([^\/]+)$/i;'."\n".
                   2610:                     '    var match = hostReg.exec(lcServer);'."\n".
                   2611:                     '    if (match.length) {'."\n".
                   2612:                     '        if (match[1] == location.hostname) {'."\n".
                   2613:                     '            lcHostname=lcServer;'."\n".
                   2614:                     '        }'."\n".
                   2615:                     '    }'."\n";
                   2616:     }
                   2617: 
                   2618:     $hostvar .= '    return lcHostname;'."\n".
                   2619: '}'."\n";
                   2620: 
1.42      www      2621: return (<<ENDUTILITY)
1.369.2.53  raeburn  2622:     $hostvar
1.368     www      2623:     var currentURL=unescape("$esc_url");
                   2624:     var reloadURL=unescape("$esc_url");
                   2625:     var currentSymb=unescape("$esc_symb");
1.42      www      2626: 
1.306     raeburn  2627: $dc_popup_cid
1.114     albertel 2628: 
1.369.2.26  raeburn  2629: $jumptores
1.336     raeburn  2630: 
1.42      www      2631: function gopost(url,postdata) {
                   2632:    if (url!='') {
1.369.2.53  raeburn  2633:       var lcHostname = setLCHost();
                   2634:       this.document.server.action=lcHostname+url;
1.42      www      2635:       this.document.server.postdata.value=postdata;
                   2636:       this.document.server.command.value='';
                   2637:       this.document.server.url.value='';
                   2638:       this.document.server.symb.value='';
                   2639:       this.document.server.submit();
                   2640:    }
                   2641: }
                   2642: 
                   2643: function gocmd(url,cmd) {
                   2644:    if (url!='') {
1.369.2.53  raeburn  2645:       var lcHostname = setLCHost();
                   2646:       this.document.server.action=lcHostname+url;
1.42      www      2647:       this.document.server.postdata.value='';
                   2648:       this.document.server.command.value=cmd;
                   2649:       this.document.server.url.value=currentURL;
                   2650:       this.document.server.symb.value=currentSymb;
                   2651:       this.document.server.submit();
                   2652:    }
1.57      www      2653: }
                   2654: 
1.121     raeburn  2655: function gocstr(url,filename) {
                   2656:     if (url == '/adm/cfile?action=delete') {
                   2657:         this.document.cstrdelete.filename.value = filename
                   2658:         this.document.cstrdelete.submit();
                   2659:         return;
                   2660:     }
1.137     raeburn  2661:     if (url == '/adm/printout') {
                   2662:         this.document.cstrprint.postdata.value = filename
                   2663:         this.document.cstrprint.curseed.value = 0;
                   2664:         this.document.cstrprint.problemtype.value = 0;
1.138     raeburn  2665:         if (this.document.lonhomework) {
                   2666:             if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
                   2667:                 this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
                   2668:             }
                   2669:             if (this.document.lonhomework.problemtype) {
1.164     albertel 2670: 		if (this.document.lonhomework.problemtype.value) {
                   2671: 		    this.document.cstrprint.problemtype.value = 
                   2672: 			this.document.lonhomework.problemtype.value;
                   2673: 		} else if (this.document.lonhomework.problemtype.options) {
                   2674: 		    for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
                   2675: 			if (this.document.lonhomework.problemtype.options[i].selected) {
                   2676: 			    if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') { 
                   2677: 				this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
                   2678: 				}
                   2679: 			}
                   2680: 		    }
                   2681: 		}
                   2682: 	    }
                   2683: 	}
1.137     raeburn  2684:         this.document.cstrprint.submit();
                   2685:         return;
                   2686:     }
1.121     raeburn  2687:     if (url !='') {
                   2688:         this.document.constspace.filename.value = filename;
                   2689:         this.document.constspace.action = url;
                   2690:         this.document.constspace.submit();
                   2691:     }
                   2692: }
                   2693: 
1.131     raeburn  2694: function golist(url) {
                   2695:    if (url!='' && url!= null) {
                   2696:        currentURL = null;
                   2697:        currentSymb= null;
1.369.2.53  raeburn  2698:        var lcHostname = setLCHost();
1.369.2.83.2.  (raeburn 2699:):        var deeplinktarget = '$deeplinktarget';
                   2700:):        if (deeplinktarget == '_self') {
                   2701:):            document.location.href=lcHostname+url;
                   2702:):        } else {
                   2703:):            top.location.href=lcHostname+url;
                   2704:):        }
1.131     raeburn  2705:    }
                   2706: }
                   2707: 
                   2708: 
1.121     raeburn  2709: 
1.369.2.83.2.  (raeburn 2710:): function catalog_info(url,isMobile) {
1.369.2.52  raeburn  2711:     if (isMobile == 1) {
1.369.2.83.2.  (raeburn 2712:):         openMyModal(url+'.meta?modal=1',500,400,'yes');
1.369.2.52  raeburn  2713:     } else {
1.369.2.83.2.  (raeburn 2714:):         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  2715:     }
1.57      www      2716: }
                   2717: 
                   2718: function chat_win() {
1.369.2.53  raeburn  2719:    var lcHostname = setLCHost();
                   2720:    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      2721: }
1.169     raeburn  2722: 
                   2723: function group_chat(group) {
1.369.2.53  raeburn  2724:    var lcHostname = setLCHost();
                   2725:    var url = lcHostname+'/adm/groupchat?group='+group;
1.169     raeburn  2726:    var winName = 'LONchat_'+group;
                   2727:    grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
                   2728: }
1.175     albertel 2729: 
                   2730: function annotate() {
                   2731:    w_Annotator_flag=1;
                   2732:    annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
                   2733:    annotator.document.write(
                   2734:    '$start_page_annotate'
                   2735:   +"<form name='goannotate' target='Annotator' method='post' "
1.369.2.75  raeburn  2736:   +"action='$annotateurl'>"
1.217     albertel 2737:   +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />"
1.181     albertel 2738:   +"<\\/form>"
1.205     albertel 2739:   +'$end_page_annotate');
1.175     albertel 2740:    annotator.document.close();
                   2741: }
                   2742: 
1.369.2.8  raeburn  2743: function open_StoredLinks_Import(rat) {
                   2744:    var newWin;
1.369.2.53  raeburn  2745:    var lcHostname = setLCHost();
1.369.2.8  raeburn  2746:    if (rat) {
1.369.2.53  raeburn  2747:        newWin = window.open(lcHostname+'/adm/wishlist?inhibitmenu=yes&mode=import&rat='+rat,
1.369.2.8  raeburn  2748:                             'wishlistImport','scrollbars=1,resizable=1,menubar=0');
                   2749:    }
                   2750:    else {
1.369.2.53  raeburn  2751:        newWin = window.open(lcHostname+'/adm/wishlist?inhibitmenu=yes&mode=import',
1.369.2.8  raeburn  2752:                             'wishlistImport','scrollbars=1,resizable=1,menubar=0');
                   2753:    }
                   2754:    newWin.focus();
                   2755: }
                   2756: 
1.369.2.79  raeburn  2757: function open_source() {
                   2758:    sourcewin=window.open('/adm/source?inhibitmenu=yes&viewonly=1&filename='+currentURL,'LONsource',
                   2759:                          'height=500,width=600,resizable=yes,location=no,menubar=no,toolbar=no,scrollbars=yes');
                   2760: }
                   2761: 
1.369.2.4  raeburn  2762: (function (\$) {
                   2763:   \$(document).ready(function () {
                   2764:     \$.single=function(a){return function(b){a[0]=b;return a}}(\$([1]));
                   2765:     /*\@cc_on
                   2766:       if (!window.XMLHttpRequest) {
                   2767:         \$('.LC_hoverable').each(function () {
                   2768:           this.attachEvent('onmouseenter', function (evt) { \$.single(evt.srcElement).addClass('hover'); });
                   2769:           this.attachEvent('onmouseleave', function (evt) { \$.single(evt.srcElement).removeClass('hover'); });
                   2770:         });
                   2771:       }
                   2772:     \@*/
                   2773:   });
                   2774: }(jQuery));
                   2775: 
1.369.2.10  raeburn  2776: $countdown
                   2777: 
1.42      www      2778: ENDUTILITY
                   2779: }
                   2780: 
                   2781: sub serverform {
1.369.2.83.2.  (raeburn 2782:):     my $target;
                   2783:):     if (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self')) {
                   2784:):         $target = ' target="_self"';
                   2785:):     } else {
                   2786:):         $target = ' target="_top"';
                   2787:):     }
1.42      www      2788:     return(<<ENDSERVERFORM);
1.369.2.83.2.  (raeburn 2789:): <form name="server" action="/adm/logout" method="post"$target>
1.42      www      2790: <input type="hidden" name="postdata" value="none" />
                   2791: <input type="hidden" name="command" value="none" />
                   2792: <input type="hidden" name="url" value="none" />
                   2793: <input type="hidden" name="symb" value="none" />
                   2794: </form>
                   2795: ENDSERVERFORM
                   2796: }
1.113     albertel 2797: 
1.121     raeburn  2798: sub constspaceform {
1.369.2.83.2.  (raeburn 2799:):     my ($frameset) = @_;
                   2800:):     my ($target,$printtarget);
                   2801:):     if ($frameset) {
                   2802:):         $target = ' target="_parent"';
                   2803:):         $printtarget = ' target="_parent"';
                   2804:):     } else {
                   2805:):         unless (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self')) {
                   2806:):             $target = ' target="_top"';
                   2807:):             $printtarget = ' target="_top"';
                   2808:):         }
                   2809:):     }
1.121     raeburn  2810:     return(<<ENDCONSTSPACEFORM);
1.369.2.83.2.  (raeburn 2811:): <form name="constspace" action="/adm/logout" method="post"$target>
1.121     raeburn  2812: <input type="hidden" name="filename" value="" />
                   2813: </form>
1.369.2.83.2.  (raeburn 2814:): <form name="cstrdelete" action="/adm/cfile" method="post"$target>
1.121     raeburn  2815: <input type="hidden" name="action" value="delete" /> 
                   2816: <input type="hidden" name="filename" value="" />
                   2817: </form>
1.369.2.83.2.  (raeburn 2818:): <form name="cstrprint" action="/adm/printout" method="post"$printtarget>
1.137     raeburn  2819: <input type="hidden" name="postdata" value="" />
                   2820: <input type="hidden" name="curseed" value="" />
                   2821: <input type="hidden" name="problemtype" value="" />
                   2822: </form>
                   2823: 
1.121     raeburn  2824: ENDCONSTSPACEFORM
                   2825: }
                   2826: 
1.369.2.17  raeburn  2827: sub get_nav_status {
                   2828:     my $navstatus="swmenu.w_loncapanav_flag=";
                   2829:     if ($env{'environment.remotenavmap'} eq 'on') {
                   2830:         $navstatus.="1";
                   2831:     } else {
                   2832:         $navstatus.="-1";
                   2833:     }
                   2834:     return $navstatus;
                   2835: }
                   2836: 
1.220     raeburn  2837: sub hidden_button_check {
1.317     droeschl 2838:     if ( $env{'request.course.id'} eq ''
                   2839:          || $env{'request.role.adv'} ) {
                   2840: 
1.220     raeburn  2841:         return;
                   2842:     }
1.232     raeburn  2843:     my $buttonshide = &Apache::lonnet::EXT('resource.0.buttonshide');
                   2844:     return $buttonshide; 
1.220     raeburn  2845: }
1.184     raeburn  2846: 
1.235     raeburn  2847: sub roles_selector {
1.369.2.83.2.  (raeburn 2848:):     my ($cdom,$cnum,$httphost,$target,$menucoll,$menuref) = @_;
1.298     raeburn  2849:     my $crstype = &Apache::loncommon::course_type();
1.235     raeburn  2850:     my $now = time;
1.369.2.68  raeburn  2851:     my (%courseroles,%seccount,%courseprivs,%roledesc);
1.235     raeburn  2852:     my $is_cc;
1.369.2.83.2.  (raeburn 2853:):     my ($js,$form,$switcher,$has_opa_priv);
1.298     raeburn  2854:     my $ccrole;
                   2855:     if ($crstype eq 'Community') {
                   2856:         $ccrole = 'co';
                   2857:     } else {
                   2858:         $ccrole = 'cc';
1.350     raeburn  2859:     }
1.369.2.61  raeburn  2860:     my ($privref,$gotsymb,$destsymb);
1.350     raeburn  2861:     my $destinationurl = $ENV{'REQUEST_URI'};
1.369.2.75  raeburn  2862:     if ($destinationurl =~ /(\?|\&)symb=/) {
1.369.2.23  raeburn  2863:         $gotsymb = 1;
                   2864:     } elsif ($destinationurl =~ m{^/enc/}) {
                   2865:         my $plainurl = &Apache::lonenc::unencrypted($destinationurl);
1.369.2.75  raeburn  2866:         if ($plainurl =~ /(\?|\&)symb=/) {
1.369.2.23  raeburn  2867:             $gotsymb = 1;
                   2868:         }
                   2869:     }
                   2870:     unless ($gotsymb) {
                   2871:         $destsymb = &Apache::lonnet::symbread();
                   2872:         if ($destsymb ne '') {
                   2873:             $destsymb = &Apache::lonenc::check_encrypt($destsymb);
                   2874:         }
                   2875:     }
1.350     raeburn  2876:     my $reqprivs = &required_privs();
                   2877:     if (ref($reqprivs) eq 'HASH') {
                   2878:         my $destination = $destinationurl;
                   2879:         $destination =~ s/(\?.*)$//;
                   2880:         if (exists($reqprivs->{$destination})) {
1.369.2.61  raeburn  2881:             if ($reqprivs->{$destination} =~ /,/) {
                   2882:                 @{$privref} = split(/,/,$reqprivs->{$destination});
                   2883:             } else {
                   2884:                 $privref = [$reqprivs->{$destination}];
                   2885:             }
1.350     raeburn  2886:         }
                   2887:     }
1.298     raeburn  2888:     if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
                   2889:         my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
1.235     raeburn  2890:         if ((($start) && ($start<0)) || 
                   2891:             (($end) && ($end<$now))  ||
                   2892:             (($start) && ($now<$start))) {
                   2893:             $is_cc = 0;
                   2894:         } else {
                   2895:             $is_cc = 1;
                   2896:         }
                   2897:     }
                   2898:     if ($is_cc) {
1.369.2.61  raeburn  2899:         &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs);
                   2900:     } elsif ($env{'request.role'} =~ m{^\Qcr/$cdom/$cdom-domainconfig/\E(\w+)\.\Q/$cdom/$cnum\E}) {
1.369.2.68  raeburn  2901:         &get_customadhoc_roles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs,\%roledesc,$privref);
1.235     raeburn  2902:     } else {
1.262     raeburn  2903:         my %gotnosection;
1.235     raeburn  2904:         foreach my $item (keys(%env)) {
1.239     raeburn  2905:             if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
1.235     raeburn  2906:                 my $role = $1;
                   2907:                 my $sec = $2;
                   2908:                 next if ($role eq 'gr');
                   2909:                 my ($start,$end) = split(/\./,$env{$item});
                   2910:                 next if (($start && $start > $now) || ($end && $end < $now));
                   2911:                 if ($sec eq '') {
1.239     raeburn  2912:                     if (!$gotnosection{$role}) {
                   2913:                         $seccount{$role} ++;
                   2914:                         $gotnosection{$role} = 1;
                   2915:                     }
1.235     raeburn  2916:                 }
1.369.2.61  raeburn  2917:                 if ((ref($privref) eq 'ARRAY') && (@{$privref} > 0)) {
1.350     raeburn  2918:                     my $cnumsec = $cnum;
                   2919:                     if ($sec ne '') {
                   2920:                         $cnumsec .= "/$sec";
                   2921:                     }
                   2922:                     $courseprivs{"$role./$cdom/$cnumsec./"} =
                   2923:                         $env{"user.priv.$role./$cdom/$cnumsec./"};
                   2924:                     $courseprivs{"$role./$cdom/$cnumsec./$cdom/"} =
                   2925:                         $env{"user.priv.$role./$cdom/$cnumsec./$cdom/"};
                   2926:                     $courseprivs{"$role./$cdom/$cnumsec./$cdom/$cnumsec"} =
                   2927:                         $env{"user.priv.$role./$cdom/$cnumsec./$cdom/$cnumsec"};
                   2928:                 }
1.235     raeburn  2929:                 if (ref($courseroles{$role}) eq 'ARRAY') {
1.239     raeburn  2930:                     if ($sec ne '') {
1.264     raeburn  2931:                         if (!grep(/^\Q$sec\E$/,@{$courseroles{$role}})) {
1.239     raeburn  2932:                             push(@{$courseroles{$role}},$sec);
                   2933:                             $seccount{$role} ++;
                   2934:                         }
                   2935:                     }
                   2936:                 } else {
                   2937:                     @{$courseroles{$role}} = ();
                   2938:                     if ($sec ne '') {
                   2939:                         $seccount{$role} ++;
1.235     raeburn  2940:                         push(@{$courseroles{$role}},$sec);
                   2941:                     }
                   2942:                 }
                   2943:             }
                   2944:         }
                   2945:     }
1.298     raeburn  2946:     my @roles_order = ($ccrole,'in','ta','ep','ad','st');
1.369.2.30  raeburn  2947:     my $numdiffsec;
                   2948:     if (keys(%seccount) == 1) {
                   2949:         foreach my $key (keys(%seccount)) {
                   2950:             $numdiffsec = $seccount{$key};
                   2951:         }
                   2952:     }
                   2953:     if ((keys(%seccount) > 1) || ($numdiffsec > 1)) {
1.369.2.83.2.  (raeburn 2954:):         my $targetattr;
                   2955:):         if ($target ne '') {
                   2956:):             $targetattr = ' target="'.$target.'"';
                   2957:):         }
1.369.2.30  raeburn  2958:         my @submenu;
1.369.2.83.2.  (raeburn 2959:):         $js = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles,\%courseprivs,
                   2960:):                             \%roledesc,$privref,$menucoll,$menuref);
1.369.2.30  raeburn  2961:         $form = 
1.369.2.83.2.  (raeburn 2962:):             '<form name="rolechooser" method="post" action="'.$httphost.'/adm/roles"'.$targetattr.'>'."\n".
1.369.2.30  raeburn  2963:             '  <input type="hidden" name="destinationurl" value="'.
                   2964:             &HTML::Entities::encode($destinationurl).'" />'."\n".
                   2965:             '  <input type="hidden" name="gotorole" value="1" />'."\n".
                   2966:             '  <input type="hidden" name="selectrole" value="" />'."\n".
                   2967:             '  <input type="hidden" name="switchrole" value="" />'."\n";
                   2968:         if ($destsymb ne '') {
                   2969:             $form .= '   <input type="hidden" name="destsymb" value="'.
                   2970:                          &HTML::Entities::encode($destsymb).'" />'."\n";
                   2971:         }
                   2972:         $form .= '</form>'."\n";
1.235     raeburn  2973:         foreach my $role (@roles_order) {
1.369.2.30  raeburn  2974:             my $include;
1.235     raeburn  2975:             if (defined($courseroles{$role})) {
1.369.2.30  raeburn  2976:                 if ($env{'request.role'} =~ m{^\Q$role\E}) {
                   2977:                     if ($seccount{$role} > 1) {
                   2978:                         $include = 1;
1.369.2.83.2.  (raeburn 2979:):                     } else {
                   2980:):                         if ($env{'user.priv.'.$env{'request.role'}."./$cdom/$cnum"} =~/opa\&([^\:]*)/) {
                   2981:):                             $has_opa_priv = 1;
                   2982:):                         }
1.369.2.30  raeburn  2983:                     }
                   2984:                 } else {
                   2985:                     $include = 1;
                   2986:                 }
                   2987:             }
                   2988:             if ($include) {
1.369.2.83.2.  (raeburn 2989:):                 if ($env{"user.priv.$role./$cdom/$cnum./$cdom/$cnum"} =~/opa\&([^\:]*)/) {
                   2990:):                     $has_opa_priv = 1;
                   2991:):                 }
1.369.2.30  raeburn  2992:                 push(@submenu,['javascript:adhocRole('."'$role'".')',
                   2993:                                &Apache::lonnet::plaintext($role,$crstype)]);
1.235     raeburn  2994:             }
                   2995:         }
                   2996:         foreach my $role (sort(keys(%courseroles))) {
                   2997:             if ($role =~ /^cr/) {
1.369.2.30  raeburn  2998:                 my $include;
                   2999:                 if ($env{'request.role'} =~ m{^\Q$role\E}) {
                   3000:                     if ($seccount{$role} > 1) {
                   3001:                         $include = 1;
                   3002:                     }
                   3003:                 } else {
                   3004:                     $include = 1;
                   3005:                 }
                   3006:                 if ($include) {
1.369.2.65  raeburn  3007:                     my $rolename;
                   3008:                     if ($role =~ m{^cr/$cdom/$cdom\-domainconfig/(\w+)(?:/\w+|$)}) {
1.369.2.68  raeburn  3009:                         $rolename = $roledesc{$role};
                   3010:                         if ($rolename eq '') {
                   3011:                             $rolename = &mt('Helpdesk [_1]',$1);
                   3012:                         }
1.369.2.65  raeburn  3013:                     } else {
                   3014:                         $rolename = &Apache::lonnet::plaintext($role);
                   3015:                     }
1.369.2.83.2.  (raeburn 3016:):                     if ($env{"user.priv.$role./$cdom/$cnum./$cdom/$cnum"} =~/opa\&([^\:]*)/) {
                   3017:):                         $has_opa_priv = 1;
                   3018:):                     }
1.369.2.30  raeburn  3019:                     push(@submenu,['javascript:adhocRole('."'$role'".')',
1.369.2.65  raeburn  3020:                                    $rolename]);
1.369.2.30  raeburn  3021:                 }
1.235     raeburn  3022:             }
                   3023:         }
1.369.2.30  raeburn  3024:         if (@submenu > 0) {
1.369.2.83.2.  (raeburn 3025:):             $switcher = &create_submenu('#',$target,&mt('Switch role'),\@submenu);
1.369.2.23  raeburn  3026:         }
1.235     raeburn  3027:     }
1.369.2.83.2.  (raeburn 3028:):     return ($js,$form,$switcher,$has_opa_priv);
1.235     raeburn  3029: }
                   3030: 
1.262     raeburn  3031: sub get_all_courseroles {
1.350     raeburn  3032:     my ($cdom,$cnum,$courseroles,$seccount,$courseprivs) = @_;
1.351     raeburn  3033:     unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH') &&
1.350     raeburn  3034:             (ref($courseprivs) eq 'HASH')) {
1.262     raeburn  3035:         return;
                   3036:     }
                   3037:     my ($result,$cached) = 
                   3038:         &Apache::lonnet::is_cached_new('getcourseroles',$cdom.'_'.$cnum);
                   3039:     if (defined($cached)) {
                   3040:         if (ref($result) eq 'HASH') {
                   3041:             if ((ref($result->{'roles'}) eq 'HASH') && 
1.350     raeburn  3042:                 (ref($result->{'seccount'}) eq 'HASH') && 
                   3043:                 (ref($result->{'privs'}) eq 'HASH')) {
1.262     raeburn  3044:                 %{$courseroles} = %{$result->{'roles'}};
                   3045:                 %{$seccount} = %{$result->{'seccount'}};
1.350     raeburn  3046:                 %{$courseprivs} = %{$result->{'privs'}};
1.262     raeburn  3047:                 return;
                   3048:             }
                   3049:         }
                   3050:     }
                   3051:     my %gotnosection;
                   3052:     my %adv_roles =
                   3053:          &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
                   3054:     foreach my $role (keys(%adv_roles)) {
                   3055:         my ($urole,$usec) = split(/:/,$role);
                   3056:         if (!$gotnosection{$urole}) {
                   3057:             $seccount->{$urole} ++;
                   3058:             $gotnosection{$urole} = 1;
                   3059:         }
                   3060:         if (ref($courseroles->{$urole}) eq 'ARRAY') {
                   3061:             if ($usec ne '') {
                   3062:                 if (!grep(/^Q$usec\E$/,@{$courseroles->{$urole}})) {
                   3063:                     push(@{$courseroles->{$urole}},$usec);
                   3064:                     $seccount->{$urole} ++;
                   3065:                 }
                   3066:             }
                   3067:         } else {
                   3068:             @{$courseroles->{$urole}} = ();
                   3069:             if ($usec ne '') {
                   3070:                 $seccount->{$urole} ++;
                   3071:                 push(@{$courseroles->{$urole}},$usec);
                   3072:             }
                   3073:         }
1.350     raeburn  3074:         my $area = '/'.$cdom.'/'.$cnum;
                   3075:         if ($usec ne '') {
                   3076:             $area .= '/'.$usec;
                   3077:         }
                   3078:         if ($role =~ /^cr\//) {
                   3079:             &Apache::lonnet::custom_roleprivs($courseprivs,$urole,$cdom,$cnum,$urole.'.'.$area,$area);
                   3080:         } else {
                   3081:             &Apache::lonnet::standard_roleprivs($courseprivs,$urole,$cdom,$urole.'.'.$area,$cnum,$area);
                   3082:         }
1.262     raeburn  3083:     }
                   3084:     my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum,['st']);
                   3085:     @{$courseroles->{'st'}} = ();
1.350     raeburn  3086:     &Apache::lonnet::standard_roleprivs($courseprivs,'st',$cdom,"st./$cdom/$cnum",$cnum,"/$cdom/$cnum");
1.262     raeburn  3087:     if (keys(%sections_count) > 0) {
                   3088:         push(@{$courseroles->{'st'}},keys(%sections_count));
1.350     raeburn  3089:         $seccount->{'st'} = scalar(keys(%sections_count));
1.262     raeburn  3090:     }
1.369.2.38  raeburn  3091:     $seccount->{'st'} ++; # Increment for a section-less student role.
1.262     raeburn  3092:     my $rolehash = {
                   3093:                      'roles'    => $courseroles,
                   3094:                      'seccount' => $seccount,
1.350     raeburn  3095:                      'privs'    => $courseprivs,
1.262     raeburn  3096:                    };
                   3097:     &Apache::lonnet::do_cache_new('getcourseroles',$cdom.'_'.$cnum,$rolehash);
                   3098:     return;
                   3099: }
                   3100: 
1.369.2.61  raeburn  3101: sub get_customadhoc_roles {
1.369.2.68  raeburn  3102:     my ($cdom,$cnum,$courseroles,$seccount,$courseprivs,$roledesc,$privref) = @_;
1.369.2.61  raeburn  3103:     unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH') &&
1.369.2.68  raeburn  3104:             (ref($courseprivs) eq 'HASH') && (ref($roledesc) eq 'HASH')) {
1.369.2.61  raeburn  3105:         return;
                   3106:     }
1.369.2.69  raeburn  3107:     my $is_helpdesk = 0;
                   3108:     my $now = time;
                   3109:     foreach my $role ('dh','da') {
                   3110:         if ($env{"user.role.$role./$cdom/"}) {
                   3111:             my ($start,$end)=split(/\./,$env{"user.role.$role./$cdom/"});
                   3112:             if (!($start && ($now<$start)) && !($end && ($now>$end))) {
                   3113:                 $is_helpdesk = 1;
                   3114:                 last;
                   3115:             }
                   3116:         }
                   3117:     }
                   3118:     if ($is_helpdesk) {
                   3119:         my ($possroles,$description) = &Apache::lonnet::get_my_adhocroles($cdom.'_'.$cnum);
                   3120:         my %available;
                   3121:         if (ref($possroles) eq 'ARRAY') {
                   3122:             map { $available{$_} = 1; } @{$possroles};
                   3123:         }
                   3124:         my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
                   3125:         if (ref($domdefaults{'adhocroles'}) eq 'HASH') {
                   3126:             if (keys(%{$domdefaults{'adhocroles'}})) {
                   3127:                 my $numsec = 1;
                   3128:                 my @sections;
                   3129:                 my ($allseclist,$cached) =
                   3130:                     &Apache::lonnet::is_cached_new('courseseclist',$cdom.'_'.$cnum);
                   3131:                 if (defined($cached)) {
                   3132:                     if ($allseclist ne '') {
                   3133:                         @sections = split(/,/,$allseclist);
1.369.2.68  raeburn  3134:                         $numsec += scalar(@sections);
1.369.2.61  raeburn  3135:                     }
1.369.2.69  raeburn  3136:                 } else {
                   3137:                     my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
                   3138:                     @sections = sort(keys(%sections_count));
                   3139:                     $numsec += scalar(@sections);
                   3140:                     $allseclist = join(',',@sections);
                   3141:                     &Apache::lonnet::do_cache_new('courseseclist',$cdom.'_'.$cnum,$allseclist);
                   3142:                 }
                   3143:                 my (%adhoc,$gotprivs);
                   3144:                 my $prefix = "cr/$cdom/$cdom".'-domainconfig';
                   3145:                 foreach my $role (keys(%{$domdefaults{'adhocroles'}})) {
                   3146:                     next if (($role eq '') || ($role =~ /\W/));
                   3147:                     $seccount->{"$prefix/$role"} = $numsec;
                   3148:                     $roledesc->{"$prefix/$role"} = $description->{$role};  
                   3149:                     if ((ref($privref) eq 'ARRAY') && (@{$privref} > 0)) {
                   3150:                         if (exists($env{"user.priv.$prefix/$role./$cdom/$cnum./"})) {
                   3151:                             $courseprivs->{"$prefix/$role./$cdom/$cnum./"} =
                   3152:                                 $env{"user.priv.$prefix/$role./$cdom/$cnum./"};
                   3153:                             $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/"} =
                   3154:                                 $env{"user.priv.$prefix/$role./$cdom/$cnum./$cdom/"};
                   3155:                             $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/$cnum"} =
                   3156:                                 $env{"user.priv.$prefix/$role./$cdom/$cnum./$cdom/$cnum"};
                   3157:                         } else {
                   3158:                             unless ($gotprivs) {
                   3159:                                 my ($adhocroles,$privscached) =
                   3160:                                     &Apache::lonnet::is_cached_new('adhocroles',$cdom);
                   3161:                                 if ((defined($privscached)) && (ref($adhocroles) eq 'HASH')) {
                   3162:                                     %adhoc = %{$adhocroles};
                   3163:                                 } else {
                   3164:                                     my $confname = &Apache::lonnet::get_domainconfiguser($cdom);
                   3165:                                     my %roledefs = &Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
                   3166:                                     foreach my $key (keys(%roledefs)) {
                   3167:                                         (undef,my $rolename) = split(/_/,$key);
                   3168:                                         if ($rolename ne '') {
                   3169:                                             my ($systempriv,$domainpriv,$coursepriv) = split(/\_/,$roledefs{$key});
                   3170:                                             $coursepriv = &Apache::lonnet::course_adhocrole_privs($rolename,$cdom,$cnum,$coursepriv);
                   3171:                                             $adhoc{$rolename} = join('_',($systempriv,$domainpriv,$coursepriv));
1.369.2.61  raeburn  3172:                                         }
                   3173:                                     }
1.369.2.69  raeburn  3174:                                     &Apache::lonnet::do_cache_new('adhocroles',$cdom,\%adhoc);
1.369.2.61  raeburn  3175:                                 }
1.369.2.69  raeburn  3176:                                 $gotprivs = 1;
1.369.2.61  raeburn  3177:                             }
1.369.2.69  raeburn  3178:                             ($courseprivs->{"$prefix/$role./$cdom/$cnum./"},
                   3179:                              $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/"},
                   3180:                              $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/$cnum"}) =
                   3181:                                  split(/\_/,$adhoc{$role});
1.369.2.61  raeburn  3182:                         }
1.369.2.69  raeburn  3183:                     }
                   3184:                     if ($available{$role}) {
                   3185:                         $courseroles->{"$prefix/$role"} = \@sections;
1.369.2.61  raeburn  3186:                     }
                   3187:                 }
                   3188:             }
                   3189:         }
                   3190:     }
                   3191:     return;
                   3192: }
                   3193: 
1.235     raeburn  3194: sub jump_to_role {
1.369.2.83.2.  (raeburn 3195:):     my ($cdom,$cnum,$seccount,$courseroles,$courseprivs,$roledesc,$privref,
                   3196:):         $menucoll,$menuref) = @_;
1.239     raeburn  3197:     my %lt = &Apache::lonlocal::texthash(
                   3198:                 this => 'This role has section(s) associated with it.',
                   3199:                 ente => 'Enter a specific section.',
                   3200:                 orlb => 'Enter a specific section, or leave blank for no section.',
                   3201:                 avai => 'Available sections are:',
                   3202:                 youe => 'You entered an invalid section choice:',
1.352     raeburn  3203:                 plst => 'Please try again.',
1.350     raeburn  3204:                 role => 'The role you selected is not permitted to view the current page.',
                   3205:                 swit => 'Switch role, but display Main Menu page instead?',
1.239     raeburn  3206:     );
1.369.2.83.2.  (raeburn 3207:):     &js_escape(\%lt);
1.239     raeburn  3208:     my $js;
                   3209:     if (ref($courseroles) eq 'HASH') {
                   3210:         $js = '    var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n". 
                   3211:               '    var numsec = new Array();'."\n".
                   3212:               '    var rolesections = new Array();'."\n".
                   3213:               '    var rolenames = new Array();'."\n".
                   3214:               '    var roleseclist = new Array();'."\n";
                   3215:         my @items = keys(%{$courseroles});
                   3216:         for (my $i=0; $i<@items; $i++) {
                   3217:             $js .= '    rolenames['.$i.'] = "'.$items[$i].'";'."\n";
                   3218:             my ($secs,$secstr);
                   3219:             if (ref($courseroles->{$items[$i]}) eq 'ARRAY') {
                   3220:                 my @sections = sort { $a <=> $b } @{$courseroles->{$items[$i]}};
                   3221:                 $secs = join('","',@sections);
                   3222:                 $secstr = join(', ',@sections);
                   3223:             }
                   3224:             $js .= '    rolesections['.$i.'] = new Array("'.$secs.'");'."\n".
                   3225:                    '    roleseclist['.$i.'] = "'.$secstr.'";'."\n".
                   3226:                    '    numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n";
                   3227:         }
                   3228:     }
1.350     raeburn  3229:     my $checkroles = 0;
1.369.2.83.2.  (raeburn 3230:):     my $fallback = '/adm/menu';
                   3231:):     my $displaymsg = $lt{'swit'};
1.369.2.61  raeburn  3232:     if ((ref($privref) eq 'ARRAY') && (@{$privref} > 0) && (ref($courseprivs) eq 'HASH')) {
                   3233:         my %disallowed;
1.350     raeburn  3234:         foreach my $role (sort(keys(%{$courseprivs}))) {
                   3235:             my $trole;
                   3236:             if ($role =~ m{^(.+?)\Q./$cdom/$cnum\E}) {
                   3237:                 $trole = $1;
                   3238:             }
                   3239:             if (($trole ne '') && ($trole ne 'cm')) {
1.369.2.61  raeburn  3240:                 $disallowed{$trole} = 1;
                   3241:                 foreach my $priv (@{$privref}) { 
                   3242:                     if ($courseprivs->{$role} =~ /\Q:$priv\E($|:|\&\w+)/) {
                   3243:                         delete($disallowed{$trole});
                   3244:                         last;
                   3245:                     }
1.350     raeburn  3246:                 }
                   3247:             }
                   3248:         }
1.369.2.61  raeburn  3249:         if (keys(%disallowed) > 0) {
1.350     raeburn  3250:             $checkroles = 1;
1.369.2.61  raeburn  3251:             $js .= "    var disallow = new Array('".join("','",keys(%disallowed))."');\n".
1.350     raeburn  3252:                    "    var rolecheck = 1;\n";
1.369.2.83.2.  (raeburn 3253:):             if ($menucoll) {
                   3254:):                 if (ref($menuref) eq 'HASH') {
                   3255:):                     if ($menuref->{'main'} eq 'n') {
                   3256:):                         $fallback = '/adm/navmaps';
                   3257:):                         if (&Apache::loncommon::course_type() eq 'Community') {
                   3258:):                             $displaymsg = &mt('Switch role, but display Community Contents page instead?');
                   3259:):                         } else {
                   3260:):                             $displaymsg = &mt('Switch role, but display Course Contents page instead?');
                   3261:):                         }
                   3262:):                         &js_escape(\$displaymsg);
                   3263:):                     }
                   3264:):                 }
                   3265:):             }
1.350     raeburn  3266:         }
                   3267:     }
1.369.2.83.2.  (raeburn 3268:):     &js_escape(\$fallback);
1.350     raeburn  3269:     if (!$checkroles) {
                   3270:         $js .=  "    var disallow = new Array();\n".
                   3271:                 "    rolecheck = 0;\n";
                   3272:     }
1.273     droeschl 3273:     return <<"END";
1.235     raeburn  3274: <script type="text/javascript">
1.273     droeschl 3275: //<![CDATA[
1.369.2.30  raeburn  3276: function adhocRole(newrole) {
1.239     raeburn  3277:     $js
1.235     raeburn  3278:     if (newrole == '') {
1.350     raeburn  3279:         return;
1.235     raeburn  3280:     } 
1.239     raeburn  3281:     var fullrole = newrole+'./$cdom/$cnum';
                   3282:     var selidx = '';
                   3283:     for (var i=0; i<rolenames.length; i++) {
                   3284:         if (rolenames[i] == newrole) {
                   3285:             selidx = i;
                   3286:         }
                   3287:     }
1.350     raeburn  3288:     if (rolecheck > 0) {
                   3289:         for (var i=0; i<disallow.length; i++) {
                   3290:             if (disallow[i] == newrole) {
1.369.2.83.2.  (raeburn 3291:):                 if (confirm("$lt{'role'}\\n$displaymsg")) {
                   3292:):                     document.rolechooser.destinationurl.value = '$fallback';
1.350     raeburn  3293:                 } else {
                   3294:                     return;
                   3295:                 }
                   3296:             }
                   3297:         }
                   3298:     }
1.239     raeburn  3299:     var secok = 1;
                   3300:     var secchoice = '';
                   3301:     if (selidx >= 0) {
                   3302:         if (numsec[selidx] > 1) {
                   3303:             secok = 0;
                   3304:             var numrolesec = rolesections[selidx].length;
                   3305:             var msgidx = numsec[selidx] - numrolesec;
1.339     raeburn  3306:             secchoice = prompt("$lt{'this'} "+secpick[msgidx]+"\\n$lt{'avai'} "+roleseclist[selidx],"");
1.239     raeburn  3307:             if (secchoice == '') {
                   3308:                 if (msgidx > 0) {
                   3309:                     secok = 1;
                   3310:                 }
                   3311:             } else {
                   3312:                 for (var j=0; j<rolesections[selidx].length; j++) {
                   3313:                     if (rolesections[selidx][j] == secchoice) {
                   3314:                         secok = 1;
                   3315:                     }
                   3316:                 }
                   3317:             }
                   3318:         } else {
                   3319:             if (rolesections[selidx].length == 1) {
                   3320:                 secchoice = rolesections[selidx][0];
                   3321:             }
                   3322:         }
                   3323:     }
                   3324:     if (secok == 1) {
                   3325:         if (secchoice != '') {
                   3326:             fullrole += '/'+secchoice;
                   3327:         }
                   3328:     } else {
                   3329:         document.rolechooser.elements[roleitem].selectedIndex = 0;
                   3330:         if (secchoice != null) {
                   3331:             alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}");
                   3332:         }
                   3333:         return;
                   3334:     }
                   3335:     if (fullrole == "$env{'request.role'}") {
1.235     raeburn  3336:         return;
                   3337:     }
                   3338:     itemid = retrieveIndex('gotorole');
                   3339:     if (itemid != -1) {
1.239     raeburn  3340:         document.rolechooser.elements[itemid].name = fullrole;
1.235     raeburn  3341:     }
1.369.2.30  raeburn  3342:     document.rolechooser.switchrole.value = fullrole;
1.235     raeburn  3343:     document.rolechooser.selectrole.value = '1';
                   3344:     document.rolechooser.submit();
                   3345:     return;
                   3346: }
                   3347: 
                   3348: function retrieveIndex(item) {
                   3349:     for (var i=0;i<document.rolechooser.elements.length;i++) {
                   3350:         if (document.rolechooser.elements[i].name == item) {
                   3351:             return i;
                   3352:         }
                   3353:     }
                   3354:     return -1;
                   3355: }
1.273     droeschl 3356: // ]]>
1.235     raeburn  3357: </script>
                   3358: END
                   3359: }
                   3360: 
1.350     raeburn  3361: sub required_privs {
                   3362:     my $privs =  {
1.369.2.61  raeburn  3363:              '/adm/parmset'      => 'opa,vpa',
                   3364:              '/adm/courseprefs'  => 'opa,vpa',
1.350     raeburn  3365:              '/adm/whatsnew'     => 'whn',
1.369.2.65  raeburn  3366:              '/adm/populate'     => 'cst,vpa,vcl',
1.350     raeburn  3367:              '/adm/trackstudent' => 'vsa',
1.369.2.61  raeburn  3368:              '/adm/statistics'   => 'mgr,vgr',
                   3369:              '/adm/setblock'     => 'dcm,vcb',
1.367     raeburn  3370:              '/adm/coursedocs'   => 'mdc',
1.350     raeburn  3371:            };
                   3372:     unless ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'spreadsheet') {
1.364     raeburn  3373:         $privs->{'/adm/classcalc'}   = 'vgr',
                   3374:         $privs->{'/adm/assesscalc'}  = 'vgr',
                   3375:         $privs->{'/adm/studentcalc'} = 'vgr';
1.350     raeburn  3376:     }
                   3377:     return $privs;
                   3378: }
1.235     raeburn  3379: 
1.369.2.10  raeburn  3380: sub countdown_timer {
                   3381:     if (($env{'request.course.id'}) && ($env{'request.symb'} ne '') &&
1.369.2.24  raeburn  3382:         ($env{'request.filename'}=~/$LONCAPA::assess_re/)) {
                   3383:         my ($type,$hastimeleft,$slothastime);
                   3384:         my $now = time;
                   3385:         if ($env{'request.filename'} =~ /\.task$/) {
                   3386:             $type = 'Task';
                   3387:         } else {
                   3388:             $type = 'problem';
                   3389:         }
                   3390:         my ($status,$accessmsg,$slot_name,$slot) =
                   3391:             &Apache::lonhomework::check_slot_access('0',$type);
                   3392:         if ($slot_name ne '') {
                   3393:             if (ref($slot) eq 'HASH') {
                   3394:                 if (($slot->{'starttime'} < $now) &&
                   3395:                     ($slot->{'endtime'} > $now)) {
                   3396:                     $slothastime = 1;
                   3397:                 }
                   3398:             }
                   3399:         }
                   3400:         if ($status ne 'CAN_ANSWER') {
                   3401:             return;
                   3402:         }
1.369.2.10  raeburn  3403:         my $duedate = &Apache::lonnet::EXT("resource.0.duedate");
1.369.2.12  raeburn  3404:         my @interval=&Apache::lonnet::EXT("resource.0.interval");
1.369.2.83.2.  (raeburn 3405:):         my ($timelimit,$usesdone,$donebuttontext,$proctor,$secret);
1.369.2.13  raeburn  3406:         if (@interval > 1) {
1.369.2.83.2.  (raeburn 3407:):             ($timelimit,my $donesuffix) = split(/_/,$interval[0],2);
                   3408:):             if ($donesuffix =~ /^done\:([^\:]+)\:(.*)$/) {
                   3409:):                 $usesdone = 'done';
                   3410:):                 $donebuttontext = $1;
                   3411:):                 (undef,$proctor,$secret) = split(/_/,$2);
                   3412:):             } elsif ($donesuffix =~ /^done(|_.+)$/) {
                   3413:):                 $donebuttontext = &mt('Done');
                   3414:):                 ($usesdone,$proctor,$secret) = split(/_/,$donesuffix);
                   3415:):             }
1.369.2.13  raeburn  3416:             my $first_access=&Apache::lonnet::get_first_access($interval[1]);
                   3417:             if ($first_access > 0) {
1.369.2.83.2.  (raeburn 3418:):                 if ($first_access+$timelimit > time) {
1.369.2.13  raeburn  3419:                     $hastimeleft = 1;
                   3420:                 }
                   3421:             }
                   3422:         }
1.369.2.12  raeburn  3423:         if (($duedate && $duedate > time) ||
1.369.2.24  raeburn  3424:             (!$duedate && $hastimeleft) ||
                   3425:             ($slot_name ne '' && $slothastime)) {
1.369.2.83.2.  (raeburn 3426:):             my ($collapse,$expand,$alttxt,$title,$currdisp,$donebutton);
1.369.2.24  raeburn  3427:             if ((@interval > 1 && $hastimeleft) ||
                   3428:                 ($type eq 'Task' && $slothastime)) {
1.369.2.10  raeburn  3429:                 $currdisp = 'inline';
                   3430:                 $collapse = '&#9658;&nbsp;';
1.369.2.83.2.  (raeburn 3431:):                 if ((@interval > 1) && ($hastimeleft)) {
                   3432:):                     if ($usesdone eq 'done') {
                   3433:):                         $donebutton = &done_button_js($interval[1],'','',$proctor,$donebuttontext);
                   3434:):                     }
                   3435:):                 }
1.369.2.10  raeburn  3436:             } else {
                   3437:                 $currdisp = 'none';
                   3438:                 $expand = '&#9668;&nbsp;';
                   3439:             }
                   3440:             unless ($env{'environment.icons'} eq 'iconsonly') {
1.369.2.11  raeburn  3441:                 $alttxt = &mt('Timer');
                   3442:                 $title = $alttxt.'&nbsp;';
1.369.2.10  raeburn  3443:             }
                   3444:             my $desc = &mt('Countdown to due date/time');
                   3445:             return <<END;
1.369.2.83.2.  (raeburn 3446:): $donebutton
1.369.2.10  raeburn  3447: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
                   3448: <span id="ddcountcollapse" class="LC_menubuttons_inline_text">
                   3449: $collapse
1.369.2.11  raeburn  3450: </span></a>
1.369.2.10  raeburn  3451: <span id="duedatecountdown" class="LC_menubuttons_inline_text" style="display: $currdisp;"></span>
                   3452: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
                   3453: <span id="ddcountexpand" class="LC_menubuttons_inline_text" >$expand</span>
1.369.2.11  raeburn  3454: <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  3455: END
                   3456:         }
                   3457:     }
                   3458:     return;
                   3459: }
                   3460: 
1.369.2.83.2.  (raeburn 3461:): sub linkprot_exit {
                   3462:):     if (($env{'request.course.id'}) && ($env{'request.deeplink.login'})) {
                   3463:):         my ($deeplink_symb,$deeplink);
                   3464:):         my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                   3465:):         my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   3466:):         if (($cnum ne '') && ($cdom ne '')) {
                   3467:):             $deeplink_symb = &Apache::loncommon::deeplink_login_symb($cnum,$cdom);
                   3468:):             if ($deeplink_symb) {
                   3469:):                 if ($deeplink_symb =~ /\.(page|sequence)$/) {
                   3470:):                     my $mapname = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($deeplink_symb))[2]);
                   3471:):                     my $navmap = Apache::lonnavmaps::navmap->new();
                   3472:):                     if (ref($navmap)) {
                   3473:):                         $deeplink = $navmap->get_mapparam(undef,$mapname,'0.deeplink');
                   3474:):                     }
                   3475:):                 } else {
                   3476:):                     $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$deeplink_symb);
                   3477:):                 }
                   3478:):                 if ($deeplink ne '') {
                   3479:):                     my ($state,$others,$listed,$scope,$protect,$display,$target,$exit) = split(/,/,$deeplink);
                   3480:):                     my %lt = &Apache::lonlocal::texthash(
                   3481:):                         title    => 'Exit Tool',
                   3482:):                         okdone   => 'Click "OK" to exit embedded tool',
                   3483:):                         cancel   => 'Click "Cancel" to continue working.',
                   3484:):                         ok       => 'OK',
                   3485:):                         exit     => 'Cancel',
                   3486:):                     );
                   3487:):                     if ($exit) {
                   3488:):                         my ($show,$text) = split(/:/,$exit);
                   3489:):                         unless ($show eq 'no') {
                   3490:):                             my $height = 250;
                   3491:):                             my $width = 300;
                   3492:):                             my $exitbuttontext;
                   3493:):                             if ($text eq '') {
                   3494:):                                 $exitbuttontext = &mt('Exit Tool');
                   3495:):                             } else {
                   3496:):                                 $exitbuttontext = $text;
                   3497:):                             }
                   3498:):                             return <<END;
                   3499:): <form method="post" name="LCexitButton" action="/adm/linkexit">
                   3500:):     <input type="hidden" name="LC_deeplink_exit" value="" />
                   3501:):     <button id="LC_exit-confirm-opener" type="button">$exitbuttontext</button>
                   3502:): </form>
                   3503:): 
                   3504:): <div id="LC_exit-confirm" title="$lt{'title'}">
                   3505:):     <p>$lt{'okdone'} $lt{'cancel'}</p>
                   3506:): </div>
                   3507:): 
                   3508:): <script type="text/javascript">
                   3509:): // <![CDATA[
                   3510:): \$( "#LC_exit-confirm" ).dialog({ autoOpen: false });
                   3511:): \$( "#LC_exit-confirm-opener" ).click(function() {
                   3512:):     \$( "#LC_exit-confirm" ).dialog( "open" );
                   3513:):     \$( "#LC_exit-confirm" ).dialog({
                   3514:):       resizable: false,
                   3515:):       height: $height,
                   3516:):       width: $width,
                   3517:):       modal: true,
                   3518:):       buttons: [
                   3519:):                  {
                   3520:):                     text: "$lt{'ok'}",
                   3521:):                     click: function() {
                   3522:):                         \$( this ).dialog( "close" );
                   3523:):                         \$( '[name="LC_deeplink_exit"]' )[0].value = 'true';
                   3524:):                         \$( '[name="LCexitButton"]' )[0].submit();
                   3525:):                     },
                   3526:):                  },
                   3527:):                  {
                   3528:):                      text: "$lt{'exit'}",
                   3529:):                      click: function() {
                   3530:):                          \$( this ).dialog( "close" );
                   3531:):                      },
                   3532:):                   },
                   3533:):                ],
                   3534:):        });
                   3535:): });
                   3536:): // ]]>
                   3537:): </script>
                   3538:): 
                   3539:): END
                   3540:):                         }
                   3541:):                     }
                   3542:):                 }
                   3543:):             }
                   3544:):         }
                   3545:):     }
                   3546:):     return;
                   3547:): }
                   3548:): 
1.2       www      3549: # ================================================================ Main Program
                   3550: 
1.16      harris41 3551: BEGIN {
1.166     albertel 3552:     if (! defined($readdesk)) {
1.283     droeschl 3553:         {
                   3554:             my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
                   3555:             if ( CORE::open( my $config,"<$tabfile") ) {
                   3556:                 while (my $configline=<$config>) {
                   3557:                     $configline=(split(/\#/,$configline))[0];
                   3558:                     $configline=~s/^\s+//;
                   3559:                     chomp($configline);
1.209     www      3560:                     if ($configline=~/^cat\:/) {
1.283     droeschl 3561:                         my @entries=split(/\:/,$configline);
                   3562:                         $category_positions{$entries[2]}=$entries[1];
                   3563:                         $category_names{$entries[2]}=$entries[3];
                   3564:                     } elsif ($configline=~/^prim\:/) {
1.369.2.83.2.  (raeburn 3565:):                         my @entries = (split(/\:/, $configline))[1..7];
1.369.2.30  raeburn  3566:                         push(@primary_menu,\@entries);
1.369.2.3  raeburn  3567:                     } elsif ($configline=~/^primsub\:/) {
1.369.2.83.2.  (raeburn 3568:):                         my ($parent,@entries) = (split(/\:/, $configline))[1..5];
1.369.2.30  raeburn  3569:                         push(@{$primary_submenu{$parent}},\@entries);
1.283     droeschl 3570:                     } elsif ($configline=~/^scnd\:/) {
1.369.2.83.2.  (raeburn 3571:):                         my @entries = (split(/\:/, $configline))[1..6];
1.369.2.30  raeburn  3572:                         push(@secondary_menu,\@entries);
1.369.2.5  raeburn  3573:                     } elsif ($configline=~/^scndsub\:/) {
                   3574:                         my ($parent,@entries) = (split(/\:/, $configline))[1..4];
1.369.2.30  raeburn  3575:                         push(@{$secondary_submenu{$parent}},\@entries);
1.283     droeschl 3576:                     } elsif ($configline) {
                   3577:                         push(@desklines,$configline);
                   3578:                     }
                   3579:                 }
                   3580:                 CORE::close($config);
                   3581:             }
                   3582:         }
                   3583:         $readdesk='done';
1.2       www      3584:     }
                   3585: }
1.30      www      3586: 
1.1       www      3587: 1;
                   3588: __END__
                   3589: 

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