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

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

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