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

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

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