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; }
} // 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')) { include phpAds_path . '/libraries/deliverycache/cache-' . $phpAds_config['delivery_caching'] . '.inc.php'; } phpAds_cacheDelete(); Header("Location: campaign-zone.php?clientid=" . $clientid . "&campaignid=" . $campaignid); exit; } /*********************************************************/ /* HTML framework */ /*********************************************************/ if ($campaignid != "") { if (isset($Session['prefs']['client-campaigns.php'][$clientid]['listorder'])) { $navorder = $Session['prefs']['client-campaigns.php'][$clientid]['listorder']; } else { $navorder = ''; } if (isset($Session['prefs']['client-campaigns.php'][$clientid]['orderdirection'])) { $navdirection = $Session['prefs']['client-campaigns.php'][$clientid]['orderdirection']; } else {
} include '../libraries/layerstyles/' . $layerstyle . '/invocation.inc.php'; } $append = addslashes(phpAds_GenerateInvocationCode()); //Temporary fix - allow {source} for popup tags... $append = str_replace('%7Bsource%7D', '{source}', $append); } $sqlupdate[] = "append='" . $append . "'"; $sqlupdate[] = "appendtype='" . $appendtype . "'"; } $res = phpAds_dbQuery("\n\t\t\tUPDATE\n\t\t\t\t" . $phpAds_config['tbl_zones'] . "\n\t\t\tSET\n\t\t\t\t" . join(', ', $sqlupdate) . "\n\t\t\tWHERE\n\t\t\t\tzoneid='" . $zoneid . "'\n\t\t") or phpAds_sqlDie(); // Rebuild Cache if (!defined('LIBVIEWCACHE_INCLUDED')) { include phpAds_path . '/libraries/deliverycache/cache-' . $phpAds_config['delivery_caching'] . '.inc.php'; } phpAds_cacheDelete('what=zone:' . $zoneid); // Do not redirect until not finished with zone appending, if present if (!isset($appendsave) || $appendsave) { if (phpAds_isUser(phpAds_Affiliate)) { if (phpAds_isAllowed(phpAds_LinkBanners)) { header("Location: zone-include.php?affiliateid=" . $affiliateid . "&zoneid=" . $zoneid); } else { header("Location: zone-probability.php?affiliateid=" . $affiliateid . "&zoneid=" . $zoneid); } } else { header("Location: zone-include.php?affiliateid=" . $affiliateid . "&zoneid=" . $zoneid); } exit; } } }
// Edit if (isset($zoneid) && $zoneid != '') { $res = phpAds_dbQuery("\n\t\t\tUPDATE\n\t\t\t\t" . $phpAds_config['tbl_zones'] . "\n\t\t\tSET\n\t\t\t\tzonename='" . $zonename . "',\n\t\t\t\tdescription='" . $description . "',\n\t\t\t\twidth='" . $zwidth . "',\n\t\t\t\theight='" . $zheight . "',\n\t\t\t\tdelivery='" . $delivery . "'\n\t\t\t\t" . ($delivery != phpAds_ZoneText && $delivery != phpAds_ZoneBanner ? ", append = ''" : "") . "\n\t\t\t\t" . ($delivery != phpAds_ZoneText ? ", prepend = ''" : "") . "\n\t\t\tWHERE\n\t\t\t\tzoneid='" . $zoneid . "'\n\t\t\t") or phpAds_sqlDie(); // Rebuild Cache if (!defined('LIBVIEWCACHE_INCLUDED')) { include phpAds_path . '/libraries/deliverycache/cache-' . $phpAds_config['delivery_caching'] . '.inc.php'; } phpAds_cacheDelete('what=zone:' . $zoneid); // Reset append codes which called this zone $res = phpAds_dbQuery("\n\t\t\t\tSELECT\n\t\t\t\t\tzoneid,\n\t\t\t\t\tappend\n\t\t\t\tFROM\n\t\t\t\t\t" . $phpAds_config['tbl_zones'] . "\n\t\t\t\tWHERE\n\t\t\t\t\tappendtype = " . phpAds_ZoneAppendZone . "\n\t\t\t"); while ($row = phpAds_dbFetchArray($res)) { $append = phpAds_ZoneParseAppendCode($row['append']); if ($append[0]['zoneid'] == $zoneid) { phpAds_dbQuery("\n\t\t\t\t\t\tUPDATE\n\t\t\t\t\t\t\t" . $phpAds_config['tbl_zones'] . "\n\t\t\t\t\t\tSET\n\t\t\t\t\t\t\tappendtype = " . phpAds_ZoneAppendRaw . ",\n\t\t\t\t\t\t\tappend = ''\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tzoneid = '" . $row['zoneid'] . "'\n\t\t\t\t\t"); } phpAds_cacheDelete('what=zone:' . $row['zoneid']); } header("Location: zone-advanced.php?affiliateid=" . $affiliateid . "&zoneid=" . $zoneid); exit; } else { $res = phpAds_dbQuery("\n\t\t\tINSERT INTO\n\t\t\t\t" . $phpAds_config['tbl_zones'] . "\n\t\t\t\t(\n\t\t\t\taffiliateid,\n\t\t\t\tzonename,\n\t\t\t\tzonetype,\n\t\t\t\tdescription,\n\t\t\t\twidth,\n\t\t\t\theight,\n\t\t\t\tdelivery\n\t\t\t\t)\n\t\t\t VALUES (\n\t\t\t \t'" . $affiliateid . "',\n\t\t\t\t'" . $zonename . "',\n\t\t\t\t'" . phpAds_ZoneCampaign . "',\n\t\t\t\t'" . $description . "',\n\t\t\t\t'" . $zwidth . "',\n\t\t\t\t'" . $zheight . "',\n\t\t\t\t'" . $delivery . "'\n\t\t\t\t)\n\t\t\t") or phpAds_sqlDie(); $zoneid = phpAds_dbInsertID(); header("Location: zone-advanced.php?affiliateid=" . $affiliateid . "&zoneid=" . $zoneid); exit; } } /*********************************************************/ /* HTML framework */ /*********************************************************/ if ($zoneid != "") { if (isset($Session['prefs']['affiliate-zones.php']['listorder'])) {
function phpAds_ToggleCampaignInZone($clientid, $zoneid) { global $phpAds_config; if (isset($zoneid) && $zoneid != '') { $res = phpAds_dbQuery("\n\t\t\tSELECT\n\t\t\t\t*\n\t\t\tFROM\n\t\t\t\t" . $phpAds_config['tbl_zones'] . "\n\t\t\tWHERE\n\t\t\t\tzoneid = '{$zoneid}'\n\t\t\t") or phpAds_sqlDie(); if (phpAds_dbNumRows($res)) { $zone = phpAds_dbFetchArray($res); if ($zone['what'] != '') { $what_array = explode(",", $zone['what']); } else { $what_array = array(); } $available = false; $changed = false; for ($k = 0; $k < count($what_array); $k++) { if (substr($what_array[$k], 0, 9) == "clientid:" && substr($what_array[$k], 9) == $clientid) { // Remove from array unset($what_array[$k]); $available = true; $changed = true; } } if ($available == false) { // Add to array $what_array[] = 'clientid:' . $clientid; $changed = true; } if ($changed == true) { // Convert back to a string $zone['what'] = implode(",", $what_array); // Store string back into database $res = phpAds_dbQuery("\n\t\t\t\t\tUPDATE\n\t\t\t\t\t\t" . $phpAds_config['tbl_zones'] . "\n\t\t\t\t\tSET \n\t\t\t\t\t\twhat = '" . $zone['what'] . "'\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tzoneid = '{$zoneid}'\n\t\t\t\t\t") or phpAds_sqlDie(); // Rebuild cache if (!defined('LIBVIEWCACHE_INCLUDED')) { include phpAds_path . '/libraries/deliverycache/cache-' . $phpAds_config['delivery_caching'] . '.inc.php'; } phpAds_cacheDelete('what=zone:' . $zoneid); } } } return false; }
function phpAds_logExpire($clientid, $type = 0) { global $phpAds_config; // Get campaign information $campaignresult = phpAds_dbQuery("SELECT *, UNIX_TIMESTAMP(expire) AS expire_st, UNIX_TIMESTAMP(activate) AS activate_st FROM " . $phpAds_config['tbl_clients'] . " WHERE clientid = '" . $clientid . "'"); if ($campaign = phpAds_dbFetchArray($campaignresult)) { // Decrement views if ($type == phpAds_Views && $campaign['views'] > 0) { phpAds_dbQuery("UPDATE " . $phpAds_config['tbl_clients'] . " SET views = views - 1 WHERE clientid = '" . $clientid . "'"); $campaign['views']--; // Mail warning - preset is reached if ($campaign['views'] == $phpAds_config['warn_limit'] && ($phpAds_config['warn_admin'] || $phpAds_config['warn_client'])) { // Include warning library if (!defined('LIBWARNING_INCLUDED')) { require phpAds_path . '/libraries/lib-warnings.inc.php'; } if (!defined('LIBMAIL_INCLUDED')) { require phpAds_path . '/libraries/lib-mail.inc.php'; } if (!defined('LIBUSERLOG_INCLUDED')) { require phpAds_path . '/libraries/lib-userlog.inc.php'; } phpAds_userlogSetUser(phpAds_userDeliveryEngine); phpAds_warningMail($campaign); } } // Decrement clicks if ($type == phpAds_Clicks && $campaign['clicks'] > 0) { phpAds_dbQuery("UPDATE " . $phpAds_config['tbl_clients'] . " SET clicks = clicks - 1 WHERE clientid='" . $clientid . "'"); $campaign['clicks']--; } // Check activation status $active = "t"; if ($campaign["clicks"] == 0 || $campaign["views"] == 0 || time() < $campaign["activate_st"] || time() > $campaign["expire_st"] && $campaign["expire_st"] != 0) { $active = "f"; } if ($campaign["active"] != $active) { if (!defined('LIBUSERLOG_INCLUDED')) { require phpAds_path . '/libraries/lib-userlog.inc.php'; } // Log deactivation phpAds_userlogSetUser(phpAds_userDeliveryEngine); phpAds_userlogAdd(phpAds_actionDeactiveCampaign, $campaign['clientid']); // Deactivate campaign phpAds_dbQuery("UPDATE " . $phpAds_config['tbl_clients'] . " SET active='" . $active . "' WHERE clientid='" . $clientid . "'"); // Send deactivation warning if ($active == 'f') { // Rebuild priorities if (!defined('LIBPRIORITY_INCLUDED')) { require phpAds_path . '/libraries/lib-priority.inc.php'; } phpAds_PriorityCalculate(); // Recalculate cache if (!defined('LIBVIEWCACHE_INCLUDED')) { include phpAds_path . '/libraries/deliverycache/cache-' . $phpAds_config['delivery_caching'] . '.inc.php'; } phpAds_cacheDelete(); // Include warning library if (!defined('LIBWARNING_INCLUDED')) { require phpAds_path . '/libraries/lib-warnings.inc.php'; } if (!defined('LIBMAIL_INCLUDED')) { require phpAds_path . '/libraries/lib-mail.inc.php'; } phpAds_deactivateMail($campaign); } } } }