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

1.1       www         1: # The LearningOnline Network with CAPA
                      2: # Routines to control the menu
                      3: #
1.433   ! raeburn     4: # $Id: lonmenu.pm,v 1.432 2015/04/16 10:13:25 droeschl 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.417     raeburn   374:     my ($cdom,$cnum,$showsyllabus,$showfeeds,$showresv);
1.413     raeburn   375:     if ($env{'request.course.id'}) {
                    376:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                    377:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                    378:         if ($canedit) {
                    379:             $showsyllabus = 1;
                    380:             $showfeeds = 1;
                    381:         } else {
1.414     raeburn   382:             unless (&Apache::lonnet::is_on_map("public/$cdom/$cnum/syllabus")) {
                    383:                 if (($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'}) ||
                    384:                     ($env{'course.'.$env{'request.course.id'}.'.uploadedsyllabus'}) ||
                    385:                     ($env{'course.'.$env{'request.course.id'}.'.updatedsyllabus'}) ||
                    386:                     ($env{'request.course.syllabustime'})) {
                    387:                     $showsyllabus = 1;
                    388:                 }
                    389:             }
                    390:             if ($env{'request.course.feeds'}) {
                    391:                 $showfeeds = 1;
1.413     raeburn   392:             }
                    393:         }
1.417     raeburn   394:         unless ($canmgr) {
                    395:             my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
                    396:             if (keys(%slots) > 0) {
                    397:                 $showresv = 1;
                    398:             }
                    399:         }
1.413     raeburn   400:     }
                    401: 
1.404     raeburn   402:     my ($canmodifycoauthor); 
                    403:     if ($env{'request.role'} eq "au./$env{'user.domain'}/") {
                    404:         my $extent = "$env{'user.domain'}/$env{'user.name'}";
                    405:         if ((&Apache::lonnet::allowed('cca',$extent)) ||
                    406:             (&Apache::lonnet::allowed('caa',$extent))) {
                    407:             $canmodifycoauthor = 1;
                    408:         }
                    409:     }
                    410: 
1.286     raeburn   411:     my %groups = &Apache::lonnet::get_active_groups(
                    412:                      $env{'user.domain'}, $env{'user.name'},
                    413:                      $env{'course.' . $env{'request.course.id'} . '.domain'},
                    414:                      $env{'course.' . $env{'request.course.id'} . '.num'});
1.327     droeschl  415: 
1.401     raeburn   416:     my ($roleswitcher_js,$roleswitcher_form);
                    417: 
1.283     droeschl  418:     foreach my $menuitem (@secondary_menu) {
                    419:         # evaluate conditions 
1.296     droeschl  420:         next if    ref($menuitem)  ne 'ARRAY';
1.283     droeschl  421:         next if    $$menuitem[4]   ne 'always'
1.404     raeburn   422:                 && ($$menuitem[4]   ne 'author' && $$menuitem[4] ne 'cca')
1.283     droeschl  423:                 && !$env{'request.course.id'};
                    424:         next if    $$menuitem[4]   =~ /^mdc/
1.286     raeburn   425:                 && !$canedit;
1.341     www       426:         next if    $$menuitem[4]  eq 'nvgr'
                    427:                 && $canvgr;
                    428:         next if    $$menuitem[4]  eq 'vgr'
                    429:                 && !$canvgr;
1.327     droeschl  430:         next if    $$menuitem[4]   eq 'cst'
                    431:                 && !$canmodifyuser;
1.343     www       432:         next if    $$menuitem[4]   eq 'ncst'
1.376     raeburn   433:                 && ($canmodifyuser || !$canviewroster);
1.343     www       434:         next if    $$menuitem[4]   eq 'mgr'
                    435:                 && !$canmgr;
1.417     raeburn   436:         next if    $$menuitem[4]   eq 'showresv'
                    437:                 && !$showresv;
1.327     droeschl  438:         next if    $$menuitem[4]   eq 'whn'
                    439:                 && !$canviewwnew;
                    440:         next if    $$menuitem[4]   eq 'opa'
                    441:                 && !$canmodpara;
1.283     droeschl  442:         next if    $$menuitem[4]   =~ /showgroups$/
1.300     raeburn   443:                 && !$canviewgrps
1.286     raeburn   444:                 && !%groups;
1.413     raeburn   445:         next if    $$menuitem[4]   eq 'showsyllabus'
                    446:                 && !$showsyllabus;
                    447:         next if    $$menuitem[4]   eq 'showfeeds'
                    448:                 && !$showfeeds;
1.329     droeschl  449:         next if    $$menuitem[4]    eq 'author'
                    450:                 && !$author;
1.404     raeburn   451:         next if    $$menuitem[4]    eq 'cca'
                    452:                 && !$canmodifycoauthor;
1.283     droeschl  453: 
1.286     raeburn   454:         if ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) {
1.283     droeschl  455:             # special treatment for role selector
1.401     raeburn   456:             ($roleswitcher_js,$roleswitcher_form,my $switcher) =
                    457:                 &roles_selector(
1.283     droeschl  458:                         $env{'course.' . $env{'request.course.id'} . '.domain'},
1.421     raeburn   459:                         $env{'course.' . $env{'request.course.id'} . '.num'},
                    460:                         $httphost
1.401     raeburn   461:                 );
                    462:             $menu .= $switcher;
1.296     droeschl  463:         } else {
1.414     raeburn   464:             if ($$menuitem[3] eq 'Syllabus' && $env{'request.course.id'}) {
                    465:                 my $url = $$menuitem[0];
                    466:                 $url =~ s{\[cdom\]/\[cnum\]}{$cdom/$cnum};
                    467:                 if (&Apache::lonnet::is_on_map($url)) {
                    468:                     unless ($$menuitem[0] =~ /\?register=1/) {
                    469:                         $$menuitem[0] .= '?register=1';
                    470:                     }
                    471:                 } else {
                    472:                     $$menuitem[0] =~ s{\?register=1}{};
                    473:                 }
                    474:             }
1.296     droeschl  475:             $menu .= &prep_menuitem(\@$menuitem);
1.283     droeschl  476:         }
                    477:     }
                    478:     if ($menu =~ /\[url\].*\[symb\]/) {
1.291     raeburn   479:         my $escurl  = &escape( &Apache::lonenc::check_encrypt(
                    480:                              $env{'request.noversionuri'}));
1.283     droeschl  481: 
1.291     raeburn   482:         my $escsymb = &escape( &Apache::lonenc::check_encrypt(
                    483:                              $env{'request.symb'})); 
1.283     droeschl  484: 
                    485:         if (    $env{'request.state'} eq 'construct'
                    486:             and (   $env{'request.noversionuri'} eq '' 
                    487:                  || !defined($env{'request.noversionuri'}))) 
                    488:         {
1.359     raeburn   489:             my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
                    490:             ($escurl = $env{'request.filename'}) =~ s{^\Q$londocroot\E}{};
1.291     raeburn   491:             $escurl  = &escape($escurl);
1.283     droeschl  492:         }    
                    493:         $menu =~ s/\[url\]/$escurl/g;
                    494:         $menu =~ s/\[symb\]/$escsymb/g;
                    495:     }
1.329     droeschl  496:     $menu =~ s/\[uname\]/$$author{user}/g;
                    497:     $menu =~ s/\[udom\]/$$author{dom}/g;
1.413     raeburn   498:     if ($showsyllabus || $showfeeds) {
                    499:         $menu =~ s/\[cnum\]/$cnum/g;
                    500:         $menu =~ s/\[cdom\]/$cdom/g;
                    501:     }
1.385     raeburn   502:     if ($menu) {
                    503:         $menu = "<ul id=\"LC_secondary_menu\">$menu</ul>";
                    504:     }
1.401     raeburn   505:     if ($roleswitcher_form) {
                    506:         $menu .= "\n$roleswitcher_js\n$roleswitcher_form";
                    507:     }
1.385     raeburn   508:     return $menu;
1.283     droeschl  509: }
                    510: 
1.375     raeburn   511: sub create_submenu {
1.419     bisitz    512:     my ($link,$target,$title,$submenu,$translate) = @_;
1.375     raeburn   513:     return unless (ref($submenu) eq 'ARRAY');
1.379     raeburn   514:     my $disptarget;
                    515:     if ($target ne '') {
                    516:         $disptarget = ' target="'.$target.'"';
                    517:     }
1.375     raeburn   518:     my $menu = '<li class="LC_hoverable">'.
1.379     raeburn   519:                '<a href="'.$link.'"'.$disptarget.'>'.
1.432     droeschl  520:                '<span class="LC_nobreak">'.$title.
1.375     raeburn   521:                '<span class="LC_fontsize_small" style="font-weight:normal;">'.
                    522:                ' &#9660;</span></span></a>'.
                    523:                '<ul>';
1.431     golterma  524: 
                    525:     # $link and $title are only used in the initial string written in $menu
                    526:     # as seen above, not needed for nested submenus
                    527:     $menu .= &build_submenu($target, $submenu, $translate, '1');
                    528:     $menu .= '</ul></li>';
                    529: 
                    530:     return $menu;
                    531: }
                    532: 
                    533: # helper routine for create_submenu
                    534: # build the dropdown (and nested submenus) recursively
                    535: # see perldoc create_submenu documentation for further information
                    536: sub build_submenu {
                    537:     my ($target, $submenu, $translate, $first_level) = @_; 
                    538:     if (!defined(@{$submenu})) {
                    539:         return '';
                    540:     }
                    541: 
                    542:     my $menu = '';
1.375     raeburn   543:     my $count = 0;
                    544:     my $numsub = scalar(@{$submenu});
                    545:     foreach my $item (@{$submenu}) {
                    546:         $count ++;
                    547:         if (ref($item) eq 'ARRAY') {
1.416     raeburn   548:             my $href = $item->[0];
1.431     golterma  549:             my $bordertop;
                    550:             my $borderbot;
                    551:             my $title;
                    552: 
                    553:             if ($translate) {
                    554:                  $title = &mt($item->[1]);
                    555:             } else {
                    556:                 $title = $item->[1];
                    557:             }
                    558: 
                    559:             if ($count == 1 && !$first_level) {
                    560:                 $bordertop = 'border-top: 1px solid black;';
1.416     raeburn   561:             }
1.375     raeburn   562:             if ($count == $numsub) {
1.431     golterma  563:                 $borderbot = 'border-bottom: 1px solid black;';
1.375     raeburn   564:             }
1.431     golterma  565: 
                    566:             # href is a reference to another submenu
                    567:             if (ref($href) eq 'ARRAY') {
                    568:                 $menu .= '<li style="margin:0;padding:0;'.$bordertop . $borderbot . '">';
                    569:                 $menu .= '<p><span class="LC_primary_menu_innertitle">'
                    570: 					. $title . '</span><span class="LC_primary_menu_innerarrow">&#9654;</span></p>';
                    571:                 $menu .= '<ul>';
                    572:                 $menu .= &build_submenu($target, $href, $translate);
                    573:                 $menu .= '</ul>';
                    574:                 $menu .= '</li>';    
                    575:             } else {    # href is the actual hyperlink and does not represent another submenu
                    576:                         # for the current menu title
                    577:                 if ($href =~ /(aboutme|rss\.html)$/) {
                    578:                     next unless (($env{'user.name'} ne '') && ($env{'user.domain'} ne ''));
                    579:                     $href =~ s/\[domain\]/$env{'user.domain'}/g;
                    580:                     $href =~ s/\[user\]/$env{'user.name'}/g;
                    581:                 }
                    582:                 unless (($href eq '') || ($href =~ /^\#/)) {
                    583:                     $target = ' target="_top"';
                    584:                 }
                    585: 
                    586:                 $menu .= '<li style="margin:0;padding:0;'. $bordertop . $borderbot .'">';
                    587:                 $menu .= '<a href="'.$href.'"'.$target.'>' .  $title . '</a>';
                    588:                 $menu .= '</li>';
1.425     raeburn   589:             }
1.375     raeburn   590:         }
                    591:     }
                    592:     return $menu;
                    593: }
                    594: 
1.40      www       595: sub innerregister {
1.390     raeburn   596:     my ($forcereg,$bread_crumbs,$group) = @_;
1.152     albertel  597:     my $const_space = ($env{'request.state'} eq 'construct');
1.131     raeburn   598:     my $is_const_dir = 0;
1.120     raeburn   599: 
1.175     albertel  600:     if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
1.40      www       601: 
1.174     albertel  602:     $env{'request.registered'} = 1;
1.40      www       603: 
1.177     albertel  604:     undef(@inlineremote);
1.56      www       605: 
1.393     raeburn   606:     my ($mapurl,$resurl);
1.390     raeburn   607: 
1.393     raeburn   608:     if ($env{'request.course.id'}) {
                    609:         if ($env{'request.symb'}) {
                    610:             ($mapurl, my $rid, $resurl) = &Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
                    611:             my $coursetitle = $env{'course.'.$env{'request.course.id'}.'.description'};
1.267     droeschl  612: 
1.393     raeburn   613:             my $maptitle = &Apache::lonnet::gettitle($mapurl);
                    614:             my $restitle = &Apache::lonnet::gettitle(&Apache::lonnet::symbread());
1.318     droeschl  615: 
                    616: #SD
                    617: #course_type only Course and Community?
                    618: #
1.393     raeburn   619:             my @crumbs;
                    620:             unless (($forcereg) &&
                    621:                     ($env{'request.noversionuri'} eq '/adm/navmaps') &&
                    622:                     ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'})) {
                    623:                 @crumbs = ({text  => Apache::loncommon::course_type() 
                    624:                                     . ' Contents', 
                    625:                             href  => "Javascript:gopost('/adm/navmaps','')"});
                    626:             }
                    627:             if ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) { 
                    628:                 push(@crumbs, {text  => '...',
                    629:                                no_mt => 1});
                    630:             }
                    631: 
                    632:             push @crumbs, {text => $maptitle, no_mt => 1} if ($maptitle 
                    633:                                                        && $maptitle ne 'default.sequence' 
                    634:                                                        && $maptitle ne $coursetitle);
1.268     droeschl  635: 
1.393     raeburn   636:             push @crumbs, {text => $restitle, no_mt => 1} if $restitle; 
                    637:             &Apache::lonhtmlcommon::clear_breadcrumbs();
                    638:             &Apache::lonhtmlcommon::add_breadcrumb(@crumbs);
                    639:         } else {
                    640:             $resurl = $env{'request.noversionuri'};
                    641:             my $courseurl = &Apache::lonnet::courseid_to_courseurl($env{'request.course.id'});
                    642:             my $crstype = &Apache::loncommon::course_type();
                    643:             my $title = &mt('View Resource');
                    644:             if ($resurl =~ m{^\Q/uploaded$courseurl/supplemental/\E(default|\d+)/}) {
                    645:                 &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folderpath','title']);
1.392     raeburn   646:                 &Apache::lonhtmlcommon::clear_breadcrumbs();
1.393     raeburn   647:                 if ($env{'form.title'}) {
                    648:                     $title = $env{'form.title'};
                    649:                 }
1.394     raeburn   650:                 my $trail;
1.393     raeburn   651:                 if ($env{'form.folderpath'}) {
1.399     raeburn   652:                     &prepare_functions($resurl,$forcereg,$group,undef,undef,1);
1.394     raeburn   653:                     ($trail) =
1.393     raeburn   654:                         &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
                    655:                 } else {
                    656:                     &Apache::lonhtmlcommon::add_breadcrumb(
1.392     raeburn   657:                     {text  => "Supplemental $crstype Content",
                    658:                      href  => "javascript:gopost('/adm/supplemental','')"});
1.393     raeburn   659:                     $title = &mt('View Resource');
1.394     raeburn   660:                     ($trail) = 
                    661:                         &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
1.392     raeburn   662:                 }
1.394     raeburn   663:                 return $trail;
1.412     raeburn   664:             } elsif ($resurl =~ m{^\Q/uploaded$courseurl/portfolio/syllabus/}) {
                    665:                 &Apache::lonhtmlcommon::clear_breadcrumbs();
                    666:                 &prepare_functions('/public'.$courseurl."/syllabus",
                    667:                                    $forcereg,$group,undef,undef,1);
                    668:                 $title = &mt('Syllabus File');
                    669:                 my ($trail) =
                    670:                     &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
                    671:                 return $trail;
1.392     raeburn   672:             }
1.395     raeburn   673:             unless ($env{'request.state'} eq 'construct') {
                    674:                 &Apache::lonhtmlcommon::clear_breadcrumbs();
                    675:                 &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
                    676:             }
1.392     raeburn   677:         }
1.390     raeburn   678:     } elsif (! $const_space){
1.328     droeschl  679:         #a situation when we're looking at a resource outside of context of a 
                    680:         #course or construction space (e.g. with cumulative rights)
                    681:         &Apache::lonhtmlcommon::clear_breadcrumbs();
1.390     raeburn   682:         unless ($env{'request.noversionuri'} =~ m{^/adm/$match_domain/$match_username/aboutme$}) {
                    683:             &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
                    684:         }
1.65      www       685:     }
1.41      www       686: # =============================================================================
                    687: # ============================ This is for URLs that actually can be registered
1.316     droeschl  688:     return '' unless ( ($env{'request.noversionuri'}!~m{^/(res/)*adm/}) 
                    689:                        || $forcereg );
1.390     raeburn   690:     my ($cdom,$cnum,%perms,$cfile,$switchserver,$home,$forceedit,
                    691:         $forceview,$editbutton);
1.391     raeburn   692:     if (($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) ||
                    693:         ($env{'request.role'} !~/^(aa|ca|au)/)) {
1.390     raeburn   694:         $editbutton = &prepare_functions($resurl,$forcereg,$group);
                    695:     }
                    696:     if ($editbutton eq '') {
1.399     raeburn   697:         $editbutton = &clear(6,1);
1.390     raeburn   698:     }
1.317     droeschl  699: 
1.390     raeburn   700: #
                    701: # This applies in course context
                    702: #
                    703:     if ($env{'request.course.id'}) {
                    704:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                    705:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                    706:         $perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
                    707:         my @privs;
                    708:         if ($env{'request.symb'} ne '') {
                    709:              if ($env{'request.filename'}=~/$LONCAPA::assess_re/) {
                    710:                  push(@privs,('mgr','vgr'));
                    711:              }
                    712:              push(@privs,'opa');
                    713:         }
                    714:         foreach my $priv (@privs) {
                    715:             $perms{$priv} = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
                    716:             if (!$perms{$priv} && $env{'request.course.sec'} ne '') {
                    717:                 $perms{$priv} = 
                    718:                     &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
                    719:             }
                    720:         }
                    721: #
                    722: # Determine whether or not to show Grades and Submissions buttons
                    723: #
                    724:         if ($env{'request.symb'} ne '' &&
                    725:             $env{'request.filename'}=~/$LONCAPA::assess_re/) {
                    726:             if ($perms{'mgr'}) {
                    727:                 &switch('','',7,2,'pgrd.png','Content Grades','grades[_4]',
                    728:                         "gocmd('/adm/grades','gradingmenu')",
                    729:                         'Content Grades');
                    730:             } elsif ($perms{'vgr'}) {
                    731:                 &switch('','',7,2,'subm.png','Content Submissions','missions[_1]',
                    732:                         "gocmd('/adm/grades','submission')",
                    733:                         'Content Submissions');
                    734:              }
                    735:         }
                    736:         if (($env{'request.symb'} ne '') && ($perms{'opa'})) {
                    737:             &switch('','',7,3,'pparm.png','Content Settings','parms[_2]',
                    738:                     "gocmd('/adm/parmset','set')",
                    739:                     'Content Settings');
1.107     albertel  740: 	}
1.393     raeburn   741: # End grades/submissions check
1.107     albertel  742: 
1.274     www       743: #
1.393     raeburn   744: # This applies to items inside a folder/page modifiable in the course.
1.274     www       745: #
1.390     raeburn   746:         if (($env{'request.symb'}=~/^uploaded/) && ($perms{'mdc'})) {
1.393     raeburn   747:             my $text = 'Edit Folder';
1.395     raeburn   748:             if (($mapurl =~ /\.page$/) ||
                    749:                 ($env{'request.symb'}=~
1.396     raeburn   750:                      m{uploaded/$cdom/$cnum/default_\d+\.page$}))  {
1.393     raeburn   751:                 $text = 'Edit Page';
                    752:             }
                    753:             &switch('','',7,4,'docs-22x22.png',$text,'parms[_2]',
1.390     raeburn   754:                     "gocmd('/adm/coursedocs','direct')",
                    755:                     'Folder/Page Content');
1.258     raeburn   756:         }
1.390     raeburn   757: # End modifiable folder/page container check
                    758:     }
                    759: # End course context
                    760: 
1.41      www       761: # Prepare the rest of the buttons
1.383     raeburn   762:         my ($menuitems,$got_prt,$got_wishlist);
1.120     raeburn   763:         if ($const_space) {
1.274     www       764: #
                    765: # We are in construction space
                    766: #
1.353     www       767: 
1.355     raeburn   768:             my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.353     www       769: 	    my ($udom,$uname,$thisdisfn) =
1.355     raeburn   770: 		($env{'request.filename'}=~m{^\Q$londocroot/priv/\E([^/]+)/([^/]+)/(.*)$});
1.353     www       771:             my $currdir = '/priv/'.$udom.'/'.$uname.'/'.$thisdisfn;
1.131     raeburn   772:             if ($currdir =~ m-/$-) {
                    773:                 $is_const_dir = 1;
1.433   ! raeburn   774:                 if ($thisdisfn eq '') {
        !           775:                     $is_const_dir = 2;
        !           776:                 }
1.131     raeburn   777:             } else {
1.267     droeschl  778:                 $currdir =~ s|[^/]+$||;
1.200     foxr      779: 		my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn);
1.208     albertel  780: 		my $esc_currdir = &Apache::loncommon::escape_single($currdir);
1.274     www       781: #
                    782: # Probably should be in mydesk.tab
                    783: #
1.131     raeburn   784:                 $menuitems=(<<ENDMENUITEMS);
1.344     www       785: s&6&1&list.png&Directory&dir[_1]&golist('$esc_currdir')&List current directory
1.353     www       786: s&6&2&rtrv.png&Retrieve&version[_1]&gocstr('/adm/retrieve','/priv/$udom/$uname/$cleandisfn')&Retrieve old version
                    787: s&6&3&pub.png&Publish&resource[_3]&gocstr('/adm/publish','/priv/$udom/$uname/$cleandisfn')&Publish this resource
                    788: s&7&1&del.png&Delete&resource[_2]&gocstr('/adm/cfile?action=delete','/priv/$udom/$uname/$cleandisfn')&Delete this resource
                    789: s&7&2&prt.png&Print&printout[_1]&gocstr('/adm/printout','/priv/$udom/$uname/$cleandisfn')&Prepare a printable document
1.120     raeburn   790: ENDMENUITEMS
1.131     raeburn   791:             }
1.308     raeburn   792:                 if (ref($bread_crumbs) eq 'ARRAY') {
                    793:                     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    794:                     foreach my $crumb (@{$bread_crumbs}){
                    795:                         &Apache::lonhtmlcommon::add_breadcrumb($crumb);
                    796:                     }
                    797:                 }
1.203     foxr      798:         } elsif ( defined($env{'request.course.id'}) && 
                    799: 		 $env{'request.symb'} ne '' ) {
1.274     www       800: #
1.383     raeburn   801: # We are in a course and looking at a registered URL
1.274     www       802: # Should probably be in mydesk.tab
                    803: #
1.120     raeburn   804: 	    $menuitems=(<<ENDMENUITEMS);
1.41      www       805: c&3&1
1.344     www       806: s&2&1&back.png&&&gopost('/adm/flip','back:'+currentURL)&Previous content resource&&1
                    807: s&2&3&forw.png&&&gopost('/adm/flip','forward:'+currentURL)&Next content resource&&3
1.77      www       808: c&6&3
                    809: c&8&1
                    810: c&8&2
1.344     www       811: s&8&3&prt.png&Print&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
1.41      www       812: ENDMENUITEMS
1.383     raeburn   813:             $got_prt = 1;
                    814:             if (($env{'user.adv'}) && ($env{'request.uri'} =~ /^\/res/)
                    815:                 && (!$env{'request.enc'})) {
1.332     wenzelju  816:                 # wishlist is only available for users with access to resource-pool
                    817:                 # and links can only be set for resources within the resource-pool
                    818:                 $menuitems .= (<<ENDMENUITEMS);
1.431     golterma  819: 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  820: ENDMENUITEMS
1.383     raeburn   821:                 $got_wishlist = 1;
1.332     wenzelju  822:             }
1.216     albertel  823: 
1.243     tempelho  824: my $currentURL = &Apache::loncommon::get_symb();
                    825: my ($symb_old,$symb_old_enc) = &Apache::loncommon::clean_symb($currentURL);
                    826: my $annotation = &Apache::loncommon::get_annotation($symb_old,$symb_old_enc);
                    827: $menuitems.="s&9&3&";
                    828: if(length($annotation) > 0){
1.317     droeschl  829: 	$menuitems.="anot2.png";
1.243     tempelho  830: }else{
1.317     droeschl  831: 	$menuitems.="anot.png";
1.243     tempelho  832: }
1.344     www       833: $menuitems.="&Notes&&annotate()&";
1.243     tempelho  834: $menuitems.="Make notes and annotations about this resource&&1\n";
1.428     raeburn   835: my $is_mobile;
                    836: if ($env{'browser.mobile'}) {
                    837:     $is_mobile = 1;
                    838: }
1.243     tempelho  839: 
1.323     raeburn   840:             unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|viewclasslist|portfolio)(\?|$)/) {
1.382     raeburn   841: 		if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/}) && ($env{'request.noversionuri'} !~ m{^/uploaded/$match_domain/$match_courseid/docs/})) {
1.216     albertel  842: 		    $menuitems.=(<<ENDREALRES);
1.428     raeburn   843: s&6&3&catalog.png&Info&info[_1]&catalog_info('$is_mobile')&Show Metadata
1.216     albertel  844: ENDREALRES
                    845:                 }
