File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.369.2.8: download - view: text, annotated - select for diffs
Fri May 25 23:47:16 2012 UTC (12 years ago) by raeburn
Branches: version_2_11_X
- For 2.11.
  - Reverse changes in 1.369.2.2. Stored Links ("Wishlist") included in 2.11 in
    place of Bookmarks.
  - Backport 1.370.

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

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