<?php
session_start();
ob_start(); // Initiate the output buffer
date_default_timezone_set("Pacific/Auckland");

	
function redirect($url)
{
    if (!headers_sent())
    {    
        header('Location: '.$url);
        exit;
        }
    else
        {  
        echo '<script type="text/javascript">';
        echo 'window.location.href="'.$url.'";';
        echo '</script>';
        echo '<noscript>';
        echo '<meta http-equiv="refresh" content="0;url='.$url.'" />';
        echo '</noscript>'; exit;
    }
}
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($conn, $theValue, $theType,   $theDefinedValue = "", $theNotDefinedValue = "")   
    {  
      $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) :   $theValue;  

      $theValue = function_exists("mysqli_real_escape_string") ?   mysqli_real_escape_string($conn, $theValue) :  
mysqli_escape_string($conn_vote, $theValue);

      switch ($theType) {  
        case "text":  
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";  
          break;      
        case "long":  
        case "int":  
          $theValue = ($theValue != "") ? intval($theValue) : "NULL";    
          break;    
        case "double":    
          $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";  
          break;  
        case "date":  
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;  
        case "defined":  
          $theValue = ($theValue != "") ? $theDefinedValue :
$theNotDefinedValue;
break;
}
return $theValue;
}
}

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;
}

function add_email($username){
	
	include("php/configi.php");
	
	$curdatetime 	= GetSQLValueString(date('Y-m-d H:i:s'), "text");
	
	$email_to		=GetSQLValueString($username, "text");
	
	$subject 		= "Mybizsafe login from " . $username . " " . getUserIpAddr();
	
	$messagebody 	= "Successful login from user";

	$messagebody	=GetSQLValueString($messagebody, "text");

	$subject		=GetSQLValueString($subject, "text");
	
	$insertSQL = "insert into 94_send_email(email_to, email_subject, email_body, email_date_add, email_status) 	values(".$email_to.",".$subject.",".$messagebody.",".$curdatetime.",0)";
	
	
	$result = mysqli_query($conn, $insertSQL);
	
	
}

function send_email($username){

	$username = $username;
	
	$hostname = "ZZ".$_SERVER['HTTP_HOST'];
	
//	echo $hostname;
//	exit;
	

	if ($hostname == "ZZmybizsafe.app"){
		
		

		//main host website

		echo "main host website";
		
		require 'PHPMailer-master/PHPMailerAutoload.php';
		$subject = "Mybizsafe login from " . $username . " " . getUserIpAddr();
		$messagebody = "Successful login from user";

		$mail = new PHPMailer;
		//Tell PHPMailer to use SMTP	
		$mail->isSMTP();
		
		$mail->Host="gsydm1007.siteground.biz";

		$mail->Port=465;

		$mail->SMTPAuth = true;	
		$mail->Username="david@phoenixsoftware.co.nz";
		$mail->Password="Gg1@haylee101";
		$mail->SMTPSecure = 'ssl';		
		//Enable SMTP debugging
		// 0 = off (for production use)
		// 1 = client messages
		// 2 = client and server messages
		$mail->SMTPDebug=0;
		//Ask for HTML-friendly debug output
		$mail->Debugoutput='html';
		//Set the hostname of the mail server
		//Set the hostname of the mail server

		$mail->setFrom("david@phoenixsoftware.co.nz", "contact");
		//Set an alternative reply-to address
		$mail->addReplyTo("david@phoenixsoftware.co.nz", "david");
		//Set who the message is to be sent to
		$mail->addAddress("david@phoenixsoftware.co.nz");
		//$mail->AddCC($staff_email_address);
		//Set the subject line
		$mail->Subject = $subject;
		//Read an HTML message body from an external file, convert referenced images to embedded,
		//convert HTML into a basic plain-text alternative body
		$mail->msgHTML($messagebody);
		$mail ->isHTML(true);
		

				
		//Replace the plain text body with one created manually
		//Attach an image file
		//$mail->addAttachment($filename);

		//send the message, check for errors
		
		if (!$mail->send()) {
			  echo "Mailer Error: " . $mail->ErrorInfo;
		} else {
			 echo "Message Sent";
		}


	}else{
		
		echo "NOT".$hostname;
//		exit;

		//somehwere else - probably local - no need to send email

	}
}


