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

1.1       www         1: # The LearningOnline Network with CAPA
                      2: # Routines to control the menu
                      3: #
1.435   ! musolffc    4: # $Id: lonmenu.pm,v 1.434 2015/05/28 03:14:25 raeburn Exp $
1.11      albertel    5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
1.1       www        28: #
                     29: 
1.244     jms        30: =head1 NAME
                     31: 
                     32: Apache::lonmenu
                     33: 
                     34: =head1 SYNOPSIS
                     35: 
1.371     raeburn    36: Loads contents of /home/httpd/lonTabs/mydesk.tab, 
                     37: used to generate inline menu, and Main Menu page. 
1.244     jms        38: 
                     39: This is part of the LearningOnline Network with CAPA project
                     40: described at http://www.lon-capa.org.
                     41: 
1.314     droeschl   42: =head1 GLOBAL VARIABLES
                     43: 
                     44: =over
                     45: 
                     46: =item @desklines
                     47: 
                     48: Each element of this array contains a line of mydesk.tab that doesn't start with
                     49: cat, prim or scnd. 
                     50: It gets filled in the BEGIN block of this module.
                     51: 
                     52: =item %category_names
                     53: 
                     54: The keys of this hash are the abbreviations used in mydesk.tab in those lines that 
                     55: start with cat, the values are strings representing titles. 
                     56: It gets filled in the BEGIN block of this module.
                     57: 
                     58: =item %category_members
                     59: 
                     60: TODO 
                     61: 
                     62: =item %category_positions
                     63: 
                     64: The keys of this hash are the abbreviations used in mydesk.tab in those lines that
                     65: start with cat, its values are position vectors (column, row). 
                     66: It gets filled in the BEGIN block of this module.
                     67: 
                     68: =item $readdesk
                     69: 
                     70: Indicates that mydesk.tab has been read. 
                     71: It is set to 'done' in the BEGIN block of this module.
                     72: 
                     73: =item @primary_menu
                     74: 
                     75: The elements of this array reference arrays that are made up of the components
1.371     raeburn    76: of those lines of mydesk.tab that start with prim:.
1.314     droeschl   77: It is used by primary_menu() to generate the corresponding menu.
                     78: It gets filled in the BEGIN block of this module.
                     79: 
1.371     raeburn    80: =item %primary_sub_menu
                     81: 
                     82: The keys of this hash reference are the names of items in the primary_menu array 
                     83: which have sub-menus.  For each key, the corresponding value is a reference to
                     84: an array containing components extracted from lines in mydesk.tab which begin
                     85: with primsub:.
                     86: This hash, which is used by primary_menu to generate sub-menus, is populated in
                     87: the BEGIN block.
                     88: 
1.314     droeschl   89: =item @secondary_menu
                     90: 
                     91: The elements of this array reference arrays that are made up of the components
                     92: of those lines of mydesk.tab that start with scnd.
                     93: It is used by secondary_menu() to generate the corresponding menu.
                     94: It gets filled in the BEGIN block of this module.
                     95: 
                     96: =back
                     97: 
1.244     jms        98: =head1 SUBROUTINES
                     99: 
                    100: =over
                    101: 
1.314     droeschl  102: =item prep_menuitems(\@menuitem)
                    103: 
                    104: This routine wraps a menuitem in proper HTML. It is used by primary_menu() and 
                    105: secondary_menu().
                    106: 
                    107: =item primary_menu()
                    108: 
1.415     raeburn   109: This routine evaluates @primary_menu and returns a two item array, 
                    110: with the array elements containing XHTML for the left and right sides of 
                    111: the menu that contains the following links: About, Message, Roles, Help, Logout 
1.314     droeschl  112: @primary_menu is filled within the BEGIN block of this module with 
1.415     raeburn   113: entries from mydesk.tab
1.314     droeschl  114: 
                    115: =item secondary_menu()
                    116: 
                    117: Same as primary_menu() but operates on @secondary_menu.
                    118: 
1.375     raeburn   119: =item create_submenu()
                    120: 
                    121: Creates XHTML for unordered list of sub-menu items which belong to a 
                    122: particular top-level menu item. Uses hover pseudo class in css to display
                    123: dropdown list when mouse hovers over top-level item. Support for IE6 
                    124: (no hover psuedo class) via LC_hoverable class for <li> tag for top-
                    125: level item, which employs jQuery to handle behavior on mouseover.
                    126: 
                    127: Inputs: 4 - (a) link and (b) target for anchor href in top level item,
                    128:             (c) title for text wrapped by anchor tag in top level item.
                    129:             (d) reference to array of arrays of sub-menu items.
                    130: 
1.431     golterma  131:  The underlying datastructure used in (d) contains data from mydesk.tab.
                    132:  It consists of an array which has an array for each item appearing in
                    133:  the menu (e.g. [["link", "title", "condition"]] for a single-item menu).
                    134:  create_submenu() supports also the creation of XHTML for nested dropdown
                    135:  menus represented by unordered lists. This is done by replacing the
                    136:  scalar used for the link with an arrayreference containing the menuitems
                    137:  for the nested menu. This can be done recursively so that the next menu
                    138:  may also contain nested submenus.
                    139: 
                    140:  Example:
                    141:  [											# begin of datastructure
                    142: 	["/home/", "Home", "condition1"], 		# 1st item of the 1st layer menu
                    143: 	[										# 2nd item of the 1st layer menu
                    144: 		[									# anon. array for nested menu
                    145: 			["/path1", "Path1", undef], 	# 1st item of the 2nd layer menu
                    146: 			["/path2", "Path2", undef], 	# 2nd item of the 2nd layer menu
                    147: 			[								# 3rd item of the 2nd layer menu
                    148: 				[[...], [...], ..., [...]],	# containing another menu layer
                    149: 				"Sub-Sub-Menu",				# title for this container
                    150: 				undef
                    151: 			]
                    152: 		],									# end of array/nested menu
                    153: 		"Sub-Menu",							# title for the container item
                    154: 		undef
                    155: 	]										# end of 2nd item of the 1st layer menu
                    156: ]
                    157: 
1.244     jms       158: =item innerregister()
                    159: 
1.320     droeschl  160: This gets called in order to register a URL in the body of the document
1.244     jms       161: 
                    162: =item clear()
                    163: 
                    164: =item switch()
                    165: 
                    166: Switch a button or create a link
                    167: Switch acts on the javascript that is executed when a button is clicked.  
                    168: The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
                    169: 
                    170: =item secondlevel()
                    171: 
                    172: =item openmenu()
                    173: 
                    174: =item inlinemenu()
                    175: 
                    176: =item rawconfig()
                    177: 
                    178: =item utilityfunctions()
                    179: 
1.371     raeburn   180: Output from this routine is a number of javascript functions called by
                    181: items in the inline menu, and in some cases items in the Main Menu page. 
                    182: 
1.244     jms       183: =item serverform()
                    184: 
                    185: =item constspaceform()
                    186: 
                    187: =item get_nav_status()
                    188: 
                    189: =item hidden_button_check()
                    190: 
                    191: =item roles_selector()
                    192: 
                    193: =item jump_to_role()
                    194: 
                    195: =back
                    196: 
                    197: =cut
                    198: 
1.1       www       199: package Apache::lonmenu;
                    200: 
                    201: use strict;
1.152     albertel  202: use Apache::lonnet;
1.47      matthew   203: use Apache::lonhtmlcommon();
1.115     albertel  204: use Apache::loncommon();
1.127     albertel  205: use Apache::lonenc();
1.88      www       206: use Apache::lonlocal;
1.361     raeburn   207: use Apache::lonmsg();
1.207     foxr      208: use LONCAPA qw(:DEFAULT :match);
1.282     amueller  209: use HTML::Entities();
1.346     wenzelju  210: use Apache::lonwishlist();
1.88      www       211: 
1.283     droeschl  212: use vars qw(@desklines %category_names %category_members %category_positions 
1.371     raeburn   213:             $readdesk @primary_menu %primary_submenu @secondary_menu);
1.88      www       214: 
1.56      www       215: my @inlineremote;
1.38      www       216: 
1.283     droeschl  217: sub prep_menuitem {
1.291     raeburn   218:     my ($menuitem) = @_;
                    219:     return '' unless(ref($menuitem) eq 'ARRAY');
1.283     droeschl  220:     my $link;
                    221:     if ($$menuitem[1]) { # graphical Link
                    222:         $link = "<img class=\"LC_noBorder\""
1.291     raeburn   223:               . " src=\"" . &Apache::loncommon::lonhttpdurl($$menuitem[1]) . "\"" 
                    224:               . " alt=\"" . &mt($$menuitem[2]) . "\" />";
1.283     droeschl  225:     } else {             # textual Link
1.291     raeburn   226:         $link = &mt($$menuitem[3]);
                    227:     }
1.316     droeschl  228:     return '<li><a' 
                    229:            # highlighting for new messages
                    230:            . ( $$menuitem[4] eq 'newmsg' ? ' class="LC_new_message"' : '') 
1.325     droeschl  231:            . qq| href="$$menuitem[0]" target="_top">$link</a></li>|;
1.283     droeschl  232: }
                    233: 
1.415     raeburn   234: # primary_menu() evaluates @primary_menu and returns a two item array,
                    235: # with the array elements containing XHTML for the left and right sides of 
                    236: # the menu that contains the following links:
                    237: # Personal, About, Message, Roles, Help, Logout
1.283     droeschl  238: # @primary_menu is filled within the BEGIN block of this module with 
                    239: # entries from mydesk.tab
                    240: sub primary_menu {
1.415     raeburn   241:     my (%menu);
1.283     droeschl  242:     # each element of @primary contains following array:
1.415     raeburn   243:     # (link url, icon path, alt text, link text, condition, position)
1.319     raeburn   244:     my $public;
                    245:     if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
                    246:         || (($env{'user.name'} eq '') && ($env{'user.domain'} eq ''))) {
                    247:         $public = 1;
                    248:     }
