2020-02-07 10:58:17 +01:00
< ? php
2023-03-19 10:19:35 +01:00
/* Copyright ( C ) 2020 - 2023 Laurent Destailleur < eldy @ users . sourceforge . net >
2020-02-07 10:58:17 +01:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2022-09-07 20:21:01 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2020-02-11 10:38:09 +01:00
*
2020-04-13 00:33:50 +02:00
* Note : This tool can be included into a list page with :
2021-04-02 13:31:03 +02:00
* define ( 'USE_CUSTOM_REPORT_AS_INCLUDE' , 1 );
2020-02-11 10:38:09 +01:00
* include DOL_DOCUMENT_ROOT . '/core/customreports.php' ;
2020-02-07 10:58:17 +01:00
*/
/**
* \file htdocs / core / customreports . php
2020-02-08 17:46:41 +01:00
* \ingroup core
2020-02-07 10:58:17 +01:00
* \brief Page to make custom reports
*/
2021-04-02 13:31:03 +02:00
if ( ! defined ( 'USE_CUSTOM_REPORT_AS_INCLUDE' )) {
2020-02-11 10:38:09 +01:00
require '../main.inc.php' ;
// Get parameters
2023-12-04 12:07:53 +01:00
$action = GETPOST ( 'action' , 'aZ09' ) ? GETPOST ( 'action' , 'aZ09' ) : 'view' ; // The action 'add', 'create', 'edit', 'update', 'view', ...
2020-02-11 10:38:09 +01:00
$massaction = GETPOST ( 'massaction' , 'alpha' ); // The bulk action (combo box choice into lists)
2020-02-13 10:44:08 +01:00
$mode = GETPOST ( 'mode' , 'alpha' ) ? GETPOST ( 'mode' , 'alpha' ) : 'graph' ;
2024-02-15 18:40:04 +01:00
$objecttype = GETPOST ( 'objecttype' , 'aZ09arobase' );
2020-02-11 10:38:09 +01:00
$tabfamily = GETPOST ( 'tabfamily' , 'aZ09' );
2021-02-23 22:03:23 +01:00
if ( empty ( $objecttype )) {
$objecttype = 'thirdparty' ;
}
2020-02-11 10:38:09 +01:00
$search_measures = GETPOST ( 'search_measures' , 'array' );
2020-03-06 17:13:51 +01:00
//$search_xaxis = GETPOST('search_xaxis', 'array');
2021-02-23 22:03:23 +01:00
if ( GETPOST ( 'search_xaxis' , 'alpha' ) && GETPOST ( 'search_xaxis' , 'alpha' ) != '-1' ) {
$search_xaxis = array ( GETPOST ( 'search_xaxis' , 'alpha' ));
} else {
$search_xaxis = array ();
}
2020-03-06 17:13:51 +01:00
//$search_groupby = GETPOST('search_groupby', 'array');
2021-02-23 22:03:23 +01:00
if ( GETPOST ( 'search_groupby' , 'alpha' ) && GETPOST ( 'search_groupby' , 'alpha' ) != '-1' ) {
$search_groupby = array ( GETPOST ( 'search_groupby' , 'alpha' ));
} else {
$search_groupby = array ();
}
2020-03-06 17:13:51 +01:00
2020-02-11 10:38:09 +01:00
$search_yaxis = GETPOST ( 'search_yaxis' , 'array' );
2022-01-19 15:20:10 +01:00
$search_graph = GETPOST ( 'search_graph' , 'restricthtml' );
2020-02-11 10:38:09 +01:00
// Load variable for pagination
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
2020-09-18 17:13:01 +02:00
$sortfield = GETPOST ( 'sortfield' , 'aZ09comma' );
2020-09-17 14:31:25 +02:00
$sortorder = GETPOST ( 'sortorder' , 'aZ09comma' );
2020-03-13 13:07:11 +01:00
$page = GETPOSTISSET ( 'pageplusone' ) ? ( GETPOST ( 'pageplusone' ) - 1 ) : GETPOST ( " page " , 'int' );
2021-02-23 22:03:23 +01:00
if ( empty ( $page ) || $page == - 1 || GETPOST ( 'button_search' , 'alpha' ) || GETPOST ( 'button_removefilter' , 'alpha' ) || ( empty ( $toselect ) && $massaction === '0' )) {
$page = 0 ;
} // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
2020-02-11 10:38:09 +01:00
$offset = $limit * $page ;
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
$diroutputmassaction = $conf -> user -> dir_temp . '/' . $user -> id . '/customreport' ;
2020-02-07 10:58:17 +01:00
}
2020-03-06 17:13:51 +01:00
require_once DOL_DOCUMENT_ROOT . " /core/lib/admin.lib.php " ;
require_once DOL_DOCUMENT_ROOT . " /core/lib/company.lib.php " ;
require_once DOL_DOCUMENT_ROOT . " /core/class/dolgraph.class.php " ;
require_once DOL_DOCUMENT_ROOT . " /core/class/doleditor.class.php " ;
require_once DOL_DOCUMENT_ROOT . " /core/class/html.formother.class.php " ;
2020-02-11 10:38:09 +01:00
// Load traductions files requiredby by page
2020-03-08 20:10:31 +01:00
$langs -> loadLangs ( array ( " companies " , " other " , " exports " , " sendings " ));
2020-02-11 10:38:09 +01:00
2020-02-07 10:58:17 +01:00
$extrafields = new ExtraFields ( $db );
$hookmanager -> initHooks ( array ( 'customreport' )); // Note that conf->hooks_modules contains array
$title = '' ;
$picto = '' ;
$head = array ();
$object = null ;
$ObjectClassName = '' ;
2020-02-08 17:46:41 +01:00
// Objects available by default
2020-02-07 10:58:17 +01:00
$arrayoftype = array (
2023-02-22 03:03:35 +01:00
'thirdparty' => array ( 'langs' => 'companies' , 'label' => 'ThirdParties' , 'picto' => 'company' , 'ObjectClassName' => 'Societe' , 'enabled' => isModEnabled ( 'societe' ), 'ClassPath' => " /societe/class/societe.class.php " ),
'contact' => array ( 'label' => 'Contacts' , 'picto' => 'contact' , 'ObjectClassName' => 'Contact' , 'enabled' => isModEnabled ( 'societ' ), 'ClassPath' => " /contact/class/contact.class.php " ),
'proposal' => array ( 'label' => 'Proposals' , 'picto' => 'proposal' , 'ObjectClassName' => 'Propal' , 'enabled' => isModEnabled ( 'propal' ), 'ClassPath' => " /comm/propal/class/propal.class.php " ),
'order' => array ( 'label' => 'Orders' , 'picto' => 'order' , 'ObjectClassName' => 'Commande' , 'enabled' => isModEnabled ( 'commande' ), 'ClassPath' => " /commande/class/commande.class.php " ),
'invoice' => array ( 'langs' => 'facture' , 'label' => 'Invoices' , 'picto' => 'bill' , 'ObjectClassName' => 'Facture' , 'enabled' => isModEnabled ( 'facture' ), 'ClassPath' => " /compta/facture/class/facture.class.php " ),
2023-03-19 10:19:35 +01:00
'invoice_template' => array ( 'label' => 'PredefinedInvoices' , 'picto' => 'bill' , 'ObjectClassName' => 'FactureRec' , 'enabled' => isModEnabled ( 'facture' ), 'ClassPath' => " /compta/class/facturerec.class.php " , 'langs' => 'bills' ),
2023-02-22 03:03:35 +01:00
'contract' => array ( 'label' => 'Contracts' , 'picto' => 'contract' , 'ObjectClassName' => 'Contrat' , 'enabled' => isModEnabled ( 'contrat' ), 'ClassPath' => " /contrat/class/contrat.class.php " , 'langs' => 'contracts' ),
'contractdet' => array ( 'label' => 'ContractLines' , 'picto' => 'contract' , 'ObjectClassName' => 'ContratLigne' , 'enabled' => isModEnabled ( 'contrat' ), 'ClassPath' => " /contrat/class/contrat.class.php " , 'langs' => 'contracts' ),
'bom' => array ( 'label' => 'BOM' , 'picto' => 'bom' , 'ObjectClassName' => 'Bom' , 'enabled' => isModEnabled ( 'bom' )),
'mo' => array ( 'label' => 'MO' , 'picto' => 'mrp' , 'ObjectClassName' => 'Mo' , 'enabled' => isModEnabled ( 'mrp' ), 'ClassPath' => " /mrp/class/mo.class.php " ),
'ticket' => array ( 'label' => 'Ticket' , 'picto' => 'ticket' , 'ObjectClassName' => 'Ticket' , 'enabled' => isModEnabled ( 'ticket' )),
'member' => array ( 'label' => 'Adherent' , 'picto' => 'member' , 'ObjectClassName' => 'Adherent' , 'enabled' => isModEnabled ( 'adherent' ), 'ClassPath' => " /adherents/class/adherent.class.php " , 'langs' => 'members' ),
'cotisation' => array ( 'label' => 'Subscriptions' , 'picto' => 'member' , 'ObjectClassName' => 'Subscription' , 'enabled' => isModEnabled ( 'adherent' ), 'ClassPath' => " /adherents/class/subscription.class.php " , 'langs' => 'members' ),
2020-02-07 10:58:17 +01:00
);
2020-02-29 00:11:19 +01:00
// Complete $arrayoftype by external modules
2020-02-07 10:58:17 +01:00
$parameters = array ( 'objecttype' => $objecttype , 'tabfamily' => $tabfamily );
$reshook = $hookmanager -> executeHooks ( 'loadDataForCustomReports' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2021-02-23 22:03:23 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
} elseif ( is_array ( $hookmanager -> resArray )) {
2020-02-13 10:44:08 +01:00
if ( ! empty ( $hookmanager -> resArray [ 'title' ])) { // Add entries for tabs
2020-02-07 10:58:17 +01:00
$title = $hookmanager -> resArray [ 'title' ];
}
2020-02-13 10:44:08 +01:00
if ( ! empty ( $hookmanager -> resArray [ 'picto' ])) { // Add entries for tabs
2020-02-07 10:58:17 +01:00
$picto = $hookmanager -> resArray [ 'picto' ];
}
2020-02-13 10:44:08 +01:00
if ( ! empty ( $hookmanager -> resArray [ 'head' ])) { // Add entries for tabs
2020-02-07 10:58:17 +01:00
$head = array_merge ( $head , $hookmanager -> resArray [ 'head' ]);
}
2020-02-13 10:44:08 +01:00
if ( ! empty ( $hookmanager -> resArray [ 'arrayoftype' ])) { // Add entries from hook
foreach ( $hookmanager -> resArray [ 'arrayoftype' ] as $key => $val ) {
2020-10-31 14:32:18 +01:00
$arrayoftype [ $key ] = $val ;
}
2020-02-07 10:58:17 +01:00
}
}
if ( $objecttype ) {
2020-10-31 14:32:18 +01:00
try {
if ( ! empty ( $arrayoftype [ $objecttype ][ 'ClassPath' ])) {
dol_include_once ( $arrayoftype [ $objecttype ][ 'ClassPath' ]);
} else {
dol_include_once ( " / " . $objecttype . " /class/ " . $objecttype . " .class.php " );
}
2024-02-15 18:40:04 +01:00
2020-10-31 14:32:18 +01:00
$ObjectClassName = $arrayoftype [ $objecttype ][ 'ObjectClassName' ];
2024-02-15 18:40:04 +01:00
if ( class_exists ( $ObjectClassName )) {
$object = new $ObjectClassName ( $db );
} else {
print 'Failed to load class for type ' . $objecttype . '. Class file found but class object ' . $ObjectClassName . ' not found.' ;
}
2020-10-31 14:32:18 +01:00
} catch ( Exception $e ) {
2024-02-15 18:40:04 +01:00
print 'Failed to load class for type ' . $objecttype . '. Class path not found.' ;
2020-10-31 14:32:18 +01:00
}
2020-02-07 10:58:17 +01:00
}
2020-02-07 11:53:09 +01:00
// Security check
$socid = 0 ;
2021-02-23 22:03:23 +01:00
if ( $user -> socid > 0 ) { // Protection if external user
2020-02-07 11:53:09 +01:00
//$socid = $user->socid;
2024-02-15 18:40:04 +01:00
accessforbidden ( 'Access forbidden to external users' );
2020-02-07 11:53:09 +01:00
}
2020-03-08 18:26:41 +01:00
2020-02-07 10:58:17 +01:00
// Fetch optionals attributes and labels
2023-05-24 00:19:27 +02:00
$extrafields -> fetch_name_optionals_label ( 'all' ); // We load all extrafields definitions for all objects
2020-02-07 10:58:17 +01:00
//$extrafields->fetch_name_optionals_label($object->table_element_line);
$search_array_options = $extrafields -> getOptionalsFromPost ( $object -> table_element , '' , 'search_' );
2020-02-13 10:44:08 +01:00
$search_component_params = array ( '' );
2024-02-16 01:19:53 +01:00
$search_component_params_hidden = trim ( GETPOST ( 'search_component_params_hidden' , 'alphanohtml' ));
$search_component_params_input = trim ( GETPOST ( 'search_component_params_input' , 'alphanohtml' ));
//var_dump($search_component_params_hidden);
//var_dump($search_component_params_input);
2020-02-07 10:58:17 +01:00
2024-02-16 01:19:53 +01:00
$arrayofandtagshidden = dolForgeExplodeAnd ( $search_component_params_hidden );
$arrayofandtagsinput = dolForgeExplodeAnd ( $search_component_params_input );
$search_component_params_hidden = implode ( ' AND ' , array_merge ( $arrayofandtagshidden , $arrayofandtagsinput ));
//var_dump($search_component_params_hidden);
2022-02-15 11:03:48 +01:00
2020-03-06 01:18:35 +01:00
$MAXUNIQUEVALFORGROUP = 20 ;
$MAXMEASURESINBARGRAPH = 20 ;
2020-03-06 17:13:51 +01:00
2020-03-12 12:45:44 +01:00
$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 );
$MM = substr ( $langs -> trans ( " Month " ), 0 , 1 ) . substr ( $langs -> trans ( " Month " ), 0 , 1 );
$DD = substr ( $langs -> trans ( " Day " ), 0 , 1 ) . substr ( $langs -> trans ( " Day " ), 0 , 1 );
$HH = substr ( $langs -> trans ( " Hour " ), 0 , 1 ) . substr ( $langs -> trans ( " Hour " ), 0 , 1 );
$MI = substr ( $langs -> trans ( " Minute " ), 0 , 1 ) . substr ( $langs -> trans ( " Minute " ), 0 , 1 );
$SS = substr ( $langs -> trans ( " Second " ), 0 , 1 ) . substr ( $langs -> trans ( " Second " ), 0 , 1 );
2020-03-06 01:18:35 +01:00
2022-02-21 19:09:26 +01:00
$arrayofmesures = array ();
2020-03-06 01:18:35 +01:00
$arrayofxaxis = array ();
$arrayofgroupby = array ();
$arrayofyaxis = array ();
$arrayofvaluesforgroupby = array ();
2022-02-15 11:03:48 +01:00
$features = $object -> element ;
if ( ! empty ( $object -> element_for_permission )) {
$features = $object -> element_for_permission ;
}
2024-02-15 18:40:04 +01:00
restrictedArea ( $user , $features . ( empty ( $object -> module ) ? '' : '@' . $object -> module ), 0 , '' );
2022-01-03 04:47:17 +01:00
$error = 0 ;
2020-03-06 01:18:35 +01:00
2020-02-07 10:58:17 +01:00
/*
* Actions
*/
2022-01-03 04:47:17 +01:00
// None
2020-02-07 10:58:17 +01:00
/*
* View
*/
2020-02-13 10:44:08 +01:00
$form = new Form ( $db );
2020-03-06 17:13:51 +01:00
$formother = new FormOther ( $db );
2020-02-07 10:58:17 +01:00
2021-04-02 13:31:03 +02:00
if ( ! defined ( 'USE_CUSTOM_REPORT_AS_INCLUDE' )) {
2020-02-11 10:38:09 +01:00
llxHeader ( '' , $langs -> transnoentitiesnoconv ( 'CustomReports' ), '' );
2020-02-07 10:58:17 +01:00
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( $head , 'customreports' , $title , - 1 , $picto );
2020-02-08 17:46:41 +01:00
}
2020-02-07 10:58:17 +01:00
2022-03-22 11:47:25 +01:00
$newarrayoftype = array ();
foreach ( $arrayoftype as $key => $val ) {
if ( dol_eval ( $val [ 'enabled' ], 1 , 1 , '1' )) {
$newarrayoftype [ $key ] = $arrayoftype [ $key ];
}
2022-07-16 02:23:30 +02:00
if ( ! empty ( $val [ 'langs' ])) {
2022-03-22 11:47:25 +01:00
$langs -> load ( $val [ 'langs' ]);
}
}
$count = 0 ;
$arrayofmesures = fillArrayOfMeasures ( $object , 't' , $langs -> trans ( $newarrayoftype [ $objecttype ][ 'label' ]), $arrayofmesures , 0 , $count );
2022-03-22 13:23:16 +01:00
$arrayofmesures = dol_sort_array ( $arrayofmesures , 'position' , 'asc' , 0 , 0 , 1 );
2022-03-22 11:47:25 +01:00
$count = 0 ;
$arrayofxaxis = fillArrayOfXAxis ( $object , 't' , $langs -> trans ( $newarrayoftype [ $objecttype ][ 'label' ]), $arrayofxaxis , 0 , $count );
$arrayofxaxis = dol_sort_array ( $arrayofxaxis , 'position' , 'asc' , 0 , 0 , 1 );
$count = 0 ;
$arrayofgroupby = fillArrayOfGroupBy ( $object , 't' , $langs -> trans ( $newarrayoftype [ $objecttype ][ 'label' ]), $arrayofgroupby , 0 , $count );
$arrayofgroupby = dol_sort_array ( $arrayofgroupby , 'position' , 'asc' , 0 , 0 , 1 );
2020-02-11 10:38:09 +01:00
// Check parameters
if ( $action == 'viewgraph' ) {
2020-02-13 10:44:08 +01:00
if ( ! count ( $search_measures )) {
2020-02-11 10:38:09 +01:00
setEventMessages ( $langs -> trans ( " AtLeastOneMeasureIsRequired " ), null , 'warnings' );
} elseif ( $mode == 'graph' && count ( $search_xaxis ) > 1 ) {
setEventMessages ( $langs -> trans ( " OnlyOneFieldForXAxisIsPossible " ), null , 'warnings' );
$search_xaxis = array ( 0 => $search_xaxis [ 0 ]);
}
2020-03-04 19:28:15 +01:00
if ( count ( $search_groupby ) >= 2 ) {
2020-03-06 01:18:35 +01:00
setEventMessages ( $langs -> trans ( " ErrorOnlyOneFieldForGroupByIsPossible " ), null , 'warnings' );
$search_groupby = array ( 0 => $search_groupby [ 0 ]);
2020-03-04 19:28:15 +01:00
}
2020-02-13 10:44:08 +01:00
if ( ! count ( $search_xaxis )) {
2020-02-11 10:38:09 +01:00
setEventMessages ( $langs -> trans ( " AtLeastOneXAxisIsRequired " ), null , 'warnings' );
2020-03-06 01:18:35 +01:00
} elseif ( $mode == 'graph' && $search_graph == 'bars' && count ( $search_measures ) > $MAXMEASURESINBARGRAPH ) {
$langs -> load ( " errors " );
setEventMessages ( $langs -> trans ( " GraphInBarsAreLimitedToNMeasures " , $MAXMEASURESINBARGRAPH ), null , 'warnings' );
2020-02-11 10:38:09 +01:00
$search_graph = 'lines' ;
}
}
2020-02-07 10:58:17 +01:00
2020-03-12 11:09:18 +01:00
// Get all possible values of fields when a 'group by' is set, and save this into $arrayofvaluesforgroupby
2020-04-13 01:10:35 +02:00
// $arrayofvaluesforgroupby will be used to forge lael of each grouped series
2020-03-06 01:18:35 +01:00
if ( is_array ( $search_groupby ) && count ( $search_groupby )) {
2020-03-12 12:45:44 +01:00
foreach ( $search_groupby as $gkey => $gval ) {
2020-03-06 01:18:35 +01:00
$gvalwithoutprefix = preg_replace ( '/^[a-z]+\./' , '' , $gval );
if ( preg_match ( '/\-year$/' , $search_groupby [ $gkey ])) {
$tmpval = preg_replace ( '/\-year$/' , '' , $search_groupby [ $gkey ]);
$fieldtocount .= 'DATE_FORMAT(' . $tmpval . " , '%Y') " ;
} elseif ( preg_match ( '/\-month$/' , $search_groupby [ $gkey ])) {
$tmpval = preg_replace ( '/\-month$/' , '' , $search_groupby [ $gkey ]);
$fieldtocount .= 'DATE_FORMAT(' . $tmpval . " , '%Y-%m') " ;
} elseif ( preg_match ( '/\-day$/' , $search_groupby [ $gkey ])) {
$tmpval = preg_replace ( '/\-day$/' , '' , $search_groupby [ $gkey ]);
$fieldtocount .= 'DATE_FORMAT(' . $tmpval . " , '%Y-%m-%d') " ;
} else {
$fieldtocount = $search_groupby [ $gkey ];
}
2021-08-28 00:55:51 +02:00
$sql = " SELECT DISTINCT " . $fieldtocount . " as val " ;
2022-03-22 13:23:16 +01:00
2023-05-24 03:18:00 +02:00
if ( strpos ( $fieldtocount , 'te' ) === 0 ) {
$tabletouse = $object -> table_element ;
$tablealiastouse = 'te' ;
if ( ! empty ( $arrayofgroupby [ $gval ])) {
$tmpval = explode ( '.' , $gval );
$tabletouse = $arrayofgroupby [ $gval ][ 'table' ];
$tablealiastouse = $tmpval [ 0 ];
}
//var_dump($tablealiastouse);exit;
//$sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element."_extrafields as te";
$sql .= " FROM " . MAIN_DB_PREFIX . $tabletouse . " _extrafields as " . $tablealiastouse ;
2020-03-06 20:02:05 +01:00
} else {
2022-03-22 13:23:16 +01:00
$tabletouse = $object -> table_element ;
$tablealiastouse = 't' ;
if ( ! empty ( $arrayofgroupby [ $gval ])) {
$tmpval = explode ( '.' , $gval );
$tabletouse = $arrayofgroupby [ $gval ][ 'table' ];
$tablealiastouse = $tmpval [ 0 ];
}
2022-03-22 13:37:33 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . $tabletouse . " as " . $tablealiastouse ;
2020-03-06 20:02:05 +01:00
}
2022-01-03 04:47:17 +01:00
2024-01-13 19:48:20 +01:00
// Add a where here keeping only the criteria on $tabletouse
2023-05-25 14:26:48 +02:00
// TODO
/* $sqlfilters = ... GETPOST ( 'search_component_params_hidden' , 'alphanohtml' );
2022-01-03 04:47:17 +01:00
if ( $sqlfilters ) {
$errormessage = '' ;
2023-02-25 19:48:33 +01:00
$sql .= forgeSQLFromUniversalSearchCriteria ( $sqlfilters , $errormessage );
2022-01-03 04:47:17 +01:00
} */
2020-03-06 01:18:35 +01:00
2022-03-22 13:37:33 +01:00
$sql .= " LIMIT " . (( int ) ( $MAXUNIQUEVALFORGROUP + 1 ));
2020-03-06 20:02:05 +01:00
//print $sql;
2020-03-06 01:18:35 +01:00
$resql = $db -> query ( $sql );
if ( ! $resql ) {
dol_print_error ( $db );
}
while ( $obj = $db -> fetch_object ( $resql )) {
2020-03-06 20:02:05 +01:00
if ( is_null ( $obj -> val )) {
$keytouse = '__NULL__' ;
$valuetranslated = $langs -> transnoentitiesnoconv ( " NotDefined " );
2020-05-21 15:05:19 +02:00
} elseif ( $obj -> val === '' ) {
2020-03-06 20:02:05 +01:00
$keytouse = '' ;
$valuetranslated = $langs -> transnoentitiesnoconv ( " Empty " );
2020-05-21 15:05:19 +02:00
} else {
2020-03-06 20:02:05 +01:00
$keytouse = ( string ) $obj -> val ;
$valuetranslated = $obj -> val ;
}
2020-04-13 01:10:35 +02:00
$regs = array ();
2020-03-06 01:18:35 +01:00
if ( ! empty ( $object -> fields [ $gvalwithoutprefix ][ 'arrayofkeyval' ])) {
$valuetranslated = $object -> fields [ $gvalwithoutprefix ][ 'arrayofkeyval' ][ $obj -> val ];
2021-02-23 22:03:23 +01:00
if ( is_null ( $valuetranslated )) {
$valuetranslated = $langs -> transnoentitiesnoconv ( " UndefinedKey " );
}
2020-03-12 11:09:18 +01:00
$valuetranslated = $langs -> trans ( $valuetranslated );
2020-05-21 15:05:19 +02:00
} elseif ( preg_match ( '/integer:([^:]+):([^:]+)$/' , $object -> fields [ $gvalwithoutprefix ][ 'type' ], $regs )) {
2020-04-13 01:10:35 +02:00
$classname = $regs [ 1 ];
$classpath = $regs [ 2 ];
dol_include_once ( $classpath );
if ( class_exists ( $classname )) {
$tmpobject = new $classname ( $db );
$tmpobject -> fetch ( $obj -> val );
2020-04-25 13:52:07 +02:00
foreach ( $tmpobject -> fields as $fieldkey => $field ) {
2020-04-13 01:10:35 +02:00
if ( $field [ 'showoncombobox' ]) {
$valuetranslated = $tmpobject -> $fieldkey ;
//if ($valuetranslated == '-') $valuetranslated = $langs->transnoentitiesnoconv("Unknown")
break ;
}
}
//$valuetranslated = $tmpobject->ref.'eee';
}
}
2020-03-06 01:18:35 +01:00
2020-03-06 20:02:05 +01:00
$arrayofvaluesforgroupby [ 'g_' . $gkey ][ $keytouse ] = $valuetranslated ;
2020-03-06 01:18:35 +01:00
}
2022-03-22 13:23:16 +01:00
// Add also the possible NULL value if field is a parent field that is not a strict join
$tmpfield = explode ( '.' , $gval );
if ( $tmpfield [ 0 ] != 't' || ( is_array ( $object -> fields [ $tmpfield [ 1 ]]) && empty ( $object -> fields [ $tmpfield [ 1 ]][ 'notnull' ]))) {
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 " );
//var_dump($gval); var_dump($object->fields);
$arrayofvaluesforgroupby [ 'g_' . $gkey ][ '__NULL__' ] = $langs -> transnoentitiesnoconv ( " NotDefined " );
}
2020-03-06 01:18:35 +01:00
asort ( $arrayofvaluesforgroupby [ 'g_' . $gkey ]);
2022-03-22 13:23:16 +01:00
// Add a protection/error to refuse the request if number of differentr values for the group by is higher than $MAXUNIQUEVALFORGROUP
2020-03-06 01:18:35 +01:00
if ( count ( $arrayofvaluesforgroupby [ 'g_' . $gkey ]) > $MAXUNIQUEVALFORGROUP ) {
$langs -> load ( " errors " );
2023-05-24 03:18:00 +02:00
if ( strpos ( $fieldtocount , 'te' ) === 0 ) { // This is a field of an extrafield
2020-10-31 14:32:18 +01:00
//if (!empty($extrafields->attributes[$object->table_element]['langfile'][$gvalwithoutprefix])) {
// $langs->load($extrafields->attributes[$object->table_element]['langfile'][$gvalwithoutprefix]);
//}
$keyforlabeloffield = $extrafields -> attributes [ $object -> table_element ][ 'label' ][ $gvalwithoutprefix ];
2022-08-23 02:31:38 +02:00
$labeloffield = $langs -> transnoentitiesnoconv ( $keyforlabeloffield );
} elseif ( strpos ( $fieldtocount , 't__' ) === 0 ) { // This is a field of a foreign key
$reg = array ();
if ( preg_match ( '/^(.*)\.(.*)/' , $gvalwithoutprefix , $reg )) {
2023-05-24 03:18:00 +02:00
/*
2022-08-23 02:31:38 +02:00
$gvalwithoutprefix = preg_replace ( '/\..*$/' , '' , $gvalwithoutprefix );
2023-05-24 03:18:00 +02:00
$gvalwithoutprefix = preg_replace ( '/^t__/' , '' , $gvalwithoutprefix );
2022-08-23 02:31:38 +02:00
$keyforlabeloffield = $object -> fields [ $gvalwithoutprefix ][ 'label' ];
$labeloffield = $langs -> transnoentitiesnoconv ( $keyforlabeloffield ) . '-' . $reg [ 2 ];
2023-05-24 03:18:00 +02:00
*/
$labeloffield = $arrayofgroupby [ $fieldtocount ][ 'labelnohtml' ];
2022-08-23 02:31:38 +02:00
} else {
$labeloffield = $langs -> transnoentitiesnoconv ( $keyforlabeloffield );
}
} else { // This is a common field
$reg = array ();
if ( preg_match ( '/^(.*)\-(year|month|day)/' , $gvalwithoutprefix , $reg )) {
$gvalwithoutprefix = preg_replace ( '/\-(year|month|day)/' , '' , $gvalwithoutprefix );
$keyforlabeloffield = $object -> fields [ $gvalwithoutprefix ][ 'label' ];
$labeloffield = $langs -> transnoentitiesnoconv ( $keyforlabeloffield ) . '-' . $reg [ 2 ];
} else {
$keyforlabeloffield = $object -> fields [ $gvalwithoutprefix ][ 'label' ];
$labeloffield = $langs -> transnoentitiesnoconv ( $keyforlabeloffield );
}
2020-10-31 14:32:18 +01:00
}
2022-08-23 02:31:38 +02:00
//var_dump($object->fields);
2020-03-06 01:18:35 +01:00
setEventMessages ( $langs -> trans ( " ErrorTooManyDifferentValueForSelectedGroupBy " , $MAXUNIQUEVALFORGROUP , $labeloffield ), null , 'warnings' );
$search_groupby = array ();
}
$db -> free ( $resql );
}
}
//var_dump($arrayofvaluesforgroupby);exit;
2020-02-13 10:44:08 +01:00
$tmparray = dol_getdate ( dol_now ());
$endyear = $tmparray [ 'year' ];
$endmonth = $tmparray [ 'mon' ];
$datelastday = dol_get_last_day ( $endyear , $endmonth , 1 );
$startyear = $endyear - 2 ;
2020-02-07 10:58:17 +01:00
$param = '' ;
2023-05-25 12:03:04 +02:00
print '<form method="post" action="' . $_SERVER [ 'PHP_SELF' ] . '" autocomplete="off">' ;
2020-09-14 16:24:02 +02:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2020-02-11 10:38:09 +01:00
print '<input type="hidden" name="action" value="viewgraph">' ;
2020-02-08 14:49:26 +01:00
print '<input type="hidden" name="tabfamily" value="' . $tabfamily . '">' ;
2020-02-07 10:58:17 +01:00
2022-01-03 04:47:17 +01:00
$viewmode = '' ;
$viewmode .= '<div class="divadvancedsearchfield">' ;
$arrayofgraphs = array ( 'bars' => 'Bars' , 'lines' => 'Lines' ); // also 'pies'
$viewmode .= '<div class="inline-block opacitymedium"><span class="fas fa-chart-area paddingright" title="' . $langs -> trans ( " Graph " ) . '"></span>' . $langs -> trans ( " Graph " ) . '</div> ' ;
2023-02-22 03:40:39 +01:00
$viewmode .= $form -> selectarray ( 'search_graph' , $arrayofgraphs , $search_graph , 0 , 0 , 0 , '' , 1 , 0 , 0 , '' , 'graphtype width100' );
2022-01-03 04:47:17 +01:00
$viewmode .= '</div>' ;
$num = 0 ;
$massactionbutton = '' ;
$nav = '' ;
$newcardbutton = '' ;
$limit = 0 ;
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 );
2023-02-22 03:03:35 +01:00
foreach ( $newarrayoftype as $tmpkey => $tmpval ) {
$newarrayoftype [ $tmpkey ][ 'label' ] = img_picto ( '' , $tmpval [ 'picto' ], 'class="pictofixedwidth"' ) . $langs -> trans ( $tmpval [ 'label' ]);
}
2022-01-03 04:47:17 +01:00
2023-03-11 01:09:22 +01:00
print '<div class="liste_titre liste_titre_bydiv liste_titre_bydiv_inlineblock centpercent">' ;
2020-02-07 10:58:17 +01:00
// Select object
print '<div class="divadvancedsearchfield center floatnone">' ;
print '<div class="inline-block"><span class="opacitymedium">' . $langs -> trans ( " StatisticsOn " ) . '</span></div> ' ;
2023-02-22 03:03:35 +01:00
print $form -> selectarray ( 'objecttype' , $newarrayoftype , $objecttype , 0 , 0 , 0 , '' , 1 , 0 , 0 , '' , 'minwidth200' , 1 , '' , 0 , 1 );
2021-02-23 22:03:23 +01:00
if ( empty ( $conf -> use_javascript_ajax )) {
2022-01-01 21:46:16 +01:00
print '<input type="submit" class="button buttongen button-save nomargintop" name="changeobjecttype" value="' . $langs -> trans ( " Refresh " ) . '">' ;
2021-02-23 22:03:23 +01:00
} else {
2022-01-03 04:47:17 +01:00
print ' <!-- js code to reload page with good object type -->
2023-02-18 15:10:05 +01:00
< script nonce = " '.getNonce().' " type = " text/javascript " >
2020-02-07 10:58:17 +01:00
jQuery ( document ) . ready ( function () {
jQuery ( " #objecttype " ) . change ( function () {
console . log ( " Reload for " + jQuery ( " #objecttype " ) . val ());
2022-01-03 04:47:17 +01:00
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')) : '').' " ;
2020-02-07 10:58:17 +01:00
});
});
</ script > ' ;
}
print '</div><div class="clearboth"></div>' ;
2023-05-24 00:19:27 +02:00
// Filter (you can use param &show_search_component_params_hidden=1 for debug)
2020-02-07 10:58:17 +01:00
print '<div class="divadvancedsearchfield quatrevingtpercent">' ;
2022-01-03 04:47:17 +01:00
print $form -> searchComponent ( array ( $object -> element => $object -> fields ), $search_component_params , array (), $search_component_params_hidden );
2020-02-07 10:58:17 +01:00
print '</div>' ;
2023-05-24 00:19:27 +02:00
// YAxis (add measures into array)
2022-02-21 19:09:26 +01:00
$count = 0 ;
//var_dump($arrayofmesures);
2020-02-07 10:58:17 +01:00
print '<div class="divadvancedsearchfield clearboth">' ;
2022-02-15 23:01:14 +01:00
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>' ;
2022-03-22 13:23:16 +01:00
$simplearrayofmesures = array ();
foreach ( $arrayofmesures as $key => $val ) {
$simplearrayofmesures [ $key ] = $arrayofmesures [ $key ][ 'label' ];
}
2022-07-18 14:51:03 +02:00
print $form -> multiselectarray ( 'search_measures' , $simplearrayofmesures , $search_measures , 0 , 0 , 'minwidth300' , 1 , 0 , '' , '' , $langs -> trans ( " Measures " )); // Fill the array $arrayofmeasures with possible fields
2020-02-07 10:58:17 +01:00
print '</div>' ;
2022-01-03 04:47:17 +01:00
// XAxis
2022-02-21 19:09:26 +01:00
$count = 0 ;
2020-03-04 19:28:15 +01:00
print '<div class="divadvancedsearchfield">' ;
2022-02-15 23:01:14 +01:00
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>' ;
2022-02-21 19:09:26 +01:00
//var_dump($arrayofxaxis);
2022-07-18 14:51:03 +02:00
print $formother -> selectXAxisField ( $object , $search_xaxis , $arrayofxaxis , $langs -> trans ( " XAxis " ), 'minwidth300 maxwidth400' ); // Fill the array $arrayofxaxis with possible fields
2020-03-04 19:28:15 +01:00
print '</div>' ;
2022-01-03 04:47:17 +01:00
// Group by
2022-02-21 19:09:26 +01:00
$count = 0 ;
2020-02-07 10:58:17 +01:00
print '<div class="divadvancedsearchfield">' ;
2022-02-15 23:01:14 +01:00
print '<div class="inline-block opacitymedium"><span class="fas fa-ruler-horizontal paddingright pictofixedwidth" title="' . dol_escape_htmltag ( $langs -> trans ( " GroupBy " )) . '"></span></div>' ;
2022-05-18 11:00:43 +02:00
print $formother -> selectGroupByField ( $object , $search_groupby , $arrayofgroupby , 'minwidth250 maxwidth300' , $langs -> trans ( " GroupBy " )); // Fill the array $arrayofgroupby with possible fields
2020-02-07 10:58:17 +01:00
print '</div>' ;
2020-03-06 17:13:51 +01:00
2020-02-07 10:58:17 +01:00
if ( $mode == 'grid' ) {
2020-03-06 17:13:51 +01:00
// YAxis
print '<div class="divadvancedsearchfield">' ;
2020-10-31 14:32:18 +01:00
foreach ( $object -> fields as $key => $val ) {
2022-03-01 16:38:06 +01:00
if ( empty ( $val [ 'measure' ]) && ( ! isset ( $val [ 'enabled' ]) || dol_eval ( $val [ 'enabled' ], 1 , 1 , '1' ))) {
2021-02-23 22:03:23 +01:00
if ( in_array ( $key , array ( 'id' , 'rowid' , 'entity' , 'last_main_doc' , 'extraparams' ))) {
continue ;
}
if ( preg_match ( '/^fk_/' , $key )) {
continue ;
}
if ( in_array ( $val [ 'type' ], array ( 'html' , 'text' ))) {
continue ;
}
2020-10-31 14:32:18 +01:00
if ( in_array ( $val [ 'type' ], array ( 'timestamp' , 'date' , 'datetime' ))) {
2022-03-22 13:23:16 +01:00
$arrayofyaxis [ 't.' . $key . '-year' ] = array (
'label' => $langs -> trans ( $val [ 'label' ]) . ' (' . $YYYY . ')' ,
'position' => $val [ 'position' ],
'table' => $object -> table_element
);
$arrayofyaxis [ 't.' . $key . '-month' ] = array (
'label' => $langs -> trans ( $val [ 'label' ]) . ' (' . $YYYY . '-' . $MM . ')' ,
'position' => $val [ 'position' ],
'table' => $object -> table_element
);
$arrayofyaxis [ 't.' . $key . '-day' ] = array (
'label' => $langs -> trans ( $val [ 'label' ]) . ' (' . $YYYY . '-' . $MM . '-' . $DD . ')' ,
'position' => $val [ 'position' ],
'table' => $object -> table_element
);
2020-10-31 14:32:18 +01:00
} else {
2022-03-22 13:23:16 +01:00
$arrayofyaxis [ 't.' . $key ] = array (
'label' => $val [ 'label' ],
'position' => ( int ) $val [ 'position' ],
'table' => $object -> table_element
);
2020-10-31 14:32:18 +01:00
}
}
2022-06-12 11:17:11 +02:00
}
// Add measure from extrafields
if ( $object -> isextrafieldmanaged ) {
foreach ( $extrafields -> attributes [ $object -> table_element ][ 'label' ] as $key => $val ) {
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' ))) {
$arrayofyaxis [ 'te.' . $key ] = array (
'label' => $extrafields -> attributes [ $object -> table_element ][ 'label' ][ $key ],
'position' => ( int ) $extrafields -> attributes [ $object -> table_element ][ 'pos' ][ $key ],
'table' => $object -> table_element
);
2020-10-31 14:32:18 +01:00
}
}
}
$arrayofyaxis = dol_sort_array ( $arrayofyaxis , 'position' );
$arrayofyaxislabel = array ();
foreach ( $arrayofyaxis as $key => $val ) {
$arrayofyaxislabel [ $key ] = $val [ 'label' ];
}
print '<div class="inline-block opacitymedium"><span class="fas fa-ruler-vertical paddingright" title="' . $langs -> trans ( " YAxis " ) . '"></span>' . $langs -> trans ( " YAxis " ) . '</div> ' ;
print $form -> multiselectarray ( 'search_yaxis' , $arrayofyaxislabel , $search_yaxis , 0 , 0 , 'minwidth100' , 1 );
print '</div>' ;
2020-02-07 10:58:17 +01:00
}
if ( $mode == 'graph' ) {
2022-01-03 04:47:17 +01:00
//
2020-02-07 10:58:17 +01:00
}
2022-01-03 04:47:17 +01:00
2020-02-07 10:58:17 +01:00
print '<div class="divadvancedsearchfield">' ;
2022-01-01 21:46:16 +01:00
print '<input type="submit" class="button buttongen button-save nomargintop" value="' . $langs -> trans ( " Refresh " ) . '">' ;
2020-02-07 10:58:17 +01:00
print '</div>' ;
print '</div>' ;
print '</form>' ;
// Generate the SQL request
$sql = '' ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $search_measures ) && ! empty ( $search_xaxis )) {
2023-05-25 12:25:06 +02:00
$errormessage = '' ;
2020-10-31 14:32:18 +01:00
$fieldid = 'rowid' ;
2022-03-22 13:23:16 +01:00
$sql = " SELECT " ;
2020-10-31 14:32:18 +01:00
foreach ( $search_xaxis as $key => $val ) {
if ( preg_match ( '/\-year$/' , $val )) {
$tmpval = preg_replace ( '/\-year$/' , '' , $val );
2021-08-28 00:55:51 +02:00
$sql .= " DATE_FORMAT( " . $tmpval . " , '%Y') as x_ " . $key . ', ' ;
2020-10-31 14:32:18 +01:00
} elseif ( preg_match ( '/\-month$/' , $val )) {
$tmpval = preg_replace ( '/\-month$/' , '' , $val );
2021-08-28 00:55:51 +02:00
$sql .= " DATE_FORMAT( " . $tmpval . " , '%Y-%m') as x_ " . $key . ', ' ;
2020-10-31 14:32:18 +01:00
} elseif ( preg_match ( '/\-day$/' , $val )) {
$tmpval = preg_replace ( '/\-day$/' , '' , $val );
2021-08-28 00:55:51 +02:00
$sql .= " DATE_FORMAT( " . $tmpval . " , '%Y-%m-%d') as x_ " . $key . ', ' ;
2021-02-23 22:03:23 +01:00
} else {
2021-08-28 00:55:51 +02:00
$sql .= $val . " as x_ " . $key . " , " ;
2021-02-23 22:03:23 +01:00
}
2020-10-31 14:32:18 +01:00
}
foreach ( $search_groupby as $key => $val ) {
if ( preg_match ( '/\-year$/' , $val )) {
$tmpval = preg_replace ( '/\-year$/' , '' , $val );
2021-08-28 00:55:51 +02:00
$sql .= " DATE_FORMAT( " . $tmpval . " , '%Y') as g_ " . $key . ', ' ;
2020-10-31 14:32:18 +01:00
} elseif ( preg_match ( '/\-month$/' , $val )) {
$tmpval = preg_replace ( '/\-month$/' , '' , $val );
2021-08-28 00:55:51 +02:00
$sql .= " DATE_FORMAT( " . $tmpval . " , '%Y-%m') as g_ " . $key . ', ' ;
2020-10-31 14:32:18 +01:00
} elseif ( preg_match ( '/\-day$/' , $val )) {
$tmpval = preg_replace ( '/\-day$/' , '' , $val );
2021-08-28 00:55:51 +02:00
$sql .= " DATE_FORMAT( " . $tmpval . " , '%Y-%m-%d') as g_ " . $key . ', ' ;
2021-02-23 22:03:23 +01:00
} else {
2021-08-28 00:55:51 +02:00
$sql .= $val . " as g_ " . $key . " , " ;
2021-02-23 22:03:23 +01:00
}
2020-10-31 14:32:18 +01:00
}
foreach ( $search_measures as $key => $val ) {
2021-02-23 22:03:23 +01:00
if ( $val == 't.count' ) {
2021-08-28 00:55:51 +02:00
$sql .= " COUNT(t. " . $fieldid . " ) as y_ " . $key . ', ' ;
2021-02-23 22:03:23 +01:00
} elseif ( preg_match ( '/\-sum$/' , $val )) {
2020-10-31 14:32:18 +01:00
$tmpval = preg_replace ( '/\-sum$/' , '' , $val );
2021-08-28 00:55:51 +02:00
$sql .= " SUM( " . $db -> ifsql ( $tmpval . ' IS NULL' , '0' , $tmpval ) . " ) as y_ " . $key . " , " ;
2020-10-31 14:32:18 +01:00
} elseif ( preg_match ( '/\-average$/' , $val )) {
$tmpval = preg_replace ( '/\-average$/' , '' , $val );
2021-08-28 00:55:51 +02:00
$sql .= " AVG( " . $db -> ifsql ( $tmpval . ' IS NULL' , '0' , $tmpval ) . " ) as y_ " . $key . " , " ;
2020-10-31 14:32:18 +01:00
} elseif ( preg_match ( '/\-min$/' , $val )) {
2020-10-31 18:51:30 +01:00
$tmpval = preg_replace ( '/\-min$/' , '' , $val );
2021-08-28 00:55:51 +02:00
$sql .= " MIN( " . $db -> ifsql ( $tmpval . ' IS NULL' , '0' , $tmpval ) . " ) as y_ " . $key . " , " ;
2020-10-31 14:32:18 +01:00
} elseif ( preg_match ( '/\-max$/' , $val )) {
$tmpval = preg_replace ( '/\-max$/' , '' , $val );
2021-08-28 00:55:51 +02:00
$sql .= " MAX( " . $db -> ifsql ( $tmpval . ' IS NULL' , '0' , $tmpval ) . " ) as y_ " . $key . " , " ;
2020-10-31 14:32:18 +01:00
}
}
$sql = preg_replace ( '/,\s*$/' , '' , $sql );
2022-03-22 13:23:16 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . $object -> table_element . " as t " ;
2020-10-31 14:32:18 +01:00
// Add measure from extrafields
if ( $object -> isextrafieldmanaged ) {
2021-08-28 00:55:51 +02:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . $object -> table_element . " _extrafields as te ON te.fk_object = t. " . $fieldid ;
2020-10-31 14:32:18 +01:00
}
2023-05-24 03:18:00 +02:00
// Add table for link on multientity
2022-03-22 13:23:16 +01:00
if ( $object -> ismultientitymanaged ) { // 0=No test on entity, 1=Test with field entity, 'field@table'=Test with link by field@table
2020-10-31 14:32:18 +01:00
if ( $object -> ismultientitymanaged == 1 ) {
2022-03-22 13:23:16 +01:00
// No table to add here
2020-10-31 14:32:18 +01:00
} else {
$tmparray = explode ( '@' , $object -> ismultientitymanaged );
2022-03-22 13:23:16 +01:00
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . $tmparray [ 1 ] . " as parenttableforentity ON t. " . $tmparray [ 0 ] . " = parenttableforentity.rowid " ;
$sql .= " AND parenttableforentity.entity IN ( " . getEntity ( $tmparray [ 1 ]) . " ) " ;
2020-10-31 14:32:18 +01:00
}
}
2022-03-21 22:02:34 +01:00
2023-05-24 03:18:00 +02:00
// Init the list of tables added. We include by default always the main table.
2022-03-21 22:02:34 +01:00
$listoftablesalreadyadded = array ( $object -> table_element => $object -> table_element );
2022-03-22 13:23:16 +01:00
2024-01-13 19:48:20 +01:00
// Add LEFT JOIN for all parent tables mentioned into the Xaxis
2022-03-22 13:23:16 +01:00
//var_dump($arrayofxaxis); var_dump($search_xaxis);
2022-03-21 22:02:34 +01:00
foreach ( $search_xaxis as $key => $val ) {
if ( ! empty ( $arrayofxaxis [ $val ])) {
$tmpval = explode ( '.' , $val );
2023-05-24 03:18:00 +02:00
//var_dump($arrayofgroupby);
$tmpforloop = dolExplodeIntoArray ( $arrayofxaxis [ $val ][ 'tablefromt' ], ',' );
foreach ( $tmpforloop as $tmptable => $tmptablealias ) {
if ( ! in_array ( $tmptable , $listoftablesalreadyadded )) { // We do not add join for main table and tables already added
$tmpforexplode = explode ( '__' , $tmptablealias );
$endpart = end ( $tmpforexplode );
$parenttableandfield = preg_replace ( '/__' . $endpart . '$/' , '' , $tmptablealias ) . '.' . $endpart ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . $tmptable . " as " . $db -> sanitize ( $tmptablealias ) . " ON " . $db -> sanitize ( $parenttableandfield ) . " = " . $db -> sanitize ( $tmptablealias ) . " .rowid " ;
$listoftablesalreadyadded [ $tmptable ] = $tmptable ;
if ( preg_match ( '/^te/' , $tmpval [ 0 ]) && preg_replace ( '/^t_/' , 'te_' , $tmptablealias ) == $tmpval [ 0 ]) {
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . $tmptable . " _extrafields as " . $db -> sanitize ( $tmpval [ 0 ]) . " ON " . $db -> sanitize ( $tmpval [ 0 ]) . " .fk_object = " . $db -> sanitize ( $tmptablealias ) . " .rowid " ;
$listoftablesalreadyadded [ $tmptable ] = $tmptable ;
}
}
2022-03-21 22:02:34 +01:00
}
} else {
2023-05-25 12:25:06 +02:00
$errormessage = 'Found a key into search_xaxis not found into arrayofxaxis' ;
2022-03-21 22:02:34 +01:00
}
}
2024-01-13 19:48:20 +01:00
// Add LEFT JOIN for all parent tables mentioned into the Group by
2022-03-22 13:23:16 +01:00
//var_dump($arrayofgroupby); var_dump($search_groupby);
foreach ( $search_groupby as $key => $val ) {
if ( ! empty ( $arrayofgroupby [ $val ])) {
$tmpval = explode ( '.' , $val );
2023-05-24 03:18:00 +02:00
//var_dump($arrayofgroupby[$val]); var_dump($tmpval);
$tmpforloop = dolExplodeIntoArray ( $arrayofgroupby [ $val ][ 'tablefromt' ], ',' );
foreach ( $tmpforloop as $tmptable => $tmptablealias ) {
if ( ! in_array ( $tmptable , $listoftablesalreadyadded )) { // We do not add join for main table and tables already added
$tmpforexplode = explode ( '__' , $tmptablealias );
$endpart = end ( $tmpforexplode );
$parenttableandfield = preg_replace ( '/__' . $endpart . '$/' , '' , $tmptablealias ) . '.' . $endpart ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . $tmptable . " as " . $db -> sanitize ( $tmptablealias ) . " ON " . $db -> sanitize ( $parenttableandfield ) . " = " . $db -> sanitize ( $tmptablealias ) . " .rowid " ;
$listoftablesalreadyadded [ $tmptable ] = $tmptable ;
if ( preg_match ( '/^te/' , $tmpval [ 0 ]) && preg_replace ( '/^t_/' , 'te_' , $tmptablealias ) == $tmpval [ 0 ]) {
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . $tmptable . " _extrafields as " . $db -> sanitize ( $tmpval [ 0 ]) . " ON " . $db -> sanitize ( $tmpval [ 0 ]) . " .fk_object = " . $db -> sanitize ( $tmptablealias ) . " .rowid " ;
$listoftablesalreadyadded [ $tmptable ] = $tmptable ;
}
}
2022-03-22 13:23:16 +01:00
}
} else {
2023-05-25 12:25:06 +02:00
$errormessage = 'Found a key into search_groupby not found into arrayofgroupby' ;
2022-03-22 13:23:16 +01:00
}
}
2024-01-13 19:48:20 +01:00
// Add LEFT JOIN for all parent tables mentioned into the Yaxis
2022-03-22 13:23:16 +01:00
//var_dump($arrayofgroupby); var_dump($search_groupby);
foreach ( $search_measures as $key => $val ) {
if ( ! empty ( $arrayofmesures [ $val ])) {
$tmpval = explode ( '.' , $val );
2023-05-24 03:18:00 +02:00
//var_dump($arrayofgroupby);
$tmpforloop = dolExplodeIntoArray ( $arrayofmesures [ $val ][ 'tablefromt' ], ',' );
foreach ( $tmpforloop as $tmptable => $tmptablealias ) {
if ( ! in_array ( $tmptable , $listoftablesalreadyadded )) { // We do not add join for main table and tables already added
$tmpforexplode = explode ( '__' , $tmptablealias );
$endpart = end ( $tmpforexplode );
$parenttableandfield = preg_replace ( '/__' . $endpart . '$/' , '' , $tmptablealias ) . '.' . $endpart ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . $tmptable . " as " . $db -> sanitize ( $tmptablealias ) . " ON " . $db -> sanitize ( $parenttableandfield ) . " = " . $db -> sanitize ( $tmptablealias ) . " .rowid " ;
$listoftablesalreadyadded [ $tmptable ] = $tmptable ;
if ( preg_match ( '/^te/' , $tmpval [ 0 ]) && preg_replace ( '/^t_/' , 'te_' , $tmptablealias ) == $tmpval [ 0 ]) {
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . $tmptable . " _extrafields as " . $db -> sanitize ( $tmpval [ 0 ]) . " ON " . $db -> sanitize ( $tmpval [ 0 ]) . " .fk_object = " . $db -> sanitize ( $tmptablealias ) . " .rowid " ;
$listoftablesalreadyadded [ $tmptable ] = $tmptable ;
}
}
2022-03-22 13:23:16 +01:00
}
} else {
2023-05-25 12:25:06 +02:00
$errormessage = 'Found a key into search_measures not found into arrayofmesures' ;
2022-03-21 22:02:34 +01:00
}
}
2022-03-22 13:23:16 +01:00
$sql .= " WHERE 1 = 1 " ;
if ( $object -> ismultientitymanaged == 1 ) { // 0=No test on entity, 1=Test with field entity, 'field@table'=Test with link by field@table
$sql .= " AND t.entity IN ( " . getEntity ( $object -> element ) . " ) " ;
2020-10-31 14:32:18 +01:00
}
2022-01-03 04:47:17 +01:00
// Add the where here
2022-02-15 11:03:48 +01:00
$sqlfilters = $search_component_params_hidden ;
2022-01-03 04:47:17 +01:00
if ( $sqlfilters ) {
2023-05-25 14:26:48 +02:00
$sql .= forgeSQLFromUniversalSearchCriteria ( $sqlfilters , $errormessage , 0 , 0 , 1 );
2020-10-31 14:32:18 +01:00
}
2022-03-22 13:23:16 +01:00
$sql .= " GROUP BY " ;
2020-10-31 14:32:18 +01:00
foreach ( $search_xaxis as $key => $val ) {
if ( preg_match ( '/\-year$/' , $val )) {
$tmpval = preg_replace ( '/\-year$/' , '' , $val );
2021-08-28 00:55:51 +02:00
$sql .= " DATE_FORMAT( " . $tmpval . " , '%Y'), " ;
2020-10-31 14:32:18 +01:00
} elseif ( preg_match ( '/\-month$/' , $val )) {
$tmpval = preg_replace ( '/\-month$/' , '' , $val );
2021-08-28 00:55:51 +02:00
$sql .= " DATE_FORMAT( " . $tmpval . " , '%Y-%m'), " ;
2020-10-31 14:32:18 +01:00
} elseif ( preg_match ( '/\-day$/' , $val )) {
$tmpval = preg_replace ( '/\-day$/' , '' , $val );
2021-08-28 00:55:51 +02:00
$sql .= " DATE_FORMAT( " . $tmpval . " , '%Y-%m-%d'), " ;
2021-02-23 22:03:23 +01:00
} else {
2021-08-28 00:55:51 +02:00
$sql .= $val . " , " ;
2021-02-23 22:03:23 +01:00
}
2020-10-31 14:32:18 +01:00
}
foreach ( $search_groupby as $key => $val ) {
if ( preg_match ( '/\-year$/' , $val )) {
$tmpval = preg_replace ( '/\-year$/' , '' , $val );
2021-08-28 00:55:51 +02:00
$sql .= " DATE_FORMAT( " . $tmpval . " , '%Y'), " ;
2020-10-31 14:32:18 +01:00
} elseif ( preg_match ( '/\-month$/' , $val )) {
$tmpval = preg_replace ( '/\-month$/' , '' , $val );
2021-08-28 00:55:51 +02:00
$sql .= " DATE_FORMAT( " . $tmpval . " , '%Y-%m'), " ;
2020-10-31 14:32:18 +01:00
} elseif ( preg_match ( '/\-day$/' , $val )) {
$tmpval = preg_replace ( '/\-day$/' , '' , $val );
2021-08-28 00:55:51 +02:00
$sql .= " DATE_FORMAT( " . $tmpval . " , '%Y-%m-%d'), " ;
2021-02-23 22:03:23 +01:00
} else {
$sql .= $val . ', ' ;
}
2020-10-31 14:32:18 +01:00
}
$sql = preg_replace ( '/,\s*$/' , '' , $sql );
$sql .= ' ORDER BY ' ;
foreach ( $search_xaxis as $key => $val ) {
if ( preg_match ( '/\-year$/' , $val )) {
$tmpval = preg_replace ( '/\-year$/' , '' , $val );
2021-08-28 00:55:51 +02:00
$sql .= " DATE_FORMAT( " . $tmpval . " , '%Y'), " ;
2020-10-31 14:32:18 +01:00
} elseif ( preg_match ( '/\-month$/' , $val )) {
$tmpval = preg_replace ( '/\-month$/' , '' , $val );
2021-08-28 00:55:51 +02:00
$sql .= " DATE_FORMAT( " . $tmpval . " , '%Y-%m'), " ;
2020-10-31 14:32:18 +01:00
} elseif ( preg_match ( '/\-day$/' , $val )) {
$tmpval = preg_replace ( '/\-day$/' , '' , $val );
2021-08-28 00:55:51 +02:00
$sql .= " DATE_FORMAT( " . $tmpval . " , '%Y-%m-%d'), " ;
2021-02-23 22:03:23 +01:00
} else {
$sql .= $val . ', ' ;
}
2020-10-31 14:32:18 +01:00
}
foreach ( $search_groupby as $key => $val ) {
if ( preg_match ( '/\-year$/' , $val )) {
$tmpval = preg_replace ( '/\-year$/' , '' , $val );
2021-08-28 00:55:51 +02:00
$sql .= " DATE_FORMAT( " . $tmpval . " , '%Y'), " ;
2020-10-31 14:32:18 +01:00
} elseif ( preg_match ( '/\-month$/' , $val )) {
$tmpval = preg_replace ( '/\-month$/' , '' , $val );
2021-08-28 00:55:51 +02:00
$sql .= " DATE_FORMAT( " . $tmpval . " , '%Y-%m'), " ;
2020-10-31 14:32:18 +01:00
} elseif ( preg_match ( '/\-day$/' , $val )) {
$tmpval = preg_replace ( '/\-day$/' , '' , $val );
2021-08-28 00:55:51 +02:00
$sql .= " DATE_FORMAT( " . $tmpval . " , '%Y-%m-%d'), " ;
2021-02-23 22:03:23 +01:00
} else {
$sql .= $val . ', ' ;
}
2020-10-31 14:32:18 +01:00
}
$sql = preg_replace ( '/,\s*$/' , '' , $sql );
2020-02-07 10:58:17 +01:00
}
2020-03-06 01:18:35 +01:00
//print $sql;
2020-02-07 10:58:17 +01:00
2023-05-25 12:25:06 +02:00
if ( $errormessage ) {
print dol_escape_htmltag ( $errormessage );
$sql = '' ;
}
2020-02-13 10:44:08 +01:00
$legend = array ();
foreach ( $search_measures as $key => $val ) {
2022-03-22 13:23:16 +01:00
$legend [] = $langs -> trans ( $arrayofmesures [ $val ][ 'label' ]);
2020-02-07 10:58:17 +01:00
}
2020-03-06 20:02:05 +01:00
$useagroupby = ( is_array ( $search_groupby ) && count ( $search_groupby ));
2020-03-08 19:25:00 +01:00
//var_dump($useagroupby);
2020-03-06 20:02:05 +01:00
//var_dump($arrayofvaluesforgroupby);
2020-02-07 10:58:17 +01:00
// Execute the SQL request
$totalnbofrecord = 0 ;
$data = array ();
if ( $sql ) {
2020-10-31 14:32:18 +01:00
$resql = $db -> query ( $sql );
if ( ! $resql ) {
dol_print_error ( $db );
}
2021-03-01 20:37:16 +01:00
$ifetch = 0 ;
$xi = 0 ;
$oldlabeltouse = '' ;
2020-10-31 14:32:18 +01:00
while ( $obj = $db -> fetch_object ( $resql )) {
$ifetch ++ ;
if ( $useagroupby ) {
$xval = $search_xaxis [ 0 ];
$fieldforxkey = 'x_0' ;
$xlabel = $obj -> $fieldforxkey ;
$xvalwithoutprefix = preg_replace ( '/^[a-z]+\./' , '' , $xval );
// Define $xlabel
if ( ! empty ( $object -> fields [ $xvalwithoutprefix ][ 'arrayofkeyval' ])) {
$xlabel = $object -> fields [ $xvalwithoutprefix ][ 'arrayofkeyval' ][ $obj -> $fieldforxkey ];
}
2022-03-22 13:23:16 +01:00
$labeltouse = (( $xlabel || $xlabel == '0' ) ? dol_trunc ( $xlabel , 20 , 'middle' ) : ( $xlabel === '' ? $langs -> transnoentitiesnoconv ( " Empty " ) : $langs -> transnoentitiesnoconv ( " NotDefined " )));
2020-10-31 14:32:18 +01:00
if ( $oldlabeltouse && ( $labeltouse != $oldlabeltouse )) {
$xi ++ ; // Increase $xi
}
//var_dump($labeltouse.' '.$oldlabeltouse.' '.$xi);
$oldlabeltouse = $labeltouse ;
/* Example of value for $arrayofvaluesforgroupby
2021-02-23 22:03:23 +01:00
* array ( size = 1 )
2020-03-06 20:02:05 +01:00
* 'g_0' =>
* array ( size = 6 )
* 0 => string '0' ( length = 1 )
* '' => string 'Empty' ( length = 5 )
* '__NULL__' => string 'Not defined' ( length = 11 )
* 'done' => string 'done' ( length = 4 )
* 'processing' => string 'processing' ( length = 10 )
* 'undeployed' => string 'undeployed' ( length = 10 )
2021-02-23 22:03:23 +01:00
*/
2020-10-31 14:32:18 +01:00
foreach ( $search_measures as $key => $val ) {
$gi = 0 ;
foreach ( $search_groupby as $gkey ) {
//var_dump('*** Fetch #'.$ifetch.' for labeltouse='.$labeltouse.' measure number '.$key.' and group g_'.$gi);
//var_dump($arrayofvaluesforgroupby);
foreach ( $arrayofvaluesforgroupby [ 'g_' . $gi ] as $gvaluepossiblekey => $gvaluepossiblelabel ) {
$ykeysuffix = $gvaluepossiblelabel ;
$gvalwithoutprefix = preg_replace ( '/^[a-z]+\./' , '' , $gval );
$fieldfory = 'y_' . $key ;
$fieldforg = 'g_' . $gi ;
$fieldforybis = 'y_' . $key . '_' . $ykeysuffix ;
//var_dump('gvaluepossiblekey='.$gvaluepossiblekey.' gvaluepossiblelabel='.$gvaluepossiblelabel.' ykeysuffix='.$ykeysuffix.' gval='.$gval.' gvalwithoutsuffix='.$gvalwithoutprefix);
//var_dump('fieldforg='.$fieldforg.' obj->$fieldforg='.$obj->$fieldforg.' fieldfory='.$fieldfory.' obj->$fieldfory='.$obj->$fieldfory.' fieldforybis='.$fieldforybis);
2021-02-23 22:03:23 +01:00
if ( ! is_array ( $data [ $xi ])) {
$data [ $xi ] = array ();
}
2020-03-06 20:06:56 +01:00
2020-03-12 12:45:44 +01:00
if ( ! array_key_exists ( 'label' , $data [ $xi ])) {
2020-10-31 14:32:18 +01:00
$data [ $xi ] = array ();
$data [ $xi ][ 'label' ] = $labeltouse ;
}
$objfieldforg = $obj -> $fieldforg ;
2021-02-23 22:03:23 +01:00
if ( is_null ( $objfieldforg )) {
$objfieldforg = '__NULL__' ;
}
2020-10-31 14:32:18 +01:00
if ( $gvaluepossiblekey == '0' ) { // $gvaluepossiblekey can have type int or string. So we create a special if, used when value is '0'
//var_dump($objfieldforg.' == \'0\' -> '.($objfieldforg == '0'));
if ( $objfieldforg == '0' ) {
// The record we fetch is for this group
$data [ $xi ][ $fieldforybis ] = $obj -> $fieldfory ;
2021-03-01 20:37:16 +01:00
} elseif ( ! isset ( $data [ $xi ][ $fieldforybis ])) {
// The record we fetch is not for this group
2020-10-31 14:32:18 +01:00
$data [ $xi ][ $fieldforybis ] = '0' ;
}
} else {
//var_dump((string) $objfieldforg.' === '.(string) $gvaluepossiblekey.' -> '.((string) $objfieldforg === (string) $gvaluepossiblekey));
if (( string ) $objfieldforg === ( string ) $gvaluepossiblekey ) {
// The record we fetch is for this group
$data [ $xi ][ $fieldforybis ] = $obj -> $fieldfory ;
2021-03-01 20:37:16 +01:00
} elseif ( ! isset ( $data [ $xi ][ $fieldforybis ])) {
// The record we fetch is not for this group
2020-10-31 14:32:18 +01:00
$data [ $xi ][ $fieldforybis ] = '0' ;
}
}
}
//var_dump($data[$xi]);
$gi ++ ;
}
}
} else { // No group by
$xval = $search_xaxis [ 0 ];
$fieldforxkey = 'x_0' ;
$xlabel = $obj -> $fieldforxkey ;
$xvalwithoutprefix = preg_replace ( '/^[a-z]+\./' , '' , $xval );
// Define $xlabel
if ( ! empty ( $object -> fields [ $xvalwithoutprefix ][ 'arrayofkeyval' ])) {
$xlabel = $object -> fields [ $xvalwithoutprefix ][ 'arrayofkeyval' ][ $obj -> $fieldforxkey ];
}
2023-03-11 01:09:22 +01:00
$labeltouse = (( $xlabel || $xlabel == '0' ) ? dol_trunc ( $xlabel , 20 , 'middle' ) : ( $xlabel === '' ? $langs -> transnoentitiesnoconv ( " Empty " ) : $langs -> transnoentitiesnoconv ( " NotDefined " )));
2020-10-31 14:32:18 +01:00
$xarrayforallseries = array ( 'label' => $labeltouse );
foreach ( $search_measures as $key => $val ) {
$fieldfory = 'y_' . $key ;
$xarrayforallseries [ $fieldfory ] = $obj -> $fieldfory ;
}
$data [ $xi ] = $xarrayforallseries ;
$xi ++ ;
}
}
$totalnbofrecord = count ( $data );
2020-02-07 10:58:17 +01:00
}
2020-03-06 20:02:05 +01:00
//var_dump($data);
2020-02-07 10:58:17 +01:00
2020-02-13 10:44:08 +01:00
print '<div class="customreportsoutput' . ( $totalnbofrecord ? '' : ' customreportsoutputnotdata' ) . '">' ;
2020-02-07 10:58:17 +01:00
if ( $mode == 'grid' ) {
2020-02-07 12:51:08 +01:00
// TODO
2020-02-07 10:58:17 +01:00
}
if ( $mode == 'graph' ) {
2020-10-31 14:32:18 +01:00
$WIDTH = '80%' ;
2023-02-22 03:03:35 +01:00
$HEIGHT = ( empty ( $_SESSION [ 'dol_screenheight' ]) ? 400 : $_SESSION [ 'dol_screenheight' ] - 500 );
2020-10-31 14:32:18 +01:00
// Show graph
$px1 = new DolGraph ();
$mesg = $px1 -> isGraphKo ();
2021-02-23 22:03:23 +01:00
if ( ! $mesg ) {
2022-05-17 14:55:38 +02:00
//var_dump($legend);
//var_dump($data);
2020-10-31 14:32:18 +01:00
$px1 -> SetData ( $data );
unset ( $data );
$arrayoftypes = array ();
foreach ( $search_measures as $key => $val ) {
$arrayoftypes [] = $search_graph ;
}
$px1 -> SetLegend ( $legend );
$px1 -> SetMinValue ( $px1 -> GetFloorMinValue ());
$px1 -> SetMaxValue ( $px1 -> GetCeilMaxValue ());
$px1 -> SetWidth ( $WIDTH );
$px1 -> SetHeight ( $HEIGHT );
$px1 -> SetYLabel ( $langs -> trans ( " Y " ));
$px1 -> SetShading ( 3 );
$px1 -> SetHorizTickIncrement ( 1 );
$px1 -> SetCssPrefix ( " cssboxes " );
$px1 -> SetType ( $arrayoftypes );
$px1 -> mode = 'depth' ;
$px1 -> SetTitle ( '' );
$dir = $conf -> user -> dir_temp ;
dol_mkdir ( $dir );
$filenamenb = $dir . '/customreport_' . $object -> element . '.png' ;
$fileurlnb = DOL_URL_ROOT . '/viewimage.php?modulepart=user&file=customreport_' . $object -> element . '.png' ;
$px1 -> draw ( $filenamenb , $fileurlnb );
$texttoshow = $langs -> trans ( " NoRecordFound " );
if ( ! GETPOSTISSET ( 'search_measures' ) || ! GETPOSTISSET ( 'search_xaxis' )) {
$texttoshow = $langs -> trans ( " SelectYourGraphOptionsFirst " );
}
print $px1 -> show ( $totalnbofrecord ? 0 : $texttoshow );
}
2020-02-07 10:58:17 +01:00
}
if ( $sql ) {
2020-10-31 14:32:18 +01:00
// Show admin info
print '<br>' . info_admin ( $langs -> trans ( " SQLUsedForExport " ) . ':<br> ' . $sql , 0 , 0 , 1 , '' , 'TechnicalInformation' );
2020-02-07 10:58:17 +01:00
}
print '<div>' ;
2021-04-02 13:31:03 +02:00
if ( ! defined ( 'USE_CUSTOM_REPORT_AS_INCLUDE' )) {
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2020-02-11 10:38:09 +01:00
}
2020-02-07 10:58:17 +01:00
// End of page
llxFooter ();
$db -> close ();
2022-02-21 19:09:26 +01:00
/**
* Fill arrayofmesures for an object
*
* @ param mixed $object Any object
* @ param string $tablealias Alias of table
* @ param string $labelofobject Label of object
2024-01-13 19:48:20 +01:00
* @ param array $arrayofmesures Array of measures already filled
2022-02-21 19:09:26 +01:00
* @ param int $level Level
* @ param int $count Count
2023-05-24 03:18:00 +02:00
* @ param string $tablepath Path of all tables ( 't' or 't,contract' or 't,contract,societe' ... )
2024-01-13 19:48:20 +01:00
* @ return array Array of measures
2022-02-21 19:09:26 +01:00
*/
2023-05-24 03:18:00 +02:00
function fillArrayOfMeasures ( $object , $tablealias , $labelofobject , & $arrayofmesures , $level = 0 , & $count = 0 , & $tablepath = '' )
2022-02-21 19:09:26 +01:00
{
global $langs , $extrafields , $db ;
if ( $level > 10 ) { // Protection against infinite loop
return $arrayofmesures ;
}
2023-05-24 03:18:00 +02:00
if ( empty ( $tablepath )) {
$tablepath = $object -> table_element . '=' . $tablealias ;
} else {
$tablepath .= ',' . $object -> table_element . '=' . $tablealias ;
}
2022-02-21 19:09:26 +01:00
if ( $level == 0 ) {
2024-01-13 19:48:20 +01:00
// Add the count of record only for the main/first level object. Parents are necessarily unique for each record.
2022-03-22 13:23:16 +01:00
$arrayofmesures [ $tablealias . '.count' ] = array (
'label' => img_picto ( '' , $object -> picto , 'class="pictofixedwidth"' ) . ' ' . $labelofobject . ': Count' ,
2023-05-24 03:18:00 +02:00
'labelnohtml' => $labelofobject . ': Count' ,
2022-03-22 13:23:16 +01:00
'position' => 0 ,
2023-05-24 03:18:00 +02:00
'table' => $object -> table_element ,
'tablefromt' => $tablepath
2022-03-22 13:23:16 +01:00
);
2022-02-21 19:09:26 +01:00
}
2023-05-24 03:18:00 +02:00
// Note: here $tablealias can be 't' or 't__fk_contract' or 't_fk_contract_fk_soc'
2022-02-21 19:09:26 +01:00
// Add main fields of object
foreach ( $object -> fields as $key => $val ) {
2022-03-01 16:48:29 +01:00
if ( ! empty ( $val [ 'isameasure' ]) && ( ! isset ( $val [ 'enabled' ]) || dol_eval ( $val [ 'enabled' ], 1 , 1 , '1' ))) {
2024-01-12 20:40:34 +01:00
$position = ( empty ( $val [ 'position' ]) ? 0 : intval ( $val [ 'position' ]));
2022-03-22 13:23:16 +01:00
$arrayofmesures [ $tablealias . '.' . $key . '-sum' ] = array (
'label' => img_picto ( '' , $object -> picto , 'class="pictofixedwidth"' ) . ' ' . $labelofobject . ': ' . $langs -> trans ( $val [ 'label' ]) . ' <span class="opacitymedium">(' . $langs -> trans ( " Sum " ) . ')</span>' ,
2023-05-24 03:18:00 +02:00
'labelnohtml' => $labelofobject . ': ' . $langs -> trans ( $val [ 'label' ]),
2022-07-16 02:23:30 +02:00
'position' => ( $position + ( $count * 100000 )) . '.1' ,
2023-05-24 03:18:00 +02:00
'table' => $object -> table_element ,
'tablefromt' => $tablepath
2022-03-22 13:23:16 +01:00
);
$arrayofmesures [ $tablealias . '.' . $key . '-average' ] = array (
'label' => img_picto ( '' , $object -> picto , 'class="pictofixedwidth"' ) . ' ' . $labelofobject . ': ' . $langs -> trans ( $val [ 'label' ]) . ' <span class="opacitymedium">(' . $langs -> trans ( " Average " ) . ')</span>' ,
2023-05-24 03:18:00 +02:00
'labelnohtml' => $labelofobject . ': ' . $langs -> trans ( $val [ 'label' ]),
2022-07-16 02:23:30 +02:00
'position' => ( $position + ( $count * 100000 )) . '.2' ,
2023-05-24 03:18:00 +02:00
'table' => $object -> table_element ,
'tablefromt' => $tablepath
2022-03-22 13:23:16 +01:00
);
$arrayofmesures [ $tablealias . '.' . $key . '-min' ] = array (
'label' => img_picto ( '' , $object -> picto , 'class="pictofixedwidth"' ) . ' ' . $labelofobject . ': ' . $langs -> trans ( $val [ 'label' ]) . ' <span class="opacitymedium">(' . $langs -> trans ( " Minimum " ) . ')</span>' ,
2023-05-24 03:18:00 +02:00
'labelnohtml' => $labelofobject . ': ' . $langs -> trans ( $val [ 'label' ]),
2022-07-16 02:23:30 +02:00
'position' => ( $position + ( $count * 100000 )) . '.3' ,
2023-05-24 03:18:00 +02:00
'table' => $object -> table_element ,
'tablefromt' => $tablepath
2022-03-22 13:23:16 +01:00
);
$arrayofmesures [ $tablealias . '.' . $key . '-max' ] = array (
'label' => img_picto ( '' , $object -> picto , 'class="pictofixedwidth"' ) . ' ' . $labelofobject . ': ' . $langs -> trans ( $val [ 'label' ]) . ' <span class="opacitymedium">(' . $langs -> trans ( " Maximum " ) . ')</span>' ,
2023-05-24 03:18:00 +02:00
'labelnohtml' => $labelofobject . ': ' . $langs -> trans ( $val [ 'label' ]),
2022-07-16 02:23:30 +02:00
'position' => ( $position + ( $count * 100000 )) . '.4' ,
2023-05-24 03:18:00 +02:00
'table' => $object -> table_element ,
'tablefromt' => $tablepath
2022-03-22 13:23:16 +01:00
);
2022-02-21 19:09:26 +01:00
}
}
// Add extrafields to Measures
2023-10-02 08:22:20 +02:00
if ( ! empty ( $object -> isextrafieldmanaged ) && isset ( $extrafields -> attributes [ $object -> table_element ][ 'label' ])) {
2022-02-21 19:09:26 +01:00
foreach ( $extrafields -> attributes [ $object -> table_element ][ 'label' ] as $key => $val ) {
2022-03-01 16:48:29 +01:00
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' ))) {
2022-03-27 11:11:16 +02:00
$position = ( ! empty ( $val [ 'position' ]) ? $val [ 'position' ] : 0 );
2023-05-24 03:18:00 +02:00
$arrayofmesures [ preg_replace ( '/^t/' , 'te' , $tablealias ) . '.' . $key . '-sum' ] = array (
2022-03-22 13:23:16 +01:00
'label' => img_picto ( '' , $object -> picto , 'class="pictofixedwidth"' ) . ' ' . $labelofobject . ': ' . $langs -> trans ( $extrafields -> attributes [ $object -> table_element ][ 'label' ][ $key ]) . ' <span class="opacitymedium">(' . $langs -> trans ( " Sum " ) . ')</span>' ,
2023-05-24 03:18:00 +02:00
'labelnohtml' => $labelofobject . ': ' . $langs -> trans ( $val ),
2022-03-27 11:11:16 +02:00
'position' => ( $position + ( $count * 100000 )) . '.1' ,
2023-05-24 03:18:00 +02:00
'table' => $object -> table_element ,
'tablefromt' => $tablepath
2022-03-22 13:23:16 +01:00
);
2023-05-24 03:18:00 +02:00
$arrayofmesures [ preg_replace ( '/^t/' , 'te' , $tablealias ) . '.' . $key . '-average' ] = array (
2022-03-22 13:23:16 +01:00
'label' => img_picto ( '' , $object -> picto , 'class="pictofixedwidth"' ) . ' ' . $labelofobject . ': ' . $langs -> trans ( $extrafields -> attributes [ $object -> table_element ][ 'label' ][ $key ]) . ' <span class="opacitymedium">(' . $langs -> trans ( " Average " ) . ')</span>' ,
2023-05-24 03:18:00 +02:00
'labelnohtml' => $labelofobject . ': ' . $langs -> trans ( $val ),
2022-03-27 11:11:16 +02:00
'position' => ( $position + ( $count * 100000 )) . '.2' ,
2023-05-24 03:18:00 +02:00
'table' => $object -> table_element ,
'tablefromt' => $tablepath
2022-03-22 13:23:16 +01:00
);
2023-05-24 03:18:00 +02:00
$arrayofmesures [ preg_replace ( '/^t/' , 'te' , $tablealias ) . '.' . $key . '-min' ] = array (
2022-03-22 13:23:16 +01:00
'label' => img_picto ( '' , $object -> picto , 'class="pictofixedwidth"' ) . ' ' . $labelofobject . ': ' . $langs -> trans ( $extrafields -> attributes [ $object -> table_element ][ 'label' ][ $key ]) . ' <span class="opacitymedium">(' . $langs -> trans ( " Minimum " ) . ')</span>' ,
2023-05-24 03:18:00 +02:00
'labelnohtml' => $labelofobject . ': ' . $langs -> trans ( $val ),
2022-03-27 11:11:16 +02:00
'position' => ( $position + ( $count * 100000 )) . '.3' ,
2023-05-24 03:18:00 +02:00
'table' => $object -> table_element ,
'tablefromt' => $tablepath
2022-03-22 13:23:16 +01:00
);
2023-05-24 03:18:00 +02:00
$arrayofmesures [ preg_replace ( '/^t/' , 'te' , $tablealias ) . '.' . $key . '-max' ] = array (
2022-03-22 13:23:16 +01:00
'label' => img_picto ( '' , $object -> picto , 'class="pictofixedwidth"' ) . ' ' . $labelofobject . ': ' . $langs -> trans ( $extrafields -> attributes [ $object -> table_element ][ 'label' ][ $key ]) . ' <span class="opacitymedium">(' . $langs -> trans ( " Maximum " ) . ')</span>' ,
2023-05-24 03:18:00 +02:00
'labelnohtml' => $labelofobject . ': ' . $langs -> trans ( $val ),
2022-03-27 11:11:16 +02:00
'position' => ( $position + ( $count * 100000 )) . '.4' ,
2023-05-24 03:18:00 +02:00
'table' => $object -> table_element ,
'tablefromt' => $tablepath
2022-03-22 13:23:16 +01:00
);
2022-02-21 19:09:26 +01:00
}
}
}
// Add fields for parent objects
foreach ( $object -> fields as $key => $val ) {
if ( preg_match ( '/^[^:]+:[^:]+:/' , $val [ 'type' ])) {
$tmptype = explode ( ':' , $val [ 'type' ], 4 );
2023-05-24 00:19:27 +02:00
if ( $tmptype [ 0 ] == 'integer' && ! empty ( $tmptype [ 1 ]) && ! empty ( $tmptype [ 2 ])) {
2022-02-21 19:09:26 +01:00
$newobject = $tmptype [ 1 ];
dol_include_once ( $tmptype [ 2 ]);
if ( class_exists ( $newobject )) {
$tmpobject = new $newobject ( $db );
2022-03-22 13:23:16 +01:00
//var_dump($key); var_dump($tmpobject->element); var_dump($val['label']); var_dump($tmptype); var_dump('t-'.$key);
2022-02-21 19:09:26 +01:00
$count ++ ;
2023-05-24 03:18:00 +02:00
$arrayofmesures = fillArrayOfMeasures ( $tmpobject , $tablealias . '__' . $key , $langs -> trans ( $val [ 'label' ]), $arrayofmesures , $level + 1 , $count , $tablepath );
2022-02-21 19:09:26 +01:00
} else {
2022-03-22 13:23:16 +01:00
print 'For property ' . $object -> element . '->' . $key . ', type="' . $val [ 'type' ] . '": Failed to find class ' . $newobject . " in file " . $tmptype [ 2 ] . " <br> \n " ;
2022-02-21 19:09:26 +01:00
}
}
}
}
return $arrayofmesures ;
}
/**
* Fill arrayofmesures for an object
*
* @ param mixed $object Any object
2022-03-21 22:02:34 +01:00
* @ param string $tablealias Alias of table ( 't' for example )
2022-02-21 19:09:26 +01:00
* @ param string $labelofobject Label of object
* @ param array $arrayofxaxis Array of xaxis already filled
* @ param int $level Level
* @ param int $count Count
2023-05-24 03:18:00 +02:00
* @ param string $tablepath Path of all tables ( 't' or 't,contract' or 't,contract,societe' ... )
2022-02-21 19:09:26 +01:00
* @ return array Array of xaxis
*/
2023-05-24 03:18:00 +02:00
function fillArrayOfXAxis ( $object , $tablealias , $labelofobject , & $arrayofxaxis , $level = 0 , & $count = 0 , & $tablepath = '' )
2022-02-21 19:09:26 +01:00
{
global $langs , $extrafields , $db ;
2023-05-24 00:24:14 +02:00
if ( $level >= 3 ) { // Limit scan on 2 levels max
2022-02-21 19:09:26 +01:00
return $arrayofxaxis ;
}
2023-05-24 03:18:00 +02:00
if ( empty ( $tablepath )) {
$tablepath = $object -> table_element . '=' . $tablealias ;
} else {
$tablepath .= ',' . $object -> table_element . '=' . $tablealias ;
}
2022-02-21 19:09:26 +01:00
$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 );
$MM = substr ( $langs -> trans ( " Month " ), 0 , 1 ) . substr ( $langs -> trans ( " Month " ), 0 , 1 );
$DD = substr ( $langs -> trans ( " Day " ), 0 , 1 ) . substr ( $langs -> trans ( " Day " ), 0 , 1 );
$HH = substr ( $langs -> trans ( " Hour " ), 0 , 1 ) . substr ( $langs -> trans ( " Hour " ), 0 , 1 );
$MI = substr ( $langs -> trans ( " Minute " ), 0 , 1 ) . substr ( $langs -> trans ( " Minute " ), 0 , 1 );
$SS = substr ( $langs -> trans ( " Second " ), 0 , 1 ) . substr ( $langs -> trans ( " Second " ), 0 , 1 );
2023-05-24 00:19:27 +02:00
/* if ( $level > 0 ) {
var_dump ( $object -> element . ' ' . $object -> isextrafieldmanaged );
} */
2023-05-24 03:18:00 +02:00
// Note: here $tablealias can be 't' or 't__fk_contract' or 't_fk_contract_fk_soc'
2022-02-21 19:09:26 +01:00
// Add main fields of object
foreach ( $object -> fields as $key => $val ) {
if ( empty ( $val [ 'measure' ])) {
if ( in_array ( $key , array (
2022-09-23 09:35:17 +02:00
'id' , 'ref_ext' , 'rowid' , 'entity' , 'last_main_doc' , 'logo' , 'logo_squarred' , 'extraparams' ,
2022-02-21 19:09:26 +01:00
'parent' , 'photo' , 'socialnetworks' , 'webservices_url' , 'webservices_key' ))) {
continue ;
}
2022-03-01 16:48:29 +01:00
if ( isset ( $val [ 'enabled' ]) && ! dol_eval ( $val [ 'enabled' ], 1 , 1 , '1' )) {
2022-02-21 19:09:26 +01:00
continue ;
}
2022-03-01 16:48:29 +01:00
if ( isset ( $val [ 'visible' ]) && ! dol_eval ( $val [ 'visible' ], 1 , 1 , '1' )) {
2022-02-21 19:09:26 +01:00
continue ;
}
if ( preg_match ( '/^fk_/' , $key ) && ! preg_match ( '/^fk_statu/' , $key )) {
continue ;
}
if ( preg_match ( '/^pass/' , $key )) {
continue ;
}
if ( in_array ( $val [ 'type' ], array ( 'html' , 'text' ))) {
continue ;
}
if ( in_array ( $val [ 'type' ], array ( 'timestamp' , 'date' , 'datetime' ))) {
2024-01-12 20:40:34 +01:00
$position = ( empty ( $val [ 'position' ]) ? 0 : intval ( $val [ 'position' ]));
2022-03-21 22:02:34 +01:00
$arrayofxaxis [ $tablealias . '.' . $key . '-year' ] = array (
'label' => img_picto ( '' , $object -> picto , 'class="pictofixedwidth"' ) . ' ' . $labelofobject . ': ' . $langs -> trans ( $val [ 'label' ]) . ' <span class="opacitymedium">(' . $YYYY . ')</span>' ,
2023-05-24 03:18:00 +02:00
'labelnohtml' => $labelofobject . ': ' . $langs -> trans ( $val [ 'label' ]),
2022-07-16 02:23:30 +02:00
'position' => ( $position + ( $count * 100000 )) . '.1' ,
2023-05-24 03:18:00 +02:00
'table' => $object -> table_element ,
'tablefromt' => $tablepath
2022-03-21 22:02:34 +01:00
);
$arrayofxaxis [ $tablealias . '.' . $key . '-month' ] = array (
'label' => img_picto ( '' , $object -> picto , 'class="pictofixedwidth"' ) . ' ' . $labelofobject . ': ' . $langs -> trans ( $val [ 'label' ]) . ' <span class="opacitymedium">(' . $YYYY . '-' . $MM . ')</span>' ,
2023-05-24 03:18:00 +02:00
'labelnohtml' => $labelofobject . ': ' . $langs -> trans ( $val [ 'label' ]),
2022-07-16 02:23:30 +02:00
'position' => ( $position + ( $count * 100000 )) . '.2' ,
2023-05-24 03:18:00 +02:00
'table' => $object -> table_element ,
'tablefromt' => $tablepath
2022-03-21 22:02:34 +01:00
);
$arrayofxaxis [ $tablealias . '.' . $key . '-day' ] = array (
'label' => img_picto ( '' , $object -> picto , 'class="pictofixedwidth"' ) . ' ' . $labelofobject . ': ' . $langs -> trans ( $val [ 'label' ]) . ' <span class="opacitymedium">(' . $YYYY . '-' . $MM . '-' . $DD . ')</span>' ,
2023-05-24 03:18:00 +02:00
'labelnohtml' => $labelofobject . ': ' . $langs -> trans ( $val [ 'label' ]),
2022-07-16 02:23:30 +02:00
'position' => ( $position + ( $count * 100000 )) . '.3' ,
2023-05-24 03:18:00 +02:00
'table' => $object -> table_element ,
'tablefromt' => $tablepath
2022-03-21 22:02:34 +01:00
);
2022-02-21 19:09:26 +01:00
} else {
2024-01-12 20:40:34 +01:00
$position = ( empty ( $val [ 'position' ]) ? 0 : intval ( $val [ 'position' ]));
2022-03-21 22:02:34 +01:00
$arrayofxaxis [ $tablealias . '.' . $key ] = array (
'label' => img_picto ( '' , $object -> picto , 'class="pictofixedwidth"' ) . ' ' . $labelofobject . ': ' . $langs -> trans ( $val [ 'label' ]),
2023-05-24 03:18:00 +02:00
'labelnohtml' => $labelofobject . ': ' . $langs -> trans ( $val [ 'label' ]),
2022-07-16 02:23:30 +02:00
'position' => ( $position + ( $count * 100000 )),
2023-05-24 03:18:00 +02:00
'table' => $object -> table_element ,
'tablefromt' => $tablepath
2022-03-21 22:02:34 +01:00
);
2022-02-21 19:09:26 +01:00
}
}
}
2022-03-21 22:02:34 +01:00
2022-02-21 19:09:26 +01:00
// Add extrafields to X-Axis
2023-10-02 08:22:20 +02:00
if ( ! empty ( $object -> isextrafieldmanaged ) && isset ( $extrafields -> attributes [ $object -> table_element ][ 'label' ])) {
2022-02-21 19:09:26 +01:00
foreach ( $extrafields -> attributes [ $object -> table_element ][ 'label' ] as $key => $val ) {
if ( $extrafields -> attributes [ $object -> table_element ][ 'type' ][ $key ] == 'separate' ) {
continue ;
}
if ( ! empty ( $extrafields -> attributes [ $object -> table_element ][ 'totalizable' ][ $key ])) {
continue ;
}
2023-05-24 03:18:00 +02:00
2023-05-24 00:19:27 +02:00
if ( in_array ( $extrafields -> attributes [ $object -> table_element ][ 'type' ][ $key ], array ( 'timestamp' , 'date' , 'datetime' ))) {
2024-01-12 20:40:34 +01:00
$position = ( empty ( $extrafields -> attributes [ $object -> table_element ][ 'pos' ][ $key ]) ? 0 : intval ( $extrafields -> attributes [ $object -> table_element ][ 'pos' ][ $key ]));
2023-05-24 03:18:00 +02:00
$arrayofxaxis [ preg_replace ( '/^t/' , 'te' , $tablealias ) . '.' . $key . '-year' ] = array (
2023-05-24 00:19:27 +02:00
'label' => img_picto ( '' , $object -> picto , 'class="pictofixedwidth"' ) . ' ' . $labelofobject . ': ' . $langs -> trans ( $val ) . ' <span class="opacitymedium">(' . $YYYY . ')</span>' ,
2023-05-24 03:18:00 +02:00
'labelnohtml' => $labelofobject . ': ' . $langs -> trans ( $val ),
2023-05-24 00:19:27 +02:00
'position' => ( $position + ( $count * 100000 )) . '.1' ,
2023-05-24 03:18:00 +02:00
'table' => $object -> table_element ,
'tablefromt' => $tablepath
2023-05-24 00:19:27 +02:00
);
2023-05-24 03:18:00 +02:00
$arrayofxaxis [ preg_replace ( '/^t/' , 'te' , $tablealias ) . '.' . $key . '-month' ] = array (
2023-05-24 00:19:27 +02:00
'label' => img_picto ( '' , $object -> picto , 'class="pictofixedwidth"' ) . ' ' . $labelofobject . ': ' . $langs -> trans ( $val ) . ' <span class="opacitymedium">(' . $YYYY . '-' . $MM . ')</span>' ,
2023-05-24 03:18:00 +02:00
'labelnohtml' => $labelofobject . ': ' . $langs -> trans ( $val ),
2023-05-24 00:19:27 +02:00
'position' => ( $position + ( $count * 100000 )) . '.2' ,
2023-05-24 03:18:00 +02:00
'table' => $object -> table_element ,
'tablefromt' => $tablepath
2023-05-24 00:19:27 +02:00
);
2023-05-24 03:18:00 +02:00
$arrayofxaxis [ preg_replace ( '/^t/' , 'te' , $tablealias ) . '.' . $key . '-day' ] = array (
2023-05-24 00:19:27 +02:00
'label' => img_picto ( '' , $object -> picto , 'class="pictofixedwidth"' ) . ' ' . $labelofobject . ': ' . $langs -> trans ( $val ) . ' <span class="opacitymedium">(' . $YYYY . '-' . $MM . '-' . $DD . ')</span>' ,
2023-05-24 03:18:00 +02:00
'labelnohtml' => $labelofobject . ': ' . $langs -> trans ( $val ),
2023-05-24 00:19:27 +02:00
'position' => ( $position + ( $count * 100000 )) . '.3' ,
2023-05-24 03:18:00 +02:00
'table' => $object -> table_element ,
'tablefromt' => $tablepath
2023-05-24 00:19:27 +02:00
);
} else {
2023-05-24 03:18:00 +02:00
$arrayofxaxis [ preg_replace ( '/^t/' , 'te' , $tablealias ) . '.' . $key ] = array (
2023-05-24 00:19:27 +02:00
'label' => img_picto ( '' , $object -> picto , 'class="pictofixedwidth"' ) . ' ' . $labelofobject . ': ' . $langs -> trans ( $val ),
2023-05-24 03:18:00 +02:00
'labelnohtml' => $labelofobject . ': ' . $langs -> trans ( $val ),
2023-05-24 00:19:27 +02:00
'position' => 1000 + ( int ) $extrafields -> attributes [ $object -> table_element ][ 'pos' ][ $key ] + ( $count * 100000 ),
2023-05-24 03:18:00 +02:00
'table' => $object -> table_element ,
'tablefromt' => $tablepath
2023-05-24 00:19:27 +02:00
);
}
2022-02-21 19:09:26 +01:00
}
}
2022-03-21 22:02:34 +01:00
2022-02-21 19:09:26 +01:00
// Add fields for parent objects
foreach ( $object -> fields as $key => $val ) {
if ( preg_match ( '/^[^:]+:[^:]+:/' , $val [ 'type' ])) {
$tmptype = explode ( ':' , $val [ 'type' ], 4 );
2022-03-22 13:23:16 +01:00
if ( $tmptype [ 0 ] == 'integer' && $tmptype [ 1 ] && $tmptype [ 2 ]) {
2022-02-21 19:09:26 +01:00
$newobject = $tmptype [ 1 ];
dol_include_once ( $tmptype [ 2 ]);
if ( class_exists ( $newobject )) {
$tmpobject = new $newobject ( $db );
2022-03-21 22:02:34 +01:00
//var_dump($key); var_dump($tmpobject->element); var_dump($val['label']); var_dump($tmptype); var_dump('t-'.$key);
2022-02-21 19:09:26 +01:00
$count ++ ;
2023-05-24 03:18:00 +02:00
$arrayofxaxis = fillArrayOfXAxis ( $tmpobject , $tablealias . '__' . $key , $langs -> trans ( $val [ 'label' ]), $arrayofxaxis , $level + 1 , $count , $tablepath );
2022-02-21 19:09:26 +01:00
} else {
2022-03-22 13:23:16 +01:00
print 'For property ' . $object -> element . '->' . $key . ', type="' . $val [ 'type' ] . '": Failed to find class ' . $newobject . " in file " . $tmptype [ 2 ] . " <br> \n " ;
2022-02-21 19:09:26 +01:00
}
}
}
}
return $arrayofxaxis ;
}
/**
* Fill arrayofgrupby for an object
*
* @ param mixed $object Any object
* @ param string $tablealias Alias of table
* @ param string $labelofobject Label of object
* @ param array $arrayofgroupby Array of groupby already filled
* @ param int $level Level
* @ param int $count Count
2023-05-24 03:18:00 +02:00
* @ param string $tablepath Path of all tables ( 't' or 't,contract' or 't,contract,societe' ... )
2022-02-21 19:09:26 +01:00
* @ return array Array of groupby
*/
2023-05-24 03:18:00 +02:00
function fillArrayOfGroupBy ( $object , $tablealias , $labelofobject , & $arrayofgroupby , $level = 0 , & $count = 0 , & $tablepath = '' )
2022-02-21 19:09:26 +01:00
{
global $langs , $extrafields , $db ;
2023-05-24 03:18:00 +02:00
if ( $level >= 3 ) {
2022-02-21 19:09:26 +01:00
return $arrayofgroupby ;
}
2023-05-24 03:18:00 +02:00
if ( empty ( $tablepath )) {
$tablepath = $object -> table_element . '=' . $tablealias ;
} else {
$tablepath .= ',' . $object -> table_element . '=' . $tablealias ;
2022-02-21 19:09:26 +01:00
}
$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 );
$MM = substr ( $langs -> trans ( " Month " ), 0 , 1 ) . substr ( $langs -> trans ( " Month " ), 0 , 1 );
$DD = substr ( $langs -> trans ( " Day " ), 0 , 1 ) . substr ( $langs -> trans ( " Day " ), 0 , 1 );
$HH = substr ( $langs -> trans ( " Hour " ), 0 , 1 ) . substr ( $langs -> trans ( " Hour " ), 0 , 1 );
$MI = substr ( $langs -> trans ( " Minute " ), 0 , 1 ) . substr ( $langs -> trans ( " Minute " ), 0 , 1 );
$SS = substr ( $langs -> trans ( " Second " ), 0 , 1 ) . substr ( $langs -> trans ( " Second " ), 0 , 1 );
2023-05-24 03:18:00 +02:00
// Note: here $tablealias can be 't' or 't__fk_contract' or 't_fk_contract_fk_soc'
2022-02-21 19:09:26 +01:00
// Add main fields of object
foreach ( $object -> fields as $key => $val ) {
2022-07-16 02:23:30 +02:00
if ( empty ( $val [ 'isameasure' ])) {
2022-02-21 19:09:26 +01:00
if ( in_array ( $key , array (
2022-09-23 09:35:17 +02:00
'id' , 'ref_ext' , 'rowid' , 'entity' , 'last_main_doc' , 'logo' , 'logo_squarred' , 'extraparams' ,
2022-02-21 19:09:26 +01:00
'parent' , 'photo' , 'socialnetworks' , 'webservices_url' , 'webservices_key' ))) {
continue ;
}
2022-03-01 16:48:29 +01:00
if ( isset ( $val [ 'enabled' ]) && ! dol_eval ( $val [ 'enabled' ], 1 , 1 , '1' )) {
2022-02-21 19:09:26 +01:00
continue ;
}
2022-03-01 16:48:29 +01:00
if ( isset ( $val [ 'visible' ]) && ! dol_eval ( $val [ 'visible' ], 1 , 1 , '1' )) {
2022-02-21 19:09:26 +01:00
continue ;
}
if ( preg_match ( '/^fk_/' , $key ) && ! preg_match ( '/^fk_statu/' , $key )) {
continue ;
}
if ( preg_match ( '/^pass/' , $key )) {
continue ;
}
if ( in_array ( $val [ 'type' ], array ( 'html' , 'text' ))) {
continue ;
}
if ( in_array ( $val [ 'type' ], array ( 'timestamp' , 'date' , 'datetime' ))) {
2024-01-12 20:40:34 +01:00
$position = ( empty ( $val [ 'position' ]) ? 0 : intval ( $val [ 'position' ]));
2022-03-22 11:47:25 +01:00
$arrayofgroupby [ $tablealias . '.' . $key . '-year' ] = array (
2023-05-24 03:18:00 +02:00
'label' => img_picto ( '' , $object -> picto , 'class="pictofixedwidth"' ) . ' ' . $labelofobject . ': ' . $langs -> trans ( $val [ 'label' ]) . ' <span class="opacitymedium">(' . $YYYY . ')</span>' ,
'labelnohtml' => $labelofobject . ': ' . $langs -> trans ( $val [ 'label' ]),
'position' => ( $position + ( $count * 100000 )) . '.1' ,
'table' => $object -> table_element ,
'tablefromt' => $tablepath
2022-03-22 11:47:25 +01:00
);
$arrayofgroupby [ $tablealias . '.' . $key . '-month' ] = array (
2023-05-24 03:18:00 +02:00
'label' => img_picto ( '' , $object -> picto , 'class="pictofixedwidth"' ) . ' ' . $labelofobject . ': ' . $langs -> trans ( $val [ 'label' ]) . ' <span class="opacitymedium">(' . $YYYY . '-' . $MM . ')</span>' ,
'labelnohtml' => $labelofobject . ': ' . $langs -> trans ( $val [ 'label' ]),
'position' => ( $position + ( $count * 100000 )) . '.2' ,
'table' => $object -> table_element ,
'tablefromt' => $tablepath
2022-03-22 11:47:25 +01:00
);
$arrayofgroupby [ $tablealias . '.' . $key . '-day' ] = array (
2023-05-24 03:18:00 +02:00
'label' => img_picto ( '' , $object -> picto , 'class="pictofixedwidth"' ) . ' ' . $labelofobject . ': ' . $langs -> trans ( $val [ 'label' ]) . ' <span class="opacitymedium">(' . $YYYY . '-' . $MM . '-' . $DD . ')</span>' ,
'labelnohtml' => $labelofobject . ': ' . $langs -> trans ( $val [ 'label' ]),
'position' => ( $position + ( $count * 100000 )) . '.3' ,
'table' => $object -> table_element ,
'tablefromt' => $tablepath
2022-03-22 11:47:25 +01:00
);
2022-02-21 19:09:26 +01:00
} else {
2024-01-12 20:40:34 +01:00
$position = ( empty ( $val [ 'position' ]) ? 0 : intval ( $val [ 'position' ]));
2022-03-22 11:47:25 +01:00
$arrayofgroupby [ $tablealias . '.' . $key ] = array (
2023-05-24 03:18:00 +02:00
'label' => img_picto ( '' , $object -> picto , 'class="pictofixedwidth"' ) . ' ' . $labelofobject . ': ' . $langs -> trans ( $val [ 'label' ]),
'labelnohtml' => $labelofobject . ': ' . $langs -> trans ( $val [ 'label' ]),
'position' => ( $position + ( $count * 100000 )),
'table' => $object -> table_element ,
'tablefromt' => $tablepath
2022-03-22 11:47:25 +01:00
);
2022-02-21 19:09:26 +01:00
}
}
}
2022-03-22 11:47:25 +01:00
2022-02-21 19:09:26 +01:00
// Add extrafields to Group by
2023-10-02 08:22:20 +02:00
if ( ! empty ( $object -> isextrafieldmanaged ) && isset ( $extrafields -> attributes [ $object -> table_element ][ 'label' ])) {
2022-02-21 19:09:26 +01:00
foreach ( $extrafields -> attributes [ $object -> table_element ][ 'label' ] as $key => $val ) {
if ( $extrafields -> attributes [ $object -> table_element ][ 'type' ][ $key ] == 'separate' ) {
continue ;
}
if ( ! empty ( $extrafields -> attributes [ $object -> table_element ][ 'totalizable' ][ $key ])) {
continue ;
}
2023-05-24 03:18:00 +02:00
if ( in_array ( $extrafields -> attributes [ $object -> table_element ][ 'type' ][ $key ], array ( 'timestamp' , 'date' , 'datetime' ))) {
2024-01-12 20:40:34 +01:00
$position = ( empty ( $extrafields -> attributes [ $object -> table_element ][ 'pos' ][ $key ]) ? 0 : intval ( $extrafields -> attributes [ $object -> table_element ][ 'pos' ][ $key ]));
2023-05-24 03:18:00 +02:00
$arrayofgroupby [ preg_replace ( '/^t/' , 'te' , $tablealias ) . '.' . $key . '-year' ] = array (
'label' => img_picto ( '' , $object -> picto , 'class="pictofixedwidth"' ) . ' ' . $labelofobject . ': ' . $langs -> trans ( $val ) . ' <span class="opacitymedium">(' . $YYYY . ')</span>' ,
'labelnohtml' => $labelofobject . ': ' . $langs -> trans ( $val ),
'position' => ( $position + ( $count * 100000 )) . '.1' ,
'table' => $object -> table_element ,
'tablefromt' => $tablepath
);
$arrayofgroupby [ preg_replace ( '/^t/' , 'te' , $tablealias ) . '.' . $key . '-month' ] = array (
'label' => img_picto ( '' , $object -> picto , 'class="pictofixedwidth"' ) . ' ' . $labelofobject . ': ' . $langs -> trans ( $val ) . ' <span class="opacitymedium">(' . $YYYY . '-' . $MM . ')</span>' ,
'labelnohtml' => $labelofobject . ': ' . $langs -> trans ( $val ),
'position' => ( $position + ( $count * 100000 )) . '.2' ,
'table' => $object -> table_element ,
'tablefromt' => $tablepath
);
$arrayofgroupby [ preg_replace ( '/^t/' , 'te' , $tablealias ) . '.' . $key . '-day' ] = array (
'label' => img_picto ( '' , $object -> picto , 'class="pictofixedwidth"' ) . ' ' . $labelofobject . ': ' . $langs -> trans ( $val ) . ' <span class="opacitymedium">(' . $YYYY . '-' . $MM . '-' . $DD . ')</span>' ,
'labelnohtml' => $labelofobject . ': ' . $langs -> trans ( $val ),
'position' => ( $position + ( $count * 100000 )) . '.3' ,
'table' => $object -> table_element ,
'tablefromt' => $tablepath
);
} else {
$arrayofgroupby [ preg_replace ( '/^t/' , 'te' , $tablealias ) . '.' . $key ] = array (
'label' => img_picto ( '' , $object -> picto , 'class="pictofixedwidth"' ) . ' ' . $labelofobject . ': ' . $langs -> trans ( $val ),
'labelnohtml' => $labelofobject . ': ' . $langs -> trans ( $val ),
'position' => 1000 + ( int ) $extrafields -> attributes [ $object -> table_element ][ 'pos' ][ $key ] + ( $count * 100000 ),
'table' => $object -> table_element ,
'tablefromt' => $tablepath
);
}
2022-02-21 19:09:26 +01:00
}
}
2022-03-22 11:47:25 +01:00
2022-02-21 19:09:26 +01:00
// Add fields for parent objects
foreach ( $object -> fields as $key => $val ) {
if ( preg_match ( '/^[^:]+:[^:]+:/' , $val [ 'type' ])) {
$tmptype = explode ( ':' , $val [ 'type' ], 4 );
2022-03-22 13:23:16 +01:00
if ( $tmptype [ 0 ] == 'integer' && $tmptype [ 1 ] && $tmptype [ 2 ]) {
2022-02-21 19:09:26 +01:00
$newobject = $tmptype [ 1 ];
dol_include_once ( $tmptype [ 2 ]);
if ( class_exists ( $newobject )) {
$tmpobject = new $newobject ( $db );
2022-03-22 11:47:25 +01:00
//var_dump($key); var_dump($tmpobject->element); var_dump($val['label']); var_dump($tmptype); var_dump('t-'.$key);
2022-02-21 19:09:26 +01:00
$count ++ ;
2023-05-24 03:18:00 +02:00
$arrayofgroupby = fillArrayOfGroupBy ( $tmpobject , $tablealias . '__' . $key , $langs -> trans ( $val [ 'label' ]), $arrayofgroupby , $level + 1 , $count , $tablepath );
2022-02-21 19:09:26 +01:00
} else {
2022-03-22 13:23:16 +01:00
print 'For property ' . $object -> element . '->' . $key . ', type="' . $val [ 'type' ] . '": Failed to find class ' . $newobject . " in file " . $tmptype [ 2 ] . " <br> \n " ;
2022-02-21 19:09:26 +01:00
}
}
}
}
return $arrayofgroupby ;
}