?>
<!DOCTYPE html>

<?php
	include("../php/configi.php");
	
	function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}


$error = 0;

$compnameErr = "";
$emailaddrErr = "";
$passwdErr = "";
$passwd2Err = "";
$firstnameErr = "";
$tandcErr = "";

	$comp_name = "";
	$email_address = "";
	$password = "";
	$password2 = "";
	$first_name = "";
	$last_name = "";
	$tandc = "";
	
$nameErr = $emailErr = $genderErr = $websiteErr = "";
$name = $email = $gender = $comment = $website = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
	
  
   if (empty($_POST["email_address"])) {
		$emailaddrErr = "Email Address is required";
		$error = $error + 1;
  } else {
    $email_address = test_input($_POST["email_address"]);
	if (!filter_var($email_address, FILTER_VALIDATE_EMAIL)) {
	//	$emailaddrErr = "Invalid email format";
	//	$error = $error + 1;
	}
  }

  if (empty($_POST["password"])) {
    $passwdErr = "Password is required";
	$error = $error + 1;
  } else {
    $password = test_input($_POST["password"]);
  }


}
   ?>
<html lang="en">
	<head>
		<meta charset="utf-8" />
	<title>phoenixcrm.co.nz login </title>
		<meta name="description" content="Website development and hosting. Health and Safety. Phoenix Software - Blog" />
		<meta name="Author" content="Phoenix Software" />

		<!-- mobile settings -->
		<meta name="viewport" content="width=device-width, maximum-scale=1, initial-scale=1, user-scalable=0" />
		<!--[if IE]><meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'><![endif]-->

		<!-- WEB FONTS : use %7C instead of | (pipe) -->
		<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600%7CRaleway:300,400,500,600,700%7CLato:300,400,400italic,600,700" rel="stylesheet" type="text/css" />
<link rel='stylesheet' id='et-builder-googlefonts-cached-css'  href='https://fonts.googleapis.com/css?family=Raleway:100,100italic,200,200italic,300,300italic,regular,italic,500,500italic,600,600italic,700,700italic,800,800italic,900,900italic&#038;subset=latin,latin-ext&#038;display=swap' type='text/css' media='all' />
		<!-- CORE CSS -->
		<link href="../assets/plugins/bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css" />

		<!-- THEME CSS -->
		<link href="../assets/css/essentials.css" rel="stylesheet" type="text/css" />
		<link href="../assets/css/layout.css" rel="stylesheet" type="text/css" />
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.3/css/all.css">
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.3/css/v4-shims.css">
		<!-- PAGE LEVEL SCRIPTS -->
		<link href="../assets/css/header-1.css" rel="stylesheet" type="text/css" />
		<link href="../assets/css/color_scheme/orange.css" rel="stylesheet" type="text/css" id="color_scheme" />

<script async src="https://www.googletagmanager.com/gtag/js?id=G-XM9LYY3M9R"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-XM9LYY3M9R');
</script>
  

	</head>

	<!--
		AVAILABLE BODY CLASSES:
		
		smoothscroll 			= create a browser smooth scroll
		enable-animation		= enable WOW animations

		bg-grey					= grey background
		grain-grey				= grey grain background
		grain-blue				= blue grain background
		grain-green				= green grain background
		grain-blue				= blue grain background
		grain-orange			= orange grain background
		grain-yellow			= yellow grain background
		
		boxed 					= boxed layout
		pattern1 ... patern11	= pattern background
		menu-vertical-hide		= hidden, open on click
		
		BACKGROUND IMAGE [together with .boxed class]
		data-background="../assets/../images/_smarty/boxed_background/1.jpg"
		
		
		
	-->

