<?php

/**
 *
 * @copyright  2020-2021 objectivejs.org
 * @version    2
 * @link       http://www.objectivejs.org
 */

require_once 'validatefilename.php';
require_once 'models/wall.inc';

function walldelete($lang, $arglist=false) {
	if (!isset($_SESSION['wall_id'])) {
		goto badrequest;
	}

	$wall_id=$_SESSION['wall_id'];

	$name=false;

	if (isset($_POST['file_name'])) {
		$name=$_POST['file_name'];
	}

	if (!$name or !validate_filename($name)) {
		goto badrequest;
	}

	$file=wall_file($wall_id, $name);

	if (!file_exists($file)) {
		goto badrequest;
	}

	$r = @unlink($file);

	if (!$r) {
		goto internalerror;
	}

	$file=wall_file_tag($wall_id, $name);

	$r = @unlink($file);

	if (!$r) {
		goto internalerror;
	}

	return false;

badrequest:
	header('HTTP/1.1 400 Bad Request');
	return false;

internalerror:
	header('HTTP/1.1 500 Internal Error');
	return false;
}
