File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.369.2.34: download - view: text, annotated - select for diffs
Thu Jan 3 20:25:12 2013 UTC (11 years, 4 months ago) by raeburn
Branches: version_2_11_X
- For 2.11
  - Backport 1.408.
  - Backport one change in rev 1.401 omitted in earlier backport (rev. 1.369.2.30)

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

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