D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
ksclnmuac
/
www
/
ci_panel
/
application
/
controllers
/
admin
/
Filename :
Slider.php
back
Copy
<?php class Slider 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(base_url('admin/login/index')); } } public function create() { // ===> view code start # code... $data = []; // for sidebar $data['mainModule'] = 'slider'; $data['subModule'] = 'slider'; $this->load->library('form_validation'); $this->load->model('Slider_model'); $slider = $this->Slider_model->getSlider(); $data['slider'] = $slider; // print_r($slider); // ===> view code end # code... $config['upload_path'] = './public/uploads/slider/'; $config['allowed_types'] = 'png|jpeg|jpg'; $config['encrypt_name'] = TRUE; $this->load->library('upload', $config); $this->form_validation->set_rules('text1', 'Text1', 'trim|required'); $this->form_validation->set_rules('text2', 'Text2', 'trim|required'); $this->form_validation->set_error_delimiters('<p class="invalid-feedback">', '</p>'); if($this->form_validation->run() == true){ if(!empty($_FILES['image']['name'])){ if($this->upload->do_upload('image')){ // uploading image and inserting data in database $data = $this->upload->data(); $formArray = []; $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->Slider_model->addSlider($formArray); $this->session->set_flashdata('success', 'Slider Uploaded Successfully!'); redirect(base_url().'admin/slider/create'); }else{ $error = $this->upload->display_errors('<p class="invalid-feedback">', '</p>'); $data['error'] = $error; redirect(base_url().'admin/slider/create'); } } else{ $error = $this->upload->display_errors('<p class="invalid-feedback">', '</p>'); redirect(base_url().'admin/slider/create'); } }else{ $this->load->view("admin/slider", $data); } } public function delete($id) { # code... $this->load->model('Slider_model'); $slide = $this->Slider_model->getSlide($id); if(empty($slide)){ $this->session->set_flashdata('error', 'Slider not found!'); redirect(base_url().'admin/slider/create'); }else{ if(file_exists('./public/uploads/slider/'.$slide[0]['pic'])){ unlink('./public/uploads/slider/'.$slide[0]['pic']); } $this->Slider_model->deleteSlider($id); $this->session->set_flashdata('success', 'Slider deleted successfully!'); redirect(base_url().'admin/slider/create'); } } public function getDataAjax($id) { # code... $this->load->model('Slider_model'); $temp_slide = $this->Slider_model->getSlide($id); $slide = json_encode($temp_slide); echo $slide; } public function edit() { # code... $config['upload_path'] = './public/uploads/slider/'; $config['allowed_types'] = 'png|jpeg|jpg'; $config['encrypt_name'] = TRUE; $this->load->library('upload', $config); $this->load->library('form_validation'); $this->load->model('Slider_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){ // main threat for updation ---> $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 $slide = $this->Slider_model->getSlide($id); $path = './public/uploads/slider/'.$slide[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->Slider_model->editSlider($id, $formArray); $this->session->set_flashdata('success', 'Slider Updated Successfully!'); redirect(base_url().'admin/slider/create'); }else{ $error = $this->upload->display_errors("<p class='invalid-feedback'>", "</p>"); $data['errorFileUpload'] = $error; redirect(base_url().'admin/slider/create'); } }else{ $formArray = []; $formArray['text1'] = $this->input->post('etext1'); $formArray['text2'] = $this->input->post('etext2'); $this->Slider_model->editSlider($id, $formArray); $this->session->set_flashdata('success', 'Slider Updated Successfully!'); redirect(base_url().'admin/slider/create'); } }else{ $this->session->set_flashdata('error', 'Sorry, something went wrong!'); redirect(base_url().'admin/slider/create'); } } }