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; }
/** * A private method to prepare the body of an advertiser's "campaign delivery" * report email. * * @access private * @param integer $advertiserId The advertiser's ID. * @param PEAR::Date $oStartDate The start date of the report, inclusive. * @param PEAR::Date $oEndDate The end date of the report, inclusive. * @param integer $campaignId Restrict the report to a single campaign. */ function _prepareCampaignDeliveryEmailBody($advertiserId, $oStartDate, $oEndDate, $campaignId) { // 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 the impression, click and conversion delivery strings, and // prepare formatting strings global $strImpressions, $strClicks, $strConversions, $strTotal, $strTotalThisPeriodLength; $strTotalImpressions = $strImpressions . ' (' . $strTotal . ')'; $strTotalClicks = $strClicks . ' (' . $strTotal . ')'; $strTotalConversions = $strConversions . ' (' . $strTotal . ')'; $strTotalImpressionsLength = strlen($strTotalImpressions); $strTotalClicksLength = strlen($strTotalClicks); $strTotalConversionsLength = strlen($strTotalConversions); $strTotalThisPeriodLength = strlen($strTotalThisPeriod); $maxLength = max($strTotalImpressionsLength, $strTotalClicksLength, $strTotalConversionsLength, $strTotalThisPeriodLength); $adTextPrint = ' %' . $maxLength . 's'; // Load remaining required strings global $strLinkedTo, $strNoStatsForCampaign; // Prepare the result $emailBody = ''; $totalAdviewsInPeriod = 0; // Fetch all the advertiser's campaigns $doCampaigns = OA_Dal::factoryDO('campaigns'); $doCampaigns->clientid = $advertiserId; if (!empty($campaignId)) { $doCampaigns->campaignid = $campaignId; } $doCampaigns->orderBy('campaignid'); $doCampaigns->find(); if ($doCampaigns->getRowCount() > 0) { while ($doCampaigns->fetch()) { $aCampaign = $doCampaigns->toArray(); // If campaign is active or we are running the report for a single campaign. if ($aCampaign['status'] == '0' || !empty($campaignId)) { // 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=' . $advertiserId . '&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) { $adsWithDelivery = false; while ($doBanners->fetch()) { $aAd = $doBanners->toArray(); // Get the total impressions, clicks and conversions delivered by this ad $adImpressions = phpAds_totalViews($aAd['bannerid']); $adClicks = phpAds_totalClicks($aAd['bannerid']); $adConversions = phpAds_totalConversions($aAd['bannerid']); if ($adImpressions > 0 || $adClicks > 0 || $adConversions > 0) { $adsWithDelivery = true; // This ad has delivered at some stage, 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"; } // Add a divider before the ad's stats $emailBody .= " ------------------------------------------------------\n"; $adHasStats = false; if ($adImpressions > 0) { // The ad has impressions $adHasStats = true; $emailBody .= sprintf($adTextPrint, $strTotalImpressions) . ': '; $emailBody .= sprintf('%15s', phpAds_formatNumber($adImpressions)) . "\n"; // Fetch the ad's impressions for the report period, grouped by day $aEmailBody = $this->_prepareCampaignDeliveryEmailBodyStats($aAd['bannerid'], $oStartDate, $oEndDate, 'impressions', $adTextPrint); $emailBody .= $aEmailBody['body']; $totalAdviewsInPeriod += $aEmailBody['adviews']; } if ($adClicks > 0) { // The ad has clicks $adHasStats = true; $emailBody .= "\n" . sprintf($adTextPrint, $strTotalClicks) . ': '; $emailBody .= sprintf('%15s', phpAds_formatNumber($adClicks)) . "\n"; // Fetch the ad's clicks for the report period, grouped by day $aEmailBody = $this->_prepareCampaignDeliveryEmailBodyStats($aAd['bannerid'], $oStartDate, $oEndDate, 'clicks', $adTextPrint); $emailBody .= $aEmailBody['body']; $totalAdviewsInPeriod += $aEmailBody['adviews']; } if ($adConversions > 0) { // The ad has conversions $adHasStats = true; $emailBody .= "\n" . sprintf($adTextPrint, $strTotalConversions) . ': '; $emailBody .= sprintf('%15s', phpAds_formatNumber($adConversions)) . "\n"; // Fetch the ad's conversions for the report period, grouped by day $aEmailBody = $this->_prepareCampaignDeliveryEmailBodyStats($aAd['bannerid'], $oStartDate, $oEndDate, 'conversions', $adTextPrint); $emailBody .= $aEmailBody['body']; $totalAdviewsInPeriod += $aEmailBody['adviews']; } $emailBody .= "\n"; } } } // Did the campaign have any stats? if ($adsWithDelivery != true) { $emailBody .= $strNoStatsForCampaign . "\n\n\n"; } } } } // Return the email body return array('body' => $emailBody, 'adviews' => $totalAdviewsInPeriod); }
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; }