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

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

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