donation/app/Controllers/My_controller.php
2021-01-05 22:00:46 +05:30

231 lines
6.6 KiB
PHP

<?php namespace App\Controllers;
use App\Models\My_model;
use App\Models\Dashboard_model;
use App\Models\Address_model;
class My_controller extends BaseController
{
public $session;
public function __construct()
{
$this->session = session();
$this->My_model = new My_model();
$this->Dashboard_model = new Dashboard_model();
}
// public function donor_register() {
// helper(['form', 'url']);
// $input = $this->validate([
// 'name' =>'required|min_length[3]|max_length[20]',
// 'phone' =>'required|min_length[3]|max_length[10]',
// 'email' =>'required|min_length[6]|max_length[50]|valid_email|is_unique[donar_management.email]',
// 'pan' =>'required|min_length[3]|max_length[20]',
// 'address' =>'required|min_length[3]|max_length[70]',
// 'country' =>'required',
// 'state' =>'required',
// 'city' =>'required',
// 'pin_code' =>'required|min_length[6]|max_length[6]',
// 'date_of_birth' =>'required|min_length[3]|max_length[20]',
// 'gender' =>'required',
// 'org_name' =>'required|min_length[3]|max_length[20]',
// 'gstin' =>'required|min_length[3]|max_length[20]',
// ]);
// $formModel = new FormModel();
// if (!$input) {
// echo view('contact_form', [
// 'validation' => $this->validator
// ]);
// } else {
// $formModel->save([
// 'name' => $this->request->getVar('name'),
// 'email' => $this->request->getVar('email'),
// 'phone' => $this->request->getVar('phone'),
// ]);
// return $this->response->redirect(site_url('/submit-form'));
// }
// }
public function donor_register()
{
$data['country']=$this->Dashboard_model->fetch_country();
helper(['form', 'url']);
if(!session()->has('logged_user'))
{
return redirect()->to(base_url());
}
if($this->request->getmethod() == 'post')
{
// validate
$rules=[
'name' =>'required|min_length[3]|max_length[20]',
'phone' =>'required|min_length[10]|max_length[12]|is_unique[donar_management.phone]',
'email' =>'required|min_length[6]|max_length[50]|valid_email|is_unique[donar_management.email]',
'pan' =>'required|min_length[10]|max_length[10]|is_unique[donar_management.pan]',
'address' =>'required|min_length[3]|max_length[70]',
'pin_code' =>'required|min_length[6]|max_length[6]',
'date_of_birth' =>'required|min_length[6]|max_length[10]',
'org_name' =>'required|min_length[3]|max_length[20]',
'gstin' =>'required|min_length[15]|max_length[15]|is_unique[donar_management.gstin]',
];
if(! $this->validate($rules))
{
$data['validation'] = $this->validator;
//echo '<script>alert("Please import correct file, did not match excel sheet column")</script>';
}else{
$Address_model = new Address_model();
$country_id=$this->request->getVar('country');
$state_id=$this->request->getVar('state');
$city_id=$this->request->getVar('city');
$country_name=$Address_model->country($country_id);
foreach($country_name as $key){ $key['country_name']; }
$country=$key['country_name'];
$state_name=$Address_model->state($state_id);
foreach($state_name as $key){ $key['state_name']; }
$state=$key['state_name'];
$city_name=$Address_model->city($city_id);
foreach($city_name as $key){ $key['city_name']; }
$city=$key['city_name'];
$model = new My_model();
$donorData=[
'name' =>$this->request->getVar('name'),
'phone' =>$this->request->getVar('phone'),
'email' =>$this->request->getVar('email'),
'pan' =>$this->request->getVar('pan'),
'address' =>$this->request->getVar('address'),
'country' =>$country,
'state' =>$state,
'city' =>$city,
'pin_code' =>$this->request->getVar('pin_code'),
'date_of_birth' =>$this->request->getVar('date_of_birth'),
'gender' =>$this->request->getVar('gender'),
'org_name' =>$this->request->getVar('org_name'),
'gstin' =>$this->request->getVar('gstin'),
];
//print_r($donorData); die();
$model->save($donorData);
$session = session();
$session ->setFlashdata('success','Successful Added');
return redirect()->to(base_url().'/all_donor');
}
}
// echo view('templates/header',$data);
return view('donor_registration');
// echo view('templates/footer');
}
public function all_donor()
{
$data = [];
if(!session()->has('logged_user'))
{
return redirect()->to(base_url());
}
$data['receiptdata']=$this->My_model->all_donor();
return view('donor_table',$data);
}
function edit_donor($id)
{
if(!session()->has('logged_user'))
{
return redirect()->to(base_url());
}
$model = new My_model();
$donor_data=$model->find($id);
$data= [ 'post'=>$donor_data ];
if($this->request->getMethod() == 'post')
{
$model = new My_model();
$_POST['id'] = $id;
$model->save($_POST);
return redirect()->to(base_url()."/all_donor");
}
return view('donor_edit',$data);
}
function update_donor()
{
if(!session()->has('logged_user'))
{
return redirect()->to(base_url());
}
$donor_id=$this->request->getVar('id');
$DonorData=[
'name' =>$this->request->getVar('name'),
'phone' =>$this->request->getVar('phone'),
'email' =>$this->request->getVar('email'),
'pan' =>$this->request->getVar('pan'),
'address' =>$this->request->getVar('address'),
'country' =>$this->request->getVar('country'),
'state' =>$this->request->getVar('state'),
'city' =>$this->request->getVar('city'),
'pin_code' =>$this->request->getVar('pin_code'),
'date_of_birth' =>$this->request->getVar('date_of_birth'),
'gender' =>$this->request->getVar('gender'),
'org_name' =>$this->request->getVar('org_name'),
'gstin' =>$this->request->getVar('gstin'),
];
//print_r($DonorData);die();
$model = new My_model();
$model->update($donor_id , $DonorData);
return redirect()->to(base_url().'/all_donor');
}
function fetch_country()
{
echo $this->Dashboard_model->fetch_country();
}
function fetch_state()
{
if($this->request->getVar('country_id'))
{
echo $this->Dashboard_model->fetch_state($this->request->getVar('country_id'));
}
}
function fetch_city()
{
if($this->request->getVar('state_id'))
{
echo $this->Dashboard_model->fetch_city($this->request->getVar('state_id'));
}
}
//--------------------------------------------------------------------
}