Commit 106cab4a authored by Carsten  Rose's avatar Carsten Rose
Browse files

F6650 Report hide content (line) - use later via a variable. First version -...

F6650 Report hide content (line) - use later via a variable. First version - problem with enclosed ticks.
parent 190bd3ce
Pipeline #851 passed with stage
in 2 minutes and 5 seconds
......@@ -1292,11 +1292,15 @@ const TOKEN_FORM = CLIENT_FORM;
const TOKEN_RECORD_ID = CLIENT_RECORD_ID;
const TOKEN_DEBUG_BODYTEXT = TYPO3_DEBUG_SHOW_BODY_TEXT;
const TOKEN_DB_INDEX = F_DB_INDEX;
const TOKEN_CONTENT = 'content';
const TOKEN_VALID_LIST = 'sql|head|althead|altsql|tail|shead|stail|rbeg|rend|renr|rsep|fbeg|fend|fsep|rbgd|debug|form|r|debugShowBodyText|dbIndex|sqlLog|sqlLogMode';
const TOKEN_VALID_LIST = 'sql|head|althead|altsql|tail|shead|stail|rbeg|rend|renr|rsep|fbeg|fend|fsep|rbgd|debug|form|r|debugShowBodyText|dbIndex|sqlLog|sqlLogMode|content';
const TOKEN_COLUMN_CTRL = '_';
const TOKEN_CONTENT_STORE = 'store';
const TOKEN_CONTENT_HIDE = 'hide';
//Report: Column Token
const COLUMN_LINK = 'link';
const COLUMN_EXEC = 'exec';
......
......@@ -450,9 +450,9 @@ class Report {
// CurrentLevel "10.10.50"
if (isset($this->indexArray[$counter]) && is_array($this->indexArray[$counter])) {
$full_level = implode(".", $this->indexArray[$counter]);
$fullLevel = implode(".", $this->indexArray[$counter]);
} else {
$full_level = '';
$fullLevel = '';
}
// Superlevel "10.10"
......@@ -464,58 +464,59 @@ class Report {
//condition1: indexArray
//condition2: full_level == Superlevel (but at the length of the Superlevel)
while ($counter < count($this->indexArray) && $full_super_level == substr($full_level, 0, strlen($full_super_level))) {
while ($counter < count($this->indexArray) && $full_super_level == substr($fullLevel, 0, strlen($full_super_level))) {
$contentLevel = '';
//True: The cur_level is a subquery -> continue
if ($cur_level != count($this->indexArray[$counter])) {
++$counter;
if (isset($this->indexArray[$counter]) && is_array($this->indexArray[$counter])) {
$full_level = implode(".", $this->indexArray[$counter]);
$fullLevel = implode(".", $this->indexArray[$counter]);
} else {
$full_level = '';
$fullLevel = '';
}
continue;
}
// Set debug, if one is specified else keep the parent one.
$lineDebug = $this->getValueParentDefault(TOKEN_DEBUG, $full_super_level, $full_level, $cur_level, 0);
$lineDebug = $this->getValueParentDefault(TOKEN_DEBUG, $full_super_level, $fullLevel, $cur_level, 0);
// Prepare Error reporting
$this->store->setVar(SYSTEM_SQL_RAW, $this->frArray[$full_level . "." . TOKEN_SQL], STORE_SYSTEM);
$this->store->setVar(SYSTEM_REPORT_FULL_LEVEL, $full_level, STORE_SYSTEM);
$this->store->setVar(SYSTEM_SQL_RAW, $this->frArray[$fullLevel . "." . TOKEN_SQL], STORE_SYSTEM);
$this->store->setVar(SYSTEM_REPORT_FULL_LEVEL, $fullLevel, STORE_SYSTEM);
// Prepare SQL: replace variables. Actual 'line.total' or 'line.count' will recalculated: don't replace them now!
unset($this->variables->resultArray[$full_level . ".line."]["total"]);
unset($this->variables->resultArray[$full_level . ".line."]["count"]);
unset($this->variables->resultArray[$fullLevel . ".line."]["total"]);
unset($this->variables->resultArray[$fullLevel . ".line."]["count"]);
$sql = $this->variables->doVariables($this->frArray[$full_level . "." . TOKEN_SQL]);
$sql = $this->variables->doVariables($this->frArray[$fullLevel . "." . TOKEN_SQL]);
$this->store->setVar(SYSTEM_SQL_FINAL, $sql, STORE_SYSTEM);
//Execute SQL. All errors have been already catched.
//Execute SQL. All errors have been already catch'd.
unset($result);
$result = $this->db->sql($sql, ROW_KEYS, array(), '', $keys, $stat);
// If an array is returned, $sql was a query, otherwise an 'insert', 'update', 'delete', ...
// Query: total nummber of rows
// Query: total number of rows
// insert, delete, update: number of affected rows
$rowTotal = isset($stat[DB_NUM_ROWS]) ? $stat[DB_NUM_ROWS] : $stat[DB_AFFECTED_ROWS];
$this->variables->resultArray[$full_level . ".line."]["total"] = $rowTotal;
$this->variables->resultArray[$full_level . ".line."]["count"] = is_array($result) ? 1 : 0;
$this->variables->resultArray[$full_level . ".line."]["insertId"] = isset($stat[DB_INSERT_ID]) ? $stat[DB_INSERT_ID] : 0;
$this->variables->resultArray[$fullLevel . ".line."]["total"] = $rowTotal;
$this->variables->resultArray[$fullLevel . ".line."]["count"] = is_array($result) ? 1 : 0;
$this->variables->resultArray[$fullLevel . ".line."]["insertId"] = isset($stat[DB_INSERT_ID]) ? $stat[DB_INSERT_ID] : 0;
$content .= $this->variables->doVariables($this->frArray[$full_level . "." . TOKEN_SHEAD]);
$contentLevel .= $this->variables->doVariables($this->frArray[$fullLevel . "." . TOKEN_SHEAD]);
// HEAD: If there is at least one record, do 'head'.
if ($rowTotal > 0) {
$content .= $this->variables->doVariables($this->frArray[$full_level . "." . TOKEN_HEAD]);
$contentLevel .= $this->variables->doVariables($this->frArray[$fullLevel . "." . TOKEN_HEAD]);
}
if (is_array($result)) {
// Prepare row alteration
$arrRbgd = explode("|", $this->frArray[$full_level . "." . TOKEN_RBGD], 2);
$arrRbgd = explode("|", $this->frArray[$fullLevel . "." . TOKEN_RBGD], 2);
if (count($arrRbgd) < 2) {
$arrRbgd[] = '';
$arrRbgd[] = '';
......@@ -527,63 +528,84 @@ class Report {
$rowIndex = 0;
foreach ($result as $row) {
// record number counter
$this->variables->resultArray[$full_level . ".line."]["count"] = ++$rowIndex;
$this->variables->resultArray[$fullLevel . ".line."]["count"] = ++$rowIndex;
// replace {{<level>.line.count}} and {{<level>.line.total}} in __result__, if the variables specify their own full_level. This can't be replaced before firing the query.
for ($ii = 0; $ii < count($row); $ii++) {
$row[$ii] = str_replace("{{" . $full_level . ".line.count}}", $rowIndex, $row[$ii]);
$row[$ii] = str_replace("{{" . $full_level . ".line.total}}", $rowTotal, $row[$ii]);
$row[$ii] = str_replace("{{" . $fullLevel . ".line.count}}", $rowIndex, $row[$ii]);
$row[$ii] = str_replace("{{" . $fullLevel . ".line.total}}", $rowTotal, $row[$ii]);
}
// SEP set separator (empty on first run)
$content .= $columnValueSeparator;
$columnValueSeparator = $this->variables->doVariables($this->frArray[$full_level . "." . TOKEN_RSEP]);
$contentLevel .= $columnValueSeparator;
$columnValueSeparator = $this->variables->doVariables($this->frArray[$fullLevel . "." . TOKEN_RSEP]);
// RBEG
$rbeg = $this->variables->doVariables($this->frArray[$full_level . "." . TOKEN_RBEG]);
$rbeg = $this->variables->doVariables($this->frArray[$fullLevel . "." . TOKEN_RBEG]);
// RBGD: even/odd rows
$content .= str_replace(TOKEN_RBGD, $arrRbgd[$rowIndex % 2], $rbeg);
$contentLevel .= str_replace(TOKEN_RBGD, $arrRbgd[$rowIndex % 2], $rbeg);
//-----------------------------
// COLUMNS: Collect all columns
$content .= $this->collectRow($row, $keys, $full_level, $rowIndex);
$contentLevel .= $this->collectRow($row, $keys, $fullLevel, $rowIndex);
// REND
$content .= $this->variables->doVariables($this->frArray[$full_level . "." . TOKEN_REND]);
$contentLevel .= $this->variables->doVariables($this->frArray[$fullLevel . "." . TOKEN_REND]);
// Trigger subqueries of this level
$content .= $this->triggerReport($cur_level + 1, $this->indexArray[$counter], $counter + 1);
$contentLevel .= $this->triggerReport($cur_level + 1, $this->indexArray[$counter], $counter + 1);
// RENR
$content .= $this->variables->doVariables($this->frArray[$full_level . "." . TOKEN_RENR]);
$contentLevel .= $this->variables->doVariables($this->frArray[$fullLevel . "." . TOKEN_RENR]);
}
}
if ($rowTotal > 0) {
// tail
$content .= $this->variables->doVariables($this->frArray[$full_level . "." . TOKEN_TAIL]);
$contentLevel .= $this->variables->doVariables($this->frArray[$fullLevel . "." . TOKEN_TAIL]);
} else {
// althead
$content .= $this->variables->doVariables($this->frArray[$full_level . "." . TOKEN_ALT_HEAD]);
$contentLevel .= $this->variables->doVariables($this->frArray[$fullLevel . "." . TOKEN_ALT_HEAD]);
// altsql
$sql = $this->variables->doVariables($this->frArray[$full_level . "." . TOKEN_ALT_SQL]);
$sql = $this->variables->doVariables($this->frArray[$fullLevel . "." . TOKEN_ALT_SQL]);
if (!empty($sql)) {
$result = $this->db->sql($sql, ROW_KEYS, array(), '', $keys, $stat);
foreach ($result as $row) {
$rowIndex = 0;
$content .= $this->collectRow($row, $keys, $full_level, $rowIndex);
$contentLevel .= $this->collectRow($row, $keys, $fullLevel, $rowIndex);
}
}
}
$content .= $this->variables->doVariables($this->frArray[$full_level . "." . TOKEN_STAIL]);
$contentLevel .= $this->variables->doVariables($this->frArray[$fullLevel . "." . TOKEN_STAIL]);
$token = $this->frArray[$fullLevel . "." . TOKEN_CONTENT];
switch ($token) {
case TOKEN_CONTENT_HIDE:
$this->variables->resultArray[$fullLevel . ".line."][TOKEN_CONTENT] = $contentLevel;
$contentLevel = '';
break;
case TOKEN_CONTENT_STORE:
$this->variables->resultArray[$fullLevel . ".line."][TOKEN_CONTENT] = $contentLevel;
break;
case '':
break;
default:
throw new UserReportException ("Unknown token: $token in Line '$fullLevel''", ERROR_UNKNOWN_TOKEN);
break;
}
$content .= $contentLevel;
++$counter;
if (isset($this->indexArray[$counter]) && is_array($this->indexArray[$counter])) {
$full_level = implode(".", $this->indexArray[$counter]);
$fullLevel = implode(".", $this->indexArray[$counter]);
} else {
$full_level = '';
$fullLevel = '';
}
}
return $content;
......@@ -774,17 +796,17 @@ class Report {
case COLUMN_SAVE_PDF:
$tokenGiven = [];
$vars = $this->link->fillParameter($columnValue,$tokenGiven);
$vars = $this->link->fillParameter($columnValue, $tokenGiven);
$vars[DOWNLOAD_MODE] = DOWNLOAD_MODE_PDF;
$vars[SIP_DOWNLOAD_PARAMETER] = implode(PARAM_DELIMITER, $vars[NAME_COLLECT_ELEMENTS]);
// Save file with specified export filename
$pathFileName = $vars[DOWNLOAD_EXPORT_FILENAME];
$sanitizedFileName = Sanitize::safeFilename($pathFileName, false, true);
if($pathFileName == '' ||
if ($pathFileName == '' ||
substr($pathFileName, 0, strlen("fileadmin/")) !== "fileadmin/" ||
substr($pathFileName, -4) !== '.pdf') {
throw new UserReportException( "savePdf filenames need to be in the fileadmin/ directory and end in .pdf for security reasons.", ERROR_INVALID_SAVE_PDF_FILENAME);
throw new UserReportException("savePdf filenames need to be in the fileadmin/ directory and end in .pdf for security reasons.", ERROR_INVALID_SAVE_PDF_FILENAME);
} elseif ($pathFileName !== $sanitizedFileName) {
throw new UserReportException("The provided filename '$pathFileName' does not meet sanitize criteria. Use '$sanitizedFileName' instead.", ERROR_INVALID_SAVE_PDF_FILENAME);
} else {
......@@ -940,7 +962,7 @@ class Report {
$outerWrapStyle = "display:table; $extraOuterWrap";
$innerWrapStyle = "padding:50% 0; height:0;";
$style = "transform:rotate(" . $angle . "deg) translate$translate; margin-top:-50%; white-space:nowrap; transform-origin:0 0; height:0px;";
$content = Support::wrapTag("<div style='$style'>",$arr[0]);
$content = Support::wrapTag("<div style='$style'>", $arr[0]);
$content = Support::wrapTag("<div style='$innerWrapStyle'>", $content);
$content = Support::wrapTag("<div style='$outerWrapStyle'>", $content);
break;
......
......@@ -72,7 +72,6 @@ class Variables {
return '';
}
// $str = preg_replace_callback("/(~([a-zA-Z0-9._])*)/", array($this, 'replaceVariables'), $text);
// $str = preg_replace_callback("/{{(([a-zA-Z0-9.:_])*)}}/", array($this, 'replaceVariables'), $text);
// Process all {{x[.x].name}}
$str = preg_replace_callback('/{{\s*(([0-9]+.)+[a-zA-Z0-9_.]+)\s*}}/', array($this, 'replaceVariables'), $text);
......@@ -85,7 +84,7 @@ class Variables {
/**
* Callbackfunction called by variableSQL()
* Replaces the variablenames whith the value from the resultArray
* Replaces the variablenames with the value from the resultArray
*
* @param $matches
*
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment