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

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

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