1.283     droeschl  249:     foreach my $menuitem (@primary_menu) {
                    250:         # evaluate conditions 
1.296     droeschl  251:         next if    ref($menuitem)       ne 'ARRAY';    #
1.283     droeschl  252:         next if    $$menuitem[4]        eq 'nonewmsg'  # show links depending on
1.291     raeburn   253:                 && &Apache::lonmsg::mynewmail();       # whether a new msg 
1.283     droeschl  254:         next if    $$menuitem[4]        eq 'newmsg'    # arrived or not
1.291     raeburn   255:                 && !&Apache::lonmsg::mynewmail();      # 
1.319     raeburn   256:         next if    $$menuitem[4]        !~ /public/    ##we've a public user,
                    257:                 && $public;                            ##who should not see all
                    258:                                                        ##links
1.283     droeschl  259:         next if    $$menuitem[4]        eq 'onlypublic'# hide links which are 
1.319     raeburn   260:                 && !$public;                           # only visible to public
                    261:                                                        # users
1.283     droeschl  262:         next if    $$menuitem[4]        eq 'roles'     ##show links depending on
1.291     raeburn   263:                 && &Apache::loncommon::show_course();  ##term 'Courses' or 
1.283     droeschl  264:         next if    $$menuitem[4]        eq 'courses'   ##'Roles' wanted
1.291     raeburn   265:                 && !&Apache::loncommon::show_course(); ##
                    266:         
1.371     raeburn   267:         my $title = $menuitem->[3];
1.415     raeburn   268:         my $position = $menuitem->[5];
                    269:         if ($position eq '') {
                    270:             $position = 'right';
                    271:         }
1.371     raeburn   272:         if (defined($primary_submenu{$title})) {
1.375     raeburn   273:             my ($link,$target);
1.371     raeburn   274:             if ($menuitem->[0] ne '') {
                    275:                 $link = $menuitem->[0];
                    276:                 $target = '_top';
                    277:             } else {
                    278:                 $link = '#';
                    279:             }
1.375     raeburn   280:             my @primsub;
1.371     raeburn   281:             if (ref($primary_submenu{$title}) eq 'ARRAY') {
1.375     raeburn   282:                 foreach my $item (@{$primary_submenu{$title}}) {
1.383     raeburn   283:                     next if (($item->[2] eq 'wishlist') && (!$env{'user.adv'}));
1.375     raeburn   284:                     next if ((($item->[2] eq 'portfolio') ||
                    285:                              ($item->[2] eq 'blog')) &&
                    286:                              (!&Apache::lonnet::usertools_access('','',$item->[2],
                    287:                                                            undef,'tools')));
                    288:                     push(@primsub,$item);
                    289:                 }
                    290:                 if (@primsub > 0) {
1.432     droeschl  291:                     if ($title eq 'Personal' && $env{'user.name'} && $env{'user.domain'} ) {
                    292:                         $title = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'});
                    293:                     } else {
                    294:                         $title = &mt($title);
                    295:                     }
1.419     bisitz    296:                     $menu{$position} .= &create_submenu($link,$target,$title,\@primsub,1);
1.375     raeburn   297:                 } elsif ($link) {
1.415     raeburn   298:                     $menu{$position} .= '<li><a href="'.$link.'" target="'.$target.'">'.&mt($title).'</a></li>';
1.371     raeburn   299:                 }
                    300:             }
                    301:         } elsif ($$menuitem[3] eq 'Help') { # special treatment for helplink
1.340     raeburn   302:             if ($public) {
                    303:                 my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
                    304:                 my $defdom = &Apache::lonnet::default_login_domain();
                    305:                 my $to = &Apache::loncommon::build_recipient_list(undef,
                    306:                                                                   'helpdeskmail',
                    307:                                                                   $defdom,$origmail);
                    308:                 if ($to ne '') {
1.415     raeburn   309:                     $menu{$position} .= &prep_menuitem($menuitem); 
1.340     raeburn   310:                 }
                    311:             } else {
1.415     raeburn   312:                 $menu{$position} .= '<li>'.&Apache::loncommon::top_nav_help('Help').'</li>';
1.340     raeburn   313:             }
1.283     droeschl  314:         } else {
1.415     raeburn   315:             $menu{$position} .= prep_menuitem($menuitem);
1.283     droeschl  316:         }
1.291     raeburn   317:     }
1.423     raeburn   318:     my @output = ('','');
                    319:     if ($menu{'left'} ne '') {
                    320:         $output[0] = "<ol class=\"LC_primary_menu LC_floatleft\">$menu{'left'}</ol>";
                    321:     }
                    322:     if ($menu{'right'} ne '') {
                    323:         $output[1] = "<ol class=\"LC_primary_menu LC_floatright LC_right\">$menu{'right'}</ol>";
                    324:     }
                    325:     return @output;
1.283     droeschl  326: }
                    327: 
1.329     droeschl  328: #returns hashref {user=>'',dom=>''} containing:
                    329: #   own name, domain if user is au
                    330: #   name, domain of parent author if user is ca or aa
                    331: #empty return if user is not an author or not on homeserver
                    332: #
                    333: #TODO this should probably be moved somewhere more central
                    334: #since it can be used by different parts of the system
                    335: sub getauthor{
                    336:     return unless $env{'request.role'}=~/^(ca|aa|au)/; #nothing to do if user isn't some kind of author
                    337: 
                    338:                         #co- or assistent author?
                    339:     my ($dom, $user) = ($env{'request.role'} =~ /^(?:ca|aa)\.\/($match_domain)\/($match_username)$/)
                    340:                        ? ($1, $2) #domain, username of the parent author
                    341:                        : @env{ ('request.role.domain', 'user.name') }; #own domain, username
                    342: 
                    343:     # current server == home server?
                    344:     my $home =  &Apache::lonnet::homeserver($user,$dom);
                    345:     foreach (&Apache::lonnet::current_machine_ids()){
                    346:         return {user => $user, dom => $dom} if $_ eq $home;
                    347:     }
                    348: 
                    349:     # if wrong server
                    350:     return;
                    351: }
1.283     droeschl  352: 
                    353: sub secondary_menu {
1.421     raeburn   354:     my ($httphost) = @_;
1.283     droeschl  355:     my $menu;
                    356: 
1.286     raeburn   357:     my $crstype = &Apache::loncommon::course_type();
1.327     droeschl  358:     my $crs_sec = $env{'request.course.id'} . ($env{'request.course.sec'} 
                    359:                                                ? "/$env{'request.course.sec'}"
                    360:                                                : '');
                    361:     my $canedit       = &Apache::lonnet::allowed('mdc', $env{'request.course.id'});
1.376     raeburn   362:     my $canviewroster = $env{'course.'.$env{'request.course.id'}.'.student_classlist_view'};
1.418     raeburn   363:     if ($canviewroster eq 'disabled') {
                    364:         undef($canviewroster);
                    365:     }
1.327     droeschl  366:     my $canviewgrps   = &Apache::lonnet::allowed('vcg', $crs_sec); 
                    367:     my $canmodifyuser = &Apache::lonnet::allowed('cst', $crs_sec); 
                    368:     my $canviewwnew   = &Apache::lonnet::allowed('whn', $crs_sec); 
1.341     www       369:     my $canmodpara    = &Apache::lonnet::allowed('opa', $crs_sec);
1.343     www       370:     my $canvgr        = &Apache::lonnet::allowed('vgr', $crs_sec);
                    371:     my $canmgr        = &Apache::lonnet::allowed('mgr', $crs_sec); 
                    372:     my $author        = &getauthor();
1.327     droeschl  373: 
1.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) {
1.434     raeburn   930:         if ((($ENV{'SERVER_PORT'} == 443) || 
                    931:              ($Apache::lonnet::protocol{$Apache::lonnet::perlvar{'lonHostID'}} eq 'https')) && 
                    932:             (&Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},'webdav'))) {
1.433     raeburn   933:             $topic_help = 'Authoring_WebDAV,Authoring_WebDAV_Mac_10v6,Authoring_WebDAV_Mac_10v10,'.
                    934:                           'Authoring_WebDAV_Windows_v7,Authoring_WebDAV_Linux_Centos';
                    935:             $topic_help_text = 'About WebDAV access';
                    936:         }
                    937:     }
1.342     www       938:     return   &Apache::lonhtmlcommon::scripttag('', 'start')
1.433     raeburn   939:            . &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0,'','','','',$topic_help,$topic_help_text)
1.342     www       940:            . &Apache::lonhtmlcommon::scripttag('', 'end');
1.38      www       941: }
                    942: 
1.389     raeburn   943: sub get_editbutton {
1.390     raeburn   944:     my ($cfile,$home,$switchserver,$forceedit,$forceview,$forcereg) = @_;
1.398     raeburn   945:     my $jscall;
                    946:     if (($forceview) && ($env{'form.todocs'})) {
                    947:         my ($folderpath,$command);
                    948:         if ($env{'request.symb'}) {
                    949:             $folderpath = &Apache::loncommon::symb_to_docspath($env{'request.symb'});
                    950:         } elsif ($env{'form.folderpath'} =~ /^supplemental/) {
                    951:             $folderpath = $env{'form.folderpath'};
                    952:             $command = '&forcesupplement=1';
                    953:         }
                    954:         $folderpath = &escape(&HTML::Entities::encode(&escape($folderpath),'<>&"'));
                    955:         $jscall = "go('/adm/coursedocs?folderpath=$folderpath$command')";
                    956:     } else {
                    957:         $jscall = &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,$switchserver,
1.393     raeburn   958:                                                 $forceedit,$forcereg,$env{'request.symb'},
                    959:                                                 &escape($env{'form.folderpath'}),
                    960:                                                 &escape($env{'form.title'}),$env{'form.idx'},
1.398     raeburn   961:                                                 &escape($env{'form.suppurl'},$env{'form.todocs'}));
                    962:     }
1.389     raeburn   963:     if ($jscall) {
1.390     raeburn   964:         my $icon = 'pcstr.png';
                    965:         my $label = 'Edit';
                    966:         if ($forceview) {
                    967:             $icon = 'tolastloc.png';
                    968:             $label = 'Exit Editing';
                    969:         }
                    970:         &switch('','',6,1,$icon,$label,'resource[_2]',
                    971:                 $jscall,"Edit this resource");
                    972:         return 1;
                    973:     }
                    974:     return;
                    975: }
                    976: 
                    977: sub prepare_functions {
1.393     raeburn   978:     my ($resurl,$forcereg,$group,$bread_crumbs,$advtools,$docscrumbs) = @_;
1.390     raeburn   979:     unless ($env{'request.registered'}) {
                    980:         undef(@inlineremote);
                    981:     }
                    982:     my ($cdom,$cnum,%perms,$cfile,$switchserver,$home,$forceedit,
                    983:         $forceview);
                    984: 
                    985:     if ($env{'request.course.id'}) {
                    986:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                    987:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                    988:         $perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
                    989:     }
                    990: 
                    991:     my $editbutton = '';
                    992: #
                    993: # Determine whether or not to display 'Edit' icon/button
                    994: #
                    995:     if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
                    996:         my $file=&Apache::lonnet::declutter($env{'request.filename'});
1.391     raeburn   997:         ($cfile,$home,$switchserver,$forceedit,$forceview) =
                    998:             &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
                    999:                 &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
                   1000:         if (($cfile) && ($home ne '') && ($home ne 'no_host')) {
                   1001:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
1.390     raeburn  1002:                                           $forceedit,$forceview,$forcereg);
                   1003:         }
