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

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

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