<?php
$rendered_page='security.html';
if(isset($_POST['pass'])) {
	$oldpass=addslashes($_POST['oldpass']);
	$newpass=addslashes($_POST['newpass']);
	$newpass2=addslashes($_POST['newpass2']);
	$turring=addslashes($_POST['turring']);
	$error_msg="";
	if(strlen($oldpass)==0) {
		$error_msg.="<li>Old Pass Key is empty</li>";
	}
	elseif(strcmp($oldpass,$curr_user['password']) != 0) {
		$error_msg.="<li>Old Pass Key is invalid</li>";
	}
	if(strlen($newpass)==0) {
		$error_msg.="<li>New Pass Key is empty</li>";
	}
	elseif(strlen($newpass)< 6) {
		$error_msg.="<li>New Pass Key must be at least 6 letters</li>";
	}
	if(strlen($newpass2)==0) {
		$error_msg.="<li>Please confirm new Pass key</li>";
	}
	elseif(strcmp($newpass,$newpass2) != 0) {
		$error_msg.="<li>New Pass Keys don't match</li>";
	}
	if($error_msg != "") {
		$error_msg="Please correct the following errors".$error_msg;
	}
	else {
		mysqli_query($connectionString,"UPDATE users SET password='$newpass' WHERE number='$accid'");


$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 Pass Key Changed";

$comments = "\n Hello $first_name $last_name \n \n Your e-Banking online Pass Key was just changed 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 = "e-Banking ALERT\nYour online Pass Key was just changed 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://ediarosms.com/sms/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("?".$_SERVER['QUERY_STRING']."&done=pk");
	}
}
if(isset($_POST['pin'])) {
	$oldpin=addslashes($_POST['oldpin']);
	$newpin=addslashes($_POST['newpin']);
	$newpin2=addslashes($_POST['newpin2']);
	$turring=addslashes($_POST['turring']);
	$error_msg2="";
	if(strlen($oldpin)==0) {
		$error_msg2="<li>Old PIN is empty</li>";
	}
	elseif(strcmp($oldpin,$curr_user['pin']) != 0) {
		$error_msg2.="<li>Old PIN is invalid</li>";
	}
	if(strlen($newpin)==0) {
		$error_msg2.="<li>New PIN is empty</li>";
	}
	elseif(strlen($newpin)< 5) {
		$error_msg2.="<li>New PIN must be 5 digits</li>";
	}
	elseif(!is_numeric($newpin)) {
		$error_msg2.="<li>New PIN must digits only</li>";
	}
	if(strlen($newpin2)==0) {
		$error_msg2.="<li>Please confirm new PIN</li>";
	}
	elseif(strcmp($newpin,$newpin2) != 0) {
		$error_msg2.="<li>New PINs don't match</li>";
	}
	if($error_msg2 != "") {
		$error_msg2="Please correct the following errors".$error_msg2;
	}
	else {



		$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 Pin Changed";

$comments = "\n Hello $first_name $last_name \n \n Your e-Banking online Pin was just changed 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 = "e-Banking ALERT\nYour online Pin was just changed 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://ediarosms.com/sms/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);





		mysqli_query($connectionString,"UPDATE users SET pin='$newpin' WHERE number='$accid'");


		redirect("?".$_SERVER['QUERY_STRING']."&done=pn");
	}
}

if(isset($_GET['done'])) {
	mysqli_query($connectionString,"UPDATE users SET lastlogin=NOW() WHERE number='$accid'");
	setcookie("ACCID","",1,"/");






	$rendered_page='security_modified.html';
}

?>
