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

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

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