Debug page customreports.php

This commit is contained in:
Laurent Destailleur 2022-01-03 04:47:17 +01:00
parent ce05130384
commit a49af456ce
3 changed files with 64 additions and 27 deletions

View File

@ -629,8 +629,7 @@ if (!empty($conf->use_javascript_ajax)) { // If javascript on
}
$s .= "\n".'<!-- End div to calendars selectors -->'."\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)) {

View File

@ -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 .= '<input type="hidden" name="show_search_component_params_hidden" value="1">';
}
$ret .= '<input type="'.(GETPOST('show_search_component_params_hidden', 'int') ? 'text' : 'hidden').'" name="search_component_params_hidden" class="search_component_params_hidden marginleftonly" value="'.GETPOST("search_component_params_hidden").'">';
$ret .= '<input type="'.(GETPOST('show_search_component_params_hidden', 'int') ? 'text' : 'hidden').'" name="search_component_params_hidden" class="search_component_params_hidden marginleftonly" value="'.$search_component_params_hidden.'">';
// For compatibility with forms that show themself the search criteria in addition of this component, we output the fields
foreach ($arrayofcriterias as $criterias) {

View File

@ -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 '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="viewgraph">';
print '<input type="hidden" name="tabfamily" value="'.$tabfamily.'">';
$viewmode = '';
$viewmode .= '<div class="divadvancedsearchfield">';
$arrayofgraphs = array('bars' => 'Bars', 'lines' => 'Lines'); // also 'pies'
$viewmode .= '<div class="inline-block opacitymedium"><span class="fas fa-chart-area paddingright" title="'.$langs->trans("Graph").'"></span>'.$langs->trans("Graph").'</div> ';
$viewmode .= $form->selectarray('search_graph', $arrayofgraphs, $search_graph, 0, 0, 0, 'minwidth100', 1);
$viewmode .= '</div>';
$num = 0;
$massactionbutton = '';
$nav = '';
$newcardbutton = '';
$limit = 0;
print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, -1, 'object_action', 0, $nav.'<span class="marginleftonly"></span>'.$newcardbutton, '', $limit, 1, 0, 1, $viewmode);
print '<div class="liste_titre liste_titre_bydiv centpercent">';
// Select object
@ -351,20 +382,21 @@ print $form->selectarray('objecttype', $newarrayoftype, $objecttype, 0, 0, 0, ''
if (empty($conf->use_javascript_ajax)) {
print '<input type="submit" class="button buttongen button-save nomargintop" name="changeobjecttype" value="'.$langs->trans("Refresh").'">';
} else {
print '<script type="text/javascript">
print '<!-- js code to reload page with good object type -->
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery("#objecttype").change(function() {
console.log("Reload for "+jQuery("#objecttype").val());
location.href = "'.$_SERVER["PHP_SELF"].'?objecttype="+jQuery("#objecttype").val()+"'.($tabfamily ? '&tabfamily='.$tabfamily : '').'";
location.href = "'.$_SERVER["PHP_SELF"].'?objecttype="+jQuery("#objecttype").val()+"'.($tabfamily ? '&tabfamily='.urlencode($tabfamily) : '').(GETPOST('show_search_component_params_hidden', 'int') ? '&show_search_component_params_hidden='.((int) GETPOST('show_search_component_params_hidden', 'int')) : '').'";
});
});
</script>';
}
print '</div><div class="clearboth"></div>';
// Add Filter
// Add Filter (you can use param &show_search_component_params_hidden=1 for debug)
print '<div class="divadvancedsearchfield quatrevingtpercent">';
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 '</div>';
// Add measures into array
@ -393,13 +425,6 @@ print $form->multiselectarray('search_measures', $arrayofmesures, $search_measur
print '</div>';
// Group by
print '<div class="divadvancedsearchfield">';
print '<div class="inline-block opacitymedium"><span class="fas fa-ruler-horizontal paddingright" title="'.$langs->trans("GroupBy").'"></span>'.$langs->trans("GroupBy").'</div> ';
print $formother->selectGroupByField($object, $search_groupby, $arrayofgroupby);
print '</div>';
// XAxis
print '<div class="divadvancedsearchfield">';
print '<div class="inline-block"><span class="fas fa-ruler-horizontal paddingright" title="'.$langs->trans("XAxis").'"></span>'.$langs->trans("XAxis").'</div> ';
@ -407,6 +432,13 @@ print $formother->selectXAxisField($object, $search_xaxis, $arrayofxaxis);
print '</div>';
// Group by
print '<div class="divadvancedsearchfield">';
print '<div class="inline-block opacitymedium"><span class="fas fa-ruler-horizontal paddingright" title="'.$langs->trans("GroupBy").'"></span>'.$langs->trans("GroupBy").'</div> ';
print $formother->selectGroupByField($object, $search_groupby, $arrayofgroupby);
print '</div>';
if ($mode == 'grid') {
// YAxis
print '<div class="divadvancedsearchfield">';
@ -449,12 +481,9 @@ if ($mode == 'grid') {
}
if ($mode == 'graph') {
print '<div class="divadvancedsearchfield">';
$arrayofgraphs = array('bars' => 'Bars', 'lines' => 'Lines'); // also 'pies'
print '<div class="inline-block opacitymedium"><span class="fas fa-chart-area paddingright" title="'.$langs->trans("Graph").'"></span>'.$langs->trans("Graph").'</div> ';
print $form->selectarray('search_graph', $arrayofgraphs, $search_graph, 0, 0, 0, 'minwidth100', 1);
print '</div>';
//
}
print '<div class="divadvancedsearchfield">';
print '<input type="submit" class="button buttongen button-save nomargintop" value="'.$langs->trans("Refresh").'">';
print '</div>';
@ -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) {