Show column if you have the rights
Show column if you have the rights
Is it possible to show some more column if you have the rights for that?
I have written the rights in the $_SESSION. How can I read the $_SESSION rights with js. I do it with following line on the of my php script.
$rdata = array(
"data" => $data,
"draw" => "1",
"recordsTotal" => $nr_datarows,
"recordsFiltered" => $nr_datarows,
"recordRights" => (isset($_SESSION["administrator"]) and $_SESSION["administrator"] == "1") ? "1" : "0"
);
echo json_encode($rdata);
I know that js can not read the $_SESSION, but maybe you have better idea. Now comes my Problem. How can I show the columns if the rights are ok.
I tried something like this and more, but it did not work.
"columnDefs": [
{ targets: [ 0, 1, 2, 3, 4, 5, 6, 7, 9 ], visible: true },
{ render: function(data, type, row){
($data.recordRights == '1') ? (targets: 8, visible: true) : (targets: 8, visible: true);
}},
{ targets: '_all', visible: false }
],
I know that code is bullshit, but I have no more ideas, how can I do this.
Can you give me an hint, what I should do?
Andreas
This question has accepted answers - jump to:
Answers
I found the right code. I think it was yesterday to late for clear thinking
I write the code now:
But my fist question about to "read the User rights of PHP $_SESSION"
is open. Is there a better way to get the Values than I written abouve?
You would need to either expose the rights information in Javascript, or otherwise dynamically generate the Javascript based on the rights. The second is more secure, but also of course more difficult.
Allan