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

1.1       www         1: # The LearningOnline Network with CAPA
                      2: # Routines to control the menu
                      3: #
1.201   ! albertel    4: # $Id: lonmenu.pm,v 1.200 2006/07/31 21:53:45 foxr 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: 
                     39: package Apache::lonmenu;
                     40: 
                     41: use strict;
1.152     albertel   42: use Apache::lonnet;
1.47      matthew    43: use Apache::lonhtmlcommon();
1.115     albertel   44: use Apache::loncommon();
1.127     albertel   45: use Apache::lonenc();
1.88      www        46: use Apache::lonlocal;
1.183     www        47: use lib '/home/httpd/lib/perl/';
                     48: use LONCAPA;
1.88      www        49: 
1.2       www        50: use vars qw(@desklines $readdesk);
1.88      www        51: 
                     52: 
1.56      www        53: my @inlineremote;
1.38      www        54: 
1.88      www        55: # ================================================================ Little texts
                     56: 
                     57: sub initlittle {
                     58:     return &Apache::lonlocal::texthash('ret' => 'Return to Last Location',
                     59: 				       'nav' => 'Navigate Contents',
                     60: 				       'main' => 'Main Menu',
1.152     albertel   61:                                        'roles' => ($env{'user.adv'}?
1.149     www        62:                                                     'Roles':'Courses'),
1.151     www        63:                                        'docs' => 'Course Documents',
1.149     www        64:                                        'exit' => 'Exit',
1.165     raeburn    65: 				       'launch' => 'Launch Remote Control',
1.188     albertel   66:                                        'groups' => 'Groups',
1.184     raeburn    67:                                        'gdoc' => 'Group Documents',
                     68:                                        );
1.88      www        69: }
                     70: 
1.40      www        71: # ============================= This gets called at the top of the body section
1.38      www        72: 
                     73: sub menubuttons {
                     74:     my $forcereg=shift;
1.40      www        75:     my $registration=shift;
1.131     raeburn    76:     my $titletable=shift;
1.112     albertel   77:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                     78: 					    ['inhibitmenu']);
1.152     albertel   79:     if (($env{'form.inhibitmenu'} eq 'yes') ||
1.149     www        80:         ($ENV{'REQUEST_URI'} eq '/adm/logout')) { return ''; }
1.175     albertel   81: 
                     82:     if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
                     83: 
1.163     www        84:     my %lt=&initlittle();
1.55      www        85:     my $navmaps='';
1.59      www        86:     my $reloadlink='';
1.151     www        87:     my $docs='';
1.165     raeburn    88:     my $groups='';
                     89:     my $showgroups=0;
1.183     www        90:     my $escurl=&escape(&Apache::lonenc::check_encrypt($env{'request.noversionuri'}));
                     91:     my $escsymb=&escape(&Apache::lonenc::check_encrypt($env{'request.symb'}));
1.176     albertel   92: 
1.199     albertel   93:     my $logo=&Apache::loncommon::lonhttpdurl("/adm/lonIcons/minilogo.gif");
                     94:     $logo = '<td class="LC_top_nav_logo"><a href="/adm/about.html"><img src="'.
                     95: 	$logo.'" alt="LON-CAPA Logo" /></a></td>';
                     96: 
1.152     albertel   97:     if ($env{'request.state'} eq 'construct') {
                     98:         if (($env{'request.noversionuri'} eq '') || (!defined($env{'request.noversionuri'}))) {
                     99:             my $returnurl = $env{'request.filename'};
1.134     raeburn   100:             $returnurl =~ s:^/home/([^/]+)/public_html/(.*)$:/priv/$1/$2:;
1.183     www       101:             $escurl = &escape($returnurl);
1.134     raeburn   102:         }
                    103:     }
