find $current_user and $current_id_group in a javascript function

Hello,

if I start a javascript function by custom button, how can I find the actual user id and the group id?

In the docu I have found the variable in PHP: global $current_user, $current_id_group;
But I have not found the variable in a javascript function.

Thanks!
Michael

You are using DaDaBIK version 9.4-Monterosso enterprise
PHP Version: 7.1.31
mysql version: 5.7.27
Web server: Apache
Client: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:72.0) Gecko/20100101 Firefox/72.0
 

eugenio

Administrator
Staff member
Hello,
those are PHP variable and they are available server side only.

To have it in your Javascript global scope you could do something like this in your include/custom_functions.js

<?php

if (isset($current_user)){
echo 'current_user = "'.$current_user.'";'; // I assign the current username to a javascript variable
}

if (isset($current_id_group)){
echo 'current_id_group = '.$current_id_group.';'; // I assign the current group id to a javascript variable
}

?>

I haven't tested it but is should work

Best,
 
Hello,

thanks. I have now this solution ....
[pre]
<?php
global $current_id_group;

if($current_id_group==3 || $current_id_group==4) {
include('test_search.php');
} else {
echo "<script>";
echo "window.setTimeout('window.location = \"https://www.domain.com/entwicklung/dadabik/index.php?function=show_search_form&show_result_static_page=1&id_static_page=6\"',0);";
echo "</script>";
}
?>
[/pre]

... and it works fine!
Regards
Michael
 
Top