1.391     raeburn  1004:     } elsif ((!$env{'request.course.id'}) &&
1.390     raeburn  1005:              ($env{'user.author'}) && ($env{'request.filename'}) &&
                   1006:              ($env{'request.role'} !~/^(aa|ca|au)/)) {
                   1007: #
                   1008: # Currently do not have the role of author or co-author.
                   1009: # Do we have authoring privileges for the resource?
                   1010: #
                   1011:         my $file=&Apache::lonnet::declutter($env{'request.filename'});
                   1012:         ($cfile,$home,$switchserver,$forceedit,$forceview) =
                   1013:             &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
                   1014:                 &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
                   1015:         if (($cfile) && ($home ne '') && ($home ne 'no_host')) {
                   1016:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
                   1017:                                           $forceedit,$forceview,$forcereg);
                   1018:         }
                   1019:     } elsif ($env{'request.course.id'}) {
                   1020: #
                   1021: # This applies in course context
                   1022: #
1.412     raeburn  1023:         if (($perms{'mdc'}) &&
                   1024:             (($resurl eq "/public/$cdom/$cnum/syllabus") ||
                   1025:             ($resurl =~ m{^/uploaded/$cdom/$cnum/portfolio/syllabus/}))) {
1.411     raeburn  1026:             $cfile = $resurl;
                   1027:             $home = &Apache::lonnet::homeserver($cnum,$cdom);
                   1028:             if ($env{'form.forceedit'}) {
                   1029:                 $forceview = 1;
1.390     raeburn  1030:             } else {
1.411     raeburn  1031:                 $forceedit = 1;
1.390     raeburn  1032:             }
1.411     raeburn  1033:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
                   1034:                                           $forceedit,$forceview,$forcereg);
1.393     raeburn  1035:         } elsif (($resurl eq '/adm/extresedit') &&
                   1036:                  (($env{'form.symb'}) || ($env{'form.folderpath'}))) {
                   1037:             ($cfile,$home,$switchserver,$forceedit,$forceview) =
                   1038:             &Apache::lonnet::can_edit_resource($resurl,$cnum,$cdom,$resurl,
                   1039:                                                $env{'form.symb'});
                   1040:             if ($cfile ne '') {
                   1041:                 $editbutton = &get_editbutton($cfile,$home,$switchserver,
                   1042:                                               $forceedit,$forceview,$forcereg,
                   1043:                                               $env{'form.title'},$env{'form.suppurl'});
                   1044:             }
1.406     raeburn  1045:         } elsif (($resurl =~ m{^/?adm/viewclasslist$}) &&
                   1046:                  (&Apache::lonnet::allowed('opa',$env{'request.course.id'}))) {
                   1047:             ($cfile,$home,$switchserver,$forceedit,$forceview) =
                   1048:             &Apache::lonnet::can_edit_resource($resurl,$cnum,$cdom,$resurl,
                   1049:                                                $env{'form.symb'});
                   1050:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
                   1051:                                           $forceedit,$forceview,$forcereg);
1.405     raeburn  1052:         } elsif (($resurl !~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) &&
                   1053:                  ($resurl ne '/cgi-bin/printout.pl')) {
1.390     raeburn  1054:             if ($env{'request.filename'}) {
                   1055:                 my $file=&Apache::lonnet::declutter($env{'request.filename'});
                   1056:                 ($cfile,$home,$switchserver,$forceedit,$forceview) =
                   1057:                     &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
                   1058:                         &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
                   1059:                 if ($cfile ne '') {
                   1060:                     $editbutton = &get_editbutton($cfile,$home,$switchserver,
                   1061:                                                   $forceedit,$forceview,$forcereg);
                   1062:                 }
                   1063:             }
                   1064:         }
                   1065:     }
                   1066: # End determination of 'Edit' icon/button display
                   1067: 
1.393     raeburn  1068:     if ($env{'request.course.id'}) {
1.390     raeburn  1069: # This applies to about me page for users in a course
1.391     raeburn  1070:         if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
1.390     raeburn  1071:             my ($sdom,$sname) = ($1,$2);
                   1072:             unless (&Apache::lonnet::is_course($sdom,$sname)) {
                   1073:                 &switch('','',6,4,'mail-message-new-22x22.png','Message to user',
                   1074:                         '',
1.415     raeburn  1075:                         "go('/adm/email?compose=individual&amp;recname=$sname&amp;recdom=$sdom')",
1.390     raeburn  1076:                             'Send message to specific user');
                   1077:             }
1.391     raeburn  1078:             my $hideprivileged = 1;
                   1079:             if (&Apache::lonnet::in_course($sdom,$sname,$cdom,$cnum,undef,
                   1080:                                            $hideprivileged)) {
1.390     raeburn  1081:                 foreach my $priv ('vsa','vgr','srm') {
                   1082:                     $perms{$priv} = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
                   1083:                     if (!$perms{$priv} && $env{'request.course.sec'} ne '') {
                   1084:                         $perms{$priv} =
                   1085:                             &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
                   1086:                     }
                   1087:                 }
                   1088:                 if ($perms{'vsa'}) {
                   1089:                     &switch('','',6,5,'trck-22x22.png','Activity',
                   1090:                             '',
                   1091:                             "go('/adm/trackstudent?selected_student=$sname:$sdom')",
                   1092:                             'View recent activity by this person');
                   1093:                 }
                   1094:                 if ($perms{'vgr'}) {
                   1095:                     &switch('','',6,6,'rsrv-22x22.png','Reservations',
                   1096:                             '',
1.415     raeburn  1097:                             "go('/adm/slotrequest?command=showresv&amp;origin=aboutme&amp;uname=$sname&amp;udom=$sdom')",
1.390     raeburn  1098:                             'Slot reservation history');
                   1099:                 }
                   1100:                 if ($perms{'srm'}) {
                   1101:                     &switch('','',6,7,'contact-new-22x22.png','Records',
                   1102:                             '',
1.415     raeburn  1103:                             "go('/adm/email?recordftf=retrieve&amp;recname=$sname&amp;recdom=$sdom')",
1.390     raeburn  1104:                             'Add records');
                   1105:                 }
                   1106:             }
1.393     raeburn  1107:         }
                   1108:         if (($env{'form.folderpath'} =~ /^supplemental/) &&
                   1109:             (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) &&
                   1110:             (($resurl =~ m{^/adm/wrapper/ext/}) ||
                   1111:              ($resurl =~ m{^/uploaded/$cdom/$cnum/supplemental/}) ||
1.397     raeburn  1112:              ($resurl eq '/adm/supplemental') ||
                   1113:              ($resurl =~ m{^/public/$cdom/$cnum/syllabus$}) ||
                   1114:              ($resurl =~ m{^/adm/$match_domain/$match_username/aboutme$}))) {
1.393     raeburn  1115:             my @folders=split('&',$env{'form.folderpath'});
1.394     raeburn  1116:             if ((@folders > 2) || ($resurl ne '/adm/supplemental')) {
1.393     raeburn  1117:                 my $esc_path=&escape(&HTML::Entities::encode(&escape($env{'form.folderpath'}),'<>&"'));
                   1118:                 &switch('','',7,4,'docs-22x22.png','Edit Folder','parms[_2]',
1.415     raeburn  1119:                         "location.href='/adm/coursedocs?command=direct&amp;forcesupplement=1&amp;supppath=$esc_path'",
1.393     raeburn  1120:                         'Folder/Page Content');
                   1121:             }
1.390     raeburn  1122:         }
                   1123:     }
                   1124: 
                   1125: # End checking for items for about me page for users in a course
1.393     raeburn  1126:     if ($docscrumbs) {
                   1127:         &Apache::lonhtmlcommon::clear_breadcrumb_tools();
                   1128:         &advtools_crumbs(@inlineremote);
                   1129:         return $editbutton;
                   1130:     } elsif ($env{'request.registered'}) {
1.390     raeburn  1131:         return $editbutton;
                   1132:     } else {
                   1133:         if (ref($bread_crumbs) eq 'ARRAY') {
                   1134:             if (@inlineremote > 0) {
                   1135:                 if (ref($advtools) eq 'ARRAY') {
                   1136:                     @{$advtools} = @inlineremote;
                   1137:                 }
                   1138:             }
                   1139:             return;
                   1140:         } elsif (@inlineremote > 0) {
                   1141:             &Apache::lonhtmlcommon::clear_breadcrumb_tools();
                   1142:             &advtools_crumbs(@inlineremote);
                   1143:             return   &Apache::lonhtmlcommon::scripttag('', 'start')
                   1144:                    . &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
                   1145:                    . &Apache::lonhtmlcommon::scripttag('', 'end');
                   1146:         }
                   1147:     }
                   1148: }
                   1149: 
                   1150: sub advtools_crumbs {
                   1151:     my @funcs = @_;
                   1152:     if ($env{'request.noversionuri'} =~ m{^/adm/$match_domain/$match_username/aboutme$}) {
                   1153:         &Apache::lonhtmlcommon::add_breadcrumb_tool(
                   1154:             'advtools', @funcs[61,64,65,66,67,74]);
                   1155:     } elsif ($env{'request.noversionuri'} !~ m{^/adm/(navmaps|viewclasslist)(\?|$)}) {
                   1156:         &Apache::lonhtmlcommon::add_breadcrumb_tool(
                   1157:             'advtools', @funcs[61,71,72,73,74,92]);
1.393     raeburn  1158:     } elsif ($env{'request.noversionuri'} eq '/adm/viewclasslist') {
                   1159:         &Apache::lonhtmlcommon::add_breadcrumb_tool(
1.407     raeburn  1160:             'advtools', $funcs[61]);
1.393     raeburn  1161:     }
1.412     raeburn  1162:     return;
1.258     raeburn  1163: }
                   1164: 
1.2       www      1165: # ================================================================== Raw Config
                   1166: 
1.3       www      1167: sub clear {
                   1168:     my ($row,$col)=@_;
1.316     droeschl 1169:     $inlineremote[10*$row+$col]='';
                   1170:     return ''; 
1.3       www      1171: }
                   1172: 
1.40      www      1173: # ============================================ Switch a button or create a link
1.25      matthew  1174: # Switch acts on the javascript that is executed when a button is clicked.  
                   1175: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
1.40      www      1176: 
1.2       www      1177: sub switch {
1.209     www      1178:     my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak)=@_;
1.2       www      1179:     $act=~s/\$uname/$uname/g;
                   1180:     $act=~s/\$udom/$udom/g;
1.88      www      1181:     $top=&mt($top);
                   1182:     $bot=&mt($bot);
                   1183:     $desc=&mt($desc);
1.209     www      1184:     my $idx=10*$row+$col;
                   1185:     $category_members{$cat}.=':'.$idx;
                   1186: 
1.320     droeschl 1187: # Inline Menu
1.317     droeschl 1188:     if ($nobreak==2) { return ''; }
                   1189:     my $text=$top.' '.$bot;
                   1190:     $text=~s/\s*\-\s*//gs;
1.105     www      1191: 
1.317     droeschl 1192:     my $pic=
1.225     albertel 1193: 	   '<img alt="'.$text.'" src="'.
                   1194: 	   &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
1.303     droeschl 1195: 	   '" align="'.($nobreak==3?'right':'left').'" class="LC_icon" />';
1.317     droeschl 1196:     if ($env{'browser.interface'} eq 'faketextual') {
1.274     www      1197: # Main Menu
1.103     www      1198: 	   if ($nobreak==3) {
1.209     www      1199: 	       $inlineremote[$idx]="\n".
1.177     albertel 1200: 		   '<td class="LC_menubuttons_text" align="right">'.$text.
1.247     harmsja  1201: 		   '</td><td align="left">'.
1.103     www      1202: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
                   1203: 	   } elsif ($nobreak) {
1.209     www      1204: 	       $inlineremote[$idx]="\n<tr>".
1.247     harmsja  1205: 		   '<td align="left">'.
1.177     albertel 1206: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td>
1.215     www      1207:                     <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      1208: 	   } else {
1.209     www      1209: 	       $inlineremote[$idx]="\n<tr>".
1.247     harmsja  1210: 		   '<td align="left">'.
1.103     www      1211: 		   '<a href="javascript:'.$act.';">'.$pic.
1.177     albertel 1212: 		   '</a></td><td class="LC_menubuttons_text" colspan="3">'.
1.215     www      1213: 		   '<a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$desc.'</span></a></td></tr>';
1.103     www      1214: 	   }
1.317     droeschl 1215:     } else {
1.103     www      1216: # Inline Menu
1.378     raeburn  1217:         my @tools = (93,91,81,82,83);
                   1218:         unless ($env{'request.state'} eq 'construct') {
                   1219:             push(@tools,63);
                   1220:         }
                   1221:         if (($env{'environment.icons'} eq 'iconsonly') && 
                   1222:             (grep(/^$idx$/,@tools))) {
                   1223:             $inlineremote[$idx] =
                   1224:         '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.'</a>';
                   1225:         } else {
                   1226:             $inlineremote[$idx] =
1.317     droeschl 1227:        '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.
1.344     www      1228:        '<span class="LC_menubuttons_inline_text">'.$top.'&nbsp;</span></a>';
1.378     raeburn  1229:         }
1.317     droeschl 1230:     }
1.56      www      1231:     return '';
1.2       www      1232: }
                   1233: 
                   1234: sub secondlevel {
                   1235:     my $output='';
                   1236:     my 
1.209     www      1237:     ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_;
1.2       www      1238:     if ($prt eq 'any') {
1.209     www      1239: 	   $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1240:     } elsif ($prt=~/^r(\w+)/) {
                   1241:         if ($rol eq $1) {
1.209     www      1242:            $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1243:         }
                   1244:     }
                   1245:     return $output;
                   1246: }
                   1247: 
