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

1.1       www         1: # The LearningOnline Network with CAPA
                      2: # Routines to control the menu
                      3: #
1.500   ! raeburn     4: # $Id: lonmenu.pm,v 1.499 2019/08/06 23:10:18 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.486     raeburn   102: =item prep_menuitems(\@menuitem,$ltitarget)
1.314     droeschl  103: 
                    104: This routine wraps a menuitem in proper HTML. It is used by primary_menu() and 
                    105: secondary_menu().
                    106: 
                    107: =item primary_menu()
                    108: 
1.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: 
1.447     raeburn   127: Inputs: 6 - (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:             (e) boolean to indicate whether to call &mt() to translate 
                    131:                 name of menu item,
                    132:             (f) optional class for <li> element in primary menu, for which
                    133:                 sub menu is being generated.
1.375     raeburn   134: 
1.431     golterma  135:  The underlying datastructure used in (d) contains data from mydesk.tab.
                    136:  It consists of an array which has an array for each item appearing in
                    137:  the menu (e.g. [["link", "title", "condition"]] for a single-item menu).
                    138:  create_submenu() supports also the creation of XHTML for nested dropdown
                    139:  menus represented by unordered lists. This is done by replacing the
                    140:  scalar used for the link with an arrayreference containing the menuitems
                    141:  for the nested menu. This can be done recursively so that the next menu
                    142:  may also contain nested submenus.
                    143: 
                    144:  Example:
                    145:  [											# begin of datastructure
                    146: 	["/home/", "Home", "condition1"], 		# 1st item of the 1st layer menu
                    147: 	[										# 2nd item of the 1st layer menu
                    148: 		[									# anon. array for nested menu
                    149: 			["/path1", "Path1", undef], 	# 1st item of the 2nd layer menu
                    150: 			["/path2", "Path2", undef], 	# 2nd item of the 2nd layer menu
                    151: 			[								# 3rd item of the 2nd layer menu
                    152: 				[[...], [...], ..., [...]],	# containing another menu layer
                    153: 				"Sub-Sub-Menu",				# title for this container
                    154: 				undef
                    155: 			]
                    156: 		],									# end of array/nested menu
                    157: 		"Sub-Menu",							# title for the container item
                    158: 		undef
                    159: 	]										# end of 2nd item of the 1st layer menu
                    160: ]
                    161: 
1.244     jms       162: =item innerregister()
                    163: 
1.320     droeschl  164: This gets called in order to register a URL in the body of the document
1.244     jms       165: 
                    166: =item clear()
                    167: 
                    168: =item switch()
                    169: 
                    170: Switch a button or create a link
                    171: Switch acts on the javascript that is executed when a button is clicked.  
                    172: The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
                    173: 
                    174: =item secondlevel()
                    175: 
                    176: =item openmenu()
                    177: 
                    178: =item inlinemenu()
                    179: 
                    180: =item rawconfig()
                    181: 
                    182: =item utilityfunctions()
                    183: 
1.371     raeburn   184: Output from this routine is a number of javascript functions called by
                    185: items in the inline menu, and in some cases items in the Main Menu page. 
                    186: 
1.244     jms       187: =item serverform()
                    188: 
                    189: =item constspaceform()
                    190: 
                    191: =item get_nav_status()
                    192: 
                    193: =item hidden_button_check()
                    194: 
                    195: =item roles_selector()
                    196: 
                    197: =item jump_to_role()
                    198: 
                    199: =back
                    200: 
                    201: =cut
                    202: 
1.1       www       203: package Apache::lonmenu;
                    204: 
                    205: use strict;
1.152     albertel  206: use Apache::lonnet;
1.47      matthew   207: use Apache::lonhtmlcommon();
1.115     albertel  208: use Apache::loncommon();
1.127     albertel  209: use Apache::lonenc();
1.88      www       210: use Apache::lonlocal;
1.361     raeburn   211: use Apache::lonmsg();
1.207     foxr      212: use LONCAPA qw(:DEFAULT :match);
1.486     raeburn   213: use LONCAPA::ltiutils;
1.282     amueller  214: use HTML::Entities();
1.346     wenzelju  215: use Apache::lonwishlist();
1.88      www       216: 
1.283     droeschl  217: use vars qw(@desklines %category_names %category_members %category_positions 
1.482     raeburn   218:             $readdesk @primary_menu %primary_submenu @secondary_menu %secondary_submenu);
1.88      www       219: 
1.56      www       220: my @inlineremote;
1.38      www       221: 
1.283     droeschl  222: sub prep_menuitem {
1.486     raeburn   223:     my ($menuitem,$ltitarget) = @_;
1.291     raeburn   224:     return '' unless(ref($menuitem) eq 'ARRAY');
1.283     droeschl  225:     my $link;
                    226:     if ($$menuitem[1]) { # graphical Link
                    227:         $link = "<img class=\"LC_noBorder\""
1.291     raeburn   228:               . " src=\"" . &Apache::loncommon::lonhttpdurl($$menuitem[1]) . "\"" 
                    229:               . " alt=\"" . &mt($$menuitem[2]) . "\" />";
1.283     droeschl  230:     } else {             # textual Link
1.291     raeburn   231:         $link = &mt($$menuitem[3]);
                    232:     }
1.486     raeburn   233:     my $target = ' target="_top"';
                    234:     if ($ltitarget eq 'iframe') {
                    235:         $target ='';
                    236:     }
1.316     droeschl  237:     return '<li><a' 
                    238:            # highlighting for new messages
                    239:            . ( $$menuitem[4] eq 'newmsg' ? ' class="LC_new_message"' : '') 
1.486     raeburn   240:            . qq| href="$$menuitem[0]"$target>$link</a></li>|;
1.283     droeschl  241: }
                    242: 
1.415     raeburn   243: # primary_menu() evaluates @primary_menu and returns a two item array,
                    244: # with the array elements containing XHTML for the left and right sides of 
                    245: # the menu that contains the following links:
                    246: # Personal, About, Message, Roles, Help, Logout
1.283     droeschl  247: # @primary_menu is filled within the BEGIN block of this module with 
                    248: # entries from mydesk.tab
                    249: sub primary_menu {
1.491     raeburn   250:     my ($crstype,$ltimenu) = @_;
                    251:     my (%menu,%ltiexc);
1.283     droeschl  252:     # each element of @primary contains following array:
1.415     raeburn   253:     # (link url, icon path, alt text, link text, condition, position)
1.319     raeburn   254:     my $public;
                    255:     if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
                    256:         || (($env{'user.name'} eq '') && ($env{'user.domain'} eq ''))) {
                    257:         $public = 1;
                    258:     }
1.443     raeburn   259:     my $rolecount;
                    260:     if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) {
                    261:         my $update=$env{'user.update.time'};
                    262:         if (!$update) {
                    263:             $update = $env{'user.login.time'};
                    264:         }
                    265:         my %roles_in_env;
                    266:         $rolecount = &Apache::lonroles::roles_from_env(\%roles_in_env,$update);
                    267:     }
1.491     raeburn   268:     my ($lti,$ltitarget);
1.486     raeburn   269:     if ($env{'request.lti.login'}) {
1.491     raeburn   270:         $lti = 1;
1.486     raeburn   271:         $ltitarget = $env{'request.lti.target'};
1.491     raeburn   272:         if (ref($ltimenu) eq 'HASH') {
                    273:             foreach my $item ('fullname','logout') {
                    274:                 unless ($ltimenu->{$item}) {
                    275:                     $ltiexc{$item} = 1;
                    276:                 }
                    277:             }
                    278:         }
1.486     raeburn   279:     }
1.283     droeschl  280:     foreach my $menuitem (@primary_menu) {
                    281:         # evaluate conditions 
1.296     droeschl  282:         next if    ref($menuitem)       ne 'ARRAY';    #
1.283     droeschl  283:         next if    $$menuitem[4]        eq 'nonewmsg'  # show links depending on
1.291     raeburn   284:                 && &Apache::lonmsg::mynewmail();       # whether a new msg 
1.283     droeschl  285:         next if    $$menuitem[4]        eq 'newmsg'    # arrived or not
1.291     raeburn   286:                 && !&Apache::lonmsg::mynewmail();      # 
1.319     raeburn   287:         next if    $$menuitem[4]        !~ /public/    ##we've a public user,
                    288:                 && $public;                            ##who should not see all
                    289:                                                        ##links
1.283     droeschl  290:         next if    $$menuitem[4]        eq 'onlypublic'# hide links which are 
1.319     raeburn   291:                 && !$public;                           # only visible to public
                    292:                                                        # users
1.283     droeschl  293:         next if    $$menuitem[4]        eq 'roles'     ##show links depending on
1.491     raeburn   294:                 && (&Apache::loncommon::show_course()  ##term 'Courses' or
                    295:                 || $env{'request.lti.login'});         ##'Roles' wanted
                    296:         next if    $$menuitem[4]        eq 'courses'   ##and not LTI access
                    297:                 && (!&Apache::loncommon::show_course()
                    298:                 || !$env{'request.lti.login'});
                    299:         next if    $$menuitem[4]        eq 'notlti'
                    300:                 && $lti;
                    301:         next if    $$menuitem[4]        eq 'ltiexc'
                    302:                 && exists($ltiexc{lc($menuitem->[3])});
1.371     raeburn   303:         my $title = $menuitem->[3];
1.443     raeburn   304:         if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) {
                    305:             if ($menuitem->[4] eq 'courses') {
                    306:                 next unless ($rolecount>1);
                    307:             } else {
                    308:                 next unless (($title eq 'Personal') || ($title eq 'Logout'));
                    309:             }
                    310:         }
1.415     raeburn   311:         my $position = $menuitem->[5];
                    312:         if ($position eq '') {
                    313:             $position = 'right';
                    314:         }
1.371     raeburn   315:         if (defined($primary_submenu{$title})) {
1.375     raeburn   316:             my ($link,$target);
1.371     raeburn   317:             if ($menuitem->[0] ne '') {
                    318:                 $link = $menuitem->[0];
1.486     raeburn   319:                 unless ($ltitarget eq 'iframe') {
                    320:                     $target = '_top';
                    321:                 }
1.371     raeburn   322:             } else {
                    323:                 $link = '#';
                    324:             }
1.375     raeburn   325:             my @primsub;
1.371     raeburn   326:             if (ref($primary_submenu{$title}) eq 'ARRAY') {
1.375     raeburn   327:                 foreach my $item (@{$primary_submenu{$title}}) {
1.443     raeburn   328:                     next if (($crstype eq 'Placement') && (!$env{'request.role.adv'}));
1.383     raeburn   329:                     next if (($item->[2] eq 'wishlist') && (!$env{'user.adv'}));
1.375     raeburn   330:                     next if ((($item->[2] eq 'portfolio') ||
                    331:                              ($item->[2] eq 'blog')) &&
                    332:                              (!&Apache::lonnet::usertools_access('','',$item->[2],
                    333:                                                            undef,'tools')));
                    334:                     push(@primsub,$item);
                    335:                 }
1.443     raeburn   336:                 if ($title eq 'Personal' && $env{'user.name'} && $env{'user.domain'} ) {
1.491     raeburn   337:                     unless ($ltiexc{'fullname'}) {
                    338:                         $title = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'});
                    339:                     }
1.443     raeburn   340:                 } else {
                    341:                     $title = &mt($title);
                    342:                 }
1.375     raeburn   343:                 if (@primsub > 0) {
1.419     bisitz    344:                     $menu{$position} .= &create_submenu($link,$target,$title,\@primsub,1);
1.375     raeburn   345:                 } elsif ($link) {
1.443     raeburn   346:                     $menu{$position} .= '<li><a href="'.$link.'" target="'.$target.'">'.$title.'</a></li>';
1.371     raeburn   347:                 }
                    348:             }
                    349:         } elsif ($$menuitem[3] eq 'Help') { # special treatment for helplink
1.443     raeburn   350:             next if ($crstype eq 'Placement'); 
1.340     raeburn   351:             if ($public) {
                    352:                 my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
                    353:                 my $defdom = &Apache::lonnet::default_login_domain();
                    354:                 my $to = &Apache::loncommon::build_recipient_list(undef,
                    355:                                                                   'helpdeskmail',
                    356:                                                                   $defdom,$origmail);
                    357:                 if ($to ne '') {
1.486     raeburn   358:                     $menu{$position} .= &prep_menuitem($menuitem,$ltitarget); 
1.340     raeburn   359:                 }
                    360:             } else {
1.415     raeburn   361:                 $menu{$position} .= '<li>'.&Apache::loncommon::top_nav_help('Help').'</li>';
1.340     raeburn   362:             }
1.283     droeschl  363:         } else {
1.486     raeburn   364:             $menu{$position} .= prep_menuitem($menuitem,$ltitarget);
1.283     droeschl  365:         }
1.291     raeburn   366:     }
1.423     raeburn   367:     my @output = ('','');
                    368:     if ($menu{'left'} ne '') {
                    369:         $output[0] = "<ol class=\"LC_primary_menu LC_floatleft\">$menu{'left'}</ol>";
                    370:     }
                    371:     if ($menu{'right'} ne '') {
                    372:         $output[1] = "<ol class=\"LC_primary_menu LC_floatright LC_right\">$menu{'right'}</ol>";
                    373:     }
                    374:     return @output;
1.283     droeschl  375: }
                    376: 
1.329     droeschl  377: #returns hashref {user=>'',dom=>''} containing:
                    378: #   own name, domain if user is au
                    379: #   name, domain of parent author if user is ca or aa
                    380: #empty return if user is not an author or not on homeserver
                    381: #
                    382: #TODO this should probably be moved somewhere more central
                    383: #since it can be used by different parts of the system
                    384: sub getauthor{
                    385:     return unless $env{'request.role'}=~/^(ca|aa|au)/; #nothing to do if user isn't some kind of author
                    386: 
                    387:                         #co- or assistent author?
                    388:     my ($dom, $user) = ($env{'request.role'} =~ /^(?:ca|aa)\.\/($match_domain)\/($match_username)$/)
                    389:                        ? ($1, $2) #domain, username of the parent author
                    390:                        : @env{ ('request.role.domain', 'user.name') }; #own domain, username
                    391: 
                    392:     # current server == home server?
                    393:     my $home =  &Apache::lonnet::homeserver($user,$dom);
                    394:     foreach (&Apache::lonnet::current_machine_ids()){
                    395:         return {user => $user, dom => $dom} if $_ eq $home;
                    396:     }
                    397: 
                    398:     # if wrong server
                    399:     return;
                    400: }
