45@phan-var-force ?int[] $toselect
48if (!defined(
'USE_CUSTOM_REPORT_AS_INCLUDE')) {
49 require
'../main.inc.php';
52 $action =
GETPOST(
'action',
'aZ09') ?
GETPOST(
'action',
'aZ09') :
'view';
53 $massaction =
GETPOST(
'massaction',
'alpha');
55 $mode =
GETPOST(
'mode',
'alpha');
56 $objecttype = (string)
GETPOST(
'objecttype',
'aZ09arobase');
57 $tabfamily =
GETPOST(
'tabfamily',
'aZ09');
59 $search_measures =
GETPOST(
'search_measures',
'array');
62 if (
GETPOST(
'search_xaxis',
'alpha') &&
GETPOST(
'search_xaxis',
'alpha') !=
'-1') {
63 $search_xaxis = array(
GETPOST(
'search_xaxis',
'alpha'));
65 $search_xaxis = array();
68 if (
GETPOST(
'search_groupby',
'alpha') &&
GETPOST(
'search_groupby',
'alpha') !=
'-1') {
69 $search_groupby = array(
GETPOST(
'search_groupby',
'alpha'));
71 $search_groupby = array();
74 '@phan-var-force string[] $search_groupby';
76 $search_yaxis =
GETPOST(
'search_yaxis',
'array');
77 $search_graph =
GETPOST(
'search_graph',
'restricthtml');
81 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
82 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
84 if (empty($page) || $page == -1 ||
GETPOST(
'button_search',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha') || (empty($toselect) && $massaction ===
'0')) {
87 $offset = $limit * $page;
88 $pageprev = $page - 1;
89 $pagenext = $page + 1;
91 $diroutputmassaction =
$conf->user->dir_temp.
'/'.$user->id.
'/customreport';
97 @phan-var-force int<0,1> $SHOWLEGEND
98 @phan-var-force string customreportkey
103 if (empty($user) || empty($user->id)) {
104 print
'Page is called as an include but $user and its permission loaded with loadRights() are not defined. We stop here.';
108 print
'Page is called as an include but $object is not defined. We stop here.';
116if (!isset($search_measures)) {
117 $search_measures = array(0 =>
't.count');
120 $objecttype =
$object->element.($object->module ?
'@'.$object->module :
'');
122if (empty($objecttype)) {
123 $objecttype =
'thirdparty';
126require_once DOL_DOCUMENT_ROOT.
"/core/class/extrafields.class.php";
127require_once DOL_DOCUMENT_ROOT.
"/core/class/html.form.class.php";
128require_once DOL_DOCUMENT_ROOT.
"/core/lib/admin.lib.php";
129require_once DOL_DOCUMENT_ROOT.
"/core/lib/company.lib.php";
130require_once DOL_DOCUMENT_ROOT.
"/core/lib/date.lib.php";
131require_once DOL_DOCUMENT_ROOT.
"/core/lib/customreports.lib.php";
132require_once DOL_DOCUMENT_ROOT.
"/core/class/dolgraph.class.php";
133require_once DOL_DOCUMENT_ROOT.
"/core/class/doleditor.class.php";
134require_once DOL_DOCUMENT_ROOT.
"/core/class/html.formother.class.php";
137$langs->loadLangs(array(
"companies",
"other",
"exports",
"sendings"));
141$hookmanager->initHooks(array(
'customreport'));
146$keyforlabeloffield =
null;
148$ObjectClassName =
'';
151 'thirdparty' => array(
'langs' =>
'companies',
'label' =>
'ThirdParties',
'picto' =>
'company',
'ObjectClassName' =>
'Societe',
'enabled' => isModEnabled(
'societe'),
'ClassPath' =>
"/societe/class/societe.class.php"),
152 'contact' => array(
'label' =>
'Contacts',
'picto' =>
'contact',
'ObjectClassName' =>
'Contact',
'enabled' => isModEnabled(
'societe'),
'ClassPath' =>
"/contact/class/contact.class.php"),
153 'proposal' => array(
'label' =>
'Proposals',
'picto' =>
'proposal',
'ObjectClassName' =>
'Propal',
'enabled' => isModEnabled(
'propal'),
'ClassPath' =>
"/comm/propal/class/propal.class.php"),
154 'order' => array(
'label' =>
'Orders',
'picto' =>
'order',
'ObjectClassName' =>
'Commande',
'enabled' => isModEnabled(
'order'),
'ClassPath' =>
"/commande/class/commande.class.php"),
155 'invoice' => array(
'langs' =>
'facture',
'label' =>
'Invoices',
'picto' =>
'bill',
'ObjectClassName' =>
'Facture',
'enabled' => isModEnabled(
'invoice'),
'ClassPath' =>
"/compta/facture/class/facture.class.php"),
156 'invoice_template' => array(
'label' =>
'PredefinedInvoices',
'picto' =>
'bill',
'ObjectClassName' =>
'FactureRec',
'enabled' => isModEnabled(
'invoice'),
'ClassPath' =>
"/compta/facture/class/facture-rec.class.php",
'langs' =>
'bills'),
157 'contract' => array(
'label' =>
'Contracts',
'picto' =>
'contract',
'ObjectClassName' =>
'Contrat',
'enabled' => isModEnabled(
'contract'),
'ClassPath' =>
"/contrat/class/contrat.class.php",
'langs' =>
'contracts'),
158 'contractdet' => array(
'label' =>
'ContractLines',
'picto' =>
'contract',
'ObjectClassName' =>
'ContratLigne',
'enabled' => isModEnabled(
'contract'),
'ClassPath' =>
"/contrat/class/contrat.class.php",
'langs' =>
'contracts'),
159 'bom' => array(
'label' =>
'BOM',
'picto' =>
'bom',
'ObjectClassName' =>
'Bom',
'enabled' => isModEnabled(
'bom')),
160 'mrp' => array(
'label' =>
'MO',
'picto' =>
'mrp',
'ObjectClassName' =>
'Mo',
'enabled' => isModEnabled(
'mrp'),
'ClassPath' =>
"/mrp/class/mo.class.php"),
161 'ticket' => array(
'label' =>
'Ticket',
'picto' =>
'ticket',
'ObjectClassName' =>
'Ticket',
'enabled' => isModEnabled(
'ticket')),
162 'member' => array(
'label' =>
'Adherent',
'picto' =>
'member',
'ObjectClassName' =>
'Adherent',
'enabled' => isModEnabled(
'member'),
'ClassPath' =>
"/adherents/class/adherent.class.php",
'langs' =>
'members'),
163 'cotisation' => array(
'label' =>
'Subscriptions',
'picto' =>
'member',
'ObjectClassName' =>
'Subscription',
'enabled' => isModEnabled(
'member'),
'ClassPath' =>
"/adherents/class/subscription.class.php",
'langs' =>
'members'),
168$parameters = array(
'objecttype' => $objecttype,
'tabfamily' => $tabfamily);
169$reshook = $hookmanager->executeHooks(
'loadDataForCustomReports', $parameters,
$object, $action);
172} elseif (is_array($hookmanager->resArray)) {
173 if (!empty($hookmanager->resArray[
'title'])) {
174 $title = $hookmanager->resArray[
'title'];
176 if (!empty($hookmanager->resArray[
'picto'])) {
177 $picto = $hookmanager->resArray[
'picto'];
179 if (!empty($hookmanager->resArray[
'head'])) {
180 $head = array_merge($head, $hookmanager->resArray[
'head']);
182 if (!empty($hookmanager->resArray[
'arrayoftype'])) {
183 foreach ($hookmanager->resArray[
'arrayoftype'] as $key => $val) {
184 $arrayoftype[$key] = $val;
192 if (!empty($arrayoftype[$objecttype][
'ClassPath'])) {
193 $fileforclass = $arrayoftype[$objecttype][
'ClassPath'];
195 $fileforclass =
"/".$objecttype.
"/class/".$objecttype.
".class.php";
199 $ObjectClassName = $arrayoftype[$objecttype][
'ObjectClassName'];
200 if (!empty($ObjectClassName)) {
201 if (class_exists($ObjectClassName)) {
202 $object =
new $ObjectClassName($db);
204 print
'Failed to load class for type '.$objecttype.
'. Class file found but Class object named '.$ObjectClassName.
' not found.';
207 print
'Failed to load class for type '.$objecttype.
'. Class file name is unknown.';
210 print
'Failed to load class for type '.$objecttype.
'. Class path not found.';
214'@phan-var-force CommonObject $object';
218if ($user->socid > 0) {
224$extrafields->fetch_name_optionals_label(
'all');
227$search_array_options = $extrafields->getOptionalsFromPost(
$object->table_element,
'',
'search_');
229$search_component_params = array(
'');
230$search_component_params_hidden = trim(
GETPOST(
'search_component_params_hidden',
'alphanohtml'));
231$search_component_params_input = trim(
GETPOST(
'search_component_params_input',
'alphanohtml'));
240 $value = $search_component_params_input;
242 $value = preg_replace(
'/([a-z\.]+)\s*([!<>=]+|in|notin|like|notlike)\s*/',
'\1:\2:', $value);
243 $value = preg_replace(
'/\s*\|\s*/',
'|', $value);
246 $crits = explode(
' ', trim($value));
250 foreach ($crits as $crit) {
255 $tmpcrits = explode(
'|', $crit);
257 foreach ($tmpcrits as $tmpcrit) {
258 if ($tmpcrit !==
'0' && empty($tmpcrit)) {
261 $tmpcrit = trim($tmpcrit);
265 $parenthesislevel = 0;
266 $rescheckfilter =
dolCheckFilters($tmpcrit, $errorstr, $parenthesislevel);
267 if ($rescheckfilter) {
268 while ($parenthesislevel > 0) {
269 $tmpcrit = preg_replace(
'/^\(/',
'', preg_replace(
'/\)$/',
'', $tmpcrit));
274 $field = preg_replace(
'/(:[!<>=\s]+:|:in:|:notin:|:like:|:notlike:).*$/',
'', $tmpcrit);
275 $tmpcrit = preg_replace(
'/^.*(:[!<>=\s]+:|:in:|:notin:|:like:|:notlike:)/',
'\1', $tmpcrit);
278 $newres .= (($i2 > 0 || $i3 > 0) ?
' OR ' :
'');
281 $newcrit = preg_replace(
'/(:[!<>=\s]+:|:in:|:notin:|:like:|:notlike:)/',
'', $tmpcrit);
285 preg_match(
'/:([!<>=\s]+|in|notin|like|notlike):/', $tmpcrit, $reg);
286 if (!empty($reg[1])) {
289 if ($newcrit !=
'') {
290 if (!preg_match(
'/^\'[^\']*\'$/', $newcrit)) {
292 $newres .=
'('.$field.
':'.$operator.
':'.((float) $numnewcrit).
')';
294 $newres .=
'('.$field.
':'.$operator.
":".((string) $newcrit).
')';
302 $res = $res.($res ?
' AND ' :
'').($i2 > 1 ?
'(' :
'').$newres.($i2 > 1 ?
')' :
'');
309 $search_component_params_input = $res;
315$search_component_params_hidden = implode(
' AND ', array_merge($arrayofandtagshidden, $arrayofandtagsinput));
318$MAXUNIQUEVALFORGROUP = 20;
319$MAXMEASURESINBARGRAPH = 20;
320$SHOWLEGEND = (isset($SHOWLEGEND) ? $SHOWLEGEND : 1);
322$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);
323$MM = substr($langs->trans(
"Month"), 0, 1).substr($langs->trans(
"Month"), 0, 1);
324$DD = substr($langs->trans(
"Day"), 0, 1).substr($langs->trans(
"Day"), 0, 1);
325$HH = substr($langs->trans(
"Hour"), 0, 1).substr($langs->trans(
"Hour"), 0, 1);
326$MI = substr($langs->trans(
"Minute"), 0, 1).substr($langs->trans(
"Minute"), 0, 1);
327$SS = substr($langs->trans(
"Second"), 0, 1).substr($langs->trans(
"Second"), 0, 1);
329$arrayoffilterfields = array();
330$arrayofmesures = array();
331$arrayofxaxis = array();
332$arrayofgroupby = array();
333$arrayofyaxis = array();
334$arrayofvaluesforgroupby = array();
337if (!empty(
$object->element_for_permission)) {
338 $features =
$object->element_for_permission;
340 $features .= (empty(
$object->module) ?
'' :
'@'.$object->module);
361$form =
new Form($db);
364if (!defined(
'USE_CUSTOM_REPORT_AS_INCLUDE')) {
365 llxHeader(
'', $langs->transnoentitiesnoconv(
'CustomReports'),
'');
374$newarrayoftype = array();
375foreach ($arrayoftype as $key => $val) {
376 if (
dol_eval($val[
'enabled'], 1, 1,
'1')) {
377 $newarrayoftype[$key] = $arrayoftype[$key];
379 if (!empty($val[
'langs'])) {
380 $langs->load($val[
'langs']);
385$arrayoffilterfields =
fillArrayOfFilterFields(
$object,
't', $langs->trans($newarrayoftype[$objecttype][
'label']), $arrayoffilterfields, 0, $count);
386$arrayoffilterfields =
dol_sort_array($arrayoffilterfields,
'position',
'asc', 0, 0, 1);
389$arrayofmesures =
fillArrayOfMeasures(
$object,
't', $langs->trans($newarrayoftype[$objecttype][
'label']), $arrayofmesures, 0, $count);
390$arrayofmesures =
dol_sort_array($arrayofmesures,
'position',
'asc', 0, 0, 1);
393$arrayofxaxis =
fillArrayOfXAxis(
$object,
't', $langs->trans($newarrayoftype[$objecttype][
'label']), $arrayofxaxis, 0, $count);
394$arrayofxaxis =
dol_sort_array($arrayofxaxis,
'position',
'asc', 0, 0, 1);
397$arrayofgroupby =
fillArrayOfGroupBy(
$object,
't', $langs->trans($newarrayoftype[$objecttype][
'label']), $arrayofgroupby, 0, $count);
398$arrayofgroupby =
dol_sort_array($arrayofgroupby,
'position',
'asc', 0, 0, 1);
402if ($action ==
'viewgraph') {
403 if (is_array($search_measures) && !count($search_measures)) {
404 setEventMessages($langs->trans(
"AtLeastOneMeasureIsRequired"),
null,
'warnings');
405 } elseif ($mode ==
'graph' && is_array($search_xaxis) && count($search_xaxis) > 1) {
406 setEventMessages($langs->trans(
"OnlyOneFieldForXAxisIsPossible"),
null,
'warnings');
407 $search_xaxis = array(0 => $search_xaxis[0]);
409 if (is_array($search_groupby) && count($search_groupby) >= 2) {
410 setEventMessages($langs->trans(
"ErrorOnlyOneFieldForGroupByIsPossible"),
null,
'warnings');
411 $search_groupby = array(0 => $search_groupby[0]);
413 if (is_array($search_xaxis) && !count($search_xaxis)) {
414 setEventMessages($langs->trans(
"AtLeastOneXAxisIsRequired"),
null,
'warnings');
415 } elseif ($mode ==
'graph' && $search_graph ==
'bars' && count($search_measures) > $MAXMEASURESINBARGRAPH) {
416 $langs->load(
"errors");
417 setEventMessages($langs->trans(
"GraphInBarsAreLimitedToNMeasures", $MAXMEASURESINBARGRAPH),
null,
'warnings');
418 $search_graph =
'lines';
424if (is_array($search_groupby) && count($search_groupby)) {
426 foreach ($search_groupby as $gkey => $gval) {
427 $gvalwithoutprefix = preg_replace(
'/^[a-z]+\./',
'', $gval);
429 if (preg_match(
'/\-year$/', $search_groupby[$gkey])) {
430 $tmpval = preg_replace(
'/\-year$/',
'', $search_groupby[$gkey]);
431 $fieldtocount .=
'DATE_FORMAT('.$tmpval.
", '%Y')";
432 } elseif (preg_match(
'/\-month$/', $search_groupby[$gkey])) {
433 $tmpval = preg_replace(
'/\-month$/',
'', $search_groupby[$gkey]);
434 $fieldtocount .=
'DATE_FORMAT('.$tmpval.
", '%Y-%m')";
435 } elseif (preg_match(
'/\-day$/', $search_groupby[$gkey])) {
436 $tmpval = preg_replace(
'/\-day$/',
'', $search_groupby[$gkey]);
437 $fieldtocount .=
'DATE_FORMAT('.$tmpval.
", '%Y-%m-%d')";
439 $fieldtocount = $search_groupby[$gkey];
442 $sql =
"SELECT DISTINCT ".$fieldtocount.
" as val";
444 if (strpos($fieldtocount,
'te') === 0) {
445 $tabletouse =
$object->table_element;
446 $tablealiastouse =
'te';
447 if (!empty($arrayofgroupby[$gval])) {
448 $tmpval = explode(
'.', $gval);
449 $tabletouse = $arrayofgroupby[$gval][
'table'];
450 $tablealiastouse = $tmpval[0];
455 $sql .=
" FROM ".MAIN_DB_PREFIX.$tabletouse.
"_extrafields as ".$tablealiastouse;
457 $tabletouse =
$object->table_element;
458 $tablealiastouse =
't';
459 if (!empty($arrayofgroupby[$gval])) {
460 $tmpval = explode(
'.', $gval);
461 $tabletouse = $arrayofgroupby[$gval][
'table'];
462 $tablealiastouse = $tmpval[0];
464 $sql .=
" FROM ".MAIN_DB_PREFIX.$tabletouse.
" as ".$tablealiastouse;
475 $sql .=
" LIMIT ".((int) ($MAXUNIQUEVALFORGROUP + 1));
478 $resql = $db->query($sql);
483 while ($obj = $db->fetch_object($resql)) {
484 if (is_null($obj->val)) {
485 $keytouse =
'__NULL__';
486 $valuetranslated = $langs->transnoentitiesnoconv(
"NotDefined");
487 } elseif ($obj->val ===
'') {
489 $valuetranslated = $langs->transnoentitiesnoconv(
"Empty");
491 $keytouse = (string) $obj->val;
492 $valuetranslated = $obj->val;
496 if (!empty(
$object->fields[$gvalwithoutprefix][
'arrayofkeyval'])) {
497 $valuetranslated =
$object->fields[$gvalwithoutprefix][
'arrayofkeyval'][$obj->val];
498 if (is_null($valuetranslated)) {
499 $valuetranslated = $langs->transnoentitiesnoconv(
"UndefinedKey");
501 $valuetranslated = $langs->trans($valuetranslated);
502 } elseif (preg_match(
'/integer:([^:]+):([^:]+)$/',
$object->fields[$gvalwithoutprefix][
'type'], $regs)) {
503 $classname = $regs[1];
504 $classpath = $regs[2];
506 if (class_exists($classname)) {
507 $tmpobject =
new $classname($db);
508 '@phan-var-force CommonObject $tmpobject';
509 $tmpobject->fetch($obj->val);
510 foreach ($tmpobject->fields as $fieldkey => $field) {
511 if ($field[
'showoncombobox']) {
512 $valuetranslated = $tmpobject->$fieldkey;
521 $arrayofvaluesforgroupby[
'g_'.$gkey][$keytouse] = $valuetranslated;
524 $tmpfield = explode(
'.', $gval);
525 if ($tmpfield[0] !=
't' || (is_array(
$object->fields[$tmpfield[1]]) && empty(
$object->fields[$tmpfield[1]][
'notnull']))) {
526 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");
528 $arrayofvaluesforgroupby[
'g_'.$gkey][
'__NULL__'] = $langs->transnoentitiesnoconv(
"NotDefined");
531 if (is_array($arrayofvaluesforgroupby[
'g_'.$gkey])) {
532 asort($arrayofvaluesforgroupby[
'g_'.$gkey]);
536 if (is_array($arrayofvaluesforgroupby[
'g_'.$gkey]) && count($arrayofvaluesforgroupby[
'g_'.$gkey]) > $MAXUNIQUEVALFORGROUP) {
537 $langs->load(
"errors");
539 if (strpos($fieldtocount,
'te') === 0) {
543 $keyforlabeloffield = $extrafields->attributes[
$object->table_element][
'label'][$gvalwithoutprefix];
544 $labeloffield = $langs->transnoentitiesnoconv($keyforlabeloffield);
545 } elseif (strpos($fieldtocount,
't__') === 0) {
547 if (preg_match(
'/^(.*)\.(.*)/', $gvalwithoutprefix, $reg)) {
554 $labeloffield = $arrayofgroupby[$fieldtocount][
'labelnohtml'];
556 $labeloffield = $langs->transnoentitiesnoconv($keyforlabeloffield);
560 if (preg_match(
'/^(.*)\-(year|month|day)/', $gvalwithoutprefix, $reg)) {
561 $gvalwithoutprefix = preg_replace(
'/\-(year|month|day)/',
'', $gvalwithoutprefix);
562 $keyforlabeloffield =
$object->fields[$gvalwithoutprefix][
'label'];
563 $labeloffield = $langs->transnoentitiesnoconv($keyforlabeloffield).
'-'.$reg[2];
565 $keyforlabeloffield =
$object->fields[$gvalwithoutprefix][
'label'];
566 $labeloffield = $langs->transnoentitiesnoconv($keyforlabeloffield);
570 setEventMessages($langs->transnoentitiesnoconv(
"ErrorTooManyDifferentValueForSelectedGroupBy", $MAXUNIQUEVALFORGROUP, $labeloffield),
null,
'warnings');
571 $search_groupby = array();
581$endyear = $tmparray[
'year'];
582$endmonth = $tmparray[
'mon'];
584$startyear = $endyear - 2;
589if (!defined(
'MAIN_CUSTOM_REPORT_KEEP_GRAPH_ONLY')) {
590 print
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'" autocomplete="off">';
591 print
'<input type="hidden" name="token" value="'.newToken().
'">';
592 print
'<input type="hidden" name="action" value="viewgraph">';
593 print
'<input type="hidden" name="tabfamily" value="'.$tabfamily.
'">';
597 $viewmode .=
'<div class="divadvancedsearchfield">';
598 $arrayofgraphs = array(
'bars' =>
'Bars',
'lines' =>
'Lines');
599 $viewmode .=
'<div class="inline-block opacitymedium"><span class="fas fa-chart-area paddingright" title="'.$langs->trans(
"Graph").
'"></span>'.$langs->trans(
"Graph").
'</div> ';
600 $viewmode .= $form->selectarray(
'search_graph', $arrayofgraphs, $search_graph, 0, 0, 0,
'', 1, 0, 0,
'',
'graphtype width100');
601 $viewmode .=
'</div>';
604 $massactionbutton =
'';
609 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);
612 foreach ($newarrayoftype as $tmpkey => $tmpval) {
613 $newarrayoftype[$tmpkey][
'label'] =
img_picto(
'', $tmpval[
'picto'],
'class="pictofixedwidth"').$langs->trans($tmpval[
'label']);
616 print
'<div class="liste_titre liste_titre_bydiv liste_titre_bydiv_inlineblock liste_titre_bydiv_nothingafter centpercent">';
619 print
'<div class="divadvancedsearchfield center floatnone">';
620 print
'<div class="inline-block"><span class="opacitymedium">'.$langs->trans(
"StatisticsOn").
'</span></div> ';
621 print $form->selectarray(
'objecttype', $newarrayoftype, $objecttype, 0, 0, 0,
'', 1, 0, 0,
'',
'minwidth200', 1,
'', 0, 1);
622 if (empty(
$conf->use_javascript_ajax)) {
623 print
'<input type="submit" class="button buttongen button-save nomargintop" name="changeobjecttype" value="'.$langs->trans(
"Refresh").
'">';
625 print
'<!-- js code to reload page with good object type -->
626 <script nonce="'.getNonce().
'" type="text/javascript">
627 jQuery(document).ready(function() {
628 jQuery("#objecttype").change(function() {
629 console.log("Reload for "+jQuery("#objecttype").val());
630 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')) :
'').
'";
635 print
'</div><div class="clearboth"></div>';
639 print
'<div class="divadvancedsearchfield">';
640 print $form->searchComponent(array(
$object->element =>
$object->fields), $search_component_params, array(), $search_component_params_hidden, $arrayoffilterfields);
647 print
'<div class="divadvancedsearchfield clearboth">';
648 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>';
649 $simplearrayofmesures = array();
650 foreach ($arrayofmesures as $key => $val) {
651 $simplearrayofmesures[$key] = $arrayofmesures[$key][
'label'];
653 print $form->multiselectarray(
'search_measures', $simplearrayofmesures, $search_measures, 0, 0,
'minwidth300 widthcentpercentminusx', 1, 0,
'',
'', $langs->transnoentitiesnoconv(
"Measures"));
658 print
'<div class="divadvancedsearchfield">';
659 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>';
661 print $formother->selectXAxisField(
$object, $search_xaxis, $arrayofxaxis, $langs->trans(
"XAxis"),
'minwidth300 maxwidth400 widthcentpercentminusx');
666 print
'<div class="divadvancedsearchfield">';
667 print
'<div class="inline-block opacitymedium"><span class="fas fa-ruler-horizontal paddingright pictofixedwidth" title="'.dol_escape_htmltag($langs->trans(
"GroupBy")).
'"></span></div>';
668 print $formother->selectGroupByField(
$object, $search_groupby, $arrayofgroupby,
'minwidth250 maxwidth300 widthcentpercentminusx', $langs->trans(
"GroupBy"));
672 if ($mode ==
'grid') {
674 print
'<div class="divadvancedsearchfield">';
675 foreach (
$object->fields as $key => $val) {
676 if (empty($val[
'measure']) && (!isset($val[
'enabled']) ||
dol_eval($val[
'enabled'], 1, 1,
'1'))) {
677 if (in_array($key, array(
'id',
'rowid',
'entity',
'last_main_doc',
'extraparams'))) {
680 if (preg_match(
'/^fk_/', $key)) {
683 if (in_array($val[
'type'], array(
'html',
'text'))) {
686 if (in_array($val[
'type'], array(
'timestamp',
'date',
'datetime'))) {
687 $arrayofyaxis[
't.'.$key.
'-year'] = array(
688 'label' => $langs->trans($val[
'label']).
' ('.$YYYY.
')',
689 'position' => $val[
'position'],
690 'table' =>
$object->table_element
692 $arrayofyaxis[
't.'.$key.
'-month'] = array(
693 'label' => $langs->trans($val[
'label']).
' ('.$YYYY.
'-'.$MM.
')',
694 'position' => $val[
'position'],
695 'table' =>
$object->table_element
697 $arrayofyaxis[
't.'.$key.
'-day'] = array(
698 'label' => $langs->trans($val[
'label']).
' ('.$YYYY.
'-'.$MM.
'-'.$DD.
')',
699 'position' => $val[
'position'],
700 'table' =>
$object->table_element
703 $arrayofyaxis[
't.'.$key] = array(
704 'label' => $val[
'label'],
705 'position' => (
int) $val[
'position'],
706 'table' =>
$object->table_element
712 if (
$object->isextrafieldmanaged) {
713 foreach ($extrafields->attributes[
$object->table_element][
'label'] as $key => $val) {
714 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'))) {
715 $arrayofyaxis[
'te.'.$key] = array(
716 'label' => $extrafields->attributes[
$object->table_element][
'label'][$key],
717 'position' => (
int) $extrafields->attributes[
$object->table_element][
'pos'][$key],
718 'table' =>
$object->table_element
724 $arrayofyaxislabel = array();
725 foreach ($arrayofyaxis as $key => $val) {
726 $arrayofyaxislabel[$key] = $val[
'label'];
728 print
'<div class="inline-block opacitymedium"><span class="fas fa-ruler-vertical paddingright" title="'.$langs->trans(
"YAxis").
'"></span>'.$langs->trans(
"YAxis").
'</div> ';
729 print $form->multiselectarray(
'search_yaxis', $arrayofyaxislabel, $search_yaxis, 0, 0,
'minwidth100', 1);
733 if ($mode ==
'graph') {
737 print
'<div class="divadvancedsearchfield">';
738 print
'<input type="submit" class="button buttongen button-save nomargintop" value="'.$langs->trans(
"Refresh").
'">';
746if (!empty($search_measures) && !empty($search_xaxis)) {
752 foreach ($search_xaxis as $key => $val) {
753 if (preg_match(
'/\-year$/', $val)) {
754 $tmpval = preg_replace(
'/\-year$/',
'', $val);
755 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y') as x_".$key.
', ';
756 } elseif (preg_match(
'/\-month$/', $val)) {
757 $tmpval = preg_replace(
'/\-month$/',
'', $val);
758 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m') as x_".$key.
', ';
759 } elseif (preg_match(
'/\-day$/', $val)) {
760 $tmpval = preg_replace(
'/\-day$/',
'', $val);
761 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m-%d') as x_".$key.
', ';
763 $sql .= $val.
" as x_".$key.
", ";
766 if (!empty($search_groupby)) {
767 foreach ($search_groupby as $key => $val) {
768 if (preg_match(
'/\-year$/', $val)) {
769 $tmpval = preg_replace(
'/\-year$/',
'', $val);
770 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y') as g_".$key.
', ';
771 } elseif (preg_match(
'/\-month$/', $val)) {
772 $tmpval = preg_replace(
'/\-month$/',
'', $val);
773 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m') as g_".$key.
', ';
774 } elseif (preg_match(
'/\-day$/', $val)) {
775 $tmpval = preg_replace(
'/\-day$/',
'', $val);
776 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m-%d') as g_".$key.
', ';
778 $sql .= $val.
" as g_".$key.
", ";
782 foreach ($search_measures as $key => $val) {
783 if ($val ==
't.count') {
784 $sql .=
"COUNT(t.".$fieldid.
") as y_".$key.
', ';
785 } elseif (preg_match(
'/\-sum$/', $val)) {
786 $tmpval = preg_replace(
'/\-sum$/',
'', $val);
787 $sql .=
"SUM(".$db->ifsql($tmpval.
' IS NULL',
'0', $tmpval).
") as y_".$key.
", ";
788 } elseif (preg_match(
'/\-average$/', $val)) {
789 $tmpval = preg_replace(
'/\-average$/',
'', $val);
790 $sql .=
"AVG(".$db->ifsql($tmpval.
' IS NULL',
'0', $tmpval).
") as y_".$key.
", ";
791 } elseif (preg_match(
'/\-min$/', $val)) {
792 $tmpval = preg_replace(
'/\-min$/',
'', $val);
793 $sql .=
"MIN(".$db->ifsql($tmpval.
' IS NULL',
'0', $tmpval).
") as y_".$key.
", ";
794 } elseif (preg_match(
'/\-max$/', $val)) {
795 $tmpval = preg_replace(
'/\-max$/',
'', $val);
796 $sql .=
"MAX(".$db->ifsql($tmpval.
' IS NULL',
'0', $tmpval).
") as y_".$key.
", ";
797 } elseif (preg_match(
'/\-stddevpop$/', $val)) {
798 $tmpval = preg_replace(
'/\-stddevpop$/',
'', $val);
799 $sql .=
"STDDEV_POP(".$db->ifsql($tmpval.
' IS NULL',
'0', $tmpval).
") as y_".$key.
", ";
802 $sql = preg_replace(
'/,\s*$/',
'', $sql);
803 $sql .=
" FROM ".MAIN_DB_PREFIX.$object->table_element.
" as t";
805 if (
$object->isextrafieldmanaged) {
806 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element.
"_extrafields as te ON te.fk_object = t.".$fieldid;
809 if (
$object->ismultientitymanaged) {
810 if (
$object->ismultientitymanaged == 1) {
813 $tmparray = explode(
'@',
$object->ismultientitymanaged);
814 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.$tmparray[1].
" as parenttableforentity ON t.".$tmparray[0].
" = parenttableforentity.rowid";
815 $sql .=
" AND parenttableforentity.entity IN (".getEntity($tmparray[1]).
")";
820 $listoftablesalreadyadded = array(
$object->table_element =>
$object->table_element);
824 foreach ($search_xaxis as $key => $val) {
825 if (!empty($arrayofxaxis[$val])) {
826 $tmpval = explode(
'.', $val);
829 foreach ($tmpforloop as $tmptable => $tmptablealias) {
830 if (! in_array($tmptable, $listoftablesalreadyadded)) {
831 $tmpforexplode = explode(
'__', $tmptablealias);
832 $endpart = end($tmpforexplode);
833 $parenttableandfield = preg_replace(
'/__'.$endpart.
'$/',
'', $tmptablealias).
'.'.$endpart;
835 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$tmptable.
" as ".$db->sanitize($tmptablealias).
" ON ".$db->sanitize($parenttableandfield).
" = ".$db->sanitize($tmptablealias).
".rowid";
836 $listoftablesalreadyadded[$tmptable] = $tmptable;
838 if (preg_match(
'/^te/', $tmpval[0]) && preg_replace(
'/^t_/',
'te_', $tmptablealias) == $tmpval[0]) {
839 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$tmptable.
"_extrafields as ".$db->sanitize($tmpval[0]).
" ON ".$db->sanitize($tmpval[0]).
".fk_object = ".$db->sanitize($tmptablealias).
".rowid";
840 $listoftablesalreadyadded[$tmptable] = $tmptable;
845 $errormessage =
'Found a key into search_xaxis not found into arrayofxaxis';
851 foreach ($search_groupby as $key => $val) {
852 if (!empty($arrayofgroupby[$val])) {
853 $tmpval = explode(
'.', $val);
856 foreach ($tmpforloop as $tmptable => $tmptablealias) {
857 if (! in_array($tmptable, $listoftablesalreadyadded)) {
858 $tmpforexplode = explode(
'__', $tmptablealias);
859 $endpart = end($tmpforexplode);
860 $parenttableandfield = preg_replace(
'/__'.$endpart.
'$/',
'', $tmptablealias).
'.'.$endpart;
862 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$tmptable.
" as ".$db->sanitize($tmptablealias).
" ON ".$db->sanitize($parenttableandfield).
" = ".$db->sanitize($tmptablealias).
".rowid";
863 $listoftablesalreadyadded[$tmptable] = $tmptable;
865 if (preg_match(
'/^te/', $tmpval[0]) && preg_replace(
'/^t_/',
'te_', $tmptablealias) == $tmpval[0]) {
866 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$tmptable.
"_extrafields as ".$db->sanitize($tmpval[0]).
" ON ".$db->sanitize($tmpval[0]).
".fk_object = ".$db->sanitize($tmptablealias).
".rowid";
867 $listoftablesalreadyadded[$tmptable] = $tmptable;
872 $errormessage =
'Found a key into search_groupby not found into arrayofgroupby';
878 foreach ($search_measures as $key => $val) {
879 if (!empty($arrayofmesures[$val])) {
880 $tmpval = explode(
'.', $val);
883 foreach ($tmpforloop as $tmptable => $tmptablealias) {
884 if (! in_array($tmptable, $listoftablesalreadyadded)) {
885 $tmpforexplode = explode(
'__', $tmptablealias);
886 $endpart = end($tmpforexplode);
887 $parenttableandfield = preg_replace(
'/__'.$endpart.
'$/',
'', $tmptablealias).
'.'.$endpart;
889 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$tmptable.
" as ".$db->sanitize($tmptablealias).
" ON ".$db->sanitize($parenttableandfield).
" = ".$db->sanitize($tmptablealias).
".rowid";
890 $listoftablesalreadyadded[$tmptable] = $tmptable;
892 if (preg_match(
'/^te/', $tmpval[0]) && preg_replace(
'/^t_/',
'te_', $tmptablealias) == $tmpval[0]) {
893 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$tmptable.
"_extrafields as ".$db->sanitize($tmpval[0]).
" ON ".$db->sanitize($tmpval[0]).
".fk_object = ".$db->sanitize($tmptablealias).
".rowid";
894 $listoftablesalreadyadded[$tmptable] = $tmptable;
899 $errormessage =
'Found a key into search_measures not found into arrayofmesures';
904 if (!empty($search_component_params_hidden)) {
906 preg_match_all(
'/\b(t[\w]*_[\w]*)\.(\w+(-\w+)?)/', $search_component_params_hidden, $matches);
907 $fieldsUsedInFilter = array_unique($matches[0]);
910 $fieldsToRemove = array_merge($search_measures, $search_groupby, $search_xaxis);
911 $fieldsUsedInFilter = array_diff($fieldsUsedInFilter, $fieldsToRemove);
913 foreach ($fieldsUsedInFilter as $key => $val) {
914 if (!empty($arrayoffilterfields[$val])) {
915 $tmpval = explode(
'.', $val);
917 foreach ($tmpforloop as $tmptable => $tmptablealias) {
918 if (! in_array($tmptable, $listoftablesalreadyadded)) {
919 $tmpforexplode = explode(
'__', $tmptablealias);
920 $endpart = end($tmpforexplode);
921 $parenttableandfield = preg_replace(
'/__'.$endpart.
'$/',
'', $tmptablealias).
'.'.$endpart;
923 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$tmptable.
" as ".$db->sanitize($tmptablealias).
" ON ".$db->sanitize($parenttableandfield).
" = ".$db->sanitize($tmptablealias).
".rowid";
924 $listoftablesalreadyadded[$tmptable] = $tmptable;
926 if (preg_match(
'/^te/', $tmpval[0]) && preg_replace(
'/^t_/',
'te_', $tmptablealias) == $tmpval[0]) {
927 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$tmptable.
"_extrafields as ".$db->sanitize($tmpval[0]).
" ON ".$db->sanitize($tmpval[0]).
".fk_object = ".$db->sanitize($tmptablealias).
".rowid";
928 $listoftablesalreadyadded[$tmptable] = $tmptable;
933 $errormessage =
'Found a key into search_filterfields not found into arrayoffilterfields';
938 $sql .=
" WHERE 1 = 1";
939 if (
$object->ismultientitymanaged == 1) {
940 $sql .=
" AND t.entity IN (".getEntity(
$object->element).
")";
943 $sqlfilters = $search_component_params_hidden;
948 $sql = preg_replace_callback(
949 "/(\w+)\.(\w+)\s*(=|!=|<>|<|>|<=|>=)\s*'(\d{4})-(\d{2})-(\d{2})'/",
954 function (array $matches): string {
956 $column = $matches[1] .
'.' . $matches[2];
957 $operator = $matches[3];
958 $year = (int) $matches[4];
959 $month = (int) $matches[5];
960 $day = (int) $matches[6];
962 $startOfDay = $db->idate(
dol_mktime(0, 0, 0, $month, $day, $year));
963 $endOfDay = $db->idate(
dol_mktime(23, 59, 59, $month, $day, $year));
967 return "($column >= '$startOfDay' AND $column <= '$endOfDay')";
970 return "NOT ($column >= '$startOfDay' AND $column <= '$endOfDay')";
972 return "$column < '$startOfDay'";
974 return "$column > '$endOfDay'";
976 return "$column <= '$endOfDay'";
978 return "$column >= '$startOfDay'";
986 $sql .=
" GROUP BY ";
987 foreach ($search_xaxis as $key => $val) {
988 if (preg_match(
'/\-year$/', $val)) {
989 $tmpval = preg_replace(
'/\-year$/',
'', $val);
990 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y'), ";
991 } elseif (preg_match(
'/\-month$/', $val)) {
992 $tmpval = preg_replace(
'/\-month$/',
'', $val);
993 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m'), ";
994 } elseif (preg_match(
'/\-day$/', $val)) {
995 $tmpval = preg_replace(
'/\-day$/',
'', $val);
996 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m-%d'), ";
1001 if (!empty($search_groupby)) {
1002 foreach ($search_groupby as $key => $val) {
1003 if (preg_match(
'/\-year$/', $val)) {
1004 $tmpval = preg_replace(
'/\-year$/',
'', $val);
1005 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y'), ";
1006 } elseif (preg_match(
'/\-month$/', $val)) {
1007 $tmpval = preg_replace(
'/\-month$/',
'', $val);
1008 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m'), ";
1009 } elseif (preg_match(
'/\-day$/', $val)) {
1010 $tmpval = preg_replace(
'/\-day$/',
'', $val);
1011 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m-%d'), ";
1017 $sql = preg_replace(
'/,\s*$/',
'', $sql);
1018 $sql .=
' ORDER BY ';
1019 foreach ($search_xaxis as $key => $val) {
1020 if (preg_match(
'/\-year$/', $val)) {
1021 $tmpval = preg_replace(
'/\-year$/',
'', $val);
1022 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y'), ";
1023 } elseif (preg_match(
'/\-month$/', $val)) {
1024 $tmpval = preg_replace(
'/\-month$/',
'', $val);
1025 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m'), ";
1026 } elseif (preg_match(
'/\-day$/', $val)) {
1027 $tmpval = preg_replace(
'/\-day$/',
'', $val);
1028 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m-%d'), ";
1033 if (!empty($search_groupby)) {
1034 foreach ($search_groupby as $key => $val) {
1035 if (preg_match(
'/\-year$/', $val)) {
1036 $tmpval = preg_replace(
'/\-year$/',
'', $val);
1037 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y'), ";
1038 } elseif (preg_match(
'/\-month$/', $val)) {
1039 $tmpval = preg_replace(
'/\-month$/',
'', $val);
1040 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m'), ";
1041 } elseif (preg_match(
'/\-day$/', $val)) {
1042 $tmpval = preg_replace(
'/\-day$/',
'', $val);
1043 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m-%d'), ";
1049 $sql = preg_replace(
'/,\s*$/',
'', $sql);
1052 if (!empty($customsql)) {
1059 print
'<div class="warning">';
1067foreach ($search_measures as $key => $val) {
1068 $legend[] = $langs->trans($arrayofmesures[$val][
'label']);
1071$useagroupby = (is_array($search_groupby) && count($search_groupby));
1076$totalnbofrecord = 0;
1079 $resql = $db->query($sql);
1081 print
'<div class="warning">';
1088 $oldlabeltouse =
'';
1089 while ($obj = $db->fetch_object($resql)) {
1092 $xval = $search_xaxis[0];
1093 $fieldforxkey =
'x_0';
1094 $xlabel = $obj->$fieldforxkey;
1095 $xvalwithoutprefix = preg_replace(
'/^[a-z]+\./',
'', $xval);
1098 if (!empty(
$object->fields[$xvalwithoutprefix][
'arrayofkeyval'])) {
1099 $xlabel =
$object->fields[$xvalwithoutprefix][
'arrayofkeyval'][$obj->$fieldforxkey];
1101 $labeltouse = (($xlabel || $xlabel ==
'0') ?
dol_trunc($xlabel, 20,
'middle') : ($xlabel ===
'' ? $langs->transnoentitiesnoconv(
"Empty") : $langs->transnoentitiesnoconv(
"NotDefined")));
1103 if ($oldlabeltouse !==
'' && ($labeltouse != $oldlabeltouse)) {
1107 $oldlabeltouse = $labeltouse;
1120 foreach ($search_measures as $key => $val) {
1122 foreach ($search_groupby as $gkey) {
1125 foreach ($arrayofvaluesforgroupby[
'g_'.$gi] as $gvaluepossiblekey => $gvaluepossiblelabel) {
1126 $ykeysuffix = $gvaluepossiblelabel;
1127 $gvalwithoutprefix = preg_replace(
'/^[a-z]+\./',
'', $gval);
1129 $fieldfory =
'y_'.$key;
1130 $fieldforg =
'g_'.$gi;
1131 $fieldforybis =
'y_'.$key.
'_'.$ykeysuffix;
1135 if (!array_key_exists($xi, $data)) {
1136 $data[$xi] = array();
1139 if (!array_key_exists(
'label', $data[$xi])) {
1140 $data[$xi] = array();
1141 $data[$xi][
'label'] = $labeltouse;
1144 $objfieldforg = $obj->$fieldforg;
1145 if (is_null($objfieldforg)) {
1146 $objfieldforg =
'__NULL__';
1149 if ($gvaluepossiblekey ==
'0') {
1151 if ($objfieldforg ==
'0') {
1153 $data[$xi][$fieldforybis] = $obj->$fieldfory;
1154 } elseif (!isset($data[$xi][$fieldforybis])) {
1156 $data[$xi][$fieldforybis] =
'0';
1160 if ((
string) $objfieldforg === (
string) $gvaluepossiblekey) {
1162 $data[$xi][$fieldforybis] = $obj->$fieldfory;
1163 } elseif (!isset($data[$xi][$fieldforybis])) {
1165 $data[$xi][$fieldforybis] =
'0';
1174 $xval = $search_xaxis[0];
1175 $fieldforxkey =
'x_0';
1176 $xlabel = $obj->$fieldforxkey;
1177 $xvalwithoutprefix = preg_replace(
'/^[a-z]+\./',
'', $xval);
1180 if (!empty(
$object->fields[$xvalwithoutprefix][
'arrayofkeyval'])) {
1181 $xlabel =
$object->fields[$xvalwithoutprefix][
'arrayofkeyval'][$obj->$fieldforxkey];
1184 $labeltouse = (($xlabel || $xlabel ==
'0') ?
dol_trunc($xlabel, 20,
'middle') : ($xlabel ===
'' ? $langs->transnoentitiesnoconv(
"Empty") : $langs->transnoentitiesnoconv(
"NotDefined")));
1185 $xarrayforallseries = array(
'label' => $labeltouse);
1186 foreach ($search_measures as $key => $val) {
1187 $fieldfory =
'y_'.$key;
1188 $xarrayforallseries[$fieldfory] = $obj->$fieldfory;
1190 $data[$xi] = $xarrayforallseries;
1195 $totalnbofrecord = count($data);
1200print
'<!-- Section to show the result -->'.
"\n";
1201print
'<div class="customreportsoutput'.($totalnbofrecord ?
'' :
' customreportsoutputnotdata').
'">';
1204if ($mode ==
'grid') {
1208if ($mode ==
'graph') {
1210 $HEIGHT = (empty($_SESSION[
'dol_screenheight']) ? 400 : $_SESSION[
'dol_screenheight'] - 500);
1214 $mesg = $px1->isGraphKo();
1218 $px1->SetData($data);
1221 $arrayoftypes = array();
1222 foreach ($search_measures as $key => $val) {
1223 $arrayoftypes[] = $search_graph;
1226 $px1->SetLegend($legend);
1227 $px1->setShowLegend($SHOWLEGEND);
1228 $px1->SetMinValue($px1->GetFloorMinValue());
1229 $px1->SetMaxValue($px1->GetCeilMaxValue());
1230 $px1->SetWidth($WIDTH);
1231 $px1->SetHeight($HEIGHT);
1232 $px1->SetYLabel($langs->trans(
"Y"));
1233 $px1->SetShading(3);
1234 $px1->SetHorizTickIncrement(1);
1235 $px1->SetCssPrefix(
"cssboxes");
1236 $px1->SetType($arrayoftypes);
1237 $px1->mode =
'depth';
1240 $dir =
$conf->user->dir_temp;
1243 $filenamekey = $dir.
'/customreport_'.
$object->element.(empty($customreportkey) ?
'' : $customreportkey).
'.png';
1244 $fileurlkey = DOL_URL_ROOT.
'/viewimage.php?modulepart=user&file=customreport_'.
$object->element.(empty($customreportkey) ?
'' : $customreportkey).
'.png';
1246 $px1->draw($filenamekey, $fileurlkey);
1248 $texttoshow = $langs->trans(
"NoRecordFound");
1249 if (!GETPOSTISSET(
'search_measures') || !GETPOSTISSET(
'search_xaxis')) {
1250 $texttoshow = $langs->trans(
"SelectYourGraphOptionsFirst");
1253 print $px1->show($totalnbofrecord ? 0 : $texttoshow);
1259if ($sql && !defined(
'MAIN_CUSTOM_REPORT_KEEP_GRAPH_ONLY')) {
1261 print
'<br>'.info_admin($langs->trans(
"SQLUsedForExport").
':<br> '.$sql, 0, 0,
'1',
'',
'TechnicalInformation');
1265if (!defined(
'USE_CUSTOM_REPORT_AS_INCLUDE')) {
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $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_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
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)
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_now($mode='auto')
Return date for now.
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.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
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.