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

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

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