Page 1 of 1

Quick way to customize the yourtablename.fieldname.csv file

Posted: 2013-06-22 04:31
by shasta59
Okay everyone.

Even though Calgary AB has been hit with massive flooding my area of town is ok. While out helping a few friends in the stricken area I had a bit of a brainstorm on how to give a quick way to create a csv file used with lookup values as found in the hooks folder. This method means you do not need to update the csv file then upload it. It is all handled for you in a separate table to which only admin or whomever you want has access.

This is based upon this example on the AppGini site but taken further.

http://www.bigprof.com/appgini/help/adv ... agic-files

Step 1:

Create a new table and call it what you wish but I call mine csvfiles
Fields are: (for example)

id
csv_file_contents_yourtablename
csv_file_contents_yourtablename2

Create as many fields as you need csv files created.

Then in the hook file for the table for which you need the csv file created put in the following code under both after insert and after update

Code: Select all

$csvFile='tablename.fieldname.csv';

	$fp=@fopen("$csvFile", "w");
	fwrite($fp, $data['your_field_name']);
	fclose($fp);
		return '';
The above code assumes only one field and therefore only one csv file to create. If you have many csv files to create then just setup a loop to enter all the correct filenames etc.

Or you could write one of the above for each filename.

This way you no longer have to edit the csv file and then upload it. You just enter the table, make your changes and it will overwrite the file for you. Only caution, the 'w' flag in the fopen command will overwrite the file each time.

Enjoy

Alan

Re: Quick way to customize the yourtablename.fieldname.csv f

Posted: 2013-06-22 05:53
by KSan
Great to hear you are not affected by the floods. Wishing all the best. Thanks for the shared code. As always, superb!!!

Re: Quick way to customize the yourtablename.fieldname.csv file

Posted: 2019-03-04 14:16
by fbrano
Where is problem in my code, when I want conditionally modify content of choices in field:

When existing record is open for modification in DV, list of options does not change according value in `Stav_pristupu`
When new record is added also I have to set value of list options to one choice = "ziadany"
Should it be somewhere else e.g. Pristupy_before_insert or Pristupy_dv?

function Pristupy_before_update(&$data, $memberInfo, &$args){

$csvFile='./hooks/Pristupy.stav_pristupu.csv';
$fp=@fopen("$csvFile", "w");
$aktualny_stav_pristupu = $data['Stav_pristupu'];
switch ($aktualny_stav_pristupu) {
case "ziadany":
fwrite($fp, "ziadany;;schvaleny;;zamietnuty");
break;
case "schvaleny":
fwrite($fp, "schvaleny;;aktivny");
break;
case "aktivny":
fwrite($fp, "aktivny;;zamknuty;;odoberany;;zruseny");
break;
case "zamknuty":
fwrite($fp, "aktivny;;zamknuty;;odoberany;;zruseny");
break;
case "odoberany":
fwrite($fp, "odoberany;;zruseny");
break;
case "zruseny":
fwrite($fp, "zruseny");
break;
default:
fwrite($fp, "ziadany");
}
fclose($fp);

return TRUE;
}