| Current Path : /home/seto/tdsbs.com/v9/files/ |
| Current File : /home/seto/tdsbs.com/v9/files/source.php |
<?php
if(!defined('INDEX')){header('HTTP/1.1 403 Forbidden'); die('403 Forbidden');}
$se_label = 0;
if($q == 'sources' && empty($d)){
$db = new SQLite3($folder_log.'/'.$g_id.'.db');
$db->busyTimeout($timeout_2);
$db->exec('PRAGMA journal_mode = WAL;');
if(!empty($s_name)){
echo '<div class="align_center bold indt_10">'.$trans['group']['g2'].': '.$g_name.' | '.$trans['stream']['s1'].': '.$s_name.'</div>';
}
else{
echo '<div class="align_center bold indt_10">'.$trans['group']['g2'].': '.$g_name.'</div>';
}
echo '<div class="align_center h_auto indt_20 indb_10">';
echo '<table id="example" class="cell-border display compact responsive" width="100%" cellspacing="0">
<thead>
<tr>
<th data-priority="1"></th>';
foreach($col_source as $name => $v){
$v_ex = explode(':', $v);
if($v_ex[0] == 0){$dtclass = ' class="none"';}
if($v_ex[0] == 1){$dtclass = '';}
$dp = 'data-priority="'.$v_ex[1].'"';
echo "<th $dp$dtclass>$name</th>\n";
}
echo '</tr>
</thead>
<tfoot>
<tr>
<th data-priority="1"></th>';
foreach($col_source as $name => $v){
echo "<th>$name</th>\n";
}
echo '</tr>
</tfoot>
<tbody>';
$source_arr = array();
foreach($all_tables as $table_temp){
if(empty($s)){
$res = $db->query("SELECT * FROM '$table_temp' WHERE bot = '$empty';");
$st = '';
}
else{
$res = $db->query("SELECT * FROM '$table_temp' WHERE nstream = '$s_name' AND bot = '$empty';");
$st = "&s=$s";
}
while($array = $res->fetchArray(SQLITE3_ASSOC)){
$domain = trim($array['domain']);
if(!in_array($domain, $source_arr)){
$source_arr[$domain] = array(0,0,0,0,0,0,0,0);
}
}
}
foreach($all_tables as $table_temp){
foreach($source_arr as $domain => $v){
if(!empty($s)){
$query = "SELECT COUNT (*) FROM '$table_temp' WHERE domain = '$domain' AND nstream = '$s_name' AND bot = '$empty'";
}
else{
$query = "SELECT COUNT (*) FROM '$table_temp' WHERE domain = '$domain' AND bot = '$empty'";
}
if(!empty($s)){
$query_pb = "SELECT * FROM '$table_temp' WHERE domain = '$domain' AND nstream = '$s_name' AND bot = '$empty';";
}
else{
$query_pb = "SELECT * FROM '$table_temp' WHERE domain = '$domain' AND bot = '$empty';";
}
$res = $db->query("$query_pb;");
while($array = $res->fetchArray(SQLITE3_ASSOC)){
if($array['postback'] != $empty){
$source_arr[$domain][7] = $source_arr[$domain][7] + $array['postback'];
}
}
$source_arr[$domain][0] = $v[0] + $db->querySingle("$query;");
$source_arr[$domain][1] = $v[1] + $db->querySingle("$query AND uniq = 'yes';");
$source_arr[$domain][2] = $v[2] + $db->querySingle("$query AND se != '$empty' AND uniq = 'yes';");
$source_arr[$domain][3] = $v[3] + $db->querySingle("$query AND device = 'computer' AND uniq = 'yes';");
$source_arr[$domain][4] = $v[4] + $db->querySingle("$query AND device = 'tablet' AND uniq = 'yes';");
$source_arr[$domain][5] = $v[5] + $db->querySingle("$query AND device = 'phone' AND uniq = 'yes';");
$source_arr[$domain][6] = $v[6] + $db->querySingle("$query AND operator != '$empty' AND uniq = 'yes';");
}
}
foreach($source_arr as $domain => $v){
$sources_visitors = $v[0];
if($v[0] == 0){
$sources_visitors = $empty;
}
$sources_unique = $v[1];
if($v[1] == 0){
$sources_unique = $empty;
}
$sources_se = $v[2];
if($v[2] == 0){
$sources_se = $empty;
}
else{
$se_label = 1;
}
$sources_computers = $v[3];
if($v[3] == 0){
$sources_computers = $empty;
}
$sources_tablets = $v[4];
if($v[4] == 0){
$sources_tablets = $empty;
}
$sources_phones = $v[5];
if($v[5] == 0){
$sources_phones = $empty;
}
$sources_wap = $v[6];
if($v[6] == 0){
$sources_wap = $empty;
}
$sources_profit = $v[7];
if($v[7] == 0){
$sources_profit = $empty;
}
$td = '<td></td>
<td class="stdicon"><a class="sicon" title="View" target="_blank" href="http://'.$domain.'">✓</a><a class="sicon" title="Log" href="'.$admin_page.'?q=log'.$ar.'&col=domain&find='.$domain.'">☷</a><a class="sicon" title="Postback" href="'.$admin_page.'?q=pb'.$ar.'&d='.$domain.'">$</a><a class="sicon" href="'.$admin_page.'?q=d_del_log'.$ar.'&d='.$domain.'" title="Delete domain log" onclick="return confirm(\'Delete domain log ?\') ? true : false;">☓</a><a class="sicon" title="Config" href="'.$admin_page.'?q=conf&g='.$g_id.$st.'&d='.$domain.'">✎</a><a class="slink" href="'.$admin_page.'?q=sources'.$ar.'&d='.$domain.'">'.$domain.'</a></td>
<td>'.$sources_visitors.'</td>
<td>'.$sources_unique.'</td>
<td>'.$sources_se.'</td>
<td>'.$sources_wap.'</td>
<td>'.$sources_computers.'</td>
<td>'.$sources_tablets.'</td>
<td>'.$sources_phones.'</td>
<td>'.$sources_profit.'</td>';
echo '<tr align="center">'.$td.'</tr>';
}
echo '</tbody>
</table>';
$db->close();
$sort = 3;
if($se_label == 1){
$sort = 4;
}
echo '<script type="text/javascript" class="init">
$(document).ready(function(){
var t = $("#example").DataTable({
"paging":true,
"searching":false,
"info":false,
"ordering":true,
"order":[['.$sort.', "desc"]],
"lengthMenu":[[50, 100, 200, 300, 500, 1000 -1], [50, 100, 200, 300, 500, 1000, "All"]],
"pageLength":50,
"language":{
"thousands":"",
"paginate":{
"first":"First",
"last":"Last",
"next":"Next",
"previous":"Prev"
},
},
},
{
"columnDefs":[{
"searchable":false,
"orderable":false,
"targets":0
}],
"order":[[1, "asc"]]
});
t.on("order.dt search.dt", function(){
t.column(0, {search:"applied", order:"applied"}).nodes().each(function(cell, i){
cell.innerHTML = i+1;
});
}).draw();
});
</script>
</div>';
}
if($q == 'sources' && !empty($d)){
$ch_view = $ch_pb_view = 0;
$db = new SQLite3($folder_log.'/'.$g_id.'.db');
$db->busyTimeout($timeout_2);
$db->exec('PRAGMA journal_mode = WAL;');
$dt = '';
$lp = $period_log;
while(true){
$table_temp = strtotime(date('Y-m-d', strtotime('-'.$lp.' day')));
if($db->querySingle("SELECT name FROM sqlite_master WHERE type = 'table' AND name = '$table_temp';")){
$dt = date('Y-m-d', $table_temp);
$dt = explode('-', $dt);
if(!empty($dt[2])){
$dt = $dt[2];
}
else{
$dt = date('d', strtotime('-'.$lp.' day'));
}
if(!empty($s)){
$query = "SELECT COUNT (*) FROM '$table_temp' WHERE domain = '$d' AND nstream = '$s_name' AND bot = '$empty'";
}
else{
$query = "SELECT COUNT (*) FROM '$table_temp' WHERE domain = '$d' AND bot = '$empty'";
}
$ch_visitors = $db->querySingle("$query;");
$ch_hosts = $db->querySingle("$query AND uniq = 'yes';");
$ch_wap = $db->querySingle("$query AND operator != '$empty' AND uniq = 'yes';");
if($ch_visitors != 0){
$ch_view = 1;
}
if($chart_bots == 1){
if(!empty($s)){
$ch_bots = $db->querySingle("SELECT COUNT (*) FROM '$table_temp' WHERE domain = '$d' AND nstream = '$s_name' AND bot != '$empty' AND uniq = 'yes';");
}
else{
$ch_bots = $db->querySingle("SELECT COUNT (*) FROM '$table_temp' WHERE domain = '$d' AND bot != '$empty' AND uniq = 'yes';");
}
}
else{
$ch_bots = 0;
}
if(empty($dg_stats)){
$dg_stats = '[\''.$dt.'\','.$ch_visitors.','.$ch_hosts.','.$ch_wap.','.$ch_bots.']';
}
else{
$dg_stats = $dg_stats.',[\''.$dt.'\','.$ch_visitors.','.$ch_hosts.','.$ch_wap.','.$ch_bots.']';
}
if($charts_source['se'] == 1){
$ch_google = $db->querySingle("$query AND se = 'google' AND uniq = 'yes';");
$ch_yandex = $db->querySingle("$query AND se = 'yandex' AND uniq = 'yes';");
$ch_mail = $db->querySingle("$query AND se = 'mail' AND uniq = 'yes';");
$ch_yahoo = $db->querySingle("$query AND se = 'yahoo' AND uniq = 'yes';");
$ch_bing = $db->querySingle("$query AND se = 'bing' AND uniq = 'yes';");
$ch_baidu = $db->querySingle("$query AND se = 'baidu' AND uniq = 'yes';");
if($ch_google != 0 || $ch_yandex != 0 || $ch_mail != 0 || $ch_yahoo != 0 || $ch_bing != 0 || $ch_baidu != 0){
$ch_se_view = 1;
}
if(empty($dg_se)){
$dg_se = '[\''.$dt.'\','.$ch_google.','.$ch_yandex.','.$ch_mail.','.$ch_yahoo.','.$ch_bing.','.$ch_baidu.']';
}
else{
$dg_se = $dg_se.',[\''.$dt.'\','.$ch_google.','.$ch_yandex.','.$ch_mail.','.$ch_yahoo.','.$ch_bing.','.$ch_baidu.']';
}
}
}
else{
if(empty($dg_stats)){
$dg_stats = '[\''.date('d', strtotime('-'.$lp.' day')).'\',0,0,0,0]';
}
else{
$dg_stats = $dg_stats.',[\''.date('d', strtotime('-'.$lp.' day')).'\',0,0,0,0]';
}
if(empty($dg_se)){
$dg_se = '[\''.date('d', strtotime('-'.$lp.' day')).'\',0,0,0,0,0,0]';
}
else{
$dg_se = $dg_se.',[\''.date('d', strtotime('-'.$lp.' day')).'\',0,0,0,0,0,0]';
}
}
if($lp == 0){
break;
}
$lp--;
}
if($charts_source['unique'] == 1){
$table = strtotime($date);
$ch_today = array();
$date_today = $ch_time = date('Y-m-d', $table);
if($db->querySingle("SELECT name FROM sqlite_master WHERE type = 'table' AND name = '$table';")){
$ch_start = $table;
$ch_time = '';
if(!empty($s)){
$query = "SELECT COUNT (*) FROM '$table' WHERE domain = '$d' AND nstream = '$s_name' AND bot = '$empty'";
}
else{
$query = "SELECT COUNT (*) FROM '$table' WHERE domain = '$d' AND bot = '$empty'";
}
while($ch_time != '00'){
$ch_end = $ch_start + 3600;
$ch_time = date('H', $ch_end);
$ch_hosts_today = $db->querySingle("$query AND uniq = 'yes' AND strtotime >= $ch_start AND strtotime < $ch_end;");
$ch_today[$ch_time] = $ch_hosts_today;
$ch_start = $ch_end;
if($ch_hosts_today != 0){
$ch_unique_view = 1;
}
}
}
$ch_yesterday = array();
$table_yesterday = $table - 86400;
$date_yesterday = $ch_time = date('Y-m-d', $table_yesterday);
if($db->querySingle("SELECT name FROM sqlite_master WHERE type = 'table' AND name = '$table_yesterday';")){
$ch_start = $table_yesterday;
$ch_time = '';
if(!empty($s)){
$query = "SELECT COUNT (*) FROM '$table_yesterday' WHERE domain = '$d' AND nstream = '$s_name' AND bot = '$empty'";
}
else{
$query = "SELECT COUNT (*) FROM '$table_yesterday' WHERE domain = '$d' AND bot = '$empty'";
}
while($ch_time != '00'){
$ch_end = $ch_start + 3600;
$ch_time = date('H', $ch_end);
$ch_hosts_yesterday = $db->querySingle("$query AND uniq = 'yes' AND strtotime >= $ch_start AND strtotime < $ch_end;");
$ch_yesterday[$ch_time] = $ch_hosts_yesterday;
$ch_start = $ch_end;
if($ch_hosts_yesterday != 0){
$ch_unique_view = 1;
}
}
}
$ch_t = array('01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','00');
$h = date('H');
foreach($ch_t as $v){
if(!empty($ch_today[$v]) || ($table != strtotime(date('Y-m-d')) && isset($ch_today[$v]))){
$x = $ch_today[$v];
$x = ",$x";
}
else{
if($v == '00' || $h < $v){
$x = ',null';
}
else{
$x = ',0';
}
}
if(!empty($ch_yesterday[$v])){
$y = $ch_yesterday[$v];
$y = ",$y";
}
else{
$y = ',0';
}
if(empty($dg_unique)){
$dg_unique = '[\''.$v.'\''.$y.$x.']';
}
else{
$dg_unique = $dg_unique.',[\''.$v.'\''.$y.$x.']';
}
}
}
if($charts_source['postback'] == 1 && $ch_view == 1){
$db_pb = new SQLite3($folder_log.'/postback.db');
$db_pb->busyTimeout($timeout_2);
$db_pb->exec('PRAGMA journal_mode = WAL;');
$dx = '';
$lp = $period_log;
while(true){
$dx = date('d', strtotime('-'.$lp.' day'));
$date_pb = date('Y-m-d', strtotime('-'.$lp.' day'));
if(!isset($stat_pb[$dx])){
$stat_pb[$dx] = 0;
}
$profit = 0;
$res = $db_pb->query("SELECT * FROM 'postback' WHERE domain = '$d' AND date = '$date_pb';");
while($array = $res->fetchArray(SQLITE3_ASSOC)){
if(is_numeric($array['profit'])){
$profit = $profit + $array['profit'];
}
if($profit != 0){
$ch_pb_view = 1;
}
}
$stat_pb[$dx] = $profit;
if($lp == 0){
break;
}
$lp--;
}
$db_pb->close();
foreach($stat_pb as $stat_date => $stat_data){
if(empty($dg_pb)){
$dg_pb = '[\''.$stat_date.'\','.$stat_data.']';
}
else{
$dg_pb = $dg_pb.',[\''.$stat_date.'\','.$stat_data.']';
}
}
}
echo '<div class="align_center h_auto indt_10">';
if(!empty($s_name)){
echo '<div class="align_center bold indt_10">'.$trans['group']['g2'].': '.$g_name.' | '.$trans['stream']['s1'].': '.$s_name.' | Domain: '.$d.'</div>';
$ch_se_view = 0;
}
else{
echo '<div class="align_center bold indt_10">'.$trans['group']['g2'].': '.$g_name.' | Domain: '.$d.'</div>';
}
echo '<div id="curve_chart_stats" class="chart indt_20"></div>';
if($charts_source['se'] == 1 && $ch_se_view == 1){
echo '<div id="curve_chart_se" class="chart indt_10"></div>';
}
if($charts_source['unique'] == 1 && $ch_unique_view == 1){
echo '<div id="curve_chart_unique" class="chart indt_20"></div>';
}
if($charts_source['postback'] == 1 && $ch_pb_view == 1 && $ch_view == 1){
echo '<div id="curve_chart_pb" class="chart indt_10"></div>';
}
echo '<div class="indt_20 indb_10">
<table id="example" class="cell-border display compact responsive" width="100%" cellspacing="0">
<thead>
<tr>
<th data-priority="1"></th>';
foreach($col_country as $name => $v){
$v_ex = explode(':', $v);
if($v_ex[0] == 0){$dtclass = ' class="none"';}
if($v_ex[0] == 1){$dtclass = '';}
$dp = 'data-priority="'.$v_ex[1].'"';
echo "<th $dp$dtclass>$name</th>\n";
}
echo '</tr>
</thead>
<tfoot>
<tr>
<th data-priority="1"></th>';
foreach($col_country as $name => $v){
echo "<th>$name</th>\n";
}
echo '</tr>
</tfoot>
<tbody>';
if(!empty($all_tables)){
$country_res = array();
foreach($country_arr as $country){
$country_res[$country] = array(0,0,0);
}
foreach($all_tables as $table_temp){
foreach($country_arr as $country){
if(!empty($s)){
$query = "SELECT COUNT (*) FROM '$table_temp' WHERE country = '$country' AND domain = '$d' AND nstream = '$s_name' AND bot = '$empty'";
}
else{
$query = "SELECT COUNT (*) FROM '$table_temp' WHERE country = '$country' AND domain = '$d' AND bot = '$empty'";
}
$visitors = $db->querySingle("$query;");
$uniq = $db->querySingle("$query AND uniq = 'yes';");
$se = $db->querySingle("$query AND se != '$empty' AND uniq = 'yes';");
$country_res[$country][0] = $country_res[$country][0] + $visitors;
$country_res[$country][1] = $country_res[$country][1] + $uniq;
$country_res[$country][2] = $country_res[$country][2] + $se;
}
}
foreach($country_res as $country => $v){
if(!empty($v[0]) || !empty($v[1]) || !empty($v[2])){
if($v[0] == 0){
$countries_visitors = $empty;
}
else{
$countries_visitors = $v[0];
}
if($v[1] == 0){
$countries_uniq = $empty;
}
else{
$countries_uniq = $v[1];
}
if($v[2] == 0){
$countries_se = $empty;
}
else{
$countries_se = $v[2];
$se_label = 1;
}
country_names($country);
if($country != $empty){
$country = '<span class="flag"><img src="files/img/flags/'.$country.'.png"></span><span class="flag"> '.strtoupper($country).'</span>';
}
$td = '<td></td>
<td title="'.$cn.'">'.$country.'</td>
<td>'.$countries_visitors.'</td>
<td>'.$countries_uniq.'</td>
<td>'.$countries_se.'</td>';
echo '<tr align="center">'.$td.'</tr>';
}
}
}
$db->close();
$sort = 3;
if($se_label == 1){
$sort = 4;
}
echo '</tbody>
</table>
</div>
<script type="text/javascript" class="init">
$(document).ready(function(){
var t = $("#example").DataTable({
"paging":true,
"searching":false,
"info":false,
"ordering":true,
"order":[['.$sort.', "desc"]],
"lengthMenu":[[50, 100, -1], [50, 100, "All"]],
"pageLength":50,
"language":{
"thousands":"",
"paginate":{
"first":"First",
"last":"Last",
"next":"Next",
"previous":"Prev"
},
},
},
{
"columnDefs":[{
"searchable":false,
"orderable":false,
"targets":0
}],
"order":[[1, "asc"]]
});
t.on("order.dt search.dt", function(){
t.column(0, {search:"applied", order:"applied"}).nodes().each(function(cell, i){
cell.innerHTML = i+1;
});
}).draw();
});
</script>
</div>';
}
?>