Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- *
- * @ This file is created by http://DeZender.Net
- * @ deZender (PHP7 Decoder for ionCube Encoder)
- *
- * @ Version : 4.1.0.1
- * @ Author : DeZender
- * @ Release on : 29.08.2020
- * @ Official site : http://DeZender.Net
- *
- */
- class ApplicationController extends Controller
- {
- final public function license_check($addoncode = '', $from_framework = 0)
- {
- $lic_data = '';
- for ($i = 0; $i < VALIDATOR_SERVER_COUNT; $i++) {
- $validator = ($i == 0 ? 'validator' : 'validator' . $i);
- $url = 'http://' . $validator . '.mariascripts.com/index.php?page=license/validate/' . PRODUCT_CODE . '/' . $_SERVER['HTTP_HOST'] . '/' . LICENSE_KEY;
- $lic_data = '';
- if ((ini_get('allow_url_fopen') == 1) && ($fp_license = fopen($url, 'r'))) {
- while (!feof($fp_license)) {
- $lic_data .= fgetc($fp_license);
- }
- fclose($fp_license);
- }
- else if (function_exists('curl_init')) {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- $content = curl_exec($ch);
- curl_close($ch);
- $lic_data = $content;
- }
- else {
- Main::print_error('Either URL fopen or CURL must be enabled on your server.');
- exit();
- }
- if ($lic_data == -1) {
- $this->set_root_cookie(COOKIE_ADMIN_USERNAME, '', 0, ADMIN_DIR);
- $this->set_root_cookie(COOKIE_ADMIN_PASSWORD, '', 0, ADMIN_DIR);
- $this->set_root_cookie(COOKIE_ADMIN_LOGINID, '', 0, ADMIN_DIR);
- $this->set_root_cookie(COOKIE_ADMIN_TYPE, '', 0, ADMIN_DIR);
- if ($from_framework == 0) {
- Main::print_error('License validation failed. Please verify the key in your configuration file.');
- exit();
- }
- else {
- return $lic_data;
- }
- continue;
- }
- if ($lic_data == 1) {
- if ($from_framework == 0) {
- break;
- }
- else {
- return $lic_data;
- }
- continue;
- }
- continue;
- }
- if ($lic_data == '') {
- return $this->check_license_validation_network_failure();
- }
- }
- final public function check_license_validation_network_failure()
- {
- $db = DAL::get_instance();
- $rowdata = $db->execute_query('SELECT id,value FROM ' . TABLE_PREFIX . 'config WHERE name=?', ['report_lnfth']);
- $rowdatacount = $rowdata->get_num_records();
- $config_id = 0;
- $report_lnfth = '';
- if (0 < $rowdatacount) {
- $rowdatacontent = $rowdata->fetch_assoc();
- $config_id = $rowdatacontent['id'];
- $report_lnfth = $rowdatacontent['value'];
- }
- $secret_key = 'xyzadmarkethash';
- $failure_time = 0;
- $hash = '';
- $dbinsert_flag = 0;
- $print_error_flag = 0;
- $current_time = time();
- if ($report_lnfth != '') {
- $report_array = json_decode($report_lnfth, 1);
- if (isset($report_array['ft'])) {
- $failure_time = intval($report_array['ft']);
- }
- if (isset($report_array['h'])) {
- $hash = $report_array['h'];
- }
- if (0 < $failure_time) {
- if (43200 <= $current_time - $failure_time) {
- $print_error_flag = 1;
- }
- }
- else {
- $dbinsert_flag = 1;
- $print_error_flag = 1;
- }
- if ($print_error_flag == 0) {
- $created_hash = md5($failure_time . $secret_key);
- if ($hash != $created_hash) {
- $print_error_flag = 1;
- }
- }
- }
- else {
- $dbinsert_flag = 1;
- $print_error_flag = 1;
- }
- if ($dbinsert_flag == 1) {
- $failure_time = $current_time;
- $new_hash = md5($failure_time . $secret_key);
- $json_data = '{"ft":' . $failure_time . ',"h":"' . $new_hash . '"}';
- if ($config_id == 0) {
- $db->execute_query('INSERT INTO `' . TABLE_PREFIX . 'config` (`id`, `name`, `value`) VALUES (?,?,?)', ['', 'report_lnfth', $json_data]);
- }
- else {
- $db->execute_query('UPDATE `' . TABLE_PREFIX . 'config` SET value=? WHERE name=?', [$json_data, 'report_lnfth']);
- }
- }
- if ($print_error_flag == 1) {
- Main::print_error('Unable to validate license. If you are repeatedly getting this error please contact support desk.');
- exit();
- }
- else {
- return 1;
- }
- }
- public function before_execute()
- {
- parent::before_execute();
- $curr_folder = substr(getcwd(), strrpos(getcwd(), DIRECTORY_SEPARATOR) + 1);
- if ($curr_folder != INSTALL_DIR) {
- date_default_timezone_set(Configuration::get_instance()->read('default_time_zone'));
- }
- }
- public function get_fraud_type($type)
- {
- if ($type == 1) {
- $fraud = $this->get_label('repetitive click');
- }
- else if ($type == 2) {
- $fraud = $this->get_label('publisher fraud click');
- }
- else if ($type == 3) {
- $fraud = $this->get_label('invalid ip click');
- }
- else if ($type == 4) {
- $fraud = $this->get_label('invalid geo click');
- }
- else if ($type == 5) {
- $fraud = $this->get_label('proxy click');
- }
- else if ($type == 6) {
- $fraud = $this->get_label('bot click');
- }
- else if ($type == 7) {
- $fraud = $this->get_label('ip limit exceed');
- }
- return $fraud;
- }
- public function get_publisher_top_adunits($time_flag = 3, $pid = 0, $display_type = 0)
- {
- $cpa_addon_enabled = $this->get_addon_status('cpa_enabled');
- $cpm_addon_enabled = $this->get_addon_status('cpm_enabled');
- $html_addon_enabled = $this->get_addon_status('html_enabled');
- $pop_addon_enabled = $this->get_addon_status('pop-ads_enabled');
- $affiliate_addon_enabled = $this->get_addon_status('affiliate-ads_enabled');
- $cpv_addon_enabled = $this->get_addon_status('video-ads_enabled');
- $result_array = [];
- $db = DAL::get_instance();
- $query_string = '';
- $uidspc_str = '';
- if ($pid == 0) {
- $query_string = '';
- $uidspc_str = '';
- }
- else {
- $query_string .= ' s.uid=\'' . intval($pid) . '\' and ';
- $uidspc_str .= ' and a.pubid=\'' . intval($pid) . '\' ';
- }
- $impressionstring = '';
- $datastring = '';
- if ($display_type == 0) {
- $impressionstring = ' sum(s.pub_profit) ';
- $datastring = ' AND (display_type=0 OR display_type=4) ';
- }
- else if (($display_type == 1) && ($cpm_addon_enabled == 1) && ($html_addon_enabled == 1)) {
- $impressionstring = ' sum(s.cpm_profit+s.html_profit) ';
- $datastring = ' AND (display_type=1 OR display_type=4) ';
- }
- else if (($display_type == 1) && ($cpm_addon_enabled == 1)) {
- $impressionstring = ' sum(s.cpm_profit) ';
- $datastring = ' AND (display_type=1 OR display_type=4) ';
- }
- else if (($display_type == 1) && ($html_addon_enabled == 1)) {
- $impressionstring = ' sum(s.html_profit) ';
- $datastring = ' AND (display_type=1 OR display_type=4) ';
- }
- else if (($display_type == 6) && ($cpa_addon_enabled == 1)) {
- $impressionstring = ' sum(s.cpa_profit) ';
- $datastring = ' AND (display_type=6 OR display_type=4) ';
- }
- else if (($display_type == 9) && ($pop_addon_enabled == 1)) {
- $impressionstring = ' sum(s.pop_profit) ';
- $datastring = ' AND (display_type=9) ';
- }
- else if (($display_type == 12) && ($affiliate_addon_enabled == 1)) {
- $impressionstring = ' sum(s.affiliate_profit) ';
- $datastring = ' AND (display_type=12) ';
- }
- else if (($display_type == 13) && ($cpv_addon_enabled == 1)) {
- $impressionstring = ' sum(s.cpv_profit) ';
- $datastring = ' AND (display_type=13) ';
- }
- $text_ads_enabled = Configuration::get_instance()->read('text-ads_enabled');
- $adtype_str = '';
- if ($this->get_addon_status('interstitial_enabled') != 1) {
- $adtype_str .= ' ab.banner_type <>1 ';
- }
- if ($this->get_addon_status('text-image-ads_enabled') != 1) {
- if ($adtype_str != '') {
- $adtype_str .= ' AND ';
- }
- $adtype_str .= ' ab.banner_type <>3 ';
- }
- if ($this->get_addon_status('skin-ads_enabled') != 1) {
- if ($adtype_str != '') {
- $adtype_str .= ' AND ';
- }
- $adtype_str .= ' ab.banner_type <>4 ';
- }
- if ($text_ads_enabled != 1) {
- if ($adtype_str != '') {
- $adtype_str .= ' AND ';
- }
- $adtype_str .= ' ab.type <>1 ';
- }
- if ($adtype_str != '') {
- $adtype_str = ' AND ((' . $adtype_str . ') OR ab.banner_type IS NULL) ';
- }
- if ($time_flag == 1) {
- $start_time = date('Y', time());
- $start_time .= date('m', time());
- $start_time .= date('d', time());
- $start = $start_time;
- $table = TABLE_PREFIX . 'statistics_pub_daily';
- }
- else if ($time_flag == 2) {
- $start_time = date('Y', time());
- $start_time .= date('m', time());
- $start_time .= date('d', time());
- for ($i = 0; $i < 13; $i++) {
- $start_time = $this->get_previous_day($start_time);
- }
- $start = $start_time;
- $table = TABLE_PREFIX . 'statistics_pub_daily';
- }
- else if ($time_flag == 3) {
- $start_time = date('Y', time());
- $start_time .= date('m', time());
- $start_time .= date('d', time());
- for ($i = 0; $i < 29; $i++) {
- $start_time = $this->get_previous_day($start_time);
- }
- $start = $start_time;
- $table = TABLE_PREFIX . 'statistics_pub_daily';
- }
- else if ($time_flag == 4) {
- $start_time = date('Y', time());
- $start_time .= date('m', time());
- $start_temp = $start_time;
- for ($i = 0; $i < 11; $i++) {
- $start_time = $this->get_previous_month($start_time);
- }
- $start = $start_time;
- $table = TABLE_PREFIX . 'statistics_pub_monthly';
- $table1 = TABLE_PREFIX . 'statistics_pub_monthly_temp';
- }
- else if ($time_flag == 5) {
- $start_temp = date('Y', time());
- $start = 0;
- $table = TABLE_PREFIX . 'statistics_pub_yearly';
- $table1 = TABLE_PREFIX . 'statistics_pub_yearly_temp';
- }
- if (($time_flag == 1) || ($time_flag == 2) || ($time_flag == 3)) {
- $row_res = $db->execute_query('SELECT a.id as aduid,a.pubid as apubid,a.name as aduname,display_type as disp from ' . TABLE_PREFIX . 'adunit a LEFT OUTER JOIN ' . TABLE_PREFIX . 'adblock ab ON ab.id=a.blockid LEFT OUTER JOIN ' . $table . ' s ON a.id=s.bid WHERE display_type <>3 ' . $datastring . $adtype_str . ' AND ((' . $query_string . ' s.time >=?) OR (s.uid IS NULL AND s.time IS NULL)) ' . $uidspc_str . ' GROUP BY a.id ORDER BY ' . $impressionstring . ' DESC LIMIT 0,6', [$start]);
- }
- else if (($time_flag == 4) || ($time_flag == 5)) {
- $row = 'SELECT x.aduid as aduid,x.apubid as apubid,x.aduname as aduname,x.disp as disp FROM' . "\r\n\t\t" . '((SELECT a.id as aduid,' . $impressionstring . ' as impss,a.pubid as apubid,a.name as aduname,display_type as disp from ' . TABLE_PREFIX . 'adunit a LEFT OUTER JOIN ' . TABLE_PREFIX . 'adblock ab ON ab.id=a.blockid LEFT OUTER JOIN ' . $table . ' s ON a.id=s.bid WHERE display_type <>3 ' . $datastring . $adtype_str . ' AND ((' . $query_string . ' s.time >=?) OR (s.uid IS NULL AND s.time IS NULL)) ' . $uidspc_str . ' GROUP BY a.id ORDER BY impss DESC LIMIT 0,6)' . "\r\n\t\t\t\t" . 'UNION (SELECT a.id as aduid,' . $impressionstring . ' as impss,a.pubid as apubid,a.name as aduname,display_type as disp from ' . TABLE_PREFIX . 'adunit a LEFT OUTER JOIN ' . TABLE_PREFIX . 'adblock ab ON ab.id=a.blockid LEFT OUTER JOIN ' . $table1 . ' s ON a.id=s.bid WHERE display_type <>3 ' . $datastring . $adtype_str . ' AND ((' . $query_string . ' s.time >=?) OR (s.uid IS NULL AND s.time IS NULL)) ' . $uidspc_str . ' GROUP BY a.id ORDER BY impss DESC LIMIT 0,6)) as x GROUP BY x.aduid ORDER BY sum(x.impss) DESC LIMIT 0,6';
- $row_res = $db->execute_query($row, [$start, $start_temp]);
- }
- $key = 0;
- while ($row_result = $row_res->fetch_assoc()) {
- $result_array[$key][0] = $row_result['aduid'];
- $result_array[$key][1] = $row_result['apubid'];
- if (0 < $row_result['apubid']) {
- $result_array[$key][2] = $this->get_user_name($row_result['apubid']);
- }
- else {
- $result_array[$key][2] = $this->get_label('admin');
- }
- $result_array[$key][3] = $row_result['aduname'];
- $result_array[$key][4] = $row_result['disp'];
- $key = $key + 1;
- }
- return $result_array;
- }
- public function get_advertiser_top_ads($time_flag = 3, $uid = 0, $display_type = 0)
- {
- $cpa_addon_enabled = $this->get_addon_status('cpa_enabled');
- $cpm_addon_enabled = $this->get_addon_status('cpm_enabled');
- $html_addon_enabled = $this->get_addon_status('html_enabled');
- $pop_addon_enabled = $this->get_addon_status('pop-ads_enabled');
- $affiliate_addon_enabled = $this->get_addon_status('affiliate-ads_enabled');
- $cpv_addon_enabled = $this->get_addon_status('video-ads_enabled');
- $text_ads_enabled = Configuration::get_instance()->read('text-ads_enabled');
- $result_array = [];
- $db = DAL::get_instance();
- $query_string = '';
- $uidspc_str = '';
- if ($uid == 0) {
- $query_string = '';
- $uidspc_str = '';
- }
- else {
- $query_string .= ' s.uid=\'' . intval($uid) . '\' and ';
- $uidspc_str .= ' and a.uid=\'' . intval($uid) . '\' ';
- }
- if ($time_flag == 1) {
- $start_time = date('Y', time());
- $start_time .= date('m', time());
- $start_time .= date('d', time());
- $start = $start_time;
- $table = TABLE_PREFIX . 'statistics_adv_daily';
- }
- else if ($time_flag == 2) {
- $start_time = date('Y', time());
- $start_time .= date('m', time());
- $start_time .= date('d', time());
- for ($i = 0; $i < 13; $i++) {
- $start_time = $this->get_previous_day($start_time);
- }
- $start = $start_time;
- $table = TABLE_PREFIX . 'statistics_adv_daily';
- }
- else if ($time_flag == 3) {
- $start_time = date('Y', time());
- $start_time .= date('m', time());
- $start_time .= date('d', time());
- for ($i = 0; $i < 29; $i++) {
- $start_time = $this->get_previous_day($start_time);
- }
- $start = $start_time;
- $table = TABLE_PREFIX . 'statistics_adv_daily';
- }
- else if ($time_flag == 4) {
- $start_time = date('Y', time());
- $start_time .= date('m', time());
- $start_temp = $start_time;
- for ($i = 0; $i < 11; $i++) {
- $start_time = $this->get_previous_month($start_time);
- }
- $start = $start_time;
- $table = TABLE_PREFIX . 'statistics_adv_monthly';
- $table1 = TABLE_PREFIX . 'statistics_adv_monthly_temp';
- }
- else if ($time_flag == 5) {
- $start_temp = date('Y', time());
- $start = 0;
- $table = TABLE_PREFIX . 'statistics_adv_yearly';
- $table1 = TABLE_PREFIX . 'statistics_adv_yearly_temp';
- }
- $impressionstring = '';
- $uidstrings = '';
- if ($display_type == 0) {
- $impressionstring = ' sum(s.money_spent) ';
- $uidstrings = ' and a.uid<>0 ';
- }
- else if (($display_type == 1) && ($cpm_addon_enabled == 1)) {
- $impressionstring = ' sum(s.cpm_spend) ';
- $uidstrings = ' and a.uid<>0 ';
- }
- else if (($display_type == 2) && ($html_addon_enabled == 1)) {
- $impressionstring = ' sum(s.html_profit) ';
- $uidstrings = ' and a.uid=0 AND a.html_default =0 ';
- }
- else if (($display_type == 6) && ($cpa_addon_enabled == 1)) {
- $impressionstring = ' sum(s.cpa_spend) ';
- $uidstrings = ' and a.uid<>0 ';
- }
- else if (($display_type == 9) && ($pop_addon_enabled == 1)) {
- $impressionstring = ' sum(s.pop_spend) ';
- $uidstrings = ' and a.uid<>0 ';
- }
- else if (($display_type == 12) && ($affiliate_addon_enabled == 1)) {
- $impressionstring = ' sum(s.affiliate_spend) ';
- $uidstrings = ' and a.uid<>0 ';
- }
- else if (($display_type == 13) && ($cpv_addon_enabled == 1)) {
- $impressionstring = ' sum(s.cpv_spend) ';
- $uidstrings = ' and a.uid<>0 ';
- }
- $adtype_str = '';
- if ($this->get_addon_status('ecommerce-ads_enabled') != 1) {
- $adtype_str .= ' AND a.type <>7 ';
- }
- else {
- $adtype_str .= ' AND (a.type <>7 OR (a.type =7 AND a.ecommerce_parent >0)) ';
- }
- if ($this->get_addon_status('text-image-ads_enabled') != 1) {
- $adtype_str .= ' AND a.type <>11 ';
- }
- if ($this->get_addon_status('interstitial_enabled') != 1) {
- $adtype_str .= ' AND a.type <>5 ';
- }
- if ($cpv_addon_enabled != 1) {
- $adtype_str .= ' AND a.type <>13 ';
- }
- if ($this->get_addon_status('skin-ads_enabled') != 1) {
- $adtype_str .= ' AND a.type <>14 ';
- }
- if ($text_ads_enabled != 1) {
- $adtype_str .= ' AND a.type <>1 ';
- }
- if (($time_flag == 1) || ($time_flag == 2) || ($time_flag == 3)) {
- $row_res = $db->execute_query('SELECT a.id as ad_id,a.uid as auid,a.name as aname from ' . TABLE_PREFIX . 'ads a LEFT OUTER JOIN ' . $table . ' s ON a.id=s.aid WHERE a.display_type <>3 AND ((' . $query_string . ' s.time >=?) OR (s.uid IS NULL AND s.time IS NULL)) ' . $uidstrings . $adtype_str . ' and a.status=? and a.display_type=? ' . $uidspc_str . ' GROUP BY a.id ORDER BY ' . $impressionstring . ' DESC LIMIT 0,6', [$start, 1, $display_type]);
- }
- else if (($time_flag == 4) || ($time_flag == 5)) {
- $row_res = $db->execute_query('SELECT x.ad_id as ad_id,x.auid as auid,x.aname as aname FROM' . "\r\n\t\t" . '((SELECT a.id as ad_id,' . $impressionstring . ' as impss,a.uid as auid,a.name as aname from ' . TABLE_PREFIX . 'ads a LEFT OUTER JOIN ' . $table . ' s ON a.id=s.aid WHERE a.display_type <>3 AND ((' . $query_string . ' s.time >=?) OR (s.uid IS NULL AND s.time IS NULL)) ' . $uidstrings . $adtype_str . ' and a.status=1 and a.display_type=? ' . $uidspc_str . ' GROUP BY a.id ORDER BY impss DESC LIMIT 0,6)' . "\r\n\t\t\t\t" . 'UNION (SELECT a.id as ad_id,' . $impressionstring . ' as impss,a.uid as auid,a.name as aname from ' . TABLE_PREFIX . 'ads a LEFT OUTER JOIN ' . $table1 . ' s ON a.id=s.aid WHERE a.display_type <>3 AND ((' . $query_string . ' s.time >=?) OR (s.uid IS NULL AND s.time IS NULL)) ' . $uidstrings . $adtype_str . ' and a.status=1 and a.display_type=? ' . $uidspc_str . ' GROUP BY a.id ORDER BY impss DESC LIMIT 0,6)) as x GROUP BY x.ad_id ORDER BY sum(x.impss) DESC LIMIT 0,6', [$start, $display_type, $start_temp, $display_type]);
- }
- $key = 0;
- while ($row_result = $row_res->fetch_assoc()) {
- $result_array[$key][0] = $row_result['ad_id'];
- $result_array[$key][1] = $row_result['auid'];
- $result_array[$key][2] = $this->get_user_name($row_result['auid']);
- $result_array[$key][3] = $row_result['aname'];
- $key = $key + 1;
- }
- return $result_array;
- }
- public function get_suggested_value_ad($type, $aid, $bannerid = 0, $pricing = 0, $device = 2)
- {
- $increment_value = 0.01;
- $db = DAL::get_instance();
- $uid = $this->read_cookie_param(COOKIE_LOGINID);
- $devicestring = '';
- if ($device != 2) {
- $devicestring = ' AND (a.device=2 OR a.device=' . intval($device) . ') ';
- }
- if (($type == 2) || ($type == 7)) {
- $typestring = ' AND (a.type=2 OR a.type=7) ';
- }
- else {
- $typestring = ' AND a.type=' . intval($type) . ' ';
- }
- $sugest_val = $db->read_single_column('SELECT COALESCE(round(max(default_rate),2),0) FROM ' . "\r\n\t\t\t\t" . TABLE_PREFIX . 'ads a ' . "\r\n\t\t\t\t" . 'WHERE a.status=1 ' . "\r\n\t\t\t\t" . 'AND a.id<>? ' . "\r\n\t\t\t\t" . 'AND a.display_type=?' . "\r\n\t\t\t\t" . 'AND a.pause_status=0' . "\r\n\t\t\t\t" . 'AND a.pricing_status=1' . "\r\n\t\t\t\t" . 'AND a.user_status=1' . "\r\n\t\t\t\t" . $devicestring . "\t\t\t\t\r\n\t\t\t\t" . $typestring . "\r\n\t\t\t\t" . 'AND a.banner_id=?', [$aid, $pricing, $bannerid]);
- $minvalue = $this->get_minrate_by_uid($uid, $pricing);
- if ($minvalue <= $sugest_val) {
- $value = $sugest_val + $increment_value;
- }
- else {
- $value = $minvalue;
- }
- return $value;
- }
- public function get_date_format($type, $year, $month = '', $day = '', $hour = '')
- {
- $d = Configuration::get_instance()->read('day_format');
- $m = Configuration::get_instance()->read('month_format');
- $y = Configuration::get_instance()->read('year_format');
- $dp = Configuration::get_instance()->read('day_position');
- $ds = Configuration::get_instance()->read('day_separator');
- $hs = Configuration::get_instance()->read('time_separator');
- $hds = Configuration::get_instance()->read('hour_display_format');
- $h = Configuration::get_instance()->read('hour_format');
- $mfor = Configuration::get_instance()->read('minute_format');
- $sfor = Configuration::get_instance()->read('second_format');
- if ($type == 2) {
- $time = $year;
- $cday = date('j', $time);
- $cday1 = date('d', $time);
- $cmonth0 = date('n', $time);
- $cmonth = date('m', $time);
- $cmonth1 = date('M', $time);
- $cyear = date('y', $time);
- $cyear1 = date('Y', $time);
- if ($hds == 12) {
- if ($h == 'HH') {
- $chour = date('h', $time);
- }
- else {
- $chour = date('g', $time);
- }
- }
- else if ($hds == 24) {
- if ($h == 'HH') {
- $chour = date('H', $time);
- }
- else {
- $chour = date('G', $time);
- }
- }
- $cminute = date('i', $time);
- if ($mfor == 'M') {
- if ($cminute < 10) {
- $cminute = substr($cminute, -1);
- }
- }
- $csecond = date('s', $time);
- if ($sfor == 'S') {
- if ($csecond < 10) {
- $csecond = substr($csecond, -1);
- }
- }
- $cformat = date('A', $time);
- $datestring = '';
- if ($d == 'd') {
- $datestring_day = $cday;
- }
- else if ($d == 'D') {
- $datestring_day = $cday1;
- }
- if ($m == 'm') {
- $daystring_month = $cmonth0;
- }
- else if ($m == 'M') {
- $daystring_month = $cmonth;
- }
- else if ($m == 'Mon') {
- $daystring_month = $cmonth1;
- }
- if ($y == 'y') {
- $daystring_year = $cyear;
- }
- else if ($y == 'Y') {
- $daystring_year = $cyear1;
- }
- if ($hds == 12) {
- $daystring_time = ' ' . $chour . $hs . $cminute . $hs . $csecond . ' ' . $cformat;
- }
- else if ($hds == 24) {
- $daystring_time = ' ' . $chour . $hs . $cminute . $hs . $csecond;
- }
- if ($dp == 1) {
- $datestring = $datestring_day . $ds . $daystring_month . $ds . $daystring_year . $daystring_time;
- }
- else if ($dp == 2) {
- $datestring = $daystring_month . $ds . $datestring_day . $ds . $daystring_year . $daystring_time;
- }
- else if ($dp == 3) {
- $datestring = $daystring_year . $ds . $daystring_month . $ds . $datestring_day . $daystring_time;
- }
- else if ($dp == 4) {
- $datestring = $daystring_year . $ds . $datestring_day . $ds . $daystring_month . $daystring_time;
- }
- return $datestring;
- }
- if ($type == 1) {
- $day_str = '';
- $month_str = '';
- $hour_str = '';
- if ($hour != '') {
- $hour_str = ' ' . $hour;
- }
- if ($day != '') {
- if ($d == 'd') {
- $day_first = substr($day, 0, 1);
- if ($day_first == 0) {
- $day = substr($day, 1, 1);
- }
- }
- if ($dp == 3) {
- $day_str = $day;
- }
- else {
- $day_str = $day . $ds;
- }
- }
- if ($month != '') {
- if ($m == 'm') {
- $month_first = substr($month, 0, 1);
- if ($month_first == 0) {
- $month = substr($month, 1, 1);
- }
- }
- else if ($m == 'Mon') {
- if ($month == '01') {
- $month = 'Jan';
- }
- else if ($month == '02') {
- $month = 'Feb';
- }
- else if ($month == '03') {
- $month = 'Mar';
- }
- else if ($month == '04') {
- $month = 'Apr';
- }
- else if ($month == '05') {
- $month = 'May';
- }
- else if ($month == '06') {
- $month = 'Jun';
- }
- else if ($month == '07') {
- $month = 'Jul';
- }
- else if ($month == '08') {
- $month = 'Aug';
- }
- else if ($month == '09') {
- $month = 'Sep';
- }
- else if ($month == '10') {
- $month = 'Oct';
- }
- else if ($month == '11') {
- $month = 'Nov';
- }
- else if ($month == '12') {
- $month = 'Dec';
- }
- }
- if ($dp == 4) {
- $month_str = $month;
- }
- else {
- $month_str = $month . $ds;
- }
- }
- if ($y == 'y') {
- $year = substr($year, 2, 2);
- }
- if ($dp == 1) {
- $d_format = $day_str . $month_str . $year . $hour_str;
- }
- else if ($dp == 2) {
- $d_format = $month_str . $day_str . $year . $hour_str;
- }
- else if ($dp == 3) {
- $d_format = $year . $ds . $month_str . $day_str . $hour_str;
- }
- else if ($dp == 4) {
- $d_format = $year . $ds . $day_str . $month_str . $hour_str;
- }
- return $d_format;
- }
- if ($type == 3) {
- $time = $year;
- $cday = date('j', $time);
- $cday1 = date('d', $time);
- $cmonth0 = date('n', $time);
- $cmonth = date('m', $time);
- $cmonth1 = date('M', $time);
- $cyear = date('y', $time);
- $cyear1 = date('Y', $time);
- $datestring = '';
- if ($d == 'd') {
- $datestring_day = $cday;
- }
- else if ($d == 'D') {
- $datestring_day = $cday1;
- }
- if ($m == 'm') {
- $daystring_month = $cmonth0;
- }
- else if ($m == 'M') {
- $daystring_month = $cmonth;
- }
- else if ($m == 'Mon') {
- $daystring_month = $cmonth1;
- }
- if ($y == 'y') {
- $daystring_year = $cyear;
- }
- else if ($y == 'Y') {
- $daystring_year = $cyear1;
- }
- $daystring_time = '';
- if ($dp == 1) {
- $datestring = $datestring_day . $ds . $daystring_month . $ds . $daystring_year . $daystring_time;
- }
- else if ($dp == 2) {
- $datestring = $daystring_month . $ds . $datestring_day . $ds . $daystring_year . $daystring_time;
- }
- else if ($dp == 3) {
- $datestring = $daystring_year . $ds . $daystring_month . $ds . $datestring_day . $daystring_time;
- }
- else if ($dp == 4) {
- $datestring = $daystring_year . $ds . $datestring_day . $ds . $daystring_month . $daystring_time;
- }
- return $datestring;
- }
- }
- public function get_number_format($value, $places = 2)
- {
- $ts = Configuration::get_instance()->read('thousand_separator');
- $ds = Configuration::get_instance()->read('decimal_separator');
- $ds_places = Configuration::get_instance()->read('decimal_place');
- if ($places == 0) {
- $value = sprintf('%d', round($value, $ds_places));
- return number_format($value, 0, $ds, $ts);
- }
- else {
- $value = sprintf('%0.' . $ds_places . 'F', round($value, $ds_places));
- return number_format($value, $ds_places, $ds, $ts);
- }
- }
- public function get_money_format($money, $places = 2)
- {
- $money = self::get_number_format($money, $places);
- if (Configuration::get_instance()->read('currency_position') == 1) {
- $money = Configuration::get_instance()->read('currency_symbol') . ' ' . $money;
- }
- else {
- $money = $money . ' ' . Configuration::get_instance()->read('currency_symbol');
- }
- return $money;
- }
- public function get_advertiser_check_statistics($time_flag)
- {
- $cpa_addon_enabled = $this->get_addon_status('cpa_enabled');
- $cpm_addon_enabled = $this->get_addon_status('cpm_enabled');
- $html_addon_enabled = $this->get_addon_status('html_enabled');
- $pop_addon_enabled = $this->get_addon_status('pop-ads_enabled');
- $affiliate_addon_enabled = $this->get_addon_status('affiliate-ads_enabled');
- $cpv_addon_enabled = $this->get_addon_status('video-ads_enabled');
- if ($cpa_addon_enabled == 1) {
- $cpaquerystring = ' ,COALESCE(sum(cpa_impression),0) as cpaimp,COALESCE(sum(cpa_click),0) as cpaclick,COALESCE(sum(cpa_conversion),0) as cpaconversion,COALESCE(sum(cpa_spend),0) as cpaspend,COALESCE(sum(cpa_profit),0) as cpaprofit ';
- $cpaquerystring1 = ' ,COALESCE(sum(x.cpaimp),0) as cpaimp,COALESCE(sum(x.cpaclick),0) as cpaclick,COALESCE(sum(x.cpaconversion),0) as cpaconversion,COALESCE(sum(x.cpaspend),0) as cpaspend,COALESCE(sum(x.cpaprofit),0) as cpaprofit ';
- $cpaquerystring2 = ' ,COALESCE(sum(cpa_impression),0) as cpaimp ';
- }
- else {
- $cpaquerystring = '';
- $cpaquerystring1 = '';
- $cpaquerystring2 = '';
- }
- if ($affiliate_addon_enabled == 1) {
- $cpaquerystring .= ' ,COALESCE(sum(affiliate_click),0) as affiliateclick,COALESCE(sum(affiliate_conversion),0) as affiliateconversion,COALESCE(sum(affiliate_spend),0) as affiliatespend,COALESCE(sum(affiliate_profit),0) as affiliateprofit ';
- $cpaquerystring1 .= ' ,COALESCE(sum(x.affiliateclick),0) as affiliateclick,COALESCE(sum(x.affiliateconversion),0) as affiliateconversion,COALESCE(sum(x.affiliatespend),0) as affiliatespend,COALESCE(sum(x.affiliateprofit),0) as affiliateprofit ';
- }
- if ($cpm_addon_enabled == 1) {
- $cpmquerystring = ' ,COALESCE(sum(cpm_impression),0) as cpmimp,COALESCE(sum(cpm_spend),0) as cpmspend,COALESCE(sum(cpm_profit),0) as cpmprofit,COALESCE(sum(cpm_click),0) as cpmclick ';
- $cpmquerystring1 = ' ,COALESCE(sum(x.cpmimp),0) as cpmimp,COALESCE(sum(x.cpmspend),0) as cpmspend,COALESCE(sum(x.cpmprofit),0) as cpmprofit,COALESCE(sum(x.cpmclick),0) as cpmclick ';
- }
- else {
- $cpmquerystring = '';
- $cpmquerystring1 = '';
- }
- if ($cpv_addon_enabled == 1) {
- $cpmquerystring .= ' ,COALESCE(sum(cpv_impression),0) as cpvimp,COALESCE(sum(cpv_spend),0) as cpvspend,COALESCE(sum(cpv_profit),0) as cpvprofit,COALESCE(sum(cpv_click),0) as cpvclick ';
- $cpmquerystring1 .= ' ,COALESCE(sum(x.cpvimp),0) as cpvimp,COALESCE(sum(x.cpvspend),0) as cpvspend,COALESCE(sum(x.cpvprofit),0) as cpvprofit,COALESCE(sum(x.cpvclick),0) as cpvclick ';
- }
- if ($pop_addon_enabled == 1) {
- $cpmquerystring .= ' ,COALESCE(sum(pop_impression),0) as popimp,COALESCE(sum(pop_spend),0) as popspend,COALESCE(sum(pop_profit),0) as popprofit ';
- $cpmquerystring1 .= ' ,COALESCE(sum(x.popimp),0) as popimp,COALESCE(sum(x.popspend),0) as popspend,COALESCE(sum(x.popprofit),0) as popprofit ';
- }
- if ($html_addon_enabled == 1) {
- $htmlquerystring = ' ,COALESCE(sum(html_impression),0) as htmlimp,COALESCE(sum(html_profit),0) as htmlprofit ';
- $htmlquerystring1 = ' ,COALESCE(sum(x.htmlimp),0) as htmlimp,COALESCE(sum(x.htmlprofit),0) as htmlprofit ';
- }
- else {
- $htmlquerystring = '';
- $htmlquerystring1 = '';
- }
- $db = DAL::get_instance();
- $data_array = [];
- if ($time_flag == 3) {
- $start_time = date('Y', time());
- $start_time .= date('m', time());
- $start_time .= date('d', time());
- $current_time = $start_time;
- $start = date('Y', time());
- $start .= date('m', time());
- $start .= '01';
- $table = TABLE_PREFIX . 'statistics_adv_daily';
- }
- else if ($time_flag == 4) {
- $start_time = date('Y', time());
- $start_time .= date('m', time());
- $start_time = $this->get_previous_month($start_time);
- $current_time = $start_time;
- $start_temp = $start_time;
- $start = date('Y', time());
- $start .= '01';
- $table = TABLE_PREFIX . 'statistics_adv_monthly';
- $table1 = TABLE_PREFIX . 'statistics_adv_monthly_temp';
- }
- else if ($time_flag == 5) {
- $start_temp = date('Y', time());
- $start_temp = $this->get_previousyear($start_temp);
- $current_time = $start_temp;
- $start = $db->read_single_column('SELECT min(time) FROM ' . TABLE_PREFIX . 'statistics_adv_yearly');
- if (($start == '') || ($start == 0)) {
- $start = $start_temp;
- }
- $table = TABLE_PREFIX . 'statistics_adv_yearly';
- $table1 = TABLE_PREFIX . 'statistics_adv_yearly_temp';
- }
- if ($time_flag == 3) {
- $row_res = $db->execute_query('SELECT COALESCE(sum(impression),0) as imp,COALESCE(sum(click),0) as clk,COALESCE(sum(money_spent),0) as spent,time' . $cpmquerystring . ' ' . $htmlquerystring . ' ' . $cpaquerystring . ' FROM ' . $table . ' WHERE time >=? GROUP BY time ORDER BY time ASC', [$start]);
- $today_array = [];
- while ($tdy = $row_res->fetch_assoc()) {
- $key = $tdy['time'];
- $today_array[$key]['impression'] = $tdy['imp'];
- $today_array[$key]['click'] = $tdy['clk'];
- $today_array[$key]['money_spent'] = $tdy['spent'];
- if ($cpm_addon_enabled == 1) {
- $today_array[$key]['cpm_impression'] = $tdy['cpmimp'];
- $today_array[$key]['cpm_spend'] = $tdy['cpmspend'];
- $today_array[$key]['cpm_click'] = $tdy['cpmclick'];
- }
- if ($cpv_addon_enabled == 1) {
- $today_array[$key]['cpv_impression'] = $tdy['cpvimp'];
- $today_array[$key]['cpv_spend'] = $tdy['cpvspend'];
- $today_array[$key]['cpv_click'] = $tdy['cpvclick'];
- }
- if ($html_addon_enabled == 1) {
- $today_array[$key]['html_impression'] = $tdy['htmlimp'];
- $today_array[$key]['html_profit'] = $tdy['htmlprofit'];
- }
- if ($cpa_addon_enabled == 1) {
- $today_array[$key]['cpa_impression'] = $tdy['cpaimp'];
- $today_array[$key]['cpa_click'] = $tdy['cpaclick'];
- $today_array[$key]['cpa_conversion'] = $tdy['cpaconversion'];
- $today_array[$key]['cpa_spend'] = $tdy['cpaspend'];
- $today_array[$key]['cpa_profit'] = $tdy['cpaprofit'];
- }
- if ($affiliate_addon_enabled == 1) {
- $today_array[$key]['affiliate_click'] = $tdy['affiliateclick'];
- $today_array[$key]['affiliate_conversion'] = $tdy['affiliateconversion'];
- $today_array[$key]['affiliate_spend'] = $tdy['affiliatespend'];
- $today_array[$key]['affiliate_profit'] = $tdy['affiliateprofit'];
- }
- if ($pop_addon_enabled == 1) {
- $today_array[$key]['pop_impression'] = $tdy['popimp'];
- $today_array[$key]['pop_spend'] = $tdy['popspend'];
- }
- }
- }
- else if (($time_flag == 4) || ($time_flag == 5)) {
- $row_res = $db->execute_query('SELECT COALESCE(sum(x.imp),0) as imp,COALESCE(sum(x.clk),0) as clk,COALESCE(sum(x.spent),0) as spent,time' . $cpmquerystring1 . ' ' . $htmlquerystring1 . ' ' . $cpaquerystring1 . ' FROM' . "\r\n\t\t\t" . '((SELECT COALESCE(sum(impression),0) as imp,COALESCE(sum(click),0) as clk,COALESCE(sum(money_spent),0) as spent,time' . $cpmquerystring . ' ' . $htmlquerystring . ' ' . $cpaquerystring . ' FROM ' . $table . ' WHERE time >=? GROUP BY time ORDER BY time ASC)' . "\r\n\t\t\t" . 'UNION (SELECT COALESCE(sum(impression),0) as imp,COALESCE(sum(click),0) as clk,COALESCE(sum(money_spent),0) as spent,time' . $cpmquerystring . ' ' . $htmlquerystring . ' ' . $cpaquerystring . ' FROM ' . $table1 . ' WHERE time >=? GROUP BY time ORDER BY time ASC)) as x' . "\r\n\t\t\t" . 'GROUP BY x.time ORDER BY x.time ASC', [$start, $start_temp]);
- $today_array = [];
- while ($tdy = $row_res->fetch_assoc()) {
- $key = $tdy['time'];
- $today_array[$key]['impression'] = $tdy['imp'];
- $today_array[$key]['click'] = $tdy['clk'];
- $today_array[$key]['money_spent'] = $tdy['spent'];
- if ($cpm_addon_enabled == 1) {
- $today_array[$key]['cpm_impression'] = $tdy['cpmimp'];
- $today_array[$key]['cpm_spend'] = $tdy['cpmspend'];
- $today_array[$key]['cpm_click'] = $tdy['cpmclick'];
- }
- if ($cpv_addon_enabled == 1) {
- $today_array[$key]['cpv_impression'] = $tdy['cpvimp'];
- $today_array[$key]['cpv_spend'] = $tdy['cpvspend'];
- $today_array[$key]['cpv_click'] = $tdy['cpvclick'];
- }
- if ($html_addon_enabled == 1) {
- $today_array[$key]['html_impression'] = $tdy['htmlimp'];
- $today_array[$key]['html_profit'] = $tdy['htmlprofit'];
- }
- if ($cpa_addon_enabled == 1) {
- $today_array[$key]['cpa_impression'] = $tdy['cpaimp'];
- $today_array[$key]['cpa_click'] = $tdy['cpaclick'];
- $today_array[$key]['cpa_conversion'] = $tdy['cpaconversion'];
- $today_array[$key]['cpa_spend'] = $tdy['cpaspend'];
- $today_array[$key]['cpa_profit'] = $tdy['cpaprofit'];
- }
- if ($affiliate_addon_enabled == 1) {
- $today_array[$key]['affiliate_click'] = $tdy['affiliateclick'];
- $today_array[$key]['affiliate_conversion'] = $tdy['affiliateconversion'];
- $today_array[$key]['affiliate_spend'] = $tdy['affiliatespend'];
- $today_array[$key]['affiliate_profit'] = $tdy['affiliateprofit'];
- }
- if ($pop_addon_enabled == 1) {
- $today_array[$key]['pop_impression'] = $tdy['popimp'];
- $today_array[$key]['pop_spend'] = $tdy['popspend'];
- }
- }
- }
- while ($start <= $current_time) {
- if (array_key_exists($start, $today_array)) {
- $data_array[$start]['impression'] = $today_array[$start]['impression'];
- $data_array[$start]['click'] = $today_array[$start]['click'];
- $data_array[$start]['money_spent'] = $today_array[$start]['money_spent'];
- if ($cpm_addon_enabled == 1) {
- $data_array[$start]['cpm_impression'] = $today_array[$start]['cpm_impression'];
- $data_array[$start]['cpm_spend'] = $today_array[$start]['cpm_spend'];
- $data_array[$start]['cpm_click'] = $today_array[$start]['cpm_click'];
- }
- if ($cpv_addon_enabled == 1) {
- $data_array[$start]['cpv_impression'] = $today_array[$start]['cpv_impression'];
- $data_array[$start]['cpv_spend'] = $today_array[$start]['cpv_spend'];
- $data_array[$start]['cpv_click'] = $today_array[$start]['cpv_click'];
- }
- if ($html_addon_enabled == 1) {
- $data_array[$start]['html_impression'] = $today_array[$start]['html_impression'];
- $data_array[$start]['html_profit'] = $today_array[$start]['html_profit'];
- }
- if ($cpa_addon_enabled == 1) {
- $data_array[$start]['cpa_impression'] = $today_array[$start]['cpa_impression'];
- $data_array[$start]['cpa_click'] = $today_array[$start]['cpa_click'];
- $data_array[$start]['cpa_conversion'] = $today_array[$start]['cpa_conversion'];
- $data_array[$start]['cpa_spend'] = $today_array[$start]['cpa_spend'];
- $data_array[$start]['cpa_profit'] = $today_array[$start]['cpa_profit'];
- }
- if ($affiliate_addon_enabled == 1) {
- $data_array[$start]['affiliate_click'] = $today_array[$start]['affiliate_click'];
- $data_array[$start]['affiliate_conversion'] = $today_array[$start]['affiliate_conversion'];
- $data_array[$start]['affiliate_spend'] = $today_array[$start]['affiliate_spend'];
- $data_array[$start]['affiliate_profit'] = $today_array[$start]['affiliate_profit'];
- }
- if ($pop_addon_enabled == 1) {
- $data_array[$start]['pop_impression'] = $today_array[$start]['pop_impression'];
- $data_array[$start]['pop_spend'] = $today_array[$start]['pop_spend'];
- }
- }
- else {
- $data_array[$start]['impression'] = 0;
- $data_array[$start]['click'] = 0;
- $data_array[$start]['money_spent'] = 0;
- if ($cpm_addon_enabled == 1) {
- $data_array[$start]['cpm_impression'] = 0;
- $data_array[$start]['cpm_spend'] = 0;
- $data_array[$start]['cpm_click'] = 0;
- }
- if ($cpv_addon_enabled == 1) {
- $data_array[$start]['cpv_impression'] = 0;
- $data_array[$start]['cpv_spend'] = 0;
- $data_array[$start]['cpv_click'] = 0;
- }
- if ($html_addon_enabled == 1) {
- $data_array[$start]['html_impression'] = 0;
- $data_array[$start]['html_profit'] = 0;
- }
- if ($cpa_addon_enabled == 1) {
- $data_array[$start]['cpa_impression'] = 0;
- $data_array[$start]['cpa_click'] = 0;
- $data_array[$start]['cpa_conversion'] = 0;
- $data_array[$start]['cpa_spend'] = 0;
- $data_array[$start]['cpa_profit'] = 0;
- }
- if ($affiliate_addon_enabled == 1) {
- $data_array[$start]['affiliate_click'] = 0;
- $data_array[$start]['affiliate_conversion'] = 0;
- $data_array[$start]['affiliate_spend'] = 0;
- $data_array[$start]['affiliate_profit'] = 0;
- }
- if ($pop_addon_enabled == 1) {
- $data_array[$start]['pop_impression'] = 0;
- $data_array[$start]['pop_spend'] = 0;
- }
- }
- if ($time_flag == 3) {
- $start = $this->get_nextday($start);
- continue;
- }
- if ($time_flag == 4) {
- $start = $this->get_nextmonth($start);
- continue;
- }
- if ($time_flag == 5) {
- $start = $this->get_nextyear($start);
- }
- }
- return $data_array;
- }
- public function get_publisher_check_statistics($time_flag)
- {
- $cpa_addon_enabled = $this->get_addon_status('cpa_enabled');
- $cpm_addon_enabled = $this->get_addon_status('cpm_enabled');
- $html_addon_enabled = $this->get_addon_status('html_enabled');
- $pop_addon_enabled = $this->get_addon_status('pop-ads_enabled');
- $affiliate_addon_enabled = $this->get_addon_status('affiliate-ads_enabled');
- $cpv_addon_enabled = $this->get_addon_status('video-ads_enabled');
- if ($cpa_addon_enabled == 1) {
- $cpaquerystring = ' ,COALESCE(sum(cpa_impression),0) as cpaimp,COALESCE(sum(cpa_click),0) as cpaclick,COALESCE(sum(cpa_conversion),0) as cpaconversion,COALESCE(sum(cpa_spend),0) as cpaspend,COALESCE(sum(cpa_profit),0) as cpaprofit ';
- $cpaquerystring1 = ' ,COALESCE(sum(x.cpaimp),0) as cpaimp,COALESCE(sum(x.cpaclick),0) as cpaclick,COALESCE(sum(x.cpaconversion),0) as cpaconversion,COALESCE(sum(x.cpaspend),0) as cpaspend,COALESCE(sum(x.cpaprofit),0) as cpaprofit ';
- $cpaquerystring2 = ' ,COALESCE(sum(cpa_impression),0) as cpaimp ';
- }
- else {
- $cpaquerystring = '';
- $cpaquerystring1 = '';
- $cpaquerystring2 = '';
- }
- if ($affiliate_addon_enabled == 1) {
- $cpaquerystring .= ' ,COALESCE(sum(affiliate_click),0) as affiliateclick,COALESCE(sum(affiliate_conversion),0) as affiliateconversion,COALESCE(sum(affiliate_spend),0) as affiliatespend,COALESCE(sum(affiliate_profit),0) as affiliateprofit ';
- $cpaquerystring1 .= ' ,COALESCE(sum(x.affiliateclick),0) as affiliateclick,COALESCE(sum(x.affiliateconversion),0) as affiliateconversion,COALESCE(sum(x.affiliatespend),0) as affiliatespend,COALESCE(sum(x.affiliateprofit),0) as affiliateprofit ';
- }
- if ($cpm_addon_enabled == 1) {
- $cpmquerystring = ' ,COALESCE(sum(cpm_impression),0) as cpmimp,COALESCE(sum(cpm_spend),0) as cpmspend,COALESCE(sum(cpm_profit),0) as cpmprofit,COALESCE(sum(cpm_click),0) as cpmclick ';
- $cpmquerystring1 = ' ,COALESCE(sum(x.cpmimp),0) as cpmimp,COALESCE(sum(x.cpmspend),0) as cpmspend,COALESCE(sum(x.cpmprofit),0) as cpmprofit,COALESCE(sum(x.cpmclick),0) as cpmclick ';
- }
- else {
- $cpmquerystring = '';
- $cpmquerystring1 = '';
- }
- if ($cpv_addon_enabled == 1) {
- $cpmquerystring .= ' ,COALESCE(sum(cpv_impression),0) as cpvimp,COALESCE(sum(cpv_spend),0) as cpvspend,COALESCE(sum(cpv_profit),0) as cpvprofit,COALESCE(sum(cpv_click),0) as cpvclick ';
- $cpmquerystring1 .= ' ,COALESCE(sum(x.cpvimp),0) as cpvimp,COALESCE(sum(x.cpvspend),0) as cpvspend,COALESCE(sum(x.cpvprofit),0) as cpvprofit,COALESCE(sum(x.cpvclick),0) as cpvclick ';
- }
- if ($pop_addon_enabled == 1) {
- $cpmquerystring .= ' ,COALESCE(sum(pop_impression),0) as popimp,COALESCE(sum(pop_spend),0) as popspend,COALESCE(sum(pop_profit),0) as popprofit ';
- $cpmquerystring1 .= ' ,COALESCE(sum(x.popimp),0) as popimp,COALESCE(sum(x.popspend),0) as popspend,COALESCE(sum(x.popprofit),0) as popprofit ';
- }
- if ($html_addon_enabled == 1) {
- $htmlquerystring = ' ,COALESCE(sum(html_impression),0) as htmlimp,COALESCE(sum(html_profit),0) as htmlprofit ';
- $htmlquerystring1 = ' ,COALESCE(sum(x.htmlimp),0) as htmlimp,COALESCE(sum(x.htmlprofit),0) as htmlprofit ';
- }
- else {
- $htmlquerystring = '';
- $htmlquerystring1 = '';
- }
- $db = DAL::get_instance();
- $data_array = [];
- if ($time_flag == 3) {
- $start_time = date('Y', time());
- $start_time .= date('m', time());
- $start_time .= date('d', time());
- $current_time = $start_time;
- $start = date('Y', time());
- $start .= date('m', time());
- $start .= '01';
- $table = TABLE_PREFIX . 'statistics_pub_daily';
- }
- else if ($time_flag == 4) {
- $start_time = date('Y', time());
- $start_time .= date('m', time());
- $start_time = $this->get_previous_month($start_time);
- $current_time = $start_time;
- $start_temp = $start_time;
- $start = date('Y', time());
- $start .= '01';
- $table = TABLE_PREFIX . 'statistics_pub_monthly';
- $table1 = TABLE_PREFIX . 'statistics_pub_monthly_temp';
- }
- else if ($time_flag == 5) {
- $start_temp = date('Y', time());
- $start_temp = $this->get_previousyear($start_temp);
- $current_time = $start_temp;
- $start = $db->read_single_column('SELECT min(time) FROM ' . TABLE_PREFIX . 'statistics_pub_yearly');
- if (($start == '') || ($start == 0)) {
- $start = $start_temp;
- }
- $table = TABLE_PREFIX . 'statistics_pub_yearly';
- $table1 = TABLE_PREFIX . 'statistics_pub_yearly_temp';
- }
- if ($time_flag == 3) {
- $row_res = $db->execute_query('SELECT COALESCE(sum(impression),0) as imp,COALESCE(sum(click),0) as clk,COALESCE(sum(money_spent),0) as spent,time' . $cpmquerystring . ' ' . $htmlquerystring . ' ' . $cpaquerystring . ' FROM ' . $table . ' WHERE time >=? GROUP BY time ORDER BY time ASC', [$start]);
- $today_array = [];
- while ($tdy = $row_res->fetch_assoc()) {
- $key = $tdy['time'];
- $today_array[$key]['impression'] = $tdy['imp'];
- $today_array[$key]['click'] = $tdy['clk'];
- $today_array[$key]['money_spent'] = $tdy['spent'];
- if ($cpm_addon_enabled == 1) {
- $today_array[$key]['cpm_impression'] = $tdy['cpmimp'];
- $today_array[$key]['cpm_spend'] = $tdy['cpmspend'];
- $today_array[$key]['cpm_click'] = $tdy['cpmclick'];
- }
- if ($cpv_addon_enabled == 1) {
- $today_array[$key]['cpv_impression'] = $tdy['cpvimp'];
- $today_array[$key]['cpv_spend'] = $tdy['cpvspend'];
- $today_array[$key]['cpv_click'] = $tdy['cpvclick'];
- }
- if ($html_addon_enabled == 1) {
- $today_array[$key]['html_impression'] = $tdy['htmlimp'];
- $today_array[$key]['html_profit'] = $tdy['htmlprofit'];
- }
- if ($cpa_addon_enabled == 1) {
- $today_array[$key]['cpa_impression'] = $tdy['cpaimp'];
- $today_array[$key]['cpa_click'] = $tdy['cpaclick'];
- $today_array[$key]['cpa_conversion'] = $tdy['cpaconversion'];
- $today_array[$key]['cpa_spend'] = $tdy['cpaspend'];
- $today_array[$key]['cpa_profit'] = $tdy['cpaprofit'];
- }
- if ($affiliate_addon_enabled == 1) {
- $today_array[$key]['affiliate_click'] = $tdy['affiliateclick'];
- $today_array[$key]['affiliate_conversion'] = $tdy['affiliateconversion'];
- $today_array[$key]['affiliate_spend'] = $tdy['affiliatespend'];
- $today_array[$key]['affiliate_profit'] = $tdy['affiliateprofit'];
- }
- if ($pop_addon_enabled == 1) {
- $today_array[$key]['pop_impression'] = $tdy['popimp'];
- $today_array[$key]['pop_spend'] = $tdy['popspend'];
- }
- }
- }
- else if (($time_flag == 4) || ($time_flag == 5)) {
- $row_res = $db->execute_query('SELECT COALESCE(sum(x.imp),0) as imp,COALESCE(sum(x.clk),0) as clk,COALESCE(sum(x.spent),0) as spent,time' . $cpmquerystring1 . ' ' . $htmlquerystring1 . ' ' . $cpaquerystring1 . ' FROM' . "\r\n\t\t\t" . '((SELECT COALESCE(sum(impression),0) as imp,COALESCE(sum(click),0) as clk,COALESCE(sum(money_spent),0) as spent,time' . $cpmquerystring . ' ' . $htmlquerystring . ' ' . $cpaquerystring . ' FROM ' . $table . ' WHERE time >=? GROUP BY time ORDER BY time ASC)' . "\r\n\t\t\t" . 'UNION (SELECT COALESCE(sum(impression),0) as imp,COALESCE(sum(click),0) as clk,COALESCE(sum(money_spent),0) as spent,time' . $cpmquerystring . ' ' . $htmlquerystring . ' ' . $cpaquerystring . ' FROM ' . $table1 . ' WHERE time >=? GROUP BY time ORDER BY time ASC)) as x' . "\r\n\t\t\t" . 'GROUP BY x.time ORDER BY x.time ASC', [$start, $start_temp]);
- $today_array = [];
- while ($tdy = $row_res->fetch_assoc()) {
- $key = $tdy['time'];
- $today_array[$key]['impression'] = $tdy['imp'];
- $today_array[$key]['click'] = $tdy['clk'];
- $today_array[$key]['money_spent'] = $tdy['spent'];
- if ($cpm_addon_enabled == 1) {
- $today_array[$key]['cpm_impression'] = $tdy['cpmimp'];
- $today_array[$key]['cpm_spend'] = $tdy['cpmspend'];
- $today_array[$key]['cpm_click'] = $tdy['cpmclick'];
- }
- if ($cpv_addon_enabled == 1) {
- $today_array[$key]['cpv_impression'] = $tdy['cpvimp'];
- $today_array[$key]['cpv_spend'] = $tdy['cpvspend'];
- $today_array[$key]['cpv_click'] = $tdy['cpvclick'];
- }
- if ($html_addon_enabled == 1) {
- $today_array[$key]['html_impression'] = $tdy['htmlimp'];
- $today_array[$key]['html_profit'] = $tdy['htmlprofit'];
- }
- if ($cpa_addon_enabled == 1) {
- $today_array[$key]['cpa_impression'] = $tdy['cpaimp'];
- $today_array[$key]['cpa_click'] = $tdy['cpaclick'];
- $today_array[$key]['cpa_conversion'] = $tdy['cpaconversion'];
- $today_array[$key]['cpa_spend'] = $tdy['cpaspend'];
- $today_array[$key]['cpa_profit'] = $tdy['cpaprofit'];
- }
- if ($affiliate_addon_enabled == 1) {
- $today_array[$key]['affiliate_click'] = $tdy['affiliateclick'];
- $today_array[$key]['affiliate_conversion'] = $tdy['affiliateconversion'];
- $today_array[$key]['affiliate_spend'] = $tdy['affiliatespend'];
- $today_array[$key]['affiliate_profit'] = $tdy['affiliateprofit'];
- }
- if ($pop_addon_enabled == 1) {
- $today_array[$key]['pop_impression'] = $tdy['popimp'];
- $today_array[$key]['pop_spend'] = $tdy['popspend'];
- }
- }
- }
- while ($start <= $current_time) {
- if (array_key_exists($start, $today_array)) {
- $data_array[$start]['impression'] = $today_array[$start]['impression'];
- $data_array[$start]['click'] = $today_array[$start]['click'];
- $data_array[$start]['money_spent'] = $today_array[$start]['money_spent'];
- if ($cpm_addon_enabled == 1) {
- $data_array[$start]['cpm_impression'] = $today_array[$start]['cpm_impression'];
- $data_array[$start]['cpm_spend'] = $today_array[$start]['cpm_spend'];
- $data_array[$start]['cpm_click'] = $today_array[$start]['cpm_click'];
- }
- if ($cpv_addon_enabled == 1) {
- $data_array[$start]['cpv_impression'] = $today_array[$start]['cpv_impression'];
- $data_array[$start]['cpv_spend'] = $today_array[$start]['cpv_spend'];
- $data_array[$start]['cpv_click'] = $today_array[$start]['cpv_click'];
- }
- if ($html_addon_enabled == 1) {
- $data_array[$start]['html_impression'] = $today_array[$start]['html_impression'];
- $data_array[$start]['html_profit'] = $today_array[$start]['html_profit'];
- }
- if ($cpa_addon_enabled == 1) {
- $data_array[$start]['cpa_impression'] = $today_array[$start]['cpa_impression'];
- $data_array[$start]['cpa_click'] = $today_array[$start]['cpa_click'];
- $data_array[$start]['cpa_conversion'] = $today_array[$start]['cpa_conversion'];
- $data_array[$start]['cpa_spend'] = $today_array[$start]['cpa_spend'];
- $data_array[$start]['cpa_profit'] = $today_array[$start]['cpa_profit'];
- }
- if ($affiliate_addon_enabled == 1) {
- $data_array[$start]['affiliate_click'] = $today_array[$start]['affiliate_click'];
- $data_array[$start]['affiliate_conversion'] = $today_array[$start]['affiliate_conversion'];
- $data_array[$start]['affiliate_spend'] = $today_array[$start]['affiliate_spend'];
- $data_array[$start]['affiliate_profit'] = $today_array[$start]['affiliate_profit'];
- }
- if ($pop_addon_enabled == 1) {
- $data_array[$start]['pop_impression'] = $today_array[$start]['pop_impression'];
- $data_array[$start]['pop_spend'] = $today_array[$start]['pop_spend'];
- }
- }
- else {
- $data_array[$start]['impression'] = 0;
- $data_array[$start]['click'] = 0;
- $data_array[$start]['money_spent'] = 0;
- if ($cpm_addon_enabled == 1) {
- $data_array[$start]['cpm_impression'] = 0;
- $data_array[$start]['cpm_spend'] = 0;
- $data_array[$start]['cpm_click'] = 0;
- }
- if ($cpv_addon_enabled == 1) {
- $data_array[$start]['cpv_impression'] = 0;
- $data_array[$start]['cpv_spend'] = 0;
- $data_array[$start]['cpv_click'] = 0;
- }
- if ($html_addon_enabled == 1) {
- $data_array[$start]['html_impression'] = 0;
- $data_array[$start]['html_profit'] = 0;
- }
- if ($cpa_addon_enabled == 1) {
- $data_array[$start]['cpa_impression'] = 0;
- $data_array[$start]['cpa_click'] = 0;
- $data_array[$start]['cpa_conversion'] = 0;
- $data_array[$start]['cpa_spend'] = 0;
- $data_array[$start]['cpa_profit'] = 0;
- }
- if ($affiliate_addon_enabled == 1) {
- $data_array[$start]['affiliate_click'] = 0;
- $data_array[$start]['affiliate_conversion'] = 0;
- $data_array[$start]['affiliate_spend'] = 0;
- $data_array[$start]['affiliate_profit'] = 0;
- }
- if ($pop_addon_enabled == 1) {
- $data_array[$start]['pop_impression'] = 0;
- $data_array[$start]['pop_spend'] = 0;
- }
- }
- if ($time_flag == 3) {
- $start = $this->get_nextday($start);
- continue;
- }
- if ($time_flag == 4) {
- $start = $this->get_nextmonth($start);
- continue;
- }
- if ($time_flag == 5) {
- $start = $this->get_nextyear($start);
- }
- }
- return $data_array;
- }
- public function get_publisher_timeperiod_statistics($time_flag = 1, $pid = -1, $bid = 0, $sid = 0)
- {
- $cpa_addon_enabled = $this->get_addon_status('cpa_enabled');
- $category_targeting_enabled = $this->get_addon_status('category-targeting_enabled');
- $cpm_addon_enabled = $this->get_addon_status('cpm_enabled');
- $html_addon_enabled = $this->get_addon_status('html_enabled');
- $pop_addon_enabled = $this->get_addon_status('pop-ads_enabled');
- $affiliate_addon_enabled = $this->get_addon_status('affiliate-ads_enabled');
- $cpv_addon_enabled = $this->get_addon_status('video-ads_enabled');
- if ($cpa_addon_enabled == 1) {
- $cpaquerystring = ' ,COALESCE(sum(cpa_impression),0) as cpaimp,COALESCE(sum(cpa_click),0) as cpaclick,COALESCE(sum(cpa_conversion),0) as cpaconversion,COALESCE(sum(cpa_spend),0) as cpaspend,COALESCE(sum(cpa_profit),0) as cpaprofit ';
- $cpaquerystring1 = ' ,COALESCE(sum(x.cpaimp),0) as cpaimp,COALESCE(sum(x.cpaclick),0) as cpaclick,COALESCE(sum(x.cpaconversion),0) as cpaconversion,COALESCE(sum(x.cpaspend),0) as cpaspend,COALESCE(sum(x.cpaprofit),0) as cpaprofit ';
- $cpaquerystring2 = ' ,COALESCE(sum(cpa_impression),0) as cpaimp ';
- }
- else {
- $cpaquerystring = '';
- $cpaquerystring1 = '';
- $cpaquerystring2 = '';
- }
- if ($affiliate_addon_enabled == 1) {
- $cpaquerystring .= ' ,COALESCE(sum(affiliate_click),0) as affiliateclick,COALESCE(sum(affiliate_conversion),0) as affiliateconversion,COALESCE(sum(affiliate_spend),0) as affiliatespend,COALESCE(sum(affiliate_profit),0) as affiliateprofit ';
- $cpaquerystring1 .= ' ,COALESCE(sum(x.affiliateclick),0) as affiliateclick,COALESCE(sum(x.affiliateconversion),0) as affiliateconversion,COALESCE(sum(x.affiliatespend),0) as affiliatespend,COALESCE(sum(x.affiliateprofit),0) as affiliateprofit ';
- }
- if ($cpm_addon_enabled == 1) {
- $cpmquerystring = ' ,COALESCE(sum(cpm_impression),0) as cpmimp,COALESCE(sum(cpm_profit),0) as cpmprofit,COALESCE(sum(cpm_spend),0) as cpmspend ';
- $cpmquerystring1 = ' ,COALESCE(sum(x.cpmimp),0) as cpmimp,COALESCE(sum(x.cpmprofit),0) as cpmprofit,COALESCE(sum(x.cpmspend),0) as cpmspend ';
- $cpmquerystring2 = ' ,COALESCE(sum(cpm_click),0) as cpmclick ';
- $cpmquerystring3 = ' ,COALESCE(sum(x.cpmclick),0) as cpmclick ';
- }
- else {
- $cpmquerystring = '';
- $cpmquerystring1 = '';
- .................................................................
- ..........................................
- ...............
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement