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

1.1       www         1: # The LearningOnline Network with CAPA
                      2: # Routines to control the menu
                      3: #
1.309.2.11! raeburn     4: # $Id: lonmenu.pm,v 1.309.2.10 2010/01/06 22:40:34 raeburn 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: #
                     31: # environment.remote - if this is 'on', the routines controll the remote
1.269     droeschl   32: # control, otherwise they render the main window controls; 
1.1       www        33: 
1.244     jms        34: =head1 NAME
                     35: 
                     36: Apache::lonmenu
                     37: 
                     38: =head1 SYNOPSIS
                     39: 
                     40: Coordinates the response to clicking an image.
                     41: 
                     42: This is part of the LearningOnline Network with CAPA project
                     43: described at http://www.lon-capa.org.
                     44: 
                     45: =head1 SUBROUTINES
                     46: 
                     47: =over
                     48: 
                     49: Little texts
                     50: 
                     51: =item initlittle()
                     52: 
                     53: =item menubuttons()
                     54: 
                     55: This gets called at the top of the body section
                     56: 
                     57: =item show_return_link()
                     58: 
                     59: =item registerurl()
                     60: 
                     61: This gets called in the header section
                     62: 
                     63: =item innerregister()
                     64: 
                     65: This gets called in order to register a URL, both with the Remote
                     66: and in the body of the document
                     67: 
                     68: =item loadevents()
                     69: 
                     70: =item unloadevents()
                     71: 
                     72: =item startupremote()
                     73: 
                     74: =item setflags()
                     75: 
                     76: =item maincall()
                     77: 
                     78: =item load_remote_msg()
                     79: 
                     80: =item get_menu_name()
                     81: 
                     82: =item reopenmenu()
                     83: 
                     84: =item open()
                     85: 
                     86: Open the menu
                     87: 
                     88: =item clear()
                     89: 
                     90: =item switch()
                     91: 
                     92: Switch a button or create a link
                     93: Switch acts on the javascript that is executed when a button is clicked.  
                     94: The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
                     95: 
                     96: =item secondlevel()
                     97: 
                     98: =item openmenu()
                     99: 
                    100: =item inlinemenu()
                    101: 
                    102: =item rawconfig()
                    103: 
                    104: =item close()
                    105: 
                    106: =item footer()
                    107: 
                    108: =item utilityfunctions()
                    109: 
                    110: =item serverform()
                    111: 
                    112: =item constspaceform()
                    113: 
                    114: =item get_nav_status()
                    115: 
                    116: =item hidden_button_check()
                    117: 
                    118: =item roles_selector()
                    119: 
                    120: =item jump_to_role()
                    121: 
                    122: =back
                    123: 
                    124: =cut
                    125: 
1.1       www       126: package Apache::lonmenu;
                    127: 
                    128: use strict;
1.152     albertel  129: use Apache::lonnet;
1.47      matthew   130: use Apache::lonhtmlcommon();
1.115     albertel  131: use Apache::loncommon();
1.127     albertel  132: use Apache::lonenc();
1.88      www       133: use Apache::lonlocal;
1.207     foxr      134: use LONCAPA qw(:DEFAULT :match);
1.282     amueller  135: use HTML::Entities();
1.88      www       136: 
1.283     droeschl  137: use vars qw(@desklines %category_names %category_members %category_positions 
                    138:             $readdesk @primary_menu @secondary_menu);
1.88      www       139: 
1.56      www       140: my @inlineremote;
1.38      www       141: 
1.283     droeschl  142: sub prep_menuitem {
1.291     raeburn   143:     my ($menuitem) = @_;
                    144:     return '' unless(ref($menuitem) eq 'ARRAY');
1.283     droeschl  145:     my $link;
                    146:     if ($$menuitem[1]) { # graphical Link
                    147:         $link = "<img class=\"LC_noBorder\""
1.291     raeburn   148:               . " src=\"" . &Apache::loncommon::lonhttpdurl($$menuitem[1]) . "\"" 
                    149:               . " alt=\"" . &mt($$menuitem[2]) . "\" />";
1.283     droeschl  150:     } else {             # textual Link
1.291     raeburn   151:         $link = &mt($$menuitem[3]);
                    152:     }
1.299     raeburn   153:     return '<li><a href="'.$$menuitem[0].'">'.$link.'</a></li>';
1.283     droeschl  154: }
                    155: 
                    156: # primary_menu() evaluates @primary_menu and returns XHTML for the menu
                    157: # that contains following links:
                    158: # About, Message, Roles, Help, Logout
                    159: # @primary_menu is filled within the BEGIN block of this module with 
                    160: # entries from mydesk.tab
                    161: sub primary_menu {
                    162:     my $menu;
1.309.2.1  raeburn   163:     my $custommenu = &Apache::loncommon::needs_gci_custom();
1.283     droeschl  164:     # each element of @primary contains following array:
                    165:     # (link url, icon path, alt text, link text, condition)
                    166:     foreach my $menuitem (@primary_menu) {
                    167:         # evaluate conditions 
1.296     droeschl  168:         next if    ref($menuitem)       ne 'ARRAY';    #
1.283     droeschl  169:         next if    $$menuitem[4]        eq 'nonewmsg'  # show links depending on
1.291     raeburn   170:                 && &Apache::lonmsg::mynewmail();       # whether a new msg 
1.283     droeschl  171:         next if    $$menuitem[4]        eq 'newmsg'    # arrived or not
1.291     raeburn   172:                 && !&Apache::lonmsg::mynewmail();      # 
1.283     droeschl  173:         next if    $$menuitem[4]        !~ /public/    ##we've a public user, 
                    174:                 && $env{'user.name'}    eq 'public'    ##who should not see all 
                    175:                 && $env{'user.domain'}  eq 'public';   ##links
                    176:         next if    $$menuitem[4]        eq 'onlypublic'# hide links which are 
                    177:                 && $env{'user.name'}    ne 'public'    # only visible to public
                    178:                 && $env{'user.domain'}  ne 'public';   # users
1.309.2.1  raeburn   179:         next if    $$menuitem[4]        eq 'roles'     # hide links which are
                    180:                 && $custommenu;                        # not visible when GCI
                    181:         next if    $$menuitem[4]        eq 'courses'   # tabbed interface in use
                    182:                 && $custommenu;                        # 
1.283     droeschl  183:         next if    $$menuitem[4]        eq 'roles'     ##show links depending on
1.291     raeburn   184:                 && &Apache::loncommon::show_course();  ##term 'Courses' or 
1.283     droeschl  185:         next if    $$menuitem[4]        eq 'courses'   ##'Roles' wanted
1.291     raeburn   186:                 && !&Apache::loncommon::show_course(); ##
                    187:         
                    188:             
1.283     droeschl  189:         if ($$menuitem[3] eq 'Help') { # special treatment for helplink
1.291     raeburn   190:             $menu .= '<li>'.&Apache::loncommon::top_nav_help('Help').'</li>';
1.283     droeschl  191:         } else {
1.296     droeschl  192:             my @items = @{$menuitem};
                    193:             $items[0] = 'javascript:'.$menuitem->[0].';';
                    194:             $menu .= &prep_menuitem(\@items);
1.283     droeschl  195:         }
1.291     raeburn   196:     }
1.283     droeschl  197: 
1.291     raeburn   198:     return "<ol class=\"LC_primary_menu LC_right\">$menu</ol>";
1.283     droeschl  199: }
                    200: 
                    201: 
                    202: sub secondary_menu {
                    203:     my $menu;
                    204: 
1.286     raeburn   205:     my $crstype = &Apache::loncommon::course_type();
                    206:     my $canedit = &Apache::lonnet::allowed('mdc', $env{'request.course.id'});
                    207:     my $canviewgrps = &Apache::lonnet::allowed('vcg', $env{'request.course.id'}
                    208:                    . ($env{'request.course.sec'} ? "/$env{'request.course.sec'}"
                    209:                                                  : '')); 
                    210:     my $showlink = &show_return_link();
                    211:     my %groups = &Apache::lonnet::get_active_groups(
                    212:                      $env{'user.domain'}, $env{'user.name'},
                    213:                      $env{'course.' . $env{'request.course.id'} . '.domain'},
                    214:                      $env{'course.' . $env{'request.course.id'} . '.num'});
1.283     droeschl  215:     foreach my $menuitem (@secondary_menu) {
                    216:         # evaluate conditions 
1.296     droeschl  217:         next if    ref($menuitem)  ne 'ARRAY';
1.283     droeschl  218:         next if    $$menuitem[4]   ne 'always'
                    219:                 && !$env{'request.course.id'};
                    220:         next if    $$menuitem[4]   eq 'showreturn'
1.286     raeburn   221:                 && !$showlink
1.283     droeschl  222:                 && !($env{'request.state'} eq 'construct');
                    223:         next if    $$menuitem[4]   =~ /^mdc/
1.286     raeburn   224:                 && !$canedit;
                    225:         next if    $$menuitem[4]  eq 'mdcCourse'
                    226:                 && $crstype eq 'Community';
                    227:         next if    $$menuitem[4]  eq 'mdcCommunity'
                    228:                 && $crstype ne 'Community';
                    229:         next if    $$menuitem[4]  =~ /^remotenav/
1.283     droeschl  230:                 && $env{'environment.remotenavmap'} ne 'on';
1.286     raeburn   231:         next if    $$menuitem[4]  =~ /noremotenav/
1.283     droeschl  232:                 && $env{'environment.remotenavmap'} eq 'on';
1.295     raeburn   233:         next if $$menuitem[4] =~ /^(no|)remotenav$/ 
                    234:                 && $crstype eq 'Community';
                    235:         next if $$menuitem[4] =~ /^(no|)remotenavCommunity$/ 
                    236:                 && $crstype ne 'Community';
1.283     droeschl  237:         next if    $$menuitem[4]   =~ /showgroups$/
1.300     raeburn   238:                 && !$canviewgrps
1.286     raeburn   239:                 && !%groups;
1.283     droeschl  240: 
1.286     raeburn   241:         if ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) {
1.283     droeschl  242:             # special treatment for role selector
1.298     raeburn   243:             my $roles_selector = &roles_selector(
1.283     droeschl  244:                         $env{'course.' . $env{'request.course.id'} . '.domain'},
                    245:                         $env{'course.' . $env{'request.course.id'} . '.num'}  );
                    246: 
                    247:             $menu .= $roles_selector ? "<li>$roles_selector</li>"
                    248:                                      : '';
1.296     droeschl  249:         } elsif ($env{'environment.remotenavmap'} eq 'on') {
                    250:             # open link using javascript when remote navmap is activated
                    251:             my @items = @{$menuitem}; 
                    252:             if ($menuitem->[4] eq 'remotenav') {
                    253:                 $items[0] = "javascript:gonav('$menuitem->[0]');";
1.291     raeburn   254:             } else {
1.296     droeschl  255:                 $items[0] = "javascript:go('$menuitem->[0]');";
1.291     raeburn   256:             }
1.296     droeschl  257:             $menu .= &prep_menuitem(\@items);
                    258:         } else {
                    259:             $menu .= &prep_menuitem(\@$menuitem);
1.283     droeschl  260:         }
                    261:     }
                    262:     if ($menu =~ /\[url\].*\[symb\]/) {
1.291     raeburn   263:         my $escurl  = &escape( &Apache::lonenc::check_encrypt(
                    264:                              $env{'request.noversionuri'}));
1.283     droeschl  265: 
1.291     raeburn   266:         my $escsymb = &escape( &Apache::lonenc::check_encrypt(
                    267:                              $env{'request.symb'})); 
1.283     droeschl  268: 
                    269:         if (    $env{'request.state'} eq 'construct'
                    270:             and (   $env{'request.noversionuri'} eq '' 
                    271:                  || !defined($env{'request.noversionuri'}))) 
                    272:         {
                    273:             ($escurl = $env{'request.filename'}) =~ 
                    274:                 s{^/home/([^/]+)/public_html/(.*)$}{/priv/$1/$2};
                    275: 
1.291     raeburn   276:             $escurl  = &escape($escurl);
1.283     droeschl  277:         }    
                    278:         $menu =~ s/\[url\]/$escurl/g;
                    279:         $menu =~ s/\[symb\]/$escsymb/g;
                    280:     }
                    281: 
1.285     wenzelju  282:     return "<ul id=\"LC_secondary_menu\">$menu</ul>";
1.283     droeschl  283: }
                    284: 
1.309.2.1  raeburn   285: sub gci_secondary_menu {
                    286:     my %courses = (
                    287:         'review' => 'gci_9615072b469884921gcil1',
                    288:         'submit' => 'gci_1H96711d710194bfegcil1',
                    289:     );
                    290:     my %linktext = (
                    291:         'review'      => 'Review Questions',
                    292:         'submit'      => 'Submit Questions',
1.309.2.3  raeburn   293:         'managetest'  => 'Manage Tests',
1.309.2.1  raeburn   294:     );
1.309.2.3  raeburn   295:     my %links = (
                    296:                   'managetest' => '/adm/menu',
                    297:                 );
                    298:     my $current = 'managetest';
1.309.2.5  raeburn   299:     if ($env{'form.destinationurl'} eq '/adm/gci_info') {
                    300:         undef($current);
                    301:     }
1.309.2.1  raeburn   302:     foreach my $key (keys(%courses)) {
                    303:         $links{$key} = "javascript:switchpage('$key');";
                    304:         if ($env{'request.course.id'} eq $courses{$key}) {
                    305:             $links{$key} = '/adm/navmaps';
                    306:             $current = $key;
1.309.2.3  raeburn   307:             $links{'managetest'} = '/adm/roles?selectrole=1&cm=1&orgurl=%2fadm%2fmenu';
1.309.2.1  raeburn   308:         }
                    309:     }
1.309.2.3  raeburn   310:     my @menutabs = ('review','submit','managetest');
1.309.2.1  raeburn   311:     my $tabs;
                    312:     foreach my $item (@menutabs) {
                    313:         if ($item eq $current) {
                    314:             $tabs .= ' <li id="current"><a href="'.$links{$item}.'">'.
                    315:                      $linktext{$item}.'</a></li>';
                    316:         } else {
                    317:             $tabs .= ' <li><a href="'.$links{$item}.'">'.
                    318:                      $linktext{$item}.'</a></li>';
                    319:         }
                    320:     }
                    321:     return '<div id="gciheader">'.
                    322:            '<ul>'.$tabs.'</ul></div><br />';
                    323: }
1.283     droeschl  324: 
1.274     www       325: #
                    326: # This routine returns a translated hash for the menu items in the top inline menu row
                    327: # Probably should be in mydesk.tab
                    328: 
