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];
371 $labeloffield = $langs->transnoentitiesnoconv($keyforlabeloffield);
372 } elseif (strpos($fieldtocount,
't__') === 0) {
374 if (preg_match(
'/^(.*)\.(.*)/', $gvalwithoutprefix, $reg)) {
375 $gvalwithoutprefix = preg_replace(
'/\..*$/',
'', $gvalwithoutprefix);
376 $gvalwithoutprefix = preg_replace(
'/t__/',
'', $gvalwithoutprefix);
377 $keyforlabeloffield = $object->fields[$gvalwithoutprefix][
'label'];
378 $labeloffield = $langs->transnoentitiesnoconv($keyforlabeloffield).
'-'.$reg[2];
380 $labeloffield = $langs->transnoentitiesnoconv($keyforlabeloffield);
384 if (preg_match(
'/^(.*)\-(year|month|day)/', $gvalwithoutprefix, $reg)) {
385 $gvalwithoutprefix = preg_replace(
'/\-(year|month|day)/',
'', $gvalwithoutprefix);
386 $keyforlabeloffield = $object->fields[$gvalwithoutprefix][
'label'];
387 $labeloffield = $langs->transnoentitiesnoconv($keyforlabeloffield).
'-'.$reg[2];
389 $keyforlabeloffield = $object->fields[$gvalwithoutprefix][
'label'];
390 $labeloffield = $langs->transnoentitiesnoconv($keyforlabeloffield);
395 setEventMessages($langs->trans(
"ErrorTooManyDifferentValueForSelectedGroupBy", $MAXUNIQUEVALFORGROUP, $labeloffield),
null,
'warnings');
396 $search_groupby = array();
406 $endyear = $tmparray[
'year'];
407 $endmonth = $tmparray[
'mon'];
409 $startyear = $endyear - 2;
413 print
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'">';
414 print
'<input type="hidden" name="token" value="'.newToken().
'">';
415 print
'<input type="hidden" name="action" value="viewgraph">';
416 print
'<input type="hidden" name="tabfamily" value="'.$tabfamily.
'">';
420 $viewmode .=
'<div class="divadvancedsearchfield">';
421 $arrayofgraphs = array(
'bars' =>
'Bars',
'lines' =>
'Lines');
422 $viewmode .=
'<div class="inline-block opacitymedium"><span class="fas fa-chart-area paddingright" title="'.$langs->trans(
"Graph").
'"></span>'.$langs->trans(
"Graph").
'</div> ';
423 $viewmode .=
$form->selectarray(
'search_graph', $arrayofgraphs, $search_graph, 0, 0, 0,
'minwidth100', 1);
424 $viewmode .=
'</div>';
427 $massactionbutton =
'';
432 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);
436 print
'<div class="liste_titre liste_titre_bydiv centpercent">';
439 print
'<div class="divadvancedsearchfield center floatnone">';
440 print
'<div class="inline-block"><span class="opacitymedium">'.$langs->trans(
"StatisticsOn").
'</span></div> ';
441 print
$form->selectarray(
'objecttype', $newarrayoftype, $objecttype, 0, 0, 0,
'', 1, 0, 0,
'',
'minwidth200', 1);
442 if (empty($conf->use_javascript_ajax)) {
443 print
'<input type="submit" class="button buttongen button-save nomargintop" name="changeobjecttype" value="'.$langs->trans(
"Refresh").
'">';
445 print
'<!-- js code to reload page with good object type -->
446 <script type="text/javascript">
447 jQuery(document).ready(function() {
448 jQuery("#objecttype").change(function() {
449 console.log("Reload for "+jQuery("#objecttype").val());
450 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')) :
'').
'";
455 print
'</div><div class="clearboth"></div>';
458 print
'<div class="divadvancedsearchfield quatrevingtpercent">';
459 print
$form->searchComponent(array($object->element => $object->fields), $search_component_params, array(), $search_component_params_hidden);
465 print
'<div class="divadvancedsearchfield clearboth">';
466 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>';
467 $simplearrayofmesures = array();
468 foreach ($arrayofmesures as $key => $val) {
469 $simplearrayofmesures[$key] = $arrayofmesures[$key][
'label'];
471 print
$form->multiselectarray(
'search_measures', $simplearrayofmesures, $search_measures, 0, 0,
'minwidth300', 1, 0,
'',
'', $langs->trans(
"Measures"));
476 print
'<div class="divadvancedsearchfield">';
477 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>';
479 print $formother->selectXAxisField($object, $search_xaxis, $arrayofxaxis, $langs->trans(
"XAxis"),
'minwidth300 maxwidth400');
484 print
'<div class="divadvancedsearchfield">';
485 print
'<div class="inline-block opacitymedium"><span class="fas fa-ruler-horizontal paddingright pictofixedwidth" title="'.dol_escape_htmltag($langs->trans(
"GroupBy")).
'"></span></div>';
486 print $formother->selectGroupByField($object, $search_groupby, $arrayofgroupby,
'minwidth250 maxwidth300', $langs->trans(
"GroupBy"));
490 if ($mode ==
'grid') {
492 print
'<div class="divadvancedsearchfield">';
493 foreach ($object->fields as $key => $val) {
494 if (empty($val[
'measure']) && (!isset($val[
'enabled']) ||
dol_eval($val[
'enabled'], 1, 1,
'1'))) {
495 if (in_array($key, array(
'id',
'rowid',
'entity',
'last_main_doc',
'extraparams'))) {
498 if (preg_match(
'/^fk_/', $key)) {
501 if (in_array($val[
'type'], array(
'html',
'text'))) {
504 if (in_array($val[
'type'], array(
'timestamp',
'date',
'datetime'))) {
505 $arrayofyaxis[
't.'.$key.
'-year'] = array(
506 'label' => $langs->trans($val[
'label']).
' ('.$YYYY.
')',
507 'position' => $val[
'position'],
508 'table' => $object->table_element
510 $arrayofyaxis[
't.'.$key.
'-month'] = array(
511 'label' => $langs->trans($val[
'label']).
' ('.$YYYY.
'-'.$MM.
')',
512 'position' => $val[
'position'],
513 'table' => $object->table_element
515 $arrayofyaxis[
't.'.$key.
'-day'] = array(
516 'label' => $langs->trans($val[
'label']).
' ('.$YYYY.
'-'.$MM.
'-'.$DD.
')',
517 'position' => $val[
'position'],
518 'table' => $object->table_element
521 $arrayofyaxis[
't.'.$key] = array(
522 'label' => $val[
'label'],
523 'position' => (
int) $val[
'position'],
524 'table' => $object->table_element
530 if ($object->isextrafieldmanaged) {
531 foreach ($extrafields->attributes[$object->table_element][
'label'] as $key => $val) {
532 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'))) {
533 $arrayofyaxis[
'te.'.$key] = array(
534 'label' => $extrafields->attributes[$object->table_element][
'label'][$key],
535 'position' => (
int) $extrafields->attributes[$object->table_element][
'pos'][$key],
536 'table' => $object->table_element
542 $arrayofyaxislabel = array();
543 foreach ($arrayofyaxis as $key => $val) {
544 $arrayofyaxislabel[$key] = $val[
'label'];
546 print
'<div class="inline-block opacitymedium"><span class="fas fa-ruler-vertical paddingright" title="'.$langs->trans(
"YAxis").
'"></span>'.$langs->trans(
"YAxis").
'</div> ';
547 print
$form->multiselectarray(
'search_yaxis', $arrayofyaxislabel, $search_yaxis, 0, 0,
'minwidth100', 1);
551 if ($mode ==
'graph') {
555 print
'<div class="divadvancedsearchfield">';
556 print
'<input type="submit" class="button buttongen button-save nomargintop" value="'.$langs->trans(
"Refresh").
'">';
563 if (!empty($search_measures) && !empty($search_xaxis)) {
567 foreach ($search_xaxis as $key => $val) {
568 if (preg_match(
'/\-year$/', $val)) {
569 $tmpval = preg_replace(
'/\-year$/',
'', $val);
570 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y') as x_".$key.
', ';
571 } elseif (preg_match(
'/\-month$/', $val)) {
572 $tmpval = preg_replace(
'/\-month$/',
'', $val);
573 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m') as x_".$key.
', ';
574 } elseif (preg_match(
'/\-day$/', $val)) {
575 $tmpval = preg_replace(
'/\-day$/',
'', $val);
576 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m-%d') as x_".$key.
', ';
578 $sql .= $val.
" as x_".$key.
", ";
581 foreach ($search_groupby as $key => $val) {
582 if (preg_match(
'/\-year$/', $val)) {
583 $tmpval = preg_replace(
'/\-year$/',
'', $val);
584 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y') as g_".$key.
', ';
585 } elseif (preg_match(
'/\-month$/', $val)) {
586 $tmpval = preg_replace(
'/\-month$/',
'', $val);
587 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m') as g_".$key.
', ';
588 } elseif (preg_match(
'/\-day$/', $val)) {
589 $tmpval = preg_replace(
'/\-day$/',
'', $val);
590 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m-%d') as g_".$key.
', ';
592 $sql .= $val.
" as g_".$key.
", ";
595 foreach ($search_measures as $key => $val) {
596 if ($val ==
't.count') {
597 $sql .=
"COUNT(t.".$fieldid.
") as y_".$key.
', ';
598 } elseif (preg_match(
'/\-sum$/', $val)) {
599 $tmpval = preg_replace(
'/\-sum$/',
'', $val);
600 $sql .=
"SUM(".$db->ifsql($tmpval.
' IS NULL',
'0', $tmpval).
") as y_".$key.
", ";
601 } elseif (preg_match(
'/\-average$/', $val)) {
602 $tmpval = preg_replace(
'/\-average$/',
'', $val);
603 $sql .=
"AVG(".$db->ifsql($tmpval.
' IS NULL',
'0', $tmpval).
") as y_".$key.
", ";
604 } elseif (preg_match(
'/\-min$/', $val)) {
605 $tmpval = preg_replace(
'/\-min$/',
'', $val);
606 $sql .=
"MIN(".$db->ifsql($tmpval.
' IS NULL',
'0', $tmpval).
") as y_".$key.
", ";
607 } elseif (preg_match(
'/\-max$/', $val)) {
608 $tmpval = preg_replace(
'/\-max$/',
'', $val);
609 $sql .=
"MAX(".$db->ifsql($tmpval.
' IS NULL',
'0', $tmpval).
") as y_".$key.
", ";
612 $sql = preg_replace(
'/,\s*$/',
'', $sql);
613 $sql .=
" FROM ".MAIN_DB_PREFIX.$object->table_element.
" as t";
615 if ($object->isextrafieldmanaged) {
616 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element.
"_extrafields as te ON te.fk_object = t.".$fieldid;
619 if ($object->ismultientitymanaged) {
620 if ($object->ismultientitymanaged == 1) {
623 $tmparray = explode(
'@', $object->ismultientitymanaged);
624 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.$tmparray[1].
" as parenttableforentity ON t.".$tmparray[0].
" = parenttableforentity.rowid";
625 $sql .=
" AND parenttableforentity.entity IN (".getEntity($tmparray[1]).
")";
629 $listoftablesalreadyadded = array($object->table_element => $object->table_element);
633 foreach ($search_xaxis as $key => $val) {
634 if (!empty($arrayofxaxis[$val])) {
635 $tmpval = explode(
'.', $val);
637 if (! in_array($arrayofxaxis[$val][
'table'], $listoftablesalreadyadded)) {
638 $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";
639 $listoftablesalreadyadded[$arrayofxaxis[$val][
'table']] = $arrayofxaxis[$val][
'table'];
642 dol_print_error($db,
'Found a key into search_xaxis not found into arrayofxaxis');
648 foreach ($search_groupby as $key => $val) {
649 if (!empty($arrayofgroupby[$val])) {
650 $tmpval = explode(
'.', $val);
652 if (! in_array($arrayofgroupby[$val][
'table'], $listoftablesalreadyadded)) {
653 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$arrayofgroupby[$val][
'table'].
" as ".$tmpval[0].
" ON t.".str_replace(
't__',
'', $tmpval[0]).
" = ".$tmpval[0].
".rowid";
654 $listoftablesalreadyadded[$arrayofgroupby[$val][
'table']] = $arrayofgroupby[$val][
'table'];
657 dol_print_error($db,
'Found a key into search_groupby not found into arrayofgroupby');
663 foreach ($search_measures as $key => $val) {
664 if (!empty($arrayofmesures[$val])) {
665 $tmpval = explode(
'.', $val);
667 if (! in_array($arrayofmesures[$val][
'table'], $listoftablesalreadyadded)) {
668 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$arrayofmesures[$val][
'table'].
" as ".$tmpval[0].
" ON t.".str_replace(
't__',
'', $tmpval[0]).
" = ".$tmpval[0].
".rowid";
669 $listoftablesalreadyadded[$arrayofmesures[$val][
'table']] = $arrayofmesures[$val][
'table'];
672 dol_print_error($db,
'Found a key into search_measures not found into arrayofmesures');
676 $sql .=
" WHERE 1 = 1";
677 if ($object->ismultientitymanaged == 1) {
678 $sql .=
" AND t.entity IN (".getEntity($object->element).
")";
681 $sqlfilters = $search_component_params_hidden;
685 $regexstring =
'\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
686 $sql .=
" AND (".preg_replace_callback(
'/'.$regexstring.
'/',
'dolForgeCriteriaCallback', $sqlfilters).
")";
691 $sql .=
" GROUP BY ";
692 foreach ($search_xaxis as $key => $val) {
693 if (preg_match(
'/\-year$/', $val)) {
694 $tmpval = preg_replace(
'/\-year$/',
'', $val);
695 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y'), ";
696 } elseif (preg_match(
'/\-month$/', $val)) {
697 $tmpval = preg_replace(
'/\-month$/',
'', $val);
698 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m'), ";
699 } elseif (preg_match(
'/\-day$/', $val)) {
700 $tmpval = preg_replace(
'/\-day$/',
'', $val);
701 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m-%d'), ";
706 foreach ($search_groupby as $key => $val) {
707 if (preg_match(
'/\-year$/', $val)) {
708 $tmpval = preg_replace(
'/\-year$/',
'', $val);
709 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y'), ";
710 } elseif (preg_match(
'/\-month$/', $val)) {
711 $tmpval = preg_replace(
'/\-month$/',
'', $val);
712 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m'), ";
713 } elseif (preg_match(
'/\-day$/', $val)) {
714 $tmpval = preg_replace(
'/\-day$/',
'', $val);
715 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m-%d'), ";
720 $sql = preg_replace(
'/,\s*$/',
'', $sql);
721 $sql .=
' ORDER BY ';
722 foreach ($search_xaxis as $key => $val) {
723 if (preg_match(
'/\-year$/', $val)) {
724 $tmpval = preg_replace(
'/\-year$/',
'', $val);
725 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y'), ";
726 } elseif (preg_match(
'/\-month$/', $val)) {
727 $tmpval = preg_replace(
'/\-month$/',
'', $val);
728 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m'), ";
729 } elseif (preg_match(
'/\-day$/', $val)) {
730 $tmpval = preg_replace(
'/\-day$/',
'', $val);
731 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m-%d'), ";
736 foreach ($search_groupby as $key => $val) {
737 if (preg_match(
'/\-year$/', $val)) {
738 $tmpval = preg_replace(
'/\-year$/',
'', $val);
739 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y'), ";
740 } elseif (preg_match(
'/\-month$/', $val)) {
741 $tmpval = preg_replace(
'/\-month$/',
'', $val);
742 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m'), ";
743 } elseif (preg_match(
'/\-day$/', $val)) {
744 $tmpval = preg_replace(
'/\-day$/',
'', $val);
745 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m-%d'), ";
750 $sql = preg_replace(
'/,\s*$/',
'', $sql);
755 foreach ($search_measures as $key => $val) {
756 $legend[] = $langs->trans($arrayofmesures[$val][
'label']);
759 $useagroupby = (is_array($search_groupby) && count($search_groupby));
764 $totalnbofrecord = 0;
767 $resql = $db->query($sql);
775 while ($obj = $db->fetch_object(
$resql)) {
778 $xval = $search_xaxis[0];
779 $fieldforxkey =
'x_0';
780 $xlabel = $obj->$fieldforxkey;
781 $xvalwithoutprefix = preg_replace(
'/^[a-z]+\./',
'', $xval);
784 if (!empty($object->fields[$xvalwithoutprefix][
'arrayofkeyval'])) {
785 $xlabel = $object->fields[$xvalwithoutprefix][
'arrayofkeyval'][$obj->$fieldforxkey];
787 $labeltouse = (($xlabel || $xlabel ==
'0') ?
dol_trunc($xlabel, 20,
'middle') : ($xlabel ===
'' ? $langs->transnoentitiesnoconv(
"Empty") : $langs->transnoentitiesnoconv(
"NotDefined")));
789 if ($oldlabeltouse && ($labeltouse != $oldlabeltouse)) {
793 $oldlabeltouse = $labeltouse;
806 foreach ($search_measures as $key => $val) {
808 foreach ($search_groupby as $gkey) {
811 foreach ($arrayofvaluesforgroupby[
'g_'.$gi] as $gvaluepossiblekey => $gvaluepossiblelabel) {
812 $ykeysuffix = $gvaluepossiblelabel;
813 $gvalwithoutprefix = preg_replace(
'/^[a-z]+\./',
'', $gval);
815 $fieldfory =
'y_'.$key;
816 $fieldforg =
'g_'.$gi;
817 $fieldforybis =
'y_'.$key.
'_'.$ykeysuffix;
821 if (!is_array($data[$xi])) {
822 $data[$xi] = array();
825 if (!array_key_exists(
'label', $data[$xi])) {
826 $data[$xi] = array();
827 $data[$xi][
'label'] = $labeltouse;
830 $objfieldforg = $obj->$fieldforg;
831 if (is_null($objfieldforg)) {
832 $objfieldforg =
'__NULL__';
835 if ($gvaluepossiblekey ==
'0') {
837 if ($objfieldforg ==
'0') {
839 $data[$xi][$fieldforybis] = $obj->$fieldfory;
840 } elseif (!isset($data[$xi][$fieldforybis])) {
842 $data[$xi][$fieldforybis] =
'0';
846 if ((
string) $objfieldforg === (
string) $gvaluepossiblekey) {
848 $data[$xi][$fieldforybis] = $obj->$fieldfory;
849 } elseif (!isset($data[$xi][$fieldforybis])) {
851 $data[$xi][$fieldforybis] =
'0';
860 $xval = $search_xaxis[0];
861 $fieldforxkey =
'x_0';
862 $xlabel = $obj->$fieldforxkey;
863 $xvalwithoutprefix = preg_replace(
'/^[a-z]+\./',
'', $xval);
866 if (!empty($object->fields[$xvalwithoutprefix][
'arrayofkeyval'])) {
867 $xlabel = $object->fields[$xvalwithoutprefix][
'arrayofkeyval'][$obj->$fieldforxkey];
870 $labeltouse = (($xlabel || $xlabel ==
'0') ?
dol_trunc($xlabel, 20,
'middle') : ($xlabel ===
'' ? $langs->trans(
"Empty") : $langs->trans(
"NotDefined")));
871 $xarrayforallseries = array(
'label' => $labeltouse);
872 foreach ($search_measures as $key => $val) {
873 $fieldfory =
'y_'.$key;
874 $xarrayforallseries[$fieldfory] = $obj->$fieldfory;
876 $data[$xi] = $xarrayforallseries;
881 $totalnbofrecord = count($data);
886 print
'<div class="customreportsoutput'.($totalnbofrecord ?
'' :
' customreportsoutputnotdata').
'">';
889 if ($mode ==
'grid') {
893 if ($mode ==
'graph') {
899 $mesg = $px1->isGraphKo();
903 $px1->SetData($data);
906 $arrayoftypes = array();
907 foreach ($search_measures as $key => $val) {
908 $arrayoftypes[] = $search_graph;
911 $px1->SetLegend($legend);
912 $px1->SetMinValue($px1->GetFloorMinValue());
913 $px1->SetMaxValue($px1->GetCeilMaxValue());
914 $px1->SetWidth($WIDTH);
915 $px1->SetHeight($HEIGHT);
916 $px1->SetYLabel($langs->trans(
"Y"));
918 $px1->SetHorizTickIncrement(1);
919 $px1->SetCssPrefix(
"cssboxes");
920 $px1->SetType($arrayoftypes);
921 $px1->mode =
'depth';
924 $dir = $conf->user->dir_temp;
926 $filenamenb = $dir.
'/customreport_'.$object->element.
'.png';
927 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=user&file=customreport_'.$object->element.
'.png';
929 $px1->draw($filenamenb, $fileurlnb);
931 $texttoshow = $langs->trans(
"NoRecordFound");
933 $texttoshow = $langs->trans(
"SelectYourGraphOptionsFirst");
936 print $px1->show($totalnbofrecord ? 0 : $texttoshow);
942 print
'<br>'.info_admin($langs->trans(
"SQLUsedForExport").
':<br> '.$sql, 0, 0, 1,
'',
'TechnicalInformation');
947 if (!defined(
'USE_CUSTOM_REPORT_AS_INCLUDE')) {
971 function fillArrayOfMeasures($object, $tablealias, $labelofobject, &$arrayofmesures, $level = 0, &$count = 0)
973 global $langs, $extrafields, $db;
976 return $arrayofmesures;
981 $arrayofmesures[$tablealias.
'.count'] = array(
982 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': Count',
984 'table' => $object->table_element
989 foreach ($object->fields as $key => $val) {
990 if (!empty($val[
'isameasure']) && (!isset($val[
'enabled']) ||
dol_eval($val[
'enabled'], 1, 1,
'1'))) {
991 $position = (empty($val[
'position']) ? 0 : intVal($val[
'position']));
992 $arrayofmesures[$tablealias.
'.'.$key.
'-sum'] = array(
993 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']).
' <span class="opacitymedium">('.$langs->trans(
"Sum").
')</span>',
994 'position' => ($position + ($count * 100000)).
'.1',
995 'table' => $object->table_element
997 $arrayofmesures[$tablealias.
'.'.$key.
'-average'] = array(
998 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']).
' <span class="opacitymedium">('.$langs->trans(
"Average").
')</span>',
999 'position' => ($position + ($count * 100000)).
'.2',
1000 'table' => $object->table_element
1002 $arrayofmesures[$tablealias.
'.'.$key.
'-min'] = array(
1003 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']).
' <span class="opacitymedium">('.$langs->trans(
"Minimum").
')</span>',
1004 'position' => ($position + ($count * 100000)).
'.3',
1005 'table' => $object->table_element
1007 $arrayofmesures[$tablealias.
'.'.$key.
'-max'] = array(
1008 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']).
' <span class="opacitymedium">('.$langs->trans(
"Maximum").
')</span>',
1009 'position' => ($position + ($count * 100000)).
'.4',
1010 'table' => $object->table_element
1015 if (!empty($object->isextrafieldmanaged)) {
1016 foreach ($extrafields->attributes[$object->table_element][
'label'] as $key => $val) {
1017 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'))) {
1018 $position = (!empty($val[
'position']) ? $val[
'position'] : 0);
1019 $arrayofmesures[$tablealias.
'e.'.$key.
'-sum'] = array(
1020 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($extrafields->attributes[$object->table_element][
'label'][$key]).
' <span class="opacitymedium">('.$langs->trans(
"Sum").
')</span>',
1021 'position' => ($position+($count * 100000)).
'.1',
1022 'table' => $object->table_element
1024 $arrayofmesures[$tablealias.
'e.'.$key.
'-average'] = array(
1025 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($extrafields->attributes[$object->table_element][
'label'][$key]).
' <span class="opacitymedium">('.$langs->trans(
"Average").
')</span>',
1026 'position' => ($position+($count * 100000)).
'.2',
1027 'table' => $object->table_element
1029 $arrayofmesures[$tablealias.
'e.'.$key.
'-min'] = array(
1030 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($extrafields->attributes[$object->table_element][
'label'][$key]).
' <span class="opacitymedium">('.$langs->trans(
"Minimum").
')</span>',
1031 'position' => ($position+($count * 100000)).
'.3',
1032 'table' => $object->table_element
1034 $arrayofmesures[$tablealias.
'e.'.$key.
'-max'] = array(
1035 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($extrafields->attributes[$object->table_element][
'label'][$key]).
' <span class="opacitymedium">('.$langs->trans(
"Maximum").
')</span>',
1036 'position' => ($position+($count * 100000)).
'.4',
1037 'table' => $object->table_element
1043 foreach ($object->fields as $key => $val) {
1044 if (preg_match(
'/^[^:]+:[^:]+:/', $val[
'type'])) {
1045 $tmptype = explode(
':', $val[
'type'], 4);
1046 if ($tmptype[0] ==
'integer' && $tmptype[1] && $tmptype[2]) {
1047 $newobject = $tmptype[1];
1049 if (class_exists($newobject)) {
1050 $tmpobject =
new $newobject($db);
1053 $arrayofmesures = fillArrayOfMeasures($tmpobject, $tablealias.
'__'.$key, $langs->trans($val[
'label']), $arrayofmesures, $level + 1, $count);
1055 print
'For property '.$object->element.
'->'.$key.
', type="'.$val[
'type'].
'": Failed to find class '.$newobject.
" in file ".$tmptype[2].
"<br>\n";
1061 return $arrayofmesures;
1076 function fillArrayOfXAxis($object, $tablealias, $labelofobject, &$arrayofxaxis, $level = 0, &$count = 0)
1078 global $langs, $extrafields, $db;
1081 return $arrayofxaxis;
1085 return $arrayofxaxis;
1088 $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);
1089 $MM = substr($langs->trans(
"Month"), 0, 1).substr($langs->trans(
"Month"), 0, 1);
1090 $DD = substr($langs->trans(
"Day"), 0, 1).substr($langs->trans(
"Day"), 0, 1);
1091 $HH = substr($langs->trans(
"Hour"), 0, 1).substr($langs->trans(
"Hour"), 0, 1);
1092 $MI = substr($langs->trans(
"Minute"), 0, 1).substr($langs->trans(
"Minute"), 0, 1);
1093 $SS = substr($langs->trans(
"Second"), 0, 1).substr($langs->trans(
"Second"), 0, 1);
1096 foreach ($object->fields as $key => $val) {
1097 if (empty($val[
'measure'])) {
1098 if (in_array($key, array(
1099 'id',
'ref_ext',
'rowid',
'entity',
'last_main_doc',
'logo',
'logo_squarred',
'extraparams',
1100 'parent',
'photo',
'socialnetworks',
'webservices_url',
'webservices_key'))) {
1103 if (isset($val[
'enabled']) && !
dol_eval($val[
'enabled'], 1, 1,
'1')) {
1106 if (isset($val[
'visible']) && !
dol_eval($val[
'visible'], 1, 1,
'1')) {
1109 if (preg_match(
'/^fk_/', $key) && !preg_match(
'/^fk_statu/', $key)) {
1112 if (preg_match(
'/^pass/', $key)) {
1115 if (in_array($val[
'type'], array(
'html',
'text'))) {
1118 if (in_array($val[
'type'], array(
'timestamp',
'date',
'datetime'))) {
1119 $position = (empty($val[
'position']) ? 0 : intVal($val[
'position']));
1120 $arrayofxaxis[$tablealias.
'.'.$key.
'-year'] = array(
1121 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']).
' <span class="opacitymedium">('.$YYYY.
')</span>',
1122 'position' => ($position + ($count * 100000)).
'.1',
1123 'table' => $object->table_element
1125 $arrayofxaxis[$tablealias.
'.'.$key.
'-month'] = array(
1126 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']).
' <span class="opacitymedium">('.$YYYY.
'-'.$MM.
')</span>',
1127 'position' => ($position + ($count * 100000)).
'.2',
1128 'table' => $object->table_element
1130 $arrayofxaxis[$tablealias.
'.'.$key.
'-day'] = array(
1131 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']).
' <span class="opacitymedium">('.$YYYY.
'-'.$MM.
'-'.$DD.
')</span>',
1132 'position' => ($position + ($count * 100000)).
'.3',
1133 'table' => $object->table_element
1136 $position = (empty($val[
'position']) ? 0 : intVal($val[
'position']));
1137 $arrayofxaxis[$tablealias.
'.'.$key] = array(
1138 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']),
1139 'position' => ($position + ($count * 100000)),
1140 'table' => $object->table_element
1147 if (!empty($object->isextrafieldmanaged)) {
1148 foreach ($extrafields->attributes[$object->table_element][
'label'] as $key => $val) {
1149 if ($extrafields->attributes[$object->table_element][
'type'][$key] ==
'separate') {
1152 if (!empty($extrafields->attributes[$object->table_element][
'totalizable'][$key])) {
1155 $arrayofxaxis[$tablealias.
'e.'.$key] = array(
1156 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($extrafields->attributes[$object->table_element][
'label'][$key]),
1157 'position' => 1000 + (
int) $extrafields->attributes[$object->table_element][
'pos'][$key] + ($count * 100000),
1158 'table' => $object->table_element
1164 foreach ($object->fields as $key => $val) {
1165 if (preg_match(
'/^[^:]+:[^:]+:/', $val[
'type'])) {
1166 $tmptype = explode(
':', $val[
'type'], 4);
1167 if ($tmptype[0] ==
'integer' && $tmptype[1] && $tmptype[2]) {
1168 $newobject = $tmptype[1];
1170 if (class_exists($newobject)) {
1171 $tmpobject =
new $newobject($db);
1174 $arrayofxaxis = fillArrayOfXAxis($tmpobject, $tablealias.
'__'.$key, $langs->trans($val[
'label']), $arrayofxaxis, $level + 1, $count);
1176 print
'For property '.$object->element.
'->'.$key.
', type="'.$val[
'type'].
'": Failed to find class '.$newobject.
" in file ".$tmptype[2].
"<br>\n";
1182 return $arrayofxaxis;
1197 function fillArrayOfGroupBy($object, $tablealias, $labelofobject, &$arrayofgroupby, $level = 0, &$count = 0)
1199 global $langs, $extrafields, $db;
1202 return $arrayofgroupby;
1206 return $arrayofgroupby;
1209 $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);
1210 $MM = substr($langs->trans(
"Month"), 0, 1).substr($langs->trans(
"Month"), 0, 1);
1211 $DD = substr($langs->trans(
"Day"), 0, 1).substr($langs->trans(
"Day"), 0, 1);
1212 $HH = substr($langs->trans(
"Hour"), 0, 1).substr($langs->trans(
"Hour"), 0, 1);
1213 $MI = substr($langs->trans(
"Minute"), 0, 1).substr($langs->trans(
"Minute"), 0, 1);
1214 $SS = substr($langs->trans(
"Second"), 0, 1).substr($langs->trans(
"Second"), 0, 1);
1217 foreach ($object->fields as $key => $val) {
1218 if (empty($val[
'isameasure'])) {
1219 if (in_array($key, array(
1220 'id',
'ref_ext',
'rowid',
'entity',
'last_main_doc',
'logo',
'logo_squarred',
'extraparams',
1221 'parent',
'photo',
'socialnetworks',
'webservices_url',
'webservices_key'))) {
1224 if (isset($val[
'enabled']) && !
dol_eval($val[
'enabled'], 1, 1,
'1')) {
1227 if (isset($val[
'visible']) && !
dol_eval($val[
'visible'], 1, 1,
'1')) {
1230 if (preg_match(
'/^fk_/', $key) && !preg_match(
'/^fk_statu/', $key)) {
1233 if (preg_match(
'/^pass/', $key)) {
1236 if (in_array($val[
'type'], array(
'html',
'text'))) {
1239 if (in_array($val[
'type'], array(
'timestamp',
'date',
'datetime'))) {
1240 $position = (empty($val[
'position']) ? 0 : intVal($val[
'position']));
1241 $arrayofgroupby[$tablealias.
'.'.$key.
'-year'] = array(
1242 'label' =>
img_picto(
'', $object->picto,
1243 'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']).
' <span class="opacitymedium">('.$YYYY.
')</span>',
'position' => ($position + ($count * 100000)).
'.1',
1244 'table' => $object->table_element
1246 $arrayofgroupby[$tablealias.
'.'.$key.
'-month'] = array(
1247 'label' =>
img_picto(
'', $object->picto,
1248 'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']).
' <span class="opacitymedium">('.$YYYY.
'-'.$MM.
')</span>',
'position' => ($position + ($count * 100000)).
'.2',
1249 'table' => $object->table_element
1251 $arrayofgroupby[$tablealias.
'.'.$key.
'-day'] = array(
1252 'label' =>
img_picto(
'', $object->picto,
1253 'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']).
' <span class="opacitymedium">('.$YYYY.
'-'.$MM.
'-'.$DD.
')</span>',
'position' => ($position + ($count * 100000)).
'.3',
1254 'table' => $object->table_element
1257 $position = (empty($val[
'position']) ? 0 : intVal($val[
'position']));
1258 $arrayofgroupby[$tablealias.
'.'.$key] = array(
1259 'label' =>
img_picto(
'', $object->picto,
1260 'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']),
'position' => ($position + ($count * 100000)),
1261 'table' => $object->table_element
1268 if (!empty($object->isextrafieldmanaged)) {
1269 foreach ($extrafields->attributes[$object->table_element][
'label'] as $key => $val) {
1270 if ($extrafields->attributes[$object->table_element][
'type'][$key] ==
'separate') {
1273 if (!empty($extrafields->attributes[$object->table_element][
'totalizable'][$key])) {
1276 $arrayofgroupby[$tablealias.
'e.'.$key] = array(
1277 'label' =>
img_picto(
'', $object->picto,
1278 'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($extrafields->attributes[$object->table_element][
'label'][$key]),
'position' => 1000 + (
int) $extrafields->attributes[$object->table_element][
'pos'][$key] + ($count * 100000),
1279 'table' => $object->table_element
1285 foreach ($object->fields as $key => $val) {
1286 if (preg_match(
'/^[^:]+:[^:]+:/', $val[
'type'])) {
1287 $tmptype = explode(
':', $val[
'type'], 4);
1288 if ($tmptype[0] ==
'integer' && $tmptype[1] && $tmptype[2]) {
1289 $newobject = $tmptype[1];
1291 if (class_exists($newobject)) {
1292 $tmpobject =
new $newobject($db);
1295 $arrayofgroupby = fillArrayOfGroupBy($tmpobject, $tablealias.
'__'.$key, $langs->trans($val[
'label']), $arrayofgroupby, $level + 1, $count);
1297 print
'For property '.$object->element.
'->'.$key.
', type="'.$val[
'type'].
'": Failed to find class '.$newobject.
" in file ".$tmptype[2].
"<br>\n";
1303 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.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
dolCheckFilters($sqlfilters, &$error='')
Return if a $sqlfilters parameter is valid and will pass the preg_replace_callback() to replace Gener...
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.
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.