D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
ksclnmuac
/
www
/
ci_panel
/
application
/
controllers
/
admin
/
Filename :
Press.php
back
Copy
<?php class Press extends CI_controller{ public function __construct() { # code... parent::__construct(); $admin = $this->session->userdata('admin'); if(empty($admin)){ $this->session->set_flashdata('msg', 'Your session has been expired'); redirect('admin/login/index'); } } public function create() { // ====> view code start # code... $data = []; // for sidebar $data['mainModule'] = 'press'; $data['subModule'] = 'press'; $this->load->library('form_validation'); $this->load->model('Press_model'); $press = $this->Press_model->get_press(); $data['press'] = $press; // ====> view code end # code... $config['upload_path'] = './public/uploads/press/'; $config['allowed_types'] = 'png|jpeg|jpg'; $config['encrypt_name'] = TRUE; $this->load->library('upload', $config); $this->form_validation->set_rules('text1', 'Text 1', 'trim|required'); $this->form_validation->set_rules('text2', 'Text 2', 'trim|required'); $this->form_validation->set_error_delimiters('<p class="invalid-feedback">', '</p>'); if($this->form_validation->run()==true){ if($_FILES['image']['name']!=""){ if($this->upload->do_upload('image')){ $data = $this->upload->data(); $formArray['text1'] = $this->input->post('text1'); $formArray['text2'] = $this->input->post('text2'); $formArray['pic'] = $data['file_name']; $formArray['date'] = date('Y-m-d H:i:s'); $this->Press_model->add_press($formArray); $this->session->set_flashdata('success', 'Press Added Successfully!'); redirect(base_url().'admin/press/create'); }else{ $this->session->set_flashdata('error', 'Sorry, something went wrong!'); redirect(base_url().'admin/press/create'); } }else{ $this->session->set_flashdata('error', 'Sorry, something went wrong!'); redirect(base_url().'admin/press/create'); } }else{ $this->load->view('admin/press', $data); } } public function delete($id) { # code... // echo $id; $this->load->model('Press_model'); $press = $this->Press_model->getPressSingle($id); if(empty($press)){ $this->session->set_flashdata('error', 'Press not found!'); redirect(base_url().'admin/press/create'); }else{ if(file_exists('./public/uploads/press/'.$press[0]['pic'])){ unlink('./public/uploads/press/'.$press[0]['pic']); } $this->Press_model->deletePress($id); $this->session->set_flashdata('success', 'Press deleted successfully!'); redirect(base_url().'admin/press/create'); } } public function getDataAjax($id) { # code... $this->load->model('Press_model'); $tem_press = $this->Press_model->getPressSingle($id); $press = json_encode($tem_press); echo $press; } public function edit() { # code... # code... $config['upload_path'] = './public/uploads/press/'; $config['allowed_types'] = 'png|jpeg|jpg'; $config['encrypt_name'] = TRUE; $this->load->library('upload', $config); $this->load->library('form_validation'); $this->load->model('Press_model'); $this->form_validation->set_rules('etext1', 'Text1', 'trim|required'); $this->form_validation->set_rules('etext2', 'Text2', 'trim|required'); $this->form_validation->set_error_delimiters('<p class="invalid-feedback">', '</p>'); if($this->form_validation->run()==true){ $id = $this->input->post('eid'); if(!empty($_FILES['eimage']['name'])){ if($this->upload->do_upload('eimage')){ $data = $this->upload->data(); // unlink the older file first $press = $this->Press_model->getPressSingle($id); $path = './public/uploads/press/'.$press[0]['pic']; if(file_exists($path)){ unlink($path); } $formArray = []; $formArray['text1'] = $this->input->post('etext1'); $formArray['text2'] = $this->input->post('etext2'); $formArray['pic'] = $data['file_name']; $this->Press_model->editPress($id, $formArray); $this->session->set_flashdata('success', 'Press Updated Successfully!'); redirect(base_url().'admin/press/create'); }else{ $error = $this->upload->display_errors("<p class='invalid-feedback'>", "</p>"); $data['errorFileUpload'] = $error; redirect(base_url().'admin/press/create'); } }else{ $formArray = []; $formArray['text1'] = $this->input->post('etext1'); $formArray['text2'] = $this->input->post('etext2'); $this->Press_model->editPress($id, $formArray); $this->session->set_flashdata('success', 'Press Updated Successfully!'); redirect(base_url().'admin/press/create'); } }else{ $this->session->set_flashdata('error', 'Sorry, something went wrong!'); redirect(base_url().'admin/press/create'); } } }