<?php
    header('Access-Control-Allow-Origin: '.$config->get('site_url'));
    header('Content-Type: application/json');
    header('Access-Control-Allow-Methods: POST');
    header('Access-Control-Allow-Headers: Access-Control-Allow-Headers,Content-Type,Access-Control-Allow-Methods, Authorization, X-Requested-With');

    $response = "";
    if($_SERVER["REQUEST_METHOD"] == "POST") {
        if(isset($_POST['csrf_token']) && $anticsrf->validate($_POST['csrf_token'])) {
            if(isset($_POST['type']) && isset($_POST['action'])) {
                if($_POST['type'] == "action"){
                    switch($_POST['action']){
                        case "add":
                            $default = $_POST['default'];
                            if($_POST['invoice_type'] == 0){
                                $tckno = $_POST['tckno'];
                                $company = "";
                                $tax_no = "";
                                $tax_office = "";

                                if(!$utils->validateIdentityNumber($tckno)) {
                                    $response = array('status'=>false, 'message'=>'Lütfen geçerli bir TC Kimlik No giriniz.');
                                    echo json_encode($response);
                                    exit();
                                }
                            }else{
                                $tckno = "";
                                $company = $_POST['company'];
                                $tax_no = $_POST['tax_no'];
                                $tax_office = $_POST['tax_office'];
                                    
                                if(!$utils->validateTaxNumber($tax_no)) {
                                    $response = array('status'=>false, 'message'=>'Lütfen geçerli bir Vergi No giriniz.');
                                    echo json_encode($response);
                                    exit();
                                }
                            }
                            $stmt = $db->query("INSERT INTO {$db->prefix}address (`status`, `type`, `user_id`, `title`, `firstname`, `lastname`, `tckno`, `company`, `tax_no`, `tax_office`, `address`, `city`, `town`, `phone`, `isdefault`, `date_added`, `date_updated`) VALUES (1, :type, :user_id, :title, :firstname, :lastname, :tckno, :company, :tax_no, :tax_office, :address, :city, :town, :phone, :isdefault, NOW(),NOW())", array(":type"=>$_POST['invoice_type'], ":user_id"=>$session->data['user_id'], ":title"=>$_POST['title'], ":firstname"=>$_POST['firstname'], ":lastname"=>$_POST['lastname'], ":tckno"=>$tckno, ":company"=>$company, ":tax_no"=>$tax_no, ":tax_office"=>$tax_office, ":address"=>$_POST['address'], ":city"=>$_POST['city'], ":town"=>$_POST['town'], ":phone"=>$_POST['phone'], ":isdefault"=>$default));
                    
                            if (!$stmt->error) {
                                if($default == 1){
                                    $inserted_id = $db->getLastId();
                                    $user->changeDefaultAddress($inserted_id);
                                }
                                $response = array('status'=>true, 'message'=>'Adres başarıyla kaydedildi.');
                            }else{
                                $utils->errorLog("error", "Cannot add address. ".$stmt->error_info['message'], $session->data['user_id'], $_SERVER['REQUEST_URI']);
                                $response = array('status'=>false, 'message'=>'Bir hata oluştu ve adres eklenemedi. Lütfen daha sonra tekrar deneyiniz.');
                            }
                        break;
                        case "update":
                            if(isset($_POST['id'])) {
                                $default = isset($_POST['default']) && $_POST['default']==1 ? 1 : 0;
                                if($_POST['invoice_type'] == 0){
                                    $tckno = $_POST['tckno'];
                                    $company = "";
                                    $tax_no = "";
                                    $tax_office = "";
                                    
                                    if(!$utils->validateIdentityNumber($tckno)) {
                                        $response = array('status'=>false, 'message'=>'Lütfen geçerli bir TC Kimlik No giriniz.');
                                        echo json_encode($response);
                                        exit();
                                    }
                                }else{
                                    $tckno = "";
                                    $company = $_POST['company'];
                                    $tax_no = $_POST['tax_no'];
                                    $tax_office = $_POST['tax_office'];
                                    
                                    if(!$utils->validateTaxNumber($tax_no)) {
                                        $response = array('status'=>false, 'message'=>'Lütfen geçerli bir Vergi No giriniz.');
                                        echo json_encode($response);
                                        exit();
                                    }
                                }
                                $stmt = $db->query("UPDATE {$db->prefix}address SET `status`=:status, `type`=:type, `title`=:title, `firstname`=:firstname, `lastname`=:lastname, `tckno`=:tckno, `company`=:company, `tax_no`=:tax_no, `tax_office`=:tax_office, `address`=:address, `city`=:city, `town`=:town, `phone`=:phone, `isdefault`=:isdefault, `date_updated`=NOW() WHERE id=:id", array(":status"=>$_POST['status'], ":type"=>$_POST['invoice_type'], ":title"=>$_POST['title'], ":firstname"=>$_POST['firstname'], ":lastname"=>$_POST['lastname'], ":tckno"=>$tckno, ":company"=>$company, ":tax_no"=>$tax_no, ":tax_office"=>$tax_office, ":address"=>$_POST['address'], ":city"=>$_POST['city'], ":town"=>$_POST['town'], ":phone"=>$_POST['phone'], ":isdefault"=>$default, ":id"=>$_POST['id']));
                        
                                if (!$stmt->error) {
                                    if($default == 1){
                                        $user->changeDefaultAddress($_POST['id']);
                                    }
                                    $response = array('status'=>true, 'message'=>'Adres başarıyla güncellendi.');
                                }else{
                                    $utils->errorLog("error", "Cannot update address. ".$stmt->error_info['message'], $session->data['user_id'], $_SERVER['REQUEST_URI']);
                                    $response = array('status'=>false, 'message'=>'Bir hata oluştu ve adres güncellenemedi. Lütfen daha sonra tekrar deneyiniz.');
                                }
                            }else{
                                $response = array('status'=>false, 'message'=>'Bir hata oluştu ve adres güncellenemedi. Lütfen daha sonra tekrar deneyiniz.');
                            }
                        break;
                        case "delete":
                            if(isset($_POST['id'])) {
                                $stmt = $db->query("DELETE FROM {$db->prefix}address WHERE id=:id", array(':id'=>(int)$_POST['id']));
                                if (!$stmt->error) {
                                    $response = array('status'=>true, 'message'=>'Adres başarıyla silindi.');
                                }else{
                                    $utils->errorLog("error", "Cannot delete address. ".$stmt->error_info['message'], $session->data['user_id'], $_SERVER['REQUEST_URI']);
                                    $response = array('status'=>false, 'message'=>'Bir hata oluştu ve adres silinemedi. Lütfen daha sonra tekrar deneyiniz.');
                                }
                            }else{
                                $response = array('status'=>false, 'message'=>'Bir hata oluştu ve adres silinemedi. Lütfen daha sonra tekrar deneyiniz.');
                            }
                        break;
                    }
                } else if($_POST['type'] == "get"){
                    switch($_POST['action']){
                        case "add":
                            $modal_id = $utils->randomString(6);
                            $cities = $utils->getCities();

                            $modal = "<form id=\"address-form\" action=\"\" method=\"POST\">
                                            <div class=\"modal fade\" id=\"$modal_id\" tabindex=\"-1\" role=\"dialog\" aria-hidden=\"true\">
                                                <div class=\"modal-dialog modal-lg modal-dialog-centered modal-dialog-scrollable modal-fullscreen-md-down\" role=\"document\">
                                                    <div class=\"modal-content\">
                                                        <div class=\"modal-header\">
                                                            <h5 class=\"modal-title\">Adres Ekle</h5>
                                                            <button class=\"custom-close\" id=\"modal-close\" type=\"button\" data-bs-dismiss=\"modal\" aria-label=\"Close\"></button>
                                                        </div>
                                                        <div class=\"modal-body\">
                                                            <div class=\"row mb-3\">
                                                                <label for=\"title\" class=\"col-md-3 col-form-label text-md-end\">Adres Başlığı</label>
                                                                <div class=\"col-md-9\">
                                                                <input type=\"text\" class=\"form-control\" name=\"title\" id=\"title\" placeholder=\"\" value=\"\" required>
                                                                </div>
                                                            </div>
                                                            <div class=\"row mb-3\">
                                                                <label for=\"firstname\" class=\"col-md-3 col-form-label text-md-end\">Adınız</label>
                                                                <div class=\"col-md-9\">
                                                                    <input type=\"text\" class=\"form-control\" name=\"firstname\" id=\"firstname\" placeholder=\"\" required autocomplete=\"given-name\">
                                                                </div>
                                                            </div>
                                                            <div class=\"row mb-3\">
                                                                <label for=\"lastname\" class=\"col-md-3 col-form-label text-md-end\">Soyadınız</label>
                                                                <div class=\"col-md-9\">
                                                                    <input type=\"text\" class=\"form-control\" name=\"lastname\" id=\"lastname\" placeholder=\"\" required autocomplete=\"family-name\">
                                                                </div>
                                                            </div>
                                                            <div class=\"row mb-3\">
                                                                <label for=\"phone\" class=\"col-md-3 col-form-label text-md-end\">Telefon</label>
                                                                <div class=\"col-md-9\">
                                                                    <input type=\"tel\" class=\"form-control\" name=\"phone\" id=\"phone\" placeholder=\"(___)___-__-__\" value=\"\" required autocomplete=\"tel\">
                                                                </div>
                                                            </div>
                                                            <div class=\"row mb-3\">
                                                                <label for=\"city\" class=\"col-md-3 col-form-label text-md-end\">İl</label>
                                                                <div class=\"col-md-9\">
                                                                <select name=\"city\" id=\"city\" class=\"form-select form-control\" required autocomplete=\"billing address-level2\">
                                                                    <option value=\"\">Seçiniz..</option>";
                                                                        foreach($cities as $key => $item){
                                                                            $modal .= "<option value=\"{$item['plate_no']}\">{$item['name']}</option>";
                                                                        }
                                                        $modal .= "</select>
                                                                </div>
                                                            </div>
                                                            <div class=\"row mb-3\">
                                                                <label for=\"town\" class=\"col-md-3 col-form-label text-md-end\">İlçe</label>
                                                                <div class=\"col-md-9\">
                                                                <select name=\"town\" id=\"town\" class=\"form-select form-control\" required autocomplete=\"billling address-level1\"></select>
                                                                </div>
                                                            </div>
                                                            <div class=\"row mb-3\">
                                                                <label for=\"address\" class=\"col-md-3 col-form-label text-md-end\">Adres</label>
                                                                <div class=\"col-md-9\">
                                                                <textarea class=\"form-control\" name=\"address\" id=\"address\"  rows=\"2\" required autocomplete=\"billing street-address\"></textarea>
                                                                </div>
                                                            </div>
                                                            <fieldset class=\"row mb-3\">
                                                                <legend class=\"col-form-label col-md-3 pt-0 text-md-end\">Fatura Tipi</legend>
                                                                <div class=\"col-md-9\">
                                                                    <div class=\"form-check styled-radio\">
                                                                        <input type=\"radio\" name=\"invoice_type\" id=\"personal\" value=\"0\" checked>
                                                                        <label for=\"personal\">Bireysel</label>
                                                                    </div>
                                                                    <div class=\"form-check styled-radio\">
                                                                        <input type=\"radio\" name=\"invoice_type\" id=\"commercial\" value=\"1\">
                                                                        <label for=\"commercial\">Kurumsal</label>
                                                                    </div>
                                                                </div>
                                                            </fieldset>
                                                            <div id=\"personal_collapse\" class=\"collapse show\">
                                                                <div class=\"row mb-3\">
                                                                    <label for=\"tckno\" class=\"col-md-3 col-form-label text-md-end\">TC Kimlik No</label>
                                                                    <div class=\"col-md-9\">
                                                                        <input type=\"number\" class=\"form-control\" name=\"tckno\" id=\"tckno\" placeholder=\"\" value=\"\" required>
                                                                    </div>
                                                                </div>
                                                            </div>
                                                            <div id=\"commercial_collapse\" class=\"collapse\">
                                                                <div class=\"row mb-3\">
                                                                    <label for=\"company\" class=\"col-md-3 col-form-label text-md-end\">Unvan</label>
                                                                    <div class=\"col-md-9\">
                                                                        <input type=\"text\" class=\"form-control\" name=\"company\" id=\"company\" autocomplete=\"organization\">
                                                                    </div>
                                                                </div>
                                                                <div class=\"row mb-3\">
                                                                    <label for=\"tax_no\" class=\"col-md-3 col-form-label text-md-end\">Vergi No</label>
                                                                    <div class=\"col-md-9\">
                                                                        <input type=\"number\" class=\"form-control\" name=\"tax_no\" id=\"tax_no\">
                                                                    </div>
                                                                </div>
                                                                <div class=\"row mb-3\">
                                                                    <label for=\"tax_office\" class=\"col-md-3 col-form-label text-md-end\">Vergi Dairesi</label>
                                                                    <div class=\"col-md-9\">
                                                                        <input type=\"text\" class=\"form-control\" name=\"tax_office\" id=\"tax_office\">
                                                                    </div>
                                                                </div>
                                                            </div>
                                                            <div class=\"row mb-3\">
                                                                <label for=\"default\" class=\"col-md-3 col-form-label\"></label>
                                                                <div class=\"col-md-9\">
                                                                    <input type=\"checkbox\" id=\"default\" name=\"default\" class=\"styled-checkbox\" checked>
                                                                    <label for=\"default\" class=\"form-label\">Varsayılan Olarak Ayarla</label>
                                                                </div>
                                                            </div>
                                                            <input type=\"hidden\" name=\"type\" value=\"action\">
                                                            <input type=\"hidden\" name=\"action\" value=\"add\">
                                                        </div>
                                                        <div class=\"modal-footer\">
                                                            <button class=\"btn btn-secondary\" type=\"button\" data-bs-dismiss=\"modal\">İptal</button>
                                                            <button type=\"submit\" class=\"btn btn-primary\">Kaydet</a>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </form>";
                            $response = array('status'=>true, 'content'=>$modal, 'modal_id'=>$modal_id);
                        break;
                        case "update":
                            if(isset($_POST['id']) && !empty($_POST['id'])) {
                                $modal_id                = $utils->randomString(6);
                                $addres                  = $user->getAdress($_POST['id']);
                                $cities                  = $utils->getCities();
                                $towns                   = $utils->getTowns($addres["city"]);
                                $checked                 = $addres['default'] == 1 ? "checked" : "";
                                $is_commercial           = $addres['type'] == 1 ? "checked" : "";
                                $is_personal             = $addres['type'] == 0 ? "checked" : "";
                                $is_commercial_required  = $addres['type'] == 1 ? "required" : "";
                                $is_personal_required    = $addres['type'] == 0 ? "required" : "";
                                $commercial_collapse     = $addres['type'] == 1 ? "show" : "";
                                $personal_collapse       = $addres['type'] == 0 ? "show" : "";

                                $modal = "<form id=\"address-form\" action=\"\" method=\"POST\">
                                                <div class=\"modal fade\" id=\"$modal_id\" tabindex=\"-1\" role=\"dialog\" aria-hidden=\"true\">
                                                    <div class=\"modal-dialog modal-lg modal-dialog-centered modal-dialog-scrollable modal-fullscreen-md-down\" role=\"document\">
                                                        <div class=\"modal-content\">
                                                            <div class=\"modal-header\">
                                                                <h5 class=\"modal-title\">Adres Güncelle</h5>
                                                                <button class=\"custom-close\" id=\"modal-close\" type=\"button\" data-bs-dismiss=\"modal\" aria-label=\"Close\"></button>
                                                            </div>
                                                            <div class=\"modal-body\">
                                                                <div class=\"row mb-3\">
                                                                    <label for=\"title\" class=\"col-md-3 col-form-label text-md-end\">Adres Başlığı</label>
                                                                    <div class=\"col-md-9\">
                                                                    <input type=\"text\" class=\"form-control\" name=\"title\" id=\"title\" placeholder=\"\" value=\"".htmlspecialchars($addres['title'], ENT_QUOTES, 'UTF-8')."\" required>
                                                                    </div>
                                                                </div>
                                                                <div class=\"row mb-3\">
                                                                    <label for=\"firstname\" class=\"col-md-3 col-form-label text-md-end\">Adınız</label>
                                                                    <div class=\"col-md-9\">
                                                                        <input type=\"text\" class=\"form-control\" name=\"firstname\" id=\"firstname\" placeholder=\"\" value=\"".htmlspecialchars($addres['firstname'], ENT_QUOTES, 'UTF-8')."\" required>
                                                                    </div>
                                                                </div>
                                                                <div class=\"row mb-3\">
                                                                    <label for=\"lastname\" class=\"col-md-3 col-form-label text-md-end\">Soyadınız</label>
                                                                    <div class=\"col-md-9\">
                                                                        <input type=\"text\" class=\"form-control\" name=\"lastname\" id=\"lastname\" placeholder=\"\" value=\"".htmlspecialchars($addres['lastname'], ENT_QUOTES, 'UTF-8')."\" required>
                                                                    </div>
                                                                </div>
                                                                <div class=\"row mb-3\">
                                                                    <label for=\"phone\" class=\"col-md-3 col-form-label text-md-end\">Telefon</label>
                                                                    <div class=\"col-md-9\">
                                                                    <input type=\"tel\" class=\"form-control\" name=\"phone\" id=\"phone\" placeholder=\"(___)___-__-__\" value=\"".htmlspecialchars($addres['phone'], ENT_QUOTES, 'UTF-8')."\" required>
                                                                    </div>
                                                                </div>
                                                                <div class=\"row mb-3\">
                                                                    <label for=\"city\" class=\"col-md-3 col-form-label text-md-end\">İl</label>
                                                                    <div class=\"col-md-9\">
                                                                    <select name=\"city\" id=\"city\" class=\"form-select form-control\" required>
                                                                        <option value=\"\">Seçiniz..</option>";
                                                                            foreach($cities as $key => $item){
                                                                                if($addres['city'] == $item['plate_no']){
                                                                                    $modal .= "<option value=\"{$item['plate_no']}\" selected>{$item['name']}</option>";
                                                                                }else{
                                                                                    $modal .= "<option value=\"{$item['plate_no']}\">{$item['name']}</option>";
                                                                                }
                                                                            }
                                                            $modal .= "</select>
                                                                    </div>
                                                                </div>
                                                                <div class=\"row mb-3\">
                                                                    <label for=\"town\" class=\"col-md-3 col-form-label text-md-end\">İlçe</label>
                                                                    <div class=\"col-md-9\">
                                                                    <select name=\"town\" id=\"town\" class=\"form-select form-control\" required>";
                                                                        foreach($towns as $key => $town){
                                                                            if($addres['town'] == $town['id']){
                                                                                $modal .= "<option value=\"{$town['id']}\" selected>{$town['name']}</option>";
                                                                            }else{
                                                                                $modal .= "<option value=\"{$town['id']}\">{$town['name']}</option>";
                                                                            }
                                                                        }
                                                                        
                                                            $modal .= "</select>
                                                                    </div>
                                                                </div>
                                                                <div class=\"row mb-3\">
                                                                    <label for=\"address\" class=\"col-md-3 col-form-label text-md-end\">Adres</label>
                                                                    <div class=\"col-md-9\">
                                                                    <textarea class=\"form-control\" name=\"address\" id=\"address\"  rows=\"2\" required>".htmlspecialchars($addres['address'], ENT_QUOTES, 'UTF-8')."</textarea>
                                                                    </div>
                                                                </div>
                                                                <div class=\"row mb-3\">
                                                                    <label for=\"status\" class=\"col-md-3 col-form-label text-md-end\">Durum</label>
                                                                    <div class=\"col-md-9\">
                                                                        <select name=\"status\" id=\"status\" class=\"form-select form-control\" required>";
                                                                            if($addres['status'] == 1){
                                                                                $modal .= "<option value=\"1\" selected>Aktif</option>
                                                                                <option value=\"0\">Pasif</option>";
                                                                            }else{
                                                                                $modal .= "<option value=\"1\">Aktif</option>
                                                                                <option value=\"0\" selected>Pasif</option>";
                                                                            }
                                                                            
                                                            $modal .= "</select>
                                                                    </div>
                                                                </div>
                                                                <fieldset class=\"row mb-3\">
                                                                    <legend class=\"col-form-label col-md-3 pt-0 text-md-end\">Fatura Tipi</legend>
                                                                    <div class=\"col-md-9\">
                                                                        <div class=\"form-check styled-radio\">
                                                                            <input type=\"radio\" name=\"invoice_type\" id=\"personal\" value=\"0\" $is_personal>
                                                                            <label for=\"personal\">Bireysel</label>
                                                                        </div>
                                                                        <div class=\"form-check styled-radio\">
                                                                            <input type=\"radio\" name=\"invoice_type\" id=\"commercial\" value=\"1\" $is_commercial>
                                                                            <label for=\"commercial\">Kurumsal</label>
                                                                        </div>
                                                                    </div>
                                                                </fieldset>
                                                                <div id=\"personal_collapse\" class=\"collapse $personal_collapse\">
                                                                    <div class=\"row mb-3\">
                                                                        <label for=\"tckno\" class=\"col-md-3 col-form-label text-md-end\">TC Kimlik No</label>
                                                                        <div class=\"col-md-9\">
                                                                            <input type=\"number\" class=\"form-control\" name=\"tckno\" id=\"tckno\" placeholder=\"\" value=\"".htmlspecialchars($addres['tckno'], ENT_QUOTES, 'UTF-8')."\" $is_personal_required>
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                                <div id=\"commercial_collapse\" class=\"collapse $commercial_collapse\">
                                                                    <div class=\"row mb-3\">
                                                                        <label for=\"company\" class=\"col-md-3 col-form-label text-md-end\">Unvan</label>
                                                                        <div class=\"col-md-9\">
                                                                            <input type=\"text\" class=\"form-control\" name=\"company\" id=\"company\" value=\"".htmlspecialchars($addres['company'], ENT_QUOTES, 'UTF-8')."\" autocomplete=\"organization\" $is_commercial_required>
                                                                        </div>
                                                                    </div>
                                                                    <div class=\"row mb-3\">
                                                                        <label for=\"tax_no\" class=\"col-md-3 col-form-label text-md-end\">Vergi No</label>
                                                                        <div class=\"col-md-9\">
                                                                            <input type=\"number\" class=\"form-control\" name=\"tax_no\" id=\"tax_no\" value=\"".htmlspecialchars($addres['tax_no'], ENT_QUOTES, 'UTF-8')."\" $is_commercial_required>
                                                                        </div>
                                                                    </div>
                                                                    <div class=\"row mb-3\">
                                                                        <label for=\"tax_office\" class=\"col-md-3 col-form-label text-md-end\">Vergi Dairesi</label>
                                                                        <div class=\"col-md-9\">
                                                                            <input type=\"text\" class=\"form-control\" name=\"tax_office\" id=\"tax_office\" value=\"".htmlspecialchars($addres['tax_office'], ENT_QUOTES, 'UTF-8')."\" $is_commercial_required>
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                                <div class=\"row mb-3\">
                                                                    <label for=\"default\" class=\"col-md-3 col-form-label text-md-end\"></label>
                                                                    <div class=\"col-md-9\">
                                                                        <input type=\"checkbox\" id=\"default\" name=\"default\" class=\"styled-checkbox\" $checked>
                                                                        <label for=\"default\" class=\"form-label\">Varsayılan Olarak Ayarla</label>
                                                                    </div>
                                                                </div>
                                                                <input type=\"hidden\" name=\"type\" value=\"action\">
                                                                <input type=\"hidden\" name=\"action\" value=\"update\">
                                                                <input type=\"hidden\" name=\"id\" value=\"{$addres['id']}\">
                                                            </div>
                                                            <div class=\"modal-footer\">
                                                                <button class=\"btn btn-secondary\" type=\"button\" data-bs-dismiss=\"modal\">İptal</button>
                                                                <button type=\"submit\" class=\"btn btn-primary\">Güncelle</a>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </form>";
                                $response = array('status'=>true, 'content'=>$modal, 'modal_id'=>$modal_id);
                            }
                        break;
                        case "list":
                            $filter_data = array(
                                'user_id'			 => $session->data['user_id'],
                                'search_keywords'    => "",
                                'default'            => 0
                            );
                            $address_list = $user->getAdresses($filter_data);
                            $response = array('status'=>true, 'addresses'=>$address_list);
                        break;
                    }
                }
            } else {
                $response = array('status'=>false, 'message'=>'Lütfen tüm alanları doldurunuz.');
            } 
        } else {
            $response = array('status'=>false, 'message'=>'Hatalı CSRF token. Lütfen daha sonra tekrar deneyiniz.');
        }
    } else {
        $response = array('status'=>false, 'message'=>'Hatalı istek. Lütfen daha sonra tekrar deneyiniz.');
    }

    echo json_encode($response);