NEW The conditional IF into ODT templates works also on not defined var

so we can show data only if defined. Close #3819
This commit is contained in:
Laurent Destailleur 2015-11-02 15:44:15 +01:00
parent c119859696
commit d0d4c5e7f8
2 changed files with 19 additions and 6 deletions

View File

@ -99,14 +99,14 @@ if (! empty($conf->askpricesupplier->enabled) && empty($conf->global->MAIN_SEARC
$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));

View File

@ -283,12 +283,25 @@ IMG;
*/
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);