File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.340: download - view: text, annotated - select for diffs
Thu Dec 2 06:00:12 2010 UTC (13 years, 7 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Help Link to support form for public pages, if support mail recipient defined.
  For: /adm/createaccount, /adm/coursecatalog, /adm/resetpw, and syllabus pages.

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

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