Skip to content

Commit

Permalink
Backend Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
algobasket committed Aug 25, 2020
1 parent af1e5f1 commit ec9c88f
Show file tree
Hide file tree
Showing 19 changed files with 557 additions and 224 deletions.
2 changes: 1 addition & 1 deletion app/Config/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Filters extends BaseConfig
'before' => [
//'honeypot'
// 'csrf',
'authFilter' => ['except' =>['login','login-staff','login-agent','login-developer','register','forgot-password','forgot-password/*','auth/*','/','ajax/*','browse','browse/*','property-detail/*','home/*','about','contact','careers','terms-and-conditions','testimonials','policy','report','safety','find-agent']]
'authFilter' => ['except' =>['login','logout','login-staff','login-agent','login-developer','register','forgot-password','forgot-password/*','auth/*','/','ajax/*','browse','browse/*','property-detail/*','home/*','about','contact','careers','terms-and-conditions','testimonials','policy','report','safety','find-agent']]
],
'after' => [
'toolbar',
Expand Down
5 changes: 3 additions & 2 deletions app/Controllers/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ public function login_staff()
return redirect()->back()->withInput();
}
}
}
}
$data['staffRoles'] = $this->UserModel->getAllRolesByRoleType('staff');
return view('frontend/login-auth',$data);
}

Expand Down Expand Up @@ -446,7 +447,7 @@ public function forgot_password()

