Location: PHPKode > projects > eBlog > contact.php
<?php

/**************************************************************************
 *                                                                        *
 *                                                                        *
 *         Solution: eBlog                                                *
 *          Release: 1.7                                                  *
 *             File: contact.php                                          *
 *               By: Emuci inc.                                           *
 *          Website: http://www.emuci.com                                 *
 *        Copyright: (C) 2010 Emcui inc.                                  *
 *                                                                        *
 *                                                                        *
 **************************************************************************
 *                                                                        *
 *                                                                        *
 *   This script is NOT freeware and is subjected to Emuci terms of use   *
 *   located in the docs folder.                                          *
 *                                                                        *
 *                                                                        *
 *************************************************************************/



include_once 'includes/global.php';

$action = $_GET['action'];
$id = $_GET['id'];

if(empty($action))
$action = "main";
		
$defaultTemplate = $template;
$copyrights = "&copy; " . date("Y") . " " . $lang_admin_globalRights1;

// 1: Main View
if($action == "main"){
	
	$tree_map = $lang_blog_emailMe;	
	
	$conn = mysql_connect($dbhost, $dbuser, $dbpass);
	mysql_select_db($dbname);
	
	$random = rand(18989, 99999);
	$countries_list = "<select name=\"location\">";
	$query  = "SELECT id, name FROM eblog_countries";
	$result = mysql_query($query);
	while($row = mysql_fetch_array($result, MYSQL_ASSOC))
	{
		$ThisRowID = $row['id'];
		$ThisRowName = $row['name'];
		
		if($ThisRowID == $location)
		{
		$countries_list = $countries_list . "<option value=\"$ThisRowID\" SELECTED>$ThisRowName</option>";
		}
		else
		{
		$countries_list = $countries_list . "<option value=\"$ThisRowID\">$ThisRowName</option>";
		}	
	}
	$countries_list = $countries_list . "</select>";	
	
	mysql_close($conn);		
		
	$static_value = array ($blog_dir, $lang_blog_form_name, $lang_blog_form_country, $countries_list,$lang_blog_form_email,$lang_blog_form_title,$lang_blog_form_comment,$lang_blog_form_cc,$random,$lang_blog_submit, $blog_windows_encoding, $lang_erorr_code149, $lang_erorr_code150, $lang_erorr_code151, $lang_erorr_code154, $lang_erorr_code155, $lang_erorr_code156);
	$static_name = array ("{blog_dir}","{lang_blog_form_name}", "{lang_blog_form_country}","{countries_list}","{lang_blog_form_email}", "{lang_blog_form_title}", "{lang_blog_form_comment}" , "{lang_blog_form_cc}","{random}","{lang_blog_submit}", "{blog_windows_encoding}", "{lang_erorr_code149}", "{lang_erorr_code150}", "{lang_erorr_code151}", "{lang_erorr_code154}", "{lang_erorr_code155}","{lang_erorr_code156}");
	$file = $new_template->load_template ("templates/$defaultTemplate/contact.html");
	$template = $new_template->replace_static($static_name, $static_value, $file);
	
	if($popup < 1){
	
		$static_value = array ($lang_blog_secionsList, $sections_list);
		$static_name = array ("{lang_blog_secionsList}","{sections_list}");
		$file = $new_template->load_template ("templates/$defaultTemplate/sideMenu.html");
		$side_menu = $new_template->replace_static($static_name, $static_value, $file);
	
		$static_value = array (
								$blog_windows_encoding, $blog_slogan, $lang_blog_search, $lang_blog_recentTopics,
							    $tree_map, $css, $side_menu,$template, $blog_dir, $blog_name,
							    $meta, $social_networks, $copyrights, $lang_blog_emailMe, $lang_blog_joinMyMainingList,
							    $lang_blog_MyFriends, $lang_blog_visitors, $visitors,$popupDefine, $blog_windows_encoding
							  );
							  
							  
		$static_name  = array (
							   "{blog_windows_encoding}", "{blog_slogan}","{lang_blog_search}", "{lang_blog_recentTopics}",
							   "{tree_map}", "{css}", "{side_menu}", "{page_content}", "{blog_dir}", "{blog_name}",
							   "{meta}", "{social_networks}", "{copyrights}", "{lang_blog_emailMe}", "{lang_blog_joinMyMainingList}",
							   "{lang_blog_MyFriends}", "{lang_blog_visitors}", "{visitors}", "{popupDefine}", "{blog_windows_encoding}"
							  );
		
		$header = $new_template->load_template ("templates/$defaultTemplate/header.html");
		$body = $new_template->load_template ("templates/$defaultTemplate/layout.html");
		$footer = $new_template->load_template ("templates/$defaultTemplate/footer.html");
		$template = $new_template->replace_static($static_name, $static_value, $header . $body	. $footer);
	}
		
	echo $template;
}