1.283     droeschl  329: #SD this sub is deprecated - don't use it
1.88      www       330: sub initlittle {
                    331:     return &Apache::lonlocal::texthash('ret' => 'Return to Last Location',
1.281     raeburn   332: 				       'nav' => 'Course Contents',
1.88      www       333: 				       'main' => 'Main Menu',
1.266     raeburn   334:                                        'roles' => (&Apache::loncommon::show_course()?
1.231     albertel  335:                                                     'Courses':'Roles'),
1.235     raeburn   336:                                        'other' => 'Other Roles',
1.219     albertel  337:                                        'docs' => 'Edit Course',
1.257     hauer     338:                                        'exit' => 'Logout',
1.202     albertel  339:                                        'login' => 'Log In',
1.165     raeburn   340: 				       'launch' => 'Launch Remote Control',
1.188     albertel  341:                                        'groups' => 'Groups',
1.286     raeburn   342:                                        'gdoc' => 'Community Documents',
1.184     raeburn   343:                                        );
1.88      www       344: }
                    345: 
1.283     droeschl  346: #SD this sub is deprecated - don't use it
                    347: #SD functionality is covered by new loncommon::bodytag and primary_menu(), secondary_menu()
1.38      www       348: sub menubuttons {
                    349:     my $forcereg=shift;
1.131     raeburn   350:     my $titletable=shift;
1.274     www       351: #
                    352: # Early-out for pages that should not have a menu, triggered by query string "inhibitmenu=yes"
                    353: #
1.112     albertel  354:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                    355: 					    ['inhibitmenu']);
1.152     albertel  356:     if (($env{'form.inhibitmenu'} eq 'yes') ||
1.149     www       357:         ($ENV{'REQUEST_URI'} eq '/adm/logout')) { return ''; }
1.175     albertel  358: 
                    359:     if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
                    360: 
1.163     www       361:     my %lt=&initlittle();
1.55      www       362:     my $navmaps='';
1.59      www       363:     my $reloadlink='';
1.151     www       364:     my $docs='';
1.165     raeburn   365:     my $groups='';
1.235     raeburn   366:     my $roles='<a href="/adm/roles" target="_top">'.$lt{'roles'}.'</a>';
                    367:     my $role_selector;
1.165     raeburn   368:     my $showgroups=0;
1.235     raeburn   369:     my ($cnum,$cdom);
1.274     www       370: #
                    371: # if the URL is hidden, symbs and the non-versioned version of the URL would be encrypted
                    372: #
1.183     www       373:     my $escurl=&escape(&Apache::lonenc::check_encrypt($env{'request.noversionuri'}));
                    374:     my $escsymb=&escape(&Apache::lonenc::check_encrypt($env{'request.symb'}));
1.176     albertel  375: 
1.199     albertel  376:     my $logo=&Apache::loncommon::lonhttpdurl("/adm/lonIcons/minilogo.gif");
1.253     kaisler   377:     $logo = '<a href="/adm/about.html"><img src="'.
                    378: 	$logo.'" alt="LON-CAPA Logo" class="LC_noBorder" /></a>';
1.199     albertel  379: 
1.152     albertel  380:     if ($env{'request.state'} eq 'construct') {
1.274     www       381: #
                    382: # We are in construction space
                    383: #
1.152     albertel  384:         if (($env{'request.noversionuri'} eq '') || (!defined($env{'request.noversionuri'}))) {
                    385:             my $returnurl = $env{'request.filename'};
1.134     raeburn   386:             $returnurl =~ s:^/home/([^/]+)/public_html/(.*)$:/priv/$1/$2:;
1.183     www       387:             $escurl = &escape($returnurl);
1.134     raeburn   388:         }
                    389:     }
1.165     raeburn   390:     if ($env{'request.course.id'}) {
1.274     www       391: #
                    392: # We are in a course
                    393: #
1.235     raeburn   394:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                    395:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.165     raeburn   396:         my %coursegroups;
1.188     albertel  397:         my $viewgrps_permission =
1.197     raeburn   398: 	    &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
1.165     raeburn   399:         if (!$viewgrps_permission) {
1.235     raeburn   400:             %coursegroups = &Apache::lonnet::get_active_groups($env{'user.domain'},$env{'user.name'},$cdom,$cnum);
1.188     albertel  401: 	}
1.165     raeburn   402:         if ((keys(%coursegroups) > 0) || ($viewgrps_permission)) {
                    403:             $showgroups = 1;
                    404:         }
1.235     raeburn   405:         $role_selector = &roles_selector($cdom,$cnum);
                    406:         if ($role_selector) {
                    407:             $roles = '<span class="LC_nobreak">'.$role_selector.'&nbsp;&nbsp;<a href="/adm/roles" target="_top">'.$lt{'other'}.'</a></span>';
                    408:         }
1.165     raeburn   409:     }
                    410: 
1.267     droeschl  411:     if ($env{'environment.remote'} eq 'off') {
1.48      www       412: # Remote Control is switched off
1.58      www       413: # figure out colors
1.267     droeschl  414:         my %lt=&initlittle();
1.172     albertel  415: 
1.58      www       416:         my $domain=&Apache::loncommon::determinedomain();
1.291     raeburn   417:         my $function=&Apache::loncommon::get_users_function();
1.58      www       418:         my $link=&Apache::loncommon::designparm($function.'.link',$domain);
                    419:         my $alink=&Apache::loncommon::designparm($function.'.alink',$domain);
                    420:         my $vlink=&Apache::loncommon::designparm($function.'.vlink',$domain);
                    421:         my $sidebg=&Apache::loncommon::designparm($function.'.sidebg',$domain);
1.267     droeschl  422: 
                    423:         if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
                    424:             return (<<ENDINLINEMENU);
1.285     wenzelju  425:             <ol class="LC_primary_menu LC_right">
1.271     droeschl  426:                 <li>$logo</li>
                    427:                 <li><a href="/adm/roles" target="_top">$lt{'login'}</a></li>
                    428:             </ol>
                    429:             <hr />
1.156     albertel  430: ENDINLINEMENU
                    431:         }
1.253     kaisler   432:         $roles = '<a href="/adm/roles" target="_top">'.$lt{'roles'}.'</a>';
1.58      www       433: # Do we have a NAV link?
1.152     albertel  434:         if ($env{'request.course.id'}) {
1.141     albertel  435: 	    my $link='/adm/navmaps?postdata='.$escurl.'&amp;postsymb='.
                    436: 		$escsymb;
1.152     albertel  437: 	    if ($env{'environment.remotenavmap'} eq 'on') {
1.141     albertel  438: 		$link="javascript:gonav('".$link."')";
                    439: 	    }
                    440: 	    $navmaps=(<<ENDNAV);
1.253     kaisler   441: <li><a href="$link" target="_top">$lt{'nav'}</a></li>
1.114     albertel  442: ENDNAV
1.286     raeburn   443:             my $is_community = 
                    444:                 (&Apache::loncommon::course_type() eq 'Community');
1.152     albertel  445: 	    if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1.286     raeburn   446:                 my $text = ($is_community) ? $lt{'gdoc'} : $lt{'docs'};
1.151     www       447: 		$docs=(<<ENDDOCS);
1.253     kaisler   448: <li><a href="/adm/coursedocs" target="_top">$text</a></li>
1.151     www       449: ENDDOCS
                    450:             }
1.197     raeburn   451:             if ($showgroups) {
                    452:                 $groups =(<<ENDGROUPS);
1.253     kaisler   453: <li><a href="/adm/coursegroups" target="_top">$lt{'groups'}</a></li>
1.197     raeburn   454: ENDGROUPS
                    455:             }
1.228     albertel  456: 	    if (&show_return_link()) {
1.183     www       457:                 my $escreload=&escape('return:');
1.59      www       458:                 $reloadlink=(<<ENDRELOAD);
1.253     kaisler   459: <li><a href="/adm/flip?postdata=$escreload" target="_top">$lt{'ret'}</a></li>
1.59      www       460: ENDRELOAD
                    461:             }
1.235     raeburn   462:             if ($role_selector) {
1.253     kaisler   463:             	#$roles = '<td>'.$role_selector.'</td><td><a href="/adm/roles" target="_top">'.$lt{'other'}.'</a></td>';
                    464: 				$role_selector = '<li>'.$role_selector.'</li>';
1.235     raeburn   465:             }
1.55      www       466:         }
1.163     www       467: 	if (($env{'request.state'} eq 'construct') && ($env{'request.course.id'})) {
1.183     www       468: 	    my $escreload=&escape('return:');
1.163     www       469: 	    $reloadlink=(<<ENDCRELOAD);
1.253     kaisler   470: <li><a href="/adm/flip?postdata=$escreload" target="_top">$lt{'ret'}</a></li>
1.163     www       471: ENDCRELOAD
                    472:         }
1.276     droeschl  473:     my $reg     = $forcereg ? &innerregister($forcereg,$titletable) : '';
                    474:     my $form    = &serverform();
                    475:     my $utility = &utilityfunctions();
                    476: 
                    477:     #Prepare the message link that indicates the arrival of new mail
1.291     raeburn   478:     my $messagelink = &Apache::lonmsg::mynewmail() ? "Message (new)" : "Message";
1.276     droeschl  479:        $messagelink = '<a href="javascript:go(\'/adm/communicate\');">'
                    480:                       . mt($messagelink) .'</a>';
                    481: 
                    482:     my $helplink = &Apache::loncommon::top_nav_help('Help');
1.58      www       483: 	return (<<ENDINLINEMENU);
1.129     albertel  484: <script type="text/javascript">
1.277     bisitz    485: // <![CDATA[
1.150     albertel  486: // BEGIN LON-CAPA Internal
1.116     albertel  487: $utility
1.150     albertel  488: // ]]>
1.48      www       489: </script>
1.285     wenzelju  490: <ol class="LC_primary_menu LC_right">
1.253     kaisler   491: 	<li>$logo</li>
1.256     kaisler   492: 	<li>$messagelink</li>
1.253     kaisler   493: 	<li>$roles</li>
                    494: 	<li>$helplink</li>
                    495: 	<li><a href="/adm/logout" target="_top">$lt{'exit'}</a></li>
                    496: </ol>
1.285     wenzelju  497: <ul id="LC_secondary_menu">
1.253     kaisler   498: <li><a href="/adm/menu" target="_top">$lt{'main'}</a></li>
1.59      www       499: $reloadlink
1.55      www       500: $navmaps
1.151     www       501: $docs
1.165     raeburn   502: $groups
1.253     kaisler   503: $role_selector
1.263     droeschl  504: </ul>
1.168     albertel  505: $form
1.129     albertel  506: <script type="text/javascript">
1.48      www       507: // END LON-CAPA Internal
                    508: </script>
1.58      www       509: $reg
1.48      www       510: ENDINLINEMENU
                    511:     } else {
                    512: 	return '';
                    513:     }
1.72      www       514: }
                    515: 
1.228     albertel  516: sub show_return_link {
                    517:     return (($env{'request.noversionuri'}=~m{^/(res|public)/} &&
                    518: 	     $env{'request.symb'} eq '')
                    519: 	    ||
                    520: 	    ($env{'request.noversionuri'}=~ m{^/cgi-bin/printout.pl})
                    521: 	    ||
                    522: 	    (($env{'request.noversionuri'}=~/^\/adm\//) &&
                    523: 	     ($env{'request.noversionuri'}!~/^\/adm\/wrapper\//) &&
                    524: 	     ($env{'request.noversionuri'}!~
                    525: 	      m[^/adm/.*/(smppg|bulletinboard|aboutme)($|\?)])
                    526: 	     ));
                    527: }
                    528: 
1.38      www       529: 
                    530: sub registerurl {
1.173     albertel  531:     my ($forcereg) = @_;
1.38      www       532:     my $result = '';
1.175     albertel  533:     if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
1.66      albertel  534:     my $force_title='';
1.152     albertel  535:     if ($env{'request.state'} eq 'construct') {
1.66      albertel  536: 	$force_title=&Apache::lonxml::display_title();
                    537:     }
1.269     droeschl  538:     if (($env{'environment.remote'} eq 'off') ||
1.152     albertel  539:         ((($env{'request.publicaccess'}) || 
1.83      www       540:          (!&Apache::lonnet::is_on_map(
1.183     www       541: 	   &unescape($env{'request.noversionuri'})))) &&
1.38      www       542:         (!$forcereg))) {
1.277     bisitz    543:  	return
                    544:         $result
                    545:        .'<script type="text/javascript">'."\n"
                    546:        .'// <![CDATA['."\n"
                    547:        .'function LONCAPAreg(){;} function LONCAPAstale(){}'."\n"
                    548:        .'// ]]>'."\n"
                    549:        .'</script>'
                    550:        .$force_title;
1.38      www       551:     }
1.41      www       552: # Graphical display after login only
1.174     albertel  553:     if ($env{'request.registered'} && !$forcereg) { return ''; }
1.173     albertel  554:     $result.=&innerregister($forcereg);
1.66      albertel  555:     return $result.$force_title;
1.40      www       556: }
                    557: 
                    558: sub innerregister {
1.308     raeburn   559:     my ($forcereg,$titletable,$bread_crumbs) = @_;
1.40      www       560:     my $result = '';
1.120     raeburn   561:     my ($uname,$thisdisfn);
1.152     albertel  562:     my $const_space = ($env{'request.state'} eq 'construct');
1.131     raeburn   563:     my $is_const_dir = 0;
1.120     raeburn   564: 
1.175     albertel  565:     if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
1.40      www       566: 
1.174     albertel  567:     $env{'request.registered'} = 1;
1.40      www       568: 
1.267     droeschl  569:     my $noremote = ($env{'environment.remote'} eq 'off');
1.49      www       570:     
1.177     albertel  571:     undef(@inlineremote);
1.56      www       572: 
1.38      www       573:     my $reopen=&Apache::lonmenu::reopenmenu();
1.40      www       574: 
1.38      www       575:     my $newmail='';
1.267     droeschl  576: 
                    577:     if (&Apache::lonmsg::newmail() && !$noremote) { 
                    578:         # We have new mail and remote is up
                    579:         $newmail= 'swmenu.setstatus("you have","messages");';
1.233     www       580:     } 
1.276     droeschl  581: 
1.288     raeburn   582:     my ($breadcrumb,$separator);
1.267     droeschl  583:     if ($noremote
1.177     albertel  584: 	     && ($env{'request.symb'}) 
                    585: 	     && ($env{'request.course.id'})) {
1.267     droeschl  586: 
                    587:         my ($mapurl,$rid,$resurl) = &Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
                    588:         my $coursetitle = $env{'course.'.$env{'request.course.id'}.'.description'};
                    589: 
                    590:         my $maptitle = &Apache::lonnet::gettitle($mapurl);
                    591:         my $restitle = &Apache::lonnet::gettitle(&Apache::lonnet::symbread());
1.299     raeburn   592:         my $contentstext;
                    593:         if ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Community') {
                    594:             $contentstext = &mt('Community Contents');
                    595:         } else {
                    596:             $contentstext = &mt('Course Contents');
                    597:         }
                    598:         my @crumbs = ({text  => $contentstext, 
1.289     raeburn   599:                        href  => "Javascript:gonav('/adm/navmaps')"});
                    600: 
                    601:         if ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) { 
                    602:             push(@crumbs, {text  => '...',
                    603:                            no_mt => 1});
                    604:         }
1.268     droeschl  605: 
                    606:         push @crumbs, {text => $maptitle, no_mt => 1} if ($maptitle 
                    607:                                                    && $maptitle ne 'default.sequence' 
                    608:                                                    && $maptitle ne $coursetitle);
                    609: 
                    610:         push @crumbs, {text => $restitle, no_mt => 1} if $restitle; 
                    611: 
1.291     raeburn   612:         &Apache::lonhtmlcommon::clear_breadcrumbs();
                    613:         &Apache::lonhtmlcommon::add_breadcrumb(@crumbs);
1.301     droeschl  614:         #$breadcrumb .= &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0);
1.288     raeburn   615: 	unless (($env{'request.state'} eq 'edit') || ($newmail) ||
                    616: 		($env{'request.state'} eq 'construct') ||
                    617: 		($env{'form.register'})) {
                    618:             $separator = &Apache::loncommon::head_subbox();
                    619:         }
1.267     droeschl  620:         #
1.65      www       621:     }
1.152     albertel  622:     if ($env{'request.state'} eq 'construct') {
1.131     raeburn   623:         $newmail = $titletable;
1.267     droeschl  624:     } 
                    625:     my $timesync   = ( $noremote ? '' : 'swmenu.syncclock(1000*'.time.');' );
                    626:     my $tablestart = ( $noremote ? '<table id="LC_menubuttons">' : '');
                    627:     my $tableend   = ( $noremote ? '</table>' : '');
1.41      www       628: # =============================================================================
                    629: # ============================ This is for URLs that actually can be registered
1.296     droeschl  630:     if (($env{'request.noversionuri'}!~m{^/(res/)*adm/}) || ($forcereg)) {
1.40      www       631: # -- This applies to homework problems for users with grading privileges
1.152     albertel  632: 	my $crs='/'.$env{'request.course.id'};
                    633: 	if ($env{'request.course.sec'}) {
                    634: 	    $crs.='_'.$env{'request.course.sec'};
1.107     albertel  635: 	}
                    636: 	$crs=~s/\_/\//g;
                    637: 
1.38      www       638:         my $hwkadd='';
1.152     albertel  639:         if ($env{'request.symb'} ne '' &&
1.161     albertel  640: 	    $env{'request.filename'}=~/\.(problem|exam|quiz|assess|survey|form|task)$/) {
1.79      www       641: 	    if (&Apache::lonnet::allowed('mgr',$crs)) {
1.259     bisitz    642: 		$hwkadd.=&switch('','',7,2,'pgrd.gif','problem[_1]','grades[_4]',
1.40      www       643:                        "gocmd('/adm/grades','gradingmenu')",
                    644:                        'Modify user grades for this assessment resource');
1.154     www       645:             } elsif (&Apache::lonnet::allowed('vgr',$crs)) {
                    646: 		$hwkadd.=&switch('','',7,2,'subm.gif','view sub-[_1]','missions[_1]',
                    647:                        "gocmd('/adm/grades','submission')",
                    648: 		       'View user submissions for this assessment resource');
1.38      www       649:             }
1.107     albertel  650: 	}
1.152     albertel  651: 	if ($env{'request.symb'} ne '' &&
1.145     albertel  652: 	    &Apache::lonnet::allowed('opa',$crs)) {
1.107     albertel  653: 	    $hwkadd.=&switch('','',7,3,'pparm.gif','problem[_2]','parms[_2]',
                    654: 			     "gocmd('/adm/parmset','set')",
1.196     www       655: 			     'Modify parameter settings for this resource');
1.38      www       656: 	}
1.40      www       657: # -- End Homework
1.38      www       658:         ###
                    659:         ### Determine whether or not to display the 'cstr' button for this
                    660:         ### resource
                    661:         ###
                    662:         my $editbutton = '';
1.258     raeburn   663:         my $noeditbutton = 1;
                    664:         my ($cnum,$cdom);
                    665:         if ($env{'request.course.id'}) {
                    666:             $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                    667:             $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                    668:         }
1.152     albertel  669:         if ($env{'user.author'}) {
1.234     raeburn   670:             if ($env{'request.role'}=~/^(aa|ca|au)/) {
1.274     www       671: #
                    672: # We have the role of an author
                    673: #
1.38      www       674:                 # Set defaults for authors
                    675:                 my ($top,$bottom) = ('con-','struct');
1.152     albertel  676:                 my $action = "go('/priv/".$env{'user.name'}."');";
                    677:                 my $cadom  = $env{'request.role.domain'};
                    678:                 my $caname = $env{'user.name'};
1.236     bisitz    679:                 my $desc = "Enter my construction space";
1.38      www       680:                 # Set defaults for co-authors
1.152     albertel  681:                 if ($env{'request.role'} =~ /^ca/) { 
1.206     albertel  682:                     ($cadom,$caname)=($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.38      www       683:                     ($top,$bottom) = ('co con-','struct');
                    684:                     $action = "go('/priv/".$caname."');";
                    685:                     $desc = "Enter construction space as co-author";
1.234     raeburn   686:                 } elsif ($env{'request.role'} =~ /^aa/) {
                    687:                     ($cadom,$caname)=($env{'request.role'}=~/($match_domain)\/($match_username)$/);
                    688:                     ($top,$bottom) = ('co con-','struct');
                    689:                     $action = "go('/priv/".$caname."');";
                    690:                     $desc = "Enter construction space as assistant co-author";
1.38      www       691:                 }
                    692:                 # Check that we are on the correct machine
                    693:                 my $home = &Apache::lonnet::homeserver($caname,$cadom);
1.109     albertel  694: 		my $allowed=0;
                    695: 		my @ids=&Apache::lonnet::current_machine_ids();
                    696: 		foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                    697: 		if (!$allowed) {
                    698: 		    $editbutton=&switch('','',6,1,$top,,$bottom,$action,$desc);
1.258     raeburn   699:                     $noeditbutton = 0;
1.38      www       700:                 }
                    701:             }
1.274     www       702: #
                    703: # We are an author for some stuff, but currently do not have the role of author.
                    704: # Figure out if we have authoring privileges for the resource we are looking at.
                    705: # This should maybe become a privilege check in lonnet
                    706: #
1.38      www       707:             ##
                    708:             ## Determine if user can edit url.
                    709:             ##
                    710:             my $cfile='';
                    711:             my $cfuname='';
                    712:             my $cfudom='';
1.258     raeburn   713:             my $uploaded;
1.152     albertel  714:             if ($env{'request.filename'}) {
                    715:                 my $file=&Apache::lonnet::declutter($env{'request.filename'});
1.258     raeburn   716:                 if (defined($cnum) && defined($cdom)) {
                    717:                     $uploaded = &is_course_upload($file,$cnum,$cdom);
                    718:                 }
                    719:                 if (!$uploaded) {
                    720:                     $file=~s/^($match_domain)\/($match_username)/\/priv\/$2/;
                    721:                     # Check that the user has permission to edit this resource
                    722:                     ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$1);
                    723:                     if (defined($cfudom)) {
                    724: 		        my $home=&Apache::lonnet::homeserver($cfuname,$cfudom);
                    725: 		        my $allowed=0;
                    726: 		        my @ids=&Apache::lonnet::current_machine_ids();
                    727: 		        foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                    728: 		        if ($allowed) {
                    729:                             $cfile=$file;
                    730:                         }
1.38      www       731:                     }
                    732:                 }
1.258     raeburn   733:             }
1.38      www       734:             # Finally, turn the button on or off
1.120     raeburn   735:             if ($cfile && !$const_space) {
1.302     raeburn   736:                 my $nocrsedit;
                    737:                 # Suppress display where CC has switched to student role.
                    738:                 if ($env{'request.course.id'}) {
                    739:                     unless(&Apache::lonnet::allowed('mdc',
                    740:                                                     $env{'request.course.id'})) {
                    741:                         $nocrsedit = 1;
                    742:                     }
                    743:                 }
                    744:                 if ($nocrsedit) {
                    745:                     $editbutton=&clear(6,1);
                    746:                 } else {
                    747:                     $editbutton=&switch
                    748:                        ('','',6,1,'pcstr.gif','edit[_1]','resource[_2]',
1.38      www       749:                      "go('".$cfile."');","Edit this resource");
1.302     raeburn   750:                     $noeditbutton = 0;
                    751:                 }
1.38      www       752:             } elsif ($editbutton eq '') {
1.191     www       753:                 $editbutton=&clear(6,1);
1.38      www       754:             }
                    755:         }
1.258     raeburn   756:         if (($noeditbutton) && ($env{'request.filename'})) { 
                    757:             if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
                    758:                 my $file=&Apache::lonnet::declutter($env{'request.filename'});
                    759:                 if (defined($cnum) && defined($cdom)) {
                    760:                     if (&is_course_upload($file,$cnum,$cdom)) {
                    761:                         my $cfile = &edit_course_upload($file,$cnum,$cdom);
                    762:                         if ($cfile) {
                    763:                             $editbutton=&switch
                    764:                                         ('','',6,1,'pcstr.gif','edit[_1]',
                    765:                                          'resource[_2]',"go('".$cfile."');",
                    766:                                          'Edit this resource');
                    767:                         }
                    768:                     }
                    769:                 }
                    770:             }
                    771:         }
1.38      www       772:         ###
                    773:         ###
1.41      www       774: # Prepare the rest of the buttons
1.120     raeburn   775:         my $menuitems;
                    776:         if ($const_space) {
1.274     www       777: #
                    778: # We are in construction space
                    779: #
1.128     albertel  780: 	    my ($uname,$thisdisfn) =
1.152     albertel  781: 		($env{'request.filename'}=~m|^/home/([^/]+)/public_html/(.*)|);
1.121     raeburn   782:             my $currdir = '/priv/'.$uname.'/'.$thisdisfn;
1.131     raeburn   783:             if ($currdir =~ m-/$-) {
                    784:                 $is_const_dir = 1;
                    785:             } else {
1.267     droeschl  786:                 $currdir =~ s|[^/]+$||;
1.200     foxr      787: 		my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn);
1.208     albertel  788: 		my $esc_currdir = &Apache::loncommon::escape_single($currdir);
1.274     www       789: #
                    790: # Probably should be in mydesk.tab
                    791: #
1.131     raeburn   792:                 $menuitems=(<<ENDMENUITEMS);
1.208     albertel  793: s&6&1&list.gif&list[_1]&dir[_1]&golist('$esc_currdir')&List current directory
1.200     foxr      794: s&6&2&rtrv.gif&retrieve[_1]&version[_1]&gocstr('/adm/retrieve','/~$uname/$cleandisfn')&Retrieve old version
1.259     bisitz    795: s&6&3&pub.gif&publish[_1]&resource[_3]&gocstr('/adm/publish','/~$uname/$cleandisfn')&Publish this resource
1.200     foxr      796: s&7&1&del.gif&delete[_1]&resource[_2]&gocstr('/adm/cfile?action=delete','/~$uname/$cleandisfn')&Delete this resource
                    797: s&7&2&prt.gif&prepare[_1]&printout[_1]&gocstr('/adm/printout','/~$uname/$cleandisfn')&Prepare a printable document
1.120     raeburn   798: ENDMENUITEMS
1.131     raeburn   799:             }
1.308     raeburn   800:             if ($noremote) {
                    801:                 if (ref($bread_crumbs) eq 'ARRAY') {
                    802:                     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    803:                     foreach my $crumb (@{$bread_crumbs}){
                    804:                         &Apache::lonhtmlcommon::add_breadcrumb($crumb);
                    805:                     }
                    806:                 }
                    807:             }
1.203     foxr      808:         } elsif ( defined($env{'request.course.id'}) && 
                    809: 		 $env{'request.symb'} ne '' ) {
1.274     www       810: #
                    811: # We are in a course and looking at a registred URL
                    812: # Should probably be in mydesk.tab
                    813: #
1.120     raeburn   814: 	    $menuitems=(<<ENDMENUITEMS);
1.41      www       815: c&3&1
1.209     www       816: s&2&1&back.gif&backward[_1]&&gopost('/adm/flip','back:'+currentURL)&Go to the previous resource in the course sequence&&1
                    817: s&2&3&forw.gif&forward[_1]&&gopost('/adm/flip','forward:'+currentURL)&Go to the next resource in the course sequence&&3
1.77      www       818: c&6&3
                    819: c&8&1
                    820: c&8&2
1.106     www       821: s&8&3&prt.gif&prepare[_1]&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
1.209     www       822: s&9&1&sbkm.gif&set[_1]&bookmark[_2]&set_bookmark()&Set a bookmark for this resource&&1
1.41      www       823: ENDMENUITEMS
1.216     albertel  824: 
1.243     tempelho  825: my $currentURL = &Apache::loncommon::get_symb();
                    826: my ($symb_old,$symb_old_enc) = &Apache::loncommon::clean_symb($currentURL);
                    827: my $annotation = &Apache::loncommon::get_annotation($symb_old,$symb_old_enc);
                    828: $menuitems.="s&9&3&";
                    829: if(length($annotation) > 0){
                    830: 	$menuitems.="anot2.gif";
                    831: }else{
                    832: 	$menuitems.="anot.gif";
                    833: }
                    834: $menuitems.="&anno-[_1]&tations[_1]&annotate()&";
                    835: $menuitems.="Make notes and annotations about this resource&&1\n";
                    836: 
1.279     raeburn   837:             unless ($noremote) { 
                    838:                 my $showreqcrs = &check_for_rcrs();
                    839:                 if ($showreqcrs) {
                    840:                     $menuitems.="s&8&1&rcrs.gif&request[_1]&course[_16]".
                    841:                                 "&go('/adm/requestcourse')&Course requests\n";
                    842:                 }
                    843:             }
1.193     raeburn   844:             unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme)(\?|$)/) {
1.294     raeburn   845: 		if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/})) {
1.216     albertel  846: 		    $menuitems.=(<<ENDREALRES);
1.259     bisitz    847: s&6&3&catalog.gif&catalog[_2]&info[_1]&catalog_info()&Show Metadata
1.216     albertel  848: ENDREALRES
                    849:                 }
1.120     raeburn   850: 	        $menuitems.=(<<ENDREALRES);
1.106     www       851: s&8&1&eval.gif&evaluate[_1]&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
                    852: s&8&2&fdbk.gif&feedback[_1]&discuss[_1]&gopost('/adm/feedback',currentURL,1)&Provide feedback messages or contribute to the course discussion about this resource
1.77      www       853: ENDREALRES
1.120     raeburn   854: 	    }
                    855:         }
1.203     foxr      856: 	if ($env{'request.uri'} =~ /^\/res/) {
                    857: 	    $menuitems .= (<<ENDMENUITEMS);
                    858: s&8&3&prt.gif&prepare[_1]&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
                    859: ENDMENUITEMS
                    860: 	}