1.422     raeburn   846:                 unless (($env{'request.noversionuri'} =~ m{^/uploaded/$match_domain/$match_courseid/docs/}) ||
                    847:                         ($env{'request.noversionuri'} =~ m{^\Q/adm/wrapper/\E(ext|uploaded)/})) {  
1.382     raeburn   848:                     $menuitems.=(<<ENDREALRES);
1.344     www       849: s&8&1&eval.png&Evaluate&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
1.382     raeburn   850: ENDREALRES
                    851:                 }
1.422     raeburn   852:                 unless ($env{'request.noversionuri'} =~ m{^\Q/adm/wrapper/\E(ext|uploaded)/}) {
                    853:                     $menuitems.=(<<ENDREALRES);
1.344     www       854: 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       855: ENDREALRES
1.422     raeburn   856:                 }
1.120     raeburn   857: 	    }
                    858:         }
1.203     foxr      859: 	if ($env{'request.uri'} =~ /^\/res/) {
1.383     raeburn   860:             unless ($got_prt) {
                    861: 	        $menuitems .= (<<ENDMENUITEMS);
1.344     www       862: s&8&3&prt.png&Print&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
1.203     foxr      863: ENDMENUITEMS
1.384     raeburn   864:                 $got_prt = 1;
1.383     raeburn   865:             }
                    866:             unless ($got_wishlist) {
                    867:                 if (($env{'user.adv'}) && (!$env{'request.enc'})) {
                    868:                     # wishlist is only available for users with access to resource-pool
                    869:                     $menuitems .= (<<ENDMENUITEMS);
1.431     golterma  870: 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  871: ENDMENUITEMS
1.383     raeburn   872:                     $got_wishlist = 1;
                    873:                 }
                    874: 	    }
                    875:         }
1.41      www       876:         my $buttons='';
                    877:         foreach (split(/\n/,$menuitems)) {
                    878: 	    my ($command,@rest)=split(/\&/,$_);
1.220     raeburn   879:             my $idx=10*$rest[0]+$rest[1];
                    880:             if (&hidden_button_check() eq 'yes') {
                    881:                 if ($idx == 21 ||$idx == 23) {
                    882:                     $buttons.=&switch('','',@rest);
                    883:                 } else {
                    884:                     $buttons.=&clear(@rest);
                    885:                 }
                    886:             } else {  
                    887:                 if ($command eq 's') {
                    888: 	            $buttons.=&switch('','',@rest);
                    889:                 } else {
                    890:                     $buttons.=&clear(@rest);
                    891:                 }
1.41      www       892:             }
                    893:         }
1.148     albertel  894: 
                    895: 	    my $addremote=0;
1.267     droeschl  896: 	    foreach (@inlineremote) { if ($_ ne '') { $addremote=1; last;} }
1.301     droeschl  897:     if ($addremote) {
                    898: 
1.342     www       899:         &Apache::lonhtmlcommon::clear_breadcrumb_tools();
1.301     droeschl  900: 
1.342     www       901:             &Apache::lonhtmlcommon::add_breadcrumb_tool(
1.312     droeschl  902:                 'navigation', @inlineremote[21,23]);
                    903: 
1.378     raeburn   904:         my $countdown = &countdown_timer();
                    905:         if (&hidden_button_check() eq 'yes') {
                    906:             if ($countdown) {
                    907:                 &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$countdown);
                    908:             }
                    909:         } else {
                    910:             my @tools = @inlineremote[93,91,81,82,83];
                    911:             if ($countdown) {
                    912:                 unshift(@tools,$countdown);
                    913:             }
1.342     www       914:             &Apache::lonhtmlcommon::add_breadcrumb_tool(
1.378     raeburn   915:                 'tools',@tools);
1.313     droeschl  916: 
                    917:             #publish button in construction space
                    918:             if ($env{'request.state'} eq 'construct'){
1.342     www       919:                 &Apache::lonhtmlcommon::add_breadcrumb_tool(
1.349     raeburn   920:                      'advtools', $inlineremote[63]);
1.342     www       921:             } else {
                    922:                 &Apache::lonhtmlcommon::add_breadcrumb_tool(
1.349     raeburn   923:                      'tools', $inlineremote[63]);
1.313     droeschl  924:             }
1.390     raeburn   925:             &advtools_crumbs(@inlineremote);
1.301     droeschl  926:         }
1.38      www       927:     }
1.433   ! raeburn   928:     my ($topic_help,$topic_help_text);
        !           929:     if ($is_const_dir == 2) {
        !           930:         if (&Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},'webdav')) {
        !           931:             $topic_help = 'Authoring_WebDAV,Authoring_WebDAV_Mac_10v6,Authoring_WebDAV_Mac_10v10,'.
        !           932:                           'Authoring_WebDAV_Windows_v7,Authoring_WebDAV_Linux_Centos';
        !           933:             $topic_help_text = 'About WebDAV access';
        !           934:         }
        !           935:     }
1.342     www       936:     return   &Apache::lonhtmlcommon::scripttag('', 'start')
1.433   ! raeburn   937:            . &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0,'','','','',$topic_help,$topic_help_text)
1.342     www       938:            . &Apache::lonhtmlcommon::scripttag('', 'end');
1.38      www       939: }
                    940: 
1.389     raeburn   941: sub get_editbutton {
1.390     raeburn   942:     my ($cfile,$home,$switchserver,$forceedit,$forceview,$forcereg) = @_;
1.398     raeburn   943:     my $jscall;
                    944:     if (($forceview) && ($env{'form.todocs'})) {
                    945:         my ($folderpath,$command);
                    946:         if ($env{'request.symb'}) {
                    947:             $folderpath = &Apache::loncommon::symb_to_docspath($env{'request.symb'});
                    948:         } elsif ($env{'form.folderpath'} =~ /^supplemental/) {
                    949:             $folderpath = $env{'form.folderpath'};
                    950:             $command = '&forcesupplement=1';
                    951:         }
                    952:         $folderpath = &escape(&HTML::Entities::encode(&escape($folderpath),'<>&"'));
                    953:         $jscall = "go('/adm/coursedocs?folderpath=$folderpath$command')";
                    954:     } else {
                    955:         $jscall = &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,$switchserver,
1.393     raeburn   956:                                                 $forceedit,$forcereg,$env{'request.symb'},
                    957:                                                 &escape($env{'form.folderpath'}),
                    958:                                                 &escape($env{'form.title'}),$env{'form.idx'},
1.398     raeburn   959:                                                 &escape($env{'form.suppurl'},$env{'form.todocs'}));
                    960:     }
1.389     raeburn   961:     if ($jscall) {
1.390     raeburn   962:         my $icon = 'pcstr.png';
                    963:         my $label = 'Edit';
                    964:         if ($forceview) {
                    965:             $icon = 'tolastloc.png';
                    966:             $label = 'Exit Editing';
                    967:         }
                    968:         &switch('','',6,1,$icon,$label,'resource[_2]',
                    969:                 $jscall,"Edit this resource");
                    970:         return 1;
                    971:     }
                    972:     return;
                    973: }
                    974: 
                    975: sub prepare_functions {
1.393     raeburn   976:     my ($resurl,$forcereg,$group,$bread_crumbs,$advtools,$docscrumbs) = @_;
1.390     raeburn   977:     unless ($env{'request.registered'}) {
                    978:         undef(@inlineremote);
                    979:     }
                    980:     my ($cdom,$cnum,%perms,$cfile,$switchserver,$home,$forceedit,
                    981:         $forceview);
                    982: 
                    983:     if ($env{'request.course.id'}) {
                    984:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                    985:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                    986:         $perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
                    987:     }
                    988: 
                    989:     my $editbutton = '';
                    990: #
                    991: # Determine whether or not to display 'Edit' icon/button
                    992: #
                    993:     if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
                    994:         my $file=&Apache::lonnet::declutter($env{'request.filename'});
1.391     raeburn   995:         ($cfile,$home,$switchserver,$forceedit,$forceview) =
                    996:             &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
                    997:                 &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
                    998:         if (($cfile) && ($home ne '') && ($home ne 'no_host')) {
                    999:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
1.390     raeburn  1000:                                           $forceedit,$forceview,$forcereg);
                   1001:         }
1.391     raeburn  1002:     } elsif ((!$env{'request.course.id'}) &&
1.390     raeburn  1003:              ($env{'user.author'}) && ($env{'request.filename'}) &&
                   1004:              ($env{'request.role'} !~/^(aa|ca|au)/)) {
                   1005: #
                   1006: # Currently do not have the role of author or co-author.
                   1007: # Do we have authoring privileges for the resource?
                   1008: #
                   1009:         my $file=&Apache::lonnet::declutter($env{'request.filename'});
                   1010:         ($cfile,$home,$switchserver,$forceedit,$forceview) =
                   1011:             &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
                   1012:                 &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
                   1013:         if (($cfile) && ($home ne '') && ($home ne 'no_host')) {
                   1014:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
                   1015:                                           $forceedit,$forceview,$forcereg);
                   1016:         }
                   1017:     } elsif ($env{'request.course.id'}) {
                   1018: #
                   1019: # This applies in course context
                   1020: #
1.412     raeburn  1021:         if (($perms{'mdc'}) &&
                   1022:             (($resurl eq "/public/$cdom/$cnum/syllabus") ||
                   1023:             ($resurl =~ m{^/uploaded/$cdom/$cnum/portfolio/syllabus/}))) {
1.411     raeburn  1024:             $cfile = $resurl;
                   1025:             $home = &Apache::lonnet::homeserver($cnum,$cdom);
                   1026:             if ($env{'form.forceedit'}) {
                   1027:                 $forceview = 1;
1.390     raeburn  1028:             } else {
1.411     raeburn  1029:                 $forceedit = 1;
1.390     raeburn  1030:             }
1.411     raeburn  1031:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
                   1032:                                           $forceedit,$forceview,$forcereg);
1.393     raeburn  1033:         } elsif (($resurl eq '/adm/extresedit') &&
                   1034:                  (($env{'form.symb'}) || ($env{'form.folderpath'}))) {
                   1035:             ($cfile,$home,$switchserver,$forceedit,$forceview) =
                   1036:             &Apache::lonnet::can_edit_resource($resurl,$cnum,$cdom,$resurl,
                   1037:                                                $env{'form.symb'});
                   1038:             if ($cfile ne '') {
                   1039:                 $editbutton = &get_editbutton($cfile,$home,$switchserver,
                   1040:                                               $forceedit,$forceview,$forcereg,
                   1041:                                               $env{'form.title'},$env{'form.suppurl'});
                   1042:             }
1.406     raeburn  1043:         } elsif (($resurl =~ m{^/?adm/viewclasslist$}) &&
                   1044:                  (&Apache::lonnet::allowed('opa',$env{'request.course.id'}))) {
                   1045:             ($cfile,$home,$switchserver,$forceedit,$forceview) =
                   1046:             &Apache::lonnet::can_edit_resource($resurl,$cnum,$cdom,$resurl,
                   1047:                                                $env{'form.symb'});
                   1048:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
                   1049:                                           $forceedit,$forceview,$forcereg);
