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

1.1       www         1: # The LearningOnline Network with CAPA
                      2: # Routines to control the menu
                      3: #
1.431.2.4! raeburn     4: # $Id: lonmenu.pm,v 1.431.2.3 2015/05/26 13:25:43 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.371     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.371     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.371     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.314     droeschl  102: =item prep_menuitems(\@menuitem)
                    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.415     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.415     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.375     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: 
                    127: Inputs: 4 - (a) link and (b) target for anchor href in top level item,
                    128:             (c) title for text wrapped by anchor tag in top level item.
                    129:             (d) reference to array of arrays of sub-menu items.
                    130: 
1.431     golterma  131:  The underlying datastructure used in (d) contains data from mydesk.tab.
                    132:  It consists of an array which has an array for each item appearing in
                    133:  the menu (e.g. [["link", "title", "condition"]] for a single-item menu).
                    134:  create_submenu() supports also the creation of XHTML for nested dropdown
                    135:  menus represented by unordered lists. This is done by replacing the
                    136:  scalar used for the link with an arrayreference containing the menuitems
                    137:  for the nested menu. This can be done recursively so that the next menu
                    138:  may also contain nested submenus.
                    139: 
                    140:  Example:
                    141:  [											# begin of datastructure
                    142: 	["/home/", "Home", "condition1"], 		# 1st item of the 1st layer menu
                    143: 	[										# 2nd item of the 1st layer menu
                    144: 		[									# anon. array for nested menu
                    145: 			["/path1", "Path1", undef], 	# 1st item of the 2nd layer menu
                    146: 			["/path2", "Path2", undef], 	# 2nd item of the 2nd layer menu
                    147: 			[								# 3rd item of the 2nd layer menu
                    148: 				[[...], [...], ..., [...]],	# containing another menu layer
                    149: 				"Sub-Sub-Menu",				# title for this container
                    150: 				undef
                    151: 			]
                    152: 		],									# end of array/nested menu
                    153: 		"Sub-Menu",							# title for the container item
                    154: 		undef
                    155: 	]										# end of 2nd item of the 1st layer menu
                    156: ]
                    157: 
1.244     jms       158: =item innerregister()
                    159: 
1.320     droeschl  160: This gets called in order to register a URL in the body of the document
1.244     jms       161: 
                    162: =item clear()
                    163: 
                    164: =item switch()
                    165: 
                    166: Switch a button or create a link
                    167: Switch acts on the javascript that is executed when a button is clicked.  
                    168: The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
                    169: 
                    170: =item secondlevel()
                    171: 
                    172: =item openmenu()
                    173: 
                    174: =item inlinemenu()
                    175: 
                    176: =item rawconfig()
                    177: 
                    178: =item utilityfunctions()
                    179: 
1.371     raeburn   180: Output from this routine is a number of javascript functions called by
                    181: items in the inline menu, and in some cases items in the Main Menu page. 
                    182: 
1.244     jms       183: =item serverform()
                    184: 
                    185: =item constspaceform()
                    186: 
                    187: =item get_nav_status()
                    188: 
                    189: =item hidden_button_check()
                    190: 
                    191: =item roles_selector()
                    192: 
                    193: =item jump_to_role()
                    194: 
                    195: =back
                    196: 
                    197: =cut
                    198: 
1.1       www       199: package Apache::lonmenu;
                    200: 
                    201: use strict;
1.152     albertel  202: use Apache::lonnet;
1.47      matthew   203: use Apache::lonhtmlcommon();
1.115     albertel  204: use Apache::loncommon();
1.127     albertel  205: use Apache::lonenc();
1.88      www       206: use Apache::lonlocal;
1.361     raeburn   207: use Apache::lonmsg();
1.207     foxr      208: use LONCAPA qw(:DEFAULT :match);
1.282     amueller  209: use HTML::Entities();
1.346     wenzelju  210: use Apache::lonwishlist();
1.88      www       211: 
1.283     droeschl  212: use vars qw(@desklines %category_names %category_members %category_positions 
1.371     raeburn   213:             $readdesk @primary_menu %primary_submenu @secondary_menu);
1.88      www       214: 
1.56      www       215: my @inlineremote;
1.38      www       216: 
1.283     droeschl  217: sub prep_menuitem {
1.291     raeburn   218:     my ($menuitem) = @_;
                    219:     return '' unless(ref($menuitem) eq 'ARRAY');
1.283     droeschl  220:     my $link;
                    221:     if ($$menuitem[1]) { # graphical Link
                    222:         $link = "<img class=\"LC_noBorder\""
1.291     raeburn   223:               . " src=\"" . &Apache::loncommon::lonhttpdurl($$menuitem[1]) . "\"" 
                    224:               . " alt=\"" . &mt($$menuitem[2]) . "\" />";
1.283     droeschl  225:     } else {             # textual Link
1.291     raeburn   226:         $link = &mt($$menuitem[3]);
                    227:     }
1.316     droeschl  228:     return '<li><a' 
                    229:            # highlighting for new messages
                    230:            . ( $$menuitem[4] eq 'newmsg' ? ' class="LC_new_message"' : '') 
1.325     droeschl  231:            . qq| href="$$menuitem[0]" target="_top">$link</a></li>|;
1.283     droeschl  232: }
                    233: 
1.415     raeburn   234: # primary_menu() evaluates @primary_menu and returns a two item array,
                    235: # with the array elements containing XHTML for the left and right sides of 
                    236: # the menu that contains the following links:
                    237: # Personal, About, Message, Roles, Help, Logout
1.283     droeschl  238: # @primary_menu is filled within the BEGIN block of this module with 
                    239: # entries from mydesk.tab
                    240: sub primary_menu {
1.415     raeburn   241:     my (%menu);
1.283     droeschl  242:     # each element of @primary contains following array:
1.415     raeburn   243:     # (link url, icon path, alt text, link text, condition, position)
1.319     raeburn   244:     my $public;
                    245:     if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
                    246:         || (($env{'user.name'} eq '') && ($env{'user.domain'} eq ''))) {
                    247:         $public = 1;
                    248:     }
1.283     droeschl  249:     foreach my $menuitem (@primary_menu) {
                    250:         # evaluate conditions 
1.296     droeschl  251:         next if    ref($menuitem)       ne 'ARRAY';    #
1.283     droeschl  252:         next if    $$menuitem[4]        eq 'nonewmsg'  # show links depending on
1.291     raeburn   253:                 && &Apache::lonmsg::mynewmail();       # whether a new msg 
1.283     droeschl  254:         next if    $$menuitem[4]        eq 'newmsg'    # arrived or not
1.291     raeburn   255:                 && !&Apache::lonmsg::mynewmail();      # 
1.319     raeburn   256:         next if    $$menuitem[4]        !~ /public/    ##we've a public user,
                    257:                 && $public;                            ##who should not see all
                    258:                                                        ##links
1.283     droeschl  259:         next if    $$menuitem[4]        eq 'onlypublic'# hide links which are 
1.319     raeburn   260:                 && !$public;                           # only visible to public
                    261:                                                        # users
1.283     droeschl  262:         next if    $$menuitem[4]        eq 'roles'     ##show links depending on
1.291     raeburn   263:                 && &Apache::loncommon::show_course();  ##term 'Courses' or 
1.283     droeschl  264:         next if    $$menuitem[4]        eq 'courses'   ##'Roles' wanted
1.291     raeburn   265:                 && !&Apache::loncommon::show_course(); ##
                    266:         
1.371     raeburn   267:         my $title = $menuitem->[3];
1.415     raeburn   268:         my $position = $menuitem->[5];
                    269:         if ($position eq '') {
                    270:             $position = 'right';
                    271:         }
1.371     raeburn   272:         if (defined($primary_submenu{$title})) {
1.375     raeburn   273:             my ($link,$target);
1.371     raeburn   274:             if ($menuitem->[0] ne '') {
                    275:                 $link = $menuitem->[0];
                    276:                 $target = '_top';
                    277:             } else {
                    278:                 $link = '#';
                    279:             }
1.375     raeburn   280:             my @primsub;
1.371     raeburn   281:             if (ref($primary_submenu{$title}) eq 'ARRAY') {
1.375     raeburn   282:                 foreach my $item (@{$primary_submenu{$title}}) {
1.383     raeburn   283:                     next if (($item->[2] eq 'wishlist') && (!$env{'user.adv'}));
1.375     raeburn   284:                     next if ((($item->[2] eq 'portfolio') ||
                    285:                              ($item->[2] eq 'blog')) &&
                    286:                              (!&Apache::lonnet::usertools_access('','',$item->[2],
                    287:                                                            undef,'tools')));
                    288:                     push(@primsub,$item);
                    289:                 }
                    290:                 if (@primsub > 0) {
1.419     bisitz    291:                     $menu{$position} .= &create_submenu($link,$target,$title,\@primsub,1);
1.375     raeburn   292:                 } elsif ($link) {
1.415     raeburn   293:                     $menu{$position} .= '<li><a href="'.$link.'" target="'.$target.'">'.&mt($title).'</a></li>';
1.371     raeburn   294:                 }
                    295:             }
                    296:         } elsif ($$menuitem[3] eq 'Help') { # special treatment for helplink
1.340     raeburn   297:             if ($public) {
                    298:                 my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
                    299:                 my $defdom = &Apache::lonnet::default_login_domain();
                    300:                 my $to = &Apache::loncommon::build_recipient_list(undef,
                    301:                                                                   'helpdeskmail',
                    302:                                                                   $defdom,$origmail);
                    303:                 if ($to ne '') {
1.415     raeburn   304:                     $menu{$position} .= &prep_menuitem($menuitem); 
1.340     raeburn   305:                 }
                    306:             } else {
1.415     raeburn   307:                 $menu{$position} .= '<li>'.&Apache::loncommon::top_nav_help('Help').'</li>';
1.340     raeburn   308:             }
1.283     droeschl  309:         } else {
1.415     raeburn   310:             $menu{$position} .= prep_menuitem($menuitem);
1.283     droeschl  311:         }
1.291     raeburn   312:     }
1.423     raeburn   313:     my @output = ('','');
                    314:     if ($menu{'left'} ne '') {
                    315:         $output[0] = "<ol class=\"LC_primary_menu LC_floatleft\">$menu{'left'}</ol>";
                    316:     }
                    317:     if ($menu{'right'} ne '') {
                    318:         $output[1] = "<ol class=\"LC_primary_menu LC_floatright LC_right\">$menu{'right'}</ol>";
                    319:     }
                    320:     return @output;
1.283     droeschl  321: }
                    322: 
1.329     droeschl  323: #returns hashref {user=>'',dom=>''} containing:
                    324: #   own name, domain if user is au
                    325: #   name, domain of parent author if user is ca or aa
                    326: #empty return if user is not an author or not on homeserver
                    327: #
                    328: #TODO this should probably be moved somewhere more central
                    329: #since it can be used by different parts of the system
                    330: sub getauthor{
                    331:     return unless $env{'request.role'}=~/^(ca|aa|au)/; #nothing to do if user isn't some kind of author
                    332: 
                    333:                         #co- or assistent author?
                    334:     my ($dom, $user) = ($env{'request.role'} =~ /^(?:ca|aa)\.\/($match_domain)\/($match_username)$/)
                    335:                        ? ($1, $2) #domain, username of the parent author
                    336:                        : @env{ ('request.role.domain', 'user.name') }; #own domain, username
                    337: 
                    338:     # current server == home server?
                    339:     my $home =  &Apache::lonnet::homeserver($user,$dom);
                    340:     foreach (&Apache::lonnet::current_machine_ids()){
                    341:         return {user => $user, dom => $dom} if $_ eq $home;
                    342:     }
                    343: 
                    344:     # if wrong server
                    345:     return;
                    346: }
1.283     droeschl  347: 
                    348: sub secondary_menu {
1.421     raeburn   349:     my ($httphost) = @_;
1.283     droeschl  350:     my $menu;
                    351: 
1.286     raeburn   352:     my $crstype = &Apache::loncommon::course_type();
1.327     droeschl  353:     my $crs_sec = $env{'request.course.id'} . ($env{'request.course.sec'} 
                    354:                                                ? "/$env{'request.course.sec'}"
                    355:                                                : '');
                    356:     my $canedit       = &Apache::lonnet::allowed('mdc', $env{'request.course.id'});
1.376     raeburn   357:     my $canviewroster = $env{'course.'.$env{'request.course.id'}.'.student_classlist_view'};
1.418     raeburn   358:     if ($canviewroster eq 'disabled') {
                    359:         undef($canviewroster);
                    360:     }
1.327     droeschl  361:     my $canviewgrps   = &Apache::lonnet::allowed('vcg', $crs_sec); 
                    362:     my $canmodifyuser = &Apache::lonnet::allowed('cst', $crs_sec); 
                    363:     my $canviewwnew   = &Apache::lonnet::allowed('whn', $crs_sec); 
1.341     www       364:     my $canmodpara    = &Apache::lonnet::allowed('opa', $crs_sec);
1.343     www       365:     my $canvgr        = &Apache::lonnet::allowed('vgr', $crs_sec);
                    366:     my $canmgr        = &Apache::lonnet::allowed('mgr', $crs_sec); 
                    367:     my $author        = &getauthor();
1.327     droeschl  368: 
1.417     raeburn   369:     my ($cdom,$cnum,$showsyllabus,$showfeeds,$showresv);
1.413     raeburn   370:     if ($env{'request.course.id'}) {
                    371:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                    372:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                    373:         if ($canedit) {
                    374:             $showsyllabus = 1;
                    375:             $showfeeds = 1;
                    376:         } else {
1.414     raeburn   377:             unless (&Apache::lonnet::is_on_map("public/$cdom/$cnum/syllabus")) {
                    378:                 if (($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'}) ||
                    379:                     ($env{'course.'.$env{'request.course.id'}.'.uploadedsyllabus'}) ||
                    380:                     ($env{'course.'.$env{'request.course.id'}.'.updatedsyllabus'}) ||
                    381:                     ($env{'request.course.syllabustime'})) {
                    382:                     $showsyllabus = 1;
                    383:                 }
                    384:             }
                    385:             if ($env{'request.course.feeds'}) {
                    386:                 $showfeeds = 1;
1.413     raeburn   387:             }
                    388:         }
1.417     raeburn   389:         unless ($canmgr) {
                    390:             my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
                    391:             if (keys(%slots) > 0) {
                    392:                 $showresv = 1;
                    393:             }
                    394:         }
1.413     raeburn   395:     }
                    396: 
1.404     raeburn   397:     my ($canmodifycoauthor); 
                    398:     if ($env{'request.role'} eq "au./$env{'user.domain'}/") {
                    399:         my $extent = "$env{'user.domain'}/$env{'user.name'}";
                    400:         if ((&Apache::lonnet::allowed('cca',$extent)) ||
                    401:             (&Apache::lonnet::allowed('caa',$extent))) {
                    402:             $canmodifycoauthor = 1;
                    403:         }
                    404:     }
                    405: 
1.286     raeburn   406:     my %groups = &Apache::lonnet::get_active_groups(
                    407:                      $env{'user.domain'}, $env{'user.name'},
                    408:                      $env{'course.' . $env{'request.course.id'} . '.domain'},
                    409:                      $env{'course.' . $env{'request.course.id'} . '.num'});
1.327     droeschl  410: 
1.401     raeburn   411:     my ($roleswitcher_js,$roleswitcher_form);
                    412: 
1.283     droeschl  413:     foreach my $menuitem (@secondary_menu) {
                    414:         # evaluate conditions 
1.296     droeschl  415:         next if    ref($menuitem)  ne 'ARRAY';
1.283     droeschl  416:         next if    $$menuitem[4]   ne 'always'
1.404     raeburn   417:                 && ($$menuitem[4]   ne 'author' && $$menuitem[4] ne 'cca')
1.283     droeschl  418:                 && !$env{'request.course.id'};
                    419:         next if    $$menuitem[4]   =~ /^mdc/
1.286     raeburn   420:                 && !$canedit;
1.341     www       421:         next if    $$menuitem[4]  eq 'nvgr'
                    422:                 && $canvgr;
                    423:         next if    $$menuitem[4]  eq 'vgr'
                    424:                 && !$canvgr;
1.327     droeschl  425:         next if    $$menuitem[4]   eq 'cst'
                    426:                 && !$canmodifyuser;
1.343     www       427:         next if    $$menuitem[4]   eq 'ncst'
1.376     raeburn   428:                 && ($canmodifyuser || !$canviewroster);
1.343     www       429:         next if    $$menuitem[4]   eq 'mgr'
                    430:                 && !$canmgr;
1.417     raeburn   431:         next if    $$menuitem[4]   eq 'showresv'
                    432:                 && !$showresv;
1.327     droeschl  433:         next if    $$menuitem[4]   eq 'whn'
                    434:                 && !$canviewwnew;
                    435:         next if    $$menuitem[4]   eq 'opa'
                    436:                 && !$canmodpara;
1.283     droeschl  437:         next if    $$menuitem[4]   =~ /showgroups$/
1.300     raeburn   438:                 && !$canviewgrps
1.286     raeburn   439:                 && !%groups;
1.413     raeburn   440:         next if    $$menuitem[4]   eq 'showsyllabus'
                    441:                 && !$showsyllabus;
                    442:         next if    $$menuitem[4]   eq 'showfeeds'
                    443:                 && !$showfeeds;
1.329     droeschl  444:         next if    $$menuitem[4]    eq 'author'
                    445:                 && !$author;
1.404     raeburn   446:         next if    $$menuitem[4]    eq 'cca'
                    447:                 && !$canmodifycoauthor;
1.283     droeschl  448: 
1.286     raeburn   449:         if ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) {
1.283     droeschl  450:             # special treatment for role selector
1.401     raeburn   451:             ($roleswitcher_js,$roleswitcher_form,my $switcher) =
                    452:                 &roles_selector(
1.283     droeschl  453:                         $env{'course.' . $env{'request.course.id'} . '.domain'},
1.421     raeburn   454:                         $env{'course.' . $env{'request.course.id'} . '.num'},
                    455:                         $httphost
1.401     raeburn   456:                 );
                    457:             $menu .= $switcher;
1.296     droeschl  458:         } else {
1.414     raeburn   459:             if ($$menuitem[3] eq 'Syllabus' && $env{'request.course.id'}) {
                    460:                 my $url = $$menuitem[0];
                    461:                 $url =~ s{\[cdom\]/\[cnum\]}{$cdom/$cnum};
                    462:                 if (&Apache::lonnet::is_on_map($url)) {
                    463:                     unless ($$menuitem[0] =~ /\?register=1/) {
                    464:                         $$menuitem[0] .= '?register=1';
                    465:                     }
                    466:                 } else {
                    467:                     $$menuitem[0] =~ s{\?register=1}{};
                    468:                 }
                    469:             }
1.296     droeschl  470:             $menu .= &prep_menuitem(\@$menuitem);
1.283     droeschl  471:         }
                    472:     }
                    473:     if ($menu =~ /\[url\].*\[symb\]/) {
1.291     raeburn   474:         my $escurl  = &escape( &Apache::lonenc::check_encrypt(
                    475:                              $env{'request.noversionuri'}));
1.283     droeschl  476: 
1.291     raeburn   477:         my $escsymb = &escape( &Apache::lonenc::check_encrypt(
                    478:                              $env{'request.symb'})); 
1.283     droeschl  479: 
                    480:         if (    $env{'request.state'} eq 'construct'
                    481:             and (   $env{'request.noversionuri'} eq '' 
                    482:                  || !defined($env{'request.noversionuri'}))) 
                    483:         {
1.359     raeburn   484:             my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
                    485:             ($escurl = $env{'request.filename'}) =~ s{^\Q$londocroot\E}{};
1.291     raeburn   486:             $escurl  = &escape($escurl);
1.283     droeschl  487:         }    
                    488:         $menu =~ s/\[url\]/$escurl/g;
                    489:         $menu =~ s/\[symb\]/$escsymb/g;
                    490:     }
1.329     droeschl  491:     $menu =~ s/\[uname\]/$$author{user}/g;
                    492:     $menu =~ s/\[udom\]/$$author{dom}/g;
1.413     raeburn   493:     if ($showsyllabus || $showfeeds) {
                    494:         $menu =~ s/\[cnum\]/$cnum/g;
                    495:         $menu =~ s/\[cdom\]/$cdom/g;
                    496:     }
1.385     raeburn   497:     if ($menu) {
                    498:         $menu = "<ul id=\"LC_secondary_menu\">$menu</ul>";
                    499:     }
1.401     raeburn   500:     if ($roleswitcher_form) {
                    501:         $menu .= "\n$roleswitcher_js\n$roleswitcher_form";
                    502:     }
1.385     raeburn   503:     return $menu;
1.283     droeschl  504: }
                    505: 
1.375     raeburn   506: sub create_submenu {
1.419     bisitz    507:     my ($link,$target,$title,$submenu,$translate) = @_;
1.375     raeburn   508:     return unless (ref($submenu) eq 'ARRAY');
1.379     raeburn   509:     my $disptarget;
                    510:     if ($target ne '') {
                    511:         $disptarget = ' target="'.$target.'"';
                    512:     }
1.415     raeburn   513:     my $name;
                    514:     if ($title eq 'Personal') {
                    515:         if ($env{'user.name'} && $env{'user.domain'}) {
                    516:             $name = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'});
                    517:         } else {
                    518:             $name = &mt($title);
                    519:         }
                    520:     } else {
                    521:         $name = &mt($title);
                    522:     }
1.375     raeburn   523:     my $menu = '<li class="LC_hoverable">'.
1.379     raeburn   524:                '<a href="'.$link.'"'.$disptarget.'>'.
1.415     raeburn   525:                '<span class="LC_nobreak">'.$name.
1.375     raeburn   526:                '<span class="LC_fontsize_small" style="font-weight:normal;">'.
                    527:                ' &#9660;</span></span></a>'.
                    528:                '<ul>';
1.431     golterma  529: 
                    530:     # $link and $title are only used in the initial string written in $menu
                    531:     # as seen above, not needed for nested submenus
                    532:     $menu .= &build_submenu($target, $submenu, $translate, '1');
                    533:     $menu .= '</ul></li>';
                    534: 
                    535:     return $menu;
                    536: }
                    537: 
                    538: # helper routine for create_submenu
                    539: # build the dropdown (and nested submenus) recursively
                    540: # see perldoc create_submenu documentation for further information
                    541: sub build_submenu {
                    542:     my ($target, $submenu, $translate, $first_level) = @_; 
                    543:     if (!defined(@{$submenu})) {
                    544:         return '';
                    545:     }
                    546: 
                    547:     my $menu = '';
1.375     raeburn   548:     my $count = 0;
                    549:     my $numsub = scalar(@{$submenu});
                    550:     foreach my $item (@{$submenu}) {
                    551:         $count ++;
                    552:         if (ref($item) eq 'ARRAY') {
1.416     raeburn   553:             my $href = $item->[0];
1.431     golterma  554:             my $bordertop;
                    555:             my $borderbot;
                    556:             my $title;
                    557: 
                    558:             if ($translate) {
                    559:                  $title = &mt($item->[1]);
                    560:             } else {
                    561:                 $title = $item->[1];
                    562:             }
                    563: 
                    564:             if ($count == 1 && !$first_level) {
                    565:                 $bordertop = 'border-top: 1px solid black;';
1.416     raeburn   566:             }
1.375     raeburn   567:             if ($count == $numsub) {
1.431     golterma  568:                 $borderbot = 'border-bottom: 1px solid black;';
1.375     raeburn   569:             }
1.431     golterma  570: 
                    571:             # href is a reference to another submenu
                    572:             if (ref($href) eq 'ARRAY') {
                    573:                 $menu .= '<li style="margin:0;padding:0;'.$bordertop . $borderbot . '">';
                    574:                 $menu .= '<p><span class="LC_primary_menu_innertitle">'
                    575: 					. $title . '</span><span class="LC_primary_menu_innerarrow">&#9654;</span></p>';
                    576:                 $menu .= '<ul>';
                    577:                 $menu .= &build_submenu($target, $href, $translate);
                    578:                 $menu .= '</ul>';
                    579:                 $menu .= '</li>';    
                    580:             } else {    # href is the actual hyperlink and does not represent another submenu
                    581:                         # for the current menu title
                    582:                 if ($href =~ /(aboutme|rss\.html)$/) {
                    583:                     next unless (($env{'user.name'} ne '') && ($env{'user.domain'} ne ''));
                    584:                     $href =~ s/\[domain\]/$env{'user.domain'}/g;
                    585:                     $href =~ s/\[user\]/$env{'user.name'}/g;
                    586:                 }
                    587:                 unless (($href eq '') || ($href =~ /^\#/)) {
                    588:                     $target = ' target="_top"';
                    589:                 }
                    590: 
                    591:                 $menu .= '<li style="margin:0;padding:0;'. $bordertop . $borderbot .'">';
                    592:                 $menu .= '<a href="'.$href.'"'.$target.'>' .  $title . '</a>';
                    593:                 $menu .= '</li>';
1.425     raeburn   594:             }
1.375     raeburn   595:         }
                    596:     }
                    597:     return $menu;
                    598: }
                    599: 
1.40      www       600: sub innerregister {
1.390     raeburn   601:     my ($forcereg,$bread_crumbs,$group) = @_;
1.152     albertel  602:     my $const_space = ($env{'request.state'} eq 'construct');
1.131     raeburn   603:     my $is_const_dir = 0;
1.120     raeburn   604: 
1.175     albertel  605:     if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
1.40      www       606: 
1.174     albertel  607:     $env{'request.registered'} = 1;
1.40      www       608: 
1.177     albertel  609:     undef(@inlineremote);
1.56      www       610: 
1.393     raeburn   611:     my ($mapurl,$resurl);
1.390     raeburn   612: 
1.393     raeburn   613:     if ($env{'request.course.id'}) {
                    614:         if ($env{'request.symb'}) {
                    615:             ($mapurl, my $rid, $resurl) = &Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
                    616:             my $coursetitle = $env{'course.'.$env{'request.course.id'}.'.description'};
1.267     droeschl  617: 
1.393     raeburn   618:             my $maptitle = &Apache::lonnet::gettitle($mapurl);
                    619:             my $restitle = &Apache::lonnet::gettitle(&Apache::lonnet::symbread());
1.318     droeschl  620: 
                    621: #SD
                    622: #course_type only Course and Community?
                    623: #
1.393     raeburn   624:             my @crumbs;
                    625:             unless (($forcereg) &&
                    626:                     ($env{'request.noversionuri'} eq '/adm/navmaps') &&
                    627:                     ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'})) {
                    628:                 @crumbs = ({text  => Apache::loncommon::course_type() 
                    629:                                     . ' Contents', 
                    630:                             href  => "Javascript:gopost('/adm/navmaps','')"});
                    631:             }
                    632:             if ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) { 
                    633:                 push(@crumbs, {text  => '...',
                    634:                                no_mt => 1});
                    635:             }
                    636: 
                    637:             push @crumbs, {text => $maptitle, no_mt => 1} if ($maptitle 
                    638:                                                        && $maptitle ne 'default.sequence' 
                    639:                                                        && $maptitle ne $coursetitle);
1.268     droeschl  640: 
1.393     raeburn   641:             push @crumbs, {text => $restitle, no_mt => 1} if $restitle; 
                    642:             &Apache::lonhtmlcommon::clear_breadcrumbs();
                    643:             &Apache::lonhtmlcommon::add_breadcrumb(@crumbs);
                    644:         } else {
                    645:             $resurl = $env{'request.noversionuri'};
                    646:             my $courseurl = &Apache::lonnet::courseid_to_courseurl($env{'request.course.id'});
                    647:             my $crstype = &Apache::loncommon::course_type();
                    648:             my $title = &mt('View Resource');
                    649:             if ($resurl =~ m{^\Q/uploaded$courseurl/supplemental/\E(default|\d+)/}) {
                    650:                 &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folderpath','title']);
1.392     raeburn   651:                 &Apache::lonhtmlcommon::clear_breadcrumbs();
1.393     raeburn   652:                 if ($env{'form.title'}) {
                    653:                     $title = $env{'form.title'};
                    654:                 }
1.394     raeburn   655:                 my $trail;
1.393     raeburn   656:                 if ($env{'form.folderpath'}) {
1.399     raeburn   657:                     &prepare_functions($resurl,$forcereg,$group,undef,undef,1);
1.394     raeburn   658:                     ($trail) =
1.393     raeburn   659:                         &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
                    660:                 } else {
                    661:                     &Apache::lonhtmlcommon::add_breadcrumb(
1.392     raeburn   662:                     {text  => "Supplemental $crstype Content",
                    663:                      href  => "javascript:gopost('/adm/supplemental','')"});
1.393     raeburn   664:                     $title = &mt('View Resource');
1.394     raeburn   665:                     ($trail) = 
                    666:                         &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
1.392     raeburn   667:                 }
1.394     raeburn   668:                 return $trail;
1.412     raeburn   669:             } elsif ($resurl =~ m{^\Q/uploaded$courseurl/portfolio/syllabus/}) {
                    670:                 &Apache::lonhtmlcommon::clear_breadcrumbs();
                    671:                 &prepare_functions('/public'.$courseurl."/syllabus",
                    672:                                    $forcereg,$group,undef,undef,1);
                    673:                 $title = &mt('Syllabus File');
                    674:                 my ($trail) =
                    675:                     &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
                    676:                 return $trail;
1.392     raeburn   677:             }
1.395     raeburn   678:             unless ($env{'request.state'} eq 'construct') {
                    679:                 &Apache::lonhtmlcommon::clear_breadcrumbs();
                    680:                 &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
                    681:             }
1.392     raeburn   682:         }
1.390     raeburn   683:     } elsif (! $const_space){
1.328     droeschl  684:         #a situation when we're looking at a resource outside of context of a 
                    685:         #course or construction space (e.g. with cumulative rights)
                    686:         &Apache::lonhtmlcommon::clear_breadcrumbs();
1.390     raeburn   687:         unless ($env{'request.noversionuri'} =~ m{^/adm/$match_domain/$match_username/aboutme$}) {
                    688:             &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
                    689:         }
1.65      www       690:     }
1.41      www       691: # =============================================================================
                    692: # ============================ This is for URLs that actually can be registered
1.316     droeschl  693:     return '' unless ( ($env{'request.noversionuri'}!~m{^/(res/)*adm/}) 
                    694:                        || $forcereg );
1.390     raeburn   695:     my ($cdom,$cnum,%perms,$cfile,$switchserver,$home,$forceedit,
                    696:         $forceview,$editbutton);
1.391     raeburn   697:     if (($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) ||
                    698:         ($env{'request.role'} !~/^(aa|ca|au)/)) {
1.390     raeburn   699:         $editbutton = &prepare_functions($resurl,$forcereg,$group);
                    700:     }
                    701:     if ($editbutton eq '') {
1.399     raeburn   702:         $editbutton = &clear(6,1);
1.390     raeburn   703:     }
1.317     droeschl  704: 
1.390     raeburn   705: #
                    706: # This applies in course context
                    707: #
                    708:     if ($env{'request.course.id'}) {
                    709:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                    710:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                    711:         $perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
                    712:         my @privs;
                    713:         if ($env{'request.symb'} ne '') {
                    714:              if ($env{'request.filename'}=~/$LONCAPA::assess_re/) {
                    715:                  push(@privs,('mgr','vgr'));
                    716:              }
                    717:              push(@privs,'opa');
                    718:         }
                    719:         foreach my $priv (@privs) {
                    720:             $perms{$priv} = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
                    721:             if (!$perms{$priv} && $env{'request.course.sec'} ne '') {
                    722:                 $perms{$priv} = 
                    723:                     &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
                    724:             }
                    725:         }
                    726: #
                    727: # Determine whether or not to show Grades and Submissions buttons
                    728: #
                    729:         if ($env{'request.symb'} ne '' &&
                    730:             $env{'request.filename'}=~/$LONCAPA::assess_re/) {
                    731:             if ($perms{'mgr'}) {
                    732:                 &switch('','',7,2,'pgrd.png','Content Grades','grades[_4]',
                    733:                         "gocmd('/adm/grades','gradingmenu')",
                    734:                         'Content Grades');
                    735:             } elsif ($perms{'vgr'}) {
                    736:                 &switch('','',7,2,'subm.png','Content Submissions','missions[_1]',
                    737:                         "gocmd('/adm/grades','submission')",
                    738:                         'Content Submissions');
                    739:              }
                    740:         }
                    741:         if (($env{'request.symb'} ne '') && ($perms{'opa'})) {
                    742:             &switch('','',7,3,'pparm.png','Content Settings','parms[_2]',
                    743:                     "gocmd('/adm/parmset','set')",
                    744:                     'Content Settings');
1.107     albertel  745: 	}
1.393     raeburn   746: # End grades/submissions check
1.107     albertel  747: 
1.274     www       748: #
1.393     raeburn   749: # This applies to items inside a folder/page modifiable in the course.
1.274     www       750: #
1.390     raeburn   751:         if (($env{'request.symb'}=~/^uploaded/) && ($perms{'mdc'})) {
1.393     raeburn   752:             my $text = 'Edit Folder';
1.395     raeburn   753:             if (($mapurl =~ /\.page$/) ||
                    754:                 ($env{'request.symb'}=~
1.396     raeburn   755:                      m{uploaded/$cdom/$cnum/default_\d+\.page$}))  {
1.393     raeburn   756:                 $text = 'Edit Page';
                    757:             }
                    758:             &switch('','',7,4,'docs-22x22.png',$text,'parms[_2]',
1.390     raeburn   759:                     "gocmd('/adm/coursedocs','direct')",
                    760:                     'Folder/Page Content');
1.258     raeburn   761:         }
1.390     raeburn   762: # End modifiable folder/page container check
                    763:     }
                    764: # End course context
                    765: 
1.41      www       766: # Prepare the rest of the buttons
1.383     raeburn   767:         my ($menuitems,$got_prt,$got_wishlist);
1.120     raeburn   768:         if ($const_space) {
1.274     www       769: #
                    770: # We are in construction space
                    771: #
1.353     www       772: 
1.355     raeburn   773:             my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.353     www       774: 	    my ($udom,$uname,$thisdisfn) =
1.355     raeburn   775: 		($env{'request.filename'}=~m{^\Q$londocroot/priv/\E([^/]+)/([^/]+)/(.*)$});
1.353     www       776:             my $currdir = '/priv/'.$udom.'/'.$uname.'/'.$thisdisfn;
1.131     raeburn   777:             if ($currdir =~ m-/$-) {
                    778:                 $is_const_dir = 1;
1.431.2.4! raeburn   779:                 if ($thisdisfn eq '') {
        !           780:                     $is_const_dir = 2;
        !           781:                 }
1.131     raeburn   782:             } else {
1.267     droeschl  783:                 $currdir =~ s|[^/]+$||;
1.200     foxr      784: 		my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn);
1.208     albertel  785: 		my $esc_currdir = &Apache::loncommon::escape_single($currdir);
1.274     www       786: #
                    787: # Probably should be in mydesk.tab
                    788: #
1.131     raeburn   789:                 $menuitems=(<<ENDMENUITEMS);
1.344     www       790: s&6&1&list.png&Directory&dir[_1]&golist('$esc_currdir')&List current directory
1.353     www       791: s&6&2&rtrv.png&Retrieve&version[_1]&gocstr('/adm/retrieve','/priv/$udom/$uname/$cleandisfn')&Retrieve old version
                    792: s&6&3&pub.png&Publish&resource[_3]&gocstr('/adm/publish','/priv/$udom/$uname/$cleandisfn')&Publish this resource
                    793: s&7&1&del.png&Delete&resource[_2]&gocstr('/adm/cfile?action=delete','/priv/$udom/$uname/$cleandisfn')&Delete this resource
                    794: s&7&2&prt.png&Print&printout[_1]&gocstr('/adm/printout','/priv/$udom/$uname/$cleandisfn')&Prepare a printable document
1.120     raeburn   795: ENDMENUITEMS
1.131     raeburn   796:             }
1.308     raeburn   797:                 if (ref($bread_crumbs) eq 'ARRAY') {
                    798:                     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    799:                     foreach my $crumb (@{$bread_crumbs}){
                    800:                         &Apache::lonhtmlcommon::add_breadcrumb($crumb);
                    801:                     }
                    802:                 }
1.203     foxr      803:         } elsif ( defined($env{'request.course.id'}) && 
                    804: 		 $env{'request.symb'} ne '' ) {
1.274     www       805: #
1.383     raeburn   806: # We are in a course and looking at a registered URL
1.274     www       807: # Should probably be in mydesk.tab
                    808: #
1.120     raeburn   809: 	    $menuitems=(<<ENDMENUITEMS);
1.41      www       810: c&3&1
1.344     www       811: s&2&1&back.png&&&gopost('/adm/flip','back:'+currentURL)&Previous content resource&&1
                    812: s&2&3&forw.png&&&gopost('/adm/flip','forward:'+currentURL)&Next content resource&&3
1.77      www       813: c&6&3
                    814: c&8&1
                    815: c&8&2
1.344     www       816: s&8&3&prt.png&Print&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
1.41      www       817: ENDMENUITEMS
1.383     raeburn   818:             $got_prt = 1;
                    819:             if (($env{'user.adv'}) && ($env{'request.uri'} =~ /^\/res/)
                    820:                 && (!$env{'request.enc'})) {
1.332     wenzelju  821:                 # wishlist is only available for users with access to resource-pool
                    822:                 # and links can only be set for resources within the resource-pool
                    823:                 $menuitems .= (<<ENDMENUITEMS);
1.431     golterma  824: s&9&1&wishlist-link.png&Stored Links&wishlistlink[_2]&set_wishlistlink()&Save a link for this resource in my personal Stored Links repository&&1
1.332     wenzelju  825: ENDMENUITEMS
1.383     raeburn   826:                 $got_wishlist = 1;
1.332     wenzelju  827:             }
1.216     albertel  828: 
1.243     tempelho  829: my $currentURL = &Apache::loncommon::get_symb();
                    830: my ($symb_old,$symb_old_enc) = &Apache::loncommon::clean_symb($currentURL);
                    831: my $annotation = &Apache::loncommon::get_annotation($symb_old,$symb_old_enc);
                    832: $menuitems.="s&9&3&";
                    833: if(length($annotation) > 0){
1.317     droeschl  834: 	$menuitems.="anot2.png";
1.243     tempelho  835: }else{
1.317     droeschl  836: 	$menuitems.="anot.png";
1.243     tempelho  837: }
1.344     www       838: $menuitems.="&Notes&&annotate()&";
1.243     tempelho  839: $menuitems.="Make notes and annotations about this resource&&1\n";
1.428     raeburn   840: my $is_mobile;
                    841: if ($env{'browser.mobile'}) {
                    842:     $is_mobile = 1;
                    843: }
1.243     tempelho  844: 
1.323     raeburn   845:             unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|viewclasslist|portfolio)(\?|$)/) {
1.382     raeburn   846: 		if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/}) && ($env{'request.noversionuri'} !~ m{^/uploaded/$match_domain/$match_courseid/docs/})) {
1.216     albertel  847: 		    $menuitems.=(<<ENDREALRES);
1.428     raeburn   848: s&6&3&catalog.png&Info&info[_1]&catalog_info('$is_mobile')&Show Metadata
1.216     albertel  849: ENDREALRES
                    850:                 }
1.422     raeburn   851:                 unless (($env{'request.noversionuri'} =~ m{^/uploaded/$match_domain/$match_courseid/docs/}) ||
                    852:                         ($env{'request.noversionuri'} =~ m{^\Q/adm/wrapper/\E(ext|uploaded)/})) {  
1.382     raeburn   853:                     $menuitems.=(<<ENDREALRES);
1.344     www       854: s&8&1&eval.png&Evaluate&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
1.382     raeburn   855: ENDREALRES
                    856:                 }
1.422     raeburn   857:                 unless ($env{'request.noversionuri'} =~ m{^\Q/adm/wrapper/\E(ext|uploaded)/}) {
                    858:                     $menuitems.=(<<ENDREALRES);
1.344     www       859: s&8&2&fdbk.png&Communicate&discuss[_1]&gopost('/adm/feedback',currentURL,1)&Provide feedback messages or contribute to the course discussion about this resource
1.77      www       860: ENDREALRES
1.422     raeburn   861:                 }
1.120     raeburn   862: 	    }
                    863:         }
1.203     foxr      864: 	if ($env{'request.uri'} =~ /^\/res/) {
1.383     raeburn   865:             unless ($got_prt) {
                    866: 	        $menuitems .= (<<ENDMENUITEMS);
1.344     www       867: s&8&3&prt.png&Print&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
1.203     foxr      868: ENDMENUITEMS
1.384     raeburn   869:                 $got_prt = 1;
1.383     raeburn   870:             }
                    871:             unless ($got_wishlist) {
                    872:                 if (($env{'user.adv'}) && (!$env{'request.enc'})) {
                    873:                     # wishlist is only available for users with access to resource-pool
                    874:                     $menuitems .= (<<ENDMENUITEMS);
1.431     golterma  875: s&9&1&wishlist-link.png&Stored Links&wishlistlink[_2]&set_wishlistlink()&Save a link for this resource in your personal Stored Links repository&&1
1.332     wenzelju  876: ENDMENUITEMS
1.383     raeburn   877:                     $got_wishlist = 1;
                    878:                 }
                    879: 	    }
                    880:         }
1.41      www       881:         my $buttons='';
                    882:         foreach (split(/\n/,$menuitems)) {
                    883: 	    my ($command,@rest)=split(/\&/,$_);
1.220     raeburn   884:             my $idx=10*$rest[0]+$rest[1];
                    885:             if (&hidden_button_check() eq 'yes') {
                    886:                 if ($idx == 21 ||$idx == 23) {
                    887:                     $buttons.=&switch('','',@rest);
                    888:                 } else {
                    889:                     $buttons.=&clear(@rest);
                    890:                 }
                    891:             } else {  
                    892:                 if ($command eq 's') {
                    893: 	            $buttons.=&switch('','',@rest);
                    894:                 } else {
                    895:                     $buttons.=&clear(@rest);
                    896:                 }
1.41      www       897:             }
                    898:         }
1.148     albertel  899: 
                    900: 	    my $addremote=0;
1.267     droeschl  901: 	    foreach (@inlineremote) { if ($_ ne '') { $addremote=1; last;} }
1.301     droeschl  902:     if ($addremote) {
                    903: 
1.342     www       904:         &Apache::lonhtmlcommon::clear_breadcrumb_tools();
1.301     droeschl  905: 
1.342     www       906:             &Apache::lonhtmlcommon::add_breadcrumb_tool(
1.312     droeschl  907:                 'navigation', @inlineremote[21,23]);
                    908: 
1.378     raeburn   909:         my $countdown = &countdown_timer();
                    910:         if (&hidden_button_check() eq 'yes') {
                    911:             if ($countdown) {
                    912:                 &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$countdown);
                    913:             }
                    914:         } else {
                    915:             my @tools = @inlineremote[93,91,81,82,83];
                    916:             if ($countdown) {
                    917:                 unshift(@tools,$countdown);
                    918:             }
1.342     www       919:             &Apache::lonhtmlcommon::add_breadcrumb_tool(
1.378     raeburn   920:                 'tools',@tools);
1.313     droeschl  921: 
                    922:             #publish button in construction space
                    923:             if ($env{'request.state'} eq 'construct'){
1.342     www       924:                 &Apache::lonhtmlcommon::add_breadcrumb_tool(
1.349     raeburn   925:                      'advtools', $inlineremote[63]);
1.342     www       926:             } else {
                    927:                 &Apache::lonhtmlcommon::add_breadcrumb_tool(
1.349     raeburn   928:                      'tools', $inlineremote[63]);
1.313     droeschl  929:             }
1.390     raeburn   930:             &advtools_crumbs(@inlineremote);
1.301     droeschl  931:         }
1.38      www       932:     }
1.431.2.4! raeburn   933:     my ($topic_help,$topic_help_text);
        !           934:     if ($is_const_dir == 2) {
        !           935:         if ((($ENV{'SERVER_PORT'} == 443) ||
        !           936:              ($Apache::lonnet::protocol{$Apache::lonnet::perlvar{'lonHostID'}} eq 'https')) &&
        !           937:             (&Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},'webdav'))) {
        !           938:             $topic_help = 'Authoring_WebDAV,Authoring_WebDAV_Mac_10v6,Authoring_WebDAV_Mac_10v10,'.
        !           939:                           'Authoring_WebDAV_Windows_v7,Authoring_WebDAV_Linux_Centos';
        !           940:             $topic_help_text = 'About WebDAV access';
        !           941:         }
        !           942:     }
