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

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

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