File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.369.2.37: download - view: text, annotated - select for diffs
Mon Jan 14 18:04:32 2013 UTC (11 years, 4 months ago) by raeburn
Branches: version_2_11_X
- For 2.11
  "Edit" item in "Functions" box for HTML files uploaded directly to course
   when Remote Control is active.

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

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