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;
301 $sql .=
" LIMIT ".((int) ($MAXUNIQUEVALFORGROUP + 1));
304 $resql = $db->query($sql);
309 while ($obj = $db->fetch_object(
$resql)) {
310 if (is_null($obj->val)) {
311 $keytouse =
'__NULL__';
312 $valuetranslated = $langs->transnoentitiesnoconv(
"NotDefined");
313 } elseif ($obj->val ===
'') {
315 $valuetranslated = $langs->transnoentitiesnoconv(
"Empty");
317 $keytouse = (string) $obj->val;
318 $valuetranslated = $obj->val;
322 if (!empty($object->fields[$gvalwithoutprefix][
'arrayofkeyval'])) {
323 $valuetranslated = $object->fields[$gvalwithoutprefix][
'arrayofkeyval'][$obj->val];
324 if (is_null($valuetranslated)) {
325 $valuetranslated = $langs->transnoentitiesnoconv(
"UndefinedKey");
327 $valuetranslated = $langs->trans($valuetranslated);
328 } elseif (preg_match(
'/integer:([^:]+):([^:]+)$/', $object->fields[$gvalwithoutprefix][
'type'], $regs)) {
329 $classname = $regs[1];
330 $classpath = $regs[2];
332 if (class_exists($classname)) {
333 $tmpobject =
new $classname($db);
334 $tmpobject->fetch($obj->val);
335 foreach ($tmpobject->fields as $fieldkey => $field) {
336 if ($field[
'showoncombobox']) {
337 $valuetranslated = $tmpobject->$fieldkey;
346 $arrayofvaluesforgroupby[
'g_'.$gkey][$keytouse] = $valuetranslated;
349 $tmpfield = explode(
'.', $gval);
350 if ($tmpfield[0] !=
't' || (is_array($object->fields[$tmpfield[1]]) && empty($object->fields[$tmpfield[1]][
'notnull']))) {
351 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");
353 $arrayofvaluesforgroupby[
'g_'.$gkey][
'__NULL__'] = $langs->transnoentitiesnoconv(
"NotDefined");
356 asort($arrayofvaluesforgroupby[
'g_'.$gkey]);
359 if (count($arrayofvaluesforgroupby[
'g_'.$gkey]) > $MAXUNIQUEVALFORGROUP) {
360 $langs->load(
"errors");
361 if (strpos($fieldtocount,
'te.') === 0) {
365 $keyforlabeloffield = $extrafields->attributes[$object->table_element][
'label'][$gvalwithoutprefix];
366 $labeloffield = $langs->transnoentitiesnoconv($keyforlabeloffield);
367 } elseif (strpos($fieldtocount,
't__') === 0) {
369 if (preg_match(
'/^(.*)\.(.*)/', $gvalwithoutprefix, $reg)) {
370 $gvalwithoutprefix = preg_replace(
'/\..*$/',
'', $gvalwithoutprefix);
371 $gvalwithoutprefix = preg_replace(
'/t__/',
'', $gvalwithoutprefix);
372 $keyforlabeloffield = $object->fields[$gvalwithoutprefix][
'label'];
373 $labeloffield = $langs->transnoentitiesnoconv($keyforlabeloffield).
'-'.$reg[2];
375 $labeloffield = $langs->transnoentitiesnoconv($keyforlabeloffield);
379 if (preg_match(
'/^(.*)\-(year|month|day)/', $gvalwithoutprefix, $reg)) {
380 $gvalwithoutprefix = preg_replace(
'/\-(year|month|day)/',
'', $gvalwithoutprefix);
381 $keyforlabeloffield = $object->fields[$gvalwithoutprefix][
'label'];
382 $labeloffield = $langs->transnoentitiesnoconv($keyforlabeloffield).
'-'.$reg[2];
384 $keyforlabeloffield = $object->fields[$gvalwithoutprefix][
'label'];
385 $labeloffield = $langs->transnoentitiesnoconv($keyforlabeloffield);
390 setEventMessages($langs->trans(
"ErrorTooManyDifferentValueForSelectedGroupBy", $MAXUNIQUEVALFORGROUP, $labeloffield),
null,
'warnings');
391 $search_groupby = array();
401 $endyear = $tmparray[
'year'];
402 $endmonth = $tmparray[
'mon'];
404 $startyear = $endyear - 2;
408 print
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'">';
409 print
'<input type="hidden" name="token" value="'.newToken().
'">';
410 print
'<input type="hidden" name="action" value="viewgraph">';
411 print
'<input type="hidden" name="tabfamily" value="'.$tabfamily.
'">';
415 $viewmode .=
'<div class="divadvancedsearchfield">';
416 $arrayofgraphs = array(
'bars' =>
'Bars',
'lines' =>
'Lines');
417 $viewmode .=
'<div class="inline-block opacitymedium"><span class="fas fa-chart-area paddingright" title="'.$langs->trans(
"Graph").
'"></span>'.$langs->trans(
"Graph").
'</div> ';
418 $viewmode .=
$form->selectarray(
'search_graph', $arrayofgraphs, $search_graph, 0, 0, 0,
'minwidth100', 1);
419 $viewmode .=
'</div>';
422 $massactionbutton =
'';
427 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);
431 print
'<div class="liste_titre liste_titre_bydiv centpercent">';
434 print
'<div class="divadvancedsearchfield center floatnone">';
435 print
'<div class="inline-block"><span class="opacitymedium">'.$langs->trans(
"StatisticsOn").
'</span></div> ';
436 print
$form->selectarray(
'objecttype', $newarrayoftype, $objecttype, 0, 0, 0,
'', 1, 0, 0,
'',
'minwidth200', 1);
437 if (empty($conf->use_javascript_ajax)) {
438 print
'<input type="submit" class="button buttongen button-save nomargintop" name="changeobjecttype" value="'.$langs->trans(
"Refresh").
'">';
440 print
'<!-- js code to reload page with good object type -->
441 <script type="text/javascript">
442 jQuery(document).ready(function() {
443 jQuery("#objecttype").change(function() {
444 console.log("Reload for "+jQuery("#objecttype").val());
445 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')) :
'').
'";
450 print
'</div><div class="clearboth"></div>';
453 print
'<div class="divadvancedsearchfield quatrevingtpercent">';
454 print
$form->searchComponent(array($object->element => $object->fields), $search_component_params, array(), $search_component_params_hidden);
460 print
'<div class="divadvancedsearchfield clearboth">';
461 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>';
462 $simplearrayofmesures = array();
463 foreach ($arrayofmesures as $key => $val) {
464 $simplearrayofmesures[$key] = $arrayofmesures[$key][
'label'];
466 print
$form->multiselectarray(
'search_measures', $simplearrayofmesures, $search_measures, 0, 0,
'minwidth300', 1, 0,
'',
'', $langs->trans(
"Measures"));
471 print
'<div class="divadvancedsearchfield">';
472 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>';
474 print $formother->selectXAxisField($object, $search_xaxis, $arrayofxaxis, $langs->trans(
"XAxis"),
'minwidth300 maxwidth400');
479 print
'<div class="divadvancedsearchfield">';
480 print
'<div class="inline-block opacitymedium"><span class="fas fa-ruler-horizontal paddingright pictofixedwidth" title="'.dol_escape_htmltag($langs->trans(
"GroupBy")).
'"></span></div>';
481 print $formother->selectGroupByField($object, $search_groupby, $arrayofgroupby,
'minwidth250 maxwidth300', $langs->trans(
"GroupBy"));
485 if ($mode ==
'grid') {
487 print
'<div class="divadvancedsearchfield">';
488 foreach ($object->fields as $key => $val) {
489 if (empty($val[
'measure']) && (!isset($val[
'enabled']) ||
dol_eval($val[
'enabled'], 1, 1,
'1'))) {
490 if (in_array($key, array(
'id',
'rowid',
'entity',
'last_main_doc',
'extraparams'))) {
493 if (preg_match(
'/^fk_/', $key)) {
496 if (in_array($val[
'type'], array(
'html',
'text'))) {
499 if (in_array($val[
'type'], array(
'timestamp',
'date',
'datetime'))) {
500 $arrayofyaxis[
't.'.$key.
'-year'] = array(
501 'label' => $langs->trans($val[
'label']).
' ('.$YYYY.
')',
502 'position' => $val[
'position'],
503 'table' => $object->table_element
505 $arrayofyaxis[
't.'.$key.
'-month'] = array(
506 'label' => $langs->trans($val[
'label']).
' ('.$YYYY.
'-'.$MM.
')',
507 'position' => $val[
'position'],
508 'table' => $object->table_element
510 $arrayofyaxis[
't.'.$key.
'-day'] = array(
511 'label' => $langs->trans($val[
'label']).
' ('.$YYYY.
'-'.$MM.
'-'.$DD.
')',
512 'position' => $val[
'position'],
513 'table' => $object->table_element
516 $arrayofyaxis[
't.'.$key] = array(
517 'label' => $val[
'label'],
518 'position' => (
int) $val[
'position'],
519 'table' => $object->table_element
525 if ($object->isextrafieldmanaged) {
526 foreach ($extrafields->attributes[$object->table_element][
'label'] as $key => $val) {
527 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'))) {
528 $arrayofyaxis[
'te.'.$key] = array(
529 'label' => $extrafields->attributes[$object->table_element][
'label'][$key],
530 'position' => (
int) $extrafields->attributes[$object->table_element][
'pos'][$key],
531 'table' => $object->table_element
537 $arrayofyaxislabel = array();
538 foreach ($arrayofyaxis as $key => $val) {
539 $arrayofyaxislabel[$key] = $val[
'label'];
541 print
'<div class="inline-block opacitymedium"><span class="fas fa-ruler-vertical paddingright" title="'.$langs->trans(
"YAxis").
'"></span>'.$langs->trans(
"YAxis").
'</div> ';
542 print
$form->multiselectarray(
'search_yaxis', $arrayofyaxislabel, $search_yaxis, 0, 0,
'minwidth100', 1);
546 if ($mode ==
'graph') {
550 print
'<div class="divadvancedsearchfield">';
551 print
'<input type="submit" class="button buttongen button-save nomargintop" value="'.$langs->trans(
"Refresh").
'">';
558 if (!empty($search_measures) && !empty($search_xaxis)) {
562 foreach ($search_xaxis as $key => $val) {
563 if (preg_match(
'/\-year$/', $val)) {
564 $tmpval = preg_replace(
'/\-year$/',
'', $val);
565 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y') as x_".$key.
', ';
566 } elseif (preg_match(
'/\-month$/', $val)) {
567 $tmpval = preg_replace(
'/\-month$/',
'', $val);
568 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m') as x_".$key.
', ';
569 } elseif (preg_match(
'/\-day$/', $val)) {
570 $tmpval = preg_replace(
'/\-day$/',
'', $val);
571 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m-%d') as x_".$key.
', ';
573 $sql .= $val.
" as x_".$key.
", ";
576 foreach ($search_groupby as $key => $val) {
577 if (preg_match(
'/\-year$/', $val)) {
578 $tmpval = preg_replace(
'/\-year$/',
'', $val);
579 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y') as g_".$key.
', ';
580 } elseif (preg_match(
'/\-month$/', $val)) {
581 $tmpval = preg_replace(
'/\-month$/',
'', $val);
582 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m') as g_".$key.
', ';
583 } elseif (preg_match(
'/\-day$/', $val)) {
584 $tmpval = preg_replace(
'/\-day$/',
'', $val);
585 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m-%d') as g_".$key.
', ';
587 $sql .= $val.
" as g_".$key.
", ";
590 foreach ($search_measures as $key => $val) {
591 if ($val ==
't.count') {
592 $sql .=
"COUNT(t.".$fieldid.
") as y_".$key.
', ';
593 } elseif (preg_match(
'/\-sum$/', $val)) {
594 $tmpval = preg_replace(
'/\-sum$/',
'', $val);
595 $sql .=
"SUM(".$db->ifsql($tmpval.
' IS NULL',
'0', $tmpval).
") as y_".$key.
", ";
596 } elseif (preg_match(
'/\-average$/', $val)) {
597 $tmpval = preg_replace(
'/\-average$/',
'', $val);
598 $sql .=
"AVG(".$db->ifsql($tmpval.
' IS NULL',
'0', $tmpval).
") as y_".$key.
", ";
599 } elseif (preg_match(
'/\-min$/', $val)) {
600 $tmpval = preg_replace(
'/\-min$/',
'', $val);
601 $sql .=
"MIN(".$db->ifsql($tmpval.
' IS NULL',
'0', $tmpval).
") as y_".$key.
", ";
602 } elseif (preg_match(
'/\-max$/', $val)) {
603 $tmpval = preg_replace(
'/\-max$/',
'', $val);
604 $sql .=
"MAX(".$db->ifsql($tmpval.
' IS NULL',
'0', $tmpval).
") as y_".$key.
", ";
607 $sql = preg_replace(
'/,\s*$/',
'', $sql);
608 $sql .=
" FROM ".MAIN_DB_PREFIX.$object->table_element.
" as t";
610 if ($object->isextrafieldmanaged) {
611 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element.
"_extrafields as te ON te.fk_object = t.".$fieldid;
614 if ($object->ismultientitymanaged) {
615 if ($object->ismultientitymanaged == 1) {
618 $tmparray = explode(
'@', $object->ismultientitymanaged);
619 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.$tmparray[1].
" as parenttableforentity ON t.".$tmparray[0].
" = parenttableforentity.rowid";
620 $sql .=
" AND parenttableforentity.entity IN (".getEntity($tmparray[1]).
")";
624 $listoftablesalreadyadded = array($object->table_element => $object->table_element);
628 foreach ($search_xaxis as $key => $val) {
629 if (!empty($arrayofxaxis[$val])) {
630 $tmpval = explode(
'.', $val);
632 if (! in_array($arrayofxaxis[$val][
'table'], $listoftablesalreadyadded)) {
633 $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";
634 $listoftablesalreadyadded[$arrayofxaxis[$val][
'table']] = $arrayofxaxis[$val][
'table'];
637 dol_print_error($db,
'Found a key into search_xaxis not found into arrayofxaxis');
643 foreach ($search_groupby as $key => $val) {
644 if (!empty($arrayofgroupby[$val])) {
645 $tmpval = explode(
'.', $val);
647 if (! in_array($arrayofgroupby[$val][
'table'], $listoftablesalreadyadded)) {
648 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$arrayofgroupby[$val][
'table'].
" as ".$tmpval[0].
" ON t.".str_replace(
't__',
'', $tmpval[0]).
" = ".$tmpval[0].
".rowid";
649 $listoftablesalreadyadded[$arrayofgroupby[$val][
'table']] = $arrayofgroupby[$val][
'table'];
652 dol_print_error($db,
'Found a key into search_groupby not found into arrayofgroupby');
658 foreach ($search_measures as $key => $val) {
659 if (!empty($arrayofmesures[$val])) {
660 $tmpval = explode(
'.', $val);
662 if (! in_array($arrayofmesures[$val][
'table'], $listoftablesalreadyadded)) {
663 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$arrayofmesures[$val][
'table'].
" as ".$tmpval[0].
" ON t.".str_replace(
't__',
'', $tmpval[0]).
" = ".$tmpval[0].
".rowid";
664 $listoftablesalreadyadded[$arrayofmesures[$val][
'table']] = $arrayofmesures[$val][
'table'];
667 dol_print_error($db,
'Found a key into search_measures not found into arrayofmesures');
671 $sql .=
" WHERE 1 = 1";
672 if ($object->ismultientitymanaged == 1) {
673 $sql .=
" AND t.entity IN (".getEntity($object->element).
")";
676 $sqlfilters = $search_component_params_hidden;
684 $sql .=
" GROUP BY ";
685 foreach ($search_xaxis as $key => $val) {
686 if (preg_match(
'/\-year$/', $val)) {
687 $tmpval = preg_replace(
'/\-year$/',
'', $val);
688 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y'), ";
689 } elseif (preg_match(
'/\-month$/', $val)) {
690 $tmpval = preg_replace(
'/\-month$/',
'', $val);
691 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m'), ";
692 } elseif (preg_match(
'/\-day$/', $val)) {
693 $tmpval = preg_replace(
'/\-day$/',
'', $val);
694 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m-%d'), ";
699 foreach ($search_groupby as $key => $val) {
700 if (preg_match(
'/\-year$/', $val)) {
701 $tmpval = preg_replace(
'/\-year$/',
'', $val);
702 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y'), ";
703 } elseif (preg_match(
'/\-month$/', $val)) {
704 $tmpval = preg_replace(
'/\-month$/',
'', $val);
705 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m'), ";
706 } elseif (preg_match(
'/\-day$/', $val)) {
707 $tmpval = preg_replace(
'/\-day$/',
'', $val);
708 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m-%d'), ";
713 $sql = preg_replace(
'/,\s*$/',
'', $sql);
714 $sql .=
' ORDER BY ';
715 foreach ($search_xaxis as $key => $val) {
716 if (preg_match(
'/\-year$/', $val)) {
717 $tmpval = preg_replace(
'/\-year$/',
'', $val);
718 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y'), ";
719 } elseif (preg_match(
'/\-month$/', $val)) {
720 $tmpval = preg_replace(
'/\-month$/',
'', $val);
721 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m'), ";
722 } elseif (preg_match(
'/\-day$/', $val)) {
723 $tmpval = preg_replace(
'/\-day$/',
'', $val);
724 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m-%d'), ";
729 foreach ($search_groupby as $key => $val) {
730 if (preg_match(
'/\-year$/', $val)) {
731 $tmpval = preg_replace(
'/\-year$/',
'', $val);
732 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y'), ";
733 } elseif (preg_match(
'/\-month$/', $val)) {
734 $tmpval = preg_replace(
'/\-month$/',
'', $val);
735 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m'), ";
736 } elseif (preg_match(
'/\-day$/', $val)) {
737 $tmpval = preg_replace(
'/\-day$/',
'', $val);
738 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m-%d'), ";
743 $sql = preg_replace(
'/,\s*$/',
'', $sql);
748 foreach ($search_measures as $key => $val) {
749 $legend[] = $langs->trans($arrayofmesures[$val][
'label']);
752 $useagroupby = (is_array($search_groupby) && count($search_groupby));
757 $totalnbofrecord = 0;
760 $resql = $db->query($sql);
768 while ($obj = $db->fetch_object(
$resql)) {
771 $xval = $search_xaxis[0];
772 $fieldforxkey =
'x_0';
773 $xlabel = $obj->$fieldforxkey;
774 $xvalwithoutprefix = preg_replace(
'/^[a-z]+\./',
'', $xval);
777 if (!empty($object->fields[$xvalwithoutprefix][
'arrayofkeyval'])) {
778 $xlabel = $object->fields[$xvalwithoutprefix][
'arrayofkeyval'][$obj->$fieldforxkey];
780 $labeltouse = (($xlabel || $xlabel ==
'0') ?
dol_trunc($xlabel, 20,
'middle') : ($xlabel ===
'' ? $langs->transnoentitiesnoconv(
"Empty") : $langs->transnoentitiesnoconv(
"NotDefined")));
782 if ($oldlabeltouse && ($labeltouse != $oldlabeltouse)) {
786 $oldlabeltouse = $labeltouse;
799 foreach ($search_measures as $key => $val) {
801 foreach ($search_groupby as $gkey) {
804 foreach ($arrayofvaluesforgroupby[
'g_'.$gi] as $gvaluepossiblekey => $gvaluepossiblelabel) {
805 $ykeysuffix = $gvaluepossiblelabel;
806 $gvalwithoutprefix = preg_replace(
'/^[a-z]+\./',
'', $gval);
808 $fieldfory =
'y_'.$key;
809 $fieldforg =
'g_'.$gi;
810 $fieldforybis =
'y_'.$key.
'_'.$ykeysuffix;
814 if (!is_array($data[$xi])) {
815 $data[$xi] = array();
818 if (!array_key_exists(
'label', $data[$xi])) {
819 $data[$xi] = array();
820 $data[$xi][
'label'] = $labeltouse;
823 $objfieldforg = $obj->$fieldforg;
824 if (is_null($objfieldforg)) {
825 $objfieldforg =
'__NULL__';
828 if ($gvaluepossiblekey ==
'0') {
830 if ($objfieldforg ==
'0') {
832 $data[$xi][$fieldforybis] = $obj->$fieldfory;
833 } elseif (!isset($data[$xi][$fieldforybis])) {
835 $data[$xi][$fieldforybis] =
'0';
839 if ((
string) $objfieldforg === (
string) $gvaluepossiblekey) {
841 $data[$xi][$fieldforybis] = $obj->$fieldfory;
842 } elseif (!isset($data[$xi][$fieldforybis])) {
844 $data[$xi][$fieldforybis] =
'0';
853 $xval = $search_xaxis[0];
854 $fieldforxkey =
'x_0';
855 $xlabel = $obj->$fieldforxkey;
856 $xvalwithoutprefix = preg_replace(
'/^[a-z]+\./',
'', $xval);
859 if (!empty($object->fields[$xvalwithoutprefix][
'arrayofkeyval'])) {
860 $xlabel = $object->fields[$xvalwithoutprefix][
'arrayofkeyval'][$obj->$fieldforxkey];
863 $labeltouse = (($xlabel || $xlabel ==
'0') ?
dol_trunc($xlabel, 20,
'middle') : ($xlabel ===
'' ? $langs->trans(
"Empty") : $langs->trans(
"NotDefined")));
864 $xarrayforallseries = array(
'label' => $labeltouse);
865 foreach ($search_measures as $key => $val) {
866 $fieldfory =
'y_'.$key;
867 $xarrayforallseries[$fieldfory] = $obj->$fieldfory;
869 $data[$xi] = $xarrayforallseries;
874 $totalnbofrecord = count($data);
879 print
'<div class="customreportsoutput'.($totalnbofrecord ?
'' :
' customreportsoutputnotdata').
'">';
882 if ($mode ==
'grid') {
886 if ($mode ==
'graph') {
892 $mesg = $px1->isGraphKo();
896 $px1->SetData($data);
899 $arrayoftypes = array();
900 foreach ($search_measures as $key => $val) {
901 $arrayoftypes[] = $search_graph;
904 $px1->SetLegend($legend);
905 $px1->SetMinValue($px1->GetFloorMinValue());
906 $px1->SetMaxValue($px1->GetCeilMaxValue());
907 $px1->SetWidth($WIDTH);
908 $px1->SetHeight($HEIGHT);
909 $px1->SetYLabel($langs->trans(
"Y"));
911 $px1->SetHorizTickIncrement(1);
912 $px1->SetCssPrefix(
"cssboxes");
913 $px1->SetType($arrayoftypes);
914 $px1->mode =
'depth';
917 $dir = $conf->user->dir_temp;
919 $filenamenb = $dir.
'/customreport_'.$object->element.
'.png';
920 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=user&file=customreport_'.$object->element.
'.png';
922 $px1->draw($filenamenb, $fileurlnb);
924 $texttoshow = $langs->trans(
"NoRecordFound");
926 $texttoshow = $langs->trans(
"SelectYourGraphOptionsFirst");
929 print $px1->show($totalnbofrecord ? 0 : $texttoshow);
935 print
'<br>'.info_admin($langs->trans(
"SQLUsedForExport").
':<br> '.$sql, 0, 0, 1,
'',
'TechnicalInformation');
940 if (!defined(
'USE_CUSTOM_REPORT_AS_INCLUDE')) {
964 function fillArrayOfMeasures($object, $tablealias, $labelofobject, &$arrayofmesures, $level = 0, &$count = 0)
966 global $langs, $extrafields, $db;
969 return $arrayofmesures;
974 $arrayofmesures[$tablealias.
'.count'] = array(
975 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': Count',
977 'table' => $object->table_element
982 foreach ($object->fields as $key => $val) {
983 if (!empty($val[
'isameasure']) && (!isset($val[
'enabled']) ||
dol_eval($val[
'enabled'], 1, 1,
'1'))) {
984 $position = (empty($val[
'position']) ? 0 : intVal($val[
'position']));
985 $arrayofmesures[$tablealias.
'.'.$key.
'-sum'] = array(
986 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']).
' <span class="opacitymedium">('.$langs->trans(
"Sum").
')</span>',
987 'position' => ($position + ($count * 100000)).
'.1',
988 'table' => $object->table_element
990 $arrayofmesures[$tablealias.
'.'.$key.
'-average'] = array(
991 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']).
' <span class="opacitymedium">('.$langs->trans(
"Average").
')</span>',
992 'position' => ($position + ($count * 100000)).
'.2',
993 'table' => $object->table_element
995 $arrayofmesures[$tablealias.
'.'.$key.
'-min'] = array(
996 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']).
' <span class="opacitymedium">('.$langs->trans(
"Minimum").
')</span>',
997 'position' => ($position + ($count * 100000)).
'.3',
998 'table' => $object->table_element
1000 $arrayofmesures[$tablealias.
'.'.$key.
'-max'] = array(
1001 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']).
' <span class="opacitymedium">('.$langs->trans(
"Maximum").
')</span>',
1002 'position' => ($position + ($count * 100000)).
'.4',
1003 'table' => $object->table_element
1008 if (!empty($object->isextrafieldmanaged)) {
1009 foreach ($extrafields->attributes[$object->table_element][
'label'] as $key => $val) {
1010 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'))) {
1011 $position = (!empty($val[
'position']) ? $val[
'position'] : 0);
1012 $arrayofmesures[$tablealias.
'e.'.$key.
'-sum'] = array(
1013 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($extrafields->attributes[$object->table_element][
'label'][$key]).
' <span class="opacitymedium">('.$langs->trans(
"Sum").
')</span>',
1014 'position' => ($position+($count * 100000)).
'.1',
1015 'table' => $object->table_element
1017 $arrayofmesures[$tablealias.
'e.'.$key.
'-average'] = array(
1018 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($extrafields->attributes[$object->table_element][
'label'][$key]).
' <span class="opacitymedium">('.$langs->trans(
"Average").
')</span>',
1019 'position' => ($position+($count * 100000)).
'.2',
1020 'table' => $object->table_element
1022 $arrayofmesures[$tablealias.
'e.'.$key.
'-min'] = array(
1023 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($extrafields->attributes[$object->table_element][
'label'][$key]).
' <span class="opacitymedium">('.$langs->trans(
"Minimum").
')</span>',
1024 'position' => ($position+($count * 100000)).
'.3',
1025 'table' => $object->table_element
1027 $arrayofmesures[$tablealias.
'e.'.$key.
'-max'] = array(
1028 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($extrafields->attributes[$object->table_element][
'label'][$key]).
' <span class="opacitymedium">('.$langs->trans(
"Maximum").
')</span>',
1029 'position' => ($position+($count * 100000)).
'.4',
1030 'table' => $object->table_element
1036 foreach ($object->fields as $key => $val) {
1037 if (preg_match(
'/^[^:]+:[^:]+:/', $val[
'type'])) {
1038 $tmptype = explode(
':', $val[
'type'], 4);
1039 if ($tmptype[0] ==
'integer' && $tmptype[1] && $tmptype[2]) {
1040 $newobject = $tmptype[1];
1042 if (class_exists($newobject)) {
1043 $tmpobject =
new $newobject($db);
1046 $arrayofmesures =
fillArrayOfMeasures($tmpobject, $tablealias.
'__'.$key, $langs->trans($val[
'label']), $arrayofmesures, $level + 1, $count);
1048 print
'For property '.$object->element.
'->'.$key.
', type="'.$val[
'type'].
'": Failed to find class '.$newobject.
" in file ".$tmptype[2].
"<br>\n";
1054 return $arrayofmesures;
1069 function fillArrayOfXAxis($object, $tablealias, $labelofobject, &$arrayofxaxis, $level = 0, &$count = 0)
1071 global $langs, $extrafields, $db;
1074 return $arrayofxaxis;
1078 return $arrayofxaxis;
1081 $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);
1082 $MM = substr($langs->trans(
"Month"), 0, 1).substr($langs->trans(
"Month"), 0, 1);
1083 $DD = substr($langs->trans(
"Day"), 0, 1).substr($langs->trans(
"Day"), 0, 1);
1084 $HH = substr($langs->trans(
"Hour"), 0, 1).substr($langs->trans(
"Hour"), 0, 1);
1085 $MI = substr($langs->trans(
"Minute"), 0, 1).substr($langs->trans(
"Minute"), 0, 1);
1086 $SS = substr($langs->trans(
"Second"), 0, 1).substr($langs->trans(
"Second"), 0, 1);
1089 foreach ($object->fields as $key => $val) {
1090 if (empty($val[
'measure'])) {
1091 if (in_array($key, array(
1092 'id',
'ref_ext',
'rowid',
'entity',
'last_main_doc',
'logo',
'logo_squarred',
'extraparams',
1093 'parent',
'photo',
'socialnetworks',
'webservices_url',
'webservices_key'))) {
1096 if (isset($val[
'enabled']) && !
dol_eval($val[
'enabled'], 1, 1,
'1')) {
1099 if (isset($val[
'visible']) && !
dol_eval($val[
'visible'], 1, 1,
'1')) {
1102 if (preg_match(
'/^fk_/', $key) && !preg_match(
'/^fk_statu/', $key)) {
1105 if (preg_match(
'/^pass/', $key)) {
1108 if (in_array($val[
'type'], array(
'html',
'text'))) {
1111 if (in_array($val[
'type'], array(
'timestamp',
'date',
'datetime'))) {
1112 $position = (empty($val[
'position']) ? 0 : intVal($val[
'position']));
1113 $arrayofxaxis[$tablealias.
'.'.$key.
'-year'] = array(
1114 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']).
' <span class="opacitymedium">('.$YYYY.
')</span>',
1115 'position' => ($position + ($count * 100000)).
'.1',
1116 'table' => $object->table_element
1118 $arrayofxaxis[$tablealias.
'.'.$key.
'-month'] = array(
1119 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']).
' <span class="opacitymedium">('.$YYYY.
'-'.$MM.
')</span>',
1120 'position' => ($position + ($count * 100000)).
'.2',
1121 'table' => $object->table_element
1123 $arrayofxaxis[$tablealias.
'.'.$key.
'-day'] = array(
1124 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']).
' <span class="opacitymedium">('.$YYYY.
'-'.$MM.
'-'.$DD.
')</span>',
1125 'position' => ($position + ($count * 100000)).
'.3',
1126 'table' => $object->table_element
1129 $position = (empty($val[
'position']) ? 0 : intVal($val[
'position']));
1130 $arrayofxaxis[$tablealias.
'.'.$key] = array(
1131 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']),
1132 'position' => ($position + ($count * 100000)),
1133 'table' => $object->table_element
1140 if (!empty($object->isextrafieldmanaged)) {
1141 foreach ($extrafields->attributes[$object->table_element][
'label'] as $key => $val) {
1142 if ($extrafields->attributes[$object->table_element][
'type'][$key] ==
'separate') {
1145 if (!empty($extrafields->attributes[$object->table_element][
'totalizable'][$key])) {
1148 $arrayofxaxis[$tablealias.
'e.'.$key] = array(
1149 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($extrafields->attributes[$object->table_element][
'label'][$key]),
1150 'position' => 1000 + (
int) $extrafields->attributes[$object->table_element][
'pos'][$key] + ($count * 100000),
1151 'table' => $object->table_element
1157 foreach ($object->fields as $key => $val) {
1158 if (preg_match(
'/^[^:]+:[^:]+:/', $val[
'type'])) {
1159 $tmptype = explode(
':', $val[
'type'], 4);
1160 if ($tmptype[0] ==
'integer' && $tmptype[1] && $tmptype[2]) {
1161 $newobject = $tmptype[1];
1163 if (class_exists($newobject)) {
1164 $tmpobject =
new $newobject($db);
1167 $arrayofxaxis =
fillArrayOfXAxis($tmpobject, $tablealias.
'__'.$key, $langs->trans($val[
'label']), $arrayofxaxis, $level + 1, $count);
1169 print
'For property '.$object->element.
'->'.$key.
', type="'.$val[
'type'].
'": Failed to find class '.$newobject.
" in file ".$tmptype[2].
"<br>\n";
1175 return $arrayofxaxis;
1190 function fillArrayOfGroupBy($object, $tablealias, $labelofobject, &$arrayofgroupby, $level = 0, &$count = 0)
1192 global $langs, $extrafields, $db;
1195 return $arrayofgroupby;
1199 return $arrayofgroupby;
1202 $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);
1203 $MM = substr($langs->trans(
"Month"), 0, 1).substr($langs->trans(
"Month"), 0, 1);
1204 $DD = substr($langs->trans(
"Day"), 0, 1).substr($langs->trans(
"Day"), 0, 1);
1205 $HH = substr($langs->trans(
"Hour"), 0, 1).substr($langs->trans(
"Hour"), 0, 1);
1206 $MI = substr($langs->trans(
"Minute"), 0, 1).substr($langs->trans(
"Minute"), 0, 1);
1207 $SS = substr($langs->trans(
"Second"), 0, 1).substr($langs->trans(
"Second"), 0, 1);
1210 foreach ($object->fields as $key => $val) {
1211 if (empty($val[
'isameasure'])) {
1212 if (in_array($key, array(
1213 'id',
'ref_ext',
'rowid',
'entity',
'last_main_doc',
'logo',
'logo_squarred',
'extraparams',
1214 'parent',
'photo',
'socialnetworks',
'webservices_url',
'webservices_key'))) {
1217 if (isset($val[
'enabled']) && !
dol_eval($val[
'enabled'], 1, 1,
'1')) {
1220 if (isset($val[
'visible']) && !
dol_eval($val[
'visible'], 1, 1,
'1')) {
1223 if (preg_match(
'/^fk_/', $key) && !preg_match(
'/^fk_statu/', $key)) {
1226 if (preg_match(
'/^pass/', $key)) {
1229 if (in_array($val[
'type'], array(
'html',
'text'))) {
1232 if (in_array($val[
'type'], array(
'timestamp',
'date',
'datetime'))) {
1233 $position = (empty($val[
'position']) ? 0 : intVal($val[
'position']));
1234 $arrayofgroupby[$tablealias.
'.'.$key.
'-year'] = array(
1235 'label' =>
img_picto(
'', $object->picto,
1236 'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']).
' <span class="opacitymedium">('.$YYYY.
')</span>',
'position' => ($position + ($count * 100000)).
'.1',
1237 'table' => $object->table_element
1239 $arrayofgroupby[$tablealias.
'.'.$key.
'-month'] = array(
1240 'label' =>
img_picto(
'', $object->picto,
1241 'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']).
' <span class="opacitymedium">('.$YYYY.
'-'.$MM.
')</span>',
'position' => ($position + ($count * 100000)).
'.2',
1242 'table' => $object->table_element
1244 $arrayofgroupby[$tablealias.
'.'.$key.
'-day'] = array(
1245 'label' =>
img_picto(
'', $object->picto,
1246 'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']).
' <span class="opacitymedium">('.$YYYY.
'-'.$MM.
'-'.$DD.
')</span>',
'position' => ($position + ($count * 100000)).
'.3',
1247 'table' => $object->table_element
1250 $position = (empty($val[
'position']) ? 0 : intVal($val[
'position']));
1251 $arrayofgroupby[$tablealias.
'.'.$key] = array(
1252 'label' =>
img_picto(
'', $object->picto,
1253 'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']),
'position' => ($position + ($count * 100000)),
1254 'table' => $object->table_element
1261 if (!empty($object->isextrafieldmanaged)) {
1262 foreach ($extrafields->attributes[$object->table_element][
'label'] as $key => $val) {
1263 if ($extrafields->attributes[$object->table_element][
'type'][$key] ==
'separate') {
1266 if (!empty($extrafields->attributes[$object->table_element][
'totalizable'][$key])) {
1269 $arrayofgroupby[$tablealias.
'e.'.$key] = array(
1270 'label' =>
img_picto(
'', $object->picto,
1271 'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($extrafields->attributes[$object->table_element][
'label'][$key]),
'position' => 1000 + (
int) $extrafields->attributes[$object->table_element][
'pos'][$key] + ($count * 100000),
1272 'table' => $object->table_element
1278 foreach ($object->fields as $key => $val) {
1279 if (preg_match(
'/^[^:]+:[^:]+:/', $val[
'type'])) {
1280 $tmptype = explode(
':', $val[
'type'], 4);
1281 if ($tmptype[0] ==
'integer' && $tmptype[1] && $tmptype[2]) {
1282 $newobject = $tmptype[1];
1284 if (class_exists($newobject)) {
1285 $tmpobject =
new $newobject($db);
1288 $arrayofgroupby =
fillArrayOfGroupBy($tmpobject, $tablealias.
'__'.$key, $langs->trans($val[
'label']), $arrayofgroupby, $level + 1, $count);
1290 print
'For property '.$object->element.
'->'.$key.
', type="'.$val[
'type'].
'": Failed to find class '.$newobject.
" in file ".$tmptype[2].
"<br>\n";
1296 return $arrayofgroupby;
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
fillArrayOfGroupBy($object, $tablealias, $labelofobject, &$arrayofgroupby, $level=0, &$count=0)
Fill arrayofgrupby for an object.
fillArrayOfMeasures($object, $tablealias, $labelofobject, &$arrayofmesures, $level=0, &$count=0)
Fill arrayofmesures for an object.
fillArrayOfXAxis($object, $tablealias, $labelofobject, &$arrayofxaxis, $level=0, &$count=0)
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_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
forgeSQLFromUniversalSearchCriteria($filter, &$error='')
forgeSQLFromUniversalSearchCriteria
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
dol_eval($s, $returnvalue=0, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
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.
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)
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.