![]() ![]() | ![]() |
- apparently it is resizable not resizeable
1: # The LearningOnline Network with CAPA 2: # Routines to control the menu 3: # 4: # $Id: lonmenu.pm,v 1.102 2003/11/11 20:27:15 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::Constants qw(:common); 44: use Apache::lonhtmlcommon(); 45: use Apache::loncommon; 46: use Apache::File; 47: use Apache::lonlocal; 48: 49: use vars qw(@desklines $readdesk); 50: 51: 52: my @inlineremote; 53: my $font; 54: my $tabbg; 55: my $pgbg; 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: 'launch' => 'Launch Remote Control'); 64: } 65: 66: # ============================= This gets called at the top of the body section 67: 68: sub menubuttons { 69: my $forcereg=shift; 70: my $target =shift; 71: my $registration=shift; 72: my $navmaps=''; 73: my $reloadlink=''; 74: my $escurl=&Apache::lonnet::escape($ENV{'request.noversionuri'}); 75: my $escsymb=&Apache::lonnet::escape($ENV{'request.symb'}); 76: if ($ENV{'browser.interface'} eq 'textual') { 77: # Textual display only 78: my %lt=&initlittle(); 79: $pgbg='#FFFFFF'; 80: $tabbg='#FFFFFF'; 81: $font='#000000'; 82: if ($ENV{'request.course.id'}) { 83: $navmaps=(<<ENDNAV); 84: <a href="/adm/navmaps?postdata=$escurl&postsymb=$escsymb" target="_top">$lt{'nav'}</a> 85: ENDNAV 86: if (($ENV{'request.noversionuri'}=~/^\/adm\//) && 87: ($ENV{'request.noversionuri'}!~/^\/adm\/wrapper\//) && 88: ($ENV{'request.noversionuri'}!~/^\/adm\/.*\/(smppg|bulletinboard|aboutme)(\?|$)/)) { 89: my $escreload=&Apache::lonnet::escape('return:'); 90: $reloadlink=(<<ENDRELOAD); 91: <a href="/adm/flip?postdata=$escreload" target="_top"><font color="$font">$lt{'ret'}</font></a> 92: ENDRELOAD 93: } 94: } 95: my $output=(<<ENDMAINMENU); 96: <script> 97: // BEGIN LON-CAPA Internal 98: </script> 99: <a href="/adm/menu" target="_top">$lt{'main'}</a> 100: $reloadlink $navmaps<br /> 101: <script> 102: // END LON-CAPA Internal 103: </script> 104: ENDMAINMENU 105: if ($registration) { $output.=&innerregister($forcereg,$target); } 106: return $output."<hr />"; 107: } elsif ($ENV{'environment.remote'} eq 'off') { 108: # Remote Control is switched off 109: # figure out colors 110: my %lt=&initlittle(); 111: my $function='student'; 112: if ($ENV{'request.role'}=~/^(cc|in|ta|ep)/) { 113: $function='coordinator'; 114: } 115: if ($ENV{'request.role'}=~/^(su|dc|ad|li)/) { 116: $function='admin'; 117: } 118: if (($ENV{'request.role'}=~/^(au|ca)/) || 119: ($ENV{'request.noversionuri'}=~/^(\/priv|\~)/)) { 120: $function='author'; 121: } 122: my $domain=&Apache::loncommon::determinedomain(); 123: $pgbg=&Apache::loncommon::designparm($function.'.pgbg',$domain); 124: $tabbg=&Apache::loncommon::designparm($function.'.tabbg',$domain); 125: $font=&Apache::loncommon::designparm($function.'.font',$domain); 126: my $link=&Apache::loncommon::designparm($function.'.link',$domain); 127: my $alink=&Apache::loncommon::designparm($function.'.alink',$domain); 128: my $vlink=&Apache::loncommon::designparm($function.'.vlink',$domain); 129: my $sidebg=&Apache::loncommon::designparm($function.'.sidebg',$domain); 130: # Do we have a NAV link? 131: if ($ENV{'request.course.id'}) { 132: $navmaps=(<<ENDNAVREM); 133: <td bgcolor="$tabbg"> 134: <a href="/adm/navmaps?postdata=$escurl&postsymb=$escsymb" target="_top"><font color="$font">$lt{'nav'}</font></a></td> 135: ENDNAVREM 136: if (($ENV{'request.noversionuri'}=~/^\/adm\//) && 137: ($ENV{'request.noversionuri'}!~/^\/adm\/wrapper\//) && 138: ($ENV{'request.noversionuri'}!~/^\/adm\/.*\/(smppg|bulletinboard|aboutme)(\?|$)/)) { 139: my $escreload=&Apache::lonnet::escape('return:'); 140: $reloadlink=(<<ENDRELOAD); 141: <td bgcolor="$tabbg"> 142: <a href="/adm/flip?postdata=$escreload" target="_top"><font color="$font">$lt{'ret'}</font></a></td> 143: ENDRELOAD 144: } 145: } 146: my $reg=''; 147: if ($registration) { 148: $reg=&innerregister($forcereg,$target); 149: } 150: return (<<ENDINLINEMENU); 151: <script> 152: // BEGIN LON-CAPA Internal 153: </script> 154: <font face="Arial,Helvetica,sans-serif"><table bgcolor="$pgbg" width="100%" border="0" cellpadding="1" cellspacing="1"> 155: <tr> 156: <td bgcolor="$tabbg"> 157: <a href="/adm/menu" target="_top"><font color="$font">$lt{'main'}</font></a> 158: </td> 159: $reloadlink 160: $navmaps 161: <td bgcolor="$tabbg"> 162: <a href="/adm/remote?action=launch&url=$escurl" target="_top"> 163: <font color="$font">$lt{'launch'}</font></a></td> 164: <td bgcolor="$tabbg"> 165: <img align="right" src="/adm/lonIcons/minilogo.gif" /> 166: <b>LON-CAPA</b></td> 167: </tr> 168: </table> 169: </font> 170: <script> 171: // END LON-CAPA Internal 172: </script> 173: $reg 174: ENDINLINEMENU 175: } else { 176: return ''; 177: } 178: } 179: 180: # ====================================== This gets called in the header section 181: 182: sub registerurl { 183: my $forcereg=shift; 184: my $target = shift; 185: my $result = ''; 186: if ($ENV{'request.noversionuri'} eq '/res/adm/pages/menu.html') { return ''; } 187: my $force_title=''; 188: if ($ENV{'request.state'} eq 'construct') { 189: $force_title=&Apache::lonxml::display_title(); 190: } 191: if ($target eq 'edit') { 192: $result .="<script type=\"text/javascript\">\n". 193: "if (typeof swmenu != 'undefined') {swmenu.currentURL=null;}\n". 194: &Apache::loncommon::browser_and_searcher_javascript(). 195: "\n</script>\n"; 196: } 197: if (($ENV{'browser.interface'} eq 'textual') || 198: ($ENV{'environment.remote'} eq 'off') || 199: ((($ENV{'request.publicaccess'}) || 200: (!&Apache::lonnet::is_on_map( 201: &Apache::lonnet::unescape($ENV{'request.noversionuri'})))) && 202: (!$forcereg))) { 203: return $result. 204: '<script type="text/javascript">function LONCAPAreg(){;} function LONCAPAstale(){}</script>'.$force_title; 205: } 206: # Graphical display after login only 207: if ($Apache::lonxml::registered && !$forcereg) { return ''; } 208: if ($target ne 'edit') { 209: $result.=&innerregister($forcereg,$target); 210: } 211: return $result.$force_title; 212: } 213: 214: # =========== This gets called in order to register a URL, both with the Remote 215: # =========== and in the body of the document 216: 217: sub innerregister { 218: my $forcereg=shift; 219: my $target = shift; 220: my $result = ''; 221: if ($ENV{'request.noversionuri'} eq '/res/adm/pages/menu.html') { return ''; } 222: 223: $Apache::lonxml::registered=1; 224: 225: my $textinter=($ENV{'browser.interface'} eq 'textual'); 226: my $noremote=($ENV{'environment.remote'} eq 'off'); 227: 228: my $textual=($textinter || $noremote); 229: 230: @inlineremote=(); 231: undef @inlineremote; 232: 233: my $reopen=&Apache::lonmenu::reopenmenu(); 234: 235: my $newmail=''; 236: if ($noremote) { 237: $newmail='<font face="Arial,Helvetica,sans-serif"><table bgcolor="'.$pgbg.'" border="0" cellspacing="1" cellpadding="1" width="100%"><tr><td bgcolor="'.$tabbg.'">'; 238: } 239: if (($textual) && ($ENV{'request.symb'}) && ($ENV{'request.course.id'})) { 240: my ($mapurl,$rid,$resurl)=&Apache::lonnet::decode_symb($ENV{'request.symb'}); 241: $newmail.=$ENV{'course.'.$ENV{'request.course.id'}.'.description'}; 242: my $maptitle=&Apache::lonnet::gettitle($mapurl); 243: my $restitle=&Apache::lonnet::gettitle($resurl); 244: if ($maptitle) { 245: $newmail.=', '.$maptitle; 246: } 247: if ($restitle) { 248: $newmail.=': '.$restitle; 249: } 250: $newmail.=' '; 251: } 252: if (&Apache::lonmsg::newmail()) { 253: $newmail=($textual? 254: '<b><a href="/adm/communicate" target="_top">You have new messages</a></b><br />': 255: 'swmenu.setstatus("you have","messages");'); 256: } 257: if ($noremote) { 258: $newmail.='</td></tr></table></font>'; 259: } 260: my $timesync=($textual?'':'swmenu.syncclock(1000*'.time.');'); 261: my $tablestart=($noremote?'<font face="Arial,Helvetica,sans-serif"><table bgcolor="'.$pgbg.'" border="0" cellspacing="1" cellpadding="1" width="100%">':'').($textinter?'<br /><a href="#content">'.&mt('Skip to Content').'</a><br />':''); 262: my $tableend=($noremote?'</table></font>':'').($textinter?'<a name="content" />':''); 263: # ============================================================================= 264: # ============================ This is for URLs that actually can be registered 265: if (($ENV{'request.noversionuri'}!~/^\/(res\/)*adm\//) || ($forcereg)) { 266: # -- This applies to homework problems for users with grading privileges 267: my $hwkadd=''; 268: if 269: ($ENV{'request.filename'}=~/\.(problem|exam|quiz|assess|survey|form)$/) { 270: my $crs='/'.$ENV{'request.course.id'}; 271: if ($ENV{'request.course.sec'}) { 272: $crs.='_'.$ENV{'request.course.sec'}; 273: } 274: $crs=~s/\_/\//g; 275: 276: if (&Apache::lonnet::allowed('vgr',$crs)) { 277: $hwkadd.=&switch('','',7,1,'subm.gif','view sub-','missions', 278: "gocmd('/adm/grades','submission')", 279: 'View user submissions for this assessment resource'); 280: } 281: if (&Apache::lonnet::allowed('mgr',$crs)) { 282: $hwkadd.=&switch('','',7,2,'pgrd.gif','problem','grades', 283: "gocmd('/adm/grades','gradingmenu')", 284: 'Modify user grades for this assessment resource'); 285: } 286: if (&Apache::lonnet::allowed('opa',$crs)) { 287: $hwkadd.=&switch('','',7,3,'pparm.gif','problem','parms', 288: "gocmd('/adm/parmset','set')", 289: 'Modify deadlines, etc, for this assessment resource'); 290: } 291: } 292: # -- End Homework 293: ### 294: ### Determine whether or not to display the 'cstr' button for this 295: ### resource 296: ### 297: my $editbutton = ''; 298: if ($ENV{'user.author'}) { 299: if ($ENV{'request.role'}=~/^(ca|au)/) { 300: # Set defaults for authors 301: my ($top,$bottom) = ('con-','struct'); 302: my $action = "go('/priv/".$ENV{'user.name'}."');"; 303: my $cadom = $ENV{'request.role.domain'}; 304: my $caname = $ENV{'user.name'}; 305: my $desc = "Enter my resource construction space"; 306: # Set defaults for co-authors 307: if ($ENV{'request.role'} =~ /^ca/) { 308: ($cadom,$caname)=($ENV{'request.role'}=~/(\w+)\/(\w+)$/); 309: ($top,$bottom) = ('co con-','struct'); 310: $action = "go('/priv/".$caname."');"; 311: $desc = "Enter construction space as co-author"; 312: } 313: # Check that we are on the correct machine 314: my $home = &Apache::lonnet::homeserver($caname,$cadom); 315: if ($home eq $Apache::lonnet::perlvar{'lonHostID'}) { 316: $editbutton=&switch 317: ('','',6,1,$top,,$bottom,$action,$desc); 318: } 319: } 320: ## 321: ## Determine if user can edit url. 322: ## 323: my $cfile=''; 324: my $cfuname=''; 325: my $cfudom=''; 326: if ($ENV{'request.filename'}) { 327: my $file=&Apache::lonnet::declutter($ENV{'request.filename'}); 328: $file=~s/^(\w+)\/(\w+)/\/priv\/$2/; 329: # Chech that the user has permission to edit this resource 330: ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$1); 331: if (defined($cfudom)) { 332: if (&Apache::lonnet::homeserver($cfuname,$cfudom) 333: eq $Apache::lonnet::perlvar{'lonHostID'}) { 334: $cfile=$file; 335: } 336: } 337: } 338: # Finally, turn the button on or off 339: if ($cfile) { 340: $editbutton=&switch 341: ('','',6,1,'cstr.gif','edit','resource', 342: "go('".$cfile."');","Edit this resource"); 343: } elsif ($editbutton eq '') { 344: $editbutton=&clear(6,1); 345: } 346: } 347: ### 348: ### 349: # Prepare the rest of the buttons 350: my $menuitems=(<<ENDMENUITEMS); 351: c&3&1 352: s&2&1&back.gif&backward&&gopost('/adm/flip','back:'+currentURL)&Go to the previous resource in the course sequence&1 353: s&2&3&forw.gif&forward&&gopost('/adm/flip','forward:'+currentURL)&Go to the next resource in the course sequence&3 354: c&6&3 355: c&8&1 356: c&8&2 357: s&8&3&prt.gif&prepare&printout&gopost('/adm/printout',currentURL)&Prepare a printable document 358: s&9&1&sbkm.gif&set&bookmark&set_bookmark()&Set a bookmark for this resource&2 359: s&9&3&anot.gif&anno-&tations&annotate()&Make notes and annotations about this resource&2 360: ENDMENUITEMS 361: unless ($ENV{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme)(\?|$)/) { 362: $menuitems.=(<<ENDREALRES); 363: s&6&3&catalog.gif&catalog&info&catalog_info()&Show catalog information 364: s&8&1&eval.gif&evaluate&this&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource 365: s&8&2&fdbk.gif&feedback&discuss&gopost('/adm/feedback',currentURL,1)&Provide feedback messages or contribute to the course discussion about this resource 366: ENDREALRES 367: } 368: my $buttons=''; 369: foreach (split(/\n/,$menuitems)) { 370: my ($command,@rest)=split(/\&/,$_); 371: if ($command eq 's') { 372: $buttons.=&switch('','',@rest); 373: } else { 374: $buttons.=&clear(@rest); 375: } 376: } 377: if ($textual) { 378: # Registered, textual output 379: my $utility=&utilityfunctions(); 380: my $form=&serverform(); 381: my $inlinebuttons= 382: join('',map { (defined($_)?$_:'') } @inlineremote); 383: $result =(<<ENDREGTEXT); 384: <script> 385: // BEGIN LON-CAPA Internal 386: $utility 387: </script> 388: $timesync 389: $newmail 390: $tablestart 391: $inlinebuttons 392: $tableend 393: $form 394: <script> 395: // END LON-CAPA Internal 396: </script> 397: 398: ENDREGTEXT 399: # Registered, graphical output 400: } else { 401: my $requri=(split(/\?/,$ENV{'request.noversionuri'}))[0]; 402: $requri=&Apache::lonnet::unescape($requri); 403: $result = (<<ENDREGTHIS); 404: 405: <script language="JavaScript"> 406: // BEGIN LON-CAPA Internal 407: var swmenu=null; 408: 409: function LONCAPAreg() { 410: swmenu=$reopen; 411: swmenu.clearTimeout(swmenu.menucltim); 412: $timesync 413: $newmail 414: $buttons 415: swmenu.currentURL="$requri"; 416: swmenu.reloadURL=swmenu.currentURL+window.location.search; 417: swmenu.currentSymb="$ENV{'request.symb'}"; 418: swmenu.reloadSymb="$ENV{'request.symb'}"; 419: swmenu.currentStale=0; 420: $hwkadd 421: $editbutton 422: } 423: 424: function LONCAPAstale() { 425: swmenu=$reopen 426: swmenu.currentStale=1; 427: if (swmenu.reloadURL!='' && swmenu.reloadURL!= null) { 428: swmenu.switchbutton 429: (3,1,'reload.gif','return','location','go(reloadURL)','Return to the last known location in the course sequence'); 430: } 431: swmenu.clearbut(7,1); 432: swmenu.clearbut(7,2); 433: swmenu.clearbut(7,3); 434: swmenu.menucltim=swmenu.setTimeout( 435: 'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+ 436: 'clearbut(9,1);clearbut(9,2);clearbut(9,3);clearbut(6,3);clearbut(6,1)', 437: 2000); 438: } 439: 440: // END LON-CAPA Internal 441: </script> 442: ENDREGTHIS 443: } 444: # ============================================================================= 445: } else { 446: # ========================================== This can or will not be registered 447: if ($textual) { 448: # Not registered, textual 449: $result= (<<ENDDONOTREGTEXT); 450: ENDDONOTREGTEXT 451: } else { 452: # Not registered, graphical 453: $result = (<<ENDDONOTREGTHIS); 454: 455: <script language="JavaScript"> 456: // BEGIN LON-CAPA Internal 457: var swmenu=null; 458: 459: function LONCAPAreg() { 460: swmenu=$reopen 461: $timesync 462: swmenu.currentStale=1; 463: swmenu.clearbut(2,1); 464: swmenu.clearbut(2,3); 465: swmenu.clearbut(8,1); 466: swmenu.clearbut(8,2); 467: swmenu.clearbut(8,3); 468: if (swmenu.currentURL) { 469: swmenu.switchbutton 470: (3,1,'reload.gif','return','location','go(currentURL)'); 471: } else { 472: swmenu.clearbut(3,1); 473: } 474: } 475: 476: function LONCAPAstale() { 477: } 478: 479: // END LON-CAPA Internal 480: </script> 481: ENDDONOTREGTHIS 482: } 483: # ============================================================================= 484: } 485: return $result; 486: } 487: 488: sub loadevents() { 489: if ($ENV{'request.noversionuri'} eq '/res/adm/pages/menu.html') { return ''; } 490: return 'LONCAPAreg();'; 491: } 492: 493: sub unloadevents() { 494: if ($ENV{'request.noversionuri'} eq '/res/adm/pages/menu.html') { return ''; } 495: return 'LONCAPAstale();'; 496: } 497: 498: # ============================================================= Start up remote 499: 500: sub startupremote { 501: my ($lowerurl)=@_; 502: if (($ENV{'browser.interface'} eq 'textual') || 503: ($ENV{'environment.remote'} eq 'off')) { 504: return ('<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.$lowerurl.'" />'); 505: } 506: # 507: # The Remote actually gets launched! 508: # 509: my $configmenu=&rawconfig(); 510: my $esclowerurl=&Apache::lonnet::escape($lowerurl); 511: 512: return(<<ENDREMOTESTARTUP); 513: <script> 514: 515: function wheelswitch() { 516: if (window.status=='|') { 517: window.status='/'; 518: } else { 519: if (window.status=='/') { 520: window.status='-'; 521: } else { 522: if (window.status=='-') { 523: window.status='\\\\'; 524: } else { 525: if (window.status=='\\\\') { window.status='|'; } 526: } 527: } 528: } 529: } 530: 531: // ---------------------------------------------------------- The wait function 532: var canceltim; 533: function wait() { 534: if ((menuloaded==1) || (tim==1)) { 535: window.status='Done.'; 536: if (tim==0) { 537: clearTimeout(canceltim); 538: $configmenu 539: window.location='$lowerurl'; 540: } else { 541: window.location='/adm/remote?action=collapse&url=$esclowerurl'; 542: } 543: } else { 544: wheelswitch(); 545: setTimeout('wait();',200); 546: } 547: } 548: 549: function main() { 550: canceltim=setTimeout('tim=1;',30000); 551: window.status='-'; 552: wait(); 553: } 554: 555: </script> 556: ENDREMOTESTARTUP 557: } 558: 559: sub setflags() { 560: return(<<ENDSETFLAGS); 561: <script> 562: menuloaded=0; 563: tim=0; 564: </script> 565: ENDSETFLAGS 566: } 567: 568: sub maincall() { 569: if (($ENV{'browser.interface'} eq 'textual') || 570: ($ENV{'environment.remote'} eq 'off')) { return ''; } 571: return(<<ENDMAINCALL); 572: <script> 573: main(); 574: </script> 575: ENDMAINCALL 576: } 577: # ================================================================= Reopen menu 578: 579: sub reopenmenu { 580: if (($ENV{'browser.interface'} eq 'textual') || 581: ($ENV{'environment.remote'} eq 'off')) { return ''; } 582: my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'}; 583: my $nothing = &Apache::lonhtmlcommon::javascript_nothing(); 584: return('window.open('.$nothing.',"'.$menuname.'","",false);'); 585: } 586: 587: # =============================================================== Open the menu 588: 589: sub open { 590: my $returnval=''; 591: if (($ENV{'browser.interface'} eq 'textual') || 592: ($ENV{'environment.remote'} eq 'off')) { return ''; } 593: my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'}; 594: unless (shift eq 'unix') { 595: # resizing does not work on linux because of virtual desktop sizes 596: $returnval.=(<<ENDRESIZE); 597: if (window.screen) { 598: self.resizeTo(screen.availWidth-215,screen.availHeight-55); 599: self.moveTo(190,15); 600: } 601: ENDRESIZE 602: } 603: $returnval.=(<<ENDOPEN); 604: window.status='Opening LON-CAPA Remote Control'; 605: var menu=window.open("/res/adm/pages/menu.html","$menuname", 606: "height=350,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5"); 607: self.name='loncapaclient'; 608: ENDOPEN 609: return '<script>'.$returnval.'</script>'; 610: } 611: 612: 613: # ================================================================== Raw Config 614: 615: sub clear { 616: my ($row,$col)=@_; 617: unless (($ENV{'browser.interface'} eq 'textual') || 618: ($ENV{'environment.remote'} eq 'off')) { 619: return "\n".qq(window.status+='.';swmenu.clearbut($row,$col);); 620: } else { 621: $inlineremote[10*$row+$col]=''; 622: return ''; 623: } 624: } 625: 626: # ============================================ Switch a button or create a link 627: # Switch acts on the javascript that is executed when a button is clicked. 628: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)". 629: 630: sub switch { 631: my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$nobreak)=@_; 632: $act=~s/\$uname/$uname/g; 633: $act=~s/\$udom/$udom/g; 634: $top=&mt($top); 635: $bot=&mt($bot); 636: $desc=&mt($desc); 637: unless (($ENV{'browser.interface'} eq 'textual') || 638: ($ENV{'environment.remote'} eq 'off')) { 639: # Remote 640: return "\n". 641: qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc");); 642: } elsif ($ENV{'browser.interface'} eq 'textual') { 643: # Accessibility 644: if ($nobreak==2) { return ''; } 645: my $text=$top.' '.$bot; 646: $text=~s/\s*\-\s*//gs; 647: if ($nobreak) { 648: $inlineremote[10*$row+$col]= 649: '<a href="javascript:'.$act.';">'.$text.'</a>'; 650: } else { 651: $inlineremote[10*$row+$col]="\n<br />". 652: $desc.' <a href="javascript:'.$act.';">'.$text.'</a>'; 653: } 654: } else { 655: # Inline Remote 656: if ($nobreak==2) { return ''; } 657: my $text=$top.' '.$bot; 658: $text=~s/\s*\-\s*//gs; 659: my $pic= 660: '<img border="0" alt="'.$text.'" src="/res/adm/pages/'.$img.'" />'; 661: if ($nobreak==3) { 662: $inlineremote[10*$row+$col]="\n". 663: '<td width="40%" align="right"><font color="'.$font.'" size="+1">'.$text. 664: '</font></td><td width="10%" align="right" bgcolor="'.$tabbg.'">'. 665: '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>'; 666: } elsif ($nobreak) { 667: $inlineremote[10*$row+$col]="\n<tr>". 668: '<td width="10%" align="left" bgcolor="'.$tabbg.'">'. 669: '<a href="javascript:'.$act.';">'.$pic. 670: '</a></td><td width="40%" align="left"><font color="'.$font.'" size="+1">'.$text.'</font></td>'; 671: } else { 672: $inlineremote[10*$row+$col]="\n<tr>". 673: '<td width="10%" align="left" bgcolor="'.$tabbg.'">'. 674: '<a href="javascript:'.$act.';">'.$pic. 675: '</a></td><td colspan="3"><font color="'.$font.'">'.$desc. 676: '</font></td></tr>'; 677: } 678: } 679: return ''; 680: } 681: 682: sub secondlevel { 683: my $output=''; 684: my 685: ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc)=@_; 686: if ($prt eq 'any') { 687: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc); 688: } elsif ($prt=~/^r(\w+)/) { 689: if ($rol eq $1) { 690: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc); 691: } 692: } 693: return $output; 694: } 695: 696: sub openmenu { 697: my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'}; 698: if (($ENV{'browser.interface'} eq 'textual') || 699: ($ENV{'environment.remote'} eq 'off')) { return ''; } 700: my $nothing = &Apache::lonhtmlcommon::javascript_nothing(); 701: return "window.open(".$nothing.",'".$menuname."');"; 702: } 703: 704: sub inlinemenu { 705: @inlineremote=(); 706: undef @inlineremote; 707: &rawconfig(1); 708: return join('',map { (defined($_)?$_:'') } @inlineremote); 709: } 710: 711: sub rawconfig { 712: my $textualoverride=shift; 713: my $output=''; 714: unless (($ENV{'browser.interface'} eq 'textual') || 715: ($ENV{'environment.remote'} eq 'off')) { 716: $output.= 717: "window.status='Opening Remote Control';var swmenu=".&openmenu(). 718: "\nwindow.status='Configuring Remote Control ';"; 719: } else { 720: unless ($textualoverride) { return ''; } 721: } 722: my $uname=$ENV{'user.name'}; 723: my $udom=$ENV{'user.domain'}; 724: my $adv=$ENV{'user.adv'}; 725: my $author=$ENV{'user.author'}; 726: my $crs=''; 727: if ($ENV{'request.course.id'}) { 728: $crs='/'.$ENV{'request.course.id'}; 729: if ($ENV{'request.course.sec'}) { 730: $crs.='_'.$ENV{'request.course.sec'}; 731: } 732: $crs=~s/\_/\//g; 733: } 734: my $pub=($ENV{'request.state'} eq 'published'); 735: my $con=($ENV{'request.state'} eq 'construct'); 736: my $rol=$ENV{'request.role'}; 737: my $requested_domain = $ENV{'request.role.domain'}; 738: foreach (@desklines) { 739: my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc)=split(/\:/,$_); 740: $prt=~s/\$uname/$uname/g; 741: $prt=~s/\$udom/$udom/g; 742: $prt=~s/\$crs/$crs/g; 743: $prt=~s/\$requested_domain/$requested_domain/g; 744: if ($pro eq 'clear') { 745: $output.=&clear($row,$col); 746: } elsif ($pro eq 'any') { 747: $output.=&secondlevel( 748: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc); 749: } elsif ($pro eq 'smp') { 750: unless ($adv) { 751: $output.=&secondlevel( 752: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc); 753: } 754: } elsif ($pro eq 'adv') { 755: if ($adv) { 756: $output.=&secondlevel( 757: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc); 758: } 759: } elsif (($pro=~/^p(\w+)/) && ($prt)) { 760: if (&Apache::lonnet::allowed($1,$prt)) { 761: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc); 762: } 763: } elsif ($pro eq 'course') { 764: if ($ENV{'request.course.fn'}) { 765: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc); 766: } 767: } elsif ($pro =~ /^course_(.*)$/) { 768: # Check for permissions inside of a course 769: if (($ENV{'request.course.id'}) && 770: (&Apache::lonnet::allowed($1,$ENV{'request.course.id'}. 771: ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:'')) 772: )) { 773: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc); 774: } 775: } elsif ($pro eq 'author') { 776: if ($author) { 777: if ((($prt eq 'rca') && ($ENV{'request.role'}=~/^ca/)) || 778: (($prt eq 'rau') && ($ENV{'request.role'}=~/^au/))) { 779: # Check that we are on the correct machine 780: my $cadom=$requested_domain; 781: my $caname=$ENV{'user.name'}; 782: if ($prt eq 'rca') { 783: ($cadom,$caname)= 784: ($ENV{'request.role'}=~/(\w+)\/(\w+)$/); 785: } 786: $act =~ s/\$caname/$caname/g; 787: my $home = &Apache::lonnet::homeserver($caname,$cadom); 788: if ($home eq $Apache::lonnet::perlvar{'lonHostID'}) { 789: $output.=switch($caname,$cadom, 790: $row,$col,$img,$top,$bot,$act,$desc); 791: } 792: } 793: } 794: } 795: } 796: unless (($ENV{'browser.interface'} eq 'textual') || 797: ($ENV{'environment.remote'} eq 'off')) { 798: $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';"; 799: } 800: return $output; 801: } 802: 803: # ======================================================================= Close 804: 805: sub close { 806: if (($ENV{'browser.interface'} eq 'textual') || 807: ($ENV{'environment.remote'} eq 'off')) { return ''; } 808: my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'}; 809: return(<<ENDCLOSE); 810: <script> 811: window.status='Accessing Remote Control'; 812: menu=window.open("/adm/rat/empty.html","$menuname", 813: "height=350,width=150,scrollbars=no,menubar=no"); 814: window.status='Disabling Remote Control'; 815: menu.active=0; 816: menu.autologout=0; 817: window.status='Closing Remote Control'; 818: menu.close(); 819: window.status='Done.'; 820: </script> 821: ENDCLOSE 822: } 823: 824: # ====================================================================== Footer 825: 826: sub footer { 827: 828: } 829: 830: sub utilityfunctions { 831: unless (($ENV{'browser.interface'} eq 'textual') || 832: ($ENV{'environment.remote'} eq 'off')) { return ''; } 833: my $currenturl=$ENV{'request.noversionuri'}; 834: my $currentsymb=$ENV{'request.symb'}; 835: return (<<ENDUTILITY) 836: 837: var currentURL="$currenturl"; 838: var reloadURL="$currenturl"; 839: var currentSymb="$currentsymb"; 840: 841: function go(url) { 842: if (url!='' && url!= null) { 843: currentURL = null; 844: currentSymb= null; 845: window.location.href=url; 846: } 847: } 848: 849: function gopost(url,postdata) { 850: if (url!='') { 851: this.document.server.action=url; 852: this.document.server.postdata.value=postdata; 853: this.document.server.command.value=''; 854: this.document.server.url.value=''; 855: this.document.server.symb.value=''; 856: this.document.server.submit(); 857: } 858: } 859: 860: function gocmd(url,cmd) { 861: if (url!='') { 862: this.document.server.action=url; 863: this.document.server.postdata.value=''; 864: this.document.server.command.value=cmd; 865: this.document.server.url.value=currentURL; 866: this.document.server.symb.value=currentSymb; 867: this.document.server.submit(); 868: } 869: } 870: 871: function catalog_info() { 872: loncatinfo=window.open(window.location.pathname+'.meta',"LONcatInfo",'height=320,width=280,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no'); 873: } 874: 875: function chat_win() { 876: lonchat=window.open('/res/adm/pages/chatroom.html',"LONchat",'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no'); 877: } 878: ENDUTILITY 879: } 880: 881: sub serverform { 882: return(<<ENDSERVERFORM); 883: 884: <form name="server" action="/adm/logout" method="post" target="_top"> 885: <input type="hidden" name="postdata" value="none" /> 886: <input type="hidden" name="command" value="none" /> 887: <input type="hidden" name="url" value="none" /> 888: <input type="hidden" name="symb" value="none" /> 889: </form> 890: ENDSERVERFORM 891: } 892: # ================================================ Handler when called directly 893: 894: 895: sub handler { 896: my $r = shift; 897: &Apache::loncommon::content_type($r,'text/html'); 898: $r->send_http_header; 899: return OK if $r->header_only; 900: 901: my $form=&serverform(); 902: my $bodytag=&Apache::loncommon::bodytag('Main Menu'); 903: my $function='student'; 904: if ($ENV{'request.role'}=~/^(cc|in|ta|ep)/) { 905: $function='coordinator'; 906: } 907: if ($ENV{'request.role'}=~/^(su|dc|ad|li)/) { 908: $function='admin'; 909: } 910: if (($ENV{'request.role'}=~/^(au|ca)/) || 911: ($ENV{'request.noversionuri'}=~/^(\/priv|\~)/)) { 912: $function='author'; 913: } 914: my $domain=&Apache::loncommon::determinedomain(); 915: $pgbg=&Apache::loncommon::designparm($function.'.pgbg',$domain); 916: $tabbg=&Apache::loncommon::designparm($function.'.tabbg',$domain); 917: $font=&Apache::loncommon::designparm($function.'.font',$domain); 918: # ---- Print the screen, pretent to be in text mode to generate text-based menu 919: unless ($ENV{'brower.interface'} eq 'textual') { 920: $ENV{'environment.remote'}='off'; 921: } 922: my $utility=&utilityfunctions(); 923: $r->print(<<ENDHEADER); 924: <html><head> 925: <title>LON-CAPA Main Menu</title> 926: <script> 927: $utility 928: </script> 929: </head> 930: $bodytag 931: ENDHEADER 932: $r->print('<table>'.&inlinemenu().'</table>'.$form); 933: $r->print('</body></html>'); 934: return OK; 935: } 936: 937: # ================================================================ Main Program 938: 939: BEGIN { 940: if (! defined($readdesk)) { 941: { 942: my $config=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}. 943: '/mydesk.tab'); 944: while (my $configline=<$config>) { 945: $configline=(split(/\#/,$configline))[0]; 946: $configline=~s/^\s+//; 947: chomp($configline); 948: if ($configline) { 949: $desklines[$#desklines+1]=$configline; 950: } 951: } 952: } 953: $readdesk='done'; 954: } 955: } 956: 957: 1; 958: __END__ 959: 960: 961: 962: 963: 964: 965: