db_smartone = $this->load->database("onedev", true); } public function loadx() { try { //# cek token valid /*if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; }*/ $prm = $this->sys_input; $sql = "select COUNT(*) as total from m_religion where M_ReligionIsActive = 'Y'"; $sql_param = array($search); $total = $this->db_smartone->query($sql, $sql_param)->row()->total; $sql = "select * from m_religion where M_ReligionIsActive = 'Y'"; $sql_param = array($search); $query = $this->db_smartone->query($sql, $sql_param); if ($query) { $rows = $query->result_array(); } else { $this->sys_error_db("m_schedule select"); exit; } $result = array( "total" => $total, "total_filter" => count($rows), "records" => $rows, "ownIP" => $_SERVER["REMOTE_ADDR"] ); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } public function save() { try { //# cek token valid /*if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; }*/ //# ambil parameter input $prm = $this->sys_input; $name = $prm['name']; $query = "SELECT COUNT(*) as exist FROM m_religion WHERE M_ReligionIsActive = 'Y' AND M_ReligionName = '{$name}'"; $exist_code = $this->db_smartone->query($query)->row()->exist; if ($exist_code == 0) { $sql = "insert into m_religion( M_ReligionName ) values( ?)"; $query = $this->db_smartone->query( $sql, array( $name ) ); //echo $query; if (!$query) { $this->sys_error_db("m_religion insert"); exit; } $result = array("total" => 1, "records" => array("form_rel_id" => 0)); $this->sys_ok($result); } else { $result = array("total" => -1, "records" => 0); $this->sys_ok($result); } } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } public function update() { // print_r("sekarang di backend" . $prm); // exit; try { //# ambil parameter input $prm = $this->sys_input; $id = $prm['id']; $name = $prm['name']; $date = $prm['date']; $query = "SELECT COUNT(*) as exist FROM m_religion WHERE M_ReligionIsActive = 'Y' AND M_ReligionCreated = '{$date}' AND M_ReligionID <> {$id}"; // echo $query; $exist_code = $this->db_smartone->query($query)->row()->exist; // $query = "SELECT COUNT(*) as exist FROM m_religion WHERE M_ReligionCreated = {$date} M_ReligionIsActive = 'Y' AND M_ReligionID <> {$id}"; // //echo $query; // $exist_code = $this->db_smartone->query($query)->row()->exist; if ($exist_code == 0) { $sql = "update m_religion set M_ReligionName = ? where M_ReligionID = ? "; $query = $this->db_smartone->query( $sql, array( $name, $id ) ); //echo $query; if (!$query) { $this->sys_error_db("m_religion update"); exit; } $result = array("total" => 1, "records" => array("form_rel_id" => 0)); $this->sys_ok($result); } else { $result = array("total" => -1, "records" => 0); $this->sys_ok($result); } } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } public function deletex() { try { //# cek token valid /*if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; }*/ //# ambil parameter input $prm = $this->sys_input; $id = $prm['id']; $sql = "update m_religion set M_ReligionIsActive = 'N' where M_ReligionID = ? "; $query = $this->db_smartone->query( $sql, array( $id ) ); //echo $query; if (!$query) { $this->sys_error_db("m_religion delete"); exit; } $result = array("total" => 1, "records" => array("xid" => 0)); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } }