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

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

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