File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.309.2.22: download - view: text, annotated - select for diffs
Sun Dec 5 17:24:13 2010 UTC (13 years, 5 months ago) by raeburn
Branches: GCI_3
- Customization for GCI_3.
  - Suport for multiple Concept Inventories.

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

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