<?php
require_once '_admin_setting.php';

$action = $_REQUEST['action'];
$success = false;

switch ($action) {
    case 'update':
		$answer = $_POST['content'];
        $id = $_POST['id'];
		$sql = "UPDATE qa SET answer = '{$answer}' WHERE id = {$id}";
		$nsodb->query($sql);
        $success = true;
        break;

    case 'delete':
        $id = $_GET['id'];
        if (! is_numeric($id))
            break;
		$sql = "DELETE FROM qa WHERE id = '{$id}'";
        $nsodb->query($sql);
        $success = true;
        break;

    default:
        break;
}

// ------------------------------------------
// 如果是AJAX请求，返回JSON.
// ------------------------------------------
if ($_SERVER['HTTP_X_REQUESTED_WITH']) {
    $array = array('success' => $success, 'id' => $postId);
    echo json_encode($array);
    exit();
}
header('Location: qa.php');