chess/application/controllers/User_management.php

414 lines
10 KiB
PHP

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class User_management extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->model('insert_model');
$this->load->model('get_model');
$this->load->model('common_model');
$this->load->library('pagination');
$this->load->library('email');
$this->load->config('email');
if(!$this->session->userdata('admin_name')){
redirect('login');
}
}
public function send_reply()
{
$email = $_POST['email'];
$message = $_POST['message'];
$id = $_POST['id'];
$data['message'] = $message;
//$data1['email'] = $email;
$this->email->from('testingsites.com@gmail.com', 'Reply from Chess Admin')
->to($email)
->subject('Reply from Chess Admin')
->message($this->load->view('reply_template', $data, true));
//->message("email has been sent succesfully".$data, true);
//$this->email->send();
if($this->email->send()){
$status = 1;
}
else {
$status = 2;
}
$reply_date = date('Y-m-d');
$data = array(
'rply_msg' => $message,
'rply_status' => $status,
'rply_date' => $reply_date
);
$where= array('id' => $id);
$this->common_model->update('user_contact_us', $data, $where);
redirect('contact_us',$this->session->set_flashdata('success', 'Reply Sent Successfully',3));
//email send code
}
public function add_testi()
{
//print_r($_FILES); die;
if(isset($_FILES['file']) && $_FILES['file'] != '') {
// echo "in"; die;
$config['upload_path'] = './assets/images/';
$config['allowed_types'] = 'jpg|jpeg|gif|png';
//$config['max_size'] = '10000'; // max_size in kb
$config['file_name'] = $_FILES['file']['name'];
// Load upload library
$this->load->library('upload',$config);
// File upload
$this->upload->initialize($config);
if($this->upload->do_upload('file')){
// Get data about the file
$uploadData = $this->upload->data();
$filename = $uploadData['file_name'];
$path = '/assets/images/';
$msg = array(
'name' => $_POST['name'],
'message' => $_POST['message'],
'image' => $path.$filename
);
$insert = $this->insert_model->insert('tbl_testimonials', $msg);
if($insert){
$this->session->set_flashdata('success', 'Testimonial Added Successfully...!');
redirect('client_testimonial');
}
}else{
$error = array('error' => $this->upload->display_errors());
$this->session->set_flashdata('error',$error['error']);
redirect('client_testimonial');
}
}
else {
$this->session->set_flashdata('error', 'Please Upload Image...!');
redirect('client_testimonial');
}
}
public function edit_testi()
{
$id=$this->input->post("id");
// print_r($_FILES); exit();
if(isset($_FILES['file_e']) && !empty($_FILES['file_e']))
{
$path = '/assets/images/';
$config['upload_path'] = './assets/images/';
$config['allowed_types'] = '*';
$config['file_name'] = $_FILES['file_e']['name'];
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ( $this->upload->do_upload('file_e'))
{
$upload_data=$this->upload->data();
$image_name=$upload_data['file_name'];
// delete old file from server, if exists...
$old_img=$this->input->post('photo');
$image_path = FCPATH .'assets/images/';
$filename = $image_path . $old_img;
$image_name=$path.$image_name;
if (file_exists($filename))
{
unlink($filename);
//echo "file deleted on server successfully"; exit();
}
}
else
{
$image_name=$this->input->post('photo');
}
}
else{
$image_name=$this->input->post('photo');
}
$data = array(
'name' => $_POST['name'],
'message' => $_POST['message'],
'image'=> $image_name,
);
$where= array('id' => $id);
$this->common_model->update('tbl_testimonials', $data, $where);
redirect('client_testimonial',$this->session->set_flashdata('success', 'Testimonial Update Successfully',3));
}
// add country
public function add_country()
{
//print_r($_FILES); die;
if(isset($_FILES['file']) && $_FILES['file'] != '') {
// echo "in"; die;
$config['upload_path'] = './assets/images/country/';
$config['allowed_types'] = 'jpg|jpeg|gif|png';
//$config['max_size'] = '10000'; // max_size in kb
$config['file_name'] = $_FILES['file']['name'];
// Load upload library
$this->load->library('upload',$config);
// File upload
$this->upload->initialize($config);
if($this->upload->do_upload('file')){
// Get data about the file
$uploadData = $this->upload->data();
$filename = $uploadData['file_name'];
$path = 'assets/images/country/';
$msg = array(
'country_name' => $_POST['name'],
'country_flag' => $path.$filename
);
$insert = $this->insert_model->insert('tbl_country', $msg);
if($insert){
$this->session->set_flashdata('success', 'Country Added Successfully...!');
redirect('add_country');
}
}else{
$error = array('error' => $this->upload->display_errors());
$this->session->set_flashdata('error',$error['error']);
redirect('add_country');
}
}
else {
$this->session->set_flashdata('error', 'Please Upload Image...!');
redirect('add_country');
}
}
public function edit_country()
{
$id=$this->input->post("id");
if(isset($_FILES['file_e']) && !empty($_FILES['file_e']))
{
$path = 'assets/images/country/';
$config['upload_path'] = './assets/images/country/';
$config['allowed_types'] = '*';
$config['file_name'] = $_FILES['file_e']['name'];
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ( $this->upload->do_upload('file_e'))
{
$upload_data=$this->upload->data();
$image_name=$upload_data['file_name'];
// delete old file from server, if exists...
$old_img=$this->input->post('photo');
$image_path = FCPATH .'assets/images/country/';
$filename = $image_path . $old_img;
$image_name=$path.$image_name;
if (file_exists($filename))
{
unlink($filename);
//echo "file deleted on server successfully"; exit();
}
}
else
{
$image_name=$this->input->post('photo');
}
}
else{
$image_name=$this->input->post('photo');
}
$data = array(
'country_name' => $_POST['name'],
'country_flag'=> $image_name,
);
$where= array('id' => $id);
$this->common_model->update('tbl_country', $data, $where);
redirect('add_country',$this->session->set_flashdata('success', 'Country Update Successfully',3));
}
public function insert_lang()
{
$msg = array(
'name' => $this->input->post('lang')
);
$insert = $this->insert_model->insert('tbl_lang', $msg);
if($insert){
$this->session->set_flashdata('success', 'Language Added Successfully...!');
redirect('add_language');
}
}
public function edit_lang()
{
$id=$this->input->post("id");
$lang=$this->input->post("lang");
$data=array('name'=>$lang);
$where= array('id' => $id);
$this->common_model->update('tbl_lang', $data, $where);
redirect('add_language',$this->session->set_flashdata('success', 'Language Update Successfully',3));
}
public function change_status()
{
// print_r($_POST); die;
$id = $this->input->post('id');
$status = $this->input->post('status');
// 'updated_at' => date('Y-m-d H:i:s')
$where = array('user_id' => $id);
$data = array('is_active' => $status );
$update = $this->common_model->update_data('tbl_user',$data, $where);
$arr = array('success' => false, 'data' => '');
if($update){
$arr = array('success' => true, 'data' => $update);
}
echo json_encode($arr);
}
//user details page
public function view_user($id)
{
$user_id = $id;
$where = '(user_id ="'.$user_id.'")';
// var_dump($user_id);
$data['user'] = $this->get_model->get_by_id('tbl_user', $where);
$data['bank'] = $this->get_model->get_by_id('user_bank_details', $where);
$where1 = '(player1_id = "'.$id.'")';
// var_dump($id);
$view_user_data = $this->get_model->get_all($tbl = 'tbl_game_data',$where1);
$data['view_user_data']= $view_user_data;
$config = [
'base_url' => base_url('view_user/'.$id."/"),
'per_page' => 5,
'total_rows' => count($view_user_data),
'next_link' => '>',
'prev_link' => '<',
'first_link' => false,
'last_link' => false,
'full_tag_open' => '<ul class="pagination pagination-circle">',
'full_tag_close' => "</ul>",
'attributes' => ['class' => 'page-link'],
'next_tag_open' => '<li class="page-item">',
'next_tag_close' => "</li>",
'prev_tag_open' => '<li class="page-item">',
'prev_tag_close' => "</li>",
'num_tag_open' => '<li class="page-item">',
'num_tag_close' => "</li>",
'cur_tag_open' => '<li class="active page-item"><span class="page-link">',
'cur_tag_close' => '<span class="sr-only">(current)</span></span></li>'
];
$this->pagination->initialize($config);
$data['view_user_data'] = $this->get_model->list_by_desc($config['per_page'], $this->uri->segment(3),$tbl="tbl_game_data", "player1_id");
// var_dump($view_user_data);
$this->load->view('pages/view_user', $data);
}
public function edit_time_slot()
{
//print_r($_POST); exit();
$id=$this->input->post("id");
$time_slot=$this->input->post("time_slot");
$data=array('time_slot'=>$time_slot);
$where= array('id' => $id);
$this->common_model->update('tbl_time_Slot', $data, $where);
redirect('time_slot',$this->session->set_flashdata('success', 'Time Slot Updated Successfully',3));
}
}