File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.369.2.17: download - view: text, annotated - select for diffs
Fri Aug 3 17:35:32 2012 UTC (11 years, 10 months ago) by raeburn
Branches: version_2_11_X
- For 2.11.
  - Remote Control retained in 2.11.
  - Reverse part of changes in loncommon.pm rev 1.949, 1.953, 1.962, 1.964.
  - Reverse part of changes in lonmenu.pm rev 1.316, 1.318, 1.321.
  - Reverse part of changes in lonroles.pm rev 1.245.

    1: # The LearningOnline Network with CAPA
    2: # Routines to control the menu
    3: #
    4: # $Id: lonmenu.pm,v 1.369.2.17 2012/08/03 17:35:32 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:     unless ( ($env{'request.noversionuri'}!~m{^/(res/)*adm/})
  573:                        || ($forcereg)) {
  574:         unless ($noremote) {
  575: # Not registered, graphical
  576:            return (<<ENDDONOTREGTHIS);
  577: 
  578: <script type="text/javascript">
  579: // <![CDATA[
  580: // BEGIN LON-CAPA Internal
  581: var swmenu=null;
  582: 
  583:     function LONCAPAreg() {
  584:           swmenu=$reopen
  585:           $timesync
  586:           swmenu.currentStale=1;
  587:           swmenu.clearbut(2,1);
  588:           swmenu.clearbut(2,3);
  589:           swmenu.clearbut(8,1);
  590:           swmenu.clearbut(8,2);
  591:           swmenu.clearbut(8,3);
  592:           if (swmenu.currentURL) {
  593:              swmenu.switchbutton
  594:               (3,1,'reload.gif','return','location','go(currentURL)');
  595:           } else {
  596:               swmenu.clearbut(3,1);
  597:           }
  598:     }
  599: 
  600:     function LONCAPAstale() {
  601:     }
  602: 
  603: // END LON-CAPA Internal
  604: // ]]>
  605: </script>
  606: ENDDONOTREGTHIS
  607: 
  608:         }
  609:         return '';
  610:     }
  611: 
  612: # -- This applies to homework problems for users with grading privileges
  613: 	my $crs='/'.$env{'request.course.id'};
  614: 	if ($env{'request.course.sec'}) {
  615: 	    $crs.='_'.$env{'request.course.sec'};
  616: 	}
  617: 	$crs=~s/\_/\//g;
  618: 
  619:         my $hwkadd='';
  620:         if ($env{'request.symb'} ne '' &&
  621: 	    $env{'request.filename'}=~/$LONCAPA::assess_re/) {
  622: 	    if (&Apache::lonnet::allowed('mgr',$crs)) {
  623: 		$hwkadd.=&switch('','',7,2,'pgrd.png','Content Grades','grades[_4]',
  624:                        "gocmd('/adm/grades','gradingmenu')",
  625:                        'Content Grades');
  626:             } elsif (&Apache::lonnet::allowed('vgr',$crs)) {
  627: 		$hwkadd.=&switch('','',7,2,'subm.png','Content Submissions','missions[_1]',
  628:                        "gocmd('/adm/grades','submission')",
  629: 		       'Content Submissions');
  630:             }
  631: 	}
  632: 	if ($env{'request.symb'} ne '' &&
  633: 	    &Apache::lonnet::allowed('opa',$crs)) {
  634: 	    $hwkadd.=&switch('','',7,3,'pparm.png','Content Settings','parms[_2]',
  635: 			     "gocmd('/adm/parmset','set')",
  636: 			     'Content Settings');
  637: 	}
  638:         if ($env{'request.symb'}=~/^uploaded/ &&
  639:             &Apache::lonnet::allowed('mdc',$crs)) {
  640:             $hwkadd.=&switch('','',7,4,'docs.png','Folder/Page Content','parms[_2]',
  641:                              "gocmd('/adm/coursedocs','direct')",
  642:                              'Folder/Page Content');
  643:         }
  644: # -- End Homework
  645:         ###
  646:         ### Determine whether or not to display the 'cstr' button for this
  647:         ### resource
  648:         ###
  649:         my $editbutton = '';
  650:         my $noeditbutton = 1;
  651:         my ($cnum,$cdom);
  652:         if ($env{'request.course.id'}) {
  653:             $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
  654:             $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  655:         }
  656:         if ($env{'user.author'}) {
  657:             if ($env{'request.role'}=~/^(aa|ca|au)/) {
  658: #
  659: # We have the role of an author
  660: #
  661:                 # Set defaults for authors
  662:                 my ($top,$bottom) = ('con-','struct');
  663:                 my $action = "go('/priv/".$env{'user.domain'}.'/'.$env{'user.name'}."');";
  664:                 my $cadom  = $env{'request.role.domain'};
  665:                 my $caname = $env{'user.name'};
  666:                 my $desc = "Enter my construction space";
  667:                 # Set defaults for co-authors
  668:                 if ($env{'request.role'} =~ /^ca/) { 
  669:                     ($cadom,$caname)=($env{'request.role'}=~/($match_domain)\/($match_username)$/);
  670:                     ($top,$bottom) = ('co con-','struct');
  671:                     $action = "go('/priv/".$cadom.'/'.$caname."');";
  672:                     $desc = "Enter construction space as co-author";
  673:                 } elsif ($env{'request.role'} =~ /^aa/) {
  674:                     ($cadom,$caname)=($env{'request.role'}=~/($match_domain)\/($match_username)$/);
  675:                     ($top,$bottom) = ('co con-','struct');
  676:                     $action = "go('/priv/".$cadom.'/'.$caname."');";
  677:                     $desc = "Enter construction space as assistant co-author";
  678:                 }
  679:                 # Check that we are on the correct machine
  680:                 my $home = &Apache::lonnet::homeserver($caname,$cadom);
  681: 		my $allowed=0;
  682: 		my @ids=&Apache::lonnet::current_machine_ids();
  683: 		foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
  684: 		if (!$allowed) {
  685: 		    $editbutton=&switch('','',6,1,$top,,$bottom,$action,$desc);
  686:                     $noeditbutton = 0;
  687:                 }
  688:             }
  689: #
  690: # We are an author for some stuff, but currently do not have the role of author.
  691: # Figure out if we have authoring privileges for the resource we are looking at.
  692: # This should maybe become a privilege check in lonnet
  693: #
  694:             ##
  695:             ## Determine if user can edit url.
  696:             ##
  697:             my $cfile='';
  698:             my $cfuname='';
  699:             my $cfudom='';
  700:             my $uploaded;
  701:             my $switchserver='';
  702:             my $home;
  703:             if ($env{'request.filename'}) {
  704:                 my $file=&Apache::lonnet::declutter($env{'request.filename'});
  705:                 if (defined($cnum) && defined($cdom)) {
  706:                     $uploaded = &is_course_upload($file,$cnum,$cdom);
  707:                 }
  708:                 if (!$uploaded) {
  709: 
  710:                     $file=~s{^(priv/$match_domain/$match_username)}{/$1};
  711:                     $file=~s{^($match_domain/$match_username)}{/priv/$1};
  712: 
  713:                     # Check that the user has permission to edit this resource
  714:                     my $setpriv = 1;
  715:                     ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$setpriv);
  716:                     if (defined($cfudom)) {
  717: 		        $home=&Apache::lonnet::homeserver($cfuname,$cfudom);
  718: 		        my $allowed=0;
  719: 		        my @ids=&Apache::lonnet::current_machine_ids();
  720: 		        foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
  721: 		        if ($allowed) {
  722:                             $cfile=$file;
  723:                         } else {
  724:                             $switchserver=$file;
  725:                         }
  726:                     }
  727:                 }
  728:             }
  729:             # Finally, turn the button on or off
  730:             if (($cfile || $switchserver) && !$const_space) {
  731:                 my $nocrsedit;
  732:                 # Suppress display where CC has switched to student role.
  733:                 if ($env{'request.course.id'}) {
  734:                     unless(&Apache::lonnet::allowed('mdc',
  735:                                                     $env{'request.course.id'})) {
  736:                         $nocrsedit = 1;
  737:                     }
  738:                 }
  739:                 if ($nocrsedit) {
  740:                     $editbutton=&clear(6,1);
  741:                 } else {
  742:                     my $bot = "go('$cfile')";
  743:                     if ($switchserver) {
  744:                         if ( $env{'request.symb'} && $env{'request.course.id'} ) {
  745:                             $cfile = '/adm/switchserver?otherserver='.$home.'&amp;role='.
  746:                                      &HTML::Entities::encode($env{'request.role'},'"<>&').'&amp;symb='.
  747:                                      &HTML::Entities::encode($env{'request.symb'},'"<>&');
  748:                             $bot = "need_switchserver('$cfile');";
  749:                         }
  750:                     }
  751:                     $editbutton=&switch
  752:                        ('','',6,1,'pcstr.png','Edit','resource[_2]',
  753:                         $bot,"Edit this resource");
  754:                     $noeditbutton = 0;
  755:                 }
  756:             } elsif ($editbutton eq '') {
  757:                 $editbutton=&clear(6,1);
  758:             }
  759:         }
  760:         if (($noeditbutton) && ($env{'request.filename'})) { 
  761:             if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
  762:                 my $file=&Apache::lonnet::declutter($env{'request.filename'});
  763:                 if (defined($cnum) && defined($cdom)) {
  764:                     if (&is_course_upload($file,$cnum,$cdom)) {
  765:                         my $cfile = &edit_course_upload($file,$cnum,$cdom);
  766:                         if ($cfile) {
  767:                             $editbutton=&switch
  768:                                         ('','',6,1,'pcstr.png','Edit',
  769:                                          'resource[_2]',"go('".$cfile."');",
  770:                                          'Edit this resource');
  771:                         }
  772:                     }
  773:                 }
  774:             }
  775:         }
  776:         if ($env{'request.course.id'}) {
  777:             if ($resurl eq "public/$cdom/$cnum/syllabus") {
  778:                 if ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ /\w/) {
  779:                     if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
  780:                         $editbutton=&switch('','',6,1,'pcstr.png','Edit',
  781:                                             'resource[_2]',
  782:                                             "go('/adm/courseprefs?phase=display&actions=courseinfo')",
  783:                                             'Edit this resource');
  784:                     }
  785:                 }
  786:             }
  787:         }
  788:         ###
  789:         ###
  790: # Prepare the rest of the buttons
  791:         my ($menuitems,$got_prt,$got_wishlist);
  792:         if ($const_space) {
  793: #
  794: # We are in construction space
  795: #
  796: 
  797:             my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
  798: 	    my ($udom,$uname,$thisdisfn) =
  799: 		($env{'request.filename'}=~m{^\Q$londocroot/priv/\E([^/]+)/([^/]+)/(.*)$});
  800:             my $currdir = '/priv/'.$udom.'/'.$uname.'/'.$thisdisfn;
  801:             if ($currdir =~ m-/$-) {
  802:                 $is_const_dir = 1;
  803:             } else {
  804:                 $currdir =~ s|[^/]+$||;
  805: 		my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn);
  806: 		my $esc_currdir = &Apache::loncommon::escape_single($currdir);
  807: #
  808: # Probably should be in mydesk.tab
  809: #
  810:                 $menuitems=(<<ENDMENUITEMS);
  811: s&6&1&list.png&Directory&dir[_1]&golist('$esc_currdir')&List current directory
  812: s&6&2&rtrv.png&Retrieve&version[_1]&gocstr('/adm/retrieve','/priv/$udom/$uname/$cleandisfn')&Retrieve old version
  813: s&6&3&pub.png&Publish&resource[_3]&gocstr('/adm/publish','/priv/$udom/$uname/$cleandisfn')&Publish this resource
  814: s&7&1&del.png&Delete&resource[_2]&gocstr('/adm/cfile?action=delete','/priv/$udom/$uname/$cleandisfn')&Delete this resource
  815: s&7&2&prt.png&Print&printout[_1]&gocstr('/adm/printout','/priv/$udom/$uname/$cleandisfn')&Prepare a printable document
  816: ENDMENUITEMS
  817:             }
  818:                 if (ref($bread_crumbs) eq 'ARRAY') {
  819:                     &Apache::lonhtmlcommon::clear_breadcrumbs();
  820:                     foreach my $crumb (@{$bread_crumbs}){
  821:                         &Apache::lonhtmlcommon::add_breadcrumb($crumb);
  822:                     }
  823:                 }
  824:         } elsif ( defined($env{'request.course.id'}) && 
  825: 		 $env{'request.symb'} ne '' ) {
  826: #
  827: # We are in a course and looking at a registered URL
  828: # Should probably be in mydesk.tab
  829: #
  830: 	    $menuitems=(<<ENDMENUITEMS);
  831: c&3&1
  832: s&2&1&back.png&&&gopost('/adm/flip','back:'+currentURL)&Previous content resource&&1
  833: s&2&3&forw.png&&&gopost('/adm/flip','forward:'+currentURL)&Next content resource&&3
  834: c&6&3
  835: c&8&1
  836: c&8&2
  837: s&8&3&prt.png&Print&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
  838: ENDMENUITEMS
  839:             $got_prt = 1;
  840:             if (($env{'user.adv'}) && ($env{'request.uri'} =~ /^\/res/)
  841:                 && (!$env{'request.enc'})) {
  842:                 # wishlist is only available for users with access to resource-pool
  843:                 # and links can only be set for resources within the resource-pool
  844:                 $menuitems .= (<<ENDMENUITEMS);
  845: 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
  846: ENDMENUITEMS
  847:                 $got_wishlist = 1;
  848:             }
  849: 
  850: my $currentURL = &Apache::loncommon::get_symb();
  851: my ($symb_old,$symb_old_enc) = &Apache::loncommon::clean_symb($currentURL);
  852: my $annotation = &Apache::loncommon::get_annotation($symb_old,$symb_old_enc);
  853: $menuitems.="s&9&3&";
  854: if(length($annotation) > 0){
  855: 	$menuitems.="anot2.png";
  856: }else{
  857: 	$menuitems.="anot.png";
  858: }
  859: $menuitems.="&Notes&&annotate()&";
  860: $menuitems.="Make notes and annotations about this resource&&1\n";
  861: 
  862:             unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|viewclasslist|portfolio)(\?|$)/) {
  863: 		if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/}) && ($env{'request.noversionuri'} !~ m{^/uploaded/$match_domain/$match_courseid/docs/})) {
  864: 		    $menuitems.=(<<ENDREALRES);
  865: s&6&3&catalog.png&Info&info[_1]&catalog_info()&Show Metadata
  866: ENDREALRES
  867:                 }
  868:                 unless ($env{'request.noversionuri'} =~ m{^/uploaded/$match_domain/$match_courseid/docs/}) {
  869: 	            $menuitems.=(<<ENDREALRES);
  870: s&8&1&eval.png&Evaluate&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
  871: ENDREALRES
  872:                 }
  873:                 $menuitems.=(<<ENDREALRES);
  874: 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
  875: ENDREALRES
  876: 	    }
  877:         }
  878: 	if ($env{'request.uri'} =~ /^\/res/) {
  879:             unless ($got_prt) {
  880: 	        $menuitems .= (<<ENDMENUITEMS);
  881: s&8&3&prt.png&Print&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
  882: ENDMENUITEMS
  883:                 $got_prt = 1;
  884:             }
  885:             unless ($got_wishlist) {
  886:                 if (($env{'user.adv'}) && (!$env{'request.enc'})) {
  887:                     # wishlist is only available for users with access to resource-pool
  888:                     $menuitems .= (<<ENDMENUITEMS);
  889: 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
  890: ENDMENUITEMS
  891:                     $got_wishlist = 1;
  892:                 }
  893:             }
  894: 	}
  895:         my $buttons='';
  896:         foreach (split(/\n/,$menuitems)) {
  897: 	    my ($command,@rest)=split(/\&/,$_);
  898:             my $idx=10*$rest[0]+$rest[1];
  899:             if (&hidden_button_check() eq 'yes') {
  900:                 if ($idx == 21 ||$idx == 23) {
  901:                     $buttons.=&switch('','',@rest);
  902:                 } else {
  903:                     $buttons.=&clear(@rest);
  904:                 }
  905:             } else {  
  906:                 if ($command eq 's') {
  907: 	            $buttons.=&switch('','',@rest);
  908:                 } else {
  909:                     $buttons.=&clear(@rest);
  910:                 }
  911:             }
  912:         }
  913:         if ($noremote) {
  914: 	    my $addremote=0;
  915: 	    foreach (@inlineremote) { if ($_ ne '') { $addremote=1; last;} }
  916:             if ($addremote) {
  917: 
  918:                 &Apache::lonhtmlcommon::clear_breadcrumb_tools();
  919: 
  920:                 &Apache::lonhtmlcommon::add_breadcrumb_tool(
  921:                     'navigation', @inlineremote[21,23]);
  922: 
  923:                 my $countdown = &countdown_timer();
  924:                 if (&hidden_button_check() eq 'yes') {
  925:                     if ($countdown) {
  926:                         &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$countdown);
  927:                     }
  928:                 } else {
  929:                     my @tools = @inlineremote[93,91,81,82,83];
  930:                     if ($countdown) {
  931:                         unshift(@tools,$countdown);
  932:                     }
  933:                     &Apache::lonhtmlcommon::add_breadcrumb_tool(
  934:                         'tools',@tools);
  935: 
  936:                     #publish button in construction space
  937:                     if ($env{'request.state'} eq 'construct'){
  938:                         &Apache::lonhtmlcommon::add_breadcrumb_tool(
  939:                             'advtools', $inlineremote[63]);
  940:                     } else {
  941:                         &Apache::lonhtmlcommon::add_breadcrumb_tool(
  942:                             'tools', $inlineremote[63]);
  943:                     }
  944:                     unless ($env{'request.noversionuri'}=~ m{^/adm/(navmaps|viewclasslist)(\?|$)}) {
  945:                         &Apache::lonhtmlcommon::add_breadcrumb_tool(
  946:                             'advtools', @inlineremote[61,71,72,73,74,92]);
  947:                     }
  948:                 }
  949:             }
  950:         } else {
  951:             my $requri=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
  952:             $requri=&Apache::lonenc::check_encrypt(&unescape($requri));
  953:             my $cursymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
  954:             my $navstatus=&get_nav_status();
  955:             my $clearcstr;
  956: 
  957:             if ($env{'user.adv'}) { $clearcstr='clearbut(6,1)'; }
  958:             return <<ENDREGTHIS;
  959: 
  960: <script type="text/javascript">
  961: // <![CDATA[
  962: // BEGIN LON-CAPA Internal
  963: var swmenu=null;
  964: 
  965:     function LONCAPAreg() {
  966:           swmenu=$reopen;
  967:           swmenu.clearTimeout(swmenu.menucltim);
  968:           $timesync
  969:           $newmail
  970:           $buttons
  971:           swmenu.currentURL="$requri";
  972:           swmenu.reloadURL=swmenu.currentURL+window.location.search;
  973:           swmenu.currentSymb="$cursymb";
  974:           swmenu.reloadSymb="$cursymb";
  975:           swmenu.currentStale=0;
  976:           $navstatus
  977:           $hwkadd
  978:           $editbutton
  979:     }
  980: 
  981:     function LONCAPAstale() {
  982:           swmenu=$reopen
  983:           swmenu.currentStale=1;
  984:           if (swmenu.reloadURL!='' && swmenu.reloadURL!= null) {
  985:              swmenu.switchbutton
  986:              (3,1,'reload.gif','return','location','go(reloadURL)','Return to the last known location in the course sequence');
  987:           }
  988:           swmenu.clearbut(7,2);
  989:           swmenu.clearbut(7,3);
  990:           swmenu.menucltim=swmenu.setTimeout(
  991:  'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+
  992:  'clearbut(9,1);clearbut(9,3);clearbut(6,3);$clearcstr',
  993:                           2000);
  994:       }
  995: 
  996: // END LON-CAPA Internal
  997: // ]]>
  998: </script>
  999: ENDREGTHIS
 1000:         }
 1001: 
 1002:     return   &Apache::lonhtmlcommon::scripttag('', 'start')
 1003:            . &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
 1004:            . &Apache::lonhtmlcommon::scripttag('', 'end');
 1005: }
 1006: 
 1007: sub is_course_upload {
 1008:     my ($file,$cnum,$cdom) = @_;
 1009:     my $uploadpath = &LONCAPA::propath($cdom,$cnum);
 1010:     $uploadpath =~ s{^\/}{};
 1011:     if (($file =~ m{^\Q$uploadpath\E/userfiles/docs/}) ||
 1012:         ($file =~ m{^userfiles/\Q$cdom\E/\Q$cnum\E/docs/})) {
 1013:         return 1;
 1014:     }
 1015:     return;
 1016: }
 1017: 
 1018: sub edit_course_upload {
 1019:     my ($file,$cnum,$cdom) = @_;
 1020:     my $cfile;
 1021:     if ($file =~/\.(htm|html|css|js|txt)$/) {
 1022:         my $ext = $1;
 1023:         my $url = &Apache::lonnet::hreflocation('',$file);
 1024:         my $home = &Apache::lonnet::homeserver($cnum,$cdom);
 1025:         my @ids=&Apache::lonnet::current_machine_ids();
 1026:         my $dest;
 1027:         if ($home && grep(/^\Q$home\E$/,@ids)) {
 1028:             $dest = $url.'?forceedit=1';
 1029:         } else {
 1030:             unless (&Apache::lonnet::get_locks()) {
 1031:                 $dest = '/adm/switchserver?otherserver='.
 1032:                         $home.'&role='.$env{'request.role'}.
 1033:                         '&url='.$url.'&forceedit=1';
 1034:             }
 1035:         }
 1036:         if ($dest) {
 1037:             $cfile = &HTML::Entities::encode($dest,'"<>&');
 1038:         }
 1039:     }
 1040:     return $cfile;
 1041: }
 1042: 
 1043: sub loadevents() {
 1044:     if ($env{'request.state'} eq 'construct' ||
 1045:         $env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
 1046:     return 'LONCAPAreg();';
 1047: }
 1048: 
 1049: sub unloadevents() {
 1050:     if ($env{'request.state'} eq 'construct' ||
 1051:         $env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
 1052:     return 'LONCAPAstale();';
 1053: }
 1054: 
 1055: sub startupremote {
 1056:     my ($lowerurl)=@_;
 1057:     unless ($env{'environment.remote'} eq 'on') {
 1058:         return ('<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.$lowerurl.'" />');
 1059:     }
 1060: #
 1061: # The Remote actually gets launched!
 1062: #
 1063:     my $configmenu=&rawconfig();
 1064:     my $esclowerurl=&escape($lowerurl);
 1065:     my $message=&mt('"Waiting for Remote Control window to load: "+[_1]','waited');
 1066:     return(<<ENDREMOTESTARTUP);
 1067: <script type="text/javascript">
 1068: // <![CDATA[
 1069: var timestart;
 1070: function wheelswitch() {
 1071:     if (typeof(document.wheel) != 'undefined') {
 1072:         if (typeof(document.wheel.spin) != 'undefined') {
 1073:             var date=new Date();
 1074:             var waited=Math.round(30-((date.getTime()-timestart)/1000));
 1075:             document.wheel.spin.value=$message;
 1076:         }
 1077:     }
 1078:    if (window.status=='|') {
 1079:       window.status='/';
 1080:    } else {
 1081:       if (window.status=='/') {
 1082:          window.status='-';
 1083:       } else {
 1084:          if (window.status=='-') {
 1085:             window.status='\\\\';
 1086:          } else {
 1087:             if (window.status=='\\\\') { window.status='|'; }
 1088:          }
 1089:       }
 1090:    }
 1091: }
 1092: 
 1093: // ---------------------------------------------------------- The wait function
 1094: var canceltim;
 1095: function wait() {
 1096:    if ((menuloaded==1) || (tim==1)) {
 1097:       window.status='Done.';
 1098:       if (tim==0) {
 1099:          clearTimeout(canceltim);
 1100:          $configmenu
 1101:          window.location='$lowerurl';
 1102:       } else {
 1103:           window.location='/adm/remote?action=collapse&url=$esclowerurl';
 1104:       }
 1105:    } else {
 1106:       wheelswitch();
 1107:       setTimeout('wait();',200);
 1108:    }
 1109: }
 1110: 
 1111: function main() {
 1112:    canceltim=setTimeout('tim=1;',30000);
 1113:    window.status='-';
 1114:    var date=new Date();
 1115:    timestart=date.getTime();
 1116:    wait();
 1117: }
 1118: 
 1119: // ]]>
 1120: </script>
 1121: ENDREMOTESTARTUP
 1122: }
 1123: 
 1124: sub setflags() {
 1125:     return(<<ENDSETFLAGS);
 1126: <script type="text/javascript">
 1127: // <![CDATA[
 1128:     menuloaded=0;
 1129:     tim=0;
 1130: // ]]>
 1131: </script>
 1132: ENDSETFLAGS
 1133: }
 1134: 
 1135: sub maincall() {
 1136:     unless ($env{'environment.remote'} eq 'on') { return ''; }
 1137:     return(<<ENDMAINCALL);
 1138: <script type="text/javascript">
 1139: // <![CDATA[
 1140:     main();
 1141: // ]]>
 1142: </script>
 1143: ENDMAINCALL
 1144: }
 1145: 
 1146: sub load_remote_msg {
 1147:     my ($lowerurl)=@_;
 1148: 
 1149:     unless ($env{'environment.remote'} eq 'on') { return ''; }
 1150: 
 1151:     my $esclowerurl=&escape($lowerurl);
 1152:     my $link=&mt('[_1]Continue[_2] on in Inline Menu mode'
 1153:                 ,'<a href="/adm/remote?action=collapse&amp;url='.$esclowerurl.'">'
 1154:                 ,'</a>');
 1155:     return(<<ENDREMOTEFORM);
 1156: <p>
 1157: <form name="wheel">
 1158: <input name="spin" type="text" size="60" />
 1159: </form>
 1160: </p>
 1161: <p>$link</p>
 1162: ENDREMOTEFORM
 1163: }
 1164: 
 1165: sub get_menu_name {
 1166:     my $hostid = $Apache::lonnet::perlvar{'lonHostID'};
 1167:     $hostid =~ s/\W//g;
 1168:     return 'LCmenu'.$hostid;
 1169: }
 1170: 
 1171: 
 1172: sub reopenmenu {
 1173:    unless ($env{'environment.remote'} eq 'on') { return ''; }
 1174:    my $menuname = &get_menu_name();
 1175:    my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
 1176:    return('window.open('.$nothing.',"'.$menuname.'","",false);');
 1177: }
 1178: 
 1179: 
 1180: sub open {
 1181:     my $returnval='';
 1182:     unless ($env{'environment.remote'} eq 'on') {
 1183:         return
 1184:         '<script type="text/javascript">'."\n"
 1185:        .'// <![CDATA['."\n"
 1186:        .'self.name="loncapaclient";'."\n"
 1187:        .'// ]]>'."\n"
 1188:        .'</script>';
 1189:     }
 1190:     my $menuname = &get_menu_name();
 1191: 
 1192: #    unless (shift eq 'unix') {
 1193: # resizing does not work on linux because of virtual desktop sizes
 1194: #       $returnval.=(<<ENDRESIZE);
 1195: #if (window.screen) {
 1196: #    self.resizeTo(screen.availWidth-215,screen.availHeight-55);
 1197: #    self.moveTo(190,15);
 1198: #}
 1199: #ENDRESIZE
 1200: #    }
 1201:     $returnval=(<<ENDOPEN);
 1202: // <![CDATA[
 1203: window.status='Opening LON-CAPA Remote Control';
 1204: var menu=window.open("/res/adm/pages/menu.html?inhibitmenu=yes","$menuname",
 1205: "height=375,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5");
 1206: self.name='loncapaclient';
 1207: // ]]>
 1208: ENDOPEN
 1209:     return '<script type="text/javascript">'.$returnval.'</script>';
 1210: }
 1211: 
 1212: 
 1213: # ================================================================== Raw Config
 1214: 
 1215: sub clear {
 1216:     my ($row,$col)=@_;
 1217:     if ($env{'environment.remote'} eq 'on') {
 1218:        if (($row<1) || ($row>13)) { return ''; }
 1219:        return "\n".qq(window.status+='.';swmenu.clearbut($row,$col););
 1220:     } else {
 1221:         $inlineremote[10*$row+$col]='';
 1222:         return '';
 1223:     }
 1224: }
 1225: 
 1226: # ============================================ Switch a button or create a link
 1227: # Switch acts on the javascript that is executed when a button is clicked.  
 1228: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
 1229: 
 1230: sub switch {
 1231:     my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak)=@_;
 1232:     $act=~s/\$uname/$uname/g;
 1233:     $act=~s/\$udom/$udom/g;
 1234:     $top=&mt($top);
 1235:     $bot=&mt($bot);
 1236:     $desc=&mt($desc);
 1237:     my $idx=10*$row+$col;
 1238:     $category_members{$cat}.=':'.$idx;
 1239: 
 1240:     if ($env{'environment.remote'} eq 'on') {
 1241:         if (($row<1) || ($row>13)) { return ''; }
 1242: # Remote
 1243:         $img=~s/\.png$/\.gif/;
 1244:         return "\n".
 1245:  qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
 1246:     }
 1247: 
 1248: # Inline Menu
 1249:     if ($nobreak==2) { return ''; }
 1250:     my $text=$top.' '.$bot;
 1251:     $text=~s/\s*\-\s*//gs;
 1252: 
 1253:     my $pic=
 1254: 	   '<img alt="'.$text.'" src="'.
 1255: 	   &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
 1256: 	   '" align="'.($nobreak==3?'right':'left').'" class="LC_icon" />';
 1257:     if ($env{'browser.interface'} eq 'faketextual') {
 1258: # Main Menu
 1259: 	   if ($nobreak==3) {
 1260: 	       $inlineremote[$idx]="\n".
 1261: 		   '<td class="LC_menubuttons_text" align="right">'.$text.
 1262: 		   '</td><td align="left">'.
 1263: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
 1264: 	   } elsif ($nobreak) {
 1265: 	       $inlineremote[$idx]="\n<tr>".
 1266: 		   '<td align="left">'.
 1267: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td>
 1268:                     <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>';
 1269: 	   } else {
 1270: 	       $inlineremote[$idx]="\n<tr>".
 1271: 		   '<td align="left">'.
 1272: 		   '<a href="javascript:'.$act.';">'.$pic.
 1273: 		   '</a></td><td class="LC_menubuttons_text" colspan="3">'.
 1274: 		   '<a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$desc.'</span></a></td></tr>';
 1275: 	   }
 1276:     } else {
 1277: # Inline Menu
 1278:         my @tools = (93,91,81,82,83);
 1279:         unless ($env{'request.state'} eq 'construct') {
 1280:             push(@tools,63);
 1281:         }
 1282:         if (($env{'environment.icons'} eq 'iconsonly') &&
 1283:             (grep(/^$idx$/,@tools))) {
 1284:             $inlineremote[$idx] =
 1285:         '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.'</a>';
 1286:         } else {
 1287:             $inlineremote[$idx] =
 1288:        '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.
 1289:        '<span class="LC_menubuttons_inline_text">'.$top.'&nbsp;</span></a>';
 1290:         }
 1291:     }
 1292:     return '';
 1293: }
 1294: 
 1295: sub secondlevel {
 1296:     my $output='';
 1297:     my 
 1298:     ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_;
 1299:     if ($prt eq 'any') {
 1300: 	   $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1301:     } elsif ($prt=~/^r(\w+)/) {
 1302:         if ($rol eq $1) {
 1303:            $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1304:         }
 1305:     }
 1306:     return $output;
 1307: }
 1308: 
 1309: sub openmenu {
 1310:     my $menuname = &get_menu_name();
 1311:     unless ($env{'environment.remote'} eq 'on') { return ''; }
 1312:     my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
 1313:     return "window.open(".$nothing.",'".$menuname."');";
 1314: }
 1315: 
 1316: sub inlinemenu {
 1317:     undef(@inlineremote);
 1318:     undef(%category_members);
 1319: # calling rawconfig with "1" will evaluate mydesk.tab, even if there is no active remote control
 1320:     &rawconfig(1);
 1321:     my $output='<table><tr>';
 1322:     for (my $col=1; $col<=2; $col++) {
 1323:         $output.='<td class="LC_mainmenu_col_fieldset">';
 1324:         for (my $row=1; $row<=8; $row++) {
 1325:             foreach my $cat (keys(%category_members)) {
 1326:                if ($category_positions{$cat} ne "$col,$row") { next; }
 1327:                #$output.='<table><tr><td colspan="4" class="LC_menubuttons_category">'.&mt($category_names{$cat}).'</td></tr>';
 1328:                $output.='<div class="LC_Box LC_400Box">';
 1329: 	       $output.='<h3 class="LC_hcell">'.&mt($category_names{$cat}).'</h3>';
 1330:                $output.='<table>';
 1331:                my %active=();
 1332:                foreach my $menu_item (split(/\:/,$category_members{$cat})) {
 1333:                   if ($inlineremote[$menu_item]) {
 1334:                      $active{$menu_item}=1;
 1335:                   }
 1336:                }  
 1337:                foreach my $item (sort(keys(%active))) {
 1338:                   $output.=$inlineremote[$item];
 1339:                }
 1340:                $output.='</table>';
 1341:                $output.='</div>';
 1342:             }
 1343:          }
 1344:          $output.="</td>";
 1345:     }
 1346:     $output.="</tr></table>";
 1347:     return $output;
 1348: }
 1349: 
 1350: sub rawconfig {
 1351: #
 1352: # This evaluates mydesk.tab
 1353: # Need to add more positions and more privileges to deal with all
 1354: # menu items.
 1355: #
 1356:     my $textualoverride=shift;
 1357:     my $output='';
 1358:     if ($env{'environment.remote'} eq 'on') {
 1359:        $output.=
 1360:  "window.status='Opening Remote Control';var swmenu=".&openmenu().
 1361: "\nwindow.status='Configuring Remote Control ';";
 1362:     } else {
 1363:         unless ($textualoverride) { return ''; }
 1364:     }
 1365:     my $uname=$env{'user.name'};
 1366:     my $udom=$env{'user.domain'};
 1367:     my $adv=$env{'user.adv'};
 1368:     my $show_course=&Apache::loncommon::show_course();
 1369:     my $author=$env{'user.author'};
 1370:     my $crs='';
 1371:     my $crstype='';
 1372:     if ($env{'request.course.id'}) {
 1373:        $crs='/'.$env{'request.course.id'};
 1374:        if ($env{'request.course.sec'}) {
 1375: 	   $crs.='_'.$env{'request.course.sec'};
 1376:        }
 1377:        $crs=~s/\_/\//g;
 1378:        $crstype = &Apache::loncommon::course_type();
 1379:     }
 1380:     my $pub=($env{'request.state'} eq 'published');
 1381:     my $con=($env{'request.state'} eq 'construct');
 1382:     my $rol=$env{'request.role'};
 1383:     my $requested_domain = $env{'request.role.domain'};
 1384:     foreach my $line (@desklines) {
 1385:         my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
 1386:         $prt=~s/\$uname/$uname/g;
 1387:         $prt=~s/\$udom/$udom/g;
 1388:         if ($prt =~ /\$crs/) {
 1389:             next unless ($env{'request.course.id'});
 1390:             next if ($crstype eq 'Community');
 1391:             $prt=~s/\$crs/$crs/g;
 1392:         } elsif ($prt =~ /\$cmty/) {
 1393:             next unless ($env{'request.course.id'});
 1394:             next if ($crstype ne 'Community');
 1395:             $prt=~s/\$cmty/$crs/g;
 1396:         }
 1397:         $prt=~s/\$requested_domain/$requested_domain/g;
 1398:         if ($category_names{$cat}!~/\w/) { $cat='oth'; }
 1399:         if ($pro eq 'clear') {
 1400: 	    $output.=&clear($row,$col);
 1401:         } elsif ($pro eq 'any') {
 1402:                $output.=&secondlevel(
 1403: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1404: 	} elsif ($pro eq 'smp') {
 1405:             unless ($adv) {
 1406:                $output.=&secondlevel(
 1407:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1408:             }
 1409:         } elsif ($pro eq 'adv') {
 1410:             if ($adv) {
 1411:                $output.=&secondlevel(
 1412: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1413:             }
 1414: 	} elsif ($pro eq 'shc') {
 1415:             if ($show_course) {
 1416:                $output.=&secondlevel(
 1417:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1418:             }
 1419:         } elsif ($pro eq 'nsc') {
 1420:             if (!$show_course) {
 1421:                $output.=&secondlevel(
 1422: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1423:             }
 1424:         } elsif (($pro=~/^p(\w+)/) && ($prt)) {
 1425:             my $priv = $1;
 1426:             if ($priv =~ /^mdc(Course|Community)/) {
 1427:                 if ($crstype eq $1) {
 1428:                     $priv = 'mdc';
 1429:                 } else {
 1430:                     next;
 1431:                 }
 1432:             }
 1433: 	    if (&Apache::lonnet::allowed($priv,$prt)) {
 1434:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1435:             }
 1436:         } elsif ($pro eq 'course')  {
 1437:             if (($env{'request.course.fn'}) && ($crstype ne 'Community')) {
 1438:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1439: 	    }
 1440:         } elsif ($pro eq 'community')  {
 1441:             if (($env{'request.course.fn'}) && ($crstype eq 'Community')) {
 1442:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1443:             }
 1444:         } elsif ($pro =~ /^courseenv_(.*)$/) {
 1445:             my $key = $1;
 1446:             if ($crstype ne 'Community') {
 1447:                 my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
 1448:                 if ($key eq 'canuse_pdfforms') {
 1449:                     if ($env{'request.course.id'} && $coursepref eq '') {
 1450:                         my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
 1451:                         $coursepref = $domdefs{'canuse_pdfforms'};
 1452:                     }
 1453:                 }
 1454:                 if ($coursepref) { 
 1455:                     $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1456:                 }
 1457:             }
 1458:         } elsif ($pro =~ /^communityenv_(.*)$/) {
 1459:             my $key = $1;
 1460:             if ($crstype eq 'Community') {
 1461:                 my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
 1462:                 if ($key eq 'canuse_pdfforms') {
 1463:                     if ($env{'request.course.id'} && $coursepref eq '') {
 1464:                         my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
 1465:                         $coursepref = $domdefs{'canuse_pdfforms'};
 1466:                     }
 1467:                 }
 1468:                 if ($coursepref) { 
 1469:                     $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1470:                 }
 1471:             }
 1472:         } elsif ($pro =~ /^course_(.*)$/) {
 1473:             # Check for permissions inside of a course
 1474:             if (($env{'request.course.id'}) && ($crstype ne 'Community') && 
 1475:                 (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
 1476:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
 1477:                  )) {
 1478:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1479: 	    }
 1480:         } elsif ($pro =~ /^community_(.*)$/) {
 1481:             # Check for permissions inside of a community
 1482:             if (($env{'request.course.id'}) && ($crstype eq 'Community') &&   
 1483:                 (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
 1484:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
 1485:                  )) {
 1486:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1487:             }
 1488:         } elsif ($pro eq 'author') {
 1489:             if ($author) {
 1490:                 if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
 1491:                     (($prt eq 'raa') && ($env{'request.role'}=~/^aa/)) || 
 1492:                     (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
 1493:                     # Check that we are on the correct machine
 1494:                     my $cadom=$requested_domain;
 1495:                     my $caname=$env{'user.name'};
 1496:                     if (($prt eq 'rca') || ($prt eq 'raa')) {
 1497: 		       ($cadom,$caname)=
 1498:                                ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
 1499:                     }                       
 1500:                     $act =~ s/\$caname/$caname/g;
 1501:                     $act =~ s/\$cadom/$cadom/g;
 1502:                     my $home = &Apache::lonnet::homeserver($caname,$cadom);
 1503: 		    my $allowed=0;
 1504: 		    my @ids=&Apache::lonnet::current_machine_ids();
 1505: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
 1506: 		    if ($allowed) {
 1507:                         $output.=&switch($caname,$cadom,
 1508:                                         $row,$col,$img,$top,$bot,$act,$desc,$cat);
 1509:                     }
 1510:                 }
 1511:             }
 1512:         } elsif ($pro eq 'tools') {
 1513:             my @tools = ('aboutme','blog','portfolio');
 1514:             if (grep(/^\Q$prt\E$/,@tools)) {
 1515:                 if (!&Apache::lonnet::usertools_access($env{'user.name'},
 1516:                                                        $env{'user.domain'},
 1517:                                                        $prt,undef,'tools')) {
 1518:                     $output.=&clear($row,$col);
 1519:                     next;
 1520:                 }
 1521:             } elsif (($prt eq 'reqcrsnsc') || ($prt eq 'reqcrsshc')) {
 1522:                 if (($prt eq 'reqcrsnsc') && ($show_course))   {
 1523:                     next;
 1524:                 }
 1525:                 if (($prt eq 'reqcrsshc') && (!$show_course)) {
 1526:                     next;
 1527:                 }
 1528:                 my $showreqcrs = &check_for_rcrs();
 1529:                 if (!$showreqcrs) {
 1530:                     $output.=&clear($row,$col);
 1531:                     next;
 1532:                 }
 1533:             }
 1534:             $prt='any';
 1535:             $output.=&secondlevel(
 1536:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1537:         }
 1538:     }
 1539:     if ($env{'environment.remote'} eq 'on') {
 1540:         $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
 1541:         if (&Apache::lonmsg::newmail()) {
 1542:             $output.='swmenu.setstatus("you have","messages");';
 1543:         }
 1544:     }
 1545:     return $output;
 1546: }
 1547: 
 1548: sub check_for_rcrs {
 1549:     my $showreqcrs = 0;
 1550:     my @reqtypes = ('official','unofficial','community');
 1551:     foreach my $type (@reqtypes) {
 1552:         if (&Apache::lonnet::usertools_access($env{'user.name'},
 1553:                                               $env{'user.domain'},
 1554:                                               $type,undef,'requestcourses')) {
 1555:             $showreqcrs = 1;
 1556:             last;
 1557:         }
 1558:     }
 1559:     if (!$showreqcrs) {
 1560:         foreach my $type (@reqtypes) {
 1561:             if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
 1562:                 $showreqcrs = 1;
 1563:                 last;
 1564:             }
 1565:         }
 1566:     }
 1567:     return $showreqcrs;
 1568: }
 1569: 
 1570: # ======================================================================= Close
 1571: 
 1572: sub close {
 1573:     unless ($env{'environment.remote'} eq 'on') { return ''; }
 1574:     my $menuname = &get_menu_name();
 1575:     return(<<ENDCLOSE);
 1576: <script type="text/javascript">
 1577: // <![CDATA[
 1578: window.status='Accessing Remote Control';
 1579: menu=window.open("/adm/rat/empty.html","$menuname",
 1580:                  "height=350,width=150,scrollbars=no,menubar=no");
 1581: window.status='Disabling Remote Control';
 1582: menu.active=0;
 1583: menu.autologout=0;
 1584: window.status='Closing Remote Control';
 1585: menu.close();
 1586: window.status='Done.';
 1587: // ]]>
 1588: </script>
 1589: ENDCLOSE
 1590: }
 1591: 
 1592: sub dc_popup_js {
 1593:     my %lt = &Apache::lonlocal::texthash(
 1594:                                           more => '(More ...)',
 1595:                                           less => '(Less ...)',
 1596:                                         );
 1597:     return <<"END";
 1598: 
 1599: function showCourseID() {
 1600:     document.getElementById('dccid').style.display='block';
 1601:     document.getElementById('dccid').style.textAlign='left';
 1602:     document.getElementById('dccid').style.textFace='normal';
 1603:     document.getElementById('dccidtext').innerHTML ='<a href="javascript:hideCourseID();" class="LC_menubuttons_link">$lt{'less'}</a>';
 1604:     return;
 1605: }
 1606: 
 1607: function hideCourseID() {
 1608:     document.getElementById('dccid').style.display='none';
 1609:     document.getElementById('dccidtext').innerHTML ='<a href="javascript:showCourseID()" class="LC_menubuttons_link">$lt{'more'}</a>';
 1610:     return;
 1611: }
 1612: 
 1613: END
 1614: 
 1615: }
 1616: 
 1617: sub countdown_toggle_js {
 1618:     return <<"END";
 1619: 
 1620: function toggleCountdown() {
 1621:     var countdownid = document.getElementById('duedatecountdown');
 1622:     var currstyle = countdownid.style.display;
 1623:     if (currstyle == 'inline') {
 1624:         countdownid.style.display = 'none';
 1625:         document.getElementById('ddcountcollapse').innerHTML='';
 1626:         document.getElementById('ddcountexpand').innerHTML='&#9668;&nbsp;';
 1627:     } else {
 1628:         countdownid.style.display = 'inline';
 1629:         document.getElementById('ddcountcollapse').innerHTML='&#9658;&nbsp;';
 1630:         document.getElementById('ddcountexpand').innerHTML='';
 1631:     }
 1632:     return;
 1633: }
 1634: 
 1635: END
 1636: }
 1637: 
 1638: sub utilityfunctions {
 1639:     my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
 1640:     if ($currenturl =~ m{^/adm/wrapper/ext/}
 1641:         && $env{'request.external.querystring'} ) {
 1642:             $currenturl .= ($currenturl=~/\?/)?'&':'?'.$env{'request.external.querystring'};
 1643:     }
 1644:     $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
 1645:     
 1646:     my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
 1647: 
 1648:     my $dc_popup_cid;
 1649:     if ($env{'user.adv'} && exists($env{'user.role.dc./'.
 1650:                         $env{'course.'.$env{'request.course.id'}.
 1651:                                  '.domain'}.'/'})) {
 1652:         $dc_popup_cid = &dc_popup_js();
 1653:     }
 1654: 
 1655:     my $start_page_annotate = 
 1656:         &Apache::loncommon::start_page('Annotator',undef,
 1657: 				       {'only_body' => 1,
 1658: 					'js_ready'  => 1,
 1659: 					'bgcolor'   => '#BBBBBB',
 1660: 					'add_entries' => {
 1661: 					    'onload' => 'javascript:document.goannotate.submit();'}});
 1662: 
 1663:     my $end_page_annotate = 
 1664:         &Apache::loncommon::end_page({'js_ready' => 1});
 1665: 
 1666:     my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
 1667:                          &mt('Switch server?');
 1668: 
 1669:     my $esc_url=&escape($currenturl);
 1670:     my $esc_symb=&escape($currentsymb);
 1671: 
 1672:     my $countdown = &countdown_toggle_js();
 1673: 
 1674: return (<<ENDUTILITY)
 1675: 
 1676:     var currentURL=unescape("$esc_url");
 1677:     var reloadURL=unescape("$esc_url");
 1678:     var currentSymb=unescape("$esc_symb");
 1679: 
 1680: $dc_popup_cid
 1681: 
 1682: function go(url) {
 1683:    if (url!='' && url!= null) {
 1684:        currentURL = null;
 1685:        currentSymb= null;
 1686:        window.location.href=url;
 1687:    }
 1688: }
 1689: 
 1690: function need_switchserver(url) {
 1691:     if (url!='' && url!= null) {
 1692:         if (confirm("$confirm_switch")) {
 1693:             go(url); 
 1694:         }
 1695:     }
 1696:     return;
 1697: }
 1698: 
 1699: function gopost(url,postdata) {
 1700:    if (url!='') {
 1701:       this.document.server.action=url;
 1702:       this.document.server.postdata.value=postdata;
 1703:       this.document.server.command.value='';
 1704:       this.document.server.url.value='';
 1705:       this.document.server.symb.value='';
 1706:       this.document.server.submit();
 1707:    }
 1708: }
 1709: 
 1710: function gocmd(url,cmd) {
 1711:    if (url!='') {
 1712:       this.document.server.action=url;
 1713:       this.document.server.postdata.value='';
 1714:       this.document.server.command.value=cmd;
 1715:       this.document.server.url.value=currentURL;
 1716:       this.document.server.symb.value=currentSymb;
 1717:       this.document.server.submit();
 1718:    }
 1719: }
 1720: 
 1721: function gocstr(url,filename) {
 1722:     if (url == '/adm/cfile?action=delete') {
 1723:         this.document.cstrdelete.filename.value = filename
 1724:         this.document.cstrdelete.submit();
 1725:         return;
 1726:     }
 1727:     if (url == '/adm/printout') {
 1728:         this.document.cstrprint.postdata.value = filename
 1729:         this.document.cstrprint.curseed.value = 0;
 1730:         this.document.cstrprint.problemtype.value = 0;
 1731:         if (this.document.lonhomework) {
 1732:             if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
 1733:                 this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
 1734:             }
 1735:             if (this.document.lonhomework.problemtype) {
 1736: 		if (this.document.lonhomework.problemtype.value) {
 1737: 		    this.document.cstrprint.problemtype.value = 
 1738: 			this.document.lonhomework.problemtype.value;
 1739: 		} else if (this.document.lonhomework.problemtype.options) {
 1740: 		    for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
 1741: 			if (this.document.lonhomework.problemtype.options[i].selected) {
 1742: 			    if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') { 
 1743: 				this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
 1744: 				}
 1745: 			}
 1746: 		    }
 1747: 		}
 1748: 	    }
 1749: 	}
 1750:         this.document.cstrprint.submit();
 1751:         return;
 1752:     }
 1753:     if (url !='') {
 1754:         this.document.constspace.filename.value = filename;
 1755:         this.document.constspace.action = url;
 1756:         this.document.constspace.submit();
 1757:     }
 1758: }
 1759: 
 1760: function golist(url) {
 1761:    if (url!='' && url!= null) {
 1762:        currentURL = null;
 1763:        currentSymb= null;
 1764:        top.location.href=url;
 1765:    }
 1766: }
 1767: 
 1768: 
 1769: 
 1770: function catalog_info() {
 1771:    openMyModal(window.location.pathname+'.meta',500,400,'yes');
 1772: }
 1773: 
 1774: function chat_win() {
 1775:    lonchat=window.open('/res/adm/pages/chatroom.html',"LONchat",'height=320,width=480,resizable=yes,location=no,menubar=no,toolbar=no');
 1776: }
 1777: 
 1778: function group_chat(group) {
 1779:    var url = '/adm/groupchat?group='+group;
 1780:    var winName = 'LONchat_'+group;
 1781:    grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
 1782: }
 1783: 
 1784: function annotate() {
 1785:    w_Annotator_flag=1;
 1786:    annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
 1787:    annotator.document.write(
 1788:    '$start_page_annotate'
 1789:   +"<form name='goannotate' target='Annotator' method='post' "
 1790:   +"action='/adm/annotations'>"
 1791:   +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />"
 1792:   +"<\\/form>"
 1793:   +'$end_page_annotate');
 1794:    annotator.document.close();
 1795: }
 1796: 
 1797: function open_StoredLinks_Import(rat) {
 1798:    var newWin;
 1799:    if (rat) {
 1800:        newWin = window.open('/adm/wishlist?inhibitmenu=yes&mode=import&rat='+rat,
 1801:                             'wishlistImport','scrollbars=1,resizable=1,menubar=0');
 1802:    }
 1803:    else {
 1804:        newWin = window.open('/adm/wishlist?inhibitmenu=yes&mode=import',
 1805:                             'wishlistImport','scrollbars=1,resizable=1,menubar=0');
 1806:    }
 1807:    newWin.focus();
 1808: }
 1809: 
 1810: (function (\$) {
 1811:   \$(document).ready(function () {
 1812:     \$.single=function(a){return function(b){a[0]=b;return a}}(\$([1]));
 1813:     /*\@cc_on
 1814:       if (!window.XMLHttpRequest) {
 1815:         \$('.LC_hoverable').each(function () {
 1816:           this.attachEvent('onmouseenter', function (evt) { \$.single(evt.srcElement).addClass('hover'); });
 1817:           this.attachEvent('onmouseleave', function (evt) { \$.single(evt.srcElement).removeClass('hover'); });
 1818:         });
 1819:       }
 1820:     \@*/
 1821:   });
 1822: }(jQuery));
 1823: 
 1824: $countdown
 1825: 
 1826: ENDUTILITY
 1827: }
 1828: 
 1829: sub serverform {
 1830:     return(<<ENDSERVERFORM);
 1831: <form name="server" action="/adm/logout" method="post" target="_top">
 1832: <input type="hidden" name="postdata" value="none" />
 1833: <input type="hidden" name="command" value="none" />
 1834: <input type="hidden" name="url" value="none" />
 1835: <input type="hidden" name="symb" value="none" />
 1836: </form>
 1837: ENDSERVERFORM
 1838: }
 1839: 
 1840: sub constspaceform {
 1841:     return(<<ENDCONSTSPACEFORM);
 1842: <form name="constspace" action="/adm/logout" method="post" target="_top">
 1843: <input type="hidden" name="filename" value="" />
 1844: </form>
 1845: <form name="cstrdelete" action="/adm/cfile" method="post" target="_top">
 1846: <input type="hidden" name="action" value="delete" /> 
 1847: <input type="hidden" name="filename" value="" />
 1848: </form>
 1849: <form name="cstrprint" action="/adm/printout" target="_parent" method="post">
 1850: <input type="hidden" name="postdata" value="" />
 1851: <input type="hidden" name="curseed" value="" />
 1852: <input type="hidden" name="problemtype" value="" />
 1853: </form>
 1854: 
 1855: ENDCONSTSPACEFORM
 1856: }
 1857: 
 1858: sub get_nav_status {
 1859:     my $navstatus="swmenu.w_loncapanav_flag=";
 1860:     if ($env{'environment.remotenavmap'} eq 'on') {
 1861:         $navstatus.="1";
 1862:     } else {
 1863:         $navstatus.="-1";
 1864:     }
 1865:     return $navstatus;
 1866: }
 1867: 
 1868: sub hidden_button_check {
 1869:     if ( $env{'request.course.id'} eq ''
 1870:          || $env{'request.role.adv'} ) {
 1871: 
 1872:         return;
 1873:     }
 1874:     my $buttonshide = &Apache::lonnet::EXT('resource.0.buttonshide');
 1875:     return $buttonshide; 
 1876: }
 1877: 
 1878: sub roles_selector {
 1879:     my ($cdom,$cnum) = @_;
 1880:     my $crstype = &Apache::loncommon::course_type();
 1881:     my $now = time;
 1882:     my (%courseroles,%seccount,%courseprivs);
 1883:     my $is_cc;
 1884:     my $role_selector;
 1885:     my $ccrole;
 1886:     if ($crstype eq 'Community') {
 1887:         $ccrole = 'co';
 1888:     } else {
 1889:         $ccrole = 'cc';
 1890:     }
 1891:     my $priv;
 1892:     my $destinationurl = $ENV{'REQUEST_URI'};
 1893:     my $reqprivs = &required_privs();
 1894:     if (ref($reqprivs) eq 'HASH') {
 1895:         my $destination = $destinationurl;
 1896:         $destination =~ s/(\?.*)$//;
 1897:         if (exists($reqprivs->{$destination})) {
 1898:             $priv = $reqprivs->{$destination};
 1899:         }
 1900:     }
 1901:     if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
 1902:         my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
 1903:         
 1904:         if ((($start) && ($start<0)) || 
 1905:             (($end) && ($end<$now))  ||
 1906:             (($start) && ($now<$start))) {
 1907:             $is_cc = 0;
 1908:         } else {
 1909:             $is_cc = 1;
 1910:         }
 1911:     }
 1912:     if ($is_cc) {
 1913:         &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs,$priv);
 1914:     } else {
 1915:         my %gotnosection;
 1916:         foreach my $item (keys(%env)) {
 1917:             if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
 1918:                 my $role = $1;
 1919:                 my $sec = $2;
 1920:                 next if ($role eq 'gr');
 1921:                 my ($start,$end) = split(/\./,$env{$item});
 1922:                 next if (($start && $start > $now) || ($end && $end < $now));
 1923:                 if ($sec eq '') {
 1924:                     if (!$gotnosection{$role}) {
 1925:                         $seccount{$role} ++;
 1926:                         $gotnosection{$role} = 1;
 1927:                     }
 1928:                 }
 1929:                 if ($priv ne '') {
 1930:                     my $cnumsec = $cnum;
 1931:                     if ($sec ne '') {
 1932:                         $cnumsec .= "/$sec";
 1933:                     }
 1934:                     $courseprivs{"$role./$cdom/$cnumsec./"} =
 1935:                         $env{"user.priv.$role./$cdom/$cnumsec./"};
 1936:                     $courseprivs{"$role./$cdom/$cnumsec./$cdom/"} =
 1937:                         $env{"user.priv.$role./$cdom/$cnumsec./$cdom/"};
 1938:                     $courseprivs{"$role./$cdom/$cnumsec./$cdom/$cnumsec"} =
 1939:                         $env{"user.priv.$role./$cdom/$cnumsec./$cdom/$cnumsec"};
 1940:                 }
 1941:                 if (ref($courseroles{$role}) eq 'ARRAY') {
 1942:                     if ($sec ne '') {
 1943:                         if (!grep(/^\Q$sec\E$/,@{$courseroles{$role}})) {
 1944:                             push(@{$courseroles{$role}},$sec);
 1945:                             $seccount{$role} ++;
 1946:                         }
 1947:                     }
 1948:                 } else {
 1949:                     @{$courseroles{$role}} = ();
 1950:                     if ($sec ne '') {
 1951:                         $seccount{$role} ++;
 1952:                         push(@{$courseroles{$role}},$sec);
 1953:                     }
 1954:                 }
 1955:             }
 1956:         }
 1957:     }
 1958:     my $switchtext;
 1959:     if ($crstype eq 'Community') {
 1960:         $switchtext = &mt('Switch community role to...')
 1961:     } else {
 1962:         $switchtext = &mt('Switch course role to...')
 1963:     }
 1964:     my @roles_order = ($ccrole,'in','ta','ep','ad','st');
 1965:     if (keys(%courseroles) > 1) {
 1966:         $role_selector = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles,\%courseprivs,$priv);
 1967:         $role_selector .= '<form name="rolechooser" method="post" action="/adm/roles">
 1968:                           <select name="switchrole" onchange="javascript:adhocRole('."'switchrole'".')">';
 1969:         $role_selector .= '<option value="">'.$switchtext.'</option>';
 1970:         foreach my $role (@roles_order) {
 1971:             if (defined($courseroles{$role})) {
 1972:                 $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role,$crstype).'</option>'; 
 1973:             }
 1974:         }
 1975:         foreach my $role (sort(keys(%courseroles))) {
 1976:             if ($role =~ /^cr/) {
 1977:                 $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role).'</option>'; 
 1978:             }
 1979:         }
 1980:         $role_selector .= '</select>'."\n".
 1981:                '<input type="hidden" name="destinationurl" value="'.
 1982:                &HTML::Entities::encode($destinationurl).'" />'."\n".
 1983:                '<input type="hidden" name="gotorole" value="1" />'."\n".
 1984:                '<input type="hidden" name="selectrole" value="" />'."\n".
 1985:                '<input type="hidden" name="switch" value="1" />'."\n".
 1986:                '</form>';
 1987:     }
 1988:     return $role_selector;
 1989: }
 1990: 
 1991: sub get_all_courseroles {
 1992:     my ($cdom,$cnum,$courseroles,$seccount,$courseprivs) = @_;
 1993:     unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH') &&
 1994:             (ref($courseprivs) eq 'HASH')) {
 1995:         return;
 1996:     }
 1997:     my ($result,$cached) = 
 1998:         &Apache::lonnet::is_cached_new('getcourseroles',$cdom.'_'.$cnum);
 1999:     if (defined($cached)) {
 2000:         if (ref($result) eq 'HASH') {
 2001:             if ((ref($result->{'roles'}) eq 'HASH') && 
 2002:                 (ref($result->{'seccount'}) eq 'HASH') && 
 2003:                 (ref($result->{'privs'}) eq 'HASH')) {
 2004:                 %{$courseroles} = %{$result->{'roles'}};
 2005:                 %{$seccount} = %{$result->{'seccount'}};
 2006:                 %{$courseprivs} = %{$result->{'privs'}};
 2007:                 return;
 2008:             }
 2009:         }
 2010:     }
 2011:     my %gotnosection;
 2012:     my %adv_roles =
 2013:          &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
 2014:     foreach my $role (keys(%adv_roles)) {
 2015:         my ($urole,$usec) = split(/:/,$role);
 2016:         if (!$gotnosection{$urole}) {
 2017:             $seccount->{$urole} ++;
 2018:             $gotnosection{$urole} = 1;
 2019:         }
 2020:         if (ref($courseroles->{$urole}) eq 'ARRAY') {
 2021:             if ($usec ne '') {
 2022:                 if (!grep(/^Q$usec\E$/,@{$courseroles->{$urole}})) {
 2023:                     push(@{$courseroles->{$urole}},$usec);
 2024:                     $seccount->{$urole} ++;
 2025:                 }
 2026:             }
 2027:         } else {
 2028:             @{$courseroles->{$urole}} = ();
 2029:             if ($usec ne '') {
 2030:                 $seccount->{$urole} ++;
 2031:                 push(@{$courseroles->{$urole}},$usec);
 2032:             }
 2033:         }
 2034:         my $area = '/'.$cdom.'/'.$cnum;
 2035:         if ($usec ne '') {
 2036:             $area .= '/'.$usec;
 2037:         }
 2038:         if ($role =~ /^cr\//) {
 2039:             &Apache::lonnet::custom_roleprivs($courseprivs,$urole,$cdom,$cnum,$urole.'.'.$area,$area);
 2040:         } else {
 2041:             &Apache::lonnet::standard_roleprivs($courseprivs,$urole,$cdom,$urole.'.'.$area,$cnum,$area);
 2042:         }
 2043:     }
 2044:     my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum,['st']);
 2045:     @{$courseroles->{'st'}} = ();
 2046:     &Apache::lonnet::standard_roleprivs($courseprivs,'st',$cdom,"st./$cdom/$cnum",$cnum,"/$cdom/$cnum");
 2047:     if (keys(%sections_count) > 0) {
 2048:         push(@{$courseroles->{'st'}},keys(%sections_count));
 2049:         $seccount->{'st'} = scalar(keys(%sections_count));
 2050:     }
 2051:     my $rolehash = {
 2052:                      'roles'    => $courseroles,
 2053:                      'seccount' => $seccount,
 2054:                      'privs'    => $courseprivs,
 2055:                    };
 2056:     &Apache::lonnet::do_cache_new('getcourseroles',$cdom.'_'.$cnum,$rolehash);
 2057:     return;
 2058: }
 2059: 
 2060: sub jump_to_role {
 2061:     my ($cdom,$cnum,$seccount,$courseroles,$courseprivs,$priv) = @_;
 2062:     my %lt = &Apache::lonlocal::texthash(
 2063:                 this => 'This role has section(s) associated with it.',
 2064:                 ente => 'Enter a specific section.',
 2065:                 orlb => 'Enter a specific section, or leave blank for no section.',
 2066:                 avai => 'Available sections are:',
 2067:                 youe => 'You entered an invalid section choice:',
 2068:                 plst => 'Please try again.',
 2069:                 role => 'The role you selected is not permitted to view the current page.',
 2070:                 swit => 'Switch role, but display Main Menu page instead?',
 2071:     );
 2072:     my $js;
 2073:     if (ref($courseroles) eq 'HASH') {
 2074:         $js = '    var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n". 
 2075:               '    var numsec = new Array();'."\n".
 2076:               '    var rolesections = new Array();'."\n".
 2077:               '    var rolenames = new Array();'."\n".
 2078:               '    var roleseclist = new Array();'."\n";
 2079:         my @items = keys(%{$courseroles});
 2080:         for (my $i=0; $i<@items; $i++) {
 2081:             $js .= '    rolenames['.$i.'] = "'.$items[$i].'";'."\n";
 2082:             my ($secs,$secstr);
 2083:             if (ref($courseroles->{$items[$i]}) eq 'ARRAY') {
 2084:                 my @sections = sort { $a <=> $b } @{$courseroles->{$items[$i]}};
 2085:                 $secs = join('","',@sections);
 2086:                 $secstr = join(', ',@sections);
 2087:             }
 2088:             $js .= '    rolesections['.$i.'] = new Array("'.$secs.'");'."\n".
 2089:                    '    roleseclist['.$i.'] = "'.$secstr.'";'."\n".
 2090:                    '    numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n";
 2091:         }
 2092:     }
 2093:     my $checkroles = 0;
 2094:     if ($priv && ref($courseprivs) eq 'HASH') {
 2095:         my (%disallowed,%allowed,@disallow);
 2096:         foreach my $role (sort(keys(%{$courseprivs}))) {
 2097:             my $trole;
 2098:             if ($role =~ m{^(.+?)\Q./$cdom/$cnum\E}) {
 2099:                 $trole = $1;
 2100:             }
 2101:             if (($trole ne '') && ($trole ne 'cm')) {
 2102:                 if ($courseprivs->{$role} =~ /\Q:$priv\E($|:|\&\w+)/) {
 2103:                     $allowed{$trole} = 1;
 2104:                 } else {
 2105:                     $disallowed{$trole} = 1;
 2106:                 }
 2107:             }
 2108:         }
 2109:         foreach my $trole (keys(%disallowed)) {
 2110:             unless ($allowed{$trole}) {
 2111:                 push(@disallow,$trole);
 2112:             }
 2113:         }
 2114:         if (@disallow > 0) {
 2115:             $checkroles = 1;
 2116:             $js .= "    var disallow = new Array('".join("','",@disallow)."');\n".
 2117:                    "    var rolecheck = 1;\n";
 2118:         }
 2119:     }
 2120:     if (!$checkroles) {
 2121:         $js .=  "    var disallow = new Array();\n".
 2122:                 "    rolecheck = 0;\n";
 2123:     }
 2124:     return <<"END";
 2125: <script type="text/javascript">
 2126: //<![CDATA[
 2127: function adhocRole(roleitem) {
 2128:     $js
 2129:     var newrole =  document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value;
 2130:     if (newrole == '') {
 2131:         return;
 2132:     } 
 2133:     var fullrole = newrole+'./$cdom/$cnum';
 2134:     var selidx = '';
 2135:     for (var i=0; i<rolenames.length; i++) {
 2136:         if (rolenames[i] == newrole) {
 2137:             selidx = i;
 2138:         }
 2139:     }
 2140:     if (rolecheck > 0) {
 2141:         for (var i=0; i<disallow.length; i++) {
 2142:             if (disallow[i] == newrole) {
 2143:                 if (confirm("$lt{'role'}\\n$lt{'swit'}")) {
 2144:                     document.rolechooser.destinationurl.value = '/adm/menu';
 2145:                 } else {
 2146:                     document.rolechooser.elements[roleitem].selectedIndex = 0;
 2147:                     return;
 2148:                 }
 2149:             }
 2150:         }
 2151:     }
 2152:     var secok = 1;
 2153:     var secchoice = '';
 2154:     if (selidx >= 0) {
 2155:         if (numsec[selidx] > 1) {
 2156:             secok = 0;
 2157:             var numrolesec = rolesections[selidx].length;
 2158:             var msgidx = numsec[selidx] - numrolesec;
 2159:             secchoice = prompt("$lt{'this'} "+secpick[msgidx]+"\\n$lt{'avai'} "+roleseclist[selidx],"");
 2160:             if (secchoice == '') {
 2161:                 if (msgidx > 0) {
 2162:                     secok = 1;
 2163:                 }
 2164:             } else {
 2165:                 for (var j=0; j<rolesections[selidx].length; j++) {
 2166:                     if (rolesections[selidx][j] == secchoice) {
 2167:                         secok = 1;
 2168:                     }
 2169:                 }
 2170:             }
 2171:         } else {
 2172:             if (rolesections[selidx].length == 1) {
 2173:                 secchoice = rolesections[selidx][0];
 2174:             }
 2175:         }
 2176:     }
 2177:     if (secok == 1) {
 2178:         if (secchoice != '') {
 2179:             fullrole += '/'+secchoice;
 2180:         }
 2181:     } else {
 2182:         document.rolechooser.elements[roleitem].selectedIndex = 0;
 2183:         if (secchoice != null) {
 2184:             alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}");
 2185:         }
 2186:         return;
 2187:     }
 2188:     if (fullrole == "$env{'request.role'}") {
 2189:         document.rolechooser.elements[roleitem].selectedIndex = 0;
 2190:         return;
 2191:     }
 2192:     itemid = retrieveIndex('gotorole');
 2193:     if (itemid != -1) {
 2194:         document.rolechooser.elements[itemid].name = fullrole;
 2195:     }
 2196:     document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value = fullrole;
 2197:     document.rolechooser.selectrole.value = '1';
 2198:     document.rolechooser.submit();
 2199:     return;
 2200: }
 2201: 
 2202: function retrieveIndex(item) {
 2203:     for (var i=0;i<document.rolechooser.elements.length;i++) {
 2204:         if (document.rolechooser.elements[i].name == item) {
 2205:             return i;
 2206:         }
 2207:     }
 2208:     return -1;
 2209: }
 2210: // ]]>
 2211: </script>
 2212: END
 2213: }
 2214: 
 2215: sub required_privs {
 2216:     my $privs =  {
 2217:              '/adm/parmset'      => 'opa',
 2218:              '/adm/courseprefs'  => 'opa',
 2219:              '/adm/whatsnew'     => 'whn',
 2220:              '/adm/populate'     => 'cst',
 2221:              '/adm/trackstudent' => 'vsa',
 2222:              '/adm/statistics'   => 'vgr',
 2223:              '/adm/setblock'     => 'dcm',
 2224:              '/adm/coursedocs'   => 'mdc',
 2225:            };
 2226:     unless ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'spreadsheet') {
 2227:         $privs->{'/adm/classcalc'}   = 'vgr',
 2228:         $privs->{'/adm/assesscalc'}  = 'vgr',
 2229:         $privs->{'/adm/studentcalc'} = 'vgr';
 2230:     }
 2231:     return $privs;
 2232: }
 2233: 
 2234: sub countdown_timer {
 2235:     if (($env{'request.course.id'}) && ($env{'request.symb'} ne '') &&
 2236:         ($env{'request.filename'}=~/$LONCAPA::assess_re/) &&
 2237:         ($Apache::inputtags::status[-1] eq 'CAN_ANSWER')) {
 2238:         my $duedate = &Apache::lonnet::EXT("resource.0.duedate");
 2239:         my @interval=&Apache::lonnet::EXT("resource.0.interval");
 2240:         my $hastimeleft;
 2241:         if (@interval > 1) {
 2242:             my $first_access=&Apache::lonnet::get_first_access($interval[1]);
 2243:             if ($first_access > 0) {
 2244:                 if ($first_access+$interval[0] > time) {
 2245:                     $hastimeleft = 1;
 2246:                 }
 2247:             }
 2248:         }
 2249:         if (($duedate && $duedate > time) ||
 2250:             (!$duedate && $hastimeleft)) {
 2251:             my ($collapse,$expand,$alttxt,$title,$currdisp);
 2252:             if (@interval > 1 && $hastimeleft) {
 2253:                 $currdisp = 'inline';
 2254:                 $collapse = '&#9658;&nbsp;';
 2255:             } else {
 2256:                 $currdisp = 'none';
 2257:                 $expand = '&#9668;&nbsp;';
 2258:             }
 2259:             unless ($env{'environment.icons'} eq 'iconsonly') {
 2260:                 $alttxt = &mt('Timer');
 2261:                 $title = $alttxt.'&nbsp;';
 2262:             }
 2263:             my $desc = &mt('Countdown to due date/time');
 2264:             return <<END;
 2265: 
 2266: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
 2267: <span id="ddcountcollapse" class="LC_menubuttons_inline_text">
 2268: $collapse
 2269: </span></a>
 2270: <span id="duedatecountdown" class="LC_menubuttons_inline_text" style="display: $currdisp;"></span>
 2271: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
 2272: <span id="ddcountexpand" class="LC_menubuttons_inline_text" >$expand</span>
 2273: <img src="/res/adm/pages/timer.png" title="$desc" class="LC_icon" alt="$alttxt" /><span class="LC_menubuttons_inline_text">$title</span></a>
 2274: END
 2275:         }
 2276:     }
 2277:     return;
 2278: }
 2279: 
 2280: # ================================================================ Main Program
 2281: 
 2282: BEGIN {
 2283:     if (! defined($readdesk)) {
 2284:         {
 2285:             my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
 2286:             if ( CORE::open( my $config,"<$tabfile") ) {
 2287:                 while (my $configline=<$config>) {
 2288:                     $configline=(split(/\#/,$configline))[0];
 2289:                     $configline=~s/^\s+//;
 2290:                     chomp($configline);
 2291:                     if ($configline=~/^cat\:/) {
 2292:                         my @entries=split(/\:/,$configline);
 2293:                         $category_positions{$entries[2]}=$entries[1];
 2294:                         $category_names{$entries[2]}=$entries[3];
 2295:                     } elsif ($configline=~/^prim\:/) {
 2296:                         my @entries = (split(/\:/, $configline))[1..5];
 2297:                         push @primary_menu, \@entries;
 2298:                     } elsif ($configline=~/^primsub\:/) {
 2299:                         my ($parent,@entries) = (split(/\:/, $configline))[1..4];
 2300:                         push (@{$primary_submenu{$parent}},\@entries);
 2301:                     } elsif ($configline=~/^scnd\:/) {
 2302:                         my @entries = (split(/\:/, $configline))[1..5];
 2303:                         push @secondary_menu, \@entries; 
 2304:                     } elsif ($configline=~/^scndsub\:/) {
 2305:                         my ($parent,@entries) = (split(/\:/, $configline))[1..4];
 2306:                         push (@{$secondary_submenu{$parent}},\@entries);
 2307:                     } elsif ($configline) {
 2308:                         push(@desklines,$configline);
 2309:                     }
 2310:                 }
 2311:                 CORE::close($config);
 2312:             }
 2313:         }
 2314:         $readdesk='done';
 2315:     }
 2316: }
 2317: 
 2318: 1;
 2319: __END__
 2320: 

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