<?php 

require_once $_SERVER['DOCUMENT_ROOT'].'/admin/system/settings/db.php';



function id($text) {

    $find = array('Ç', 'Ş', 'Ğ', 'Ü', 'İ', 'Ö', 'ç', 'ş', 'ğ', 'ü', 'ö', 'ı', '+', '#');

    $replace = array('c', 's', 'g', 'u', 'i', 'o', 'c', 's', 'g', 'u', 'o', 'i', 'plus', 'sharp');

    $text = strtolower(str_replace($find, $replace, $text));

    $text = preg_replace("@[^A-Za-z0-9\-_\.\+]@i", ' ', $text);

    $text = trim(preg_replace('/\s+/', ' ', $text));

    $text = str_replace(' ', '', $text);



    return $text;

}


session_start();
$user_id = $_SESSION['memberId'];
$providerCheckSite= $DB->prepare("select * from provider where id=?");
$providerCheckSite->execute(array($user_id));
$providerChk = $providerCheckSite->fetch(PDO::FETCH_ASSOC);

if ($providerChk['isAdmin'] == '1') {
    $provider = $DB->query("SELECT * FROM provider WHERE working = '1' ORDER BY sira ASC")->fetchAll(PDO::FETCH_ASSOC);
} else {
    $provider = $DB->prepare("SELECT * FROM provider WHERE working = '1' AND id = :user_id ORDER BY sira ASC");
    $provider->execute(['user_id' => $user_id]);
    $provider = $provider->fetchAll(PDO::FETCH_ASSOC);
}


$deger = array();

foreach ($provider as $providerVeri) {

    if (empty($providerVeri['photo'])) {

        $providerVeri['photo'] = "no-photo.png";

    }

    $deger[] = array(

        "id" => $providerVeri['id'],

        "title" => $providerVeri['name'],

        "html" => '<span class="avatar"><img class="round" src="app-assets/images/profile/'.$providerVeri['photo'].'" alt="avatar" height="40" width="40"></span>',

        "sira" => $providerVeri['sira'] // Sıralama bilgisi de JSON'a ekleniyor

    );

}



header('Content-Type: application/json');

echo json_encode($deger, JSON_PRETTY_PRINT);

?>