1.56      www      1248: sub inlinemenu {
1.210     albertel 1249:     undef(@inlineremote);
                   1250:     undef(%category_members);
1.275     www      1251: # calling rawconfig with "1" will evaluate mydesk.tab, even if there is no active remote control
1.56      www      1252:     &rawconfig(1);
1.309     bisitz   1253:     my $output='<table><tr>';
1.209     www      1254:     for (my $col=1; $col<=2; $col++) {
1.241     riegler  1255:         $output.='<td class="LC_mainmenu_col_fieldset">';
1.209     www      1256:         for (my $row=1; $row<=8; $row++) {
                   1257:             foreach my $cat (keys(%category_members)) {
                   1258:                if ($category_positions{$cat} ne "$col,$row") { next; }
1.247     harmsja  1259:                #$output.='<table><tr><td colspan="4" class="LC_menubuttons_category">'.&mt($category_names{$cat}).'</td></tr>';
1.309     bisitz   1260:                $output.='<div class="LC_Box LC_400Box">';
                   1261: 	       $output.='<h3 class="LC_hcell">'.&mt($category_names{$cat}).'</h3>';
1.247     harmsja  1262:                $output.='<table>';
1.240     riegler  1263:                my %active=();
                   1264:                foreach my $menu_item (split(/\:/,$category_members{$cat})) {
                   1265:                   if ($inlineremote[$menu_item]) {
                   1266:                      $active{$menu_item}=1;
                   1267:                   }
                   1268:                }  
                   1269:                foreach my $item (sort(keys(%active))) {
                   1270:                   $output.=$inlineremote[$item];
                   1271:                }
                   1272:                $output.='</table>';
1.245     harmsja  1273:                $output.='</div>';
1.240     riegler  1274:             }
                   1275:          }
                   1276:          $output.="</td>";
                   1277:     }
                   1278:     $output.="</tr></table>";
                   1279:     return $output;
                   1280: }
                   1281: 
