File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.315.2.8: download - view: text, annotated - select for diffs
Fri Jan 7 22:21:02 2011 UTC (13 years, 5 months ago) by raeburn
Branches: version_2_10_X
CVS tags: version_2_10_0_RC2
- Backport more of 1.325.

    1: # The LearningOnline Network with CAPA
    2: # Routines to control the menu
    3: #
    4: # $Id: lonmenu.pm,v 1.315.2.8 2011/01/07 22:21:02 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);
  457:     if ($noremote
  458: 	     && ($env{'request.symb'}) 
  459: 	     && ($env{'request.course.id'})) {
  460: 
  461:         my ($mapurl,$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:         ###
  674:         ###
  675: # Prepare the rest of the buttons
  676:         my $menuitems;
  677:         if ($const_space) {
  678: #
  679: # We are in construction space
  680: #
  681: 	    my ($uname,$thisdisfn) =
  682: 		($env{'request.filename'}=~m|^/home/([^/]+)/public_html/(.*)|);
  683:             my $currdir = '/priv/'.$uname.'/'.$thisdisfn;
  684:             if ($currdir =~ m-/$-) {
  685:                 $is_const_dir = 1;
  686:             } else {
  687:                 $currdir =~ s|[^/]+$||;
  688: 		my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn);
  689: 		my $esc_currdir = &Apache::loncommon::escape_single($currdir);
  690: #
  691: # Probably should be in mydesk.tab
  692: #
  693:                 $menuitems=(<<ENDMENUITEMS);
  694: s&6&1&list.gif&list[_1]&dir[_1]&golist('$esc_currdir')&List current directory
  695: s&6&2&rtrv.gif&retrieve[_1]&version[_1]&gocstr('/adm/retrieve','/~$uname/$cleandisfn')&Retrieve old version
  696: s&6&3&pub.gif&publish[_1]&resource[_3]&gocstr('/adm/publish','/~$uname/$cleandisfn')&Publish this resource
  697: s&7&1&del.gif&delete[_1]&resource[_2]&gocstr('/adm/cfile?action=delete','/~$uname/$cleandisfn')&Delete this resource
  698: s&7&2&prt.gif&prepare[_1]&printout[_1]&gocstr('/adm/printout','/~$uname/$cleandisfn')&Prepare a printable document
  699: ENDMENUITEMS
  700:             }
  701:             if ($noremote) {
  702:                 if (ref($bread_crumbs) eq 'ARRAY') {
  703:                     &Apache::lonhtmlcommon::clear_breadcrumbs();
  704:                     foreach my $crumb (@{$bread_crumbs}){
  705:                         &Apache::lonhtmlcommon::add_breadcrumb($crumb);
  706:                     }
  707:                 }
  708:             }
  709:         } elsif ( defined($env{'request.course.id'}) && 
  710: 		 $env{'request.symb'} ne '' ) {
  711: #
  712: # We are in a course and looking at a registred URL
  713: # Should probably be in mydesk.tab
  714: #
  715: 	    $menuitems=(<<ENDMENUITEMS);
  716: c&3&1
  717: s&2&1&back.gif&backward[_1]&&gopost('/adm/flip','back:'+currentURL)&Go to the previous resource in the course sequence&&1
  718: s&2&3&forw.gif&forward[_1]&&gopost('/adm/flip','forward:'+currentURL)&Go to the next resource in the course sequence&&3
  719: c&6&3
  720: c&8&1
  721: c&8&2
  722: s&8&3&prt.gif&prepare[_1]&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
  723: s&9&1&sbkm.gif&set[_1]&bookmark[_2]&set_bookmark()&Set a bookmark for this resource&&1
  724: ENDMENUITEMS
  725: 
  726: my $currentURL = &Apache::loncommon::get_symb();
  727: my ($symb_old,$symb_old_enc) = &Apache::loncommon::clean_symb($currentURL);
  728: my $annotation = &Apache::loncommon::get_annotation($symb_old,$symb_old_enc);
  729: $menuitems.="s&9&3&";
  730: if(length($annotation) > 0){
  731: 	$menuitems.="anot2.gif";
  732: }else{
  733: 	$menuitems.="anot.gif";
  734: }
  735: $menuitems.="&anno-[_1]&tations[_1]&annotate()&";
  736: $menuitems.="Make notes and annotations about this resource&&1\n";
  737: 
  738:             unless ($noremote) { 
  739:                 my $showreqcrs = &check_for_rcrs();
  740:                 if ($showreqcrs) {
  741:                     $menuitems.="s&8&1&rcrs.gif&request[_1]&course[_16]".
  742:                                 "&go('/adm/requestcourse')&Course requests\n";
  743:                 }
  744:             }
  745:             unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|viewclasslist|portfolio)(\?|$)/) {
  746: 		if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/})) {
  747: 		    $menuitems.=(<<ENDREALRES);
  748: s&6&3&catalog.gif&catalog[_2]&info[_1]&catalog_info()&Show Metadata
  749: ENDREALRES
  750:                 }
  751: 	        $menuitems.=(<<ENDREALRES);
  752: s&8&1&eval.gif&evaluate[_1]&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
  753: 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
  754: ENDREALRES
  755: 	    }
  756:         }
  757: 	if ($env{'request.uri'} =~ /^\/res/) {
  758: 	    $menuitems .= (<<ENDMENUITEMS);
  759: s&8&3&prt.gif&prepare[_1]&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
  760: ENDMENUITEMS
  761: 	}
  762:         my $buttons='';
  763:         foreach (split(/\n/,$menuitems)) {
  764: 	    my ($command,@rest)=split(/\&/,$_);
  765:             my $idx=10*$rest[0]+$rest[1];
  766:             if (&hidden_button_check() eq 'yes') {
  767:                 if ($idx == 21 ||$idx == 23) {
  768:                     $buttons.=&switch('','',@rest);
  769:                 } else {
  770:                     $buttons.=&clear(@rest);
  771:                 }
  772:             } else {  
  773:                 if ($command eq 's') {
  774: 	            $buttons.=&switch('','',@rest);
  775:                 } else {
  776:                     $buttons.=&clear(@rest);
  777:                 }
  778:             }
  779:         }
  780: 
  781:         if ($noremote) {
  782: 	    my $addremote=0;
  783: 	    foreach (@inlineremote) { if ($_ ne '') { $addremote=1; last;} }
  784: 	    my $inlinebuttons='';
  785:     if ($addremote) {
  786: 
  787:         Apache::lonhtmlcommon::clear_breadcrumb_tools();
  788: 
  789:             Apache::lonhtmlcommon::add_breadcrumb_tool(
  790:                 'navigation', @inlineremote[21,23]);
  791: 
  792:         if(hidden_button_check() ne 'yes') {
  793:             Apache::lonhtmlcommon::add_breadcrumb_tool(
  794:                 'tools', @inlineremote[93,91,81,82,83]);
  795: 
  796:             #publish button in construction space
  797:             if ($env{'request.state'} eq 'construct'){
  798:                 Apache::lonhtmlcommon::add_breadcrumb_tool(
  799:                      'advtools', @inlineremote[63]);
  800:             }else{
  801:                 Apache::lonhtmlcommon::add_breadcrumb_tool(
  802:                      'tools', @inlineremote[63]);
  803:             }
  804: 
  805:             unless ($env{'request.noversionuri'}=~ m{^/adm/(navmaps|viewclasslist)(\?|$)}) {
  806:                 Apache::lonhtmlcommon::add_breadcrumb_tool(
  807:                     'advtools', @inlineremote[61,71,72,73,92]);
  808:             }
  809:         }
  810: 
  811: #       # Registered, textual output
  812: #        if ( $env{'environment.icons'} eq 'iconsonly' ) {
  813: #            $inlinebuttons = (<<ENDARROWSINLINE);
  814: #<tr><td>
  815: #$inlineremote[21] $inlineremote[23]
  816: #ENDARROWSINLINE
  817: #            if ( &hidden_button_check() ne 'yes' ) {
  818: #                $inlinebuttons .= (<<ENDINLINEICONS);
  819: #$inlineremote[61] $inlineremote[63]
  820: #$inlineremote[71] $inlineremote[72] $inlineremote[73]
  821: #$inlineremote[81] $inlineremote[82] $inlineremote[83]
  822: #$inlineremote[91] $inlineremote[92] $inlineremote[93]</td></tr>
  823: #ENDINLINEICONS
  824: #            }
  825: #        } else { # not iconsonly
  826: #            if ( $inlineremote[21] ne '' || $inlineremote[23] ne '' ) {
  827: #                $inlinebuttons = (<<ENDFIRSTLINE);
  828: #<tr><td>$inlineremote[21]</td><td>&nbsp;</td><td>$inlineremote[23]</td></tr>
  829: #ENDFIRSTLINE
  830: #            }
  831: #            if ( &hidden_button_check() ne 'yes' ) {
  832: #                foreach my $row ( 6 .. 9 ) {
  833: #                    if (   $inlineremote[ ${row} . '1' ] ne ''
  834: #                        || $inlineremote[ $row . '2' ] ne ''
  835: #                        || $inlineremote[ $row . '3' ] ne '' )
  836: #                    {
  837: #                        $inlinebuttons .= <<"ENDLINE";
  838: #<tr><td>$inlineremote["${row}1"]</td><td>$inlineremote["${row}2"]</td><td>$inlineremote["${row}3"]</td></tr>
  839: #ENDLINE
  840: #                    }
  841: #                }
  842: #            }
  843: #        }
  844:     }
  845:         $breadcrumb = &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0);
  846: 	    $result =(<<ENDREGTEXT);
  847: <script type="text/javascript">
  848: // BEGIN LON-CAPA Internal
  849: </script>
  850: $timesync
  851: $breadcrumb
  852: <!-- $tablestart -->
  853: <!-- $inlinebuttons -->
  854: <!-- $tableend -->
  855: $newmail
  856: <!-- $separator -->
  857: <script type="text/javascript">
  858: // END LON-CAPA Internal
  859: </script>
  860: 
  861: ENDREGTEXT
  862: # Registered, graphical output
  863:         } else {
  864: 	    my $requri=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
  865: 	    $requri=&Apache::lonenc::check_encrypt(&unescape($requri));
  866: 	    my $cursymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
  867: 	    my $navstatus=&get_nav_status();
  868: 	    my $clearcstr;
  869: 
  870: 	    if ($env{'user.adv'}) { $clearcstr='clearbut(6,1)'; }
  871: 	    $result = (<<ENDREGTHIS);
  872:      
  873: <script type="text/javascript">
  874: // <![CDATA[
  875: // BEGIN LON-CAPA Internal
  876: var swmenu=null;
  877: 
  878:     function LONCAPAreg() {
  879: 	  swmenu=$reopen;
  880:           swmenu.clearTimeout(swmenu.menucltim);
  881:           $timesync
  882:           $newmail
  883:           $buttons
  884: 	  swmenu.currentURL="$requri";
  885:           swmenu.reloadURL=swmenu.currentURL+window.location.search;
  886:           swmenu.currentSymb="$cursymb";
  887:           swmenu.reloadSymb="$cursymb";
  888:           swmenu.currentStale=0;
  889: 	  $navstatus
  890:           $hwkadd
  891:           $editbutton
  892:     }
  893: 
  894:     function LONCAPAstale() {
  895: 	  swmenu=$reopen
  896:           swmenu.currentStale=1;
  897:           if (swmenu.reloadURL!='' && swmenu.reloadURL!= null) { 
  898:              swmenu.switchbutton
  899:              (3,1,'reload.gif','return','location','go(reloadURL)','Return to the last known location in the course sequence');
  900: 	  }
  901:           swmenu.clearbut(7,2);
  902:           swmenu.clearbut(7,3);
  903:           swmenu.menucltim=swmenu.setTimeout(
  904:  'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+
  905:  'clearbut(9,1);clearbut(9,3);clearbut(6,3);$clearcstr',
  906: 			  2000);
  907:       }
  908: 
  909: // END LON-CAPA Internal 
  910: // ]]>
  911: </script>
  912: ENDREGTHIS
  913:         }
  914: # =============================================================================
  915:     } else {
  916: # ========================================== This can or will not be registered
  917:         if ($noremote) {
  918: # Not registered
  919:             $result= (<<ENDDONOTREGTEXT);
  920: ENDDONOTREGTEXT
  921:         } else {
  922: # Not registered, graphical
  923:            $result = (<<ENDDONOTREGTHIS);
  924: 
  925: <script type="text/javascript">
  926: // <![CDATA[
  927: // BEGIN LON-CAPA Internal
  928: var swmenu=null;
  929: 
  930:     function LONCAPAreg() {
  931: 	  swmenu=$reopen
  932:           $timesync
  933:           swmenu.currentStale=1;
  934:           swmenu.clearbut(2,1);
  935:           swmenu.clearbut(2,3);
  936:           swmenu.clearbut(8,1);
  937:           swmenu.clearbut(8,2);
  938:           swmenu.clearbut(8,3);
  939:           if (swmenu.currentURL) {
  940:              swmenu.switchbutton
  941:               (3,1,'reload.gif','return','location','go(currentURL)');
  942:  	  } else {
  943: 	      swmenu.clearbut(3,1);
  944:           }
  945:     }
  946: 
  947:     function LONCAPAstale() {
  948:     }
  949: 
  950: // END LON-CAPA Internal
  951: // ]]>
  952: </script>
  953: ENDDONOTREGTHIS
  954:        }
  955: # =============================================================================
  956:     }
  957:     return $result;
  958: }
  959: 
  960: sub is_course_upload {
  961:     my ($file,$cnum,$cdom) = @_;
  962:     my $uploadpath = &LONCAPA::propath($cdom,$cnum);
  963:     $uploadpath =~ s{^\/}{};
  964:     if (($file =~ m{^\Q$uploadpath\E/userfiles/docs/}) ||
  965:         ($file =~ m{^userfiles/\Q$cdom\E/\Q$cnum\E/docs/})) {
  966:         return 1;
  967:     }
  968:     return;
  969: }
  970: 
  971: sub edit_course_upload {
  972:     my ($file,$cnum,$cdom) = @_;
  973:     my $cfile;
  974:     if ($file =~/\.(htm|html|css|js|txt)$/) {
  975:         my $ext = $1;
  976:         my $url = &Apache::lonnet::hreflocation('',$file);
  977:         my $home = &Apache::lonnet::homeserver($cnum,$cdom);
  978:         my @ids=&Apache::lonnet::current_machine_ids();
  979:         my $dest;
  980:         if ($home && grep(/^\Q$home\E$/,@ids)) {
  981:             $dest = $url.'?forceedit=1';
  982:         } else {
  983:             unless (&Apache::lonnet::get_locks()) {
  984:                 $dest = '/adm/switchserver?otherserver='.
  985:                         $home.'&role='.$env{'request.role'}.
  986:                         '&url='.$url.'&forceedit=1';
  987:             }
  988:         }
  989:         if ($dest) {
  990:             $cfile = &HTML::Entities::encode($dest,'"<>&');
  991:         }
  992:     }
  993:     return $cfile;
  994: }
  995: 
  996: sub loadevents() {
  997:     if ($env{'request.state'} eq 'construct' ||
  998: 	$env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
  999:     return 'LONCAPAreg();';
 1000: }
 1001: 
 1002: sub unloadevents() {
 1003:     if ($env{'request.state'} eq 'construct' ||
 1004: 	$env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
 1005:     return 'LONCAPAstale();';
 1006: }
 1007: 
 1008: 
 1009: sub startupremote {
 1010:     my ($lowerurl)=@_;
 1011:     if ($env{'environment.remote'} eq 'off') {
 1012:      return ('<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.$lowerurl.'" />');
 1013:     }
 1014: #
 1015: # The Remote actually gets launched!
 1016: #
 1017:     my $configmenu=&rawconfig();
 1018:     my $esclowerurl=&escape($lowerurl);
 1019:     my $message=&mt('"Waiting for Remote Control window to load: "+[_1]','waited');
 1020:     return(<<ENDREMOTESTARTUP);
 1021: <script type="text/javascript">
 1022: // <![CDATA[
 1023: var timestart;
 1024: function wheelswitch() {
 1025:     if (typeof(document.wheel) != 'undefined') {
 1026: 	if (typeof(document.wheel.spin) != 'undefined') {
 1027: 	    var date=new Date();
 1028: 	    var waited=Math.round(30-((date.getTime()-timestart)/1000));
 1029: 	    document.wheel.spin.value=$message;
 1030: 	}
 1031:     }
 1032:    if (window.status=='|') { 
 1033:       window.status='/'; 
 1034:    } else {
 1035:       if (window.status=='/') {
 1036:          window.status='-';
 1037:       } else {
 1038:          if (window.status=='-') { 
 1039:             window.status='\\\\'; 
 1040:          } else {
 1041:             if (window.status=='\\\\') { window.status='|'; }
 1042:          }
 1043:       }
 1044:    } 
 1045: }
 1046: 
 1047: // ---------------------------------------------------------- The wait function
 1048: var canceltim;
 1049: function wait() {
 1050:    if ((menuloaded==1) || (tim==1)) {
 1051:       window.status='Done.';
 1052:       if (tim==0) {
 1053:          clearTimeout(canceltim);
 1054:          $configmenu
 1055:          window.location='$lowerurl';  
 1056:       } else {
 1057: 	  window.location='/adm/remote?action=collapse&url=$esclowerurl';
 1058:       }
 1059:    } else {
 1060:       wheelswitch();
 1061:       setTimeout('wait();',200);
 1062:    }
 1063: }
 1064: 
 1065: function main() {
 1066:    canceltim=setTimeout('tim=1;',30000);
 1067:    window.status='-';
 1068:    var date=new Date();
 1069:    timestart=date.getTime();
 1070:    wait();
 1071: }
 1072: 
 1073: // ]]>
 1074: </script>
 1075: ENDREMOTESTARTUP
 1076: }
 1077: 
 1078: sub setflags() {
 1079:     return(<<ENDSETFLAGS);
 1080: <script type="text/javascript">
 1081: // <![CDATA[
 1082:     menuloaded=0;
 1083:     tim=0;
 1084: // ]]>
 1085: </script>
 1086: ENDSETFLAGS
 1087: }
 1088: 
 1089: sub maincall() {
 1090:     if ($env{'environment.remote'} eq 'off') { return ''; }
 1091:     return(<<ENDMAINCALL);
 1092: <script type="text/javascript">
 1093: // <![CDATA[
 1094:     main();
 1095: // ]]>
 1096: </script>
 1097: ENDMAINCALL
 1098: }
 1099: 
 1100: sub load_remote_msg {
 1101:     my ($lowerurl)=@_;
 1102: 
 1103:     if ($env{'environment.remote'} eq 'off') { return ''; }
 1104: 
 1105:     my $esclowerurl=&escape($lowerurl);
 1106:     my $link=&mt('[_1]Continue[_2] on in Inline Menu mode'
 1107:                 ,'<a href="/adm/remote?action=collapse&amp;url='.$esclowerurl.'">'
 1108:                 ,'</a>');
 1109:     return(<<ENDREMOTEFORM);
 1110: <p>
 1111: <form name="wheel">
 1112: <input name="spin" type="text" size="60" />
 1113: </form>
 1114: </p>
 1115: <p>$link</p>
 1116: ENDREMOTEFORM
 1117: }
 1118: 
 1119: sub get_menu_name {
 1120:     my $hostid = $Apache::lonnet::perlvar{'lonHostID'};
 1121:     $hostid =~ s/\W//g;
 1122:     return 'LCmenu'.$hostid;
 1123: }
 1124: 
 1125: 
 1126: sub reopenmenu {
 1127:    if ($env{'environment.remote'} eq 'off') { return ''; }
 1128:    my $menuname = &get_menu_name();
 1129:    my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
 1130:    return('window.open('.$nothing.',"'.$menuname.'","",false);');
 1131: } 
 1132: 
 1133: 
 1134: sub open {
 1135:     my $returnval='';
 1136:     if ($env{'environment.remote'} eq 'off') { 
 1137: 	return
 1138:         '<script type="text/javascript">'."\n"
 1139:        .'// <![CDATA['."\n"
 1140:        .'self.name="loncapaclient";'."\n"
 1141:        .'// ]]>'."\n"
 1142:        .'</script>';
 1143:     }
 1144:     my $menuname = &get_menu_name();
 1145:     
 1146: #    unless (shift eq 'unix') {
 1147: # resizing does not work on linux because of virtual desktop sizes
 1148: #       $returnval.=(<<ENDRESIZE);
 1149: #if (window.screen) {
 1150: #    self.resizeTo(screen.availWidth-215,screen.availHeight-55);
 1151: #    self.moveTo(190,15);
 1152: #}
 1153: #ENDRESIZE
 1154: #    }
 1155:     $returnval=(<<ENDOPEN);
 1156: // <![CDATA[
 1157: window.status='Opening LON-CAPA Remote Control';
 1158: var menu=window.open("/res/adm/pages/menu.html?inhibitmenu=yes","$menuname",
 1159: "height=375,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5");
 1160: self.name='loncapaclient';
 1161: // ]]>
 1162: ENDOPEN
 1163:     return '<script type="text/javascript">'.$returnval.'</script>';
 1164: }
 1165: 
 1166: 
 1167: # ================================================================== Raw Config
 1168: 
 1169: sub clear {
 1170:     my ($row,$col)=@_;
 1171:     unless ($env{'environment.remote'} eq 'off') {
 1172:        if (($row<1) || ($row>13)) { return ''; }
 1173:        return "\n".qq(window.status+='.';swmenu.clearbut($row,$col););
 1174:    } else { 
 1175:        $inlineremote[10*$row+$col]='';
 1176:        return ''; 
 1177:    }
 1178: }
 1179: 
 1180: # ============================================ Switch a button or create a link
 1181: # Switch acts on the javascript that is executed when a button is clicked.  
 1182: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
 1183: 
 1184: sub switch {
 1185:     my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak)=@_;
 1186:     $act=~s/\$uname/$uname/g;
 1187:     $act=~s/\$udom/$udom/g;
 1188:     $top=&mt($top);
 1189:     $bot=&mt($bot);
 1190:     $desc=&mt($desc);
 1191:     if (($env{'environment.remote'} ne 'off') || ($env{'environment.icons'} eq 'classic')) {
 1192:        $img=&mt($img);
 1193:     }
 1194:     my $idx=10*$row+$col;
 1195:     $category_members{$cat}.=':'.$idx;
 1196: 
 1197:     unless ($env{'environment.remote'} eq 'off') {
 1198:        if (($row<1) || ($row>13)) { return ''; }
 1199: # Remote
 1200:        return "\n".
 1201:  qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
 1202:    } else {
 1203: # Inline Remote
 1204:        if ($env{'environment.icons'} ne 'classic') {
 1205:           $img=~s/\.gif$/\.png/;
 1206:        }
 1207:        if ($nobreak==2) { return ''; }
 1208:        my $text=$top.' '.$bot;
 1209:        $text=~s/\s*\-\s*//gs;
 1210: 
 1211:        my $pic=
 1212: 	   '<img alt="'.$text.'" src="'.
 1213: 	   &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
 1214: 	   '" align="'.($nobreak==3?'right':'left').'" class="LC_icon" />';
 1215:        if ($env{'browser.interface'} eq 'faketextual') {
 1216: # Main Menu
 1217: 	   if ($nobreak==3) {
 1218: 	       $inlineremote[$idx]="\n".
 1219: 		   '<td class="LC_menubuttons_text" align="right">'.$text.
 1220: 		   '</td><td align="left">'.
 1221: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
 1222: 	   } elsif ($nobreak) {
 1223: 	       $inlineremote[$idx]="\n<tr>".
 1224: 		   '<td align="left">'.
 1225: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td>
 1226:                     <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>';
 1227: 	   } else {
 1228: 	       $inlineremote[$idx]="\n<tr>".
 1229: 		   '<td align="left">'.
 1230: 		   '<a href="javascript:'.$act.';">'.$pic.
 1231: 		   '</a></td><td class="LC_menubuttons_text" colspan="3">'.
 1232: 		   '<a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$desc.'</span></a></td></tr>';
 1233: 	   }
 1234:        } else {
 1235: # Inline Menu
 1236:            if ($env{'environment.icons'} eq 'iconsonly') {
 1237:               $inlineremote[$idx]='<a title="'.$desc.'" href="javascript:'.$act.';">'.$pic.'</a>';
 1238:            } else {
 1239: 	      $inlineremote[$idx]=
 1240: 		   '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.
 1241: 		   '<span class="LC_menubuttons_inline_text">'.$desc.'</span></a>';
 1242:            }
 1243:        }
 1244:    }
 1245:     return '';
 1246: }
 1247: 
 1248: sub secondlevel {
 1249:     my $output='';
 1250:     my 
 1251:     ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_;
 1252:     if ($prt eq 'any') {
 1253: 	   $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1254:     } elsif ($prt=~/^r(\w+)/) {
 1255:         if ($rol eq $1) {
 1256:            $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1257:         }
 1258:     }
 1259:     return $output;
 1260: }
 1261: 
 1262: sub openmenu {
 1263:     my $menuname = &get_menu_name();
 1264:     if ($env{'environment.remote'} eq 'off') { return ''; }
 1265:     my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
 1266:     return "window.open(".$nothing.",'".$menuname."');";
 1267: }
 1268: 
 1269: sub inlinemenu {
 1270:     undef(@inlineremote);
 1271:     undef(%category_members);
 1272: # calling rawconfig with "1" will evaluate mydesk.tab, even if there is no active remote control
 1273:     &rawconfig(1);
 1274:     my $output='<table><tr>';
 1275:     for (my $col=1; $col<=2; $col++) {
 1276:         $output.='<td class="LC_mainmenu_col_fieldset">';
 1277:         for (my $row=1; $row<=8; $row++) {
 1278:             foreach my $cat (keys(%category_members)) {
 1279:                if ($category_positions{$cat} ne "$col,$row") { next; }
 1280:                #$output.='<table><tr><td colspan="4" class="LC_menubuttons_category">'.&mt($category_names{$cat}).'</td></tr>';
 1281:                $output.='<div class="LC_Box LC_400Box">';
 1282: 	       $output.='<h3 class="LC_hcell">'.&mt($category_names{$cat}).'</h3>';
 1283:                $output.='<table>';
 1284:                my %active=();
 1285:                foreach my $menu_item (split(/\:/,$category_members{$cat})) {
 1286:                   if ($inlineremote[$menu_item]) {
 1287:                      $active{$menu_item}=1;
 1288:                   }
 1289:                }  
 1290:                foreach my $item (sort(keys(%active))) {
 1291:                   $output.=$inlineremote[$item];
 1292:                }
 1293:                $output.='</table>';
 1294:                $output.='</div>';
 1295:             }
 1296:          }
 1297:          $output.="</td>";
 1298:     }
 1299:     $output.="</tr></table>";
 1300:     return $output;
 1301: }
 1302: 
 1303: sub rawconfig {
 1304: #
 1305: # This evaluates mydesk.tab
 1306: # Need to add more positions and more privileges to deal with all
 1307: # menu items.
 1308: #
 1309:     my $textualoverride=shift;
 1310:     my $output='';
 1311:     unless ($env{'environment.remote'} eq 'off') {
 1312:        $output.=
 1313:  "window.status='Opening Remote Control';var swmenu=".&openmenu().
 1314: "\nwindow.status='Configuring Remote Control ';";
 1315:     } else {
 1316:        unless ($textualoverride) { return ''; }
 1317:     }
 1318:     my $uname=$env{'user.name'};
 1319:     my $udom=$env{'user.domain'};
 1320:     my $adv=$env{'user.adv'};
 1321:     my $show_course=&Apache::loncommon::show_course();
 1322:     my $author=$env{'user.author'};
 1323:     my $crs='';
 1324:     my $crstype='';
 1325:     if ($env{'request.course.id'}) {
 1326:        $crs='/'.$env{'request.course.id'};
 1327:        if ($env{'request.course.sec'}) {
 1328: 	   $crs.='_'.$env{'request.course.sec'};
 1329:        }
 1330:        $crs=~s/\_/\//g;
 1331:        $crstype = &Apache::loncommon::course_type();
 1332:     }
 1333:     my $pub=($env{'request.state'} eq 'published');
 1334:     my $con=($env{'request.state'} eq 'construct');
 1335:     my $rol=$env{'request.role'};
 1336:     my $requested_domain = $env{'request.role.domain'};
 1337:     foreach my $line (@desklines) {
 1338:         my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
 1339:         $prt=~s/\$uname/$uname/g;
 1340:         $prt=~s/\$udom/$udom/g;
 1341:         if ($env{'environment.remotenavmap'} eq 'on') {
 1342:              unless ($env{'environment.remote'} eq 'on') {
 1343:                  if ($img eq 'nav.gif') {
 1344:                      $act = "gonav('/adm/navmaps','')";
 1345:                  }
 1346:              }
 1347:         }
 1348:         if ($prt =~ /\$crs/) {
 1349:             next unless ($env{'request.course.id'});
 1350:             next if ($crstype eq 'Community');
 1351:             $prt=~s/\$crs/$crs/g;
 1352:         } elsif ($prt =~ /\$cmty/) {
 1353:             next unless ($env{'request.course.id'});
 1354:             next if ($crstype ne 'Community');
 1355:             $prt=~s/\$cmty/$crs/g;
 1356:         }
 1357:         $prt=~s/\$requested_domain/$requested_domain/g;
 1358:         if ($category_names{$cat}!~/\w/) { $cat='oth'; }
 1359:         if ($pro eq 'clear') {
 1360: 	    $output.=&clear($row,$col);
 1361:         } elsif ($pro eq 'any') {
 1362:                $output.=&secondlevel(
 1363: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1364: 	} elsif ($pro eq 'smp') {
 1365:             unless ($adv) {
 1366:                $output.=&secondlevel(
 1367:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1368:             }
 1369:         } elsif ($pro eq 'adv') {
 1370:             if ($adv) {
 1371:                $output.=&secondlevel(
 1372: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1373:             }
 1374: 	} elsif ($pro eq 'shc') {
 1375:             if ($show_course) {
 1376:                $output.=&secondlevel(
 1377:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1378:             }
 1379:         } elsif ($pro eq 'nsc') {
 1380:             if (!$show_course) {
 1381:                $output.=&secondlevel(
 1382: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1383:             }
 1384:         } elsif (($pro=~/^p(\w+)/) && ($prt)) {
 1385:             my $priv = $1;
 1386:             if ($priv =~ /^mdc(Course|Community)/) {
 1387:                 if ($crstype eq $1) {
 1388:                     $priv = 'mdc';
 1389:                 } else {
 1390:                     next;
 1391:                 }
 1392:             }
 1393: 	    if (&Apache::lonnet::allowed($priv,$prt)) {
 1394:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1395:             }
 1396:         } elsif ($pro eq 'course')  {
 1397:             if (($env{'request.course.fn'}) && ($crstype ne 'Community')) {
 1398:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1399: 	    }
 1400:         } elsif ($pro eq 'community')  {
 1401:             if (($env{'request.course.fn'}) && ($crstype eq 'Community')) {
 1402:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1403:             }
 1404:         } elsif ($pro =~ /^courseenv_(.*)$/) {
 1405:             my $key = $1;
 1406:             if ($crstype ne 'Community') {
 1407:                 my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
 1408:                 if ($key eq 'canuse_pdfforms') {
 1409:                     if ($env{'request.course.id'} && $coursepref eq '') {
 1410:                         my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
 1411:                         $coursepref = $domdefs{'canuse_pdfforms'};
 1412:                     }
 1413:                 }
 1414:                 if ($coursepref) { 
 1415:                     $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1416:                 }
 1417:             }
 1418:         } elsif ($pro =~ /^communityenv_(.*)$/) {
 1419:             my $key = $1;
 1420:             if ($crstype eq 'Community') {
 1421:                 my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
 1422:                 if ($key eq 'canuse_pdfforms') {
 1423:                     if ($env{'request.course.id'} && $coursepref eq '') {
 1424:                         my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
 1425:                         $coursepref = $domdefs{'canuse_pdfforms'};
 1426:                     }
 1427:                 }
 1428:                 if ($coursepref) { 
 1429:                     $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1430:                 }
 1431:             }
 1432:         } elsif ($pro =~ /^course_(.*)$/) {
 1433:             # Check for permissions inside of a course
 1434:             if (($env{'request.course.id'}) && ($crstype ne 'Community') && 
 1435:                 (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
 1436:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
 1437:                  )) {
 1438:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1439: 	    }
 1440:         } elsif ($pro =~ /^community_(.*)$/) {
 1441:             # Check for permissions inside of a community
 1442:             if (($env{'request.course.id'}) && ($crstype eq 'Community') &&   
 1443:                 (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
 1444:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
 1445:                  )) {
 1446:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1447:             }
 1448:         } elsif ($pro eq 'author') {
 1449:             if ($author) {
 1450:                 if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
 1451:                     (($prt eq 'raa') && ($env{'request.role'}=~/^aa/)) || 
 1452:                     (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
 1453:                     # Check that we are on the correct machine
 1454:                     my $cadom=$requested_domain;
 1455:                     my $caname=$env{'user.name'};
 1456:                     if (($prt eq 'rca') || ($prt eq 'raa')) {
 1457: 		       ($cadom,$caname)=
 1458:                                ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
 1459:                     }                       
 1460:                     $act =~ s/\$caname/$caname/g;
 1461:                     my $home = &Apache::lonnet::homeserver($caname,$cadom);
 1462: 		    my $allowed=0;
 1463: 		    my @ids=&Apache::lonnet::current_machine_ids();
 1464: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
 1465: 		    if ($allowed) {
 1466:                         $output.=&switch($caname,$cadom,
 1467:                                         $row,$col,$img,$top,$bot,$act,$desc,$cat);
 1468:                     }
 1469:                 }
 1470:             }
 1471:         } elsif ($pro eq 'tools') {
 1472:             my @tools = ('aboutme','blog','portfolio');
 1473:             if (grep(/^\Q$prt\E$/,@tools)) {
 1474:                 if (!&Apache::lonnet::usertools_access($env{'user.name'},
 1475:                                                        $env{'user.domain'},
 1476:                                                        $prt,undef,'tools')) {
 1477:                     $output.=&clear($row,$col);
 1478:                     next;
 1479:                 }
 1480:             } elsif (($prt eq 'reqcrsnsc') || ($prt eq 'reqcrsshc')) {
 1481:                 if (($prt eq 'reqcrsnsc') && ($show_course))   {
 1482:                     next;
 1483:                 }
 1484:                 if (($prt eq 'reqcrsshc') && (!$show_course)) {
 1485:                     next;
 1486:                 }
 1487:                 my $showreqcrs = &check_for_rcrs();
 1488:                 if (!$showreqcrs) {
 1489:                     $output.=&clear($row,$col);
 1490:                     next;
 1491:                 }
 1492:             }
 1493:             $prt='any';
 1494:             $output.=&secondlevel(
 1495:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1496:         }
 1497:     }
 1498:     unless ($env{'environment.remote'} eq 'off') {
 1499:        $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
 1500:        if (&Apache::lonmsg::newmail()) { 
 1501: 	   $output.='swmenu.setstatus("you have","messages");';
 1502:        }
 1503:     }
 1504: 
 1505:     return $output;
 1506: }
 1507: 
 1508: sub check_for_rcrs {
 1509:     my $showreqcrs = 0;
 1510:     my @reqtypes = ('official','unofficial','community');
 1511:     foreach my $type (@reqtypes) {
 1512:         if (&Apache::lonnet::usertools_access($env{'user.name'},
 1513:                                               $env{'user.domain'},
 1514:                                               $type,undef,'requestcourses')) {
 1515:             $showreqcrs = 1;
 1516:             last;
 1517:         }
 1518:     }
 1519:     if (!$showreqcrs) {
 1520:         foreach my $type (@reqtypes) {
 1521:             if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
 1522:                 $showreqcrs = 1;
 1523:                 last;
 1524:             }
 1525:         }
 1526:     }
 1527:     return $showreqcrs;
 1528: }
 1529: 
 1530: # ======================================================================= Close
 1531: 
 1532: sub close {
 1533:     if ($env{'environment.remote'} eq 'off') { return ''; }
 1534:     my $menuname = &get_menu_name();
 1535:     return(<<ENDCLOSE);
 1536: <script type="text/javascript">
 1537: // <![CDATA[
 1538: window.status='Accessing Remote Control';
 1539: menu=window.open("/adm/rat/empty.html","$menuname",
 1540:                  "height=350,width=150,scrollbars=no,menubar=no");
 1541: window.status='Disabling Remote Control';
 1542: menu.active=0;
 1543: menu.autologout=0;
 1544: window.status='Closing Remote Control';
 1545: menu.close();
 1546: window.status='Done.';
 1547: // ]]>
 1548: </script>
 1549: ENDCLOSE
 1550: }
 1551: 
 1552: # ====================================================================== Footer
 1553: 
 1554: sub footer {
 1555: 
 1556: }
 1557: 
 1558: sub nav_control_js {
 1559:     my $nav=($env{'environment.remotenavmap'} eq 'on');
 1560:     return (<<NAVCONTROL);
 1561:     var w_loncapanav_flag="$nav";
 1562: 
 1563: 
 1564: function gonav(url) {
 1565:    if (w_loncapanav_flag != 1) {
 1566:       gopost(url,'');
 1567:    }  else {
 1568:       navwindow=window.open(url,
 1569:                   "loncapanav","height=600,width=400,scrollbars=1"); 
 1570:    }
 1571: }
 1572: NAVCONTROL
 1573: }
 1574: 
 1575: sub dc_popup_js {
 1576:     my %lt = &Apache::lonlocal::texthash(
 1577:                                           more => '(More ...)',
 1578:                                           less => '(Less ...)',
 1579:                                         );
 1580:     return <<"END";
 1581: 
 1582: function showCourseID() {
 1583:     document.getElementById('dccid').style.display='block';
 1584:     document.getElementById('dccid').style.textAlign='left';
 1585:     document.getElementById('dccid').style.textFace='normal';
 1586:     document.getElementById('dccidtext').innerHTML ='<a href="javascript:hideCourseID();">$lt{'less'}</a>';
 1587:     return;
 1588: }
 1589: 
 1590: function hideCourseID() {
 1591:     document.getElementById('dccid').style.display='none';
 1592:     document.getElementById('dccidtext').innerHTML ='<a href="javascript:showCourseID()">$lt{'more'}</a>';
 1593:     return;
 1594: }
 1595: 
 1596: END
 1597: 
 1598: }
 1599: 
 1600: sub utilityfunctions {
 1601:     my $caller = shift;
 1602:     unless ($env{'environment.remote'} eq 'off' || 
 1603:             $caller eq '/adm/menu') { 
 1604:             return ''; }
 1605:             
 1606:     my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
 1607:     if ($currenturl =~ m{^/adm/wrapper/ext/}) {
 1608:         if ($env{'request.external.querystring'}) {
 1609:             $currenturl .= ($currenturl=~/\?/)?'&':'?'.$env{'request.external.querystring'};
 1610:         }
 1611:     }
 1612:     $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
 1613:     
 1614:     my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
 1615:     my $nav_control=&nav_control_js();
 1616: 
 1617:     my $dc_popup_cid;
 1618:     if ($env{'user.adv'} && exists($env{'user.role.dc./'.
 1619:                         $env{'course.'.$env{'request.course.id'}.
 1620:                                  '.domain'}.'/'})) {
 1621:         $dc_popup_cid = &dc_popup_js();
 1622:     }
 1623: 
 1624:     my $start_page_annotate = 
 1625:         &Apache::loncommon::start_page('Annotator',undef,
 1626: 				       {'only_body' => 1,
 1627: 					'js_ready'  => 1,
 1628: 					'bgcolor'   => '#BBBBBB',
 1629: 					'add_entries' => {
 1630: 					    'onload' => 'javascript:document.goannotate.submit();'}});
 1631: 
 1632:     my $end_page_annotate = 
 1633:         &Apache::loncommon::end_page({'js_ready' => 1});
 1634: 
 1635:     my $start_page_bookmark = 
 1636:         &Apache::loncommon::start_page('Bookmarks',undef,
 1637: 				       {'only_body' => 1,
 1638: 					'js_ready'  => 1,
 1639: 					'bgcolor'   => '#BBBBBB',});
 1640: 
 1641:     my $end_page_bookmark = 
 1642:         &Apache::loncommon::end_page({'js_ready' => 1});
 1643: 
 1644:     my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
 1645:                          &mt('Switch server?');
 1646: 
 1647: return (<<ENDUTILITY)
 1648: 
 1649:     var currentURL="$currenturl";
 1650:     var reloadURL="$currenturl";
 1651:     var currentSymb="$currentsymb";
 1652: 
 1653: $nav_control
 1654: $dc_popup_cid
 1655: 
 1656: function go(url) {
 1657:    if (url!='' && url!= null) {
 1658:        currentURL = null;
 1659:        currentSymb= null;
 1660:        window.location.href=url;
 1661:    }
 1662: }
 1663: 
 1664: function need_switchserver(url) {
 1665:     if (url!='' && url!= null) {
 1666:         if (confirm("$confirm_switch")) {
 1667:             go(url);
 1668:         }
 1669:     }
 1670:     return;
 1671: }
 1672: 
 1673: function gopost(url,postdata) {
 1674:    if (url!='') {
 1675:       this.document.server.action=url;
 1676:       this.document.server.postdata.value=postdata;
 1677:       this.document.server.command.value='';
 1678:       this.document.server.url.value='';
 1679:       this.document.server.symb.value='';
 1680:       this.document.server.submit();
 1681:    }
 1682: }
 1683: 
 1684: function gocmd(url,cmd) {
 1685:    if (url!='') {
 1686:       this.document.server.action=url;
 1687:       this.document.server.postdata.value='';
 1688:       this.document.server.command.value=cmd;
 1689:       this.document.server.url.value=currentURL;
 1690:       this.document.server.symb.value=currentSymb;
 1691:       this.document.server.submit();
 1692:    }
 1693: }
 1694: 
 1695: function gocstr(url,filename) {
 1696:     if (url == '/adm/cfile?action=delete') {
 1697:         this.document.cstrdelete.filename.value = filename
 1698:         this.document.cstrdelete.submit();
 1699:         return;
 1700:     }
 1701:     if (url == '/adm/printout') {
 1702:         this.document.cstrprint.postdata.value = filename
 1703:         this.document.cstrprint.curseed.value = 0;
 1704:         this.document.cstrprint.problemtype.value = 0;
 1705:         if (this.document.lonhomework) {
 1706:             if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
 1707:                 this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
 1708:             }
 1709:             if (this.document.lonhomework.problemtype) {
 1710: 		if (this.document.lonhomework.problemtype.value) {
 1711: 		    this.document.cstrprint.problemtype.value = 
 1712: 			this.document.lonhomework.problemtype.value;
 1713: 		} else if (this.document.lonhomework.problemtype.options) {
 1714: 		    for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
 1715: 			if (this.document.lonhomework.problemtype.options[i].selected) {
 1716: 			    if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') { 
 1717: 				this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
 1718: 				}
 1719: 			}
 1720: 		    }
 1721: 		}
 1722: 	    }
 1723: 	}
 1724:         this.document.cstrprint.submit();
 1725:         return;
 1726:     }
 1727:     if (url !='') {
 1728:         this.document.constspace.filename.value = filename;
 1729:         this.document.constspace.action = url;
 1730:         this.document.constspace.submit();
 1731:     }
 1732: }
 1733: 
 1734: function golist(url) {
 1735:    if (url!='' && url!= null) {
 1736:        currentURL = null;
 1737:        currentSymb= null;
 1738:        top.location.href=url;
 1739:    }
 1740: }
 1741: 
 1742: 
 1743: 
 1744: function catalog_info() {
 1745:    loncatinfo=window.open(window.location.pathname+'.meta',"LONcatInfo",'height=320,width=280,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
 1746: }
 1747: 
 1748: function chat_win() {
 1749:    lonchat=window.open('/res/adm/pages/chatroom.html',"LONchat",'height=320,width=480,resizable=yes,location=no,menubar=no,toolbar=no');
 1750: }
 1751: 
 1752: function group_chat(group) {
 1753:    var url = '/adm/groupchat?group='+group;
 1754:    var winName = 'LONchat_'+group;
 1755:    grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
 1756: }
 1757: 
 1758: function edit_bookmarks() {
 1759:    go('');
 1760:    w_BookmarkPal_flag=1;
 1761:    bookmarkpal=window.open("/adm/bookmarks",
 1762:                "BookmarkPal", "width=500,height=505,scrollbars=0");
 1763: }
 1764: 
 1765: function annotate() {
 1766:    w_Annotator_flag=1;
 1767:    annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
 1768:    annotator.document.write(
 1769:    '$start_page_annotate'
 1770:   +"<form name='goannotate' target='Annotator' method='post' "
 1771:   +"action='/adm/annotations'>"
 1772:   +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />"
 1773:   +"<\\/form>"
 1774:   +'$end_page_annotate');
 1775:    annotator.document.close();
 1776: }
 1777: 
 1778: function set_bookmark() {
 1779:    go('');
 1780:    clienttitle=document.title;
 1781:    clienthref=location.pathname;
 1782:    w_bmquery_flag=1;
 1783:    bmquery=window.open('','bmquery','width=365,height=165,scrollbars=0');
 1784:    bmquery.document.write(
 1785:    '$start_page_bookmark'
 1786:    +'<center><form method="post"'
 1787:    +' name="newlink" action="/adm/bookmarks" target="bmquery" '
 1788:    +'> <table width="340" height="150" '
 1789:    +'bgcolor="#FFFFFF" align="center"><tr><td>Link Name:<br /><input '
 1790:    +'type="text" name="title" size="45" value="'+clienttitle+'" />'
 1791:    +'<br />Address:<br /><input type="text" name="address" size="45" '
 1792:    +'value="'+clienthref+'" /><br /><center><input type="submit" '
 1793:    +'value="Save" /> <input type="button" value="Close" '
 1794:    +'onclick="javascript:window.close();" /></center></td>'
 1795:    +'</tr></table></form></center>'
 1796:    +'$end_page_bookmark' );
 1797:    bmquery.document.close();
 1798: }
 1799: 
 1800: ENDUTILITY
 1801: }
 1802: 
 1803: sub serverform {
 1804:     return(<<ENDSERVERFORM);
 1805: <form name="server" action="/adm/logout" method="post" target="_top">
 1806: <input type="hidden" name="postdata" value="none" />
 1807: <input type="hidden" name="command" value="none" />
 1808: <input type="hidden" name="url" value="none" />
 1809: <input type="hidden" name="symb" value="none" />
 1810: </form>
 1811: ENDSERVERFORM
 1812: }
 1813: 
 1814: sub constspaceform {
 1815:     return(<<ENDCONSTSPACEFORM);
 1816: <form name="constspace" action="/adm/logout" method="post" target="_top">
 1817: <input type="hidden" name="filename" value="" />
 1818: </form>
 1819: <form name="cstrdelete" action="/adm/cfile" method="post" target="_top">
 1820: <input type="hidden" name="action" value="delete" /> 
 1821: <input type="hidden" name="filename" value="" />
 1822: </form>
 1823: <form name="cstrprint" action="/adm/printout" target="_parent" method="post">
 1824: <input type="hidden" name="postdata" value="" />
 1825: <input type="hidden" name="curseed" value="" />
 1826: <input type="hidden" name="problemtype" value="" />
 1827: </form>
 1828: 
 1829: ENDCONSTSPACEFORM
 1830: }
 1831: 
 1832: 
 1833: sub get_nav_status {
 1834:     my $navstatus="swmenu.w_loncapanav_flag=";
 1835:     if ($env{'environment.remotenavmap'} eq 'on') {
 1836: 	$navstatus.="1";
 1837:     } else {
 1838: 	$navstatus.="-1";
 1839:     }
 1840:     return $navstatus;
 1841: }
 1842: 
 1843: sub hidden_button_check {
 1844:     my $hidden;
 1845:     if ($env{'request.course.id'} eq '') {
 1846:         return;
 1847:     }
 1848:     if ($env{'request.role.adv'}) {
 1849:         return;
 1850:     }
 1851:     my $buttonshide = &Apache::lonnet::EXT('resource.0.buttonshide');
 1852:     return $buttonshide; 
 1853: }
 1854: 
 1855: sub roles_selector {
 1856:     my ($cdom,$cnum) = @_;
 1857:     my $crstype = &Apache::loncommon::course_type();
 1858:     my $now = time;
 1859:     my (%courseroles,%seccount);
 1860:     my $is_cc;
 1861:     my $role_selector;
 1862:     my $ccrole;
 1863:     if ($crstype eq 'Community') {
 1864:         $ccrole = 'co';
 1865:     } else {
 1866:         $ccrole = 'cc';
 1867:     } 
 1868:     if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
 1869:         my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
 1870:         
 1871:         if ((($start) && ($start<0)) || 
 1872:             (($end) && ($end<$now))  ||
 1873:             (($start) && ($now<$start))) {
 1874:             $is_cc = 0;
 1875:         } else {
 1876:             $is_cc = 1;
 1877:         }
 1878:     }
 1879:     if ($is_cc) {
 1880:         &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount);
 1881:     } else {
 1882:         my %gotnosection;
 1883:         foreach my $item (keys(%env)) {
 1884:             if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
 1885:                 my $role = $1;
 1886:                 my $sec = $2;
 1887:                 next if ($role eq 'gr');
 1888:                 my ($start,$end) = split(/\./,$env{$item});
 1889:                 next if (($start && $start > $now) || ($end && $end < $now));
 1890:                 if ($sec eq '') {
 1891:                     if (!$gotnosection{$role}) {
 1892:                         $seccount{$role} ++;
 1893:                         $gotnosection{$role} = 1;
 1894:                     }
 1895:                 }
 1896:                 if (ref($courseroles{$role}) eq 'ARRAY') {
 1897:                     if ($sec ne '') {
 1898:                         if (!grep(/^\Q$sec\E$/,@{$courseroles{$role}})) {
 1899:                             push(@{$courseroles{$role}},$sec);
 1900:                             $seccount{$role} ++;
 1901:                         }
 1902:                     }
 1903:                 } else {
 1904:                     @{$courseroles{$role}} = ();
 1905:                     if ($sec ne '') {
 1906:                         $seccount{$role} ++;
 1907:                         push(@{$courseroles{$role}},$sec);
 1908:                     }
 1909:                 }
 1910:             }
 1911:         }
 1912:     }
 1913:     my $switchtext;
 1914:     if ($crstype eq 'Community') {
 1915:         $switchtext = &mt('Switch community role to...')
 1916:     } else {
 1917:         $switchtext = &mt('Switch course role to...')
 1918:     }
 1919:     my @roles_order = ($ccrole,'in','ta','ep','ad','st');
 1920:     if (keys(%courseroles) > 1) {
 1921:         $role_selector = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles);
 1922:         $role_selector .= '<form name="rolechooser" method="post" action="/adm/roles">
 1923:                           <select name="switchrole" onchange="javascript:adhocRole('."'switchrole'".')">';
 1924:         $role_selector .= '<option value="">'.$switchtext.'</option>';
 1925:         foreach my $role (@roles_order) {
 1926:             if (defined($courseroles{$role})) {
 1927:                 $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role,$crstype).'</option>'; 
 1928:             }
 1929:         }
 1930:         foreach my $role (sort(keys(%courseroles))) {
 1931:             if ($role =~ /^cr/) {
 1932:                 $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role).'</option>'; 
 1933:             }
 1934:         }
 1935:         $role_selector .= '</select>'."\n".
 1936:                '<input type="hidden" name="destinationurl" value="'.
 1937:                &HTML::Entities::encode($ENV{'REQUEST_URI'}).'" />'."\n".
 1938:                '<input type="hidden" name="gotorole" value="1" />'."\n".
 1939:                '<input type="hidden" name="selectrole" value="" />'."\n".
 1940:                '<input type="hidden" name="switch" value="1" />'."\n".
 1941:                '</form>';
 1942:     }
 1943:     return $role_selector;
 1944: }
 1945: 
 1946: sub get_all_courseroles {
 1947:     my ($cdom,$cnum,$courseroles,$seccount) = @_;
 1948:     unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH')) {
 1949:         return;
 1950:     }
 1951:     my ($result,$cached) = 
 1952:         &Apache::lonnet::is_cached_new('getcourseroles',$cdom.'_'.$cnum);
 1953:     if (defined($cached)) {
 1954:         if (ref($result) eq 'HASH') {
 1955:             if ((ref($result->{'roles'}) eq 'HASH') && 
 1956:                 (ref($result->{'seccount'}) eq 'HASH')) {
 1957:                 %{$courseroles} = %{$result->{'roles'}};
 1958:                 %{$seccount} = %{$result->{'seccount'}};
 1959:                 return;
 1960:             }
 1961:         }
 1962:     }
 1963:     my %gotnosection;
 1964:     my %adv_roles =
 1965:          &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
 1966:     foreach my $role (keys(%adv_roles)) {
 1967:         my ($urole,$usec) = split(/:/,$role);
 1968:         if (!$gotnosection{$urole}) {
 1969:             $seccount->{$urole} ++;
 1970:             $gotnosection{$urole} = 1;
 1971:         }
 1972:         if (ref($courseroles->{$urole}) eq 'ARRAY') {
 1973:             if ($usec ne '') {
 1974:                 if (!grep(/^Q$usec\E$/,@{$courseroles->{$urole}})) {
 1975:                     push(@{$courseroles->{$urole}},$usec);
 1976:                     $seccount->{$urole} ++;
 1977:                 }
 1978:             }
 1979:         } else {
 1980:             @{$courseroles->{$urole}} = ();
 1981:             if ($usec ne '') {
 1982:                 $seccount->{$urole} ++;
 1983:                 push(@{$courseroles->{$urole}},$usec);
 1984:             }
 1985:         }
 1986:     }
 1987:     my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum,['st']);
 1988:     @{$courseroles->{'st'}} = ();
 1989:     if (keys(%sections_count) > 0) {
 1990:         push(@{$courseroles->{'st'}},keys(%sections_count));
 1991:         $seccount->{'st'} = scalar(keys(%sections_count)); 
 1992:     }
 1993:     my $rolehash = {
 1994:                      'roles'    => $courseroles,
 1995:                      'seccount' => $seccount,
 1996:                    };
 1997:     &Apache::lonnet::do_cache_new('getcourseroles',$cdom.'_'.$cnum,$rolehash);
 1998:     return;
 1999: }
 2000: 
 2001: sub jump_to_role {
 2002:     my ($cdom,$cnum,$seccount,$courseroles) = @_;
 2003:     my %lt = &Apache::lonlocal::texthash(
 2004:                 this => 'This role has section(s) associated with it.',
 2005:                 ente => 'Enter a specific section.',
 2006:                 orlb => 'Enter a specific section, or leave blank for no section.',
 2007:                 avai => 'Available sections are:',
 2008:                 youe => 'You entered an invalid section choice:',
 2009:                 plst => 'Please try again',
 2010:     );
 2011:     my $js;
 2012:     if (ref($courseroles) eq 'HASH') {
 2013:         $js = '    var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n". 
 2014:               '    var numsec = new Array();'."\n".
 2015:               '    var rolesections = new Array();'."\n".
 2016:               '    var rolenames = new Array();'."\n".
 2017:               '    var roleseclist = new Array();'."\n";
 2018:         my @items = keys(%{$courseroles});
 2019:         for (my $i=0; $i<@items; $i++) {
 2020:             $js .= '    rolenames['.$i.'] = "'.$items[$i].'";'."\n";
 2021:             my ($secs,$secstr);
 2022:             if (ref($courseroles->{$items[$i]}) eq 'ARRAY') {
 2023:                 my @sections = sort { $a <=> $b } @{$courseroles->{$items[$i]}};
 2024:                 $secs = join('","',@sections);
 2025:                 $secstr = join(', ',@sections);
 2026:             }
 2027:             $js .= '    rolesections['.$i.'] = new Array("'.$secs.'");'."\n".
 2028:                    '    roleseclist['.$i.'] = "'.$secstr.'";'."\n".
 2029:                    '    numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n";
 2030:         }
 2031:     }
 2032:     return <<"END";
 2033: <script type="text/javascript">
 2034: //<![CDATA[
 2035: function adhocRole(roleitem) {
 2036:     $js
 2037:     var newrole =  document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value;
 2038:     if (newrole == '') {
 2039:         return; 
 2040:     } 
 2041:     var fullrole = newrole+'./$cdom/$cnum';
 2042:     var selidx = '';
 2043:     for (var i=0; i<rolenames.length; i++) {
 2044:         if (rolenames[i] == newrole) {
 2045:             selidx = i;
 2046:         }
 2047:     }
 2048:     var secok = 1;
 2049:     var secchoice = '';
 2050:     if (selidx >= 0) {
 2051:         if (numsec[selidx] > 1) {
 2052:             secok = 0;
 2053:             var numrolesec = rolesections[selidx].length;
 2054:             var msgidx = numsec[selidx] - numrolesec;
 2055:             secchoice = prompt("$lt{'this'} "+secpick[msgidx]+"\\n$lt{'avai'} "+roleseclist[selidx],"");
 2056:             if (secchoice == '') {
 2057:                 if (msgidx > 0) {
 2058:                     secok = 1;
 2059:                 }
 2060:             } else {
 2061:                 for (var j=0; j<rolesections[selidx].length; j++) {
 2062:                     if (rolesections[selidx][j] == secchoice) {
 2063:                         secok = 1;
 2064:                     }
 2065:                 }
 2066:             }
 2067:         } else {
 2068:             if (rolesections[selidx].length == 1) {
 2069:                 secchoice = rolesections[selidx][0];
 2070:             }
 2071:         }
 2072:     }
 2073:     if (secok == 1) {
 2074:         if (secchoice != '') {
 2075:             fullrole += '/'+secchoice;
 2076:         }
 2077:     } else {
 2078:         document.rolechooser.elements[roleitem].selectedIndex = 0;
 2079:         if (secchoice != null) {
 2080:             alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}");
 2081:         }
 2082:         return;
 2083:     }
 2084:     if (fullrole == "$env{'request.role'}") {
 2085:         return;
 2086:     }
 2087:     itemid = retrieveIndex('gotorole');
 2088:     if (itemid != -1) {
 2089:         document.rolechooser.elements[itemid].name = fullrole;
 2090:     }
 2091:     document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value = fullrole;
 2092:     document.rolechooser.selectrole.value = '1';
 2093:     document.rolechooser.submit();
 2094:     return;
 2095: }
 2096: 
 2097: function retrieveIndex(item) {
 2098:     for (var i=0;i<document.rolechooser.elements.length;i++) {
 2099:         if (document.rolechooser.elements[i].name == item) {
 2100:             return i;
 2101:         }
 2102:     }
 2103:     return -1;
 2104: }
 2105: // ]]>
 2106: </script>
 2107: END
 2108: }
 2109: 
 2110: 
 2111: # ================================================================ Main Program
 2112: 
 2113: BEGIN {
 2114:     if (! defined($readdesk)) {
 2115:         {
 2116:             my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
 2117:             if ( CORE::open( my $config,"<$tabfile") ) {
 2118:                 while (my $configline=<$config>) {
 2119:                     $configline=(split(/\#/,$configline))[0];
 2120:                     $configline=~s/^\s+//;
 2121:                     chomp($configline);
 2122:                     if ($configline=~/^cat\:/) {
 2123:                         my @entries=split(/\:/,$configline);
 2124:                         $category_positions{$entries[2]}=$entries[1];
 2125:                         $category_names{$entries[2]}=$entries[3];
 2126:                     } elsif ($configline=~/^prim\:/) {
 2127:                         my @entries = (split(/\:/, $configline))[1..5];
 2128:                         push @primary_menu, \@entries;
 2129:                     } elsif ($configline=~/^scnd\:/) {
 2130:                         my @entries = (split(/\:/, $configline))[1..5];
 2131:                         push @secondary_menu, \@entries; 
 2132:                     } elsif ($configline) {
 2133:                         push(@desklines,$configline);
 2134:                     }
 2135:                 }
 2136:                 CORE::close($config);
 2137:             }
 2138:         }
 2139:         $readdesk='done';
 2140:     }
 2141: }
 2142: 
 2143: 1;
 2144: __END__
 2145: 

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