<?php function knbase_new_entry_action($params) { $create_at = date("Y-m-d H:i:s"); $query = db() -> prepare("INSERT INTO `adm_entry`(`type`, `include_to`, `title`, `content`, `hlink`, `price`, `create_at`) VALUES (:type, :include_to, :title, :content, :hlink, :price, :create_at)"); $include_to = []; foreach($params["include_to"] as $botname => $enabled) { if($enabled) { $include_to[] = $botname; } } $include_to = implode(",", $include_to); $query -> execute([ ":type" => $params["type"], ":include_to" => $include_to, ":title" => $params["title"], ":content" => $params["content"], ":hlink" => $params["hlink"], ":price" => $params["price"], ":create_at" => $create_at ]); echo json_encode([ "status" => true, "entry_id" => db() -> lastInsertId() ]); } function knbase_entries_action($params) { $type = $params["type"]; $type = ($type == "*") ? "%%" : $type; $query = db() -> prepare("SELECT * FROM `adm_entry` WHERE `type` LIKE :type ORDER BY `id` DESC"); $query -> execute([ ":type" => $type ]); $result = $query -> fetchAll(PDO::FETCH_ASSOC); echo json_encode([ "status" => true, "entries" => $result ]); } function knbase_entry_action($params) { $query = db() -> prepare("SELECT * FROM `adm_entry` ORDER BY `id`=:id DESC"); $query -> execute([ ":id" => $params["entry_id"] ]); $result = $query -> fetch(PDO::FETCH_ASSOC); echo json_encode([ "status" => true, "entry" => $result ]); } function knbase_update_entry_action($params) { $query = db() -> prepare("UPDATE `adm_entry` SET `type`=:type,`include_to`=:include_to,`title`=:title,`content`=:content,`hlink`=:hlink,`price`=:price WHERE `id`=:id LIMIT 1"); $include_to = []; foreach($params["include_to"] as $botname => $enabled) { if($enabled) { $include_to[] = $botname; } } $include_to = implode(",", $include_to); $query -> execute([ ":type" => $params["type"], ":include_to" => $include_to, ":title" => $params["title"], ":content" => $params["content"], ":hlink" => $params["hlink"], ":price" => $params["price"], ":id" => intval($params["id"]) ]); echo json_encode([ "status" => true ]); } function knbase_remove_entry_action($params) { $query = db() -> prepare("DELETE FROM `adm_entry` WHERE `id`=:id LIMIT 1"); $query -> execute([ ":id" => intval($params["id"]) ]); echo json_encode([ "status" => true ]); }