1.165     raeburn   104:     if ($env{'request.course.id'}) {
                    105:         my %coursegroups;
1.188     albertel  106:         my $viewgrps_permission =
1.197     raeburn   107: 	    &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
1.165     raeburn   108:         if (!$viewgrps_permission) {
                    109:             %coursegroups = &Apache::lonnet::get_active_groups($env{'user.domain'},$env{'user.name'},$env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'});
1.188     albertel  110: 	}
1.165     raeburn   111:         if ((keys(%coursegroups) > 0) || ($viewgrps_permission)) {
                    112:             $showgroups = 1;
                    113:         }
                    114:     }
                    115: 
1.152     albertel  116:     if ($env{'browser.interface'} eq 'textual') {
1.41      www       117: # Textual display only
1.152     albertel  118:         if ($env{'request.course.id'}) {
1.55      www       119: 	    $navmaps=(<<ENDNAV);
1.181     albertel  120: <a href="/adm/navmaps?postdata=$escurl&amp;postsymb=$escsymb" target="_top">$lt{'nav'}</a>
1.55      www       121: ENDNAV
1.152     albertel  122:             if (($env{'request.noversionuri'}=~/^\/adm\//) &&
                    123:          ($env{'request.noversionuri'}!~/^\/adm\/wrapper\//) &&
1.193     raeburn   124:          ($env{'request.noversionuri'}!~/^\/adm\/.*\/(smppg|bulletinboard|aboutme)(\?|$)/)) {
1.183     www       125:                 my $escreload=&escape('return:');
1.59      www       126:                 $reloadlink=(<<ENDRELOAD);
1.176     albertel  127: <a href="/adm/flip?postdata=$escreload" target="_top">$lt{'ret'}</a>
1.59      www       128: ENDRELOAD
                    129:             }
1.152     albertel  130: 	    if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1.151     www       131:                $docs=(<<ENDDOCS);
1.176     albertel  132: <a href="/adm/coursedocs" target="_top">$lt{'docs'}</a>
1.151     www       133: ENDDOCS
                    134:             }
1.197     raeburn   135:             if ($showgroups) {
                    136:                 $groups =(<<ENDGROUPS);
                    137: <a href="/adm/coursegroups" target="_top">$lt{'groups'}</a>
                    138: ENDGROUPS
                    139:             }
1.194     banghart  140: 	}
1.130     albertel  141:         my $form=&serverform();
1.116     albertel  142:         my $utility=&utilityfunctions();
1.48      www       143: 	my $output=(<<ENDMAINMENU);
1.129     albertel  144: <script type="text/javascript">
1.150     albertel  145: // BEGIN LON-CAPA Internal
1.116     albertel  146: $utility
1.44      www       147: </script>
1.176     albertel  148: <div id="LC_top_nav">
1.88      www       149: <a href="/adm/menu" target="_top">$lt{'main'}</a>
1.165     raeburn   150: $reloadlink $navmaps $docs $groups
1.176     albertel  151: <a href="/adm/roles" target="_top">$lt{'roles'}</a>
                    152: <a href="/adm/logout" target="_top">$lt{'exit'}</a>
                    153: </div>
1.149     www       154: <br />
1.129     albertel  155: <script type="text/javascript">
1.44      www       156: // END LON-CAPA Internal
                    157: </script>
1.130     albertel  158: $form
1.44      www       159: ENDMAINMENU
1.173     albertel  160:         if ($registration) { $output.=&innerregister($forcereg); }
1.48      www       161: 	return $output."<hr />";
1.152     albertel  162:     } elsif ($env{'environment.remote'} eq 'off') {
1.48      www       163: # Remote Control is switched off
1.58      www       164: # figure out colors
1.88      www       165: 	my %lt=&initlittle();
1.172     albertel  166: 
1.58      www       167:         my $domain=&Apache::loncommon::determinedomain();
1.172     albertel  168: 	my $function =&Apache::loncommon::get_users_function();
1.58      www       169:         my $link=&Apache::loncommon::designparm($function.'.link',$domain);
                    170:         my $alink=&Apache::loncommon::designparm($function.'.alink',$domain);
                    171:         my $vlink=&Apache::loncommon::designparm($function.'.vlink',$domain);
                    172:         my $sidebg=&Apache::loncommon::designparm($function.'.sidebg',$domain);
1.156     albertel  173: 	if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
                    174: 	    return (<<ENDINLINEMENU);
1.176     albertel  175:    <table id="LC_top_nav">
1.156     albertel  176:     <tr>
1.199     albertel  177:       $logo
                    178:       <td></td>
                    179:       <td class="LC_top_nav_exit">
1.176     albertel  180:         <a href="/adm/logout" target="_top">$lt{'exit'}</a>
1.156     albertel  181:      </td>
1.189     albertel  182:     </tr>
1.156     albertel  183:   </table>
                    184: </font>
                    185: ENDINLINEMENU
                    186:         }
1.58      www       187: # Do we have a NAV link?
1.152     albertel  188:         if ($env{'request.course.id'}) {
1.141     albertel  189: 	    my $link='/adm/navmaps?postdata='.$escurl.'&amp;postsymb='.
                    190: 		$escsymb;
1.152     albertel  191: 	    if ($env{'environment.remotenavmap'} eq 'on') {
1.141     albertel  192: 		$link="javascript:gonav('".$link."')";
                    193: 	    }
                    194: 	    $navmaps=(<<ENDNAV);
1.176     albertel  195: <td><a href="$link" target="_top">$lt{'nav'}</a></td>
1.114     albertel  196: ENDNAV
1.186     albertel  197: my $is_group = (&Apache::loncommon::course_type() eq 'Group');
1.152     albertel  198: 	    if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1.186     albertel  199:                 my $text = ($is_group) ? $lt{'gdoc'} : $lt{'docs'};
1.151     www       200: 		$docs=(<<ENDDOCS);
1.184     raeburn   201: <td><a href="/adm/coursedocs" target="_top">$text</a></td>
1.151     www       202: ENDDOCS
                    203:             }
1.197     raeburn   204:             if ($showgroups) {
                    205:                 $groups =(<<ENDGROUPS);
                    206: <td><a href="/adm/coursegroups" target="_top">$lt{'groups'}</a></td>
                    207: ENDGROUPS
                    208:             }
1.144     albertel  209: 	    if (
1.152     albertel  210: 		($env{'request.noversionuri'}=~m[^/(res|public)/] &&
                    211: 		 $env{'request.symb'} eq '')
1.144     albertel  212: 		||
1.152     albertel  213: 		(($env{'request.noversionuri'}=~/^\/adm\//) &&
                    214: 		 ($env{'request.noversionuri'}!~/^\/adm\/wrapper\//) &&
                    215: 		 ($env{'request.noversionuri'}!~
1.193     raeburn   216: 		        m[^/adm/.*/(smppg|bulletinboard|aboutme)($|\?)])
1.144     albertel  217: 		  )
                    218: 		 ) {
1.183     www       219:                 my $escreload=&escape('return:');
1.59      www       220:                 $reloadlink=(<<ENDRELOAD);
1.176     albertel  221: <td><a href="/adm/flip?postdata=$escreload" target="_top">$lt{'ret'}</a></td>
1.59      www       222: ENDRELOAD
                    223:             }
1.55      www       224:         }
1.163     www       225: 	if (($env{'request.state'} eq 'construct') && ($env{'request.course.id'})) {
1.183     www       226: 	    my $escreload=&escape('return:');
1.163     www       227: 	    $reloadlink=(<<ENDCRELOAD);
1.176     albertel  228: <td><a href="/adm/flip?postdata=$escreload" target="_top">$lt{'ret'}</a></td>
1.163     www       229: ENDCRELOAD
                    230:         }
1.58      www       231:         my $reg='';
                    232:         if ($registration) {
1.173     albertel  233:            $reg=&innerregister($forcereg,$titletable);
1.58      www       234:         }
1.130     albertel  235:         my $form=&serverform();
1.116     albertel  236: 	my $utility=&utilityfunctions();
1.179     albertel  237: 	my $remote;
                    238: 	if ($env{'user.adv'}) {
1.181     albertel  239: 	    $remote = '<td><a href="/adm/remote?action=launch&amp;url='.$escurl.'" target="_top">'.$lt{'launch'}.'</a></td>'
1.179     albertel  240: 	}
1.198     albertel  241: 
                    242:         my $helplink=&Apache::loncommon::top_nav_help('Help');
1.58      www       243: 	return (<<ENDINLINEMENU);
1.129     albertel  244: <script type="text/javascript">
1.150     albertel  245: // BEGIN LON-CAPA Internal
                    246: // <![CDATA[
1.116     albertel  247: $utility
1.150     albertel  248: // ]]>
1.48      www       249: </script>
1.176     albertel  250: <table id="LC_top_nav">
1.58      www       251: <tr>
1.199     albertel  252: $logo
1.176     albertel  253: <td><a href="/adm/menu" target="_top">$lt{'main'}</a></td>
1.59      www       254: $reloadlink
1.55      www       255: $navmaps
1.151     www       256: $docs
1.165     raeburn   257: $groups
1.179     albertel  258: $remote
1.176     albertel  259: <td><a href="/adm/roles" target="_top">$lt{'roles'}</a></td>
1.199     albertel  260: <td class="LC_top_nav_help">$helplink</td>
                    261: <td class="LC_top_nav_exit"><a href="/adm/logout" target="_top">$lt{'exit'}</a></td>
1.58      www       262: </tr>
                    263: </table>
1.168     albertel  264: $form
1.129     albertel  265: <script type="text/javascript">
1.48      www       266: // END LON-CAPA Internal
                    267: </script>
1.58      www       268: $reg
1.48      www       269: ENDINLINEMENU
                    270:     } else {
                    271: 	return '';
                    272:     }
1.72      www       273: }
                    274: 
1.40      www       275: # ====================================== This gets called in the header section
1.38      www       276: 
                    277: sub registerurl {
1.173     albertel  278:     my ($forcereg) = @_;
1.38      www       279:     my $result = '';
1.175     albertel  280:     if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
1.66      albertel  281:     my $force_title='';
1.152     albertel  282:     if ($env{'request.state'} eq 'construct') {
1.66      albertel  283: 	$force_title=&Apache::lonxml::display_title();
                    284:     }
1.152     albertel  285:     if (($env{'browser.interface'} eq 'textual') ||
                    286:         ($env{'environment.remote'} eq 'off') ||
                    287:         ((($env{'request.publicaccess'}) || 
1.83      www       288:          (!&Apache::lonnet::is_on_map(
1.183     www       289: 	   &unescape($env{'request.noversionuri'})))) &&
1.38      www       290:         (!$forcereg))) {
1.76      www       291:  	return $result.
                    292:           '<script type="text/javascript">function LONCAPAreg(){;} function LONCAPAstale(){}</script>'.$force_title;
1.38      www       293:     }
1.41      www       294: # Graphical display after login only
1.174     albertel  295:     if ($env{'request.registered'} && !$forcereg) { return ''; }
1.173     albertel  296:     $result.=&innerregister($forcereg);
1.66      albertel  297:     return $result.$force_title;
1.40      www       298: }
                    299: 
                    300: # =========== This gets called in order to register a URL, both with the Remote
                    301: # =========== and in the body of the document
                    302: 
                    303: sub innerregister {
1.173     albertel  304:     my ($forcereg, $titletable) = @_;
1.40      www       305:     my $result = '';
1.120     raeburn   306:     my ($uname,$thisdisfn);
1.152     albertel  307:     my $const_space = ($env{'request.state'} eq 'construct');
1.131     raeburn   308:     my $is_const_dir = 0;
1.120     raeburn   309: 
1.175     albertel  310:     if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
1.40      www       311: 
1.174     albertel  312:     $env{'request.registered'} = 1;
1.40      www       313: 
1.152     albertel  314:     my $textinter=($env{'browser.interface'} eq 'textual');
                    315:     my $noremote=($env{'environment.remote'} eq 'off');
1.49      www       316:     
                    317:     my $textual=($textinter || $noremote);
                    318: 
1.177     albertel  319:     undef(@inlineremote);
1.56      www       320: 
1.38      www       321:     my $reopen=&Apache::lonmenu::reopenmenu();
1.40      www       322: 
1.38      www       323:     my $newmail='';
1.65      www       324:     if ($noremote) {
1.177     albertel  325: 	$newmail='<table id="LC_nav_location"><tr>';
1.65      www       326:     }
1.177     albertel  327:     if (&Apache::lonmsg::newmail()) { 
                    328: 	if ($textual) {
                    329: 	    $newmail.= '<td class="LC_new_mail">
                    330:                    <a href="/adm/communicate" target="_top">'.
                    331: 		   &mt('You have new messages').'</a></td>';
                    332: 	} else {
                    333: 	    $newmail= 'swmenu.setstatus("you have","messages");';
                    334: 	}
                    335:     } elsif (($textual) 
                    336: 	     && ($env{'request.symb'}) 
                    337: 	     && ($env{'request.course.id'})) {
                    338: 	$newmail.= '<td class="LC_current_location">';
1.153     albertel  339: 	my ($mapurl,$rid,$resurl)=
                    340: 	    &Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
1.152     albertel  341:         $newmail.=$env{'course.'.$env{'request.course.id'}.'.description'};
1.61      www       342:         my $maptitle=&Apache::lonnet::gettitle($mapurl);
1.153     albertel  343: 	my $restitle=&Apache::lonnet::gettitle(&Apache::lonnet::symbread());
1.133     albertel  344:         if ($maptitle && $maptitle ne 'default.sequence') {
1.61      www       345: 	    $newmail.=', '.$maptitle;
                    346:         }
                    347:         if ($restitle) {
                    348: 	    $newmail.=': '.$restitle;
                    349:         }
1.177     albertel  350:         $newmail.='&nbsp;&nbsp;&nbsp;</td>';
1.65      www       351:     }
1.152     albertel  352:     if ($env{'request.state'} eq 'construct') {
1.131     raeburn   353:         $newmail = $titletable;
1.150     albertel  354:     } else {
                    355: 	if ($noremote) {
1.181     albertel  356: 	    $newmail.='</tr></table>';
1.150     albertel  357: 	}
1.38      www       358:     }
1.40      www       359:     my $timesync=($textual?'':'swmenu.syncclock(1000*'.time.');');
1.177     albertel  360:     my $tablestart=($noremote?'<table id="LC_menubuttons">':'').
                    361: 	($textinter?'<br /><a href="#content">'.&mt('Skip to Content').'</a><br />':'');
                    362:     my $tableend=($noremote?'</table>':'').($textinter?'<a name="content" />':'');
1.41      www       363: # =============================================================================
                    364: # ============================ This is for URLs that actually can be registered
1.152     albertel  365:     if (($env{'request.noversionuri'}!~m|^/(res/)*adm/|) || ($forcereg)) {
1.40      www       366: # -- This applies to homework problems for users with grading privileges
1.152     albertel  367: 	my $crs='/'.$env{'request.course.id'};
                    368: 	if ($env{'request.course.sec'}) {
                    369: 	    $crs.='_'.$env{'request.course.sec'};
1.107     albertel  370: 	}
                    371: 	$crs=~s/\_/\//g;
                    372: 
1.38      www       373:         my $hwkadd='';
1.152     albertel  374:         if ($env{'request.symb'} ne '' &&
1.161     albertel  375: 	    $env{'request.filename'}=~/\.(problem|exam|quiz|assess|survey|form|task)$/) {
1.79      www       376: 	    if (&Apache::lonnet::allowed('mgr',$crs)) {
1.106     www       377: 		$hwkadd.=&switch('','',7,2,'pgrd.gif','problem[_1]','grades[_3]',
1.40      www       378:                        "gocmd('/adm/grades','gradingmenu')",
                    379:                        'Modify user grades for this assessment resource');
1.154     www       380:             } elsif (&Apache::lonnet::allowed('vgr',$crs)) {
                    381: 		$hwkadd.=&switch('','',7,2,'subm.gif','view sub-[_1]','missions[_1]',
                    382:                        "gocmd('/adm/grades','submission')",
                    383: 		       'View user submissions for this assessment resource');
1.38      www       384:             }
1.107     albertel  385: 	}
1.152     albertel  386: 	if ($env{'request.symb'} ne '' &&
1.145     albertel  387: 	    &Apache::lonnet::allowed('opa',$crs)) {
1.107     albertel  388: 	    $hwkadd.=&switch('','',7,3,'pparm.gif','problem[_2]','parms[_2]',
                    389: 			     "gocmd('/adm/parmset','set')",
1.196     www       390: 			     'Modify parameter settings for this resource');
1.38      www       391: 	}
1.40      www       392: # -- End Homework
1.38      www       393:         ###
                    394:         ### Determine whether or not to display the 'cstr' button for this
                    395:         ### resource
                    396:         ###
                    397:         my $editbutton = '';
1.152     albertel  398:         if ($env{'user.author'}) {
                    399:             if ($env{'request.role'}=~/^(ca|au)/) {
1.38      www       400:                 # Set defaults for authors
                    401:                 my ($top,$bottom) = ('con-','struct');
1.152     albertel  402:                 my $action = "go('/priv/".$env{'user.name'}."');";
                    403:                 my $cadom  = $env{'request.role.domain'};
                    404:                 my $caname = $env{'user.name'};
1.38      www       405:                 my $desc = "Enter my resource construction space";
                    406:                 # Set defaults for co-authors
1.152     albertel  407:                 if ($env{'request.role'} =~ /^ca/) { 
                    408:                     ($cadom,$caname)=($env{'request.role'}=~/(\w+)\/(\w+)$/);
1.38      www       409:                     ($top,$bottom) = ('co con-','struct');
                    410:                     $action = "go('/priv/".$caname."');";
                    411:                     $desc = "Enter construction space as co-author";
                    412:                 }
                    413:                 # Check that we are on the correct machine
                    414:                 my $home = &Apache::lonnet::homeserver($caname,$cadom);
1.109     albertel  415: 		my $allowed=0;
                    416: 		my @ids=&Apache::lonnet::current_machine_ids();
                    417: 		foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                    418: 		if (!$allowed) {
                    419: 		    $editbutton=&switch('','',6,1,$top,,$bottom,$action,$desc);
1.38      www       420:                 }
                    421:             }
                    422:             ##
                    423:             ## Determine if user can edit url.
                    424:             ##
                    425:             my $cfile='';
                    426:             my $cfuname='';
                    427:             my $cfudom='';
1.152     albertel  428:             if ($env{'request.filename'}) {
                    429:                 my $file=&Apache::lonnet::declutter($env{'request.filename'});
1.38      www       430:                 $file=~s/^(\w+)\/(\w+)/\/priv\/$2/;
1.109     albertel  431:                 # Check that the user has permission to edit this resource
1.38      www       432:                 ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$1);
                    433:                 if (defined($cfudom)) {
1.109     albertel  434: 		    my $home=&Apache::lonnet::homeserver($cfuname,$cfudom);
                    435: 		    my $allowed=0;
                    436: 		    my @ids=&Apache::lonnet::current_machine_ids();
                    437: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                    438: 		    if ($allowed) {
1.38      www       439:                         $cfile=$file;
                    440:                     }
                    441:                 }
                    442:             }        
                    443:             # Finally, turn the button on or off
1.120     raeburn   444:             if ($cfile && !$const_space) {
1.40      www       445:                 $editbutton=&switch
1.106     www       446:                     ('','',6,1,'cstr.gif','edit[_1]','resource[_2]',
1.38      www       447:                      "go('".$cfile."');","Edit this resource");
                    448:             } elsif ($editbutton eq '') {
1.191     www       449:                 $editbutton=&clear(6,1);
1.38      www       450:             }
                    451:         }
                    452:         ###
                    453:         ###
1.41      www       454: # Prepare the rest of the buttons
1.120     raeburn   455:         my $menuitems;
                    456:         if ($const_space) {
1.128     albertel  457: 	    my ($uname,$thisdisfn) =
1.152     albertel  458: 		($env{'request.filename'}=~m|^/home/([^/]+)/public_html/(.*)|);
1.121     raeburn   459:             my $currdir = '/priv/'.$uname.'/'.$thisdisfn;
1.131     raeburn   460:             if ($currdir =~ m-/$-) {
                    461:                 $is_const_dir = 1;
                    462:             } else {
                    463:                 $currdir =~ s#[^/]+$##;
1.200     foxr      464: 		my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn);
1.131     raeburn   465:                 $menuitems=(<<ENDMENUITEMS);
                    466: s&6&1&list.gif&list[_1]&dir[_1]&golist('$currdir')&List current directory
1.200     foxr      467: s&6&2&rtrv.gif&retrieve[_1]&version[_1]&gocstr('/adm/retrieve','/~$uname/$cleandisfn')&Retrieve old version
                    468: s&6&3&pub.gif&publish[_1]&resource[_1]&gocstr('/adm/publish','/~$uname/$cleandisfn')&Publish this resource
                    469: s&7&1&del.gif&delete[_1]&resource[_2]&gocstr('/adm/cfile?action=delete','/~$uname/$cleandisfn')&Delete this resource
                    470: s&7&2&prt.gif&prepare[_1]&printout[_1]&gocstr('/adm/printout','/~$uname/$cleandisfn')&Prepare a printable document
1.120     raeburn   471: ENDMENUITEMS
1.131     raeburn   472:             }
1.152     albertel  473:         } elsif (defined($env{'request.course.id'}) && 
                    474: 		 $env{'request.symb'} ne '') {
1.120     raeburn   475: 	    $menuitems=(<<ENDMENUITEMS);
1.41      www       476: c&3&1
1.106     www       477: s&2&1&back.gif&backward[_1]&&gopost('/adm/flip','back:'+currentURL)&Go to the previous resource in the course sequence&1
                    478: 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       479: c&6&3
                    480: c&8&1
                    481: c&8&2
1.106     www       482: s&8&3&prt.gif&prepare[_1]&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
1.175     albertel  483: s&9&1&sbkm.gif&set[_1]&bookmark[_2]&set_bookmark()&Set a bookmark for this resource&1
                    484: s&9&3&anot.gif&anno-[_1]&tations[_1]&annotate()&Make notes and annotations about this resource&1
1.41      www       485: ENDMENUITEMS
1.193     raeburn   486:             unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme)(\?|$)/) {
1.120     raeburn   487: 	        $menuitems.=(<<ENDREALRES);
1.106     www       488: s&6&3&catalog.gif&catalog[_1]&info[_1]&catalog_info()&Show catalog information
                    489: s&8&1&eval.gif&evaluate[_1]&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
                    490: 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       491: ENDREALRES
1.120     raeburn   492: 	    }
                    493:         }
