File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.315.2.6: download - view: text, annotated - select for diffs
Thu Dec 30 21:36:50 2010 UTC (13 years, 5 months ago) by raeburn
Branches: version_2_10_X
- Support for pop-up Course Contents window (remotenavmap) retained in 2.10.

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

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