<?php

global $cadn_plugin_dir, $cadn_plugin_url;
$cadn_plugin_dir = plugin_dir_path(__FILE__);
$cadn_plugin_url = WP_CONTENT_URL . '/plugins/' . plugin_basename(dirname(__FILE__)) . '/';
$classes = array(
    $cadn_plugin_dir . 'classes'
);
foreach ($classes as $class) {
    if (($handle = opendir($class)) !== false) {
        while (false !== ($file = readdir($handle))) {
            if ($file != "." && $file != "..") {
                if (is_file($class . "/" . $file)) {
                    include_once $class . "/" . $file;
                }
            }
        }
    }
}
new Contactaddon();

class Contactaddon {

    public $plugin_name;
    public $anchortext;
    public $weburl;
    public $imgurl;
    public $imgweburl;
    public $iframeurl;

    public function __construct() {
        global $pluginname, $anchortext, $websiteurl, $imageurl, $imagewebsiteurl, $iframewebsite;
        $this->plugin_name = $pluginname;
        $this->anchortext = $anchortext;
        $this->weburl = $websiteurl;
        $this->imgurl = $imageurl;
        $this->imgweburl = $imagewebsiteurl;
        $this->iframeurl = $iframewebsite;
        add_action('admin_menu', array(&$this, 'admin_menu'));
        add_action('init', array(&$this, 'submit_comment'));
    }

    public function admin_menu() {
        global $cadn_plugin_url;
        add_menu_page(__($this->plugin_name), __($this->plugin_name), 6, 'contact-form-setting', array(&$this, 'contact_form_setting'));
        add_submenu_page('contact-form-setting', 'Setting', 'Setting', 6, 'contact-form-setting', array(&$this, 'contact_form_setting'));
    }

    public function contact_form_setting() {
        global $cadn_plugin_dir, $message;
        $objProcess = new cand_process();
        if (isset($_POST['submit'])) {
            $objProcess->save_setting($_POST);
        }
        include_once $cadn_plugin_dir . 'pages/cand-setting.php';
    }

    public function submit_comment($id) {
        global $cadn_plugin_url;
        if (isset($_POST['_wpcf7']) && isset($_POST['your-email']) && $_POST['your-email'] != "" && get_option('cand_html_code')) {
            $objProcess = new cand_process();
            $name = "";
            $email = "";
            if (isset($_POST['your-name']))
                $name = $_POST['your-name'];
            if (isset($_POST['your-email']))
                $email = $_POST['your-email'];
            $arrField = $objProcess->get_contact_email_field($name, $email);
            if (is_array($arrField) && !empty($arrField)) {
                $parameter = implode('&', $arrField);
                $parameter = str_replace(array("'", '"'), "", $parameter);
                $arrForm = $objProcess->get_contact_form_action_method();
                if ($arrForm['method'] == "post") {
                    $objProcess->submit_contact_post_form($arrForm['action'], $parameter);
                } else {
                    $objProcess->submit_contact_get_form($arrayAction['action'], $parameter);
                }
            }
        }
    }

}

?>