File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.358: download - view: text, annotated - select for diffs
Mon Oct 31 22:46:09 2011 UTC (12 years, 6 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Clean up after changes for bug 1320.

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

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