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

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

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