1.405     raeburn  1050:         } elsif (($resurl !~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) &&
                   1051:                  ($resurl ne '/cgi-bin/printout.pl')) {
1.390     raeburn  1052:             if ($env{'request.filename'}) {
                   1053:                 my $file=&Apache::lonnet::declutter($env{'request.filename'});
                   1054:                 ($cfile,$home,$switchserver,$forceedit,$forceview) =
                   1055:                     &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
                   1056:                         &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
                   1057:                 if ($cfile ne '') {
                   1058:                     $editbutton = &get_editbutton($cfile,$home,$switchserver,
                   1059:                                                   $forceedit,$forceview,$forcereg);
                   1060:                 }
                   1061:             }
                   1062:         }
                   1063:     }
                   1064: # End determination of 'Edit' icon/button display
                   1065: 
1.393     raeburn  1066:     if ($env{'request.course.id'}) {
1.390     raeburn  1067: # This applies to about me page for users in a course
1.391     raeburn  1068:         if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
1.390     raeburn  1069:             my ($sdom,$sname) = ($1,$2);
                   1070:             unless (&Apache::lonnet::is_course($sdom,$sname)) {
                   1071:                 &switch('','',6,4,'mail-message-new-22x22.png','Message to user',
                   1072:                         '',
1.415     raeburn  1073:                         "go('/adm/email?compose=individual&amp;recname=$sname&amp;recdom=$sdom')",
1.390     raeburn  1074:                             'Send message to specific user');
                   1075:             }
1.391     raeburn  1076:             my $hideprivileged = 1;
                   1077:             if (&Apache::lonnet::in_course($sdom,$sname,$cdom,$cnum,undef,
                   1078:                                            $hideprivileged)) {
1.390     raeburn  1079:                 foreach my $priv ('vsa','vgr','srm') {
                   1080:                     $perms{$priv} = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
                   1081:                     if (!$perms{$priv} && $env{'request.course.sec'} ne '') {
                   1082:                         $perms{$priv} =
                   1083:                             &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
                   1084:                     }
                   1085:                 }
                   1086:                 if ($perms{'vsa'}) {
                   1087:                     &switch('','',6,5,'trck-22x22.png','Activity',
                   1088:                             '',
                   1089:                             "go('/adm/trackstudent?selected_student=$sname:$sdom')",
                   1090:                             'View recent activity by this person');
                   1091:                 }
                   1092:                 if ($perms{'vgr'}) {
                   1093:                     &switch('','',6,6,'rsrv-22x22.png','Reservations',
                   1094:                             '',
1.415     raeburn  1095:                             "go('/adm/slotrequest?command=showresv&amp;origin=aboutme&amp;uname=$sname&amp;udom=$sdom')",
1.390     raeburn  1096:                             'Slot reservation history');
                   1097:                 }
                   1098:                 if ($perms{'srm'}) {
                   1099:                     &switch('','',6,7,'contact-new-22x22.png','Records',
                   1100:                             '',
1.415     raeburn  1101:                             "go('/adm/email?recordftf=retrieve&amp;recname=$sname&amp;recdom=$sdom')",
1.390     raeburn  1102:                             'Add records');
                   1103:                 }
                   1104:             }
1.393     raeburn  1105:         }
                   1106:         if (($env{'form.folderpath'} =~ /^supplemental/) &&
                   1107:             (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) &&
                   1108:             (($resurl =~ m{^/adm/wrapper/ext/}) ||
                   1109:              ($resurl =~ m{^/uploaded/$cdom/$cnum/supplemental/}) ||
1.397     raeburn  1110:              ($resurl eq '/adm/supplemental') ||
                   1111:              ($resurl =~ m{^/public/$cdom/$cnum/syllabus$}) ||
                   1112:              ($resurl =~ m{^/adm/$match_domain/$match_username/aboutme$}))) {
1.393     raeburn  1113:             my @folders=split('&',$env{'form.folderpath'});
1.394     raeburn  1114:             if ((@folders > 2) || ($resurl ne '/adm/supplemental')) {
1.393     raeburn  1115:                 my $esc_path=&escape(&HTML::Entities::encode(&escape($env{'form.folderpath'}),'<>&"'));
                   1116:                 &switch('','',7,4,'docs-22x22.png','Edit Folder','parms[_2]',
1.415     raeburn  1117:                         "location.href='/adm/coursedocs?command=direct&amp;forcesupplement=1&amp;supppath=$esc_path'",
1.393     raeburn  1118:                         'Folder/Page Content');
                   1119:             }
1.390     raeburn  1120:         }
                   1121:     }
                   1122: 
                   1123: # End checking for items for about me page for users in a course
1.393     raeburn  1124:     if ($docscrumbs) {
                   1125:         &Apache::lonhtmlcommon::clear_breadcrumb_tools();
                   1126:         &advtools_crumbs(@inlineremote);
                   1127:         return $editbutton;
                   1128:     } elsif ($env{'request.registered'}) {
1.390     raeburn  1129:         return $editbutton;
                   1130:     } else {
                   1131:         if (ref($bread_crumbs) eq 'ARRAY') {
                   1132:             if (@inlineremote > 0) {
                   1133:                 if (ref($advtools) eq 'ARRAY') {
                   1134:                     @{$advtools} = @inlineremote;
                   1135:                 }
                   1136:             }
                   1137:             return;
                   1138:         } elsif (@inlineremote > 0) {
                   1139:             &Apache::lonhtmlcommon::clear_breadcrumb_tools();
                   1140:             &advtools_crumbs(@inlineremote);
                   1141:             return   &Apache::lonhtmlcommon::scripttag('', 'start')
                   1142:                    . &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
                   1143:                    . &Apache::lonhtmlcommon::scripttag('', 'end');
                   1144:         }
                   1145:     }
                   1146: }
                   1147: 
                   1148: sub advtools_crumbs {
                   1149:     my @funcs = @_;
                   1150:     if ($env{'request.noversionuri'} =~ m{^/adm/$match_domain/$match_username/aboutme$}) {
                   1151:         &Apache::lonhtmlcommon::add_breadcrumb_tool(
                   1152:             'advtools', @funcs[61,64,65,66,67,74]);
                   1153:     } elsif ($env{'request.noversionuri'} !~ m{^/adm/(navmaps|viewclasslist)(\?|$)}) {
                   1154:         &Apache::lonhtmlcommon::add_breadcrumb_tool(
                   1155:             'advtools', @funcs[61,71,72,73,74,92]);
1.393     raeburn  1156:     } elsif ($env{'request.noversionuri'} eq '/adm/viewclasslist') {
                   1157:         &Apache::lonhtmlcommon::add_breadcrumb_tool(
1.407     raeburn  1158:             'advtools', $funcs[61]);
1.393     raeburn  1159:     }
1.412     raeburn  1160:     return;
1.258     raeburn  1161: }
                   1162: 
1.2       www      1163: # ================================================================== Raw Config
                   1164: 
1.3       www      1165: sub clear {
                   1166:     my ($row,$col)=@_;
1.316     droeschl 1167:     $inlineremote[10*$row+$col]='';
                   1168:     return ''; 
1.3       www      1169: }
                   1170: 
1.40      www      1171: # ============================================ Switch a button or create a link
1.25      matthew  1172: # Switch acts on the javascript that is executed when a button is clicked.  
                   1173: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
1.40      www      1174: 
1.2       www      1175: sub switch {
1.209     www      1176:     my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak)=@_;
1.2       www      1177:     $act=~s/\$uname/$uname/g;
                   1178:     $act=~s/\$udom/$udom/g;
1.88      www      1179:     $top=&mt($top);
                   1180:     $bot=&mt($bot);
                   1181:     $desc=&mt($desc);
1.209     www      1182:     my $idx=10*$row+$col;
                   1183:     $category_members{$cat}.=':'.$idx;
                   1184: 
1.320     droeschl 1185: # Inline Menu
1.317     droeschl 1186:     if ($nobreak==2) { return ''; }
                   1187:     my $text=$top.' '.$bot;
                   1188:     $text=~s/\s*\-\s*//gs;
1.105     www      1189: 
1.317     droeschl 1190:     my $pic=
1.225     albertel 1191: 	   '<img alt="'.$text.'" src="'.
                   1192: 	   &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
1.303     droeschl 1193: 	   '" align="'.($nobreak==3?'right':'left').'" class="LC_icon" />';
1.317     droeschl 1194:     if ($env{'browser.interface'} eq 'faketextual') {
1.274     www      1195: # Main Menu
1.103     www      1196: 	   if ($nobreak==3) {
1.209     www      1197: 	       $inlineremote[$idx]="\n".
1.177     albertel 1198: 		   '<td class="LC_menubuttons_text" align="right">'.$text.
1.247     harmsja  1199: 		   '</td><td align="left">'.
1.103     www      1200: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
                   1201: 	   } elsif ($nobreak) {
1.209     www      1202: 	       $inlineremote[$idx]="\n<tr>".
1.247     harmsja  1203: 		   '<td align="left">'.
1.177     albertel 1204: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td>
1.215     www      1205:                     <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      1206: 	   } else {
1.209     www      1207: 	       $inlineremote[$idx]="\n<tr>".
1.247     harmsja  1208: 		   '<td align="left">'.
1.103     www      1209: 		   '<a href="javascript:'.$act.';">'.$pic.
1.177     albertel 1210: 		   '</a></td><td class="LC_menubuttons_text" colspan="3">'.
1.215     www      1211: 		   '<a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$desc.'</span></a></td></tr>';
1.103     www      1212: 	   }
1.317     droeschl 1213:     } else {
1.103     www      1214: # Inline Menu
1.378     raeburn  1215:         my @tools = (93,91,81,82,83);
                   1216:         unless ($env{'request.state'} eq 'construct') {
                   1217:             push(@tools,63);
                   1218:         }
                   1219:         if (($env{'environment.icons'} eq 'iconsonly') && 
                   1220:             (grep(/^$idx$/,@tools))) {
                   1221:             $inlineremote[$idx] =
                   1222:         '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.'</a>';
                   1223:         } else {
                   1224:             $inlineremote[$idx] =
1.317     droeschl 1225:        '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.
1.344     www      1226:        '<span class="LC_menubuttons_inline_text">'.$top.'&nbsp;</span></a>';
1.378     raeburn  1227:         }
1.317     droeschl 1228:     }
1.56      www      1229:     return '';
1.2       www      1230: }
                   1231: 
                   1232: sub secondlevel {
                   1233:     my $output='';
                   1234:     my 
1.209     www      1235:     ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_;
1.2       www      1236:     if ($prt eq 'any') {
1.209     www      1237: 	   $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1238:     } elsif ($prt=~/^r(\w+)/) {
                   1239:         if ($rol eq $1) {
1.209     www      1240:            $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1241:         }
                   1242:     }
                   1243:     return $output;
                   1244: }
                   1245: 
1.56      www      1246: sub inlinemenu {
1.210     albertel 1247:     undef(@inlineremote);
                   1248:     undef(%category_members);
1.275     www      1249: # calling rawconfig with "1" will evaluate mydesk.tab, even if there is no active remote control
1.56      www      1250:     &rawconfig(1);
1.309     bisitz   1251:     my $output='<table><tr>';
1.209     www      1252:     for (my $col=1; $col<=2; $col++) {
1.241     riegler  1253:         $output.='<td class="LC_mainmenu_col_fieldset">';
1.209     www      1254:         for (my $row=1; $row<=8; $row++) {
                   1255:             foreach my $cat (keys(%category_members)) {
                   1256:                if ($category_positions{$cat} ne "$col,$row") { next; }
1.247     harmsja  1257:                #$output.='<table><tr><td colspan="4" class="LC_menubuttons_category">'.&mt($category_names{$cat}).'</td></tr>';
1.309     bisitz   1258:                $output.='<div class="LC_Box LC_400Box">';
                   1259: 	       $output.='<h3 class="LC_hcell">'.&mt($category_names{$cat}).'</h3>';
1.247     harmsja  1260:                $output.='<table>';
1.240     riegler  1261:                my %active=();
                   1262:                foreach my $menu_item (split(/\:/,$category_members{$cat})) {
                   1263:                   if ($inlineremote[$menu_item]) {
                   1264:                      $active{$menu_item}=1;
                   1265:                   }
                   1266:                }  
                   1267:                foreach my $item (sort(keys(%active))) {
                   1268:                   $output.=$inlineremote[$item];
                   1269:                }
                   1270:                $output.='</table>';
1.245     harmsja  1271:                $output.='</div>';
1.240     riegler  1272:             }
                   1273:          }
                   1274:          $output.="</td>";
                   1275:     }
                   1276:     $output.="</tr></table>";
                   1277:     return $output;
                   1278: }
                   1279: 
1.2       www      1280: sub rawconfig {
1.274     www      1281: #
                   1282: # This evaluates mydesk.tab
                   1283: # Need to add more positions and more privileges to deal with all
                   1284: # menu items.
                   1285: #
1.34      www      1286:     my $textualoverride=shift;
                   1287:     my $output='';
1.316     droeschl 1288:     return '' unless $textualoverride;
1.152     albertel 1289:     my $uname=$env{'user.name'};
                   1290:     my $udom=$env{'user.domain'};
                   1291:     my $adv=$env{'user.adv'};
1.266     raeburn  1292:     my $show_course=&Apache::loncommon::show_course();
1.152     albertel 1293:     my $author=$env{'user.author'};
1.5       www      1294:     my $crs='';
1.295     raeburn  1295:     my $crstype='';
1.152     albertel 1296:     if ($env{'request.course.id'}) {
                   1297:        $crs='/'.$env{'request.course.id'};
                   1298:        if ($env{'request.course.sec'}) {
                   1299: 	   $crs.='_'.$env{'request.course.sec'};
1.7       www      1300:        }
1.8       www      1301:        $crs=~s/\_/\//g;
1.295     raeburn  1302:        $crstype = &Apache::loncommon::course_type();
1.5       www      1303:     }
1.152     albertel 1304:     my $pub=($env{'request.state'} eq 'published');
                   1305:     my $con=($env{'request.state'} eq 'construct');
                   1306:     my $rol=$env{'request.role'};
1.427     raeburn  1307:     my $requested_domain;
                   1308:     if ($rol) {
                   1309:        $requested_domain = $env{'request.role.domain'};
                   1310:     }
1.184     raeburn  1311:     foreach my $line (@desklines) {
1.209     www      1312:         my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
1.3       www      1313:         $prt=~s/\$uname/$uname/g;
                   1314:         $prt=~s/\$udom/$udom/g;
1.295     raeburn  1315:         if ($prt =~ /\$crs/) {
                   1316:             next unless ($env{'request.course.id'});
                   1317:             next if ($crstype eq 'Community');
                   1318:             $prt=~s/\$crs/$crs/g;
                   1319:         } elsif ($prt =~ /\$cmty/) {
                   1320:             next unless ($env{'request.course.id'});
                   1321:             next if ($crstype ne 'Community');
                   1322:             $prt=~s/\$cmty/$crs/g;
                   1323:         }
1.427     raeburn  1324:         if ($prt =~ m/\$requested_domain/) {
                   1325:             if ((!$requested_domain) && ($pro eq 'pbre') && ($env{'user.adv'})) {
                   1326:                 $prt=~s/\$requested_domain/$env{'user.domain'}/g;
                   1327:             } else {
                   1328:                 $prt=~s/\$requested_domain/$requested_domain/g;
                   1329:             }
                   1330:         }
1.211     www      1331:         if ($category_names{$cat}!~/\w/) { $cat='oth'; }
1.3       www      1332:         if ($pro eq 'clear') {
1.4       www      1333: 	    $output.=&clear($row,$col);
1.3       www      1334:         } elsif ($pro eq 'any') {
1.2       www      1335:                $output.=&secondlevel(
1.209     www      1336: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1337: 	} elsif ($pro eq 'smp') {
                   1338:             unless ($adv) {
                   1339:                $output.=&secondlevel(
1.209     www      1340:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1341:             }
                   1342:         } elsif ($pro eq 'adv') {
                   1343:             if ($adv) {
                   1344:                $output.=&secondlevel(
1.209     www      1345: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1346:             }
1.231     albertel 1347: 	} elsif ($pro eq 'shc') {
                   1348:             if ($show_course) {
                   1349:                $output.=&secondlevel(
                   1350:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
                   1351:             }
                   1352:         } elsif ($pro eq 'nsc') {
                   1353:             if (!$show_course) {
                   1354:                $output.=&secondlevel(
                   1355: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
                   1356:             }
1.81      matthew  1357:         } elsif (($pro=~/^p(\w+)/) && ($prt)) {
1.295     raeburn  1358:             my $priv = $1;
                   1359:             if ($priv =~ /^mdc(Course|Community)/) {
                   1360:                 if ($crstype eq $1) {
                   1361:                     $priv = 'mdc';
                   1362:                 } else {
                   1363:                     next;
                   1364:                 }
                   1365:             }
1.427     raeburn  1366:             if ((($priv eq 'bre') && (&Apache::lonnet::allowed($priv,$prt) eq 'F')) ||
                   1367:                 (($priv ne 'bre') && (&Apache::lonnet::allowed($priv,$prt)))) {
                   1368:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.4       www      1369:             }
1.295     raeburn  1370:         } elsif ($pro eq 'course')  {
                   1371:             if (($env{'request.course.fn'}) && ($crstype ne 'Community')) {
1.209     www      1372:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.81      matthew  1373: 	    }
1.295     raeburn  1374:         } elsif ($pro eq 'community')  {
                   1375:             if (($env{'request.course.fn'}) && ($crstype eq 'Community')) {
                   1376:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
                   1377:             }
1.124     matthew  1378:         } elsif ($pro =~ /^courseenv_(.*)$/) {
                   1379:             my $key = $1;
1.307     raeburn  1380:             if ($crstype ne 'Community') {
                   1381:                 my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
                   1382:                 if ($key eq 'canuse_pdfforms') {
                   1383:                     if ($env{'request.course.id'} && $coursepref eq '') {
                   1384:                         my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
                   1385:                         $coursepref = $domdefs{'canuse_pdfforms'};
                   1386:                     }
                   1387:                 }
                   1388:                 if ($coursepref) { 
                   1389:                     $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
                   1390:                 }
1.295     raeburn  1391:             }
                   1392:         } elsif ($pro =~ /^communityenv_(.*)$/) {
                   1393:             my $key = $1;
1.307     raeburn  1394:             if ($crstype eq 'Community') {
                   1395:                 my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
                   1396:                 if ($key eq 'canuse_pdfforms') {
                   1397:                     if ($env{'request.course.id'} && $coursepref eq '') {
                   1398:                         my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
                   1399:                         $coursepref = $domdefs{'canuse_pdfforms'};
                   1400:                     }
                   1401:                 }
                   1402:                 if ($coursepref) { 
                   1403:                     $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
                   1404:                 }
1.124     matthew  1405:             }
1.81      matthew  1406:         } elsif ($pro =~ /^course_(.*)$/) {
                   1407:             # Check for permissions inside of a course
1.295     raeburn  1408:             if (($env{'request.course.id'}) && ($crstype ne 'Community') && 
1.152     albertel 1409:                 (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
                   1410:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
1.81      matthew  1411:                  )) {
1.209     www      1412:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.26      www      1413: 	    }
1.295     raeburn  1414:         } elsif ($pro =~ /^community_(.*)$/) {
                   1415:             # Check for permissions inside of a community
                   1416:             if (($env{'request.course.id'}) && ($crstype eq 'Community') &&   
                   1417:                 (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
                   1418:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
                   1419:                  )) {
                   1420:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
                   1421:             }
1.4       www      1422:         } elsif ($pro eq 'author') {
                   1423:             if ($author) {
1.152     albertel 1424:                 if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
1.234     raeburn  1425:                     (($prt eq 'raa') && ($env{'request.role'}=~/^aa/)) || 
1.152     albertel 1426:                     (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
1.19      matthew  1427:                     # Check that we are on the correct machine
1.29      matthew  1428:                     my $cadom=$requested_domain;
1.152     albertel 1429:                     my $caname=$env{'user.name'};
1.234     raeburn  1430:                     if (($prt eq 'rca') || ($prt eq 'raa')) {
1.29      matthew  1431: 		       ($cadom,$caname)=
1.206     albertel 1432:                                ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.29      matthew  1433:                     }                       
                   1434:                     $act =~ s/\$caname/$caname/g;
1.353     www      1435:                     $act =~ s/\$cadom/$cadom/g;
1.19      matthew  1436:                     my $home = &Apache::lonnet::homeserver($caname,$cadom);
1.109     albertel 1437: 		    my $allowed=0;
                   1438: 		    my @ids=&Apache::lonnet::current_machine_ids();
                   1439: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                   1440: 		    if ($allowed) {
1.209     www      1441:                         $output.=&switch($caname,$cadom,
                   1442:                                         $row,$col,$img,$top,$bot,$act,$desc,$cat);
1.19      matthew  1443:                     }
1.6       www      1444:                 }
1.2       www      1445:             }
1.248     raeburn  1446:         } elsif ($pro eq 'tools') {
                   1447:             my @tools = ('aboutme','blog','portfolio');
                   1448:             if (grep(/^\Q$prt\E$/,@tools)) {
1.249     raeburn  1449:                 if (!&Apache::lonnet::usertools_access($env{'user.name'},
1.251     raeburn  1450:                                                        $env{'user.domain'},
                   1451:                                                        $prt,undef,'tools')) {
                   1452:                     $output.=&clear($row,$col);
                   1453:                     next;
                   1454:                 }
1.278     raeburn  1455:             } elsif (($prt eq 'reqcrsnsc') || ($prt eq 'reqcrsshc')) {
                   1456:                 if (($prt eq 'reqcrsnsc') && ($show_course))   {
                   1457:                     next;
                   1458:                 }
                   1459:                 if (($prt eq 'reqcrsshc') && (!$show_course)) {
                   1460:                     next;
                   1461:                 }
1.279     raeburn  1462:                 my $showreqcrs = &check_for_rcrs();
1.251     raeburn  1463:                 if (!$showreqcrs) {
1.248     raeburn  1464:                     $output.=&clear($row,$col);
                   1465:                     next;
                   1466:                 }
                   1467:             }
                   1468:             $prt='any';
                   1469:             $output.=&secondlevel(
                   1470:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1471:         }
1.13      harris41 1472:     }
1.2       www      1473:     return $output;
                   1474: }
                   1475: 
1.279     raeburn  1476: sub check_for_rcrs {
                   1477:     my $showreqcrs = 0;
1.424     raeburn  1478:     my @reqtypes = ('official','unofficial','community','textbook');
1.280     raeburn  1479:     foreach my $type (@reqtypes) {
1.279     raeburn  1480:         if (&Apache::lonnet::usertools_access($env{'user.name'},
                   1481:                                               $env{'user.domain'},
                   1482:                                               $type,undef,'requestcourses')) {
                   1483:             $showreqcrs = 1;
                   1484:             last;
                   1485:         }
                   1486:     }
1.280     raeburn  1487:     if (!$showreqcrs) {
                   1488:         foreach my $type (@reqtypes) {
                   1489:             if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
                   1490:                 $showreqcrs = 1;
                   1491:                 last;
                   1492:             }
                   1493:         }
                   1494:     }
1.279     raeburn  1495:     return $showreqcrs;
                   1496: }
                   1497: 
1.306     raeburn  1498: sub dc_popup_js {
                   1499:     my %lt = &Apache::lonlocal::texthash(
                   1500:                                           more => '(More ...)',
                   1501:                                           less => '(Less ...)',
                   1502:                                         );
                   1503:     return <<"END";
                   1504: 
                   1505: function showCourseID() {
                   1506:     document.getElementById('dccid').style.display='block';
                   1507:     document.getElementById('dccid').style.textAlign='left';
1.307     raeburn  1508:     document.getElementById('dccid').style.textFace='normal';
1.369     raeburn  1509:     document.getElementById('dccidtext').innerHTML ='<a href="javascript:hideCourseID();" class="LC_menubuttons_link">$lt{'less'}</a>';
1.306     raeburn  1510:     return;
                   1511: }
                   1512: 
                   1513: function hideCourseID() {
                   1514:     document.getElementById('dccid').style.display='none';
1.369     raeburn  1515:     document.getElementById('dccidtext').innerHTML ='<a href="javascript:showCourseID()" class="LC_menubuttons_link">$lt{'more'}</a>';
1.306     raeburn  1516:     return;
                   1517: }
                   1518: 
                   1519: END
                   1520: 
                   1521: }
                   1522: 
1.378     raeburn  1523: sub countdown_toggle_js {
                   1524:     return <<"END";
                   1525: 
                   1526: function toggleCountdown() {
                   1527:     var countdownid = document.getElementById('duedatecountdown');
                   1528:     var currstyle = countdownid.style.display;
                   1529:     if (currstyle == 'inline') {
                   1530:         countdownid.style.display = 'none';
                   1531:         document.getElementById('ddcountcollapse').innerHTML='';
                   1532:         document.getElementById('ddcountexpand').innerHTML='&#9668;&nbsp;';
                   1533:     } else {
                   1534:         countdownid.style.display = 'inline';
                   1535:         document.getElementById('ddcountcollapse').innerHTML='&#9658;&nbsp;';
                   1536:         document.getElementById('ddcountexpand').innerHTML='';
                   1537:     }
                   1538:     return;
                   1539: }
                   1540: 
                   1541: END
                   1542: }
                   1543: 
1.42      www      1544: sub utilityfunctions {
1.421     raeburn  1545:     my ($httphost) = @_;
1.152     albertel 1546:     my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
1.316     droeschl 1547:     if ($currenturl =~ m{^/adm/wrapper/ext/}
                   1548:         && $env{'request.external.querystring'} ) {
1.293     raeburn  1549:             $currenturl .= ($currenturl=~/\?/)?'&':'?'.$env{'request.external.querystring'};
                   1550:     }
1.183     www      1551:     $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
1.125     albertel 1552:     
1.152     albertel 1553:     my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
1.175     albertel 1554: 
1.306     raeburn  1555:     my $dc_popup_cid;
                   1556:     if ($env{'user.adv'} && exists($env{'user.role.dc./'.
                   1557:                         $env{'course.'.$env{'request.course.id'}.
                   1558:                                  '.domain'}.'/'})) {
                   1559:         $dc_popup_cid = &dc_popup_js();
                   1560:     }
                   1561: 
1.175     albertel 1562:     my $start_page_annotate = 
                   1563:         &Apache::loncommon::start_page('Annotator',undef,
                   1564: 				       {'only_body' => 1,
                   1565: 					'js_ready'  => 1,
                   1566: 					'bgcolor'   => '#BBBBBB',
                   1567: 					'add_entries' => {
                   1568: 					    'onload' => 'javascript:document.goannotate.submit();'}});
                   1569: 
1.205     albertel 1570:     my $end_page_annotate = 
                   1571:         &Apache::loncommon::end_page({'js_ready' => 1});
                   1572: 
1.389     raeburn  1573:     my $jumptores = &Apache::lonhtmlcommon::javascript_jumpto_resource();
1.336     raeburn  1574: 
1.368     www      1575:     my $esc_url=&escape($currenturl);
                   1576:     my $esc_symb=&escape($currentsymb);
1.332     wenzelju 1577: 
1.378     raeburn  1578:     my $countdown = &countdown_toggle_js();
                   1579: 
1.429     raeburn  1580:     my $hostvar = '
                   1581: function setLCHost() {
                   1582:     var lcHostname="";
                   1583: ';
                   1584:     if ($httphost =~ m{^https?\://}) {
                   1585:         $hostvar .= '    var lcServer="'.$httphost.'";'."\n".
                   1586:                     '    var hostReg = /^https?:\/\/([^\/]+)$/i;'."\n".
                   1587:                     '    var match = hostReg.exec(lcServer);'."\n".
                   1588:                     '    if (match.length) {'."\n".
                   1589:                     '        if (match[1] == location.hostname) {'."\n".
                   1590:                     '            lcHostname=lcServer;'."\n".
                   1591:                     '        }'."\n".
                   1592:                     '    }'."\n";
                   1593:     }
                   1594:     
                   1595:     $hostvar .= '    return lcHostname;'."\n".
                   1596: '}'."\n";
                   1597: 
1.42      www      1598: return (<<ENDUTILITY)
1.429     raeburn  1599:     $hostvar
1.368     www      1600:     var currentURL=unescape("$esc_url");
                   1601:     var reloadURL=unescape("$esc_url");
                   1602:     var currentSymb=unescape("$esc_symb");
1.42      www      1603: 
1.306     raeburn  1604: $dc_popup_cid
1.114     albertel 1605: 
1.389     raeburn  1606: $jumptores
1.336     raeburn  1607: 
1.42      www      1608: function gopost(url,postdata) {
                   1609:    if (url!='') {
1.429     raeburn  1610:       var lcHostname = setLCHost();
                   1611:       this.document.server.action=lcHostname+url;
1.42      www      1612:       this.document.server.postdata.value=postdata;
                   1613:       this.document.server.command.value='';
                   1614:       this.document.server.url.value='';
                   1615:       this.document.server.symb.value='';
                   1616:       this.document.server.submit();
                   1617:    }
                   1618: }
                   1619: 
                   1620: function gocmd(url,cmd) {
                   1621:    if (url!='') {
1.429     raeburn  1622:       var lcHostname = setLCHost();
                   1623:       this.document.server.action=lcHostname+url;
1.42      www      1624:       this.document.server.postdata.value='';
                   1625:       this.document.server.command.value=cmd;
                   1626:       this.document.server.url.value=currentURL;
                   1627:       this.document.server.symb.value=currentSymb;
                   1628:       this.document.server.submit();
                   1629:    }
1.57      www      1630: }
                   1631: 
1.121     raeburn  1632: function gocstr(url,filename) {
                   1633:     if (url == '/adm/cfile?action=delete') {
                   1634:         this.document.cstrdelete.filename.value = filename
                   1635:         this.document.cstrdelete.submit();
                   1636:         return;
                   1637:     }
1.137     raeburn  1638:     if (url == '/adm/printout') {
                   1639:         this.document.cstrprint.postdata.value = filename
                   1640:         this.document.cstrprint.curseed.value = 0;
                   1641:         this.document.cstrprint.problemtype.value = 0;
1.138     raeburn  1642:         if (this.document.lonhomework) {
                   1643:             if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
                   1644:                 this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
                   1645:             }
                   1646:             if (this.document.lonhomework.problemtype) {
1.164     albertel 1647: 		if (this.document.lonhomework.problemtype.value) {
                   1648: 		    this.document.cstrprint.problemtype.value = 
                   1649: 			this.document.lonhomework.problemtype.value;
                   1650: 		} else if (this.document.lonhomework.problemtype.options) {
                   1651: 		    for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
                   1652: 			if (this.document.lonhomework.problemtype.options[i].selected) {
                   1653: 			    if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') { 
                   1654: 				this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
                   1655: 				}
                   1656: 			}
                   1657: 		    }
                   1658: 		}
                   1659: 	    }
                   1660: 	}
1.137     raeburn  1661:         this.document.cstrprint.submit();
                   1662:         return;
                   1663:     }
1.121     raeburn  1664:     if (url !='') {
                   1665:         this.document.constspace.filename.value = filename;
                   1666:         this.document.constspace.action = url;
                   1667:         this.document.constspace.submit();
                   1668:     }
                   1669: }
                   1670: 
1.131     raeburn  1671: function golist(url) {
                   1672:    if (url!='' && url!= null) {
                   1673:        currentURL = null;
                   1674:        currentSymb= null;
1.429     raeburn  1675:        var lcHostname = setLCHost();
                   1676:        top.location.href=lcHostname+url;
1.131     raeburn  1677:    }
                   1678: }
                   1679: 
                   1680: 
1.121     raeburn  1681: 
1.428     raeburn  1682: function catalog_info(isMobile) {
                   1683:     if (isMobile == 1) {
                   1684:         openMyModal(window.location.pathname+'.meta?modal=1',500,400,'yes');
                   1685:     } else {
                   1686:         loncatinfo=window.open(window.location.pathname+'.meta',"LONcatInfo",'height=500,width=400,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
                   1687:     }
1.57      www      1688: }
                   1689: 
                   1690: function chat_win() {
1.429     raeburn  1691:    var lcHostname = setLCHost();
                   1692:    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      1693: }
1.169     raeburn  1694: 
                   1695: function group_chat(group) {
1.429     raeburn  1696:    var lcHostname = setLCHost();
                   1697:    var url = lcHostname+'/adm/groupchat?group='+group;
1.169     raeburn  1698:    var winName = 'LONchat_'+group;
                   1699:    grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
                   1700: }
1.175     albertel 1701: 
                   1702: function annotate() {
                   1703:    w_Annotator_flag=1;
                   1704:    annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
                   1705:    annotator.document.write(
                   1706:    '$start_page_annotate'
                   1707:   +"<form name='goannotate' target='Annotator' method='post' "
                   1708:   +"action='/adm/annotations'>"
1.217     albertel 1709:   +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />"
1.181     albertel 1710:   +"<\\/form>"
1.205     albertel 1711:   +'$end_page_annotate');
1.175     albertel 1712:    annotator.document.close();
                   1713: }
                   1714: 
1.370     raeburn  1715: function open_StoredLinks_Import(rat) {
1.335     wenzelju 1716:    var newWin;
1.429     raeburn  1717:    var lcHostname = setLCHost();
1.335     wenzelju 1718:    if (rat) {
1.429     raeburn  1719:        newWin = window.open(lcHostname+'/adm/wishlist?inhibitmenu=yes&mode=import&rat='+rat,
1.334     wenzelju 1720:                             'wishlistImport','scrollbars=1,resizable=1,menubar=0');
1.335     wenzelju 1721:    }
                   1722:    else {
1.429     raeburn  1723:        newWin = window.open(lcHostname+'/adm/wishlist?inhibitmenu=yes&mode=import',
1.335     wenzelju 1724:                             'wishlistImport','scrollbars=1,resizable=1,menubar=0');
                   1725:    }
1.334     wenzelju 1726:    newWin.focus();
                   1727: }
                   1728: 
1.372     raeburn  1729: (function (\$) {
                   1730:   \$(document).ready(function () {
                   1731:     \$.single=function(a){return function(b){a[0]=b;return a}}(\$([1]));
                   1732:     /*\@cc_on
                   1733:       if (!window.XMLHttpRequest) {
                   1734:         \$('.LC_hoverable').each(function () {
                   1735:           this.attachEvent('onmouseenter', function (evt) { \$.single(evt.srcElement).addClass('hover'); });
                   1736:           this.attachEvent('onmouseleave', function (evt) { \$.single(evt.srcElement).removeClass('hover'); });
                   1737:         });
                   1738:       }
                   1739:     \@*/
                   1740:   });
                   1741: }(jQuery));
                   1742: 
1.378     raeburn  1743: $countdown
                   1744: 
1.42      www      1745: ENDUTILITY
                   1746: }
                   1747: 
                   1748: sub serverform {
                   1749:     return(<<ENDSERVERFORM);
1.181     albertel 1750: <form name="server" action="/adm/logout" method="post" target="_top">
1.42      www      1751: <input type="hidden" name="postdata" value="none" />
                   1752: <input type="hidden" name="command" value="none" />
                   1753: <input type="hidden" name="url" value="none" />
                   1754: <input type="hidden" name="symb" value="none" />
                   1755: </form>
                   1756: ENDSERVERFORM
                   1757: }
1.113     albertel 1758: 
1.121     raeburn  1759: sub constspaceform {
                   1760:     return(<<ENDCONSTSPACEFORM);
1.181     albertel 1761: <form name="constspace" action="/adm/logout" method="post" target="_top">
1.121     raeburn  1762: <input type="hidden" name="filename" value="" />
                   1763: </form>
1.181     albertel 1764: <form name="cstrdelete" action="/adm/cfile" method="post" target="_top">
1.121     raeburn  1765: <input type="hidden" name="action" value="delete" /> 
                   1766: <input type="hidden" name="filename" value="" />
                   1767: </form>
1.181     albertel 1768: <form name="cstrprint" action="/adm/printout" target="_parent" method="post">
1.137     raeburn  1769: <input type="hidden" name="postdata" value="" />
                   1770: <input type="hidden" name="curseed" value="" />
                   1771: <input type="hidden" name="problemtype" value="" />
                   1772: </form>
                   1773: 
1.121     raeburn  1774: ENDCONSTSPACEFORM
                   1775: }
                   1776: 
1.220     raeburn  1777: sub hidden_button_check {
1.317     droeschl 1778:     if ( $env{'request.course.id'} eq ''
                   1779:          || $env{'request.role.adv'} ) {
                   1780: 
1.220     raeburn  1781:         return;
                   1782:     }
1.232     raeburn  1783:     my $buttonshide = &Apache::lonnet::EXT('resource.0.buttonshide');
                   1784:     return $buttonshide; 
1.220     raeburn  1785: }
1.184     raeburn  1786: 
1.235     raeburn  1787: sub roles_selector {
1.421     raeburn  1788:     my ($cdom,$cnum,$httphost) = @_;
1.298     raeburn  1789:     my $crstype = &Apache::loncommon::course_type();
1.235     raeburn  1790:     my $now = time;
1.350     raeburn  1791:     my (%courseroles,%seccount,%courseprivs);
1.235     raeburn  1792:     my $is_cc;
1.432     droeschl 1793:     my ($js,$form,$switcher);
1.298     raeburn  1794:     my $ccrole;
                   1795:     if ($crstype eq 'Community') {
                   1796:         $ccrole = 'co';
                   1797:     } else {
                   1798:         $ccrole = 'cc';
1.350     raeburn  1799:     }
1.386     raeburn  1800:     my ($priv,$gotsymb,$destsymb);
1.350     raeburn  1801:     my $destinationurl = $ENV{'REQUEST_URI'};
1.386     raeburn  1802:     if ($destinationurl =~ /\?symb=/) {
                   1803:         $gotsymb = 1;
                   1804:     } elsif ($destinationurl =~ m{^/enc/}) {
                   1805:         my $plainurl = &Apache::lonenc::unencrypted($destinationurl);
                   1806:         if ($plainurl =~ /\?symb=/) {
                   1807:             $gotsymb = 1;
                   1808:         }
                   1809:     }
                   1810:     unless ($gotsymb) {
                   1811:         $destsymb = &Apache::lonnet::symbread();
                   1812:         if ($destsymb ne '') {
                   1813:             $destsymb = &Apache::lonenc::check_encrypt($destsymb);
                   1814:         }
                   1815:     }
1.350     raeburn  1816:     my $reqprivs = &required_privs();
                   1817:     if (ref($reqprivs) eq 'HASH') {
                   1818:         my $destination = $destinationurl;
                   1819:         $destination =~ s/(\?.*)$//;
                   1820:         if (exists($reqprivs->{$destination})) {
                   1821:             $priv = $reqprivs->{$destination};
                   1822:         }
                   1823:     }
1.298     raeburn  1824:     if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
                   1825:         my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
1.235     raeburn  1826:         
                   1827:         if ((($start) && ($start<0)) || 
                   1828:             (($end) && ($end<$now))  ||
                   1829:             (($start) && ($now<$start))) {
                   1830:             $is_cc = 0;
                   1831:         } else {
                   1832:             $is_cc = 1;
                   1833:         }
                   1834:     }
                   1835:     if ($is_cc) {
1.350     raeburn  1836:         &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs,$priv);
1.235     raeburn  1837:     } else {
1.262     raeburn  1838:         my %gotnosection;
1.235     raeburn  1839:         foreach my $item (keys(%env)) {
1.239     raeburn  1840:             if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
1.235     raeburn  1841:                 my $role = $1;
                   1842:                 my $sec = $2;
                   1843:                 next if ($role eq 'gr');
                   1844:                 my ($start,$end) = split(/\./,$env{$item});
                   1845:                 next if (($start && $start > $now) || ($end && $end < $now));
                   1846:                 if ($sec eq '') {
1.239     raeburn  1847:                     if (!$gotnosection{$role}) {
                   1848:                         $seccount{$role} ++;
                   1849:                         $gotnosection{$role} = 1;
                   1850:                     }
1.235     raeburn  1851:                 }
1.350     raeburn  1852:                 if ($priv ne '') {
                   1853:                     my $cnumsec = $cnum;
                   1854:                     if ($sec ne '') {
                   1855:                         $cnumsec .= "/$sec";
                   1856:                     }
                   1857:                     $courseprivs{"$role./$cdom/$cnumsec./"} =
                   1858:                         $env{"user.priv.$role./$cdom/$cnumsec./"};
                   1859:                     $courseprivs{"$role./$cdom/$cnumsec./$cdom/"} =
                   1860:                         $env{"user.priv.$role./$cdom/$cnumsec./$cdom/"};
                   1861:                     $courseprivs{"$role./$cdom/$cnumsec./$cdom/$cnumsec"} =
                   1862:                         $env{"user.priv.$role./$cdom/$cnumsec./$cdom/$cnumsec"};
                   1863:                 }
1.235     raeburn  1864:                 if (ref($courseroles{$role}) eq 'ARRAY') {
1.239     raeburn  1865:                     if ($sec ne '') {
1.264     raeburn  1866:                         if (!grep(/^\Q$sec\E$/,@{$courseroles{$role}})) {
1.239     raeburn  1867:                             push(@{$courseroles{$role}},$sec);
                   1868:                             $seccount{$role} ++;
                   1869:                         }
                   1870:                     }
                   1871:                 } else {
                   1872:                     @{$courseroles{$role}} = ();
                   1873:                     if ($sec ne '') {
                   1874:                         $seccount{$role} ++;
1.235     raeburn  1875:                         push(@{$courseroles{$role}},$sec);
                   1876:                     }
                   1877:                 }
                   1878:             }
                   1879:         }
                   1880:     }
1.298     raeburn  1881:     my @roles_order = ($ccrole,'in','ta','ep','ad','st');
1.402     raeburn  1882:     my $numdiffsec;
                   1883:     if (keys(%seccount) == 1) {
                   1884:         foreach my $key (keys(%seccount)) {
                   1885:             $numdiffsec = $seccount{$key};
                   1886:         }
                   1887:     }
                   1888:     if ((keys(%seccount) > 1) || ($numdiffsec > 1)) {
1.401     raeburn  1889:         my @submenu;
                   1890:         $js = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles,\%courseprivs,$priv);
                   1891:         $form = 
1.421     raeburn  1892:             '<form name="rolechooser" method="post" action="'.$httphost.'/adm/roles">'."\n".
1.401     raeburn  1893:             '  <input type="hidden" name="destinationurl" value="'.
                   1894:             &HTML::Entities::encode($destinationurl).'" />'."\n".
                   1895:             '  <input type="hidden" name="gotorole" value="1" />'."\n".
                   1896:             '  <input type="hidden" name="selectrole" value="" />'."\n".
1.402     raeburn  1897:             '  <input type="hidden" name="switchrole" value="" />'."\n";
                   1898:         if ($destsymb ne '') {
                   1899:             $form .= '  <input type="hidden" name="destsymb" value="'.
                   1900:                         &HTML::Entities::encode($destsymb).'" />'."\n";
                   1901:         }
                   1902:         $form .= '</form>'."\n";
1.235     raeburn  1903:         foreach my $role (@roles_order) {
1.402     raeburn  1904:             my $include;
1.235     raeburn  1905:             if (defined($courseroles{$role})) {
1.402     raeburn  1906:                 if ($env{'request.role'} =~ m{^\Q$role\E}) {
                   1907:                     if ($seccount{$role} > 1) {
                   1908:                         $include = 1;
                   1909:                     }
                   1910:                 } else {
                   1911:                     $include = 1;
                   1912:                 }
                   1913:             }
                   1914:             if ($include) {
1.401     raeburn  1915:                 push(@submenu,['javascript:adhocRole('."'$role'".')',
                   1916:                                &Apache::lonnet::plaintext($role,$crstype)]);
1.235     raeburn  1917:             }
                   1918:         }
                   1919:         foreach my $role (sort(keys(%courseroles))) {
                   1920:             if ($role =~ /^cr/) {
1.403     raeburn  1921:                 my $include;
                   1922:                 if ($env{'request.role'} =~ m{^\Q$role\E}) {
1.402     raeburn  1923:                     if ($seccount{$role} > 1) {
                   1924:                         $include = 1;
                   1925:                     }
1.403     raeburn  1926:                 } else {
                   1927:                     $include = 1; 
                   1928:                 }
                   1929:                 if ($include) {
                   1930:                     push(@submenu,['javascript:adhocRole('."'$role'".')',
                   1931:                                    &Apache::lonnet::plaintext($role)]);
                   1932:                 }
1.235     raeburn  1933:             }
                   1934:         }
1.401     raeburn  1935:         if (@submenu > 0) {
1.432     droeschl 1936:             $switcher = &create_submenu('','',&mt('Switch role'),\@submenu);
1.386     raeburn  1937:         }
1.235     raeburn  1938:     }
1.401     raeburn  1939:     return ($js,$form,$switcher);
1.235     raeburn  1940: }
                   1941: 
1.262     raeburn  1942: sub get_all_courseroles {
1.350     raeburn  1943:     my ($cdom,$cnum,$courseroles,$seccount,$courseprivs) = @_;
1.351     raeburn  1944:     unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH') &&
1.350     raeburn  1945:             (ref($courseprivs) eq 'HASH')) {
1.262     raeburn  1946:         return;
                   1947:     }
                   1948:     my ($result,$cached) = 
                   1949:         &Apache::lonnet::is_cached_new('getcourseroles',$cdom.'_'.$cnum);
                   1950:     if (defined($cached)) {
                   1951:         if (ref($result) eq 'HASH') {
                   1952:             if ((ref($result->{'roles'}) eq 'HASH') && 
1.350     raeburn  1953:                 (ref($result->{'seccount'}) eq 'HASH') && 
                   1954:                 (ref($result->{'privs'}) eq 'HASH')) {
1.262     raeburn  1955:                 %{$courseroles} = %{$result->{'roles'}};
                   1956:                 %{$seccount} = %{$result->{'seccount'}};
1.350     raeburn  1957:                 %{$courseprivs} = %{$result->{'privs'}};
1.262     raeburn  1958:                 return;
                   1959:             }
                   1960:         }
                   1961:     }
                   1962:     my %gotnosection;
                   1963:     my %adv_roles =
                   1964:          &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
                   1965:     foreach my $role (keys(%adv_roles)) {
                   1966:         my ($urole,$usec) = split(/:/,$role);
                   1967:         if (!$gotnosection{$urole}) {
                   1968:             $seccount->{$urole} ++;
                   1969:             $gotnosection{$urole} = 1;
                   1970:         }
                   1971:         if (ref($courseroles->{$urole}) eq 'ARRAY') {
                   1972:             if ($usec ne '') {
                   1973:                 if (!grep(/^Q$usec\E$/,@{$courseroles->{$urole}})) {
                   1974:                     push(@{$courseroles->{$urole}},$usec);
                   1975:                     $seccount->{$urole} ++;
                   1976:                 }
                   1977:             }
                   1978:         } else {
                   1979:             @{$courseroles->{$urole}} = ();
                   1980:             if ($usec ne '') {
                   1981:                 $seccount->{$urole} ++;
                   1982:                 push(@{$courseroles->{$urole}},$usec);
                   1983:             }
                   1984:         }
1.350     raeburn  1985:         my $area = '/'.$cdom.'/'.$cnum;
                   1986:         if ($usec ne '') {
                   1987:             $area .= '/'.$usec;
                   1988:         }
                   1989:         if ($role =~ /^cr\//) {
                   1990:             &Apache::lonnet::custom_roleprivs($courseprivs,$urole,$cdom,$cnum,$urole.'.'.$area,$area);
                   1991:         } else {
                   1992:             &Apache::lonnet::standard_roleprivs($courseprivs,$urole,$cdom,$urole.'.'.$area,$cnum,$area);
                   1993:         }
1.262     raeburn  1994:     }
                   1995:     my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum,['st']);
                   1996:     @{$courseroles->{'st'}} = ();
