<!DOCTYPE html>
<html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
</head>
  
<?php
 session_start();
 error_reporting(E_ALL); ini_set('display_errors', 1);
 session_unset(); 
 
 $_SESSION['CheckPWD']=false;
// 10 mins in seconds
$inactive = 30; 
//$_session['start_time']='xcadsasdasdasd' ;
//$_session['timeout']=time();

 header('Content-Type: charset=utf-8');
?>
 
<?php

//  echo gethostbyaddr($_SERVER['REMOTE_ADDR']).'<br>';
//  echo gethostname().'<br>';
//  echo php_uname('n').'<br>';
//  echo '-' . $_SERVER['HTTP_CLIENT_IP'].'<br>';

global $iniValues;

$file = fopen("config.ini","r");
 while(! feof($file)) {
   $line=fgets($file);
   $myArray  = explode('=', $line);
   if (count($myArray)>1) {
		 $key = str_replace("'", "\'",trim($myArray[0]));	
	   $value = str_replace("'", "\'",trim($myArray[1]));  
	   $value = str_replace('"', '',trim($myArray[1]));
	   
		  if($key!='') { $iniValues[$key]= $value;}
	}    
  }
fclose($file);



$_SESSION['inValues']=$iniValues;



# $ini_array = parse_ini_file('vsApps.ini'); 
# echo "<br>==========================". 
#      "<br>". $ini_array['DB_USERNAME'].
#	  "<br>==========================<br>";
# print_r(parse_ini_file("vsApps.ini"));
 
$LoginError=0 ;

/* 
$DB_SERVER = '127.0.0.1';  
$DB_USERNAME = 'root'; 
$DB_PASSWORD = 'P@ssw0rd~!'; 
$DB_NAME = 'vsapps'; 
 
$DB_SERVER = '185.138.42.20';  
$DB_USERNAME = 'liat066349_vaggelis.t'; 
$DB_PASSWORD = 'vs0760~!'; 
$DB_NAME = 'liat066349_vsapps'; 
 
$DB_SERVER = '192.168.1.161';  
$DB_USERNAME = 'vaggelis.t'; 
$DB_PASSWORD = 'vs0760!'; 
$DB_NAME = 'vsapps'; 


$DB_SERVER = '62.38.70.230';  
$DB_USERNAME = 'vaggelis.t'; 
$DB_PASSWORD = 'vs0760!'; 
$DB_NAME = 'vsapps';  
 
  vsApps --> liat066349_vsapps liat066349_vsappsuser,  VsApps12~!

*/
$iniValues['DB_USERNAME']=$iniValues['DB_PREFIX'].$iniValues['DB_USERNAME'];
$iniValues['DB_NAME']=$iniValues['DB_PREFIX'].$iniValues['DB_NAME'];

$txtUserName = $_POST["txtUserName"];
$txtUserPassword = $_POST["txtUserPassword"];

$DB_SERVER=str_replace('"', '',$iniValues['DB_SERVER']);
$DB_USERNAME=str_replace('"', '',$iniValues['DB_USERNAME']);
$DB_PASSWORD=str_replace('"', '',$iniValues['DB_PASSWORD']);
$DB_NAME=str_replace('"', '',$iniValues['DB_NAME']);


$_SESSION['inactive_time']=$iniValues['inactive_time'];
 
# $_serverHost = $_SERVER['HTTP_HOST'];
# $_phpSelf = $_SERVER['PHP_SELF'];
# $_serverDir = dirname( $_phpSelf );
# $_serverPort = $_SERVER['SERVER_PORT'];
# echo "phpversion : ";  print_r(phpversion() );
# echo "IsWindows : ". IsWindows()."<br>";
# echo function_exists('parse_ini_file');

# echo file_exists( "vsApps.ini");
 
