File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.369.2.5: download - view: text, annotated - select for diffs
Wed May 23 00:29:22 2012 UTC (12 years ago) by raeburn
Branches: version_2_11_X
- For 2.11
  - 'Home' removed from primary menu items ("3.0" feature).
  - 'Main Menu', 'Course Editor' restored to secondary menu.
  - Order of items in secondary menu changed.
  - For course personnel: Grades, People, Settings are now dropdown lists.
  - For students, 'People' link not shown if access to classlist not enabled.

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

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