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

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

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