<?php

class Cliente extends Email
{
  public $customer = false;

  public function __construct($registry)
  {
    parent::__construct($registry);
  }

  public function getCustomerInfo($cliente_id)
  {
    $this->load->type('tipocomum');
    $this->load->type('tipofuturaserver');
    $this->language->load('mail/customer');
    $this->load->dmodel('account/customer');

    $this->customer = $this->dmodel_account_customer->getCustomer($cliente_id);
  }


  public function getInfosCustomerTemplate($cliente_id)
  {

    $this->getCustomerInfo($cliente_id);

    if ($this->customer) {
      $this->load->dmodel('layout_personalizado/custom_layout');

      $this->load->helper('ftr_geral');

      $this->to = $this->customer['email'];
      $this->sender = $this->config->get('config_name');

      // HTML Mail
      $this->template->data['title'] = $this->language->get('title');
      $this->subject = sprintf($this->language->get('text_subject'), $this->config->get('config_name'));

      $mail_info = $this->dmodel_layout_personalizado_custom_layout->getContents(Type_LayoutPersonalizado::Tp_LayoutCliente);

      $this->template->data['content'] = html_entity_decode($mail_info[0]['conteudo_layout']);
      $this->template->data['cli_nome'] = $this->customer['firstname'];
      $this->template->data['cli_email'] = $this->customer['email'];
      $this->template->data['loj_nome'] = $this->config->get('config_name');
      $this->template->data['loj_link'] = '<a href="' . $this->url->link('common/home', '', 'NONSSL', 'false') . '">' . $this->url->link('common/home', '', 'NONSSL', 'false') . '</a>';
      $this->template->data['loj_login_link'] = '<a href="' . $this->url->link('account/register', '', 'SSL') . '">' . $this->url->link('account/register', '', 'SSL') . '</a>';
      $this->template->data['loj_botao_acessar'] = '<p><a style="display: inline-block; padding: 15px 20px; border-radius: 4px; text-transform: uppercase; background: ' . $this->config->get('wg24_mm_bgcol') . '; color: ' . $this->config->get('wg24_menum_lcolor') . '; text-decoration: none; font: normal normal 14px Arial, Helvetica, sans-serif; margin-bottom: 10px;" href="' . $this->url->link('account/register', '', 'SSL') . '">Acessar minha conta</a></p>';


      $server = $this->url->link('', '', 'SSL', false);

      if ($this->config->get('config_logo') && file_exists(DIR_IMAGE . $this->config->get('config_logo'))) {
        $logo = $server . 'image/' . $this->config->get('config_logo');
      } else {
        $logo = '';
      }

      $this->template->data['loj_logo'] = ($logo) ? '<img src="' . $logo . '" alt="logo" style="max-width: 100%;">' : '';

    }

  }

  public function getInfosOwerCustomer($cliente_id){

    $this->getCustomerInfo($cliente_id);

    $customer_group_info =  $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "customer_group cg LEFT JOIN " . DB_PREFIX . "customer_group_description cgd ON (cg.customer_group_id = cgd.customer_group_id) WHERE cg.customer_group_id = '" . (int)$this->customer['customer_group_id'] . "' AND cgd.language_id = '" . (int)$this->config->get('config_language_id') . "'")->row;

    $this->text  = $this->language->get('text_signup') . "\n\n";
    $this->text .= $this->language->get('text_website') . ' ' . $this->config->get('config_name') . "\n";
    $this->text .= $this->language->get('text_firstname') . ' ' . $this->customer['firstname'] . "\n";
    $this->text .= $this->language->get('text_lastname') . ' ' . $this->customer['lastname'] . "\n";
    $this->text .= $this->language->get('text_customer_group') . ' ' . $customer_group_info['name'] . "\n";
    $this->text .= $this->language->get('text_email') . ' '  .  $this->customer['email'] . "\n";
    $this->text .= $this->language->get('text_celular') . ' ' . $this->customer['celular'] . "\n";
    $this->text .= $this->language->get('text_telephone') . ' ' . $this->customer['telephone'] . "\n";

    $this->subject = $this->language->get('text_new_customer');
    $this->to = $this->config->get('config_email');
    $this->sender = $this->config->get('config_name');

  }


}