388 lines
12 KiB
PHP
388 lines
12 KiB
PHP
<?php
|
|
class Mdpic 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 PIC";
|
|
}
|
|
|
|
function search()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$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_filter = "SELECT count(*) as total
|
|
FROM m_pic
|
|
JOIN m_staff ON M_PicM_StaffID = M_StaffID
|
|
AND M_StaffIsActive = 'Y'
|
|
JOIN m_pic_type ON M_PicM_PicTypeID = M_PicTypeID
|
|
AND M_PicTypeIsActive = 'Y'
|
|
WHERE M_PicIsActive = 'Y'
|
|
AND (M_StaffName LIKE ?)";
|
|
$qry_filter = $this->db_onedev->query($sql_filter, array($search));
|
|
$tot_count = 0;
|
|
$tot_page = 0;
|
|
if ($qry_filter) {
|
|
$tot_count = $qry_filter->result_array()[0]["total"];
|
|
$tot_page = ceil($tot_count / $number_limit);
|
|
} else {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("pic count error", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT M_PicID,
|
|
M_PicM_StaffID,
|
|
M_PicHP,
|
|
M_PicEmail,
|
|
M_PicM_PicTypeID,
|
|
M_StaffID,
|
|
M_StaffName,
|
|
M_PicTypeID,
|
|
M_PicTypeName
|
|
FROM m_pic
|
|
JOIN m_staff ON M_PicM_StaffID = M_StaffID
|
|
AND M_StaffIsActive = 'Y'
|
|
JOIN m_pic_type ON M_PicM_PicTypeID = M_PicTypeID
|
|
AND M_PicTypeIsActive = 'Y'
|
|
WHERE M_PicIsActive = 'Y' AND (M_StaffName LIKE ?)
|
|
limit ? offset ?";
|
|
$qry = $this->db_onedev->query($sql, array($search, $number_limit, $number_offset));
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
} else {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("pic select error", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$result = array(
|
|
"total" => $tot_page,
|
|
"total_filter" => $tot_count,
|
|
"records" => $rows
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function search_staff($staffID = '')
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
|
|
$search = "";
|
|
$number_limit = 10;
|
|
$tot_count = 0;
|
|
|
|
if (isset($prm['search'])) {
|
|
$search = trim($prm["search"]);
|
|
if ($search != "") {
|
|
$search = '%' . $prm['search'] . '%';
|
|
} else {
|
|
$search = '%%';
|
|
}
|
|
}
|
|
|
|
$sql_filter = "SELECT count(*) as total
|
|
FROM m_staff
|
|
WHERE M_StaffIsActive = 'Y'
|
|
AND (M_StaffName LIKE ?)
|
|
AND M_StaffID NOT IN (SELECT M_PicM_StaffID
|
|
FROM m_pic
|
|
WHERE M_PicIsActive = 'Y')
|
|
LIMIT ?";
|
|
$qry_filter = $this->db_onedev->query($sql_filter, [$search, $number_limit]);
|
|
if ($qry_filter) {
|
|
$tot_count = $qry_filter->result_array()[0]["total"];
|
|
} else {
|
|
$this->sys_error_db("staff count");
|
|
exit;
|
|
}
|
|
|
|
$sql_search = "SELECT M_StaffID,
|
|
M_StaffName,
|
|
M_StaffHP
|
|
FROM m_staff
|
|
WHERE M_StaffIsActive = 'Y'
|
|
AND (M_StaffName LIKE ?)
|
|
AND M_StaffID NOT IN (SELECT M_PicM_StaffID
|
|
FROM m_pic
|
|
WHERE M_PicIsActive = 'Y')
|
|
LIMIT ?";
|
|
if ($staffID != '') {
|
|
$sql_search = "SELECT M_StaffID,
|
|
M_StaffName,
|
|
M_StaffHP
|
|
FROM m_staff
|
|
WHERE M_StaffIsActive = 'Y'
|
|
AND (M_StaffName LIKE ?)
|
|
AND M_StaffID NOT IN (SELECT M_PicM_StaffID
|
|
FROM m_pic
|
|
WHERE M_PicIsActive = 'Y'
|
|
AND M_PicM_StaffID <> $staffID )
|
|
LIMIT ?";
|
|
}
|
|
$qry_search = $this->db_onedev->query($sql_search, [$search, $number_limit]);
|
|
// print_r($this->db_onedev->last_query());
|
|
// exit;
|
|
if ($qry_search) {
|
|
$rows = $qry_search->result_array();
|
|
} else {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("satff select error", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$result = array(
|
|
"total" => $tot_count,
|
|
"total_display" => sizeof($rows),
|
|
"records" => $rows
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function get_typepic()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
|
|
$sql = "SELECT M_PicTypeID,
|
|
M_PicTypeCode,
|
|
M_PicTypeName
|
|
FROM m_pic_type
|
|
WHERE M_PicTypeIsActive = 'Y'";
|
|
$qry = $this->db_onedev->query($sql);
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
} else {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("type pic select error", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$result = array(
|
|
"total_display" => sizeof($rows),
|
|
"records" => $rows
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function add()
|
|
{
|
|
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'];
|
|
|
|
$staffId = "";
|
|
if (isset($prm["staffId"])) {
|
|
$staffId = trim($prm["staffId"]);
|
|
}
|
|
$nohp = "";
|
|
if (isset($prm["nohp"])) {
|
|
$nohp = trim($prm["nohp"]);
|
|
}
|
|
$email = "";
|
|
if (isset($prm["email"])) {
|
|
$email = trim($prm["email"]);
|
|
}
|
|
$pictypeId = "";
|
|
if (isset($prm["pictypeId"])) {
|
|
$pictypeId = trim($prm["pictypeId"]);
|
|
}
|
|
|
|
$sql = "INSERT INTO m_pic(
|
|
M_PicM_StaffID,
|
|
M_PicHP,
|
|
M_PicEmail,
|
|
M_PicM_PicTypeID,
|
|
M_PicUserID,
|
|
M_PicIsActive,
|
|
M_PicCreated,
|
|
M_PicLastUpdated) VALUES(?,?,?,?,?,'Y',NOW(),NOW())";
|
|
$qry = $this->db_onedev->query($sql, [
|
|
$staffId,
|
|
$nohp,
|
|
$email,
|
|
$pictypeId,
|
|
$userid
|
|
]);
|
|
if (!$qry) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("pic insert error", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$this->db_onedev->trans_commit();
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => array("xid" => 0)
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function edit()
|
|
{
|
|
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'];
|
|
|
|
$staffId = "";
|
|
if (isset($prm["staffId"])) {
|
|
$staffId = trim($prm["staffId"]);
|
|
}
|
|
$nohp = "";
|
|
if (isset($prm["nohp"])) {
|
|
$nohp = trim($prm["nohp"]);
|
|
}
|
|
$email = "";
|
|
if (isset($prm["email"])) {
|
|
$email = trim($prm["email"]);
|
|
}
|
|
$pictypeId = "";
|
|
if (isset($prm["pictypeId"])) {
|
|
$pictypeId = trim($prm["pictypeId"]);
|
|
}
|
|
$Id = "";
|
|
if (isset($prm["Id"])) {
|
|
$Id = trim($prm["Id"]);
|
|
}
|
|
|
|
$sql = "UPDATE m_pic SET
|
|
M_PicM_StaffID = ?,
|
|
M_PicHP = ?,
|
|
M_PicEmail = ?,
|
|
M_PicM_PicTypeID = ?,
|
|
M_PicUserID = ?,
|
|
M_PicLastUpdated = NOW()
|
|
WHERE M_PicID = ?";
|
|
$qry = $this->db_onedev->query($sql, [
|
|
$staffId,
|
|
$nohp,
|
|
$email,
|
|
$pictypeId,
|
|
$userid,
|
|
$Id
|
|
]);
|
|
if (!$qry) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("update pic error", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$this->db_onedev->trans_commit();
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => array("xid" => 0)
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function deleterow()
|
|
{
|
|
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 = "";
|
|
if (isset($prm["Id"])) {
|
|
$Id = trim($prm["Id"]);
|
|
}
|
|
|
|
$sql = "UPDATE m_pic SET
|
|
M_PicUserID = ?,
|
|
M_PicIsActive = 'N',
|
|
M_PicLastUpdated = NOW()
|
|
WHERE M_PicID = ?";
|
|
$qry = $this->db_onedev->query($sql, [$userid, $Id]);
|
|
if (!$qry) {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("pic delete error", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$this->db_onedev->trans_commit();
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => array("xid" => 0)
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
}
|