File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.309.2.24: download - view: text, annotated - select for diffs
Tue Dec 7 04:33:49 2010 UTC (13 years, 5 months ago) by raeburn
Branches: GCI_3
- Customization for GCI_3
  - Tabs displayed to faculty depend on Concept Inventory in use.

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

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