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

	switch ($act){
		case 'update_sID_reOrder':
			$index=$_GET['index'];
			$field=$_GET['field'];
			$value=$_GET['value'];
			update_sID_reOrder($index,$field,$value);
			break;
		case 'update_sField':
			$index=$_GET['index'];
			$field=$_GET['field'];
			$value=$_GET['value'];
			update_sField($index,$field,$value);
			break;
		case 'update_sUrl':
			$sid=$_GET['sid'];
			$sUrl=$_GET['sUrl'];
			update_sUrl($sid,$sUrl);
			break;
		case 'update_exempt':
			$index=$_GET['index'];
			$statVal=$_GET['statVal'];
			update_exempt($index,$statVal);
			break;
	}


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

			$empty = 0;
			$emptyNew = -1;

			// Set ID to NULL
			$result = $conn->query("UPDATE survey SET order_".$field."='".$empty."' WHERE order_id='".$index."'");
			$result = $conn->query("UPDATE survey SET order_".$field."='".$emptyNew."' WHERE order_id='".$value."'");

			// Set ID to new
			$result = $conn->query("UPDATE survey SET order_".$field."='".$value."' WHERE order_id='".$empty."'");

			// Set new ID to NULL
			$result = $conn->query("UPDATE survey SET order_".$field."='".$index."' WHERE order_id='".$emptyNew."'");

		$conn->close();
	}

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

			$result = $conn->query("UPDATE survey SET survey_".$field."='".$value."' WHERE order_id='".$index."'");

		$conn->close();
	}

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

			$result = $conn->query("UPDATE survey SET survey_url='".$sUrl."' WHERE order_id='".$sid."'");

		$conn->close();
	}

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

			if ( $conn->query("UPDATE survey SET survey_exempt='".$statVal."' WHERE survey_id='".$index."'") === true){
				echo 1;
			}

		$conn->close();
	}

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

	// 		$empty = 0;
	// 		$emptyNew = -1;

	// 		// Set ID to NULL
	// 		$result = $conn->query("UPDATE survey SET order_".$field."='".$empty."' WHERE order_id='".$index."'");
	// 		$result = $conn->query("UPDATE survey SET order_".$field."='".$emptyNew."' WHERE order_id='".$value."'");

	// 		// Set ID to new
	// 		$result = $conn->query("UPDATE survey SET order_".$field."='".$value."' WHERE order_id='".$empty."'");

	// 		// Set new ID to NULL
	// 		$result = $conn->query("UPDATE survey SET order_".$field."='".$index."' WHERE order_id='".$emptyNew."'");

	// 	$conn->close();
	// }
?>