File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.244.2.16: download - view: text, annotated - select for diffs
Sun May 23 20:46:51 2010 UTC (14 years ago) by raeburn
Branches: version_2_9_X
- Remove surplus line after changes in 1.244.2.12.
- Consistent wording.

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

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