File: /var/www/doco/keytest/wp-content/themes/ormedia/keyAlertData/alert/u_alert.php
<?php
if (isset($_REQUEST['checking_api_file'])){
exit();
}
function is_alert_opened($uid, $msg_id)
{
global $wpdb;
$res = $wpdb->get_row($wpdb->prepare("select id from keylab_alert_opened where uid = %d and msg_id = %d", $uid, $msg_id));
return $res != null;
}
date_default_timezone_set('Asia/Hong_Kong');
$uid = $_REQUEST['uid'];
$msg_id = $_REQUEST['msg_id'];
if (empty($uid) || empty($msg_id)) {
$rv->rc = -1;
$rv->msg = "missing params";
} else {
if (is_alert_opened($uid, $msg_id)) {
$rv->rc = -2;
$rv->msg = "is opened";
} else {
$res = $wpdb->insert(
'keylab_alert_opened',
array(
'uid' => $uid,
'msg_id' => $msg_id,
'creation_time' => current_time('mysql')
),
array('%d', '%d', '%s')
);
if ($res === false) {
$rv->rc = -3;
$rv->msg = "failed to insert a row";
} else {
$rv->rc = 1;
$rv->msg = "success";
}
}
}
insert_log($_REQUEST['uid'], $token, 0, get_request_string(), "更新alert狀態:rc=" . $rv->rc . ",msg=" . $rv->msg);
echo json_encode($rv);