Merge pull request #16335 from frederic34/countactioncomm

count actioncomm for thirdparty tab agenda
This commit is contained in:
Laurent Destailleur 2021-02-20 17:24:36 +01:00 committed by GitHub
commit e81b012489
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 281 additions and 154 deletions

View File

@ -7,7 +7,7 @@
* Copyright (C) 2013-2014 Juanjo Menent <jmenent@2byte.es> * Copyright (C) 2013-2014 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2013 Christophe Battarel <contact@altairis.fr> * Copyright (C) 2013 Christophe Battarel <contact@altairis.fr>
* Copyright (C) 2013-2018 Alexandre Spangaro <aspangaro@open-dsi.fr> * Copyright (C) 2013-2018 Alexandre Spangaro <aspangaro@open-dsi.fr>
* Copyright (C) 2015-2019 Frédéric France <frederic.france@netlogic.fr> * Copyright (C) 2015-2021 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr> * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) 2017 Rui Strecht <rui.strecht@aliartalentos.com> * Copyright (C) 2017 Rui Strecht <rui.strecht@aliartalentos.com>
* Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es> * Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
@ -53,20 +53,34 @@ function societe_prepare_head(Societe $object)
if (empty($conf->global->MAIN_SUPPORT_SHARED_CONTACT_BETWEEN_THIRDPARTIES)) { if (empty($conf->global->MAIN_SUPPORT_SHARED_CONTACT_BETWEEN_THIRDPARTIES)) {
if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->societe->contact->lire) { 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 = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external'));
$nbContact = 0; // TODO $nbContact = 0;
$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 = "SELECT COUNT(p.rowid) as nb";
$sql .= " FROM ".MAIN_DB_PREFIX."socpeople as p"; $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as p";
$sql .= " WHERE p.fk_soc = ".$object->id; $sql .= " WHERE p.fk_soc = ".$object->id;
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) { if ($resql) {
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
if ($obj) $nbContact = $obj->nb; $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);
}
} }
$head[$h][0] = DOL_URL_ROOT.'/societe/contact.php?socid='.$object->id; $head[$h][0] = DOL_URL_ROOT.'/societe/contact.php?socid='.$object->id;
$head[$h][1] = $langs->trans('ContactsAddresses'); $head[$h][1] = $langs->trans('ContactsAddresses');
if ($nbContact > 0) $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>'; if ($nbContact > 0) {
$head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
}
$head[$h][2] = 'contact'; $head[$h][2] = 'contact';
$h++; $h++;
} }
@ -74,7 +88,9 @@ function societe_prepare_head(Societe $object)
$head[$h][0] = DOL_URL_ROOT.'/societe/societecontact.php?socid='.$object->id; $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')); $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
$head[$h][1] = $langs->trans("ContactsAddresses"); $head[$h][1] = $langs->trans("ContactsAddresses");
if ($nbContact > 0) $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>'; if ($nbContact > 0) {
$head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
}
$head[$h][2] = 'contact'; $head[$h][2] = 'contact';
$h++; $h++;
} }
@ -82,9 +98,15 @@ function societe_prepare_head(Societe $object)
if ($object->client == 1 || $object->client == 2 || $object->client == 3) { if ($object->client == 1 || $object->client == 2 || $object->client == 3) {
$head[$h][0] = DOL_URL_ROOT.'/comm/card.php?socid='.$object->id; $head[$h][0] = DOL_URL_ROOT.'/comm/card.php?socid='.$object->id;
$head[$h][1] = ''; $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) && ($object->client == 2 || $object->client == 3)) {
if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && $object->client == 3) $head[$h][1] .= ' | '; $head[$h][1] .= $langs->trans("Prospect");
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) && 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'; $head[$h][2] = 'customer';
$h++; $h++;
@ -98,7 +120,9 @@ function societe_prepare_head(Societe $object)
} }
} }
$supplier_module_enabled = 0; $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)) { 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][0] = DOL_URL_ROOT.'/fourn/card.php?socid='.$object->id;
$head[$h][1] = $langs->trans("Supplier"); $head[$h][1] = $langs->trans("Supplier");
@ -107,8 +131,6 @@ function societe_prepare_head(Societe $object)
} }
if (!empty($conf->projet->enabled) && (!empty($user->rights->projet->lire))) { 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; $nbNote = 0;
$sql = "SELECT COUNT(n.rowid) as nb"; $sql = "SELECT COUNT(n.rowid) as nb";
$sql .= " FROM ".MAIN_DB_PREFIX."projet as n"; $sql .= " FROM ".MAIN_DB_PREFIX."projet as n";
@ -116,17 +138,16 @@ function societe_prepare_head(Societe $object)
$sql .= " AND entity IN (".getEntity('project').")"; $sql .= " AND entity IN (".getEntity('project').")";
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) { if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
while ($i < $num) {
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
$nbNote = $obj->nb; $nbNote = $obj->nb;
$i++;
}
} else { } else {
dol_print_error($db); dol_print_error($db);
} }
if ($nbNote > 0) $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>'; $head[$h][0] = DOL_URL_ROOT.'/societe/project.php?socid='.$object->id;
$head[$h][1] = $langs->trans("Projects");
if ($nbNote > 0) {
$head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
}
$head[$h][2] = 'project'; $head[$h][2] = 'project';
$h++; $h++;
} }
@ -180,12 +201,16 @@ function societe_prepare_head(Societe $object)
//$title = $langs->trans("BankAccountsAndGateways"); //$title = $langs->trans("BankAccountsAndGateways");
$servicestatus = 0; $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'; include_once DOL_DOCUMENT_ROOT.'/societe/class/societeaccount.class.php';
$societeaccount = new SocieteAccount($db); $societeaccount = new SocieteAccount($db);
$stripecu = $societeaccount->getCustomerAccount($object->id, 'stripe', $servicestatus); // Get thirdparty cu_... $stripecu = $societeaccount->getCustomerAccount($object->id, 'stripe', $servicestatus); // Get thirdparty cu_...
if ($stripecu) $foundonexternalonlinesystem++; if ($stripecu) {
$foundonexternalonlinesystem++;
}
} }
$sql = "SELECT COUNT(n.rowid) as nb"; $sql = "SELECT COUNT(n.rowid) as nb";
@ -199,13 +224,8 @@ function societe_prepare_head(Societe $object)
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) { if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
while ($i < $num) {
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
$nbBankAccount = $obj->nb; $nbBankAccount = $obj->nb;
$i++;
}
} else { } else {
dol_print_error($db); dol_print_error($db);
} }
@ -214,8 +234,11 @@ function societe_prepare_head(Societe $object)
$head[$h][0] = DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id; $head[$h][0] = DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id;
$head[$h][1] = $title; $head[$h][1] = $title;
if ($foundonexternalonlinesystem) $head[$h][1] .= '<span class="badge marginleftonlyshort">...</span>'; if ($foundonexternalonlinesystem) {
elseif ($nbBankAccount > 0) $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbBankAccount.'</span>'; $head[$h][1] .= '<span class="badge marginleftonlyshort">...</span>';
} elseif ($nbBankAccount > 0) {
$head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbBankAccount.'</span>';
}
$head[$h][2] = 'rib'; $head[$h][2] = 'rib';
$h++; $h++;
} }
@ -229,17 +252,14 @@ function societe_prepare_head(Societe $object)
$sql .= " WHERE fk_soc = ".$object->id.' AND fk_website > 0'; $sql .= " WHERE fk_soc = ".$object->id.' AND fk_website > 0';
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) { if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
while ($i < $num) {
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
$nbNote = $obj->nb; $nbNote = $obj->nb;
$i++;
}
} else { } else {
dol_print_error($db); dol_print_error($db);
} }
if ($nbNote > 0) $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>'; if ($nbNote > 0) {
$head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
}
$head[$h][2] = 'website'; $head[$h][2] = 'website';
$h++; $h++;
} }
@ -253,37 +273,54 @@ function societe_prepare_head(Societe $object)
if ($user->socid == 0) { if ($user->socid == 0) {
// Notifications // Notifications
if (!empty($conf->notification->enabled)) { if (!empty($conf->notification->enabled)) {
$nbNote = 0; $nbNotif = 0;
// 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 = "SELECT COUNT(n.rowid) as nb";
$sql .= " FROM ".MAIN_DB_PREFIX."notify_def as n"; $sql .= " FROM ".MAIN_DB_PREFIX."notify_def as n";
$sql .= " WHERE fk_soc = ".$object->id; $sql .= " WHERE fk_soc = ".$object->id;
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) { if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
while ($i < $num) {
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
$nbNote = $obj->nb; $nbNotif = $obj->nb;
$i++;
}
} else { } else {
dol_print_error($db); 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);
}
}
$head[$h][0] = DOL_URL_ROOT.'/societe/notify/card.php?socid='.$object->id; $head[$h][0] = DOL_URL_ROOT.'/societe/notify/card.php?socid='.$object->id;
$head[$h][1] = $langs->trans("Notifications"); $head[$h][1] = $langs->trans("Notifications");
if ($nbNote > 0) $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>'; if ($nbNotif > 0) {
$head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNotif.'</span>';
}
$head[$h][2] = 'notify'; $head[$h][2] = 'notify';
$h++; $h++;
} }
// Notes // Notes
$nbNote = 0; $nbNote = 0;
if (!empty($object->note_private)) $nbNote++; if (!empty($object->note_private)) {
if (!empty($object->note_public)) $nbNote++; $nbNote++;
}
if (!empty($object->note_public)) {
$nbNote++;
}
$head[$h][0] = DOL_URL_ROOT.'/societe/note.php?id='.$object->id; $head[$h][0] = DOL_URL_ROOT.'/societe/note.php?id='.$object->id;
$head[$h][1] = $langs->trans("Notes"); $head[$h][1] = $langs->trans("Notes");
if ($nbNote > 0) $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>'; if ($nbNote > 0) {
$head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
}
$head[$h][2] = 'note'; $head[$h][2] = 'note';
$h++; $h++;
@ -296,7 +333,9 @@ function societe_prepare_head(Societe $object)
$head[$h][0] = DOL_URL_ROOT.'/societe/document.php?socid='.$object->id; $head[$h][0] = DOL_URL_ROOT.'/societe/document.php?socid='.$object->id;
$head[$h][1] = $langs->trans("Documents"); $head[$h][1] = $langs->trans("Documents");
if (($nbFiles + $nbLinks) > 0) $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>'; if (($nbFiles + $nbLinks) > 0) {
$head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
}
$head[$h][2] = 'document'; $head[$h][2] = 'document';
$h++; $h++;
} }
@ -304,8 +343,37 @@ function societe_prepare_head(Societe $object)
$head[$h][0] = DOL_URL_ROOT.'/societe/agenda.php?socid='.$object->id; $head[$h][0] = DOL_URL_ROOT.'/societe/agenda.php?socid='.$object->id;
$head[$h][1] = $langs->trans("Events"); $head[$h][1] = $langs->trans("Events");
if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) { 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';
$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;
$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);
}
$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] .= '/'; $head[$h][1] .= '/';
$head[$h][1] .= $langs->trans("Agenda"); $head[$h][1] .= $langs->trans("Agenda");
if ($nbEvent > 0) {
$head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbEvent.'</span>';
}
} }
$head[$h][2] = 'agenda'; $head[$h][2] = 'agenda';
$h++; $h++;
@ -412,16 +480,27 @@ function getCountry($searchkey, $withcode = '', $dbtouse = 0, $outputlangs = '',
// Check parameters // Check parameters
if (empty($searchkey) && empty($searchlabel)) { if (empty($searchkey) && empty($searchlabel)) {
if ($withcode === 'all') return array('id'=>'', 'code'=>'', 'label'=>''); if ($withcode === 'all') {
else return ''; 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"; $sql = "SELECT rowid, code, label FROM ".MAIN_DB_PREFIX."c_country";
if (is_numeric($searchkey)) $sql .= " WHERE rowid=".$searchkey; if (is_numeric($searchkey)) {
elseif (!empty($searchkey)) $sql .= " WHERE code='".$db->escape($searchkey)."'"; $sql .= " WHERE rowid=".$searchkey;
else $sql .= " WHERE label='".$db->escape($searchlabel)."'"; } elseif (!empty($searchkey)) {
$sql .= " WHERE code='".$db->escape($searchkey)."'";
} else {
$sql .= " WHERE label='".$db->escape($searchlabel)."'";
}
$resql = $dbtouse->query($sql); $resql = $dbtouse->query($sql);
if ($resql) { if ($resql) {
@ -433,17 +512,25 @@ 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; 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; 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"; if ($withcode == 1) {
elseif ($withcode == 2) $result = $obj->code; $result = $label ? "$obj->code - $label" : "$obj->code";
elseif ($withcode == 3) $result = $obj->rowid; } elseif ($withcode == 2) {
elseif ($withcode === 'all') $result = array('id'=>$obj->rowid, 'code'=>$obj->code, 'label'=>$label); $result = $obj->code;
else $result = $label; } elseif ($withcode == 3) {
$result = $obj->rowid;
} elseif ($withcode === 'all') {
$result = array('id'=>$obj->rowid, 'code'=>$obj->code, 'label'=>$label);
} else {
$result = $label;
}
} else { } else {
$result = 'NotDefined'; $result = 'NotDefined';
} }
$dbtouse->free($resql); $dbtouse->free($resql);
return $result; return $result;
} else dol_print_error($dbtouse, ''); } else {
dol_print_error($dbtouse, '');
}
return 'Error'; return 'Error';
} }
@ -466,7 +553,9 @@ function getState($id, $withcode = '', $dbtouse = 0, $withregion = 0, $outputlan
{ {
global $db, $langs; 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 = "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"; $sql .= " ".MAIN_DB_PREFIX."c_departements as d, ".MAIN_DB_PREFIX."c_regions as r,".MAIN_DB_PREFIX."c_country as c";
@ -529,7 +618,9 @@ function currency_name($code_iso, $withcode = '', $outputlangs = null)
{ {
global $langs, $db; global $langs, $db;
if (empty($outputlangs)) $outputlangs = $langs; if (empty($outputlangs)) {
$outputlangs = $langs;
}
$outputlangs->load("dict"); $outputlangs->load("dict");
@ -549,8 +640,11 @@ function currency_name($code_iso, $withcode = '', $outputlangs = null)
if ($num) { if ($num) {
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
$label = ($obj->label != '-' ? $obj->label : ''); $label = ($obj->label != '-' ? $obj->label : '');
if ($withcode) return ($label == $code_iso) ? "$code_iso" : "$code_iso - $label"; if ($withcode) {
else return $label; return ($label == $code_iso) ? "$code_iso" : "$code_iso - $label";
} else {
return $label;
}
} else { } else {
return $code_iso; return $code_iso;
} }
@ -1260,14 +1354,27 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon = '', $noprin
$sql .= " a.fk_contact,"; $sql .= " a.fk_contact,";
$sql .= " c.code as acode, c.libelle as alabel, c.picto as apicto,"; $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"; $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"; if (is_object($filterobj) && in_array(get_class($filterobj), array('Societe', 'Client', 'Fournisseur'))) {
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"; $sql .= ", sp.lastname, sp.firstname";
elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') $sql .= ", o.ref"; } elseif (is_object($filterobj) && get_class($filterobj) == 'Dolresource') {
elseif (is_object($filterobj) && get_class($filterobj) == 'Product') $sql .= ", o.ref"; /* Nothing */
elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') $sql .= ", o.ref"; } elseif (is_object($filterobj) && get_class($filterobj) == 'Project') {
elseif (is_object($filterobj) && get_class($filterobj) == 'BOM') $sql .= ", o.ref"; /* Nothing */
elseif (is_object($filterobj) && get_class($filterobj) == 'Contrat') $sql .= ", o.ref"; } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
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 .= ", 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 .= " FROM ".MAIN_DB_PREFIX."actioncomm as a";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u on u.rowid = a.fk_user_action"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u on u.rowid = a.fk_user_action";
@ -1286,7 +1393,9 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon = '', $noprin
$sql .= " ON er.resource_type = 'dolresource'"; $sql .= " ON er.resource_type = 'dolresource'";
$sql .= " AND er.element_id = a.id"; $sql .= " AND er.element_id = a.id";
$sql .= " AND er.resource_id = ".$filterobj->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) == '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) == 'Product') $sql .= ", ".MAIN_DB_PREFIX."product as o";
elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') $sql .= ", ".MAIN_DB_PREFIX."ticket as o"; elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') $sql .= ", ".MAIN_DB_PREFIX."ticket as o";

View File

@ -1,5 +1,6 @@
<?php <?php
/* Copyright (C) 2009-2010 Laurent Destailleur <eldy@users.sourceforge.net> /* Copyright (C) 2009-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2021 Frédéric France <frederic.france@netlogic.fr>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -23,11 +24,34 @@
global $shmkeys, $shmoffset; global $shmkeys, $shmoffset;
$shmkeys = array('main'=>1, 'admin'=>2, 'dict'=>3, 'companies'=>4, 'suppliers'=>5, 'products'=>6, $shmkeys = array(
'commercial'=>7, 'compta'=>8, 'projects'=>9, 'cashdesk'=>10, 'agenda'=>11, 'bills'=>12, 'main' => 1,
'propal'=>13, 'boxes'=>14, 'banks'=>15, 'other'=>16, 'errors'=>17, 'members'=>18, 'ecm'=>19, 'admin' => 2,
'orders'=>20, 'users'=>21, 'help'=>22, 'stocks'=>23, 'interventions'=>24, 'dict' => 3,
'donations'=>25, 'contracts'=>26); '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. $shmoffset = 1000; // Max number of entries found into a language file. If too low, some entries will be overwritten.
@ -45,51 +69,45 @@ function dol_setcache($memoryid, $data)
global $conf; global $conf;
$result = 0; $result = 0;
if (!empty($conf->memcached->enabled) && class_exists('Memcached')) {
// Using a memcached server // Using a memcached server
if (!empty($conf->memcached->enabled) && class_exists('Memcached'))
{
global $dolmemcache; global $dolmemcache;
if (empty($dolmemcache) || !is_object($dolmemcache)) if (empty($dolmemcache) || !is_object($dolmemcache)) {
{
$dolmemcache = new Memcached(); $dolmemcache = new Memcached();
$tmparray = explode(':', $conf->global->MEMCACHED_SERVER); $tmparray = explode(':', $conf->global->MEMCACHED_SERVER);
$result = $dolmemcache->addServer($tmparray[0], $tmparray[1] ? $tmparray[1] : 11211); $result = $dolmemcache->addServer($tmparray[0], $tmparray[1] ? $tmparray[1] : 11211);
if (!$result) return -1; if (!$result) return -1;
} }
$memoryid = session_name().'_'.$memoryid; $memoryid = session_name() . '_' . $memoryid;
//$dolmemcache->setOption(Memcached::OPT_COMPRESSION, false); //$dolmemcache->setOption(Memcached::OPT_COMPRESSION, false);
$dolmemcache->add($memoryid, $data); // This fails if key already exists $dolmemcache->add($memoryid, $data); // This fails if key already exists
$rescode = $dolmemcache->getResultCode(); $rescode = $dolmemcache->getResultCode();
if ($rescode == 0) if ($rescode == 0) {
{
return count($data); return count($data);
} else { } else {
return -$rescode; return -$rescode;
} }
} elseif (!empty($conf->memcached->enabled) && class_exists('Memcache')) } elseif (!empty($conf->memcached->enabled) && class_exists('Memcache')) {
{ // Using a memcache server
global $dolmemcache; global $dolmemcache;
if (empty($dolmemcache) || !is_object($dolmemcache)) if (empty($dolmemcache) || !is_object($dolmemcache)) {
{
$dolmemcache = new Memcache(); $dolmemcache = new Memcache();
$tmparray = explode(':', $conf->global->MEMCACHED_SERVER); $tmparray = explode(':', $conf->global->MEMCACHED_SERVER);
$result = $dolmemcache->addServer($tmparray[0], $tmparray[1] ? $tmparray[1] : 11211); $result = $dolmemcache->addServer($tmparray[0], $tmparray[1] ? $tmparray[1] : 11211);
if (!$result) return -1; if (!$result) return -1;
} }
$memoryid = session_name().'_'.$memoryid; $memoryid = session_name() . '_' . $memoryid;
//$dolmemcache->setOption(Memcached::OPT_COMPRESSION, false); //$dolmemcache->setOption(Memcached::OPT_COMPRESSION, false);
$result = $dolmemcache->add($memoryid, $data); // This fails if key already exists $result = $dolmemcache->add($memoryid, $data); // This fails if key already exists
if ($result) if ($result) {
{
return count($data); return count($data);
} else { } else {
return -1; 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); $result = dol_setshmop($memoryid, $data);
} }
@ -117,7 +135,7 @@ function dol_getcache($memoryid)
if (!$result) return -1; if (!$result) return -1;
} }
$memoryid = session_name().'_'.$memoryid; $memoryid = session_name() . '_' . $memoryid;
//$m->setOption(Memcached::OPT_COMPRESSION, false); //$m->setOption(Memcached::OPT_COMPRESSION, false);
//print "Get memoryid=".$memoryid; //print "Get memoryid=".$memoryid;
$data = $m->get($memoryid); $data = $m->get($memoryid);
@ -138,7 +156,7 @@ function dol_getcache($memoryid)
if (!$result) return -1; if (!$result) return -1;
} }
$memoryid = session_name().'_'.$memoryid; $memoryid = session_name() . '_' . $memoryid;
//$m->setOption(Memcached::OPT_COMPRESSION, false); //$m->setOption(Memcached::OPT_COMPRESSION, false);
$data = $m->get($memoryid); $data = $m->get($memoryid);
//print "memoryid=".$memoryid." - rescode=".$rescode." - data=".count($data)."\n<br>"; //print "memoryid=".$memoryid." - rescode=".$rescode." - data=".count($data)."\n<br>";
@ -168,7 +186,9 @@ function dol_getcache($memoryid)
function dol_getshmopaddress($memoryid) function dol_getshmopaddress($memoryid)
{ {
global $shmkeys, $shmoffset; global $shmkeys, $shmoffset;
if (empty($shmkeys[$memoryid])) return 0; if (empty($shmkeys[$memoryid])) {
return 0;
}
return $shmkeys[$memoryid] + $shmoffset; return $shmkeys[$memoryid] + $shmoffset;
} }
@ -182,10 +202,11 @@ function dol_listshmop()
global $shmkeys, $shmoffset; global $shmkeys, $shmoffset;
$resarray = array(); $resarray = array();
foreach ($shmkeys as $key => $val) foreach ($shmkeys as $key => $val) {
{
$result = dol_getshmop($key); $result = dol_getshmop($key);
if (!is_numeric($result) || $result > 0) $resarray[$key] = $result; if (!is_numeric($result) || $result > 0) {
$resarray[$key] = $result;
}
} }
return $resarray; return $resarray;
} }
@ -208,18 +229,16 @@ function dol_setshmop($memoryid, $data)
$size = strlen($newdata); $size = strlen($newdata);
//print 'dol_setshmop memoryid='.$memoryid." shmkey=".$shmkey." newdata=".$size."bytes<br>\n"; //print 'dol_setshmop memoryid='.$memoryid." shmkey=".$shmkey." newdata=".$size."bytes<br>\n";
$handle = shmop_open($shmkey, 'c', 0644, 6 + $size); $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_written1 = shmop_write($handle, str_pad($size, 6), 0);
$shm_bytes_written2 = shmop_write($handle, $newdata, 6); $shm_bytes_written2 = shmop_write($handle, $newdata, 6);
if (($shm_bytes_written1 + $shm_bytes_written2) != (6 + dol_strlen($newdata))) if (($shm_bytes_written1 + $shm_bytes_written2) != (6 + dol_strlen($newdata))) {
{
print "Couldn't write the entire length of data\n"; print "Couldn't write the entire length of data\n";
} }
shmop_close($handle); shmop_close($handle);
return ($shm_bytes_written1 + $shm_bytes_written2); return ($shm_bytes_written1 + $shm_bytes_written2);
} else { } 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; return -1;
} }
} }
@ -238,8 +257,7 @@ function dol_getshmop($memoryid)
$shmkey = dol_getshmopaddress($memoryid); $shmkey = dol_getshmopaddress($memoryid);
//print 'dol_getshmop memoryid='.$memoryid." shmkey=".$shmkey."<br>\n"; //print 'dol_getshmop memoryid='.$memoryid." shmkey=".$shmkey."<br>\n";
$handle = @shmop_open($shmkey, 'a', 0, 0); $handle = @shmop_open($shmkey, 'a', 0, 0);
if ($handle) if ($handle) {
{
$size = trim(shmop_read($handle, 0, 6)); $size = trim(shmop_read($handle, 0, 6));
if ($size) $data = unserialize(shmop_read($handle, 6, $size)); if ($size) $data = unserialize(shmop_read($handle, 6, $size));
else return -1; else return -1;