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

  Copyright (c) 2010, 2011, 2012 MailBeez

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

  Released under the GNU General Public License

  v2.7.1
 */

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

echo $MAILBEEZ_TABS;


if (mh_cfg('MAILBEEZ_DASHBOARD_INSTALLED')) {
    $adm_array = explode(';', mh_cfg('MAILBEEZ_DASHBOARD_INSTALLED'));

    // bulletproof - make sure classes are loaded
    if (!in_array('dashboard_status.php', $adm_array)) {
        $adm_array[] = 'dashboard_status.php';
    }
    if (!in_array('dashboard_statsbar.php', $adm_array)) {
        $adm_array[] = 'dashboard_statsbar.php';
    }
    if (!in_array('dashboard_beez_o_graph.php', $adm_array)) {
        $adm_array[] = 'dashboard_beez_o_graph.php';
    }

    $col = 0;

    for ($i = 0, $n = sizeof($adm_array); $i < $n; $i++) {
        $adm = $adm_array[$i];

        $class = substr($adm, 0, strrpos($adm, '.'));

        if (!class_exists($class)) {
            if (file_exists(mh_cfg('MH_DASHBOARD_MODULE_DIRECTORY') . $class . mh_cfg('MH_FILE_EXTENSION'))) {
                mh_load_modules_language_files(mh_cfg('MH_DASHBOARD_MODULE_DIRECTORY'), $class);
                include_once(mh_cfg('MH_DASHBOARD_MODULE_DIRECTORY') . $class . mh_cfg('MH_FILE_EXTENSION'));
            } else {
                continue;
            }
        }

        if (class_exists($class)) {
            $dashboard_module = new $class;
            if (($dashboard_module->sort_order > 0) && !isset($installed_dashboard_modules[$dashboard_module->sort_order])) {
                $installed_dashboard_modules[$dashboard_module->sort_order] = $class;
            } else {
                $installed_dashboard_modules[] = $class;
            }
        }
    }

    uksort($installed_dashboard_modules, "sortbyintvalue");
    $adm_array = array_values($installed_dashboard_modules);
}

?>