1.41      www       861:         my $buttons='';
                    862:         foreach (split(/\n/,$menuitems)) {
                    863: 	    my ($command,@rest)=split(/\&/,$_);
1.220     raeburn   864:             my $idx=10*$rest[0]+$rest[1];
                    865:             if (&hidden_button_check() eq 'yes') {
                    866:                 if ($idx == 21 ||$idx == 23) {
                    867:                     $buttons.=&switch('','',@rest);
                    868:                 } else {
                    869:                     $buttons.=&clear(@rest);
                    870:                 }
                    871:             } else {  
                    872:                 if ($command eq 's') {
                    873: 	            $buttons.=&switch('','',@rest);
                    874:                 } else {
                    875:                     $buttons.=&clear(@rest);
                    876:                 }
1.41      www       877:             }
                    878:         }
1.148     albertel  879: 
1.267     droeschl  880:         if ($noremote) {
1.148     albertel  881: 	    my $addremote=0;
1.267     droeschl  882: 	    foreach (@inlineremote) { if ($_ ne '') { $addremote=1; last;} }
1.148     albertel  883: 	    my $inlinebuttons='';
1.301     droeschl  884:     if ($addremote) {
                    885: 
                    886:         #SD START (work in progress!)
1.304     droeschl  887:         Apache::lonhtmlcommon::clear_breadcrumb_tools();
1.301     droeschl  888:         # Arrows for navigation
                    889:         Apache::lonhtmlcommon::add_breadcrumb_tool( 'A', $inlineremote[21] );
                    890:         Apache::lonhtmlcommon::add_breadcrumb_tool( 'A', $inlineremote[23] );
                    891:         if(hidden_button_check() ne 'yes'){
                    892:             # notes
                    893:             Apache::lonhtmlcommon::add_breadcrumb_tool( 'B', $inlineremote[93]);
                    894:             # bookmark
                    895:             Apache::lonhtmlcommon::add_breadcrumb_tool( 'B', $inlineremote[91]);
                    896:             # evaluate
                    897:             Apache::lonhtmlcommon::add_breadcrumb_tool( 'B', $inlineremote[81]);
                    898:             # feedback
                    899:             Apache::lonhtmlcommon::add_breadcrumb_tool( 'B', $inlineremote[82]);
                    900:             # print
                    901:             Apache::lonhtmlcommon::add_breadcrumb_tool( 'B', $inlineremote[83]);
                    902:             # metadata
                    903:             Apache::lonhtmlcommon::add_breadcrumb_tool( 'B', $inlineremote[63]);
                    904: 
                    905:             # ?
                    906:             Apache::lonhtmlcommon::add_breadcrumb_tool( 'C', $inlineremote[61]);
                    907:             # ?
                    908:             Apache::lonhtmlcommon::add_breadcrumb_tool( 'C', $inlineremote[71]);
                    909:             # ?
                    910:             Apache::lonhtmlcommon::add_breadcrumb_tool( 'C', $inlineremote[72]);
                    911:             # ?
                    912:             Apache::lonhtmlcommon::add_breadcrumb_tool( 'C', $inlineremote[73]);
                    913:             # ?
                    914:             Apache::lonhtmlcommon::add_breadcrumb_tool( 'C', $inlineremote[92]);
                    915: 
                    916:         }
                    917: 
                    918:         #SD END
                    919: #       # Registered, textual output
                    920: #        if ( $env{'environment.icons'} eq 'iconsonly' ) {
                    921: #            $inlinebuttons = (<<ENDARROWSINLINE);
                    922: #<tr><td>
                    923: #$inlineremote[21] $inlineremote[23]
                    924: #ENDARROWSINLINE
                    925: #            if ( &hidden_button_check() ne 'yes' ) {
                    926: #                $inlinebuttons .= (<<ENDINLINEICONS);
                    927: #$inlineremote[61] $inlineremote[63]
                    928: #$inlineremote[71] $inlineremote[72] $inlineremote[73]
                    929: #$inlineremote[81] $inlineremote[82] $inlineremote[83]
                    930: #$inlineremote[91] $inlineremote[92] $inlineremote[93]</td></tr>
                    931: #ENDINLINEICONS
                    932: #            }
                    933: #        } else { # not iconsonly
                    934: #            if ( $inlineremote[21] ne '' || $inlineremote[23] ne '' ) {
                    935: #                $inlinebuttons = (<<ENDFIRSTLINE);
                    936: #<tr><td>$inlineremote[21]</td><td>&nbsp;</td><td>$inlineremote[23]</td></tr>
                    937: #ENDFIRSTLINE
                    938: #            }
                    939: #            if ( &hidden_button_check() ne 'yes' ) {
                    940: #                foreach my $row ( 6 .. 9 ) {
                    941: #                    if (   $inlineremote[ ${row} . '1' ] ne ''
                    942: #                        || $inlineremote[ $row . '2' ] ne ''
                    943: #                        || $inlineremote[ $row . '3' ] ne '' )
                    944: #                    {
                    945: #                        $inlinebuttons .= <<"ENDLINE";
                    946: #<tr><td>$inlineremote["${row}1"]</td><td>$inlineremote["${row}2"]</td><td>$inlineremote["${row}3"]</td></tr>
                    947: #ENDLINE
                    948: #                    }
                    949: #                }
                    950: #            }
                    951: #        }
                    952:     }
                    953:         #SD see below
                    954:         $breadcrumb = &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0);
1.41      www       955: 	    $result =(<<ENDREGTEXT);
1.129     albertel  956: <script type="text/javascript">
1.42      www       957: // BEGIN LON-CAPA Internal
                    958: </script>
1.41      www       959: $timesync
1.267     droeschl  960: $breadcrumb
1.305     bisitz    961: <!-- $tablestart -->
                    962: <!-- $inlinebuttons -->
                    963: <!-- $tableend -->
1.224     albertel  964: $newmail
1.305     bisitz    965: <!-- $separator -->
1.129     albertel  966: <script type="text/javascript">
1.64      www       967: // END LON-CAPA Internal
1.42      www       968: </script>
                    969: 
1.41      www       970: ENDREGTEXT
                    971: # Registered, graphical output
                    972:         } else {
1.152     albertel  973: 	    my $requri=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
1.183     www       974: 	    $requri=&Apache::lonenc::check_encrypt(&unescape($requri));
1.152     albertel  975: 	    my $cursymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
1.113     albertel  976: 	    my $navstatus=&get_nav_status();
1.140     albertel  977: 	    my $clearcstr;
1.148     albertel  978: 
1.152     albertel  979: 	    if ($env{'user.adv'}) { $clearcstr='clearbut(6,1)'; }
1.41      www       980: 	    $result = (<<ENDREGTHIS);
1.38      www       981:      
1.129     albertel  982: <script type="text/javascript">
1.277     bisitz    983: // <![CDATA[
1.150     albertel  984: // BEGIN LON-CAPA Internal
1.42      www       985: var swmenu=null;
1.38      www       986: 
                    987:     function LONCAPAreg() {
                    988: 	  swmenu=$reopen;
                    989:           swmenu.clearTimeout(swmenu.menucltim);
                    990:           $timesync
                    991:           $newmail
1.41      www       992:           $buttons
1.84      www       993: 	  swmenu.currentURL="$requri";
1.85      www       994:           swmenu.reloadURL=swmenu.currentURL+window.location.search;
1.125     albertel  995:           swmenu.currentSymb="$cursymb";
                    996:           swmenu.reloadSymb="$cursymb";
1.38      www       997:           swmenu.currentStale=0;
1.113     albertel  998: 	  $navstatus
1.38      www       999:           $hwkadd
                   1000:           $editbutton
                   1001:     }
                   1002: 
                   1003:     function LONCAPAstale() {
                   1004: 	  swmenu=$reopen
                   1005:           swmenu.currentStale=1;
                   1006:           if (swmenu.reloadURL!='' && swmenu.reloadURL!= null) { 
                   1007:              swmenu.switchbutton
                   1008:              (3,1,'reload.gif','return','location','go(reloadURL)','Return to the last known location in the course sequence');
                   1009: 	  }
                   1010:           swmenu.clearbut(7,2);
                   1011:           swmenu.clearbut(7,3);
                   1012:           swmenu.menucltim=swmenu.setTimeout(
                   1013:  'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+
1.140     albertel 1014:  'clearbut(9,1);clearbut(9,3);clearbut(6,3);$clearcstr',
1.38      www      1015: 			  2000);
                   1016:       }
                   1017: 
1.150     albertel 1018: // END LON-CAPA Internal 
1.277     bisitz   1019: // ]]>
1.38      www      1020: </script>
                   1021: ENDREGTHIS
1.41      www      1022:         }
                   1023: # =============================================================================
1.38      www      1024:     } else {
1.41      www      1025: # ========================================== This can or will not be registered
1.267     droeschl 1026:         if ($noremote) {
1.269     droeschl 1027: # Not registered
1.267     droeschl 1028:             $result= (<<ENDDONOTREGTEXT);
1.41      www      1029: ENDDONOTREGTEXT
                   1030:         } else {
                   1031: # Not registered, graphical
                   1032:            $result = (<<ENDDONOTREGTHIS);
1.38      www      1033: 
1.129     albertel 1034: <script type="text/javascript">
1.277     bisitz   1035: // <![CDATA[
1.38      www      1036: // BEGIN LON-CAPA Internal
1.42      www      1037: var swmenu=null;
1.38      www      1038: 
                   1039:     function LONCAPAreg() {
                   1040: 	  swmenu=$reopen
                   1041:           $timesync
                   1042:           swmenu.currentStale=1;
                   1043:           swmenu.clearbut(2,1);
                   1044:           swmenu.clearbut(2,3);
                   1045:           swmenu.clearbut(8,1);
                   1046:           swmenu.clearbut(8,2);
                   1047:           swmenu.clearbut(8,3);
                   1048:           if (swmenu.currentURL) {
                   1049:              swmenu.switchbutton
                   1050:               (3,1,'reload.gif','return','location','go(currentURL)');
                   1051:  	  } else {
                   1052: 	      swmenu.clearbut(3,1);
                   1053:           }
                   1054:     }
                   1055: 
                   1056:     function LONCAPAstale() {
                   1057:     }
                   1058: 
                   1059: // END LON-CAPA Internal
1.277     bisitz   1060: // ]]>
1.38      www      1061: </script>
                   1062: ENDDONOTREGTHIS
1.41      www      1063:        }
                   1064: # =============================================================================
1.38      www      1065:     }
                   1066:     return $result;
                   1067: }
                   1068: 
1.258     raeburn  1069: sub is_course_upload {
                   1070:     my ($file,$cnum,$cdom) = @_;
                   1071:     my $uploadpath = &LONCAPA::propath($cdom,$cnum);
                   1072:     $uploadpath =~ s{^\/}{};
                   1073:     if (($file =~ m{^\Q$uploadpath\E/userfiles/docs/}) ||
                   1074:         ($file =~ m{^userfiles/\Q$cdom\E/\Q$cnum\E/docs/})) {
                   1075:         return 1;
                   1076:     }
                   1077:     return;
                   1078: }
                   1079: 
                   1080: sub edit_course_upload {
                   1081:     my ($file,$cnum,$cdom) = @_;
                   1082:     my $cfile;
                   1083:     if ($file =~/\.(htm|html|css|js|txt)$/) {
                   1084:         my $ext = $1;
                   1085:         my $url = &Apache::lonnet::hreflocation('',$file);
                   1086:         my $home = &Apache::lonnet::homeserver($cnum,$cdom);
                   1087:         my @ids=&Apache::lonnet::current_machine_ids();
                   1088:         my $dest;
                   1089:         if ($home && grep(/^\Q$home\E$/,@ids)) {
                   1090:             $dest = $url.'?forceedit=1';
                   1091:         } else {
                   1092:             unless (&Apache::lonnet::get_locks()) {
                   1093:                 $dest = '/adm/switchserver?otherserver='.
                   1094:                         $home.'&role='.$env{'request.role'}.
                   1095:                         '&url='.$url.'&forceedit=1';
                   1096:             }
                   1097:         }
                   1098:         if ($dest) {
                   1099:             $cfile = &HTML::Entities::encode($dest,'"<>&');
                   1100:         }
                   1101:     }
                   1102:     return $cfile;
                   1103: }
                   1104: 
