<?php
include '../env.php';
require_once(LIB.'common.inc.php');
require_once(LIB.'Box.class.php');
$box = new Box();
if (! can_action('admin')) {
	_a_log_fail('box', 'modify', 'invalid auth', array('target_key' => @$_POST['old_name']));
	echo json_encode(FALSE);
	die;
}

$log_ret = FALSE;
if (empty($_POST['old_name'])) {
	$log_ret = _a_log2('box', 'create', array(
		'detail' => serialize($_POST),
		'target_key' => $_POST['name']
	));
} else {
	$log_ret = _a_log2('box', 'modify', array(
		'detail' => serialize($_POST),
		'target_key' => $_POST['old_name']
	));
}

if ($log_ret) {
	$ret = $box->updateBox(
		$_POST['old_name'],
		$_POST['name'],
		@$_POST['description'],
		@$_POST['script']
	);
	_a_log_write($log_ret, array('success' => $ret === FALSE ? '0' : '1'));
	echo json_encode($ret);
} else {
	echo json_encode(FALSE);
}
?>