<?php
	require_once("../system.engine/system.core.php");
	
	$mPong = array();
	$a = &$mPong;
	$p = &$_POST;
	
	global $systemHandler;
	$systemExecution = $systemHandler->loadHandler("EXECUTION");
	$systemHash = $systemHandler->loadHandler("HASH");
	/* ### DO YOUR CODES ONLY FROM HERE ### */

	$mAlbumId = $p["albumId"];
	$mAlbumName = $p["albumName"];
	$mUserId = $systemHandler->loadHandler("USER")->mUserId;
	
	if($systemExecution->runQuery("SELECT COUNT(id) AS albumCount FROM web_albums WHERE album_name = '%s' AND album_owner_id = '%s'", array($mAlbumName, $mUserId))->fetch_object()->albumCount == 0) {
		$systemExecution->runQuery("UPDATE web_albums SET album_name = '%s' WHERE id = '%s' AND album_owner_id = '%s'", array($mAlbumName, $mAlbumId, $mUserId));
		$a["isValid"] = true;
	} else $a["isValid"] = false;
	
	/* ### DO NOT CHANGE ANYTHING FROM HERE ### */
	header("Content-Type: application/json");
	echo json_encode($mPong);
?>