From f84ae10dbfde513435f2d430a4e8982b893b0a70 Mon Sep 17 00:00:00 2001 From: Lucas Marcouiller <45882981+Hystepik@users.noreply.github.com> Date: Mon, 19 Feb 2024 17:57:16 +0100 Subject: [PATCH] Fix some php warnings (#28278) Co-authored-by: Hystepik --- htdocs/contact/consumption.php | 12 +++++++----- htdocs/contact/project.php | 2 +- htdocs/core/db/DoliDB.class.php | 2 +- htdocs/core/lib/company.lib.php | 2 +- htdocs/product/class/product.class.php | 2 +- htdocs/product/price.php | 2 +- htdocs/societe/class/societe.class.php | 2 +- 7 files changed, 13 insertions(+), 11 deletions(-) diff --git a/htdocs/contact/consumption.php b/htdocs/contact/consumption.php index 2b2e52e1bad..1e82f807105 100644 --- a/htdocs/contact/consumption.php +++ b/htdocs/contact/consumption.php @@ -46,7 +46,7 @@ if ($id > 0) { if (empty($object->thirdparty)) { $object->fetch_thirdparty(); } -$socid = $object->thirdparty->id; +$socid = !empty($object->thirdparty->id) ? $object->thirdparty->id : null; // Sort & Order fields $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; @@ -153,7 +153,7 @@ print ''.$langs->trans("UserTitle").''; print $object->getCivilityLabel(); print ''; -if ($object->thirdparty->client) { +if (!empty($object->thirdparty->client)) { $thirdTypeArray['customer'] = $langs->trans("customer"); if (isModEnabled("propal") && $user->hasRight('propal', 'lire')) { $elementTypeArray['propal'] = $langs->transnoentitiesnoconv('Proposals'); @@ -173,7 +173,7 @@ if (isModEnabled('ficheinter') && $user->hasRight('ficheinter', 'lire')) { $elementTypeArray['fichinter'] = $langs->transnoentitiesnoconv('Interventions'); } -if ($object->thirdparty->fournisseur) { +if (!empty($object->thirdparty->fournisseur)) { $thirdTypeArray['supplier'] = $langs->trans("supplier"); if ((isModEnabled("fournisseur") && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight('fournisseur', 'facture', 'lire')) || (isModEnabled("supplier_invoice") && $user->hasRight('supplier_invoice', 'lire'))) { $elementTypeArray['supplier_invoice'] = $langs->transnoentitiesnoconv('SuppliersInvoices'); @@ -364,7 +364,9 @@ $param .= "&sref=".urlencode($sref); $param .= "&month=".urlencode($month); $param .= "&year=".urlencode($year); $param .= "&sprod_fulldescr=".urlencode($sprod_fulldescr); -$param .= "&socid=".urlencode($socid); +if (!empty($socid)) { + $param .= "&socid=".urlencode($socid); +} $param .= "&type_element=".urlencode($type_element); $total_qty = 0; @@ -377,7 +379,7 @@ if ($sql_select) { $num = $db->num_rows($resql); - $param = "&socid=".urlencode($socid)."&type_element=".urlencode($type_element)."&id=".urlencode($id); + $param = (!empty($socid) ? "&socid=".urlencode($socid) : "")."&type_element=".urlencode($type_element)."&id=".urlencode($id); if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { $param .= '&contextpage='.urlencode($contextpage); } diff --git a/htdocs/contact/project.php b/htdocs/contact/project.php index a28bdd861d1..9cc60d2cbe4 100644 --- a/htdocs/contact/project.php +++ b/htdocs/contact/project.php @@ -61,7 +61,7 @@ if ($id) { if (empty($object->thirdparty)) { $object->fetch_thirdparty(); } - $socid = $object->thirdparty->id; + $socid = !empty($object->thirdparty->id) ? $object->thirdparty->id : null; $title = $langs->trans("Projects"); if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/thirdpartynameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) { $title = $object->name." - ".$title; diff --git a/htdocs/core/db/DoliDB.class.php b/htdocs/core/db/DoliDB.class.php index 498183faca6..3b1184c7f85 100644 --- a/htdocs/core/db/DoliDB.class.php +++ b/htdocs/core/db/DoliDB.class.php @@ -296,7 +296,7 @@ abstract class DoliDB implements Database $oldsortorder = ''; $return = ''; $fields = explode(',', $sortfield); - $orders = explode(',', $sortorder); + $orders = (!empty($sortorder) ? explode(',', $sortorder) : array()); $i = 0; foreach ($fields as $val) { if (!$return) { diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 9d1e5192bbe..250a6a34756 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -1692,7 +1692,7 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon = '', $noprin $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u on u.rowid = a.fk_user_action"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_actioncomm as c ON a.fk_action = c.id"; - if (get_class($filterobj) !== 'User') { + if (is_object($filterobj) && get_class($filterobj) !== 'User') { $force_filter_contact = false; } else { $force_filter_contact = true; diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index e045071dfc1..e42e6161064 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -1145,7 +1145,7 @@ class Product extends CommonObject $this->barcode = (empty($this->barcode) ? '' : trim($this->barcode)); $this->accountancy_code_buy = trim($this->accountancy_code_buy); - $this->accountancy_code_buy_intra = trim($this->accountancy_code_buy_intra); + $this->accountancy_code_buy_intra = (!empty($this->accountancy_code_buy_intra) ? trim($this->accountancy_code_buy_intra) : ''); $this->accountancy_code_buy_export = trim($this->accountancy_code_buy_export); $this->accountancy_code_sell = trim($this->accountancy_code_sell); $this->accountancy_code_sell_intra = trim($this->accountancy_code_sell_intra); diff --git a/htdocs/product/price.php b/htdocs/product/price.php index a7557f75bb9..a2abdf524a3 100644 --- a/htdocs/product/price.php +++ b/htdocs/product/price.php @@ -2420,7 +2420,7 @@ if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES')) { $positiverates = '0'; } - echo vatrate($positiverates.($line->default_vat_code ? ' ('.$line->default_vat_code.')' : ''), '%', ($line->tva_npr ? $line->tva_npr : $line->recuperableonly)); + echo vatrate($positiverates.($line->default_vat_code ? ' ('.$line->default_vat_code.')' : ''), '%', (!empty($line->tva_npr) ? $line->tva_npr : $line->recuperableonly)); print ""; diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index b19c0b8a695..b2342b78b7d 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -255,7 +255,7 @@ class Societe extends CommonObject 'localtax2_value' =>array('type'=>'double(6,3)', 'label'=>'Localtax2 value', 'enabled'=>1, 'visible'=>-1, 'position'=>355), 'vat_reverse_charge' =>array('type'=>'tinyint(4)', 'label'=>'Vat reverse charge', 'enabled'=>1, 'visible'=>-1, 'position'=>335), 'barcode' =>array('type'=>'varchar(255)', 'label'=>'Barcode', 'enabled'=>1, 'visible'=>-1, 'position'=>360), - 'price_level' =>array('type'=>'integer', 'label'=>'Price level', 'enabled'=>'$conf->global->PRODUIT_MULTIPRICES || $conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES', 'visible'=>-1, 'position'=>365), + 'price_level' =>array('type'=>'integer', 'label'=>'Price level', 'enabled'=>'$conf->global->PRODUIT_MULTIPRICES || getDolGlobalString("PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES")', 'visible'=>-1, 'position'=>365), 'default_lang' =>array('type'=>'varchar(6)', 'label'=>'Default lang', 'enabled'=>1, 'visible'=>-1, 'position'=>370), 'canvas' =>array('type'=>'varchar(32)', 'label'=>'Canvas', 'enabled'=>1, 'visible'=>-1, 'position'=>375), 'fk_barcode_type' =>array('type'=>'integer', 'label'=>'Fk barcode type', 'enabled'=>1, 'visible'=>-1, 'position'=>405),