File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.369.2.45: download - view: text, annotated - select for diffs
Thu Aug 8 02:31:11 2013 UTC (10 years, 10 months ago) by raeburn
Branches: version_2_11_X
- For 2.11
  - Backport 1.417.

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

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