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

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

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