function phpAds_getBannerStats($query, $name = '', $omit_arr = null)
{
    if (!isset($omit_arr) || !is_array($omit_arr)) {
        $omit_arr = array();
    }
    $banner_stats = array();
    $banner_stats['name'] = $name;
    $banner_stats['path'] = $name;
    $banner_stats['views'] = 0;
    $banner_stats['clicks'] = 0;
    $banner_stats['conversions'] = 0;
    $res_banner_stats = phpAds_dbQuery($query) or phpAds_sqlDie();
    while ($row_banner_stats = phpAds_dbFetchArray($res_banner_stats)) {
        $banner_stats['children'][] = $row_banner_stats;
        $index = sizeof($banner_stats['children']) - 1;
        $banner_stats['children'][$index]['name'] = phpAds_buildBannerName($row_banner_stats['bannerid'], $row_banner_stats['description'], $row_banner_stats['alt'], null, false);
        $banner_stats['children'][$index]['path'] = $name . '/' . $banner_stats['children'][$index]['name'];
        if (!in_array($banner_stats['children'][$index]['path'], $omit_arr)) {
            $banner_stats['clicks'] += $row_banner_stats['clicks'];
            $banner_stats['conversions'] += $row_banner_stats['conversions'];
            $banner_stats['views'] += $row_banner_stats['views'];
            $banner_stats['id'][] = $row_banner_stats['bannerid'];
        }
    }
    $banner_stats['ctr'] += phpAds_buildRatio($banner_stats['clicks'], $banner_stats['views']);
    $banner_stats['cnvr'] += phpAds_buildRatio($banner_stats['conversions'], $banner_stats['clicks']);
    return $banner_stats;
}
function phpAds_getBannerName($bannerid, $limit = 30, $id = true, $checkanonymous = false)
{
    $conf = $GLOBALS['_MAX']['CONF'];
    global $bannerCache;
    if (isset($bannerCache[$bannerid]) && is_array($bannerCache[$bannerid])) {
        $row = $bannerCache[$bannerid];
    } else {
        $doBanners = OA_Dal::staticGetDO('banners', $bannerid);
        $row = $doBanners->toArray();
        if ($checkanonymous) {
            $doCampaigns = OA_Dal::staticGetDO('campaigns', $row['campaignid']);
            $row['anonymous'] = $doCampaigns->anonymous;
            if ((OA_Permission::isAccount(OA_ACCOUNT_TRAFFICKER) || OA_Permission::isAccount(OA_ACCOUNT_ADVERTISER)) && MAX_isAnonymous($row['anonymous'])) {
                $row['description'] = $GLOBALS['strHiddenAd'] . ' ' . $bannerid;
            }
        }
        $bannerCache[$bannerid] = $row;
    }
    if ($id) {
        return phpAds_buildBannerName($bannerid, $row['description'], $row['alt'], $limit);
    } else {
        return phpAds_buildBannerName('', $row['description'], $row['alt'], $limit);
    }
}
Ejemplo n.º 3
0
| but WITHOUT ANY WARRANTY; without even the implied warranty of            |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             |
| GNU General Public License for more details.                              |
|                                                                           |
| You should have received a copy of the GNU General Public License         |
| along with this program; if not, write to the Free Software               |
| Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA |
+---------------------------------------------------------------------------+
$Id: banner-htmlpreview.php 37157 2009-05-28 12:31:10Z andrew.hill $
*/
// Require the initialisation file
require_once '../../init.php';
// Required files
require_once MAX_PATH . '/www/admin/config.php';
require_once MAX_PATH . '/www/admin/lib-statistics.inc.php';
require_once MAX_PATH . '/lib/max/Delivery/adRender.php';
require_once MAX_PATH . '/lib/max/Admin_DA.php';
/*-------------------------------------------------------*/
/* Main code                                             */
/*-------------------------------------------------------*/
$aBanner = Admin_DA::getAd($bannerid);
$aBanner['bannerid'] = $aBanner['ad_id'];
if (!empty($aBanner)) {
    $conf = $GLOBALS['_MAX']['CONF'];
    $bannerName = strip_tags(phpAds_buildBannerName($bannerid, $aBanner['name'], $aBanner['alt']));
    $sizeDescription = $aBanner['type'] == 'txt' ? ' ' : "   width: {$aBanner['width']}  height: {$aBanner['height']}";
    $bannerCode = MAX_adRender($aBanner, 0, '', '', '', true, '', false, false);
    $protocol = $_SERVER['SERVER_PORT'] == $conf['openads']['sslPort'] ? "https" : "http";
    $deliveryUrl = $protocol . ':' . MAX_commonConstructPartialDeliveryUrl($conf['file']['flash']);
    echo "\n<html>\n<head>\n<title>{$bannerName}</title>\n<link rel='stylesheet' href='" . OX::assetPath() . "/css/interface-{$phpAds_TextDirection}.css'>\n<script type='text/javascript' src='{$deliveryUrl}'></script>\n</head>\n<body marginheight='0' marginwidth='0' leftmargin='0' topmargin='0' bgcolor='#EFEFEF'>\n<table cellpadding='0' cellspacing='0' border='0'>\n<tr height='32'>\n    <td width='32'><img src='" . OX::assetPath() . "/images/cropmark-tl.gif' width='32' height='32'></td>\n    <td background='" . OX::assetPath() . "/images/ruler-top.gif'>&nbsp;</td>\n    <td width='32'><img src='" . OX::assetPath() . "/images/cropmark-tr.gif' width='32' height='32'></td>\n</tr>\n<tr height='{$aBanner['height']}'>\n    <td width='32' background='" . OX::assetPath() . "/images/ruler-left.gif'>&nbsp;</td>\n    <td bgcolor='#FFFFFF' width='{$aBanner['width']}'>\n        {$bannerCode}\n    </td>\n    <td width='32'>&nbsp;</td>\n</tr>\n<tr height='32'>\n    <td width='32'><img src='" . OX::assetPath() . "/images/cropmark-bl.gif' width='32' height='32'></td>\n    <td>{$sizeDescription}</td>\n    <td width='32'><img src='" . OX::assetPath() . "/images/cropmark-br.gif' width='32' height='32'></td>\n</tr>\n</table>\n</body>\n</html>";
}
/*********************************************************/
/* HTML framework                                        */
/*********************************************************/
if (isset($Session['prefs']['stats-campaign-banners.php']['listorder'])) {
    $navorder = $Session['prefs']['stats-campaign-banners.php']['listorder'];
} else {
    $navorder = '';
}
if (isset($Session['prefs']['stats-campaign-banners.php']['orderdirection'])) {
    $navdirection = $Session['prefs']['stats-campaign-banners.php']['orderdirection'];
} else {
    $navdirection = '';
}
$res = phpAds_dbQuery("\n\tSELECT\n\t\t*\n\tFROM\n\t\t" . $phpAds_config['tbl_banners'] . "\n\tWHERE\n\t\tclientid = '{$campaignid}'\n\t" . phpAds_getBannerListOrder($navorder, $navdirection) . "\n") or phpAds_sqlDie();
while ($row = phpAds_dbFetchArray($res)) {
    phpAds_PageContext(phpAds_buildBannerName($row['bannerid'], $row['description'], $row['alt']), "stats-banner-affiliates.php?clientid=" . $clientid . "&campaignid=" . $campaignid . "&bannerid=" . $row['bannerid'], $bannerid == $row['bannerid']);
}
phpAds_PageShortcut($strClientProperties, 'client-edit.php?clientid=' . $clientid, 'images/icon-client.gif');
phpAds_PageShortcut($strCampaignProperties, 'campaign-edit.php?clientid=' . $clientid . '&campaignid=' . $campaignid, 'images/icon-campaign.gif');
phpAds_PageShortcut($strBannerProperties, 'banner-edit.php?clientid=' . $clientid . '&campaignid=' . $campaignid . '&bannerid=' . $bannerid, 'images/icon-banner-stored.gif');
phpAds_PageShortcut($strModifyBannerAcl, 'banner-acl.php?clientid=' . $clientid . '&campaignid=' . $campaignid . '&bannerid=' . $bannerid, 'images/icon-acl.gif');
phpAds_PageHeader("2.1.2.2.2");
echo "<img src='images/icon-client.gif' align='absmiddle'>&nbsp;" . phpAds_getParentName($campaignid);
echo "&nbsp;<img src='images/" . $phpAds_TextDirection . "/caret-rs.gif'>&nbsp;";
echo "<img src='images/icon-campaign.gif' align='absmiddle'>&nbsp;" . phpAds_getClientName($campaignid);
echo "&nbsp;<img src='images/" . $phpAds_TextDirection . "/caret-rs.gif'>&nbsp;";
echo "<img src='images/icon-banner-stored.gif' align='absmiddle'>&nbsp;<b>" . phpAds_getBannerName($bannerid) . "</b><br><br>";
echo phpAds_buildBannerCode($bannerid) . "<br><br><br><br>";
phpAds_ShowSections(array("2.1.2.2.1", "2.1.2.2.2"));
/*********************************************************/
/* Main code                                             */
Ejemplo n.º 5
0
} elseif (phpAds_isUser(phpAds_Agency)) {
    $query = "SELECT m.campaignid AS campaignid" . ",m.campaignname AS campaignname" . " FROM " . $phpAds_config['tbl_campaigns'] . " AS m" . "," . $phpAds_config['tbl_clients'] . " AS c" . " WHERE m.clientid=c.clientid" . " AND m.campaignid!=" . $campaignid . " AND c.agencyid=" . phpAds_getAgencyID();
}
$res = phpAds_dbQuery($query) or phpAds_sqlDie();
while ($row = phpAds_dbFetchArray($res)) {
    $extra .= "<option value='" . $row['campaignid'] . "'>" . phpAds_buildName($row['campaignid'], $row['campaignname']) . "</option>";
}
$extra .= "</select>&nbsp;<input type='image' name='moveto' src='images/" . $phpAds_TextDirection . "/go_blue.gif'><br>";
$extra .= "<img src='images/break.gif' height='1' width='160' vspace='4'><br>";
$extra .= "<img src='images/icon-duplicate-acl.gif' align='absmiddle'>&nbsp;{$strApplyLimitationsTo}<br>";
$extra .= "<img src='images/spacer.gif' height='1' width='160' vspace='2'><br>";
$extra .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
$extra .= "<select name='applyto' style='width: 110;'>";
$res = phpAds_dbQuery("SELECT * FROM " . $phpAds_config['tbl_banners'] . " WHERE bannerid != '" . $bannerid . "' AND campaignid = '" . $campaignid . "'") or phpAds_sqlDie();
while ($row = phpAds_dbFetchArray($res)) {
    $extra .= "<option value='" . $row['bannerid'] . "'>" . phpAds_buildBannerName($row['bannerid'], $row['description'], $row['alt']) . "</option>";
}
$extra .= "</select>&nbsp;<input type='image' name='applyto' src='images/" . $phpAds_TextDirection . "/go_blue.gif'><br>";
$extra .= "<img src='images/break.gif' height='1' width='160' vspace='4'><br>";
$extra .= "<img src='images/icon-recycle.gif' align='absmiddle'>&nbsp;<a href='banner-delete.php?clientid=" . $clientid . "&campaignid=" . $campaignid . "&bannerid=" . $bannerid . "&returnurl=campaign-banners.php'" . phpAds_DelConfirm($strConfirmDeleteBanner) . ">{$strDelete}</a><br>";
$extra .= "</form>";
phpAds_PageHeader("4.1.3.3.3", $extra);
echo "<img src='images/icon-advertiser.gif' align='absmiddle'>&nbsp;" . phpAds_getParentClientName($campaignid);
echo "&nbsp;<img src='images/" . $phpAds_TextDirection . "/caret-rs.gif'>&nbsp;";
echo "<img src='images/icon-campaign.gif' align='absmiddle'>&nbsp;" . phpAds_getCampaignName($campaignid);
echo "&nbsp;<img src='images/" . $phpAds_TextDirection . "/caret-rs.gif'>&nbsp;";
echo "<img src='images/icon-banner-stored.gif' align='absmiddle'>&nbsp;<b>" . phpAds_getBannerName($bannerid) . "</b><br><br>";
echo phpAds_buildBannerCode($bannerid) . "<br><br><br><br>";
phpAds_ShowSections(array("4.1.3.3.2", "4.1.3.3.3", "4.1.3.3.6", "4.1.3.3.4"));
/*********************************************************/
/* Main code                                             */
/* 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";
// Initialize random generator
mt_srand((double) microtime() * 1000000);
/*********************************************************/
/* Main code                                             */
/*********************************************************/
$res = phpAds_dbQuery("\n\tSELECT\n\t\t*\n\tFROM\n\t\t" . $phpAds_config['tbl_banners'] . "\n\tWHERE\n\t\tbannerid = '{$bannerid}'\n\t") or phpAds_sqlDie();
if ($res) {
    $row = phpAds_dbFetchArray($res);
    echo "<html><head><title>" . strip_tags(phpAds_buildBannerName($bannerid, $row['description'], $row['alt'])) . "</title>";
    echo "<link rel='stylesheet' href='images/" . $phpAds_TextDirection . "/interface.css'></head>";
    echo "<body marginheight='0' marginwidth='0' leftmargin='0' topmargin='0' bgcolor='#EFEFEF'>";
    echo "<table cellpadding='0' cellspacing='0' border='0'>";
    echo "<tr height='32'><td width='32'><img src='images/cropmark-tl.gif' width='32' height='32'></td>";
    echo "<td background='images/ruler-top.gif'>&nbsp;</td><td width='32'><img src='images/cropmark-tr.gif' width='32' height='32'></td></tr>";
    echo "<tr height='" . $row['height'] . "'><td width='32' background='images/ruler-left.gif'>&nbsp;</td><td bgcolor='#FFFFFF' width='" . $row['width'] . "'>";
    if ($row['contenttype'] == 'html') {
        $htmlcode = $row['htmlcache'];
        // Basic modifications
        $htmlcode = str_replace('{url_prefix}', $phpAds_config['url_prefix'], $htmlcode);
        $htmlcode = str_replace('{bannerid}', $bannerid, $htmlcode);
        $htmlcode = str_replace('{zoneid}', '', $htmlcode);
        $htmlcode = str_replace('{source}', '', $htmlcode);
        $htmlcode = str_replace('{target}', '_blank', $htmlcode);
        $htmlcode = str_replace('[bannertext]', '', $htmlcode);
Ejemplo n.º 7
0
 $res = phpAds_dbQuery("\n\t\tSELECT\n\t\t\t*\n\t\tFROM\n\t\t\t" . $phpAds_config['tbl_banners'] . "\n\t\tWHERE\n\t\t\tbannerid = '{$bannerid}'\n\t") or phpAds_sqlDie();
 $row = phpAds_dbFetchArray($res);
 if (isset($Session['prefs']['campaign-banners.php'][$campaignid]['listorder'])) {
     $navorder = $Session['prefs']['campaign-banners.php'][$campaignid]['listorder'];
 } else {
     $navorder = '';
 }
 if (isset($Session['prefs']['campaign-banners.php'][$campaignid]['orderdirection'])) {
     $navdirection = $Session['prefs']['campaign-banners.php'][$campaignid]['orderdirection'];
 } else {
     $navdirection = '';
 }
 // Get other banners
 $res = phpAds_dbQuery("\n\t\tSELECT\n\t\t\t*\n\t\tFROM\n\t\t\t" . $phpAds_config['tbl_banners'] . "\n\t\tWHERE\n\t\t\tcampaignid = '{$campaignid}'\n\t\t" . phpAds_getBannerListOrder($navorder, $navdirection) . "\n\t");
 while ($others = phpAds_dbFetchArray($res)) {
     phpAds_PageContext(phpAds_buildBannerName($others['bannerid'], $others['description'], $others['alt']), "banner-edit.php?clientid=" . $clientid . "&campaignid=" . $campaignid . "&bannerid=" . $others['bannerid'], $bannerid == $others['bannerid']);
 }
 if (phpAds_isUser(phpAds_Admin) || phpAds_isUser(phpAds_Agency)) {
     phpAds_PageShortcut($strClientProperties, 'advertiser-edit.php?clientid=' . $clientid, 'images/icon-advertiser.gif');
     phpAds_PageShortcut($strCampaignProperties, 'campaign-edit.php?clientid=' . $clientid . '&campaignid=' . $campaignid, 'images/icon-campaign.gif');
     phpAds_PageShortcut($strBannerHistory, 'stats-banner-history.php?clientid=' . $clientid . '&campaignid=' . $campaignid . '&bannerid=' . $bannerid, 'images/icon-statistics.gif');
     $extra = "<form action='banner-modify.php'>";
     $extra .= "<input type='hidden' name='bannerid' value='{$bannerid}'>";
     $extra .= "<input type='hidden' name='clientid' value='{$clientid}'>";
     $extra .= "<input type='hidden' name='campaignid' value='{$campaignid}'>";
     $extra .= "<input type='hidden' name='returnurl' value='banner-edit.php'>";
     $extra .= "<br><br>";
     $extra .= "<b>{$strModifyBanner}</b><br>";
     $extra .= "<img src='images/break.gif' height='1' width='160' vspace='4'><br>";
     $extra .= "<img src='images/icon-duplicate-banner.gif' align='absmiddle'>&nbsp;<a href='banner-modify.php?clientid=" . $clientid . "&campaignid=" . $campaignid . "&bannerid=" . $bannerid . "&duplicate=true&returnurl=banner-edit.php'>{$strDuplicate}</a><br>";
     $extra .= "<img src='images/break.gif' height='1' width='160' vspace='4'><br>";
Ejemplo n.º 8
0
 while ($row = phpAds_dbFetchArray($res)) {
     $available[$row['delivery']][$row['zoneid']] = phpAds_buildZoneName($row['zoneid'], $row['zonename']);
 }
 // Get available zones
 $available_banners = array();
 // Get campaigns from same advertiser
 $res = phpAds_dbQuery("SELECT * FROM " . $phpAds_config['tbl_clients'] . " WHERE parent = '" . $clientid . "' AND active = 't'");
 while ($row = phpAds_dbFetchArray($res)) {
     $available_banners[] = "clientid = '" . $row['clientid'] . "'";
 }
 $available_banners = implode($available_banners, ' OR ');
 // Get banners from same advertiser
 $res = phpAds_dbQuery("SELECT bannerid, clientid, description, alt FROM " . $phpAds_config['tbl_banners'] . " WHERE " . "active = 't' AND (" . $available_banners . ") AND bannerid != " . $bannerid . " ORDER BY clientid, bannerid");
 $available_banners = array();
 while ($row = phpAds_dbFetchArray($res)) {
     $available_banners[$row['bannerid']] = phpAds_buildBannerName($row['bannerid'], $row['description'], $row['alt']);
 }
 // Determine the candidates for each type
 $candidates[phpAds_AppendPopup] = count($available[phpAds_ZonePopup]) + count($available_banners);
 $candidates[phpAds_AppendInterstitial] = count($available[phpAds_ZoneInterstitial]) + count($available_banners);
 // Determine appendtype
 if (!isset($appendtype)) {
     $appendtype = $banner['appendtype'];
 }
 if (!isset($appendtype_previous)) {
     $appendtype_previous = '';
 }
 echo "<input type='hidden' name='appendtype_previous' value='" . $appendtype . "'>";
 echo "<input type='hidden' name='appendsave' value='1'>";
 // Appendtype choices
 echo "<tr><td width='30'>&nbsp;</td><td width='200' valign='top'>" . $GLOBALS['strAppendType'] . "</td><td>";
Ejemplo n.º 9
0
 /**
  * A private method to prepare the body of an advertiser's "campaign activated"
  * or "campaign deactivated" report email.
  *
  * @access private
  * @param integer $advertiserId The advertiser's ID.
  * @param array   $acampaign    The campaign details.
  */
 function _prepareCampaignActivatedDeactivatedEmailBody($aCampaign)
 {
     // Load the "Campaign" and "Banner" strings, and prepare formatting strings
     global $strCampaign, $strBanner;
     $strCampaignLength = strlen($strCampaign);
     $strBannerLength = strlen($strBanner);
     $maxLength = max($strCampaignLength, $strBannerLength);
     $strCampaignPrint = '%-' . $maxLength . 's';
     $strBannerPrint = ' %-' . ($maxLength - 1) . 's';
     // Load remaining strings
     global $strLinkedTo;
     // Prepare the result
     $emailBody = '';
     // Add the name of the campaign to the report
     $emailBody .= "\n" . sprintf($strCampaignPrint, $strCampaign) . ' ';
     $emailBody .= strip_tags(phpAds_buildName($aCampaign['campaignid'], $aCampaign['campaignname'])) . "\n";
     // Add a URL link to the stats page of the campaign
     $page = 'stats.php?clientid=' . $aCampaign['clientid'] . '&campaignid=' . $aCampaign['campaignid'] . '&statsBreakdown=day&entity=campaign&breakdown=history&period_preset=all_stats&period_start=&period_end=';
     $emailBody .= MAX::constructURL(MAX_URL_ADMIN, $page) . "\n";
     // Add a nice divider
     $emailBody .= "=======================================================\n\n";
     // Fetch all ads in the campaign
     $doBanners = OA_Dal::factoryDO('banners');
     $doBanners->campaignid = $aCampaign['campaignid'];
     $doBanners->orderBy('bannerid');
     $doBanners->find();
     if ($doBanners->getRowCount() > 0) {
         while ($doBanners->fetch()) {
             $aAd = $doBanners->toArray();
             // Add the name of the ad to the report
             $emailBody .= sprintf($strBannerPrint, $strBanner) . ' ';
             $emailBody .= strip_tags(phpAds_buildBannerName($aAd['bannerid'], $aAd['description'], $aAd['alt'])) . "\n";
             // If the ad has a URL, add the URL the add is linked to to the report
             if (!empty($aAd['url'])) {
                 $emailBody .= '  ' . $strLinkedTo . ': ' . $aAd['url'] . "\n";
             }
             $emailBody .= "\n";
         }
     }
     return $emailBody;
 }
Ejemplo n.º 10
0
function phpAds_getBannerName($bannerid, $limit = 30, $id = true, $checkanonymous = false)
{
    $conf = $GLOBALS['_MAX']['CONF'];
    global $bannerCache;
    if (isset($bannerCache[$bannerid]) && is_array($bannerCache[$bannerid])) {
        $row = $bannerCache[$bannerid];
    } else {
        $doBanners = OA_Dal::staticGetDO('banners', $bannerid);
        $row = $doBanners->toArray();
        $bannerCache[$bannerid] = $row;
    }
    if ($checkanonymous) {
        if (!isset($row['anonymous']) || ($row['anonymous'] = '')) {
            $doCampaigns = OA_Dal::factoryDO('campaigns');
            $doCampaigns->addReferenceFilter('banners', $bannerid);
            $doCampaigns->selectAdd();
            $doCampaigns->selectAdd('anonymous');
            $doCampaigns->find(true);
            $anonymous = $doCampaigns->anonymous;
            $bannerCache[$bannerid]['anonymous'] = $anonymous;
        } else {
            $anonymous = $row['anonymous'];
        }
    }
    if ($id) {
        return phpAds_buildBannerName($bannerid, $row['description'], $row['alt'], $limit);
    } else {
        return phpAds_buildBannerName('', $row['description'], $row['alt'], $limit);
    }
}
Ejemplo n.º 11
0
function phpAds_SendMaintenanceReport($clientid, $first_unixtimestamp, $last_unixtimestamp, $update = true)
{
    global $phpAds_config, $phpAds_CharSet, $date_format, $strBanner, $strCampaign, $strViews, $strClicks, $strConversions, $strLinkedTo, $strMailSubject, $strMailHeader, $strMailBannerStats, $strMailFooter, $strMailReportPeriod, $strMailReportPeriodAll, $strLogErrorBanners, $strLogErrorClients, $strLogErrorViews, $strLogErrorClicks, $strLogErrorConversions, $strNoStatsForCampaign, $strNoViewLoggedInInterval, $strNoClickLoggedInInterval, $strNoCampaignLoggedInInterval, $strTotal, $strTotalThisPeriod;
    // Convert timestamps to SQL format
    $last_sqltimestamp = date("YmdHis", $last_unixtimestamp);
    $first_sqltimestamp = date("YmdHis", $first_unixtimestamp);
    // Get Client information
    $res_client = phpAds_dbQuery("SELECT" . " clientid" . ",clientname" . ",contact" . ",email" . ",language" . ",report" . ",reportinterval" . ",reportlastdate" . ",UNIX_TIMESTAMP(reportlastdate) AS reportlastdate_t" . " FROM " . $phpAds_config['tbl_clients'] . " WHERE clientid=" . $clientid);
    if (phpAds_dbNumRows($res_client) > 0) {
        $client = phpAds_dbFetchArray($res_client);
        // Load client language strings
        @(include phpAds_path . '/language/english/default.lang.php');
        if ($client['language'] != '') {
            $phpAds_config['language'] = $client['language'];
        }
        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');
        }
        $active_campaigns = false;
        $log = "";
        // Fetch all campaigns belonging to client
        $res_campaigns = phpAds_dbQuery("SELECT" . " campaignid" . ",campaignname" . ",views" . ",clicks" . ",conversions" . ",expire" . ",UNIX_TIMESTAMP(expire) as expire_st" . ",activate" . ",UNIX_TIMESTAMP(activate) as activate_st" . ",active" . " FROM " . $phpAds_config['tbl_campaigns'] . " WHERE clientid=" . $client['clientid']) or die($strLogErrorClients);
        while ($campaign = phpAds_dbFetchArray($res_campaigns)) {
            // Fetch all banners belonging to campaign
            $res_banners = phpAds_dbQuery("SELECT" . " bannerid" . ",campaignid" . ",URL" . ",active" . ",description" . ",alt" . " FROM " . $phpAds_config['tbl_banners'] . " WHERE campaignid=" . $campaign['campaignid']) or die($strLogErrorBanners);
            $active_banners = false;
            $log .= "\n" . $strCampaign . "  " . strip_tags(phpAds_buildName($campaign['campaignid'], $campaign['campaignname'])) . "\n";
            $log .= "=======================================================\n\n";
            while ($row_banners = phpAds_dbFetchArray($res_banners)) {
                $adviews = phpAds_totalViews($row_banners["bannerid"]);
                $client["views_used"] = $adviews;
                $adclicks = phpAds_totalClicks($row_banners["bannerid"]);
                $campaign["clicks_used"] = $adclicks;
                $adconversions = phpAds_totalConversions($row_banners["bannerid"]);
                $campaign["conversions_used"] = $adconversions;
                if ($adviews > 0 || $adclicks > 0 || $adconversions > 0) {
                    $log .= $strBanner . "  " . strip_tags(phpAds_buildBannerName($row_banners['bannerid'], $row_banners['description'], $row_banners['alt'])) . "\n";
                    $log .= $strLinkedTo . ": " . $row_banners['URL'] . "\n";
                    $log .= "-------------------------------------------------------\n";
                    $active_banner_stats = false;
                    if ($adviews > 0) {
                        $log .= $strViews . " (" . $strTotal . "):    " . $adviews . "\n";
                        // Fetch all adviews belonging to banner belonging to client, grouped by day
                        $res_adviews = phpAds_dbQuery("SELECT" . " SUM(views) as qnt" . ",DATE_FORMAT(day, '{$date_format}') as t_stamp_f" . ",TO_DAYS(day) AS the_day" . " FROM " . $phpAds_config['tbl_adstats'] . " WHERE bannerid=" . $row_banners['bannerid'] . " AND views>0" . " AND UNIX_TIMESTAMP(day)>=" . $first_unixtimestamp . " AND UNIX_TIMESTAMP(day)<" . $last_unixtimestamp . " GROUP BY day" . " ORDER BY day DESC") or die($strLogErrorViews . " " . phpAds_dbError());
                        if (phpAds_dbNumRows($res_adviews)) {
                            $total = 0;
                            while ($row_adviews = phpAds_dbFetchArray($res_adviews)) {
                                $log .= "      " . $row_adviews['t_stamp_f'] . ":   " . $row_adviews['qnt'] . "\n";
                                $total += $row_adviews['qnt'];
                            }
                            $log .= $strTotalThisPeriod . ": " . $total . "\n";
                            $active_banner_stats = true;
                        } else {
                            $log .= "      " . $strNoViewLoggedInInterval . "\n";
                        }
                    }
                    if ($adclicks > 0) {
                        // Total adclicks
                        $log .= "\n" . $strClicks . " (" . $strTotal . "):   " . $adclicks . "\n";
                        // Fetch all adclicks belonging to banner belonging to client, grouped by day
                        $res_adclicks = phpAds_dbQuery("SELECT" . " SUM(clicks) as qnt" . ",DATE_FORMAT(day, '{$date_format}') as t_stamp_f" . ",TO_DAYS(day) AS the_day" . " FROM " . $phpAds_config['tbl_adstats'] . " WHERE bannerid = " . $row_banners['bannerid'] . " AND clicks>0" . " AND UNIX_TIMESTAMP(day)>=" . $first_unixtimestamp . " AND UNIX_TIMESTAMP(day)<" . $last_unixtimestamp . " GROUP BY day" . " ORDER BY day DESC") or die($strLogErrorClicks . " " . phpAds_dbError());
                        if (phpAds_dbNumRows($res_adclicks)) {
                            $total = 0;
                            while ($row_adclicks = phpAds_dbFetchArray($res_adclicks)) {
                                $log .= "      " . $row_adclicks['t_stamp_f'] . ":   " . $row_adclicks['qnt'] . "\n";
                                $total += $row_adclicks['qnt'];
                            }
                            $log .= $strTotalThisPeriod . ": " . $total . "\n";
                            $active_banner_stats = true;
                        } else {
                            $log .= "      " . $strNoClickLoggedInInterval . "\n";
                        }
                    }
                    if ($adconversions > 0) {
                        // Total adconversions
                        $log .= "\n" . $strConversions . " (" . $strTotal . "):   " . $adconversions . "\n";
                        // Fetch all adclicks belonging to banner belonging to client, grouped by day
                        $res_adconversions = phpAds_dbQuery("SELECT" . " SUM(conversions) as qnt" . ",DATE_FORMAT(day, '{$date_format}') as t_stamp_f" . ",TO_DAYS(day) AS the_day" . " FROM " . $phpAds_config['tbl_adstats'] . " WHERE bannerid = " . $row_banners['bannerid'] . " AND conversions>0" . " AND UNIX_TIMESTAMP(day)>=" . $first_unixtimestamp . " AND UNIX_TIMESTAMP(day)<" . $last_unixtimestamp . " GROUP BY day" . " ORDER BY day DESC") or die($strLogErrorConversions . " " . phpAds_dbError());
                        if (phpAds_dbNumRows($res_adconversions)) {
                            $total = 0;
                            while ($row_adconversions = phpAds_dbFetchArray($res_adconversions)) {
                                $log .= "      " . $row_adcconversions['t_stamp_f'] . ":   " . $row_adconversions['qnt'] . "\n";
                                $total += $row_adconversions['qnt'];
                            }
                            $log .= $strTotalThisPeriod . ": " . $total . "\n";
                            $active_banner_stats = true;
                        } else {
                            $log .= "      " . $strNoConversionLoggedInInterval . "\n";
                        }
                    }
                    $log .= "\n\n";
                    if ($active_banner_stats == true || $active_banner_stats == false && $campaign['active'] == 't') {
                        $active_banners = true;
                    }
                }
            }
            if ($active_banners == true) {
                $active_campaigns = true;
            } else {
                $log .= $strNoStatsForCampaign . "\n\n\n";
            }
        }
        // E-mail Stats to active clients
        if ($client["email"] != '' && $active_campaigns == true) {
            $Subject = $strMailSubject . ": " . $client["clientname"];
            $Body = "{$strMailHeader}\n";
            $Body .= "{$strMailBannerStats}\n";
            if ($first_unixtimestamp == 0) {
                $Body .= "{$strMailReportPeriodAll}\n\n";
            } else {
                $Body .= "{$strMailReportPeriod}\n\n";
            }
            $Body .= "{$log}\n";
            $Body .= "{$strMailFooter}";
            $Body = str_replace("{clientname}", $client['clientname'], $Body);
            $Body = str_replace("{contact}", $client['contact'], $Body);
            $Body = str_replace("{adminfullname}", $phpAds_config['admin_fullname'], $Body);
            $Body = str_replace("{startdate}", date(str_replace('%', '', $date_format), $first_unixtimestamp), $Body);
            $Body = str_replace("{enddate}", date(str_replace('%', '', $date_format), $last_unixtimestamp), $Body);
            if ($phpAds_config['userlog_email']) {
                phpAds_userlogAdd(phpAds_actionAdvertiserReportMailed, $client['clientid'], $Subject . "\n\n" . $Body);
            }
            if (phpAds_sendMail($client['email'], $client['contact'], $Subject, $Body)) {
                // Update last run
                if ($update == true) {
                    $res_update = phpAds_dbQuery("UPDATE " . $phpAds_config['tbl_clients'] . " SET reportlastdate=NOW() WHERE clientid=" . $client['clientid']);
                }
                return true;
            }
        }
    }
    return false;
}
function phpAds_getBannerName($bannerid, $limit = 0, $id = true, $html = true)
{
    global $phpAds_config;
    global $bannerCache;
    if (!$limit) {
        $limit = 30;
    }
    if (isset($bannerCache[$bannerid]) && is_array($bannerCache[$bannerid])) {
        $row = $bannerCache[$bannerid];
    } else {
        $res = phpAds_dbQuery("\n\t\t\tSELECT\n\t\t\t\t*\n\t\t\tFROM\n\t\t\t\t" . $phpAds_config['tbl_banners'] . "\n\t\t\tWHERE\n\t\t\t\tbannerid = '{$bannerid}'\n\t\t") or phpAds_sqlDie();
        $row = phpAds_dbFetchArray($res);
        $bannerCache[$bannerid] = $row;
    }
    if ($id) {
        return phpAds_buildBannerName($bannerid, $row['description'], $row['alt'], $limit, $html);
    } else {
        return phpAds_buildBannerName('', $row['description'], $row['alt'], $limit, $html);
    }
}
function phpAds_getBannerName($bannerid, $limit = 30, $id = true, $checkanonymous = false)
{
    global $phpAds_config;
    global $bannerCache;
    if (isset($bannerCache[$bannerid]) && is_array($bannerCache[$bannerid])) {
        $row = $bannerCache[$bannerid];
    } else {
        $res = phpAds_dbQuery("\n\t\t\tSELECT\n\t\t\t\t*\n\t\t\tFROM\n\t\t\t\t" . $phpAds_config['tbl_banners'] . "\n\t\t\tWHERE\n\t\t\t\tbannerid = '{$bannerid}'\n\t\t") or phpAds_sqlDie();
        $row = phpAds_dbFetchArray($res);
        $bannerCache[$bannerid] = $row;
    }
    if ($checkanonymous) {
        if (!isset($row['anonymous']) || ($row['anonymous'] = '')) {
            $anonres = phpAds_dbQuery("SELECT anonymous" . " FROM " . $phpAds_config['tbl_campaigns'] . "," . $phpAds_config['tbl_banners'] . " WHERE " . $phpAds_config['tbl_campaigns'] . ".campaignid=" . $phpAds_config['tbl_banners'] . ".campaignid" . " AND " . $phpAds_config['tbl_banners'] . ".bannerid=" . $bannerid);
            $anonrow = phpAds_dbFetchArray($anonres);
            $anonymous = $anonrow['anonymous'];
            $bannerCache[$bannerid]['anonymous'] = $anonymous;
        } else {
            $anonymous = $row['anonymous'];
        }
    }
    if ($id) {
        return phpAds_buildBannerName($bannerid, $row['description'], $row['alt'], $limit);
    } else {
        return phpAds_buildBannerName('', $row['description'], $row['alt'], $limit);
    }
}
         echo "<img src='images/icon-banner-url.gif' align='absmiddle'>";
     } else {
         echo "<img src='images/icon-banner-stored.gif' align='absmiddle'>";
     }
 } else {
     if ($row_banners['storagetype'] == 'html') {
         echo "<img src='images/icon-banner-html-d.gif' align='absmiddle'>";
     } elseif ($row_banners['storagetype'] == 'txt') {
         echo "<img src='images/icon-banner-text-d.gif' align='absmiddle'>";
     } elseif ($row_banners['storagetype'] == 'url') {
         echo "<img src='images/icon-banner-url-d.gif' align='absmiddle'>";
     } else {
         echo "<img src='images/icon-banner-stored-d.gif' align='absmiddle'>";
     }
 }
 echo "&nbsp;<b>" . phpAds_buildBannerName($row_banners['bannerid'], $row_banners['description'], $row_banners['alt']) . "</b>";
 echo "</td></tr>";
 echo "<tr><td height='1' colspan='4' bgcolor='#888888'><img src='images/break.gif' height='1' width='100%'></td></tr>";
 // Banner
 echo "<tr><td height='10' colspan='4' bgcolor='{$bgcolor}'>&nbsp;</td></tr>";
 echo "<tr bgcolor='{$bgcolor}'>";
 echo "<td height='25' align='" . $phpAds_TextAlignLeft . "' nowrap>&nbsp;&nbsp;&nbsp;&nbsp;</td>";
 echo "<td colspan='3' align='" . $phpAds_TextAlignLeft . "'>";
 echo phpAds_buildBannerCode($row_banners['bannerid'], true);
 echo "</td></tr>";
 echo "<tr><td height='10' colspan='4' bgcolor='{$bgcolor}'>&nbsp;</td></tr>";
 if ($adclicks > 0 || $adviews > 0) {
     // Stats
     echo "<tr bgcolor='{$bgcolor}'>";
     echo "<td height='25' align='" . $phpAds_TextAlignRight . "' nowrap>&nbsp;</td>";
     echo "<td height='25' align='" . $phpAds_TextAlignRight . "' nowrap>{$strViews}: <b>" . phpAds_formatNumber($adviews) . "</b></td>";
function phpAds_SendMaintenanceReport($clientid, $first_unixtimestamp, $last_unixtimestamp, $update = true)
{
    global $phpAds_config;
    global $date_format;
    global $strMailSubject, $strMailHeader, $strMailBannerStats, $strMailFooter, $strMailReportPeriod;
    global $strLogErrorClients, $strLogErrorBanners, $strLogErrorViews, $strNoStatsForCampaign;
    global $strLogErrorClicks, $strNoClickLoggedInInterval, $strNoViewLoggedInInterval;
    global $strTotal, $strTotalThisPeriod;
    global $strCampaign, $strBanner, $strLinkedTo, $strViews, $strClicks, $strMailReportPeriodAll;
    global $phpAds_CharSet;
    // Convert timestamps to SQL format
    $last_sqltimestamp = date("YmdHis", $last_unixtimestamp);
    $first_sqltimestamp = date("YmdHis", $first_unixtimestamp);
    // Get Client information
    $res_client = phpAds_dbQuery("\n\t\tSELECT\n\t\t\tclientid,\n\t\t\tclientname,\n\t\t\tcontact,\n\t\t\temail,\n\t\t\tlanguage,\n\t\t\treport,\n\t\t\treportinterval,\n\t\t\treportlastdate,\n\t\t\tUNIX_TIMESTAMP(reportlastdate) AS reportlastdate_t\n\t\tFROM\n\t\t\t" . $phpAds_config['tbl_clients'] . "\n\t\tWHERE\n\t\t\tclientid='" . $clientid . "'\n\t\t");
    if (phpAds_dbNumRows($res_client) > 0) {
        $client = phpAds_dbFetchArray($res_client);
        // Load client language strings
        @(include phpAds_path . '/language/english/default.lang.php');
        if ($client['language'] != '') {
            $phpAds_config['language'] = $client['language'];
        }
        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');
        }
        $active_campaigns = false;
        $log = "";
        // Fetch all campaings belonging to client
        $res_campaigns = phpAds_dbQuery("\n\t\t\tSELECT\n\t\t\t\tclientid,\n\t\t\t\tclientname,\n\t\t\t\tviews,\n\t\t\t\tclicks,\n\t\t\t\texpire,\n\t\t\t\tUNIX_TIMESTAMP(expire) as expire_st,\n\t\t\t\tactivate,\n\t\t\t\tUNIX_TIMESTAMP(activate) as activate_st,\n\t\t\t\tactive\n\t\t\tFROM\n\t\t\t\t" . $phpAds_config['tbl_clients'] . "\n\t\t\tWHERE\n\t\t\t\tparent = " . $client['clientid'] . "\n\t\t\n\t\t") or die($strLogErrorClients);
        while ($campaign = phpAds_dbFetchArray($res_campaigns)) {
            $current_log = '';
            // Fetch all banners belonging to campaign
            $res_banners = phpAds_dbQuery("\n\t\t\t\tSELECT\n\t\t\t\t\tbannerid,\n\t\t\t\t\tclientid,\n\t\t\t\t\turl,\n\t\t\t\t\tactive,\n\t\t\t\t\tdescription,\n\t\t\t\t\talt\n\t\t\t\tFROM\n\t\t\t\t\t" . $phpAds_config['tbl_banners'] . "\n\t\t\t\tWHERE\n\t\t\t\t\tclientid = " . $campaign['clientid'] . "\n\t\t\t\t") or die($strLogErrorBanners);
            $active_banners = false;
            $current_log .= "\n" . $strCampaign . "  " . phpAds_buildClientName($campaign['clientid'], $campaign['clientname'], false) . "\n";
            $current_log .= "=======================================================\n\n";
            while ($row_banners = phpAds_dbFetchArray($res_banners)) {
                $adviews = phpAds_totalViews($row_banners["bannerid"]);
                $client["views_used"] = $adviews;
                $adclicks = phpAds_totalClicks($row_banners["bannerid"]);
                $campaign["clicks_used"] = $adclicks;
                $current_log .= $strBanner . "  " . phpAds_buildBannerName($row_banners['bannerid'], $row_banners['description'], $row_banners['alt'], 0, false) . "\n";
                $current_log .= $strLinkedTo . ": " . $row_banners['url'] . "\n";
                $current_log .= "-------------------------------------------------------\n";
                $active_banner_stats = false;
                if ($adviews > 0) {
                    $current_log .= $strViews . " (" . $strTotal . "):    " . $adviews . "\n";
                    // Fetch all adviews belonging to banner belonging to client, grouped by day
                    if ($phpAds_config['compact_stats']) {
                        $res_adviews = phpAds_dbQuery("\n\t\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t\tSUM(views) as qnt,\n\t\t\t\t\t\t\t\tDATE_FORMAT(day, '{$date_format}') as t_stamp_f,\n\t\t\t\t\t\t\t\tTO_DAYS(day) AS the_day\n\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\t" . $phpAds_config['tbl_adstats'] . "\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\tbannerid = " . $row_banners['bannerid'] . " AND\n\t\t\t\t\t\t\t\tviews > 0 AND\n\t\t\t\t\t\t\t\tUNIX_TIMESTAMP(day) >= {$first_unixtimestamp} AND\n\t\t\t\t\t\t\t\tUNIX_TIMESTAMP(day) < {$last_unixtimestamp}\n\t\t\t\t\t\t\tGROUP BY\n\t\t\t\t\t\t\t\tday\n\t\t\t\t\t\t\tORDER BY\n\t\t\t\t\t\t\t\tday DESC\n\t\t\t\t\t\t\t") or die("{$strLogErrorViews} " . phpAds_dbError());
                    } else {
                        $res_adviews = phpAds_dbQuery("\n\t\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t\t*,\n\t\t\t\t\t\t\t\tcount(*) as qnt,\n\t\t\t\t\t\t\t\tDATE_FORMAT(t_stamp, '{$date_format}') as t_stamp_f,\n\t\t\t\t\t\t\t\tTO_DAYS(t_stamp) AS the_day\n\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\t" . $phpAds_config['tbl_adviews'] . "\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\tbannerid = " . $row_banners['bannerid'] . " AND\n\t\t\t\t\t\t\t\tt_stamp >= {$first_sqltimestamp} AND\n\t\t\t\t\t\t\t\tt_stamp < {$last_sqltimestamp}\n\t\t\t\t\t\t\tGROUP BY\n\t\t\t\t\t\t\t\tthe_day\n\t\t\t\t\t\t\tORDER BY\n\t\t\t\t\t\t\t\tthe_day DESC\n\t\t\t\t\t\t\t") or die("{$strLogErrorViews} " . phpAds_dbError());
                    }
                    if (phpAds_dbNumRows($res_adviews)) {
                        $total = 0;
                        while ($row_adviews = phpAds_dbFetchArray($res_adviews)) {
                            $current_log .= "      " . $row_adviews['t_stamp_f'] . ":   " . $row_adviews['qnt'] . "\n";
                            $total += $row_adviews['qnt'];
                        }
                        $current_log .= $strTotalThisPeriod . ": " . $total . "\n";
                        $active_banner_stats = true;
                    } else {
                        $current_log .= "      " . $strNoViewLoggedInInterval . "\n";
                    }
                }
                if ($adclicks > 0) {
                    // Total adclicks
                    $current_log .= "\n" . $strClicks . " (" . $strTotal . "):   " . $adclicks . "\n";
                    // Fetch all adclicks belonging to banner belonging to client, grouped by day
                    if ($phpAds_config['compact_stats']) {
                        $res_adclicks = phpAds_dbQuery("\n\t\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t\tSUM(clicks) as qnt,\n\t\t\t\t\t\t\t\tDATE_FORMAT(day, '{$date_format}') as t_stamp_f,\n\t\t\t\t\t\t\t\tTO_DAYS(day) AS the_day\n\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\t" . $phpAds_config['tbl_adstats'] . "\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\tbannerid = " . $row_banners['bannerid'] . " AND\n\t\t\t\t\t\t\t\tclicks > 0 AND\n\t\t\t\t\t\t\t\tUNIX_TIMESTAMP(day) >= {$first_unixtimestamp} AND\n\t\t\t\t\t\t\t\tUNIX_TIMESTAMP(day) < {$last_unixtimestamp}\n\t\t\t\t\t\t\tGROUP BY\n\t\t\t\t\t\t\t\tday\n\t\t\t\t\t\t\tORDER BY\n\t\t\t\t\t\t\t\tday DESC\n\t\t\t\t\t\t\t") or die("{$strLogErrorClicks} " . phpAds_dbError());
                    } else {
                        $res_adclicks = phpAds_dbQuery("\n\t\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t\tcount(*) as qnt,\n\t\t\t\t\t\t\t\tDATE_FORMAT(t_stamp, '{$date_format}') as t_stamp_f,\n\t\t\t\t\t\t\t\tTO_DAYS(t_stamp) AS the_day\n\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\t" . $phpAds_config['tbl_adclicks'] . "\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\tbannerid = " . $row_banners['bannerid'] . " AND\n\t\t\t\t\t\t\t\tt_stamp >= {$first_sqltimestamp} AND\n\t\t\t\t\t\t\t\tt_stamp < {$last_sqltimestamp}\n\t\t\t\t\t\t\tGROUP BY\n\t\t\t\t\t\t\t\tthe_day\n\t\t\t\t\t\t\tORDER BY\n\t\t\t\t\t\t\t\tthe_day DESC\n\t\t\t\t\t\t\t") or die("{$strLogErrorClicks} " . phpAds_dbError());
                    }
                    if (phpAds_dbNumRows($res_adclicks)) {
                        $total = 0;
                        while ($row_adclicks = phpAds_dbFetchArray($res_adclicks)) {
                            $current_log .= "      " . $row_adclicks['t_stamp_f'] . ":   " . $row_adclicks['qnt'] . "\n";
                            $total += $row_adclicks['qnt'];
                        }
                        $current_log .= $strTotalThisPeriod . ": " . $total . "\n";
                        $active_banner_stats = true;
                    } else {
                        $current_log .= "      " . $strNoClickLoggedInInterval . "\n";
                    }
                }
                if ($adclicks == 0 && $adviews == 0) {
                    $current_log .= "      " . $strNoStatsForCampaign . "\n";
                }
                $current_log .= "\n\n";
                if ($campaign['active'] == 't' || $active_banner_stats == true) {
                    $active_banners = true;
                }
            }
            if ($active_banners == true) {
                $active_campaigns = true;
                $log .= $current_log;
            }
        }
        // E-mail Stats to active clients
        if ($client["email"] != '' && $active_campaigns == true) {
            $Subject = $strMailSubject . ": " . $client["clientname"];
            $Body = "{$strMailHeader}\n";
            $Body .= "{$strMailBannerStats}\n";
            if ($first_unixtimestamp == 0) {
                $Body .= "{$strMailReportPeriodAll}\n\n";
            } else {
                $Body .= "{$strMailReportPeriod}\n\n";
            }
            $Body .= "{$log}\n";
            $Body .= "{$strMailFooter}";
            $Body = str_replace("{clientname}", $client['clientname'], $Body);
            $Body = str_replace("{contact}", $client['contact'], $Body);
            $Body = str_replace("{adminfullname}", $phpAds_config['admin_fullname'], $Body);
            $Body = str_replace("{startdate}", date(str_replace('%', '', $date_format), $first_unixtimestamp), $Body);
            $Body = str_replace("{enddate}", date(str_replace('%', '', $date_format), $last_unixtimestamp), $Body);
            if ($phpAds_config['userlog_email']) {
                phpAds_userlogAdd(phpAds_actionAdvertiserReportMailed, $client['clientid'], $Subject . "\n\n" . $Body);
            }
            phpAds_sendMail($client['email'], $client['contact'], $Subject, $Body);
            // Update last run
            if ($update == true) {
                $res_update = phpAds_dbQuery("UPDATE " . $phpAds_config['tbl_clients'] . " SET reportlastdate=NOW() WHERE clientid=" . $client['clientid']);
            }
            return true;
        }
    }
    return false;
}