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

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

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