Your IP : 216.73.216.172
<?php
include_once 'constant.php';
include_once 'function.php';
$uri = basename($_SERVER['REQUEST_URI'], '?' . $_SERVER['QUERY_STRING']);
class Profile{
function __construct() {
//select
if (array_key_exists('LoginUser', $_POST)) { $this->LoginUser();}
elseif (array_key_exists('LoginUser2', $_POST)) { $this->LoginUser2();}
elseif (array_key_exists('ApplyNow', $_POST)) { $this->ApplyNow();}
elseif (array_key_exists('UpdateCv', $_POST)) { $this->UpdateCv();}
elseif (array_key_exists('UpdatePhoto', $_POST)) { $this->UpdatePhoto();}
elseif(isset($_GET['logout'])){ $this->Logout(); }
//delete
}
function Uid(){
return $_SESSION['useridX']??'';
}
function checkLogin(){
if(isset($_SESSION['useridX'])){
return true;
}
return false;
}
function Admin($uid){
$admin = userName($uid,'type')==2 ? true : false;
return $admin;
}
function adminAccess(){
if($this->Admin($this->Uid())){
}else{
$this->redirect('login.php');
}
return;
}
function redirect($str){
header("Location: $str");
exit;
}
function Logout(){
setcookie('user_agent', 0, time() - (86400 * 730), "/");
setcookie('user_agent_type', 0, time() - (86400 * 730), "/");
// session_destroy();
header('location: login.php');
return;
}
function LoginUser(){
extract($_POST);
$sql = dbSelect('user',['email'=>$email]);
if(mysqli_num_rows($sql) != 1){
$_SESSION['error_message'] = 'Invalid email or password!';
return;
}
$row = mysqli_fetch_assoc($sql);
extract($row);
if(password_verify($passwordx, $password)) {
setcookie('user_agent', $pub, time() + (86400 * 730), "/");
setcookie('user_agent_type', $type, time() + (86400 * 730), "/");
$_SESSION['success_message'] = 'Successfully logged in';
if($type==1){ header('location: ./dashboard.php'); }
elseif($type==2){ header('location: ./jobportal.php'); }
elseif($type==3){header('location: ./adminportal.php');}
}
else{
$_SESSION['error_message'] = 'Invalid email or password!';
return;
}
}
function LoginUser2(){
extract($_POST);
$sql = dbSelect('user',['email'=>$email]);
if(mysqli_num_rows($sql) != 1){
$_SESSION['error_message'] = 'Invalid email or password!';
return;
}
$row = mysqli_fetch_assoc($sql);
extract($row);
if(password_verify($passwordx, $password)) {
$_SESSION['user_id'] = $row['id'];
$_SESSION['type'] = $type;
setcookie('user_agent', $pub, time() + (86400 * 730), "/");
setcookie('user_agent_type', $type, time() + (86400 * 730), "/");
$_SESSION['success_message'] = 'Successfully Logged in!';
}
else{
$_SESSION['error_message'] = 'Invalid email or password!';
return;
}
}
function ApplyNow(){
$pub = $_COOKIE['user_agent']??0;
$uid = sqLx('user','pub',$pub,'id');
$job = $_GET['job']??0;
$jobid = sqLx('listing','slug',$job,'id');
$sid = $_POST['ApplyNow']??0;
$array = ['uid'=>$uid,'sid'=>$sid,'lid'=>$jobid,];
if(sqL2('application','uid',$uid,'lid',$jobid)==0){
dbInsert('application',$array);
$_SESSION['success_message'] = 'Application Successfully Submitted!';
}
}
function applicationStatus($st){
$status = '';
if($st==1){$status = 'Submitted'; }
elseif($st==2){$status = 'Processing'; }
elseif($st==3){$status = 'Shortlisted for Interview'; }
elseif($st==4){$status = 'Interview Passed'; }
elseif($st==5){$status = 'Interview Failed'; }
elseif($st==6){$status = 'Not Offered'; }
elseif($st==7){$status = 'Job Offered'; }
return $status;
}
function UpdateCv() {
if (!isset($_FILES['cv']) || $_FILES['cv']['error'] !== UPLOAD_ERR_OK) {
echo "Error uploading file.";
return;
}
$file = $_FILES['cv'];
$allowedMime = 'application/pdf';
$maxSize = 1000000; // 1000 KB
$uploadDir = 'docs/cv/';
// Ensure upload directory exists
if (!file_exists($uploadDir)) {
mkdir($uploadDir, 0775, true);
}
// Validate file type and size
if ($file['type'] !== $allowedMime) {
echo "Only PDF files are allowed.";
return;
}
if ($file['size'] > $maxSize) {
echo "File is too large. Must be under 1000KB.";
return;
}
$pub = $_COOKIE['user_agent']??0;
// Sanitize filename
// $filename = basename($file['name']);
$filename = 'cv'.win_hashs(12).'.pdf';// preg_replace("/[^a-zA-Z0-9\._-]/", "_", $filename);
$targetPath = $uploadDir . $filename;
if (move_uploaded_file($file['tmp_name'], $targetPath)) {
dbUpdate('user',['cv'=>$filename],['pub'=>$pub]);
echo "CV uploaded successfully!";
} else {
echo "Failed to move uploaded file.";
}
}
function UpdatePhoto() {
if (!isset($_FILES['photo']) || $_FILES['photo']['error'] !== UPLOAD_ERR_OK) {
echo "Error uploading file.";
return;
}
$file = $_FILES['photo'];
$allowedMimes = ['image/jpeg', 'image/png'];
$maxSize = 400000; // 200 KB
$uploadDir = 'docs/ph/';
// Ensure upload directory exists
if (!file_exists($uploadDir)) {
mkdir($uploadDir, 0775, true);
}
// Validate file type and size
if (!in_array($file['type'], $allowedMimes)) {
echo "Only JPG and PNG files are allowed.";
return;
}
if ($file['size'] > $maxSize) {
echo "File is too large. Must be under 400KB.";
return;
}
$pub = $_COOKIE['user_agent'] ?? 0;
// Generate a unique filename with correct extension
$ext = $file['type'] === 'image/png' ? '.png' : '.jpg';
$filename = 'ph_' . win_hashs(12) . $ext;
$targetPath = $uploadDir . $filename;
if (move_uploaded_file($file['tmp_name'], $targetPath)) {
dbUpdate('user', ['photo' => $filename], ['pub' => $pub]);
echo "Photo uploaded successfully!";
} else {
echo "Failed to move uploaded file.";
}
}
}
$pro = new Profile();
$admin = $pro->Uid();
$pub = $_COOKIE['user_agent']??0;
if(isset($_COOKIE['user_agent'])){
$uid = sqLx('user','pub',$pub,'id');
}
?>