File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.341: download - view: text, annotated - select for diffs
Thu Jan 13 19:43:12 2011 UTC (13 years, 4 months ago) by www
Branches: MAIN
CVS tags: HEAD
For 3.0: adapt secondary menu

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

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