<?php
header('Content-Type: application/json');
include('../class/include.php');
if (!Account::isAuthentified() || !CSRF::isAjaxRequest())
{
    die("Bad request");
}

if (!Account::IsAdmin()) {
  $no = [];
  array_push($no, ["DT_RowId" => "A user don't need to know thoses infos", "A user don't need to know thoses infos", "A user don't need to know thoses infos", "A user don't need to know thoses infos", "A user don't need to know thoses infos"]);
  die(json_encode($no));
}

$all_users_predata = Account::GetAllAccount();
$list = [];

foreach ($all_users_predata as $data)

{
	if ($data['active'] == 1) {
	$himrole = Account::GetRole($data['id']);
	$fuckkey = Account::GetKey($data['id']);
  $rolecolor = Account::GetRoleColor($data['id']);
  $rolecolorlink = Account::GetRoleColorFire($data['id']);

    if ($data['id'] != 72) {
    $button = '<button style="padding: 0; border: none; background: none; color: gray;" onclick="deleteUser('.$data['id'].')" class="btn btn-danger btn-sm"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-x-circle"><circle cx="12" cy="12" r="10"></circle><line x1="15" y1="9" x2="9" y2="15"></line><line x1="9" y1="9" x2="15" y2="15"></line></svg></button>';

   	$setrole = '  <button style="padding: 0; border: none; background: none; color: gray;" onclick="showrole('.$data['id'].')" type="button" class="btn btn-info btn-sm"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-user"><path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path><circle cx="12" cy="7" r="4"></circle></svg></button>';

    if ($data['ban'] == 1) {
    $ban = '  <button style="padding: 0; border: none; background: none; color: gray;" onclick="deban('.$data['id'].')" type="button" class="btn btn-danger btn-sm"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-user-x"><path d="M16 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"></path><circle cx="8.5" cy="7" r="4"></circle><line x1="18" y1="8" x2="23" y2="13"></line><line x1="23" y1="8" x2="18" y2="13"></line></svg></button>';
    } else {
    $ban = '  <button style="padding: 0; border: none; background: none; color: gray;" onclick="ban('.$data['id'].')" type="button" class="btn btn-success btn-sm"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-user-check"><path d="M16 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"></path><circle cx="8.5" cy="7" r="4"></circle><polyline points="17 11 19 13 23 9"></polyline></svg></button>';
    }
  } else {
    $button = 'Ce membre est intouchable';
    $setrole = '';
    $himrole = '<span style="font-size: 12px; color: #000000; font-weight: bold; text-shadow: 0 0 5px '.$rolecolor.', 0 0 5px '.$rolecolor.'; background: url('.$rolecolorlink.') repeat scroll 0% 0% transparent;}">Gérant</span>';
    $fuckkey = '<span style="filter: blur(3px)"> XXXXXXXXXX </span>';
    $ban = '';
  }

  if ($data['id'] == 75) {
    $button = 'Tu touche t\'es mort';
    $setrole = '';
    $himrole = '<span style="font-size: 12px; color: #000000; font-weight: bold; text-shadow: 0 0 5px '.$rolecolor.', 0 0 5px '.$rolecolor.'; background: url('.$rolecolorlink.') repeat scroll 0% 0% transparent;}">Gérant</span>';
    $fuckkey = '<span style="filter: blur(3px)"> XXXXXXXXXX </span>';
    $ban = '';
  }

  if ($himrole == "Administrateur") {
    $himrole = '<span style="font-size: 12px; color: #000000; font-weight: bold; text-shadow: 0 0 5px '.$rolecolor.', 0 0 5px '.$rolecolor.'; background: url('.$rolecolorlink.') repeat scroll 0% 0% transparent;}">Administrateur</span>';
  }

    array_push($list, ["DT_RowId" => "user-".$data['id'], $data['username'], $himrole, $fuckkey, $button.$setrole.$resetkey.$ban]);
	}
}

echo json_encode(['data' => $list]);
?>
