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

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

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