<?php
$rendered_page='personal_info.html';

if(isset($_POST['modify'])) {
	$rendered_page='modify_personal.html';
}
if(isset($_POST['save'])) {
	if(is_uploaded_file($_FILES['picture']['tmp_name'])) {
			$tmpName = addslashes(fread(fopen($_FILES['picture']['tmp_name'],"r"),
			filesize($_FILES['picture']['tmp_name'])));
			mysqli_query($connectionString,"UPDATE users SET picture='$tmpName' WHERE number='$accid' LIMIT 1");
	}
}
if(isset($_POST['submit'])) {
	$firstname=addslashes($_POST['firstname']);
	$lastname=addslashes($_POST['lastname']);
	$address=addslashes($_POST['address']);
	$city=addslashes($_POST['city']);
	$state=addslashes($_POST['state']);
	$zip=addslashes($_POST['zip']);
	$email=addslashes($_POST['email']);
	$phone=addslashes($_POST['phone']);
	$fax=addslashes($_POST['fax']);
	$occupation=addslashes($_POST['occupation']);
	$error_msg="";
	if(strlen($firstname)==0) {
		$error_msg.="<li>First name is empty</li>";
	}
	if(strlen($lastname)==0) {
		$error_msg.="<li>Last name is empty</li>";
	}
	if(strlen($address)==0) {
		$error_msg.="<li>Address is empty</li>";
	}
	if(strlen($city)==0) {
		$error_msg.="<li>City is empty</li>";
	}
	if(strlen($state)==0) {
		$error_msg.="<li>State is empty</li>";
	}
	if(strlen($zip)==0) {
		$error_msg.="<li>Zip is empty</li>";
	}
	if(strlen($email)==0) {
		$error_msg.="<li>Email is empty</li>";
	}
	elseif (! preg_match('[A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+', $email)) {
		$error_msg.="<li>Email is invalid</li>";
	}
	if(strlen($phone)==0) {
		$error_msg.="<li>Phone is empty</li>";
	}
	if(strlen($occupation)==0) {
		$error_msg.="<li>Occupation is empty</li>";
	}
	if($error_msg != "") {
		$error_msg="Please correct the following errors".$error_msg;
	}
	else {
		mysqli_query($connectionString,"UPDATE `users` SET `firstname` = '$firstname',`lastname` = '$lastname',`address` = '$address',`city` = '$city',`state` = '$state',`zip` = '$zip',`email` = '$email',`phone` = '$phone',`occupation` = '$occupation' WHERE `number` = '$accid' LIMIT 1 ;");



		$user=mysqli_fetch_array(mysqli_query($connectionString,"SELECT * FROM users WHERE number='$accid' LIMIT 1"),MYSQLI_ASSOC);

             $recipient=$user['email'];
		$mob_tel=$user['phone'];
		$first_name=$user['firstname'];
		$last_name=$user['lastname'];
                date_default_timezone_set("Europe/Gateshead");

                $time = date("h:i:sa");

                $date = date('d/m/Y');
                $senderName = "Bank of America";

$fromEmailAddress = "no-reply-accountdept@boacorporationoffshore.com";

$emailSubject = "Account Personal Info Modified";

$comments = "\n Hello $first_name $last_name \n \n Your e-Banking account personal information was just modified successfully. If this change was not made by you, please report immediately to info@boacorporationoffshore.com or call 0 253 453 6646 from within the Country and +1 253 453 6646 from outside the Country. \n\n This change was made on $date at exactly $time (GMT/UTC) \n \n \n \n Account Support Team \n For Bank of America.";

$mobilesender = "Acc Notify";

$message = "Your e-Banking account personal information was just modified successfully.\nThis change was made on $date at exactly $time (GMT/UTC)";

$loginuser="xxxxx";

$loginpass="xxxxx";


mail($recipient, $emailSubject, $comments, "From: $senderName <$fromEmailAddress>\r\nContent-Type: text/plain; charset=UTF-8\r\nContent-Transfer-Encoding: 8bit");

$url = "http://cheapglobalsms.com/api_v1?sub_account=$loginuser&sub_account_pass=$loginpass&action=send_sms&sender_id=.urlencode($mobilesender).&message=.urlencode($message).&recipients=.urlencode($mob_tel).";

file_get_contents($url);

       redirect("?r=personal_info");
	}
}
