Annotation of loncom/interface/lonmenu.pm, revision 1.244.2.18

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

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