<?php

	// Check nonce
	PHPCUS_PARAM::CUS_REQUIRES_NONCE();
	
	// Check already authenticated
	PHPCUS_PARAM::CUS_REQUIRES_AUTHENTICATION();
	
	// Check array size
	PHPCUS_PARAM::CUS_DOES_NOT_SUPPORT_ARRAY();
	/*
	if
	(
			PHPRC_HTTP_PARAM::REF_ISSET_IN_ARRAY
			(
					[
							'PARAM_PROFILE_IMAGE'
					], True
			)
	)
	{
	*/
	
		Try
		{
			// Read params
			// ------------------------------------------------------------------
			$PARAM_PROFILE_IMAGE = PHPCUS_PARAM::CUS_READ_FILES('PARAM_PROFILE_IMAGE');
			
			// Execute Stored Procedure
			// ------------------------------------------------------------------
			Try
			{
				// Move uploaded image
				if(StrToUpper(PathInfo($PARAM_PROFILE_IMAGE['name'], PATHINFO_EXTENSION)) == "JPEG")
				{
					PHPRC_UPLOAD::REF_UPLOAD_TRANSACTION_MOVEFILE
					(
							$PARAM_PROFILE_IMAGE['tmp_name'],
							PHPSET::$ROOT . '/p/profile/' . PHPCUS_SP::$SESSION_AUTHENTICATED_ACCOUNT_ID . '.' .
							StrToUpper('JPG')
					);
				}
				else
				{
					PHPRC_UPLOAD::REF_UPLOAD_TRANSACTION_MOVEFILE
					(
							$PARAM_PROFILE_IMAGE['tmp_name'],
							PHPSET::$ROOT . '/Pages/profile/' . PHPCUS_SP::$SESSION_AUTHENTICATED_ACCOUNT_ID . '.' .
							StrToUpper(PathInfo($PARAM_PROFILE_IMAGE['name'], PATHINFO_EXTENSION))
					);
				}

			}
			Catch(Exception $PDO_ERR)
			{
				// Move uploaded image
				PHPRC_UPLOAD::REF_UPLOAD_TRANSACTION_ROLLBACK();
				PHPCUS_PARAM::CUS_JSON_ERROR($PDO_ERR);
			}
			
			
			// Return JSON response
			// ------------------------------------------------------------------
			PHPCUS_PARAM::CUS_JSON_SUCCESS("");		
			// ------------------------------------------------------------------
					
		}
		Catch(Exception $ERR)
		{
			PHPVC_LOG::VAR_REPORT_ERROR($ERR, 0);
			PHPCUS_PARAM::CUS_JSON_ERROR($ERR->getMessage());
		}
		/*
	}
	else
	{
		PHPCUS_PARAM::CUS_JSON_ERROR('Missing parameters');
	}
	*/

?>