File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.312: download - view: text, annotated - select for diffs
Tue Jan 19 19:00:02 2010 UTC (14 years, 5 months ago) by droeschl
Branches: MAIN
CVS tags: bz6209-base, bz6209, HEAD
- Bug #6064 Breadcrumbs will be visually cut off if text is too long to fit into one line.
- Bug #6081 Breadcrumbs that don't have an href attribute are no longer wrapped with <a> tag.
- Added some POD in lonhtmlcommon and repaired errors and warnings reported by podchecker.
- new functions in lonhtmlcommon:
  o list_from_array: constructs a XHTML list from arraydata
  o funclist_from_array: constructs a XHTML list from arraydata with first item highlighted (see other funclist functions)

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

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