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

1.1       www         1: # The LearningOnline Network with CAPA
                      2: # Routines to control the menu
                      3: #
1.44    ! www         4: # $Id: lonmenu.pm,v 1.43 2003/02/20 18:00:31 www Exp $
1.11      albertel    5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
1.1       www        28: # (TeX Conversion Module
                     29: #
                     30: # 05/29/00,05/30 Gerd Kortemeyer)
                     31: #
1.8       www        32: # 10/05,05/28,05/30,06/01,06/08,06/09,07/04,08/07 Gerd Kortemeyer
1.17      matthew    33: # 02/15/02 Matthew Hall
1.1       www        34: 
                     35: package Apache::lonmenu;
                     36: 
                     37: use strict;
1.2       www        38: use Apache::lonnet;
1.33      www        39: use Apache::Constants qw(:common);
                     40: use Apache::loncommon;
1.2       www        41: use Apache::File;
                     42: use vars qw(@desklines $readdesk);
1.38      www        43: 
1.40      www        44: # ============================= This gets called at the top of the body section
1.38      www        45: 
                     46: sub menubuttons {
                     47:     my $forcereg=shift;
                     48:     my $target  =shift;
1.40      www        49:     my $registration=shift;
1.38      www        50:     unless ($ENV{'browser.interface'} eq 'textual') { return ''; }
1.41      www        51: # Textual display only
1.44    ! www        52:     my $output=(<<ENDMAINMENU);
        !            53: <script>
        !            54: // BEGIN LON-CAPA Internal
        !            55: </script>
        !            56: <a href="/adm/menu" target="_top">Main Menu</a><br />
        !            57: <script>
        !            58: // END LON-CAPA Internal
        !            59: </script>
        !            60: ENDMAINMENU
1.40      www        61:     if ($registration) { $output.=&innerregister($forcereg,$target); }
1.39      www        62:     return $output."<hr />";
1.38      www        63: }
                     64: 
