File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.204: download - view: text, annotated - select for diffs
Mon Aug 14 09:28:56 2006 UTC (17 years, 9 months ago) by foxr
Branches: MAIN
CVS tags: HEAD
Remove some log spew.

    1: # The LearningOnline Network with CAPA
    2: # Routines to control the menu
    3: #
    4: # $Id: lonmenu.pm,v 1.204 2006/08/14 09:28:56 foxr 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 lib '/home/httpd/lib/perl/';
   48: use LONCAPA;
   49: 
   50: use vars qw(@desklines $readdesk);
   51: 
   52: 
   53: my @inlineremote;
   54: 
   55: 
   56: 
   57: # ================================================================ Little texts
   58: 
   59: sub initlittle {
   60:     return &Apache::lonlocal::texthash('ret' => 'Return to Last Location',
   61: 				       'nav' => 'Navigate Contents',
   62: 				       'main' => 'Main Menu',
   63:                                        'roles' => ($env{'user.adv'}?
   64:                                                     'Roles':'Courses'),
   65:                                        'docs' => 'Course Documents',
   66:                                        'exit' => 'Exit',
   67:                                        'login' => 'Log In',
   68: 				       'launch' => 'Launch Remote Control',
   69:                                        'groups' => 'Groups',
   70:                                        'gdoc' => 'Group Documents',
   71:                                        );
   72: }
   73: 
   74: # ============================= This gets called at the top of the body section
   75: 
   76: sub menubuttons {
   77:     my $forcereg=shift;
   78:     my $registration=shift;
   79:     my $titletable=shift;
   80:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
   81: 					    ['inhibitmenu']);
   82:     if (($env{'form.inhibitmenu'} eq 'yes') ||
   83:         ($ENV{'REQUEST_URI'} eq '/adm/logout')) { return ''; }
   84: 
   85:     if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
   86: 
   87:     my %lt=&initlittle();
   88:     my $navmaps='';
   89:     my $reloadlink='';
   90:     my $docs='';
   91:     my $groups='';
   92:     my $showgroups=0;
   93:     my $escurl=&escape(&Apache::lonenc::check_encrypt($env{'request.noversionuri'}));
   94:     my $escsymb=&escape(&Apache::lonenc::check_encrypt($env{'request.symb'}));
   95: 
   96:     my $logo=&Apache::loncommon::lonhttpdurl("/adm/lonIcons/minilogo.gif");
   97:     $logo = '<td class="LC_top_nav_logo"><a href="/adm/about.html"><img src="'.
   98: 	$logo.'" alt="LON-CAPA Logo" /></a></td>';
   99: 
  100:     if ($env{'request.state'} eq 'construct') {
  101:         if (($env{'request.noversionuri'} eq '') || (!defined($env{'request.noversionuri'}))) {
  102:             my $returnurl = $env{'request.filename'};
  103:             $returnurl =~ s:^/home/([^/]+)/public_html/(.*)$:/priv/$1/$2:;
  104:             $escurl = &escape($returnurl);
  105:         }
  106:     }
  107:     if ($env{'request.course.id'}) {
  108:         my %coursegroups;
  109:         my $viewgrps_permission =
  110: 	    &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
  111:         if (!$viewgrps_permission) {
  112:             %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'});
  113: 	}
  114:         if ((keys(%coursegroups) > 0) || ($viewgrps_permission)) {
  115:             $showgroups = 1;
  116:         }
  117:     }
  118: 
  119:     if ($env{'browser.interface'} eq 'textual') {
  120: # Textual display only
  121:         if ($env{'request.course.id'}) {
  122: 	    $navmaps=(<<ENDNAV);
  123: <a href="/adm/navmaps?postdata=$escurl&amp;postsymb=$escsymb" target="_top">$lt{'nav'}</a>
  124: ENDNAV
  125:             if (($env{'request.noversionuri'}=~/^\/adm\//) &&
  126:          ($env{'request.noversionuri'}!~/^\/adm\/wrapper\//) &&
  127:          ($env{'request.noversionuri'}!~/^\/adm\/.*\/(smppg|bulletinboard|aboutme)(\?|$)/)) {
  128:                 my $escreload=&escape('return:');
  129:                 $reloadlink=(<<ENDRELOAD);
  130: <a href="/adm/flip?postdata=$escreload" target="_top">$lt{'ret'}</a>
  131: ENDRELOAD
  132:             }
  133: 	    if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
  134:                $docs=(<<ENDDOCS);
  135: <a href="/adm/coursedocs" target="_top">$lt{'docs'}</a>
  136: ENDDOCS
  137:             }
  138:             if ($showgroups) {
  139:                 $groups =(<<ENDGROUPS);
  140: <a href="/adm/coursegroups" target="_top">$lt{'groups'}</a>
  141: ENDGROUPS
  142:             }
  143: 	}
  144:         my $form=&serverform();
  145:         my $utility=&utilityfunctions();
  146: 	my $output=(<<ENDMAINMENU);
  147: <script type="text/javascript">
  148: // BEGIN LON-CAPA Internal
  149: $utility
  150: </script>
  151: <div id="LC_top_nav">
  152: <a href="/adm/menu" target="_top">$lt{'main'}</a>
  153: $reloadlink $navmaps $docs $groups
  154: <a href="/adm/roles" target="_top">$lt{'roles'}</a>
  155: <a href="/adm/logout" target="_top">$lt{'exit'}</a>
  156: </div>
  157: <br />
  158: <script type="text/javascript">
  159: // END LON-CAPA Internal
  160: </script>
  161: $form
  162: ENDMAINMENU
  163:         if ($registration) { $output.=&innerregister($forcereg); }
  164: 	return $output."<hr />";
  165:     } elsif ($env{'environment.remote'} eq 'off') {
  166: # Remote Control is switched off
  167: # figure out colors
  168: 	my %lt=&initlittle();
  169: 
  170:         my $domain=&Apache::loncommon::determinedomain();
  171: 	my $function =&Apache::loncommon::get_users_function();
  172:         my $link=&Apache::loncommon::designparm($function.'.link',$domain);
  173:         my $alink=&Apache::loncommon::designparm($function.'.alink',$domain);
  174:         my $vlink=&Apache::loncommon::designparm($function.'.vlink',$domain);
  175:         my $sidebg=&Apache::loncommon::designparm($function.'.sidebg',$domain);
  176: 	if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
  177: 	    return (<<ENDINLINEMENU);
  178:    <table id="LC_top_nav">
  179:     <tr>
  180:       $logo
  181:       <td></td>
  182:       <td class="LC_top_nav_login">
  183:         <a href="/adm/roles" target="_top">$lt{'login'}</a>
  184:      </td>
  185:     </tr>
  186:   </table>
  187: </font>
  188: ENDINLINEMENU
  189:         }
  190: # Do we have a NAV link?
  191:         if ($env{'request.course.id'}) {
  192: 	    my $link='/adm/navmaps?postdata='.$escurl.'&amp;postsymb='.
  193: 		$escsymb;
  194: 	    if ($env{'environment.remotenavmap'} eq 'on') {
  195: 		$link="javascript:gonav('".$link."')";
  196: 	    }
  197: 	    $navmaps=(<<ENDNAV);
  198: <td><a href="$link" target="_top">$lt{'nav'}</a></td>
  199: ENDNAV
  200: my $is_group = (&Apache::loncommon::course_type() eq 'Group');
  201: 	    if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
  202:                 my $text = ($is_group) ? $lt{'gdoc'} : $lt{'docs'};
  203: 		$docs=(<<ENDDOCS);
  204: <td><a href="/adm/coursedocs" target="_top">$text</a></td>
  205: ENDDOCS
  206:             }
  207:             if ($showgroups) {
  208:                 $groups =(<<ENDGROUPS);
  209: <td><a href="/adm/coursegroups" target="_top">$lt{'groups'}</a></td>
  210: ENDGROUPS
  211:             }
  212: 	    if (
  213: 		($env{'request.noversionuri'}=~m[^/(res|public)/] &&
  214: 		 $env{'request.symb'} eq '')
  215: 		||
  216: 		(($env{'request.noversionuri'}=~/^\/adm\//) &&
  217: 		 ($env{'request.noversionuri'}!~/^\/adm\/wrapper\//) &&
  218: 		 ($env{'request.noversionuri'}!~
  219: 		        m[^/adm/.*/(smppg|bulletinboard|aboutme)($|\?)])
  220: 		  )
  221: 		 ) {
  222:                 my $escreload=&escape('return:');
  223:                 $reloadlink=(<<ENDRELOAD);
  224: <td><a href="/adm/flip?postdata=$escreload" target="_top">$lt{'ret'}</a></td>
  225: ENDRELOAD
  226:             }
  227:         }
  228: 	if (($env{'request.state'} eq 'construct') && ($env{'request.course.id'})) {
  229: 	    my $escreload=&escape('return:');
  230: 	    $reloadlink=(<<ENDCRELOAD);
  231: <td><a href="/adm/flip?postdata=$escreload" target="_top">$lt{'ret'}</a></td>
  232: ENDCRELOAD
  233:         }
  234:         my $reg='';
  235:         if ($registration) {
  236:            $reg=&innerregister($forcereg,$titletable);
  237:         }
  238:         my $form=&serverform();
  239: 	my $utility=&utilityfunctions();
  240: 	my $remote;
  241: 	if ($env{'user.adv'}) {
  242: 	    $remote = '<td><a href="/adm/remote?action=launch&amp;url='.$escurl.'" target="_top">'.$lt{'launch'}.'</a></td>'
  243: 	}
  244: 
  245:         my $helplink=&Apache::loncommon::top_nav_help('Help');
  246: 	return (<<ENDINLINEMENU);
  247: <script type="text/javascript">
  248: // BEGIN LON-CAPA Internal
  249: // <![CDATA[
  250: $utility
  251: // ]]>
  252: </script>
  253: <table id="LC_top_nav">
  254: <tr>
  255: $logo
  256: <td><a href="/adm/menu" target="_top">$lt{'main'}</a></td>
  257: $reloadlink
  258: $navmaps
  259: $docs
  260: $groups
  261: $remote
  262: <td><a href="/adm/roles" target="_top">$lt{'roles'}</a></td>
  263: <td class="LC_top_nav_help">$helplink</td>
  264: <td class="LC_top_nav_exit"><a href="/adm/logout" target="_top">$lt{'exit'}</a></td>
  265: </tr>
  266: </table>
  267: $form
  268: <script type="text/javascript">
  269: // END LON-CAPA Internal
  270: </script>
  271: $reg
  272: ENDINLINEMENU
  273:     } else {
  274: 	return '';
  275:     }
  276: }
  277: 
  278: # ====================================== This gets called in the header section
  279: 
  280: sub registerurl {
  281:     my ($forcereg) = @_;
  282:     my $result = '';
  283:     if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
  284:     my $force_title='';
  285:     if ($env{'request.state'} eq 'construct') {
  286: 	$force_title=&Apache::lonxml::display_title();
  287:     }
  288:     if (($env{'browser.interface'} eq 'textual') ||
  289:         ($env{'environment.remote'} eq 'off') ||
  290:         ((($env{'request.publicaccess'}) || 
  291:          (!&Apache::lonnet::is_on_map(
  292: 	   &unescape($env{'request.noversionuri'})))) &&
  293:         (!$forcereg))) {
  294:  	return $result.
  295:           '<script type="text/javascript">function LONCAPAreg(){;} function LONCAPAstale(){}</script>'.$force_title;
  296:     }
  297: # Graphical display after login only
  298:     if ($env{'request.registered'} && !$forcereg) { return ''; }
  299:     $result.=&innerregister($forcereg);
  300:     return $result.$force_title;
  301: }
  302: 
  303: # =========== This gets called in order to register a URL, both with the Remote
  304: # =========== and in the body of the document
  305: 
  306: sub innerregister {
  307:     my ($forcereg, $titletable) = @_;
  308:     my $result = '';
  309:     my ($uname,$thisdisfn);
  310:     my $const_space = ($env{'request.state'} eq 'construct');
  311:     my $is_const_dir = 0;
  312: 
  313:     if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
  314: 
  315:     $env{'request.registered'} = 1;
  316: 
  317:     my $textinter=($env{'browser.interface'} eq 'textual');
  318:     my $noremote=($env{'environment.remote'} eq 'off');
  319:     
  320:     my $textual=($textinter || $noremote);
  321: 
  322:     undef(@inlineremote);
  323: 
  324:     my $reopen=&Apache::lonmenu::reopenmenu();
  325: 
  326:     my $newmail='';
  327:     if ($noremote) {
  328: 	$newmail='<table id="LC_nav_location"><tr>';
  329:     }
  330:     if (&Apache::lonmsg::newmail()) { 
  331: 	if ($textual) {
  332: 	    $newmail.= '<td class="LC_new_mail">
  333:                    <a href="/adm/communicate" target="_top">'.
  334: 		   &mt('You have new messages').'</a></td>';
  335: 	} else {
  336: 	    $newmail= 'swmenu.setstatus("you have","messages");';
  337: 	}
  338:     } elsif (($textual) 
  339: 	     && ($env{'request.symb'}) 
  340: 	     && ($env{'request.course.id'})) {
  341: 	$newmail.= '<td class="LC_current_location">';
  342: 	my ($mapurl,$rid,$resurl)=
  343: 	    &Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
  344:         $newmail.=$env{'course.'.$env{'request.course.id'}.'.description'};
  345:         my $maptitle=&Apache::lonnet::gettitle($mapurl);
  346: 	my $restitle=&Apache::lonnet::gettitle(&Apache::lonnet::symbread());
  347:         if ($maptitle && $maptitle ne 'default.sequence') {
  348: 	    $newmail.=', '.$maptitle;
  349:         }
  350:         if ($restitle) {
  351: 	    $newmail.=': '.$restitle;
  352:         }
  353:         $newmail.='&nbsp;&nbsp;&nbsp;</td>';
  354:     }
  355:     if ($env{'request.state'} eq 'construct') {
  356:         $newmail = $titletable;
  357:     } else {
  358: 	if ($noremote) {
  359: 	    $newmail.='</tr></table>';
  360: 	}
  361:     }
  362:     my $timesync=($textual?'':'swmenu.syncclock(1000*'.time.');');
  363:     my $tablestart=($noremote?'<table id="LC_menubuttons">':'').
  364: 	($textinter?'<br /><a href="#content">'.&mt('Skip to Content').'</a><br />':'');
  365:     my $tableend=($noremote?'</table>':'').($textinter?'<a name="content" />':'');
  366: # =============================================================================
  367: # ============================ This is for URLs that actually can be registered
  368:     if (($env{'request.noversionuri'}!~m|^/(res/)*adm/|) || ($forcereg)) {
  369: # -- This applies to homework problems for users with grading privileges
  370: 	my $crs='/'.$env{'request.course.id'};
  371: 	if ($env{'request.course.sec'}) {
  372: 	    $crs.='_'.$env{'request.course.sec'};
  373: 	}
  374: 	$crs=~s/\_/\//g;
  375: 
  376:         my $hwkadd='';
  377:         if ($env{'request.symb'} ne '' &&
  378: 	    $env{'request.filename'}=~/\.(problem|exam|quiz|assess|survey|form|task)$/) {
  379: 	    if (&Apache::lonnet::allowed('mgr',$crs)) {
  380: 		$hwkadd.=&switch('','',7,2,'pgrd.gif','problem[_1]','grades[_3]',
  381:                        "gocmd('/adm/grades','gradingmenu')",
  382:                        'Modify user grades for this assessment resource');
  383:             } elsif (&Apache::lonnet::allowed('vgr',$crs)) {
  384: 		$hwkadd.=&switch('','',7,2,'subm.gif','view sub-[_1]','missions[_1]',
  385:                        "gocmd('/adm/grades','submission')",
  386: 		       'View user submissions for this assessment resource');
  387:             }
  388: 	}
  389: 	if ($env{'request.symb'} ne '' &&
  390: 	    &Apache::lonnet::allowed('opa',$crs)) {
  391: 	    $hwkadd.=&switch('','',7,3,'pparm.gif','problem[_2]','parms[_2]',
  392: 			     "gocmd('/adm/parmset','set')",
  393: 			     'Modify parameter settings for this resource');
  394: 	}
  395: # -- End Homework
  396:         ###
  397:         ### Determine whether or not to display the 'cstr' button for this
  398:         ### resource
  399:         ###
  400:         my $editbutton = '';
  401:         if ($env{'user.author'}) {
  402:             if ($env{'request.role'}=~/^(ca|au)/) {
  403:                 # Set defaults for authors
  404:                 my ($top,$bottom) = ('con-','struct');
  405:                 my $action = "go('/priv/".$env{'user.name'}."');";
  406:                 my $cadom  = $env{'request.role.domain'};
  407:                 my $caname = $env{'user.name'};
  408:                 my $desc = "Enter my resource construction space";
  409:                 # Set defaults for co-authors
  410:                 if ($env{'request.role'} =~ /^ca/) { 
  411:                     ($cadom,$caname)=($env{'request.role'}=~/(\w+)\/(\w+)$/);
  412:                     ($top,$bottom) = ('co con-','struct');
  413:                     $action = "go('/priv/".$caname."');";
  414:                     $desc = "Enter construction space as co-author";
  415:                 }
  416:                 # Check that we are on the correct machine
  417:                 my $home = &Apache::lonnet::homeserver($caname,$cadom);
  418: 		my $allowed=0;
  419: 		my @ids=&Apache::lonnet::current_machine_ids();
  420: 		foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
  421: 		if (!$allowed) {
  422: 		    $editbutton=&switch('','',6,1,$top,,$bottom,$action,$desc);
  423:                 }
  424:             }
  425:             ##
  426:             ## Determine if user can edit url.
  427:             ##
  428:             my $cfile='';
  429:             my $cfuname='';
  430:             my $cfudom='';
  431:             if ($env{'request.filename'}) {
  432:                 my $file=&Apache::lonnet::declutter($env{'request.filename'});
  433:                 $file=~s/^(\w+)\/(\w+)/\/priv\/$2/;
  434:                 # Check that the user has permission to edit this resource
  435:                 ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$1);
  436:                 if (defined($cfudom)) {
  437: 		    my $home=&Apache::lonnet::homeserver($cfuname,$cfudom);
  438: 		    my $allowed=0;
  439: 		    my @ids=&Apache::lonnet::current_machine_ids();
  440: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
  441: 		    if ($allowed) {
  442:                         $cfile=$file;
  443:                     }
  444:                 }
  445:             }        
  446:             # Finally, turn the button on or off
  447:             if ($cfile && !$const_space) {
  448:                 $editbutton=&switch
  449:                     ('','',6,1,'cstr.gif','edit[_1]','resource[_2]',
  450:                      "go('".$cfile."');","Edit this resource");
  451:             } elsif ($editbutton eq '') {
  452:                 $editbutton=&clear(6,1);
  453:             }
  454:         }
  455:         ###
  456:         ###
  457: # Prepare the rest of the buttons
  458:         my $menuitems;
  459:         if ($const_space) {
  460: 	    my ($uname,$thisdisfn) =
  461: 		($env{'request.filename'}=~m|^/home/([^/]+)/public_html/(.*)|);
  462:             my $currdir = '/priv/'.$uname.'/'.$thisdisfn;
  463:             if ($currdir =~ m-/$-) {
  464:                 $is_const_dir = 1;
  465:             } else {
  466:                 $currdir =~ s#[^/]+$##;
  467: 		my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn);
  468:                 $menuitems=(<<ENDMENUITEMS);
  469: s&6&1&list.gif&list[_1]&dir[_1]&golist('$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,$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:     unless (($env{'browser.interface'} eq 'textual')  ||
  824:             ($env{'environment.remote'} eq 'off')) {
  825: # Remote
  826:        return "\n".
  827:  qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
  828:    } elsif ($env{'browser.interface'} eq 'textual') {
  829: # Accessibility
  830:        if ($nobreak==2) { return ''; }
  831:        my $text=$top.' '.$bot;
  832:        $text=~s/\s*\-\s*//gs;
  833:        if ($nobreak) {
  834: 	   $inlineremote[10*$row+$col]=
  835: 	       '<a href="javascript:'.$act.';">'.$text.'</a>';
  836:        } else {
  837: 	   $inlineremote[10*$row+$col]="\n<br />".
  838: 	       $desc.' <a href="javascript:'.$act.';">'.$text.'</a>';
  839:        }
  840:    } else {
  841: # Inline Remote
  842:        if ($nobreak==2) { return ''; }
  843:        my $text=$top.' '.$bot;
  844:        $text=~s/\s*\-\s*//gs;
  845: 
  846:        my $lonhttpdPort=$Apache::lonnet::perlvar{'lonhttpdPort'};
  847:        if (!defined($lonhttpdPort)) { $lonhttpdPort='8080'; }
  848:        my $pic=
  849: 	   '<img alt="'.$text.'" src="http://'.$ENV{'HTTP_HOST'}.
  850: 	   ':'.$lonhttpdPort.'/res/adm/pages/'.$img.'" align="'.
  851: 	   ($nobreak==3?'right':'left').'" />';
  852:        if ($env{'browser.interface'} eq 'faketextual') {
  853: # Accessibility
  854: 	   if ($nobreak==3) {
  855: 	       $inlineremote[10*$row+$col]="\n".
  856: 		   '<td class="LC_menubuttons_text" align="right">'.$text.
  857: 		   '</td><td class="LC_menubuttons_img" align="left">'.
  858: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
  859: 	   } elsif ($nobreak) {
  860: 	       $inlineremote[10*$row+$col]="\n<tr>".
  861: 		   '<td class="LC_menubuttons_img" align="left">'.
  862: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td>
  863:                     <td class="LC_menubuttons_text" align="left">'.$text.'</td>';
  864: 	   } else {
  865: 	       $inlineremote[10*$row+$col]="\n<tr>".
  866: 		   '<td class="LC_menubuttons_img" align="left">'.
  867: 		   '<a href="javascript:'.$act.';">'.$pic.
  868: 		   '</a></td><td class="LC_menubuttons_text" colspan="3">'.
  869: 		   $desc.'</td></tr>';
  870: 	   }
  871:        } else {
  872: # Inline Menu
  873: 	   $inlineremote[10*$row+$col]=
  874: 		   '<a href="javascript:'.$act.';">'.$pic.
  875: 		   '</a><span class="LC_menubuttons_inline_text">'.$desc.'</span>';
  876:        }
  877:    }
  878:     return '';
  879: }
  880: 
  881: sub secondlevel {
  882:     my $output='';
  883:     my 
  884:     ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc)=@_;
  885:     if ($prt eq 'any') {
  886: 	   $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
  887:     } elsif ($prt=~/^r(\w+)/) {
  888:         if ($rol eq $1) {
  889:            $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
  890:         }
  891:     }
  892:     return $output;
  893: }
  894: 
  895: sub openmenu {
  896:     my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
  897:     if (($env{'browser.interface'} eq 'textual') ||
  898:         ($env{'environment.remote'} eq 'off')) { return ''; }
  899:     my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
  900:     return "window.open(".$nothing.",'".$menuname."');";
  901: }
  902: 
  903: sub inlinemenu {
  904:     @inlineremote=();
  905:     undef @inlineremote;
  906:     &rawconfig(1);
  907:     return join('',map { (defined($_)?$_:'') } @inlineremote);
  908: }
  909: 
  910: sub rawconfig {
  911:     my $textualoverride=shift;
  912:     my $output='';
  913:     unless (($env{'browser.interface'} eq 'textual') ||
  914:             ($env{'environment.remote'} eq 'off')) {
  915:        $output.=
  916:  "window.status='Opening Remote Control';var swmenu=".&openmenu().
  917: "\nwindow.status='Configuring Remote Control ';";
  918:     } else {
  919:        unless ($textualoverride) { return ''; }
  920:     }
  921:     my $uname=$env{'user.name'};
  922:     my $udom=$env{'user.domain'};
  923:     my $adv=$env{'user.adv'};
  924:     my $author=$env{'user.author'};
  925:     my $crs='';
  926:     if ($env{'request.course.id'}) {
  927:        $crs='/'.$env{'request.course.id'};
  928:        if ($env{'request.course.sec'}) {
  929: 	   $crs.='_'.$env{'request.course.sec'};
  930:        }
  931:        $crs=~s/\_/\//g;
  932:     }
  933:     my $pub=($env{'request.state'} eq 'published');
  934:     my $con=($env{'request.state'} eq 'construct');
  935:     my $rol=$env{'request.role'};
  936:     my $requested_domain = $env{'request.role.domain'};
  937:     foreach my $line (@desklines) {
  938:         my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc)=split(/\:/,$line);
  939:         $prt=~s/\$uname/$uname/g;
  940:         $prt=~s/\$udom/$udom/g;
  941:         $prt=~s/\$crs/$crs/g; 
  942:         $prt=~s/\$requested_domain/$requested_domain/g;
  943:         my $type = &Apache::loncommon::course_type();
  944:         if ($type eq 'Group') {
  945:             $desc = &convert_menu_function($desc,$type);
  946:         }
  947:         if ($pro eq 'clear') {
  948: 	    $output.=&clear($row,$col);
  949:         } elsif ($pro eq 'any') {
  950:                $output.=&secondlevel(
  951: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
  952: 	} elsif ($pro eq 'smp') {
  953:             unless ($adv) {
  954:                $output.=&secondlevel(
  955:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
  956:             }
  957:         } elsif ($pro eq 'adv') {
  958:             if ($adv) {
  959:                $output.=&secondlevel(
  960: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
  961:             }
  962:         } elsif (($pro=~/^p(\w+)/) && ($prt)) {
  963: 	    if (&Apache::lonnet::allowed($1,$prt)) {
  964:                $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
  965:             }
  966:         } elsif ($pro eq 'course') {
  967:             if ($env{'request.course.fn'}) {
  968:                $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
  969: 	    }
  970:         } elsif ($pro =~ /^courseenv_(.*)$/) {
  971:             my $key = $1;
  972:             if ($env{'course.'.$env{'request.course.id'}.'.'.$key}) {
  973:                 $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
  974:             }
  975:         } elsif ($pro =~ /^course_(.*)$/) {
  976:             # Check for permissions inside of a course
  977:             if (($env{'request.course.id'}) &&
  978:                 (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
  979:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
  980:                  )) {
  981:                 $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
  982: 	    }
  983:         } elsif ($pro eq 'author') {
  984:             if ($author) {
  985:                 if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
  986:                     (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
  987:                     # Check that we are on the correct machine
  988:                     my $cadom=$requested_domain;
  989:                     my $caname=$env{'user.name'};
  990:                     if ($prt eq 'rca') {
  991: 		       ($cadom,$caname)=
  992:                                ($env{'request.role'}=~/(\w+)\/(\w+)$/);
  993:                     }                       
  994:                     $act =~ s/\$caname/$caname/g;
  995:                     my $home = &Apache::lonnet::homeserver($caname,$cadom);
  996: 		    my $allowed=0;
  997: 		    my @ids=&Apache::lonnet::current_machine_ids();
  998: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
  999: 		    if ($allowed) {
 1000:                         $output.=switch($caname,$cadom,
 1001:                                         $row,$col,$img,$top,$bot,$act,$desc);
 1002:                     }
 1003:                 }
 1004:             }
 1005:         }
 1006:     }
 1007:     unless (($env{'browser.interface'} eq 'textual') ||
 1008:             ($env{'environment.remote'} eq 'off')) {
 1009:        $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
 1010:        if (&Apache::lonmsg::newmail()) { 
 1011: 	   $output.='swmenu.setstatus("you have","messages");';
 1012:        }
 1013:     }
 1014: 
 1015:     return $output;
 1016: }
 1017: 
 1018: # ======================================================================= Close
 1019: 
 1020: sub close {
 1021:     if (($env{'browser.interface'} eq 'textual') ||
 1022:         ($env{'environment.remote'} eq 'off')) { return ''; }
 1023:     my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
 1024:     return(<<ENDCLOSE);
 1025: <script type="text/javascript">
 1026: window.status='Accessing Remote Control';
 1027: menu=window.open("/adm/rat/empty.html","$menuname",
 1028:                  "height=350,width=150,scrollbars=no,menubar=no");
 1029: window.status='Disabling Remote Control';
 1030: menu.active=0;
 1031: menu.autologout=0;
 1032: window.status='Closing Remote Control';
 1033: menu.close();
 1034: window.status='Done.';
 1035: </script>
 1036: ENDCLOSE
 1037: }
 1038: 
 1039: # ====================================================================== Footer
 1040: 
 1041: sub footer {
 1042: 
 1043: }
 1044: 
 1045: sub nav_control_js {
 1046:     my $nav=($env{'environment.remotenavmap'} eq 'on');
 1047:     return (<<NAVCONTROL);
 1048:     var w_loncapanav_flag="$nav";
 1049: 
 1050: 
 1051: function gonav(url) {
 1052:    if (w_loncapanav_flag != 1) {
 1053:       gopost(url,'');
 1054:    }  else {
 1055:       navwindow=window.open(url,
 1056:                   "loncapanav","height=600,width=400,scrollbars=1"); 
 1057:    }
 1058: }
 1059: NAVCONTROL
 1060: }
 1061: 
 1062: sub utilityfunctions {
 1063:     my $caller = shift;
 1064:     unless (($env{'browser.interface'} eq 'textual')  ||
 1065:         ($env{'environment.remote'} eq 'off') || ($caller eq '/adm/menu')) { return ''; }
 1066:     my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
 1067:     $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
 1068:     
 1069:     my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
 1070:     my $nav_control=&nav_control_js();
 1071: 
 1072:     my $start_page_annotate = 
 1073:         &Apache::loncommon::start_page('Annotator',undef,
 1074: 				       {'only_body' => 1,
 1075: 					'js_ready'  => 1,
 1076: 					'bgcolor'   => '#BBBBBB',
 1077: 					'add_entries' => {
 1078: 					    'onload' => 'javascript:document.goannotate.submit();'}});
 1079: 
 1080:     my $start_page_bookmark = 
 1081:         &Apache::loncommon::start_page('Bookmarks',undef,
 1082: 				       {'only_body' => 1,
 1083: 					'js_ready'  => 1,
 1084: 					'bgcolor'   => '#BBBBBB',});
 1085: 
 1086:     my $end_page = 
 1087:         &Apache::loncommon::end_page({'js_ready' => 1});
 1088: 
 1089: return (<<ENDUTILITY)
 1090: 
 1091:     var currentURL="$currenturl";
 1092:     var reloadURL="$currenturl";
 1093:     var currentSymb="$currentsymb";
 1094: 
 1095: $nav_control
 1096: 
 1097: function go(url) {
 1098:    if (url!='' && url!= null) {
 1099:        currentURL = null;
 1100:        currentSymb= null;
 1101:        window.location.href=url;
 1102:    }
 1103: }
 1104: 
 1105: function gopost(url,postdata) {
 1106:    if (url!='') {
 1107:       this.document.server.action=url;
 1108:       this.document.server.postdata.value=postdata;
 1109:       this.document.server.command.value='';
 1110:       this.document.server.url.value='';
 1111:       this.document.server.symb.value='';
 1112:       this.document.server.submit();
 1113:    }
 1114: }
 1115: 
 1116: function gocmd(url,cmd) {
 1117:    if (url!='') {
 1118:       this.document.server.action=url;
 1119:       this.document.server.postdata.value='';
 1120:       this.document.server.command.value=cmd;
 1121:       this.document.server.url.value=currentURL;
 1122:       this.document.server.symb.value=currentSymb;
 1123:       this.document.server.submit();
 1124:    }
 1125: }
 1126: 
 1127: function gocstr(url,filename) {
 1128:     if (url == '/adm/cfile?action=delete') {
 1129:         this.document.cstrdelete.filename.value = filename
 1130:         this.document.cstrdelete.submit();
 1131:         return;
 1132:     }
 1133:     if (url == '/adm/printout') {
 1134:         this.document.cstrprint.postdata.value = filename
 1135:         this.document.cstrprint.curseed.value = 0;
 1136:         this.document.cstrprint.problemtype.value = 0;
 1137:         if (this.document.lonhomework) {
 1138:             if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
 1139:                 this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
 1140:             }
 1141:             if (this.document.lonhomework.problemtype) {
 1142: 		if (this.document.lonhomework.problemtype.value) {
 1143: 		    this.document.cstrprint.problemtype.value = 
 1144: 			this.document.lonhomework.problemtype.value;
 1145: 		} else if (this.document.lonhomework.problemtype.options) {
 1146: 		    for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
 1147: 			if (this.document.lonhomework.problemtype.options[i].selected) {
 1148: 			    if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') { 
 1149: 				this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
 1150: 				}
 1151: 			}
 1152: 		    }
 1153: 		}
 1154: 	    }
 1155: 	}
 1156:         this.document.cstrprint.submit();
 1157:         return;
 1158:     }
 1159:     if (url !='') {
 1160:         this.document.constspace.filename.value = filename;
 1161:         this.document.constspace.action = url;
 1162:         this.document.constspace.submit();
 1163:     }
 1164: }
 1165: 
 1166: function golist(url) {
 1167:    if (url!='' && url!= null) {
 1168:        currentURL = null;
 1169:        currentSymb= null;
 1170:        top.location.href=url;
 1171:    }
 1172: }
 1173: 
 1174: 
 1175: 
 1176: function catalog_info() {
 1177:    loncatinfo=window.open(window.location.pathname+'.meta',"LONcatInfo",'height=320,width=280,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
 1178: }
 1179: 
 1180: function chat_win() {
 1181:    lonchat=window.open('/res/adm/pages/chatroom.html',"LONchat",'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
 1182: }
 1183: 
 1184: function group_chat(group) {
 1185:    var url = '/adm/groupchat?group='+group;
 1186:    var winName = 'LONchat_'+group;
 1187:    grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
 1188: }
 1189: 
 1190: function edit_bookmarks() {
 1191:    go('');
 1192:    w_BookmarkPal_flag=1;
 1193:    bookmarkpal=window.open("/adm/bookmarks",
 1194:                "BookmarkPal", "width=400,height=505,scrollbars=0");
 1195: }
 1196: 
 1197: function annotate() {
 1198:    w_Annotator_flag=1;
 1199:    annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
 1200:    annotator.document.write(
 1201:    '$start_page_annotate'
 1202:   +"<form name='goannotate' target='Annotator' method='post' "
 1203:   +"action='/adm/annotations'>"
 1204:   +"<input type='hidden' name='urlnew' value='"+currentURL+"' />"
 1205:   +"<\\/form>"
 1206:   +'$end_page');
 1207:    annotator.document.close();
 1208: }
 1209: 
 1210: function set_bookmark() {
 1211:    go('');
 1212:    clienttitle=document.title;
 1213:    clienthref=location.pathname;
 1214:    w_bmquery_flag=1;
 1215:    bmquery=window.open('','bmquery','width=365,height=165,scrollbars=0');
 1216:    bmquery.document.write(
 1217:    '$start_page_bookmark'
 1218:    +"<center><form method='post'"
 1219:    +" name='newlink' action='/adm/bookmarks' target='bmquery' "
 1220:    +">\\n <table width=340 height=150 "
 1221:    +"bgcolor='ffffff' align=center><tr><td>Link Name:<br /><input "
 1222:    +"type='text' name='title' size=45 value='"+clienttitle+"' />"
 1223:    +"<br />Address:<br /><input type='text' name='address' size='45' "
 1224:    +"value='"+clienthref+"' /><br /><center><input type='submit' "
 1225:    +"value='Save' /> <input type='button' value='Close (no save)' "
 1226:    +"onclick='javascript:window.close();' /><\\/center><\\/td>"
 1227:    +"<\\/tr><\\/table><\\/form><\\/center>"
 1228:    +'$end_page' );
 1229:    bmquery.document.close();
 1230: }
 1231: 
 1232: ENDUTILITY
 1233: }
 1234: 
 1235: sub serverform {
 1236:     return(<<ENDSERVERFORM);
 1237: <form name="server" action="/adm/logout" method="post" target="_top">
 1238: <input type="hidden" name="postdata" value="none" />
 1239: <input type="hidden" name="command" value="none" />
 1240: <input type="hidden" name="url" value="none" />
 1241: <input type="hidden" name="symb" value="none" />
 1242: </form>
 1243: ENDSERVERFORM
 1244: }
 1245: 
 1246: sub constspaceform {
 1247:     return(<<ENDCONSTSPACEFORM);
 1248: <form name="constspace" action="/adm/logout" method="post" target="_top">
 1249: <input type="hidden" name="filename" value="" />
 1250: </form>
 1251: <form name="cstrdelete" action="/adm/cfile" method="post" target="_top">
 1252: <input type="hidden" name="action" value="delete" /> 
 1253: <input type="hidden" name="filename" value="" />
 1254: </form>
 1255: <form name="cstrprint" action="/adm/printout" target="_parent" method="post">
 1256: <input type="hidden" name="postdata" value="" />
 1257: <input type="hidden" name="curseed" value="" />
 1258: <input type="hidden" name="problemtype" value="" />
 1259: </form>
 1260: 
 1261: ENDCONSTSPACEFORM
 1262: }
 1263: 
 1264: 
 1265: sub get_nav_status {
 1266:     my $navstatus="swmenu.w_loncapanav_flag=";
 1267:     if ($env{'environment.remotenavmap'} eq 'on') {
 1268: 	$navstatus.="1";
 1269:     } else {
 1270: 	$navstatus.="-1";
 1271:     }
 1272:     return $navstatus;
 1273: }
 1274: 
 1275: #FIXME this needs to move into mydesktab and the other locations 
 1276: # the text is generated
 1277: sub convert_menu_function {
 1278:     my ($rolename,$type) = @_;
 1279:     if ($type eq 'Group') {
 1280:         $rolename =~ s/student/member/g;
 1281:         $rolename =~ s/group/team/g;
 1282:         $rolename =~ s/course/group/g;
 1283:         $rolename =~ s/Course/Group/g;
 1284:     }
 1285:     return $rolename;
 1286: }
 1287: 
 1288: 
 1289: # ================================================================ Main Program
 1290: 
 1291: BEGIN {
 1292:     if (! defined($readdesk)) {
 1293: 	{
 1294: 	    my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
 1295: 	    if ( CORE::open( my $config,"<$tabfile") ) {
 1296: 		while (my $configline=<$config>) {
 1297: 		    $configline=(split(/\#/,$configline))[0];
 1298: 		    $configline=~s/^\s+//;
 1299: 		    chomp($configline);
 1300: 		    if ($configline) {
 1301: 			push(@desklines,$configline);
 1302: 		    }
 1303: 		}
 1304: 		CORE::close($config);
 1305: 	    }
 1306: 	}
 1307: 	$readdesk='done';
 1308:     }
 1309: }
 1310: 
 1311: 1;
 1312: __END__
 1313: 
 1314: 
 1315: 
 1316: 
 1317: 
 1318: 
 1319: 

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