<?php

namespace App\Controllers;

use CodeIgniter\API\ResponseTrait;
use CodeIgniter\Controller;

class Lqms extends BaseController {
	use ResponseTrait;

	public function index() {
		$db = \Config\Database::connect();
		$sql = "SELECT * FROM lqms_log LimiT 0,30";
		$query = $db->query($sql);
		$results = $query->getResultArray();
		$data['logs'] = $results;
		return view('lqms_index', $data);
	}

	public function POSTData() {
		$db = \Config\Database::connect();
		$POST = $this->request->getJSON();
		$sql = "insert into lqms_log(message) values(".$db->escape(json_encode($POST)).")";
		$query = $db->query($sql);
		$data['POST'] = $POST;
		echo "$sql";
		//return $this->respond($data);
		/*
		echo "<pre>";
		print_r(json_encode($POST));
		echo "</pre>";
		*/
	}
	
	public function log_clear() {
		$db = \Config\Database::connect();
		$sql = "DELETE FROM lqms_log";
		$query = $db->query($sql);
	}
	
	public function log_delete($mesid=null) {
		$db = \Config\Database::connect();
		$sql = "DELETE FROM lqms_log where mesid=$mesid";
		$query = $db->query($sql);
	}
}