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

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

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