File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.315.2.1: download - view: text, annotated - select for diffs
Wed May 26 19:50:46 2010 UTC (14 years ago) by raeburn
Branches: version_2_10_X
- Backport 1.319, 1.320, 1.322, 1.323, 1.324, 1.326.

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

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