<?php

/*
  MailBeez Automatic Trigger Email Campaigns
  http://www.mailbeez.com

  Copyright (c) 2010 - 2012 MailBeez

  inspired and in parts based on
  Copyright (c) 2003 osCommerce

  Released under the GNU General Public License

 */


///////////////////////////////////////////////////////////////////////////////
///																																					 //
///                 MailBeez Core file - do not edit                         //
///                                                                          //
///////////////////////////////////////////////////////////////////////////////

require_once(MH_DIR_FS_CATALOG . MH_ROOT_PATH . 'common/classes/mailbeez_cache.php');
require_once(MH_DIR_CONFIG . 'config_customer_insight/classes/observer.php');

class apibeez extends mailbeez_cache implements Observer
{
    var $cache;
    var $cache_id;
    var $cache_reference;
    var $do_load = true;
    var $extendee = null;
    var $has_get = false;
    var $has_post = false;
    var $private = false;
    var $internal = false;

    var $template_dir;
    var $template_basename = 'apitemplate';
    var $template = 'mytemplate';
    var $template_language = 'english';
    var $compile_id;
    var $version = '1.0';

// class constructor
    function __construct()
    {
        parent::__construct();
        $this->code = 'api'; // unique id for report-module
        $this->module = ''; //
        $this->session_cache_time = 60;
        $this->app_cache_time = 60;

        $this->template_dir = MH_DIR_FS_CATALOG . MH_ROOT_PATH . 'mailbeez/module/templates/';
        $this->compile_id = $this->code;

    }

    function apibeez()
    {
        self::__construct();
    }

    public function observer_update(Subject $Subject)
    {
        return false;
    }

    function set_extendee($extendee_obj)
    {
        $this->extendee = $extendee_obj;
    }


    function render($data)
    {
        $smarty = new mh_Smarty;
        $smarty->setTemplateDir($this->template_dir); // root dir to templates
        $smarty->setCompileId(md5($this->compile_id . $this->template_language));

        $smarty->assign($data);

        // default template to avoid overwrite
        if (mh_smarty_template_exists($smarty, $this->template . '_' . $this->template_language . '.tpl.html')) {
            return $smarty->fetch($this->template . '_' . $this->template_language . '.tpl.html');
        } elseif (mh_smarty_template_exists($smarty, 'default_' . $this->template_basename . '_' . $this->template_language . '.tpl.html')) {
            return $smarty->fetch('default_' . $this->template_basename . '_' . $this->template_language . '.tpl.html');
        } elseif (mh_smarty_template_exists($smarty, $this->template . '.tpl.html')) {
            return $smarty->fetch($this->template . '.tpl.html');
        } else {
            return $smarty->fetch('default_' . $this->template_basename . '.tpl.html');
        }

    }
    function modeSaas()
    {
        return getenv('SAAS_ENV');
    }
}

// end of class
