28if (!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');
65 $page = GETPOSTISSET(
'pageplusone') ? (
GETPOST(
'pageplusone') - 1) :
GETPOST(
"page",
'int');
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';
76require_once DOL_DOCUMENT_ROOT.
"/core/lib/admin.lib.php";
77require_once DOL_DOCUMENT_ROOT.
"/core/lib/company.lib.php";
78require_once DOL_DOCUMENT_ROOT.
"/core/class/dolgraph.class.php";
79require_once DOL_DOCUMENT_ROOT.
"/core/class/doleditor.class.php";
80require_once DOL_DOCUMENT_ROOT.
"/core/class/html.formother.class.php";
83$langs->loadLangs(array(
"companies",
"other",
"exports",
"sendings"));
87$hookmanager->initHooks(array(
'customreport'));
96 'thirdparty' => array(
'langs'=>
'companies',
'label' =>
'ThirdParties',
'picto'=>
'company',
'ObjectClassName' =>
'Societe',
'enabled' => isModEnabled(
'societe'),
'ClassPath' =>
"/societe/class/societe.class.php"),
97 'contact' => array(
'label' =>
'Contacts',
'picto'=>
'contact',
'ObjectClassName' =>
'Contact',
'enabled' => isModEnabled(
'societe'),
'ClassPath' =>
"/contact/class/contact.class.php"),
98 'proposal' => array(
'label' =>
'Proposals',
'picto'=>
'proposal',
'ObjectClassName' =>
'Propal',
'enabled' => isModEnabled(
'propal'),
'ClassPath' =>
"/comm/propal/class/propal.class.php"),
99 'order' => array(
'label' =>
'Orders',
'picto'=>
'order',
'ObjectClassName' =>
'Commande',
'enabled' => isModEnabled(
'commande'),
'ClassPath' =>
"/commande/class/commande.class.php"),
100 'invoice' => array(
'langs'=>
'facture',
'label' =>
'Invoices',
'picto'=>
'bill',
'ObjectClassName' =>
'Facture',
'enabled' => isModEnabled(
'facture'),
'ClassPath' =>
"/compta/facture/class/facture.class.php"),
101 'invoice_template'=>array(
'label' =>
'PredefinedInvoices',
'picto'=>
'bill',
'ObjectClassName' =>
'FactureRec',
'enabled' => isModEnabled(
'facture'),
'ClassPath' =>
"/compta/class/facturerec.class.php",
'langs'=>
'bills'),
102 'contract' => array(
'label' =>
'Contracts',
'picto'=>
'contract',
'ObjectClassName' =>
'Contrat',
'enabled' => isModEnabled(
'contrat'),
'ClassPath' =>
"/contrat/class/contrat.class.php",
'langs'=>
'contracts'),
103 'contractdet' => array(
'label' =>
'ContractLines',
'picto'=>
'contract',
'ObjectClassName' =>
'ContratLigne',
'enabled' => isModEnabled(
'contrat'),
'ClassPath' =>
"/contrat/class/contrat.class.php",
'langs'=>
'contracts'),
104 'bom' => array(
'label' =>
'BOM',
'picto'=>
'bom',
'ObjectClassName' =>
'Bom',
'enabled' => isModEnabled(
'bom')),
105 'mo' => array(
'label' =>
'MO',
'picto'=>
'mrp',
'ObjectClassName' =>
'Mo',
'enabled' => isModEnabled(
'mrp'),
'ClassPath' =>
"/mrp/class/mo.class.php"),
106 'ticket' => array(
'label' =>
'Ticket',
'picto'=>
'ticket',
'ObjectClassName' =>
'Ticket',
'enabled' => isModEnabled(
'ticket')),
107 'member' => array(
'label' =>
'Adherent',
'picto'=>
'member',
'ObjectClassName' =>
'Adherent',
'enabled' => isModEnabled(
'adherent'),
'ClassPath' =>
"/adherents/class/adherent.class.php",
'langs'=>
'members'),
108 'cotisation' => array(
'label' =>
'Subscriptions',
'picto'=>
'member',
'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;
149if ($user->socid > 0) {
155$extrafields->fetch_name_optionals_label(
'all');
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');
164if (
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;
185if (!empty($object->element_for_permission)) {
186 $features = $object->element_for_permission;
206$form =
new Form($db);
209if (!defined(
'USE_CUSTOM_REPORT_AS_INCLUDE')) {
210 llxHeader(
'', $langs->transnoentitiesnoconv(
'CustomReports'),
'');
215$newarrayoftype = array();
216foreach ($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);
239if ($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';
261if (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 $tabletouse = $object->table_element;
282 $tablealiastouse =
'te';
283 if (!empty($arrayofgroupby[$gval])) {
284 $tmpval = explode(
'.', $gval);
285 $tabletouse = $arrayofgroupby[$gval][
'table'];
286 $tablealiastouse = $tmpval[0];
291 $sql .=
" FROM ".MAIN_DB_PREFIX.$tabletouse.
"_extrafields as ".$tablealiastouse;
293 $tabletouse = $object->table_element;
294 $tablealiastouse =
't';
295 if (!empty($arrayofgroupby[$gval])) {
296 $tmpval = explode(
'.', $gval);
297 $tabletouse = $arrayofgroupby[$gval][
'table'];
298 $tablealiastouse = $tmpval[0];
300 $sql .=
" FROM ".MAIN_DB_PREFIX.$tabletouse.
" as ".$tablealiastouse;
311 $sql .=
" LIMIT ".((int) ($MAXUNIQUEVALFORGROUP + 1));
314 $resql = $db->query($sql);
319 while ($obj = $db->fetch_object($resql)) {
320 if (is_null($obj->val)) {
321 $keytouse =
'__NULL__';
322 $valuetranslated = $langs->transnoentitiesnoconv(
"NotDefined");
323 } elseif ($obj->val ===
'') {
325 $valuetranslated = $langs->transnoentitiesnoconv(
"Empty");
327 $keytouse = (string) $obj->val;
328 $valuetranslated = $obj->val;
332 if (!empty($object->fields[$gvalwithoutprefix][
'arrayofkeyval'])) {
333 $valuetranslated = $object->fields[$gvalwithoutprefix][
'arrayofkeyval'][$obj->val];
334 if (is_null($valuetranslated)) {
335 $valuetranslated = $langs->transnoentitiesnoconv(
"UndefinedKey");
337 $valuetranslated = $langs->trans($valuetranslated);
338 } elseif (preg_match(
'/integer:([^:]+):([^:]+)$/', $object->fields[$gvalwithoutprefix][
'type'], $regs)) {
339 $classname = $regs[1];
340 $classpath = $regs[2];
342 if (class_exists($classname)) {
343 $tmpobject =
new $classname($db);
344 $tmpobject->fetch($obj->val);
345 foreach ($tmpobject->fields as $fieldkey => $field) {
346 if ($field[
'showoncombobox']) {
347 $valuetranslated = $tmpobject->$fieldkey;
356 $arrayofvaluesforgroupby[
'g_'.$gkey][$keytouse] = $valuetranslated;
359 $tmpfield = explode(
'.', $gval);
360 if ($tmpfield[0] !=
't' || (is_array($object->fields[$tmpfield[1]]) && empty($object->fields[$tmpfield[1]][
'notnull']))) {
361 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");
363 $arrayofvaluesforgroupby[
'g_'.$gkey][
'__NULL__'] = $langs->transnoentitiesnoconv(
"NotDefined");
366 asort($arrayofvaluesforgroupby[
'g_'.$gkey]);
369 if (count($arrayofvaluesforgroupby[
'g_'.$gkey]) > $MAXUNIQUEVALFORGROUP) {
370 $langs->load(
"errors");
372 if (strpos($fieldtocount,
'te') === 0) {
376 $keyforlabeloffield = $extrafields->attributes[$object->table_element][
'label'][$gvalwithoutprefix];
377 $labeloffield = $langs->transnoentitiesnoconv($keyforlabeloffield);
378 } elseif (strpos($fieldtocount,
't__') === 0) {
380 if (preg_match(
'/^(.*)\.(.*)/', $gvalwithoutprefix, $reg)) {
387 $labeloffield = $arrayofgroupby[$fieldtocount][
'labelnohtml'];
389 $labeloffield = $langs->transnoentitiesnoconv($keyforlabeloffield);
393 if (preg_match(
'/^(.*)\-(year|month|day)/', $gvalwithoutprefix, $reg)) {
394 $gvalwithoutprefix = preg_replace(
'/\-(year|month|day)/',
'', $gvalwithoutprefix);
395 $keyforlabeloffield = $object->fields[$gvalwithoutprefix][
'label'];
396 $labeloffield = $langs->transnoentitiesnoconv($keyforlabeloffield).
'-'.$reg[2];
398 $keyforlabeloffield = $object->fields[$gvalwithoutprefix][
'label'];
399 $labeloffield = $langs->transnoentitiesnoconv($keyforlabeloffield);
403 setEventMessages($langs->trans(
"ErrorTooManyDifferentValueForSelectedGroupBy", $MAXUNIQUEVALFORGROUP, $labeloffield),
null,
'warnings');
404 $search_groupby = array();
414$endyear = $tmparray[
'year'];
415$endmonth = $tmparray[
'mon'];
417$startyear = $endyear - 2;
421print
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'" autocomplete="off">';
422print
'<input type="hidden" name="token" value="'.newToken().
'">';
423print
'<input type="hidden" name="action" value="viewgraph">';
424print
'<input type="hidden" name="tabfamily" value="'.$tabfamily.
'">';
428$viewmode .=
'<div class="divadvancedsearchfield">';
429$arrayofgraphs = array(
'bars' =>
'Bars',
'lines' =>
'Lines');
430$viewmode .=
'<div class="inline-block opacitymedium"><span class="fas fa-chart-area paddingright" title="'.$langs->trans(
"Graph").
'"></span>'.$langs->trans(
"Graph").
'</div> ';
431$viewmode .= $form->selectarray(
'search_graph', $arrayofgraphs, $search_graph, 0, 0, 0,
'', 1, 0, 0,
'',
'graphtype width100');
432$viewmode .=
'</div>';
435$massactionbutton =
'';
440print_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);
443foreach ($newarrayoftype as $tmpkey => $tmpval) {
444 $newarrayoftype[$tmpkey][
'label'] =
img_picto(
'', $tmpval[
'picto'],
'class="pictofixedwidth"').$langs->trans($tmpval[
'label']);
447print
'<div class="liste_titre liste_titre_bydiv liste_titre_bydiv_inlineblock centpercent">';
450print
'<div class="divadvancedsearchfield center floatnone">';
451print
'<div class="inline-block"><span class="opacitymedium">'.$langs->trans(
"StatisticsOn").
'</span></div> ';
452print $form->selectarray(
'objecttype', $newarrayoftype, $objecttype, 0, 0, 0,
'', 1, 0, 0,
'',
'minwidth200', 1,
'', 0, 1);
453if (empty($conf->use_javascript_ajax)) {
454 print
'<input type="submit" class="button buttongen button-save nomargintop" name="changeobjecttype" value="'.$langs->trans(
"Refresh").
'">';
456 print
'<!-- js code to reload page with good object type -->
457 <script nonce="'.getNonce().
'" type="text/javascript">
458 jQuery(document).ready(function() {
459 jQuery("#objecttype").change(function() {
460 console.log("Reload for "+jQuery("#objecttype").val());
461 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')) :
'').
'";
466print
'</div><div class="clearboth"></div>';
469print
'<div class="divadvancedsearchfield quatrevingtpercent">';
470print $form->searchComponent(array($object->element => $object->fields), $search_component_params, array(), $search_component_params_hidden);
476print
'<div class="divadvancedsearchfield clearboth">';
477print
'<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>';
478$simplearrayofmesures = array();
479foreach ($arrayofmesures as $key => $val) {
480 $simplearrayofmesures[$key] = $arrayofmesures[$key][
'label'];
482print $form->multiselectarray(
'search_measures', $simplearrayofmesures, $search_measures, 0, 0,
'minwidth300', 1, 0,
'',
'', $langs->trans(
"Measures"));
487print
'<div class="divadvancedsearchfield">';
488print
'<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>';
490print $formother->selectXAxisField($object, $search_xaxis, $arrayofxaxis, $langs->trans(
"XAxis"),
'minwidth300 maxwidth400');
495print
'<div class="divadvancedsearchfield">';
496print
'<div class="inline-block opacitymedium"><span class="fas fa-ruler-horizontal paddingright pictofixedwidth" title="'.dol_escape_htmltag($langs->trans(
"GroupBy")).
'"></span></div>';
497print $formother->selectGroupByField($object, $search_groupby, $arrayofgroupby,
'minwidth250 maxwidth300', $langs->trans(
"GroupBy"));
501if ($mode ==
'grid') {
503 print
'<div class="divadvancedsearchfield">';
504 foreach ($object->fields as $key => $val) {
505 if (empty($val[
'measure']) && (!isset($val[
'enabled']) ||
dol_eval($val[
'enabled'], 1, 1,
'1'))) {
506 if (in_array($key, array(
'id',
'rowid',
'entity',
'last_main_doc',
'extraparams'))) {
509 if (preg_match(
'/^fk_/', $key)) {
512 if (in_array($val[
'type'], array(
'html',
'text'))) {
515 if (in_array($val[
'type'], array(
'timestamp',
'date',
'datetime'))) {
516 $arrayofyaxis[
't.'.$key.
'-year'] = array(
517 'label' => $langs->trans($val[
'label']).
' ('.$YYYY.
')',
518 'position' => $val[
'position'],
519 'table' => $object->table_element
521 $arrayofyaxis[
't.'.$key.
'-month'] = array(
522 'label' => $langs->trans($val[
'label']).
' ('.$YYYY.
'-'.$MM.
')',
523 'position' => $val[
'position'],
524 'table' => $object->table_element
526 $arrayofyaxis[
't.'.$key.
'-day'] = array(
527 'label' => $langs->trans($val[
'label']).
' ('.$YYYY.
'-'.$MM.
'-'.$DD.
')',
528 'position' => $val[
'position'],
529 'table' => $object->table_element
532 $arrayofyaxis[
't.'.$key] = array(
533 'label' => $val[
'label'],
534 'position' => (
int) $val[
'position'],
535 'table' => $object->table_element
541 if ($object->isextrafieldmanaged) {
542 foreach ($extrafields->attributes[$object->table_element][
'label'] as $key => $val) {
543 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'))) {
544 $arrayofyaxis[
'te.'.$key] = array(
545 'label' => $extrafields->attributes[$object->table_element][
'label'][$key],
546 'position' => (
int) $extrafields->attributes[$object->table_element][
'pos'][$key],
547 'table' => $object->table_element
553 $arrayofyaxislabel = array();
554 foreach ($arrayofyaxis as $key => $val) {
555 $arrayofyaxislabel[$key] = $val[
'label'];
557 print
'<div class="inline-block opacitymedium"><span class="fas fa-ruler-vertical paddingright" title="'.$langs->trans(
"YAxis").
'"></span>'.$langs->trans(
"YAxis").
'</div> ';
558 print $form->multiselectarray(
'search_yaxis', $arrayofyaxislabel, $search_yaxis, 0, 0,
'minwidth100', 1);
562if ($mode ==
'graph') {
566print
'<div class="divadvancedsearchfield">';
567print
'<input type="submit" class="button buttongen button-save nomargintop" value="'.$langs->trans(
"Refresh").
'">';
574if (!empty($search_measures) && !empty($search_xaxis)) {
580 foreach ($search_xaxis as $key => $val) {
581 if (preg_match(
'/\-year$/', $val)) {
582 $tmpval = preg_replace(
'/\-year$/',
'', $val);
583 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y') as x_".$key.
', ';
584 } elseif (preg_match(
'/\-month$/', $val)) {
585 $tmpval = preg_replace(
'/\-month$/',
'', $val);
586 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m') as x_".$key.
', ';
587 } elseif (preg_match(
'/\-day$/', $val)) {
588 $tmpval = preg_replace(
'/\-day$/',
'', $val);
589 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m-%d') as x_".$key.
', ';
591 $sql .= $val.
" as x_".$key.
", ";
594 foreach ($search_groupby as $key => $val) {
595 if (preg_match(
'/\-year$/', $val)) {
596 $tmpval = preg_replace(
'/\-year$/',
'', $val);
597 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y') as g_".$key.
', ';
598 } elseif (preg_match(
'/\-month$/', $val)) {
599 $tmpval = preg_replace(
'/\-month$/',
'', $val);
600 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m') as g_".$key.
', ';
601 } elseif (preg_match(
'/\-day$/', $val)) {
602 $tmpval = preg_replace(
'/\-day$/',
'', $val);
603 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m-%d') as g_".$key.
', ';
605 $sql .= $val.
" as g_".$key.
", ";
608 foreach ($search_measures as $key => $val) {
609 if ($val ==
't.count') {
610 $sql .=
"COUNT(t.".$fieldid.
") as y_".$key.
', ';
611 } elseif (preg_match(
'/\-sum$/', $val)) {
612 $tmpval = preg_replace(
'/\-sum$/',
'', $val);
613 $sql .=
"SUM(".$db->ifsql($tmpval.
' IS NULL',
'0', $tmpval).
") as y_".$key.
", ";
614 } elseif (preg_match(
'/\-average$/', $val)) {
615 $tmpval = preg_replace(
'/\-average$/',
'', $val);
616 $sql .=
"AVG(".$db->ifsql($tmpval.
' IS NULL',
'0', $tmpval).
") as y_".$key.
", ";
617 } elseif (preg_match(
'/\-min$/', $val)) {
618 $tmpval = preg_replace(
'/\-min$/',
'', $val);
619 $sql .=
"MIN(".$db->ifsql($tmpval.
' IS NULL',
'0', $tmpval).
") as y_".$key.
", ";
620 } elseif (preg_match(
'/\-max$/', $val)) {
621 $tmpval = preg_replace(
'/\-max$/',
'', $val);
622 $sql .=
"MAX(".$db->ifsql($tmpval.
' IS NULL',
'0', $tmpval).
") as y_".$key.
", ";
625 $sql = preg_replace(
'/,\s*$/',
'', $sql);
626 $sql .=
" FROM ".MAIN_DB_PREFIX.$object->table_element.
" as t";
628 if ($object->isextrafieldmanaged) {
629 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element.
"_extrafields as te ON te.fk_object = t.".$fieldid;
632 if ($object->ismultientitymanaged) {
633 if ($object->ismultientitymanaged == 1) {
636 $tmparray = explode(
'@', $object->ismultientitymanaged);
637 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.$tmparray[1].
" as parenttableforentity ON t.".$tmparray[0].
" = parenttableforentity.rowid";
638 $sql .=
" AND parenttableforentity.entity IN (".getEntity($tmparray[1]).
")";
643 $listoftablesalreadyadded = array($object->table_element => $object->table_element);
647 foreach ($search_xaxis as $key => $val) {
648 if (!empty($arrayofxaxis[$val])) {
649 $tmpval = explode(
'.', $val);
652 foreach ($tmpforloop as $tmptable => $tmptablealias) {
653 if (! in_array($tmptable, $listoftablesalreadyadded)) {
654 $tmpforexplode = explode(
'__', $tmptablealias);
655 $endpart = end($tmpforexplode);
656 $parenttableandfield = preg_replace(
'/__'.$endpart.
'$/',
'', $tmptablealias).
'.'.$endpart;
658 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$tmptable.
" as ".$db->sanitize($tmptablealias).
" ON ".$db->sanitize($parenttableandfield).
" = ".$db->sanitize($tmptablealias).
".rowid";
659 $listoftablesalreadyadded[$tmptable] = $tmptable;
661 if (preg_match(
'/^te/', $tmpval[0]) && preg_replace(
'/^t_/',
'te_', $tmptablealias) == $tmpval[0]) {
662 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$tmptable.
"_extrafields as ".$db->sanitize($tmpval[0]).
" ON ".$db->sanitize($tmpval[0]).
".fk_object = ".$db->sanitize($tmptablealias).
".rowid";
663 $listoftablesalreadyadded[$tmptable] = $tmptable;
668 $errormessage =
'Found a key into search_xaxis not found into arrayofxaxis';
674 foreach ($search_groupby as $key => $val) {
675 if (!empty($arrayofgroupby[$val])) {
676 $tmpval = explode(
'.', $val);
679 foreach ($tmpforloop as $tmptable => $tmptablealias) {
680 if (! in_array($tmptable, $listoftablesalreadyadded)) {
681 $tmpforexplode = explode(
'__', $tmptablealias);
682 $endpart = end($tmpforexplode);
683 $parenttableandfield = preg_replace(
'/__'.$endpart.
'$/',
'', $tmptablealias).
'.'.$endpart;
685 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$tmptable.
" as ".$db->sanitize($tmptablealias).
" ON ".$db->sanitize($parenttableandfield).
" = ".$db->sanitize($tmptablealias).
".rowid";
686 $listoftablesalreadyadded[$tmptable] = $tmptable;
688 if (preg_match(
'/^te/', $tmpval[0]) && preg_replace(
'/^t_/',
'te_', $tmptablealias) == $tmpval[0]) {
689 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$tmptable.
"_extrafields as ".$db->sanitize($tmpval[0]).
" ON ".$db->sanitize($tmpval[0]).
".fk_object = ".$db->sanitize($tmptablealias).
".rowid";
690 $listoftablesalreadyadded[$tmptable] = $tmptable;
695 $errormessage =
'Found a key into search_groupby not found into arrayofgroupby';
701 foreach ($search_measures as $key => $val) {
702 if (!empty($arrayofmesures[$val])) {
703 $tmpval = explode(
'.', $val);
706 foreach ($tmpforloop as $tmptable => $tmptablealias) {
707 if (! in_array($tmptable, $listoftablesalreadyadded)) {
708 $tmpforexplode = explode(
'__', $tmptablealias);
709 $endpart = end($tmpforexplode);
710 $parenttableandfield = preg_replace(
'/__'.$endpart.
'$/',
'', $tmptablealias).
'.'.$endpart;
712 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$tmptable.
" as ".$db->sanitize($tmptablealias).
" ON ".$db->sanitize($parenttableandfield).
" = ".$db->sanitize($tmptablealias).
".rowid";
713 $listoftablesalreadyadded[$tmptable] = $tmptable;
715 if (preg_match(
'/^te/', $tmpval[0]) && preg_replace(
'/^t_/',
'te_', $tmptablealias) == $tmpval[0]) {
716 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$tmptable.
"_extrafields as ".$db->sanitize($tmpval[0]).
" ON ".$db->sanitize($tmpval[0]).
".fk_object = ".$db->sanitize($tmptablealias).
".rowid";
717 $listoftablesalreadyadded[$tmptable] = $tmptable;
722 $errormessage =
'Found a key into search_measures not found into arrayofmesures';
726 $sql .=
" WHERE 1 = 1";
727 if ($object->ismultientitymanaged == 1) {
728 $sql .=
" AND t.entity IN (".getEntity($object->element).
")";
731 $sqlfilters = $search_component_params_hidden;
735 $sql .=
" GROUP BY ";
736 foreach ($search_xaxis 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 foreach ($search_groupby as $key => $val) {
751 if (preg_match(
'/\-year$/', $val)) {
752 $tmpval = preg_replace(
'/\-year$/',
'', $val);
753 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y'), ";
754 } elseif (preg_match(
'/\-month$/', $val)) {
755 $tmpval = preg_replace(
'/\-month$/',
'', $val);
756 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m'), ";
757 } elseif (preg_match(
'/\-day$/', $val)) {
758 $tmpval = preg_replace(
'/\-day$/',
'', $val);
759 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m-%d'), ";
764 $sql = preg_replace(
'/,\s*$/',
'', $sql);
765 $sql .=
' ORDER BY ';
766 foreach ($search_xaxis as $key => $val) {
767 if (preg_match(
'/\-year$/', $val)) {
768 $tmpval = preg_replace(
'/\-year$/',
'', $val);
769 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y'), ";
770 } elseif (preg_match(
'/\-month$/', $val)) {
771 $tmpval = preg_replace(
'/\-month$/',
'', $val);
772 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m'), ";
773 } elseif (preg_match(
'/\-day$/', $val)) {
774 $tmpval = preg_replace(
'/\-day$/',
'', $val);
775 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m-%d'), ";
780 foreach ($search_groupby as $key => $val) {
781 if (preg_match(
'/\-year$/', $val)) {
782 $tmpval = preg_replace(
'/\-year$/',
'', $val);
783 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y'), ";
784 } elseif (preg_match(
'/\-month$/', $val)) {
785 $tmpval = preg_replace(
'/\-month$/',
'', $val);
786 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m'), ";
787 } elseif (preg_match(
'/\-day$/', $val)) {
788 $tmpval = preg_replace(
'/\-day$/',
'', $val);
789 $sql .=
"DATE_FORMAT(".$tmpval.
", '%Y-%m-%d'), ";
794 $sql = preg_replace(
'/,\s*$/',
'', $sql);
804foreach ($search_measures as $key => $val) {
805 $legend[] = $langs->trans($arrayofmesures[$val][
'label']);
808$useagroupby = (is_array($search_groupby) && count($search_groupby));
816 $resql = $db->query($sql);
824 while ($obj = $db->fetch_object($resql)) {
827 $xval = $search_xaxis[0];
828 $fieldforxkey =
'x_0';
829 $xlabel = $obj->$fieldforxkey;
830 $xvalwithoutprefix = preg_replace(
'/^[a-z]+\./',
'', $xval);
833 if (!empty($object->fields[$xvalwithoutprefix][
'arrayofkeyval'])) {
834 $xlabel = $object->fields[$xvalwithoutprefix][
'arrayofkeyval'][$obj->$fieldforxkey];
836 $labeltouse = (($xlabel || $xlabel ==
'0') ?
dol_trunc($xlabel, 20,
'middle') : ($xlabel ===
'' ? $langs->transnoentitiesnoconv(
"Empty") : $langs->transnoentitiesnoconv(
"NotDefined")));
838 if ($oldlabeltouse && ($labeltouse != $oldlabeltouse)) {
842 $oldlabeltouse = $labeltouse;
855 foreach ($search_measures as $key => $val) {
857 foreach ($search_groupby as $gkey) {
860 foreach ($arrayofvaluesforgroupby[
'g_'.$gi] as $gvaluepossiblekey => $gvaluepossiblelabel) {
861 $ykeysuffix = $gvaluepossiblelabel;
862 $gvalwithoutprefix = preg_replace(
'/^[a-z]+\./',
'', $gval);
864 $fieldfory =
'y_'.$key;
865 $fieldforg =
'g_'.$gi;
866 $fieldforybis =
'y_'.$key.
'_'.$ykeysuffix;
870 if (!is_array($data[$xi])) {
871 $data[$xi] = array();
874 if (!array_key_exists(
'label', $data[$xi])) {
875 $data[$xi] = array();
876 $data[$xi][
'label'] = $labeltouse;
879 $objfieldforg = $obj->$fieldforg;
880 if (is_null($objfieldforg)) {
881 $objfieldforg =
'__NULL__';
884 if ($gvaluepossiblekey ==
'0') {
886 if ($objfieldforg ==
'0') {
888 $data[$xi][$fieldforybis] = $obj->$fieldfory;
889 } elseif (!isset($data[$xi][$fieldforybis])) {
891 $data[$xi][$fieldforybis] =
'0';
895 if ((
string) $objfieldforg === (
string) $gvaluepossiblekey) {
897 $data[$xi][$fieldforybis] = $obj->$fieldfory;
898 } elseif (!isset($data[$xi][$fieldforybis])) {
900 $data[$xi][$fieldforybis] =
'0';
909 $xval = $search_xaxis[0];
910 $fieldforxkey =
'x_0';
911 $xlabel = $obj->$fieldforxkey;
912 $xvalwithoutprefix = preg_replace(
'/^[a-z]+\./',
'', $xval);
915 if (!empty($object->fields[$xvalwithoutprefix][
'arrayofkeyval'])) {
916 $xlabel = $object->fields[$xvalwithoutprefix][
'arrayofkeyval'][$obj->$fieldforxkey];
919 $labeltouse = (($xlabel || $xlabel ==
'0') ?
dol_trunc($xlabel, 20,
'middle') : ($xlabel ===
'' ? $langs->transnoentitiesnoconv(
"Empty") : $langs->transnoentitiesnoconv(
"NotDefined")));
920 $xarrayforallseries = array(
'label' => $labeltouse);
921 foreach ($search_measures as $key => $val) {
922 $fieldfory =
'y_'.$key;
923 $xarrayforallseries[$fieldfory] = $obj->$fieldfory;
925 $data[$xi] = $xarrayforallseries;
930 $totalnbofrecord = count($data);
935print
'<div class="customreportsoutput'.($totalnbofrecord ?
'' :
' customreportsoutputnotdata').
'">';
938if ($mode ==
'grid') {
942if ($mode ==
'graph') {
944 $HEIGHT = (empty($_SESSION[
'dol_screenheight']) ? 400 : $_SESSION[
'dol_screenheight'] - 500);
948 $mesg = $px1->isGraphKo();
952 $px1->SetData($data);
955 $arrayoftypes = array();
956 foreach ($search_measures as $key => $val) {
957 $arrayoftypes[] = $search_graph;
960 $px1->SetLegend($legend);
961 $px1->SetMinValue($px1->GetFloorMinValue());
962 $px1->SetMaxValue($px1->GetCeilMaxValue());
963 $px1->SetWidth($WIDTH);
964 $px1->SetHeight($HEIGHT);
965 $px1->SetYLabel($langs->trans(
"Y"));
967 $px1->SetHorizTickIncrement(1);
968 $px1->SetCssPrefix(
"cssboxes");
969 $px1->SetType($arrayoftypes);
970 $px1->mode =
'depth';
973 $dir = $conf->user->dir_temp;
975 $filenamenb = $dir.
'/customreport_'.$object->element.
'.png';
976 $fileurlnb = DOL_URL_ROOT.
'/viewimage.php?modulepart=user&file=customreport_'.$object->element.
'.png';
978 $px1->draw($filenamenb, $fileurlnb);
980 $texttoshow = $langs->trans(
"NoRecordFound");
981 if (!GETPOSTISSET(
'search_measures') || !GETPOSTISSET(
'search_xaxis')) {
982 $texttoshow = $langs->trans(
"SelectYourGraphOptionsFirst");
985 print $px1->show($totalnbofrecord ? 0 : $texttoshow);
991 print
'<br>'.info_admin($langs->trans(
"SQLUsedForExport").
':<br> '.$sql, 0, 0, 1,
'',
'TechnicalInformation');
996if (!defined(
'USE_CUSTOM_REPORT_AS_INCLUDE')) {
1020function fillArrayOfMeasures($object, $tablealias, $labelofobject, &$arrayofmesures, $level = 0, &$count = 0, &$tablepath =
'')
1022 global $langs, $extrafields, $db;
1025 return $arrayofmesures;
1028 if (empty($tablepath)) {
1029 $tablepath = $object->table_element.
'='.$tablealias;
1031 $tablepath .=
','.$object->table_element.
'='.$tablealias;
1036 $arrayofmesures[$tablealias.
'.count'] = array(
1037 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': Count',
1038 'labelnohtml' => $labelofobject.
': Count',
1040 'table' => $object->table_element,
1041 'tablefromt' => $tablepath
1048 foreach ($object->fields as $key => $val) {
1049 if (!empty($val[
'isameasure']) && (!isset($val[
'enabled']) ||
dol_eval($val[
'enabled'], 1, 1,
'1'))) {
1050 $position = (empty($val[
'position']) ? 0 : intVal($val[
'position']));
1051 $arrayofmesures[$tablealias.
'.'.$key.
'-sum'] = array(
1052 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']).
' <span class="opacitymedium">('.$langs->trans(
"Sum").
')</span>',
1053 'labelnohtml' => $labelofobject.
': '.$langs->trans($val[
'label']),
1054 'position' => ($position + ($count * 100000)).
'.1',
1055 'table' => $object->table_element,
1056 'tablefromt' => $tablepath
1058 $arrayofmesures[$tablealias.
'.'.$key.
'-average'] = array(
1059 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']).
' <span class="opacitymedium">('.$langs->trans(
"Average").
')</span>',
1060 'labelnohtml' => $labelofobject.
': '.$langs->trans($val[
'label']),
1061 'position' => ($position + ($count * 100000)).
'.2',
1062 'table' => $object->table_element,
1063 'tablefromt' => $tablepath
1065 $arrayofmesures[$tablealias.
'.'.$key.
'-min'] = array(
1066 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']).
' <span class="opacitymedium">('.$langs->trans(
"Minimum").
')</span>',
1067 'labelnohtml' => $labelofobject.
': '.$langs->trans($val[
'label']),
1068 'position' => ($position + ($count * 100000)).
'.3',
1069 'table' => $object->table_element,
1070 'tablefromt' => $tablepath
1072 $arrayofmesures[$tablealias.
'.'.$key.
'-max'] = array(
1073 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']).
' <span class="opacitymedium">('.$langs->trans(
"Maximum").
')</span>',
1074 'labelnohtml' => $labelofobject.
': '.$langs->trans($val[
'label']),
1075 'position' => ($position + ($count * 100000)).
'.4',
1076 'table' => $object->table_element,
1077 'tablefromt' => $tablepath
1082 if (!empty($object->isextrafieldmanaged) && isset($extrafields->attributes[$object->table_element][
'label'])) {
1083 foreach ($extrafields->attributes[$object->table_element][
'label'] as $key => $val) {
1084 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'))) {
1085 $position = (!empty($val[
'position']) ? $val[
'position'] : 0);
1086 $arrayofmesures[preg_replace(
'/^t/',
'te', $tablealias).
'.'.$key.
'-sum'] = array(
1087 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($extrafields->attributes[$object->table_element][
'label'][$key]).
' <span class="opacitymedium">('.$langs->trans(
"Sum").
')</span>',
1088 'labelnohtml' => $labelofobject.
': '.$langs->trans($val),
1089 'position' => ($position+($count * 100000)).
'.1',
1090 'table' => $object->table_element,
1091 'tablefromt' => $tablepath
1093 $arrayofmesures[preg_replace(
'/^t/',
'te', $tablealias).
'.'.$key.
'-average'] = array(
1094 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($extrafields->attributes[$object->table_element][
'label'][$key]).
' <span class="opacitymedium">('.$langs->trans(
"Average").
')</span>',
1095 'labelnohtml' => $labelofobject.
': '.$langs->trans($val),
1096 'position' => ($position+($count * 100000)).
'.2',
1097 'table' => $object->table_element,
1098 'tablefromt' => $tablepath
1100 $arrayofmesures[preg_replace(
'/^t/',
'te', $tablealias).
'.'.$key.
'-min'] = array(
1101 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($extrafields->attributes[$object->table_element][
'label'][$key]).
' <span class="opacitymedium">('.$langs->trans(
"Minimum").
')</span>',
1102 'labelnohtml' => $labelofobject.
': '.$langs->trans($val),
1103 'position' => ($position+($count * 100000)).
'.3',
1104 'table' => $object->table_element,
1105 'tablefromt' => $tablepath
1107 $arrayofmesures[preg_replace(
'/^t/',
'te', $tablealias).
'.'.$key.
'-max'] = array(
1108 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($extrafields->attributes[$object->table_element][
'label'][$key]).
' <span class="opacitymedium">('.$langs->trans(
"Maximum").
')</span>',
1109 'labelnohtml' => $labelofobject.
': '.$langs->trans($val),
1110 'position' => ($position+($count * 100000)).
'.4',
1111 'table' => $object->table_element,
1112 'tablefromt' => $tablepath
1118 foreach ($object->fields as $key => $val) {
1119 if (preg_match(
'/^[^:]+:[^:]+:/', $val[
'type'])) {
1120 $tmptype = explode(
':', $val[
'type'], 4);
1121 if ($tmptype[0] ==
'integer' && !empty($tmptype[1]) && !empty($tmptype[2])) {
1122 $newobject = $tmptype[1];
1124 if (class_exists($newobject)) {
1125 $tmpobject =
new $newobject($db);
1128 $arrayofmesures =
fillArrayOfMeasures($tmpobject, $tablealias.
'__'.$key, $langs->trans($val[
'label']), $arrayofmesures, $level + 1, $count, $tablepath);
1130 print
'For property '.$object->element.
'->'.$key.
', type="'.$val[
'type'].
'": Failed to find class '.$newobject.
" in file ".$tmptype[2].
"<br>\n";
1136 return $arrayofmesures;
1152function fillArrayOfXAxis($object, $tablealias, $labelofobject, &$arrayofxaxis, $level = 0, &$count = 0, &$tablepath =
'')
1154 global $langs, $extrafields, $db;
1157 return $arrayofxaxis;
1160 if (empty($tablepath)) {
1161 $tablepath = $object->table_element.
'='.$tablealias;
1163 $tablepath .=
','.$object->table_element.
'='.$tablealias;
1166 $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);
1167 $MM = substr($langs->trans(
"Month"), 0, 1).substr($langs->trans(
"Month"), 0, 1);
1168 $DD = substr($langs->trans(
"Day"), 0, 1).substr($langs->trans(
"Day"), 0, 1);
1169 $HH = substr($langs->trans(
"Hour"), 0, 1).substr($langs->trans(
"Hour"), 0, 1);
1170 $MI = substr($langs->trans(
"Minute"), 0, 1).substr($langs->trans(
"Minute"), 0, 1);
1171 $SS = substr($langs->trans(
"Second"), 0, 1).substr($langs->trans(
"Second"), 0, 1);
1180 foreach ($object->fields as $key => $val) {
1181 if (empty($val[
'measure'])) {
1182 if (in_array($key, array(
1183 'id',
'ref_ext',
'rowid',
'entity',
'last_main_doc',
'logo',
'logo_squarred',
'extraparams',
1184 'parent',
'photo',
'socialnetworks',
'webservices_url',
'webservices_key'))) {
1187 if (isset($val[
'enabled']) && !
dol_eval($val[
'enabled'], 1, 1,
'1')) {
1190 if (isset($val[
'visible']) && !
dol_eval($val[
'visible'], 1, 1,
'1')) {
1193 if (preg_match(
'/^fk_/', $key) && !preg_match(
'/^fk_statu/', $key)) {
1196 if (preg_match(
'/^pass/', $key)) {
1199 if (in_array($val[
'type'], array(
'html',
'text'))) {
1202 if (in_array($val[
'type'], array(
'timestamp',
'date',
'datetime'))) {
1203 $position = (empty($val[
'position']) ? 0 : intVal($val[
'position']));
1204 $arrayofxaxis[$tablealias.
'.'.$key.
'-year'] = array(
1205 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']).
' <span class="opacitymedium">('.$YYYY.
')</span>',
1206 'labelnohtml' => $labelofobject.
': '.$langs->trans($val[
'label']),
1207 'position' => ($position + ($count * 100000)).
'.1',
1208 'table' => $object->table_element,
1209 'tablefromt' => $tablepath
1211 $arrayofxaxis[$tablealias.
'.'.$key.
'-month'] = array(
1212 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']).
' <span class="opacitymedium">('.$YYYY.
'-'.$MM.
')</span>',
1213 'labelnohtml' => $labelofobject.
': '.$langs->trans($val[
'label']),
1214 'position' => ($position + ($count * 100000)).
'.2',
1215 'table' => $object->table_element,
1216 'tablefromt' => $tablepath
1218 $arrayofxaxis[$tablealias.
'.'.$key.
'-day'] = array(
1219 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']).
' <span class="opacitymedium">('.$YYYY.
'-'.$MM.
'-'.$DD.
')</span>',
1220 'labelnohtml' => $labelofobject.
': '.$langs->trans($val[
'label']),
1221 'position' => ($position + ($count * 100000)).
'.3',
1222 'table' => $object->table_element,
1223 'tablefromt' => $tablepath
1226 $position = (empty($val[
'position']) ? 0 : intVal($val[
'position']));
1227 $arrayofxaxis[$tablealias.
'.'.$key] = array(
1228 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']),
1229 'labelnohtml' => $labelofobject.
': '.$langs->trans($val[
'label']),
1230 'position' => ($position + ($count * 100000)),
1231 'table' => $object->table_element,
1232 'tablefromt' => $tablepath
1239 if (!empty($object->isextrafieldmanaged) && isset($extrafields->attributes[$object->table_element][
'label'])) {
1240 foreach ($extrafields->attributes[$object->table_element][
'label'] as $key => $val) {
1241 if ($extrafields->attributes[$object->table_element][
'type'][$key] ==
'separate') {
1244 if (!empty($extrafields->attributes[$object->table_element][
'totalizable'][$key])) {
1248 if (in_array($extrafields->attributes[$object->table_element][
'type'][$key], array(
'timestamp',
'date',
'datetime'))) {
1249 $position = (empty($extrafields->attributes[$object->table_element][
'pos'][$key]) ? 0 : intVal($extrafields->attributes[$object->table_element][
'pos'][$key]));
1250 $arrayofxaxis[preg_replace(
'/^t/',
'te', $tablealias).
'.'.$key.
'-year'] = array(
1251 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val).
' <span class="opacitymedium">('.$YYYY.
')</span>',
1252 'labelnohtml' => $labelofobject.
': '.$langs->trans($val),
1253 'position' => ($position + ($count * 100000)).
'.1',
1254 'table' => $object->table_element,
1255 'tablefromt' => $tablepath
1257 $arrayofxaxis[preg_replace(
'/^t/',
'te', $tablealias).
'.'.$key.
'-month'] = array(
1258 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val).
' <span class="opacitymedium">('.$YYYY.
'-'.$MM.
')</span>',
1259 'labelnohtml' => $labelofobject.
': '.$langs->trans($val),
1260 'position' => ($position + ($count * 100000)).
'.2',
1261 'table' => $object->table_element,
1262 'tablefromt' => $tablepath
1264 $arrayofxaxis[preg_replace(
'/^t/',
'te', $tablealias).
'.'.$key.
'-day'] = array(
1265 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val).
' <span class="opacitymedium">('.$YYYY.
'-'.$MM.
'-'.$DD.
')</span>',
1266 'labelnohtml' => $labelofobject.
': '.$langs->trans($val),
1267 'position' => ($position + ($count * 100000)).
'.3',
1268 'table' => $object->table_element,
1269 'tablefromt' => $tablepath
1272 $arrayofxaxis[preg_replace(
'/^t/',
'te', $tablealias).
'.'.$key] = array(
1273 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val),
1274 'labelnohtml' => $labelofobject.
': '.$langs->trans($val),
1275 'position' => 1000 + (
int) $extrafields->attributes[$object->table_element][
'pos'][$key] + ($count * 100000),
1276 'table' => $object->table_element,
1277 'tablefromt' => $tablepath
1284 foreach ($object->fields as $key => $val) {
1285 if (preg_match(
'/^[^:]+:[^:]+:/', $val[
'type'])) {
1286 $tmptype = explode(
':', $val[
'type'], 4);
1287 if ($tmptype[0] ==
'integer' && $tmptype[1] && $tmptype[2]) {
1288 $newobject = $tmptype[1];
1290 if (class_exists($newobject)) {
1291 $tmpobject =
new $newobject($db);
1294 $arrayofxaxis =
fillArrayOfXAxis($tmpobject, $tablealias.
'__'.$key, $langs->trans($val[
'label']), $arrayofxaxis, $level + 1, $count, $tablepath);
1296 print
'For property '.$object->element.
'->'.$key.
', type="'.$val[
'type'].
'": Failed to find class '.$newobject.
" in file ".$tmptype[2].
"<br>\n";
1302 return $arrayofxaxis;
1318function fillArrayOfGroupBy($object, $tablealias, $labelofobject, &$arrayofgroupby, $level = 0, &$count = 0, &$tablepath =
'')
1320 global $langs, $extrafields, $db;
1323 return $arrayofgroupby;
1326 if (empty($tablepath)) {
1327 $tablepath = $object->table_element.
'='.$tablealias;
1329 $tablepath .=
','.$object->table_element.
'='.$tablealias;
1332 $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);
1333 $MM = substr($langs->trans(
"Month"), 0, 1).substr($langs->trans(
"Month"), 0, 1);
1334 $DD = substr($langs->trans(
"Day"), 0, 1).substr($langs->trans(
"Day"), 0, 1);
1335 $HH = substr($langs->trans(
"Hour"), 0, 1).substr($langs->trans(
"Hour"), 0, 1);
1336 $MI = substr($langs->trans(
"Minute"), 0, 1).substr($langs->trans(
"Minute"), 0, 1);
1337 $SS = substr($langs->trans(
"Second"), 0, 1).substr($langs->trans(
"Second"), 0, 1);
1342 foreach ($object->fields as $key => $val) {
1343 if (empty($val[
'isameasure'])) {
1344 if (in_array($key, array(
1345 'id',
'ref_ext',
'rowid',
'entity',
'last_main_doc',
'logo',
'logo_squarred',
'extraparams',
1346 'parent',
'photo',
'socialnetworks',
'webservices_url',
'webservices_key'))) {
1349 if (isset($val[
'enabled']) && !
dol_eval($val[
'enabled'], 1, 1,
'1')) {
1352 if (isset($val[
'visible']) && !
dol_eval($val[
'visible'], 1, 1,
'1')) {
1355 if (preg_match(
'/^fk_/', $key) && !preg_match(
'/^fk_statu/', $key)) {
1358 if (preg_match(
'/^pass/', $key)) {
1361 if (in_array($val[
'type'], array(
'html',
'text'))) {
1364 if (in_array($val[
'type'], array(
'timestamp',
'date',
'datetime'))) {
1365 $position = (empty($val[
'position']) ? 0 : intVal($val[
'position']));
1366 $arrayofgroupby[$tablealias.
'.'.$key.
'-year'] = array(
1367 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']).
' <span class="opacitymedium">('.$YYYY.
')</span>',
1368 'labelnohtml' => $labelofobject.
': '.$langs->trans($val[
'label']),
1369 'position' => ($position + ($count * 100000)).
'.1',
1370 'table' => $object->table_element,
1371 'tablefromt' => $tablepath
1373 $arrayofgroupby[$tablealias.
'.'.$key.
'-month'] = array(
1374 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']).
' <span class="opacitymedium">('.$YYYY.
'-'.$MM.
')</span>',
1375 'labelnohtml' => $labelofobject.
': '.$langs->trans($val[
'label']),
1376 'position' => ($position + ($count * 100000)).
'.2',
1377 'table' => $object->table_element,
1378 'tablefromt' => $tablepath
1380 $arrayofgroupby[$tablealias.
'.'.$key.
'-day'] = array(
1381 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']).
' <span class="opacitymedium">('.$YYYY.
'-'.$MM.
'-'.$DD.
')</span>',
1382 'labelnohtml' => $labelofobject.
': '.$langs->trans($val[
'label']),
1383 'position' => ($position + ($count * 100000)).
'.3',
1384 'table' => $object->table_element,
1385 'tablefromt' => $tablepath
1388 $position = (empty($val[
'position']) ? 0 : intVal($val[
'position']));
1389 $arrayofgroupby[$tablealias.
'.'.$key] = array(
1390 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val[
'label']),
1391 'labelnohtml' => $labelofobject.
': '.$langs->trans($val[
'label']),
1392 'position' => ($position + ($count * 100000)),
1393 'table' => $object->table_element,
1394 'tablefromt' => $tablepath
1401 if (!empty($object->isextrafieldmanaged) && isset($extrafields->attributes[$object->table_element][
'label'])) {
1402 foreach ($extrafields->attributes[$object->table_element][
'label'] as $key => $val) {
1403 if ($extrafields->attributes[$object->table_element][
'type'][$key] ==
'separate') {
1406 if (!empty($extrafields->attributes[$object->table_element][
'totalizable'][$key])) {
1410 if (in_array($extrafields->attributes[$object->table_element][
'type'][$key], array(
'timestamp',
'date',
'datetime'))) {
1411 $position = (empty($extrafields->attributes[$object->table_element][
'pos'][$key]) ? 0 : intVal($extrafields->attributes[$object->table_element][
'pos'][$key]));
1412 $arrayofgroupby[preg_replace(
'/^t/',
'te', $tablealias).
'.'.$key.
'-year'] = array(
1413 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val).
' <span class="opacitymedium">('.$YYYY.
')</span>',
1414 'labelnohtml' => $labelofobject.
': '.$langs->trans($val),
1415 'position' => ($position + ($count * 100000)).
'.1',
1416 'table' => $object->table_element,
1417 'tablefromt' => $tablepath
1419 $arrayofgroupby[preg_replace(
'/^t/',
'te', $tablealias).
'.'.$key.
'-month'] = array(
1420 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val).
' <span class="opacitymedium">('.$YYYY.
'-'.$MM.
')</span>',
1421 'labelnohtml' => $labelofobject.
': '.$langs->trans($val),
1422 'position' => ($position + ($count * 100000)).
'.2',
1423 'table' => $object->table_element,
1424 'tablefromt' => $tablepath
1426 $arrayofgroupby[preg_replace(
'/^t/',
'te', $tablealias).
'.'.$key.
'-day'] = array(
1427 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val).
' <span class="opacitymedium">('.$YYYY.
'-'.$MM.
'-'.$DD.
')</span>',
1428 'labelnohtml' => $labelofobject.
': '.$langs->trans($val),
1429 'position' => ($position + ($count * 100000)).
'.3',
1430 'table' => $object->table_element,
1431 'tablefromt' => $tablepath
1434 $arrayofgroupby[preg_replace(
'/^t/',
'te', $tablealias).
'.'.$key] = array(
1435 'label' =>
img_picto(
'', $object->picto,
'class="pictofixedwidth"').
' '.$labelofobject.
': '.$langs->trans($val),
1436 'labelnohtml' => $labelofobject.
': '.$langs->trans($val),
1437 'position' => 1000 + (
int) $extrafields->attributes[$object->table_element][
'pos'][$key] + ($count * 100000),
1438 'table' => $object->table_element,
1439 'tablefromt' => $tablepath
1446 foreach ($object->fields as $key => $val) {
1447 if (preg_match(
'/^[^:]+:[^:]+:/', $val[
'type'])) {
1448 $tmptype = explode(
':', $val[
'type'], 4);
1449 if ($tmptype[0] ==
'integer' && $tmptype[1] && $tmptype[2]) {
1450 $newobject = $tmptype[1];
1452 if (class_exists($newobject)) {
1453 $tmpobject =
new $newobject($db);
1456 $arrayofgroupby =
fillArrayOfGroupBy($tmpobject, $tablealias.
'__'.$key, $langs->trans($val[
'label']), $arrayofgroupby, $level + 1, $count, $tablepath);
1458 print
'For property '.$object->element.
'->'.$key.
', type="'.$val[
'type'].
'": Failed to find class '.$newobject.
" in file ".$tmptype[2].
"<br>\n";
1464 return $arrayofgroupby;
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
fillArrayOfGroupBy($object, $tablealias, $labelofobject, &$arrayofgroupby, $level=0, &$count=0, &$tablepath='')
Fill arrayofgrupby for an object.
fillArrayOfMeasures($object, $tablealias, $labelofobject, &$arrayofmesures, $level=0, &$count=0, &$tablepath='')
Fill arrayofmesures for an object.
fillArrayOfXAxis($object, $tablealias, $labelofobject, &$arrayofxaxis, $level=0, &$count=0, &$tablepath='')
Fill arrayofmesures for an object.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
dolExplodeIntoArray($string, $delimiter=';', $kv='=')
Split a string with 2 keys into key array.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
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.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
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...
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
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.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
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.