1.283     droeschl  401: 
                    402: sub secondary_menu {
1.491     raeburn   403:     my ($httphost,$ltiscope,$ltimenu,$noprimary) = @_;
1.283     droeschl  404:     my $menu;
                    405: 
1.286     raeburn   406:     my $crstype = &Apache::loncommon::course_type();
1.327     droeschl  407:     my $crs_sec = $env{'request.course.id'} . ($env{'request.course.sec'} 
                    408:                                                ? "/$env{'request.course.sec'}"
                    409:                                                : '');
                    410:     my $canedit       = &Apache::lonnet::allowed('mdc', $env{'request.course.id'});
1.464     raeburn   411:     my $canvieweditor = &Apache::lonnet::allowed('cev', $env{'request.course.id'});
1.376     raeburn   412:     my $canviewroster = $env{'course.'.$env{'request.course.id'}.'.student_classlist_view'};
1.418     raeburn   413:     if ($canviewroster eq 'disabled') {
                    414:         undef($canviewroster);
                    415:     }
1.327     droeschl  416:     my $canviewgrps   = &Apache::lonnet::allowed('vcg', $crs_sec); 
1.453     raeburn   417:     my $canmodifyuser = &Apache::lonnet::allowed('cst', $crs_sec);
                    418:     my $canviewusers  = &Apache::lonnet::allowed('vcl', $crs_sec); 
1.327     droeschl  419:     my $canviewwnew   = &Apache::lonnet::allowed('whn', $crs_sec); 
1.454     raeburn   420:     my $canviewpara   = &Apache::lonnet::allowed('vpa', $crs_sec);
1.341     www       421:     my $canmodpara    = &Apache::lonnet::allowed('opa', $crs_sec);
1.343     www       422:     my $canvgr        = &Apache::lonnet::allowed('vgr', $crs_sec);
                    423:     my $canmgr        = &Apache::lonnet::allowed('mgr', $crs_sec); 
1.489     raeburn   424:     my $canplc        = &Apache::lonnet::allowed('plc', $crs_sec);
1.343     www       425:     my $author        = &getauthor();
1.327     droeschl  426: 
1.491     raeburn   427:     my ($cdom,$cnum,$showsyllabus,$showfeeds,$showresv,$grouptools,$lti,$ltimapres,%ltiexc);
1.439     raeburn   428:     $grouptools = 0;
1.413     raeburn   429:     if ($env{'request.course.id'}) {
                    430:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                    431:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.482     raeburn   432:         unless ($canedit || $canvieweditor)  {
1.414     raeburn   433:             unless (&Apache::lonnet::is_on_map("public/$cdom/$cnum/syllabus")) {
                    434:                 if (($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'}) ||
                    435:                     ($env{'course.'.$env{'request.course.id'}.'.uploadedsyllabus'}) ||
                    436:                     ($env{'course.'.$env{'request.course.id'}.'.updatedsyllabus'}) ||
                    437:                     ($env{'request.course.syllabustime'})) {
                    438:                     $showsyllabus = 1;
                    439:                 }
                    440:             }
                    441:             if ($env{'request.course.feeds'}) {
                    442:                 $showfeeds = 1;
1.413     raeburn   443:             }
                    444:         }
1.464     raeburn   445:         unless ($canmgr || $canvgr) {
1.417     raeburn   446:             my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
                    447:             if (keys(%slots) > 0) {
                    448:                 $showresv = 1;
                    449:             }
                    450:         }
1.497     raeburn   451:         if ($env{'request.course.groups'} ne '') {
1.499     raeburn   452:             foreach my $group (split(/:/,$env{'request.course.groups'})) {
1.498     raeburn   453:                 next unless ($group =~ /^\w+$/);
1.439     raeburn   454:                 my @privs = split(/:/,$env{"user.priv.$env{'request.role'}./$cdom/$cnum/$group"});
                    455:                 shift(@privs);
                    456:                 if (@privs) {
                    457:                     $grouptools ++;
                    458:                 }
                    459:             }
                    460:         }
1.491     raeburn   461:         if ($env{'request.lti.login'}) {
                    462:             $lti = 1;
                    463:             if (ref($ltimenu) eq 'HASH') {
                    464:                 foreach my $item ('fullname','coursetitle','role','logout','grades') {
                    465:                     unless ($ltimenu->{$item}) {
                    466:                         $ltiexc{$item} = 1;
                    467:                     }
                    468:                 }
                    469:             }
                    470:             if (($ltiscope eq 'map') || ($ltiscope eq 'resource')) {
                    471:                 $ltimapres = 1;
                    472:             }
                    473:         }
1.413     raeburn   474:     }
                    475: 
1.404     raeburn   476:     my ($canmodifycoauthor); 
                    477:     if ($env{'request.role'} eq "au./$env{'user.domain'}/") {
                    478:         my $extent = "$env{'user.domain'}/$env{'user.name'}";
                    479:         if ((&Apache::lonnet::allowed('cca',$extent)) ||
                    480:             (&Apache::lonnet::allowed('caa',$extent))) {
                    481:             $canmodifycoauthor = 1;
                    482:         }
                    483:     }
1.491     raeburn   484: 
1.486     raeburn   485:     my ($roleswitcher_js,$roleswitcher_form,$ltitarget);
                    486:     if ($env{'request.lti.login'}) {
                    487:         $ltitarget = $env{'request.lti.target'};
                    488:     }
1.401     raeburn   489: 
1.283     droeschl  490:     foreach my $menuitem (@secondary_menu) {
                    491:         # evaluate conditions 
1.296     droeschl  492:         next if    ref($menuitem)  ne 'ARRAY';
1.443     raeburn   493:         next if (($crstype eq 'Placement') && ($$menuitem[3] ne 'Roles') && (!$env{'request.role.adv'}));
1.283     droeschl  494:         next if    $$menuitem[4]   ne 'always'
1.404     raeburn   495:                 && ($$menuitem[4]   ne 'author' && $$menuitem[4] ne 'cca')
1.283     droeschl  496:                 && !$env{'request.course.id'};
1.464     raeburn   497:         next if    $$menuitem[4]   =~ /^crsedit/
                    498:                 && (!$canedit && !$canvieweditor);
1.341     www       499:         next if    $$menuitem[4]  eq 'nvgr'
1.491     raeburn   500:                 && ($canvgr || $ltiexc{'grades'});
1.341     www       501:         next if    $$menuitem[4]  eq 'vgr'
                    502:                 && !$canvgr;
1.456     raeburn   503:         next if    $$menuitem[4]   eq 'viewusers'
1.453     raeburn   504:                 && !$canmodifyuser && !$canviewusers;
1.456     raeburn   505:         next if    $$menuitem[4]   eq 'noviewusers'
1.453     raeburn   506:                 && ($canmodifyuser || $canviewusers || !$canviewroster);
1.343     www       507:         next if    $$menuitem[4]   eq 'mgr'
                    508:                 && !$canmgr;
1.417     raeburn   509:         next if    $$menuitem[4]   eq 'showresv'
                    510:                 && !$showresv;
1.327     droeschl  511:         next if    $$menuitem[4]   eq 'whn'
                    512:                 && !$canviewwnew;
1.454     raeburn   513:         next if    $$menuitem[4]   eq 'params'
                    514:                 && (!$canmodpara && !$canviewpara);
1.482     raeburn   515:         next if    $$menuitem[4]   eq 'showgroups'
                    516:                 && ($canviewgrps || !$grouptools);
1.413     raeburn   517:         next if    $$menuitem[4]   eq 'showsyllabus'
                    518:                 && !$showsyllabus;
                    519:         next if    $$menuitem[4]   eq 'showfeeds'
                    520:                 && !$showfeeds;
1.489     raeburn   521:         next if     $$menuitem[4]  eq 'plc'
                    522:                 && !$canplc;
1.329     droeschl  523:         next if    $$menuitem[4]    eq 'author'
                    524:                 && !$author;
1.404     raeburn   525:         next if    $$menuitem[4]    eq 'cca'
                    526:                 && !$canmodifycoauthor;
1.490     raeburn   527:         next if    $$menuitem[4]    eq 'notltimapres'
1.491     raeburn   528:                 && $ltimapres;
                    529:         next if    $$menuitem[4]    eq 'notlti'
                    530:                 && $lti;
                    531:         next if    $$menuitem[4]    eq 'lti'
                    532:                 && (!$lti || !$noprimary);
                    533:         next if    $$menuitem[3]    eq 'Logout'
                    534:                 && $ltiexc{'logout'};
1.283     droeschl  535: 
1.482     raeburn   536:         my $title = $menuitem->[3];
                    537:         if (defined($secondary_submenu{$title})) {
                    538:             my ($link,$target);
                    539:             if ($menuitem->[0] ne '') {
                    540:                 $link = $menuitem->[0];
1.486     raeburn   541:                 unless ($ltitarget eq 'iframe') {   
                    542:                     $target = '_top';
                    543:                 }
1.482     raeburn   544:             } else {
                    545:                 $link = '#';
                    546:             }
                    547:             my @scndsub;
                    548:             if (ref($secondary_submenu{$title}) eq 'ARRAY') {
                    549:                 foreach my $item (@{$secondary_submenu{$title}}) {
                    550:                     if (ref($item) eq 'ARRAY') {
                    551:                         next if ($item->[2] eq 'vgr' && !$canvgr);
                    552:                         next if ($item->[2] eq 'opa' && !$canmodpara);
                    553:                         next if ($item->[2] eq 'vpa' && !$canviewpara);
                    554:                         next if ($item->[2] eq 'viewusers' && !($canmodifyuser || $canviewusers));
                    555:                         next if ($item->[2] eq 'mgr' && !$canmgr);
                    556:                         next if ($item->[2] eq 'vcg' && !$canviewgrps);
                    557:                         next if ($item->[2] eq 'crsedit' && !$canedit && !$canvieweditor);
                    558:                         next if ($item->[2] eq 'params' && !$canmodpara && !$canviewpara);
1.483     raeburn   559:                         next if ($item->[2] eq 'author' && !$author);
                    560:                         next if ($item->[2] eq 'cca' && !$canmodifycoauthor);
1.491     raeburn   561:                         next if ($item->[2] eq 'lti' && !$lti);
                    562:                         if ($item->[2] =~ /^lti(portfolio|wishlist|blog)$/) {
                    563:                             my $tool = $1;
                    564:                             next if !$lti;
                    565:                             next if (!&Apache::lonnet::usertools_access('','',$tool,
                    566:                                                                         undef,'tools'));
                    567:                         }
1.482     raeburn   568:                         push(@scndsub,$item);
                    569:                     }
                    570:                 }
1.491     raeburn   571:                 if ($title eq 'Personal' && $env{'user.name'} && $env{'user.domain'} ) {
                    572:                     unless ($ltiexc{'fullname'}) {
                    573:                         $title = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'});
                    574:                     }
                    575:                 }
1.482     raeburn   576:                 if (@scndsub > 0) {
                    577:                     $menu .= &create_submenu($link,$target,$title,\@scndsub,1);
                    578:                 } elsif ($link ne '#') {
                    579:                     $menu .= '<li><a href="'.$link.'" target="'.$target.'">'.&mt($title).'</a></li>';
                    580:                 }
                    581:             }
                    582:         } elsif ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) {
1.283     droeschl  583:             # special treatment for role selector
1.491     raeburn   584:             ($roleswitcher_js,$roleswitcher_form,my $switcher) =
                    585:                 &roles_selector(
                    586:                     $env{'course.' . $env{'request.course.id'} . '.domain'},
                    587:                     $env{'course.' . $env{'request.course.id'} . '.num'},
                    588:                     $httphost,$ltitarget
                    589:                 );
                    590:             $menu .= $switcher;
                    591:         } elsif ($$menuitem[3] eq 'Help') { # special treatment for helplink
                    592:             next if ($crstype eq 'Placement');
                    593:             $menu .= '<li>'.&Apache::loncommon::top_nav_help('Help').'</li>';
1.296     droeschl  594:         } else {
1.414     raeburn   595:             if ($$menuitem[3] eq 'Syllabus' && $env{'request.course.id'}) {
                    596:                 my $url = $$menuitem[0];
                    597:                 $url =~ s{\[cdom\]/\[cnum\]}{$cdom/$cnum};
                    598:                 if (&Apache::lonnet::is_on_map($url)) {
1.468     raeburn   599:                     unless ($$menuitem[0] =~ /(\?|\&)register=1/) {
                    600:                         $$menuitem[0] .= (($$menuitem[0]=~/\?/)? '&' : '?').'register=1';
1.414     raeburn   601:                     }
                    602:                 } else {
1.468     raeburn   603:                     $$menuitem[0] =~ s{\&?register=1}{};
1.414     raeburn   604:                 }
1.468     raeburn   605:                 if ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://}) {
                    606:                     if (($ENV{'SERVER_PORT'} == 443) || ($env{'request.use_absolute'} =~ m{^https://})) {
1.493     raeburn   607:                         unless (&Apache::lonnet::uses_sts()) {
                    608:                             unless ($$menuitem[0] =~ m{^https?://}) {
                    609:                                 $$menuitem[0] = 'http://'.$ENV{'SERVER_NAME'}.$$menuitem[0];
                    610:                             }
                    611:                             unless ($$menuitem[0] =~ /(\&|\?)usehttp=1/) {
                    612:                                 $$menuitem[0] .= (($$menuitem[0]=~/\?/) ? '&' : '?').'usehttp=1';
                    613:                             }
1.468     raeburn   614:                         }
                    615:                     }
1.467     raeburn   616:                 }
1.473     raeburn   617:                 $$menuitem[0] = &HTML::Entities::encode($$menuitem[0],'&<>"');
1.414     raeburn   618:             }
1.486     raeburn   619:             $menu .= &prep_menuitem(\@$menuitem,$ltitarget);
1.283     droeschl  620:         }
                    621:     }
                    622:     if ($menu =~ /\[url\].*\[symb\]/) {
1.291     raeburn   623:         my $escurl  = &escape( &Apache::lonenc::check_encrypt(
                    624:                              $env{'request.noversionuri'}));
1.283     droeschl  625: 
1.291     raeburn   626:         my $escsymb = &escape( &Apache::lonenc::check_encrypt(
                    627:                              $env{'request.symb'})); 
1.283     droeschl  628: 
                    629:         if (    $env{'request.state'} eq 'construct'
                    630:             and (   $env{'request.noversionuri'} eq '' 
                    631:                  || !defined($env{'request.noversionuri'}))) 
                    632:         {
1.359     raeburn   633:             my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
                    634:             ($escurl = $env{'request.filename'}) =~ s{^\Q$londocroot\E}{};
1.291     raeburn   635:             $escurl  = &escape($escurl);
1.473     raeburn   636:         }
1.283     droeschl  637:         $menu =~ s/\[url\]/$escurl/g;
                    638:         $menu =~ s/\[symb\]/$escsymb/g;
                    639:     }
1.329     droeschl  640:     $menu =~ s/\[uname\]/$$author{user}/g;
                    641:     $menu =~ s/\[udom\]/$$author{dom}/g;
1.491     raeburn   642:     $menu =~ s/\[javascript\]/javascript:/g;
1.482     raeburn   643:     if ($env{'request.course.id'}) {
1.413     raeburn   644:         $menu =~ s/\[cnum\]/$cnum/g;
                    645:         $menu =~ s/\[cdom\]/$cdom/g;
                    646:     }
1.385     raeburn   647:     if ($menu) {
                    648:         $menu = "<ul id=\"LC_secondary_menu\">$menu</ul>";
                    649:     }
1.401     raeburn   650:     if ($roleswitcher_form) {
                    651:         $menu .= "\n$roleswitcher_js\n$roleswitcher_form";
                    652:     }
1.385     raeburn   653:     return $menu;
1.283     droeschl  654: }
                    655: 
1.375     raeburn   656: sub create_submenu {
1.447     raeburn   657:     my ($link,$target,$title,$submenu,$translate,$addclass) = @_;
1.375     raeburn   658:     return unless (ref($submenu) eq 'ARRAY');
1.379     raeburn   659:     my $disptarget;
                    660:     if ($target ne '') {
                    661:         $disptarget = ' target="'.$target.'"';
                    662:     }
1.447     raeburn   663:     my $menu = '<li class="LC_hoverable '.$addclass.'">'.
1.379     raeburn   664:                '<a href="'.$link.'"'.$disptarget.'>'.
1.432     droeschl  665:                '<span class="LC_nobreak">'.$title.
1.375     raeburn   666:                '<span class="LC_fontsize_small" style="font-weight:normal;">'.
                    667:                ' &#9660;</span></span></a>'.
                    668:                '<ul>';
1.431     golterma  669: 
                    670:     # $link and $title are only used in the initial string written in $menu
                    671:     # as seen above, not needed for nested submenus
                    672:     $menu .= &build_submenu($target, $submenu, $translate, '1');
                    673:     $menu .= '</ul></li>';
                    674: 
                    675:     return $menu;
                    676: }
                    677: 
                    678: # helper routine for create_submenu
                    679: # build the dropdown (and nested submenus) recursively
                    680: # see perldoc create_submenu documentation for further information
                    681: sub build_submenu {
                    682:     my ($target, $submenu, $translate, $first_level) = @_; 
1.446     raeburn   683:     unless (@{$submenu}) {
1.431     golterma  684:         return '';
                    685:     }
                    686: 
                    687:     my $menu = '';
1.375     raeburn   688:     my $count = 0;
                    689:     my $numsub = scalar(@{$submenu});
                    690:     foreach my $item (@{$submenu}) {
                    691:         $count ++;
                    692:         if (ref($item) eq 'ARRAY') {
1.416     raeburn   693:             my $href = $item->[0];
1.431     golterma  694:             my $bordertop;
                    695:             my $borderbot;
                    696:             my $title;
                    697: 
                    698:             if ($translate) {
                    699:                  $title = &mt($item->[1]);
                    700:             } else {
                    701:                 $title = $item->[1];
                    702:             }
                    703: 
                    704:             if ($count == 1 && !$first_level) {
                    705:                 $bordertop = 'border-top: 1px solid black;';
1.416     raeburn   706:             }
1.375     raeburn   707:             if ($count == $numsub) {
1.431     golterma  708:                 $borderbot = 'border-bottom: 1px solid black;';
1.375     raeburn   709:             }
1.431     golterma  710: 
                    711:             # href is a reference to another submenu
                    712:             if (ref($href) eq 'ARRAY') {
                    713:                 $menu .= '<li style="margin:0;padding:0;'.$bordertop . $borderbot . '">';
                    714:                 $menu .= '<p><span class="LC_primary_menu_innertitle">'
                    715: 					. $title . '</span><span class="LC_primary_menu_innerarrow">&#9654;</span></p>';
                    716:                 $menu .= '<ul>';
                    717:                 $menu .= &build_submenu($target, $href, $translate);
                    718:                 $menu .= '</ul>';
                    719:                 $menu .= '</li>';    
                    720:             } else {    # href is the actual hyperlink and does not represent another submenu
                    721:                         # for the current menu title
                    722:                 if ($href =~ /(aboutme|rss\.html)$/) {
                    723:                     next unless (($env{'user.name'} ne '') && ($env{'user.domain'} ne ''));
                    724:                     $href =~ s/\[domain\]/$env{'user.domain'}/g;
                    725:                     $href =~ s/\[user\]/$env{'user.name'}/g;
1.488     raeburn   726:                 } elsif (($href =~ m{^/adm/preferences\?}) && ($href =~ /\[returnurl\]/)) {
                    727:                     my $returnurl = $ENV{'REQUEST_URI'};
                    728:                     if ($ENV{'REQUEST_URI'} =~ m{/adm/preferences\?action=(?:changedomcoord|authorsettings)\&returnurl=([^\&]+)$}) {
                    729:                         $returnurl = $1;
                    730:                     }
                    731:                     if (($returnurl =~ m{^/adm/createuser($|\?action=)}) ||
                    732:                         ($returnurl =~ m{^/priv/$match_domain/$match_username}) ||
                    733:                         ($returnurl =~ m{^/res(/?$|/$match_domain/$match_username)})) {
                    734:                         $returnurl =~ s{\?.*$}{};
                    735:                         $returnurl = '&amp;returnurl='.&HTML::Entities::encode($returnurl,'"<>&\'');
                    736:                     } else {
                    737:                         undef($returnurl);
                    738:                     }
                    739:                     $href =~ s/\[returnurl\]/$returnurl/;
1.431     golterma  740:                 }
                    741:                 unless (($href eq '') || ($href =~ /^\#/)) {
1.486     raeburn   742:                     if ($target eq '_top') {
                    743:                         $target = ' target="_top"';
                    744:                     }
1.431     golterma  745:                 }
                    746: 
                    747:                 $menu .= '<li style="margin:0;padding:0;'. $bordertop . $borderbot .'">';
                    748:                 $menu .= '<a href="'.$href.'"'.$target.'>' .  $title . '</a>';
                    749:                 $menu .= '</li>';
1.425     raeburn   750:             }
1.375     raeburn   751:         }
                    752:     }
                    753:     return $menu;
                    754: }
                    755: 
1.40      www       756: sub innerregister {
1.490     raeburn   757:     my ($forcereg,$bread_crumbs,$group,$pagebuttonshide,$hostname,$ltiscope,$ltiuri) = @_;
1.152     albertel  758:     my $const_space = ($env{'request.state'} eq 'construct');
1.131     raeburn   759:     my $is_const_dir = 0;
1.120     raeburn   760: 
1.175     albertel  761:     if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
1.40      www       762: 
1.174     albertel  763:     $env{'request.registered'} = 1;
1.40      www       764: 
1.177     albertel  765:     undef(@inlineremote);
1.56      www       766: 
1.490     raeburn   767:     my ($mapurl,$resurl,$crstype,$navmap);
1.390     raeburn   768: 
1.393     raeburn   769:     if ($env{'request.course.id'}) {
1.443     raeburn   770: #
                    771: #course_type:  Course, Community, or Placement
                    772: #
                    773:         $crstype = &Apache::loncommon::course_type();
1.393     raeburn   774:         if ($env{'request.symb'}) {
1.476     raeburn   775:             my $ignorenull;
                    776:             unless ($env{'request.noversionuri'} eq '/adm/navmaps') {
                    777:                 $ignorenull = 1;
                    778:             }
                    779:             my $symb = &Apache::lonnet::symbread('','',$ignorenull);
                    780:             ($mapurl, my $rid, $resurl) = &Apache::lonnet::decode_symb($symb);
1.393     raeburn   781:             my $coursetitle = $env{'course.'.$env{'request.course.id'}.'.description'};
1.267     droeschl  782: 
1.393     raeburn   783:             my $maptitle = &Apache::lonnet::gettitle($mapurl);
1.476     raeburn   784:             my $restitle = &Apache::lonnet::gettitle($symb);
1.475     raeburn   785:             my (@crumbs,@mapcrumbs);
1.478     raeburn   786:             if (($env{'request.noversionuri'} ne '/adm/navmaps') && ($mapurl ne '') &&
                    787:                 (!(($crstype eq 'Placement') && !$env{'request.role.adv'}))) {
1.486     raeburn   788:                 unless ($ltiscope eq 'resource') {
                    789:                     if (($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) &&
                    790:                         !(($ltiscope eq 'map') && (&Apache::lonnet::clutter($resurl) eq $ltiuri))) {
                    791:                         $navmap = Apache::lonnavmaps::navmap->new();
                    792:                         if (ref($navmap)) {
                    793:                             @mapcrumbs = $navmap->recursed_crumbs($mapurl,$restitle);
                    794:                         }
                    795:                     }
1.475     raeburn   796:                 }
                    797:             }
1.393     raeburn   798:             unless (($forcereg) &&
                    799:                     ($env{'request.noversionuri'} eq '/adm/navmaps') &&
1.443     raeburn   800:                     ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'}) ||
1.486     raeburn   801:                     (($crstype eq 'Placement') && (!$env{'request.role.adv'})) ||
                    802:                     ($ltiscope eq 'map') || ($ltiscope eq 'resource')) {
1.443     raeburn   803:                 @crumbs = ({text  => $crstype.' Contents', 
1.393     raeburn   804:                             href  => "Javascript:gopost('/adm/navmaps','')"});
                    805:             }
                    806:             if ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) { 
1.475     raeburn   807:                 if (@mapcrumbs) {
                    808:                     push(@crumbs,@mapcrumbs);
1.486     raeburn   809:                 } elsif (!(($crstype eq 'Placement') && (!$env{'request.role.adv'})) &&
                    810:                          ($ltiscope ne 'map') && ($ltiscope ne 'resource')) {
1.475     raeburn   811:                     push(@crumbs, {text  => '...',
                    812:                                    no_mt => 1});
                    813:                 }
1.393     raeburn   814:             }
                    815: 
1.475     raeburn   816:             unless ((($crstype eq 'Placement') && (!$env{'request.role.adv'})) || (@mapcrumbs) ||
                    817:                     (!$maptitle) || ($maptitle eq 'default.sequence') ||
1.486     raeburn   818:                     ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'}) ||
                    819:                     ($ltiscope eq 'resource')) {
                    820:                 push @crumbs, {text => $maptitle, no_mt => 1, 
                    821:                                href => &Apache::lonnet::clutter($mapurl).'?navmap=1'};
1.443     raeburn   822:             }
1.479     raeburn   823:             if ($restitle && !@mapcrumbs) {
                    824:                 push(@crumbs,{text => $restitle, no_mt => 1});
                    825:             }
1.436     raeburn   826:             my @tools;
                    827:             if ($env{'request.filename'} =~ /\.page$/) {
                    828:                 my %breadcrumb_tools = &Apache::lonhtmlcommon::current_breadcrumb_tools();
                    829:                 if (ref($breadcrumb_tools{'tools'}) eq 'ARRAY') {
                    830:                     @tools = @{$breadcrumb_tools{'tools'}};
                    831:                 }
                    832:             }
1.393     raeburn   833:             &Apache::lonhtmlcommon::clear_breadcrumbs();
                    834:             &Apache::lonhtmlcommon::add_breadcrumb(@crumbs);
1.436     raeburn   835:             if (@tools) {
                    836:                 &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',@tools);
                    837:             }
1.393     raeburn   838:         } else {
                    839:             $resurl = $env{'request.noversionuri'};
                    840:             my $courseurl = &Apache::lonnet::courseid_to_courseurl($env{'request.course.id'});
                    841:             my $title = &mt('View Resource');
                    842:             if ($resurl =~ m{^\Q/uploaded$courseurl/supplemental/\E(default|\d+)/}) {
                    843:                 &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folderpath','title']);
1.392     raeburn   844:                 &Apache::lonhtmlcommon::clear_breadcrumbs();
1.393     raeburn   845:                 if ($env{'form.title'}) {
                    846:                     $title = $env{'form.title'};
                    847:                 }
1.394     raeburn   848:                 my $trail;
1.393     raeburn   849:                 if ($env{'form.folderpath'}) {
1.468     raeburn   850:                     &prepare_functions($resurl,$forcereg,$group,undef,undef,1,$hostname);
1.394     raeburn   851:                     ($trail) =
1.393     raeburn   852:                         &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
                    853:                 } else {
                    854:                     &Apache::lonhtmlcommon::add_breadcrumb(
1.392     raeburn   855:                     {text  => "Supplemental $crstype Content",
                    856:                      href  => "javascript:gopost('/adm/supplemental','')"});
1.393     raeburn   857:                     $title = &mt('View Resource');
1.394     raeburn   858:                     ($trail) = 
                    859:                         &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
1.392     raeburn   860:                 }
1.394     raeburn   861:                 return $trail;
1.412     raeburn   862:             } elsif ($resurl =~ m{^\Q/uploaded$courseurl/portfolio/syllabus/}) {
                    863:                 &Apache::lonhtmlcommon::clear_breadcrumbs();
                    864:                 &prepare_functions('/public'.$courseurl."/syllabus",
1.468     raeburn   865:                                    $forcereg,$group,undef,undef,1,$hostname);
1.412     raeburn   866:                 $title = &mt('Syllabus File');
                    867:                 my ($trail) =
1.468     raeburn   868:                     &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1,$hostname);
1.412     raeburn   869:                 return $trail;
1.392     raeburn   870:             }
1.395     raeburn   871:             unless ($env{'request.state'} eq 'construct') {
                    872:                 &Apache::lonhtmlcommon::clear_breadcrumbs();
                    873:                 &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
                    874:             }
1.392     raeburn   875:         }
1.390     raeburn   876:     } elsif (! $const_space){
1.328     droeschl  877:         #a situation when we're looking at a resource outside of context of a 
                    878:         #course or construction space (e.g. with cumulative rights)
                    879:         &Apache::lonhtmlcommon::clear_breadcrumbs();
1.390     raeburn   880:         unless ($env{'request.noversionuri'} =~ m{^/adm/$match_domain/$match_username/aboutme$}) {
                    881:             &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
                    882:         }
1.65      www       883:     }
1.41      www       884: # =============================================================================
                    885: # ============================ This is for URLs that actually can be registered
1.316     droeschl  886:     return '' unless ( ($env{'request.noversionuri'}!~m{^/(res/)*adm/}) 
                    887:                        || $forcereg );
1.390     raeburn   888:     my ($cdom,$cnum,%perms,$cfile,$switchserver,$home,$forceedit,
                    889:         $forceview,$editbutton);
1.391     raeburn   890:     if (($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) ||
                    891:         ($env{'request.role'} !~/^(aa|ca|au)/)) {
1.468     raeburn   892:         $editbutton = &prepare_functions($resurl,$forcereg,$group,'','','',$hostname);
1.390     raeburn   893:     }
                    894:     if ($editbutton eq '') {
1.399     raeburn   895:         $editbutton = &clear(6,1);
1.390     raeburn   896:     }
1.317     droeschl  897: 
1.390     raeburn   898: #
                    899: # This applies in course context
                    900: #
                    901:     if ($env{'request.course.id'}) {
                    902:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                    903:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                    904:         $perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
1.462     raeburn   905:         $perms{'cev'} = &Apache::lonnet::allowed('cev',$env{'request.course.id'});
1.390     raeburn   906:         my @privs;
1.484     raeburn   907:         my $gradable_exttool;
1.390     raeburn   908:         if ($env{'request.symb'} ne '') {
1.484     raeburn   909:              if ($env{'request.noversionuri'} =~ m{^/adm/$cdom/$cnum/(\d+)/ext\.tool$}) {
                    910:                  if (&Apache::lonnet::EXT('resource.0.gradable') =~ /^yes$/i) {
                    911:                      $gradable_exttool = 1;
                    912:                      push(@privs,('mgr','vgr'));
                    913:                  }
                    914:              } elsif ($env{'request.filename'}=~/$LONCAPA::assess_re/) {
1.390     raeburn   915:                  push(@privs,('mgr','vgr'));
                    916:              }
1.455     raeburn   917:              push(@privs,('opa','vpa'));
1.390     raeburn   918:         }
                    919:         foreach my $priv (@privs) {
                    920:             $perms{$priv} = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
                    921:             if (!$perms{$priv} && $env{'request.course.sec'} ne '') {
                    922:                 $perms{$priv} = 
                    923:                     &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
                    924:             }
                    925:         }
                    926: #
                    927: # Determine whether or not to show Grades and Submissions buttons
                    928: #
1.484     raeburn   929:         if (($env{'request.symb'} ne '') &&
                    930:             (($env{'request.filename'}=~/$LONCAPA::assess_re/) || ($gradable_exttool))) {
1.390     raeburn   931:             if ($perms{'mgr'}) {
                    932:                 &switch('','',7,2,'pgrd.png','Content Grades','grades[_4]',
                    933:                         "gocmd('/adm/grades','gradingmenu')",
                    934:                         'Content Grades');
                    935:             } elsif ($perms{'vgr'}) {
                    936:                 &switch('','',7,2,'subm.png','Content Submissions','missions[_1]',
                    937:                         "gocmd('/adm/grades','submission')",
                    938:                         'Content Submissions');
                    939:              }
                    940:         }
1.455     raeburn   941:         if (($env{'request.symb'} ne '') && (($perms{'opa'}) || ($perms{'vpa'}))) {
1.390     raeburn   942:             &switch('','',7,3,'pparm.png','Content Settings','parms[_2]',
                    943:                     "gocmd('/adm/parmset','set')",
                    944:                     'Content Settings');
1.107     albertel  945: 	}
1.393     raeburn   946: # End grades/submissions check
1.107     albertel  947: 
1.274     www       948: #
1.393     raeburn   949: # This applies to items inside a folder/page modifiable in the course.
1.274     www       950: #
1.462     raeburn   951:         if (($env{'request.symb'}=~/^uploaded/) && (($perms{'mdc'}) || ($perms{'cev'}))) {
1.393     raeburn   952:             my $text = 'Edit Folder';
1.395     raeburn   953:             if (($mapurl =~ /\.page$/) ||
                    954:                 ($env{'request.symb'}=~
1.396     raeburn   955:                      m{uploaded/$cdom/$cnum/default_\d+\.page$}))  {
1.393     raeburn   956:                 $text = 'Edit Page';
                    957:             }
                    958:             &switch('','',7,4,'docs-22x22.png',$text,'parms[_2]',
1.390     raeburn   959:                     "gocmd('/adm/coursedocs','direct')",
                    960:                     'Folder/Page Content');
1.258     raeburn   961:         }
1.390     raeburn   962: # End modifiable folder/page container check
                    963:     }
                    964: # End course context
                    965: 
1.41      www       966: # Prepare the rest of the buttons
1.383     raeburn   967:         my ($menuitems,$got_prt,$got_wishlist);
1.120     raeburn   968:         if ($const_space) {
1.274     www       969: #
                    970: # We are in construction space
                    971: #
1.353     www       972: 
1.355     raeburn   973:             my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.353     www       974: 	    my ($udom,$uname,$thisdisfn) =
1.355     raeburn   975: 		($env{'request.filename'}=~m{^\Q$londocroot/priv/\E([^/]+)/([^/]+)/(.*)$});
1.353     www       976:             my $currdir = '/priv/'.$udom.'/'.$uname.'/'.$thisdisfn;
1.131     raeburn   977:             if ($currdir =~ m-/$-) {
                    978:                 $is_const_dir = 1;
1.433     raeburn   979:                 if ($thisdisfn eq '') {
1.451     raeburn   980:                     unless (($env{'request.course.id'}) && 
                    981:                             ($env{'course.'.$env{'request.course.id'}.'.num'} eq $uname) &&
                    982:                             ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $udom)) { 
                    983:                         $is_const_dir = 2;
                    984:                     }
1.433     raeburn   985:                 }
1.131     raeburn   986:             } else {
1.267     droeschl  987:                 $currdir =~ s|[^/]+$||;
1.200     foxr      988: 		my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn);
1.208     albertel  989: 		my $esc_currdir = &Apache::loncommon::escape_single($currdir);
1.274     www       990: #
                    991: # Probably should be in mydesk.tab
                    992: #
1.131     raeburn   993:                 $menuitems=(<<ENDMENUITEMS);
1.344     www       994: s&6&1&list.png&Directory&dir[_1]&golist('$esc_currdir')&List current directory
1.353     www       995: s&6&2&rtrv.png&Retrieve&version[_1]&gocstr('/adm/retrieve','/priv/$udom/$uname/$cleandisfn')&Retrieve old version
                    996: s&6&3&pub.png&Publish&resource[_3]&gocstr('/adm/publish','/priv/$udom/$uname/$cleandisfn')&Publish this resource
                    997: s&7&1&del.png&Delete&resource[_2]&gocstr('/adm/cfile?action=delete','/priv/$udom/$uname/$cleandisfn')&Delete this resource
                    998: s&7&2&prt.png&Print&printout[_1]&gocstr('/adm/printout','/priv/$udom/$uname/$cleandisfn')&Prepare a printable document
1.120     raeburn   999: ENDMENUITEMS
1.131     raeburn  1000:             }
1.308     raeburn  1001:                 if (ref($bread_crumbs) eq 'ARRAY') {
                   1002:                     &Apache::lonhtmlcommon::clear_breadcrumbs();
                   1003:                     foreach my $crumb (@{$bread_crumbs}){
                   1004:                         &Apache::lonhtmlcommon::add_breadcrumb($crumb);
                   1005:                     }
                   1006:                 }
1.203     foxr     1007:         } elsif ( defined($env{'request.course.id'}) && 
                   1008: 		 $env{'request.symb'} ne '' ) {
1.274     www      1009: #
1.383     raeburn  1010: # We are in a course and looking at a registered URL
1.274     www      1011: # Should probably be in mydesk.tab
                   1012: #
1.443     raeburn  1013:             $menuitems = "c&3&1";
1.486     raeburn  1014:             if ($ltiscope eq 'resource') {
                   1015: # Suppress display of backward arrow for LTI Provider if scope is resource.
                   1016: # Suppress display of forward arrow for LTI Provider if scope is resource.
                   1017:             } elsif ($ltiscope eq 'map') {
                   1018: # Suppress display of backward arrow for LTI Provider if scope is map and this is first resource.
                   1019: # Suppress display of forward arrow for LTI Provider if scope is map and this is the last resource.
                   1020:                 my $showforw = 1;
                   1021:                 my $showback = 1;
                   1022:                 my $navmap = Apache::lonnavmaps::navmap->new();
                   1023:                 if (ref($navmap)) {
                   1024:                     my $mapres = $navmap->getResourceByUrl($ltiuri);
                   1025:                     if (ref($mapres)) {
                   1026:                         if ($navmap->isLastResource($mapres,$env{'request.symb'})) {
                   1027:                             $showforw = 0;
                   1028:                         }
                   1029:                         if ($navmap->isFirstResource($mapres,$env{'request.symb'})) {
                   1030:                             $showback = 0;
                   1031:                         }
                   1032:                     }
                   1033:                 }
                   1034:                 if ($showback) {
                   1035:                     $menuitems.="
                   1036: s&2&1&back.png&&&gopost('/adm/flip','back:'+currentURL)&Previous content resource&&1";
                   1037:                 }
                   1038:                 if ($showforw) {
                   1039:                     $menuitems.="
                   1040: s&2&3&forw.png&&&gopost('/adm/flip','forward:'+currentURL)&Next content resource&&3";
                   1041:                 }
                   1042:             } elsif (($crstype ne 'Placement') || ($env{'request.role.adv'})) {
1.443     raeburn  1043:                 $menuitems.="
1.444     raeburn  1044: s&2&1&back.png&&&gopost('/adm/flip','back:'+currentURL)&Previous content resource&&1
                   1045: s&2&3&forw.png&&&gopost('/adm/flip','forward:'+currentURL)&Next content resource&&3";
                   1046:             } else {
                   1047: # Suppress display of backward arrow for Placement Tests
                   1048: # Suppress display of forward arrow for Placement Tests if this is the last resource.
                   1049:                 my $showforw = 1;
                   1050:                 if ($env{'request.symb'}) {
                   1051:                     my $navmap = Apache::lonnavmaps::navmap->new();
                   1052:                     if (ref($navmap)) {
                   1053:                         if (&Apache::lonplacementtest::is_lastres($env{'request.symb'},$navmap)) {
                   1054:                             $showforw = 0;
                   1055:                         }
                   1056:                     }
                   1057:                 }
                   1058:                 if ($showforw) {
                   1059:                     $menuitems.="
                   1060: s&2&3&forw.png&&&gopost('/adm/flip','forward:'+currentURL)&Next content resource&&3";
                   1061:                 }
1.443     raeburn  1062:             }
                   1063: 	    $menuitems .= (<<ENDMENUITEMS);
                   1064: 
1.77      www      1065: c&6&3
                   1066: c&8&1
                   1067: c&8&2
1.344     www      1068: s&8&3&prt.png&Print&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
1.41      www      1069: ENDMENUITEMS
1.383     raeburn  1070:             $got_prt = 1;
                   1071:             if (($env{'user.adv'}) && ($env{'request.uri'} =~ /^\/res/)
                   1072:                 && (!$env{'request.enc'})) {
1.452     raeburn  1073:                 my ($cnum,$cdom) = &Apache::loncommon::crsauthor_url($env{'request.uri'});
                   1074:                 unless ($cnum) {
                   1075:                     # wishlist is only available for users with access to resource-pool
                   1076:                     # and links can only be set for resources within the resource-pool
                   1077:                     $menuitems .= (<<ENDMENUITEMS);
1.431     golterma 1078: 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 1079: ENDMENUITEMS
1.452     raeburn  1080:                     $got_wishlist = 1;
                   1081:                 }
1.332     wenzelju 1082:             }
1.216     albertel 1083: 
1.243     tempelho 1084: my $currentURL = &Apache::loncommon::get_symb();
                   1085: my ($symb_old,$symb_old_enc) = &Apache::loncommon::clean_symb($currentURL);
                   1086: my $annotation = &Apache::loncommon::get_annotation($symb_old,$symb_old_enc);
                   1087: $menuitems.="s&9&3&";
                   1088: if(length($annotation) > 0){
1.317     droeschl 1089: 	$menuitems.="anot2.png";
1.243     tempelho 1090: }else{
1.317     droeschl 1091: 	$menuitems.="anot.png";
1.243     tempelho 1092: }
1.344     www      1093: $menuitems.="&Notes&&annotate()&";
1.243     tempelho 1094: $menuitems.="Make notes and annotations about this resource&&1\n";
1.428     raeburn  1095: my $is_mobile;
                   1096: if ($env{'browser.mobile'}) {
                   1097:     $is_mobile = 1;
                   1098: }
1.243     tempelho 1099: 
1.484     raeburn  1100:             unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|viewclasslist|portfolio)(\?|$)/) {
                   1101: 		if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/}) && ($env{'request.noversionuri'} !~ m{^/uploaded/$match_domain/$match_courseid/docs/}) && ($env{'request.noversionuri'} !~ m{^/adm/.+/ext\.tool$})) {
1.216     albertel 1102: 		    $menuitems.=(<<ENDREALRES);
1.496     raeburn  1103: s&6&3&catalog.png&Info&info[_1]&catalog_info(currentURL,'$is_mobile')&Show Metadata
1.216     albertel 1104: ENDREALRES
                   1105:                 }
