function phpAds_storeCompact($base, $count, $stats) { global $phpAds_config; global $strConvertAdViews, $strConvertAdClicks; $adviews = 0; $adclicks = 0; $day = date('Ymd', $base + $count * 60 * 60 * 24); foreach (array_keys($stats) as $bannerid) { $stats_b = $stats[$bannerid]; foreach (array_keys($stats_b) as $zoneid) { $stats_z = $stats_b[$zoneid]; foreach (array_keys($stats_z) as $hour) { $stats_h = $stats_z[$hour]; foreach (array_keys($stats_h) as $source) { $stats_s = $stats_h[$source]; $result = phpAds_dbQuery("INSERT INTO " . $phpAds_config['tbl_adstats'] . " SET clicks = " . $stats_s['clicks'] . ", views = " . $stats_s['views'] . ", \n\t\t\t\t\t\tday = {$day}, hour = {$hour}, bannerid = {$bannerid}, zoneid = {$zoneid}, source = {$source} "); if (phpAds_dbAffectedRows() < 1) { $result = phpAds_dbQuery("UPDATE " . $phpAds_config['tbl_adstats'] . " SET views = views + " . $stats_s['views'] . ",\n\t\t\t\t\t\t\tclicks = clicks + " . $stats_s['clicks'] . " WHERE day = {$day} AND hour = {$hour} \n\t\t\t\t\t\t\tAND bannerid = {$bannerid} AND zoneid = {$zoneid} AND source = {$source} "); } $adclicks += $stats_s['clicks']; $adviews += $stats_s['views']; } } } } phpAds_printResult(" " . $adviews . " " . $strConvertAdViews . " " . $adclicks . " " . $strConvertAdClicks . "\\n"); return true; }
function phpAds_cacheStore($name, $cache) { global $phpAds_config; $result = phpAds_dbQuery("UPDATE " . $phpAds_config['tbl_cache'] . " SET content='" . addslashes(serialize($cache)) . "' WHERE cacheid='" . $name . "'"); if (phpAds_dbAffectedRows() == 0) { $result = phpAds_dbQuery("INSERT INTO " . $phpAds_config['tbl_cache'] . " SET cacheid='" . $name . "', content='" . addslashes(serialize($cache)) . "'"); } }
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_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; }
if (is_array($targetviews)) { list($targetviews, ) = $targetviews; } phpAds_dbQuery("\n\t\t\tUPDATE " . $phpAds_config['tbl_clients'] . "\n\t\t\tSET\n\t\t\t\ttarget = " . $targetviews . "\n\t\t\tWHERE\n\t\t\t\tclientid = " . $campaignid); } if (isset($move) && $move == 't') { // We are moving a client to a campaign // Update banners $res = phpAds_dbQuery("\n\t\t\tUPDATE\n\t\t\t\t" . $phpAds_config['tbl_banners'] . "\n\t\t\tSET\n\t\t\t\tclientid='" . $campaignid . "'\n\t\t\tWHERE\n\t\t\t\tclientid='" . $clientid . "'\n\t\t\t") or phpAds_sqlDie(); // Force priority recalculation $new_campaing = false; } // Update targetstats if ($targetviews != $target_old) { $res = phpAds_dbQuery("\n\t\t\tUPDATE\n\t\t\t\t" . $phpAds_config['tbl_targetstats'] . "\n\t\t\tSET\n\t\t\t\ttarget = '" . $targetviews . "',\n\t\t\t\tmodified = 1\n\t\t\tWHERE\n\t\t\t\tclientid = '" . $campaignid . "' AND\n\t\t\t\tday = " . date('Ymd') . "\n\t\t\t"); if (!phpAds_dbAffectedRows($res)) { phpAds_dbQuery("\n\t\t\t\tINSERT INTO " . $phpAds_config['tbl_targetstats'] . "\n\t\t\t\t\t(day, clientid, target, modified)\n\t\t\t\tVALUES\n\t\t\t\t\t(" . date('Ymd') . ", '" . $campaignid . "', '" . $targetviews . "', 1)\n\t\t\t\t"); } } // Recalculate priority only when editing a campaign // or moving banners into a newly created, and when: // // - campaing changes status (activated or deactivated) or // - the campaign is active and target/weight are changed // if (!$new_campaign && ($active != $active_old || $active == 't' && ($targetviews != $target_old || $weight != $weight_old))) { include "../libraries/lib-priority.inc.php"; phpAds_PriorityCalculate(); } // Rebuild cache if (!defined('LIBVIEWCACHE_INCLUDED')) {
} $phpAds_config['compatibility_mode'] = false; $phpAds_config['dblocal'] = isset($dblocal); $phpAds_config['dbhost'] = $dbhost; $phpAds_config['dbport'] = isset($dbport) && $dbport ? $dbport : 3306; $phpAds_config['dbuser'] = $dbuser; $phpAds_config['dbpassword'] = isset($dbpassword) ? $dbpassword : ''; $phpAds_config['dbname'] = $dbname; if (!phpAds_dbConnect()) { $errormessage[0][] = $strCouldNotConnectToDB; } else { // Drop test table if one exists phpAds_dbQuery("DROP TABLE phpads_tmp_dbpriviligecheck"); // Check if phpAdsNew can create tables phpAds_dbQuery("CREATE TABLE phpads_tmp_dbpriviligecheck (tmp int)"); if (phpAds_dbAffectedRows() >= 0) { phpAds_dbQuery("DROP TABLE phpads_tmp_dbpriviligecheck"); } else { $errormessage[0][] = $strCreateTableTestFailed; } // Check table type if (phpAds_tableTypesSupported && !phpAds_checkTableType($table_type)) { $errormessage[1][] = $strTableWrongType; } } // Check table prefix if (strlen($table_prefix) && !eregi("^[a-z][a-z0-9_]*\$", $table_prefix)) { $errormessage[1][] = $strTablePrefixInvalid; } if (!isset($errormessage) || !count($errormessage)) { $installvars['dblocal'] = $phpAds_config['dblocal'];
// Check for PREG extention if (!function_exists('preg_match')) { $fatal[] = $strWarningPREG; } // Check if config file is writable if (!phpAds_isConfigWritable()) { $fatal[] = $strConfigLockedDetected; } // Drop test table if one exists phpAds_dbQuery("DROP TABLE phpads_tmp_dbpriviligecheck"); // Try to create a new table phpAds_dbQuery("CREATE TABLE phpads_tmp_dbpriviligecheck (tmp int)"); // Check if phpAdsNew can create tables if (phpAds_dbAffectedRows() >= 0) { phpAds_dbQuery("ALTER TABLE phpads_tmp_dbpriviligecheck MODIFY COLUMN tmp int"); if (phpAds_dbAffectedRows() < 0) { $fatal[] = $strUpdateTableTestFailed; } // Passed all test, now drop the test table phpAds_dbQuery("DROP TABLE phpads_tmp_dbpriviligecheck"); } else { $fatal[] = $strUpdateTableTestFailed; } // Repeat proceed request if config still not writeable if (count($fatal)) { $step = 1; } } if ($upgrade && $step == 1) { // Print a proceed request if an upgrade is needed phpAds_PageHeader("1");
function phpAds_logClick($bannerid, $clientid, $zoneid, $source) { global $phpAds_config, $phpAds_geo; if ($host = phpads_logCheckHost()) { $log_source = $phpAds_config['log_source'] ? $source : ''; if ($phpAds_config['compact_stats']) { // LOW PRIORITY UPDATEs are disabled until further notice - Matteo $result = phpAds_dbQuery("UPDATE " . (false && $phpAds_config['insert_delayed'] ? 'LOW_PRIORITY' : '') . " " . $phpAds_config['tbl_adstats'] . " SET clicks = clicks + 1 WHERE day = NOW() AND\n\t\t\t\thour = HOUR(NOW()) AND bannerid = '" . $bannerid . "' AND zoneid = '" . $zoneid . "' AND\n\t\t\t\tsource = '" . $log_source . "' "); if (phpAds_dbAffectedRows() == 0) { $result = phpAds_dbQuery("INSERT " . ($phpAds_config['insert_delayed'] ? 'DELAYED' : '') . " INTO " . $phpAds_config['tbl_adstats'] . " SET clicks = 1, views = 0, day = NOW(),\n\t\t\t\t\thour = HOUR(NOW()), bannerid = '" . $bannerid . "', zoneid = '" . $zoneid . "',\n\t\t\t\t\tsource = '" . $log_source . "' "); } } else { $log_country = $phpAds_config['geotracking_stats'] && $phpAds_geo && $phpAds_geo['country'] ? $phpAds_geo['country'] : ''; $log_host = $phpAds_config['log_hostname'] ? $_SERVER['REMOTE_HOST'] : ''; $log_host = $phpAds_config['log_iponly'] ? $_SERVER['REMOTE_ADDR'] : $log_host; $result = phpAds_dbQuery("INSERT " . ($phpAds_config['insert_delayed'] ? 'DELAYED' : '') . " INTO " . $phpAds_config['tbl_adclicks'] . " SET bannerid = '" . $bannerid . "', zoneid = '" . $zoneid . "',\n\t\t\t\thost = '" . $log_host . "', source = '" . $log_source . "', country = '" . $log_country . "' "); } phpAds_logExpire($clientid, phpAds_Clicks); } }
function phpAds_countConversions($begin_timestamp, $end_timestamp, $day, $hour) { global $phpAds_config, $report; //Process conversions... $num_conversions = 0; $time = time(); $report .= "\tCounting the verbose conversions between " . $begin_timestamp . " and " . $end_timestamp . "...\n"; // Get all of the conversions for this hour... $conversion_query = "SELECT userid" . ",t_stamp" . ",trackerid" . ",host" . ",country" . " FROM " . $phpAds_config['tbl_adconversions'] . " WHERE userid!=''" . " AND t_stamp>=" . $begin_timestamp . " AND t_stamp<" . $end_timestamp . " ORDER BY trackerid"; $res = phpAds_dbQuery($conversion_query) or $report .= "Could not perform SQL: " . $conversion_query . "\n"; while ($row = phpAds_dbFetchArray($res)) { $userid = $row['userid']; $t_stamp = $row['t_stamp']; $trackerid = $row['trackerid']; $host = $row['host']; $country = $row['country']; $campaign_query = "SELECT *" . " FROM " . $phpAds_config['tbl_campaigns_trackers'] . " WHERE trackerid=" . $trackerid; $campaign_res = phpAds_dbQuery($campaign_query) or $report .= "Could not perform SQL: " . $campaign_query . "\n"; while ($campaign_row = phpAds_dbFetchArray($campaign_res)) { $found = false; $action_query = "SELECT c.t_stamp AS t_stamp" . ",c.bannerid AS bannerid" . ",c.zoneid AS zoneid" . ",c.host AS host" . ",c.source AS source" . ",c.country AS country" . " FROM " . $phpAds_config['tbl_adclicks'] . " AS c" . "," . $phpAds_config['tbl_banners'] . " AS b" . " WHERE c.userid='" . $userid . "'" . " AND c.bannerid=b.bannerid" . " AND b.campaignid=" . $campaign_row['campaignid'] . " AND c.t_stamp>= DATE_SUB(" . $t_stamp . ", INTERVAL " . $campaign_row['clickwindow'] . " SECOND)" . " AND c.t_stamp<" . $t_stamp . " ORDER BY t_stamp DESC" . " LIMIT 1"; /* $action_query = "SELECT t_stamp". ",bannerid". ",zoneid". ",host". ",source". ",country". " FROM ".$phpAds_config['tbl_adclicks']. " WHERE userid='".$userid."'". " AND t_stamp>= DATE_SUB(".$t_stamp.", INTERVAL ".$campaign_row['clickwindow']." SECOND)". " AND t_stamp<".$t_stamp. " ORDER BY t_stamp DESC". " LIMIT 1" ; */ $action_res = phpAds_dbQuery($action_query) or $report .= "Could not perform SQL: " . $action_query . "\n"; if ($action_row = phpAds_dbFetchArray($action_res)) { $found = true; $action = 'click'; } else { $action_query = "SELECT v.t_stamp AS t_stamp" . ",v.bannerid AS bannerid" . ",v.zoneid AS zoneid" . ",v.host AS host" . ",v.source AS source" . ",v.country AS country" . " FROM " . $phpAds_config['tbl_adviews'] . " AS v" . "," . $phpAds_config['tbl_banners'] . " AS b" . " WHERE v.userid='" . $userid . "'" . " AND v.bannerid=b.bannerid" . " AND b.campaignid=" . $campaign_row['campaignid'] . " AND v.t_stamp>= DATE_SUB(" . $t_stamp . ", INTERVAL " . $campaign_row['viewwindow'] . " SECOND)" . " AND v.t_stamp<" . $t_stamp . " ORDER BY t_stamp DESC" . " LIMIT 1"; /* $action_query = "SELECT t_stamp". ",bannerid". ",zoneid". ",host". ",source". ",country". " FROM ".$phpAds_config['tbl_adviews']. " WHERE userid='".$userid."'". " AND t_stamp>= DATE_SUB(".$t_stamp.", INTERVAL ".$campaign_row['viewwindow']." SECOND)". " AND t_stamp<".$t_stamp. " ORDER BY t_stamp DESC". " LIMIT 1" ; */ $action_res = phpAds_dbQuery($action_query) or $report .= "Could not perform SQL: " . $action_query . "\n"; if ($action_row = phpAds_dbFetchArray($action_res)) { $found = true; $action = 'view'; } } if ($found) { $campaignid = $campaign_row['campaignid']; $action_t_stamp = $action_row['t_stamp']; $action_bannerid = $action_row['bannerid']; $action_zoneid = $action_row['zoneid']; $action_host = $action_row['host']; $action_source = $action_row['source']; $action_country = $action_row['country']; $cnv_logstats = $campaign_row['logstats']; $cnv_clickwindow = $campaign_row['clickwindow']; $cnv_viewwindow = $campaign_row['viewwindow']; // Found an item which passed the rules. // Now, log this item $log_query = "INSERT INTO " . $phpAds_config['tbl_conversionlog'] . " (campaignid" . ",trackerid" . ",userid" . ",t_stamp" . ",host" . ",country" . ",cnv_logstats" . ",cnv_clickwindow" . ",cnv_viewwindow" . ",action" . ",action_bannerid" . ",action_zoneid" . ",action_t_stamp" . ",action_host" . ",action_source" . ",action_country)" . " VALUES " . " (" . $campaignid . "," . $trackerid . ",'" . $userid . "'" . "," . $t_stamp . ",'" . $host . "'" . ",'" . $country . "'" . ",'" . $cnv_logstats . "'" . "," . $cnv_clickwindow . "," . $cnv_viewwindow . ",'" . $action . "'" . "," . $action_bannerid . "," . $action_zoneid . "," . $action_t_stamp . ",'" . $action_host . "'" . ",'" . $action_source . "'" . ",'" . $action_country . "')"; phpAds_dbQuery($log_query) or $report .= "Could not perform SQL: " . $log_query . "\n"; $conversionlogid = phpAds_dbInsertID(); $conversion_update_query = "UPDATE " . $phpAds_config['tbl_adconversions'] . " SET conversionlogid=" . $conversionlogid . " WHERE userid='" . $userid . "'" . " AND t_stamp=" . $t_stamp; phpAds_dbQuery($conversion_query) or $report .= "Could not perform SQL: " . $conversion_query . "\n"; $num_conversions++; } } } // Now, add up all of the conversions that we just logged and put them into adstats. //Process conversions... $num_conversions = 0; $conversion_query = "SELECT action_bannerid" . ",action_zoneid" . ",action_source" . ",count(*) as conversions" . " FROM " . $phpAds_config['tbl_conversionlog'] . " WHERE t_stamp>=" . $begin_timestamp . " AND t_stamp<" . $end_timestamp . " AND cnv_logstats='y'" . " GROUP BY action_bannerid,action_zoneid,action_source"; $conversion_result = phpAds_dbQuery($conversion_query) or $report .= "Could not perform SQL: " . $conversion_query . "\n"; while ($conversion_row = phpAds_dbFetchArray($conversion_result)) { $stat_query = "UPDATE " . $phpAds_config['tbl_adstats'] . " SET conversions=conversions+" . $conversion_row['conversions'] . " WHERE day='" . $day . "'" . " AND hour=" . $hour . " AND bannerid=" . $conversion_row['action_bannerid'] . " AND zoneid=" . $conversion_row['action_zoneid']; $stat_result = phpAds_dbQuery($stat_query) or $report .= " Could not perform SQL: " . $stat_query . "\n"; if (phpAds_dbAffectedRows($stat_result) < 1) { $stat_query = "INSERT INTO " . $phpAds_config['tbl_adstats'] . " SET day='" . $day . "'" . ",hour=" . $hour . ",bannerid=" . $conversion_row['action_bannerid'] . ",zoneid=" . $conversion_row['action_zoneid'] . ",conversions=" . $conversion_row['conversions']; $stat_result = phpAds_dbQuery($stat_query) or $report .= " Could not perform SQL: " . $stat_query . "\n"; } $num_conversions += $conversion_row['conversions']; } $report .= "\tCounted " . $num_conversions . " conversions in " . (time() - $time) . " seconds.\n\n"; }
function phpAds_predictFutureTraffic($zoneid, $hourly_views, $avg_hourly_views, $trend, $days_running, $report) { global $phpAds_config; $day_of_week = 0; for ($i = 0; $i <= 28; $i++) { if ($i == 0) { $day_of_week = $days_running > -1 ? $hourly_views[$i]['day_of_week'] : 0; } else { $day_of_week++; if ($day_of_week > 6) { $day_of_week = 0; } } for ($j = 0; $j < 24; $j++) { if (!isset($hourly_views[$i]['hour'][$j])) { $target_this_hour = $days_running > -1 ? round($avg_hourly_views[$i][$j] * $trend) : 0; $query = "UPDATE " . $phpAds_config['tbl_targetstats'] . " SET target=" . $target_this_hour . " WHERE zoneid=" . $zoneid . " AND campaignid=0" . " AND day=DATE_ADD('" . $current_day . "', INTERVAL " . $i . " DAY)" . " AND hour=" . $j; $res = phpAds_dbQuery($query) or $report .= " Broken Query : " . $query . "\n"; if (phpAds_dbAffectedRows($res) < 1) { $query = "INSERT INTO " . $phpAds_config['tbl_targetstats'] . " SET target=" . $target_this_hour . ",zoneid=" . $zoneid . ",campaignid=0" . ",day=DATE_ADD('" . $current_day . "', INTERVAL " . $i . " DAY)" . ",hour=" . $j; $res = phpAds_dbQuery($query) or $report .= " Broken Query : " . $query . "\n"; } } } } }
function phpAds_changeSourcePart($source_part_old, $source_part_new, $parent) { $unknown_source = '3284729384723984701euijswhfjdncfr9283yrfhe'; global $phpAds_config; $source_old = strlen($parent) > 0 ? $parent . '/' . $source_part_old : $source_part_old; $len_source_old = strlen($source_old); echo "Converting: " . $source_old . "...<br>\n"; $prev_source = $unknown_source; $views = 0; $query = "SELECT *" . " FROM " . $phpAds_config['tbl_adstats'] . " WHERE source='" . $source_old . "'" . " OR source LIKE '" . $source_old . "/%'" . " ORDER BY source"; $res = phpAds_dbQuery($query); while ($row = phpAds_dbFetchArray($res)) { $source_new = strlen($parent) > 0 ? $parent . '/' . $source_part_new : $source_part_new; $source_new .= substr($row['source'], $len_source_old); if ($prev_source != $row['source']) { if ($prev_source != $unknown_source) { echo "Total Views Processed: " . $views . ".<br>\n"; } echo "Processing: " . $source_new . "..."; $prev_source = $row['source']; $views = 0; // Update the adviews table... $query1 = "UPDATE " . $phpAds_config['tbl_adviews'] . " SET source='" . addslashes($source_new) . "'" . " WHERE source='" . addslashes($row['source']) . "'"; $res1 = phpAds_dbQuery($query1) or phpAds_sqlDie(); echo "v "; // Update the adclicks table... $query1 = "UPDATE " . $phpAds_config['tbl_adclicks'] . " SET source='" . addslashes($source_new) . "'" . " WHERE source='" . addslashes($row['source']) . "'"; $res1 = phpAds_dbQuery($query1) or phpAds_sqlDie(); echo "c "; // Update the conversion log table... $query1 = "UPDATE " . $phpAds_config['tbl_conversionlog'] . " SET action_source='" . addslashes($source_new) . "'" . " WHERE action_source='" . addslashes($row['source']) . "'"; $res1 = phpAds_dbQuery($query1) or phpAds_sqlDie(); echo "n "; } else { $views += $row['views']; echo ". "; } $query1 = "UPDATE " . $phpAds_config['tbl_adstats'] . " SET views=views+" . $row['views'] . ",clicks=clicks+" . $row['clicks'] . ",conversions=conversions+" . $row['conversions'] . " WHERE bannerid=" . $row['bannerid'] . " AND zoneid=" . $row['zoneid'] . " AND source='" . addslashes($source_new) . "'" . " AND hour=" . $row['hour'] . " AND day='" . $row['day'] . "'"; $res1 = phpAds_dbQuery($query1) or phpAds_sqlDie(); if (phpAds_dbAffectedRows($res1) < 1) { $query1 = "INSERT INTO " . $phpAds_config['tbl_adstats'] . " SET views=" . $row['views'] . ",clicks=" . $row['clicks'] . ",conversions=" . $row['conversions'] . ",bannerid=" . $row['bannerid'] . ",zoneid=" . $row['zoneid'] . ",source='" . addslashes($source_new) . "'" . ",hour=" . $row['hour'] . ",day='" . $row['day'] . "'"; $res1 = phpAds_dbQuery($query1) or phpAds_sqlDie(); } $query1 = "DELETE FROM " . $phpAds_config['tbl_adstats'] . " WHERE bannerid=" . $row['bannerid'] . " AND zoneid=" . $row['zoneid'] . " AND source='" . addslashes($row['source']) . "'" . " AND hour=" . $row['hour'] . " AND day='" . $row['day'] . "'"; $res1 = phpAds_dbQuery($query1) or phpAds_sqlDie(); } echo "Total Views Processed: " . $views . ".<br>\n"; }