File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.309.2.18: download - view: text, annotated - select for diffs
Mon Nov 8 22:51:23 2010 UTC (13 years, 6 months ago) by raeburn
Branches: GCI_3
- Customization for GCI-3
  - Support for pop-up navigation window
  - Remove reference to undefined css class.

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

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