Authorized PHP code before php_output.php
I need to install and run the PHPspreadsheet library to send a list of registrants in an attached Xlsx (Excel) file. This feature existed natively in Chronoform5.
So I installed version 1.30.1 of the phpoffice/phpspreadsheet library (supported by php 7.4.33) Then I created a PHP element in the Submit section of the form setup, positioned after the creation of a CSV file to load the class names of the library functions, to initiate the reading of the CSV file, convert it, and then save it in a compatible Xlsx format.
I don't have any error messages in the Debug consoles (chronoform + Joomla simple Debug), but the Xlsx file is not created. Is this a scope or filtering issue with php_output.php?
JLoader::registerNamespace('PhpOffice', JPATH_ROOT.'/vendor/phpoffice');
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Reader\Csv;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
$spreadsheet = new Spreadsheet();
$reader = new Csv();
/* Set CSV parsing options */
$reader->setDelimiter(',');
$reader->setEnclosure('"');
$reader->setSheetIndex(0);
/* Load a CSV file and save as a XLS */
$spreadsheet = $reader->load('../../exports/csv/file.csv');
$writer = new Xlsx($spreadsheet);
$writer->save('../../exports/xlsx/file.xlsx');
$spreadsheet->disconnectWorksheets();
unset($spreadsheet);
Hi
Do you get any PHP errors on the page ? if not then no errors have occurred.
And are you sure this XLSX library work on your PHP version ?
Thank you Max for your interest in my question.
In fact, I started the script with the php require instruction and received this single error opening the autoload.php file located in the wrong vendor directory where the library is installed at the root of the Joomla installation directory.
Warning: require(../vendor/autoload.php): failed to open stream: No such file or directory in /var/www/vhosts/studiojb.com/clients/mcr/html_testv16/libraries/cegcore2/admin/extensions/chronofc/functions/php/php_output.php(6) : eval()'d code on line 1
But I also tried the following in turn:
JLoader::registerNamespace(‘PhpOffice’, ‘vendor/phpoffice’);
and
require ‘vendor/autoload.php’;
And I got the same result: no PHP error but no Xlsx file saved
The library structure is as follows (see attached file)
Joomla
|__ vendor
|__ autoload.php
|__ phpoffice
|__ phpspreadsheet
Version 1.30.1 of the PHPspreadsheet library installed by Composer corresponds to PHP version 7.4.33 on the site where it was installed.
In the composer.json file (in joomla root), I have:
"require": { "phpoffice/phpspreadsheet": "^1.30" }
And in the composer.lock file(in joomla root), I have:
"name": "phpoffice/phpspreadsheet", "version": "1.30.1",
"source": {
"type": "git",
"url": "https://github.com/PHPOffice/PhpSpreadsheet.git",
"reference": "fa8257a579ec623473eabfe49731de5967306c4c"},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/PHPOffice/PhpSpreadsheet/zipball/fa8257a579ec623473eabfe49731de5967306c4c",
"reference": "fa8257a579ec623473eabfe49731de5967306c4c",
"shasum": ""},
...
Hi Max, i forgot to mention that when I turn on PHP v8.2.29, I receive this error on all pages of the site:
0
Call to undefined function get_magic_quotes_gpc()
Call stack#
Function Location1
() JROOT/libraries/cegcore2/gcloader.php:63
Line 63:
if(get_magic_quotes_gpc()){
function stripslashes_gpc(&$value){
$value = stripslashes($value);
}
array_walk_recursive($_GET, 'stripslashes_gpc');
array_walk_recursive($_POST, 'stripslashes_gpc');
array_walk_recursive($_COOKIE, 'stripslashes_gpc');
array_walk_recursive($_REQUEST, 'stripslashes_gpc');
}
Hi Max. Do I need to disable the ChronoengineGcore2 plugin and certain components/plugins/packages of Chronoform 5 before upgrading to PHP 8.2?
My configuration
Joomla! 3.10.12
PHP 7.4.33
Components:
Nom Emplacement Type Version Date Auteur Dossier ID du paquet
ChronoengineGcore2 Site Plug-in 1.0 2017 chronoengine.com system 10215 10214
ChronoForms5 Administration Composant 5.0.17 May 2018 ChronoEngine.com N/A 10031
ChronoForms5 Site Module V5 RC1.2 December 2013 ChronoEngine.com N/A 10033
Chronoforms5 Site Plug-in V5.0 08.Dec.2013 ChronoEngine.com content 10034
ChronoForms5 Package Site Paquet V5.0 2016 ChronoEngine.com Team N/A 10032
ChronoForms6 Administration Composant 6.1.4 June 2019 Chronoman N/A 10215 10213
ChronoForms6 Site Module v6.0.1 April 2017 ChronoEngine.com N/A 10216
ChronoForms6 Package Site Paquet 6.1.2 May 2019 ChronoEngine.com Team N/A
Hi studiojb
I think that if you update php to 8.2 then you better use ChronoForms v8 because earlier versions WILL have different issues and limits, otherwise you can stay on an earlier PHP
And if you update then you can disable or uninstall earlier ChronoForms but you need to keep a backup of your forms and make sure they can work correctly on the new version, v8 can import v6 and v7 forms but not "completely", some things will need to be remade.
if you do not receive error messages then the file should be created, did you check the correct path ?
Thanks Max for all these details.
My problem is that there is no native Xls file export in C8, just as there isn't in C6. I have already installed C8 on Joomla 4 and searched in vain for a way to do this without finding it.
The problem I have with the lack of Xls file export in C6 will not be solved in C8, unless I've missed something.
If this feature existed natively in C8, I wouldn't even bother going through C6 as an intermediate step to redo the forms that worked in C5.
That's why I'm trying to do it with the PHPSpreadSheet library for C6, as I would have done for C8, since ultimately it will have to work in C8.
Good evening Max,
Thank you for pointing me towards the solution.
The constant defined in the variable {path:front} cannot be interpreted in the PHP code because of the php_output.php parser.
So the files were neither loaded nor converted...
Now it works like a charm ;-)
I think my post can be marked as resolved!
But don't know how to do this.
defined('_JEXEC') or die;
// Load PHPSpreadSheet Library
require "vendor/autoload.php";
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Reader\Csv;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
// Create SpreadSheet + CSV Instances
$spreadsheet = new Spreadsheet();
$reader = new Csv();
// Define File Path
$filepath="components/com_chronoforms6/chronoforms/exports/";
// Set CSV parsing options
$reader->setDelimiter(',');
$reader->setEnclosure('"');
$reader->setSheetIndex(0);
// Load CSV file and save as XLS
$spreadsheet = $reader->load($filepath."file.csv");
$writer = new Xlsx($spreadsheet);
$writer->save($filepath."file.xlsx");
// Close SpreadSheet & Library
$spreadsheet->disconnectWorksheets();
unset($spreadsheet);
Hi studiojb
Great news, and yes, using shortcodes in PHP will not work, you need to use the PHP version of the shortcode.
Regarding the XLSX export, we support CSV export which I think is enough for most use cases, if XLSX is needed then that's usually rare and it requires a heavy library and can not be included in the default installer.
Hello Max, thank you for your reply and your help.
I understand that the CSV solution suits most people, as it would suit me too if my clients weren't used to receiving Xls files.
It provides an alternative for those who, for example, don't want to use Google Sheets (in C8).
But yes, this library is quite large at ~8MB.
To obtain {path:front} in PHP, should I add this line?
$pathroot=$this->get(“path”, “front”);
Is this list of shortcodes valid for Chronoform 6?
Thank you in advance.
Otherwise, Chronoform always surprises me with its modularity.
No problem.
This is the shortcodes list for v8:
https://www.chronoengine.com/faqs/chronoforms/chronoforms8/chronoforms-shortcodes
For getting path front in PHP you need:
$this->front_path
Thank you, Max.
But it seems that
$this->front_path
does not work with C6, only with C8.
I cannot find the variable in C6.
I'm not sure if that was available for v6, I suggest that you use v8 whenever you can :)
yes Max, it's the goal!
