Skip to content

Commit

Permalink
NEW The conditional IF into ODT templates works also on not defined var
Browse files Browse the repository at this point in the history
so we can show data only if defined. Close #3819
  • Loading branch information
eldy committed Nov 2, 2015
1 parent c119859 commit d0d4c5e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
8 changes: 4 additions & 4 deletions htdocs/core/ajax/selectsearchbox.php
Expand Up @@ -99,14 +99,14 @@
$arrayresult['searchintosupplierpropal']=array('text'=>img_picto('','object_propal').' '.$langs->trans("SearchIntoSupplierProposals", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/askpricesupplier/list.php?sall='.urlencode($search_boxvalue));
}

if (! empty($conf->ficheinter->enabled) && empty($conf->global->MAIN_SEARCHFORM_FICHINTER_DISABLED) && $user->rights->ficheinter->lire)
{
$arrayresult['searchintointervention']=array('text'=>img_picto('','object_intervention').' '.$langs->trans("SearchIntoInterventions", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/fichinter/list.php?sall='.urlencode($search_boxvalue));
}
if (! empty($conf->contrat->enabled) && empty($conf->global->MAIN_SEARCHFORM_CONTRACT_DISABLED) && $user->rights->contrat->lire)
{
$arrayresult['searchintocontract']=array('text'=>img_picto('','object_contract').' '.$langs->trans("SearchIntoContracts", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/contrat/list.php?sall='.urlencode($search_boxvalue));
}
if (! empty($conf->ficheinter->enabled) && empty($conf->global->MAIN_SEARCHFORM_FICHINTER_DISABLED) && $user->rights->ficheinter->lire)
{
$arrayresult['searchintointervention']=array('text'=>img_picto('','object_intervention').' '.$langs->trans("SearchIntoInterventions", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/fichinter/list.php?sall='.urlencode($search_boxvalue));
}
if (! empty($conf->expensereport->enabled) && empty($conf->global->MAIN_SEARCHFORM_EXPENSEREPORT_DISABLED) && $user->rights->expensereport->lire)
{
$arrayresult['searchintoexpensereport']=array('text'=>img_picto('','object_trip').' '.$langs->trans("SearchIntoExpenseReports", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/expensereport/list.php?sall='.urlencode($search_boxvalue));
Expand Down
17 changes: 15 additions & 2 deletions htdocs/includes/odtphp/odf.php
Expand Up @@ -283,12 +283,25 @@ private function _moveRowSegments()
*/
private function _parse($type='content')
{
// Search all tags fou into condition to complete $this->vars, so we will proceed all tests even if not defined
$reg='@\[!--\sIF\s([{}a-zA-Z_]+)\s--\]@smU';
preg_match_all($reg, $this->contentXml, $matches, PREG_SET_ORDER);
//var_dump($this->vars);exit;
foreach($matches as $match) // For each match, if there is no entry into this->vars, we add it
{
if (! empty($match[1]) && ! isset($this->vars[$match[1]]))
{
$this->vars[$match[1]] = ''; // Not defined, so we set it to '', we just need entry into this->vars for next loop
}
}
//var_dump($this->vars);exit;

// Conditionals substitution
// Note: must be done before static substitution, else the variable will be replaced by its value and the conditional won't work anymore
foreach($this->vars as $key => $value)
foreach($this->vars as $key => $value)
{
// If value is true (not 0 nor false nor null nor empty string)
if($value)
if ($value)
{
// Remove the IF tag
$this->contentXml = str_replace('[!-- IF '.$key.' --]', '', $this->contentXml);
Expand Down

0 comments on commit d0d4c5e

Please sign in to comment.