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

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

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