Skip to content

Commit

Permalink
v4.1.3 release
Browse files Browse the repository at this point in the history
  • Loading branch information
bcchr dev team committed Jun 5, 2024
1 parent 090cd8e commit fa1c573
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 23 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
vendor/
*.zip
error_log
*.xml

35 changes: 24 additions & 11 deletions CustomTemplateEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,21 @@ public function setPaths() {
$this->temp_dir = $this->getSystemSetting("temp-folder");
$this->img_dir = $this->getSystemSetting("img-folder");
$this->pid = $this->getProjectId();
$this->redcap_data_table = \REDCap::getDataTable($this->pid);
/*
** check REDCap version of the server; versions before v14 only have a single data table and no
** getDataTable() function, which returns -1 if first < second, 0 if equal, 1 otherwise
*/

if ( \REDCap::versionCompare(REDCAP_VERSION, '14.0.0') == -1) { // pre v14, so only a single table an no function to call

$this->redcap_data_table = 'redcap_data';

} else { // use REDCap::getDataTable() function to check if there may be other redcap_data tables

$this->redcap_data_table = \REDCap::getDataTable($this->pid);
// REDCap::logEvent('version is ' . REDCAP_VERSION . ' compare check is ' . \REDCap::versionCompare(REDCAP_VERSION, '14.0.0'));

} // end if

if (!empty($this->pid)) {

Expand Down Expand Up @@ -970,8 +984,9 @@ public function saveTemplate()
else
{
// Validate Template
$template = new Template($this->templates_dir, $this->compiled_dir);

// $template = new Template($this->templates_dir, $this->compiled_dir);
$template = new Template();
$template->setPaths($this->templates_dir, $this->compiled_dir);
$template_errors = $template->validateTemplate($data);
$header_errors = $template->validateTemplate($header);
$footer_errors = $template->validateTemplate($footer);
Expand Down Expand Up @@ -1200,7 +1215,9 @@ public function batchFillReports()
// $records = htmlspecialchars($_POST["participantID"], ENT_QUOTES);
$records = array_map('htmlspecialchars', $_POST["participantID"], array(ENT_QUOTES));
$template_filename = htmlspecialchars($_POST['template'], ENT_QUOTES);
$template = new Template($this->templates_dir, $this->compiled_dir);
// $template = new Template($this->templates_dir, $this->compiled_dir);
$template = new Template();
$template->setPaths($this->templates_dir, $this->compiled_dir);

$zip_name = "{$this->temp_dir}reports.zip";
$z = new ZipArchive();
Expand Down Expand Up @@ -1306,12 +1323,6 @@ public function batchFillReports()
header('Content-Type: application/zip;\n');
header("Content-Transfer-Encoding: Binary");
header("Content-Disposition: attachment; filename=\"".basename($zip_name)."\"");
/*
header('Content-Description: File Transfer');
header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename="'.basename($zip_name).'"');
header('Content-length: '.filesize($zip_name));
*/
readfile($zip_name);
REDCap::logEvent("Custom Template Engine - Downloaded Reports ", $template_filename , "" , implode(", ", $records));
}
Expand Down Expand Up @@ -1369,7 +1380,9 @@ public function generateFillTemplatePage()
}

$template_filename = $_POST['template'];
$template = new Template($this->templates_dir, $this->compiled_dir);
//$template = new Template($this->templates_dir, $this->compiled_dir);
$template = new Template();
$template->setPaths($this->templates_dir, $this->compiled_dir);

try
{
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ The module users the PHP template engine, Smarty, to fill in the templates with
WARNING: This module is not currently able to support REDCap instances using load balancers due to the requirement to save templates to the file system.

## Changelog
* v4.1.1
* v4.1.3
* upgraded packages to address security isues:
* smarty/smarty (v5.1.0 => v5.3.0)
* backward compatibility fix for pre v14 versions of REDCap (without access to getDataTables() function)
* bug fix for Smarty "class not found" during template creation; implemented lazy loading.
* v4.1.2
* Basic date formatting through Smarty; can format with dd-mm-yyyy formatting by passing formatting information through the template as ```{$redcap['visit_date']|date_format:'%d-%m-%Y'}``` This will format the visit_date into two digit day, two digit month, four digit year. **Please note**: this is currently the only other format allowed outside the default REDCap display.
* Added code to process the new format returned by REDCap::getUserRightsdata()
* Fixed bug found when downloading a zip file of batched reports (modified headers set before download)
Expand All @@ -60,7 +65,6 @@ WARNING: This module is not currently able to support REDCap instances using lo
* smarty/smarty (v4.3.4 => v5.1.0)
* New packages installed per upgrades above:
* polyfill-mbstring (v1.29.0)

* v4.0.0
* Minimal REDCap version is v12.4
* Implemented support for the RC v12.4+ instrument-level data export permissions.
Expand Down
16 changes: 15 additions & 1 deletion Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
require_once "vendor/autoload.php";

use REDCap;
use Smarty;
use Smarty\Smarty;
use DOMDocument;
require_once "./ExportRights.php"; // class to manage instrument-level rights

Expand Down Expand Up @@ -43,6 +43,7 @@ class Template
* @param String $templates_dir Directory where templates are stored.
* @param String $compiled_dir Directory where templates compiled by Smarty are stored.
*/
/*
function __construct($templates_dir, $compiled_dir)
{
$this->dictionary = REDCap::getDataDictionary('array', false);
Expand All @@ -52,7 +53,20 @@ function __construct($templates_dir, $compiled_dir)
$this->smarty->setCompileDir($compiled_dir);
$this->smarty->assign("showLabelAndRow", $this->show_label_and_row);
}
*/
public function setPaths($templates_dir, $compiled_dir) {
/*
**lazy loading to avoid the constructor, for the EM framework recommendations
*/
$this->dictionary = REDCap::getDataDictionary('array', false);
$this->instruments = REDCap::getInstrumentNames();
$this->smarty = new Smarty();
$this->smarty->setTemplateDir($templates_dir);
$this->smarty->setCompileDir($compiled_dir);
$this->smarty->assign("showLabelAndRow", $this->show_label_and_row);

} // end setPaths()

/**
* Checks whether all the siblings that come before or after an html element are empty
*
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"require": {
"ckeditor/ckeditor": "dev-full/4.21.x",
"dompdf/dompdf": ">=2.0.5",
"smarty/smarty": ">=4.5.2"
"dompdf/dompdf": ">=3",
"smarty/smarty": ">=5.3.0"
},
"config": {
"platform": {
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fa1c573

Please sign in to comment.