<?php
$GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"] ?: array()) + array("_5159b3572969eca46" . "acd1b2e1418459c" => base64_decode("aW1wbG9kZ" . "Q=="), "_03476a12ff01e" . "917c40934a774c" . "214e1" => base64_decode("CgkJCVNFTEVDVCBkLioKCQkJRlJPTSBFUk1TX2RhdGEgZAoJCQlXSEVSRQoJCQkJZC5pZCA9IGQucHJpbWFyeV92ZXJzaW9uX2lkCgkJCUFORCBkLmRlbGV0ZWQgPSBpbnQ6ZGVsZXRlZAoJCQlBTkQgZC5kYXRlX2xhc3RfbW9kaWZpZWQgPiBpbnQ6ZGF0ZV9sYXN0X21vZGlmaWVkC" . "gkJCUFORCBkLmRvY190eXBlID0gaW50OmRvY190eXBlCgkJCUFORCAoTE9XRVIoZC50aXRsZSkgTElLRSAnJS5qcGcnCgkJCQlPUiBMT1dFUihkLnRpdGxlKSBMSUtFICclLmpwZWcnCgkJCQlPUiBMT1dFUihkLnRpdGxlKSBMSUtFICclLnRpZmYnKQ=="), "_6e38cb9e043a07c" . "d69a1711a6704c62" . "a" => base64_decode("cGFyZW5" . "0X2lk"), "_1b3c842857887ee3f414016f277" . "666b0" => base64_decode("bG9uZ2l" . "0dWRl"), "i" . "d" => base64_decode("aW" . "Q="), "_33eda2072a2dedc3f617356ac598a6" . "32" => base64_decode("Y2ZnX2RvY3NfZ2VvX3RhZ2dpbmdfbGF0aXR1ZG" . "Vfa2V5"), "_549205b" . "c2a2067b" . "f83af2df" . "95b1cd2c" . "f" => base64_decode("aHR0cHM6Ly9t" . "YXBzLmdvb2ds" . "ZS5jby51ay9t" . "YXBzP3E9"), "_6565b632ef932c09b17243a4ada" . "2bfab" => base64_decode("ZGF0ZV9s" . "YXN0X21v" . "ZGlmaWVk"), "_1ac5cc48c34c5362e9" . "4d8667cc7b0ddc" => base64_decode("LA=" . "="), "_4b43208a" . "06070ee32" . "2599b3bb9" . "88db75" => base64_decode("ZGVsZX" . "RlZA=="), "_bd71c3b5c201fc11db82ed14ce424de" . "5" => base64_decode("aW5fY" . "XJyYX" . "k="), "_83d95ab6" . "1a12263c6" . "df1f5c4e0" . "722f5e" => base64_decode("Y2ZnX2RvY3NfZ2VvX3RhZ" . "2dpbmdfZ29vZ2xlX2xpbm" . "tfa2V5"), "_67c1cf597" . "04004889c3" . "c1eebbb763" . "302" => base64_decode("ZG9jX3R5cGU" . "="), "_570be769e8" . "64777f5f801" . "bb6b56bc9a0" => base64_decode("ClNob3cgaW" . "4gR29vZ2xl"), "_88c2fcddf45348c46294e5dfaf" . "a92dac" => base64_decode("Y2ZnX2RvY3NfZ" . "2VvX3RhZ2dpbm" . "dfbG9uZ2l0dWR" . "lX2tleQ=="), "_110f2b134" . "88fd277a3d" . "3e695566e8" . "097" => base64_decode("bGF0aXR1" . "ZGU="), "_ea2c830dc2c0e3ef1" . "fb7e5afe1184eb1" => base64_decode("Y2ZnX2RvY3NfZ2VvX3R" . "hZ2dpbmdfcmVjb3JkX3" . "R5cGVfa2V5"));
use Claromentis\Documents\DocumentsApplication;









