Custom csv formatting

Hello,
the standard csv-Export-option inside of Dadabik creates a csv-File in which all entries are surrounded with quotes. Is it possible to change this format? For our export file we need to prevent quotes.
Is it also possible to create a custom export-file, e.g. in Excel-format? We have established an own Excel-Export but only with an own php-file with custom database-queries independent from Dadabik which is a security issue. We had to comment-out the line

if(!defined('custom_page_from_inclusion')) { die(); }

because if we didn't we got some xls-formatting issues. In that case additional html-source-code of the page was added to the excel-file that made it unreadable.

Thank you in advance
Andreas

You are using DaDaBIK version 8.1-Lerici enterprise, installed on 10-01-2017 (installation code: 124685910a21b35192), the latest version of DaDaBIK is 8.1-Lerici released on 09-05-2017
You are runnning the last release of DaDaBIK
PHP Version: 5.5.30
mysql version: 5.6.19-67.0-log
Web server: Apache
Client: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:57.0) Gecko/20100101 Firefox/57.0
 

eugenio

Administrator
Staff member
Hello,
the function that is responsible for creating the CSV is build_csv() in /include/business_logic.php

You can edit that function if you don't like the format; In particular, if you want to remove quotes, you should work on these lines:

// this line creates the header
$csv .= "\"".str_replace("\"", "\"\"", $fields_labels_ar[$i]["label_field"])."\"".$csv_separator;

// this line adds the opening quote to a field
$csv .= "\"";

// this line adds the closing quote + the separator
$csv .= "\"".$csv_separator;

Please note, however, that the quotes produced by DaDaBIK are useful if you want to produce a valid CSV, in particular if your fields contain line-breaks, double-quotes or commas.

I am not sure if I have understood your last question, you have created a custom DaDaBIK PHP page that exports a CSV ? I don't think it is possible that the line:
if(!defined('custom_page_from_inclusion')) { die(); }
affects the output; it's a security check, it checks if the page has been called from inside DaDaBIK or not.

Best,
 
Hi Eugenio,

thank you for your reply and the hints for csv-formatting.
I created a text-link on a custom page that calls a php-page "export.php" where the xls-file is created. The "export.php" calls a function from another php-file "php-excel.class.php" where the magic happens.
If I use the line
if(!defined('custom_page_from_inclusion')) { die(); }
the produced xls-file contains html-tags from the page source generated by dadabik. If I comment it out the resulting xls-file is OK, but as I mentioned, this is very unsecure.
Any idea what could cause the unwanted html?

Best wishes and thanks in advance
Andreas
 

eugenio

Administrator
Staff member
Hello,
I still don't understand how that can happen, that line just stops the execution of the script if the script is executed outside DaDaBIK.

How the export.php file is called?
 
The xport.php file is called via a link with href="/include/custom_php_files/export.php".
Inside of export.php the file "php-excel.class.php", where the excel-generation is made is loaded with "require" at the beginning.
After that the DB-connection is made and the fields to export are collected. At the end a new "Excel_XML" class is created and processed by the php-excel.class.php.

Best wishes
Andreas
 

eugenio

Administrator
Staff member
Ok, so the export.php file is the custom php file itself. I confirm that that line cannot impact on the HTML generated. Did you change in any way the DaDaBIK code (except from config.php and custom functions / files)?
If you didn't change anything, what I can guess is that when you add that line you are also adding by mistake some additional (maybe invisible) characters out of the php tags?
 
Hi Eugenio,
I just realized that I haven't closed this topic yet, sorry for the late reply.
Everything's fine now, I have overlooked a change I made.
Best wishes
Andreas
 
Top