From 9f7fcdc8bf59eaf041e7aa248002f8a5df9b9fbd Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Mon, 2 Apr 2018 09:44:45 +0200 Subject: [PATCH] Fix: multiple avoid Warning and errors --- htdocs/core/lib/functions.lib.php | 39 ++++++++++--------- htdocs/expedition/list.php | 7 ++-- .../install/mysql/migration/7.0.0-8.0.0.sql | 6 +++ htdocs/product/inventory/list.php | 13 ++++--- htdocs/product/list.php | 8 +++- htdocs/product/stock/list.php | 2 +- htdocs/product/stock/massstockmove.php | 1 + htdocs/product/stock/mouvement.php | 2 +- 8 files changed, 48 insertions(+), 30 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index dc9d179bb59..9138f886991 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -6466,27 +6466,30 @@ function dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensiti // Clean parameters $order=strtolower($order); - $sizearray=count($array); - if (is_array($array) && $sizearray>0) + if (is_array($array)) { - $temp = array(); - foreach(array_keys($array) as $key) $temp[$key]=$array[$key][$index]; - - if (!$natsort) ($order=='asc') ? asort($temp) : arsort($temp); - else + $sizearray=count($array); + if ($sizearray>0) { - ($case_sensitive) ? natsort($temp) : natcasesort($temp); - if($order!='asc') $temp=array_reverse($temp,TRUE); + $temp = array(); + foreach(array_keys($array) as $key) $temp[$key]=$array[$key][$index]; + + if (!$natsort) ($order=='asc') ? asort($temp) : arsort($temp); + else + { + ($case_sensitive) ? natsort($temp) : natcasesort($temp); + if($order!='asc') $temp=array_reverse($temp,TRUE); + } + + $sorted = array(); + + foreach(array_keys($temp) as $key) + { + (is_numeric($key) && empty($keepindex)) ? $sorted[]=$array[$key] : $sorted[$key]=$array[$key]; + } + + return $sorted; } - - $sorted = array(); - - foreach(array_keys($temp) as $key) - { - (is_numeric($key) && empty($keepindex)) ? $sorted[]=$array[$key] : $sorted[$key]=$array[$key]; - } - - return $sorted; } return $array; } diff --git a/htdocs/expedition/list.php b/htdocs/expedition/list.php index dd6fa84ec4b..f8e082d3b66 100644 --- a/htdocs/expedition/list.php +++ b/htdocs/expedition/list.php @@ -148,12 +148,13 @@ if (empty($reshook)) { // Mass actions. Controls on number of lines checked $maxformassaction=1000; - if (! empty($massaction) && count($toselect) < 1) + $numtoselect = (is_array($toselect)?count($toselect):0); + if (! empty($massaction) && $numtoselect < 1) { $error++; setEventMessages($langs->trans("NoLineChecked"), null, "warnings"); } - if (! $error && count($toselect) > $maxformassaction) + if (! $error && $numtoselect > $maxformassaction) { setEventMessages($langs->trans('TooManyRecordForMassAction',$maxformassaction), null, 'errors'); $error++; @@ -541,7 +542,7 @@ if ($resql) { $shipment->fetchObjectLinked($shipment->id,$shipment->element); $receiving=''; - if (count($shipment->linkedObjects['delivery']) > 0) $receiving=reset($shipment->linkedObjects['delivery']); + if (is_array($shipment->linkedObjects['delivery']) && count($shipment->linkedObjects['delivery']) > 0) $receiving=reset($shipment->linkedObjects['delivery']); if (! empty($arrayfields['l.ref']['checked'])) { diff --git a/htdocs/install/mysql/migration/7.0.0-8.0.0.sql b/htdocs/install/mysql/migration/7.0.0-8.0.0.sql index d9513242969..c8681e7cac3 100644 --- a/htdocs/install/mysql/migration/7.0.0-8.0.0.sql +++ b/htdocs/install/mysql/migration/7.0.0-8.0.0.sql @@ -41,6 +41,12 @@ DROP TABLE llx_c_accountingaccount; update llx_propal set fk_statut = 1 where fk_statut = -1; +ALTER TABLE llx_inventory ADD COLUMN fk_user_author integer; +ALTER TABLE llx_inventory CHANGE COLUMN fk_user_author fk_user_creat integer; +ALTER TABLE llx_inventory ADD COLUMN fk_user_modif integer; +ALTER TABLE llx_inventory ADD COLUMN fk_user_valid integer; +ALTER TABLE llx_inventory ADD COLUMN import_key varchar(14); + -- For 8.0 diff --git a/htdocs/product/inventory/list.php b/htdocs/product/inventory/list.php index a24ca1c8808..95670698380 100644 --- a/htdocs/product/inventory/list.php +++ b/htdocs/product/inventory/list.php @@ -185,7 +185,9 @@ foreach($object->fields as $key => $val) $sql.='t.'.$key.', '; } // Add fields from extrafields -foreach ($extrafields->attributes[$object->element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : ''); +if (! empty($extrafields->attributes[$object->element]['label'])) { + foreach ($extrafields->attributes[$object->element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : ''); +} // Add fields from hooks $parameters=array(); $reshook=$hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook @@ -409,12 +411,13 @@ print ''."\n"; // Detect if we need a fetch on each output line $needToFetchEachLine=0; -foreach ($extrafields->attributes[$object->element]['computed'] as $key => $val) -{ - if (preg_match('/\$object/',$val)) $needToFetchEachLine++; // There is at least one compute field that use $object +if (! empty($extrafields->attributes[$object->element]['computed'])) { + foreach ($extrafields->attributes[$object->element]['computed'] as $key => $val) + { + if (preg_match('/\$object/',$val)) $needToFetchEachLine++; // There is at least one compute field that use $object + } } - // Loop on record // -------------------------------------------------------------------- $i=0; diff --git a/htdocs/product/list.php b/htdocs/product/list.php index c6a7835158d..f030ea3d53e 100644 --- a/htdocs/product/list.php +++ b/htdocs/product/list.php @@ -278,7 +278,9 @@ else $sql .= ', pac.rowid prod_comb_id'; } // Add fields from extrafields - foreach ($extrafields->attributes[$object->element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->element]['type'][$key] != 'separate' ? ",ef.".$key.' as options_'.$key : ''); + if (! empty($extrafields->attributes[$object->element]['label'])) { + foreach ($extrafields->attributes[$object->element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->element]['type'][$key] != 'separate' ? ",ef.".$key.' as options_'.$key : ''); + } // Add fields from hooks $parameters=array(); $reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook @@ -335,7 +337,9 @@ else $sql .= ', pac.rowid'; } // Add fields from extrafields - foreach ($extrafields->attributes[$object->element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->element]['type'][$key] != 'separate' ? ",ef.".$key : ''); + if (! empty($extrafields->attributes[$object->element]['label'])) { + foreach ($extrafields->attributes[$object->element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->element]['type'][$key] != 'separate' ? ",ef.".$key : ''); + } // Add fields from hooks $parameters=array(); $reshook=$hookmanager->executeHooks('printFieldSelect',$parameters); // Note that $action and $object may have been modified by hook diff --git a/htdocs/product/stock/list.php b/htdocs/product/stock/list.php index 58ea5eadc21..20900e31826 100644 --- a/htdocs/product/stock/list.php +++ b/htdocs/product/stock/list.php @@ -43,7 +43,7 @@ $sortorder = GETPOST("sortorder"); if (! $sortfield) $sortfield="e.ref"; if (! $sortorder) $sortorder="ASC"; $page = GETPOST("page"); -if ($page < 0) $page = 0; +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; $year = strftime("%Y",time()); diff --git a/htdocs/product/stock/massstockmove.php b/htdocs/product/stock/massstockmove.php index caea260118f..ebe1fbe5375 100644 --- a/htdocs/product/stock/massstockmove.php +++ b/htdocs/product/stock/massstockmove.php @@ -55,6 +55,7 @@ $idline = GETPOST('idline'); $sortfield = GETPOST('sortfield','alpha'); $sortorder = GETPOST('sortorder','alpha'); $page = GETPOST('page','int'); +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 if (!$sortfield) { $sortfield = 'p.ref'; diff --git a/htdocs/product/stock/mouvement.php b/htdocs/product/stock/mouvement.php index 0bed4022eb3..6093a252cb6 100644 --- a/htdocs/product/stock/mouvement.php +++ b/htdocs/product/stock/mouvement.php @@ -72,7 +72,7 @@ $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit; $page = GETPOST("page",'int'); $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); -if ($page < 0) $page = 0; +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; if (! $sortfield) $sortfield="m.datem"; if (! $sortorder) $sortorder="DESC";