Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- class Pelapor extends CI_Controller {
- function __construct(){
- parent::__construct();
- // Add origin header
- header('Access-Control-Allow-Origin: *');
- header('Access-Control-Allow-Credentials: true');
- header('Access-Control-Allow-Method: PUT, GET, POST, DELETE, OPTIONS');
- header('Access-Control-Allow-Headers: Content-Type, x-xsrf-token');
- $this->load->model('pelapor_model');
- }
- private function outputJson($response=array(),$status=200){
- $this->output
- ->set_status_header($status)
- ->set_content_type('application/json', 'utf-8')
- ->set_output(json_encode($response, JSON_PRETTY_PRINT))
- ->_display();
- exit();
- }
- public function index(){
- $json=array(
- 'message' => 'Naon?',
- 'data' => '',
- 'code' => 404
- );
- $this->outputJson($json);
- }
- public function sign_up(){
- $postdata = (array)json_decode(file_get_contents('php://input'));
- $json=array(
- 'message' => '',
- 'data' => '',
- 'code' => 404
- );
- @$email = $postdata['email'];
- @$no_telphone = $postdata['no_telphone'];
- @$username = $postdata['username'];
- @$password = $postdata['password'];
- if(!empty($email)){
- // validasi
- $cekUsername = $this->pelapor_model->cekUsername($username);
- $cekEmail = $this->pelapor_model->cekEmail($email);
- $cekPhone = $this->pelapor_model->cekPhone($no_telphone);
- if(!$cekUsername){
- if(!$cekEmail){
- if(!$cekPhone){
- $data = array(
- 'email' => $email,
- 'no_telphone' => $no_telphone,
- 'username' => $username,
- 'password' => md5($password),
- 'status' => 'f',
- 'device_token' => ''
- );
- // insert data user
- $insert = $this->pelapor_model->add($data);
- if($insert){
- $json = array (
- 'message' => 'Anda telah berhasil daftar, Akun anda akan segera diaktifkan',
- 'data' => '',
- 'code' => 200
- );
- }else{
- $json = array (
- 'message' => 'Maaf anda gagal mendaftar, silahkan coba lagi ',
- 'data' => '',
- 'code' => 500
- );
- }
- }else{
- $json = array (
- 'message' => 'Maaf nomor telphone sudah digunakan',
- 'data' => '',
- 'code' => 500
- );
- }
- }else{
- $json = array (
- 'message' => 'Maaf email sudah digunakan',
- 'data' => '',
- 'code' => 500
- );
- }
- }else{
- $json = array (
- 'message' => 'Maaf username sudah digunakan',
- 'data' => '',
- 'code' => 500
- );
- }
- }
- $this->outputJson($json);
- }
- public function login(){
- $postdata = (array)json_decode(file_get_contents('php://input'));
- $json=array(
- 'message' => '',
- 'data' => '',
- 'code' => 404
- );
- @$email = $postdata['email'];
- @$password = $postdata['password'];
- @$device_token = $postdata['device_token'];
- if(!empty($email)){
- $data = array();
- $data['device_token']=$device_token;
- $data['email']=$email;
- $data['password']=md5($password);
- $status = $this->pelapor_model->cekLogin($data)->result();
- if($status!=null){
- //update device token
- $this->pelapor_model->updateDeviceToken($data['device_token'],$status[0]->id);
- $json = array (
- 'message' => 'Login Berhasil',
- 'data' => $status,
- 'code' => 200
- );
- }else{
- $json = array (
- 'message' => 'Maaf email atau password tidak sama',
- 'data' => '',
- 'code' => 500
- );
- }
- }
- $this->outputJson($json);
- }
- public function lapor(){
- $this->load->model('laporan_model');
- $this->load->library('upload');
- //set preferences
- $config['upload_path'] = './uploads/';
- $config['allowed_types'] = 'png|jpg|jpeg';
- //load upload class library
- $this->load->library('upload', $config);
- if (!$this->upload->do_upload('foto_pelapor')) {
- $json = array (
- 'message' => 'Gagal melaporkan',
- 'data' => '',
- 'code' => 500
- );
- }else{
- $gambar = $this->upload->data('file_name');
- $this->laporan_model->add($this->input->post(),$gambar);
- $json = array (
- 'message' => 'Berhasil Melaporkan',
- 'data' => '',
- 'code' => 200
- );
- }
- $this->output
- ->set_content_type('application/json')
- ->set_output(json_encode($json));
- }
- public function activeAccount(){
- $id = $this->input->post('id');
- if($this->pelapor_model->updateStatusActive($id)){
- $json = array (
- 'message' => 'Akun telah diaktifkan',
- 'data' => '',
- 'code' => 200
- );
- }else{
- $json = array (
- 'message' => 'Akun gagal diaktifkan',
- 'data' => '',
- 'code' => 500
- );
- }
- $this->output
- ->set_content_type('application/json')
- ->set_output(json_encode($json));
- }
- public function updatePassword(){
- $postdata = (array)json_decode(file_get_contents('php://input'));
- $json=array(
- 'message' => '',
- 'data' => '',
- 'code' => 404
- );
- @$password = $postdata['password'];
- @$id = $postdata['id'];
- if(!empty($password)){
- $data = array();
- $data['password'] = md5($password);
- $data['id'] = $id;
- if($this->pelapor_model->updatePassword($data)){
- $json = array (
- 'message' => 'Password berhasil diubah',
- 'data' => '',
- 'code' => 200
- );
- }else{
- $json = array (
- 'message' => 'Password gagal diubah',
- 'data' => '',
- 'code' => 500
- );
- }
- }
- $this->outputJson($json);
- }
- public function getAllPelapor(){
- $offset = 0;
- if($this->input->post('offset')!=null){
- $offset = $this->input->post('offset');
- }
- $limit = 0;
- if($this->input->post('limit')!=null){
- $limit = $this->input->post('limit');
- }
- $data = $this->pelapor_model->getAll($offset,$limit);
- if(!empty($data)){
- $json = array (
- 'message' => 'List pelapor berhasil di ambil',
- 'data' => $data,
- 'code' => 200
- );
- }else{
- $json = array (
- 'message' => 'List pelapor kosong',
- 'data' => '',
- 'code' => 500
- );
- }
- $this->output
- ->set_content_type('application/json')
- ->set_output(json_encode($json));
- }
- public function getLaporanByPelapor(){
- $offset = 0;
- if($this->input->post('offset')!=null){
- $offset = $this->input->post('offset');
- }
- $limit = 10;
- if($this->input->post('limit')!=null){
- $limit = $this->input->post('limit');
- }
- $data = $this->pelapor_model->getlaporanByid($this->input->post('id'),$limit,$offset);
- if(!empty($data)){
- $json = array (
- 'message' => 'List Laporan berhasil di ambil',
- 'data' => $data,
- 'code' => 200
- );
- }else{
- $json = array (
- 'message' => 'List Laporan kosong',
- 'data' => '',
- 'code' => 500
- );
- }
- $this->output
- ->set_content_type('application/json')
- ->set_output(json_encode($json));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement