Skip to content

Commit

Permalink
Admin functionality added to the project
Browse files Browse the repository at this point in the history
  • Loading branch information
haastrupea committed Jul 6, 2020
1 parent cd822e1 commit 2a69096
Show file tree
Hide file tree
Showing 60 changed files with 2,779 additions and 46 deletions.
237 changes: 232 additions & 5 deletions app/mainland.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,28 @@
include_once 'controller/loader.php';
include_once 'view/loader.php';

//admin login check

function adminCHeck(){
if(!isset($_SESSION['adminLogIn'])){
header('Location: /home');
exit();
}

if(empty($_SESSION['adminLogIn'])){
header('Location: /home');
exit();
}

// check the
$model = new adminModel();
if($model->loginTokenCheck($_SESSION['adminLogIn'])!==true){
header('Location: /home');
exit();
}

return $_SESSION['adminLogIn'];
}
$router= new Router;

$router->get("/[home]",function(){
Expand Down Expand Up @@ -35,11 +57,6 @@
$resultPage->run($action,$param);
});

$router->get("/house/images/{view}/{quality}/{house_id}",function($req,$arg){
//view=front/back/bath/dinning/right/left/kitchen/bed
//quality=thumbnail/mobile/desktop/hd;
//house_id=house id used
});

$router->get("/house-search/{searchType}",function($req,$arg){
//redirect to landing page with form of search type preloaded
Expand All @@ -49,6 +66,216 @@

});

$router->get("/admin",function($req,$arg){
//loadController
$login=adminCHeck();

include_once "template/admin/home.php";
});//admin home page

//put the
$router->get("/admin/login/{loginToken}",function($req,$arg){
//loadController
$loginToken=filter_var($arg['loginToken'],FILTER_SANITIZE_SPECIAL_CHARS);

if(isset($_SESSION['adminLogIn']) && $_SESSION['adminLogIn'] ===$loginToken){
header("Location: /admin");
exit();
}


$action="login";
$loginController=new adminLoginController();
$loginController->run($action,$loginToken);
});

$router->get("/admin/logout",function($req,$arg){
//loadController
$token = $_SESSION['adminLogIn'];
unset($_SESSION['adminLogIn']);
unset($_SESSION['manage-filter']);
unset($_SESSION["hide-notice"]);
unset($_SESSION["gallery-referer"]);
unset($_SESSION["view-house"]);
unset($_SESSION["house-message"]);
unset($_SESSION["add-photo-message"]);

header("Location: /admin/login/$token");
exit();
});//admin home page


//manage a photo
$router->get("/admin/gallery/{action}/{photo_id}",function($req,$arg){
$action = $arg['action'];
$photo = $arg['photo_id'];
$galleryController = new galleryController;
$galleryController->run($action,$photo);
});

//manage a photo
$router->post("/admin/gallery/updateView/{photo_id}/{value}/ajax",function($req,$arg){
$action = "updateView";
$value = $arg['value'];
$photo = $arg['photo_id'];
$galleryController = new galleryController;
$galleryController->run($action,['data'=>$value,'imgId'=>$photo]);
});

//manage a photo
$router->post("/admin/gallery/add-photo",function($req){
$post = $req->getBody();
$action = "addPhoto";
$galleryController = new galleryController;
$galleryController->run($action,$post);
});


/**===========================Edit house Start======================================= */

$router->get("/admin/edit-house/{house_id}[/{step}]",function($req,$arg){
$model = new housedataModel;
global $config;
$login =adminCHeck();
$step = isset($arg['step'])?$arg['step']:"";
$house_id = $arg['house_id'];
$house =$model->getHouseInfoById($house_id);
$views = $model->allImageView();
$gallery = $model->getphotogallery($house_id,false);
$imgDir = $config['housePictureDir']['unCategorisedPictures'];

$measureUnit = $model->getMeasuringUnit();
$category = $model->gethouseCategory();
$houseStructure = $model->gethouseStructure();
$propType = $model->propType($house['type']);
$countries = $model->allCountries();
$states = $model->getState($house['Country']);
$currencies = $model->getCurrency();

$error =isset($_SESSION['edit-house-error'])?$_SESSION['edit-house-error']:[];
include_once "template/admin/edit-house.php";
unset($_SESSION['edit-house-error']);
});//manage home page

