2

I have a page that allow users to access it. This page have certain things that not allow user to see that particular thing, For my case, user is unable to edit edit() or view this function, so I want to hide it by putting below code in JS because I am using function on this link.

I already enabled Session in PHP page like this <?php session_start(); ?>

And I try this putting this PHP in JS inside Datatables function. The dataTable function is working fine. Just the PHP is not working.

{ data : "project_id",
    render: function(data) {
    return  "<span onclick='view()'></span>&nbsp;"+    // This is allow to user and admin level
            "<?php 
              if ($_SESSION['user_privilege'] == 'Admin') { ?>
                 <span onclick='edit()'</span>
             <?php } ?>";   // This is allow for admin level only
    }
}
mastersuse
  • 936
  • 1
  • 15
  • 35

1 Answers1

6

Check the following

<?php
if(isset($_SESSION["user_user_privilege"])){
  echo "<script>
     let button = '<span onclick='edit()'></span>';
  </script>";
}else{
 echo "<script>
     let button = '';
  </script>";
}
?>

Now check the button is empty or not.

{ data : "project_id",
    render: function(data) {
    return  "<span onclick='view()'></span>&nbsp;"+  ((button!="") ? button : "");

    }
}
Hassan Nasir
  • 146
  • 5