File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.339: download - view: text, annotated - select for diffs
Thu Sep 9 19:33:18 2010 UTC (13 years, 8 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- One less line feed in javascript pop-up.
  List of possible sections was being hidden in Internet Explorer.

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

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