recon/application/controllers/Admin.php
2023-04-17 10:43:50 +05:30

272 lines
8.1 KiB
PHP

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Admin extends CI_Controller {
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* @see https://codeigniter.com/user_guide/general/urls.html
*/
function __construct()
{
parent::__construct();
$this->load->model('Admin_model','admin');
//force_ssl();
}
public function index(){
redirect('admin/users');
// $this->checksess();
// $this->load->view('admin/users');
}
public function users(){
$this->checksess();
$data['corp_info'] = $this->admin->get_corp();
$this->load->view('admin/users',$data);
}
public function corporates(){
$this->checksess();
$this->load->view('admin/corporates');
}
public function airline(){
$this->checksess();
$this->load->view('admin/airline_gstin');
}
public function add_corpdetail(){
$this->checksess();
$data = $this->input->post('usr');
$con['c_code'] = $data['c_code'];
$echk = $this->admin->get_corp($con);
if($echk->num_rows()>0){
echo 2; exit;
}
else{
$con1['c_email'] = $data['c_email'];
$echk1 = $this->admin->get_corp($con1);
if($echk1->num_rows()>0){
echo 3; exit;
}
else{
$data['c_createdby'] = $this->session->userdata['recon_sess_i']['u_id'];
$data['c_createdon'] = date('Y-m-d H:i:s',time());
$this->db->insert('corporates',$data);
echo 1; exit;
}
}
}
public function add_airline_gstin(){
$this->checksess();
$data = $this->input->post();
if ($this->input->post()) {
$this->db->insert('airline_gstin',$data);
echo 1;
} else {
echo 0;
}
}
public function upd_corpdetail(){
$this->checksess();
$c_id = $this->input->post('c_id');
$data = $this->input->post('usr');
$con['c_code'] = $data['c_code'];
$con['c_id !='] = $c_id;
$echk = $this->admin->get_corp($con);
if($echk->num_rows()>0){
echo 2; exit;
}
else{
$con['c_email'] = $data['c_email'];
$con['c_id !='] = $c_id;
$echk = $this->admin->get_corp($con);
if($echk->num_rows()>0){
echo 3; exit;
}
else{
$data['c_updatedby'] = $this->session->userdata['recon_sess_i']['u_id'];
$data['c_updatedon'] = date('Y-m-d H:i:s',time());
$this->db->where('c_id',$c_id);
$this->db->update('corporates',$data);
echo 1; exit;
}
}
}
public function upd_airline_detail(){
$this->checksess();
$a_id = $this->input->post('a_id');
$data = $this->input->post();
if($a_id){
$this->db->where('a_id',$a_id);
$this->db->update('airline_gstin',$data);
echo 1; exit;
}
else{
echo 0; exit;
}
}
public function get_corpdetail(){
$this->checksess();
$u_id = $this->input->post('c_id');
$data = $this->admin->get_corp(null,$u_id,null);
if($data->num_rows()>0){
foreach($data->result() as $dat){
$fdata[] = $dat;
}
$fary['data'] = $fdata;
}
echo json_encode($fary);
}
public function get_airline_gstno_data(){
$this->checksess();
$a_id = $this->input->post('a_id');
$data = $this->admin->get_airline(null,$a_id,1);
if($data->num_rows()>0){
foreach($data->result() as $dat){
$fdata[] = $dat;
}
$fary['data'] = $fdata;
}
echo json_encode($fary);
}
public function get_usrdetail(){
$this->checksess();
$u_id = $this->input->post('u_id');
$data = $this->db->query('select * from (select u_corporateid,u_email,u_id,u_isactive,u_name,u_number,u_role from users where u_id = "'.$u_id.'") u left join corporates c on u.u_corporateid=c.c_id');
if($data->num_rows()>0){
foreach($data->result() as $dat){
$fdata[] = $dat;
}
$fary['data'] = $fdata;
}
echo json_encode($fary);
}
public function get_corp(){
$res = $this->admin->get_corp()->result();
foreach($res as $r){
$fary['data'][] = $r;
}
echo json_encode($fary);
}
public function get_airline_data(){
$res = $this->admin->get_airline()->result();
foreach($res as $r){
$fary['data'][] = $r;
}
echo json_encode($fary);
}
public function generateHash($plainText, $salt = null)
{
if ($salt === null)
{
$salt = substr(md5(uniqid(rand(), true)), 0, 25);
}
else
{
$salt = substr($salt, 0, 25);
}
return $salt . sha1($salt . $plainText);
}
public function add_usrdetail(){
$this->checksess();
$data = $this->input->post('usr');
$data['u_password'] = $this->generateHash($data['u_password']);
$con['u_email'] = $data['u_email'];
$echk = $this->admin->get_user($con);
if($echk->num_rows()>0){
echo 2; exit;
}
else{
$data['u_createdby'] = $this->session->userdata['recon_sess_i']['u_id'];
$data['u_createdon'] = date('Y-m-d H:i:s',time());
$this->db->insert('users',$data);
echo 1; exit;
}
}
public function upd_usrdetail(){
$this->checksess();
$u_id = $this->input->post('u_id');
$data = $this->input->post('usr');
if($data['u_password'] == '')
unset($data['u_password']);
else
$data['u_password'] = $this->generateHash($data['u_password']);
$con['u_email'] = $data['u_email'];
$con['u_id !='] = $u_id;
$echk = $this->admin->get_user($con);
if($echk->num_rows()>0){
echo 2; exit;
}
else{
$data['u_updatedby'] = $this->session->userdata['recon_sess_i']['u_id'];
$data['u_updatedon'] = date('Y-m-d H:i:s',time());
$this->db->where('u_id',$u_id);
$this->db->update('users',$data);
echo 1; exit;
}
}
public function get_usr(){
$this->checksess();
$res = $this->db->query("SELECT * FROM (select u_corporateid,u_email,u_id,u_isactive,u_name,u_number,u_role from users) a left join corporates c on a.u_corporateid=c.c_id where u_role != 'admin'");
if($res->num_rows()>0){
foreach($res->result() as $resi){
$resi->refrole = ucfirst($resi->u_role);
if($resi->u_role == 'corporate')
$resi->refrole = $resi->c_name;
else if($resi->u_role == 'tmc')
$resi->refrole = $resi->c_name."/".$resi->refrole;
$fary['data'][] = $resi;
}
}
echo json_encode($fary);
}
public function checksess(){
if(isset($this->session->userdata['recon_sess_i']['u_role'])){
if($this->session->userdata['recon_sess_i']['u_role'] == 'corporate')
redirect('corporate');
}
else
redirect('login');
}
}