1.342     www       943:     return   &Apache::lonhtmlcommon::scripttag('', 'start')
1.431.2.4! raeburn   944:            . &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0,'','','','',$topic_help,$topic_help_text)
1.342     www       945:            . &Apache::lonhtmlcommon::scripttag('', 'end');
1.38      www       946: }
                    947: 
1.389     raeburn   948: sub get_editbutton {
1.390     raeburn   949:     my ($cfile,$home,$switchserver,$forceedit,$forceview,$forcereg) = @_;
1.398     raeburn   950:     my $jscall;
                    951:     if (($forceview) && ($env{'form.todocs'})) {
                    952:         my ($folderpath,$command);
                    953:         if ($env{'request.symb'}) {
                    954:             $folderpath = &Apache::loncommon::symb_to_docspath($env{'request.symb'});
                    955:         } elsif ($env{'form.folderpath'} =~ /^supplemental/) {
                    956:             $folderpath = $env{'form.folderpath'};
                    957:             $command = '&forcesupplement=1';
                    958:         }
                    959:         $folderpath = &escape(&HTML::Entities::encode(&escape($folderpath),'<>&"'));
                    960:         $jscall = "go('/adm/coursedocs?folderpath=$folderpath$command')";
                    961:     } else {
                    962:         $jscall = &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,$switchserver,
1.393     raeburn   963:                                                 $forceedit,$forcereg,$env{'request.symb'},
                    964:                                                 &escape($env{'form.folderpath'}),
                    965:                                                 &escape($env{'form.title'}),$env{'form.idx'},
1.398     raeburn   966:                                                 &escape($env{'form.suppurl'},$env{'form.todocs'}));
                    967:     }
1.389     raeburn   968:     if ($jscall) {
1.390     raeburn   969:         my $icon = 'pcstr.png';
                    970:         my $label = 'Edit';
                    971:         if ($forceview) {
                    972:             $icon = 'tolastloc.png';
                    973:             $label = 'Exit Editing';
                    974:         }
                    975:         &switch('','',6,1,$icon,$label,'resource[_2]',
                    976:                 $jscall,"Edit this resource");
                    977:         return 1;
                    978:     }
                    979:     return;
                    980: }
                    981: 
                    982: sub prepare_functions {
1.393     raeburn   983:     my ($resurl,$forcereg,$group,$bread_crumbs,$advtools,$docscrumbs) = @_;
1.390     raeburn   984:     unless ($env{'request.registered'}) {
                    985:         undef(@inlineremote);
                    986:     }
                    987:     my ($cdom,$cnum,%perms,$cfile,$switchserver,$home,$forceedit,
                    988:         $forceview);
                    989: 
                    990:     if ($env{'request.course.id'}) {
                    991:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                    992:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                    993:         $perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
                    994:     }
                    995: 
                    996:     my $editbutton = '';
                    997: #
                    998: # Determine whether or not to display 'Edit' icon/button
                    999: #
                   1000:     if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
                   1001:         my $file=&Apache::lonnet::declutter($env{'request.filename'});
1.391     raeburn  1002:         ($cfile,$home,$switchserver,$forceedit,$forceview) =
                   1003:             &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
                   1004:                 &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
                   1005:         if (($cfile) && ($home ne '') && ($home ne 'no_host')) {
                   1006:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
1.390     raeburn  1007:                                           $forceedit,$forceview,$forcereg);
                   1008:         }
1.391     raeburn  1009:     } elsif ((!$env{'request.course.id'}) &&
1.390     raeburn  1010:              ($env{'user.author'}) && ($env{'request.filename'}) &&
                   1011:              ($env{'request.role'} !~/^(aa|ca|au)/)) {
                   1012: #
                   1013: # Currently do not have the role of author or co-author.
                   1014: # Do we have authoring privileges for the resource?
                   1015: #
                   1016:         my $file=&Apache::lonnet::declutter($env{'request.filename'});
                   1017:         ($cfile,$home,$switchserver,$forceedit,$forceview) =
                   1018:             &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
                   1019:                 &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
                   1020:         if (($cfile) && ($home ne '') && ($home ne 'no_host')) {
                   1021:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
                   1022:                                           $forceedit,$forceview,$forcereg);
                   1023:         }
                   1024:     } elsif ($env{'request.course.id'}) {
                   1025: #
                   1026: # This applies in course context
                   1027: #
1.412     raeburn  1028:         if (($perms{'mdc'}) &&
                   1029:             (($resurl eq "/public/$cdom/$cnum/syllabus") ||
                   1030:             ($resurl =~ m{^/uploaded/$cdom/$cnum/portfolio/syllabus/}))) {
1.411     raeburn  1031:             $cfile = $resurl;
                   1032:             $home = &Apache::lonnet::homeserver($cnum,$cdom);
                   1033:             if ($env{'form.forceedit'}) {
                   1034:                 $forceview = 1;
1.390     raeburn  1035:             } else {
1.411     raeburn  1036:                 $forceedit = 1;
1.390     raeburn  1037:             }
1.411     raeburn  1038:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
                   1039:                                           $forceedit,$forceview,$forcereg);
1.393     raeburn  1040:         } elsif (($resurl eq '/adm/extresedit') &&
                   1041:                  (($env{'form.symb'}) || ($env{'form.folderpath'}))) {
                   1042:             ($cfile,$home,$switchserver,$forceedit,$forceview) =
                   1043:             &Apache::lonnet::can_edit_resource($resurl,$cnum,$cdom,$resurl,
                   1044:                                                $env{'form.symb'});
                   1045:             if ($cfile ne '') {
                   1046:                 $editbutton = &get_editbutton($cfile,$home,$switchserver,
                   1047:                                               $forceedit,$forceview,$forcereg,
                   1048:                                               $env{'form.title'},$env{'form.suppurl'});
                   1049:             }
1.406     raeburn  1050:         } elsif (($resurl =~ m{^/?adm/viewclasslist$}) &&
                   1051:                  (&Apache::lonnet::allowed('opa',$env{'request.course.id'}))) {
                   1052:             ($cfile,$home,$switchserver,$forceedit,$forceview) =
                   1053:             &Apache::lonnet::can_edit_resource($resurl,$cnum,$cdom,$resurl,
                   1054:                                                $env{'form.symb'});
                   1055:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
                   1056:                                           $forceedit,$forceview,$forcereg);
1.405     raeburn  1057:         } elsif (($resurl !~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) &&
                   1058:                  ($resurl ne '/cgi-bin/printout.pl')) {
1.390     raeburn  1059:             if ($env{'request.filename'}) {
                   1060:                 my $file=&Apache::lonnet::declutter($env{'request.filename'});
                   1061:                 ($cfile,$home,$switchserver,$forceedit,$forceview) =
                   1062:                     &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
                   1063:                         &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
                   1064:                 if ($cfile ne '') {
                   1065:                     $editbutton = &get_editbutton($cfile,$home,$switchserver,
                   1066:                                                   $forceedit,$forceview,$forcereg);
                   1067:                 }
                   1068:             }
                   1069:         }
                   1070:     }
                   1071: # End determination of 'Edit' icon/button display
                   1072: 
1.393     raeburn  1073:     if ($env{'request.course.id'}) {
1.390     raeburn  1074: # This applies to about me page for users in a course
1.391     raeburn  1075:         if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
1.390     raeburn  1076:             my ($sdom,$sname) = ($1,$2);
                   1077:             unless (&Apache::lonnet::is_course($sdom,$sname)) {
                   1078:                 &switch('','',6,4,'mail-message-new-22x22.png','Message to user',
                   1079:                         '',
1.415     raeburn  1080:                         "go('/adm/email?compose=individual&amp;recname=$sname&amp;recdom=$sdom')",
1.390     raeburn  1081:                             'Send message to specific user');
                   1082:             }
1.391     raeburn  1083:             my $hideprivileged = 1;
                   1084:             if (&Apache::lonnet::in_course($sdom,$sname,$cdom,$cnum,undef,
                   1085:                                            $hideprivileged)) {
1.390     raeburn  1086:                 foreach my $priv ('vsa','vgr','srm') {
                   1087:                     $perms{$priv} = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
                   1088:                     if (!$perms{$priv} && $env{'request.course.sec'} ne '') {
                   1089:                         $perms{$priv} =
                   1090:                             &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
                   1091:                     }
                   1092:                 }
                   1093:                 if ($perms{'vsa'}) {
                   1094:                     &switch('','',6,5,'trck-22x22.png','Activity',
                   1095:                             '',
                   1096:                             "go('/adm/trackstudent?selected_student=$sname:$sdom')",
                   1097:                             'View recent activity by this person');
                   1098:                 }
                   1099:                 if ($perms{'vgr'}) {
                   1100:                     &switch('','',6,6,'rsrv-22x22.png','Reservations',
                   1101:                             '',
1.415     raeburn  1102:                             "go('/adm/slotrequest?command=showresv&amp;origin=aboutme&amp;uname=$sname&amp;udom=$sdom')",
1.390     raeburn  1103:                             'Slot reservation history');
                   1104:                 }
                   1105:                 if ($perms{'srm'}) {
                   1106:                     &switch('','',6,7,'contact-new-22x22.png','Records',
                   1107:                             '',
1.415     raeburn  1108:                             "go('/adm/email?recordftf=retrieve&amp;recname=$sname&amp;recdom=$sdom')",
1.390     raeburn  1109:                             'Add records');
                   1110:                 }
                   1111:             }
1.393     raeburn  1112:         }
                   1113:         if (($env{'form.folderpath'} =~ /^supplemental/) &&
                   1114:             (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) &&
                   1115:             (($resurl =~ m{^/adm/wrapper/ext/}) ||
                   1116:              ($resurl =~ m{^/uploaded/$cdom/$cnum/supplemental/}) ||
1.397     raeburn  1117:              ($resurl eq '/adm/supplemental') ||
                   1118:              ($resurl =~ m{^/public/$cdom/$cnum/syllabus$}) ||
                   1119:              ($resurl =~ m{^/adm/$match_domain/$match_username/aboutme$}))) {
1.393     raeburn  1120:             my @folders=split('&',$env{'form.folderpath'});
1.394     raeburn  1121:             if ((@folders > 2) || ($resurl ne '/adm/supplemental')) {
1.393     raeburn  1122:                 my $esc_path=&escape(&HTML::Entities::encode(&escape($env{'form.folderpath'}),'<>&"'));
                   1123:                 &switch('','',7,4,'docs-22x22.png','Edit Folder','parms[_2]',
1.415     raeburn  1124:                         "location.href='/adm/coursedocs?command=direct&amp;forcesupplement=1&amp;supppath=$esc_path'",
1.393     raeburn  1125:                         'Folder/Page Content');
                   1126:             }
1.390     raeburn  1127:         }
                   1128:     }
                   1129: 
                   1130: # End checking for items for about me page for users in a course
1.393     raeburn  1131:     if ($docscrumbs) {
                   1132:         &Apache::lonhtmlcommon::clear_breadcrumb_tools();
                   1133:         &advtools_crumbs(@inlineremote);
                   1134:         return $editbutton;
                   1135:     } elsif ($env{'request.registered'}) {
1.390     raeburn  1136:         return $editbutton;
                   1137:     } else {
                   1138:         if (ref($bread_crumbs) eq 'ARRAY') {
                   1139:             if (@inlineremote > 0) {
                   1140:                 if (ref($advtools) eq 'ARRAY') {
                   1141:                     @{$advtools} = @inlineremote;
                   1142:                 }
                   1143:             }
                   1144:             return;
                   1145:         } elsif (@inlineremote > 0) {
                   1146:             &Apache::lonhtmlcommon::clear_breadcrumb_tools();
                   1147:             &advtools_crumbs(@inlineremote);
                   1148:             return   &Apache::lonhtmlcommon::scripttag('', 'start')
                   1149:                    . &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
                   1150:                    . &Apache::lonhtmlcommon::scripttag('', 'end');
                   1151:         }
                   1152:     }
                   1153: }
                   1154: 
                   1155: sub advtools_crumbs {
                   1156:     my @funcs = @_;
                   1157:     if ($env{'request.noversionuri'} =~ m{^/adm/$match_domain/$match_username/aboutme$}) {
                   1158:         &Apache::lonhtmlcommon::add_breadcrumb_tool(
                   1159:             'advtools', @funcs[61,64,65,66,67,74]);
                   1160:     } elsif ($env{'request.noversionuri'} !~ m{^/adm/(navmaps|viewclasslist)(\?|$)}) {
                   1161:         &Apache::lonhtmlcommon::add_breadcrumb_tool(
                   1162:             'advtools', @funcs[61,71,72,73,74,92]);
1.393     raeburn  1163:     } elsif ($env{'request.noversionuri'} eq '/adm/viewclasslist') {
                   1164:         &Apache::lonhtmlcommon::add_breadcrumb_tool(
1.407     raeburn  1165:             'advtools', $funcs[61]);
1.393     raeburn  1166:     }
1.412     raeburn  1167:     return;
1.258     raeburn  1168: }
                   1169: 
1.2       www      1170: # ================================================================== Raw Config
                   1171: 
1.3       www      1172: sub clear {
                   1173:     my ($row,$col)=@_;
1.316     droeschl 1174:     $inlineremote[10*$row+$col]='';
                   1175:     return ''; 
1.3       www      1176: }
                   1177: 
1.40      www      1178: # ============================================ Switch a button or create a link
1.25      matthew  1179: # Switch acts on the javascript that is executed when a button is clicked.  
                   1180: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
1.40      www      1181: 
1.2       www      1182: sub switch {
1.209     www      1183:     my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak)=@_;
1.2       www      1184:     $act=~s/\$uname/$uname/g;
                   1185:     $act=~s/\$udom/$udom/g;
1.88      www      1186:     $top=&mt($top);
                   1187:     $bot=&mt($bot);
                   1188:     $desc=&mt($desc);
1.209     www      1189:     my $idx=10*$row+$col;
                   1190:     $category_members{$cat}.=':'.$idx;
                   1191: 
1.320     droeschl 1192: # Inline Menu
1.317     droeschl 1193:     if ($nobreak==2) { return ''; }
                   1194:     my $text=$top.' '.$bot;
                   1195:     $text=~s/\s*\-\s*//gs;