1.422     raeburn  1106:                 unless (($env{'request.noversionuri'} =~ m{^/uploaded/$match_domain/$match_courseid/docs/}) ||
1.484     raeburn  1107:                         ($env{'request.noversionuri'} =~ m{^\Q/adm/wrapper/\E(ext|uploaded)/}) ||
                   1108:                         ($env{'request.noversionuri'} =~ m{^/adm/.+/ext\.tool$})) {
1.382     raeburn  1109:                     $menuitems.=(<<ENDREALRES);
1.344     www      1110: s&8&1&eval.png&Evaluate&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
1.382     raeburn  1111: ENDREALRES
                   1112:                 }
1.422     raeburn  1113:                 unless ($env{'request.noversionuri'} =~ m{^\Q/adm/wrapper/\E(ext|uploaded)/}) {
                   1114:                     $menuitems.=(<<ENDREALRES);
1.344     www      1115: 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      1116: ENDREALRES
1.422     raeburn  1117:                 }
1.120     raeburn  1118: 	    }
                   1119:         }
1.203     foxr     1120: 	if ($env{'request.uri'} =~ /^\/res/) {
1.383     raeburn  1121:             unless ($got_prt) {
                   1122: 	        $menuitems .= (<<ENDMENUITEMS);
1.344     www      1123: s&8&3&prt.png&Print&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
1.203     foxr     1124: ENDMENUITEMS
1.384     raeburn  1125:                 $got_prt = 1;
1.383     raeburn  1126:             }
                   1127:             unless ($got_wishlist) {
                   1128:                 if (($env{'user.adv'}) && (!$env{'request.enc'})) {
                   1129:                     # wishlist is only available for users with access to resource-pool
                   1130:                     $menuitems .= (<<ENDMENUITEMS);
1.431     golterma 1131: 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 1132: ENDMENUITEMS
1.383     raeburn  1133:                     $got_wishlist = 1;
                   1134:                 }
                   1135: 	    }
                   1136:         }
1.41      www      1137:         my $buttons='';
                   1138:         foreach (split(/\n/,$menuitems)) {
                   1139: 	    my ($command,@rest)=split(/\&/,$_);
1.220     raeburn  1140:             my $idx=10*$rest[0]+$rest[1];
                   1141:             if (&hidden_button_check() eq 'yes') {
                   1142:                 if ($idx == 21 ||$idx == 23) {
                   1143:                     $buttons.=&switch('','',@rest);
                   1144:                 } else {
                   1145:                     $buttons.=&clear(@rest);
                   1146:                 }
                   1147:             } else {  
                   1148:                 if ($command eq 's') {
                   1149: 	            $buttons.=&switch('','',@rest);
                   1150:                 } else {
                   1151:                     $buttons.=&clear(@rest);
                   1152:                 }
1.41      www      1153:             }
                   1154:         }
1.445     raeburn  1155:         my $showprogress;
                   1156:         if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) {
                   1157:             $showprogress = &placement_progress();
                   1158:         }
                   1159: 
                   1160: 	my $addremote=0;
                   1161: 	foreach (@inlineremote) { if ($_ ne '') { $addremote=1; last;} }