// 2: Process
else if($action == "process"){
	$erorr = 0;
	$name = htmlspecialchars($_POST['name']);
	$message = htmlspecialchars($_POST['comment']);
	$code = $_POST['code'];
	$code2 = $_POST['code2'];
	$location = $_POST['location'];
	$title = htmlspecialchars($_POST['title']);
	$email = $_POST['email'];
	
	if(empty($name)){
	$erorr++;
	}
	
	if(empty($title)){
	$erorr++;
	}
	
	if(empty($message)){
	$erorr++;
	}
	
	
	if(empty($email)){
	$erorr++;
	}				
	
	if($code != $code2){
	$erorr++;
	}
	
	
	
	if($erorr < 1)
	{

		$conn = mysql_connect($dbhost, $dbuser, $dbpass);
		mysql_select_db($dbname);
		
		$newID = 0;
		$query  = "SELECT id FROM eblog_messages ORDER BY id ASC";
		$result = mysql_query($query);
		$rowDate = date("d-m-Y");
		while($row = mysql_fetch_array($result, MYSQL_ASSOC))
		{
			$newID = $row['id'];
		}
		$newID++;
		
	    $result2 = mysql_query("SELECT  enable4, admin_email, admin_username FROM eblog_settings WHERE id = '1'");	
		$row2 = mysql_fetch_row($result2);
		$enable4 = $row2[0];
		$admin_email = $row2[1];
		$admin_username = $row2[2];
		
	    mysql_query("INSERT INTO eblog_messages  VALUES ('$newID', '$name', '$admin_username', '$title', '$rowDate', '$message', '1', '$email')");
				
/*
	    $result2 = mysql_query("SELECT enable3 FROM eblog_settings WHERE id = '1'");	
		$row2 = mysql_fetch_row($result2);
		$enable3 = $row2[0];
*/				
		
		if($enable3 == 1)
		{
		    $result2 = mysql_query("SELECT mails FROM eblog_alerts WHERE id = '1'");	
			$row2 = mysql_fetch_row($result2);
			$currentAlerts = $row2[0] + 1;	
			$sql="UPDATE eblog_alerts SET mails='$currentAlerts' WHERE id = '1'";
			$result=mysql_query($sql);	
			
			$query  = "SELECT id FROM eblog_new ORDER BY id ASC";
			$result = mysql_query($query);
			while($row = mysql_fetch_array($result, MYSQL_ASSOC))
			{
				$thisNewID = $row['id'];
			}
			$thisNewID++;
			 mysql_query("INSERT INTO eblog_new  VALUES ('$thisNewID', '$newID', '4')");									
		}				
						
		if($enable4 == 1)
		{
			//$subject_encoded="=?UTF-8?B?".base64_encode($title)."?=\n";
			$subject_encoded= $title;			
			$headers = "Content-type: text/html; charset=$blog_windows_encoding\r\n";
			$headers .= "From: ".$name."\r\n" ."X-Mailer: php";				
			@mail($admin_email, $subject_encoded, $message, $headers);				
		}								    
		
		mysql_close($conn);
		
		if($popup == 3)
		{
			echo "
			<script type='text/javascript'> 
			alert('$lang_blog_messageSent');
			javascript:window.close();
			</script>
			";			
		}
		else if($popup == 1)
		{
			echo "
			<script type='text/javascript'> 
			alert('$lang_blog_messageSent');
			window.location='contact.php';
			</script>
			";			
		}		
		else
		{
			echo "
			<script type='text/javascript'> 
			alert('$lang_blog_messageSent');
			window.location='index.php';
			</script>
			";	
		}
	}
				
}

// 3: Else, show error message
else
{
	echo "
	<script type='text/javascript'> 
	alert('$lang_erorr_PgaeNotFound');
	parent.location='index.php';
	</script>
	";
}


?>
Return current item: eBlog