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

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

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