1.148     albertel 1162: 
1.301     droeschl 1163:     if ($addremote) {
1.458     raeburn  1164:         my ($countdown,$buttonshide);
1.436     raeburn  1165:         if ($env{'request.filename'} =~ /\.page$/) {
                   1166:             my %breadcrumb_tools = &Apache::lonhtmlcommon::current_breadcrumb_tools();
                   1167:             if (ref($breadcrumb_tools{'tools'}) eq 'ARRAY') {
1.458     raeburn  1168:                 $countdown = $breadcrumb_tools{'tools'}->[0];
1.436     raeburn  1169:             }
1.458     raeburn  1170:             $buttonshide = $pagebuttonshide;
1.436     raeburn  1171:         } else {
                   1172:             $countdown = &countdown_timer();
1.458     raeburn  1173:             $buttonshide = &hidden_button_check();
1.436     raeburn  1174:         }
1.342     www      1175:         &Apache::lonhtmlcommon::clear_breadcrumb_tools();
1.301     droeschl 1176: 
1.342     www      1177:             &Apache::lonhtmlcommon::add_breadcrumb_tool(
1.312     droeschl 1178:                 'navigation', @inlineremote[21,23]);
                   1179: 
1.458     raeburn  1180:         if ($buttonshide eq 'yes') {
1.378     raeburn  1181:             if ($countdown) {
                   1182:                 &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$countdown);
                   1183:             }
1.445     raeburn  1184:             if ($showprogress) {
                   1185:                 &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$showprogress);
                   1186:             }
1.378     raeburn  1187:         } else {
                   1188:             my @tools = @inlineremote[93,91,81,82,83];
                   1189:             if ($countdown) {
                   1190:                 unshift(@tools,$countdown);
                   1191:             }
1.342     www      1192:             &Apache::lonhtmlcommon::add_breadcrumb_tool(
1.378     raeburn  1193:                 'tools',@tools);
1.313     droeschl 1194: 
                   1195:             #publish button in construction space
                   1196:             if ($env{'request.state'} eq 'construct'){
1.342     www      1197:                 &Apache::lonhtmlcommon::add_breadcrumb_tool(
1.349     raeburn  1198:                      'advtools', $inlineremote[63]);
1.342     www      1199:             } else {
                   1200:                 &Apache::lonhtmlcommon::add_breadcrumb_tool(
1.349     raeburn  1201:                      'tools', $inlineremote[63]);
1.313     droeschl 1202:             }
1.390     raeburn  1203:             &advtools_crumbs(@inlineremote);
1.301     droeschl 1204:         }
1.445     raeburn  1205:     } else {
                   1206:         if ($showprogress) {
                   1207:             &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$showprogress);
                   1208:         }
1.38      www      1209:     }
1.433     raeburn  1210:     my ($topic_help,$topic_help_text);
                   1211:     if ($is_const_dir == 2) {
1.434     raeburn  1212:         if ((($ENV{'SERVER_PORT'} == 443) || 
                   1213:              ($Apache::lonnet::protocol{$Apache::lonnet::perlvar{'lonHostID'}} eq 'https')) && 
                   1214:             (&Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},'webdav'))) {
1.433     raeburn  1215:             $topic_help = 'Authoring_WebDAV,Authoring_WebDAV_Mac_10v6,Authoring_WebDAV_Mac_10v10,'.
                   1216:                           'Authoring_WebDAV_Windows_v7,Authoring_WebDAV_Linux_Centos';
                   1217:             $topic_help_text = 'About WebDAV access';
                   1218:         }
                   1219:     }
1.342     www      1220:     return   &Apache::lonhtmlcommon::scripttag('', 'start')
1.433     raeburn  1221:            . &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0,'','','','',$topic_help,$topic_help_text)
1.342     www      1222:            . &Apache::lonhtmlcommon::scripttag('', 'end');
1.38      www      1223: }
                   1224: 
1.389     raeburn  1225: sub get_editbutton {
1.468     raeburn  1226:     my ($cfile,$home,$switchserver,$forceedit,$forceview,$forcereg,$hostname) = @_;
1.398     raeburn  1227:     my $jscall;
                   1228:     if (($forceview) && ($env{'form.todocs'})) {
1.463     raeburn  1229:         my ($folderpath,$command,$navmap);
1.398     raeburn  1230:         if ($env{'request.symb'}) {
1.463     raeburn  1231:             $folderpath = &Apache::loncommon::symb_to_docspath($env{'request.symb'},\$navmap);
1.398     raeburn  1232:         } elsif ($env{'form.folderpath'} =~ /^supplemental/) {
                   1233:             $folderpath = $env{'form.folderpath'};
                   1234:             $command = '&forcesupplement=1';
                   1235:         }
                   1236:         $folderpath = &escape(&HTML::Entities::encode(&escape($folderpath),'<>&"'));
                   1237:         $jscall = "go('/adm/coursedocs?folderpath=$folderpath$command')";
                   1238:     } else {
1.459     raeburn  1239:         my $suppanchor;
                   1240:         if ($env{'form.folderpath'}) {
                   1241:             $suppanchor = $env{'form.anchor'};
                   1242:         }
1.398     raeburn  1243:         $jscall = &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,$switchserver,
1.393     raeburn  1244:                                                 $forceedit,$forcereg,$env{'request.symb'},
                   1245:                                                 &escape($env{'form.folderpath'}),
1.468     raeburn  1246:                                                 &escape($env{'form.title'}),$hostname,
                   1247:                                                 $env{'form.idx'},&escape($env{'form.suppurl'}),
                   1248:                                                 $env{'form.todocs'},$suppanchor);
1.398     raeburn  1249:     }
1.389     raeburn  1250:     if ($jscall) {
1.390     raeburn  1251:         my $icon = 'pcstr.png';
                   1252:         my $label = 'Edit';
                   1253:         if ($forceview) {
                   1254:             $icon = 'tolastloc.png';
                   1255:             $label = 'Exit Editing';
                   1256:         }
                   1257:         &switch('','',6,1,$icon,$label,'resource[_2]',
                   1258:                 $jscall,"Edit this resource");
                   1259:         return 1;
                   1260:     }
                   1261:     return;
                   1262: }
                   1263: 
                   1264: sub prepare_functions {
1.468     raeburn  1265:     my ($resurl,$forcereg,$group,$bread_crumbs,$advtools,$docscrumbs,$hostname) = @_;
1.390     raeburn  1266:     unless ($env{'request.registered'}) {
                   1267:         undef(@inlineremote);
                   1268:     }
                   1269:     my ($cdom,$cnum,%perms,$cfile,$switchserver,$home,$forceedit,
                   1270:         $forceview);
                   1271: 
                   1272:     if ($env{'request.course.id'}) {
                   1273:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                   1274:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   1275:         $perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
                   1276:     }
                   1277: 
                   1278:     my $editbutton = '';
1.480     raeburn  1279:     my $viewsrcbutton = '';
1.390     raeburn  1280: #
1.480     raeburn  1281: # Determine whether or not to display 'Edit' or 'View Source' icon/button
1.390     raeburn  1282: #
                   1283:     if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
                   1284:         my $file=&Apache::lonnet::declutter($env{'request.filename'});
1.391     raeburn  1285:         ($cfile,$home,$switchserver,$forceedit,$forceview) =
                   1286:             &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
                   1287:                 &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
                   1288:         if (($cfile) && ($home ne '') && ($home ne 'no_host')) {
                   1289:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
1.390     raeburn  1290:                                           $forceedit,$forceview,$forcereg);
                   1291:         }
1.391     raeburn  1292:     } elsif ((!$env{'request.course.id'}) &&
1.390     raeburn  1293:              ($env{'user.author'}) && ($env{'request.filename'}) &&
                   1294:              ($env{'request.role'} !~/^(aa|ca|au)/)) {
                   1295: #
                   1296: # Currently do not have the role of author or co-author.
                   1297: # Do we have authoring privileges for the resource?
                   1298: #
                   1299:         my $file=&Apache::lonnet::declutter($env{'request.filename'});
                   1300:         ($cfile,$home,$switchserver,$forceedit,$forceview) =
                   1301:             &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
                   1302:                 &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
                   1303:         if (($cfile) && ($home ne '') && ($home ne 'no_host')) {
                   1304:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
                   1305:                                           $forceedit,$forceview,$forcereg);
                   1306:         }
                   1307:     } elsif ($env{'request.course.id'}) {
                   1308: #
                   1309: # This applies in course context
                   1310: #
1.412     raeburn  1311:         if (($perms{'mdc'}) &&
1.469     raeburn  1312:             (($resurl =~ m{^/?public/$cdom/$cnum/syllabus}) ||
1.477     raeburn  1313:              ($resurl =~ m{^/?uploaded/$cdom/$cnum/portfolio/syllabus/}) ||
                   1314:              (($resurl =~ m{^/?uploaded/$cdom/$cnum/default_\d+\.sequence$}) && ($env{'form.navmap'})))) {
1.470     raeburn  1315:             if ($resurl =~ m{^/}) {
                   1316:                 $cfile = $resurl;
                   1317:             } else {
                   1318:                 $cfile = "/$resurl";
                   1319:             }
1.411     raeburn  1320:             $home = &Apache::lonnet::homeserver($cnum,$cdom);
                   1321:             if ($env{'form.forceedit'}) {
                   1322:                 $forceview = 1;
1.390     raeburn  1323:             } else {
1.411     raeburn  1324:                 $forceedit = 1;
1.390     raeburn  1325:             }
1.477     raeburn  1326:             if ($cfile =~ m{^/uploaded/$cdom/$cnum/default_\d+\.sequence$}) {
                   1327:                 my $text = 'Edit Folder';
                   1328:                 &switch('','',7,4,'docs-22x22.png','Edit Folder','parms[_2]',
                   1329:                         "gocmd('/adm/coursedocs','direct')",
                   1330:                         'Folder/Page Content');
                   1331:                 $editbutton = 1;
                   1332:             } else {
                   1333:                 $editbutton = &get_editbutton($cfile,$home,$switchserver,
                   1334:                                               $forceedit,$forceview,$forcereg,
                   1335:                                               $hostname);
                   1336:             }
1.393     raeburn  1337:         } elsif (($resurl eq '/adm/extresedit') &&
                   1338:                  (($env{'form.symb'}) || ($env{'form.folderpath'}))) {
                   1339:             ($cfile,$home,$switchserver,$forceedit,$forceview) =
                   1340:             &Apache::lonnet::can_edit_resource($resurl,$cnum,$cdom,$resurl,
                   1341:                                                $env{'form.symb'});
                   1342:             if ($cfile ne '') {
                   1343:                 $editbutton = &get_editbutton($cfile,$home,$switchserver,
1.468     raeburn  1344:                                               $forceedit,$forceview,$forcereg);
1.393     raeburn  1345:             }
1.406     raeburn  1346:         } elsif (($resurl =~ m{^/?adm/viewclasslist$}) &&
                   1347:                  (&Apache::lonnet::allowed('opa',$env{'request.course.id'}))) {
                   1348:             ($cfile,$home,$switchserver,$forceedit,$forceview) =
                   1349:             &Apache::lonnet::can_edit_resource($resurl,$cnum,$cdom,$resurl,
                   1350:                                                $env{'form.symb'});
                   1351:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
                   1352:                                           $forceedit,$forceview,$forcereg);
1.405     raeburn  1353:         } elsif (($resurl !~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) &&
                   1354:                  ($resurl ne '/cgi-bin/printout.pl')) {
1.390     raeburn  1355:             if ($env{'request.filename'}) {
                   1356:                 my $file=&Apache::lonnet::declutter($env{'request.filename'});
                   1357:                 ($cfile,$home,$switchserver,$forceedit,$forceview) =
                   1358:                     &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
                   1359:                         &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
                   1360:                 if ($cfile ne '') {
                   1361:                     $editbutton = &get_editbutton($cfile,$home,$switchserver,
1.468     raeburn  1362:                                                   $forceedit,$forceview,$forcereg,
                   1363:                                                   $hostname);
1.390     raeburn  1364:                 }
1.480     raeburn  1365:                 if ((($cfile eq '') || (!$editbutton)) &&
                   1366:                     ($resurl =~ /$LONCAPA::assess_re/)) {
                   1367:                     my $showurl = &Apache::lonnet::clutter($resurl);
                   1368:                     if ((&Apache::lonnet::allowed('cre','/')) &&
                   1369:                         (&Apache::lonnet::metadata($resurl,'sourceavail') eq 'open')) {
                   1370:                         $viewsrcbutton = 1;
                   1371:                     } elsif (&Apache::lonnet::allowed('vxc',$env{'request.course.id'})) {
                   1372:                         if ($showurl =~ m{^\Q/res/$cdom/\E($match_username)/}) {
                   1373:                             my $auname = $1;
                   1374:                             if (($env{'request.course.adhocsrcaccess'} ne '') &&
                   1375:                                 (grep(/^\Q$auname\E$/,split(/,/,$env{'request.course.adhocsrcaccess'})))) {
                   1376:                                 $viewsrcbutton = 1;
1.481     raeburn  1377:                             } elsif ((&Apache::lonnet::metadata($resurl,'sourceavail') eq 'open') &&
                   1378:                                      (&Apache::lonnet::allowed('bre','/'))) {
                   1379:                                 $viewsrcbutton = 1;
1.480     raeburn  1380:                             }
                   1381:                         }
                   1382:                     }
                   1383:                     if ($viewsrcbutton) {
                   1384:                         &switch('','',6,1,'pcstr.png','View Source','resource[_2]','open_source()',
                   1385:                                 'View source code');
                   1386:                     }
                   1387:                 }
1.390     raeburn  1388:             }
                   1389:         }
                   1390:     }
                   1391: # End determination of 'Edit' icon/button display
                   1392: 
1.393     raeburn  1393:     if ($env{'request.course.id'}) {
1.390     raeburn  1394: # This applies to about me page for users in a course
1.391     raeburn  1395:         if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
1.390     raeburn  1396:             my ($sdom,$sname) = ($1,$2);
                   1397:             unless (&Apache::lonnet::is_course($sdom,$sname)) {
                   1398:                 &switch('','',6,4,'mail-message-new-22x22.png','Message to user',
                   1399:                         '',
1.415     raeburn  1400:                         "go('/adm/email?compose=individual&amp;recname=$sname&amp;recdom=$sdom')",
1.390     raeburn  1401:                             'Send message to specific user');
                   1402:             }
1.391     raeburn  1403:             my $hideprivileged = 1;
                   1404:             if (&Apache::lonnet::in_course($sdom,$sname,$cdom,$cnum,undef,
                   1405:                                            $hideprivileged)) {
1.390     raeburn  1406:                 foreach my $priv ('vsa','vgr','srm') {
                   1407:                     $perms{$priv} = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
                   1408:                     if (!$perms{$priv} && $env{'request.course.sec'} ne '') {
                   1409:                         $perms{$priv} =
                   1410:                             &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
                   1411:                     }
                   1412:                 }
                   1413:                 if ($perms{'vsa'}) {
                   1414:                     &switch('','',6,5,'trck-22x22.png','Activity',
                   1415:                             '',
                   1416:                             "go('/adm/trackstudent?selected_student=$sname:$sdom')",
                   1417:                             'View recent activity by this person');
                   1418:                 }
                   1419:                 if ($perms{'vgr'}) {
                   1420:                     &switch('','',6,6,'rsrv-22x22.png','Reservations',
                   1421:                             '',
1.415     raeburn  1422:                             "go('/adm/slotrequest?command=showresv&amp;origin=aboutme&amp;uname=$sname&amp;udom=$sdom')",
1.390     raeburn  1423:                             'Slot reservation history');
                   1424:                 }
                   1425:                 if ($perms{'srm'}) {
                   1426:                     &switch('','',6,7,'contact-new-22x22.png','Records',
                   1427:                             '',
1.415     raeburn  1428:                             "go('/adm/email?recordftf=retrieve&amp;recname=$sname&amp;recdom=$sdom')",
1.390     raeburn  1429:                             'Add records');
                   1430:                 }
                   1431:             }
1.393     raeburn  1432:         }
                   1433:         if (($env{'form.folderpath'} =~ /^supplemental/) &&
                   1434:             (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) &&
                   1435:             (($resurl =~ m{^/adm/wrapper/ext/}) ||
1.472     raeburn  1436:              ($resurl =~ m{^/adm/$cdom/$cnum/\d+/ext\.tool$}) ||
1.393     raeburn  1437:              ($resurl =~ m{^/uploaded/$cdom/$cnum/supplemental/}) ||
1.397     raeburn  1438:              ($resurl eq '/adm/supplemental') ||
                   1439:              ($resurl =~ m{^/public/$cdom/$cnum/syllabus$}) ||
                   1440:              ($resurl =~ m{^/adm/$match_domain/$match_username/aboutme$}))) {
1.393     raeburn  1441:             my @folders=split('&',$env{'form.folderpath'});
1.394     raeburn  1442:             if ((@folders > 2) || ($resurl ne '/adm/supplemental')) {
1.459     raeburn  1443:                 my $suppanchor;
                   1444:                 if ($resurl =~ m{^/adm/wrapper/ext/}) {
                   1445:                     $suppanchor = $env{'form.anchor'};
                   1446:                 }
1.393     raeburn  1447:                 my $esc_path=&escape(&HTML::Entities::encode(&escape($env{'form.folderpath'}),'<>&"'));
1.468     raeburn  1448:                 my $link = '/adm/coursedocs?command=direct&amp;forcesupplement=1&amp;supppath='.
                   1449:                            "$esc_path&amp;anchor=$suppanchor";
                   1450:                 if ($env{'request.use_absolute'} ne '') {
                   1451:                     $link = $env{'request.use_absolute'}.$link;
                   1452:                 }
1.393     raeburn  1453:                 &switch('','',7,4,'docs-22x22.png','Edit Folder','parms[_2]',
1.468     raeburn  1454:                         "location.href='$link'",'Folder/Page Content');
1.393     raeburn  1455:             }
1.390     raeburn  1456:         }
                   1457:     }
                   1458: 
                   1459: # End checking for items for about me page for users in a course
1.393     raeburn  1460:     if ($docscrumbs) {
                   1461:         &Apache::lonhtmlcommon::clear_breadcrumb_tools();
                   1462:         &advtools_crumbs(@inlineremote);
                   1463:         return $editbutton;
                   1464:     } elsif ($env{'request.registered'}) {
1.480     raeburn  1465:         return $editbutton || $viewsrcbutton;
1.390     raeburn  1466:     } else {
                   1467:         if (ref($bread_crumbs) eq 'ARRAY') {
                   1468:             if (@inlineremote > 0) {
                   1469:                 if (ref($advtools) eq 'ARRAY') {
                   1470:                     @{$advtools} = @inlineremote;
                   1471:                 }
                   1472:             }
                   1473:             return;
                   1474:         } elsif (@inlineremote > 0) {
                   1475:             &Apache::lonhtmlcommon::clear_breadcrumb_tools();
                   1476:             &advtools_crumbs(@inlineremote);
                   1477:             return   &Apache::lonhtmlcommon::scripttag('', 'start')
                   1478:                    . &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
                   1479:                    . &Apache::lonhtmlcommon::scripttag('', 'end');
                   1480:         }
                   1481:     }
                   1482: }
                   1483: 
                   1484: sub advtools_crumbs {
                   1485:     my @funcs = @_;
                   1486:     if ($env{'request.noversionuri'} =~ m{^/adm/$match_domain/$match_username/aboutme$}) {
                   1487:         &Apache::lonhtmlcommon::add_breadcrumb_tool(
                   1488:             'advtools', @funcs[61,64,65,66,67,74]);
                   1489:     } elsif ($env{'request.noversionuri'} !~ m{^/adm/(navmaps|viewclasslist)(\?|$)}) {
                   1490:         &Apache::lonhtmlcommon::add_breadcrumb_tool(
                   1491:             'advtools', @funcs[61,71,72,73,74,92]);
1.393     raeburn  1492:     } elsif ($env{'request.noversionuri'} eq '/adm/viewclasslist') {
                   1493:         &Apache::lonhtmlcommon::add_breadcrumb_tool(
1.407     raeburn  1494:             'advtools', $funcs[61]);
1.393     raeburn  1495:     }
1.412     raeburn  1496:     return;
1.258     raeburn  1497: }
                   1498: 