1.40      www        65: # ====================================== This gets called in the header section
1.38      www        66: 
                     67: sub registerurl {
                     68:     my $forcereg=shift;
                     69:     my $target = shift;
                     70:     my $result = '';
                     71:     
                     72:     if ($target eq 'edit') {
                     73:         $result .="<script type=\"text/javascrtipt\">\n".
                     74:             "if (typeof swmenu != 'undefined') {swmenu.currentURL=null;}\n".
                     75:             &Apache::loncommon::browser_and_searcher_javascript().
                     76:                 "\n</script>\n";
                     77:     }
                     78:     if (($ENV{'browser.interface'} eq 'textual') ||
                     79:         ((($ENV{'request.publicaccess'}) || 
                     80:          (!&Apache::lonnet::is_on_map($ENV{'REQUEST_URI'}))) &&
                     81:         (!$forcereg))) {
                     82: 	return $result.
                     83:          '<script type="text/javascript">function LONCAPAreg(){;} function LONCAPAstale(){}</script>';
                     84:     }
1.41      www        85: # Graphical display after login only
1.38      www        86:     if ($Apache::lonxml::registered && !$forcereg) { return ''; }
1.40      www        87:     $result.=&innerregister($forcereg,$target);
                     88:     return $result;
                     89: }
                     90: 
                     91: # =========== This gets called in order to register a URL, both with the Remote
                     92: # =========== and in the body of the document
                     93: 
                     94: sub innerregister {
                     95:     my $forcereg=shift;
                     96:     my $target = shift;
                     97:     my $result = '';
                     98: 
1.38      www        99:     $Apache::lonxml::registered=1;
1.40      www       100: 
                    101:     my $textual=($ENV{'browser.interface'} eq 'textual');
1.38      www       102:     my $reopen=&Apache::lonmenu::reopenmenu();
1.40      www       103: 
1.38      www       104:     my $newmail='';
                    105:     if (&Apache::lonmsg::newmail()) { 
1.41      www       106:        $newmail=($textual?
                    107:  '<b><a href="/adm/communicate">You have new messages</a></b><br />':
1.40      www       108:                           'swmenu.setstatus("you have","messages");');
1.38      www       109:     }
1.40      www       110:     my $timesync=($textual?'':'swmenu.syncclock(1000*'.time.');');
1.41      www       111: # =============================================================================
                    112: # ============================ This is for URLs that actually can be registered
1.38      www       113:     if (($ENV{'REQUEST_URI'}!~/^\/(res\/)*adm\//) || ($forcereg)) {
1.40      www       114: # -- This applies to homework problems for users with grading privileges
1.38      www       115:         my $hwkadd='';
1.40      www       116:         if 
                    117:       ($ENV{'request.filename'}=~/\.(problem|exam|quiz|assess|survey|form)$/) {
1.38      www       118: 	    if (&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) {
1.40      www       119: 		$hwkadd.=&switch('','',7,1,'subm.gif','view sub','missions',
                    120:                        "gocmd('/adm/grades','submission')",
                    121: 		       'View user submissions for this assessment resource');
1.38      www       122:             }
                    123: 	    if (&Apache::lonnet::allowed('mgr',$ENV{'request.course.id'})) {
1.40      www       124: 		$hwkadd.=&switch('','',7,2,'pgrd.gif','problem','grades',
                    125:                        "gocmd('/adm/grades','gradingmenu')",
                    126:                        'Modify user grades for this assessment resource');
1.38      www       127:             }
                    128: 	    if (&Apache::lonnet::allowed('opa',$ENV{'request.course.id'})) {
1.40      www       129: 		$hwkadd.=&switch('','',7,3,'pparm.gif','problem','parms',
                    130:                        "gocmd('/adm/parmset','set')",
                    131:                        'Modify deadlines, etc, for this assessment resource');
1.38      www       132:             }
                    133: 	}
1.40      www       134: # -- End Homework
1.38      www       135:         ###
                    136:         ### Determine whether or not to display the 'cstr' button for this
                    137:         ### resource
                    138:         ###
                    139:         my $editbutton = '';
                    140:         if ($ENV{'user.author'}) {
                    141:             if ($ENV{'request.role'}=~/^(ca|au)/) {
                    142:                 # Set defaults for authors
                    143:                 my ($top,$bottom) = ('con-','struct');
                    144:                 my $action = "go('/priv/".$ENV{'user.name'}."');";
                    145:                 my $cadom  = $ENV{'request.role.domain'};
                    146:                 my $caname = $ENV{'user.name'};
                    147:                 my $desc = "Enter my resource construction space";
                    148:                 # Set defaults for co-authors
                    149:                 if ($ENV{'request.role'} =~ /^ca/) { 
                    150:                     ($cadom,$caname)=($ENV{'request.role'}=~/(\w+)\/(\w+)$/);
                    151:                     ($top,$bottom) = ('co con-','struct');
                    152:                     $action = "go('/priv/".$caname."');";
                    153:                     $desc = "Enter construction space as co-author";
                    154:                 }
                    155:                 # Check that we are on the correct machine
                    156:                 my $home = &Apache::lonnet::homeserver($caname,$cadom);
                    157:                 if ($home eq $Apache::lonnet::perlvar{'lonHostID'}) {
1.40      www       158:                     $editbutton=&switch
1.38      www       159:                         ('','',6,1,$top,,$bottom,$action,$desc);
                    160:                 }
                    161:             }
                    162:             ##
                    163:             ## Determine if user can edit url.
                    164:             ##
                    165:             my $cfile='';
                    166:             my $cfuname='';
                    167:             my $cfudom='';
                    168:             if ($ENV{'request.filename'}) {
                    169:                 my $file=&Apache::lonnet::declutter($ENV{'request.filename'});
                    170:                 $file=~s/^(\w+)\/(\w+)/\/priv\/$2/;
                    171:                 # Chech that the user has permission to edit this resource
                    172:                 ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$1);
                    173:                 if (defined($cfudom)) {
                    174:                     if (&Apache::lonnet::homeserver($cfuname,$cfudom) 
                    175:                         eq $Apache::lonnet::perlvar{'lonHostID'}) {
                    176:                         $cfile=$file;
                    177:                     }
                    178:                 }
                    179:             }        
                    180:             # Finally, turn the button on or off
                    181:             if ($cfile) {
1.40      www       182:                 $editbutton=&switch
1.38      www       183:                     ('','',6,1,'cstr.gif','edit','resource',
                    184:                      "go('".$cfile."');","Edit this resource");
                    185:             } elsif ($editbutton eq '') {
1.40      www       186:                 $editbutton=&clear(6,1);
1.38      www       187:             }
                    188:         }
                    189:         ###
                    190:         ###
1.41      www       191: # Prepare the rest of the buttons
                    192: 	my $menuitems=(<<ENDMENUITEMS);
                    193: c&3&1
                    194: s&2&1&back.gif&backward&&gopost('/adm/flip','back:'+currentURL)&Go to the previous resource in the course sequence&1
                    195: s&2&3&forw.gif&forward&&gopost('/adm/flip','forward:'+currentURL)&Go to the next resource in the course sequence&1
                    196: s&6&3&catalog.gif&catalog&info&catalog_info()&Show catalog information
                    197: s&8&1&eval.gif&evaluate&this&gopost('/adm/evaluate',currentURL)&Provide my evaluation of this resource
                    198: s&8&2&fdbk.gif&feedback&discuss&gopost('/adm/feedback',currentURL)&Provide feedback messages or contribute to the course discussion about this resource
                    199: s&8&3&prt.gif&prepare&printout&gopost('/adm/printout',currentURL)&Prepare a printable document
                    200: s&9&1&sbkm.gif&set&bookmark&set_bookmark()&Set a bookmark for this resource&2
                    201: s&9&2&vbkm.gif&view&bookmark&edit_bookmarks()&Use or edit my bookmark collection&2
                    202: s&9&3&anot.gif&anno-&tations&annotate()&Make notes and annotations about this resource&2
                    203: ENDMENUITEMS
                    204:         my $buttons='';
                    205:         foreach (split(/\n/,$menuitems)) {
                    206: 	    my ($command,@rest)=split(/\&/,$_);
                    207:             if ($command eq 's') {
                    208: 		$buttons.=&switch('','',@rest);
                    209:             } else {
                    210:                 $buttons.=&clear(@rest);
                    211:             }
                    212:         }
                    213:         if ($textual) {
                    214: # Registered, textual output
1.42      www       215:             my $utility=&utilityfunctions();
                    216:             my $form=&serverform();
1.41      www       217: 	    $result =(<<ENDREGTEXT);
1.42      www       218: <script>
                    219: // BEGIN LON-CAPA Internal
                    220: $utility
                    221: </script>
1.41      www       222: $timesync
                    223: $newmail
                    224: $buttons
                    225: $hwkadd
                    226: $editbutton
1.42      www       227: $form
                    228: <script>
                    229: //END LON-CAPA Internal
                    230: </script>
                    231: 
1.41      www       232: ENDREGTEXT
                    233: # Registered, graphical output
                    234:         } else {
                    235: 	    $result = (<<ENDREGTHIS);
1.38      www       236:      
                    237: <script language="JavaScript">
                    238: // BEGIN LON-CAPA Internal
1.42      www       239: var swmenu=null;
1.38      www       240: 
                    241:     function LONCAPAreg() {
                    242: 	  swmenu=$reopen;
                    243:           swmenu.clearTimeout(swmenu.menucltim);
                    244:           $timesync
                    245:           $newmail
1.41      www       246:           $buttons
1.38      www       247: 	  swmenu.currentURL=window.location.pathname;
                    248:           swmenu.reloadURL=window.location.pathname;
                    249:           swmenu.currentSymb="$ENV{'request.symb'}";
                    250:           swmenu.reloadSymb="$ENV{'request.symb'}";
                    251:           swmenu.currentStale=0;
                    252:           $hwkadd
                    253:           $editbutton
                    254:     }
                    255: 
                    256:     function LONCAPAstale() {
                    257: 	  swmenu=$reopen
                    258:           swmenu.currentStale=1;
                    259:           if (swmenu.reloadURL!='' && swmenu.reloadURL!= null) { 
                    260:              swmenu.switchbutton
                    261:              (3,1,'reload.gif','return','location','go(reloadURL)','Return to the last known location in the course sequence');
                    262: 	  }
                    263:           swmenu.clearbut(7,1);
                    264:           swmenu.clearbut(7,2);
                    265:           swmenu.clearbut(7,3);
                    266:           swmenu.menucltim=swmenu.setTimeout(
                    267:  'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+
                    268:  'clearbut(9,1);clearbut(9,2);clearbut(9,3);clearbut(6,3);clearbut(6,1)',
                    269: 			  2000);
                    270: 
                    271:       }
                    272: 
                    273: // END LON-CAPA Internal
                    274: </script>
                    275: ENDREGTHIS
1.41      www       276:         }
                    277: # =============================================================================
1.38      www       278:     } else {
1.41      www       279: # ========================================== This can or will not be registered
                    280:         if ($textual) {
                    281: # Not registered, textual
                    282: 	    $result= (<<ENDDONOTREGTEXT);
                    283: ENDDONOTREGTEXT
                    284:         } else {
                    285: # Not registered, graphical
                    286:            $result = (<<ENDDONOTREGTHIS);
1.38      www       287: 
                    288: <script language="JavaScript">
                    289: // BEGIN LON-CAPA Internal
1.42      www       290: var swmenu=null;
1.38      www       291: 
                    292:     function LONCAPAreg() {
                    293: 	  swmenu=$reopen
                    294:           $timesync
                    295:           swmenu.currentStale=1;
                    296:           swmenu.clearbut(2,1);
                    297:           swmenu.clearbut(2,3);
                    298:           swmenu.clearbut(8,1);
                    299:           swmenu.clearbut(8,2);
                    300:           swmenu.clearbut(8,3);
                    301:           if (swmenu.currentURL) {
                    302:              swmenu.switchbutton
                    303:               (3,1,'reload.gif','return','location','go(currentURL)');
                    304:  	  } else {
                    305: 	      swmenu.clearbut(3,1);
                    306:           }
                    307:     }
                    308: 
                    309:     function LONCAPAstale() {
                    310:     }
                    311: 
                    312: // END LON-CAPA Internal
                    313: </script>
                    314: ENDDONOTREGTHIS
1.41      www       315:        }
                    316: # =============================================================================
1.38      www       317:     }
                    318:     return $result;
                    319: }
                    320: 
                    321: sub loadevents() {
                    322:     return 'LONCAPAreg();';
                    323: }
                    324: 
                    325: sub unloadevents() {
                    326:     return 'LONCAPAstale();';
                    327: }
