File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.315.2.15.2.1: download - view: text, annotated - select for diffs
Fri Mar 2 14:48:19 2012 UTC (12 years, 3 months ago) by raeburn
Branches: loncapaMITrelate_1
Diff to branchpoint 1.315.2.15: preferred, unified
- Customization for MITrelate
  - Suppress display of printing icon in inline menu for non-CC roles
    in Mechanics Online course.

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

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