1.41      www       494:         my $buttons='';
                    495:         foreach (split(/\n/,$menuitems)) {
                    496: 	    my ($command,@rest)=split(/\&/,$_);
                    497:             if ($command eq 's') {
                    498: 		$buttons.=&switch('','',@rest);
                    499:             } else {
                    500:                 $buttons.=&clear(@rest);
                    501:             }
                    502:         }
1.148     albertel  503: 
                    504:         if ($textual) {
                    505: 	    my $addremote=0;
                    506: 	    foreach (@inlineremote) { if ($_ ne '') { $addremote=1; } }
                    507: 	    my $inlinebuttons='';
                    508: 	    if ($addremote) {
1.41      www       509: # Registered, textual output
1.103     www       510: 
1.152     albertel  511: 		if ($env{'browser.interface'} eq 'textual') {
1.148     albertel  512: 		    $inlinebuttons=
1.56      www       513:                         join('',map { (defined($_)?$_:'') } @inlineremote);
1.148     albertel  514: 		} else {
                    515: 		    $inlinebuttons=(<<ENDINLINE);
1.129     albertel  516: <tr><td>$inlineremote[21]</td><td>&nbsp;</td><td>$inlineremote[23]</td></tr>
1.103     www       517: <tr><td>$inlineremote[61]</td><td>$inlineremote[62]</td><td>$inlineremote[63]</td></tr>
                    518: <tr><td>$inlineremote[71]</td><td>$inlineremote[72]</td><td>$inlineremote[73]</td></tr>
                    519: <tr><td>$inlineremote[81]</td><td>$inlineremote[82]</td><td>$inlineremote[83]</td></tr>
                    520: <tr><td>$inlineremote[91]</td><td>$inlineremote[92]</td><td>$inlineremote[93]</td></tr>
                    521: ENDINLINE
1.148     albertel  522:                 }
1.103     www       523: 	    }
1.41      www       524: 	    $result =(<<ENDREGTEXT);
1.129     albertel  525: <script type="text/javascript">
1.42      www       526: // BEGIN LON-CAPA Internal
                    527: </script>
1.41      www       528: $timesync
                    529: $newmail
1.58      www       530: $tablestart
1.56      www       531: $inlinebuttons
1.58      www       532: $tableend
1.129     albertel  533: <script type="text/javascript">
1.64      www       534: // END LON-CAPA Internal
1.42      www       535: </script>
                    536: 
1.41      www       537: ENDREGTEXT
                    538: # Registered, graphical output
                    539:         } else {
1.152     albertel  540: 	    my $requri=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
1.183     www       541: 	    $requri=&Apache::lonenc::check_encrypt(&unescape($requri));
1.152     albertel  542: 	    my $cursymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
1.113     albertel  543: 	    my $navstatus=&get_nav_status();
1.140     albertel  544: 	    my $clearcstr;
1.148     albertel  545: 
1.152     albertel  546: 	    if ($env{'user.adv'}) { $clearcstr='clearbut(6,1)'; }
1.41      www       547: 	    $result = (<<ENDREGTHIS);
1.38      www       548:      
1.129     albertel  549: <script type="text/javascript">
1.150     albertel  550: // BEGIN LON-CAPA Internal
1.42      www       551: var swmenu=null;
1.38      www       552: 
                    553:     function LONCAPAreg() {
                    554: 	  swmenu=$reopen;
                    555:           swmenu.clearTimeout(swmenu.menucltim);
                    556:           $timesync
                    557:           $newmail
1.41      www       558:           $buttons
1.84      www       559: 	  swmenu.currentURL="$requri";
1.85      www       560:           swmenu.reloadURL=swmenu.currentURL+window.location.search;
1.125     albertel  561:           swmenu.currentSymb="$cursymb";
                    562:           swmenu.reloadSymb="$cursymb";
1.38      www       563:           swmenu.currentStale=0;
1.113     albertel  564: 	  $navstatus
1.38      www       565:           $hwkadd
                    566:           $editbutton
                    567:     }
                    568: 
                    569:     function LONCAPAstale() {
                    570: 	  swmenu=$reopen
                    571:           swmenu.currentStale=1;
                    572:           if (swmenu.reloadURL!='' && swmenu.reloadURL!= null) { 
                    573:              swmenu.switchbutton
                    574:              (3,1,'reload.gif','return','location','go(reloadURL)','Return to the last known location in the course sequence');
                    575: 	  }
                    576:           swmenu.clearbut(7,2);
                    577:           swmenu.clearbut(7,3);
                    578:           swmenu.menucltim=swmenu.setTimeout(
                    579:  'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+
1.140     albertel  580:  'clearbut(9,1);clearbut(9,3);clearbut(6,3);$clearcstr',
1.38      www       581: 			  2000);
                    582:       }
                    583: 
1.150     albertel  584: // END LON-CAPA Internal 
1.38      www       585: </script>
                    586: ENDREGTHIS
1.41      www       587:         }
                    588: # =============================================================================
