Copy/Move a table entry into another table.

uwec

New member
I have a list of items in strorage and want to copy or move those items to a list(another table) so that someone has a packing list to work whith.

I whish to add a button for this like in this thread :
https://dadabik.com/forum/read.php?1,19599

The only option i see right now is to create a seperate .php file to do this via ajax , but this field does not fall under restrictions of the user access controll, so its unsave by design.

It would be even better to have some checkboxes to select multiple lines and have an extra button to finally send those.

I thought of abusing the unique ID field for generating those box fields and adding a Send button via the template. But this interferes whith the forms i used for the search buttons . That was the reason why i asked if i can generate those buttons as simple links.

Using update hooks does not seem possible to me, as they require an edit form to be send.

Another thought i had was using a custom .php page for the AJAX functions , so at least its a litle bit save.

Any ideas how to get this done ?
 

eugenio

Administrator
Staff member
Hello,
it is not a trivial custom function to develop, the easiest way (without any hack) is adding a "status" field to the record, the user needs to edit the record, change the "status" and then an after update hook does the rest, also redirecting to the other table. This, however, needs an edit step.

A button calling a custom php function would work as well, but you have to handle the security by yourself in the custom page.

Best,
 

NorbertH

New member
Finally solved this by adding several hooks to the core.

First hook i added is in index.php around line 1387

After :
[pre]
case "search":

if ($enable_browse === '1'){
[/pre]

I added :
[pre]
// Top search hook for manipulating search vars and so on
if (isset($hooks[$table_name]['search']['top'])){
if ( substr($hooks[$table_name]['search']['top'],0,8) === 'dadabik_'){
call_user_func($hooks[$table_name]['search']['top'], $table_name, $where_field, $where_value);
}
}
[/pre]


Still index.php

around Line 1605

After:

[pre]
if (isset($just_delete_no_authorization) && $just_delete_no_authorization == "1") {
//txt_out('<p>'.$error_messages_ar["no_authorization_update_delete"]);
txt_out('<div class="msg_error"><p>'.$error_messages_ar["no_authorization_delete"].'</p></div>');

} // end if

[/pre]

I added
[pre]
// Hook for adding actions triggered by the extra buttons like output as Exel or printable list.
// This can be actions for buttons above grid or below.
if (isset($hooks[$table_name]['search']['buttons_actions'])){
if ( substr($hooks[$table_name]['search']['buttons_actions'],0,8) === 'dadabik_'){
call_user_func($hooks[$table_name]['search']['buttons_actions'] );
}
}

[/pre]


Next hook added around 1646
After :
[pre]
if ( $export_to_csv_feature == 1) {
echo ' <a class="btn btn-primary" href="'.$action.'?tablename='. urlencode($table_name).'&function='.$function.'&where_clause='.urlencode($whe
}
[/pre]

I added:

[pre]
// Hook for adding buttons like output as Exel or printable list. Those are placed right next to the other top buttons.
if (isset($hooks[$table_name]['search']['buttons'])){
if ( substr($hooks[$table_name]['search']['buttons'],0,8) === 'dadabik_'){
call_user_func($hooks[$table_name]['search']['buttons'], $where_field, $where_value);
}
}

[/pre]


Around line 1791

below :
[pre]
echo $results_table;
[/pre]

I added:
[pre]
// Hook below results Table we can add additional buttons or maybe the end of a form
if (isset($hooks[$table_name]['search']['grid_below'])){
if ( substr($hooks[$table_name]['search']['grid_below'],0,8) === 'dadabik_'){
call_user_func($hooks[$table_name]['search']['grid_below'],$table_name);
}
}
[/pre]



In include/business_logic.php

Around line 6085
After :

[pre]
} // end for
$results_table .= "</tr></thead><tbody>";
[/pre]

I added :
[pre]
// Hook here we add an extra place for form that uses fields added to the Table.
// as the function returns echos we need a buffer
ob_start();
if (isset($hooks[$table_name]['search']['grid_top'])){
if ( substr($hooks[$table_name]['search']['grid_top'],0,8) === 'dadabik_'){
call_user_func($hooks[$table_name]['search']['grid_top'], $table_name, $count_temp);
}
}
$results_table .= ob_get_clean();

[/pre]



After adding all those Hooks it was not too hard to build the additions i wanted all could be done in custom functions.


Fist i added some checkboxes to the id field whith a simple format function.
Then i added a starting formtag whith $hooks['Lager']['search']['grid_top']. (Just added an invisible row whith formtag)
Added the send button and the end of the form in $hooks['Lager']['search']['grid_below'].
Adn finally added the logic to copy the selected entries to another table in $hooks['Lager']['search']['buttons_actions'].

the Result looks like this :

move_to_another_table.png
 

eugenio

Administrator
Staff member
Very interesting use of hooks, I'll check more in details and maybe I'll add something similar in the official DaDaBIK release!
 
Top