I have an array defined to print a datatables but I would like that in the buttons part (position 0 of the array) it would not show the option to delete or deactivate when a specific data type is given, in my case, when the user is administrator cannot be disabled but I don't know how to put a conditional inside the array... Any idea?
My code:
while ($reg=$rspta->fetch_object()) {
$data[]=array(
"0"=>($reg->estado)?'<button class="btn btn-warning btn-xs" onclick="mostrar('.$reg->idusuario.')"><i class="fa fa-pen"></i></button>'.' '.'<button class="btn btn-primary btn-xs" onclick="mostrar_clave('.$reg->idusuario.')"><i class="fa fa-key"></i></button>'.' '.'<button class="btn btn-danger btn-xs" onclick="desactivar('.$reg->idusuario.')"><i class="fas fa-toggle-off"></i></button>':'<button class="btn btn-warning btn-xs" onclick="mostrar('.$reg->idusuario.')"><i class="fa fa-pen"></i></button>'.' '.'<button class="btn btn-primary btn-xs" onclick="mostrar_clave('.$reg->idusuario.')"><i class="fa fa-key"></i></button>'.' '.'<button class="btn btn-success btn-xs" onclick="activar('.$reg->idusuario.')"><i class="fas fa-toggle-off"></i></button>',
"1"=>$reg->nombre,
"2"=>$reg->apellidos,
"3"=>$reg->codigo_persona,
"4"=>$reg->email,
"5"=>"<img src='../../admin/files/usuarios/".$reg->imagen."' height='50px' width='50px'>",
"6"=>$reg->fechacreado,
"7"=>($reg->estado)?'<span class="label bg-green">Activado</span>':'<span class="label bg-red">Desactivado</span>'
);
}
Assuming that you know if a user is the admin by means of a boolean value in this field
$reg->admin
, a possible solution would be this:Surely you will want to make more changes, but it is for you to take the idea and apply it.
Tell us if it works for you.