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

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

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