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

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

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