//pārbauda vai lietotājs eksistē
function checks(){
	fetch("sesion.php")
		.then((response) => response.json())
		.then((data) => {
			sessionStorage.setItem("uid",data["uid"]);
			if(sessionStorage.getItem("uid")==null||sessionStorage.getItem("uid")=="undefined"){
				document.location.href="login.html";
			}else{
				GetData();
			}
		}
	);
}

//savāc visus datus kas saistīti ar lietotāju
function GetData() {
	//alert(sessionStorage.getItem("uid"));
	fetch(
			`bkend.php?q=full&u=${sessionStorage.getItem("uid")}`
		)
		.then(
			response => response.json()
		)
		.then(
			function(table) {
				document.getElementById("logindata").innerHTML = "";
				for (let key in table) {
					document.getElementById("logindata").innerHTML +=
					`<tr>
					<td> <input type="hidden" value="${table[key].USER_ID}"> ${table[key].DATE}</td>
					<td> ${table[key].TASK}</td>
					<td> <input type="button" value="delete" onclick="del(${table[key].ID})"><?td>
					</tr>`
				}
			}
		);
}
/*
function del(ID){
	fetch(`bkend.php?d=del&id=${ID}`)
	window.location.reload();
}

function add(){
	let nt = document.getElementById("ntask").value;
	fetch(`bkend.php?d=add&name=${nt}&uid=${sessionStorage.getItem("uid")}`);
	window.location.reload();
}
*/