<?php

/**
 * @package: EGPS - Easy Sell for Google Photo
 * 
 * EGPS Email sending class
 */

 if(!defined('ABSPATH')){
  exit; // Exit if accessed directly
}


class EgpsEmailSend{

    private static $emaildata;
    private static $fromemail, $fromname;

    function __construct(){
      
      $dataout = get_option('egps_email_settings_options');

      if( $dataout != false){
        
        self::$fromemail = $dataout['sender_email'] . "@" . get_bloginfo();
        self::$fromname = $dataout['sender_name'];

      }
      
    }


    public function egpsEmailGetFields(){

        $field_array = array(
            "subject"       => "Welcome to the ". get_bloginfo("", "name") ." Family! 🎉",
            "title"         => "Your sign up was successful",
            "intro"         => "Dear Friend,

A warm welcome and a big thank you for registering with us at <b>". get_bloginfo("", "name") ."!</b> 
We’re so excited to have you on board and can’t wait to embark on this incredible journey together. 🌟

You’ve unlocked a world where capturing moments becomes a part of your daily life, not just a task. Our community thrives on creativity, passion, and the stories that each photo tells. You’re now a vital part of this ever-growing family.",

            "text_main"     => "To get started, why not head over to our website and dive into some of our latest content? And remember, our community is always here for you. 

If you have any questions, suggestions, or just want to share your first photo experience with us, don’t hesitate to reach out at Support Email or Support Phone Number.
            
Thank you once again for choosing ". get_bloginfo("", "name") .". Here’s to the beginning of a beautiful friendship and lots of picture-perfect moments.

Warmest regards,
". get_bloginfo("", "name") ."'s Team",

            "text_bottom"   => "P.S. We love to grow our family! If you know someone who shares your passion for photography, feel free to invite them to join us too. Let’s make the world a more beautiful place, one photo at a time. 📷✨",

            "url_text"      => "Visit our website by clicking here.",
            "url"           => get_site_url() . "/photoalbum",
            "link_insta"    => "https://instagram.com",
            "link_twit"     => "#",
            "link_fb"       => "https://facebook.com"
        );
        return $field_array;
    }


    public function egpsEmailGetFieldsOrder(){

      $field_array = array(
          "subject"       => "📸 Your purchase details 🌟",
          "title"         => "Thank you for choosing us",
          "intro"         => "Dear [customer_name],
          
We're thrilled to let you know that your recent purchase of photos from <b>". get_bloginfo("", "name") ."</b> has been successfully processed! 🎉
            
From the entire team here, a huge THANK YOU for choosing us. We're truly honored to have the opportunity to share our passion for photography with you. Each photo is captured with care and tells a unique story, aiming to bring inspiration, beauty, and a touch of magic into your space.
            
Your support means the world to us and fuels our creativity and drive to continue capturing the breathtaking moments that our planet has to offer. We hope these photos bring as much joy to you as we felt in taking them.",
          
          "text_main"     => "🔍 For any queries or if you need further assistance, please don't hesitate to reach out to our customer support team at [Support Email] or give us a call at [Support Phone Number]. We're here to help!

Stay connected with us on Social Media to get a sneak peek of our upcoming collections, exclusive offers, and more behind-the-scenes magic.

Once again, thank you for your trust and support.

Warmest regards,
". get_bloginfo("", "name") ."'s Team
          ",

          "text_bottom"   => "P.S. We love seeing our photos in their new homes! Feel free to share your displays with us on social media or via email.
It might just make our day! 🌈✨",
          
          "url_text"      => "Download your photos from your account",
          "url"           => get_site_url() . "/egpslogin",
          "link_insta"    => "https://instagram.com",
          "link_twit"     => "#",
          "link_fb"       => "https://facebook.com"
      );
      return $field_array;
  }


