<?php
# ---------------------------------------------------------------------
# truc is a tool for requirement and use case tracking
# Copyright (C) 2006 ASDIS - http://sf.net/projects/truc
#
# (rth) Initial truc version based on rth
#       Copyright (C) 2005 George Holbrook - rth@lists.sourceforge.net
#
# This program is distributed under the terms and conditions of the GPL
# See the README and LICENSE files for details
#----------------------------------------------------------------------

include"./api/include_api.php";

$switch_project 	= $_POST['login']['switch_project'];
$redirect_page		= $_POST['login']['page'];
$redirect_page_get	= $_POST['login']['get'];

if( isset( $_POST['uname'] ) ) {
    $username = $_POST['uname'];
} else {
    $username = '';
}

if( isset( $_POST['pword'] ) ) {
    $password = $_POST['pword'];
} else {
    $password = '';
}

auth_attempt_login($username, $password);

# save login
if( isset( $_POST['save_login'] ) ) {
	auth_set_login_cookies($username, $password);
}

# check for javascript
if( isset( $_POST['non_javascript_browser'] ) ) {
	session_set_javascript_enabled(false);
} else {
	session_set_javascript_enabled(true);
}

# if switch_project is not empty then switch project
if( !empty( $switch_project ) ) {

	include"login_switch_proj.php";

# else redirect to the appropriate page
} else {

	if( empty( $redirect_page ) ) {

		html_redirect("home_page.php");
	} else {

		html_redirect( $redirect_page."?".$redirect_page_get );
	}
}
?>