1.38      www      1105: sub loadevents() {
1.152     albertel 1106:     if ($env{'request.state'} eq 'construct' ||
1.175     albertel 1107: 	$env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
1.38      www      1108:     return 'LONCAPAreg();';
                   1109: }
                   1110: 
                   1111: sub unloadevents() {
1.152     albertel 1112:     if ($env{'request.state'} eq 'construct' ||
1.175     albertel 1113: 	$env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
1.38      www      1114:     return 'LONCAPAstale();';
                   1115: }
1.30      www      1116: 
1.32      www      1117: 
                   1118: sub startupremote {
                   1119:     my ($lowerurl)=@_;
1.269     droeschl 1120:     if ($env{'environment.remote'} eq 'off') {
1.34      www      1121:      return ('<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.$lowerurl.'" />');
                   1122:     }
1.49      www      1123: #
                   1124: # The Remote actually gets launched!
                   1125: #
1.32      www      1126:     my $configmenu=&rawconfig();
1.183     www      1127:     my $esclowerurl=&escape($lowerurl);
1.119     www      1128:     my $message=&mt('"Waiting for Remote Control window to load: "+[_1]','waited');
1.32      www      1129:     return(<<ENDREMOTESTARTUP);
1.129     albertel 1130: <script type="text/javascript">
1.277     bisitz   1131: // <![CDATA[
1.118     albertel 1132: var timestart;
1.35      www      1133: function wheelswitch() {
1.118     albertel 1134:     if (typeof(document.wheel) != 'undefined') {
                   1135: 	if (typeof(document.wheel.spin) != 'undefined') {
                   1136: 	    var date=new Date();
                   1137: 	    var waited=Math.round(30-((date.getTime()-timestart)/1000));
                   1138: 	    document.wheel.spin.value=$message;
                   1139: 	}
                   1140:     }
1.35      www      1141:    if (window.status=='|') { 
                   1142:       window.status='/'; 
                   1143:    } else {
                   1144:       if (window.status=='/') {
                   1145:          window.status='-';
                   1146:       } else {
                   1147:          if (window.status=='-') { 
                   1148:             window.status='\\\\'; 
                   1149:          } else {
                   1150:             if (window.status=='\\\\') { window.status='|'; }
                   1151:          }
                   1152:       }
                   1153:    } 
                   1154: }
                   1155: 
1.32      www      1156: // ---------------------------------------------------------- The wait function
                   1157: var canceltim;
                   1158: function wait() {
                   1159:    if ((menuloaded==1) || (tim==1)) {
1.35      www      1160:       window.status='Done.';
1.32      www      1161:       if (tim==0) {
                   1162:          clearTimeout(canceltim);
                   1163:          $configmenu
                   1164:          window.location='$lowerurl';  
                   1165:       } else {
1.52      www      1166: 	  window.location='/adm/remote?action=collapse&url=$esclowerurl';
1.32      www      1167:       }
                   1168:    } else {
1.35      www      1169:       wheelswitch();
                   1170:       setTimeout('wait();',200);
1.32      www      1171:    }
                   1172: }
                   1173: 
                   1174: function main() {
1.52      www      1175:    canceltim=setTimeout('tim=1;',30000);
1.35      www      1176:    window.status='-';
1.118     albertel 1177:    var date=new Date();
                   1178:    timestart=date.getTime();
1.32      www      1179:    wait();
                   1180: }
                   1181: 
1.277     bisitz   1182: // ]]>
1.32      www      1183: </script>
                   1184: ENDREMOTESTARTUP
                   1185: }
                   1186: 
                   1187: sub setflags() {
                   1188:     return(<<ENDSETFLAGS);
1.129     albertel 1189: <script type="text/javascript">
1.277     bisitz   1190: // <![CDATA[
1.32      www      1191:     menuloaded=0;
                   1192:     tim=0;
1.277     bisitz   1193: // ]]>
1.32      www      1194: </script>
                   1195: ENDSETFLAGS
                   1196: }
                   1197: 
                   1198: sub maincall() {
1.269     droeschl 1199:     if ($env{'environment.remote'} eq 'off') { return ''; }
1.32      www      1200:     return(<<ENDMAINCALL);
1.129     albertel 1201: <script type="text/javascript">
1.277     bisitz   1202: // <![CDATA[
1.32      www      1203:     main();
1.277     bisitz   1204: // ]]>
1.32      www      1205: </script>
                   1206: ENDMAINCALL
                   1207: }
1.118     albertel 1208: 
                   1209: sub load_remote_msg {
                   1210:     my ($lowerurl)=@_;
                   1211: 
1.269     droeschl 1212:     if ($env{'environment.remote'} eq 'off') { return ''; }
1.118     albertel 1213: 
1.183     www      1214:     my $esclowerurl=&escape($lowerurl);
1.261     bisitz   1215:     my $link=&mt('[_1]Continue[_2] on in Inline Menu mode'
                   1216:                 ,'<a href="/adm/remote?action=collapse&amp;url='.$esclowerurl.'">'
                   1217:                 ,'</a>');
1.118     albertel 1218:     return(<<ENDREMOTEFORM);
                   1219: <p>
                   1220: <form name="wheel">
1.119     www      1221: <input name="spin" type="text" size="60" />
1.118     albertel 1222: </form>
                   1223: </p>
                   1224: <p>$link</p>
                   1225: ENDREMOTEFORM
                   1226: }
1.230     albertel 1227: 
                   1228: sub get_menu_name {
                   1229:     my $hostid = $Apache::lonnet::perlvar{'lonHostID'};
                   1230:     $hostid =~ s/\W//g;
                   1231:     return 'LCmenu'.$hostid;
                   1232: }
                   1233: 
1.30      www      1234: 
                   1235: sub reopenmenu {
1.269     droeschl 1236:    if ($env{'environment.remote'} eq 'off') { return ''; }
1.230     albertel 1237:    my $menuname = &get_menu_name();
1.47      matthew  1238:    my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
                   1239:    return('window.open('.$nothing.',"'.$menuname.'","",false);');
1.30      www      1240: } 
                   1241: 
1.1       www      1242: 
                   1243: sub open {
1.22      www      1244:     my $returnval='';
1.269     droeschl 1245:     if ($env{'environment.remote'} eq 'off') { 
1.277     bisitz   1246: 	return
                   1247:         '<script type="text/javascript">'."\n"
                   1248:        .'// <![CDATA['."\n"
                   1249:        .'self.name="loncapaclient";'."\n"
                   1250:        .'// ]]>'."\n"
                   1251:        .'</script>';
1.111     albertel 1252:     }
1.230     albertel 1253:     my $menuname = &get_menu_name();
1.222     albertel 1254:     
                   1255: #    unless (shift eq 'unix') {
1.22      www      1256: # resizing does not work on linux because of virtual desktop sizes
1.222     albertel 1257: #       $returnval.=(<<ENDRESIZE);
                   1258: #if (window.screen) {
                   1259: #    self.resizeTo(screen.availWidth-215,screen.availHeight-55);
                   1260: #    self.moveTo(190,15);
                   1261: #}
                   1262: #ENDRESIZE
                   1263: #    }
1.277     bisitz   1264:     $returnval=(<<ENDOPEN);
                   1265: // <![CDATA[
1.35      www      1266: window.status='Opening LON-CAPA Remote Control';
1.272     droeschl 1267: var menu=window.open("/res/adm/pages/menu.html?inhibitmenu=yes","$menuname",
1.191     www      1268: "height=375,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5");
1.71      www      1269: self.name='loncapaclient';
1.277     bisitz   1270: // ]]>
1.1       www      1271: ENDOPEN
1.129     albertel 1272:     return '<script type="text/javascript">'.$returnval.'</script>';
1.1       www      1273: }
                   1274: 
1.2       www      1275: 
                   1276: # ================================================================== Raw Config
                   1277: 
1.3       www      1278: sub clear {
                   1279:     my ($row,$col)=@_;
1.269     droeschl 1280:     unless ($env{'environment.remote'} eq 'off') {
1.275     www      1281:        if (($row<1) || ($row>13)) { return ''; }
1.35      www      1282:        return "\n".qq(window.status+='.';swmenu.clearbut($row,$col););
1.56      www      1283:    } else { 
                   1284:        $inlineremote[10*$row+$col]='';
                   1285:        return ''; 
                   1286:    }
1.3       www      1287: }
                   1288: 
1.40      www      1289: # ============================================ Switch a button or create a link
1.25      matthew  1290: # Switch acts on the javascript that is executed when a button is clicked.  
                   1291: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
1.40      www      1292: 
1.2       www      1293: sub switch {
1.209     www      1294:     my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak)=@_;
1.2       www      1295:     $act=~s/\$uname/$uname/g;
                   1296:     $act=~s/\$udom/$udom/g;
1.88      www      1297:     $top=&mt($top);
                   1298:     $bot=&mt($bot);
                   1299:     $desc=&mt($desc);
1.238     www      1300:     if (($env{'environment.remote'} ne 'off') || ($env{'environment.icons'} eq 'classic')) {
                   1301:        $img=&mt($img);
                   1302:     }
1.209     www      1303:     my $idx=10*$row+$col;
                   1304:     $category_members{$cat}.=':'.$idx;
                   1305: 
1.269     droeschl 1306:     unless ($env{'environment.remote'} eq 'off') {
1.275     www      1307:        if (($row<1) || ($row>13)) { return ''; }
1.50      www      1308: # Remote
1.34      www      1309:        return "\n".
1.35      www      1310:  qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
1.34      www      1311:    } else {
1.50      www      1312: # Inline Remote
1.213     www      1313:        if ($env{'environment.icons'} ne 'classic') {
                   1314:           $img=~s/\.gif$/\.png/;
                   1315:        }
1.41      www      1316:        if ($nobreak==2) { return ''; }
1.34      www      1317:        my $text=$top.' '.$bot;
1.78      www      1318:        $text=~s/\s*\-\s*//gs;
1.105     www      1319: 
1.99      www      1320:        my $pic=
1.225     albertel 1321: 	   '<img alt="'.$text.'" src="'.
                   1322: 	   &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
1.303     droeschl 1323: 	   '" align="'.($nobreak==3?'right':'left').'" class="LC_icon" />';
1.177     albertel 1324:        if ($env{'browser.interface'} eq 'faketextual') {
1.274     www      1325: # Main Menu
1.103     www      1326: 	   if ($nobreak==3) {
1.209     www      1327: 	       $inlineremote[$idx]="\n".
1.177     albertel 1328: 		   '<td class="LC_menubuttons_text" align="right">'.$text.
1.247     harmsja  1329: 		   '</td><td align="left">'.
1.103     www      1330: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
                   1331: 	   } elsif ($nobreak) {
1.209     www      1332: 	       $inlineremote[$idx]="\n<tr>".
1.247     harmsja  1333: 		   '<td align="left">'.
1.177     albertel 1334: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td>
1.215     www      1335:                     <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      1336: 	   } else {
1.209     www      1337: 	       $inlineremote[$idx]="\n<tr>".
1.247     harmsja  1338: 		   '<td align="left">'.
1.103     www      1339: 		   '<a href="javascript:'.$act.';">'.$pic.
1.177     albertel 1340: 		   '</a></td><td class="LC_menubuttons_text" colspan="3">'.
1.215     www      1341: 		   '<a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$desc.'</span></a></td></tr>';
1.103     www      1342: 	   }
1.94      www      1343:        } else {
1.103     www      1344: # Inline Menu
1.218     www      1345:            if ($env{'environment.icons'} eq 'iconsonly') {
                   1346:               $inlineremote[$idx]='<a title="'.$desc.'" href="javascript:'.$act.';">'.$pic.'</a>';
                   1347:            } else {
                   1348: 	      $inlineremote[$idx]=
1.301     droeschl 1349: 		   '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.
1.215     www      1350: 		   '<span class="LC_menubuttons_inline_text">'.$desc.'</span></a>';
1.218     www      1351:            }
1.94      www      1352:        }
1.34      www      1353:    }
1.56      www      1354:     return '';
1.2       www      1355: }
                   1356: 
                   1357: sub secondlevel {
                   1358:     my $output='';
                   1359:     my 
1.209     www      1360:     ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_;
1.2       www      1361:     if ($prt eq 'any') {
1.209     www      1362: 	   $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1363:     } elsif ($prt=~/^r(\w+)/) {
                   1364:         if ($rol eq $1) {
1.209     www      1365:            $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1366:         }
                   1367:     }
                   1368:     return $output;
                   1369: }
                   1370: 
1.18      www      1371: sub openmenu {
1.230     albertel 1372:     my $menuname = &get_menu_name();
1.269     droeschl 1373:     if ($env{'environment.remote'} eq 'off') { return ''; }
1.47      matthew  1374:     my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
                   1375:     return "window.open(".$nothing.",'".$menuname."');";
1.18      www      1376: }
                   1377: 
1.56      www      1378: sub inlinemenu {
1.309.2.1  raeburn  1379:     my ($context,$switcher) = @_;
1.210     albertel 1380:     undef(@inlineremote);
                   1381:     undef(%category_members);
1.309.2.1  raeburn  1382:     my $output;
1.309.2.7  raeburn  1383:     if (($context eq 'gcicustom') || ($context eq 'gcistudent')) {
1.309.2.3  raeburn  1384:         $output='<table><tr>'.
                   1385:                 '<td class="LC_mainmenu_col_fieldset">'.
                   1386:                 '<div class="LC_Box LC_400Box">'.
                   1387:                 '<h3 class="LC_hcell">'.&mt('Utilities').'</h3>'.
1.309.2.7  raeburn  1388:                 '<table>';
                   1389:         if ($context eq 'gcicustom') {
                   1390:             my $createtext = &mt('Create Concept Test');
                   1391:             if ($switcher) {
                   1392:                 $createtext = &mt('Create New Test');
                   1393:             }
                   1394:             $output .= '<tr><td align="left"><a href="javascript:switchpage('."'createtest'".');"><img alt="choose role" src="/res/adm/pages/rcrs.png" align="left" class="LC_icon" /></a></td><td class="LC_menubuttons_text" colspan="3"><a class="LC_menubuttons_link" href="javascript:switchpage('."'createtest'".');"><span class="LC_menubuttons_inline_text">'.$createtext.'</span></a></td></tr>';
                   1395:         }
1.309.2.1  raeburn  1396:         if ($switcher) {
1.309.2.4  raeburn  1397:             $output .= '<tr><td align="left"><a href="javascript:courseswitcher('."'icon'".');"><img alt="choose role" src="/res/adm/pages/roles.png" align="left" class="LC_icon" /></a></td><td class="LC_menubuttons_text" colspan="2">'.$switcher.'</td></tr>';
1.309.2.1  raeburn  1398:         }
1.309.2.8  raeburn  1399:         $output .= '<tr><td align="left"><a href="javascript:go('."'/adm/communicate'".');"><img alt="communication" src="/res/adm/pages/com.png" align="left" class="LC_icon" /></a></td><td class="LC_menubuttons_text" colspan="3"><a class="LC_menubuttons_link" href="javascript:go('."'/adm/communicate'".');"><span class="LC_menubuttons_inline_text">'.&mt('Send/Display Messages').'</span></a></td></tr>'.
                   1400: '<tr><td align="left"><a href="javascript:go('."'/adm/preferences'".');"><img alt="user preferences" src="/res/adm/pages/pref.png" align="left" class="LC_icon" /></a></td><td class="LC_menubuttons_text" colspan="3"><a class="LC_menubuttons_link" href="javascript:go('."'/adm/preferences'".');"><span class="LC_menubuttons_inline_text">'.&mt('Set my user preferences').'</span></a></td></tr>';
                   1401:         if ($env{'request.course.id'}) {
1.309.2.7  raeburn  1402:             if (($context eq 'gcicustom') && (&Apache::lonnet::allowed('mdc',$env{'request.course.id'}))) {
                   1403:                 $output.= '</td></tr></table></div></td>'.
                   1404:                           '<td class="LC_mainmenu_col_fieldset">'.
                   1405:                           '<div class="LC_Box LC_400Box">'.
                   1406:                           '<h3 class="LC_hcell">'.&mt('Test Management').'</h3>'.
                   1407:                           '<table><tr><td align="left"><a href="javascript:gonav('."'/adm/navmaps'".');"><img alt="course contents" src="/res/adm/pages/nav.png" align="left" class="LC_icon" /></a></td><td class="LC_menubuttons_text" colspan="3"><a class="LC_menubuttons_link" href="javascript:gonav('."'/adm/navmaps'".');"><span class="LC_menubuttons_inline_text">Concept Test Contents</span></a></td></tr>'."\n".
                   1408:                           '<tr><td align="left"><a href="javascript:go('."'/adm/coursedocs'".');"><img alt="assemble test" src="/res/adm/pages/docs.png" align="left" class="LC_icon" /></a></td><td class="LC_menubuttons_text" colspan="3"><a class="LC_menubuttons_link" href="javascript:go('."'/adm/coursedocs'".');"><span class="LC_menubuttons_inline_text">Assemble Concept Test</span></a></td></tr>'."\n".
                   1409:                           '<tr><td align="left"><a href="javascript:go('."'/adm/createuser'".');"><img alt="user privs" src="/res/adm/pages/cprv.png" align="left" class="LC_icon" /></a></td><td class="LC_menubuttons_text" colspan="3"><a class="LC_menubuttons_link" href="javascript:go('."'/adm/createuser'".');"><span class="LC_menubuttons_inline_text">'.&mt('Manage Enrollment').'</span></a></td></tr>'."\n".
1.309.2.9  raeburn  1410:                          '<tr><td align="left"><a href="javascript:go('."'/adm/whatsnew'".');"><img alt="what is new" src="/res/adm/pages/new.png" align="left" class="LC_icon" /></a></td><td class="LC_menubuttons_text" colspan="3"><a class="LC_menubuttons_link" href="javascript:go('."'/adm/whatsnew'".');"><span class="LC_menubuttons_inline_text">'.&mt("What's New?").'</span></a></td></tr>'.
                   1411:                          '<tr><td align="left"><a href="javascript:go('."'/adm/statistics'".');"><img alt="Test Statistics" src="/res/adm/pages/chrt.png" align="left" class="LC_icon" /></a></td><td class="LC_menubuttons_text" colspan="3"><a class="LC_menubuttons_link" href="javascript:go('."'/adm/statistics'".');"><span class="LC_menubuttons_inline_text">'.&mt("Concept Test Statistics").'</span></a></td></tr></table></div></td>';
1.309.2.7  raeburn  1412:             } else {
                   1413:                 my $navtext = &mt('Table of Contents');
                   1414:                 if ($env{'request.role.domain'} eq 'gcitest') {
                   1415:                     $navtext = &mt('Display Test Contents');
                   1416:                 }
                   1417:                 $output .= '<tr><td align="left"><a href="javascript:gonav('."'/adm/navmaps'".');"><img alt="course contents" src="/res/adm/pages/nav.png" align="left" class="LC_icon" /></a></td><td class="LC_menubuttons_text" colspan="3"><a class="LC_menubuttons_link" href="javascript:gonav('."'/adm/navmaps'".');"><span class="LC_menubuttons_inline_text">'.$navtext.'</span></a></td></tr></table></div></td>';
                   1418:             }
1.309.2.11! raeburn  1419:         } else {
        !          1420:             $output.='</td></tr></table></div></td>';
1.309.2.1  raeburn  1421:         }
1.309.2.3  raeburn  1422:         $output.='</tr></table>';
1.309.2.2  raeburn  1423:     } else {
1.309.2.1  raeburn  1424:         # calling rawconfig with "1" will evaluate mydesk.tab, 
                   1425:         # even if there is no active remote control
                   1426:         &rawconfig(1);
1.309.2.2  raeburn  1427:         $output='<table><tr>';
1.309.2.1  raeburn  1428:         for (my $col=1; $col<=2; $col++) {
                   1429:             $output.='<td class="LC_mainmenu_col_fieldset">';
                   1430:             for (my $row=1; $row<=8; $row++) {
                   1431:                 foreach my $cat (keys(%category_members)) {
                   1432:                     if ($category_positions{$cat} ne "$col,$row") { next; }
                   1433:                     $output.='<div class="LC_Box LC_400Box">';
                   1434: 	            $output.='<h3 class="LC_hcell">'.&mt($category_names{$cat}).'</h3>';
                   1435:                     $output.='<table>';
                   1436:                     my %active=();
                   1437:                     foreach my $menu_item (split(/\:/,$category_members{$cat})) {
                   1438:                         if ($inlineremote[$menu_item]) {
                   1439:                             $active{$menu_item}=1;
                   1440:                         }
                   1441:                     }
                   1442:                     foreach my $item (sort(keys(%active))) {
                   1443:                         $output.=$inlineremote[$item];
                   1444:                     }
                   1445:                     $output.='</table>';
                   1446:                     $output.='</div>';
1.309.2.2  raeburn  1447:                 }
1.240     riegler  1448:             }
1.309.2.1  raeburn  1449:             $output.="</td>";
                   1450:         }
                   1451:         $output.="</tr></table>";
1.240     riegler  1452:     }
                   1453:     return $output;
                   1454: }
                   1455: 
1.2       www      1456: sub rawconfig {
1.274     www      1457: #
                   1458: # This evaluates mydesk.tab
                   1459: # Need to add more positions and more privileges to deal with all
                   1460: # menu items.
                   1461: #
1.34      www      1462:     my $textualoverride=shift;
                   1463:     my $output='';
1.269     droeschl 1464:     unless ($env{'environment.remote'} eq 'off') {
1.35      www      1465:        $output.=
                   1466:  "window.status='Opening Remote Control';var swmenu=".&openmenu().
                   1467: "\nwindow.status='Configuring Remote Control ';";
1.34      www      1468:     } else {
                   1469:        unless ($textualoverride) { return ''; }
                   1470:     }
1.152     albertel 1471:     my $uname=$env{'user.name'};
                   1472:     my $udom=$env{'user.domain'};
                   1473:     my $adv=$env{'user.adv'};
1.266     raeburn  1474:     my $show_course=&Apache::loncommon::show_course();
1.152     albertel 1475:     my $author=$env{'user.author'};
1.5       www      1476:     my $crs='';
1.295     raeburn  1477:     my $crstype='';
1.152     albertel 1478:     if ($env{'request.course.id'}) {
                   1479:        $crs='/'.$env{'request.course.id'};
                   1480:        if ($env{'request.course.sec'}) {
                   1481: 	   $crs.='_'.$env{'request.course.sec'};
1.7       www      1482:        }
1.8       www      1483:        $crs=~s/\_/\//g;
1.295     raeburn  1484:        $crstype = &Apache::loncommon::course_type();
1.5       www      1485:     }
1.152     albertel 1486:     my $pub=($env{'request.state'} eq 'published');
                   1487:     my $con=($env{'request.state'} eq 'construct');
                   1488:     my $rol=$env{'request.role'};
                   1489:     my $requested_domain = $env{'request.role.domain'};
1.184     raeburn  1490:     foreach my $line (@desklines) {
1.209     www      1491:         my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
1.3       www      1492:         $prt=~s/\$uname/$uname/g;
                   1493:         $prt=~s/\$udom/$udom/g;
1.295     raeburn  1494:         if ($prt =~ /\$crs/) {
                   1495:             next unless ($env{'request.course.id'});
                   1496:             next if ($crstype eq 'Community');
                   1497:             $prt=~s/\$crs/$crs/g;
                   1498:         } elsif ($prt =~ /\$cmty/) {
                   1499:             next unless ($env{'request.course.id'});
                   1500:             next if ($crstype ne 'Community');
                   1501:             $prt=~s/\$cmty/$crs/g;
                   1502:         }
1.25      matthew  1503:         $prt=~s/\$requested_domain/$requested_domain/g;
1.211     www      1504:         if ($category_names{$cat}!~/\w/) { $cat='oth'; }
1.3       www      1505:         if ($pro eq 'clear') {
1.4       www      1506: 	    $output.=&clear($row,$col);
1.3       www      1507:         } elsif ($pro eq 'any') {
1.2       www      1508:                $output.=&secondlevel(
1.209     www      1509: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1510: 	} elsif ($pro eq 'smp') {
                   1511:             unless ($adv) {
                   1512:                $output.=&secondlevel(
1.209     www      1513:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1514:             }
                   1515:         } elsif ($pro eq 'adv') {
                   1516:             if ($adv) {
                   1517:                $output.=&secondlevel(
1.209     www      1518: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1519:             }
1.231     albertel 1520: 	} elsif ($pro eq 'shc') {
                   1521:             if ($show_course) {
                   1522:                $output.=&secondlevel(
                   1523:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
                   1524:             }
                   1525:         } elsif ($pro eq 'nsc') {
                   1526:             if (!$show_course) {
                   1527:                $output.=&secondlevel(
                   1528: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
                   1529:             }
1.81      matthew  1530:         } elsif (($pro=~/^p(\w+)/) && ($prt)) {
1.295     raeburn  1531:             my $priv = $1;
                   1532:             if ($priv =~ /^mdc(Course|Community)/) {
                   1533:                 if ($crstype eq $1) {
                   1534:                     $priv = 'mdc';
                   1535:                 } else {
                   1536:                     next;
                   1537:                 }
                   1538:             }
                   1539: 	    if (&Apache::lonnet::allowed($priv,$prt)) {
1.209     www      1540:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.4       www      1541:             }
1.295     raeburn  1542:         } elsif ($pro eq 'course')  {
                   1543:             if (($env{'request.course.fn'}) && ($crstype ne 'Community')) {
1.209     www      1544:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.81      matthew  1545: 	    }
1.295     raeburn  1546:         } elsif ($pro eq 'community')  {
                   1547:             if (($env{'request.course.fn'}) && ($crstype eq 'Community')) {
                   1548:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
                   1549:             }
1.124     matthew  1550:         } elsif ($pro =~ /^courseenv_(.*)$/) {
                   1551:             my $key = $1;
1.307     raeburn  1552:             if ($crstype ne 'Community') {
                   1553:                 my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
                   1554:                 if ($key eq 'canuse_pdfforms') {
                   1555:                     if ($env{'request.course.id'} && $coursepref eq '') {
                   1556:                         my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
                   1557:                         $coursepref = $domdefs{'canuse_pdfforms'};
                   1558:                     }
                   1559:                 }
                   1560:                 if ($coursepref) { 
                   1561:                     $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
                   1562:                 }
1.295     raeburn  1563:             }
                   1564:         } elsif ($pro =~ /^communityenv_(.*)$/) {
                   1565:             my $key = $1;
1.307     raeburn  1566:             if ($crstype eq 'Community') {
                   1567:                 my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
                   1568:                 if ($key eq 'canuse_pdfforms') {
                   1569:                     if ($env{'request.course.id'} && $coursepref eq '') {
                   1570:                         my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
                   1571:                         $coursepref = $domdefs{'canuse_pdfforms'};
                   1572:                     }
                   1573:                 }
                   1574:                 if ($coursepref) { 
                   1575:                     $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
                   1576:                 }
1.124     matthew  1577:             }
1.81      matthew  1578:         } elsif ($pro =~ /^course_(.*)$/) {
                   1579:             # Check for permissions inside of a course
1.295     raeburn  1580:             if (($env{'request.course.id'}) && ($crstype ne 'Community') && 
1.152     albertel 1581:                 (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
                   1582:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
1.81      matthew  1583:                  )) {
1.209     www      1584:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.26      www      1585: 	    }
1.295     raeburn  1586:         } elsif ($pro =~ /^community_(.*)$/) {
                   1587:             # Check for permissions inside of a community
                   1588:             if (($env{'request.course.id'}) && ($crstype eq 'Community') &&   
                   1589:                 (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
                   1590:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
                   1591:                  )) {
                   1592:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
                   1593:             }
1.4       www      1594:         } elsif ($pro eq 'author') {
                   1595:             if ($author) {
1.152     albertel 1596:                 if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
1.234     raeburn  1597:                     (($prt eq 'raa') && ($env{'request.role'}=~/^aa/)) || 
1.152     albertel 1598:                     (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
1.19      matthew  1599:                     # Check that we are on the correct machine
1.29      matthew  1600:                     my $cadom=$requested_domain;
1.152     albertel 1601:                     my $caname=$env{'user.name'};
1.234     raeburn  1602:                     if (($prt eq 'rca') || ($prt eq 'raa')) {
1.29      matthew  1603: 		       ($cadom,$caname)=
1.206     albertel 1604:                                ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.29      matthew  1605:                     }                       
                   1606:                     $act =~ s/\$caname/$caname/g;
1.19      matthew  1607:                     my $home = &Apache::lonnet::homeserver($caname,$cadom);
1.109     albertel 1608: 		    my $allowed=0;
                   1609: 		    my @ids=&Apache::lonnet::current_machine_ids();
                   1610: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                   1611: 		    if ($allowed) {
1.209     www      1612:                         $output.=&switch($caname,$cadom,
                   1613:                                         $row,$col,$img,$top,$bot,$act,$desc,$cat);
1.19      matthew  1614:                     }
1.6       www      1615:                 }
1.2       www      1616:             }
1.248     raeburn  1617:         } elsif ($pro eq 'tools') {
                   1618:             my @tools = ('aboutme','blog','portfolio');
                   1619:             if (grep(/^\Q$prt\E$/,@tools)) {
1.249     raeburn  1620:                 if (!&Apache::lonnet::usertools_access($env{'user.name'},
1.251     raeburn  1621:                                                        $env{'user.domain'},
                   1622:                                                        $prt,undef,'tools')) {
                   1623:                     $output.=&clear($row,$col);
                   1624:                     next;
                   1625:                 }
1.278     raeburn  1626:             } elsif (($prt eq 'reqcrsnsc') || ($prt eq 'reqcrsshc')) {
                   1627:                 if (($prt eq 'reqcrsnsc') && ($show_course))   {
                   1628:                     next;
                   1629:                 }
                   1630:                 if (($prt eq 'reqcrsshc') && (!$show_course)) {
                   1631:                     next;
                   1632:                 }
1.279     raeburn  1633:                 my $showreqcrs = &check_for_rcrs();
1.251     raeburn  1634:                 if (!$showreqcrs) {
1.248     raeburn  1635:                     $output.=&clear($row,$col);
                   1636:                     next;
                   1637:                 }
                   1638:             }
                   1639:             $prt='any';
                   1640:             $output.=&secondlevel(
                   1641:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2       www      1642:         }
1.13      harris41 1643:     }
1.269     droeschl 1644:     unless ($env{'environment.remote'} eq 'off') {
1.35      www      1645:        $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
1.123     www      1646:        if (&Apache::lonmsg::newmail()) { 
                   1647: 	   $output.='swmenu.setstatus("you have","messages");';
                   1648:        }
1.34      www      1649:     }
1.123     www      1650: 
1.2       www      1651:     return $output;
                   1652: }
                   1653: 
1.279     raeburn  1654: sub check_for_rcrs {
                   1655:     my $showreqcrs = 0;
1.280     raeburn  1656:     my @reqtypes = ('official','unofficial','community');
                   1657:     foreach my $type (@reqtypes) {
1.279     raeburn  1658:         if (&Apache::lonnet::usertools_access($env{'user.name'},
                   1659:                                               $env{'user.domain'},
                   1660:                                               $type,undef,'requestcourses')) {
                   1661:             $showreqcrs = 1;
                   1662:             last;
                   1663:         }
                   1664:     }
1.280     raeburn  1665:     if (!$showreqcrs) {
                   1666:         foreach my $type (@reqtypes) {
                   1667:             if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
                   1668:                 $showreqcrs = 1;
                   1669:                 last;
                   1670:             }
                   1671:         }
                   1672:     }
1.279     raeburn  1673:     return $showreqcrs;
                   1674: }
                   1675: 
1.2       www      1676: # ======================================================================= Close
1.1       www      1677: 
                   1678: sub close {
1.269     droeschl 1679:     if ($env{'environment.remote'} eq 'off') { return ''; }
1.230     albertel 1680:     my $menuname = &get_menu_name();
1.1       www      1681:     return(<<ENDCLOSE);
1.129     albertel 1682: <script type="text/javascript">
1.277     bisitz   1683: // <![CDATA[
1.35      www      1684: window.status='Accessing Remote Control';
1.30      www      1685: menu=window.open("/adm/rat/empty.html","$menuname",
1.1       www      1686:                  "height=350,width=150,scrollbars=no,menubar=no");
1.35      www      1687: window.status='Disabling Remote Control';
                   1688: menu.active=0;
1.31      www      1689: menu.autologout=0;
1.35      www      1690: window.status='Closing Remote Control';
1.1       www      1691: menu.close();
1.35      www      1692: window.status='Done.';
1.277     bisitz   1693: // ]]>
1.1       www      1694: </script>
                   1695: ENDCLOSE
                   1696: }
                   1697: 
                   1698: # ====================================================================== Footer
                   1699: 
                   1700: sub footer {
                   1701: 
1.33      www      1702: }
                   1703: 
1.122     albertel 1704: sub nav_control_js {
1.152     albertel 1705:     my $nav=($env{'environment.remotenavmap'} eq 'on');
1.122     albertel 1706:     return (<<NAVCONTROL);
                   1707:     var w_loncapanav_flag="$nav";
                   1708: 
                   1709: 
                   1710: function gonav(url) {
                   1711:    if (w_loncapanav_flag != 1) {
                   1712:       gopost(url,'');
                   1713:    }  else {
                   1714:       navwindow=window.open(url,
                   1715:                   "loncapanav","height=600,width=400,scrollbars=1"); 
                   1716:    }
                   1717: }
                   1718: NAVCONTROL
                   1719: }
                   1720: 
1.306     raeburn  1721: sub dc_popup_js {
                   1722:     my %lt = &Apache::lonlocal::texthash(
                   1723:                                           more => '(More ...)',
                   1724:                                           less => '(Less ...)',
                   1725:                                         );
                   1726:     return <<"END";
                   1727: 
                   1728: function showCourseID() {
                   1729:     document.getElementById('dccid').style.display='block';
                   1730:     document.getElementById('dccid').style.textAlign='left';
1.307     raeburn  1731:     document.getElementById('dccid').style.textFace='normal';
1.306     raeburn  1732:     document.getElementById('dccidtext').innerHTML ='<a href="javascript:hideCourseID();">$lt{'less'}</a>';
                   1733:     return;
                   1734: }
                   1735: 
                   1736: function hideCourseID() {
                   1737:     document.getElementById('dccid').style.display='none';
                   1738:     document.getElementById('dccidtext').innerHTML ='<a href="javascript:showCourseID()">$lt{'more'}</a>';
                   1739:     return;
                   1740: }
                   1741: 
                   1742: END
                   1743: 
                   1744: }
                   1745: 
1.42      www      1746: sub utilityfunctions {
1.309.2.1  raeburn  1747:     my ($caller,$custommenu) = @_;
1.269     droeschl 1748:     unless ($env{'environment.remote'} eq 'off' || 
                   1749:             $caller eq '/adm/menu') { 
                   1750:             return ''; }
1.309.2.1  raeburn  1751:      
                   1752:     my $gcimenujs;
                   1753:     if ($custommenu) {
1.309.2.10  raeburn  1754:         my %concepttests = &Apache::loncommon::existing_gcitest_courses('cc');
1.309.2.1  raeburn  1755:         my $managetesturl = '/adm/menu';
                   1756:         my $createtesturl = '/adm/requestcourse';
                   1757:         if (($env{'request.course.id'}) &&
                   1758:             ($env{'course.'.$env{'request.course.id'}.'.domain'} eq 'gci')) {
                   1759:             my @items = keys(%concepttests);
                   1760:             if (@items== 1) {
                   1761:                 my $newrole = $items[0];
                   1762:                 $newrole =~ s{_}{/};
                   1763:                 $managetesturl = '/adm/roles?selectrole=1&cc./'.$newrole.'=1';
                   1764:             } else {
                   1765:                 $managetesturl = '/adm/roles?selectrole=1&cm=1&orgurl=%2fadm%2fmenu';
                   1766:             }
                   1767:         }
                   1768:         if ($env{'request.course.id'}) {
                   1769:             $createtesturl = '/adm/roles?selectrole=1&cm=1&orgurl=%2fadm%2frequestcourse';
                   1770:         }
                   1771:         $gcimenujs = <<"ENDCUSTOM";
                   1772: 
                   1773: function switchpage(caller) {
                   1774:     if (caller == 'review') {
                   1775:         document.location.href = '/adm/roles?selectrole=1&st./gci/9615072b469884921gcil1=1';
                   1776:     }
                   1777:     if (caller == 'submit') {
                   1778:         document.location.href = '/adm/roles?selectrole=1&st./gci/1H96711d710194bfegcil1=1';
                   1779:     }
                   1780:     if (caller == 'createtest') {
                   1781:         document.location.href = '$createtesturl';
                   1782:     }
                   1783:     if (caller == 'managetest') {
                   1784:         document.location.href = '$managetesturl';
                   1785:     }
                   1786:     return;
                   1787: }
                   1788: 
                   1789: ENDCUSTOM
                   1790:     }
                   1791:        
1.152     albertel 1792:     my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
1.293     raeburn  1793:     if ($currenturl =~ m{^/adm/wrapper/ext/}) {
                   1794:         if ($env{'request.external.querystring'}) {
                   1795:             $currenturl .= ($currenturl=~/\?/)?'&':'?'.$env{'request.external.querystring'};
                   1796:         }
                   1797:     }
1.183     www      1798:     $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
1.125     albertel 1799:     
1.152     albertel 1800:     my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
1.122     albertel 1801:     my $nav_control=&nav_control_js();
1.175     albertel 1802: 
1.306     raeburn  1803:     my $dc_popup_cid;
                   1804:     if ($env{'user.adv'} && exists($env{'user.role.dc./'.
                   1805:                         $env{'course.'.$env{'request.course.id'}.
                   1806:                                  '.domain'}.'/'})) {
                   1807:         $dc_popup_cid = &dc_popup_js();
                   1808:     }
                   1809: 
1.175     albertel 1810:     my $start_page_annotate = 
                   1811:         &Apache::loncommon::start_page('Annotator',undef,
                   1812: 				       {'only_body' => 1,
                   1813: 					'js_ready'  => 1,
                   1814: 					'bgcolor'   => '#BBBBBB',
                   1815: 					'add_entries' => {
                   1816: 					    'onload' => 'javascript:document.goannotate.submit();'}});
                   1817: 
1.205     albertel 1818:     my $end_page_annotate = 
                   1819:         &Apache::loncommon::end_page({'js_ready' => 1});
                   1820: 
1.175     albertel 1821:     my $start_page_bookmark = 
                   1822:         &Apache::loncommon::start_page('Bookmarks',undef,
                   1823: 				       {'only_body' => 1,
                   1824: 					'js_ready'  => 1,
                   1825: 					'bgcolor'   => '#BBBBBB',});
                   1826: 
1.205     albertel 1827:     my $end_page_bookmark = 
1.175     albertel 1828:         &Apache::loncommon::end_page({'js_ready' => 1});
                   1829: 
1.42      www      1830: return (<<ENDUTILITY)
                   1831: 
                   1832:     var currentURL="$currenturl";
                   1833:     var reloadURL="$currenturl";
                   1834:     var currentSymb="$currentsymb";
                   1835: 
1.114     albertel 1836: $nav_control
1.306     raeburn  1837: $dc_popup_cid
1.114     albertel 1838: 
1.309.2.1  raeburn  1839: $gcimenujs
                   1840: 
1.42      www      1841: function go(url) {
                   1842:    if (url!='' && url!= null) {
                   1843:        currentURL = null;
                   1844:        currentSymb= null;
                   1845:        window.location.href=url;
                   1846:    }
                   1847: }
                   1848: 
1.297     raeburn  1849: function gotop(url) {
                   1850:     if (url!='' && url!= null) {
                   1851:         top.location.href = url;
                   1852:     }
                   1853: }
                   1854: 
1.42      www      1855: function gopost(url,postdata) {
                   1856:    if (url!='') {
                   1857:       this.document.server.action=url;
                   1858:       this.document.server.postdata.value=postdata;
                   1859:       this.document.server.command.value='';
                   1860:       this.document.server.url.value='';
                   1861:       this.document.server.symb.value='';
                   1862:       this.document.server.submit();
                   1863:    }
                   1864: }
                   1865: 
                   1866: function gocmd(url,cmd) {
                   1867:    if (url!='') {
                   1868:       this.document.server.action=url;
                   1869:       this.document.server.postdata.value='';
                   1870:       this.document.server.command.value=cmd;
                   1871:       this.document.server.url.value=currentURL;
                   1872:       this.document.server.symb.value=currentSymb;
                   1873:       this.document.server.submit();
                   1874:    }
1.57      www      1875: }
                   1876: 
1.121     raeburn  1877: function gocstr(url,filename) {
                   1878:     if (url == '/adm/cfile?action=delete') {
                   1879:         this.document.cstrdelete.filename.value = filename
                   1880:         this.document.cstrdelete.submit();
                   1881:         return;
                   1882:     }
1.137     raeburn  1883:     if (url == '/adm/printout') {
                   1884:         this.document.cstrprint.postdata.value = filename
                   1885:         this.document.cstrprint.curseed.value = 0;
                   1886:         this.document.cstrprint.problemtype.value = 0;
1.138     raeburn  1887:         if (this.document.lonhomework) {
                   1888:             if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
                   1889:                 this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
                   1890:             }
                   1891:             if (this.document.lonhomework.problemtype) {
1.164     albertel 1892: 		if (this.document.lonhomework.problemtype.value) {
                   1893: 		    this.document.cstrprint.problemtype.value = 
                   1894: 			this.document.lonhomework.problemtype.value;
                   1895: 		} else if (this.document.lonhomework.problemtype.options) {
                   1896: 		    for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
                   1897: 			if (this.document.lonhomework.problemtype.options[i].selected) {
                   1898: 			    if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') { 
                   1899: 				this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
                   1900: 				}
                   1901: 			}
                   1902: 		    }
                   1903: 		}
                   1904: 	    }
                   1905: 	}
1.137     raeburn  1906:         this.document.cstrprint.submit();
                   1907:         return;
                   1908:     }
1.121     raeburn  1909:     if (url !='') {
                   1910:         this.document.constspace.filename.value = filename;
                   1911:         this.document.constspace.action = url;
                   1912:         this.document.constspace.submit();
                   1913:     }
                   1914: }
                   1915: 
1.131     raeburn  1916: function golist(url) {
                   1917:    if (url!='' && url!= null) {
                   1918:        currentURL = null;
                   1919:        currentSymb= null;
                   1920:        top.location.href=url;
                   1921:    }
                   1922: }
                   1923: 
                   1924: 
1.121     raeburn  1925: 
1.57      www      1926: function catalog_info() {
1.102     albertel 1927:    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      1928: }
                   1929: 
                   1930: function chat_win() {
1.290     raeburn  1931:    lonchat=window.open('/res/adm/pages/chatroom.html',"LONchat",'height=320,width=480,resizable=yes,location=no,menubar=no,toolbar=no');
1.42      www      1932: }
1.169     raeburn  1933: 
                   1934: function group_chat(group) {
                   1935:    var url = '/adm/groupchat?group='+group;
                   1936:    var winName = 'LONchat_'+group;
                   1937:    grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
                   1938: }
1.175     albertel 1939: 
                   1940: function edit_bookmarks() {
                   1941:    go('');
                   1942:    w_BookmarkPal_flag=1;
                   1943:    bookmarkpal=window.open("/adm/bookmarks",
                   1944:                "BookmarkPal", "width=400,height=505,scrollbars=0");
                   1945: }
                   1946: 
                   1947: function annotate() {
                   1948:    w_Annotator_flag=1;
                   1949:    annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
                   1950:    annotator.document.write(
                   1951:    '$start_page_annotate'
                   1952:   +"<form name='goannotate' target='Annotator' method='post' "
                   1953:   +"action='/adm/annotations'>"
1.217     albertel 1954:   +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />"
1.181     albertel 1955:   +"<\\/form>"
1.205     albertel 1956:   +'$end_page_annotate');
1.175     albertel 1957:    annotator.document.close();
                   1958: }
                   1959: 
                   1960: function set_bookmark() {
                   1961:    go('');
                   1962:    clienttitle=document.title;
                   1963:    clienthref=location.pathname;
                   1964:    w_bmquery_flag=1;
                   1965:    bmquery=window.open('','bmquery','width=365,height=165,scrollbars=0');
                   1966:    bmquery.document.write(
                   1967:    '$start_page_bookmark'
1.260     bisitz   1968:    +'<center><form method="post"'
                   1969:    +' name="newlink" action="/adm/bookmarks" target="bmquery" '
                   1970:    +'> <table width="340" height="150" '
                   1971:    +'bgcolor="#FFFFFF" align="center"><tr><td>Link Name:<br /><input '
                   1972:    +'type="text" name="title" size="45" value="'+clienttitle+'" />'
                   1973:    +'<br />Address:<br /><input type="text" name="address" size="45" '
                   1974:    +'value="'+clienthref+'" /><br /><center><input type="submit" '
                   1975:    +'value="Save" /> <input type="button" value="Close" '
                   1976:    +'onclick="javascript:window.close();" /></center></td>'
                   1977:    +'</tr></table></form></center>'
1.205     albertel 1978:    +'$end_page_bookmark' );
1.175     albertel 1979:    bmquery.document.close();
                   1980: }
                   1981: 
1.42      www      1982: ENDUTILITY
                   1983: }
                   1984: 
                   1985: sub serverform {
                   1986:     return(<<ENDSERVERFORM);
1.181     albertel 1987: <form name="server" action="/adm/logout" method="post" target="_top">
1.42      www      1988: <input type="hidden" name="postdata" value="none" />
                   1989: <input type="hidden" name="command" value="none" />
                   1990: <input type="hidden" name="url" value="none" />
                   1991: <input type="hidden" name="symb" value="none" />
                   1992: </form>
                   1993: ENDSERVERFORM
                   1994: }
1.113     albertel 1995: 
1.121     raeburn  1996: sub constspaceform {
                   1997:     return(<<ENDCONSTSPACEFORM);
1.181     albertel 1998: <form name="constspace" action="/adm/logout" method="post" target="_top">
1.121     raeburn  1999: <input type="hidden" name="filename" value="" />
                   2000: </form>
1.181     albertel 2001: <form name="cstrdelete" action="/adm/cfile" method="post" target="_top">
1.121     raeburn  2002: <input type="hidden" name="action" value="delete" /> 
                   2003: <input type="hidden" name="filename" value="" />
                   2004: </form>
1.181     albertel 2005: <form name="cstrprint" action="/adm/printout" target="_parent" method="post">
1.137     raeburn  2006: <input type="hidden" name="postdata" value="" />
                   2007: <input type="hidden" name="curseed" value="" />
                   2008: <input type="hidden" name="problemtype" value="" />
                   2009: </form>
                   2010: 
1.121     raeburn  2011: ENDCONSTSPACEFORM
                   2012: }
                   2013: 
                   2014: 
1.113     albertel 2015: sub get_nav_status {
                   2016:     my $navstatus="swmenu.w_loncapanav_flag=";
1.152     albertel 2017:     if ($env{'environment.remotenavmap'} eq 'on') {
1.113     albertel 2018: 	$navstatus.="1";
                   2019:     } else {
                   2020: 	$navstatus.="-1";
                   2021:     }
                   2022:     return $navstatus;
                   2023: }
                   2024: 
1.220     raeburn  2025: sub hidden_button_check {
                   2026:     my $hidden;
                   2027:     if ($env{'request.course.id'} eq '') {
                   2028:         return;
                   2029:     }
                   2030:     if ($env{'request.role.adv'}) {
1.309.2.6  raeburn  2031:         unless (&Apache::loncommon::needs_gci_custom()) {
                   2032:             return;
                   2033:         }
1.220     raeburn  2034:     }
1.232     raeburn  2035:     my $buttonshide = &Apache::lonnet::EXT('resource.0.buttonshide');
                   2036:     return $buttonshide; 
1.220     raeburn  2037: }
1.184     raeburn  2038: 
1.235     raeburn  2039: sub roles_selector {
                   2040:     my ($cdom,$cnum) = @_;
1.298     raeburn  2041:     my $crstype = &Apache::loncommon::course_type();
1.235     raeburn  2042:     my $now = time;
1.262     raeburn  2043:     my (%courseroles,%seccount);
1.235     raeburn  2044:     my $is_cc;
                   2045:     my $role_selector;
1.298     raeburn  2046:     my $ccrole;
                   2047:     if ($crstype eq 'Community') {
                   2048:         $ccrole = 'co';
                   2049:     } else {
                   2050:         $ccrole = 'cc';
                   2051:     } 
                   2052:     if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
                   2053:         my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
1.235     raeburn  2054:         
                   2055:         if ((($start) && ($start<0)) || 
                   2056:             (($end) && ($end<$now))  ||
                   2057:             (($start) && ($now<$start))) {
                   2058:             $is_cc = 0;
                   2059:         } else {
                   2060:             $is_cc = 1;
                   2061:         }
                   2062:     }
                   2063:     if ($is_cc) {
1.264     raeburn  2064:         &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount);
1.235     raeburn  2065:     } else {
1.262     raeburn  2066:         my %gotnosection;
1.235     raeburn  2067:         foreach my $item (keys(%env)) {
1.239     raeburn  2068:             if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
1.235     raeburn  2069:                 my $role = $1;
                   2070:                 my $sec = $2;
                   2071:                 next if ($role eq 'gr');
                   2072:                 my ($start,$end) = split(/\./,$env{$item});
                   2073:                 next if (($start && $start > $now) || ($end && $end < $now));
                   2074:                 if ($sec eq '') {
1.239     raeburn  2075:                     if (!$gotnosection{$role}) {
                   2076:                         $seccount{$role} ++;
                   2077:                         $gotnosection{$role} = 1;
                   2078:                     }
1.235     raeburn  2079:                 }
                   2080:                 if (ref($courseroles{$role}) eq 'ARRAY') {
1.239     raeburn  2081:                     if ($sec ne '') {
1.264     raeburn  2082:                         if (!grep(/^\Q$sec\E$/,@{$courseroles{$role}})) {
1.239     raeburn  2083:                             push(@{$courseroles{$role}},$sec);
                   2084:                             $seccount{$role} ++;
                   2085:                         }
                   2086:                     }
                   2087:                 } else {
                   2088:                     @{$courseroles{$role}} = ();
                   2089:                     if ($sec ne '') {
                   2090:                         $seccount{$role} ++;
1.235     raeburn  2091:                         push(@{$courseroles{$role}},$sec);
                   2092:                     }
                   2093:                 }
                   2094:             }
                   2095:         }
                   2096:     }
1.286     raeburn  2097:     my $switchtext;
                   2098:     if ($crstype eq 'Community') {
                   2099:         $switchtext = &mt('Switch community role to...')
                   2100:     } else {
                   2101:         $switchtext = &mt('Switch course role to...')
                   2102:     }
1.298     raeburn  2103:     my @roles_order = ($ccrole,'in','ta','ep','ad','st');
1.235     raeburn  2104:     if (keys(%courseroles) > 1) {
1.239     raeburn  2105:         $role_selector = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles);
1.235     raeburn  2106:         $role_selector .= '<form name="rolechooser" method="post" action="/adm/roles">
                   2107:                           <select name="switchrole" onchange="javascript:adhocRole('."'switchrole'".')">';
1.286     raeburn  2108:         $role_selector .= '<option value="">'.$switchtext.'</option>';
1.235     raeburn  2109:         foreach my $role (@roles_order) {
                   2110:             if (defined($courseroles{$role})) {
1.298     raeburn  2111:                 $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role,$crstype).'</option>'; 
1.235     raeburn  2112:             }
                   2113:         }
                   2114:         foreach my $role (sort(keys(%courseroles))) {
                   2115:             if ($role =~ /^cr/) {
                   2116:                 $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role).'</option>'; 
                   2117:             }
                   2118:         }
                   2119:         $role_selector .= '</select>'."\n".
                   2120:                '<input type="hidden" name="destinationurl" value="'.
