File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.431.2.3: download - view: text, annotated - select for diffs
Tue May 26 13:25:43 2015 UTC (9 years ago) by raeburn
Branches: version_2_11_donebutton
"Done" button (allows student to end his/her access to a timed (interval)
quiz.
  - Name spacing
  - Localization
  - Support interval set either for resource or map.
  - Move button to left of countdown timer to make it standout a little more.

    1: # The LearningOnline Network with CAPA
    2: # Routines to control the menu
    3: #
    4: # $Id: lonmenu.pm,v 1.431.2.3 2015/05/26 13:25:43 raeburn Exp $
    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: #
   28: #
   29: 
   30: =head1 NAME
   31: 
   32: Apache::lonmenu
   33: 
   34: =head1 SYNOPSIS
   35: 
   36: Loads contents of /home/httpd/lonTabs/mydesk.tab, 
   37: used to generate inline menu, and Main Menu page. 
   38: 
   39: This is part of the LearningOnline Network with CAPA project
   40: described at http://www.lon-capa.org.
   41: 
   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
   76: of those lines of mydesk.tab that start with prim:.
   77: It is used by primary_menu() to generate the corresponding menu.
   78: It gets filled in the BEGIN block of this module.
   79: 
   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: 
   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: 
   98: =head1 SUBROUTINES
   99: 
  100: =over
  101: 
  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: 
  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 
  112: @primary_menu is filled within the BEGIN block of this module with 
  113: entries from mydesk.tab
  114: 
  115: =item secondary_menu()
  116: 
  117: Same as primary_menu() but operates on @secondary_menu.
  118: 
  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: 
  127: Inputs: 4 - (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: 
  131:  The underlying datastructure used in (d) contains data from mydesk.tab.
  132:  It consists of an array which has an array for each item appearing in
  133:  the menu (e.g. [["link", "title", "condition"]] for a single-item menu).
  134:  create_submenu() supports also the creation of XHTML for nested dropdown
  135:  menus represented by unordered lists. This is done by replacing the
  136:  scalar used for the link with an arrayreference containing the menuitems
  137:  for the nested menu. This can be done recursively so that the next menu
  138:  may also contain nested submenus.
  139: 
  140:  Example:
  141:  [											# begin of datastructure
  142: 	["/home/", "Home", "condition1"], 		# 1st item of the 1st layer menu
  143: 	[										# 2nd item of the 1st layer menu
  144: 		[									# anon. array for nested menu
  145: 			["/path1", "Path1", undef], 	# 1st item of the 2nd layer menu
  146: 			["/path2", "Path2", undef], 	# 2nd item of the 2nd layer menu
  147: 			[								# 3rd item of the 2nd layer menu
  148: 				[[...], [...], ..., [...]],	# containing another menu layer
  149: 				"Sub-Sub-Menu",				# title for this container
  150: 				undef
  151: 			]
  152: 		],									# end of array/nested menu
  153: 		"Sub-Menu",							# title for the container item
  154: 		undef
  155: 	]										# end of 2nd item of the 1st layer menu
  156: ]
  157: 
  158: =item innerregister()
  159: 
  160: This gets called in order to register a URL in the body of the document
  161: 
  162: =item clear()
  163: 
  164: =item switch()
  165: 
  166: Switch a button or create a link
  167: Switch acts on the javascript that is executed when a button is clicked.  
  168: The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
  169: 
  170: =item secondlevel()
  171: 
  172: =item openmenu()
  173: 
  174: =item inlinemenu()
  175: 
  176: =item rawconfig()
  177: 
  178: =item utilityfunctions()
  179: 
  180: Output from this routine is a number of javascript functions called by
  181: items in the inline menu, and in some cases items in the Main Menu page. 
  182: 
  183: =item serverform()
  184: 
  185: =item constspaceform()
  186: 
  187: =item get_nav_status()
  188: 
  189: =item hidden_button_check()
  190: 
  191: =item roles_selector()
  192: 
  193: =item jump_to_role()
  194: 
  195: =back
  196: 
  197: =cut
  198: 
  199: package Apache::lonmenu;
  200: 
  201: use strict;
  202: use Apache::lonnet;
  203: use Apache::lonhtmlcommon();
  204: use Apache::loncommon();
  205: use Apache::lonenc();
  206: use Apache::lonlocal;
  207: use Apache::lonmsg();
  208: use LONCAPA qw(:DEFAULT :match);
  209: use HTML::Entities();
  210: use Apache::lonwishlist();
  211: 
  212: use vars qw(@desklines %category_names %category_members %category_positions 
  213:             $readdesk @primary_menu %primary_submenu @secondary_menu);
  214: 
  215: my @inlineremote;
  216: 
  217: sub prep_menuitem {
  218:     my ($menuitem) = @_;
  219:     return '' unless(ref($menuitem) eq 'ARRAY');
  220:     my $link;
  221:     if ($$menuitem[1]) { # graphical Link
  222:         $link = "<img class=\"LC_noBorder\""
  223:               . " src=\"" . &Apache::loncommon::lonhttpdurl($$menuitem[1]) . "\"" 
  224:               . " alt=\"" . &mt($$menuitem[2]) . "\" />";
  225:     } else {             # textual Link
  226:         $link = &mt($$menuitem[3]);
  227:     }
  228:     return '<li><a' 
  229:            # highlighting for new messages
  230:            . ( $$menuitem[4] eq 'newmsg' ? ' class="LC_new_message"' : '') 
  231:            . qq| href="$$menuitem[0]" target="_top">$link</a></li>|;
  232: }
  233: 
  234: # primary_menu() evaluates @primary_menu and returns a two item array,
  235: # with the array elements containing XHTML for the left and right sides of 
  236: # the menu that contains the following links:
  237: # Personal, About, Message, Roles, Help, Logout
  238: # @primary_menu is filled within the BEGIN block of this module with 
  239: # entries from mydesk.tab
  240: sub primary_menu {
  241:     my (%menu);
  242:     # each element of @primary contains following array:
  243:     # (link url, icon path, alt text, link text, condition, position)
  244:     my $public;
  245:     if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
  246:         || (($env{'user.name'} eq '') && ($env{'user.domain'} eq ''))) {
  247:         $public = 1;
  248:     }
  249:     foreach my $menuitem (@primary_menu) {
  250:         # evaluate conditions 
  251:         next if    ref($menuitem)       ne 'ARRAY';    #
  252:         next if    $$menuitem[4]        eq 'nonewmsg'  # show links depending on
  253:                 && &Apache::lonmsg::mynewmail();       # whether a new msg 
  254:         next if    $$menuitem[4]        eq 'newmsg'    # arrived or not
  255:                 && !&Apache::lonmsg::mynewmail();      # 
  256:         next if    $$menuitem[4]        !~ /public/    ##we've a public user,
  257:                 && $public;                            ##who should not see all
  258:                                                        ##links
  259:         next if    $$menuitem[4]        eq 'onlypublic'# hide links which are 
  260:                 && !$public;                           # only visible to public
  261:                                                        # users
  262:         next if    $$menuitem[4]        eq 'roles'     ##show links depending on
  263:                 && &Apache::loncommon::show_course();  ##term 'Courses' or 
  264:         next if    $$menuitem[4]        eq 'courses'   ##'Roles' wanted
  265:                 && !&Apache::loncommon::show_course(); ##
  266:         
  267:         my $title = $menuitem->[3];
  268:         my $position = $menuitem->[5];
  269:         if ($position eq '') {
  270:             $position = 'right';
  271:         }
  272:         if (defined($primary_submenu{$title})) {
  273:             my ($link,$target);
  274:             if ($menuitem->[0] ne '') {
  275:                 $link = $menuitem->[0];
  276:                 $target = '_top';
  277:             } else {
  278:                 $link = '#';
  279:             }
  280:             my @primsub;
  281:             if (ref($primary_submenu{$title}) eq 'ARRAY') {
  282:                 foreach my $item (@{$primary_submenu{$title}}) {
  283:                     next if (($item->[2] eq 'wishlist') && (!$env{'user.adv'}));
  284:                     next if ((($item->[2] eq 'portfolio') ||
  285:                              ($item->[2] eq 'blog')) &&
  286:                              (!&Apache::lonnet::usertools_access('','',$item->[2],
  287:                                                            undef,'tools')));
  288:                     push(@primsub,$item);
  289:                 }
  290:                 if (@primsub > 0) {
  291:                     $menu{$position} .= &create_submenu($link,$target,$title,\@primsub,1);
  292:                 } elsif ($link) {
  293:                     $menu{$position} .= '<li><a href="'.$link.'" target="'.$target.'">'.&mt($title).'</a></li>';
  294:                 }
  295:             }
  296:         } elsif ($$menuitem[3] eq 'Help') { # special treatment for helplink
  297:             if ($public) {
  298:                 my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
  299:                 my $defdom = &Apache::lonnet::default_login_domain();
  300:                 my $to = &Apache::loncommon::build_recipient_list(undef,
  301:                                                                   'helpdeskmail',
  302:                                                                   $defdom,$origmail);
  303:                 if ($to ne '') {
  304:                     $menu{$position} .= &prep_menuitem($menuitem); 
  305:                 }
  306:             } else {
  307:                 $menu{$position} .= '<li>'.&Apache::loncommon::top_nav_help('Help').'</li>';
  308:             }
  309:         } else {
  310:             $menu{$position} .= prep_menuitem($menuitem);
  311:         }
  312:     }
  313:     my @output = ('','');
  314:     if ($menu{'left'} ne '') {
  315:         $output[0] = "<ol class=\"LC_primary_menu LC_floatleft\">$menu{'left'}</ol>";
  316:     }
  317:     if ($menu{'right'} ne '') {
  318:         $output[1] = "<ol class=\"LC_primary_menu LC_floatright LC_right\">$menu{'right'}</ol>";
  319:     }
  320:     return @output;
  321: }
  322: 
  323: #returns hashref {user=>'',dom=>''} containing:
  324: #   own name, domain if user is au
  325: #   name, domain of parent author if user is ca or aa
  326: #empty return if user is not an author or not on homeserver
  327: #
  328: #TODO this should probably be moved somewhere more central
  329: #since it can be used by different parts of the system
  330: sub getauthor{
  331:     return unless $env{'request.role'}=~/^(ca|aa|au)/; #nothing to do if user isn't some kind of author
  332: 
  333:                         #co- or assistent author?
  334:     my ($dom, $user) = ($env{'request.role'} =~ /^(?:ca|aa)\.\/($match_domain)\/($match_username)$/)
  335:                        ? ($1, $2) #domain, username of the parent author
  336:                        : @env{ ('request.role.domain', 'user.name') }; #own domain, username
  337: 
  338:     # current server == home server?
  339:     my $home =  &Apache::lonnet::homeserver($user,$dom);
  340:     foreach (&Apache::lonnet::current_machine_ids()){
  341:         return {user => $user, dom => $dom} if $_ eq $home;
  342:     }
  343: 
  344:     # if wrong server
  345:     return;
  346: }
  347: 
  348: sub secondary_menu {
  349:     my ($httphost) = @_;
  350:     my $menu;
  351: 
  352:     my $crstype = &Apache::loncommon::course_type();
  353:     my $crs_sec = $env{'request.course.id'} . ($env{'request.course.sec'} 
  354:                                                ? "/$env{'request.course.sec'}"
  355:                                                : '');
  356:     my $canedit       = &Apache::lonnet::allowed('mdc', $env{'request.course.id'});
  357:     my $canviewroster = $env{'course.'.$env{'request.course.id'}.'.student_classlist_view'};
  358:     if ($canviewroster eq 'disabled') {
  359:         undef($canviewroster);
  360:     }
  361:     my $canviewgrps   = &Apache::lonnet::allowed('vcg', $crs_sec); 
  362:     my $canmodifyuser = &Apache::lonnet::allowed('cst', $crs_sec); 
  363:     my $canviewwnew   = &Apache::lonnet::allowed('whn', $crs_sec); 
  364:     my $canmodpara    = &Apache::lonnet::allowed('opa', $crs_sec);
  365:     my $canvgr        = &Apache::lonnet::allowed('vgr', $crs_sec);
  366:     my $canmgr        = &Apache::lonnet::allowed('mgr', $crs_sec); 
  367:     my $author        = &getauthor();
  368: 
  369:     my ($cdom,$cnum,$showsyllabus,$showfeeds,$showresv);
  370:     if ($env{'request.course.id'}) {
  371:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  372:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
  373:         if ($canedit) {
  374:             $showsyllabus = 1;
  375:             $showfeeds = 1;
  376:         } else {
  377:             unless (&Apache::lonnet::is_on_map("public/$cdom/$cnum/syllabus")) {
  378:                 if (($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'}) ||
  379:                     ($env{'course.'.$env{'request.course.id'}.'.uploadedsyllabus'}) ||
  380:                     ($env{'course.'.$env{'request.course.id'}.'.updatedsyllabus'}) ||
  381:                     ($env{'request.course.syllabustime'})) {
  382:                     $showsyllabus = 1;
  383:                 }
  384:             }
  385:             if ($env{'request.course.feeds'}) {
  386:                 $showfeeds = 1;
  387:             }
  388:         }
  389:         unless ($canmgr) {
  390:             my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
  391:             if (keys(%slots) > 0) {
  392:                 $showresv = 1;
  393:             }
  394:         }
  395:     }
  396: 
  397:     my ($canmodifycoauthor); 
  398:     if ($env{'request.role'} eq "au./$env{'user.domain'}/") {
  399:         my $extent = "$env{'user.domain'}/$env{'user.name'}";
  400:         if ((&Apache::lonnet::allowed('cca',$extent)) ||
  401:             (&Apache::lonnet::allowed('caa',$extent))) {
  402:             $canmodifycoauthor = 1;
  403:         }
  404:     }
  405: 
  406:     my %groups = &Apache::lonnet::get_active_groups(
  407:                      $env{'user.domain'}, $env{'user.name'},
  408:                      $env{'course.' . $env{'request.course.id'} . '.domain'},
  409:                      $env{'course.' . $env{'request.course.id'} . '.num'});
  410: 
  411:     my ($roleswitcher_js,$roleswitcher_form);
  412: 
  413:     foreach my $menuitem (@secondary_menu) {
  414:         # evaluate conditions 
  415:         next if    ref($menuitem)  ne 'ARRAY';
  416:         next if    $$menuitem[4]   ne 'always'
  417:                 && ($$menuitem[4]   ne 'author' && $$menuitem[4] ne 'cca')
  418:                 && !$env{'request.course.id'};
  419:         next if    $$menuitem[4]   =~ /^mdc/
  420:                 && !$canedit;
  421:         next if    $$menuitem[4]  eq 'nvgr'
  422:                 && $canvgr;
  423:         next if    $$menuitem[4]  eq 'vgr'
  424:                 && !$canvgr;
  425:         next if    $$menuitem[4]   eq 'cst'
  426:                 && !$canmodifyuser;
  427:         next if    $$menuitem[4]   eq 'ncst'
  428:                 && ($canmodifyuser || !$canviewroster);
  429:         next if    $$menuitem[4]   eq 'mgr'
  430:                 && !$canmgr;
  431:         next if    $$menuitem[4]   eq 'showresv'
  432:                 && !$showresv;
  433:         next if    $$menuitem[4]   eq 'whn'
  434:                 && !$canviewwnew;
  435:         next if    $$menuitem[4]   eq 'opa'
  436:                 && !$canmodpara;
  437:         next if    $$menuitem[4]   =~ /showgroups$/
  438:                 && !$canviewgrps
  439:                 && !%groups;
  440:         next if    $$menuitem[4]   eq 'showsyllabus'
  441:                 && !$showsyllabus;
  442:         next if    $$menuitem[4]   eq 'showfeeds'
  443:                 && !$showfeeds;
  444:         next if    $$menuitem[4]    eq 'author'
  445:                 && !$author;
  446:         next if    $$menuitem[4]    eq 'cca'
  447:                 && !$canmodifycoauthor;
  448: 
  449:         if ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) {
  450:             # special treatment for role selector
  451:             ($roleswitcher_js,$roleswitcher_form,my $switcher) =
  452:                 &roles_selector(
  453:                         $env{'course.' . $env{'request.course.id'} . '.domain'},
  454:                         $env{'course.' . $env{'request.course.id'} . '.num'},
  455:                         $httphost
  456:                 );
  457:             $menu .= $switcher;
  458:         } else {
  459:             if ($$menuitem[3] eq 'Syllabus' && $env{'request.course.id'}) {
  460:                 my $url = $$menuitem[0];
  461:                 $url =~ s{\[cdom\]/\[cnum\]}{$cdom/$cnum};
  462:                 if (&Apache::lonnet::is_on_map($url)) {
  463:                     unless ($$menuitem[0] =~ /\?register=1/) {
  464:                         $$menuitem[0] .= '?register=1';
  465:                     }
  466:                 } else {
  467:                     $$menuitem[0] =~ s{\?register=1}{};
  468:                 }
  469:             }
  470:             $menu .= &prep_menuitem(\@$menuitem);
  471:         }
  472:     }
  473:     if ($menu =~ /\[url\].*\[symb\]/) {
  474:         my $escurl  = &escape( &Apache::lonenc::check_encrypt(
  475:                              $env{'request.noversionuri'}));
  476: 
  477:         my $escsymb = &escape( &Apache::lonenc::check_encrypt(
  478:                              $env{'request.symb'})); 
  479: 
  480:         if (    $env{'request.state'} eq 'construct'
  481:             and (   $env{'request.noversionuri'} eq '' 
  482:                  || !defined($env{'request.noversionuri'}))) 
  483:         {
  484:             my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
  485:             ($escurl = $env{'request.filename'}) =~ s{^\Q$londocroot\E}{};
  486:             $escurl  = &escape($escurl);
  487:         }    
  488:         $menu =~ s/\[url\]/$escurl/g;
  489:         $menu =~ s/\[symb\]/$escsymb/g;
  490:     }
  491:     $menu =~ s/\[uname\]/$$author{user}/g;
  492:     $menu =~ s/\[udom\]/$$author{dom}/g;
  493:     if ($showsyllabus || $showfeeds) {
  494:         $menu =~ s/\[cnum\]/$cnum/g;
  495:         $menu =~ s/\[cdom\]/$cdom/g;
  496:     }
  497:     if ($menu) {
  498:         $menu = "<ul id=\"LC_secondary_menu\">$menu</ul>";
  499:     }
  500:     if ($roleswitcher_form) {
  501:         $menu .= "\n$roleswitcher_js\n$roleswitcher_form";
  502:     }
  503:     return $menu;
  504: }
  505: 
  506: sub create_submenu {
  507:     my ($link,$target,$title,$submenu,$translate) = @_;
  508:     return unless (ref($submenu) eq 'ARRAY');
  509:     my $disptarget;
  510:     if ($target ne '') {
  511:         $disptarget = ' target="'.$target.'"';
  512:     }
  513:     my $name;
  514:     if ($title eq 'Personal') {
  515:         if ($env{'user.name'} && $env{'user.domain'}) {
  516:             $name = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'});
  517:         } else {
  518:             $name = &mt($title);
  519:         }
  520:     } else {
  521:         $name = &mt($title);
  522:     }
  523:     my $menu = '<li class="LC_hoverable">'.
  524:                '<a href="'.$link.'"'.$disptarget.'>'.
  525:                '<span class="LC_nobreak">'.$name.
  526:                '<span class="LC_fontsize_small" style="font-weight:normal;">'.
  527:                ' &#9660;</span></span></a>'.
  528:                '<ul>';
  529: 
  530:     # $link and $title are only used in the initial string written in $menu
  531:     # as seen above, not needed for nested submenus
  532:     $menu .= &build_submenu($target, $submenu, $translate, '1');
  533:     $menu .= '</ul></li>';
  534: 
  535:     return $menu;
  536: }
  537: 
  538: # helper routine for create_submenu
  539: # build the dropdown (and nested submenus) recursively
  540: # see perldoc create_submenu documentation for further information
  541: sub build_submenu {
  542:     my ($target, $submenu, $translate, $first_level) = @_; 
  543:     if (!defined(@{$submenu})) {
  544:         return '';
  545:     }
  546: 
  547:     my $menu = '';
  548:     my $count = 0;
  549:     my $numsub = scalar(@{$submenu});
  550:     foreach my $item (@{$submenu}) {
  551:         $count ++;
  552:         if (ref($item) eq 'ARRAY') {
  553:             my $href = $item->[0];
  554:             my $bordertop;
  555:             my $borderbot;
  556:             my $title;
  557: 
  558:             if ($translate) {
  559:                  $title = &mt($item->[1]);
  560:             } else {
  561:                 $title = $item->[1];
  562:             }
  563: 
  564:             if ($count == 1 && !$first_level) {
  565:                 $bordertop = 'border-top: 1px solid black;';
  566:             }
  567:             if ($count == $numsub) {
  568:                 $borderbot = 'border-bottom: 1px solid black;';
  569:             }
  570: 
  571:             # href is a reference to another submenu
  572:             if (ref($href) eq 'ARRAY') {
  573:                 $menu .= '<li style="margin:0;padding:0;'.$bordertop . $borderbot . '">';
  574:                 $menu .= '<p><span class="LC_primary_menu_innertitle">'
  575: 					. $title . '</span><span class="LC_primary_menu_innerarrow">&#9654;</span></p>';
  576:                 $menu .= '<ul>';
  577:                 $menu .= &build_submenu($target, $href, $translate);
  578:                 $menu .= '</ul>';
  579:                 $menu .= '</li>';    
  580:             } else {    # href is the actual hyperlink and does not represent another submenu
  581:                         # for the current menu title
  582:                 if ($href =~ /(aboutme|rss\.html)$/) {
  583:                     next unless (($env{'user.name'} ne '') && ($env{'user.domain'} ne ''));
  584:                     $href =~ s/\[domain\]/$env{'user.domain'}/g;
  585:                     $href =~ s/\[user\]/$env{'user.name'}/g;
  586:                 }
  587:                 unless (($href eq '') || ($href =~ /^\#/)) {
  588:                     $target = ' target="_top"';
  589:                 }
  590: 
  591:                 $menu .= '<li style="margin:0;padding:0;'. $bordertop . $borderbot .'">';
  592:                 $menu .= '<a href="'.$href.'"'.$target.'>' .  $title . '</a>';
  593:                 $menu .= '</li>';
  594:             }
  595:         }
  596:     }
  597:     return $menu;
  598: }
  599: 
  600: sub innerregister {
  601:     my ($forcereg,$bread_crumbs,$group) = @_;
  602:     my $const_space = ($env{'request.state'} eq 'construct');
  603:     my $is_const_dir = 0;
  604: 
  605:     if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
  606: 
  607:     $env{'request.registered'} = 1;
  608: 
  609:     undef(@inlineremote);
  610: 
  611:     my ($mapurl,$resurl);
  612: 
  613:     if ($env{'request.course.id'}) {
  614:         if ($env{'request.symb'}) {
  615:             ($mapurl, my $rid, $resurl) = &Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
  616:             my $coursetitle = $env{'course.'.$env{'request.course.id'}.'.description'};
  617: 
  618:             my $maptitle = &Apache::lonnet::gettitle($mapurl);
  619:             my $restitle = &Apache::lonnet::gettitle(&Apache::lonnet::symbread());
  620: 
  621: #SD
  622: #course_type only Course and Community?
  623: #
  624:             my @crumbs;
  625:             unless (($forcereg) &&
  626:                     ($env{'request.noversionuri'} eq '/adm/navmaps') &&
  627:                     ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'})) {
  628:                 @crumbs = ({text  => Apache::loncommon::course_type() 
  629:                                     . ' Contents', 
  630:                             href  => "Javascript:gopost('/adm/navmaps','')"});
  631:             }
  632:             if ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) { 
  633:                 push(@crumbs, {text  => '...',
  634:                                no_mt => 1});
  635:             }
  636: 
  637:             push @crumbs, {text => $maptitle, no_mt => 1} if ($maptitle 
  638:                                                        && $maptitle ne 'default.sequence' 
  639:                                                        && $maptitle ne $coursetitle);
  640: 
  641:             push @crumbs, {text => $restitle, no_mt => 1} if $restitle; 
  642:             &Apache::lonhtmlcommon::clear_breadcrumbs();
  643:             &Apache::lonhtmlcommon::add_breadcrumb(@crumbs);
  644:         } else {
  645:             $resurl = $env{'request.noversionuri'};
  646:             my $courseurl = &Apache::lonnet::courseid_to_courseurl($env{'request.course.id'});
  647:             my $crstype = &Apache::loncommon::course_type();
  648:             my $title = &mt('View Resource');
  649:             if ($resurl =~ m{^\Q/uploaded$courseurl/supplemental/\E(default|\d+)/}) {
  650:                 &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folderpath','title']);
  651:                 &Apache::lonhtmlcommon::clear_breadcrumbs();
  652:                 if ($env{'form.title'}) {
  653:                     $title = $env{'form.title'};
  654:                 }
  655:                 my $trail;
  656:                 if ($env{'form.folderpath'}) {
  657:                     &prepare_functions($resurl,$forcereg,$group,undef,undef,1);
  658:                     ($trail) =
  659:                         &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
  660:                 } else {
  661:                     &Apache::lonhtmlcommon::add_breadcrumb(
  662:                     {text  => "Supplemental $crstype Content",
  663:                      href  => "javascript:gopost('/adm/supplemental','')"});
  664:                     $title = &mt('View Resource');
  665:                     ($trail) = 
  666:                         &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
  667:                 }
  668:                 return $trail;
  669:             } elsif ($resurl =~ m{^\Q/uploaded$courseurl/portfolio/syllabus/}) {
  670:                 &Apache::lonhtmlcommon::clear_breadcrumbs();
  671:                 &prepare_functions('/public'.$courseurl."/syllabus",
  672:                                    $forcereg,$group,undef,undef,1);
  673:                 $title = &mt('Syllabus File');
  674:                 my ($trail) =
  675:                     &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
  676:                 return $trail;
  677:             }
  678:             unless ($env{'request.state'} eq 'construct') {
  679:                 &Apache::lonhtmlcommon::clear_breadcrumbs();
  680:                 &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
  681:             }
  682:         }
  683:     } elsif (! $const_space){
  684:         #a situation when we're looking at a resource outside of context of a 
  685:         #course or construction space (e.g. with cumulative rights)
  686:         &Apache::lonhtmlcommon::clear_breadcrumbs();
  687:         unless ($env{'request.noversionuri'} =~ m{^/adm/$match_domain/$match_username/aboutme$}) {
  688:             &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
  689:         }
  690:     }
  691: # =============================================================================
  692: # ============================ This is for URLs that actually can be registered
  693:     return '' unless ( ($env{'request.noversionuri'}!~m{^/(res/)*adm/}) 
  694:                        || $forcereg );
  695:     my ($cdom,$cnum,%perms,$cfile,$switchserver,$home,$forceedit,
  696:         $forceview,$editbutton);
  697:     if (($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) ||
  698:         ($env{'request.role'} !~/^(aa|ca|au)/)) {
  699:         $editbutton = &prepare_functions($resurl,$forcereg,$group);
  700:     }
  701:     if ($editbutton eq '') {
  702:         $editbutton = &clear(6,1);
  703:     }
  704: 
  705: #
  706: # This applies in course context
  707: #
  708:     if ($env{'request.course.id'}) {
  709:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
  710:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  711:         $perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
  712:         my @privs;
  713:         if ($env{'request.symb'} ne '') {
  714:              if ($env{'request.filename'}=~/$LONCAPA::assess_re/) {
  715:                  push(@privs,('mgr','vgr'));
  716:              }
  717:              push(@privs,'opa');
  718:         }
  719:         foreach my $priv (@privs) {
  720:             $perms{$priv} = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
  721:             if (!$perms{$priv} && $env{'request.course.sec'} ne '') {
  722:                 $perms{$priv} = 
  723:                     &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
  724:             }
  725:         }
  726: #
  727: # Determine whether or not to show Grades and Submissions buttons
  728: #
  729:         if ($env{'request.symb'} ne '' &&
  730:             $env{'request.filename'}=~/$LONCAPA::assess_re/) {
  731:             if ($perms{'mgr'}) {
  732:                 &switch('','',7,2,'pgrd.png','Content Grades','grades[_4]',
  733:                         "gocmd('/adm/grades','gradingmenu')",
  734:                         'Content Grades');
  735:             } elsif ($perms{'vgr'}) {
  736:                 &switch('','',7,2,'subm.png','Content Submissions','missions[_1]',
  737:                         "gocmd('/adm/grades','submission')",
  738:                         'Content Submissions');
  739:              }
  740:         }
  741:         if (($env{'request.symb'} ne '') && ($perms{'opa'})) {
  742:             &switch('','',7,3,'pparm.png','Content Settings','parms[_2]',
  743:                     "gocmd('/adm/parmset','set')",
  744:                     'Content Settings');
  745: 	}
  746: # End grades/submissions check
  747: 
  748: #
  749: # This applies to items inside a folder/page modifiable in the course.
  750: #
  751:         if (($env{'request.symb'}=~/^uploaded/) && ($perms{'mdc'})) {
  752:             my $text = 'Edit Folder';
  753:             if (($mapurl =~ /\.page$/) ||
  754:                 ($env{'request.symb'}=~
  755:                      m{uploaded/$cdom/$cnum/default_\d+\.page$}))  {
  756:                 $text = 'Edit Page';
  757:             }
  758:             &switch('','',7,4,'docs-22x22.png',$text,'parms[_2]',
  759:                     "gocmd('/adm/coursedocs','direct')",
  760:                     'Folder/Page Content');
  761:         }
  762: # End modifiable folder/page container check
  763:     }
  764: # End course context
  765: 
  766: # Prepare the rest of the buttons
  767:         my ($menuitems,$got_prt,$got_wishlist);
  768:         if ($const_space) {
  769: #
  770: # We are in construction space
  771: #
  772: 
  773:             my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
  774: 	    my ($udom,$uname,$thisdisfn) =
  775: 		($env{'request.filename'}=~m{^\Q$londocroot/priv/\E([^/]+)/([^/]+)/(.*)$});
  776:             my $currdir = '/priv/'.$udom.'/'.$uname.'/'.$thisdisfn;
  777:             if ($currdir =~ m-/$-) {
  778:                 $is_const_dir = 1;
  779:             } else {
  780:                 $currdir =~ s|[^/]+$||;
  781: 		my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn);
  782: 		my $esc_currdir = &Apache::loncommon::escape_single($currdir);
  783: #
  784: # Probably should be in mydesk.tab
  785: #
  786:                 $menuitems=(<<ENDMENUITEMS);
  787: s&6&1&list.png&Directory&dir[_1]&golist('$esc_currdir')&List current directory
  788: s&6&2&rtrv.png&Retrieve&version[_1]&gocstr('/adm/retrieve','/priv/$udom/$uname/$cleandisfn')&Retrieve old version
  789: s&6&3&pub.png&Publish&resource[_3]&gocstr('/adm/publish','/priv/$udom/$uname/$cleandisfn')&Publish this resource
  790: s&7&1&del.png&Delete&resource[_2]&gocstr('/adm/cfile?action=delete','/priv/$udom/$uname/$cleandisfn')&Delete this resource
  791: s&7&2&prt.png&Print&printout[_1]&gocstr('/adm/printout','/priv/$udom/$uname/$cleandisfn')&Prepare a printable document
  792: ENDMENUITEMS
  793:             }
  794:                 if (ref($bread_crumbs) eq 'ARRAY') {
  795:                     &Apache::lonhtmlcommon::clear_breadcrumbs();
  796:                     foreach my $crumb (@{$bread_crumbs}){
  797:                         &Apache::lonhtmlcommon::add_breadcrumb($crumb);
  798:                     }
  799:                 }
  800:         } elsif ( defined($env{'request.course.id'}) && 
  801: 		 $env{'request.symb'} ne '' ) {
  802: #
  803: # We are in a course and looking at a registered URL
  804: # Should probably be in mydesk.tab
  805: #
  806: 	    $menuitems=(<<ENDMENUITEMS);
  807: c&3&1
  808: s&2&1&back.png&&&gopost('/adm/flip','back:'+currentURL)&Previous content resource&&1
  809: s&2&3&forw.png&&&gopost('/adm/flip','forward:'+currentURL)&Next content resource&&3
  810: c&6&3
  811: c&8&1
  812: c&8&2
  813: s&8&3&prt.png&Print&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
  814: ENDMENUITEMS
  815:             $got_prt = 1;
  816:             if (($env{'user.adv'}) && ($env{'request.uri'} =~ /^\/res/)
  817:                 && (!$env{'request.enc'})) {
  818:                 # wishlist is only available for users with access to resource-pool
  819:                 # and links can only be set for resources within the resource-pool
  820:                 $menuitems .= (<<ENDMENUITEMS);
  821: 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
  822: ENDMENUITEMS
  823:                 $got_wishlist = 1;
  824:             }
  825: 
  826: my $currentURL = &Apache::loncommon::get_symb();
  827: my ($symb_old,$symb_old_enc) = &Apache::loncommon::clean_symb($currentURL);
  828: my $annotation = &Apache::loncommon::get_annotation($symb_old,$symb_old_enc);
  829: $menuitems.="s&9&3&";
  830: if(length($annotation) > 0){
  831: 	$menuitems.="anot2.png";
  832: }else{
  833: 	$menuitems.="anot.png";
  834: }
  835: $menuitems.="&Notes&&annotate()&";
  836: $menuitems.="Make notes and annotations about this resource&&1\n";
  837: my $is_mobile;
  838: if ($env{'browser.mobile'}) {
  839:     $is_mobile = 1;
  840: }
  841: 
  842:             unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|viewclasslist|portfolio)(\?|$)/) {
  843: 		if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/}) && ($env{'request.noversionuri'} !~ m{^/uploaded/$match_domain/$match_courseid/docs/})) {
  844: 		    $menuitems.=(<<ENDREALRES);
  845: s&6&3&catalog.png&Info&info[_1]&catalog_info('$is_mobile')&Show Metadata
  846: ENDREALRES
  847:                 }
  848:                 unless (($env{'request.noversionuri'} =~ m{^/uploaded/$match_domain/$match_courseid/docs/}) ||
  849:                         ($env{'request.noversionuri'} =~ m{^\Q/adm/wrapper/\E(ext|uploaded)/})) {  
  850:                     $menuitems.=(<<ENDREALRES);
  851: s&8&1&eval.png&Evaluate&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
  852: ENDREALRES
  853:                 }
  854:                 unless ($env{'request.noversionuri'} =~ m{^\Q/adm/wrapper/\E(ext|uploaded)/}) {
  855:                     $menuitems.=(<<ENDREALRES);
  856: 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
  857: ENDREALRES
  858:                 }
  859: 	    }
  860:         }
  861: 	if ($env{'request.uri'} =~ /^\/res/) {
  862:             unless ($got_prt) {
  863: 	        $menuitems .= (<<ENDMENUITEMS);
  864: s&8&3&prt.png&Print&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
  865: ENDMENUITEMS
  866:                 $got_prt = 1;
  867:             }
  868:             unless ($got_wishlist) {
  869:                 if (($env{'user.adv'}) && (!$env{'request.enc'})) {
  870:                     # wishlist is only available for users with access to resource-pool
  871:                     $menuitems .= (<<ENDMENUITEMS);
  872: 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
  873: ENDMENUITEMS
  874:                     $got_wishlist = 1;
  875:                 }
  876: 	    }
  877:         }
  878:         my $buttons='';
  879:         foreach (split(/\n/,$menuitems)) {
  880: 	    my ($command,@rest)=split(/\&/,$_);
  881:             my $idx=10*$rest[0]+$rest[1];
  882:             if (&hidden_button_check() eq 'yes') {
  883:                 if ($idx == 21 ||$idx == 23) {
  884:                     $buttons.=&switch('','',@rest);
  885:                 } else {
  886:                     $buttons.=&clear(@rest);
  887:                 }
  888:             } else {  
  889:                 if ($command eq 's') {
  890: 	            $buttons.=&switch('','',@rest);
  891:                 } else {
  892:                     $buttons.=&clear(@rest);
  893:                 }
  894:             }
  895:         }
  896: 
  897: 	    my $addremote=0;
  898: 	    foreach (@inlineremote) { if ($_ ne '') { $addremote=1; last;} }
  899:     if ($addremote) {
  900: 
  901:         &Apache::lonhtmlcommon::clear_breadcrumb_tools();
  902: 
  903:             &Apache::lonhtmlcommon::add_breadcrumb_tool(
  904:                 'navigation', @inlineremote[21,23]);
  905: 
  906:         my $countdown = &countdown_timer();
  907:         if (&hidden_button_check() eq 'yes') {
  908:             if ($countdown) {
  909:                 &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$countdown);
  910:             }
  911:         } else {
  912:             my @tools = @inlineremote[93,91,81,82,83];
  913:             if ($countdown) {
  914:                 unshift(@tools,$countdown);
  915:             }
  916:             &Apache::lonhtmlcommon::add_breadcrumb_tool(
  917:                 'tools',@tools);
  918: 
  919:             #publish button in construction space
  920:             if ($env{'request.state'} eq 'construct'){
  921:                 &Apache::lonhtmlcommon::add_breadcrumb_tool(
  922:                      'advtools', $inlineremote[63]);
  923:             } else {
  924:                 &Apache::lonhtmlcommon::add_breadcrumb_tool(
  925:                      'tools', $inlineremote[63]);
  926:             }
  927:             &advtools_crumbs(@inlineremote);
  928:         }
  929:     }
  930: 
  931:     return   &Apache::lonhtmlcommon::scripttag('', 'start')
  932:            . &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
  933:            . &Apache::lonhtmlcommon::scripttag('', 'end');
  934: }
  935: 
  936: sub get_editbutton {
  937:     my ($cfile,$home,$switchserver,$forceedit,$forceview,$forcereg) = @_;
  938:     my $jscall;
  939:     if (($forceview) && ($env{'form.todocs'})) {
  940:         my ($folderpath,$command);
  941:         if ($env{'request.symb'}) {
  942:             $folderpath = &Apache::loncommon::symb_to_docspath($env{'request.symb'});
  943:         } elsif ($env{'form.folderpath'} =~ /^supplemental/) {
  944:             $folderpath = $env{'form.folderpath'};
  945:             $command = '&forcesupplement=1';
  946:         }
  947:         $folderpath = &escape(&HTML::Entities::encode(&escape($folderpath),'<>&"'));
  948:         $jscall = "go('/adm/coursedocs?folderpath=$folderpath$command')";
  949:     } else {
  950:         $jscall = &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,$switchserver,
  951:                                                 $forceedit,$forcereg,$env{'request.symb'},
  952:                                                 &escape($env{'form.folderpath'}),
  953:                                                 &escape($env{'form.title'}),$env{'form.idx'},
  954:                                                 &escape($env{'form.suppurl'},$env{'form.todocs'}));
  955:     }
  956:     if ($jscall) {
  957:         my $icon = 'pcstr.png';
  958:         my $label = 'Edit';
  959:         if ($forceview) {
  960:             $icon = 'tolastloc.png';
  961:             $label = 'Exit Editing';
  962:         }
  963:         &switch('','',6,1,$icon,$label,'resource[_2]',
  964:                 $jscall,"Edit this resource");
  965:         return 1;
  966:     }
  967:     return;
  968: }
  969: 
  970: sub prepare_functions {
  971:     my ($resurl,$forcereg,$group,$bread_crumbs,$advtools,$docscrumbs) = @_;
  972:     unless ($env{'request.registered'}) {
  973:         undef(@inlineremote);
  974:     }
  975:     my ($cdom,$cnum,%perms,$cfile,$switchserver,$home,$forceedit,
  976:         $forceview);
  977: 
  978:     if ($env{'request.course.id'}) {
  979:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
  980:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  981:         $perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
  982:     }
  983: 
  984:     my $editbutton = '';
  985: #
  986: # Determine whether or not to display 'Edit' icon/button
  987: #
  988:     if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
  989:         my $file=&Apache::lonnet::declutter($env{'request.filename'});
  990:         ($cfile,$home,$switchserver,$forceedit,$forceview) =
  991:             &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
  992:                 &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
  993:         if (($cfile) && ($home ne '') && ($home ne 'no_host')) {
  994:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
  995:                                           $forceedit,$forceview,$forcereg);
  996:         }
  997:     } elsif ((!$env{'request.course.id'}) &&
  998:              ($env{'user.author'}) && ($env{'request.filename'}) &&
  999:              ($env{'request.role'} !~/^(aa|ca|au)/)) {
 1000: #
 1001: # Currently do not have the role of author or co-author.
 1002: # Do we have authoring privileges for the resource?
 1003: #
 1004:         my $file=&Apache::lonnet::declutter($env{'request.filename'});
 1005:         ($cfile,$home,$switchserver,$forceedit,$forceview) =
 1006:             &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
 1007:                 &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
 1008:         if (($cfile) && ($home ne '') && ($home ne 'no_host')) {
 1009:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
 1010:                                           $forceedit,$forceview,$forcereg);
 1011:         }
 1012:     } elsif ($env{'request.course.id'}) {
 1013: #
 1014: # This applies in course context
 1015: #
 1016:         if (($perms{'mdc'}) &&
 1017:             (($resurl eq "/public/$cdom/$cnum/syllabus") ||
 1018:             ($resurl =~ m{^/uploaded/$cdom/$cnum/portfolio/syllabus/}))) {
 1019:             $cfile = $resurl;
 1020:             $home = &Apache::lonnet::homeserver($cnum,$cdom);
 1021:             if ($env{'form.forceedit'}) {
 1022:                 $forceview = 1;
 1023:             } else {
 1024:                 $forceedit = 1;
 1025:             }
 1026:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
 1027:                                           $forceedit,$forceview,$forcereg);
 1028:         } elsif (($resurl eq '/adm/extresedit') &&
 1029:                  (($env{'form.symb'}) || ($env{'form.folderpath'}))) {
 1030:             ($cfile,$home,$switchserver,$forceedit,$forceview) =
 1031:             &Apache::lonnet::can_edit_resource($resurl,$cnum,$cdom,$resurl,
 1032:                                                $env{'form.symb'});
 1033:             if ($cfile ne '') {
 1034:                 $editbutton = &get_editbutton($cfile,$home,$switchserver,
 1035:                                               $forceedit,$forceview,$forcereg,
 1036:                                               $env{'form.title'},$env{'form.suppurl'});
 1037:             }
 1038:         } elsif (($resurl =~ m{^/?adm/viewclasslist$}) &&
 1039:                  (&Apache::lonnet::allowed('opa',$env{'request.course.id'}))) {
 1040:             ($cfile,$home,$switchserver,$forceedit,$forceview) =
 1041:             &Apache::lonnet::can_edit_resource($resurl,$cnum,$cdom,$resurl,
 1042:                                                $env{'form.symb'});
 1043:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
 1044:                                           $forceedit,$forceview,$forcereg);
 1045:         } elsif (($resurl !~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) &&
 1046:                  ($resurl ne '/cgi-bin/printout.pl')) {
 1047:             if ($env{'request.filename'}) {
 1048:                 my $file=&Apache::lonnet::declutter($env{'request.filename'});
 1049:                 ($cfile,$home,$switchserver,$forceedit,$forceview) =
 1050:                     &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
 1051:                         &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
 1052:                 if ($cfile ne '') {
 1053:                     $editbutton = &get_editbutton($cfile,$home,$switchserver,
 1054:                                                   $forceedit,$forceview,$forcereg);
 1055:                 }
 1056:             }
 1057:         }
 1058:     }
 1059: # End determination of 'Edit' icon/button display
 1060: 
 1061:     if ($env{'request.course.id'}) {
 1062: # This applies to about me page for users in a course
 1063:         if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
 1064:             my ($sdom,$sname) = ($1,$2);
 1065:             unless (&Apache::lonnet::is_course($sdom,$sname)) {
 1066:                 &switch('','',6,4,'mail-message-new-22x22.png','Message to user',
 1067:                         '',
 1068:                         "go('/adm/email?compose=individual&amp;recname=$sname&amp;recdom=$sdom')",
 1069:                             'Send message to specific user');
 1070:             }
 1071:             my $hideprivileged = 1;
 1072:             if (&Apache::lonnet::in_course($sdom,$sname,$cdom,$cnum,undef,
 1073:                                            $hideprivileged)) {
 1074:                 foreach my $priv ('vsa','vgr','srm') {
 1075:                     $perms{$priv} = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
 1076:                     if (!$perms{$priv} && $env{'request.course.sec'} ne '') {
 1077:                         $perms{$priv} =
 1078:                             &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
 1079:                     }
 1080:                 }
 1081:                 if ($perms{'vsa'}) {
 1082:                     &switch('','',6,5,'trck-22x22.png','Activity',
 1083:                             '',
 1084:                             "go('/adm/trackstudent?selected_student=$sname:$sdom')",
 1085:                             'View recent activity by this person');
 1086:                 }
 1087:                 if ($perms{'vgr'}) {
 1088:                     &switch('','',6,6,'rsrv-22x22.png','Reservations',
 1089:                             '',
 1090:                             "go('/adm/slotrequest?command=showresv&amp;origin=aboutme&amp;uname=$sname&amp;udom=$sdom')",
 1091:                             'Slot reservation history');
 1092:                 }
 1093:                 if ($perms{'srm'}) {
 1094:                     &switch('','',6,7,'contact-new-22x22.png','Records',
 1095:                             '',
 1096:                             "go('/adm/email?recordftf=retrieve&amp;recname=$sname&amp;recdom=$sdom')",
 1097:                             'Add records');
 1098:                 }
 1099:             }
 1100:         }
 1101:         if (($env{'form.folderpath'} =~ /^supplemental/) &&
 1102:             (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) &&
 1103:             (($resurl =~ m{^/adm/wrapper/ext/}) ||
 1104:              ($resurl =~ m{^/uploaded/$cdom/$cnum/supplemental/}) ||
 1105:              ($resurl eq '/adm/supplemental') ||
 1106:              ($resurl =~ m{^/public/$cdom/$cnum/syllabus$}) ||
 1107:              ($resurl =~ m{^/adm/$match_domain/$match_username/aboutme$}))) {
 1108:             my @folders=split('&',$env{'form.folderpath'});
 1109:             if ((@folders > 2) || ($resurl ne '/adm/supplemental')) {
 1110:                 my $esc_path=&escape(&HTML::Entities::encode(&escape($env{'form.folderpath'}),'<>&"'));
 1111:                 &switch('','',7,4,'docs-22x22.png','Edit Folder','parms[_2]',
 1112:                         "location.href='/adm/coursedocs?command=direct&amp;forcesupplement=1&amp;supppath=$esc_path'",
 1113:                         'Folder/Page Content');
 1114:             }
 1115:         }
 1116:     }
 1117: 
 1118: # End checking for items for about me page for users in a course
 1119:     if ($docscrumbs) {
 1120:         &Apache::lonhtmlcommon::clear_breadcrumb_tools();
 1121:         &advtools_crumbs(@inlineremote);
 1122:         return $editbutton;
 1123:     } elsif ($env{'request.registered'}) {
 1124:         return $editbutton;
 1125:     } else {
 1126:         if (ref($bread_crumbs) eq 'ARRAY') {
 1127:             if (@inlineremote > 0) {
 1128:                 if (ref($advtools) eq 'ARRAY') {
 1129:                     @{$advtools} = @inlineremote;
 1130:                 }
 1131:             }
 1132:             return;
 1133:         } elsif (@inlineremote > 0) {
 1134:             &Apache::lonhtmlcommon::clear_breadcrumb_tools();
 1135:             &advtools_crumbs(@inlineremote);
 1136:             return   &Apache::lonhtmlcommon::scripttag('', 'start')
 1137:                    . &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
 1138:                    . &Apache::lonhtmlcommon::scripttag('', 'end');
 1139:         }
 1140:     }
 1141: }
 1142: 
 1143: sub advtools_crumbs {
 1144:     my @funcs = @_;
 1145:     if ($env{'request.noversionuri'} =~ m{^/adm/$match_domain/$match_username/aboutme$}) {
 1146:         &Apache::lonhtmlcommon::add_breadcrumb_tool(
 1147:             'advtools', @funcs[61,64,65,66,67,74]);
 1148:     } elsif ($env{'request.noversionuri'} !~ m{^/adm/(navmaps|viewclasslist)(\?|$)}) {
 1149:         &Apache::lonhtmlcommon::add_breadcrumb_tool(
 1150:             'advtools', @funcs[61,71,72,73,74,92]);
 1151:     } elsif ($env{'request.noversionuri'} eq '/adm/viewclasslist') {
 1152:         &Apache::lonhtmlcommon::add_breadcrumb_tool(
 1153:             'advtools', $funcs[61]);
 1154:     }
 1155:     return;
 1156: }
 1157: 
 1158: # ================================================================== Raw Config
 1159: 
 1160: sub clear {
 1161:     my ($row,$col)=@_;
 1162:     $inlineremote[10*$row+$col]='';
 1163:     return ''; 
 1164: }
 1165: 
 1166: # ============================================ Switch a button or create a link
 1167: # Switch acts on the javascript that is executed when a button is clicked.  
 1168: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
 1169: 
 1170: sub switch {
 1171:     my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak)=@_;
 1172:     $act=~s/\$uname/$uname/g;
 1173:     $act=~s/\$udom/$udom/g;
 1174:     $top=&mt($top);
 1175:     $bot=&mt($bot);
 1176:     $desc=&mt($desc);
 1177:     my $idx=10*$row+$col;
 1178:     $category_members{$cat}.=':'.$idx;
 1179: 
 1180: # Inline Menu
 1181:     if ($nobreak==2) { return ''; }
 1182:     my $text=$top.' '.$bot;
 1183:     $text=~s/\s*\-\s*//gs;
 1184: 
 1185:     my $pic=
 1186: 	   '<img alt="'.$text.'" src="'.
 1187: 	   &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
 1188: 	   '" align="'.($nobreak==3?'right':'left').'" class="LC_icon" />';
 1189:     if ($env{'browser.interface'} eq 'faketextual') {
 1190: # Main Menu
 1191: 	   if ($nobreak==3) {
 1192: 	       $inlineremote[$idx]="\n".
 1193: 		   '<td class="LC_menubuttons_text" align="right">'.$text.
 1194: 		   '</td><td align="left">'.
 1195: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
 1196: 	   } elsif ($nobreak) {
 1197: 	       $inlineremote[$idx]="\n<tr>".
 1198: 		   '<td align="left">'.
 1199: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td>
 1200:                     <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>';
 1201: 	   } else {
 1202: 	       $inlineremote[$idx]="\n<tr>".
 1203: 		   '<td align="left">'.
 1204: 		   '<a href="javascript:'.$act.';">'.$pic.
 1205: 		   '</a></td><td class="LC_menubuttons_text" colspan="3">'.
 1206: 		   '<a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$desc.'</span></a></td></tr>';
 1207: 	   }
 1208:     } else {
 1209: # Inline Menu
 1210:         my @tools = (93,91,81,82,83);
 1211:         unless ($env{'request.state'} eq 'construct') {
 1212:             push(@tools,63);
 1213:         }
 1214:         if (($env{'environment.icons'} eq 'iconsonly') && 
 1215:             (grep(/^$idx$/,@tools))) {
 1216:             $inlineremote[$idx] =
 1217:         '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.'</a>';
 1218:         } else {
 1219:             $inlineremote[$idx] =
 1220:        '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.
 1221:        '<span class="LC_menubuttons_inline_text">'.$top.'&nbsp;</span></a>';
 1222:         }
 1223:     }
 1224:     return '';
 1225: }
 1226: 
 1227: sub secondlevel {
 1228:     my $output='';
 1229:     my 
 1230:     ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_;
 1231:     if ($prt eq 'any') {
 1232: 	   $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1233:     } elsif ($prt=~/^r(\w+)/) {
 1234:         if ($rol eq $1) {
 1235:            $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1236:         }
 1237:     }
 1238:     return $output;
 1239: }
 1240: 
 1241: sub inlinemenu {
 1242:     undef(@inlineremote);
 1243:     undef(%category_members);
 1244: # calling rawconfig with "1" will evaluate mydesk.tab, even if there is no active remote control
 1245:     &rawconfig(1);
 1246:     my $output='<table><tr>';
 1247:     for (my $col=1; $col<=2; $col++) {
 1248:         $output.='<td class="LC_mainmenu_col_fieldset">';
 1249:         for (my $row=1; $row<=8; $row++) {
 1250:             foreach my $cat (keys(%category_members)) {
 1251:                if ($category_positions{$cat} ne "$col,$row") { next; }
 1252:                #$output.='<table><tr><td colspan="4" class="LC_menubuttons_category">'.&mt($category_names{$cat}).'</td></tr>';
 1253:                $output.='<div class="LC_Box LC_400Box">';
 1254: 	       $output.='<h3 class="LC_hcell">'.&mt($category_names{$cat}).'</h3>';
 1255:                $output.='<table>';
 1256:                my %active=();
 1257:                foreach my $menu_item (split(/\:/,$category_members{$cat})) {
 1258:                   if ($inlineremote[$menu_item]) {
 1259:                      $active{$menu_item}=1;
 1260:                   }
 1261:                }  
 1262:                foreach my $item (sort(keys(%active))) {
 1263:                   $output.=$inlineremote[$item];
 1264:                }
 1265:                $output.='</table>';
 1266:                $output.='</div>';
 1267:             }
 1268:          }
 1269:          $output.="</td>";
 1270:     }
 1271:     $output.="</tr></table>";
 1272:     return $output;
 1273: }
 1274: 
 1275: sub rawconfig {
 1276: #
 1277: # This evaluates mydesk.tab
 1278: # Need to add more positions and more privileges to deal with all
 1279: # menu items.
 1280: #
 1281:     my $textualoverride=shift;
 1282:     my $output='';
 1283:     return '' unless $textualoverride;
 1284:     my $uname=$env{'user.name'};
 1285:     my $udom=$env{'user.domain'};
 1286:     my $adv=$env{'user.adv'};
 1287:     my $show_course=&Apache::loncommon::show_course();
 1288:     my $author=$env{'user.author'};
 1289:     my $crs='';
 1290:     my $crstype='';
 1291:     if ($env{'request.course.id'}) {
 1292:        $crs='/'.$env{'request.course.id'};
 1293:        if ($env{'request.course.sec'}) {
 1294: 	   $crs.='_'.$env{'request.course.sec'};
 1295:        }
 1296:        $crs=~s/\_/\//g;
 1297:        $crstype = &Apache::loncommon::course_type();
 1298:     }
 1299:     my $pub=($env{'request.state'} eq 'published');
 1300:     my $con=($env{'request.state'} eq 'construct');
 1301:     my $rol=$env{'request.role'};
 1302:     my $requested_domain;
 1303:     if ($rol) {
 1304:        $requested_domain = $env{'request.role.domain'};
 1305:     }
 1306:     foreach my $line (@desklines) {
 1307:         my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
 1308:         $prt=~s/\$uname/$uname/g;
 1309:         $prt=~s/\$udom/$udom/g;
 1310:         if ($prt =~ /\$crs/) {
 1311:             next unless ($env{'request.course.id'});
 1312:             next if ($crstype eq 'Community');
 1313:             $prt=~s/\$crs/$crs/g;
 1314:         } elsif ($prt =~ /\$cmty/) {
 1315:             next unless ($env{'request.course.id'});
 1316:             next if ($crstype ne 'Community');
 1317:             $prt=~s/\$cmty/$crs/g;
 1318:         }
 1319:         if ($prt =~ m/\$requested_domain/) {
 1320:             if ((!$requested_domain) && ($pro eq 'pbre') && ($env{'user.adv'})) {
 1321:                 $prt=~s/\$requested_domain/$env{'user.domain'}/g;
 1322:             } else {
 1323:                 $prt=~s/\$requested_domain/$requested_domain/g;
 1324:             }
 1325:         }
 1326:         if ($category_names{$cat}!~/\w/) { $cat='oth'; }
 1327:         if ($pro eq 'clear') {
 1328: 	    $output.=&clear($row,$col);
 1329:         } elsif ($pro eq 'any') {
 1330:                $output.=&secondlevel(
 1331: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1332: 	} elsif ($pro eq 'smp') {
 1333:             unless ($adv) {
 1334:                $output.=&secondlevel(
 1335:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1336:             }
 1337:         } elsif ($pro eq 'adv') {
 1338:             if ($adv) {
 1339:                $output.=&secondlevel(
 1340: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1341:             }
 1342: 	} elsif ($pro eq 'shc') {
 1343:             if ($show_course) {
 1344:                $output.=&secondlevel(
 1345:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1346:             }
 1347:         } elsif ($pro eq 'nsc') {
 1348:             if (!$show_course) {
 1349:                $output.=&secondlevel(
 1350: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1351:             }
 1352:         } elsif (($pro=~/^p(\w+)/) && ($prt)) {
 1353:             my $priv = $1;
 1354:             if ($priv =~ /^mdc(Course|Community)/) {
 1355:                 if ($crstype eq $1) {
 1356:                     $priv = 'mdc';
 1357:                 } else {
 1358:                     next;
 1359:                 }
 1360:             }
 1361:             if ((($priv eq 'bre') && (&Apache::lonnet::allowed($priv,$prt) eq 'F')) ||
 1362:                 (($priv ne 'bre') && (&Apache::lonnet::allowed($priv,$prt)))) {
 1363:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1364:             }
 1365:         } elsif ($pro eq 'course')  {
 1366:             if (($env{'request.course.fn'}) && ($crstype ne 'Community')) {
 1367:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1368: 	    }
 1369:         } elsif ($pro eq 'community')  {
 1370:             if (($env{'request.course.fn'}) && ($crstype eq 'Community')) {
 1371:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1372:             }
 1373:         } elsif ($pro =~ /^courseenv_(.*)$/) {
 1374:             my $key = $1;
 1375:             if ($crstype ne 'Community') {
 1376:                 my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
 1377:                 if ($key eq 'canuse_pdfforms') {
 1378:                     if ($env{'request.course.id'} && $coursepref eq '') {
 1379:                         my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
 1380:                         $coursepref = $domdefs{'canuse_pdfforms'};
 1381:                     }
 1382:                 }
 1383:                 if ($coursepref) { 
 1384:                     $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1385:                 }
 1386:             }
 1387:         } elsif ($pro =~ /^communityenv_(.*)$/) {
 1388:             my $key = $1;
 1389:             if ($crstype eq 'Community') {
 1390:                 my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
 1391:                 if ($key eq 'canuse_pdfforms') {
 1392:                     if ($env{'request.course.id'} && $coursepref eq '') {
 1393:                         my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
 1394:                         $coursepref = $domdefs{'canuse_pdfforms'};
 1395:                     }
 1396:                 }
 1397:                 if ($coursepref) { 
 1398:                     $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1399:                 }
 1400:             }
 1401:         } elsif ($pro =~ /^course_(.*)$/) {
 1402:             # Check for permissions inside of a course
 1403:             if (($env{'request.course.id'}) && ($crstype ne 'Community') && 
 1404:                 (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
 1405:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
 1406:                  )) {
 1407:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1408: 	    }
 1409:         } elsif ($pro =~ /^community_(.*)$/) {
 1410:             # Check for permissions inside of a community
 1411:             if (($env{'request.course.id'}) && ($crstype eq 'Community') &&   
 1412:                 (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
 1413:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
 1414:                  )) {
 1415:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1416:             }
 1417:         } elsif ($pro eq 'author') {
 1418:             if ($author) {
 1419:                 if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
 1420:                     (($prt eq 'raa') && ($env{'request.role'}=~/^aa/)) || 
 1421:                     (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
 1422:                     # Check that we are on the correct machine
 1423:                     my $cadom=$requested_domain;
 1424:                     my $caname=$env{'user.name'};
 1425:                     if (($prt eq 'rca') || ($prt eq 'raa')) {
 1426: 		       ($cadom,$caname)=
 1427:                                ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
 1428:                     }                       
 1429:                     $act =~ s/\$caname/$caname/g;
 1430:                     $act =~ s/\$cadom/$cadom/g;
 1431:                     my $home = &Apache::lonnet::homeserver($caname,$cadom);
 1432: 		    my $allowed=0;
 1433: 		    my @ids=&Apache::lonnet::current_machine_ids();
 1434: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
 1435: 		    if ($allowed) {
 1436:                         $output.=&switch($caname,$cadom,
 1437:                                         $row,$col,$img,$top,$bot,$act,$desc,$cat);
 1438:                     }
 1439:                 }
 1440:             }
 1441:         } elsif ($pro eq 'tools') {
 1442:             my @tools = ('aboutme','blog','portfolio');
 1443:             if (grep(/^\Q$prt\E$/,@tools)) {
 1444:                 if (!&Apache::lonnet::usertools_access($env{'user.name'},
 1445:                                                        $env{'user.domain'},
 1446:                                                        $prt,undef,'tools')) {
 1447:                     $output.=&clear($row,$col);
 1448:                     next;
 1449:                 }
 1450:             } elsif (($prt eq 'reqcrsnsc') || ($prt eq 'reqcrsshc')) {
 1451:                 if (($prt eq 'reqcrsnsc') && ($show_course))   {
 1452:                     next;
 1453:                 }
 1454:                 if (($prt eq 'reqcrsshc') && (!$show_course)) {
 1455:                     next;
 1456:                 }
 1457:                 my $showreqcrs = &check_for_rcrs();
 1458:                 if (!$showreqcrs) {
 1459:                     $output.=&clear($row,$col);
 1460:                     next;
 1461:                 }
 1462:             }
 1463:             $prt='any';
 1464:             $output.=&secondlevel(
 1465:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1466:         }
 1467:     }
 1468:     return $output;
 1469: }
 1470: 
 1471: sub check_for_rcrs {
 1472:     my $showreqcrs = 0;
 1473:     my @reqtypes = ('official','unofficial','community','textbook');
 1474:     foreach my $type (@reqtypes) {
 1475:         if (&Apache::lonnet::usertools_access($env{'user.name'},
 1476:                                               $env{'user.domain'},
 1477:                                               $type,undef,'requestcourses')) {
 1478:             $showreqcrs = 1;
 1479:             last;
 1480:         }
 1481:     }
 1482:     if (!$showreqcrs) {
 1483:         foreach my $type (@reqtypes) {
 1484:             if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
 1485:                 $showreqcrs = 1;
 1486:                 last;
 1487:             }
 1488:         }
 1489:     }
 1490:     return $showreqcrs;
 1491: }
 1492: 
 1493: sub dc_popup_js {
 1494:     my %lt = &Apache::lonlocal::texthash(
 1495:                                           more => '(More ...)',
 1496:                                           less => '(Less ...)',
 1497:                                         );
 1498:     return <<"END";
 1499: 
 1500: function showCourseID() {
 1501:     document.getElementById('dccid').style.display='block';
 1502:     document.getElementById('dccid').style.textAlign='left';
 1503:     document.getElementById('dccid').style.textFace='normal';
 1504:     document.getElementById('dccidtext').innerHTML ='<a href="javascript:hideCourseID();" class="LC_menubuttons_link">$lt{'less'}</a>';
 1505:     return;
 1506: }
 1507: 
 1508: function hideCourseID() {
 1509:     document.getElementById('dccid').style.display='none';
 1510:     document.getElementById('dccidtext').innerHTML ='<a href="javascript:showCourseID()" class="LC_menubuttons_link">$lt{'more'}</a>';
 1511:     return;
 1512: }
 1513: 
 1514: END
 1515: 
 1516: }
 1517: 
 1518: sub countdown_toggle_js {
 1519:     return <<"END";
 1520: 
 1521: function toggleCountdown() {
 1522:     var countdownid = document.getElementById('duedatecountdown');
 1523:     var currstyle = countdownid.style.display;
 1524:     if (currstyle == 'inline') {
 1525:         countdownid.style.display = 'none';
 1526:         document.getElementById('ddcountcollapse').innerHTML='';
 1527:         document.getElementById('ddcountexpand').innerHTML='&#9668;&nbsp;';
 1528:     } else {
 1529:         countdownid.style.display = 'inline';
 1530:         document.getElementById('ddcountcollapse').innerHTML='&#9658;&nbsp;';
 1531:         document.getElementById('ddcountexpand').innerHTML='';
 1532:     }
 1533:     return;
 1534: }
 1535: 
 1536: END
 1537: }
 1538: 
 1539: # This creates a "done button" for timed events.  The confirmation box is a jQuery
 1540: # dialog widget.  Clicking OK will set (LC_interval_done = 'true') which is checked in 
 1541: # lonhomework.pm.
 1542: sub done_button_js {
 1543:     my ($type,$height) = @_;
 1544:     if ($height !~ /^\d+$/) {
 1545:         $height = 320;
 1546:     }
 1547:     my %lt = &Apache::lonlocal::texthash(
 1548:                  title    => 'WARNING!',
 1549:                  button   => 'Done',
 1550:                  preamble => 'You are trying to end this timed event early.',
 1551:                  map      => 'Confirming that you are done will cause the time to expire and prevent you from changing any answers in the current folder.',
 1552:                  resource => 'Confirming that you are done will cause the time to expire for this question, and prevent you from changing your answer(s).', 
 1553:                  ok       => 'Click "OK" if you are completely finished.',
 1554:                  cancel   => 'Click "Cancel" to continue working.',
 1555:     );
 1556:     my $confirm;
 1557:     if (($type eq 'map') || ($type eq 'resource')) {
 1558:         $confirm = $lt{'preamble'}.' '.$lt{$type}.' '.$lt{'ok'}.' '.$lt{'cancel'};
 1559:     }
 1560:     if ($confirm) {
 1561:         return <<END;
 1562: 
 1563: <form method="post" name="LCdoneButton" action="">
 1564:     <input type="hidden" name="LC_interval_done" value="" />
 1565:     <button id="LC_done-confirm-opener" type="button">$lt{'button'}</button>
 1566: </form>
 1567: 
 1568: <div id="LC_done-confirm" title="$lt{'title'}">
 1569:     <p>$confirm</p>
 1570: </div>
 1571: 
 1572: <script type="text/javascript">
 1573: // <![CDATA[
 1574: \$( "#LC_done-confirm" ).dialog({ autoOpen: false });
 1575: \$( "#LC_done-confirm-opener" ).click(function() {
 1576:     \$( "#LC_done-confirm" ).dialog( "open" );
 1577:     \$( "#LC_done-confirm" ).dialog({
 1578:       resizable: false,
 1579:       height: $height,
 1580:       modal: true,
 1581:       buttons: {
 1582:         "OK": function() {
 1583:             \$( this ).dialog( "close" );
 1584:             \$( '[name="LC_interval_done"]' )[0].value = 'true';
 1585:             \$( '[name="LCdoneButton"]' )[0].submit();
 1586:         },
 1587:         Cancel: function() {
 1588:           \$( this ).dialog( "close" );
 1589:         }
 1590:       }    
 1591:     })
 1592: });
 1593: // ]]>
 1594: </script>
 1595: 
 1596: END
 1597:     } else {
 1598:         return;
 1599:     }
 1600: }
 1601: 
 1602: sub utilityfunctions {
 1603:     my ($httphost) = @_;
 1604:     my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
 1605:     if ($currenturl =~ m{^/adm/wrapper/ext/}
 1606:         && $env{'request.external.querystring'} ) {
 1607:             $currenturl .= ($currenturl=~/\?/)?'&':'?'.$env{'request.external.querystring'};
 1608:     }
 1609:     $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
 1610:     
 1611:     my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
 1612: 
 1613:     my $dc_popup_cid;
 1614:     if ($env{'user.adv'} && exists($env{'user.role.dc./'.
 1615:                         $env{'course.'.$env{'request.course.id'}.
 1616:                                  '.domain'}.'/'})) {
 1617:         $dc_popup_cid = &dc_popup_js();
 1618:     }
 1619: 
 1620:     my $start_page_annotate = 
 1621:         &Apache::loncommon::start_page('Annotator',undef,
 1622: 				       {'only_body' => 1,
 1623: 					'js_ready'  => 1,
 1624: 					'bgcolor'   => '#BBBBBB',
 1625: 					'add_entries' => {
 1626: 					    'onload' => 'javascript:document.goannotate.submit();'}});
 1627: 
 1628:     my $end_page_annotate = 
 1629:         &Apache::loncommon::end_page({'js_ready' => 1});
 1630: 
 1631:     my $jumptores = &Apache::lonhtmlcommon::javascript_jumpto_resource();
 1632: 
 1633:     my $esc_url=&escape($currenturl);
 1634:     my $esc_symb=&escape($currentsymb);
 1635: 
 1636:     my $countdown = &countdown_toggle_js();
 1637: 
 1638:     my $hostvar = '
 1639: function setLCHost() {
 1640:     var lcHostname="";
 1641: ';
 1642:     if ($httphost =~ m{^https?\://}) {
 1643:         $hostvar .= '    var lcServer="'.$httphost.'";'."\n".
 1644:                     '    var hostReg = /^https?:\/\/([^\/]+)$/i;'."\n".
 1645:                     '    var match = hostReg.exec(lcServer);'."\n".
 1646:                     '    if (match.length) {'."\n".
 1647:                     '        if (match[1] == location.hostname) {'."\n".
 1648:                     '            lcHostname=lcServer;'."\n".
 1649:                     '        }'."\n".
 1650:                     '    }'."\n";
 1651:     }
 1652:     
 1653:     $hostvar .= '    return lcHostname;'."\n".
 1654: '}'."\n";
 1655: 
 1656: return (<<ENDUTILITY)
 1657:     $hostvar
 1658:     var currentURL=unescape("$esc_url");
 1659:     var reloadURL=unescape("$esc_url");
 1660:     var currentSymb=unescape("$esc_symb");
 1661: 
 1662: $dc_popup_cid
 1663: 
 1664: $jumptores
 1665: 
 1666: function gopost(url,postdata) {
 1667:    if (url!='') {
 1668:       var lcHostname = setLCHost();
 1669:       this.document.server.action=lcHostname+url;
 1670:       this.document.server.postdata.value=postdata;
 1671:       this.document.server.command.value='';
 1672:       this.document.server.url.value='';
 1673:       this.document.server.symb.value='';
 1674:       this.document.server.submit();
 1675:    }
 1676: }
 1677: 
 1678: function gocmd(url,cmd) {
 1679:    if (url!='') {
 1680:       var lcHostname = setLCHost();
 1681:       this.document.server.action=lcHostname+url;
 1682:       this.document.server.postdata.value='';
 1683:       this.document.server.command.value=cmd;
 1684:       this.document.server.url.value=currentURL;
 1685:       this.document.server.symb.value=currentSymb;
 1686:       this.document.server.submit();
 1687:    }
 1688: }
 1689: 
 1690: function gocstr(url,filename) {
 1691:     if (url == '/adm/cfile?action=delete') {
 1692:         this.document.cstrdelete.filename.value = filename
 1693:         this.document.cstrdelete.submit();
 1694:         return;
 1695:     }
 1696:     if (url == '/adm/printout') {
 1697:         this.document.cstrprint.postdata.value = filename
 1698:         this.document.cstrprint.curseed.value = 0;
 1699:         this.document.cstrprint.problemtype.value = 0;
 1700:         if (this.document.lonhomework) {
 1701:             if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
 1702:                 this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
 1703:             }
 1704:             if (this.document.lonhomework.problemtype) {
 1705: 		if (this.document.lonhomework.problemtype.value) {
 1706: 		    this.document.cstrprint.problemtype.value = 
 1707: 			this.document.lonhomework.problemtype.value;
 1708: 		} else if (this.document.lonhomework.problemtype.options) {
 1709: 		    for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
 1710: 			if (this.document.lonhomework.problemtype.options[i].selected) {
 1711: 			    if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') { 
 1712: 				this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
 1713: 				}
 1714: 			}
 1715: 		    }
 1716: 		}
 1717: 	    }
 1718: 	}
 1719:         this.document.cstrprint.submit();
 1720:         return;
 1721:     }
 1722:     if (url !='') {
 1723:         this.document.constspace.filename.value = filename;
 1724:         this.document.constspace.action = url;
 1725:         this.document.constspace.submit();
 1726:     }
 1727: }
 1728: 
 1729: function golist(url) {
 1730:    if (url!='' && url!= null) {
 1731:        currentURL = null;
 1732:        currentSymb= null;
 1733:        var lcHostname = setLCHost();
 1734:        top.location.href=lcHostname+url;
 1735:    }
 1736: }
 1737: 
 1738: 
 1739: 
 1740: function catalog_info(isMobile) {
 1741:     if (isMobile == 1) {
 1742:         openMyModal(window.location.pathname+'.meta?modal=1',500,400,'yes');
 1743:     } else {
 1744:         loncatinfo=window.open(window.location.pathname+'.meta',"LONcatInfo",'height=500,width=400,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
 1745:     }
 1746: }
 1747: 
 1748: function chat_win() {
 1749:    var lcHostname = setLCHost();
 1750:    lonchat=window.open(lcHostname+'/res/adm/pages/chatroom.html',"LONchat",'height=320,width=480,resizable=yes,location=no,menubar=no,toolbar=no');
 1751: }
 1752: 
 1753: function group_chat(group) {
 1754:    var lcHostname = setLCHost();
 1755:    var url = lcHostname+'/adm/groupchat?group='+group;
 1756:    var winName = 'LONchat_'+group;
 1757:    grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
 1758: }
 1759: 
 1760: function annotate() {
 1761:    w_Annotator_flag=1;
 1762:    annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
 1763:    annotator.document.write(
 1764:    '$start_page_annotate'
 1765:   +"<form name='goannotate' target='Annotator' method='post' "
 1766:   +"action='/adm/annotations'>"
 1767:   +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />"
 1768:   +"<\\/form>"
 1769:   +'$end_page_annotate');
 1770:    annotator.document.close();
 1771: }
 1772: 
 1773: function open_StoredLinks_Import(rat) {
 1774:    var newWin;
 1775:    var lcHostname = setLCHost();
 1776:    if (rat) {
 1777:        newWin = window.open(lcHostname+'/adm/wishlist?inhibitmenu=yes&mode=import&rat='+rat,
 1778:                             'wishlistImport','scrollbars=1,resizable=1,menubar=0');
 1779:    }
 1780:    else {
 1781:        newWin = window.open(lcHostname+'/adm/wishlist?inhibitmenu=yes&mode=import',
 1782:                             'wishlistImport','scrollbars=1,resizable=1,menubar=0');
 1783:    }
 1784:    newWin.focus();
 1785: }
 1786: 
 1787: (function (\$) {
 1788:   \$(document).ready(function () {
 1789:     \$.single=function(a){return function(b){a[0]=b;return a}}(\$([1]));
 1790:     /*\@cc_on
 1791:       if (!window.XMLHttpRequest) {
 1792:         \$('.LC_hoverable').each(function () {
 1793:           this.attachEvent('onmouseenter', function (evt) { \$.single(evt.srcElement).addClass('hover'); });
 1794:           this.attachEvent('onmouseleave', function (evt) { \$.single(evt.srcElement).removeClass('hover'); });
 1795:         });
 1796:       }
 1797:     \@*/
 1798:   });
 1799: }(jQuery));
 1800: 
 1801: $countdown
 1802: 
 1803: ENDUTILITY
 1804: }
 1805: 
 1806: sub serverform {
 1807:     return(<<ENDSERVERFORM);
 1808: <form name="server" action="/adm/logout" method="post" target="_top">
 1809: <input type="hidden" name="postdata" value="none" />
 1810: <input type="hidden" name="command" value="none" />
 1811: <input type="hidden" name="url" value="none" />
 1812: <input type="hidden" name="symb" value="none" />
 1813: </form>
 1814: ENDSERVERFORM
 1815: }
 1816: 
 1817: sub constspaceform {
 1818:     return(<<ENDCONSTSPACEFORM);
 1819: <form name="constspace" action="/adm/logout" method="post" target="_top">
 1820: <input type="hidden" name="filename" value="" />
 1821: </form>
 1822: <form name="cstrdelete" action="/adm/cfile" method="post" target="_top">
 1823: <input type="hidden" name="action" value="delete" /> 
 1824: <input type="hidden" name="filename" value="" />
 1825: </form>
 1826: <form name="cstrprint" action="/adm/printout" target="_parent" method="post">
 1827: <input type="hidden" name="postdata" value="" />
 1828: <input type="hidden" name="curseed" value="" />
 1829: <input type="hidden" name="problemtype" value="" />
 1830: </form>
 1831: 
 1832: ENDCONSTSPACEFORM
 1833: }
 1834: 
 1835: sub hidden_button_check {
 1836:     if ( $env{'request.course.id'} eq ''
 1837:          || $env{'request.role.adv'} ) {
 1838: 
 1839:         return;
 1840:     }
 1841:     my $buttonshide = &Apache::lonnet::EXT('resource.0.buttonshide');
 1842:     return $buttonshide; 
 1843: }
 1844: 
 1845: sub roles_selector {
 1846:     my ($cdom,$cnum,$httphost) = @_;
 1847:     my $crstype = &Apache::loncommon::course_type();
 1848:     my $now = time;
 1849:     my (%courseroles,%seccount,%courseprivs);
 1850:     my $is_cc;
 1851:     my ($js,$form,$switcher,$switchtext);
 1852:     my $ccrole;
 1853:     if ($crstype eq 'Community') {
 1854:         $ccrole = 'co';
 1855:     } else {
 1856:         $ccrole = 'cc';
 1857:     }
 1858:     my ($priv,$gotsymb,$destsymb);
 1859:     my $destinationurl = $ENV{'REQUEST_URI'};
 1860:     if ($destinationurl =~ /\?symb=/) {
 1861:         $gotsymb = 1;
 1862:     } elsif ($destinationurl =~ m{^/enc/}) {
 1863:         my $plainurl = &Apache::lonenc::unencrypted($destinationurl);
 1864:         if ($plainurl =~ /\?symb=/) {
 1865:             $gotsymb = 1;
 1866:         }
 1867:     }
 1868:     unless ($gotsymb) {
 1869:         $destsymb = &Apache::lonnet::symbread();
 1870:         if ($destsymb ne '') {
 1871:             $destsymb = &Apache::lonenc::check_encrypt($destsymb);
 1872:         }
 1873:     }
 1874:     my $reqprivs = &required_privs();
 1875:     if (ref($reqprivs) eq 'HASH') {
 1876:         my $destination = $destinationurl;
 1877:         $destination =~ s/(\?.*)$//;
 1878:         if (exists($reqprivs->{$destination})) {
 1879:             $priv = $reqprivs->{$destination};
 1880:         }
 1881:     }
 1882:     if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
 1883:         my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
 1884:         
 1885:         if ((($start) && ($start<0)) || 
 1886:             (($end) && ($end<$now))  ||
 1887:             (($start) && ($now<$start))) {
 1888:             $is_cc = 0;
 1889:         } else {
 1890:             $is_cc = 1;
 1891:         }
 1892:     }
 1893:     if ($is_cc) {
 1894:         &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs,$priv);
 1895:     } else {
 1896:         my %gotnosection;
 1897:         foreach my $item (keys(%env)) {
 1898:             if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
 1899:                 my $role = $1;
 1900:                 my $sec = $2;
 1901:                 next if ($role eq 'gr');
 1902:                 my ($start,$end) = split(/\./,$env{$item});
 1903:                 next if (($start && $start > $now) || ($end && $end < $now));
 1904:                 if ($sec eq '') {
 1905:                     if (!$gotnosection{$role}) {
 1906:                         $seccount{$role} ++;
 1907:                         $gotnosection{$role} = 1;
 1908:                     }
 1909:                 }
 1910:                 if ($priv ne '') {
 1911:                     my $cnumsec = $cnum;
 1912:                     if ($sec ne '') {
 1913:                         $cnumsec .= "/$sec";
 1914:                     }
 1915:                     $courseprivs{"$role./$cdom/$cnumsec./"} =
 1916:                         $env{"user.priv.$role./$cdom/$cnumsec./"};
 1917:                     $courseprivs{"$role./$cdom/$cnumsec./$cdom/"} =
 1918:                         $env{"user.priv.$role./$cdom/$cnumsec./$cdom/"};
 1919:                     $courseprivs{"$role./$cdom/$cnumsec./$cdom/$cnumsec"} =
 1920:                         $env{"user.priv.$role./$cdom/$cnumsec./$cdom/$cnumsec"};
 1921:                 }
 1922:                 if (ref($courseroles{$role}) eq 'ARRAY') {
 1923:                     if ($sec ne '') {
 1924:                         if (!grep(/^\Q$sec\E$/,@{$courseroles{$role}})) {
 1925:                             push(@{$courseroles{$role}},$sec);
 1926:                             $seccount{$role} ++;
 1927:                         }
 1928:                     }
 1929:                 } else {
 1930:                     @{$courseroles{$role}} = ();
 1931:                     if ($sec ne '') {
 1932:                         $seccount{$role} ++;
 1933:                         push(@{$courseroles{$role}},$sec);
 1934:                     }
 1935:                 }
 1936:             }
 1937:         }
 1938:     }
 1939:     $switchtext = 'Switch role'; # do not translate here
 1940:     my @roles_order = ($ccrole,'in','ta','ep','ad','st');
 1941:     my $numdiffsec;
 1942:     if (keys(%seccount) == 1) {
 1943:         foreach my $key (keys(%seccount)) {
 1944:             $numdiffsec = $seccount{$key};
 1945:         }
 1946:     }
 1947:     if ((keys(%seccount) > 1) || ($numdiffsec > 1)) {
 1948:         my @submenu;
 1949:         $js = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles,\%courseprivs,$priv);
 1950:         $form = 
 1951:             '<form name="rolechooser" method="post" action="'.$httphost.'/adm/roles">'."\n".
 1952:             '  <input type="hidden" name="destinationurl" value="'.
 1953:             &HTML::Entities::encode($destinationurl).'" />'."\n".
 1954:             '  <input type="hidden" name="gotorole" value="1" />'."\n".
 1955:             '  <input type="hidden" name="selectrole" value="" />'."\n".
 1956:             '  <input type="hidden" name="switchrole" value="" />'."\n";
 1957:         if ($destsymb ne '') {
 1958:             $form .= '  <input type="hidden" name="destsymb" value="'.
 1959:                         &HTML::Entities::encode($destsymb).'" />'."\n";
 1960:         }
 1961:         $form .= '</form>'."\n";
 1962:         foreach my $role (@roles_order) {
 1963:             my $include;
 1964:             if (defined($courseroles{$role})) {
 1965:                 if ($env{'request.role'} =~ m{^\Q$role\E}) {
 1966:                     if ($seccount{$role} > 1) {
 1967:                         $include = 1;
 1968:                     }
 1969:                 } else {
 1970:                     $include = 1;
 1971:                 }
 1972:             }
 1973:             if ($include) {
 1974:                 push(@submenu,['javascript:adhocRole('."'$role'".')',
 1975:                                &Apache::lonnet::plaintext($role,$crstype)]);
 1976:             }
 1977:         }
 1978:         foreach my $role (sort(keys(%courseroles))) {
 1979:             if ($role =~ /^cr/) {
 1980:                 my $include;
 1981:                 if ($env{'request.role'} =~ m{^\Q$role\E}) {
 1982:                     if ($seccount{$role} > 1) {
 1983:                         $include = 1;
 1984:                     }
 1985:                 } else {
 1986:                     $include = 1; 
 1987:                 }
 1988:                 if ($include) {
 1989:                     push(@submenu,['javascript:adhocRole('."'$role'".')',
 1990:                                    &Apache::lonnet::plaintext($role)]);
 1991:                 }
 1992:             }
 1993:         }
 1994:         if (@submenu > 0) {
 1995:             $switcher = &create_submenu('','',$switchtext,\@submenu);
 1996:         }
 1997:     }
 1998:     return ($js,$form,$switcher);
 1999: }
 2000: 
 2001: sub get_all_courseroles {
 2002:     my ($cdom,$cnum,$courseroles,$seccount,$courseprivs) = @_;
 2003:     unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH') &&
 2004:             (ref($courseprivs) eq 'HASH')) {
 2005:         return;
 2006:     }
 2007:     my ($result,$cached) = 
 2008:         &Apache::lonnet::is_cached_new('getcourseroles',$cdom.'_'.$cnum);
 2009:     if (defined($cached)) {
 2010:         if (ref($result) eq 'HASH') {
 2011:             if ((ref($result->{'roles'}) eq 'HASH') && 
 2012:                 (ref($result->{'seccount'}) eq 'HASH') && 
 2013:                 (ref($result->{'privs'}) eq 'HASH')) {
 2014:                 %{$courseroles} = %{$result->{'roles'}};
 2015:                 %{$seccount} = %{$result->{'seccount'}};
 2016:                 %{$courseprivs} = %{$result->{'privs'}};
 2017:                 return;
 2018:             }
 2019:         }
 2020:     }
 2021:     my %gotnosection;
 2022:     my %adv_roles =
 2023:          &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
 2024:     foreach my $role (keys(%adv_roles)) {
 2025:         my ($urole,$usec) = split(/:/,$role);
 2026:         if (!$gotnosection{$urole}) {
 2027:             $seccount->{$urole} ++;
 2028:             $gotnosection{$urole} = 1;
 2029:         }
 2030:         if (ref($courseroles->{$urole}) eq 'ARRAY') {
 2031:             if ($usec ne '') {
 2032:                 if (!grep(/^Q$usec\E$/,@{$courseroles->{$urole}})) {
 2033:                     push(@{$courseroles->{$urole}},$usec);
 2034:                     $seccount->{$urole} ++;
 2035:                 }
 2036:             }
 2037:         } else {
 2038:             @{$courseroles->{$urole}} = ();
 2039:             if ($usec ne '') {
 2040:                 $seccount->{$urole} ++;
 2041:                 push(@{$courseroles->{$urole}},$usec);
 2042:             }
 2043:         }
 2044:         my $area = '/'.$cdom.'/'.$cnum;
 2045:         if ($usec ne '') {
 2046:             $area .= '/'.$usec;
 2047:         }
 2048:         if ($role =~ /^cr\//) {
 2049:             &Apache::lonnet::custom_roleprivs($courseprivs,$urole,$cdom,$cnum,$urole.'.'.$area,$area);
 2050:         } else {
 2051:             &Apache::lonnet::standard_roleprivs($courseprivs,$urole,$cdom,$urole.'.'.$area,$cnum,$area);
 2052:         }
 2053:     }
 2054:     my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum,['st']);
 2055:     @{$courseroles->{'st'}} = ();
 2056:     &Apache::lonnet::standard_roleprivs($courseprivs,'st',$cdom,"st./$cdom/$cnum",$cnum,"/$cdom/$cnum");
 2057:     if (keys(%sections_count) > 0) {
 2058:         push(@{$courseroles->{'st'}},keys(%sections_count));
 2059:         $seccount->{'st'} = scalar(keys(%sections_count));
 2060:     }
 2061:     $seccount->{'st'} ++; # Increment for a section-less student role.  
 2062:     my $rolehash = {
 2063:                      'roles'    => $courseroles,
 2064:                      'seccount' => $seccount,
 2065:                      'privs'    => $courseprivs,
 2066:                    };
 2067:     &Apache::lonnet::do_cache_new('getcourseroles',$cdom.'_'.$cnum,$rolehash);
 2068:     return;
 2069: }
 2070: 
 2071: sub jump_to_role {
 2072:     my ($cdom,$cnum,$seccount,$courseroles,$courseprivs,$priv) = @_;
 2073:     my %lt = &Apache::lonlocal::texthash(
 2074:                 this => 'This role has section(s) associated with it.',
 2075:                 ente => 'Enter a specific section.',
 2076:                 orlb => 'Enter a specific section, or leave blank for no section.',
 2077:                 avai => 'Available sections are:',
 2078:                 youe => 'You entered an invalid section choice:',
 2079:                 plst => 'Please try again.',
 2080:                 role => 'The role you selected is not permitted to view the current page.',
 2081:                 swit => 'Switch role, but display Main Menu page instead?',
 2082:     );
 2083:     my $js;
 2084:     if (ref($courseroles) eq 'HASH') {
 2085:         $js = '    var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n". 
 2086:               '    var numsec = new Array();'."\n".
 2087:               '    var rolesections = new Array();'."\n".
 2088:               '    var rolenames = new Array();'."\n".
 2089:               '    var roleseclist = new Array();'."\n";
 2090:         my @items = keys(%{$courseroles});
 2091:         for (my $i=0; $i<@items; $i++) {
 2092:             $js .= '    rolenames['.$i.'] = "'.$items[$i].'";'."\n";
 2093:             my ($secs,$secstr);
 2094:             if (ref($courseroles->{$items[$i]}) eq 'ARRAY') {
 2095:                 my @sections = sort { $a <=> $b } @{$courseroles->{$items[$i]}};
 2096:                 $secs = join('","',@sections);
 2097:                 $secstr = join(', ',@sections);
 2098:             }
 2099:             $js .= '    rolesections['.$i.'] = new Array("'.$secs.'");'."\n".
 2100:                    '    roleseclist['.$i.'] = "'.$secstr.'";'."\n".
 2101:                    '    numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n";
 2102:         }
 2103:     }
 2104:     my $checkroles = 0;
 2105:     if ($priv && ref($courseprivs) eq 'HASH') {
 2106:         my (%disallowed,%allowed,@disallow);
 2107:         foreach my $role (sort(keys(%{$courseprivs}))) {
 2108:             my $trole;
 2109:             if ($role =~ m{^(.+?)\Q./$cdom/$cnum\E}) {
 2110:                 $trole = $1;
 2111:             }
 2112:             if (($trole ne '') && ($trole ne 'cm')) {
 2113:                 if ($courseprivs->{$role} =~ /\Q:$priv\E($|:|\&\w+)/) {
 2114:                     $allowed{$trole} = 1;
 2115:                 } else {
 2116:                     $disallowed{$trole} = 1;
 2117:                 }
 2118:             }
 2119:         }
 2120:         foreach my $trole (keys(%disallowed)) {
 2121:             unless ($allowed{$trole}) {
 2122:                 push(@disallow,$trole);
 2123:             }
 2124:         }
 2125:         if (@disallow > 0) {
 2126:             $checkroles = 1;
 2127:             $js .= "    var disallow = new Array('".join("','",@disallow)."');\n".
 2128:                    "    var rolecheck = 1;\n";
 2129:         }
 2130:     }
 2131:     if (!$checkroles) {
 2132:         $js .=  "    var disallow = new Array();\n".
 2133:                 "    rolecheck = 0;\n";
 2134:     }
 2135:     return <<"END";
 2136: <script type="text/javascript">
 2137: //<![CDATA[
 2138: function adhocRole(newrole) {
 2139:     $js
 2140:     if (newrole == '') {
 2141:         return;
 2142:     } 
 2143:     var fullrole = newrole+'./$cdom/$cnum';
 2144:     var selidx = '';
 2145:     for (var i=0; i<rolenames.length; i++) {
 2146:         if (rolenames[i] == newrole) {
 2147:             selidx = i;
 2148:         }
 2149:     }
 2150:     if (rolecheck > 0) {
 2151:         for (var i=0; i<disallow.length; i++) {
 2152:             if (disallow[i] == newrole) {
 2153:                 if (confirm("$lt{'role'}\\n$lt{'swit'}")) {
 2154:                     document.rolechooser.destinationurl.value = '/adm/menu';
 2155:                 } else {
 2156:                     return;
 2157:                 }
 2158:             }
 2159:         }
 2160:     }
 2161:     var secok = 1;
 2162:     var secchoice = '';
 2163:     if (selidx >= 0) {
 2164:         if (numsec[selidx] > 1) {
 2165:             secok = 0;
 2166:             var numrolesec = rolesections[selidx].length;
 2167:             var msgidx = numsec[selidx] - numrolesec;
 2168:             secchoice = prompt("$lt{'this'} "+secpick[msgidx]+"\\n$lt{'avai'} "+roleseclist[selidx],"");
 2169:             if (secchoice == '') {
 2170:                 if (msgidx > 0) {
 2171:                     secok = 1;
 2172:                 }
 2173:             } else {
 2174:                 for (var j=0; j<rolesections[selidx].length; j++) {
 2175:                     if (rolesections[selidx][j] == secchoice) {
 2176:                         secok = 1;
 2177:                     }
 2178:                 }
 2179:             }
 2180:         } else {
 2181:             if (rolesections[selidx].length == 1) {
 2182:                 secchoice = rolesections[selidx][0];
 2183:             }
 2184:         }
 2185:     }
 2186:     if (secok == 1) {
 2187:         if (secchoice != '') {
 2188:             fullrole += '/'+secchoice;
 2189:         }
 2190:     } else {
 2191:         if (secchoice != null) {
 2192:             alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}");
 2193:         }
 2194:         return;
 2195:     }
 2196:     if (fullrole == "$env{'request.role'}") {
 2197:         return;
 2198:     }
 2199:     itemid = retrieveIndex('gotorole');
 2200:     if (itemid != -1) {
 2201:         document.rolechooser.elements[itemid].name = fullrole;
 2202:     }
 2203:     document.rolechooser.switchrole.value = fullrole;
 2204:     document.rolechooser.selectrole.value = '1';
 2205:     document.rolechooser.submit();
 2206:     return;
 2207: }
 2208: 
 2209: function retrieveIndex(item) {
 2210:     for (var i=0;i<document.rolechooser.elements.length;i++) {
 2211:         if (document.rolechooser.elements[i].name == item) {
 2212:             return i;
 2213:         }
 2214:     }
 2215:     return -1;
 2216: }
 2217: // ]]>
 2218: </script>
 2219: END
 2220: }
 2221: 
 2222: sub required_privs {
 2223:     my $privs =  {
 2224:              '/adm/parmset'      => 'opa',
 2225:              '/adm/courseprefs'  => 'opa',
 2226:              '/adm/whatsnew'     => 'whn',
 2227:              '/adm/populate'     => 'cst',
 2228:              '/adm/trackstudent' => 'vsa',
 2229:              '/adm/statistics'   => 'vgr',
 2230:              '/adm/setblock'     => 'dcm',
 2231:              '/adm/coursedocs'   => 'mdc',
 2232:            };
 2233:     unless ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'spreadsheet') {
 2234:         $privs->{'/adm/classcalc'}   = 'vgr',
 2235:         $privs->{'/adm/assesscalc'}  = 'vgr',
 2236:         $privs->{'/adm/studentcalc'} = 'vgr';
 2237:     }
 2238:     return $privs;
 2239: }
 2240: 
 2241: sub countdown_timer {
 2242:     if (($env{'request.course.id'}) && ($env{'request.symb'} ne '') &&
 2243:         ($env{'request.filename'}=~/$LONCAPA::assess_re/)) {
 2244:         my ($type,$hastimeleft,$slothastime);
 2245:         my $now = time;
 2246:         if ($env{'request.filename'} =~ /\.task$/) {
 2247:             $type = 'Task';
 2248:         } else {
 2249:             $type = 'problem';
 2250:         }
 2251:         my ($status,$accessmsg,$slot_name,$slot) =
 2252:             &Apache::lonhomework::check_slot_access('0',$type);
 2253:         if ($slot_name ne '') {
 2254:             if (ref($slot) eq 'HASH') {
 2255:                 if (($slot->{'starttime'} < $now) &&
 2256:                     ($slot->{'endtime'} > $now)) {
 2257:                     $slothastime = 1;
 2258:                 }
 2259:             }
 2260:         }
 2261:         if ($status ne 'CAN_ANSWER') {
 2262:             return;
 2263:         }
 2264:         my $duedate = &Apache::lonnet::EXT("resource.0.duedate");
 2265:         my @interval=&Apache::lonnet::EXT("resource.0.interval");
 2266:         if (@interval > 1) {
 2267:             my $first_access=&Apache::lonnet::get_first_access($interval[1]);
 2268:             if ($first_access > 0) {
 2269:                 if ($first_access+$interval[0] > time) {
 2270:                     $hastimeleft = 1;
 2271:                 }
 2272:             }
 2273:         }
 2274:         if (($duedate && $duedate > time) ||
 2275:             (!$duedate && $hastimeleft) ||
 2276:             ($slot_name ne '' && $slothastime)) {
 2277:             my ($collapse,$expand,$alttxt,$title,$currdisp,$donebutton);
 2278:             if ((@interval > 1 && $hastimeleft) ||
 2279:                 ($type eq 'Task' && $slothastime)) {
 2280:                 $currdisp = 'inline';
 2281:                 $collapse = '&#9658;&nbsp;';
 2282:                 if ((@interval > 1) && ($hastimeleft)) {
 2283:                     $donebutton = &done_button_js($interval[1]);
 2284:                 }
 2285:             } else {
 2286:                 $currdisp = 'none';
 2287:                 $expand = '&#9668;&nbsp;';
 2288:             }
 2289:             unless ($env{'environment.icons'} eq 'iconsonly') {
 2290:                 $alttxt = &mt('Timer');
 2291:                 $title = $alttxt.'&nbsp;';
 2292:             }
 2293:             my $desc = &mt('Countdown to due date/time');
 2294: 
 2295:             return <<END;
 2296: $donebutton
 2297: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
 2298: <span id="ddcountcollapse" class="LC_menubuttons_inline_text">
 2299: $collapse
 2300: </span></a>
 2301: <span id="duedatecountdown" class="LC_menubuttons_inline_text" style="display: $currdisp;"></span>
 2302: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
 2303: <span id="ddcountexpand" class="LC_menubuttons_inline_text" >$expand</span>
 2304: <img src="/res/adm/pages/timer.png" title="$desc" class="LC_icon" alt="$alttxt" /><span class="LC_menubuttons_inline_text">$title</span></a>
 2305: END
 2306:         }
 2307:     }
 2308:     return;
 2309: }
 2310: 
 2311: # ================================================================ Main Program
 2312: 
 2313: BEGIN {
 2314:     if (! defined($readdesk)) {
 2315:         {
 2316:             my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
 2317:             if ( CORE::open( my $config,"<$tabfile") ) {
 2318:                 while (my $configline=<$config>) {
 2319:                     $configline=(split(/\#/,$configline))[0];
 2320:                     $configline=~s/^\s+//;
 2321:                     chomp($configline);
 2322:                     if ($configline=~/^cat\:/) {
 2323:                         my @entries=split(/\:/,$configline);
 2324:                         $category_positions{$entries[2]}=$entries[1];
 2325:                         $category_names{$entries[2]}=$entries[3];
 2326:                     } elsif ($configline=~/^prim\:/) {
 2327:                         my @entries = (split(/\:/, $configline))[1..6];
 2328:                         push(@primary_menu,\@entries);
 2329:                     } elsif ($configline=~/^primsub\:/) {
 2330:                         my ($parent,@entries) = (split(/\:/, $configline))[1..4];
 2331:                         push(@{$primary_submenu{$parent}},\@entries);
 2332:                     } elsif ($configline=~/^scnd\:/) {
 2333:                         my @entries = (split(/\:/, $configline))[1..5];
 2334:                         push(@secondary_menu,\@entries);
 2335:                     } elsif ($configline) {
 2336:                         push(@desklines,$configline);
 2337:                     }
 2338:                 }
 2339:                 CORE::close($config);
 2340:             }
 2341:         }
 2342:         $readdesk='done';
 2343:     }
 2344: }
 2345: 
 2346: 1;
 2347: __END__
 2348: 

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