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

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

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