<?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
#----------------------------------------------------------------------

$redirect_page 	= basename( $_SERVER['PHP_SELF'] );
$username		= $_COOKIE[USER_COOKIE_NAME];
$project_name	= "";
$get 			= "";

# get the query string and remove the invalid login error message
# if it is part of the query string
if( !empty($_SERVER['QUERY_STRING']) ) {

	$get = $_SERVER['QUERY_STRING'];
	$get = preg_replace("/&failed=true&error=10/", "", $get);
}

# if project_id set in the url get the project name for switching to the project
if( !empty($_GET['project_id']) ) {

	$project_name = project_get_name($_GET['project_id']);
}

if( !empty($_GET['page']) ) {

	$redirect_page = $_GET['page'];
}

# Prevent getting redirected to a login_ page
if( strpos($redirect_page, 'login', 0)===0 ) {

	$redirect_page = "";
}

html_window_title();
html_print_body("login", "pword");
html_page_title(lang_get('login_page') . PAGE_TITLE);

error_report_check( $_GET );

print"<div align=center>\n";
print"<table class=width40>\n";
print"<tr>\n";
print"<td>\n";
print"<form name=login action='login_validate.php' method=post>\n";
print"<input type=hidden name=uname value='$username'>\n";

# login variables taken from the query string
print"<input type=hidden name=login[switch_project] value='$project_name'>\n";
print"<input type=hidden name=login[page] value='$redirect_page'>\n";
print"<input type=hidden name=login[get] value='$get'>\n";

# Check for Javascript
print"<noscript>\n";
print"<input type=hidden name=javascript_disabled value=true>\n";
print"</noscript>\n";

print"<table class=inner>\n";

# Form Title
print"<tr>\n";
print"<td colspan=3 class=form-header-l>" . lang_get('confirm_password') ."</td>";
print"</tr>\n";

# Spacer
print"<tr>\n";
print"<td colspan=3 class=form-header-l>&nbsp;</td>";
print"</tr>\n";


# User Name Text Box
print"<tr>\n";
print"<td class=form-lbl-r>". lang_get('username') ."</td>\n";
print"<td>&nbsp;</td>\n";
print"<td class=left>$username</td>\n";
print"</tr>\n";

# Password Text Box
print"<tr>\n";
print"<td class=form-lbl-r>". lang_get('password') ."</td>\n";
print"<td>&nbsp;</td>\n";
print"<td class=left>\n";
print"<input type=password name=pword size=15></td>\n";
print"</tr>\n";

# Login Button
print"<tr>\n";
print"<td colspan=3 class=center><input type='submit' value=". lang_get('submit_btn') ."></td>\n";
print"</tr>\n";

print"</table>\n";
print"</form>\n";
print"</td>\n";
print"</tr>\n";
print"</table>\n";

print"<br>\n";
print"If this is not your username, click <a href=logout.php>here</a> to login under a different username.";

print"</div>\n";

html_print_footer();
?>