<?php 
include_once('../classes/database.class.php');

$db = new database();

if (isset($_POST['action'])) {
	# code...
	$action = $_POST['action'];

	if ($action == "algo") {
		# code...	
		$uid = $_POST['uid'];

		$vl = $_POST['vl'];

		$result = array();

		$checkExist = $db->db->prepare("SELECT *, count(id) AS total FROM algovalues WHERE userid = '$uid'");
		$checkExist->execute();
		$checkExistVal = $checkExist->fetch(PDO::FETCH_OBJ);

		if ($checkExistVal->total >= 1) {
			# code...
			if ($vl == "auto") {
				# code...
				$update = $db->db->prepare("UPDATE algovalues SET man_auto = '1' WHERE userid = '$uid'");
				if ($update->execute()) {
					# code...
					$result = array('res'=>'success');
				}else{

					$result = array('res'=>'failed');
				}
			}


			if ($vl == "manual") {
				# code...
			$update = $db->db->prepare("UPDATE algovalues SET man_auto = '0' WHERE userid = '$uid'");
				if ($update->execute()) {
					# code...
					$result = array('res'=>'success');
				}else{

					$result = array('res'=>'failed');
				}
			}
		}

		print_r(json_encode($result));

	}elseif ($action == 'actionAccountType') {
		# code...
		$uid = $_POST['uid'];

		$type = $_POST['type'];

		$stmt = $db->db->prepare("UPDATE users SET acctype = '$type' WHERE id = '$uid'");
		$stmt->execute();
	}
}

?>