function Plugin_AffiliatehistoryExecute($affiliateid, $delimiter = ",")
{
    global $phpAds_config, $date_format;
    global $strAffiliate, $strTotal, $strDay, $strViews, $strClicks, $strCTRShort;
    header("Content-type: application/csv\nContent-Disposition: \"inline; filename=affiliatehistory.csv\"");
    $idresult = phpAds_dbQuery("\n\t\tSELECT\n\t\t\tzoneid\n\t\tFROM\n\t\t\t" . $phpAds_config['tbl_zones'] . "\n\t\tWHERE\n\t\t\taffiliateid = '" . $affiliateid . "'\n\t");
    while ($row = phpAds_dbFetchArray($idresult)) {
        $zoneids[] = "zoneid = " . $row['zoneid'];
    }
    $res_query = "\n\t\tSELECT\n\t\t\tDATE_FORMAT(day, '" . $date_format . "') as day,\n\t\t\tSUM(views) AS adviews,\n\t\t\tSUM(clicks) AS adclicks\n\t\tFROM\n\t\t\t" . $phpAds_config['tbl_adstats'] . "\n\t\tWHERE\n\t\t\t(" . implode(' OR ', $zoneids) . ")\n\t\tGROUP BY\n\t\t\tday\n\t";
    $res_banners = phpAds_dbQuery($res_query) or phpAds_sqlDie();
    while ($row_banners = phpAds_dbFetchArray($res_banners)) {
        $stats[$row_banners['day']]['views'] = $row_banners['adviews'];
        $stats[$row_banners['day']]['clicks'] = $row_banners['adclicks'];
    }
    echo $strAffiliate . ": " . strip_tags(phpAds_getAffiliateName($affiliateid)) . "\n\n";
    echo $strDay . $delimiter . $strViews . $delimiter . $strClicks . $delimiter . $strCTRShort . "\n";
    $totalclicks = 0;
    $totalviews = 0;
    if (isset($stats) && is_array($stats)) {
        for (reset($stats); $key = key($stats); next($stats)) {
            $row = array();
            //			$key = implode('/',array_reverse(split('[-]',$key)));
            $row[] = $key;
            $row[] = $stats[$key]['views'];
            $row[] = $stats[$key]['clicks'];
            $row[] = phpAds_buildCTR($stats[$key]['views'], $stats[$key]['clicks']);
            echo implode($delimiter, $row) . "\n";
            $totalclicks += $stats[$key]['clicks'];
            $totalviews += $stats[$key]['views'];
        }
    }
    echo "\n";
    echo $strTotal . $delimiter . $totalviews . $delimiter . $totalclicks . $delimiter . phpAds_buildCTR($totalviews, $totalclicks) . "\n";
}
function phpAds_dbConnect()
{
    global $phpAds_config;
    global $phpAds_db_link;
    // Add port to connect, if needed
    if (!isset($phpAds_config['dbport']) || !$phpAds_config['dbport']) {
        $phpAds_config['dbport'] = 3306;
    }
    $host = $phpAds_config['dbhost'];
    if ((!isset($phpAds_config['dblocal']) || !$phpAds_config['dblocal']) && $host[0] != ':') {
        $host .= ':' . $phpAds_config['dbport'];
    }
    if ($phpAds_config['persistent_connections']) {
        $phpAds_db_link = @mysql_pconnect($host, $phpAds_config['dbuser'], $phpAds_config['dbpassword']);
    } else {
        $phpAds_db_link = @mysql_connect($host, $phpAds_config['dbuser'], $phpAds_config['dbpassword']);
    }
    if ($phpAds_config['mysql4_compatibility']) {
        phpAds_dbQuery("SET SESSION sql_mode='MYSQL40'");
    }
    if ($phpAds_config['compatibility_mode']) {
        return $phpAds_db_link;
    }
    if (@mysql_select_db($phpAds_config['dbname'], $phpAds_db_link)) {
        return $phpAds_db_link;
    }
}
function phpAds_checkForUpdates($already_seen = 0, $send_sw_data = true)
{
    global $phpAds_config, $phpAds_updatesServer;
    global $xmlrpcerruser;
    // Create client object
    $client = new xmlrpc_client($phpAds_updatesServer['script'], $phpAds_updatesServer['host'], $phpAds_updatesServer['port']);
    $params = array(new xmlrpcval($GLOBALS['phpAds_productname'], "string"), new xmlrpcval($phpAds_config['config_version'], "string"), new xmlrpcval($already_seen, "string"), new xmlrpcval($phpAds_config['updates_dev_builds'] ? 'dev' : '', "string"), new xmlrpcval($phpAds_config['instance_id'], "string"));
    if ($send_sw_data) {
        // Prepare software data
        $params[] = phpAds_xmlrpcEncode(array('os_type' => php_uname('s'), 'os_version' => php_uname('r'), 'webserver_type' => isset($_SERVER['SERVER_SOFTWARE']) ? preg_replace('#^(.*?)/.*$#', '$1', $_SERVER['SERVER_SOFTWARE']) : '', 'webserver_version' => isset($_SERVER['SERVER_SOFTWARE']) ? preg_replace('#^.*?/(.*?)(?: .*)?$#', '$1', $_SERVER['SERVER_SOFTWARE']) : '', 'db_type' => $GLOBALS['phpAds_dbmsname'], 'db_version' => phpAds_dbResult(phpAds_dbQuery("SELECT VERSION()"), 0, 0), 'php_version' => phpversion(), 'php_sapi' => ucfirst(php_sapi_name()), 'php_extensions' => get_loaded_extensions(), 'php_register_globals' => (bool) ini_get('register_globals'), 'php_magic_quotes_gpc' => (bool) ini_get('magic_quotes_gpc'), 'php_safe_mode' => (bool) ini_get('safe_mode'), 'php_open_basedir' => (bool) strlen(ini_get('open_basedir')), 'php_upload_tmp_readable' => (bool) is_readable(ini_get('upload_tmp_dir') . DIRECTORY_SEPARATOR)));
    }
    // Create XML-RPC request message
    $msg = new xmlrpcmsg("Openads.Sync", $params);
    // Send XML-RPC request message
    if ($response = $client->send($msg, 10)) {
        // XML-RPC server found, now checking for errors
        if (!$response->faultCode()) {
            $ret = array(0, phpAds_xmlrpcDecode($response->value()));
            // Prepare cache
            $cache = $ret[1];
        } else {
            $ret = array($response->faultCode(), $response->faultString());
            // Prepare cache
            $cache = false;
        }
        // Save to cache
        phpAds_dbQuery("\n\t\t\tUPDATE\n\t\t\t\t" . $phpAds_config['tbl_config'] . "\n\t\t\tSET\n\t\t\t\tupdates_cache = '" . addslashes(serialize($cache)) . "',\n\t\t\t\tupdates_timestamp = " . time() . "\n\t\t");
        return $ret;
    }
    return array(-1, 'No response from the server');
}
function phpAds_LoadDbConfig($agencyid = 0)
{
    global $phpAds_config, $phpAds_settings_information;
    if ((!empty($GLOBALS['phpAds_db_link']) || phpAds_dbConnect()) && isset($phpAds_config['tbl_config'])) {
        $query = "SELECT *" . " FROM " . $phpAds_config['tbl_config'] . " WHERE agencyid=" . $agencyid;
        if ($res = phpAds_dbQuery($query)) {
            if ($row = phpAds_dbFetchArray($res, 0)) {
                while (list($k, $v) = each($phpAds_settings_information)) {
                    if (!$v['sql'] || !isset($row[$k])) {
                        continue;
                    }
                    switch ($v['type']) {
                        case 'boolean':
                            $row[$k] = $row[$k] == 't';
                            break;
                        case 'integer':
                            $row[$k] = (int) $row[$k];
                            break;
                        case 'array':
                            $row[$k] = unserialize($row[$k]);
                            break;
                        case 'float':
                            $row[$k] = (double) $row[$k];
                            break;
                    }
                    $phpAds_config[$k] = $row[$k];
                }
                reset($phpAds_settings_information);
                return true;
            }
        }
    }
    return false;
}
function Plugin_TrackerHistoryExecute($clientid, $start, $end, $delimiter = ",")
{
    global $phpAds_config, $date_format;
    global $strCampaign, $strTotal, $strDay, $strViews, $strClicks, $strCTRShort;
    header("Content-type: application/csv\nContent-Disposition: inline; filename=trackerhistory.csv");
    // get all trackers and group them by advertiser and campaign
    $res_trackers = phpAds_dbQuery("SELECT\n\t\t\t\t\t\t\t\t\t\ttrackers.trackerid,\n\t\t\t\t\t\t\t\t\t\ttrackers.trackername\n\t\t\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\t\t\t" . $phpAds_config['tbl_trackers'] . " as trackers\n\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\ttrackers.clientid = " . $clientid . "\n\t\t\t\t\t\t\t\t\t");
    $trackers = array();
    while ($row = phpAds_dbFetchArray($res_trackers)) {
        $trackers[$row['trackerid']] = array();
        $trackers[$row['trackerid']]['name'] = $row['trackername'];
    }
    $res_total_conversions = phpAds_dbQuery("SELECT\n\t\t\t\t\t\t\t\t\t\t\ttrackers.trackerid,\n\t\t\t\t\t\t\t\t\t\t\tcount(conversions.conversionid) as hits\n\t\t\t\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\t\t\t\t" . $phpAds_config['tbl_adconversions'] . " as conversions,\n\t\t\t\t\t\t\t\t\t\t\t" . $phpAds_config['tbl_trackers'] . " as trackers\n\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\ttrackers.trackerid = conversions.trackerid\n\t\t\t\t\t\t\t\t\t\t\tAND trackers.clientid = " . $clientid . "\n\t\t\t\t\t\t\t\t\t\t\tAND conversions.t_stamp >= '" . str_replace("/", "", $start) . "000000'\n\t\t\t\t\t\t\t\t\t\t\tAND conversions.t_stamp <= '" . str_replace("/", "", $end) . "235959'\n\t\t\t\t\t\t\t\t\t\tGROUP BY\n\t\t\t\t\t\t\t\t\t\t\tconversions.trackerid\n\t\t\t\t\t\t\t\t");
    while ($row = phpAds_dbFetchArray($res_total_conversions)) {
        $trackers[$row['trackerid']]['total_conversions'] = $row['hits'];
    }
    $res_conversions = phpAds_dbQuery("SELECT\n\t\t\t\t\t\t\t\t\t\t\ttrackers.trackerid,\n\t\t\t\t\t\t\t\t\t\t\tcount(*) as hits\n\t\t\t\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\t\t\t\t" . $phpAds_config['tbl_conversionlog'] . " as conversions,\n\t\t\t\t\t\t\t\t\t\t\t" . $phpAds_config['tbl_trackers'] . " as trackers\n\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\ttrackers.trackerid = conversions.trackerid\n\t\t\t\t\t\t\t\t\t\t\tAND trackers.clientid = " . $clientid . "\n\t\t\t\t\t\t\t\t\t\t\tAND conversions.t_stamp >= '" . str_replace("/", "", $start) . "000000'\n\t\t\t\t\t\t\t\t\t\t\tAND conversions.t_stamp <= '" . str_replace("/", "", $end) . "235959'\n\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\tGROUP BY\n\t\t\t\t\t\t\t\t\t\t\tconversions.trackerid\n\t\t\t\t\t\t\t\t");
    while ($row = phpAds_dbFetchArray($res_conversions)) {
        $trackers[$row['trackerid']]['conversions'] = $row['hits'];
    }
    //echo "<pre>";
    //print_r($trackers);
    //echo "</pre>";
    echo "Client: " . strip_tags(phpAds_getClientName($clientid)) . " - " . $start . " - " . $end . "\n\n";
    echo $GLOBALS['strName'] . $delimiter . $GLOBALS['strID'] . $delimiter . "Conversions" . $delimiter . "Total Hits" . "\n";
    echo "\n";
    foreach ($trackers as $id => $tracker) {
        echo $tracker['name'] . $delimiter . $id . $delimiter . $tracker['conversions'] . $delimiter . $tracker['total_conversions'] . $delimiter . "\n";
    }
}
function Plugin_GlobalhistoryExecute($delimiter = ",")
{
    global $phpAds_config, $date_format;
    global $strGlobalHistory, $strTotal, $strDay, $strViews, $strClicks, $strCTRShort;
    header("Content-type: application/csv\nContent-Disposition: \"inline; filename=globalhistory.csv\"");
    if (phpAds_isUser(phpAds_Admin)) {
        $res_query = "\n\t\tSELECT\n\t\t\tDATE_FORMAT(day, '" . $date_format . "') as day,\n\t\t\tSUM(views) AS adviews,\n\t\t\tSUM(clicks) AS adclicks\n\t\tFROM\n\t\t\t" . $phpAds_config['tbl_adstats'] . "\n\t\tGROUP BY\n\t\t\tday\n\t";
    } else {
        $res_query = "SELECT\n\t\t\t\t\t\tDATE_FORMAT(s.day, '" . $date_format . "') as day,\n\t\t\t\t\t\tSUM(s.views) AS adviews,\n\t\t\t\t\t\tSUM(s.clicks) AS adclicks\n\t\t\t\t\tFROM\n\t\t\t\t\t\t" . $phpAds_config['tbl_adstats'] . " \tas s,\n\t\t\t\t\t\t" . $phpAds_config['tbl_banners'] . " \tas b,\n\t\t\t\t\t\t" . $phpAds_config['tbl_campaigns'] . " as m,\n\t\t\t\t\t\t" . $phpAds_config['tbl_clients'] . " \tas c\n\t\t\t\t\tWHERE\n\t\t\t\t\t\ts.bannerid \t\t= b.bannerid AND\n\t\t\t\t\t\tb.campaignid \t= m.campaignid AND\n\t\t\t\t\t\tm.clientid \t\t= c.clientid AND\n\t\t\t\t\t\tc.agencyid \t\t= " . phpAds_getUserID() . "\n\t\t\t\t\tGROUP BY\n\t\t\t\t\t\tday";
    }
    $res_banners = phpAds_dbQuery($res_query) or phpAds_sqlDie();
    while ($row_banners = phpAds_dbFetchArray($res_banners)) {
        $stats[$row_banners['day']]['views'] = $row_banners['adviews'];
        $stats[$row_banners['day']]['clicks'] = $row_banners['adclicks'];
    }
    echo $strGlobalHistory . "\n\n";
    echo $strDay . $delimiter . $strViews . $delimiter . $strClicks . $delimiter . $strCTRShort . "\n";
    $totalclicks = 0;
    $totalviews = 0;
    if (isset($stats) && is_array($stats)) {
        for (reset($stats); $key = key($stats); next($stats)) {
            $row = array();
            //$key = implode('/',array_reverse(split('[-]',$key)));
            $row[] = $key;
            $row[] = $stats[$key]['views'];
            $row[] = $stats[$key]['clicks'];
            $row[] = phpAds_buildCTR($stats[$key]['views'], $stats[$key]['clicks']);
            echo implode($delimiter, $row) . "\n";
            $totalclicks += $stats[$key]['clicks'];
            $totalviews += $stats[$key]['views'];
        }
    }
    echo "\n";
    echo $strTotal . $delimiter . $totalviews . $delimiter . $totalclicks . $delimiter . phpAds_buildCTR($totalviews, $totalclicks) . "\n";
}
function phpAds_maintenanceReleaseLock($lock)
{
    switch ($lock['type']) {
        case 'db':
            phpAds_dbQuery("DO RELEASE('{$lock['id']}')");
            break;
    }
}
function phpAds_showBanners()
{
    global $phpAds_config;
    global $strUntitled, $strName, $strID, $strWeight;
    global $strProbability, $strPriority, $strRecalculatePriority;
    global $phpAds_TextDirection;
    $res = phpAds_dbQuery("\n\t\tSELECT\n\t\t\t*\n\t\tFROM\n\t\t\t" . $phpAds_config['tbl_banners'] . "\n\t\tORDER BY\n\t\t\tpriority DESC\n\t");
    $rows = array();
    $prioritysum = 0;
    while ($tmprow = phpAds_dbFetchArray($res)) {
        if ($tmprow['priority']) {
            $prioritysum += $tmprow['priority'];
            $rows[$tmprow['bannerid']] = $tmprow;
        }
    }
    if (is_array($rows)) {
        $i = 0;
        // Header
        echo "<table width='100%' border='0' align='center' cellspacing='0' cellpadding='0'>";
        echo "<tr height='25'>";
        echo "<td height='25'><b>&nbsp;&nbsp;" . $strName . "</b></td>";
        echo "<td height='25'><b>" . $strID . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b></td>";
        echo "<td height='25'><b>" . $strPriority . "</b></td>";
        echo "<td height='25'><b>" . $strProbability . "</b></td>";
        echo "</tr>";
        echo "<tr height='1'><td colspan='5' bgcolor='#888888'><img src='images/break.gif' height='1' width='100%'></td></tr>";
        // Banners
        foreach (array_keys($rows) as $key) {
            $name = phpAds_getBannerName($rows[$key]['bannerid'], 60, false);
            if ($i > 0) {
                echo "<tr height='1'><td colspan='5' bgcolor='#888888'><img src='images/break-l.gif' height='1' width='100%'></td></tr>";
            }
            echo "<tr height='25' " . ($i % 2 == 0 ? "bgcolor='#F6F6F6'" : "") . ">";
            echo "<td height='25'>";
            echo "&nbsp;&nbsp;";
            // Banner icon
            if ($rows[$key]['storagetype'] == 'html') {
                echo "<img src='images/icon-banner-html.gif' align='absmiddle'>&nbsp;";
            } elseif ($rows[$key]['storagetype'] == 'url') {
                echo "<img src='images/icon-banner-url.gif' align='absmiddle'>&nbsp;";
            } else {
                echo "<img src='images/icon-banner-stored.gif' align='absmiddle'>&nbsp;";
            }
            // Name
            echo $name;
            echo "</td>";
            echo "<td height='25'>" . $rows[$key]['bannerid'] . "</td>";
            echo "<td height='25'>" . $rows[$key]['priority'] . "</td>";
            echo "<td height='25'>" . number_format($rows[$key]['priority'] / $prioritysum * 100, $phpAds_config['percentage_decimals']) . "%</td>";
            echo "</tr>";
            $i++;
        }
        // Footer
        echo "<tr height='1'><td colspan='5' bgcolor='#888888'><img src='images/break.gif' height='1' width='100%'></td></tr>";
        echo "</table>";
    }
}
function phpAds_MaintenanceSelection($section)
{
    global $phpAds_config;
    global $phpAds_TextDirection;
    global $strChooseSection, $strPriority, $strCache, $strBanners, $strStats, $strStorage, $strMaintenance;
    if ($phpAds_config['compact_stats']) {
        // Determine left over verbose stats
        $viewresult = phpAds_dbQuery("SELECT COUNT(*) AS cnt FROM " . $phpAds_config['tbl_adviews']);
        $viewrow = phpAds_dbFetchArray($viewresult);
        if (isset($viewrow["cnt"]) && $viewrow["cnt"] != '') {
            $verboseviews = $viewrow["cnt"];
        } else {
            $verboseviews = 0;
        }
        $clickresult = phpAds_dbQuery("SELECT COUNT(*) AS cnt FROM " . $phpAds_config['tbl_adclicks']);
        $clickrow = phpAds_dbFetchArray($viewresult);
        if (isset($clickrow["cnt"]) && $clickrow["cnt"] != '') {
            $verboseclicks = $clickrow["cnt"];
        } else {
            $verboseclicks = 0;
        }
    }
    ?>
<script language="JavaScript">
<!--
function maintenance_goto_section()
{
	s = document.maintenance_selection.section.selectedIndex;

	s = document.maintenance_selection.section.options[s].value;
	document.location = 'maintenance-' + s + '.php';
}
// -->
</script>
<?php 
    echo "<table border='0' width='100%' cellpadding='0' cellspacing='0'>";
    echo "<tr><form name='maintenance_selection'><td height='35'>";
    echo "<b>" . $strChooseSection . ":&nbsp;</b>";
    echo "<select name='section' onChange='maintenance_goto_section();'>";
    echo "<option value='maintenance'" . ($section == 'maintenance' ? ' selected' : '') . ">" . $strMaintenance . "</option>";
    echo "<option value='banners'" . ($section == 'banners' ? ' selected' : '') . ">" . $strBanners . "</option>";
    echo "<option value='priority'" . ($section == 'priority' ? ' selected' : '') . ">" . $strPriority . "</option>";
    if ($phpAds_config['compact_stats'] && ($verboseviews > 0 || $verboseclicks > 0)) {
        echo "<option value='stats'" . ($section == 'stats' ? ' selected' : '') . ">" . $strStats . "</option>";
    }
    if ($phpAds_config['type_web_allow'] == true && ($phpAds_config['type_web_mode'] == 0 && $phpAds_config['type_web_dir'] != '' || $phpAds_config['type_web_mode'] == 1 && $phpAds_config['type_web_ftp'] != '') && $phpAds_config['type_web_url'] != '') {
        echo "<option value='storage'" . ($section == 'storage' ? ' selected' : '') . ">" . $strStorage . "</option>";
    }
    if ($phpAds_config['delivery_caching'] != 'none') {
        echo "<option value='cache'" . ($section == 'zones' ? ' selected' : '') . ">" . $strCache . "</option>";
    }
    echo "</select>&nbsp;<a href='javascript:void(0)' onClick='maintenance_goto_section();'>";
    echo "<img src='images/" . $phpAds_TextDirection . "/go_blue.gif' border='0'></a>";
    echo "</td></form></tr>";
    echo "</table>";
    phpAds_ShowBreak();
}
function phpAds_getCampaign($query)
{
    $campaigns = array();
    $res = phpAds_dbQuery($query) or phpAds_sqlDie();
    while ($row = phpAds_dbFetchArray($res)) {
        $campaigns[$row['campaignid']] = $row;
    }
    return $campaigns;
}
function Plugin_GlobalhistoryExecute($delimiter = 't', $quotes = '')
{
    global $phpAds_config, $date_format;
    global $strGlobalHistory, $strTotal, $strDay, $strViews, $strClicks, $strCTRShort;
    // Expand delimiter and quotes
    if ($delimiter == 't') {
        $delimiter = "\t";
    }
    if ($quotes == '1') {
        $quotes = "'";
    }
    if ($quotes == '2') {
        $quotes = '"';
    }
    header("Content-type: application/csv");
    header("Content-Disposition: inline; filename=\"publisherhistory.csv\"");
    if ($phpAds_config['compact_stats']) {
        $res_query = "\n\t\t\tSELECT\n\t\t\t\tDATE_FORMAT(day, '%Y%m%d') as date,\n\t\t\t\tDATE_FORMAT(day, '{$date_format}') as date_formatted,\n\t\t\t\tSUM(views) AS adviews,\n\t\t\t\tSUM(clicks) AS adclicks\n\t\t\tFROM\n\t\t\t\t" . $phpAds_config['tbl_adstats'] . "\n\t\t\tGROUP BY\n\t\t\t\tday\n\t\t\tORDER BY\n\t\t\t\tdate\n\t\t";
        $res_banners = phpAds_dbQuery($res_query) or phpAds_sqlDie();
        while ($row_banners = phpAds_dbFetchArray($res_banners)) {
            $stats[$row_banners['date_formatted']]['views'] = $row_banners['adviews'];
            $stats[$row_banners['date_formatted']]['clicks'] = $row_banners['adclicks'];
        }
    } else {
        $res_query = "\n\t\t\tSELECT\n\t\t\t\tDATE_FORMAT(t_stamp, '%Y%m%d') as date,\n\t\t\t\tDATE_FORMAT(t_stamp, '" . $date_format . "') as date_formatted,\n\t\t\t\tcount(bannerid) as adviews\n\t\t\tFROM\n\t\t\t\t" . $phpAds_config['tbl_adviews'] . "\n\t\t\tGROUP BY\n\t\t\t\tdate, date_formatted\n\t\t\tORDER BY\n\t\t\t\tdate\n\t\t";
        $res_banners = phpAds_dbQuery($res_query) or phpAds_sqlDie();
        while ($row_banners = phpAds_dbFetchArray($res_banners)) {
            $stats[$row_banners['date_formatted']]['views'] = $row_banners['adviews'];
            $stats[$row_banners['date_formatted']]['clicks'] = 0;
        }
        $res_query = "\n\t\t\tSELECT\n\t\t\t\tDATE_FORMAT(t_stamp, '%Y%m%d') as date,\n\t\t\t\tDATE_FORMAT(t_stamp, '" . $date_format . "') as date_formatted,\n\t\t\t\tcount(bannerid) as adclicks\n\t\t\tFROM\n\t\t\t\t" . $phpAds_config['tbl_adclicks'] . "\n\t\t\tGROUP BY\n\t\t\t\tdate, date_formatted\n\t\t\tORDER BY\n\t\t\t\tdate\n\t\t";
        $res_banners = phpAds_dbQuery($res_query) or phpAds_sqlDie();
        while ($row_banners = phpAds_dbFetchArray($res_banners)) {
            $stats[$row_banners['date_formatted']]['clicks'] = $row_banners['adclicks'];
        }
    }
    echo $quotes . $strGlobalHistory . $quotes . "\n\n";
    echo $quotes . $strDay . $quotes . $delimiter . $quotes . $strViews . $quotes . $delimiter;
    echo $quotes . $strClicks . $quotes . $delimiter . $quotes . $strCTRShort . $quotes . "\n";
    $totalclicks = 0;
    $totalviews = 0;
    if (isset($stats) && is_array($stats)) {
        foreach (array_keys($stats) as $key) {
            $row = array();
            $row[] = $quotes . $key . $quotes;
            $row[] = $quotes . $stats[$key]['views'] . $quotes;
            $row[] = $quotes . $stats[$key]['clicks'] . $quotes;
            $row[] = $quotes . phpAds_buildCTR($stats[$key]['views'], $stats[$key]['clicks']) . $quotes;
            echo implode($delimiter, $row) . "\n";
            $totalclicks += $stats[$key]['clicks'];
            $totalviews += $stats[$key]['views'];
        }
    }
    echo "\n";
    echo $quotes . $strTotal . $quotes . $delimiter . $quotes . $totalviews . $quotes . $delimiter;
    echo $quotes . $totalclicks . $quotes . $delimiter . $quotes . phpAds_buildCTR($totalviews, $totalclicks) . $quotes . "\n";
}
function phpAds_cacheInfo()
{
    global $phpAds_config;
    $result = array();
    $cacheres = phpAds_dbQuery("SELECT * FROM " . $phpAds_config['tbl_cache']);
    while ($cacherow = phpAds_dbFetchArray($cacheres)) {
        $result[$cacherow['cacheid']] = strlen($cacherow['content']);
    }
    return $result;
}
function phpAds_cacheInfo()
{
    global $phpAds_config;
    $result = array();
    $cacheres = phpAds_dbQuery("SELECT cacheid, LENGTH(content) AS len FROM " . $phpAds_config['tbl_cache']);
    while ($cacherow = phpAds_dbFetchArray($cacheres)) {
        $result[$cacherow['cacheid']] = $cacherow['len'];
    }
    return $result;
}
function phpAds_DeleteTracker($trackerid)
{
    global $phpAds_config;
    // Delete Campaign
    $res = phpAds_dbQuery("DELETE FROM " . $phpAds_config['tbl_trackers'] . " WHERE trackerid=" . $trackerid) or phpAds_sqlDie();
    // Delete Campaign/Tracker links
    $res = phpAds_dbQuery("DELETE FROM " . $phpAds_config['tbl_campaigns_trackers'] . " WHERE trackerid=" . $trackerid) or phpAds_sqlDie();
    // Delete Conversions Logged to this Tracker
    $res = phpAds_dbQuery("DELETE FROM " . $phpAds_config['tbl_conversionlog'] . " WHERE trackerid=" . $trackerid) or phpAds_sqlDie();
    // Delete stats for each banner
    phpAds_deleteStatsByTrackerID($trackerid);
}
Example #15
0
function phpAds_logConversion($userid, $trackerid)
{
    global $HTTP_SERVER_VARS, $phpAds_config, $phpAds_geo;
    // Check if host is on list of hosts to ignore
    if ($host = phpads_logCheckHost()) {
        $log_country = $phpAds_config['geotracking_stats'] && $phpAds_geo && $phpAds_geo['country'] ? $phpAds_geo['country'] : '';
        $log_host = $phpAds_config['log_hostname'] ? $HTTP_SERVER_VARS['REMOTE_HOST'] : '';
        $log_host = $phpAds_config['log_iponly'] ? $HTTP_SERVER_VARS['REMOTE_ADDR'] : $log_host;
        phpAds_dbQuery("INSERT " . ($phpAds_config['insert_delayed'] ? 'DELAYED' : '') . " INTO " . $phpAds_config['tbl_adconversions'] . "(userid" . ",trackerid" . ",host" . ",country)" . " VALUES " . "('" . $userid . "'" . "," . $trackerid . ",'" . $log_host . "'" . ",'" . $log_country . "')");
        return phpAds_dbInsertID();
    }
}
function phpAds_userlogAdd($action, $object, $details = '')
{
    global $phpAds_config, $phpAds_Usertype;
    if ($phpAds_Usertype != 0) {
        $usertype = $phpAds_Usertype;
        $userid = 0;
    } else {
        $usertype = phpAds_userAdministrator;
        $userid = 0;
    }
    $res = phpAds_dbQuery("\n\t\tINSERT INTO\n\t\t\t" . $phpAds_config['tbl_userlog'] . "\n\t\tSET\n\t\t\ttimestamp = " . time() . ",\n\t\t\tusertype = '" . $usertype . "',\n\t\t\tuserid = '" . $userid . "',\n\t\t\taction = '" . $action . "',\n\t\t\tobject = '" . $object . "',\n\t\t\tdetails = '" . addslashes($details) . "'\n\t");
}
function phpAds_performMaintenance()
{
    global $phpAds_config;
    // Include required files
    if (!defined('LIBLOCKS_INCLUDED')) {
        require phpAds_path . '/libraries/lib-locks.inc.php';
    }
    // Aquire lock to ensure that maintenance runs only once
    if ($lock = phpAds_maintenanceGetLock()) {
        // Set time limit and ignore user abort
        if (!get_cfg_var('safe_mode')) {
            @set_time_limit(300);
            @ignore_user_abort(1);
        }
        // Include required files
        if (!defined('LIBMAIL_INCLUDED')) {
            require phpAds_path . "/libraries/lib-mail.inc.php";
        }
        if (!defined('LIBADMINSTATISTICS_INCLUDED')) {
            require phpAds_path . "/admin/lib-statistics.inc.php";
        }
        if (!defined('LIBADMINCONFIG_INCLUDED')) {
            require phpAds_path . "/admin/lib-config.inc.php";
        }
        // Load language strings
        @(include phpAds_path . '/language/english/default.lang.php');
        if ($phpAds_config['language'] != 'english' && file_exists(phpAds_path . '/language/' . $phpAds_config['language'] . '/default.lang.php')) {
            @(include phpAds_path . '/language/' . $phpAds_config['language'] . '/default.lang.php');
        }
        // Update the timestamp
        $res = phpAds_dbQuery("\n\t\t\tUPDATE\n\t\t\t\t" . $phpAds_config['tbl_config'] . "\n\t\t\tSET\n\t\t\t\tmaintenance_timestamp = '" . time() . "'\n\t\t");
        // Run different maintenance tasks on midnight or soon after if the last run was before midnight
        if ($phpAds_config['maintenance_timestamp'] < phpAds_LastMidnight) {
            include phpAds_path . "/maintenance/maintenance-reports.php";
            include phpAds_path . "/maintenance/maintenance-activation.php";
            include phpAds_path . "/maintenance/maintenance-autotargeting.php";
            include phpAds_path . "/maintenance/maintenance-geotargeting.php";
            include phpAds_path . "/maintenance/maintenance-cleantables.php";
            include phpAds_path . "/maintenance/maintenance-openadssync.php";
        }
        include phpAds_path . "/maintenance/maintenance-priority.php";
        // Rebuild cache
        if (!defined('LIBVIEWCACHE_INCLUDED')) {
            include phpAds_path . '/libraries/deliverycache/cache-' . $phpAds_config['delivery_caching'] . '.inc.php';
        }
        phpAds_cacheDelete();
        // Release lock
        phpAds_maintenanceReleaseLock($lock);
        return true;
    }
    return false;
}
function phpAds_updateSources($old_source, $new_source)
{
    global $phpAds_config;
    $old_source_len = strlen($old_source);
    echo "Converting: " . $old_source . " to " . $new_source . " ...";
    $query = "UPDATE " . $phpAds_config['tbl_adclicks'] . " SET source=CONCAT('" . $new_source . "',SUBSTRING(source," . ($old_source_len + 1) . ")) WHERE source LIKE '" . $old_source . "%'";
    $res = phpAds_dbQuery($query) or phpAds_sqlDie();
    $query = "UPDATE " . $phpAds_config['tbl_conversionlog'] . " SET action_source=CONCAT('" . $new_source . "',SUBSTRING(action_source," . ($old_source_len + 1) . ")) WHERE action_source LIKE '" . $old_source . "%'";
    $res = phpAds_dbQuery($query) or phpAds_sqlDie();
    $query = "UPDATE " . $phpAds_config['tbl_adviews'] . " SET source=CONCAT('" . $new_source . "',SUBSTRING(source," . ($old_source_len + 1) . "))" . " WHERE source='" . $old_source . "%'" . " OR source LIKE '" . $old_source . "/%'";
    $res = phpAds_dbQuery($query) or phpAds_sqlDie();
    echo "Done.<br>";
}
function phpAds_getSourceStats($query, $listorder, $orderdirection)
{
    $res_stats = phpAds_dbQuery($query) or phpAds_sqlDie();
    while ($row_stats = phpAds_dbFetchArray($res_stats)) {
        $source = $row_stats['source'];
        if (strlen($source) > 0) {
            $sources = phpAds_buildSourceArray($sources, $source, '', $row_stats);
        }
    }
    // Sort the array
    $ascending = !($orderdirection == 'down' || $orderdirection == '');
    phpAds_qsort($sources, $listorder, $ascending);
}
 function _getTrackerArray()
 {
     $conf = $GLOBALS['_MAX']['CONF'];
     $where = "c.clientid = t.clientid";
     if (OA_Permission::isAccount(OA_ACCOUNT_MANAGER)) {
         $where .= " AND c.agencyid = " . OA_Permission::getEntityId();
     } elseif (OA_Permission::isAccount(OA_ACCOUNT_ADVERTISER)) {
         $where .= " AND t.clientid = " . OA_Permission::getEntityId();
     }
     $query = "\n            SELECT\n                c.clientname AS client_name,\n                c.clientid AS client_id,\n                t.trackername AS tracker_name,\n                t.trackerid AS tracker_id\n            FROM\n                {$conf['table']['trackers']} AS t,\n                {$conf['table']['clients']} AS c\n            WHERE\n                {$where}\n            ORDER BY\n                c.clientname,t.trackername\n        ";
     $res = phpAds_dbQuery($query);
     while ($row = phpAds_dbFetchArray($res)) {
         $trackerArray[$row['tracker_id']] = "<span dir='" . $GLOBALS['phpAds_TextDirection'] . "'>[id" . $row['client_id'] . "] " . $row['client_name'] . " - [id" . $row['tracker_id'] . "] " . $row['tracker_name'] . "</span> ";
     }
     return $trackerArray;
 }
function phpAds_SettingsWriteFlush()
{
    global $phpAds_config;
    global $phpAds_settings_information, $phpAds_settings_write_cache;
    $sql = array();
    $config_inc = array();
    while (list($k, $v) = each($phpAds_settings_write_cache)) {
        $k_sql = $phpAds_settings_information[$k]['sql'];
        $k_type = $phpAds_settings_information[$k]['type'];
        if ($k_sql) {
            if ($k_type == 'boolean') {
                $v = $v ? 't' : 'f';
            }
            $sql[] = $k . " = '" . $v . "'";
        } else {
            if ($k_type == 'boolean') {
                $v = $v ? true : false;
            } elseif ($k_type != 'array') {
                $v = stripslashes($v);
            }
            $config_inc[] = array($k, $v, $k_type);
        }
    }
    if (count($sql)) {
        if (phpAds_isUser(phpAds_Agency)) {
            $agencyid = phpAds_getUserID();
        } else {
            $agencyid = 0;
        }
        $query = "UPDATE " . $phpAds_config['tbl_config'] . " SET " . join(", ", $sql) . " WHERE agencyid=" . $agencyid;
        $res = @phpAds_dbQuery($query);
        if (@phpAds_dbAffectedRows() < 1) {
            $query = "INSERT INTO " . $phpAds_config['tbl_config'] . " SET " . join(", ", $sql) . ",agencyid=" . $agencyid;
            @phpAds_dbQuery($query);
        }
    }
    if (count($config_inc)) {
        if (!phpAds_ConfigFilePrepare()) {
            return false;
        }
        while (list(, $v) = each($config_inc)) {
            phpAds_ConfigFileSet($v[0], $v[1], $v[2]);
        }
        return phpAds_ConfigFileFlush();
    }
    return true;
}
function phpAds_DeleteBanner($bannerid)
{
    global $phpAds_config;
    // Cleanup webserver stored image
    $res = phpAds_dbQuery("\n\t\tSELECT\n\t\t\tstoragetype, filename\n\t\tFROM\n\t\t\t" . $phpAds_config['tbl_banners'] . "\n\t\tWHERE\n\t\t\tbannerid = '{$bannerid}'\n\t") or phpAds_sqlDie();
    if ($row = phpAds_dbFetchArray($res)) {
        if (($row['storagetype'] == 'web' || $row['storagetype'] == 'sql') && $row['filename'] != '') {
            phpAds_ImageDelete($row['storagetype'], $row['filename']);
        }
    }
    // Delete banner
    $res = phpAds_dbQuery("\n\t\tDELETE FROM\n\t\t\t" . $phpAds_config['tbl_banners'] . "\n\t\tWHERE\n\t\t\tbannerid = '{$bannerid}'\n\t\t") or phpAds_sqlDie();
    // Delete banner ACLs
    $res = phpAds_dbQuery("\n\t\tDELETE FROM\n\t\t\t" . $phpAds_config['tbl_acls'] . "\n\t\tWHERE\n\t\t\tbannerid = '{$bannerid}'\n\t\t") or phpAds_sqlDie();
    // Delete statistics for this banner
    phpAds_deleteStatsByBannerID($bannerid);
}
Example #23
0
 /**
  * @todo Handle cases where user is not Admin, Agency or Advertiser
  */
 function _getPublisherArray($orderBy = null)
 {
     $conf = $GLOBALS['_MAX']['CONF'];
     if (OA_Permission::isAccount(OA_ACCOUNT_ADMIN)) {
         $query = "SELECT affiliateid,name" . " FROM " . $conf['table']['prefix'] . $conf['table']['affiliates'];
     } elseif (OA_Permission::isAccount(OA_ACCOUNT_MANAGER)) {
         $query = "SELECT affiliateid,name" . " FROM " . $conf['table']['prefix'] . $conf['table']['affiliates'] . " WHERE agencyid=" . OA_Permission::getEntityId();
     } elseif (OA_Permission::isAccount(OA_ACCOUNT_ADVERTISER)) {
         $query = "SELECT affiliateid,name" . " FROM " . $conf['table']['prefix'] . $conf['table']['affiliates'] . " WHERE affiliateid=" . OA_Permission::getEntityId();
     }
     $orderBy ? $query .= " ORDER BY {$orderBy} ASC" : 0;
     $res = phpAds_dbQuery($query);
     while ($row = phpAds_dbFetchArray($res)) {
         $affiliateArray[$row['affiliateid']] = phpAds_buildAffiliateName($row['affiliateid'], $row['name']);
     }
     return $affiliateArray;
 }
