File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.369.2.48: download - view: text, annotated - select for diffs
Fri Dec 13 14:30:49 2013 UTC (10 years, 5 months ago) by raeburn
Branches: version_2_11_X
- For 2.11
  - Backport 1.422, 1.423.

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

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