File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.284: download - view: text, annotated - select for diffs
Tue Oct 6 14:06:12 2009 UTC (14 years, 7 months ago) by droeschl
Branches: MAIN
CVS tags: HEAD
Added missing <li> tag for helplink.

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

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