From 933a9446038b7b2010321fd120f1ce945b492a11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Wed, 17 Feb 2021 22:14:21 +0100 Subject: [PATCH 01/36] count actioncomm for thirdparty tab agenda --- htdocs/core/lib/company.lib.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index a424657e206..867180ef9b6 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -304,8 +304,22 @@ function societe_prepare_head(Societe $object) $head[$h][0] = DOL_URL_ROOT.'/societe/agenda.php?socid='.$object->id; $head[$h][1] = $langs->trans("Events"); if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) { + $nbNote = 0; + $sql = "SELECT COUNT(id) as nb"; + $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm"; + $sql .= " WHERE fk_soc = ".$object->id; + $resql = $db->query($sql); + if ($resql) { + $obj = $db->fetch_object($resql); + $nbNote = $obj->nb; + } else { + dol_print_error($db); + } $head[$h][1] .= '/'; $head[$h][1] .= $langs->trans("Agenda"); + if ($nbNote > 0) { + $head[$h][1] .= ''.$nbNote.''; + } } $head[$h][2] = 'agenda'; $h++; From 45e947ee2b73063cd4cb7e8e55f80367d1707eae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Wed, 17 Feb 2021 22:16:07 +0100 Subject: [PATCH 02/36] count actioncomm for thirdparty tab agenda --- htdocs/core/lib/company.lib.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 867180ef9b6..1fd7b653925 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -304,21 +304,21 @@ function societe_prepare_head(Societe $object) $head[$h][0] = DOL_URL_ROOT.'/societe/agenda.php?socid='.$object->id; $head[$h][1] = $langs->trans("Events"); if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) { - $nbNote = 0; + $nbEvent = 0; $sql = "SELECT COUNT(id) as nb"; $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm"; $sql .= " WHERE fk_soc = ".$object->id; $resql = $db->query($sql); if ($resql) { $obj = $db->fetch_object($resql); - $nbNote = $obj->nb; + $nbEvent = $obj->nb; } else { dol_print_error($db); } $head[$h][1] .= '/'; $head[$h][1] .= $langs->trans("Agenda"); - if ($nbNote > 0) { - $head[$h][1] .= ''.$nbNote.''; + if ($nbEvent > 0) { + $head[$h][1] .= ''.$nbEvent.''; } } $head[$h][2] = 'agenda'; @@ -326,9 +326,9 @@ function societe_prepare_head(Societe $object) // Log /*$head[$h][0] = DOL_URL_ROOT.'/societe/info.php?socid='.$object->id; - $head[$h][1] = $langs->trans("Info"); - $head[$h][2] = 'info'; - $h++;*/ + $head[$h][1] = $langs->trans("Info"); + $head[$h][2] = 'info'; + $h++;*/ complete_head_from_modules($conf, $langs, $object, $head, $h, 'thirdparty', 'remove'); @@ -1003,7 +1003,7 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '') } elseif (in_array($key, array('role'))) { print $formcompany->showRoles("search_roles", $contactstatic, 'edit', $search_roles); } else { - print ''; + print ''; } print ''; } From c7efd68916b1dec7f4c15362aace2c87ca063737 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Thu, 18 Feb 2021 18:45:04 +0100 Subject: [PATCH 03/36] fix actioncomm index --- htdocs/comm/action/index.php | 139 ++++++++++++++++------------------- 1 file changed, 63 insertions(+), 76 deletions(-) diff --git a/htdocs/comm/action/index.php b/htdocs/comm/action/index.php index ab712c89847..e66f84f9987 100644 --- a/htdocs/comm/action/index.php +++ b/htdocs/comm/action/index.php @@ -836,93 +836,80 @@ if ($showbirthday) } // HOLIDAYS CALENDAR -//if ($conf->global->AGENDA_SHOW_HOLIDAYS) -//{ - $sql = "SELECT u.rowid as uid, u.lastname, u.firstname, u.statut, x.rowid, x.date_debut as date_start, x.date_fin as date_end, x.halfday, x.statut as status"; - $sql .= " FROM ".MAIN_DB_PREFIX."holiday as x, ".MAIN_DB_PREFIX."user as u"; - $sql .= " WHERE u.rowid = x.fk_user"; - $sql .= " AND u.statut = '1'"; // Show only active users (0 = inactive user, 1 = active user) - $sql .= " AND (x.statut = '2' OR x.statut = '3')"; // Show only public leaves (2 = leave wait for approval, 3 = leave approved) +$sql = "SELECT u.rowid as uid, u.lastname, u.firstname, u.statut, x.rowid, x.date_debut as date_start, x.date_fin as date_end, x.halfday, x.statut as status"; +$sql .= " FROM ".MAIN_DB_PREFIX."holiday as x, ".MAIN_DB_PREFIX."user as u"; +$sql .= " WHERE u.rowid = x.fk_user"; +$sql .= " AND u.statut = '1'"; // Show only active users (0 = inactive user, 1 = active user) +$sql .= " AND (x.statut = '2' OR x.statut = '3')"; // Show only public leaves (2 = leave wait for approval, 3 = leave approved) - if ($action == 'show_day') - { - // Request only leaves for the current selected day - $sql .= " AND '".$db->escape($year)."-".$db->escape($month)."-".$db->escape($day)."' BETWEEN x.date_debut AND x.date_fin"; - } elseif ($action == 'show_week') - { - // TODO: Add filter to reduce database request - } elseif ($action == 'show_month') - { - // TODO: Add filter to reduce database request - } +if ($action == 'show_day') { + // Request only leaves for the current selected day + $sql .= " AND '".$db->escape($year)."-".$db->escape($month)."-".$db->escape($day)."' BETWEEN x.date_debut AND x.date_fin"; +} elseif ($action == 'show_week') { + // TODO: Add filter to reduce database request +} elseif ($action == 'show_month') { + // TODO: Add filter to reduce database request +} - $resql = $db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); - $i = 0; +$resql = $db->query($sql); +if ($resql) { + $num = $db->num_rows($resql); + $i = 0; - while ($i < $num) - { - $obj = $db->fetch_object($resql); + while ($i < $num) { + $obj = $db->fetch_object($resql); - $dateStartArray = dol_getdate(dol_stringtotime($obj->date_start, 1), true); - $dateEndArray = dol_getdate(dol_stringtotime($obj->date_end, 1), true); + $dateStartArray = dol_getdate(dol_stringtotime($obj->date_start, 1), true); + $dateEndArray = dol_getdate(dol_stringtotime($obj->date_end, 1), true); - $event = new ActionComm($db); + $event = new ActionComm($db); - // Need the id of the leave object for link to it - $event->id = $obj->rowid; - $event->ref = $event->id; + // Need the id of the leave object for link to it + $event->id = $obj->rowid; + $event->ref = $event->id; - $event->type_code = 'HOLIDAY'; - $event->type_label = ''; - $event->type_color = ''; - $event->type = 'holiday'; - $event->type_picto = 'holiday'; + $event->type_code = 'HOLIDAY'; + $event->type_label = ''; + $event->type_color = ''; + $event->type = 'holiday'; + $event->type_picto = 'holiday'; - $event->datep = dol_mktime(0, 0, 0, $dateStartArray['mon'], $dateStartArray['mday'], $dateStartArray['year'], true); - $event->datef = dol_mktime(0, 0, 0, $dateEndArray['mon'], $dateEndArray['mday'], $dateEndArray['year'], true); - $event->date_start_in_calendar = $event->datep; - $event->date_end_in_calendar = $event->datef; + $event->datep = dol_mktime(0, 0, 0, $dateStartArray['mon'], $dateStartArray['mday'], $dateStartArray['year'], true); + $event->datef = dol_mktime(0, 0, 0, $dateEndArray['mon'], $dateEndArray['mday'], $dateEndArray['year'], true); + $event->date_start_in_calendar = $event->datep; + $event->date_end_in_calendar = $event->datef; - if ($obj->status == 3) - { - // Show no symbol for leave with state "leave approved" - $event->percentage = -1; - } elseif ($obj->status == 2) - { - // Show TO-DO symbol for leave with state "leave wait for approval" - $event->percentage = 0; - } - - if ($obj->halfday == 1) - { - $event->label = $obj->lastname.' ('.$langs->trans("Morning").')'; - } elseif ($obj->halfday == -1) - { - $event->label = $obj->lastname.' ('.$langs->trans("Afternoon").')'; - } else { - $event->label = $obj->lastname; - } - - $daycursor = $event->date_start_in_calendar; - $annee = dol_print_date($daycursor, '%Y'); - $mois = dol_print_date($daycursor, '%m'); - $jour = dol_print_date($daycursor, '%d'); - - $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee); - - do { - $eventarray[$daykey][] = $event; - - $daykey += 60 * 60 * 24; - } while ($daykey <= $event->date_end_in_calendar); - - $i++; + if ($obj->status == 3) { + // Show no symbol for leave with state "leave approved" + $event->percentage = -1; + } elseif ($obj->status == 2) { + // Show TO-DO symbol for leave with state "leave wait for approval" + $event->percentage = 0; } + + if ($obj->halfday == 1) { + $event->label = $obj->lastname.' ('.$langs->trans("Morning").')'; + } elseif ($obj->halfday == -1) { + $event->label = $obj->lastname.' ('.$langs->trans("Afternoon").')'; + } else { + $event->label = $obj->lastname; + } + + $daycursor = $event->date_start_in_calendar; + $annee = dol_print_date($daycursor, '%Y'); + $mois = dol_print_date($daycursor, '%m'); + $jour = dol_print_date($daycursor, '%d'); + + $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee); + + do { + $eventarray[$daykey][] = $event; + $daykey += 60 * 60 * 24; + } while ($daykey <= $event->date_end_in_calendar); + + $i++; } -//} +} // EXTERNAL CALENDAR // Complete $eventarray with external import Ical From 042038d185686e88dc727941694034d1145e9909 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Thu, 18 Feb 2021 22:42:55 +0100 Subject: [PATCH 04/36] Code enhanced - Standardize field name #14697 --- htdocs/comm/propal/class/propal.class.php | 8 ++++- htdocs/comm/propal/index.php | 2 +- htdocs/comm/propal/list.php | 30 +++++++++---------- .../install/mysql/migration/13.0.0-14.0.0.sql | 3 ++ htdocs/install/mysql/tables/llx_propal.sql | 6 ++-- 5 files changed, 29 insertions(+), 20 deletions(-) diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index a115d8bca5e..51ec7e6e53a 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -185,6 +185,12 @@ class Propal extends CommonObject */ public $total; + public $total_ht = 0; + public $total_tva = 0; + public $total_localtax1 = 0; + public $total_localtax2 = 0; + public $total_ttc = 0; + public $cond_reglement_code; public $mode_reglement_code; public $remise = 0; @@ -285,7 +291,7 @@ class Propal extends CommonObject 'remise_absolue' =>array('type'=>'double', 'label'=>'CustomerRelativeDiscount', 'enabled'=>1, 'visible'=>-1, 'position'=>115), //'remise' =>array('type'=>'double', 'label'=>'Remise', 'enabled'=>1, 'visible'=>-1, 'position'=>120), 'total_ht' =>array('type'=>'double(24,8)', 'label'=>'TotalHT', 'enabled'=>1, 'visible'=>-1, 'position'=>125, 'isameasure'=>1), - 'tva' =>array('type'=>'double(24,8)', 'label'=>'VAT', 'enabled'=>1, 'visible'=>-1, 'position'=>130, 'isameasure'=>1), + 'total_tva' =>array('type'=>'double(24,8)', 'label'=>'VAT', 'enabled'=>1, 'visible'=>-1, 'position'=>130, 'isameasure'=>1), 'localtax1' =>array('type'=>'double(24,8)', 'label'=>'LocalTax1', 'enabled'=>1, 'visible'=>-1, 'position'=>135, 'isameasure'=>1), 'localtax2' =>array('type'=>'double(24,8)', 'label'=>'LocalTax2', 'enabled'=>1, 'visible'=>-1, 'position'=>140, 'isameasure'=>1), 'total' =>array('type'=>'double(24,8)', 'label'=>'TotalTTC', 'enabled'=>1, 'visible'=>-1, 'position'=>145, 'isameasure'=>1), diff --git a/htdocs/comm/propal/index.php b/htdocs/comm/propal/index.php index b51f138b0e5..c274ebf74f3 100644 --- a/htdocs/comm/propal/index.php +++ b/htdocs/comm/propal/index.php @@ -198,7 +198,7 @@ if ($resql) * Draft proposals */ if (!empty($conf->propal->enabled)) { - $sql = "SELECT p.rowid, p.ref, p.ref_client, p.total_ht, p.tva as total_tva, p.total as total_ttc"; + $sql = "SELECT p.rowid, p.ref, p.ref_client, p.total_ht, p.total_tva, p.total as total_ttc"; $sql .= ", s.rowid as socid, s.nom as name, s.client, s.canvas, s.code_client, s.email, s.entity, s.code_compta"; $sql .= " FROM ".MAIN_DB_PREFIX."propal as p"; $sql .= ", ".MAIN_DB_PREFIX."societe as s"; diff --git a/htdocs/comm/propal/list.php b/htdocs/comm/propal/list.php index 5eca82f022c..d05543530d1 100644 --- a/htdocs/comm/propal/list.php +++ b/htdocs/comm/propal/list.php @@ -181,14 +181,14 @@ $arrayfields = array( 'p.fk_cond_reglement'=>array('label'=>"PaymentConditionsShort", 'checked'=>0), 'p.fk_mode_reglement'=>array('label'=>"PaymentMode", 'checked'=>0), 'p.total_ht'=>array('label'=>"AmountHT", 'checked'=>1), - 'p.total_vat'=>array('label'=>"AmountVAT", 'checked'=>0), + 'p.total_tva'=>array('label'=>"AmountVAT", 'checked'=>0), 'p.total_ttc'=>array('label'=>"AmountTTC", 'checked'=>0), 'p.total_ht_invoiced'=>array('label'=>"AmountInvoicedHT", 'checked'=>0, 'enabled'=>!empty($conf->global->PROPOSAL_SHOW_INVOICED_AMOUNT)), 'p.total_invoiced'=>array('label'=>"AmountInvoicedTTC", 'checked'=>0, 'enabled'=>!empty($conf->global->PROPOSAL_SHOW_INVOICED_AMOUNT)), 'p.multicurrency_code'=>array('label'=>'Currency', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)), 'p.multicurrency_tx'=>array('label'=>'CurrencyRate', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)), 'p.multicurrency_total_ht'=>array('label'=>'MulticurrencyAmountHT', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)), - 'p.multicurrency_total_vat'=>array('label'=>'MulticurrencyAmountVAT', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)), + 'p.multicurrency_total_tva'=>array('label'=>'MulticurrencyAmountVAT', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)), 'p.multicurrency_total_ttc'=>array('label'=>'MulticurrencyAmountTTC', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)), 'p.multicurrency_total_ht_invoiced'=>array('label'=>'MulticurrencyAmountInvoicedHT', 'checked'=>0, 'enabled'=>!empty($conf->multicurrency->enabled) && !empty($conf->global->PROPOSAL_SHOW_INVOICED_AMOUNT)), 'p.multicurrency_total_invoiced'=>array('label'=>'MulticurrencyAmountInvoicedTTC', 'checked'=>0, 'enabled'=>!empty($conf->multicurrency->enabled) && !empty($conf->global->PROPOSAL_SHOW_INVOICED_AMOUNT)), @@ -391,8 +391,8 @@ $sql .= ' s.rowid as socid, s.nom as name, s.name_alias as alias, s.email, s.tow $sql .= " typent.code as typent_code,"; $sql .= " ava.rowid as availability,"; $sql .= " state.code_departement as state_code, state.nom as state_name,"; -$sql .= ' p.rowid, p.entity, p.note_private, p.total_ht, p.tva as total_vat, p.total as total_ttc, p.localtax1, p.localtax2, p.ref, p.ref_client, p.fk_statut as status, p.fk_user_author, p.datep as dp, p.fin_validite as dfv,p.date_livraison as ddelivery,'; -$sql .= ' p.fk_multicurrency, p.multicurrency_code, p.multicurrency_tx, p.multicurrency_total_ht, p.multicurrency_total_tva as multicurrency_total_vat, p.multicurrency_total_ttc,'; +$sql .= ' p.rowid, p.entity, p.note_private, p.total_ht, p.total_tva, p.total as total_ttc, p.localtax1, p.localtax2, p.ref, p.ref_client, p.fk_statut as status, p.fk_user_author, p.datep as dp, p.fin_validite as dfv,p.date_livraison as ddelivery,'; +$sql .= ' p.fk_multicurrency, p.multicurrency_code, p.multicurrency_tx, p.multicurrency_total_ht, p.multicurrency_total_tva, p.multicurrency_total_ttc,'; $sql .= ' p.datec as date_creation, p.tms as date_update, p.date_cloture as date_cloture,'; $sql .= ' p.note_public, p.note_private,'; $sql .= ' p.fk_cond_reglement,p.fk_mode_reglement,p.fk_shipping_method,'; @@ -449,7 +449,7 @@ if ($search_societe) $sql .= natural_search('s.nom', $search_societe); if ($search_societe_alias) $sql .= natural_search('s.name_alias', $search_societe_alias); if ($search_login) $sql .= natural_search("u.login", $search_login); if ($search_montant_ht != '') $sql .= natural_search("p.total_ht", $search_montant_ht, 1); -if ($search_montant_vat != '') $sql .= natural_search("p.tva", $search_montant_vat, 1); +if ($search_montant_vat != '') $sql .= natural_search("p.total_tva", $search_montant_vat, 1); if ($search_montant_ttc != '') $sql .= natural_search("p.total", $search_montant_ttc, 1); if ($search_multicurrency_code != '') $sql .= ' AND p.multicurrency_code = "'.$db->escape($search_multicurrency_code).'"'; if ($search_multicurrency_tx != '') $sql .= natural_search('p.multicurrency_tx', $search_multicurrency_tx, 1); @@ -834,7 +834,7 @@ if ($resql) print ''; print ''; } - if (!empty($arrayfields['p.total_vat']['checked'])) + if (!empty($arrayfields['p.total_tva']['checked'])) { // Amount print ''; @@ -881,7 +881,7 @@ if ($resql) print ''; print ''; } - if (!empty($arrayfields['p.multicurrency_total_vat']['checked'])) + if (!empty($arrayfields['p.multicurrency_total_tva']['checked'])) { // Amount print ''; @@ -992,14 +992,14 @@ if ($resql) if (!empty($arrayfields['p.fk_cond_reglement']['checked'])) print_liste_field_titre($arrayfields['p.fk_cond_reglement']['label'], $_SERVER["PHP_SELF"], "p.fk_cond_reglement", "", $param, '', $sortfield, $sortorder); if (!empty($arrayfields['p.fk_mode_reglement']['checked'])) print_liste_field_titre($arrayfields['p.fk_mode_reglement']['label'], $_SERVER["PHP_SELF"], "p.fk_mode_reglement", "", $param, '', $sortfield, $sortorder); if (!empty($arrayfields['p.total_ht']['checked'])) print_liste_field_titre($arrayfields['p.total_ht']['label'], $_SERVER["PHP_SELF"], 'p.total_ht', '', $param, 'class="right"', $sortfield, $sortorder); - if (!empty($arrayfields['p.total_vat']['checked'])) print_liste_field_titre($arrayfields['p.total_vat']['label'], $_SERVER["PHP_SELF"], 'p.tva', '', $param, 'class="right"', $sortfield, $sortorder); + if (!empty($arrayfields['p.total_tva']['checked'])) print_liste_field_titre($arrayfields['p.total_tva']['label'], $_SERVER["PHP_SELF"], 'p.total_tva', '', $param, 'class="right"', $sortfield, $sortorder); if (!empty($arrayfields['p.total_ttc']['checked'])) print_liste_field_titre($arrayfields['p.total_ttc']['label'], $_SERVER["PHP_SELF"], 'p.total', '', $param, 'class="right"', $sortfield, $sortorder); if (!empty($arrayfields['p.total_ht_invoiced']['checked'])) print_liste_field_titre($arrayfields['p.total_ht_invoiced']['label'], $_SERVER["PHP_SELF"], '', '', $param, 'class="right"', $sortfield, $sortorder); if (!empty($arrayfields['p.total_invoiced']['checked'])) print_liste_field_titre($arrayfields['p.total_invoiced']['label'], $_SERVER["PHP_SELF"], '', '', $param, 'class="right"', $sortfield, $sortorder); if (!empty($arrayfields['p.multicurrency_code']['checked'])) print_liste_field_titre($arrayfields['p.multicurrency_code']['label'], $_SERVER['PHP_SELF'], 'p.multicurrency_code', '', $param, '', $sortfield, $sortorder); if (!empty($arrayfields['p.multicurrency_tx']['checked'])) print_liste_field_titre($arrayfields['p.multicurrency_tx']['label'], $_SERVER['PHP_SELF'], 'p.multicurrency_tx', '', $param, '', $sortfield, $sortorder); if (!empty($arrayfields['p.multicurrency_total_ht']['checked'])) print_liste_field_titre($arrayfields['p.multicurrency_total_ht']['label'], $_SERVER['PHP_SELF'], 'p.multicurrency_total_ht', '', $param, 'class="right"', $sortfield, $sortorder); - if (!empty($arrayfields['p.multicurrency_total_vat']['checked'])) print_liste_field_titre($arrayfields['p.multicurrency_total_vat']['label'], $_SERVER['PHP_SELF'], 'p.multicurrency_total_tva', '', $param, 'class="right"', $sortfield, $sortorder); + if (!empty($arrayfields['p.multicurrency_total_tva']['checked'])) print_liste_field_titre($arrayfields['p.multicurrency_total_tva']['label'], $_SERVER['PHP_SELF'], 'p.multicurrency_total_tva', '', $param, 'class="right"', $sortfield, $sortorder); if (!empty($arrayfields['p.multicurrency_total_ttc']['checked'])) print_liste_field_titre($arrayfields['p.multicurrency_total_ttc']['label'], $_SERVER['PHP_SELF'], 'p.multicurrency_total_ttc', '', $param, 'class="right"', $sortfield, $sortorder); if (!empty($arrayfields['p.multicurrency_total_ht_invoiced']['checked'])) print_liste_field_titre($arrayfields['p.multicurrency_total_ht_invoiced']['label'], $_SERVER["PHP_SELF"], '', '', $param, 'class="right"', $sortfield, $sortorder); if (!empty($arrayfields['p.multicurrency_total_invoiced']['checked'])) print_liste_field_titre($arrayfields['p.multicurrency_total_invoiced']['label'], $_SERVER["PHP_SELF"], '', '', $param, 'class="right"', $sortfield, $sortorder); @@ -1267,12 +1267,12 @@ if ($resql) $totalarray['val']['p.total_ht'] += $obj->total_ht; } // Amount VAT - if (!empty($arrayfields['p.total_vat']['checked'])) + if (!empty($arrayfields['p.total_tva']['checked'])) { - print ''.price($obj->total_vat)."\n"; + print ''.price($obj->total_tva)."\n"; if (!$i) $totalarray['nbfield']++; - if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'p.total_vat'; - $totalarray['val']['p.total_vat'] += $obj->total_vat; + if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'p.total_tva'; + $totalarray['val']['p.total_tva'] += $obj->total_tva; } // Amount TTC if (!empty($arrayfields['p.total_ttc']['checked'])) @@ -1320,9 +1320,9 @@ if ($resql) if (!$i) $totalarray['nbfield']++; } // Amount VAT - if (!empty($arrayfields['p.multicurrency_total_vat']['checked'])) + if (!empty($arrayfields['p.multicurrency_total_tva']['checked'])) { - print ''.price($obj->multicurrency_total_vat)."\n"; + print ''.price($obj->multicurrency_total_tva)."\n"; if (!$i) $totalarray['nbfield']++; } // Amount TTC diff --git a/htdocs/install/mysql/migration/13.0.0-14.0.0.sql b/htdocs/install/mysql/migration/13.0.0-14.0.0.sql index f2be5893c0a..49809f2de91 100644 --- a/htdocs/install/mysql/migration/13.0.0-14.0.0.sql +++ b/htdocs/install/mysql/migration/13.0.0-14.0.0.sql @@ -170,3 +170,6 @@ INSERT INTO llx_c_email_templates (entity, module, type_template, lang, private, INSERT INTO llx_c_email_templates (entity, module, type_template, lang, private, fk_user, datec, tms, label, position, active, topic, content, content_lines, enabled, joinfiles) values (0, '', 'eventorganization_send', '', 0, null, null, '2021-02-14 14:42:41', 'EventOrganizationEmailSubsEvent', 40, 1, '[__[MAIN_INFO_SOCIETE_NOM]__] __(EventOrganizationEmailSubsEvent)__', '__(Hello)__ __THIRDPARTY_NAME__,

__(ThisIsContentOfYourOragnisationEventEventSubscriptionWasReceived)__

__ONLINE_PAYMENT_TEXT_AND_URL__


__(Sincerely)__
__USER_SIGNATURE__', null, '1', null); INSERT INTO llx_c_email_templates (entity, module, type_template, lang, private, fk_user, datec, tms, label, position, active, topic, content, content_lines, enabled, joinfiles) values (0, '', 'eventorganization_send', '', 0, null, null, '2021-02-14 14:42:41', 'EventOrganizationMassEmailAttendes', 50, 1, '[__[MAIN_INFO_SOCIETE_NOM]__] __(EventOrganizationMassEmailAttendes)__', '__(Hello)__ __THIRDPARTY_NAME__,

__(ThisIsContentOfYourOragnisationEventBulkMailToAttendes)__

__(Sincerely)__
__USER_SIGNATURE__', null, '1', null); INSERT INTO llx_c_email_templates (entity, module, type_template, lang, private, fk_user, datec, tms, label, position, active, topic, content, content_lines, enabled, joinfiles) values (0, '', 'eventorganization_send', '', 0, null, null, '2021-02-14 14:42:41', 'EventOrganizationMassEmailSpeakers', 60, 1, '[__[MAIN_INFO_SOCIETE_NOM]__] __(EventOrganizationMassEmailSpeakers)__', '__(Hello)__ __THIRDPARTY_NAME__,

__(ThisIsContentOfYourOragnisationEventBulkMailToSpeakers)__

__(Sincerely)__
__USER_SIGNATURE__', null, '1', null); + +-- Uniformize field total_ht, total_tva, total_ttc +ALTER TABLE llx_propal CHANGE COLUMN tva total_tva double(24,8) default 0; diff --git a/htdocs/install/mysql/tables/llx_propal.sql b/htdocs/install/mysql/tables/llx_propal.sql index 6e3e38dffd6..0a348c6aa6c 100644 --- a/htdocs/install/mysql/tables/llx_propal.sql +++ b/htdocs/install/mysql/tables/llx_propal.sql @@ -48,7 +48,7 @@ create table llx_propal remise_absolue real DEFAULT 0, -- remise globale absolue (obsolete) remise real DEFAULT 0, -- remise calculee (obsolete) total_ht double(24,8) DEFAULT 0, -- montant total ht apres remise globale - tva double(24,8) DEFAULT 0, -- montant total tva apres remise globale + total_tva double(24,8) DEFAULT 0, -- montant total tva apres remise globale localtax1 double(24,8) DEFAULT 0, -- amount total localtax1 localtax2 double(24,8) DEFAULT 0, -- amount total localtax2 total double(24,8) DEFAULT 0, -- montant total ttc apres remise globale @@ -76,9 +76,9 @@ create table llx_propal fk_delivery_address integer, -- delivery address (deprecated) fk_multicurrency integer, - multicurrency_code varchar(255), + multicurrency_code varchar(255), multicurrency_tx double(24,8) DEFAULT 1, - multicurrency_total_ht double(24,8) DEFAULT 0, + multicurrency_total_ht double(24,8) DEFAULT 0, multicurrency_total_tva double(24,8) DEFAULT 0, multicurrency_total_ttc double(24,8) DEFAULT 0 )ENGINE=innodb; From 041390dc2242745efe913e076e7629558240bc3d Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Fri, 19 Feb 2021 06:49:24 +0100 Subject: [PATCH 05/36] Code enhanced - Standardize field name #14697 --- ChangeLog | 1 + htdocs/comm/propal/class/propal.class.php | 14 ++++---------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5b73c4b2212..de736200364 100644 --- a/ChangeLog +++ b/ChangeLog @@ -19,6 +19,7 @@ WARNING: Following changes may create regressions for some external modules, but were necessary to make Dolibarr better: * The ICS value for direct debit or credit transfer is now store on each bank account instead of into the global setup. * API /setup/shipment_methods has been replaced with API /setup/shipping_methods +* Field tva move to total_tva in llx_propal diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 51ec7e6e53a..aadc1f55281 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -185,12 +185,6 @@ class Propal extends CommonObject */ public $total; - public $total_ht = 0; - public $total_tva = 0; - public $total_localtax1 = 0; - public $total_localtax2 = 0; - public $total_ttc = 0; - public $cond_reglement_code; public $mode_reglement_code; public $remise = 0; @@ -1044,7 +1038,7 @@ class Propal extends CommonObject $sql .= ", remise"; $sql .= ", remise_percent"; $sql .= ", remise_absolue"; - $sql .= ", tva"; + $sql .= ", total_tva"; $sql .= ", total"; $sql .= ", datep"; $sql .= ", datec"; @@ -1431,7 +1425,7 @@ class Propal extends CommonObject public function fetch($rowid, $ref = '', $ref_ext = '') { $sql = "SELECT p.rowid, p.ref, p.entity, p.remise, p.remise_percent, p.remise_absolue, p.fk_soc"; - $sql .= ", p.total, p.tva, p.localtax1, p.localtax2, p.total_ht"; + $sql .= ", p.total, p.total_tva, p.localtax1, p.localtax2, p.total_ht"; $sql .= ", p.datec"; $sql .= ", p.date_valid as datev"; $sql .= ", p.datep as dp"; @@ -1489,7 +1483,7 @@ class Propal extends CommonObject $this->remise_absolue = $obj->remise_absolue; $this->total = $obj->total; // TODO deprecated $this->total_ht = $obj->total_ht; - $this->total_tva = $obj->tva; + $this->total_tva = $obj->total_tva; $this->total_localtax1 = $obj->localtax1; $this->total_localtax2 = $obj->localtax2; $this->total_ttc = $obj->total; @@ -1624,7 +1618,7 @@ class Propal extends CommonObject $sql .= " datep=".(strval($this->date) != '' ? "'".$this->db->idate($this->date)."'" : 'null').","; if (!empty($this->fin_validite)) $sql .= " fin_validite=".(strval($this->fin_validite) != '' ? "'".$this->db->idate($this->fin_validite)."'" : 'null').","; $sql .= " date_valid=".(strval($this->date_validation) != '' ? "'".$this->db->idate($this->date_validation)."'" : 'null').","; - $sql .= " tva=".(isset($this->total_tva) ? $this->total_tva : "null").","; + $sql .= " total_tva=".(isset($this->total_tva) ? $this->total_tva : "null").","; $sql .= " localtax1=".(isset($this->total_localtax1) ? $this->total_localtax1 : "null").","; $sql .= " localtax2=".(isset($this->total_localtax2) ? $this->total_localtax2 : "null").","; $sql .= " total_ht=".(isset($this->total_ht) ? $this->total_ht : "null").","; From 708a9fb453cd3d14a93bb06e52efb36c4ff6c926 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Fri, 19 Feb 2021 21:57:54 +0100 Subject: [PATCH 06/36] Code enhanced - Standardize field name --- htdocs/core/class/commonobject.class.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 08391a4a797..367ca1cc813 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -3230,7 +3230,10 @@ abstract class CommonObject // Specific code for backward compatibility with old field names if ($this->element == 'facture' || $this->element == 'facturerec') $fieldht = 'total'; if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') $fieldtva = 'total_tva'; - if ($this->element == 'propal') $fieldttc = 'total'; + if ($this->element == 'propal') { + $fieldttc = 'total'; + $fieldtva = 'total_tva'; + } if ($this->element == 'expensereport') $fieldtva = 'total_tva'; if ($this->element == 'supplier_proposal') $fieldttc = 'total'; From 1e3ae8348ae15f27de0c6ba4681e114501790e2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Fri, 19 Feb 2021 23:16:56 +0100 Subject: [PATCH 07/36] use cache --- htdocs/core/lib/company.lib.php | 49 +++++++--- htdocs/core/lib/memory.lib.php | 153 +++++++++++++++++--------------- 2 files changed, 121 insertions(+), 81 deletions(-) diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 1fd7b653925..c4565a5660c 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -304,16 +304,45 @@ function societe_prepare_head(Societe $object) $head[$h][0] = DOL_URL_ROOT.'/societe/agenda.php?socid='.$object->id; $head[$h][1] = $langs->trans("Events"); if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) { - $nbEvent = 0; - $sql = "SELECT COUNT(id) as nb"; - $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm"; - $sql .= " WHERE fk_soc = ".$object->id; - $resql = $db->query($sql); - if ($resql) { - $obj = $db->fetch_object($resql); - $nbEvent = $obj->nb; - } else { - dol_print_error($db); + // Enable caching of count actioncomm + $usecachekey = ''; + $found = false; + if (!empty($conf->memcached->enabled) && !empty($conf->global->MEMCACHED_SERVER)) { + // Using a memcached/memcache server + $usecachekey = 'count_event_'.$object->id; + } elseif (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x02)) { + // Using cache with shmop + $usecachekey = 'count_event_'.$object->id; + } + if ($usecachekey) { + require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php'; + $dataretrieved = dol_getcache($usecachekey); + if (is_array($dataretrieved) && count($dataretrieved)) { + $nbEvent = $dataretrieved[$usecachekey]; + $found = true; + } + } + if (!$found) { + $nbEvent = 0; + $sql = "SELECT COUNT(id) as nb"; + $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm"; + $sql .= " WHERE fk_soc = ".$object->id; + $resql = $db->query($sql); + if ($resql) { + $obj = $db->fetch_object($resql); + $nbEvent = $obj->nb; + } else { + dol_syslog('Failed to count actioncomm '.$db->lasterror(), LOG_ERR); + } + if ($usecachekey) { + $datatocache = array(); + $datatocache[$usecachekey] = $nbEvent; + $ressetcache = dol_setcache($usecachekey, $datatocache); + if ($ressetcache < 0) { + $error = 'Failed to set cache for usecachekey='.$usecachekey.' result='.$ressetcache; + dol_syslog($error, LOG_ERR); + } + } } $head[$h][1] .= '/'; $head[$h][1] .= $langs->trans("Agenda"); diff --git a/htdocs/core/lib/memory.lib.php b/htdocs/core/lib/memory.lib.php index 7b863391b24..ccf2ce7ce12 100644 --- a/htdocs/core/lib/memory.lib.php +++ b/htdocs/core/lib/memory.lib.php @@ -1,5 +1,6 @@ + * Copyright (C) 2021 Frédéric France * * 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 @@ -23,11 +24,34 @@ global $shmkeys, $shmoffset; -$shmkeys = array('main'=>1, 'admin'=>2, 'dict'=>3, 'companies'=>4, 'suppliers'=>5, 'products'=>6, - 'commercial'=>7, 'compta'=>8, 'projects'=>9, 'cashdesk'=>10, 'agenda'=>11, 'bills'=>12, - 'propal'=>13, 'boxes'=>14, 'banks'=>15, 'other'=>16, 'errors'=>17, 'members'=>18, 'ecm'=>19, - 'orders'=>20, 'users'=>21, 'help'=>22, 'stocks'=>23, 'interventions'=>24, - 'donations'=>25, 'contracts'=>26); +$shmkeys = array( + 'main' => 1, + 'admin' => 2, + 'dict' => 3, + 'companies' => 4, + 'suppliers' => 5, + 'products' => 6, + 'commercial' => 7, + 'compta' => 8, + 'projects' => 9, + 'cashdesk' => 10, + 'agenda' => 11, + 'bills' => 12, + 'propal' => 13, + 'boxes' => 14, + 'banks' => 15, + 'other' => 16, + 'errors' => 17, + 'members' => 18, + 'ecm' => 19, + 'orders' => 20, + 'users' => 21, + 'help' => 22, + 'stocks' => 23, + 'interventions' => 24, + 'donations' => 25, + 'contracts' => 26, +); $shmoffset = 1000; // Max number of entries found into a language file. If too low, some entries will be overwritten. @@ -44,51 +68,45 @@ function dol_setcache($memoryid, $data) global $conf; $result = 0; - // Using a memcached server - if (!empty($conf->memcached->enabled) && class_exists('Memcached')) - { + if (!empty($conf->memcached->enabled) && class_exists('Memcached')) { + // Using a memcached server global $dolmemcache; - if (empty($dolmemcache) || !is_object($dolmemcache)) - { - $dolmemcache = new Memcached(); - $tmparray = explode(':', $conf->global->MEMCACHED_SERVER); - $result = $dolmemcache->addServer($tmparray[0], $tmparray[1] ? $tmparray[1] : 11211); - if (!$result) return -1; - } + if (empty($dolmemcache) || !is_object($dolmemcache)) { + $dolmemcache = new Memcached(); + $tmparray = explode(':', $conf->global->MEMCACHED_SERVER); + $result = $dolmemcache->addServer($tmparray[0], $tmparray[1] ? $tmparray[1] : 11211); + if (!$result) return -1; + } - $memoryid = session_name().'_'.$memoryid; + $memoryid = session_name() . '_' . $memoryid; //$dolmemcache->setOption(Memcached::OPT_COMPRESSION, false); $dolmemcache->add($memoryid, $data); // This fails if key already exists $rescode = $dolmemcache->getResultCode(); - if ($rescode == 0) - { + if ($rescode == 0) { return count($data); } else { return -$rescode; } - } elseif (!empty($conf->memcached->enabled) && class_exists('Memcache')) - { + } elseif (!empty($conf->memcached->enabled) && class_exists('Memcache')) { + // Using a memcache server global $dolmemcache; - if (empty($dolmemcache) || !is_object($dolmemcache)) - { - $dolmemcache = new Memcache(); - $tmparray = explode(':', $conf->global->MEMCACHED_SERVER); - $result = $dolmemcache->addServer($tmparray[0], $tmparray[1] ? $tmparray[1] : 11211); - if (!$result) return -1; - } + if (empty($dolmemcache) || !is_object($dolmemcache)) { + $dolmemcache = new Memcache(); + $tmparray = explode(':', $conf->global->MEMCACHED_SERVER); + $result = $dolmemcache->addServer($tmparray[0], $tmparray[1] ? $tmparray[1] : 11211); + if (!$result) return -1; + } - $memoryid = session_name().'_'.$memoryid; + $memoryid = session_name() . '_' . $memoryid; //$dolmemcache->setOption(Memcached::OPT_COMPRESSION, false); $result = $dolmemcache->add($memoryid, $data); // This fails if key already exists - if ($result) - { + if ($result) { return count($data); } else { return -1; } - } // Using shmop - elseif (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x02)) - { + } elseif (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x02)) { + // Using shmop $result = dol_setshmop($memoryid, $data); } @@ -106,55 +124,48 @@ function dol_getcache($memoryid) global $conf; // Using a memcached server - if (!empty($conf->memcached->enabled) && class_exists('Memcached')) - { + if (!empty($conf->memcached->enabled) && class_exists('Memcached')) { global $m; - if (empty($m) || !is_object($m)) - { + if (empty($m) || !is_object($m)) { $m = new Memcached(); - $tmparray = explode(':', $conf->global->MEMCACHED_SERVER); - $result = $m->addServer($tmparray[0], $tmparray[1] ? $tmparray[1] : 11211); - if (!$result) return -1; - } + $tmparray = explode(':', $conf->global->MEMCACHED_SERVER); + $result = $m->addServer($tmparray[0], $tmparray[1] ? $tmparray[1] : 11211); + if (!$result) return -1; + } - $memoryid = session_name().'_'.$memoryid; + $memoryid = session_name() . '_' . $memoryid; //$m->setOption(Memcached::OPT_COMPRESSION, false); //print "Get memoryid=".$memoryid; $data = $m->get($memoryid); $rescode = $m->getResultCode(); //print "memoryid=".$memoryid." - rescode=".$rescode." - data=".count($data)."\n
"; //var_dump($data); - if ($rescode == 0) - { + if ($rescode == 0) { return $data; } else { return -$rescode; } - } elseif (!empty($conf->memcached->enabled) && class_exists('Memcache')) - { + } elseif (!empty($conf->memcached->enabled) && class_exists('Memcache')) { global $m; - if (empty($m) || !is_object($m)) - { - $m = new Memcache(); - $tmparray = explode(':', $conf->global->MEMCACHED_SERVER); - $result = $m->addServer($tmparray[0], $tmparray[1] ? $tmparray[1] : 11211); - if (!$result) return -1; - } + if (empty($m) || !is_object($m)) { + $m = new Memcache(); + $tmparray = explode(':', $conf->global->MEMCACHED_SERVER); + $result = $m->addServer($tmparray[0], $tmparray[1] ? $tmparray[1] : 11211); + if (!$result) return -1; + } - $memoryid = session_name().'_'.$memoryid; + $memoryid = session_name() . '_' . $memoryid; //$m->setOption(Memcached::OPT_COMPRESSION, false); $data = $m->get($memoryid); //print "memoryid=".$memoryid." - rescode=".$rescode." - data=".count($data)."\n
"; //var_dump($data); - if ($data) - { + if ($data) { return $data; } else { return -1; } - } // Using shmop - elseif (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x02)) - { + } elseif (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x02)) { + // Using shmop $data = dol_getshmop($memoryid); return $data; } @@ -173,7 +184,9 @@ function dol_getcache($memoryid) function dol_getshmopaddress($memoryid) { global $shmkeys, $shmoffset; - if (empty($shmkeys[$memoryid])) return 0; + if (empty($shmkeys[$memoryid])) { + return 0; + } return $shmkeys[$memoryid] + $shmoffset; } @@ -187,10 +200,11 @@ function dol_listshmop() global $shmkeys, $shmoffset; $resarray = array(); - foreach ($shmkeys as $key => $val) - { + foreach ($shmkeys as $key => $val) { $result = dol_getshmop($key); - if (!is_numeric($result) || $result > 0) $resarray[$key] = $result; + if (!is_numeric($result) || $result > 0) { + $resarray[$key] = $result; + } } return $resarray; } @@ -213,18 +227,16 @@ function dol_setshmop($memoryid, $data) $size = strlen($newdata); //print 'dol_setshmop memoryid='.$memoryid." shmkey=".$shmkey." newdata=".$size."bytes
\n"; $handle = shmop_open($shmkey, 'c', 0644, 6 + $size); - if ($handle) - { + if ($handle) { $shm_bytes_written1 = shmop_write($handle, str_pad($size, 6), 0); $shm_bytes_written2 = shmop_write($handle, $newdata, 6); - if (($shm_bytes_written1 + $shm_bytes_written2) != (6 + dol_strlen($newdata))) - { - print "Couldn't write the entire length of data\n"; + if (($shm_bytes_written1 + $shm_bytes_written2) != (6 + dol_strlen($newdata))) { + print "Couldn't write the entire length of data\n"; } shmop_close($handle); return ($shm_bytes_written1 + $shm_bytes_written2); } else { - print 'Error in shmop_open for memoryid='.$memoryid.' shmkey='.$shmkey.' 6+size=6+'.$size; + print 'Error in shmop_open for memoryid=' . $memoryid . ' shmkey=' . $shmkey . ' 6+size=6+' . $size; return -1; } } @@ -243,8 +255,7 @@ function dol_getshmop($memoryid) $shmkey = dol_getshmopaddress($memoryid); //print 'dol_getshmop memoryid='.$memoryid." shmkey=".$shmkey."
\n"; $handle = @shmop_open($shmkey, 'a', 0, 0); - if ($handle) - { + if ($handle) { $size = trim(shmop_read($handle, 0, 6)); if ($size) $data = unserialize(shmop_read($handle, 6, $size)); else return -1; From fe1aedd825c627d47e47a28bc6c74d6e42d287f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Fri, 19 Feb 2021 23:23:47 +0100 Subject: [PATCH 08/36] restore file --- htdocs/comm/action/index.php | 154 +++++++++++++++++++++-------------- 1 file changed, 95 insertions(+), 59 deletions(-) diff --git a/htdocs/comm/action/index.php b/htdocs/comm/action/index.php index e66f84f9987..f9274189109 100644 --- a/htdocs/comm/action/index.php +++ b/htdocs/comm/action/index.php @@ -114,8 +114,7 @@ if ($status == '' && !GETPOSTISSET('search_status')) $status = (empty($conf->glo $defaultview = (empty($conf->global->AGENDA_DEFAULT_VIEW) ? 'show_month' : $conf->global->AGENDA_DEFAULT_VIEW); $defaultview = (empty($user->conf->AGENDA_DEFAULT_VIEW) ? $defaultview : $user->conf->AGENDA_DEFAULT_VIEW); if (empty($action) && !GETPOSTISSET('action')) $action = $defaultview; -if ($action == 'default') // When action is default, we want a calendar view and not the list -{ +if ($action == 'default') { // When action is default, we want a calendar view and not the list $action = (($defaultview != 'show_list') ? $defaultview : 'show_month'); } if (GETPOST('viewcal', 'restricthtml') && GETPOST('action', 'alpha') != 'show_day' && GETPOST('action', 'alpha') != 'show_week') { @@ -488,8 +487,8 @@ if (!empty($conf->use_javascript_ajax)) // If javascript on $s .= "\n".''."\n"; $s .= ''."\n"; } @@ -1951,7 +1988,6 @@ function sort_events_by_date($a, $b) { return -1; } - if ($b->type_code === 'HOLIDAY') { return 1; From 1017d480f927034b623e61087a19ae06cb940e71 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sat, 20 Feb 2021 07:08:37 +0100 Subject: [PATCH 09/36] Code enhanced - Standardize field name #14697 --- ChangeLog | 3 ++- htdocs/core/class/commonobject.class.php | 2 +- .../install/mysql/migration/13.0.0-14.0.0.sql | 4 ++++ .../mysql/tables/llx_supplier_proposal.sql | 4 ++-- .../class/supplier_proposal.class.php | 13 ++++++------ htdocs/supplier_proposal/list.php | 20 +++++++++---------- 6 files changed, 25 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7c88dec9f5e..795379c40ab 100644 --- a/ChangeLog +++ b/ChangeLog @@ -19,7 +19,8 @@ WARNING: Following changes may create regressions for some external modules, but were necessary to make Dolibarr better: * The ICS value for direct debit or credit transfer is now store on each bank account instead of into the global setup. * API /setup/shipment_methods has been replaced with API /setup/shipping_methods - +* Field tva move to total_tva in llx_supplier_proposal +* Field total move to total_ttc in llx_supplier_proposal ***** ChangeLog for 13.0.1 compared to 13.0.0 ***** diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 0c0de66840b..335c56e989f 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -3232,7 +3232,7 @@ abstract class CommonObject if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') $fieldtva = 'total_tva'; if ($this->element == 'propal') $fieldttc = 'total'; if ($this->element == 'expensereport') $fieldtva = 'total_tva'; - if ($this->element == 'supplier_proposal') $fieldttc = 'total'; + if ($this->element == 'supplier_proposal') $fieldtva = 'total_tva'; if (empty($nodatabaseupdate)) { diff --git a/htdocs/install/mysql/migration/13.0.0-14.0.0.sql b/htdocs/install/mysql/migration/13.0.0-14.0.0.sql index bf3c9183b91..c166c97428e 100644 --- a/htdocs/install/mysql/migration/13.0.0-14.0.0.sql +++ b/htdocs/install/mysql/migration/13.0.0-14.0.0.sql @@ -173,3 +173,7 @@ INSERT INTO llx_c_email_templates (entity, module, type_template, lang, private, INSERT INTO llx_c_email_templates (entity, module, type_template, lang, private, fk_user, datec, tms, label, position, active, topic, content, content_lines, enabled, joinfiles) values (0, '', 'eventorganization_send', '', 0, null, null, '2021-02-14 14:42:41', 'EventOrganizationEmailSubsEvent', 40, 1, '[__[MAIN_INFO_SOCIETE_NOM]__] __(EventOrganizationEmailSubsEvent)__', '__(Hello)__ __THIRDPARTY_NAME__,

