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

if( isset($_POST['submit_button']) ) {

	require_once("requirement_notification_action.php");
	exit;
}

include"./api/include_api.php";
auth_authenticate_user();

$page                   = basename(__FILE__);
$action_page            = 'requirement_action.php';
$project_properties     = session_get_project_properties();
$project_name           = $project_properties['project_name'];
$project_id				= $project_properties['project_id'];
$s_user_properties		= session_get_user_properties();
$user_id				= $s_user_properties['user_id'];
$row_style				= '';
$records 				= "";

session_records(	"requirements_notification",
					user_requirement_notifications($project_id, $user_id) );

$order_by			= REQ_FILENAME;
$order_dir			= "ASC";
$page_number 		= 1;

util_set_order_by($order_by, $_POST);
util_set_order_dir($order_dir, $_POST);
util_set_page_number($page_number, $_POST);

html_window_title();
html_print_body();
html_page_title($project_name ." - ". lang_get('req_notifications'));
html_page_header( $db, $project_name );
html_print_menu();
requirement_menu_print($page);

error_report_check( $_GET );

print"<br>\n";

print"<form action='$page' method=post name=requirements>\n";

print"<div align=center>\n";
print"<table class=hide60>\n";
print"<tr>\n";
print"<td>\n";
$rows_requirement = requirement_get($project_id, $page_number, $order_by, $order_dir,
						"", "", "", "", "", "latest", $per_page=RECORDS_PER_PAGE_REQUIREMENT_NOTIFICATIONS, "", "");
print"<input type=hidden name='order_dir' value='$order_dir'>";
print"<input type=hidden name='order_by' value='$order_by'>";
print"</td>\n";
print"</tr>\n";
print"</table>\n";
print"</div>\n";

################################################################################
# Testset table

if($rows_requirement) {

	print"<div align=center>\n";
	print"<table class=width60 rules=cols>\n";

	# Table headers
	print"<tr class=tbl_header>\n";
	html_tbl_print_header( "email" );
	html_tbl_print_header( lang_get('req_id'), REQ_ID, $order_by, $order_dir );
	html_tbl_print_header( lang_get('req_name'), REQ_FILENAME, $order_by, $order_dir );
	print"</tr>\n";

	foreach($rows_requirement as $row_requirement) {

		$req_id		= $row_requirement[REQ_ID];
		$req_name	= $row_requirement[REQ_FILENAME];

		if( empty($records) ) {
			$records = $row_requirement[REQ_ID]." => ''";
		} else {
			$records .= ", ".$row_requirement[REQ_ID]." => ''";
		}

		$row_style = html_tbl_alternate_bgcolor($row_style);

		# Rows
		print"<tr class='$row_style'>\n";
		if( session_records_ischecked("requirements_notification", $req_id) ) {
			print"<td><input type=checkbox name=row_$req_id value='' checked></td>\n";
		} else {
			print"<td><input type=checkbox name=row_$req_id value=''></td>\n";
		}
		print"<td class='tbl-1'>".util_pad_id($req_id)."</td>\n";
		print"<td class='tbl-l'>$req_name</td>\n";
		print"</tr>\n";
	}

	print"</table>\n";
	print"</div>\n";

	print"<div align=center>\n";
	print"<table class=hide60>\n";
	print"<tr>\n";
	print"<td align=left>\n";
	if( session_use_javascript() ) {
		print"<input id=select_all type=checkbox name=thispage onClick='checkAll( this )'>\n";
		print"<label for=select_all>".lang_get("select_all")."</label>";
		print"&nbsp;\n";
	}
	print"</td>\n";
	print"</tr>\n";
	print"</table>\n";
	print"</div>\n";

	print"<br>\n";

	print"<div align=center>\n";
	print"<input type=hidden name=records value=\"$records\">\n";
	print"<input type=submit name=submit_button value='".lang_get("change")."'>";
	print"</div>\n";
} else {

	print lang_get("no_requirements");
}

print"</form>\n";

html_print_footer();
?>