1.2       www      1282: sub rawconfig {
1.274     www      1283: #
                   1284: # This evaluates mydesk.tab
                   1285: # Need to add more positions and more privileges to deal with all
                   1286: # menu items.
                   1287: #
1.34      www      1288:     my $textualoverride=shift;
                   1289:     my $output='';
1.316     droeschl 1290:     return '' unless $textualoverride;
1.152     albertel 1291:     my $uname=$env{'user.name'};
                   1292:     my $udom=$env{'user.domain'};
                   1293:     my $adv=$env{'user.adv'};
1.266     raeburn  1294:     my $show_course=&Apache::loncommon::show_course();
1.152     albertel 1295:     my $author=$env{'user.author'};
1.5       www      1296:     my $crs='';
1.295     raeburn  1297:     my $crstype='';
1.152     albertel 1298:     if ($env{'request.course.id'}) {
                   1299:        $crs='/'.$env{'request.course.id'};
                   1300:        if ($env{'request.course.sec'}) {
                   1301: 	   $crs.='_'.$env{'request.course.sec'};
1.7       www      1302:        }
1.8       www      1303:        $crs=~s/\_/\//g;
1.295     raeburn  1304:        $crstype = &Apache::loncommon::course_type();
1.5       www      1305:     }
1.152     albertel 1306:     my $pub=($env{'request.state'} eq 'published');
                   1307:     my $con=($env{'request.state'} eq 'construct');
                   1308:     my $rol=$env{'request.role'};
1.427     raeburn  1309:     my $requested_domain;
                   1310:     if ($rol) {
                   1311:        $requested_domain = $env{'request.role.domain'};
                   1312:     }
1.184     raeburn  1313:     foreach my $line (@desklines) {
1.209     www      1314:         my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
1.3       www      1315:         $prt=~s/\$uname/$uname/g;
                   1316:         $prt=~s/\$udom/$udom/g;
1.295     raeburn  1317:         if ($prt =~ /\$crs/) {
                   1318:             next unless ($env{'request.course.id'});
                   1319:             next if ($crstype eq 'Community');
                   1320:             $prt=~s/\$crs/$crs/g;
                   1321:         } elsif ($prt =~ /\$cmty/) {
                   1322:             next unless ($env{'request.course.id'});
                   1323:             next if ($crstype ne 'Community');
                   1324:             $prt=~s/\$cmty/$crs/g;
                   1325:         }
1.427     raeburn  1326:         if ($prt =~ m/\$requested_domain/) {
                   1327:             if ((!$requested_domain) && ($pro eq 'pbre') && ($env{'user.adv'})) {
                   1328:                 $prt=~s/\$requested_domain/$env{'user.domain'}/g;
                   1329:             } else {
                   1330:                 $prt=~s/\$requested_domain/$requested_domain/g;
                   1331:             }
                   1332:         }
1.211     www      1333:         if ($category_names{$cat}!~/\w/) { $cat='oth'; }
1.3       www      1334:         if ($pro eq 'clear') {
1.4       www      1335: 	    $output.=&clear($row,$col);
1.3       www      1336:         } elsif ($pro eq 'any') {
1.2       www      1337:                $output.=&secondlevel(
1.209     www      1338: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1339: 	} elsif ($pro eq 'smp') {
                   1340:             unless ($adv) {
                   1341:                $output.=&secondlevel(
1.209     www      1342:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1343:             }
                   1344:         } elsif ($pro eq 'adv') {
                   1345:             if ($adv) {
                   1346:                $output.=&secondlevel(
1.209     www      1347: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1348:             }
1.231     albertel 1349: 	} elsif ($pro eq 'shc') {
                   1350:             if ($show_course) {
                   1351:                $output.=&secondlevel(
                   1352:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
                   1353:             }
                   1354:         } elsif ($pro eq 'nsc') {
                   1355:             if (!$show_course) {
                   1356:                $output.=&secondlevel(
                   1357: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
                   1358:             }
1.81      matthew  1359:         } elsif (($pro=~/^p(\w+)/) && ($prt)) {
1.295     raeburn  1360:             my $priv = $1;
                   1361:             if ($priv =~ /^mdc(Course|Community)/) {
                   1362:                 if ($crstype eq $1) {
                   1363:                     $priv = 'mdc';
                   1364:                 } else {
                   1365:                     next;
                   1366:                 }
                   1367:             }
1.427     raeburn  1368:             if ((($priv eq 'bre') && (&Apache::lonnet::allowed($priv,$prt) eq 'F')) ||
                   1369:                 (($priv ne 'bre') && (&Apache::lonnet::allowed($priv,$prt)))) {
                   1370:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.4       www      1371:             }
1.295     raeburn  1372:         } elsif ($pro eq 'course')  {
                   1373:             if (($env{'request.course.fn'}) && ($crstype ne 'Community')) {
1.209     www      1374:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.81      matthew  1375: 	    }
1.295     raeburn  1376:         } elsif ($pro eq 'community')  {
                   1377:             if (($env{'request.course.fn'}) && ($crstype eq 'Community')) {
                   1378:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
                   1379:             }
1.124     matthew  1380:         } elsif ($pro =~ /^courseenv_(.*)$/) {
                   1381:             my $key = $1;
1.307     raeburn  1382:             if ($crstype ne 'Community') {
                   1383:                 my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
                   1384:                 if ($key eq 'canuse_pdfforms') {
                   1385:                     if ($env{'request.course.id'} && $coursepref eq '') {
                   1386:                         my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
                   1387:                         $coursepref = $domdefs{'canuse_pdfforms'};
                   1388:                     }
                   1389:                 }
                   1390:                 if ($coursepref) { 
                   1391:                     $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
                   1392:                 }
1.295     raeburn  1393:             }
                   1394:         } elsif ($pro =~ /^communityenv_(.*)$/) {
                   1395:             my $key = $1;
1.307     raeburn  1396:             if ($crstype eq 'Community') {
                   1397:                 my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
                   1398:                 if ($key eq 'canuse_pdfforms') {
                   1399:                     if ($env{'request.course.id'} && $coursepref eq '') {
                   1400:                         my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
                   1401:                         $coursepref = $domdefs{'canuse_pdfforms'};
                   1402:                     }
                   1403:                 }
                   1404:                 if ($coursepref) { 
                   1405:                     $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
                   1406:                 }
1.124     matthew  1407:             }
1.81      matthew  1408:         } elsif ($pro =~ /^course_(.*)$/) {
                   1409:             # Check for permissions inside of a course
1.295     raeburn  1410:             if (($env{'request.course.id'}) && ($crstype ne 'Community') && 
1.152     albertel 1411:                 (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
                   1412:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
1.81      matthew  1413:                  )) {
1.209     www      1414:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.26      www      1415: 	    }
1.295     raeburn  1416:         } elsif ($pro =~ /^community_(.*)$/) {
                   1417:             # Check for permissions inside of a community
                   1418:             if (($env{'request.course.id'}) && ($crstype eq 'Community') &&   
                   1419:                 (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
                   1420:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
                   1421:                  )) {
                   1422:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
                   1423:             }
1.4       www      1424:         } elsif ($pro eq 'author') {
                   1425:             if ($author) {
1.152     albertel 1426:                 if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
1.234     raeburn  1427:                     (($prt eq 'raa') && ($env{'request.role'}=~/^aa/)) || 
1.152     albertel 1428:                     (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
1.19      matthew  1429:                     # Check that we are on the correct machine
1.29      matthew  1430:                     my $cadom=$requested_domain;
1.152     albertel 1431:                     my $caname=$env{'user.name'};
1.234     raeburn  1432:                     if (($prt eq 'rca') || ($prt eq 'raa')) {
1.29      matthew  1433: 		       ($cadom,$caname)=
1.206     albertel 1434:                                ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.29      matthew  1435:                     }                       
                   1436:                     $act =~ s/\$caname/$caname/g;
1.353     www      1437:                     $act =~ s/\$cadom/$cadom/g;
1.19      matthew  1438:                     my $home = &Apache::lonnet::homeserver($caname,$cadom);
1.109     albertel 1439: 		    my $allowed=0;
                   1440: 		    my @ids=&Apache::lonnet::current_machine_ids();
                   1441: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                   1442: 		    if ($allowed) {
1.209     www      1443:                         $output.=&switch($caname,$cadom,
                   1444:                                         $row,$col,$img,$top,$bot,$act,$desc,$cat);
1.19      matthew  1445:                     }
1.6       www      1446:                 }
1.2       www      1447:             }
1.248     raeburn  1448:         } elsif ($pro eq 'tools') {
                   1449:             my @tools = ('aboutme','blog','portfolio');
                   1450:             if (grep(/^\Q$prt\E$/,@tools)) {
1.249     raeburn  1451:                 if (!&Apache::lonnet::usertools_access($env{'user.name'},
1.251     raeburn  1452:                                                        $env{'user.domain'},
                   1453:                                                        $prt,undef,'tools')) {
                   1454:                     $output.=&clear($row,$col);
                   1455:                     next;
                   1456:                 }
1.278     raeburn  1457:             } elsif (($prt eq 'reqcrsnsc') || ($prt eq 'reqcrsshc')) {
                   1458:                 if (($prt eq 'reqcrsnsc') && ($show_course))   {
                   1459:                     next;
                   1460:                 }
                   1461:                 if (($prt eq 'reqcrsshc') && (!$show_course)) {
                   1462:                     next;
                   1463:                 }
1.279     raeburn  1464:                 my $showreqcrs = &check_for_rcrs();
1.251     raeburn  1465:                 if (!$showreqcrs) {
1.248     raeburn  1466:                     $output.=&clear($row,$col);
                   1467:                     next;
                   1468:                 }
                   1469:             }
                   1470:             $prt='any';
                   1471:             $output.=&secondlevel(
                   1472:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1473:         }
1.13      harris41 1474:     }
1.2       www      1475:     return $output;
                   1476: }
                   1477: 
1.279     raeburn  1478: sub check_for_rcrs {
                   1479:     my $showreqcrs = 0;
1.424     raeburn  1480:     my @reqtypes = ('official','unofficial','community','textbook');
1.280     raeburn  1481:     foreach my $type (@reqtypes) {
1.279     raeburn  1482:         if (&Apache::lonnet::usertools_access($env{'user.name'},
                   1483:                                               $env{'user.domain'},
                   1484:                                               $type,undef,'requestcourses')) {
                   1485:             $showreqcrs = 1;
                   1486:             last;
                   1487:         }
                   1488:     }
1.280     raeburn  1489:     if (!$showreqcrs) {
                   1490:         foreach my $type (@reqtypes) {
                   1491:             if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
                   1492:                 $showreqcrs = 1;
                   1493:                 last;
                   1494:             }
                   1495:         }
                   1496:     }
1.279     raeburn  1497:     return $showreqcrs;
                   1498: }
                   1499: 
1.306     raeburn  1500: sub dc_popup_js {
                   1501:     my %lt = &Apache::lonlocal::texthash(
                   1502:                                           more => '(More ...)',
                   1503:                                           less => '(Less ...)',
                   1504:                                         );
                   1505:     return <<"END";
                   1506: 
                   1507: function showCourseID() {
                   1508:     document.getElementById('dccid').style.display='block';
                   1509:     document.getElementById('dccid').style.textAlign='left';
1.307     raeburn  1510:     document.getElementById('dccid').style.textFace='normal';
1.369     raeburn  1511:     document.getElementById('dccidtext').innerHTML ='<a href="javascript:hideCourseID();" class="LC_menubuttons_link">$lt{'less'}</a>';
1.306     raeburn  1512:     return;
                   1513: }
                   1514: 
                   1515: function hideCourseID() {
                   1516:     document.getElementById('dccid').style.display='none';
1.369     raeburn  1517:     document.getElementById('dccidtext').innerHTML ='<a href="javascript:showCourseID()" class="LC_menubuttons_link">$lt{'more'}</a>';
1.306     raeburn  1518:     return;
                   1519: }
                   1520: 
                   1521: END
                   1522: 
                   1523: }
                   1524: 
1.378     raeburn  1525: sub countdown_toggle_js {
                   1526:     return <<"END";
                   1527: 
                   1528: function toggleCountdown() {
                   1529:     var countdownid = document.getElementById('duedatecountdown');
                   1530:     var currstyle = countdownid.style.display;
                   1531:     if (currstyle == 'inline') {
                   1532:         countdownid.style.display = 'none';
                   1533:         document.getElementById('ddcountcollapse').innerHTML='';
                   1534:         document.getElementById('ddcountexpand').innerHTML='&#9668;&nbsp;';
                   1535:     } else {
                   1536:         countdownid.style.display = 'inline';
                   1537:         document.getElementById('ddcountcollapse').innerHTML='&#9658;&nbsp;';
                   1538:         document.getElementById('ddcountexpand').innerHTML='';
                   1539:     }
                   1540:     return;
                   1541: }
                   1542: 
                   1543: END
                   1544: }
                   1545: 
1.435   ! musolffc 1546: # This creates a "done button" for timed events.  The confirmation box is a jQuery
        !          1547: # dialog widget.  Clicking OK will set (LC_interval_done = 'true') which is checked in 
        !          1548: # lonhomework.pm.
        !          1549: sub done_button_js {
        !          1550:     my ($type,$height) = @_;
        !          1551:     if ($height !~ /^\d+$/) {
        !          1552:         $height = 320;
        !          1553:     }
        !          1554:     my %lt = &Apache::lonlocal::texthash(
        !          1555:                  title    => 'WARNING!',
        !          1556:                  button   => 'Done',
        !          1557:                  preamble => 'You are trying to end this timed event early.',
        !          1558:                  map      => 'Confirming that you are done will cause the time to expire and prevent you from changing any answers in the current folder.',
        !          1559:                  resource => 'Confirming that you are done will cause the time to expire for this question, and prevent you from changing your answer(s).', 
        !          1560:                  ok       => 'Click "OK" if you are completely finished.',
        !          1561:                  cancel   => 'Click "Cancel" to continue working.',
        !          1562:     );
        !          1563:     my $confirm;
        !          1564:     if (($type eq 'map') || ($type eq 'resource')) {
        !          1565:         $confirm = $lt{'preamble'}.' '.$lt{$type}.' '.$lt{'ok'}.' '.$lt{'cancel'};
        !          1566:     }
        !          1567:     if ($confirm) {
        !          1568:         return <<END;
        !          1569: 
        !          1570: <form method="post" name="LCdoneButton" action="">
        !          1571:     <input type="hidden" name="LC_interval_done" value="" />
        !          1572:     <button id="LC_done-confirm-opener" type="button">$lt{'button'}</button>
        !          1573: </form>
        !          1574: 
        !          1575: <div id="LC_done-confirm" title="$lt{'title'}">
        !          1576:     <p>$confirm</p>
        !          1577: </div>
        !          1578: 
        !          1579: <script type="text/javascript">
        !          1580: // <![CDATA[
        !          1581: \$( "#LC_done-confirm" ).dialog({ autoOpen: false });
        !          1582: \$( "#LC_done-confirm-opener" ).click(function() {
        !          1583:     \$( "#LC_done-confirm" ).dialog( "open" );
        !          1584:     \$( "#LC_done-confirm" ).dialog({
        !          1585:       resizable: false,
        !          1586:       height: $height,
        !          1587:       modal: true,
        !          1588:       buttons: {
        !          1589:         "OK": function() {
        !          1590:             \$( this ).dialog( "close" );
        !          1591:             \$( '[name="LC_interval_done"]' )[0].value = 'true';
        !          1592:             \$( '[name="LCdoneButton"]' )[0].submit();
        !          1593:         },
        !          1594:         Cancel: function() {
        !          1595:           \$( this ).dialog( "close" );
        !          1596:         }
        !          1597:       }    
        !          1598:     })
        !          1599: });
        !          1600: // ]]>
        !          1601: </script>
        !          1602: 
        !          1603: END
        !          1604:     } else {
        !          1605:         return;
        !          1606:     }
        !          1607: }
        !          1608: 
1.42      www      1609: sub utilityfunctions {
1.421     raeburn  1610:     my ($httphost) = @_;
1.152     albertel 1611:     my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
1.316     droeschl 1612:     if ($currenturl =~ m{^/adm/wrapper/ext/}
                   1613:         && $env{'request.external.querystring'} ) {
1.293     raeburn  1614:             $currenturl .= ($currenturl=~/\?/)?'&':'?'.$env{'request.external.querystring'};
                   1615:     }
1.183     www      1616:     $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
1.125     albertel 1617:     
1.152     albertel 1618:     my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
1.175     albertel 1619: 
1.306     raeburn  1620:     my $dc_popup_cid;
                   1621:     if ($env{'user.adv'} && exists($env{'user.role.dc./'.
                   1622:                         $env{'course.'.$env{'request.course.id'}.
                   1623:                                  '.domain'}.'/'})) {
                   1624:         $dc_popup_cid = &dc_popup_js();
                   1625:     }
                   1626: 
1.175     albertel 1627:     my $start_page_annotate = 
                   1628:         &Apache::loncommon::start_page('Annotator',undef,
                   1629: 				       {'only_body' => 1,
                   1630: 					'js_ready'  => 1,
                   1631: 					'bgcolor'   => '#BBBBBB',
                   1632: 					'add_entries' => {
                   1633: 					    'onload' => 'javascript:document.goannotate.submit();'}});
                   1634: 
1.205     albertel 1635:     my $end_page_annotate = 
                   1636:         &Apache::loncommon::end_page({'js_ready' => 1});
                   1637: 
1.389     raeburn  1638:     my $jumptores = &Apache::lonhtmlcommon::javascript_jumpto_resource();
1.336     raeburn  1639: 
1.368     www      1640:     my $esc_url=&escape($currenturl);
                   1641:     my $esc_symb=&escape($currentsymb);
1.332     wenzelju 1642: 
1.378     raeburn  1643:     my $countdown = &countdown_toggle_js();
                   1644: 
1.429     raeburn  1645:     my $hostvar = '
                   1646: function setLCHost() {
                   1647:     var lcHostname="";
                   1648: ';
                   1649:     if ($httphost =~ m{^https?\://}) {
                   1650:         $hostvar .= '    var lcServer="'.$httphost.'";'."\n".
                   1651:                     '    var hostReg = /^https?:\/\/([^\/]+)$/i;'."\n".
                   1652:                     '    var match = hostReg.exec(lcServer);'."\n".
                   1653:                     '    if (match.length) {'."\n".
                   1654:                     '        if (match[1] == location.hostname) {'."\n".
                   1655:                     '            lcHostname=lcServer;'."\n".
                   1656:                     '        }'."\n".
                   1657:                     '    }'."\n";
                   1658:     }
                   1659:     
                   1660:     $hostvar .= '    return lcHostname;'."\n".
                   1661: '}'."\n";
                   1662: 
1.42      www      1663: return (<<ENDUTILITY)
1.429     raeburn  1664:     $hostvar
1.368     www      1665:     var currentURL=unescape("$esc_url");
                   1666:     var reloadURL=unescape("$esc_url");
                   1667:     var currentSymb=unescape("$esc_symb");
1.42      www      1668: 
1.306     raeburn  1669: $dc_popup_cid
1.114     albertel 1670: 
1.389     raeburn  1671: $jumptores
1.336     raeburn  1672: 
1.42      www      1673: function gopost(url,postdata) {
                   1674:    if (url!='') {
1.429     raeburn  1675:       var lcHostname = setLCHost();
                   1676:       this.document.server.action=lcHostname+url;
1.42      www      1677:       this.document.server.postdata.value=postdata;
                   1678:       this.document.server.command.value='';
                   1679:       this.document.server.url.value='';
                   1680:       this.document.server.symb.value='';
                   1681:       this.document.server.submit();
                   1682:    }
                   1683: }
                   1684: 
                   1685: function gocmd(url,cmd) {
                   1686:    if (url!='') {
1.429     raeburn  1687:       var lcHostname = setLCHost();
                   1688:       this.document.server.action=lcHostname+url;
1.42      www      1689:       this.document.server.postdata.value='';
                   1690:       this.document.server.command.value=cmd;
                   1691:       this.document.server.url.value=currentURL;
                   1692:       this.document.server.symb.value=currentSymb;
                   1693:       this.document.server.submit();
                   1694:    }
1.57      www      1695: }
                   1696: 
1.121     raeburn  1697: function gocstr(url,filename) {
                   1698:     if (url == '/adm/cfile?action=delete') {
                   1699:         this.document.cstrdelete.filename.value = filename
                   1700:         this.document.cstrdelete.submit();
                   1701:         return;
                   1702:     }
1.137     raeburn  1703:     if (url == '/adm/printout') {
                   1704:         this.document.cstrprint.postdata.value = filename
                   1705:         this.document.cstrprint.curseed.value = 0;
                   1706:         this.document.cstrprint.problemtype.value = 0;
1.138     raeburn  1707:         if (this.document.lonhomework) {
                   1708:             if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
                   1709:                 this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
                   1710:             }
                   1711:             if (this.document.lonhomework.problemtype) {
1.164     albertel 1712: 		if (this.document.lonhomework.problemtype.value) {
                   1713: 		    this.document.cstrprint.problemtype.value = 
                   1714: 			this.document.lonhomework.problemtype.value;
                   1715: 		} else if (this.document.lonhomework.problemtype.options) {
                   1716: 		    for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
                   1717: 			if (this.document.lonhomework.problemtype.options[i].selected) {
                   1718: 			    if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') { 
                   1719: 				this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
                   1720: 				}
                   1721: 			}
                   1722: 		    }
                   1723: 		}
                   1724: 	    }
                   1725: 	}
1.137     raeburn  1726:         this.document.cstrprint.submit();
                   1727:         return;
                   1728:     }
1.121     raeburn  1729:     if (url !='') {
                   1730:         this.document.constspace.filename.value = filename;
                   1731:         this.document.constspace.action = url;
                   1732:         this.document.constspace.submit();
                   1733:     }
                   1734: }
                   1735: 
1.131     raeburn  1736: function golist(url) {
                   1737:    if (url!='' && url!= null) {
                   1738:        currentURL = null;
                   1739:        currentSymb= null;
1.429     raeburn  1740:        var lcHostname = setLCHost();
                   1741:        top.location.href=lcHostname+url;
1.131     raeburn  1742:    }
                   1743: }
                   1744: 
                   1745: 
1.121     raeburn  1746: 
1.428     raeburn  1747: function catalog_info(isMobile) {
                   1748:     if (isMobile == 1) {
                   1749:         openMyModal(window.location.pathname+'.meta?modal=1',500,400,'yes');
                   1750:     } else {
                   1751:         loncatinfo=window.open(window.location.pathname+'.meta',"LONcatInfo",'height=500,width=400,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
                   1752:     }
1.57      www      1753: }
                   1754: 
                   1755: function chat_win() {
1.429     raeburn  1756:    var lcHostname = setLCHost();
                   1757:    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      1758: }
1.169     raeburn  1759: 
                   1760: function group_chat(group) {
1.429     raeburn  1761:    var lcHostname = setLCHost();
                   1762:    var url = lcHostname+'/adm/groupchat?group='+group;
1.169     raeburn  1763:    var winName = 'LONchat_'+group;
                   1764:    grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
                   1765: }
1.175     albertel 1766: 
                   1767: function annotate() {
                   1768:    w_Annotator_flag=1;
                   1769:    annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
                   1770:    annotator.document.write(
                   1771:    '$start_page_annotate'
                   1772:   +"<form name='goannotate' target='Annotator' method='post' "
                   1773:   +"action='/adm/annotations'>"
1.217     albertel 1774:   +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />"
1.181     albertel 1775:   +"<\\/form>"
1.205     albertel 1776:   +'$end_page_annotate');
1.175     albertel 1777:    annotator.document.close();
                   1778: }
                   1779: 
1.370     raeburn  1780: function open_StoredLinks_Import(rat) {
1.335     wenzelju 1781:    var newWin;
1.429     raeburn  1782:    var lcHostname = setLCHost();
1.335     wenzelju 1783:    if (rat) {
1.429     raeburn  1784:        newWin = window.open(lcHostname+'/adm/wishlist?inhibitmenu=yes&mode=import&rat='+rat,
1.334     wenzelju 1785:                             'wishlistImport','scrollbars=1,resizable=1,menubar=0');
1.335     wenzelju 1786:    }
                   1787:    else {
1.429     raeburn  1788:        newWin = window.open(lcHostname+'/adm/wishlist?inhibitmenu=yes&mode=import',
1.335     wenzelju 1789:                             'wishlistImport','scrollbars=1,resizable=1,menubar=0');
                   1790:    }
1.334     wenzelju 1791:    newWin.focus();
                   1792: }
                   1793: 
1.372     raeburn  1794: (function (\$) {
                   1795:   \$(document).ready(function () {
                   1796:     \$.single=function(a){return function(b){a[0]=b;return a}}(\$([1]));
                   1797:     /*\@cc_on
                   1798:       if (!window.XMLHttpRequest) {
                   1799:         \$('.LC_hoverable').each(function () {
                   1800:           this.attachEvent('onmouseenter', function (evt) { \$.single(evt.srcElement).addClass('hover'); });
                   1801:           this.attachEvent('onmouseleave', function (evt) { \$.single(evt.srcElement).removeClass('hover'); });
                   1802:         });
                   1803:       }
                   1804:     \@*/
                   1805:   });
                   1806: }(jQuery));
                   1807: 
1.378     raeburn  1808: $countdown
                   1809: 
1.42      www      1810: ENDUTILITY
                   1811: }
                   1812: 
                   1813: sub serverform {
                   1814:     return(<<ENDSERVERFORM);
1.181     albertel 1815: <form name="server" action="/adm/logout" method="post" target="_top">
1.42      www      1816: <input type="hidden" name="postdata" value="none" />
                   1817: <input type="hidden" name="command" value="none" />
                   1818: <input type="hidden" name="url" value="none" />
                   1819: <input type="hidden" name="symb" value="none" />
                   1820: </form>
                   1821: ENDSERVERFORM
                   1822: }
1.113     albertel 1823: 
1.121     raeburn  1824: sub constspaceform {
                   1825:     return(<<ENDCONSTSPACEFORM);
1.181     albertel 1826: <form name="constspace" action="/adm/logout" method="post" target="_top">
1.121     raeburn  1827: <input type="hidden" name="filename" value="" />
                   1828: </form>
1.181     albertel 1829: <form name="cstrdelete" action="/adm/cfile" method="post" target="_top">
1.121     raeburn  1830: <input type="hidden" name="action" value="delete" /> 
                   1831: <input type="hidden" name="filename" value="" />
                   1832: </form>
1.181     albertel 1833: <form name="cstrprint" action="/adm/printout" target="_parent" method="post">
1.137     raeburn  1834: <input type="hidden" name="postdata" value="" />
                   1835: <input type="hidden" name="curseed" value="" />
                   1836: <input type="hidden" name="problemtype" value="" />
                   1837: </form>
                   1838: 
1.121     raeburn  1839: ENDCONSTSPACEFORM
                   1840: }
                   1841: 
1.220     raeburn  1842: sub hidden_button_check {
1.317     droeschl 1843:     if ( $env{'request.course.id'} eq ''
                   1844:          || $env{'request.role.adv'} ) {
                   1845: 
1.220     raeburn  1846:         return;
                   1847:     }
1.232     raeburn  1848:     my $buttonshide = &Apache::lonnet::EXT('resource.0.buttonshide');
                   1849:     return $buttonshide; 
1.220     raeburn  1850: }
1.184     raeburn  1851: 
1.235     raeburn  1852: sub roles_selector {
1.421     raeburn  1853:     my ($cdom,$cnum,$httphost) = @_;
1.298     raeburn  1854:     my $crstype = &Apache::loncommon::course_type();
1.235     raeburn  1855:     my $now = time;
1.350     raeburn  1856:     my (%courseroles,%seccount,%courseprivs);
1.235     raeburn  1857:     my $is_cc;
1.432     droeschl 1858:     my ($js,$form,$switcher);
1.298     raeburn  1859:     my $ccrole;
                   1860:     if ($crstype eq 'Community') {
                   1861:         $ccrole = 'co';
                   1862:     } else {
                   1863:         $ccrole = 'cc';
1.350     raeburn  1864:     }
1.386     raeburn  1865:     my ($priv,$gotsymb,$destsymb);
1.350     raeburn  1866:     my $destinationurl = $ENV{'REQUEST_URI'};
1.386     raeburn  1867:     if ($destinationurl =~ /\?symb=/) {
                   1868:         $gotsymb = 1;
                   1869:     } elsif ($destinationurl =~ m{^/enc/}) {
                   1870:         my $plainurl = &Apache::lonenc::unencrypted($destinationurl);
                   1871:         if ($plainurl =~ /\?symb=/) {
                   1872:             $gotsymb = 1;
                   1873:         }
                   1874:     }
                   1875:     unless ($gotsymb) {
                   1876:         $destsymb = &Apache::lonnet::symbread();
                   1877:         if ($destsymb ne '') {
                   1878:             $destsymb = &Apache::lonenc::check_encrypt($destsymb);
                   1879:         }
                   1880:     }
1.350     raeburn  1881:     my $reqprivs = &required_privs();
                   1882:     if (ref($reqprivs) eq 'HASH') {
                   1883:         my $destination = $destinationurl;
                   1884:         $destination =~ s/(\?.*)$//;
                   1885:         if (exists($reqprivs->{$destination})) {
                   1886:             $priv = $reqprivs->{$destination};
                   1887:         }
                   1888:     }
1.298     raeburn  1889:     if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
                   1890:         my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
1.235     raeburn  1891:         
                   1892:         if ((($start) && ($start<0)) || 
                   1893:             (($end) && ($end<$now))  ||
                   1894:             (($start) && ($now<$start))) {
                   1895:             $is_cc = 0;
                   1896:         } else {
                   1897:             $is_cc = 1;
                   1898:         }
                   1899:     }
                   1900:     if ($is_cc) {
1.350     raeburn  1901:         &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs,$priv);
1.235     raeburn  1902:     } else {
1.262     raeburn  1903:         my %gotnosection;
1.235     raeburn  1904:         foreach my $item (keys(%env)) {
1.239     raeburn  1905:             if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
1.235     raeburn  1906:                 my $role = $1;
                   1907:                 my $sec = $2;
                   1908:                 next if ($role eq 'gr');
                   1909:                 my ($start,$end) = split(/\./,$env{$item});
                   1910:                 next if (($start && $start > $now) || ($end && $end < $now));
                   1911:                 if ($sec eq '') {
1.239     raeburn  1912:                     if (!$gotnosection{$role}) {
                   1913:                         $seccount{$role} ++;
                   1914:                         $gotnosection{$role} = 1;
                   1915:                     }
1.235     raeburn  1916:                 }
1.350     raeburn  1917:                 if ($priv ne '') {
                   1918:                     my $cnumsec = $cnum;
                   1919:                     if ($sec ne '') {
                   1920:                         $cnumsec .= "/$sec";
                   1921:                     }
                   1922:                     $courseprivs{"$role./$cdom/$cnumsec./"} =
                   1923:                         $env{"user.priv.$role./$cdom/$cnumsec./"};
                   1924:                     $courseprivs{"$role./$cdom/$cnumsec./$cdom/"} =
                   1925:                         $env{"user.priv.$role./$cdom/$cnumsec./$cdom/"};
                   1926:                     $courseprivs{"$role./$cdom/$cnumsec./$cdom/$cnumsec"} =
                   1927:                         $env{"user.priv.$role./$cdom/$cnumsec./$cdom/$cnumsec"};
                   1928:                 }
1.235     raeburn  1929:                 if (ref($courseroles{$role}) eq 'ARRAY') {
1.239     raeburn  1930:                     if ($sec ne '') {
1.264     raeburn  1931:                         if (!grep(/^\Q$sec\E$/,@{$courseroles{$role}})) {
1.239     raeburn  1932:                             push(@{$courseroles{$role}},$sec);
                   1933:                             $seccount{$role} ++;
                   1934:                         }
                   1935:                     }
                   1936:                 } else {
                   1937:                     @{$courseroles{$role}} = ();
                   1938:                     if ($sec ne '') {
                   1939:                         $seccount{$role} ++;
1.235     raeburn  1940:                         push(@{$courseroles{$role}},$sec);
                   1941:                     }
                   1942:                 }
                   1943:             }
                   1944:         }
                   1945:     }
1.298     raeburn  1946:     my @roles_order = ($ccrole,'in','ta','ep','ad','st');
1.402     raeburn  1947:     my $numdiffsec;
                   1948:     if (keys(%seccount) == 1) {
                   1949:         foreach my $key (keys(%seccount)) {
                   1950:             $numdiffsec = $seccount{$key};
                   1951:         }
                   1952:     }
                   1953:     if ((keys(%seccount) > 1) || ($numdiffsec > 1)) {
1.401     raeburn  1954:         my @submenu;
                   1955:         $js = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles,\%courseprivs,$priv);
                   1956:         $form = 
1.421     raeburn  1957:             '<form name="rolechooser" method="post" action="'.$httphost.'/adm/roles">'."\n".
1.401     raeburn  1958:             '  <input type="hidden" name="destinationurl" value="'.
                   1959:             &HTML::Entities::encode($destinationurl).'" />'."\n".
                   1960:             '  <input type="hidden" name="gotorole" value="1" />'."\n".
                   1961:             '  <input type="hidden" name="selectrole" value="" />'."\n".
1.402     raeburn  1962:             '  <input type="hidden" name="switchrole" value="" />'."\n";
                   1963:         if ($destsymb ne '') {
                   1964:             $form .= '  <input type="hidden" name="destsymb" value="'.
                   1965:                         &HTML::Entities::encode($destsymb).'" />'."\n";
                   1966:         }
                   1967:         $form .= '</form>'."\n";
1.235     raeburn  1968:         foreach my $role (@roles_order) {
1.402     raeburn  1969:             my $include;
1.235     raeburn  1970:             if (defined($courseroles{$role})) {
1.402     raeburn  1971:                 if ($env{'request.role'} =~ m{^\Q$role\E}) {
                   1972:                     if ($seccount{$role} > 1) {
                   1973:                         $include = 1;
                   1974:                     }
                   1975:                 } else {
                   1976:                     $include = 1;
                   1977:                 }
                   1978:             }
                   1979:             if ($include) {
1.401     raeburn  1980:                 push(@submenu,['javascript:adhocRole('."'$role'".')',
                   1981:                                &Apache::lonnet::plaintext($role,$crstype)]);
1.235     raeburn  1982:             }
                   1983:         }
                   1984:         foreach my $role (sort(keys(%courseroles))) {
                   1985:             if ($role =~ /^cr/) {
1.403     raeburn  1986:                 my $include;
                   1987:                 if ($env{'request.role'} =~ m{^\Q$role\E}) {
1.402     raeburn  1988:                     if ($seccount{$role} > 1) {
                   1989:                         $include = 1;
                   1990:                     }
1.403     raeburn  1991:                 } else {
                   1992:                     $include = 1; 
                   1993:                 }
                   1994:                 if ($include) {
                   1995:                     push(@submenu,['javascript:adhocRole('."'$role'".')',
                   1996:                                    &Apache::lonnet::plaintext($role)]);
                   1997:                 }
1.235     raeburn  1998:             }
                   1999:         }
1.401     raeburn  2000:         if (@submenu > 0) {
1.432     droeschl 2001:             $switcher = &create_submenu('','',&mt('Switch role'),\@submenu);
1.386     raeburn  2002:         }
1.235     raeburn  2003:     }
1.401     raeburn  2004:     return ($js,$form,$switcher);
1.235     raeburn  2005: }
                   2006: 
1.262     raeburn  2007: sub get_all_courseroles {
1.350     raeburn  2008:     my ($cdom,$cnum,$courseroles,$seccount,$courseprivs) = @_;
1.351     raeburn  2009:     unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH') &&
1.350     raeburn  2010:             (ref($courseprivs) eq 'HASH')) {
1.262     raeburn  2011:         return;
                   2012:     }
                   2013:     my ($result,$cached) = 
                   2014:         &Apache::lonnet::is_cached_new('getcourseroles',$cdom.'_'.$cnum);
                   2015:     if (defined($cached)) {
                   2016:         if (ref($result) eq 'HASH') {
                   2017:             if ((ref($result->{'roles'}) eq 'HASH') && 
1.350     raeburn  2018:                 (ref($result->{'seccount'}) eq 'HASH') && 
                   2019:                 (ref($result->{'privs'}) eq 'HASH')) {
1.262     raeburn  2020:                 %{$courseroles} = %{$result->{'roles'}};
                   2021:                 %{$seccount} = %{$result->{'seccount'}};
1.350     raeburn  2022:                 %{$courseprivs} = %{$result->{'privs'}};
1.262     raeburn  2023:                 return;
                   2024:             }
                   2025:         }
                   2026:     }
                   2027:     my %gotnosection;
                   2028:     my %adv_roles =
                   2029:          &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
                   2030:     foreach my $role (keys(%adv_roles)) {
                   2031:         my ($urole,$usec) = split(/:/,$role);
                   2032:         if (!$gotnosection{$urole}) {
                   2033:             $seccount->{$urole} ++;
                   2034:             $gotnosection{$urole} = 1;
                   2035:         }
                   2036:         if (ref($courseroles->{$urole}) eq 'ARRAY') {
                   2037:             if ($usec ne '') {
                   2038:                 if (!grep(/^Q$usec\E$/,@{$courseroles->{$urole}})) {
                   2039:                     push(@{$courseroles->{$urole}},$usec);
                   2040:                     $seccount->{$urole} ++;
                   2041:                 }
                   2042:             }
                   2043:         } else {
                   2044:             @{$courseroles->{$urole}} = ();
                   2045:             if ($usec ne '') {
                   2046:                 $seccount->{$urole} ++;
                   2047:                 push(@{$courseroles->{$urole}},$usec);
                   2048:             }
                   2049:         }
1.350     raeburn  2050:         my $area = '/'.$cdom.'/'.$cnum;
                   2051:         if ($usec ne '') {
                   2052:             $area .= '/'.$usec;
                   2053:         }
                   2054:         if ($role =~ /^cr\//) {
                   2055:             &Apache::lonnet::custom_roleprivs($courseprivs,$urole,$cdom,$cnum,$urole.'.'.$area,$area);
                   2056:         } else {
                   2057:             &Apache::lonnet::standard_roleprivs($courseprivs,$urole,$cdom,$urole.'.'.$area,$cnum,$area);
                   2058:         }
1.262     raeburn  2059:     }
                   2060:     my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum,['st']);
                   2061:     @{$courseroles->{'st'}} = ();
