%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\Informasi_footer_Model; class Informasi_footer extends BaseController { protected $History; protected $session; protected $Informasi_footer_Model; public function __construct() { $this->History = new History_model(); $this->session = session(); $this->Informasi_footer_Model = new Informasi_footer_Model(); } 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' => '31', 'page1' => 'Add Informasi', 'page2' => 'Informasi', 'link01' => base_url() . '/informasi_footer/add', 'link02' => base_url() . '/informasi_footer', 'title' => old('title'), 'introtext' => old('introtext'), 'active' => 0, 'id' => 0, 'status' => 'add', 'url_form' => base_url('informasi_footer/save'), 'componen' => 'theme/BeyondAdmin/halaman/modul/informasi_footer/add' ); echo view('layout', $data); } public function index() { $user_id = session()->get('user_id'); $username = session()->get('username'); $firstname = session()->get('firstname'); $lastname = session()->get('lastname'); $id = 16; // $this->data_dashboard = new DashboardModel(); $dt_data = $this->Informasi_footer_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' => '11', 'parent_id_submenu' => '', 'id_menu' => '31', 'page1' => 'Edit Informasi Footer', 'page2' => 'Informasi Footer', 'link01' => base_url() . '/informasi_footer/edit', 'link02' => base_url() . '/informasi_footer', 'title' => $dt_data[0]->title, 'alias' => $dt_data[0]->alias, 'catid' => $dt_data[0]->catid, 'internaltags' => old('internaltags'), 'publish_up' => $dt_data[0]->publish_up, 'published' => $dt_data[0]->published, 'introtext' => $dt_data[0]->introtext, 'fulltexts' => $dt_data[0]->fulltexts, 'metadesc' => $dt_data[0]->metadesc, 'metakey' => $dt_data[0]->metakey, 'active' => $dt_data[0]->active, 'id' => $dt_data[0]->id, 'url_image' => $dt_data[0]->url_image, 'video' => $dt_data[0]->video, 'data_baru' => 'T', 'status' => 'edit', 'url_form' => base_url('informasi_footer/update'), 'componen' => 'theme/BeyondAdmin/halaman/modul/informasi_footer/add' ); echo view('layout', $data); } public function save() { 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 { $active = 0; // $this->request->getVar('active'); if (!is_null($this->request->getVar('active'))) { $active = 1; } $data = array( 'title' => $this->request->getVar('title'), 'introtext' => $this->request->getVar('introtext'), 'active' => $active, ); $this->Informasi_footer_Model->save_data($data); return redirect()->to(base_url('informasi_footer')); } } 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/sistemnusantara.com/compro.sistemnusantara.com"; // $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(); // ------ 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); // } // 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' => 5, 'publish_up' => $publish_up, 'published' => $published, 'introtext' => substr(($this->request->getVar('fulltexts')), 0, 550), 'fulltexts' => $this->request->getVar('fulltexts'), 'metadesc' => $this->request->getVar('metadesc'), 'metakey' => $this->request->getVar('metakey'), //'video' => $this->request->getVar('video'), 'active' => $published, 'modified_by' => $user_id, //'url_image' => $url_image, ); $this->Informasi_footer_Model->update_data($data, $id); return redirect()->to(base_url('informasi_footer')); } } public function delete($id) { $data = array( 'trash' => 1, ); $this->Informasi_footer_Model->update_data($data, $id); return redirect()->to(base_url('informasi_footer')); } 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->Informasi_footer_Model->update_data($data, $id); // return redirect()->to(base_url('informasi_footer')); } function simpan_active() { $id = $this->request->getVar('ids'); $active = $this->request->getVar('cek'); $data = array( 'active' => $active, ); $this->Informasi_footer_Model->update_data($data, $id); } function simpan_publish() { $id = $this->request->getVar('ids'); $active = $this->request->getVar('cek'); $data = array( 'published' => $active, ); $this->Informasi_footer_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; } } ?>