File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.315.2.4: download - view: text, annotated - select for diffs
Tue Sep 14 03:16:04 2010 UTC (13 years, 8 months ago) by raeburn
Branches: version_2_10_X
- Backport 1.339.

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

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