%PDF-1.4
Directory : /var/www/vhosts/lautnusantara.com/httpdocs/mis/app/Controllers/ |
<?php namespace App\Controllers; use CodeIgniter\Controller; // use App\Models\DashboardModel; use App\Models\History_model; use App\Models\Hubungi_kami_Model; class Hubungi_kami extends BaseController { protected $History; protected $session; protected $Hubungi_kami_Model; public function __construct() { $this->History = new History_model(); $this->session = session(); $this->Hubungi_kami_Model = new Hubungi_kami_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' => 'Artikel', 'jenis_kegiatan' => 'Daftar Artikel', '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' => '11', 'page1' => 'Hubungi Kami', 'page2' => '', 'link01' => base_url() . '/hubungi_kami/add', 'link02' => base_url() . '/hubungi_kami', 'data_hubungi' => $this->Hubungi_kami_Model->get_data()->getResultArray(), 'componen' => 'theme/BeyondAdmin/halaman/modul/hubungi_kami/daftar' ); 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' => '2', 'id_menu' => '10', 'page1' => 'Add Artikel', 'page2' => 'Artikel', 'link01' => base_url() . '/hubungi_kami/add', 'link02' => base_url() . '/hubungi_kami', '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'), 'active' => 0, 'id' => 0, 'status' => 'add', 'data_baru' => 'Y', 'url_form' => base_url('hubungi_kami/save'), 'componen' => 'theme/BeyondAdmin/halaman/modul/hubungi_kami/add' ); 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'); // $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_hubungi = $this->Hubungi_kami_Model->get_data($id)->getResult(); $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' => '10', 'page1' => 'Balas Hubungi Kami', 'page2' => 'Hubungi Kami', 'link01' => base_url() . '/hubungi_kami/edit', 'link02' => base_url() . '/hubungi_kami', 'nama' => $dt_hubungi[0]->nama, 'created' => $dt_hubungi[0]->created, 'subjek' => $dt_hubungi[0]->subjek, 'email' => $dt_hubungi[0]->email, 'telp' => $dt_hubungi[0]->telp, 'pesan' => $dt_hubungi[0]->pesan, 'active' => $dt_hubungi[0]->active, 'id' => $dt_hubungi[0]->id, 'data_baru' => 'T', 'status' => 'edit', 'url_form' => base_url('hubungi_kami/update'), 'componen' => 'theme/BeyondAdmin/halaman/modul/hubungi_kami/kirim' ); 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' ] ] ]) ) { 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; } $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, ); $this->Hubungi_kami_Model->save_data($data); return redirect()->to(base_url('hubungi_kami')); } } public function update() { if ( !$this->validate([ 'title' => [ 'rules' => 'required|min_length[3]', 'errors' => [ 'required' => 'Judul 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; $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; } } } $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, ); $this->Hubungi_kami_Model->update_data($data, $id); return redirect()->to(base_url('hubungi_kami')); } } // 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->Hubungi_kami_Model->update_data($data, $id); return redirect()->to(base_url('artikel')); } 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->Hubungi_kami_Model->update_data($data, $id); // return redirect()->to(base_url('artikel')); } function simpan_active() { $id = $this->request->getVar('ids'); $active = $this->request->getVar('cek'); $data = array( 'active' => $active, ); $this->Hubungi_kami_Model->update_data($data, $id); } function simpan_publish() { $id = $this->request->getVar('ids'); $active = $this->request->getVar('cek'); $data = array( 'published' => $active, ); $this->Hubungi_kami_Model->update_data($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; } } ?>