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

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

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