    public function egpsEmailFieldData($egps_email_opt, $field_array){

        $dataout = array();

        foreach($field_array as $key => $val ){

            if(isset($egps_email_opt[ $key ]) && $egps_email_opt[ $key ] != ""){
                $dataout[ $key ] = $egps_email_opt[ $key ];
            }else{
                $dataout[ $key ] = $val;
            }
    
        }

        self::$emaildata = $dataout;

        return $dataout;

    }


    public static function egpsEmailRegister($userdata){

        self::$emaildata["toemail"] = $userdata["email"];

        self::egpsEmailSending();

    }


    public static function egpsEmailPhotoPurchase($userdata){

      self::$emaildata["toemail"] = $userdata["email"];

      self::egpsEmailSending();

    }


    public static function egpsEmailSending(){

      $cust = EgpsOrders::getAllOrdersByCustomer(self::$emaildata["toemail"], "1");

      try{

          $to = self::$emaildata["toemail"];
          $subject = self::$emaildata["subject"];
          $headers = array( 
            'Content-Type: text/html; charset=UTF-8',
            'From: '. self::$fromname .' <'. self::$fromemail .'>'
          );
          $body = self::egpsEmailTemplate();

          //email variables
          if( !empty($cust)){
            $body = str_replace("[customer_name]", $cust[0]->customer_name, $body);
          }

          $retmail = wp_mail( $to, $subject, $body, $headers );

          return true;

      }catch(Exception $e){
            Egps::egps_vardump($e);
      }
      return false;

    }


