policybot/application/controllers/Slider.php
2021-11-30 16:26:55 +05:30

158 lines
3.9 KiB
PHP

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Slider extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('Slider_model');
}
function list_slider()
{
if($this->session->userdata('id')==""){redirect('admin/login');}
$data['slider']=$this->Slider_model->list_sliders();
$this->load->view('admin/slider/list',$data);
}
function add_slider()
{
if($this->session->userdata('id')==""){redirect('admin/login');}
if($this->input->post("addslider"))
{
$Title=$this->input->post("Title");
$Subtitle=$this->input->post("Subtitle");
//make directory
if (!is_dir('uploads/slider')) {
mkdir('./uploads/slider', 0777, TRUE);
}
$valid_extensions = array('jpeg', 'jpg', 'png'); // valid extensions
$path = 'uploads/slider/'; // upload directory
if($_FILES['Image'])
{
$img = $_FILES['Image']['name'];
$tmp = $_FILES['Image']['tmp_name'];
// get uploaded file's extension
$ext = strtolower(pathinfo($img, PATHINFO_EXTENSION));
// can upload same image using rand function
$final_image = "Image".rand(1000,1000000).$img;
// check's valid format
if(in_array($ext, $valid_extensions))
{
$path = $path.strtolower($final_image);
if(move_uploaded_file($tmp,$path))
{
$table="slider";
$rvalue=array(
'title'=>$Title,
'subtitle'=>$Subtitle,
'image'=>$path,
'cdate'=>date('Y-m-d H:i:s'),
'cby'=>$this->session->userdata('id'),
'status'=>1);
if($Title!="" && $Subtitle!="" && $path!="") {
$result=$this->commonsql_model->insert_table($table,$rvalue);
}
} } }
if($result)
{
$this->session->set_userdata('suc','successfully added');
redirect('admin/slider');
}
else
{
$this->session->set_userdata('err','Please try again');
redirect('admin/slider');
}
}
$this->load->view('admin/slider/add');
}
function edit_slider($id)
{
if($this->session->userdata('id')==""){redirect('admin/login');}
if($this->input->post("editslider"))
{
$Title=$this->input->post("Title");
$Subtitle=$this->input->post("Subtitle");
$oldimage=$this->input->post("old_image");
$image=$this->input->post("Image");
if($Image=="") {
$simage=$oldimage;
}
if (!is_dir('uploads/slider')) {
mkdir('./uploads/slider', 0777, TRUE);
}
$valid_extensions = array('jpeg', 'jpg', 'png'); // valid extensions
$path = 'uploads/slider/'; // upload directory
if($_FILES['Image']['tmp_name'])
{
$img = $_FILES['Image']['name'];
$tmp = $_FILES['Image']['tmp_name'];
// get uploaded file's extension
$ext = strtolower(pathinfo($img, PATHINFO_EXTENSION));
// can upload same image using rand function
$final_image = "Image".rand(1000,1000000).$img;
// check's valid format
if(in_array($ext, $valid_extensions))
{
$simage = $path.strtolower($final_image);
if(move_uploaded_file($tmp,$simage))
{}} }
$tblname="slider";
$wheredata=(array('id'=>$id));
$values=array(
'title'=>$Title,
'subtitle'=>$Subtitle,
'image'=>$simage,
'udate'=>date('Y-m-d H:i:s'),
);
$result=$this->commonsql_model->updateTable($tblname,$wheredata,$values);
if($result)
{
$this->session->set_userdata('suc','successfully Updated');
redirect('admin/slider');
}
else
{
$this->session->set_userdata('err','Please try again');
redirect('admin/slider');
}
}
$data['slider']=$this->Slider_model->list_sliders($id);
$this->load->view('admin/slider/edit',$data);
}
function check_uncheck_slider()
{
$id=$_POST['id'];
$value=$_POST['val'];
$tblname="slider";
$where=array('id'=>$id);
$update=array('status'=>$value);
$results=$this->commonsql_model->updateTable($tblname,$where,$update);
if($results)
{
echo "1";
}
else
{
echo "2";
}
}
}
?>