1.350     raeburn  1997:     &Apache::lonnet::standard_roleprivs($courseprivs,'st',$cdom,"st./$cdom/$cnum",$cnum,"/$cdom/$cnum");
1.262     raeburn  1998:     if (keys(%sections_count) > 0) {
                   1999:         push(@{$courseroles->{'st'}},keys(%sections_count));
1.350     raeburn  2000:         $seccount->{'st'} = scalar(keys(%sections_count));
1.262     raeburn  2001:     }
1.410     raeburn  2002:     $seccount->{'st'} ++; # Increment for a section-less student role.  
1.262     raeburn  2003:     my $rolehash = {
                   2004:                      'roles'    => $courseroles,
                   2005:                      'seccount' => $seccount,
1.350     raeburn  2006:                      'privs'    => $courseprivs,
1.262     raeburn  2007:                    };
                   2008:     &Apache::lonnet::do_cache_new('getcourseroles',$cdom.'_'.$cnum,$rolehash);
                   2009:     return;
                   2010: }
                   2011: 
1.235     raeburn  2012: sub jump_to_role {
1.350     raeburn  2013:     my ($cdom,$cnum,$seccount,$courseroles,$courseprivs,$priv) = @_;
1.239     raeburn  2014:     my %lt = &Apache::lonlocal::texthash(
                   2015:                 this => 'This role has section(s) associated with it.',
                   2016:                 ente => 'Enter a specific section.',
                   2017:                 orlb => 'Enter a specific section, or leave blank for no section.',
                   2018:                 avai => 'Available sections are:',
                   2019:                 youe => 'You entered an invalid section choice:',
1.352     raeburn  2020:                 plst => 'Please try again.',
1.350     raeburn  2021:                 role => 'The role you selected is not permitted to view the current page.',
                   2022:                 swit => 'Switch role, but display Main Menu page instead?',
1.239     raeburn  2023:     );
                   2024:     my $js;
                   2025:     if (ref($courseroles) eq 'HASH') {
                   2026:         $js = '    var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n". 
                   2027:               '    var numsec = new Array();'."\n".
                   2028:               '    var rolesections = new Array();'."\n".
                   2029:               '    var rolenames = new Array();'."\n".
                   2030:               '    var roleseclist = new Array();'."\n";
                   2031:         my @items = keys(%{$courseroles});
                   2032:         for (my $i=0; $i<@items; $i++) {
                   2033:             $js .= '    rolenames['.$i.'] = "'.$items[$i].'";'."\n";
                   2034:             my ($secs,$secstr);
                   2035:             if (ref($courseroles->{$items[$i]}) eq 'ARRAY') {
                   2036:                 my @sections = sort { $a <=> $b } @{$courseroles->{$items[$i]}};
                   2037:                 $secs = join('","',@sections);
                   2038:                 $secstr = join(', ',@sections);
                   2039:             }
                   2040:             $js .= '    rolesections['.$i.'] = new Array("'.$secs.'");'."\n".
                   2041:                    '    roleseclist['.$i.'] = "'.$secstr.'";'."\n".
                   2042:                    '    numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n";
                   2043:         }
                   2044:     }
1.350     raeburn  2045:     my $checkroles = 0;
                   2046:     if ($priv && ref($courseprivs) eq 'HASH') {
                   2047:         my (%disallowed,%allowed,@disallow);
                   2048:         foreach my $role (sort(keys(%{$courseprivs}))) {
                   2049:             my $trole;
                   2050:             if ($role =~ m{^(.+?)\Q./$cdom/$cnum\E}) {
                   2051:                 $trole = $1;
                   2052:             }
                   2053:             if (($trole ne '') && ($trole ne 'cm')) {
                   2054:                 if ($courseprivs->{$role} =~ /\Q:$priv\E($|:|\&\w+)/) {
                   2055:                     $allowed{$trole} = 1;
                   2056:                 } else {
                   2057:                     $disallowed{$trole} = 1;
                   2058:                 }
                   2059:             }
                   2060:         }
                   2061:         foreach my $trole (keys(%disallowed)) {
                   2062:             unless ($allowed{$trole}) {
                   2063:                 push(@disallow,$trole);
                   2064:             }
                   2065:         }
                   2066:         if (@disallow > 0) {
                   2067:             $checkroles = 1;
                   2068:             $js .= "    var disallow = new Array('".join("','",@disallow)."');\n".
                   2069:                    "    var rolecheck = 1;\n";
                   2070:         }
                   2071:     }
                   2072:     if (!$checkroles) {
                   2073:         $js .=  "    var disallow = new Array();\n".
                   2074:                 "    rolecheck = 0;\n";
                   2075:     }
1.273     droeschl 2076:     return <<"END";
1.235     raeburn  2077: <script type="text/javascript">
1.273     droeschl 2078: //<![CDATA[
1.401     raeburn  2079: function adhocRole(newrole) {
1.239     raeburn  2080:     $js
1.235     raeburn  2081:     if (newrole == '') {
1.350     raeburn  2082:         return;
1.235     raeburn  2083:     } 
1.239     raeburn  2084:     var fullrole = newrole+'./$cdom/$cnum';
                   2085:     var selidx = '';
                   2086:     for (var i=0; i<rolenames.length; i++) {
                   2087:         if (rolenames[i] == newrole) {
                   2088:             selidx = i;
                   2089:         }
                   2090:     }
1.350     raeburn  2091:     if (rolecheck > 0) {
                   2092:         for (var i=0; i<disallow.length; i++) {
                   2093:             if (disallow[i] == newrole) {
                   2094:                 if (confirm("$lt{'role'}\\n$lt{'swit'}")) {
                   2095:                     document.rolechooser.destinationurl.value = '/adm/menu';
                   2096:                 } else {
                   2097:                     return;
                   2098:                 }
                   2099:             }
                   2100:         }
                   2101:     }
1.239     raeburn  2102:     var secok = 1;
                   2103:     var secchoice = '';
                   2104:     if (selidx >= 0) {
                   2105:         if (numsec[selidx] > 1) {
                   2106:             secok = 0;
                   2107:             var numrolesec = rolesections[selidx].length;
                   2108:             var msgidx = numsec[selidx] - numrolesec;
1.339     raeburn  2109:             secchoice = prompt("$lt{'this'} "+secpick[msgidx]+"\\n$lt{'avai'} "+roleseclist[selidx],"");
1.239     raeburn  2110:             if (secchoice == '') {
                   2111:                 if (msgidx > 0) {
                   2112:                     secok = 1;
                   2113:                 }
                   2114:             } else {
                   2115:                 for (var j=0; j<rolesections[selidx].length; j++) {
                   2116:                     if (rolesections[selidx][j] == secchoice) {
                   2117:                         secok = 1;
                   2118:                     }
                   2119:                 }
                   2120:             }
                   2121:         } else {
                   2122:             if (rolesections[selidx].length == 1) {
                   2123:                 secchoice = rolesections[selidx][0];
                   2124:             }
                   2125:         }
                   2126:     }
                   2127:     if (secok == 1) {
                   2128:         if (secchoice != '') {
                   2129:             fullrole += '/'+secchoice;
                   2130:         }
                   2131:     } else {
                   2132:         if (secchoice != null) {
                   2133:             alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}");
                   2134:         }
                   2135:         return;
                   2136:     }
                   2137:     if (fullrole == "$env{'request.role'}") {
1.235     raeburn  2138:         return;
                   2139:     }
                   2140:     itemid = retrieveIndex('gotorole');
                   2141:     if (itemid != -1) {
1.239     raeburn  2142:         document.rolechooser.elements[itemid].name = fullrole;
1.235     raeburn  2143:     }
1.401     raeburn  2144:     document.rolechooser.switchrole.value = fullrole;
1.235     raeburn  2145:     document.rolechooser.selectrole.value = '1';
                   2146:     document.rolechooser.submit();
                   2147:     return;
                   2148: }
                   2149: 
                   2150: function retrieveIndex(item) {
                   2151:     for (var i=0;i<document.rolechooser.elements.length;i++) {
                   2152:         if (document.rolechooser.elements[i].name == item) {
                   2153:             return i;
                   2154:         }
                   2155:     }
                   2156:     return -1;
                   2157: }
