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

$email_form_after = nl2br(addslashes($_POST['email_form_after'])); 
$email_form_after_description = nl2br(addslashes($_POST['email_form_after_description'])); 
$email_form_after_name = nl2br(addslashes($_POST['email_form_after_name'])); 
$email_form2_after = nl2br(addslashes($_POST['email_form2_after'])); 
$email_form2_after_description = nl2br(addslashes($_POST['email_form2_after_description'])); 
$email_form2_after_name = nl2br(addslashes($_POST['email_form2_after_name'])); 

$email_form3_after = nl2br(addslashes($_POST['email_form3_after'])); 
$email_form3_after_name = nl2br(addslashes($_POST['email_form3_after_name'])); 
$email_form3_after_description = nl2br(addslashes($_POST['email_form3_after_description']));

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


$reminderonoff = nl2br(addslashes($_POST['reminder_on_off'])); 
$reminderonoffone = nl2br(addslashes($_POST['reminder_on_off_one'])); 
$reminderonofftwo = nl2br(addslashes($_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!';


?>