File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.289: download - view: text, annotated - select for diffs
Fri Oct 16 00:46:01 2009 UTC (14 years, 7 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Bug 6088.
- Omit ellipsis if resource is in top level sequence in course.

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

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