File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.244.2.15: download - view: text, annotated - select for diffs
Sun May 23 19:16:02 2010 UTC (14 years ago) by raeburn
Branches: version_2_9_X
- Course -> Community.

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

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