<?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"];
	$mUserId = $systemHandler->loadHandler("USER")->mUserId;
	
	if($systemExecution->runQuery("SELECT COUNT(id) AS albumCount FROM web_albums WHERE id = '%s' AND album_owner_id = '%s'", array($mAlbumId, $mUserId))->fetch_object()->albumCount > 0) {
		$systemExecution->runQuery("DELETE FROM web_albums WHERE id = '%s' AND album_owner_id = '%s'", array($mAlbumId, $mUserId));
		
		$mImageIdCollection = array();
		$mImageIdSource = $systemExecution->runQuery("SELECT id FROM web_images WHERE image_album_id = '%s'", $mAlbumId);
		
		while($mRow = $mImageIdSource->fetch_assoc())
			array_push($mImageIdCollection, $mRow["id"]);
			
		foreach($mImageIdCollection as $mImageId)
			$systemExecution->runQuery("DELETE FROM web_timeline WHERE post_image_id = '%s'", $mImageId);
		
		$systemExecution->runQuery("DELETE FROM web_images WHERE image_album_id = '%s'", $mAlbumId);
		$a["isValid"] = true;
	} else $a["isValid"] = false;
	
	/* ### DO NOT CHANGE ANYTHING FROM HERE ### */
	header("Content-Type: application/json");
	echo json_encode($mPong);
?>