1.282     amueller 2121:                &HTML::Entities::encode($ENV{'REQUEST_URI'}).'" />'."\n".
1.235     raeburn  2122:                '<input type="hidden" name="gotorole" value="1" />'."\n".
                   2123:                '<input type="hidden" name="selectrole" value="" />'."\n".
                   2124:                '<input type="hidden" name="switch" value="1" />'."\n".
                   2125:                '</form>';
                   2126:     }
                   2127:     return $role_selector;
                   2128: }
                   2129: 
1.262     raeburn  2130: sub get_all_courseroles {
                   2131:     my ($cdom,$cnum,$courseroles,$seccount) = @_;
                   2132:     unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH')) {
                   2133:         return;
                   2134:     }
                   2135:     my ($result,$cached) = 
                   2136:         &Apache::lonnet::is_cached_new('getcourseroles',$cdom.'_'.$cnum);
                   2137:     if (defined($cached)) {
                   2138:         if (ref($result) eq 'HASH') {
                   2139:             if ((ref($result->{'roles'}) eq 'HASH') && 
                   2140:                 (ref($result->{'seccount'}) eq 'HASH')) {
                   2141:                 %{$courseroles} = %{$result->{'roles'}};
                   2142:                 %{$seccount} = %{$result->{'seccount'}};
                   2143:                 return;
                   2144:             }
                   2145:         }
                   2146:     }
                   2147:     my %gotnosection;
                   2148:     my %adv_roles =
                   2149:          &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
                   2150:     foreach my $role (keys(%adv_roles)) {
                   2151:         my ($urole,$usec) = split(/:/,$role);
                   2152:         if (!$gotnosection{$urole}) {
                   2153:             $seccount->{$urole} ++;
                   2154:             $gotnosection{$urole} = 1;
                   2155:         }
                   2156:         if (ref($courseroles->{$urole}) eq 'ARRAY') {
                   2157:             if ($usec ne '') {
                   2158:                 if (!grep(/^Q$usec\E$/,@{$courseroles->{$urole}})) {
                   2159:                     push(@{$courseroles->{$urole}},$usec);
                   2160:                     $seccount->{$urole} ++;
                   2161:                 }
                   2162:             }
                   2163:         } else {
                   2164:             @{$courseroles->{$urole}} = ();
                   2165:             if ($usec ne '') {
                   2166:                 $seccount->{$urole} ++;
                   2167:                 push(@{$courseroles->{$urole}},$usec);
                   2168:             }
                   2169:         }
                   2170:     }
                   2171:     my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum,['st']);
                   2172:     @{$courseroles->{'st'}} = ();
                   2173:     if (keys(%sections_count) > 0) {
                   2174:         push(@{$courseroles->{'st'}},keys(%sections_count));
                   2175:         $seccount->{'st'} = scalar(keys(%sections_count)); 
                   2176:     }
                   2177:     my $rolehash = {
                   2178:                      'roles'    => $courseroles,
                   2179:                      'seccount' => $seccount,
                   2180:                    };
                   2181:     &Apache::lonnet::do_cache_new('getcourseroles',$cdom.'_'.$cnum,$rolehash);
                   2182:     return;
                   2183: }
                   2184: 
