Annotation of loncom/interface/lonmenu.pm, revision 1.318

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

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