File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.315: download - view: text, annotated - select for diffs
Wed Mar 3 21:33:15 2010 UTC (14 years, 3 months ago) by droeschl
Branches: MAIN
CVS tags: version_2_10_X, HEAD
- replaced frameset by iframe in lonwrapper
    ! IE 7 doesn't scale iframe to 100% height, IE 6 and 8 do
    ! scrolling in Mobile Safari is limited
- added styles for iframe to loncommon
- replaced menubuttons call in lonwrapper by start_page call to make full use of the new header
- removed remote control specific code (RC will be removed shortly)
- replaced code in lonsyllabus with a call to new wrapper routine
- removed subs initlittle and menubutton from lonmenu since they aren't needed anymore

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

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