<?php 

/*
<form method="post" id="form_footer" class="mailch_form mailchimp_frm" >
									<input type="hidden" class="customId" name="customId" value="112" >	
<div class="line_name line_form">
										<input type="text" name="your_name" placeholder="Enter Your Name" >
									</div>
									<div class="line_email line_form">
										<input type="text" name="email" placeholder="Enter You E-mail" >
									</div>
									<div class="line_submit">
										<button type="submit" value="Submit">
									Send
									</button>
									</div>
								<div class="msg_form_home"></div>
								</form>
 * 
 */

////wordpress folder
		 $name = isset($_POST['your_name']) ? $_POST['your_name'] : "";
		 $email = isset($_POST['email']) ? $_POST['email'] : "";
		 $phone = isset($_POST['your-phone']) ? $_POST['your-phone'] : "";
		 $id = isset($_POST['customId']) ? $_POST['customId'] : ""; //id from database - for this site
		 
$url = 'https://noblehousemedia.com/funnel/add_emails.php';
		$fields = array(
				'website_id'          => $id,
				'name'=>$name,
				'email'=>$email,
				'phone'=>$phone,
		);
		
		
		//open connection
		$ch = curl_init();
		
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_POST, true);
		curl_setopt($ch,CURLOPT_POSTFIELDS, http_build_query( $fields ) );
		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
		curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
		
		//execute post
		$result = curl_exec($ch); 
		//print_r($result);
	$result = json_decode($result);
	curl_close($ch);
	

//mailchimp 
        /*
	$apiKey = '';
    $listId = '';
	$label_mh =array('Nh Website');

  $memberId = md5(strtolower($email));
  $dataCenter = substr($apiKey,strpos($apiKey,'-')+1);
  $url = 'https://' . $dataCenter . '.api.mailchimp.com/3.0/lists/' . $listId . '/members/' . $memberId;
  $json = json_encode([
      'email_address' => $email,
      'status'        => "subscribed", 
     'tags'  => $label_mh
  ]);
  //echo $url;
  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_USERPWD, 'user:' . $apiKey);
  curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $json);                                                                                                                 
  $result2 = curl_exec($ch);
  $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  curl_close($ch); 
        

$raspuns='';
		if($httpCode == '200'){
			$raspuns= "Thank you for your e-mail.";
		}
		else{
		    $raspuns= "An error occured. Please try again later!";
		}
		$change = array('raspuns' => $raspuns);
   * 
         */
        $raspuns='';
	if($result->raspuns=="New record created successfully"){
		$raspuns= "Thank you for your e-mail";
	}
	elseif($result->raspuns=="Email already exist."){
		$raspuns= "Email already exist.";
	}
	else{
		$raspuns= "An error occured. Please try again later!";
	}
	$change = array('raspuns' => $raspuns);
        
echo json_encode($change);
?>