<?php

class Plugin_Mailer
{

  public static function sendSenhaAlterada($cliente, $senha)
  {
    $return = new stdClass();
    $return->error = false;
    $return->message = '';
    try {

      $dados = array();

      // the mail class
      $mail = new Pampa_Util_Mail();
      // the site settings
      $modelSettings = new Model_Cms_Settings();
      $settings = $modelSettings->getSettings();
      // load the mail file
      $mail->loadHTML("altera-senha.html");

      // setup the file info
      $dados['data'] = date("F d, Y - H:i");
      $dados['base_url'] = BASE_URL;

      // dados do cliente
      $dados['nome'] = $cliente->name;
      $dados['senha'] = $senha;


      $mail->setData($dados);
      // the mail header
      $mail->setHeader($cliente->email, $settings->email, "EACIN - New password");

      // sends email
      //$mail->isFile = true;
      $mail->send();

    }
    catch (exception $exc)
    {
      $return->error = true;
      $return->message = $exc->getMessage();
    }

    return $return;
  }

  /**
   * send a request to admin
   * @param String $email
   * @return stdClass
   */
  public static function sendContact($contact)
  {
    $return = new stdClass();
    $return->error = false;
    $return->message = '';

    try
    {
      // check for send data
      if (empty($contact))
      {
        throw new Exception("Invalid form data");
      }

      // the mail class
      $mail = new Pampa_Util_Mail();
      // the site settings
      $modelSettings = new Model_Cms_Settings();
      $settings = $modelSettings->getSettings();
      // load the mail file
      $mail->loadHTML("contact.html");
      // setup the file info
      $contact['date'] = date("d/m/Y, H:i");
      $mail->setData($contact);
      // the mail header
      $mail->setHeader($settings->email, $contact['email'], "Contato do site EAD - CEPED", $settings->email_cco);

      // sends email
//      $mail->isFile = true;
      $mail->send();
    }
    catch (exception $exc)
    {
      $return->error = true;
      $return->message = $exc->getMessage();
    }

    return $return;
  }

  public static function sendNewInnovator($innovator)
  {
    $return = new stdClass();
    $return->error = false;
    $return->message = '';

    try
    {
      // check for send data
      if (empty($innovator))
      {
        throw new Exception("Invalid form data");
      }

      // the mail class
      $mail = new Pampa_Util_Mail();
      // the site settings
      $modelSettings = new Model_Cms_Settings();
      $settings = $modelSettings->getSettings();
      // load the mail file
      $mail->loadHTML("new-innovator.html");
      // setup the file info
      $innovator['date'] = date("m/d/Y, H:i");
      $mail->setData($innovator);

      // the mail header
      $mail->setHeader($settings->email, $settings->email, "EACIN - New Innovator", $settings->email_cco);

      // sends email
      //$mail->isFile = true;
      $mail->send();
    }
    catch (exception $exc)
    {
      $return->error = true;
      $return->message = $exc->getMessage();
    }

    return $return;
  }

  public static function sendNewProject($project)
  {
    $return = new stdClass();
    $return->error = false;
    $return->message = '';

    try
    {
      // check for send data
      if (empty($project))
      {
        throw new Exception("Invalid form data");
      }

      // the mail class
      $mail = new Pampa_Util_Mail();
      // the site settings
      $modelSettings = new Model_Cms_Settings();
      $settings = $modelSettings->getSettings();
      // load the mail file
      $mail->loadHTML("new-project.html");
      // setup the file info
      $project['date'] = date("m/d/Y, H:i");
      $mail->setData($project);

      // the mail header
      $mail->setHeader($settings->email, $settings->email, "EACIN - New Project", $settings->email_cco);

      // sends email
      //$mail->isFile = true;
      $mail->send();
    }
    catch (exception $exc)
    {
      $return->error = true;
      $return->message = $exc->getMessage();
    }

    return $return;
  }

  public static function sendNewProposal($proposal)
  {
    $return = new stdClass();
    $return->error = false;
    $return->message = '';

    try
    {
      // check for send data
      if (empty($proposal))
      {
        throw new Exception("Invalid form data");
      }

      // the mail class
      $mail = new Pampa_Util_Mail();
      // the site settings
      $modelSettings = new Model_Cms_Settings();
      $settings = $modelSettings->getSettings();
      // load the mail file
      $mail->loadHTML("new-proposal.html");
      // setup the file info
      $proposal['date'] = date("m/d/Y, H:i");
      $mail->setData($proposal);

      // the mail header
      $mail->setHeader($settings->email, $settings->email, "EACIN - New Proposal", $settings->email_cco);

      // sends email
      //$mail->isFile = true;
      $mail->send();
    }
    catch (exception $exc)
    {
      $return->error = true;
      $return->message = $exc->getMessage();
    }

    return $return;
  }
  public static function sendNewUser($user)
  {
    $return = new stdClass();
    $return->error = false;
    $return->message = '';

    try
    {
      // check for send data
      if (empty($user))
      {
        throw new Exception("Invalid form data");
      }

      // the mail class
      $mail = new Pampa_Util_Mail();
      // the site settings
      $modelSettings = new Model_Cms_Settings();
      $settings = $modelSettings->getSettings();
      // load the mail file
      $mail->loadHTML("new-user.html");
      // setup the file info
      $user['date'] = date("m/d/Y, H:i");
      $mail->setData($user);

      // the mail header
      $mail->setHeader($settings->email, $settings->email, "EACIN - New User", $settings->email_cco);

      // sends email
      //$mail->isFile = true;
      $mail->send();
    }
    catch (exception $exc)
    {
      $return->error = true;
      $return->message = $exc->getMessage();
    }

    return $return;
  }

}
