File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.342: download - view: text, annotated - select for diffs
Sun Jan 16 22:45:05 2011 UTC (13 years, 4 months ago) by www
Branches: MAIN
CVS tags: HEAD
Move "return" button to where the other navigation arrows are (also, it's
not a function that is available in courses at all times, so it should
not have been in the line where it was)

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

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