<?php
require_once "get_data_class.php";

if($_REQUEST['api_name'] != ""){
	
	$ObjHandler = new ApiSdata();
	$api_name = $_REQUEST['api_name'];
	if($api_name == 'get_assigned_category'){
		$ObjHandler->get_assigned_category($_REQUEST);
	}else if($api_name == 'get_assigned_category_dev'){
		$ObjHandler->get_assigned_category_dev($_REQUEST);
	}else if($api_name == 'delete_changes'){
		$ObjHandler->discards_changes($_REQUEST);
	}else if($api_name == 'check_category'){
		$ObjHandler->check_category_is_running_status($_REQUEST);
	}else if($api_name == 'run_category_assignment'){
		$ObjHandler->run_category_assignment($_REQUEST);
	}else if($api_name == 'run_category_assignment_dev'){
		$ObjHandler->run_category_assignment_dev($_REQUEST);
	}else if($api_name == 'generate_content'){
		$post_id = $_REQUEST['post_report_id'];
		$collections = $_REQUEST['tbl'];
		$cmd = "nohup php content_generation.php {$post_id} {$collections}  >/dev/null 2>&1 &";
		shell_exec($cmd);
	}else if($api_name == 'generate_content_dev'){
		$post_id = $_REQUEST['post_report_id'];
		$collections = $_REQUEST['tbl'];
		$website_id = $_REQUEST['website_id'];
		$cmd = "nohup php content_generation_dev.php {$post_id} {$website_id} {$collections} >/dev/null 2>&1 &";
		shell_exec($cmd);  
	}else if($api_name == 'run_cron_watch_content'){
		$user_id = $_REQUEST['user_id'];
		$report_id = $_REQUEST['report_id'];
		$check_process = $_REQUEST['check_process'];
		$cmd = "nohup php /home/mysamm/openai/ContentGenerator/cron_watch_content.php {$user_id} {$report_id} {$check_process}  >/dev/null 2>&1 &";
		shell_exec($cmd);  
	}else if($api_name == 'check_api_key'){
		$data = $ObjHandler->check_api_key($_REQUEST); 
		echo json_encode(array("error"=>$data)); exit;
	}else if($api_name == 'save_prime'){
		
		$ObjHandler->save_category_as_prim($_REQUEST);
		
	}
}



?>