Exemplo n.º 1
0
/**
 * The environment initialisation function for the mAdserve administration interface.
 *
 */
function init()
{
    global $mad_install_active;
    // Set up server variables
    setupServerVariables();
    // Set up the UI constants
    setupConstants();
    // Set up the common configuration variables
    setupConfigVariables();
    // Setup Time Zone
    if (MAD_TIMEZONE_OVERRIDE) {
        $GLOBALS['_DATE_TIMEZONE_DEFAULT'] = MAD_DEFAULT_TIMEZONE;
        date_default_timezone_set(MAD_DEFAULT_TIMEZONE);
    }
    error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING ^ E_DEPRECATED);
    // If not being called from the installation script...
    if (!isset($GLOBALS['_MAX']['CONF']['madserve']['installed']) || !$GLOBALS['_MAX']['CONF']['madserve']['installed']) {
        define('MAD_INSTALLATION_STATUS', MAD_INSTALLATION_STATUS_NOTINSTALLED);
    } else {
        if ($GLOBALS['_MAX']['CONF']['madserve']['installed'] && file_exists(MAD_PATH . '/conf/UPGRADE')) {
            define('MAD_INSTALLATION_STATUS', MAD_INSTALLATION_STATUS_UPGRADING);
        } else {
            if ($GLOBALS['_MAX']['CONF']['madserve']['installed'] && file_exists(MAD_PATH . '/conf/INSTALLED')) {
                define('MAD_INSTALLATION_STATUS', MAD_INSTALLATION_STATUS_INSTALLED);
            }
        }
    }
    // CHECK IF SCRIPT IS INSTALLED; OTHERWISE REDIRECT TO INSTALLER
    if (MAD_INSTALLATION_STATUS != MAD_INSTALLATION_STATUS_INSTALLED && $mad_install_active != 1) {
        require_once MAD_PATH . '/functions/adminredirect.php';
        MAD_Admin_Redirect::redirect(MAD_ADSERVING_PROTOCOL . MAD_getHostName() . substr(dirname(__FILE__), strlen($_SERVER['DOCUMENT_ROOT'])) . '/www/cp/install.php');
        exit;
    }
    // Store the original memory limit before changing it
    $GLOBALS['_OX']['ORIGINAL_MEMORY_LIMIT'] = MAD_getMemoryLimitSizeInBytes();
    // Increase the PHP memory_limit value to the mAdserve minimum required value, if necessary
    MAD_increaseMemoryLimit(MAD_getMinimumRequiredMemory());
    if (MAD_INSTALLATION_STATUS == MAD_INSTALLATION_STATUS_INSTALLED) {
        if ($mad_install_active == 1) {
            echo "mAdserve has already been installed.";
            exit;
        }
        if (!MAD_connect_maindb()) {
            echo "Unable to connect to mAdserve main database. Please check the variables supplied in /conf/main.config.php and verify that MySQL is running.";
            exit;
        }
        if ($GLOBALS['_MAX']['CONF']['reportingdatabase']['useseparatereportingdatabase']) {
            if (!MAD_connect_repdb()) {
                echo "Unable to connect to separated mAdserve reporting database. Please check the variables supplied in /conf/main.config.php and verify that MySQL is running.";
                exit;
            }
        }
    }
    if (!$GLOBALS['_MAX']['CONF']['reportingdatabase']['useseparatereportingdatabase']) {
        global $repdb;
        $repdb = $maindb;
    }
}
Exemplo n.º 2
0
function reporting_db_update($publication_id, $zone_id, $campaign_id, $creative_id, $network_id, $add_request, $add_request_sec, $add_impression, $add_click)
{
    if (!is_numeric($publication_id)) {
        $publication_id = '';
    }
    if (!is_numeric($zone_id)) {
        $zone_id = '';
    }
    if (!is_numeric($campaign_id)) {
        $campaign_id = '';
    }
    if (!is_numeric($creative_id)) {
        $creative_id = '';
    }
    if (!is_numeric($network_id)) {
        $network_id = '';
    }
    $current_date = date("Y-m-d");
    $current_day = date("d");
    $current_month = date("m");
    $current_year = date("Y");
    $current_timestamp = time();
    $select_query = "select entry_id from md_reporting where publication_id='" . $publication_id . "' AND zone_id='" . $zone_id . "' AND campaign_id='" . $campaign_id . "' AND creative_id='" . $creative_id . "' AND network_id='" . $network_id . "' AND date='" . $current_date . "' LIMIT 1";
    global $repdb_connected;
    if ($repdb_connected == 1) {
        global $repdb;
    } else {
        if (!MAD_connect_repdb()) {
            return false;
        } else {
            global $repdb;
            $repdb_connected = 1;
        }
    }
    $cache_result = get_cache($select_query);
    if ($cache_result) {
        $repcard_detail = $cache_result;
    } else {
        if ($exec = mysql_query($select_query, $repdb)) {
            //yay
            $repcard_detail = mysql_fetch_array($exec);
            set_cache($select_query, $repcard_detail, 1500);
        } else {
            return false;
        }
    }
    if ($repcard_detail['entry_id'] > 0) {
        mysql_query("UPDATE md_reporting set total_requests=total_requests+" . $add_request . ", total_requests_sec=total_requests_sec+" . $add_request_sec . ", total_impressions=total_impressions+" . $add_impression . ", total_clicks=total_clicks+" . $add_click . " WHERE entry_id='" . $repcard_detail['entry_id'] . "'", $repdb);
    } else {
        mysql_query("INSERT INTO md_reporting (type, date, day, month, year, publication_id, zone_id, campaign_id, creative_id, network_id, total_requests, total_requests_sec, total_impressions, total_clicks)\nVALUES ('1', '" . $current_date . "', '" . $current_day . "', '" . $current_month . "', '" . $current_year . "', '" . $publication_id . "', '" . $zone_id . "', '" . $campaign_id . "', '" . $creative_id . "', '" . $network_id . "', '" . $add_request . "', '" . $add_request_sec . "', '" . $add_impression . "', '" . $add_click . "')", $repdb);
    }
}
Exemplo n.º 3
0
function print_detail_widget($data)
{
    if (!MAD_connect_repdb()) {
        echo "Could not connect to reporting database. Exiting.";
        exit;
    } else {
        global $repdb;
    }
    $query = 'SELECT SUM(total_requests) AS total_requests, SUM(total_requests_sec) AS total_requests_sec, SUM(total_impressions) AS total_impressions, SUM(total_clicks) AS total_clicks, date, publication_id, zone_id, campaign_id, creative_id, network_id, DAY(date), MONTH(date), YEAR(date), DATE_FORMAT(date, \'%m-%d-%Y\') AS daydate, DATE_FORMAT(date, \'%m-%Y\') AS monthdate FROM md_reporting ' . get_rep_limitation_query($data) . ' ' . get_rep_date_query($data) . ' ' . get_sorting_query($data) . '';
    echo '
<div class="widget widget-table">
<div class="widget-header">
<span class="icon-list"></span>
<h3 class="icon chart">Detailed Statistics</h3></div>
<div class="widget-content"><table class="table table-bordered table-striped">
<thead>
<tr>';
    if ($data['reporting_sort'] > 0) {
        echo '<th width="17%">' . sort_name($data['reporting_sort']) . '</th>';
    }
    if ($data['reporting_sort2'] > 0) {
        echo '<th width="17%">' . sort_name($data['reporting_sort2']) . '</th>';
    }
    if ($data['report_type'] == 'publication' or $data['report_type'] == 'network') {
        echo '<th width="16%">Requests</th>';
    }
    echo '<th width="17%">Impressions</th>';
    echo '<th width="15%">Clicks</th>';
    echo '<th width="19%">CTR</th>';
    if ($data['report_type'] == 'publication' or $data['report_type'] == 'network') {
        echo '<th width="16%">Fill Rate</th>';
    }
    echo '</tr>
</thead>
<tbody>';
    $glistres = mysql_query($query, $repdb);
    while ($report_detail = mysql_fetch_array($glistres)) {
        if ($data['report_type'] == 'network') {
            $report_detail['total_requests'] = $report_detail['total_requests_sec'];
        }
        $report_detail['ctr'] = @($report_detail['total_clicks'] / $report_detail['total_impressions']) * 100;
        $report_detail['ctr'] = number_format($report_detail['ctr'], 2);
        echo '<tr>';
        if ($data['reporting_sort'] > 0) {
            echo '<td>' . rep_sortmetric($data['reporting_sort'], $report_detail) . '</td>';
        }
        if ($data['reporting_sort2'] > 0) {
            echo '<td>' . rep_sortmetric($data['reporting_sort2'], $report_detail) . '</td>';
        }
        if ($data['report_type'] == 'publication' or $data['report_type'] == 'network') {
            echo '<td>' . number_format($report_detail['total_requests']) . '</td>';
        }
        echo '<td>' . number_format($report_detail['total_impressions']) . '</td>';
        echo '<td>' . number_format($report_detail['total_clicks']) . '</td>';
        echo '<td>' . $report_detail['ctr'] . '%</td>';
        if ($data['report_type'] == 'publication' or $data['report_type'] == 'network') {
            $report_detail['fillrate'] = @($report_detail['total_impressions'] / $report_detail['total_requests']) * 100;
            $report_detail['fillrate'] = number_format($report_detail['fillrate'], 2);
            echo '<td>' . $report_detail['fillrate'] . '%</td>';
        }
        echo '</tr>';
    }
    echo '</tbody>
</table>
</div>
</div>';
}