File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.309.2.17: download - view: text, annotated - select for diffs
Thu Oct 7 15:39:27 2010 UTC (13 years, 8 months ago) by raeburn
Branches: GCI_3
- Customization for GCI_3.
  - Home link in primary menu only shown to GCI Faculty
  - Roles link in primary menu
  - Skip all but first link in secondary menu unless in course or CSTR.
  - No "Return to Last Location" unless in course.
  - Backport 1.339.

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

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