File:  [LON-CAPA] / loncom / auth / lonlogout.pm
Revision 1.30: download - view: text, annotated - select for diffs
Wed Apr 2 12:29:38 2008 UTC (16 years, 3 months ago) by bisitz
Branches: MAIN
CVS tags: version_2_6_X, version_2_6_3, HEAD
Localization:
Optimized mt/lt calls for logout screen

    1: # The LearningOnline Network
    2: # Logout Handler
    3: #
    4: # $Id: lonlogout.pm,v 1.30 2008/04/02 12:29:38 bisitz 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: package Apache::lonlogout;
   30: 
   31: use strict;
   32: use Apache::Constants qw(:common);
   33: use Apache::File;
   34: use Apache::lonnet;
   35: use Apache::lonmenu;
   36: use CGI::Cookie();
   37: use Apache::lonlocal;
   38: 
   39: sub handler {
   40:     my $r = shift;
   41: 
   42:     #Check for cookie
   43:     my $requrl=$r->uri;
   44:     my $handle = &Apache::lonnet::check_for_valid_session($r);
   45:     #check if cookie still valid
   46:     if ($handle eq '') {
   47: 	$r->log_reason("Cookie $handle not valid", $r->filename); 
   48: 	return FORBIDDEN;
   49:     }
   50: 
   51:     #we've got a valid user
   52:     my @profile;
   53:     my $lonidsdir=$r->dir_config('lonIDsDir');
   54:     &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
   55:     unlink("$lonidsdir/$handle.id");
   56:     my %temp=('logout' => time);
   57:     &Apache::lonnet::put('email_status',\%temp);
   58:     &Apache::lonnet::log($env{'user.domain'},
   59: 			 $env{'user.name'},
   60: 			 $env{'user.home'},
   61: 			 "Logout $ENV{'REMOTE_ADDR'}");
   62: 
   63:     &Apache::loncommon::content_type($r,'text/html');
   64: 
   65:     #expire the cookie
   66:     my $c = new CGI::Cookie(-name    => 'lonID',
   67: 			    -value   => '',
   68: 			    -expires => '-10y',);
   69:     $r->header_out('Set-cookie' => $c);
   70: 
   71:     $r->send_http_header;
   72:     return OK if $r->header_only;
   73: # -------------------------------------------------------- Menu script and info
   74: 
   75:     my $windowinfo=&Apache::lonmenu::close();
   76:     $windowinfo.=&Apache::lonnavmaps::close();
   77: # ---------------------------------------------------------------- Get handover
   78:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['handover']);
   79:     my $switch='';
   80:     my $start_page='';
   81:     my $relogmessage='';
   82:     if ($env{'form.handover'}) {
   83: 	$switch='<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.
   84: 	    $env{'form.handover'}.'">';
   85: 	$start_page=&Apache::loncommon::start_page('Switching Server ...',
   86: 						   $switch);
   87:     } else {
   88: 	$start_page=&Apache::loncommon::start_page('Logged Out',undef,
   89: 						   {'no_inline_link' => 1,});
   90: 	
   91: 	$relogmessage.='<h1>'.&mt('Goodbye').'</h1>';
   92: 
   93: 	if (!$env{'request.sso.norelogin'}) {
   94: 	    my $relogin_server;
   95: 	    if ($env{'request.sso.reloginserver'}) {
   96: 		$relogin_server = $env{'request.sso.reloginserver'};
   97: 	    }
   98: 	    my $login_url = $relogin_server.'/adm/'.
   99: 		($env{'request.sso.login'} ? 'roles': 'login');
  100: 
  101: 	    $relogmessage.=&mt('Please either [_1]close this window[_2] or [_3]log in again[_4].'
  102:                               ,'<a href="javascript:self.close();">','</a>'
  103:                               ,'<a href="'.$login_url.'?domain='.$env{'user.domain'}.'">','</a>');
  104:         }
  105: 	my $domain = $env{'user.domain'};
  106:         if ($env{'request.sso.login'}
  107: 	    && defined($r->dir_config("lonSSOUserLogoutMessageFile_$domain"))) {
  108: 	    open(my $fh,$r->dir_config("lonSSOUserLogoutMessageFile_$domain"));
  109: 	    $relogmessage.= join('',<$fh>);
  110: 	}
  111: 	if ($env{'request.sso.login'}
  112: 	    && defined($r->dir_config('lonSSOUserLogoutMessageFile'))) {
  113: 	    open(my $fh,$r->dir_config('lonSSOUserLogoutMessageFile'));
  114: 	    $relogmessage.= join('',<$fh>);
  115: 	}
  116: 
  117:     }
  118:     my $end_page=&Apache::loncommon::end_page();
  119: # --------------------------------------------------------------- Screen Output
  120:     $r->print(<<ENDDOCUMENT);
  121: $start_page
  122: $windowinfo
  123: $relogmessage
  124: $end_page
  125: ENDDOCUMENT
  126:     $r->register_cleanup(\&flush_course_logs);
  127:     return OK; 
  128: }
  129: 
  130: sub flush_course_logs {
  131:     &Apache::lonnet::flushcourselogs();
  132:     return OK;
  133: }
  134: 
  135: 1;
  136: __END__
  137: 
  138: 
  139: 
  140: 
  141: 
  142: 
  143: 
  144: 

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