1.38      www       589:     } else {
1.41      www       590: # ========================================== This can or will not be registered
                    591:         if ($textual) {
                    592: # Not registered, textual
                    593: 	    $result= (<<ENDDONOTREGTEXT);
                    594: ENDDONOTREGTEXT
                    595:         } else {
                    596: # Not registered, graphical
                    597:            $result = (<<ENDDONOTREGTHIS);
1.38      www       598: 
1.129     albertel  599: <script type="text/javascript">
1.38      www       600: // BEGIN LON-CAPA Internal
1.42      www       601: var swmenu=null;
1.38      www       602: 
                    603:     function LONCAPAreg() {
                    604: 	  swmenu=$reopen
                    605:           $timesync
                    606:           swmenu.currentStale=1;
                    607:           swmenu.clearbut(2,1);
                    608:           swmenu.clearbut(2,3);
                    609:           swmenu.clearbut(8,1);
                    610:           swmenu.clearbut(8,2);
                    611:           swmenu.clearbut(8,3);
                    612:           if (swmenu.currentURL) {
                    613:              swmenu.switchbutton
                    614:               (3,1,'reload.gif','return','location','go(currentURL)');
                    615:  	  } else {
                    616: 	      swmenu.clearbut(3,1);
                    617:           }
                    618:     }
                    619: 
                    620:     function LONCAPAstale() {
                    621:     }
                    622: 
                    623: // END LON-CAPA Internal
                    624: </script>
                    625: ENDDONOTREGTHIS
1.41      www       626:        }
                    627: # =============================================================================
1.38      www       628:     }
                    629:     return $result;
                    630: }
                    631: 
                    632: sub loadevents() {
1.152     albertel  633:     if ($env{'request.state'} eq 'construct' ||
1.175     albertel  634: 	$env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
1.38      www       635:     return 'LONCAPAreg();';
                    636: }
                    637: 
                    638: sub unloadevents() {
1.152     albertel  639:     if ($env{'request.state'} eq 'construct' ||
1.175     albertel  640: 	$env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
1.38      www       641:     return 'LONCAPAstale();';
                    642: }
1.30      www       643: 
1.32      www       644: # ============================================================= Start up remote
                    645: 
                    646: sub startupremote {
                    647:     my ($lowerurl)=@_;
1.152     albertel  648:     if (($env{'browser.interface'} eq 'textual') ||
                    649:         ($env{'environment.remote'} eq 'off')) {
1.34      www       650:      return ('<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.$lowerurl.'" />');
                    651:     }
1.49      www       652: #
                    653: # The Remote actually gets launched!
                    654: #
1.32      www       655:     my $configmenu=&rawconfig();
1.183     www       656:     my $esclowerurl=&escape($lowerurl);
1.119     www       657:     my $message=&mt('"Waiting for Remote Control window to load: "+[_1]','waited');
1.32      www       658:     return(<<ENDREMOTESTARTUP);
1.129     albertel  659: <script type="text/javascript">
1.118     albertel  660: var timestart;
1.35      www       661: function wheelswitch() {
1.118     albertel  662:     if (typeof(document.wheel) != 'undefined') {
                    663: 	if (typeof(document.wheel.spin) != 'undefined') {
                    664: 	    var date=new Date();
                    665: 	    var waited=Math.round(30-((date.getTime()-timestart)/1000));
                    666: 	    document.wheel.spin.value=$message;
                    667: 	}
                    668:     }
1.35      www       669:    if (window.status=='|') { 
                    670:       window.status='/'; 
                    671:    } else {
                    672:       if (window.status=='/') {
                    673:          window.status='-';
                    674:       } else {
                    675:          if (window.status=='-') { 
                    676:             window.status='\\\\'; 
                    677:          } else {
                    678:             if (window.status=='\\\\') { window.status='|'; }
                    679:          }
                    680:       }
                    681:    } 
                    682: }
                    683: 
1.32      www       684: // ---------------------------------------------------------- The wait function
                    685: var canceltim;
                    686: function wait() {
                    687:    if ((menuloaded==1) || (tim==1)) {
1.35      www       688:       window.status='Done.';
1.32      www       689:       if (tim==0) {
                    690:          clearTimeout(canceltim);
                    691:          $configmenu
                    692:          window.location='$lowerurl';  
                    693:       } else {
1.52      www       694: 	  window.location='/adm/remote?action=collapse&url=$esclowerurl';
1.32      www       695:       }
                    696:    } else {
1.35      www       697:       wheelswitch();
                    698:       setTimeout('wait();',200);
1.32      www       699:    }
                    700: }
                    701: 
                    702: function main() {
1.52      www       703:    canceltim=setTimeout('tim=1;',30000);
1.35      www       704:    window.status='-';
1.118     albertel  705:    var date=new Date();
                    706:    timestart=date.getTime();
1.32      www       707:    wait();
                    708: }
                    709: 
                    710: </script>
                    711: ENDREMOTESTARTUP
                    712: }
                    713: 
                    714: sub setflags() {
                    715:     return(<<ENDSETFLAGS);
1.129     albertel  716: <script type="text/javascript">
1.32      www       717:     menuloaded=0;
                    718:     tim=0;
                    719: </script>
                    720: ENDSETFLAGS
                    721: }
                    722: 
                    723: sub maincall() {
1.152     albertel  724:     if (($env{'browser.interface'} eq 'textual') ||
                    725:         ($env{'environment.remote'} eq 'off')) { return ''; }
1.32      www       726:     return(<<ENDMAINCALL);
1.129     albertel  727: <script type="text/javascript">
1.32      www       728:     main();
                    729: </script>
                    730: ENDMAINCALL
                    731: }
1.118     albertel  732: 
                    733: sub load_remote_msg {
                    734:     my ($lowerurl)=@_;
                    735: 
1.152     albertel  736:     if (($env{'browser.interface'} eq 'textual') ||
                    737:         ($env{'environment.remote'} eq 'off')) { return ''; }
1.118     albertel  738: 
1.183     www       739:     my $esclowerurl=&escape($lowerurl);
1.119     www       740:     my $link=&mt('<a href="[_1]">Continue</a> on in Inline Menu mode',
1.182     albertel  741: 		 "/adm/remote?action=collapse&amp;url=$esclowerurl");
1.118     albertel  742:     return(<<ENDREMOTEFORM);
                    743: <p>
                    744: <form name="wheel">
1.119     www       745: <input name="spin" type="text" size="60" />
1.118     albertel  746: </form>
                    747: </p>
                    748: <p>$link</p>
                    749: ENDREMOTEFORM
                    750: }
1.30      www       751: # ================================================================= Reopen menu
                    752: 
                    753: sub reopenmenu {
1.152     albertel  754:    if (($env{'browser.interface'} eq 'textual') ||
                    755:        ($env{'environment.remote'} eq 'off')) { return ''; }
1.30      www       756:    my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
1.47      matthew   757:    my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
                    758:    return('window.open('.$nothing.',"'.$menuname.'","",false);');
1.30      www       759: } 
                    760: 
1.1       www       761: # =============================================================== Open the menu
                    762: 
                    763: sub open {
1.22      www       764:     my $returnval='';
1.152     albertel  765:     if (($env{'browser.interface'} eq 'textual') ||
                    766:         ($env{'environment.remote'} eq 'off')) { 
1.111     albertel  767: 	return '<script type="text/javascript">self.name="loncapaclient";</script>';
                    768:     }
1.30      www       769:     my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
1.22      www       770:     unless (shift eq 'unix') {
                    771: # resizing does not work on linux because of virtual desktop sizes
                    772:        $returnval.=(<<ENDRESIZE);
                    773: if (window.screen) {
1.28      www       774:     self.resizeTo(screen.availWidth-215,screen.availHeight-55);
1.22      www       775:     self.moveTo(190,15);
                    776: }
                    777: ENDRESIZE
                    778:     }
                    779:     $returnval.=(<<ENDOPEN);
1.35      www       780: window.status='Opening LON-CAPA Remote Control';
1.30      www       781: var menu=window.open("/res/adm/pages/menu.html","$menuname",
1.191     www       782: "height=375,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5");
1.71      www       783: self.name='loncapaclient';
1.1       www       784: ENDOPEN
1.129     albertel  785:     return '<script type="text/javascript">'.$returnval.'</script>';
1.1       www       786: }
                    787: 
1.2       www       788: 
                    789: # ================================================================== Raw Config
                    790: 
1.3       www       791: sub clear {
                    792:     my ($row,$col)=@_;
1.152     albertel  793:     unless (($env{'browser.interface'} eq 'textual') ||
                    794:             ($env{'environment.remote'} eq 'off')) {
1.35      www       795:        return "\n".qq(window.status+='.';swmenu.clearbut($row,$col););
1.56      www       796:    } else { 
                    797:        $inlineremote[10*$row+$col]='';
                    798:        return ''; 
                    799:    }
1.3       www       800: }
                    801: 
1.40      www       802: # ============================================ Switch a button or create a link
1.25      matthew   803: # Switch acts on the javascript that is executed when a button is clicked.  
                    804: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
1.40      www       805: 
1.2       www       806: sub switch {
1.40      www       807:     my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$nobreak)=@_;
1.2       www       808:     $act=~s/\$uname/$uname/g;
                    809:     $act=~s/\$udom/$udom/g;
1.88      www       810:     $top=&mt($top);
                    811:     $bot=&mt($bot);
                    812:     $desc=&mt($desc);
1.105     www       813:     $img=&mt($img);
1.172     albertel  814: 
1.152     albertel  815:     unless (($env{'browser.interface'} eq 'textual')  ||
                    816:             ($env{'environment.remote'} eq 'off')) {
1.50      www       817: # Remote
1.34      www       818:        return "\n".
1.35      www       819:  qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
1.152     albertel  820:    } elsif ($env{'browser.interface'} eq 'textual') {
1.50      www       821: # Accessibility
                    822:        if ($nobreak==2) { return ''; }
                    823:        my $text=$top.' '.$bot;
1.78      www       824:        $text=~s/\s*\-\s*//gs;
1.94      www       825:        if ($nobreak) {
                    826: 	   $inlineremote[10*$row+$col]=
                    827: 	       '<a href="javascript:'.$act.';">'.$text.'</a>';
                    828:        } else {
                    829: 	   $inlineremote[10*$row+$col]="\n<br />".
1.100     www       830: 	       $desc.' <a href="javascript:'.$act.';">'.$text.'</a>';
1.94      www       831:        }
1.34      www       832:    } else {
1.50      www       833: # Inline Remote
1.41      www       834:        if ($nobreak==2) { return ''; }
1.34      www       835:        my $text=$top.' '.$bot;
1.78      www       836:        $text=~s/\s*\-\s*//gs;
1.105     www       837: 
                    838:        my $lonhttpdPort=$Apache::lonnet::perlvar{'lonhttpdPort'};
                    839:        if (!defined($lonhttpdPort)) { $lonhttpdPort='8080'; }
1.99      www       840:        my $pic=
1.177     albertel  841: 	   '<img alt="'.$text.'" src="http://'.$ENV{'HTTP_HOST'}.
1.105     www       842: 	   ':'.$lonhttpdPort.'/res/adm/pages/'.$img.'" align="'.
1.103     www       843: 	   ($nobreak==3?'right':'left').'" />';
1.177     albertel  844:        if ($env{'browser.interface'} eq 'faketextual') {
1.103     www       845: # Accessibility
                    846: 	   if ($nobreak==3) {
                    847: 	       $inlineremote[10*$row+$col]="\n".
1.177     albertel  848: 		   '<td class="LC_menubuttons_text" align="right">'.$text.
                    849: 		   '</td><td class="LC_menubuttons_img" align="left">'.
1.103     www       850: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
                    851: 	   } elsif ($nobreak) {
                    852: 	       $inlineremote[10*$row+$col]="\n<tr>".
1.177     albertel  853: 		   '<td class="LC_menubuttons_img" align="left">'.
                    854: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td>
                    855:                     <td class="LC_menubuttons_text" align="left">'.$text.'</td>';
1.103     www       856: 	   } else {
                    857: 	       $inlineremote[10*$row+$col]="\n<tr>".
1.177     albertel  858: 		   '<td class="LC_menubuttons_img" align="left">'.
1.103     www       859: 		   '<a href="javascript:'.$act.';">'.$pic.
1.177     albertel  860: 		   '</a></td><td class="LC_menubuttons_text" colspan="3">'.
                    861: 		   $desc.'</td></tr>';
1.103     www       862: 	   }
1.94      www       863:        } else {
1.103     www       864: # Inline Menu
                    865: 	   $inlineremote[10*$row+$col]=
                    866: 		   '<a href="javascript:'.$act.';">'.$pic.
1.177     albertel  867: 		   '</a><span class="LC_menubuttons_inline_text">'.$desc.'</span>';
1.94      www       868:        }
1.34      www       869:    }
1.56      www       870:     return '';
1.2       www       871: }
                    872: 
                    873: sub secondlevel {
                    874:     my $output='';
                    875:     my 
1.27      www       876:     ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc)=@_;
1.2       www       877:     if ($prt eq 'any') {
1.27      www       878: 	   $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.2       www       879:     } elsif ($prt=~/^r(\w+)/) {
                    880:         if ($rol eq $1) {
1.27      www       881:            $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.2       www       882:         }
                    883:     }
                    884:     return $output;
                    885: }
                    886: 
1.18      www       887: sub openmenu {
1.30      www       888:     my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
1.152     albertel  889:     if (($env{'browser.interface'} eq 'textual') ||
                    890:         ($env{'environment.remote'} eq 'off')) { return ''; }
1.47      matthew   891:     my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
                    892:     return "window.open(".$nothing.",'".$menuname."');";
1.18      www       893: }
                    894: 
1.56      www       895: sub inlinemenu {
                    896:     @inlineremote=();
                    897:     undef @inlineremote;
                    898:     &rawconfig(1);
                    899:     return join('',map { (defined($_)?$_:'') } @inlineremote);
                    900: }
                    901: 
1.2       www       902: sub rawconfig {
1.34      www       903:     my $textualoverride=shift;
                    904:     my $output='';
1.152     albertel  905:     unless (($env{'browser.interface'} eq 'textual') ||
                    906:             ($env{'environment.remote'} eq 'off')) {
1.35      www       907:        $output.=
                    908:  "window.status='Opening Remote Control';var swmenu=".&openmenu().
                    909: "\nwindow.status='Configuring Remote Control ';";
1.34      www       910:     } else {
                    911:        unless ($textualoverride) { return ''; }
                    912:     }
1.152     albertel  913:     my $uname=$env{'user.name'};
                    914:     my $udom=$env{'user.domain'};
                    915:     my $adv=$env{'user.adv'};
                    916:     my $author=$env{'user.author'};
1.5       www       917:     my $crs='';
1.152     albertel  918:     if ($env{'request.course.id'}) {
                    919:        $crs='/'.$env{'request.course.id'};
                    920:        if ($env{'request.course.sec'}) {
                    921: 	   $crs.='_'.$env{'request.course.sec'};
1.7       www       922:        }
1.8       www       923:        $crs=~s/\_/\//g;
1.5       www       924:     }
1.152     albertel  925:     my $pub=($env{'request.state'} eq 'published');
                    926:     my $con=($env{'request.state'} eq 'construct');
                    927:     my $rol=$env{'request.role'};
                    928:     my $requested_domain = $env{'request.role.domain'};
1.184     raeburn   929:     foreach my $line (@desklines) {
                    930:         my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc)=split(/\:/,$line);
1.3       www       931:         $prt=~s/\$uname/$uname/g;
                    932:         $prt=~s/\$udom/$udom/g;
1.5       www       933:         $prt=~s/\$crs/$crs/g; 
1.25      matthew   934:         $prt=~s/\$requested_domain/$requested_domain/g;
1.186     albertel  935:         my $type = &Apache::loncommon::course_type();
1.184     raeburn   936:         if ($type eq 'Group') {
                    937:             $desc = &convert_menu_function($desc,$type);
                    938:         }
1.3       www       939:         if ($pro eq 'clear') {
1.4       www       940: 	    $output.=&clear($row,$col);
1.3       www       941:         } elsif ($pro eq 'any') {
1.2       www       942:                $output.=&secondlevel(
1.27      www       943: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
1.2       www       944: 	} elsif ($pro eq 'smp') {
                    945:             unless ($adv) {
                    946:                $output.=&secondlevel(
1.27      www       947:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
1.2       www       948:             }
                    949:         } elsif ($pro eq 'adv') {
                    950:             if ($adv) {
                    951:                $output.=&secondlevel(
1.27      www       952: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
1.2       www       953:             }
1.81      matthew   954:         } elsif (($pro=~/^p(\w+)/) && ($prt)) {
1.2       www       955: 	    if (&Apache::lonnet::allowed($1,$prt)) {
1.27      www       956:                $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.4       www       957:             }
1.26      www       958:         } elsif ($pro eq 'course') {
1.152     albertel  959:             if ($env{'request.course.fn'}) {
1.27      www       960:                $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.81      matthew   961: 	    }
1.124     matthew   962:         } elsif ($pro =~ /^courseenv_(.*)$/) {
                    963:             my $key = $1;
1.152     albertel  964:             if ($env{'course.'.$env{'request.course.id'}.'.'.$key}) {
1.124     matthew   965:                 $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
                    966:             }
1.81      matthew   967:         } elsif ($pro =~ /^course_(.*)$/) {
                    968:             # Check for permissions inside of a course
1.152     albertel  969:             if (($env{'request.course.id'}) &&
                    970:                 (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
                    971:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
1.81      matthew   972:                  )) {
                    973:                 $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.26      www       974: 	    }
1.4       www       975:         } elsif ($pro eq 'author') {
                    976:             if ($author) {
1.152     albertel  977:                 if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
                    978:                     (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
1.19      matthew   979:                     # Check that we are on the correct machine
1.29      matthew   980:                     my $cadom=$requested_domain;
1.152     albertel  981:                     my $caname=$env{'user.name'};
1.29      matthew   982:                     if ($prt eq 'rca') {
                    983: 		       ($cadom,$caname)=
1.152     albertel  984:                                ($env{'request.role'}=~/(\w+)\/(\w+)$/);
1.29      matthew   985:                     }                       
                    986:                     $act =~ s/\$caname/$caname/g;
1.19      matthew   987:                     my $home = &Apache::lonnet::homeserver($caname,$cadom);
1.109     albertel  988: 		    my $allowed=0;
                    989: 		    my @ids=&Apache::lonnet::current_machine_ids();
                    990: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                    991: 		    if ($allowed) {
1.19      matthew   992:                         $output.=switch($caname,$cadom,
1.27      www       993:                                         $row,$col,$img,$top,$bot,$act,$desc);
1.19      matthew   994:                     }
1.6       www       995:                 }
1.2       www       996:             }
                    997:         }
1.13      harris41  998:     }
1.152     albertel  999:     unless (($env{'browser.interface'} eq 'textual') ||
                   1000:             ($env{'environment.remote'} eq 'off')) {
1.35      www      1001:        $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
1.123     www      1002:        if (&Apache::lonmsg::newmail()) { 
                   1003: 	   $output.='swmenu.setstatus("you have","messages");';
                   1004:        }
1.34      www      1005:     }
1.123     www      1006: 
1.2       www      1007:     return $output;
                   1008: }
                   1009: 
                   1010: # ======================================================================= Close
1.1       www      1011: 
                   1012: sub close {
1.152     albertel 1013:     if (($env{'browser.interface'} eq 'textual') ||
                   1014:         ($env{'environment.remote'} eq 'off')) { return ''; }
1.30      www      1015:     my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
1.1       www      1016:     return(<<ENDCLOSE);
1.129     albertel 1017: <script type="text/javascript">
1.35      www      1018: window.status='Accessing Remote Control';
1.30      www      1019: menu=window.open("/adm/rat/empty.html","$menuname",
1.1       www      1020:                  "height=350,width=150,scrollbars=no,menubar=no");
1.35      www      1021: window.status='Disabling Remote Control';
                   1022: menu.active=0;
1.31      www      1023: menu.autologout=0;
1.35      www      1024: window.status='Closing Remote Control';
1.1       www      1025: menu.close();
1.35      www      1026: window.status='Done.';
1.1       www      1027: </script>
                   1028: ENDCLOSE
                   1029: }
                   1030: 
                   1031: # ====================================================================== Footer
                   1032: 
                   1033: sub footer {
                   1034: 
1.33      www      1035: }
                   1036: 
1.122     albertel 1037: sub nav_control_js {
1.152     albertel 1038:     my $nav=($env{'environment.remotenavmap'} eq 'on');
1.122     albertel 1039:     return (<<NAVCONTROL);
                   1040:     var w_loncapanav_flag="$nav";
                   1041: 
                   1042: 
                   1043: function gonav(url) {
                   1044:    if (w_loncapanav_flag != 1) {
                   1045:       gopost(url,'');
                   1046:    }  else {
                   1047:       navwindow=window.open(url,
                   1048:                   "loncapanav","height=600,width=400,scrollbars=1"); 
                   1049:    }
                   1050: }
                   1051: NAVCONTROL
                   1052: }
                   1053: 
1.42      www      1054: sub utilityfunctions {
1.132     raeburn  1055:     my $caller = shift;
1.152     albertel 1056:     unless (($env{'browser.interface'} eq 'textual')  ||
                   1057:         ($env{'environment.remote'} eq 'off') || ($caller eq '/adm/menu')) { return ''; }
                   1058:     my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
1.183     www      1059:     $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
1.125     albertel 1060:     
1.152     albertel 1061:     my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
1.122     albertel 1062:     my $nav_control=&nav_control_js();
1.175     albertel 1063: 
                   1064:     my $start_page_annotate = 
                   1065:         &Apache::loncommon::start_page('Annotator',undef,
                   1066: 				       {'only_body' => 1,
                   1067: 					'js_ready'  => 1,
                   1068: 					'bgcolor'   => '#BBBBBB',
                   1069: 					'add_entries' => {
                   1070: 					    'onload' => 'javascript:document.goannotate.submit();'}});
                   1071: 
                   1072:     my $start_page_bookmark = 
                   1073:         &Apache::loncommon::start_page('Bookmarks',undef,
                   1074: 				       {'only_body' => 1,
                   1075: 					'js_ready'  => 1,
                   1076: 					'bgcolor'   => '#BBBBBB',});
                   1077: 
                   1078:     my $end_page = 
                   1079:         &Apache::loncommon::end_page({'js_ready' => 1});
                   1080: 
1.42      www      1081: return (<<ENDUTILITY)
                   1082: 
                   1083:     var currentURL="$currenturl";
                   1084:     var reloadURL="$currenturl";
                   1085:     var currentSymb="$currentsymb";
                   1086: 
1.114     albertel 1087: $nav_control
                   1088: 
1.42      www      1089: function go(url) {
                   1090:    if (url!='' && url!= null) {
                   1091:        currentURL = null;
                   1092:        currentSymb= null;
                   1093:        window.location.href=url;
                   1094:    }
                   1095: }
                   1096: 
                   1097: function gopost(url,postdata) {
                   1098:    if (url!='') {
                   1099:       this.document.server.action=url;
                   1100:       this.document.server.postdata.value=postdata;
                   1101:       this.document.server.command.value='';
                   1102:       this.document.server.url.value='';
                   1103:       this.document.server.symb.value='';
                   1104:       this.document.server.submit();
                   1105:    }
                   1106: }
                   1107: 
                   1108: function gocmd(url,cmd) {
                   1109:    if (url!='') {
                   1110:       this.document.server.action=url;
                   1111:       this.document.server.postdata.value='';
                   1112:       this.document.server.command.value=cmd;
                   1113:       this.document.server.url.value=currentURL;
                   1114:       this.document.server.symb.value=currentSymb;
                   1115:       this.document.server.submit();
                   1116:    }
1.57      www      1117: }
                   1118: 
1.121     raeburn  1119: function gocstr(url,filename) {
                   1120:     if (url == '/adm/cfile?action=delete') {
                   1121:         this.document.cstrdelete.filename.value = filename
                   1122:         this.document.cstrdelete.submit();
                   1123:         return;
                   1124:     }
1.137     raeburn  1125:     if (url == '/adm/printout') {
                   1126:         this.document.cstrprint.postdata.value = filename
                   1127:         this.document.cstrprint.curseed.value = 0;
                   1128:         this.document.cstrprint.problemtype.value = 0;
1.138     raeburn  1129:         if (this.document.lonhomework) {
                   1130:             if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
                   1131:                 this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
                   1132:             }
                   1133:             if (this.document.lonhomework.problemtype) {
1.164     albertel 1134: 		if (this.document.lonhomework.problemtype.value) {
                   1135: 		    this.document.cstrprint.problemtype.value = 
                   1136: 			this.document.lonhomework.problemtype.value;
                   1137: 		} else if (this.document.lonhomework.problemtype.options) {
                   1138: 		    for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
                   1139: 			if (this.document.lonhomework.problemtype.options[i].selected) {
                   1140: 			    if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') { 
                   1141: 				this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
                   1142: 				}
                   1143: 			}
                   1144: 		    }
                   1145: 		}
                   1146: 	    }
                   1147: 	}
1.137     raeburn  1148:         this.document.cstrprint.submit();
                   1149:         return;
                   1150:     }
1.121     raeburn  1151:     if (url !='') {
                   1152:         this.document.constspace.filename.value = filename;
                   1153:         this.document.constspace.action = url;
                   1154:         this.document.constspace.submit();
                   1155:     }
                   1156: }
                   1157: 
1.131     raeburn  1158: function golist(url) {
                   1159:    if (url!='' && url!= null) {
                   1160:        currentURL = null;
                   1161:        currentSymb= null;
                   1162:        top.location.href=url;
                   1163:    }
                   1164: }
                   1165: 
                   1166: 
1.121     raeburn  1167: 
1.57      www      1168: function catalog_info() {
1.102     albertel 1169:    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      1170: }
                   1171: 
                   1172: function chat_win() {
1.102     albertel 1173:    lonchat=window.open('/res/adm/pages/chatroom.html',"LONchat",'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
1.42      www      1174: }
1.169     raeburn  1175: 
                   1176: function group_chat(group) {
                   1177:    var url = '/adm/groupchat?group='+group;
                   1178:    var winName = 'LONchat_'+group;
                   1179:    grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
                   1180: }
1.175     albertel 1181: 
                   1182: function edit_bookmarks() {
                   1183:    go('');
                   1184:    w_BookmarkPal_flag=1;
                   1185:    bookmarkpal=window.open("/adm/bookmarks",
                   1186:                "BookmarkPal", "width=400,height=505,scrollbars=0");
                   1187: }
                   1188: 
                   1189: function annotate() {
                   1190:    w_Annotator_flag=1;
                   1191:    annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
                   1192:    annotator.document.write(
                   1193:    '$start_page_annotate'
                   1194:   +"<form name='goannotate' target='Annotator' method='post' "
                   1195:   +"action='/adm/annotations'>"
                   1196:   +"<input type='hidden' name='urlnew' value='"+currentURL+"' />"
1.181     albertel 1197:   +"<\\/form>"
1.175     albertel 1198:   +'$end_page');
                   1199:    annotator.document.close();
                   1200: }
                   1201: 
                   1202: function set_bookmark() {
                   1203:    go('');
                   1204:    clienttitle=document.title;
                   1205:    clienthref=location.pathname;
                   1206:    w_bmquery_flag=1;
                   1207:    bmquery=window.open('','bmquery','width=365,height=165,scrollbars=0');
                   1208:    bmquery.document.write(
                   1209:    '$start_page_bookmark'
                   1210:    +"<center><form method='post'"
                   1211:    +" name='newlink' action='/adm/bookmarks' target='bmquery' "
                   1212:    +">\\n <table width=340 height=150 "
1.181     albertel 1213:    +"bgcolor='ffffff' align=center><tr><td>Link Name:<br /><input "
                   1214:    +"type='text' name='title' size=45 value='"+clienttitle+"' />"
                   1215:    +"<br />Address:<br /><input type='text' name='address' size='45' "
                   1216:    +"value='"+clienthref+"' /><br /><center><input type='submit' "
                   1217:    +"value='Save' /> <input type='button' value='Close (no save)' "
                   1218:    +"onclick='javascript:window.close();' /><\\/center><\\/td>"
                   1219:    +"<\\/tr><\\/table><\\/form><\\/center>"
1.175     albertel 1220:    +'$end_page' );
                   1221:    bmquery.document.close();
                   1222: }
                   1223: 
1.42      www      1224: ENDUTILITY
                   1225: }
                   1226: 
                   1227: sub serverform {
                   1228:     return(<<ENDSERVERFORM);
1.181     albertel 1229: <form name="server" action="/adm/logout" method="post" target="_top">
1.42      www      1230: <input type="hidden" name="postdata" value="none" />
                   1231: <input type="hidden" name="command" value="none" />
                   1232: <input type="hidden" name="url" value="none" />
                   1233: <input type="hidden" name="symb" value="none" />
                   1234: </form>
                   1235: ENDSERVERFORM
                   1236: }
1.113     albertel 1237: 
1.121     raeburn  1238: sub constspaceform {
                   1239:     return(<<ENDCONSTSPACEFORM);
1.181     albertel 1240: <form name="constspace" action="/adm/logout" method="post" target="_top">
1.121     raeburn  1241: <input type="hidden" name="filename" value="" />
                   1242: </form>
1.181     albertel 1243: <form name="cstrdelete" action="/adm/cfile" method="post" target="_top">
1.121     raeburn  1244: <input type="hidden" name="action" value="delete" /> 
                   1245: <input type="hidden" name="filename" value="" />
                   1246: </form>
1.181     albertel 1247: <form name="cstrprint" action="/adm/printout" target="_parent" method="post">
1.137     raeburn  1248: <input type="hidden" name="postdata" value="" />
                   1249: <input type="hidden" name="curseed" value="" />
                   1250: <input type="hidden" name="problemtype" value="" />
                   1251: </form>
                   1252: 
1.121     raeburn  1253: ENDCONSTSPACEFORM
                   1254: }
                   1255: 
                   1256: 
1.113     albertel 1257: sub get_nav_status {
                   1258:     my $navstatus="swmenu.w_loncapanav_flag=";
1.152     albertel 1259:     if ($env{'environment.remotenavmap'} eq 'on') {
1.113     albertel 1260: 	$navstatus.="1";
                   1261:     } else {
                   1262: 	$navstatus.="-1";
                   1263:     }
                   1264:     return $navstatus;
                   1265: }
                   1266: 
1.186     albertel 1267: #FIXME this needs to move into mydesktab and the other locations 
                   1268: # the text is generated
1.184     raeburn  1269: sub convert_menu_function {
                   1270:     my ($rolename,$type) = @_;
                   1271:     if ($type eq 'Group') {
                   1272:         $rolename =~ s/student/member/g;
                   1273:         $rolename =~ s/group/team/g;
                   1274:         $rolename =~ s/course/group/g;
                   1275:         $rolename =~ s/Course/Group/g;
                   1276:     }
                   1277:     return $rolename;
                   1278: }
                   1279: 
                   1280: 
1.2       www      1281: # ================================================================ Main Program
                   1282: 
1.16      harris41 1283: BEGIN {
1.166     albertel 1284:     if (! defined($readdesk)) {
                   1285: 	{
                   1286: 	    my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
                   1287: 	    if ( CORE::open( my $config,"<$tabfile") ) {
                   1288: 		while (my $configline=<$config>) {
                   1289: 		    $configline=(split(/\#/,$configline))[0];
                   1290: 		    $configline=~s/^\s+//;
                   1291: 		    chomp($configline);
                   1292: 		    if ($configline) {
                   1293: 			push(@desklines,$configline);
                   1294: 		    }
                   1295: 		}
                   1296: 		CORE::close($config);
                   1297: 	    }
                   1298: 	}
                   1299: 	$readdesk='done';
1.2       www      1300:     }
                   1301: }
1.30      www      1302: 
1.1       www      1303: 1;
                   1304: __END__
                   1305: 
                   1306: 
                   1307: 
                   1308: 
                   1309: 
                   1310: 
                   1311: 

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