<?php
////////////////////////////////////////////////////////////////////////
// Breeze Website Builder
// Copyright Silver Dolphin Solutions, LLC, Edward Lemmers, P.E.
// For licensing, see license.txt.
// Created:	3/9/2013	ELL

// Process HTML message.
$msg_arr = explode("[IF]", $html_msg);
if (count($msg_arr) > 1)
{
	$msg = $msg_arr[0];
	$if_cnt = count($msg_arr) - 1;
	for ($i = 0; $i < $if_cnt; $i++)
	{
		if ($i > 0)
		{
			$start_msg_str = explode("[ENDIF]", $msg_arr[$i]);
			$msg .= $start_msg_str[1];
		}
		$if_arr = explode("[ENDIF]", $msg_arr[$i + 1]);
		$if_str = $if_arr[0];
		if (strpos($if_str, "[EQ]") !== false)
		{
			$comp_arr = explode("[EQ]", $if_str);
			$echo_arr = explode("[ECHO]", $comp_arr[1]);
			$post_var_placeholder = trim($comp_arr[0]);
			$post_var_key = $user_defined_placeholders[$post_var_placeholder];
			if ($_POST[$post_var_key] == trim($echo_arr[0]))
				$msg .= str_replace($post_var_placeholder, $_POST[$post_var_key], $echo_arr[1]);
		}
		elseif (strpos($if_str, "[NE]") !== false)
		{
			$comp_arr = explode("[NE]", $if_str);
			$echo_arr = explode("[ECHO]", $comp_arr[1]);
			$post_var_placeholder = trim($comp_arr[0]);
			$post_var_key = $user_defined_placeholders[$post_var_placeholder];
			if ($_POST[$post_var_key] != trim($echo_arr[0]))
				$msg .= str_replace($post_var_placeholder, $_POST[$post_var_key], $echo_arr[1]);
		}
		elseif (strpos($if_str, "[GT]") !== false)
		{
			$comp_arr = explode("[GT]", $if_str);
			$echo_arr = explode("[ECHO]", $comp_arr[1]);
			$post_var_placeholder = trim($comp_arr[0]);
			$post_var_key = $user_defined_placeholders[$post_var_placeholder];
			if ($_POST[$post_var_key] > trim($echo_arr[0]))
				$msg .= str_replace($post_var_placeholder, $_POST[$post_var_key], $echo_arr[1]);
		}
		elseif (strpos($if_str, "[LT]") !== false)
		{
			$comp_arr = explode("[LT]", $if_str);
			$echo_arr = explode("[ECHO]", $comp_arr[1]);
			$post_var_placeholder = trim($comp_arr[0]);
			$post_var_key = $user_defined_placeholders[$post_var_placeholder];
			if ($_POST[$post_var_key] < trim($echo_arr[0]))
				$msg .= str_replace($post_var_placeholder, $_POST[$post_var_key], $echo_arr[1]);
		}
	}
	$end_msg_arr = explode("[ENDIF]", $msg_arr[$if_cnt]);
	$msg .= $end_msg_arr[1];
	
	$html_msg = $msg;
}
		
?>