1.30      www       328: 
1.32      www       329: # ============================================================= Start up remote
                    330: 
                    331: sub startupremote {
                    332:     my ($lowerurl)=@_;
1.34      www       333:     if ($ENV{'browser.interface'} eq 'textual') {
                    334:      return ('<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.$lowerurl.'" />');
                    335:     }
1.32      www       336:     my $configmenu=&rawconfig();
                    337:     return(<<ENDREMOTESTARTUP);
                    338: <script>
                    339: 
1.35      www       340: function wheelswitch() {
                    341:    if (window.status=='|') { 
                    342:       window.status='/'; 
                    343:    } else {
                    344:       if (window.status=='/') {
                    345:          window.status='-';
                    346:       } else {
                    347:          if (window.status=='-') { 
                    348:             window.status='\\\\'; 
                    349:          } else {
                    350:             if (window.status=='\\\\') { window.status='|'; }
                    351:          }
                    352:       }
                    353:    } 
                    354: }
                    355: 
1.32      www       356: // ---------------------------------------------------------- The wait function
                    357: var canceltim;
                    358: function wait() {
                    359:    if ((menuloaded==1) || (tim==1)) {
1.35      www       360:       window.status='Done.';
1.32      www       361:       if (tim==0) {
                    362:          clearTimeout(canceltim);
                    363:          $configmenu
                    364:          window.location='$lowerurl';  
                    365:       } else {
1.35      www       366:          alert("Remote Control timed out. It is possible that it was blocked by pop-up window filters.");
1.32      www       367:       }
                    368:    } else {
1.35      www       369:       wheelswitch();
                    370:       setTimeout('wait();',200);
1.32      www       371:    }
                    372: }
                    373: 
                    374: function main() {
1.35      www       375:    canceltim=setTimeout('tim=1;',60000);
                    376:    window.status='-';
1.32      www       377:    wait();
                    378: }
                    379: 
                    380: </script>
                    381: ENDREMOTESTARTUP
                    382: }
                    383: 
                    384: sub setflags() {
                    385:     return(<<ENDSETFLAGS);
                    386: <script>
                    387:     menuloaded=0;
                    388:     tim=0;
                    389: </script>
                    390: ENDSETFLAGS
                    391: }
                    392: 
                    393: sub maincall() {
1.34      www       394:     if ($ENV{'browser.interface'} eq 'textual') { return ''; }
1.32      www       395:     return(<<ENDMAINCALL);
                    396: <script>
                    397:     main();
                    398: </script>
                    399: ENDMAINCALL
                    400: }
1.30      www       401: # ================================================================= Reopen menu
                    402: 
                    403: sub reopenmenu {
                    404:    my $nothing='';
1.34      www       405:    if ($ENV{'browser.interface'} eq 'textual') { return ''; }
1.30      www       406:    my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
                    407:    if ($ENV{'browser.type'} eq 'explorer') { $nothing='javascript:void(0);'; }
                    408:    return('window.open("'.$nothing.'","'.$menuname.'","",false);');
                    409: } 
                    410: 
1.1       www       411: # =============================================================== Open the menu
                    412: 
                    413: sub open {
1.22      www       414:     my $returnval='';
1.34      www       415:     if ($ENV{'browser.interface'} eq 'textual') { return ''; }
1.30      www       416:     my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
1.22      www       417:     unless (shift eq 'unix') {
                    418: # resizing does not work on linux because of virtual desktop sizes
                    419:        $returnval.=(<<ENDRESIZE);
                    420: if (window.screen) {
1.28      www       421:     self.resizeTo(screen.availWidth-215,screen.availHeight-55);
1.22      www       422:     self.moveTo(190,15);
                    423: }
                    424: ENDRESIZE
                    425:     }
                    426:     $returnval.=(<<ENDOPEN);
1.35      www       427: window.status='Opening LON-CAPA Remote Control';
1.30      www       428: var menu=window.open("/res/adm/pages/menu.html","$menuname",
1.14      www       429: "height=350,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5");
1.1       www       430: ENDOPEN
1.22      www       431:     return '<script>'.$returnval.'</script>';
1.1       www       432: }
                    433: 
1.2       www       434: 
                    435: # ================================================================== Raw Config
                    436: 
1.3       www       437: sub clear {
                    438:     my ($row,$col)=@_;
1.34      www       439:     unless ($ENV{'browser.interface'} eq 'textual') {
1.35      www       440:        return "\n".qq(window.status+='.';swmenu.clearbut($row,$col););
1.34      www       441:    } else { return ''; }
1.3       www       442: }
                    443: 
1.40      www       444: # ============================================ Switch a button or create a link
1.25      matthew   445: # Switch acts on the javascript that is executed when a button is clicked.  
                    446: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
1.40      www       447: 
1.2       www       448: sub switch {
1.40      www       449:     my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$nobreak)=@_;
1.2       www       450:     $act=~s/\$uname/$uname/g;
                    451:     $act=~s/\$udom/$udom/g;
1.34      www       452:     unless ($ENV{'browser.interface'} eq 'textual') {
                    453:        return "\n".
1.35      www       454:  qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
1.34      www       455:    } else {
1.41      www       456:        if ($nobreak==2) { return ''; }
1.34      www       457:        my $text=$top.' '.$bot;
                    458:        $text=~s/\- //;
1.42      www       459:        return "\n".($nobreak?' ':'<br />').
1.43      www       460:         '<a href="javascript:'.$act.';" target="_top">'.$text.'</a> '.
                    461:         ($nobreak?'':$desc);
1.34      www       462:    }
1.2       www       463: }
                    464: 
                    465: sub secondlevel {
                    466:     my $output='';
                    467:     my 
1.27      www       468:     ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc)=@_;
1.2       www       469:     if ($prt eq 'any') {
1.27      www       470: 	   $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.2       www       471:     } elsif ($prt=~/^r(\w+)/) {
                    472:         if ($rol eq $1) {
1.27      www       473:            $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.2       www       474:         }
                    475:     }
                    476:     return $output;
                    477: }
                    478: 
