218 lines
6.9 KiB
PHP
218 lines
6.9 KiB
PHP
<?php
|
|
class Mdfitness extends MY_Controller
|
|
{
|
|
var $db_onedev;
|
|
var $load;
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_onedev = $this->load->database("onedev", true);
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
// $cek = $this->db_onedev->query("select database() as current_db")->result();
|
|
// print_r($cek);
|
|
echo "MASTER FITNESS";
|
|
}
|
|
|
|
function search()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user['M_UserID'];
|
|
|
|
$search = "";
|
|
if (isset($prm["search"])) {
|
|
$search = trim($prm["search"]);
|
|
if ($search != "") {
|
|
$search = "%" . $prm["search"] . "%";
|
|
} else {
|
|
$search = "%%";
|
|
}
|
|
}
|
|
|
|
$number_offset = 0;
|
|
$number_limit = 10;
|
|
|
|
if ($prm["current_page"] > 0) {
|
|
$number_offset = ($prm["current_page"] - 1) * $number_limit;
|
|
}
|
|
|
|
$sql_tot = "SELECT count(*) as total
|
|
FROM mcu_fitness
|
|
WHERE Mcu_FitnessIsActive ='Y'
|
|
AND (Mcu_FitnessName LIKE ?)";
|
|
$qry_tot = $this->db_onedev->query($sql_tot, [$search]);
|
|
$last_qry = $this->db_onedev->last_query();
|
|
$tot_count = 0;
|
|
$tot_page = 0;
|
|
if ($qry_tot) {
|
|
$tot_count = $qry_tot->result_array()[0]["total"];
|
|
$tot_page = ceil($tot_count / $number_limit);
|
|
} else {
|
|
$this->db_onedev->trans_rollback();
|
|
$message['last_qry'] = $last_qry;
|
|
$this->sys_error_db("mcu fitness count error", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT Mcu_FitnessID,
|
|
'' as rownumber,
|
|
Mcu_FitnessName,
|
|
Mcu_FitnessUserID,
|
|
Mcu_FitnessCreated
|
|
FROM mcu_fitness
|
|
WHERE Mcu_FitnessIsActive ='Y'
|
|
AND (Mcu_FitnessName LIKE ?)
|
|
LIMIT ? OFFSET ?";
|
|
$qry = $this->db_onedev->query($sql, [$search, $number_limit, $number_offset]);;
|
|
$last_qry = $this->db_onedev->last_query();
|
|
if (!$qry) {
|
|
$message = $this->db_onedev->error();
|
|
$message['last_qry'] = $last_qry;
|
|
$this->sys_error_db("mcu fitness select error", $this->db_onedev);
|
|
exit;
|
|
}
|
|
$rows = $qry->result_array();
|
|
|
|
foreach ($rows as $k => $v) {
|
|
$xno = ($k + 1) + $number_offset;
|
|
$rows[$k]['rownumber'] = $xno;
|
|
}
|
|
$result = array(
|
|
"total_page" => $tot_page,
|
|
"total" => $tot_count,
|
|
"records" => $rows,
|
|
"last_qry" => $last_qry
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function addnewfitness()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$this->db_onedev->trans_begin();
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user['M_UserID'];
|
|
|
|
$xname = $prm['xname'];
|
|
|
|
$sql = "INSERT INTO mcu_fitness(
|
|
Mcu_FitnessName,
|
|
Mcu_FitnessIsActive,
|
|
Mcu_FitnessUserID,
|
|
Mcu_FitnessCreated,
|
|
Mcu_FitnessLastUpdated) VALUES(?,'Y',?,NOW(),NOW())";
|
|
$qry = $this->db_onedev->query($sql, [$xname, $userid]);
|
|
|
|
if (!$qry) {
|
|
$this->sys_error_db("mcu fitness insert", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$this->db_onedev->trans_commit();
|
|
$rst = array(
|
|
"total" => 1,
|
|
"records" => array("xid" => 0)
|
|
);
|
|
$this->sys_ok($rst);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function updatefitness()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$this->db_onedev->trans_begin();
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user['M_UserID'];
|
|
|
|
$xname = $prm['xname'];
|
|
$id = $prm["id"];
|
|
|
|
$sql = "UPDATE mcu_fitness SET
|
|
Mcu_FitnessName = ?,
|
|
Mcu_FitnessUserID = ?,
|
|
Mcu_FitnessLastUpdated = NOW()
|
|
WHERE Mcu_FitnessID = ?";
|
|
$qry = $this->db_onedev->query($sql, [
|
|
$xname,
|
|
$userid,
|
|
$id
|
|
]);
|
|
if (!$qry) {
|
|
$this->sys_error_db("mcu fitness update", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$this->db_onedev->trans_commit();
|
|
$rst = array(
|
|
"total" => 1,
|
|
"records" => array("xid" => 0)
|
|
);
|
|
$this->sys_ok($rst);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function deletefitness()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$this->db_onedev->trans_begin();
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user['M_UserID'];
|
|
|
|
$id = $prm["id"];
|
|
|
|
$sql = "UPDATE mcu_fitness SET
|
|
Mcu_FitnessIsActive = 'N',
|
|
Mcu_FitnessUserID = ?,
|
|
Mcu_FitnessLastUpdated = NOW()
|
|
WHERE Mcu_FitnessID = ?";
|
|
$qry = $this->db_onedev->query($sql, [
|
|
$userid,
|
|
$id
|
|
]);
|
|
if (!$qry) {
|
|
$this->sys_error_db("mcu fitness delete", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$this->db_onedev->trans_commit();
|
|
$rst = array(
|
|
"total" => 1,
|
|
"records" => array("xid" => 0)
|
|
);
|
|
$this->sys_ok($rst);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
}
|