Location: PHPKode > projects > WB News > includes/filter.php
<?php

/*========================================================*\
||########################################################||
||#                                                      #||
||#     WB News v2.0.0                                   #||
||# ---------------------------------------------------- #||
||#     Copyright (c) 2004-2007                          #||
||#     Created: 23rd April 2007                         #||
||#     Filename: filter.php                             #||
||#                                                      #||
||########################################################||
/*========================================================*/

/**
 *  @author $Author: pmcilwaine $
 *	@version $Id: filter.php,v 1.1.2.1 2008/02/03 09:46:21 pmcilwaine Exp $
 */

$f_tmpl = new TemplateEngine( BuildPath( "admin/filter.ihtml" ), FALSE );
$f_tmpl->AddParam( "caption", $params["caption"] );
$formdata =& $f_tmpl->AddParam( "formdata", array() );
$labels =& $f_tmpl->AddParam( "labels", array() );
$fields =& $f_tmpl->AddParam( "fields", array() );

foreach ( $params["fields"] as $name => $field )
{
	$labels[] = $field["heading"];
	$fields[] = array(
		"name" => $name,
		"type" => $field["type"]
		);
	$formdata[$name] = NULL;
}

if ( $_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["form"]) && $_POST["form"] == $params["index"] )
{

	switch ( Submit() )
	{
	case "Ok" :

		$sess_fields = array();
		foreach ( $fields as $field )
		{
			switch ( $field["type"] )
			{
			case "text" :
				if ( "" != $_POST[$field["name"]] )
				{
					$sess_fields[$field["name"]] = sanitize_post( $field["name"] );
				}
				break;
			case "daterange" :
				if ( "" != $_POST[$field["name"]][0] )
				{
					$sess_fields[$field["name"]][0] = sanitize_post( 0, NULL, $_POST[$field["name"]] );
				}
				if ( "" != $_POST[$field["name"]][1] )
				{
					$sess_fields[$field["name"]][1] = sanitize_post( 1, NULL, $_POST[$field["name"]] );
				}
				break;
			}
		}

		if ( count($sess_fields) > 0 )
		{
			$_SESSION[$params["index"]] = $sess_fields;
		}
		
		break;
	case "Reset" :
		unset( $_SESSION[$params["index"]] );
		break;
	}

}

$formdata["hidden"] = array(
	"form" => $params["index"]
	);

$f_tmpl->AddParam( "buttons", "Ok" );

if ( isset($_SESSION[$params["index"]]) )
{
	$sess_filter[$params["index"]] = $_SESSION[$params["index"]];
	
	foreach ( $fields as $field )
	{
		if ( isset($sess_filter[$params["index"]][$field["name"]]) )
		{
			switch ( $field["type"] )
			{
			case "text" :
				$formdata[$field["name"]] =  sanitize_post_html( $field["name"], NULL, $_SESSION[$params["index"]] );
				break;
			case "daterange" :
				$formdata[$field["name"]][0] =  sanitize_post_html( 0, NULL, $_SESSION[$params["index"]][$field["name"]] );
				$formdata[$field["name"]][1] =  sanitize_post_html( 1, NULL, $_SESSION[$params["index"]][$field["name"]] );
				break;
			}
		}
	}
	$f_tmpl->AddParam( "buttons", "Reset,Ok" );
}

return $f_tmpl->GetHTML();

?>
Return current item: WB News