1.350     raeburn  2062:     &Apache::lonnet::standard_roleprivs($courseprivs,'st',$cdom,"st./$cdom/$cnum",$cnum,"/$cdom/$cnum");
1.262     raeburn  2063:     if (keys(%sections_count) > 0) {
                   2064:         push(@{$courseroles->{'st'}},keys(%sections_count));
1.350     raeburn  2065:         $seccount->{'st'} = scalar(keys(%sections_count));
1.262     raeburn  2066:     }
1.410     raeburn  2067:     $seccount->{'st'} ++; # Increment for a section-less student role.  
1.262     raeburn  2068:     my $rolehash = {
                   2069:                      'roles'    => $courseroles,
                   2070:                      'seccount' => $seccount,
1.350     raeburn  2071:                      'privs'    => $courseprivs,
1.262     raeburn  2072:                    };
                   2073:     &Apache::lonnet::do_cache_new('getcourseroles',$cdom.'_'.$cnum,$rolehash);
                   2074:     return;
                   2075: }
                   2076: 
1.235     raeburn  2077: sub jump_to_role {
1.350     raeburn  2078:     my ($cdom,$cnum,$seccount,$courseroles,$courseprivs,$priv) = @_;
1.239     raeburn  2079:     my %lt = &Apache::lonlocal::texthash(
                   2080:                 this => 'This role has section(s) associated with it.',
                   2081:                 ente => 'Enter a specific section.',
                   2082:                 orlb => 'Enter a specific section, or leave blank for no section.',
                   2083:                 avai => 'Available sections are:',
                   2084:                 youe => 'You entered an invalid section choice:',
1.352     raeburn  2085:                 plst => 'Please try again.',
1.350     raeburn  2086:                 role => 'The role you selected is not permitted to view the current page.',
                   2087:                 swit => 'Switch role, but display Main Menu page instead?',
1.239     raeburn  2088:     );
                   2089:     my $js;
                   2090:     if (ref($courseroles) eq 'HASH') {
                   2091:         $js = '    var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n". 
                   2092:               '    var numsec = new Array();'."\n".
                   2093:               '    var rolesections = new Array();'."\n".
                   2094:               '    var rolenames = new Array();'."\n".
                   2095:               '    var roleseclist = new Array();'."\n";
                   2096:         my @items = keys(%{$courseroles});
                   2097:         for (my $i=0; $i<@items; $i++) {
                   2098:             $js .= '    rolenames['.$i.'] = "'.$items[$i].'";'."\n";
                   2099:             my ($secs,$secstr);
                   2100:             if (ref($courseroles->{$items[$i]}) eq 'ARRAY') {
                   2101:                 my @sections = sort { $a <=> $b } @{$courseroles->{$items[$i]}};
                   2102:                 $secs = join('","',@sections);
                   2103:                 $secstr = join(', ',@sections);
                   2104:             }
                   2105:             $js .= '    rolesections['.$i.'] = new Array("'.$secs.'");'."\n".
                   2106:                    '    roleseclist['.$i.'] = "'.$secstr.'";'."\n".
                   2107:                    '    numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n";
                   2108:         }
                   2109:     }
1.350     raeburn  2110:     my $checkroles = 0;
                   2111:     if ($priv && ref($courseprivs) eq 'HASH') {
                   2112:         my (%disallowed,%allowed,@disallow);
                   2113:         foreach my $role (sort(keys(%{$courseprivs}))) {
                   2114:             my $trole;
                   2115:             if ($role =~ m{^(.+?)\Q./$cdom/$cnum\E}) {
                   2116:                 $trole = $1;
                   2117:             }
                   2118:             if (($trole ne '') && ($trole ne 'cm')) {
                   2119:                 if ($courseprivs->{$role} =~ /\Q:$priv\E($|:|\&\w+)/) {
                   2120:                     $allowed{$trole} = 1;
                   2121:                 } else {
                   2122:                     $disallowed{$trole} = 1;
                   2123:                 }
                   2124:             }
                   2125:         }
                   2126:         foreach my $trole (keys(%disallowed)) {
                   2127:             unless ($allowed{$trole}) {
                   2128:                 push(@disallow,$trole);
                   2129:             }
                   2130:         }
                   2131:         if (@disallow > 0) {
                   2132:             $checkroles = 1;
                   2133:             $js .= "    var disallow = new Array('".join("','",@disallow)."');\n".
                   2134:                    "    var rolecheck = 1;\n";
                   2135:         }
                   2136:     }
                   2137:     if (!$checkroles) {
                   2138:         $js .=  "    var disallow = new Array();\n".
                   2139:                 "    rolecheck = 0;\n";
                   2140:     }
1.273     droeschl 2141:     return <<"END";
1.235     raeburn  2142: <script type="text/javascript">
1.273     droeschl 2143: //<![CDATA[
1.401     raeburn  2144: function adhocRole(newrole) {
1.239     raeburn  2145:     $js
1.235     raeburn  2146:     if (newrole == '') {
1.350     raeburn  2147:         return;
1.235     raeburn  2148:     } 
1.239     raeburn  2149:     var fullrole = newrole+'./$cdom/$cnum';
                   2150:     var selidx = '';
                   2151:     for (var i=0; i<rolenames.length; i++) {
                   2152:         if (rolenames[i] == newrole) {
                   2153:             selidx = i;
                   2154:         }
                   2155:     }
1.350     raeburn  2156:     if (rolecheck > 0) {
                   2157:         for (var i=0; i<disallow.length; i++) {
                   2158:             if (disallow[i] == newrole) {
                   2159:                 if (confirm("$lt{'role'}\\n$lt{'swit'}")) {
                   2160:                     document.rolechooser.destinationurl.value = '/adm/menu';
                   2161:                 } else {
                   2162:                     return;
                   2163:                 }
                   2164:             }
                   2165:         }
                   2166:     }
1.239     raeburn  2167:     var secok = 1;
                   2168:     var secchoice = '';
                   2169:     if (selidx >= 0) {
                   2170:         if (numsec[selidx] > 1) {
                   2171:             secok = 0;
                   2172:             var numrolesec = rolesections[selidx].length;
                   2173:             var msgidx = numsec[selidx] - numrolesec;
1.339     raeburn  2174:             secchoice = prompt("$lt{'this'} "+secpick[msgidx]+"\\n$lt{'avai'} "+roleseclist[selidx],"");
1.239     raeburn  2175:             if (secchoice == '') {
                   2176:                 if (msgidx > 0) {
                   2177:                     secok = 1;
                   2178:                 }
                   2179:             } else {
                   2180:                 for (var j=0; j<rolesections[selidx].length; j++) {
                   2181:                     if (rolesections[selidx][j] == secchoice) {
                   2182:                         secok = 1;
                   2183:                     }
                   2184:                 }
                   2185:             }
                   2186:         } else {
                   2187:             if (rolesections[selidx].length == 1) {
                   2188:                 secchoice = rolesections[selidx][0];
                   2189:             }
                   2190:         }
                   2191:     }
                   2192:     if (secok == 1) {
                   2193:         if (secchoice != '') {
                   2194:             fullrole += '/'+secchoice;
                   2195:         }
                   2196:     } else {
                   2197:         if (secchoice != null) {
                   2198:             alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}");
                   2199:         }
                   2200:         return;
                   2201:     }
                   2202:     if (fullrole == "$env{'request.role'}") {
1.235     raeburn  2203:         return;
                   2204:     }
                   2205:     itemid = retrieveIndex('gotorole');
                   2206:     if (itemid != -1) {
1.239     raeburn  2207:         document.rolechooser.elements[itemid].name = fullrole;
1.235     raeburn  2208:     }
1.401     raeburn  2209:     document.rolechooser.switchrole.value = fullrole;
1.235     raeburn  2210:     document.rolechooser.selectrole.value = '1';
                   2211:     document.rolechooser.submit();
                   2212:     return;
                   2213: }
                   2214: 
                   2215: function retrieveIndex(item) {
                   2216:     for (var i=0;i<document.rolechooser.elements.length;i++) {
                   2217:         if (document.rolechooser.elements[i].name == item) {
                   2218:             return i;
                   2219:         }
                   2220:     }
                   2221:     return -1;
                   2222: }
