File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.295: download - view: text, annotated - select for diffs
Mon Oct 26 21:19:22 2009 UTC (14 years, 7 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Main menu and inline menu use "Community" instead of "Course" when a user's current role is a community role.

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

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