$router->post("/admin/edit-house",function($req){
$post= $req->getBody();
$action="editHouse";

$editHouse= new editHouseController;
$editHouse->run($action,$post);
});//manage home page

/**===========================edit new house end======================================= */



/**===========================Add new house Start======================================= */

$router->get("/admin/add-house[/{step}][/{house_id}]",function($req,$arg){
global $config;
$login =adminCHeck();
$model = new housedataModel;
$step = isset($arg['step'])?$arg['step']:"";
$house_id = isset($arg['house_id'])?$arg['house_id']:"";
$views = $model->allImageView();
$gallery = $model->getphotogallery($house_id,false);
$imgDir = $config['housePictureDir']['unCategorisedPictures'];
$error =isset($_SESSION['add-house-error'])?$_SESSION['add-house-error']:[];
include_once "template/admin/add-house.php";
unset($_SESSION['add-house-error']);
});//manage home page

$router->post("/admin/add-house",function($req){
$post= $req->getBody();
$action="addHouse";

$addHouse= new AddHouseController;
$addHouse->run($action,$post);
});//manage home page

/**===========================Add new house end======================================= */




/**===========================View house Start======================================= */

$router->get("/admin/view-house/{id}",function($req,$arg){
$action = "viewHouse";
$house_id = $arg['id'];
unset($_SESSION['manage-filter']);//remove last action for proper redirection to manage houses tab

$viewHouses = new viewHouseController;
$viewHouses->run($action,$house_id);
});//manage home page

$router->post("/admin/view-house",function($req){
$post = $req->getBody();
$house_id = $post['house_id'];
header("Location: /admin/view-house/$house_id");
exit();
});//manage home page

/**===========================View house end======================================= */



/**===========================manage start======================================= */

$router->get("/admin/manage-houses/{filter}",function($req,$arg){
$action = "manageHouses";
$filter = $arg['filter'];
unset($_SESSION['view-house']);//remove last view house link for proper redirection to manage houses tab
$_SESSION['manage-filter'] = $filter;
$manageHouses = new manageHouseController;
$manageHouses->run($action,$filter);

});//manage home page

$router->get("/admin/manage-houses",function($req,$arg){
header("Location: /admin/manage-houses/listed");
exit();
});//manage houses landing page

$router->get("/admin/manage-house/{action}/{id}",function($req,$arg){
$action=$arg['action'];
$id=$arg['id'];
$manageHouses=new manageHouseController();
$manageHouses->run($action,$id);
});


$router->get("/admin/unlist-house/{id}",function($req,$arg){
$id=$arg['id'];
header("Location: /admin/manage-house/unlist/$id");
exit();
});

$router->get("/admin/list-house/{id}",function($req,$arg){
$id=$arg['id'];
header("Location: /admin/manage-house/list/$id");
exit();
});

$router->get("/admin/sold-house/{id}",function($req,$arg){
$id=$arg['id'];
header("Location: /admin/manage-house/sell/$id");
exit();
});

/**===============================manage end====================================== */
//admin login processing
$router->post("/admin/login/{loginToken}",function($req,$arg){
//capture form data
$post = $req->getBody();
//loadController
$loginToken=filter_var($arg['loginToken'],FILTER_SANITIZE_SPECIAL_CHARS);
$action="logAdminIn";
$loginController=new adminLoginController();
$loginController->run($action,['loginToken'=>$loginToken,'loginDetails'=>$post]);
});



