File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.369.2.18: download - view: text, annotated - select for diffs
Fri Aug 3 22:38:35 2012 UTC (11 years, 10 months ago) by raeburn
Branches: version_2_11_X
- For 2.11.
  - Modify changes in 1.1075.2.12 so CSTR button is available for editing
    a resource in course context, where uses has au/ca role for resource's
    authorship.
  - Prevent javascript error for Folder/Page Content item when remote control
    is active.

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

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