File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.210: download - view: text, annotated - select for diffs
Wed Apr 11 15:37:04 2007 UTC (17 years, 1 month ago) by albertel
Branches: MAIN
CVS tags: HEAD
- style

    1: # The LearningOnline Network with CAPA
    2: # Routines to control the menu
    3: #
    4: # $Id: lonmenu.pm,v 1.210 2007/04/11 15:37:04 albertel Exp $
    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: #
   28: #
   29: # There are two parameters controlling the action of this module:
   30: #
   31: # browser.interface - if this is 'textual', it overrides the second parameter
   32: # and goes to screen reader PDA mode
   33: #
   34: # environment.remote - if this is 'on', the routines controll the remote
   35: # control, otherwise they render the main window controls; ignored it
   36: # browser.interface is 'textual'
   37: #
   38: 
   39: package Apache::lonmenu;
   40: 
   41: use strict;
   42: use Apache::lonnet;
   43: use Apache::lonhtmlcommon();
   44: use Apache::loncommon();
   45: use Apache::lonenc();
   46: use Apache::lonlocal;
   47: use LONCAPA qw(:DEFAULT :match);
   48: 
   49: use vars qw(@desklines %category_names %category_members %category_positions $readdesk);
   50: 
   51: 
   52: my @inlineremote;
   53: 
   54: 
   55: 
   56: # ================================================================ Little texts
   57: 
   58: sub initlittle {
   59:     return &Apache::lonlocal::texthash('ret' => 'Return to Last Location',
   60: 				       'nav' => 'Navigate Contents',
   61: 				       'main' => 'Main Menu',
   62:                                        'roles' => ($env{'user.adv'}?
   63:                                                     'Roles':'Courses'),
   64:                                        'docs' => 'Course Documents',
   65:                                        'exit' => 'Exit',
   66:                                        'login' => 'Log In',
   67: 				       'launch' => 'Launch Remote Control',
   68:                                        'groups' => 'Groups',
   69:                                        'gdoc' => 'Group Documents',
   70:                                        );
   71: }
   72: 
   73: # ============================= This gets called at the top of the body section
   74: 
   75: sub menubuttons {
   76:     my $forcereg=shift;
   77:     my $registration=shift;
   78:     my $titletable=shift;
   79:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
   80: 					    ['inhibitmenu']);
   81:     if (($env{'form.inhibitmenu'} eq 'yes') ||
   82:         ($ENV{'REQUEST_URI'} eq '/adm/logout')) { return ''; }
   83: 
   84:     if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
   85: 
   86:     my %lt=&initlittle();
   87:     my $navmaps='';
   88:     my $reloadlink='';
   89:     my $docs='';
   90:     my $groups='';
   91:     my $showgroups=0;
   92:     my $escurl=&escape(&Apache::lonenc::check_encrypt($env{'request.noversionuri'}));
   93:     my $escsymb=&escape(&Apache::lonenc::check_encrypt($env{'request.symb'}));
   94: 
   95:     my $logo=&Apache::loncommon::lonhttpdurl("/adm/lonIcons/minilogo.gif");
   96:     $logo = '<td class="LC_top_nav_logo"><a href="/adm/about.html"><img src="'.
   97: 	$logo.'" alt="LON-CAPA Logo" /></a></td>';
   98: 
   99:     if ($env{'request.state'} eq 'construct') {
  100:         if (($env{'request.noversionuri'} eq '') || (!defined($env{'request.noversionuri'}))) {
  101:             my $returnurl = $env{'request.filename'};
  102:             $returnurl =~ s:^/home/([^/]+)/public_html/(.*)$:/priv/$1/$2:;
  103:             $escurl = &escape($returnurl);
  104:         }
  105:     }
  106:     if ($env{'request.course.id'}) {
  107:         my %coursegroups;
  108:         my $viewgrps_permission =
  109: 	    &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
  110:         if (!$viewgrps_permission) {
  111:             %coursegroups = &Apache::lonnet::get_active_groups($env{'user.domain'},$env{'user.name'},$env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'});
  112: 	}
  113:         if ((keys(%coursegroups) > 0) || ($viewgrps_permission)) {
  114:             $showgroups = 1;
  115:         }
  116:     }
  117: 
  118:     if ($env{'browser.interface'} eq 'textual') {
  119: # Textual display only
  120:         if ($env{'request.course.id'}) {
  121: 	    $navmaps=(<<ENDNAV);
  122: <a href="/adm/navmaps?postdata=$escurl&amp;postsymb=$escsymb" target="_top">$lt{'nav'}</a>
  123: ENDNAV
  124:             if (($env{'request.noversionuri'}=~/^\/adm\//) &&
  125:          ($env{'request.noversionuri'}!~/^\/adm\/wrapper\//) &&
  126:          ($env{'request.noversionuri'}!~/^\/adm\/.*\/(smppg|bulletinboard|aboutme)(\?|$)/)) {
  127:                 my $escreload=&escape('return:');
  128:                 $reloadlink=(<<ENDRELOAD);
  129: <a href="/adm/flip?postdata=$escreload" target="_top">$lt{'ret'}</a>
  130: ENDRELOAD
  131:             }
  132: 	    if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
  133:                $docs=(<<ENDDOCS);
  134: <a href="/adm/coursedocs" target="_top">$lt{'docs'}</a>
  135: ENDDOCS
  136:             }
  137:             if ($showgroups) {
  138:                 $groups =(<<ENDGROUPS);
  139: <a href="/adm/coursegroups" target="_top">$lt{'groups'}</a>
  140: ENDGROUPS
  141:             }
  142: 	}
  143:         my $form=&serverform();
  144:         my $utility=&utilityfunctions();
  145: 	my $output=(<<ENDMAINMENU);
  146: <script type="text/javascript">
  147: // BEGIN LON-CAPA Internal
  148: $utility
  149: </script>
  150: <div id="LC_top_nav">
  151: <a href="/adm/menu" target="_top">$lt{'main'}</a>
  152: $reloadlink $navmaps $docs $groups
  153: <a href="/adm/roles" target="_top">$lt{'roles'}</a>
  154: <a href="/adm/logout" target="_top">$lt{'exit'}</a>
  155: </div>
  156: <br />
  157: <script type="text/javascript">
  158: // END LON-CAPA Internal
  159: </script>
  160: $form
  161: ENDMAINMENU
  162:         if ($registration) { $output.=&innerregister($forcereg); }
  163: 	return $output."<hr />";
  164:     } elsif ($env{'environment.remote'} eq 'off') {
  165: # Remote Control is switched off
  166: # figure out colors
  167: 	my %lt=&initlittle();
  168: 
  169:         my $domain=&Apache::loncommon::determinedomain();
  170: 	my $function =&Apache::loncommon::get_users_function();
  171:         my $link=&Apache::loncommon::designparm($function.'.link',$domain);
  172:         my $alink=&Apache::loncommon::designparm($function.'.alink',$domain);
  173:         my $vlink=&Apache::loncommon::designparm($function.'.vlink',$domain);
  174:         my $sidebg=&Apache::loncommon::designparm($function.'.sidebg',$domain);
  175: 	if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
  176: 	    return (<<ENDINLINEMENU);
  177:    <table id="LC_top_nav">
  178:     <tr>
  179:       $logo
  180:       <td></td>
  181:       <td class="LC_top_nav_login">
  182:         <a href="/adm/roles" target="_top">$lt{'login'}</a>
  183:      </td>
  184:     </tr>
  185:   </table>
  186: </font>
  187: ENDINLINEMENU
  188:         }
  189: # Do we have a NAV link?
  190:         if ($env{'request.course.id'}) {
  191: 	    my $link='/adm/navmaps?postdata='.$escurl.'&amp;postsymb='.
  192: 		$escsymb;
  193: 	    if ($env{'environment.remotenavmap'} eq 'on') {
  194: 		$link="javascript:gonav('".$link."')";
  195: 	    }
  196: 	    $navmaps=(<<ENDNAV);
  197: <td><a href="$link" target="_top">$lt{'nav'}</a></td>
  198: ENDNAV
  199: my $is_group = (&Apache::loncommon::course_type() eq 'Group');
  200: 	    if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
  201:                 my $text = ($is_group) ? $lt{'gdoc'} : $lt{'docs'};
  202: 		$docs=(<<ENDDOCS);
  203: <td><a href="/adm/coursedocs" target="_top">$text</a></td>
  204: ENDDOCS
  205:             }
  206:             if ($showgroups) {
  207:                 $groups =(<<ENDGROUPS);
  208: <td><a href="/adm/coursegroups" target="_top">$lt{'groups'}</a></td>
  209: ENDGROUPS
  210:             }
  211: 	    if (
  212: 		($env{'request.noversionuri'}=~m[^/(res|public)/] &&
  213: 		 $env{'request.symb'} eq '')
  214: 		||
  215: 		(($env{'request.noversionuri'}=~/^\/adm\//) &&
  216: 		 ($env{'request.noversionuri'}!~/^\/adm\/wrapper\//) &&
  217: 		 ($env{'request.noversionuri'}!~
  218: 		        m[^/adm/.*/(smppg|bulletinboard|aboutme)($|\?)])
  219: 		  )
  220: 		 ) {
  221:                 my $escreload=&escape('return:');
  222:                 $reloadlink=(<<ENDRELOAD);
  223: <td><a href="/adm/flip?postdata=$escreload" target="_top">$lt{'ret'}</a></td>
  224: ENDRELOAD
  225:             }
  226:         }
  227: 	if (($env{'request.state'} eq 'construct') && ($env{'request.course.id'})) {
  228: 	    my $escreload=&escape('return:');
  229: 	    $reloadlink=(<<ENDCRELOAD);
  230: <td><a href="/adm/flip?postdata=$escreload" target="_top">$lt{'ret'}</a></td>
  231: ENDCRELOAD
  232:         }
  233:         my $reg='';
  234:         if ($registration) {
  235:            $reg=&innerregister($forcereg,$titletable);
  236:         }
  237:         my $form=&serverform();
  238: 	my $utility=&utilityfunctions();
  239: 	my $remote;
  240: 	if ($env{'user.adv'}) {
  241: 	    $remote = '<td><a href="/adm/remote?action=launch&amp;url='.$escurl.'" target="_top">'.$lt{'launch'}.'</a></td>'
  242: 	}
  243: 
  244:         my $helplink=&Apache::loncommon::top_nav_help('Help');
  245: 	return (<<ENDINLINEMENU);
  246: <script type="text/javascript">
  247: // BEGIN LON-CAPA Internal
  248: // <![CDATA[
  249: $utility
  250: // ]]>
  251: </script>
  252: <table id="LC_top_nav">
  253: <tr>
  254: $logo
  255: <td><a href="/adm/menu" target="_top">$lt{'main'}</a></td>
  256: $reloadlink
  257: $navmaps
  258: $docs
  259: $groups
  260: $remote
  261: <td><a href="/adm/roles" target="_top">$lt{'roles'}</a></td>
  262: <td class="LC_top_nav_help">$helplink</td>
  263: <td class="LC_top_nav_exit"><a href="/adm/logout" target="_top">$lt{'exit'}</a></td>
  264: </tr>
  265: </table>
  266: $form
  267: <script type="text/javascript">
  268: // END LON-CAPA Internal
  269: </script>
  270: $reg
  271: ENDINLINEMENU
  272:     } else {
  273: 	return '';
  274:     }
  275: }
  276: 
  277: # ====================================== This gets called in the header section
  278: 
  279: sub registerurl {
  280:     my ($forcereg) = @_;
  281:     my $result = '';
  282:     if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
  283:     my $force_title='';
  284:     if ($env{'request.state'} eq 'construct') {
  285: 	$force_title=&Apache::lonxml::display_title();
  286:     }
  287:     if (($env{'browser.interface'} eq 'textual') ||
  288:         ($env{'environment.remote'} eq 'off') ||
  289:         ((($env{'request.publicaccess'}) || 
  290:          (!&Apache::lonnet::is_on_map(
  291: 	   &unescape($env{'request.noversionuri'})))) &&
  292:         (!$forcereg))) {
  293:  	return $result.
  294:           '<script type="text/javascript">function LONCAPAreg(){;} function LONCAPAstale(){}</script>'.$force_title;
  295:     }
  296: # Graphical display after login only
  297:     if ($env{'request.registered'} && !$forcereg) { return ''; }
  298:     $result.=&innerregister($forcereg);
  299:     return $result.$force_title;
  300: }
  301: 
  302: # =========== This gets called in order to register a URL, both with the Remote
  303: # =========== and in the body of the document
  304: 
  305: sub innerregister {
  306:     my ($forcereg, $titletable) = @_;
  307:     my $result = '';
  308:     my ($uname,$thisdisfn);
  309:     my $const_space = ($env{'request.state'} eq 'construct');
  310:     my $is_const_dir = 0;
  311: 
  312:     if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
  313: 
  314:     $env{'request.registered'} = 1;
  315: 
  316:     my $textinter=($env{'browser.interface'} eq 'textual');
  317:     my $noremote=($env{'environment.remote'} eq 'off');
  318:     
  319:     my $textual=($textinter || $noremote);
  320: 
  321:     undef(@inlineremote);
  322: 
  323:     my $reopen=&Apache::lonmenu::reopenmenu();
  324: 
  325:     my $newmail='';
  326:     if ($noremote) {
  327: 	$newmail='<table id="LC_nav_location"><tr>';
  328:     }
  329:     if (&Apache::lonmsg::newmail()) { 
  330: 	if ($textual) {
  331: 	    $newmail.= '<td class="LC_new_mail">
  332:                    <a href="/adm/communicate" target="_top">'.
  333: 		   &mt('You have new messages').'</a></td>';
  334: 	} else {
  335: 	    $newmail= 'swmenu.setstatus("you have","messages");';
  336: 	}
  337:     } elsif (($textual) 
  338: 	     && ($env{'request.symb'}) 
  339: 	     && ($env{'request.course.id'})) {
  340: 	$newmail.= '<td class="LC_current_location">';
  341: 	my ($mapurl,$rid,$resurl)=
  342: 	    &Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
  343:         $newmail.=$env{'course.'.$env{'request.course.id'}.'.description'};
  344:         my $maptitle=&Apache::lonnet::gettitle($mapurl);
  345: 	my $restitle=&Apache::lonnet::gettitle(&Apache::lonnet::symbread());
  346:         if ($maptitle && $maptitle ne 'default.sequence') {
  347: 	    $newmail.=', '.$maptitle;
  348:         }
  349:         if ($restitle) {
  350: 	    $newmail.=': '.$restitle;
  351:         }
  352:         $newmail.='&nbsp;&nbsp;&nbsp;</td>';
  353:     }
  354:     if ($env{'request.state'} eq 'construct') {
  355:         $newmail = $titletable;
  356:     } else {
  357: 	if ($noremote) {
  358: 	    $newmail.='</tr></table>';
  359: 	}
  360:     }
  361:     my $timesync=($textual?'':'swmenu.syncclock(1000*'.time.');');
  362:     my $tablestart=($noremote?'<table id="LC_menubuttons">':'').
  363: 	($textinter?'<br /><a href="#content">'.&mt('Skip to Content').'</a><br />':'');
  364:     my $tableend=($noremote?'</table>':'').($textinter?'<a name="content" />':'');
  365: # =============================================================================
  366: # ============================ This is for URLs that actually can be registered
  367:     if (($env{'request.noversionuri'}!~m|^/(res/)*adm/|) || ($forcereg)) {
  368: # -- This applies to homework problems for users with grading privileges
  369: 	my $crs='/'.$env{'request.course.id'};
  370: 	if ($env{'request.course.sec'}) {
  371: 	    $crs.='_'.$env{'request.course.sec'};
  372: 	}
  373: 	$crs=~s/\_/\//g;
  374: 
  375:         my $hwkadd='';
  376:         if ($env{'request.symb'} ne '' &&
  377: 	    $env{'request.filename'}=~/\.(problem|exam|quiz|assess|survey|form|task)$/) {
  378: 	    if (&Apache::lonnet::allowed('mgr',$crs)) {
  379: 		$hwkadd.=&switch('','',7,2,'pgrd.gif','problem[_1]','grades[_3]',
  380:                        "gocmd('/adm/grades','gradingmenu')",
  381:                        'Modify user grades for this assessment resource');
  382:             } elsif (&Apache::lonnet::allowed('vgr',$crs)) {
  383: 		$hwkadd.=&switch('','',7,2,'subm.gif','view sub-[_1]','missions[_1]',
  384:                        "gocmd('/adm/grades','submission')",
  385: 		       'View user submissions for this assessment resource');
  386:             }
  387: 	}
  388: 	if ($env{'request.symb'} ne '' &&
  389: 	    &Apache::lonnet::allowed('opa',$crs)) {
  390: 	    $hwkadd.=&switch('','',7,3,'pparm.gif','problem[_2]','parms[_2]',
  391: 			     "gocmd('/adm/parmset','set')",
  392: 			     'Modify parameter settings for this resource');
  393: 	}
  394: # -- End Homework
  395:         ###
  396:         ### Determine whether or not to display the 'cstr' button for this
  397:         ### resource
  398:         ###
  399:         my $editbutton = '';
  400:         if ($env{'user.author'}) {
  401:             if ($env{'request.role'}=~/^(ca|au)/) {
  402:                 # Set defaults for authors
  403:                 my ($top,$bottom) = ('con-','struct');
  404:                 my $action = "go('/priv/".$env{'user.name'}."');";
  405:                 my $cadom  = $env{'request.role.domain'};
  406:                 my $caname = $env{'user.name'};
  407:                 my $desc = "Enter my resource construction space";
  408:                 # Set defaults for co-authors
  409:                 if ($env{'request.role'} =~ /^ca/) { 
  410:                     ($cadom,$caname)=($env{'request.role'}=~/($match_domain)\/($match_username)$/);
  411:                     ($top,$bottom) = ('co con-','struct');
  412:                     $action = "go('/priv/".$caname."');";
  413:                     $desc = "Enter construction space as co-author";
  414:                 }
  415:                 # Check that we are on the correct machine
  416:                 my $home = &Apache::lonnet::homeserver($caname,$cadom);
  417: 		my $allowed=0;
  418: 		my @ids=&Apache::lonnet::current_machine_ids();
  419: 		foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
  420: 		if (!$allowed) {
  421: 		    $editbutton=&switch('','',6,1,$top,,$bottom,$action,$desc);
  422:                 }
  423:             }
  424:             ##
  425:             ## Determine if user can edit url.
  426:             ##
  427:             my $cfile='';
  428:             my $cfuname='';
  429:             my $cfudom='';
  430:             if ($env{'request.filename'}) {
  431:                 my $file=&Apache::lonnet::declutter($env{'request.filename'});
  432:                 $file=~s/^($match_domain)\/($match_username)/\/priv\/$2/;
  433:                 # Check that the user has permission to edit this resource
  434:                 ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$1);
  435:                 if (defined($cfudom)) {
  436: 		    my $home=&Apache::lonnet::homeserver($cfuname,$cfudom);
  437: 		    my $allowed=0;
  438: 		    my @ids=&Apache::lonnet::current_machine_ids();
  439: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
  440: 		    if ($allowed) {
  441:                         $cfile=$file;
  442:                     }
  443:                 }
  444:             }        
  445:             # Finally, turn the button on or off
  446:             if ($cfile && !$const_space) {
  447:                 $editbutton=&switch
  448:                     ('','',6,1,'cstr.gif','edit[_1]','resource[_2]',
  449:                      "go('".$cfile."');","Edit this resource");
  450:             } elsif ($editbutton eq '') {
  451:                 $editbutton=&clear(6,1);
  452:             }
  453:         }
  454:         ###
  455:         ###
  456: # Prepare the rest of the buttons
  457:         my $menuitems;
  458:         if ($const_space) {
  459: 	    my ($uname,$thisdisfn) =
  460: 		($env{'request.filename'}=~m|^/home/([^/]+)/public_html/(.*)|);
  461:             my $currdir = '/priv/'.$uname.'/'.$thisdisfn;
  462:             if ($currdir =~ m-/$-) {
  463:                 $is_const_dir = 1;
  464:             } else {
  465:                 $currdir =~ s#[^/]+$##;
  466: 		my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn);
  467: 		my $esc_currdir = &Apache::loncommon::escape_single($currdir);
  468:                 $menuitems=(<<ENDMENUITEMS);
  469: s&6&1&list.gif&list[_1]&dir[_1]&golist('$esc_currdir')&List current directory
  470: s&6&2&rtrv.gif&retrieve[_1]&version[_1]&gocstr('/adm/retrieve','/~$uname/$cleandisfn')&Retrieve old version
  471: s&6&3&pub.gif&publish[_1]&resource[_1]&gocstr('/adm/publish','/~$uname/$cleandisfn')&Publish this resource
  472: s&7&1&del.gif&delete[_1]&resource[_2]&gocstr('/adm/cfile?action=delete','/~$uname/$cleandisfn')&Delete this resource
  473: s&7&2&prt.gif&prepare[_1]&printout[_1]&gocstr('/adm/printout','/~$uname/$cleandisfn')&Prepare a printable document
  474: ENDMENUITEMS
  475:             }
  476:         } elsif ( defined($env{'request.course.id'}) && 
  477: 		 $env{'request.symb'} ne '' ) {
  478: 	    $menuitems=(<<ENDMENUITEMS);
  479: c&3&1
  480: s&2&1&back.gif&backward[_1]&&gopost('/adm/flip','back:'+currentURL)&Go to the previous resource in the course sequence&&1
  481: s&2&3&forw.gif&forward[_1]&&gopost('/adm/flip','forward:'+currentURL)&Go to the next resource in the course sequence&&3
  482: c&6&3
  483: c&8&1
  484: c&8&2
  485: s&8&3&prt.gif&prepare[_1]&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
  486: s&9&1&sbkm.gif&set[_1]&bookmark[_2]&set_bookmark()&Set a bookmark for this resource&&1
  487: s&9&3&anot.gif&anno-[_1]&tations[_1]&annotate()&Make notes and annotations about this resource&&1
  488: ENDMENUITEMS
  489:             unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme)(\?|$)/) {
  490: 	        $menuitems.=(<<ENDREALRES);
  491: s&6&3&catalog.gif&catalog[_1]&info[_1]&catalog_info()&Show catalog information
  492: s&8&1&eval.gif&evaluate[_1]&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
  493: 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
  494: ENDREALRES
  495: 	    }
  496:         }
  497: 	if ($env{'request.uri'} =~ /^\/res/) {
  498: 	    $menuitems .= (<<ENDMENUITEMS);
  499: s&8&3&prt.gif&prepare[_1]&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
  500: ENDMENUITEMS
  501: 	}
  502:         my $buttons='';
  503:         foreach (split(/\n/,$menuitems)) {
  504: 	    my ($command,@rest)=split(/\&/,$_);
  505:             if ($command eq 's') {
  506: 		$buttons.=&switch('','',@rest);
  507:             } else {
  508:                 $buttons.=&clear(@rest);
  509:             }
  510:         }
  511: 
  512:         if ($textual) {
  513: 	    my $addremote=0;
  514: 	    foreach (@inlineremote) { if ($_ ne '') { $addremote=1; } }
  515: 	    my $inlinebuttons='';
  516: 	    if ($addremote) {
  517: # Registered, textual output
  518: 
  519: 		if ($env{'browser.interface'} eq 'textual') {
  520: 		    $inlinebuttons=
  521:                         join('',map { (defined($_)?$_:'') } @inlineremote);
  522: 		} else {
  523: 		    $inlinebuttons=(<<ENDINLINE);
  524: <tr><td>$inlineremote[21]</td><td>&nbsp;</td><td>$inlineremote[23]</td></tr>
  525: <tr><td>$inlineremote[61]</td><td>$inlineremote[62]</td><td>$inlineremote[63]</td></tr>
  526: <tr><td>$inlineremote[71]</td><td>$inlineremote[72]</td><td>$inlineremote[73]</td></tr>
  527: <tr><td>$inlineremote[81]</td><td>$inlineremote[82]</td><td>$inlineremote[83]</td></tr>
  528: <tr><td>$inlineremote[91]</td><td>$inlineremote[92]</td><td>$inlineremote[93]</td></tr>
  529: ENDINLINE
  530:                 }
  531: 	    }
  532: 	    $result =(<<ENDREGTEXT);
  533: <script type="text/javascript">
  534: // BEGIN LON-CAPA Internal
  535: </script>
  536: $timesync
  537: $newmail
  538: $tablestart
  539: $inlinebuttons
  540: $tableend
  541: <script type="text/javascript">
  542: // END LON-CAPA Internal
  543: </script>
  544: 
  545: ENDREGTEXT
  546: # Registered, graphical output
  547:         } else {
  548: 	    my $requri=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
  549: 	    $requri=&Apache::lonenc::check_encrypt(&unescape($requri));
  550: 	    my $cursymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
  551: 	    my $navstatus=&get_nav_status();
  552: 	    my $clearcstr;
  553: 
  554: 	    if ($env{'user.adv'}) { $clearcstr='clearbut(6,1)'; }
  555: 	    $result = (<<ENDREGTHIS);
  556:      
  557: <script type="text/javascript">
  558: // BEGIN LON-CAPA Internal
  559: var swmenu=null;
  560: 
  561:     function LONCAPAreg() {
  562: 	  swmenu=$reopen;
  563:           swmenu.clearTimeout(swmenu.menucltim);
  564:           $timesync
  565:           $newmail
  566:           $buttons
  567: 	  swmenu.currentURL="$requri";
  568:           swmenu.reloadURL=swmenu.currentURL+window.location.search;
  569:           swmenu.currentSymb="$cursymb";
  570:           swmenu.reloadSymb="$cursymb";
  571:           swmenu.currentStale=0;
  572: 	  $navstatus
  573:           $hwkadd
  574:           $editbutton
  575:     }
  576: 
  577:     function LONCAPAstale() {
  578: 	  swmenu=$reopen
  579:           swmenu.currentStale=1;
  580:           if (swmenu.reloadURL!='' && swmenu.reloadURL!= null) { 
  581:              swmenu.switchbutton
  582:              (3,1,'reload.gif','return','location','go(reloadURL)','Return to the last known location in the course sequence');
  583: 	  }
  584:           swmenu.clearbut(7,2);
  585:           swmenu.clearbut(7,3);
  586:           swmenu.menucltim=swmenu.setTimeout(
  587:  'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+
  588:  'clearbut(9,1);clearbut(9,3);clearbut(6,3);$clearcstr',
  589: 			  2000);
  590:       }
  591: 
  592: // END LON-CAPA Internal 
  593: </script>
  594: ENDREGTHIS
  595:         }
  596: # =============================================================================
  597:     } else {
  598: # ========================================== This can or will not be registered
  599:         if ($textual) {
  600: # Not registered, textual
  601: 	    $result= (<<ENDDONOTREGTEXT);
  602: ENDDONOTREGTEXT
  603:         } else {
  604: # Not registered, graphical
  605:            $result = (<<ENDDONOTREGTHIS);
  606: 
  607: <script type="text/javascript">
  608: // BEGIN LON-CAPA Internal
  609: var swmenu=null;
  610: 
  611:     function LONCAPAreg() {
  612: 	  swmenu=$reopen
  613:           $timesync
  614:           swmenu.currentStale=1;
  615:           swmenu.clearbut(2,1);
  616:           swmenu.clearbut(2,3);
  617:           swmenu.clearbut(8,1);
  618:           swmenu.clearbut(8,2);
  619:           swmenu.clearbut(8,3);
  620:           if (swmenu.currentURL) {
  621:              swmenu.switchbutton
  622:               (3,1,'reload.gif','return','location','go(currentURL)');
  623:  	  } else {
  624: 	      swmenu.clearbut(3,1);
  625:           }
  626:     }
  627: 
  628:     function LONCAPAstale() {
  629:     }
  630: 
  631: // END LON-CAPA Internal
  632: </script>
  633: ENDDONOTREGTHIS
  634:        }
  635: # =============================================================================
  636:     }
  637:     return $result;
  638: }
  639: 
  640: sub loadevents() {
  641:     if ($env{'request.state'} eq 'construct' ||
  642: 	$env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
  643:     return 'LONCAPAreg();';
  644: }
  645: 
  646: sub unloadevents() {
  647:     if ($env{'request.state'} eq 'construct' ||
  648: 	$env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
  649:     return 'LONCAPAstale();';
  650: }
  651: 
  652: # ============================================================= Start up remote
  653: 
  654: sub startupremote {
  655:     my ($lowerurl)=@_;
  656:     if (($env{'browser.interface'} eq 'textual') ||
  657:         ($env{'environment.remote'} eq 'off')) {
  658:      return ('<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.$lowerurl.'" />');
  659:     }
  660: #
  661: # The Remote actually gets launched!
  662: #
  663:     my $configmenu=&rawconfig();
  664:     my $esclowerurl=&escape($lowerurl);
  665:     my $message=&mt('"Waiting for Remote Control window to load: "+[_1]','waited');
  666:     return(<<ENDREMOTESTARTUP);
  667: <script type="text/javascript">
  668: var timestart;
  669: function wheelswitch() {
  670:     if (typeof(document.wheel) != 'undefined') {
  671: 	if (typeof(document.wheel.spin) != 'undefined') {
  672: 	    var date=new Date();
  673: 	    var waited=Math.round(30-((date.getTime()-timestart)/1000));
  674: 	    document.wheel.spin.value=$message;
  675: 	}
  676:     }
  677:    if (window.status=='|') { 
  678:       window.status='/'; 
  679:    } else {
  680:       if (window.status=='/') {
  681:          window.status='-';
  682:       } else {
  683:          if (window.status=='-') { 
  684:             window.status='\\\\'; 
  685:          } else {
  686:             if (window.status=='\\\\') { window.status='|'; }
  687:          }
  688:       }
  689:    } 
  690: }
  691: 
  692: // ---------------------------------------------------------- The wait function
  693: var canceltim;
  694: function wait() {
  695:    if ((menuloaded==1) || (tim==1)) {
  696:       window.status='Done.';
  697:       if (tim==0) {
  698:          clearTimeout(canceltim);
  699:          $configmenu
  700:          window.location='$lowerurl';  
  701:       } else {
  702: 	  window.location='/adm/remote?action=collapse&url=$esclowerurl';
  703:       }
  704:    } else {
  705:       wheelswitch();
  706:       setTimeout('wait();',200);
  707:    }
  708: }
  709: 
  710: function main() {
  711:    canceltim=setTimeout('tim=1;',30000);
  712:    window.status='-';
  713:    var date=new Date();
  714:    timestart=date.getTime();
  715:    wait();
  716: }
  717: 
  718: </script>
  719: ENDREMOTESTARTUP
  720: }
  721: 
  722: sub setflags() {
  723:     return(<<ENDSETFLAGS);
  724: <script type="text/javascript">
  725:     menuloaded=0;
  726:     tim=0;
  727: </script>
  728: ENDSETFLAGS
  729: }
  730: 
  731: sub maincall() {
  732:     if (($env{'browser.interface'} eq 'textual') ||
  733:         ($env{'environment.remote'} eq 'off')) { return ''; }
  734:     return(<<ENDMAINCALL);
  735: <script type="text/javascript">
  736:     main();
  737: </script>
  738: ENDMAINCALL
  739: }
  740: 
  741: sub load_remote_msg {
  742:     my ($lowerurl)=@_;
  743: 
  744:     if (($env{'browser.interface'} eq 'textual') ||
  745:         ($env{'environment.remote'} eq 'off')) { return ''; }
  746: 
  747:     my $esclowerurl=&escape($lowerurl);
  748:     my $link=&mt('<a href="[_1]">Continue</a> on in Inline Menu mode',
  749: 		 "/adm/remote?action=collapse&amp;url=$esclowerurl");
  750:     return(<<ENDREMOTEFORM);
  751: <p>
  752: <form name="wheel">
  753: <input name="spin" type="text" size="60" />
  754: </form>
  755: </p>
  756: <p>$link</p>
  757: ENDREMOTEFORM
  758: }
  759: # ================================================================= Reopen menu
  760: 
  761: sub reopenmenu {
  762:    if (($env{'browser.interface'} eq 'textual') ||
  763:        ($env{'environment.remote'} eq 'off')) { return ''; }
  764:    my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
  765:    my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
  766:    return('window.open('.$nothing.',"'.$menuname.'","",false);');
  767: } 
  768: 
  769: # =============================================================== Open the menu
  770: 
  771: sub open {
  772:     my $returnval='';
  773:     if (($env{'browser.interface'} eq 'textual') ||
  774:         ($env{'environment.remote'} eq 'off')) { 
  775: 	return '<script type="text/javascript">self.name="loncapaclient";</script>';
  776:     }
  777:     my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
  778:     unless (shift eq 'unix') {
  779: # resizing does not work on linux because of virtual desktop sizes
  780:        $returnval.=(<<ENDRESIZE);
  781: if (window.screen) {
  782:     self.resizeTo(screen.availWidth-215,screen.availHeight-55);
  783:     self.moveTo(190,15);
  784: }
  785: ENDRESIZE
  786:     }
  787:     $returnval.=(<<ENDOPEN);
  788: window.status='Opening LON-CAPA Remote Control';
  789: var menu=window.open("/res/adm/pages/menu.html","$menuname",
  790: "height=375,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5");
  791: self.name='loncapaclient';
  792: ENDOPEN
  793:     return '<script type="text/javascript">'.$returnval.'</script>';
  794: }
  795: 
  796: 
  797: # ================================================================== Raw Config
  798: 
  799: sub clear {
  800:     my ($row,$col)=@_;
  801:     unless (($env{'browser.interface'} eq 'textual') ||
  802:             ($env{'environment.remote'} eq 'off')) {
  803:        return "\n".qq(window.status+='.';swmenu.clearbut($row,$col););
  804:    } else { 
  805:        $inlineremote[10*$row+$col]='';
  806:        return ''; 
  807:    }
  808: }
  809: 
  810: # ============================================ Switch a button or create a link
  811: # Switch acts on the javascript that is executed when a button is clicked.  
  812: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
  813: 
  814: sub switch {
  815:     my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak)=@_;
  816:     $act=~s/\$uname/$uname/g;
  817:     $act=~s/\$udom/$udom/g;
  818:     $top=&mt($top);
  819:     $bot=&mt($bot);
  820:     $desc=&mt($desc);
  821:     $img=&mt($img);
  822: 
  823:     my $idx=10*$row+$col;
  824:     $category_members{$cat}.=':'.$idx;
  825: 
  826:     unless (($env{'browser.interface'} eq 'textual')  ||
  827:             ($env{'environment.remote'} eq 'off')) {
  828: # Remote
  829:        return "\n".
  830:  qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
  831:    } elsif ($env{'browser.interface'} eq 'textual') {
  832: # Accessibility
  833:        if ($nobreak==2) { return ''; }
  834:        my $text=$top.' '.$bot;
  835:        $text=~s/\s*\-\s*//gs;
  836:        if ($nobreak) {
  837: 	   $inlineremote[$idx]=
  838: 	       '<a href="javascript:'.$act.';">'.$text.'</a>';
  839:        } else {
  840: 	   $inlineremote[$idx]="\n<br />".
  841: 	       $desc.' <a href="javascript:'.$act.';">'.$text.'</a>';
  842:        }
  843:    } else {
  844: # Inline Remote
  845:        if ($nobreak==2) { return ''; }
  846:        my $text=$top.' '.$bot;
  847:        $text=~s/\s*\-\s*//gs;
  848: 
  849:        my $lonhttpdPort=$Apache::lonnet::perlvar{'lonhttpdPort'};
  850:        if (!defined($lonhttpdPort)) { $lonhttpdPort='8080'; }
  851:        my $pic=
  852: 	   '<img alt="'.$text.'" src="http://'.$ENV{'HTTP_HOST'}.
  853: 	   ':'.$lonhttpdPort.'/res/adm/pages/'.$img.'" align="'.
  854: 	   ($nobreak==3?'right':'left').'" />';
  855:        if ($env{'browser.interface'} eq 'faketextual') {
  856: # Accessibility
  857: 	   if ($nobreak==3) {
  858: 	       $inlineremote[$idx]="\n".
  859: 		   '<td class="LC_menubuttons_text" align="right">'.$text.
  860: 		   '</td><td class="LC_menubuttons_img" align="left">'.
  861: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
  862: 	   } elsif ($nobreak) {
  863: 	       $inlineremote[$idx]="\n<tr>".
  864: 		   '<td class="LC_menubuttons_img" align="left">'.
  865: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td>
  866:                     <td class="LC_menubuttons_text" align="left">'.$text.'</td>';
  867: 	   } else {
  868: 	       $inlineremote[$idx]="\n<tr>".
  869: 		   '<td class="LC_menubuttons_img" align="left">'.
  870: 		   '<a href="javascript:'.$act.';">'.$pic.
  871: 		   '</a></td><td class="LC_menubuttons_text" colspan="3">'.
  872: 		   $desc.'</td></tr>';
  873: 	   }
  874:        } else {
  875: # Inline Menu
  876: 	   $inlineremote[$idx]=
  877: 		   '<a href="javascript:'.$act.';">'.$pic.
  878: 		   '</a><span class="LC_menubuttons_inline_text">'.$desc.'</span>';
  879:        }
  880:    }
  881:     return '';
  882: }
  883: 
  884: sub secondlevel {
  885:     my $output='';
  886:     my 
  887:     ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_;
  888:     if ($prt eq 'any') {
  889: 	   $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
  890:     } elsif ($prt=~/^r(\w+)/) {
  891:         if ($rol eq $1) {
  892:            $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
  893:         }
  894:     }
  895:     return $output;
  896: }
  897: 
  898: sub openmenu {
  899:     my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
  900:     if (($env{'browser.interface'} eq 'textual') ||
  901:         ($env{'environment.remote'} eq 'off')) { return ''; }
  902:     my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
  903:     return "window.open(".$nothing.",'".$menuname."');";
  904: }
  905: 
  906: sub inlinemenu {
  907:     undef(@inlineremote);
  908:     undef(%category_members);
  909:     &rawconfig(1);
  910:     my $output='<table><tr>';
  911:     for (my $col=1; $col<=2; $col++) {
  912:         $output.='<td>';
  913:         for (my $row=1; $row<=8; $row++) {
  914:             foreach my $cat (keys(%category_members)) {
  915:                if ($category_positions{$cat} ne "$col,$row") { next; }
  916:                $output.='<table id="LC_menubuttons_mainmenu"><tr><td colspan="4" class="LC_menu_category">'.&mt($category_names{$cat}).'</td></tr>';
  917:                my %active=();
  918:                foreach my $menu_item (split(/\:/,$category_members{$cat})) {
  919:                   if ($inlineremote[$menu_item]) {
  920:                      $active{$menu_item}=1;
  921:                   }
  922:                }  
  923:                foreach my $item (sort(keys(%active))) {
  924:                   $output.=$inlineremote[$item];
  925:                }
  926:                $output.='</table>';
  927:             }
  928:          }
  929:          $output.="</td>";
  930:     }
  931:     $output.="</tr></table>";
  932:     return $output;
  933: }
  934: 
  935: sub rawconfig {
  936:     my $textualoverride=shift;
  937:     my $output='';
  938:     unless (($env{'browser.interface'} eq 'textual') ||
  939:             ($env{'environment.remote'} eq 'off')) {
  940:        $output.=
  941:  "window.status='Opening Remote Control';var swmenu=".&openmenu().
  942: "\nwindow.status='Configuring Remote Control ';";
  943:     } else {
  944:        unless ($textualoverride) { return ''; }
  945:     }
  946:     my $uname=$env{'user.name'};
  947:     my $udom=$env{'user.domain'};
  948:     my $adv=$env{'user.adv'};
  949:     my $author=$env{'user.author'};
  950:     my $crs='';
  951:     if ($env{'request.course.id'}) {
  952:        $crs='/'.$env{'request.course.id'};
  953:        if ($env{'request.course.sec'}) {
  954: 	   $crs.='_'.$env{'request.course.sec'};
  955:        }
  956:        $crs=~s/\_/\//g;
  957:     }
  958:     my $pub=($env{'request.state'} eq 'published');
  959:     my $con=($env{'request.state'} eq 'construct');
  960:     my $rol=$env{'request.role'};
  961:     my $requested_domain = $env{'request.role.domain'};
  962:     foreach my $line (@desklines) {
  963:         my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
  964:         $prt=~s/\$uname/$uname/g;
  965:         $prt=~s/\$udom/$udom/g;
  966:         $prt=~s/\$crs/$crs/g; 
  967:         $prt=~s/\$requested_domain/$requested_domain/g;
  968:         my $type = &Apache::loncommon::course_type();
  969:         if ($type eq 'Group') {
  970:             $desc = &convert_menu_function($desc,$type);
  971:         }
  972:         if ($pro eq 'clear') {
  973: 	    $output.=&clear($row,$col);
  974:         } elsif ($pro eq 'any') {
  975:                $output.=&secondlevel(
  976: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
  977: 	} elsif ($pro eq 'smp') {
  978:             unless ($adv) {
  979:                $output.=&secondlevel(
  980:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
  981:             }
  982:         } elsif ($pro eq 'adv') {
  983:             if ($adv) {
  984:                $output.=&secondlevel(
  985: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
  986:             }
  987:         } elsif (($pro=~/^p(\w+)/) && ($prt)) {
  988: 	    if (&Apache::lonnet::allowed($1,$prt)) {
  989:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
  990:             }
  991:         } elsif ($pro eq 'course') {
  992:             if ($env{'request.course.fn'}) {
  993:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
  994: 	    }
  995:         } elsif ($pro =~ /^courseenv_(.*)$/) {
  996:             my $key = $1;
  997:             if ($env{'course.'.$env{'request.course.id'}.'.'.$key}) {
  998:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
  999:             }
 1000:         } elsif ($pro =~ /^course_(.*)$/) {
 1001:             # Check for permissions inside of a course
 1002:             if (($env{'request.course.id'}) &&
 1003:                 (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
 1004:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
 1005:                  )) {
 1006:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1007: 	    }
 1008:         } elsif ($pro eq 'author') {
 1009:             if ($author) {
 1010:                 if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
 1011:                     (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
 1012:                     # Check that we are on the correct machine
 1013:                     my $cadom=$requested_domain;
 1014:                     my $caname=$env{'user.name'};
 1015:                     if ($prt eq 'rca') {
 1016: 		       ($cadom,$caname)=
 1017:                                ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
 1018:                     }                       
 1019:                     $act =~ s/\$caname/$caname/g;
 1020:                     my $home = &Apache::lonnet::homeserver($caname,$cadom);
 1021: 		    my $allowed=0;
 1022: 		    my @ids=&Apache::lonnet::current_machine_ids();
 1023: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
 1024: 		    if ($allowed) {
 1025:                         $output.=&switch($caname,$cadom,
 1026:                                         $row,$col,$img,$top,$bot,$act,$desc,$cat);
 1027:                     }
 1028:                 }
 1029:             }
 1030:         }
 1031:     }
 1032:     unless (($env{'browser.interface'} eq 'textual') ||
 1033:             ($env{'environment.remote'} eq 'off')) {
 1034:        $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
 1035:        if (&Apache::lonmsg::newmail()) { 
 1036: 	   $output.='swmenu.setstatus("you have","messages");';
 1037:        }
 1038:     }
 1039: 
 1040:     return $output;
 1041: }
 1042: 
 1043: # ======================================================================= Close
 1044: 
 1045: sub close {
 1046:     if (($env{'browser.interface'} eq 'textual') ||
 1047:         ($env{'environment.remote'} eq 'off')) { return ''; }
 1048:     my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
 1049:     return(<<ENDCLOSE);
 1050: <script type="text/javascript">
 1051: window.status='Accessing Remote Control';
 1052: menu=window.open("/adm/rat/empty.html","$menuname",
 1053:                  "height=350,width=150,scrollbars=no,menubar=no");
 1054: window.status='Disabling Remote Control';
 1055: menu.active=0;
 1056: menu.autologout=0;
 1057: window.status='Closing Remote Control';
 1058: menu.close();
 1059: window.status='Done.';
 1060: </script>
 1061: ENDCLOSE
 1062: }
 1063: 
 1064: # ====================================================================== Footer
 1065: 
 1066: sub footer {
 1067: 
 1068: }
 1069: 
 1070: sub nav_control_js {
 1071:     my $nav=($env{'environment.remotenavmap'} eq 'on');
 1072:     return (<<NAVCONTROL);
 1073:     var w_loncapanav_flag="$nav";
 1074: 
 1075: 
 1076: function gonav(url) {
 1077:    if (w_loncapanav_flag != 1) {
 1078:       gopost(url,'');
 1079:    }  else {
 1080:       navwindow=window.open(url,
 1081:                   "loncapanav","height=600,width=400,scrollbars=1"); 
 1082:    }
 1083: }
 1084: NAVCONTROL
 1085: }
 1086: 
 1087: sub utilityfunctions {
 1088:     my $caller = shift;
 1089:     unless (($env{'browser.interface'} eq 'textual')  ||
 1090:         ($env{'environment.remote'} eq 'off') || ($caller eq '/adm/menu')) { return ''; }
 1091:     my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
 1092:     $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
 1093:     
 1094:     my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
 1095:     my $nav_control=&nav_control_js();
 1096: 
 1097:     my $start_page_annotate = 
 1098:         &Apache::loncommon::start_page('Annotator',undef,
 1099: 				       {'only_body' => 1,
 1100: 					'js_ready'  => 1,
 1101: 					'bgcolor'   => '#BBBBBB',
 1102: 					'add_entries' => {
 1103: 					    'onload' => 'javascript:document.goannotate.submit();'}});
 1104: 
 1105:     my $end_page_annotate = 
 1106:         &Apache::loncommon::end_page({'js_ready' => 1});
 1107: 
 1108:     my $start_page_bookmark = 
 1109:         &Apache::loncommon::start_page('Bookmarks',undef,
 1110: 				       {'only_body' => 1,
 1111: 					'js_ready'  => 1,
 1112: 					'bgcolor'   => '#BBBBBB',});
 1113: 
 1114:     my $end_page_bookmark = 
 1115:         &Apache::loncommon::end_page({'js_ready' => 1});
 1116: 
 1117: return (<<ENDUTILITY)
 1118: 
 1119:     var currentURL="$currenturl";
 1120:     var reloadURL="$currenturl";
 1121:     var currentSymb="$currentsymb";
 1122: 
 1123: $nav_control
 1124: 
 1125: function go(url) {
 1126:    if (url!='' && url!= null) {
 1127:        currentURL = null;
 1128:        currentSymb= null;
 1129:        window.location.href=url;
 1130:    }
 1131: }
 1132: 
 1133: function gopost(url,postdata) {
 1134:    if (url!='') {
 1135:       this.document.server.action=url;
 1136:       this.document.server.postdata.value=postdata;
 1137:       this.document.server.command.value='';
 1138:       this.document.server.url.value='';
 1139:       this.document.server.symb.value='';
 1140:       this.document.server.submit();
 1141:    }
 1142: }
 1143: 
 1144: function gocmd(url,cmd) {
 1145:    if (url!='') {
 1146:       this.document.server.action=url;
 1147:       this.document.server.postdata.value='';
 1148:       this.document.server.command.value=cmd;
 1149:       this.document.server.url.value=currentURL;
 1150:       this.document.server.symb.value=currentSymb;
 1151:       this.document.server.submit();
 1152:    }
 1153: }
 1154: 
 1155: function gocstr(url,filename) {
 1156:     if (url == '/adm/cfile?action=delete') {
 1157:         this.document.cstrdelete.filename.value = filename
 1158:         this.document.cstrdelete.submit();
 1159:         return;
 1160:     }
 1161:     if (url == '/adm/printout') {
 1162:         this.document.cstrprint.postdata.value = filename
 1163:         this.document.cstrprint.curseed.value = 0;
 1164:         this.document.cstrprint.problemtype.value = 0;
 1165:         if (this.document.lonhomework) {
 1166:             if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
 1167:                 this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
 1168:             }
 1169:             if (this.document.lonhomework.problemtype) {
 1170: 		if (this.document.lonhomework.problemtype.value) {
 1171: 		    this.document.cstrprint.problemtype.value = 
 1172: 			this.document.lonhomework.problemtype.value;
 1173: 		} else if (this.document.lonhomework.problemtype.options) {
 1174: 		    for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
 1175: 			if (this.document.lonhomework.problemtype.options[i].selected) {
 1176: 			    if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') { 
 1177: 				this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
 1178: 				}
 1179: 			}
 1180: 		    }
 1181: 		}
 1182: 	    }
 1183: 	}
 1184:         this.document.cstrprint.submit();
 1185:         return;
 1186:     }
 1187:     if (url !='') {
 1188:         this.document.constspace.filename.value = filename;
 1189:         this.document.constspace.action = url;
 1190:         this.document.constspace.submit();
 1191:     }
 1192: }
 1193: 
 1194: function golist(url) {
 1195:    if (url!='' && url!= null) {
 1196:        currentURL = null;
 1197:        currentSymb= null;
 1198:        top.location.href=url;
 1199:    }
 1200: }
 1201: 
 1202: 
 1203: 
 1204: function catalog_info() {
 1205:    loncatinfo=window.open(window.location.pathname+'.meta',"LONcatInfo",'height=320,width=280,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
 1206: }
 1207: 
 1208: function chat_win() {
 1209:    lonchat=window.open('/res/adm/pages/chatroom.html',"LONchat",'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
 1210: }
 1211: 
 1212: function group_chat(group) {
 1213:    var url = '/adm/groupchat?group='+group;
 1214:    var winName = 'LONchat_'+group;
 1215:    grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
 1216: }
 1217: 
 1218: function edit_bookmarks() {
 1219:    go('');
 1220:    w_BookmarkPal_flag=1;
 1221:    bookmarkpal=window.open("/adm/bookmarks",
 1222:                "BookmarkPal", "width=400,height=505,scrollbars=0");
 1223: }
 1224: 
 1225: function annotate() {
 1226:    w_Annotator_flag=1;
 1227:    annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
 1228:    annotator.document.write(
 1229:    '$start_page_annotate'
 1230:   +"<form name='goannotate' target='Annotator' method='post' "
 1231:   +"action='/adm/annotations'>"
 1232:   +"<input type='hidden' name='urlnew' value='"+currentURL+"' />"
 1233:   +"<\\/form>"
 1234:   +'$end_page_annotate');
 1235:    annotator.document.close();
 1236: }
 1237: 
 1238: function set_bookmark() {
 1239:    go('');
 1240:    clienttitle=document.title;
 1241:    clienthref=location.pathname;
 1242:    w_bmquery_flag=1;
 1243:    bmquery=window.open('','bmquery','width=365,height=165,scrollbars=0');
 1244:    bmquery.document.write(
 1245:    '$start_page_bookmark'
 1246:    +"<center><form method='post'"
 1247:    +" name='newlink' action='/adm/bookmarks' target='bmquery' "
 1248:    +">\\n <table width=340 height=150 "
 1249:    +"bgcolor='ffffff' align=center><tr><td>Link Name:<br /><input "
 1250:    +"type='text' name='title' size=45 value='"+clienttitle+"' />"
 1251:    +"<br />Address:<br /><input type='text' name='address' size='45' "
 1252:    +"value='"+clienthref+"' /><br /><center><input type='submit' "
 1253:    +"value='Save' /> <input type='button' value='Close (no save)' "
 1254:    +"onclick='javascript:window.close();' /><\\/center><\\/td>"
 1255:    +"<\\/tr><\\/table><\\/form><\\/center>"
 1256:    +'$end_page_bookmark' );
 1257:    bmquery.document.close();
 1258: }
 1259: 
 1260: ENDUTILITY
 1261: }
 1262: 
 1263: sub serverform {
 1264:     return(<<ENDSERVERFORM);
 1265: <form name="server" action="/adm/logout" method="post" target="_top">
 1266: <input type="hidden" name="postdata" value="none" />
 1267: <input type="hidden" name="command" value="none" />
 1268: <input type="hidden" name="url" value="none" />
 1269: <input type="hidden" name="symb" value="none" />
 1270: </form>
 1271: ENDSERVERFORM
 1272: }
 1273: 
 1274: sub constspaceform {
 1275:     return(<<ENDCONSTSPACEFORM);
 1276: <form name="constspace" action="/adm/logout" method="post" target="_top">
 1277: <input type="hidden" name="filename" value="" />
 1278: </form>
 1279: <form name="cstrdelete" action="/adm/cfile" method="post" target="_top">
 1280: <input type="hidden" name="action" value="delete" /> 
 1281: <input type="hidden" name="filename" value="" />
 1282: </form>
 1283: <form name="cstrprint" action="/adm/printout" target="_parent" method="post">
 1284: <input type="hidden" name="postdata" value="" />
 1285: <input type="hidden" name="curseed" value="" />
 1286: <input type="hidden" name="problemtype" value="" />
 1287: </form>
 1288: 
 1289: ENDCONSTSPACEFORM
 1290: }
 1291: 
 1292: 
 1293: sub get_nav_status {
 1294:     my $navstatus="swmenu.w_loncapanav_flag=";
 1295:     if ($env{'environment.remotenavmap'} eq 'on') {
 1296: 	$navstatus.="1";
 1297:     } else {
 1298: 	$navstatus.="-1";
 1299:     }
 1300:     return $navstatus;
 1301: }
 1302: 
 1303: #FIXME this needs to move into mydesktab and the other locations 
 1304: # the text is generated
 1305: sub convert_menu_function {
 1306:     my ($rolename,$type) = @_;
 1307:     if ($type eq 'Group') {
 1308:         $rolename =~ s/student/member/g;
 1309:         $rolename =~ s/group/team/g;
 1310:         $rolename =~ s/course/group/g;
 1311:         $rolename =~ s/Course/Group/g;
 1312:     }
 1313:     return $rolename;
 1314: }
 1315: 
 1316: 
 1317: # ================================================================ Main Program
 1318: 
 1319: BEGIN {
 1320:     if (! defined($readdesk)) {
 1321: 	{
 1322: 	    my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
 1323: 	    if ( CORE::open( my $config,"<$tabfile") ) {
 1324: 		while (my $configline=<$config>) {
 1325: 		    $configline=(split(/\#/,$configline))[0];
 1326: 		    $configline=~s/^\s+//;
 1327: 		    chomp($configline);
 1328:                     if ($configline=~/^cat\:/) {
 1329:                        my @entries=split(/\:/,$configline);
 1330:                        $category_positions{$entries[2]}=$entries[1];
 1331:                        $category_names{$entries[2]}=$entries[3];
 1332: 		    } elsif ($configline) {
 1333: 			push(@desklines,$configline);
 1334: 		    }
 1335: 		}
 1336: 		CORE::close($config);
 1337: 	    }
 1338: 	}
 1339: 	$readdesk='done';
 1340:     }
 1341: }
 1342: 
 1343: 1;
 1344: __END__
 1345: 
 1346: 
 1347: 
 1348: 
 1349: 
 1350: 
 1351: 

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