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

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

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