__(ThisIsContentOfYourOragnisationEventEventSubscriptionWasReceived)__

__ONLINE_PAYMENT_TEXT_AND_URL__


__(Sincerely)__
__USER_SIGNATURE__', null, '1', null); INSERT INTO llx_c_email_templates (entity, module, type_template, lang, private, fk_user, datec, tms, label, position, active, topic, content, content_lines, enabled, joinfiles) values (0, '', 'eventorganization_send', '', 0, null, null, '2021-02-14 14:42:41', 'EventOrganizationMassEmailAttendes', 50, 1, '[__[MAIN_INFO_SOCIETE_NOM]__] __(EventOrganizationMassEmailAttendes)__', '__(Hello)__ __THIRDPARTY_NAME__,

__(ThisIsContentOfYourOragnisationEventBulkMailToAttendes)__

__(Sincerely)__
__USER_SIGNATURE__', null, '1', null); INSERT INTO llx_c_email_templates (entity, module, type_template, lang, private, fk_user, datec, tms, label, position, active, topic, content, content_lines, enabled, joinfiles) values (0, '', 'eventorganization_send', '', 0, null, null, '2021-02-14 14:42:41', 'EventOrganizationMassEmailSpeakers', 60, 1, '[__[MAIN_INFO_SOCIETE_NOM]__] __(EventOrganizationMassEmailSpeakers)__', '__(Hello)__ __THIRDPARTY_NAME__,

