Page 1 of 1

table view - data decryption

Posted: 2018-07-15 13:22
by G Scott
I have a table with 8 columns, 3 of these columns contain encrypted data.
I wish to display the data in a decrypted format in the Table View.

I've been trying to do this using the table_init hook to no avail.

Basically, I need to run the data in the 3 encrypted columns through a php function before it is displayed in the table view.

Can anyone help me?
My php decrypt function looks like:

Code: Select all

decrypt($data_to_decrypt, $key);
Column names to decrypt are ColumnB, ColumnC, ColumnD.

I just can't figure out how this can be done.

Re: table view - data decryption

Posted: 2018-07-16 10:23
by pbottcher
Hi,

I cannot provide a solution via a hook, but if you want, you can try the following. (Remeber that the changes will be overwritten when you recreate your project.)

Edit the template/<tablename>_templateTV.html

replace
<td id="<tablename>-ColumnB-<%%VALUE(ID)%%>" class="<tablename>-ColumnB"><%%SELECT%%><%%VALUE(ColumnB)%%><%%ENDSELECT%%></td>
<td id="<tablename>-ColumnC-<%%VALUE(ID)%%>" class="<tablename>-ColumnC"><%%SELECT%%><%%VALUE(ColumnC)%%><%%ENDSELECT%%></td>
<td id="<tablename>-ColumnD-<%%VALUE(ID)%%>" class="<tablename>-ColumnD"><%%SELECT%%><%%VALUE(ColumnD)%%><%%ENDSELECT%%></td>

by
<td id="<tablename>-ColumnB-<%%VALUE(ID)%%>" class="<tablename>-ColumnB"><%%SELECT%%><%%DECRYPT(ColumnB)%%><%%ENDSELECT%%></td>
<td id="<tablename>-ColumnC-<%%VALUE(ID)%%>" class="<tablename>-ColumnC"><%%SELECT%%><%%DECRYPT(ColumnC)%%><%%ENDSELECT%%></td>
<td id="<tablename>-ColumnD-<%%VALUE(ID)%%>" class="<tablename>-ColumnD"><%%SELECT%%><%%DECRYPT(ColumnD)%%><%%ENDSELECT%%></td>

Then edit the datalist.php, search for %%VALUE(Field caption)%% and add an additional like

$rowTemp = str_replace("<%%DECRYPT($fieldTVCaption)%%>", <YOURFUNCTION>($fd), $rowTemp);

recplace <tablename> with your tablename and <YOURFUNCTION> with your function. Make sure your function is available at the time you call it.

Re: table view - data decryption

Posted: 2018-07-16 20:55
by G Scott
Hi pböttcher,

Thanks for your help, I'm having trouble including the files for the function to work.

I.e. I placed the following code on line 16 of datalist.php

Code: Select all

require_once($curr_dir . '/encryption.class.php');
I also tried placing the code on line 21 of common.js.php and changing require_once to include_once.

I've placed the file encryption.class.php in the root folder of my project.
Whenever I try to access that table in the web browser, I get a 500 server error however no event is logged in the server error log.

At this point I have not tried to call the function within datalist.php, just merely tried to include the function files.

Do you have any suggestions on how I can make the code for the function available?

Many thanks for your help,

Grant

Re: table view - data decryption

Posted: 2018-07-16 22:10
by G Scott
Hi pböttcher,

Please ignore the last post, I was getting the error because I had already included the function elsewhere in the project so the class was already declared...

I do have one more question though, when I select a record and the detail view is displayed, how could I decrypt those fields when on the detail view form?

Many thanks,
Grant

Re: table view - data decryption

Posted: 2018-07-17 06:07
by pbottcher
Hi,

you can use the hooks/<tablename>.php -> <tablename>_dv function to replace the text with the decryptet text.