| Current File : //www-data/newsites/adminpanel/application/controllers/Gallery.php |
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Gallery extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->library('form_validation');
$this->load->library('session');
$this->load->helper('url');
}
public function index()
{
$user_id=$this->session->userdata('user_id');
$this->load->model('Login_Model');
$this->load->model('Gallery_Model');
if(!empty($user_id))
{
$data['profile'] = $this->Login_Model->get_profile($user_id);
$usersdata['usersdata1'] = $this->Gallery_Model->get_gallery_data();
$this->load->view('header',$data);
$this->load->view('gallery_view',$usersdata);
$this->load->view('footer');
}
else
{
redirect('login');
}
}
public function viewwebsiteajaxdata()
{
$this->load->model('Submenu_Model');
$user_id=$this->input->post('userid');
$userdataview = $this->Submenu_Model->get_websitedataview($user_id);
//print_r($userdataview[0]['hostname']);exit;
$result_html='';
$result_html.="<div id='tabledata'>";
$result_html.="<div class='row'>";
$result_html.="<div class='col-md-6 pr-0'>";
$result_html.="<div class='form-group form-group-default'>";
$result_html.="<span><b>Host Name :</b>".$userdataview[0]['host_name']."</span>";
$result_html.="</div>";
$result_html.="</div>";
$result_html.="</div>";
$result_html.="<div class='row'>";
$result_html.="<div class='col-md-6'>";
$result_html.="<div class='form-group form-group-default'>";
$result_html.="<span><b>Active Status :</b> ".$userdataview[0]['active']."</span>";
$result_html.="</div>";
$result_html.="</div>";
$result_html.="</div>";
$result_html.="</div>";
echo "<br>";
print_r($result_html);
}
public function galleryadd()
{
$user_id=$this->session->userdata('user_id');
$this->load->model('Login_Model');
$this->load->model('Gallery_Model');
if(!empty($user_id))
{
$data['profile'] = $this->Login_Model->get_profile($user_id);
$hostdata['hostdata11'] = $this->Gallery_Model->get_hostname();
$this->load->view('header',$data);
$this->load->view('gallery_add',$hostdata);
$this->load->view('footer');
}
else
{
redirect('login');
}
}
public function check_email_exists($email)
{
$where_array = array('email' => $email);
$this->db->where($where_array);
$switch = $this->db->count_all_results("user");
if ($switch != NULL){
$this->form_validation->set_message('check_email_exists', 'The %s field value already exist, please try another.');
return false;
}else{
return true;
}
}
public function insertgallerydata()
{
//echo "ssfjdsfjdsfjs";exit;
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->form_validation->set_rules('host_id', 'host_id', 'required');
$this->form_validation->set_rules('caption', 'caption', 'required');
date_default_timezone_set("Asia/Calcutta");
if($this->input->post("activestatus")){
$activestatus=$this->input->post("activestatus");
}else{
$activestatus=0;
}
$host_id=$this->input->post("host_id");
$module_id=$this->input->post("module_id");
$sub_module_id=$this->input->post("submodule_id");
$caption=$this->input->post("caption");
$created_at=date('Y-m-d H:i:s');
$active=$activestatus;
if (!empty($_FILES["image"]["name"]))
{
$date = date('Y-m-d H:i:s');
$tempFile1 = $_FILES['image']['tmp_name'];
$temp1 = $_FILES["image"]["name"];
$targetPath1 = './assets/images/';
$file_name1=$caption.$date.'1'.'_'.$temp1;
$targetFile1 = $targetPath1.$file_name1;
move_uploaded_file($tempFile1, $targetFile1);
}
//$this->load->model('Users_Model');
$this->load->model('Gallery_Model');
$this->Gallery_Model->add_gallerydata($host_id,$file_name1,$caption,$active);
$this->load->model('Settings_m');
$this->session->set_flashdata('success', 'Gallery Added Successfully');
redirect(base_url("index.php/Gallery"));
}
public function galleryedit()
{
$user_id=$this->session->userdata('user_id');
$this->load->model('Login_Model');
$this->load->model('Gallery_Model');
$this->load->model('Settings_m');
if(!empty($user_id))
{
$data['profile'] = $this->Login_Model->get_profile($user_id);
$id = htmlentities($this->uri->segment(3));
$hostdata['get_user'] = $this->Settings_m->get_single('gallery', $id);
$hostdata['hostdata11'] = $this->Gallery_Model->get_hostname();
$hostdata['submodulesdata'] = $this->Gallery_Model->get_gallery($id);
$this->load->view('header',$data);
$this->load->view('gallery_edit',$hostdata);
$this->load->view('footer');
}
else
{
redirect('login');
}
}
public function updategallerydata()
{
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->form_validation->set_rules('host_id', 'host_id', 'required');
$this->form_validation->set_rules('caption', 'caption', 'required');
if ($this->form_validation->run() == FALSE)
{
$user_id=$this->session->userdata('user_id');
$this->load->model('Login_Model');
$data['profile'] = $this->Login_Model->get_profile($user_id);
$this->load->view('header',$data);
$this->load->view('gallery_edit');
$this->load->view('footer');
}
if($this->input->post("activestatus"))
{
$activestatus=$this->input->post("activestatus");
}
else
{
$activestatus=0;
}
$id = htmlentities($this->uri->segment(3));
$this->load->model('Settings_m');
$hostdata['get_user'] = $this->Settings_m->get_single('gallery', $id);
foreach($hostdata['get_user'] as $contact)
{
$filename[] = $contact;
}
$file_name=$filename[3];
$caption=$this->input->post("caption");
if (!empty($_FILES["image"]["name"]))
{
$date = date('Y-m-d H:i:s');
$tempFile1 = $_FILES['image']['tmp_name'];
$temp1 = $_FILES["image"]["name"];
$targetPath1 = './assets/images/';
$file_name1 =$caption.$date.'1'.'_'.$temp1;
$targetFile1 = $targetPath1.$file_name1;
$unlinkpath1= './assets/images/'.$file_name;
unlink($unlinkpath1);
move_uploaded_file($tempFile1, $targetFile1);
}
else
{
$file_name1=$file_name;
}
$array = array(
"host_id" => $this->input->post("host_id"),
"caption" => $this->input->post("caption"),
"image" => $file_name1,
"is_active" => $activestatus,
);
$this->Settings_m->update('gallery', $array, $id);
$this->session->set_flashdata('success', 'Gallery Updated Successfully');
redirect(base_url("index.php/Gallery"));
}
function gallery_delete()
{
$id=$this->input->post('id');
$this->db->where('id', $id);
$result=$this->db->delete('gallery');
echo json_encode($result);
}
}