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

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

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