1.105     www      1196: 
1.317     droeschl 1197:     my $pic=
1.225     albertel 1198: 	   '<img alt="'.$text.'" src="'.
                   1199: 	   &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
1.303     droeschl 1200: 	   '" align="'.($nobreak==3?'right':'left').'" class="LC_icon" />';
1.317     droeschl 1201:     if ($env{'browser.interface'} eq 'faketextual') {
1.274     www      1202: # Main Menu
1.103     www      1203: 	   if ($nobreak==3) {
1.209     www      1204: 	       $inlineremote[$idx]="\n".
1.177     albertel 1205: 		   '<td class="LC_menubuttons_text" align="right">'.$text.
1.247     harmsja  1206: 		   '</td><td align="left">'.
1.103     www      1207: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
                   1208: 	   } elsif ($nobreak) {
1.209     www      1209: 	       $inlineremote[$idx]="\n<tr>".
1.247     harmsja  1210: 		   '<td align="left">'.
1.177     albertel 1211: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td>
1.215     www      1212:                     <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      1213: 	   } else {
1.209     www      1214: 	       $inlineremote[$idx]="\n<tr>".
1.247     harmsja  1215: 		   '<td align="left">'.
1.103     www      1216: 		   '<a href="javascript:'.$act.';">'.$pic.
1.177     albertel 1217: 		   '</a></td><td class="LC_menubuttons_text" colspan="3">'.
1.215     www      1218: 		   '<a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$desc.'</span></a></td></tr>';
1.103     www      1219: 	   }
1.317     droeschl 1220:     } else {
1.103     www      1221: # Inline Menu
1.378     raeburn  1222:         my @tools = (93,91,81,82,83);
                   1223:         unless ($env{'request.state'} eq 'construct') {
                   1224:             push(@tools,63);
                   1225:         }
                   1226:         if (($env{'environment.icons'} eq 'iconsonly') && 
                   1227:             (grep(/^$idx$/,@tools))) {
                   1228:             $inlineremote[$idx] =
                   1229:         '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.'</a>';
                   1230:         } else {
                   1231:             $inlineremote[$idx] =
1.317     droeschl 1232:        '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.
1.344     www      1233:        '<span class="LC_menubuttons_inline_text">'.$top.'&nbsp;</span></a>';
1.378     raeburn  1234:         }
1.317     droeschl 1235:     }
1.56      www      1236:     return '';
1.2       www      1237: }
                   1238: 
                   1239: sub secondlevel {
                   1240:     my $output='';
                   1241:     my 
1.209     www      1242:     ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_;
1.2       www      1243:     if ($prt eq 'any') {
1.209     www      1244: 	   $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1245:     } elsif ($prt=~/^r(\w+)/) {
                   1246:         if ($rol eq $1) {
1.209     www      1247:            $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1248:         }
                   1249:     }
                   1250:     return $output;
                   1251: }
                   1252: 
1.56      www      1253: sub inlinemenu {
1.210     albertel 1254:     undef(@inlineremote);
                   1255:     undef(%category_members);
1.275     www      1256: # calling rawconfig with "1" will evaluate mydesk.tab, even if there is no active remote control
1.56      www      1257:     &rawconfig(1);
1.309     bisitz   1258:     my $output='<table><tr>';
1.209     www      1259:     for (my $col=1; $col<=2; $col++) {
1.241     riegler  1260:         $output.='<td class="LC_mainmenu_col_fieldset">';
1.209     www      1261:         for (my $row=1; $row<=8; $row++) {
                   1262:             foreach my $cat (keys(%category_members)) {
                   1263:                if ($category_positions{$cat} ne "$col,$row") { next; }
1.247     harmsja  1264:                #$output.='<table><tr><td colspan="4" class="LC_menubuttons_category">'.&mt($category_names{$cat}).'</td></tr>';
1.309     bisitz   1265:                $output.='<div class="LC_Box LC_400Box">';
                   1266: 	       $output.='<h3 class="LC_hcell">'.&mt($category_names{$cat}).'</h3>';
1.247     harmsja  1267:                $output.='<table>';
1.240     riegler  1268:                my %active=();
                   1269:                foreach my $menu_item (split(/\:/,$category_members{$cat})) {
                   1270:                   if ($inlineremote[$menu_item]) {
                   1271:                      $active{$menu_item}=1;
                   1272:                   }
                   1273:                }  
                   1274:                foreach my $item (sort(keys(%active))) {
                   1275:                   $output.=$inlineremote[$item];
                   1276:                }
                   1277:                $output.='</table>';
1.245     harmsja  1278:                $output.='</div>';
1.240     riegler  1279:             }
                   1280:          }
                   1281:          $output.="</td>";
                   1282:     }
                   1283:     $output.="</tr></table>";
                   1284:     return $output;
                   1285: }
                   1286: 