1.18      www       479: sub openmenu {
1.30      www       480:     my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
1.34      www       481:     if ($ENV{'browser.interface'} eq 'textual') { return ''; }
1.18      www       482:     if ($ENV{'browser.type'} eq 'explorer') {
1.30      www       483:        return "window.open('javascript:void(0);','".$menuname."');";
1.18      www       484:    } else {
1.30      www       485:        return "window.open('','".$menuname."');";
1.18      www       486:    }
                    487: }
                    488: 
1.2       www       489: sub rawconfig {
1.34      www       490:     my $textualoverride=shift;
                    491:     my $output='';
                    492:     unless ($ENV{'browser.interface'} eq 'textual') {
1.35      www       493:        $output.=
                    494:  "window.status='Opening Remote Control';var swmenu=".&openmenu().
                    495: "\nwindow.status='Configuring Remote Control ';";
1.34      www       496:     } else {
                    497:        unless ($textualoverride) { return ''; }
                    498:     }
1.2       www       499:     my $uname=$ENV{'user.name'};
                    500:     my $udom=$ENV{'user.domain'};
                    501:     my $adv=$ENV{'user.adv'};
1.4       www       502:     my $author=$ENV{'user.author'};
1.5       www       503:     my $crs='';
                    504:     if ($ENV{'request.course.id'}) {
                    505:        $crs='/'.$ENV{'request.course.id'};
1.7       www       506:        if ($ENV{'request.course.sec'}) {
                    507: 	   $crs.='_'.$ENV{'request.course.sec'};
                    508:        }
1.8       www       509:        $crs=~s/\_/\//g;
1.5       www       510:     }
1.2       www       511:     my $pub=($ENV{'request.state'} eq 'published');
                    512:     my $con=($ENV{'request.state'} eq 'construct');
                    513:     my $rol=$ENV{'request.role'};
1.25      matthew   514:     my $requested_domain = $ENV{'request.role.domain'};
1.13      harris41  515:     foreach (@desklines) {
1.27      www       516:         my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc)=split(/\:/,$_);
1.3       www       517:         $prt=~s/\$uname/$uname/g;
                    518:         $prt=~s/\$udom/$udom/g;
1.5       www       519:         $prt=~s/\$crs/$crs/g; 
1.25      matthew   520:         $prt=~s/\$requested_domain/$requested_domain/g;
1.3       www       521:         if ($pro eq 'clear') {
1.4       www       522: 	    $output.=&clear($row,$col);
1.3       www       523:         } elsif ($pro eq 'any') {
1.2       www       524:                $output.=&secondlevel(
1.27      www       525: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
1.2       www       526: 	} elsif ($pro eq 'smp') {
                    527:             unless ($adv) {
                    528:                $output.=&secondlevel(
1.27      www       529:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
1.2       www       530:             }
                    531:         } elsif ($pro eq 'adv') {
                    532:             if ($adv) {
                    533:                $output.=&secondlevel(
1.27      www       534: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
1.2       www       535:             }
                    536:         } elsif (($pro=~/p(\w+)/) && ($prt)) {
                    537: 	    if (&Apache::lonnet::allowed($1,$prt)) {
1.27      www       538:                $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.4       www       539:             }
1.26      www       540:         } elsif ($pro eq 'course') {
                    541:             if ($ENV{'request.course.fn'}) {
1.27      www       542:                $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.26      www       543: 	    }
1.4       www       544:         } elsif ($pro eq 'author') {
                    545:             if ($author) {
1.29      matthew   546:                 if ((($prt eq 'rca') && ($ENV{'request.role'}=~/^ca/)) ||
                    547:                     (($prt eq 'rau') && ($ENV{'request.role'}=~/^au/))) {
1.19      matthew   548:                     # Check that we are on the correct machine
1.29      matthew   549:                     my $cadom=$requested_domain;
                    550:                     my $caname=$ENV{'user.name'};
                    551:                     if ($prt eq 'rca') {
                    552: 		       ($cadom,$caname)=
1.6       www       553:                                ($ENV{'request.role'}=~/(\w+)\/(\w+)$/);
1.29      matthew   554:                     }                       
                    555:                     $act =~ s/\$caname/$caname/g;
1.19      matthew   556:                     my $home = &Apache::lonnet::homeserver($caname,$cadom);
1.32      www       557:                     if ($home eq $Apache::lonnet::perlvar{'lonHostID'}) {
1.19      matthew   558:                         $output.=switch($caname,$cadom,
1.27      www       559:                                         $row,$col,$img,$top,$bot,$act,$desc);
1.19      matthew   560:                     }
1.6       www       561:                 }
1.2       www       562:             }
                    563:         }
1.13      harris41  564:     }
1.34      www       565:     unless ($ENV{'browser.interface'} eq 'textual') {
1.35      www       566:        $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
1.34      www       567:     }
1.2       www       568:     return $output;
                    569: }
                    570: 
                    571: # ======================================================================= Close
1.1       www       572: 
                    573: sub close {
1.35      www       574:     if ($ENV{'browser.interface'} eq 'textual') { return ''; }
1.30      www       575:     my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
1.1       www       576:     return(<<ENDCLOSE);
                    577: <script>
1.35      www       578: window.status='Accessing Remote Control';
1.30      www       579: menu=window.open("/adm/rat/empty.html","$menuname",
1.1       www       580:                  "height=350,width=150,scrollbars=no,menubar=no");
1.35      www       581: window.status='Disabling Remote Control';
                    582: menu.active=0;
1.31      www       583: menu.autologout=0;
1.35      www       584: window.status='Closing Remote Control';
1.1       www       585: menu.close();
1.35      www       586: window.status='Done.';
1.1       www       587: </script>
                    588: ENDCLOSE
                    589: }
                    590: 
                    591: # ====================================================================== Footer
                    592: 
                    593: sub footer {
                    594: 
1.33      www       595: }
                    596: 
1.42      www       597: sub utilityfunctions {
                    598:     unless ($ENV{'browser.interface'} eq 'textual') { return ''; }
                    599:     my $currenturl=$ENV{'REQUEST_URI'};
                    600:     my $currentsymb=$ENV{'request.symb'};
                    601: return (<<ENDUTILITY)
                    602: 
                    603:     var currentURL="$currenturl";
                    604:     var reloadURL="$currenturl";
                    605:     var currentSymb="$currentsymb";
                    606: 
                    607: function go(url) {
                    608:    if (url!='' && url!= null) {
                    609:        currentURL = null;
                    610:        currentSymb= null;
                    611:        window.location.href=url;
                    612:    }
                    613: }
                    614: 
                    615: function gopost(url,postdata) {
                    616:    if (url!='') {
                    617:       this.document.server.action=url;
                    618:       this.document.server.postdata.value=postdata;
                    619:       this.document.server.command.value='';
                    620:       this.document.server.url.value='';
                    621:       this.document.server.symb.value='';
                    622:       this.document.server.submit();
                    623:    }
                    624: }
                    625: 
                    626: function gocmd(url,cmd) {
                    627:    if (url!='') {
                    628:       this.document.server.action=url;
                    629:       this.document.server.postdata.value='';
                    630:       this.document.server.command.value=cmd;
                    631:       this.document.server.url.value=currentURL;
                    632:       this.document.server.symb.value=currentSymb;
                    633:       this.document.server.submit();
                    634:    }
                    635: }
                    636: ENDUTILITY
                    637: }
                    638: 
                    639: sub serverform {
                    640:     return(<<ENDSERVERFORM);
                    641: 
                    642: <form name="server" action="/adm/logout" method="post">
                    643: <input type="hidden" name="postdata" value="none" />
                    644: <input type="hidden" name="command" value="none" />
                    645: <input type="hidden" name="url" value="none" />
                    646: <input type="hidden" name="symb" value="none" />
                    647: </form>
                    648: ENDSERVERFORM
                    649: }
1.33      www       650: # ================================================ Handler when called directly
                    651: 
                    652: 
                    653: sub handler {
                    654:     my $r = shift;
                    655:     $r->content_type('text/html');
                    656:     $r->send_http_header;
                    657:     return OK if $r->header_only;
                    658: 
1.42      www       659:     my $utility=&utilityfunctions();
                    660:     my $form=&serverform();
1.34      www       661:     my $bodytag=&Apache::loncommon::bodytag('Main Menu');
1.33      www       662: # ------------------------------------------------------------ Print the screen
1.36      www       663:     $r->print(<<ENDHEADER);
                    664: <html><head>
                    665: <title>LON-CAPA Main Menu</title>
                    666: <script>
1.42      www       667: $utility
1.36      www       668: </script>
                    669: </head>
                    670: $bodytag
                    671: ENDHEADER
1.42      www       672:     $r->print(&rawconfig(1).$form);
1.33      www       673:     $r->print('</body></html>');
                    674:     return OK;
1.1       www       675: }
                    676: 
1.2       www       677: # ================================================================ Main Program
                    678: 
1.16      harris41  679: BEGIN {
1.15      matthew   680:   if (! defined($readdesk)) {
1.14      www       681:    {
1.10      albertel  682:     my $config=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
                    683: 				  '/mydesk.tab');
                    684:     while (my $configline=<$config>) {
1.14      www       685:        $configline=(split(/\#/,$configline))[0];
                    686:        $configline=~s/^\s+//;
1.10      albertel  687:        chomp($configline);
1.14      www       688:        if ($configline) {
                    689:           $desklines[$#desklines+1]=$configline;
                    690:        }
1.2       www       691:     }
1.14      www       692:    }
                    693:    $readdesk='done';
1.10      albertel  694:   }
1.2       www       695: }
1.30      www       696: 
1.1       www       697: 1;
                    698: __END__
                    699: 
                    700: 
                    701: 
                    702: 
                    703: 
                    704: 
                    705: 

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