2017-10-20 18:44:03 +02:00
< ? php
/* Copyright ( C ) 2001 - 2007 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2005 Brice Davoleau < brice . davoleau @ gmail . com >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ inodbox . com >
2017-10-20 18:44:03 +02:00
* Copyright ( C ) 2006 - 2015 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) 2007 Patrick Raguin < patrick . raguin @ gmail . com >
* Copyright ( C ) 2010 Juanjo Menent < jmenent @ 2 byte . es >
* Copyright ( C ) 2015 Marcos García < marcosgdf @ gmail . com >
2018-04-20 10:38:16 +02:00
* Copyright ( C ) 2018 Ferran Marcet < fmarcet @ 2 byte . es >
2017-10-20 18:44:03 +02: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
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2017-10-20 18:44:03 +02:00
*/
/**
* \file htdocs / societe / website . php
2017-10-20 21:39:19 +02:00
* \ingroup website
2017-10-20 18:44:03 +02:00
* \brief Page of web sites accounts
*/
require '../main.inc.php' ;
require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php' ;
2017-10-20 21:39:19 +02:00
require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php' ;
2018-07-05 02:31:49 +02:00
require_once DOL_DOCUMENT_ROOT . '/societe/class/societeaccount.class.php' ;
2017-10-20 18:44:03 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php' ;
2017-10-20 21:39:19 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php' ;
2019-11-12 09:46:08 +01:00
$langs -> loadLangs ( array ( " companies " , " website " ));
2017-10-20 18:44:03 +02:00
2019-11-12 09:46:08 +01:00
$action = GETPOST ( 'action' , 'aZ09' ) ? GETPOST ( 'action' , 'aZ09' ) : 'view' ; // The action 'add', 'create', 'edit', 'update', 'view', ...
2019-05-15 18:59:46 +02:00
$show_files = GETPOST ( 'show_files' , 'int' );
2020-09-25 10:27:30 +02:00
$contextpage = GETPOST ( 'contextpage' , 'aZ' ) ? GETPOST ( 'contextpage' , 'aZ' ) : 'websitelist' ; // To manage different context of search
2019-11-12 09:46:08 +01:00
$backtopage = GETPOST ( 'backtopage' , 'alpha' ); // Go back to a dedicated page
$optioncss = GETPOST ( 'optioncss' , 'aZ' ); // Option for the css output (always '' except when 'print')
2019-05-15 18:59:46 +02:00
2017-10-20 18:44:03 +02:00
// Security check
2019-11-12 09:46:08 +01:00
$id = GETPOST ( 'id' , 'int' ) ? GETPOST ( 'id' , 'int' ) : GETPOST ( 'socid' , 'int' );
2021-02-26 21:17:52 +01:00
if ( $user -> socid ) {
$socid = $user -> socid ;
}
2017-10-20 18:44:03 +02:00
$result = restrictedArea ( $user , 'societe' , $socid , '&societe' );
2019-11-12 09:46:08 +01:00
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
2022-01-13 11:09:37 +01:00
$sortfield = GETPOST ( 'sortfield' , 'aZ09comma' );
$sortorder = GETPOST ( 'sortorder' , 'aZ09comma' );
2020-03-13 13:07:11 +01:00
$page = GETPOSTISSET ( 'pageplusone' ) ? ( GETPOST ( 'pageplusone' ) - 1 ) : GETPOST ( " page " , 'int' );
2021-02-26 21:17:52 +01:00
if ( empty ( $page ) || $page == - 1 ) {
$page = 0 ;
} // If $page is not defined, or '' or -1
2017-10-20 18:44:03 +02:00
$offset = $limit * $page ;
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
2021-02-26 21:17:52 +01:00
if ( ! $sortfield ) {
$sortfield = 't.login' ;
}
if ( ! $sortorder ) {
$sortorder = 'ASC' ;
}
2017-10-20 18:44:03 +02:00
2017-10-20 23:48:42 +02:00
// Initialize technical objects
2019-11-12 09:46:08 +01:00
$object = new Societe ( $db );
$objectwebsiteaccount = new SocieteAccount ( $db );
2017-10-20 23:48:42 +02:00
$extrafields = new ExtraFields ( $db );
2019-11-12 09:46:08 +01:00
$diroutputmassaction = $conf -> website -> dir_output . '/temp/massgeneration/' . $user -> id ;
$hookmanager -> initHooks ( array ( 'websitethirdpartylist' )); // Note that conf->hooks_modules contains array
2019-10-06 14:41:52 +02:00
2017-10-20 23:48:42 +02:00
// Fetch optionals attributes and labels
2019-10-06 14:41:52 +02:00
$extrafields -> fetch_name_optionals_label ( $objectwebsiteaccount -> table_element );
2019-11-12 09:46:08 +01:00
$search_array_options = $extrafields -> getOptionalsFromPost ( $objectwebsiteaccount -> table_element , '' , 'search_' );
2017-10-20 23:48:42 +02:00
2019-11-12 09:46:08 +01:00
unset ( $objectwebsiteaccount -> fields [ 'fk_soc' ]); // Remove this field, we are already on the thirdparty
2017-10-20 23:48:42 +02:00
// Initialize array of search criterias
2020-08-28 21:27:50 +02:00
$search_all = GETPOST ( " search_all " , 'alpha' );
2019-11-12 09:46:08 +01:00
$search = array ();
2021-02-26 21:17:52 +01:00
foreach ( $objectwebsiteaccount -> fields as $key => $val ) {
if ( GETPOST ( 'search_' . $key , 'alpha' )) {
$search [ $key ] = GETPOST ( 'search_' . $key , 'alpha' );
}
2017-10-20 23:48:42 +02:00
}
// List of fields to search into when doing a "search in all"
$fieldstosearchall = array ();
2021-02-26 21:17:52 +01:00
foreach ( $objectwebsiteaccount -> fields as $key => $val ) {
2021-06-14 01:55:58 +02:00
if ( ! empty ( $val [ 'searchall' ])) {
2021-02-26 21:17:52 +01:00
$fieldstosearchall [ 't.' . $key ] = $val [ 'label' ];
}
2017-10-20 23:48:42 +02:00
}
// Definition of fields for list
2019-11-12 09:46:08 +01:00
$arrayfields = array ();
2021-02-26 21:17:52 +01:00
foreach ( $objectwebsiteaccount -> fields as $key => $val ) {
2017-10-20 23:48:42 +02:00
// If $val['visible']==0, then we never show the field
2021-02-26 21:17:52 +01:00
if ( ! empty ( $val [ 'visible' ])) {
$arrayfields [ 't.' . $key ] = array ( 'label' => $val [ 'label' ], 'checked' => (( $val [ 'visible' ] < 0 ) ? 0 : 1 ), 'enabled' => $val [ 'enabled' ]);
}
2017-10-20 23:48:42 +02:00
}
2017-10-25 22:23:54 +02:00
2017-10-20 23:48:42 +02:00
// Extra fields
2020-12-23 19:14:47 +01:00
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_array_fields.tpl.php' ;
2019-09-02 03:58:00 +02:00
$object -> fields = dol_sort_array ( $object -> fields , 'position' );
$arrayfields = dol_sort_array ( $arrayfields , 'position' );
2017-10-20 23:48:42 +02:00
2021-02-26 21:17:52 +01:00
if ( $id > 0 ) {
2017-10-20 23:48:42 +02:00
$result = $object -> fetch ( $id );
}
2017-10-20 18:44:03 +02:00
/*
* Actions
*/
2019-11-12 09:46:08 +01:00
$parameters = array ( 'id' => $socid );
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2021-02-26 21:17:52 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
2017-10-20 18:44:03 +02:00
2021-02-26 21:17:52 +01:00
if ( empty ( $reshook )) {
2020-10-31 14:32:18 +01:00
// Cancel
2021-02-26 21:17:52 +01:00
if ( GETPOST ( 'cancel' , 'alpha' ) && ! empty ( $backtopage )) {
2020-10-31 14:32:18 +01:00
header ( " Location: " . $backtopage );
exit ;
}
// Selection of new fields
include DOL_DOCUMENT_ROOT . '/core/actions_changeselectedfields.inc.php' ;
// Purge search criteria
2021-02-26 21:17:52 +01:00
if ( GETPOST ( 'button_removefilter_x' , 'alpha' ) || GETPOST ( 'button_removefilter.x' , 'alpha' ) || GETPOST ( 'button_removefilter' , 'alpha' )) { // All tests are required to be compatible with all browsers
foreach ( $objectwebsiteaccount -> fields as $key => $val ) {
2020-10-31 14:32:18 +01:00
$search [ $key ] = '' ;
}
2022-05-08 18:25:22 +02:00
$toselect = array ();
2020-10-31 14:32:18 +01:00
$search_array_options = array ();
}
if ( GETPOST ( 'button_removefilter_x' , 'alpha' ) || GETPOST ( 'button_removefilter.x' , 'alpha' ) || GETPOST ( 'button_removefilter' , 'alpha' )
2021-02-26 21:17:52 +01:00
|| GETPOST ( 'button_search_x' , 'alpha' ) || GETPOST ( 'button_search.x' , 'alpha' ) || GETPOST ( 'button_search' , 'alpha' )) {
2020-10-31 14:32:18 +01:00
$massaction = '' ; // Protection to avoid mass action if we force a new search during a mass action confirmation
}
// Mass actions
$objectclass = 'WebsiteAccount' ;
$objectlabel = 'WebsiteAccount' ;
$permissiontoread = $user -> rights -> societe -> lire ;
$permissiontodelete = $user -> rights -> societe -> supprimer ;
2021-12-02 15:10:29 +01:00
$uploaddir = $conf -> societe -> multidir_output [ $object -> entity ];
2020-10-31 14:32:18 +01:00
include DOL_DOCUMENT_ROOT . '/core/actions_massactions.inc.php' ;
2017-10-20 18:44:03 +02:00
}
/*
* View
*/
$contactstatic = new Contact ( $db );
$form = new Form ( $db );
2017-10-20 21:39:19 +02:00
$langs -> load ( " companies " );
2017-10-20 18:44:03 +02:00
2017-10-20 23:48:42 +02:00
$title = $langs -> trans ( " WebsiteAccounts " );
2017-10-20 21:39:19 +02:00
llxHeader ( '' , $title );
2017-10-20 18:44:03 +02:00
2019-11-12 09:46:08 +01:00
$param = '' ;
2021-02-26 21:17:52 +01:00
if ( ! empty ( $contextpage ) && $contextpage != $_SERVER [ " PHP_SELF " ]) {
$param .= '&contextpage=' . urlencode ( $contextpage );
}
if ( $id > 0 ) {
$param .= '&id=' . urlencode ( $id );
}
if ( $limit > 0 && $limit != $conf -> liste_limit ) {
$param .= '&limit=' . urlencode ( $limit );
}
foreach ( $search as $key => $val ) {
2019-11-12 09:46:08 +01:00
$param .= '&search_' . $key . '=' . urlencode ( $search [ $key ]);
2017-10-20 23:48:42 +02:00
}
2021-02-26 21:17:52 +01:00
if ( $optioncss != '' ) {
$param .= '&optioncss=' . urlencode ( $optioncss );
}
2017-10-20 23:48:42 +02:00
// Add $param from extra fields
2017-11-27 15:24:29 +01:00
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_param.tpl.php' ;
2017-10-20 23:48:42 +02:00
2017-10-20 21:39:19 +02:00
$head = societe_prepare_head ( $object );
2017-10-20 18:44:03 +02:00
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( $head , 'website' , $langs -> trans ( " ThirdParty " ), - 1 , 'company' );
2017-10-20 18:44:03 +02:00
2019-11-12 09:46:08 +01:00
$linkback = '<a href="' . DOL_URL_ROOT . '/societe/list.php?restore_lastsearch_values=1">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2017-10-20 18:44:03 +02:00
2019-10-31 20:46:31 +01:00
dol_banner_tab ( $object , 'socid' , $linkback , ( $user -> socid ? 0 : 1 ), 'rowid' , 'nom' );
2017-10-20 18:44:03 +02:00
2017-10-20 21:39:19 +02:00
print '<div class="fichecenter">' ;
2017-10-20 18:44:03 +02:00
2017-10-20 21:39:19 +02:00
print '<div class="underbanner clearboth"></div>' ;
2017-10-20 18:44:03 +02:00
2017-10-20 21:39:19 +02:00
print '<table class="border centpercent">' ;
2017-10-20 18:44:03 +02:00
2017-10-20 21:39:19 +02:00
// Prefix
2021-02-26 21:17:52 +01:00
if ( ! empty ( $conf -> global -> SOCIETE_USEPREFIX )) { // Old not used prefix field
2019-11-12 09:46:08 +01:00
print '<tr><td class="titlefield">' . $langs -> trans ( 'Prefix' ) . '</td><td colspan="3">' . $object -> prefix_comm . '</td></tr>' ;
2017-10-20 21:39:19 +02:00
}
2017-10-20 18:44:03 +02:00
2017-10-20 21:39:19 +02:00
if ( $object -> client ) {
print '<tr><td class="titlefield">' ;
2019-11-12 09:46:08 +01:00
print $langs -> trans ( 'CustomerCode' ) . '</td><td colspan="3">' ;
2017-10-20 21:39:19 +02:00
print $object -> code_client ;
2020-12-20 13:54:02 +01:00
$tmpcheck = $object -> check_codeclient ();
if ( $tmpcheck != 0 && $tmpcheck != - 5 ) {
2021-10-05 10:20:35 +02:00
print ' <span class="error">(' . $langs -> trans ( " WrongCustomerCode " ) . ')</span>' ;
2020-12-20 13:54:02 +01:00
}
2017-10-20 21:39:19 +02:00
print '</td></tr>' ;
}
2017-10-20 18:44:03 +02:00
2017-10-20 21:39:19 +02:00
if ( $object -> fournisseur ) {
print '<tr><td class="titlefield">' ;
2019-11-12 09:46:08 +01:00
print $langs -> trans ( 'SupplierCode' ) . '</td><td colspan="3">' ;
2017-10-20 21:39:19 +02:00
print $object -> code_fournisseur ;
2020-12-20 13:54:02 +01:00
$tmpcheck = $object -> check_codefournisseur ();
if ( $tmpcheck != 0 && $tmpcheck != - 5 ) {
2021-10-05 10:20:35 +02:00
print ' <span class="error">(' . $langs -> trans ( " WrongSupplierCode " ) . ')</span>' ;
2020-12-20 13:54:02 +01:00
}
2017-10-20 21:39:19 +02:00
print '</td></tr>' ;
}
2017-10-20 18:44:03 +02:00
2017-10-20 21:39:19 +02:00
print '</table>' ;
2017-10-20 18:44:03 +02:00
2017-10-20 21:39:19 +02:00
print '</div>' ;
2017-10-20 18:44:03 +02:00
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2017-10-20 18:44:03 +02:00
2018-04-15 16:35:18 +02:00
$newcardbutton = '' ;
2019-11-12 09:46:08 +01:00
if ( ! empty ( $conf -> website -> enabled )) {
if ( ! empty ( $user -> rights -> societe -> lire )) {
$newcardbutton .= dolGetButtonTitle ( $langs -> trans ( " AddWebsiteAccount " ), '' , 'fa fa-plus-circle' , DOL_URL_ROOT . '/website/websiteaccount_card.php?action=create&fk_soc=' . $object -> id . '&backtopage=' . urlencode ( $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id ));
2020-10-31 14:32:18 +01:00
} else {
$newcardbutton .= dolGetButtonTitle ( $langs -> trans ( " AddAction " ), '' , 'fa fa-plus-circle' , DOL_URL_ROOT . '/website/websiteaccount_card.php?action=create&fk_soc=' . $object -> id . '&backtopage=' . urlencode ( $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id ), '' , 0 );
2017-10-20 21:39:19 +02:00
}
}
2017-10-20 18:44:03 +02:00
2017-10-20 21:39:19 +02:00
print '<br>' ;
2017-10-20 18:44:03 +02:00
2017-10-20 21:39:19 +02:00
// Build and execute select
// --------------------------------------------------------------------
$sql = 'SELECT ' ;
2021-02-26 21:17:52 +01:00
foreach ( $objectwebsiteaccount -> fields as $key => $val ) {
2021-08-27 22:42:04 +02:00
$sql .= " t. " . $key . " , " ;
2017-10-20 21:39:19 +02:00
}
// Add fields from extrafields
2021-02-26 21:17:52 +01:00
if ( ! empty ( $extrafields -> attributes [ $object -> table_element ][ 'label' ])) {
foreach ( $extrafields -> attributes [ $object -> table_element ][ 'label' ] as $key => $val ) {
2021-08-27 22:42:04 +02:00
$sql .= ( $extrafields -> attributes [ $object -> table_element ][ 'type' ][ $key ] != 'separate' ? " ef. " . $key . " as options_ " . $key . ', ' : '' );
2021-02-26 21:17:52 +01:00
}
}
2017-10-20 21:39:19 +02:00
// Add fields from hooks
2019-11-12 09:46:08 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'printFieldListSelect' , $parameters , $objectwebsiteaccount ); // Note that $action and $object may have been modified by hook
$sql .= $hookmanager -> resPrint ;
$sql = preg_replace ( '/, $/' , '' , $sql );
$sql .= " FROM " . MAIN_DB_PREFIX . " societe_account as t " ;
2022-04-30 19:50:20 +02:00
if ( isset ( $extrafields -> attributes [ $object -> table_element ][ 'label' ]) && is_array ( $extrafields -> attributes [ $object -> table_element ][ 'label' ]) && count ( $extrafields -> attributes [ $object -> table_element ][ 'label' ])) {
2021-02-26 21:17:52 +01:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . $object -> table_element . " _extrafields as ef on (t.rowid = ef.fk_object) " ;
}
if ( $objectwebsiteaccount -> ismultientitymanaged == 1 ) {
$sql .= " WHERE t.entity IN ( " . getEntity ( 'societeaccount' ) . " ) " ;
} else {
$sql .= " WHERE 1 = 1 " ;
}
2021-03-22 13:31:06 +01:00
$sql .= " AND fk_soc = " . (( int ) $object -> id );
2021-02-26 21:17:52 +01:00
foreach ( $search as $key => $val ) {
2019-11-12 09:46:08 +01:00
$mode_search = (( $objectwebsiteaccount -> isInt ( $objectwebsiteaccount -> fields [ $key ]) || $objectwebsiteaccount -> isFloat ( $objectwebsiteaccount -> fields [ $key ])) ? 1 : 0 );
2021-02-26 21:17:52 +01:00
if ( $search [ $key ] != '' ) {
$sql .= natural_search ( $key , $search [ $key ], (( $key == 'status' ) ? 2 : $mode_search ));
}
}
if ( $search_all ) {
$sql .= natural_search ( array_keys ( $fieldstosearchall ), $search_all );
2017-10-20 21:39:19 +02:00
}
// Add where from extra fields
2017-11-27 15:24:29 +01:00
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_sql.tpl.php' ;
2017-10-20 21:39:19 +02:00
// Add where from hooks
2019-11-12 09:46:08 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'printFieldListWhere' , $parameters , $objectwebsiteaccount ); // Note that $action and $objectwebsiteaccount may have been modified by hook
$sql .= $hookmanager -> resPrint ;
2017-10-20 21:39:19 +02:00
/* If a group by is required
2019-10-08 09:28:50 +02:00
$sql .= " GROUP BY "
foreach ( $objectwebsiteaccount -> fields as $key => $val )
{
2021-08-27 22:42:04 +02:00
$sql .= " t. " . $key . " , " ;
2019-10-08 09:28:50 +02:00
}
// Add fields from extrafields
if ( ! empty ( $extrafields -> attributes [ $object -> table_element ][ 'label' ])) {
foreach ( $extrafields -> attributes [ $object -> table_element ][ 'label' ] as $key => $val ) $sql .= ( $extrafields -> attributes [ $object -> table_element ][ 'type' ][ $key ] != 'separate' ? " ef. " . $key . ', ' : '' );
// Add where from hooks
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'printFieldListGroupBy' , $parameters ); // Note that $action and $objectwebsiteaccount may have been modified by hook
$sql .= $hookmanager -> resPrint ;
*/
2017-10-20 18:44:03 +02:00
2019-11-12 09:46:08 +01:00
$sql .= $db -> order ( $sortfield , $sortorder );
2017-10-20 18:44:03 +02:00
2017-10-20 21:39:19 +02:00
// Count total nb of records
$nbtotalofrecords = '' ;
2021-02-26 21:17:52 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_FULL_SCANLIST )) {
2017-10-20 21:39:19 +02:00
$result = $db -> query ( $sql );
$nbtotalofrecords = $db -> num_rows ( $result );
2021-02-26 21:17:52 +01:00
if (( $page * $limit ) > $nbtotalofrecords ) { // if total resultset is smaller then paging size (filtering), goto and load page 0
2018-04-24 11:37:57 +02:00
$page = 0 ;
$offset = 0 ;
}
2017-10-20 21:39:19 +02:00
}
2017-10-20 18:44:03 +02:00
2019-11-12 09:46:08 +01:00
$sql .= $db -> plimit ( $limit + 1 , $offset );
2017-10-20 18:44:03 +02:00
2019-11-12 09:46:08 +01:00
$resql = $db -> query ( $sql );
2021-02-26 21:17:52 +01:00
if ( ! $resql ) {
2017-10-20 21:39:19 +02:00
dol_print_error ( $db );
exit ;
}
2017-10-20 18:44:03 +02:00
2017-10-20 23:48:42 +02:00
$num = $db -> num_rows ( $resql );
2019-11-12 09:46:08 +01:00
$arrayofselected = is_array ( $toselect ) ? $toselect : array ();
2017-10-20 23:48:42 +02:00
// List of mass actions available
2019-11-12 09:46:08 +01:00
$arrayofmassactions = array (
2017-10-20 23:48:42 +02:00
//'presend'=>$langs->trans("SendByMail"),
//'builddoc'=>$langs->trans("PDFMerge"),
);
2021-02-26 21:17:52 +01:00
if ( $user -> rights -> mymodule -> delete ) {
$arrayofmassactions [ 'predelete' ] = '<span class="fa fa-trash paddingrightonly"></span>' . $langs -> trans ( " Delete " );
}
if ( in_array ( $massaction , array ( 'presend' , 'predelete' ))) {
$arrayofmassactions = array ();
}
2019-11-12 09:46:08 +01:00
$massactionbutton = $form -> selectMassAction ( '' , $arrayofmassactions );
2017-10-20 23:48:42 +02:00
print '<form method="POST" id="searchFormList" action="' . $_SERVER [ " PHP_SELF " ] . '">' ;
2021-02-26 21:17:52 +01:00
if ( $optioncss != '' ) {
print '<input type="hidden" name="optioncss" value="' . $optioncss . '">' ;
}
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2017-10-20 23:48:42 +02:00
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">' ;
print '<input type="hidden" name="action" value="list">' ;
print '<input type="hidden" name="sortfield" value="' . $sortfield . '">' ;
print '<input type="hidden" name="sortorder" value="' . $sortorder . '">' ;
print '<input type="hidden" name="page" value="' . $page . '">' ;
print '<input type="hidden" name="id" value="' . $id . '">' ;
print '<input type="hidden" name="contextpage" value="' . $contextpage . '">' ;
2018-04-15 16:35:18 +02:00
print_barre_liste ( $title , $page , $_SERVER [ " PHP_SELF " ], $param , $sortfield , $sortorder , $massactionbutton , $num , $nbtotalofrecords , '' , 0 , $newcardbutton , '' , $limit );
2017-10-20 23:48:42 +02:00
2019-11-12 09:46:08 +01:00
$topicmail = " Information " ;
$modelmail = " societeaccount " ;
$objecttmp = new SocieteAccount ( $db );
$trackid = 'thi' . $object -> id ;
2017-11-15 11:39:11 +01:00
include DOL_DOCUMENT_ROOT . '/core/tpl/massactions_pre.tpl.php' ;
2019-05-15 18:59:46 +02:00
/* if ( $sall )
2017-10-20 23:48:42 +02:00
{
foreach ( $fieldstosearchall as $key => $val ) $fieldstosearchall [ $key ] = $langs -> trans ( $val );
2019-01-27 11:55:16 +01:00
print '<div class="divsearchfieldfilter">' . $langs -> trans ( " FilterOnInto " , $sall ) . join ( ', ' , $fieldstosearchall ) . '</div>' ;
2019-05-15 18:59:46 +02:00
} */
2017-10-20 23:48:42 +02:00
2019-05-15 18:59:46 +02:00
$moreforfilter = '' ;
/* $moreforfilter .= '<div class="divsearchfield">' ;
2017-10-20 23:48:42 +02:00
$moreforfilter .= $langs -> trans ( 'MyFilter' ) . ': <input type="text" name="search_myfield" value="' . dol_escape_htmltag ( $search_myfield ) . '">' ;
$moreforfilter .= '</div>' ; */
2019-11-12 09:46:08 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'printFieldPreListTitle' , $parameters , $objectwebsiteaccount ); // Note that $action and $objectwebsiteaccount may have been modified by hook
2021-02-26 21:17:52 +01:00
if ( empty ( $reshook )) {
$moreforfilter .= $hookmanager -> resPrint ;
} else {
$moreforfilter = $hookmanager -> resPrint ;
}
2017-10-20 23:48:42 +02:00
2021-02-26 21:17:52 +01:00
if ( ! empty ( $moreforfilter )) {
2017-10-20 23:48:42 +02:00
print '<div class="liste_titre liste_titre_bydiv centpercent">' ;
print $moreforfilter ;
print '</div>' ;
}
2019-11-12 09:46:08 +01:00
$varpage = empty ( $contextpage ) ? $_SERVER [ " PHP_SELF " ] : $contextpage ;
$selectedfields = $form -> multiSelectArrayWithCheckbox ( 'selectedfields' , $arrayfields , $varpage ); // This also change content of $arrayfields
$selectedfields .= ( count ( $arrayofmassactions ) ? $form -> showCheckAddButtons ( 'checkforselect' , 1 ) : '' );
2017-10-20 23:48:42 +02:00
2019-11-12 09:46:08 +01:00
print '<div class="div-table-responsive">' ; // You can use div-table-responsive-no-min if you dont need reserved height for your table
print '<table class="tagtable liste' . ( $moreforfilter ? " listwithfilterbefore " : " " ) . '">' . " \n " ;
2017-10-20 23:48:42 +02:00
// Fields title search
// --------------------------------------------------------------------
print '<tr class="liste_titre">' ;
2021-02-26 21:17:52 +01:00
foreach ( $objectwebsiteaccount -> fields as $key => $val ) {
2019-11-12 09:46:08 +01:00
$align = '' ;
2021-02-26 21:17:52 +01:00
if ( in_array ( $val [ 'type' ], array ( 'date' , 'datetime' , 'timestamp' ))) {
$align = 'center' ;
}
if ( in_array ( $val [ 'type' ], array ( 'timestamp' ))) {
$align .= ' nowrap' ;
}
if ( $key == 'status' ) {
$align .= ( $align ? ' ' : '' ) . 'center' ;
}
if ( ! empty ( $arrayfields [ 't.' . $key ][ 'checked' ])) {
print '<td class="liste_titre' . ( $align ? ' ' . $align : '' ) . '"><input type="text" class="flat maxwidth75" name="search_' . $key . '" value="' . dol_escape_htmltag ( $search [ $key ]) . '"></td>' ;
}
2017-10-20 23:48:42 +02:00
}
// Extra fields
2017-11-27 15:24:29 +01:00
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_input.tpl.php' ;
2017-10-20 23:48:42 +02:00
// Fields from hook
2019-11-12 09:46:08 +01:00
$parameters = array ( 'arrayfields' => $arrayfields );
$reshook = $hookmanager -> executeHooks ( 'printFieldListOption' , $parameters , $objectwebsiteaccount ); // Note that $action and $object may have been modified by hook
2017-10-20 23:48:42 +02:00
print $hookmanager -> resPrint ;
// Action column
2019-05-19 13:51:47 +02:00
print '<td class="liste_titre maxwidthsearch">' ;
2019-11-12 09:46:08 +01:00
$searchpicto = $form -> showFilterButtons ();
2017-10-20 23:48:42 +02:00
print $searchpicto ;
print '</td>' ;
print '</tr>' . " \n " ;
// Fields title label
// --------------------------------------------------------------------
print '<tr class="liste_titre">' ;
2021-02-26 21:17:52 +01:00
foreach ( $objectwebsiteaccount -> fields as $key => $val ) {
2019-11-12 09:46:08 +01:00
$align = '' ;
2021-02-26 21:17:52 +01:00
if ( in_array ( $val [ 'type' ], array ( 'date' , 'datetime' , 'timestamp' ))) {
$align = 'center' ;
}
if ( in_array ( $val [ 'type' ], array ( 'timestamp' ))) {
$align .= 'nowrap' ;
}
if ( $key == 'status' ) {
$align .= ( $align ? ' ' : '' ) . 'center' ;
}
if ( ! empty ( $arrayfields [ 't.' . $key ][ 'checked' ])) {
print getTitleFieldOfList ( $arrayfields [ 't.' . $key ][ 'label' ], 0 , $_SERVER [ 'PHP_SELF' ], 't.' . $key , '' , $param , ( $align ? 'class="' . $align . '"' : '' ), $sortfield , $sortorder , $align . ' ' ) . " \n " ;
}
2017-10-20 23:48:42 +02:00
}
// Extra fields
2017-11-27 15:24:29 +01:00
// Extra fields
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_title.tpl.php' ;
2017-10-20 23:48:42 +02:00
// Hook fields
2019-11-12 09:46:08 +01:00
$parameters = array ( 'arrayfields' => $arrayfields , 'param' => $param , 'sortfield' => $sortfield , 'sortorder' => $sortorder );
$reshook = $hookmanager -> executeHooks ( 'printFieldListTitle' , $parameters , $objectwebsiteaccount ); // Note that $action and $object may have been modified by hook
2017-10-20 23:48:42 +02:00
print $hookmanager -> resPrint ;
2019-02-23 21:02:39 +01:00
print getTitleFieldOfList ( $selectedfields , 0 , $_SERVER [ " PHP_SELF " ], " " , '' , '' , '' , $sortfield , $sortorder , 'maxwidthsearch center ' ) . " \n " ;
2017-10-20 23:48:42 +02:00
print '</tr>' . " \n " ;
2019-07-20 15:53:46 +02:00
// Detect if we need a fetch on each output line
2019-11-12 09:46:08 +01:00
$needToFetchEachLine = 0 ;
2022-04-30 19:50:20 +02:00
if ( isset ( $extrafields -> attributes [ $object -> table_element ][ 'computed' ]) && is_array ( $extrafields -> attributes [ $object -> table_element ][ 'computed' ]) && count ( $extrafields -> attributes [ $object -> table_element ][ 'computed' ]) > 0 ) {
2021-02-26 21:17:52 +01:00
foreach ( $extrafields -> attributes [ $object -> table_element ][ 'computed' ] as $key => $val ) {
if ( preg_match ( '/\$object/' , $val )) {
$needToFetchEachLine ++ ; // There is at least one compute field that use $object
}
2019-07-20 15:53:46 +02:00
}
}
2017-10-20 23:48:42 +02:00
// Loop on record
// --------------------------------------------------------------------
2019-11-12 09:46:08 +01:00
$i = 0 ;
$totalarray = array ();
2021-02-26 21:17:52 +01:00
while ( $i < min ( $num , $limit )) {
2017-10-20 23:48:42 +02:00
$obj = $db -> fetch_object ( $resql );
2021-02-26 21:17:52 +01:00
if ( empty ( $obj )) {
break ; // Should not happen
}
2017-10-20 23:48:42 +02:00
// Store properties in $object
$objectwebsiteaccount -> id = $obj -> rowid ;
2020-04-23 12:33:22 +02:00
$objectwebsiteaccount -> login = $obj -> login ;
$objectwebsiteaccount -> ref = $obj -> login ;
2021-02-26 21:17:52 +01:00
foreach ( $objectwebsiteaccount -> fields as $key => $val ) {
2021-10-19 16:26:43 +02:00
if ( property_exists ( $objectwebsiteaccount , $key )) {
$objectwebsiteaccount -> $key = $obj -> $key ;
2021-02-26 21:17:52 +01:00
}
2017-10-20 23:48:42 +02:00
}
// Show here line of result
print '<tr class="oddeven">' ;
2021-02-26 21:17:52 +01:00
foreach ( $objectwebsiteaccount -> fields as $key => $val ) {
2019-11-12 09:46:08 +01:00
$align = '' ;
2021-02-26 21:17:52 +01:00
if ( in_array ( $val [ 'type' ], array ( 'date' , 'datetime' , 'timestamp' ))) {
$align = 'center' ;
}
if ( in_array ( $val [ 'type' ], array ( 'timestamp' ))) {
$align .= 'nowrap' ;
}
if ( $key == 'status' ) {
$align .= ( $align ? ' ' : '' ) . 'center' ;
}
if ( ! empty ( $arrayfields [ 't.' . $key ][ 'checked' ])) {
2017-11-03 15:56:16 +01:00
print '<td' ;
2021-02-26 21:17:52 +01:00
if ( $align ) {
print ' class="' . $align . '"' ;
}
2017-11-03 15:56:16 +01:00
print '>' ;
2021-02-26 21:17:52 +01:00
if ( $key == 'login' ) {
print $objectwebsiteaccount -> getNomUrl ( 1 , '' , 0 , '' , 1 );
} else {
print $objectwebsiteaccount -> showOutputField ( $val , $key , $obj -> $key , '' );
}
2017-10-20 23:48:42 +02:00
print '</td>' ;
2021-02-26 21:17:52 +01:00
if ( ! $i ) {
$totalarray [ 'nbfield' ] ++ ;
}
2021-10-19 16:26:43 +02:00
if ( ! empty ( $val [ 'isameasure' ]) && $val [ 'isameasure' ] == 1 ) {
2021-02-26 21:17:52 +01:00
if ( ! $i ) {
$totalarray [ 'pos' ][ $totalarray [ 'nbfield' ]] = 't.' . $key ;
}
2021-06-14 01:55:58 +02:00
if ( ! isset ( $totalarray [ 'val' ])) {
$totalarray [ 'val' ] = array ();
}
if ( ! isset ( $totalarray [ 'val' ][ 't.' . $key ])) {
$totalarray [ 'val' ][ 't.' . $key ] = 0 ;
}
2021-10-19 16:26:43 +02:00
$totalarray [ 'val' ][ 't.' . $key ] += $objectwebsiteaccount -> $key ;
2017-10-20 23:48:42 +02:00
}
}
}
// Extra fields
2017-11-27 15:24:29 +01:00
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_print_fields.tpl.php' ;
2017-10-20 23:48:42 +02:00
// Fields from hook
2020-05-08 01:40:25 +02:00
$parameters = array ( 'arrayfields' => $arrayfields , 'obj' => $obj , 'i' => $i , 'totalarray' =>& $totalarray );
2019-11-12 09:46:08 +01:00
$reshook = $hookmanager -> executeHooks ( 'printFieldListValue' , $parameters , $objectwebsiteaccount ); // Note that $action and $object may have been modified by hook
2017-10-20 23:48:42 +02:00
print $hookmanager -> resPrint ;
// Action column
2019-02-23 21:02:39 +01:00
print '<td class="nowrap center">' ;
2021-02-26 21:17:52 +01:00
if ( $massactionbutton || $massaction ) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
2019-11-12 09:46:08 +01:00
$selected = 0 ;
2021-02-26 21:17:52 +01:00
if ( in_array ( $obj -> rowid , $arrayofselected )) {
$selected = 1 ;
}
2019-11-12 09:46:08 +01:00
print '<input id="cb' . $obj -> rowid . '" class="flat checkforselect" type="checkbox" name="toselect[]" value="' . $obj -> rowid . '"' . ( $selected ? ' checked="checked"' : '' ) . '>' ;
2017-10-20 23:48:42 +02:00
}
print '</td>' ;
2021-02-26 21:17:52 +01:00
if ( ! $i ) {
$totalarray [ 'nbfield' ] ++ ;
}
2017-10-20 23:48:42 +02:00
print '</tr>' ;
$i ++ ;
}
// Show total line
2019-11-05 12:47:38 +01:00
include DOL_DOCUMENT_ROOT . '/core/tpl/list_print_total.tpl.php' ;
2017-10-20 23:48:42 +02:00
// If no record found
2021-02-26 21:17:52 +01:00
if ( $num == 0 ) {
2019-11-12 09:46:08 +01:00
$colspan = 1 ;
2021-02-26 21:17:52 +01:00
foreach ( $arrayfields as $key => $val ) {
if ( ! empty ( $val [ 'checked' ])) {
$colspan ++ ;
}
}
2017-10-20 23:48:42 +02:00
print '<tr><td colspan="' . $colspan . '" class="opacitymedium">' . $langs -> trans ( " NoRecordFound " ) . '</td></tr>' ;
}
$db -> free ( $resql );
2019-11-12 09:46:08 +01:00
$parameters = array ( 'arrayfields' => $arrayfields , 'sql' => $sql );
$reshook = $hookmanager -> executeHooks ( 'printFieldListFooter' , $parameters , $objectwebsiteaccount ); // Note that $action and $object may have been modified by hook
2017-10-20 23:48:42 +02:00
print $hookmanager -> resPrint ;
print '</table>' . " \n " ;
print '</div>' . " \n " ;
print '</form>' . " \n " ;
2021-02-26 21:17:52 +01:00
if ( in_array ( 'builddoc' , $arrayofmassactions ) && ( $nbtotalofrecords === '' || $nbtotalofrecords )) {
2019-11-12 09:46:08 +01:00
$hidegeneratedfilelistifempty = 1 ;
2021-02-26 21:17:52 +01:00
if ( $massaction == 'builddoc' || $action == 'remove_file' || $show_files ) {
$hidegeneratedfilelistifempty = 0 ;
}
2017-10-20 23:48:42 +02:00
2018-07-26 11:57:25 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php' ;
2018-02-21 11:02:45 +01:00
$formfile = new FormFile ( $db );
2017-10-20 23:48:42 +02:00
2018-02-21 11:02:45 +01:00
// Show list of available documents
2019-11-12 09:46:08 +01:00
$urlsource = $_SERVER [ 'PHP_SELF' ] . '?sortfield=' . $sortfield . '&sortorder=' . $sortorder ;
$urlsource .= str_replace ( '&' , '&' , $param );
2017-10-20 23:48:42 +02:00
2019-11-12 09:46:08 +01:00
$filedir = $diroutputmassaction ;
$genallowed = $user -> rights -> mymodule -> read ;
$delallowed = $user -> rights -> mymodule -> create ;
2018-02-21 11:02:45 +01:00
2019-01-27 11:55:16 +01:00
print $formfile -> showdocuments ( 'massfilesarea_mymodule' , '' , $filedir , $urlsource , 0 , $delallowed , '' , 1 , 1 , 0 , 48 , 1 , $param , $title , '' , '' , '' , null , $hidegeneratedfilelistifempty );
2017-10-20 23:48:42 +02:00
}
2017-10-20 18:44:03 +02:00
2018-08-05 17:21:59 +02:00
// End of page
2017-10-20 18:44:03 +02:00
llxFooter ();
$db -> close ();