public function logout()
{
delete_cookie('userCookie');
delete_cookie('userCookie');
$array_items = ['userId', 'email','display','role'];
$this->session->remove($array_items);
$this->session->setFlashdata('alert','<div class="alert alert-success">Logged out from all devices</div>');
Expand Down
11 changes: 4 additions & 7 deletions app/Controllers/Backend/BackendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ public function initController(\CodeIgniter\HTTP\RequestInterface $request, \Cod

public function isTrustedUser()
{
$role = $this->session->get('role');
if($role)
{
if(in_array($role,['admin','subadmin','contentwriter','sales']))
{
$role = $this->session->get('role');
if($role){
if(in_array($role,['admin','subadmin','contentwriter','sales'])){
return true;
}else{
throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound();
Expand All @@ -39,8 +37,7 @@ public function isTrustedUser()
throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound();
}
}

}
}


}
26 changes: 23 additions & 3 deletions app/Controllers/Backend/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,30 @@
class Dashboard extends BackendController
{

function index()
function __construct()
{
$data['title'] = "Dashboard";
return view('backend/dashboard',$data);
$this->AccountModel = model('AccountModel');
$this->GeographyModel = model('GeographyModel');
$this->PropertyModel = model('PropertyModel');
$this->UserModel = model('UserModel');
$this->CrudModel = model('CrudModel');
helper('inflector');
}

function index()
{
$data['title'] = "Dashboard";

$data['totalProperties'] = count($this->PropertyModel->getProperties());
$data['totalAgents'] = count($this->UserModel->getAllUsersByRole('agent'));
$data['totalDevelopers'] = count($this->UserModel->getAllUsersByRole('developers'));

$data['totalAdmin'] = count($this->UserModel->getAllUsersByRole('admin'));
$data['totalSubAdmin'] = count($this->UserModel->getAllUsersByRole('sub-admin'));
$data['totalSales'] = count($this->UserModel->getAllUsersByRole('sales'));
$data['totalAccountant'] = count($this->UserModel->getAllUsersByRole('accountant'));
$data['totalStaff'] = $data['totalAdmin'] + $data['totalSubAdmin'] + $data['totalSales'] + $data['totalAccountant'];
return view('backend/dashboard',$data);
}

}
107 changes: 103 additions & 4 deletions app/Controllers/Backend/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,55 @@ function customers()
$data['cities'] = $this->GeographyModel->cities();
$total_sold = $this->PropertyModel->totalPropertiesSoldByUser(segment(5));
$data['total_sold'] = $total_sold ? $total_sold : 0 ;
}elseif($data['section'] == "add"){
if($this->request->getPost('addStaff'))
{
if(! $this->validate([
'firstname' => 'required|min_length[1]|max_length[20]|alpha',
'lastname' => 'required|min_length[1]|max_length[20]|alpha',
'display_name' => 'required|min_length[2]|max_length[30]|alpha',
'username' => 'min_length[0]|max_length[50]|alpha_numeric',
'mobile' => 'min_length[10]|max_length[15]|numeric',
'email' => 'min_length[5]|max_length[40]|valid_email',
'address1' => 'min_length[5]|max_length[100]',
'address2' => 'min_length[0]|max_length[100]'
])){
$this->session->setFlashdata('alert','<div class="alert alert-danger">'.\Config\Services::validation()->listErrors().'</div>');
}else{
$toUpdate = [
'display_name' => $this->request->getPost('display_name'),
'username' => $this->request->getPost('username'),
'mobile' => $this->request->getPost('mobile'),
'email' => $this->request->getPost('email'),
'status' => $this->request->getPost('status')
];
$toUpdate2 = [
'firstname' => $this->request->getPost('firstname'),
'lastname' => $this->request->getPost('lastname'),
'address1' => $this->request->getPost('address1'),
'address2' => $this->request->getPost('address2'),
'country' => $this->request->getPost('country'),
'state' => $this->request->getPost('state'),
'city' => $this->request->getPost('city'),
'activity' => $this->request->getPost('myActivity'),
'specialities' => $this->request->getPost('specialities'),
'experience' => $this->request->getPost('experience'),
'website' => $this->request->getPost('website'),
'linkedin' => $this->request->getPost('linkedin'),
'twitter' => $this->request->getPost('twitter'),
'facebook' => $this->request->getPost('facebook'),
'instagram' => $this->request->getPost('instagram'),
'blog' => $this->request->getPost('blog'),
'english_level' => $this->request->getPost('english_level'),
're_license_no' => $this->request->getPost('re_license_no'),
'service_area' => json_encode($this->request->getPost('service_area'),true),
'updated_at' => date('Y-m-d h:i:s')
];
$userId = $this->AuthModel->register($toUpdate,$toUpdate2);
$this->session->setFlashdata('alert',successAlert('Staff Account Created!'));
return redirect()->to('/backend/user/staff/edit/'.$userId);
}
}
}else{

$data['customers'] = $this->UserModel->getAllUsersByRole('customer');
Expand Down Expand Up @@ -613,15 +662,65 @@ function staff()
}
}
$data['profile'] = $this->AccountModel->getProfileDetail(segment(5));
$data['countries'] = $this->GeographyModel->countries();
$data['states'] = $this->GeographyModel->states();
$data['cities'] = $this->GeographyModel->cities();
$total_sold = $this->PropertyModel->totalPropertiesSoldByUser(segment(5));
$data['total_sold'] = $total_sold ? $total_sold : 0 ;
}elseif($data['section'] == "add"){
if($this->request->getPost('addStaff'))
{
if(! $this->validate([
'firstname' => 'required|min_length[1]|max_length[20]|alpha',
'lastname' => 'required|min_length[1]|max_length[20]|alpha',
'display_name' => 'required|min_length[2]|max_length[30]|alpha',
'username' => 'min_length[0]|max_length[50]|alpha_numeric',
'mobile' => 'min_length[10]|max_length[15]|numeric',
'email' => 'min_length[5]|max_length[40]|valid_email',
'address1' => 'min_length[5]|max_length[100]',
'address2' => 'min_length[0]|max_length[100]'
])){
$this->session->setFlashdata('alert','<div class="alert alert-danger">'.\Config\Services::validation()->listErrors().'</div>');

}else{
$toUpdate = [
'display_name' => $this->request->getPost('display_name'),
'username' => $this->request->getPost('username'),
'mobile' => $this->request->getPost('mobile'),
'email' => $this->request->getPost('email'),
'status' => $this->request->getPost('status')
];
$toUpdate2 = [
'firstname' => $this->request->getPost('firstname'),
'lastname' => $this->request->getPost('lastname'),
'address1' => $this->request->getPost('address1'),
'address2' => $this->request->getPost('address2'),
'country' => $this->request->getPost('country'),
'state' => $this->request->getPost('state'),
'city' => $this->request->getPost('city'),
'activity' => $this->request->getPost('myActivity'),
'specialities' => $this->request->getPost('specialities'),
'experience' => $this->request->getPost('experience'),
'website' => $this->request->getPost('website'),
'linkedin' => $this->request->getPost('linkedin'),
'twitter' => $this->request->getPost('twitter'),
'facebook' => $this->request->getPost('facebook'),
'instagram' => $this->request->getPost('instagram'),
'blog' => $this->request->getPost('blog'),
'english_level' => $this->request->getPost('english_level'),
're_license_no' => $this->request->getPost('re_license_no'),
'service_area' => json_encode($this->request->getPost('service_area'),true),
'updated_at' => date('Y-m-d h:i:s')
];
$userId = $this->AuthModel->register($toUpdate,$toUpdate2);
$this->session->setFlashdata('alert',successAlert('Staff Account Created!'));
return redirect()->to('/backend/user/staff/edit/'.$userId);
}
}
}else{
$data['cRole'] = $this->request->getGet('role') ? $this->request->getGet('role') : "admin";
$data['staff'] = $this->UserModel->getAllUsersByRole($data['cRole']);
}
}
$data['countries'] = $this->GeographyModel->countries();
$data['states'] = $this->GeographyModel->states();
$data['cities'] = $this->GeographyModel->cities();
return view('backend/staff-members',$data);
}

