<?php
	$act=$_GET['act'];

	switch ($act){
		case 'update_sField':
			$index=$_GET['index'];
			$field=$_GET['field'];
			$value=$_GET['value'];
			update_sField($index,$field,$value);
			break;
		case 'update_sName':
			$sid=$_GET['sid'];
			$sName=$_GET['sName'];
			update_sName($sid,$sName);
			break;
		case 'update_sUrl':
			$sid=$_GET['sid'];
			$sUrl=$_GET['sUrl'];
			update_sUrl($sid,$sUrl);
			break;
		case 'update_active':
			$sid=$_GET['sid'];
			$sUrl=$_GET['sActive'];
			update_Active($sid,$sUrl);
			break;
	}


	function update_sField($index,$field,$value){
		include($_SERVER['DOCUMENT_ROOT'] ."/_ps2020/config/connect.php");

			if ($field == 'name'){
				$result = $conn->query("UPDATE user_account SET username = '".$value."' WHERE user_id = '".$index."'");
			}

			if ($field == 'email'){
				$result = $conn->query("UPDATE user_account SET email = '".$value."' WHERE user_id = '".$index."'");
			}

		$conn->close();
	}

	function update_sName($sid,$sName){
		include($_SERVER['DOCUMENT_ROOT'] ."/_ps2020/config/connect.php");

			$result = $conn->query("UPDATE user_account SET username='".$sName."' WHERE user_id='".$sid."'");

		$conn->close();
	}

	function update_sUrl($sid,$sUrl){
		include($_SERVER['DOCUMENT_ROOT'] ."/_ps2020/config/connect.php");

		$password = hash('sha256', mysqli_real_escape_string($conn, $sUrl), false);	
		$result = $conn->query("UPDATE user_account SET password='".$password."' WHERE user_id='".$sid."'");

		$conn->close();
	}

	function update_Active($sid,$sUrl){
		include($_SERVER['DOCUMENT_ROOT'] ."/_ps2020/config/connect.php");

			$result = $conn->query("UPDATE user_account SET active=".$sUrl." WHERE user_id='".$sid."'");

		$conn->close();
	}
?>