49@phan-var-force ?int[] $toselect
56if (!defined(
'USE_CUSTOM_REPORT_AS_INCLUDE')) {
57 require
'../main.inc.php';
60 $action =
GETPOST(
'action',
'aZ09') ?
GETPOST(
'action',
'aZ09') :
'view';
61 $massaction =
GETPOST(
'massaction',
'alpha');
63 $mode =
GETPOST(
'mode',
'alpha');
65 $tabfamily =
GETPOST(
'tabfamily',
'aZ09');
67 $search_measures =
GETPOST(
'search_measures',
'array:alphanohtml');
69 if (
GETPOST(
'search_xaxis',
'alpha') &&
GETPOST(
'search_xaxis',
'alpha') !=
'-1') {
70 $search_xaxis = array(
GETPOST(
'search_xaxis',
'alpha'));
72 $search_xaxis = array();
74 if (
GETPOST(
'search_groupby',
'alpha') &&
GETPOST(
'search_groupby',
'alpha') !=
'-1') {
75 $search_groupby = array(
GETPOST(
'search_groupby',
'alpha'));
77 $search_groupby = array();
79 '@phan-var-force string[] $search_groupby';
81 $search_yaxis =
GETPOST(
'search_yaxis',
'array:alphanohtml');
82 $search_graph = (
string)
GETPOST(
'search_graph',
'restricthtml');
90 function sanititzekey($value)
92 return preg_replace(
'/[^a-z0-9\._\-]+/',
'', $value);
95 $sanitized_search_measures = array_map(
'sanititzekey', $search_measures);
96 $sanitized_search_xaxis = array_map(
'sanititzekey', $search_xaxis);
97 $sanitized_search_yaxis = array_map(
'sanititzekey', $search_yaxis);
98 $sanitized_search_groupby = array_map(
'sanititzekey', $search_groupby);
102 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
103 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
105 if (empty($page) || $page == -1 ||
GETPOST(
'button_search',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha') || (empty($toselect) && $massaction ===
'0')) {
108 $offset = $limit * $page;
109 $pageprev = $page - 1;
110 $pagenext = $page + 1;
125 @phan-var-force int<0,1> $SHOWLEGEND
126 @phan-var-force string $customreportkey
127 @phan-var-force ?string $customsql
128 @phan-var-force ?string[] $sanitized_search_groupby Array with the third dimension
129 @phan-var-force int $page
130 @phan-var-force string $sortfield
131 @phan-var-force string $sortorder
136 if (empty($user) || empty($user->id)) {
137 print
'Page is called as an include but $user and its permission loaded with loadRights() are not defined. We stop here.';
141 print
'Page is called as an include but $object is not defined. We stop here.';
147global $dolibarr_allow_unsecured_select_in_extrafields_filter;
148$dolibarr_allow_unsecured_select_in_extrafields_filter = 0;
153if (!isset($sanitized_search_measures)) {
154 $sanitized_search_measures = array(0 =>
't.count');
156if (!isset($sanitized_search_xaxis)) {
158 $sanitized_search_xaxis = array();
160if (!isset($sanitized_search_yaxis)) {
162 $sanitized_search_yaxis = array();
164if (!isset($sanitized_search_groupby)) {
166 $sanitized_search_groupby = array();
168if (!isset($search_graph)) {
173 $objecttype =
$object->element.($object->module ?
'@'.$object->module :
'');
175if ((!is_string($objecttype) || empty($objecttype)) &&
isModEnabled(
'societe')) {
176 $objecttype =
'thirdparty';
178'@phan-var-force string $objecttype';
180require_once DOL_DOCUMENT_ROOT.
"/core/class/extrafields.class.php";
181require_once DOL_DOCUMENT_ROOT.
"/core/class/html.form.class.php";
182require_once DOL_DOCUMENT_ROOT.
"/core/lib/admin.lib.php";
183require_once DOL_DOCUMENT_ROOT.
"/core/lib/company.lib.php";
184require_once DOL_DOCUMENT_ROOT.
"/core/lib/date.lib.php";
185require_once DOL_DOCUMENT_ROOT.
"/core/lib/customreports.lib.php";
186require_once DOL_DOCUMENT_ROOT.
"/core/class/dolgraph.class.php";
187require_once DOL_DOCUMENT_ROOT.
"/core/class/doleditor.class.php";
188require_once DOL_DOCUMENT_ROOT.
"/core/class/html.formother.class.php";
191$langs->loadLangs(array(
"companies",
"other",
"exports",
"sendings"));
195$hookmanager->initHooks(array(
'customreport'));
200$keyforlabeloffield =
null;
202$ObjectClassName =
'';
205 'thirdparty' => array(
'label' =>
'ThirdParties',
'picto' =>
'company',
'ObjectClassName' =>
'Societe',
'enabled' =>
isModEnabled(
'societe'),
'ClassPath' =>
"/societe/class/societe.class.php",
'langs' =>
'companies'),
206 'contact' => array(
'label' =>
'Contacts',
'picto' =>
'contact',
'ObjectClassName' =>
'Contact',
'enabled' =>
isModEnabled(
'societe'),
'ClassPath' =>
"/contact/class/contact.class.php"),
207 'proposal' => array(
'label' =>
'Proposals',
'picto' =>
'proposal',
'ObjectClassName' =>
'Propal',
'enabled' =>
isModEnabled(
'propal'),
'ClassPath' =>
"/comm/propal/class/propal.class.php",
'langs' =>
'propal'),
208 'proposaldet' => array(
'label' =>
'ProposalLines',
'picto' =>
'proposal',
'ObjectClassName' =>
'PropaleLigne',
'enabled' =>
isModEnabled(
'propal'),
'ClassPath' =>
"/comm/propal/class/propaleligne.class.php",
'langs' =>
'propal'),
209 'order' => array(
'label' =>
'Orders',
'picto' =>
'order',
'ObjectClassName' =>
'Commande',
'enabled' =>
isModEnabled(
'order'),
'ClassPath' =>
"/commande/class/commande.class.php",
'langs' =>
'orders'),
210 'orderdet' => array(
'label' =>
'SaleOrderLines',
'picto' =>
'order',
'ObjectClassName' =>
'OrderLine',
'enabled' =>
isModEnabled(
'order'),
'ClassPath' =>
"/commande/class/orderline.class.php",
'langs' =>
'orders'),
211 'invoice' => array(
'label' =>
'Invoices',
'picto' =>
'bill',
'ObjectClassName' =>
'Facture',
'enabled' =>
isModEnabled(
'invoice'),
'ClassPath' =>
"/compta/facture/class/facture.class.php",
'langs' =>
'bills'),
212 'invoice_template' => array(
'label' =>
'PredefinedInvoices',
'picto' =>
'bill',
'ObjectClassName' =>
'FactureRec',
'enabled' =>
isModEnabled(
'invoice'),
'ClassPath' =>
"/compta/facture/class/facture-rec.class.php",
'langs' =>
'bills'),
213 'contract' => array(
'label' =>
'Contracts',
'picto' =>
'contract',
'ObjectClassName' =>
'Contrat',
'enabled' =>
isModEnabled(
'contract'),
'ClassPath' =>
"/contrat/class/contrat.class.php",
'langs' =>
'contracts'),
214 'contractdet' => array(
'label' =>
'ContractLines',
'picto' =>
'contract',
'ObjectClassName' =>
'ContratLigne',
'enabled' =>
isModEnabled(
'contract'),
'ClassPath' =>
"/contrat/class/contrat.class.php",
'langs' =>
'contracts'),
215 'bom' => array(
'label' =>
'BOM',
'picto' =>
'bom',
'ObjectClassName' =>
'Bom',
'enabled' =>
isModEnabled(
'bom')),
216 'mrp' => array(
'label' =>
'MO',
'picto' =>
'mrp',
'ObjectClassName' =>
'Mo',
'enabled' =>
isModEnabled(
'mrp'),
'ClassPath' =>
"/mrp/class/mo.class.php"),
217 'ticket' => array(
'label' =>
'Ticket',
'picto' =>
'ticket',
'ObjectClassName' =>
'Ticket',
'enabled' =>
isModEnabled(
'ticket')),
218 'member' => array(
'langs' =>
'members',
'label' =>
'Adherent',
'picto' =>
'member',
'ObjectClassName' =>
'Adherent',
'enabled' =>
isModEnabled(
'member'),
'ClassPath' =>
"/adherents/class/adherent.class.php"),
219 'cotisation' => array(
'langs' =>
'members',
'label' =>
'Subscriptions',
'picto' =>
'member',
'ObjectClassName' =>
'Subscription',
'enabled' =>
isModEnabled(
'member'),
'ClassPath' =>
"/adherents/class/subscription.class.php"),
224$parameters = array(
'objecttype' => $objecttype,
'tabfamily' => $tabfamily);
226$reshook = $hookmanager->executeHooks(
'loadDataForCustomReports', $parameters,
$object, $action);
229} elseif (is_array($hookmanager->resArray)) {
230 if (!empty($hookmanager->resArray[
'title'])) {
231 $title = $hookmanager->resArray[
'title'];
233 if (!empty($hookmanager->resArray[
'picto'])) {
234 $picto = $hookmanager->resArray[
'picto'];
236 if (!empty($hookmanager->resArray[
'head'])) {
237 $head = array_merge($head, $hookmanager->resArray[
'head']);
239 if (!empty($hookmanager->resArray[
'arrayoftype'])) {
240 foreach ($hookmanager->resArray[
'arrayoftype'] as $key => $val) {
241 $arrayoftype[$key] = $val;
249 if (!empty($arrayoftype[$objecttype][
'ClassPath'])) {
250 $fileforclass = $arrayoftype[$objecttype][
'ClassPath'];
252 $fileforclass =
"/".$objecttype.
"/class/".$objecttype.
".class.php";
254 $ObjectClassName =
null;
256 if ($fileforclass !==
null) {
259 $ObjectClassName = $arrayoftype[$objecttype][
'ObjectClassName'];
261 if (!empty($ObjectClassName)) {
262 if (class_exists($ObjectClassName)) {
265 print
'Failed to load class for type '.$objecttype.
'. Class file found but Class object named '.$ObjectClassName.
' not found.';
268 print
'Failed to load class for type '.$objecttype.
'. Class file name is unknown.';
271 print
'Failed to load class for type '.$objecttype.
'. Class path not found.';
275'@phan-var-force CommonObject $object';
279if ($user->socid > 0) {
285$extrafields->fetch_name_optionals_label(
'all');
288if (!empty(
$object->table_element)) {
289 $search_array_options = $extrafields->getOptionalsFromPost(
$object->table_element,
'',
'search_');
291 $search_array_options = array();
294$search_component_params = array(
'');
295$search_component_params_hidden = trim(
GETPOST(
'search_component_params_hidden',
'alphanohtml'));
296$search_component_params_input = trim(
GETPOST(
'search_component_params_input',
'alphanohtml'));
305 $value = $search_component_params_input;
307 $value = preg_replace(
'/([a-z\.]+)\s*([!<>=]+|in|notin|like|notlike)\s*/',
'\1:\2:', $value);
308 $value = preg_replace(
'/\s*\|\s*/',
'|', $value);
311 $crits = explode(
' ', trim($value));
315 foreach ($crits as $crit) {
320 $tmpcrits = explode(
'|', $crit);
322 foreach ($tmpcrits as $tmpcrit) {
323 if ($tmpcrit !==
'0' && empty($tmpcrit)) {
326 $tmpcrit = trim($tmpcrit);
330 $parenthesislevel = 0;
331 $rescheckfilter =
dolCheckFilters($tmpcrit, $errorstr, $parenthesislevel);
332 if ($rescheckfilter) {
333 while ($parenthesislevel > 0) {
334 $tmpcrit = preg_replace(
'/^\(/',
'', preg_replace(
'/\)$/',
'', $tmpcrit));
339 $field = preg_replace(
'/(:[!<>=\s]+:|:in:|:notin:|:like:|:notlike:).*$/',
'', $tmpcrit);
340 $tmpcrit = preg_replace(
'/^.*(:[!<>=\s]+:|:in:|:notin:|:like:|:notlike:)/',
'\1', $tmpcrit);
343 $newres .= (($i2 > 0 || $i3 > 0) ?
' OR ' :
'');
346 $newcrit = preg_replace(
'/(:[!<>=\s]+:|:in:|:notin:|:like:|:notlike:)/',
'', $tmpcrit);
350 preg_match(
'/:([!<>=\s]+|in|notin|like|notlike):/', $tmpcrit, $reg);
351 if (!empty($reg[1])) {
354 if ($newcrit !=
'') {
355 if (!preg_match(
'/^\'[^\']*\'$/', $newcrit)) {
357 $newres .=
'('.$field.
':'.$operator.
':'.((float) $numnewcrit).
')';
359 $newres .=
'('.$field.
':'.$operator.
":".((
string) $newcrit).
')';
367 $res = $res.($res ?
' AND ' :
'').($i2 > 1 ?
'(' :
'').$newres.($i2 > 1 ?
')' :
'');
374 $search_component_params_input = $res;
380$search_component_params_hidden = implode(
' AND ', array_merge($arrayofandtagshidden, $arrayofandtagsinput));
383$MAXUNIQUEVALFORGROUP = 20;
384$MAXMEASURESINBARGRAPH = 20;
385$SHOWLEGEND = (isset($SHOWLEGEND) ? $SHOWLEGEND : 1);
387$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);
388$MM = substr($langs->trans(
"Month"), 0, 1).substr($langs->trans(
"Month"), 0, 1);
389$DD = substr($langs->trans(
"Day"), 0, 1).substr($langs->trans(
"Day"), 0, 1);
390$HH = substr($langs->trans(
"Hour"), 0, 1).substr($langs->trans(
"Hour"), 0, 1);
391$MI = substr($langs->trans(
"Minute"), 0, 1).substr($langs->trans(
"Minute"), 0, 1);
392$SS = substr($langs->trans(
"Second"), 0, 1).substr($langs->trans(
"Second"), 0, 1);
394$arrayoffilterfields = array();
395$arrayofmesures = array();
396$arrayofxaxis = array();
397$arrayofgroupby = array();
398$arrayofyaxis = array();
399$arrayofvaluesforgroupby = array();
407if (!empty(
$object->element_for_permission)) {
408 $features =
$object->element_for_permission;
410 $features .= (empty(
$object->module) ?
'' :
'@'.$object->module);
417$resultcheck =
restrictedArea($user, $features, 0,
'',
'',
'fk_soc',
'rowid', 0, 1);
435if (!defined(
'USE_CUSTOM_REPORT_AS_INCLUDE')) {
436 llxHeader(
'', $langs->transnoentitiesnoconv(
'CustomReports'),
'');
446$newarrayoftype = array();
447foreach ($arrayoftype as $key => $val) {
448 if (
dol_eval((
string) $val[
'enabled'], 1, 1,
'1')) {
449 $newarrayoftype[$key] = $arrayoftype[$key];
451 if (!empty($val[
'langs'])) {
452 $langs->load($val[
'langs']);
458if (array_key_exists($objecttype, $newarrayoftype)) {
459 $label = $langs->trans($newarrayoftype[$objecttype][
'label']);
462$arrayoffilterfields =
dol_sort_array($arrayoffilterfields,
'position',
'asc', 0, 0, 1);
466$arrayofmesures =
dol_sort_array($arrayofmesures,
'position',
'asc', 0, 0, 1);
470$arrayofxaxis =
dol_sort_array($arrayofxaxis,
'position',
'asc', 0, 0, 1);
474$arrayofgroupby =
dol_sort_array($arrayofgroupby,
'position',
'asc', 0, 0, 1);
478if ($action ==
'viewgraph') {
479 if (!count($sanitized_search_measures)) {
480 setEventMessages($langs->trans(
"AtLeastOneMeasureIsRequired"),
null,
'warnings');
481 } elseif ($mode ==
'graph' && is_array($sanitized_search_xaxis) && count($sanitized_search_xaxis) > 1) {
482 setEventMessages($langs->trans(
"OnlyOneFieldForXAxisIsPossible"),
null,
'warnings');
483 $sanitized_search_xaxis = array(0 => $sanitized_search_xaxis[0]);
485 if (count($sanitized_search_groupby) >= 2) {
486 setEventMessages($langs->trans(
"ErrorOnlyOneFieldForGroupByIsPossible"),
null,
'warnings');
487 $sanitized_search_groupby = array(0 => $sanitized_search_groupby[0]);
489 if (!count($sanitized_search_xaxis)) {
490 setEventMessages($langs->trans(
"AtLeastOneXAxisIsRequired"),
null,
'warnings');
491 } elseif ($mode ==
'graph' && $search_graph ==
'bars' && count($sanitized_search_measures) > $MAXMEASURESINBARGRAPH) {
492 $langs->load(
"errors");
493 setEventMessages($langs->trans(
"GraphInBarsAreLimitedToNMeasures", $MAXMEASURESINBARGRAPH),
null,
'warnings');
494 $search_graph =
'lines';
500if (count($sanitized_search_groupby)) {
502 foreach ($sanitized_search_groupby as $gkey => $sanitized_gval) {
503 $gvalwithoutprefix = preg_replace(
'/^[a-z]+\./i',
'', $sanitized_gval);
504 $gvalsanitized = preg_replace(
'/[^a-z0-9\._\-]+/i',
'', $sanitized_gval);
506 $sanitizedfieldtocount =
'';
508 if (preg_match(
'/\-year$/', $gvalsanitized)) {
509 $tmpval = preg_replace(
'/\-year$/',
'', $gvalsanitized);
510 $sanitizedfieldtocount .=
'DATE_FORMAT('.$tmpval.
", '%Y')";
511 } elseif (preg_match(
'/\-month$/', $gvalsanitized)) {
512 $tmpval = preg_replace(
'/\-month$/',
'', $gvalsanitized);
513 $sanitizedfieldtocount .=
'DATE_FORMAT('.$tmpval.
", '%Y-%m')";
514 } elseif (preg_match(
'/\-day$/', $gvalsanitized)) {
515 $tmpval = preg_replace(
'/\-day$/',
'', $gvalsanitized);
516 $sanitizedfieldtocount .=
'DATE_FORMAT('.$tmpval.
", '%Y-%m-%d')";
518 $sanitizedfieldtocount = $gvalsanitized;
521 $fieldtocount = $sanitizedfieldtocount;
522 $sql =
"SELECT DISTINCT ".$sanitizedfieldtocount.
" as val";
524 if (strpos($fieldtocount,
'te') === 0) {
525 $tabletouse =
$object->table_element;
526 $tablealiastouse =
'te';
527 if (!empty($arrayofgroupby[$sanitized_gval])) {
528 $tmpval = explode(
'.', $sanitized_gval);
529 $tabletouse = $arrayofgroupby[$sanitized_gval][
'table'];
530 $tablealiastouse = $tmpval[0];
535 $sql .=
" FROM ".MAIN_DB_PREFIX.$tabletouse.
"_extrafields as ".$tablealiastouse;
537 $tabletouse =
$object->table_element;
538 $tablealiastouse =
't';
539 if (!empty($arrayofgroupby[$sanitized_gval])) {
540 $tmpval = explode(
'.', $sanitized_gval);
541 $tabletouse = $arrayofgroupby[$sanitized_gval][
'table'];
542 $tablealiastouse = $tmpval[0];
544 $sql .=
" FROM ".MAIN_DB_PREFIX.$tabletouse.
" as ".$tablealiastouse;
555 $sql .=
" LIMIT ".((int) ($MAXUNIQUEVALFORGROUP + 1));
558 $resql =
$db->query($sql);
563 while ($obj =
$db->fetch_object($resql)) {
564 if (is_null($obj->val)) {
565 $keytouse =
'__NULL__';
566 $valuetranslated = $langs->transnoentitiesnoconv(
"NotDefined");
567 } elseif ($obj->val ===
'') {
569 $valuetranslated = $langs->transnoentitiesnoconv(
"Empty");
571 $keytouse = (
string) $obj->val;
572 $valuetranslated = $obj->val;
576 if (isset(
$object->fields[$gvalwithoutprefix])) {
577 if (!empty(
$object->fields[$gvalwithoutprefix][
'arrayofkeyval'])) {
578 $valuetranslated =
$object->fields[$gvalwithoutprefix][
'arrayofkeyval'][$obj->val];
579 if (is_null($valuetranslated)) {
580 $valuetranslated = $langs->transnoentitiesnoconv(
"UndefinedKey");
582 $valuetranslated = $langs->trans($valuetranslated);
583 } elseif (preg_match(
'/integer:([^:]+):([^:]+)$/',
$object->fields[$gvalwithoutprefix][
'type'], $regs)) {
584 $classname = $regs[1];
585 $classpath = $regs[2];
587 if (class_exists($classname)) {
588 $tmpobject =
new $classname(
$db);
589 '@phan-var-force CommonObject $tmpobject';
590 $tmpobject->fetch($obj->val);
591 foreach ($tmpobject->fields as $fieldkey => $field) {
592 if ($field[
'showoncombobox']) {
593 $valuetranslated = $tmpobject->$fieldkey;
603 $arrayofvaluesforgroupby[
'g_'.$gkey][$keytouse] = $valuetranslated;
606 $tmpfield = explode(
'.', $sanitized_gval);
607 if ($tmpfield[0] !=
't' || (isset(
$object->fields[$tmpfield[1]]) && is_array(
$object->fields[$tmpfield[1]]) && empty(
$object->fields[$tmpfield[1]][
'notnull']))) {
608 dol_syslog(
"The group by field ".$sanitized_gval.
" may be null (because field is null or it is a left join), so we add __NULL__ entry in list of possible values");
610 $arrayofvaluesforgroupby[
'g_'.$gkey][
'__NULL__'] = $langs->transnoentitiesnoconv(
"NotDefined");
613 if (is_array($arrayofvaluesforgroupby[
'g_'.$gkey])) {
614 asort($arrayofvaluesforgroupby[
'g_'.$gkey]);
618 if (is_array($arrayofvaluesforgroupby[
'g_'.$gkey]) && count($arrayofvaluesforgroupby[
'g_'.$gkey]) > $MAXUNIQUEVALFORGROUP) {
619 $langs->load(
"errors");
621 if (strpos($fieldtocount,
'te') === 0) {
625 $keyforlabeloffield = $extrafields->attributes[
$object->table_element][
'label'][$gvalwithoutprefix];
626 $labeloffield = $langs->transnoentitiesnoconv($keyforlabeloffield);
627 } elseif (strpos($fieldtocount,
't__') === 0) {
629 if (preg_match(
'/^(.*)\.(.*)/', $gvalwithoutprefix, $reg)) {
636 $labeloffield = $arrayofgroupby[$fieldtocount][
'labelnohtml'];
638 $labeloffield =
'FK_ISSUE';
642 if (preg_match(
'/^(.*)\-(year|month|day)/', $gvalwithoutprefix, $reg)) {
643 $gvalwithoutprefix = preg_replace(
'/\-(year|month|day)/',
'', $gvalwithoutprefix);
644 $keyforlabeloffield =
$object->fields[$gvalwithoutprefix][
'label'];
645 $labeloffield = $langs->transnoentitiesnoconv($keyforlabeloffield).
'-'.$reg[2];
647 $keyforlabeloffield =
$object->fields[$gvalwithoutprefix][
'label'];
648 $labeloffield = $langs->transnoentitiesnoconv($keyforlabeloffield);
652 setEventMessages($langs->transnoentitiesnoconv(
"ErrorTooManyDifferentValueForSelectedGroupBy", (
string) $MAXUNIQUEVALFORGROUP, (
string) $labeloffield),
null,
'warnings');
653 $sanitized_search_groupby = array();
663 print
'<div class="error">';
664 print $langs->trans(
"NotEnoughPermissions");
679if (!defined(
'MAIN_CUSTOM_REPORT_KEEP_GRAPH_ONLY')) {
680 print
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'" autocomplete="off">';
681 print
'<input type="hidden" name="token" value="'.newToken().
'">';
682 print
'<input type="hidden" name="action" value="viewgraph">';
683 print
'<input type="hidden" name="tabfamily" value="'.(string) $tabfamily.
'">';
687 $viewmode .=
'<div class="divadvancedsearchfield">';
688 $arrayofgraphs = array(
'bars' =>
'Bars',
'lines' =>
'Lines');
689 $viewmode .=
'<div class="inline-block opacitymedium"><span class="fas fa-chart-area paddingright" title="'.$langs->trans(
"Graph").
'"></span>'.$langs->trans(
"Graph").
'</div> ';
690 $viewmode .= $form->selectarray(
'search_graph', $arrayofgraphs, $search_graph, 0, 0, 0,
'', 1, 0, 0,
'',
'graphtype width100');
691 $viewmode .=
'</div>';
694 $massactionbutton =
'';
699 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);
702 foreach ($newarrayoftype as $tmpkey => $tmpval) {
703 $newarrayoftype[$tmpkey][
'data-html'] =
img_picto(
'', $tmpval[
'picto'],
'class="pictofixedwidth"').$langs->trans($tmpval[
'label']);
704 $newarrayoftype[$tmpkey][
'label'] = $langs->trans($tmpval[
'label']);
707 print
'<div class="liste_titre liste_titre_bydiv liste_titre_bydiv_inlineblock liste_titre_bydiv_nothingafter centpercent">';
710 print
'<div class="divadvancedsearchfield center floatnone">';
711 print
'<div class="inline-block"><span class="opacitymedium">'.$langs->trans(
"StatisticsOn").
'</span></div> ';
713 print $form->selectarray(
'objecttype', $newarrayoftype, $objecttype, 0, 0, 0,
'', 1, 0, 0,
'',
'minwidth250', 1,
'', 0, 1);
714 if (empty(
$conf->use_javascript_ajax)) {
715 print
'<input type="submit" class="button buttongen button-save nomargintop" name="changeobjecttype" value="'.$langs->trans(
"Refresh").
'">';
717 print
'<!-- js code to reload page with good object type -->
718 <script nonce="'.getNonce().
'" type="text/javascript">
719 jQuery(document).ready(function() {
720 jQuery("#objecttype").change(function() {
721 console.log("Reload for "+jQuery("#objecttype").val());
722 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')) :
'').
'";
727 print
'</div><div class="clearboth"></div>';
729 if (!empty($newarrayoftype)) {
732 print
'<div class="divadvancedsearchfield">';
733 print $form->searchComponent(array(
$object->element =>
$object->fields), $search_component_params, array(), $search_component_params_hidden, $arrayoffilterfields);
740 print
'<div class="divadvancedsearchfield clearboth">';
741 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>';
742 $simplearrayofmesures = array();
743 foreach ($arrayofmesures as $key => $val) {
744 $simplearrayofmesures[$key] = $arrayofmesures[$key][
'label'];
746 print $form->multiselectarray(
'search_measures', $simplearrayofmesures, $sanitized_search_measures, 0, 0,
'minwidth300 widthcentpercentminusx', 1, 0,
'',
'', $langs->transnoentitiesnoconv(
"Measures"));
751 print
'<div class="divadvancedsearchfield">';
752 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>';
754 print $formother->selectXAxisField(
$object, $sanitized_search_xaxis, $arrayofxaxis, $langs->trans(
"XAxis"),
'minwidth300 maxwidth400 widthcentpercentminusx');
759 print
'<div class="divadvancedsearchfield">';
760 print
'<div class="inline-block opacitymedium"><span class="fas fa-ruler-horizontal paddingright pictofixedwidth" title="'.dol_escape_htmltag($langs->trans(
"GroupBy")).
'"></span></div>';
761 print $formother->selectGroupByField(
$object, $sanitized_search_groupby, $arrayofgroupby,
'minwidth250 maxwidth300 widthcentpercentminusx', $langs->trans(
"GroupBy"));
765 if ($mode ==
'grid') {
767 print
'<div class="divadvancedsearchfield">';
768 foreach (
$object->fields as $key => $val) {
769 if (empty($val[
'measure']) && (!isset($val[
'enabled']) ||
dol_eval((
string) $val[
'enabled'], 1, 1,
'1'))) {
770 if (in_array($key, array(
'id',
'rowid',
'entity',
'last_main_doc',
'extraparams'))) {
773 if (preg_match(
'/^fk_/', $key)) {
776 if (in_array($val[
'type'], array(
'html',
'text'))) {
779 if (in_array($val[
'type'], array(
'timestamp',
'date',
'datetime'))) {
780 $arrayofyaxis[
't.'.$key.
'-year'] = array(
781 'label' => $langs->trans($val[
'label']).
' ('.$YYYY.
')',
782 'position' => $val[
'position'],
783 'table' =>
$object->table_element
785 $arrayofyaxis[
't.'.$key.
'-month'] = array(
786 'label' => $langs->trans($val[
'label']).
' ('.$YYYY.
'-'.$MM.
')',
787 'position' => $val[
'position'],
788 'table' =>
$object->table_element
790 $arrayofyaxis[
't.'.$key.
'-day'] = array(
791 'label' => $langs->trans($val[
'label']).
' ('.$YYYY.
'-'.$MM.
'-'.$DD.
')',
792 'position' => $val[
'position'],
793 'table' =>
$object->table_element
796 $arrayofyaxis[
't.'.$key] = array(
797 'label' => $val[
'label'],
798 'position' => (
int) $val[
'position'],
799 'table' =>
$object->table_element
805 if (
$object->isextrafieldmanaged) {
806 foreach ($extrafields->attributes[
$object->table_element][
'label'] as $key => $val) {
807 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'))) {
808 $arrayofyaxis[
'te.'.$key] = array(
809 'label' => $extrafields->attributes[
$object->table_element][
'label'][$key],
810 'position' => (
int) $extrafields->attributes[
$object->table_element][
'pos'][$key],
811 'table' =>
$object->table_element
817 $arrayofyaxislabel = array();
818 foreach ($arrayofyaxis as $key => $val) {
819 $arrayofyaxislabel[$key] = $val[
'label'];
821 print
'<div class="inline-block opacitymedium"><span class="fas fa-ruler-vertical paddingright" title="'.$langs->trans(
"YAxis").
'"></span>'.$langs->trans(
"YAxis").
'</div> ';
822 print $form->multiselectarray(
'search_yaxis', $arrayofyaxislabel, $sanitized_search_yaxis !=
null ? $sanitized_search_yaxis : array(), 0, 0,
'minwidth100', 1);
826 if (!empty($newarrayoftype)) {
827 print
'<div class="divadvancedsearchfield">';
828 print
'<input type="submit" class="button buttongen button-save nomargintop" value="'.$langs->trans(
"Refresh").
'">';
838if (!empty($sanitized_search_measures) && !empty($sanitized_search_xaxis)) {
844 foreach ($sanitized_search_xaxis as $sql_key => $sql_val) {
845 if (preg_match(
'/\-year$/', $sql_val)) {
846 $sql_tmpval = preg_replace(
'/\-year$/',
'', $sql_val);
847 $sql .=
"DATE_FORMAT(".$sql_tmpval.
", '%Y') as x_".$sql_key.
', ';
848 } elseif (preg_match(
'/\-month$/', $sql_val)) {
849 $sql_tmpval = preg_replace(
'/\-month$/',
'', $sql_val);
850 $sql .=
"DATE_FORMAT(".$sql_tmpval.
", '%Y-%m') as x_".$sql_key.
', ';
851 } elseif (preg_match(
'/\-day$/', $sql_val)) {
852 $sql_tmpval = preg_replace(
'/\-day$/',
'', $sql_val);
853 $sql .=
"DATE_FORMAT(".$sql_tmpval.
", '%Y-%m-%d') as x_".$sql_key.
', ';
855 $sql .= $sql_val.
" as x_".$sql_key.
", ";
858 if (!empty($sanitized_search_groupby)) {
859 foreach ($sanitized_search_groupby as $sql_key => $sql_val) {
860 if (preg_match(
'/\-year$/', $sql_val)) {
861 $sql_tmpval = preg_replace(
'/\-year$/',
'', $sql_val);
862 $sql .=
"DATE_FORMAT(".$sql_tmpval.
", '%Y') as g_".$sql_key.
', ';
863 } elseif (preg_match(
'/\-month$/', $sql_val)) {
864 $sql_tmpval = preg_replace(
'/\-month$/',
'', $sql_val);
865 $sql .=
"DATE_FORMAT(".$sql_tmpval.
", '%Y-%m') as g_".$sql_key.
', ';
866 } elseif (preg_match(
'/\-day$/', $sql_val)) {
867 $sql_tmpval = preg_replace(
'/\-day$/',
'', $sql_val);
868 $sql .=
"DATE_FORMAT(".$sql_tmpval.
", '%Y-%m-%d') as g_".$sql_key.
', ';
870 $sql .= $sql_val.
" as g_".$sql_key.
", ";
874 foreach ($sanitized_search_measures as $sql_key => $sql_val) {
875 if ($sql_val ==
't.count') {
876 $sql .=
"COUNT(t.".$fieldid.
") as y_".$sql_key.
', ';
877 } elseif (preg_match(
'/\-sum$/', $sql_val)) {
878 $sql_tmpval = preg_replace(
'/\-sum$/',
'', $sql_val);
879 $sql .=
"SUM(".$db->ifsql($sql_tmpval.
' IS NULL',
'0', $sql_tmpval).
") as y_".$sql_key.
", ";
880 } elseif (preg_match(
'/\-average$/', $sql_val)) {
881 $sql_tmpval = preg_replace(
'/\-average$/',
'', $sql_val);
882 $sql .=
"AVG(".$db->ifsql($sql_tmpval.
' IS NULL',
'0', $sql_tmpval).
") as y_".$sql_key.
", ";
883 } elseif (preg_match(
'/\-min$/', $sql_val)) {
884 $sql_tmpval = preg_replace(
'/\-min$/',
'', $sql_val);
885 $sql .=
"MIN(".$db->ifsql($sql_tmpval.
' IS NULL',
'0', $sql_tmpval).
") as y_".$sql_key.
", ";
886 } elseif (preg_match(
'/\-max$/', $sql_val)) {
887 $sql_tmpval = preg_replace(
'/\-max$/',
'', $sql_val);
888 $sql .=
"MAX(".$db->ifsql($sql_tmpval.
' IS NULL',
'0', $sql_tmpval).
") as y_".$sql_key.
", ";
889 } elseif (preg_match(
'/\-stddevpop$/', $sql_val)) {
890 $sql_tmpval = preg_replace(
'/\-stddevpop$/',
'', $sql_val);
891 $sql .=
"STDDEV_POP(".$db->ifsql($sql_tmpval.
' IS NULL',
'0', $sql_tmpval).
") as y_".$sql_key.
", ";
894 $sql = preg_replace(
'/,\s*$/',
'', $sql);
895 $sql .=
" FROM ".MAIN_DB_PREFIX.$object->table_element.
" as t";
897 if (
$object->isextrafieldmanaged) {
898 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element.
"_extrafields as te ON te.fk_object = t.".$fieldid;
901 if (
$object->ismultientitymanaged) {
902 if (
$object->ismultientitymanaged == 1) {
905 $tmparray = explode(
'@',
$object->ismultientitymanaged);
906 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.$db->sanitize($tmparray[1]).
" as parenttableforentity ON t.".
$db->sanitize($tmparray[0]).
" = parenttableforentity.rowid";
907 $sql .=
" AND parenttableforentity.entity IN (".getEntity($tmparray[1]).
")";
912 $listoftablesalreadyadded = array(
$object->table_element =>
$object->table_element);
916 foreach ($sanitized_search_xaxis as $key => $val) {
917 if (!empty($arrayofxaxis[$val])) {
918 $tmpval = explode(
'.', $val);
921 foreach ($tmpforloop as $tmptable => $tmptablealias) {
922 if (! in_array($tmptable, $listoftablesalreadyadded)) {
923 $tmpforexplode = explode(
'__', $tmptablealias);
924 $endpart = end($tmpforexplode);
925 $parenttableandfield = preg_replace(
'/__'.$endpart.
'$/',
'', $tmptablealias).
'.'.$endpart;
927 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$tmptable.
" as ".
$db->sanitize($tmptablealias).
" ON ".
$db->sanitize($parenttableandfield).
" = ".
$db->sanitize($tmptablealias).
".rowid";
928 $listoftablesalreadyadded[$tmptable] = $tmptable;
930 if (preg_match(
'/^te/', $tmpval[0]) && preg_replace(
'/^t_/',
'te_', $tmptablealias) == $tmpval[0]) {
931 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$tmptable.
"_extrafields as ".
$db->sanitize($tmpval[0]).
" ON ".
$db->sanitize($tmpval[0]).
".fk_object = ".
$db->sanitize($tmptablealias).
".rowid";
932 $listoftablesalreadyadded[$tmptable] = $tmptable;
937 $errormessage =
'Found a key into search_xaxis not found into arrayofxaxis';
943 foreach ($sanitized_search_groupby as $key => $val) {
944 if (!empty($arrayofgroupby[$val])) {
945 $tmpval = explode(
'.', $val);
948 foreach ($tmpforloop as $tmptable => $tmptablealias) {
949 if (! in_array($tmptable, $listoftablesalreadyadded)) {
950 $tmpforexplode = explode(
'__', $tmptablealias);
951 $endpart = end($tmpforexplode);
952 $parenttableandfield = preg_replace(
'/__'.$endpart.
'$/',
'', $tmptablealias).
'.'.$endpart;
954 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$tmptable.
" as ".
$db->sanitize($tmptablealias).
" ON ".
$db->sanitize($parenttableandfield).
" = ".
$db->sanitize($tmptablealias).
".rowid";
955 $listoftablesalreadyadded[$tmptable] = $tmptable;
957 if (preg_match(
'/^te/', $tmpval[0]) && preg_replace(
'/^t_/',
'te_', $tmptablealias) == $tmpval[0]) {
958 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$tmptable.
"_extrafields as ".
$db->sanitize($tmpval[0]).
" ON ".
$db->sanitize($tmpval[0]).
".fk_object = ".
$db->sanitize($tmptablealias).
".rowid";
959 $listoftablesalreadyadded[$tmptable] = $tmptable;
964 $errormessage =
'Found a key into search_groupby not found into arrayofgroupby';
970 foreach ($sanitized_search_measures as $key => $val) {
971 if (!empty($arrayofmesures[$val])) {
972 $tmpval = explode(
'.', $val);
975 foreach ($tmpforloop as $tmptable => $tmptablealias) {
976 if (! in_array($tmptable, $listoftablesalreadyadded)) {
977 $tmpforexplode = explode(
'__', $tmptablealias);
978 $endpart = end($tmpforexplode);
979 $parenttableandfield = preg_replace(
'/__'.$endpart.
'$/',
'', $tmptablealias).
'.'.$endpart;
981 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$tmptable.
" as ".
$db->sanitize($tmptablealias).
" ON ".
$db->sanitize($parenttableandfield).
" = ".
$db->sanitize($tmptablealias).
".rowid";
982 $listoftablesalreadyadded[$tmptable] = $tmptable;
984 if (preg_match(
'/^te/', $tmpval[0]) && preg_replace(
'/^t_/',
'te_', $tmptablealias) == $tmpval[0]) {
985 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$tmptable.
"_extrafields as ".
$db->sanitize($tmpval[0]).
" ON ".
$db->sanitize($tmpval[0]).
".fk_object = ".
$db->sanitize($tmptablealias).
".rowid";
986 $listoftablesalreadyadded[$tmptable] = $tmptable;
991 $errormessage =
'Found a key into search_measures not found into arrayofmesures';
996 if (!empty($search_component_params_hidden)) {
999 preg_match_all(
'/\b(t[\w]*_[\w]*)\.(\w+(-\w+)?)/', $search_component_params_hidden, $matches);
1000 $fieldsUsedInFilter = array_unique($matches[0]);
1003 $fieldsToRemove = array_merge($sanitized_search_measures, $sanitized_search_groupby, $sanitized_search_xaxis);
1004 $fieldsUsedInFilter = array_diff($fieldsUsedInFilter, $fieldsToRemove);
1006 foreach ($fieldsUsedInFilter as $key => $val) {
1007 if (!empty($arrayoffilterfields[$val])) {
1008 $tmpval = explode(
'.', $val);
1010 foreach ($tmpforloop as $tmptable => $tmptablealias) {
1011 if (! in_array($tmptable, $listoftablesalreadyadded)) {
1012 $tmpforexplode = explode(
'__', $tmptablealias);
1013 $endpart = end($tmpforexplode);
1014 $parenttableandfield = preg_replace(
'/__'.$endpart.
'$/',
'', $tmptablealias).
'.'.$endpart;
1016 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$tmptable.
" as ".
$db->sanitize($tmptablealias).
" ON ".
$db->sanitize($parenttableandfield).
" = ".
$db->sanitize($tmptablealias).
".rowid";
1017 $listoftablesalreadyadded[$tmptable] = $tmptable;
1019 if (preg_match(
'/^te/', $tmpval[0]) && preg_replace(
'/^t_/',
'te_', $tmptablealias) == $tmpval[0]) {
1020 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$tmptable.
"_extrafields as ".
$db->sanitize($tmpval[0]).
" ON ".
$db->sanitize($tmpval[0]).
".fk_object = ".
$db->sanitize($tmptablealias).
".rowid";
1021 $listoftablesalreadyadded[$tmptable] = $tmptable;
1026 $errormessage =
'Found a key into search_filterfields not found into arrayoffilterfields';
1031 $sql .=
" WHERE 1 = 1";
1032 if (
$object->ismultientitymanaged == 1) {
1033 $sql .=
" AND t.entity IN (".getEntity(
$object->element).
")";
1036 if ($search_component_params_hidden) {
1040 $sql = preg_replace_callback(
1041 "/(\w+)\.(\w+)\s*(=|!=|<>|<|>|<=|>=)\s*'(\d{4})-(\d{2})-(\d{2})'/",
1046 static function (array $matches):
string {
1048 '@phan-var-force DoliDB $db';
1049 $column = $matches[1] .
'.' . $matches[2];
1050 $operator = $matches[3];
1051 $year = (int) $matches[4];
1052 $month = (int) $matches[5];
1053 $day = (int) $matches[6];
1055 $startOfDay =
$db->idate(
dol_mktime(0, 0, 0, $month, $day, $year));
1056 $endOfDay =
$db->idate(
dol_mktime(23, 59, 59, $month, $day, $year));
1058 switch ($operator) {
1060 return "($column >= '$startOfDay' AND $column <= '$endOfDay')";
1063 return "NOT ($column >= '$startOfDay' AND $column <= '$endOfDay')";
1065 return "$column < '$startOfDay'";
1067 return "$column > '$endOfDay'";
1069 return "$column <= '$endOfDay'";
1071 return "$column >= '$startOfDay'";
1079 $sql .=
" GROUP BY ";
1080 foreach ($sanitized_search_xaxis as $key => $sanitized_val) {
1081 if (preg_match(
'/\-year$/', $sanitized_val)) {
1082 $sanitized_tmpval = preg_replace(
'/\-year$/',
'', $sanitized_val);
1083 $sql .=
"DATE_FORMAT(".$sanitized_tmpval.
", '%Y'), ";
1084 } elseif (preg_match(
'/\-month$/', $sanitized_val)) {
1085 $sanitized_tmpval = preg_replace(
'/\-month$/',
'', $sanitized_val);
1086 $sql .=
"DATE_FORMAT(".$sanitized_tmpval.
", '%Y-%m'), ";
1087 } elseif (preg_match(
'/\-day$/', $sanitized_val)) {
1088 $sanitized_tmpval = preg_replace(
'/\-day$/',
'', $sanitized_val);
1089 $sql .=
"DATE_FORMAT(".$sanitized_tmpval.
", '%Y-%m-%d'), ";
1091 $sql .= $sanitized_val.
", ";
1094 if (!empty($sanitized_search_groupby)) {
1095 foreach ($sanitized_search_groupby as $key => $sanitized_val) {
1096 if (preg_match(
'/\-year$/', $sanitized_val)) {
1097 $sanitized_tmpval = preg_replace(
'/\-year$/',
'', $sanitized_val);
1098 $sql .=
"DATE_FORMAT(".$sanitized_tmpval.
", '%Y'), ";
1099 } elseif (preg_match(
'/\-month$/', $sanitized_val)) {
1100 $sanitized_tmpval = preg_replace(
'/\-month$/',
'', $sanitized_val);
1101 $sql .=
"DATE_FORMAT(".$sanitized_tmpval.
", '%Y-%m'), ";
1102 } elseif (preg_match(
'/\-day$/', $sanitized_val)) {
1103 $sanitized_tmpval = preg_replace(
'/\-day$/',
'', $sanitized_val);
1104 $sql .=
"DATE_FORMAT(".$sanitized_tmpval.
", '%Y-%m-%d'), ";
1106 $sql .= $sanitized_val.
', ';
1110 $sql = preg_replace(
'/,\s*$/',
'', $sql);
1111 $sql .=
' ORDER BY ';
1112 foreach ($sanitized_search_xaxis as $key => $sanitized_val) {
1113 if (preg_match(
'/\-year$/', $sanitized_val)) {
1114 $sanitized_tmpval = preg_replace(
'/\-year$/',
'', $sanitized_val);
1115 $sql .=
"DATE_FORMAT(".$sanitized_tmpval.
", '%Y'), ";
1116 } elseif (preg_match(
'/\-month$/', $sanitized_val)) {
1117 $sanitized_tmpval = preg_replace(
'/\-month$/',
'', $sanitized_val);
1118 $sql .=
"DATE_FORMAT(".$sanitized_tmpval.
", '%Y-%m'), ";
1119 } elseif (preg_match(
'/\-day$/', $sanitized_val)) {
1120 $sanitized_tmpval = preg_replace(
'/\-day$/',
'', $sanitized_val);
1121 $sql .=
"DATE_FORMAT(".$sanitized_tmpval.
", '%Y-%m-%d'), ";
1123 $sql .= $sanitized_val.
', ';
1126 if (!empty($sanitized_search_groupby)) {
1127 foreach ($sanitized_search_groupby as $key => $sanitized_val) {
1128 if (preg_match(
'/\-year$/', $sanitized_val)) {
1129 $sanitized_tmpval = preg_replace(
'/\-year$/',
'', $sanitized_val);
1130 $sql .=
"DATE_FORMAT(".$sanitized_tmpval.
", '%Y'), ";
1131 } elseif (preg_match(
'/\-month$/', $sanitized_val)) {
1132 $sanitized_tmpval = preg_replace(
'/\-month$/',
'', $sanitized_val);
1133 $sql .=
"DATE_FORMAT(".$sanitized_tmpval.
", '%Y-%m'), ";
1134 } elseif (preg_match(
'/\-day$/', $sanitized_val)) {
1135 $sanitized_tmpval = preg_replace(
'/\-day$/',
'', $sanitized_val);
1136 $sql .=
"DATE_FORMAT(".$sanitized_tmpval.
", '%Y-%m-%d'), ";
1138 $sql .= $sanitized_val.
', ';
1142 $sql = preg_replace(
'/,\s*$/',
'', $sql);
1145 if (!empty($customsql)) {
1152 print
'<div class="warning">';
1160foreach ($sanitized_search_measures as $key => $val) {
1161 $legend[] = $langs->trans($arrayofmesures[$val][
'label']);
1164$useagroupby = count($sanitized_search_groupby);
1169$totalnbofrecord = 0;
1172 $resql =
$db->query($sql);
1174 print
'<div class="warning">';
1181 $oldlabeltouse =
'';
1182 while ($obj =
$db->fetch_object($resql)) {
1185 $xval = $sanitized_search_xaxis[0];
1186 $fieldforxkey =
'x_0';
1187 $xlabel = $obj->$fieldforxkey;
1188 $xvalwithoutprefix = preg_replace(
'/^[a-z]+\./',
'', $xval);
1191 if (!empty(
$object->fields[$xvalwithoutprefix][
'arrayofkeyval'])) {
1192 $xlabel =
$object->fields[$xvalwithoutprefix][
'arrayofkeyval'][$obj->$fieldforxkey];
1194 $labeltouse = (($xlabel || $xlabel ==
'0') ?
dol_trunc($xlabel, 20,
'middle') : ($xlabel ===
'' ? $langs->transnoentitiesnoconv(
"Empty") : $langs->transnoentitiesnoconv(
"NotDefined")));
1196 if ($oldlabeltouse !==
'' && ($labeltouse != $oldlabeltouse)) {
1200 $oldlabeltouse = $labeltouse;
1213 foreach ($sanitized_search_measures as $key => $val) {
1215 foreach ($sanitized_search_groupby as $gkey => $gval) {
1218 foreach ($arrayofvaluesforgroupby[
'g_'.$gi] as $gvaluepossiblekey => $gvaluepossiblelabel) {
1219 $ykeysuffix = $gvaluepossiblelabel;
1220 $gvalwithoutprefix = preg_replace(
'/^[a-z]+\./',
'', $gval);
1222 $fieldfory =
'y_'.$key;
1223 $fieldforg =
'g_'.$gi;
1224 $fieldforybis =
'y_'.$key.
'_'.$ykeysuffix;
1228 if (!array_key_exists($xi, $data)) {
1229 $data[$xi] = array();
1232 if (!array_key_exists(
'label', $data[$xi])) {
1233 $data[$xi] = array();
1234 $data[$xi][
'label'] = $labeltouse;
1237 $objfieldforg = $obj->$fieldforg;
1238 if (is_null($objfieldforg)) {
1239 $objfieldforg =
'__NULL__';
1242 if ($gvaluepossiblekey ==
'0') {
1244 if ($objfieldforg ==
'0') {
1246 $data[$xi][$fieldforybis] = $obj->$fieldfory;
1247 } elseif (!isset($data[$xi][$fieldforybis])) {
1249 $data[$xi][$fieldforybis] =
'0';
1253 if ((
string) $objfieldforg === (
string) $gvaluepossiblekey) {
1255 $data[$xi][$fieldforybis] = $obj->$fieldfory;
1256 } elseif (!isset($data[$xi][$fieldforybis])) {
1258 $data[$xi][$fieldforybis] =
'0';
1267 $xval = $sanitized_search_xaxis[0];
1268 $fieldforxkey =
'x_0';
1269 $xlabel = $obj->$fieldforxkey;
1270 $xvalwithoutprefix = preg_replace(
'/^[a-z]+\./',
'', $xval);
1273 if (!empty(
$object->fields[$xvalwithoutprefix][
'arrayofkeyval'])) {
1274 $xlabel =
$object->fields[$xvalwithoutprefix][
'arrayofkeyval'][$obj->$fieldforxkey];
1277 $labeltouse = (($xlabel || $xlabel ==
'0') ?
dol_trunc($xlabel, 20,
'middle') : ($xlabel ===
'' ? $langs->transnoentitiesnoconv(
"Empty") : $langs->transnoentitiesnoconv(
"NotDefined")));
1278 $xarrayforallseries = array(
'label' => $labeltouse);
1279 foreach ($sanitized_search_measures as $key => $val) {
1280 $fieldfory =
'y_'.$key;
1281 $xarrayforallseries[$fieldfory] = $obj->$fieldfory;
1283 $data[$xi] = $xarrayforallseries;
1288 $totalnbofrecord = count($data);
1293print
'<!-- Section to show the result -->'.
"\n";
1294print
'<div class="customreportsoutput'.($totalnbofrecord ?
'' :
' customreportsoutputnotdata').
'">';
1296if (empty($newarrayoftype)) {
1297 $langs->load(
"admin");
1298 print
info_admin($langs->trans(
"NoSupportedModulesHaveBeenActivated").
' '.$langs->trans(
"YouCanEnableModulesFrom"), 0, 0,
'info');
1301if ($mode ==
'grid') {
1305if ($mode ==
'graph') {
1307 $HEIGHT = (empty($_SESSION[
'dol_screenheight']) ? 400 : $_SESSION[
'dol_screenheight'] - 500);
1311 $mesg = $px1->isGraphKo();
1315 $px1->SetData($data);
1318 $arrayoftypes = array();
1319 foreach ($sanitized_search_measures as $key => $val) {
1320 $arrayoftypes[] = $search_graph;
1323 $px1->SetLegend($legend);
1324 $px1->setShowLegend($SHOWLEGEND);
1325 $px1->SetMinValue((
int) $px1->GetFloorMinValue());
1326 $px1->SetMaxValue($px1->GetCeilMaxValue());
1327 $px1->SetWidth($WIDTH);
1328 $px1->SetHeight($HEIGHT);
1329 $px1->SetYLabel($langs->trans(
"Y"));
1330 $px1->SetShading(3);
1331 $px1->SetHorizTickIncrement(1);
1332 $px1->SetCssPrefix(
"cssboxes");
1333 $px1->SetType($arrayoftypes);
1334 $px1->mode =
'depth';
1337 $dir =
$conf->user->dir_temp;
1340 if (!empty(
$object->element)) {
1341 $filenamekey = $dir.
'/customreport_'.
$object->element.(empty($customreportkey) ?
'' : $customreportkey).
'.png';
1342 $fileurlkey = DOL_URL_ROOT.
'/viewimage.php?modulepart=user&file=customreport_'.
$object->element.(empty($customreportkey) ?
'' : $customreportkey).
'.png';
1345 if (isset($filenamekey) && isset($fileurlkey)) {
1346 $px1->draw($filenamekey, $fileurlkey);
1349 $texttoshow = $langs->trans(
"NoRecordFound");
1351 $texttoshow = $langs->trans(
"SelectYourGraphOptionsFirst");
1354 print $px1->show($totalnbofrecord ? 0 : $texttoshow);
1360if ($sql && !defined(
'MAIN_CUSTOM_REPORT_KEEP_GRAPH_ONLY')) {
1362 print
'<br>'.info_admin($langs->trans(
"SQLUsedForExport").
':<br> '.$sql, 0, 0,
'1',
'',
'TechnicalInformation');
1366if (!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)
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, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isModEnabled($module)
Is Dolibarr module enabled.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='', $cssfordropdown='info_admin')
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...
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
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.