1.273     droeschl 2223: // ]]>
1.235     raeburn  2224: </script>
                   2225: END
                   2226: }
                   2227: 
1.350     raeburn  2228: sub required_privs {
                   2229:     my $privs =  {
                   2230:              '/adm/parmset'      => 'opa',
                   2231:              '/adm/courseprefs'  => 'opa',
                   2232:              '/adm/whatsnew'     => 'whn',
                   2233:              '/adm/populate'     => 'cst',
                   2234:              '/adm/trackstudent' => 'vsa',
                   2235:              '/adm/statistics'   => 'vgr',
1.366     raeburn  2236:              '/adm/setblock'     => 'dcm',
1.367     raeburn  2237:              '/adm/coursedocs'   => 'mdc',
1.350     raeburn  2238:            };
                   2239:     unless ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'spreadsheet') {
1.364     raeburn  2240:         $privs->{'/adm/classcalc'}   = 'vgr',
                   2241:         $privs->{'/adm/assesscalc'}  = 'vgr',
                   2242:         $privs->{'/adm/studentcalc'} = 'vgr';
1.350     raeburn  2243:     }
                   2244:     return $privs;
                   2245: }
1.235     raeburn  2246: 
1.378     raeburn  2247: sub countdown_timer {
                   2248:     if (($env{'request.course.id'}) && ($env{'request.symb'} ne '') &&
1.387     raeburn  2249:         ($env{'request.filename'}=~/$LONCAPA::assess_re/)) {
                   2250:         my ($type,$hastimeleft,$slothastime);
                   2251:         my $now = time;
                   2252:         if ($env{'request.filename'} =~ /\.task$/) {
                   2253:             $type = 'Task';
                   2254:         } else {
                   2255:             $type = 'problem';
                   2256:         }
                   2257:         my ($status,$accessmsg,$slot_name,$slot) =
                   2258:             &Apache::lonhomework::check_slot_access('0',$type);
                   2259:         if ($slot_name ne '') {
                   2260:             if (ref($slot) eq 'HASH') {
                   2261:                 if (($slot->{'starttime'} < $now) &&
                   2262:                     ($slot->{'endtime'} > $now)) {
                   2263:                     $slothastime = 1;
                   2264:                 }
                   2265:             }
                   2266:         }
                   2267:         if ($status ne 'CAN_ANSWER') {
                   2268:             return;
                   2269:         }
1.378     raeburn  2270:         my $duedate = &Apache::lonnet::EXT("resource.0.duedate");
1.380     raeburn  2271:         my @interval=&Apache::lonnet::EXT("resource.0.interval");
1.381     raeburn  2272:         if (@interval > 1) {
                   2273:             my $first_access=&Apache::lonnet::get_first_access($interval[1]);
                   2274:             if ($first_access > 0) {
                   2275:                 if ($first_access+$interval[0] > time) {
                   2276:                     $hastimeleft = 1;
                   2277:                 }
                   2278:             }
                   2279:         }
1.380     raeburn  2280:         if (($duedate && $duedate > time) ||
1.387     raeburn  2281:             (!$duedate && $hastimeleft) ||
                   2282:             ($slot_name ne '' && $slothastime)) {
1.435   ! musolffc 2283:             my ($collapse,$expand,$alttxt,$title,$currdisp,$donebutton);
1.387     raeburn  2284:             if ((@interval > 1 && $hastimeleft) ||
                   2285:                 ($type eq 'Task' && $slothastime)) {
1.378     raeburn  2286:                 $currdisp = 'inline';
                   2287:                 $collapse = '&#9658;&nbsp;';
1.435   ! musolffc 2288:                 if ((@interval > 1) && ($hastimeleft)) {
        !          2289:                     $donebutton = &done_button_js($interval[1]);
        !          2290:                 }
1.378     raeburn  2291:             } else {
                   2292:                 $currdisp = 'none';
                   2293:                 $expand = '&#9668;&nbsp;';
                   2294:             }
                   2295:             unless ($env{'environment.icons'} eq 'iconsonly') {
1.379     raeburn  2296:                 $alttxt = &mt('Timer');
                   2297:                 $title = $alttxt.'&nbsp;';
1.378     raeburn  2298:             }
                   2299:             my $desc = &mt('Countdown to due date/time');
1.435   ! musolffc 2300: 
1.378     raeburn  2301:             return <<END;
1.435   ! musolffc 2302: $donebutton
1.378     raeburn  2303: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
                   2304: <span id="ddcountcollapse" class="LC_menubuttons_inline_text">
                   2305: $collapse
1.379     raeburn  2306: </span></a>
1.378     raeburn  2307: <span id="duedatecountdown" class="LC_menubuttons_inline_text" style="display: $currdisp;"></span>
                   2308: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
                   2309: <span id="ddcountexpand" class="LC_menubuttons_inline_text" >$expand</span>
1.379     raeburn  2310: <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  2311: END
                   2312:         }
                   2313:     }
                   2314:     return;
                   2315: }
                   2316: 
