<?php
require('config.php'); 
$service = $_POST['service']; 
//echo $service;
$email_header = $_POST['email_header']; 
$email_description = $_POST['email_description']; 
$email_header_one = $_POST['email_header_one']; 
$email_description_one = $_POST['email_description_one']; 
$email_header_two = $_POST['email_header_two']; 
$email_description_two = $_POST['email_description_two']; 
$text_message = $_POST['text_message']; 
$text_message_one = $_POST['text_message_one']; 
$text_message_two = $_POST['text_message_two']; 

$email_form_after = $_POST['email_form_after']; 
$email_form_after_description = $_POST['email_form_after_description']; 
$email_form_after_name = $_POST['email_form_after_name']; 
$email_form2_after = $_POST['email_form2_after']; 
$email_form2_after_description = $_POST['email_form2_after_description']; 
$email_form2_after_name = $_POST['email_form2_after_name']; 

$email_form3_after = $_POST['email_form3_after']; 
$email_form3_after_name = $_POST['email_form3_after_name']; 
$email_form3_after_description = $_POST['email_form3_after_description'];

$email_form = $_POST['email_form']; 
$email_form_description = $_POST['email_form_description']; 
$email_form_name = $_POST['email_form_name']; 
$email_form2 = $_POST['email_form2']; 
$email_form2_description = $_POST['email_form2_description']; 
$email_form2_name = $_POST['email_form2_name']; 
$email_form3 = $_POST['email_form3']; 
$email_form3_description = $_POST['email_form3_description'];
$email_form3_name = $_POST['email_form3_name']; 


$reminderonoff = $_POST['reminder_on_off']; 
$reminderonoffone = $_POST['reminder_on_off_one']; 
$reminderonofftwo = $_POST['reminder_on_off_two']; 


$linkID = new PDO('mysql:host='.Config::DB_HOST.';dbname='.Config::DB_NAME, Config::DB_USERNAME, Config::DB_PASSWORD);
$linkID->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Setting ERRMODE
$data = [
    'service' => $service,
    'email_header' => $email_header,
    'email_description' => $email_description,
    'email_header_one' => $email_header_one,
    'email_description_one' => $email_description_one,
    'email_header_two' => $email_header_two, 
    'email_description_two' => $email_description_two, 
    'text_message' => $text_message, 
    'text_message_one' => $text_message_one, 
    'text_message_two' => $text_message_two, 
    'email_form' => $email_form, 
    'email_form_description'=> $email_form_description, 
    'email_form_name'=>$email_form_name, 
    'email_form2' => $email_form2, 
    'email_form2_description'=>$email_form2_description, 
    'email_form2_name'=>$email_form2_name, 
    'email_form3' => $email_form3,
    'email_form3_description' => $email_form3_description,
    'email_form3_name'=>$email_form3_name,
    'email_form_after' => $email_form_after, 
    'email_form_after_description'=>$email_form_after_description, 
    'email_form_after_name' => $email_form_after_name, 
    'email_form2_after' => $email_form2_after, 
    'email_form2_after_description' => $email_form2_after_description, 
    'email_form2_after_name' => $email_form2_after_name, 
    'email_form3_after' => $email_form3_after, 
    'email_form3_after_name' => $email_form3_after_name, 
    'email_form3_after_description' => $email_form3_after_description, 
    'send_reminder'=>$reminderonoff, 
    'send_reminder2'=>$reminderonoffone,
    'send_reminder3'=>$reminderonofftwo

];

$result = $linkID->query("SELECT * FROM millie_service WHERE service='".$service."'")->fetchAll(PDO::FETCH_ASSOC);
//echo $result[0]['service']; 

if($result[0]['service'] == null){
   // echo 'here'; 
$sql = "INSERT INTO `millie_service`(`service`, `email_header`, `email_description`, `email_header2`, `email_description2`, `email_header3`, `email_description3`, `text_message`, `text_message_one`, `text_message_two`, `email_form`, `email_form_description`, `email_form_name`, `email_form_two`, `email_form_two_description`, `email_form_two_name`, `email_form_three`, `email_form_three_description`, `email_form_three_name`, `email_form_after`, `email_form_after_name`, `email_form_after_description`, `email_form2_after`, `email_form2_after_name`, `email_form2_after_description`, `email_form3_after`, `email_form3_after_name`, `email_form3_after_description`, `send_reminder`, `send_reminder2`, `send_reminder3`)
VALUES('".$service."', '".$email_header."', '".$email_description."', '".$email_header_one."', '".$email_description_one."', '".$email_header_two."', '".$email_description_two."', '".$text_message."', '".$text_message_one."', '".$text_message_two."', '".$email_form."', '".$email_form_description."', '".$email_form_name."', '".$email_form2."', '".$email_form2_description."', '".$email_form2_name."', '".$email_form3."', '".$email_form3_description."', '".$email_form3_name."', '".$email_form_after."', '".$email_form_after_name."', '".$email_form_after_description."', '".$email_form2_after."', '".$email_form2_after_name."', '".$email_form2_after_description."', '".$email_form3_after."', '".$email_form3_after_name."', '".$email_form3_after_description."', '".$reminderonoff."', '".$reminderonoffone."', '".$reminderonofftwo."')"; 
}else{
    //echo 'here2';
$sql = "UPDATE millie_service SET service='".$service."', email_header='".$email_header."', email_description='".$email_description."', email_header2='".$email_header_one."', email_description2='".$email_description_one."', email_header3='".$email_header_two."', email_description3='".$email_description_two."', text_message='".$text_message."', text_message_one='".$text_message_one."', text_message_two='".$text_message_two."', email_form='".$email_form."', email_form_description='".$email_form_description."', email_form_name='".$email_form_name."', email_form_two='".$email_form2."', email_form_two_description='".$email_form2_description."', email_form_two_name='".$email_form2_name."', email_form_three='".$email_form3."', email_form_three_description='".$email_form3_description."', email_form_three_name='".$email_form3_name."', email_form_after='".$email_form_after."', email_form_after_name='".$email_form_after_name."', email_form_after_description='".$email_form_after_description."', email_form2_after='".$email_form2_after."', email_form2_after_name='".$email_form2_after_name."', email_form2_after_description='".$email_form2_after_description."', email_form3_after='".$email_form3_after."', email_form3_after_name='".$email_form3_after_name."', email_form3_after_description='".$email_form3_after_description."', send_reminder='".$reminderonoff."', send_reminder2='".$reminderonoffone."', send_reminder3='".$reminderonofftwo."' WHERE service='".$service."'"; 

    
}
//echo $stmt; 

 $stmt= $linkID->prepare($sql);

$stmt->execute($data);
echo '<a href='.'"'.Config::BASE_URL.'/index.php/backend/settings'.'"'.'>'.'<image src='.'"'.'leftarrow.png'.'"'. 'width='.'"'.'100'.'"'. 'height='.'"'.'50'.'"'.'>'.'</a>'.'<br>';

echo 'Success, return to mainpage by clicking the black arrow!';


?>