<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Carbon;

class FunctionsController extends Controller{
    private $responseController;

    public function __construct(){
      $this->responseController = new ResponseController();
    }

    public static function uuidv5($namespace, $name) {
        if(!self::is_valid($namespace)) return false;

        // Get hexadecimal components of namespace
        $nhex = str_replace(array('-','{','}'), '', $namespace);

        // Binary Value
        $nstr = '';

        // Convert Namespace UUID to bits
        for($i = 0; $i < strlen($nhex); $i+=2) {
            $nstr .= chr(hexdec($nhex[$i].$nhex[$i+1]));
        }

        // Calculate hash value
        $hash = sha1($nstr . $name);

        return sprintf('%08s-%04s-%04x-%04x-%12s',

            // 32 bits for "time_low"
            substr($hash, 0, 8),

            // 16 bits for "time_mid"
            substr($hash, 8, 4),

            // 16 bits for "time_hi_and_version",
            // four most significant bits holds version number 5
            (hexdec(substr($hash, 12, 4)) & 0x0fff) | 0x5000,

            // 16 bits, 8 bits for "clk_seq_hi_res",
            // 8 bits for "clk_seq_low",
            // two most significant bits holds zero and one for variant DCE1.1
            (hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000,

            // 48 bits for "node"
            substr($hash, 20, 12)
        );
    }

    public static function is_valid($uuid) {
        return preg_match('/^\{?[0-9a-f]{8}\-?[0-9a-f]{4}\-?[0-9a-f]{4}\-?'.
                        '[0-9a-f]{4}\-?[0-9a-f]{12}\}?$/i', $uuid) === 1;
    }

    public function generateID($seed, $timestamp){
        $string = str_replace(" ", "", $seed) . $timestamp;
        $array = [];
        for($i = 0; $i < strlen($string); $i++){
            $array[] = $string[$i];
        }

        shuffle($array);
        $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        
        $ID = '';
        foreach($array as $char){
            $ascii = ord($char);

            $s = $ascii / 100;
            if($s >= 1) continue;

            $s = $s * strlen($chars);
            $s = intval($s);

            $l = $chars[$s];
            if(strlen($ID) < 20) $ID .= $l;
        }

        if(strlen($ID) < 20){
            for($i = strlen($ID); $i < 20; $i++){
                $s = rand(0, strlen($chars) - 1);
                $l = $chars[$s];
                $ID .= $l;
            }
        }
        
        return $ID;
    }

    public function getType($type){
        switch($type){
            case "insert":
                return "CREATE";
            break;
            case "update":
                return strtoupper($type);
            break;
            case "select":
                return "READ";
            break;
            case "delete":
                return strtoupper($type);
            break;
            default:
                return "UNKNOWN";
            break;
        }
    }

    public function registerLog($querys, $user, $date, $idac, $line){
        foreach($querys as $query){
            $script = $query['query'];
            $params = json_encode($query['bindings']);

            DB::table('S002V01TLOMY')->insert([
                'LOMY_NULI' => $line,
                'LOMY_IDAC' => $idac,
                'LOMY_QUER' => $script,
                'LOMY_PARA' => $params,
                'LOMY_FECH' => $date,
                'LOMY_IDUS' => $user,
            ]);
        }
    }

    public function registerActivity($line, $module, $function, $screen, $action, $description, $user, $date, $submodule = null){
        $id = DB::table('S002V01TACCI')->insertGetId([
            'ACCI_NULI' => $line,
            'ACCI_IDMO' => $module,
            'ACCI_IDSM' => $submodule,
            'ACCI_IDFU' => $function,
            'ACCI_IDPA' => $screen,
            'ACCI_TIAC' => $action,
            'ACCI_DESC' => $description,
            'ACCI_IDUS' => $user,
            'ACCI_FEAC' => $date
        ]);

        DB::table('S002V01TUSUA')->where('USUA_IDUS', '=', $user)->update([
            'USUA_ULAC' => $id
        ]);

        return $id;
    }

    public function joinName($name, $fApe, $sApe = null){
        $fullName = "$name $fApe";
        if(!is_null($sApe)){
            $fullName = "$fullName $sApe";
        }

        return $fullName;
    }

    public function checkFileSize($ext, $size){
        $availableFiles = [
            250=> ["zip", "tar", "rar", "7z", "mp3", "mpeg", "wav", "ogg", "opus", "jpg", "png", "gif", "bmp", "tiff", "svg",
            "txt", "webm", "mp4", "3gp", "mov", "avi", "wmv", "flv", "dwg", "dxf", "3ds", "ai", "psd", "xml"],
            50 => ["doc", "docx", "vsd", "vsdx", "pdf"],
            75 => ["xls", "xlsx"],
            100=> ["ppt", "pptx"],
        ];

        $maxFileSizeMB = 0;
        foreach($availableFiles as $k=>$v){
            if(in_array($ext, $v)) $maxFileSizeMB = $k;
        }

        if($maxFileSizeMB == 0) return false;

        $maxFileSize = $maxFileSizeMB * 1048576;
        return $size < $maxFileSize;
    }

    public function checkInvoice($file) {

        try {
            $xml = simplexml_load_string($file, 'SimpleXMLElement', LIBXML_NOCDATA);
            $ns = $xml->getNamespaces(true);
            $xml->registerXPathNamespace('c', $ns['cfdi']);
            $xml->registerXPathNamespace('t', $ns['tfd']);
        } catch (\Throwable $th) {
            return $this->responseController->makeResponse(
                true,
                "ERR_INVOICE_COMPARE006: Ocurrió un error al obtener la información del documento.",
                $th->getMessage(),
                500
            );
        }
        $arrInfoInvoice = ((array) $xml)['@attributes'];
        if (
            array_key_exists('Version', $arrInfoInvoice) &&
            array_key_exists('Serie', $arrInfoInvoice) &&
            array_key_exists('Folio', $arrInfoInvoice) &&
            array_key_exists('TipoDeComprobante', $arrInfoInvoice) &&
            array_key_exists('NoCertificado', $arrInfoInvoice) &&
            array_key_exists('Certificado', $arrInfoInvoice) &&
            array_key_exists('Sello', $arrInfoInvoice) &&
            array_key_exists('FormaPago', $arrInfoInvoice) &&
            array_key_exists('MetodoPago', $arrInfoInvoice) &&
            array_key_exists('SubTotal', $arrInfoInvoice) &&
            array_key_exists('Moneda', $arrInfoInvoice) &&
            array_key_exists('TipoCambio', $arrInfoInvoice) &&
            array_key_exists('Total', $arrInfoInvoice) &&
            array_key_exists('LugarExpedicion', $arrInfoInvoice) &&
            array_key_exists('CondicionesDePago', $arrInfoInvoice) &&
            array_key_exists('Fecha', $arrInfoInvoice) &&
            array_key_exists('Exportacion', $arrInfoInvoice)
        ) {
            return true;
        }
        return false;
    }

    public function now(){
        $completeDate = shell_exec('echo %date%');
        $completeDate = trim($completeDate);
        
        $serverDateTime = "";
        if(strlen($completeDate) == 14){
            $serverDateTime = shell_exec('echo %date:~10,4%-%date:~4,2%-%date:~7,2% %time:~0,2%:%time:~3,2%:%time:~6,2%');
            $serverDateTime = trim($serverDateTime);
        }else{
            $serverDateTime = shell_exec('echo %date:~6,4%-%date:~3,2%-%date:~0,2% %time:~0,2%:%time:~3,2%:%time:~6,2%');
            $serverDateTime = trim($serverDateTime);
        }

        return new Carbon($serverDateTime);
    }

    public function validDate($date){
        if(preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/",$date)){
            return true;
        }else{
            return false;
        }
    }

    public function floatAdd(...$numbers) : float{
        $result = "0.0";
        foreach($numbers as $n){
            $result = bcadd("$result", "$n", 18);
        }
        return floatval($result);
    }

    public function floatSub($fn, $sn) : float{
        $result = bcsub("$fn", "$sn", 18);
        return floatval($result);
    }

    public function floatDiv($fn, $sn) : float{
        $result = bcdiv("$fn", "$sn", 18);
        return floatval($result);
    }

    public function floatMul($n1, $n2) : float {
        $result = bcmul("$n1", "$n2", 18);
        return floatval($result);
    }

    public function formatDateTime(string $dateTime) : string {
        if(str_contains($dateTime, '0001-01-01')){
            return "-";
        }

        $MONTHS = ["01" => "Enero", "02" => "Febrero", "03" => "Marzo", "04" => "Abril", "05" => "Mayo", "06" => "Junio", "07" => "Julio", 
        "08" => "Agosto", "09" => "Septiembre", "10" => "Octubre", "11" => "Noviembre", "12" => "Diciembre"];
        $dateTimeArr = explode(" ", $dateTime);
        $dateArr = explode("-", $dateTimeArr[0]);
        $month = $MONTHS[$dateArr[1]];
        $day = intval($dateArr[2]);

        $dateTimeStr = $day . " de " . $month . " del " . $dateArr[0];
        $timeArr = explode(":", $dateTimeArr[1]);
        $hour = intval($timeArr[0]);
        $period = $hour < 12 ? 'AM' : 'PM';
        $hour = $hour > 12 ? $hour - 12 : $hour;

        $dateTimeStr .= " a las " . $hour . ":" . $timeArr[1] . " " . $period;
        return $dateTimeStr;
    }

    public function buildHumanCurrentDate(string $dateTime) : string {
        $DAYS = ["Mo" => "Lunes", "Tu" => "Martes", "We" => "Miércoles", "Th" => "Jueves", 
        "Fr" => "Viernes", "Sa" => "Sábado", "Su" => "Domingo"];
        $MONTHS = ["01" => "Enero", "02" => "Febrero", "03" => "Marzo", "04" => "Abril", "05" => "Mayo", "06" => "Junio", "07" => "Julio", 
        "08" => "Agosto", "09" => "Septiembre", "10" => "Octubre", "11" => "Noviembre", "12" => "Diciembre"];
        
        $dateTimeArr = explode(" ", $dateTime);
        $dateArr = explode("-", $dateTimeArr[0]);
        $dateObj = new Carbon($dateTime);
        $dayName = $dateObj->format('l');
        $dayInd = substr($dayName, 0, 2);
        
        return $DAYS[$dayInd] . ", " . $dateArr[2] . " de " . $MONTHS[$dateArr[1]] . " del " . $dateArr[0];
    }

    public function buildProjectDate($dateStr): string {
        $MONTHS = ["01" => "enero", "02" => "febrero", "03" => "marzo", "04" => "abril", "05" => "mayo", "06" => "junio", "07" => "julio", 
        "08" => "agosto", "09" => "septiembre", "10" => "octubre", "11" => "noviembre", "12" => "diciembre"];

        $dateObj = new Carbon($dateStr);
        $dateFormatted = $dateObj->toDateTimeString();
        $dateTimeArr = explode(" ", $dateFormatted);

        $dateArr = explode('-', $dateTimeArr[0]);
        $monthName = $MONTHS[$dateArr[1]];

        $timeArr = explode(':', $dateTimeArr[1]);
        $hour = intval($timeArr[0]);
        $period = $hour < 12 ? 'a. m.' : 'p. m.';
        $hour = $hour > 12 ? $hour - 12 : $hour;
        $hourStr = $hour < 10 ? "0$hour" : "$hour";
        
        return "$dateArr[2] de $monthName $dateArr[0] $hourStr:$timeArr[1] $period";
    }

    public function getApiURI(): string {
      return "http://git.ittec.mx/";
    }

    public function validPhoneNumber(string $number) : bool {
        if(intval($number) <= 0) return false;

        $validChars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
        $numberArr = str_split($number);
        $validNumber = '';

        foreach($numberArr as $char){
            if(in_array($char, $validChars)) $validNumber .= $char;
        }

        if(strlen($validNumber) >= 10 && strlen($validNumber) <= 11){
            return true;
        }else{
            return false;
        }
    }

    public function unaccent(string $value): string{
        $transliteration = array(
        'Ĳ' => 'I', 'Ö' => 'O','Œ' => 'O','Ü' => 'U','ä' => 'a','æ' => 'a',
        'ĳ' => 'i','ö' => 'o','œ' => 'o','ü' => 'u','ß' => 's','ſ' => 's',
        'À' => 'A','Á' => 'A','Â' => 'A','Ã' => 'A','Ä' => 'A','Å' => 'A',
        'Æ' => 'A','Ā' => 'A','Ą' => 'A','Ă' => 'A','Ç' => 'C','Ć' => 'C',
        'Č' => 'C','Ĉ' => 'C','Ċ' => 'C','Ď' => 'D','Đ' => 'D','È' => 'E',
        'É' => 'E','Ê' => 'E','Ë' => 'E','Ē' => 'E','Ę' => 'E','Ě' => 'E',
        'Ĕ' => 'E','Ė' => 'E','Ĝ' => 'G','Ğ' => 'G','Ġ' => 'G','Ģ' => 'G',
        'Ĥ' => 'H','Ħ' => 'H','Ì' => 'I','Í' => 'I','Î' => 'I','Ï' => 'I',
        'Ī' => 'I','Ĩ' => 'I','Ĭ' => 'I','Į' => 'I','İ' => 'I','Ĵ' => 'J',
        'Ķ' => 'K','Ľ' => 'K','Ĺ' => 'K','Ļ' => 'K','Ŀ' => 'K','Ł' => 'L',
        'Ñ' => 'N','Ń' => 'N','Ň' => 'N','Ņ' => 'N','Ŋ' => 'N','Ò' => 'O',
        'Ó' => 'O','Ô' => 'O','Õ' => 'O','Ø' => 'O','Ō' => 'O','Ő' => 'O',
        'Ŏ' => 'O','Ŕ' => 'R','Ř' => 'R','Ŗ' => 'R','Ś' => 'S','Ş' => 'S',
        'Ŝ' => 'S','Ș' => 'S','Š' => 'S','Ť' => 'T','Ţ' => 'T','Ŧ' => 'T',
        'Ț' => 'T','Ù' => 'U','Ú' => 'U','Û' => 'U','Ū' => 'U','Ů' => 'U',
        'Ű' => 'U','Ŭ' => 'U','Ũ' => 'U','Ų' => 'U','Ŵ' => 'W','Ŷ' => 'Y',
        'Ÿ' => 'Y','Ý' => 'Y','Ź' => 'Z','Ż' => 'Z','Ž' => 'Z','à' => 'a',
        'á' => 'a','â' => 'a','ã' => 'a','ā' => 'a','ą' => 'a','ă' => 'a',
        'å' => 'a','ç' => 'c','ć' => 'c','č' => 'c','ĉ' => 'c','ċ' => 'c',
        'ď' => 'd','đ' => 'd','è' => 'e','é' => 'e','ê' => 'e','ë' => 'e',
        'ē' => 'e','ę' => 'e','ě' => 'e','ĕ' => 'e','ė' => 'e','ƒ' => 'f',
        'ĝ' => 'g','ğ' => 'g','ġ' => 'g','ģ' => 'g','ĥ' => 'h','ħ' => 'h',
        'ì' => 'i','í' => 'i','î' => 'i','ï' => 'i','ī' => 'i','ĩ' => 'i',
        'ĭ' => 'i','į' => 'i','ı' => 'i','ĵ' => 'j','ķ' => 'k','ĸ' => 'k',
        'ł' => 'l','ľ' => 'l','ĺ' => 'l','ļ' => 'l','ŀ' => 'l','ñ' => 'n',
        'ń' => 'n','ň' => 'n','ņ' => 'n','ŉ' => 'n','ŋ' => 'n','ò' => 'o',
        'ó' => 'o','ô' => 'o','õ' => 'o','ø' => 'o','ō' => 'o','ő' => 'o',
        'ŏ' => 'o','ŕ' => 'r','ř' => 'r','ŗ' => 'r','ś' => 's','š' => 's',
        'ť' => 't','ù' => 'u','ú' => 'u','û' => 'u','ū' => 'u','ů' => 'u',
        'ű' => 'u','ŭ' => 'u','ũ' => 'u','ų' => 'u','ŵ' => 'w','ÿ' => 'y',
        'ý' => 'y','ŷ' => 'y','ż' => 'z','ź' => 'z','ž' => 'z','Α' => 'A',
        'Ά' => 'A','Ἀ' => 'A','Ἁ' => 'A','Ἂ' => 'A','Ἃ' => 'A','Ἄ' => 'A',
        'Ἅ' => 'A','Ἆ' => 'A','Ἇ' => 'A','ᾈ' => 'A','ᾉ' => 'A','ᾊ' => 'A',
        'ᾋ' => 'A','ᾌ' => 'A','ᾍ' => 'A','ᾎ' => 'A','ᾏ' => 'A','Ᾰ' => 'A',
        'Ᾱ' => 'A','Ὰ' => 'A','ᾼ' => 'A','Β' => 'B','Γ' => 'G','Δ' => 'D',
        'Ε' => 'E','Έ' => 'E','Ἐ' => 'E','Ἑ' => 'E','Ἒ' => 'E','Ἓ' => 'E',
        'Ἔ' => 'E','Ἕ' => 'E','Ὲ' => 'E','Ζ' => 'Z','Η' => 'I','Ή' => 'I',
        'Ἠ' => 'I','Ἡ' => 'I','Ἢ' => 'I','Ἣ' => 'I','Ἤ' => 'I','Ἥ' => 'I',
        'Ἦ' => 'I','Ἧ' => 'I','ᾘ' => 'I','ᾙ' => 'I','ᾚ' => 'I','ᾛ' => 'I',
        'ᾜ' => 'I','ᾝ' => 'I','ᾞ' => 'I','ᾟ' => 'I','Ὴ' => 'I','ῌ' => 'I',
        'Θ' => 'T','Ι' => 'I','Ί' => 'I','Ϊ' => 'I','Ἰ' => 'I','Ἱ' => 'I',
        'Ἲ' => 'I','Ἳ' => 'I','Ἴ' => 'I','Ἵ' => 'I','Ἶ' => 'I','Ἷ' => 'I',
        'Ῐ' => 'I','Ῑ' => 'I','Ὶ' => 'I','Κ' => 'K','Λ' => 'L','Μ' => 'M',
        'Ν' => 'N','Ξ' => 'K','Ο' => 'O','Ό' => 'O','Ὀ' => 'O','Ὁ' => 'O',
        'Ὂ' => 'O','Ὃ' => 'O','Ὄ' => 'O','Ὅ' => 'O','Ὸ' => 'O','Π' => 'P',
        'Ρ' => 'R','Ῥ' => 'R','Σ' => 'S','Τ' => 'T','Υ' => 'Y','Ύ' => 'Y',
        'Ϋ' => 'Y','Ὑ' => 'Y','Ὓ' => 'Y','Ὕ' => 'Y','Ὗ' => 'Y','Ῠ' => 'Y',
        'Ῡ' => 'Y','Ὺ' => 'Y','Φ' => 'F','Χ' => 'X','Ψ' => 'P','Ω' => 'O',
        'Ώ' => 'O','Ὠ' => 'O','Ὡ' => 'O','Ὢ' => 'O','Ὣ' => 'O','Ὤ' => 'O',
        'Ὥ' => 'O','Ὦ' => 'O','Ὧ' => 'O','ᾨ' => 'O','ᾩ' => 'O','ᾪ' => 'O',
        'ᾫ' => 'O','ᾬ' => 'O','ᾭ' => 'O','ᾮ' => 'O','ᾯ' => 'O','Ὼ' => 'O',
        'ῼ' => 'O','α' => 'a','ά' => 'a','ἀ' => 'a','ἁ' => 'a','ἂ' => 'a',
        'ἃ' => 'a','ἄ' => 'a','ἅ' => 'a','ἆ' => 'a','ἇ' => 'a','ᾀ' => 'a',
        'ᾁ' => 'a','ᾂ' => 'a','ᾃ' => 'a','ᾄ' => 'a','ᾅ' => 'a','ᾆ' => 'a',
        'ᾇ' => 'a','ὰ' => 'a','ᾰ' => 'a','ᾱ' => 'a','ᾲ' => 'a','ᾳ' => 'a',
        'ᾴ' => 'a','ᾶ' => 'a','ᾷ' => 'a','β' => 'b','γ' => 'g','δ' => 'd',
        'ε' => 'e','έ' => 'e','ἐ' => 'e','ἑ' => 'e','ἒ' => 'e','ἓ' => 'e',
        'ἔ' => 'e','ἕ' => 'e','ὲ' => 'e','ζ' => 'z','η' => 'i','ή' => 'i',
        'ἠ' => 'i','ἡ' => 'i','ἢ' => 'i','ἣ' => 'i','ἤ' => 'i','ἥ' => 'i',
        'ἦ' => 'i','ἧ' => 'i','ᾐ' => 'i','ᾑ' => 'i','ᾒ' => 'i','ᾓ' => 'i',
        'ᾔ' => 'i','ᾕ' => 'i','ᾖ' => 'i','ᾗ' => 'i','ὴ' => 'i','ῂ' => 'i',
        'ῃ' => 'i','ῄ' => 'i','ῆ' => 'i','ῇ' => 'i','θ' => 't','ι' => 'i',
        'ί' => 'i','ϊ' => 'i','ΐ' => 'i','ἰ' => 'i','ἱ' => 'i','ἲ' => 'i',
        'ἳ' => 'i','ἴ' => 'i','ἵ' => 'i','ἶ' => 'i','ἷ' => 'i','ὶ' => 'i',
        'ῐ' => 'i','ῑ' => 'i','ῒ' => 'i','ῖ' => 'i','ῗ' => 'i','κ' => 'k',
        'λ' => 'l','μ' => 'm','ν' => 'n','ξ' => 'k','ο' => 'o','ό' => 'o',
        'ὀ' => 'o','ὁ' => 'o','ὂ' => 'o','ὃ' => 'o','ὄ' => 'o','ὅ' => 'o',
        'ὸ' => 'o','π' => 'p','ρ' => 'r','ῤ' => 'r','ῥ' => 'r','σ' => 's',
        'ς' => 's','τ' => 't','υ' => 'y','ύ' => 'y','ϋ' => 'y','ΰ' => 'y',
        'ὐ' => 'y','ὑ' => 'y','ὒ' => 'y','ὓ' => 'y','ὔ' => 'y','ὕ' => 'y',
        'ὖ' => 'y','ὗ' => 'y','ὺ' => 'y','ῠ' => 'y','ῡ' => 'y','ῢ' => 'y',
        'ῦ' => 'y','ῧ' => 'y','φ' => 'f','χ' => 'x','ψ' => 'p','ω' => 'o',
        'ώ' => 'o','ὠ' => 'o','ὡ' => 'o','ὢ' => 'o','ὣ' => 'o','ὤ' => 'o',
        'ὥ' => 'o','ὦ' => 'o','ὧ' => 'o','ᾠ' => 'o','ᾡ' => 'o','ᾢ' => 'o',
        'ᾣ' => 'o','ᾤ' => 'o','ᾥ' => 'o','ᾦ' => 'o','ᾧ' => 'o','ὼ' => 'o',
        'ῲ' => 'o','ῳ' => 'o','ῴ' => 'o','ῶ' => 'o','ῷ' => 'o','А' => 'A',
        'Б' => 'B','В' => 'V','Г' => 'G','Д' => 'D','Е' => 'E','Ё' => 'E',
        'Ж' => 'Z','З' => 'Z','И' => 'I','Й' => 'I','К' => 'K','Л' => 'L',
        'М' => 'M','Н' => 'N','О' => 'O','П' => 'P','Р' => 'R','С' => 'S',
        'Т' => 'T','У' => 'U','Ф' => 'F','Х' => 'K','Ц' => 'T','Ч' => 'C',
        'Ш' => 'S','Щ' => 'S','Ы' => 'Y','Э' => 'E','Ю' => 'Y','Я' => 'Y',
        'а' => 'A','б' => 'B','в' => 'V','г' => 'G','д' => 'D','е' => 'E',
        'ё' => 'E','ж' => 'Z','з' => 'Z','и' => 'I','й' => 'I','к' => 'K',
        'л' => 'L','м' => 'M','н' => 'N','о' => 'O','п' => 'P','р' => 'R',
        'с' => 'S','т' => 'T','у' => 'U','ф' => 'F','х' => 'K','ц' => 'T',
        'ч' => 'C','ш' => 'S','щ' => 'S','ы' => 'Y','э' => 'E','ю' => 'Y',
        'я' => 'Y','ð' => 'd','Ð' => 'D','þ' => 't','Þ' => 'T','ა' => 'a',
        'ბ' => 'b','გ' => 'g','დ' => 'd','ე' => 'e','ვ' => 'v','ზ' => 'z',
        'თ' => 't','ი' => 'i','კ' => 'k','ლ' => 'l','მ' => 'm','ნ' => 'n',
        'ო' => 'o','პ' => 'p','ჟ' => 'z','რ' => 'r','ს' => 's','ტ' => 't',
        'უ' => 'u','ფ' => 'p','ქ' => 'k','ღ' => 'g','ყ' => 'q','შ' => 's',
        'ჩ' => 'c','ც' => 't','ძ' => 'd','წ' => 't','ჭ' => 'c','ხ' => 'k',
        'ჯ' => 'j','ჰ' => 'h' 
        );
        $str = str_replace( array_keys( $transliteration ),  array_values( $transliteration ), $value);
        return $str;
    }
}