Advertisement
darmariduan

master.php

Aug 18th, 2022
625
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 36.56 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') or exit('No direct script access allowed');
  3.  
  4. class Master extends CI_Controller
  5. {
  6.     public function __construct()
  7.     {
  8.         parent::__construct();
  9.         $this->load->library('form_validation');
  10.         $this->load->library('datatables');
  11.         $this->load->library('src/Toastr');
  12.         $this->load->model('dashboard/Dashboard_model', 'Dashboard', TRUE);
  13.         set_zone();
  14.  
  15.         if ($this->session->userdata('role_id') !== '1') {
  16.             $this->toastr->error('Please Login to Continue !!!');
  17.  
  18.             redirect('Login.html');
  19.         }
  20.     }
  21.  
  22.     public function index()
  23.     {
  24.         // Redirect to Dashboard when access master index
  25.         redirect('Dashboard.html', 'refresh');
  26.     }
  27.  
  28.     // View Users
  29.     public function Users()
  30.     {
  31.         $data        = [
  32.             'titles'        => "Dashboard Administrator || View Users Pages",
  33.             'settings'      => $this->Dashboard->viewAll('*', 'tbl_setting')->result_array(),
  34.             'user'            => $this->Dashboard->viewWhere('tbl_users', 'id_users', $this->session->userdata('id'))->result_array(),
  35.             'version'       => $this->Dashboard->viewWhere('tbl_version', 'id_version', 1)->result_array(),
  36.             'role'          => $this->Dashboard->viewAll('*', 'tbl_role')->result_array(),
  37.             'viewUsers'        => true,
  38.             'card_title'    => 'Data Users',
  39.             'breadcumb'        => "View Users",
  40.             'view'            => "v_Users"
  41.         ];
  42.  
  43.         $this->load->view("index", $data);
  44.     }
  45.  
  46.     // Json View Datatable Users
  47.     public function jsonUsers()
  48.     {
  49.         header('Content-Type: application/json');
  50.  
  51.         $join = array(
  52.             ['tbl_role', 'tbl_users.role_id=tbl_role.id_role', 'LEFT']
  53.         );
  54.  
  55.         echo $this->Dashboard->jsonGlobalJoin(
  56.             '
  57.                tbl_users.id_users AS id_users,
  58.                tbl_users.username AS username,
  59.                tbl_users.users_name AS users_name,
  60.                tbl_users.role_id AS role_id,
  61.                tbl_role.role_name AS role_name
  62.            ',
  63.             'tbl_users',
  64.             $join
  65.         );
  66.     }
  67.  
  68.     // Get Data Ajax For Table Role Users
  69.     public function getUsersType()
  70.     {
  71.         // Search term
  72.         $searchTerm     = $this->input->post('searchTerm');
  73.  
  74.         // Get Role Users
  75.         $response = $this->Dashboard->getSelect2('*', $searchTerm, 'tbl_role', 'id_role', 'role_name');
  76.  
  77.         echo json_encode($response);
  78.     }
  79.  
  80.     // Action Add Users Data
  81.     public function ActionAddUsers()
  82.     {
  83.         $data = array('success' => false, 'messages' => array());
  84.  
  85.         $this->form_validation->set_rules("name", "name", "trim|min_length[3]|required");
  86.         $this->form_validation->set_rules("username", "Username", "trim|min_length[3]|is_unique[tbl_users.username]|required");
  87.         $this->form_validation->set_rules("password", "Password", "trim|required");
  88.         $this->form_validation->set_rules("role", "Role USers", "trim|required");
  89.         $this->form_validation->set_error_delimiters('<p class="text-danger">', '</p>');
  90.  
  91.         if ($this->form_validation->run()) {
  92.             $input     = [
  93.                 'users_name'            => htmlentities($this->input->post('name')),
  94.                 'username'              => htmlentities($this->input->post('username')),
  95.                 'password'              => password_hash($this->input->post('password'), PASSWORD_BCRYPT),
  96.                 'role_id'               => htmlentities($this->input->post('role'))
  97.             ];
  98.  
  99.             if ($this->Dashboard->insert('tbl_users', $input)) {
  100.                 $this->toastr->success('Username = ' . $this->session->userdata('username') . ' Successfully Inserted New Users !!!');
  101.  
  102.                 helper_log('add', $this->session->userdata('username') . ' Successfully Inserted New Users !!!', 'Inserted Users ' . $input['username']);
  103.                 $data['success']            = true;
  104.             }
  105.         } else {
  106.             foreach ($_POST as $key => $value) {
  107.                 $data['messages'][$key]     = form_error($key);
  108.             }
  109.         }
  110.  
  111.         echo json_encode($data);
  112.     }
  113.  
  114.     // View Users Data
  115.     public function ViewEditUsers($id = 0)
  116.     {
  117.         $data        = [
  118.             'titles'        => "Dashboard Administrator || View Users Pages",
  119.             'settings'      => $this->Dashboard->viewAll('*', 'tbl_setting')->result_array(),
  120.             'user'            => $this->Dashboard->viewWhere('tbl_users', 'id_users', $this->session->userdata('id'))->result_array(),
  121.             'version'       => $this->Dashboard->viewWhere('tbl_version', 'id_version', 1)->result_array(),
  122.             'EditData'      => $this->Dashboard->viewWhere('tbl_users', 'id_users', $id)->result_array(),
  123.             'role'          => $this->Dashboard->viewAll('*', 'tbl_role')->result_array(),
  124.             'viewUsers'        => true,
  125.             'card_title'    => 'Data Users',
  126.             'breadcumb'        => "View Users",
  127.             'view'            => "v_EditUsers"
  128.         ];
  129.  
  130.         $this->load->view("index", $data);
  131.     }
  132.  
  133.     // Action Edit Data User
  134.     public function ActionEditUsers()
  135.     {
  136.         $this->form_validation->set_rules("name", "Nama Users", "trim|min_length[3]|required");
  137.         $this->form_validation->set_rules("username", "Username", "trim|min_length[4]|required");
  138.         $this->form_validation->set_rules("role", "Role Users", "trim|required");
  139.  
  140.         $id                         = decrypt_url(htmlentities($this->input->post('idEdit')));
  141.  
  142.         if ($this->form_validation->run() === false) {
  143.             $this->ViewEditUsers($id);
  144.         } else {
  145.             // Check Pass ID
  146.             $pass               = $this->Dashboard->viewWhere('tbl_users', 'id_users', $id)->result_array();
  147.             if ($this->input->post('passwordEdit') === '' || $this->input->post('passwordEdit') === null) {
  148.                 $passEdit       = password_hash($this->input->post('passwordEdit'), PASSWORD_BCRYPT);
  149.             } else {
  150.                 $passEdit       = $pass[0]['password'];
  151.             }
  152.  
  153.             $update     = [
  154.                 'users_name'            => htmlentities($this->input->post('name')),
  155.                 'username'              => htmlentities($this->input->post('username')),
  156.                 'password'              => $passEdit,
  157.                 'role_id'               => htmlentities($this->input->post('role'))
  158.             ];
  159.  
  160.             // Update Into Database
  161.             if ($this->Dashboard->update('tbl_users', 'id_users', $id, $update)) {
  162.                 helper_log('edit', $this->session->userdata('username') . ' Successfully Updated Users ID ' . $id . ' !!!', 'Updated ID ' . $id);
  163.                 $this->toastr->success('Username = ' . $this->session->userdata('username') . ' Successfully Updated Users Data !!!');
  164.  
  165.                 redirect('master/Users', 'refresh');
  166.             }
  167.         }
  168.     }
  169.  
  170.     // Action Delete Users Data
  171.     public function ActionDeleteUsers($id = 0)
  172.     {
  173.         if ($id !== '0') {
  174.             if ($this->Dashboard->delete('id_users', 'tbl_users', $id)) {
  175.                 helper_log('delete', $this->session->userdata('username') . ' Successfully Delete Users ID = ' . $id . ' !!!', 'Deleted ID ' . $id);
  176.                 $this->toastr->success('Username = ' . $this->session->userdata('username') . ' Successfully Deleted Users ID : ' . $id . ' !!!');
  177.  
  178.                 redirect('master/Users', 'refresh');
  179.             }
  180.         } else {
  181.             redirect('Dashboard.html', 'refresh');
  182.         }
  183.     }
  184.  
  185.     // View Jabatan
  186.     public function Jabatan()
  187.     {
  188.         $data        = [
  189.             'titles'        => "Dashboard Administrator || View Jabatan Pages",
  190.             'settings'      => $this->Dashboard->viewAll('*', 'tbl_setting')->result_array(),
  191.             'user'            => $this->Dashboard->viewWhere('tbl_users', 'id_users', $this->session->userdata('id'))->result_array(),
  192.             'version'       => $this->Dashboard->viewWhere('tbl_version', 'id_version', 1)->result_array(),
  193.             'jenis'         => $this->Dashboard->viewAll('*', 'tbl_jenis_jabatan')->result_array(),
  194.             'perangkat'     => $this->Dashboard->viewAll('*', 'tbl_perangkat')->result_array(),
  195.             'viewJabatan'   => true,
  196.             'card_title'    => 'Data Jabatan',
  197.             'breadcumb'        => "View Jabatan",
  198.             'view'            => "v_Jabatan"
  199.         ];
  200.  
  201.         $this->load->view("index", $data);
  202.     }
  203.  
  204.     // Json View Datatable Jabatan
  205.     public function jsonJabatan()
  206.     {
  207.         header('Content-Type: application/json');
  208.  
  209.         $join = array(
  210.             ['tbl_jenis_jabatan', 'tbl_jabatan.jenis_jabatan=tbl_jenis_jabatan.id_jenis_jabatan', 'LEFT'],
  211.             ['tbl_perangkat', 'tbl_jabatan.id_perangkat=tbl_perangkat.id_perangkat', 'LEFT']
  212.         );
  213.  
  214.         echo $this->Dashboard->jsonGlobalJoin(
  215.             '
  216.                tbl_jabatan.id_jabatan AS id_jabatan,
  217.                tbl_jabatan.nama_jabatan AS nama_jabatan,
  218.                tbl_jabatan.kelas AS kelas,
  219.                tbl_jabatan.pagu AS pagu,
  220.                tbl_jenis_jabatan.nama_jenis_jabatan AS nama_jenis_jabatan,
  221.                tbl_perangkat.nama_perangkat AS nama_perangkat,
  222.            ',
  223.             'tbl_jabatan',
  224.             $join
  225.         );
  226.     }
  227.  
  228.     // Action Add Jabatan Data
  229.     public function ActionAddJabatan()
  230.     {
  231.         $data = array('success' => false, 'messages' => array());
  232.  
  233.         $this->form_validation->set_rules("name", "name", "trim|min_length[3]|required");
  234.         $this->form_validation->set_rules("jenisjabatan", "Jenis Jabatan", "trim|required");
  235.         $this->form_validation->set_rules("instansi", "Nama Instansi", "trim|required");
  236.         $this->form_validation->set_rules("kelas", "Kelas", "trim|required");
  237.         $this->form_validation->set_rules("pagu", "Pagu", "trim|required");
  238.         $this->form_validation->set_error_delimiters('<p class="text-danger">', '</p>');
  239.  
  240.         if ($this->form_validation->run()) {
  241.             $input     = [
  242.                 'nama_jabatan'              => htmlentities($this->input->post('name')),
  243.                 'jenis_jabatan'             => htmlentities($this->input->post('jenisjabatan')),
  244.                 'id_perangkat'              => htmlentities($this->input->post('instansi')),
  245.                 'kelas'                     => htmlentities($this->input->post('kelas')),
  246.                 'pagu'                      => str_replace(",", "", htmlentities($this->input->post('pagu')))
  247.             ];
  248.  
  249.             if ($this->Dashboard->insert('tbl_jabatan', $input)) {
  250.                 $this->toastr->success('Username = ' . $this->session->userdata('username') . ' Successfully Inserted New Jabatan !!!');
  251.  
  252.                 helper_log('add', $this->session->userdata('username') . ' Successfully Inserted New Jabatan !!!', 'Inserted Jabatan ' . $input['nama_jabatan']);
  253.                 $data['success']            = true;
  254.             }
  255.         } else {
  256.             foreach ($_POST as $key => $value) {
  257.                 $data['messages'][$key]     = form_error($key);
  258.             }
  259.         }
  260.  
  261.         echo json_encode($data);
  262.     }
  263.  
  264.     // View Jabatan Data
  265.     public function ViewEditJabatan($id = 0)
  266.     {
  267.         $data        = [
  268.             'titles'        => "Dashboard Administrator || View Jabatan Pages",
  269.             'settings'      => $this->Dashboard->viewAll('*', 'tbl_setting')->result_array(),
  270.             'user'            => $this->Dashboard->viewWhere('tbl_users', 'id_users', $this->session->userdata('id'))->result_array(),
  271.             'version'       => $this->Dashboard->viewWhere('tbl_version', 'id_version', 1)->result_array(),
  272.             'jenis'         => $this->Dashboard->viewAll('*', 'tbl_jenis_jabatan')->result_array(),
  273.             'perangkat'     => $this->Dashboard->viewAll('*', 'tbl_perangkat')->result_array(),
  274.             'EditData'      => $this->Dashboard->viewWhere('tbl_jabatan', 'id_jabatan', $id)->result_array(),
  275.             'viewJabatan'   => true,
  276.             'card_title'    => 'Data Jabatan',
  277.             'breadcumb'        => "View Jabatan",
  278.             'view'            => "v_EditJabatan"
  279.         ];
  280.  
  281.         $this->load->view("index", $data);
  282.     }
  283.  
  284.     // Action Edit Data Jabatan
  285.     public function ActionEditJabatan()
  286.     {
  287.         $this->form_validation->set_rules("name", "name", "trim|min_length[3]|required");
  288.         $this->form_validation->set_rules("jenisjabatan", "Jenis Jabatan", "trim|required");
  289.         $this->form_validation->set_rules("instansi", "Nama Instansi", "trim|required");
  290.         $this->form_validation->set_rules("kelas", "Kelas", "trim|required");
  291.         $this->form_validation->set_rules("pagu", "Pagu", "trim|required");
  292.  
  293.         $id                         = decrypt_url(htmlentities($this->input->post('idEdit')));
  294.  
  295.         if ($this->form_validation->run() === false) {
  296.             $this->ViewEditJabatan($id);
  297.         } else {
  298.  
  299.             $update     = [
  300.                 'nama_jabatan'              => htmlentities($this->input->post('name')),
  301.                 'jenis_jabatan'             => htmlentities($this->input->post('jenisjabatan')),
  302.                 'id_perangkat'              => htmlentities($this->input->post('instansi')),
  303.                 'kelas'                     => htmlentities($this->input->post('kelas')),
  304.                 'pagu'                      => str_replace(",", "", htmlentities($this->input->post('pagu')))
  305.             ];
  306.  
  307.             // Update Into Database
  308.             if ($this->Dashboard->update('tbl_jabatan', 'id_jabatan', $id, $update)) {
  309.                 helper_log('edit', $this->session->userdata('username') . ' Successfully Updated Jabatan ID ' . $id . ' !!!', 'Updated ID ' . $id);
  310.                 $this->toastr->success('Username = ' . $this->session->userdata('username') . ' Successfully Updated Jabatan Data ID ' . $id . ' !!!');
  311.  
  312.                 redirect('master/Jabatan', 'refresh');
  313.             }
  314.         }
  315.     }
  316.  
  317.     // Action Delete Jabatan Data
  318.     public function ActionDeleteJabatan($id = 0)
  319.     {
  320.         if ($id !== '0') {
  321.             if ($this->Dashboard->delete('id_jabatan', 'tbl_jabatan', $id)) {
  322.                 helper_log('delete', $this->session->userdata('username') . ' Successfully Delete Jabatan ID = ' . $id . ' !!!', 'Deleted ID ' . $id);
  323.                 $this->toastr->info('Username = ' . $this->session->userdata('username') . ' Successfully Deleted Jabatan ID : ' . $id . ' !!!');
  324.  
  325.                 redirect('master/Jabatan', 'refresh');
  326.             }
  327.         } else {
  328.             redirect('dashboard', 'refresh');
  329.         }
  330.     }
  331.  
  332.     // View Golongan
  333.     public function Golongan()
  334.     {
  335.         $data        = [
  336.             'titles'        => "Dashboard Administrator || View Golongan Pages",
  337.             'settings'      => $this->Dashboard->viewAll('*', 'tbl_setting')->result_array(),
  338.             'user'            => $this->Dashboard->viewWhere('tbl_users', 'id_users', $this->session->userdata('id'))->result_array(),
  339.             'version'       => $this->Dashboard->viewWhere('tbl_version', 'id_version', 1)->result_array(),
  340.             'viewGolongan'  => true,
  341.             'card_title'    => 'Data Golongan',
  342.             'breadcumb'        => "View Golongan",
  343.             'view'            => "v_Golongan"
  344.         ];
  345.  
  346.         $this->load->view("index", $data);
  347.     }
  348.  
  349.     // Json View Datatable Golongan
  350.     public function jsonGolongan()
  351.     {
  352.         header('Content-Type: application/json');
  353.  
  354.         echo $this->Dashboard->json(
  355.             '
  356.                tbl_golongan.id_golongan AS id_golongan,
  357.                tbl_golongan.nama_golongan AS nama_golongan
  358.            ',
  359.             'tbl_golongan'
  360.         );
  361.     }
  362.  
  363.     // Action Add Golongan Data
  364.     public function ActionAddGolongan()
  365.     {
  366.         $data = array('success' => false, 'messages' => array());
  367.  
  368.         $this->form_validation->set_rules("golongan", "Nama Golongan", "trim|required");
  369.         $this->form_validation->set_error_delimiters('<p class="text-danger">', '</p>');
  370.  
  371.         if ($this->form_validation->run()) {
  372.             $input     = [
  373.                 'nama_golongan'         => htmlentities($this->input->post('golongan'))
  374.             ];
  375.  
  376.             if ($this->Dashboard->insert('tbl_golongan', $input)) {
  377.                 $this->toastr->success('Username = ' . $this->session->userdata('username') . ' Successfully Inserted New Golongan !!!');
  378.  
  379.                 helper_log('add', $this->session->userdata('username') . ' Successfully Inserted New Golongan !!!', 'Inserted Golongan ' . $input['nama_golongan']);
  380.                 $data['success']            = true;
  381.             }
  382.         } else {
  383.             foreach ($_POST as $key => $value) {
  384.                 $data['messages'][$key]     = form_error($key);
  385.             }
  386.         }
  387.  
  388.         echo json_encode($data);
  389.     }
  390.  
  391.     // View Golongan Data
  392.     public function ViewEditGolongan($id = 0)
  393.     {
  394.         $data        = [
  395.             'titles'        => "Dashboard Administrator || View Users Pages",
  396.             'settings'      => $this->Dashboard->viewAll('*', 'tbl_setting')->result_array(),
  397.             'user'            => $this->Dashboard->viewWhere('tbl_users', 'id_users', $this->session->userdata('id'))->result_array(),
  398.             'version'       => $this->Dashboard->viewWhere('tbl_version', 'id_version', 1)->result_array(),
  399.             'showEdit'      => $this->Dashboard->viewWhere('tbl_golongan', 'id_golongan', $id)->result_array(),
  400.             'jabatan'       => $this->Dashboard->viewAll('*', 'tbl_jabatan')->result_array(),
  401.             'golongan'      => $this->Dashboard->viewAll('*', 'tbl_golongan')->result_array(),
  402.             'viewGolongan'  => true,
  403.             'card_title'    => 'Data Golongan',
  404.             'breadcumb'        => "View Golongan",
  405.             'view'            => "v_EditGolongan"
  406.         ];
  407.  
  408.         $this->load->view("index", $data);
  409.     }
  410.  
  411.     // Action Edit Data Golongan
  412.     public function ActionEditGolongan()
  413.     {
  414.         $this->form_validation->set_rules("golongan", "Golongan", "trim|required");
  415.  
  416.         $id                         = decrypt_url(htmlentities($this->input->post('idEdit')));
  417.  
  418.         if ($this->form_validation->run() === false) {
  419.             $this->ViewEditGolongan($id);
  420.         } else {
  421.             $update     = [
  422.                 'nama_golongan'         => htmlentities($this->input->post('golongan'))
  423.             ];
  424.  
  425.             // Update Into Database
  426.             if ($this->Dashboard->update('tbl_golongan', 'id_golongan', $id, $update)) {
  427.                 helper_log('edit', $this->session->userdata('username') . ' Successfully Updated Golongan ID ' . $id . ' !!!', 'Updated ID ' . $id);
  428.                 $this->toastr->success('Username = ' . $this->session->userdata('username') . ' Successfully Updated Golongan Data !!!');
  429.  
  430.                 redirect('master/Golongan', 'refresh');
  431.             }
  432.         }
  433.     }
  434.  
  435.     // Action Delete Golongan Data
  436.     public function ActionDeleteGolongan($id = 0)
  437.     {
  438.         if ($id !== '0') {
  439.             if ($this->Dashboard->delete('id_golongan', 'tbl_golongan', $id)) {
  440.                 helper_log('delete', $this->session->userdata('username') . ' Successfully Delete Golongan ID = ' . $id . ' !!!', 'Deleted ID ' . $id);
  441.                 $this->toastr->info('Username = ' . $this->session->userdata('username') . ' Successfully Deleted Golongan ID : ' . $id . ' !!!');
  442.  
  443.                 redirect('master/Golongan', 'refresh');
  444.             }
  445.         } else {
  446.             redirect('dashboard', 'refresh');
  447.         }
  448.     }
  449.  
  450.     // View Employeer
  451.     public function Employeer()
  452.     {
  453.         $data        = [
  454.             'titles'        => "Dashboard Administrator || View Users Pages",
  455.             'settings'      => $this->Dashboard->viewAll('*', 'tbl_setting')->result_array(),
  456.             'user'            => $this->Dashboard->viewWhere('tbl_users', 'id_users', $this->session->userdata('id'))->result_array(),
  457.             'version'       => $this->Dashboard->viewWhere('tbl_version', 'id_version', 1)->result_array(),
  458.             'viewEmployeer' => true,
  459.             'card_title'    => 'Data Employeer',
  460.             'breadcumb'        => "View Employeer",
  461.             'view'            => "v_Employeer"
  462.         ];
  463.  
  464.         $this->load->view("index", $data);
  465.     }
  466.  
  467.     // Json View Datatable Employeer
  468.     public function jsonEmployeer()
  469.     {
  470.         header('Content-Type: application/json');
  471.  
  472.         $join = array(
  473.             ['tbl_jabatan', 'tbl_pegawai.id_jabatan=tbl_jabatan.id_jabatan', 'LEFT'],
  474.             ['tbl_golongan', 'tbl_pegawai.id_golongan=tbl_golongan.id_golongan', 'LEFT'],
  475.             ['tbl_status', 'tbl_pegawai.id_status=tbl_status.id', 'LEFT']
  476.         );
  477.  
  478.         echo $this->Dashboard->jsonGlobalJoin(
  479.             '
  480.                tbl_pegawai.id_pegawai AS id_pegawai,
  481.                tbl_pegawai.nip AS nip,
  482.                tbl_pegawai.nama_pegawai AS nama_pegawai,
  483.                tbl_pegawai.tempat_lahir AS tempat_lahir,
  484.                tbl_pegawai.tanggal_lahir AS tanggal_lahir,
  485.                tbl_pegawai.tanggal_masuk AS tanggal_masuk,
  486.                tbl_jabatan.nama_jabatan AS nama_jabatan,
  487.                tbl_golongan.nama_golongan AS nama_golongan,
  488.                tbl_status.status AS status
  489.            ',
  490.             'tbl_pegawai',
  491.             $join
  492.         );
  493.     }
  494.  
  495.     // View Employeer Data
  496.     public function ViewEditEmployeer($id = 0)
  497.     {
  498.         $join       = array(
  499.             ['tbl_perangkat', 'tbl_jabatan.id_perangkat=tbl_perangkat.id_perangkat', 'LEFT']
  500.         );
  501.         $data        = [
  502.             'titles'        => "Dashboard Administrator || View Users Pages",
  503.             'settings'      => $this->Dashboard->viewAll('*', 'tbl_setting')->result_array(),
  504.             'user'            => $this->Dashboard->viewWhere('tbl_users', 'id_users', $this->session->userdata('id'))->result_array(),
  505.             'version'       => $this->Dashboard->viewWhere('tbl_version', 'id_version', 1)->result_array(),
  506.             'showEdit'      => $this->Dashboard->viewWhere('tbl_pegawai', 'id_pegawai', $id)->result_array(),
  507.             'jabatan'       => $this->Dashboard->viewGlobalJoin(
  508.                 '
  509.                    tbl_jabatan.id_jabatan,
  510.                    tbl_jabatan.nama_jabatan,
  511.                    tbl_jabatan.pagu,
  512.                    tbl_jabatan.id_perangkat,
  513.                    tbl_perangkat.nama_perangkat
  514.                ',
  515.                 'tbl_jabatan',
  516.                 $join
  517.             )->result_array(),
  518.             'golongan'      => $this->Dashboard->viewAll('*', 'tbl_golongan')->result_array(),
  519.             'status'        => $this->Dashboard->viewAll('*', 'tbl_status')->result_array(),
  520.             'viewEmployeer' => true,
  521.             'card_title'    => 'Data Employeer',
  522.             'breadcumb'        => "View Employeer",
  523.             'view'            => "v_EditEmployeer"
  524.         ];
  525.  
  526.         $this->load->view("index", $data);
  527.     }
  528.  
  529.     // Action Edit Data Employeer
  530.     public function ActionEditEmployeer()
  531.     {
  532.         $this->form_validation->set_rules("nik", "Nomor Induk Pegawai", "trim|min_length[16]|required");
  533.         $this->form_validation->set_rules("nama_pegawai", "Nama Pegawai", "trim|required");
  534.         $this->form_validation->set_rules("tempat_lahir", "Tempat Lahir", "trim|required");
  535.         $this->form_validation->set_rules("tgl_lahir", "Tanggal Lahir", "trim|required");
  536.         $this->form_validation->set_rules("jabatan", "Jabatan", "trim|required");
  537.         $this->form_validation->set_rules("golongan", "Golongan", "trim|required");
  538.         $this->form_validation->set_rules("id_status", "Status", "trim|required");
  539.  
  540.         $id                         = decrypt_url(htmlentities($this->input->post('idEdit')));
  541.  
  542.         if ($this->form_validation->run() === false) {
  543.             $this->ViewEditEmployeer($id);
  544.         } else {
  545.             $pisahIn                = explode(" ", $this->input->post('tgl_lahir'));
  546.             $tgl_lahir              = $pisahIn[2] . '-' . getConvertBulan($pisahIn[1]) . '-' . $pisahIn[0];
  547.  
  548.             $pisahIn1               = explode(" ", $this->input->post('tgl_masuk'));
  549.             $tgl_masuk              = $pisahIn1[2] . '-' . getConvertBulan($pisahIn1[1]) . '-' . $pisahIn1[0];
  550.  
  551.             // Check Pegawai
  552.             $checkPegawai           = $this->Dashboard->viewWhere('tbl_pegawai', 'id_pegawai', $id)->result_array();
  553.  
  554.             if ($checkPegawai[0]['nip'] === '') {
  555.                 $update     = [
  556.                     'nip'                   => htmlentities($this->input->post('nik')),
  557.                     'nama_pegawai'          => htmlentities($this->input->post('nama_pegawai')),
  558.                     'tempat_lahir'          => htmlentities($this->input->post('tempat_lahir')),
  559.                     'tanggal_lahir'         => $tgl_lahir,
  560.                     'tanggal_masuk'         => $tgl_masuk,
  561.                     'id_jabatan'            => htmlentities($this->input->post('jabatan')),
  562.                     'id_golongan'           => htmlentities($this->input->post('golongan')),
  563.                     'id_status'                => htmlentities($this->input->post('id_status'))
  564.                 ];
  565.             } else {
  566.                 $update     = [
  567.                     'nama_pegawai'          => htmlentities($this->input->post('nama_pegawai')),
  568.                     'tempat_lahir'          => htmlentities($this->input->post('tempat_lahir')),
  569.                     'tanggal_lahir'         => $tgl_lahir,
  570.                     'tanggal_masuk'         => $tgl_masuk,
  571.                     'id_jabatan'            => htmlentities($this->input->post('jabatan')),
  572.                     'id_golongan'           => htmlentities($this->input->post('golongan')),
  573.                     'id_status'                => htmlentities($this->input->post('id_status')),
  574.                 ];
  575.             }
  576.  
  577.             // Check nip Already On Database
  578.             // $checknip           = $this->Dashboard->viewWhere('tbl_pegawai','nip', htmlentities($this->input->post('nip')))->num_rows();
  579.  
  580.             // if($checknip === 0){
  581.             // Update Into Database
  582.             if ($this->Dashboard->update('tbl_pegawai', 'id_pegawai', $id, $update)) {
  583.                 helper_log('edit', $this->session->userdata('username') . ' Successfully Updated Employeer ID ' . $id . ' !!!', 'Updated ID ' . $id);
  584.                 $this->toastr->success('Username = ' . $this->session->userdata('username') . ' Successfully Updated Employeer Data !!!');
  585.  
  586.                 redirect('master/Employeer', 'refresh');
  587.             }
  588.             // }else{
  589.             //     helper_log('failed', $this->session->userdata('username').' Failed Updated Employeer ID '.$id.' Cause nip Already Exist !!!', 'Failed Updated ID '.$id);
  590.             //     $this->toastr->error('Username = ' . $this->session->userdata('username') . ' Failed Updated Employeer ID '.$id.' Cause nip Already Exist !!!');
  591.  
  592.             //     redirect('master/Employeer', 'refresh');
  593.             // }
  594.         }
  595.     }
  596.  
  597.     // Action Delete Employeer Data
  598.     public function ActionDeleteEmployeer($id = 0)
  599.     {
  600.         if ($id !== '0') {
  601.             if ($this->Dashboard->delete('id_pegawai', 'tbl_pegawai', $id)) {
  602.                 helper_log('delete', $this->session->userdata('username') . ' Successfully Delete Pegawai ID = ' . $id . ' !!!', 'Deleted ID ' . $id);
  603.                 $this->toastr->info('Username = ' . $this->session->userdata('username') . ' Successfully Deleted Pegawai ID : ' . $id . ' !!!');
  604.  
  605.                 redirect('master/Employeer', 'refresh');
  606.             }
  607.         } else {
  608.             redirect('dashboard', 'refresh');
  609.         }
  610.     }
  611.  
  612.     // Make Account Employeer
  613.     public function MakeAccountEmployeer($id = 0)
  614.     {
  615.         if ($id != 0) {
  616.  
  617.             // Check ID Pegawai
  618.             $checkPegawai       = $this->Dashboard->viewWhere('tbl_pegawai', 'id_pegawai', $id)->result_array();
  619.  
  620.             if ($checkPegawai[0]['nip'] === '') {
  621.                 helper_log('failed', $this->session->userdata('username') . ' Failed Create Users Account For Pegawai = ' . $checkPegawai[0]['nama_pegawai'] . ' Cause Nip is Empty!!!', 'Failed to Created Users ' . $checkPegawai[0]['nama_pegawai']);
  622.                 $this->toastr->error('Username = ' . $this->session->userdata('username') . ' Failed Create Users Account For Pegawai = ' . $checkPegawai[0]['nama_pegawai'] . ' Cause Nip is Empty!!!');
  623.  
  624.                 redirect('master/Employeer', 'refresh');
  625.             } else {
  626.                 // Check if Username Exist
  627.                 $checkUsername      = $this->Dashboard->viewWhere('tbl_users', 'username', $checkPegawai[0]['nip'])->num_rows();
  628.  
  629.                 if ($checkUsername === 0) {
  630.                     $username   = $checkPegawai[0]['nip'];
  631.                 } else {
  632.                     $username   = '';
  633.                 }
  634.  
  635.                 // Buat Akun
  636.                 $createAccount      = [
  637.                     'users_name'    => $checkPegawai[0]['nama_pegawai'],
  638.                     'username'      => $username,
  639.                     'password'      => password_hash('123456', PASSWORD_BCRYPT),
  640.                     'role_id'       => 3,
  641.                     'userid'        => $checkPegawai[0]['userid_machines']
  642.                 ];
  643.  
  644.                 // Check if on tbl_users exist that usersname
  645.                 $checkAccount       = $this->Dashboard->viewWhere('tbl_users', 'users_name', $createAccount['users_name'])->num_rows();
  646.  
  647.                 if ($checkAccount === 0) {
  648.                     if ($this->Dashboard->insert('tbl_users', $createAccount)) {
  649.                         helper_log('add', $this->session->userdata('username') . ' Successfully Create Users Account For Pegawai = ' . $checkPegawai[0]['nama_pegawai'] . ' !!!', 'Created Users ' . $createAccount['users_name']);
  650.                         $this->toastr->success('Username = ' . $this->session->userdata('username') . ' Successfully Created Pegawai Account for Pegawai : ' . $checkPegawai[0]['nama_pegawai'] . ' !!!');
  651.  
  652.                         redirect('master/Employeer', 'refresh');
  653.                     }
  654.                 } else {
  655.                     $this->toastr->warning('Username = ' . $this->session->userdata('username') . ' Created Pegawai Account for Pegawai : ' . $checkPegawai[0]['nama_pegawai'] . ' Exists On Database !!!');
  656.  
  657.                     redirect('master/Employeer', 'refresh');
  658.                 }
  659.             }
  660.         }
  661.     }
  662.  
  663.     // View Holiday
  664.     public function Holiday()
  665.     {
  666.         $data        = [
  667.             'titles'        => "Dashboard Administrator || View Holiday Pages",
  668.             'settings'      => $this->Dashboard->viewAll('*', 'tbl_setting')->result_array(),
  669.             'user'            => $this->Dashboard->viewWhere('tbl_users', 'id_users', $this->session->userdata('id'))->result_array(),
  670.             'version'       => $this->Dashboard->viewWhere('tbl_version', 'id_version', 1)->result_array(),
  671.             'jenis'         => $this->Dashboard->viewAll('*', 'tbl_jenis_libur')->result_array(),
  672.             'viewHoliday'   => true,
  673.             'card_title'    => 'Data Holiday',
  674.             'breadcumb'        => "View Holiday",
  675.             'view'            => "v_Holiday"
  676.         ];
  677.  
  678.         $this->load->view("index", $data);
  679.     }
  680.  
  681.     // Json View Datatable Holiday
  682.     public function jsonHoliday()
  683.     {
  684.         header('Content-Type: application/json');
  685.  
  686.         echo $this->Dashboard->json(
  687.             '
  688.                tbl_libur.id_libur AS id_libur,
  689.                tbl_libur.tgl_libur AS tgl_libur,
  690.                tbl_libur.keterangan AS keterangan,
  691.                tbl_libur.type AS type
  692.            ',
  693.             'tbl_libur'
  694.         );
  695.     }
  696.  
  697.     // Action Add Holiday Data
  698.     public function ActionAddHoliday()
  699.     {
  700.         $data = array('success' => false, 'messages' => array());
  701.  
  702.         $this->form_validation->set_rules("tgl_libur", "Tanggal Libur", "trim|required");
  703.         $this->form_validation->set_rules("keterangan", "Keterangan", "trim|required");
  704.         $this->form_validation->set_rules("jenislibur", "Jenis Libur", "trim|required");
  705.         $this->form_validation->set_error_delimiters('<p class="text-danger">', '</p>');
  706.  
  707.         if ($this->form_validation->run()) {
  708.             // Rubah Format Tgl Libur Ke Dalam Format Mysql
  709.             $pisah      = explode(" ", $this->input->post('tgl_libur'));
  710.             $tgl_libur  = $pisah[2] . '-' . getConvertBulan($pisah[1]) . '-' . $pisah[0];
  711.  
  712.             $input     = [
  713.                 'tgl_libur'         => $tgl_libur,
  714.                 'keterangan'        => htmlentities($this->input->post('keterangan')),
  715.                 'type'              => htmlentities($this->input->post('jenislibur'))
  716.             ];
  717.  
  718.             if ($this->Dashboard->insert('tbl_libur', $input)) {
  719.                 $this->toastr->success('Username = ' . $this->session->userdata('username') . ' Successfully Inserted New Holiday !!!');
  720.  
  721.                 helper_log('add', $this->session->userdata('username') . ' Successfully Inserted New Holiday !!!', 'Inserted Holiday ' . $input['keterangan']);
  722.                 $data['success']            = true;
  723.             }
  724.         } else {
  725.             foreach ($_POST as $key => $value) {
  726.                 $data['messages'][$key]     = form_error($key);
  727.             }
  728.         }
  729.  
  730.         echo json_encode($data);
  731.     }
  732.  
  733.     // View Holiday Data
  734.     public function ViewEditHoliday($id = 0)
  735.     {
  736.         $data        = [
  737.             'titles'        => "Dashboard Administrator || View Edit Holiday Pages",
  738.             'settings'      => $this->Dashboard->viewAll('*', 'tbl_setting')->result_array(),
  739.             'user'            => $this->Dashboard->viewWhere('tbl_users', 'id_users', $this->session->userdata('id'))->result_array(),
  740.             'version'       => $this->Dashboard->viewWhere('tbl_version', 'id_version', 1)->result_array(),
  741.             'showEdit'      => $this->Dashboard->viewWhere('tbl_libur', 'id_libur', $id)->result_array(),
  742.             'jenis'         => $this->Dashboard->viewAll('*', 'tbl_jenis_libur')->result_array(),
  743.             'viewHoliday'   => true,
  744.             'card_title'    => 'Data Holiday',
  745.             'breadcumb'        => "View Holiday",
  746.             'view'            => "v_EditHoliday"
  747.         ];
  748.  
  749.         $this->load->view("index", $data);
  750.     }
  751.  
  752.     // Action Edit Data Holiday
  753.     public function ActionEditHoliday()
  754.     {
  755.         $this->form_validation->set_rules("tgl_libur", "Tanggal Libur", "trim|required");
  756.         $this->form_validation->set_rules("keterangan", "Keterangan", "trim|required");
  757.         $this->form_validation->set_rules("jenislibur", "Jenis Libur", "trim|required");
  758.  
  759.         $id                         = decrypt_url(htmlentities($this->input->post('idEdit')));
  760.  
  761.         if ($this->form_validation->run() === false) {
  762.             $this->ViewEditHoliday($id);
  763.         } else {
  764.             $pisahIn                = explode(" ", $this->input->post('tgl_libur'));
  765.             $tgl_libur              = $pisahIn[2] . '-' . getConvertBulan($pisahIn[1]) . '-' . $pisahIn[0];
  766.  
  767.             $update                 = [
  768.                 'tgl_libur'         => $tgl_libur,
  769.                 'keterangan'        => htmlentities($this->input->post('keterangan')),
  770.                 'type'              => htmlentities($this->input->post('jenislibur'))
  771.             ];
  772.  
  773.             // Update Into Database
  774.             if ($this->Dashboard->update('tbl_libur', 'id_libur', $id, $update)) {
  775.                 helper_log('edit', $this->session->userdata('username') . ' Successfully Updated Holiday ID ' . $id . ' !!!', 'Updated ID ' . $id);
  776.                 $this->toastr->success('Username = ' . $this->session->userdata('username') . ' Successfully Updated Holiday Data !!!');
  777.  
  778.                 redirect('master/Holiday', 'refresh');
  779.             }
  780.         }
  781.     }
  782.  
  783.     // Action Delete Holiday Data
  784.     public function ActionDeleteHoliday($id = 0)
  785.     {
  786.         if ($id !== '0') {
  787.             if ($this->Dashboard->delete('id_libur', 'tbl_libur', $id)) {
  788.                 helper_log('delete', $this->session->userdata('username') . ' Successfully Delete Holiday ID = ' . $id . ' !!!', 'Deleted ID ' . $id);
  789.                 $this->toastr->success('Username = ' . $this->session->userdata('username') . ' Successfully Deleted Holiday ID : ' . $id . ' !!!');
  790.  
  791.                 redirect('master/Holiday', 'refresh');
  792.             }
  793.         } else {
  794.             redirect('Dashboard.html', 'refresh');
  795.         }
  796.     }
  797. }
  798.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement