File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.248: download - view: text, annotated - select for diffs
Mon Dec 8 23:07:03 2008 UTC (15 years, 5 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Bug 5839. DCs can set availability of User Tools.
- Don't show Portfolio and Blog links in Main Menu if these User Tools are unavailable to the user.

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

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