<?php  
  session_start();
    header('Content-Type: text/html; charset=utf-8');
	$ClientId = $_SESSION['client_id'];
        //require "log.php";
        //include "../settings.php";
		include "writedblog.php";
		
		$dbset = json_decode($_SESSION['settingsApp'],true);
		$db = new mysqli ($dbset['DB']['DB_HOST'],$dbset['DB']['DB_USER'],$dbset['DB']['DB_PASS'],$dbset['DB']['DB_NAME']);
        //$db = new mysqli ($DB_HOST,$DB_USER,$DB_PASS,$DB_NAME);
		//print_r($db);
        $db->query("SET CHARSET SET utf8");
        $db->query("SET NAMES 'utf8'");
        if (mysqli_connect_errno()) {
            echo "Error connecting to DB";
            exit('bad situetion');
        }
//-----------------------------------------------------------------show-------------------------------------------------------------    
   // echo $_GET['func'];
    if ($_GET['func'] == 'show') {
	//echo $ClientId;
	$query = "SELECT s.`id`,      
    s.`spares_group`,
    s.`spare`,
    s.`aticle`,
    s.`count` ,
    u.name 	FROM toir_spares s 
	INNER JOIN  `user` u ON u.id = s.users_id
    WHERE client_id = $ClientId";
	//echo $query;
	//if ($stmt = $db->prepare($query)) {
	$stmt = $db->prepare($query);
    $stmt->execute();
	$stmt->bind_result($id, $spares_group, $spare, $aticle, $count,$user);
		while($stmt->fetch()) {		
			$data[] = array(
				'id' => $id,
				'spares_group' => $spares_group,
				'spare' => $spare,
				'aticle' => $aticle,
				'count' => $count,		
				'user' => $user
			);
		}
	/*} else {
		echo 'not good';
	}*/
	$stmt->close();
	echo '{rows:'.json_encode($data).'}';
}

/*if ($_GET['func'] == 'showUsers') {
	echo 'asdsd';
	$query = "SELECT `id`, `name` FROM user";
	$stmt = $db->prepare($query)
    $stmt->execute();
	$stmt->bind_result($id, $name);
	while($stmt->fetch()) {
		$data[] = array(
			'id' => $id,
			'name' => $name
		);
	}
	$stmt->close();
	print_r($data);
	echo '{rows:'.json_encode($data).'}';
	
}*/