donation/app/Controllers/Donor_controller.php
2021-01-08 11:20:29 +05:30

189 lines
5.1 KiB
PHP

<?php namespace App\Controllers;
use App\Models\Donor_model;
use App\Models\Dashboard_model;
use App\Models\Address_model;
class Donor_controller extends BaseController
{
public $session;
public function __construct()
{
$this->session = session();
$this->Donor_model = new Donor_model();
$this->Dashboard_model = new Dashboard_model();
}
public function index()
{
$data=[];
helper(['form']);
if($this->request->getmethod() == 'post')
{
$email = $this->request->getVar('email');
$password = $this->request->getVar('password');
$userdata = $this->Donor_model->verifyEmail($email);
if($userdata)
{
if(password_verify($password, $userdata['password']))
{
$this->session->set('logged_user',$userdata['id']);
return redirect()->to(base_url().'/Dashboard');
}
else{
$this->session->setTempdata('error','sorry wrong password entered for the Email',3);
return redirect()->to(base_url());
}
}else
{
$this->session->setTempdata('error','sorry Email does not existe',3);
return redirect()->to(base_url());
}
}
return view('login');
}
public function register()
{
$data['country']=$this->Dashboard_model->fetch_country();
helper(['form']);
if($this->request->getmethod() == 'post')
{
//validate
$rules=[
'name' =>'required|min_length[3]|max_length[30]',
'phone' =>'required|min_length[10]|max_length[12]|is_unique[user_management.phone]',
'email' =>'required|min_length[6]|max_length[50]|valid_email|is_unique[user_management.email]',
'pan' =>'required|min_length[10]|max_length[10]|is_unique[user_management.pan]',
'address' =>'required|min_length[3]|max_length[70]',
'pin_code' =>'required|min_length[6]|max_length[6]',
'org_name' =>'required|min_length[3]|max_length[20]',
'gstin' =>'required|min_length[15]|max_length[15]|is_unique[user_management.gstin]',
'password' =>'required|min_length[5]|max_length[20]',
'password_confirm' =>'matches[password]',
'userfile' => [
'uploaded[userfile]',
'mime_in[userfile,image/jpg,image/png,image/jpeg]',
'max_size[userfile,1000]',
],
];
if(! $this->validate($rules))
{
$data['validation'] = $this->validator;
}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'];
$path="public/assets/uploads";
if($img = $this->request->getFile('userfile'))
{
if ($img->isValid() && ! $img->hasMoved())
{
//$newName = $img->getRandomName();
$f_type=date('Y-m-d').time().$_FILES['userfile']['name'];
$img->move($path, $f_type);
$signature="public/assets/uploads/".$f_type;
}
}
//store the donor in database
$model = new Donor_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'),
'foreign_key' =>$this->request->getVar('email'),
'password' =>$this->request->getVar('password'),
'signature' =>$signature,
];
//print_r($donorData);die();
$model->save($donorData);
$session = session();
$session ->setFlashdata('success','Successful Registration');
return redirect()->to(base_url());
}
}
//echo view('templates/header',$data);
return view('register',$data);
//echo view('templates/footer');
}
function profile()
{
$id= session()->get('logged_user');
$data['userdata']=$this->Dashboard_model->getLoggedInUserData($id);
return view('profile',$data);
}
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'));
}
}
//--------------------------------------------------------------------
}