/*
 * $Id: ActiveUserListAction.java,v 1.12 2006/10/04 03:15:00 marbobo Exp $
 *
 * Copyright (c) Siemens AG 2008 
 *           (c) Universität Paderborn 2008 
 * Licensed under EUPL 1.1. 
 *
 * $Log: ActiveUserListAction.java,v $
 * Revision 1.12  2006/10/04 03:15:00  marbobo
 * + Vollständige Unterstützung für Templates implementiert
 * + Alles von Virtoweb auf ProCoBa umgestellt
 *
 * Revision 1.11  2005/02/14 14:01:45  bigmac
 * Applikationsweites CSS konfigurierbar gemacht + Refactorings
 *
 * Revision 1.10  2005/02/10 17:42:02  marbobo
 * + Forward-Path korrigiert
 *
 * Revision 1.9  2005/02/10 16:28:33  bigmac
 * Forwards angepasst
 *
 * Revision 1.8  2004/09/16 13:07:29  marbobo
 * + Eventhandling umgestellt
 *
 * Revision 1.7  2004/03/30 20:31:25  marbobo
 * Unbenutzte Variablen entsorgt
 *
 * Revision 1.6  2003/11/21 14:19:46  bigmac
 * Usertracking erweitert
 *
 * Revision 1.5  2003/11/05 15:59:08  marbobo
 * Bugfix
 *
 *
 */
 
package vkc.administration.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import vkc.administration.form.ActiveUserListForm;
import vkc.db.entities.VKCUser;
import vkc.view.WebShare;

public class ActiveUserListAction extends Action {

	private ActionForward DEFAULT_FORWARD = 
		new ActionForward( "/templates/${template.name}/administration/activeUserList.jsp", false );

    private ActionForward INFO_FORWARD = 
		new ActionForward( "/templates/${template.name}/common/InfoPage.jsp" );

	public ActionForward execute( ActionMapping mapping, 
								  ActionForm f,
								  HttpServletRequest request, 
								  HttpServletResponse response )
		throws JspException {
		ActiveUserListForm form = (ActiveUserListForm)f;
		VKCUser user = form.getUser();

		if ( !user.hasAdminPrivileges() ) {
			request.setAttribute( WebShare.INFO_KEY, "vkc.info.access_denied" );
			
			return INFO_FORWARD;
		}
		
		if ( request.getParameter( "action.show.sessionids" ) != null ) {
			return handleShowSessionIdsAction( form, request );
		}

		if ( request.getParameter( "action.hide.sessionids" ) != null ) {
			return handleHideSessionIdsAction( form, request );
		}

		return DEFAULT_FORWARD;
	}

    private ActionForward handleHideSessionIdsAction( ActiveUserListForm form, HttpServletRequest request ) {
        form.setSessionIdsVisible( false );
        
        return DEFAULT_FORWARD;
    }

    private ActionForward handleShowSessionIdsAction( ActiveUserListForm form, HttpServletRequest request ) {
        form.setSessionIdsVisible( true );
        
        return DEFAULT_FORWARD;
    }
}