<style>
.mortgageimage {
  display: block;
  width: 100%;
  height: auto;
}


.containermort {
  position: relative;
 width: 250px; -moz-border-radius: 50%;-webkit-border-radius: 50%;border-radius: 50%;
}

.imagemort {
  display: block;
  height: auto;
  width: 250px; -moz-border-radius: 50%;-webkit-border-radius: 50%;border-radius: 50%;
}

.overlaymort {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  height: 100%;
  width: 100%;
  opacity: 0;
  transition: .5s ease;
  background-color:rgb(221,105,107);
   -moz-border-radius: 50%;-webkit-border-radius: 50%;border-radius: 50%;
}

.containermort:hover .overlaymort {
  opacity: 1;
}

.text {
  color: white;
  font-size: 20px;
  position: absolute;
  top: 50%;
  left: 50%;
  -webkit-transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  text-align: center;
}

.parallax {
  /* The image used */
  background-image: url("../images/WHDividerDown.png");

  /* Set a specific height */
  min-height: 400px;

  /* Create the parallax scrolling effect */
  background-attachment: fixed;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}


.parallax2 {
  /* The image used */
  background-image: url("../images/WHDividerDown.png");

  /* Set a specific height */
  min-height: 100px;

  /* Create the parallax scrolling effect */
  background-attachment: fixed;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}
.parallaxfooter {
  /* The image used */
  background-image: url("../images/footer.png");

  /* Set a specific height */
  min-height: 400px;

  /* Create the parallax scrolling effect */
  background-attachment: fixed;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}

section.module:last-child {
  margin-bottom: 0;
}
section.module h2 {
  margin-bottom: 40px;
  font-family: "Roboto Slab", serif;
  font-size: 30px;
}
section.module p {
  margin-bottom: 40px;
  font-size: 16px;
  font-weight: 300;
}
section.module p:last-child {
  margin-bottom: 0;
}
section.module.content {
  padding: 40px 0;
  height: 600px;
}

section.module.parallax h1 {
  color: rgba(255, 255, 255, 0.8);
  font-size: 48px;
  font-weight: 700;
  text-align: center;
  text-transform: uppercase;
  text-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
}