1.235     raeburn  2185: sub jump_to_role {
1.239     raeburn  2186:     my ($cdom,$cnum,$seccount,$courseroles) = @_;
                   2187:     my %lt = &Apache::lonlocal::texthash(
                   2188:                 this => 'This role has section(s) associated with it.',
                   2189:                 ente => 'Enter a specific section.',
                   2190:                 orlb => 'Enter a specific section, or leave blank for no section.',
                   2191:                 avai => 'Available sections are:',
                   2192:                 youe => 'You entered an invalid section choice:',
                   2193:                 plst => 'Please try again',
                   2194:     );
                   2195:     my $js;
                   2196:     if (ref($courseroles) eq 'HASH') {
                   2197:         $js = '    var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n". 
                   2198:               '    var numsec = new Array();'."\n".
                   2199:               '    var rolesections = new Array();'."\n".
                   2200:               '    var rolenames = new Array();'."\n".
                   2201:               '    var roleseclist = new Array();'."\n";
                   2202:         my @items = keys(%{$courseroles});
                   2203:         for (my $i=0; $i<@items; $i++) {
                   2204:             $js .= '    rolenames['.$i.'] = "'.$items[$i].'";'."\n";
                   2205:             my ($secs,$secstr);
                   2206:             if (ref($courseroles->{$items[$i]}) eq 'ARRAY') {
                   2207:                 my @sections = sort { $a <=> $b } @{$courseroles->{$items[$i]}};
                   2208:                 $secs = join('","',@sections);
                   2209:                 $secstr = join(', ',@sections);
                   2210:             }
                   2211:             $js .= '    rolesections['.$i.'] = new Array("'.$secs.'");'."\n".
                   2212:                    '    roleseclist['.$i.'] = "'.$secstr.'";'."\n".
                   2213:                    '    numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n";
                   2214:         }
                   2215:     }
1.273     droeschl 2216:     return <<"END";
1.235     raeburn  2217: <script type="text/javascript">
1.273     droeschl 2218: //<![CDATA[
1.235     raeburn  2219: function adhocRole(roleitem) {
1.239     raeburn  2220:     $js
1.235     raeburn  2221:     var newrole =  document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value;
                   2222:     if (newrole == '') {
                   2223:         return; 
                   2224:     } 
1.239     raeburn  2225:     var fullrole = newrole+'./$cdom/$cnum';
                   2226:     var selidx = '';
                   2227:     for (var i=0; i<rolenames.length; i++) {
                   2228:         if (rolenames[i] == newrole) {
                   2229:             selidx = i;
                   2230:         }
                   2231:     }
                   2232:     var secok = 1;
                   2233:     var secchoice = '';
                   2234:     if (selidx >= 0) {
                   2235:         if (numsec[selidx] > 1) {
                   2236:             secok = 0;
                   2237:             var numrolesec = rolesections[selidx].length;
                   2238:             var msgidx = numsec[selidx] - numrolesec;
                   2239:             secchoice = prompt("$lt{'this'}\\n"+secpick[msgidx]+"\\n$lt{'avai'} "+roleseclist[selidx],"");
                   2240:             if (secchoice == '') {
                   2241:                 if (msgidx > 0) {
                   2242:                     secok = 1;
                   2243:                 }
                   2244:             } else {
                   2245:                 for (var j=0; j<rolesections[selidx].length; j++) {
                   2246:                     if (rolesections[selidx][j] == secchoice) {
                   2247:                         secok = 1;
                   2248:                     }
                   2249:                 }
                   2250:             }
                   2251:         } else {
                   2252:             if (rolesections[selidx].length == 1) {
                   2253:                 secchoice = rolesections[selidx][0];
                   2254:             }
                   2255:         }
                   2256:     }
                   2257:     if (secok == 1) {
                   2258:         if (secchoice != '') {
                   2259:             fullrole += '/'+secchoice;
                   2260:         }
                   2261:     } else {
                   2262:         document.rolechooser.elements[roleitem].selectedIndex = 0;
                   2263:         if (secchoice != null) {
                   2264:             alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}");
                   2265:         }
                   2266:         return;
                   2267:     }
                   2268:     if (fullrole == "$env{'request.role'}") {
1.235     raeburn  2269:         return;
                   2270:     }
                   2271:     itemid = retrieveIndex('gotorole');
                   2272:     if (itemid != -1) {
1.239     raeburn  2273:         document.rolechooser.elements[itemid].name = fullrole;
1.235     raeburn  2274:     }
1.239     raeburn  2275:     document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value = fullrole;
1.235     raeburn  2276:     document.rolechooser.selectrole.value = '1';
                   2277:     document.rolechooser.submit();
                   2278:     return;
                   2279: }
                   2280: 
                   2281: function retrieveIndex(item) {
                   2282:     for (var i=0;i<document.rolechooser.elements.length;i++) {
                   2283:         if (document.rolechooser.elements[i].name == item) {
                   2284:             return i;
                   2285:         }
                   2286:     }
                   2287:     return -1;
                   2288: }
