File "update_ui_tables.php"

Full path: /home/mysamm/public_html/mysamm_login/update_ui_tables.php
File size: 6.67 B
MIME-type: text/x-php; charset=us-ascii
Charset: utf-8

Download   Open   Edit   Advanced Editor &nnbsp; Back

<?php

require_once "/home/mysamm/price_checker/lib/connections.php";
require_once "/home/mysamm/price_checker/lib/connections_master_2.php";
require_once "/home/mysamm/price_checker/lib/connections_master_multi.php";

if(isset($argv[1])){
	$user_deatails = $argv[1];
	$user_date_updats = json_decode($user_deatails, true);

	$map_break_table = $user_date_updats['map_break_table'];
	$server_name = $user_date_updats['server_name'];
	$group_id = $user_date_updats['group_id'];
	$user_id = $user_date_updats['user_id'];
	$map_break_crawling_histories = $user_date_updats['map_break_crawling_histories'];
	$map_break_amazon_histories = $user_date_updats['map_break_amazon_histories'];
	$map_break_unmatched_histories = $user_date_updats['map_break_unmatched_histories'];
	$curren_crawler_date = $user_date_updats['curren_crawler_date'];
	
	if($server_name == 2){
		if($group_id == 8){
			$dbCon = new ConnectionMasterMulti();
		}else{
			$dbCon = new ConnectionMaster2();
		}
	}else{
		$dbCon = new Connection();
	}
	
	$total_matched_mapbreak = $dbCon->QueryCount("SELECT * FROM $map_break_table where created='$curren_crawler_date' AND is_matched=1 AND unwanted_product_reports=0");
	
	$total_un_matched_mapbreak = $dbCon->QueryCount("SELECT * FROM $map_break_table where created='$curren_crawler_date' AND is_matched=0 AND unwanted_product_reports=0");
	
	$total_matched_account = $dbCon->Query("SELECT account_id, count(*) as map_break FROM $map_break_table where created='$curren_crawler_date' AND is_matched=1 AND unwanted_product_reports=0 group by account_id");
	
	$total_matched_account_amazon = $dbCon->Query("SELECT account_id, count(*) as map_break FROM $map_break_table where created='$curren_crawler_date' AND is_matched=1 AND unwanted_product_reports=0 AND crawler_id = 4 group by account_id");
	
	$total_unmatched_seller = $dbCon->Query("SELECT product_seller, count(*) as map_break FROM $map_break_table where created='$curren_crawler_date' AND is_matched=0 AND unwanted_product_reports=0 group by product_seller");
	
	
	//--------UPDATE AMAZON History------------//
	
	$dbCon->execute("UPDATE $map_break_amazon_histories SET is_map_breaker = 0, below_map_count = 0 where crawl_date='$curren_crawler_date'");
	
	
	
	foreach($total_matched_account_amazon as $row){
		$account_id = $row['account_id'];
		$map_break = $row['map_break'];
		$is_break = 0;
		if($map_break > 0){
			$is_break = 1;
		}
		
		$dbCon->execute("UPDATE $map_break_amazon_histories SET is_map_breaker = '$is_break', below_map_count = '$map_break' where account_id = '$account_id' AND crawl_date='$curren_crawler_date'");
	}
	
	
	//--------UPDATE Crawling History------------//
	
	$dbCon->execute("UPDATE $map_break_crawling_histories SET is_map_breaker = 0, below_map_count = 0 where crawl_date='$curren_crawler_date'");
	
	$dbCon->execute("UPDATE new_dashboard_reports SET curr_below_map = '0' where curr_crawl_date = '$curren_crawler_date' AND user_id = '$user_id'");
	
	foreach($total_matched_account as $row){
		$account_id = $row['account_id'];
		$map_break = $row['map_break'];
		$is_break = 0;
		if($map_break > 0){
			$is_break = 1;
			$account_id = $dbCon->real_escape_string($account_id);
			$dbCon->execute("UPDATE $map_break_crawling_histories SET is_map_breaker = '$is_break', below_map_count = '$map_break' where account_id = '$account_id' AND crawl_date='$curren_crawler_date'");
		
			$dbCon->execute("UPDATE new_dashboard_reports SET curr_below_map = '$map_break' where account_number = '$account_id' AND curr_crawl_date = '$curren_crawler_date' AND user_id = '$user_id'");
		}
		
		
		
		
	}
	
	//-----UPDATE UNMATCHED-------HISTORY--------//
	
	$dbCon->execute("UPDATE $map_break_unmatched_histories SET is_map_breaker = 0, below_map_count = 0 where crawl_date='$curren_crawler_date'");
	
	$dbCon->execute("UPDATE unmatched_accounts SET curr_below_map = '0' where curr_crawl_date = '$curren_crawler_date' AND user_id = '$user_id'");
	foreach($total_unmatched_seller as $row){
		$product_seller = $row['product_seller'];
		$map_break = $row['map_break'];
		$is_break = 0;
		if($map_break > 0){
			
		   $is_break = 1;
		   
		   $product_seller = $dbCon->real_escape_string($product_seller);
		   
		   $dbCon->execute("UPDATE $map_break_unmatched_histories SET is_map_breaker = '$is_break', below_map_count = '$map_break' where product_seller = '$product_seller' AND crawl_date='$curren_crawler_date'");
		
		   $dbCon->execute("UPDATE unmatched_accounts SET curr_below_map = '$map_break' where user_id = '$user_id' AND curr_crawl_date = '$curren_crawler_date' AND product_seller = '$product_seller'");
		}
	}
	
	//----------UPDATE dashboard account_dashboards-------//
	
	$top_matched_Q = $dbCon->Query("SELECT display_title, curr_below_map FROM new_dashboard_reports where curr_crawl_date = '$curren_crawler_date' AND user_id = '$user_id' order by curr_below_map DESC limit 5");
	$top_matched = array();
	foreach($top_matched_Q as $mrow){
		$display_title = $mrow['display_title'];
		$curr_below_map = $mrow['curr_below_map'];
		$top_matched[$display_title] = $curr_below_map;
	}
	
	$top_matched_str = json_encode($top_matched, true);
	
	$top_unmatched_Q = $dbCon->Query("SELECT product_seller,curr_below_map  FROM unmatched_accounts where curr_crawl_date = '$curren_crawler_date' AND user_id = '$user_id' group by product_seller order by curr_below_map DESC limit 5");
	
	$top_unmatched = array();
	foreach($top_unmatched_Q as $mrow){
		$product_seller = $mrow['product_seller'];
		$curr_below_map = $mrow['curr_below_map'];
		$top_unmatched[$product_seller] = $curr_below_map;
	}
	
	//print_r($top_unmatched);
	$top_unmatched_str = json_encode($top_unmatched, true);
	
	
	$get_prev_map = $dbCon->Query("SELECT graph_map_breaks FROM account_dashboards where user_id = '$user_id'");
	$map_break_graph = array();
	$map_break_array = array();
	$map_break_array_new[$curren_crawler_date] = $total_matched_mapbreak;
	foreach($get_prev_map as $mprow){
		$map_break_json = $mprow['graph_map_breaks'];
		$map_break_array = json_decode($map_break_json, true);
		unset($map_break_array[$curren_crawler_date]);
	}
	
	$map_break_graph = array_merge($map_break_array_new, $map_break_array);
	
	$map_break_graph_str = json_encode($map_break_graph, true);
	$map_break_graph_str = $dbCon->real_escape_string($map_break_graph_str);
	$top_matched_str = $dbCon->real_escape_string($top_matched_str);
	$top_unmatched_str = $dbCon->real_escape_string($top_unmatched_str);
	
	$dbCon->execute("UPDATE account_dashboards SET curr_matched_product_below_map='$total_matched_mapbreak', curr_unmatched_product_below_map = '$total_un_matched_mapbreak', top_unmatched_map_breakers='$top_unmatched_str', top_matched_map_breakers='$top_matched_str', graph_map_breaks='$map_break_graph_str' where user_id = '$user_id'");
	
	print "update_done\n";
}



?>