section.module.parallax-1 {
  background-image: url("../");
  background-repeat:no-repeat;
background-size:contain;
  background-size: 100%;
top: 0;

section.module.parallax-2 {
  background-image: url("../images/WHDividerDown.png");
  background-repeat:no-repeat;
  background-size:contain;
top: 0;

}

</style>

	<body onload="javascript: init_user()" class="smoothscroll enable-animation" style="font-family: Raleway, Helvetica, Arial, Lucida, sans-serif;">

		<!-- SLIDE TOP -->

		<!-- /SLIDE TOP -->


		<!-- wrapper -->
		<div id="wrapper">


			<!-- 
				AVAILABLE HEADER CLASSES

				Default nav height: 96px
				.header-md 		= 70px nav height
				.header-sm 		= 60px nav height

				.b-0 		= remove bottom border (only with transparent use)
				.transparent	= transparent header
				.translucent	= translucent header
				.sticky			= sticky header
				.static			= static header
				.dark			= dark header
				.bottom			= header on bottom
				
				shadow-before-1 = shadow 1 header top
				shadow-after-1 	= shadow 1 header bottom
				shadow-before-2 = shadow 2 header top
				shadow-after-2 	= shadow 2 header bottom
				shadow-before-3 = shadow 3 header top
				shadow-after-3 	= shadow 3 header bottom

				.clearfix		= required for mobile menu, do not remove!

				Example Usage:  class="clearfix sticky header-sm transparent b-0"

			-->
			
			
				<div id="topBar">
<?php include 'topbar.php'; ?>
			</div>
			
			
			<div  id="header" class="navbar-toggleable-md sticky shadow-after-3 clearfix">

				<!-- TOP NAV -->
				<header id="topNav">
					<div class="container">

						<!-- Mobile Menu Button -->
						<button class="btn btn-mobile" data-toggle="collapse" data-target=".nav-main-collapse">
							<i class="fa fa-bars"></i>
						</button>

						<!-- BUTTONS -->

						<!-- /BUTTONS -->


						<!-- Logo -->
						<a  class="logo float-left">
							<img style="width: 100%" class="img-fluid" src="../images/phoenix_logo.png" alt="" />
						</a>

						<!-- 
							Top Nav 
							
							AVAILABLE CLASSES:
							submenu-dark = dark sub menu
						-->
<? include 'topnav.php'; ?>

					</div>
				</header>
				<!-- /Top Nav -->

			</div>



			<!-- 
				SLIDER 
				
				.h-300
				.h-350
				.h-400
				.h-450
				.h-500
				.h-550
				.h-600
				.h-650
				.h-700
				.h-750
				.h-800
			-->

			<!-- /SLIDER -->



			<!-- -->

			<!-- / -->
			

			

			<section style="border-bottom-style: none; padding-bottom: 0px; padding-top: 80px;">
				<div class="container">

					<!-- -->
					<div class="row">
						<div class="col-md-12">

<h1 style="font-size: 40px; font-weight: 700; color: #eb3856;font-family: Raleway, Helvetica, Arial, Lucida, sans-serif;; margin-bottom: 0px">Existing Customer Login</h1>


<br>
<br>
			<section style="margin-top: 5px; padding-top: 5px; padding-bottom: 25px;">
				<div class="container">
					
					<div class="row">

						<!-- LOGIN -->
						<div class="col-md-6">

							<!-- ALERT -->
							<!--
							<div class="alert alert-mini alert-danger mb-30">
								<strong>Oh snap!</strong> Login Incorrect!
							</div>
							-->
							<!-- /ALERT -->

							<!-- register form -->
							<form class="m-0 sky-form boxed" method="post"  action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
								<header>
									<i class="fa fa-users"></i> Company Login
									</header>

								<fieldset class="m-0">			
								
									<label class="input mb-10">
										<i class="ico-append fa fa-envelope"></i>
										<input type="text" required name="email_address" placeholder="Email address" value="<?php echo $email_address;?>">
										<b class="tooltip tooltip-bottom-right">Needed to verify your account</b>
									</label>
																				<? if ($emailaddrErr == ""){
											}else{
												?>
										<span style="color: red" class="error">* <?php echo $emailaddrErr;?></span>
											<?
											}
											?>
								
									<label class="input mb-10">
										<i class="ico-append fa fa-lock"></i>
										<input type="password" required name="password" placeholder="Password"  value="<?php echo $password;?>">
										<b class="tooltip tooltip-bottom-right">Only latin characters and numbers</b>
									</label>
									
																													<? if ($passwdErr == ""){
											}else{
												?>
										<span style="color: red" class="error">* <?php echo $passwdErr;?></span>
											<?
											}
											?>

								
								</fieldset>

								<div class="row mb-20">
									<div class="col-md-12">
										<button type="submit" style="background-color: #eb3856" class="btn btn-primary"><i class="fa fa-check"></i> LOGIN</button>
										<br>
						<?

if ($_SERVER["REQUEST_METHOD"] == "POST") {
	


	if ($error == 0){
		
		




		setcookie("phxcrmclient_id", "", time() + (20 * 365 * 24 * 60 * 60),'/');
		$_SESSION['phxcrmclient_id'] = "";
		include("../php/configi.php");
			
			
		$sqluser = "SELECT * FROM phx_userid where email = '".$email_address."' or short_userid =  '".$email_address."'";
		
	//	echo $sqluser;
		
		$resultuser = $conn->query($sqluser);

		if ($resultuser->num_rows > 0) {
			// output data of each row
			while($rowuser = $resultuser->fetch_assoc()) {


					$passworddb = $rowuser["passwordnew"];	
					$phxclient_casual = 0;					

				
				if (password_verify($password, $passworddb)) {


		//		if ("1"=="1") {
					$phx_comp_name 				= 	$rowuser['comp_name'];
					$phxclient_type 			= 	$rowuser['comp_type'];
					$phxcrmclient_id 				= 	$rowuser['idphx_userid'];
					$phxclient_name 			= 	$rowuser['comp_name'];
					$phxclient_system_type 		= 	$rowuser['comp_system_option'];
					$phxclient_comp_status 		= 	$rowuser['comp_status'];			


					setcookie("phxcrmclient_id", $phxcrmclient_id, time() + (20 * 365 * 24 * 60 * 60),'/');
					$_SESSION['phxcrmclient_id'] = $phxcrmclient_id;

					setcookie("phxcrm_outlet_id", 1, time() + (20 * 365 * 24 * 60 * 60),'/');



			//		redirect("fthome/home");
			
				//	send_email($email_address);
					
					
//					add_email($email_address);
					
	//				exit;
	
			if ($_SERVER['HTTP_HOST'] == "localhost"){
				
				$app_url = "../../app.phoenixcrm.co.nz/crm/home/";
				

			}else{

				$app_url = "https://app.phoenixcrm.co.nz/crm/home/";
			
		
			}
					if ($phxclient_type == "shop"){
	

						redirect($app_url);
					
					}else{
						redirect($app_url);
					}

//					echo 'Password is valid!';
				} else {
					echo 'Invalid User or password.';
				}
			}
		} else {
			echo "user or password not valid";
		}



	}else{

	//	echo "errors found".$error.$_POST["tandc"];
		
	}
}

?>
									</div>
								</div>

							</form>
							<!-- /register form -->

						</div>
						<!-- /LOGIN -->

						<!-- SOCIAL LOGIN -->

						<!-- /SOCIAL LOGIN -->



					</div>

					
				</div>
			</section>
</div>


<div class="col-md-12">
	<div class="row">
		<div class="col-md-3">


		</div>
		
				<div class="col-md-9">
<h2 style="margin-bottom: 0px">

</h2>


		</div>
	</div>




						</div>
						




					</div>
					<!-- / -->

				</div>
			</section>

			<!-- CALLOUT -->

			<!-- /CALLOUT -->







	<section class="module parallax parallax-1 img-responsive">

	

		<center>


   <h3><strong><span style="font-weight: 700; font-size: 30px; color: white; font-family: Raleway, Helvetica, Arial, Lucida, sans-serif">Get in touch with us today to see how we can help you</span></strong></h3>	


	<br>

		<a style="color: black; font-size: 28px" class=""  href="https://phoenixcrm.co.nz/"> <button type="button" style="color: white; background-color: #5cb85c; border-color: #5cb85c; font-weight: 700; font-size: 22px; border-radius: 12px;  font-family: Raleway, Helvetica, Arial, Lucida, sans-serif;" class="btn btn-warning">Go to our main site</button></a>
	</center>



 

</section>

					





			<!-- -->

			<!-- / -->






			<!--
				.box-pink
				.box-blue
				.box-orange
				.box-yellow
				.box-purple
				.box-red
				.box-brown
				.box-green
				.box-black
				.box-gray
				.box-teal
			-->






			<!-- -->

			<!-- / -->

			<!-- FOOTER -->

<?php include 'footer.php'; ?>
			<!-- /FOOTER -->

		</div>
		<!-- /wrapper -->


		<!-- SCROLL TO TOP -->
		<a href="#" id="toTop"></a>





		<!-- JAVASCRIPT FILES -->
		<script type="text/javascript">var plugin_path = '../assets/plugins/';</script>
		<script type="text/javascript" src="../assets/plugins/jquery/jquery-3.2.1.min.js"></script>

		<script type="text/javascript" src="../assets/js/scripts.js"></script>
		
		<!-- STYLESWITCHER - REMOVE -->

	</body>
	
	<script>
	
	function init_user(){

		sessionStorage.setItem("phxcrmuserid", "");	
		
	}
	
	</script>
</html>