function phpAds_fetchJavascriptVariables($trackerid)
{
    global $phpAds_config;
    include phpAds_path . '/libraries/deliverycache/cache-' . $phpAds_config['delivery_caching'] . '.inc.php';
    // Get cache
    $cache = phpAds_cacheFetch('what=tracker:' . $trackerid);
    if (!$cache) {
        $variables_result = phpAds_dbQuery("\n\t\t\t\t\t\t\t\tSELECT \n\t\t\t\t\t\t\t\t\tvariableid,\n\t\t\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\t\t\tvariabletype\n\t\t\t\t\t\t\t\tFROM \n\t\t\t\t\t\t\t\t\t" . $phpAds_config['tbl_variables'] . "\n\t\t\t\t\t\t\t\tWHERE \n\t\t\t\t\t\t\t\t\ttrackerid='" . $trackerid . "'");
        while ($variable = phpAds_dbFetchArray($variables_result)) {
            $cache[$variable['variableid']] = array('name' => $variable['name'], 'variabletype' => $variable['variabletype']);
        }
        if (count(cache) > 0) {
            phpAds_cacheStore('what=tracker:' . $trackerid, $cache);
        } else {
            return;
        }
    }
    return $cache;
}
function phpAds_DeleteCampaign($campaignid)
{
    global $phpAds_config;
    // Delete Campaign
    $res = phpAds_dbQuery("\n\t\tDELETE FROM\n\t\t\t" . $phpAds_config['tbl_clients'] . "\n\t\tWHERE\n\t\t\tclientid = '{$campaignid}'\n\t") or phpAds_sqlDie();
    // Loop through each banner
    $res_banners = phpAds_dbQuery("\n\t\tSELECT\n\t\t\tbannerid,\n\t\t\tstoragetype,\n\t\t\tfilename\n\t\tFROM\n\t\t\t" . $phpAds_config['tbl_banners'] . "\n\t\tWHERE\n\t\t\tclientid = '{$campaignid}'\n\t") or phpAds_sqlDie();
    while ($row = phpAds_dbFetchArray($res_banners)) {
        // Cleanup stored images for each banner
        if (($row['storagetype'] == 'web' || $row['storagetype'] == 'sql') && $row['filename'] != '') {
            phpAds_ImageDelete($row['storagetype'], $row['filename']);
        }
        // Delete Banner ACLs
        phpAds_dbQuery("\n\t\t\tDELETE FROM\n\t\t\t\t" . $phpAds_config['tbl_acls'] . "\n\t\t\tWHERE\n\t\t\t\tbannerid = " . $row['bannerid'] . "\n\t\t") or phpAds_sqlDie();
        // Delete stats for each banner
        phpAds_deleteStats($row['bannerid']);
    }
    // Delete Banners
    phpAds_dbQuery("\n\t\tDELETE FROM\n\t\t\t" . $phpAds_config['tbl_banners'] . "\n\t\tWHERE\n\t\t\tclientid = '{$campaignid}'\n\t") or phpAds_sqlDie();
}
function phpAds_checkForUpdates($already_seen = 0)
{
    global $phpAds_config, $phpAds_updatesServer;
    global $xmlrpcerruser;
    // Create client object
    $client = new xmlrpc_client($phpAds_updatesServer['script'], $phpAds_updatesServer['host'], $phpAds_updatesServer['port']);
    // Create XML-RPC request message
    $msg = new xmlrpcmsg("updateAdsNew.check", array(new xmlrpcval($phpAds_config['config_version'], "string"), new xmlrpcval($already_seen, "string")));
    // Send XML-RPC request message
    if ($response = $client->send($msg)) {
        // XML-RPC server found, now checking for errors
        if (!$response->faultCode()) {
            $ret = array(0, phpAds_xmlrpcDecode($response->value()));
            phpAds_dbQuery("\n\t\t\t\tUPDATE\n\t\t\t\t\t" . $phpAds_config['tbl_config'] . "\n\t\t\t\tSET\n\t\t\t\t\tupdates_last_seen = '" . $ret[1]['config_version'] . "',\n\t\t\t\t\tupdates_timestamp = " . time() . "\n\t\t\t");
        } else {
            $ret = array($response->faultCode(), $response->faultString());
        }
        return $ret;
    }
    return array(-1, 'No response from the server');
}
function phpAds_getSources($name = '', $parent = '')
{
    global $phpAds_config;
    if (strlen($parent) > 0) {
        $n = substr_count($parent, '/') + 2;
        $query = "SELECT" . " SUBSTRING_INDEX(SUBSTRING_INDEX(source,'/'," . $n . "),'/',-1) AS source_part" . ",COUNT(*) AS sum_views" . " FROM " . $phpAds_config['tbl_adviews'] . " WHERE source LIKE '" . $parent . "/%'" . " AND t_stamp > DATE_SUB(NOW(), INTERVAL 7 DAY)" . " GROUP BY source_part" . " ORDER BY sum_views DESC";
    } else {
        $query = "SELECT" . " SUBSTRING_INDEX(source, '/', 1) AS source_part" . ",COUNT(*) AS sum_views" . " FROM " . $phpAds_config['tbl_adviews'] . " WHERE t_stamp > DATE_SUB(NOW(), INTERVAL 7 DAY)" . " GROUP BY source_part" . " ORDER BY sum_views DESC";
    }
    $source_arr = array();
    $res_sources = phpAds_dbQuery($query) or phpAds_sqlDie();
    while ($row_sources = phpAds_dbFetchArray($res_sources)) {
        $source_arr[] = $row_sources;
        //echo "filing source: ".$row_sources['source']."...<br>\n";
        //phpAds_buildSourceArrayChildren($source_arr, $row_sources['source']);
    }
    // Sort the array
    //$ascending = !( ($orderdirection == 'down') || ($orderdirection == '') );
    //phpAds_sortSources($source_arr, $listorder, $ascending);
    return $source_arr;
}
function phpAds_cleanTables($weeks, $stats)
{
    global $phpAds_config;
    $report = '';
    // Determine tables
    if ($stats) {
        $tables = array($phpAds_config['tbl_adstats'] => array('day', 'Ymd'), $phpAds_config['tbl_adviews'] => array('t_stamp', 'YmdHis'), $phpAds_config['tbl_adclicks'] => array('t_stamp', 'YmdHis'), $phpAds_config['tbl_adconversions'] => array('t_stamp', 'YmdHis'));
    } else {
        $tables = array($phpAds_config['tbl_userlog'] => array('timestamp', ''));
    }
    $t_stamp = phpAds_makeTimestamp(mktime(0, 0, 0, date('m'), date('d'), date('Y')), (-7 * $weeks + 1) * 60 * 60 * 24);
    while (list($k, $v) = each($tables)) {
        if (!$v[1]) {
            $begin = $t_stamp;
        } else {
            $begin = date($v[1], $t_stamp);
        }
        phpAds_dbQuery("\n\t\t\tDELETE FROM\n\t\t\t\t" . $k . "\n\t\t\tWHERE\n\t\t\t\t" . $v[0] . " < " . $begin . "\n\t\t");
        $report .= 'Table ' . $k . ': deleted ' . phpAds_dbAffectedRows() . ' rows' . "\n";
    }
    return $report;
}
echo "<input type='hidden' name='previousweight' value='" . (isset($row["weight"]) ? $row["weight"] : '') . "'>";
echo "<input type='hidden' name='previousactive' value='" . (isset($row["active"]) ? $row["active"] : '') . "'>";
echo "</td></tr></table>";
echo "</td></tr>";
echo "<tr><td height='10' colspan='3'>&nbsp;</td></tr>";
echo "<tr height='1'><td colspan='3' bgcolor='#888888'><img src='images/break.gif' height='1' width='100%'></td></tr>";
echo "</table>";
echo "<br><br>";
echo "<input type='submit' name='submit' value='" . $strSaveChanges . "' tabindex='" . $tabindex++ . "'>";
echo "</form>";
/*********************************************************/
/* Form requirements                                     */
/*********************************************************/
// Get unique affiliate
$unique_names = array();
$res = phpAds_dbQuery("SELECT * FROM " . $phpAds_config['tbl_clients'] . " WHERE parent = " . $clientid . " AND clientid != '" . $campaignid . "'");
while ($row = phpAds_dbFetchArray($res)) {
    $unique_names[] = $row['clientname'];
}
?>

