<?php 
function validate_email($val) 
{ 
	if($val != "") 
	{ 
		if (preg_match('/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!\.)){0,61}[a-zA-Z0-9_-]?\.)+[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!$)){0,61}[a-zA-Z0-9_]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/', $val))
		{
			return true;
		}
		else
		{
			return false;
		}	
	} 
	else 
	{ 
		return false; 
	} 
} 

function errorMessage($error)
{
	if (!empty($error))
	{
		
			echo "<table id='error' border='0' cellspacing='0' cellpadding='10'>
			  <tr>
			  <td align='left'>
			  $error<br />
				
				</td>
				</tr>
    		</table>";
	}
}

function left($string, $chars)
{
	if (strlen($string) > $chars)
	{
		return substr ( $string, 0, $chars ) . '...';
	}
	else
	{
		return $string;
	}
}

function dl_file($content){

	//Begin writing headers
    header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Cache-Control: public");
    header("Content-Description: File Transfer");
   
    //Use the switch-generated Content-Type
    header("Content-Type: application/force-download");

    //Force the download
    $header="Content-Disposition: inline; filename=campaign.report.html;";
    header($header);
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: ".strlen($content));
    echo $content;
    exit;
}
?>