<style type="text/css">
    div.mb_systemcheck_path {
        visibility: visible;
        font-weight: normal;
        border: 1px solid #FF9999;
        color: #C31B00;
        background: #FFCCCC; /* old browsers */
        background-attachment: scroll;
        background-color: transparent;
        background-image: -moz-linear-gradient(center top, #FFCCCC, #FFC0C0);
        background-position: 0 0;
        background-repeat: repeat;
        padding: 30px;
        font-family: "Trebuchet MS";
    }
</style>

<link rel="stylesheet" type="text/css" media="print, projection, screen"
      href="<?php echo mh_cfg('MH_CATALOG_SERVER') . mh_cfg('MH_DIR_WS_CATALOG') . mh_cfg('MH_ROOT_PATH'); ?>common/admin_application_plugins/main_mailbeez.css?ver=<?php echo mh_cfg('MAILBEEZ_VERSION'); ?>">
<link rel="stylesheet" type="text/css" media="print, projection, screen"
      href="<?php echo mh_cfg('MH_CATALOG_SERVER') . mh_cfg('MH_DIR_WS_CATALOG') . mh_cfg('MH_ROOT_PATH'); ?>common/admin_application_plugins/dashboard.css?ver=<?php echo mh_cfg('MAILBEEZ_VERSION'); ?>">
<script language="javascript"
        src="<?php echo mh_cfg('MH_CATALOG_SERVER') . mh_cfg('MH_DIR_WS_CATALOG') . mh_cfg('MH_ROOT_PATH'); ?>configbeez/config_customer_insight/js/base64.js"></script>
<div class="mb_systemcheck_path">
    <?php echo mh_lng('MAILBEEZ_SYSTEM_CHECK_MSG_PATH'); ?>
</div>
<script type="text/javascript">

    function loadWidget(callUrl, widgetID, action, refresh) {
        jQuery("#spinner_" + widgetID).fadeIn();

        jQuery.ajax({
            type: 'GET',
            url: callUrl + '&dashboard_action=' + action + '&dashboard_module=' + widgetID,
            timeout: 30 * 1000,
            success: function (dataStr) {
                var dataObj = jQuery.parseJSON(dataStr);
                jQuery("#" + widgetID).html((dataObj.widgetContent));
                jQuery("#spinner_" + widgetID).fadeOut();
                jQuery.timeago.settings.allowFuture = true;
                jQuery("abbr.timeago").timeago();
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                // not used yet
                jQuery("#spinner_" + widgetID).hide();

                jQuery("#" + widgetID).html('Timeout while contacting server');
            }
        });
    }
</script>

<table border="0" width="100%" cellspacing="0" cellpadding="0">
    <tr>
        <td valign="top">
            <table border="0" width="100%" cellspacing="0" cellpadding="2">
                <tr>
                    <td width="100%" valign="top" class="smallText ">

                        <?php
                        $module_version_check_result = mh_check_module_versions();
                        if ($module_version_check_result != '') {
                            ?>
                            <div class="mb_inline_msg alert">
                                <div class="mb_inline_msg img">
                                    <img
                                            src="<?php echo mh_cfg('MH_CATALOG_SERVER') . mh_cfg('MH_DIR_WS_CATALOG') . mh_cfg('MH_ROOT_PATH'); ?>common/images/attention.png"
                                            width="32"
                                            height="32">
                                </div>
                                <div class="mb_inline_msg text">
                                    <strong><?php echo mh_lng('MAILBEEZ_VERSION_CHECK_MSG_UPDATE_MODULES'); ?></strong>
                                    <br/>
                                    <?php echo $module_version_check_result; ?>
                                    <?php echo mh_lng('MAILBEEZ_VERSION_CHECK_MSG_UPDATE_MODULES_TEXT'); ?>
                                </div>
                            </div>
                        <?php } ?>

                        <?php
                        $module_system_check_result = mh_system_check();

                        if ($module_system_check_result != false) {
                            ?>
                            <div class="mb_inline_msg alert">
                                <div class="mb_inline_msg img">
                                    <img
                                            src="<?php echo mh_cfg('MH_CATALOG_SERVER') . mh_cfg('MH_DIR_WS_CATALOG') . mh_cfg('MH_ROOT_PATH'); ?>common/images/attention.png"
                                            width="32"
                                            height="32">
                                </div>
                                <div class="mb_inline_msg text">
                                    <strong><?php echo mh_lng('MAILBEEZ_SYSTEM_CHECK_MSG'); ?></strong>
                                    (<?php echo mb_admin_button(mh_href_link(FILENAME_MAILBEEZ, 'app=load_app&app_path=config_queen/admin_application_plugins/systemcheck_refresh.php&app_action=systemcheck_refresh'), mh_lng('MAILBEEZ_BUTTON_SYSTEMCHECK_REFRESH'), '', 'link', 'link', '', 'document', 'iframe width:650', '_self'); ?>
                                    )
                                    <br/>
                                    <ul>
                                        <?php echo $module_system_check_result; ?>
                                    </ul>
                                </div>
                            </div>
                        <?php } ?>



                        <?php if (isset($_SESSION['mailbeez_upd_msg'])) { ?>
                            <div class="mb_inline_msg msg">
                                <div class="mb_inline_msg img">
                                    <img
                                            src="<?php echo mh_cfg('MH_CATALOG_SERVER') . mh_cfg('MH_DIR_WS_CATALOG') . mh_cfg('MH_ROOT_PATH'); ?>common/images/mb_icon.png"
                                            width="32"
                                            height="32">
                                </div>
                                <div class="mb_inline_msg text">
                                    <strong><?php echo mh_lng('MAILBEEZ_VERSION_CHECK_MSG_INTRO'); ?></strong>
                                    <br/>
                                    <?php echo $_SESSION['mailbeez_upd_msg']; ?>
                                </div>
                            </div>
                        <?php } ?>

                        <?php
                        if (isset($_SESSION['mailbeez_new']['dashboardbeez']) || isset($_SESSION['mailbeez_upd']['dashboardbeez'])) {
                            ?>
                            <div class="mb_inline_msg new_modules">
                                <div class="mb_inline_msg_inner">
                                    <?php echo mh_lng('MH_VERSIONCHECK_INFO_DASHBOARD'); ?><br/>

                                    <a href="<?php echo mh_href_link(mh_fn('FILENAME_MAILBEEZ'), 'tab=dashboardbeez'); ?>"><?php echo mh_lng('MH_DASHBOARD_CONFIG_BUTTON'); ?></a>
                                </div>
                            </div>
                            <?php

                        }
                        ?>

                        <div class="dashboard_main">

                            <table border="0" width="100%" cellspacing="5" cellpadding="2">


                                <tr>
                                    <td colspan="2" width="100" valign="top" class="smallText">
                                        <div style=" position: relative
                                        ">

                                            <div id="spinner_dashboard_status"
                                                 style="display: none; z-index: 200; position: absolute; width: 100%; height:100%; background-color: rgba(255,255,255,0.75)">
                                                <div class="spinner tiny">
                                                    <div class="bounce1"></div>
                                                    <div class="bounce2"></div>
                                                    <div class="bounce3"></div>
                                                </div>
                                            </div>
                                            <div class="system_bar" style="min-height: 18px; height: auto !important;"
                                                 id="dashboard_status">
                                                <?php
                                                $class = 'dashboard_status';
                                                $request_profiler->restart('dashboard_before_get_output-' . $class);
                                                $ad = new $class();
                                                echo $ad->getOutput();
                                                $request_profiler->restart('dashboard_after_get_output-' . $class);
                                                $config_link = mh_href_link(mh_fn('FILENAME_MAILBEEZ'), '&action=edit&module=' . $ad->module);

                                                ?>
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="2" width="100" valign="top" class="smallText">
                                        <div class="dashboard_area_top">

                                            <div id="spinner_dashboard_statsbar"
                                                 style="display: none; z-index: 200; position: absolute; width: 100%; height:100%; background-color: rgba(255,255,255,0.75)">
                                                <div class="spinner small">
                                                    <div class="bounce1"></div>
                                                    <div class="bounce2"></div>
                                                    <div class="bounce3"></div>
                                                </div>
                                            </div>
                                            <div class="dashboard_area"
                                                 style="min-height: 100px; height: auto !important;"
                                                 id="dashboard_statsbar">
                                                <?php
                                                $class = 'dashboard_statsbar';
                                                $request_profiler->restart('dashboard_before_get_output-' . $class);
                                                $ad = new $class();
                                                echo $ad->getOutput();
                                                $request_profiler->restart('dashboard_after_get_output-' . $class);
                                                $config_link = mh_href_link(mh_fn('FILENAME_MAILBEEZ'), '&action=edit&module=' . $ad->module);

                                                ?>
                                            </div>
                                        </div>
                                    </td>
                                </tr>


                                <tr>
                                    <td colspan="2" width="100" valign="top" class="smallText">
                                        <div class="dashboard_area_top">

                                            <div id="spinner_dashboard_beez_o_graph"
                                                 style="display: none; z-index: 200; position: absolute; width: 100%;height:100%;background-color: rgba(255,255,255,0.75)">
                                                <div class="spinner">
                                                    <div class="bounce1"></div>
                                                    <div class="bounce2"></div>
                                                    <div class="bounce3"></div>
                                                </div>
                                            </div>
                                            <div class="dashboard_area" style="height: 300px;"
                                                 id="dashboard_beez_o_graph">
                                                <?php
                                                $class = 'dashboard_beez_o_graph';
                                                $request_profiler->restart('dashboard_before_get_output-' . $class);
                                                $ad = new $class();
                                                echo $ad->getOutput();
                                                $request_profiler->restart('dashboard_after_get_output-' . $class);
                                                $config_link = mh_href_link(mh_fn('FILENAME_MAILBEEZ'), '&action=edit&module=' . $ad->module);

                                                ?>

                                            </div>
                                        </div>
                                        <div align="right"><a
                                                    href="<?php echo $config_link; ?>"><?php echo mh_lng('MH_DASHBOARD_CONFIG'); ?></a>
                                        </div>

                                    </td>
                                </tr>


                                <?php
                                // thanks to osCommerce ms2.3
                                if (mh_cfg('MAILBEEZ_DASHBOARD_INSTALLED')) {

                                    for ($i = 0, $n = sizeof($adm_array); $i < $n; $i++) {

                                        $class = $adm_array[$i];
                                        if ($class == 'dashboard_beez_o_graph' || $class == 'dashboard_statsbar') {
                                            continue;
                                        }
                                        $ad = new $class();

                                        if (!$ad->isMlbz()) {
                                            continue;
                                        }

                                        if ($ad->isEnabled()) {
                                            if ($col < 1) {
                                                echo '          <tr>' . "\n";
                                            }

                                            $col++;

                                            if ($col <= 2) {
                                                echo '<td width="50%" valign="top" class="smallText">
                                                        <div class="dashboard_area_top">

                                                        <div id="spinner_' . $ad->module . '"
                                                             style="display: none; z-index: 200; position: absolute; width: 100%;height:100%;background-color: rgba(255,255,255,0.75)">
                                                            <div class="spinner">
                                                                <div class="bounce1"></div>
                                                                <div class="bounce2"></div>
                                                                <div class="bounce3"></div>
                                                            </div>
                                                        </div>
                                                        <div class="dashboard_area" id="' . $ad->module . '">' . "\n";
                                            }


                                            $request_profiler->restart('dashboard_before_get_output-' . $class);
                                            echo $ad->getOutput();
                                            $request_profiler->restart('dashboard_after_get_output-' . $class);

                                            $config_disable_link = mh_href_link(mh_fn('FILENAME_MAILBEEZ'), 'app=load_app&app_path=common/admin_application_plugins/disable_dashboardbeez.php' . '&key=' . $ad->status_key);
                                            $config_link = mh_href_link(mh_fn('FILENAME_MAILBEEZ'), '&action=edit&module=' . $ad->module);

                                            if ($col <= 2) {
                                                echo '            </div>';
                                                echo '<div align="right"><a href="' . $config_link . '">' . mh_lng('MH_DASHBOARD_CONFIG') . '</a>';
                                                if ($ad->removable) {
                                                    echo '  |  <a href="' . $config_disable_link . '">' . mh_lng('MH_DASHBOARD_REMOVE') . '</a></div>';
                                                }

                                                echo '</div></td>' . "\n";
                                            }

                                            if (!isset($adm_array[$i + 1]) || ($col == 2)) {
                                                if (!isset($adm_array[$i + 1]) && ($col == 1)) {
                                                    ?>
                                                    <td width="50%" valign="top">
                                                    <div class="dashboard_area_empty">
                                                        <div
                                                                class="dashboard_area_empty_content"><?php echo mh_lng('MH_MSG_EMPTY_DASHBOARD_AREA'); ?>
                                                            <br/>
                                                            <a href="<?php echo mh_href_link(mh_fn('FILENAME_MAILBEEZ'), 'tab=dashboardbeez'); ?>"><?php echo mh_lng('MH_DASHBOARD_CONFIG_BUTTON'); ?></a>
                                                        </div>
                                                    </div>
                                                    </td><?php

                                                }

                                                $col = 0;

                                                echo '  </tr>' . "\n";
                                            }
                                        }
                                    }
                                }
                                ?>
                            </table>

                            <a href="<?php echo mh_href_link(mh_fn('FILENAME_MAILBEEZ'), 'tab=dashboardbeez'); ?>"><?php echo mh_lng('MH_DASHBOARD_CONFIG_BUTTON'); ?></a>
                        </div>

                    </td>
                </tr>
                <tr>
                    <td>
                        <br/>
                        <br/>
                        <?php if (!getenv('SAAS_ENV')) {
                            echo $MAILBEEZ_FOOTER;
                        } ?>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>