<?php

	error_reporting(E_ALL);
	include_once("../classes/database.class.php");

	// Setting up some basic classes
	$db = new database();
	




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

		if ($action == 'removeAlert') {
			# code...

			$id = $_POST['id'];

			$stmt = $db->db->prepare("DELETE FROM invataTracker WHERE id = '$id'");

			$array = array();

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

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

			print_r(json_encode($array));




		}elseif ($action == 'insertTracker') {
			# code...


			$email = filter_input(INPUT_POST, 'tracker_email');
			$symbol = filter_input(INPUT_POST, 'tracker_symbol');
			$price = filter_input(INPUT_POST, 'tracker_price');
			$length = filter_input(INPUT_POST, 'tracker_length');
			$userUId = filter_input(INPUT_COOKIE, 'uid');

			$stmt = $db->db->prepare("INSERT INTO invataTracker (symbol, email, price, length,  user_id) VALUES (?, ?, ?, ?, ?)");
			
			$array = array();

			if ($stmt->execute(array($symbol, $email, $price, $length, $userUId))) {
				# code...
				
				$array = array('result'=>'success');				
			
			}else{

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

			print_r(json_encode($array));

			
		}elseif ($action == "modifytrackeraction") {
			# code...

			$email = filter_input(INPUT_POST, 'tracker_email_modify');
			$symbol = filter_input(INPUT_POST, 'tracker_symbol_modify');
			$price = filter_input(INPUT_POST, 'tracker_price_modify');
			$length = filter_input(INPUT_POST, 'tracker_length_modify');
			$id = $_POST['tid'];


			$stmt = $db->db->prepare("UPDATE invataTracker SET symbol = '$symbol', email = '$email', price = '$price', length = '$length' WHERE id = '$id'");


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

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

			print_r(json_encode($array));



		}
	}







?>