class DocsImagesExifReader extends ErrorHandler
{
    
    
    
    
    const GEO_TAGGING_RECORD_TYPE_NAME = 'exif_data';
    const GEO_TAGGING_LATITUDE = 'exif_latitude';
    const GEO_TAGGING_LONGITUDE = 'exif_longitude';
    const GEO_TAGGING_GOOGLE_LINK = 'exif_google_link';
    
    
    
    
    const DOCS_EXIF_LAST_SCAN_DATETIME = 'DOCS_EXIF_LAST_SCAN_DATETIME';
    
    
    
    
    protected $record_type_id = null;
    
    
    
    
    protected $last_check = null;
    public function __construct()
    {
        $this->FindAndSetRecordTypeId()->LoadLastCheck();
    }
    public static function Run()
    {
        $_a6dc579c9d5a1727b0a656008d6e928e = new DocsImagesExifReader();
        if (!$_a6dc579c9d5a1727b0a656008d6e928e->record_type_id) {
            return;
        }
        $_a6dc579c9d5a1727b0a656008d6e928e->UpdateLastCheck()->FindAndProcessDocuments();
    }
    protected function FindAndProcessDocuments()
    {
        global $db;
        $_d88b50ddb42db648a9c7ac08065b9409 = new Query($GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_03476a12ff0" . "1e917c40934a" . "774c214e1"]);
        $_d88b50ddb42db648a9c7ac08065b9409->Bind($GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_4b43208a06070ee322599b3bb988db" . "75"], 0);
        $_d88b50ddb42db648a9c7ac08065b9409->Bind($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_6565b632ef932c09b17243a4ada" . "2bfab"], $this->last_check);
        $_d88b50ddb42db648a9c7ac08065b9409->Bind($GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_67c1cf597040048" . "89c3c1eebbb76330" . "2"], DOC_TYPE_STANDARD);
        $_b4af1f7aa1ccde1a449e9d8afe15b753 = $db->query($_d88b50ddb42db648a9c7ac08065b9409);
        while ($_b8cfc2e06d9d1fec1893ea4a054002bf = $_b4af1f7aa1ccde1a449e9d8afe15b753->FetchArray()) {
            $_09f61d3133f39f8e5aff0eb6a7d185a1 = ERMSBrowser::I()->GetData($_b8cfc2e06d9d1fec1893ea4a054002bf[$GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["i" . "d"]], $_b8cfc2e06d9d1fec1893ea4a054002bf[$GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_6e38cb9" . "e043a07c" . "d69a1711" . "a6704c62" . "a"]]);
            if ($_09f61d3133f39f8e5aff0eb6a7d185a1->IsError()) {
                continue;
            }
            if (!$GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_bd71c3b5c201fc11db82ed14" . "ce424de5"]($this->record_type_id, $_09f61d3133f39f8e5aff0eb6a7d185a1->GetRecordTypeIDs()) && $_09f61d3133f39f8e5aff0eb6a7d185a1 instanceof ERMSRecordTypesContainer) {
                $_09f61d3133f39f8e5aff0eb6a7d185a1->AddRecordTypeId($this->record_type_id);
                $_09f61d3133f39f8e5aff0eb6a7d185a1->Save();
                if ($_09f61d3133f39f8e5aff0eb6a7d185a1->IsError()) {
                    continue;
                }
            }
            $this->ReadAndSaveExifData($_09f61d3133f39f8e5aff0eb6a7d185a1);
        }
    }
    protected function ReadAndSaveExifData($_09f61d3133f39f8e5aff0eb6a7d185a1)
    {
        $_f1de4b91c0ea54779101f16d8085bd54 = new ClaExif($_09f61d3133f39f8e5aff0eb6a7d185a1->GetPrimaryComponent()->GetContentPath());
        if ($_f1de4b91c0ea54779101f16d8085bd54->IsError()) {
            return;
        }
        $_f6dad07c07b4ad2b67749b28951702e5 = $_f1de4b91c0ea54779101f16d8085bd54->getGeoCoordinates();
        if ($_f6dad07c07b4ad2b67749b28951702e5[$GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_1b3c842857887ee3f414016f27766" . "6b0"]] && $_f6dad07c07b4ad2b67749b28951702e5[$GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_110f2b13488fd277a3d3e69" . "5566e8097"]]) {
            $_09f61d3133f39f8e5aff0eb6a7d185a1->SetRecordTypeValue($this->record_type_id, $this->GetGeoTaggingLatitudeKey(), $_f6dad07c07b4ad2b67749b28951702e5[$GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_110f2b13" . "488fd277a" . "3d3e69556" . "6e8097"]]);
            $_09f61d3133f39f8e5aff0eb6a7d185a1->SetRecordTypeValue($this->record_type_id, $this->GetGeoTaggingLongitudeKey(), $_f6dad07c07b4ad2b67749b28951702e5[$GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_1b3c84285" . "7887ee3f41" . "4016f27766" . "6b0"]]);
            $_09f61d3133f39f8e5aff0eb6a7d185a1->SetRecordTypeValue($this->record_type_id, $this->GetGeoTaggingGoogleLinkKey(), $this->GetGoogleLink($_f6dad07c07b4ad2b67749b28951702e5));
            $_09f61d3133f39f8e5aff0eb6a7d185a1->RecordTypes()->Save();
        }
    }
    protected function GetGoogleLink($_f6dad07c07b4ad2b67749b28951702e5)
    {
        $_f6dad07c07b4ad2b67749b28951702e5 = $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_5159b3572969eca46acd1b2e14" . "18459c"]($GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_1ac5cc48c34c5362e94d8667cc" . "7b0ddc"], $_f6dad07c07b4ad2b67749b28951702e5);
        return $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_549205bc2a2067bf83af2df95b1c" . "d2cf"] . $_f6dad07c07b4ad2b67749b28951702e5 . $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_570be769e864777f5f801b" . "b6b56bc9a0"];
    }
    protected function FindAndSetRecordTypeId()
    {
        $_355e5ec81ee448ec7f6354c9d865a2c6 = new ERMSRecordType();
        $_355e5ec81ee448ec7f6354c9d865a2c6->LoadByName($this->GetGeoTaggingRecordTypeKey());
        $this->record_type_id = $_355e5ec81ee448ec7f6354c9d865a2c6->GetId();
        return $this;
    }
    protected function LoadLastCheck()
    {
        if ($_6066fd2345ae19147a32b3b2cf9d79c5 = DBVar::Get(self::DOCS_EXIF_LAST_SCAN_DATETIME)) {
            $this->last_check = $_6066fd2345ae19147a32b3b2cf9d79c5;
        } else {
            $this->last_check = 0;
        }
        return $this;
    }
    protected function UpdateLastCheck()
    {
        $_d230962d9a57dc6ba2b774d9ba3bb81e = new Date();
        DBVar::Set(self::DOCS_EXIF_LAST_SCAN_DATETIME, $_d230962d9a57dc6ba2b774d9ba3bb81e->getDate());
        return $this;
    }
    protected function GetGeoTaggingRecordTypeKey()
    {
        $_b34ab5f1ac69818b996067e04caa4631 = DocumentsApplication::getConfig();
        $_ea2c830dc2c0e3ef1fb7e5afe1184eb1 = $_b34ab5f1ac69818b996067e04caa4631->Get($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_ea2c830dc2c0e3" . "ef1fb7e5afe1184" . "eb1"]);
        if (!$_ea2c830dc2c0e3ef1fb7e5afe1184eb1) {
            return self::GEO_TAGGING_RECORD_TYPE_NAME;
        }
        return $_ea2c830dc2c0e3ef1fb7e5afe1184eb1;
    }
    protected function GetGeoTaggingLatitudeKey()
    {
        $_b34ab5f1ac69818b996067e04caa4631 = DocumentsApplication::getConfig();
        $_33eda2072a2dedc3f617356ac598a632 = $_b34ab5f1ac69818b996067e04caa4631->Get($GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_33eda2072a2dedc3f61735" . "6ac598a632"]);
        if (!$_33eda2072a2dedc3f617356ac598a632) {
            return self::GEO_TAGGING_LATITUDE;
        }
        return $_33eda2072a2dedc3f617356ac598a632;
    }
    protected function GetGeoTaggingLongitudeKey()
    {
        $_b34ab5f1ac69818b996067e04caa4631 = DocumentsApplication::getConfig();
        $_88c2fcddf45348c46294e5dfafa92dac = $_b34ab5f1ac69818b996067e04caa4631->Get($GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_88c2fcddf45348c46294e5dfa" . "fa92dac"]);
        if (!$_88c2fcddf45348c46294e5dfafa92dac) {
            return self::GEO_TAGGING_LONGITUDE;
        }
        return $_88c2fcddf45348c46294e5dfafa92dac;
    }
    protected function GetGeoTaggingGoogleLinkKey()
    {
        $_b34ab5f1ac69818b996067e04caa4631 = DocumentsApplication::getConfig();
        $_83d95ab61a12263c6df1f5c4e0722f5e = $_b34ab5f1ac69818b996067e04caa4631->Get($GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_83d95ab61" . "a12263c6df" . "1f5c4e0722" . "f5e"]);
        if (!$_83d95ab61a12263c6df1f5c4e0722f5e) {
            return self::GEO_TAGGING_GOOGLE_LINK;
        }
        return $_83d95ab61a12263c6df1f5c4e0722f5e;
    }
}