1.273     droeschl 2289: // ]]>
1.235     raeburn  2290: </script>
                   2291: END
                   2292: }
                   2293: 
                   2294: 
1.2       www      2295: # ================================================================ Main Program
                   2296: 
1.16      harris41 2297: BEGIN {
1.166     albertel 2298:     if (! defined($readdesk)) {
1.283     droeschl 2299:         {
                   2300:             my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
                   2301:             if ( CORE::open( my $config,"<$tabfile") ) {
                   2302:                 while (my $configline=<$config>) {
                   2303:                     $configline=(split(/\#/,$configline))[0];
                   2304:                     $configline=~s/^\s+//;
                   2305:                     chomp($configline);
1.209     www      2306:                     if ($configline=~/^cat\:/) {
1.283     droeschl 2307:                         my @entries=split(/\:/,$configline);
                   2308:                         $category_positions{$entries[2]}=$entries[1];
                   2309:                         $category_names{$entries[2]}=$entries[3];
                   2310:                     } elsif ($configline=~/^prim\:/) {
                   2311:                         my @entries = (split(/\:/, $configline))[1..5];
                   2312:                         push @primary_menu, \@entries;
                   2313:                     } elsif ($configline=~/^scnd\:/) {
                   2314:                         my @entries = (split(/\:/, $configline))[1..5];
                   2315:                         push @secondary_menu, \@entries; 
                   2316:                     } elsif ($configline) {
                   2317:                         push(@desklines,$configline);
                   2318:                     }
                   2319:                 }
                   2320:                 CORE::close($config);
                   2321:             }
                   2322:         }
                   2323:         $readdesk='done';
1.2       www      2324:     }
                   2325: }
1.30      www      2326: 
1.1       www      2327: 1;
                   2328: __END__
                   2329: 

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