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

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

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