<?php
/*
Generated by OutputBooks Team
*/

defined("\x42\x41\x53\x45\120\x41\x54\110") or exit("\116\157\40\144\151\162\145\x63\164\40\x73\143\x72\151\x70\164\40\x61\143\143\145\163\x73\x20\x61\x6c\154\x6f\x77\145\144");
class GridParser
{
    protected $patterns = array();
    protected $isExactMatch = true;
    protected $spreadsheet = null;
    protected $extension = '';
    protected $parsedData = array("\x6c\151\163\164\x49\164\145\155\163" => array(), "\x78\x6c\x73\x48\x65\141\x64\x65\162" => array());
    public $error = '';
    public function getDelimiter($file = '')
    {
        goto zUMHg;
        DVfi0:
        arsort($res);
        goto GpQ9X;
        GpQ9X:
        reset($res);
        goto Ml5Mz;
        zUMHg:
        $delimiters = ["\x73\145\x6d\x69\143\x6f\x6c\157\x6e" => "\73", "\164\141\142" => "\11", "\x63\x6f\155\155\x61" => "\54", "\160\151\x70\x65" => "\174"];
        goto kcoOY;
        kcoOY:
        $csv = file_get_contents($file);
        goto pceOq;
        pceOq:
        foreach ($delimiters as $key => $delim) {
            $res[$key] = substr_count($csv, $delim);
            IDS3S:
        }
        goto YWFuX;
        Ml5Mz:
        return $delimiters[key($res)];
        goto KzyrD;
        YWFuX:
        a3Xmj:
        goto DVfi0;
        KzyrD:
    }
    public function parse($filepath = '', $param = array())
    {
        goto Ml1E5;
        Ml1E5:
        $this->extension = strtolower(pathinfo($filepath, PATHINFO_EXTENSION));
        goto XL7re;
        iosLG:
        $this->preparePatterns($param);
        goto pSuCT;
        P_REA:
        if (!in_array($this->extension, ["\x63\x73\x76", "\x74\x73\166"]) && mime_content_type($filepath) == "\x74\x65\x78\164\57\160\154\x61\151\x6e") {
            goto SHsa9;
            NR7kO:
            if (isset($extMap[$delim])) {
                goto ukfvh;
                Zqro7:
                $filepath .= "\x2e" . $extMap[$delim];
                goto cbHkq;
                cbHkq:
                $this->extension = $extMap[$delim];
                goto Ifhzq;
                ukfvh:
                copy($filepath, $filepath . "\x2e" . $extMap[$delim]);
                goto Zqro7;
                Ifhzq:
            }
            goto N3CF1;
            WKcFq:
            $extMap = ["\x9" => "\164\x73\166", "\54" => "\x63\x73\166"];
            goto NR7kO;
            SHsa9:
            $delim = $this->getDelimiter($filepath);
            goto WKcFq;
            N3CF1:
        }
        goto af52v;
        af52v:
        $this->spreadsheet = new SpreadsheetReader($filepath, false, false, ["\x42\165\151\x6c\x74\x69\x6e\x46\x6f\162\x6d\141\x74\163" => [14 => "\144\x64\x2d\155\155\55\x79\x79\171\x79", 22 => "\x64\57\155\57\171\171\x20\150\x3a\x6d\155"]]);
        goto iosLG;
        UXllj:
        require_once APPPATH . "\x74\x68\x69\x72\x64\137\160\141\x72\164\x79\x2f\163\x70\x72\x65\141\x64\163\x68\x65\x65\164\55\162\145\141\x64\x65\162\57\160\x68\160\x2d\145\170\143\145\154\55\x72\145\x61\x64\145\x72\57\145\x78\143\x65\154\x5f\162\145\141\x64\145\x72\x32\56\160\150\x70";
        goto CNO9j;
        P7JvL:
        date_default_timezone_set("\125\x54\103");
        goto P_REA;
        pSuCT:
        return $this->extractData($param);
        goto nQ1IR;
        CNO9j:
        require_once APPPATH . "\x74\x68\x69\162\x64\137\x70\141\x72\164\171\57\163\x70\162\x65\x61\x64\x73\x68\x65\145\164\55\162\x65\x61\144\x65\x72\x2f\123\x70\x72\x65\141\144\x73\150\145\145\164\x52\x65\141\144\x65\162\56\x70\150\x70";
        goto P7JvL;
        XL7re:
        if (in_array($this->extension, ["\x70\144\146", "\x6a\x70\x67", "\160\156\x67"])) {
            goto Y2KCr;
            KhdNw:
            if ($file === false) {
                die("\125\x6e\x61\142\154\145\40\x74\157\x20\157\160\x65\156\40\x6f\x72\x20\x63\162\x65\x61\x74\145\40\164\150\145\x20\146\151\154\145\x2e");
            }
            goto fvRD8;
            Egm8I:
            HU3xP:
            goto kC0jQ;
            Y2KCr:
            $retData = $this->handleCurlUpload($filepath);
            goto ew3ak;
            kC0jQ:
            fclose($file);
            goto DAikb;
            ew3ak:
            if (empty($retData) || empty($retData["\x6f\x62\137\153\x65\171\163"]) || empty($retData["\157\x62\x5f\x76\141\x6c\x75\145\x73"])) {
                $this->error = "\x43\x61\156\x27\164\x20\x70\x61\162\x73\x65\x20\x70\144\x66\x2e";
                return false;
            }
            goto bS70e;
            iSjiF:
            foreach ($retData["\x6f\x62\137\x76\x61\154\165\145\163"] as $row) {
                fputcsv($file, $row);
                k10C2:
            }
            goto Egm8I;
            TyzvA:
            $file = fopen($filepath, "\167");
            goto KhdNw;
            bS70e:
            $filepath = $filepath . "\56\143\163\166";
            goto TyzvA;
            fvRD8:
            fputcsv($file, $retData["\x6f\142\x5f\x6b\x65\x79\163"]);
            goto iSjiF;
            DAikb:
        }
        goto UXllj;
        nQ1IR:
    }
    protected function handleCurlUpload($filepath)
    {
        goto LEwdd;
        LQOfw:
        $curl = curl_init();
        goto A83Qj;
        chZkt:
        $response = curl_exec($curl);
        goto ypaFs;
        LEwdd:
        $ci =& get_instance();
        goto eaBmK;
        A83Qj:
        curl_setopt_array($curl, [CURLOPT_URL => $pdfparse_url, CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_POSTFIELDS => ["\x66\151\154\x65" => new CURLFile($filepath)]]);
        goto chZkt;
        HTqEB:
        if (empty($pdfparse_url)) {
            $pdfparse_url = "\x68\164\164\160\72\57\x2f\61\62\67\56\x30\56\60\56\61\x3a\x35\x30\x30\x30\x2f\145\x78\164\162\141\143\164\x5f\x64\x61\164\x61";
        }
        goto LQOfw;
        Cwz7k:
        return json_decode($response, true);
        goto lziir;
        ypaFs:
        curl_close($curl);
        goto qJ5Ws;
        eaBmK:
        $pdfparse_url = $ci->config->item("\160\x64\146\160\141\x72\x73\145\137\165\x72\x6c");
        goto HTqEB;
        qJ5Ws:
        if (curl_errno($curl)) {
            throw new Exception("\103\165\x72\154\40\x65\x72\x72\x6f\x72\x3a\40" . curl_error($curl));
        }
        goto Cwz7k;
        lziir:
    }
    protected function preparePatterns($param)
    {
        foreach ($param as $key => $val) {
            goto Kkyii;
            Kkyii:
            if (!is_array($val)) {
                $val = preg_split("\x2f\50\x2c\174\73\51\57", $val);
            }
            goto CkWLg;
            jXrb9:
            $val = str_replace("\x2f", "\x5c\x2f", $val);
            goto lVXph;
            pWqNy:
            d8NLk:
            goto OsNo3;
            lVXph:
            $this->patterns[$key] = "\x2f\x5e\x28" . implode("\x7c", $val) . "\51" . ($this->isExactMatch ? "\44" : '') . "\57\151";
            goto pWqNy;
            CkWLg:
            $val = array_map("\164\162\x69\155", $val);
            goto jXrb9;
            OsNo3:
        }
        VwNZi:
    }
    protected function extractData($param)
    {
        goto uYzss;
        C5c0U:
        $sMonth = ['', "\152\141\x6e", "\146\x65\142", "\x6d\141\x72", "\141\160\162", "\155\141\x79", "\152\x75\156", "\x6a\165\x6c", "\141\x75\147", "\x73\145\160", "\157\143\164", "\x6e\157\x76", "\x64\x65\143"];
        goto t1PIr;
        uYzss:
        $indexes = [];
        goto J_9DJ;
        J_9DJ:
        $isDataDetected = false;
        goto C5c0U;
        ofDj6:
        thntP:
        goto Kuclx;
        uAUo9:
        foreach ($this->spreadsheet as $row) {
            goto Bmwrq;
            CyDeb:
            $this->parsedData["\170\154\163\110\x65\x61\144\145\x72"] = $row;
            goto D4e4x;
            zU7YK:
            foreach ($this->patterns as $key => $pattern) {
                goto NkItc;
                NkItc:
                $matched = preg_grep($pattern, $row);
                goto Qjz_4;
                Wp1iN:
                AxpKm:
                goto mXx6K;
                Qjz_4:
                if (!empty($matched)) {
                    $indexes[$key] = array_keys($matched);
                    $identified++;
                }
                goto Wp1iN;
                mXx6K:
            }
            goto yDCBD;
            D4e4x:
            if ($identified >= 3) {
                $isDataDetected = true;
            } else {
                goto thntP;
            }
            goto ENl9w;
            mZkci:
            if ($this->extension == "\143\x73\166" && !empty($row[0]) && (!is_array($row) || count($row) == 1)) {
                $row = str_getcsv($row[0]);
            }
            goto EGgFP;
            ttQJV:
            $row = array_map(function ($val) {
                $val = mb_convert_encoding(trim($val), "\x55\124\x46\x2d\70", "\x55\124\106\x2d\70");
                return $val;
            }, $row);
            goto XJlJ9;
            Bmwrq:
            $cellsInfo = $this->spreadsheet->getCellsInfo();
            goto mZkci;
            ENl9w:
            NrNgF:
            goto m8CGj;
            EGgFP:
            if ($isDataDetected) {
                goto ofUms;
                I4xg1:
                goto NrNgF;
                goto haiAM;
                ofUms:
                $rowData = $this->mapRowData($row, $indexes, $param, $cellsInfo, $sMonth, $lMonth);
                goto jlzSP;
                jlzSP:
                if (!empty($rowData)) {
                    $this->parsedData["\154\151\163\x74\111\x74\145\x6d\163"][] = $rowData;
                }
                goto I4xg1;
                haiAM:
            }
            goto ttQJV;
            yDCBD:
            HSMjz:
            goto CyDeb;
            XJlJ9:
            $identified = 0;
            goto zU7YK;
            m8CGj:
        }
        goto ofDj6;
        Kuclx:
        return $this->parsedData;
        goto cfYEx;
        t1PIr:
        $lMonth = ['', "\x6a\141\156\165\141\162\171", "\146\145\x62\162\165\141\162\171", "\155\x61\162\143\150", "\x61\x70\162\151\154", "\x6d\x61\171", "\152\x75\156\145", "\152\x75\154\x79", "\141\x75\x67\165\163\x74", "\x73\x65\160\164\145\x6d\x62\145\162", "\157\x63\x74\157\142\x65\x72", "\156\157\166\145\x6d\142\x65\x72", "\x64\145\143\x65\155\142\x65\x72"];
        goto uAUo9;
        cfYEx:
    }
    protected function mapRowData($row, $indexes, $param, $cellsInfo, $sMonth, $lMonth)
    {
        goto SLaht;
        xLVok:
        b7OgF:
        goto jvkZr;
        IhY6y:
        foreach ($indexes as $key => $val) {
            goto E1QAy;
            JW8Ma:
            if (empty($row[$index])) {
                $emptyCount++;
                goto k0vlU;
            }
            goto Xlf_R;
            adGMS:
            k0vlU:
            goto vzqnd;
            lTY1f:
            switch ($key) {
                case "\x6d\146\147\x44\141\164\145":
                case "\145\170\x70\x44\141\x74\x65":
                    goto PFdqK;
                    tHHy9:
                    $value = str_ireplace($sMonth, range(1, 12), $value);
                    goto os7Rg;
                    rRV1P:
                    goto UO2KS;
                    goto Dx3vV;
                    mN1VR:
                    if (is_numeric($date)) {
                        $date = gmdate("\155\57\x64\x2f\131", ($date - 25569) * 86400);
                    }
                    goto QIJBd;
                    os7Rg:
                    $date = preg_replace("\x2f\x28\x5c\144\x2b\x29\x5b\x5c\57\x5c\55\54\x5c\x73\135\x28\134\144\x2b\x29\x5b\x5c\57\134\x2d\54\x5c\163\x5d\50\134\x64\x2b\x29\57", "\44\62\x2f\x24\x31\x2f\x24\x33", $value);
                    goto mN1VR;
                    O5h18:
                    if (strlen($dateParts[2]) == 2) {
                        $dateParts[2] = "\x32\x30" . $dateParts[2];
                    }
                    goto EFd86;
                    EFd86:
                    $rowData[$key] = implode("\x2d", array_reverse($dateParts));
                    goto rRV1P;
                    QIJBd:
                    $dateParts = explode("\57", $date);
                    goto O5h18;
                    PFdqK:
                    $value = str_ireplace($lMonth, range(1, 12), strtolower($value));
                    goto tHHy9;
                    Dx3vV:
                case "\161\164\x79":
                case "\x72\141\164\145":
                case "\x64\151\163\143\157\x75\156\x74":
                case "\x74\141\x78\141\142\154\145\x41\155\x6f\165\x6e\164":
                    $rowData[$key] = (double) str_replace("\x2c", '', $value);
                    goto UO2KS;
                default:
                    $rowData[$key] = $value;
                    goto UO2KS;
            }
            goto iFoVy;
            E1QAy:
            $index = $val[0];
            goto JW8Ma;
            iFoVy:
            vVgPD:
            goto Cqqbc;
            Cqqbc:
            UO2KS:
            goto adGMS;
            Xlf_R:
            $value = preg_replace("\x2f\x5c\163\53\57", "\x20", trim($row[$index]));
            goto lTY1f;
            vzqnd:
        }
        goto xLVok;
        jvkZr:
        return $emptyCount < count($indexes) ? $rowData : [];
        goto ZwpzZ;
        s_Eqg:
        $emptyCount = 0;
        goto IhY6y;
        SLaht:
        $rowData = [];
        goto s_Eqg;
        ZwpzZ:
    }
}