    public static function egpsEmailTemplate(){

      $logo = Egps::egps_getlogo();

        $mailbody = '<body class="clean-body u_body" style="
                                    margin: 0;
                                    padding: 0;
                                    padding-top: 25px;
                                    -webkit-text-size-adjust: 100%;
                                    background-image: linear-gradient(to bottom, #116466, #00c9cc);
                                    color: #000000
                                    ">
  <table id="u_body" style="border-collapse: collapse;table-layout: fixed;border-spacing: 0;mso-table-lspace: 0pt;mso-table-rspace: 0pt;vertical-align: top;min-width: 320px;Margin: 0 auto;background-color: transparent;width:100%" cellpadding="0" cellspacing="0">
  <tbody>
  <tr style="vertical-align: top">
    <td style="word-break: break-word;border-collapse: collapse !important;vertical-align: top">
    
  
  
<div class="u-row-container" style="padding: 0px;background-color: transparent">
  <div class="u-row" style="margin: 0 auto;min-width: 320px;max-width: 600px;overflow-wrap: break-word;word-wrap: break-word;word-break: break-word;background-color: transparent;">
    <div style="border-collapse: collapse;display: table;width: 100%;height: 100%;background-color: transparent;">
      
<div class="u-col u-col-100" style="max-width: 320px;min-width: 600px;display: table-cell;vertical-align: top;">
  <div style="background-color: #ffffff;height: 100%;width: 100% !important;border-radius:30px 30px 0px 0px">
  
<table id="u_content_image_1" style="font-family:\'Raleway\',sans-serif;" role="presentation" cellpadding="0" cellspacing="0" width="100%" border="0">
  <tbody>
    <tr>
      <td class="v-container-padding-padding" style="overflow-wrap:break-word;word-break:break-word;padding:60px 10px 10px;font-family:\'Raleway\',sans-serif;" align="left">
        
<table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr>
    <td style="padding-right: 0px;padding-left: 0px;" align="center">
      
      <img 
        align="center" 
        border="0" 
        src="'. esc_html($logo[0]) .'" 
        alt="" 
        title="Site logo" 
        style="outline: none;text-decoration: none;-ms-interpolation-mode: bicubic;clear: both;display: inline-block !important;border: none;height: auto;float: none;width: 35%;max-width: 150px;" 
        width="150" 
        class="v-src-width v-src-max-width"/>
      
    </td>
  </tr>
</table>

      </td>
    </tr>
  </tbody>
</table>

<table id="u_content_heading_1" style="font-family:\'Raleway\',sans-serif;" role="presentation" cellpadding="0" cellspacing="0" width="100%" border="0">
  <tbody>
    <tr>
      <td class="v-container-padding-padding" style="overflow-wrap:break-word;word-break:break-word;padding:10px 10px 30px;font-family:\'Raleway\',sans-serif;" align="left">
        
    <h1 class="v-font-size" style="margin: 0px; line-height: 140%; text-align: center; word-wrap: break-word; font-size: 28px; font-weight: 400;">
        <strong>' . esc_html(self::$emaildata["title"]) . '</strong>
    </h1>

      </td>
    </tr>
  </tbody>
</table>

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

  <div class="u-row-container" style="padding: 0px;background-color: transparent">
  <div class="u-row" style="margin: 0 auto;min-width: 320px;max-width: 600px;overflow-wrap: break-word;word-wrap: break-word;word-break: break-word;background-color: transparent;">
    <div style="border-collapse: collapse;display: table;width: 100%;height: 100%;background-color: transparent;">
      
<div class="u-col u-col-100" style="max-width: 320px;min-width: 600px;display: table-cell;vertical-align: top;">
  <div style="background-color: #ffffff;height: 100%;width: 100% !important;border-radius: 0px;-webkit-border-radius: 0px; -moz-border-radius: 0px;border-radius:0px 0px 30px 30px;">
';  


if( self::$emaildata["intro"] != "#"){
    $mailbody .= '<table id="u_content_heading_2" style="font-family:\'Raleway\',sans-serif;" role="presentation" cellpadding="0" cellspacing="0" width="100%" border="0">
  <tbody>
    <tr>
      <td class="v-container-padding-padding" style="overflow-wrap:break-word;word-break:break-word;padding:40px 60px 10px;font-family:\'Raleway\',sans-serif;" align="left">
        
    <h1 class="v-font-size" style="margin: 0px; line-height: 140%; text-align: left; word-wrap: break-word; font-size: 16px; font-weight: 400;">
        <pre class="egps_admin_email_css" style="white-space: pre-wrap;">' . self::$emaildata["intro"]. '</pre>
    </h1>

      </td>
    </tr>
  </tbody>
</table>';
}


if( self::$emaildata["url"] != "#"){
    $mailbody .= '<table id="u_content_text_2" style="font-family:\'Raleway\',sans-serif;" role="presentation" cellpadding="0" cellspacing="0" width="100%" border="0">
  <tbody>
    <tr>
      <td class="v-container-padding-padding" style="overflow-wrap:break-word;word-break:break-word;padding:10px 60px;font-family:\'Raleway\',sans-serif;" align="left">
        
  <div class="v-font-size" style="font-size: 14px; color: #1386e5; line-height: 140%; text-align: left; word-wrap: break-word;">
    <p style="line-height: 140%;">
        <span style="text-decoration: underline; line-height: 19.6px;">
            <span style="line-height: 19.6px;">
                <strong><a href="' . esc_url(self::$emaildata["url"]) . '">' . esc_html(self::$emaildata["url_text"]) .'</strong>
            </span>
        </span>
    </p>
  </div>

      </td>
    </tr>
  </tbody>
</table>
';
}


if( self::$emaildata["text_main"] != "#" ){
$mailbody .= '<table id="u_content_heading_3" style="font-family:\'Raleway\',sans-serif;" role="presentation" cellpadding="0" cellspacing="0" width="100%" border="0">
  <tbody>
    <tr>
      <td class="v-container-padding-padding" style="overflow-wrap:break-word;word-break:break-word;padding:10px 60px;font-family:\'Raleway\',sans-serif;" align="left">
        
    <h1 class="v-font-size" style="margin: 0px; line-height: 140%; text-align: left; word-wrap: break-word; font-size: 14px; font-weight: 400;">
        
    <pre class="egps_admin_email_css" style="white-space: pre-wrap;">'. self::$emaildata["text_main"] .'</pre>
    
    </h1>

      </td>
    </tr>
  </tbody>
</table>';
}

$mailbody .= '
  </div>
</div>
    </div>
  </div>
  </div>
  


  
  
<div class="u-row-container" style="padding: 0px;background-color: transparent">
  <div class="u-row" style="margin: 0 auto;min-width: 320px;max-width: 600px;overflow-wrap: break-word;word-wrap: break-word;word-break: break-word;background-color: transparent;">
    <div style="border-collapse: collapse;display: table;width: 100%;height: 100%;background-color: transparent;">
      
<div class="u-col u-col-100" style="max-width: 320px;min-width: 600px;display: table-cell;vertical-align: top;">
  <div style="height: 100%;width: 100% !important;border-radius: 0px;-webkit-border-radius: 0px; -moz-border-radius: 0px;">
  
<table id="u_content_social_1" style="font-family:\'Raleway\',sans-serif;" role="presentation" cellpadding="0" cellspacing="0" width="100%" border="0">
  <tbody>
    <tr>
      <td class="v-container-padding-padding" style="overflow-wrap:break-word;word-break:break-word;padding:40px 10px 10px;font-family:\'Raleway\',sans-serif;" align="left">
        
<div align="center">
  <div style="display: table; max-width:167px;">
';  



if(self::$emaildata["link_fb"] != "#"){
    $mailbody .= '
    <table align="left" border="0" cellspacing="0" cellpadding="0" width="32" height="32" style="width: 32px !important;height: 32px !important;display: inline-block;border-collapse: collapse;table-layout: fixed;border-spacing: 0;mso-table-lspace: 0pt;mso-table-rspace: 0pt;vertical-align: top;margin-right: 10px">
      <tbody><tr style="vertical-align: top"><td align="left" valign="middle" style="word-break: break-word;border-collapse: collapse !important;vertical-align: top">
        <a 
            href="'. esc_url(self::$emaildata["link_fb"]). '" 
            title="Facebook" 
            target="_blank">
            <img 
                src="'. plugin_dir_url(__DIR__) .'public/images/fb.png" 
                alt="Facebook" 
                title="Facebook" 
                width="32" 
                style="outline: none;text-decoration: none;-ms-interpolation-mode: bicubic;clear: both;display: block !important;border: none;height: auto;float: none;max-width: 32px !important">
        </a>
      </td></tr>
    </tbody></table>';

}


if(self::$emaildata["link_twit"] != "#"){
    
    $mailbody .= '
    <table align="left" border="0" cellspacing="0" cellpadding="0" width="32" height="32" style="width: 32px !important;height: 32px !important;display: inline-block;border-collapse: collapse;table-layout: fixed;border-spacing: 0;mso-table-lspace: 0pt;mso-table-rspace: 0pt;vertical-align: top;margin-right: 10px">
      <tbody><tr style="vertical-align: top"><td align="left" valign="middle" style="word-break: break-word;border-collapse: collapse !important;vertical-align: top">
        <a 
            href="'. esc_url(self::$emaildata["link_twit"]) .'" 
            title="X (Twitter)" 
            target="_blank">
            <img 
                src="'.plugin_dir_url(__DIR__).'public/images/twitter.png" 
                alt="X (Twitter)" 
                title="X (Twitter)" 
                width="32" 
                style="outline: none;text-decoration: none;-ms-interpolation-mode: bicubic;clear: both;display: block !important;border: none;height: auto;float: none;max-width: 32px !important">
        </a>
      </td></tr>
    </tbody></table>
    ';

}
    
if(self::$emaildata["link_insta"] != "#"){

    $mailbody .= '
    <table align="left" border="0" cellspacing="0" cellpadding="0" width="32" height="32" style="width: 32px !important;height: 32px !important;display: inline-block;border-collapse: collapse;table-layout: fixed;border-spacing: 0;mso-table-lspace: 0pt;mso-table-rspace: 0pt;vertical-align: top;margin-right: 10px">
      <tbody><tr style="vertical-align: top"><td align="left" valign="middle" style="word-break: break-word;border-collapse: collapse !important;vertical-align: top">
        <a 
            href="'. esc_url(self::$emaildata["link_insta"]) .'" 
            title="Instagram" 
            target="_blank">
            <img 
                src="'.plugin_dir_url(__DIR__).'public/images/insta.png" 
                alt="Instagram" 
                title="Instagram" 
                width="32" 
                style="outline: none;text-decoration: none;-ms-interpolation-mode: bicubic;clear: both;display: block !important;border: none;height: auto;float: none;max-width: 32px !important">
        </a>
      </td></tr>
    </tbody></table>
    ';
}
    


$mailbody .= '
  </div>
</div>

      </td>
    </tr>
  </tbody>
</table>

<table id="u_content_text_deprecated_1" style="font-family:\'Raleway\',sans-serif;" role="presentation" cellpadding="0" cellspacing="0" width="100%" border="0">
  <tbody>
    <tr>
      <td class="v-container-padding-padding" style="overflow-wrap:break-word;word-break:break-word;padding:10px 100px 30px;font-family:\'Raleway\',sans-serif;" align="left">
        
  <div class="v-font-size" style="font-size: 14px; line-height: 170%; text-align: center; word-wrap: break-word;">
    <p style="font-size: 14px; line-height: 170%;">';

    $pplink = get_the_privacy_policy_link();
    if($pplink != ""){
        $mailbody .= '<a href="'. esc_url($pplink) .'">PRIVACY POLICY</a> | ';
    }
        
    $mailbody .= '<a href="' . get_site_url() . '">WEB</a>
    </p>';


    if( self::$emaildata["text_bottom"] != "#"){
        $mailbody .= '<p style="font-size: 14px; line-height: 170%;"></p>
        <p style="font-size: 14px; line-height: 170%;">

            <pre class="egps_admin_email_css" style="white-space: pre-wrap;">'. self::$emaildata["text_bottom"] .'</pre>

        </p>';
    }


  $mailbody .= '</div>

      </td>
    </tr>
  </tbody>
</table>

<table style="font-family:\'Raleway\',sans-serif;" role="presentation" cellpadding="0" cellspacing="0" width="100%" border="0">
  <tbody>
    <tr>
      <td class="v-container-padding-padding" style="overflow-wrap:break-word;word-break:break-word;padding:0px;font-family:\'Raleway\',sans-serif;" align="left">
        
  <table height="0px" align="center" border="0" cellpadding="0" cellspacing="0" width="100%" style="border-collapse: collapse;table-layout: fixed;border-spacing: 0;mso-table-lspace: 0pt;mso-table-rspace: 0pt;vertical-align: top;border-top: 1px solid #BBBBBB;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%">
    <tbody>
      <tr style="vertical-align: top">
        <td style="word-break: break-word;border-collapse: collapse !important;vertical-align: top;font-size: 0px;line-height: 0px;mso-line-height-rule: exactly;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%">
          <span>&#160;</span>
        </td>
      </tr>
    </tbody>
  </table>

      </td>
    </tr>
  </tbody>
</table>

<table id="u_content_image_2" style="font-family:\'Raleway\',sans-serif;" role="presentation" cellpadding="0" cellspacing="0" width="100%" border="0">
  <tbody>
    <tr>
      <td class="v-container-padding-padding" style="overflow-wrap:break-word;word-break:break-word;padding:30px 10px 40px;font-family:\'Raleway\',sans-serif;" align="left">
        
<table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr>
    <td style="padding-right: 0px;padding-left: 0px;" align="center">
      
      <img 
        align="center" 
        border="0" 
        src="'. esc_html($logo[0]) .'" 
        alt="" 
        title="Site logo" 
        style="outline: none;text-decoration: none;-ms-interpolation-mode: bicubic;clear: both;display: inline-block !important;border: none;height: auto;float: none;width: 100%;max-width: 100px;" 
        width="100" 
        class="v-src-width v-src-max-width"/>
      
    </td>
  </tr>
</table>

      </td>
    </tr>
  </tbody>
</table>';

return $mailbody;

    }


}