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

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

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