<?php
session_start();
include "../classes/db.class.php";
include "../classes/fc.class.php";

if (isset($_SESSION['uid'])) {
    $tabela = $_SESSION['tabela'];
    $coluna = $_SESSION['coluna'];
    $ret = "";
    $con = DB::conecta();
    $sql = "SELECT * FROM ".$tabela." ORDER BY ".$coluna;
    $bs = $con->prepare($sql);
    $bs->execute();
    $row = $bs->fetchAll(PDO::FETCH_ASSOC);
    $con = null;
    if (count($row) == 0) {
        echo "<tr><td  class='text-center'><div class='alert alert-warning bg-warning texte-center' ><h5>Nenhum cliente cadastrado!</h5></div></td></tr>";
    } else {

        $ret = "";
        foreach ($row as $r) {
            $ret .= "<tr>";
            $ret .= "<td class='col-2 text-center'><img src='assets/img/avatar.png' class='img-circle img-responsive' width='32' height='32' /></td>";
            $ret .= "<td>" . $r['NOME'] . "</td>";
            $ret .= "<td class='col-3 text-end'><a href='#' id='" . $r['idcliente'] . "' class='btn btn-link btn-sm text-secondary' onclick='dados(" . $r['idcliente'] . ",1)'><i class='fas fa-edit'></i></a><a href='#' data-bs-toggle='modal' data-bs-target='#mDados' id='" . $r['idcliente'] . "' class='btn btn-link btn-sm   text-secondary' onclick='dados(" . $r['idcliente'] . ",2);' ><i class='fas fa-eye'></i></a></td>";

            $ret .="</tr>";
            
        }
        echo $ret;
        
    }
} else {
    echo "erro";
}
