From a49af456ce207a8ca8124de17366368a2f3fd62a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 3 Jan 2022 04:47:17 +0100 Subject: [PATCH] Debug page customreports.php --- htdocs/comm/action/index.php | 3 +- htdocs/core/class/html.form.class.php | 5 +- htdocs/core/customreports.php | 83 +++++++++++++++++++-------- 3 files changed, 64 insertions(+), 27 deletions(-) diff --git a/htdocs/comm/action/index.php b/htdocs/comm/action/index.php index b139b222fa2..93b235a37da 100644 --- a/htdocs/comm/action/index.php +++ b/htdocs/comm/action/index.php @@ -629,8 +629,7 @@ if (!empty($conf->use_javascript_ajax)) { // If javascript on } $s .= "\n".''."\n"; -} else // If javascript off -{ +} else { // If javascript off $newparam = $param; // newparam is for birthday links $newparam = preg_replace('/showbirthday=[0-1]/i', 'showbirthday='.(empty($showbirthday) ? 1 : 0), $newparam); if (!preg_match('/showbirthday=/i', $newparam)) { diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 8b7b3a78049..89c45d4236b 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -9646,9 +9646,10 @@ class Form * @param array $arrayofcriterias Array of available search criterias. Example: array($object->element => $object->fields, 'otherfamily' => otherarrayoffields, ...) * @param array $search_component_params Array of selected search criterias * @param array $arrayofinputfieldsalreadyoutput Array of input fields already inform. The component will not generate a hidden input field if it is in this list. + * @param string $search_component_params_hidden String with $search_component_params criterias * @return string HTML component for advanced search */ - public function searchComponent($arrayofcriterias, $search_component_params, $arrayofinputfieldsalreadyoutput = array()) + public function searchComponent($arrayofcriterias, $search_component_params, $arrayofinputfieldsalreadyoutput = array(), $search_component_params_hidden = '') { global $langs; @@ -9670,7 +9671,7 @@ class Form if (GETPOST('show_search_component_params_hidden', 'int')) { $ret .= ''; } - $ret .= ''; + $ret .= ''; // For compatibility with forms that show themself the search criteria in addition of this component, we output the fields foreach ($arrayofcriterias as $criterias) { diff --git a/htdocs/core/customreports.php b/htdocs/core/customreports.php index 00258ba7d09..e380dea8403 100644 --- a/htdocs/core/customreports.php +++ b/htdocs/core/customreports.php @@ -40,7 +40,6 @@ if (!defined('USE_CUSTOM_REPORT_AS_INCLUDE')) { $objecttype = 'thirdparty'; } - $search_filters = GETPOST('search_filters', 'array'); $search_measures = GETPOST('search_measures', 'array'); //$search_xaxis = GETPOST('search_xaxis', 'array'); @@ -158,6 +157,7 @@ $extrafields->fetch_name_optionals_label($object->table_element); $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); $search_component_params = array(''); +$search_component_params_hidden = GETPOST('search_component_params_hidden', 'alphanohtml'); $MAXUNIQUEVALFORGROUP = 20; $MAXMEASURESINBARGRAPH = 20; @@ -175,14 +175,16 @@ $arrayofgroupby = array(); $arrayofyaxis = array(); $arrayofvaluesforgroupby = array(); -$result = restrictedArea($user, $object->element, 0, ''); +restrictedArea($user, $object->element, 0, ''); + +$error = 0; /* * Actions */ - +// None @@ -245,8 +247,19 @@ if (is_array($search_groupby) && count($search_groupby)) { } else { $sql .= ' FROM '.MAIN_DB_PREFIX.$object->table_element.' as t'; } - // TODO Add the where here - // ... + + // Add the where here + /* + $sqlfilters = GETPOST('search_component_params_hidden', 'alphanohtml'); + if ($sqlfilters) { + $errormessage = ''; + if (dolCheckFilters($sqlfilters, $errormessage)) { + $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)'; + $sql .= " WHERE (".preg_replace_callback('/'.$regexstring.'/', 'dolForgeCriteriaCallback', $sqlfilters).")"; + } else { + print $errormessage; + } + }*/ $sql .= ' LIMIT '.($MAXUNIQUEVALFORGROUP + 1); @@ -333,6 +346,24 @@ print ''; print ''; print ''; +$viewmode = ''; + +$viewmode .= '
'; +$arrayofgraphs = array('bars' => 'Bars', 'lines' => 'Lines'); // also 'pies' +$viewmode .= '
'.$langs->trans("Graph").'
'; +$viewmode .= $form->selectarray('search_graph', $arrayofgraphs, $search_graph, 0, 0, 0, 'minwidth100', 1); +$viewmode .= '
'; + +$num = 0; +$massactionbutton = ''; +$nav = ''; +$newcardbutton = ''; +$limit = 0; + +print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, -1, 'object_action', 0, $nav.''.$newcardbutton, '', $limit, 1, 0, 1, $viewmode); + + + print '
'; // Select object @@ -351,20 +382,21 @@ print $form->selectarray('objecttype', $newarrayoftype, $objecttype, 0, 0, 0, '' if (empty($conf->use_javascript_ajax)) { print ''; } else { - print ''; } print '
'; -// Add Filter +// Add Filter (you can use param &show_search_component_params_hidden=1 for debug) print '
'; -print $form->searchComponent(array($object->element => $object->fields), $search_component_params); +print $form->searchComponent(array($object->element => $object->fields), $search_component_params, array(), $search_component_params_hidden); print '
'; // Add measures into array @@ -393,13 +425,6 @@ print $form->multiselectarray('search_measures', $arrayofmesures, $search_measur print ''; -// Group by -print '
'; -print '
'.$langs->trans("GroupBy").'
'; -print $formother->selectGroupByField($object, $search_groupby, $arrayofgroupby); -print '
'; - - // XAxis print '
'; print '
'.$langs->trans("XAxis").'
'; @@ -407,6 +432,13 @@ print $formother->selectXAxisField($object, $search_xaxis, $arrayofxaxis); print '
'; +// Group by +print '
'; +print '
'.$langs->trans("GroupBy").'
'; +print $formother->selectGroupByField($object, $search_groupby, $arrayofgroupby); +print '
'; + + if ($mode == 'grid') { // YAxis print '
'; @@ -449,12 +481,9 @@ if ($mode == 'grid') { } if ($mode == 'graph') { - print '
'; - $arrayofgraphs = array('bars' => 'Bars', 'lines' => 'Lines'); // also 'pies' - print '
'.$langs->trans("Graph").'
'; - print $form->selectarray('search_graph', $arrayofgraphs, $search_graph, 0, 0, 0, 'minwidth100', 1); - print '
'; + // } + print '
'; print ''; print '
'; @@ -531,8 +560,16 @@ if (!empty($search_measures) && !empty($search_xaxis)) { if ($object->ismultientitymanaged == 1) { $sql .= ' AND entity IN ('.getEntity($object->element).')'; } - foreach ($search_filters as $key => $val) { - // TODO Add the where here + // Add the where here + $sqlfilters = GETPOST('search_component_params_hidden', 'alphanohtml'); + if ($sqlfilters) { + $errormessage = ''; + if (dolCheckFilters($sqlfilters, $errormessage)) { + $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)'; + $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'dolForgeCriteriaCallback', $sqlfilters).")"; + } else { + print $errormessage; + } } $sql .= ' GROUP BY '; foreach ($search_xaxis as $key => $val) {