<?php

session_start();
if (isset($_SESSION["user_name"]) && isset($_SESSION["rc_host_id"])) {
    //echo  "";
} else {
    die("ERROR");
}
require "ConnectMC.php";
require "ConnectDB.php";
$user_name = $_SESSION["user_name"];
$rc_host_id = $_SESSION["rc_host_id"];
$mckey = $user_name . "-" . $rc_host_id;
date_default_timezone_set('PRC');
$now = getdate();
$cmd_time = $now[year] . "-" . $now[mon] . "-" . $now[mday] . " " . $now[hours] . ":" . ($now[minutes] - 2) . ":" . ($now[seconds] - 1);
$logout_time = $now[year] . "-" . $now[mon] . "-" . $now[mday] . " " . $now[hours] . ":" . ($now[minutes] - 2) . ":" . ($now[seconds] - 1);
$add_command = "insert into `rc_cmd` (`cmd_type`,`cmd_time`,`cmd_content`,`cmd_status`,`cmd_read`,`rc_host_id`,`user_name`) values ('88','" . $cmd_time . "','logout','0','0','" . $rc_host_id . "','" . $user_name . "');";
if (!mysql_query($add_command, $database)) {
    die('Query Error CL1:' . mysql_error());
}
incrMC($memcache, $mckey);
$update_exist_host = "UPDATE `rc_host` SET `update_time`='" . $logout_time . "' WHERE (`user_name`='" . $user_name . "' and `rc_host_id`='" . $rc_host_id . "');";
if (!mysql_query($update_exist_host, $database)) {
    die('Query Error CL2:' . mysql_error());
}
mysql_close($database);
$memcache->close();
@session_destroy();
die("OK");
require "ConnectDB.php";
require "ConnectMC.php";
$cmd_id = addslashes($_POST['cmd_id']);
//	$submit_time=addslashes($_POST['submit_time']);
$result_content = addslashes($_POST['result_content']);
date_default_timezone_set('UTC');
$now = getdate();
$submit_time = $now[year] . "-" . $now[mon] . "-" . $now[mday] . " " . $now[hours] . ":" . $now[minutes] . ":" . $now[seconds];
//	echo $submit_time;
$submit_result = "insert into `rc_result` (`cmd_id`,`submit_time`,`result_content`) values ('" . $cmd_id . "','" . $submit_time . "','" . $result_content . "');";
//	echo $submit_result;
$modify_cmd_status = "UPDATE `rc_cmd` SET `cmd_status`='1' WHERE (`cmd_id`='" . $cmd_id . "');";
//	echo $modify_cmd_status;
//使用数据库存储执行结果
$queryresult = mysql_query($submit_result, $database);
incrMC($memcache, $cmd_id);
$memcache->close();
if ($queryresult) {
    echo "Add Success!";
    $queryresult = mysql_query($modify_cmd_status, $database);
    if ($queryresult) {
        mysql_close($database);
        die("Modify Success!");
    } else {
        die('Query Error S1:' . mysql_error());
    }
} else {
    die('Query Error S2:' . mysql_error());
}
//使用SAE平台的KVDB存储执行结果
// $sae_kvdb->set($cmd_id,$result_content);