1.2       www      1499: # ================================================================== Raw Config
                   1500: 
1.3       www      1501: sub clear {
                   1502:     my ($row,$col)=@_;
1.316     droeschl 1503:     $inlineremote[10*$row+$col]='';
                   1504:     return ''; 
1.3       www      1505: }
                   1506: 
1.40      www      1507: # ============================================ Switch a button or create a link
1.25      matthew  1508: # Switch acts on the javascript that is executed when a button is clicked.  
                   1509: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
1.40      www      1510: 
1.2       www      1511: sub switch {
1.209     www      1512:     my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak)=@_;
1.2       www      1513:     $act=~s/\$uname/$uname/g;
                   1514:     $act=~s/\$udom/$udom/g;
1.88      www      1515:     $top=&mt($top);
                   1516:     $bot=&mt($bot);
                   1517:     $desc=&mt($desc);
1.209     www      1518:     my $idx=10*$row+$col;
                   1519:     $category_members{$cat}.=':'.$idx;
                   1520: 
1.320     droeschl 1521: # Inline Menu
1.317     droeschl 1522:     if ($nobreak==2) { return ''; }
                   1523:     my $text=$top.' '.$bot;
                   1524:     $text=~s/\s*\-\s*//gs;
1.105     www      1525: 
1.317     droeschl 1526:     my $pic=
1.225     albertel 1527: 	   '<img alt="'.$text.'" src="'.
                   1528: 	   &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
1.303     droeschl 1529: 	   '" align="'.($nobreak==3?'right':'left').'" class="LC_icon" />';
1.317     droeschl 1530:     if ($env{'browser.interface'} eq 'faketextual') {
1.274     www      1531: # Main Menu
1.103     www      1532: 	   if ($nobreak==3) {
1.209     www      1533: 	       $inlineremote[$idx]="\n".
1.177     albertel 1534: 		   '<td class="LC_menubuttons_text" align="right">'.$text.
1.247     harmsja  1535: 		   '</td><td align="left">'.
1.103     www      1536: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
                   1537: 	   } elsif ($nobreak) {
1.209     www      1538: 	       $inlineremote[$idx]="\n<tr>".
1.247     harmsja  1539: 		   '<td align="left">'.
1.177     albertel 1540: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td>
1.215     www      1541:                     <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      1542: 	   } else {
1.209     www      1543: 	       $inlineremote[$idx]="\n<tr>".
1.247     harmsja  1544: 		   '<td align="left">'.
1.103     www      1545: 		   '<a href="javascript:'.$act.';">'.$pic.
1.177     albertel 1546: 		   '</a></td><td class="LC_menubuttons_text" colspan="3">'.
1.215     www      1547: 		   '<a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$desc.'</span></a></td></tr>';
1.103     www      1548: 	   }
1.317     droeschl 1549:     } else {
1.103     www      1550: # Inline Menu
1.378     raeburn  1551:         my @tools = (93,91,81,82,83);
                   1552:         unless ($env{'request.state'} eq 'construct') {
                   1553:             push(@tools,63);
                   1554:         }
1.492     raeburn  1555:         if ((($env{'environment.icons'} eq 'iconsonly') ||
                   1556:              ($env{'environment.icons'} eq '') && ($env{'request.lti.login'})) &&
1.378     raeburn  1557:             (grep(/^$idx$/,@tools))) {
                   1558:             $inlineremote[$idx] =
                   1559:         '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.'</a>';
                   1560:         } else {
                   1561:             $inlineremote[$idx] =
1.317     droeschl 1562:        '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.
1.344     www      1563:        '<span class="LC_menubuttons_inline_text">'.$top.'&nbsp;</span></a>';
1.378     raeburn  1564:         }
1.317     droeschl 1565:     }
1.56      www      1566:     return '';
1.2       www      1567: }
                   1568: 
                   1569: sub secondlevel {
                   1570:     my $output='';
                   1571:     my 
1.209     www      1572:     ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_;
1.2       www      1573:     if ($prt eq 'any') {
1.209     www      1574: 	   $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1575:     } elsif ($prt=~/^r(\w+)/) {
                   1576:         if ($rol eq $1) {
1.209     www      1577:            $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1578:         }
                   1579:     }
                   1580:     return $output;
                   1581: }
                   1582: 
1.56      www      1583: sub inlinemenu {
1.210     albertel 1584:     undef(@inlineremote);
                   1585:     undef(%category_members);
1.275     www      1586: # calling rawconfig with "1" will evaluate mydesk.tab, even if there is no active remote control
1.56      www      1587:     &rawconfig(1);
1.309     bisitz   1588:     my $output='<table><tr>';
1.209     www      1589:     for (my $col=1; $col<=2; $col++) {
1.241     riegler  1590:         $output.='<td class="LC_mainmenu_col_fieldset">';
1.209     www      1591:         for (my $row=1; $row<=8; $row++) {
                   1592:             foreach my $cat (keys(%category_members)) {
                   1593:                if ($category_positions{$cat} ne "$col,$row") { next; }
1.247     harmsja  1594:                #$output.='<table><tr><td colspan="4" class="LC_menubuttons_category">'.&mt($category_names{$cat}).'</td></tr>';
1.309     bisitz   1595:                $output.='<div class="LC_Box LC_400Box">';
                   1596: 	       $output.='<h3 class="LC_hcell">'.&mt($category_names{$cat}).'</h3>';
1.247     harmsja  1597:                $output.='<table>';
1.240     riegler  1598:                my %active=();
                   1599:                foreach my $menu_item (split(/\:/,$category_members{$cat})) {
                   1600:                   if ($inlineremote[$menu_item]) {
                   1601:                      $active{$menu_item}=1;
                   1602:                   }
                   1603:                }  
                   1604:                foreach my $item (sort(keys(%active))) {
                   1605:                   $output.=$inlineremote[$item];
                   1606:                }
                   1607:                $output.='</table>';
1.245     harmsja  1608:                $output.='</div>';
1.240     riegler  1609:             }
                   1610:          }
                   1611:          $output.="</td>";
                   1612:     }
                   1613:     $output.="</tr></table>";
                   1614:     return $output;
                   1615: }
                   1616: 