1.2       www      2317: # ================================================================ Main Program
                   2318: 
1.16      harris41 2319: BEGIN {
1.166     albertel 2320:     if (! defined($readdesk)) {
1.283     droeschl 2321:         {
                   2322:             my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
                   2323:             if ( CORE::open( my $config,"<$tabfile") ) {
                   2324:                 while (my $configline=<$config>) {
                   2325:                     $configline=(split(/\#/,$configline))[0];
                   2326:                     $configline=~s/^\s+//;
                   2327:                     chomp($configline);
1.209     www      2328:                     if ($configline=~/^cat\:/) {
1.283     droeschl 2329:                         my @entries=split(/\:/,$configline);
                   2330:                         $category_positions{$entries[2]}=$entries[1];
                   2331:                         $category_names{$entries[2]}=$entries[3];
                   2332:                     } elsif ($configline=~/^prim\:/) {
1.415     raeburn  2333:                         my @entries = (split(/\:/, $configline))[1..6];
1.400     raeburn  2334:                         push(@primary_menu,\@entries);
1.371     raeburn  2335:                     } elsif ($configline=~/^primsub\:/) {
                   2336:                         my ($parent,@entries) = (split(/\:/, $configline))[1..4];
1.400     raeburn  2337:                         push(@{$primary_submenu{$parent}},\@entries);
1.283     droeschl 2338:                     } elsif ($configline=~/^scnd\:/) {
                   2339:                         my @entries = (split(/\:/, $configline))[1..5];
1.401     raeburn  2340:                         push(@secondary_menu,\@entries);
1.283     droeschl 2341:                     } elsif ($configline) {
                   2342:                         push(@desklines,$configline);
                   2343:                     }
                   2344:                 }
                   2345:                 CORE::close($config);
                   2346:             }
                   2347:         }
                   2348:         $readdesk='done';
1.2       www      2349:     }
                   2350: }
1.30      www      2351: 
1.1       www      2352: 1;
                   2353: __END__
                   2354: 

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