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

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

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