Custom button that uses a filtered query

taubes

Member
Hi,

I hope somebody can help me here.

I am using a custom button to generate a custom PDF from the results_grid (see below). The only variable that I can use is $table_name. Is there a way to access the filter, set by search and quick search in my custom_function.

(...)
$custom_buttons['some_table'][$cnt]['callback_function'] = 'dadabik_custom_function';
$custom_buttons['some_table'][$cnt]['show_in'] = 'results_grid';
(...)
function dadabik_custom_function($table_name, $where_field, $where_value) {
global $conn;

$sql = "SELECT * FROM :table_name ";
$res_prepare = prepare_db($conn, $sql);
$res_bind = bind_param_db($res_prepare, ':table_name', $table_name);
$res = execute_prepared_db($res_prepare,0);
$row = fetch_row_db($res_prepare);
(...)
}

What I would like to do is:

(...)
$custom_buttons['some_table'][$cnt]['callback_function'] = 'dadabik_custom_function';
$custom_buttons['some_table'][$cnt]['show_in'] = 'results_grid';
(...)
function dadabik_custom_function($table_name, $where_field, $where_value) {
global $conn;

$filter = xxx; // something like WHERE username_user = 'xxxx' AND year = 'xxxx'

$sql = "SELECT * FROM :table_name :filter";
$res_prepare = prepare_db($conn, $sql);
$res_bind = bind_param_db($res_prepare, ':table_name', $table_name);
$res_bind = bind_param_db($res_prepare, ':filter', $filter);
$res = execute_prepared_db($res_prepare,0);
$row = fetch_row_db($res_prepare);
(...)
}

Thanks so much for your help

Stefan

+++ using DaDaBIK version 9.2.2-Monterosso enterprise
 

eugenio

Administrator
Staff member
Hello Stefan,
you can find the current WHERE clause produced by search & filters in the global variable $where_clause.
So add it to your custom function:

global $conn, $where_clause

and use it.

Best,
 

taubes

Member
Awesome, that was easy ;-)

Is there a resource where one can look up global or session values?

Thanks

Stefan
 

eugenio

Administrator
Staff member
Hi,
not yet, but I want to add a section about it in the documentation.

Best,
 
Top