File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.301: download - view: text, annotated - select for diffs
Tue Nov 10 13:58:55 2009 UTC (14 years, 6 months ago) by droeschl
Branches: MAIN
CVS tags: HEAD
Changed innerregister menu to a new layout. All options available to students are
listed in the same line as breadcrumbs, advanced options which are only available
to roles such as course coordinators are listed in a seperate menu below.
This is work in progress.

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

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