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

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

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