<?php
include '../env.php';
require_once(LIB.'common.inc.php');
if (can_action('admin') && !empty($_POST['skin']) && isset($_POST['admin']) && isset($_POST['operator'])) {
	require_once(LIB.'Skin.class.php');
	$skin = new Skin();
	$ret = $skin->load($_POST['skin']);
	if ($ret === FALSE) {
		echo json_encode(FALSE);
		die;
	}
	$skin->colors['admin'] = $_POST['admin'];
	$skin->colors['operator'] = $_POST['operator'];
	$log_ret = _a_log2('skin', 'modify', array(
		'target_key' => $_POST['skin'],
		'detail' => serialize($_POST)
	));
	if ($log_ret) {
		$ret = $skin->generate();
		_a_log_write($log_ret, array('success' => $ret === FALSE ? '0' : '1'));
		echo json_encode($ret);
		if ($ret) {
			Setting::Set('skin', $_POST['skin']);
			Setting::Set('admin-color', $_POST['admin']);
			Setting::Set('operator-color', $_POST['operator']);
		}
	} else {
		echo json_encode(FALSE);
	}
} else {
	_a_log_fail('skin', 'modify', 'invalid auth', array(
		'target_key' => @$_POST['skin']
	));
	echo json_encode(FALSE);
}
?>