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

$log_ret = _a_log2('auth', 'modify', array(
	'target_id' => @$_POST['user_type_id'],
	'target_key' => @$_POST['auth_name'],
	'detail' => serialize($_POST)
));

if ($log_ret) {
	$ret = $user->updateAuth($_POST['auth_name'], $_POST['user_type_id'], $_POST['auth']);
	_a_log_write($log_ret, array('success' => $ret === FALSE ? '0' : '1'));
	echo json_encode($ret);
	$user->saveAuthCache();
} else {
	echo json_encode(FALSE);
}
?>