using a custom button to apply a filter (via redirecting)

webmarco

New member
I have page PIANI_LINEE that is created on a VIEW.
In the results_grid form I placed 3 custom buttons in each row since they act on the single record.

Furthermore I'd like having 3 custom buttons on the top: LINEA 2 , LINEA 3 , LINEA 4
I would use header(Location...... function so when I click on button LINEA 2, I will be redirected on the page PIANI_LINEE but showing only data where the filed ID_LINEA = 2
At the moment I am not able to find documentation about the syntax of the url I should use.

Looking at the manual, in the custom buttons explaination I see something like: header('Location:'.$dadabik_main_file.'?tablename='.urlencode($table_name).'&function=edit&where_field='.urlencode($where_field).'&where_value='.urlencode($where_value)); but since I am not that expert, I am asking help about forming the proper url to be redirected on the proper filtered page.

The not filtered page is reached at the url: ipaddress/mydir/index.php?function=search&tablename=PIANO_LINEE
I don't know what syntax I should use for adding WHERE ID_LINEA=2 to the url

Your current DaDaBIK version​

You are using DaDaBIK version 11.12-Elba enterprise, installed on 25-03-2024 (installation code: ), the latest version of DaDaBIK is 11.12-Elba released on 30-11-2023

You are running the latest release of DaDaBIK

In case you want to upgrade to a more powerful edition (from Pro to Enterprise/Platinum, from Enterprise to Platinum) please contact us.

System info​

PHP Version: 7.3.31-1~deb10u5

mysql version: 5.5.5-10.3.39-MariaDB-0+deb10u2

Web server: Apache/2.4.38 (Raspbian)

Client: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36

URL installation: http://myip/app_gest_dir/
 

eugenio

Administrator
Staff member
Hello Marco,
you mentioned PIANO_LINEE and PIANI_LINEE, are them two different tables or is it a typo?
 

webmarco

New member
my "solution" has been setting a $SESSION['valore'] using a custom button for each "filter" I need; after setting this value, the "redirection" is again on the same page, but the page has a custom filter that is built on the value assigned to $SESSION['valore']

i.e for LINEA 2 (ID_LINEA = 2) I used the following code:


// pulsante per aprire vista PIANI_LINEE su linea 2
$custom_buttons['PIANO_LINEE'][$cnt]['type'] = 'php_standard';
$custom_buttons['PIANO_LINEE'][$cnt]['callback_function'] = 'dadabik_piano_linea_2';
$custom_buttons['PIANO_LINEE'][$cnt]['permission_needed'] = 'edit';
$custom_buttons['PIANO_LINEE'][$cnt]['show_in'][] = 'results_grid' ;
$custom_buttons['PIANO_LINEE'][$cnt]['position_form'] = 'top';
$custom_buttons['PIANO_LINEE'][$cnt]['label_type'] = 'fixed';
$custom_buttons['PIANO_LINEE'][$cnt]['label'] = 'LINEA 2';
$custom_buttons['PIANO_LINEE'][$cnt]['style'] = 'background:#ffff00;color:#000000;width:100px';
$cnt++;

function dadabik_piano_linea_2($table_name, $where_field, $where_value)
{
$_cp_filtro = 2;
$_SESSION['valore']=$_cp_filtro;
header('Location:index.php?function=search&tablename=PIANO_LINEE');
exit;
}


$custom_filters['PIANO_LINEE'] = 'dadabik_custom_filter_PIANO_LINEE';
function dadabik_custom_filter_PIANO_LINEE()
{
$_cp_filtro=$_SESSION['valore'];
global $current_user, $current_id_group, $quote;

if ($_cp_filtro > 0 ){ // applica filtro solo per la linea
$filter = $quote."PIANO_LINEE".$quote.".".$quote."ID_LINEA".$quote." = ".$_cp_filtro;
}
else{
$filter = "1=1";
}

/* azzero variabile per evitare blank page se non ho record, è sufficiente fare refresh della pagine e si ottengono tutti i dati senza ulteriore filtro */
$_SESSION['valore']=0;
return $filter;
}

this post helped me: https://dadabik.com/forum/index.php?threads/custom-button-custom-filter.23263/post-23265
 

eugenio

Administrator
Staff member
I am not sure if I got what you need, but if you only need to open a table with a pre-defined search filter, you can execute the search using the advanced search feature, then click on "show search URL" at the bottom of the page and finally use that URL as a redirect URL in your custom button.

Best,
 

webmarco

New member
Thank you for the answer, I didn't think about this solution to have the right URL to copy.
Maybve I missed the way of opening a table with a pre-defined search filter.
"Show search URL" button is present only when I open a table with pre-defined filter?
 

eugenio

Administrator
Staff member
The button is displayed after the execution of an advanced search and allows you to simulate, using an URL (the one the button shows you), the same advanced search.
 

webmarco

New member
This is what I got after an advanced search execution:

Immagine 2024-04-06 093131.jpg
I can't see any "Show search URL" button. Maybe I am missing the point...
 

eugenio

Administrator
Staff member
That's strange, is the config parameter $enable_search_by_url set to 1 (by default it is)?
If you use one of our online demo (dadabik.com/demo), do you see the button?
 

webmarco

New member
Hi, thank you for the hint.
The $enable_search_by_utl is set to 1 in config.php but I didn't copy it to my config_custom.php.
After copying it to the custom_config.php file, the button is working properly.
I didn't add before since I was following the manual suggestion:
  • config.php contains ALL the configuration parameters you can set, together with their default value, but you don't need to specify all of them in config_custom.php. In config_custom.php you need the nine required parameters + any additional parameter whose value you want to change from the default. If you are new to DaDaBIK, probably you want to install it by setting only the nine required parameters (plus the four, additional, suggested parameters), then, in case you need it, you can add additional parameters later.

Thank you again.
 

eugenio

Administrator
Staff member
You don't need to copy it to config_custom.php (and you shouldn't unless you want to change the default setting). There might be something wrong somewhere else..
I see you wrote $enable_search_by_utl (utl instead of url), is this a typo or in your config.php file it is written utl ?
 

webmarco

New member
it is a typo; in my config.php it is written properly but it works only since I added to my config_custom.php.
Is it possible that somewhere I made a mistake and config.php is ignored? I didn't edit it at all
 

eugenio

Administrator
Staff member
I am pretty sure that $enable_search_by_url is overwritten somewhere or not set in config.php due to a file edit.
I would test a fresh installation of DaDaBIK, using the original files you downloaded and editing only config_custom.php with the required parameters and see if you get the same behaviour. If it works properly, I would double check all the files you edited in your current installation.
 

webmarco

New member
Would it be possible testing just by using a just downloaded config.php substituing it in the include folder?
Would I miss some customization in the app (i.e. layout basic settings)?
 
Top