169 lines
4.0 KiB
PHP
169 lines
4.0 KiB
PHP
|
<?php
|
||
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
||
|
|
||
|
class Testimonial extends CI_Controller {
|
||
|
public function __construct()
|
||
|
{
|
||
|
parent::__construct();
|
||
|
$this->load->model('Testimonial_model');
|
||
|
|
||
|
|
||
|
}
|
||
|
function list_testimonial()
|
||
|
{
|
||
|
if($this->session->userdata('id')==""){redirect('admin/login');}
|
||
|
$data['tes']=$this->Testimonial_model->list_testimonial();
|
||
|
$this->load->view('admin/testimonial/list',$data);
|
||
|
}
|
||
|
function add_testimonial()
|
||
|
{
|
||
|
if($this->session->userdata('id')==""){redirect('admin/login');}
|
||
|
if($this->input->post("add"))
|
||
|
{
|
||
|
$Title=$this->input->post("Title");
|
||
|
|
||
|
$Detail=$this->input->post("Detail");
|
||
|
$tg =array();
|
||
|
foreach($tags as $key1=>$val1)
|
||
|
{
|
||
|
$tg[]=$tags[$key1];
|
||
|
}
|
||
|
$tg_res= implode(', ', $tg);
|
||
|
//make directory
|
||
|
|
||
|
if (!is_dir('uploads/testimonial')) {
|
||
|
mkdir('./uploads/testimonial', 0777, TRUE);
|
||
|
|
||
|
}
|
||
|
|
||
|
$valid_extensions = array('jpeg', 'jpg', 'png'); // valid extensions
|
||
|
$path = 'uploads/testimonial/'; // 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="testimonial";
|
||
|
$rvalue=array(
|
||
|
'name'=>$Title,
|
||
|
'message'=>$Detail,
|
||
|
'image'=>$path,
|
||
|
|
||
|
'cdate'=>date('Y-m-d H:i:s'),
|
||
|
|
||
|
'status'=>1);
|
||
|
|
||
|
$result=$this->commonsql_model->insert_table($table,$rvalue);
|
||
|
|
||
|
|
||
|
} } }
|
||
|
if($result)
|
||
|
{
|
||
|
$this->session->set_userdata('suc','successfully added');
|
||
|
redirect('admin/testimonial');
|
||
|
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
$this->session->set_userdata('err','Please try again');
|
||
|
redirect('admin/testimonial');
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
$this->load->view('admin/testimonial/add');
|
||
|
}
|
||
|
function edit_testimonial($id)
|
||
|
{
|
||
|
if($this->session->userdata('id')==""){redirect('admin/login');}
|
||
|
if($this->input->post("edit"))
|
||
|
{
|
||
|
$Title=$this->input->post("Title");
|
||
|
|
||
|
$Detail=$this->input->post("Detail");
|
||
|
$oldimage=$this->input->post("old_image");
|
||
|
$Image=$this->input->post("Image");
|
||
|
|
||
|
if($Image=="") {
|
||
|
$simage=$oldimage;
|
||
|
}
|
||
|
if (!is_dir('uploads/testimonial')) {
|
||
|
mkdir('./uploads/testimonial', 0777, TRUE);
|
||
|
|
||
|
}
|
||
|
$valid_extensions = array('jpeg', 'jpg', 'png'); // valid extensions
|
||
|
$path = 'uploads/testimonial/'; // 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="testimonial";
|
||
|
$wheredata=(array('id'=>$id));
|
||
|
$values=array(
|
||
|
'name'=>$Title,
|
||
|
'message'=>$Detail,
|
||
|
'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/testimonial');
|
||
|
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
$this->session->set_userdata('err','Please try again');
|
||
|
redirect('admin/testimonial');
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
$data['tes']=$this->Testimonial_model->list_testimonial($id);
|
||
|
$this->load->view('admin/testimonial/edit',$data);
|
||
|
}
|
||
|
function check_uncheck_testimonial()
|
||
|
{
|
||
|
$id=$_POST['id'];
|
||
|
$value=$_POST['val'];
|
||
|
$tblname="testimonial";
|
||
|
$where=array('id'=>$id);
|
||
|
$update=array('status'=>$value);
|
||
|
$results=$this->commonsql_model->updateTable($tblname,$where,$update);
|
||
|
if($results)
|
||
|
{
|
||
|
echo "1";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
echo "2";
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
?>
|