1.2       www      1617: sub rawconfig {
1.274     www      1618: #
                   1619: # This evaluates mydesk.tab
                   1620: # Need to add more positions and more privileges to deal with all
                   1621: # menu items.
                   1622: #
1.34      www      1623:     my $textualoverride=shift;
                   1624:     my $output='';
1.316     droeschl 1625:     return '' unless $textualoverride;
1.152     albertel 1626:     my $uname=$env{'user.name'};
                   1627:     my $udom=$env{'user.domain'};
                   1628:     my $adv=$env{'user.adv'};
1.266     raeburn  1629:     my $show_course=&Apache::loncommon::show_course();
1.152     albertel 1630:     my $author=$env{'user.author'};
1.5       www      1631:     my $crs='';
1.295     raeburn  1632:     my $crstype='';
1.152     albertel 1633:     if ($env{'request.course.id'}) {
                   1634:        $crs='/'.$env{'request.course.id'};
                   1635:        if ($env{'request.course.sec'}) {
                   1636: 	   $crs.='_'.$env{'request.course.sec'};
1.7       www      1637:        }
1.8       www      1638:        $crs=~s/\_/\//g;
1.295     raeburn  1639:        $crstype = &Apache::loncommon::course_type();
1.5       www      1640:     }
1.152     albertel 1641:     my $pub=($env{'request.state'} eq 'published');
                   1642:     my $con=($env{'request.state'} eq 'construct');
                   1643:     my $rol=$env{'request.role'};
1.427     raeburn  1644:     my $requested_domain;
                   1645:     if ($rol) {
                   1646:        $requested_domain = $env{'request.role.domain'};
                   1647:     }
1.184     raeburn  1648:     foreach my $line (@desklines) {
1.209     www      1649:         my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
1.3       www      1650:         $prt=~s/\$uname/$uname/g;
                   1651:         $prt=~s/\$udom/$udom/g;
1.295     raeburn  1652:         if ($prt =~ /\$crs/) {
                   1653:             next unless ($env{'request.course.id'});
                   1654:             next if ($crstype eq 'Community');
                   1655:             $prt=~s/\$crs/$crs/g;
                   1656:         } elsif ($prt =~ /\$cmty/) {
                   1657:             next unless ($env{'request.course.id'});
                   1658:             next if ($crstype ne 'Community');
                   1659:             $prt=~s/\$cmty/$crs/g;
                   1660:         }
1.427     raeburn  1661:         if ($prt =~ m/\$requested_domain/) {
                   1662:             if ((!$requested_domain) && ($pro eq 'pbre') && ($env{'user.adv'})) {
                   1663:                 $prt=~s/\$requested_domain/$env{'user.domain'}/g;
                   1664:             } else {
                   1665:                 $prt=~s/\$requested_domain/$requested_domain/g;
                   1666:             }
                   1667:         }
1.211     www      1668:         if ($category_names{$cat}!~/\w/) { $cat='oth'; }
1.3       www      1669:         if ($pro eq 'clear') {
1.4       www      1670: 	    $output.=&clear($row,$col);
1.3       www      1671:         } elsif ($pro eq 'any') {
1.2       www      1672:                $output.=&secondlevel(
1.209     www      1673: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1674: 	} elsif ($pro eq 'smp') {
                   1675:             unless ($adv) {
                   1676:                $output.=&secondlevel(
1.209     www      1677:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1678:             }
                   1679:         } elsif ($pro eq 'adv') {
                   1680:             if ($adv) {
                   1681:                $output.=&secondlevel(
1.209     www      1682: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1683:             }
1.231     albertel 1684: 	} elsif ($pro eq 'shc') {
                   1685:             if ($show_course) {
                   1686:                $output.=&secondlevel(
                   1687:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
                   1688:             }
                   1689:         } elsif ($pro eq 'nsc') {
                   1690:             if (!$show_course) {
                   1691:                $output.=&secondlevel(
                   1692: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
                   1693:             }
1.81      matthew  1694:         } elsif (($pro=~/^p(\w+)/) && ($prt)) {
1.295     raeburn  1695:             my $priv = $1;
                   1696:             if ($priv =~ /^mdc(Course|Community)/) {
                   1697:                 if ($crstype eq $1) {
                   1698:                     $priv = 'mdc';
                   1699:                 } else {
                   1700:                     next;
                   1701:                 }
                   1702:             }
1.427     raeburn  1703:             if ((($priv eq 'bre') && (&Apache::lonnet::allowed($priv,$prt) eq 'F')) ||
                   1704:                 (($priv ne 'bre') && (&Apache::lonnet::allowed($priv,$prt)))) {
                   1705:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.4       www      1706:             }
1.295     raeburn  1707:         } elsif ($pro eq 'course')  {
                   1708:             if (($env{'request.course.fn'}) && ($crstype ne 'Community')) {
1.209     www      1709:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.81      matthew  1710: 	    }
1.295     raeburn  1711:         } elsif ($pro eq 'community')  {
                   1712:             if (($env{'request.course.fn'}) && ($crstype eq 'Community')) {
                   1713:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
                   1714:             }
1.124     matthew  1715:         } elsif ($pro =~ /^courseenv_(.*)$/) {
                   1716:             my $key = $1;
1.307     raeburn  1717:             if ($crstype ne 'Community') {
                   1718:                 my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
                   1719:                 if ($key eq 'canuse_pdfforms') {
                   1720:                     if ($env{'request.course.id'} && $coursepref eq '') {
                   1721:                         my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
                   1722:                         $coursepref = $domdefs{'canuse_pdfforms'};
                   1723:                     }
                   1724:                 }
                   1725:                 if ($coursepref) { 
                   1726:                     $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
                   1727:                 }
1.295     raeburn  1728:             }
                   1729:         } elsif ($pro =~ /^communityenv_(.*)$/) {
                   1730:             my $key = $1;
1.307     raeburn  1731:             if ($crstype eq 'Community') {
                   1732:                 my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
                   1733:                 if ($key eq 'canuse_pdfforms') {
                   1734:                     if ($env{'request.course.id'} && $coursepref eq '') {
                   1735:                         my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
                   1736:                         $coursepref = $domdefs{'canuse_pdfforms'};
                   1737:                     }
                   1738:                 }
                   1739:                 if ($coursepref) { 
                   1740:                     $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
                   1741:                 }
1.124     matthew  1742:             }
1.81      matthew  1743:         } elsif ($pro =~ /^course_(.*)$/) {
                   1744:             # Check for permissions inside of a course
1.295     raeburn  1745:             if (($env{'request.course.id'}) && ($crstype ne 'Community') && 
1.152     albertel 1746:                 (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
                   1747:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
1.81      matthew  1748:                  )) {
1.209     www      1749:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.26      www      1750: 	    }
1.295     raeburn  1751:         } elsif ($pro =~ /^community_(.*)$/) {
                   1752:             # Check for permissions inside of a community
                   1753:             if (($env{'request.course.id'}) && ($crstype eq 'Community') &&   
                   1754:                 (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
                   1755:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
                   1756:                  )) {
                   1757:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
                   1758:             }
1.4       www      1759:         } elsif ($pro eq 'author') {
                   1760:             if ($author) {
1.152     albertel 1761:                 if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
1.234     raeburn  1762:                     (($prt eq 'raa') && ($env{'request.role'}=~/^aa/)) || 
1.152     albertel 1763:                     (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
1.19      matthew  1764:                     # Check that we are on the correct machine
1.29      matthew  1765:                     my $cadom=$requested_domain;
1.152     albertel 1766:                     my $caname=$env{'user.name'};
1.234     raeburn  1767:                     if (($prt eq 'rca') || ($prt eq 'raa')) {
1.29      matthew  1768: 		       ($cadom,$caname)=
1.206     albertel 1769:                                ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.29      matthew  1770:                     }                       
                   1771:                     $act =~ s/\$caname/$caname/g;
1.353     www      1772:                     $act =~ s/\$cadom/$cadom/g;
1.19      matthew  1773:                     my $home = &Apache::lonnet::homeserver($caname,$cadom);
1.109     albertel 1774: 		    my $allowed=0;
                   1775: 		    my @ids=&Apache::lonnet::current_machine_ids();
                   1776: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                   1777: 		    if ($allowed) {
1.209     www      1778:                         $output.=&switch($caname,$cadom,
                   1779:                                         $row,$col,$img,$top,$bot,$act,$desc,$cat);
1.19      matthew  1780:                     }
1.6       www      1781:                 }
1.2       www      1782:             }
1.248     raeburn  1783:         } elsif ($pro eq 'tools') {
                   1784:             my @tools = ('aboutme','blog','portfolio');
                   1785:             if (grep(/^\Q$prt\E$/,@tools)) {
1.249     raeburn  1786:                 if (!&Apache::lonnet::usertools_access($env{'user.name'},
1.251     raeburn  1787:                                                        $env{'user.domain'},
                   1788:                                                        $prt,undef,'tools')) {
                   1789:                     $output.=&clear($row,$col);
                   1790:                     next;
                   1791:                 }
1.278     raeburn  1792:             } elsif (($prt eq 'reqcrsnsc') || ($prt eq 'reqcrsshc')) {
                   1793:                 if (($prt eq 'reqcrsnsc') && ($show_course))   {
                   1794:                     next;
                   1795:                 }
                   1796:                 if (($prt eq 'reqcrsshc') && (!$show_course)) {
                   1797:                     next;
                   1798:                 }
1.279     raeburn  1799:                 my $showreqcrs = &check_for_rcrs();
1.251     raeburn  1800:                 if (!$showreqcrs) {
1.248     raeburn  1801:                     $output.=&clear($row,$col);
                   1802:                     next;
                   1803:                 }
                   1804:             }
                   1805:             $prt='any';
                   1806:             $output.=&secondlevel(
                   1807:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1808:         }
1.13      harris41 1809:     }
1.2       www      1810:     return $output;
                   1811: }
                   1812: 
1.279     raeburn  1813: sub check_for_rcrs {
                   1814:     my $showreqcrs = 0;
1.443     raeburn  1815:     my @reqtypes = ('official','unofficial','community','textbook','placement');
1.280     raeburn  1816:     foreach my $type (@reqtypes) {
1.279     raeburn  1817:         if (&Apache::lonnet::usertools_access($env{'user.name'},
                   1818:                                               $env{'user.domain'},
                   1819:                                               $type,undef,'requestcourses')) {
                   1820:             $showreqcrs = 1;
                   1821:             last;
                   1822:         }
                   1823:     }
1.280     raeburn  1824:     if (!$showreqcrs) {
                   1825:         foreach my $type (@reqtypes) {
                   1826:             if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
                   1827:                 $showreqcrs = 1;
                   1828:                 last;
                   1829:             }
                   1830:         }
                   1831:     }
1.279     raeburn  1832:     return $showreqcrs;
                   1833: }
                   1834: 
1.306     raeburn  1835: sub dc_popup_js {
                   1836:     my %lt = &Apache::lonlocal::texthash(
                   1837:                                           more => '(More ...)',
                   1838:                                           less => '(Less ...)',
                   1839:                                         );
                   1840:     return <<"END";
                   1841: 
                   1842: function showCourseID() {
                   1843:     document.getElementById('dccid').style.display='block';
                   1844:     document.getElementById('dccid').style.textAlign='left';
1.307     raeburn  1845:     document.getElementById('dccid').style.textFace='normal';
1.369     raeburn  1846:     document.getElementById('dccidtext').innerHTML ='<a href="javascript:hideCourseID();" class="LC_menubuttons_link">$lt{'less'}</a>';
1.306     raeburn  1847:     return;
                   1848: }
                   1849: 
                   1850: function hideCourseID() {
                   1851:     document.getElementById('dccid').style.display='none';
1.369     raeburn  1852:     document.getElementById('dccidtext').innerHTML ='<a href="javascript:showCourseID()" class="LC_menubuttons_link">$lt{'more'}</a>';
1.306     raeburn  1853:     return;
                   1854: }
                   1855: 
                   1856: END
                   1857: 
                   1858: }
                   1859: 
1.378     raeburn  1860: sub countdown_toggle_js {
                   1861:     return <<"END";
                   1862: 
                   1863: function toggleCountdown() {
                   1864:     var countdownid = document.getElementById('duedatecountdown');
                   1865:     var currstyle = countdownid.style.display;
                   1866:     if (currstyle == 'inline') {
                   1867:         countdownid.style.display = 'none';
                   1868:         document.getElementById('ddcountcollapse').innerHTML='';
                   1869:         document.getElementById('ddcountexpand').innerHTML='&#9668;&nbsp;';
                   1870:     } else {
                   1871:         countdownid.style.display = 'inline';
                   1872:         document.getElementById('ddcountcollapse').innerHTML='&#9658;&nbsp;';
                   1873:         document.getElementById('ddcountexpand').innerHTML='';
                   1874:     }
                   1875:     return;
                   1876: }
                   1877: 
                   1878: END
                   1879: }
                   1880: 
1.435     musolffc 1881: # This creates a "done button" for timed events.  The confirmation box is a jQuery
1.440     raeburn  1882: # dialog widget. If the interval parameter requires a proctor key for the timed 
                   1883: # event to be marked done, there will also be a textbox where that can be entered. 
                   1884: # Clicking OK will set the value of LC_interval_done to 'true', and, if needed will 
                   1885: # set the value of LC_interval_done_proctorpass to the text entered in that box, 
                   1886: # and submit the corresponding form.
                   1887: # 
                   1888: # The &zero_time() routine in lonhomework.pm is called when a page is rendered if
                   1889: # LC_interval_done is true.
                   1890: #
1.435     musolffc 1891: sub done_button_js {
1.448     raeburn  1892:     my ($type,$width,$height,$proctor,$donebuttontext) = @_;
1.441     raeburn  1893:     return unless (($type eq 'map') || ($type eq 'resource'));
1.435     musolffc 1894:     my %lt = &Apache::lonlocal::texthash(
                   1895:                  title    => 'WARNING!',
                   1896:                  preamble => 'You are trying to end this timed event early.',
                   1897:                  map      => 'Confirming that you are done will cause the time to expire and prevent you from changing any answers in the current folder.',
                   1898:                  resource => 'Confirming that you are done will cause the time to expire for this question, and prevent you from changing your answer(s).', 
1.440     raeburn  1899:                  okdone   => 'Click "OK" if you are completely finished.',
1.435     musolffc 1900:                  cancel   => 'Click "Cancel" to continue working.',
1.440     raeburn  1901:                  proctor  => 'Ask a proctor to enter the key, then click "OK" if you are completely finished.',
                   1902:                  ok       => 'OK',
                   1903:                  exit     => 'Cancel',
                   1904:                  key      => 'Key:',
                   1905:                  nokey    => 'A proctor key is required', 
1.435     musolffc 1906:     );
1.441     raeburn  1907:     my $navmap = Apache::lonnavmaps::navmap->new(); 
1.450     raeburn  1908:     my ($missing,$tried) = (0,0);
1.441     raeburn  1909:     if (ref($navmap)) {
                   1910:         my @resources=();
                   1911:         if ($type eq 'map') {
                   1912:             my ($mapurl,$rid,$resurl)=&Apache::lonnet::decode_symb($env{'request.symb'});
1.500   ! raeburn  1913:             if ($env{'request.symb'} =~ /\.page$/) {
        !          1914:                 @resources=$navmap->retrieveResources($resurl,sub { $_[0]->is_problem() });
        !          1915:             } else {
        !          1916:                 @resources=$navmap->retrieveResources($mapurl,sub { $_[0]->is_problem() });
        !          1917:             }
1.441     raeburn  1918:         } else {
                   1919:             my $res = $navmap->getBySymb($env{'request.symb'});
                   1920:             if (ref($res)) {
                   1921:                 if ($res->is_problem()) {
                   1922:                     push(@resources,$res);
                   1923:                 }
                   1924:             }
                   1925:         }
                   1926:         foreach my $res (@resources) {
1.450     raeburn  1927:             if (ref($res->parts()) eq 'ARRAY') {
1.441     raeburn  1928:                 foreach my $part (@{$res->parts()}) {
                   1929:                     if (!$res->tries($part)) {
                   1930:                         $missing++;
                   1931:                     } else {
                   1932:                         $tried++;
                   1933:                     }
                   1934:                 }
                   1935:             }
                   1936:         }
                   1937:     }
                   1938:     if ($missing) {
                   1939:         $lt{'miss'} .= '<p class="LC_error">';
                   1940:         if ($type eq 'map') {
                   1941:             $lt{'miss'} .= &mt('Submissions are missing for [quant,_1,question part,question parts] in this folder.',$missing);
                   1942:         } else {
                   1943:             $lt{'miss'} .= &mt('Submissions are missing for [quant,_1,part] in this question.',$missing);
                   1944:         }
                   1945:         if ($missing > 1) {
                   1946:             $lt{'miss'} .= ' '.&mt('If you confirm you are done you will be unable to submit answers for them.').'</span>';
                   1947:         } else {
                   1948:             $lt{'miss'} .= ' '.&mt('If you confirm you are done you will be unable to submit an answer for it.').'</p>';
                   1949:         }
                   1950:     }
1.449     raeburn  1951:     $donebuttontext = &HTML::Entities::encode($donebuttontext,'<>&"');
1.441     raeburn  1952:     if ($proctor) {
                   1953:         if ($height !~ /^\d+$/) {
                   1954:             $height = 400;
                   1955:             if ($missing) {
                   1956:                 $height += 60; 
1.440     raeburn  1957:             }
1.441     raeburn  1958:         }
                   1959:         if ($width !~ /^\d+$/) {
                   1960:             $width = 400;
                   1961:             if ($missing) {
                   1962:                 $width += 60;
1.440     raeburn  1963:             }
1.441     raeburn  1964:         }
                   1965:         return <<END;
1.440     raeburn  1966: <form method="post" name="LCdoneButton" action="">
                   1967:     <input type="hidden" name="LC_interval_done" value="" />
                   1968:     <input type="hidden" name="LC_interval_done_proctorpass" value="" />
1.448     raeburn  1969:     <button id="LC_done-confirm-opener" type="button">$donebuttontext</button>
1.440     raeburn  1970: </form>
                   1971: 
                   1972: <div id="LC_done-confirm" title="$lt{'title'}">
                   1973:   <p>$lt{'preamble'} $lt{$type}</p>
1.441     raeburn  1974:   $lt{'miss'}
1.440     raeburn  1975:   <p>$lt{'proctor'}</p>
1.449     raeburn  1976:   <form name="LCdoneButtonProctor" action="">
1.440     raeburn  1977:     <label>$lt{'key'}<input type="password" name="LC_interval_done_proctorkey" value="" /></label>
                   1978:     <input type="submit" tabindex="-1" style="position:absolute; top:-1000px" />
                   1979:   </form>
                   1980:   <p>$lt{'cancel'}</p>
                   1981: </div>
                   1982: 
                   1983: <script type="text/javascript">
                   1984: // <![CDATA[
                   1985:     \$( "#LC_done-confirm" ).dialog({ autoOpen: false });
                   1986:     \$( "#LC_done-confirm-opener" ).on("click", function() {
                   1987:         \$( "#LC_done-confirm" ).dialog("open");
                   1988:         \$( "#LC_done-confirm" ).dialog({
                   1989:             height: $height,
                   1990:             width: $width,
                   1991:             modal: true,
                   1992:             resizable: false,
                   1993:             buttons: [
                   1994:                 {
                   1995:                     text: "$lt{'ok'}",
                   1996:                     click: function() {
                   1997:                         var proctorkey = \$( '[name="LC_interval_done_proctorkey"]' )[0].value;
                   1998:                         if ((proctorkey == '') || (proctorkey == null)) {
                   1999:                             alert("$lt{'nokey'}"); 
                   2000:                         } else { 
                   2001:                             \$( '[name="LC_interval_done"]' )[0].value = 'true';
                   2002:                             \$( '[name="LC_interval_done_proctorpass"]' )[0].value = proctorkey;
                   2003:                             \$( '[name="LCdoneButton"]' )[0].submit();
                   2004:                         }
                   2005:                     },
                   2006:                 },
                   2007:                 {
                   2008:                     text: "$lt{'exit'}",
                   2009:                     click: function() {
                   2010:                         \$("#LC_done-confirm").dialog( "close" );
                   2011:                     }
                   2012:                 }
                   2013:             ],
                   2014:             close: function() {
                   2015:                 \$( '[name="LC_interval_done_proctorkey"]' )[0].value = '';
                   2016:             }
                   2017:         });
                   2018:         \$( "#LC_done-confirm" ).find( "form" ).on( "submit", function( event ) {
                   2019:             event.preventDefault();
                   2020:             \$( '[name="LC_interval_done"]' )[0].value = 'true';
                   2021:             \$( '[name="LC_interval_done_proctorpass"]' )[0].value = \$( '[name="LC_interval_done_proctorkey"]' )[0].value;
                   2022:             \$( '[name="LCdoneButton"]' )[0].submit();
                   2023:         });
                   2024: });
                   2025: 
                   2026: // ]]>
                   2027: </script>
                   2028: 
                   2029: END
1.441     raeburn  2030:     } else {
                   2031:         if ($height !~ /^\d+$/) {
                   2032:             $height = 320;
                   2033:             if ($missing) {
                   2034:                 $height += 60;
1.440     raeburn  2035:             }
1.441     raeburn  2036:         }
                   2037:         if ($width !~ /^\d+$/) {
                   2038:             $width = 320;
                   2039:             if ($missing) {
                   2040:                 $width += 60;
1.440     raeburn  2041:             }
1.441     raeburn  2042:         }
                   2043:         if ($missing) {
                   2044:             $lt{'miss'} = '</p>'.$lt{'miss'}.'<p>';
                   2045:         }
                   2046:         return <<END;
1.435     musolffc 2047: 
                   2048: <form method="post" name="LCdoneButton" action="">
                   2049:     <input type="hidden" name="LC_interval_done" value="" />
1.449     raeburn  2050:     <button id="LC_done-confirm-opener" type="button">$donebuttontext</button>
1.435     musolffc 2051: </form>
                   2052: 
                   2053: <div id="LC_done-confirm" title="$lt{'title'}">
1.441     raeburn  2054:     <p>$lt{'preamble'} $lt{$type} $lt{'miss'} $lt{'okdone'} $lt{'cancel'}</p>
1.435     musolffc 2055: </div>
                   2056: 
                   2057: <script type="text/javascript">
                   2058: // <![CDATA[
                   2059: \$( "#LC_done-confirm" ).dialog({ autoOpen: false });
                   2060: \$( "#LC_done-confirm-opener" ).click(function() {
                   2061:     \$( "#LC_done-confirm" ).dialog( "open" );
                   2062:     \$( "#LC_done-confirm" ).dialog({
                   2063:       resizable: false,
                   2064:       height: $height,
1.440     raeburn  2065:       width: $width,
1.435     musolffc 2066:       modal: true,
1.440     raeburn  2067:       buttons: [
                   2068:                  {
                   2069:                     text: "$lt{'ok'}",
                   2070:                     click: function() {
                   2071:                         \$( this ).dialog( "close" );
                   2072:                         \$( '[name="LC_interval_done"]' )[0].value = 'true';
                   2073:                         \$( '[name="LCdoneButton"]' )[0].submit();
                   2074:                     },
                   2075:                  },
                   2076:                  {
                   2077:                      text: "$lt{'exit'}",
                   2078:                      click: function() {
                   2079:                          \$( this ).dialog( "close" );
                   2080:                      },
                   2081:                   },
                   2082:                ],
                   2083:        });
1.435     musolffc 2084: });
                   2085: // ]]>
                   2086: </script>
                   2087: 
                   2088: END
                   2089:     }
                   2090: }
                   2091: 
1.42      www      2092: sub utilityfunctions {
1.421     raeburn  2093:     my ($httphost) = @_;
1.152     albertel 2094:     my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
1.494     raeburn  2095:     my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
                   2096:     if ($currenturl =~ m{^/adm/wrapper/ext/}) {
                   2097:         if ($env{'request.external.querystring'}) {
1.293     raeburn  2098:             $currenturl .= ($currenturl=~/\?/)?'&':'?'.$env{'request.external.querystring'};
1.494     raeburn  2099:         }
1.495     raeburn  2100:         my ($anchor) = ($env{'request.symb'} =~ /(\#[^\#]+)$/);
                   2101:         if (($anchor) && ($currenturl !~ /\Q$anchor\E$/)) {
1.494     raeburn  2102:             $currenturl .= $1;
                   2103:         }
1.293     raeburn  2104:     }
1.183     www      2105:     $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
1.175     albertel 2106: 
1.306     raeburn  2107:     my $dc_popup_cid;
                   2108:     if ($env{'user.adv'} && exists($env{'user.role.dc./'.
                   2109:                         $env{'course.'.$env{'request.course.id'}.
                   2110:                                  '.domain'}.'/'})) {
                   2111:         $dc_popup_cid = &dc_popup_js();
                   2112:     }
                   2113: 
1.175     albertel 2114:     my $start_page_annotate = 
                   2115:         &Apache::loncommon::start_page('Annotator',undef,
                   2116: 				       {'only_body' => 1,
                   2117: 					'js_ready'  => 1,
                   2118: 					'bgcolor'   => '#BBBBBB',
                   2119: 					'add_entries' => {
                   2120: 					    'onload' => 'javascript:document.goannotate.submit();'}});
                   2121: 
1.205     albertel 2122:     my $end_page_annotate = 
                   2123:         &Apache::loncommon::end_page({'js_ready' => 1});
                   2124: 
1.389     raeburn  2125:     my $jumptores = &Apache::lonhtmlcommon::javascript_jumpto_resource();
1.336     raeburn  2126: 
1.368     www      2127:     my $esc_url=&escape($currenturl);
                   2128:     my $esc_symb=&escape($currentsymb);
1.332     wenzelju 2129: 
1.378     raeburn  2130:     my $countdown = &countdown_toggle_js();
                   2131: 
1.487     raeburn  2132:     my $ltitarget;
                   2133:     if ($env{'request.lti.login'}) {
                   2134:         $ltitarget = $env{'request.lti.target'};
                   2135:     }
                   2136: 
1.493     raeburn  2137:     my $annotateurl = '/adm/annotation';
                   2138:     if ($httphost) {
                   2139:         $annotateurl = '/adm/annotations';
                   2140:     }
1.429     raeburn  2141:     my $hostvar = '
                   2142: function setLCHost() {
                   2143:     var lcHostname="";
                   2144: ';
                   2145:     if ($httphost =~ m{^https?\://}) {
                   2146:         $hostvar .= '    var lcServer="'.$httphost.'";'."\n".
                   2147:                     '    var hostReg = /^https?:\/\/([^\/]+)$/i;'."\n".
                   2148:                     '    var match = hostReg.exec(lcServer);'."\n".
                   2149:                     '    if (match.length) {'."\n".
                   2150:                     '        if (match[1] == location.hostname) {'."\n".
                   2151:                     '            lcHostname=lcServer;'."\n".
                   2152:                     '        }'."\n".
                   2153:                     '    }'."\n";
                   2154:     }
                   2155:     
                   2156:     $hostvar .= '    return lcHostname;'."\n".
                   2157: '}'."\n";
                   2158: 
1.42      www      2159: return (<<ENDUTILITY)
1.429     raeburn  2160:     $hostvar
1.368     www      2161:     var currentURL=unescape("$esc_url");
                   2162:     var reloadURL=unescape("$esc_url");
                   2163:     var currentSymb=unescape("$esc_symb");
1.42      www      2164: 
1.306     raeburn  2165: $dc_popup_cid
1.114     albertel 2166: 
1.389     raeburn  2167: $jumptores
1.336     raeburn  2168: 
1.42      www      2169: function gopost(url,postdata) {
                   2170:    if (url!='') {
1.429     raeburn  2171:       var lcHostname = setLCHost();
                   2172:       this.document.server.action=lcHostname+url;
1.42      www      2173:       this.document.server.postdata.value=postdata;
                   2174:       this.document.server.command.value='';
                   2175:       this.document.server.url.value='';
                   2176:       this.document.server.symb.value='';
                   2177:       this.document.server.submit();
                   2178:    }
                   2179: }
                   2180: 
                   2181: function gocmd(url,cmd) {
                   2182:    if (url!='') {
1.429     raeburn  2183:       var lcHostname = setLCHost();
                   2184:       this.document.server.action=lcHostname+url;
1.42      www      2185:       this.document.server.postdata.value='';
                   2186:       this.document.server.command.value=cmd;
                   2187:       this.document.server.url.value=currentURL;
                   2188:       this.document.server.symb.value=currentSymb;
                   2189:       this.document.server.submit();
                   2190:    }
1.57      www      2191: }
                   2192: 
1.121     raeburn  2193: function gocstr(url,filename) {
                   2194:     if (url == '/adm/cfile?action=delete') {
                   2195:         this.document.cstrdelete.filename.value = filename
                   2196:         this.document.cstrdelete.submit();
                   2197:         return;
                   2198:     }
1.137     raeburn  2199:     if (url == '/adm/printout') {
                   2200:         this.document.cstrprint.postdata.value = filename
                   2201:         this.document.cstrprint.curseed.value = 0;
                   2202:         this.document.cstrprint.problemtype.value = 0;
1.138     raeburn  2203:         if (this.document.lonhomework) {
                   2204:             if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
                   2205:                 this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
                   2206:             }
                   2207:             if (this.document.lonhomework.problemtype) {
1.164     albertel 2208: 		if (this.document.lonhomework.problemtype.value) {
                   2209: 		    this.document.cstrprint.problemtype.value = 
                   2210: 			this.document.lonhomework.problemtype.value;
                   2211: 		} else if (this.document.lonhomework.problemtype.options) {
                   2212: 		    for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
                   2213: 			if (this.document.lonhomework.problemtype.options[i].selected) {
                   2214: 			    if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') { 
                   2215: 				this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
                   2216: 				}
                   2217: 			}
                   2218: 		    }
                   2219: 		}
                   2220: 	    }
                   2221: 	}
1.137     raeburn  2222:         this.document.cstrprint.submit();
                   2223:         return;
                   2224:     }
1.121     raeburn  2225:     if (url !='') {
                   2226:         this.document.constspace.filename.value = filename;
                   2227:         this.document.constspace.action = url;
                   2228:         this.document.constspace.submit();
                   2229:     }
                   2230: }
                   2231: 
1.131     raeburn  2232: function golist(url) {
                   2233:    if (url!='' && url!= null) {
                   2234:        currentURL = null;
                   2235:        currentSymb= null;
1.429     raeburn  2236:        var lcHostname = setLCHost();
1.487     raeburn  2237:        var ltitarget = '$ltitarget';
                   2238:        if (ltitarget == 'iframe') {
                   2239:            document.location.href=lcHostname+url;
                   2240:        } else {
                   2241:            top.location.href=lcHostname+url;
                   2242:        }
1.131     raeburn  2243:    }
                   2244: }
                   2245: 
                   2246: 
1.121     raeburn  2247: 
1.496     raeburn  2248: function catalog_info(url,isMobile) {
1.428     raeburn  2249:     if (isMobile == 1) {
1.496     raeburn  2250:         openMyModal(url+'.meta?modal=1',500,400,'yes');
1.428     raeburn  2251:     } else {
1.496     raeburn  2252:         loncatinfo=window.open(url+'.meta',"LONcatInfo",'height=500,width=400,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
1.428     raeburn  2253:     }
1.57      www      2254: }
                   2255: 
                   2256: function chat_win() {
1.429     raeburn  2257:    var lcHostname = setLCHost();
                   2258:    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      2259: }
1.169     raeburn  2260: 
                   2261: function group_chat(group) {
1.429     raeburn  2262:    var lcHostname = setLCHost();
                   2263:    var url = lcHostname+'/adm/groupchat?group='+group;
1.169     raeburn  2264:    var winName = 'LONchat_'+group;
                   2265:    grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
                   2266: }
1.175     albertel 2267: 
                   2268: function annotate() {
                   2269:    w_Annotator_flag=1;
                   2270:    annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
                   2271:    annotator.document.write(
                   2272:    '$start_page_annotate'
                   2273:   +"<form name='goannotate' target='Annotator' method='post' "
1.493     raeburn  2274:   +"action='$annotateurl'>"
1.217     albertel 2275:   +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />"
1.181     albertel 2276:   +"<\\/form>"
1.205     albertel 2277:   +'$end_page_annotate');
1.175     albertel 2278:    annotator.document.close();
                   2279: }
                   2280: 
1.370     raeburn  2281: function open_StoredLinks_Import(rat) {
1.335     wenzelju 2282:    var newWin;
1.429     raeburn  2283:    var lcHostname = setLCHost();
1.335     wenzelju 2284:    if (rat) {
1.429     raeburn  2285:        newWin = window.open(lcHostname+'/adm/wishlist?inhibitmenu=yes&mode=import&rat='+rat,
1.334     wenzelju 2286:                             'wishlistImport','scrollbars=1,resizable=1,menubar=0');
1.335     wenzelju 2287:    }
                   2288:    else {
1.429     raeburn  2289:        newWin = window.open(lcHostname+'/adm/wishlist?inhibitmenu=yes&mode=import',
1.335     wenzelju 2290:                             'wishlistImport','scrollbars=1,resizable=1,menubar=0');
                   2291:    }
1.334     wenzelju 2292:    newWin.focus();
                   2293: }
                   2294: 
1.480     raeburn  2295: function open_source() {
1.496     raeburn  2296:    sourcewin=window.open('/adm/source?inhibitmenu=yes&viewonly=1&filename='+currentURL,'LONsource',
1.480     raeburn  2297:                          'height=500,width=600,resizable=yes,location=no,menubar=no,toolbar=no,scrollbars=yes');
                   2298: }
                   2299: 
1.491     raeburn  2300: function open_aboutLC() {
                   2301:     var isMobile = "$env{'browser.mobile'}";
                   2302:     var url = '/adm/about.html';
                   2303:     if (isMobile == 1) {
                   2304:         openMyModal(url,600,400,'yes');
                   2305:     } else {
                   2306:         window.open(url,"aboutLONCAPA","height=400,width=600,scrollbars=1,resizable=1,menubar=0,location=1");
                   2307:     }
                   2308:     return;
                   2309: }
                   2310: 
                   2311: 
1.372     raeburn  2312: (function (\$) {
                   2313:   \$(document).ready(function () {
                   2314:     \$.single=function(a){return function(b){a[0]=b;return a}}(\$([1]));
                   2315:     /*\@cc_on
                   2316:       if (!window.XMLHttpRequest) {
                   2317:         \$('.LC_hoverable').each(function () {
                   2318:           this.attachEvent('onmouseenter', function (evt) { \$.single(evt.srcElement).addClass('hover'); });
                   2319:           this.attachEvent('onmouseleave', function (evt) { \$.single(evt.srcElement).removeClass('hover'); });
                   2320:         });
                   2321:       }
                   2322:     \@*/
                   2323:   });
                   2324: }(jQuery));
                   2325: 
1.378     raeburn  2326: $countdown
                   2327: 
1.42      www      2328: ENDUTILITY
                   2329: }
                   2330: 
                   2331: sub serverform {
1.486     raeburn  2332:     my $target;
                   2333:     unless (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
                   2334:         $target = ' target="_top"';
                   2335:     }
1.42      www      2336:     return(<<ENDSERVERFORM);
1.486     raeburn  2337: <form name="server" action="/adm/logout" method="post"$target>
1.42      www      2338: <input type="hidden" name="postdata" value="none" />
                   2339: <input type="hidden" name="command" value="none" />
                   2340: <input type="hidden" name="url" value="none" />
                   2341: <input type="hidden" name="symb" value="none" />
                   2342: </form>
                   2343: ENDSERVERFORM
                   2344: }
1.113     albertel 2345: 
1.121     raeburn  2346: sub constspaceform {
1.487     raeburn  2347:     my ($target,$printtarget);
                   2348:     unless (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
                   2349:         $target = ' target="_top"';
                   2350:         $printtarget = ' target="_parent"';
                   2351:     }
1.121     raeburn  2352:     return(<<ENDCONSTSPACEFORM);
1.487     raeburn  2353: <form name="constspace" action="/adm/logout" method="post"$target>
1.121     raeburn  2354: <input type="hidden" name="filename" value="" />
                   2355: </form>
1.487     raeburn  2356: <form name="cstrdelete" action="/adm/cfile" method="post"$target>
1.121     raeburn  2357: <input type="hidden" name="action" value="delete" /> 
                   2358: <input type="hidden" name="filename" value="" />
                   2359: </form>
1.487     raeburn  2360: <form name="cstrprint" action="/adm/printout" method="post"$printtarget>
1.137     raeburn  2361: <input type="hidden" name="postdata" value="" />
                   2362: <input type="hidden" name="curseed" value="" />
                   2363: <input type="hidden" name="problemtype" value="" />
                   2364: </form>
                   2365: 
1.121     raeburn  2366: ENDCONSTSPACEFORM
                   2367: }
                   2368: 
1.220     raeburn  2369: sub hidden_button_check {
1.317     droeschl 2370:     if ( $env{'request.course.id'} eq ''
                   2371:          || $env{'request.role.adv'} ) {
                   2372: 
1.220     raeburn  2373:         return;
                   2374:     }
1.232     raeburn  2375:     my $buttonshide = &Apache::lonnet::EXT('resource.0.buttonshide');
                   2376:     return $buttonshide; 
1.220     raeburn  2377: }
1.184     raeburn  2378: 
1.235     raeburn  2379: sub roles_selector {
1.486     raeburn  2380:     my ($cdom,$cnum,$httphost,$ltitarget) = @_;
1.298     raeburn  2381:     my $crstype = &Apache::loncommon::course_type();
1.235     raeburn  2382:     my $now = time;
1.465     raeburn  2383:     my (%courseroles,%seccount,%courseprivs,%roledesc);
1.235     raeburn  2384:     my $is_cc;
1.432     droeschl 2385:     my ($js,$form,$switcher);
1.298     raeburn  2386:     my $ccrole;
                   2387:     if ($crstype eq 'Community') {
                   2388:         $ccrole = 'co';
                   2389:     } else {
                   2390:         $ccrole = 'cc';
1.350     raeburn  2391:     }
1.457     raeburn  2392:     my ($privref,$gotsymb,$destsymb);
1.350     raeburn  2393:     my $destinationurl = $ENV{'REQUEST_URI'};
1.468     raeburn  2394:     if ($destinationurl =~ /(\?|\&)symb=/) {
1.386     raeburn  2395:         $gotsymb = 1;
                   2396:     } elsif ($destinationurl =~ m{^/enc/}) {
                   2397:         my $plainurl = &Apache::lonenc::unencrypted($destinationurl);
1.468     raeburn  2398:         if ($plainurl =~ /(\?|\&)symb=/) {
1.386     raeburn  2399:             $gotsymb = 1;
                   2400:         }
                   2401:     }
                   2402:     unless ($gotsymb) {
                   2403:         $destsymb = &Apache::lonnet::symbread();
                   2404:         if ($destsymb ne '') {
                   2405:             $destsymb = &Apache::lonenc::check_encrypt($destsymb);
                   2406:         }
                   2407:     }
1.350     raeburn  2408:     my $reqprivs = &required_privs();
                   2409:     if (ref($reqprivs) eq 'HASH') {
                   2410:         my $destination = $destinationurl;
                   2411:         $destination =~ s/(\?.*)$//;
                   2412:         if (exists($reqprivs->{$destination})) {
1.457     raeburn  2413:             if ($reqprivs->{$destination} =~ /,/) {
                   2414:                 @{$privref} = split(/,/,$reqprivs->{$destination});
                   2415:             } else { 
                   2416:                 $privref = [$reqprivs->{$destination}];
                   2417:             }
1.350     raeburn  2418:         }
                   2419:     }
1.298     raeburn  2420:     if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
                   2421:         my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
1.235     raeburn  2422:         if ((($start) && ($start<0)) || 
                   2423:             (($end) && ($end<$now))  ||
                   2424:             (($start) && ($now<$start))) {
                   2425:             $is_cc = 0;
                   2426:         } else {
                   2427:             $is_cc = 1;
                   2428:         }
                   2429:     }
                   2430:     if ($is_cc) {
1.457     raeburn  2431:         &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs);
                   2432:     } elsif ($env{'request.role'} =~ m{^\Qcr/$cdom/$cdom-domainconfig/\E(\w+)\.\Q/$cdom/$cnum\E}) {
1.465     raeburn  2433:         &get_customadhoc_roles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs,\%roledesc,$privref);
1.235     raeburn  2434:     } else {
1.262     raeburn  2435:         my %gotnosection;
1.235     raeburn  2436:         foreach my $item (keys(%env)) {
1.239     raeburn  2437:             if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
1.235     raeburn  2438:                 my $role = $1;
                   2439:                 my $sec = $2;
                   2440:                 next if ($role eq 'gr');
                   2441:                 my ($start,$end) = split(/\./,$env{$item});
                   2442:                 next if (($start && $start > $now) || ($end && $end < $now));
                   2443:                 if ($sec eq '') {
1.239     raeburn  2444:                     if (!$gotnosection{$role}) {
                   2445:                         $seccount{$role} ++;
                   2446:                         $gotnosection{$role} = 1;
                   2447:                     }
1.235     raeburn  2448:                 }
1.457     raeburn  2449:                 if ((ref($privref) eq 'ARRAY') && (@{$privref} > 0)) {
1.350     raeburn  2450:                     my $cnumsec = $cnum;
                   2451:                     if ($sec ne '') {
                   2452:                         $cnumsec .= "/$sec";
                   2453:                     }
                   2454:                     $courseprivs{"$role./$cdom/$cnumsec./"} =
                   2455:                         $env{"user.priv.$role./$cdom/$cnumsec./"};
                   2456:                     $courseprivs{"$role./$cdom/$cnumsec./$cdom/"} =
                   2457:                         $env{"user.priv.$role./$cdom/$cnumsec./$cdom/"};
                   2458:                     $courseprivs{"$role./$cdom/$cnumsec./$cdom/$cnumsec"} =
                   2459:                         $env{"user.priv.$role./$cdom/$cnumsec./$cdom/$cnumsec"};
                   2460:                 }
1.235     raeburn  2461:                 if (ref($courseroles{$role}) eq 'ARRAY') {
1.239     raeburn  2462:                     if ($sec ne '') {
1.264     raeburn  2463:                         if (!grep(/^\Q$sec\E$/,@{$courseroles{$role}})) {
1.239     raeburn  2464:                             push(@{$courseroles{$role}},$sec);
                   2465:                             $seccount{$role} ++;
                   2466:                         }
                   2467:                     }
                   2468:                 } else {
                   2469:                     @{$courseroles{$role}} = ();
                   2470:                     if ($sec ne '') {
                   2471:                         $seccount{$role} ++;
1.235     raeburn  2472:                         push(@{$courseroles{$role}},$sec);
                   2473:                     }
                   2474:                 }
                   2475:             }
                   2476:         }
                   2477:     }
1.298     raeburn  2478:     my @roles_order = ($ccrole,'in','ta','ep','ad','st');
1.402     raeburn  2479:     my $numdiffsec;
                   2480:     if (keys(%seccount) == 1) {
                   2481:         foreach my $key (keys(%seccount)) {
                   2482:             $numdiffsec = $seccount{$key};
                   2483:         }
                   2484:     }
                   2485:     if ((keys(%seccount) > 1) || ($numdiffsec > 1)) {
1.401     raeburn  2486:         my @submenu;
1.465     raeburn  2487:         $js = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles,\%courseprivs,\%roledesc,$privref);
1.401     raeburn  2488:         $form = 
1.421     raeburn  2489:             '<form name="rolechooser" method="post" action="'.$httphost.'/adm/roles">'."\n".
1.401     raeburn  2490:             '  <input type="hidden" name="destinationurl" value="'.
                   2491:             &HTML::Entities::encode($destinationurl).'" />'."\n".
                   2492:             '  <input type="hidden" name="gotorole" value="1" />'."\n".
                   2493:             '  <input type="hidden" name="selectrole" value="" />'."\n".
1.402     raeburn  2494:             '  <input type="hidden" name="switchrole" value="" />'."\n";
                   2495:         if ($destsymb ne '') {
                   2496:             $form .= '  <input type="hidden" name="destsymb" value="'.
                   2497:                         &HTML::Entities::encode($destsymb).'" />'."\n";
                   2498:         }
                   2499:         $form .= '</form>'."\n";
1.235     raeburn  2500:         foreach my $role (@roles_order) {
1.402     raeburn  2501:             my $include;
1.235     raeburn  2502:             if (defined($courseroles{$role})) {
1.402     raeburn  2503:                 if ($env{'request.role'} =~ m{^\Q$role\E}) {
                   2504:                     if ($seccount{$role} > 1) {
                   2505:                         $include = 1;
                   2506:                     }
                   2507:                 } else {
                   2508:                     $include = 1;
                   2509:                 }
                   2510:             }
                   2511:             if ($include) {
1.401     raeburn  2512:                 push(@submenu,['javascript:adhocRole('."'$role'".')',
                   2513:                                &Apache::lonnet::plaintext($role,$crstype)]);
1.235     raeburn  2514:             }
                   2515:         }
                   2516:         foreach my $role (sort(keys(%courseroles))) {
                   2517:             if ($role =~ /^cr/) {
1.403     raeburn  2518:                 my $include;
                   2519:                 if ($env{'request.role'} =~ m{^\Q$role\E}) {
1.402     raeburn  2520:                     if ($seccount{$role} > 1) {
                   2521:                         $include = 1;
                   2522:                     }
1.403     raeburn  2523:                 } else {
                   2524:                     $include = 1; 
                   2525:                 }
                   2526:                 if ($include) {
1.460     raeburn  2527:                     my $rolename;
                   2528:                     if ($role =~ m{^cr/$cdom/$cdom\-domainconfig/(\w+)(?:/\w+|$)}) {
1.465     raeburn  2529:                         $rolename = $roledesc{$role};
                   2530:                         if ($rolename eq '') {
                   2531:                             $rolename = &mt('Helpdesk [_1]',$1);
                   2532:                         }
1.460     raeburn  2533:                     } else {
                   2534:                         $rolename = &Apache::lonnet::plaintext($role);
                   2535:                     }
1.403     raeburn  2536:                     push(@submenu,['javascript:adhocRole('."'$role'".')',
1.460     raeburn  2537:                                    $rolename]);
1.403     raeburn  2538:                 }
1.235     raeburn  2539:             }
                   2540:         }
1.401     raeburn  2541:         if (@submenu > 0) {
1.486     raeburn  2542:             $switcher = &create_submenu('','',&mt('Switch role'),\@submenu,'','',$ltitarget);
1.386     raeburn  2543:         }
1.235     raeburn  2544:     }
1.401     raeburn  2545:     return ($js,$form,$switcher);
1.235     raeburn  2546: }
                   2547: 
1.262     raeburn  2548: sub get_all_courseroles {
1.350     raeburn  2549:     my ($cdom,$cnum,$courseroles,$seccount,$courseprivs) = @_;
1.351     raeburn  2550:     unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH') &&
1.350     raeburn  2551:             (ref($courseprivs) eq 'HASH')) {
1.262     raeburn  2552:         return;
                   2553:     }
                   2554:     my ($result,$cached) = 
                   2555:         &Apache::lonnet::is_cached_new('getcourseroles',$cdom.'_'.$cnum);
                   2556:     if (defined($cached)) {
                   2557:         if (ref($result) eq 'HASH') {
                   2558:             if ((ref($result->{'roles'}) eq 'HASH') && 
1.350     raeburn  2559:                 (ref($result->{'seccount'}) eq 'HASH') && 
                   2560:                 (ref($result->{'privs'}) eq 'HASH')) {
1.262     raeburn  2561:                 %{$courseroles} = %{$result->{'roles'}};
                   2562:                 %{$seccount} = %{$result->{'seccount'}};
1.350     raeburn  2563:                 %{$courseprivs} = %{$result->{'privs'}};
1.262     raeburn  2564:                 return;
                   2565:             }
                   2566:         }
                   2567:     }
                   2568:     my %gotnosection;
                   2569:     my %adv_roles =
                   2570:          &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
                   2571:     foreach my $role (keys(%adv_roles)) {
                   2572:         my ($urole,$usec) = split(/:/,$role);
                   2573:         if (!$gotnosection{$urole}) {
                   2574:             $seccount->{$urole} ++;
                   2575:             $gotnosection{$urole} = 1;
                   2576:         }
                   2577:         if (ref($courseroles->{$urole}) eq 'ARRAY') {
                   2578:             if ($usec ne '') {
                   2579:                 if (!grep(/^Q$usec\E$/,@{$courseroles->{$urole}})) {
                   2580:                     push(@{$courseroles->{$urole}},$usec);
                   2581:                     $seccount->{$urole} ++;
                   2582:                 }
                   2583:             }
                   2584:         } else {
                   2585:             @{$courseroles->{$urole}} = ();
                   2586:             if ($usec ne '') {
                   2587:                 $seccount->{$urole} ++;
                   2588:                 push(@{$courseroles->{$urole}},$usec);
                   2589:             }
                   2590:         }
1.350     raeburn  2591:         my $area = '/'.$cdom.'/'.$cnum;
                   2592:         if ($usec ne '') {
                   2593:             $area .= '/'.$usec;
                   2594:         }
                   2595:         if ($role =~ /^cr\//) {
                   2596:             &Apache::lonnet::custom_roleprivs($courseprivs,$urole,$cdom,$cnum,$urole.'.'.$area,$area);
                   2597:         } else {
                   2598:             &Apache::lonnet::standard_roleprivs($courseprivs,$urole,$cdom,$urole.'.'.$area,$cnum,$area);
                   2599:         }
1.262     raeburn  2600:     }
                   2601:     my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum,['st']);
                   2602:     @{$courseroles->{'st'}} = ();
1.350     raeburn  2603:     &Apache::lonnet::standard_roleprivs($courseprivs,'st',$cdom,"st./$cdom/$cnum",$cnum,"/$cdom/$cnum");
1.262     raeburn  2604:     if (keys(%sections_count) > 0) {
                   2605:         push(@{$courseroles->{'st'}},keys(%sections_count));
1.350     raeburn  2606:         $seccount->{'st'} = scalar(keys(%sections_count));
1.262     raeburn  2607:     }
1.410     raeburn  2608:     $seccount->{'st'} ++; # Increment for a section-less student role.  
1.262     raeburn  2609:     my $rolehash = {
                   2610:                      'roles'    => $courseroles,
                   2611:                      'seccount' => $seccount,
1.350     raeburn  2612:                      'privs'    => $courseprivs,
1.262     raeburn  2613:                    };
                   2614:     &Apache::lonnet::do_cache_new('getcourseroles',$cdom.'_'.$cnum,$rolehash);
                   2615:     return;
                   2616: }
                   2617: 
1.457     raeburn  2618: sub get_customadhoc_roles {
1.465     raeburn  2619:     my ($cdom,$cnum,$courseroles,$seccount,$courseprivs,$roledesc,$privref) = @_;
1.457     raeburn  2620:     unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH') &&
1.465     raeburn  2621:             (ref($courseprivs) eq 'HASH') && (ref($roledesc) eq 'HASH')) {
1.457     raeburn  2622:         return;
                   2623:     }
1.466     raeburn  2624:     my $is_helpdesk = 0;
                   2625:     my $now = time;
                   2626:     foreach my $role ('dh','da') {
                   2627:         if ($env{"user.role.$role./$cdom/"}) {
                   2628:             my ($start,$end)=split(/\./,$env{"user.role.$role./$cdom/"});
                   2629:             if (!($start && ($now<$start)) && !($end && ($now>$end))) {
                   2630:                 $is_helpdesk = 1;
                   2631:                 last;
                   2632:             }
                   2633:         }
                   2634:     }
                   2635:     if ($is_helpdesk) {
                   2636:         my ($possroles,$description) = &Apache::lonnet::get_my_adhocroles($cdom.'_'.$cnum);
                   2637:         my %available;
                   2638:         if (ref($possroles) eq 'ARRAY') {
                   2639:             map { $available{$_} = 1; } @{$possroles};
                   2640:         }
                   2641:         my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
                   2642:         if (ref($domdefaults{'adhocroles'}) eq 'HASH') {
                   2643:             if (keys(%{$domdefaults{'adhocroles'}})) {
                   2644:                 my $numsec = 1;
                   2645:                 my @sections;
                   2646:                 my ($allseclist,$cached) =
                   2647:                     &Apache::lonnet::is_cached_new('courseseclist',$cdom.'_'.$cnum);
                   2648:                 if (defined($cached)) {
                   2649:                     if ($allseclist ne '') {
                   2650:                         @sections = split(/,/,$allseclist);
1.465     raeburn  2651:                         $numsec += scalar(@sections);
1.457     raeburn  2652:                     }
1.466     raeburn  2653:                 } else {
                   2654:                     my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
                   2655:                     @sections = sort(keys(%sections_count));
                   2656:                     $numsec += scalar(@sections);
                   2657:                     $allseclist = join(',',@sections);
                   2658:                     &Apache::lonnet::do_cache_new('courseseclist',$cdom.'_'.$cnum,$allseclist);
                   2659:                 }
                   2660:                 my (%adhoc,$gotprivs);
                   2661:                 my $prefix = "cr/$cdom/$cdom".'-domainconfig';
                   2662:                 foreach my $role (keys(%{$domdefaults{'adhocroles'}})) {
                   2663:                     next if (($role eq '') || ($role =~ /\W/));
                   2664:                     $seccount->{"$prefix/$role"} = $numsec;
                   2665:                     $roledesc->{"$prefix/$role"} = $description->{$role};
                   2666:                     if ((ref($privref) eq 'ARRAY') && (@{$privref} > 0)) {
                   2667:                         if (exists($env{"user.priv.$prefix/$role./$cdom/$cnum./"})) {
                   2668:                             $courseprivs->{"$prefix/$role./$cdom/$cnum./"} =
                   2669:                                 $env{"user.priv.$prefix/$role./$cdom/$cnum./"};
                   2670:                             $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/"} =
                   2671:                                 $env{"user.priv.$prefix/$role./$cdom/$cnum./$cdom/"};
                   2672:                             $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/$cnum"} =
                   2673:                                 $env{"user.priv.$prefix/$role./$cdom/$cnum./$cdom/$cnum"};
                   2674:                         } else {
                   2675:                             unless ($gotprivs) {
                   2676:                                 my ($adhocroles,$privscached) =
                   2677:                                     &Apache::lonnet::is_cached_new('adhocroles',$cdom);
                   2678:                                 if ((defined($privscached)) && (ref($adhocroles) eq 'HASH')) {
                   2679:                                     %adhoc = %{$adhocroles};
                   2680:                                 } else {
                   2681:                                     my $confname = &Apache::lonnet::get_domainconfiguser($cdom);
                   2682:                                     my %roledefs = &Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
                   2683:                                     foreach my $key (keys(%roledefs)) {
                   2684:                                         (undef,my $rolename) = split(/_/,$key);
                   2685:                                         if ($rolename ne '') {
                   2686:                                             my ($systempriv,$domainpriv,$coursepriv) = split(/\_/,$roledefs{$key});
                   2687:                                             $coursepriv = &Apache::lonnet::course_adhocrole_privs($rolename,$cdom,$cnum,$coursepriv);
                   2688:                                             $adhoc{$rolename} = join('_',($systempriv,$domainpriv,$coursepriv));
1.457     raeburn  2689:                                         }
                   2690:                                     }
1.466     raeburn  2691:                                     &Apache::lonnet::do_cache_new('adhocroles',$cdom,\%adhoc);
1.457     raeburn  2692:                                 }
1.466     raeburn  2693:                                 $gotprivs = 1;
1.457     raeburn  2694:                             }
1.466     raeburn  2695:                             ($courseprivs->{"$prefix/$role./$cdom/$cnum./"},
                   2696:                              $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/"},
                   2697:                              $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/$cnum"}) =
                   2698:                                  split(/\_/,$adhoc{$role});
1.457     raeburn  2699:                         }
1.466     raeburn  2700:                     }
                   2701:                     if ($available{$role}) {
                   2702:                         $courseroles->{"$prefix/$role"} = \@sections;
1.457     raeburn  2703:                     }
                   2704:                 }
                   2705:             }
                   2706:         }
                   2707:     }
                   2708:     return;
                   2709: }
                   2710: 
1.235     raeburn  2711: sub jump_to_role {
1.465     raeburn  2712:     my ($cdom,$cnum,$seccount,$courseroles,$courseprivs,$roledesc,$privref) = @_;
1.239     raeburn  2713:     my %lt = &Apache::lonlocal::texthash(
                   2714:                 this => 'This role has section(s) associated with it.',
                   2715:                 ente => 'Enter a specific section.',
                   2716:                 orlb => 'Enter a specific section, or leave blank for no section.',
                   2717:                 avai => 'Available sections are:',
                   2718:                 youe => 'You entered an invalid section choice:',
1.352     raeburn  2719:                 plst => 'Please try again.',
1.350     raeburn  2720:                 role => 'The role you selected is not permitted to view the current page.',
                   2721:                 swit => 'Switch role, but display Main Menu page instead?',
1.239     raeburn  2722:     );
                   2723:     my $js;
                   2724:     if (ref($courseroles) eq 'HASH') {
                   2725:         $js = '    var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n". 
                   2726:               '    var numsec = new Array();'."\n".
                   2727:               '    var rolesections = new Array();'."\n".
                   2728:               '    var rolenames = new Array();'."\n".
                   2729:               '    var roleseclist = new Array();'."\n";
                   2730:         my @items = keys(%{$courseroles});
                   2731:         for (my $i=0; $i<@items; $i++) {
                   2732:             $js .= '    rolenames['.$i.'] = "'.$items[$i].'";'."\n";
                   2733:             my ($secs,$secstr);
                   2734:             if (ref($courseroles->{$items[$i]}) eq 'ARRAY') {
                   2735:                 my @sections = sort { $a <=> $b } @{$courseroles->{$items[$i]}};
                   2736:                 $secs = join('","',@sections);
                   2737:                 $secstr = join(', ',@sections);
                   2738:             }
                   2739:             $js .= '    rolesections['.$i.'] = new Array("'.$secs.'");'."\n".
                   2740:                    '    roleseclist['.$i.'] = "'.$secstr.'";'."\n".
                   2741:                    '    numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n";
                   2742:         }
                   2743:     }
1.350     raeburn  2744:     my $checkroles = 0;
1.457     raeburn  2745:     if ((ref($privref) eq 'ARRAY') && (@{$privref} > 0) && (ref($courseprivs) eq 'HASH')) {
                   2746:         my %disallowed;
1.350     raeburn  2747:         foreach my $role (sort(keys(%{$courseprivs}))) {
                   2748:             my $trole;
                   2749:             if ($role =~ m{^(.+?)\Q./$cdom/$cnum\E}) {
                   2750:                 $trole = $1;
                   2751:             }
                   2752:             if (($trole ne '') && ($trole ne 'cm')) {
1.457     raeburn  2753:                 $disallowed{$trole} = 1;
                   2754:                 foreach my $priv (@{$privref}) { 
                   2755:                     if ($courseprivs->{$role} =~ /\Q:$priv\E($|:|\&\w+)/) {
                   2756:                         delete($disallowed{$trole});
                   2757:                         last;
                   2758:                     }
1.350     raeburn  2759:                 }
                   2760:             }
                   2761:         }
1.457     raeburn  2762:         if (keys(%disallowed) > 0) {
1.350     raeburn  2763:             $checkroles = 1;
1.457     raeburn  2764:             $js .= "    var disallow = new Array('".join("','",keys(%disallowed))."');\n".
1.350     raeburn  2765:                    "    var rolecheck = 1;\n";
                   2766:         }
                   2767:     }
                   2768:     if (!$checkroles) {
                   2769:         $js .=  "    var disallow = new Array();\n".
                   2770:                 "    rolecheck = 0;\n";
                   2771:     }
1.273     droeschl 2772:     return <<"END";
1.235     raeburn  2773: <script type="text/javascript">
1.273     droeschl 2774: //<![CDATA[
1.401     raeburn  2775: function adhocRole(newrole) {
1.239     raeburn  2776:     $js
1.235     raeburn  2777:     if (newrole == '') {
1.350     raeburn  2778:         return;
1.235     raeburn  2779:     } 
1.239     raeburn  2780:     var fullrole = newrole+'./$cdom/$cnum';
                   2781:     var selidx = '';
                   2782:     for (var i=0; i<rolenames.length; i++) {
                   2783:         if (rolenames[i] == newrole) {
                   2784:             selidx = i;
                   2785:         }
                   2786:     }
1.350     raeburn  2787:     if (rolecheck > 0) {
                   2788:         for (var i=0; i<disallow.length; i++) {
                   2789:             if (disallow[i] == newrole) {
                   2790:                 if (confirm("$lt{'role'}\\n$lt{'swit'}")) {
                   2791:                     document.rolechooser.destinationurl.value = '/adm/menu';
                   2792:                 } else {
                   2793:                     return;
                   2794:                 }
                   2795:             }
                   2796:         }
                   2797:     }
1.239     raeburn  2798:     var secok = 1;
                   2799:     var secchoice = '';
                   2800:     if (selidx >= 0) {
                   2801:         if (numsec[selidx] > 1) {
                   2802:             secok = 0;
                   2803:             var numrolesec = rolesections[selidx].length;
                   2804:             var msgidx = numsec[selidx] - numrolesec;
1.339     raeburn  2805:             secchoice = prompt("$lt{'this'} "+secpick[msgidx]+"\\n$lt{'avai'} "+roleseclist[selidx],"");
1.239     raeburn  2806:             if (secchoice == '') {
                   2807:                 if (msgidx > 0) {
                   2808:                     secok = 1;
                   2809:                 }
                   2810:             } else {
                   2811:                 for (var j=0; j<rolesections[selidx].length; j++) {
                   2812:                     if (rolesections[selidx][j] == secchoice) {
                   2813:                         secok = 1;
                   2814:                     }
                   2815:                 }
                   2816:             }
                   2817:         } else {
                   2818:             if (rolesections[selidx].length == 1) {
                   2819:                 secchoice = rolesections[selidx][0];
                   2820:             }
                   2821:         }
                   2822:     }
                   2823:     if (secok == 1) {
                   2824:         if (secchoice != '') {
                   2825:             fullrole += '/'+secchoice;
                   2826:         }
                   2827:     } else {
                   2828:         if (secchoice != null) {
                   2829:             alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}");
                   2830:         }
                   2831:         return;
                   2832:     }
                   2833:     if (fullrole == "$env{'request.role'}") {
1.235     raeburn  2834:         return;
                   2835:     }
                   2836:     itemid = retrieveIndex('gotorole');
                   2837:     if (itemid != -1) {
1.239     raeburn  2838:         document.rolechooser.elements[itemid].name = fullrole;
1.235     raeburn  2839:     }
1.401     raeburn  2840:     document.rolechooser.switchrole.value = fullrole;
1.235     raeburn  2841:     document.rolechooser.selectrole.value = '1';
                   2842:     document.rolechooser.submit();
                   2843:     return;
                   2844: }
                   2845: 
                   2846: function retrieveIndex(item) {
                   2847:     for (var i=0;i<document.rolechooser.elements.length;i++) {
                   2848:         if (document.rolechooser.elements[i].name == item) {
                   2849:             return i;
                   2850:         }
                   2851:     }
                   2852:     return -1;
                   2853: }
1.273     droeschl 2854: // ]]>
1.235     raeburn  2855: </script>
                   2856: END
                   2857: }
                   2858: 
1.350     raeburn  2859: sub required_privs {
                   2860:     my $privs =  {
1.457     raeburn  2861:              '/adm/parmset'      => 'opa,vpa',
                   2862:              '/adm/courseprefs'  => 'opa,vpa',
1.350     raeburn  2863:              '/adm/whatsnew'     => 'whn',
1.461     raeburn  2864:              '/adm/populate'     => 'cst,vpa,vcl',
1.350     raeburn  2865:              '/adm/trackstudent' => 'vsa',
1.457     raeburn  2866:              '/adm/statistics'   => 'mgr,vgr',
                   2867:              '/adm/setblock'     => 'dcm,vcb',
1.367     raeburn  2868:              '/adm/coursedocs'   => 'mdc',
1.350     raeburn  2869:            };
                   2870:     unless ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'spreadsheet') {
1.364     raeburn  2871:         $privs->{'/adm/classcalc'}   = 'vgr',
                   2872:         $privs->{'/adm/assesscalc'}  = 'vgr',
                   2873:         $privs->{'/adm/studentcalc'} = 'vgr';
1.350     raeburn  2874:     }
                   2875:     return $privs;
                   2876: }
1.235     raeburn  2877: 
1.378     raeburn  2878: sub countdown_timer {
                   2879:     if (($env{'request.course.id'}) && ($env{'request.symb'} ne '') &&
1.484     raeburn  2880:         (($env{'request.filename'}=~/$LONCAPA::assess_re/) ||
                   2881:          (($env{'request.symb'} =~ /ext\.tool$/) &&
                   2882:          (&Apache::lonnet::EXT('resource.0.gradable',$env{'request.symb'}) =~ /^yes$/i)))) {
1.387     raeburn  2883:         my ($type,$hastimeleft,$slothastime);
                   2884:         my $now = time;
                   2885:         if ($env{'request.filename'} =~ /\.task$/) {
                   2886:             $type = 'Task';
1.485     raeburn  2887:         } elsif ($env{'request.symb'} =~ /ext\.tool$/) {
                   2888:             $type = 'tool';
1.387     raeburn  2889:         } else {
                   2890:             $type = 'problem';
                   2891:         }
1.485     raeburn  2892:         my ($status,$accessmsg,$slot_name,$slot);
                   2893:         if ($type eq 'tool') {
                   2894:             ($status,$accessmsg,$slot_name,$slot) =
                   2895:                 &Apache::lonhomework::check_slot_access('0',$type,$env{'request.symb'},['0']);
                   2896:         } else {
                   2897:             ($status,$accessmsg,$slot_name,$slot) =
                   2898:                 &Apache::lonhomework::check_slot_access('0',$type);
                   2899:         }
1.387     raeburn  2900:         if ($slot_name ne '') {
                   2901:             if (ref($slot) eq 'HASH') {
                   2902:                 if (($slot->{'starttime'} < $now) &&
                   2903:                     ($slot->{'endtime'} > $now)) {
                   2904:                     $slothastime = 1;
                   2905:                 }
                   2906:             }
                   2907:         }
                   2908:         if ($status ne 'CAN_ANSWER') {
                   2909:             return;
                   2910:         }
1.378     raeburn  2911:         my $duedate = &Apache::lonnet::EXT("resource.0.duedate");
1.380     raeburn  2912:         my @interval=&Apache::lonnet::EXT("resource.0.interval");
1.448     raeburn  2913:         my ($timelimit,$usesdone,$donebuttontext,$proctor,$secret);
1.381     raeburn  2914:         if (@interval > 1) {
1.448     raeburn  2915:             ($timelimit,my $donesuffix) = split(/_/,$interval[0],2);
                   2916:             if ($donesuffix =~ /^done\:([^\:]+)\:(.*)$/) {
                   2917:                 $usesdone = 'done';
                   2918:                 $donebuttontext = $1;
                   2919:                 (undef,$proctor,$secret) = split(/_/,$2);
                   2920:             } elsif ($donesuffix =~ /^done(|_.+)$/) {
                   2921:                 $donebuttontext = &mt('Done');
                   2922:                 ($usesdone,$proctor,$secret) = split(/_/,$donesuffix);
                   2923:             }
1.381     raeburn  2924:             my $first_access=&Apache::lonnet::get_first_access($interval[1]);
                   2925:             if ($first_access > 0) {
1.437     raeburn  2926:                 if ($first_access+$timelimit > time) {
1.381     raeburn  2927:                     $hastimeleft = 1;
                   2928:                 }
                   2929:             }
                   2930:         }
1.380     raeburn  2931:         if (($duedate && $duedate > time) ||
1.387     raeburn  2932:             (!$duedate && $hastimeleft) ||
                   2933:             ($slot_name ne '' && $slothastime)) {
1.435     musolffc 2934:             my ($collapse,$expand,$alttxt,$title,$currdisp,$donebutton);
1.387     raeburn  2935:             if ((@interval > 1 && $hastimeleft) ||
                   2936:                 ($type eq 'Task' && $slothastime)) {
1.378     raeburn  2937:                 $currdisp = 'inline';
                   2938:                 $collapse = '&#9658;&nbsp;';
1.435     musolffc 2939:                 if ((@interval > 1) && ($hastimeleft)) {
1.437     raeburn  2940:                     if ($usesdone eq 'done') {
1.448     raeburn  2941:                         $donebutton = &done_button_js($interval[1],'','',$proctor,$donebuttontext);
1.437     raeburn  2942:                     }
1.435     musolffc 2943:                 }
1.378     raeburn  2944:             } else {
                   2945:                 $currdisp = 'none';
                   2946:                 $expand = '&#9668;&nbsp;';
                   2947:             }
                   2948:             unless ($env{'environment.icons'} eq 'iconsonly') {
1.379     raeburn  2949:                 $alttxt = &mt('Timer');
                   2950:                 $title = $alttxt.'&nbsp;';
1.378     raeburn  2951:             }
                   2952:             my $desc = &mt('Countdown to due date/time');
1.435     musolffc 2953: 
1.378     raeburn  2954:             return <<END;
1.435     musolffc 2955: $donebutton
1.378     raeburn  2956: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
                   2957: <span id="ddcountcollapse" class="LC_menubuttons_inline_text">
                   2958: $collapse
1.379     raeburn  2959: </span></a>
1.378     raeburn  2960: <span id="duedatecountdown" class="LC_menubuttons_inline_text" style="display: $currdisp;"></span>
                   2961: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
                   2962: <span id="ddcountexpand" class="LC_menubuttons_inline_text" >$expand</span>
1.379     raeburn  2963: <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  2964: END
                   2965:         }
                   2966:     }
                   2967:     return;
                   2968: }
                   2969: 
1.445     raeburn  2970: sub placement_progress {
                   2971:     my ($totalpoints,$incomplete) = &Apache::lonplacementtest::check_completion(undef,undef,1);
                   2972:     my $complete = 100 - $incomplete;
                   2973:     return '<span class="LC_placement_prog">'.
                   2974:            &mt('Test is [_1]% complete',$complete).'</span>';
                   2975: }
                   2976: 
1.2       www      2977: # ================================================================ Main Program
                   2978: 
1.16      harris41 2979: BEGIN {
1.166     albertel 2980:     if (! defined($readdesk)) {
1.283     droeschl 2981:         {
                   2982:             my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
                   2983:             if ( CORE::open( my $config,"<$tabfile") ) {
                   2984:                 while (my $configline=<$config>) {
                   2985:                     $configline=(split(/\#/,$configline))[0];
                   2986:                     $configline=~s/^\s+//;
                   2987:                     chomp($configline);
1.209     www      2988:                     if ($configline=~/^cat\:/) {
1.283     droeschl 2989:                         my @entries=split(/\:/,$configline);
                   2990:                         $category_positions{$entries[2]}=$entries[1];
                   2991:                         $category_names{$entries[2]}=$entries[3];
                   2992:                     } elsif ($configline=~/^prim\:/) {
1.415     raeburn  2993:                         my @entries = (split(/\:/, $configline))[1..6];
1.400     raeburn  2994:                         push(@primary_menu,\@entries);
1.371     raeburn  2995:                     } elsif ($configline=~/^primsub\:/) {
                   2996:                         my ($parent,@entries) = (split(/\:/, $configline))[1..4];
1.400     raeburn  2997:                         push(@{$primary_submenu{$parent}},\@entries);
1.283     droeschl 2998:                     } elsif ($configline=~/^scnd\:/) {
                   2999:                         my @entries = (split(/\:/, $configline))[1..5];
1.401     raeburn  3000:                         push(@secondary_menu,\@entries);
1.482     raeburn  3001:                     } elsif ($configline=~/^scndsub\:/) {
                   3002:                         my ($parent,@entries) = (split(/\:/, $configline))[1..4];
                   3003:                         push(@{$secondary_submenu{$parent}},\@entries);
1.283     droeschl 3004:                     } elsif ($configline) {
                   3005:                         push(@desklines,$configline);
                   3006:                     }
                   3007:                 }
                   3008:                 CORE::close($config);
                   3009:             }
                   3010:         }
                   3011:         $readdesk='done';
1.2       www      3012:     }
                   3013: }
1.30      www      3014: 
1.1       www      3015: 1;
                   3016: __END__
                   3017: 

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