File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.222.2.1: download - view: text, annotated - select for diffs
Thu Aug 30 22:37:27 2007 UTC (16 years, 8 months ago) by albertel
Branches: version_2_5_X
CVS tags: version_2_5_2, version_2_5_1
Diff to branchpoint 1.222: preferred, unified
- backport 1.225

    1: # The LearningOnline Network with CAPA
    2: # Routines to control the menu
    3: #
    4: # $Id: lonmenu.pm,v 1.222.2.1 2007/08/30 22:37:27 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' => 'Edit Course',
   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,'pcstr.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: 
  490:             unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme)(\?|$)/) {
  491: 		if (!$env{'request.enc'}) {
  492: 		    $menuitems.=(<<ENDREALRES);
  493: s&6&3&catalog.gif&catalog[_1]&info[_1]&catalog_info()&Show catalog information
  494: ENDREALRES
  495:                 }
  496: 	        $menuitems.=(<<ENDREALRES);
  497: s&8&1&eval.gif&evaluate[_1]&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
  498: 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
  499: ENDREALRES
  500: 	    }
  501:         }
  502: 	if ($env{'request.uri'} =~ /^\/res/) {
  503: 	    $menuitems .= (<<ENDMENUITEMS);
  504: s&8&3&prt.gif&prepare[_1]&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
  505: ENDMENUITEMS
  506: 	}
  507:         my $buttons='';
  508:         foreach (split(/\n/,$menuitems)) {
  509: 	    my ($command,@rest)=split(/\&/,$_);
  510:             my $idx=10*$rest[0]+$rest[1];
  511:             if (&hidden_button_check() eq 'yes') {
  512:                 if ($idx == 21 ||$idx == 23) {
  513:                     $buttons.=&switch('','',@rest);
  514:                 } else {
  515:                     $buttons.=&clear(@rest);
  516:                 }
  517:             } else {  
  518:                 if ($command eq 's') {
  519: 	            $buttons.=&switch('','',@rest);
  520:                 } else {
  521:                     $buttons.=&clear(@rest);
  522:                 }
  523:             }
  524:         }
  525: 
  526:         if ($textual) {
  527: 	    my $addremote=0;
  528: 	    foreach (@inlineremote) { if ($_ ne '') { $addremote=1; } }
  529: 	    my $inlinebuttons='';
  530: 	    if ($addremote) {
  531: # Registered, textual output
  532: 		if ($env{'browser.interface'} eq 'textual') {
  533: 		    $inlinebuttons=
  534:                         join('',map { (defined($_)?$_:'') } @inlineremote);
  535: 		} else {
  536:                     if ($env{'environment.icons'} eq 'iconsonly') {
  537:                         $inlinebuttons=(<<ENDARROWSINLINE);
  538: <tr><td>
  539: $inlineremote[21] $inlineremote[23]
  540: ENDARROWSINLINE
  541:                         if (&hidden_button_check() ne 'yes') {
  542:                             $inlinebuttons .= (<<ENDINLINEICONS);
  543: $inlineremote[61] $inlineremote[63]
  544: $inlineremote[71] $inlineremote[72] $inlineremote[73]
  545: $inlineremote[81] $inlineremote[82] $inlineremote[83]
  546: $inlineremote[91] $inlineremote[92] $inlineremote[93]</td></tr>
  547: ENDINLINEICONS
  548:                         }
  549:                     } else {
  550: 			$inlinebuttons=(<<ENDFIRSTLINE);
  551: <tr><td>$inlineremote[21]</td><td>&nbsp;</td><td>$inlineremote[23]</td></tr>
  552: ENDFIRSTLINE
  553:                         if (&hidden_button_check() ne 'yes') { 
  554:                             $inlinebuttons .= (<<ENDINLINE);
  555: <tr><td>$inlineremote[61]</td><td>$inlineremote[62]</td><td>$inlineremote[63]</td></tr>
  556: <tr><td>$inlineremote[71]</td><td>$inlineremote[72]</td><td>$inlineremote[73]</td></tr>
  557: <tr><td>$inlineremote[81]</td><td>$inlineremote[82]</td><td>$inlineremote[83]</td></tr>
  558: <tr><td>$inlineremote[91]</td><td>$inlineremote[92]</td><td>$inlineremote[93]</td></tr>
  559: ENDINLINE
  560:                         }
  561:                     }
  562:                 }
  563: 	    }
  564: 	    $result =(<<ENDREGTEXT);
  565: <script type="text/javascript">
  566: // BEGIN LON-CAPA Internal
  567: </script>
  568: $timesync
  569: $newmail
  570: $tablestart
  571: $inlinebuttons
  572: $tableend
  573: <script type="text/javascript">
  574: // END LON-CAPA Internal
  575: </script>
  576: 
  577: ENDREGTEXT
  578: # Registered, graphical output
  579:         } else {
  580: 	    my $requri=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
  581: 	    $requri=&Apache::lonenc::check_encrypt(&unescape($requri));
  582: 	    my $cursymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
  583: 	    my $navstatus=&get_nav_status();
  584: 	    my $clearcstr;
  585: 
  586: 	    if ($env{'user.adv'}) { $clearcstr='clearbut(6,1)'; }
  587: 	    $result = (<<ENDREGTHIS);
  588:      
  589: <script type="text/javascript">
  590: // BEGIN LON-CAPA Internal
  591: var swmenu=null;
  592: 
  593:     function LONCAPAreg() {
  594: 	  swmenu=$reopen;
  595:           swmenu.clearTimeout(swmenu.menucltim);
  596:           $timesync
  597:           $newmail
  598:           $buttons
  599: 	  swmenu.currentURL="$requri";
  600:           swmenu.reloadURL=swmenu.currentURL+window.location.search;
  601:           swmenu.currentSymb="$cursymb";
  602:           swmenu.reloadSymb="$cursymb";
  603:           swmenu.currentStale=0;
  604: 	  $navstatus
  605:           $hwkadd
  606:           $editbutton
  607:     }
  608: 
  609:     function LONCAPAstale() {
  610: 	  swmenu=$reopen
  611:           swmenu.currentStale=1;
  612:           if (swmenu.reloadURL!='' && swmenu.reloadURL!= null) { 
  613:              swmenu.switchbutton
  614:              (3,1,'reload.gif','return','location','go(reloadURL)','Return to the last known location in the course sequence');
  615: 	  }
  616:           swmenu.clearbut(7,2);
  617:           swmenu.clearbut(7,3);
  618:           swmenu.menucltim=swmenu.setTimeout(
  619:  'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+
  620:  'clearbut(9,1);clearbut(9,3);clearbut(6,3);$clearcstr',
  621: 			  2000);
  622:       }
  623: 
  624: // END LON-CAPA Internal 
  625: </script>
  626: ENDREGTHIS
  627:         }
  628: # =============================================================================
  629:     } else {
  630: # ========================================== This can or will not be registered
  631:         if ($textual) {
  632: # Not registered, textual
  633: 	    $result= (<<ENDDONOTREGTEXT);
  634: ENDDONOTREGTEXT
  635:         } else {
  636: # Not registered, graphical
  637:            $result = (<<ENDDONOTREGTHIS);
  638: 
  639: <script type="text/javascript">
  640: // BEGIN LON-CAPA Internal
  641: var swmenu=null;
  642: 
  643:     function LONCAPAreg() {
  644: 	  swmenu=$reopen
  645:           $timesync
  646:           swmenu.currentStale=1;
  647:           swmenu.clearbut(2,1);
  648:           swmenu.clearbut(2,3);
  649:           swmenu.clearbut(8,1);
  650:           swmenu.clearbut(8,2);
  651:           swmenu.clearbut(8,3);
  652:           if (swmenu.currentURL) {
  653:              swmenu.switchbutton
  654:               (3,1,'reload.gif','return','location','go(currentURL)');
  655:  	  } else {
  656: 	      swmenu.clearbut(3,1);
  657:           }
  658:     }
  659: 
  660:     function LONCAPAstale() {
  661:     }
  662: 
  663: // END LON-CAPA Internal
  664: </script>
  665: ENDDONOTREGTHIS
  666:        }
  667: # =============================================================================
  668:     }
  669:     return $result;
  670: }
  671: 
  672: sub loadevents() {
  673:     if ($env{'request.state'} eq 'construct' ||
  674: 	$env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
  675:     return 'LONCAPAreg();';
  676: }
  677: 
  678: sub unloadevents() {
  679:     if ($env{'request.state'} eq 'construct' ||
  680: 	$env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
  681:     return 'LONCAPAstale();';
  682: }
  683: 
  684: # ============================================================= Start up remote
  685: 
  686: sub startupremote {
  687:     my ($lowerurl)=@_;
  688:     if (($env{'browser.interface'} eq 'textual') ||
  689:         ($env{'environment.remote'} eq 'off')) {
  690:      return ('<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.$lowerurl.'" />');
  691:     }
  692: #
  693: # The Remote actually gets launched!
  694: #
  695:     my $configmenu=&rawconfig();
  696:     my $esclowerurl=&escape($lowerurl);
  697:     my $message=&mt('"Waiting for Remote Control window to load: "+[_1]','waited');
  698:     return(<<ENDREMOTESTARTUP);
  699: <script type="text/javascript">
  700: var timestart;
  701: function wheelswitch() {
  702:     if (typeof(document.wheel) != 'undefined') {
  703: 	if (typeof(document.wheel.spin) != 'undefined') {
  704: 	    var date=new Date();
  705: 	    var waited=Math.round(30-((date.getTime()-timestart)/1000));
  706: 	    document.wheel.spin.value=$message;
  707: 	}
  708:     }
  709:    if (window.status=='|') { 
  710:       window.status='/'; 
  711:    } else {
  712:       if (window.status=='/') {
  713:          window.status='-';
  714:       } else {
  715:          if (window.status=='-') { 
  716:             window.status='\\\\'; 
  717:          } else {
  718:             if (window.status=='\\\\') { window.status='|'; }
  719:          }
  720:       }
  721:    } 
  722: }
  723: 
  724: // ---------------------------------------------------------- The wait function
  725: var canceltim;
  726: function wait() {
  727:    if ((menuloaded==1) || (tim==1)) {
  728:       window.status='Done.';
  729:       if (tim==0) {
  730:          clearTimeout(canceltim);
  731:          $configmenu
  732:          window.location='$lowerurl';  
  733:       } else {
  734: 	  window.location='/adm/remote?action=collapse&url=$esclowerurl';
  735:       }
  736:    } else {
  737:       wheelswitch();
  738:       setTimeout('wait();',200);
  739:    }
  740: }
  741: 
  742: function main() {
  743:    canceltim=setTimeout('tim=1;',30000);
  744:    window.status='-';
  745:    var date=new Date();
  746:    timestart=date.getTime();
  747:    wait();
  748: }
  749: 
  750: </script>
  751: ENDREMOTESTARTUP
  752: }
  753: 
  754: sub setflags() {
  755:     return(<<ENDSETFLAGS);
  756: <script type="text/javascript">
  757:     menuloaded=0;
  758:     tim=0;
  759: </script>
  760: ENDSETFLAGS
  761: }
  762: 
  763: sub maincall() {
  764:     if (($env{'browser.interface'} eq 'textual') ||
  765:         ($env{'environment.remote'} eq 'off')) { return ''; }
  766:     return(<<ENDMAINCALL);
  767: <script type="text/javascript">
  768:     main();
  769: </script>
  770: ENDMAINCALL
  771: }
  772: 
  773: sub load_remote_msg {
  774:     my ($lowerurl)=@_;
  775: 
  776:     if (($env{'browser.interface'} eq 'textual') ||
  777:         ($env{'environment.remote'} eq 'off')) { return ''; }
  778: 
  779:     my $esclowerurl=&escape($lowerurl);
  780:     my $link=&mt('<a href="[_1]">Continue</a> on in Inline Menu mode',
  781: 		 "/adm/remote?action=collapse&amp;url=$esclowerurl");
  782:     return(<<ENDREMOTEFORM);
  783: <p>
  784: <form name="wheel">
  785: <input name="spin" type="text" size="60" />
  786: </form>
  787: </p>
  788: <p>$link</p>
  789: ENDREMOTEFORM
  790: }
  791: # ================================================================= Reopen menu
  792: 
  793: sub reopenmenu {
  794:    if (($env{'browser.interface'} eq 'textual') ||
  795:        ($env{'environment.remote'} eq 'off')) { return ''; }
  796:    my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
  797:    my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
  798:    return('window.open('.$nothing.',"'.$menuname.'","",false);');
  799: } 
  800: 
  801: # =============================================================== Open the menu
  802: 
  803: sub open {
  804:     my $returnval='';
  805:     if (($env{'browser.interface'} eq 'textual') ||
  806:         ($env{'environment.remote'} eq 'off')) { 
  807: 	return '<script type="text/javascript">self.name="loncapaclient";</script>';
  808:     }
  809:     my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
  810:     
  811: #    unless (shift eq 'unix') {
  812: # resizing does not work on linux because of virtual desktop sizes
  813: #       $returnval.=(<<ENDRESIZE);
  814: #if (window.screen) {
  815: #    self.resizeTo(screen.availWidth-215,screen.availHeight-55);
  816: #    self.moveTo(190,15);
  817: #}
  818: #ENDRESIZE
  819: #    }
  820:     $returnval.=(<<ENDOPEN);
  821: window.status='Opening LON-CAPA Remote Control';
  822: var menu=window.open("/res/adm/pages/menu.html","$menuname",
  823: "height=375,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5");
  824: self.name='loncapaclient';
  825: ENDOPEN
  826:     return '<script type="text/javascript">'.$returnval.'</script>';
  827: }
  828: 
  829: 
  830: # ================================================================== Raw Config
  831: 
  832: sub clear {
  833:     my ($row,$col)=@_;
  834:     unless (($env{'browser.interface'} eq 'textual') ||
  835:             ($env{'environment.remote'} eq 'off')) {
  836:        return "\n".qq(window.status+='.';swmenu.clearbut($row,$col););
  837:    } else { 
  838:        $inlineremote[10*$row+$col]='';
  839:        return ''; 
  840:    }
  841: }
  842: 
  843: # ============================================ Switch a button or create a link
  844: # Switch acts on the javascript that is executed when a button is clicked.  
  845: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
  846: 
  847: sub switch {
  848:     my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak)=@_;
  849:     $act=~s/\$uname/$uname/g;
  850:     $act=~s/\$udom/$udom/g;
  851:     $top=&mt($top);
  852:     $bot=&mt($bot);
  853:     $desc=&mt($desc);
  854:     $img=&mt($img);
  855: 
  856:     my $idx=10*$row+$col;
  857:     $category_members{$cat}.=':'.$idx;
  858: 
  859:     unless (($env{'browser.interface'} eq 'textual')  ||
  860:             ($env{'environment.remote'} eq 'off')) {
  861: # Remote
  862:        return "\n".
  863:  qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
  864:    } elsif ($env{'browser.interface'} eq 'textual') {
  865: # Accessibility
  866:        if ($nobreak==2) { return ''; }
  867:        my $text=$top.' '.$bot;
  868:        $text=~s/\s*\-\s*//gs;
  869:        if ($nobreak) {
  870: 	   $inlineremote[$idx]=
  871: 	       '<a href="javascript:'.$act.';">'.$text.'</a>';
  872:        } else {
  873: 	   $inlineremote[$idx]="\n<br />".
  874: 	       $desc.' <a href="javascript:'.$act.';">'.$text.'</a>';
  875:        }
  876:    } else {
  877: # Inline Remote
  878:        if ($env{'environment.icons'} ne 'classic') {
  879:           $img=~s/\.gif$/\.png/;
  880:        }
  881:        if ($nobreak==2) { return ''; }
  882:        my $text=$top.' '.$bot;
  883:        $text=~s/\s*\-\s*//gs;
  884: 
  885:        my $lonhttpdPort=$Apache::lonnet::perlvar{'lonhttpdPort'};
  886:        if (!defined($lonhttpdPort)) { $lonhttpdPort='8080'; }
  887:        my $pic=
  888: 	   '<img alt="'.$text.'" src="'.
  889: 	   &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
  890: 	   '" align="'.($nobreak==3?'right':'left').'" />';
  891:        if ($env{'browser.interface'} eq 'faketextual') {
  892: # Accessibility
  893: 	   if ($nobreak==3) {
  894: 	       $inlineremote[$idx]="\n".
  895: 		   '<td class="LC_menubuttons_text" align="right">'.$text.
  896: 		   '</td><td class="LC_menubuttons_img" align="left">'.
  897: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
  898: 	   } elsif ($nobreak) {
  899: 	       $inlineremote[$idx]="\n<tr>".
  900: 		   '<td class="LC_menubuttons_img" align="left">'.
  901: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td>
  902:                     <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>';
  903: 	   } else {
  904: 	       $inlineremote[$idx]="\n<tr>".
  905: 		   '<td class="LC_menubuttons_img" align="left">'.
  906: 		   '<a href="javascript:'.$act.';">'.$pic.
  907: 		   '</a></td><td class="LC_menubuttons_text" colspan="3">'.
  908: 		   '<a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$desc.'</span></a></td></tr>';
  909: 	   }
  910:        } else {
  911: # Inline Menu
  912:            if ($env{'environment.icons'} eq 'iconsonly') {
  913:               $inlineremote[$idx]='<a title="'.$desc.'" href="javascript:'.$act.';">'.$pic.'</a>';
  914:            } else {
  915: 	      $inlineremote[$idx]=
  916: 		   '<a class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.
  917: 		   '<span class="LC_menubuttons_inline_text">'.$desc.'</span></a>';
  918:            }
  919:        }
  920:    }
  921:     return '';
  922: }
  923: 
  924: sub secondlevel {
  925:     my $output='';
  926:     my 
  927:     ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_;
  928:     if ($prt eq 'any') {
  929: 	   $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
  930:     } elsif ($prt=~/^r(\w+)/) {
  931:         if ($rol eq $1) {
  932:            $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
  933:         }
  934:     }
  935:     return $output;
  936: }
  937: 
  938: sub openmenu {
  939:     my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
  940:     if (($env{'browser.interface'} eq 'textual') ||
  941:         ($env{'environment.remote'} eq 'off')) { return ''; }
  942:     my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
  943:     return "window.open(".$nothing.",'".$menuname."');";
  944: }
  945: 
  946: sub inlinemenu {
  947:     undef(@inlineremote);
  948:     undef(%category_members);
  949:     &rawconfig(1);
  950:     my $output='<table id="LC_mainmenu"><tr>';
  951:     for (my $col=1; $col<=2; $col++) {
  952:         $output.='<td class="LC_mainmenu_column">';
  953:         for (my $row=1; $row<=8; $row++) {
  954:             foreach my $cat (keys(%category_members)) {
  955:                if ($category_positions{$cat} ne "$col,$row") { next; }
  956:                $output.='<table id="LC_menubuttons_mainmenu"><tr><td colspan="4" class="LC_menubuttons_category">'.&mt($category_names{$cat}).'</td></tr>';
  957:                my %active=();
  958:                foreach my $menu_item (split(/\:/,$category_members{$cat})) {
  959:                   if ($inlineremote[$menu_item]) {
  960:                      $active{$menu_item}=1;
  961:                   }
  962:                }  
  963:                foreach my $item (sort(keys(%active))) {
  964:                   $output.=$inlineremote[$item];
  965:                }
  966:                $output.='</table>';
  967:             }
  968:          }
  969:          $output.="</td>";
  970:     }
  971:     $output.="</tr></table>";
  972:     return $output;
  973: }
  974: 
  975: sub rawconfig {
  976:     my $textualoverride=shift;
  977:     my $output='';
  978:     unless (($env{'browser.interface'} eq 'textual') ||
  979:             ($env{'environment.remote'} eq 'off')) {
  980:        $output.=
  981:  "window.status='Opening Remote Control';var swmenu=".&openmenu().
  982: "\nwindow.status='Configuring Remote Control ';";
  983:     } else {
  984:        unless ($textualoverride) { return ''; }
  985:     }
  986:     my $uname=$env{'user.name'};
  987:     my $udom=$env{'user.domain'};
  988:     my $adv=$env{'user.adv'};
  989:     my $author=$env{'user.author'};
  990:     my $crs='';
  991:     if ($env{'request.course.id'}) {
  992:        $crs='/'.$env{'request.course.id'};
  993:        if ($env{'request.course.sec'}) {
  994: 	   $crs.='_'.$env{'request.course.sec'};
  995:        }
  996:        $crs=~s/\_/\//g;
  997:     }
  998:     my $pub=($env{'request.state'} eq 'published');
  999:     my $con=($env{'request.state'} eq 'construct');
 1000:     my $rol=$env{'request.role'};
 1001:     my $requested_domain = $env{'request.role.domain'};
 1002:     foreach my $line (@desklines) {
 1003:         my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
 1004:         $prt=~s/\$uname/$uname/g;
 1005:         $prt=~s/\$udom/$udom/g;
 1006:         $prt=~s/\$crs/$crs/g; 
 1007:         $prt=~s/\$requested_domain/$requested_domain/g;
 1008:         if ($category_names{$cat}!~/\w/) { $cat='oth'; }
 1009:         my $type = &Apache::loncommon::course_type();
 1010:         if ($type eq 'Group') {
 1011:             $desc = &convert_menu_function($desc,$type);
 1012:         }
 1013:         if ($pro eq 'clear') {
 1014: 	    $output.=&clear($row,$col);
 1015:         } elsif ($pro eq 'any') {
 1016:                $output.=&secondlevel(
 1017: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1018: 	} elsif ($pro eq 'smp') {
 1019:             unless ($adv) {
 1020:                $output.=&secondlevel(
 1021:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1022:             }
 1023:         } elsif ($pro eq 'adv') {
 1024:             if ($adv) {
 1025:                $output.=&secondlevel(
 1026: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1027:             }
 1028:         } elsif (($pro=~/^p(\w+)/) && ($prt)) {
 1029: 	    if (&Apache::lonnet::allowed($1,$prt)) {
 1030:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1031:             }
 1032:         } elsif ($pro eq 'course') {
 1033:             if ($env{'request.course.fn'}) {
 1034:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1035: 	    }
 1036:         } elsif ($pro =~ /^courseenv_(.*)$/) {
 1037:             my $key = $1;
 1038:             if ($env{'course.'.$env{'request.course.id'}.'.'.$key}) {
 1039:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1040:             }
 1041:         } elsif ($pro =~ /^course_(.*)$/) {
 1042:             # Check for permissions inside of a course
 1043:             if (($env{'request.course.id'}) &&
 1044:                 (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
 1045:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
 1046:                  )) {
 1047:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1048: 	    }
 1049:         } elsif ($pro eq 'author') {
 1050:             if ($author) {
 1051:                 if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
 1052:                     (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
 1053:                     # Check that we are on the correct machine
 1054:                     my $cadom=$requested_domain;
 1055:                     my $caname=$env{'user.name'};
 1056:                     if ($prt eq 'rca') {
 1057: 		       ($cadom,$caname)=
 1058:                                ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
 1059:                     }                       
 1060:                     $act =~ s/\$caname/$caname/g;
 1061:                     my $home = &Apache::lonnet::homeserver($caname,$cadom);
 1062: 		    my $allowed=0;
 1063: 		    my @ids=&Apache::lonnet::current_machine_ids();
 1064: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
 1065: 		    if ($allowed) {
 1066:                         $output.=&switch($caname,$cadom,
 1067:                                         $row,$col,$img,$top,$bot,$act,$desc,$cat);
 1068:                     }
 1069:                 }
 1070:             }
 1071:         }
 1072:     }
 1073:     unless (($env{'browser.interface'} eq 'textual') ||
 1074:             ($env{'environment.remote'} eq 'off')) {
 1075:        $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
 1076:        if (&Apache::lonmsg::newmail()) { 
 1077: 	   $output.='swmenu.setstatus("you have","messages");';
 1078:        }
 1079:     }
 1080: 
 1081:     return $output;
 1082: }
 1083: 
 1084: # ======================================================================= Close
 1085: 
 1086: sub close {
 1087:     if (($env{'browser.interface'} eq 'textual') ||
 1088:         ($env{'environment.remote'} eq 'off')) { return ''; }
 1089:     my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
 1090:     return(<<ENDCLOSE);
 1091: <script type="text/javascript">
 1092: window.status='Accessing Remote Control';
 1093: menu=window.open("/adm/rat/empty.html","$menuname",
 1094:                  "height=350,width=150,scrollbars=no,menubar=no");
 1095: window.status='Disabling Remote Control';
 1096: menu.active=0;
 1097: menu.autologout=0;
 1098: window.status='Closing Remote Control';
 1099: menu.close();
 1100: window.status='Done.';
 1101: </script>
 1102: ENDCLOSE
 1103: }
 1104: 
 1105: # ====================================================================== Footer
 1106: 
 1107: sub footer {
 1108: 
 1109: }
 1110: 
 1111: sub nav_control_js {
 1112:     my $nav=($env{'environment.remotenavmap'} eq 'on');
 1113:     return (<<NAVCONTROL);
 1114:     var w_loncapanav_flag="$nav";
 1115: 
 1116: 
 1117: function gonav(url) {
 1118:    if (w_loncapanav_flag != 1) {
 1119:       gopost(url,'');
 1120:    }  else {
 1121:       navwindow=window.open(url,
 1122:                   "loncapanav","height=600,width=400,scrollbars=1"); 
 1123:    }
 1124: }
 1125: NAVCONTROL
 1126: }
 1127: 
 1128: sub utilityfunctions {
 1129:     my $caller = shift;
 1130:     unless (($env{'browser.interface'} eq 'textual')  ||
 1131:         ($env{'environment.remote'} eq 'off') || ($caller eq '/adm/menu')) { return ''; }
 1132:     my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
 1133:     $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
 1134:     
 1135:     my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
 1136:     my $nav_control=&nav_control_js();
 1137: 
 1138:     my $start_page_annotate = 
 1139:         &Apache::loncommon::start_page('Annotator',undef,
 1140: 				       {'only_body' => 1,
 1141: 					'js_ready'  => 1,
 1142: 					'bgcolor'   => '#BBBBBB',
 1143: 					'add_entries' => {
 1144: 					    'onload' => 'javascript:document.goannotate.submit();'}});
 1145: 
 1146:     my $end_page_annotate = 
 1147:         &Apache::loncommon::end_page({'js_ready' => 1});
 1148: 
 1149:     my $start_page_bookmark = 
 1150:         &Apache::loncommon::start_page('Bookmarks',undef,
 1151: 				       {'only_body' => 1,
 1152: 					'js_ready'  => 1,
 1153: 					'bgcolor'   => '#BBBBBB',});
 1154: 
 1155:     my $end_page_bookmark = 
 1156:         &Apache::loncommon::end_page({'js_ready' => 1});
 1157: 
 1158: return (<<ENDUTILITY)
 1159: 
 1160:     var currentURL="$currenturl";
 1161:     var reloadURL="$currenturl";
 1162:     var currentSymb="$currentsymb";
 1163: 
 1164: $nav_control
 1165: 
 1166: function go(url) {
 1167:    if (url!='' && url!= null) {
 1168:        currentURL = null;
 1169:        currentSymb= null;
 1170:        window.location.href=url;
 1171:    }
 1172: }
 1173: 
 1174: function gopost(url,postdata) {
 1175:    if (url!='') {
 1176:       this.document.server.action=url;
 1177:       this.document.server.postdata.value=postdata;
 1178:       this.document.server.command.value='';
 1179:       this.document.server.url.value='';
 1180:       this.document.server.symb.value='';
 1181:       this.document.server.submit();
 1182:    }
 1183: }
 1184: 
 1185: function gocmd(url,cmd) {
 1186:    if (url!='') {
 1187:       this.document.server.action=url;
 1188:       this.document.server.postdata.value='';
 1189:       this.document.server.command.value=cmd;
 1190:       this.document.server.url.value=currentURL;
 1191:       this.document.server.symb.value=currentSymb;
 1192:       this.document.server.submit();
 1193:    }
 1194: }
 1195: 
 1196: function gocstr(url,filename) {
 1197:     if (url == '/adm/cfile?action=delete') {
 1198:         this.document.cstrdelete.filename.value = filename
 1199:         this.document.cstrdelete.submit();
 1200:         return;
 1201:     }
 1202:     if (url == '/adm/printout') {
 1203:         this.document.cstrprint.postdata.value = filename
 1204:         this.document.cstrprint.curseed.value = 0;
 1205:         this.document.cstrprint.problemtype.value = 0;
 1206:         if (this.document.lonhomework) {
 1207:             if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
 1208:                 this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
 1209:             }
 1210:             if (this.document.lonhomework.problemtype) {
 1211: 		if (this.document.lonhomework.problemtype.value) {
 1212: 		    this.document.cstrprint.problemtype.value = 
 1213: 			this.document.lonhomework.problemtype.value;
 1214: 		} else if (this.document.lonhomework.problemtype.options) {
 1215: 		    for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
 1216: 			if (this.document.lonhomework.problemtype.options[i].selected) {
 1217: 			    if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') { 
 1218: 				this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
 1219: 				}
 1220: 			}
 1221: 		    }
 1222: 		}
 1223: 	    }
 1224: 	}
 1225:         this.document.cstrprint.submit();
 1226:         return;
 1227:     }
 1228:     if (url !='') {
 1229:         this.document.constspace.filename.value = filename;
 1230:         this.document.constspace.action = url;
 1231:         this.document.constspace.submit();
 1232:     }
 1233: }
 1234: 
 1235: function golist(url) {
 1236:    if (url!='' && url!= null) {
 1237:        currentURL = null;
 1238:        currentSymb= null;
 1239:        top.location.href=url;
 1240:    }
 1241: }
 1242: 
 1243: 
 1244: 
 1245: function catalog_info() {
 1246:    loncatinfo=window.open(window.location.pathname+'.meta',"LONcatInfo",'height=320,width=280,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
 1247: }
 1248: 
 1249: function chat_win() {
 1250:    lonchat=window.open('/res/adm/pages/chatroom.html',"LONchat",'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
 1251: }
 1252: 
 1253: function group_chat(group) {
 1254:    var url = '/adm/groupchat?group='+group;
 1255:    var winName = 'LONchat_'+group;
 1256:    grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
 1257: }
 1258: 
 1259: function edit_bookmarks() {
 1260:    go('');
 1261:    w_BookmarkPal_flag=1;
 1262:    bookmarkpal=window.open("/adm/bookmarks",
 1263:                "BookmarkPal", "width=400,height=505,scrollbars=0");
 1264: }
 1265: 
 1266: function annotate() {
 1267:    w_Annotator_flag=1;
 1268:    annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
 1269:    annotator.document.write(
 1270:    '$start_page_annotate'
 1271:   +"<form name='goannotate' target='Annotator' method='post' "
 1272:   +"action='/adm/annotations'>"
 1273:   +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />"
 1274:   +"<\\/form>"
 1275:   +'$end_page_annotate');
 1276:    annotator.document.close();
 1277: }
 1278: 
 1279: function set_bookmark() {
 1280:    go('');
 1281:    clienttitle=document.title;
 1282:    clienthref=location.pathname;
 1283:    w_bmquery_flag=1;
 1284:    bmquery=window.open('','bmquery','width=365,height=165,scrollbars=0');
 1285:    bmquery.document.write(
 1286:    '$start_page_bookmark'
 1287:    +"<center><form method='post'"
 1288:    +" name='newlink' action='/adm/bookmarks' target='bmquery' "
 1289:    +">\\n <table width=340 height=150 "
 1290:    +"bgcolor='ffffff' align=center><tr><td>Link Name:<br /><input "
 1291:    +"type='text' name='title' size=45 value='"+clienttitle+"' />"
 1292:    +"<br />Address:<br /><input type='text' name='address' size='45' "
 1293:    +"value='"+clienthref+"' /><br /><center><input type='submit' "
 1294:    +"value='Save' /> <input type='button' value='Close (no save)' "
 1295:    +"onclick='javascript:window.close();' /><\\/center><\\/td>"
 1296:    +"<\\/tr><\\/table><\\/form><\\/center>"
 1297:    +'$end_page_bookmark' );
 1298:    bmquery.document.close();
 1299: }
 1300: 
 1301: ENDUTILITY
 1302: }
 1303: 
 1304: sub serverform {
 1305:     return(<<ENDSERVERFORM);
 1306: <form name="server" action="/adm/logout" method="post" target="_top">
 1307: <input type="hidden" name="postdata" value="none" />
 1308: <input type="hidden" name="command" value="none" />
 1309: <input type="hidden" name="url" value="none" />
 1310: <input type="hidden" name="symb" value="none" />
 1311: </form>
 1312: ENDSERVERFORM
 1313: }
 1314: 
 1315: sub constspaceform {
 1316:     return(<<ENDCONSTSPACEFORM);
 1317: <form name="constspace" action="/adm/logout" method="post" target="_top">
 1318: <input type="hidden" name="filename" value="" />
 1319: </form>
 1320: <form name="cstrdelete" action="/adm/cfile" method="post" target="_top">
 1321: <input type="hidden" name="action" value="delete" /> 
 1322: <input type="hidden" name="filename" value="" />
 1323: </form>
 1324: <form name="cstrprint" action="/adm/printout" target="_parent" method="post">
 1325: <input type="hidden" name="postdata" value="" />
 1326: <input type="hidden" name="curseed" value="" />
 1327: <input type="hidden" name="problemtype" value="" />
 1328: </form>
 1329: 
 1330: ENDCONSTSPACEFORM
 1331: }
 1332: 
 1333: 
 1334: sub get_nav_status {
 1335:     my $navstatus="swmenu.w_loncapanav_flag=";
 1336:     if ($env{'environment.remotenavmap'} eq 'on') {
 1337: 	$navstatus.="1";
 1338:     } else {
 1339: 	$navstatus.="-1";
 1340:     }
 1341:     return $navstatus;
 1342: }
 1343: 
 1344: #FIXME this needs to move into mydesktab and the other locations 
 1345: # the text is generated
 1346: sub convert_menu_function {
 1347:     my ($rolename,$type) = @_;
 1348:     if ($type eq 'Group') {
 1349:         $rolename =~ s/student/member/g;
 1350:         $rolename =~ s/group/team/g;
 1351:         $rolename =~ s/course/group/g;
 1352:         $rolename =~ s/Course/Group/g;
 1353:     }
 1354:     return $rolename;
 1355: }
 1356: 
 1357: sub hidden_button_check {
 1358:     my $hidden;
 1359:     if ($env{'request.course.id'} eq '') {
 1360:         return;
 1361:     }
 1362:     if ($env{'request.role.adv'}) {
 1363:         return;
 1364:     }
 1365:     return &Apache::lonnet::EXT('resource.0.buttonshide'); 
 1366: }
 1367: 
 1368: # ================================================================ Main Program
 1369: 
 1370: BEGIN {
 1371:     if (! defined($readdesk)) {
 1372: 	{
 1373: 	    my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
 1374: 	    if ( CORE::open( my $config,"<$tabfile") ) {
 1375: 		while (my $configline=<$config>) {
 1376: 		    $configline=(split(/\#/,$configline))[0];
 1377: 		    $configline=~s/^\s+//;
 1378: 		    chomp($configline);
 1379:                     if ($configline=~/^cat\:/) {
 1380:                        my @entries=split(/\:/,$configline);
 1381:                        $category_positions{$entries[2]}=$entries[1];
 1382:                        $category_names{$entries[2]}=$entries[3];
 1383: 		    } elsif ($configline) {
 1384: 			push(@desklines,$configline);
 1385: 		    }
 1386: 		}
 1387: 		CORE::close($config);
 1388: 	    }
 1389: 	}
 1390: 	$readdesk='done';
 1391:     }
 1392: }
 1393: 
 1394: 1;
 1395: __END__
 1396: 
 1397: 
 1398: 
 1399: 
 1400: 
 1401: 
 1402: 

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