예제 #1
0
function phpAds_getSources($parent, $level)
{
    global $bannerids, $campaignid, $hours, $phpAds_config, $sources, $total_views, $total_clicks, $total_conversions, $viewmin;
    $source_sql = "SELECT" . " SUBSTRING_INDEX(source,'/'," . $level . ") AS source_part" . ",SUM(views) AS sum_views" . ",SUM(clicks) AS sum_clicks" . ",IF(SUM(views) > 0, SUM(clicks)/SUM(views)*100, 0.00) AS sum_ctr" . " FROM " . $phpAds_config['tbl_banners'] . "," . $phpAds_config['tbl_adstats'] . " WHERE campaignid = " . $campaignid;
    if ($level > 1) {
        $source_sql .= " AND SUBSTRING_INDEX(source,'/'," . ($level - 1) . ")='" . $parent . "'";
    }
    $source_sql .= " AND " . $phpAds_config['tbl_banners'] . ".bannerid=" . $phpAds_config['tbl_adstats'] . ".bannerid" . " AND " . phpAds_buildBannerWhereClause($bannerids) . " AND " . phpAds_buildHourWhereClause($hours) . " GROUP BY SUBSTRING_INDEX(source,'/'," . $level . ")" . " ORDER BY sum_ctr DESC";
    $source_res = phpAds_dbQuery($source_sql) or phpAds_sqlDie();
    while ($source_row = phpAds_dbFetchArray($source_res)) {
        $same = $source_row['source_part'] == $parent;
        if ($source_row['sum_views'] >= $viewmin) {
            $checked = false;
            for ($i = 0; $i < sizeof($sources); $i++) {
                $found = false;
                if ($sources[$i] == $source_row['source_part']) {
                    $found = true;
                } elseif (strrchr($sources[$i], '*') > -1 && strrchr($sources[$i], '*') == strlen($sources[$i])) {
                    $found = true;
                }
                if ($found) {
                    $checked = true;
                    $total_views += $source_row['sum_views'];
                    $total_clicks += $source_row['sum_clicks'];
                    $total_conversions += $source_row['sum_conversions'];
                    break;
                }
            }
            echo "<tr>\n";
            echo "\t<td><input type='checkbox' name='sources[]' value='" . $source_row['source_part'] . ($same ? '' : '*') . "'" . ($checked ? ' checked' : '') . "></td>\n";
            echo "\t<td>";
            for ($i = 0; $i < $level - 1; $i++) {
                echo "&nbsp;&nbsp;&nbsp;&nbsp;";
            }
            echo $source_row['source_part'] . ($same ? '' : '*') . "</td>\n";
            echo "\t<td>&nbsp;</td>\n";
            echo "\t<td>" . $source_row['sum_views'] . "</td>\n";
            echo "\t<td>" . $source_row['sum_clicks'] . "</td>\n";
            echo "\t<td>" . $source_row['sum_conversions'] . "</td>\n";
            echo "\t<td>" . $source_row['sum_ctr'] . "</td>\n";
            echo "\t<td>" . $source_row['sum_cnvr'] . "</td>\n";
            echo "</tr>\n";
            if ($checked && !$same) {
                phpAds_getSources($source_row['source_part'], $level + 1);
            }
        }
    }
}
function phpAds_getPageData($pageID)
{
    global $parent;
    // GET PREFERENCES
    require_once "lib-prefs.inc.php";
    if (!isset($parent)) {
        $parent = phpAds_getPref($pageID, 'parent');
    }
    // GET DATA
    require_once 'lib-data-sources.inc.php';
    $source_arr = phpAds_getSources('SOURCES', $parent);
    return $source_arr;
}