<?php


mh_define('MAILBEEZ_REPORT_DETAILS_IMG', '');

mh_define('MH_POPUP', true);

$module_url = 'app=load_app&app_path=report_analytics/standalone_widget.php&';

mh_load_modules_language_files(MH_REPORT_MODULE_DIRECTORY, 'report_analytics', MH_FILE_EXTENSION);


$begin_of_time = mh_cfg('MAILBEEZ_ANALYTICS_BEGIN_OF_TIME','2000-01-01 00:00:00');

$selected_startdate = mh_get('selected_startdate', false); // date('m/d/Y', strtotime($begin_of_time)); //
$selected_enddate = mh_get('selected_enddate', false); // date('m/d/Y'); // now
$selected_module = mh_get('selected_module', false);

if ($selected_startdate != '') {
    $_GET['selected_startdate'] = $selected_startdate;
}
if ($selected_enddate != '') {
    $_GET['selected_enddate'] = $selected_enddate;
}

$app_action = mh_get('app_action', '');
$msg = '';

if (mh_not_null($app_action)) {
    switch ($app_action) {
        case 'update':

            mh_redirect(mh_href_link(FILENAME_MAILBEEZ, $module_url . mh_get_all_get_params(array('app', 'app_path', 'app_action', 'selected_startdate', 'selected_enddate')) . '&selected_startdate=' . $_POST['selected_startdate'] . '&selected_enddate=' . $_POST['selected_enddate']));
//            mh_redirect(mh_href_link(FILENAME_MAILBEEZ, $module_url . '&selected_module=' .$_POST['selected_module'] . '&selected_startdate=' .$_POST['selected_startdate'] . '&selected_enddate=' .$_POST['selected_enddate'] ));

            break;
    }
}

?>

<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'); ?>">
<link type="text/css"
      href="<?php echo mh_cfg('MH_CATALOG_SERVER') . mh_cfg('MH_DIR_WS_CATALOG') . mh_cfg('MH_ROOT_PATH'); ?>common/css/smoothness/jquery-ui-1.7.3.custom.css"
      rel="Stylesheet"/>


<style type="text/css">
    .dashboard_area {
        border: none;
        height: auto;
    }

    .dashboard_main {
        min-height: 110px;
    }

</style>

<script type="text/javascript"
        src="<?php echo mh_cfg('MH_CATALOG_SERVER') . mh_cfg('MH_DIR_WS_CATALOG') . mh_cfg('MH_ROOT_PATH'); ?>common/js/jquery-ui-1.7.3.custom.min.js"></script>
<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 colspan="2">
            <div style="min-height: 100px">

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

                        <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: 120px;" id="dashboard_statsbar">
                                        <?php
                                        $class = 'dashboard_statsbar';
                                        if (file_exists(MH_DASHBOARD_MODULE_DIRECTORY . $class . MH_FILE_EXTENSION)) {
                                            include_once(MH_DASHBOARD_MODULE_DIRECTORY . $class . MH_FILE_EXTENSION);
                                            mh_load_modules_language_files(MH_DASHBOARD_MODULE_DIRECTORY, $class);
                                        }

                                        $sb = new dashboard_statsbar(true);
                                        echo $sb->getOutput();
                                        ?>
                                    </div>
                                </div>
                            </td>
                        </tr>

                    </table>
                </div>


            </div>
        </td>
    </tr>
</table>
