From 1b1d1a8d0b093f0bc34d717acce479048afea69e Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@destailleur.fr>
Date: Wed, 23 Aug 2017 16:57:07 +0200
Subject: [PATCH] FIX #7156

---
 htdocs/societe/soc.php | 55 ++++++++++++++++++++++--------------------
 1 file changed, 29 insertions(+), 26 deletions(-)

diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php
index b9c962a5168..06846d34203 100644
--- a/htdocs/societe/soc.php
+++ b/htdocs/societe/soc.php
@@ -140,7 +140,7 @@ if (empty($reshook))
 			if (!$errors)
 			{
 			    // TODO Move the merge function into class of object.
-			    
+
 				$db->begin();
 
 				// Recopy some data
@@ -157,26 +157,29 @@ if (empty($reshook))
 				{
 				    if (empty($object->$property)) $object->$property = $soc_origin->$property;
 				}
-				
+
 				// Concat some data
 				$listofproperties=array(
-				    'note_public', 'note_private' 
+				    'note_public', 'note_private'
 				);
 				foreach ($listofproperties as $property)
 				{
 				    $object->$property = dol_concatdesc($object->$property, $soc_origin->$property);
 				}
-				
+
 				// Merge extrafields
-				foreach ($soc_origin->array_options as $key => $val)
+				if (is_array($soc_origin->array_options))
 				{
-				    if (empty($object->array_options[$key])) $object->array_options[$key] = $val;
+					foreach ($soc_origin->array_options as $key => $val)
+					{
+					    if (empty($object->array_options[$key])) $object->array_options[$key] = $val;
+					}
 				}
 
 				// TODO Merge categories
 				$object->update($object->id, $user);
-				
-				// Move links 
+
+				// Move links
 				$objects = array(
 					'Adherent' => '/adherents/class/adherent.class.php',
 					'Societe' => '/societe/class/societe.class.php',
@@ -487,7 +490,7 @@ if (empty($reshook))
                 if (empty($object->fournisseur)) $object->code_fournisseur='';
 
                 $result = $object->create($user);
-                
+
 				if ($result >= 0)
                 {
                     if ($object->particulier)
@@ -557,7 +560,7 @@ if (empty($reshook))
 						$object->code_fournisseur = null;
 						$object->code_client = null;
 					}
-					
+
                     $error=$object->error; $errors=$object->errors;
                 }
 
@@ -852,7 +855,7 @@ else
         $object->particulier		= $private;
         $object->prefix_comm		= GETPOST('prefix_comm');
         $object->client				= GETPOST('client')?GETPOST('client'):$object->client;
-        
+
         if(empty($duplicate_code_error)) {
 	        $object->code_client		= GETPOST('code_client', 'alpha');
 	        $object->fournisseur		= GETPOST('fournisseur')?GETPOST('fournisseur'):$object->fournisseur;
@@ -860,7 +863,7 @@ else
 		else {
 			setEventMessages($langs->trans('NewCustomerSupplierCodeProposed'),'', 'warnings');
 		}
-		
+
         $object->code_fournisseur	= GETPOST('code_fournisseur', 'alpha');
         $object->address			= GETPOST('address', 'alpha');
         $object->zip				= GETPOST('zipcode', 'alpha');
@@ -1136,7 +1139,7 @@ else
 	    print '<td colspan="3"><input type="text" name="email" id="email" value="'.$object->email.'"></td></tr>';
         print '<tr><td>'.fieldLabel('Web','url').'</td>';
 	    print '<td colspan="3"><input type="text" name="url" id="url" value="'.$object->url.'"></td></tr>';
-	    
+
         // Skype
         if (! empty($conf->skype->enabled))
         {
@@ -1216,7 +1219,7 @@ else
             print '</td><td>'.$langs->transcountry("LocalTax2IsUsed",$mysoc->country_code).'</td><td>';
             print $form->selectyesno('localtax2assuj_value',(isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2)?$conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2:0),1);
             print '</td></tr>';
-        
+
         }
         elseif($mysoc->localtax1_assuj=="1")
         {
@@ -1230,7 +1233,7 @@ else
             print $form->selectyesno('localtax2assuj_value',(isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2)?$conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2:0),1);
             print '</td></tr>';
         }
-        
+
         // Type - Size
         print '<tr><td>'.fieldLabel('ThirdPartyType','typent_id').'</td><td class="maxwidthonsmartphone">'."\n";
         $sortparam=(empty($conf->global->SOCIETE_SORT_ON_TYPEENT)?'ASC':$conf->global->SOCIETE_SORT_ON_TYPEENT); // NONE means we keep sort of original array, so we sort on position. ASC, means next function will sort on label.
@@ -1751,7 +1754,7 @@ else
                     $formcompany->select_localtax(1,$object->localtax1_value, "lt1");
                     print '</span>';
                 }
-            
+
                 print '</td><td>'.fieldLabel($langs->transcountry("LocalTax2IsUsed",$mysoc->country_code),'localtax2assuj_value').'</td><td>';
                 print $form->selectyesno('localtax2assuj_value',$object->localtax2_assuj,1);
                 if  (! isOnlyOneLocalTax(2))
@@ -1761,7 +1764,7 @@ else
                     print '</span>';
                 }
                 print '</td></tr>';
-            
+
             }
             elseif($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj!="1")
             {
@@ -1774,7 +1777,7 @@ else
                     print '</span>';
                 }
                 print '</td></tr>';
-            
+
             }
             elseif($mysoc->localtax2_assuj=="1" && $mysoc->localtax1_assuj!="1")
             {
@@ -1788,7 +1791,7 @@ else
                 }
                 print '</td></tr>';
             }
-            
+
             // VAT Code
             print '<tr><td>'.fieldLabel('VATIntra','intra_vat').'</td>';
             print '<td colspan="3">';
@@ -2090,7 +2093,7 @@ else
 		    print '</td></tr><tr><td>'.$langs->transcountry("LocalTax2IsUsed",$mysoc->country_code).'</td><td>';
 		    print yn($object->localtax2_assuj);
 		    print '</td></tr>';
-		
+
 		    if($object->localtax1_assuj=="1" && (! isOnlyOneLocalTax(1)))
 		    {
 		        print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
@@ -2144,7 +2147,7 @@ else
 		            print '<td>'.$object->localtax1_value.'</td>';
 		        }
 		        print '</tr></form>';
-		
+
 		    }
 		}
 		elseif($mysoc->localtax2_assuj=="1" && $mysoc->localtax1_assuj!="1")
@@ -2154,7 +2157,7 @@ else
 		    print '</td></tr>';
 		    if($object->localtax2_assuj=="1" && (! isOnlyOneLocalTax(2)))
 		    {
-		
+
 		        print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
 		        print '<input type="hidden" name="action" value="set_localtax2">';
 		        print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
@@ -2167,7 +2170,7 @@ else
 		            print '<td>'.$object->localtax2_value.'</td>';
 		        }
 		        print '</tr></form>';
-		
+
 		    }
 		}
 		/*
@@ -2178,7 +2181,7 @@ else
 		 print '</td><tr>';
 		 }
 		 */
-		
+
         // VAT Code
         print '<tr>';
 		print '<td class="nowrap">'.$langs->trans('VATIntra').'</td><td>';
@@ -2573,10 +2576,10 @@ else
 
 	        // Subsidiaries list
 	        if (empty($conf->global->SOCIETE_DISABLE_SUBSIDIARIES))
-	        {	        
+	        {
 	           $result=show_subsidiaries($conf,$langs,$db,$object);
 	        }
-	        
+
 	        // Contacts list
 	        if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
 	        {
-- 
GitLab