// =========================== 
// Connect to MySQL database /
// ===========================
// echo $DB_SERVER . " " . $iniValues['DB_PREFIX'] . $DB_USERNAME . " " . $DB_PASSWORD . " " . $iniValues['DB_PREFIX'] . $DB_NAME . "<br>";
#echo "DB_SERVER : " . $DB_SERVER . " "  . "\r\n" . "<br>";
#echo "DB_USERNAME : " .  $DB_USERNAME . " "  . "\r\n" . "<br>";
#echo "DB_PASSWORD : " . $DB_PASSWORD . " " . "\r\n" . "<br>";
#echo "DB_NAME : " .  $DB_NAME . "\r\n" . "<br>";

#echo "<br>";
#echo "<br>";
#echo "<br>";
#echo "<br>";
#echo "<br>";
#echo "<br>";

$_SESSION['NOT_ADMIN']="";
$_SESSION['btnAdd']="";
$_SESSION['btnSave']="";
$_SESSION['btnDelete']="";

  $conn = mysqli_connect($DB_SERVER, $DB_USERNAME, $DB_PASSWORD,  $DB_NAME);
   mysqli_set_charset($conn, "utf8");
   
if($conn === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());
}
 else
{
	$sql = "SELECT * FROM users WHERE UserName='$txtUserName' and UserPassword='$txtUserPassword' and isActive=-1";
//	$vrs = $conn->query($sql);
//	echo $vrs->num_rows ;
	  $result = mysqli_query($conn, $sql);
		  $rs = mysqli_fetch_assoc($result);
	$num_rows = $result->num_rows; 
//	echo ("========================" . $num_rows);
	 
	if ($num_rows > 0) {
		 	 $_SESSION['DB_SERVER']=$DB_SERVER;
			 $_SESSION['DB_USERNAME']=$DB_USERNAME;
			 $_SESSION['DB_PASSWORD']=$DB_PASSWORD;
			 $_SESSION['DB_NAME']=$DB_NAME;
			 $_SESSION['DB_PREFIX']= $iniValues['DB_PREFIX'];
			 //$_SESSION['USER_TYPE']= $vrs['UserType'];
			 $_SESSION['CheckPWD']=true;
			 $_SESSION['USER']=$rs['UserName'];
			 if ($rs['UserType']=="Administrator"){$_SESSION['ISADMIN']=true;}
			 if ($rs['UserType']!="Administrator"){$_SESSION['NOT_ADMIN']="disabled";}
			 if ($rs['UserType']=="Read Only"){$_SESSION['btnAdd']="disabled";$_SESSION['btnSave']="disabled";$_SESSION['btnDelete']="disabled";}
			 if ($rs['UserType']=="Read/Write"){$_SESSION['btnDelete']="disabled";}
		//	header("Location: kentriko_menou.php");
		// exit();
	} else {
	 $LoginError=1;
	 $_SESSION['CheckPWD']=false;
	 header("Location: login.php?LoginError=$LoginError");
	 //echo '<script>alert("Λάθος όνομα χρήστη ή κωδικός (Password).");</script>';
	 $conn->close();
	}
	
if ( $_SESSION['CheckPWD']=true) {

$sql = "SELECT * FROM company_parameters ";
	  $result = mysqli_query($conn, $sql);
		  $rs = mysqli_fetch_assoc($result);
	$num_rows = $result->num_rows; 
 
	if ($num_rows > 0) {
		 	 $_SESSION['COMPANY_NAME']=$rs['CompanyName'];
			 $_SESSION['COMPANY_AFM']=$rs['CompanyAFM'];
			 $_SESSION['FOLDER_LOGOS']=$rs['Folder_Logos'];
			 $_SESSION['FOLDER_PICTURES']=$rs['Folder_Pictures'];
			 $_SESSION['FOLDER_UPLOAD']=$rs['Folder_Upload'];
			 $_SESSION['FTP_SERVER_FOLDER']=$rs['FtpServerFolder'];
			 $_SESSION['FTP_PROGRAM_FOLDER']=$rs['FtpProgrammFolder'];
	}
if($_SESSION['FTP_SERVER_FOLDER']== "") {
	$_SESSION['FTP_SERVER_FOLDER']= $_SERVER['DOCUMENT_ROOT']."/ftp";
}

header("Location: kentriko_menou.php");
}	
	// echo $sql .'<br>';	
}

 
?>

 
