예제 #1
0
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);
            }
        }
    }
}
    // 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')) {
        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'];
// $Revision: 2.0 $
/************************************************************************/
/* phpAdsNew 2                                                          */
/* ===========                                                          */
/*                                                                      */
/* Copyright (c) 2000-2002 by the phpAdsNew developers                  */
/* For more information visit: http://www.phpadsnew.com                 */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/
// Include required files
require "config.php";
require "lib-statistics.inc.php";
require "../libraries/lib-priority.inc.php";
// Security check
phpAds_checkAccess(phpAds_Admin);
/*********************************************************/
/* Main code                                             */
/*********************************************************/
$report = phpAds_PriorityCalculate();
if ($report != '' && $phpAds_config['userlog_priority']) {
    phpAds_userlogAdd(phpAds_actionPriorityCalculation, 0, $report);
}
// Rebuild cache
if (!defined('LIBVIEWCACHE_INCLUDED')) {
    include phpAds_path . '/libraries/deliverycache/cache-' . $phpAds_config['delivery_caching'] . '.inc.php';
}
phpAds_cacheDelete();
Header("Location: maintenance-priority.php");