File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.359: download - view: text, annotated - select for diffs
Mon Nov 7 18:22:37 2011 UTC (12 years, 7 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- use lonDocRoot perlvar in place of static string: '/home/httpd/html'.

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

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