__(ThisIsContentOfYourOragnisationEventBulkMailToSpeakers)__

__(Sincerely)__
__USER_SIGNATURE__', null, '1', null); + +-- Code enhanced - Standardize field name +ALTER TABLE llx_supplier_proposal CHANGE COLUMN tva total_tva double(24,8) default 0; +ALTER TABLE llx_supplier_proposal CHANGE COLUMN total total_ttc double(24,8) default 0; diff --git a/htdocs/install/mysql/tables/llx_supplier_proposal.sql b/htdocs/install/mysql/tables/llx_supplier_proposal.sql index e63c4ff64c7..cf64d76d7d1 100644 --- a/htdocs/install/mysql/tables/llx_supplier_proposal.sql +++ b/htdocs/install/mysql/tables/llx_supplier_proposal.sql @@ -37,10 +37,10 @@ CREATE TABLE llx_supplier_proposal ( remise_absolue double DEFAULT 0, remise double DEFAULT 0, total_ht double(24,8) DEFAULT 0, - tva double(24,8) DEFAULT 0, + total_tva double(24,8) DEFAULT 0, localtax1 double(24,8) DEFAULT 0, localtax2 double(24,8) DEFAULT 0, - total double(24,8) DEFAULT 0, + total_ttc double(24,8) DEFAULT 0, fk_account integer DEFAULT NULL, fk_currency varchar(3) DEFAULT NULL, fk_cond_reglement integer DEFAULT NULL, diff --git a/htdocs/supplier_proposal/class/supplier_proposal.class.php b/htdocs/supplier_proposal/class/supplier_proposal.class.php index 405c34734f3..c56fac31a3f 100644 --- a/htdocs/supplier_proposal/class/supplier_proposal.class.php +++ b/htdocs/supplier_proposal/class/supplier_proposal.class.php @@ -906,8 +906,8 @@ class SupplierProposal extends CommonObject $sql .= ", remise"; $sql .= ", remise_percent"; $sql .= ", remise_absolue"; - $sql .= ", tva"; - $sql .= ", total"; + $sql .= ", total_tva"; + $sql .= ", total_ttc"; $sql .= ", datec"; $sql .= ", ref"; $sql .= ", fk_user_author"; @@ -1200,7 +1200,7 @@ class SupplierProposal extends CommonObject global $conf; $sql = "SELECT p.rowid, p.entity, p.ref, p.remise, p.remise_percent, p.remise_absolue, p.fk_soc"; - $sql .= ", p.total, p.tva, p.localtax1, p.localtax2, p.total_ht"; + $sql .= ", p.total_ttc, p.total_tva, p.localtax1, p.localtax2, p.total_ht"; $sql .= ", p.datec"; $sql .= ", p.date_valid as datev"; $sql .= ", p.date_livraison as delivery_date"; @@ -1239,12 +1239,11 @@ class SupplierProposal extends CommonObject $this->remise = $obj->remise; $this->remise_percent = $obj->remise_percent; $this->remise_absolue = $obj->remise_absolue; - $this->total = $obj->total; // TODO deprecated $this->total_ht = $obj->total_ht; - $this->total_tva = $obj->tva; + $this->total_tva = $obj->total_tva; $this->total_localtax1 = $obj->localtax1; $this->total_localtax2 = $obj->localtax2; - $this->total_ttc = $obj->total; + $this->total_ttc = $obj->total_ttc; $this->socid = $obj->fk_soc; $this->fk_project = $obj->fk_project; $this->model_pdf = $obj->model_pdf; @@ -2784,7 +2783,7 @@ class SupplierProposalLine extends CommonObjectLine // Bit 0: 0 si TVA normal - 1 si TVA NPR // Bit 1: 0 ligne normale - 1 si ligne de remise fixe - public $total_ht; // Total HT de la ligne toute quantite et incluant la remise ligne + public $total_ht; // Total HT de la ligne toute quantite et incluant la remise ligne public $total_tva; // Total TVA de la ligne toute quantite et incluant la remise ligne public $total_ttc; // Total TTC de la ligne toute quantite et incluant la remise ligne diff --git a/htdocs/supplier_proposal/list.php b/htdocs/supplier_proposal/list.php index 9826c2a409d..04bafe19297 100644 --- a/htdocs/supplier_proposal/list.php +++ b/htdocs/supplier_proposal/list.php @@ -152,7 +152,7 @@ $arrayfields = array( 'sp.date_valid'=>array('label'=>$langs->trans("Date"), 'checked'=>1), 'sp.date_livraison'=>array('label'=>$langs->trans("DateEnd"), 'checked'=>1), 'sp.total_ht'=>array('label'=>$langs->trans("AmountHT"), 'checked'=>1), - 'sp.total_vat'=>array('label'=>$langs->trans("AmountVAT"), 'checked'=>0), + 'sp.total_tva'=>array('label'=>$langs->trans("AmountVAT"), 'checked'=>0), 'sp.total_ttc'=>array('label'=>$langs->trans("AmountTTC"), 'checked'=>0), 'sp.multicurrency_code'=>array('label'=>'Currency', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)), 'sp.multicurrency_tx'=>array('label'=>'CurrencyRate', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)), @@ -253,7 +253,7 @@ if ($sall || $search_product_category > 0 || $search_user > 0) $sql = 'SELECT DI $sql .= ' s.rowid as socid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s.code_client,'; $sql .= " typent.code as typent_code,"; $sql .= " state.code_departement as state_code, state.nom as state_name,"; -$sql .= ' sp.rowid, sp.note_private, sp.total_ht, sp.tva as total_vat, sp.total as total_ttc, sp.localtax1, sp.localtax2, sp.ref, sp.fk_statut as status, sp.fk_user_author, sp.date_valid, sp.date_livraison as dp,'; +$sql .= ' sp.rowid, sp.note_private, sp.total_ht, sp.total_tva, sp.total_ttc, sp.localtax1, sp.localtax2, sp.ref, sp.fk_statut as status, sp.fk_user_author, sp.date_valid, sp.date_livraison as dp,'; $sql .= ' sp.fk_multicurrency, sp.multicurrency_code, sp.multicurrency_tx, sp.multicurrency_total_ht, sp.multicurrency_total_tva as multicurrency_total_vat, sp.multicurrency_total_ttc,'; $sql .= ' sp.datec as date_creation, sp.tms as date_update,'; $sql .= " p.rowid as project_id, p.ref as project_ref,"; @@ -299,8 +299,8 @@ if ($search_ref) $sql .= natural_search('sp.ref', $search_ref); if ($search_societe) $sql .= natural_search('s.nom', $search_societe); if ($search_login) $sql .= natural_search('u.login', $search_login); if ($search_montant_ht) $sql .= natural_search('sp.total_ht=', $search_montant_ht, 1); -if ($search_montant_vat != '') $sql .= natural_search("sp.tva", $search_montant_vat, 1); -if ($search_montant_ttc != '') $sql .= natural_search("sp.total", $search_montant_ttc, 1); +if ($search_montant_vat != '') $sql .= natural_search("sp.total_tva", $search_montant_vat, 1); +if ($search_montant_ttc != '') $sql .= natural_search("sp.total_ttc", $search_montant_ttc, 1); if ($search_multicurrency_code != '') $sql .= ' AND sp.multicurrency_code = "'.$db->escape($search_multicurrency_code).'"'; if ($search_multicurrency_tx != '') $sql .= natural_search('sp.multicurrency_tx', $search_multicurrency_tx, 1); if ($search_multicurrency_montant_ht != '') $sql .= natural_search('sp.multicurrency_total_ht', $search_multicurrency_montant_ht, 1); @@ -552,7 +552,7 @@ if ($resql) print ''; print ''; } - if (!empty($arrayfields['sp.total_vat']['checked'])) + if (!empty($arrayfields['sp.total_tva']['checked'])) { // Amount print ''; @@ -653,7 +653,7 @@ if ($resql) if (!empty($arrayfields['sp.date_valid']['checked'])) print_liste_field_titre($arrayfields['sp.date_valid']['label'], $_SERVER["PHP_SELF"], 'sp.date_valid', '', $param, '', $sortfield, $sortorder, 'center '); if (!empty($arrayfields['sp.date_livraison']['checked'])) print_liste_field_titre($arrayfields['sp.date_livraison']['label'], $_SERVER["PHP_SELF"], 'sp.date_livraison', '', $param, '', $sortfield, $sortorder, 'center '); if (!empty($arrayfields['sp.total_ht']['checked'])) print_liste_field_titre($arrayfields['sp.total_ht']['label'], $_SERVER["PHP_SELF"], 'sp.total_ht', '', $param, '', $sortfield, $sortorder, 'right '); - if (!empty($arrayfields['sp.total_vat']['checked'])) print_liste_field_titre($arrayfields['sp.total_vat']['label'], $_SERVER["PHP_SELF"], 'sp.total_vat', '', $param, '', $sortfield, $sortorder, 'right '); + if (!empty($arrayfields['sp.total_tva']['checked'])) print_liste_field_titre($arrayfields['sp.total_tva']['label'], $_SERVER["PHP_SELF"], 'sp.total_tva', '', $param, '', $sortfield, $sortorder, 'right '); if (!empty($arrayfields['sp.total_ttc']['checked'])) print_liste_field_titre($arrayfields['sp.total_ttc']['label'], $_SERVER["PHP_SELF"], 'sp.total_ttc', '', $param, '', $sortfield, $sortorder, 'right '); if (!empty($arrayfields['sp.multicurrency_code']['checked'])) print_liste_field_titre($arrayfields['sp.multicurrency_code']['label'], $_SERVER['PHP_SELF'], 'sp.multicurrency_code', '', $param, '', $sortfield, $sortorder); if (!empty($arrayfields['sp.multicurrency_tx']['checked'])) print_liste_field_titre($arrayfields['sp.multicurrency_tx']['label'], $_SERVER['PHP_SELF'], 'sp.multicurrency_tx', '', $param, '', $sortfield, $sortorder); @@ -803,12 +803,12 @@ if ($resql) $totalarray['val']['sp.total_ht'] += $obj->total_ht; } // Amount VAT - if (!empty($arrayfields['sp.total_vat']['checked'])) + if (!empty($arrayfields['sp.total_tva']['checked'])) { - print ''.price($obj->total_vat)."\n"; + print ''.price($obj->total_tva)."\n"; if (!$i) $totalarray['nbfield']++; - if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'sp.total_vat'; - $totalarray['val']['sp.total_vat'] += $obj->total_vat; + if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'sp.total_tva'; + $totalarray['val']['sp.total_tva'] += $obj->total_tva; } // Amount TTC if (!empty($arrayfields['sp.total_ttc']['checked'])) From 99fa13cbad65518977c6746e68e0fa9e5ed9159c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sat, 20 Feb 2021 15:41:57 +0100 Subject: [PATCH 10/36] enhance caching --- htdocs/core/lib/company.lib.php | 200 +++++++++++++++++++++----------- 1 file changed, 131 insertions(+), 69 deletions(-) diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index c4565a5660c..7d1d9b9a709 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -7,7 +7,7 @@ * Copyright (C) 2013-2014 Juanjo Menent * Copyright (C) 2013 Christophe Battarel * Copyright (C) 2013-2018 Alexandre Spangaro - * Copyright (C) 2015-2019 Frédéric France + * Copyright (C) 2015-2021 Frédéric France * Copyright (C) 2015 Raphaël Doursenaud * Copyright (C) 2017 Rui Strecht * Copyright (C) 2018 Ferran Marcet @@ -53,20 +53,46 @@ function societe_prepare_head(Societe $object) if (empty($conf->global->MAIN_SUPPORT_SHARED_CONTACT_BETWEEN_THIRDPARTIES)) { if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->societe->contact->lire) { //$nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external')); - $nbContact = 0; // TODO - - $sql = "SELECT COUNT(p.rowid) as nb"; - $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as p"; - $sql .= " WHERE p.fk_soc = ".$object->id; - $resql = $db->query($sql); - if ($resql) { - $obj = $db->fetch_object($resql); - if ($obj) $nbContact = $obj->nb; + $nbContact = 0; + if (!empty($conf->memcached->enabled) && !empty($conf->global->MEMCACHED_SERVER)) { + // Using a memcached/memcache server + $usecachekey = 'thirdparty_countcontact_'.$object->id; + } elseif (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x02)) { + // Using cache with shmop + $usecachekey = 'thirdparty_countcontact_'.$object->id; + } + if ($usecachekey) { + require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php'; + $dataretrieved = dol_getcache($usecachekey); + if (is_array($dataretrieved) && count($dataretrieved)) { + $nbContact = $dataretrieved[$usecachekey]; + $found = true; + } + } + if (!$found) { + $sql = "SELECT COUNT(p.rowid) as nb"; + $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as p"; + $sql .= " WHERE p.fk_soc = ".$object->id; + $resql = $db->query($sql); + if ($resql) { + $obj = $db->fetch_object($resql); + $nbContact = $obj->nb; + } + if ($usecachekey) { + $datatocache = array(); + $datatocache[$usecachekey] = $nbContact; + $res_setcache = dol_setcache($usecachekey, $datatocache); + if ($res_setcache < 0) { + $error = 'Failed to set cache for usecachekey='.$usecachekey.' result='.$ressetcache; + dol_syslog($error, LOG_ERR); + } + } } - $head[$h][0] = DOL_URL_ROOT.'/societe/contact.php?socid='.$object->id; $head[$h][1] = $langs->trans('ContactsAddresses'); - if ($nbContact > 0) $head[$h][1] .= ''.$nbContact.''; + if ($nbContact > 0) { + $head[$h][1] .= ''.$nbContact.''; + } $head[$h][2] = 'contact'; $h++; } @@ -74,7 +100,9 @@ function societe_prepare_head(Societe $object) $head[$h][0] = DOL_URL_ROOT.'/societe/societecontact.php?socid='.$object->id; $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external')); $head[$h][1] = $langs->trans("ContactsAddresses"); - if ($nbContact > 0) $head[$h][1] .= ''.$nbContact.''; + if ($nbContact > 0) { + $head[$h][1] .= ''.$nbContact.''; + } $head[$h][2] = 'contact'; $h++; } @@ -82,9 +110,15 @@ function societe_prepare_head(Societe $object) if ($object->client == 1 || $object->client == 2 || $object->client == 3) { $head[$h][0] = DOL_URL_ROOT.'/comm/card.php?socid='.$object->id; $head[$h][1] = ''; - if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && ($object->client == 2 || $object->client == 3)) $head[$h][1] .= $langs->trans("Prospect"); - if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && $object->client == 3) $head[$h][1] .= ' | '; - if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && ($object->client == 1 || $object->client == 3)) $head[$h][1] .= $langs->trans("Customer"); + if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && ($object->client == 2 || $object->client == 3)) { + $head[$h][1] .= $langs->trans("Prospect"); + } + if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && $object->client == 3) { + $head[$h][1] .= ' | '; + } + if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && ($object->client == 1 || $object->client == 3)) { + $head[$h][1] .= $langs->trans("Customer"); + } $head[$h][2] = 'customer'; $h++; @@ -98,7 +132,9 @@ function societe_prepare_head(Societe $object) } } $supplier_module_enabled = 0; - if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_proposal->enabled) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) $supplier_module_enabled = 1; + if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_proposal->enabled) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) { + $supplier_module_enabled = 1; + } if ($supplier_module_enabled == 1 && $object->fournisseur && !empty($user->rights->fournisseur->lire)) { $head[$h][0] = DOL_URL_ROOT.'/fourn/card.php?socid='.$object->id; $head[$h][1] = $langs->trans("Supplier"); @@ -107,8 +143,6 @@ function societe_prepare_head(Societe $object) } if (!empty($conf->projet->enabled) && (!empty($user->rights->projet->lire))) { - $head[$h][0] = DOL_URL_ROOT.'/societe/project.php?socid='.$object->id; - $head[$h][1] = $langs->trans("Projects"); $nbNote = 0; $sql = "SELECT COUNT(n.rowid) as nb"; $sql .= " FROM ".MAIN_DB_PREFIX."projet as n"; @@ -116,17 +150,16 @@ function societe_prepare_head(Societe $object) $sql .= " AND entity IN (".getEntity('project').")"; $resql = $db->query($sql); if ($resql) { - $num = $db->num_rows($resql); - $i = 0; - while ($i < $num) { - $obj = $db->fetch_object($resql); - $nbNote = $obj->nb; - $i++; - } + $obj = $db->fetch_object($resql); + $nbNote = $obj->nb; } else { dol_print_error($db); } - if ($nbNote > 0) $head[$h][1] .= ''.$nbNote.''; + $head[$h][0] = DOL_URL_ROOT.'/societe/project.php?socid='.$object->id; + $head[$h][1] = $langs->trans("Projects"); + if ($nbNote > 0) { + $head[$h][1] .= ''.$nbNote.''; + } $head[$h][2] = 'project'; $h++; } @@ -180,12 +213,16 @@ function societe_prepare_head(Societe $object) //$title = $langs->trans("BankAccountsAndGateways"); $servicestatus = 0; - if (!empty($conf->global->STRIPE_LIVE) && !GETPOST('forcesandbox', 'alpha')) $servicestatus = 1; + if (!empty($conf->global->STRIPE_LIVE) && !GETPOST('forcesandbox', 'alpha')) { + $servicestatus = 1; + } include_once DOL_DOCUMENT_ROOT.'/societe/class/societeaccount.class.php'; $societeaccount = new SocieteAccount($db); $stripecu = $societeaccount->getCustomerAccount($object->id, 'stripe', $servicestatus); // Get thirdparty cu_... - if ($stripecu) $foundonexternalonlinesystem++; + if ($stripecu) { + $foundonexternalonlinesystem++; + } } $sql = "SELECT COUNT(n.rowid) as nb"; @@ -199,13 +236,8 @@ function societe_prepare_head(Societe $object) $resql = $db->query($sql); if ($resql) { - $num = $db->num_rows($resql); - $i = 0; - while ($i < $num) { - $obj = $db->fetch_object($resql); - $nbBankAccount = $obj->nb; - $i++; - } + $obj = $db->fetch_object($resql); + $nbBankAccount = $obj->nb; } else { dol_print_error($db); } @@ -214,8 +246,11 @@ function societe_prepare_head(Societe $object) $head[$h][0] = DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id; $head[$h][1] = $title; - if ($foundonexternalonlinesystem) $head[$h][1] .= '...'; - elseif ($nbBankAccount > 0) $head[$h][1] .= ''.$nbBankAccount.''; + if ($foundonexternalonlinesystem) { + $head[$h][1] .= '...'; + } elseif ($nbBankAccount > 0) { + $head[$h][1] .= ''.$nbBankAccount.''; + } $head[$h][2] = 'rib'; $h++; } @@ -229,17 +264,14 @@ function societe_prepare_head(Societe $object) $sql .= " WHERE fk_soc = ".$object->id.' AND fk_website > 0'; $resql = $db->query($sql); if ($resql) { - $num = $db->num_rows($resql); - $i = 0; - while ($i < $num) { - $obj = $db->fetch_object($resql); - $nbNote = $obj->nb; - $i++; - } + $obj = $db->fetch_object($resql); + $nbNote = $obj->nb; } else { dol_print_error($db); } - if ($nbNote > 0) $head[$h][1] .= ''.$nbNote.''; + if ($nbNote > 0) { + $head[$h][1] .= ''.$nbNote.''; + } $head[$h][2] = 'website'; $h++; } @@ -253,26 +285,52 @@ function societe_prepare_head(Societe $object) if ($user->socid == 0) { // Notifications if (!empty($conf->notification->enabled)) { - $nbNote = 0; - $sql = "SELECT COUNT(n.rowid) as nb"; - $sql .= " FROM ".MAIN_DB_PREFIX."notify_def as n"; - $sql .= " WHERE fk_soc = ".$object->id; - $resql = $db->query($sql); - if ($resql) { - $num = $db->num_rows($resql); - $i = 0; - while ($i < $num) { - $obj = $db->fetch_object($resql); - $nbNote = $obj->nb; - $i++; + // Enable caching of thirdrparty count notifications + $usecachekey = ''; + $found = false; + $nbNotif = 0; + if (!empty($conf->memcached->enabled) && !empty($conf->global->MEMCACHED_SERVER)) { + // Using a memcached/memcache server + $usecachekey = 'thirdparty_countnotif_'.$object->id; + } elseif (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x02)) { + // Using cache with shmop + $usecachekey = 'thirdparty_countnotif_'.$object->id; + } + if ($usecachekey) { + require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php'; + $dataretrieved = dol_getcache($usecachekey); + if (is_array($dataretrieved) && count($dataretrieved)) { + $nbNotif = $dataretrieved[$usecachekey]; + $found = true; + } + } + if (!$found) { + $sql = "SELECT COUNT(n.rowid) as nb"; + $sql .= " FROM ".MAIN_DB_PREFIX."notify_def as n"; + $sql .= " WHERE fk_soc = ".$object->id; + $resql = $db->query($sql); + if ($resql) { + $obj = $db->fetch_object($resql); + $nbNotif = $obj->nb; + } else { + dol_print_error($db); + } + if ($usecachekey) { + $datatocache = array(); + $datatocache[$usecachekey] = $nbNotif; + $res_setcache = dol_setcache($usecachekey, $datatocache); + if ($res_setcache < 0) { + $error = 'Failed to set cache for usecachekey='.$usecachekey.' result='.$ressetcache; + dol_syslog($error, LOG_ERR); + } } - } else { - dol_print_error($db); } $head[$h][0] = DOL_URL_ROOT.'/societe/notify/card.php?socid='.$object->id; $head[$h][1] = $langs->trans("Notifications"); - if ($nbNote > 0) $head[$h][1] .= ''.$nbNote.''; + if ($nbNotif > 0) { + $head[$h][1] .= ''.$nbNotif.''; + } $head[$h][2] = 'notify'; $h++; } @@ -283,7 +341,9 @@ function societe_prepare_head(Societe $object) if (!empty($object->note_public)) $nbNote++; $head[$h][0] = DOL_URL_ROOT.'/societe/note.php?id='.$object->id; $head[$h][1] = $langs->trans("Notes"); - if ($nbNote > 0) $head[$h][1] .= ''.$nbNote.''; + if ($nbNote > 0) { + $head[$h][1] .= ''.$nbNote.''; + } $head[$h][2] = 'note'; $h++; @@ -296,7 +356,9 @@ function societe_prepare_head(Societe $object) $head[$h][0] = DOL_URL_ROOT.'/societe/document.php?socid='.$object->id; $head[$h][1] = $langs->trans("Documents"); - if (($nbFiles + $nbLinks) > 0) $head[$h][1] .= ''.($nbFiles + $nbLinks).''; + if (($nbFiles + $nbLinks) > 0) { + $head[$h][1] .= ''.($nbFiles + $nbLinks).''; + } $head[$h][2] = 'document'; $h++; } @@ -304,15 +366,16 @@ function societe_prepare_head(Societe $object) $head[$h][0] = DOL_URL_ROOT.'/societe/agenda.php?socid='.$object->id; $head[$h][1] = $langs->trans("Events"); if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) { - // Enable caching of count actioncomm + // Enable caching of thirdrparty count actioncomm $usecachekey = ''; $found = false; + $nbEvent = 0; if (!empty($conf->memcached->enabled) && !empty($conf->global->MEMCACHED_SERVER)) { // Using a memcached/memcache server - $usecachekey = 'count_event_'.$object->id; + $usecachekey = 'thirdparty_countevent_'.$object->id; } elseif (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x02)) { // Using cache with shmop - $usecachekey = 'count_event_'.$object->id; + $usecachekey = 'thirdparty_countevent_'.$object->id; } if ($usecachekey) { require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php'; @@ -323,7 +386,6 @@ function societe_prepare_head(Societe $object) } } if (!$found) { - $nbEvent = 0; $sql = "SELECT COUNT(id) as nb"; $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm"; $sql .= " WHERE fk_soc = ".$object->id; @@ -337,8 +399,8 @@ function societe_prepare_head(Societe $object) if ($usecachekey) { $datatocache = array(); $datatocache[$usecachekey] = $nbEvent; - $ressetcache = dol_setcache($usecachekey, $datatocache); - if ($ressetcache < 0) { + $res_setcache = dol_setcache($usecachekey, $datatocache); + if ($res_setcache < 0) { $error = 'Failed to set cache for usecachekey='.$usecachekey.' result='.$ressetcache; dol_syslog($error, LOG_ERR); } From ec1dd40a8a5a5f15313573a4ce1c4661c19bb620 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sat, 20 Feb 2021 15:52:45 +0100 Subject: [PATCH 11/36] enhance caching --- htdocs/core/lib/company.lib.php | 49 +++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 7d1d9b9a709..2251a21e7b3 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -337,8 +337,12 @@ function societe_prepare_head(Societe $object) // Notes $nbNote = 0; - if (!empty($object->note_private)) $nbNote++; - if (!empty($object->note_public)) $nbNote++; + if (!empty($object->note_private)) { + $nbNote++; + } + if (!empty($object->note_public)) { + $nbNote++; + } $head[$h][0] = DOL_URL_ROOT.'/societe/note.php?id='.$object->id; $head[$h][1] = $langs->trans("Notes"); if ($nbNote > 0) { @@ -548,7 +552,9 @@ function getCountry($searchkey, $withcode = '', $dbtouse = 0, $outputlangs = '', } $dbtouse->free($resql); return $result; - } else dol_print_error($dbtouse, ''); + } else { + dol_print_error($dbtouse, ''); + } return 'Error'; } @@ -1000,8 +1006,8 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '') // Purge search criteria 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 $search_status = ''; - $search_name = ''; - $search_roles = array(); + $search_name = ''; + $search_roles = array(); $search_address = ''; $search_poste = ''; $search = array(); @@ -1365,14 +1371,27 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon = '', $noprin $sql .= " a.fk_contact,"; $sql .= " c.code as acode, c.libelle as alabel, c.picto as apicto,"; $sql .= " u.rowid as user_id, u.login as user_login, u.photo as user_photo, u.firstname as user_firstname, u.lastname as user_lastname"; - if (is_object($filterobj) && in_array(get_class($filterobj), array('Societe', 'Client', 'Fournisseur'))) $sql .= ", sp.lastname, sp.firstname"; - elseif (is_object($filterobj) && get_class($filterobj) == 'Dolresource') { /* Nothing */ } elseif (is_object($filterobj) && get_class($filterobj) == 'Project') { /* Nothing */ } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') $sql .= ", m.lastname, m.firstname"; - elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') $sql .= ", o.ref"; - elseif (is_object($filterobj) && get_class($filterobj) == 'Product') $sql .= ", o.ref"; - elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') $sql .= ", o.ref"; - elseif (is_object($filterobj) && get_class($filterobj) == 'BOM') $sql .= ", o.ref"; - elseif (is_object($filterobj) && get_class($filterobj) == 'Contrat') $sql .= ", o.ref"; - elseif (is_object($filterobj) && is_array($filterobj->fields) && is_array($filterobj->fields['rowid']) && is_array($filterobj->fields['ref']) && $filterobj->table_element && $filterobj->element) $sql .= ", o.ref"; + if (is_object($filterobj) && in_array(get_class($filterobj), array('Societe', 'Client', 'Fournisseur'))) { + $sql .= ", sp.lastname, sp.firstname"; + } elseif (is_object($filterobj) && get_class($filterobj) == 'Dolresource') { + /* Nothing */ + } elseif (is_object($filterobj) && get_class($filterobj) == 'Project') { + /* Nothing */ + } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') { + $sql .= ", m.lastname, m.firstname"; + } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') { + $sql .= ", o.ref"; + } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') { + $sql .= ", o.ref"; + } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') { + $sql .= ", o.ref"; + } elseif (is_object($filterobj) && get_class($filterobj) == 'BOM') { + $sql .= ", o.ref"; + } elseif (is_object($filterobj) && get_class($filterobj) == 'Contrat') { + $sql .= ", o.ref"; + } elseif (is_object($filterobj) && is_array($filterobj->fields) && is_array($filterobj->fields['rowid']) && is_array($filterobj->fields['ref']) && $filterobj->table_element && $filterobj->element) { + $sql .= ", o.ref"; + } $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u on u.rowid = a.fk_user_action"; @@ -1391,7 +1410,9 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon = '', $noprin $sql .= " ON er.resource_type = 'dolresource'"; $sql .= " AND er.element_id = a.id"; $sql .= " AND er.resource_id = ".$filterobj->id; - } elseif (is_object($filterobj) && get_class($filterobj) == 'Project') { /* Nothing */ } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') $sql .= ", ".MAIN_DB_PREFIX."adherent as m"; + } elseif (is_object($filterobj) && get_class($filterobj) == 'Project') { + /* Nothing */ + } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') $sql .= ", ".MAIN_DB_PREFIX."adherent as m"; elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') $sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as o"; elseif (is_object($filterobj) && get_class($filterobj) == 'Product') $sql .= ", ".MAIN_DB_PREFIX."product as o"; elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') $sql .= ", ".MAIN_DB_PREFIX."ticket as o"; From ade5d98d560ab3d18b7fa7ffcd47a49be90dc0c3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 20 Feb 2021 17:03:27 +0100 Subject: [PATCH 12/36] Rename script to run cron by url to avoid confusion with script from cli --- htdocs/core/lib/cron.lib.php | 4 ++-- .../cron/{cron_run_jobs.php => cron_run_jobs_by_url.php} | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename htdocs/public/cron/{cron_run_jobs.php => cron_run_jobs_by_url.php} (100%) diff --git a/htdocs/core/lib/cron.lib.php b/htdocs/core/lib/cron.lib.php index fda122be7bf..9702c8ab1dc 100644 --- a/htdocs/core/lib/cron.lib.php +++ b/htdocs/core/lib/cron.lib.php @@ -99,10 +99,10 @@ function dol_print_cron_urls() // Cron launch print '
'; print $langs->trans("URLToLaunchCronJobs").':
'; - $url = $urlwithroot.'/public/cron/cron_run_jobs.php?'.(empty($conf->global->CRON_KEY) ? '' : 'securitykey='.$conf->global->CRON_KEY.'&').'userlogin='.$user->login; + $url = $urlwithroot.'/public/cron/cron_run_jobs_by_url.php?'.(empty($conf->global->CRON_KEY) ? '' : 'securitykey='.$conf->global->CRON_KEY.'&').'userlogin='.$user->login; print img_picto('', 'globe').' '.$url."
\n"; print ' '.$langs->trans("OrToLaunchASpecificJob").'
'; - $url = $urlwithroot.'/public/cron/cron_run_jobs.php?'.(empty($conf->global->CRON_KEY) ? '' : 'securitykey='.$conf->global->CRON_KEY.'&').'userlogin='.$user->login.'&id=cronjobid'; + $url = $urlwithroot.'/public/cron/cron_run_jobs_by_url.php?'.(empty($conf->global->CRON_KEY) ? '' : 'securitykey='.$conf->global->CRON_KEY.'&').'userlogin='.$user->login.'&id=cronjobid'; print img_picto('', 'globe').' '.$url."
\n"; print '
'; print '
'; diff --git a/htdocs/public/cron/cron_run_jobs.php b/htdocs/public/cron/cron_run_jobs_by_url.php similarity index 100% rename from htdocs/public/cron/cron_run_jobs.php rename to htdocs/public/cron/cron_run_jobs_by_url.php From 57e15eb46ddc9c247a7bc408a87b16bc95e6c14e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sat, 20 Feb 2021 17:12:06 +0100 Subject: [PATCH 13/36] try to apply the advice --- htdocs/core/lib/company.lib.php | 171 ++++++++++++++------------------ 1 file changed, 77 insertions(+), 94 deletions(-) diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 2251a21e7b3..238f069c919 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -54,22 +54,12 @@ function societe_prepare_head(Societe $object) if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->societe->contact->lire) { //$nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external')); $nbContact = 0; - if (!empty($conf->memcached->enabled) && !empty($conf->global->MEMCACHED_SERVER)) { - // Using a memcached/memcache server - $usecachekey = 'thirdparty_countcontact_'.$object->id; - } elseif (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x02)) { - // Using cache with shmop - $usecachekey = 'thirdparty_countcontact_'.$object->id; - } - if ($usecachekey) { - require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php'; - $dataretrieved = dol_getcache($usecachekey); - if (is_array($dataretrieved) && count($dataretrieved)) { - $nbContact = $dataretrieved[$usecachekey]; - $found = true; - } - } - if (!$found) { + $cachekey = 'thirdparty_countcontact_'.$object->id; + require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php'; + $dataretrieved = dol_getcache($cachekey); + if (is_array($dataretrieved) && count($dataretrieved)) { + $nbContact = $dataretrieved[$cachekey]; + } else { $sql = "SELECT COUNT(p.rowid) as nb"; $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as p"; $sql .= " WHERE p.fk_soc = ".$object->id; @@ -78,14 +68,12 @@ function societe_prepare_head(Societe $object) $obj = $db->fetch_object($resql); $nbContact = $obj->nb; } - if ($usecachekey) { - $datatocache = array(); - $datatocache[$usecachekey] = $nbContact; - $res_setcache = dol_setcache($usecachekey, $datatocache); - if ($res_setcache < 0) { - $error = 'Failed to set cache for usecachekey='.$usecachekey.' result='.$ressetcache; - dol_syslog($error, LOG_ERR); - } + $datatocache = array(); + $datatocache[$cachekey] = $nbContact; + $res_setcache = dol_setcache($cachekey, $datatocache); + if ($res_setcache < 0) { + $error = 'Failed to set cache for cachekey='.$cachekey.' result='.$res_setcache; + dol_syslog($error, LOG_ERR); } } $head[$h][0] = DOL_URL_ROOT.'/societe/contact.php?socid='.$object->id; @@ -285,26 +273,14 @@ function societe_prepare_head(Societe $object) if ($user->socid == 0) { // Notifications if (!empty($conf->notification->enabled)) { - // Enable caching of thirdrparty count notifications - $usecachekey = ''; - $found = false; $nbNotif = 0; - if (!empty($conf->memcached->enabled) && !empty($conf->global->MEMCACHED_SERVER)) { - // Using a memcached/memcache server - $usecachekey = 'thirdparty_countnotif_'.$object->id; - } elseif (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x02)) { - // Using cache with shmop - $usecachekey = 'thirdparty_countnotif_'.$object->id; - } - if ($usecachekey) { - require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php'; - $dataretrieved = dol_getcache($usecachekey); - if (is_array($dataretrieved) && count($dataretrieved)) { - $nbNotif = $dataretrieved[$usecachekey]; - $found = true; - } - } - if (!$found) { + // Enable caching of thirdrparty count notifications + $cachekey = 'thirdparty_countnotif_'.$object->id; + require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php'; + $dataretrieved = dol_getcache($cachekey); + if (is_array($dataretrieved) && count($dataretrieved)) { + $nbNotif = $dataretrieved[$cachekey]; + } else { $sql = "SELECT COUNT(n.rowid) as nb"; $sql .= " FROM ".MAIN_DB_PREFIX."notify_def as n"; $sql .= " WHERE fk_soc = ".$object->id; @@ -315,17 +291,14 @@ function societe_prepare_head(Societe $object) } else { dol_print_error($db); } - if ($usecachekey) { - $datatocache = array(); - $datatocache[$usecachekey] = $nbNotif; - $res_setcache = dol_setcache($usecachekey, $datatocache); - if ($res_setcache < 0) { - $error = 'Failed to set cache for usecachekey='.$usecachekey.' result='.$ressetcache; - dol_syslog($error, LOG_ERR); - } + $datatocache = array(); + $datatocache[$cachekey] = $nbNotif; + $res_setcache = dol_setcache($cachekey, $datatocache); + if ($res_setcache < 0) { + $error = 'Failed to set cache for cachekey='.$cachekey.' result='.$res_setcache; + dol_syslog($error, LOG_ERR); } } - $head[$h][0] = DOL_URL_ROOT.'/societe/notify/card.php?socid='.$object->id; $head[$h][1] = $langs->trans("Notifications"); if ($nbNotif > 0) { @@ -371,25 +344,13 @@ function societe_prepare_head(Societe $object) $head[$h][1] = $langs->trans("Events"); if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) { // Enable caching of thirdrparty count actioncomm - $usecachekey = ''; - $found = false; $nbEvent = 0; - if (!empty($conf->memcached->enabled) && !empty($conf->global->MEMCACHED_SERVER)) { - // Using a memcached/memcache server - $usecachekey = 'thirdparty_countevent_'.$object->id; - } elseif (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x02)) { - // Using cache with shmop - $usecachekey = 'thirdparty_countevent_'.$object->id; - } - if ($usecachekey) { - require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php'; - $dataretrieved = dol_getcache($usecachekey); - if (is_array($dataretrieved) && count($dataretrieved)) { - $nbEvent = $dataretrieved[$usecachekey]; - $found = true; - } - } - if (!$found) { + $cachekey = 'thirdparty_countevent_'.$object->id; + require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php'; + $dataretrieved = dol_getcache($cachekey); + if (is_array($dataretrieved) && count($dataretrieved)) { + $nbEvent = $dataretrieved[$cachekey]; + } else { $sql = "SELECT COUNT(id) as nb"; $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm"; $sql .= " WHERE fk_soc = ".$object->id; @@ -400,14 +361,12 @@ function societe_prepare_head(Societe $object) } else { dol_syslog('Failed to count actioncomm '.$db->lasterror(), LOG_ERR); } - if ($usecachekey) { - $datatocache = array(); - $datatocache[$usecachekey] = $nbEvent; - $res_setcache = dol_setcache($usecachekey, $datatocache); - if ($res_setcache < 0) { - $error = 'Failed to set cache for usecachekey='.$usecachekey.' result='.$ressetcache; - dol_syslog($error, LOG_ERR); - } + $datatocache = array(); + $datatocache[$cachekey] = $nbEvent; + $res_setcache = dol_setcache($cachekey, $datatocache); + if ($res_setcache < 0) { + $error = 'Failed to set cache for cachekey='.$cachekey.' result='.$res_setcache; + dol_syslog($error, LOG_ERR); } } $head[$h][1] .= '/'; @@ -521,16 +480,27 @@ function getCountry($searchkey, $withcode = '', $dbtouse = 0, $outputlangs = '', // Check parameters if (empty($searchkey) && empty($searchlabel)) { - if ($withcode === 'all') return array('id'=>'', 'code'=>'', 'label'=>''); - else return ''; + if ($withcode === 'all') { + return array('id'=>'', 'code'=>'', 'label'=>''); + } else { + return ''; + } + } + if (!is_object($dbtouse)) { + $dbtouse = $db; + } + if (!is_object($outputlangs)) { + $outputlangs = $langs; } - if (!is_object($dbtouse)) $dbtouse = $db; - if (!is_object($outputlangs)) $outputlangs = $langs; $sql = "SELECT rowid, code, label FROM ".MAIN_DB_PREFIX."c_country"; - if (is_numeric($searchkey)) $sql .= " WHERE rowid=".$searchkey; - elseif (!empty($searchkey)) $sql .= " WHERE code='".$db->escape($searchkey)."'"; - else $sql .= " WHERE label='".$db->escape($searchlabel)."'"; + if (is_numeric($searchkey)) { + $sql .= " WHERE rowid=".$searchkey; + } elseif (!empty($searchkey)) { + $sql .= " WHERE code='".$db->escape($searchkey)."'"; + } else { + $sql .= " WHERE label='".$db->escape($searchlabel)."'"; + } $resql = $dbtouse->query($sql); if ($resql) { @@ -542,11 +512,17 @@ function getCountry($searchkey, $withcode = '', $dbtouse = 0, $outputlangs = '', if ($entconv) $label = ($obj->code && ($outputlangs->trans("Country".$obj->code) != "Country".$obj->code)) ? $outputlangs->trans("Country".$obj->code) : $label; else $label = ($obj->code && ($outputlangs->transnoentitiesnoconv("Country".$obj->code) != "Country".$obj->code)) ? $outputlangs->transnoentitiesnoconv("Country".$obj->code) : $label; } - if ($withcode == 1) $result = $label ? "$obj->code - $label" : "$obj->code"; - elseif ($withcode == 2) $result = $obj->code; - elseif ($withcode == 3) $result = $obj->rowid; - elseif ($withcode === 'all') $result = array('id'=>$obj->rowid, 'code'=>$obj->code, 'label'=>$label); - else $result = $label; + if ($withcode == 1) { + $result = $label ? "$obj->code - $label" : "$obj->code"; + } elseif ($withcode == 2) { + $result = $obj->code; + } elseif ($withcode == 3) { + $result = $obj->rowid; + } elseif ($withcode === 'all') { + $result = array('id'=>$obj->rowid, 'code'=>$obj->code, 'label'=>$label); + } else { + $result = $label; + } } else { $result = 'NotDefined'; } @@ -577,7 +553,9 @@ function getState($id, $withcode = '', $dbtouse = 0, $withregion = 0, $outputlan { global $db, $langs; - if (!is_object($dbtouse)) $dbtouse = $db; + if (!is_object($dbtouse)) { + $dbtouse = $db; + } $sql = "SELECT d.rowid as id, d.code_departement as code, d.nom as name, d.active, c.label as country, c.code as country_code, r.code_region as region_code, r.nom as region_name FROM"; $sql .= " ".MAIN_DB_PREFIX."c_departements as d, ".MAIN_DB_PREFIX."c_regions as r,".MAIN_DB_PREFIX."c_country as c"; @@ -640,7 +618,9 @@ function currency_name($code_iso, $withcode = '', $outputlangs = null) { global $langs, $db; - if (empty($outputlangs)) $outputlangs = $langs; + if (empty($outputlangs)) { + $outputlangs = $langs; + } $outputlangs->load("dict"); @@ -660,8 +640,11 @@ function currency_name($code_iso, $withcode = '', $outputlangs = null) if ($num) { $obj = $db->fetch_object($resql); $label = ($obj->label != '-' ? $obj->label : ''); - if ($withcode) return ($label == $code_iso) ? "$code_iso" : "$code_iso - $label"; - else return $label; + if ($withcode) { + return ($label == $code_iso) ? "$code_iso" : "$code_iso - $label"; + } else { + return $label; + } } else { return $code_iso; } From cfccc4923572186e99f0982cabd54d6283317e4e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 20 Feb 2021 17:23:03 +0100 Subject: [PATCH 14/36] Code comment --- htdocs/core/class/translate.class.php | 2 +- htdocs/core/lib/memory.lib.php | 29 ++++++++++----------------- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/htdocs/core/class/translate.class.php b/htdocs/core/class/translate.class.php index a706d9a880e..c2850990ff5 100644 --- a/htdocs/core/class/translate.class.php +++ b/htdocs/core/class/translate.class.php @@ -460,7 +460,7 @@ class Translate $tmparray = dol_getcache($usecachekey); if (is_array($tmparray) && count($tmparray)) { - $this->tab_translate += $tmparray; // Faster than array_merge($tmparray,$this->tab_translate). Note: If a valuer already exists into tab_translate, value into tmparaay is not added. + $this->tab_translate += $tmparray; // Faster than array_merge($tmparray,$this->tab_translate). Note: If a value already exists into tab_translate, value into tmparaay is not added. //print $newdomain."\n"; //var_dump($this->tab_translate); $fileread = 1; diff --git a/htdocs/core/lib/memory.lib.php b/htdocs/core/lib/memory.lib.php index 90120dc63f1..95e9aff52d3 100644 --- a/htdocs/core/lib/memory.lib.php +++ b/htdocs/core/lib/memory.lib.php @@ -36,7 +36,7 @@ $shmoffset = 1000; // Max number of entries found into a language file. If too l * Save data into a memory area shared by all users, all sessions on server * * @param string $memoryid Memory id of shared area - * @param mixed $data Data to save + * @param mixed $data Data to save. It must not be a null value. * @return int <0 if KO, Nb of bytes written if OK * @see dol_getcache() */ @@ -100,7 +100,7 @@ function dol_setcache($memoryid, $data) * Read a memory area shared by all users, all sessions on server * * @param string $memoryid Memory id of shared area - * @return int|mixed <0 if KO, data if OK + * @return int|mixed <0 if KO, data if OK, null if not found into cache * @see dol_setcache() */ function dol_getcache($memoryid) @@ -108,11 +108,9 @@ function dol_getcache($memoryid) global $conf; // Using a memcached server - if (!empty($conf->memcached->enabled) && class_exists('Memcached')) - { + if (!empty($conf->memcached->enabled) && class_exists('Memcached')) { global $m; - if (empty($m) || !is_object($m)) - { + if (empty($m) || !is_object($m)) { $m = new Memcached(); $tmparray = explode(':', $conf->global->MEMCACHED_SERVER); $result = $m->addServer($tmparray[0], $tmparray[1] ? $tmparray[1] : 11211); @@ -126,17 +124,14 @@ function dol_getcache($memoryid) $rescode = $m->getResultCode(); //print "memoryid=".$memoryid." - rescode=".$rescode." - data=".count($data)."\n
"; //var_dump($data); - if ($rescode == 0) - { + if ($rescode == 0) { return $data; } else { return -$rescode; } - } elseif (!empty($conf->memcached->enabled) && class_exists('Memcache')) - { + } elseif (!empty($conf->memcached->enabled) && class_exists('Memcache')) { global $m; - if (empty($m) || !is_object($m)) - { + if (empty($m) || !is_object($m)) { $m = new Memcache(); $tmparray = explode(':', $conf->global->MEMCACHED_SERVER); $result = $m->addServer($tmparray[0], $tmparray[1] ? $tmparray[1] : 11211); @@ -148,20 +143,18 @@ function dol_getcache($memoryid) $data = $m->get($memoryid); //print "memoryid=".$memoryid." - rescode=".$rescode." - data=".count($data)."\n
"; //var_dump($data); - if ($data) - { + if ($data) { return $data; } else { return -1; } - } // Using shmop - elseif (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x02)) - { + } elseif (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x02)) { + // Using shmop $data = dol_getshmop($memoryid); return $data; } - return 0; + return null; } From 997dee67afedcd4ac728aff00616d059e16e35fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sat, 20 Feb 2021 17:42:51 +0100 Subject: [PATCH 15/36] fix propal box --- htdocs/core/boxes/box_propales.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/boxes/box_propales.php b/htdocs/core/boxes/box_propales.php index 6efd56c01db..747bae87cf7 100644 --- a/htdocs/core/boxes/box_propales.php +++ b/htdocs/core/boxes/box_propales.php @@ -2,7 +2,7 @@ /* Copyright (C) 2003-2007 Rodolphe Quiedeville * Copyright (C) 2004-2007 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin - * Copyright (C) 2015-2019 Frederic France + * Copyright (C) 2015-2021 Frederic France * Copyright (C) 2020 Pierre Ardoin * * This program is free software; you can redistribute it and/or modify @@ -88,7 +88,7 @@ class box_propales extends ModeleBoxes $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias"; $sql .= ", s.code_client, s.code_compta, s.client"; $sql .= ", s.logo, s.email, s.entity"; - $sql .= ", p.rowid, p.ref, p.fk_statut, p.datep as dp, p.datec, p.fin_validite, p.date_cloture, p.total_ht, p.tva as total_tva, p.total as total_ttc, p.tms"; + $sql .= ", p.rowid, p.ref, p.fk_statut, p.datep as dp, p.datec, p.fin_validite, p.date_cloture, p.total_ht, p.total_tva, p.total as total_ttc, p.tms"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; $sql .= ", ".MAIN_DB_PREFIX."propal as p"; if (!$user->rights->societe->client->voir && !$user->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; From aa7b7101e4e19e04b28ae8f7454a92f481528860 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sat, 20 Feb 2021 17:45:55 +0100 Subject: [PATCH 16/36] Update index.php --- htdocs/comm/index.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/comm/index.php b/htdocs/comm/index.php index 46636f93812..cce0b202603 100644 --- a/htdocs/comm/index.php +++ b/htdocs/comm/index.php @@ -137,7 +137,7 @@ if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) { * Draft customer proposals */ if (!empty($conf->propal->enabled) && $user->rights->propal->lire) { - $sql = "SELECT p.rowid, p.ref, p.ref_client, p.total_ht, p.tva as total_tva, p.total as total_ttc, p.fk_statut as status"; + $sql = "SELECT p.rowid, p.ref, p.ref_client, p.total_ht, p.total_tva, p.total as total_ttc, p.fk_statut as status"; $sql .= ", s.rowid as socid, s.nom as name, s.name_alias"; $sql .= ", s.code_client, s.code_compta, s.client"; $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur"; @@ -765,7 +765,7 @@ if (!empty($conf->contrat->enabled) && $user->rights->contrat->lire && 0) { // T * Opened (validated) proposals */ if (!empty($conf->propal->enabled) && $user->rights->propal->lire) { - $sql = "SELECT p.rowid as propalid, p.entity, p.total as total_ttc, p.total_ht, p.tva as total_tva, p.ref, p.ref_client, p.fk_statut, p.datep as dp, p.fin_validite as dfv"; + $sql = "SELECT p.rowid as propalid, p.entity, p.total as total_ttc, p.total_ht, p.total_tva, p.ref, p.ref_client, p.fk_statut, p.datep as dp, p.fin_validite as dfv"; $sql .= ", s.rowid as socid, s.nom as name, s.name_alias"; $sql .= ", s.code_client, s.code_compta, s.client"; $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur"; From e94c78deafdfd739c59809dbc3a7693b004aeec3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sat, 20 Feb 2021 17:47:12 +0100 Subject: [PATCH 17/36] Update card.php --- htdocs/comm/card.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/htdocs/comm/card.php b/htdocs/comm/card.php index 2f5cb064a5e..faffe18a8e6 100644 --- a/htdocs/comm/card.php +++ b/htdocs/comm/card.php @@ -7,7 +7,7 @@ * Copyright (C) 2008 Raphael Bertrand (Resultic) * Copyright (C) 2010-2020 Juanjo Menent * Copyright (C) 2013 Alexandre Spangaro - * Copyright (C) 2015-2019 Frédéric France + * Copyright (C) 2015-2021 Frédéric France * Copyright (C) 2015 Marcos García * Copyright (C) 2020 Open-Dsi * @@ -741,12 +741,11 @@ if ($object->id > 0) /* * Latest proposals */ - if (!empty($conf->propal->enabled) && $user->rights->propal->lire) - { + if (!empty($conf->propal->enabled) && $user->rights->propal->lire) { $langs->load("propal"); $sql = "SELECT s.nom, s.rowid, p.rowid as propalid, p.fk_statut, p.total_ht"; - $sql .= ", p.tva as total_tva"; + $sql .= ", p.total_tva"; $sql .= ", p.total as total_ttc"; $sql .= ", p.ref, p.ref_client, p.remise"; $sql .= ", p.datep as dp, p.fin_validite as date_limit"; From 341cd06252ab567622d794a1200d6587297adc79 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 20 Feb 2021 18:21:10 +0100 Subject: [PATCH 18/36] Clean code for cache feature --- htdocs/core/lib/company.lib.php | 58 ++++++++++++++------------------- htdocs/core/lib/memory.lib.php | 34 ++++++++++++------- 2 files changed, 46 insertions(+), 46 deletions(-) diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 238f069c919..1da9f5faedd 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -52,13 +52,15 @@ function societe_prepare_head(Societe $object) if (empty($conf->global->MAIN_SUPPORT_SHARED_CONTACT_BETWEEN_THIRDPARTIES)) { if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->societe->contact->lire) { + require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php'; + //$nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external')); $nbContact = 0; - $cachekey = 'thirdparty_countcontact_'.$object->id; - require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php'; + $cachekey = 'thirdparty_'.$object->id.'_countcontacts'; $dataretrieved = dol_getcache($cachekey); - if (is_array($dataretrieved) && count($dataretrieved)) { - $nbContact = $dataretrieved[$cachekey]; + + if (!is_null($dataretrieved)) { + $nbContact = $dataretrieved; } else { $sql = "SELECT COUNT(p.rowid) as nb"; $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as p"; @@ -68,14 +70,10 @@ function societe_prepare_head(Societe $object) $obj = $db->fetch_object($resql); $nbContact = $obj->nb; } - $datatocache = array(); - $datatocache[$cachekey] = $nbContact; - $res_setcache = dol_setcache($cachekey, $datatocache); - if ($res_setcache < 0) { - $error = 'Failed to set cache for cachekey='.$cachekey.' result='.$res_setcache; - dol_syslog($error, LOG_ERR); - } + + dol_setcache($cachekey, $nbContact); // If setting cache fails, this is not a problem, so we do not test result. } + $head[$h][0] = DOL_URL_ROOT.'/societe/contact.php?socid='.$object->id; $head[$h][1] = $langs->trans('ContactsAddresses'); if ($nbContact > 0) { @@ -273,13 +271,14 @@ function societe_prepare_head(Societe $object) if ($user->socid == 0) { // Notifications if (!empty($conf->notification->enabled)) { + require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php'; + $nbNotif = 0; // Enable caching of thirdrparty count notifications - $cachekey = 'thirdparty_countnotif_'.$object->id; - require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php'; + $cachekey = 'thirdparty_'.$object->id.'_countnotifications'; $dataretrieved = dol_getcache($cachekey); - if (is_array($dataretrieved) && count($dataretrieved)) { - $nbNotif = $dataretrieved[$cachekey]; + if (!is_null($dataretrieved)) { + $nbNotif = $dataretrieved; } else { $sql = "SELECT COUNT(n.rowid) as nb"; $sql .= " FROM ".MAIN_DB_PREFIX."notify_def as n"; @@ -291,14 +290,9 @@ function societe_prepare_head(Societe $object) } else { dol_print_error($db); } - $datatocache = array(); - $datatocache[$cachekey] = $nbNotif; - $res_setcache = dol_setcache($cachekey, $datatocache); - if ($res_setcache < 0) { - $error = 'Failed to set cache for cachekey='.$cachekey.' result='.$res_setcache; - dol_syslog($error, LOG_ERR); - } + dol_setcache($cachekey, $nbNotif); // If setting cache fails, this is not a problem, so we do not test result. } + $head[$h][0] = DOL_URL_ROOT.'/societe/notify/card.php?socid='.$object->id; $head[$h][1] = $langs->trans("Notifications"); if ($nbNotif > 0) { @@ -343,13 +337,14 @@ function societe_prepare_head(Societe $object) $head[$h][0] = DOL_URL_ROOT.'/societe/agenda.php?socid='.$object->id; $head[$h][1] = $langs->trans("Events"); if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) { - // Enable caching of thirdrparty count actioncomm - $nbEvent = 0; - $cachekey = 'thirdparty_countevent_'.$object->id; require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php'; + + $nbEvent = 0; + // Enable caching of thirdrparty count actioncomm + $cachekey = 'thirdparty_'.$object->id.'_countevents'; $dataretrieved = dol_getcache($cachekey); - if (is_array($dataretrieved) && count($dataretrieved)) { - $nbEvent = $dataretrieved[$cachekey]; + if (!is_null($dataretrieved)) { + $nbEvent = $dataretrieved; } else { $sql = "SELECT COUNT(id) as nb"; $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm"; @@ -361,14 +356,9 @@ function societe_prepare_head(Societe $object) } else { dol_syslog('Failed to count actioncomm '.$db->lasterror(), LOG_ERR); } - $datatocache = array(); - $datatocache[$cachekey] = $nbEvent; - $res_setcache = dol_setcache($cachekey, $datatocache); - if ($res_setcache < 0) { - $error = 'Failed to set cache for cachekey='.$cachekey.' result='.$res_setcache; - dol_syslog($error, LOG_ERR); - } + dol_setcache($cachekey, $nbEvent); // If setting cache fails, this is not a problem, so we do not test result. } + $head[$h][1] .= '/'; $head[$h][1] .= $langs->trans("Agenda"); if ($nbEvent > 0) { diff --git a/htdocs/core/lib/memory.lib.php b/htdocs/core/lib/memory.lib.php index 11fa6082b05..818ff0bf171 100644 --- a/htdocs/core/lib/memory.lib.php +++ b/htdocs/core/lib/memory.lib.php @@ -88,7 +88,7 @@ function dol_setcache($memoryid, $data) } else { return -$rescode; } - } elseif (!empty($conf->memcached->enabled) && class_exists('Memcache')) { + } elseif (!empty($conf->memcached->enabled) && class_exists('Memcache')) { // This is a really not reliable cache ! Use Memcached instead. // Using a memcache server global $dolmemcache; if (empty($dolmemcache) || !is_object($dolmemcache)) { @@ -106,7 +106,7 @@ function dol_setcache($memoryid, $data) } else { return -1; } - } elseif (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x02)) { + } elseif (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x02)) { // This is a really not reliable cache ! Use Memcached instead. // Using shmop $result = dol_setshmop($memoryid, $data); } @@ -140,14 +140,16 @@ function dol_getcache($memoryid) //print "Get memoryid=".$memoryid; $data = $m->get($memoryid); $rescode = $m->getResultCode(); - //print "memoryid=".$memoryid." - rescode=".$rescode." - data=".count($data)."\n
"; + //print "memoryid=".$memoryid." - rescode=".$rescode." - count(response)=".count($data)."\n
"; //var_dump($data); if ($rescode == 0) { return $data; + } elseif ($rescode == 16) { // = Memcached::MEMCACHED_NOTFOUND but this constant doe snot exists. + return null; } else { return -$rescode; } - } elseif (!empty($conf->memcached->enabled) && class_exists('Memcache')) { + } elseif (!empty($conf->memcached->enabled) && class_exists('Memcache')) { // This is a really not reliable cache ! Use Memcached instead. global $m; if (empty($m) || !is_object($m)) { $m = new Memcache(); @@ -164,9 +166,9 @@ function dol_getcache($memoryid) if ($data) { return $data; } else { - return -1; + return null; // There is no way to make a difference between NOTFOUND and error when using Memcache. So do not use it, use Memcached instead. } - } elseif (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x02)) { + } elseif (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x02)) { // This is a really not reliable cache ! Use Memcached instead. // Using shmop $data = dol_getshmop($memoryid); return $data; @@ -186,7 +188,7 @@ function dol_getcache($memoryid) function dol_getshmopaddress($memoryid) { global $shmkeys, $shmoffset; - if (empty($shmkeys[$memoryid])) { + if (empty($shmkeys[$memoryid])) { // No room reserved for thid memoryid, no way to use cache return 0; } return $shmkeys[$memoryid] + $shmoffset; @@ -215,8 +217,8 @@ function dol_listshmop() * Save data into a memory area shared by all users, all sessions on server * * @param int $memoryid Memory id of shared area ('main', 'agenda', ...) - * @param string $data Data to save - * @return int <0 if KO, Nb of bytes written if OK + * @param string $data Data to save. Must be a not null value. + * @return int <0 if KO, 0=Caching not available, Nb of bytes written if OK */ function dol_setshmop($memoryid, $data) { @@ -225,6 +227,8 @@ function dol_setshmop($memoryid, $data) //print 'dol_setshmop memoryid='.$memoryid."
\n"; if (empty($shmkeys[$memoryid]) || !function_exists("shmop_write")) return 0; $shmkey = dol_getshmopaddress($memoryid); + if (empty($shmkey)) return 0; // No key reserved for this memoryid, we can't cache this memoryid + $newdata = serialize($data); $size = strlen($newdata); //print 'dol_setshmop memoryid='.$memoryid." shmkey=".$shmkey." newdata=".$size."bytes
\n"; @@ -247,14 +251,20 @@ function dol_setshmop($memoryid, $data) * Read a memory area shared by all users, all sessions on server * * @param string $memoryid Memory id of shared area ('main', 'agenda', ...) - * @return int <0 if KO, data if OK + * @return int <0 if KO, data if OK, Null if no cache enabled or not found */ function dol_getshmop($memoryid) { global $shmkeys, $shmoffset; - if (empty($shmkeys[$memoryid]) || !function_exists("shmop_open")) return 0; + $data = null; + + if (empty($shmkeys[$memoryid]) || !function_exists("shmop_open")) { + return null; + } $shmkey = dol_getshmopaddress($memoryid); + if (empty($shmkey)) return null; // No key reserved for this memoryid, we can't cache this memoryid + //print 'dol_getshmop memoryid='.$memoryid." shmkey=".$shmkey."
\n"; $handle = @shmop_open($shmkey, 'a', 0, 0); if ($handle) { @@ -263,7 +273,7 @@ function dol_getshmop($memoryid) else return -1; shmop_close($handle); } else { - return -2; + return null; // Can't open existing block, so we suppose it was not created, so nothing were cached yet for the memoryid } return $data; } From 1dd1dcefc5da3e4ebb4d72408ad8ebe155bfbc2d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 20 Feb 2021 18:25:48 +0100 Subject: [PATCH 19/36] Rename cache keys --- htdocs/core/lib/company.lib.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 1da9f5faedd..4d56fd9697a 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -56,7 +56,7 @@ function societe_prepare_head(Societe $object) //$nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external')); $nbContact = 0; - $cachekey = 'thirdparty_'.$object->id.'_countcontacts'; + $cachekey = 'count_contacts_thirdparty_'.$object->id; $dataretrieved = dol_getcache($cachekey); if (!is_null($dataretrieved)) { @@ -275,7 +275,7 @@ function societe_prepare_head(Societe $object) $nbNotif = 0; // Enable caching of thirdrparty count notifications - $cachekey = 'thirdparty_'.$object->id.'_countnotifications'; + $cachekey = 'count_notifications_thirdparty_'.$object->id; $dataretrieved = dol_getcache($cachekey); if (!is_null($dataretrieved)) { $nbNotif = $dataretrieved; @@ -341,7 +341,7 @@ function societe_prepare_head(Societe $object) $nbEvent = 0; // Enable caching of thirdrparty count actioncomm - $cachekey = 'thirdparty_'.$object->id.'_countevents'; + $cachekey = 'count_events_thirdparty_'.$object->id; $dataretrieved = dol_getcache($cachekey); if (!is_null($dataretrieved)) { $nbEvent = $dataretrieved; From 91d06524767bf98b9c55a026e04e8a9300cf10a9 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 20 Feb 2021 18:32:16 +0100 Subject: [PATCH 20/36] Clean code of cache --- htdocs/core/lib/memory.lib.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/memory.lib.php b/htdocs/core/lib/memory.lib.php index 818ff0bf171..232b5a9d94a 100644 --- a/htdocs/core/lib/memory.lib.php +++ b/htdocs/core/lib/memory.lib.php @@ -61,7 +61,7 @@ $shmoffset = 1000; // Max number of entries found into a language file. If too l * * @param string $memoryid Memory id of shared area * @param mixed $data Data to save. It must not be a null value. - * @return int <0 if KO, Nb of bytes written if OK + * @return int <0 if KO, 0 if nothing is done, Nb of bytes written if OK * @see dol_getcache() */ function dol_setcache($memoryid, $data) @@ -69,6 +69,10 @@ function dol_setcache($memoryid, $data) global $conf; $result = 0; + if (strpos($memoryid, 'count_') === 0) { // The memoryid key start with 'count_...' + if (empty($conf->global->MAIN_CACHE_COUNT)) return 0; + } + if (!empty($conf->memcached->enabled) && class_exists('Memcached')) { // Using a memcached server global $dolmemcache; @@ -118,13 +122,17 @@ function dol_setcache($memoryid, $data) * Read a memory area shared by all users, all sessions on server * * @param string $memoryid Memory id of shared area - * @return int|mixed <0 if KO, data if OK, null if not found into cache + * @return int|mixed <0 if KO, data if OK, null if not found into cache or no caching feature enabled * @see dol_setcache() */ function dol_getcache($memoryid) { global $conf; + if (strpos($memoryid, 'count_') === 0) { // The memoryid key start with 'count_...' + if (empty($conf->global->MAIN_CACHE_COUNT)) return null; + } + // Using a memcached server if (!empty($conf->memcached->enabled) && class_exists('Memcached')) { global $m; From da37497a38938c8736646c12c766b90d722ead6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sat, 20 Feb 2021 20:47:01 +0100 Subject: [PATCH 21/36] memcached can set expire --- htdocs/core/lib/memory.lib.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/htdocs/core/lib/memory.lib.php b/htdocs/core/lib/memory.lib.php index 232b5a9d94a..484b3933e42 100644 --- a/htdocs/core/lib/memory.lib.php +++ b/htdocs/core/lib/memory.lib.php @@ -61,10 +61,11 @@ $shmoffset = 1000; // Max number of entries found into a language file. If too l * * @param string $memoryid Memory id of shared area * @param mixed $data Data to save. It must not be a null value. + * @param int $expire ttl in seconds, 0 never expire * @return int <0 if KO, 0 if nothing is done, Nb of bytes written if OK * @see dol_getcache() */ -function dol_setcache($memoryid, $data) +function dol_setcache($memoryid, $data, $expire = 0) { global $conf; $result = 0; @@ -85,7 +86,7 @@ function dol_setcache($memoryid, $data) $memoryid = session_name() . '_' . $memoryid; //$dolmemcache->setOption(Memcached::OPT_COMPRESSION, false); - $dolmemcache->add($memoryid, $data); // This fails if key already exists + $dolmemcache->add($memoryid, $data, $expire); // This fails if key already exists $rescode = $dolmemcache->getResultCode(); if ($rescode == 0) { return count($data); @@ -104,7 +105,7 @@ function dol_setcache($memoryid, $data) $memoryid = session_name() . '_' . $memoryid; //$dolmemcache->setOption(Memcached::OPT_COMPRESSION, false); - $result = $dolmemcache->add($memoryid, $data); // This fails if key already exists + $result = $dolmemcache->add($memoryid, $data, false, $expire); // This fails if key already exists if ($result) { return count($data); } else { @@ -112,7 +113,7 @@ function dol_setcache($memoryid, $data) } } elseif (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x02)) { // This is a really not reliable cache ! Use Memcached instead. // Using shmop - $result = dol_setshmop($memoryid, $data); + $result = dol_setshmop($memoryid, $data, $expire); } return $result; @@ -226,9 +227,10 @@ function dol_listshmop() * * @param int $memoryid Memory id of shared area ('main', 'agenda', ...) * @param string $data Data to save. Must be a not null value. + * @param int $expire ttl in seconds, 0 never expire * @return int <0 if KO, 0=Caching not available, Nb of bytes written if OK */ -function dol_setshmop($memoryid, $data) +function dol_setshmop($memoryid, $data, $expire) { global $shmkeys, $shmoffset; From 65925e60b9a3e9d524b58165d7e47a70862ff06d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sat, 20 Feb 2021 20:48:59 +0100 Subject: [PATCH 22/36] memcached can set expire --- htdocs/core/lib/company.lib.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 4d56fd9697a..1cc2945fef3 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -71,7 +71,7 @@ function societe_prepare_head(Societe $object) $nbContact = $obj->nb; } - dol_setcache($cachekey, $nbContact); // If setting cache fails, this is not a problem, so we do not test result. + dol_setcache($cachekey, $nbContact, 120); // If setting cache fails, this is not a problem, so we do not test result. } $head[$h][0] = DOL_URL_ROOT.'/societe/contact.php?socid='.$object->id; @@ -290,7 +290,7 @@ function societe_prepare_head(Societe $object) } else { dol_print_error($db); } - dol_setcache($cachekey, $nbNotif); // If setting cache fails, this is not a problem, so we do not test result. + dol_setcache($cachekey, $nbNotif, 120); // If setting cache fails, this is not a problem, so we do not test result. } $head[$h][0] = DOL_URL_ROOT.'/societe/notify/card.php?socid='.$object->id; @@ -356,7 +356,7 @@ function societe_prepare_head(Societe $object) } else { dol_syslog('Failed to count actioncomm '.$db->lasterror(), LOG_ERR); } - dol_setcache($cachekey, $nbEvent); // If setting cache fails, this is not a problem, so we do not test result. + dol_setcache($cachekey, $nbEvent, 120); // If setting cache fails, this is not a problem, so we do not test result. } $head[$h][1] .= '/'; From 518826ad3d3299dcc81c0568e683fd7bbf8b483b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sat, 20 Feb 2021 22:03:11 +0100 Subject: [PATCH 23/36] add project --- htdocs/core/lib/company.lib.php | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 1cc2945fef3..02754798681 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -129,22 +129,30 @@ function societe_prepare_head(Societe $object) } if (!empty($conf->projet->enabled) && (!empty($user->rights->projet->lire))) { - $nbNote = 0; - $sql = "SELECT COUNT(n.rowid) as nb"; - $sql .= " FROM ".MAIN_DB_PREFIX."projet as n"; - $sql .= " WHERE fk_soc = ".$object->id; - $sql .= " AND entity IN (".getEntity('project').")"; - $resql = $db->query($sql); - if ($resql) { - $obj = $db->fetch_object($resql); - $nbNote = $obj->nb; + $nbProject = 0; + $cachekey = 'count_projects_thirdparty_'.$object->id; + $dataretrieved = dol_getcache($cachekey); + + if (!is_null($dataretrieved)) { + $nbProject = $dataretrieved; } else { - dol_print_error($db); + $sql = "SELECT COUNT(n.rowid) as nb"; + $sql .= " FROM ".MAIN_DB_PREFIX."projet as n"; + $sql .= " WHERE fk_soc = ".$object->id; + $sql .= " AND entity IN (".getEntity('project').")"; + $resql = $db->query($sql); + if ($resql) { + $obj = $db->fetch_object($resql); + $nbProject = $obj->nb; + } else { + dol_print_error($db); + } + dol_setcache($cachekey, $nbProject, 120); // If setting cache fails, this is not a problem, so we do not test result. } $head[$h][0] = DOL_URL_ROOT.'/societe/project.php?socid='.$object->id; $head[$h][1] = $langs->trans("Projects"); - if ($nbNote > 0) { - $head[$h][1] .= ''.$nbNote.''; + if ($nbProject > 0) { + $head[$h][1] .= ''.$nbProject.''; } $head[$h][2] = 'project'; $h++; From 41b89ae6774b64d5428b5744c31d9009cb489988 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sun, 21 Feb 2021 09:50:58 +0100 Subject: [PATCH 24/36] add files and links --- htdocs/core/lib/company.lib.php | 39 +++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 02754798681..310f34a86fb 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -52,10 +52,10 @@ function societe_prepare_head(Societe $object) if (empty($conf->global->MAIN_SUPPORT_SHARED_CONTACT_BETWEEN_THIRDPARTIES)) { if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->societe->contact->lire) { - require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php'; - //$nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external')); $nbContact = 0; + // Enable caching of thirdrparty count Contacts + require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php'; $cachekey = 'count_contacts_thirdparty_'.$object->id; $dataretrieved = dol_getcache($cachekey); @@ -130,6 +130,8 @@ function societe_prepare_head(Societe $object) if (!empty($conf->projet->enabled) && (!empty($user->rights->projet->lire))) { $nbProject = 0; + // Enable caching of thirdrparty count projects + require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php'; $cachekey = 'count_projects_thirdparty_'.$object->id; $dataretrieved = dol_getcache($cachekey); @@ -279,10 +281,9 @@ function societe_prepare_head(Societe $object) if ($user->socid == 0) { // Notifications if (!empty($conf->notification->enabled)) { - require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php'; - $nbNotif = 0; // Enable caching of thirdrparty count notifications + require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php'; $cachekey = 'count_notifications_thirdparty_'.$object->id; $dataretrieved = dol_getcache($cachekey); if (!is_null($dataretrieved)) { @@ -326,17 +327,28 @@ function societe_prepare_head(Societe $object) $head[$h][2] = 'note'; $h++; - // Attached files - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php'; - $upload_dir = $conf->societe->multidir_output[$object->entity]."/".$object->id; - $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$')); - $nbLinks = Link::count($db, $object->element, $object->id); + // Attached files and Links + $totalAttached = 0; + // Enable caching of thirdrparty count attached files and links + require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php'; + $cachekey = 'count_attached_thirdparty_'.$object->id; + $dataretrieved = dol_getcache($cachekey); + if (!is_null($dataretrieved)) { + $totalAttached = $dataretrieved; + } else { + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php'; + $upload_dir = $conf->societe->multidir_output[$object->entity]."/".$object->id; + $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$')); + $nbLinks = Link::count($db, $object->element, $object->id); + $totalAttached = $nbFiles + $nbLinks; + dol_setcache($cachekey, $totalAttached, 120); // If setting cache fails, this is not a problem, so we do not test result. + } $head[$h][0] = DOL_URL_ROOT.'/societe/document.php?socid='.$object->id; $head[$h][1] = $langs->trans("Documents"); - if (($nbFiles + $nbLinks) > 0) { - $head[$h][1] .= ''.($nbFiles + $nbLinks).''; + if (($totalAttached) > 0) { + $head[$h][1] .= ''.($totalAttached).''; } $head[$h][2] = 'document'; $h++; @@ -345,10 +357,9 @@ function societe_prepare_head(Societe $object) $head[$h][0] = DOL_URL_ROOT.'/societe/agenda.php?socid='.$object->id; $head[$h][1] = $langs->trans("Events"); if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) { - require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php'; - $nbEvent = 0; // Enable caching of thirdrparty count actioncomm + require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php'; $cachekey = 'count_events_thirdparty_'.$object->id; $dataretrieved = dol_getcache($cachekey); if (!is_null($dataretrieved)) { From 5096c5bf2d3c70ad0006c9fdb6e131826c445034 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sun, 21 Feb 2021 10:18:05 +0100 Subject: [PATCH 25/36] cache socialnetworks array --- htdocs/core/lib/functions.lib.php | 35 ++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 7d994616e5c..28098dab45b 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -2450,21 +2450,32 @@ function dol_print_email($email, $cid = 0, $socid = 0, $addlink = 0, $max = 64, function getArrayOfSocialNetworks() { global $conf, $db; - $sql = "SELECT rowid, code, label, url, icon, active FROM ".MAIN_DB_PREFIX."c_socialnetworks"; - $sql .= " WHERE entity=".$conf->entity; + $socialnetworks = array(); - $resql = $db->query($sql); - if ($resql) { - while ($obj = $db->fetch_object($resql)) { - $socialnetworks[$obj->code] = array( - 'rowid' => $obj->rowid, - 'label' => $obj->label, - 'url' => $obj->url, - 'icon' => $obj->icon, - 'active' => $obj->active, - ); + // Enable caching of array + require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php'; + $cachekey = 'socialnetworks_' . $conf->entity; + $dataretrieved = dol_getcache($cachekey); + if (!is_null($dataretrieved)) { + $socialnetworks = $dataretrieved; + } else { + $sql = "SELECT rowid, code, label, url, icon, active FROM ".MAIN_DB_PREFIX."c_socialnetworks"; + $sql .= " WHERE entity=".$conf->entity; + $resql = $db->query($sql); + if ($resql) { + while ($obj = $db->fetch_object($resql)) { + $socialnetworks[$obj->code] = array( + 'rowid' => $obj->rowid, + 'label' => $obj->label, + 'url' => $obj->url, + 'icon' => $obj->icon, + 'active' => $obj->active, + ); + } } + dol_setcache($cachekey, $socialnetworks); // If setting cache fails, this is not a problem, so we do not test result. } + return $socialnetworks; } From 0d01041166f71498df9428fbbcf574de474c6486 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 21 Feb 2021 12:10:07 +0100 Subject: [PATCH 26/36] css --- htdocs/admin/system/dolibarr.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/admin/system/dolibarr.php b/htdocs/admin/system/dolibarr.php index 2b3bb6e8d21..46ed0c75934 100644 --- a/htdocs/admin/system/dolibarr.php +++ b/htdocs/admin/system/dolibarr.php @@ -120,7 +120,7 @@ if (function_exists('curl_init')) print $langs->trans("LastStableVersion").' : '.$langs->trans("UpdateServerOffline").''; } } else { - print $langs->trans("LastStableVersion").' : '.$langs->trans("Check").''; + print $langs->trans("LastStableVersion").' : '.$langs->trans("Check").''; } } From d3a98c7680178da9811a579773c47aeb580254f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sun, 21 Feb 2021 13:00:31 +0100 Subject: [PATCH 27/36] replace ... by one char in dol_trunc --- htdocs/core/lib/functions.lib.php | 75 ++++++++++++++++++------------- 1 file changed, 43 insertions(+), 32 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 7d994616e5c..39ac3b7a80e 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -3178,10 +3178,10 @@ function dol_substr($string, $start, $length, $stringencoding = '', $trunconbyte * MAIN_DISABLE_TRUNC=1 can disable all truncings * * @param string $string String to truncate - * @param int $size Max string size visible (excluding ...). 0 for no limit. WARNING: Final string size can have 3 more chars (if we added ..., or if size was max+1 or max+2 or max+3 so it does not worse to replace with ...) + * @param int $size Max string size visible (excluding …). 0 for no limit. WARNING: Final string size can have 3 more chars (if we added ..., or if size was max+1 or max+2 or max+3 so it does not worse to replace with ...) * @param string $trunc Where to trunc: 'right', 'left', 'middle' (size must be a 2 power), 'wrap' * @param string $stringencoding Tell what is source string encoding - * @param int $nodot Truncation do not add ... after truncation. So it's an exact truncation. + * @param int $nodot Truncation do not add … after truncation. So it's an exact truncation. * @param int $display Trunc is used to display data and can be changed for small screen. TODO Remove this param (must be dealt with CSS) * @return string Truncated string. WARNING: length is never higher than $size if $nodot is set, but can be 3 chars higher otherwise. */ @@ -3189,42 +3189,53 @@ function dol_trunc($string, $size = 40, $trunc = 'right', $stringencoding = 'UTF { global $conf; - if ($size == 0 || !empty($conf->global->MAIN_DISABLE_TRUNC)) return $string; + if ($size == 0 || !empty($conf->global->MAIN_DISABLE_TRUNC)) { + return $string; + } - if (empty($stringencoding)) $stringencoding = 'UTF-8'; + if (empty($stringencoding)) { + $stringencoding = 'UTF-8'; + } // reduce for small screen - if ($conf->dol_optimize_smallscreen == 1 && $display == 1) $size = round($size / 3); + // if ($conf->dol_optimize_smallscreen == 1 && $display == 1) $size = round($size / 3); // We go always here - if ($trunc == 'right') - { - $newstring = dol_textishtml($string) ?dol_string_nohtmltag($string, 1) : $string; - if (dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 3))) // If nodot is 0 and size is 1,2 or 3 chars more, we don't trunc and don't add ... - return dol_substr($newstring, 0, $size, $stringencoding).($nodot ? '' : '...'); - else //return 'u'.$size.'-'.$newstring.'-'.dol_strlen($newstring,$stringencoding).'-'.$string; - return $string; - } elseif ($trunc == 'middle') - { - $newstring = dol_textishtml($string) ?dol_string_nohtmltag($string, 1) : $string; - if (dol_strlen($newstring, $stringencoding) > 2 && dol_strlen($newstring, $stringencoding) > ($size + 1)) - { + if ($trunc == 'right') { + $newstring = dol_textishtml($string) ? dol_string_nohtmltag($string, 1) : $string; + if (dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 1))) { + // If nodot is 0 and size is 1 chars more, we don't trunc and don't add … + return dol_substr($newstring, 0, $size, $stringencoding).($nodot ? '' : '…'); + } else { + //return 'u'.$size.'-'.$newstring.'-'.dol_strlen($newstring,$stringencoding).'-'.$string; + return $string; + } + } elseif ($trunc == 'middle') { + $newstring = dol_textishtml($string) ? dol_string_nohtmltag($string, 1) : $string; + if (dol_strlen($newstring, $stringencoding) > 2 && dol_strlen($newstring, $stringencoding) > ($size + 1)) { $size1 = round($size / 2); $size2 = round($size / 2); - return dol_substr($newstring, 0, $size1, $stringencoding).'...'.dol_substr($newstring, dol_strlen($newstring, $stringencoding) - $size2, $size2, $stringencoding); - } else return $string; - } elseif ($trunc == 'left') - { - $newstring = dol_textishtml($string) ?dol_string_nohtmltag($string, 1) : $string; - if (dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 3))) // If nodot is 0 and size is 1,2 or 3 chars more, we don't trunc and don't add ... - return '...'.dol_substr($newstring, dol_strlen($newstring, $stringencoding) - $size, $size, $stringencoding); - else return $string; - } elseif ($trunc == 'wrap') - { - $newstring = dol_textishtml($string) ?dol_string_nohtmltag($string, 1) : $string; - if (dol_strlen($newstring, $stringencoding) > ($size + 1)) - return dol_substr($newstring, 0, $size, $stringencoding)."\n".dol_trunc(dol_substr($newstring, $size, dol_strlen($newstring, $stringencoding) - $size, $stringencoding), $size, $trunc); - else return $string; - } else return 'BadParam3CallingDolTrunc'; + return dol_substr($newstring, 0, $size1, $stringencoding).'…'.dol_substr($newstring, dol_strlen($newstring, $stringencoding) - $size2, $size2, $stringencoding); + } else { + return $string; + } + } elseif ($trunc == 'left') { + $newstring = dol_textishtml($string) ? dol_string_nohtmltag($string, 1) : $string; + if (dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 1))) { + // If nodot is 0 and size is 1 chars more, we don't trunc and don't add … + return '…'.dol_substr($newstring, dol_strlen($newstring, $stringencoding) - $size, $size, $stringencoding); + } else { + return $string; + } + } elseif ($trunc == 'wrap') { + $newstring = dol_textishtml($string) ? dol_string_nohtmltag($string, 1) : $string; + if (dol_strlen($newstring, $stringencoding) > ($size + 1)) { + return dol_substr($newstring, 0, $size, $stringencoding)."\n".dol_trunc(dol_substr($newstring, $size, dol_strlen($newstring, $stringencoding) - $size, $stringencoding), $size, $trunc); + } else { + return $string; + } + } else { + return 'BadParam3CallingDolTrunc'; + } } /** From 1bb27f8f18f2a90c44be4fb1484ccec9c5350c75 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 21 Feb 2021 13:12:16 +0100 Subject: [PATCH 28/36] Responsive --- htdocs/compta/facture/list.php | 2 +- htdocs/theme/eldy/global.inc.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index 7b60dd639f6..249df885435 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -1376,7 +1376,7 @@ if ($resql) // Alias if (!empty($arrayfields['s.name_alias']['checked'])) { - print ''; + print ''; print $obj->name_alias; print ''; if (!$i) $totalarray['nbfield']++; diff --git a/htdocs/theme/eldy/global.inc.php b/htdocs/theme/eldy/global.inc.php index d2c8ffdbcc4..515a42bd8f1 100644 --- a/htdocs/theme/eldy/global.inc.php +++ b/htdocs/theme/eldy/global.inc.php @@ -3503,6 +3503,7 @@ table.hidepaginationnext .paginationnext { } + /* Set the color for hover lines */ .oddeven:hover, .evenodd:hover, .impair:hover, .pair:hover { From 6e3a1a1d418a083e15c95aff536bd2a811f7d577 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sun, 21 Feb 2021 13:32:54 +0100 Subject: [PATCH 29/36] fix tests --- htdocs/core/lib/functions.lib.php | 6 +++--- test/phpunit/FunctionsLibTest.php | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 39ac3b7a80e..efe3824c5c4 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -3173,12 +3173,12 @@ function dol_substr($string, $start, $length, $stringencoding = '', $trunconbyte /** - * Truncate a string to a particular length adding '...' if string larger than length. - * If length = max length+1, we do no truncate to avoid having just 1 char replaced with '...'. + * Truncate a string to a particular length adding '…' if string larger than length. + * If length = max length+1, we do no truncate to avoid having just 1 char replaced with '…'. * MAIN_DISABLE_TRUNC=1 can disable all truncings * * @param string $string String to truncate - * @param int $size Max string size visible (excluding …). 0 for no limit. WARNING: Final string size can have 3 more chars (if we added ..., or if size was max+1 or max+2 or max+3 so it does not worse to replace with ...) + * @param int $size Max string size visible (excluding …). 0 for no limit. WARNING: Final string size can have 3 more chars (if we added …, or if size was max+1 so it does not worse to replace with ...) * @param string $trunc Where to trunc: 'right', 'left', 'middle' (size must be a 2 power), 'wrap' * @param string $stringencoding Tell what is source string encoding * @param int $nodot Truncation do not add … after truncation. So it's an exact truncation. diff --git a/test/phpunit/FunctionsLibTest.php b/test/phpunit/FunctionsLibTest.php index 4f6bfb1963e..fe9d0563167 100644 --- a/test/phpunit/FunctionsLibTest.php +++ b/test/phpunit/FunctionsLibTest.php @@ -765,21 +765,21 @@ class FunctionsLibTest extends PHPUnit\Framework\TestCase */ public function testDolTrunc() { - // Default trunc (will add ... if truncation truncation or keep last char if only one char) + // Default trunc (will add … if truncation truncation or keep last char if only one char) $input="éeéeéeàa"; $after=dol_trunc($input, 3); - $this->assertEquals("éeé...", $after, 'Test A1'); + $this->assertEquals("éeé…", $after, 'Test A1'); $after=dol_trunc($input, 2); - $this->assertEquals("ée...", $after, 'Test A2'); + $this->assertEquals("ée…", $after, 'Test A2'); $after=dol_trunc($input, 1); - $this->assertEquals("é...", $after, 'Test A3'); + $this->assertEquals("é…", $after, 'Test A3'); $input="éeéeé"; $after=dol_trunc($input, 3); $this->assertEquals("éeéeé", $after, 'Test B1'); $after=dol_trunc($input, 2); $this->assertEquals("éeéeé", $after, 'Test B2'); $after=dol_trunc($input, 1); - $this->assertEquals("é...", $after, 'Test B3'); + $this->assertEquals("é…", $after, 'Test B3'); $input="éeée"; $after=dol_trunc($input, 3); $this->assertEquals("éeée", $after, 'Test C1'); @@ -794,7 +794,7 @@ class FunctionsLibTest extends PHPUnit\Framework\TestCase $this->assertEquals("éeé", $after, 'Test D'); $after=dol_trunc($input, 1); $this->assertEquals("éeé", $after, 'Test E'); - // Trunc with no ... + // Trunc with no … $input="éeéeéeàa"; $after=dol_trunc($input, 3, 'right', 'UTF-8', 1); $this->assertEquals("éeé", $after, 'Test F'); @@ -809,7 +809,7 @@ class FunctionsLibTest extends PHPUnit\Framework\TestCase $this->assertEquals("é", $after, 'Test J'); $input="éeéeéeàa"; $after=dol_trunc($input, 4, 'middle'); - $this->assertEquals("ée...àa", $after, 'Test K'); + $this->assertEquals("ée…àa", $after, 'Test K'); return true; } From 548820011a702f2bafc086fbe0da4836bb7f7175 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sun, 21 Feb 2021 13:39:59 +0100 Subject: [PATCH 30/36] fix tests --- htdocs/core/lib/functions.lib.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index efe3824c5c4..3604308708b 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -3202,7 +3202,7 @@ function dol_trunc($string, $size = 40, $trunc = 'right', $stringencoding = 'UTF // We go always here if ($trunc == 'right') { $newstring = dol_textishtml($string) ? dol_string_nohtmltag($string, 1) : $string; - if (dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 1))) { + if (dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 2))) { // If nodot is 0 and size is 1 chars more, we don't trunc and don't add … return dol_substr($newstring, 0, $size, $stringencoding).($nodot ? '' : '…'); } else { @@ -3220,7 +3220,7 @@ function dol_trunc($string, $size = 40, $trunc = 'right', $stringencoding = 'UTF } } elseif ($trunc == 'left') { $newstring = dol_textishtml($string) ? dol_string_nohtmltag($string, 1) : $string; - if (dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 1))) { + if (dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 2))) { // If nodot is 0 and size is 1 chars more, we don't trunc and don't add … return '…'.dol_substr($newstring, dol_strlen($newstring, $stringencoding) - $size, $size, $stringencoding); } else { From 0a7e692fbf57f26b59b86a53fa6b3b11fb17ab3b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 21 Feb 2021 14:46:52 +0100 Subject: [PATCH 31/36] Wip website module --- htdocs/core/lib/website.lib.php | 8 ++++---- htdocs/theme/eldy/global.inc.php | 4 ++++ htdocs/theme/md/style.css.php | 4 ++++ htdocs/website/index.php | 32 +++++++++++++++++--------------- 4 files changed, 29 insertions(+), 19 deletions(-) diff --git a/htdocs/core/lib/website.lib.php b/htdocs/core/lib/website.lib.php index 75a20ac6852..07112ed66d9 100644 --- a/htdocs/core/lib/website.lib.php +++ b/htdocs/core/lib/website.lib.php @@ -205,7 +205,7 @@ function dolWebsiteReplacementOfLinks($website, $content, $removephppart = 0, $c /** * Render a string of an HTML content and output it. - * Used to ouput the page when viewed from server (Dolibarr or Apache). + * Used to ouput the page when viewed from a server (Dolibarr or Apache). * * @param string $content Content string * @param string $contenttype Content type @@ -231,7 +231,7 @@ function dolWebsiteOutput($content, $contenttype = 'html', $containerid = '') $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current - if (defined('USEDOLIBARREDITOR')) // REPLACEMENT OF LINKS When page called from Dolibarr editor + if (defined('USEDOLIBARREDITOR')) // REPLACEMENT OF LINKS When page called from Dolibarr editor (this case should not happen) { // We remove the part of content if ($contenttype == 'html') @@ -296,7 +296,7 @@ function dolWebsiteOutput($content, $contenttype = 'html', $containerid = '') if (empty($includehtmlcontentopened)) { $content = str_replace('!~!~!~', '', $content); } - } else // REPLACEMENT OF LINKS When page called from virtual host + } else // REPLACEMENT OF LINKS When page called from virtual host web server { $symlinktomediaexists = 1; if ($website->virtualhost) { @@ -355,7 +355,7 @@ function dolWebsiteOutput($content, $contenttype = 'html', $containerid = '') } } - $content = str_replace(' contenteditable="true"', ' contenteditable="false"', $content); + //$content = str_replace(' contenteditable="true"', ' contenteditable="false"', $content); if (!empty($conf->global->WEBSITE_ADD_CSS_TO_BODY)) { $content = str_replace(''."\n"; print '
'; - print '
'; + + print '
'; // Button include dynamic contant + print $langs->trans("ShowSubcontainers"); + if (empty($conf->global->WEBSITE_SUBCONTAINERSINLINE)) + { + print ''.img_picto($langs->trans("ShowSubContainersOnOff", $langs->transnoentitiesnoconv("Off")), 'switch_off', '', false, 0, 0, '', 'nomarginleft').''; + } + else { + print ''.img_picto($langs->trans("ShowSubContainersOnOff", $langs->transnoentitiesnoconv("On")), 'switch_on', '', false, 0, 0, '', 'nomarginleft').''; + } + print '
'; + + print '
'; // Button edit inline print ''."\n"; print ''."\n"; @@ -2812,17 +2824,7 @@ if (!GETPOST('hide_websitemenu')) } print '
'; - print ''; + print '
'; // Set page as homepage @@ -4275,7 +4277,7 @@ if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpa // REPLACEMENT OF LINKS When page called by website editor $out .= ''."\n"; - $out .= '