1.273     droeschl 2158: // ]]>
1.235     raeburn  2159: </script>
                   2160: END
                   2161: }
                   2162: 
1.350     raeburn  2163: sub required_privs {
                   2164:     my $privs =  {
                   2165:              '/adm/parmset'      => 'opa',
                   2166:              '/adm/courseprefs'  => 'opa',
                   2167:              '/adm/whatsnew'     => 'whn',
                   2168:              '/adm/populate'     => 'cst',
                   2169:              '/adm/trackstudent' => 'vsa',
                   2170:              '/adm/statistics'   => 'vgr',
1.366     raeburn  2171:              '/adm/setblock'     => 'dcm',
1.367     raeburn  2172:              '/adm/coursedocs'   => 'mdc',
1.350     raeburn  2173:            };
                   2174:     unless ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'spreadsheet') {
1.364     raeburn  2175:         $privs->{'/adm/classcalc'}   = 'vgr',
                   2176:         $privs->{'/adm/assesscalc'}  = 'vgr',
                   2177:         $privs->{'/adm/studentcalc'} = 'vgr';
1.350     raeburn  2178:     }
                   2179:     return $privs;
                   2180: }
1.235     raeburn  2181: 
1.378     raeburn  2182: sub countdown_timer {
                   2183:     if (($env{'request.course.id'}) && ($env{'request.symb'} ne '') &&
1.387     raeburn  2184:         ($env{'request.filename'}=~/$LONCAPA::assess_re/)) {
                   2185:         my ($type,$hastimeleft,$slothastime);
                   2186:         my $now = time;
                   2187:         if ($env{'request.filename'} =~ /\.task$/) {
                   2188:             $type = 'Task';
                   2189:         } else {
                   2190:             $type = 'problem';
                   2191:         }
                   2192:         my ($status,$accessmsg,$slot_name,$slot) =
                   2193:             &Apache::lonhomework::check_slot_access('0',$type);
                   2194:         if ($slot_name ne '') {
                   2195:             if (ref($slot) eq 'HASH') {
                   2196:                 if (($slot->{'starttime'} < $now) &&
                   2197:                     ($slot->{'endtime'} > $now)) {
                   2198:                     $slothastime = 1;
                   2199:                 }
                   2200:             }
                   2201:         }
                   2202:         if ($status ne 'CAN_ANSWER') {
                   2203:             return;
                   2204:         }
1.378     raeburn  2205:         my $duedate = &Apache::lonnet::EXT("resource.0.duedate");
1.380     raeburn  2206:         my @interval=&Apache::lonnet::EXT("resource.0.interval");
1.381     raeburn  2207:         if (@interval > 1) {
                   2208:             my $first_access=&Apache::lonnet::get_first_access($interval[1]);
                   2209:             if ($first_access > 0) {
                   2210:                 if ($first_access+$interval[0] > time) {
                   2211:                     $hastimeleft = 1;
                   2212:                 }
                   2213:             }
                   2214:         }
1.380     raeburn  2215:         if (($duedate && $duedate > time) ||
1.387     raeburn  2216:             (!$duedate && $hastimeleft) ||
                   2217:             ($slot_name ne '' && $slothastime)) {
1.379     raeburn  2218:             my ($collapse,$expand,$alttxt,$title,$currdisp);
1.387     raeburn  2219:             if ((@interval > 1 && $hastimeleft) ||
                   2220:                 ($type eq 'Task' && $slothastime)) {
1.378     raeburn  2221:                 $currdisp = 'inline';
                   2222:                 $collapse = '&#9658;&nbsp;';
                   2223:             } else {
                   2224:                 $currdisp = 'none';
                   2225:                 $expand = '&#9668;&nbsp;';
                   2226:             }
                   2227:             unless ($env{'environment.icons'} eq 'iconsonly') {
1.379     raeburn  2228:                 $alttxt = &mt('Timer');
                   2229:                 $title = $alttxt.'&nbsp;';
1.378     raeburn  2230:             }
                   2231:             my $desc = &mt('Countdown to due date/time');
                   2232:             return <<END;
                   2233: 
                   2234: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
                   2235: <span id="ddcountcollapse" class="LC_menubuttons_inline_text">
                   2236: $collapse
1.379     raeburn  2237: </span></a>
1.378     raeburn  2238: <span id="duedatecountdown" class="LC_menubuttons_inline_text" style="display: $currdisp;"></span>
                   2239: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
                   2240: <span id="ddcountexpand" class="LC_menubuttons_inline_text" >$expand</span>
1.379     raeburn  2241: <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  2242: END
                   2243:         }
                   2244:     }
                   2245:     return;
                   2246: }
                   2247: 
