File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.296: download - view: text, annotated - select for diffs
Wed Oct 28 09:01:59 2009 UTC (14 years, 7 months ago) by droeschl
Branches: MAIN
CVS tags: HEAD
Small optimizations.

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

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