<?php

	function show_403(){
		throw new Exception("ERROR: Access denied.", 403);
	}

	function show_404(){
		throw new Exception("ERROR: This page does not exist.", 404);
	}

	function show_500($message){
		throw new Exception("ERROR: $message.", 500);
	}

	function show_503(){
		throw new Exception("ERROR: We are under maintenance.", 503);
	}

	function convert_date($data, $type=null){
		if (strpos($data, "/") != "") {
			if (strpos($data, ":") != "" and strpos($data, " ") != ""){
				$aux = explode(" ", $data);
				$d = $aux[0];
				$h = $aux[1];

				$aux = explode("/", $d);
				return $aux[2]."-".$aux[1]."-".$aux[0]." ".$h;
			}
			else{
				$aux = explode("/", $data);
				return $aux[2]."-".$aux[1]."-".$aux[0];
			}
		}
		else if (strpos($data, "-") != "") {
			if (strpos($data, ":") != "" and strpos($data, " ") != ""){
				$aux = explode(" ", $data);
				$d = $aux[0];
				$h = $aux[1];

				$aux = explode("-", $d);
				return $aux[2]."/".$aux[1]."/".$aux[0]." ".$h;
			}
			else{
				$aux = explode("-", $data);
				return $aux[2]."/".$aux[1]."/".$aux[0];
			}
		}
		else{
			return $data;
		}
	}

	function first_name($name){
		$array = explode(" ", $name);

		if (count($array) > 1) {
			return $array[0];
		}
		else{
			return $name;
		}
	}

	function first_last_name($name){
		$array = explode(" ", $name);

		if (count($array) == 1) {
			return $array[0];
		}
		else if (count($array) >= 2) {
			return $array[0]." ".$array[1];
		}
		else{
			return $name;
		}
	}

	function validate_cpf($cpf){
		if (empty($cpf)) {
			return false;
		}

		$cpf = preg_replace("/[^0-9]/", "", $cpf);
		$cpf = str_pad($cpf, 11, '0', STR_PAD_LEFT);
	
		if (strlen($cpf) != 11) {
			return false;
		}
		elseif ($cpf == "00000000000" or $cpf == "11111111111" or $cpf == "22222222222" or $cpf == "33333333333" or $cpf == "44444444444" or $cpf == "55555555555" or $cpf == "66666666666" or $cpf == "77777777777" or $cpf == "88888888888" or $cpf == "99999999999" or $cpf == "12345678909") {
			return false;
		}
		else{   
			for ($t = 9; $t < 11; $t++) {
				for ($d = 0, $c = 0; $c < $t; $c++) {
					$d += $cpf[$c] * (($t + 1) - $c);
				}
				$d = ((10 * $d) % 11) % 10;
				if ($cpf[$c] != $d) {
					return false;
				}
			}
			return true;
		}
	}

	function validate_cnpj($cnpj){ 
		if (empty($cnpj)) {
			return false;
		}

		$cnpj = preg_replace("/[^0-9]/", "", $cnpj);
		$cnpj = str_pad($cnpj, 14, '0', STR_PAD_LEFT);
		
		if (strlen($cnpj) != 14) {
			return false;
		}
		else if ($cnpj == "00000000000000" or $cnpj == "11111111111111" or $cnpj == "22222222222222" or $cnpj == "33333333333333" or $cnpj == "44444444444444" or $cnpj == "55555555555555" or $cnpj == "66666666666666" or $cnpj == "77777777777777" or $cnpj == "88888888888888" or $cnpj == "99999999999999") {
			return false;
		}
		else {   
			$j = 5;
			$k = 6;
			$soma1 = 0;
			$soma2 = 0;

			for ($i = 0; $i < 13; $i++) {
				$j = $j == 1 ? 9 : $j;
				$k = $k == 1 ? 9 : $k;

				$soma2 += ($cnpj[$i] * $k);

				if ($i < 12) {
					$soma1 += ($cnpj[$i] * $j);
				}

				$k--;
				$j--;
			}

			$digito1 = $soma1 % 11 < 2 ? 0 : 11 - $soma1 % 11;
			$digito2 = $soma2 % 11 < 2 ? 0 : 11 - $soma2 % 11;

			if ($cnpj[12] == $digito1 and $cnpj[13] == $digito2){
				return true;
			}
			else{
				return false;
			}
		}
	}

	function validate_cep($cep){
		if (preg_match("/[0-9]{5}-[0-9]{3}/", $cep) == 1) {
			if (preg_replace("/[0-9]{5}-[0-9]{3}/", "", $cep) != "") {
				return false;
			}           
			return true;
		}
		else{
			return false;
		}
	}

	function validate_date($date){
		if (preg_match("/(\d{2})\/(\d{2})\/(\d{4})/", $date, $aux) == 1) {
			$d = $aux[1];
			$m = $aux[2];
			$y = $aux[3];
		}
		elseif (preg_match("/(\d{4})\-(\d{2})\-(\d{2})/", $date, $aux) == 1) {
			$d = $aux[3];
			$m = $aux[2];
			$y = $aux[1];
		}
		else{
			return false;
		}
	
		if (checkdate($m, $d, $y) == 1){
			return true;
		}
		else{
			return false;
		}
	}

	function validate_birth_date($date){
		if (validate_date($date)) {
			if (preg_match("/(\d{2})\/(\d{2})\/(\d{4})/", $date) == 1){
				$date = convert_date($date);
			}
			
			return (date("Y-m-d") >= $date and $date >= date("Y-m-d", strtotime("-125 years", strtotime(date("Y-m-d"))))) ? true : false;
		}
		else{
			return false;
		}
	}

	function validate_email($email){
		if (preg_match("/([A-z\_\.0-9]{1,64})\@([A-z\.\_0-9]{1,254})/", $email) == 1){
			if (preg_replace("/([A-z\_\.0-9]{1,64})\@([A-z\.\_0-9]{1,254})/", "", $email) != "") {
				return false;
			}
			return true;
		}
		else{
			return false;
		}
	}

	function validate_url($url){
		if (filter_var($url, FILTER_VALIDATE_URL) !== false) {
			return true;
		}
		else{
			return false;
		}
	}

	function validate_ip($ip){
		if (filter_var($ip, FILTER_VALIDATE_IP) !== false) {
			return true;
		}
		else{
			return false;
		}
	}

	function import_file($path, $vars = [], $once=true){
		if (preg_match("/[\/]$/", $path) == 1) {
			$path = substr($path, 1);
		}

		if (preg_match("/[.php]$/", $path) == 0) {
			$path .= ".php";
		}

		if (!file_exists($path)) {
			throw new Exception("ERROR: The $path file does not exist.", 500);
		}

		if (gettype($vars) == "array" and count($vars) > 0) {
			foreach ($vars as $key => $value) {
				$$key = !empty($value) ? $value : "";
			}
		}

		if ($once == true) {
			require_once($path);
		}
		else{	
			require($path);
		}
	}

	function show_slug($string) {
		$what = ['ä','ã','à','á','â','ê','ë','è','é','ï','ì','í','ö','õ','ò','ó','ô','ü','ù','ú','û','À','Á','É','Í','Ó','Ú','ñ','Ñ','ç','Ç',' ','-','(',')',',',';',':','|','!','"','#','$','%','&','/','=','?','~','^','>','<','ª','º',"+","*",".",",",";","'",'"'];

		$by   = ['a','a','a','a','a','e','e','e','e','i','i','i','o','o','o','o','o','u','u','u','u','A','A','E','I','O','U','n','n','c','C','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_',"","","","","","",""];

		return strtolower(str_replace($what, $by, $string));
	}

	function encrypt_encode($string){
		return Encryption::encode($string);
	}

	function encrypt_decode($string){
		return Encryption::decode($string);
	}

	function get_path(){
		return Pagination::getPath();
	}

	function get_page(){
		return Pagination::getPage();
	}

	function exist_page(){
		return Pagination::issetPage();
	}

	function show_url($link = null){
		return (isset($_SERVER["HTTPS"]) ? "https" : "http")."://".$_SERVER["HTTP_HOST"].show_link($link);
	}

	function show_link($string = null){
		return Pagination::link($string);
	}

	function show_file_link($link){
		return show_link($link."?v=".filemtime($_SERVER["DOCUMENT_ROOT"].show_link($link)));
	}

	function show_dir($dir){
		return $_SERVER["DOCUMENT_ROOT"].show_link($dir);
	}

	function get_error_page($code){
		return Pagination::getErrorPage($code);
	}

	function upload_file($files, $dir, $filter=ALL_FILES, $subfolder=true, $file_name=null, $reduce=true){
		return File::upload($files, $dir, $filter, $subfolder, $file_name, $reduce);
	}

	function delete_file($dir_file, $report_error=false){
		return File::delete($dir_file, $report_error);
	}

	function money_mask_BR($money){
		$num_negativo = false;

		$money = empty($money) ? "0" : $money;
		$money = str_replace(",", ".", $money);
		$aux = explode(".", $money);
		
		if (empty($aux[1]) or intval($aux[1]) == 0) {
			$aux[1] = "00";
		}
		elseif (strlen($aux[1]) == 1){
			$aux[1] = $aux[1]."0";
		}
		else{
			$aux[1] = substr($aux[1], 0, 2);
		}

		$int = "";

		if (strpos($aux[0], "-") !== false) {
			$aux[0] = str_replace("-", "", $aux[0]);
			$num_negativo = true;
		}

		if (strlen($aux[0]) > 3) {
			$str = strrev($aux[0]);

			for ($i=0; $i < strlen($str); $i++) {
				$int .= $str[$i];

				if (is_int(($i+1) / 3) and $i != 0 and ($i+1) < strlen($str)) {
					$int .= ".";
				}
			}

			$int = strrev($int);
		}
		else{
			$int = $aux[0];
		}

		if ($num_negativo) {
			return "R$ -".$int.",".$aux[1];
		}
		else{
			return "R$ ".$int.",".$aux[1];
		}
	}

	function pct($val){
		$aux = intval(str_replace("%", "", $val));
		return ($aux/100);
	}

	function generate_password($number = 12){
		$chars = [
			1 => "q",
			2 => "w",
			3 => "e",
			4 => "r",
			5 => "t",
			6 => "y",
			7 => "u",
			8 => "i",
			9 => "o",
			10 => "p",
			11 => "a",
			12 => "s",
			13 => "d",
			14 => "f",
			15 => "g",
			16 => "h",
			17 => "j",
			18 => "k",
			19 => "l",
			20 => "ç",
			21 => "z",
			22 => "x",
			23 => "c",
			24 => "v",
			25 => "b",
			26 => "n",
			27 => "m",
			28 => "0",
			29 => "1",
			30 => "2",
			31 => "3",
			32 => "4",
			33 => "5",
			34 => "6",
			35 => "7",
			36 => "8",
			37 => "9",
			38 => "!",
			39 => "@",
			40 => "%",
			41 => "#",
			42 => "+",
			43 => "-",
			44 => "*",
			45 => "&",
			46 => "Q",
			47 => "W",
			48 => "E",
			49 => "R",
			50 => "T",
			51 => "Y",
			52 => "U",
			53 => "I",
			54 => "O",
			55 => "P",
			56 => "A",
			57 => "S",
			58 => "D",
			59 => "F",
			60 => "G",
			61 => "H",
			62 => "J",
			63 => "K",
			64 => "L",
			65 => "Ç",
			66 => "Z",
			67 => "X",
			68 => "C",
			69 => "V",
			70 => "B",
			71 => "N",
			72 => "M"
		];

		$pass = "";

		for ($i = 0; $i < $number; $i++) { 
			$pass .= $chars[rand(1, count($chars))];
		}

		return $pass;
	}

	function delete_folder($folder){ 
		$dir_folder = $_SERVER["DOCUMENT_ROOT"].show_link($folder);

		$iterator = new RecursiveDirectoryIterator($dir_folder, FilesystemIterator::SKIP_DOTS);
		$rec_iterator = new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::CHILD_FIRST);

		foreach($rec_iterator as $file){ 
			if ($file->isFile()) {
				unlink($file->getPathname());
			}
			else{
				rmdir($file->getPathname()); 
			}
		}

		rmdir($dir_folder); 
	}

	function hex_rgba($hex, $a=1){
		if (strlen($hex) == 7 and is_numeric($a) and $a <= 1) {
			$str = str_replace("#", "", $hex);
			$aux = str_split($str, 2);

			$r = hexdec($aux[0]);
			$g = hexdec($aux[1]);
			$b = hexdec($aux[2]);

			return "rgba(".$r.",".$g.",".$b.",".$a.")";
		}
		return false;
	}

	function is_color_light($hex){
		if (strlen($hex) == 7) {
			$str = str_replace("#", "", $hex);
			$aux = str_split($str, 2);

			$r = intval(hexdec($aux[0]));
			$g = intval(hexdec($aux[1]));
			$b = intval(hexdec($aux[2]));

			$lum = ($r*299 + $g*587 + $b*114)/1000;

			if ($lum > 128) {
				return true;
			}
			else{
				return false;
			}
		}
		return null;
	}

	function color_scale($hex, $grau){
		if (strlen($hex) == 7 and strpos($grau, "%") !== false and (strpos($grau, "+") !== false or strpos($grau, "-") !== false)) {
			$str = str_replace("#", "", $hex);
			$aux = str_split($str, 2);
			
			$r = intval(hexdec($aux[0]));
			$g = intval(hexdec($aux[1]));
			$b = intval(hexdec($aux[2]));
			
			if (strpos($grau, "+") !== false) {
				$num = intval(str_replace("+", "", str_replace("%", "", $grau)));
				$pct = pct($num);

				$vr = ($r == 0) ? ceil(255*$pct) : ceil($r*$pct);
				$vg = ($g == 0) ? ceil(255*$pct) : ceil($g*$pct);
				$vb = ($b == 0) ? ceil(255*$pct) : ceil($b*$pct);
		
				if ($r == 255) {
					if ($g == 0 and $b == 0) {
						$vb += $vr;
					}
					$vg += $vr;
					$new_r = 255;
				}
				else if (($r+$vr) > 255) {
					$new_r = 255;
					$aux = ($r+$vr) - 255;
					if ($g == 0 and $b == 0) {
						$vb += $aux;
					}
					$vg += $aux;
				}
				else{
					$new_r = $r+$vr;
				}
				
				$vr = 0;
				
				if ($g == 255) {
					if ($r == 0 and $b == 0) {
						$vr += $vg;
					}
					$vb += $vg;
					$new_g = 255;
				}
				else if (($g+$vg) > 255) {
					$new_g = 255;
					$aux = ($g+$vg) - 255;
					if ($r == 0 and $b == 0) {
						$vr += $aux;
					}
					$vb += $aux;
				}
				else{
					$new_g = $g+$vg;
				}
				
				$vg = 0;
				
				if ($b == 255) {
					if ($r == 0 and $g == 0) {
						$vg += $vb;
					}
					$vr += $vb;
					$new_b = 255;
				}
				else if (($b+$vb) > 255) {
					$new_b = 255;
					$aux = ($b+$vb) - 255;
					if ($r == 0 and $g == 0) {
						$vg += $aux;
					}
					$vr += $aux;
				}
				else{
					$new_b = $b+$vb;
				}
				
				$vb = 0;
				
				if (($new_r+$vr) <= 255) {
					$new_r += $vr;
				}
				else{
					$new_r = 255;
					$vg += ($new_r+$vr) - 255;
				}
				
				if (($new_g+$vg) <= 255) {
					$new_g += $vg;
				}
				else{
					$new_g = 255;
					$vb += ($new_g+$vg) - 255;
				}
				
				if (($new_b+$vb) <= 255) {
					$new_b += $vb;
				}
				else{
					$new_b = 255;
				}
			}
			else{
				$num = intval(str_replace("-", "", str_replace("%", "", $grau)));
				$pct = pct($num);
				
				$vr = ceil($r*$pct);
				$vg = ceil($g*$pct);
				$vb = ceil($b*$pct);

				if ($r == 0) {
					$new_r = 0;
				}
				else if (($r-$vr) < 0) {
					$new_r = 0;
				}
				else{
					$new_r = $r-$vr;
				}

				if ($g == 0) {
					$new_g = 0;
				}
				else if (($g-$vg) < 0) {
					$new_g = 0;
				}
				else{
					$new_g = $g-$vg;
				}

				if ($b == 0) {
					$new_b = 0;
				}
				else if (($b-$vb) < 0) {
					$new_b = 0;
				}
				else{
					$new_b = $b-$vb;
				}
			}
			
			$pr = dechex($new_r);
			$pr = (strlen($pr) == 1) ? "0".$pr : $pr;
			$pg = dechex($new_g);
			$pg = (strlen($pg) == 1) ? "0".$pg : $pg;
			$pb = dechex($new_b);
			$pb = (strlen($pb) == 1) ? "0".$pb : $pb;
			
			return "#".$pr.$pg.$pb;
		}
		return false;
	}

	function anti_injection($string){
		$string = preg_replace("/(?i)[\#\(\)\*\/\\\=\%\[\]\+\-\{\}\$\&\<\>\|\,\;\'\"]|(select|from|insert|where|delete|drop|update|table|set|value)/", "" , $string);
		$string = trim($string);
		$string = strip_tags($string);
		
		if (get_magic_quotes_gpc()) {
			return $string;
		}
		else{
			return addslashes($string);
		}
	}

	function compress_string($string, $length, $break = false){
		if (strlen($string) <= $length) {
			$new_string = $string;
		}
		else{
			if ($break == true) { 
				$new_string = trim(mb_substr($string, 0, $length))."...";
			}
			else{
				$last_space = strrpos(mb_substr($string, 0, $length), " ");
				$new_string = trim(mb_substr($string, 0, $last_space))."...";
			}
		}

		return $new_string;
	}
	
	function get_client_access(){
		$ip = $_SERVER["REMOTE_ADDR"];

		$user_agent = $_SERVER["HTTP_USER_AGENT"];
		$browser = "";
		$platform = "";

		if (preg_match("/windows phone/i", $user_agent)) {
			$platform = "Windows Phone";
		}
		elseif (preg_match("/iphone/i", $user_agent)) {
			$platform = "iPhone";
		}
		elseif (preg_match("/android/i", $user_agent)) {
			$platform = "Android";
		}
		elseif (preg_match("/blackberry/i", $user_agent)) {
			$platform = "BlackBerry";
		}
		elseif (preg_match("/webos/i", $user_agent)) {
			$platform = "Mobile";
		}
		elseif (preg_match("/ipod/i", $user_agent)) {
			$platform = "iPod";
		}
		elseif (preg_match("/ipad/i", $user_agent)) {
			$platform = "iPad";
		}
		elseif (preg_match("/linux/i", $user_agent)) {
			$platform = "Linux";
		}
		elseif (preg_match("/macintosh|mac os x/i", $user_agent)) {
			if (preg_match('/macintosh/i', $user_agent)) {
			$platform = "Mac OS X";
			}
			elseif (preg_match('/mac_powerpc/i', $user_agent)) {
			$platform = "Mac OS 9";
			}
			else{
			$platform = "Mac";
			}
		}
		elseif (preg_match("/windows|win32/i", $user_agent)) {
			if (preg_match("/Windows NT 10.0/i", $user_agent)) {
			$platform = "Windows 10";
			}
			elseif (preg_match("/Windows NT 6.3/i", $user_agent)) {
			$platform = "Windows 8.1";
			}
			elseif (preg_match("/Windows NT 6.2/i", $user_agent)) {
			$platform = "Windows 8";
			}
			elseif (preg_match("/Windows NT 6.1/i", $user_agent)) {
			$platform = "Windows 7";
			}
			elseif (preg_match("/Windows NT 6.0/i", $user_agent)) {
			$platform = "Windows Vista";
			}
			elseif (preg_match("/Windows NT 5.2/i", $user_agent)) {
			$platform = "Windows Server 2003";
			}
			elseif (preg_match("/Windows NT 5.1/i", $user_agent)) {
			$platform = "Windows XP";
			}
			elseif (preg_match("/Windows NT 5.0/i", $user_agent)) {
			$platform = "Windows 2000";
			}
			elseif (preg_match("/Windows ME/i", $user_agent)) {
			$platform = "Windows ME";
			}
			elseif (preg_match("/Win98/i", $user_agent)) {
			$platform = "Windows 98";
			}
			elseif (preg_match("/Win95/i", $user_agent)) {
			$platform = "Windows 95";
			}
			elseif (preg_match("/Win16/i", $user_agent)) {
			$platform = "Windows 3.11";
			}
			else{
			$platform = "Windows";
			}

			if (preg_match("/x86/i", $user_agent)) {
			$platform .= " x86";
			}
			elseif (preg_match("/x64/i", $user_agent)) {
			$platform .= " x64";
			}
			elseif (preg_match("/WOW64/i", $user_agent)) {
			$platform .= " x64";
			}
			elseif (preg_match("/WOW86/i", $user_agent)) {
			$platform .= " x86";
			}
		}
		else{
			$platform = "Desconhecida";
		}

		if (preg_match("/MSIE/i", $user_agent) or (preg_match("/WOW/i", $user_agent) and preg_match("/Trident/i", $user_agent))) {
			$browser = "Internet Explorer";
		}
		elseif (preg_match("/Firefox/i", $user_agent)) {
			$browser = "Mozilla Firefox";
		}
		elseif (preg_match("/Edge/i", $user_agent)) {
			$browser = "Microsoft Edge";
		}
		elseif (preg_match("/OPR/i", $user_agent)) {
			$browser = "Opera";
		}
		elseif (preg_match("/Chrome/i", $user_agent)) {
			$browser = "Google Chrome";
		}
		elseif (preg_match("/AppleWebKit/i", $user_agent)) {
			$browser = "AppleWebKit";
		}
		elseif (preg_match("/Safari/i", $user_agent)) {
			$browser = "Apple Safari";
		}
		elseif (preg_match("/Netscape/i", $user_agent)) {
			$browser = "Netscape";
		}
		else{
			$browser = "Desconhecido";
		}

		return ["ip" => $ip, "browser" => $browser, "platform" => $platform];
	}

	function add_working_days($date, $period) {
		$days = 0;
		$working_days = 0;

		while ($working_days < $period) {
			$days++;
			$weekdays = date("w", strtotime("+".$days." days", strtotime($date)));

			if ($weekdays != "0" && $weekdays != "6") {
				$working_days++;
			}
		}

		return date("Y-m-d", strtotime("+".$days." days", strtotime($date)));
	}

	function get_request_url($url) {
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		$data = curl_exec($ch);
		curl_close($ch);
		
		return $data;
	}

	function password($pass){
		return sha1(SECURITY_KEY."$3aP7_&%90Xhb".$pass);
	}

	function create_htaccess($update = false){
		if (@filemtime(show_dir("/.htaccess")) < @filemtime(show_dir("/__settings__/settings.php")) or $update == true) {
			@unlink(show_dir("/.htaccess"));

			$file = fopen(show_dir("/.htaccess"), "a+");

			$content = "RewriteEngine on

				Options -Indexes

				RewriteCond $1 !^(index.php|resources|robots.txt)
				RewriteCond %{REQUEST_FILENAME} !-f
				RewriteCond %{REQUEST_FILENAME} !-d
				RewriteRule ^(.*)$ index.php/$1 [L,QSA]

				ErrorDocument 400 ".URL_BASE."/__application__/__views__/__errors__/400.html
				ErrorDocument 401 ".URL_BASE."/__application__/__views__/__errors__/401.html
				ErrorDocument 403 ".URL_BASE."/__application__/__views__/__errors__/403.html
				ErrorDocument 404 ".URL_BASE."/__application__/__views__/__errors__/404.html
				ErrorDocument 408 ".URL_BASE."/__application__/__views__/__errors__/408.html
				ErrorDocument 500 ".URL_BASE."/__application__/__views__/__errors__/500.html
				ErrorDocument 503 ".URL_BASE."/__application__/__views__/__errors__/503.html

				<Files .htaccess>
					order allow,deny
					deny from all
				</Files>";

			fwrite($file, str_replace("\t", "", $content));
			fclose($file);

			unset($file, $content);	
		}
	}

	function create_manifest_json($update = false){
		if (@filemtime(show_dir("/manifest.json")) < @filemtime(show_dir("/__settings__/settings.php")) or $update == true) {
			@unlink(show_dir("/manifest.json"));

			$file = fopen(show_dir("/manifest.json"), "a+");

			$content = "{
				\"name\": \"".SYS_NAME."\",
				\"short_name\": \"".SYS_NAME."\",
				\"theme_color\": \"#ffffff\",
				\"background_color\": \"#ffffff\",
				\"display\": \"standalone\",
				\"start_url\": \"".show_url("/")."\",
				\"icons\": [
					{
						\"src\": \"".show_url(SYS_ICONE)."\",
						\"sizes\": \"72x72\",
						\"type\": \"image/".pathinfo(show_url(SYS_ICONE))["extension"]."\"
					}
				],
				\"url\": \"".show_url("/")."\",
				\"lang\": \"Portuguese\",
				\"screenshots\": []
			}";

			fwrite($file, str_replace("\t", "", $content));
			fclose($file);

			unset($file, $content);	
		}
	}

	if (ENABLE_EMAIL) {
		function send_email($to, $subject, $message){
			$mail = new PHPMailer\PHPMailer\PHPMailer(true);

			try {
				$mail->SMTPDebug = 0;
				$mail->isSMTP(); 
				$mail->Host       = EMAIL_HOST;
				$mail->SMTPAuth   = true;
				$mail->Username   = EMAIL_USERNAME;
				$mail->Password   = EMAIL_PASSWORD;
				$mail->SMTPSecure = "ssl";
				$mail->Port       = 465;
				$mail->CharSet    = "UTF-8";

				$mail->SMTPOptions = [
					"ssl" => [
						"verify_peer" => false,
						"verify_peer_name" => false,
						"allow_self_signed" => true
					]
				 ];   

				$mail->setLanguage("pt_br", "__libraries__/PHPMailer/language/");

				$mail->setFrom(EMAIL_USERNAME, "Não Responda | ".SYS_NAME);

				if (is_array($to["name"]) and is_array($to["email"])) {
					for ($i=0; $i < count($to["email"]); $i++) { 
						$mail->addAddress($to["email"][$i], $to["name"][$i]);
					}
				}
				else{
					$mail->addAddress($to["email"], $to["name"]);
				}

				$mail->isHTML(true);
				$mail->Subject = $subject;
				$mail->Body    = $message;

				return $mail->send();
			} 
			catch (PHPMailer\PHPMailer\Exception $e) {
				return false;
			}
		}
	}

?>