28 if (!defined(
'USE_CUSTOM_REPORT_AS_INCLUDE')) {
29 require
'../main.inc.php';
32 $action =
GETPOST(
'action',
'aZ09') ?
GETPOST(
'action',
'aZ09') :
'view';
33 $massaction =
GETPOST(
'massaction',
'alpha');
35 $mode =
GETPOST(
'mode',
'alpha') ?
GETPOST(
'mode',
'alpha') :
'graph';
36 $objecttype =
GETPOST(
'objecttype',
'aZ09');
37 $tabfamily =
GETPOST(
'tabfamily',
'aZ09');
39 if (empty($objecttype)) {
40 $objecttype =
'thirdparty';
43 $search_measures =
GETPOST(
'search_measures',
'array');
46 if (
GETPOST(
'search_xaxis',
'alpha') &&
GETPOST(
'search_xaxis',
'alpha') !=
'-1') {
47 $search_xaxis = array(
GETPOST(
'search_xaxis',
'alpha'));
49 $search_xaxis = array();
52 if (
GETPOST(
'search_groupby',
'alpha') &&
GETPOST(
'search_groupby',
'alpha') !=
'-1') {
53 $search_groupby = array(
GETPOST(
'search_groupby',
'alpha'));
55 $search_groupby = array();
58 $search_yaxis =
GETPOST(
'search_yaxis',
'array');
59 $search_graph =
GETPOST(
'search_graph',
'restricthtml');
62 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
63 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
64 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
66 if (empty($page) || $page == -1 ||
GETPOST(
'button_search',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha') || (empty($toselect) && $massaction ===
'0')) {
69 $offset = $limit * $page;
70 $pageprev = $page - 1;
71 $pagenext = $page + 1;
73 $diroutputmassaction = $conf->user->dir_temp.
'/'.$user->id.
'/customreport';
76 require_once DOL_DOCUMENT_ROOT.
"/core/lib/admin.lib.php";
77 require_once DOL_DOCUMENT_ROOT.
"/core/lib/company.lib.php";
78 require_once DOL_DOCUMENT_ROOT.
"/core/class/dolgraph.class.php";
79 require_once DOL_DOCUMENT_ROOT.
"/core/class/doleditor.class.php";
80 require_once DOL_DOCUMENT_ROOT.
"/core/class/html.formother.class.php";
83 $langs->loadLangs(array(
"companies",
"other",
"exports",
"sendings"));
87 $hookmanager->initHooks(array(
'customreport'));
93 $ObjectClassName =
'';
96 'thirdparty' => array(
'label' =>
'ThirdParties',
'ObjectClassName' =>
'Societe',
'enabled' =>
isModEnabled(
'societe'),
'ClassPath' =>
"/societe/class/societe.class.php"),
97 'contact' => array(
'label' =>
'Contacts',
'ObjectClassName' =>
'Contact',
'enabled' =>
isModEnabled(
'societ'),
'ClassPath' =>
"/contact/class/contact.class.php"),
98 'proposal' => array(
'label' =>
'Proposals',
'ObjectClassName' =>
'Propal',
'enabled' =>
isModEnabled(
'propal'),
'ClassPath' =>
"/comm/propal/class/propal.class.php"),
99 'order' => array(
'label' =>
'Orders',
'ObjectClassName' =>
'Commande',
'enabled' =>
isModEnabled(
'commande'),
'ClassPath' =>
"/commande/class/commande.class.php"),
100 'invoice' => array(
'label' =>
'Invoices',
'ObjectClassName' =>
'Facture',
'enabled' =>
isModEnabled(
'facture'),
'ClassPath' =>
"/compta/facture/class/facture.class.php"),
101 'invoice_template'=>array(
'label' =>
'PredefinedInvoices',
'ObjectClassName' =>
'FactureRec',
'enabled' =>
isModEnabled(
'facture'),
'ClassPath' =>
"/compta/class/facturerec.class.php",
'langs'=>
'bills'),
102 'contract' => array(
'label' =>
'Contracts',
'ObjectClassName' =>
'Contrat',
'enabled' =>
isModEnabled(
'contrat'),
'ClassPath' =>
"/contrat/class/contrat.class.php",
'langs'=>
'contracts'),
103 'contractdet' => array(
'label' =>
'ContractLines',
'ObjectClassName' =>
'ContratLigne',
'enabled' =>
isModEnabled(
'contrat'),
'ClassPath' =>
"/contrat/class/contrat.class.php",
'langs'=>
'contracts'),
104 'bom' => array(
'label' =>
'BOM',
'ObjectClassName' =>
'Bom',
'enabled' =>
isModEnabled(
'bom')),
105 'mo' => array(
'label' =>
'MO',
'ObjectClassName' =>
'Mo',
'enabled' =>
isModEnabled(
'mrp'),
'ClassPath' =>
"/mrp/class/mo.class.php"),
106 'ticket' => array(
'label' =>
'Ticket',
'ObjectClassName' =>
'Ticket',
'enabled' =>
isModEnabled(
'ticket')),
107 'member' => array(
'label' =>
'Adherent',
'ObjectClassName' =>
'Adherent',
'enabled' =>
isModEnabled(
'adherent'),
'ClassPath' =>
"/adherents/class/adherent.class.php",
'langs'=>
'members'),
108 'cotisation' => array(
'label' =>
'Subscriptions',
'ObjectClassName' =>
'Subscription',
'enabled' =>
isModEnabled(
'adherent'),
'ClassPath' =>
"/adherents/class/subscription.class.php",
'langs'=>
'members'),
112 $parameters = array(
'objecttype'=>$objecttype,
'tabfamily'=>$tabfamily);
113 $reshook = $hookmanager->executeHooks(
'loadDataForCustomReports', $parameters, $object, $action);
116 } elseif (is_array($hookmanager->resArray)) {
117 if (!empty($hookmanager->resArray[
'title'])) {
118 $title = $hookmanager->resArray[
'title'];
120 if (!empty($hookmanager->resArray[
'picto'])) {
121 $picto = $hookmanager->resArray[
'picto'];
123 if (!empty($hookmanager->resArray[
'head'])) {
124 $head = array_merge($head, $hookmanager->resArray[
'head']);
126 if (!empty($hookmanager->resArray[
'arrayoftype'])) {
127 foreach ($hookmanager->resArray[
'arrayoftype'] as $key => $val) {
128 $arrayoftype[$key] = $val;
135 if (!empty($arrayoftype[$objecttype][
'ClassPath'])) {
140 $ObjectClassName = $arrayoftype[$objecttype][
'ObjectClassName'];
141 $object =
new $ObjectClassName($db);
143 print
'Failed to load class for type '.$objecttype;
149 if ($user->socid > 0) {
155 $extrafields->fetch_name_optionals_label($object->table_element);
158 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element,
'',
'search_');
160 $search_component_params = array(
'');
161 $search_component_params_hidden =
GETPOST(
'search_component_params_hidden',
'alphanohtml');
164 if (
GETPOST(
'search_component_params_input',
'alphanohtml')) {
165 $search_component_params_hidden =
GETPOST(
'search_component_params_input',
'alphanohtml');
168 $MAXUNIQUEVALFORGROUP = 20;
169 $MAXMEASURESINBARGRAPH = 20;
171 $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);
172 $MM = substr($langs->trans(
"Month"), 0, 1).substr($langs->trans(
"Month"), 0, 1);
173 $DD = substr($langs->trans(
"Day"), 0, 1).substr($langs->trans(
"Day"), 0, 1);
174 $HH = substr($langs->trans(
"Hour"), 0, 1).substr($langs->trans(
"Hour"), 0, 1);
175 $MI = substr($langs->trans(
"Minute"), 0, 1).substr($langs->trans(
"Minute"), 0, 1);
176 $SS = substr($langs->trans(
"Second"), 0, 1).substr($langs->trans(
"Second"), 0, 1);
178 $arrayofmesures = array();
179 $arrayofxaxis = array();
180 $arrayofgroupby = array();
181 $arrayofyaxis = array();
182 $arrayofvaluesforgroupby = array();
184 $features = $object->element;
185 if (!empty($object->element_for_permission)) {
186 $features = $object->element_for_permission;
209 if (!defined(
'USE_CUSTOM_REPORT_AS_INCLUDE')) {
210 llxHeader(
'', $langs->transnoentitiesnoconv(
'CustomReports'),
'');
215 $newarrayoftype = array();
216 foreach ($arrayoftype as $key => $val) {
217 if (
dol_eval($val[
'enabled'], 1, 1,
'1')) {
218 $newarrayoftype[$key] = $arrayoftype[$key];
220 if (!empty($val[
'langs'])) {
221 $langs->load($val[
'langs']);
226 $arrayofmesures = fillArrayOfMeasures($object,
't', $langs->trans($newarrayoftype[$objecttype][
'label']), $arrayofmesures, 0, $count);
227 $arrayofmesures =
dol_sort_array($arrayofmesures,
'position',
'asc', 0, 0, 1);
230 $arrayofxaxis = fillArrayOfXAxis($object,
't', $langs->trans($newarrayoftype[$objecttype][
'label']), $arrayofxaxis, 0, $count);
231 $arrayofxaxis =
dol_sort_array($arrayofxaxis,
'position',
'asc', 0, 0, 1);
234 $arrayofgroupby = fillArrayOfGroupBy($object,
't', $langs->trans($newarrayoftype[$objecttype][
'label']), $arrayofgroupby, 0, $count);
235 $arrayofgroupby =
dol_sort_array($arrayofgroupby,
'position',
'asc', 0, 0, 1);
239 if ($action ==
'viewgraph') {
240 if (!count($search_measures)) {
241 setEventMessages($langs->trans(
"AtLeastOneMeasureIsRequired"),
null,
'warnings');
242 } elseif ($mode ==
'graph' && count($search_xaxis) > 1) {
243 setEventMessages($langs->trans(
"OnlyOneFieldForXAxisIsPossible"),
null,
'warnings');
244 $search_xaxis = array(0 => $search_xaxis[0]);
246 if (count($search_groupby) >= 2) {
247 setEventMessages($langs->trans(
"ErrorOnlyOneFieldForGroupByIsPossible"),
null,
'warnings');
248 $search_groupby = array(0 => $search_groupby[0]);
250 if (!count($search_xaxis)) {
251 setEventMessages($langs->trans(
"AtLeastOneXAxisIsRequired"),
null,
'warnings');
252 } elseif ($mode ==
'graph' && $search_graph ==
'bars' && count($search_measures) > $MAXMEASURESINBARGRAPH) {
253 $langs->load(
"errors");
254 setEventMessages($langs->trans(
"GraphInBarsAreLimitedToNMeasures", $MAXMEASURESINBARGRAPH),
null,
'warnings');
255 $search_graph =
'lines';
261 if (is_array($search_groupby) && count($search_groupby)) {
262 foreach ($search_groupby as $gkey => $gval) {
263 $gvalwithoutprefix = preg_replace(
'/^[a-z]+\./',
'', $gval);
265 if (preg_match(
'/\-year$/', $search_groupby[$gkey])) {
266 $tmpval = preg_replace(
'/\-year$/',
'', $search_groupby[$gkey]);
267 $fieldtocount .=
'DATE_FORMAT('.$tmpval.
", '%Y')";
268 } elseif (preg_match(
'/\-month$/', $search_groupby[$gkey])) {
269 $tmpval = preg_replace(
'/\-month$/',
'', $search_groupby[$gkey]);
270 $fieldtocount .=
'DATE_FORMAT('.$tmpval.
", '%Y-%m')";
271 } elseif (preg_match(
'/\-day$/', $search_groupby[$gkey])) {
272 $tmpval = preg_replace(
'/\-day$/',
'', $search_groupby[$gkey]);
273 $fieldtocount .=
'DATE_FORMAT('.$tmpval.
", '%Y-%m-%d')";
275 $fieldtocount = $search_groupby[$gkey];
278 $sql =
"SELECT DISTINCT ".$fieldtocount.
" as val";
280 if (strpos($fieldtocount,
'te.') === 0) {
281 $sql .=
" FROM ".MAIN_DB_PREFIX.$object->table_element.
"_extrafields as te";
283 $tabletouse = $object->table_element;
284 $tablealiastouse =
't';
285 if (!empty($arrayofgroupby[$gval])) {
286 $tmpval = explode(
'.', $gval);
287 $tabletouse = $arrayofgroupby[$gval][
'table'];
288 $tablealiastouse = $tmpval[0];
290 $sql .=
" FROM ".MAIN_DB_PREFIX.$tabletouse.
" as ".$tablealiastouse;
306 $sql .=
" LIMIT ".((int) ($MAXUNIQUEVALFORGROUP + 1));
309 $resql = $db->query($sql);
314 while ($obj = $db->fetch_object(
$resql)) {
315 if (is_null($obj->val)) {
316 $keytouse =
'__NULL__';
317 $valuetranslated = $langs->transnoentitiesnoconv(
"NotDefined");
318 } elseif ($obj->val ===
'') {
320 $valuetranslated = $langs->transnoentitiesnoconv(
"Empty");
322 $keytouse = (string) $obj->val;
323 $valuetranslated = $obj->val;
327 if (!empty($object->fields[$gvalwithoutprefix][
'arrayofkeyval'])) {
328 $valuetranslated = $object->fields[$gvalwithoutprefix][
'arrayofkeyval'][$obj->val];
329 if (is_null($valuetranslated)) {
330 $valuetranslated = $langs->transnoentitiesnoconv(
"UndefinedKey");
332 $valuetranslated = $langs->trans($valuetranslated);
333 } elseif (preg_match(
'/integer:([^:]+):([^:]+)$/', $object->fields[$gvalwithoutprefix][
'type'], $regs)) {
334 $classname = $regs[1];
335 $classpath = $regs[2];
337 if (class_exists($classname)) {
338 $tmpobject =
new $classname($db);
339 $tmpobject->fetch($obj->val);
340 foreach ($tmpobject->fields as $fieldkey => $field) {
341 if ($field[
'showoncombobox']) {
342 $valuetranslated = $tmpobject->$fieldkey;
351 $arrayofvaluesforgroupby[
'g_'.$gkey][$keytouse] = $valuetranslated;
354 $tmpfield = explode(
'.', $gval);
355 if ($tmpfield[0] !=
't' || (is_array($object->fields[$tmpfield[1]]) && empty($object->fields[$tmpfield[1]][
'notnull']))) {
356 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");
358 $arrayofvaluesforgroupby[
'g_'.$gkey][
'__NULL__'] = $langs->transnoentitiesnoconv(
"NotDefined");
361 asort($arrayofvaluesforgroupby[
'g_'.$gkey]);
364 if (count($arrayofvaluesforgroupby[
'g_'.$gkey]) > $MAXUNIQUEVALFORGROUP) {
365 $langs->load(
"errors");
366 if (strpos($fieldtocount,
'te.') === 0) {
370 $keyforlabeloffield = $extrafields->attributes[$object->table_element][
'label'][$gvalwithoutprefix];
372 $keyforlabeloffield = $object->fields[$gvalwithoutprefix][
'label'];
375 $gvalwithoutprefix = preg_replace(
'/\-(year|month|day)/',
'', $gvalwithoutprefix);
376 $labeloffield = $langs->transnoentitiesnoconv($keyforlabeloffield);
377 setEventMessages($langs->trans(
"ErrorTooManyDifferentValueForSelectedGroupBy", $MAXUNIQUEVALFORGROUP, $labeloffield),
null,
'warnings');
378 $search_groupby = array();
388 $endyear = $tmparray[
'year'];
389 $endmonth = $tmparray[
'mon'];
391 $startyear = $endyear - 2;
395 print
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'">';
396 print
'<input type="hidden" name="token" value="'.newToken().
'">';
397 print
'<input type="hidden" name="action" value="viewgraph">';
398 print
'<input type="hidden" name="tabfamily" value="'.$tabfamily.
'">';
402 $viewmode .=
'<div class="divadvancedsearchfield">';
403 $arrayofgraphs = array(
'bars' =>
'Bars',
'lines' =>
'Lines');
404 $viewmode .=
'<div class="inline-block opacitymedium"><span class="fas fa-chart-area paddingright" title="'.$langs->trans(
"Graph").
'"></span>'.$langs->trans(
"Graph").
'</div> ';
405 $viewmode .=
$form->selectarray(
'search_graph', $arrayofgraphs, $search_graph, 0, 0, 0,
'minwidth100', 1);
406 $viewmode .=
'</div>';
409 $massactionbutton =
'';
414 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);
418 print
'<div class="liste_titre liste_titre_bydiv centpercent">';
421 print
'<div class="divadvancedsearchfield center floatnone">';
422 print
'<div class="inline-block"><span class="opacitymedium">'.$langs->trans(
"StatisticsOn").
'</span></div> ';
423 print
$form->selectarray(
'objecttype', $newarrayoftype, $objecttype, 0, 0, 0,
'', 1, 0, 0,
'',
'minwidth200', 1);
424 if (empty($conf->use_javascript_ajax)) {
425 print
'<input type="submit" class="button buttongen button-save nomargintop" name="changeobjecttype" value="'.$langs->trans(
"Refresh").
'">';
427 print
'<!-- js code to reload page with good object type -->
428 <script type="text/javascript">
429 jQuery(document).ready(function() {
430 jQuery("#objecttype").change(function() {
431 console.log("Reload for "+jQuery("#objecttype").val());
432 location.href = "'.$_SERVER[
"PHP_SELF"].
'?objecttype="+jQuery("#objecttype").val()+"'.($tabfamily ?
'&tabfamily='.urlencode($tabfamily) :
'').(
GETPOST(
'show_search_component_params_hidden',
'int') ?
'&show_search_component_params_hidden='.((int)
GETPOST(
'show_search_component_params_hidden',
'int')) :
'').
'";
437 print
'</div><div class="clearboth"></div>';
440 print
'<div class="divadvancedsearchfield quatrevingtpercent">';
441 print
$form->searchComponent(array($object->element => $object->fields), $search_component_params, array(), $search_component_params_hidden);
447 print
'<div class="divadvancedsearchfield clearboth">';
448 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>';
449 $simplearrayofmesures = array();
450 foreach ($arrayofmesures as $key => $val) {
451 $simplearrayofmesures[$key] = $arrayofmesures[$key][
'label'];
453 print
$form->multiselectarray(
'search_measures', $simplearrayofmesures, $search_measures, 0, 0,
'minwidth400', 1, 0,
'',
'', $langs->trans(
"Measures"));
458 print
'<div class="divadvancedsearchfield">';
459 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>';
461 print $formother->selectXAxisField($object, $search_xaxis, $arrayofxaxis, $langs->trans(
"XAxis"));
466 print
'<div class="divadvancedsearchfield">';
467 print
'<div class="inline-block opacitymedium"><span class="fas fa-ruler-horizontal paddingright pictofixedwidth" title="'.dol_escape_htmltag($langs->trans(
"GroupBy")).
'"></span></div>';
468 print $formother->selectGroupByField($object, $search_groupby, $arrayofgroupby,
'minwidth250 maxwidth300', $langs->trans(
"GroupBy"));
472 if ($mode ==
'grid') {
474 print
'<div class="divadvancedsearchfield">';
475 foreach ($object->fields as $key => $val) {
476 if (empty($val[
'measure']) && (!isset($val[
'enabled']) ||
dol_eval($val[
'enabled'], 1, 1,
'1'))) {
477 if (in_array($key, array(
'id',
'rowid',
'entity',
'last_main_doc',
'extraparams'))) {
480 if (preg_match(
'/^fk_/', $key)) {
483 if (in_array($val[
'type'], array(
'html',
'text'))) {
486 if (in_array($val[
'type'], array(
'timestamp',
'date',
'datetime'))) {
487 $arrayofyaxis[
't.'.$key.
'-year'] = array(
488 'label' => $langs->trans($val[
'label']).
' ('.$YYYY.
')',
489 'position' => $val[
'position'],
490 'table' => $object->table_element
492 $arrayofyaxis[
't.'.$key.
'-month'] = array(
493 'label' => $langs->trans($val[
'label']).
' ('.$YYYY.
'-'.$MM.
')',
494 'position' => $val[
'position'],
495 'table' => $object->table_element
497 $arrayofyaxis[
't.'.$key.
'-day'] = array(
498 'label' => $langs->trans($val[
'label']).
' ('.$YYYY.
'-'.$MM.
'-'.$DD.
')',
499 'position' => $val[
'position'],
500 'table' => $object->table_element
503 $arrayofyaxis[
't.'.$key] = array(
504 'label' => $val[
'label'],
505 'position' => (
int) $val[
'position'],
506 'table' => $object->table_element
512 if ($object->isextrafieldmanaged) {
513 foreach ($extrafields->attributes[$object->table_element][
'label'] as $key => $val) {
514 if (!empty($extrafields->attributes[$object->table_element][
'totalizable'][$key]) && (!isset($extrafields->attributes[$object->table_element][
'enabled'][$key]) ||
dol_eval($extrafields->attributes[$object->table_element][
'enabled'][$key], 1, 1,
'1'))) {
515 $arrayofyaxis[
'te.'.$key] = array(
516 'label' => $extrafields->attributes[$object->table_element][
'label'][$key],
517 'position' => (
int) $extrafields->attributes[$object->table_element][
'pos'][$key],
518 'table' => $object->table_element
524 $arrayofyaxislabel = array();
525 foreach ($arrayofyaxis as $key => $val) {
526 $arrayofyaxislabel[$key] = $val[
'label'];
528 print
'<div class="inline-block opacitymedium"><span class="fas fa-ruler-vertical paddingright" title="'.$langs->trans(
"YAxis").
'"></span>'.$langs->trans(
"YAxis").
'</div> ';
529 print
$form->multiselectarray(
'search_yaxis', $arrayofyaxislabel, $search_yaxis, 0, 0,
'minwidth100', 1);
533 if ($mode ==
'graph') {
537 print
'<div class="divadvancedsearchfield">';
538 print
'<input type="submit" class="button buttongen button-save nomargintop" value="'.$langs->trans(
"Refresh").
'">';
545 if (!empty($search_measures) && !empty($search_xaxis)) {
549 foreach ($search_xaxis as $key => $val) {
550 if (preg_match(
'/\-year$/', $val)) {
551 $tmpval = preg_replace(
'/\-year$/',
'', $val);
552 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y') as x_".$key.
', ';
553 } elseif (preg_match(
'/\-month$/', $val)) {
554 $tmpval = preg_replace(
'/\-month$/',
'', $val);
555 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m') as x_".$key.
', ';
556 } elseif (preg_match(
'/\-day$/', $val)) {
557 $tmpval = preg_replace(
'/\-day$/',
'', $val);
558 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m-%d') as x_".$key.
', ';
560 $sql .= $val.
" as x_".$key.
", ";
563 foreach ($search_groupby as $key => $val) {
564 if (preg_match(
'/\-year$/', $val)) {
565 $tmpval = preg_replace(
'/\-year$/',
'', $val);
566 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y') as g_".$key.
', ';
567 } elseif (preg_match(
'/\-month$/', $val)) {
568 $tmpval = preg_replace(
'/\-month$/',
'', $val);
569 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m') as g_".$key.
', ';
570 } elseif (preg_match(
'/\-day$/', $val)) {
571 $tmpval = preg_replace(
'/\-day$/',
'', $val);
572 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m-%d') as g_".$key.
', ';
574 $sql .= $val.
" as g_".$key.
", ";
577 foreach ($search_measures as $key => $val) {
578 if ($val ==
't.count') {
579 $sql .=
"COUNT(t.".$fieldid.
") as y_".$key.
', ';
580 } elseif (preg_match(
'/\-sum$/', $val)) {
581 $tmpval = preg_replace(
'/\-sum$/',
'', $val);
582 $sql .=
"SUM(".$db->ifsql($tmpval.
' IS NULL',
'0', $tmpval).
") as y_".$key.
", ";
583 } elseif (preg_match(
'/\-average$/', $val)) {
584 $tmpval = preg_replace(
'/\-average$/',
'', $val);
585 $sql .=
"AVG(".$db->ifsql($tmpval.
' IS NULL',
'0', $tmpval).
") as y_".$key.
", ";
586 } elseif (preg_match(
'/\-min$/', $val)) {
587 $tmpval = preg_replace(
'/\-min$/',
'', $val);
588 $sql .=
"MIN(".$db->ifsql($tmpval.
' IS NULL',
'0', $tmpval).
") as y_".$key.
", ";
589 } elseif (preg_match(
'/\-max$/', $val)) {
590 $tmpval = preg_replace(
'/\-max$/',
'', $val);
591 $sql .=
"MAX(".$db->ifsql($tmpval.
' IS NULL',
'0', $tmpval).
") as y_".$key.
", ";
594 $sql = preg_replace(
'/,\s*$/',
'', $sql);
595 $sql .=
" FROM ".MAIN_DB_PREFIX.$object->table_element.
" as t";
597 if ($object->isextrafieldmanaged) {
598 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element.
"_extrafields as te ON te.fk_object = t.".$fieldid;
601 if ($object->ismultientitymanaged) {
602 if ($object->ismultientitymanaged == 1) {
605 $tmparray = explode(
'@', $object->ismultientitymanaged);
606 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.$tmparray[1].
" as parenttableforentity ON t.".$tmparray[0].
" = parenttableforentity.rowid";
607 $sql .=
" AND parenttableforentity.entity IN (".getEntity($tmparray[1]).
")";
611 $listoftablesalreadyadded = array($object->table_element => $object->table_element);
615 foreach ($search_xaxis as $key => $val) {
616 if (!empty($arrayofxaxis[$val])) {
617 $tmpval = explode(
'.', $val);
619 if (! in_array($arrayofxaxis[$val][
'table'], $listoftablesalreadyadded)) {
620 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$arrayofxaxis[$val][
'table'].
" as ".$db->sanitize($tmpval[0]).
" ON t.".str_replace(
't__',
'', $db->sanitize($tmpval[0])).
" = ".$db->sanitize($tmpval[0]).
".rowid";
621 $listoftablesalreadyadded[$arrayofxaxis[$val][
'table']] = $arrayofxaxis[$val][
'table'];
624 dol_print_error($db,
'Found a key into search_xaxis not found into arrayofxaxis');
630 foreach ($search_groupby as $key => $val) {
631 if (!empty($arrayofgroupby[$val])) {
632 $tmpval = explode(
'.', $val);
634 if (! in_array($arrayofgroupby[$val][
'table'], $listoftablesalreadyadded)) {
635 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$arrayofgroupby[$val][
'table'].
" as ".$tmpval[0].
" ON t.".str_replace(
't__',
'', $tmpval[0]).
" = ".$tmpval[0].
".rowid";
636 $listoftablesalreadyadded[$arrayofgroupby[$val][
'table']] = $arrayofgroupby[$val][
'table'];
639 dol_print_error($db,
'Found a key into search_groupby not found into arrayofgroupby');
645 foreach ($search_measures as $key => $val) {
646 if (!empty($arrayofmesures[$val])) {
647 $tmpval = explode(
'.', $val);
649 if (! in_array($arrayofmesures[$val][
'table'], $listoftablesalreadyadded)) {
650 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$arrayofmesures[$val][
'table'].
" as ".$tmpval[0].
" ON t.".str_replace(
't__',
'', $tmpval[0]).
" = ".$tmpval[0].
".rowid";
651 $listoftablesalreadyadded[$arrayofmesures[$val][
'table']] = $arrayofmesures[$val][
'table'];
654 dol_print_error($db,
'Found a key into search_measures not found into arrayofmesures');
658 $sql .=
" WHERE 1 = 1";
659 if ($object->ismultientitymanaged == 1) {
660 $sql .=
" AND t.entity IN (".getEntity($object->element).
")";
663 $sqlfilters = $search_component_params_hidden;
667 $regexstring =
'\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
668 $sql .=
" AND (".preg_replace_callback(
'/'.$regexstring.
'/',
'dolForgeCriteriaCallback', $sqlfilters).
")";
673 $sql .=
" GROUP BY ";
674 foreach ($search_xaxis as $key => $val) {
675 if (preg_match(
'/\-year$/', $val)) {
676 $tmpval = preg_replace(
'/\-year$/',
'', $val);
677 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y'), ";
678 } elseif (preg_match(
'/\-month$/', $val)) {
679 $tmpval = preg_replace(
'/\-month$/',
'', $val);
680 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m'), ";
681 } elseif (preg_match(
'/\-day$/', $val)) {
682 $tmpval = preg_replace(
'/\-day$/',
'', $val);
683 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m-%d'), ";
688 foreach ($search_groupby as $key => $val) {
689 if (preg_match(
'/\-year$/', $val)) {
690 $tmpval = preg_replace(
'/\-year$/',
'', $val);
691 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y'), ";
692 } elseif (preg_match(
'/\-month$/', $val)) {
693 $tmpval = preg_replace(
'/\-month$/',
'', $val);
694 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m'), ";
695 } elseif (preg_match(
'/\-day$/', $val)) {
696 $tmpval = preg_replace(
'/\-day$/',
'', $val);
697 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m-%d'), ";
702 $sql = preg_replace(
'/,\s*$/',
'', $sql);
703 $sql .=
' ORDER BY ';
704 foreach ($search_xaxis as $key => $val) {
705 if (preg_match(
'/\-year$/', $val)) {
706 $tmpval = preg_replace(
'/\-year$/',
'', $val);
707 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y'), ";
708 } elseif (preg_match(
'/\-month$/', $val)) {
709 $tmpval = preg_replace(
'/\-month$/',
'', $val);
710 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m'), ";
711 } elseif (preg_match(
'/\-day$/', $val)) {
712 $tmpval = preg_replace(
'/\-day$/',
'', $val);
713 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m-%d'), ";
718 foreach ($search_groupby as $key => $val) {
719 if (preg_match(
'/\-year$/', $val)) {
720 $tmpval = preg_replace(
'/\-year$/',
'', $val);
721 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y'), ";
722 } elseif (preg_match(
'/\-month$/', $val)) {
723 $tmpval = preg_replace(
'/\-month$/',
'', $val);
724 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m'), ";
725 } elseif (preg_match(
'/\-day$/', $val)) {
726 $tmpval = preg_replace(
'/\-day$/',
'', $val);
727 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m-%d'), ";
732 $sql = preg_replace(
'/,\s*$/',
'', $sql);
737 foreach ($search_measures as $key => $val) {
738 $legend[] = $langs->trans($arrayofmesures[$val][
'label']);
741 $useagroupby = (is_array($search_groupby) && count($search_groupby));
746 $totalnbofrecord = 0;
749 $resql = $db->query($sql);
757 while ($obj = $db->fetch_object(
$resql)) {
760 $xval = $search_xaxis[0];
761 $fieldforxkey =
'x_0';
762 $xlabel = $obj->$fieldforxkey;
763 $xvalwithoutprefix = preg_replace(
'/^[a-z]+\./',
'', $xval);
766 if (!empty($object->fields[$xvalwithoutprefix][
'arrayofkeyval'])) {
767 $xlabel = $object->fields[$xvalwithoutprefix][
'arrayofkeyval'][$obj->$fieldforxkey];
769 $labeltouse = (($xlabel || $xlabel ==
'0') ?
dol_trunc($xlabel, 20,
'middle') : ($xlabel ===
'' ? $langs->transnoentitiesnoconv(
"Empty") : $langs->transnoentitiesnoconv(
"NotDefined")));
771 if ($oldlabeltouse && ($labeltouse != $oldlabeltouse)) {
775 $oldlabeltouse = $labeltouse;
788 foreach ($search_measures as $key => $val) {
790 foreach ($search_groupby as $gkey) {
793 foreach ($arrayofvaluesforgroupby[
'g_'.$gi] as $gvaluepossiblekey => $gvaluepossiblelabel) {
794 $ykeysuffix = $gvaluepossiblelabel;
795 $gvalwithoutprefix = preg_replace(
'/^[a-z]+\./',
'', $gval);
797 $fieldfory =
'y_'.$key;
798 $fieldforg =
'g_'.$gi;
799 $fieldforybis =
'y_'.$key.
'_'.$ykeysuffix;
803 if (!is_array($data[$xi])) {
804 $data[$xi] = array();
807 if (!array_key_exists(
'label', $data[$xi])) {
808 $data[$xi] = array();
809 $data[$xi][
'label'] = $labeltouse;
812 $objfieldforg = $obj->$fieldforg;
813 if (is_null($objfieldforg)) {
814 $objfieldforg =
'__NULL__';
817 if ($gvaluepossiblekey ==
'0') {
819 if ($objfieldforg ==
'0') {
821 $data[$xi][$fieldforybis] = $obj->$fieldfory;
822 } elseif (!isset($data[$xi][$fieldforybis])) {
824 $data[$xi][$fieldforybis] =
'0';
828 if ((
string) $objfieldforg === (
string) $gvaluepossiblekey) {
830 $data[$xi][$fieldforybis] = $obj->$fieldfory;
831 } elseif (!isset($data[$xi][$fieldforybis])) {
833 $data[$xi][$fieldforybis] =
'0';
842 $xval = $search_xaxis[0];
843 $fieldforxkey =
'x_0';
844 $xlabel = $obj->$fieldforxkey;
845 $xvalwithoutprefix = preg_replace(
'/^[a-z]+\./',
'', $xval);
848 if (!empty($object->fields[$xvalwithoutprefix][
'arrayofkeyval'])) {
849 $xlabel = $object->fields[$xvalwithoutprefix][
'arrayofkeyval'][$obj->$fieldforxkey];
852 $labeltouse = (($xlabel || $xlabel ==
'0') ?
dol_trunc($xlabel, 20,
'middle') : ($xlabel ===
'' ? $langs->trans(
"Empty") : $langs->trans(
"NotDefined")));
853 $xarrayforallseries = array(
'label' => $labeltouse);
854 foreach ($search_measures as $key => $val) {
855 $fieldfory =
'y_'.$key;
856 $xarrayforallseries[$fieldfory] = $obj->$fieldfory;
858 $data[$xi] = $xarrayforallseries;
863 $totalnbofrecord = count($data);
868 print
'<div class="customreportsoutput'.($totalnbofrecord ?
'' :
' customreportsoutputnotdata').
'">';
871 if ($mode ==
'grid') {
875 if ($mode ==
'graph') {
881 $mesg = $px1->isGraphKo();
885 $px1->SetData($data);
888 $arrayoftypes = array();
889 foreach ($search_measures as $key => $val) {
890 $arrayoftypes[] = $search_graph;
893 $px1->SetLegend($legend);
894 $px1->SetMinValue($px1->GetFloorMinValue());
895 $px1->SetMaxValue($px1->GetCeilMaxValue());
896 $px1->SetWidth($WIDTH);
897 $px1->SetHeight($HEIGHT);
898 $px1->SetYLabel($langs->trans(
"Y"));
900 $px1->SetHorizTickIncrement(1);
901 $px1->SetCssPrefix(
"cssboxes");
902 $px1->SetType($arrayoftypes);
903 $px1->mode =
'depth';
906 $dir = $conf->user->dir_temp;
908 $filenamenb = $dir.
'/customreport_'.$object->element.
'.png';
909 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=user&file=customreport_'.$object->element.
'.png';
911 $px1->draw($filenamenb, $fileurlnb);
913 $texttoshow = $langs->trans(
"NoRecordFound");
915 $texttoshow = $langs->trans(
"SelectYourGraphOptionsFirst");
918 print $px1->show($totalnbofrecord ? 0 : $texttoshow);
924 print
'<br>'.info_admin($langs->trans(
"SQLUsedForExport").
':<br> '.$sql, 0, 0, 1,
'',
'TechnicalInformation');
929 if (!defined(
'USE_CUSTOM_REPORT_AS_INCLUDE')) {
953 function fillArrayOfMeasures($object, $tablealias, $labelofobject, &$arrayofmesures, $level = 0, &$count = 0)
955 global $langs, $extrafields, $db;
958 return $arrayofmesures;
963 $arrayofmesures[$tablealias.
'.count'] = array(
964 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': Count',
966 'table' => $object->table_element
971 foreach ($object->fields as $key => $val) {
972 if (!empty($val[
'isameasure']) && (!isset($val[
'enabled']) ||
dol_eval($val[
'enabled'], 1, 1,
'1'))) {
973 $position = (empty($val[
'position']) ? 0 : intVal($val[
'position']));
974 $arrayofmesures[$tablealias.
'.'.$key.
'-sum'] = array(
975 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']).
' <span class="opacitymedium">('.$langs->trans(
"Sum").
')</span>',
976 'position' => ($position + ($count * 100000)).
'.1',
977 'table' => $object->table_element
979 $arrayofmesures[$tablealias.
'.'.$key.
'-average'] = array(
980 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']).
' <span class="opacitymedium">('.$langs->trans(
"Average").
')</span>',
981 'position' => ($position + ($count * 100000)).
'.2',
982 'table' => $object->table_element
984 $arrayofmesures[$tablealias.
'.'.$key.
'-min'] = array(
985 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']).
' <span class="opacitymedium">('.$langs->trans(
"Minimum").
')</span>',
986 'position' => ($position + ($count * 100000)).
'.3',
987 'table' => $object->table_element
989 $arrayofmesures[$tablealias.
'.'.$key.
'-max'] = array(
990 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']).
' <span class="opacitymedium">('.$langs->trans(
"Maximum").
')</span>',
991 'position' => ($position + ($count * 100000)).
'.4',
992 'table' => $object->table_element
997 if (!empty($object->isextrafieldmanaged)) {
998 foreach ($extrafields->attributes[$object->table_element][
'label'] as $key => $val) {
999 if (!empty($extrafields->attributes[$object->table_element][
'totalizable'][$key]) && (!isset($extrafields->attributes[$object->table_element][
'enabled'][$key]) ||
dol_eval($extrafields->attributes[$object->table_element][
'enabled'][$key], 1, 1,
'1'))) {
1000 $position = (!empty($val[
'position']) ? $val[
'position'] : 0);
1001 $arrayofmesures[$tablealias.
'e.'.$key.
'-sum'] = array(
1002 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($extrafields->attributes[$object->table_element][
'label'][$key]).
' <span class="opacitymedium">('.$langs->trans(
"Sum").
')</span>',
1003 'position' => ($position+($count * 100000)).
'.1',
1004 'table' => $object->table_element
1006 $arrayofmesures[$tablealias.
'e.'.$key.
'-average'] = array(
1007 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($extrafields->attributes[$object->table_element][
'label'][$key]).
' <span class="opacitymedium">('.$langs->trans(
"Average").
')</span>',
1008 'position' => ($position+($count * 100000)).
'.2',
1009 'table' => $object->table_element
1011 $arrayofmesures[$tablealias.
'e.'.$key.
'-min'] = array(
1012 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($extrafields->attributes[$object->table_element][
'label'][$key]).
' <span class="opacitymedium">('.$langs->trans(
"Minimum").
')</span>',
1013 'position' => ($position+($count * 100000)).
'.3',
1014 'table' => $object->table_element
1016 $arrayofmesures[$tablealias.
'e.'.$key.
'-max'] = array(
1017 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($extrafields->attributes[$object->table_element][
'label'][$key]).
' <span class="opacitymedium">('.$langs->trans(
"Maximum").
')</span>',
1018 'position' => ($position+($count * 100000)).
'.4',
1019 'table' => $object->table_element
1025 foreach ($object->fields as $key => $val) {
1026 if (preg_match(
'/^[^:]+:[^:]+:/', $val[
'type'])) {
1027 $tmptype = explode(
':', $val[
'type'], 4);
1028 if ($tmptype[0] ==
'integer' && $tmptype[1] && $tmptype[2]) {
1029 $newobject = $tmptype[1];
1031 if (class_exists($newobject)) {
1032 $tmpobject =
new $newobject($db);
1035 $arrayofmesures = fillArrayOfMeasures($tmpobject, $tablealias.
'__'.$key, $langs->trans($val[
'label']), $arrayofmesures, $level + 1, $count);
1037 print
'For property '.$object->element.
'->'.$key.
', type="'.$val[
'type'].
'": Failed to find class '.$newobject.
" in file ".$tmptype[2].
"<br>\n";
1043 return $arrayofmesures;
1058 function fillArrayOfXAxis($object, $tablealias, $labelofobject, &$arrayofxaxis, $level = 0, &$count = 0)
1060 global $langs, $extrafields, $db;
1063 return $arrayofxaxis;
1067 return $arrayofxaxis;
1070 $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);
1071 $MM = substr($langs->trans(
"Month"), 0, 1).substr($langs->trans(
"Month"), 0, 1);
1072 $DD = substr($langs->trans(
"Day"), 0, 1).substr($langs->trans(
"Day"), 0, 1);
1073 $HH = substr($langs->trans(
"Hour"), 0, 1).substr($langs->trans(
"Hour"), 0, 1);
1074 $MI = substr($langs->trans(
"Minute"), 0, 1).substr($langs->trans(
"Minute"), 0, 1);
1075 $SS = substr($langs->trans(
"Second"), 0, 1).substr($langs->trans(
"Second"), 0, 1);
1078 foreach ($object->fields as $key => $val) {
1079 if (empty($val[
'measure'])) {
1080 if (in_array($key, array(
1081 'id',
'ref_int',
'ref_ext',
'rowid',
'entity',
'last_main_doc',
'logo',
'logo_squarred',
'extraparams',
1082 'parent',
'photo',
'socialnetworks',
'webservices_url',
'webservices_key'))) {
1085 if (isset($val[
'enabled']) && !
dol_eval($val[
'enabled'], 1, 1,
'1')) {
1088 if (isset($val[
'visible']) && !
dol_eval($val[
'visible'], 1, 1,
'1')) {
1091 if (preg_match(
'/^fk_/', $key) && !preg_match(
'/^fk_statu/', $key)) {
1094 if (preg_match(
'/^pass/', $key)) {
1097 if (in_array($val[
'type'], array(
'html',
'text'))) {
1100 if (in_array($val[
'type'], array(
'timestamp',
'date',
'datetime'))) {
1101 $position = (empty($val[
'position']) ? 0 : intVal($val[
'position']));
1102 $arrayofxaxis[$tablealias.
'.'.$key.
'-year'] = array(
1103 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']).
' <span class="opacitymedium">('.$YYYY.
')</span>',
1104 'position' => ($position + ($count * 100000)).
'.1',
1105 'table' => $object->table_element
1107 $arrayofxaxis[$tablealias.
'.'.$key.
'-month'] = array(
1108 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']).
' <span class="opacitymedium">('.$YYYY.
'-'.$MM.
')</span>',
1109 'position' => ($position + ($count * 100000)).
'.2',
1110 'table' => $object->table_element
1112 $arrayofxaxis[$tablealias.
'.'.$key.
'-day'] = array(
1113 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']).
' <span class="opacitymedium">('.$YYYY.
'-'.$MM.
'-'.$DD.
')</span>',
1114 'position' => ($position + ($count * 100000)).
'.3',
1115 'table' => $object->table_element
1118 $position = (empty($val[
'position']) ? 0 : intVal($val[
'position']));
1119 $arrayofxaxis[$tablealias.
'.'.$key] = array(
1120 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']),
1121 'position' => ($position + ($count * 100000)),
1122 'table' => $object->table_element
1129 if (!empty($object->isextrafieldmanaged)) {
1130 foreach ($extrafields->attributes[$object->table_element][
'label'] as $key => $val) {
1131 if ($extrafields->attributes[$object->table_element][
'type'][$key] ==
'separate') {
1134 if (!empty($extrafields->attributes[$object->table_element][
'totalizable'][$key])) {
1137 $arrayofxaxis[$tablealias.
'e.'.$key] = array(
1138 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($extrafields->attributes[$object->table_element][
'label'][$key]),
1139 'position' => 1000 + (
int) $extrafields->attributes[$object->table_element][
'pos'][$key] + ($count * 100000),
1140 'table' => $object->table_element
1146 foreach ($object->fields as $key => $val) {
1147 if (preg_match(
'/^[^:]+:[^:]+:/', $val[
'type'])) {
1148 $tmptype = explode(
':', $val[
'type'], 4);
1149 if ($tmptype[0] ==
'integer' && $tmptype[1] && $tmptype[2]) {
1150 $newobject = $tmptype[1];
1152 if (class_exists($newobject)) {
1153 $tmpobject =
new $newobject($db);
1156 $arrayofxaxis = fillArrayOfXAxis($tmpobject, $tablealias.
'__'.$key, $langs->trans($val[
'label']), $arrayofxaxis, $level + 1, $count);
1158 print
'For property '.$object->element.
'->'.$key.
', type="'.$val[
'type'].
'": Failed to find class '.$newobject.
" in file ".$tmptype[2].
"<br>\n";
1164 return $arrayofxaxis;
1179 function fillArrayOfGroupBy($object, $tablealias, $labelofobject, &$arrayofgroupby, $level = 0, &$count = 0)
1181 global $langs, $extrafields, $db;
1184 return $arrayofgroupby;
1188 return $arrayofgroupby;
1191 $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);
1192 $MM = substr($langs->trans(
"Month"), 0, 1).substr($langs->trans(
"Month"), 0, 1);
1193 $DD = substr($langs->trans(
"Day"), 0, 1).substr($langs->trans(
"Day"), 0, 1);
1194 $HH = substr($langs->trans(
"Hour"), 0, 1).substr($langs->trans(
"Hour"), 0, 1);
1195 $MI = substr($langs->trans(
"Minute"), 0, 1).substr($langs->trans(
"Minute"), 0, 1);
1196 $SS = substr($langs->trans(
"Second"), 0, 1).substr($langs->trans(
"Second"), 0, 1);
1199 foreach ($object->fields as $key => $val) {
1200 if (empty($val[
'isameasure'])) {
1201 if (in_array($key, array(
1202 'id',
'ref_int',
'ref_ext',
'rowid',
'entity',
'last_main_doc',
'logo',
'logo_squarred',
'extraparams',
1203 'parent',
'photo',
'socialnetworks',
'webservices_url',
'webservices_key'))) {
1206 if (isset($val[
'enabled']) && !
dol_eval($val[
'enabled'], 1, 1,
'1')) {
1209 if (isset($val[
'visible']) && !
dol_eval($val[
'visible'], 1, 1,
'1')) {
1212 if (preg_match(
'/^fk_/', $key) && !preg_match(
'/^fk_statu/', $key)) {
1215 if (preg_match(
'/^pass/', $key)) {
1218 if (in_array($val[
'type'], array(
'html',
'text'))) {
1221 if (in_array($val[
'type'], array(
'timestamp',
'date',
'datetime'))) {
1222 $position = (empty($val[
'position']) ? 0 : intVal($val[
'position']));
1223 $arrayofgroupby[$tablealias.
'.'.$key.
'-year'] = array(
1224 'label' =>
img_picto(
'', $object->picto,
1225 'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']).
' <span class="opacitymedium">('.$YYYY.
')</span>',
'position' => ($position + ($count * 100000)).
'.1',
1226 'table' => $object->table_element
1228 $arrayofgroupby[$tablealias.
'.'.$key.
'-month'] = array(
1229 'label' =>
img_picto(
'', $object->picto,
1230 'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']).
' <span class="opacitymedium">('.$YYYY.
'-'.$MM.
')</span>',
'position' => ($position + ($count * 100000)).
'.2',
1231 'table' => $object->table_element
1233 $arrayofgroupby[$tablealias.
'.'.$key.
'-day'] = array(
1234 'label' =>
img_picto(
'', $object->picto,
1235 'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']).
' <span class="opacitymedium">('.$YYYY.
'-'.$MM.
'-'.$DD.
')</span>',
'position' => ($position + ($count * 100000)).
'.3',
1236 'table' => $object->table_element
1239 $position = (empty($val[
'position']) ? 0 : intVal($val[
'position']));
1240 $arrayofgroupby[$tablealias.
'.'.$key] = array(
1241 'label' =>
img_picto(
'', $object->picto,
1242 'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']),
'position' => ($position + ($count * 100000)),
1243 'table' => $object->table_element
1250 if (! empty($object->isextrafieldmanaged)) {
1251 foreach ($extrafields->attributes[$object->table_element][
'label'] as $key => $val) {
1252 if ($extrafields->attributes[$object->table_element][
'type'][$key] ==
'separate') {
1255 if (!empty($extrafields->attributes[$object->table_element][
'totalizable'][$key])) {
1258 $arrayofgroupby[$tablealias.
'e.'.$key] = array(
1259 'label' =>
img_picto(
'', $object->picto,
1260 'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($extrafields->attributes[$object->table_element][
'label'][$key]),
'position' => 1000 + (
int) $extrafields->attributes[$object->table_element][
'pos'][$key] + ($count * 100000),
1261 'table' => $object->table_element
1267 foreach ($object->fields as $key => $val) {
1268 if (preg_match(
'/^[^:]+:[^:]+:/', $val[
'type'])) {
1269 $tmptype = explode(
':', $val[
'type'], 4);
1270 if ($tmptype[0] ==
'integer' && $tmptype[1] && $tmptype[2]) {
1271 $newobject = $tmptype[1];
1273 if (class_exists($newobject)) {
1274 $tmpobject =
new $newobject($db);
1277 $arrayofgroupby = fillArrayOfGroupBy($tmpobject, $tablealias.
'__'.$key, $langs->trans($val[
'label']), $arrayofgroupby, $level + 1, $count);
1279 print
'For property '.$object->element.
'->'.$key.
', type="'.$val[
'type'].
'": Failed to find class '.$newobject.
" in file ".$tmptype[2].
"<br>\n";
1285 return $arrayofgroupby;