<?php 

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

$db = new database();


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

	$result = array();

	if ($action == 'pi') {
		# code...
		$fname = $_POST['fname'];
		$lname = $_POST['lname'];
		$useridpi = $_POST['useridpi'];
		$email = $_POST['email'];
		$phnumberpi = $_POST['phnumberpi'];
		$pcar = $_POST['pcar'];
		$uid = $_POST['uid'];

		$fullname = $fname." ".$lname;

		$update = "UPDATE users SET name = '$fullname', email = '$email', phone = '$phnumberpi', pcarrier = '$pcar', uid = '$useridpi' WHERE id = '$uid'";

		$userUpdate = $db->db->prepare($update);

		if ($userUpdate->execute()) {
			# code...
			$result = array('result'=>'success');
		}else{
			$result = array('result'=>'failed');
		}

		print_r(json_encode($result));

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

		$pass = $_POST['pass'];


		$sql = "UPDATE users SET password = '$pass' WHERE id = '$userId'";

		$stmtupdate = $db->db->prepare($sql);

		if ($stmtupdate->execute()) {
					# code...
			
			$result = array('result'=>'success');
		
		}else{

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

		print_r(json_encode($result));



	}elseif ($action == 'ug') {
		# code...
		$anngoal = $_POST['ag'];
		$dailygoal = $_POST['dg'];
		$monthlygoal = $_POST['mg'];
		$userId = $_POST['uid'];

		$sql2 = "UPDATE users SET daily_goal = '$dailygoal', monthly_goal = '$monthlygoal', annual_goal = '$anngoal' WHERE id = '$userId'";

		$stmtupdate = $db->db->prepare($sql2);

		if ($stmtupdate->execute()) {
					# code...
			
			$result = array('result'=>'success');
		
		}else{

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

		print_r(json_encode($result));



	}elseif ($action == 'smupdate') {
		# code...
		$startingMoney = $_POST['sm'];

		$startingMoney = floatval($startingMoney);

		$userId = $_POST['uid'];

		$stmtupdate = $db->db->prepare("UPDATE users SET starting_money = '$startingMoney' WHERE id = '$userId'");

		if ($stmtupdate->execute()) {
					# code...
			
			$result = array('result'=>'success');
		
		}else{

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

		print_r(json_encode($result));

	}
}

?>