1.2       www      1287: sub rawconfig {
1.274     www      1288: #
                   1289: # This evaluates mydesk.tab
                   1290: # Need to add more positions and more privileges to deal with all
                   1291: # menu items.
                   1292: #
1.34      www      1293:     my $textualoverride=shift;
                   1294:     my $output='';
1.316     droeschl 1295:     return '' unless $textualoverride;
1.152     albertel 1296:     my $uname=$env{'user.name'};
                   1297:     my $udom=$env{'user.domain'};
                   1298:     my $adv=$env{'user.adv'};
1.266     raeburn  1299:     my $show_course=&Apache::loncommon::show_course();
1.152     albertel 1300:     my $author=$env{'user.author'};
1.5       www      1301:     my $crs='';
1.295     raeburn  1302:     my $crstype='';
1.152     albertel 1303:     if ($env{'request.course.id'}) {
                   1304:        $crs='/'.$env{'request.course.id'};
                   1305:        if ($env{'request.course.sec'}) {
                   1306: 	   $crs.='_'.$env{'request.course.sec'};
1.7       www      1307:        }
1.8       www      1308:        $crs=~s/\_/\//g;
1.295     raeburn  1309:        $crstype = &Apache::loncommon::course_type();
1.5       www      1310:     }
1.152     albertel 1311:     my $pub=($env{'request.state'} eq 'published');
                   1312:     my $con=($env{'request.state'} eq 'construct');
                   1313:     my $rol=$env{'request.role'};
1.427     raeburn  1314:     my $requested_domain;
                   1315:     if ($rol) {
                   1316:        $requested_domain = $env{'request.role.domain'};
                   1317:     }
1.184     raeburn  1318:     foreach my $line (@desklines) {
1.209     www      1319:         my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
1.3       www      1320:         $prt=~s/\$uname/$uname/g;
                   1321:         $prt=~s/\$udom/$udom/g;
1.295     raeburn  1322:         if ($prt =~ /\$crs/) {
                   1323:             next unless ($env{'request.course.id'});
                   1324:             next if ($crstype eq 'Community');
                   1325:             $prt=~s/\$crs/$crs/g;
                   1326:         } elsif ($prt =~ /\$cmty/) {
                   1327:             next unless ($env{'request.course.id'});
                   1328:             next if ($crstype ne 'Community');
                   1329:             $prt=~s/\$cmty/$crs/g;
                   1330:         }
1.427     raeburn  1331:         if ($prt =~ m/\$requested_domain/) {
                   1332:             if ((!$requested_domain) && ($pro eq 'pbre') && ($env{'user.adv'})) {
                   1333:                 $prt=~s/\$requested_domain/$env{'user.domain'}/g;
                   1334:             } else {
                   1335:                 $prt=~s/\$requested_domain/$requested_domain/g;
                   1336:             }
                   1337:         }
1.211     www      1338:         if ($category_names{$cat}!~/\w/) { $cat='oth'; }
1.3       www      1339:         if ($pro eq 'clear') {
1.4       www      1340: 	    $output.=&clear($row,$col);
1.3       www      1341:         } elsif ($pro eq 'any') {
1.2       www      1342:                $output.=&secondlevel(
1.209     www      1343: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1344: 	} elsif ($pro eq 'smp') {
                   1345:             unless ($adv) {
                   1346:                $output.=&secondlevel(
1.209     www      1347:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1348:             }
                   1349:         } elsif ($pro eq 'adv') {
                   1350:             if ($adv) {
                   1351:                $output.=&secondlevel(
1.209     www      1352: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1353:             }
1.231     albertel 1354: 	} elsif ($pro eq 'shc') {
                   1355:             if ($show_course) {
                   1356:                $output.=&secondlevel(
                   1357:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
                   1358:             }
                   1359:         } elsif ($pro eq 'nsc') {
                   1360:             if (!$show_course) {
                   1361:                $output.=&secondlevel(
                   1362: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
                   1363:             }
1.81      matthew  1364:         } elsif (($pro=~/^p(\w+)/) && ($prt)) {
1.295     raeburn  1365:             my $priv = $1;
                   1366:             if ($priv =~ /^mdc(Course|Community)/) {
                   1367:                 if ($crstype eq $1) {
                   1368:                     $priv = 'mdc';
                   1369:                 } else {
                   1370:                     next;
                   1371:                 }
                   1372:             }
1.427     raeburn  1373:             if ((($priv eq 'bre') && (&Apache::lonnet::allowed($priv,$prt) eq 'F')) ||
                   1374:                 (($priv ne 'bre') && (&Apache::lonnet::allowed($priv,$prt)))) {
                   1375:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.4       www      1376:             }
1.295     raeburn  1377:         } elsif ($pro eq 'course')  {
                   1378:             if (($env{'request.course.fn'}) && ($crstype ne 'Community')) {
1.209     www      1379:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.81      matthew  1380: 	    }
1.295     raeburn  1381:         } elsif ($pro eq 'community')  {
                   1382:             if (($env{'request.course.fn'}) && ($crstype eq 'Community')) {
                   1383:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
                   1384:             }
1.124     matthew  1385:         } elsif ($pro =~ /^courseenv_(.*)$/) {
                   1386:             my $key = $1;
1.307     raeburn  1387:             if ($crstype ne 'Community') {
                   1388:                 my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
                   1389:                 if ($key eq 'canuse_pdfforms') {
                   1390:                     if ($env{'request.course.id'} && $coursepref eq '') {
                   1391:                         my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
                   1392:                         $coursepref = $domdefs{'canuse_pdfforms'};
                   1393:                     }
                   1394:                 }
                   1395:                 if ($coursepref) { 
                   1396:                     $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
                   1397:                 }
1.295     raeburn  1398:             }
                   1399:         } elsif ($pro =~ /^communityenv_(.*)$/) {
                   1400:             my $key = $1;
1.307     raeburn  1401:             if ($crstype eq 'Community') {
                   1402:                 my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
                   1403:                 if ($key eq 'canuse_pdfforms') {
                   1404:                     if ($env{'request.course.id'} && $coursepref eq '') {
                   1405:                         my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
                   1406:                         $coursepref = $domdefs{'canuse_pdfforms'};
                   1407:                     }
                   1408:                 }
                   1409:                 if ($coursepref) { 
                   1410:                     $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
                   1411:                 }
1.124     matthew  1412:             }
1.81      matthew  1413:         } elsif ($pro =~ /^course_(.*)$/) {
                   1414:             # Check for permissions inside of a course
1.295     raeburn  1415:             if (($env{'request.course.id'}) && ($crstype ne 'Community') && 
1.152     albertel 1416:                 (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
                   1417:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
1.81      matthew  1418:                  )) {
1.209     www      1419:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.26      www      1420: 	    }
1.295     raeburn  1421:         } elsif ($pro =~ /^community_(.*)$/) {
                   1422:             # Check for permissions inside of a community
                   1423:             if (($env{'request.course.id'}) && ($crstype eq 'Community') &&   
                   1424:                 (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
                   1425:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
                   1426:                  )) {
                   1427:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
                   1428:             }
1.4       www      1429:         } elsif ($pro eq 'author') {
                   1430:             if ($author) {
1.152     albertel 1431:                 if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
1.234     raeburn  1432:                     (($prt eq 'raa') && ($env{'request.role'}=~/^aa/)) || 
1.152     albertel 1433:                     (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
1.19      matthew  1434:                     # Check that we are on the correct machine
1.29      matthew  1435:                     my $cadom=$requested_domain;
1.152     albertel 1436:                     my $caname=$env{'user.name'};
1.234     raeburn  1437:                     if (($prt eq 'rca') || ($prt eq 'raa')) {
1.29      matthew  1438: 		       ($cadom,$caname)=
1.206     albertel 1439:                                ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.29      matthew  1440:                     }                       
                   1441:                     $act =~ s/\$caname/$caname/g;
1.353     www      1442:                     $act =~ s/\$cadom/$cadom/g;
1.19      matthew  1443:                     my $home = &Apache::lonnet::homeserver($caname,$cadom);
1.109     albertel 1444: 		    my $allowed=0;
                   1445: 		    my @ids=&Apache::lonnet::current_machine_ids();
                   1446: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                   1447: 		    if ($allowed) {
1.209     www      1448:                         $output.=&switch($caname,$cadom,
                   1449:                                         $row,$col,$img,$top,$bot,$act,$desc,$cat);
1.19      matthew  1450:                     }
1.6       www      1451:                 }
1.2       www      1452:             }
1.248     raeburn  1453:         } elsif ($pro eq 'tools') {
                   1454:             my @tools = ('aboutme','blog','portfolio');
                   1455:             if (grep(/^\Q$prt\E$/,@tools)) {
1.249     raeburn  1456:                 if (!&Apache::lonnet::usertools_access($env{'user.name'},
1.251     raeburn  1457:                                                        $env{'user.domain'},
                   1458:                                                        $prt,undef,'tools')) {
                   1459:                     $output.=&clear($row,$col);
                   1460:                     next;
                   1461:                 }
1.278     raeburn  1462:             } elsif (($prt eq 'reqcrsnsc') || ($prt eq 'reqcrsshc')) {
                   1463:                 if (($prt eq 'reqcrsnsc') && ($show_course))   {
                   1464:                     next;
                   1465:                 }
                   1466:                 if (($prt eq 'reqcrsshc') && (!$show_course)) {
                   1467:                     next;
                   1468:                 }
1.279     raeburn  1469:                 my $showreqcrs = &check_for_rcrs();
1.251     raeburn  1470:                 if (!$showreqcrs) {
1.248     raeburn  1471:                     $output.=&clear($row,$col);
                   1472:                     next;
                   1473:                 }
                   1474:             }
                   1475:             $prt='any';
                   1476:             $output.=&secondlevel(
                   1477:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1478:         }
1.13      harris41 1479:     }
1.2       www      1480:     return $output;
                   1481: }
                   1482: 
1.279     raeburn  1483: sub check_for_rcrs {
                   1484:     my $showreqcrs = 0;
1.424     raeburn  1485:     my @reqtypes = ('official','unofficial','community','textbook');
1.280     raeburn  1486:     foreach my $type (@reqtypes) {
1.279     raeburn  1487:         if (&Apache::lonnet::usertools_access($env{'user.name'},
                   1488:                                               $env{'user.domain'},
                   1489:                                               $type,undef,'requestcourses')) {
                   1490:             $showreqcrs = 1;
                   1491:             last;
                   1492:         }
                   1493:     }
1.280     raeburn  1494:     if (!$showreqcrs) {
                   1495:         foreach my $type (@reqtypes) {
                   1496:             if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
                   1497:                 $showreqcrs = 1;
                   1498:                 last;
                   1499:             }
                   1500:         }
                   1501:     }
1.279     raeburn  1502:     return $showreqcrs;
                   1503: }
                   1504: 
1.306     raeburn  1505: sub dc_popup_js {
                   1506:     my %lt = &Apache::lonlocal::texthash(
                   1507:                                           more => '(More ...)',
                   1508:                                           less => '(Less ...)',
                   1509:                                         );
                   1510:     return <<"END";
                   1511: 
                   1512: function showCourseID() {
                   1513:     document.getElementById('dccid').style.display='block';
                   1514:     document.getElementById('dccid').style.textAlign='left';
1.307     raeburn  1515:     document.getElementById('dccid').style.textFace='normal';
1.369     raeburn  1516:     document.getElementById('dccidtext').innerHTML ='<a href="javascript:hideCourseID();" class="LC_menubuttons_link">$lt{'less'}</a>';
1.306     raeburn  1517:     return;
                   1518: }
                   1519: 
                   1520: function hideCourseID() {
                   1521:     document.getElementById('dccid').style.display='none';
1.369     raeburn  1522:     document.getElementById('dccidtext').innerHTML ='<a href="javascript:showCourseID()" class="LC_menubuttons_link">$lt{'more'}</a>';
1.306     raeburn  1523:     return;
                   1524: }
                   1525: 
                   1526: END
                   1527: 
                   1528: }
                   1529: 
1.378     raeburn  1530: sub countdown_toggle_js {
                   1531:     return <<"END";
                   1532: 
                   1533: function toggleCountdown() {
                   1534:     var countdownid = document.getElementById('duedatecountdown');
                   1535:     var currstyle = countdownid.style.display;
                   1536:     if (currstyle == 'inline') {
                   1537:         countdownid.style.display = 'none';
                   1538:         document.getElementById('ddcountcollapse').innerHTML='';
                   1539:         document.getElementById('ddcountexpand').innerHTML='&#9668;&nbsp;';
                   1540:     } else {
                   1541:         countdownid.style.display = 'inline';
                   1542:         document.getElementById('ddcountcollapse').innerHTML='&#9658;&nbsp;';
                   1543:         document.getElementById('ddcountexpand').innerHTML='';
                   1544:     }
                   1545:     return;
                   1546: }
                   1547: 
1.431.2.2  musolffc 1548: END
1.431.2.1  musolffc 1549: }
                   1550: 
1.431.2.3  raeburn  1551: # This creates a "done button" for timed events.  The confirmation box is a jQuery
                   1552: # dialog widget.  Clicking OK will set (LC_interval_done = 'true') which is checked in 
1.431.2.2  musolffc 1553: # lonhomework.pm.
                   1554: sub done_button_js {
1.431.2.3  raeburn  1555:     my ($type,$height) = @_;
                   1556:     if ($height !~ /^\d+$/) {
                   1557:         $height = 320;
                   1558:     }
                   1559:     my %lt = &Apache::lonlocal::texthash(
                   1560:                  title    => 'WARNING!',
                   1561:                  button   => 'Done',
                   1562:                  preamble => 'You are trying to end this timed event early.',
                   1563:                  map      => 'Confirming that you are done will cause the time to expire and prevent you from changing any answers in the current folder.',
                   1564:                  resource => 'Confirming that you are done will cause the time to expire for this question, and prevent you from changing your answer(s).', 
                   1565:                  ok       => 'Click "OK" if you are completely finished.',
                   1566:                  cancel   => 'Click "Cancel" to continue working.',
                   1567:     );
                   1568:     my $confirm;
                   1569:     if (($type eq 'map') || ($type eq 'resource')) {
                   1570:         $confirm = $lt{'preamble'}.' '.$lt{$type}.' '.$lt{'ok'}.' '.$lt{'cancel'};
                   1571:     }
                   1572:     if ($confirm) {
                   1573:         return <<END;
                   1574: 
                   1575: <form method="post" name="LCdoneButton" action="">
                   1576:     <input type="hidden" name="LC_interval_done" value="" />
                   1577:     <button id="LC_done-confirm-opener" type="button">$lt{'button'}</button>
                   1578: </form>
1.431.2.2  musolffc 1579: 
1.431.2.3  raeburn  1580: <div id="LC_done-confirm" title="$lt{'title'}">
                   1581:     <p>$confirm</p>
1.431.2.2  musolffc 1582: </div>
                   1583: 
1.431.2.3  raeburn  1584: <script type="text/javascript">
                   1585: // <![CDATA[
                   1586: \$( "#LC_done-confirm" ).dialog({ autoOpen: false });
                   1587: \$( "#LC_done-confirm-opener" ).click(function() {
                   1588:     \$( "#LC_done-confirm" ).dialog( "open" );
                   1589:     \$( "#LC_done-confirm" ).dialog({
1.431.2.2  musolffc 1590:       resizable: false,
1.431.2.3  raeburn  1591:       height: $height,
1.431.2.2  musolffc 1592:       modal: true,
                   1593:       buttons: {
                   1594:         "OK": function() {
                   1595:             \$( this ).dialog( "close" );
1.431.2.3  raeburn  1596:             \$( '[name="LC_interval_done"]' )[0].value = 'true';
                   1597:             \$( '[name="LCdoneButton"]' )[0].submit();
1.431.2.2  musolffc 1598:         },
                   1599:         Cancel: function() {
                   1600:           \$( this ).dialog( "close" );
                   1601:         }
                   1602:       }    
                   1603:     })
                   1604: });
1.431.2.3  raeburn  1605: // ]]>
1.431.2.2  musolffc 1606: </script>
                   1607: 
1.378     raeburn  1608: END
1.431.2.3  raeburn  1609:     } else {
                   1610:         return;
                   1611:     }
1.378     raeburn  1612: }
                   1613: 
1.42      www      1614: sub utilityfunctions {
1.421     raeburn  1615:     my ($httphost) = @_;
1.152     albertel 1616:     my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
1.316     droeschl 1617:     if ($currenturl =~ m{^/adm/wrapper/ext/}
                   1618:         && $env{'request.external.querystring'} ) {
1.293     raeburn  1619:             $currenturl .= ($currenturl=~/\?/)?'&':'?'.$env{'request.external.querystring'};
                   1620:     }
1.183     www      1621:     $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
1.125     albertel 1622:     
1.152     albertel 1623:     my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
1.175     albertel 1624: 
1.306     raeburn  1625:     my $dc_popup_cid;
                   1626:     if ($env{'user.adv'} && exists($env{'user.role.dc./'.
                   1627:                         $env{'course.'.$env{'request.course.id'}.
                   1628:                                  '.domain'}.'/'})) {
                   1629:         $dc_popup_cid = &dc_popup_js();
                   1630:     }
                   1631: 
1.175     albertel 1632:     my $start_page_annotate = 
                   1633:         &Apache::loncommon::start_page('Annotator',undef,
                   1634: 				       {'only_body' => 1,
                   1635: 					'js_ready'  => 1,
                   1636: 					'bgcolor'   => '#BBBBBB',
                   1637: 					'add_entries' => {
                   1638: 					    'onload' => 'javascript:document.goannotate.submit();'}});
                   1639: 
1.205     albertel 1640:     my $end_page_annotate = 
                   1641:         &Apache::loncommon::end_page({'js_ready' => 1});
                   1642: 
1.389     raeburn  1643:     my $jumptores = &Apache::lonhtmlcommon::javascript_jumpto_resource();
1.336     raeburn  1644: 
1.368     www      1645:     my $esc_url=&escape($currenturl);
                   1646:     my $esc_symb=&escape($currentsymb);
1.332     wenzelju 1647: 
1.378     raeburn  1648:     my $countdown = &countdown_toggle_js();
                   1649: 
1.429     raeburn  1650:     my $hostvar = '
                   1651: function setLCHost() {
                   1652:     var lcHostname="";
                   1653: ';
                   1654:     if ($httphost =~ m{^https?\://}) {
                   1655:         $hostvar .= '    var lcServer="'.$httphost.'";'."\n".
                   1656:                     '    var hostReg = /^https?:\/\/([^\/]+)$/i;'."\n".
                   1657:                     '    var match = hostReg.exec(lcServer);'."\n".
                   1658:                     '    if (match.length) {'."\n".
                   1659:                     '        if (match[1] == location.hostname) {'."\n".
                   1660:                     '            lcHostname=lcServer;'."\n".
                   1661:                     '        }'."\n".
                   1662:                     '    }'."\n";
                   1663:     }
                   1664:     
                   1665:     $hostvar .= '    return lcHostname;'."\n".
                   1666: '}'."\n";
                   1667: 
1.42      www      1668: return (<<ENDUTILITY)
1.429     raeburn  1669:     $hostvar
1.368     www      1670:     var currentURL=unescape("$esc_url");
                   1671:     var reloadURL=unescape("$esc_url");
                   1672:     var currentSymb=unescape("$esc_symb");
1.42      www      1673: 
1.306     raeburn  1674: $dc_popup_cid
1.114     albertel 1675: 
1.389     raeburn  1676: $jumptores
1.336     raeburn  1677: 
1.42      www      1678: function gopost(url,postdata) {
                   1679:    if (url!='') {
1.429     raeburn  1680:       var lcHostname = setLCHost();
                   1681:       this.document.server.action=lcHostname+url;
1.42      www      1682:       this.document.server.postdata.value=postdata;
                   1683:       this.document.server.command.value='';
                   1684:       this.document.server.url.value='';
                   1685:       this.document.server.symb.value='';
                   1686:       this.document.server.submit();
                   1687:    }
                   1688: }
                   1689: 
                   1690: function gocmd(url,cmd) {
                   1691:    if (url!='') {
1.429     raeburn  1692:       var lcHostname = setLCHost();
                   1693:       this.document.server.action=lcHostname+url;
1.42      www      1694:       this.document.server.postdata.value='';
                   1695:       this.document.server.command.value=cmd;
                   1696:       this.document.server.url.value=currentURL;
                   1697:       this.document.server.symb.value=currentSymb;
                   1698:       this.document.server.submit();
                   1699:    }
1.57      www      1700: }
                   1701: 
1.121     raeburn  1702: function gocstr(url,filename) {
                   1703:     if (url == '/adm/cfile?action=delete') {
                   1704:         this.document.cstrdelete.filename.value = filename
                   1705:         this.document.cstrdelete.submit();
                   1706:         return;
                   1707:     }
1.137     raeburn  1708:     if (url == '/adm/printout') {
                   1709:         this.document.cstrprint.postdata.value = filename
                   1710:         this.document.cstrprint.curseed.value = 0;
                   1711:         this.document.cstrprint.problemtype.value = 0;
1.138     raeburn  1712:         if (this.document.lonhomework) {
                   1713:             if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
                   1714:                 this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
                   1715:             }
                   1716:             if (this.document.lonhomework.problemtype) {
1.164     albertel 1717: 		if (this.document.lonhomework.problemtype.value) {
                   1718: 		    this.document.cstrprint.problemtype.value = 
                   1719: 			this.document.lonhomework.problemtype.value;
                   1720: 		} else if (this.document.lonhomework.problemtype.options) {
                   1721: 		    for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
                   1722: 			if (this.document.lonhomework.problemtype.options[i].selected) {
                   1723: 			    if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') { 
                   1724: 				this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
                   1725: 				}
                   1726: 			}
                   1727: 		    }
                   1728: 		}
                   1729: 	    }
                   1730: 	}
1.137     raeburn  1731:         this.document.cstrprint.submit();
                   1732:         return;
                   1733:     }
1.121     raeburn  1734:     if (url !='') {
                   1735:         this.document.constspace.filename.value = filename;
                   1736:         this.document.constspace.action = url;
                   1737:         this.document.constspace.submit();
                   1738:     }
                   1739: }
                   1740: 
1.131     raeburn  1741: function golist(url) {
                   1742:    if (url!='' && url!= null) {
                   1743:        currentURL = null;
                   1744:        currentSymb= null;
1.429     raeburn  1745:        var lcHostname = setLCHost();
                   1746:        top.location.href=lcHostname+url;
1.131     raeburn  1747:    }
                   1748: }
                   1749: 
                   1750: 
1.121     raeburn  1751: 
1.428     raeburn  1752: function catalog_info(isMobile) {
                   1753:     if (isMobile == 1) {
                   1754:         openMyModal(window.location.pathname+'.meta?modal=1',500,400,'yes');
                   1755:     } else {
                   1756:         loncatinfo=window.open(window.location.pathname+'.meta',"LONcatInfo",'height=500,width=400,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
                   1757:     }
1.57      www      1758: }
                   1759: 
                   1760: function chat_win() {
1.429     raeburn  1761:    var lcHostname = setLCHost();
                   1762:    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      1763: }
1.169     raeburn  1764: 
                   1765: function group_chat(group) {
1.429     raeburn  1766:    var lcHostname = setLCHost();
                   1767:    var url = lcHostname+'/adm/groupchat?group='+group;
1.169     raeburn  1768:    var winName = 'LONchat_'+group;
                   1769:    grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
                   1770: }
1.175     albertel 1771: 
                   1772: function annotate() {
                   1773:    w_Annotator_flag=1;
                   1774:    annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
                   1775:    annotator.document.write(
                   1776:    '$start_page_annotate'
                   1777:   +"<form name='goannotate' target='Annotator' method='post' "
                   1778:   +"action='/adm/annotations'>"
1.217     albertel 1779:   +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />"
1.181     albertel 1780:   +"<\\/form>"
1.205     albertel 1781:   +'$end_page_annotate');
1.175     albertel 1782:    annotator.document.close();
                   1783: }
                   1784: 
1.370     raeburn  1785: function open_StoredLinks_Import(rat) {
1.335     wenzelju 1786:    var newWin;
1.429     raeburn  1787:    var lcHostname = setLCHost();
1.335     wenzelju 1788:    if (rat) {
1.429     raeburn  1789:        newWin = window.open(lcHostname+'/adm/wishlist?inhibitmenu=yes&mode=import&rat='+rat,
1.334     wenzelju 1790:                             'wishlistImport','scrollbars=1,resizable=1,menubar=0');
1.335     wenzelju 1791:    }
                   1792:    else {
1.429     raeburn  1793:        newWin = window.open(lcHostname+'/adm/wishlist?inhibitmenu=yes&mode=import',
1.335     wenzelju 1794:                             'wishlistImport','scrollbars=1,resizable=1,menubar=0');
                   1795:    }
1.334     wenzelju 1796:    newWin.focus();
                   1797: }
                   1798: 
1.372     raeburn  1799: (function (\$) {
                   1800:   \$(document).ready(function () {
                   1801:     \$.single=function(a){return function(b){a[0]=b;return a}}(\$([1]));
                   1802:     /*\@cc_on
                   1803:       if (!window.XMLHttpRequest) {
                   1804:         \$('.LC_hoverable').each(function () {
                   1805:           this.attachEvent('onmouseenter', function (evt) { \$.single(evt.srcElement).addClass('hover'); });
                   1806:           this.attachEvent('onmouseleave', function (evt) { \$.single(evt.srcElement).removeClass('hover'); });
                   1807:         });
                   1808:       }
                   1809:     \@*/
                   1810:   });
                   1811: }(jQuery));
                   1812: 
1.378     raeburn  1813: $countdown
                   1814: 
1.42      www      1815: ENDUTILITY
                   1816: }
                   1817: 
                   1818: sub serverform {
                   1819:     return(<<ENDSERVERFORM);
1.181     albertel 1820: <form name="server" action="/adm/logout" method="post" target="_top">
1.42      www      1821: <input type="hidden" name="postdata" value="none" />
                   1822: <input type="hidden" name="command" value="none" />
                   1823: <input type="hidden" name="url" value="none" />
                   1824: <input type="hidden" name="symb" value="none" />
                   1825: </form>
                   1826: ENDSERVERFORM
                   1827: }
1.113     albertel 1828: 
1.121     raeburn  1829: sub constspaceform {
                   1830:     return(<<ENDCONSTSPACEFORM);
1.181     albertel 1831: <form name="constspace" action="/adm/logout" method="post" target="_top">
1.121     raeburn  1832: <input type="hidden" name="filename" value="" />
                   1833: </form>
1.181     albertel 1834: <form name="cstrdelete" action="/adm/cfile" method="post" target="_top">
1.121     raeburn  1835: <input type="hidden" name="action" value="delete" /> 
                   1836: <input type="hidden" name="filename" value="" />
                   1837: </form>
1.181     albertel 1838: <form name="cstrprint" action="/adm/printout" target="_parent" method="post">
1.137     raeburn  1839: <input type="hidden" name="postdata" value="" />
                   1840: <input type="hidden" name="curseed" value="" />
                   1841: <input type="hidden" name="problemtype" value="" />
                   1842: </form>
                   1843: 
1.121     raeburn  1844: ENDCONSTSPACEFORM
                   1845: }
                   1846: 
1.220     raeburn  1847: sub hidden_button_check {
1.317     droeschl 1848:     if ( $env{'request.course.id'} eq ''
                   1849:          || $env{'request.role.adv'} ) {
                   1850: 
1.220     raeburn  1851:         return;
                   1852:     }
1.232     raeburn  1853:     my $buttonshide = &Apache::lonnet::EXT('resource.0.buttonshide');
                   1854:     return $buttonshide; 
1.220     raeburn  1855: }
1.184     raeburn  1856: 
1.235     raeburn  1857: sub roles_selector {
1.421     raeburn  1858:     my ($cdom,$cnum,$httphost) = @_;
1.298     raeburn  1859:     my $crstype = &Apache::loncommon::course_type();
1.235     raeburn  1860:     my $now = time;
1.350     raeburn  1861:     my (%courseroles,%seccount,%courseprivs);
1.235     raeburn  1862:     my $is_cc;
1.401     raeburn  1863:     my ($js,$form,$switcher,$switchtext);
1.298     raeburn  1864:     my $ccrole;
                   1865:     if ($crstype eq 'Community') {
                   1866:         $ccrole = 'co';
                   1867:     } else {
                   1868:         $ccrole = 'cc';
1.350     raeburn  1869:     }
1.386     raeburn  1870:     my ($priv,$gotsymb,$destsymb);
1.350     raeburn  1871:     my $destinationurl = $ENV{'REQUEST_URI'};
1.386     raeburn  1872:     if ($destinationurl =~ /\?symb=/) {
                   1873:         $gotsymb = 1;
                   1874:     } elsif ($destinationurl =~ m{^/enc/}) {
                   1875:         my $plainurl = &Apache::lonenc::unencrypted($destinationurl);
                   1876:         if ($plainurl =~ /\?symb=/) {
                   1877:             $gotsymb = 1;
                   1878:         }
                   1879:     }
                   1880:     unless ($gotsymb) {
                   1881:         $destsymb = &Apache::lonnet::symbread();
                   1882:         if ($destsymb ne '') {
                   1883:             $destsymb = &Apache::lonenc::check_encrypt($destsymb);
                   1884:         }
                   1885:     }
1.350     raeburn  1886:     my $reqprivs = &required_privs();
                   1887:     if (ref($reqprivs) eq 'HASH') {
                   1888:         my $destination = $destinationurl;
                   1889:         $destination =~ s/(\?.*)$//;
                   1890:         if (exists($reqprivs->{$destination})) {
                   1891:             $priv = $reqprivs->{$destination};
                   1892:         }
                   1893:     }
1.298     raeburn  1894:     if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
                   1895:         my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
1.235     raeburn  1896:         
                   1897:         if ((($start) && ($start<0)) || 
                   1898:             (($end) && ($end<$now))  ||
                   1899:             (($start) && ($now<$start))) {
                   1900:             $is_cc = 0;
                   1901:         } else {
                   1902:             $is_cc = 1;
                   1903:         }
                   1904:     }
                   1905:     if ($is_cc) {
1.350     raeburn  1906:         &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs,$priv);
1.235     raeburn  1907:     } else {
1.262     raeburn  1908:         my %gotnosection;
1.235     raeburn  1909:         foreach my $item (keys(%env)) {
1.239     raeburn  1910:             if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
1.235     raeburn  1911:                 my $role = $1;
                   1912:                 my $sec = $2;
                   1913:                 next if ($role eq 'gr');
                   1914:                 my ($start,$end) = split(/\./,$env{$item});
                   1915:                 next if (($start && $start > $now) || ($end && $end < $now));
                   1916:                 if ($sec eq '') {
1.239     raeburn  1917:                     if (!$gotnosection{$role}) {
                   1918:                         $seccount{$role} ++;
                   1919:                         $gotnosection{$role} = 1;
                   1920:                     }
1.235     raeburn  1921:                 }
1.350     raeburn  1922:                 if ($priv ne '') {
                   1923:                     my $cnumsec = $cnum;
                   1924:                     if ($sec ne '') {
                   1925:                         $cnumsec .= "/$sec";
                   1926:                     }
                   1927:                     $courseprivs{"$role./$cdom/$cnumsec./"} =
                   1928:                         $env{"user.priv.$role./$cdom/$cnumsec./"};
                   1929:                     $courseprivs{"$role./$cdom/$cnumsec./$cdom/"} =
                   1930:                         $env{"user.priv.$role./$cdom/$cnumsec./$cdom/"};
                   1931:                     $courseprivs{"$role./$cdom/$cnumsec./$cdom/$cnumsec"} =
                   1932:                         $env{"user.priv.$role./$cdom/$cnumsec./$cdom/$cnumsec"};
                   1933:                 }
1.235     raeburn  1934:                 if (ref($courseroles{$role}) eq 'ARRAY') {
1.239     raeburn  1935:                     if ($sec ne '') {
1.264     raeburn  1936:                         if (!grep(/^\Q$sec\E$/,@{$courseroles{$role}})) {
1.239     raeburn  1937:                             push(@{$courseroles{$role}},$sec);
                   1938:                             $seccount{$role} ++;
                   1939:                         }
                   1940:                     }
                   1941:                 } else {
                   1942:                     @{$courseroles{$role}} = ();
                   1943:                     if ($sec ne '') {
                   1944:                         $seccount{$role} ++;
1.235     raeburn  1945:                         push(@{$courseroles{$role}},$sec);
                   1946:                     }
                   1947:                 }
                   1948:             }
                   1949:         }
                   1950:     }
1.419     bisitz   1951:     $switchtext = 'Switch role'; # do not translate here
1.298     raeburn  1952:     my @roles_order = ($ccrole,'in','ta','ep','ad','st');
1.402     raeburn  1953:     my $numdiffsec;
                   1954:     if (keys(%seccount) == 1) {
                   1955:         foreach my $key (keys(%seccount)) {
                   1956:             $numdiffsec = $seccount{$key};
                   1957:         }
                   1958:     }
                   1959:     if ((keys(%seccount) > 1) || ($numdiffsec > 1)) {
1.401     raeburn  1960:         my @submenu;
                   1961:         $js = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles,\%courseprivs,$priv);
                   1962:         $form = 
1.421     raeburn  1963:             '<form name="rolechooser" method="post" action="'.$httphost.'/adm/roles">'."\n".
1.401     raeburn  1964:             '  <input type="hidden" name="destinationurl" value="'.
                   1965:             &HTML::Entities::encode($destinationurl).'" />'."\n".
                   1966:             '  <input type="hidden" name="gotorole" value="1" />'."\n".
                   1967:             '  <input type="hidden" name="selectrole" value="" />'."\n".
1.402     raeburn  1968:             '  <input type="hidden" name="switchrole" value="" />'."\n";
                   1969:         if ($destsymb ne '') {
                   1970:             $form .= '  <input type="hidden" name="destsymb" value="'.
                   1971:                         &HTML::Entities::encode($destsymb).'" />'."\n";
                   1972:         }
                   1973:         $form .= '</form>'."\n";
1.235     raeburn  1974:         foreach my $role (@roles_order) {
1.402     raeburn  1975:             my $include;
1.235     raeburn  1976:             if (defined($courseroles{$role})) {
1.402     raeburn  1977:                 if ($env{'request.role'} =~ m{^\Q$role\E}) {
                   1978:                     if ($seccount{$role} > 1) {
                   1979:                         $include = 1;
                   1980:                     }
                   1981:                 } else {
                   1982:                     $include = 1;
                   1983:                 }
                   1984:             }
                   1985:             if ($include) {
1.401     raeburn  1986:                 push(@submenu,['javascript:adhocRole('."'$role'".')',
                   1987:                                &Apache::lonnet::plaintext($role,$crstype)]);
1.235     raeburn  1988:             }
                   1989:         }
                   1990:         foreach my $role (sort(keys(%courseroles))) {
                   1991:             if ($role =~ /^cr/) {
1.403     raeburn  1992:                 my $include;
                   1993:                 if ($env{'request.role'} =~ m{^\Q$role\E}) {
1.402     raeburn  1994:                     if ($seccount{$role} > 1) {
                   1995:                         $include = 1;
                   1996:                     }
1.403     raeburn  1997:                 } else {
                   1998:                     $include = 1; 
                   1999:                 }
                   2000:                 if ($include) {
                   2001:                     push(@submenu,['javascript:adhocRole('."'$role'".')',
                   2002:                                    &Apache::lonnet::plaintext($role)]);
                   2003:                 }
1.235     raeburn  2004:             }
                   2005:         }
1.401     raeburn  2006:         if (@submenu > 0) {
                   2007:             $switcher = &create_submenu('','',$switchtext,\@submenu);
1.386     raeburn  2008:         }
1.235     raeburn  2009:     }
1.401     raeburn  2010:     return ($js,$form,$switcher);
1.235     raeburn  2011: }
                   2012: 
1.262     raeburn  2013: sub get_all_courseroles {
1.350     raeburn  2014:     my ($cdom,$cnum,$courseroles,$seccount,$courseprivs) = @_;
1.351     raeburn  2015:     unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH') &&
1.350     raeburn  2016:             (ref($courseprivs) eq 'HASH')) {
1.262     raeburn  2017:         return;
                   2018:     }
                   2019:     my ($result,$cached) = 
                   2020:         &Apache::lonnet::is_cached_new('getcourseroles',$cdom.'_'.$cnum);
                   2021:     if (defined($cached)) {
                   2022:         if (ref($result) eq 'HASH') {
                   2023:             if ((ref($result->{'roles'}) eq 'HASH') && 
1.350     raeburn  2024:                 (ref($result->{'seccount'}) eq 'HASH') && 
                   2025:                 (ref($result->{'privs'}) eq 'HASH')) {
1.262     raeburn  2026:                 %{$courseroles} = %{$result->{'roles'}};
                   2027:                 %{$seccount} = %{$result->{'seccount'}};
1.350     raeburn  2028:                 %{$courseprivs} = %{$result->{'privs'}};
1.262     raeburn  2029:                 return;
                   2030:             }
                   2031:         }
                   2032:     }
                   2033:     my %gotnosection;
                   2034:     my %adv_roles =
                   2035:          &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
                   2036:     foreach my $role (keys(%adv_roles)) {
                   2037:         my ($urole,$usec) = split(/:/,$role);
                   2038:         if (!$gotnosection{$urole}) {
                   2039:             $seccount->{$urole} ++;
                   2040:             $gotnosection{$urole} = 1;
                   2041:         }
                   2042:         if (ref($courseroles->{$urole}) eq 'ARRAY') {
                   2043:             if ($usec ne '') {
                   2044:                 if (!grep(/^Q$usec\E$/,@{$courseroles->{$urole}})) {
                   2045:                     push(@{$courseroles->{$urole}},$usec);
                   2046:                     $seccount->{$urole} ++;
                   2047:                 }
                   2048:             }
                   2049:         } else {
                   2050:             @{$courseroles->{$urole}} = ();
                   2051:             if ($usec ne '') {
                   2052:                 $seccount->{$urole} ++;
                   2053:                 push(@{$courseroles->{$urole}},$usec);
                   2054:             }
                   2055:         }
1.350     raeburn  2056:         my $area = '/'.$cdom.'/'.$cnum;
                   2057:         if ($usec ne '') {
                   2058:             $area .= '/'.$usec;
                   2059:         }
                   2060:         if ($role =~ /^cr\//) {
                   2061:             &Apache::lonnet::custom_roleprivs($courseprivs,$urole,$cdom,$cnum,$urole.'.'.$area,$area);
                   2062:         } else {
                   2063:             &Apache::lonnet::standard_roleprivs($courseprivs,$urole,$cdom,$urole.'.'.$area,$cnum,$area);
                   2064:         }
1.262     raeburn  2065:     }
                   2066:     my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum,['st']);
                   2067:     @{$courseroles->{'st'}} = ();
1.350     raeburn  2068:     &Apache::lonnet::standard_roleprivs($courseprivs,'st',$cdom,"st./$cdom/$cnum",$cnum,"/$cdom/$cnum");
1.262     raeburn  2069:     if (keys(%sections_count) > 0) {
                   2070:         push(@{$courseroles->{'st'}},keys(%sections_count));
1.350     raeburn  2071:         $seccount->{'st'} = scalar(keys(%sections_count));
1.262     raeburn  2072:     }
1.410     raeburn  2073:     $seccount->{'st'} ++; # Increment for a section-less student role.  
1.262     raeburn  2074:     my $rolehash = {
                   2075:                      'roles'    => $courseroles,
                   2076:                      'seccount' => $seccount,
1.350     raeburn  2077:                      'privs'    => $courseprivs,
1.262     raeburn  2078:                    };
                   2079:     &Apache::lonnet::do_cache_new('getcourseroles',$cdom.'_'.$cnum,$rolehash);
                   2080:     return;
                   2081: }
                   2082: 
1.235     raeburn  2083: sub jump_to_role {
1.350     raeburn  2084:     my ($cdom,$cnum,$seccount,$courseroles,$courseprivs,$priv) = @_;
1.239     raeburn  2085:     my %lt = &Apache::lonlocal::texthash(
                   2086:                 this => 'This role has section(s) associated with it.',
                   2087:                 ente => 'Enter a specific section.',
                   2088:                 orlb => 'Enter a specific section, or leave blank for no section.',
                   2089:                 avai => 'Available sections are:',
                   2090:                 youe => 'You entered an invalid section choice:',
1.352     raeburn  2091:                 plst => 'Please try again.',
1.350     raeburn  2092:                 role => 'The role you selected is not permitted to view the current page.',
                   2093:                 swit => 'Switch role, but display Main Menu page instead?',
1.239     raeburn  2094:     );
                   2095:     my $js;
                   2096:     if (ref($courseroles) eq 'HASH') {
                   2097:         $js = '    var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n". 
                   2098:               '    var numsec = new Array();'."\n".
                   2099:               '    var rolesections = new Array();'."\n".
                   2100:               '    var rolenames = new Array();'."\n".
                   2101:               '    var roleseclist = new Array();'."\n";
                   2102:         my @items = keys(%{$courseroles});
                   2103:         for (my $i=0; $i<@items; $i++) {
                   2104:             $js .= '    rolenames['.$i.'] = "'.$items[$i].'";'."\n";
                   2105:             my ($secs,$secstr);
                   2106:             if (ref($courseroles->{$items[$i]}) eq 'ARRAY') {
                   2107:                 my @sections = sort { $a <=> $b } @{$courseroles->{$items[$i]}};
                   2108:                 $secs = join('","',@sections);
                   2109:                 $secstr = join(', ',@sections);
                   2110:             }
                   2111:             $js .= '    rolesections['.$i.'] = new Array("'.$secs.'");'."\n".
                   2112:                    '    roleseclist['.$i.'] = "'.$secstr.'";'."\n".
                   2113:                    '    numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n";
                   2114:         }
                   2115:     }
1.350     raeburn  2116:     my $checkroles = 0;
                   2117:     if ($priv && ref($courseprivs) eq 'HASH') {
                   2118:         my (%disallowed,%allowed,@disallow);
                   2119:         foreach my $role (sort(keys(%{$courseprivs}))) {
                   2120:             my $trole;
                   2121:             if ($role =~ m{^(.+?)\Q./$cdom/$cnum\E}) {
                   2122:                 $trole = $1;
                   2123:             }
                   2124:             if (($trole ne '') && ($trole ne 'cm')) {
                   2125:                 if ($courseprivs->{$role} =~ /\Q:$priv\E($|:|\&\w+)/) {
                   2126:                     $allowed{$trole} = 1;
                   2127:                 } else {
                   2128:                     $disallowed{$trole} = 1;
                   2129:                 }
                   2130:             }
                   2131:         }
                   2132:         foreach my $trole (keys(%disallowed)) {
                   2133:             unless ($allowed{$trole}) {
                   2134:                 push(@disallow,$trole);
                   2135:             }
                   2136:         }
                   2137:         if (@disallow > 0) {
                   2138:             $checkroles = 1;
                   2139:             $js .= "    var disallow = new Array('".join("','",@disallow)."');\n".
                   2140:                    "    var rolecheck = 1;\n";
                   2141:         }
                   2142:     }
                   2143:     if (!$checkroles) {
                   2144:         $js .=  "    var disallow = new Array();\n".
                   2145:                 "    rolecheck = 0;\n";
                   2146:     }
1.273     droeschl 2147:     return <<"END";
1.235     raeburn  2148: <script type="text/javascript">
1.273     droeschl 2149: //<![CDATA[
1.401     raeburn  2150: function adhocRole(newrole) {
1.239     raeburn  2151:     $js
1.235     raeburn  2152:     if (newrole == '') {
1.350     raeburn  2153:         return;
1.235     raeburn  2154:     } 
1.239     raeburn  2155:     var fullrole = newrole+'./$cdom/$cnum';
                   2156:     var selidx = '';
                   2157:     for (var i=0; i<rolenames.length; i++) {
                   2158:         if (rolenames[i] == newrole) {
                   2159:             selidx = i;
                   2160:         }
                   2161:     }
1.350     raeburn  2162:     if (rolecheck > 0) {
                   2163:         for (var i=0; i<disallow.length; i++) {
                   2164:             if (disallow[i] == newrole) {
                   2165:                 if (confirm("$lt{'role'}\\n$lt{'swit'}")) {
                   2166:                     document.rolechooser.destinationurl.value = '/adm/menu';
                   2167:                 } else {
                   2168:                     return;
                   2169:                 }
                   2170:             }
                   2171:         }
                   2172:     }
1.239     raeburn  2173:     var secok = 1;
                   2174:     var secchoice = '';
                   2175:     if (selidx >= 0) {
                   2176:         if (numsec[selidx] > 1) {
                   2177:             secok = 0;
                   2178:             var numrolesec = rolesections[selidx].length;
                   2179:             var msgidx = numsec[selidx] - numrolesec;
1.339     raeburn  2180:             secchoice = prompt("$lt{'this'} "+secpick[msgidx]+"\\n$lt{'avai'} "+roleseclist[selidx],"");
1.239     raeburn  2181:             if (secchoice == '') {
                   2182:                 if (msgidx > 0) {
                   2183:                     secok = 1;
                   2184:                 }
                   2185:             } else {
                   2186:                 for (var j=0; j<rolesections[selidx].length; j++) {
                   2187:                     if (rolesections[selidx][j] == secchoice) {
                   2188:                         secok = 1;
                   2189:                     }
                   2190:                 }
                   2191:             }
                   2192:         } else {
                   2193:             if (rolesections[selidx].length == 1) {
                   2194:                 secchoice = rolesections[selidx][0];
                   2195:             }
                   2196:         }
                   2197:     }
                   2198:     if (secok == 1) {
                   2199:         if (secchoice != '') {
                   2200:             fullrole += '/'+secchoice;
                   2201:         }
                   2202:     } else {
                   2203:         if (secchoice != null) {
                   2204:             alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}");
                   2205:         }
                   2206:         return;
                   2207:     }
                   2208:     if (fullrole == "$env{'request.role'}") {
1.235     raeburn  2209:         return;
                   2210:     }
                   2211:     itemid = retrieveIndex('gotorole');
                   2212:     if (itemid != -1) {
1.239     raeburn  2213:         document.rolechooser.elements[itemid].name = fullrole;
1.235     raeburn  2214:     }
1.401     raeburn  2215:     document.rolechooser.switchrole.value = fullrole;
1.235     raeburn  2216:     document.rolechooser.selectrole.value = '1';
                   2217:     document.rolechooser.submit();
                   2218:     return;
                   2219: }
                   2220: 
                   2221: function retrieveIndex(item) {
                   2222:     for (var i=0;i<document.rolechooser.elements.length;i++) {
                   2223:         if (document.rolechooser.elements[i].name == item) {
                   2224:             return i;
                   2225:         }
                   2226:     }
                   2227:     return -1;
                   2228: }
1.273     droeschl 2229: // ]]>
1.235     raeburn  2230: </script>
                   2231: END
                   2232: }
                   2233: 
1.350     raeburn  2234: sub required_privs {
                   2235:     my $privs =  {
                   2236:              '/adm/parmset'      => 'opa',
                   2237:              '/adm/courseprefs'  => 'opa',
                   2238:              '/adm/whatsnew'     => 'whn',
                   2239:              '/adm/populate'     => 'cst',
                   2240:              '/adm/trackstudent' => 'vsa',
                   2241:              '/adm/statistics'   => 'vgr',
1.366     raeburn  2242:              '/adm/setblock'     => 'dcm',
1.367     raeburn  2243:              '/adm/coursedocs'   => 'mdc',
1.350     raeburn  2244:            };
                   2245:     unless ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'spreadsheet') {
1.364     raeburn  2246:         $privs->{'/adm/classcalc'}   = 'vgr',
                   2247:         $privs->{'/adm/assesscalc'}  = 'vgr',
                   2248:         $privs->{'/adm/studentcalc'} = 'vgr';
1.350     raeburn  2249:     }
                   2250:     return $privs;
                   2251: }
1.235     raeburn  2252: 
1.378     raeburn  2253: sub countdown_timer {
                   2254:     if (($env{'request.course.id'}) && ($env{'request.symb'} ne '') &&
1.387     raeburn  2255:         ($env{'request.filename'}=~/$LONCAPA::assess_re/)) {
                   2256:         my ($type,$hastimeleft,$slothastime);
                   2257:         my $now = time;
                   2258:         if ($env{'request.filename'} =~ /\.task$/) {
                   2259:             $type = 'Task';
                   2260:         } else {
                   2261:             $type = 'problem';
                   2262:         }
                   2263:         my ($status,$accessmsg,$slot_name,$slot) =
                   2264:             &Apache::lonhomework::check_slot_access('0',$type);
                   2265:         if ($slot_name ne '') {
                   2266:             if (ref($slot) eq 'HASH') {
                   2267:                 if (($slot->{'starttime'} < $now) &&
                   2268:                     ($slot->{'endtime'} > $now)) {
                   2269:                     $slothastime = 1;
                   2270:                 }
                   2271:             }
                   2272:         }
                   2273:         if ($status ne 'CAN_ANSWER') {
                   2274:             return;
                   2275:         }
1.378     raeburn  2276:         my $duedate = &Apache::lonnet::EXT("resource.0.duedate");
1.380     raeburn  2277:         my @interval=&Apache::lonnet::EXT("resource.0.interval");
1.381     raeburn  2278:         if (@interval > 1) {
                   2279:             my $first_access=&Apache::lonnet::get_first_access($interval[1]);
                   2280:             if ($first_access > 0) {
                   2281:                 if ($first_access+$interval[0] > time) {
                   2282:                     $hastimeleft = 1;
                   2283:                 }
                   2284:             }
                   2285:         }
1.380     raeburn  2286:         if (($duedate && $duedate > time) ||
1.387     raeburn  2287:             (!$duedate && $hastimeleft) ||
                   2288:             ($slot_name ne '' && $slothastime)) {
1.431.2.2  musolffc 2289:             my ($collapse,$expand,$alttxt,$title,$currdisp,$donebutton);
1.387     raeburn  2290:             if ((@interval > 1 && $hastimeleft) ||
                   2291:                 ($type eq 'Task' && $slothastime)) {
1.378     raeburn  2292:                 $currdisp = 'inline';
                   2293:                 $collapse = '&#9658;&nbsp;';
1.431.2.3  raeburn  2294:                 if ((@interval > 1) && ($hastimeleft)) {
                   2295:                     $donebutton = &done_button_js($interval[1]);
                   2296:                 }
1.378     raeburn  2297:             } else {
                   2298:                 $currdisp = 'none';
                   2299:                 $expand = '&#9668;&nbsp;';
                   2300:             }
                   2301:             unless ($env{'environment.icons'} eq 'iconsonly') {
1.379     raeburn  2302:                 $alttxt = &mt('Timer');
                   2303:                 $title = $alttxt.'&nbsp;';
1.378     raeburn  2304:             }
                   2305:             my $desc = &mt('Countdown to due date/time');
1.431.2.2  musolffc 2306: 
1.378     raeburn  2307:             return <<END;
1.431.2.3  raeburn  2308: $donebutton
1.378     raeburn  2309: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
                   2310: <span id="ddcountcollapse" class="LC_menubuttons_inline_text">
                   2311: $collapse
1.379     raeburn  2312: </span></a>
1.378     raeburn  2313: <span id="duedatecountdown" class="LC_menubuttons_inline_text" style="display: $currdisp;"></span>
                   2314: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
                   2315: <span id="ddcountexpand" class="LC_menubuttons_inline_text" >$expand</span>
1.379     raeburn  2316: <img src="/res/adm/pages/timer.png" title="$desc" class="LC_icon" alt="$alttxt" /><span class="LC_menubuttons_inline_text">$title</span></a>
1.378     raeburn  2317: END
                   2318:         }
                   2319:     }
                   2320:     return;
                   2321: }
                   2322: 
1.2       www      2323: # ================================================================ Main Program
                   2324: 
1.16      harris41 2325: BEGIN {
1.166     albertel 2326:     if (! defined($readdesk)) {
1.283     droeschl 2327:         {
                   2328:             my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
                   2329:             if ( CORE::open( my $config,"<$tabfile") ) {
                   2330:                 while (my $configline=<$config>) {
                   2331:                     $configline=(split(/\#/,$configline))[0];
                   2332:                     $configline=~s/^\s+//;
                   2333:                     chomp($configline);
1.209     www      2334:                     if ($configline=~/^cat\:/) {
1.283     droeschl 2335:                         my @entries=split(/\:/,$configline);
                   2336:                         $category_positions{$entries[2]}=$entries[1];
                   2337:                         $category_names{$entries[2]}=$entries[3];
                   2338:                     } elsif ($configline=~/^prim\:/) {
1.415     raeburn  2339:                         my @entries = (split(/\:/, $configline))[1..6];
1.400     raeburn  2340:                         push(@primary_menu,\@entries);
1.371     raeburn  2341:                     } elsif ($configline=~/^primsub\:/) {
                   2342:                         my ($parent,@entries) = (split(/\:/, $configline))[1..4];
1.400     raeburn  2343:                         push(@{$primary_submenu{$parent}},\@entries);
1.283     droeschl 2344:                     } elsif ($configline=~/^scnd\:/) {
                   2345:                         my @entries = (split(/\:/, $configline))[1..5];
1.401     raeburn  2346:                         push(@secondary_menu,\@entries);
1.283     droeschl 2347:                     } elsif ($configline) {
                   2348:                         push(@desklines,$configline);
                   2349:                     }
                   2350:                 }
                   2351:                 CORE::close($config);
                   2352:             }
                   2353:         }
                   2354:         $readdesk='done';
1.2       www      2355:     }
                   2356: }
1.30      www      2357: 
1.1       www      2358: 1;
                   2359: __END__
                   2360: 

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