<?php
Class Logger {
	
		
    public function __construct() {
      //  $this->includes();
    }
	
    private function includes()
    {}
		
    public function system_debug($strMsg){
		global $system_debug;
		if($system_debug == 'true'){
			$phpver = (float)phpversion();
			if ($phpver >= 7.0) {
			   $prev_path = dirname(__DIR__, 1);
			}
			file_put_contents("$prev_path/tmp/logs/system_debug.log", '['.gmdate('Y-m-d H:i:s').'] ' . $strMsg .PHP_EOL.PHP_EOL , FILE_APPEND | LOCK_EX);
		}
    }
			
    public function scan_debug($strMsg){
		global $scan_debug;
		if($scan_debug == 'true'){
			$phpver = (float)phpversion();
			if ($phpver >= 7.0) {
			   $prev_path = dirname(__DIR__, 1);
			}
			file_put_contents("$prev_path/tmp/logs/scan_debug.log", '['.gmdate('Y-m-d H:i:s').'] ' . $strMsg .PHP_EOL.PHP_EOL , FILE_APPEND | LOCK_EX);
		}
    }
				
    public function smtp_debug($strMsg){
		global $smtp_debug;
		if($smtp_debug == 'true'){
			$phpver = (float)phpversion();
			if ($phpver >= 7.0) {
			   $prev_path = dirname(__DIR__, 1);
			}
			file_put_contents("$prev_path/tmp/logs/smtp_debug.log", '['.gmdate('Y-m-d H:i:s').'] ' . $strMsg .PHP_EOL.PHP_EOL , FILE_APPEND | LOCK_EX);
		}
    }

    public function log_delete($log_path){
		// Log cleaner
			if(file_exists($log_path)) {
			$clearfile = fopen( "$log_path", 'w' );
			fclose($clearfile);
			$error = false;
			$message = 'Log Data Cleared';
			$response = array(
				'success' => $message
			);
			exit(json_encode($response));
			} else {
				$error = true;
				$message = 'Couldn\'t delete log data. Log file don\'t exists!';
				$response = array(
					'error' => $message
				);
				exit(json_encode($response));
			}
     }
}