File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.369.2.30: download - view: text, annotated - select for diffs
Thu Dec 27 05:52:00 2012 UTC (11 years, 5 months ago) by raeburn
Branches: version_2_11_X
- For 2.11
  - Backport 1.400, 1.401, 1.402, 1.403

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

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