50@phan-var-force ?int[] $toselect
54$search_groupby = array();
58if (!defined(
'USE_CUSTOM_REPORT_AS_INCLUDE')) {
59 require
'../main.inc.php';
62 $action =
GETPOST(
'action',
'aZ09') ?
GETPOST(
'action',
'aZ09') :
'view';
63 $massaction =
GETPOST(
'massaction',
'alpha');
65 $mode =
GETPOST(
'mode',
'alpha');
66 $objecttype = (string)
GETPOST(
'objecttype',
'aZ09arobase');
67 $tabfamily =
GETPOST(
'tabfamily',
'aZ09');
69 $search_measures =
GETPOST(
'search_measures',
'array:alphanohtml');
71 if (
GETPOST(
'search_xaxis',
'alpha') &&
GETPOST(
'search_xaxis',
'alpha') !=
'-1') {
72 $search_xaxis = array(
GETPOST(
'search_xaxis',
'alpha'));
74 $search_xaxis = array();
76 if (
GETPOST(
'search_groupby',
'alpha') &&
GETPOST(
'search_groupby',
'alpha') !=
'-1') {
77 $search_groupby = array(
GETPOST(
'search_groupby',
'alpha'));
79 $search_groupby = array();
81 '@phan-var-force string[] $search_groupby';
83 $search_yaxis =
GETPOST(
'search_yaxis',
'array:alphanohtml');
84 $search_graph = (string)
GETPOST(
'search_graph',
'restricthtml');
86 $search_measures = array_map(
function ($value) {
87 return preg_replace(
'/[^a-z0-9\._\-]+/',
'', $value); }, $search_measures);
88 $search_xaxis = array_map(
function ($value) {
89 return preg_replace(
'/[^a-z0-9\._\-]+/',
'', $value); }, $search_xaxis);
90 $search_yaxis = array_map(
function ($value) {
91 return preg_replace(
'/[^a-z0-9\._\-]+/',
'', $value); }, $search_yaxis);
92 $search_groupby = array_map(
function ($value) {
93 return preg_replace(
'/[^a-z0-9\._\-]+/',
'', $value); }, $search_groupby);
97 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
98 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
100 if (empty($page) || $page == -1 ||
GETPOST(
'button_search',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha') || (empty($toselect) && $massaction ===
'0')) {
103 $offset = $limit * $page;
104 $pageprev = $page - 1;
105 $pagenext = $page + 1;
111 @phan-var-force int<0,1> $SHOWLEGEND
112 @phan-var-force string customreportkey
117 if (empty($user) || empty($user->id)) {
118 print
'Page is called as an include but $user and its permission loaded with loadRights() are not defined. We stop here.';
122 print
'Page is called as an include but $object is not defined. We stop here.';
128$conf->global->MAIN_DISALLOW_UNSECURED_SELECT_INTO_EXTRAFIELDS_FILTER = 1;
133if (!isset($search_measures)) {
134 $search_measures = array(0 =>
't.count');
136if (!isset($search_xaxis)) {
138 $search_xaxis = array();
140if (!isset($search_graph)) {
145 $objecttype =
$object->element.($object->module ?
'@'.$object->module :
'');
147if ((!is_string($objecttype) || empty($objecttype)) &&
isModEnabled(
'societe')) {
148 $objecttype =
'thirdparty';
150'@phan-var-force string $objecttype';
152require_once DOL_DOCUMENT_ROOT.
"/core/class/extrafields.class.php";
153require_once DOL_DOCUMENT_ROOT.
"/core/class/html.form.class.php";
154require_once DOL_DOCUMENT_ROOT.
"/core/lib/admin.lib.php";
155require_once DOL_DOCUMENT_ROOT.
"/core/lib/company.lib.php";
156require_once DOL_DOCUMENT_ROOT.
"/core/lib/date.lib.php";
157require_once DOL_DOCUMENT_ROOT.
"/core/lib/customreports.lib.php";
158require_once DOL_DOCUMENT_ROOT.
"/core/class/dolgraph.class.php";
159require_once DOL_DOCUMENT_ROOT.
"/core/class/doleditor.class.php";
160require_once DOL_DOCUMENT_ROOT.
"/core/class/html.formother.class.php";
163$langs->loadLangs(array(
"companies",
"other",
"exports",
"sendings"));
167$hookmanager->initHooks(array(
'customreport'));
172$keyforlabeloffield =
null;
174$ObjectClassName =
'';
177 'thirdparty' => array(
'label' =>
'ThirdParties',
'picto' =>
'company',
'ObjectClassName' =>
'Societe',
'enabled' =>
isModEnabled(
'societe'),
'ClassPath' =>
"/societe/class/societe.class.php",
'langs' =>
'companies'),
178 'contact' => array(
'label' =>
'Contacts',
'picto' =>
'contact',
'ObjectClassName' =>
'Contact',
'enabled' =>
isModEnabled(
'societe'),
'ClassPath' =>
"/contact/class/contact.class.php"),
179 'proposal' => array(
'label' =>
'Proposals',
'picto' =>
'proposal',
'ObjectClassName' =>
'Propal',
'enabled' =>
isModEnabled(
'propal'),
'ClassPath' =>
"/comm/propal/class/propal.class.php",
'langs' =>
'propal'),
180 'proposaldet' => array(
'label' =>
'ProposalLines',
'picto' =>
'proposal',
'ObjectClassName' =>
'PropaleLigne',
'enabled' =>
isModEnabled(
'propal'),
'ClassPath' =>
"/comm/propal/class/propaleligne.class.php",
'langs' =>
'propal'),
181 'order' => array(
'label' =>
'Orders',
'picto' =>
'order',
'ObjectClassName' =>
'Commande',
'enabled' =>
isModEnabled(
'order'),
'ClassPath' =>
"/commande/class/commande.class.php",
'langs' =>
'orders'),
182 'orderdet' => array(
'label' =>
'SaleOrderLines',
'picto' =>
'order',
'ObjectClassName' =>
'OrderLine',
'enabled' =>
isModEnabled(
'order'),
'ClassPath' =>
"/commande/class/orderline.class.php",
'langs' =>
'orders'),
183 'invoice' => array(
'label' =>
'Invoices',
'picto' =>
'bill',
'ObjectClassName' =>
'Facture',
'enabled' =>
isModEnabled(
'invoice'),
'ClassPath' =>
"/compta/facture/class/facture.class.php",
'langs' =>
'bills'),
184 'invoice_template' => array(
'label' =>
'PredefinedInvoices',
'picto' =>
'bill',
'ObjectClassName' =>
'FactureRec',
'enabled' =>
isModEnabled(
'invoice'),
'ClassPath' =>
"/compta/facture/class/facture-rec.class.php",
'langs' =>
'bills'),
185 'contract' => array(
'label' =>
'Contracts',
'picto' =>
'contract',
'ObjectClassName' =>
'Contrat',
'enabled' =>
isModEnabled(
'contract'),
'ClassPath' =>
"/contrat/class/contrat.class.php",
'langs' =>
'contracts'),
186 'contractdet' => array(
'label' =>
'ContractLines',
'picto' =>
'contract',
'ObjectClassName' =>
'ContratLigne',
'enabled' =>
isModEnabled(
'contract'),
'ClassPath' =>
"/contrat/class/contrat.class.php",
'langs' =>
'contracts'),
187 'bom' => array(
'label' =>
'BOM',
'picto' =>
'bom',
'ObjectClassName' =>
'Bom',
'enabled' =>
isModEnabled(
'bom')),
188 'mrp' => array(
'label' =>
'MO',
'picto' =>
'mrp',
'ObjectClassName' =>
'Mo',
'enabled' =>
isModEnabled(
'mrp'),
'ClassPath' =>
"/mrp/class/mo.class.php"),
189 'ticket' => array(
'label' =>
'Ticket',
'picto' =>
'ticket',
'ObjectClassName' =>
'Ticket',
'enabled' =>
isModEnabled(
'ticket')),
190 'member' => array(
'langs' =>
'members',
'label' =>
'Adherent',
'picto' =>
'member',
'ObjectClassName' =>
'Adherent',
'enabled' =>
isModEnabled(
'member'),
'ClassPath' =>
"/adherents/class/adherent.class.php"),
191 'cotisation' => array(
'langs' =>
'members',
'label' =>
'Subscriptions',
'picto' =>
'member',
'ObjectClassName' =>
'Subscription',
'enabled' =>
isModEnabled(
'member'),
'ClassPath' =>
"/adherents/class/subscription.class.php"),
196$parameters = array(
'objecttype' => $objecttype,
'tabfamily' => $tabfamily);
198$reshook = $hookmanager->executeHooks(
'loadDataForCustomReports', $parameters,
$object, $action);
201} elseif (is_array($hookmanager->resArray)) {
202 if (!empty($hookmanager->resArray[
'title'])) {
203 $title = $hookmanager->resArray[
'title'];
205 if (!empty($hookmanager->resArray[
'picto'])) {
206 $picto = $hookmanager->resArray[
'picto'];
208 if (!empty($hookmanager->resArray[
'head'])) {
209 $head = array_merge($head, $hookmanager->resArray[
'head']);
211 if (!empty($hookmanager->resArray[
'arrayoftype'])) {
212 foreach ($hookmanager->resArray[
'arrayoftype'] as $key => $val) {
213 $arrayoftype[$key] = $val;
221 if (!empty($arrayoftype[$objecttype][
'ClassPath'])) {
222 $fileforclass = $arrayoftype[$objecttype][
'ClassPath'];
224 $fileforclass =
"/".$objecttype.
"/class/".$objecttype.
".class.php";
226 $ObjectClassName =
null;
228 if ($fileforclass !==
null) {
231 $ObjectClassName = $arrayoftype[$objecttype][
'ObjectClassName'];
233 if (!empty($ObjectClassName)) {
234 if (class_exists($ObjectClassName)) {
235 $object =
new $ObjectClassName($db);
237 print
'Failed to load class for type '.$objecttype.
'. Class file found but Class object named '.$ObjectClassName.
' not found.';
240 print
'Failed to load class for type '.$objecttype.
'. Class file name is unknown.';
243 print
'Failed to load class for type '.$objecttype.
'. Class path not found.';
247'@phan-var-force CommonObject $object';
251if ($user->socid > 0) {
257$extrafields->fetch_name_optionals_label(
'all');
260if (!empty(
$object->table_element)) {
261 $search_array_options = $extrafields->getOptionalsFromPost(
$object->table_element,
'',
'search_');
263 $search_array_options = array();
266$search_component_params = array(
'');
267$search_component_params_hidden = trim(
GETPOST(
'search_component_params_hidden',
'alphanohtml'));
268$search_component_params_input = trim(
GETPOST(
'search_component_params_input',
'alphanohtml'));
277 $value = $search_component_params_input;
279 $value = preg_replace(
'/([a-z\.]+)\s*([!<>=]+|in|notin|like|notlike)\s*/',
'\1:\2:', $value);
280 $value = preg_replace(
'/\s*\|\s*/',
'|', $value);
283 $crits = explode(
' ', trim($value));
287 foreach ($crits as $crit) {
292 $tmpcrits = explode(
'|', $crit);
294 foreach ($tmpcrits as $tmpcrit) {
295 if ($tmpcrit !==
'0' && empty($tmpcrit)) {
298 $tmpcrit = trim($tmpcrit);
302 $parenthesislevel = 0;
303 $rescheckfilter =
dolCheckFilters($tmpcrit, $errorstr, $parenthesislevel);
304 if ($rescheckfilter) {
305 while ($parenthesislevel > 0) {
306 $tmpcrit = preg_replace(
'/^\(/',
'', preg_replace(
'/\)$/',
'', $tmpcrit));
311 $field = preg_replace(
'/(:[!<>=\s]+:|:in:|:notin:|:like:|:notlike:).*$/',
'', $tmpcrit);
312 $tmpcrit = preg_replace(
'/^.*(:[!<>=\s]+:|:in:|:notin:|:like:|:notlike:)/',
'\1', $tmpcrit);
315 $newres .= (($i2 > 0 || $i3 > 0) ?
' OR ' :
'');
318 $newcrit = preg_replace(
'/(:[!<>=\s]+:|:in:|:notin:|:like:|:notlike:)/',
'', $tmpcrit);
322 preg_match(
'/:([!<>=\s]+|in|notin|like|notlike):/', $tmpcrit, $reg);
323 if (!empty($reg[1])) {
326 if ($newcrit !=
'') {
327 if (!preg_match(
'/^\'[^\']*\'$/', $newcrit)) {
329 $newres .=
'('.$field.
':'.$operator.
':'.((float) $numnewcrit).
')';
331 $newres .=
'('.$field.
':'.$operator.
":".((string) $newcrit).
')';
339 $res = $res.($res ?
' AND ' :
'').($i2 > 1 ?
'(' :
'').$newres.($i2 > 1 ?
')' :
'');
346 $search_component_params_input = $res;
352$search_component_params_hidden = implode(
' AND ', array_merge($arrayofandtagshidden, $arrayofandtagsinput));
355$MAXUNIQUEVALFORGROUP = 20;
356$MAXMEASURESINBARGRAPH = 20;
357$SHOWLEGEND = (isset($SHOWLEGEND) ? $SHOWLEGEND : 1);
359$YYYY = substr($langs->trans(
"Year"), 0, 1).substr($langs->trans(
"Year"), 0, 1).substr($langs->trans(
"Year"), 0, 1).substr($langs->trans(
"Year"), 0, 1);
360$MM = substr($langs->trans(
"Month"), 0, 1).substr($langs->trans(
"Month"), 0, 1);
361$DD = substr($langs->trans(
"Day"), 0, 1).substr($langs->trans(
"Day"), 0, 1);
362$HH = substr($langs->trans(
"Hour"), 0, 1).substr($langs->trans(
"Hour"), 0, 1);
363$MI = substr($langs->trans(
"Minute"), 0, 1).substr($langs->trans(
"Minute"), 0, 1);
364$SS = substr($langs->trans(
"Second"), 0, 1).substr($langs->trans(
"Second"), 0, 1);
366$arrayoffilterfields = array();
367$arrayofmesures = array();
368$arrayofxaxis = array();
369$arrayofgroupby = array();
370$arrayofyaxis = array();
371$arrayofvaluesforgroupby = array();
378if (!empty(
$object->element_for_permission)) {
379 $features =
$object->element_for_permission;
381 $features .= (empty(
$object->module) ?
'' :
'@'.$object->module);
400$form =
new Form($db);
403if (!defined(
'USE_CUSTOM_REPORT_AS_INCLUDE')) {
404 llxHeader(
'', $langs->transnoentitiesnoconv(
'CustomReports'),
'');
414$newarrayoftype = array();
415foreach ($arrayoftype as $key => $val) {
416 if (
dol_eval((
string) $val[
'enabled'], 1, 1,
'1')) {
417 $newarrayoftype[$key] = $arrayoftype[$key];
419 if (!empty($val[
'langs'])) {
420 $langs->load($val[
'langs']);
426if (array_key_exists($objecttype, $newarrayoftype)) {
427 $label = $langs->trans($newarrayoftype[$objecttype][
'label']);
430$arrayoffilterfields =
dol_sort_array($arrayoffilterfields,
'position',
'asc', 0, 0, 1);
434$arrayofmesures =
dol_sort_array($arrayofmesures,
'position',
'asc', 0, 0, 1);
438$arrayofxaxis =
dol_sort_array($arrayofxaxis,
'position',
'asc', 0, 0, 1);
442$arrayofgroupby =
dol_sort_array($arrayofgroupby,
'position',
'asc', 0, 0, 1);
446if ($action ==
'viewgraph') {
447 if (!count($search_measures)) {
448 setEventMessages($langs->trans(
"AtLeastOneMeasureIsRequired"),
null,
'warnings');
449 } elseif ($mode ==
'graph' && is_array($search_xaxis) && count($search_xaxis) > 1) {
450 setEventMessages($langs->trans(
"OnlyOneFieldForXAxisIsPossible"),
null,
'warnings');
451 $search_xaxis = array(0 => $search_xaxis[0]);
453 if (count($search_groupby) >= 2) {
454 setEventMessages($langs->trans(
"ErrorOnlyOneFieldForGroupByIsPossible"),
null,
'warnings');
455 $search_groupby = array(0 => $search_groupby[0]);
457 if (!count($search_xaxis)) {
458 setEventMessages($langs->trans(
"AtLeastOneXAxisIsRequired"),
null,
'warnings');
459 } elseif ($mode ==
'graph' && $search_graph ==
'bars' && count($search_measures) > $MAXMEASURESINBARGRAPH) {
460 $langs->load(
"errors");
461 setEventMessages($langs->trans(
"GraphInBarsAreLimitedToNMeasures", $MAXMEASURESINBARGRAPH),
null,
'warnings');
462 $search_graph =
'lines';
468if (count($search_groupby)) {
470 foreach ($search_groupby as $gkey => $gval) {
471 $gvalwithoutprefix = preg_replace(
'/^[a-z]+\./i',
'', $gval);
472 $gvalsanitized = preg_replace(
'/[^a-z0-9\._\-]+/i',
'', $gval);
474 if (preg_match(
'/\-year$/', $gvalsanitized)) {
475 $tmpval = preg_replace(
'/\-year$/',
'', $gvalsanitized);
476 $fieldtocount .=
'DATE_FORMAT('.$tmpval.
", '%Y')";
477 } elseif (preg_match(
'/\-month$/', $gvalsanitized)) {
478 $tmpval = preg_replace(
'/\-month$/',
'', $gvalsanitized);
479 $fieldtocount .=
'DATE_FORMAT('.$tmpval.
", '%Y-%m')";
480 } elseif (preg_match(
'/\-day$/', $gvalsanitized)) {
481 $tmpval = preg_replace(
'/\-day$/',
'', $gvalsanitized);
482 $fieldtocount .=
'DATE_FORMAT('.$tmpval.
", '%Y-%m-%d')";
484 $fieldtocount = $gvalsanitized;
487 $sql =
"SELECT DISTINCT ".$fieldtocount.
" as val";
489 if (strpos($fieldtocount,
'te') === 0) {
490 $tabletouse =
$object->table_element;
491 $tablealiastouse =
'te';
492 if (!empty($arrayofgroupby[$gval])) {
493 $tmpval = explode(
'.', $gval);
494 $tabletouse = $arrayofgroupby[$gval][
'table'];
495 $tablealiastouse = $tmpval[0];
500 $sql .=
" FROM ".MAIN_DB_PREFIX.$tabletouse.
"_extrafields as ".$tablealiastouse;
502 $tabletouse =
$object->table_element;
503 $tablealiastouse =
't';
504 if (!empty($arrayofgroupby[$gval])) {
505 $tmpval = explode(
'.', $gval);
506 $tabletouse = $arrayofgroupby[$gval][
'table'];
507 $tablealiastouse = $tmpval[0];
509 $sql .=
" FROM ".MAIN_DB_PREFIX.$tabletouse.
" as ".$tablealiastouse;
520 $sql .=
" LIMIT ".((int) ($MAXUNIQUEVALFORGROUP + 1));
523 $resql = $db->query($sql);
528 while ($obj = $db->fetch_object($resql)) {
529 if (is_null($obj->val)) {
530 $keytouse =
'__NULL__';
531 $valuetranslated = $langs->transnoentitiesnoconv(
"NotDefined");
532 } elseif ($obj->val ===
'') {
534 $valuetranslated = $langs->transnoentitiesnoconv(
"Empty");
536 $keytouse = (string) $obj->val;
537 $valuetranslated = $obj->val;
541 if (isset(
$object->fields[$gvalwithoutprefix])) {
542 if (!empty(
$object->fields[$gvalwithoutprefix][
'arrayofkeyval'])) {
543 $valuetranslated =
$object->fields[$gvalwithoutprefix][
'arrayofkeyval'][$obj->val];
544 if (is_null($valuetranslated)) {
545 $valuetranslated = $langs->transnoentitiesnoconv(
"UndefinedKey");
547 $valuetranslated = $langs->trans($valuetranslated);
548 } elseif (preg_match(
'/integer:([^:]+):([^:]+)$/',
$object->fields[$gvalwithoutprefix][
'type'], $regs)) {
549 $classname = $regs[1];
550 $classpath = $regs[2];
552 if (class_exists($classname)) {
553 $tmpobject =
new $classname($db);
554 '@phan-var-force CommonObject $tmpobject';
555 $tmpobject->fetch($obj->val);
556 foreach ($tmpobject->fields as $fieldkey => $field) {
557 if ($field[
'showoncombobox']) {
558 $valuetranslated = $tmpobject->$fieldkey;
568 $arrayofvaluesforgroupby[
'g_'.$gkey][$keytouse] = $valuetranslated;
571 $tmpfield = explode(
'.', $gval);
572 if ($tmpfield[0] !=
't' || (isset(
$object->fields[$tmpfield[1]]) && is_array(
$object->fields[$tmpfield[1]]) && empty(
$object->fields[$tmpfield[1]][
'notnull']))) {
573 dol_syslog(
"The group by field ".$gval.
" may be null (because field is null or it is a left join), so we add __NULL__ entry in list of possible values");
575 $arrayofvaluesforgroupby[
'g_'.$gkey][
'__NULL__'] = $langs->transnoentitiesnoconv(
"NotDefined");
578 if (is_array($arrayofvaluesforgroupby[
'g_'.$gkey])) {
579 asort($arrayofvaluesforgroupby[
'g_'.$gkey]);
583 if (is_array($arrayofvaluesforgroupby[
'g_'.$gkey]) && count($arrayofvaluesforgroupby[
'g_'.$gkey]) > $MAXUNIQUEVALFORGROUP) {
584 $langs->load(
"errors");
586 if (strpos($fieldtocount,
'te') === 0) {
590 $keyforlabeloffield = $extrafields->attributes[
$object->table_element][
'label'][$gvalwithoutprefix];
591 $labeloffield = $langs->transnoentitiesnoconv($keyforlabeloffield);
592 } elseif (strpos($fieldtocount,
't__') === 0) {
594 if (preg_match(
'/^(.*)\.(.*)/', $gvalwithoutprefix, $reg)) {
601 $labeloffield = $arrayofgroupby[$fieldtocount][
'labelnohtml'];
603 $labeloffield =
'FK_ISSUE';
607 if (preg_match(
'/^(.*)\-(year|month|day)/', $gvalwithoutprefix, $reg)) {
608 $gvalwithoutprefix = preg_replace(
'/\-(year|month|day)/',
'', $gvalwithoutprefix);
609 $keyforlabeloffield =
$object->fields[$gvalwithoutprefix][
'label'];
610 $labeloffield = $langs->transnoentitiesnoconv($keyforlabeloffield).
'-'.$reg[2];
612 $keyforlabeloffield =
$object->fields[$gvalwithoutprefix][
'label'];
613 $labeloffield = $langs->transnoentitiesnoconv($keyforlabeloffield);
617 setEventMessages($langs->transnoentitiesnoconv(
"ErrorTooManyDifferentValueForSelectedGroupBy", (
string) $MAXUNIQUEVALFORGROUP, (
string) $labeloffield),
null,
'warnings');
618 $search_groupby = array();
636if (!defined(
'MAIN_CUSTOM_REPORT_KEEP_GRAPH_ONLY')) {
637 print
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'" autocomplete="off">';
638 print
'<input type="hidden" name="token" value="'.newToken().
'">';
639 print
'<input type="hidden" name="action" value="viewgraph">';
640 print
'<input type="hidden" name="tabfamily" value="'.(string) $tabfamily.
'">';
644 $viewmode .=
'<div class="divadvancedsearchfield">';
645 $arrayofgraphs = array(
'bars' =>
'Bars',
'lines' =>
'Lines');
646 $viewmode .=
'<div class="inline-block opacitymedium"><span class="fas fa-chart-area paddingright" title="'.$langs->trans(
"Graph").
'"></span>'.$langs->trans(
"Graph").
'</div> ';
647 $viewmode .= $form->selectarray(
'search_graph', $arrayofgraphs, $search_graph, 0, 0, 0,
'', 1, 0, 0,
'',
'graphtype width100');
648 $viewmode .=
'</div>';
651 $massactionbutton =
'';
656 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);
659 foreach ($newarrayoftype as $tmpkey => $tmpval) {
660 $newarrayoftype[$tmpkey][
'data-html'] =
img_picto(
'', $tmpval[
'picto'],
'class="pictofixedwidth"').$langs->trans($tmpval[
'label']);
661 $newarrayoftype[$tmpkey][
'label'] = $langs->trans($tmpval[
'label']);
664 print
'<div class="liste_titre liste_titre_bydiv liste_titre_bydiv_inlineblock liste_titre_bydiv_nothingafter centpercent">';
667 print
'<div class="divadvancedsearchfield center floatnone">';
668 print
'<div class="inline-block"><span class="opacitymedium">'.$langs->trans(
"StatisticsOn").
'</span></div> ';
670 print $form->selectarray(
'objecttype', $newarrayoftype, $objecttype, 0, 0, 0,
'', 1, 0, 0,
'',
'minwidth250', 1,
'', 0, 1);
671 if (empty($conf->use_javascript_ajax)) {
672 print
'<input type="submit" class="button buttongen button-save nomargintop" name="changeobjecttype" value="'.$langs->trans(
"Refresh").
'">';
674 print
'<!-- js code to reload page with good object type -->
675 <script nonce="'.getNonce().
'" type="text/javascript">
676 jQuery(document).ready(function() {
677 jQuery("#objecttype").change(function() {
678 console.log("Reload for "+jQuery("#objecttype").val());
679 location.href = "'.$_SERVER[
"PHP_SELF"].
'?objecttype="+jQuery("#objecttype").val()+"'.($tabfamily ?
'&tabfamily='.urlencode($tabfamily) :
'').(
GETPOSTINT(
'show_search_component_params_hidden') ?
'&show_search_component_params_hidden='.((int)
GETPOSTINT(
'show_search_component_params_hidden')) :
'').
'";
684 print
'</div><div class="clearboth"></div>';
686 if (!empty($newarrayoftype)) {
689 print
'<div class="divadvancedsearchfield">';
690 print $form->searchComponent(array(
$object->element =>
$object->fields), $search_component_params, array(), $search_component_params_hidden, $arrayoffilterfields);
697 print
'<div class="divadvancedsearchfield clearboth">';
698 print
'<div class="inline-block"><span class="fas fa-ruler-combined paddingright pictofixedwidth" title="'.dol_escape_htmltag($langs->trans(
"Measures")).
'"></span><span class="fas fa-caret-left caretleftaxis" title="'.
dol_escape_htmltag($langs->trans(
"Measures")).
'"></span></div>';
699 $simplearrayofmesures = array();
700 foreach ($arrayofmesures as $key => $val) {
701 $simplearrayofmesures[$key] = $arrayofmesures[$key][
'label'];
703 print $form->multiselectarray(
'search_measures', $simplearrayofmesures, $search_measures, 0, 0,
'minwidth300 widthcentpercentminusx', 1, 0,
'',
'', $langs->transnoentitiesnoconv(
"Measures"));
708 print
'<div class="divadvancedsearchfield">';
709 print
'<div class="inline-block"><span class="fas fa-ruler-combined paddingright pictofixedwidth" title="'.dol_escape_htmltag($langs->trans(
"XAxis")).
'"></span><span class="fas fa-caret-down caretdownaxis" title="'.
dol_escape_htmltag($langs->trans(
"XAxis")).
'"></span></div>';
711 print $formother->selectXAxisField(
$object, $search_xaxis, $arrayofxaxis, $langs->trans(
"XAxis"),
'minwidth300 maxwidth400 widthcentpercentminusx');
716 print
'<div class="divadvancedsearchfield">';
717 print
'<div class="inline-block opacitymedium"><span class="fas fa-ruler-horizontal paddingright pictofixedwidth" title="'.dol_escape_htmltag($langs->trans(
"GroupBy")).
'"></span></div>';
718 print $formother->selectGroupByField(
$object, $search_groupby, $arrayofgroupby,
'minwidth250 maxwidth300 widthcentpercentminusx', $langs->trans(
"GroupBy"));
722 if ($mode ==
'grid') {
724 print
'<div class="divadvancedsearchfield">';
725 foreach (
$object->fields as $key => $val) {
726 if (empty($val[
'measure']) && (!isset($val[
'enabled']) ||
dol_eval((
string) $val[
'enabled'], 1, 1,
'1'))) {
727 if (in_array($key, array(
'id',
'rowid',
'entity',
'last_main_doc',
'extraparams'))) {
730 if (preg_match(
'/^fk_/', $key)) {
733 if (in_array($val[
'type'], array(
'html',
'text'))) {
736 if (in_array($val[
'type'], array(
'timestamp',
'date',
'datetime'))) {
737 $arrayofyaxis[
't.'.$key.
'-year'] = array(
738 'label' => $langs->trans($val[
'label']).
' ('.$YYYY.
')',
739 'position' => $val[
'position'],
740 'table' =>
$object->table_element
742 $arrayofyaxis[
't.'.$key.
'-month'] = array(
743 'label' => $langs->trans($val[
'label']).
' ('.$YYYY.
'-'.$MM.
')',
744 'position' => $val[
'position'],
745 'table' =>
$object->table_element
747 $arrayofyaxis[
't.'.$key.
'-day'] = array(
748 'label' => $langs->trans($val[
'label']).
' ('.$YYYY.
'-'.$MM.
'-'.$DD.
')',
749 'position' => $val[
'position'],
750 'table' =>
$object->table_element
753 $arrayofyaxis[
't.'.$key] = array(
754 'label' => $val[
'label'],
755 'position' => (
int) $val[
'position'],
756 'table' =>
$object->table_element
762 if (
$object->isextrafieldmanaged) {
763 foreach ($extrafields->attributes[
$object->table_element][
'label'] as $key => $val) {
764 if (!empty($extrafields->attributes[
$object->table_element][
'totalizable'][$key]) && (!isset($extrafields->attributes[
$object->table_element][
'enabled'][$key]) ||
dol_eval((
string) $extrafields->attributes[
$object->table_element][
'enabled'][$key], 1, 1,
'1'))) {
765 $arrayofyaxis[
'te.'.$key] = array(
766 'label' => $extrafields->attributes[
$object->table_element][
'label'][$key],
767 'position' => (
int) $extrafields->attributes[
$object->table_element][
'pos'][$key],
768 'table' =>
$object->table_element
774 $arrayofyaxislabel = array();
775 foreach ($arrayofyaxis as $key => $val) {
776 $arrayofyaxislabel[$key] = $val[
'label'];
778 print
'<div class="inline-block opacitymedium"><span class="fas fa-ruler-vertical paddingright" title="'.$langs->trans(
"YAxis").
'"></span>'.$langs->trans(
"YAxis").
'</div> ';
779 print $form->multiselectarray(
'search_yaxis', $arrayofyaxislabel, $search_yaxis !=
null ? $search_yaxis : array(), 0, 0,
'minwidth100', 1);
783 if (!empty($newarrayoftype)) {
784 print
'<div class="divadvancedsearchfield">';
785 print
'<input type="submit" class="button buttongen button-save nomargintop" value="'.$langs->trans(
"Refresh").
'">';
795if (!empty($search_measures) && !empty($search_xaxis)) {
801 foreach ($search_xaxis as $key => $val) {
802 if (preg_match(
'/\-year$/', $val)) {
803 $tmpval = preg_replace(
'/\-year$/',
'', $val);
804 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y') as x_".$key.
', ';
805 } elseif (preg_match(
'/\-month$/', $val)) {
806 $tmpval = preg_replace(
'/\-month$/',
'', $val);
807 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m') as x_".$key.
', ';
808 } elseif (preg_match(
'/\-day$/', $val)) {
809 $tmpval = preg_replace(
'/\-day$/',
'', $val);
810 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m-%d') as x_".$key.
', ';
812 $sql .= $val.
" as x_".$key.
", ";
815 if (!empty($search_groupby)) {
816 foreach ($search_groupby as $key => $val) {
817 if (preg_match(
'/\-year$/', $val)) {
818 $tmpval = preg_replace(
'/\-year$/',
'', $val);
819 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y') as g_".$key.
', ';
820 } elseif (preg_match(
'/\-month$/', $val)) {
821 $tmpval = preg_replace(
'/\-month$/',
'', $val);
822 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m') as g_".$key.
', ';
823 } elseif (preg_match(
'/\-day$/', $val)) {
824 $tmpval = preg_replace(
'/\-day$/',
'', $val);
825 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m-%d') as g_".$key.
', ';
827 $sql .= $val.
" as g_".$key.
", ";
831 foreach ($search_measures as $key => $val) {
832 if ($val ==
't.count') {
833 $sql .=
"COUNT(t.".$fieldid.
") as y_".$key.
', ';
834 } elseif (preg_match(
'/\-sum$/', $val)) {
835 $tmpval = preg_replace(
'/\-sum$/',
'', $val);
836 $sql .=
"SUM(".$db->ifsql($tmpval.
' IS NULL',
'0', $tmpval).
") as y_".$key.
", ";
837 } elseif (preg_match(
'/\-average$/', $val)) {
838 $tmpval = preg_replace(
'/\-average$/',
'', $val);
839 $sql .=
"AVG(".$db->ifsql($tmpval.
' IS NULL',
'0', $tmpval).
") as y_".$key.
", ";
840 } elseif (preg_match(
'/\-min$/', $val)) {
841 $tmpval = preg_replace(
'/\-min$/',
'', $val);
842 $sql .=
"MIN(".$db->ifsql($tmpval.
' IS NULL',
'0', $tmpval).
") as y_".$key.
", ";
843 } elseif (preg_match(
'/\-max$/', $val)) {
844 $tmpval = preg_replace(
'/\-max$/',
'', $val);
845 $sql .=
"MAX(".$db->ifsql($tmpval.
' IS NULL',
'0', $tmpval).
") as y_".$key.
", ";
846 } elseif (preg_match(
'/\-stddevpop$/', $val)) {
847 $tmpval = preg_replace(
'/\-stddevpop$/',
'', $val);
848 $sql .=
"STDDEV_POP(".$db->ifsql($tmpval.
' IS NULL',
'0', $tmpval).
") as y_".$key.
", ";
851 $sql = preg_replace(
'/,\s*$/',
'', $sql);
852 $sql .=
" FROM ".MAIN_DB_PREFIX.$object->table_element.
" as t";
854 if (
$object->isextrafieldmanaged) {
855 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element.
"_extrafields as te ON te.fk_object = t.".$fieldid;
858 if (
$object->ismultientitymanaged) {
859 if (
$object->ismultientitymanaged == 1) {
862 $tmparray = explode(
'@',
$object->ismultientitymanaged);
863 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.$tmparray[1].
" as parenttableforentity ON t.".$tmparray[0].
" = parenttableforentity.rowid";
864 $sql .=
" AND parenttableforentity.entity IN (".getEntity($tmparray[1]).
")";
869 $listoftablesalreadyadded = array(
$object->table_element =>
$object->table_element);
873 foreach ($search_xaxis as $key => $val) {
874 if (!empty($arrayofxaxis[$val])) {
875 $tmpval = explode(
'.', $val);
878 foreach ($tmpforloop as $tmptable => $tmptablealias) {
879 if (! in_array($tmptable, $listoftablesalreadyadded)) {
880 $tmpforexplode = explode(
'__', $tmptablealias);
881 $endpart = end($tmpforexplode);
882 $parenttableandfield = preg_replace(
'/__'.$endpart.
'$/',
'', $tmptablealias).
'.'.$endpart;
884 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$tmptable.
" as ".$db->sanitize($tmptablealias).
" ON ".$db->sanitize($parenttableandfield).
" = ".$db->sanitize($tmptablealias).
".rowid";
885 $listoftablesalreadyadded[$tmptable] = $tmptable;
887 if (preg_match(
'/^te/', $tmpval[0]) && preg_replace(
'/^t_/',
'te_', $tmptablealias) == $tmpval[0]) {
888 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$tmptable.
"_extrafields as ".$db->sanitize($tmpval[0]).
" ON ".$db->sanitize($tmpval[0]).
".fk_object = ".$db->sanitize($tmptablealias).
".rowid";
889 $listoftablesalreadyadded[$tmptable] = $tmptable;
894 $errormessage =
'Found a key into search_xaxis not found into arrayofxaxis';
900 foreach ($search_groupby as $key => $val) {
901 if (!empty($arrayofgroupby[$val])) {
902 $tmpval = explode(
'.', $val);
905 foreach ($tmpforloop as $tmptable => $tmptablealias) {
906 if (! in_array($tmptable, $listoftablesalreadyadded)) {
907 $tmpforexplode = explode(
'__', $tmptablealias);
908 $endpart = end($tmpforexplode);
909 $parenttableandfield = preg_replace(
'/__'.$endpart.
'$/',
'', $tmptablealias).
'.'.$endpart;
911 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$tmptable.
" as ".$db->sanitize($tmptablealias).
" ON ".$db->sanitize($parenttableandfield).
" = ".$db->sanitize($tmptablealias).
".rowid";
912 $listoftablesalreadyadded[$tmptable] = $tmptable;
914 if (preg_match(
'/^te/', $tmpval[0]) && preg_replace(
'/^t_/',
'te_', $tmptablealias) == $tmpval[0]) {
915 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$tmptable.
"_extrafields as ".$db->sanitize($tmpval[0]).
" ON ".$db->sanitize($tmpval[0]).
".fk_object = ".$db->sanitize($tmptablealias).
".rowid";
916 $listoftablesalreadyadded[$tmptable] = $tmptable;
921 $errormessage =
'Found a key into search_groupby not found into arrayofgroupby';
927 foreach ($search_measures as $key => $val) {
928 if (!empty($arrayofmesures[$val])) {
929 $tmpval = explode(
'.', $val);
932 foreach ($tmpforloop as $tmptable => $tmptablealias) {
933 if (! in_array($tmptable, $listoftablesalreadyadded)) {
934 $tmpforexplode = explode(
'__', $tmptablealias);
935 $endpart = end($tmpforexplode);
936 $parenttableandfield = preg_replace(
'/__'.$endpart.
'$/',
'', $tmptablealias).
'.'.$endpart;
938 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$tmptable.
" as ".$db->sanitize($tmptablealias).
" ON ".$db->sanitize($parenttableandfield).
" = ".$db->sanitize($tmptablealias).
".rowid";
939 $listoftablesalreadyadded[$tmptable] = $tmptable;
941 if (preg_match(
'/^te/', $tmpval[0]) && preg_replace(
'/^t_/',
'te_', $tmptablealias) == $tmpval[0]) {
942 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$tmptable.
"_extrafields as ".$db->sanitize($tmpval[0]).
" ON ".$db->sanitize($tmpval[0]).
".fk_object = ".$db->sanitize($tmptablealias).
".rowid";
943 $listoftablesalreadyadded[$tmptable] = $tmptable;
948 $errormessage =
'Found a key into search_measures not found into arrayofmesures';
953 if (!empty($search_component_params_hidden)) {
956 preg_match_all(
'/\b(t[\w]*_[\w]*)\.(\w+(-\w+)?)/', $search_component_params_hidden, $matches);
957 $fieldsUsedInFilter = array_unique($matches[0]);
960 $fieldsToRemove = array_merge($search_measures, $search_groupby, $search_xaxis);
961 $fieldsUsedInFilter = array_diff($fieldsUsedInFilter, $fieldsToRemove);
963 foreach ($fieldsUsedInFilter as $key => $val) {
964 if (!empty($arrayoffilterfields[$val])) {
965 $tmpval = explode(
'.', $val);
967 foreach ($tmpforloop as $tmptable => $tmptablealias) {
968 if (! in_array($tmptable, $listoftablesalreadyadded)) {
969 $tmpforexplode = explode(
'__', $tmptablealias);
970 $endpart = end($tmpforexplode);
971 $parenttableandfield = preg_replace(
'/__'.$endpart.
'$/',
'', $tmptablealias).
'.'.$endpart;
973 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$tmptable.
" as ".$db->sanitize($tmptablealias).
" ON ".$db->sanitize($parenttableandfield).
" = ".$db->sanitize($tmptablealias).
".rowid";
974 $listoftablesalreadyadded[$tmptable] = $tmptable;
976 if (preg_match(
'/^te/', $tmpval[0]) && preg_replace(
'/^t_/',
'te_', $tmptablealias) == $tmpval[0]) {
977 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$tmptable.
"_extrafields as ".$db->sanitize($tmpval[0]).
" ON ".$db->sanitize($tmpval[0]).
".fk_object = ".$db->sanitize($tmptablealias).
".rowid";
978 $listoftablesalreadyadded[$tmptable] = $tmptable;
983 $errormessage =
'Found a key into search_filterfields not found into arrayoffilterfields';
988 $sql .=
" WHERE 1 = 1";
989 if (
$object->ismultientitymanaged == 1) {
990 $sql .=
" AND t.entity IN (".getEntity(
$object->element).
")";
993 $sqlfilters = $search_component_params_hidden;
998 $sql = preg_replace_callback(
999 "/(\w+)\.(\w+)\s*(=|!=|<>|<|>|<=|>=)\s*'(\d{4})-(\d{2})-(\d{2})'/",
1004 function (array $matches): string {
1006 $column = $matches[1] .
'.' . $matches[2];
1007 $operator = $matches[3];
1008 $year = (int) $matches[4];
1009 $month = (int) $matches[5];
1010 $day = (int) $matches[6];
1012 $startOfDay = $db->idate(
dol_mktime(0, 0, 0, $month, $day, $year));
1013 $endOfDay = $db->idate(
dol_mktime(23, 59, 59, $month, $day, $year));
1015 switch ($operator) {
1017 return "($column >= '$startOfDay' AND $column <= '$endOfDay')";
1020 return "NOT ($column >= '$startOfDay' AND $column <= '$endOfDay')";
1022 return "$column < '$startOfDay'";
1024 return "$column > '$endOfDay'";
1026 return "$column <= '$endOfDay'";
1028 return "$column >= '$startOfDay'";
1036 $sql .=
" GROUP BY ";
1037 foreach ($search_xaxis as $key => $val) {
1038 if (preg_match(
'/\-year$/', $val)) {
1039 $tmpval = preg_replace(
'/\-year$/',
'', $val);
1040 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y'), ";
1041 } elseif (preg_match(
'/\-month$/', $val)) {
1042 $tmpval = preg_replace(
'/\-month$/',
'', $val);
1043 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m'), ";
1044 } elseif (preg_match(
'/\-day$/', $val)) {
1045 $tmpval = preg_replace(
'/\-day$/',
'', $val);
1046 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m-%d'), ";
1051 if (!empty($search_groupby)) {
1052 foreach ($search_groupby as $key => $val) {
1053 if (preg_match(
'/\-year$/', $val)) {
1054 $tmpval = preg_replace(
'/\-year$/',
'', $val);
1055 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y'), ";
1056 } elseif (preg_match(
'/\-month$/', $val)) {
1057 $tmpval = preg_replace(
'/\-month$/',
'', $val);
1058 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m'), ";
1059 } elseif (preg_match(
'/\-day$/', $val)) {
1060 $tmpval = preg_replace(
'/\-day$/',
'', $val);
1061 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m-%d'), ";
1067 $sql = preg_replace(
'/,\s*$/',
'', $sql);
1068 $sql .=
' ORDER BY ';
1069 foreach ($search_xaxis as $key => $val) {
1070 if (preg_match(
'/\-year$/', $val)) {
1071 $tmpval = preg_replace(
'/\-year$/',
'', $val);
1072 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y'), ";
1073 } elseif (preg_match(
'/\-month$/', $val)) {
1074 $tmpval = preg_replace(
'/\-month$/',
'', $val);
1075 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m'), ";
1076 } elseif (preg_match(
'/\-day$/', $val)) {
1077 $tmpval = preg_replace(
'/\-day$/',
'', $val);
1078 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m-%d'), ";
1083 if (!empty($search_groupby)) {
1084 foreach ($search_groupby as $key => $val) {
1085 if (preg_match(
'/\-year$/', $val)) {
1086 $tmpval = preg_replace(
'/\-year$/',
'', $val);
1087 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y'), ";
1088 } elseif (preg_match(
'/\-month$/', $val)) {
1089 $tmpval = preg_replace(
'/\-month$/',
'', $val);
1090 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m'), ";
1091 } elseif (preg_match(
'/\-day$/', $val)) {
1092 $tmpval = preg_replace(
'/\-day$/',
'', $val);
1093 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m-%d'), ";
1099 $sql = preg_replace(
'/,\s*$/',
'', $sql);
1102 if (!empty($customsql)) {
1109 print
'<div class="warning">';
1117foreach ($search_measures as $key => $val) {
1118 $legend[] = $langs->trans($arrayofmesures[$val][
'label']);
1121$useagroupby = count($search_groupby);
1126$totalnbofrecord = 0;
1129 $resql = $db->query($sql);
1131 print
'<div class="warning">';
1138 $oldlabeltouse =
'';
1139 while ($obj = $db->fetch_object($resql)) {
1142 $xval = $search_xaxis[0];
1143 $fieldforxkey =
'x_0';
1144 $xlabel = $obj->$fieldforxkey;
1145 $xvalwithoutprefix = preg_replace(
'/^[a-z]+\./',
'', $xval);
1148 if (!empty(
$object->fields[$xvalwithoutprefix][
'arrayofkeyval'])) {
1149 $xlabel =
$object->fields[$xvalwithoutprefix][
'arrayofkeyval'][$obj->$fieldforxkey];
1151 $labeltouse = (($xlabel || $xlabel ==
'0') ?
dol_trunc($xlabel, 20,
'middle') : ($xlabel ===
'' ? $langs->transnoentitiesnoconv(
"Empty") : $langs->transnoentitiesnoconv(
"NotDefined")));
1153 if ($oldlabeltouse !==
'' && ($labeltouse != $oldlabeltouse)) {
1157 $oldlabeltouse = $labeltouse;
1170 foreach ($search_measures as $key => $val) {
1172 foreach ($search_groupby as $gkey => $gval) {
1175 foreach ($arrayofvaluesforgroupby[
'g_'.$gi] as $gvaluepossiblekey => $gvaluepossiblelabel) {
1176 $ykeysuffix = $gvaluepossiblelabel;
1177 $gvalwithoutprefix = preg_replace(
'/^[a-z]+\./',
'', $gval);
1179 $fieldfory =
'y_'.$key;
1180 $fieldforg =
'g_'.$gi;
1181 $fieldforybis =
'y_'.$key.
'_'.$ykeysuffix;
1185 if (!array_key_exists($xi, $data)) {
1186 $data[$xi] = array();
1189 if (!array_key_exists(
'label', $data[$xi])) {
1190 $data[$xi] = array();
1191 $data[$xi][
'label'] = $labeltouse;
1194 $objfieldforg = $obj->$fieldforg;
1195 if (is_null($objfieldforg)) {
1196 $objfieldforg =
'__NULL__';
1199 if ($gvaluepossiblekey ==
'0') {
1201 if ($objfieldforg ==
'0') {
1203 $data[$xi][$fieldforybis] = $obj->$fieldfory;
1204 } elseif (!isset($data[$xi][$fieldforybis])) {
1206 $data[$xi][$fieldforybis] =
'0';
1210 if ((
string) $objfieldforg === (
string) $gvaluepossiblekey) {
1212 $data[$xi][$fieldforybis] = $obj->$fieldfory;
1213 } elseif (!isset($data[$xi][$fieldforybis])) {
1215 $data[$xi][$fieldforybis] =
'0';
1224 $xval = $search_xaxis[0];
1225 $fieldforxkey =
'x_0';
1226 $xlabel = $obj->$fieldforxkey;
1227 $xvalwithoutprefix = preg_replace(
'/^[a-z]+\./',
'', $xval);
1230 if (!empty(
$object->fields[$xvalwithoutprefix][
'arrayofkeyval'])) {
1231 $xlabel =
$object->fields[$xvalwithoutprefix][
'arrayofkeyval'][$obj->$fieldforxkey];
1234 $labeltouse = (($xlabel || $xlabel ==
'0') ?
dol_trunc($xlabel, 20,
'middle') : ($xlabel ===
'' ? $langs->transnoentitiesnoconv(
"Empty") : $langs->transnoentitiesnoconv(
"NotDefined")));
1235 $xarrayforallseries = array(
'label' => $labeltouse);
1236 foreach ($search_measures as $key => $val) {
1237 $fieldfory =
'y_'.$key;
1238 $xarrayforallseries[$fieldfory] = $obj->$fieldfory;
1240 $data[$xi] = $xarrayforallseries;
1245 $totalnbofrecord = count($data);
1250print
'<!-- Section to show the result -->'.
"\n";
1251print
'<div class="customreportsoutput'.($totalnbofrecord ?
'' :
' customreportsoutputnotdata').
'">';
1253if (empty($newarrayoftype)) {
1254 $langs->load(
"admin");
1255 print
info_admin($langs->trans(
"NoSupportedModulesHaveBeenActivated").
' '.$langs->trans(
"YouCanEnableModulesFrom"), 0, 0,
'info');
1258if ($mode ==
'grid') {
1262if ($mode ==
'graph') {
1264 $HEIGHT = (empty($_SESSION[
'dol_screenheight']) ? 400 : $_SESSION[
'dol_screenheight'] - 500);
1268 $mesg = $px1->isGraphKo();
1272 $px1->SetData($data);
1275 $arrayoftypes = array();
1276 foreach ($search_measures as $key => $val) {
1277 $arrayoftypes[] = $search_graph;
1280 $px1->SetLegend($legend);
1281 $px1->setShowLegend($SHOWLEGEND);
1282 $px1->SetMinValue((
int) $px1->GetFloorMinValue());
1283 $px1->SetMaxValue($px1->GetCeilMaxValue());
1284 $px1->SetWidth($WIDTH);
1285 $px1->SetHeight($HEIGHT);
1286 $px1->SetYLabel($langs->trans(
"Y"));
1287 $px1->SetShading(3);
1288 $px1->SetHorizTickIncrement(1);
1289 $px1->SetCssPrefix(
"cssboxes");
1290 $px1->SetType($arrayoftypes);
1291 $px1->mode =
'depth';
1294 $dir = $conf->user->dir_temp;
1297 if (!empty(
$object->element)) {
1298 $filenamekey = $dir.
'/customreport_'.
$object->element.(empty($customreportkey) ?
'' : $customreportkey).
'.png';
1299 $fileurlkey = DOL_URL_ROOT.
'/viewimage.php?modulepart=user&file=customreport_'.
$object->element.(empty($customreportkey) ?
'' : $customreportkey).
'.png';
1302 if (isset($filenamekey) && isset($fileurlkey)) {
1303 $px1->draw($filenamekey, $fileurlkey);
1306 $texttoshow = $langs->trans(
"NoRecordFound");
1307 if (!GETPOSTISSET(
'search_measures') || !GETPOSTISSET(
'search_xaxis')) {
1308 $texttoshow = $langs->trans(
"SelectYourGraphOptionsFirst");
1311 print $px1->show($totalnbofrecord ? 0 : $texttoshow);
1317if ($sql && !defined(
'MAIN_CUSTOM_REPORT_KEEP_GRAPH_ONLY')) {
1319 print
'<br>'.info_admin($langs->trans(
"SQLUsedForExport").
':<br> '.$sql, 0, 0,
'1',
'',
'TechnicalInformation');
1323if (!defined(
'USE_CUSTOM_REPORT_AS_INCLUDE')) {
if(! $sortfield) if(! $sortorder) $object
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
fillArrayOfGroupBy($object, $tablealias, $labelofobject, &$arrayofgroupby, $level=0, &$count=0, &$tablepath='')
Fill arrayofgroupby for an object.
fillArrayOfFilterFields($object, $tablealias, $labelofobject, &$arrayoffields, $level=0, &$count=0, &$tablepath='')
Fill array of possible filter fields for an object.
fillArrayOfMeasures($object, $tablealias, $labelofobject, &$arrayofmesures, $level=0, &$count=0, &$tablepath='')
Fill arrayofmesures for an object.
fillArrayOfXAxis($object, $tablealias, $labelofobject, &$arrayofxaxis, $level=0, &$count=0, &$tablepath='')
Fill arrayofmesures for an object.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
dolCheckFilters($sqlfilters, &$error='', &$parenthesislevel=0)
Return if a $sqlfilters parameter has a valid balance of parenthesis.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
dolForgeExplodeAnd($sqlfilters)
Explode an universal search string with AND parts.
dolExplodeIntoArray($string, $delimiter=';', $kv='=')
Split a string with 2 keys into key array.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
isModEnabled($module)
Is Dolibarr module enabled.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.