Expand Down
13 changes: 12 additions & 1 deletion app/Controllers/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,18 @@ public function initController(\CodeIgniter\HTTP\RequestInterface $request, \Cod
$UserModel = model('UserModel');
if(session('userId'))
{
$UserModel->isUserSuspendedOrBanned();
if(segment(1) != 'logout')
{
$status = $UserModel->isUserSuspendedOrBanned(session('userId'));
if($status)
{
$data['title'] = 'Account '.$status;
$data['status'] = $status;
echo view('frontend/account-status',$data,['saveData' => TRUE]);
exit;
}
}

}

}
Expand Down
34 changes: 34 additions & 0 deletions app/Helpers/common_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,40 @@ function tabNotificationCount()
}


if(!function_exists('adminSCounter')){
function adminSCounter()
{
if(session('userId'))
{
$PropertyModel = model('PropertyModel');
$UserModel = model('UserModel');
$StatisticModel = model('StatisticModel');
$MessageModel = model('MessageModel');

$properties = $PropertyModel->getProperties();
$propertyTypes = $PropertyModel->getPropertyType();
$propertyAmenities = $PropertyModel->getPropertyAmeneties();
$leads = $UserModel->getLeads();
$agents = $UserModel->getAllUsersByRole('agent');
$developers = $UserModel->getAllUsersByRole('developer');
$customers = $UserModel->getAllUsersByRole('customer');
$staffs = $UserModel->getAllUsersByRoleType('staff');

return [
'properties' => count($properties),
'propertyTypes' => count($propertyTypes),
'propertyAmenities' => count($propertyAmenities),
'leads' => count($leads),
'agents' => count($agents),
'developers' => count($developers),
'customers' => count($customers),
'staffs' => count($staffs)
];
}
}
}


if(!function_exists('publicFolder')){
function publicFolder()
{
Expand Down
17 changes: 11 additions & 6 deletions app/Models/PropertyModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ function getPropertyType()
$builder->select($select);
$builder->join($this->status_tb,$this->status_tb.'.id = '.$this->property_ty_tb.'.status','LEFT');
$query = $builder->get();
foreach($query->getResultArray() as $r){
$data[] = $r;
}
return $data;
$data = array();
foreach($query->getResultArray() as $r)
{
$data[] = $r;
}
return $data;
}


Expand Down Expand Up @@ -124,9 +126,12 @@ function getPropertyAmeneties()
$builder->select($select);
$builder->join($this->status_tb,$this->status_tb.'.id='.$this->amenities_tb.'.status','LEFT');
$query = $builder->get();
$data = array();
foreach($query->getResultArray() as $r)
$data[] = $r;
return $data;
{
$data[] = $r;
}
return $data;
}


Expand Down
46 changes: 40 additions & 6 deletions app/Models/UserModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,42 @@ function getUserDetail($userId)
}


function getAllUsersByRoleType($roleType = NULL)
{
$builder = $this->db->table($this->users_tb);
$builder->select([$this->users_tb.'.*',$this->user_detail_tb.'.*',$this->status_tb.'.status_name',$this->status_tb.'.status_badge']);
$builder->join($this->user_detail_tb,$this->user_detail_tb.'.user_id ='.$this->users_tb.'.id','left');
$builder->join($this->status_tb,$this->status_tb.'.id ='.$this->users_tb.'.status','left');
$builder->join($this->roles_tb,$this->roles_tb.'.role_name ='.$this->users_tb.'.role','left');
if($roleType)
{
$builder->where($this->roles_tb.'.role_type',$roleType);
}
$query = $builder->get();
$data = array();
foreach($query->getResultArray() as $r)
{
$data[] = $r;
}
return $data;
}


function getAllRolesByRoleType($roleType = NULL)
{
$builder = $this->db->table($this->roles_tb);
$builder->select([$this->roles_tb.'.*']);
$builder->where($this->roles_tb.'.role_type',$roleType);
$query = $builder->get();
$data = array();
foreach($query->getResultArray() as $r)
{
$data[] = $r;
}
return $data;
}


function searchUser($txt)
{
$builder = $this->db->table($this->users_tb);
Expand Down Expand Up @@ -166,18 +202,16 @@ function isUsernameAvailable($username)
function isUserSuspendedOrBanned($userId)
{
$builder = $this->db->table($this->users_tb);
$builder->select([$this->users_tb.'status',$this->status_tb.'status_name']);
$builder->select([$this->users_tb.'.status',$this->status_tb.'.status_name']);
$builder->join($this->status_tb,$this->status_tb.'.id='.$this->users_tb.'.status','left');
$builder->where($this->users_tb.'.id',$userId);
$builder->whereIn($this->status_tb.'.status_name',['Suspended','Banned']);
$query = $builder->get();
$result = $query->getResultArray();
foreach($result as $r)
{
if(in_array($r['status_name'],['Suspended','Banned']))
{
exit('Sorry your account is '.$r['status_name'] .'due to vialation of our rules and policies!');
}
}
return $r['status_name'];
}
}


Expand Down
Loading

0 comments on commit ec9c88f

Please sign in to comment.