File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.413: download - view: text, annotated - select for diffs
Mon May 6 15:02:49 2013 UTC (11 years, 1 month ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Bug 6603.
  - Feeds item in secondary menu in course context.
  - Support case where syllabus template is not in use.
- Syllabus item in secondary menu in course context
  - Access to syllabus for cases where syllabus item is not included
    in course content.
- Syllabus and Feeds items always shown to roles with mdc priv in course.
- Feeds item only shown for roles without mdc priv if there are visible feeds.
- Syllabus item only shown for roles without mdc priv if syllabus is not in
  course content.

    1: # The LearningOnline Network with CAPA
    2: # Routines to control the menu
    3: #
    4: # $Id: lonmenu.pm,v 1.413 2013/05/06 15:02:49 raeburn Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: #
   29: 
   30: =head1 NAME
   31: 
   32: Apache::lonmenu
   33: 
   34: =head1 SYNOPSIS
   35: 
   36: Loads contents of /home/httpd/lonTabs/mydesk.tab, 
   37: used to generate inline menu, and Main Menu page. 
   38: 
   39: This is part of the LearningOnline Network with CAPA project
   40: described at http://www.lon-capa.org.
   41: 
   42: =head1 GLOBAL VARIABLES
   43: 
   44: =over
   45: 
   46: =item @desklines
   47: 
   48: Each element of this array contains a line of mydesk.tab that doesn't start with
   49: cat, prim or scnd. 
   50: It gets filled in the BEGIN block of this module.
   51: 
   52: =item %category_names
   53: 
   54: The keys of this hash are the abbreviations used in mydesk.tab in those lines that 
   55: start with cat, the values are strings representing titles. 
   56: It gets filled in the BEGIN block of this module.
   57: 
   58: =item %category_members
   59: 
   60: TODO 
   61: 
   62: =item %category_positions
   63: 
   64: The keys of this hash are the abbreviations used in mydesk.tab in those lines that
   65: start with cat, its values are position vectors (column, row). 
   66: It gets filled in the BEGIN block of this module.
   67: 
   68: =item $readdesk
   69: 
   70: Indicates that mydesk.tab has been read. 
   71: It is set to 'done' in the BEGIN block of this module.
   72: 
   73: =item @primary_menu
   74: 
   75: The elements of this array reference arrays that are made up of the components
   76: of those lines of mydesk.tab that start with prim:.
   77: It is used by primary_menu() to generate the corresponding menu.
   78: It gets filled in the BEGIN block of this module.
   79: 
   80: =item %primary_sub_menu
   81: 
   82: The keys of this hash reference are the names of items in the primary_menu array 
   83: which have sub-menus.  For each key, the corresponding value is a reference to
   84: an array containing components extracted from lines in mydesk.tab which begin
   85: with primsub:.
   86: This hash, which is used by primary_menu to generate sub-menus, is populated in
   87: the BEGIN block.
   88: 
   89: =item @secondary_menu
   90: 
   91: The elements of this array reference arrays that are made up of the components
   92: of those lines of mydesk.tab that start with scnd.
   93: It is used by secondary_menu() to generate the corresponding menu.
   94: It gets filled in the BEGIN block of this module.
   95: 
   96: =back
   97: 
   98: =head1 SUBROUTINES
   99: 
  100: =over
  101: 
  102: =item prep_menuitems(\@menuitem)
  103: 
  104: This routine wraps a menuitem in proper HTML. It is used by primary_menu() and 
  105: secondary_menu().
  106: 
  107: =item primary_menu()
  108: 
  109: This routine evaluates @primary_menu and returns XHTML for the menu
  110: that contains following links: About, Message, Roles, Help, Logout
  111: @primary_menu is filled within the BEGIN block of this module with 
  112: entries from mydesk.tab 
  113: 
  114: =item secondary_menu()
  115: 
  116: Same as primary_menu() but operates on @secondary_menu.
  117: 
  118: =item create_submenu()
  119: 
  120: Creates XHTML for unordered list of sub-menu items which belong to a 
  121: particular top-level menu item. Uses hover pseudo class in css to display
  122: dropdown list when mouse hovers over top-level item. Support for IE6 
  123: (no hover psuedo class) via LC_hoverable class for <li> tag for top-
  124: level item, which employs jQuery to handle behavior on mouseover.
  125: 
  126: Inputs: 4 - (a) link and (b) target for anchor href in top level item,
  127:             (c) title for text wrapped by anchor tag in top level item.
  128:             (d) reference to array of arrays of sub-menu items.
  129: 
  130: =item innerregister()
  131: 
  132: This gets called in order to register a URL in the body of the document
  133: 
  134: =item clear()
  135: 
  136: =item switch()
  137: 
  138: Switch a button or create a link
  139: Switch acts on the javascript that is executed when a button is clicked.  
  140: The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
  141: 
  142: =item secondlevel()
  143: 
  144: =item openmenu()
  145: 
  146: =item inlinemenu()
  147: 
  148: =item rawconfig()
  149: 
  150: =item utilityfunctions()
  151: 
  152: Output from this routine is a number of javascript functions called by
  153: items in the inline menu, and in some cases items in the Main Menu page. 
  154: 
  155: =item serverform()
  156: 
  157: =item constspaceform()
  158: 
  159: =item get_nav_status()
  160: 
  161: =item hidden_button_check()
  162: 
  163: =item roles_selector()
  164: 
  165: =item jump_to_role()
  166: 
  167: =back
  168: 
  169: =cut
  170: 
  171: package Apache::lonmenu;
  172: 
  173: use strict;
  174: use Apache::lonnet;
  175: use Apache::lonhtmlcommon();
  176: use Apache::loncommon();
  177: use Apache::lonenc();
  178: use Apache::lonlocal;
  179: use Apache::lonmsg();
  180: use LONCAPA qw(:DEFAULT :match);
  181: use HTML::Entities();
  182: use Apache::lonwishlist();
  183: 
  184: use vars qw(@desklines %category_names %category_members %category_positions 
  185:             $readdesk @primary_menu %primary_submenu @secondary_menu);
  186: 
  187: my @inlineremote;
  188: 
  189: sub prep_menuitem {
  190:     my ($menuitem) = @_;
  191:     return '' unless(ref($menuitem) eq 'ARRAY');
  192:     my $link;
  193:     if ($$menuitem[1]) { # graphical Link
  194:         $link = "<img class=\"LC_noBorder\""
  195:               . " src=\"" . &Apache::loncommon::lonhttpdurl($$menuitem[1]) . "\"" 
  196:               . " alt=\"" . &mt($$menuitem[2]) . "\" />";
  197:     } else {             # textual Link
  198:         $link = &mt($$menuitem[3]);
  199:     }
  200:     return '<li><a' 
  201:            # highlighting for new messages
  202:            . ( $$menuitem[4] eq 'newmsg' ? ' class="LC_new_message"' : '') 
  203:            . qq| href="$$menuitem[0]" target="_top">$link</a></li>|;
  204: }
  205: 
  206: # primary_menu() evaluates @primary_menu and returns XHTML for the menu
  207: # that contains following links:
  208: # About, Message, Personal, Roles, Help, Logout
  209: # @primary_menu is filled within the BEGIN block of this module with 
  210: # entries from mydesk.tab
  211: sub primary_menu {
  212:     my $menu;
  213:     # each element of @primary contains following array:
  214:     # (link url, icon path, alt text, link text, condition)
  215:     my $public;
  216:     if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
  217:         || (($env{'user.name'} eq '') && ($env{'user.domain'} eq ''))) {
  218:         $public = 1;
  219:     }
  220:     foreach my $menuitem (@primary_menu) {
  221:         # evaluate conditions 
  222:         next if    ref($menuitem)       ne 'ARRAY';    #
  223:         next if    $$menuitem[4]        eq 'nonewmsg'  # show links depending on
  224:                 && &Apache::lonmsg::mynewmail();       # whether a new msg 
  225:         next if    $$menuitem[4]        eq 'newmsg'    # arrived or not
  226:                 && !&Apache::lonmsg::mynewmail();      # 
  227:         next if    $$menuitem[4]        !~ /public/    ##we've a public user,
  228:                 && $public;                            ##who should not see all
  229:                                                        ##links
  230:         next if    $$menuitem[4]        eq 'onlypublic'# hide links which are 
  231:                 && !$public;                           # only visible to public
  232:                                                        # users
  233:         next if    $$menuitem[4]        eq 'roles'     ##show links depending on
  234:                 && &Apache::loncommon::show_course();  ##term 'Courses' or 
  235:         next if    $$menuitem[4]        eq 'courses'   ##'Roles' wanted
  236:                 && !&Apache::loncommon::show_course(); ##
  237:         
  238:         my $title = $menuitem->[3];
  239:         if (defined($primary_submenu{$title})) {
  240:             my ($link,$target);
  241:             if ($menuitem->[0] ne '') {
  242:                 $link = $menuitem->[0];
  243:                 $target = '_top';
  244:             } else {
  245:                 $link = '#';
  246:             }
  247:             my @primsub;
  248:             if (ref($primary_submenu{$title}) eq 'ARRAY') {
  249:                 foreach my $item (@{$primary_submenu{$title}}) {
  250:                     next if (($item->[2] eq 'wishlist') && (!$env{'user.adv'}));
  251:                     next if ((($item->[2] eq 'portfolio') ||
  252:                              ($item->[2] eq 'blog')) &&
  253:                              (!&Apache::lonnet::usertools_access('','',$item->[2],
  254:                                                            undef,'tools')));
  255:                     push(@primsub,$item);
  256:                 }
  257:                 if (@primsub > 0) {
  258:                     $menu .= &create_submenu($link,$target,$title,\@primsub);
  259:                 } elsif ($link) {
  260:                     $menu .= '<li><a href="'.$link.'" target="'.$target.'">'.&mt($title).'</a></li>';
  261:                 }
  262:             }
  263:         } elsif ($$menuitem[3] eq 'Help') { # special treatment for helplink
  264:             if ($public) {
  265:                 my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
  266:                 my $defdom = &Apache::lonnet::default_login_domain();
  267:                 my $to = &Apache::loncommon::build_recipient_list(undef,
  268:                                                                   'helpdeskmail',
  269:                                                                   $defdom,$origmail);
  270:                 if ($to ne '') {
  271:                     $menu .= &prep_menuitem($menuitem); 
  272:                 }
  273:             } else {
  274:                 $menu .= '<li>'.&Apache::loncommon::top_nav_help('Help').'</li>';
  275:             }
  276:         } else {
  277:             $menu .= prep_menuitem($menuitem);
  278:         }
  279:     }
  280:     $menu =~ s/\[domain\]/$env{'user.domain'}/g;
  281:     $menu =~ s/\[user\]/$env{'user.name'}/g;
  282: 
  283:     return "<ol class=\"LC_primary_menu LC_right\">$menu</ol>";
  284: }
  285: 
  286: #returns hashref {user=>'',dom=>''} containing:
  287: #   own name, domain if user is au
  288: #   name, domain of parent author if user is ca or aa
  289: #empty return if user is not an author or not on homeserver
  290: #
  291: #TODO this should probably be moved somewhere more central
  292: #since it can be used by different parts of the system
  293: sub getauthor{
  294:     return unless $env{'request.role'}=~/^(ca|aa|au)/; #nothing to do if user isn't some kind of author
  295: 
  296:                         #co- or assistent author?
  297:     my ($dom, $user) = ($env{'request.role'} =~ /^(?:ca|aa)\.\/($match_domain)\/($match_username)$/)
  298:                        ? ($1, $2) #domain, username of the parent author
  299:                        : @env{ ('request.role.domain', 'user.name') }; #own domain, username
  300: 
  301:     # current server == home server?
  302:     my $home =  &Apache::lonnet::homeserver($user,$dom);
  303:     foreach (&Apache::lonnet::current_machine_ids()){
  304:         return {user => $user, dom => $dom} if $_ eq $home;
  305:     }
  306: 
  307:     # if wrong server
  308:     return;
  309: }
  310: 
  311: sub secondary_menu {
  312:     my $menu;
  313: 
  314:     my $crstype = &Apache::loncommon::course_type();
  315:     my $crs_sec = $env{'request.course.id'} . ($env{'request.course.sec'} 
  316:                                                ? "/$env{'request.course.sec'}"
  317:                                                : '');
  318:     my $canedit       = &Apache::lonnet::allowed('mdc', $env{'request.course.id'});
  319:     my $canviewroster = $env{'course.'.$env{'request.course.id'}.'.student_classlist_view'};
  320:     my $canviewgrps   = &Apache::lonnet::allowed('vcg', $crs_sec); 
  321:     my $canmodifyuser = &Apache::lonnet::allowed('cst', $crs_sec); 
  322:     my $canviewwnew   = &Apache::lonnet::allowed('whn', $crs_sec); 
  323:     my $canmodpara    = &Apache::lonnet::allowed('opa', $crs_sec);
  324:     my $canvgr        = &Apache::lonnet::allowed('vgr', $crs_sec);
  325:     my $canmgr        = &Apache::lonnet::allowed('mgr', $crs_sec); 
  326:     my $author        = &getauthor();
  327: 
  328:     my ($cdom,$cnum,$showsyllabus,$showfeeds);
  329:     if ($env{'request.course.id'}) {
  330:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  331:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
  332:         if ($canedit) {
  333:             $showsyllabus = 1;
  334:             $showfeeds = 1;
  335:         } else {
  336:             unless (&Apache::lonnet::is_on_map("public/$cdom/$cnum",'syllabus')) {
  337:                 $showsyllabus = 1;
  338:             }
  339:             if ($env{'course.'.$env{'request.course.id'}.'.feeds'}) {
  340:                 $showfeeds = 1; 
  341:             } 
  342:         }
  343:     }
  344: 
  345:     my ($canmodifycoauthor); 
  346:     if ($env{'request.role'} eq "au./$env{'user.domain'}/") {
  347:         my $extent = "$env{'user.domain'}/$env{'user.name'}";
  348:         if ((&Apache::lonnet::allowed('cca',$extent)) ||
  349:             (&Apache::lonnet::allowed('caa',$extent))) {
  350:             $canmodifycoauthor = 1;
  351:         }
  352:     }
  353: 
  354:     my %groups = &Apache::lonnet::get_active_groups(
  355:                      $env{'user.domain'}, $env{'user.name'},
  356:                      $env{'course.' . $env{'request.course.id'} . '.domain'},
  357:                      $env{'course.' . $env{'request.course.id'} . '.num'});
  358: 
  359:     my ($roleswitcher_js,$roleswitcher_form);
  360: 
  361:     foreach my $menuitem (@secondary_menu) {
  362:         # evaluate conditions 
  363:         next if    ref($menuitem)  ne 'ARRAY';
  364:         next if    $$menuitem[4]   ne 'always'
  365:                 && ($$menuitem[4]   ne 'author' && $$menuitem[4] ne 'cca')
  366:                 && !$env{'request.course.id'};
  367:         next if    $$menuitem[4]   =~ /^mdc/
  368:                 && !$canedit;
  369:         next if    $$menuitem[4]  eq 'nvgr'
  370:                 && $canvgr;
  371:         next if    $$menuitem[4]  eq 'vgr'
  372:                 && !$canvgr;
  373:         next if    $$menuitem[4]   eq 'cst'
  374:                 && !$canmodifyuser;
  375:         next if    $$menuitem[4]   eq 'ncst'
  376:                 && ($canmodifyuser || !$canviewroster);
  377:         next if    $$menuitem[4]   eq 'mgr'
  378:                 && !$canmgr;
  379:         next if    $$menuitem[4]   eq 'nmgr'
  380:                 && $canmgr;
  381:         next if    $$menuitem[4]   eq 'whn'
  382:                 && !$canviewwnew;
  383:         next if    $$menuitem[4]   eq 'opa'
  384:                 && !$canmodpara;
  385:         next if    $$menuitem[4]   =~ /showgroups$/
  386:                 && !$canviewgrps
  387:                 && !%groups;
  388:         next if    $$menuitem[4]   eq 'showsyllabus'
  389:                 && !$showsyllabus;
  390:         next if    $$menuitem[4]   eq 'showfeeds'
  391:                 && !$showfeeds;
  392:         next if    $$menuitem[4]    eq 'author'
  393:                 && !$author;
  394:         next if    $$menuitem[4]    eq 'cca'
  395:                 && !$canmodifycoauthor;
  396: 
  397:         if ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) {
  398:             # special treatment for role selector
  399:             ($roleswitcher_js,$roleswitcher_form,my $switcher) =
  400:                 &roles_selector(
  401:                         $env{'course.' . $env{'request.course.id'} . '.domain'},
  402:                         $env{'course.' . $env{'request.course.id'} . '.num'}
  403:                 );
  404:             $menu .= $switcher;
  405:         } else {
  406:             $menu .= &prep_menuitem(\@$menuitem);
  407:         }
  408:     }
  409:     if ($menu =~ /\[url\].*\[symb\]/) {
  410:         my $escurl  = &escape( &Apache::lonenc::check_encrypt(
  411:                              $env{'request.noversionuri'}));
  412: 
  413:         my $escsymb = &escape( &Apache::lonenc::check_encrypt(
  414:                              $env{'request.symb'})); 
  415: 
  416:         if (    $env{'request.state'} eq 'construct'
  417:             and (   $env{'request.noversionuri'} eq '' 
  418:                  || !defined($env{'request.noversionuri'}))) 
  419:         {
  420:             my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
  421:             ($escurl = $env{'request.filename'}) =~ s{^\Q$londocroot\E}{};
  422:             $escurl  = &escape($escurl);
  423:         }    
  424:         $menu =~ s/\[url\]/$escurl/g;
  425:         $menu =~ s/\[symb\]/$escsymb/g;
  426:     }
  427:     $menu =~ s/\[uname\]/$$author{user}/g;
  428:     $menu =~ s/\[udom\]/$$author{dom}/g;
  429:     if ($showsyllabus || $showfeeds) {
  430:         $menu =~ s/\[cnum\]/$cnum/g;
  431:         $menu =~ s/\[cdom\]/$cdom/g;
  432:     }
  433:     if ($menu) {
  434:         $menu = "<ul id=\"LC_secondary_menu\">$menu</ul>";
  435:     }
  436:     if ($roleswitcher_form) {
  437:         $menu .= "\n$roleswitcher_js\n$roleswitcher_form";
  438:     }
  439:     return $menu;
  440: }
  441: 
  442: sub create_submenu {
  443:     my ($link,$target,$title,$submenu) = @_;
  444:     return unless (ref($submenu) eq 'ARRAY');
  445:     my $disptarget;
  446:     if ($target ne '') {
  447:         $disptarget = ' target="'.$target.'"';
  448:     }
  449:     my $menu = '<li class="LC_hoverable">'.
  450:                '<a href="'.$link.'"'.$disptarget.'>'.
  451:                '<span class="LC_nobreak">'.&mt($title).
  452:                '<span class="LC_fontsize_small" style="font-weight:normal;">'.
  453:                ' &#9660;</span></span></a>'.
  454:                '<ul>';
  455:     my $count = 0;
  456:     my $numsub = scalar(@{$submenu});
  457:     foreach my $item (@{$submenu}) {
  458:         $count ++;
  459:         if (ref($item) eq 'ARRAY') {
  460:             my $borderbot;
  461:             if ($count == $numsub) {
  462:                 $borderbot = 'border-bottom:1px solid black;';
  463:             }
  464:             $menu .= '<li style="margin:0;padding:0;'.
  465:                      $borderbot.'"><a href="'.$item->[0].'">'.
  466:                      &mt($item->[1]).'</a></li>';
  467:         }
  468:     }
  469:     $menu .= '</ul></li>';
  470:     return $menu;
  471: }
  472: 
  473: sub innerregister {
  474:     my ($forcereg,$bread_crumbs,$group) = @_;
  475:     my $const_space = ($env{'request.state'} eq 'construct');
  476:     my $is_const_dir = 0;
  477: 
  478:     if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
  479: 
  480:     $env{'request.registered'} = 1;
  481: 
  482:     undef(@inlineremote);
  483: 
  484:     my ($mapurl,$resurl);
  485: 
  486:     if ($env{'request.course.id'}) {
  487:         if ($env{'request.symb'}) {
  488:             ($mapurl, my $rid, $resurl) = &Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
  489:             my $coursetitle = $env{'course.'.$env{'request.course.id'}.'.description'};
  490: 
  491:             my $maptitle = &Apache::lonnet::gettitle($mapurl);
  492:             my $restitle = &Apache::lonnet::gettitle(&Apache::lonnet::symbread());
  493: 
  494: #SD
  495: #course_type only Course and Community?
  496: #
  497:             my @crumbs;
  498:             unless (($forcereg) &&
  499:                     ($env{'request.noversionuri'} eq '/adm/navmaps') &&
  500:                     ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'})) {
  501:                 @crumbs = ({text  => Apache::loncommon::course_type() 
  502:                                     . ' Contents', 
  503:                             href  => "Javascript:gopost('/adm/navmaps','')"});
  504:             }
  505:             if ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) { 
  506:                 push(@crumbs, {text  => '...',
  507:                                no_mt => 1});
  508:             }
  509: 
  510:             push @crumbs, {text => $maptitle, no_mt => 1} if ($maptitle 
  511:                                                        && $maptitle ne 'default.sequence' 
  512:                                                        && $maptitle ne $coursetitle);
  513: 
  514:             push @crumbs, {text => $restitle, no_mt => 1} if $restitle; 
  515:             &Apache::lonhtmlcommon::clear_breadcrumbs();
  516:             &Apache::lonhtmlcommon::add_breadcrumb(@crumbs);
  517:         } else {
  518:             $resurl = $env{'request.noversionuri'};
  519:             my $courseurl = &Apache::lonnet::courseid_to_courseurl($env{'request.course.id'});
  520:             my $crstype = &Apache::loncommon::course_type();
  521:             my $title = &mt('View Resource');
  522:             if ($resurl =~ m{^\Q/uploaded$courseurl/supplemental/\E(default|\d+)/}) {
  523:                 &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folderpath','title']);
  524:                 &Apache::lonhtmlcommon::clear_breadcrumbs();
  525:                 if ($env{'form.title'}) {
  526:                     $title = $env{'form.title'};
  527:                 }
  528:                 my $trail;
  529:                 if ($env{'form.folderpath'}) {
  530:                     &prepare_functions($resurl,$forcereg,$group,undef,undef,1);
  531:                     ($trail) =
  532:                         &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
  533:                 } else {
  534:                     &Apache::lonhtmlcommon::add_breadcrumb(
  535:                     {text  => "Supplemental $crstype Content",
  536:                      href  => "javascript:gopost('/adm/supplemental','')"});
  537:                     $title = &mt('View Resource');
  538:                     ($trail) = 
  539:                         &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
  540:                 }
  541:                 return $trail;
  542:             } elsif ($resurl =~ m{^\Q/uploaded$courseurl/portfolio/syllabus/}) {
  543:                 &Apache::lonhtmlcommon::clear_breadcrumbs();
  544:                 &prepare_functions('/public'.$courseurl."/syllabus",
  545:                                    $forcereg,$group,undef,undef,1);
  546:                 $title = &mt('Syllabus File');
  547:                 my ($trail) =
  548:                     &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
  549:                 return $trail;
  550:             }
  551:             unless ($env{'request.state'} eq 'construct') {
  552:                 &Apache::lonhtmlcommon::clear_breadcrumbs();
  553:                 &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
  554:             }
  555:         }
  556:     } elsif (! $const_space){
  557:         #a situation when we're looking at a resource outside of context of a 
  558:         #course or construction space (e.g. with cumulative rights)
  559:         &Apache::lonhtmlcommon::clear_breadcrumbs();
  560:         unless ($env{'request.noversionuri'} =~ m{^/adm/$match_domain/$match_username/aboutme$}) {
  561:             &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
  562:         }
  563:     }
  564: # =============================================================================
  565: # ============================ This is for URLs that actually can be registered
  566:     return '' unless ( ($env{'request.noversionuri'}!~m{^/(res/)*adm/}) 
  567:                        || $forcereg );
  568:     my ($cdom,$cnum,%perms,$cfile,$switchserver,$home,$forceedit,
  569:         $forceview,$editbutton);
  570:     if (($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) ||
  571:         ($env{'request.role'} !~/^(aa|ca|au)/)) {
  572:         $editbutton = &prepare_functions($resurl,$forcereg,$group);
  573:     }
  574:     if ($editbutton eq '') {
  575:         $editbutton = &clear(6,1);
  576:     }
  577: 
  578: #
  579: # This applies in course context
  580: #
  581:     if ($env{'request.course.id'}) {
  582:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
  583:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  584:         $perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
  585:         my @privs;
  586:         if ($env{'request.symb'} ne '') {
  587:              if ($env{'request.filename'}=~/$LONCAPA::assess_re/) {
  588:                  push(@privs,('mgr','vgr'));
  589:              }
  590:              push(@privs,'opa');
  591:         }
  592:         foreach my $priv (@privs) {
  593:             $perms{$priv} = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
  594:             if (!$perms{$priv} && $env{'request.course.sec'} ne '') {
  595:                 $perms{$priv} = 
  596:                     &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
  597:             }
  598:         }
  599: #
  600: # Determine whether or not to show Grades and Submissions buttons
  601: #
  602:         if ($env{'request.symb'} ne '' &&
  603:             $env{'request.filename'}=~/$LONCAPA::assess_re/) {
  604:             if ($perms{'mgr'}) {
  605:                 &switch('','',7,2,'pgrd.png','Content Grades','grades[_4]',
  606:                         "gocmd('/adm/grades','gradingmenu')",
  607:                         'Content Grades');
  608:             } elsif ($perms{'vgr'}) {
  609:                 &switch('','',7,2,'subm.png','Content Submissions','missions[_1]',
  610:                         "gocmd('/adm/grades','submission')",
  611:                         'Content Submissions');
  612:              }
  613:         }
  614:         if (($env{'request.symb'} ne '') && ($perms{'opa'})) {
  615:             &switch('','',7,3,'pparm.png','Content Settings','parms[_2]',
  616:                     "gocmd('/adm/parmset','set')",
  617:                     'Content Settings');
  618: 	}
  619: # End grades/submissions check
  620: 
  621: #
  622: # This applies to items inside a folder/page modifiable in the course.
  623: #
  624:         if (($env{'request.symb'}=~/^uploaded/) && ($perms{'mdc'})) {
  625:             my $text = 'Edit Folder';
  626:             if (($mapurl =~ /\.page$/) ||
  627:                 ($env{'request.symb'}=~
  628:                      m{uploaded/$cdom/$cnum/default_\d+\.page$}))  {
  629:                 $text = 'Edit Page';
  630:             }
  631:             &switch('','',7,4,'docs-22x22.png',$text,'parms[_2]',
  632:                     "gocmd('/adm/coursedocs','direct')",
  633:                     'Folder/Page Content');
  634:         }
  635: # End modifiable folder/page container check
  636:     }
  637: # End course context
  638: 
  639: # Prepare the rest of the buttons
  640:         my ($menuitems,$got_prt,$got_wishlist);
  641:         if ($const_space) {
  642: #
  643: # We are in construction space
  644: #
  645: 
  646:             my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
  647: 	    my ($udom,$uname,$thisdisfn) =
  648: 		($env{'request.filename'}=~m{^\Q$londocroot/priv/\E([^/]+)/([^/]+)/(.*)$});
  649:             my $currdir = '/priv/'.$udom.'/'.$uname.'/'.$thisdisfn;
  650:             if ($currdir =~ m-/$-) {
  651:                 $is_const_dir = 1;
  652:             } else {
  653:                 $currdir =~ s|[^/]+$||;
  654: 		my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn);
  655: 		my $esc_currdir = &Apache::loncommon::escape_single($currdir);
  656: #
  657: # Probably should be in mydesk.tab
  658: #
  659:                 $menuitems=(<<ENDMENUITEMS);
  660: s&6&1&list.png&Directory&dir[_1]&golist('$esc_currdir')&List current directory
  661: s&6&2&rtrv.png&Retrieve&version[_1]&gocstr('/adm/retrieve','/priv/$udom/$uname/$cleandisfn')&Retrieve old version
  662: s&6&3&pub.png&Publish&resource[_3]&gocstr('/adm/publish','/priv/$udom/$uname/$cleandisfn')&Publish this resource
  663: s&7&1&del.png&Delete&resource[_2]&gocstr('/adm/cfile?action=delete','/priv/$udom/$uname/$cleandisfn')&Delete this resource
  664: s&7&2&prt.png&Print&printout[_1]&gocstr('/adm/printout','/priv/$udom/$uname/$cleandisfn')&Prepare a printable document
  665: ENDMENUITEMS
  666:             }
  667:                 if (ref($bread_crumbs) eq 'ARRAY') {
  668:                     &Apache::lonhtmlcommon::clear_breadcrumbs();
  669:                     foreach my $crumb (@{$bread_crumbs}){
  670:                         &Apache::lonhtmlcommon::add_breadcrumb($crumb);
  671:                     }
  672:                 }
  673:         } elsif ( defined($env{'request.course.id'}) && 
  674: 		 $env{'request.symb'} ne '' ) {
  675: #
  676: # We are in a course and looking at a registered URL
  677: # Should probably be in mydesk.tab
  678: #
  679: 	    $menuitems=(<<ENDMENUITEMS);
  680: c&3&1
  681: s&2&1&back.png&&&gopost('/adm/flip','back:'+currentURL)&Previous content resource&&1
  682: s&2&3&forw.png&&&gopost('/adm/flip','forward:'+currentURL)&Next content resource&&3
  683: c&6&3
  684: c&8&1
  685: c&8&2
  686: s&8&3&prt.png&Print&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
  687: ENDMENUITEMS
  688:             $got_prt = 1;
  689:             if (($env{'user.adv'}) && ($env{'request.uri'} =~ /^\/res/)
  690:                 && (!$env{'request.enc'})) {
  691:                 # wishlist is only available for users with access to resource-pool
  692:                 # and links can only be set for resources within the resource-pool
  693:                 $menuitems .= (<<ENDMENUITEMS);
  694: s&9&1&wishlist-link.png&Stored Links&wishlistlink[_2]&set_wishlistlink()&Save a link for this resource in your personal Stored Links repository&&1
  695: ENDMENUITEMS
  696:                 $got_wishlist = 1;
  697:             }
  698: 
  699: my $currentURL = &Apache::loncommon::get_symb();
  700: my ($symb_old,$symb_old_enc) = &Apache::loncommon::clean_symb($currentURL);
  701: my $annotation = &Apache::loncommon::get_annotation($symb_old,$symb_old_enc);
  702: $menuitems.="s&9&3&";
  703: if(length($annotation) > 0){
  704: 	$menuitems.="anot2.png";
  705: }else{
  706: 	$menuitems.="anot.png";
  707: }
  708: $menuitems.="&Notes&&annotate()&";
  709: $menuitems.="Make notes and annotations about this resource&&1\n";
  710: 
  711:             unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|viewclasslist|portfolio)(\?|$)/) {
  712: 		if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/}) && ($env{'request.noversionuri'} !~ m{^/uploaded/$match_domain/$match_courseid/docs/})) {
  713: 		    $menuitems.=(<<ENDREALRES);
  714: s&6&3&catalog.png&Info&info[_1]&catalog_info()&Show Metadata
  715: ENDREALRES
  716:                 }
  717:                 unless ($env{'request.noversionuri'} =~ m{^/uploaded/$match_domain/$match_courseid/docs/}) {
  718:                     $menuitems.=(<<ENDREALRES);
  719: s&8&1&eval.png&Evaluate&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
  720: ENDREALRES
  721:                 }
  722:                 $menuitems.=(<<ENDREALRES);
  723: s&8&2&fdbk.png&Communicate&discuss[_1]&gopost('/adm/feedback',currentURL,1)&Provide feedback messages or contribute to the course discussion about this resource
  724: ENDREALRES
  725: 	    }
  726:         }
  727: 	if ($env{'request.uri'} =~ /^\/res/) {
  728:             unless ($got_prt) {
  729: 	        $menuitems .= (<<ENDMENUITEMS);
  730: s&8&3&prt.png&Print&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
  731: ENDMENUITEMS
  732:                 $got_prt = 1;
  733:             }
  734:             unless ($got_wishlist) {
  735:                 if (($env{'user.adv'}) && (!$env{'request.enc'})) {
  736:                     # wishlist is only available for users with access to resource-pool
  737:                     $menuitems .= (<<ENDMENUITEMS);
  738: s&9&1&wishlist-link.png&Stored Links&wishlistlink[_2]&set_wishlistlink()&Save a link for this resource in your personal Stored Links repository&&1
  739: ENDMENUITEMS
  740:                     $got_wishlist = 1;
  741:                 }
  742: 	    }
  743:         }
  744:         my $buttons='';
  745:         foreach (split(/\n/,$menuitems)) {
  746: 	    my ($command,@rest)=split(/\&/,$_);
  747:             my $idx=10*$rest[0]+$rest[1];
  748:             if (&hidden_button_check() eq 'yes') {
  749:                 if ($idx == 21 ||$idx == 23) {
  750:                     $buttons.=&switch('','',@rest);
  751:                 } else {
  752:                     $buttons.=&clear(@rest);
  753:                 }
  754:             } else {  
  755:                 if ($command eq 's') {
  756: 	            $buttons.=&switch('','',@rest);
  757:                 } else {
  758:                     $buttons.=&clear(@rest);
  759:                 }
  760:             }
  761:         }
  762: 
  763: 	    my $addremote=0;
  764: 	    foreach (@inlineremote) { if ($_ ne '') { $addremote=1; last;} }
  765:     if ($addremote) {
  766: 
  767:         &Apache::lonhtmlcommon::clear_breadcrumb_tools();
  768: 
  769:             &Apache::lonhtmlcommon::add_breadcrumb_tool(
  770:                 'navigation', @inlineremote[21,23]);
  771: 
  772:         my $countdown = &countdown_timer();
  773:         if (&hidden_button_check() eq 'yes') {
  774:             if ($countdown) {
  775:                 &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$countdown);
  776:             }
  777:         } else {
  778:             my @tools = @inlineremote[93,91,81,82,83];
  779:             if ($countdown) {
  780:                 unshift(@tools,$countdown);
  781:             }
  782:             &Apache::lonhtmlcommon::add_breadcrumb_tool(
  783:                 'tools',@tools);
  784: 
  785:             #publish button in construction space
  786:             if ($env{'request.state'} eq 'construct'){
  787:                 &Apache::lonhtmlcommon::add_breadcrumb_tool(
  788:                      'advtools', $inlineremote[63]);
  789:             } else {
  790:                 &Apache::lonhtmlcommon::add_breadcrumb_tool(
  791:                      'tools', $inlineremote[63]);
  792:             }
  793:             &advtools_crumbs(@inlineremote);
  794:         }
  795:     }
  796: 
  797:     return   &Apache::lonhtmlcommon::scripttag('', 'start')
  798:            . &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
  799:            . &Apache::lonhtmlcommon::scripttag('', 'end');
  800: }
  801: 
  802: sub get_editbutton {
  803:     my ($cfile,$home,$switchserver,$forceedit,$forceview,$forcereg) = @_;
  804:     my $jscall;
  805:     if (($forceview) && ($env{'form.todocs'})) {
  806:         my ($folderpath,$command);
  807:         if ($env{'request.symb'}) {
  808:             $folderpath = &Apache::loncommon::symb_to_docspath($env{'request.symb'});
  809:         } elsif ($env{'form.folderpath'} =~ /^supplemental/) {
  810:             $folderpath = $env{'form.folderpath'};
  811:             $command = '&forcesupplement=1';
  812:         }
  813:         $folderpath = &escape(&HTML::Entities::encode(&escape($folderpath),'<>&"'));
  814:         $jscall = "go('/adm/coursedocs?folderpath=$folderpath$command')";
  815:     } else {
  816:         $jscall = &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,$switchserver,
  817:                                                 $forceedit,$forcereg,$env{'request.symb'},
  818:                                                 &escape($env{'form.folderpath'}),
  819:                                                 &escape($env{'form.title'}),$env{'form.idx'},
  820:                                                 &escape($env{'form.suppurl'},$env{'form.todocs'}));
  821:     }
  822:     if ($jscall) {
  823:         my $icon = 'pcstr.png';
  824:         my $label = 'Edit';
  825:         if ($forceview) {
  826:             $icon = 'tolastloc.png';
  827:             $label = 'Exit Editing';
  828:         }
  829:         &switch('','',6,1,$icon,$label,'resource[_2]',
  830:                 $jscall,"Edit this resource");
  831:         return 1;
  832:     }
  833:     return;
  834: }
  835: 
  836: sub prepare_functions {
  837:     my ($resurl,$forcereg,$group,$bread_crumbs,$advtools,$docscrumbs) = @_;
  838:     unless ($env{'request.registered'}) {
  839:         undef(@inlineremote);
  840:     }
  841:     my ($cdom,$cnum,%perms,$cfile,$switchserver,$home,$forceedit,
  842:         $forceview);
  843: 
  844:     if ($env{'request.course.id'}) {
  845:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
  846:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  847:         $perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
  848:     }
  849: 
  850:     my $editbutton = '';
  851: #
  852: # Determine whether or not to display 'Edit' icon/button
  853: #
  854:     if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
  855:         my $file=&Apache::lonnet::declutter($env{'request.filename'});
  856:         ($cfile,$home,$switchserver,$forceedit,$forceview) =
  857:             &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
  858:                 &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
  859:         if (($cfile) && ($home ne '') && ($home ne 'no_host')) {
  860:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
  861:                                           $forceedit,$forceview,$forcereg);
  862:         }
  863:     } elsif ((!$env{'request.course.id'}) &&
  864:              ($env{'user.author'}) && ($env{'request.filename'}) &&
  865:              ($env{'request.role'} !~/^(aa|ca|au)/)) {
  866: #
  867: # Currently do not have the role of author or co-author.
  868: # Do we have authoring privileges for the resource?
  869: #
  870:         my $file=&Apache::lonnet::declutter($env{'request.filename'});
  871:         ($cfile,$home,$switchserver,$forceedit,$forceview) =
  872:             &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
  873:                 &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
  874:         if (($cfile) && ($home ne '') && ($home ne 'no_host')) {
  875:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
  876:                                           $forceedit,$forceview,$forcereg);
  877:         }
  878:     } elsif ($env{'request.course.id'}) {
  879: #
  880: # This applies in course context
  881: #
  882:         if (($perms{'mdc'}) &&
  883:             (($resurl eq "/public/$cdom/$cnum/syllabus") ||
  884:             ($resurl =~ m{^/uploaded/$cdom/$cnum/portfolio/syllabus/}))) {
  885:             $cfile = $resurl;
  886:             $home = &Apache::lonnet::homeserver($cnum,$cdom);
  887:             if ($env{'form.forceedit'}) {
  888:                 $forceview = 1;
  889:             } else {
  890:                 $forceedit = 1;
  891:             }
  892:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
  893:                                           $forceedit,$forceview,$forcereg);
  894:         } elsif (($resurl eq '/adm/extresedit') &&
  895:                  (($env{'form.symb'}) || ($env{'form.folderpath'}))) {
  896:             ($cfile,$home,$switchserver,$forceedit,$forceview) =
  897:             &Apache::lonnet::can_edit_resource($resurl,$cnum,$cdom,$resurl,
  898:                                                $env{'form.symb'});
  899:             if ($cfile ne '') {
  900:                 $editbutton = &get_editbutton($cfile,$home,$switchserver,
  901:                                               $forceedit,$forceview,$forcereg,
  902:                                               $env{'form.title'},$env{'form.suppurl'});
  903:             }
  904:         } elsif (($resurl =~ m{^/?adm/viewclasslist$}) &&
  905:                  (&Apache::lonnet::allowed('opa',$env{'request.course.id'}))) {
  906:             ($cfile,$home,$switchserver,$forceedit,$forceview) =
  907:             &Apache::lonnet::can_edit_resource($resurl,$cnum,$cdom,$resurl,
  908:                                                $env{'form.symb'});
  909:             $editbutton = &get_editbutton($cfile,$home,$switchserver,
  910:                                           $forceedit,$forceview,$forcereg);
  911:         } elsif (($resurl !~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) &&
  912:                  ($resurl ne '/cgi-bin/printout.pl')) {
  913:             if ($env{'request.filename'}) {
  914:                 my $file=&Apache::lonnet::declutter($env{'request.filename'});
  915:                 ($cfile,$home,$switchserver,$forceedit,$forceview) =
  916:                     &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
  917:                         &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
  918:                 if ($cfile ne '') {
  919:                     $editbutton = &get_editbutton($cfile,$home,$switchserver,
  920:                                                   $forceedit,$forceview,$forcereg);
  921:                 }
  922:             }
  923:         }
  924:     }
  925: # End determination of 'Edit' icon/button display
  926: 
  927:     if ($env{'request.course.id'}) {
  928: # This applies to about me page for users in a course
  929:         if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
  930:             my ($sdom,$sname) = ($1,$2);
  931:             unless (&Apache::lonnet::is_course($sdom,$sname)) {
  932:                 &switch('','',6,4,'mail-message-new-22x22.png','Message to user',
  933:                         '',
  934:                         "go('/adm/email?compose=individual&recname=$sname&recdom=$sdom')",
  935:                             'Send message to specific user');
  936:             }
  937:             my $hideprivileged = 1;
  938:             if (&Apache::lonnet::in_course($sdom,$sname,$cdom,$cnum,undef,
  939:                                            $hideprivileged)) {
  940:                 foreach my $priv ('vsa','vgr','srm') {
  941:                     $perms{$priv} = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
  942:                     if (!$perms{$priv} && $env{'request.course.sec'} ne '') {
  943:                         $perms{$priv} =
  944:                             &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
  945:                     }
  946:                 }
  947:                 if ($perms{'vsa'}) {
  948:                     &switch('','',6,5,'trck-22x22.png','Activity',
  949:                             '',
  950:                             "go('/adm/trackstudent?selected_student=$sname:$sdom')",
  951:                             'View recent activity by this person');
  952:                 }
  953:                 if ($perms{'vgr'}) {
  954:                     &switch('','',6,6,'rsrv-22x22.png','Reservations',
  955:                             '',
  956:                             "go('/adm/slotrequest?command=showresv&origin=aboutme&uname=$sname&udom=$sdom')",
  957:                             'Slot reservation history');
  958:                 }
  959:                 if ($perms{'srm'}) {
  960:                     &switch('','',6,7,'contact-new-22x22.png','Records',
  961:                             '',
  962:                             "go('/adm/email?recordftf=retrieve&recname=$sname&recdom=$sdom')",
  963:                             'Add records');
  964:                 }
  965:             }
  966:         }
  967:         if (($env{'form.folderpath'} =~ /^supplemental/) &&
  968:             (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) &&
  969:             (($resurl =~ m{^/adm/wrapper/ext/}) ||
  970:              ($resurl =~ m{^/uploaded/$cdom/$cnum/supplemental/}) ||
  971:              ($resurl eq '/adm/supplemental') ||
  972:              ($resurl =~ m{^/public/$cdom/$cnum/syllabus$}) ||
  973:              ($resurl =~ m{^/adm/$match_domain/$match_username/aboutme$}))) {
  974:             my @folders=split('&',$env{'form.folderpath'});
  975:             if ((@folders > 2) || ($resurl ne '/adm/supplemental')) {
  976:                 my $esc_path=&escape(&HTML::Entities::encode(&escape($env{'form.folderpath'}),'<>&"'));
  977:                 &switch('','',7,4,'docs-22x22.png','Edit Folder','parms[_2]',
  978:                         "location.href='/adm/coursedocs?command=direct&forcesupplement=1&supppath=$esc_path'",
  979:                         'Folder/Page Content');
  980:             }
  981:         }
  982:     }
  983: 
  984: # End checking for items for about me page for users in a course
  985:     if ($docscrumbs) {
  986:         &Apache::lonhtmlcommon::clear_breadcrumb_tools();
  987:         &advtools_crumbs(@inlineremote);
  988:         return $editbutton;
  989:     } elsif ($env{'request.registered'}) {
  990:         return $editbutton;
  991:     } else {
  992:         if (ref($bread_crumbs) eq 'ARRAY') {
  993:             if (@inlineremote > 0) {
  994:                 if (ref($advtools) eq 'ARRAY') {
  995:                     @{$advtools} = @inlineremote;
  996:                 }
  997:             }
  998:             return;
  999:         } elsif (@inlineremote > 0) {
 1000:             &Apache::lonhtmlcommon::clear_breadcrumb_tools();
 1001:             &advtools_crumbs(@inlineremote);
 1002:             return   &Apache::lonhtmlcommon::scripttag('', 'start')
 1003:                    . &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
 1004:                    . &Apache::lonhtmlcommon::scripttag('', 'end');
 1005:         }
 1006:     }
 1007: }
 1008: 
 1009: sub advtools_crumbs {
 1010:     my @funcs = @_;
 1011:     if ($env{'request.noversionuri'} =~ m{^/adm/$match_domain/$match_username/aboutme$}) {
 1012:         &Apache::lonhtmlcommon::add_breadcrumb_tool(
 1013:             'advtools', @funcs[61,64,65,66,67,74]);
 1014:     } elsif ($env{'request.noversionuri'} !~ m{^/adm/(navmaps|viewclasslist)(\?|$)}) {
 1015:         &Apache::lonhtmlcommon::add_breadcrumb_tool(
 1016:             'advtools', @funcs[61,71,72,73,74,92]);
 1017:     } elsif ($env{'request.noversionuri'} eq '/adm/viewclasslist') {
 1018:         &Apache::lonhtmlcommon::add_breadcrumb_tool(
 1019:             'advtools', $funcs[61]);
 1020:     }
 1021:     return;
 1022: }
 1023: 
 1024: # ================================================================== Raw Config
 1025: 
 1026: sub clear {
 1027:     my ($row,$col)=@_;
 1028:     $inlineremote[10*$row+$col]='';
 1029:     return ''; 
 1030: }
 1031: 
 1032: # ============================================ Switch a button or create a link
 1033: # Switch acts on the javascript that is executed when a button is clicked.  
 1034: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
 1035: 
 1036: sub switch {
 1037:     my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak)=@_;
 1038:     $act=~s/\$uname/$uname/g;
 1039:     $act=~s/\$udom/$udom/g;
 1040:     $top=&mt($top);
 1041:     $bot=&mt($bot);
 1042:     $desc=&mt($desc);
 1043:     my $idx=10*$row+$col;
 1044:     $category_members{$cat}.=':'.$idx;
 1045: 
 1046: # Inline Menu
 1047:     if ($nobreak==2) { return ''; }
 1048:     my $text=$top.' '.$bot;
 1049:     $text=~s/\s*\-\s*//gs;
 1050: 
 1051:     my $pic=
 1052: 	   '<img alt="'.$text.'" src="'.
 1053: 	   &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
 1054: 	   '" align="'.($nobreak==3?'right':'left').'" class="LC_icon" />';
 1055:     if ($env{'browser.interface'} eq 'faketextual') {
 1056: # Main Menu
 1057: 	   if ($nobreak==3) {
 1058: 	       $inlineremote[$idx]="\n".
 1059: 		   '<td class="LC_menubuttons_text" align="right">'.$text.
 1060: 		   '</td><td align="left">'.
 1061: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
 1062: 	   } elsif ($nobreak) {
 1063: 	       $inlineremote[$idx]="\n<tr>".
 1064: 		   '<td align="left">'.
 1065: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td>
 1066:                     <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>';
 1067: 	   } else {
 1068: 	       $inlineremote[$idx]="\n<tr>".
 1069: 		   '<td align="left">'.
 1070: 		   '<a href="javascript:'.$act.';">'.$pic.
 1071: 		   '</a></td><td class="LC_menubuttons_text" colspan="3">'.
 1072: 		   '<a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$desc.'</span></a></td></tr>';
 1073: 	   }
 1074:     } else {
 1075: # Inline Menu
 1076:         my @tools = (93,91,81,82,83);
 1077:         unless ($env{'request.state'} eq 'construct') {
 1078:             push(@tools,63);
 1079:         }
 1080:         if (($env{'environment.icons'} eq 'iconsonly') && 
 1081:             (grep(/^$idx$/,@tools))) {
 1082:             $inlineremote[$idx] =
 1083:         '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.'</a>';
 1084:         } else {
 1085:             $inlineremote[$idx] =
 1086:        '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.
 1087:        '<span class="LC_menubuttons_inline_text">'.$top.'&nbsp;</span></a>';
 1088:         }
 1089:     }
 1090:     return '';
 1091: }
 1092: 
 1093: sub secondlevel {
 1094:     my $output='';
 1095:     my 
 1096:     ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_;
 1097:     if ($prt eq 'any') {
 1098: 	   $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1099:     } elsif ($prt=~/^r(\w+)/) {
 1100:         if ($rol eq $1) {
 1101:            $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1102:         }
 1103:     }
 1104:     return $output;
 1105: }
 1106: 
 1107: sub inlinemenu {
 1108:     undef(@inlineremote);
 1109:     undef(%category_members);
 1110: # calling rawconfig with "1" will evaluate mydesk.tab, even if there is no active remote control
 1111:     &rawconfig(1);
 1112:     my $output='<table><tr>';
 1113:     for (my $col=1; $col<=2; $col++) {
 1114:         $output.='<td class="LC_mainmenu_col_fieldset">';
 1115:         for (my $row=1; $row<=8; $row++) {
 1116:             foreach my $cat (keys(%category_members)) {
 1117:                if ($category_positions{$cat} ne "$col,$row") { next; }
 1118:                #$output.='<table><tr><td colspan="4" class="LC_menubuttons_category">'.&mt($category_names{$cat}).'</td></tr>';
 1119:                $output.='<div class="LC_Box LC_400Box">';
 1120: 	       $output.='<h3 class="LC_hcell">'.&mt($category_names{$cat}).'</h3>';
 1121:                $output.='<table>';
 1122:                my %active=();
 1123:                foreach my $menu_item (split(/\:/,$category_members{$cat})) {
 1124:                   if ($inlineremote[$menu_item]) {
 1125:                      $active{$menu_item}=1;
 1126:                   }
 1127:                }  
 1128:                foreach my $item (sort(keys(%active))) {
 1129:                   $output.=$inlineremote[$item];
 1130:                }
 1131:                $output.='</table>';
 1132:                $output.='</div>';
 1133:             }
 1134:          }
 1135:          $output.="</td>";
 1136:     }
 1137:     $output.="</tr></table>";
 1138:     return $output;
 1139: }
 1140: 
 1141: sub rawconfig {
 1142: #
 1143: # This evaluates mydesk.tab
 1144: # Need to add more positions and more privileges to deal with all
 1145: # menu items.
 1146: #
 1147:     my $textualoverride=shift;
 1148:     my $output='';
 1149:     return '' unless $textualoverride;
 1150:     my $uname=$env{'user.name'};
 1151:     my $udom=$env{'user.domain'};
 1152:     my $adv=$env{'user.adv'};
 1153:     my $show_course=&Apache::loncommon::show_course();
 1154:     my $author=$env{'user.author'};
 1155:     my $crs='';
 1156:     my $crstype='';
 1157:     if ($env{'request.course.id'}) {
 1158:        $crs='/'.$env{'request.course.id'};
 1159:        if ($env{'request.course.sec'}) {
 1160: 	   $crs.='_'.$env{'request.course.sec'};
 1161:        }
 1162:        $crs=~s/\_/\//g;
 1163:        $crstype = &Apache::loncommon::course_type();
 1164:     }
 1165:     my $pub=($env{'request.state'} eq 'published');
 1166:     my $con=($env{'request.state'} eq 'construct');
 1167:     my $rol=$env{'request.role'};
 1168:     my $requested_domain = $env{'request.role.domain'};
 1169:     foreach my $line (@desklines) {
 1170:         my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
 1171:         $prt=~s/\$uname/$uname/g;
 1172:         $prt=~s/\$udom/$udom/g;
 1173:         if ($prt =~ /\$crs/) {
 1174:             next unless ($env{'request.course.id'});
 1175:             next if ($crstype eq 'Community');
 1176:             $prt=~s/\$crs/$crs/g;
 1177:         } elsif ($prt =~ /\$cmty/) {
 1178:             next unless ($env{'request.course.id'});
 1179:             next if ($crstype ne 'Community');
 1180:             $prt=~s/\$cmty/$crs/g;
 1181:         }
 1182:         $prt=~s/\$requested_domain/$requested_domain/g;
 1183:         if ($category_names{$cat}!~/\w/) { $cat='oth'; }
 1184:         if ($pro eq 'clear') {
 1185: 	    $output.=&clear($row,$col);
 1186:         } elsif ($pro eq 'any') {
 1187:                $output.=&secondlevel(
 1188: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1189: 	} elsif ($pro eq 'smp') {
 1190:             unless ($adv) {
 1191:                $output.=&secondlevel(
 1192:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1193:             }
 1194:         } elsif ($pro eq 'adv') {
 1195:             if ($adv) {
 1196:                $output.=&secondlevel(
 1197: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1198:             }
 1199: 	} elsif ($pro eq 'shc') {
 1200:             if ($show_course) {
 1201:                $output.=&secondlevel(
 1202:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1203:             }
 1204:         } elsif ($pro eq 'nsc') {
 1205:             if (!$show_course) {
 1206:                $output.=&secondlevel(
 1207: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1208:             }
 1209:         } elsif (($pro=~/^p(\w+)/) && ($prt)) {
 1210:             my $priv = $1;
 1211:             if ($priv =~ /^mdc(Course|Community)/) {
 1212:                 if ($crstype eq $1) {
 1213:                     $priv = 'mdc';
 1214:                 } else {
 1215:                     next;
 1216:                 }
 1217:             }
 1218: 	    if (&Apache::lonnet::allowed($priv,$prt)) {
 1219:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1220:             }
 1221:         } elsif ($pro eq 'course')  {
 1222:             if (($env{'request.course.fn'}) && ($crstype ne 'Community')) {
 1223:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1224: 	    }
 1225:         } elsif ($pro eq 'community')  {
 1226:             if (($env{'request.course.fn'}) && ($crstype eq 'Community')) {
 1227:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1228:             }
 1229:         } elsif ($pro =~ /^courseenv_(.*)$/) {
 1230:             my $key = $1;
 1231:             if ($crstype ne 'Community') {
 1232:                 my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
 1233:                 if ($key eq 'canuse_pdfforms') {
 1234:                     if ($env{'request.course.id'} && $coursepref eq '') {
 1235:                         my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
 1236:                         $coursepref = $domdefs{'canuse_pdfforms'};
 1237:                     }
 1238:                 }
 1239:                 if ($coursepref) { 
 1240:                     $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1241:                 }
 1242:             }
 1243:         } elsif ($pro =~ /^communityenv_(.*)$/) {
 1244:             my $key = $1;
 1245:             if ($crstype eq 'Community') {
 1246:                 my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
 1247:                 if ($key eq 'canuse_pdfforms') {
 1248:                     if ($env{'request.course.id'} && $coursepref eq '') {
 1249:                         my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
 1250:                         $coursepref = $domdefs{'canuse_pdfforms'};
 1251:                     }
 1252:                 }
 1253:                 if ($coursepref) { 
 1254:                     $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1255:                 }
 1256:             }
 1257:         } elsif ($pro =~ /^course_(.*)$/) {
 1258:             # Check for permissions inside of a course
 1259:             if (($env{'request.course.id'}) && ($crstype ne 'Community') && 
 1260:                 (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
 1261:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
 1262:                  )) {
 1263:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1264: 	    }
 1265:         } elsif ($pro =~ /^community_(.*)$/) {
 1266:             # Check for permissions inside of a community
 1267:             if (($env{'request.course.id'}) && ($crstype eq 'Community') &&   
 1268:                 (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
 1269:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
 1270:                  )) {
 1271:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1272:             }
 1273:         } elsif ($pro eq 'author') {
 1274:             if ($author) {
 1275:                 if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
 1276:                     (($prt eq 'raa') && ($env{'request.role'}=~/^aa/)) || 
 1277:                     (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
 1278:                     # Check that we are on the correct machine
 1279:                     my $cadom=$requested_domain;
 1280:                     my $caname=$env{'user.name'};
 1281:                     if (($prt eq 'rca') || ($prt eq 'raa')) {
 1282: 		       ($cadom,$caname)=
 1283:                                ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
 1284:                     }                       
 1285:                     $act =~ s/\$caname/$caname/g;
 1286:                     $act =~ s/\$cadom/$cadom/g;
 1287:                     my $home = &Apache::lonnet::homeserver($caname,$cadom);
 1288: 		    my $allowed=0;
 1289: 		    my @ids=&Apache::lonnet::current_machine_ids();
 1290: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
 1291: 		    if ($allowed) {
 1292:                         $output.=&switch($caname,$cadom,
 1293:                                         $row,$col,$img,$top,$bot,$act,$desc,$cat);
 1294:                     }
 1295:                 }
 1296:             }
 1297:         } elsif ($pro eq 'tools') {
 1298:             my @tools = ('aboutme','blog','portfolio');
 1299:             if (grep(/^\Q$prt\E$/,@tools)) {
 1300:                 if (!&Apache::lonnet::usertools_access($env{'user.name'},
 1301:                                                        $env{'user.domain'},
 1302:                                                        $prt,undef,'tools')) {
 1303:                     $output.=&clear($row,$col);
 1304:                     next;
 1305:                 }
 1306:             } elsif (($prt eq 'reqcrsnsc') || ($prt eq 'reqcrsshc')) {
 1307:                 if (($prt eq 'reqcrsnsc') && ($show_course))   {
 1308:                     next;
 1309:                 }
 1310:                 if (($prt eq 'reqcrsshc') && (!$show_course)) {
 1311:                     next;
 1312:                 }
 1313:                 my $showreqcrs = &check_for_rcrs();
 1314:                 if (!$showreqcrs) {
 1315:                     $output.=&clear($row,$col);
 1316:                     next;
 1317:                 }
 1318:             }
 1319:             $prt='any';
 1320:             $output.=&secondlevel(
 1321:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1322:         }
 1323:     }
 1324:     return $output;
 1325: }
 1326: 
 1327: sub check_for_rcrs {
 1328:     my $showreqcrs = 0;
 1329:     my @reqtypes = ('official','unofficial','community');
 1330:     foreach my $type (@reqtypes) {
 1331:         if (&Apache::lonnet::usertools_access($env{'user.name'},
 1332:                                               $env{'user.domain'},
 1333:                                               $type,undef,'requestcourses')) {
 1334:             $showreqcrs = 1;
 1335:             last;
 1336:         }
 1337:     }
 1338:     if (!$showreqcrs) {
 1339:         foreach my $type (@reqtypes) {
 1340:             if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
 1341:                 $showreqcrs = 1;
 1342:                 last;
 1343:             }
 1344:         }
 1345:     }
 1346:     return $showreqcrs;
 1347: }
 1348: 
 1349: sub dc_popup_js {
 1350:     my %lt = &Apache::lonlocal::texthash(
 1351:                                           more => '(More ...)',
 1352:                                           less => '(Less ...)',
 1353:                                         );
 1354:     return <<"END";
 1355: 
 1356: function showCourseID() {
 1357:     document.getElementById('dccid').style.display='block';
 1358:     document.getElementById('dccid').style.textAlign='left';
 1359:     document.getElementById('dccid').style.textFace='normal';
 1360:     document.getElementById('dccidtext').innerHTML ='<a href="javascript:hideCourseID();" class="LC_menubuttons_link">$lt{'less'}</a>';
 1361:     return;
 1362: }
 1363: 
 1364: function hideCourseID() {
 1365:     document.getElementById('dccid').style.display='none';
 1366:     document.getElementById('dccidtext').innerHTML ='<a href="javascript:showCourseID()" class="LC_menubuttons_link">$lt{'more'}</a>';
 1367:     return;
 1368: }
 1369: 
 1370: END
 1371: 
 1372: }
 1373: 
 1374: sub countdown_toggle_js {
 1375:     return <<"END";
 1376: 
 1377: function toggleCountdown() {
 1378:     var countdownid = document.getElementById('duedatecountdown');
 1379:     var currstyle = countdownid.style.display;
 1380:     if (currstyle == 'inline') {
 1381:         countdownid.style.display = 'none';
 1382:         document.getElementById('ddcountcollapse').innerHTML='';
 1383:         document.getElementById('ddcountexpand').innerHTML='&#9668;&nbsp;';
 1384:     } else {
 1385:         countdownid.style.display = 'inline';
 1386:         document.getElementById('ddcountcollapse').innerHTML='&#9658;&nbsp;';
 1387:         document.getElementById('ddcountexpand').innerHTML='';
 1388:     }
 1389:     return;
 1390: }
 1391: 
 1392: END
 1393: }
 1394: 
 1395: sub utilityfunctions {
 1396:     my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
 1397:     if ($currenturl =~ m{^/adm/wrapper/ext/}
 1398:         && $env{'request.external.querystring'} ) {
 1399:             $currenturl .= ($currenturl=~/\?/)?'&':'?'.$env{'request.external.querystring'};
 1400:     }
 1401:     $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
 1402:     
 1403:     my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
 1404: 
 1405:     my $dc_popup_cid;
 1406:     if ($env{'user.adv'} && exists($env{'user.role.dc./'.
 1407:                         $env{'course.'.$env{'request.course.id'}.
 1408:                                  '.domain'}.'/'})) {
 1409:         $dc_popup_cid = &dc_popup_js();
 1410:     }
 1411: 
 1412:     my $start_page_annotate = 
 1413:         &Apache::loncommon::start_page('Annotator',undef,
 1414: 				       {'only_body' => 1,
 1415: 					'js_ready'  => 1,
 1416: 					'bgcolor'   => '#BBBBBB',
 1417: 					'add_entries' => {
 1418: 					    'onload' => 'javascript:document.goannotate.submit();'}});
 1419: 
 1420:     my $end_page_annotate = 
 1421:         &Apache::loncommon::end_page({'js_ready' => 1});
 1422: 
 1423:     my $jumptores = &Apache::lonhtmlcommon::javascript_jumpto_resource();
 1424: 
 1425:     my $esc_url=&escape($currenturl);
 1426:     my $esc_symb=&escape($currentsymb);
 1427: 
 1428:     my $countdown = &countdown_toggle_js();
 1429: 
 1430: return (<<ENDUTILITY)
 1431: 
 1432:     var currentURL=unescape("$esc_url");
 1433:     var reloadURL=unescape("$esc_url");
 1434:     var currentSymb=unescape("$esc_symb");
 1435: 
 1436: $dc_popup_cid
 1437: 
 1438: $jumptores
 1439: 
 1440: function gopost(url,postdata) {
 1441:    if (url!='') {
 1442:       this.document.server.action=url;
 1443:       this.document.server.postdata.value=postdata;
 1444:       this.document.server.command.value='';
 1445:       this.document.server.url.value='';
 1446:       this.document.server.symb.value='';
 1447:       this.document.server.submit();
 1448:    }
 1449: }
 1450: 
 1451: function gocmd(url,cmd) {
 1452:    if (url!='') {
 1453:       this.document.server.action=url;
 1454:       this.document.server.postdata.value='';
 1455:       this.document.server.command.value=cmd;
 1456:       this.document.server.url.value=currentURL;
 1457:       this.document.server.symb.value=currentSymb;
 1458:       this.document.server.submit();
 1459:    }
 1460: }
 1461: 
 1462: function gocstr(url,filename) {
 1463:     if (url == '/adm/cfile?action=delete') {
 1464:         this.document.cstrdelete.filename.value = filename
 1465:         this.document.cstrdelete.submit();
 1466:         return;
 1467:     }
 1468:     if (url == '/adm/printout') {
 1469:         this.document.cstrprint.postdata.value = filename
 1470:         this.document.cstrprint.curseed.value = 0;
 1471:         this.document.cstrprint.problemtype.value = 0;
 1472:         if (this.document.lonhomework) {
 1473:             if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
 1474:                 this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
 1475:             }
 1476:             if (this.document.lonhomework.problemtype) {
 1477: 		if (this.document.lonhomework.problemtype.value) {
 1478: 		    this.document.cstrprint.problemtype.value = 
 1479: 			this.document.lonhomework.problemtype.value;
 1480: 		} else if (this.document.lonhomework.problemtype.options) {
 1481: 		    for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
 1482: 			if (this.document.lonhomework.problemtype.options[i].selected) {
 1483: 			    if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') { 
 1484: 				this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
 1485: 				}
 1486: 			}
 1487: 		    }
 1488: 		}
 1489: 	    }
 1490: 	}
 1491:         this.document.cstrprint.submit();
 1492:         return;
 1493:     }
 1494:     if (url !='') {
 1495:         this.document.constspace.filename.value = filename;
 1496:         this.document.constspace.action = url;
 1497:         this.document.constspace.submit();
 1498:     }
 1499: }
 1500: 
 1501: function golist(url) {
 1502:    if (url!='' && url!= null) {
 1503:        currentURL = null;
 1504:        currentSymb= null;
 1505:        top.location.href=url;
 1506:    }
 1507: }
 1508: 
 1509: 
 1510: 
 1511: function catalog_info() {
 1512:    openMyModal(window.location.pathname+'.meta',500,400,'yes');
 1513: }
 1514: 
 1515: function chat_win() {
 1516:    lonchat=window.open('/res/adm/pages/chatroom.html',"LONchat",'height=320,width=480,resizable=yes,location=no,menubar=no,toolbar=no');
 1517: }
 1518: 
 1519: function group_chat(group) {
 1520:    var url = '/adm/groupchat?group='+group;
 1521:    var winName = 'LONchat_'+group;
 1522:    grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
 1523: }
 1524: 
 1525: function annotate() {
 1526:    w_Annotator_flag=1;
 1527:    annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
 1528:    annotator.document.write(
 1529:    '$start_page_annotate'
 1530:   +"<form name='goannotate' target='Annotator' method='post' "
 1531:   +"action='/adm/annotations'>"
 1532:   +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />"
 1533:   +"<\\/form>"
 1534:   +'$end_page_annotate');
 1535:    annotator.document.close();
 1536: }
 1537: 
 1538: function open_StoredLinks_Import(rat) {
 1539:    var newWin;
 1540:    if (rat) {
 1541:        newWin = window.open('/adm/wishlist?inhibitmenu=yes&mode=import&rat='+rat,
 1542:                             'wishlistImport','scrollbars=1,resizable=1,menubar=0');
 1543:    }
 1544:    else {
 1545:        newWin = window.open('/adm/wishlist?inhibitmenu=yes&mode=import',
 1546:                             'wishlistImport','scrollbars=1,resizable=1,menubar=0');
 1547:    }
 1548:    newWin.focus();
 1549: }
 1550: 
 1551: (function (\$) {
 1552:   \$(document).ready(function () {
 1553:     \$.single=function(a){return function(b){a[0]=b;return a}}(\$([1]));
 1554:     /*\@cc_on
 1555:       if (!window.XMLHttpRequest) {
 1556:         \$('.LC_hoverable').each(function () {
 1557:           this.attachEvent('onmouseenter', function (evt) { \$.single(evt.srcElement).addClass('hover'); });
 1558:           this.attachEvent('onmouseleave', function (evt) { \$.single(evt.srcElement).removeClass('hover'); });
 1559:         });
 1560:       }
 1561:     \@*/
 1562:   });
 1563: }(jQuery));
 1564: 
 1565: $countdown
 1566: 
 1567: ENDUTILITY
 1568: }
 1569: 
 1570: sub serverform {
 1571:     return(<<ENDSERVERFORM);
 1572: <form name="server" action="/adm/logout" method="post" target="_top">
 1573: <input type="hidden" name="postdata" value="none" />
 1574: <input type="hidden" name="command" value="none" />
 1575: <input type="hidden" name="url" value="none" />
 1576: <input type="hidden" name="symb" value="none" />
 1577: </form>
 1578: ENDSERVERFORM
 1579: }
 1580: 
 1581: sub constspaceform {
 1582:     return(<<ENDCONSTSPACEFORM);
 1583: <form name="constspace" action="/adm/logout" method="post" target="_top">
 1584: <input type="hidden" name="filename" value="" />
 1585: </form>
 1586: <form name="cstrdelete" action="/adm/cfile" method="post" target="_top">
 1587: <input type="hidden" name="action" value="delete" /> 
 1588: <input type="hidden" name="filename" value="" />
 1589: </form>
 1590: <form name="cstrprint" action="/adm/printout" target="_parent" method="post">
 1591: <input type="hidden" name="postdata" value="" />
 1592: <input type="hidden" name="curseed" value="" />
 1593: <input type="hidden" name="problemtype" value="" />
 1594: </form>
 1595: 
 1596: ENDCONSTSPACEFORM
 1597: }
 1598: 
 1599: sub hidden_button_check {
 1600:     if ( $env{'request.course.id'} eq ''
 1601:          || $env{'request.role.adv'} ) {
 1602: 
 1603:         return;
 1604:     }
 1605:     my $buttonshide = &Apache::lonnet::EXT('resource.0.buttonshide');
 1606:     return $buttonshide; 
 1607: }
 1608: 
 1609: sub roles_selector {
 1610:     my ($cdom,$cnum) = @_;
 1611:     my $crstype = &Apache::loncommon::course_type();
 1612:     my $now = time;
 1613:     my (%courseroles,%seccount,%courseprivs);
 1614:     my $is_cc;
 1615:     my ($js,$form,$switcher,$switchtext);
 1616:     my $ccrole;
 1617:     if ($crstype eq 'Community') {
 1618:         $ccrole = 'co';
 1619:     } else {
 1620:         $ccrole = 'cc';
 1621:     }
 1622:     my ($priv,$gotsymb,$destsymb);
 1623:     my $destinationurl = $ENV{'REQUEST_URI'};
 1624:     if ($destinationurl =~ /\?symb=/) {
 1625:         $gotsymb = 1;
 1626:     } elsif ($destinationurl =~ m{^/enc/}) {
 1627:         my $plainurl = &Apache::lonenc::unencrypted($destinationurl);
 1628:         if ($plainurl =~ /\?symb=/) {
 1629:             $gotsymb = 1;
 1630:         }
 1631:     }
 1632:     unless ($gotsymb) {
 1633:         $destsymb = &Apache::lonnet::symbread();
 1634:         if ($destsymb ne '') {
 1635:             $destsymb = &Apache::lonenc::check_encrypt($destsymb);
 1636:         }
 1637:     }
 1638:     my $reqprivs = &required_privs();
 1639:     if (ref($reqprivs) eq 'HASH') {
 1640:         my $destination = $destinationurl;
 1641:         $destination =~ s/(\?.*)$//;
 1642:         if (exists($reqprivs->{$destination})) {
 1643:             $priv = $reqprivs->{$destination};
 1644:         }
 1645:     }
 1646:     if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
 1647:         my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
 1648:         
 1649:         if ((($start) && ($start<0)) || 
 1650:             (($end) && ($end<$now))  ||
 1651:             (($start) && ($now<$start))) {
 1652:             $is_cc = 0;
 1653:         } else {
 1654:             $is_cc = 1;
 1655:         }
 1656:     }
 1657:     if ($is_cc) {
 1658:         &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs,$priv);
 1659:     } else {
 1660:         my %gotnosection;
 1661:         foreach my $item (keys(%env)) {
 1662:             if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
 1663:                 my $role = $1;
 1664:                 my $sec = $2;
 1665:                 next if ($role eq 'gr');
 1666:                 my ($start,$end) = split(/\./,$env{$item});
 1667:                 next if (($start && $start > $now) || ($end && $end < $now));
 1668:                 if ($sec eq '') {
 1669:                     if (!$gotnosection{$role}) {
 1670:                         $seccount{$role} ++;
 1671:                         $gotnosection{$role} = 1;
 1672:                     }
 1673:                 }
 1674:                 if ($priv ne '') {
 1675:                     my $cnumsec = $cnum;
 1676:                     if ($sec ne '') {
 1677:                         $cnumsec .= "/$sec";
 1678:                     }
 1679:                     $courseprivs{"$role./$cdom/$cnumsec./"} =
 1680:                         $env{"user.priv.$role./$cdom/$cnumsec./"};
 1681:                     $courseprivs{"$role./$cdom/$cnumsec./$cdom/"} =
 1682:                         $env{"user.priv.$role./$cdom/$cnumsec./$cdom/"};
 1683:                     $courseprivs{"$role./$cdom/$cnumsec./$cdom/$cnumsec"} =
 1684:                         $env{"user.priv.$role./$cdom/$cnumsec./$cdom/$cnumsec"};
 1685:                 }
 1686:                 if (ref($courseroles{$role}) eq 'ARRAY') {
 1687:                     if ($sec ne '') {
 1688:                         if (!grep(/^\Q$sec\E$/,@{$courseroles{$role}})) {
 1689:                             push(@{$courseroles{$role}},$sec);
 1690:                             $seccount{$role} ++;
 1691:                         }
 1692:                     }
 1693:                 } else {
 1694:                     @{$courseroles{$role}} = ();
 1695:                     if ($sec ne '') {
 1696:                         $seccount{$role} ++;
 1697:                         push(@{$courseroles{$role}},$sec);
 1698:                     }
 1699:                 }
 1700:             }
 1701:         }
 1702:     }
 1703:     $switchtext = &mt('Switch role');
 1704:     my @roles_order = ($ccrole,'in','ta','ep','ad','st');
 1705:     my $numdiffsec;
 1706:     if (keys(%seccount) == 1) {
 1707:         foreach my $key (keys(%seccount)) {
 1708:             $numdiffsec = $seccount{$key};
 1709:         }
 1710:     }
 1711:     if ((keys(%seccount) > 1) || ($numdiffsec > 1)) {
 1712:         my @submenu;
 1713:         $js = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles,\%courseprivs,$priv);
 1714:         $form = 
 1715:             '<form name="rolechooser" method="post" action="/adm/roles">'."\n".
 1716:             '  <input type="hidden" name="destinationurl" value="'.
 1717:             &HTML::Entities::encode($destinationurl).'" />'."\n".
 1718:             '  <input type="hidden" name="gotorole" value="1" />'."\n".
 1719:             '  <input type="hidden" name="selectrole" value="" />'."\n".
 1720:             '  <input type="hidden" name="switchrole" value="" />'."\n";
 1721:         if ($destsymb ne '') {
 1722:             $form .= '  <input type="hidden" name="destsymb" value="'.
 1723:                         &HTML::Entities::encode($destsymb).'" />'."\n";
 1724:         }
 1725:         $form .= '</form>'."\n";
 1726:         foreach my $role (@roles_order) {
 1727:             my $include;
 1728:             if (defined($courseroles{$role})) {
 1729:                 if ($env{'request.role'} =~ m{^\Q$role\E}) {
 1730:                     if ($seccount{$role} > 1) {
 1731:                         $include = 1;
 1732:                     }
 1733:                 } else {
 1734:                     $include = 1;
 1735:                 }
 1736:             }
 1737:             if ($include) {
 1738:                 push(@submenu,['javascript:adhocRole('."'$role'".')',
 1739:                                &Apache::lonnet::plaintext($role,$crstype)]);
 1740:             }
 1741:         }
 1742:         foreach my $role (sort(keys(%courseroles))) {
 1743:             if ($role =~ /^cr/) {
 1744:                 my $include;
 1745:                 if ($env{'request.role'} =~ m{^\Q$role\E}) {
 1746:                     if ($seccount{$role} > 1) {
 1747:                         $include = 1;
 1748:                     }
 1749:                 } else {
 1750:                     $include = 1; 
 1751:                 }
 1752:                 if ($include) {
 1753:                     push(@submenu,['javascript:adhocRole('."'$role'".')',
 1754:                                    &Apache::lonnet::plaintext($role)]);
 1755:                 }
 1756:             }
 1757:         }
 1758:         if (@submenu > 0) {
 1759:             $switcher = &create_submenu('','',$switchtext,\@submenu);
 1760:         }
 1761:     }
 1762:     return ($js,$form,$switcher);
 1763: }
 1764: 
 1765: sub get_all_courseroles {
 1766:     my ($cdom,$cnum,$courseroles,$seccount,$courseprivs) = @_;
 1767:     unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH') &&
 1768:             (ref($courseprivs) eq 'HASH')) {
 1769:         return;
 1770:     }
 1771:     my ($result,$cached) = 
 1772:         &Apache::lonnet::is_cached_new('getcourseroles',$cdom.'_'.$cnum);
 1773:     if (defined($cached)) {
 1774:         if (ref($result) eq 'HASH') {
 1775:             if ((ref($result->{'roles'}) eq 'HASH') && 
 1776:                 (ref($result->{'seccount'}) eq 'HASH') && 
 1777:                 (ref($result->{'privs'}) eq 'HASH')) {
 1778:                 %{$courseroles} = %{$result->{'roles'}};
 1779:                 %{$seccount} = %{$result->{'seccount'}};
 1780:                 %{$courseprivs} = %{$result->{'privs'}};
 1781:                 return;
 1782:             }
 1783:         }
 1784:     }
 1785:     my %gotnosection;
 1786:     my %adv_roles =
 1787:          &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
 1788:     foreach my $role (keys(%adv_roles)) {
 1789:         my ($urole,$usec) = split(/:/,$role);
 1790:         if (!$gotnosection{$urole}) {
 1791:             $seccount->{$urole} ++;
 1792:             $gotnosection{$urole} = 1;
 1793:         }
 1794:         if (ref($courseroles->{$urole}) eq 'ARRAY') {
 1795:             if ($usec ne '') {
 1796:                 if (!grep(/^Q$usec\E$/,@{$courseroles->{$urole}})) {
 1797:                     push(@{$courseroles->{$urole}},$usec);
 1798:                     $seccount->{$urole} ++;
 1799:                 }
 1800:             }
 1801:         } else {
 1802:             @{$courseroles->{$urole}} = ();
 1803:             if ($usec ne '') {
 1804:                 $seccount->{$urole} ++;
 1805:                 push(@{$courseroles->{$urole}},$usec);
 1806:             }
 1807:         }
 1808:         my $area = '/'.$cdom.'/'.$cnum;
 1809:         if ($usec ne '') {
 1810:             $area .= '/'.$usec;
 1811:         }
 1812:         if ($role =~ /^cr\//) {
 1813:             &Apache::lonnet::custom_roleprivs($courseprivs,$urole,$cdom,$cnum,$urole.'.'.$area,$area);
 1814:         } else {
 1815:             &Apache::lonnet::standard_roleprivs($courseprivs,$urole,$cdom,$urole.'.'.$area,$cnum,$area);
 1816:         }
 1817:     }
 1818:     my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum,['st']);
 1819:     @{$courseroles->{'st'}} = ();
 1820:     &Apache::lonnet::standard_roleprivs($courseprivs,'st',$cdom,"st./$cdom/$cnum",$cnum,"/$cdom/$cnum");
 1821:     if (keys(%sections_count) > 0) {
 1822:         push(@{$courseroles->{'st'}},keys(%sections_count));
 1823:         $seccount->{'st'} = scalar(keys(%sections_count));
 1824:     }
 1825:     $seccount->{'st'} ++; # Increment for a section-less student role.  
 1826:     my $rolehash = {
 1827:                      'roles'    => $courseroles,
 1828:                      'seccount' => $seccount,
 1829:                      'privs'    => $courseprivs,
 1830:                    };
 1831:     &Apache::lonnet::do_cache_new('getcourseroles',$cdom.'_'.$cnum,$rolehash);
 1832:     return;
 1833: }
 1834: 
 1835: sub jump_to_role {
 1836:     my ($cdom,$cnum,$seccount,$courseroles,$courseprivs,$priv) = @_;
 1837:     my %lt = &Apache::lonlocal::texthash(
 1838:                 this => 'This role has section(s) associated with it.',
 1839:                 ente => 'Enter a specific section.',
 1840:                 orlb => 'Enter a specific section, or leave blank for no section.',
 1841:                 avai => 'Available sections are:',
 1842:                 youe => 'You entered an invalid section choice:',
 1843:                 plst => 'Please try again.',
 1844:                 role => 'The role you selected is not permitted to view the current page.',
 1845:                 swit => 'Switch role, but display Main Menu page instead?',
 1846:     );
 1847:     my $js;
 1848:     if (ref($courseroles) eq 'HASH') {
 1849:         $js = '    var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n". 
 1850:               '    var numsec = new Array();'."\n".
 1851:               '    var rolesections = new Array();'."\n".
 1852:               '    var rolenames = new Array();'."\n".
 1853:               '    var roleseclist = new Array();'."\n";
 1854:         my @items = keys(%{$courseroles});
 1855:         for (my $i=0; $i<@items; $i++) {
 1856:             $js .= '    rolenames['.$i.'] = "'.$items[$i].'";'."\n";
 1857:             my ($secs,$secstr);
 1858:             if (ref($courseroles->{$items[$i]}) eq 'ARRAY') {
 1859:                 my @sections = sort { $a <=> $b } @{$courseroles->{$items[$i]}};
 1860:                 $secs = join('","',@sections);
 1861:                 $secstr = join(', ',@sections);
 1862:             }
 1863:             $js .= '    rolesections['.$i.'] = new Array("'.$secs.'");'."\n".
 1864:                    '    roleseclist['.$i.'] = "'.$secstr.'";'."\n".
 1865:                    '    numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n";
 1866:         }
 1867:     }
 1868:     my $checkroles = 0;
 1869:     if ($priv && ref($courseprivs) eq 'HASH') {
 1870:         my (%disallowed,%allowed,@disallow);
 1871:         foreach my $role (sort(keys(%{$courseprivs}))) {
 1872:             my $trole;
 1873:             if ($role =~ m{^(.+?)\Q./$cdom/$cnum\E}) {
 1874:                 $trole = $1;
 1875:             }
 1876:             if (($trole ne '') && ($trole ne 'cm')) {
 1877:                 if ($courseprivs->{$role} =~ /\Q:$priv\E($|:|\&\w+)/) {
 1878:                     $allowed{$trole} = 1;
 1879:                 } else {
 1880:                     $disallowed{$trole} = 1;
 1881:                 }
 1882:             }
 1883:         }
 1884:         foreach my $trole (keys(%disallowed)) {
 1885:             unless ($allowed{$trole}) {
 1886:                 push(@disallow,$trole);
 1887:             }
 1888:         }
 1889:         if (@disallow > 0) {
 1890:             $checkroles = 1;
 1891:             $js .= "    var disallow = new Array('".join("','",@disallow)."');\n".
 1892:                    "    var rolecheck = 1;\n";
 1893:         }
 1894:     }
 1895:     if (!$checkroles) {
 1896:         $js .=  "    var disallow = new Array();\n".
 1897:                 "    rolecheck = 0;\n";
 1898:     }
 1899:     return <<"END";
 1900: <script type="text/javascript">
 1901: //<![CDATA[
 1902: function adhocRole(newrole) {
 1903:     $js
 1904:     if (newrole == '') {
 1905:         return;
 1906:     } 
 1907:     var fullrole = newrole+'./$cdom/$cnum';
 1908:     var selidx = '';
 1909:     for (var i=0; i<rolenames.length; i++) {
 1910:         if (rolenames[i] == newrole) {
 1911:             selidx = i;
 1912:         }
 1913:     }
 1914:     if (rolecheck > 0) {
 1915:         for (var i=0; i<disallow.length; i++) {
 1916:             if (disallow[i] == newrole) {
 1917:                 if (confirm("$lt{'role'}\\n$lt{'swit'}")) {
 1918:                     document.rolechooser.destinationurl.value = '/adm/menu';
 1919:                 } else {
 1920:                     return;
 1921:                 }
 1922:             }
 1923:         }
 1924:     }
 1925:     var secok = 1;
 1926:     var secchoice = '';
 1927:     if (selidx >= 0) {
 1928:         if (numsec[selidx] > 1) {
 1929:             secok = 0;
 1930:             var numrolesec = rolesections[selidx].length;
 1931:             var msgidx = numsec[selidx] - numrolesec;
 1932:             secchoice = prompt("$lt{'this'} "+secpick[msgidx]+"\\n$lt{'avai'} "+roleseclist[selidx],"");
 1933:             if (secchoice == '') {
 1934:                 if (msgidx > 0) {
 1935:                     secok = 1;
 1936:                 }
 1937:             } else {
 1938:                 for (var j=0; j<rolesections[selidx].length; j++) {
 1939:                     if (rolesections[selidx][j] == secchoice) {
 1940:                         secok = 1;
 1941:                     }
 1942:                 }
 1943:             }
 1944:         } else {
 1945:             if (rolesections[selidx].length == 1) {
 1946:                 secchoice = rolesections[selidx][0];
 1947:             }
 1948:         }
 1949:     }
 1950:     if (secok == 1) {
 1951:         if (secchoice != '') {
 1952:             fullrole += '/'+secchoice;
 1953:         }
 1954:     } else {
 1955:         if (secchoice != null) {
 1956:             alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}");
 1957:         }
 1958:         return;
 1959:     }
 1960:     if (fullrole == "$env{'request.role'}") {
 1961:         return;
 1962:     }
 1963:     itemid = retrieveIndex('gotorole');
 1964:     if (itemid != -1) {
 1965:         document.rolechooser.elements[itemid].name = fullrole;
 1966:     }
 1967:     document.rolechooser.switchrole.value = fullrole;
 1968:     document.rolechooser.selectrole.value = '1';
 1969:     document.rolechooser.submit();
 1970:     return;
 1971: }
 1972: 
 1973: function retrieveIndex(item) {
 1974:     for (var i=0;i<document.rolechooser.elements.length;i++) {
 1975:         if (document.rolechooser.elements[i].name == item) {
 1976:             return i;
 1977:         }
 1978:     }
 1979:     return -1;
 1980: }
 1981: // ]]>
 1982: </script>
 1983: END
 1984: }
 1985: 
 1986: sub required_privs {
 1987:     my $privs =  {
 1988:              '/adm/parmset'      => 'opa',
 1989:              '/adm/courseprefs'  => 'opa',
 1990:              '/adm/whatsnew'     => 'whn',
 1991:              '/adm/populate'     => 'cst',
 1992:              '/adm/trackstudent' => 'vsa',
 1993:              '/adm/statistics'   => 'vgr',
 1994:              '/adm/setblock'     => 'dcm',
 1995:              '/adm/coursedocs'   => 'mdc',
 1996:            };
 1997:     unless ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'spreadsheet') {
 1998:         $privs->{'/adm/classcalc'}   = 'vgr',
 1999:         $privs->{'/adm/assesscalc'}  = 'vgr',
 2000:         $privs->{'/adm/studentcalc'} = 'vgr';
 2001:     }
 2002:     return $privs;
 2003: }
 2004: 
 2005: sub countdown_timer {
 2006:     if (($env{'request.course.id'}) && ($env{'request.symb'} ne '') &&
 2007:         ($env{'request.filename'}=~/$LONCAPA::assess_re/)) {
 2008:         my ($type,$hastimeleft,$slothastime);
 2009:         my $now = time;
 2010:         if ($env{'request.filename'} =~ /\.task$/) {
 2011:             $type = 'Task';
 2012:         } else {
 2013:             $type = 'problem';
 2014:         }
 2015:         my ($status,$accessmsg,$slot_name,$slot) =
 2016:             &Apache::lonhomework::check_slot_access('0',$type);
 2017:         if ($slot_name ne '') {
 2018:             if (ref($slot) eq 'HASH') {
 2019:                 if (($slot->{'starttime'} < $now) &&
 2020:                     ($slot->{'endtime'} > $now)) {
 2021:                     $slothastime = 1;
 2022:                 }
 2023:             }
 2024:         }
 2025:         if ($status ne 'CAN_ANSWER') {
 2026:             return;
 2027:         }
 2028:         my $duedate = &Apache::lonnet::EXT("resource.0.duedate");
 2029:         my @interval=&Apache::lonnet::EXT("resource.0.interval");
 2030:         if (@interval > 1) {
 2031:             my $first_access=&Apache::lonnet::get_first_access($interval[1]);
 2032:             if ($first_access > 0) {
 2033:                 if ($first_access+$interval[0] > time) {
 2034:                     $hastimeleft = 1;
 2035:                 }
 2036:             }
 2037:         }
 2038:         if (($duedate && $duedate > time) ||
 2039:             (!$duedate && $hastimeleft) ||
 2040:             ($slot_name ne '' && $slothastime)) {
 2041:             my ($collapse,$expand,$alttxt,$title,$currdisp);
 2042:             if ((@interval > 1 && $hastimeleft) ||
 2043:                 ($type eq 'Task' && $slothastime)) {
 2044:                 $currdisp = 'inline';
 2045:                 $collapse = '&#9658;&nbsp;';
 2046:             } else {
 2047:                 $currdisp = 'none';
 2048:                 $expand = '&#9668;&nbsp;';
 2049:             }
 2050:             unless ($env{'environment.icons'} eq 'iconsonly') {
 2051:                 $alttxt = &mt('Timer');
 2052:                 $title = $alttxt.'&nbsp;';
 2053:             }
 2054:             my $desc = &mt('Countdown to due date/time');
 2055:             return <<END;
 2056: 
 2057: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
 2058: <span id="ddcountcollapse" class="LC_menubuttons_inline_text">
 2059: $collapse
 2060: </span></a>
 2061: <span id="duedatecountdown" class="LC_menubuttons_inline_text" style="display: $currdisp;"></span>
 2062: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
 2063: <span id="ddcountexpand" class="LC_menubuttons_inline_text" >$expand</span>
 2064: <img src="/res/adm/pages/timer.png" title="$desc" class="LC_icon" alt="$alttxt" /><span class="LC_menubuttons_inline_text">$title</span></a>
 2065: END
 2066:         }
 2067:     }
 2068:     return;
 2069: }
 2070: 
 2071: # ================================================================ Main Program
 2072: 
 2073: BEGIN {
 2074:     if (! defined($readdesk)) {
 2075:         {
 2076:             my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
 2077:             if ( CORE::open( my $config,"<$tabfile") ) {
 2078:                 while (my $configline=<$config>) {
 2079:                     $configline=(split(/\#/,$configline))[0];
 2080:                     $configline=~s/^\s+//;
 2081:                     chomp($configline);
 2082:                     if ($configline=~/^cat\:/) {
 2083:                         my @entries=split(/\:/,$configline);
 2084:                         $category_positions{$entries[2]}=$entries[1];
 2085:                         $category_names{$entries[2]}=$entries[3];
 2086:                     } elsif ($configline=~/^prim\:/) {
 2087:                         my @entries = (split(/\:/, $configline))[1..5];
 2088:                         push(@primary_menu,\@entries);
 2089:                     } elsif ($configline=~/^primsub\:/) {
 2090:                         my ($parent,@entries) = (split(/\:/, $configline))[1..4];
 2091:                         push(@{$primary_submenu{$parent}},\@entries);
 2092:                     } elsif ($configline=~/^scnd\:/) {
 2093:                         my @entries = (split(/\:/, $configline))[1..5];
 2094:                         push(@secondary_menu,\@entries);
 2095:                     } elsif ($configline) {
 2096:                         push(@desklines,$configline);
 2097:                     }
 2098:                 }
 2099:                 CORE::close($config);
 2100:             }
 2101:         }
 2102:         $readdesk='done';
 2103:     }
 2104: }
 2105: 
 2106: 1;
 2107: __END__
 2108: 

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