<?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 ### */

	$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("INSERT INTO web_albums (album_name, album_owner_id, album_privacy, album_is_standard, album_date_created) VALUES ('%s', '%s', '%s', '%s', '%s')", array($mAlbumName, $mUserId, "friends", "no", time()));
		$a["albumId"] = $systemExecution->runQuery("SELECT id FROM web_albums WHERE album_name = '%s' AND album_owner_id = '%s'", array($mAlbumName, $mUserId))->fetch_object()->id;
		$a["albumName"] = htmlspecialchars($mAlbumName);
		$a["albumCreated"] = $systemCore->timeAgo($systemExecution->runQuery("SELECT album_date_created FROM web_albums WHERE album_name = '%s' AND album_owner_id = '%s'", array($mAlbumName, $mUserId))->fetch_object()->album_date_created);
		$a["isValid"] = true;
	} else $a["isValid"] = false;
	/* ### DO NOT CHANGE ANYTHING FROM HERE ### */
	header("Content-Type: application/json");
	echo json_encode($mPong);
?>