1.2       www      2248: # ================================================================ Main Program
                   2249: 
1.16      harris41 2250: BEGIN {
1.166     albertel 2251:     if (! defined($readdesk)) {
1.283     droeschl 2252:         {
                   2253:             my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
                   2254:             if ( CORE::open( my $config,"<$tabfile") ) {
                   2255:                 while (my $configline=<$config>) {
                   2256:                     $configline=(split(/\#/,$configline))[0];
                   2257:                     $configline=~s/^\s+//;
                   2258:                     chomp($configline);
1.209     www      2259:                     if ($configline=~/^cat\:/) {
1.283     droeschl 2260:                         my @entries=split(/\:/,$configline);
                   2261:                         $category_positions{$entries[2]}=$entries[1];
                   2262:                         $category_names{$entries[2]}=$entries[3];
                   2263:                     } elsif ($configline=~/^prim\:/) {
1.415     raeburn  2264:                         my @entries = (split(/\:/, $configline))[1..6];
1.400     raeburn  2265:                         push(@primary_menu,\@entries);
1.371     raeburn  2266:                     } elsif ($configline=~/^primsub\:/) {
                   2267:                         my ($parent,@entries) = (split(/\:/, $configline))[1..4];
1.400     raeburn  2268:                         push(@{$primary_submenu{$parent}},\@entries);
1.283     droeschl 2269:                     } elsif ($configline=~/^scnd\:/) {
                   2270:                         my @entries = (split(/\:/, $configline))[1..5];
1.401     raeburn  2271:                         push(@secondary_menu,\@entries);
1.283     droeschl 2272:                     } elsif ($configline) {
                   2273:                         push(@desklines,$configline);
                   2274:                     }
                   2275:                 }
                   2276:                 CORE::close($config);
                   2277:             }
                   2278:         }
                   2279:         $readdesk='done';
1.2       www      2280:     }
                   2281: }
1.30      www      2282: 
1.1       www      2283: 1;
                   2284: __END__
                   2285: 

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