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

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

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