<script language='JavaScript'>
<!--
	phpAds_formSetRequirements('clientname', '<?php 
echo addslashes($strName);
?>
', true, 'unique');
	phpAds_formSetRequirements('views', '<?php 
echo addslashes($strViewsPurchased);
?>
', false, 'number+');
    // Delete stats for this banner
    phpAds_deleteStats($bannerid);
    // Return to campaign statistics
    Header("Location: stats-campaign-banners.php?clientid=" . $clientid . "&campaignid=" . $campaignid);
} elseif (isset($campaignid) && $campaignid != '') {
    // Get all banners for this client
    $idresult = phpAds_dbQuery(" SELECT\n\t\t\t\t\t\t\t\tbannerid\n\t\t\t\t\t\t\t  FROM\n\t\t\t\t\t\t\t  \t" . $phpAds_config['tbl_banners'] . "\n\t\t\t\t\t\t\t  WHERE\n\t\t\t\t\t\t\t\tclientid = '{$campaignid}'\n\t\t  \t\t\t\t ");
    // Loop to all banners for this client
    while ($row = phpAds_dbFetchArray($idresult)) {
        // Delete stats for the banner
        phpAds_deleteStats($row['bannerid']);
    }
    // Return to campaign statistics
    Header("Location: stats-client-campaigns.php?clientid=" . $clientid);
} elseif (isset($clientid) && $clientid != '') {
    // Get all banners for this client
    $idresult = phpAds_dbQuery("\n\t\tSELECT\n\t\t\tb.bannerid\n\t\tFROM\n\t\t\t" . $phpAds_config['tbl_banners'] . " AS b,\n\t\t\t" . $phpAds_config['tbl_clients'] . " AS c\n\t\tWHERE\n\t\t\tc.parent = {$clientid} AND\n\t\t\tc.clientid = b.clientid\n\t");
    // Loop to all banners for this client
    while ($row = phpAds_dbFetchArray($idresult)) {
        // Delete stats for the banner
        phpAds_deleteStats($row['bannerid']);
    }
    // Return to campaign statistics
    Header("Location: stats-global-client.php");
} elseif (isset($all) && $all == 'tr' . 'ue') {
    phpAds_dbQuery("DELETE FROM " . $phpAds_config['tbl_adviews']) or phpAds_sqlDie();
    phpAds_dbQuery("DELETE FROM " . $phpAds_config['tbl_adclicks']) or phpAds_sqlDie();
    phpAds_dbQuery("DELETE FROM " . $phpAds_config['tbl_adstats']) or phpAds_sqlDie();
    // Return to campaign statistics
    Header("Location: stats-global-client.php");
}