<?php

include('../permission/connect_sql.php');

$ajax = [];

$connectionInfo = array("Database" => "$dbname", "UID" => "$username", "PWD" => "$password", "CharacterSet" => "UTF-8");
$conn = sqlsrv_connect($hostname, $connectionInfo);
if ($conn === false) {
    die(print_r(sqlsrv_errors(), true));
}

$sql = "SELECT [Import_Log].[UserID],[UserName],[DepartmentName],[Import_Log].[project_id],[project_name],[upload_time] FROM [21000X].[dbo].[Import_Log] 
JOIN [dbo].[user] ON [user].[UserID] = [21000X].[dbo].[Import_Log].[UserID]
JOIN [21000X].[dbo].[Project_Table] ON [Project_Table].[project_id] = [Import_Log].[project_id]
JOIN [permissions].[dbo].[Department] ON [user].[DepartmentID] = [Department].[DepartmentID]";
$stmt = sqlsrv_query($conn, $sql);
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {

    $temp = array();
    $temp["UserID"] = $row["UserID"];
    $temp["UserName"] = $row["UserName"];
    $temp["DepartmentName"] = $row["DepartmentName"];
    $temp["project_id"] = $row["project_id"];
    $temp["project_name"] = $row["project_name"];
    $temp["upload_time"] = array($row["upload_time"]);
    array_push($ajax, $temp);
}

echo json_encode($ajax, JSON_UNESCAPED_UNICODE);
