File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.309.2.15: download - view: text, annotated - select for diffs
Fri Sep 3 19:20:47 2010 UTC (13 years, 9 months ago) by raeburn
Branches: GCI_3
- Customization for GCI_3.
  - Add a new "Tutorials" tab to provide access to a GCI "course" containing video tutorials.

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

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