<?php
namespace Smackcoders\FUPESM;
if ( ! defined( 'ABSPATH' ) )
exit; // Exit if accessed directly
class FUPESM_Tables {
    public function __construct(){
    }
    public static function fupesm_create_tables(){
        global $wpdb;
		$date = new \DateTime('now');
		$current_timestamp=$date->format('Y-m-d H:i:s');
		$current_user = wp_get_current_user();
        $user_id =$current_user->ID;
		$mail_table_name = $wpdb->prefix ."smack_followup_mail";
		$post_table = $wpdb->prefix ."posts";
		$table = $wpdb->query("CREATE TABLE IF NOT EXISTS $mail_table_name (
			`id` int(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
			`username` VARCHAR(255) NOT NULL,
			`event` VARCHAR(255) NOT NULL,
			`user_email` VARCHAR(255) NOT NULL,
			`template_id` VARCHAR(255) NOT NULL,
			`scheduled_date` datetime DEFAULT '0000-00-00 00:00:00',
			`orderid` VARCHAR(255) DEFAULT NULL,
			`cartid` VARCHAR(255) DEFAULT NULL,
			`product_id` int(10) DEFAULT NULL,
			`user_id` int(10) DEFAULT NULL,
            `status` int(1) DEFAULT '0',
			`form_id` int(10) DEFAULT NULL,
			`entry_id` int(10) DEFAULT NULL
			) ENGINE=InnoDB" 
				);
		$mail_log_table = $wpdb->prefix."smack_email_log";
		$mail_log = $wpdb->query("CREATE TABLE IF NOT EXISTS $mail_log_table(
			`id` int(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
			`user_email` VARCHAR(255) NOT NULL,
			`event` VARCHAR(255) NOT NULL,
			`date` datetime DEFAULT '0000-00-00 00:00:00',
			`status` VARCHAR(255) DEFAULT NULL
		)");
		
		$post_ids4 = $wpdb->get_var($wpdb->prepare("SELECT p.ID FROM $post_table as p inner join {$wpdb->prefix}postmeta as pm on p.ID=pm.post_id WHERE (pm.meta_key=%s and pm.meta_value=%s)",'type','default4'));
		if(empty($post_ids4)){
			$post_id =wp_insert_post(
				array('post_title' => 'New Order Template',
				'post_type' => 'fup_email_template',
				'post_status' => 'publish',
				'post_content' => 'test',
				'post_excerpt' => 'test',
				'comment_status' => 'closed',
				'ping_status' => 'closed',
				'post_date' => $current_timestamp,
				'post_author' => $user_id)
			);
			update_post_meta($post_id,'content','<p>Hey {customer_name},</p><p>Thank you for choosing {site_name}! We’re excited to let you know that we’ve received your order and are processing it with care.</p><p>Here’s a quick summary of your order:</p><ul><li>Order Number: {order_number}</li><li>Order Date: {order_date}</li><li>Order Total: {order_total}</li></ul><p>You can view all the details of your order here:</p><p>[View Your Order]</p><p><strong>What’s Next?</strong></p><p>We’ll send you another email as soon as your order is ready. In the meantime, if you have any questions or need help, feel free to reach out to us at [support email/contact link].</p><p><strong>Looking for Something Else?</strong></p><p>Check out our latest arrivals and trending products to see what’s new in our store.</p><p>[Shop Now]</p><p>Thank you for trusting us with your purchase. We can’t wait for you to enjoy your [product/service].</p><p><strong>Best Regards,</strong></p><p>The {site_name} Team</p>');
			update_post_meta($post_id,'event','New Order');
			update_post_meta($post_id,'trigger','10-minutes');
			update_post_meta($post_id,'type','default4');
			update_post_meta($post_id,'subject', 'Thanks for Your Order #{order_number}!');
		}

		$post_ids5 = $wpdb->get_var($wpdb->prepare("SELECT p.ID FROM $post_table as p inner join {$wpdb->prefix}postmeta as pm on p.ID=pm.post_id WHERE (pm.meta_key=%s and pm.meta_value=%s)",'type','default5'));
		if(empty($post_ids5)){
			$post_id = wp_insert_post(
				array('post_title' => 'Completed Order Template',
				'post_type' => 'fup_email_template',
				'post_status' => 'publish',
				'post_content' => 'test',
				'post_excerpt' => 'test',
				'comment_status' => 'closed',
				'ping_status' => 'closed',
				'post_date' => $current_timestamp,
				'post_author' => $user_id)
			);
			update_post_meta($post_id,'content','<p>Hey {customer_name}, </p><p>We hope your order {Order_id} reached you without any issues! Now that you’ve had some time to enjoy your new purchase, we just wanted to check in and make sure everything is perfect with what you received. </p><p>We want you to be 100% satisfied with your purchase so if you noticed anything seems off, or if you just have any questions, feel free to let us know. We’re always here to help! </p><p><strong>Love what you got? </strong></p><p>We’d be so grateful if you could take a moment to leave us a review. Your feedback means the world to us and helps us improve so we can serve you even better! [Leave a Review Button/Link] </p><p><strong>Looking for more? </strong></p><p>If you’re enjoying your purchase, check out our latest arrivals and bestsellers. There’s always something new to explore! [Shop New Arrivals Button/Link] </p><p>Thanks so much for shopping with us at {site_name}. We really appreciate your support and hope to see you back soon! </p><p>Best, </p><p>The {site_name} Team</p>');
			update_post_meta($post_id,'event','Completed Order');
			update_post_meta($post_id,'trigger','10-minutes');
			update_post_meta($post_id,'type','default5');
			update_post_meta($post_id,'subject', 'How’s Everything Going with Your Order #{order_number}?');
		}
		$post_ids6 = $wpdb->get_var($wpdb->prepare("SELECT p.ID FROM $post_table as p inner join {$wpdb->prefix}postmeta as pm on p.ID=pm.post_id WHERE (pm.meta_key=%s and pm.meta_value=%s)",'type','default6'));
		if(empty($post_ids6)){
			$post_id = wp_insert_post(
				array('post_title' => 'Failed Order Template',
				'post_type' => 'fup_email_template',
				'post_status' => 'publish',
				'post_content' => 'test',
				'post_excerpt' => 'test',
				'comment_status' => 'closed',
				'ping_status' => 'closed',
				'post_date' => $current_timestamp,
				'post_author' => $user_id)
			);
			update_post_meta($post_id,'content',' <p>Hi {customer_name},</p><p>We noticed that your order #[{order_number}] from {site_name} didn’t go through as expected. We wanted to follow up and see if there’s anything we can do to help you complete your purchase.</p><p>We understand that these things happen, and we’re here to make it right!</p><p><strong>Here’s what you can do next</strong>:</p><ol><li><strong>Check Payment Details</strong>: Sometimes payment errors are as simple as a small mistake in billing info. Double-check your payment details and try again<strong>.</strong></li><li><strong>Contact Us</strong>: If you need assistance, have any questions, or want to explore other payment options, our support team is just a message away. You can reach us at [support email/contact link].</li></ol><p>We’re here to help you every step of the way and want to make sure you have a smooth experience with us.</p><p>If you’ve already resolved the issue or completed the payment, thank you for being patient! If not, we’re ready to assist you in getting your order finalized.</p><p>We appreciate your interest in {site_name}, and we look forward to helping you complete your purchase!</p><p><strong>Best Regards,</strong></p><p>{site_name}</p><p>[Support Email]</p><p> </p><p> </p><p> </p>');
			update_post_meta($post_id,'event','Failed Order');
			update_post_meta($post_id,'trigger','10-minutes');
			update_post_meta($post_id,'type','default6');
			update_post_meta($post_id,'subject', 'Still Need Help with Your Order #{order_number}?');
		}
		$post_ids7 = $wpdb->get_var($wpdb->prepare("SELECT p.ID FROM $post_table as p inner join {$wpdb->prefix}postmeta as pm on p.ID=pm.post_id WHERE (pm.meta_key=%s and pm.meta_value=%s)",'type','default7'));
		if(empty($post_ids7)){
			$post_id = wp_insert_post(
				array('post_title' => 'Refund Order Template',
				'post_type' => 'fup_email_template',
				'post_status' => 'publish',
				'post_content' => 'test',
				'post_excerpt' => 'test',
				'comment_status' => 'closed',
				'ping_status' => 'closed',
				'post_date' => $current_timestamp,
				'post_author' => $user_id)
			);
			update_post_meta($post_id,'content','<p>Hi {customer_name}, </p><p>We hope you\'re doing well! A short while ago, we confirmed that a refund was processed for your order #{order_number}. We\'re just following up to ensure that the refund was successfully applied to your account. </p><ul><li><strong>Refund Details: </strong></li></ul><ol><li>Order Number: {order_number} </li><li>Refund Amount: {refund_amount} </li><li>Refund Processed On: {refund_date} </li></ol><p>If, for any reason, you haven\'t received the refund yet or if there are any issues, please don\'t hesitate to contact us. We\'re happy to assist you and make sure everything is resolved. </p><p><strong>We’d Love Your Feedback! </strong></p><p>Your satisfaction is very important to us. If you have any comments or suggestions on how we can improve our service, we’d be grateful to hear from you!</p><p> Thank you for being a valued customer of {site_name}. We hope to have the pleasure of serving you again in the future! </p><p><strong>Best regards, </strong></p><p>The {site_name} </p><p>Team [support email/contact link]</p>');
			update_post_meta($post_id,'event','Refunded Order');
			update_post_meta($post_id,'trigger','10-minutes');
			update_post_meta($post_id,'type','default7');
			update_post_meta($post_id,'subject', 'Checking In – Was Your Refund Processed Successfully?');
		}
		$post_ids8 = $wpdb->get_var($wpdb->prepare("SELECT p.ID FROM $post_table as p inner join {$wpdb->prefix}postmeta as pm on p.ID=pm.post_id WHERE (pm.meta_key=%s and pm.meta_value=%s)",'type','default8'));
		if(empty($post_ids8)){
			$post_id = wp_insert_post(
				array('post_title' => 'Processing Order Template',
				'post_type' => 'fup_email_template',
				'post_status' => 'publish',
				'post_content' => 'test',
				'post_excerpt' => 'test',
				'comment_status' => 'closed',
				'ping_status' => 'closed',
				'post_date' => $current_timestamp,
				'post_author' => $user_id)
			);
			update_post_meta($post_id,'content','<p>Hi {customer_name}, </p><p>We wanted to follow up on your order #[{order_number}] and provide you with an update. Your order is still in processing, and our team is diligently working to get everything ready for shipment. We truly appreciate your patience and understanding as we work to ensure that your order arrives safely and on time. </p><p><strong>Here’s a quick recap of your order:</strong><br> Order Number: {order_number} </p><p>Order Date: {order_date} </p><p>Order Total: {order_total} </p><p>Items Ordered: {item_name} </p><p>We know you’re excited to receive your order, and we’re doing everything we can to make sure it’s prepared with care. We’ll notify you as soon as it’s ready for shipment or if there are any updates. </p><p>If you have any questions or need assistance in the meantime, don’t hesitate to reach out to our support team at [support email/contact link]. We’re here to help! </p><p>Thanks again for shopping with {site_name}! </p><p>Best regards, </p><p>[Your Store Name] </p><p>[support email/contact link]</p>');
			update_post_meta($post_id,'event','Processing Order');
			update_post_meta($post_id,'trigger','10-minutes');
			update_post_meta($post_id,'type','default8');
			update_post_meta($post_id,'subject', 'Your Order #[{order_number}] – Still in Progress!');
		}
		$post_ids9 = $wpdb->get_var($wpdb->prepare("SELECT p.ID FROM $post_table as p inner join {$wpdb->prefix}postmeta as pm on p.ID=pm.post_id WHERE (pm.meta_key=%s and pm.meta_value=%s)",'type','default9'));
		if(empty($post_ids9)){
			$post_id = wp_insert_post(
				array('post_title' => 'Abandoned Cart Template',
				'post_type' => 'fup_email_template',
				'post_status' => 'publish',
				'post_content' => 'test',
				'post_excerpt' => 'test',
				'comment_status' => 'closed',
				'ping_status' => 'closed',
				'post_date' => $current_timestamp,
				'post_author' => $user_id)
			);
			update_post_meta($post_id,'content','<p>Hi {customer_name},</p><p>We noticed that you left some items behind in your cart, and we wanted to check in! Your order is just one click away from being completed, and we’d hate for you to miss out on your favorite items.</p><p><strong>Here’s a reminder of what you left behind:</strong></p><p>{product_name}</p><p>{total_price}</p><p>You can easily complete your purchase by clicking the link below to return to your cart:</p><p>[Complete Your Purchase Button/Link]</p><p>Still undecided? If you have any questions or need assistance with your order, don’t hesitate to reach out to us. We’re here to help!</p><p><strong>Special Offer:</strong></p><p>As a thank you for shopping with us, use code [COUPON CODE] to save [X% off] your order, valid for the next [X hours/days].</p><p>We hope to see you soon!</p><p>Best regards,</p><p>[Your Store Name]</p><p>[support email/contact link]</p>');
			update_post_meta($post_id,'event','Abandonment Order');
			update_post_meta($post_id,'trigger','10-minutes');
			update_post_meta($post_id,'type','default9');
			update_post_meta($post_id,'subject', 'Did You Forget Something? Your Cart Awaits!');
		}
		$post_ids10 = $wpdb->get_var($wpdb->prepare("SELECT p.ID FROM $post_table as p inner join {$wpdb->prefix}postmeta as pm on p.ID=pm.post_id WHERE (pm.meta_key=%s and pm.meta_value=%s)",'type','default10'));
		if(empty($post_ids10)){
			$post_id = wp_insert_post(
				array('post_title' => 'New User Registration Template',
				'post_type' => 'fup_email_template',
				'post_status' => 'publish',
				'post_content' => 'test',
				'post_excerpt' => 'test',
				'comment_status' => 'closed',
				'ping_status' => 'closed',
				'post_date' => $current_timestamp,
				'post_author' => $user_id)
			);
			update_post_meta($post_id,'content',' <p>Hi {first_name} {last_name}, </p><p>We’re thrilled to have you as part of the {site_name} community!</p><p> We hope you\'re finding your way around and starting to explore all we have to offer. </p><p>To ensure you\’re getting the best out of your experience, here are a few quick tips: </p><ol><li><strong>Update Your Profile</strong>: Complete your profile to customize your experience.</li><li><strong>Edit Profile Join the Conversation</strong>: Connect with other members and share your insights in our community forum. </li><li><strong>Visit Forum Stay Updated</strong>: Subscribe to our newsletter for the latest news, tips, and exclusive offers. Subscribe Now </li></ol><p>If you need any help along the way or have any questions, our support team is here for you. Feel free to reach out anytime! </p><p>We\’re excited to see you make the most of {site_name}. Let\’s get started! </p><p>Best regards, </p><p>The {site_name} </p><p>Team [support_email/contact_link]</p>');
			update_post_meta($post_id,'event','New User');
			update_post_meta($post_id,'trigger','10-minutes');
			update_post_meta($post_id,'type','default10');
			update_post_meta($post_id,'subject', 'Welcome to {site_name}! Let’s Get You Started!');
		}
		$post_ids11 = $wpdb->get_var($wpdb->prepare("SELECT p.ID FROM $post_table as p inner join {$wpdb->prefix}postmeta as pm on p.ID=pm.post_id WHERE (pm.meta_key=%s and pm.meta_value=%s)",'type','default11'));
		if(empty($post_ids11)){
			$post_id = wp_insert_post(
				array('post_title' => 'On Hold Template',
				'post_type' => 'fup_email_template',
				'post_status' => 'publish',
				'post_content' => 'test',
				'post_excerpt' => 'test',
				'comment_status' => 'closed',
				'ping_status' => 'closed',
				'post_date' => $current_timestamp,
				'post_author' => $user_id)
			);
			update_post_meta($post_id,'content','<p>Hi {customer_name}, </p><p>We wanted to follow up on your recent order with us. Currently, your order #{order_number} is on hold, and we wanted to make sure you’re aware of the status. </p><p><strong>Why is your order on hold? </strong></p><p>There could be several reasons for an order being placed on hold, such as: </p><ol><li>Payment processing issues </li><li>Stock availability concerns </li><li>Verification needed on your order details </li></ol><p>We’re here to help resolve any issues and get your order moving as quickly as possible. If there’s anything you’d like to clarify or if you believe the hold was placed in error, please reach out to us directly. </p><p><strong>How to Move Forward</strong>: </p><p><strong>Review Your Payment</strong>: If there’s any payment issue, please check your payment details and try again. </p><p><strong>Confirm Your Information</strong>: Double-check the details of your order to ensure everything is accurate. </p><p><strong>Get in Touch</strong>: If you\'re unsure about the hold, don’t hesitate to contact us. We’re here to assist you! </p><p>Once we’ve addressed the issue, we’ll update you promptly and process your order right away. We value your business and appreciate your patience!</p><p> Thank you for choosing {site_name}.</p><p> Best regards, </p><p>{site_name} Support </p><p>Team [support_email/contact_link]</p>');
			update_post_meta($post_id,'event','On-hold');
			update_post_meta($post_id,'trigger','10-minutes');
			update_post_meta($post_id,'type','default11');
			update_post_meta($post_id,'subject', 'Update on Your Order - {order_number} is On Hold');
		}
		$post_ids12 = $wpdb->get_var($wpdb->prepare("SELECT p.ID FROM $post_table as p inner join {$wpdb->prefix}postmeta as pm on p.ID=pm.post_id WHERE (pm.meta_key=%s and pm.meta_value=%s)",'type','default12'));
		if(empty($post_ids12)){
			$post_id = wp_insert_post(
				array('post_title' => 'Cancelled Order Template',
				'post_type' => 'fup_email_template',
				'post_status' => 'publish',
				'post_content' => 'test',
				'post_excerpt' => 'test',
				'comment_status' => 'closed',
				'ping_status' => 'closed',
				'post_date' => $current_timestamp,
				'post_author' => $user_id)
			);
			update_post_meta($post_id,'content',' <p>Hi {customer_name},</p><p>We noticed that your order (Order Number: {order_number}) was recently cancelled, and we wanted to check in to see if there’s anything we can assist you with.</p><p>If this cancellation was accidental or if you have any concerns or questions, please feel free to reach out to us. Our support team is always ready to help resolve any issues you might have.</p><p>If you’ve changed your mind or would like to place a new order, we’re happy to guide you through the process and make it as smooth as possible.</p><p>We truly value your business and would love to assist in any way we can.</p><p>Thank you for choosing {site_name}, and we hope to serve you again soon.</p><p><strong>Best regards,</strong></p><p>The {site_name}</p><p>Team [support_email/contact_link]</p> ');
			update_post_meta($post_id,'event','Cancelled Order');
			update_post_meta($post_id,'trigger','10-minutes');
			update_post_meta($post_id,'type','default12');
			update_post_meta($post_id,'subject', 'Need Help with Your Cancelled Order? We\'re Here to Assist!');
		}
		$post_ids13 = $wpdb->get_var($wpdb->prepare("SELECT p.ID FROM $post_table as p inner join {$wpdb->prefix}postmeta as pm on p.ID=pm.post_id WHERE (pm.meta_key=%s and pm.meta_value=%s)",'type','default13'));
		if(empty($post_ids13)){
			$post_id = wp_insert_post(
				array('post_title' => 'Gravity Form Template',
				'post_type' => 'fup_email_template',
				'post_status' => 'publish',
				'post_content' => 'test',
				'post_excerpt' => 'test',
				'comment_status' => 'closed',
				'ping_status' => 'closed',
				'post_date' => $current_timestamp,
				'post_author' => $user_id)
			);
			update_post_meta($post_id,'content','<p>Hi {customer_name},</p><p>Thanks for reaching out to us! We wanted to check in regarding your recent form submission to make sure everything is on track.</p><p>If you’ve already received a response from our team, that’s great! If not, or if you still have questions, don’t hesitate to let us know. We’re here to assist you and make sure your needs are addressed.</p><p>We understand that things can get busy, but please rest assured that we’re committed to providing the support you need and will get back to you promptly if further action is needed.</p><p>Thank you for contacting [Your Company Name]. We appreciate your patience, and we\'re here to help!</p><p>Best regards,</p><p>[Your Company Name] Team</p>');
			update_post_meta($post_id,'event','Gravity Form');
			update_post_meta($post_id,'trigger','10-minutes');
			update_post_meta($post_id,'type','default13');
			update_post_meta($post_id,'subject', 'We’re Following Up on Your Recent Inquiry');
		}
		$post_ids14 = $wpdb->get_var($wpdb->prepare("SELECT p.ID FROM $post_table as p inner join {$wpdb->prefix}postmeta as pm on p.ID=pm.post_id WHERE (pm.meta_key=%s and pm.meta_value=%s)",'type','default14'));
		if(empty($post_ids14)){
			$post_id = wp_insert_post(
				array('post_title' => 'Ninja Form Template',
				'post_type' => 'fup_email_template',
				'post_status' => 'publish',
				'post_content' => 'test',
				'post_excerpt' => 'test',
				'comment_status' => 'closed',
				'ping_status' => 'closed',
				'post_date' => $current_timestamp,
				'post_author' => $user_id)
			);
			update_post_meta($post_id,'content','<p>Hi {customer_name},</p><p>Thanks for reaching out to us! We wanted to check in regarding your recent form submission to make sure everything is on track.</p><p>If you’ve already received a response from our team, that’s great! If not, or if you still have questions, don’t hesitate to let us know. We’re here to assist you and make sure your needs are addressed.</p><p>We understand that things can get busy, but please rest assured that we’re committed to providing the support you need and will get back to you promptly if further action is needed.</p><p>Thank you for contacting [Your Company Name]. We appreciate your patience, and we\'re here to help!</p><p>Best regards,</p><p>[Your Company Name] Team</p>');
			update_post_meta($post_id,'event','Ninja Form');
			update_post_meta($post_id,'trigger','10-minutes');
			update_post_meta($post_id,'type','default14');
			update_post_meta($post_id,'subject', 'We’re Following Up on Your Recent Inquiry');
		}
		$post_ids15 = $wpdb->get_var($wpdb->prepare("SELECT p.ID FROM $post_table as p inner join {$wpdb->prefix}postmeta as pm on p.ID=pm.post_id WHERE (pm.meta_key=%s and pm.meta_value=%s)",'type','default15'));
		if(empty($post_ids15)){
			$post_id = wp_insert_post(
				array('post_title' => 'WP Form Submission Template',
				'post_type' => 'fup_email_template',
				'post_status' => 'publish',
				'post_content' => 'test',
				'post_excerpt' => 'test',
				'comment_status' => 'closed',
				'ping_status' => 'closed',
				'post_date' => $current_timestamp,
				'post_author' => $user_id)
			);
			update_post_meta($post_id,'content','<p>Hi {customer_name},</p><p>Thanks for reaching out to us! We wanted to check in regarding your recent form submission to make sure everything is on track.</p><p>If you’ve already received a response from our team, that’s great! If not, or if you still have questions, don’t hesitate to let us know. We’re here to assist you and make sure your needs are addressed.</p><p>We understand that things can get busy, but please rest assured that we’re committed to providing the support you need and will get back to you promptly if further action is needed.</p><p>Thank you for contacting [Your Company Name]. We appreciate your patience, and we\'re here to help!</p><p>Best regards,</p><p>[Your Company Name] Team</p>');
			update_post_meta($post_id,'event','WP Form Submission');
			update_post_meta($post_id,'trigger','10-minutes');
			update_post_meta($post_id,'type','default15');
			update_post_meta($post_id,'subject', 'We’re Following Up on Your Recent Inquiry');
		}
		$post_ids16 = $wpdb->get_var($wpdb->prepare("SELECT p.ID FROM $post_table as p inner join {$wpdb->prefix}postmeta as pm on p.ID=pm.post_id WHERE (pm.meta_key=%s and pm.meta_value=%s)",'type','default16'));
		if(empty($post_ids16)){
			$post_id = wp_insert_post(
				array('post_title' => 'Formidable Form Template',
				'post_type' => 'fup_email_template',
				'post_status' => 'publish',
				'post_content' => 'test',
				'post_excerpt' => 'test',
				'comment_status' => 'closed',
				'ping_status' => 'closed',
				'post_date' => $current_timestamp,
				'post_author' => $user_id)
			);
			update_post_meta($post_id,'content','<p>Hi {customer_name},</p><p>Thanks for reaching out to us! We wanted to check in regarding your recent form submission to make sure everything is on track.</p><p>If you’ve already received a response from our team, that’s great! If not, or if you still have questions, don’t hesitate to let us know. We’re here to assist you and make sure your needs are addressed.</p><p>We understand that things can get busy, but please rest assured that we’re committed to providing the support you need and will get back to you promptly if further action is needed.</p><p>Thank you for contacting [Your Company Name]. We appreciate your patience, and we\'re here to help!</p><p>Best regards,</p><p>[Your Company Name] Team</p>');
			update_post_meta($post_id,'event','Formidable Form');
			update_post_meta($post_id,'trigger','10-minutes');
			update_post_meta($post_id,'type','default16');
			update_post_meta($post_id,'subject', 'We’re Following Up on Your Recent Inquiry');
		}
		$post_ids17 = $wpdb->get_var($wpdb->prepare("SELECT p.ID FROM $post_table as p inner join {$wpdb->prefix}postmeta as pm on p.ID=pm.post_id WHERE (pm.meta_key=%s and pm.meta_value=%s)",'type','default17'));
		if(empty($post_ids17)){

			$post_id = wp_insert_post(
				array('post_title' => 'Contact Form Template',
				'post_type' => 'fup_email_template',
				'post_status' => 'publish',
				'post_content' => 'test',
				'post_excerpt' => 'test',
				'comment_status' => 'closed',
				'ping_status' => 'closed',
				'post_date' => $current_timestamp,
				'post_author' => $user_id)
			);
			update_post_meta($post_id,'content','<p>Hi,</p><p>Thanks for reaching out to us! We wanted to check in regarding your recent form submission to make sure everything is on track.</p><p>If you’ve already received a response from our team, that’s great! If not, or if you still have questions, don’t hesitate to let us know. We’re here to assist you and make sure your needs are addressed.</p><p>We understand that things can get busy, but please rest assured that we’re committed to providing the support you need and will get back to you promptly if further action is needed.</p><p>Thank you for contacting [Your Company Name]. We appreciate your patience, and we\'re here to help!</p><p>Best regards,</p><p>[Your Company Name] Team</p>');
			update_post_meta($post_id,'event','CF Submission');
			update_post_meta($post_id,'trigger','10-minutes');
			update_post_meta($post_id,'type','default17');
			update_post_meta($post_id,'subject', 'We’re Following Up on Your Recent Inquiry');
		}
		
    }

	public static function fupesm_placeholder_function($content,$user_id=null,$order_id=null,$form_id=null,$entry_id=null,$event=null){
		
		global $wpdb;
		$site_name = get_bloginfo('name');
		if($event == 'New User'){
			$user=get_user_by('ID', $user_id);
			$usermeta_data = get_user_meta($user_id);
			$user_login = $user->user_login;
			$user_email = $user->user_email;
			$display_name =$user->display_name;
			$user_role = $user->roles;
			$first_name = $usermeta_data['first_name'][0];
			$last_name = $usermeta_data['last_name'][0];
			$user_nicename = $usermeta_data['user_nicename'][0];
			$user_registered = $usermeta_data['user_registered'][0];
			$nickname = $usermeta_data['nickname'][0];
			$user_url = $user->user_url;
			$content = str_replace('{user_login}', $user_login, $content);
			$content = str_replace('{first_name}', $first_name, $content);
			$content = str_replace('{last_name}', $last_name, $content);
			$content = str_replace('{display_name}', $display_name, $content);
			$content = str_replace('{user_role}',$user_role[0], $content);
			$content = str_replace('{user_email}', $user_email, $content);
			$content = str_replace('{user_nicename}',$user_nicename,$content);
			$content = str_replace('{user_registered}',$user_registered,$content);
			$content = str_replace('{user_url}',$user_url,$content);
			$content = str_replace('{nickname}',$nickname,$content);
		}
		if($event == 'Abandonment Order'){
			$cart_id = $user_id;
			$product_id = $order_id;
			$user_id = $form_id;
			$user_data = get_user_meta($user_id);
			foreach ($user_data as $user_key => $user_val) {
				if (strpos($user_key, "_woocommerce_persistent_cart") !== false) {
					$unserialize_data = unserialize($user_val[0]);
				}
			}
			$u_data = $unserialize_data["cart"];
			if (!empty($u_data)) {
				foreach ($u_data as $data_key => $data_value) {
					if ($data_key == $cart_id) {
						$cart_id = $data_value['key'];
						$product_id = $data_value['product_id'];
						$quantity = $data_value['quantity'];
						$total_price = $data_value['line_total'];
						$customer_id = $user_id;
						if(!empty($customer_id)){
							$user_info = get_userdata($customer_id);
							$customer_email = $user_info->user_email;
							$customer_name = $user_info->user_login;

						}
						$products =wc_get_product($product_id);
						$product_name  = $products->get_name();
						$content = str_replace('{cart_id}',$cart_id,$content);
						$content = str_replace('{product_id}',$product_id,$content);
						$content = str_replace('{quantity}',$quantity,$content);
						$content = str_replace('{total_price}',$total_price,$content);
						$content = str_replace('{product_name}',$product_name,$content);
						$content = str_replace('{customer_name}',$customer_name,$content);
						
					}
				}
			}
		}
		if($event == 'New Order' || $event == 'Completed Order' || $event == 'On-hold' || $event == 'Cancelled Order' || $event == 'Refunded Order' || $event == 'Failed Order' || $event == 'Processing Order'){

			$order = new \WC_Order($order_id);
			$orders = wc_get_order($order_id);
			$order_data = $order->get_data();
			$billingaddress = $order->get_address('billing');
			$shippingaddress = $order->get_address('shipping');
			$order_key=$order->get_order_key();
			$order_link = wc_get_endpoint_url('view-order', $order_id, wc_get_page_permalink('myaccount')) . '?key=' . $order_key;
			$last_name = $billingaddress['last_name'];
			$billing_first_name = $billingaddress['first_name'];
			$billing_last_name = $last_name;
			$billing_email = $billingaddress['email'];
			$billing_phone = $billingaddress['phone'];
			$billing_country = $billingaddress['country'];
			$billing_state = $billingaddress['state'];
			$billing_city = $billingaddress['city'];
			$billing_company = $billingaddress['company'];
			$billing_address_one = $billingaddress['address_1'];
			$billing_address_two = $billingaddress['address_2'];
			$billing_postcode = $billingaddress['postcode'];
			$shipping_first_name = $name;
			$shipping_last_name = $last_name;
			$shipping_email = $shippingaddress['email'];
			$shipping_phone = $shippingaddress['phone'];
			$shipping_country = $shippingaddress['country'];
			$shipping_state = $shippingaddress['state'];
			$shipping_city = $shippingaddress['city'];
			$shipping_company = $shippingaddress['company'];
			$shipping_address_one = $shippingaddress['address_1'];
			$shipping_address_two = $shippingaddress['address_2'];
			$shipping_postcode = $shippingaddress['postcode'];
			$order_date = $order_data['date_created'];
			$order_currency = $order_data['currency'];
			$customer_note = $order_data['customer_note'];
			$customer_id = $order_data['customer_id'];
			$order_total = $order_data['total'];
			$recorded_sales = $order_data['recorded_sales'];
			$payment_method = $order_data['payment_method'];
			$transaction_id = $order_data['transaction_id'];
			$line_items = $order->get_items();
			$item_names = array();
			if(!empty($line_items)){
				foreach ($line_items as $item_id => $item) {
					$item_names[] = $item->get_name();
					$item_types[] = $item->get_type();
					$item_variation_id[] = $item->get_variation_id();
					$item_product_id[] = $item->get_product_id();
				}
			}
			$item_name = !empty($item_names) ? implode(',', $item_names) : '';
			$item_type = !empty($item_types) ? implode(',', $item_types) : '';
			$item_variation = !empty($item_varitaion_id) ? implode(',', $item_varitaion_id) : '';
			$item_product= !empty($item_product_id) ? implode(',', $item_product_id) : '';


			if(!empty($customer_id)){
				$user_info = get_userdata($customer_id);
				$customer_name = $user_info->user_email;
			}

			$content = str_replace('{billing_email}',$billing_email,$content);
			$content = str_replace('{billing_phone}',$billing_phone,$content);
			$content = str_replace('{billing_city}',$billing_city,$content);
			$content = str_replace('{billing_country}',$billing_country,$content);
			$content = str_replace('{billing_state}',$billing_state,$content);
			$content = str_replace('{billing_address_1}',$billing_address_one,$content);
			$content = str_replace('{billing_address_2}',$billing_address_two,$content);
			$content = str_replace('{billing_postcode}',$billing_postcode,$content);
			$content = str_replace('{shipping_email}',$shipping_email,$content);
			$content = str_replace('{shipping_phone}',$shipping_phone,$content);
			$content = str_replace('{shipping_city}',$shipping_city,$content);
			$content = str_replace('{shipping_country}',$shipping_country,$content);
			$content = str_replace('{shipping_state}',$shipping_state,$content);
			$content = str_replace('{shipping_address_1}',$shipping_address_one,$content);
			$content = str_replace('{shipping_address_2}',$shipping_address_two,$content);
			$content = str_replace('{shipping_postcode}',$shipping_postcode,$content);
			$content = str_replace('{order_number}',$order_id,$content);
			$content = str_replace('{order_date}',$order_date,$content);
			$content = str_replace('{customer_note}',$customer_note,$content);
			$content = str_replace('{order_currency}',$order_currency,$content);
			$content = str_replace('{customer_name}',$customer_name,$content);
			$content = str_replace('{order_total}',$order_total,$content);
			$content = str_replace('{site_name}',$site_name,$content);
			$content = str_replace('{item_name}',$item_name,$content);
			$content = str_replace('{item_type}',$item_type,$content);
			$content = str_replace('{item_variation}',$item_variation,$content);
			$content = str_replace('{item_product}',$item_product,$content);
			$content = str_replace('{billing_first_name}',$billing_first_name,$content);
			$content = str_replace('{billing_last_name}',$billing_last_name,$content);
			$content = str_replace('{shipping_last_name}',$shipping_last_name,$content);
			$content = str_replace('{shipping_first_name}',$shipping_first_name,$content);
			$content = str_replace('{recorded_sales}',$recorded_sales,$content);
			$content = str_replace('{payment_method}',$payment_method,$content);
			$content = str_replace('{transaction_id}',$transaction_id,$content);
			$content = str_replace('{order_link}',$order_link,$content);
		}

		//die('pp');
		if($event == "WP Form Submission"){
			$wpform_table = $wpdb->prefix.'wpforms_entries';
			$fields = $wpdb->get_results($wpdb->prepare("SELECT fields FROM $wpform_table WHERE form_id=%d and entry_id=%d",$form_id,$entry_id),ARRAY_A);
			foreach($fields as $field_key => $field_val){
				$wpform_fields = json_decode($field_val['fields']);
				foreach($wpform_fields as $wpforms_value){
					$name = $wpforms_value->name;
					$values = $wpforms_value->value;
					$content = str_replace('{'.$name.'}',$values,$content);
				}
			}
		}
		elseif($event == "Gravity Form"){
			
			$gravity_form_table = $wpdb->prefix.'gf_form_meta';
			$fields = $wpdb->get_results($wpdb->prepare("SELECT display_meta FROM $gravity_form_table WHERE form_id=%d",$form_id),ARRAY_A);
			foreach($fields as $fields_val){
				$gf_fields = json_decode($fields_val['display_meta']);
				$field_data = $gf_fields->fields;
				$field_list = array();
				foreach($field_data as $fieldkey =>$fieldval){
					$field_list[$fieldval->id] = $fieldval->label;
				}
			}
			$gravity_entry_table = $wpdb->prefix.'gf_entry_meta';
			$entry_fields = $wpdb->get_results($wpdb->prepare("SELECT meta_key,meta_value FROM $gravity_entry_table WHERE form_id=%d and entry_id=%d",$form_id,$entry_id),ARRAY_A);
			$entry_list = array();
			foreach($entry_fields as $entry_key => $entry_val){
				$entry_list[$entry_val['meta_key']] = $entry_val['meta_value'];
			}

			foreach($field_list as $field_k => $field_value){
				$name = $field_list[$field_k];
				$values = $entry_list[$field_k];
				$content = str_replace('{'.$name.'}',$values,$content);

			}
		}
		elseif($event == 'Formidable Form'){
			$frm_fields_table = $wpdb->prefix.'frm_fields';
			$field_list = $wpdb->get_results($wpdb->prepare("SELECT name ,type , id FROM $frm_fields_table WHERE form_id=%d",$form_id),ARRAY_A);
			$fields_entry_table = $wpdb->prefix.'frm_item_metas';
			$entry_list = $wpdb->get_results($wpdb->prepare("SELECT meta_value , field_id FROM $fields_entry_table WHERE item_id=%d",$entry_id),ARRAY_A);
			//  $final_field_list = array();
			$entry_values = array();
			foreach($entry_list  as $entry_key => $entry_val){
				$entry_values[$entry_val['field_id']] = $entry_val['meta_value'];
			}
			$final_field_list = array();
			foreach($field_list as $field_key => $field_val){
				$final_field_list[$field_val['id']] = $field_val['name'];
			}
			foreach($final_field_list as $field_k => $field_v){
				$name = $final_field_list[$field_k];
				$values = $entry_values[$field_k];
				$content = str_replace('{'.$name.'}',$values,$content);
			}
		}
		elseif($event == 'Ninja Form'){
			$ninja_field_table = $wpdb->prefix.'nf3_fields';
			$ninja_field_list = array();
			$ninja_fields = $wpdb->get_results($wpdb->prepare("SELECT id,`key`,label FROM $ninja_field_table WHERE parent_id = %d",$form_id),ARRAY_A);
			foreach($ninja_fields as $ninja_key => $ninja_val){
				$ninja_field_list[$ninja_val['id']] = $ninja_val['label'];
			}
			$entry_table = $wpdb->prefix.'postmeta';
			$ninja_entry_list = array();
			$ninja_entry = $wpdb->get_results($wpdb->prepare("SELECT meta_value,meta_key FROM $entry_table WHERE post_id = %d AND meta_key like %s",$entry_id,'%_field_%'),ARRAY_A);
			foreach($ninja_entry as $entry_key => $entry_val){
				$entry_k = str_replace('_field_', '', $entry_val['meta_key']);
				$ninja_entry_list[$entry_k] = $entry_val['meta_value'];
			}
			foreach($ninja_field_list as $field_k => $field_v){
				$name = $ninja_field_list[$field_k];
				$values = $ninja_entry_list[$field_k];
				$content = str_replace('{'.$name.'}',$values ?? '',$content);

			}
		}
		$site_name = get_bloginfo( 'name' );
		$content = str_replace('{site_name}',$site_name,$content);

		return $content;
	}


}