$router->get("/house-search",function(){
//to redirect general search back here
Expand Down
Binary file removed assets/images/houses/225c2c26ab1ce062b412.jpg
Binary file not shown.
Binary file removed assets/images/houses/335743912562170762cc.jpg
Binary file not shown.
Binary file removed assets/images/houses/35da5796aced2741e825.jpg
Binary file not shown.
Binary file added assets/images/houses/36721eb7478157ca29fa.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/images/houses/654899ffac6fad99e56a.jpg
Binary file not shown.
Binary file removed assets/images/houses/878ea143dc3e8d472344.jpg
Binary file not shown.
Binary file added assets/images/houses/8e01e8348774d40b707f.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/houses/92804d992ec6d2e2ed09.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/images/houses/9c4f6a0a3df0988784cf.jpg
Binary file not shown.
Binary file removed assets/images/houses/ae7070b4bfb20a93bf72.jpg
Binary file not shown.
Binary file added assets/images/houses/c5e49db3ad29b087ed89.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/houses/house_dummy_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/houses/house_dummy_2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/houses/house_dummy_3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/houses/house_dummy_4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/houses/house_dummy_5.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/houses/house_dummy_6.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/houses/house_dummy_7.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/houses/house_dummy_8.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/houses/house_dummy_9.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions controller/AddHouseController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
class AddHouseController{
protected $model;

private function addHouse($newFormData){
$login=adminCHeck(); //check if the admin is logged in;
//[DataType,required=1 | optional=0]
//key of validate is the same as the name of form field
$validate=["size_measurement"=>"Number,1","size_measure_unit"=>"MeasuringUnit,1","category"=>"String,1","houseCategory"=>"String,1","propType"=>"String,1","Country"=>"Country,1","State"=>"State,1","area_located"=>"String,1","address"=>"String,1","fixed_price"=>"Number,1","fixed_price_currency"=>"Currency,1","room"=>"Number,1","bath"=>"Number,1","description"=>"String,1","features"=>"String,0","amenities"=>"String,0"];


//validate the data
$error = $this->model->validate($newFormData,$validate);
//pass the data on th model for insert
if(empty($error)){
$cleanData = $this->model->removeEmptyfield($newFormData);
$Alreadyexist = $this->model->houseExist($cleanData);

if($Alreadyexist){
$houseId = $this->model->getLastHouseId($cleanData);
$_SESSION['house-message'] = "Already Exist: The house is already in your collections,Check it out <a href='/admin/view-house/$houseId' class='btn btn-outline-warning'>here</a>";
header("Location: /admin/add-house");
exit();
}

$house_id =$this->model->saveNewHouse($cleanData);
if($house_id !==false){
//set session of message
$_SESSION['house-message'] = "House added successfully";
//redirect to gallery step under add house
$_SESSION['gallery-referer'] = "/admin/add-house/gallery/$house_id";
header("Location: /admin/add-house/gallery/$house_id");
exit();
}


}else{
$_SESSION['add-house-error']=$error;
header("Location: /admin/add-house");
exit();
}

// $view = new addHouseView;
// include_once $view->run();
}
private function doNothing(){
header("Location: /admin");
exit();
}
public function run($method,$param)
{
$this->model = new housedataModel;
$run = method_exists($this,$method)?$method:"doNothing";

$this->{$run}($param);
}
}
56 changes: 56 additions & 0 deletions controller/adminLoginController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

class adminLoginController{
private $model;
protected function loginCheck($token){
//check if token given is correct
if(!$this->model->loginTokenCheck($token)){
header("Location: /home");
exit();
}
}
private function login($loginToken){
$this->loginCheck($loginToken);//login token check
//show login page
//view
$error=isset($_SESSION['adminLoginError'])?$_SESSION['adminLoginError']:null;


$login=new adminLoginView;

include_once $login->run();

if(isset($_SESSION['adminLoginError'])){
unset($_SESSION['adminLoginError']);
}
}

private function logAdminIn($credencials)
{
//with token
$loginToken = $credencials['loginToken'];
$this->loginCheck($loginToken);//login token check

$loginDetails = $credencials['loginDetails'];


$login=$this->model->adminLogin($loginDetails['username'],$loginDetails['password'],$loginToken);
if($login){
header("Location: /admin");
}else{
$_SESSION['adminLoginError'] = "Wrong Login Credentials: Try again";
header("Location: /admin/login/$loginToken");
}
exit();
}

public function run($method,$arg){

$this->model=new adminModel;

//load needed models to render current view
$run=method_exists($this,$method)?$method:'login';
$this->{$run}($arg);
}

}
Loading

0 comments on commit 2a69096

Please sign in to comment.