Completed
Branch develop (c604ce)
by
unknown
32:31
created
htdocs/core/modules/product/doc/doc_generic_product_odt.modules.php 3 patches
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -275,8 +275,8 @@  discard block
 block discarded – undo
275 275
 				$newfileformat=substr($newfile, strrpos($newfile, '.')+1);
276 276
 				if ( ! empty($conf->global->MAIN_DOC_USE_TIMING))
277 277
 				{
278
-				    $format=$conf->global->MAIN_DOC_USE_TIMING;
279
-				    if ($format == '1') $format='%Y%m%d%H%M%S';
278
+					$format=$conf->global->MAIN_DOC_USE_TIMING;
279
+					if ($format == '1') $format='%Y%m%d%H%M%S';
280 280
 					$filename=$newfiletmp.'-'.dol_print_date(dol_now(),$format).'.'.$newfileformat;
281 281
 				}
282 282
 				else
@@ -307,10 +307,10 @@  discard block
 block discarded – undo
307 307
 					// On peut utiliser le nom de la societe du contact
308 308
 					if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact;
309 309
 					else {
310
-                        			$socobject = $object->thirdparty;
311
-                        			// if we have a CUSTOMER contact and we dont use it as recipient we store the contact object for later use
312
-                        			$contactobject = $object->contact;
313
-                    			}
310
+									$socobject = $object->thirdparty;
311
+									// if we have a CUSTOMER contact and we dont use it as recipient we store the contact object for later use
312
+									$contactobject = $object->contact;
313
+								}
314 314
 				}
315 315
 				else
316 316
 				{
Please login to merge, or discard this patch.
Spacing   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -36,9 +36,9 @@  discard block
 block discarded – undo
36 36
  */
37 37
 class doc_generic_product_odt extends ModelePDFProduct
38 38
 {
39
-	var $emetteur;	// Objet societe qui emet
39
+	var $emetteur; // Objet societe qui emet
40 40
 
41
-	var $phpmin = array(5,2,0);	// Minimum version of PHP required by module
41
+	var $phpmin = array(5, 2, 0); // Minimum version of PHP required by module
42 42
 	var $version = 'dolibarr';
43 43
 
44 44
 
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 	 */
50 50
 	function __construct($db)
51 51
 	{
52
-		global $conf,$langs,$mysoc;
52
+		global $conf, $langs, $mysoc;
53 53
 
54 54
 		$langs->load("main");
55 55
 		$langs->load("companies");
@@ -57,32 +57,32 @@  discard block
 block discarded – undo
57 57
 		$this->db = $db;
58 58
 		$this->name = "ODT templates";
59 59
 		$this->description = $langs->trans("DocumentModelOdt");
60
-		$this->scandir = 'PRODUCT_ADDON_PDF_ODT_PATH';	// Name of constant that is used to save list of directories to scan
60
+		$this->scandir = 'PRODUCT_ADDON_PDF_ODT_PATH'; // Name of constant that is used to save list of directories to scan
61 61
 
62 62
 		// Dimension page pour format A4
63 63
 		$this->type = 'odt';
64 64
 		$this->page_largeur = 0;
65 65
 		$this->page_hauteur = 0;
66
-		$this->format = array($this->page_largeur,$this->page_hauteur);
67
-		$this->marge_gauche=0;
68
-		$this->marge_droite=0;
69
-		$this->marge_haute=0;
70
-		$this->marge_basse=0;
71
-
72
-		$this->option_logo = 1;                    // Affiche logo
73
-		$this->option_tva = 0;                     // Gere option tva PRODUCT_TVAOPTION
74
-		$this->option_modereg = 0;                 // Affiche mode reglement
75
-		$this->option_condreg = 0;                 // Affiche conditions reglement
76
-		$this->option_codeproduitservice = 0;      // Affiche code produit-service
77
-		$this->option_multilang = 1;               // Dispo en plusieurs langues
78
-		$this->option_escompte = 0;                // Affiche si il y a eu escompte
79
-		$this->option_credit_note = 0;             // Support credit notes
80
-		$this->option_freetext = 1;				   // Support add of a personalised text
81
-		$this->option_draft_watermark = 0;		   // Support add of a watermark on drafts
66
+		$this->format = array($this->page_largeur, $this->page_hauteur);
67
+		$this->marge_gauche = 0;
68
+		$this->marge_droite = 0;
69
+		$this->marge_haute = 0;
70
+		$this->marge_basse = 0;
71
+
72
+		$this->option_logo = 1; // Affiche logo
73
+		$this->option_tva = 0; // Gere option tva PRODUCT_TVAOPTION
74
+		$this->option_modereg = 0; // Affiche mode reglement
75
+		$this->option_condreg = 0; // Affiche conditions reglement
76
+		$this->option_codeproduitservice = 0; // Affiche code produit-service
77
+		$this->option_multilang = 1; // Dispo en plusieurs langues
78
+		$this->option_escompte = 0; // Affiche si il y a eu escompte
79
+		$this->option_credit_note = 0; // Support credit notes
80
+		$this->option_freetext = 1; // Support add of a personalised text
81
+		$this->option_draft_watermark = 0; // Support add of a watermark on drafts
82 82
 
83 83
 		// Recupere emetteur
84
-		$this->emetteur=$mysoc;
85
-		if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default if not defined
84
+		$this->emetteur = $mysoc;
85
+		if (!$this->emetteur->country_code) $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined
86 86
 	}
87 87
 
88 88
 
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 	 */
95 95
 	function info($langs)
96 96
 	{
97
-		global $conf,$langs;
97
+		global $conf, $langs;
98 98
 
99 99
 		$langs->load("companies");
100 100
 		$langs->load("errors");
@@ -102,55 +102,55 @@  discard block
 block discarded – undo
102 102
 		$form = new Form($this->db);
103 103
 
104 104
 		$texte = $this->description.".<br>\n";
105
-		$texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
106
-		$texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
107
-		$texte.= '<input type="hidden" name="action" value="setModuleOptions">';
108
-		$texte.= '<input type="hidden" name="param1" value="PRODUCT_ADDON_PDF_ODT_PATH">';
105
+		$texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
106
+		$texte .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
107
+		$texte .= '<input type="hidden" name="action" value="setModuleOptions">';
108
+		$texte .= '<input type="hidden" name="param1" value="PRODUCT_ADDON_PDF_ODT_PATH">';
109 109
 		if ($conf->global->MAIN_PROPAL_CHOOSE_ODT_DOCUMENT > 0)
110 110
 		{
111
-			$texte.= '<input type="hidden" name="param2" value="PRODUCT_ADDON_PDF_ODT_DEFAULT">';
112
-			$texte.= '<input type="hidden" name="param3" value="PRODUCT_ADDON_PDF_ODT_TOBILL">';
113
-			$texte.= '<input type="hidden" name="param4" value="PRODUCT_ADDON_PDF_ODT_CLOSED">';
111
+			$texte .= '<input type="hidden" name="param2" value="PRODUCT_ADDON_PDF_ODT_DEFAULT">';
112
+			$texte .= '<input type="hidden" name="param3" value="PRODUCT_ADDON_PDF_ODT_TOBILL">';
113
+			$texte .= '<input type="hidden" name="param4" value="PRODUCT_ADDON_PDF_ODT_CLOSED">';
114 114
 		}
115
-		$texte.= '<table class="nobordernopadding" width="100%">';
115
+		$texte .= '<table class="nobordernopadding" width="100%">';
116 116
 
117 117
 		// List of directories area
118
-		$texte.= '<tr><td>';
119
-		$texttitle=$langs->trans("ListOfDirectories");
120
-		$listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->PRODUCT_ADDON_PDF_ODT_PATH)));
121
-		$listoffiles=array();
122
-		foreach($listofdir as $key=>$tmpdir)
118
+		$texte .= '<tr><td>';
119
+		$texttitle = $langs->trans("ListOfDirectories");
120
+		$listofdir = explode(',', preg_replace('/[\r\n]+/', ',', trim($conf->global->PRODUCT_ADDON_PDF_ODT_PATH)));
121
+		$listoffiles = array();
122
+		foreach ($listofdir as $key=>$tmpdir)
123 123
 		{
124
-			$tmpdir=trim($tmpdir);
125
-			$tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir);
126
-			if (! $tmpdir) {
124
+			$tmpdir = trim($tmpdir);
125
+			$tmpdir = preg_replace('/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
126
+			if (!$tmpdir) {
127 127
 				unset($listofdir[$key]); continue;
128 128
 			}
129
-			if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
129
+			if (!is_dir($tmpdir)) $texttitle .= img_warning($langs->trans("ErrorDirNotFound", $tmpdir), 0);
130 130
 			else
131 131
 			{
132
-				$tmpfiles=dol_dir_list($tmpdir,'files',0,'\.(ods|odt)');
133
-				if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles);
132
+				$tmpfiles = dol_dir_list($tmpdir, 'files', 0, '\.(ods|odt)');
133
+				if (count($tmpfiles)) $listoffiles = array_merge($listoffiles, $tmpfiles);
134 134
 			}
135 135
 		}
136
-		$texthelp=$langs->trans("ListOfDirectoriesForModelGenODT");
136
+		$texthelp = $langs->trans("ListOfDirectoriesForModelGenODT");
137 137
 		// Add list of substitution keys
138
-		$texthelp.='<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>';
139
-		$texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation");    // This contains an url, we don't modify it
140
-
141
-		$texte.= $form->textwithpicto($texttitle,$texthelp,1,'help','',1);
142
-		$texte.= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
143
-		$texte.= '<textarea class="flat" cols="60" name="value1">';
144
-		$texte.=$conf->global->PRODUCT_ADDON_PDF_ODT_PATH;
145
-		$texte.= '</textarea>';
146
-		$texte.= '</div><div style="display: inline-block; vertical-align: middle;">';
147
-		$texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">';
148
-		$texte.= '<br></div></div>';
138
+		$texthelp .= '<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>';
139
+		$texthelp .= $langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it
140
+
141
+		$texte .= $form->textwithpicto($texttitle, $texthelp, 1, 'help', '', 1);
142
+		$texte .= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
143
+		$texte .= '<textarea class="flat" cols="60" name="value1">';
144
+		$texte .= $conf->global->PRODUCT_ADDON_PDF_ODT_PATH;
145
+		$texte .= '</textarea>';
146
+		$texte .= '</div><div style="display: inline-block; vertical-align: middle;">';
147
+		$texte .= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">';
148
+		$texte .= '<br></div></div>';
149 149
 
150 150
 		// Scan directories
151 151
 		if (count($listofdir))
152 152
 		{
153
-			$texte.=$langs->trans("NumberOfModelFilesFound").': <b>'.count($listoffiles).'</b>';
153
+			$texte .= $langs->trans("NumberOfModelFilesFound").': <b>'.count($listoffiles).'</b>';
154 154
 
155 155
 			/*if ($conf->global->MAIN_PRODUCT_CHOOSE_ODT_DOCUMENT > 0)
156 156
 			{
@@ -178,15 +178,15 @@  discard block
 block discarded – undo
178 178
 			}*/
179 179
 		}
180 180
 
181
-		$texte.= '</td>';
181
+		$texte .= '</td>';
182 182
 
183
-		$texte.= '<td valign="top" rowspan="2" class="hideonsmartphone">';
184
-		$texte.= $langs->trans("ExampleOfDirectoriesForModelGen");
185
-		$texte.= '</td>';
186
-		$texte.= '</tr>';
183
+		$texte .= '<td valign="top" rowspan="2" class="hideonsmartphone">';
184
+		$texte .= $langs->trans("ExampleOfDirectoriesForModelGen");
185
+		$texte .= '</td>';
186
+		$texte .= '</tr>';
187 187
 
188
-		$texte.= '</table>';
189
-		$texte.= '</form>';
188
+		$texte .= '</table>';
189
+		$texte .= '</form>';
190 190
 
191 191
 		return $texte;
192 192
 	}
@@ -202,9 +202,9 @@  discard block
 block discarded – undo
202 202
 	 *  @param		int			$hideref			Do not show ref
203 203
 	 *	@return		int         					1 if OK, <=0 if KO
204 204
 	 */
205
-	function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0)
205
+	function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
206 206
 	{
207
-		global $product,$langs,$conf,$mysoc,$hookmanager,$user;
207
+		global $product, $langs, $conf, $mysoc, $hookmanager, $user;
208 208
 
209 209
 		if (empty($srctemplatepath))
210 210
 		{
@@ -213,17 +213,17 @@  discard block
 block discarded – undo
213 213
 		}
214 214
 
215 215
 		// Add odtgeneration hook
216
-		if (! is_object($hookmanager))
216
+		if (!is_object($hookmanager))
217 217
 		{
218 218
 			include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
219
-			$hookmanager=new HookManager($this->db);
219
+			$hookmanager = new HookManager($this->db);
220 220
 		}
221 221
 		$hookmanager->initHooks(array('odtgeneration'));
222 222
 		global $action;
223 223
 
224
-		if (! is_object($outputlangs)) $outputlangs=$langs;
225
-		$sav_charset_output=$outputlangs->charset_output;
226
-		$outputlangs->charset_output='UTF-8';
224
+		if (!is_object($outputlangs)) $outputlangs = $langs;
225
+		$sav_charset_output = $outputlangs->charset_output;
226
+		$outputlangs->charset_output = 'UTF-8';
227 227
 
228 228
 		$outputlangs->load("main");
229 229
 		$outputlangs->load("dict");
@@ -232,14 +232,14 @@  discard block
 block discarded – undo
232 232
 		if ($conf->produit->dir_output)
233 233
 		{
234 234
 			// If $object is id instead of object
235
-			if (! is_object($object))
235
+			if (!is_object($object))
236 236
 			{
237 237
 				$id = $object;
238 238
 				$object = new Product($this->db);
239
-				$result=$object->fetch($id);
239
+				$result = $object->fetch($id);
240 240
 				if ($result < 0)
241 241
 				{
242
-					dol_print_error($this->db,$object->error);
242
+					dol_print_error($this->db, $object->error);
243 243
 					return -1;
244 244
 				}
245 245
 			}
@@ -249,14 +249,14 @@  discard block
 block discarded – undo
249 249
 
250 250
 			$dir = $conf->produit->dir_output;
251 251
 			$objectref = dol_sanitizeFileName($object->ref);
252
-			if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref;
253
-			$file = $dir . "/" . $objectref . ".odt";
252
+			if (!preg_match('/specimen/i', $objectref)) $dir .= "/".$objectref;
253
+			$file = $dir."/".$objectref.".odt";
254 254
 
255
-			if (! file_exists($dir))
255
+			if (!file_exists($dir))
256 256
 			{
257 257
 				if (dol_mkdir($dir) < 0)
258 258
 				{
259
-					$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
259
+					$this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
260 260
 					return -1;
261 261
 				}
262 262
 			}
@@ -264,26 +264,26 @@  discard block
 block discarded – undo
264 264
 			if (file_exists($dir))
265 265
 			{
266 266
 				//print "srctemplatepath=".$srctemplatepath;	// Src filename
267
-				$newfile=basename($srctemplatepath);
268
-				$newfiletmp=preg_replace('/\.od(t|s)/i','',$newfile);
269
-				$newfiletmp=preg_replace('/template_/i','',$newfiletmp);
270
-				$newfiletmp=preg_replace('/modele_/i','',$newfiletmp);
267
+				$newfile = basename($srctemplatepath);
268
+				$newfiletmp = preg_replace('/\.od(t|s)/i', '', $newfile);
269
+				$newfiletmp = preg_replace('/template_/i', '', $newfiletmp);
270
+				$newfiletmp = preg_replace('/modele_/i', '', $newfiletmp);
271 271
 
272
-				$newfiletmp=$objectref.'_'.$newfiletmp;
272
+				$newfiletmp = $objectref.'_'.$newfiletmp;
273 273
 
274 274
 				// Get extension (ods or odt)
275
-				$newfileformat=substr($newfile, strrpos($newfile, '.')+1);
276
-				if ( ! empty($conf->global->MAIN_DOC_USE_TIMING))
275
+				$newfileformat = substr($newfile, strrpos($newfile, '.') + 1);
276
+				if (!empty($conf->global->MAIN_DOC_USE_TIMING))
277 277
 				{
278
-				    $format=$conf->global->MAIN_DOC_USE_TIMING;
279
-				    if ($format == '1') $format='%Y%m%d%H%M%S';
280
-					$filename=$newfiletmp.'-'.dol_print_date(dol_now(),$format).'.'.$newfileformat;
278
+				    $format = $conf->global->MAIN_DOC_USE_TIMING;
279
+				    if ($format == '1') $format = '%Y%m%d%H%M%S';
280
+					$filename = $newfiletmp.'-'.dol_print_date(dol_now(), $format).'.'.$newfileformat;
281 281
 				}
282 282
 				else
283 283
 				{
284
-					$filename=$newfiletmp.'.'.$newfileformat;
284
+					$filename = $newfiletmp.'.'.$newfileformat;
285 285
 				}
286
-				$file=$dir.'/'.$filename;
286
+				$file = $dir.'/'.$filename;
287 287
 				//print "newdir=".$dir;
288 288
 				//print "newfile=".$newfile;
289 289
 				//print "file=".$file;
@@ -293,19 +293,19 @@  discard block
 block discarded – undo
293 293
 
294 294
 
295 295
 				// If CUSTOMER contact defined on product, we use it
296
-				$usecontact=false;
297
-				$arrayidcontact=$object->getIdContact('external','CUSTOMER');
296
+				$usecontact = false;
297
+				$arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
298 298
 				if (count($arrayidcontact) > 0)
299 299
 				{
300
-					$usecontact=true;
301
-					$result=$object->fetch_contact($arrayidcontact[0]);
300
+					$usecontact = true;
301
+					$result = $object->fetch_contact($arrayidcontact[0]);
302 302
 				}
303 303
 
304 304
 				// Recipient name
305
-				if (! empty($usecontact))
305
+				if (!empty($usecontact))
306 306
 				{
307 307
 					// On peut utiliser le nom de la societe du contact
308
-					if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact;
308
+					if (!empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact;
309 309
 					else {
310 310
                         			$socobject = $object->thirdparty;
311 311
                         			// if we have a CUSTOMER contact and we dont use it as recipient we store the contact object for later use
@@ -314,10 +314,10 @@  discard block
 block discarded – undo
314 314
 				}
315 315
 				else
316 316
 				{
317
-					$socobject=$object->thirdparty;
317
+					$socobject = $object->thirdparty;
318 318
 				}
319 319
 				// Make substitution
320
-				$substitutionarray=array(
320
+				$substitutionarray = array(
321 321
 				'__FROM_NAME__' => $this->emetteur->name,
322 322
 				'__FROM_EMAIL__' => $this->emetteur->email,
323 323
 				'__TOTAL_TTC__' => $object->total_ttc,
@@ -326,15 +326,15 @@  discard block
 block discarded – undo
326 326
 				);
327 327
 				complete_substitutions_array($substitutionarray, $langs, $object);
328 328
 				// Call the ODTSubstitution hook
329
-				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$substitutionarray);
330
-				$reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
329
+				$parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$substitutionarray);
330
+				$reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
331 331
 
332 332
 				// Line of free text
333
-				$newfreetext='';
334
-				$paramfreetext='product_FREE_TEXT';
335
-				if (! empty($conf->global->$paramfreetext))
333
+				$newfreetext = '';
334
+				$paramfreetext = 'product_FREE_TEXT';
335
+				if (!empty($conf->global->$paramfreetext))
336 336
 				{
337
-					$newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray);
337
+					$newfreetext = make_substitutions($conf->global->$paramfreetext, $substitutionarray);
338 338
 				}
339 339
 
340 340
 				// Open and load template
@@ -344,15 +344,15 @@  discard block
 block discarded – undo
344 344
 						$srctemplatepath,
345 345
 						array(
346 346
 						'PATH_TO_TMP'	  => $conf->produit->dir_temp,
347
-						'ZIP_PROXY'		  => 'PclZipProxy',	// PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy.
347
+						'ZIP_PROXY'		  => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy.
348 348
 						'DELIMITER_LEFT'  => '{',
349 349
 						'DELIMITER_RIGHT' => '}'
350 350
 						)
351 351
 					);
352 352
 				}
353
-				catch(Exception $e)
353
+				catch (Exception $e)
354 354
 				{
355
-					$this->error=$e->getMessage();
355
+					$this->error = $e->getMessage();
356 356
 					return -1;
357 357
 				}
358 358
 				// After construction $odfHandler->contentXml contains content and
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
 				try {
368 368
 					$odfHandler->setVars('free_text', $newfreetext, true, 'UTF-8');
369 369
 				}
370
-				catch(OdfException $e)
370
+				catch (OdfException $e)
371 371
 				{
372 372
 				}
373 373
 
@@ -375,25 +375,25 @@  discard block
 block discarded – undo
375 375
 				$substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
376 376
 				$array_object_from_properties = $this->get_substitutionarray_each_var_object($object, $outputlangs);
377 377
 				//$array_objet=$this->get_substitutionarray_object($object,$outputlangs);
378
-				$array_user=$this->get_substitutionarray_user($user,$outputlangs);
379
-				$array_soc=$this->get_substitutionarray_mysoc($mysoc,$outputlangs);
380
-				$array_thirdparty=$this->get_substitutionarray_thirdparty($socobject,$outputlangs);
381
-				$array_other=$this->get_substitutionarray_other($outputlangs);
378
+				$array_user = $this->get_substitutionarray_user($user, $outputlangs);
379
+				$array_soc = $this->get_substitutionarray_mysoc($mysoc, $outputlangs);
380
+				$array_thirdparty = $this->get_substitutionarray_thirdparty($socobject, $outputlangs);
381
+				$array_other = $this->get_substitutionarray_other($outputlangs);
382 382
 				// retrieve contact information for use in product as contact_xxx tags
383 383
 				$array_thirdparty_contact = array();
384
-				if ($usecontact) $array_thirdparty_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact');
384
+				if ($usecontact) $array_thirdparty_contact = $this->get_substitutionarray_contact($contactobject, $outputlangs, 'contact');
385 385
 
386
-				$tmparray = array_merge($substitutionarray,$array_object_from_properties,$array_user,$array_soc,$array_thirdparty,$array_other,$array_thirdparty_contact);
386
+				$tmparray = array_merge($substitutionarray, $array_object_from_properties, $array_user, $array_soc, $array_thirdparty, $array_other, $array_thirdparty_contact);
387 387
 				complete_substitutions_array($tmparray, $outputlangs, $object);
388 388
 
389 389
 				// Call the ODTSubstitution hook
390
-				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
391
-				$reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
390
+				$parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray);
391
+				$reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
392 392
 
393
-				foreach($tmparray as $key=>$value)
393
+				foreach ($tmparray as $key=>$value)
394 394
 				{
395 395
 					try {
396
-						if (preg_match('/logo$/',$key)) // Image
396
+						if (preg_match('/logo$/', $key)) // Image
397 397
 						{
398 398
 							if (file_exists($value)) $odfHandler->setImage($key, $value);
399 399
 							else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
@@ -403,7 +403,7 @@  discard block
 block discarded – undo
403 403
 							$odfHandler->setVars($key, $value, true, 'UTF-8');
404 404
 						}
405 405
 					}
406
-					catch(OdfException $e)
406
+					catch (OdfException $e)
407 407
 					{
408 408
 					}
409 409
 				}
@@ -411,24 +411,24 @@  discard block
 block discarded – undo
411 411
 				try
412 412
 				{
413 413
 					$listlines = $odfHandler->setSegment('supplierprices');
414
-					if(!empty($object->supplierprices)){
414
+					if (!empty($object->supplierprices)) {
415 415
 						foreach ($object->supplierprices as $supplierprice)
416 416
 						{
417 417
 							$array_lines = $this->get_substitutionarray_each_var_object($supplierprice, $outputlangs);
418 418
 							complete_substitutions_array($array_lines, $outputlangs, $object, $supplierprice, "completesubstitutionarray_lines");
419 419
 							// Call the ODTSubstitutionLine hook
420
-							$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$array_lines,'line'=>$supplierprice);
421
-							$reshook=$hookmanager->executeHooks('ODTSubstitutionLine',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
422
-							foreach($array_lines as $key => $val)
420
+							$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$array_lines, 'line'=>$supplierprice);
421
+							$reshook = $hookmanager->executeHooks('ODTSubstitutionLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
422
+							foreach ($array_lines as $key => $val)
423 423
 							{
424 424
 								try
425 425
 								{
426 426
 									$listlines->setVars($key, $val, true, 'UTF-8');
427 427
 								}
428
-								catch(OdfException $e)
428
+								catch (OdfException $e)
429 429
 								{
430 430
 								}
431
-								catch(SegmentException $e)
431
+								catch (SegmentException $e)
432 432
 								{
433 433
 								}
434 434
 							}
@@ -437,61 +437,61 @@  discard block
 block discarded – undo
437 437
 					}
438 438
 					$odfHandler->mergeSegment($listlines);
439 439
 				}
440
-				catch(OdfException $e)
440
+				catch (OdfException $e)
441 441
 				{
442
-					$this->error=$e->getMessage();
442
+					$this->error = $e->getMessage();
443 443
 					dol_syslog($this->error, LOG_WARNING);
444 444
 					return -1;
445 445
 				}
446 446
 
447 447
 				// Replace labels translated
448
-				$tmparray=$outputlangs->get_translations_for_substitutions();
449
-				foreach($tmparray as $key=>$value)
448
+				$tmparray = $outputlangs->get_translations_for_substitutions();
449
+				foreach ($tmparray as $key=>$value)
450 450
 				{
451 451
 					try {
452 452
 						$odfHandler->setVars($key, $value, true, 'UTF-8');
453 453
 					}
454
-					catch(OdfException $e)
454
+					catch (OdfException $e)
455 455
 					{
456 456
 					}
457 457
 				}
458 458
 
459 459
 				// Call the beforeODTSave hook
460
-				$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
461
-				$reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
460
+				$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
461
+				$reshook = $hookmanager->executeHooks('beforeODTSave', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
462 462
 
463 463
 				// Write new file
464 464
 				if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
465 465
 					try {
466 466
 						$odfHandler->exportAsAttachedPDF($file);
467
-					}catch (Exception $e){
468
-						$this->error=$e->getMessage();
467
+					} catch (Exception $e) {
468
+						$this->error = $e->getMessage();
469 469
 						return -1;
470 470
 					}
471 471
 				}
472 472
 				else {
473 473
 					try {
474 474
 					$odfHandler->saveToDisk($file);
475
-					}catch (Exception $e){
476
-						$this->error=$e->getMessage();
475
+					} catch (Exception $e) {
476
+						$this->error = $e->getMessage();
477 477
 						return -1;
478 478
 					}
479 479
 				}
480 480
 
481
-				$reshook=$hookmanager->executeHooks('afterODTCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
481
+				$reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
482 482
 
483
-				if (! empty($conf->global->MAIN_UMASK))
483
+				if (!empty($conf->global->MAIN_UMASK))
484 484
 					@chmod($file, octdec($conf->global->MAIN_UMASK));
485 485
 
486
-				$odfHandler=null;	// Destroy object
486
+				$odfHandler = null; // Destroy object
487 487
 
488 488
 				$this->result = array('fullpath'=>$file);
489 489
 
490
-				return 1;   // Success
490
+				return 1; // Success
491 491
 			}
492 492
 			else
493 493
 			{
494
-				$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
494
+				$this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
495 495
 				return -1;
496 496
 			}
497 497
 		}
Please login to merge, or discard this patch.
Braces   +47 added lines, -40 removed lines patch added patch discarded remove patch
@@ -82,7 +82,10 @@  discard block
 block discarded – undo
82 82
 
83 83
 		// Recupere emetteur
84 84
 		$this->emetteur=$mysoc;
85
-		if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default if not defined
85
+		if (! $this->emetteur->country_code) {
86
+			$this->emetteur->country_code=substr($langs->defaultlang,-2);
87
+		}
88
+		// By default if not defined
86 89
 	}
87 90
 
88 91
 
@@ -126,11 +129,14 @@  discard block
 block discarded – undo
126 129
 			if (! $tmpdir) {
127 130
 				unset($listofdir[$key]); continue;
128 131
 			}
129
-			if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
130
-			else
132
+			if (! is_dir($tmpdir)) {
133
+				$texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
134
+			} else
131 135
 			{
132 136
 				$tmpfiles=dol_dir_list($tmpdir,'files',0,'\.(ods|odt)');
133
-				if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles);
137
+				if (count($tmpfiles)) {
138
+					$listoffiles=array_merge($listoffiles,$tmpfiles);
139
+				}
134 140
 			}
135 141
 		}
136 142
 		$texthelp=$langs->trans("ListOfDirectoriesForModelGenODT");
@@ -221,7 +227,9 @@  discard block
 block discarded – undo
221 227
 		$hookmanager->initHooks(array('odtgeneration'));
222 228
 		global $action;
223 229
 
224
-		if (! is_object($outputlangs)) $outputlangs=$langs;
230
+		if (! is_object($outputlangs)) {
231
+			$outputlangs=$langs;
232
+		}
225 233
 		$sav_charset_output=$outputlangs->charset_output;
226 234
 		$outputlangs->charset_output='UTF-8';
227 235
 
@@ -249,7 +257,9 @@  discard block
 block discarded – undo
249 257
 
250 258
 			$dir = $conf->produit->dir_output;
251 259
 			$objectref = dol_sanitizeFileName($object->ref);
252
-			if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref;
260
+			if (! preg_match('/specimen/i',$objectref)) {
261
+				$dir.= "/" . $objectref;
262
+			}
253 263
 			$file = $dir . "/" . $objectref . ".odt";
254 264
 
255 265
 			if (! file_exists($dir))
@@ -276,10 +286,11 @@  discard block
 block discarded – undo
276 286
 				if ( ! empty($conf->global->MAIN_DOC_USE_TIMING))
277 287
 				{
278 288
 				    $format=$conf->global->MAIN_DOC_USE_TIMING;
279
-				    if ($format == '1') $format='%Y%m%d%H%M%S';
289
+				    if ($format == '1') {
290
+				    	$format='%Y%m%d%H%M%S';
291
+				    }
280 292
 					$filename=$newfiletmp.'-'.dol_print_date(dol_now(),$format).'.'.$newfileformat;
281
-				}
282
-				else
293
+				} else
283 294
 				{
284 295
 					$filename=$newfiletmp.'.'.$newfileformat;
285 296
 				}
@@ -305,14 +316,14 @@  discard block
 block discarded – undo
305 316
 				if (! empty($usecontact))
306 317
 				{
307 318
 					// On peut utiliser le nom de la societe du contact
308
-					if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact;
309
-					else {
319
+					if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) {
320
+						$socobject = $object->contact;
321
+					} else {
310 322
                         			$socobject = $object->thirdparty;
311 323
                         			// if we have a CUSTOMER contact and we dont use it as recipient we store the contact object for later use
312 324
                         			$contactobject = $object->contact;
313 325
                     			}
314
-				}
315
-				else
326
+				} else
316 327
 				{
317 328
 					$socobject=$object->thirdparty;
318 329
 				}
@@ -349,8 +360,7 @@  discard block
 block discarded – undo
349 360
 						'DELIMITER_RIGHT' => '}'
350 361
 						)
351 362
 					);
352
-				}
353
-				catch(Exception $e)
363
+				} catch(Exception $e)
354 364
 				{
355 365
 					$this->error=$e->getMessage();
356 366
 					return -1;
@@ -366,8 +376,7 @@  discard block
 block discarded – undo
366 376
 				// Make substitutions into odt of freetext
367 377
 				try {
368 378
 					$odfHandler->setVars('free_text', $newfreetext, true, 'UTF-8');
369
-				}
370
-				catch(OdfException $e)
379
+				} catch(OdfException $e)
371 380
 				{
372 381
 				}
373 382
 
@@ -381,7 +390,9 @@  discard block
 block discarded – undo
381 390
 				$array_other=$this->get_substitutionarray_other($outputlangs);
382 391
 				// retrieve contact information for use in product as contact_xxx tags
383 392
 				$array_thirdparty_contact = array();
384
-				if ($usecontact) $array_thirdparty_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact');
393
+				if ($usecontact) {
394
+					$array_thirdparty_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact');
395
+				}
385 396
 
386 397
 				$tmparray = array_merge($substitutionarray,$array_object_from_properties,$array_user,$array_soc,$array_thirdparty,$array_other,$array_thirdparty_contact);
387 398
 				complete_substitutions_array($tmparray, $outputlangs, $object);
@@ -393,17 +404,18 @@  discard block
 block discarded – undo
393 404
 				foreach($tmparray as $key=>$value)
394 405
 				{
395 406
 					try {
396
-						if (preg_match('/logo$/',$key)) // Image
407
+						if (preg_match('/logo$/',$key)) {
408
+							// Image
397 409
 						{
398 410
 							if (file_exists($value)) $odfHandler->setImage($key, $value);
399
-							else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
400
-						}
401
-						else    // Text
411
+						} else {
412
+								$odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
413
+							}
414
+						} else    // Text
402 415
 						{
403 416
 							$odfHandler->setVars($key, $value, true, 'UTF-8');
404 417
 						}
405
-					}
406
-					catch(OdfException $e)
418
+					} catch(OdfException $e)
407 419
 					{
408 420
 					}
409 421
 				}
@@ -424,11 +436,9 @@  discard block
 block discarded – undo
424 436
 								try
425 437
 								{
426 438
 									$listlines->setVars($key, $val, true, 'UTF-8');
427
-								}
428
-								catch(OdfException $e)
439
+								} catch(OdfException $e)
429 440
 								{
430
-								}
431
-								catch(SegmentException $e)
441
+								} catch(SegmentException $e)
432 442
 								{
433 443
 								}
434 444
 							}
@@ -436,8 +446,7 @@  discard block
 block discarded – undo
436 446
 						}
437 447
 					}
438 448
 					$odfHandler->mergeSegment($listlines);
439
-				}
440
-				catch(OdfException $e)
449
+				} catch(OdfException $e)
441 450
 				{
442 451
 					$this->error=$e->getMessage();
443 452
 					dol_syslog($this->error, LOG_WARNING);
@@ -450,8 +459,7 @@  discard block
 block discarded – undo
450 459
 				{
451 460
 					try {
452 461
 						$odfHandler->setVars($key, $value, true, 'UTF-8');
453
-					}
454
-					catch(OdfException $e)
462
+					} catch(OdfException $e)
455 463
 					{
456 464
 					}
457 465
 				}
@@ -464,15 +472,14 @@  discard block
 block discarded – undo
464 472
 				if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
465 473
 					try {
466 474
 						$odfHandler->exportAsAttachedPDF($file);
467
-					}catch (Exception $e){
475
+					} catch (Exception $e){
468 476
 						$this->error=$e->getMessage();
469 477
 						return -1;
470 478
 					}
471
-				}
472
-				else {
479
+				} else {
473 480
 					try {
474 481
 					$odfHandler->saveToDisk($file);
475
-					}catch (Exception $e){
482
+					} catch (Exception $e){
476 483
 						$this->error=$e->getMessage();
477 484
 						return -1;
478 485
 					}
@@ -480,16 +487,16 @@  discard block
 block discarded – undo
480 487
 
481 488
 				$reshook=$hookmanager->executeHooks('afterODTCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
482 489
 
483
-				if (! empty($conf->global->MAIN_UMASK))
484
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
490
+				if (! empty($conf->global->MAIN_UMASK)) {
491
+									@chmod($file, octdec($conf->global->MAIN_UMASK));
492
+				}
485 493
 
486 494
 				$odfHandler=null;	// Destroy object
487 495
 
488 496
 				$this->result = array('fullpath'=>$file);
489 497
 
490 498
 				return 1;   // Success
491
-			}
492
-			else
499
+			} else
493 500
 			{
494 501
 				$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
495 502
 				return -1;
Please login to merge, or discard this patch.
htdocs/core/modules/usergroup/doc/doc_generic_usergroup_odt.modules.php 2 patches
Spacing   +163 added lines, -163 removed lines patch added patch discarded remove patch
@@ -37,9 +37,9 @@  discard block
 block discarded – undo
37 37
  */
38 38
 class doc_generic_usergroup_odt extends ModelePDFUserGroup
39 39
 {
40
-	var $emetteur;	// Objet societe qui emet
40
+	var $emetteur; // Objet societe qui emet
41 41
 
42
-	var $phpmin = array(5,2,0);	// Minimum version of PHP required by module
42
+	var $phpmin = array(5, 2, 0); // Minimum version of PHP required by module
43 43
 	var $version = 'dolibarr';
44 44
 
45 45
 
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 	 */
51 51
 	function __construct($db)
52 52
 	{
53
-		global $conf,$langs,$mysoc;
53
+		global $conf, $langs, $mysoc;
54 54
 
55 55
 		$langs->load("main");
56 56
 		$langs->load("companies");
@@ -58,32 +58,32 @@  discard block
 block discarded – undo
58 58
 		$this->db = $db;
59 59
 		$this->name = "ODT templates";
60 60
 		$this->description = $langs->trans("DocumentModelOdt");
61
-		$this->scandir = 'USERGROUP_ADDON_PDF_ODT_PATH';	// Name of constant that is used to save list of directories to scan
61
+		$this->scandir = 'USERGROUP_ADDON_PDF_ODT_PATH'; // Name of constant that is used to save list of directories to scan
62 62
 
63 63
 		// Dimension page pour format A4
64 64
 		$this->type = 'odt';
65 65
 		$this->page_largeur = 0;
66 66
 		$this->page_hauteur = 0;
67
-		$this->format = array($this->page_largeur,$this->page_hauteur);
68
-		$this->marge_gauche=0;
69
-		$this->marge_droite=0;
70
-		$this->marge_haute=0;
71
-		$this->marge_basse=0;
72
-
73
-		$this->option_logo = 1;                    // Affiche logo
74
-		$this->option_tva = 0;                     // Gere option tva USERGROUP_TVAOPTION
75
-		$this->option_modereg = 0;                 // Affiche mode reglement
76
-		$this->option_condreg = 0;                 // Affiche conditions reglement
77
-		$this->option_codeproduitservice = 0;      // Affiche code produit-service
78
-		$this->option_multilang = 1;               // Dispo en plusieurs langues
79
-		$this->option_escompte = 0;                // Affiche si il y a eu escompte
80
-		$this->option_credit_note = 0;             // Support credit notes
81
-		$this->option_freetext = 1;				   // Support add of a personalised text
82
-		$this->option_draft_watermark = 0;		   // Support add of a watermark on drafts
67
+		$this->format = array($this->page_largeur, $this->page_hauteur);
68
+		$this->marge_gauche = 0;
69
+		$this->marge_droite = 0;
70
+		$this->marge_haute = 0;
71
+		$this->marge_basse = 0;
72
+
73
+		$this->option_logo = 1; // Affiche logo
74
+		$this->option_tva = 0; // Gere option tva USERGROUP_TVAOPTION
75
+		$this->option_modereg = 0; // Affiche mode reglement
76
+		$this->option_condreg = 0; // Affiche conditions reglement
77
+		$this->option_codeproduitservice = 0; // Affiche code produit-service
78
+		$this->option_multilang = 1; // Dispo en plusieurs langues
79
+		$this->option_escompte = 0; // Affiche si il y a eu escompte
80
+		$this->option_credit_note = 0; // Support credit notes
81
+		$this->option_freetext = 1; // Support add of a personalised text
82
+		$this->option_draft_watermark = 0; // Support add of a watermark on drafts
83 83
 
84 84
 		// Recupere emetteur
85
-		$this->emetteur=$mysoc;
86
-		if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default if not defined
85
+		$this->emetteur = $mysoc;
86
+		if (!$this->emetteur->country_code) $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined
87 87
 	}
88 88
 
89 89
 
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 	 */
96 96
 	function info($langs)
97 97
 	{
98
-		global $conf,$langs;
98
+		global $conf, $langs;
99 99
 
100 100
 		$langs->load("companies");
101 101
 		$langs->load("errors");
@@ -103,91 +103,91 @@  discard block
 block discarded – undo
103 103
 		$form = new Form($this->db);
104 104
 
105 105
 		$texte = $this->description.".<br>\n";
106
-		$texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
107
-		$texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
108
-		$texte.= '<input type="hidden" name="action" value="setModuleOptions">';
109
-		$texte.= '<input type="hidden" name="param1" value="USERGROUP_ADDON_PDF_ODT_PATH">';
106
+		$texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
107
+		$texte .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
108
+		$texte .= '<input type="hidden" name="action" value="setModuleOptions">';
109
+		$texte .= '<input type="hidden" name="param1" value="USERGROUP_ADDON_PDF_ODT_PATH">';
110 110
 		if ($conf->global->MAIN_PROPAL_CHOOSE_ODT_DOCUMENT > 0)
111 111
 		{
112
-			$texte.= '<input type="hidden" name="param2" value="USERGROUP_ADDON_PDF_ODT_DEFAULT">';
113
-			$texte.= '<input type="hidden" name="param3" value="USERGROUP_ADDON_PDF_ODT_TOBILL">';
114
-			$texte.= '<input type="hidden" name="param4" value="USERGROUP_ADDON_PDF_ODT_CLOSED">';
112
+			$texte .= '<input type="hidden" name="param2" value="USERGROUP_ADDON_PDF_ODT_DEFAULT">';
113
+			$texte .= '<input type="hidden" name="param3" value="USERGROUP_ADDON_PDF_ODT_TOBILL">';
114
+			$texte .= '<input type="hidden" name="param4" value="USERGROUP_ADDON_PDF_ODT_CLOSED">';
115 115
 		}
116
-		$texte.= '<table class="nobordernopadding" width="100%">';
116
+		$texte .= '<table class="nobordernopadding" width="100%">';
117 117
 
118 118
 		// List of directories area
119
-		$texte.= '<tr><td>';
120
-		$texttitle=$langs->trans("ListOfDirectories");
121
-		$listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->USERGROUP_ADDON_PDF_ODT_PATH)));
122
-		$listoffiles=array();
123
-		foreach($listofdir as $key=>$tmpdir)
119
+		$texte .= '<tr><td>';
120
+		$texttitle = $langs->trans("ListOfDirectories");
121
+		$listofdir = explode(',', preg_replace('/[\r\n]+/', ',', trim($conf->global->USERGROUP_ADDON_PDF_ODT_PATH)));
122
+		$listoffiles = array();
123
+		foreach ($listofdir as $key=>$tmpdir)
124 124
 		{
125
-			$tmpdir=trim($tmpdir);
126
-			$tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir);
127
-			if (! $tmpdir) {
125
+			$tmpdir = trim($tmpdir);
126
+			$tmpdir = preg_replace('/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
127
+			if (!$tmpdir) {
128 128
 				unset($listofdir[$key]); continue;
129 129
 			}
130
-			if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
130
+			if (!is_dir($tmpdir)) $texttitle .= img_warning($langs->trans("ErrorDirNotFound", $tmpdir), 0);
131 131
 			else
132 132
 			{
133
-				$tmpfiles=dol_dir_list($tmpdir,'files',0,'\.(ods|odt)');
134
-				if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles);
133
+				$tmpfiles = dol_dir_list($tmpdir, 'files', 0, '\.(ods|odt)');
134
+				if (count($tmpfiles)) $listoffiles = array_merge($listoffiles, $tmpfiles);
135 135
 			}
136 136
 		}
137
-		$texthelp=$langs->trans("ListOfDirectoriesForModelGenODT");
137
+		$texthelp = $langs->trans("ListOfDirectoriesForModelGenODT");
138 138
 		// Add list of substitution keys
139
-		$texthelp.='<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>';
140
-		$texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation");    // This contains an url, we don't modify it
141
-
142
-		$texte.= $form->textwithpicto($texttitle,$texthelp,1,'help','',1);
143
-		$texte.= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
144
-		$texte.= '<textarea class="flat" cols="60" name="value1">';
145
-		$texte.=$conf->global->USERGROUP_ADDON_PDF_ODT_PATH;
146
-		$texte.= '</textarea>';
147
-		$texte.= '</div><div style="display: inline-block; vertical-align: middle;">';
148
-		$texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">';
149
-		$texte.= '<br></div></div>';
139
+		$texthelp .= '<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>';
140
+		$texthelp .= $langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it
141
+
142
+		$texte .= $form->textwithpicto($texttitle, $texthelp, 1, 'help', '', 1);
143
+		$texte .= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
144
+		$texte .= '<textarea class="flat" cols="60" name="value1">';
145
+		$texte .= $conf->global->USERGROUP_ADDON_PDF_ODT_PATH;
146
+		$texte .= '</textarea>';
147
+		$texte .= '</div><div style="display: inline-block; vertical-align: middle;">';
148
+		$texte .= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">';
149
+		$texte .= '<br></div></div>';
150 150
 
151 151
 		// Scan directories
152 152
 		if (count($listofdir))
153 153
 		{
154
-			$texte.=$langs->trans("NumberOfModelFilesFound").': <b>'.count($listoffiles).'</b>';
154
+			$texte .= $langs->trans("NumberOfModelFilesFound").': <b>'.count($listoffiles).'</b>';
155 155
 
156 156
 			if ($conf->global->MAIN_PROPAL_CHOOSE_ODT_DOCUMENT > 0)
157 157
 			{
158 158
 				// Model for creation
159
-				$liste=ModelePDFUserGroup::liste_modeles($this->db);
160
-				$texte.= '<table width="50%;">';
161
-				$texte.= '<tr>';
162
-				$texte.= '<td width="60%;">'.$langs->trans("DefaultModelPropalCreate").'</td>';
163
-				$texte.= '<td colspan="">';
164
-				$texte.= $form->selectarray('value2',$liste,$conf->global->USERGROUP_ADDON_PDF_ODT_DEFAULT);
165
-				$texte.= "</td></tr>";
166
-
167
-				$texte.= '<tr>';
168
-				$texte.= '<td width="60%;">'.$langs->trans("DefaultModelPropalToBill").'</td>';
169
-				$texte.= '<td colspan="">';
170
-				$texte.= $form->selectarray('value3',$liste,$conf->global->USERGROUP_ADDON_PDF_ODT_TOBILL);
171
-				$texte.= "</td></tr>";
172
-				$texte.= '<tr>';
173
-
174
-				$texte.= '<td width="60%;">'.$langs->trans("DefaultModelPropalClosed").'</td>';
175
-				$texte.= '<td colspan="">';
176
-				$texte.= $form->selectarray('value4',$liste,$conf->global->USERGROUP_ADDON_PDF_ODT_CLOSED);
177
-				$texte.= "</td></tr>";
178
-				$texte.= '</table>';
159
+				$liste = ModelePDFUserGroup::liste_modeles($this->db);
160
+				$texte .= '<table width="50%;">';
161
+				$texte .= '<tr>';
162
+				$texte .= '<td width="60%;">'.$langs->trans("DefaultModelPropalCreate").'</td>';
163
+				$texte .= '<td colspan="">';
164
+				$texte .= $form->selectarray('value2', $liste, $conf->global->USERGROUP_ADDON_PDF_ODT_DEFAULT);
165
+				$texte .= "</td></tr>";
166
+
167
+				$texte .= '<tr>';
168
+				$texte .= '<td width="60%;">'.$langs->trans("DefaultModelPropalToBill").'</td>';
169
+				$texte .= '<td colspan="">';
170
+				$texte .= $form->selectarray('value3', $liste, $conf->global->USERGROUP_ADDON_PDF_ODT_TOBILL);
171
+				$texte .= "</td></tr>";
172
+				$texte .= '<tr>';
173
+
174
+				$texte .= '<td width="60%;">'.$langs->trans("DefaultModelPropalClosed").'</td>';
175
+				$texte .= '<td colspan="">';
176
+				$texte .= $form->selectarray('value4', $liste, $conf->global->USERGROUP_ADDON_PDF_ODT_CLOSED);
177
+				$texte .= "</td></tr>";
178
+				$texte .= '</table>';
179 179
 			}
180 180
 		}
181 181
 
182
-		$texte.= '</td>';
182
+		$texte .= '</td>';
183 183
 
184
-		$texte.= '<td valign="top" rowspan="2" class="hideonsmartphone">';
185
-		$texte.= $langs->trans("ExampleOfDirectoriesForModelGen");
186
-		$texte.= '</td>';
187
-		$texte.= '</tr>';
184
+		$texte .= '<td valign="top" rowspan="2" class="hideonsmartphone">';
185
+		$texte .= $langs->trans("ExampleOfDirectoriesForModelGen");
186
+		$texte .= '</td>';
187
+		$texte .= '</tr>';
188 188
 
189
-		$texte.= '</table>';
190
-		$texte.= '</form>';
189
+		$texte .= '</table>';
190
+		$texte .= '</form>';
191 191
 
192 192
 		return $texte;
193 193
 	}
@@ -203,9 +203,9 @@  discard block
 block discarded – undo
203 203
 	 *  @param		int			$hideref			Do not show ref
204 204
 	 *	@return		int         					1 if OK, <=0 if KO
205 205
 	 */
206
-	function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0)
206
+	function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
207 207
 	{
208
-		global $user,$langs,$conf,$mysoc,$hookmanager;
208
+		global $user, $langs, $conf, $mysoc, $hookmanager;
209 209
 
210 210
 		if (empty($srctemplatepath))
211 211
 		{
@@ -214,17 +214,17 @@  discard block
 block discarded – undo
214 214
 		}
215 215
 
216 216
 		// Add odtgeneration hook
217
-		if (! is_object($hookmanager))
217
+		if (!is_object($hookmanager))
218 218
 		{
219 219
 			include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
220
-			$hookmanager=new HookManager($this->db);
220
+			$hookmanager = new HookManager($this->db);
221 221
 		}
222 222
 		$hookmanager->initHooks(array('odtgeneration'));
223 223
 		global $action;
224 224
 
225
-		if (! is_object($outputlangs)) $outputlangs=$langs;
226
-		$sav_charset_output=$outputlangs->charset_output;
227
-		$outputlangs->charset_output='UTF-8';
225
+		if (!is_object($outputlangs)) $outputlangs = $langs;
226
+		$sav_charset_output = $outputlangs->charset_output;
227
+		$outputlangs->charset_output = 'UTF-8';
228 228
 
229 229
 		$outputlangs->load("main");
230 230
 		$outputlangs->load("dict");
@@ -234,28 +234,28 @@  discard block
 block discarded – undo
234 234
 		if ($conf->user->dir_output)
235 235
 		{
236 236
 			// If $object is id instead of object
237
-			if (! is_object($object))
237
+			if (!is_object($object))
238 238
 			{
239 239
 				$id = $object;
240 240
 				$object = new UserGroup($this->db);
241
-				$result=$object->fetch($id);
241
+				$result = $object->fetch($id);
242 242
 				if ($result < 0)
243 243
 				{
244
-					dol_print_error($this->db,$object->error);
244
+					dol_print_error($this->db, $object->error);
245 245
 					return -1;
246 246
 				}
247 247
 			}
248 248
 
249 249
 			$dir = $conf->usergroup->dir_output;
250 250
 			$objectref = dol_sanitizeFileName($object->ref);
251
-			if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref;
252
-			$file = $dir . "/" . $objectref . ".odt";
251
+			if (!preg_match('/specimen/i', $objectref)) $dir .= "/".$objectref;
252
+			$file = $dir."/".$objectref.".odt";
253 253
 
254
-			if (! file_exists($dir))
254
+			if (!file_exists($dir))
255 255
 			{
256 256
 				if (dol_mkdir($dir) < 0)
257 257
 				{
258
-					$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
258
+					$this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
259 259
 					return -1;
260 260
 				}
261 261
 			}
@@ -263,26 +263,26 @@  discard block
 block discarded – undo
263 263
 			if (file_exists($dir))
264 264
 			{
265 265
 				//print "srctemplatepath=".$srctemplatepath;	// Src filename
266
-				$newfile=basename($srctemplatepath);
267
-				$newfiletmp=preg_replace('/\.od(t|s)/i','',$newfile);
268
-				$newfiletmp=preg_replace('/template_/i','',$newfiletmp);
269
-				$newfiletmp=preg_replace('/modele_/i','',$newfiletmp);
266
+				$newfile = basename($srctemplatepath);
267
+				$newfiletmp = preg_replace('/\.od(t|s)/i', '', $newfile);
268
+				$newfiletmp = preg_replace('/template_/i', '', $newfiletmp);
269
+				$newfiletmp = preg_replace('/modele_/i', '', $newfiletmp);
270 270
 
271
-				$newfiletmp=$objectref.'_'.$newfiletmp;
271
+				$newfiletmp = $objectref.'_'.$newfiletmp;
272 272
 
273 273
 				// Get extension (ods or odt)
274
-				$newfileformat=substr($newfile, strrpos($newfile, '.')+1);
275
-				if ( ! empty($conf->global->MAIN_DOC_USE_TIMING))
274
+				$newfileformat = substr($newfile, strrpos($newfile, '.') + 1);
275
+				if (!empty($conf->global->MAIN_DOC_USE_TIMING))
276 276
 				{
277
-				    $format=$conf->global->MAIN_DOC_USE_TIMING;
278
-				    if ($format == '1') $format='%Y%m%d%H%M%S';
279
-					$filename=$newfiletmp.'-'.dol_print_date(dol_now(),$format).'.'.$newfileformat;
277
+				    $format = $conf->global->MAIN_DOC_USE_TIMING;
278
+				    if ($format == '1') $format = '%Y%m%d%H%M%S';
279
+					$filename = $newfiletmp.'-'.dol_print_date(dol_now(), $format).'.'.$newfileformat;
280 280
 				}
281 281
 				else
282 282
 				{
283
-					$filename=$newfiletmp.'.'.$newfileformat;
283
+					$filename = $newfiletmp.'.'.$newfileformat;
284 284
 				}
285
-				$file=$dir.'/'.$filename;
285
+				$file = $dir.'/'.$filename;
286 286
 				//print "newdir=".$dir;
287 287
 				//print "newfile=".$newfile;
288 288
 				//print "file=".$file;
@@ -292,19 +292,19 @@  discard block
 block discarded – undo
292 292
 
293 293
 
294 294
 				// If CUSTOMER contact defined on user, we use it
295
-				$usecontact=false;
296
-				$arrayidcontact=$object->getIdContact('external','CUSTOMER');
295
+				$usecontact = false;
296
+				$arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
297 297
 				if (count($arrayidcontact) > 0)
298 298
 				{
299
-					$usecontact=true;
300
-					$result=$object->fetch_contact($arrayidcontact[0]);
299
+					$usecontact = true;
300
+					$result = $object->fetch_contact($arrayidcontact[0]);
301 301
 				}
302 302
 
303 303
 				// Recipient name
304
-				if (! empty($usecontact))
304
+				if (!empty($usecontact))
305 305
 				{
306 306
 					// On peut utiliser le nom de la societe du contact
307
-					if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact;
307
+					if (!empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact;
308 308
 					else {
309 309
                         			$socobject = $object->thirdparty;
310 310
                         			// if we have a CUSTOMER contact and we dont use it as recipient we store the contact object for later use
@@ -313,10 +313,10 @@  discard block
 block discarded – undo
313 313
 				}
314 314
 				else
315 315
 				{
316
-					$socobject=$object->thirdparty;
316
+					$socobject = $object->thirdparty;
317 317
 				}
318 318
 				// Make substitution
319
-				$substitutionarray=array(
319
+				$substitutionarray = array(
320 320
 				'__FROM_NAME__' => $this->emetteur->name,
321 321
 				'__FROM_EMAIL__' => $this->emetteur->email,
322 322
 				'__TOTAL_TTC__' => $object->total_ttc,
@@ -325,15 +325,15 @@  discard block
 block discarded – undo
325 325
 				);
326 326
 				complete_substitutions_array($substitutionarray, $langs, $object);
327 327
 				// Call the ODTSubstitution hook
328
-				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$substitutionarray);
329
-				$reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
328
+				$parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$substitutionarray);
329
+				$reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
330 330
 
331 331
 				// Line of free text
332
-				$newfreetext='';
333
-				$paramfreetext='user_FREE_TEXT';
334
-				if (! empty($conf->global->$paramfreetext))
332
+				$newfreetext = '';
333
+				$paramfreetext = 'user_FREE_TEXT';
334
+				if (!empty($conf->global->$paramfreetext))
335 335
 				{
336
-					$newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray);
336
+					$newfreetext = make_substitutions($conf->global->$paramfreetext, $substitutionarray);
337 337
 				}
338 338
 
339 339
 				// Open and load template
@@ -343,15 +343,15 @@  discard block
 block discarded – undo
343 343
 						$srctemplatepath,
344 344
 						array(
345 345
 						'PATH_TO_TMP'	  => $conf->user->dir_temp,
346
-						'ZIP_PROXY'		  => 'PclZipProxy',	// PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy.
346
+						'ZIP_PROXY'		  => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy.
347 347
 						'DELIMITER_LEFT'  => '{',
348 348
 						'DELIMITER_RIGHT' => '}'
349 349
 						)
350 350
 					);
351 351
 				}
352
-				catch(Exception $e)
352
+				catch (Exception $e)
353 353
 				{
354
-					$this->error=$e->getMessage();
354
+					$this->error = $e->getMessage();
355 355
 					return -1;
356 356
 				}
357 357
 				// After construction $odfHandler->contentXml contains content and
@@ -365,33 +365,33 @@  discard block
 block discarded – undo
365 365
 				try {
366 366
 					$odfHandler->setVars('free_text', $newfreetext, true, 'UTF-8');
367 367
 				}
368
-				catch(OdfException $e)
368
+				catch (OdfException $e)
369 369
 				{
370 370
 				}
371 371
 
372 372
 				// Make substitutions into odt
373
-				$array_user=$this->get_substitutionarray_user($user,$outputlangs);
374
-				$array_global=$this->get_substitutionarray_each_var_object($object,$outputlangs);
375
-				$array_soc=$this->get_substitutionarray_mysoc($mysoc,$outputlangs);
376
-				$array_thirdparty=$this->get_substitutionarray_thirdparty($socobject,$outputlangs);
377
-				$array_objet=$this->get_substitutionarray_each_var_object($object,$outputlangs);
378
-				$array_other=$this->get_substitutionarray_other($outputlangs);
373
+				$array_user = $this->get_substitutionarray_user($user, $outputlangs);
374
+				$array_global = $this->get_substitutionarray_each_var_object($object, $outputlangs);
375
+				$array_soc = $this->get_substitutionarray_mysoc($mysoc, $outputlangs);
376
+				$array_thirdparty = $this->get_substitutionarray_thirdparty($socobject, $outputlangs);
377
+				$array_objet = $this->get_substitutionarray_each_var_object($object, $outputlangs);
378
+				$array_other = $this->get_substitutionarray_other($outputlangs);
379 379
 		                // retrieve contact information for use in user as contact_xxx tags
380 380
                 		$array_thirdparty_contact = array();
381 381
                 		if ($usecontact)
382
-                    			$array_thirdparty_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact');
382
+                    			$array_thirdparty_contact = $this->get_substitutionarray_contact($contactobject, $outputlangs, 'contact');
383 383
 
384
-				$tmparray = array_merge($array_global,$array_user,$array_soc,$array_thirdparty,$array_objet,$array_other,$array_thirdparty_contact);
384
+				$tmparray = array_merge($array_global, $array_user, $array_soc, $array_thirdparty, $array_objet, $array_other, $array_thirdparty_contact);
385 385
 				complete_substitutions_array($tmparray, $outputlangs, $object);
386 386
 				$object->fetch_optionals();
387 387
 				// Call the ODTSubstitution hook
388
-				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
389
-				$reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
390
-				foreach($tmparray as $key=>$value)
388
+				$parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray);
389
+				$reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
390
+				foreach ($tmparray as $key=>$value)
391 391
 				{
392 392
 					try
393 393
 					{
394
-						if (preg_match('/logo$/',$key)) // Image
394
+						if (preg_match('/logo$/', $key)) // Image
395 395
 						{
396 396
 							if (file_exists($value)) $odfHandler->setImage($key, $value);
397 397
 							else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
 							$odfHandler->setVars($key, $value, true, 'UTF-8');
402 402
 						}
403 403
 					}
404
-					catch(OdfException $e)
404
+					catch (OdfException $e)
405 405
 					{
406 406
 					}
407 407
 				}
@@ -412,7 +412,7 @@  discard block
 block discarded – undo
412 412
 					try {
413 413
 						$listlines = $odfHandler->setSegment('lines');
414 414
 					}
415
-					catch(OdfException $e)
415
+					catch (OdfException $e)
416 416
 					{
417 417
 						// We may arrive here if tags for lines not present into template
418 418
 						$foundtagforlines = 0;
@@ -422,25 +422,25 @@  discard block
 block discarded – undo
422 422
 					{
423 423
 						foreach ($object->members as $u)
424 424
 						{
425
-							$tmparray=$this->get_substitutionarray_each_var_object($u,$outputlangs);
425
+							$tmparray = $this->get_substitutionarray_each_var_object($u, $outputlangs);
426 426
 							unset($tmparray['object_pass']);
427 427
 							unset($tmparray['object_pass_indatabase']);
428 428
 							complete_substitutions_array($tmparray, $outputlangs, $object, $user, "completesubstitutionarray_users");
429 429
 							// Call the ODTSubstitutionLine hook
430
-							$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray,'line'=>$u);
431
-							$reshook=$hookmanager->executeHooks('ODTSubstitutionLine',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
432
-							foreach($tmparray as $key => $val)
430
+							$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray, 'line'=>$u);
431
+							$reshook = $hookmanager->executeHooks('ODTSubstitutionLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
432
+							foreach ($tmparray as $key => $val)
433 433
 							{
434 434
 								try
435 435
 								{
436
-									if(!is_array($val)) {
436
+									if (!is_array($val)) {
437 437
 										$listlines->setVars($key, $val, true, 'UTF-8');
438 438
 									}
439 439
 								}
440
-								catch(OdfException $e)
440
+								catch (OdfException $e)
441 441
 								{
442 442
 								}
443
-								catch(SegmentException $e)
443
+								catch (SegmentException $e)
444 444
 								{
445 445
 								}
446 446
 							}
@@ -449,61 +449,61 @@  discard block
 block discarded – undo
449 449
 						$odfHandler->mergeSegment($listlines);
450 450
 					}
451 451
 				}
452
-				catch(OdfException $e)
452
+				catch (OdfException $e)
453 453
 				{
454
-					$this->error=$e->getMessage();
454
+					$this->error = $e->getMessage();
455 455
 					dol_syslog($this->error, LOG_WARNING);
456 456
 					return -1;
457 457
 				}
458 458
 
459 459
 				// Replace labels translated
460
-				$tmparray=$outputlangs->get_translations_for_substitutions();
461
-				foreach($tmparray as $key=>$value)
460
+				$tmparray = $outputlangs->get_translations_for_substitutions();
461
+				foreach ($tmparray as $key=>$value)
462 462
 				{
463 463
 					try {
464 464
 						$odfHandler->setVars($key, $value, true, 'UTF-8');
465 465
 					}
466
-					catch(OdfException $e)
466
+					catch (OdfException $e)
467 467
 					{
468 468
 					}
469 469
 				}
470 470
 
471 471
 				// Call the beforeODTSave hook
472
-				$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
473
-				$reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
472
+				$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
473
+				$reshook = $hookmanager->executeHooks('beforeODTSave', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
474 474
 
475 475
 				// Write new file
476 476
 				if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
477 477
 					try {
478 478
 						$odfHandler->exportAsAttachedPDF($file);
479
-					}catch (Exception $e){
480
-						$this->error=$e->getMessage();
479
+					} catch (Exception $e) {
480
+						$this->error = $e->getMessage();
481 481
 						return -1;
482 482
 					}
483 483
 				}
484 484
 				else {
485 485
 					try {
486 486
 					$odfHandler->saveToDisk($file);
487
-					}catch (Exception $e){
488
-						$this->error=$e->getMessage();
487
+					} catch (Exception $e) {
488
+						$this->error = $e->getMessage();
489 489
 						return -1;
490 490
 					}
491 491
 				}
492 492
 
493
-				$reshook=$hookmanager->executeHooks('afterODTCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
493
+				$reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
494 494
 
495
-				if (! empty($conf->global->MAIN_UMASK))
495
+				if (!empty($conf->global->MAIN_UMASK))
496 496
 					@chmod($file, octdec($conf->global->MAIN_UMASK));
497 497
 
498
-				$odfHandler=null;	// Destroy object
498
+				$odfHandler = null; // Destroy object
499 499
 
500 500
 				$this->result = array('fullpath'=>$file);
501 501
 
502
-				return 1;   // Success
502
+				return 1; // Success
503 503
 			}
504 504
 			else
505 505
 			{
506
-				$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
506
+				$this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
507 507
 				return -1;
508 508
 			}
509 509
 		}
Please login to merge, or discard this patch.
Braces   +48 added lines, -43 removed lines patch added patch discarded remove patch
@@ -83,7 +83,10 @@  discard block
 block discarded – undo
83 83
 
84 84
 		// Recupere emetteur
85 85
 		$this->emetteur=$mysoc;
86
-		if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default if not defined
86
+		if (! $this->emetteur->country_code) {
87
+			$this->emetteur->country_code=substr($langs->defaultlang,-2);
88
+		}
89
+		// By default if not defined
87 90
 	}
88 91
 
89 92
 
@@ -127,11 +130,14 @@  discard block
 block discarded – undo
127 130
 			if (! $tmpdir) {
128 131
 				unset($listofdir[$key]); continue;
129 132
 			}
130
-			if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
131
-			else
133
+			if (! is_dir($tmpdir)) {
134
+				$texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
135
+			} else
132 136
 			{
133 137
 				$tmpfiles=dol_dir_list($tmpdir,'files',0,'\.(ods|odt)');
134
-				if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles);
138
+				if (count($tmpfiles)) {
139
+					$listoffiles=array_merge($listoffiles,$tmpfiles);
140
+				}
135 141
 			}
136 142
 		}
137 143
 		$texthelp=$langs->trans("ListOfDirectoriesForModelGenODT");
@@ -222,7 +228,9 @@  discard block
 block discarded – undo
222 228
 		$hookmanager->initHooks(array('odtgeneration'));
223 229
 		global $action;
224 230
 
225
-		if (! is_object($outputlangs)) $outputlangs=$langs;
231
+		if (! is_object($outputlangs)) {
232
+			$outputlangs=$langs;
233
+		}
226 234
 		$sav_charset_output=$outputlangs->charset_output;
227 235
 		$outputlangs->charset_output='UTF-8';
228 236
 
@@ -248,7 +256,9 @@  discard block
 block discarded – undo
248 256
 
249 257
 			$dir = $conf->usergroup->dir_output;
250 258
 			$objectref = dol_sanitizeFileName($object->ref);
251
-			if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref;
259
+			if (! preg_match('/specimen/i',$objectref)) {
260
+				$dir.= "/" . $objectref;
261
+			}
252 262
 			$file = $dir . "/" . $objectref . ".odt";
253 263
 
254 264
 			if (! file_exists($dir))
@@ -275,10 +285,11 @@  discard block
 block discarded – undo
275 285
 				if ( ! empty($conf->global->MAIN_DOC_USE_TIMING))
276 286
 				{
277 287
 				    $format=$conf->global->MAIN_DOC_USE_TIMING;
278
-				    if ($format == '1') $format='%Y%m%d%H%M%S';
288
+				    if ($format == '1') {
289
+				    	$format='%Y%m%d%H%M%S';
290
+				    }
279 291
 					$filename=$newfiletmp.'-'.dol_print_date(dol_now(),$format).'.'.$newfileformat;
280
-				}
281
-				else
292
+				} else
282 293
 				{
283 294
 					$filename=$newfiletmp.'.'.$newfileformat;
284 295
 				}
@@ -304,14 +315,14 @@  discard block
 block discarded – undo
304 315
 				if (! empty($usecontact))
305 316
 				{
306 317
 					// On peut utiliser le nom de la societe du contact
307
-					if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact;
308
-					else {
318
+					if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) {
319
+						$socobject = $object->contact;
320
+					} else {
309 321
                         			$socobject = $object->thirdparty;
310 322
                         			// if we have a CUSTOMER contact and we dont use it as recipient we store the contact object for later use
311 323
                         			$contactobject = $object->contact;
312 324
                     			}
313
-				}
314
-				else
325
+				} else
315 326
 				{
316 327
 					$socobject=$object->thirdparty;
317 328
 				}
@@ -348,8 +359,7 @@  discard block
 block discarded – undo
348 359
 						'DELIMITER_RIGHT' => '}'
349 360
 						)
350 361
 					);
351
-				}
352
-				catch(Exception $e)
362
+				} catch(Exception $e)
353 363
 				{
354 364
 					$this->error=$e->getMessage();
355 365
 					return -1;
@@ -364,8 +374,7 @@  discard block
 block discarded – undo
364 374
 				// Make substitutions into odt of freetext
365 375
 				try {
366 376
 					$odfHandler->setVars('free_text', $newfreetext, true, 'UTF-8');
367
-				}
368
-				catch(OdfException $e)
377
+				} catch(OdfException $e)
369 378
 				{
370 379
 				}
371 380
 
@@ -378,8 +387,9 @@  discard block
 block discarded – undo
378 387
 				$array_other=$this->get_substitutionarray_other($outputlangs);
379 388
 		                // retrieve contact information for use in user as contact_xxx tags
380 389
                 		$array_thirdparty_contact = array();
381
-                		if ($usecontact)
382
-                    			$array_thirdparty_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact');
390
+                		if ($usecontact) {
391
+                		                    			$array_thirdparty_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact');
392
+                		}
383 393
 
384 394
 				$tmparray = array_merge($array_global,$array_user,$array_soc,$array_thirdparty,$array_objet,$array_other,$array_thirdparty_contact);
385 395
 				complete_substitutions_array($tmparray, $outputlangs, $object);
@@ -391,17 +401,18 @@  discard block
 block discarded – undo
391 401
 				{
392 402
 					try
393 403
 					{
394
-						if (preg_match('/logo$/',$key)) // Image
404
+						if (preg_match('/logo$/',$key)) {
405
+							// Image
395 406
 						{
396 407
 							if (file_exists($value)) $odfHandler->setImage($key, $value);
397
-							else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
398
-						}
399
-						else    // Text
408
+						} else {
409
+								$odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
410
+							}
411
+						} else    // Text
400 412
 						{
401 413
 							$odfHandler->setVars($key, $value, true, 'UTF-8');
402 414
 						}
403
-					}
404
-					catch(OdfException $e)
415
+					} catch(OdfException $e)
405 416
 					{
406 417
 					}
407 418
 				}
@@ -411,8 +422,7 @@  discard block
 block discarded – undo
411 422
 					$foundtagforlines = 1;
412 423
 					try {
413 424
 						$listlines = $odfHandler->setSegment('lines');
414
-					}
415
-					catch(OdfException $e)
425
+					} catch(OdfException $e)
416 426
 					{
417 427
 						// We may arrive here if tags for lines not present into template
418 428
 						$foundtagforlines = 0;
@@ -436,11 +446,9 @@  discard block
 block discarded – undo
436 446
 									if(!is_array($val)) {
437 447
 										$listlines->setVars($key, $val, true, 'UTF-8');
438 448
 									}
439
-								}
440
-								catch(OdfException $e)
449
+								} catch(OdfException $e)
441 450
 								{
442
-								}
443
-								catch(SegmentException $e)
451
+								} catch(SegmentException $e)
444 452
 								{
445 453
 								}
446 454
 							}
@@ -448,8 +456,7 @@  discard block
 block discarded – undo
448 456
 						}
449 457
 						$odfHandler->mergeSegment($listlines);
450 458
 					}
451
-				}
452
-				catch(OdfException $e)
459
+				} catch(OdfException $e)
453 460
 				{
454 461
 					$this->error=$e->getMessage();
455 462
 					dol_syslog($this->error, LOG_WARNING);
@@ -462,8 +469,7 @@  discard block
 block discarded – undo
462 469
 				{
463 470
 					try {
464 471
 						$odfHandler->setVars($key, $value, true, 'UTF-8');
465
-					}
466
-					catch(OdfException $e)
472
+					} catch(OdfException $e)
467 473
 					{
468 474
 					}
469 475
 				}
@@ -476,15 +482,14 @@  discard block
 block discarded – undo
476 482
 				if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
477 483
 					try {
478 484
 						$odfHandler->exportAsAttachedPDF($file);
479
-					}catch (Exception $e){
485
+					} catch (Exception $e){
480 486
 						$this->error=$e->getMessage();
481 487
 						return -1;
482 488
 					}
483
-				}
484
-				else {
489
+				} else {
485 490
 					try {
486 491
 					$odfHandler->saveToDisk($file);
487
-					}catch (Exception $e){
492
+					} catch (Exception $e){
488 493
 						$this->error=$e->getMessage();
489 494
 						return -1;
490 495
 					}
@@ -492,16 +497,16 @@  discard block
 block discarded – undo
492 497
 
493 498
 				$reshook=$hookmanager->executeHooks('afterODTCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
494 499
 
495
-				if (! empty($conf->global->MAIN_UMASK))
496
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
500
+				if (! empty($conf->global->MAIN_UMASK)) {
501
+									@chmod($file, octdec($conf->global->MAIN_UMASK));
502
+				}
497 503
 
498 504
 				$odfHandler=null;	// Destroy object
499 505
 
500 506
 				$this->result = array('fullpath'=>$file);
501 507
 
502 508
 				return 1;   // Success
503
-			}
504
-			else
509
+			} else
505 510
 			{
506 511
 				$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
507 512
 				return -1;
Please login to merge, or discard this patch.
htdocs/core/modules/expedition/doc/doc_generic_shipment_odt.modules.php 2 patches
Spacing   +153 added lines, -153 removed lines patch added patch discarded remove patch
@@ -39,9 +39,9 @@  discard block
 block discarded – undo
39 39
  */
40 40
 class doc_generic_shipment_odt extends ModelePdfExpedition
41 41
 {
42
-	var $emetteur;	// Objet societe qui emet
42
+	var $emetteur; // Objet societe qui emet
43 43
 
44
-	var $phpmin = array(5,2,0);	// Minimum version of PHP required by module
44
+	var $phpmin = array(5, 2, 0); // Minimum version of PHP required by module
45 45
 	var $version = 'dolibarr';
46 46
 
47 47
 
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 	 */
53 53
 	function __construct($db)
54 54
 	{
55
-		global $conf,$langs,$mysoc;
55
+		global $conf, $langs, $mysoc;
56 56
 
57 57
 		$langs->load("main");
58 58
 		$langs->load("companies");
@@ -60,32 +60,32 @@  discard block
 block discarded – undo
60 60
 		$this->db = $db;
61 61
 		$this->name = "ODT templates";
62 62
 		$this->description = $langs->trans("DocumentModelOdt");
63
-		$this->scandir = 'EXPEDITION_ADDON_PDF_ODT_PATH';	// Name of constant that is used to save list of directories to scan
63
+		$this->scandir = 'EXPEDITION_ADDON_PDF_ODT_PATH'; // Name of constant that is used to save list of directories to scan
64 64
 
65 65
 		// Dimension page pour format A4
66 66
 		$this->type = 'odt';
67 67
 		$this->page_largeur = 0;
68 68
 		$this->page_hauteur = 0;
69
-		$this->format = array($this->page_largeur,$this->page_hauteur);
70
-		$this->marge_gauche=0;
71
-		$this->marge_droite=0;
72
-		$this->marge_haute=0;
73
-		$this->marge_basse=0;
74
-
75
-		$this->option_logo = 1;                    // Affiche logo
76
-		$this->option_tva = 0;                     // Gere option tva EXPEDITION_TVAOPTION
77
-		$this->option_modereg = 0;                 // Affiche mode reglement
78
-		$this->option_condreg = 0;                 // Affiche conditions reglement
79
-		$this->option_codeproduitservice = 0;      // Affiche code produit-service
80
-		$this->option_multilang = 1;               // Dispo en plusieurs langues
81
-		$this->option_escompte = 0;                // Affiche si il y a eu escompte
82
-		$this->option_credit_note = 0;             // Support credit notes
83
-		$this->option_freetext = 1;				   // Support add of a personalised text
84
-		$this->option_draft_watermark = 0;		   // Support add of a watermark on drafts
69
+		$this->format = array($this->page_largeur, $this->page_hauteur);
70
+		$this->marge_gauche = 0;
71
+		$this->marge_droite = 0;
72
+		$this->marge_haute = 0;
73
+		$this->marge_basse = 0;
74
+
75
+		$this->option_logo = 1; // Affiche logo
76
+		$this->option_tva = 0; // Gere option tva EXPEDITION_TVAOPTION
77
+		$this->option_modereg = 0; // Affiche mode reglement
78
+		$this->option_condreg = 0; // Affiche conditions reglement
79
+		$this->option_codeproduitservice = 0; // Affiche code produit-service
80
+		$this->option_multilang = 1; // Dispo en plusieurs langues
81
+		$this->option_escompte = 0; // Affiche si il y a eu escompte
82
+		$this->option_credit_note = 0; // Support credit notes
83
+		$this->option_freetext = 1; // Support add of a personalised text
84
+		$this->option_draft_watermark = 0; // Support add of a watermark on drafts
85 85
 
86 86
 		// Recupere emetteur
87
-		$this->emetteur=$mysoc;
88
-		if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default if not defined
87
+		$this->emetteur = $mysoc;
88
+		if (!$this->emetteur->country_code) $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined
89 89
 	}
90 90
 
91 91
 
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 	 */
98 98
 	function info($langs)
99 99
 	{
100
-		global $conf,$langs;
100
+		global $conf, $langs;
101 101
 
102 102
 		$langs->load("companies");
103 103
 		$langs->load("errors");
@@ -105,74 +105,74 @@  discard block
 block discarded – undo
105 105
 		$form = new Form($this->db);
106 106
 
107 107
 		$texte = $this->description.".<br>\n";
108
-		$texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
109
-		$texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
110
-		$texte.= '<input type="hidden" name="action" value="setModuleOptions">';
111
-		$texte.= '<input type="hidden" name="param1" value="EXPEDITION_ADDON_PDF_ODT_PATH">';
112
-		$texte.= '<table class="nobordernopadding" width="100%">';
108
+		$texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
109
+		$texte .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
110
+		$texte .= '<input type="hidden" name="action" value="setModuleOptions">';
111
+		$texte .= '<input type="hidden" name="param1" value="EXPEDITION_ADDON_PDF_ODT_PATH">';
112
+		$texte .= '<table class="nobordernopadding" width="100%">';
113 113
 
114 114
 		// List of directories area
115
-		$texte.= '<tr><td>';
116
-		$texttitle=$langs->trans("ListOfDirectories");
117
-		$listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->EXPEDITION_ADDON_PDF_ODT_PATH)));
118
-		$listoffiles=array();
119
-		foreach($listofdir as $key=>$tmpdir)
115
+		$texte .= '<tr><td>';
116
+		$texttitle = $langs->trans("ListOfDirectories");
117
+		$listofdir = explode(',', preg_replace('/[\r\n]+/', ',', trim($conf->global->EXPEDITION_ADDON_PDF_ODT_PATH)));
118
+		$listoffiles = array();
119
+		foreach ($listofdir as $key=>$tmpdir)
120 120
 		{
121
-			$tmpdir=trim($tmpdir);
122
-			$tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir);
123
-			if (! $tmpdir) {
121
+			$tmpdir = trim($tmpdir);
122
+			$tmpdir = preg_replace('/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
123
+			if (!$tmpdir) {
124 124
 				unset($listofdir[$key]); continue;
125 125
 			}
126
-			if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
126
+			if (!is_dir($tmpdir)) $texttitle .= img_warning($langs->trans("ErrorDirNotFound", $tmpdir), 0);
127 127
 			else
128 128
 			{
129
-				$tmpfiles=dol_dir_list($tmpdir,'files',0,'\.(ods|odt)');
130
-				if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles);
129
+				$tmpfiles = dol_dir_list($tmpdir, 'files', 0, '\.(ods|odt)');
130
+				if (count($tmpfiles)) $listoffiles = array_merge($listoffiles, $tmpfiles);
131 131
 			}
132 132
 		}
133
-		$texthelp=$langs->trans("ListOfDirectoriesForModelGenODT");
133
+		$texthelp = $langs->trans("ListOfDirectoriesForModelGenODT");
134 134
 		// Add list of substitution keys
135
-		$texthelp.='<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>';
136
-		$texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation");    // This contains an url, we don't modify it
137
-
138
-		$texte.= $form->textwithpicto($texttitle,$texthelp,1,'help','',1);
139
-		$texte.= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
140
-		$texte.= '<textarea class="flat" cols="60" name="value1">';
141
-		$texte.=$conf->global->EXPEDITION_ADDON_PDF_ODT_PATH;
142
-		$texte.= '</textarea>';
143
-		$texte.= '</div><div style="display: inline-block; vertical-align: middle;">';
144
-		$texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">';
145
-		$texte.= '<br></div></div>';
135
+		$texthelp .= '<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>';
136
+		$texthelp .= $langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it
137
+
138
+		$texte .= $form->textwithpicto($texttitle, $texthelp, 1, 'help', '', 1);
139
+		$texte .= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
140
+		$texte .= '<textarea class="flat" cols="60" name="value1">';
141
+		$texte .= $conf->global->EXPEDITION_ADDON_PDF_ODT_PATH;
142
+		$texte .= '</textarea>';
143
+		$texte .= '</div><div style="display: inline-block; vertical-align: middle;">';
144
+		$texte .= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">';
145
+		$texte .= '<br></div></div>';
146 146
 
147 147
 		// Scan directories
148
-		$nbofiles=count($listoffiles);
149
-		if (! empty($conf->global->EXPEDITION_ADDON_PDF_ODT_PATH))
148
+		$nbofiles = count($listoffiles);
149
+		if (!empty($conf->global->EXPEDITION_ADDON_PDF_ODT_PATH))
150 150
 		{
151
-			$texte.=$langs->trans("NumberOfModelFilesFound").': <b>';
151
+			$texte .= $langs->trans("NumberOfModelFilesFound").': <b>';
152 152
 			//$texte.=$nbofiles?'<a id="a_'.get_class($this).'" href="#">':'';
153
-			$texte.=count($listoffiles);
153
+			$texte .= count($listoffiles);
154 154
 			//$texte.=$nbofiles?'</a>':'';
155
-			$texte.='</b>';
155
+			$texte .= '</b>';
156 156
 		}
157 157
 		if ($nbofiles)
158 158
 		{
159
-   			$texte.='<div id="div_'.get_class($this).'" class="hidden">';
160
-   			foreach($listoffiles as $file)
159
+   			$texte .= '<div id="div_'.get_class($this).'" class="hidden">';
160
+   			foreach ($listoffiles as $file)
161 161
    			{
162
-                $texte.=$file['name'].'<br>';
162
+                $texte .= $file['name'].'<br>';
163 163
    			}
164
-   			$texte.='<div id="div_'.get_class($this).'">';
164
+   			$texte .= '<div id="div_'.get_class($this).'">';
165 165
 		}
166 166
 
167
-		$texte.= '</td>';
167
+		$texte .= '</td>';
168 168
 
169
-		$texte.= '<td valign="top" rowspan="2" class="hideonsmartphone">';
170
-		$texte.= $langs->trans("ExampleOfDirectoriesForModelGen");
171
-		$texte.= '</td>';
172
-		$texte.= '</tr>';
169
+		$texte .= '<td valign="top" rowspan="2" class="hideonsmartphone">';
170
+		$texte .= $langs->trans("ExampleOfDirectoriesForModelGen");
171
+		$texte .= '</td>';
172
+		$texte .= '</tr>';
173 173
 
174
-		$texte.= '</table>';
175
-		$texte.= '</form>';
174
+		$texte .= '</table>';
175
+		$texte .= '</form>';
176 176
 
177 177
 		return $texte;
178 178
 	}
@@ -188,9 +188,9 @@  discard block
 block discarded – undo
188 188
 	 *  @param		int			$hideref			Do not show ref
189 189
 	 *	@return		int         					1 if OK, <=0 if KO
190 190
 	 */
191
-	function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0)
191
+	function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
192 192
 	{
193
-		global $user,$langs,$conf,$mysoc,$hookmanager;
193
+		global $user, $langs, $conf, $mysoc, $hookmanager;
194 194
 
195 195
 		if (empty($srctemplatepath))
196 196
 		{
@@ -199,17 +199,17 @@  discard block
 block discarded – undo
199 199
 		}
200 200
 
201 201
 		// Add odtgeneration hook
202
-		if (! is_object($hookmanager))
202
+		if (!is_object($hookmanager))
203 203
 		{
204 204
 			include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
205
-			$hookmanager=new HookManager($this->db);
205
+			$hookmanager = new HookManager($this->db);
206 206
 		}
207 207
 		$hookmanager->initHooks(array('odtgeneration'));
208 208
 		global $action;
209 209
 
210
-		if (! is_object($outputlangs)) $outputlangs=$langs;
211
-		$sav_charset_output=$outputlangs->charset_output;
212
-		$outputlangs->charset_output='UTF-8';
210
+		if (!is_object($outputlangs)) $outputlangs = $langs;
211
+		$sav_charset_output = $outputlangs->charset_output;
212
+		$outputlangs->charset_output = 'UTF-8';
213 213
 
214 214
 		$outputlangs->load("main");
215 215
 		$outputlangs->load("dict");
@@ -219,28 +219,28 @@  discard block
 block discarded – undo
219 219
 		if ($conf->expedition->dir_output."/sending")
220 220
 		{
221 221
 			// If $object is id instead of object
222
-			if (! is_object($object))
222
+			if (!is_object($object))
223 223
 			{
224 224
 				$id = $object;
225 225
 				$object = new Expedition($this->db);
226
-				$result=$object->fetch($id);
226
+				$result = $object->fetch($id);
227 227
 				if ($result < 0)
228 228
 				{
229
-					dol_print_error($this->db,$object->error);
229
+					dol_print_error($this->db, $object->error);
230 230
 					return -1;
231 231
 				}
232 232
 			}
233 233
 
234 234
 			$dir = $conf->expedition->dir_output."/sending";
235 235
 			$objectref = dol_sanitizeFileName($object->ref);
236
-			if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref;
237
-			$file = $dir . "/" . $objectref . ".odt";
236
+			if (!preg_match('/specimen/i', $objectref)) $dir .= "/".$objectref;
237
+			$file = $dir."/".$objectref.".odt";
238 238
 
239
-			if (! file_exists($dir))
239
+			if (!file_exists($dir))
240 240
 			{
241 241
 				if (dol_mkdir($dir) < 0)
242 242
 				{
243
-					$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
243
+					$this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
244 244
 					return -1;
245 245
 				}
246 246
 			}
@@ -248,25 +248,25 @@  discard block
 block discarded – undo
248 248
 			if (file_exists($dir))
249 249
 			{
250 250
 				//print "srctemplatepath=".$srctemplatepath;	// Src filename
251
-				$newfile=basename($srctemplatepath);
252
-				$newfiletmp=preg_replace('/\.od(t|s)/i','',$newfile);
253
-				$newfiletmp=preg_replace('/template_/i','',$newfiletmp);
254
-				$newfiletmp=preg_replace('/modele_/i','',$newfiletmp);
255
-				$newfiletmp=$objectref.'_'.$newfiletmp;
251
+				$newfile = basename($srctemplatepath);
252
+				$newfiletmp = preg_replace('/\.od(t|s)/i', '', $newfile);
253
+				$newfiletmp = preg_replace('/template_/i', '', $newfiletmp);
254
+				$newfiletmp = preg_replace('/modele_/i', '', $newfiletmp);
255
+				$newfiletmp = $objectref.'_'.$newfiletmp;
256 256
 				//$file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now(),'%Y%m%d%H%M%S').'.odt';
257 257
 				// Get extension (ods or odt)
258
-				$newfileformat=substr($newfile, strrpos($newfile, '.')+1);
259
-				if ( ! empty($conf->global->MAIN_DOC_USE_TIMING))
258
+				$newfileformat = substr($newfile, strrpos($newfile, '.') + 1);
259
+				if (!empty($conf->global->MAIN_DOC_USE_TIMING))
260 260
 				{
261
-				    $format=$conf->global->MAIN_DOC_USE_TIMING;
262
-				    if ($format == '1') $format='%Y%m%d%H%M%S';
263
-					$filename=$newfiletmp.'-'.dol_print_date(dol_now(),$format).'.'.$newfileformat;
261
+				    $format = $conf->global->MAIN_DOC_USE_TIMING;
262
+				    if ($format == '1') $format = '%Y%m%d%H%M%S';
263
+					$filename = $newfiletmp.'-'.dol_print_date(dol_now(), $format).'.'.$newfileformat;
264 264
 				}
265 265
 				else
266 266
 				{
267
-					$filename=$newfiletmp.'.'.$newfileformat;
267
+					$filename = $newfiletmp.'.'.$newfileformat;
268 268
 				}
269
-				$file=$dir.'/'.$filename;
269
+				$file = $dir.'/'.$filename;
270 270
 				//print "newdir=".$dir;
271 271
 				//print "newfile=".$newfile;
272 272
 				//print "file=".$file;
@@ -276,28 +276,28 @@  discard block
 block discarded – undo
276 276
 
277 277
 
278 278
 				// If BILLING contact defined on invoice, we use it
279
-				$usecontact=false;
280
-				$arrayidcontact=$object->getIdContact('external','BILLING');
279
+				$usecontact = false;
280
+				$arrayidcontact = $object->getIdContact('external', 'BILLING');
281 281
 				if (count($arrayidcontact) > 0)
282 282
 				{
283
-					$usecontact=true;
284
-					$result=$object->fetch_contact($arrayidcontact[0]);
283
+					$usecontact = true;
284
+					$result = $object->fetch_contact($arrayidcontact[0]);
285 285
 				}
286 286
 
287 287
 				// Recipient name
288
-				if (! empty($usecontact))
288
+				if (!empty($usecontact))
289 289
 				{
290 290
 					// On peut utiliser le nom de la societe du contact
291
-					if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact;
291
+					if (!empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact;
292 292
 					else $socobject = $object->thirdparty;
293 293
 				}
294 294
 				else
295 295
 				{
296
-					$socobject=$object->thirdparty;
296
+					$socobject = $object->thirdparty;
297 297
 				}
298 298
 
299 299
 				// Make substitution
300
-				$substitutionarray=array(
300
+				$substitutionarray = array(
301 301
 				'__FROM_NAME__' => $this->emetteur->name,
302 302
 				'__FROM_EMAIL__' => $this->emetteur->email,
303 303
 				'__TOTAL_TTC__' => $object->total_ttc,
@@ -306,15 +306,15 @@  discard block
 block discarded – undo
306 306
 				);
307 307
 				complete_substitutions_array($substitutionarray, $langs, $object);
308 308
 				// Call the ODTSubstitution hook
309
-				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$substitutionarray);
310
-				$reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
309
+				$parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$substitutionarray);
310
+				$reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
311 311
 
312 312
 				// Line of free text
313
-				$newfreetext='';
314
-				$paramfreetext='EXPEDITION_FREE_TEXT';
315
-				if (! empty($conf->global->$paramfreetext))
313
+				$newfreetext = '';
314
+				$paramfreetext = 'EXPEDITION_FREE_TEXT';
315
+				if (!empty($conf->global->$paramfreetext))
316 316
 				{
317
-					$newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray);
317
+					$newfreetext = make_substitutions($conf->global->$paramfreetext, $substitutionarray);
318 318
 				}
319 319
 
320 320
 				// Open and load template
@@ -324,15 +324,15 @@  discard block
 block discarded – undo
324 324
 						$srctemplatepath,
325 325
 						array(
326 326
 						'PATH_TO_TMP'	  => $conf->expedition->dir_temp,
327
-						'ZIP_PROXY'		  => 'PclZipProxy',	// PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy.
327
+						'ZIP_PROXY'		  => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy.
328 328
 						'DELIMITER_LEFT'  => '{',
329 329
 						'DELIMITER_RIGHT' => '}'
330 330
 						)
331 331
 					);
332 332
 				}
333
-				catch(Exception $e)
333
+				catch (Exception $e)
334 334
 				{
335
-					$this->error=$e->getMessage();
335
+					$this->error = $e->getMessage();
336 336
 					return -1;
337 337
 				}
338 338
 				// After construction $odfHandler->contentXml contains content and
@@ -346,17 +346,17 @@  discard block
 block discarded – undo
346 346
 				try {
347 347
 					$odfHandler->setVars('free_text', $newfreetext, true, 'UTF-8');
348 348
 				}
349
-				catch(OdfException $e)
349
+				catch (OdfException $e)
350 350
 				{
351 351
 				}
352 352
 
353 353
 				// Make substitutions into odt of user info
354
-				$tmparray=$this->get_substitutionarray_user($user,$outputlangs);
354
+				$tmparray = $this->get_substitutionarray_user($user, $outputlangs);
355 355
 				//var_dump($tmparray); exit;
356
-				foreach($tmparray as $key=>$value)
356
+				foreach ($tmparray as $key=>$value)
357 357
 				{
358 358
 					try {
359
-						if (preg_match('/logo$/',$key)) // Image
359
+						if (preg_match('/logo$/', $key)) // Image
360 360
 						{
361 361
 							//var_dump($value);exit;
362 362
 							if (file_exists($value)) $odfHandler->setImage($key, $value);
@@ -367,17 +367,17 @@  discard block
 block discarded – undo
367 367
 							$odfHandler->setVars($key, $value, true, 'UTF-8');
368 368
 						}
369 369
 					}
370
-					catch(OdfException $e)
370
+					catch (OdfException $e)
371 371
 					{
372 372
 					}
373 373
 				}
374 374
 				// Make substitutions into odt of mysoc
375
-				$tmparray=$this->get_substitutionarray_mysoc($mysoc,$outputlangs);
375
+				$tmparray = $this->get_substitutionarray_mysoc($mysoc, $outputlangs);
376 376
 				//var_dump($tmparray); exit;
377
-				foreach($tmparray as $key=>$value)
377
+				foreach ($tmparray as $key=>$value)
378 378
 				{
379 379
 					try {
380
-						if (preg_match('/logo$/',$key))	// Image
380
+						if (preg_match('/logo$/', $key))	// Image
381 381
 						{
382 382
 							//var_dump($value);exit;
383 383
 							if (file_exists($value)) $odfHandler->setImage($key, $value);
@@ -388,16 +388,16 @@  discard block
 block discarded – undo
388 388
 							$odfHandler->setVars($key, $value, true, 'UTF-8');
389 389
 						}
390 390
 					}
391
-					catch(OdfException $e)
391
+					catch (OdfException $e)
392 392
 					{
393 393
 					}
394 394
 				}
395 395
 				// Make substitutions into odt of thirdparty
396
-				$tmparray=$this->get_substitutionarray_thirdparty($socobject,$outputlangs);
397
-				foreach($tmparray as $key=>$value)
396
+				$tmparray = $this->get_substitutionarray_thirdparty($socobject, $outputlangs);
397
+				foreach ($tmparray as $key=>$value)
398 398
 				{
399 399
 					try {
400
-						if (preg_match('/logo$/',$key))	// Image
400
+						if (preg_match('/logo$/', $key))	// Image
401 401
 						{
402 402
 							if (file_exists($value)) $odfHandler->setImage($key, $value);
403 403
 							else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
@@ -407,20 +407,20 @@  discard block
 block discarded – undo
407 407
 							$odfHandler->setVars($key, $value, true, 'UTF-8');
408 408
 						}
409 409
 					}
410
-					catch(OdfException $e)
410
+					catch (OdfException $e)
411 411
 					{
412 412
 					}
413 413
 				}
414 414
 				// Replace tags of object + external modules
415
-				$tmparray=$this->get_substitutionarray_shipment($object,$outputlangs);
415
+				$tmparray = $this->get_substitutionarray_shipment($object, $outputlangs);
416 416
 				complete_substitutions_array($tmparray, $outputlangs, $object);
417 417
 				// Call the ODTSubstitution hook
418
-				$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
419
-				$reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
420
-				foreach($tmparray as $key=>$value)
418
+				$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray);
419
+				$reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
420
+				foreach ($tmparray as $key=>$value)
421 421
 				{
422 422
 					try {
423
-						if (preg_match('/logo$/',$key)) // Image
423
+						if (preg_match('/logo$/', $key)) // Image
424 424
 						{
425 425
 							if (file_exists($value)) $odfHandler->setImage($key, $value);
426 426
 							else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
@@ -430,7 +430,7 @@  discard block
 block discarded – undo
430 430
 							$odfHandler->setVars($key, $value, true, 'UTF-8');
431 431
 						}
432 432
 					}
433
-					catch(OdfException $e)
433
+					catch (OdfException $e)
434 434
 					{
435 435
 					}
436 436
 				}
@@ -441,7 +441,7 @@  discard block
 block discarded – undo
441 441
 					try {
442 442
 						$listlines = $odfHandler->setSegment('lines');
443 443
 					}
444
-					catch(OdfException $e)
444
+					catch (OdfException $e)
445 445
 					{
446 446
 						// We may arrive here if tags for lines not present into template
447 447
 						$foundtagforlines = 0;
@@ -451,21 +451,21 @@  discard block
 block discarded – undo
451 451
 					{
452 452
 						foreach ($object->lines as $line)
453 453
 						{
454
-							$tmparray=$this->get_substitutionarray_shipment_lines($line,$outputlangs);
454
+							$tmparray = $this->get_substitutionarray_shipment_lines($line, $outputlangs);
455 455
 							complete_substitutions_array($tmparray, $outputlangs, $object, $line, "completesubstitutionarray_lines");
456 456
 							// Call the ODTSubstitutionLine hook
457
-							$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray,'line'=>$line);
458
-							$reshook=$hookmanager->executeHooks('ODTSubstitutionLine',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
459
-							foreach($tmparray as $key => $val)
457
+							$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray, 'line'=>$line);
458
+							$reshook = $hookmanager->executeHooks('ODTSubstitutionLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
459
+							foreach ($tmparray as $key => $val)
460 460
 							{
461 461
 								try
462 462
 								{
463 463
 									$listlines->setVars($key, $val, true, 'UTF-8');
464 464
 								}
465
-								catch(OdfException $e)
465
+								catch (OdfException $e)
466 466
 								{
467 467
 								}
468
-								catch(SegmentException $e)
468
+								catch (SegmentException $e)
469 469
 								{
470 470
 								}
471 471
 							}
@@ -474,61 +474,61 @@  discard block
 block discarded – undo
474 474
 						$odfHandler->mergeSegment($listlines);
475 475
 					}
476 476
 				}
477
-				catch(OdfException $e)
477
+				catch (OdfException $e)
478 478
 				{
479
-					$this->error=$e->getMessage();
479
+					$this->error = $e->getMessage();
480 480
 					dol_syslog($this->error, LOG_WARNING);
481 481
 					return -1;
482 482
 				}
483 483
 
484 484
 				// Replace labels translated
485
-				$tmparray=$outputlangs->get_translations_for_substitutions();
486
-				foreach($tmparray as $key=>$value)
485
+				$tmparray = $outputlangs->get_translations_for_substitutions();
486
+				foreach ($tmparray as $key=>$value)
487 487
 				{
488 488
 					try {
489 489
 						$odfHandler->setVars($key, $value, true, 'UTF-8');
490 490
 					}
491
-					catch(OdfException $e)
491
+					catch (OdfException $e)
492 492
 					{
493 493
 					}
494 494
 				}
495 495
 
496 496
 				// Call the beforeODTSave hook
497
-				$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
498
-				$reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
497
+				$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray);
498
+				$reshook = $hookmanager->executeHooks('beforeODTSave', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
499 499
 
500 500
 				// Write new file
501 501
 				if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
502 502
 					try {
503 503
 						$odfHandler->exportAsAttachedPDF($file);
504
-					}catch (Exception $e){
505
-						$this->error=$e->getMessage();
504
+					} catch (Exception $e) {
505
+						$this->error = $e->getMessage();
506 506
 						return -1;
507 507
 					}
508 508
 				}
509 509
 				else {
510 510
 					try {
511 511
 					$odfHandler->saveToDisk($file);
512
-					}catch (Exception $e){
513
-						$this->error=$e->getMessage();
512
+					} catch (Exception $e) {
513
+						$this->error = $e->getMessage();
514 514
 						return -1;
515 515
 					}
516 516
 				}
517
-				$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
518
-				$reshook=$hookmanager->executeHooks('afterODTCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
517
+				$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray);
518
+				$reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
519 519
 
520
-				if (! empty($conf->global->MAIN_UMASK))
520
+				if (!empty($conf->global->MAIN_UMASK))
521 521
 					@chmod($file, octdec($conf->global->MAIN_UMASK));
522 522
 
523
-				$odfHandler=null;	// Destroy object
523
+				$odfHandler = null; // Destroy object
524 524
 
525 525
 				$this->result = array('fullpath'=>$file);
526 526
 
527
-				return 1;   // Success
527
+				return 1; // Success
528 528
 			}
529 529
 			else
530 530
 			{
531
-				$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
531
+				$this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
532 532
 				return -1;
533 533
 			}
534 534
 		}
Please login to merge, or discard this patch.
Braces   +68 added lines, -59 removed lines patch added patch discarded remove patch
@@ -85,7 +85,10 @@  discard block
 block discarded – undo
85 85
 
86 86
 		// Recupere emetteur
87 87
 		$this->emetteur=$mysoc;
88
-		if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default if not defined
88
+		if (! $this->emetteur->country_code) {
89
+			$this->emetteur->country_code=substr($langs->defaultlang,-2);
90
+		}
91
+		// By default if not defined
89 92
 	}
90 93
 
91 94
 
@@ -123,11 +126,14 @@  discard block
 block discarded – undo
123 126
 			if (! $tmpdir) {
124 127
 				unset($listofdir[$key]); continue;
125 128
 			}
126
-			if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
127
-			else
129
+			if (! is_dir($tmpdir)) {
130
+				$texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
131
+			} else
128 132
 			{
129 133
 				$tmpfiles=dol_dir_list($tmpdir,'files',0,'\.(ods|odt)');
130
-				if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles);
134
+				if (count($tmpfiles)) {
135
+					$listoffiles=array_merge($listoffiles,$tmpfiles);
136
+				}
131 137
 			}
132 138
 		}
133 139
 		$texthelp=$langs->trans("ListOfDirectoriesForModelGenODT");
@@ -207,7 +213,9 @@  discard block
 block discarded – undo
207 213
 		$hookmanager->initHooks(array('odtgeneration'));
208 214
 		global $action;
209 215
 
210
-		if (! is_object($outputlangs)) $outputlangs=$langs;
216
+		if (! is_object($outputlangs)) {
217
+			$outputlangs=$langs;
218
+		}
211 219
 		$sav_charset_output=$outputlangs->charset_output;
212 220
 		$outputlangs->charset_output='UTF-8';
213 221
 
@@ -233,7 +241,9 @@  discard block
 block discarded – undo
233 241
 
234 242
 			$dir = $conf->expedition->dir_output."/sending";
235 243
 			$objectref = dol_sanitizeFileName($object->ref);
236
-			if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref;
244
+			if (! preg_match('/specimen/i',$objectref)) {
245
+				$dir.= "/" . $objectref;
246
+			}
237 247
 			$file = $dir . "/" . $objectref . ".odt";
238 248
 
239 249
 			if (! file_exists($dir))
@@ -259,10 +269,11 @@  discard block
 block discarded – undo
259 269
 				if ( ! empty($conf->global->MAIN_DOC_USE_TIMING))
260 270
 				{
261 271
 				    $format=$conf->global->MAIN_DOC_USE_TIMING;
262
-				    if ($format == '1') $format='%Y%m%d%H%M%S';
272
+				    if ($format == '1') {
273
+				    	$format='%Y%m%d%H%M%S';
274
+				    }
263 275
 					$filename=$newfiletmp.'-'.dol_print_date(dol_now(),$format).'.'.$newfileformat;
264
-				}
265
-				else
276
+				} else
266 277
 				{
267 278
 					$filename=$newfiletmp.'.'.$newfileformat;
268 279
 				}
@@ -288,10 +299,12 @@  discard block
 block discarded – undo
288 299
 				if (! empty($usecontact))
289 300
 				{
290 301
 					// On peut utiliser le nom de la societe du contact
291
-					if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact;
292
-					else $socobject = $object->thirdparty;
293
-				}
294
-				else
302
+					if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) {
303
+						$socobject = $object->contact;
304
+					} else {
305
+						$socobject = $object->thirdparty;
306
+					}
307
+				} else
295 308
 				{
296 309
 					$socobject=$object->thirdparty;
297 310
 				}
@@ -329,8 +342,7 @@  discard block
 block discarded – undo
329 342
 						'DELIMITER_RIGHT' => '}'
330 343
 						)
331 344
 					);
332
-				}
333
-				catch(Exception $e)
345
+				} catch(Exception $e)
334 346
 				{
335 347
 					$this->error=$e->getMessage();
336 348
 					return -1;
@@ -345,8 +357,7 @@  discard block
 block discarded – undo
345 357
 				// Make substitutions into odt of freetext
346 358
 				try {
347 359
 					$odfHandler->setVars('free_text', $newfreetext, true, 'UTF-8');
348
-				}
349
-				catch(OdfException $e)
360
+				} catch(OdfException $e)
350 361
 				{
351 362
 				}
352 363
 
@@ -356,18 +367,19 @@  discard block
 block discarded – undo
356 367
 				foreach($tmparray as $key=>$value)
357 368
 				{
358 369
 					try {
359
-						if (preg_match('/logo$/',$key)) // Image
370
+						if (preg_match('/logo$/',$key)) {
371
+							// Image
360 372
 						{
361 373
 							//var_dump($value);exit;
362 374
 							if (file_exists($value)) $odfHandler->setImage($key, $value);
363
-							else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
364
-						}
365
-						else    // Text
375
+						} else {
376
+								$odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
377
+							}
378
+						} else    // Text
366 379
 						{
367 380
 							$odfHandler->setVars($key, $value, true, 'UTF-8');
368 381
 						}
369
-					}
370
-					catch(OdfException $e)
382
+					} catch(OdfException $e)
371 383
 					{
372 384
 					}
373 385
 				}
@@ -377,18 +389,19 @@  discard block
 block discarded – undo
377 389
 				foreach($tmparray as $key=>$value)
378 390
 				{
379 391
 					try {
380
-						if (preg_match('/logo$/',$key))	// Image
392
+						if (preg_match('/logo$/',$key)) {
393
+							// Image
381 394
 						{
382 395
 							//var_dump($value);exit;
383 396
 							if (file_exists($value)) $odfHandler->setImage($key, $value);
384
-							else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
385
-						}
386
-						else	// Text
397
+						} else {
398
+								$odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
399
+							}
400
+						} else	// Text
387 401
 						{
388 402
 							$odfHandler->setVars($key, $value, true, 'UTF-8');
389 403
 						}
390
-					}
391
-					catch(OdfException $e)
404
+					} catch(OdfException $e)
392 405
 					{
393 406
 					}
394 407
 				}
@@ -397,17 +410,18 @@  discard block
 block discarded – undo
397 410
 				foreach($tmparray as $key=>$value)
398 411
 				{
399 412
 					try {
400
-						if (preg_match('/logo$/',$key))	// Image
413
+						if (preg_match('/logo$/',$key)) {
414
+							// Image
401 415
 						{
402 416
 							if (file_exists($value)) $odfHandler->setImage($key, $value);
403
-							else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
404
-						}
405
-						else	// Text
417
+						} else {
418
+								$odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
419
+							}
420
+						} else	// Text
406 421
 						{
407 422
 							$odfHandler->setVars($key, $value, true, 'UTF-8');
408 423
 						}
409
-					}
410
-					catch(OdfException $e)
424
+					} catch(OdfException $e)
411 425
 					{
412 426
 					}
413 427
 				}
@@ -420,17 +434,18 @@  discard block
 block discarded – undo
420 434
 				foreach($tmparray as $key=>$value)
421 435
 				{
422 436
 					try {
423
-						if (preg_match('/logo$/',$key)) // Image
437
+						if (preg_match('/logo$/',$key)) {
438
+							// Image
424 439
 						{
425 440
 							if (file_exists($value)) $odfHandler->setImage($key, $value);
426
-							else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
427
-						}
428
-						else    // Text
441
+						} else {
442
+								$odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
443
+							}
444
+						} else    // Text
429 445
 						{
430 446
 							$odfHandler->setVars($key, $value, true, 'UTF-8');
431 447
 						}
432
-					}
433
-					catch(OdfException $e)
448
+					} catch(OdfException $e)
434 449
 					{
435 450
 					}
436 451
 				}
@@ -440,8 +455,7 @@  discard block
 block discarded – undo
440 455
 					$foundtagforlines = 1;
441 456
 					try {
442 457
 						$listlines = $odfHandler->setSegment('lines');
443
-					}
444
-					catch(OdfException $e)
458
+					} catch(OdfException $e)
445 459
 					{
446 460
 						// We may arrive here if tags for lines not present into template
447 461
 						$foundtagforlines = 0;
@@ -461,11 +475,9 @@  discard block
 block discarded – undo
461 475
 								try
462 476
 								{
463 477
 									$listlines->setVars($key, $val, true, 'UTF-8');
464
-								}
465
-								catch(OdfException $e)
478
+								} catch(OdfException $e)
466 479
 								{
467
-								}
468
-								catch(SegmentException $e)
480
+								} catch(SegmentException $e)
469 481
 								{
470 482
 								}
471 483
 							}
@@ -473,8 +485,7 @@  discard block
 block discarded – undo
473 485
 						}
474 486
 						$odfHandler->mergeSegment($listlines);
475 487
 					}
476
-				}
477
-				catch(OdfException $e)
488
+				} catch(OdfException $e)
478 489
 				{
479 490
 					$this->error=$e->getMessage();
480 491
 					dol_syslog($this->error, LOG_WARNING);
@@ -487,8 +498,7 @@  discard block
 block discarded – undo
487 498
 				{
488 499
 					try {
489 500
 						$odfHandler->setVars($key, $value, true, 'UTF-8');
490
-					}
491
-					catch(OdfException $e)
501
+					} catch(OdfException $e)
492 502
 					{
493 503
 					}
494 504
 				}
@@ -501,15 +511,14 @@  discard block
 block discarded – undo
501 511
 				if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
502 512
 					try {
503 513
 						$odfHandler->exportAsAttachedPDF($file);
504
-					}catch (Exception $e){
514
+					} catch (Exception $e){
505 515
 						$this->error=$e->getMessage();
506 516
 						return -1;
507 517
 					}
508
-				}
509
-				else {
518
+				} else {
510 519
 					try {
511 520
 					$odfHandler->saveToDisk($file);
512
-					}catch (Exception $e){
521
+					} catch (Exception $e){
513 522
 						$this->error=$e->getMessage();
514 523
 						return -1;
515 524
 					}
@@ -517,16 +526,16 @@  discard block
 block discarded – undo
517 526
 				$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
518 527
 				$reshook=$hookmanager->executeHooks('afterODTCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
519 528
 
520
-				if (! empty($conf->global->MAIN_UMASK))
521
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
529
+				if (! empty($conf->global->MAIN_UMASK)) {
530
+									@chmod($file, octdec($conf->global->MAIN_UMASK));
531
+				}
522 532
 
523 533
 				$odfHandler=null;	// Destroy object
524 534
 
525 535
 				$this->result = array('fullpath'=>$file);
526 536
 
527 537
 				return 1;   // Success
528
-			}
529
-			else
538
+			} else
530 539
 			{
531 540
 				$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
532 541
 				return -1;
Please login to merge, or discard this patch.
htdocs/core/lib/functions.lib.php 2 patches
Spacing   +1663 added lines, -1663 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
  *					This file contains all frequently used functions.
36 36
  */
37 37
 
38
-include_once DOL_DOCUMENT_ROOT .'/core/lib/json.lib.php';
38
+include_once DOL_DOCUMENT_ROOT.'/core/lib/json.lib.php';
39 39
 
40 40
 
41 41
 /**
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
  */
52 52
 function getStaticMember($class, $member)
53 53
 {
54
-	dol_syslog(__FUNCTION__ . " is deprecated", LOG_WARNING);
54
+	dol_syslog(__FUNCTION__." is deprecated", LOG_WARNING);
55 55
 
56 56
 	// This part is deprecated. Uncomment if for php 5.2.*, and comment next isset class::member
57 57
 	/*if (version_compare(phpversion(), '5.3.0', '<'))
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 	}*/
76 76
 
77 77
 	if (isset($class::$member)) return $class::$member;
78
-	dol_print_error('','Try to get a static member "'.$member.'" in class "'.$class.'" that does not exists or is not static.');
78
+	dol_print_error('', 'Try to get a static member "'.$member.'" in class "'.$class.'" that does not exists or is not static.');
79 79
 	return null;
80 80
 }
81 81
 
@@ -93,10 +93,10 @@  discard block
 block discarded – undo
93 93
  */
94 94
 function getDoliDBInstance($type, $host, $user, $pass, $name, $port)
95 95
 {
96
-	require_once DOL_DOCUMENT_ROOT ."/core/db/".$type.'.class.php';
96
+	require_once DOL_DOCUMENT_ROOT."/core/db/".$type.'.class.php';
97 97
 
98
-	$class='DoliDB'.ucfirst($type);
99
-	$dolidb=new $class($type, $host, $user, $pass, $name, $port);
98
+	$class = 'DoliDB'.ucfirst($type);
99
+	$dolidb = new $class($type, $host, $user, $pass, $name, $port);
100 100
 	return $dolidb;
101 101
 }
102 102
 
@@ -117,14 +117,14 @@  discard block
 block discarded – undo
117 117
  *  @param	int		$forceentity	Entity id
118 118
  * 	@return	mixed				Entity id(s) to use
119 119
  */
120
-function getEntity($element, $shared=1, $forceentity=null)
120
+function getEntity($element, $shared = 1, $forceentity = null)
121 121
 {
122 122
 	global $conf, $mc;
123 123
 
124 124
 	// For backward compatibilty
125
-	if ($element == 'actioncomm') $element='agenda';
126
-	if ($element == 'fichinter')  $element='intervention';
127
-	if ($element == 'categorie')  $element='category';
125
+	if ($element == 'actioncomm') $element = 'agenda';
126
+	if ($element == 'fichinter')  $element = 'intervention';
127
+	if ($element == 'categorie')  $element = 'category';
128 128
 
129 129
 	if (is_object($mc))
130 130
 	{
@@ -132,10 +132,10 @@  discard block
 block discarded – undo
132 132
 	}
133 133
 	else
134 134
 	{
135
-		$out='';
135
+		$out = '';
136 136
 		$addzero = array('user', 'usergroup', 'c_email_templates', 'email_template', 'default_values');
137
-		if (in_array($element, $addzero)) $out.= '0,';
138
-		$out.= $conf->entity;
137
+		if (in_array($element, $addzero)) $out .= '0,';
138
+		$out .= $conf->entity;
139 139
 		return $out;
140 140
 	}
141 141
 }
@@ -160,9 +160,9 @@  discard block
 block discarded – undo
160 160
 {
161 161
 	include_once DOL_DOCUMENT_ROOT.'/includes/mobiledetect/mobiledetectlib/Mobile_Detect.php';
162 162
 
163
-	$name='unknown';
164
-	$version='';
165
-	$os='unknown';
163
+	$name = 'unknown';
164
+	$version = '';
165
+	$os = 'unknown';
166 166
 	$phone = '';
167 167
 
168 168
 	$detectmobile = new Mobile_Detect(null, $user_agent);
@@ -194,22 +194,22 @@  discard block
 block discarded – undo
194 194
 	}
195 195
 
196 196
 	// OS
197
-	if (preg_match('/linux/i', $user_agent))			{ $os='linux'; }
198
-	elseif (preg_match('/macintosh/i', $user_agent))	{ $os='macintosh'; }
199
-	elseif (preg_match('/windows/i', $user_agent))		{ $os='windows'; }
197
+	if (preg_match('/linux/i', $user_agent)) { $os = 'linux'; }
198
+	elseif (preg_match('/macintosh/i', $user_agent)) { $os = 'macintosh'; }
199
+	elseif (preg_match('/windows/i', $user_agent)) { $os = 'windows'; }
200 200
 
201 201
 	// Name
202
-	if (preg_match('/firefox(\/|\s)([\d\.]*)/i', $user_agent, $reg))      { $name='firefox';   $version=$reg[2]; }
203
-	elseif (preg_match('/edge(\/|\s)([\d\.]*)/i', $user_agent, $reg))     { $name='edge';      $version=$reg[2]; }
204
-	elseif (preg_match('/chrome(\/|\s)([\d\.]+)/i', $user_agent, $reg))   { $name='chrome';    $version=$reg[2]; }    // we can have 'chrome (Mozilla...) chrome x.y' in one string
205
-	elseif (preg_match('/chrome/i', $user_agent, $reg))                   { $name='chrome'; }
206
-	elseif (preg_match('/iceweasel/i', $user_agent))                      { $name='iceweasel'; }
207
-	elseif (preg_match('/epiphany/i', $user_agent))                       { $name='epiphany';  }
208
-	elseif (preg_match('/safari(\/|\s)([\d\.]*)/i', $user_agent, $reg))   { $name='safari';    $version=$reg[2]; }	// Safari is often present in string for mobile but its not.
209
-	elseif (preg_match('/opera(\/|\s)([\d\.]*)/i', $user_agent, $reg))    { $name='opera';     $version=$reg[2]; }
210
-	elseif (preg_match('/(MSIE\s([0-9]+\.[0-9]))|.*(Trident\/[0-9]+.[0-9];.*rv:([0-9]+\.[0-9]+))/i', $user_agent, $reg))  { $name='ie'; $version=end($reg); }    // MS products at end
211
-	elseif (preg_match('/(Windows NT\s([0-9]+\.[0-9])).*(Trident\/[0-9]+.[0-9];.*rv:([0-9]+\.[0-9]+))/i', $user_agent, $reg))  { $name='ie'; $version=end($reg); }    // MS products at end
212
-	elseif (preg_match('/l(i|y)n(x|ks)(\(|\/|\s)*([\d\.]+)/i', $user_agent, $reg)) { $name='lynxlinks'; $version=$reg[4]; }
202
+	if (preg_match('/firefox(\/|\s)([\d\.]*)/i', $user_agent, $reg)) { $name = 'firefox'; $version = $reg[2]; }
203
+	elseif (preg_match('/edge(\/|\s)([\d\.]*)/i', $user_agent, $reg)) { $name = 'edge'; $version = $reg[2]; }
204
+	elseif (preg_match('/chrome(\/|\s)([\d\.]+)/i', $user_agent, $reg)) { $name = 'chrome'; $version = $reg[2]; }    // we can have 'chrome (Mozilla...) chrome x.y' in one string
205
+	elseif (preg_match('/chrome/i', $user_agent, $reg)) { $name = 'chrome'; }
206
+	elseif (preg_match('/iceweasel/i', $user_agent)) { $name = 'iceweasel'; }
207
+	elseif (preg_match('/epiphany/i', $user_agent)) { $name = 'epiphany'; }
208
+	elseif (preg_match('/safari(\/|\s)([\d\.]*)/i', $user_agent, $reg)) { $name = 'safari'; $version = $reg[2]; }	// Safari is often present in string for mobile but its not.
209
+	elseif (preg_match('/opera(\/|\s)([\d\.]*)/i', $user_agent, $reg)) { $name = 'opera'; $version = $reg[2]; }
210
+	elseif (preg_match('/(MSIE\s([0-9]+\.[0-9]))|.*(Trident\/[0-9]+.[0-9];.*rv:([0-9]+\.[0-9]+))/i', $user_agent, $reg)) { $name = 'ie'; $version = end($reg); }    // MS products at end
211
+	elseif (preg_match('/(Windows NT\s([0-9]+\.[0-9])).*(Trident\/[0-9]+.[0-9];.*rv:([0-9]+\.[0-9]+))/i', $user_agent, $reg)) { $name = 'ie'; $version = end($reg); }    // MS products at end
212
+	elseif (preg_match('/l(i|y)n(x|ks)(\(|\/|\s)*([\d\.]+)/i', $user_agent, $reg)) { $name = 'lynxlinks'; $version = $reg[4]; }
213 213
 
214 214
 	if ($tablet) {
215 215
 		$layout = 'tablet';
@@ -236,10 +236,10 @@  discard block
 block discarded – undo
236 236
  */
237 237
 function dol_shutdown()
238 238
 {
239
-	global $conf,$user,$langs,$db;
240
-	$disconnectdone=false; $depth=0;
241
-	if (is_object($db) && ! empty($db->connected)) { $depth=$db->transaction_opened; $disconnectdone=$db->close(); }
242
-	dol_syslog("--- End access to ".$_SERVER["PHP_SELF"].(($disconnectdone && $depth)?' (Warn: db disconnection forced, transaction depth was '.$depth.')':''), (($disconnectdone && $depth)?LOG_WARNING:LOG_INFO));
239
+	global $conf, $user, $langs, $db;
240
+	$disconnectdone = false; $depth = 0;
241
+	if (is_object($db) && !empty($db->connected)) { $depth = $db->transaction_opened; $disconnectdone = $db->close(); }
242
+	dol_syslog("--- End access to ".$_SERVER["PHP_SELF"].(($disconnectdone && $depth) ? ' (Warn: db disconnection forced, transaction depth was '.$depth.')' : ''), (($disconnectdone && $depth) ?LOG_WARNING:LOG_INFO));
243 243
 }
244 244
 
245 245
 /**
@@ -276,9 +276,9 @@  discard block
 block discarded – undo
276 276
  *  @param	string	$noreplace	 Force disable of replacement of __xxx__ strings.
277 277
  *  @return string|string[]      Value found (string or array), or '' if check fails
278 278
  */
279
-function GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
279
+function GETPOST($paramname, $check = 'none', $method = 0, $filter = NULL, $options = NULL, $noreplace = 0)
280 280
 {
281
-	global $mysoc,$user,$conf;
281
+	global $mysoc, $user, $conf;
282 282
 
283 283
 	if (empty($paramname)) return 'BadFirstParameterForGETPOST';
284 284
 	if (empty($check))
@@ -288,11 +288,11 @@  discard block
 block discarded – undo
288 288
 		//var_dump(debug_backtrace()[0]);
289 289
 	}
290 290
 
291
-	if (empty($method)) $out = isset($_GET[$paramname])?$_GET[$paramname]:(isset($_POST[$paramname])?$_POST[$paramname]:'');
292
-	elseif ($method==1) $out = isset($_GET[$paramname])?$_GET[$paramname]:'';
293
-	elseif ($method==2) $out = isset($_POST[$paramname])?$_POST[$paramname]:'';
294
-	elseif ($method==3) $out = isset($_POST[$paramname])?$_POST[$paramname]:(isset($_GET[$paramname])?$_GET[$paramname]:'');
295
-	elseif ($method==4) $out = isset($_POST[$paramname])?$_POST[$paramname]:(isset($_GET[$paramname])?$_GET[$paramname]:(isset($_COOKIE[$paramname])?$_COOKIE[$paramname]:''));
291
+	if (empty($method)) $out = isset($_GET[$paramname]) ? $_GET[$paramname] : (isset($_POST[$paramname]) ? $_POST[$paramname] : '');
292
+	elseif ($method == 1) $out = isset($_GET[$paramname]) ? $_GET[$paramname] : '';
293
+	elseif ($method == 2) $out = isset($_POST[$paramname]) ? $_POST[$paramname] : '';
294
+	elseif ($method == 3) $out = isset($_POST[$paramname]) ? $_POST[$paramname] : (isset($_GET[$paramname]) ? $_GET[$paramname] : '');
295
+	elseif ($method == 4) $out = isset($_POST[$paramname]) ? $_POST[$paramname] : (isset($_GET[$paramname]) ? $_GET[$paramname] : (isset($_COOKIE[$paramname]) ? $_COOKIE[$paramname] : ''));
296 296
 	else return 'BadThirdParameterForGETPOST';
297 297
 
298 298
 	if (empty($method) || $method == 3 || $method == 4)
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
 
301 301
 		$relativepathstring = $_SERVER["PHP_SELF"];
302 302
 		// Clean $relativepathstring
303
-		if (constant('DOL_URL_ROOT')) $relativepathstring = preg_replace('/^'.preg_quote(constant('DOL_URL_ROOT'),'/').'/', '', $relativepathstring);
303
+		if (constant('DOL_URL_ROOT')) $relativepathstring = preg_replace('/^'.preg_quote(constant('DOL_URL_ROOT'), '/').'/', '', $relativepathstring);
304 304
 		$relativepathstring = preg_replace('/^\//', '', $relativepathstring);
305 305
 		$relativepathstring = preg_replace('/^custom\//', '', $relativepathstring);
306 306
 		//var_dump($relativepathstring);
@@ -308,25 +308,25 @@  discard block
 block discarded – undo
308 308
 
309 309
 		// Code for search criteria persistence.
310 310
 		// Retrieve values if restore_lastsearch_values is set and there is saved values
311
-		if (! empty($_GET['restore_lastsearch_values']) && ! empty($_SESSION['lastsearch_values_'.$relativepathstring]))        // Keep $_GET here
311
+		if (!empty($_GET['restore_lastsearch_values']) && !empty($_SESSION['lastsearch_values_'.$relativepathstring]))        // Keep $_GET here
312 312
 		{
313
-			$tmp=json_decode($_SESSION['lastsearch_values_'.$relativepathstring], true);
313
+			$tmp = json_decode($_SESSION['lastsearch_values_'.$relativepathstring], true);
314 314
 			if (is_array($tmp))
315 315
 			{
316
-				foreach($tmp as $key => $val)
316
+				foreach ($tmp as $key => $val)
317 317
 				{
318 318
 					if ($key == $paramname)
319 319
 					{
320
-						$out=$val;
320
+						$out = $val;
321 321
 						break;
322 322
 					}
323 323
 				}
324 324
 			}
325 325
 		}
326 326
 		// Else, retreive default values if we are not doing a sort
327
-		elseif (! isset($_GET['sortfield']))	// If we did a click on a field to sort, we do no apply default values. Same if option MAIN_ENABLE_DEFAULT_VALUES is not set
327
+		elseif (!isset($_GET['sortfield']))	// If we did a click on a field to sort, we do no apply default values. Same if option MAIN_ENABLE_DEFAULT_VALUES is not set
328 328
 		{
329
-			if (! empty($_GET['action']) && $_GET['action'] == 'create' && ! isset($_GET[$paramname]) && ! isset($_POST[$paramname]))
329
+			if (!empty($_GET['action']) && $_GET['action'] == 'create' && !isset($_GET[$paramname]) && !isset($_POST[$paramname]))
330 330
 			{
331 331
 				// Search default value from $object->field
332 332
 				global $object;
@@ -335,28 +335,28 @@  discard block
 block discarded – undo
335 335
 					$out = $object->fields[$paramname]['default'];
336 336
 				}
337 337
 			}
338
-			if (! empty($conf->global->MAIN_ENABLE_DEFAULT_VALUES))
338
+			if (!empty($conf->global->MAIN_ENABLE_DEFAULT_VALUES))
339 339
 			{
340
-				if (! empty($_GET['action']) && $_GET['action'] == 'create' && ! isset($_GET[$paramname]) && ! isset($_POST[$paramname]))
340
+				if (!empty($_GET['action']) && $_GET['action'] == 'create' && !isset($_GET[$paramname]) && !isset($_POST[$paramname]))
341 341
 				{
342 342
 					// Now search in setup to overwrite default values
343
-					if (! empty($user->default_values))		// $user->default_values defined from menu 'Setup - Default values'
343
+					if (!empty($user->default_values))		// $user->default_values defined from menu 'Setup - Default values'
344 344
 					{
345 345
 						if (isset($user->default_values[$relativepathstring]['createform']))
346 346
 						{
347
-							foreach($user->default_values[$relativepathstring]['createform'] as $defkey => $defval)
347
+							foreach ($user->default_values[$relativepathstring]['createform'] as $defkey => $defval)
348 348
 							{
349 349
 								$qualified = 0;
350 350
 								if ($defkey != '_noquery_')
351 351
 								{
352
-									$tmpqueryarraytohave=explode('&', $defkey);
353
-									$tmpqueryarraywehave=explode('&', dol_string_nohtmltag($_SERVER['QUERY_STRING']));
354
-									$foundintru=0;
355
-									foreach($tmpqueryarraytohave as $tmpquerytohave)
352
+									$tmpqueryarraytohave = explode('&', $defkey);
353
+									$tmpqueryarraywehave = explode('&', dol_string_nohtmltag($_SERVER['QUERY_STRING']));
354
+									$foundintru = 0;
355
+									foreach ($tmpqueryarraytohave as $tmpquerytohave)
356 356
 									{
357
-										if (! in_array($tmpquerytohave, $tmpqueryarraywehave)) $foundintru=1;
357
+										if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) $foundintru = 1;
358 358
 									}
359
-									if (! $foundintru) $qualified=1;
359
+									if (!$foundintru) $qualified = 1;
360 360
 									//var_dump($defkey.'-'.$qualified);
361 361
 								}
362 362
 								else $qualified = 1;
@@ -376,45 +376,45 @@  discard block
 block discarded – undo
376 376
 				}
377 377
 				// Management of default search_filters and sort order
378 378
 				//elseif (preg_match('/list.php$/', $_SERVER["PHP_SELF"]) && ! empty($paramname) && ! isset($_GET[$paramname]) && ! isset($_POST[$paramname]))
379
-				elseif (! empty($paramname) && ! isset($_GET[$paramname]) && ! isset($_POST[$paramname]))
379
+				elseif (!empty($paramname) && !isset($_GET[$paramname]) && !isset($_POST[$paramname]))
380 380
 				{
381
-					if (! empty($user->default_values))		// $user->default_values defined from menu 'Setup - Default values'
381
+					if (!empty($user->default_values))		// $user->default_values defined from menu 'Setup - Default values'
382 382
 					{
383 383
 						//var_dump($user->default_values[$relativepathstring]);
384 384
 						if ($paramname == 'sortfield' || $paramname == 'sortorder')			// Sorted on which fields ? ASC or DESC ?
385 385
 						{
386 386
 							if (isset($user->default_values[$relativepathstring]['sortorder']))	// Even if paramname is sortfield, data are stored into ['sortorder...']
387 387
 							{
388
-								foreach($user->default_values[$relativepathstring]['sortorder'] as $defkey => $defval)
388
+								foreach ($user->default_values[$relativepathstring]['sortorder'] as $defkey => $defval)
389 389
 								{
390 390
 									$qualified = 0;
391 391
 									if ($defkey != '_noquery_')
392 392
 									{
393
-										$tmpqueryarraytohave=explode('&', $defkey);
394
-										$tmpqueryarraywehave=explode('&', dol_string_nohtmltag($_SERVER['QUERY_STRING']));
395
-										$foundintru=0;
396
-										foreach($tmpqueryarraytohave as $tmpquerytohave)
393
+										$tmpqueryarraytohave = explode('&', $defkey);
394
+										$tmpqueryarraywehave = explode('&', dol_string_nohtmltag($_SERVER['QUERY_STRING']));
395
+										$foundintru = 0;
396
+										foreach ($tmpqueryarraytohave as $tmpquerytohave)
397 397
 										{
398
-											if (! in_array($tmpquerytohave, $tmpqueryarraywehave)) $foundintru=1;
398
+											if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) $foundintru = 1;
399 399
 										}
400
-										if (! $foundintru) $qualified=1;
400
+										if (!$foundintru) $qualified = 1;
401 401
 										//var_dump($defkey.'-'.$qualified);
402 402
 									}
403 403
 									else $qualified = 1;
404 404
 
405 405
 									if ($qualified)
406 406
 									{
407
-										$forbidden_chars_to_replace=array(" ","'","/","\\",":","*","?","\"","<",">","|","[","]",";","=");  // we accept _, -, . and ,
408
-										foreach($user->default_values[$relativepathstring]['sortorder'][$defkey] as $key => $val)
407
+										$forbidden_chars_to_replace = array(" ", "'", "/", "\\", ":", "*", "?", "\"", "<", ">", "|", "[", "]", ";", "="); // we accept _, -, . and ,
408
+										foreach ($user->default_values[$relativepathstring]['sortorder'][$defkey] as $key => $val)
409 409
 										{
410
-											if ($out) $out.=', ';
410
+											if ($out) $out .= ', ';
411 411
 											if ($paramname == 'sortfield')
412 412
 											{
413
-												$out.=dol_string_nospecial($key, '', $forbidden_chars_to_replace);
413
+												$out .= dol_string_nospecial($key, '', $forbidden_chars_to_replace);
414 414
 											}
415 415
 											if ($paramname == 'sortorder')
416 416
 											{
417
-												$out.=dol_string_nospecial($val, '', $forbidden_chars_to_replace);
417
+												$out .= dol_string_nospecial($val, '', $forbidden_chars_to_replace);
418 418
 											}
419 419
 										}
420 420
 										//break;	// No break for sortfield and sortorder so we can cumulate fields (is it realy usefull ?)
@@ -424,19 +424,19 @@  discard block
 block discarded – undo
424 424
 						}
425 425
 						elseif (isset($user->default_values[$relativepathstring]['filters']))
426 426
 						{
427
-							foreach($user->default_values[$relativepathstring]['filters'] as $defkey => $defval)
427
+							foreach ($user->default_values[$relativepathstring]['filters'] as $defkey => $defval)
428 428
 							{
429 429
 								$qualified = 0;
430 430
 								if ($defkey != '_noquery_')
431 431
 								{
432
-									$tmpqueryarraytohave=explode('&', $defkey);
433
-									$tmpqueryarraywehave=explode('&', dol_string_nohtmltag($_SERVER['QUERY_STRING']));
434
-									$foundintru=0;
435
-									foreach($tmpqueryarraytohave as $tmpquerytohave)
432
+									$tmpqueryarraytohave = explode('&', $defkey);
433
+									$tmpqueryarraywehave = explode('&', dol_string_nohtmltag($_SERVER['QUERY_STRING']));
434
+									$foundintru = 0;
435
+									foreach ($tmpqueryarraytohave as $tmpquerytohave)
436 436
 									{
437
-										if (! in_array($tmpquerytohave, $tmpqueryarraywehave)) $foundintru=1;
437
+										if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) $foundintru = 1;
438 438
 									}
439
-									if (! $foundintru) $qualified=1;
439
+									if (!$foundintru) $qualified = 1;
440 440
 									//var_dump($defkey.'-'.$qualified);
441 441
 								}
442 442
 								else $qualified = 1;
@@ -448,13 +448,13 @@  discard block
 block discarded – undo
448 448
 										// We made a search from quick search menu, do we still use default filter ?
449 449
 										if (empty($conf->global->MAIN_DISABLE_DEFAULT_FILTER_FOR_QUICK_SEARCH))
450 450
 										{
451
-											$forbidden_chars_to_replace=array(" ","'","/","\\",":","*","?","\"","<",">","|","[","]",";","=");  // we accept _, -, . and ,
451
+											$forbidden_chars_to_replace = array(" ", "'", "/", "\\", ":", "*", "?", "\"", "<", ">", "|", "[", "]", ";", "="); // we accept _, -, . and ,
452 452
 											$out = dol_string_nospecial($user->default_values[$relativepathstring]['filters'][$defkey][$paramname], '', $forbidden_chars_to_replace);
453 453
 										}
454 454
 									}
455 455
 									else
456 456
 									{
457
-										$forbidden_chars_to_replace=array(" ","'","/","\\",":","*","?","\"","<",">","|","[","]",";","=");  // we accept _, -, . and ,
457
+										$forbidden_chars_to_replace = array(" ", "'", "/", "\\", ":", "*", "?", "\"", "<", ">", "|", "[", "]", ";", "="); // we accept _, -, . and ,
458 458
 										$out = dol_string_nospecial($user->default_values[$relativepathstring]['filters'][$defkey][$paramname], '', $forbidden_chars_to_replace);
459 459
 									}
460 460
 									break;
@@ -470,22 +470,22 @@  discard block
 block discarded – undo
470 470
 	// Substitution variables for GETPOST (used to get final url with variable parameters or final default value with variable paramaters)
471 471
 	// Example of variables: __DAY__, __MONTH__, __YEAR__, __MYCOMPANY_COUNTRY_ID__, __USER_ID__, ...
472 472
 	// We do this only if var is a GET. If it is a POST, may be we want to post the text with vars as the setup text.
473
-	if (! is_array($out) && empty($_POST[$paramname]) && empty($noreplace))
473
+	if (!is_array($out) && empty($_POST[$paramname]) && empty($noreplace))
474 474
 	{
475
-		$maxloop=20; $loopnb=0;    // Protection against infinite loop
475
+		$maxloop = 20; $loopnb = 0; // Protection against infinite loop
476 476
 		while (preg_match('/__([A-Z0-9]+_?[A-Z0-9]+)__/i', $out, $reg) && ($loopnb < $maxloop))    // Detect '__ABCDEF__' as key 'ABCDEF' and '__ABC_DEF__' as key 'ABC_DEF'. Detection is also correct when 2 vars are side by side.
477 477
 		{
478 478
 				$loopnb++; $newout = '';
479 479
 
480
-				if ($reg[1] == 'DAY')                { $tmp=dol_getdate(dol_now(), true); $newout = $tmp['mday']; }
481
-				elseif ($reg[1] == 'MONTH')          { $tmp=dol_getdate(dol_now(), true); $newout = $tmp['mon'];  }
482
-				elseif ($reg[1] == 'YEAR')           { $tmp=dol_getdate(dol_now(), true); $newout = $tmp['year']; }
483
-				elseif ($reg[1] == 'PREVIOUS_DAY')   { $tmp=dol_getdate(dol_now(), true); $tmp2=dol_get_prev_day($tmp['mday'], $tmp['mon'], $tmp['year']); $newout = $tmp2['day']; }
484
-				elseif ($reg[1] == 'PREVIOUS_MONTH') { $tmp=dol_getdate(dol_now(), true); $tmp2=dol_get_prev_month($tmp['mday'], $tmp['mon'], $tmp['year']); $newout = $tmp2['month']; }
485
-				elseif ($reg[1] == 'PREVIOUS_YEAR')  { $tmp=dol_getdate(dol_now(), true); $newout = ($tmp['year'] - 1); }
486
-				elseif ($reg[1] == 'NEXT_DAY')       { $tmp=dol_getdate(dol_now(), true); $tmp2=dol_get_next_day($tmp['mday'], $tmp['mon'], $tmp['year']); $newout = $tmp2['day']; }
487
-				elseif ($reg[1] == 'NEXT_MONTH')     { $tmp=dol_getdate(dol_now(), true); $tmp2=dol_get_next_month($tmp['mday'], $tmp['mon'], $tmp['year']); $newout = $tmp2['month']; }
488
-				elseif ($reg[1] == 'NEXT_YEAR')      { $tmp=dol_getdate(dol_now(), true); $newout = ($tmp['year'] + 1); }
480
+				if ($reg[1] == 'DAY') { $tmp = dol_getdate(dol_now(), true); $newout = $tmp['mday']; }
481
+				elseif ($reg[1] == 'MONTH') { $tmp = dol_getdate(dol_now(), true); $newout = $tmp['mon']; }
482
+				elseif ($reg[1] == 'YEAR') { $tmp = dol_getdate(dol_now(), true); $newout = $tmp['year']; }
483
+				elseif ($reg[1] == 'PREVIOUS_DAY') { $tmp = dol_getdate(dol_now(), true); $tmp2 = dol_get_prev_day($tmp['mday'], $tmp['mon'], $tmp['year']); $newout = $tmp2['day']; }
484
+				elseif ($reg[1] == 'PREVIOUS_MONTH') { $tmp = dol_getdate(dol_now(), true); $tmp2 = dol_get_prev_month($tmp['mday'], $tmp['mon'], $tmp['year']); $newout = $tmp2['month']; }
485
+				elseif ($reg[1] == 'PREVIOUS_YEAR') { $tmp = dol_getdate(dol_now(), true); $newout = ($tmp['year'] - 1); }
486
+				elseif ($reg[1] == 'NEXT_DAY') { $tmp = dol_getdate(dol_now(), true); $tmp2 = dol_get_next_day($tmp['mday'], $tmp['mon'], $tmp['year']); $newout = $tmp2['day']; }
487
+				elseif ($reg[1] == 'NEXT_MONTH') { $tmp = dol_getdate(dol_now(), true); $tmp2 = dol_get_next_month($tmp['mday'], $tmp['mon'], $tmp['year']); $newout = $tmp2['month']; }
488
+				elseif ($reg[1] == 'NEXT_YEAR') { $tmp = dol_getdate(dol_now(), true); $newout = ($tmp['year'] + 1); }
489 489
 				elseif ($reg[1] == 'MYCOMPANY_COUNTRY_ID' || $reg[1] == 'MYCOUNTRY_ID' || $reg[1] == 'MYCOUNTRYID')
490 490
 				{
491 491
 					$newout = $mysoc->country_id;
@@ -502,9 +502,9 @@  discard block
 block discarded – undo
502 502
 				{
503 503
 					$newout = $conf->entity;
504 504
 				}
505
-				else $newout = '';     // Key not found, we replace with empty string
505
+				else $newout = ''; // Key not found, we replace with empty string
506 506
 				//var_dump('__'.$reg[1].'__ -> '.$newout);
507
-				$out = preg_replace('/__'.preg_quote($reg[1],'/').'__/', $newout, $out);
507
+				$out = preg_replace('/__'.preg_quote($reg[1], '/').'__/', $newout, $out);
508 508
 		}
509 509
 	}
510 510
 
@@ -514,58 +514,58 @@  discard block
 block discarded – undo
514 514
 		case 'none':
515 515
 			break;
516 516
 		case 'int':    // Check param is a numeric value (integer but also float or hexadecimal)
517
-			if (! is_numeric($out)) { $out=''; }
517
+			if (!is_numeric($out)) { $out = ''; }
518 518
 			break;
519 519
 		case 'intcomma':
520
-			if (preg_match('/[^0-9,-]+/i',$out)) $out='';
520
+			if (preg_match('/[^0-9,-]+/i', $out)) $out = '';
521 521
 			break;
522 522
 		case 'alpha':
523
-			if (! is_array($out))
523
+			if (!is_array($out))
524 524
 			{
525
-				$out=trim($out);
525
+				$out = trim($out);
526 526
 				// '"' is dangerous because param in url can close the href= or src= and add javascript functions.
527 527
 				// '../' is dangerous because it allows dir transversals
528
-				if (preg_match('/"/',$out)) $out='';
529
-				else if (preg_match('/\.\.\//',$out)) $out='';
528
+				if (preg_match('/"/', $out)) $out = '';
529
+				else if (preg_match('/\.\.\//', $out)) $out = '';
530 530
 			}
531 531
 			break;
532 532
 		case 'san_alpha':
533
-			$out=filter_var($out,FILTER_SANITIZE_STRING);
533
+			$out = filter_var($out, FILTER_SANITIZE_STRING);
534 534
 			break;
535 535
 		case 'aZ':
536
-			if (! is_array($out))
536
+			if (!is_array($out))
537 537
 			{
538
-				$out=trim($out);
539
-				if (preg_match('/[^a-z]+/i',$out)) $out='';
538
+				$out = trim($out);
539
+				if (preg_match('/[^a-z]+/i', $out)) $out = '';
540 540
 			}
541 541
 			break;
542 542
 		case 'aZ09':
543
-			if (! is_array($out))
543
+			if (!is_array($out))
544 544
 			{
545
-				$out=trim($out);
546
-				if (preg_match('/[^a-z0-9_\-\.]+/i',$out)) $out='';
545
+				$out = trim($out);
546
+				if (preg_match('/[^a-z0-9_\-\.]+/i', $out)) $out = '';
547 547
 			}
548 548
 			break;
549 549
 		case 'array':
550
-			if (! is_array($out) || empty($out)) $out=array();
550
+			if (!is_array($out) || empty($out)) $out = array();
551 551
 			break;
552 552
 		case 'nohtml':
553
-			$out=dol_string_nohtmltag($out, 0);
553
+			$out = dol_string_nohtmltag($out, 0);
554 554
 			break;
555 555
 		case 'alphanohtml':	// Recommended for search params
556
-			if (! is_array($out))
556
+			if (!is_array($out))
557 557
 			{
558
-				$out=trim($out);
558
+				$out = trim($out);
559 559
 				// '"' is dangerous because param in url can close the href= or src= and add javascript functions.
560 560
 				// '../' is dangerous because it allows dir transversals
561
-				if (preg_match('/"/',$out)) $out='';
562
-				else if (preg_match('/\.\.\//',$out)) $out='';
563
-				$out=dol_string_nohtmltag($out);
561
+				if (preg_match('/"/', $out)) $out = '';
562
+				else if (preg_match('/\.\.\//', $out)) $out = '';
563
+				$out = dol_string_nohtmltag($out);
564 564
 			}
565 565
 			break;
566 566
 		case 'custom':
567 567
 			if (empty($filter)) return 'BadFourthParameterForGETPOST';
568
-			$out=filter_var($out, $filter, $options);
568
+			$out = filter_var($out, $filter, $options);
569 569
 			break;
570 570
 	}
571 571
 
@@ -574,7 +574,7 @@  discard block
 block discarded – undo
574 574
 	if (empty($method) || $method == 3 || $method == 4)
575 575
 	{
576 576
 		//if (preg_match('/^search_/', $paramname) || in_array($paramname, array('sortorder', 'sortfield", 'smonth', 'syear', 'month', 'year')))
577
-		if (preg_match('/^search_/', $paramname) || in_array($paramname, array('sortorder','sortfield')))
577
+		if (preg_match('/^search_/', $paramname) || in_array($paramname, array('sortorder', 'sortfield')))
578 578
 		{
579 579
 			//var_dump($paramname.' - '.$out.' '.$user->default_values[$relativepathstring]['filters'][$paramname]);
580 580
 
@@ -583,9 +583,9 @@  discard block
 block discarded – undo
583 583
 			// - if value is empty and a default value exists that is not empty (it means we did a filter to an empty value when default was not).
584 584
 
585 585
 			//if (! empty($out) || ! empty($user->default_values[$relativepathstring]['filters'][$paramname]))
586
-			if (! empty($out))
586
+			if (!empty($out))
587 587
 			{
588
-				$user->lastsearch_values_tmp[$relativepathstring][$paramname]=$out;
588
+				$user->lastsearch_values_tmp[$relativepathstring][$paramname] = $out;
589 589
 			}
590 590
 		}
591 591
 	}
@@ -603,14 +603,14 @@  discard block
 block discarded – undo
603 603
  *  @param  string  $mode       			'' (prefix for session name) or 'email' (prefix for email id)
604 604
  *  @return	string      					A calculated prefix
605 605
  */
606
-if (! function_exists('dol_getprefix'))
606
+if (!function_exists('dol_getprefix'))
607 607
 {
608
-	function dol_getprefix($mode='')
608
+	function dol_getprefix($mode = '')
609 609
 	{
610 610
 		global $conf;
611 611
 
612 612
 		// If MAIL_PREFIX_FOR_EMAIL_ID is set and prefix is for email
613
-		if ($mode == 'email' && ! empty($conf->global->MAIL_PREFIX_FOR_EMAIL_ID))
613
+		if ($mode == 'email' && !empty($conf->global->MAIL_PREFIX_FOR_EMAIL_ID))
614 614
 		{
615 615
 			if ($conf->global->MAIL_PREFIX_FOR_EMAIL_ID != 'SERVER_NAME') return $conf->global->MAIL_PREFIX_FOR_EMAIL_ID;
616 616
 			else if (isset($_SERVER["SERVER_NAME"])) return $_SERVER["SERVER_NAME"];
@@ -636,9 +636,9 @@  discard block
 block discarded – undo
636 636
  * 	@param	string	$classname	Class name (deprecated)
637 637
  *  @return bool                True if load is a success, False if it fails
638 638
  */
639
-function dol_include_once($relpath, $classname='')
639
+function dol_include_once($relpath, $classname = '')
640 640
 {
641
-	global $conf,$langs,$user,$mysoc;   // Do not remove this. They must be defined for files we include. Other globals var must be retreived with $GLOBALS['var']
641
+	global $conf, $langs, $user, $mysoc; // Do not remove this. They must be defined for files we include. Other globals var must be retreived with $GLOBALS['var']
642 642
 
643 643
 	$fullpath = dol_buildpath($relpath);
644 644
 
@@ -647,7 +647,7 @@  discard block
 block discarded – undo
647 647
 		return false;
648 648
 	}
649 649
 
650
-	if (! empty($classname) && ! class_exists($classname)) {
650
+	if (!empty($classname) && !class_exists($classname)) {
651 651
 		return include $fullpath;
652 652
 	} else {
653 653
 		return include_once $fullpath;
@@ -665,27 +665,27 @@  discard block
 block discarded – undo
665 665
  *  											2:If $type==0 and if file was not found into alternate dir, test into main dir, return default path if found, empty string if not found
666 666
  *  @return string								Full filesystem path (if path=0), Full url path (if mode=1)
667 667
  */
668
-function dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
668
+function dol_buildpath($path, $type = 0, $returnemptyifnotfound = 0)
669 669
 {
670 670
 	global $conf;
671 671
 
672
-	$path=preg_replace('/^\//','',$path);
672
+	$path = preg_replace('/^\//', '', $path);
673 673
 
674 674
 	if (empty($type))	// For a filesystem path
675 675
 	{
676
-		$res = DOL_DOCUMENT_ROOT.'/'.$path;		// Standard default path
676
+		$res = DOL_DOCUMENT_ROOT.'/'.$path; // Standard default path
677 677
 		foreach ($conf->file->dol_document_root as $key => $dirroot)	// ex: array(["main"]=>"/home/main/htdocs", ["alt0"]=>"/home/dirmod/htdocs", ...)
678 678
 		{
679 679
 			if ($key == 'main') continue;
680 680
 			if (file_exists($dirroot.'/'.$path))
681 681
 			{
682
-				$res=$dirroot.'/'.$path;
682
+				$res = $dirroot.'/'.$path;
683 683
 				return $res;
684 684
 			}
685 685
 		}
686 686
 		if ($returnemptyifnotfound)								// Not found into alternate dir
687 687
 		{
688
-			if ($returnemptyifnotfound == 1 || ! file_exists($res)) return '';
688
+			if ($returnemptyifnotfound == 1 || !file_exists($res)) return '';
689 689
 		}
690 690
 	}
691 691
 	else				// For an url path
@@ -694,9 +694,9 @@  discard block
 block discarded – undo
694 694
 		// Note that trying to know if a file on disk exist by forging path on disk from url
695 695
 		// works only for some web server and some setup. This is bugged when
696 696
 		// using proxy, rewriting, virtual path, etc...
697
-		$res='';
698
-		if ($type == 1) $res = DOL_URL_ROOT.'/'.$path;			// Standard value
699
-		if ($type == 2) $res = DOL_MAIN_URL_ROOT.'/'.$path;		// Standard value
697
+		$res = '';
698
+		if ($type == 1) $res = DOL_URL_ROOT.'/'.$path; // Standard value
699
+		if ($type == 2) $res = DOL_MAIN_URL_ROOT.'/'.$path; // Standard value
700 700
 		if ($type == 3) $res = DOL_URL_ROOT.'/'.$path;
701 701
 
702 702
 		foreach ($conf->file->dol_document_root as $key => $dirroot)	// ex: array(["main"]=>"/home/main/htdocs", ["alt0"]=>"/home/dirmod/htdocs", ...)
@@ -708,38 +708,38 @@  discard block
 block discarded – undo
708 708
 					global $dolibarr_main_url_root;
709 709
 
710 710
 					// Define $urlwithroot
711
-					$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
712
-					$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT;		// This is to use external domain name found into config file
711
+					$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
712
+					$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
713 713
 					//$urlwithroot=DOL_MAIN_URL_ROOT;					// This is to use same domain name than current
714 714
 
715
-					$res=(preg_match('/^http/i',$conf->file->dol_url_root[$key])?'':$urlwithroot).'/'.$path;     // Test on start with http is for old conf syntax
715
+					$res = (preg_match('/^http/i', $conf->file->dol_url_root[$key]) ? '' : $urlwithroot).'/'.$path; // Test on start with http is for old conf syntax
716 716
 				}
717 717
 				continue;
718 718
 			}
719
-			preg_match('/^([^\?]+(\.css\.php|\.css|\.js\.php|\.js|\.png|\.jpg|\.php)?)/i',$path,$regs);    // Take part before '?'
720
-			if (! empty($regs[1]))
719
+			preg_match('/^([^\?]+(\.css\.php|\.css|\.js\.php|\.js|\.png|\.jpg|\.php)?)/i', $path, $regs); // Take part before '?'
720
+			if (!empty($regs[1]))
721 721
 			{
722 722
 				//print $key.'-'.$dirroot.'/'.$path.'-'.$conf->file->dol_url_root[$type].'<br>'."\n";
723 723
 				if (file_exists($dirroot.'/'.$regs[1]))
724 724
 				{
725 725
 					if ($type == 1)
726 726
 					{
727
-						$res=(preg_match('/^http/i',$conf->file->dol_url_root[$key])?'':DOL_URL_ROOT).$conf->file->dol_url_root[$key].'/'.$path;
727
+						$res = (preg_match('/^http/i', $conf->file->dol_url_root[$key]) ? '' : DOL_URL_ROOT).$conf->file->dol_url_root[$key].'/'.$path;
728 728
 					}
729 729
 					if ($type == 2)
730 730
 					{
731
-						$res=(preg_match('/^http/i',$conf->file->dol_url_root[$key])?'':DOL_MAIN_URL_ROOT).$conf->file->dol_url_root[$key].'/'.$path;
731
+						$res = (preg_match('/^http/i', $conf->file->dol_url_root[$key]) ? '' : DOL_MAIN_URL_ROOT).$conf->file->dol_url_root[$key].'/'.$path;
732 732
 					}
733 733
 					if ($type == 3)
734 734
 					{
735 735
 						global $dolibarr_main_url_root;
736 736
 
737 737
 						// Define $urlwithroot
738
-						$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
739
-						$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT;		// This is to use external domain name found into config file
738
+						$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
739
+						$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
740 740
 						//$urlwithroot=DOL_MAIN_URL_ROOT;					// This is to use same domain name than current
741 741
 
742
-						$res=(preg_match('/^http/i',$conf->file->dol_url_root[$key])?'':$urlwithroot).$conf->file->dol_url_root[$key].'/'.$path;     // Test on start with http is for old conf syntax
742
+						$res = (preg_match('/^http/i', $conf->file->dol_url_root[$key]) ? '' : $urlwithroot).$conf->file->dol_url_root[$key].'/'.$path; // Test on start with http is for old conf syntax
743 743
 					}
744 744
 					break;
745 745
 				}
@@ -760,17 +760,17 @@  discard block
 block discarded – undo
760 760
  *	@return object				Object clone
761 761
  *  @see https://php.net/manual/language.oop5.cloning.php
762 762
  */
763
-function dol_clone($object, $native=0)
763
+function dol_clone($object, $native = 0)
764 764
 {
765 765
 	//dol_syslog(__FUNCTION__ . " is deprecated", LOG_WARNING);
766 766
 
767 767
 	if (empty($native))
768 768
 	{
769
-		$myclone=unserialize(serialize($object));
769
+		$myclone = unserialize(serialize($object));
770 770
 	}
771 771
 	else
772 772
 	{
773
-		$myclone = clone $object;     // PHP clone is a shallow copy only, not a real clone, so properties of references will keep references (refer to the same target/variable)
773
+		$myclone = clone $object; // PHP clone is a shallow copy only, not a real clone, so properties of references will keep references (refer to the same target/variable)
774 774
 	}
775 775
 
776 776
 	return $myclone;
@@ -785,7 +785,7 @@  discard block
 block discarded – undo
785 785
  * 								'width' = function is used to define a width
786 786
  *	@return int					New size after optimizing
787 787
  */
788
-function dol_size($size,$type='')
788
+function dol_size($size, $type = '')
789 789
 {
790 790
 	global $conf;
791 791
 	if (empty($conf->dol_optimize_smallscreen)) return $size;
@@ -804,10 +804,10 @@  discard block
 block discarded – undo
804 804
  *
805 805
  * 	@see        	dol_string_nospecial, dol_string_unaccent, dol_sanitizePathName
806 806
  */
807
-function dol_sanitizeFileName($str,$newstr='_',$unaccent=1)
807
+function dol_sanitizeFileName($str, $newstr = '_', $unaccent = 1)
808 808
 {
809
-	$filesystem_forbidden_chars = array('<','>','/','\\','?','*','|','"','°');
810
-	return dol_string_nospecial($unaccent?dol_string_unaccent($str):$str, $newstr, $filesystem_forbidden_chars);
809
+	$filesystem_forbidden_chars = array('<', '>', '/', '\\', '?', '*', '|', '"', '°');
810
+	return dol_string_nospecial($unaccent ?dol_string_unaccent($str) : $str, $newstr, $filesystem_forbidden_chars);
811 811
 }
812 812
 
813 813
 /**
@@ -820,10 +820,10 @@  discard block
 block discarded – undo
820 820
  *
821 821
  * 	@see        	dol_string_nospecial, dol_string_unaccent, dol_sanitizeFileName
822 822
  */
823
-function dol_sanitizePathName($str,$newstr='_',$unaccent=1)
823
+function dol_sanitizePathName($str, $newstr = '_', $unaccent = 1)
824 824
 {
825
-	$filesystem_forbidden_chars = array('<','>','?','*','|','"','°');
826
-	return dol_string_nospecial($unaccent?dol_string_unaccent($str):$str, $newstr, $filesystem_forbidden_chars);
825
+	$filesystem_forbidden_chars = array('<', '>', '?', '*', '|', '"', '°');
826
+	return dol_string_nospecial($unaccent ?dol_string_unaccent($str) : $str, $newstr, $filesystem_forbidden_chars);
827 827
 }
828 828
 
829 829
 /**
@@ -841,21 +841,21 @@  discard block
 block discarded – undo
841 841
 		// See http://www.utf8-chartable.de/
842 842
 		$string = rawurlencode($str);
843 843
 		$replacements = array(
844
-		'%C3%80' => 'A','%C3%81' => 'A','%C3%82' => 'A','%C3%83' => 'A','%C3%84' => 'A','%C3%85' => 'A',
845
-		'%C3%88' => 'E','%C3%89' => 'E','%C3%8A' => 'E','%C3%8B' => 'E',
846
-		'%C3%8C' => 'I','%C3%8D' => 'I','%C3%8E' => 'I','%C3%8F' => 'I',
847
-		'%C3%92' => 'O','%C3%93' => 'O','%C3%94' => 'O','%C3%95' => 'O','%C3%96' => 'O',
848
-		'%C3%99' => 'U','%C3%9A' => 'U','%C3%9B' => 'U','%C3%9C' => 'U',
849
-		'%C3%A0' => 'a','%C3%A1' => 'a','%C3%A2' => 'a','%C3%A3' => 'a','%C3%A4' => 'a','%C3%A5' => 'a',
844
+		'%C3%80' => 'A', '%C3%81' => 'A', '%C3%82' => 'A', '%C3%83' => 'A', '%C3%84' => 'A', '%C3%85' => 'A',
845
+		'%C3%88' => 'E', '%C3%89' => 'E', '%C3%8A' => 'E', '%C3%8B' => 'E',
846
+		'%C3%8C' => 'I', '%C3%8D' => 'I', '%C3%8E' => 'I', '%C3%8F' => 'I',
847
+		'%C3%92' => 'O', '%C3%93' => 'O', '%C3%94' => 'O', '%C3%95' => 'O', '%C3%96' => 'O',
848
+		'%C3%99' => 'U', '%C3%9A' => 'U', '%C3%9B' => 'U', '%C3%9C' => 'U',
849
+		'%C3%A0' => 'a', '%C3%A1' => 'a', '%C3%A2' => 'a', '%C3%A3' => 'a', '%C3%A4' => 'a', '%C3%A5' => 'a',
850 850
 		'%C3%A7' => 'c',
851
-		'%C3%A8' => 'e','%C3%A9' => 'e','%C3%AA' => 'e','%C3%AB' => 'e',
852
-		'%C3%AC' => 'i','%C3%AD' => 'i','%C3%AE' => 'i','%C3%AF' => 'i',
851
+		'%C3%A8' => 'e', '%C3%A9' => 'e', '%C3%AA' => 'e', '%C3%AB' => 'e',
852
+		'%C3%AC' => 'i', '%C3%AD' => 'i', '%C3%AE' => 'i', '%C3%AF' => 'i',
853 853
 		'%C3%B1' => 'n',
854
-		'%C3%B2' => 'o','%C3%B3' => 'o','%C3%B4' => 'o','%C3%B5' => 'o','%C3%B6' => 'o',
855
-		'%C3%B9' => 'u','%C3%BA' => 'u','%C3%BB' => 'u','%C3%BC' => 'u',
854
+		'%C3%B2' => 'o', '%C3%B3' => 'o', '%C3%B4' => 'o', '%C3%B5' => 'o', '%C3%B6' => 'o',
855
+		'%C3%B9' => 'u', '%C3%BA' => 'u', '%C3%BB' => 'u', '%C3%BC' => 'u',
856 856
 		'%C3%BF' => 'y'
857 857
 		);
858
-		$string=strtr($string, $replacements);
858
+		$string = strtr($string, $replacements);
859 859
 		return rawurldecode($string);
860 860
 	}
861 861
 	else
@@ -892,14 +892,14 @@  discard block
 block discarded – undo
892 892
  *
893 893
  * 	@see    		dol_sanitizeFilename, dol_string_unaccent
894 894
  */
895
-function dol_string_nospecial($str,$newstr='_',$badcharstoreplace='')
895
+function dol_string_nospecial($str, $newstr = '_', $badcharstoreplace = '')
896 896
 {
897
-	$forbidden_chars_to_replace=array(" ", "'", "/", "\\", ":", "*", "?", "\"", "<", ">", "|", "[", "]", ",", ";", "=", '°');  // more complete than dol_sanitizeFileName
898
-	$forbidden_chars_to_remove=array();
899
-	if (is_array($badcharstoreplace)) $forbidden_chars_to_replace=$badcharstoreplace;
897
+	$forbidden_chars_to_replace = array(" ", "'", "/", "\\", ":", "*", "?", "\"", "<", ">", "|", "[", "]", ",", ";", "=", '°'); // more complete than dol_sanitizeFileName
898
+	$forbidden_chars_to_remove = array();
899
+	if (is_array($badcharstoreplace)) $forbidden_chars_to_replace = $badcharstoreplace;
900 900
 	//$forbidden_chars_to_remove=array("(",")");
901 901
 
902
-	return str_replace($forbidden_chars_to_replace,$newstr,str_replace($forbidden_chars_to_remove,"",$str));
902
+	return str_replace($forbidden_chars_to_replace, $newstr, str_replace($forbidden_chars_to_remove, "", $str));
903 903
 }
904 904
 
905 905
 
@@ -911,7 +911,7 @@  discard block
 block discarded – undo
911 911
  */
912 912
 function dolEscapeXML($string)
913 913
 {
914
-	return strtr($string, array('\''=>'&apos;','"'=>'&quot;','&'=>'&amp;','<'=>'&lt;','>'=>'&gt;'));
914
+	return strtr($string, array('\''=>'&apos;', '"'=>'&quot;', '&'=>'&amp;', '<'=>'&lt;', '>'=>'&gt;'));
915 915
 }
916 916
 
917 917
 /**
@@ -922,16 +922,16 @@  discard block
 block discarded – undo
922 922
  *  @param		int		$noescapebackslashn	0=Escape also \n. 1=Do not escape \n.
923 923
  *  @return     string     		 				Escaped string. Both ' and " are escaped into ' if they are escaped.
924 924
  */
925
-function dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
925
+function dol_escape_js($stringtoescape, $mode = 0, $noescapebackslashn = 0)
926 926
 {
927 927
 	// escape quotes and backslashes, newlines, etc.
928
-	$substitjs=array("&#039;"=>"\\'","\r"=>'\\r');
928
+	$substitjs = array("&#039;"=>"\\'", "\r"=>'\\r');
929 929
 	//$substitjs['</']='<\/';	// We removed this. Should be useless.
930
-	if (empty($noescapebackslashn)) { $substitjs["\n"]='\\n'; $substitjs['\\']='\\\\'; }
931
-	if (empty($mode)) { $substitjs["'"]="\\'"; $substitjs['"']="\\'"; }
932
-	else if ($mode == 1) $substitjs["'"]="\\'";
933
-	else if ($mode == 2) { $substitjs['"']='\\"'; }
934
-	else if ($mode == 3) { $substitjs["'"]="\\'"; $substitjs['"']="\\\""; }
930
+	if (empty($noescapebackslashn)) { $substitjs["\n"] = '\\n'; $substitjs['\\'] = '\\\\'; }
931
+	if (empty($mode)) { $substitjs["'"] = "\\'"; $substitjs['"'] = "\\'"; }
932
+	else if ($mode == 1) $substitjs["'"] = "\\'";
933
+	else if ($mode == 2) { $substitjs['"'] = '\\"'; }
934
+	else if ($mode == 3) { $substitjs["'"] = "\\'"; $substitjs['"'] = "\\\""; }
935 935
 	return strtr($stringtoescape, $substitjs);
936 936
 }
937 937
 
@@ -945,13 +945,13 @@  discard block
 block discarded – undo
945 945
  *  @return     string     				 		Escaped string
946 946
  *  @see		dol_string_nohtmltag
947 947
  */
948
-function dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0)
948
+function dol_escape_htmltag($stringtoescape, $keepb = 0, $keepn = 0)
949 949
 {
950 950
 	// escape quotes and backslashes, newlines, etc.
951
-	$tmp=html_entity_decode($stringtoescape, ENT_COMPAT, 'UTF-8');		// TODO Use htmlspecialchars_decode instead, that make only required change for html tags
952
-	if (! $keepb) $tmp=strtr($tmp, array("<b>"=>'','</b>'=>''));
953
-	if (! $keepn) $tmp=strtr($tmp, array("\r"=>'\\r',"\n"=>'\\n'));
954
-	return htmlentities($tmp, ENT_COMPAT, 'UTF-8');						// TODO Use htmlspecialchars instead, that make only required change for html tags
951
+	$tmp = html_entity_decode($stringtoescape, ENT_COMPAT, 'UTF-8'); // TODO Use htmlspecialchars_decode instead, that make only required change for html tags
952
+	if (!$keepb) $tmp = strtr($tmp, array("<b>"=>'', '</b>'=>''));
953
+	if (!$keepn) $tmp = strtr($tmp, array("\r"=>'\\r', "\n"=>'\\n'));
954
+	return htmlentities($tmp, ENT_COMPAT, 'UTF-8'); // TODO Use htmlspecialchars instead, that make only required change for html tags
955 955
 }
956 956
 
957 957
 
@@ -998,14 +998,14 @@  discard block
 block discarded – undo
998 998
  *  @param	string		$restricttologhandler	Output log only for this log handler
999 999
  *  @return	void
1000 1000
  */
1001
-function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename='', $restricttologhandler='')
1001
+function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename = '', $restricttologhandler = '')
1002 1002
 {
1003 1003
 	global $conf, $user;
1004 1004
 
1005 1005
 	// If syslog module enabled
1006 1006
 	if (empty($conf->syslog->enabled)) return;
1007 1007
 
1008
-	if (! empty($message))
1008
+	if (!empty($message))
1009 1009
 	{
1010 1010
 		// Test log level
1011 1011
 		$logLevels = array(LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG);
@@ -1016,14 +1016,14 @@  discard block
 block discarded – undo
1016 1016
 		if ($level > $conf->global->SYSLOG_LEVEL) return;
1017 1017
 
1018 1018
 		// If adding log inside HTML page is required
1019
-		if (! empty($_REQUEST['logtohtml']) && (! empty($conf->global->MAIN_ENABLE_LOG_TO_HTML) || ! empty($conf->global->MAIN_LOGTOHTML)))   // MAIN_LOGTOHTML kept for backward compatibility
1019
+		if (!empty($_REQUEST['logtohtml']) && (!empty($conf->global->MAIN_ENABLE_LOG_TO_HTML) || !empty($conf->global->MAIN_LOGTOHTML)))   // MAIN_LOGTOHTML kept for backward compatibility
1020 1020
 		{
1021
-			$conf->logbuffer[] = dol_print_date(time(),"%Y-%m-%d %H:%M:%S")." ".$message;
1021
+			$conf->logbuffer[] = dol_print_date(time(), "%Y-%m-%d %H:%M:%S")." ".$message;
1022 1022
 		}
1023 1023
 
1024 1024
 		//TODO: Remove this. MAIN_ENABLE_LOG_INLINE_HTML should be deprecated and use a log handler dedicated to HTML output
1025 1025
 		// If enable html log tag enabled and url parameter log defined, we show output log on HTML comments
1026
-		if (! empty($conf->global->MAIN_ENABLE_LOG_INLINE_HTML) && ! empty($_GET["log"]))
1026
+		if (!empty($conf->global->MAIN_ENABLE_LOG_INLINE_HTML) && !empty($_GET["log"]))
1027 1027
 		{
1028 1028
 			print "\n\n<!-- Log start\n";
1029 1029
 			print $message."\n";
@@ -1032,32 +1032,32 @@  discard block
 block discarded – undo
1032 1032
 
1033 1033
 		$data = array(
1034 1034
 			'message' => $message,
1035
-			'script' => (isset($_SERVER['PHP_SELF'])? basename($_SERVER['PHP_SELF'],'.php') : false),
1035
+			'script' => (isset($_SERVER['PHP_SELF']) ? basename($_SERVER['PHP_SELF'], '.php') : false),
1036 1036
 			'level' => $level,
1037 1037
 			'user' => ((is_object($user) && $user->id) ? $user->login : false),
1038 1038
 			'ip' => false
1039 1039
 		);
1040 1040
 
1041 1041
 		// This is when server run behind a reverse proxy
1042
-		if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) $data['ip'] = $_SERVER['HTTP_X_FORWARDED_FOR'].(empty($_SERVER["REMOTE_ADDR"])?'':'->'.$_SERVER['REMOTE_ADDR']);
1042
+		if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) $data['ip'] = $_SERVER['HTTP_X_FORWARDED_FOR'].(empty($_SERVER["REMOTE_ADDR"]) ? '' : '->'.$_SERVER['REMOTE_ADDR']);
1043 1043
 		// This is when server run normally on a server
1044
-		else if (! empty($_SERVER["REMOTE_ADDR"])) $data['ip'] = $_SERVER['REMOTE_ADDR'];
1044
+		else if (!empty($_SERVER["REMOTE_ADDR"])) $data['ip'] = $_SERVER['REMOTE_ADDR'];
1045 1045
 		// This is when PHP session is ran inside a web server but not inside a client request (example: init code of apache)
1046
-		else if (! empty($_SERVER['SERVER_ADDR'])) $data['ip'] = $_SERVER['SERVER_ADDR'];
1046
+		else if (!empty($_SERVER['SERVER_ADDR'])) $data['ip'] = $_SERVER['SERVER_ADDR'];
1047 1047
 		// This is when PHP session is ran outside a web server, like from Windows command line (Not always defined, but useful if OS defined it).
1048
-		else if (! empty($_SERVER['COMPUTERNAME'])) $data['ip'] = $_SERVER['COMPUTERNAME'].(empty($_SERVER['USERNAME'])?'':'@'.$_SERVER['USERNAME']);
1048
+		else if (!empty($_SERVER['COMPUTERNAME'])) $data['ip'] = $_SERVER['COMPUTERNAME'].(empty($_SERVER['USERNAME']) ? '' : '@'.$_SERVER['USERNAME']);
1049 1049
 		// This is when PHP session is ran outside a web server, like from Linux command line (Not always defined, but usefull if OS defined it).
1050
-		else if (! empty($_SERVER['LOGNAME'])) $data['ip'] = '???@'.$_SERVER['LOGNAME'];
1050
+		else if (!empty($_SERVER['LOGNAME'])) $data['ip'] = '???@'.$_SERVER['LOGNAME'];
1051 1051
 		// Loop on each log handler and send output
1052 1052
 		foreach ($conf->loghandlers as $loghandlerinstance)
1053 1053
 		{
1054 1054
 			if ($restricttologhandler && $loghandlerinstance->code != $restricttologhandler) continue;
1055
-			$loghandlerinstance->export($data,$suffixinfilename);
1055
+			$loghandlerinstance->export($data, $suffixinfilename);
1056 1056
 		}
1057 1057
 		unset($data);
1058 1058
 	}
1059 1059
 
1060
-	if (! empty($ident))
1060
+	if (!empty($ident))
1061 1061
 	{
1062 1062
 		foreach ($conf->loghandlers as $loghandlerinstance)
1063 1063
 		{
@@ -1079,7 +1079,7 @@  discard block
 block discarded – undo
1079 1079
  *  @param	string	$morehtmlright		Add more html content on right of tabs title
1080 1080
  * 	@return	void
1081 1081
  */
1082
-function dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
1082
+function dol_fiche_head($links = array(), $active = '0', $title = '', $notab = 0, $picto = '', $pictoisfullpath = 0, $morehtmlright = '')
1083 1083
 {
1084 1084
 	print dol_get_fiche_head($links, $active, $title, $notab, $picto, $pictoisfullpath, $morehtmlright);
1085 1085
 }
@@ -1096,153 +1096,153 @@  discard block
 block discarded – undo
1096 1096
  *  @param	string	$morehtmlright		Add more html content on right of tabs title
1097 1097
  * 	@return	string
1098 1098
  */
1099
-function dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
1099
+function dol_get_fiche_head($links = array(), $active = '', $title = '', $notab = 0, $picto = '', $pictoisfullpath = 0, $morehtmlright = '')
1100 1100
 {
1101 1101
 	global $conf, $langs, $hookmanager;
1102 1102
 
1103
-	$out="\n".'<div class="tabs" data-role="controlgroup" data-type="horizontal">'."\n";
1103
+	$out = "\n".'<div class="tabs" data-role="controlgroup" data-type="horizontal">'."\n";
1104 1104
 
1105
-	if ($morehtmlright) $out.='<div class="inline-block floatright tabsElem">'.$morehtmlright.'</div>';	// Output right area first so when space is missing, text is in front of tabs and not under.
1105
+	if ($morehtmlright) $out .= '<div class="inline-block floatright tabsElem">'.$morehtmlright.'</div>'; // Output right area first so when space is missing, text is in front of tabs and not under.
1106 1106
 
1107 1107
 	// Show title
1108
-	$showtitle=1;
1109
-	if (! empty($conf->dol_optimize_smallscreen)) $showtitle=0;
1110
-	if (! empty($title) && $showtitle)
1108
+	$showtitle = 1;
1109
+	if (!empty($conf->dol_optimize_smallscreen)) $showtitle = 0;
1110
+	if (!empty($title) && $showtitle)
1111 1111
 	{
1112
-		$limittitle=30;
1113
-		$out.='<a class="tabTitle">';
1114
-		if ($picto) $out.=img_picto($title,($pictoisfullpath?'':'object_').$picto,'',$pictoisfullpath).' ';
1115
-		$out.='<span class="tabTitleText">'.dol_trunc($title,$limittitle).'</span>';
1116
-		$out.='</a>';
1112
+		$limittitle = 30;
1113
+		$out .= '<a class="tabTitle">';
1114
+		if ($picto) $out .= img_picto($title, ($pictoisfullpath ? '' : 'object_').$picto, '', $pictoisfullpath).' ';
1115
+		$out .= '<span class="tabTitleText">'.dol_trunc($title, $limittitle).'</span>';
1116
+		$out .= '</a>';
1117 1117
 	}
1118 1118
 
1119 1119
 	// Define max of key (max may be higher than sizeof because of hole due to module disabling some tabs).
1120
-	$maxkey=-1;
1121
-	if (is_array($links) && ! empty($links))
1120
+	$maxkey = -1;
1121
+	if (is_array($links) && !empty($links))
1122 1122
 	{
1123
-		$keys=array_keys($links);
1124
-		if (count($keys)) $maxkey=max($keys);
1123
+		$keys = array_keys($links);
1124
+		if (count($keys)) $maxkey = max($keys);
1125 1125
 	}
1126 1126
 
1127
-	if (! empty($conf->dol_optimize_smallscreen)) $conf->global->MAIN_MAXTABS_IN_CARD=2;
1127
+	if (!empty($conf->dol_optimize_smallscreen)) $conf->global->MAIN_MAXTABS_IN_CARD = 2;
1128 1128
 
1129 1129
 	// Show tabs
1130
-	$bactive=false;
1130
+	$bactive = false;
1131 1131
 	// if =0 we don't use the feature
1132
-	$limittoshow=(empty($conf->global->MAIN_MAXTABS_IN_CARD)?99:$conf->global->MAIN_MAXTABS_IN_CARD);
1133
-	$displaytab=0;
1134
-	$nbintab=0;
1135
-	$popuptab=0; $outmore='';
1136
-	for ($i = 0 ; $i <= $maxkey ; $i++)
1132
+	$limittoshow = (empty($conf->global->MAIN_MAXTABS_IN_CARD) ? 99 : $conf->global->MAIN_MAXTABS_IN_CARD);
1133
+	$displaytab = 0;
1134
+	$nbintab = 0;
1135
+	$popuptab = 0; $outmore = '';
1136
+	for ($i = 0; $i <= $maxkey; $i++)
1137 1137
 	{
1138
-		if ((is_numeric($active) && $i == $active) || (! empty($links[$i][2]) && ! is_numeric($active) && $active == $links[$i][2]))
1138
+		if ((is_numeric($active) && $i == $active) || (!empty($links[$i][2]) && !is_numeric($active) && $active == $links[$i][2]))
1139 1139
 		{
1140 1140
 			// If active tab is already present
1141 1141
 			if ($i >= $limittoshow) $limittoshow--;
1142 1142
 		}
1143 1143
 	}
1144 1144
 
1145
-	for ($i = 0 ; $i <= $maxkey ; $i++)
1145
+	for ($i = 0; $i <= $maxkey; $i++)
1146 1146
 	{
1147
-		if ((is_numeric($active) && $i == $active) || (! empty($links[$i][2]) && ! is_numeric($active) && $active == $links[$i][2]))
1147
+		if ((is_numeric($active) && $i == $active) || (!empty($links[$i][2]) && !is_numeric($active) && $active == $links[$i][2]))
1148 1148
 		{
1149
-			$isactive=true;
1150
-			$bactive=true;
1149
+			$isactive = true;
1150
+			$bactive = true;
1151 1151
 		}
1152 1152
 		else
1153 1153
 		{
1154
-			$isactive=false;
1154
+			$isactive = false;
1155 1155
 		}
1156 1156
 
1157 1157
 		if ($i < $limittoshow || $isactive)
1158 1158
 		{
1159
-			$out.='<div class="inline-block tabsElem'.($isactive ? ' tabsElemActive' : '').((! $isactive && ! empty($conf->global->MAIN_HIDE_INACTIVETAB_ON_PRINT))?' hideonprint':'').'"><!-- id tab = '.(empty($links[$i][2])?'':$links[$i][2]).' -->';
1159
+			$out .= '<div class="inline-block tabsElem'.($isactive ? ' tabsElemActive' : '').((!$isactive && !empty($conf->global->MAIN_HIDE_INACTIVETAB_ON_PRINT)) ? ' hideonprint' : '').'"><!-- id tab = '.(empty($links[$i][2]) ? '' : $links[$i][2]).' -->';
1160 1160
 			if (isset($links[$i][2]) && $links[$i][2] == 'image')
1161 1161
 			{
1162 1162
 				if (!empty($links[$i][0]))
1163 1163
 				{
1164
-					$out.='<a class="tabimage" href="'.$links[$i][0].'">'.$links[$i][1].'</a>'."\n";
1164
+					$out .= '<a class="tabimage" href="'.$links[$i][0].'">'.$links[$i][1].'</a>'."\n";
1165 1165
 				}
1166 1166
 				else
1167 1167
 				{
1168
-					$out.='<span class="tabspan">'.$links[$i][1].'</span>'."\n";
1168
+					$out .= '<span class="tabspan">'.$links[$i][1].'</span>'."\n";
1169 1169
 				}
1170 1170
 			}
1171
-			else if (! empty($links[$i][1]))
1171
+			else if (!empty($links[$i][1]))
1172 1172
 			{
1173 1173
 				//print "x $i $active ".$links[$i][2]." z";
1174 1174
 				if ($isactive)
1175 1175
 				{
1176
-					$out.='<a'.(! empty($links[$i][2])?' id="'.$links[$i][2].'"':'').' class="tabactive tab inline-block" href="'.$links[$i][0].'">';
1177
-					$out.=$links[$i][1];
1178
-					$out.='</a>'."\n";
1176
+					$out .= '<a'.(!empty($links[$i][2]) ? ' id="'.$links[$i][2].'"' : '').' class="tabactive tab inline-block" href="'.$links[$i][0].'">';
1177
+					$out .= $links[$i][1];
1178
+					$out .= '</a>'."\n";
1179 1179
 				}
1180 1180
 				else
1181 1181
 				{
1182
-					$out.='<a'.(! empty($links[$i][2])?' id="'.$links[$i][2].'"':'').' class="tabunactive tab inline-block" href="'.$links[$i][0].'">';
1183
-					$out.=$links[$i][1];
1184
-					$out.='</a>'."\n";
1182
+					$out .= '<a'.(!empty($links[$i][2]) ? ' id="'.$links[$i][2].'"' : '').' class="tabunactive tab inline-block" href="'.$links[$i][0].'">';
1183
+					$out .= $links[$i][1];
1184
+					$out .= '</a>'."\n";
1185 1185
 				}
1186 1186
 			}
1187
-			$out.='</div>';
1187
+			$out .= '</div>';
1188 1188
 		}
1189 1189
 		else
1190 1190
 		{
1191 1191
 			// The popup with the other tabs
1192
-			if (! $popuptab)
1192
+			if (!$popuptab)
1193 1193
 			{
1194
-				$popuptab=1;
1195
-				$outmore.='<div class="popuptabset wordwrap">';	// The css used to hide/show popup
1194
+				$popuptab = 1;
1195
+				$outmore .= '<div class="popuptabset wordwrap">'; // The css used to hide/show popup
1196 1196
 			}
1197
-			$outmore.='<div class="popuptab wordwrap" style="display:inherit;">';
1197
+			$outmore .= '<div class="popuptab wordwrap" style="display:inherit;">';
1198 1198
 			if (isset($links[$i][2]) && $links[$i][2] == 'image')
1199 1199
 			{
1200 1200
 				if (!empty($links[$i][0]))
1201
-					$outmore.='<a class="tabimage" href="'.$links[$i][0].'">'.$links[$i][1].'</a>'."\n";
1201
+					$outmore .= '<a class="tabimage" href="'.$links[$i][0].'">'.$links[$i][1].'</a>'."\n";
1202 1202
 				else
1203
-					$outmore.='<span class="tabspan">'.$links[$i][1].'</span>'."\n";
1203
+					$outmore .= '<span class="tabspan">'.$links[$i][1].'</span>'."\n";
1204 1204
 
1205 1205
 			}
1206
-			else if (! empty($links[$i][1]))
1206
+			else if (!empty($links[$i][1]))
1207 1207
 			{
1208
-				$outmore.='<a'.(! empty($links[$i][2])?' id="'.$links[$i][2].'"':'').' class="wordwrap inline-block" href="'.$links[$i][0].'">';
1209
-				$outmore.=preg_replace('/([a-z])\/([a-z])/i', '\\1 / \\2', $links[$i][1]);	// Replace x/y with x / y to allow wrap on long composed texts.
1210
-				$outmore.='</a>'."\n";
1208
+				$outmore .= '<a'.(!empty($links[$i][2]) ? ' id="'.$links[$i][2].'"' : '').' class="wordwrap inline-block" href="'.$links[$i][0].'">';
1209
+				$outmore .= preg_replace('/([a-z])\/([a-z])/i', '\\1 / \\2', $links[$i][1]); // Replace x/y with x / y to allow wrap on long composed texts.
1210
+				$outmore .= '</a>'."\n";
1211 1211
 			}
1212
-			$outmore.='</div>';
1212
+			$outmore .= '</div>';
1213 1213
 
1214 1214
 			$nbintab++;
1215 1215
 		}
1216
-		$displaytab=$i;
1216
+		$displaytab = $i;
1217 1217
 	}
1218
-	if ($popuptab) $outmore.='</div>';
1218
+	if ($popuptab) $outmore .= '</div>';
1219 1219
 
1220 1220
 	if ($displaytab > $limittoshow)
1221 1221
 	{
1222
-		$left=($langs->trans("DIRECTION") == 'rtl'?'right':'left');
1223
-		$right=($langs->trans("DIRECTION") == 'rtl'?'left':'right');
1222
+		$left = ($langs->trans("DIRECTION") == 'rtl' ? 'right' : 'left');
1223
+		$right = ($langs->trans("DIRECTION") == 'rtl' ? 'left' : 'right');
1224 1224
 
1225
-		$tabsname=str_replace("@", "", $picto);
1226
-		$out.='<div id="moretabs'.$tabsname.'" class="inline-block tabsElem">';
1227
-		$out.='<a href="#" class="tab moretab inline-block tabunactive">'.$langs->trans("More").'... ('.$nbintab.')</a>';
1228
-		$out.='<div id="moretabsList'.$tabsname.'" style="position: absolute; '.$left.': -999em; text-align: '.$left.'; margin:0px; padding:2px">';
1229
-		$out.=$outmore;
1230
-		$out.='</div>';
1231
-		$out.='<div></div>';
1232
-		$out.="</div>\n";
1225
+		$tabsname = str_replace("@", "", $picto);
1226
+		$out .= '<div id="moretabs'.$tabsname.'" class="inline-block tabsElem">';
1227
+		$out .= '<a href="#" class="tab moretab inline-block tabunactive">'.$langs->trans("More").'... ('.$nbintab.')</a>';
1228
+		$out .= '<div id="moretabsList'.$tabsname.'" style="position: absolute; '.$left.': -999em; text-align: '.$left.'; margin:0px; padding:2px">';
1229
+		$out .= $outmore;
1230
+		$out .= '</div>';
1231
+		$out .= '<div></div>';
1232
+		$out .= "</div>\n";
1233 1233
 
1234
-		$out.="<script>";
1235
-		$out.="$('#moretabs".$tabsname."').mouseenter( function() { console.log('mouseenter ".$left."'); $('#moretabsList".$tabsname."').css('".$left."','auto');});";
1236
-		$out.="$('#moretabs".$tabsname."').mouseleave( function() { console.log('mouseleave ".$left."'); $('#moretabsList".$tabsname."').css('".$left."','-999em');});";
1237
-		$out.="</script>";
1234
+		$out .= "<script>";
1235
+		$out .= "$('#moretabs".$tabsname."').mouseenter( function() { console.log('mouseenter ".$left."'); $('#moretabsList".$tabsname."').css('".$left."','auto');});";
1236
+		$out .= "$('#moretabs".$tabsname."').mouseleave( function() { console.log('mouseleave ".$left."'); $('#moretabsList".$tabsname."').css('".$left."','-999em');});";
1237
+		$out .= "</script>";
1238 1238
 	}
1239 1239
 
1240
-	$out.="</div>\n";
1240
+	$out .= "</div>\n";
1241 1241
 
1242
-	if (! $notab || $notab == -1) $out.="\n".'<div class="tabBar'.($notab == -1 ? '' : ' tabBarWithBottom').'">'."\n";
1242
+	if (!$notab || $notab == -1) $out .= "\n".'<div class="tabBar'.($notab == -1 ? '' : ' tabBarWithBottom').'">'."\n";
1243 1243
 
1244
-	$parameters=array('tabname' => $active, 'out' => $out);
1245
-	$reshook=$hookmanager->executeHooks('printTabsHead',$parameters);	// This hook usage is called just before output the head of tabs. Take also a look at "completeTabsHead"
1244
+	$parameters = array('tabname' => $active, 'out' => $out);
1245
+	$reshook = $hookmanager->executeHooks('printTabsHead', $parameters); // This hook usage is called just before output the head of tabs. Take also a look at "completeTabsHead"
1246 1246
 	if ($reshook > 0)
1247 1247
 	{
1248 1248
 		$out = $hookmanager->resPrint;
@@ -1257,7 +1257,7 @@  discard block
 block discarded – undo
1257 1257
  *  @param	int		$notab       -1 or 0=Add tab footer, 1=no tab footer
1258 1258
  *  @return	void
1259 1259
  */
1260
-function dol_fiche_end($notab=0)
1260
+function dol_fiche_end($notab = 0)
1261 1261
 {
1262 1262
 	print dol_get_fiche_end($notab);
1263 1263
 }
@@ -1268,9 +1268,9 @@  discard block
 block discarded – undo
1268 1268
  *	@param  int		$notab		-1 or 0=Add tab footer, 1=no tab footer
1269 1269
  *  @return	string
1270 1270
  */
1271
-function dol_get_fiche_end($notab=0)
1271
+function dol_get_fiche_end($notab = 0)
1272 1272
 {
1273
-	if (! $notab || $notab == -1) return "\n</div>\n";
1273
+	if (!$notab || $notab == -1) return "\n</div>\n";
1274 1274
 	else return '';
1275 1275
 }
1276 1276
 
@@ -1293,53 +1293,53 @@  discard block
 block discarded – undo
1293 1293
  *	@param	string	$morehtmlright	More html code to show before navigation arrows
1294 1294
  *  @return	void
1295 1295
  */
1296
-function dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
1296
+function dol_banner_tab($object, $paramid, $morehtml = '', $shownav = 1, $fieldid = 'rowid', $fieldref = 'ref', $morehtmlref = '', $moreparam = '', $nodbprefix = 0, $morehtmlleft = '', $morehtmlstatus = '', $onlybanner = 0, $morehtmlright = '')
1297 1297
 {
1298 1298
 	global $conf, $form, $user, $langs;
1299 1299
 
1300 1300
 	$error = 0;
1301 1301
 
1302
-	$maxvisiblephotos=1;
1303
-	$showimage=1;
1304
-	$showbarcode=empty($conf->barcode->enabled)?0:($object->barcode?1:0);
1305
-	if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) $showbarcode=0;
1306
-	$modulepart='unknown';
1302
+	$maxvisiblephotos = 1;
1303
+	$showimage = 1;
1304
+	$showbarcode = empty($conf->barcode->enabled) ? 0 : ($object->barcode ? 1 : 0);
1305
+	if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) $showbarcode = 0;
1306
+	$modulepart = 'unknown';
1307 1307
 
1308
-	if ($object->element == 'societe')         $modulepart='societe';
1309
-	if ($object->element == 'contact')         $modulepart='contact';
1310
-	if ($object->element == 'member')          $modulepart='memberphoto';
1311
-	if ($object->element == 'user')            $modulepart='userphoto';
1312
-	if ($object->element == 'product')         $modulepart='product';
1308
+	if ($object->element == 'societe')         $modulepart = 'societe';
1309
+	if ($object->element == 'contact')         $modulepart = 'contact';
1310
+	if ($object->element == 'member')          $modulepart = 'memberphoto';
1311
+	if ($object->element == 'user')            $modulepart = 'userphoto';
1312
+	if ($object->element == 'product')         $modulepart = 'product';
1313 1313
 
1314 1314
 	if (class_exists("Imagick"))
1315 1315
 	{
1316
-		if ($object->element == 'propal')            $modulepart='propal';
1317
-		if ($object->element == 'commande')          $modulepart='commande';
1318
-		if ($object->element == 'facture')           $modulepart='facture';
1319
-		if ($object->element == 'fichinter')         $modulepart='ficheinter';
1320
-		if ($object->element == 'contrat')           $modulepart='contract';
1321
-		if ($object->element == 'supplier_proposal') $modulepart='supplier_proposal';
1322
-		if ($object->element == 'order_supplier')    $modulepart='supplier_order';
1323
-		if ($object->element == 'invoice_supplier')  $modulepart='supplier_invoice';
1324
-		if ($object->element == 'expensereport')     $modulepart='expensereport';
1316
+		if ($object->element == 'propal')            $modulepart = 'propal';
1317
+		if ($object->element == 'commande')          $modulepart = 'commande';
1318
+		if ($object->element == 'facture')           $modulepart = 'facture';
1319
+		if ($object->element == 'fichinter')         $modulepart = 'ficheinter';
1320
+		if ($object->element == 'contrat')           $modulepart = 'contract';
1321
+		if ($object->element == 'supplier_proposal') $modulepart = 'supplier_proposal';
1322
+		if ($object->element == 'order_supplier')    $modulepart = 'supplier_order';
1323
+		if ($object->element == 'invoice_supplier')  $modulepart = 'supplier_invoice';
1324
+		if ($object->element == 'expensereport')     $modulepart = 'expensereport';
1325 1325
 	}
1326 1326
 
1327 1327
 	if ($object->element == 'product')
1328 1328
 	{
1329
-		$width=80; $cssclass='photoref';
1330
-		$showimage=$object->is_photo_available($conf->product->multidir_output[$object->entity]);
1331
-		$maxvisiblephotos=(isset($conf->global->PRODUCT_MAX_VISIBLE_PHOTO)?$conf->global->PRODUCT_MAX_VISIBLE_PHOTO:5);
1332
-		if ($conf->browser->phone) $maxvisiblephotos=1;
1333
-		if ($showimage) $morehtmlleft.='<div class="floatleft inline-block valignmiddle divphotoref">'.$object->show_photos($conf->product->multidir_output[$object->entity],'small',$maxvisiblephotos,0,0,0,$width,0).'</div>';
1329
+		$width = 80; $cssclass = 'photoref';
1330
+		$showimage = $object->is_photo_available($conf->product->multidir_output[$object->entity]);
1331
+		$maxvisiblephotos = (isset($conf->global->PRODUCT_MAX_VISIBLE_PHOTO) ? $conf->global->PRODUCT_MAX_VISIBLE_PHOTO : 5);
1332
+		if ($conf->browser->phone) $maxvisiblephotos = 1;
1333
+		if ($showimage) $morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref">'.$object->show_photos($conf->product->multidir_output[$object->entity], 'small', $maxvisiblephotos, 0, 0, 0, $width, 0).'</div>';
1334 1334
 		else
1335 1335
 		{
1336 1336
 			if (!empty($conf->global->PRODUCT_NODISPLAYIFNOPHOTO)) {
1337
-				$nophoto='';
1338
-				$morehtmlleft.='<div class="floatleft inline-block valignmiddle divphotoref"></div>';
1337
+				$nophoto = '';
1338
+				$morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref"></div>';
1339 1339
 			}
1340 1340
 			//elseif ($conf->browser->layout != 'phone') {    // Show no photo link
1341
-				$nophoto='/public/theme/common/nophoto.png';
1342
-				$morehtmlleft.='<div class="floatleft inline-block valignmiddle divphotoref"><img class="photo'.$modulepart.($cssclass?' '.$cssclass:'').'" alt="No photo" border="0"'.($width?' width="'.$width.'"':'').' src="'.DOL_URL_ROOT.$nophoto.'"></div>';
1341
+				$nophoto = '/public/theme/common/nophoto.png';
1342
+				$morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref"><img class="photo'.$modulepart.($cssclass ? ' '.$cssclass : '').'" alt="No photo" border="0"'.($width ? ' width="'.$width.'"' : '').' src="'.DOL_URL_ROOT.$nophoto.'"></div>';
1343 1343
 			//}
1344 1344
 		}
1345 1345
 	}
@@ -1349,28 +1349,28 @@  discard block
 block discarded – undo
1349 1349
 		{
1350 1350
 			if ($modulepart != 'unknown')
1351 1351
 			{
1352
-				$phototoshow='';
1352
+				$phototoshow = '';
1353 1353
 				// Check if a preview file is available
1354 1354
 				if (in_array($modulepart, array('propal', 'commande', 'facture', 'ficheinter', 'contract', 'supplier_order', 'supplier_proposal', 'supplier_invoice', 'expensereport')) && class_exists("Imagick"))
1355 1355
 				{
1356 1356
 					$objectref = dol_sanitizeFileName($object->ref);
1357
-					$dir_output = $conf->$modulepart->dir_output . "/";
1357
+					$dir_output = $conf->$modulepart->dir_output."/";
1358 1358
 					if (in_array($modulepart, array('invoice_supplier', 'supplier_invoice')))
1359 1359
 					{
1360
-						$subdir = get_exdir($object->id, 2, 0, 0, $object, $modulepart).$objectref;		// the objectref dir is not include into get_exdir when used with level=2, so we add it here
1360
+						$subdir = get_exdir($object->id, 2, 0, 0, $object, $modulepart).$objectref; // the objectref dir is not include into get_exdir when used with level=2, so we add it here
1361 1361
 					}
1362 1362
 					else
1363 1363
 					{
1364 1364
 						$subdir = get_exdir($object->id, 0, 0, 0, $object, $modulepart);
1365 1365
 					}
1366 1366
 
1367
-					$filepath = $dir_output . $subdir . "/";
1368
-					$file = $filepath . $objectref . ".pdf";
1367
+					$filepath = $dir_output.$subdir."/";
1368
+					$file = $filepath.$objectref.".pdf";
1369 1369
 					$relativepath = $subdir.'/'.$objectref.'.pdf';
1370 1370
 
1371 1371
 					// Define path to preview pdf file (preview precompiled "file.ext" are "file.ext_preview.png")
1372
-					$fileimage = $file.'_preview.png';              // If PDF has 1 page
1373
-					$fileimagebis = $file.'_preview-0.png';         // If PDF has more than one page
1372
+					$fileimage = $file.'_preview.png'; // If PDF has 1 page
1373
+					$fileimagebis = $file.'_preview-0.png'; // If PDF has more than one page
1374 1374
 					$relativepathimage = $relativepath.'_preview.png';
1375 1375
 
1376 1376
 					// Si fichier PDF existe
@@ -1378,8 +1378,8 @@  discard block
 block discarded – undo
1378 1378
 					{
1379 1379
 						$encfile = urlencode($file);
1380 1380
 						// Conversion du PDF en image png si fichier png non existant
1381
-						if ( (! file_exists($fileimage) || (filemtime($fileimage) < filemtime($file)))
1382
-						  && (! file_exists($fileimagebis) || (filemtime($fileimagebis) < filemtime($file)))
1381
+						if ((!file_exists($fileimage) || (filemtime($fileimage) < filemtime($file)))
1382
+						  && (!file_exists($fileimagebis) || (filemtime($fileimagebis) < filemtime($file)))
1383 1383
 						   )
1384 1384
 						{
1385 1385
 							if (empty($conf->global->MAIN_DISABLE_PDF_THUMBS))		// If you experienc trouble with pdf thumb generation and imagick, you can disable here.
@@ -1389,146 +1389,146 @@  discard block
 block discarded – undo
1389 1389
 							}
1390 1390
 						}
1391 1391
 
1392
-						$heightforphotref=70;
1393
-						if (! empty($conf->dol_optimize_smallscreen)) $heightforphotref=60;
1392
+						$heightforphotref = 70;
1393
+						if (!empty($conf->dol_optimize_smallscreen)) $heightforphotref = 60;
1394 1394
 						// Si fichier png PDF d'1 page trouve
1395 1395
 						if (file_exists($fileimage))
1396 1396
 						{
1397 1397
 							$phototoshow = '<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref">';
1398
-							$phototoshow.= '<img height="'.$heightforphotref.'" class="photo photowithmargin photowithborder" src="'.DOL_URL_ROOT . '/viewimage.php?modulepart=apercu'.$modulepart.'&amp;file='.urlencode($relativepathimage).'">';
1399
-							$phototoshow.= '</div></div>';
1398
+							$phototoshow .= '<img height="'.$heightforphotref.'" class="photo photowithmargin photowithborder" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=apercu'.$modulepart.'&amp;file='.urlencode($relativepathimage).'">';
1399
+							$phototoshow .= '</div></div>';
1400 1400
 						}
1401 1401
 						// Si fichier png PDF de plus d'1 page trouve
1402 1402
 						elseif (file_exists($fileimagebis))
1403 1403
 						{
1404
-							$preview = preg_replace('/\.png/','',$relativepathimage) . "-0.png";
1404
+							$preview = preg_replace('/\.png/', '', $relativepathimage)."-0.png";
1405 1405
 							$phototoshow = '<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref">';
1406
-							$phototoshow.= '<img height="'.$heightforphotref.'" class="photo photowithmargin photowithborder" src="'.DOL_URL_ROOT . '/viewimage.php?modulepart=apercu'.$modulepart.'&amp;file='.urlencode($preview).'"><p>';
1407
-							$phototoshow.= '</div></div>';
1406
+							$phototoshow .= '<img height="'.$heightforphotref.'" class="photo photowithmargin photowithborder" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=apercu'.$modulepart.'&amp;file='.urlencode($preview).'"><p>';
1407
+							$phototoshow .= '</div></div>';
1408 1408
 						}
1409 1409
 					}
1410 1410
 				}
1411
-				else if (! $phototoshow)
1411
+				else if (!$phototoshow)
1412 1412
 				{
1413
-					$phototoshow = $form->showphoto($modulepart,$object,0,0,0,'photoref','small',1,0,$maxvisiblephotos);
1413
+					$phototoshow = $form->showphoto($modulepart, $object, 0, 0, 0, 'photoref', 'small', 1, 0, $maxvisiblephotos);
1414 1414
 				}
1415 1415
 
1416 1416
 				if ($phototoshow)
1417 1417
 				{
1418
-					$morehtmlleft.='<div class="floatleft inline-block valignmiddle divphotoref">';
1419
-					$morehtmlleft.=$phototoshow;
1420
-					$morehtmlleft.='</div>';
1418
+					$morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref">';
1419
+					$morehtmlleft .= $phototoshow;
1420
+					$morehtmlleft .= '</div>';
1421 1421
 				}
1422 1422
 			}
1423 1423
 
1424
-			if (! $phototoshow)      // Show No photo link (picto of pbject)
1424
+			if (!$phototoshow)      // Show No photo link (picto of pbject)
1425 1425
 			{
1426
-				$morehtmlleft.='<div class="floatleft inline-block valignmiddle divphotoref">';
1426
+				$morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref">';
1427 1427
 				if ($object->element == 'action')
1428 1428
 				{
1429
-					$width=80;
1430
-					$cssclass='photorefcenter';
1431
-					$nophoto=img_picto('', 'title_agenda', '', false, 1);
1429
+					$width = 80;
1430
+					$cssclass = 'photorefcenter';
1431
+					$nophoto = img_picto('', 'title_agenda', '', false, 1);
1432 1432
 				}
1433 1433
 				else
1434 1434
 				{
1435
-					$width=14; $cssclass='photorefcenter';
1435
+					$width = 14; $cssclass = 'photorefcenter';
1436 1436
 					$picto = $object->picto;
1437
-					if ($object->element == 'project' && ! $object->public) $picto = 'project'; // instead of projectpub
1438
-					$nophoto=img_picto('', 'object_'.$picto, '', false, 1);
1437
+					if ($object->element == 'project' && !$object->public) $picto = 'project'; // instead of projectpub
1438
+					$nophoto = img_picto('', 'object_'.$picto, '', false, 1);
1439 1439
 				}
1440
-				$morehtmlleft.='<!-- No photo to show -->';
1441
-				$morehtmlleft.='<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref"><img class="photo'.$modulepart.($cssclass?' '.$cssclass:'').'" alt="No photo" border="0"'.($width?' width="'.$width.'"':'').' src="'.$nophoto.'"></div></div>';
1440
+				$morehtmlleft .= '<!-- No photo to show -->';
1441
+				$morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref"><img class="photo'.$modulepart.($cssclass ? ' '.$cssclass : '').'" alt="No photo" border="0"'.($width ? ' width="'.$width.'"' : '').' src="'.$nophoto.'"></div></div>';
1442 1442
 
1443
-				$morehtmlleft.='</div>';
1443
+				$morehtmlleft .= '</div>';
1444 1444
 			}
1445 1445
 		}
1446 1446
 	}
1447 1447
 
1448
-	if ($showbarcode) $morehtmlleft.='<div class="floatleft inline-block valignmiddle divphotoref">'.$form->showbarcode($object).'</div>';
1448
+	if ($showbarcode) $morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref">'.$form->showbarcode($object).'</div>';
1449 1449
 
1450 1450
 	if ($object->element == 'societe')
1451 1451
 	{
1452
-		if (! empty($conf->use_javascript_ajax) && $user->rights->societe->creer && ! empty($conf->global->MAIN_DIRECT_STATUS_UPDATE))
1452
+		if (!empty($conf->use_javascript_ajax) && $user->rights->societe->creer && !empty($conf->global->MAIN_DIRECT_STATUS_UPDATE))
1453 1453
 		{
1454
-		   	$morehtmlstatus.=ajax_object_onoff($object, 'status', 'status', 'InActivity', 'ActivityCeased');
1454
+		   	$morehtmlstatus .= ajax_object_onoff($object, 'status', 'status', 'InActivity', 'ActivityCeased');
1455 1455
 		}
1456 1456
 		else {
1457
-			$morehtmlstatus.=$object->getLibStatut(6);
1457
+			$morehtmlstatus .= $object->getLibStatut(6);
1458 1458
 		}
1459 1459
 	}
1460 1460
 	elseif ($object->element == 'product')
1461 1461
 	{
1462 1462
 		//$morehtmlstatus.=$langs->trans("Status").' ('.$langs->trans("Sell").') ';
1463
-		if (! empty($conf->use_javascript_ajax) && $user->rights->produit->creer && ! empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) {
1464
-			$morehtmlstatus.=ajax_object_onoff($object, 'status', 'tosell', 'ProductStatusOnSell', 'ProductStatusNotOnSell');
1463
+		if (!empty($conf->use_javascript_ajax) && $user->rights->produit->creer && !empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) {
1464
+			$morehtmlstatus .= ajax_object_onoff($object, 'status', 'tosell', 'ProductStatusOnSell', 'ProductStatusNotOnSell');
1465 1465
 		} else {
1466
-			$morehtmlstatus.='<span class="statusrefsell">'.$object->getLibStatut(5,0).'</span>';
1466
+			$morehtmlstatus .= '<span class="statusrefsell">'.$object->getLibStatut(5, 0).'</span>';
1467 1467
 		}
1468
-		$morehtmlstatus.=' &nbsp; ';
1468
+		$morehtmlstatus .= ' &nbsp; ';
1469 1469
 		//$morehtmlstatus.=$langs->trans("Status").' ('.$langs->trans("Buy").') ';
1470
-		if (! empty($conf->use_javascript_ajax) && $user->rights->produit->creer && ! empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) {
1471
-			$morehtmlstatus.=ajax_object_onoff($object, 'status_buy', 'tobuy', 'ProductStatusOnBuy', 'ProductStatusNotOnBuy');
1470
+		if (!empty($conf->use_javascript_ajax) && $user->rights->produit->creer && !empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) {
1471
+			$morehtmlstatus .= ajax_object_onoff($object, 'status_buy', 'tobuy', 'ProductStatusOnBuy', 'ProductStatusNotOnBuy');
1472 1472
 		} else {
1473
-			$morehtmlstatus.='<span class="statusrefbuy">'.$object->getLibStatut(5,1).'</span>';
1473
+			$morehtmlstatus .= '<span class="statusrefbuy">'.$object->getLibStatut(5, 1).'</span>';
1474 1474
 		}
1475 1475
 	}
1476 1476
 	elseif (in_array($object->element, array('facture', 'invoice', 'invoice_supplier', 'chargesociales', 'loan')))
1477 1477
 	{
1478
-		$tmptxt=$object->getLibStatut(6, $object->totalpaye);
1479
-		if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3) || $conf->browser->layout=='phone') $tmptxt=$object->getLibStatut(5, $object->totalpaye);
1480
-		$morehtmlstatus.=$tmptxt;
1478
+		$tmptxt = $object->getLibStatut(6, $object->totalpaye);
1479
+		if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3) || $conf->browser->layout == 'phone') $tmptxt = $object->getLibStatut(5, $object->totalpaye);
1480
+		$morehtmlstatus .= $tmptxt;
1481 1481
 	}
1482 1482
 	elseif ($object->element == 'contrat' || $object->element == 'contract')
1483 1483
 	{
1484
-		if ($object->statut == 0) $morehtmlstatus.=$object->getLibStatut(5);
1485
-		else $morehtmlstatus.=$object->getLibStatut(4);
1484
+		if ($object->statut == 0) $morehtmlstatus .= $object->getLibStatut(5);
1485
+		else $morehtmlstatus .= $object->getLibStatut(4);
1486 1486
 	}
1487 1487
 	elseif ($object->element == 'facturerec')
1488 1488
 	{
1489
-		if ($object->frequency == 0) $morehtmlstatus.=$object->getLibStatut(2);
1490
-		else $morehtmlstatus.=$object->getLibStatut(5);
1489
+		if ($object->frequency == 0) $morehtmlstatus .= $object->getLibStatut(2);
1490
+		else $morehtmlstatus .= $object->getLibStatut(5);
1491 1491
 	}
1492 1492
 	else { // Generic case
1493
-		$tmptxt=$object->getLibStatut(6);
1494
-		if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3) || $conf->browser->layout=='phone') $tmptxt=$object->getLibStatut(5);
1495
-		$morehtmlstatus.=$tmptxt;
1493
+		$tmptxt = $object->getLibStatut(6);
1494
+		if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3) || $conf->browser->layout == 'phone') $tmptxt = $object->getLibStatut(5);
1495
+		$morehtmlstatus .= $tmptxt;
1496 1496
 	}
1497 1497
 
1498 1498
 	// Add if object was dispatched "into accountancy"
1499
-	if (! empty($conf->accounting->enabled) && in_array($object->element, array('bank', 'facture', 'invoice', 'invoice_supplier', 'expensereport')))
1499
+	if (!empty($conf->accounting->enabled) && in_array($object->element, array('bank', 'facture', 'invoice', 'invoice_supplier', 'expensereport')))
1500 1500
 	{
1501 1501
 		if (method_exists($object, 'getVentilExportCompta'))
1502 1502
 		{
1503 1503
 			$accounted = $object->getVentilExportCompta();
1504 1504
 			$langs->load("accountancy");
1505
-			$morehtmlstatus.='</div><div class="statusref statusrefbis">'.($accounted > 0 ? $langs->trans("Accounted") : $langs->trans("NotYetAccounted"));
1505
+			$morehtmlstatus .= '</div><div class="statusref statusrefbis">'.($accounted > 0 ? $langs->trans("Accounted") : $langs->trans("NotYetAccounted"));
1506 1506
 		}
1507 1507
 	}
1508 1508
 
1509 1509
 	// Add alias for thirdparty
1510
-	if (! empty($object->name_alias)) $morehtmlref.='<div class="refidno">'.$object->name_alias.'</div>';
1510
+	if (!empty($object->name_alias)) $morehtmlref .= '<div class="refidno">'.$object->name_alias.'</div>';
1511 1511
 
1512 1512
 	// Add label
1513 1513
 	if ($object->element == 'product' || $object->element == 'bank_account' || $object->element == 'project_task')
1514 1514
 	{
1515
-		if (! empty($object->label)) $morehtmlref.='<div class="refidno">'.$object->label.'</div>';
1515
+		if (!empty($object->label)) $morehtmlref .= '<div class="refidno">'.$object->label.'</div>';
1516 1516
 	}
1517 1517
 
1518 1518
 	if (method_exists($object, 'getBannerAddress') && $object->element != 'product' && $object->element != 'bookmark' && $object->element != 'ecm_directories' && $object->element != 'ecm_files')
1519 1519
 	{
1520
-		$morehtmlref.='<div class="refidno">';
1521
-		$morehtmlref.=$object->getBannerAddress('refaddress',$object);
1522
-		$morehtmlref.='</div>';
1520
+		$morehtmlref .= '<div class="refidno">';
1521
+		$morehtmlref .= $object->getBannerAddress('refaddress', $object);
1522
+		$morehtmlref .= '</div>';
1523 1523
 	}
1524
-	if (! empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && in_array($object->element, array('societe', 'contact', 'member', 'product')))
1524
+	if (!empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && in_array($object->element, array('societe', 'contact', 'member', 'product')))
1525 1525
 	{
1526
-		$morehtmlref.='<div style="clear: both;"></div><div class="refidno">';
1527
-		$morehtmlref.=$langs->trans("TechnicalID").': '.$object->id;
1528
-		$morehtmlref.='</div>';
1526
+		$morehtmlref .= '<div style="clear: both;"></div><div class="refidno">';
1527
+		$morehtmlref .= $langs->trans("TechnicalID").': '.$object->id;
1528
+		$morehtmlref .= '</div>';
1529 1529
 	}
1530 1530
 
1531
-	print '<div class="'.($onlybanner?'arearefnobottom ':'arearef ').'heightref valignmiddle" width="100%">';
1531
+	print '<div class="'.($onlybanner ? 'arearefnobottom ' : 'arearef ').'heightref valignmiddle" width="100%">';
1532 1532
 	print $form->showrefnav($object, $paramid, $morehtml, $shownav, $fieldid, $fieldref, $morehtmlref, $moreparam, $nodbprefix, $morehtmlleft, $morehtmlstatus, $morehtmlright);
1533 1533
 	print '</div>';
1534 1534
 	print '<div class="underrefbanner clearboth"></div>';
@@ -1542,15 +1542,15 @@  discard block
 block discarded – undo
1542 1542
  * @param	int		$fieldrequired	1=Field is mandatory
1543 1543
  * @deprecated Form::editfieldkey
1544 1544
  */
1545
-function fieldLabel($langkey, $fieldkey, $fieldrequired=0)
1545
+function fieldLabel($langkey, $fieldkey, $fieldrequired = 0)
1546 1546
 {
1547 1547
 	global $conf, $langs;
1548
-	$ret='';
1549
-	if ($fieldrequired) $ret.='<span class="fieldrequired">';
1550
-	if (($conf->dol_use_jmobile != 4)) $ret.='<label for="'.$fieldkey.'">';
1551
-	$ret.=$langs->trans($langkey);
1552
-	if (($conf->dol_use_jmobile != 4)) $ret.='</label>';
1553
-	if ($fieldrequired) $ret.='</span>';
1548
+	$ret = '';
1549
+	if ($fieldrequired) $ret .= '<span class="fieldrequired">';
1550
+	if (($conf->dol_use_jmobile != 4)) $ret .= '<label for="'.$fieldkey.'">';
1551
+	$ret .= $langs->trans($langkey);
1552
+	if (($conf->dol_use_jmobile != 4)) $ret .= '</label>';
1553
+	if ($fieldrequired) $ret .= '</span>';
1554 1554
 	return $ret;
1555 1555
 }
1556 1556
 
@@ -1561,11 +1561,11 @@  discard block
 block discarded – undo
1561 1561
  * @param	string	$moreclass		More class to add
1562 1562
  * @return	string					String to add class onto HTML element
1563 1563
  */
1564
-function dol_bc($var,$moreclass='')
1564
+function dol_bc($var, $moreclass = '')
1565 1565
 {
1566 1566
 	global $bc;
1567
-	$ret=' '.$bc[$var];
1568
-	if ($moreclass) $ret=preg_replace('/class=\"/','class="'.$moreclass.' ',$ret);
1567
+	$ret = ' '.$bc[$var];
1568
+	if ($moreclass) $ret = preg_replace('/class=\"/', 'class="'.$moreclass.' ', $ret);
1569 1569
 	return $ret;
1570 1570
 }
1571 1571
 
@@ -1580,62 +1580,62 @@  discard block
 block discarded – undo
1580 1580
  *      @return string						Formated string
1581 1581
  *      @see dol_print_address
1582 1582
  */
1583
-function dol_format_address($object, $withcountry=0, $sep="\n", $outputlangs='', $mode=0)
1583
+function dol_format_address($object, $withcountry = 0, $sep = "\n", $outputlangs = '', $mode = 0)
1584 1584
 {
1585
-	global $conf,$langs;
1585
+	global $conf, $langs;
1586 1586
 
1587
-	$ret='';
1588
-	$countriesusingstate=array('AU','CA','US','IN','GB','ES','UK','TR');    // See also MAIN_FORCE_STATE_INTO_ADDRESS
1587
+	$ret = '';
1588
+	$countriesusingstate = array('AU', 'CA', 'US', 'IN', 'GB', 'ES', 'UK', 'TR'); // See also MAIN_FORCE_STATE_INTO_ADDRESS
1589 1589
 
1590 1590
 	// Address
1591 1591
 	if (empty($mode)) {
1592 1592
 		$ret .= $object->address;
1593 1593
 	}
1594 1594
 	// Zip/Town/State
1595
-	if (in_array($object->country_code,array('AU', 'CA', 'US')) || ! empty($conf->global->MAIN_FORCE_STATE_INTO_ADDRESS))   	// US: title firstname name \n address lines \n town, state, zip \n country
1595
+	if (in_array($object->country_code, array('AU', 'CA', 'US')) || !empty($conf->global->MAIN_FORCE_STATE_INTO_ADDRESS))   	// US: title firstname name \n address lines \n town, state, zip \n country
1596 1596
 	{
1597
-		$ret .= ($ret ? $sep : '' ).$object->town;
1597
+		$ret .= ($ret ? $sep : '').$object->town;
1598 1598
 		if ($object->state)
1599 1599
 		{
1600
-			$ret.=($ret?", ":'').$object->state;
1600
+			$ret .= ($ret ? ", " : '').$object->state;
1601 1601
 		}
1602
-		if ($object->zip) $ret .= ($ret?", ":'').$object->zip;
1602
+		if ($object->zip) $ret .= ($ret ? ", " : '').$object->zip;
1603 1603
 	}
1604
-	else if (in_array($object->country_code,array('GB','UK'))) // UK: title firstname name \n address lines \n town state \n zip \n country
1604
+	else if (in_array($object->country_code, array('GB', 'UK'))) // UK: title firstname name \n address lines \n town state \n zip \n country
1605 1605
 	{
1606
-		$ret .= ($ret ? $sep : '' ).$object->town;
1606
+		$ret .= ($ret ? $sep : '').$object->town;
1607 1607
 		if ($object->state)
1608 1608
 		{
1609
-			$ret.=($ret?", ":'').$object->state;
1609
+			$ret .= ($ret ? ", " : '').$object->state;
1610 1610
 		}
1611
-		if ($object->zip) $ret .= ($ret ? $sep : '' ).$object->zip;
1611
+		if ($object->zip) $ret .= ($ret ? $sep : '').$object->zip;
1612 1612
 	}
1613
-	else if (in_array($object->country_code,array('ES','TR'))) // ES: title firstname name \n address lines \n zip town \n state \n country
1613
+	else if (in_array($object->country_code, array('ES', 'TR'))) // ES: title firstname name \n address lines \n zip town \n state \n country
1614 1614
 	{
1615
-		$ret .= ($ret ? $sep : '' ).$object->zip;
1616
-		$ret .= ($object->town?(($object->zip?' ':'').$object->town):'');
1615
+		$ret .= ($ret ? $sep : '').$object->zip;
1616
+		$ret .= ($object->town ? (($object->zip ? ' ' : '').$object->town) : '');
1617 1617
 		if ($object->state)
1618 1618
 		{
1619
-			$ret.="\n".$object->state;
1619
+			$ret .= "\n".$object->state;
1620 1620
 		}
1621 1621
 	}
1622
-	else if (in_array($object->country_code,array('IT'))) // IT: tile firstname name\n address lines \n zip (Code Departement) \n country
1622
+	else if (in_array($object->country_code, array('IT'))) // IT: tile firstname name\n address lines \n zip (Code Departement) \n country
1623 1623
 	{
1624
-                $ret .= ($ret ? $sep : '' ).$object->zip;
1625
-                $ret .= ($object->town?(($object->zip?' ':'').$object->town):'');
1626
-                $ret .= ($object->departement_id?(' ('.($object->departement_id).')'):'');
1624
+                $ret .= ($ret ? $sep : '').$object->zip;
1625
+                $ret .= ($object->town ? (($object->zip ? ' ' : '').$object->town) : '');
1626
+                $ret .= ($object->departement_id ? (' ('.($object->departement_id).')') : '');
1627 1627
 	}
1628 1628
 	else                                        		// Other: title firstname name \n address lines \n zip town \n country
1629 1629
 	{
1630
-		$ret .= $object->zip ? (($ret ? $sep : '' ).$object->zip) : '';
1631
-		$ret .= ($object->town?(($object->zip?' ':($ret ? $sep : '' )).$object->town):'');
1632
-		if ($object->state && in_array($object->country_code,$countriesusingstate))
1630
+		$ret .= $object->zip ? (($ret ? $sep : '').$object->zip) : '';
1631
+		$ret .= ($object->town ? (($object->zip ? ' ' : ($ret ? $sep : '')).$object->town) : '');
1632
+		if ($object->state && in_array($object->country_code, $countriesusingstate))
1633 1633
 		{
1634
-			$ret.=($ret?", ":'').$object->state;
1634
+			$ret .= ($ret ? ", " : '').$object->state;
1635 1635
 		}
1636 1636
 	}
1637
-	if (! is_object($outputlangs)) $outputlangs=$langs;
1638
-	if ($withcountry) $ret.=($object->country_code?($ret?$sep:'').$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$object->country_code)):'');
1637
+	if (!is_object($outputlangs)) $outputlangs = $langs;
1638
+	if ($withcountry) $ret .= ($object->country_code ? ($ret ? $sep : '').$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$object->country_code)) : '');
1639 1639
 
1640 1640
 	return $ret;
1641 1641
 }
@@ -1650,10 +1650,10 @@  discard block
 block discarded – undo
1650 1650
  *  @param	int		$is_gmt		See comment of timestamp parameter
1651 1651
  *	@return	string				A formatted string
1652 1652
  */
1653
-function dol_strftime($fmt, $ts=false, $is_gmt=false)
1653
+function dol_strftime($fmt, $ts = false, $is_gmt = false)
1654 1654
 {
1655 1655
 	if ((abs($ts) <= 0x7FFFFFFF)) { // check if number in 32-bit signed range
1656
-		return ($is_gmt)? @gmstrftime($fmt,$ts): @strftime($fmt,$ts);
1656
+		return ($is_gmt) ? @gmstrftime($fmt, $ts) : @strftime($fmt, $ts);
1657 1657
 	}
1658 1658
 	else return 'Error date into a not supported range';
1659 1659
 }
@@ -1679,144 +1679,144 @@  discard block
 block discarded – undo
1679 1679
  *
1680 1680
  *  @see        dol_mktime, dol_stringtotime, dol_getdate
1681 1681
  */
1682
-function dol_print_date($time,$format='',$tzoutput='tzserver',$outputlangs='',$encodetooutput=false)
1682
+function dol_print_date($time, $format = '', $tzoutput = 'tzserver', $outputlangs = '', $encodetooutput = false)
1683 1683
 {
1684
-	global $conf,$langs;
1684
+	global $conf, $langs;
1685 1685
 
1686 1686
 	// Clean parameters
1687
-	$to_gmt=false;
1688
-	$offsettz=$offsetdst=0;
1687
+	$to_gmt = false;
1688
+	$offsettz = $offsetdst = 0;
1689 1689
 	if ($tzoutput)
1690 1690
 	{
1691
-		$to_gmt=true;	// For backward compatibility
1691
+		$to_gmt = true; // For backward compatibility
1692 1692
 		if (is_string($tzoutput))
1693 1693
 		{
1694 1694
 			if ($tzoutput == 'tzserver')
1695 1695
 			{
1696
-				$to_gmt=false;
1697
-				$offsettzstring=@date_default_timezone_get();		// Example 'Europe/Berlin' or 'Indian/Reunion'
1698
-				$offsettz=0;
1699
-				$offsetdst=0;
1696
+				$to_gmt = false;
1697
+				$offsettzstring = @date_default_timezone_get(); // Example 'Europe/Berlin' or 'Indian/Reunion'
1698
+				$offsettz = 0;
1699
+				$offsetdst = 0;
1700 1700
 			}
1701 1701
 			elseif ($tzoutput == 'tzuser' || $tzoutput == 'tzuserrel')
1702 1702
 			{
1703
-				$to_gmt=true;
1704
-				$offsettzstring=(empty($_SESSION['dol_tz_string'])?'UTC':$_SESSION['dol_tz_string']);	// Example 'Europe/Berlin' or 'Indian/Reunion'
1705
-				$offsettz=(empty($_SESSION['dol_tz'])?0:$_SESSION['dol_tz'])*60*60;		// Will not be used anymore
1706
-				$offsetdst=(empty($_SESSION['dol_dst'])?0:$_SESSION['dol_dst'])*60*60;	// Will not be used anymore
1703
+				$to_gmt = true;
1704
+				$offsettzstring = (empty($_SESSION['dol_tz_string']) ? 'UTC' : $_SESSION['dol_tz_string']); // Example 'Europe/Berlin' or 'Indian/Reunion'
1705
+				$offsettz = (empty($_SESSION['dol_tz']) ? 0 : $_SESSION['dol_tz']) * 60 * 60; // Will not be used anymore
1706
+				$offsetdst = (empty($_SESSION['dol_dst']) ? 0 : $_SESSION['dol_dst']) * 60 * 60; // Will not be used anymore
1707 1707
 			}
1708 1708
 		}
1709 1709
 	}
1710
-	if (! is_object($outputlangs)) $outputlangs=$langs;
1711
-	if (! $format) $format='daytextshort';
1712
-	$reduceformat=(! empty($conf->dol_optimize_smallscreen) && in_array($format,array('day','dayhour')))?1:0;
1713
-	$formatwithoutreduce = preg_replace('/reduceformat/','',$format);
1714
-	if ($formatwithoutreduce != $format) { $format = $formatwithoutreduce; $reduceformat=1; }  // so format 'dayreduceformat' is processed like day
1710
+	if (!is_object($outputlangs)) $outputlangs = $langs;
1711
+	if (!$format) $format = 'daytextshort';
1712
+	$reduceformat = (!empty($conf->dol_optimize_smallscreen) && in_array($format, array('day', 'dayhour'))) ? 1 : 0;
1713
+	$formatwithoutreduce = preg_replace('/reduceformat/', '', $format);
1714
+	if ($formatwithoutreduce != $format) { $format = $formatwithoutreduce; $reduceformat = 1; }  // so format 'dayreduceformat' is processed like day
1715 1715
 
1716 1716
 	// Change predefined format into computer format. If found translation in lang file we use it, otherwise we use default.
1717 1717
 	// TODO Add format daysmallyear and dayhoursmallyear
1718
-	if ($format == 'day')				$format=($outputlangs->trans("FormatDateShort")!="FormatDateShort"?$outputlangs->trans("FormatDateShort"):$conf->format_date_short);
1719
-	else if ($format == 'hour')			$format=($outputlangs->trans("FormatHourShort")!="FormatHourShort"?$outputlangs->trans("FormatHourShort"):$conf->format_hour_short);
1720
-	else if ($format == 'hourduration')	$format=($outputlangs->trans("FormatHourShortDuration")!="FormatHourShortDuration"?$outputlangs->trans("FormatHourShortDuration"):$conf->format_hour_short_duration);
1721
-	else if ($format == 'daytext')			 $format=($outputlangs->trans("FormatDateText")!="FormatDateText"?$outputlangs->trans("FormatDateText"):$conf->format_date_text);
1722
-	else if ($format == 'daytextshort')	$format=($outputlangs->trans("FormatDateTextShort")!="FormatDateTextShort"?$outputlangs->trans("FormatDateTextShort"):$conf->format_date_text_short);
1723
-	else if ($format == 'dayhour')			 $format=($outputlangs->trans("FormatDateHourShort")!="FormatDateHourShort"?$outputlangs->trans("FormatDateHourShort"):$conf->format_date_hour_short);
1724
-	else if ($format == 'dayhoursec')		 $format=($outputlangs->trans("FormatDateHourSecShort")!="FormatDateHourSecShort"?$outputlangs->trans("FormatDateHourSecShort"):$conf->format_date_hour_sec_short);
1725
-	else if ($format == 'dayhourtext')		 $format=($outputlangs->trans("FormatDateHourText")!="FormatDateHourText"?$outputlangs->trans("FormatDateHourText"):$conf->format_date_hour_text);
1726
-	else if ($format == 'dayhourtextshort') $format=($outputlangs->trans("FormatDateHourTextShort")!="FormatDateHourTextShort"?$outputlangs->trans("FormatDateHourTextShort"):$conf->format_date_hour_text_short);
1718
+	if ($format == 'day')				$format = ($outputlangs->trans("FormatDateShort") != "FormatDateShort" ? $outputlangs->trans("FormatDateShort") : $conf->format_date_short);
1719
+	else if ($format == 'hour')			$format = ($outputlangs->trans("FormatHourShort") != "FormatHourShort" ? $outputlangs->trans("FormatHourShort") : $conf->format_hour_short);
1720
+	else if ($format == 'hourduration')	$format = ($outputlangs->trans("FormatHourShortDuration") != "FormatHourShortDuration" ? $outputlangs->trans("FormatHourShortDuration") : $conf->format_hour_short_duration);
1721
+	else if ($format == 'daytext')			 $format = ($outputlangs->trans("FormatDateText") != "FormatDateText" ? $outputlangs->trans("FormatDateText") : $conf->format_date_text);
1722
+	else if ($format == 'daytextshort')	$format = ($outputlangs->trans("FormatDateTextShort") != "FormatDateTextShort" ? $outputlangs->trans("FormatDateTextShort") : $conf->format_date_text_short);
1723
+	else if ($format == 'dayhour')			 $format = ($outputlangs->trans("FormatDateHourShort") != "FormatDateHourShort" ? $outputlangs->trans("FormatDateHourShort") : $conf->format_date_hour_short);
1724
+	else if ($format == 'dayhoursec')		 $format = ($outputlangs->trans("FormatDateHourSecShort") != "FormatDateHourSecShort" ? $outputlangs->trans("FormatDateHourSecShort") : $conf->format_date_hour_sec_short);
1725
+	else if ($format == 'dayhourtext')		 $format = ($outputlangs->trans("FormatDateHourText") != "FormatDateHourText" ? $outputlangs->trans("FormatDateHourText") : $conf->format_date_hour_text);
1726
+	else if ($format == 'dayhourtextshort') $format = ($outputlangs->trans("FormatDateHourTextShort") != "FormatDateHourTextShort" ? $outputlangs->trans("FormatDateHourTextShort") : $conf->format_date_hour_text_short);
1727 1727
 	// Format not sensitive to language
1728
-	else if ($format == 'dayhourlog')		 $format='%Y%m%d%H%M%S';
1729
-	else if ($format == 'dayhourldap')		 $format='%Y%m%d%H%M%SZ';
1730
-	else if ($format == 'dayhourxcard')	$format='%Y%m%dT%H%M%SZ';
1731
-	else if ($format == 'dayxcard')	 	$format='%Y%m%d';
1732
-	else if ($format == 'dayrfc')			 $format='%Y-%m-%d';             // DATE_RFC3339
1733
-	else if ($format == 'dayhourrfc')		 $format='%Y-%m-%dT%H:%M:%SZ';   // DATETIME RFC3339
1734
-	else if ($format == 'standard')		$format='%Y-%m-%d %H:%M:%S';
1728
+	else if ($format == 'dayhourlog')		 $format = '%Y%m%d%H%M%S';
1729
+	else if ($format == 'dayhourldap')		 $format = '%Y%m%d%H%M%SZ';
1730
+	else if ($format == 'dayhourxcard')	$format = '%Y%m%dT%H%M%SZ';
1731
+	else if ($format == 'dayxcard')	 	$format = '%Y%m%d';
1732
+	else if ($format == 'dayrfc')			 $format = '%Y-%m-%d'; // DATE_RFC3339
1733
+	else if ($format == 'dayhourrfc')		 $format = '%Y-%m-%dT%H:%M:%SZ'; // DATETIME RFC3339
1734
+	else if ($format == 'standard')		$format = '%Y-%m-%d %H:%M:%S';
1735 1735
 
1736 1736
 	if ($reduceformat)
1737 1737
 	{
1738
-		$format=str_replace('%Y','%y',$format);
1739
-		$format=str_replace('yyyy','yy',$format);
1738
+		$format = str_replace('%Y', '%y', $format);
1739
+		$format = str_replace('yyyy', 'yy', $format);
1740 1740
 	}
1741 1741
 
1742 1742
 	// If date undefined or "", we return ""
1743
-	if (dol_strlen($time) == 0) return '';		// $time=0 allowed (it means 01/01/1970 00:00:00)
1743
+	if (dol_strlen($time) == 0) return ''; // $time=0 allowed (it means 01/01/1970 00:00:00)
1744 1744
 
1745 1745
 	// Clean format
1746
-	if (preg_match('/%b/i',$format))		// There is some text to translate
1746
+	if (preg_match('/%b/i', $format))		// There is some text to translate
1747 1747
 	{
1748 1748
 		// We inhibate translation to text made by strftime functions. We will use trans instead later.
1749
-		$format=str_replace('%b','__b__',$format);
1750
-		$format=str_replace('%B','__B__',$format);
1749
+		$format = str_replace('%b', '__b__', $format);
1750
+		$format = str_replace('%B', '__B__', $format);
1751 1751
 	}
1752
-	if (preg_match('/%a/i',$format))		// There is some text to translate
1752
+	if (preg_match('/%a/i', $format))		// There is some text to translate
1753 1753
 	{
1754 1754
 		// We inhibate translation to text made by strftime functions. We will use trans instead later.
1755
-		$format=str_replace('%a','__a__',$format);
1756
-		$format=str_replace('%A','__A__',$format);
1755
+		$format = str_replace('%a', '__a__', $format);
1756
+		$format = str_replace('%A', '__A__', $format);
1757 1757
 	}
1758 1758
 
1759 1759
 	// Analyze date
1760
-	if (preg_match('/^([0-9]+)\-([0-9]+)\-([0-9]+) ?([0-9]+)?:?([0-9]+)?:?([0-9]+)?/i',$time,$reg)
1761
-	|| preg_match('/^([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])$/i',$time,$reg))	// Deprecated. Ex: 1970-01-01, 1970-01-01 01:00:00, 19700101010000
1760
+	if (preg_match('/^([0-9]+)\-([0-9]+)\-([0-9]+) ?([0-9]+)?:?([0-9]+)?:?([0-9]+)?/i', $time, $reg)
1761
+	|| preg_match('/^([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])$/i', $time, $reg))	// Deprecated. Ex: 1970-01-01, 1970-01-01 01:00:00, 19700101010000
1762 1762
 	{
1763 1763
 		// TODO Remove this.
1764 1764
 		// This part of code should not be used.
1765 1765
 		dol_syslog("Functions.lib::dol_print_date function call with deprecated value of time in page ".$_SERVER["PHP_SELF"], LOG_ERR);
1766 1766
 		// Date has format 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS' or 'YYYYMMDDHHMMSS'
1767
-		$syear	= (! empty($reg[1]) ? $reg[1] : '');
1768
-		$smonth	= (! empty($reg[2]) ? $reg[2] : '');
1769
-		$sday	= (! empty($reg[3]) ? $reg[3] : '');
1770
-		$shour	= (! empty($reg[4]) ? $reg[4] : '');
1771
-		$smin	= (! empty($reg[5]) ? $reg[5] : '');
1772
-		$ssec	= (! empty($reg[6]) ? $reg[6] : '');
1767
+		$syear	= (!empty($reg[1]) ? $reg[1] : '');
1768
+		$smonth = (!empty($reg[2]) ? $reg[2] : '');
1769
+		$sday	= (!empty($reg[3]) ? $reg[3] : '');
1770
+		$shour	= (!empty($reg[4]) ? $reg[4] : '');
1771
+		$smin	= (!empty($reg[5]) ? $reg[5] : '');
1772
+		$ssec	= (!empty($reg[6]) ? $reg[6] : '');
1773 1773
 
1774
-		$time=dol_mktime($shour,$smin,$ssec,$smonth,$sday,$syear,true);
1775
-		$ret=adodb_strftime($format, $time+$offsettz+$offsetdst, $to_gmt);
1774
+		$time = dol_mktime($shour, $smin, $ssec, $smonth, $sday, $syear, true);
1775
+		$ret = adodb_strftime($format, $time + $offsettz + $offsetdst, $to_gmt);
1776 1776
 	}
1777 1777
 	else
1778 1778
 	{
1779 1779
 		// Date is a timestamps
1780 1780
 		if ($time < 100000000000)	// Protection against bad date values
1781 1781
 		{
1782
-			$timetouse = $time+$offsettz+$offsetdst;	// TODO Replace this with function Date PHP. We also should not use anymore offsettz and offsetdst but only offsettzstring.
1782
+			$timetouse = $time + $offsettz + $offsetdst; // TODO Replace this with function Date PHP. We also should not use anymore offsettz and offsetdst but only offsettzstring.
1783 1783
 
1784
-			$ret=adodb_strftime($format, $timetouse, $to_gmt);
1784
+			$ret = adodb_strftime($format, $timetouse, $to_gmt);
1785 1785
 		}
1786
-		else $ret='Bad value '.$time.' for date';
1786
+		else $ret = 'Bad value '.$time.' for date';
1787 1787
 	}
1788 1788
 
1789
-	if (preg_match('/__b__/i',$format))
1789
+	if (preg_match('/__b__/i', $format))
1790 1790
 	{
1791
-		$timetouse = $time+$offsettz+$offsetdst;	// TODO Replace this with function Date PHP. We also should not use anymore offsettz and offsetdst but only offsettzstring.
1791
+		$timetouse = $time + $offsettz + $offsetdst; // TODO Replace this with function Date PHP. We also should not use anymore offsettz and offsetdst but only offsettzstring.
1792 1792
 
1793 1793
 		// Here ret is string in PHP setup language (strftime was used). Now we convert to $outputlangs.
1794
-		$month=adodb_strftime('%m', $timetouse);
1795
-		$month=sprintf("%02d", $month);	// $month may be return with format '06' on some installation and '6' on other, so we force it to '06'.
1794
+		$month = adodb_strftime('%m', $timetouse);
1795
+		$month = sprintf("%02d", $month); // $month may be return with format '06' on some installation and '6' on other, so we force it to '06'.
1796 1796
 		if ($encodetooutput)
1797 1797
 		{
1798
-			$monthtext=$outputlangs->transnoentities('Month'.$month);
1799
-			$monthtextshort=$outputlangs->transnoentities('MonthShort'.$month);
1798
+			$monthtext = $outputlangs->transnoentities('Month'.$month);
1799
+			$monthtextshort = $outputlangs->transnoentities('MonthShort'.$month);
1800 1800
 		}
1801 1801
 		else
1802 1802
 		{
1803
-			$monthtext=$outputlangs->transnoentitiesnoconv('Month'.$month);
1804
-			$monthtextshort=$outputlangs->transnoentitiesnoconv('MonthShort'.$month);
1803
+			$monthtext = $outputlangs->transnoentitiesnoconv('Month'.$month);
1804
+			$monthtextshort = $outputlangs->transnoentitiesnoconv('MonthShort'.$month);
1805 1805
 		}
1806 1806
 		//print 'monthtext='.$monthtext.' monthtextshort='.$monthtextshort;
1807
-		$ret=str_replace('__b__',$monthtextshort,$ret);
1808
-		$ret=str_replace('__B__',$monthtext,$ret);
1807
+		$ret = str_replace('__b__', $monthtextshort, $ret);
1808
+		$ret = str_replace('__B__', $monthtext, $ret);
1809 1809
 		//print 'x'.$outputlangs->charset_output.'-'.$ret.'x';
1810 1810
 		//return $ret;
1811 1811
 	}
1812
-	if (preg_match('/__a__/i',$format))
1812
+	if (preg_match('/__a__/i', $format))
1813 1813
 	{
1814
-		$timetouse = $time+$offsettz+$offsetdst;	// TODO Replace this with function Date PHP. We also should not use anymore offsettz and offsetdst but only offsettzstring.
1814
+		$timetouse = $time + $offsettz + $offsetdst; // TODO Replace this with function Date PHP. We also should not use anymore offsettz and offsetdst but only offsettzstring.
1815 1815
 
1816
-		$w=adodb_strftime('%w', $timetouse);						// TODO Replace this with function Date PHP. We also should not use anymore offsettz and offsetdst but only offsettzstring.
1817
-		$dayweek=$outputlangs->transnoentitiesnoconv('Day'.$w);
1818
-		$ret=str_replace('__A__',$dayweek,$ret);
1819
-		$ret=str_replace('__a__',dol_substr($dayweek,0,3),$ret);
1816
+		$w = adodb_strftime('%w', $timetouse); // TODO Replace this with function Date PHP. We also should not use anymore offsettz and offsetdst but only offsettzstring.
1817
+		$dayweek = $outputlangs->transnoentitiesnoconv('Day'.$w);
1818
+		$ret = str_replace('__A__', $dayweek, $ret);
1819
+		$ret = str_replace('__a__', dol_substr($dayweek, 0, 3), $ret);
1820 1820
 	}
1821 1821
 
1822 1822
 	return $ret;
@@ -1856,21 +1856,21 @@  discard block
 block discarded – undo
1856 1856
  *										'ndays' => $ndays
1857 1857
  * 	@see 								dol_print_date, dol_stringtotime, dol_mktime
1858 1858
  */
1859
-function dol_getdate($timestamp,$fast=false)
1859
+function dol_getdate($timestamp, $fast = false)
1860 1860
 {
1861 1861
 	global $conf;
1862 1862
 
1863
-	$usealternatemethod=false;
1864
-	if ($timestamp <= 0) $usealternatemethod=true;				// <= 1970
1865
-	if ($timestamp >= 2145913200) $usealternatemethod=true;		// >= 2038
1863
+	$usealternatemethod = false;
1864
+	if ($timestamp <= 0) $usealternatemethod = true; // <= 1970
1865
+	if ($timestamp >= 2145913200) $usealternatemethod = true; // >= 2038
1866 1866
 
1867 1867
 	if ($usealternatemethod)
1868 1868
 	{
1869
-		$arrayinfo=adodb_getdate($timestamp,$fast);
1869
+		$arrayinfo = adodb_getdate($timestamp, $fast);
1870 1870
 	}
1871 1871
 	else
1872 1872
 	{
1873
-		$arrayinfo=getdate($timestamp);
1873
+		$arrayinfo = getdate($timestamp);
1874 1874
 	}
1875 1875
 
1876 1876
 	return $arrayinfo;
@@ -1895,55 +1895,55 @@  discard block
 block discarded – undo
1895 1895
  *	@return	int|string					Date as a timestamp, '' or false if error
1896 1896
  * 	@see 								dol_print_date, dol_stringtotime, dol_getdate
1897 1897
  */
1898
-function dol_mktime($hour,$minute,$second,$month,$day,$year,$gm=false,$check=1)
1898
+function dol_mktime($hour, $minute, $second, $month, $day, $year, $gm = false, $check = 1)
1899 1899
 {
1900 1900
 	global $conf;
1901 1901
 	//print "- ".$hour.",".$minute.",".$second.",".$month.",".$day.",".$year.",".$_SERVER["WINDIR"]." -";
1902 1902
 
1903 1903
 	// Clean parameters
1904
-	if ($hour   == -1 || empty($hour)) $hour=0;
1905
-	if ($minute == -1 || empty($minute)) $minute=0;
1906
-	if ($second == -1 || empty($second)) $second=0;
1904
+	if ($hour == -1 || empty($hour)) $hour = 0;
1905
+	if ($minute == -1 || empty($minute)) $minute = 0;
1906
+	if ($second == -1 || empty($second)) $second = 0;
1907 1907
 
1908 1908
 	// Check parameters
1909 1909
 	if ($check)
1910 1910
 	{
1911
-		if (! $month || ! $day)  return '';
1912
-		if ($day   > 31) return '';
1911
+		if (!$month || !$day)  return '';
1912
+		if ($day > 31) return '';
1913 1913
 		if ($month > 12) return '';
1914
-		if ($hour  < 0 || $hour   > 24) return '';
1915
-		if ($minute< 0 || $minute > 60) return '';
1916
-		if ($second< 0 || $second > 60) return '';
1914
+		if ($hour < 0 || $hour > 24) return '';
1915
+		if ($minute < 0 || $minute > 60) return '';
1916
+		if ($second < 0 || $second > 60) return '';
1917 1917
 	}
1918 1918
 
1919
-	if (method_exists('DateTime','getTimestamp'))
1919
+	if (method_exists('DateTime', 'getTimestamp'))
1920 1920
 	{
1921 1921
 		if (empty($gm) || $gm === 'server')
1922 1922
 		{
1923
-			$default_timezone=@date_default_timezone_get();		// Example 'Europe/Berlin'
1923
+			$default_timezone = @date_default_timezone_get(); // Example 'Europe/Berlin'
1924 1924
 			$localtz = new DateTimeZone($default_timezone);
1925 1925
 		}
1926 1926
 		else if ($gm === 'user')
1927 1927
 		{
1928 1928
 			// We use dol_tz_string first because it is more reliable.
1929
-			$default_timezone=(empty($_SESSION["dol_tz_string"])?@date_default_timezone_get():$_SESSION["dol_tz_string"]);		// Example 'Europe/Berlin'
1929
+			$default_timezone = (empty($_SESSION["dol_tz_string"]) ? @date_default_timezone_get() : $_SESSION["dol_tz_string"]); // Example 'Europe/Berlin'
1930 1930
 			try {
1931 1931
 				$localtz = new DateTimeZone($default_timezone);
1932 1932
 			}
1933
-			catch(Exception $e)
1933
+			catch (Exception $e)
1934 1934
 			{
1935 1935
 				dol_syslog("Warning dol_tz_string contains an invalid value ".$_SESSION["dol_tz_string"], LOG_WARNING);
1936
-				$default_timezone=@date_default_timezone_get();
1936
+				$default_timezone = @date_default_timezone_get();
1937 1937
 			}
1938 1938
 		}
1939 1939
 		else if (strrpos($gm, "tz,") !== false)
1940 1940
 		{
1941
-			$timezone=str_replace("tz,", "", $gm);  // Example 'tz,Europe/Berlin'
1941
+			$timezone = str_replace("tz,", "", $gm); // Example 'tz,Europe/Berlin'
1942 1942
 			try
1943 1943
 			{
1944 1944
 				$localtz = new DateTimeZone($timezone);
1945 1945
 			}
1946
-			catch(Exception $e)
1946
+			catch (Exception $e)
1947 1947
 			{
1948 1948
 				dol_syslog("Warning passed timezone contains an invalid value ".$timezone, LOG_WARNING);
1949 1949
 			}
@@ -1954,16 +1954,16 @@  discard block
 block discarded – undo
1954 1954
 		}
1955 1955
 		//var_dump($localtz);
1956 1956
 		//var_dump($year.'-'.$month.'-'.$day.'-'.$hour.'-'.$minute);
1957
-		$dt = new DateTime(null,$localtz);
1958
-		$dt->setDate($year,$month,$day);
1957
+		$dt = new DateTime(null, $localtz);
1958
+		$dt->setDate($year, $month, $day);
1959 1959
 		$dt->setTime((int) $hour, (int) $minute, (int) $second);
1960
-		$date=$dt->getTimestamp();	// should include daylight saving time
1960
+		$date = $dt->getTimestamp(); // should include daylight saving time
1961 1961
 		//var_dump($date);
1962 1962
 		return $date;
1963 1963
 	}
1964 1964
 	else
1965 1965
 	{
1966
-		dol_print_error('','PHP version must be 5.3+');
1966
+		dol_print_error('', 'PHP version must be 5.3+');
1967 1967
 		return '';
1968 1968
 	}
1969 1969
 }
@@ -1978,18 +1978,18 @@  discard block
 block discarded – undo
1978 1978
  * 								'tzuser' => we add the user timezone
1979 1979
  *	@return int   $date	Timestamp
1980 1980
  */
1981
-function dol_now($mode='gmt')
1981
+function dol_now($mode = 'gmt')
1982 1982
 {
1983
-	$ret=0;
1983
+	$ret = 0;
1984 1984
 
1985 1985
 	// Note that gmmktime and mktime return same value (GMT) when used without parameters
1986 1986
 	//if ($mode == 'gmt') $ret=gmmktime(); // Strict Standards: gmmktime(): You should be using the time() function instead
1987
-	if ($mode == 'gmt') $ret=time();	// Time for now at greenwich.
1987
+	if ($mode == 'gmt') $ret = time(); // Time for now at greenwich.
1988 1988
 	else if ($mode == 'tzserver')		// Time for now with PHP server timezone added
1989 1989
 	{
1990 1990
 		require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
1991
-		$tzsecond=getServerTimeZoneInt('now');    // Contains tz+dayling saving time
1992
-		$ret=(int) dol_now('gmt')+($tzsecond*3600);
1991
+		$tzsecond = getServerTimeZoneInt('now'); // Contains tz+dayling saving time
1992
+		$ret = (int) dol_now('gmt') + ($tzsecond * 3600);
1993 1993
 	}
1994 1994
 	/*else if ($mode == 'tzref')				// Time for now with parent company timezone is added
1995 1995
 	{
@@ -2000,9 +2000,9 @@  discard block
 block discarded – undo
2000 2000
 	else if ($mode == 'tzuser')				// Time for now with user timezone added
2001 2001
 	{
2002 2002
 		//print 'eeee'.time().'-'.mktime().'-'.gmmktime();
2003
-		$offsettz=(empty($_SESSION['dol_tz'])?0:$_SESSION['dol_tz'])*60*60;
2004
-		$offsetdst=(empty($_SESSION['dol_dst'])?0:$_SESSION['dol_dst'])*60*60;
2005
-		$ret=(int) dol_now('gmt')+($offsettz+$offsetdst);
2003
+		$offsettz = (empty($_SESSION['dol_tz']) ? 0 : $_SESSION['dol_tz']) * 60 * 60;
2004
+		$offsetdst = (empty($_SESSION['dol_dst']) ? 0 : $_SESSION['dol_dst']) * 60 * 60;
2005
+		$ret = (int) dol_now('gmt') + ($offsettz + $offsetdst);
2006 2006
 	}
2007 2007
 
2008 2008
 	return $ret;
@@ -2017,29 +2017,29 @@  discard block
 block discarded – undo
2017 2017
  * @param	int		$shortunit	Use short value of size unit
2018 2018
  * @return	string				Link
2019 2019
  */
2020
-function dol_print_size($size,$shortvalue=0,$shortunit=0)
2020
+function dol_print_size($size, $shortvalue = 0, $shortunit = 0)
2021 2021
 {
2022
-	global $conf,$langs;
2023
-	$level=1024;
2022
+	global $conf, $langs;
2023
+	$level = 1024;
2024 2024
 
2025
-	if (! empty($conf->dol_optimize_smallscreen)) $shortunit=1;
2025
+	if (!empty($conf->dol_optimize_smallscreen)) $shortunit = 1;
2026 2026
 
2027 2027
 	// Set value text
2028
-	if (empty($shortvalue) || $size < ($level*10))
2028
+	if (empty($shortvalue) || $size < ($level * 10))
2029 2029
 	{
2030
-		$ret=$size;
2031
-		$textunitshort=$langs->trans("b");
2032
-		$textunitlong=$langs->trans("Bytes");
2030
+		$ret = $size;
2031
+		$textunitshort = $langs->trans("b");
2032
+		$textunitlong = $langs->trans("Bytes");
2033 2033
 	}
2034 2034
 	else
2035 2035
 	{
2036
-		$ret=round($size/$level,0);
2037
-		$textunitshort=$langs->trans("Kb");
2038
-		$textunitlong=$langs->trans("KiloBytes");
2036
+		$ret = round($size / $level, 0);
2037
+		$textunitshort = $langs->trans("Kb");
2038
+		$textunitlong = $langs->trans("KiloBytes");
2039 2039
 	}
2040 2040
 	// Use long or short text unit
2041
-	if (empty($shortunit)) { $ret.=' '.$textunitlong; }
2042
-	else { $ret.=' '.$textunitshort; }
2041
+	if (empty($shortunit)) { $ret .= ' '.$textunitlong; }
2042
+	else { $ret .= ' '.$textunitshort; }
2043 2043
 
2044 2044
 	return $ret;
2045 2045
 }
@@ -2053,22 +2053,22 @@  discard block
 block discarded – undo
2053 2053
  * @param	int			$withpicto	With picto
2054 2054
  * @return	string					HTML Link
2055 2055
  */
2056
-function dol_print_url($url,$target='_blank',$max=32,$withpicto=0)
2056
+function dol_print_url($url, $target = '_blank', $max = 32, $withpicto = 0)
2057 2057
 {
2058 2058
 	global $langs;
2059 2059
 
2060 2060
 	if (empty($url)) return '';
2061 2061
 
2062
-	$link='<a href="';
2063
-	if (! preg_match('/^http/i',$url)) $link.='http://';
2064
-	$link.=$url;
2065
-	$link.='"';
2066
-	if ($target) $link.=' target="'.$target.'"';
2067
-	$link.='>';
2068
-	if (! preg_match('/^http/i',$url)) $link.='http://';
2069
-	$link.=dol_trunc($url,$max);
2070
-	$link.='</a>';
2071
-	return '<div class="nospan float" style="margin-right: 10px">'.($withpicto?img_picto($langs->trans("Url"), 'object_globe.png').' ':'').$link.'</div>';
2062
+	$link = '<a href="';
2063
+	if (!preg_match('/^http/i', $url)) $link .= 'http://';
2064
+	$link .= $url;
2065
+	$link .= '"';
2066
+	if ($target) $link .= ' target="'.$target.'"';
2067
+	$link .= '>';
2068
+	if (!preg_match('/^http/i', $url)) $link .= 'http://';
2069
+	$link .= dol_trunc($url, $max);
2070
+	$link .= '</a>';
2071
+	return '<div class="nospan float" style="margin-right: 10px">'.($withpicto ?img_picto($langs->trans("Url"), 'object_globe.png').' ' : '').$link.'</div>';
2072 2072
 }
2073 2073
 
2074 2074
 /**
@@ -2083,44 +2083,44 @@  discard block
 block discarded – undo
2083 2083
  * @param	int			$withpicto		Show picto
2084 2084
  * @return	string						HTML Link
2085 2085
  */
2086
-function dol_print_email($email,$cid=0,$socid=0,$addlink=0,$max=64,$showinvalid=1,$withpicto=0)
2086
+function dol_print_email($email, $cid = 0, $socid = 0, $addlink = 0, $max = 64, $showinvalid = 1, $withpicto = 0)
2087 2087
 {
2088
-	global $conf,$user,$langs;
2088
+	global $conf, $user, $langs;
2089 2089
 
2090
-	$newemail=$email;
2090
+	$newemail = $email;
2091 2091
 
2092 2092
 	if (empty($email)) return '&nbsp;';
2093 2093
 
2094
-	if (! empty($addlink))
2094
+	if (!empty($addlink))
2095 2095
 	{
2096
-		$newemail='<a style="text-overflow: ellipsis;" href="';
2097
-		if (! preg_match('/^mailto:/i',$email)) $newemail.='mailto:';
2098
-		$newemail.=$email;
2099
-		$newemail.='">';
2100
-		$newemail.=dol_trunc($email,$max);
2101
-		$newemail.='</a>';
2102
-		if ($showinvalid && ! isValidEmail($email))
2096
+		$newemail = '<a style="text-overflow: ellipsis;" href="';
2097
+		if (!preg_match('/^mailto:/i', $email)) $newemail .= 'mailto:';
2098
+		$newemail .= $email;
2099
+		$newemail .= '">';
2100
+		$newemail .= dol_trunc($email, $max);
2101
+		$newemail .= '</a>';
2102
+		if ($showinvalid && !isValidEmail($email))
2103 2103
 		{
2104 2104
 			$langs->load("errors");
2105
-			$newemail.=img_warning($langs->trans("ErrorBadEMail",$email));
2105
+			$newemail .= img_warning($langs->trans("ErrorBadEMail", $email));
2106 2106
 		}
2107 2107
 
2108
-		if (($cid || $socid) && ! empty($conf->agenda->enabled) && $user->rights->agenda->myactions->create)
2108
+		if (($cid || $socid) && !empty($conf->agenda->enabled) && $user->rights->agenda->myactions->create)
2109 2109
 		{
2110
-			$type='AC_EMAIL'; $link='';
2111
-			if (! empty($conf->global->AGENDA_ADDACTIONFOREMAIL)) $link='<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&amp;backtopage=1&amp;actioncode='.$type.'&amp;contactid='.$cid.'&amp;socid='.$socid.'">'.img_object($langs->trans("AddAction"),"calendar").'</a>';
2112
-			if ($link) $newemail='<div>'.$newemail.' '.$link.'</div>';
2110
+			$type = 'AC_EMAIL'; $link = '';
2111
+			if (!empty($conf->global->AGENDA_ADDACTIONFOREMAIL)) $link = '<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&amp;backtopage=1&amp;actioncode='.$type.'&amp;contactid='.$cid.'&amp;socid='.$socid.'">'.img_object($langs->trans("AddAction"), "calendar").'</a>';
2112
+			if ($link) $newemail = '<div>'.$newemail.' '.$link.'</div>';
2113 2113
 		}
2114 2114
 	}
2115 2115
 	else
2116 2116
 	{
2117
-		if ($showinvalid && ! isValidEmail($email))
2117
+		if ($showinvalid && !isValidEmail($email))
2118 2118
 		{
2119 2119
 			$langs->load("errors");
2120
-			$newemail.=img_warning($langs->trans("ErrorBadEMail",$email));
2120
+			$newemail .= img_warning($langs->trans("ErrorBadEMail", $email));
2121 2121
 		}
2122 2122
 	}
2123
-	return '<div class="nospan float" style="margin-right: 10px">'.($withpicto?img_picto($langs->trans("EMail"), 'object_email.png').' ':'').$newemail.'</div>';
2123
+	return '<div class="nospan float" style="margin-right: 10px">'.($withpicto ?img_picto($langs->trans("EMail"), 'object_email.png').' ' : '').$newemail.'</div>';
2124 2124
 }
2125 2125
 
2126 2126
 /**
@@ -2133,41 +2133,41 @@  discard block
 block discarded – undo
2133 2133
  * @param	int			$max			Max number of characters to show
2134 2134
  * @return	string						HTML Link
2135 2135
  */
2136
-function dol_print_skype($skype,$cid=0,$socid=0,$addlink=0,$max=64)
2136
+function dol_print_skype($skype, $cid = 0, $socid = 0, $addlink = 0, $max = 64)
2137 2137
 {
2138
-	global $conf,$user,$langs;
2138
+	global $conf, $user, $langs;
2139 2139
 
2140
-	$newskype=$skype;
2140
+	$newskype = $skype;
2141 2141
 
2142 2142
 	if (empty($skype)) return '&nbsp;';
2143 2143
 
2144
-	if (! empty($addlink))
2144
+	if (!empty($addlink))
2145 2145
 	{
2146
-		$newskype =img_picto($langs->trans("Skype"), 'object_skype.png');
2147
-		$newskype.= '&nbsp;';
2148
-		$newskype.=dol_trunc($skype,$max);
2149
-		$newskype.= '&nbsp;';
2150
-		$newskype.='<a href="skype:';
2151
-		$newskype.=dol_trunc($skype,$max);
2152
-		$newskype.='?call" alt="'.$langs->trans("Call").'&nbsp;'.$skype.'" title="'.$langs->trans("Call").'&nbsp;'.$skype.'">';
2153
-		$newskype.='<img src="'.DOL_URL_ROOT.'/theme/common/skype_callbutton.png" border="0">';
2154
-		$newskype.='</a>&nbsp;&nbsp;&nbsp;<a href="skype:';
2155
-		$newskype.=dol_trunc($skype,$max);
2156
-		$newskype.='?chat" alt="'.$langs->trans("Chat").'&nbsp;'.$skype.'" title="'.$langs->trans("Chat").'&nbsp;'.$skype.'">';
2157
-		$newskype.='<img src="'.DOL_URL_ROOT.'/theme/common/skype_chatbutton.png" border="0">';
2158
-		$newskype.='</a>';
2146
+		$newskype = img_picto($langs->trans("Skype"), 'object_skype.png');
2147
+		$newskype .= '&nbsp;';
2148
+		$newskype .= dol_trunc($skype, $max);
2149
+		$newskype .= '&nbsp;';
2150
+		$newskype .= '<a href="skype:';
2151
+		$newskype .= dol_trunc($skype, $max);
2152
+		$newskype .= '?call" alt="'.$langs->trans("Call").'&nbsp;'.$skype.'" title="'.$langs->trans("Call").'&nbsp;'.$skype.'">';
2153
+		$newskype .= '<img src="'.DOL_URL_ROOT.'/theme/common/skype_callbutton.png" border="0">';
2154
+		$newskype .= '</a>&nbsp;&nbsp;&nbsp;<a href="skype:';
2155
+		$newskype .= dol_trunc($skype, $max);
2156
+		$newskype .= '?chat" alt="'.$langs->trans("Chat").'&nbsp;'.$skype.'" title="'.$langs->trans("Chat").'&nbsp;'.$skype.'">';
2157
+		$newskype .= '<img src="'.DOL_URL_ROOT.'/theme/common/skype_chatbutton.png" border="0">';
2158
+		$newskype .= '</a>';
2159 2159
 
2160
-		if (($cid || $socid) && ! empty($conf->agenda->enabled) && $user->rights->agenda->myactions->create)
2160
+		if (($cid || $socid) && !empty($conf->agenda->enabled) && $user->rights->agenda->myactions->create)
2161 2161
 		{
2162
-			$type='AC_SKYPE'; $link='';
2163
-			if (! empty($conf->global->AGENDA_ADDACTIONFORSKYPE)) $link='<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&amp;backtopage=1&amp;actioncode='.$type.'&amp;contactid='.$cid.'&amp;socid='.$socid.'">'.img_object($langs->trans("AddAction"),"calendar").'</a>';
2164
-			$newskype='<div class="divskype nowrap">'.$newskype.($link?' '.$link:'').'</div>';
2162
+			$type = 'AC_SKYPE'; $link = '';
2163
+			if (!empty($conf->global->AGENDA_ADDACTIONFORSKYPE)) $link = '<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&amp;backtopage=1&amp;actioncode='.$type.'&amp;contactid='.$cid.'&amp;socid='.$socid.'">'.img_object($langs->trans("AddAction"), "calendar").'</a>';
2164
+			$newskype = '<div class="divskype nowrap">'.$newskype.($link ? ' '.$link : '').'</div>';
2165 2165
 		}
2166 2166
 	}
2167 2167
 	else
2168 2168
 	{
2169 2169
 		$langs->load("errors");
2170
-		$newskype.=img_warning($langs->trans("ErrorBadSkype",$skype));
2170
+		$newskype .= img_warning($langs->trans("ErrorBadSkype", $skype));
2171 2171
 	}
2172 2172
 	return $newskype;
2173 2173
 }
@@ -2186,373 +2186,373 @@  discard block
 block discarded – undo
2186 2186
  *  @param  int     $adddivfloat    Add div float around phone.
2187 2187
  * 	@return string 				    Formated phone number
2188 2188
  */
2189
-function dol_print_phone($phone,$countrycode='',$cid=0,$socid=0,$addlink='',$separ="&nbsp;",$withpicto='',$titlealt='',$adddivfloat=0)
2189
+function dol_print_phone($phone, $countrycode = '', $cid = 0, $socid = 0, $addlink = '', $separ = "&nbsp;", $withpicto = '', $titlealt = '', $adddivfloat = 0)
2190 2190
 {
2191 2191
 	global $conf, $user, $langs, $mysoc, $hookmanager;
2192 2192
 
2193 2193
 	// Clean phone parameter
2194
-	$phone = preg_replace("/[\s.-]/","",trim($phone));
2194
+	$phone = preg_replace("/[\s.-]/", "", trim($phone));
2195 2195
 	if (empty($phone)) { return ''; }
2196
-	if (empty($countrycode)) $countrycode=$mysoc->country_code;
2196
+	if (empty($countrycode)) $countrycode = $mysoc->country_code;
2197 2197
 
2198 2198
 	// Short format for small screens
2199
-	if ($conf->dol_optimize_smallscreen) $separ='';
2199
+	if ($conf->dol_optimize_smallscreen) $separ = '';
2200 2200
 
2201
-	$newphone=$phone;
2201
+	$newphone = $phone;
2202 2202
 	if (strtoupper($countrycode) == "FR")
2203 2203
 	{
2204 2204
 		// France
2205 2205
 		if (dol_strlen($phone) == 10) {
2206
-			$newphone=substr($newphone,0,2).$separ.substr($newphone,2,2).$separ.substr($newphone,4,2).$separ.substr($newphone,6,2).$separ.substr($newphone,8,2);
2206
+			$newphone = substr($newphone, 0, 2).$separ.substr($newphone, 2, 2).$separ.substr($newphone, 4, 2).$separ.substr($newphone, 6, 2).$separ.substr($newphone, 8, 2);
2207 2207
 		}
2208 2208
 		elseif (dol_strlen($phone) == 7)
2209 2209
 		{
2210
-			$newphone=substr($newphone,0,3).$separ.substr($newphone,3,2).$separ.substr($newphone,5,2);
2210
+			$newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 2).$separ.substr($newphone, 5, 2);
2211 2211
 		}
2212 2212
 		elseif (dol_strlen($phone) == 9)
2213 2213
 		{
2214
-			$newphone=substr($newphone,0,2).$separ.substr($newphone,2,3).$separ.substr($newphone,5,2).$separ.substr($newphone,7,2);
2214
+			$newphone = substr($newphone, 0, 2).$separ.substr($newphone, 2, 3).$separ.substr($newphone, 5, 2).$separ.substr($newphone, 7, 2);
2215 2215
 		}
2216 2216
 		elseif (dol_strlen($phone) == 11)
2217 2217
 		{
2218
-			$newphone=substr($newphone,0,3).$separ.substr($newphone,3,2).$separ.substr($newphone,5,2).$separ.substr($newphone,7,2).$separ.substr($newphone,9,2);
2218
+			$newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 2).$separ.substr($newphone, 5, 2).$separ.substr($newphone, 7, 2).$separ.substr($newphone, 9, 2);
2219 2219
 		}
2220 2220
 		elseif (dol_strlen($phone) == 12)
2221 2221
 		{
2222
-			$newphone=substr($newphone,0,4).$separ.substr($newphone,4,2).$separ.substr($newphone,6,2).$separ.substr($newphone,8,2).$separ.substr($newphone,10,2);
2222
+			$newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 2).$separ.substr($newphone, 6, 2).$separ.substr($newphone, 8, 2).$separ.substr($newphone, 10, 2);
2223 2223
 		}
2224 2224
 	}
2225 2225
 
2226 2226
 	elseif (strtoupper($countrycode) == "CA")
2227 2227
 	{
2228 2228
 		if (dol_strlen($phone) == 10) {
2229
-			$newphone=($separ!=''?'(':'').substr($newphone,0,3).($separ!=''?')':'').$separ.substr($newphone,3,3).($separ!=''?'-':'').substr($newphone,6,4);
2229
+			$newphone = ($separ != '' ? '(' : '').substr($newphone, 0, 3).($separ != '' ? ')' : '').$separ.substr($newphone, 3, 3).($separ != '' ? '-' : '').substr($newphone, 6, 4);
2230 2230
 		}
2231 2231
 	}
2232
-	elseif (strtoupper($countrycode) == "PT" )
2232
+	elseif (strtoupper($countrycode) == "PT")
2233 2233
 	{//Portugal
2234 2234
 		if (dol_strlen($phone) == 13)
2235 2235
 		{//ex: +351_ABC_DEF_GHI
2236
-			$newphone= substr($newphone,0,4).$separ.substr($newphone,4,3).$separ.substr($newphone,7,3).$separ.substr($newphone,10,3);
2236
+			$newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 3);
2237 2237
 		}
2238 2238
 	}
2239
-	elseif (strtoupper($countrycode) == "SR" )
2239
+	elseif (strtoupper($countrycode) == "SR")
2240 2240
 	{//Suriname
2241 2241
 		if (dol_strlen($phone) == 10)
2242 2242
 		{//ex: +597_ABC_DEF
2243
-			$newphone= substr($newphone,0,4).$separ.substr($newphone,4,3).$separ.substr($newphone,7,3);
2243
+			$newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 3);
2244 2244
 		}
2245 2245
 		elseif (dol_strlen($phone) == 11)
2246 2246
 		{//ex: +597_ABC_DEFG
2247
-			$newphone= substr($newphone,0,4).$separ.substr($newphone,4,3).$separ.substr($newphone,7,4);
2247
+			$newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 4);
2248 2248
 		}
2249 2249
 	}
2250
-	elseif (strtoupper($countrycode) == "DE" )
2250
+	elseif (strtoupper($countrycode) == "DE")
2251 2251
 	{//Allemagne
2252 2252
 		if (dol_strlen($phone) == 14)
2253 2253
 		{//ex:  +49_ABCD_EFGH_IJK
2254
-			$newphone= substr($newphone,0,3).$separ.substr($newphone,3,4).$separ.substr($newphone,7,4).$separ.substr($newphone,11,3);
2254
+			$newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 4).$separ.substr($newphone, 7, 4).$separ.substr($newphone, 11, 3);
2255 2255
 		}
2256 2256
 		elseif (dol_strlen($phone) == 13)
2257 2257
 		{//ex: +49_ABC_DEFG_HIJ
2258
-			$newphone= substr($newphone,0,3).$separ.substr($newphone,3,3).$separ.substr($newphone,6,4).$separ.substr($newphone,10,3);
2258
+			$newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 4).$separ.substr($newphone, 10, 3);
2259 2259
 		}
2260 2260
 	}
2261 2261
 	elseif (strtoupper($countrycode) == "ES")
2262 2262
 	{//Espagne
2263 2263
 		if (dol_strlen($phone) == 12)
2264 2264
 		{//ex:  +34_ABC_DEF_GHI
2265
-			$newphone= substr($newphone,0,3).$separ.substr($newphone,3,3).$separ.substr($newphone,6,3).$separ.substr($newphone,9,3);
2265
+			$newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 3);
2266 2266
 		}
2267 2267
 	}
2268 2268
 	elseif (strtoupper($countrycode) == "BF")
2269 2269
 	{// Burkina Faso
2270 2270
 		if (dol_strlen($phone) == 12)
2271 2271
 		{//ex :  +22 A BC_DE_FG_HI
2272
-			$newphone= substr($newphone,0,3).$separ.substr($newphone,3,1).$separ.substr($newphone,4,2).$separ.substr($newphone,6,2).$separ.substr($newphone,8,2).$separ.substr($newphone,10,2);
2272
+			$newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 1).$separ.substr($newphone, 4, 2).$separ.substr($newphone, 6, 2).$separ.substr($newphone, 8, 2).$separ.substr($newphone, 10, 2);
2273 2273
 		}
2274 2274
 	}
2275 2275
 	elseif (strtoupper($countrycode) == "RO")
2276 2276
 	{// Roumanie
2277 2277
 		if (dol_strlen($phone) == 12)
2278 2278
 		{//ex :  +40 AB_CDE_FG_HI
2279
-			$newphone= substr($newphone,0,3).$separ.substr($newphone,3,2).$separ.substr($newphone,5,3).$separ.substr($newphone,8,2).$separ.substr($newphone,10,2);
2279
+			$newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 2).$separ.substr($newphone, 5, 3).$separ.substr($newphone, 8, 2).$separ.substr($newphone, 10, 2);
2280 2280
 		}
2281 2281
 	}
2282 2282
 	elseif (strtoupper($countrycode) == "TR")
2283 2283
 	{//Turquie
2284 2284
 		if (dol_strlen($phone) == 13)
2285 2285
 		{//ex :  +90 ABC_DEF_GHIJ
2286
-			$newphone= substr($newphone,0,3).$separ.substr($newphone,3,3).$separ.substr($newphone,6,3).$separ.substr($newphone,9,4);
2286
+			$newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 4);
2287 2287
 		}
2288 2288
 	}
2289 2289
 	elseif (strtoupper($countrycode) == "US")
2290 2290
 	{//Etat-Unis
2291 2291
 		if (dol_strlen($phone) == 12)
2292 2292
 		{//ex: +1 ABC_DEF_GHIJ
2293
-			$newphone= substr($newphone,0,2).$separ.substr($newphone,2,3).$separ.substr($newphone,5,3).$separ.substr($newphone,8,4);
2293
+			$newphone = substr($newphone, 0, 2).$separ.substr($newphone, 2, 3).$separ.substr($newphone, 5, 3).$separ.substr($newphone, 8, 4);
2294 2294
 		}
2295 2295
 	}
2296 2296
 	elseif (strtoupper($countrycode) == "MX")
2297 2297
 	{//Mexique
2298 2298
 		if (dol_strlen($phone) == 12)
2299 2299
 		{//ex: +52 ABCD_EFG_HI
2300
-			$newphone = substr($newphone,0,3).$separ.substr($newphone,3,4).$separ.substr($newphone,7,3).$separ.substr($newphone,10,2);
2300
+			$newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 4).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 2);
2301 2301
 		}
2302 2302
 		elseif (dol_strlen($phone) == 11)
2303 2303
 		{//ex: +52 AB_CD_EF_GH
2304
-			$newphone = substr($newphone,0,3).$separ.substr($newphone,3,2).$separ.substr($newphone,5,2).$separ.substr($newphone,7,2).$separ.substr($newphone,9,2);
2304
+			$newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 2).$separ.substr($newphone, 5, 2).$separ.substr($newphone, 7, 2).$separ.substr($newphone, 9, 2);
2305 2305
 		}
2306 2306
 		elseif (dol_strlen($phone) == 13)
2307 2307
 		{//ex: +52 ABC_DEF_GHIJ
2308
-			$newphone = substr($newphone,0,3).$separ.substr($newphone,3,3).$separ.substr($newphone,6,3).$separ.substr($newphone,9,4);
2308
+			$newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 4);
2309 2309
 		}
2310 2310
 	}
2311 2311
 	elseif (strtoupper($countrycode) == "ML")
2312 2312
 	{//Mali
2313
-		if(dol_strlen($phone) == 12)
2313
+		if (dol_strlen($phone) == 12)
2314 2314
 		{//ex: +223 AB_CD_EF_GH
2315
-			$newphone = substr($newphone,0,4).$separ.substr($newphone,4,2).$separ.substr($newphone,6,2).$separ.substr($newphone,8,2).$separ.substr($newphone,10,2);
2315
+			$newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 2).$separ.substr($newphone, 6, 2).$separ.substr($newphone, 8, 2).$separ.substr($newphone, 10, 2);
2316 2316
 		}
2317 2317
 	}
2318 2318
 	elseif (strtoupper($countrycode) == "TH")
2319 2319
 	{//Thaïlande
2320
-		if(dol_strlen($phone) == 11)
2320
+		if (dol_strlen($phone) == 11)
2321 2321
 		{//ex: +66_ABC_DE_FGH
2322
-			$newphone = substr($newphone,0,3).$separ.substr($newphone,3,3).$separ.substr($newphone,6,2).$separ.substr($newphone,8,3);
2322
+			$newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 2).$separ.substr($newphone, 8, 3);
2323 2323
 		}
2324
-		elseif(dol_strlen($phone) == 12)
2324
+		elseif (dol_strlen($phone) == 12)
2325 2325
 		{//ex: +66_A_BCD_EF_GHI
2326
-			$newphone = substr($newphone,0,3).$separ.substr($newphone,3,1).$separ.substr($newphone,4,3).$separ.substr($newphone,7,2).$separ.substr($newphone,9,3);
2326
+			$newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 1).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 2).$separ.substr($newphone, 9, 3);
2327 2327
 		}
2328 2328
 		}
2329 2329
 	elseif (strtoupper($countrycode) == "MU")
2330 2330
 	{//Maurice
2331
-		if(dol_strlen($phone) == 11)
2331
+		if (dol_strlen($phone) == 11)
2332 2332
 		{//ex: +230_ABC_DE_FG
2333
-			$newphone = substr($newphone,0,4).$separ.substr($newphone,4,3).$separ.substr($newphone,7,2).$separ.substr($newphone,9,2);
2333
+			$newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 2).$separ.substr($newphone, 9, 2);
2334 2334
 		}
2335
-		elseif(dol_strlen($phone) == 12)
2335
+		elseif (dol_strlen($phone) == 12)
2336 2336
 		{//ex: +230_ABCD_EF_GH
2337
-			$newphone = substr($newphone,0,4).$separ.substr($newphone,4,4).$separ.substr($newphone,8,2).$separ.substr($newphone,10,2);
2337
+			$newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 4).$separ.substr($newphone, 8, 2).$separ.substr($newphone, 10, 2);
2338 2338
 		}
2339 2339
 	}
2340 2340
 	elseif (strtoupper($countrycode) == "ZA")
2341 2341
 	{//Afrique du sud
2342
-		if(dol_strlen($phone) == 12)
2342
+		if (dol_strlen($phone) == 12)
2343 2343
 		{//ex: +27_AB_CDE_FG_HI
2344
-			$newphone = substr($newphone,0,3).$separ.substr($newphone,3,2).$separ.substr($newphone,5,3).$separ.substr($newphone,8,2).$separ.substr($newphone,10,2);
2344
+			$newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 2).$separ.substr($newphone, 5, 3).$separ.substr($newphone, 8, 2).$separ.substr($newphone, 10, 2);
2345 2345
 		}
2346 2346
 	}
2347 2347
 	elseif (strtoupper($countrycode) == "SY")
2348 2348
 	{//Syrie
2349
-		if(dol_strlen($phone) == 12)
2349
+		if (dol_strlen($phone) == 12)
2350 2350
 		{//ex: +963_AB_CD_EF_GH
2351
-			$newphone = substr($newphone,0,4).$separ.substr($newphone,4,2).$separ.substr($newphone,6,2).$separ.substr($newphone,8,2).$separ.substr($newphone,10,2);
2351
+			$newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 2).$separ.substr($newphone, 6, 2).$separ.substr($newphone, 8, 2).$separ.substr($newphone, 10, 2);
2352 2352
 		}
2353
-		elseif(dol_strlen($phone) == 13)
2353
+		elseif (dol_strlen($phone) == 13)
2354 2354
 		{//ex: +963_AB_CD_EF_GHI
2355
-			$newphone = substr($newphone,0,4).$separ.substr($newphone,4,2).$separ.substr($newphone,6,2).$separ.substr($newphone,8,2).$separ.substr($newphone,10,3);
2355
+			$newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 2).$separ.substr($newphone, 6, 2).$separ.substr($newphone, 8, 2).$separ.substr($newphone, 10, 3);
2356 2356
 		}
2357 2357
 	}
2358 2358
 	elseif (strtoupper($countrycode) == "AE")
2359 2359
 	{//Emirats Arabes Unis
2360
-		if(dol_strlen($phone) == 12)
2360
+		if (dol_strlen($phone) == 12)
2361 2361
 		{//ex: +971_ABC_DEF_GH
2362
-			$newphone = substr($newphone,0,4).$separ.substr($newphone,4,3).$separ.substr($newphone,7,3).$separ.substr($newphone,10,2);
2362
+			$newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 2);
2363 2363
 		}
2364
-		elseif(dol_strlen($phone) == 13)
2364
+		elseif (dol_strlen($phone) == 13)
2365 2365
 		{//ex: +971_ABC_DEF_GHI
2366
-			$newphone = substr($newphone,0,4).$separ.substr($newphone,4,3).$separ.substr($newphone,7,3).$separ.substr($newphone,10,3);
2366
+			$newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 3);
2367 2367
 		}
2368
-		elseif(dol_strlen($phone) == 14)
2368
+		elseif (dol_strlen($phone) == 14)
2369 2369
 		{//ex: +971_ABC_DEF_GHIK
2370
-			$newphone = substr($newphone,0,4).$separ.substr($newphone,4,3).$separ.substr($newphone,7,3).$separ.substr($newphone,10,4);
2370
+			$newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 4);
2371 2371
 		}
2372 2372
 	}
2373 2373
 	elseif (strtoupper($countrycode) == "DZ")
2374 2374
 	{//Algérie
2375
-		if(dol_strlen($phone) == 13)
2375
+		if (dol_strlen($phone) == 13)
2376 2376
 		{//ex: +213_ABC_DEF_GHI
2377
-			$newphone = substr($newphone,0,4).$separ.substr($newphone,4,3).$separ.substr($newphone,7,3).$separ.substr($newphone,10,3);
2377
+			$newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 3);
2378 2378
 		}
2379 2379
 	}
2380 2380
 	elseif (strtoupper($countrycode) == "BE")
2381 2381
 	{//Belgique
2382
-		if(dol_strlen($phone) == 11)
2382
+		if (dol_strlen($phone) == 11)
2383 2383
 		{//ex: +32_ABC_DE_FGH
2384
-			$newphone = substr($newphone,0,3).$separ.substr($newphone,3,3).$separ.substr($newphone,6,2).$separ.substr($newphone,8,3);
2384
+			$newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 2).$separ.substr($newphone, 8, 3);
2385 2385
 		}
2386
-		elseif(dol_strlen($phone) == 12)
2386
+		elseif (dol_strlen($phone) == 12)
2387 2387
 		{//ex: +32_ABC_DEF_GHI
2388
-			$newphone = substr($newphone,0,3).$separ.substr($newphone,3,3).$separ.substr($newphone,6,3).$separ.substr($newphone,9,3);
2388
+			$newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 3);
2389 2389
 		}
2390 2390
 	}
2391 2391
 	elseif (strtoupper($countrycode) == "PF")
2392 2392
 	{//Polynésie française
2393
-		if(dol_strlen($phone) == 12)
2393
+		if (dol_strlen($phone) == 12)
2394 2394
 		{//ex: +689_AB_CD_EF_GH
2395
-			$newphone = substr($newphone,0,4).$separ.substr($newphone,4,2).$separ.substr($newphone,6,2).$separ.substr($newphone,8,2).$separ.substr($newphone,10,2);
2395
+			$newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 2).$separ.substr($newphone, 6, 2).$separ.substr($newphone, 8, 2).$separ.substr($newphone, 10, 2);
2396 2396
 		}
2397 2397
 	}
2398 2398
 	elseif (strtoupper($countrycode) == "CO")
2399 2399
 	{//Colombie
2400
-		if(dol_strlen($phone) == 13)
2400
+		if (dol_strlen($phone) == 13)
2401 2401
 		{//ex: +57_ABC_DEF_GH_IJ
2402
-			$newphone = substr($newphone,0,3).$separ.substr($newphone,3,3).$separ.substr($newphone,6,3).$separ.substr($newphone,9,2).$separ.substr($newphone,11,2);
2402
+			$newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 2).$separ.substr($newphone, 11, 2);
2403 2403
 		}
2404 2404
 	}
2405 2405
 	elseif (strtoupper($countrycode) == "JO")
2406 2406
 	{//Jordanie
2407
-		if(dol_strlen($phone) == 12)
2407
+		if (dol_strlen($phone) == 12)
2408 2408
 		{//ex: +962_A_BCD_EF_GH
2409
-			$newphone = substr($newphone,0,4).$separ.substr($newphone,4,1).$separ.substr($newphone,5,3).$separ.substr($newphone,7,2).$separ.substr($newphone,9,2);
2409
+			$newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 1).$separ.substr($newphone, 5, 3).$separ.substr($newphone, 7, 2).$separ.substr($newphone, 9, 2);
2410 2410
 		}
2411 2411
 	}
2412 2412
 	elseif (strtoupper($countrycode) == "MG")
2413 2413
 	{//Madagascar
2414
-		if(dol_strlen($phone) == 13)
2414
+		if (dol_strlen($phone) == 13)
2415 2415
 		{//ex: +261_AB_CD_EF_GHI
2416
-			$newphone = substr($newphone,0,4).$separ.substr($newphone,4,2).$separ.substr($newphone,6,2).$separ.substr($newphone,8,2).$separ.substr($newphone,10,3);
2416
+			$newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 2).$separ.substr($newphone, 6, 2).$separ.substr($newphone, 8, 2).$separ.substr($newphone, 10, 3);
2417 2417
 		}
2418 2418
 	}
2419 2419
 	elseif (strtoupper($countrycode) == "GB")
2420 2420
 	{//Royaume uni
2421
-		if(dol_strlen($phone) == 13)
2421
+		if (dol_strlen($phone) == 13)
2422 2422
 		{//ex: +44_ABCD_EFG_HIJ
2423
-			$newphone = substr($newphone,0,3).$separ.substr($newphone,3,4).$separ.substr($newphone,7,3).$separ.substr($newphone,10,3);
2423
+			$newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 4).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 3);
2424 2424
 		}
2425 2425
 	}
2426 2426
 	elseif (strtoupper($countrycode) == "CH")
2427 2427
 	{//Suisse
2428
-		if(dol_strlen($phone) == 12)
2428
+		if (dol_strlen($phone) == 12)
2429 2429
 		{//ex: +41_AB_CDE_FG_HI
2430
-			$newphone = substr($newphone,0,3).$separ.substr($newphone,3,2).$separ.substr($newphone,5,3).$separ.substr($newphone,8,2).$separ.substr($newphone,10,2);
2430
+			$newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 2).$separ.substr($newphone, 5, 3).$separ.substr($newphone, 8, 2).$separ.substr($newphone, 10, 2);
2431 2431
 		}
2432
-		elseif(dol_strlen($phone) == 15)
2432
+		elseif (dol_strlen($phone) == 15)
2433 2433
 		{// +41_AB_CDE_FGH_IJKL
2434
-			$newphone =$newphone = substr($newphone,0,3).$separ.substr($newphone,3,2).$separ.substr($newphone,5,3).$separ.substr($newphone,8,3).$separ.substr($newphone,11,4);
2434
+			$newphone = $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 2).$separ.substr($newphone, 5, 3).$separ.substr($newphone, 8, 3).$separ.substr($newphone, 11, 4);
2435 2435
 		}
2436 2436
 	}
2437 2437
 	elseif (strtoupper($countrycode) == "TN")
2438 2438
 	{//Tunisie
2439
-		if(dol_strlen($phone) == 12)
2439
+		if (dol_strlen($phone) == 12)
2440 2440
 		{//ex: +216_AB_CDE_FGH
2441
-			$newphone = substr($newphone,0,4).$separ.substr($newphone,4,2).$separ.substr($newphone,6,3).$separ.substr($newphone,9,3);
2441
+			$newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 2).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 3);
2442 2442
 		}
2443 2443
 	}
2444 2444
 	elseif (strtoupper($countrycode) == "GF")
2445 2445
 	{//Guyane francaise
2446
-		if(dol_strlen($phone) == 13)
2446
+		if (dol_strlen($phone) == 13)
2447 2447
 		{//ex: +594_ABC_DE_FG_HI  (ABC=594 de nouveau)
2448
-			$newphone = substr($newphone,0,4).$separ.substr($newphone,4,3).$separ.substr($newphone,7,2).$separ.substr($newphone,9,2).$separ.substr($newphone,11,2);
2448
+			$newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 2).$separ.substr($newphone, 9, 2).$separ.substr($newphone, 11, 2);
2449 2449
 		}
2450 2450
 	}
2451 2451
 	elseif (strtoupper($countrycode) == "GP")
2452 2452
 	{//Guadeloupe
2453
-		if(dol_strlen($phone) == 13)
2453
+		if (dol_strlen($phone) == 13)
2454 2454
 		{//ex: +590_ABC_DE_FG_HI  (ABC=590 de nouveau)
2455
-			$newphone = substr($newphone,0,4).$separ.substr($newphone,4,3).$separ.substr($newphone,7,2).$separ.substr($newphone,9,2).$separ.substr($newphone,11,2);
2455
+			$newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 2).$separ.substr($newphone, 9, 2).$separ.substr($newphone, 11, 2);
2456 2456
 		}
2457 2457
 	}
2458 2458
 	elseif (strtoupper($countrycode) == "MQ")
2459 2459
 	{//Martinique
2460
-		if(dol_strlen($phone) == 13)
2460
+		if (dol_strlen($phone) == 13)
2461 2461
 		{//ex: +596_ABC_DE_FG_HI  (ABC=596 de nouveau)
2462
-			$newphone = substr($newphone,0,4).$separ.substr($newphone,4,3).$separ.substr($newphone,7,2).$separ.substr($newphone,9,2).$separ.substr($newphone,11,2);
2462
+			$newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 2).$separ.substr($newphone, 9, 2).$separ.substr($newphone, 11, 2);
2463 2463
 		}
2464 2464
 	}
2465 2465
 	elseif (strtoupper($countrycode) == "IT")
2466 2466
 	{//Italie
2467
-		if(dol_strlen($phone) == 12)
2467
+		if (dol_strlen($phone) == 12)
2468 2468
 		{//ex: +39_ABC_DEF_GHI
2469
-			$newphone = substr($newphone,0,3).$separ.substr($newphone,3,3).$separ.substr($newphone,6,3).$separ.substr($newphone,9,3);
2469
+			$newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 3);
2470 2470
 		}
2471
-		elseif(dol_strlen($phone) == 13)
2471
+		elseif (dol_strlen($phone) == 13)
2472 2472
 		{//ex: +39_ABC_DEF_GH_IJ
2473
-			$newphone = substr($newphone,0,3).$separ.substr($newphone,3,3).$separ.substr($newphone,6,3).$separ.substr($newphone,9,2).$separ.substr($newphone,11,2);
2473
+			$newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 2).$separ.substr($newphone, 11, 2);
2474 2474
 		}
2475 2475
 	}
2476
-	elseif(strtoupper($countrycode) == "AU")
2476
+	elseif (strtoupper($countrycode) == "AU")
2477 2477
 	{//Australie
2478
-		 if(dol_strlen($phone) == 12)
2478
+		 if (dol_strlen($phone) == 12)
2479 2479
 		{//ex: +61_A_BCDE_FGHI
2480
-			$newphone = substr($newphone,0,3).$separ.substr($newphone,3,1).$separ.substr($newphone,4,4).$separ.substr($newphone,8,4);
2480
+			$newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 1).$separ.substr($newphone, 4, 4).$separ.substr($newphone, 8, 4);
2481 2481
 		}
2482 2482
 	}
2483
-	if (! empty($addlink))	// Link on phone number (+ link to add action if conf->global->AGENDA_ADDACTIONFORPHONE set)
2483
+	if (!empty($addlink))	// Link on phone number (+ link to add action if conf->global->AGENDA_ADDACTIONFORPHONE set)
2484 2484
 	{
2485
-		if (! empty($conf->browser->phone) || (! empty($conf->clicktodial->enabled) && ! empty($conf->global->CLICKTODIAL_USE_TEL_LINK_ON_PHONE_NUMBERS)))	// If phone or option for, we use link of phone
2485
+		if (!empty($conf->browser->phone) || (!empty($conf->clicktodial->enabled) && !empty($conf->global->CLICKTODIAL_USE_TEL_LINK_ON_PHONE_NUMBERS)))	// If phone or option for, we use link of phone
2486 2486
 		{
2487
-			$newphone ='<a href="tel:'.$phone.'"';
2488
-			$newphone.='>'.$phone.'</a>';
2487
+			$newphone = '<a href="tel:'.$phone.'"';
2488
+			$newphone .= '>'.$phone.'</a>';
2489 2489
 		}
2490
-		else if (! empty($conf->clicktodial->enabled) && $addlink == 'AC_TEL')		// If click to dial, we use click to dial url
2490
+		else if (!empty($conf->clicktodial->enabled) && $addlink == 'AC_TEL')		// If click to dial, we use click to dial url
2491 2491
 		{
2492 2492
 			if (empty($user->clicktodial_loaded)) $user->fetch_clicktodial();
2493 2493
 
2494 2494
 			// Define urlmask
2495
-			$urlmask='ErrorClickToDialModuleNotConfigured';
2496
-			if (! empty($conf->global->CLICKTODIAL_URL)) $urlmask=$conf->global->CLICKTODIAL_URL;
2497
-			if (! empty($user->clicktodial_url)) $urlmask=$user->clicktodial_url;
2495
+			$urlmask = 'ErrorClickToDialModuleNotConfigured';
2496
+			if (!empty($conf->global->CLICKTODIAL_URL)) $urlmask = $conf->global->CLICKTODIAL_URL;
2497
+			if (!empty($user->clicktodial_url)) $urlmask = $user->clicktodial_url;
2498 2498
 
2499
-			$clicktodial_poste=(! empty($user->clicktodial_poste)?urlencode($user->clicktodial_poste):'');
2500
-			$clicktodial_login=(! empty($user->clicktodial_login)?urlencode($user->clicktodial_login):'');
2501
-			$clicktodial_password=(! empty($user->clicktodial_password)?urlencode($user->clicktodial_password):'');
2499
+			$clicktodial_poste = (!empty($user->clicktodial_poste) ?urlencode($user->clicktodial_poste) : '');
2500
+			$clicktodial_login = (!empty($user->clicktodial_login) ?urlencode($user->clicktodial_login) : '');
2501
+			$clicktodial_password = (!empty($user->clicktodial_password) ?urlencode($user->clicktodial_password) : '');
2502 2502
 			// This line is for backward compatibility
2503 2503
 			$url = sprintf($urlmask, urlencode($phone), $clicktodial_poste, $clicktodial_login, $clicktodial_password);
2504 2504
 			// Thoose lines are for substitution
2505
-			$substitarray=array('__PHONEFROM__'=>$clicktodial_poste,
2505
+			$substitarray = array('__PHONEFROM__'=>$clicktodial_poste,
2506 2506
 								'__PHONETO__'=>urlencode($phone),
2507 2507
 								'__LOGIN__'=>$clicktodial_login,
2508 2508
 								'__PASS__'=>$clicktodial_password);
2509 2509
 			$url = make_substitutions($url, $substitarray);
2510
-			$newphonesav=$newphone;
2511
-			$newphone ='<a href="'.$url.'"';
2512
-			if (! empty($conf->global->CLICKTODIAL_FORCENEWTARGET)) $newphone.=' target="_blank"';
2513
-			$newphone.='>'.$newphonesav.'</a>';
2510
+			$newphonesav = $newphone;
2511
+			$newphone = '<a href="'.$url.'"';
2512
+			if (!empty($conf->global->CLICKTODIAL_FORCENEWTARGET)) $newphone .= ' target="_blank"';
2513
+			$newphone .= '>'.$newphonesav.'</a>';
2514 2514
 		}
2515 2515
 
2516 2516
 		//if (($cid || $socid) && ! empty($conf->agenda->enabled) && $user->rights->agenda->myactions->create)
2517
-		if (! empty($conf->agenda->enabled) && $user->rights->agenda->myactions->create)
2517
+		if (!empty($conf->agenda->enabled) && $user->rights->agenda->myactions->create)
2518 2518
 		{
2519
-			$type='AC_TEL'; $link='';
2520
-			if ($addlink == 'AC_FAX') $type='AC_FAX';
2521
-			if (! empty($conf->global->AGENDA_ADDACTIONFORPHONE)) $link='<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&amp;backtopage=1&amp;actioncode='.$type.($cid?'&amp;contactid='.$cid:'').($socid?'&amp;socid='.$socid:'').'">'.img_object($langs->trans("AddAction"),"calendar").'</a>';
2522
-			if ($link) $newphone='<div>'.$newphone.' '.$link.'</div>';
2519
+			$type = 'AC_TEL'; $link = '';
2520
+			if ($addlink == 'AC_FAX') $type = 'AC_FAX';
2521
+			if (!empty($conf->global->AGENDA_ADDACTIONFORPHONE)) $link = '<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&amp;backtopage=1&amp;actioncode='.$type.($cid ? '&amp;contactid='.$cid : '').($socid ? '&amp;socid='.$socid : '').'">'.img_object($langs->trans("AddAction"), "calendar").'</a>';
2522
+			if ($link) $newphone = '<div>'.$newphone.' '.$link.'</div>';
2523 2523
 		}
2524 2524
 	}
2525 2525
 
2526 2526
 	if (empty($titlealt))
2527 2527
 	{
2528
-		$titlealt=($withpicto=='fax'?$langs->trans("Fax"):$langs->trans("Phone"));
2528
+		$titlealt = ($withpicto == 'fax' ? $langs->trans("Fax") : $langs->trans("Phone"));
2529 2529
 	}
2530
-	$rep='';
2530
+	$rep = '';
2531 2531
 
2532 2532
 	if ($hookmanager) {
2533
-            $parameters = array('countrycode' => $countrycode, 'cid' => $cid, 'socid' => $socid,'titlealt' => $titlealt, 'picto' => $withpicto);
2533
+            $parameters = array('countrycode' => $countrycode, 'cid' => $cid, 'socid' => $socid, 'titlealt' => $titlealt, 'picto' => $withpicto);
2534 2534
             $reshook = $hookmanager->executeHooks('printPhone', $parameters, $phone);
2535
-            $rep.=$hookmanager->resPrint;
2535
+            $rep .= $hookmanager->resPrint;
2536 2536
         }
2537 2537
 	 if (empty($reshook))
2538 2538
         {
2539 2539
 		$picto = '';
2540
-		if($withpicto){
2541
-			if($withpicto=='fax'){
2540
+		if ($withpicto) {
2541
+			if ($withpicto == 'fax') {
2542 2542
 				$picto = 'phoning_fax';
2543
-			}elseif($withpicto=='phone'){
2543
+			}elseif ($withpicto == 'phone') {
2544 2544
 				$picto = 'phoning';
2545
-			}elseif($withpicto=='mobile'){
2545
+			}elseif ($withpicto == 'mobile') {
2546 2546
 				$picto = 'phoning_mobile';
2547
-			}else{
2547
+			} else {
2548 2548
 				$picto = '';
2549 2549
 			}
2550 2550
 		}
2551
-		if ($adddivfloat) $rep.='<div class="nospan float" style="margin-right: 10px">';
2552
-		else $rep.='<span style="margin-right: 10px;">';
2553
-		$rep.=($withpicto?img_picto($titlealt, 'object_'.$picto.'.png').' ':'').$newphone;
2554
-		if ($adddivfloat) $rep.='</div>';
2555
-		else $rep.='</span>';
2551
+		if ($adddivfloat) $rep .= '<div class="nospan float" style="margin-right: 10px">';
2552
+		else $rep .= '<span style="margin-right: 10px;">';
2553
+		$rep .= ($withpicto ?img_picto($titlealt, 'object_'.$picto.'.png').' ' : '').$newphone;
2554
+		if ($adddivfloat) $rep .= '</div>';
2555
+		else $rep .= '</span>';
2556 2556
 	  }
2557 2557
 
2558 2558
 	return $rep;
@@ -2565,24 +2565,24 @@  discard block
 block discarded – undo
2565 2565
  * 	@param	int		$mode		0=return IP + country/flag, 1=return only country/flag, 2=return only IP
2566 2566
  * 	@return string 				Formated IP, with country if GeoIP module is enabled
2567 2567
  */
2568
-function dol_print_ip($ip,$mode=0)
2568
+function dol_print_ip($ip, $mode = 0)
2569 2569
 {
2570
-	global $conf,$langs;
2570
+	global $conf, $langs;
2571 2571
 
2572
-	$ret='';
2572
+	$ret = '';
2573 2573
 
2574
-	if (empty($mode)) $ret.=$ip;
2574
+	if (empty($mode)) $ret .= $ip;
2575 2575
 
2576 2576
 	if ($mode != 2)
2577 2577
 	{
2578
-		$countrycode=dolGetCountryCodeFromIp($ip);
2578
+		$countrycode = dolGetCountryCodeFromIp($ip);
2579 2579
 		if ($countrycode)	// If success, countrycode is us, fr, ...
2580 2580
 		{
2581 2581
 			if (file_exists(DOL_DOCUMENT_ROOT.'/theme/common/flags/'.$countrycode.'.png'))
2582 2582
 			{
2583
-				$ret.=' '.img_picto($countrycode.' '.$langs->trans("AccordingToGeoIPDatabase"),DOL_URL_ROOT.'/theme/common/flags/'.$countrycode.'.png','',1);
2583
+				$ret .= ' '.img_picto($countrycode.' '.$langs->trans("AccordingToGeoIPDatabase"), DOL_URL_ROOT.'/theme/common/flags/'.$countrycode.'.png', '', 1);
2584 2584
 			}
2585
-			else $ret.=' ('.$countrycode.')';
2585
+			else $ret .= ' ('.$countrycode.')';
2586 2586
 		}
2587 2587
 	}
2588 2588
 
@@ -2599,19 +2599,19 @@  discard block
 block discarded – undo
2599 2599
 {
2600 2600
 	global $conf;
2601 2601
 
2602
-	$countrycode='';
2602
+	$countrycode = '';
2603 2603
 
2604
-	if (! empty($conf->geoipmaxmind->enabled))
2604
+	if (!empty($conf->geoipmaxmind->enabled))
2605 2605
 	{
2606
-		$datafile=$conf->global->GEOIPMAXMIND_COUNTRY_DATAFILE;
2606
+		$datafile = $conf->global->GEOIPMAXMIND_COUNTRY_DATAFILE;
2607 2607
 		//$ip='24.24.24.24';
2608 2608
 		//$datafile='E:\Mes Sites\Web\Admin1\awstats\maxmind\GeoIP.dat';    Note that this must be downloaded datafile (not same than datafile provided with ubuntu packages)
2609 2609
 
2610 2610
 		include_once DOL_DOCUMENT_ROOT.'/core/class/dolgeoip.class.php';
2611
-		$geoip=new DolGeoIP('country',$datafile);
2611
+		$geoip = new DolGeoIP('country', $datafile);
2612 2612
 		//print 'ip='.$ip.' databaseType='.$geoip->gi->databaseType." GEOIP_CITY_EDITION_REV1=".GEOIP_CITY_EDITION_REV1."\n";
2613 2613
 		//print "geoip_country_id_by_addr=".geoip_country_id_by_addr($geoip->gi,$ip)."\n";
2614
-		$countrycode=$geoip->getCountryCodeFromIP($ip);
2614
+		$countrycode = $geoip->getCountryCodeFromIP($ip);
2615 2615
 	}
2616 2616
 
2617 2617
 	return $countrycode;
@@ -2626,20 +2626,20 @@  discard block
 block discarded – undo
2626 2626
  */
2627 2627
 function dol_user_country()
2628 2628
 {
2629
-	global $conf,$langs,$user;
2629
+	global $conf, $langs, $user;
2630 2630
 
2631 2631
 	//$ret=$user->xxx;
2632
-	$ret='';
2633
-	if (! empty($conf->geoipmaxmind->enabled))
2632
+	$ret = '';
2633
+	if (!empty($conf->geoipmaxmind->enabled))
2634 2634
 	{
2635
-		$ip=$_SERVER["REMOTE_ADDR"];
2636
-		$datafile=$conf->global->GEOIPMAXMIND_COUNTRY_DATAFILE;
2635
+		$ip = $_SERVER["REMOTE_ADDR"];
2636
+		$datafile = $conf->global->GEOIPMAXMIND_COUNTRY_DATAFILE;
2637 2637
 		//$ip='24.24.24.24';
2638 2638
 		//$datafile='E:\Mes Sites\Web\Admin1\awstats\maxmind\GeoIP.dat';
2639 2639
 		include_once DOL_DOCUMENT_ROOT.'/core/class/dolgeoip.class.php';
2640
-		$geoip=new DolGeoIP('country',$datafile);
2641
-		$countrycode=$geoip->getCountryCodeFromIP($ip);
2642
-		$ret=$countrycode;
2640
+		$geoip = new DolGeoIP('country', $datafile);
2641
+		$countrycode = $geoip->getCountryCodeFromIP($ip);
2642
+		$ret = $countrycode;
2643 2643
 	}
2644 2644
 	return $ret;
2645 2645
 }
@@ -2656,7 +2656,7 @@  discard block
 block discarded – undo
2656 2656
  *  @return string|void			Nothing if noprint is 0, formatted address if noprint is 1
2657 2657
  *  @see dol_format_address
2658 2658
  */
2659
-function dol_print_address($address, $htmlid, $mode, $id, $noprint=0, $charfornl='')
2659
+function dol_print_address($address, $htmlid, $mode, $id, $noprint = 0, $charfornl = '')
2660 2660
 {
2661 2661
 	global $conf, $user, $langs, $hookmanager;
2662 2662
 
@@ -2667,32 +2667,32 @@  discard block
 block discarded – undo
2667 2667
 		if ($hookmanager) {
2668 2668
 			$parameters = array('element' => $mode, 'id' => $id);
2669 2669
 			$reshook = $hookmanager->executeHooks('printAddress', $parameters, $address);
2670
-			$out.=$hookmanager->resPrint;
2670
+			$out .= $hookmanager->resPrint;
2671 2671
 		}
2672 2672
 		if (empty($reshook))
2673 2673
 		{
2674
-			if (empty($charfornl)) $out.=nl2br($address);
2675
-			else $out.=preg_replace('/[\r\n]+/', $charfornl, $address);
2674
+			if (empty($charfornl)) $out .= nl2br($address);
2675
+			else $out .= preg_replace('/[\r\n]+/', $charfornl, $address);
2676 2676
 
2677
-			$showgmap=$showomap=0;
2677
+			$showgmap = $showomap = 0;
2678 2678
 
2679 2679
 			// TODO Add a hook here
2680
-			if (($mode=='thirdparty' || $mode =='societe') && ! empty($conf->google->enabled) && ! empty($conf->global->GOOGLE_ENABLE_GMAPS)) $showgmap=1;
2681
-			if ($mode=='contact' && ! empty($conf->google->enabled) && ! empty($conf->global->GOOGLE_ENABLE_GMAPS_CONTACTS)) $showgmap=1;
2682
-			if ($mode=='member' && ! empty($conf->google->enabled) && ! empty($conf->global->GOOGLE_ENABLE_GMAPS_MEMBERS)) $showgmap=1;
2683
-			if (($mode=='thirdparty' || $mode =='societe') && ! empty($conf->openstreetmap->enabled) && ! empty($conf->global->OPENSTREETMAP_ENABLE_MAPS)) $showomap=1;
2684
-			if ($mode=='contact' && ! empty($conf->openstreetmap->enabled) && ! empty($conf->global->OPENSTREETMAP_ENABLE_MAPS_CONTACTS)) $showomap=1;
2685
-			if ($mode=='member' && ! empty($conf->openstreetmap->enabled) && ! empty($conf->global->OPENSTREETMAP_ENABLE_MAPS_MEMBERS)) $showomap=1;
2680
+			if (($mode == 'thirdparty' || $mode == 'societe') && !empty($conf->google->enabled) && !empty($conf->global->GOOGLE_ENABLE_GMAPS)) $showgmap = 1;
2681
+			if ($mode == 'contact' && !empty($conf->google->enabled) && !empty($conf->global->GOOGLE_ENABLE_GMAPS_CONTACTS)) $showgmap = 1;
2682
+			if ($mode == 'member' && !empty($conf->google->enabled) && !empty($conf->global->GOOGLE_ENABLE_GMAPS_MEMBERS)) $showgmap = 1;
2683
+			if (($mode == 'thirdparty' || $mode == 'societe') && !empty($conf->openstreetmap->enabled) && !empty($conf->global->OPENSTREETMAP_ENABLE_MAPS)) $showomap = 1;
2684
+			if ($mode == 'contact' && !empty($conf->openstreetmap->enabled) && !empty($conf->global->OPENSTREETMAP_ENABLE_MAPS_CONTACTS)) $showomap = 1;
2685
+			if ($mode == 'member' && !empty($conf->openstreetmap->enabled) && !empty($conf->global->OPENSTREETMAP_ENABLE_MAPS_MEMBERS)) $showomap = 1;
2686 2686
 
2687 2687
 			if ($showgmap)
2688 2688
 			{
2689
-				$url=dol_buildpath('/google/gmaps.php?mode='.$mode.'&id='.$id,1);
2690
-				$out.=' <a href="'.$url.'" target="_gmaps"><img id="'.$htmlid.'" class="valigntextbottom" src="'.DOL_URL_ROOT.'/theme/common/gmap.png"></a>';
2689
+				$url = dol_buildpath('/google/gmaps.php?mode='.$mode.'&id='.$id, 1);
2690
+				$out .= ' <a href="'.$url.'" target="_gmaps"><img id="'.$htmlid.'" class="valigntextbottom" src="'.DOL_URL_ROOT.'/theme/common/gmap.png"></a>';
2691 2691
 			}
2692 2692
 			if ($showomap)
2693 2693
 			{
2694
-				$url=dol_buildpath('/openstreetmap/maps.php?mode='.$mode.'&id='.$id,1);
2695
-				$out.=' <a href="'.$url.'" target="_gmaps"><img id="'.$htmlid.'_openstreetmap" class="valigntextbottom" src="'.DOL_URL_ROOT.'/theme/common/gmap.png"></a>';
2694
+				$url = dol_buildpath('/openstreetmap/maps.php?mode='.$mode.'&id='.$id, 1);
2695
+				$out .= ' <a href="'.$url.'" target="_gmaps"><img id="'.$htmlid.'_openstreetmap" class="valigntextbottom" src="'.DOL_URL_ROOT.'/theme/common/gmap.png"></a>';
2696 2696
 			}
2697 2697
 		}
2698 2698
 	}
@@ -2708,7 +2708,7 @@  discard block
 block discarded – undo
2708 2708
  *  @param		int			$acceptsupervisorkey	If 1, the special string '__SUPERVISOREMAIL__' is also accepted as valid
2709 2709
  *	@return     boolean     						true if email syntax is OK, false if KO or empty string
2710 2710
  */
2711
-function isValidEmail($address, $acceptsupervisorkey=0)
2711
+function isValidEmail($address, $acceptsupervisorkey = 0)
2712 2712
 {
2713 2713
 	if ($acceptsupervisorkey && $address == '__SUPERVISOREMAIL__') return true;
2714 2714
 	if (filter_var($address, FILTER_VALIDATE_EMAIL)) return true;
@@ -2736,9 +2736,9 @@  discard block
 block discarded – undo
2736 2736
  * @param   string		$stringencoding		Encoding of string
2737 2737
  * @return  int								Length of string
2738 2738
  */
2739
-function dol_strlen($string,$stringencoding='UTF-8')
2739
+function dol_strlen($string, $stringencoding = 'UTF-8')
2740 2740
 {
2741
-	if (function_exists('mb_strlen')) return mb_strlen($string,$stringencoding);
2741
+	if (function_exists('mb_strlen')) return mb_strlen($string, $stringencoding);
2742 2742
 	else return strlen($string);
2743 2743
 }
2744 2744
 
@@ -2751,20 +2751,20 @@  discard block
 block discarded – undo
2751 2751
  * @param   string	$stringencoding		Page code used for input string encoding
2752 2752
  * @return  string						substring
2753 2753
  */
2754
-function dol_substr($string,$start,$length,$stringencoding='')
2754
+function dol_substr($string, $start, $length, $stringencoding = '')
2755 2755
 {
2756 2756
 	global $langs;
2757 2757
 
2758
-	if (empty($stringencoding)) $stringencoding=$langs->charset_output;
2758
+	if (empty($stringencoding)) $stringencoding = $langs->charset_output;
2759 2759
 
2760
-	$ret='';
2760
+	$ret = '';
2761 2761
 	if (function_exists('mb_substr'))
2762 2762
 	{
2763
-		$ret=mb_substr($string,$start,$length,$stringencoding);
2763
+		$ret = mb_substr($string, $start, $length, $stringencoding);
2764 2764
 	}
2765 2765
 	else
2766 2766
 	{
2767
-		$ret=substr($string,$start,$length);
2767
+		$ret = substr($string, $start, $length);
2768 2768
 	}
2769 2769
 	return $ret;
2770 2770
 }
@@ -2788,12 +2788,12 @@  discard block
 block discarded – undo
2788 2788
  *  @deprecated
2789 2789
  *  @see DolGraph
2790 2790
  */
2791
-function dol_print_graph($htmlid,$width,$height,$data,$showlegend=0,$type='pie',$showpercent=0,$url='',$combineother=0.05,$shownographyet=0)
2791
+function dol_print_graph($htmlid, $width, $height, $data, $showlegend = 0, $type = 'pie', $showpercent = 0, $url = '', $combineother = 0.05, $shownographyet = 0)
2792 2792
 {
2793
-	dol_syslog(__FUNCTION__ . " is deprecated", LOG_WARNING);
2793
+	dol_syslog(__FUNCTION__." is deprecated", LOG_WARNING);
2794 2794
 
2795
-	global $conf,$langs;
2796
-	global $theme_datacolor;    // To have var kept when function is called several times
2795
+	global $conf, $langs;
2796
+	global $theme_datacolor; // To have var kept when function is called several times
2797 2797
 
2798 2798
 	if ($shownographyet)
2799 2799
 	{
@@ -2803,8 +2803,8 @@  discard block
 block discarded – undo
2803 2803
 	}
2804 2804
 
2805 2805
 	if (empty($conf->use_javascript_ajax)) return;
2806
-	$jsgraphlib='flot';
2807
-	$datacolor=array();
2806
+	$jsgraphlib = 'flot';
2807
+	$datacolor = array();
2808 2808
 
2809 2809
 	// Load colors of theme into $datacolor array
2810 2810
 	$color_file = DOL_DOCUMENT_ROOT."/theme/".$conf->theme."/graph-color.php";
@@ -2813,10 +2813,10 @@  discard block
 block discarded – undo
2813 2813
 		include_once $color_file;
2814 2814
 		if (isset($theme_datacolor))
2815 2815
 		{
2816
-			$datacolor=array();
2817
-			foreach($theme_datacolor as $val)
2816
+			$datacolor = array();
2817
+			foreach ($theme_datacolor as $val)
2818 2818
 			{
2819
-				$datacolor[]="#".sprintf("%02x",$val[0]).sprintf("%02x",$val[1]).sprintf("%02x",$val[2]);
2819
+				$datacolor[] = "#".sprintf("%02x", $val[0]).sprintf("%02x", $val[1]).sprintf("%02x", $val[2]);
2820 2820
 			}
2821 2821
 		}
2822 2822
 	}
@@ -2861,8 +2861,8 @@  discard block
 block discarded – undo
2861 2861
 										return \'';
2862 2862
 										print '<div style="font-size:8pt;text-align:center;padding:2px;color:black;">';
2863 2863
 										if ($url) print '<a style="color: #FFFFFF;" border="0" href="'.$url.'">';
2864
-										print '\'+'.($showlegend?'number':'label+\' \'+number');
2865
-										if (! empty($showpercent)) print '+\'<br/>\'+percent+\'%\'';
2864
+										print '\'+'.($showlegend ? 'number' : 'label+\' \'+number');
2865
+										if (!empty($showpercent)) print '+\'<br/>\'+percent+\'%\'';
2866 2866
 										print '+\'';
2867 2867
 										if ($url) print '</a>';
2868 2868
 										print '</div>\';
@@ -2882,9 +2882,9 @@  discard block
 block discarded – undo
2882 2882
 						},';
2883 2883
 						if (count($datacolor))
2884 2884
 						{
2885
-							print 'colors: '.(! empty($data['seriescolor']) ? json_encode($data['seriescolor']) : json_encode($datacolor)).',';
2885
+							print 'colors: '.(!empty($data['seriescolor']) ? json_encode($data['seriescolor']) : json_encode($datacolor)).',';
2886 2886
 						}
2887
-						print 'legend: {show: '.($showlegend?'true':'false').', position: \'ne\' }
2887
+						print 'legend: {show: '.($showlegend ? 'true' : 'false').', position: \'ne\' }
2888 2888
 					});
2889 2889
 				}
2890 2890
 				plotWithOptions();
@@ -2902,10 +2902,10 @@  discard block
 block discarded – undo
2902 2902
 			<script type="text/javascript">
2903 2903
 			$(function () {
2904 2904
 				var data = [';
2905
-				$i=0; $outputserie=0;
2906
-				foreach($data['series'] as $serie)
2905
+				$i = 0; $outputserie = 0;
2906
+				foreach ($data['series'] as $serie)
2907 2907
 				{
2908
-					if ($data['seriestype'][$i]=='line') { $i++; continue; };
2908
+					if ($data['seriestype'][$i] == 'line') { $i++; continue; };
2909 2909
 					if ($outputserie > 0) print ',';
2910 2910
 					print '{ bars: { stack: 0, show: true, barWidth: 0.9, align: \'center\' }, label: \''.dol_escape_js($serie['label']).'\', data: '.json_encode($serie['data']).'}'."\n";
2911 2911
 					$outputserie++; $i++;
@@ -2913,10 +2913,10 @@  discard block
 block discarded – undo
2913 2913
 				if ($outputserie) print ', ';
2914 2914
 				//print '];
2915 2915
 				//var datalines = [';
2916
-				$i=0; $outputserie=0;
2917
-				foreach($data['series'] as $serie)
2916
+				$i = 0; $outputserie = 0;
2917
+				foreach ($data['series'] as $serie)
2918 2918
 				{
2919
-					if (empty($data['seriestype'][$i]) || $data['seriestype'][$i]=='bar') { $i++; continue; };
2919
+					if (empty($data['seriestype'][$i]) || $data['seriestype'][$i] == 'bar') { $i++; continue; };
2920 2920
 					if ($outputserie > 0) print ',';
2921 2921
 					print '{ lines: { show: true }, label: \''.dol_escape_js($serie['label']).'\', data: '.json_encode($serie['data']).'}'."\n";
2922 2922
 					$outputserie++; $i++;
@@ -2940,7 +2940,7 @@  discard block
 block discarded – undo
2940 2940
 						{
2941 2941
 							print 'colors: '.json_encode($datacolor).',';
2942 2942
 						}
2943
-						print 'legend: {show: '.($showlegend?'true':'false').'},
2943
+						print 'legend: {show: '.($showlegend ? 'true' : 'false').'},
2944 2944
 						xaxis: {ticks: dataticks}
2945 2945
 					});
2946 2946
 				}
@@ -2965,51 +2965,51 @@  discard block
 block discarded – undo
2965 2965
  *  @param  int     $display            Trunc is use to display and can be changed for small screen. TODO Remove this param (must be dealt with CSS)
2966 2966
  *	@return string						Truncated string. WARNING: length is never higher than $size if $nodot is set, but can be 3 chars higher otherwise.
2967 2967
  */
2968
-function dol_trunc($string,$size=40,$trunc='right',$stringencoding='UTF-8',$nodot=0, $display=0)
2968
+function dol_trunc($string, $size = 40, $trunc = 'right', $stringencoding = 'UTF-8', $nodot = 0, $display = 0)
2969 2969
 {
2970 2970
 	global $conf;
2971 2971
 
2972
-	if ($size==0 || ! empty($conf->global->MAIN_DISABLE_TRUNC)) return $string;
2972
+	if ($size == 0 || !empty($conf->global->MAIN_DISABLE_TRUNC)) return $string;
2973 2973
 
2974
-	if (empty($stringencoding)) $stringencoding='UTF-8';
2974
+	if (empty($stringencoding)) $stringencoding = 'UTF-8';
2975 2975
 	// reduce for small screen
2976
-	if ($conf->dol_optimize_smallscreen==1 && $display==1) $size = round($size/3);
2976
+	if ($conf->dol_optimize_smallscreen == 1 && $display == 1) $size = round($size / 3);
2977 2977
 
2978 2978
 	// We go always here
2979 2979
 	if ($trunc == 'right')
2980 2980
 	{
2981
-		$newstring=dol_textishtml($string)?dol_string_nohtmltag($string,1):$string;
2982
-		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 ...
2983
-		return dol_substr($newstring,0,$size,$stringencoding).($nodot?'':'...');
2981
+		$newstring = dol_textishtml($string) ?dol_string_nohtmltag($string, 1) : $string;
2982
+		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 ...
2983
+		return dol_substr($newstring, 0, $size, $stringencoding).($nodot ? '' : '...');
2984 2984
 		else
2985 2985
 		//return 'u'.$size.'-'.$newstring.'-'.dol_strlen($newstring,$stringencoding).'-'.$string;
2986 2986
 		return $string;
2987 2987
 	}
2988 2988
 	elseif ($trunc == 'middle')
2989 2989
 	{
2990
-		$newstring=dol_textishtml($string)?dol_string_nohtmltag($string,1):$string;
2991
-		if (dol_strlen($newstring,$stringencoding) > 2 && dol_strlen($newstring,$stringencoding) > ($size+1))
2990
+		$newstring = dol_textishtml($string) ?dol_string_nohtmltag($string, 1) : $string;
2991
+		if (dol_strlen($newstring, $stringencoding) > 2 && dol_strlen($newstring, $stringencoding) > ($size + 1))
2992 2992
 		{
2993
-			$size1=round($size/2);
2994
-			$size2=round($size/2);
2995
-			return dol_substr($newstring,0,$size1,$stringencoding).'...'.dol_substr($newstring,dol_strlen($newstring,$stringencoding) - $size2,$size2,$stringencoding);
2993
+			$size1 = round($size / 2);
2994
+			$size2 = round($size / 2);
2995
+			return dol_substr($newstring, 0, $size1, $stringencoding).'...'.dol_substr($newstring, dol_strlen($newstring, $stringencoding) - $size2, $size2, $stringencoding);
2996 2996
 		}
2997 2997
 		else
2998 2998
 		return $string;
2999 2999
 	}
3000 3000
 	elseif ($trunc == 'left')
3001 3001
 	{
3002
-		$newstring=dol_textishtml($string)?dol_string_nohtmltag($string,1):$string;
3003
-		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 ...
3004
-		return '...'.dol_substr($newstring,dol_strlen($newstring,$stringencoding) - $size,$size,$stringencoding);
3002
+		$newstring = dol_textishtml($string) ?dol_string_nohtmltag($string, 1) : $string;
3003
+		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 ...
3004
+		return '...'.dol_substr($newstring, dol_strlen($newstring, $stringencoding) - $size, $size, $stringencoding);
3005 3005
 		else
3006 3006
 		return $string;
3007 3007
 	}
3008 3008
 	elseif ($trunc == 'wrap')
3009 3009
 	{
3010
-		$newstring=dol_textishtml($string)?dol_string_nohtmltag($string,1):$string;
3011
-		if (dol_strlen($newstring,$stringencoding) > ($size+1))
3012
-		return dol_substr($newstring,0,$size,$stringencoding)."\n".dol_trunc(dol_substr($newstring,$size,dol_strlen($newstring,$stringencoding)-$size,$stringencoding),$size,$trunc);
3010
+		$newstring = dol_textishtml($string) ?dol_string_nohtmltag($string, 1) : $string;
3011
+		if (dol_strlen($newstring, $stringencoding) > ($size + 1))
3012
+		return dol_substr($newstring, 0, $size, $stringencoding)."\n".dol_trunc(dol_substr($newstring, $size, dol_strlen($newstring, $stringencoding) - $size, $stringencoding), $size, $trunc);
3013 3013
 		else
3014 3014
 		return $string;
3015 3015
 	}
@@ -3034,7 +3034,7 @@  discard block
 block discarded – undo
3034 3034
  *  @return     string       				    Return img tag
3035 3035
  *  @see        #img_object, #img_picto_common
3036 3036
  */
3037
-function img_picto($titlealt, $picto, $moreatt = '', $pictoisfullpath = false, $srconly=0, $notitle=0, $alt='', $morecss='')
3037
+function img_picto($titlealt, $picto, $moreatt = '', $pictoisfullpath = false, $srconly = 0, $notitle = 0, $alt = '', $morecss = '')
3038 3038
 {
3039 3039
 	global $conf, $langs;
3040 3040
 
@@ -3042,7 +3042,7 @@  discard block
 block discarded – undo
3042 3042
 	if ($pictoisfullpath)
3043 3043
 	{
3044 3044
 		// Clean parameters
3045
-		if (! preg_match('/(\.png|\.gif|\.svg)$/i',$picto)) $picto .= '.png';
3045
+		if (!preg_match('/(\.png|\.gif|\.svg)$/i', $picto)) $picto .= '.png';
3046 3046
 		$fullpathpicto = $picto;
3047 3047
 	}
3048 3048
 	else
@@ -3050,15 +3050,15 @@  discard block
 block discarded – undo
3050 3050
 		//if (in_array($picto, array('switch_off', 'switch_on', 'off', 'on')))
3051 3051
 		if (in_array($picto, array('switch_off', 'switch_on', 'off', 'on')))
3052 3052
 		{
3053
-			$fakey = $picto; $facolor=''; $fasize='';
3054
-			if ($picto == 'switch_off') { $fakey = 'fa-toggle-off'; $facolor='#999';    $fasize='2em'; }
3055
-			if ($picto == 'switch_on')  { $fakey = 'fa-toggle-on';  $facolor='#227722'; $fasize='2em'; }
3056
-			if ($picto == 'off') { $fakey = 'fa-square-o'; $fasize='1.3em'; }
3057
-			if ($picto == 'on')  { $fakey = 'fa-check-square-o'; $fasize='1.3em'; }
3058
-			$enabledisablehtml='';
3059
-			$enabledisablehtml.='<span class="fa '.$fakey.' valignmiddle'.($morecss?' '.$morecss:'').'" style="'.($fasize?('font-size: '.$fasize.';'):'').($facolor?(' color: '.$facolor.';'):'').'" alt="'.dol_escape_htmltag($titlealt).'" title="'.dol_escape_htmltag($titlealt).'"'.($moreatt?' '.$moreatt:'').'">';
3060
-			if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) $enabledisablehtml.=$titlealt;
3061
-			$enabledisablehtml.='</span>';
3053
+			$fakey = $picto; $facolor = ''; $fasize = '';
3054
+			if ($picto == 'switch_off') { $fakey = 'fa-toggle-off'; $facolor = '#999'; $fasize = '2em'; }
3055
+			if ($picto == 'switch_on') { $fakey = 'fa-toggle-on'; $facolor = '#227722'; $fasize = '2em'; }
3056
+			if ($picto == 'off') { $fakey = 'fa-square-o'; $fasize = '1.3em'; }
3057
+			if ($picto == 'on') { $fakey = 'fa-check-square-o'; $fasize = '1.3em'; }
3058
+			$enabledisablehtml = '';
3059
+			$enabledisablehtml .= '<span class="fa '.$fakey.' valignmiddle'.($morecss ? ' '.$morecss : '').'" style="'.($fasize ? ('font-size: '.$fasize.';') : '').($facolor ? (' color: '.$facolor.';') : '').'" alt="'.dol_escape_htmltag($titlealt).'" title="'.dol_escape_htmltag($titlealt).'"'.($moreatt ? ' '.$moreatt : '').'">';
3060
+			if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) $enabledisablehtml .= $titlealt;
3061
+			$enabledisablehtml .= '</span>';
3062 3062
 			return $enabledisablehtml;
3063 3063
 		}
3064 3064
 
@@ -3067,26 +3067,26 @@  discard block
 block discarded – undo
3067 3067
 		$theme = $conf->theme;
3068 3068
 
3069 3069
 		$path = 'theme/'.$theme;
3070
-		if (! empty($conf->global->MAIN_OVERWRITE_THEME_PATH)) $path = $conf->global->MAIN_OVERWRITE_THEME_PATH.'/theme/'.$theme;	// If the theme does not have the same name as the module
3071
-		else if (! empty($conf->global->MAIN_OVERWRITE_THEME_RES)) $path = $conf->global->MAIN_OVERWRITE_THEME_RES.'/theme/'.$conf->global->MAIN_OVERWRITE_THEME_RES;  // To allow an external module to overwrite image resources whatever is activated theme
3072
-		else if (! empty($conf->modules_parts['theme']) && array_key_exists($theme, $conf->modules_parts['theme'])) $path = $theme.'/theme/'.$theme;	// If the theme have the same name as the module
3070
+		if (!empty($conf->global->MAIN_OVERWRITE_THEME_PATH)) $path = $conf->global->MAIN_OVERWRITE_THEME_PATH.'/theme/'.$theme; // If the theme does not have the same name as the module
3071
+		else if (!empty($conf->global->MAIN_OVERWRITE_THEME_RES)) $path = $conf->global->MAIN_OVERWRITE_THEME_RES.'/theme/'.$conf->global->MAIN_OVERWRITE_THEME_RES; // To allow an external module to overwrite image resources whatever is activated theme
3072
+		else if (!empty($conf->modules_parts['theme']) && array_key_exists($theme, $conf->modules_parts['theme'])) $path = $theme.'/theme/'.$theme; // If the theme have the same name as the module
3073 3073
 
3074 3074
 		// If we ask an image into $url/$mymodule/img (instead of default path)
3075
-		if (preg_match('/^([^@]+)@([^@]+)$/i',$picto,$regs))
3075
+		if (preg_match('/^([^@]+)@([^@]+)$/i', $picto, $regs))
3076 3076
 		{
3077 3077
 			$picto = $regs[1];
3078
-			$path = $regs[2];	// $path is $mymodule
3078
+			$path = $regs[2]; // $path is $mymodule
3079 3079
 		}
3080 3080
 
3081 3081
 		// Clean parameters
3082
-		if (! preg_match('/(\.png|\.gif|\.svg)$/i',$picto)) $picto .= '.png';
3082
+		if (!preg_match('/(\.png|\.gif|\.svg)$/i', $picto)) $picto .= '.png';
3083 3083
 		// If alt path are defined, define url where img file is, according to physical path
3084 3084
 		foreach ($conf->file->dol_document_root as $type => $dirroot)	// ex: array(["main"]=>"/home/maindir/htdocs", ["alt0"]=>"/home/moddir0/htdocs", ...)
3085 3085
 		{
3086 3086
 			if ($type == 'main') continue;
3087 3087
 			if (file_exists($dirroot.'/'.$path.'/img/'.$picto))	// This need a lot of time, that's why enabling alternative dir like "custom" dir is not recommanded
3088 3088
 			{
3089
-				$url=DOL_URL_ROOT.$conf->file->dol_url_root[$type];
3089
+				$url = DOL_URL_ROOT.$conf->file->dol_url_root[$type];
3090 3090
 				break;
3091 3091
 			}
3092 3092
 		}
@@ -3103,8 +3103,8 @@  discard block
 block discarded – undo
3103 3103
 		//if (empty($notitle) && preg_match('/:[^\s0-9]/',$titlealt)) $tmparray=explode(':',$titlealt);		// We explode if we have TextA:TextB. Not if we have TextA: TextB
3104 3104
 		//$title=$tmparray[0];
3105 3105
 		//$alt=empty($tmparray[1])?'':$tmparray[1];
3106
-		$title=$titlealt;
3107
-		return '<img src="'.$fullpathpicto.'" alt="'.dol_escape_htmltag($alt).'"'.(($notitle || empty($title))?'':' title="'.dol_escape_htmltag($title).'"').($moreatt?' '.$moreatt:' class="inline-block"').'>';	// Alt is used for accessibility, title for popup
3106
+		$title = $titlealt;
3107
+		return '<img src="'.$fullpathpicto.'" alt="'.dol_escape_htmltag($alt).'"'.(($notitle || empty($title)) ? '' : ' title="'.dol_escape_htmltag($title).'"').($moreatt ? ' '.$moreatt : ' class="inline-block"').'>'; // Alt is used for accessibility, title for popup
3108 3108
 	}
3109 3109
 }
3110 3110
 
@@ -3121,7 +3121,7 @@  discard block
 block discarded – undo
3121 3121
  *	@return	string						Return img tag
3122 3122
  *	@see	#img_picto, #img_picto_common
3123 3123
  */
3124
-function img_object($titlealt, $picto, $moreatt = '', $pictoisfullpath = false, $srconly=0, $notitle=0)
3124
+function img_object($titlealt, $picto, $moreatt = '', $pictoisfullpath = false, $srconly = 0, $notitle = 0)
3125 3125
 {
3126 3126
 	return img_picto($titlealt, 'object_'.$picto, $moreatt, $pictoisfullpath, $srconly, $notitle);
3127 3127
 }
@@ -3140,7 +3140,7 @@  discard block
 block discarded – undo
3140 3140
 {
3141 3141
 	global $conf;
3142 3142
 
3143
-	if (! preg_match('/(\.png|\.gif)$/i', $picto)) $picto .= '.png';
3143
+	if (!preg_match('/(\.png|\.gif)$/i', $picto)) $picto .= '.png';
3144 3144
 
3145 3145
 	$path = DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/weather/'.$picto;
3146 3146
 
@@ -3161,14 +3161,14 @@  discard block
 block discarded – undo
3161 3161
 {
3162 3162
 	global $conf;
3163 3163
 
3164
-	if (! preg_match('/(\.png|\.gif)$/i', $picto)) $picto .= '.png';
3164
+	if (!preg_match('/(\.png|\.gif)$/i', $picto)) $picto .= '.png';
3165 3165
 
3166 3166
 	if ($pictoisfullpath) $path = $picto;
3167 3167
 	else
3168 3168
 	{
3169 3169
 		$path = DOL_URL_ROOT.'/theme/common/'.$picto;
3170 3170
 
3171
-		if (! empty($conf->global->MAIN_MODULE_CAN_OVERWRITE_COMMONICONS))
3171
+		if (!empty($conf->global->MAIN_MODULE_CAN_OVERWRITE_COMMONICONS))
3172 3172
 		{
3173 3173
 			$themepath = DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/img/'.$picto;
3174 3174
 
@@ -3192,14 +3192,14 @@  discard block
 block discarded – undo
3192 3192
 
3193 3193
 	if (empty($titlealt) || $titlealt == 'default')
3194 3194
 	{
3195
-		if ($numaction == '-1' || $numaction == 'ST_NO')			{ $numaction = -1; $titlealt = $langs->transnoentitiesnoconv('ChangeDoNotContact'); }
3196
-		elseif ($numaction ==  '0' || $numaction == 'ST_NEVER') 	{ $numaction = 0; $titlealt = $langs->transnoentitiesnoconv('ChangeNeverContacted'); }
3197
-		elseif ($numaction ==  '1' || $numaction == 'ST_TODO')  	{ $numaction = 1; $titlealt = $langs->transnoentitiesnoconv('ChangeToContact'); }
3198
-		elseif ($numaction ==  '2' || $numaction == 'ST_PEND')  	{ $numaction = 2; $titlealt = $langs->transnoentitiesnoconv('ChangeContactInProcess'); }
3199
-		elseif ($numaction ==  '3' || $numaction == 'ST_DONE')  	{ $numaction = 3; $titlealt = $langs->transnoentitiesnoconv('ChangeContactDone'); }
3195
+		if ($numaction == '-1' || $numaction == 'ST_NO') { $numaction = -1; $titlealt = $langs->transnoentitiesnoconv('ChangeDoNotContact'); }
3196
+		elseif ($numaction == '0' || $numaction == 'ST_NEVER') { $numaction = 0; $titlealt = $langs->transnoentitiesnoconv('ChangeNeverContacted'); }
3197
+		elseif ($numaction == '1' || $numaction == 'ST_TODO') { $numaction = 1; $titlealt = $langs->transnoentitiesnoconv('ChangeToContact'); }
3198
+		elseif ($numaction == '2' || $numaction == 'ST_PEND') { $numaction = 2; $titlealt = $langs->transnoentitiesnoconv('ChangeContactInProcess'); }
3199
+		elseif ($numaction == '3' || $numaction == 'ST_DONE') { $numaction = 3; $titlealt = $langs->transnoentitiesnoconv('ChangeContactDone'); }
3200 3200
 		else { $titlealt = $langs->transnoentitiesnoconv('ChangeStatus '.$numaction); $numaction = 0; }
3201 3201
 	}
3202
-	if (! is_numeric($numaction)) $numaction=0;
3202
+	if (!is_numeric($numaction)) $numaction = 0;
3203 3203
 
3204 3204
 	return img_picto($titlealt, 'stcomm'.$numaction.'.png');
3205 3205
 }
@@ -3242,7 +3242,7 @@  discard block
 block discarded – undo
3242 3242
  *	@param  string	$other      Add more attributes on img
3243 3243
  *	@return string      		Return tag img
3244 3244
  */
3245
-function img_edit_remove($titlealt = 'default', $other='')
3245
+function img_edit_remove($titlealt = 'default', $other = '')
3246 3246
 {
3247 3247
 	global $conf, $langs;
3248 3248
 
@@ -3265,7 +3265,7 @@  discard block
 block discarded – undo
3265 3265
 
3266 3266
 	if ($titlealt == 'default') $titlealt = $langs->trans('Modify');
3267 3267
 
3268
-	return img_picto($titlealt, 'edit.png', ($float ? 'style="float: '.($langs->tab_translate["DIRECTION"] == 'rtl'?'left':'right').'"' : "") . ($other?' '.$other:''));
3268
+	return img_picto($titlealt, 'edit.png', ($float ? 'style="float: '.($langs->tab_translate["DIRECTION"] == 'rtl' ? 'left' : 'right').'"' : "").($other ? ' '.$other : ''));
3269 3269
 }
3270 3270
 
3271 3271
 /**
@@ -3310,11 +3310,11 @@  discard block
 block discarded – undo
3310 3310
  *  @param  string  $other      Add more attributes on img
3311 3311
  *  @return string              Retourne tag img
3312 3312
  */
3313
-function img_printer($titlealt = "default", $other='')
3313
+function img_printer($titlealt = "default", $other = '')
3314 3314
 {
3315
-	global $conf,$langs;
3316
-	if ($titlealt=="default") $titlealt=$langs->trans("Print");
3317
-	return img_picto($titlealt,'printer.png',$other);
3315
+	global $conf, $langs;
3316
+	if ($titlealt == "default") $titlealt = $langs->trans("Print");
3317
+	return img_picto($titlealt, 'printer.png', $other);
3318 3318
 }
3319 3319
 
3320 3320
 /**
@@ -3350,7 +3350,7 @@  discard block
 block discarded – undo
3350 3350
 		else $usealttitle = $langs->trans('Info');
3351 3351
 	}
3352 3352
 
3353
-	return img_picto($usealttitle, 'info.png', 'style="vertical-align: middle;'.($usehelpcursor == 1 ? ' cursor: help': ($usehelpcursor == 2 ? ' cursor: pointer':'')).'"');
3353
+	return img_picto($usealttitle, 'info.png', 'style="vertical-align: middle;'.($usehelpcursor == 1 ? ' cursor: help' : ($usehelpcursor == 2 ? ' cursor: pointer' : '')).'"');
3354 3354
 }
3355 3355
 
3356 3356
 /**
@@ -3382,7 +3382,7 @@  discard block
 block discarded – undo
3382 3382
 	if ($titlealt == 'default') $titlealt = $langs->trans('Warning');
3383 3383
 
3384 3384
 	//return '<div class="imglatecoin">'.img_picto($titlealt, 'warning_white.png', 'class="pictowarning valignmiddle"'.($moreatt ? ($moreatt == '1' ? ' style="float: right"' : ' '.$moreatt): '')).'</div>';
3385
-	return img_picto($titlealt, 'warning.png', 'class="pictowarning valignmiddle"'.($moreatt ? ($moreatt == '1' ? ' style="float: right"' : ' '.$moreatt): ''));
3385
+	return img_picto($titlealt, 'warning.png', 'class="pictowarning valignmiddle"'.($moreatt ? ($moreatt == '1' ? ' style="float: right"' : ' '.$moreatt) : ''));
3386 3386
 }
3387 3387
 
3388 3388
 /**
@@ -3407,7 +3407,7 @@  discard block
 block discarded – undo
3407 3407
 *	@param	string	$moreatt	Add more attribute on img tag (For example 'style="float: right"')
3408 3408
  *	@return string      		Return img tag
3409 3409
  */
3410
-function img_next($titlealt = 'default', $moreatt='')
3410
+function img_next($titlealt = 'default', $moreatt = '')
3411 3411
 {
3412 3412
 	global $conf, $langs;
3413 3413
 
@@ -3424,7 +3424,7 @@  discard block
 block discarded – undo
3424 3424
  *	@param	string	$moreatt	Add more attribute on img tag (For example 'style="float: right"')
3425 3425
  *	@return string      		Return img tag
3426 3426
  */
3427
-function img_previous($titlealt = 'default', $moreatt='')
3427
+function img_previous($titlealt = 'default', $moreatt = '')
3428 3428
 {
3429 3429
 	global $conf, $langs;
3430 3430
 
@@ -3442,13 +3442,13 @@  discard block
 block discarded – undo
3442 3442
  *  @param	string	$moreclass	Add more CSS classes
3443 3443
  *	@return string      		Return img tag
3444 3444
  */
3445
-function img_down($titlealt = 'default', $selected = 0, $moreclass='')
3445
+function img_down($titlealt = 'default', $selected = 0, $moreclass = '')
3446 3446
 {
3447 3447
 	global $conf, $langs;
3448 3448
 
3449 3449
 	if ($titlealt == 'default') $titlealt = $langs->trans('Down');
3450 3450
 
3451
-	return img_picto($titlealt, ($selected ? '1downarrow_selected.png' : '1downarrow.png'), 'class="imgdown'.($moreclass?" ".$moreclass:"").'"');
3451
+	return img_picto($titlealt, ($selected ? '1downarrow_selected.png' : '1downarrow.png'), 'class="imgdown'.($moreclass ? " ".$moreclass : "").'"');
3452 3452
 }
3453 3453
 
3454 3454
 /**
@@ -3459,13 +3459,13 @@  discard block
 block discarded – undo
3459 3459
  *  @param	string	$moreclass	Add more CSS classes
3460 3460
  *	@return string      		Return img tag
3461 3461
  */
3462
-function img_up($titlealt = 'default', $selected = 0, $moreclass='')
3462
+function img_up($titlealt = 'default', $selected = 0, $moreclass = '')
3463 3463
 {
3464 3464
 	global $conf, $langs;
3465 3465
 
3466 3466
 	if ($titlealt == 'default') $titlealt = $langs->trans('Up');
3467 3467
 
3468
-	return img_picto($titlealt, ($selected ? '1uparrow_selected.png' : '1uparrow.png'), 'class="imgup'.($moreclass?" ".$moreclass:"").'"');
3468
+	return img_picto($titlealt, ($selected ? '1uparrow_selected.png' : '1uparrow.png'), 'class="imgup'.($moreclass ? " ".$moreclass : "").'"');
3469 3469
 }
3470 3470
 
3471 3471
 /**
@@ -3476,7 +3476,7 @@  discard block
 block discarded – undo
3476 3476
  *	@param	string	$moreatt	Add more attribute on img tag (For example 'style="float: right"')
3477 3477
  *	@return string      		Return img tag
3478 3478
  */
3479
-function img_left($titlealt = 'default', $selected = 0, $moreatt='')
3479
+function img_left($titlealt = 'default', $selected = 0, $moreatt = '')
3480 3480
 {
3481 3481
 	global $conf, $langs;
3482 3482
 
@@ -3493,7 +3493,7 @@  discard block
 block discarded – undo
3493 3493
  *	@param	string	$moreatt	Add more attribute on img tag (For example 'style="float: right"')
3494 3494
  *	@return string      		Return img tag
3495 3495
  */
3496
-function img_right($titlealt = 'default', $selected = 0, $moreatt='')
3496
+function img_right($titlealt = 'default', $selected = 0, $moreatt = '')
3497 3497
 {
3498 3498
 	global $conf, $langs;
3499 3499
 
@@ -3529,7 +3529,7 @@  discard block
 block discarded – undo
3529 3529
  *  @param	string	$morecss	More css
3530 3530
  *	@return string     			Return img tag
3531 3531
  */
3532
-function img_mime($file, $titlealt = '', $morecss='')
3532
+function img_mime($file, $titlealt = '', $morecss = '')
3533 3533
 {
3534 3534
 	require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
3535 3535
 
@@ -3556,9 +3556,9 @@  discard block
 block discarded – undo
3556 3556
  */
3557 3557
 function img_phone($titlealt = 'default', $option = 0)
3558 3558
 {
3559
-	dol_syslog(__FUNCTION__ . " is deprecated", LOG_WARNING);
3559
+	dol_syslog(__FUNCTION__." is deprecated", LOG_WARNING);
3560 3560
 
3561
-	global $conf,$langs;
3561
+	global $conf, $langs;
3562 3562
 
3563 3563
 	if ($titlealt == 'default') $titlealt = $langs->trans('Call');
3564 3564
 
@@ -3584,7 +3584,7 @@  discard block
 block discarded – undo
3584 3584
 	$img = img_picto($titlealt, 'search.png', $other, false, 1);
3585 3585
 
3586 3586
 	$input = '<input type="image" class="liste_titre" name="button_search" src="'.$img.'" ';
3587
-	$input.= 'value="'.dol_escape_htmltag($titlealt).'" title="'.dol_escape_htmltag($titlealt).'" >';
3587
+	$input .= 'value="'.dol_escape_htmltag($titlealt).'" title="'.dol_escape_htmltag($titlealt).'" >';
3588 3588
 
3589 3589
 	return $input;
3590 3590
 }
@@ -3605,7 +3605,7 @@  discard block
 block discarded – undo
3605 3605
 	$img = img_picto($titlealt, 'searchclear.png', $other, false, 1);
3606 3606
 
3607 3607
 	$input = '<input type="image" class="liste_titre" name="button_removefilter" src="'.$img.'" ';
3608
-	$input.= 'value="'.dol_escape_htmltag($titlealt).'" title="'.dol_escape_htmltag($titlealt).'" >';
3608
+	$input .= 'value="'.dol_escape_htmltag($titlealt).'" title="'.dol_escape_htmltag($titlealt).'" >';
3609 3609
 
3610 3610
 	return $input;
3611 3611
 }
@@ -3620,16 +3620,16 @@  discard block
 block discarded – undo
3620 3620
  *  @param	string	$morecss		More CSS
3621 3621
  *	@return	string					String with info text
3622 3622
  */
3623
-function info_admin($text, $infoonimgalt = 0, $nodiv=0, $admin='1', $morecss='')
3623
+function info_admin($text, $infoonimgalt = 0, $nodiv = 0, $admin = '1', $morecss = '')
3624 3624
 {
3625 3625
 	global $conf, $langs;
3626 3626
 
3627 3627
 	if ($infoonimgalt)
3628 3628
 	{
3629
-		return img_picto($text, 'info', 'class="hideonsmartphone'.($morecss?' '.$morecss:'').'"');
3629
+		return img_picto($text, 'info', 'class="hideonsmartphone'.($morecss ? ' '.$morecss : '').'"');
3630 3630
 	}
3631 3631
 
3632
-	return ($nodiv?'':'<div class="'.(empty($admin)?'':($admin=='1'?'info':$admin)).' hideonsmartphone'.($morecss?' '.$morecss:'').'">').'<span class="fa fa-info-circle" title="'.dol_escape_htmltag($admin?$langs->trans('InfoAdmin'):$langs->trans('Note')).'"></span> '.$text.($nodiv?'':'</div>');
3632
+	return ($nodiv ? '' : '<div class="'.(empty($admin) ? '' : ($admin == '1' ? 'info' : $admin)).' hideonsmartphone'.($morecss ? ' '.$morecss : '').'">').'<span class="fa fa-info-circle" title="'.dol_escape_htmltag($admin ? $langs->trans('InfoAdmin') : $langs->trans('Note')).'"></span> '.$text.($nodiv ? '' : '</div>');
3633 3633
 }
3634 3634
 
3635 3635
 
@@ -3645,18 +3645,18 @@  discard block
 block discarded – undo
3645 3645
  *	@return 	void
3646 3646
  *  @see    	dol_htmloutput_errors
3647 3647
  */
3648
-function dol_print_error($db='',$error='',$errors=null)
3648
+function dol_print_error($db = '', $error = '', $errors = null)
3649 3649
 {
3650
-	global $conf,$langs,$argv;
3650
+	global $conf, $langs, $argv;
3651 3651
 	global $dolibarr_main_prod;
3652 3652
 
3653 3653
 	$out = '';
3654 3654
 	$syslog = '';
3655 3655
 
3656 3656
 	// Si erreur intervenue avant chargement langue
3657
-	if (! $langs)
3657
+	if (!$langs)
3658 3658
 	{
3659
-		require_once DOL_DOCUMENT_ROOT .'/core/class/translate.class.php';
3659
+		require_once DOL_DOCUMENT_ROOT.'/core/class/translate.class.php';
3660 3660
 		$langs = new Translate('', $conf);
3661 3661
 		$langs->load("main");
3662 3662
 	}
@@ -3665,58 +3665,58 @@  discard block
 block discarded – undo
3665 3665
 
3666 3666
 	if ($_SERVER['DOCUMENT_ROOT'])    // Mode web
3667 3667
 	{
3668
-		$out.=$langs->trans("DolibarrHasDetectedError").".<br>\n";
3669
-		if (! empty($conf->global->MAIN_FEATURES_LEVEL)) $out.="You use an experimental or develop level of features, so please do NOT report any bugs, except if problem is confirmed moving option MAIN_FEATURES_LEVEL back to 0.<br>\n";
3670
-		$out.=$langs->trans("InformationToHelpDiagnose").":<br>\n";
3668
+		$out .= $langs->trans("DolibarrHasDetectedError").".<br>\n";
3669
+		if (!empty($conf->global->MAIN_FEATURES_LEVEL)) $out .= "You use an experimental or develop level of features, so please do NOT report any bugs, except if problem is confirmed moving option MAIN_FEATURES_LEVEL back to 0.<br>\n";
3670
+		$out .= $langs->trans("InformationToHelpDiagnose").":<br>\n";
3671 3671
 
3672
-		$out.="<b>".$langs->trans("Date").":</b> ".dol_print_date(time(),'dayhourlog')."<br>\n";
3673
-		$out.="<b>".$langs->trans("Dolibarr").":</b> ".DOL_VERSION."<br>\n";
3674
-		if (isset($conf->global->MAIN_FEATURES_LEVEL)) $out.="<b>".$langs->trans("LevelOfFeature").":</b> ".$conf->global->MAIN_FEATURES_LEVEL."<br>\n";
3672
+		$out .= "<b>".$langs->trans("Date").":</b> ".dol_print_date(time(), 'dayhourlog')."<br>\n";
3673
+		$out .= "<b>".$langs->trans("Dolibarr").":</b> ".DOL_VERSION."<br>\n";
3674
+		if (isset($conf->global->MAIN_FEATURES_LEVEL)) $out .= "<b>".$langs->trans("LevelOfFeature").":</b> ".$conf->global->MAIN_FEATURES_LEVEL."<br>\n";
3675 3675
 		if (function_exists("phpversion"))
3676 3676
 		{
3677
-			$out.="<b>".$langs->trans("PHP").":</b> ".phpversion()."<br>\n";
3677
+			$out .= "<b>".$langs->trans("PHP").":</b> ".phpversion()."<br>\n";
3678 3678
 		}
3679
-		$out.="<b>".$langs->trans("Server").":</b> ".$_SERVER["SERVER_SOFTWARE"]."<br>\n";
3679
+		$out .= "<b>".$langs->trans("Server").":</b> ".$_SERVER["SERVER_SOFTWARE"]."<br>\n";
3680 3680
 		if (function_exists("php_uname"))
3681 3681
 		{
3682
-			$out.="<b>".$langs->trans("OS").":</b> ".php_uname()."<br>\n";
3682
+			$out .= "<b>".$langs->trans("OS").":</b> ".php_uname()."<br>\n";
3683 3683
 		}
3684
-		$out.="<b>".$langs->trans("UserAgent").":</b> ".$_SERVER["HTTP_USER_AGENT"]."<br>\n";
3685
-		$out.="<br>\n";
3686
-		$out.="<b>".$langs->trans("RequestedUrl").":</b> ".dol_htmlentities($_SERVER["REQUEST_URI"],ENT_COMPAT,'UTF-8')."<br>\n";
3687
-		$out.="<b>".$langs->trans("Referer").":</b> ".(isset($_SERVER["HTTP_REFERER"])?dol_htmlentities($_SERVER["HTTP_REFERER"],ENT_COMPAT,'UTF-8'):'')."<br>\n";
3688
-		$out.="<b>".$langs->trans("MenuManager").":</b> ".(isset($conf->standard_menu)?$conf->standard_menu:'')."<br>\n";
3689
-		$out.="<br>\n";
3690
-		$syslog.="url=".dol_escape_htmltag($_SERVER["REQUEST_URI"]);
3691
-		$syslog.=", query_string=".dol_escape_htmltag($_SERVER["QUERY_STRING"]);
3684
+		$out .= "<b>".$langs->trans("UserAgent").":</b> ".$_SERVER["HTTP_USER_AGENT"]."<br>\n";
3685
+		$out .= "<br>\n";
3686
+		$out .= "<b>".$langs->trans("RequestedUrl").":</b> ".dol_htmlentities($_SERVER["REQUEST_URI"], ENT_COMPAT, 'UTF-8')."<br>\n";
3687
+		$out .= "<b>".$langs->trans("Referer").":</b> ".(isset($_SERVER["HTTP_REFERER"]) ?dol_htmlentities($_SERVER["HTTP_REFERER"], ENT_COMPAT, 'UTF-8') : '')."<br>\n";
3688
+		$out .= "<b>".$langs->trans("MenuManager").":</b> ".(isset($conf->standard_menu) ? $conf->standard_menu : '')."<br>\n";
3689
+		$out .= "<br>\n";
3690
+		$syslog .= "url=".dol_escape_htmltag($_SERVER["REQUEST_URI"]);
3691
+		$syslog .= ", query_string=".dol_escape_htmltag($_SERVER["QUERY_STRING"]);
3692 3692
 	}
3693 3693
 	else                              // Mode CLI
3694 3694
 	{
3695
-		$out.='> '.$langs->transnoentities("ErrorInternalErrorDetected").":\n".$argv[0]."\n";
3696
-		$syslog.="pid=".dol_getmypid();
3695
+		$out .= '> '.$langs->transnoentities("ErrorInternalErrorDetected").":\n".$argv[0]."\n";
3696
+		$syslog .= "pid=".dol_getmypid();
3697 3697
 	}
3698 3698
 
3699 3699
 	if (is_object($db))
3700 3700
 	{
3701 3701
 		if ($_SERVER['DOCUMENT_ROOT'])  // Mode web
3702 3702
 		{
3703
-			$out.="<b>".$langs->trans("DatabaseTypeManager").":</b> ".$db->type."<br>\n";
3704
-			$out.="<b>".$langs->trans("RequestLastAccessInError").":</b> ".($db->lastqueryerror()?dol_escape_htmltag($db->lastqueryerror()):$langs->trans("ErrorNoRequestInError"))."<br>\n";
3705
-			$out.="<b>".$langs->trans("ReturnCodeLastAccessInError").":</b> ".($db->lasterrno()?dol_escape_htmltag($db->lasterrno()):$langs->trans("ErrorNoRequestInError"))."<br>\n";
3706
-			$out.="<b>".$langs->trans("InformationLastAccessInError").":</b> ".($db->lasterror()?dol_escape_htmltag($db->lasterror()):$langs->trans("ErrorNoRequestInError"))."<br>\n";
3707
-			$out.="<br>\n";
3703
+			$out .= "<b>".$langs->trans("DatabaseTypeManager").":</b> ".$db->type."<br>\n";
3704
+			$out .= "<b>".$langs->trans("RequestLastAccessInError").":</b> ".($db->lastqueryerror() ?dol_escape_htmltag($db->lastqueryerror()) : $langs->trans("ErrorNoRequestInError"))."<br>\n";
3705
+			$out .= "<b>".$langs->trans("ReturnCodeLastAccessInError").":</b> ".($db->lasterrno() ?dol_escape_htmltag($db->lasterrno()) : $langs->trans("ErrorNoRequestInError"))."<br>\n";
3706
+			$out .= "<b>".$langs->trans("InformationLastAccessInError").":</b> ".($db->lasterror() ?dol_escape_htmltag($db->lasterror()) : $langs->trans("ErrorNoRequestInError"))."<br>\n";
3707
+			$out .= "<br>\n";
3708 3708
 		}
3709 3709
 		else                            // Mode CLI
3710 3710
 		{
3711 3711
 			// No dol_escape_htmltag for output, we are in CLI mode
3712
-			$out.='> '.$langs->transnoentities("DatabaseTypeManager").":\n".$db->type."\n";
3713
-			$out.='> '.$langs->transnoentities("RequestLastAccessInError").":\n".($db->lastqueryerror()?$db->lastqueryerror():$langs->transnoentities("ErrorNoRequestInError"))."\n";
3714
-			$out.='> '.$langs->transnoentities("ReturnCodeLastAccessInError").":\n".($db->lasterrno()?$db->lasterrno():$langs->transnoentities("ErrorNoRequestInError"))."\n";
3715
-			$out.='> '.$langs->transnoentities("InformationLastAccessInError").":\n".($db->lasterror()?$db->lasterror():$langs->transnoentities("ErrorNoRequestInError"))."\n";
3712
+			$out .= '> '.$langs->transnoentities("DatabaseTypeManager").":\n".$db->type."\n";
3713
+			$out .= '> '.$langs->transnoentities("RequestLastAccessInError").":\n".($db->lastqueryerror() ? $db->lastqueryerror() : $langs->transnoentities("ErrorNoRequestInError"))."\n";
3714
+			$out .= '> '.$langs->transnoentities("ReturnCodeLastAccessInError").":\n".($db->lasterrno() ? $db->lasterrno() : $langs->transnoentities("ErrorNoRequestInError"))."\n";
3715
+			$out .= '> '.$langs->transnoentities("InformationLastAccessInError").":\n".($db->lasterror() ? $db->lasterror() : $langs->transnoentities("ErrorNoRequestInError"))."\n";
3716 3716
 
3717 3717
 		}
3718
-		$syslog.=", sql=".$db->lastquery();
3719
-		$syslog.=", db_error=".$db->lasterror();
3718
+		$syslog .= ", sql=".$db->lastquery();
3719
+		$syslog .= ", db_error=".$db->lasterror();
3720 3720
 	}
3721 3721
 
3722 3722
 	if ($error || $errors)
@@ -3724,33 +3724,33 @@  discard block
 block discarded – undo
3724 3724
 		$langs->load("errors");
3725 3725
 
3726 3726
 		// Merge all into $errors array
3727
-		if (is_array($error) && is_array($errors)) $errors=array_merge($error,$errors);
3728
-		elseif (is_array($error)) $errors=$error;
3729
-		elseif (is_array($errors)) $errors=array_merge(array($error),$errors);
3730
-		else $errors=array_merge(array($error));
3727
+		if (is_array($error) && is_array($errors)) $errors = array_merge($error, $errors);
3728
+		elseif (is_array($error)) $errors = $error;
3729
+		elseif (is_array($errors)) $errors = array_merge(array($error), $errors);
3730
+		else $errors = array_merge(array($error));
3731 3731
 
3732
-		foreach($errors as $msg)
3732
+		foreach ($errors as $msg)
3733 3733
 		{
3734 3734
 			if (empty($msg)) continue;
3735 3735
 			if ($_SERVER['DOCUMENT_ROOT'])  // Mode web
3736 3736
 			{
3737
-				$out.="<b>".$langs->trans("Message").":</b> ".dol_escape_htmltag($msg)."<br>\n" ;
3737
+				$out .= "<b>".$langs->trans("Message").":</b> ".dol_escape_htmltag($msg)."<br>\n";
3738 3738
 			}
3739 3739
 			else                        // Mode CLI
3740 3740
 			{
3741
-				$out.='> '.$langs->transnoentities("Message").":\n".$msg."\n" ;
3741
+				$out .= '> '.$langs->transnoentities("Message").":\n".$msg."\n";
3742 3742
 			}
3743
-			$syslog.=", msg=".$msg;
3743
+			$syslog .= ", msg=".$msg;
3744 3744
 		}
3745 3745
 	}
3746 3746
 	if (empty($dolibarr_main_prod) && $_SERVER['DOCUMENT_ROOT'] && function_exists('xdebug_print_function_stack') && function_exists('xdebug_call_file'))
3747 3747
 	{
3748 3748
 		xdebug_print_function_stack();
3749
-		$out.='<b>XDebug informations:</b>'."<br>\n";
3750
-		$out.='File: '.xdebug_call_file()."<br>\n";
3751
-		$out.='Line: '.xdebug_call_line()."<br>\n";
3752
-		$out.='Function: '.xdebug_call_function()."<br>\n";
3753
-		$out.="<br>\n";
3749
+		$out .= '<b>XDebug informations:</b>'."<br>\n";
3750
+		$out .= 'File: '.xdebug_call_file()."<br>\n";
3751
+		$out .= 'Line: '.xdebug_call_line()."<br>\n";
3752
+		$out .= 'Function: '.xdebug_call_function()."<br>\n";
3753
+		$out .= "<br>\n";
3754 3754
 	}
3755 3755
 
3756 3756
 	if (empty($dolibarr_main_prod)) print $out;
@@ -3773,18 +3773,18 @@  discard block
 block discarded – undo
3773 3773
  * @param	string	$morecss		More css
3774 3774
  * @return	void
3775 3775
  */
3776
-function dol_print_error_email($prefixcode, $errormessage='', $errormessages=array(), $morecss='error')
3776
+function dol_print_error_email($prefixcode, $errormessage = '', $errormessages = array(), $morecss = 'error')
3777 3777
 {
3778
-	global $langs,$conf;
3778
+	global $langs, $conf;
3779 3779
 
3780 3780
 	$langs->load("errors");
3781
-	$now=dol_now();
3781
+	$now = dol_now();
3782 3782
 	print '<br><div class="center login_main_message"><div class="'.$morecss.'">';
3783
-	print $langs->trans("ErrorContactEMail", $conf->global->MAIN_INFO_SOCIETE_MAIL, $prefixcode.dol_print_date($now,'%Y%m%d'));
3783
+	print $langs->trans("ErrorContactEMail", $conf->global->MAIN_INFO_SOCIETE_MAIL, $prefixcode.dol_print_date($now, '%Y%m%d'));
3784 3784
 	if ($errormessage) print '<br><br>'.$errormessage;
3785 3785
 	if (is_array($errormessages) && count($errormessages))
3786 3786
 	{
3787
-		foreach($errormessages as $mesgtoshow)
3787
+		foreach ($errormessages as $mesgtoshow)
3788 3788
 		{
3789 3789
 			print '<br><br>'.$mesgtoshow;
3790 3790
 		}
@@ -3807,7 +3807,7 @@  discard block
 block discarded – undo
3807 3807
  *  @param	string	$tooltip	 Tooltip
3808 3808
  *	@return	void
3809 3809
  */
3810
-function print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="")
3810
+function print_liste_field_titre($name, $file = "", $field = "", $begin = "", $moreparam = "", $moreattrib = "", $sortfield = "", $sortorder = "", $prefix = "", $tooltip = "")
3811 3811
 {
3812 3812
 	print getTitleFieldOfList($name, 0, $file, $field, $begin, $moreparam, $moreattrib, $sortfield, $sortorder, $prefix, 0, $tooltip);
3813 3813
 }
@@ -3829,68 +3829,68 @@  discard block
 block discarded – undo
3829 3829
  *  @param	string	$tooltip	 		Tooltip
3830 3830
  *	@return	string
3831 3831
  */
3832
-function getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='')
3832
+function getTitleFieldOfList($name, $thead = 0, $file = "", $field = "", $begin = "", $moreparam = "", $moreattrib = "", $sortfield = "", $sortorder = "", $prefix = "", $disablesortlink = 0, $tooltip = '')
3833 3833
 {
3834 3834
 	global $conf, $langs, $form;
3835 3835
 	//print "$name, $file, $field, $begin, $options, $moreattrib, $sortfield, $sortorder<br>\n";
3836 3836
 
3837
-	$sortorder=strtoupper($sortorder);
3838
-	$out='';
3839
-	$sortimg='';
3837
+	$sortorder = strtoupper($sortorder);
3838
+	$out = '';
3839
+	$sortimg = '';
3840 3840
 
3841
-	$tag='th';
3842
-	if ($thead==2) $tag='div';
3841
+	$tag = 'th';
3842
+	if ($thead == 2) $tag = 'div';
3843 3843
 
3844
-	$tmpsortfield=explode(',',$sortfield);
3845
-	$sortfield1=trim($tmpsortfield[0]);    // If $sortfield is 'd.datep,d.id', it becomes 'd.datep'
3846
-	$tmpfield=explode(',',$field);
3847
-	$field1=trim($tmpfield[0]);            // If $field is 'd.datep,d.id', it becomes 'd.datep'
3844
+	$tmpsortfield = explode(',', $sortfield);
3845
+	$sortfield1 = trim($tmpsortfield[0]); // If $sortfield is 'd.datep,d.id', it becomes 'd.datep'
3846
+	$tmpfield = explode(',', $field);
3847
+	$field1 = trim($tmpfield[0]); // If $field is 'd.datep,d.id', it becomes 'd.datep'
3848 3848
 
3849 3849
 	//var_dump('field='.$field.' field1='.$field1.' sortfield='.$sortfield.' sortfield1='.$sortfield1);
3850 3850
 	// If field is used as sort criteria we use a specific css class liste_titre_sel
3851 3851
 	// Example if (sortfield,field)=("nom","xxx.nom") or (sortfield,field)=("nom","nom")
3852
-	if ($field1 && ($sortfield1 == $field1 || $sortfield1 == preg_replace("/^[^\.]+\./","",$field1))) $out.= '<'.$tag.' class="'.$prefix.'liste_titre_sel" '. $moreattrib.'>';
3853
-	else $out.= '<'.$tag.' class="'.$prefix.'liste_titre" '. $moreattrib.'>';
3852
+	if ($field1 && ($sortfield1 == $field1 || $sortfield1 == preg_replace("/^[^\.]+\./", "", $field1))) $out .= '<'.$tag.' class="'.$prefix.'liste_titre_sel" '.$moreattrib.'>';
3853
+	else $out .= '<'.$tag.' class="'.$prefix.'liste_titre" '.$moreattrib.'>';
3854 3854
 
3855 3855
 	if (empty($thead) && $field && empty($disablesortlink))    // If this is a sort field
3856 3856
 	{
3857
-		$options=preg_replace('/sortfield=([a-zA-Z0-9,\s\.]+)/i','',$moreparam);
3858
-		$options=preg_replace('/sortorder=([a-zA-Z0-9,\s\.]+)/i','',$options);
3859
-		$options=preg_replace('/&+/i','&',$options);
3860
-		if (! preg_match('/^&/',$options)) $options='&'.$options;
3857
+		$options = preg_replace('/sortfield=([a-zA-Z0-9,\s\.]+)/i', '', $moreparam);
3858
+		$options = preg_replace('/sortorder=([a-zA-Z0-9,\s\.]+)/i', '', $options);
3859
+		$options = preg_replace('/&+/i', '&', $options);
3860
+		if (!preg_match('/^&/', $options)) $options = '&'.$options;
3861 3861
 
3862 3862
 		if ($field1 != $sortfield1) // We are on another field
3863 3863
 		{
3864
-			if (preg_match('/^DESC/', $sortorder)) $out.= '<a class="reposition" href="'.$file.'?sortfield='.$field.'&sortorder=desc&begin='.$begin.$options.'">';
3865
-			else $out.= '<a class="reposition" href="'.$file.'?sortfield='.$field.'&sortorder=asc&begin='.$begin.$options.'">';
3864
+			if (preg_match('/^DESC/', $sortorder)) $out .= '<a class="reposition" href="'.$file.'?sortfield='.$field.'&sortorder=desc&begin='.$begin.$options.'">';
3865
+			else $out .= '<a class="reposition" href="'.$file.'?sortfield='.$field.'&sortorder=asc&begin='.$begin.$options.'">';
3866 3866
 		}
3867 3867
 		else                      // We are of first sorting criteria
3868 3868
 		{
3869
-			if (preg_match('/^ASC/', $sortorder)) $out.= '<a class="reposition" href="'.$file.'?sortfield='.$sortfield.'&sortorder=desc&begin='.$begin.$options.'">';
3870
-			else $out.= '<a class="reposition" href="'.$file.'?sortfield='.$sortfield.'&sortorder=asc&begin='.$begin.$options.'">';
3869
+			if (preg_match('/^ASC/', $sortorder)) $out .= '<a class="reposition" href="'.$file.'?sortfield='.$sortfield.'&sortorder=desc&begin='.$begin.$options.'">';
3870
+			else $out .= '<a class="reposition" href="'.$file.'?sortfield='.$sortfield.'&sortorder=asc&begin='.$begin.$options.'">';
3871 3871
 		}
3872 3872
 	}
3873 3873
 
3874
-	if ($tooltip) $out.=$form->textwithpicto($langs->trans($name), $langs->trans($tooltip));
3875
-	else $out.=$langs->trans($name);
3874
+	if ($tooltip) $out .= $form->textwithpicto($langs->trans($name), $langs->trans($tooltip));
3875
+	else $out .= $langs->trans($name);
3876 3876
 
3877 3877
 	if (empty($thead) && $field && empty($disablesortlink))    // If this is a sort field
3878 3878
 	{
3879
-		$out.='</a>';
3879
+		$out .= '</a>';
3880 3880
 	}
3881 3881
 
3882 3882
 	if (empty($thead) && $field)    // If this is a sort field
3883 3883
 	{
3884
-		$options=preg_replace('/sortfield=([a-zA-Z0-9,\s\.]+)/i','',$moreparam);
3885
-		$options=preg_replace('/sortorder=([a-zA-Z0-9,\s\.]+)/i','',$options);
3886
-		$options=preg_replace('/&+/i','&',$options);
3887
-		if (! preg_match('/^&/',$options)) $options='&'.$options;
3884
+		$options = preg_replace('/sortfield=([a-zA-Z0-9,\s\.]+)/i', '', $moreparam);
3885
+		$options = preg_replace('/sortorder=([a-zA-Z0-9,\s\.]+)/i', '', $options);
3886
+		$options = preg_replace('/&+/i', '&', $options);
3887
+		if (!preg_match('/^&/', $options)) $options = '&'.$options;
3888 3888
 
3889 3889
 		//print "&nbsp;";
3890 3890
 		//$sortimg.= '<img width="2" src="'.DOL_URL_ROOT.'/theme/common/transparent.png" alt="">';
3891 3891
 		//$sortimg.= '<span class="nowrap">';
3892 3892
 
3893
-		if (! $sortorder || $field1 != $sortfield1)
3893
+		if (!$sortorder || $field1 != $sortfield1)
3894 3894
 		{
3895 3895
 			//$out.= '<a href="'.$file.'?sortfield='.$field.'&sortorder=asc&begin='.$begin.$options.'">'.img_down("A-Z",0).'</a>';
3896 3896
 			//$out.= '<a href="'.$file.'?sortfield='.$field.'&sortorder=desc&begin='.$begin.$options.'">'.img_up("Z-A",0).'</a>';
@@ -3900,21 +3900,21 @@  discard block
 block discarded – undo
3900 3900
 			if (preg_match('/^DESC/', $sortorder)) {
3901 3901
 				//$out.= '<a href="'.$file.'?sortfield='.$field.'&sortorder=asc&begin='.$begin.$options.'">'.img_down("A-Z",0).'</a>';
3902 3902
 				//$out.= '<a href="'.$file.'?sortfield='.$field.'&sortorder=desc&begin='.$begin.$options.'">'.img_up("Z-A",1).'</a>';
3903
-				$sortimg.= '<span class="nowrap">'.img_up("Z-A",0).'</span>';
3903
+				$sortimg .= '<span class="nowrap">'.img_up("Z-A", 0).'</span>';
3904 3904
 			}
3905 3905
 			if (preg_match('/^ASC/', $sortorder)) {
3906 3906
 				//$out.= '<a href="'.$file.'?sortfield='.$field.'&sortorder=asc&begin='.$begin.$options.'">'.img_down("A-Z",1).'</a>';
3907 3907
 				//$out.= '<a href="'.$file.'?sortfield='.$field.'&sortorder=desc&begin='.$begin.$options.'">'.img_up("Z-A",0).'</a>';
3908
-				$sortimg.= '<span class="nowrap">'.img_down("A-Z",0).'</span>';
3908
+				$sortimg .= '<span class="nowrap">'.img_down("A-Z", 0).'</span>';
3909 3909
 			}
3910 3910
 		}
3911 3911
 
3912 3912
 		//$sortimg.= '</span>';
3913 3913
 	}
3914 3914
 
3915
-	$out.=$sortimg;
3915
+	$out .= $sortimg;
3916 3916
 
3917
-	$out.='</'.$tag.'>';
3917
+	$out .= '</'.$tag.'>';
3918 3918
 
3919 3919
 	return $out;
3920 3920
 }
@@ -3929,7 +3929,7 @@  discard block
 block discarded – undo
3929 3929
  */
3930 3930
 function print_titre($title)
3931 3931
 {
3932
-	dol_syslog(__FUNCTION__ . " is deprecated", LOG_WARNING);
3932
+	dol_syslog(__FUNCTION__." is deprecated", LOG_WARNING);
3933 3933
 
3934 3934
 	print '<div class="titre">'.$title.'</div>';
3935 3935
 }
@@ -3945,7 +3945,7 @@  discard block
 block discarded – undo
3945 3945
  * 	@return	void
3946 3946
  *  @deprecated Use print load_fiche_titre instead
3947 3947
  */
3948
-function print_fiche_titre($title, $mesg='', $picto='title_generic.png', $pictoisfullpath=0, $id='')
3948
+function print_fiche_titre($title, $mesg = '', $picto = 'title_generic.png', $pictoisfullpath = 0, $id = '')
3949 3949
 {
3950 3950
 	print load_fiche_titre($title, $mesg, $picto, $pictoisfullpath, $id);
3951 3951
 }
@@ -3963,30 +3963,30 @@  discard block
 block discarded – undo
3963 3963
  * 	@return	string
3964 3964
  *  @see print_barre_liste
3965 3965
  */
3966
-function load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
3966
+function load_fiche_titre($titre, $morehtmlright = '', $picto = 'title_generic.png', $pictoisfullpath = 0, $id = 0, $morecssontable = '', $morehtmlcenter = '')
3967 3967
 {
3968 3968
 	global $conf;
3969 3969
 
3970
-	$return='';
3970
+	$return = '';
3971 3971
 
3972
-	if ($picto == 'setup') $picto='title.png';
3973
-	if (($conf->browser->name == 'ie') && $picto=='title.png') $picto='title.gif';
3972
+	if ($picto == 'setup') $picto = 'title.png';
3973
+	if (($conf->browser->name == 'ie') && $picto == 'title.png') $picto = 'title.gif';
3974 3974
 
3975
-	$return.= "\n";
3976
-	$return.= '<table '.($id?'id="'.$id.'" ':'').'summary="" class="centpercent notopnoleftnoright'.($morecssontable?' '.$morecssontable:'').'" style="margin-bottom: 2px;"><tr>';
3977
-	if ($picto) $return.= '<td class="nobordernopadding widthpictotitle" valign="middle">'.img_picto('',$picto, 'class="valignmiddle widthpictotitle" id="pictotitle"', $pictoisfullpath).'</td>';
3978
-	$return.= '<td class="nobordernopadding" valign="middle">';
3979
-	$return.= '<div class="titre">'.$titre.'</div>';
3980
-	$return.= '</td>';
3975
+	$return .= "\n";
3976
+	$return .= '<table '.($id ? 'id="'.$id.'" ' : '').'summary="" class="centpercent notopnoleftnoright'.($morecssontable ? ' '.$morecssontable : '').'" style="margin-bottom: 2px;"><tr>';
3977
+	if ($picto) $return .= '<td class="nobordernopadding widthpictotitle" valign="middle">'.img_picto('', $picto, 'class="valignmiddle widthpictotitle" id="pictotitle"', $pictoisfullpath).'</td>';
3978
+	$return .= '<td class="nobordernopadding" valign="middle">';
3979
+	$return .= '<div class="titre">'.$titre.'</div>';
3980
+	$return .= '</td>';
3981 3981
 	if (dol_strlen($morehtmlcenter))
3982 3982
 	{
3983
-		$return.= '<td class="nobordernopadding" align="center" valign="middle">'.$morehtmlcenter.'</td>';
3983
+		$return .= '<td class="nobordernopadding" align="center" valign="middle">'.$morehtmlcenter.'</td>';
3984 3984
 	}
3985 3985
 	if (dol_strlen($morehtmlright))
3986 3986
 	{
3987
-		$return.= '<td class="nobordernopadding titre_right" align="right" valign="middle">'.$morehtmlright.'</td>';
3987
+		$return .= '<td class="nobordernopadding titre_right" align="right" valign="middle">'.$morehtmlright.'</td>';
3988 3988
 	}
3989
-	$return.= '</tr></table>'."\n";
3989
+	$return .= '</tr></table>'."\n";
3990 3990
 
3991 3991
 	return $return;
3992 3992
 }
@@ -4012,16 +4012,16 @@  discard block
 block discarded – undo
4012 4012
  *  @param  int         $hidenavigation     Force to hide all navigation tools
4013 4013
  *	@return	void
4014 4014
  */
4015
-function print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='title_generic.png', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0)
4015
+function print_barre_liste($titre, $page, $file, $options = '', $sortfield = '', $sortorder = '', $morehtmlcenter = '', $num = -1, $totalnboflines = '', $picto = 'title_generic.png', $pictoisfullpath = 0, $morehtmlright = '', $morecss = '', $limit = -1, $hideselectlimit = 0, $hidenavigation = 0)
4016 4016
 {
4017
-	global $conf,$langs;
4017
+	global $conf, $langs;
4018 4018
 
4019 4019
 	$savlimit = $limit;
4020 4020
 	$savtotalnboflines = $totalnboflines;
4021
-	$totalnboflines=abs($totalnboflines);
4021
+	$totalnboflines = abs($totalnboflines);
4022 4022
 
4023
-	if ($picto == 'setup') $picto='title_setup.png';
4024
-	if (($conf->browser->name == 'ie') && $picto=='title_generic.png') $picto='title.gif';
4023
+	if ($picto == 'setup') $picto = 'title_setup.png';
4024
+	if (($conf->browser->name == 'ie') && $picto == 'title_generic.png') $picto = 'title.gif';
4025 4025
 	if ($limit < 0) $limit = $conf->liste_limit;
4026 4026
 	if ($savlimit != 0 && (($num > $limit) || ($num == -1) || ($limit == 0)))
4027 4027
 	{
@@ -4035,7 +4035,7 @@  discard block
 block discarded – undo
4035 4035
 
4036 4036
 	print "\n";
4037 4037
 	print "<!-- Begin title '".$titre."' -->\n";
4038
-	print '<table width="100%" border="0" class="notopnoleftnoright'.($morecss?' '.$morecss:'').'" style="margin-bottom: 6px;"><tr>';
4038
+	print '<table width="100%" border="0" class="notopnoleftnoright'.($morecss ? ' '.$morecss : '').'" style="margin-bottom: 6px;"><tr>';
4039 4039
 
4040 4040
 	// Left
4041 4041
 	//if ($picto && $titre) print '<td class="nobordernopadding hideonsmartphone" width="40" align="left" valign="middle">'.img_picto('', $picto, 'id="pictotitle"', $pictoisfullpath).'</td>';
@@ -4062,48 +4062,48 @@  discard block
 block discarded – undo
4062 4062
 		if ($totalnboflines)	// If we know total nb of lines
4063 4063
 		{
4064 4064
 			// Define nb of extra page links before and after selected page + ... + first or last
4065
-			$maxnbofpage=(empty($conf->dol_optimize_smallscreen) ? 4 : 1);
4065
+			$maxnbofpage = (empty($conf->dol_optimize_smallscreen) ? 4 : 1);
4066 4066
 
4067
-			if ($limit > 0) $nbpages=ceil($totalnboflines/$limit);
4068
-			else $nbpages=1;
4069
-			$cpt=($page-$maxnbofpage);
4070
-			if ($cpt < 0) { $cpt=0; }
4067
+			if ($limit > 0) $nbpages = ceil($totalnboflines / $limit);
4068
+			else $nbpages = 1;
4069
+			$cpt = ($page - $maxnbofpage);
4070
+			if ($cpt < 0) { $cpt = 0; }
4071 4071
 
4072
-			if ($cpt>=1)
4072
+			if ($cpt >= 1)
4073 4073
 			{
4074
-				$pagelist.= '<li'.(($conf->dol_use_jmobile != 4)?' class="pagination"':'').'><a href="'.$file.'?page=0'.$options.'">1</a></li>';
4075
-				if ($cpt > 2) $pagelist.='<li'.(($conf->dol_use_jmobile != 4)?' class="pagination"':'').'><span '.(($conf->dol_use_jmobile != 4)?'class="inactive"':'').'>...</span></li>';
4076
-				else if ($cpt == 2) $pagelist.='<li'.(($conf->dol_use_jmobile != 4)?' class="pagination"':'').'><a href="'.$file.'?page=1'.$options.'">2</a></li>';
4074
+				$pagelist .= '<li'.(($conf->dol_use_jmobile != 4) ? ' class="pagination"' : '').'><a href="'.$file.'?page=0'.$options.'">1</a></li>';
4075
+				if ($cpt > 2) $pagelist .= '<li'.(($conf->dol_use_jmobile != 4) ? ' class="pagination"' : '').'><span '.(($conf->dol_use_jmobile != 4) ? 'class="inactive"' : '').'>...</span></li>';
4076
+				else if ($cpt == 2) $pagelist .= '<li'.(($conf->dol_use_jmobile != 4) ? ' class="pagination"' : '').'><a href="'.$file.'?page=1'.$options.'">2</a></li>';
4077 4077
 			}
4078 4078
 
4079 4079
 			do
4080 4080
 			{
4081
-				if ($cpt==$page)
4081
+				if ($cpt == $page)
4082 4082
 				{
4083
-					$pagelist.= '<li'.(($conf->dol_use_jmobile != 4)?' class="pagination"':'').'><span '.(($conf->dol_use_jmobile != 4)?'class="active"':'').'>'.($page+1).'</span></li>';
4083
+					$pagelist .= '<li'.(($conf->dol_use_jmobile != 4) ? ' class="pagination"' : '').'><span '.(($conf->dol_use_jmobile != 4) ? 'class="active"' : '').'>'.($page + 1).'</span></li>';
4084 4084
 				}
4085 4085
 				else
4086 4086
 				{
4087
-					$pagelist.= '<li'.(($conf->dol_use_jmobile != 4)?' class="pagination"':'').'><a href="'.$file.'?page='.$cpt.$options.'">'.($cpt+1).'</a></li>';
4087
+					$pagelist .= '<li'.(($conf->dol_use_jmobile != 4) ? ' class="pagination"' : '').'><a href="'.$file.'?page='.$cpt.$options.'">'.($cpt + 1).'</a></li>';
4088 4088
 				}
4089 4089
 				$cpt++;
4090 4090
 			}
4091
-			while ($cpt < $nbpages && $cpt<=$page+$maxnbofpage);
4091
+			while ($cpt < $nbpages && $cpt <= $page + $maxnbofpage);
4092 4092
 
4093
-			if ($cpt<$nbpages)
4093
+			if ($cpt < $nbpages)
4094 4094
 			{
4095
-				if ($cpt<$nbpages-2) $pagelist.= '<li'.(($conf->dol_use_jmobile != 4)?' class="pagination"':'').'><span '.(($conf->dol_use_jmobile != 4)?'class="inactive"':'').'>...</span></li>';
4096
-				else if ($cpt == $nbpages-2) $pagelist.= '<li'.(($conf->dol_use_jmobile != 4)?' class="pagination"':'').'><a href="'.$file.'?page='.($nbpages-2).$options.'">'.($nbpages - 1).'</a></li>';
4097
-				$pagelist.= '<li'.(($conf->dol_use_jmobile != 4)?' class="pagination"':'').'><a href="'.$file.'?page='.($nbpages-1).$options.'">'.$nbpages.'</a></li>';
4095
+				if ($cpt < $nbpages - 2) $pagelist .= '<li'.(($conf->dol_use_jmobile != 4) ? ' class="pagination"' : '').'><span '.(($conf->dol_use_jmobile != 4) ? 'class="inactive"' : '').'>...</span></li>';
4096
+				else if ($cpt == $nbpages - 2) $pagelist .= '<li'.(($conf->dol_use_jmobile != 4) ? ' class="pagination"' : '').'><a href="'.$file.'?page='.($nbpages - 2).$options.'">'.($nbpages - 1).'</a></li>';
4097
+				$pagelist .= '<li'.(($conf->dol_use_jmobile != 4) ? ' class="pagination"' : '').'><a href="'.$file.'?page='.($nbpages - 1).$options.'">'.$nbpages.'</a></li>';
4098 4098
 			}
4099 4099
 		}
4100 4100
 		else
4101 4101
 		{
4102
-			$pagelist.= '<li'.(($conf->dol_use_jmobile != 4)?' class="pagination"':'').'><span '.(($conf->dol_use_jmobile != 4)?'class="active"':'').'>'.($page+1)."</li>";
4102
+			$pagelist .= '<li'.(($conf->dol_use_jmobile != 4) ? ' class="pagination"' : '').'><span '.(($conf->dol_use_jmobile != 4) ? 'class="active"' : '').'>'.($page + 1)."</li>";
4103 4103
 		}
4104 4104
 	}
4105 4105
 
4106
-	print_fleche_navigation($page, $file, $options, $nextpage, $pagelist, $morehtmlright, $savlimit, $totalnboflines, $hideselectlimit);		// output the div and ul for previous/last completed with page numbers into $pagelist
4106
+	print_fleche_navigation($page, $file, $options, $nextpage, $pagelist, $morehtmlright, $savlimit, $totalnboflines, $hideselectlimit); // output the div and ul for previous/last completed with page numbers into $pagelist
4107 4107
 
4108 4108
 	print '</td>';
4109 4109
 
@@ -4125,33 +4125,33 @@  discard block
 block discarded – undo
4125 4125
  *  @param  int             $hideselectlimit    Force to hide select limit
4126 4126
  *	@return	void
4127 4127
  */
4128
-function print_fleche_navigation($page, $file, $options='', $nextpage=0, $betweenarrows='', $afterarrows='', $limit=-1, $totalnboflines=0, $hideselectlimit=0)
4128
+function print_fleche_navigation($page, $file, $options = '', $nextpage = 0, $betweenarrows = '', $afterarrows = '', $limit = -1, $totalnboflines = 0, $hideselectlimit = 0)
4129 4129
 {
4130 4130
 	global $conf, $langs;
4131 4131
 
4132 4132
 	print '<div class="pagination"><ul>';
4133 4133
 	if ((int) $limit >= 0 && empty($hideselectlimit))
4134 4134
 	{
4135
-		$pagesizechoices='10:10,20:20,30:30,40:40,50:50,100:100,250:250,500:500,1000:1000,5000:5000';
4135
+		$pagesizechoices = '10:10,20:20,30:30,40:40,50:50,100:100,250:250,500:500,1000:1000,5000:5000';
4136 4136
 		//$pagesizechoices.=',0:'.$langs->trans("All");     // Not yet supported
4137 4137
 		//$pagesizechoices.=',2:2';
4138
-		if (! empty($conf->global->MAIN_PAGESIZE_CHOICES)) $pagesizechoices=$conf->global->MAIN_PAGESIZE_CHOICES;
4138
+		if (!empty($conf->global->MAIN_PAGESIZE_CHOICES)) $pagesizechoices = $conf->global->MAIN_PAGESIZE_CHOICES;
4139 4139
 
4140 4140
 		print '<li class="pagination">';
4141 4141
 		print '<select class="flat selectlimit" name="limit" title="'.dol_escape_htmltag($langs->trans("MaxNbOfRecordPerPage")).'">';
4142
-		$tmpchoice=explode(',',$pagesizechoices);
4143
-		$tmpkey=$limit.':'.$limit;
4144
-		if (! in_array($tmpkey, $tmpchoice)) $tmpchoice[]=$tmpkey;
4145
-		$tmpkey=$conf->liste_limit.':'.$conf->liste_limit;
4146
-		if (! in_array($tmpkey, $tmpchoice)) $tmpchoice[]=$tmpkey;
4142
+		$tmpchoice = explode(',', $pagesizechoices);
4143
+		$tmpkey = $limit.':'.$limit;
4144
+		if (!in_array($tmpkey, $tmpchoice)) $tmpchoice[] = $tmpkey;
4145
+		$tmpkey = $conf->liste_limit.':'.$conf->liste_limit;
4146
+		if (!in_array($tmpkey, $tmpchoice)) $tmpchoice[] = $tmpkey;
4147 4147
 		asort($tmpchoice, SORT_NUMERIC);
4148
-		$found=false;
4149
-		foreach($tmpchoice as $val)
4148
+		$found = false;
4149
+		foreach ($tmpchoice as $val)
4150 4150
 		{
4151
-			$selected='';
4152
-			$tmp=explode(':',$val);
4153
-			$key=$tmp[0];
4154
-			$val=$tmp[1];
4151
+			$selected = '';
4152
+			$tmp = explode(':', $val);
4153
+			$key = $tmp[0];
4154
+			$val = $tmp[1];
4155 4155
 			if ($key != '' && $val != '')
4156 4156
 			{
4157 4157
 				if ((int) $key == (int) $limit)
@@ -4180,7 +4180,7 @@  discard block
 block discarded – undo
4180 4180
 	}
4181 4181
 	if ($page > 0)
4182 4182
 	{
4183
-		print '<li class="pagination"><a class="paginationprevious" href="'.$file.'?page='.($page-1).$options.'"><i class="fa fa-chevron-left" title="'.dol_escape_htmltag($langs->trans("Previous")).'"></i></a></li>';
4183
+		print '<li class="pagination"><a class="paginationprevious" href="'.$file.'?page='.($page - 1).$options.'"><i class="fa fa-chevron-left" title="'.dol_escape_htmltag($langs->trans("Previous")).'"></i></a></li>';
4184 4184
 	}
4185 4185
 	if ($betweenarrows)
4186 4186
 	{
@@ -4188,7 +4188,7 @@  discard block
 block discarded – undo
4188 4188
 	}
4189 4189
 	if ($nextpage > 0)
4190 4190
 	{
4191
-		print '<li class="pagination"><a class="paginationnext" href="'.$file.'?page='.($page+1).$options.'"><i class="fa fa-chevron-right" title="'.dol_escape_htmltag($langs->trans("Next")).'"></i></a></li>';
4191
+		print '<li class="pagination"><a class="paginationnext" href="'.$file.'?page='.($page + 1).$options.'"><i class="fa fa-chevron-right" title="'.dol_escape_htmltag($langs->trans("Next")).'"></i></a></li>';
4192 4192
 	}
4193 4193
 	if ($afterarrows)
4194 4194
 	{
@@ -4210,35 +4210,35 @@  discard block
 block discarded – undo
4210 4210
  *	@param	int		$usestarfornpr	-1=Never show, 0 or 1=Use '*' for NPR vat rates
4211 4211
  *  @return	string					String with formated amounts ('19,6' or '19,6%' or '8.5% (NPR)' or '8.5% *' or '19,6 (CODEX)')
4212 4212
  */
4213
-function vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0)
4213
+function vatrate($rate, $addpercent = false, $info_bits = 0, $usestarfornpr = 0)
4214 4214
 {
4215
-	$morelabel='';
4215
+	$morelabel = '';
4216 4216
 
4217
-	if (preg_match('/%/',$rate))
4217
+	if (preg_match('/%/', $rate))
4218 4218
 	{
4219
-		$rate=str_replace('%','',$rate);
4220
-		$addpercent=true;
4219
+		$rate = str_replace('%', '', $rate);
4220
+		$addpercent = true;
4221 4221
 	}
4222
-	if (preg_match('/\((.*)\)/',$rate,$reg))
4222
+	if (preg_match('/\((.*)\)/', $rate, $reg))
4223 4223
 	{
4224
-		$morelabel=' ('.$reg[1].')';
4225
-		$rate=preg_replace('/\s*'.preg_quote($morelabel,'/').'/','',$rate);
4224
+		$morelabel = ' ('.$reg[1].')';
4225
+		$rate = preg_replace('/\s*'.preg_quote($morelabel, '/').'/', '', $rate);
4226 4226
 	}
4227
-	if (preg_match('/\*/',$rate))
4227
+	if (preg_match('/\*/', $rate))
4228 4228
 	{
4229
-		$rate=str_replace('*','',$rate);
4229
+		$rate = str_replace('*', '', $rate);
4230 4230
 		$info_bits |= 1;
4231 4231
 	}
4232 4232
 
4233 4233
 	// If rate is '9/9/9' we don't change it.  If rate is '9.000' we apply price()
4234
-	if (! preg_match('/\//', $rate)) $ret=price($rate,0,'',0,0).($addpercent?'%':'');
4234
+	if (!preg_match('/\//', $rate)) $ret = price($rate, 0, '', 0, 0).($addpercent ? '%' : '');
4235 4235
 	else
4236 4236
 	{
4237 4237
 		// TODO Split on / and output with a price2num to have clean numbers without ton of 000.
4238
-		$ret=$rate.($addpercent?'%':'');
4238
+		$ret = $rate.($addpercent ? '%' : '');
4239 4239
 	}
4240
-	if (($info_bits & 1) && $usestarfornpr >= 0) $ret.=' *';
4241
-	$ret.=$morelabel;
4240
+	if (($info_bits & 1) && $usestarfornpr >= 0) $ret .= ' *';
4241
+	$ret .= $morelabel;
4242 4242
 	return $ret;
4243 4243
 }
4244 4244
 
@@ -4258,47 +4258,47 @@  discard block
 block discarded – undo
4258 4258
  *
4259 4259
  *		@see	price2num					Revert function of price
4260 4260
  */
4261
-function price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
4261
+function price($amount, $form = 0, $outlangs = '', $trunc = 1, $rounding = -1, $forcerounding = -1, $currency_code = '')
4262 4262
 {
4263
-	global $langs,$conf;
4263
+	global $langs, $conf;
4264 4264
 
4265 4265
 	// Clean parameters
4266
-	if (empty($amount)) $amount=0;	// To have a numeric value if amount not defined or = ''
4267
-	$amount = (is_numeric($amount)?$amount:0); // Check if amount is numeric, for example, an error occured when amount value = o (letter) instead 0 (number)
4268
-	if ($rounding < 0) $rounding=min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT);
4269
-	$nbdecimal=$rounding;
4266
+	if (empty($amount)) $amount = 0; // To have a numeric value if amount not defined or = ''
4267
+	$amount = (is_numeric($amount) ? $amount : 0); // Check if amount is numeric, for example, an error occured when amount value = o (letter) instead 0 (number)
4268
+	if ($rounding < 0) $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT, $conf->global->MAIN_MAX_DECIMALS_TOT);
4269
+	$nbdecimal = $rounding;
4270 4270
 
4271 4271
 	// Output separators by default (french)
4272
-	$dec=','; $thousand=' ';
4272
+	$dec = ','; $thousand = ' ';
4273 4273
 
4274 4274
 	// If $outlangs not forced, we use use language
4275
-	if (! is_object($outlangs)) $outlangs=$langs;
4275
+	if (!is_object($outlangs)) $outlangs = $langs;
4276 4276
 
4277
-	if ($outlangs->transnoentitiesnoconv("SeparatorDecimal") != "SeparatorDecimal")  $dec=$outlangs->transnoentitiesnoconv("SeparatorDecimal");
4278
-	if ($outlangs->transnoentitiesnoconv("SeparatorThousand")!= "SeparatorThousand") $thousand=$outlangs->transnoentitiesnoconv("SeparatorThousand");
4279
-	if ($thousand == 'None') $thousand='';
4280
-	else if ($thousand == 'Space') $thousand=' ';
4277
+	if ($outlangs->transnoentitiesnoconv("SeparatorDecimal") != "SeparatorDecimal")  $dec = $outlangs->transnoentitiesnoconv("SeparatorDecimal");
4278
+	if ($outlangs->transnoentitiesnoconv("SeparatorThousand") != "SeparatorThousand") $thousand = $outlangs->transnoentitiesnoconv("SeparatorThousand");
4279
+	if ($thousand == 'None') $thousand = '';
4280
+	else if ($thousand == 'Space') $thousand = ' ';
4281 4281
 	//print "outlangs=".$outlangs->defaultlang." amount=".$amount." html=".$form." trunc=".$trunc." nbdecimal=".$nbdecimal." dec='".$dec."' thousand='".$thousand."'<br>";
4282 4282
 
4283 4283
 	//print "amount=".$amount."-";
4284
-	$amount = str_replace(',','.',$amount);	// should be useless
4284
+	$amount = str_replace(',', '.', $amount); // should be useless
4285 4285
 	//print $amount."-";
4286
-	$datas = explode('.',$amount);
4287
-	$decpart = isset($datas[1])?$datas[1]:'';
4288
-	$decpart = preg_replace('/0+$/i','',$decpart);	// Supprime les 0 de fin de partie decimale
4286
+	$datas = explode('.', $amount);
4287
+	$decpart = isset($datas[1]) ? $datas[1] : '';
4288
+	$decpart = preg_replace('/0+$/i', '', $decpart); // Supprime les 0 de fin de partie decimale
4289 4289
 	//print "decpart=".$decpart."<br>";
4290
-	$end='';
4290
+	$end = '';
4291 4291
 
4292 4292
 	// We increase nbdecimal if there is more decimal than asked (to not loose information)
4293
-	if (dol_strlen($decpart) > $nbdecimal) $nbdecimal=dol_strlen($decpart);
4293
+	if (dol_strlen($decpart) > $nbdecimal) $nbdecimal = dol_strlen($decpart);
4294 4294
 	// Si on depasse max
4295 4295
 	if ($trunc && $nbdecimal > $conf->global->MAIN_MAX_DECIMALS_SHOWN)
4296 4296
 	{
4297
-		$nbdecimal=$conf->global->MAIN_MAX_DECIMALS_SHOWN;
4298
-		if (preg_match('/\.\.\./i',$conf->global->MAIN_MAX_DECIMALS_SHOWN))
4297
+		$nbdecimal = $conf->global->MAIN_MAX_DECIMALS_SHOWN;
4298
+		if (preg_match('/\.\.\./i', $conf->global->MAIN_MAX_DECIMALS_SHOWN))
4299 4299
 		{
4300 4300
 			// Si un affichage est tronque, on montre des ...
4301
-			$end='...';
4301
+			$end = '...';
4302 4302
 		}
4303 4303
 	}
4304 4304
 
@@ -4306,27 +4306,27 @@  discard block
 block discarded – undo
4306 4306
 	if ($forcerounding >= 0) $nbdecimal = $forcerounding;
4307 4307
 
4308 4308
 	// Format number
4309
-	$output=number_format($amount, $nbdecimal, $dec, $thousand);
4309
+	$output = number_format($amount, $nbdecimal, $dec, $thousand);
4310 4310
 	if ($form)
4311 4311
 	{
4312
-		$output=preg_replace('/\s/','&nbsp;',$output);
4313
-		$output=preg_replace('/\'/','&#039;',$output);
4312
+		$output = preg_replace('/\s/', '&nbsp;', $output);
4313
+		$output = preg_replace('/\'/', '&#039;', $output);
4314 4314
 	}
4315 4315
 	// Add symbol of currency if requested
4316
-	$cursymbolbefore=$cursymbolafter='';
4316
+	$cursymbolbefore = $cursymbolafter = '';
4317 4317
 	if ($currency_code)
4318 4318
 	{
4319
-		if ($currency_code == 'auto') $currency_code=$conf->currency;
4319
+		if ($currency_code == 'auto') $currency_code = $conf->currency;
4320 4320
 
4321
-		$listofcurrenciesbefore=array('USD','GBP','AUD','MXN','PEN','CNY');
4322
-		if (in_array($currency_code,$listofcurrenciesbefore)) $cursymbolbefore.=$outlangs->getCurrencySymbol($currency_code);
4321
+		$listofcurrenciesbefore = array('USD', 'GBP', 'AUD', 'MXN', 'PEN', 'CNY');
4322
+		if (in_array($currency_code, $listofcurrenciesbefore)) $cursymbolbefore .= $outlangs->getCurrencySymbol($currency_code);
4323 4323
 		else
4324 4324
 		{
4325
-			$tmpcur=$outlangs->getCurrencySymbol($currency_code);
4326
-			$cursymbolafter.=($tmpcur == $currency_code ? ' '.$tmpcur : $tmpcur);
4325
+			$tmpcur = $outlangs->getCurrencySymbol($currency_code);
4326
+			$cursymbolafter .= ($tmpcur == $currency_code ? ' '.$tmpcur : $tmpcur);
4327 4327
 		}
4328 4328
 	}
4329
-	$output=$cursymbolbefore.$output.$end.($cursymbolafter?' ':'').$cursymbolafter;
4329
+	$output = $cursymbolbefore.$output.$end.($cursymbolafter ? ' ' : '').$cursymbolafter;
4330 4330
 
4331 4331
 	return $output;
4332 4332
 }
@@ -4345,18 +4345,18 @@  discard block
 block discarded – undo
4345 4345
  *
4346 4346
  *	@see    price					Opposite function of price2num
4347 4347
  */
4348
-function price2num($amount,$rounding='',$alreadysqlnb=0)
4348
+function price2num($amount, $rounding = '', $alreadysqlnb = 0)
4349 4349
 {
4350
-	global $langs,$conf;
4350
+	global $langs, $conf;
4351 4351
 
4352 4352
 	// Round PHP function does not allow number like '1,234.56' nor '1.234,56' nor '1 234,56'
4353 4353
 	// Numbers must be '1234.56'
4354 4354
 	// Decimal delimiter for PHP and database SQL requests must be '.'
4355
-	$dec=','; $thousand=' ';
4356
-	if ($langs->transnoentitiesnoconv("SeparatorDecimal") != "SeparatorDecimal")  $dec=$langs->transnoentitiesnoconv("SeparatorDecimal");
4357
-	if ($langs->transnoentitiesnoconv("SeparatorThousand")!= "SeparatorThousand") $thousand=$langs->transnoentitiesnoconv("SeparatorThousand");
4358
-	if ($thousand == 'None') $thousand='';
4359
-	elseif ($thousand == 'Space') $thousand=' ';
4355
+	$dec = ','; $thousand = ' ';
4356
+	if ($langs->transnoentitiesnoconv("SeparatorDecimal") != "SeparatorDecimal")  $dec = $langs->transnoentitiesnoconv("SeparatorDecimal");
4357
+	if ($langs->transnoentitiesnoconv("SeparatorThousand") != "SeparatorThousand") $thousand = $langs->transnoentitiesnoconv("SeparatorThousand");
4358
+	if ($thousand == 'None') $thousand = '';
4359
+	elseif ($thousand == 'Space') $thousand = ' ';
4360 4360
 	//print "amount=".$amount." html=".$form." trunc=".$trunc." nbdecimal=".$nbdecimal." dec='".$dec."' thousand='".$thousand."'<br>";
4361 4361
 
4362 4362
 	// Convert value to universal number format (no thousand separator, '.' as decimal separator)
@@ -4369,30 +4369,30 @@  discard block
 block discarded – undo
4369 4369
 		if (is_numeric($amount))
4370 4370
 		{
4371 4371
 			// We put in temps value of decimal ("0.00001"). Works with 0 and 2.0E-5 and 9999.10
4372
-			$temps=sprintf("%0.10F",$amount-intval($amount));	// temps=0.0000000000 or 0.0000200000 or 9999.1000000000
4373
-			$temps=preg_replace('/([\.1-9])0+$/','\\1',$temps); // temps=0. or 0.00002 or 9999.1
4374
-			$nbofdec=max(0,dol_strlen($temps)-2);	// -2 to remove "0."
4375
-			$amount=number_format($amount,$nbofdec,$dec,$thousand);
4372
+			$temps = sprintf("%0.10F", $amount - intval($amount)); // temps=0.0000000000 or 0.0000200000 or 9999.1000000000
4373
+			$temps = preg_replace('/([\.1-9])0+$/', '\\1', $temps); // temps=0. or 0.00002 or 9999.1
4374
+			$nbofdec = max(0, dol_strlen($temps) - 2); // -2 to remove "0."
4375
+			$amount = number_format($amount, $nbofdec, $dec, $thousand);
4376 4376
 		}
4377 4377
 		//print "QQ".$amount.'<br>';
4378 4378
 
4379 4379
 		// Now make replace (the main goal of function)
4380
-		if ($thousand != ',' && $thousand != '.') $amount=str_replace(',','.',$amount);	// To accept 2 notations for french users
4381
-		$amount=str_replace(' ','',$amount);		// To avoid spaces
4382
-		$amount=str_replace($thousand,'',$amount);	// Replace of thousand before replace of dec to avoid pb if thousand is .
4383
-		$amount=str_replace($dec,'.',$amount);
4380
+		if ($thousand != ',' && $thousand != '.') $amount = str_replace(',', '.', $amount); // To accept 2 notations for french users
4381
+		$amount = str_replace(' ', '', $amount); // To avoid spaces
4382
+		$amount = str_replace($thousand, '', $amount); // Replace of thousand before replace of dec to avoid pb if thousand is .
4383
+		$amount = str_replace($dec, '.', $amount);
4384 4384
 	}
4385 4385
 
4386 4386
 	// Now, make a rounding if required
4387 4387
 	if ($rounding)
4388 4388
 	{
4389
-		$nbofdectoround='';
4390
-		if ($rounding == 'MU')     $nbofdectoround=$conf->global->MAIN_MAX_DECIMALS_UNIT;
4391
-		elseif ($rounding == 'MT') $nbofdectoround=$conf->global->MAIN_MAX_DECIMALS_TOT;
4392
-		elseif ($rounding == 'MS') $nbofdectoround=empty($conf->global->MAIN_MAX_DECIMALS_STOCK)?5:$conf->global->MAIN_MAX_DECIMALS_STOCK;
4393
-		elseif (is_numeric($rounding))  $nbofdectoround=$rounding; 	// For admin info page
4389
+		$nbofdectoround = '';
4390
+		if ($rounding == 'MU')     $nbofdectoround = $conf->global->MAIN_MAX_DECIMALS_UNIT;
4391
+		elseif ($rounding == 'MT') $nbofdectoround = $conf->global->MAIN_MAX_DECIMALS_TOT;
4392
+		elseif ($rounding == 'MS') $nbofdectoround = empty($conf->global->MAIN_MAX_DECIMALS_STOCK) ? 5 : $conf->global->MAIN_MAX_DECIMALS_STOCK;
4393
+		elseif (is_numeric($rounding))  $nbofdectoround = $rounding; // For admin info page
4394 4394
 		//print "RR".$amount.' - '.$nbofdectoround.'<br>';
4395
-		if (dol_strlen($nbofdectoround)) $amount = round($amount,$nbofdectoround);	// $nbofdectoround can be 0.
4395
+		if (dol_strlen($nbofdectoround)) $amount = round($amount, $nbofdectoround); // $nbofdectoround can be 0.
4396 4396
 		else return 'ErrorBadParameterProvidedToFunction';
4397 4397
 		//print 'SS'.$amount.' - '.$nbofdec.' - '.$dec.' - '.$thousand.' - '.$nbofdectoround.'<br>';
4398 4398
 
@@ -4401,19 +4401,19 @@  discard block
 block discarded – undo
4401 4401
 		if (is_numeric($amount))
4402 4402
 		{
4403 4403
 			// We put in temps value of decimal ("0.00001"). Works with 0 and 2.0E-5 and 9999.10
4404
-			$temps=sprintf("%0.10F",$amount-intval($amount));	// temps=0.0000000000 or 0.0000200000 or 9999.1000000000
4405
-			$temps=preg_replace('/([\.1-9])0+$/','\\1',$temps); // temps=0. or 0.00002 or 9999.1
4406
-			$nbofdec=max(0,dol_strlen($temps)-2);	// -2 to remove "0."
4407
-			$amount=number_format($amount,min($nbofdec,$nbofdectoround),$dec,$thousand);		// Convert amount to format with dolibarr dec and thousand
4404
+			$temps = sprintf("%0.10F", $amount - intval($amount)); // temps=0.0000000000 or 0.0000200000 or 9999.1000000000
4405
+			$temps = preg_replace('/([\.1-9])0+$/', '\\1', $temps); // temps=0. or 0.00002 or 9999.1
4406
+			$nbofdec = max(0, dol_strlen($temps) - 2); // -2 to remove "0."
4407
+			$amount = number_format($amount, min($nbofdec, $nbofdectoround), $dec, $thousand); // Convert amount to format with dolibarr dec and thousand
4408 4408
 		}
4409 4409
 		//print "TT".$amount.'<br>';
4410 4410
 
4411 4411
 		// Always make replace because each math function (like round) replace
4412 4412
 		// with local values and we want a number that has a SQL string format x.y
4413
-		if ($thousand != ',' && $thousand != '.') $amount=str_replace(',','.',$amount);	// To accept 2 notations for french users
4414
-		$amount=str_replace(' ','',$amount);		// To avoid spaces
4415
-		$amount=str_replace($thousand,'',$amount);	// Replace of thousand before replace of dec to avoid pb if thousand is .
4416
-		$amount=str_replace($dec,'.',$amount);
4413
+		if ($thousand != ',' && $thousand != '.') $amount = str_replace(',', '.', $amount); // To accept 2 notations for french users
4414
+		$amount = str_replace(' ', '', $amount); // To avoid spaces
4415
+		$amount = str_replace($thousand, '', $amount); // Replace of thousand before replace of dec to avoid pb if thousand is .
4416
+		$amount = str_replace($dec, '.', $amount);
4417 4417
 	}
4418 4418
 
4419 4419
 	return $amount;
@@ -4431,16 +4431,16 @@  discard block
 block discarded – undo
4431 4431
  * @param   string      $forceunitoutput    'no' or numeric (-3, -6, ...) compared to $unit
4432 4432
  * @return  string                      String to show dimensions
4433 4433
  */
4434
-function showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round=-1, $forceunitoutput='no')
4434
+function showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round = -1, $forceunitoutput = 'no')
4435 4435
 {
4436 4436
 	require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
4437 4437
 
4438
-	if (($forceunitoutput == 'no' && $dimension < 1/10000) || (is_numeric($forceunitoutput) && $forceunitoutput == -6))
4438
+	if (($forceunitoutput == 'no' && $dimension < 1 / 10000) || (is_numeric($forceunitoutput) && $forceunitoutput == -6))
4439 4439
 	{
4440 4440
 		$dimension = $dimension * 1000000;
4441 4441
 		$unit = $unit - 6;
4442 4442
 	}
4443
-	elseif (($forceunitoutput == 'no' && $dimension < 1/10) || (is_numeric($forceunitoutput) && $forceunitoutput == -3))
4443
+	elseif (($forceunitoutput == 'no' && $dimension < 1 / 10) || (is_numeric($forceunitoutput) && $forceunitoutput == -3))
4444 4444
 	{
4445 4445
 		$dimension = $dimension * 1000;
4446 4446
 		$unit = $unit - 3;
@@ -4456,7 +4456,7 @@  discard block
 block discarded – undo
4456 4456
 		$unit = $unit + 3;
4457 4457
 	}
4458 4458
 
4459
-	$ret=price($dimension, 0, $outputlangs, 0, 0, $round).' '.measuring_units_string($unit, $type);
4459
+	$ret = price($dimension, 0, $outputlangs, 0, 0, $round).' '.measuring_units_string($unit, $type);
4460 4460
 
4461 4461
 	return $ret;
4462 4462
 }
@@ -4474,13 +4474,13 @@  discard block
 block discarded – undo
4474 4474
  * 	@return	mixed			   					0 if not found, localtax rate if found
4475 4475
  *  @see get_default_tva
4476 4476
  */
4477
-function get_localtax($vatrate, $local, $thirdparty_buyer="", $thirdparty_seller="", $vatnpr=0)
4477
+function get_localtax($vatrate, $local, $thirdparty_buyer = "", $thirdparty_seller = "", $vatnpr = 0)
4478 4478
 {
4479 4479
 	global $db, $conf, $mysoc;
4480 4480
 
4481
-	if (empty($thirdparty_seller) || ! is_object($thirdparty_seller)) $thirdparty_seller=$mysoc;
4481
+	if (empty($thirdparty_seller) || !is_object($thirdparty_seller)) $thirdparty_seller = $mysoc;
4482 4482
 
4483
-	dol_syslog("get_localtax tva=".$vatrate." local=".$local." thirdparty_buyer id=".(is_object($thirdparty_buyer)?$thirdparty_buyer->id:'')."/country_code=".(is_object($thirdparty_buyer)?$thirdparty_buyer->country_code:'')." thirdparty_seller id=".$thirdparty_seller->id."/country_code=".$thirdparty_seller->country_code." thirdparty_seller localtax1_assuj=".$thirdparty_seller->localtax1_assuj."  thirdparty_seller localtax2_assuj=".$thirdparty_seller->localtax2_assuj);
4483
+	dol_syslog("get_localtax tva=".$vatrate." local=".$local." thirdparty_buyer id=".(is_object($thirdparty_buyer) ? $thirdparty_buyer->id : '')."/country_code=".(is_object($thirdparty_buyer) ? $thirdparty_buyer->country_code : '')." thirdparty_seller id=".$thirdparty_seller->id."/country_code=".$thirdparty_seller->country_code." thirdparty_seller localtax1_assuj=".$thirdparty_seller->localtax1_assuj."  thirdparty_seller localtax2_assuj=".$thirdparty_seller->localtax2_assuj);
4484 4484
 
4485 4485
 	$vatratecleaned = $vatrate;
4486 4486
 	if (preg_match('/^(.*)\s*\((.*)\)$/', $vatrate, $reg))      // If vat is "xx (yy)"
@@ -4499,34 +4499,34 @@  discard block
 block discarded – undo
4499 4499
 	{
4500 4500
 		if ($local == 1)
4501 4501
 		{
4502
-			if (! $mysoc->localtax1_assuj || (string) $vatratecleaned == "0") return 0;
4502
+			if (!$mysoc->localtax1_assuj || (string) $vatratecleaned == "0") return 0;
4503 4503
 			if ($thirdparty_seller->id == $mysoc->id)
4504 4504
 			{
4505
-				if (! $thirdparty_buyer->localtax1_assuj) return 0;
4505
+				if (!$thirdparty_buyer->localtax1_assuj) return 0;
4506 4506
 			}
4507 4507
 			else
4508 4508
 			{
4509
-				if (! $thirdparty_seller->localtax1_assuj) return 0;
4509
+				if (!$thirdparty_seller->localtax1_assuj) return 0;
4510 4510
 			}
4511 4511
 		}
4512 4512
 
4513 4513
 		if ($local == 2)
4514 4514
 		{
4515
-			if (! $mysoc->localtax2_assuj || (string) $vatratecleaned == "0") return 0;
4515
+			if (!$mysoc->localtax2_assuj || (string) $vatratecleaned == "0") return 0;
4516 4516
 			if ($thirdparty_seller->id == $mysoc->id)
4517 4517
 			{
4518
-				if (! $thirdparty_buyer->localtax2_assuj) return 0;
4518
+				if (!$thirdparty_buyer->localtax2_assuj) return 0;
4519 4519
 			}
4520 4520
 			else
4521 4521
 			{
4522
-				if (! $thirdparty_seller->localtax2_assuj) return 0;
4522
+				if (!$thirdparty_seller->localtax2_assuj) return 0;
4523 4523
 			}
4524 4524
 		}
4525 4525
 	}
4526 4526
 	else
4527 4527
 	{
4528
-		if ($local == 1 && ! $thirdparty_seller->localtax1_assuj) return 0;
4529
-		if ($local == 2 && ! $thirdparty_seller->localtax2_assuj) return 0;
4528
+		if ($local == 1 && !$thirdparty_seller->localtax1_assuj) return 0;
4529
+		if ($local == 2 && !$thirdparty_seller->localtax2_assuj) return 0;
4530 4530
 	}
4531 4531
 
4532 4532
 	// For some country MAIN_GET_LOCALTAXES_VALUES_FROM_THIRDPARTY is forced to on.
@@ -4536,9 +4536,9 @@  discard block
 block discarded – undo
4536 4536
 	}
4537 4537
 
4538 4538
 	// Search local taxes
4539
-	if (! empty($conf->global->MAIN_GET_LOCALTAXES_VALUES_FROM_THIRDPARTY))
4539
+	if (!empty($conf->global->MAIN_GET_LOCALTAXES_VALUES_FROM_THIRDPARTY))
4540 4540
 	{
4541
-		if ($local==1)
4541
+		if ($local == 1)
4542 4542
 		{
4543 4543
 			if ($thirdparty_seller != $mysoc)
4544 4544
 			{
@@ -4555,7 +4555,7 @@  discard block
 block discarded – undo
4555 4555
 				}
4556 4556
 			}
4557 4557
 		}
4558
-		if ($local==2)
4558
+		if ($local == 2)
4559 4559
 		{
4560 4560
 			if ($thirdparty_seller != $mysoc)
4561 4561
 			{
@@ -4576,20 +4576,20 @@  discard block
 block discarded – undo
4576 4576
 	}
4577 4577
 
4578 4578
 	// By default, search value of local tax on line of common tax
4579
-	$sql  = "SELECT t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
4579
+	$sql = "SELECT t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
4580 4580
    	$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
4581 4581
    	$sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$thirdparty_seller->country_code."'";
4582 4582
    	$sql .= " AND t.taux = ".((float) $vatratecleaned)." AND t.active = 1";
4583
-   	if ($vatratecode) $sql.= " AND t.code ='".$vatratecode."'";		// If we have the code, we use it in priority
4584
-   	else $sql.= " AND t.recuperableonly ='".$vatnpr."'";
4583
+   	if ($vatratecode) $sql .= " AND t.code ='".$vatratecode."'"; // If we have the code, we use it in priority
4584
+   	else $sql .= " AND t.recuperableonly ='".$vatnpr."'";
4585 4585
    	dol_syslog("get_localtax", LOG_DEBUG);
4586
-   	$resql=$db->query($sql);
4586
+   	$resql = $db->query($sql);
4587 4587
 
4588 4588
    	if ($resql)
4589 4589
    	{
4590 4590
    		$obj = $db->fetch_object($resql);
4591
-   		if ($local==1) return $obj->localtax1;
4592
-   		elseif ($local==2) return $obj->localtax2;
4591
+   		if ($local == 1) return $obj->localtax1;
4592
+   		elseif ($local == 2) return $obj->localtax2;
4593 4593
 	}
4594 4594
 
4595 4595
 	return 0;
@@ -4606,11 +4606,11 @@  discard block
 block discarded – undo
4606 4606
  */
4607 4607
 function isOnlyOneLocalTax($local)
4608 4608
 {
4609
-	$tax=get_localtax_by_third($local);
4609
+	$tax = get_localtax_by_third($local);
4610 4610
 
4611
-	$valors=explode(":", $tax);
4611
+	$valors = explode(":", $tax);
4612 4612
 
4613
-	if (count($valors)>1)
4613
+	if (count($valors) > 1)
4614 4614
 	{
4615 4615
 		return false;
4616 4616
 	}
@@ -4629,19 +4629,19 @@  discard block
 block discarded – undo
4629 4629
 function get_localtax_by_third($local)
4630 4630
 {
4631 4631
 	global $db, $mysoc;
4632
-	$sql ="SELECT t.localtax1, t.localtax2 ";
4633
-	$sql.=" FROM ".MAIN_DB_PREFIX."c_tva as t inner join ".MAIN_DB_PREFIX."c_country as c ON c.rowid=t.fk_pays";
4634
-	$sql.=" WHERE c.code = '".$mysoc->country_code."' AND t.active = 1 AND t.taux=(";
4635
-	$sql.="  SELECT max(tt.taux) FROM ".MAIN_DB_PREFIX."c_tva as tt inner join ".MAIN_DB_PREFIX."c_country as c ON c.rowid=tt.fk_pays";
4636
-	$sql.="  WHERE c.code = '".$mysoc->country_code."' AND tt.active = 1";
4637
-	$sql.="  )";
4638
-
4639
-	$resql=$db->query($sql);
4632
+	$sql = "SELECT t.localtax1, t.localtax2 ";
4633
+	$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t inner join ".MAIN_DB_PREFIX."c_country as c ON c.rowid=t.fk_pays";
4634
+	$sql .= " WHERE c.code = '".$mysoc->country_code."' AND t.active = 1 AND t.taux=(";
4635
+	$sql .= "  SELECT max(tt.taux) FROM ".MAIN_DB_PREFIX."c_tva as tt inner join ".MAIN_DB_PREFIX."c_country as c ON c.rowid=tt.fk_pays";
4636
+	$sql .= "  WHERE c.code = '".$mysoc->country_code."' AND tt.active = 1";
4637
+	$sql .= "  )";
4638
+
4639
+	$resql = $db->query($sql);
4640 4640
 	if ($resql)
4641 4641
 	{
4642 4642
 		$obj = $db->fetch_object($resql);
4643
-		if ($local==1) return $obj->localtax1;
4644
-		elseif ($local==2) return $obj->localtax2;
4643
+		if ($local == 1) return $obj->localtax1;
4644
+		elseif ($local == 2) return $obj->localtax2;
4645 4645
 	}
4646 4646
 
4647 4647
 	return 0;
@@ -4660,7 +4660,7 @@  discard block
 block discarded – undo
4660 4660
  *  @return	array       	  				array('rowid'=> , 'code'=> ...)
4661 4661
  *  @see getLocalTaxesFromRate
4662 4662
  */
4663
-function getTaxesFromId($vatrate, $buyer=null, $seller=null, $firstparamisid=1)
4663
+function getTaxesFromId($vatrate, $buyer = null, $seller = null, $firstparamisid = 1)
4664 4664
 {
4665 4665
 	global $db, $mysoc;
4666 4666
 
@@ -4668,8 +4668,8 @@  discard block
 block discarded – undo
4668 4668
 
4669 4669
 	// Search local taxes
4670 4670
 	$sql = "SELECT t.rowid, t.code, t.taux as rate, t.recuperableonly as npr, t.accountancy_code_sell, t.accountancy_code_buy";
4671
-	$sql.= " FROM ".MAIN_DB_PREFIX."c_tva as t";
4672
-	if ($firstparamisid) $sql.= " WHERE t.rowid = ".(int) $vatrate;
4671
+	$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t";
4672
+	if ($firstparamisid) $sql .= " WHERE t.rowid = ".(int) $vatrate;
4673 4673
 	else
4674 4674
 	{
4675 4675
 		$vatratecleaned = $vatrate;
@@ -4680,14 +4680,14 @@  discard block
 block discarded – undo
4680 4680
 			$vatratecode = $reg[2];
4681 4681
 		}
4682 4682
 
4683
-		$sql.=", ".MAIN_DB_PREFIX."c_country as c";
4684
-		if ($mysoc->country_code == 'ES') $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$buyer->country_code."'";    // local tax in spain use the buyer country ??
4683
+		$sql .= ", ".MAIN_DB_PREFIX."c_country as c";
4684
+		if ($mysoc->country_code == 'ES') $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$buyer->country_code."'"; // local tax in spain use the buyer country ??
4685 4685
 		else $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$seller->country_code."'";
4686
-		$sql.= " AND t.taux = ".((float) $vatratecleaned)." AND t.active = 1";
4687
-		if ($vatratecode) $sql.= " AND t.code = '".$vatratecode."'";
4686
+		$sql .= " AND t.taux = ".((float) $vatratecleaned)." AND t.active = 1";
4687
+		if ($vatratecode) $sql .= " AND t.code = '".$vatratecode."'";
4688 4688
 	}
4689 4689
 
4690
-	$resql=$db->query($sql);
4690
+	$resql = $db->query($sql);
4691 4691
 	if ($resql)
4692 4692
 	{
4693 4693
 		$obj = $db->fetch_object($resql);
@@ -4715,7 +4715,7 @@  discard block
 block discarded – undo
4715 4715
  *  @return	array    	    				array(localtax_type1(1-6/0 if not found), rate localtax1, localtax_type2, rate localtax2, accountancycodecust, accountancycodesupp)
4716 4716
  *  @see getTaxesFromId
4717 4717
  */
4718
-function getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
4718
+function getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid = 0)
4719 4719
 {
4720 4720
 	global $db, $mysoc;
4721 4721
 
@@ -4724,7 +4724,7 @@  discard block
 block discarded – undo
4724 4724
 	// Search local taxes
4725 4725
 	$sql  = "SELECT t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type, t.accountancy_code_sell, t.accountancy_code_buy";
4726 4726
 	$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t";
4727
-	if ($firstparamisid) $sql.= " WHERE t.rowid = ".(int) $vatrate;
4727
+	if ($firstparamisid) $sql .= " WHERE t.rowid = ".(int) $vatrate;
4728 4728
 	else
4729 4729
 	{
4730 4730
 		$vatratecleaned = $vatrate;
@@ -4735,46 +4735,46 @@  discard block
 block discarded – undo
4735 4735
 			$vatratecode = $reg[2];
4736 4736
 		}
4737 4737
 
4738
-		$sql.=", ".MAIN_DB_PREFIX."c_country as c";
4739
-		if ($mysoc->country_code == 'ES') $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$buyer->country_code."'";    // local tax in spain use the buyer country ??
4738
+		$sql .= ", ".MAIN_DB_PREFIX."c_country as c";
4739
+		if ($mysoc->country_code == 'ES') $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$buyer->country_code."'"; // local tax in spain use the buyer country ??
4740 4740
 		else $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$seller->country_code."'";
4741
-		$sql.= " AND t.taux = ".((float) $vatratecleaned)." AND t.active = 1";
4742
-		if ($vatratecode) $sql.= " AND t.code = '".$vatratecode."'";
4741
+		$sql .= " AND t.taux = ".((float) $vatratecleaned)." AND t.active = 1";
4742
+		if ($vatratecode) $sql .= " AND t.code = '".$vatratecode."'";
4743 4743
 	}
4744 4744
 
4745
-	$resql=$db->query($sql);
4745
+	$resql = $db->query($sql);
4746 4746
 	if ($resql)
4747 4747
 	{
4748 4748
 		$obj = $db->fetch_object($resql);
4749 4749
 		if ($local == 1)
4750 4750
 		{
4751
-			if (! isOnlyOneLocalTax(1))
4751
+			if (!isOnlyOneLocalTax(1))
4752 4752
 			{
4753 4753
 				return array($obj->localtax1_type, get_localtax($vatrate, $local, $buyer, $seller), $obj->accountancy_code_sell, $obj->accountancy_code_buy);
4754 4754
 			}
4755 4755
 			else
4756 4756
 			{
4757
-				return array($obj->localtax1_type, $obj->localtax1,$obj->accountancy_code_sell, $obj->accountancy_code_buy);
4757
+				return array($obj->localtax1_type, $obj->localtax1, $obj->accountancy_code_sell, $obj->accountancy_code_buy);
4758 4758
 			}
4759 4759
 		}
4760 4760
 		elseif ($local == 2)
4761 4761
 		{
4762
-			if (! isOnlyOneLocalTax(2))
4762
+			if (!isOnlyOneLocalTax(2))
4763 4763
 			{
4764
-				return array($obj->localtax2_type, get_localtax($vatrate, $local, $buyer, $seller),$obj->accountancy_code_sell, $obj->accountancy_code_buy);
4764
+				return array($obj->localtax2_type, get_localtax($vatrate, $local, $buyer, $seller), $obj->accountancy_code_sell, $obj->accountancy_code_buy);
4765 4765
 			}
4766 4766
 			else
4767 4767
 			{
4768
-				return array($obj->localtax2_type, $obj->localtax2,$obj->accountancy_code_sell, $obj->accountancy_code_buy);
4768
+				return array($obj->localtax2_type, $obj->localtax2, $obj->accountancy_code_sell, $obj->accountancy_code_buy);
4769 4769
 			}
4770 4770
 		}
4771 4771
 		else
4772 4772
 		{
4773
-			if(! isOnlyOneLocalTax(1))
4773
+			if (!isOnlyOneLocalTax(1))
4774 4774
 			{
4775
-				if(! isOnlyOneLocalTax(2))
4775
+				if (!isOnlyOneLocalTax(2))
4776 4776
 				{
4777
-					return array($obj->localtax1_type, get_localtax($vatrate, 1, $buyer, $seller), $obj->localtax2_type, get_localtax($vatrate, 2, $buyer, $seller), $obj->accountancy_code_sell,$obj->accountancy_code_buy);
4777
+					return array($obj->localtax1_type, get_localtax($vatrate, 1, $buyer, $seller), $obj->localtax2_type, get_localtax($vatrate, 2, $buyer, $seller), $obj->accountancy_code_sell, $obj->accountancy_code_buy);
4778 4778
 				}
4779 4779
 				else
4780 4780
 				{
@@ -4783,7 +4783,7 @@  discard block
 block discarded – undo
4783 4783
 			}
4784 4784
 			else
4785 4785
 			{
4786
-				if(! isOnlyOneLocalTax(2))
4786
+				if (!isOnlyOneLocalTax(2))
4787 4787
 				{
4788 4788
 					return array($obj->localtax1_type, $obj->localtax1, $obj->localtax2_type, get_localtax($vatrate, 2, $buyer, $seller), $obj->accountancy_code_sell, $obj->accountancy_code_buy);
4789 4789
 				}
@@ -4808,35 +4808,35 @@  discard block
 block discarded – undo
4808 4808
  *  @return float|string   				    Vat rate to use with format 5.0 or '5.0 (XXX)'
4809 4809
  *  @see get_product_localtax_for_country
4810 4810
  */
4811
-function get_product_vat_for_country($idprod, $thirdparty_seller, $idprodfournprice=0)
4811
+function get_product_vat_for_country($idprod, $thirdparty_seller, $idprodfournprice = 0)
4812 4812
 {
4813
-	global $db,$conf,$mysoc;
4813
+	global $db, $conf, $mysoc;
4814 4814
 
4815
-	require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
4815
+	require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
4816 4816
 
4817
-	$ret=0;
4818
-	$found=0;
4817
+	$ret = 0;
4818
+	$found = 0;
4819 4819
 
4820 4820
 	if ($idprod > 0)
4821 4821
 	{
4822 4822
 		// Load product
4823
-		$product=new Product($db);
4824
-		$result=$product->fetch($idprod);
4823
+		$product = new Product($db);
4824
+		$result = $product->fetch($idprod);
4825 4825
 
4826 4826
 		if ($mysoc->country_code == $thirdparty_seller->country_code) // If selling country is ours
4827 4827
 		{
4828 4828
 			if ($idprodfournprice > 0)     // We want vat for product for a "supplier" order or invoice
4829 4829
 			{
4830
-				$product->get_buyprice($idprodfournprice,0,0,0);
4831
-				$ret=$product->vatrate_supplier;
4832
-				if ($product->default_vat_code) $ret.=' ('.$product->default_vat_code.')';
4830
+				$product->get_buyprice($idprodfournprice, 0, 0, 0);
4831
+				$ret = $product->vatrate_supplier;
4832
+				if ($product->default_vat_code) $ret .= ' ('.$product->default_vat_code.')';
4833 4833
 			}
4834 4834
 			else
4835 4835
 			{
4836
-				$ret=$product->tva_tx;    // Default vat of product we defined
4837
-				if ($product->default_vat_code) $ret.=' ('.$product->default_vat_code.')';
4836
+				$ret = $product->tva_tx; // Default vat of product we defined
4837
+				if ($product->default_vat_code) $ret .= ' ('.$product->default_vat_code.')';
4838 4838
 			}
4839
-			$found=1;
4839
+			$found = 1;
4840 4840
 		}
4841 4841
 		else
4842 4842
 		{
@@ -4845,30 +4845,30 @@  discard block
 block discarded – undo
4845 4845
 		}
4846 4846
 	}
4847 4847
 
4848
-	if (! $found)
4848
+	if (!$found)
4849 4849
 	{
4850 4850
 		if (empty($conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS))
4851 4851
 		{
4852 4852
 			// If vat of product for the country not found or not defined, we return the first higher vat of country.
4853 4853
 			$sql = "SELECT taux as vat_rate";
4854
-			$sql.= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
4855
-			$sql.= " WHERE t.active=1 AND t.fk_pays = c.rowid AND c.code='".$thirdparty_seller->country_code."'";
4856
-			$sql.= " ORDER BY t.taux DESC, t.code ASC, t.recuperableonly ASC";
4857
-			$sql.= $db->plimit(1);
4854
+			$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
4855
+			$sql .= " WHERE t.active=1 AND t.fk_pays = c.rowid AND c.code='".$thirdparty_seller->country_code."'";
4856
+			$sql .= " ORDER BY t.taux DESC, t.code ASC, t.recuperableonly ASC";
4857
+			$sql .= $db->plimit(1);
4858 4858
 
4859
-			$resql=$db->query($sql);
4859
+			$resql = $db->query($sql);
4860 4860
 			if ($resql)
4861 4861
 			{
4862
-				$obj=$db->fetch_object($resql);
4862
+				$obj = $db->fetch_object($resql);
4863 4863
 				if ($obj)
4864 4864
 				{
4865
-					$ret=$obj->vat_rate;
4865
+					$ret = $obj->vat_rate;
4866 4866
 				}
4867 4867
 				$db->free($sql);
4868 4868
 			}
4869 4869
 			else dol_print_error($db);
4870 4870
 		}
4871
-		else $ret=$conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS;    // Forced value if autodetect fails
4871
+		else $ret = $conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS; // Forced value if autodetect fails
4872 4872
 	}
4873 4873
 
4874 4874
 	dol_syslog("get_product_vat_for_country: ret=".$ret);
@@ -4886,20 +4886,20 @@  discard block
 block discarded – undo
4886 4886
  */
4887 4887
 function get_product_localtax_for_country($idprod, $local, $thirdparty_seller)
4888 4888
 {
4889
-	global $db,$mysoc;
4889
+	global $db, $mysoc;
4890 4890
 
4891
-	if (! class_exists('Product')) {
4892
-		require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
4891
+	if (!class_exists('Product')) {
4892
+		require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
4893 4893
 	}
4894 4894
 
4895
-	$ret=0;
4896
-	$found=0;
4895
+	$ret = 0;
4896
+	$found = 0;
4897 4897
 
4898 4898
 	if ($idprod > 0)
4899 4899
 	{
4900 4900
 		// Load product
4901
-		$product=new Product($db);
4902
-		$result=$product->fetch($idprod);
4901
+		$product = new Product($db);
4902
+		$result = $product->fetch($idprod);
4903 4903
 
4904 4904
 		if ($mysoc->country_code == $thirdparty_seller->country_code) // If selling country is ours
4905 4905
 		{
@@ -4917,23 +4917,23 @@  discard block
 block discarded – undo
4917 4917
 		}
4918 4918
 	}
4919 4919
 
4920
-	if (! $found)
4920
+	if (!$found)
4921 4921
 	{
4922 4922
 		// If vat of product for the country not found or not defined, we return higher vat of country.
4923 4923
 		$sql = "SELECT taux as vat_rate, localtax1, localtax2";
4924
-		$sql.= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
4925
-		$sql.= " WHERE t.active=1 AND t.fk_pays = c.rowid AND c.code='".$thirdparty_seller->country_code."'";
4926
-		$sql.= " ORDER BY t.taux DESC, t.recuperableonly ASC";
4927
-		$sql.= $db->plimit(1);
4924
+		$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
4925
+		$sql .= " WHERE t.active=1 AND t.fk_pays = c.rowid AND c.code='".$thirdparty_seller->country_code."'";
4926
+		$sql .= " ORDER BY t.taux DESC, t.recuperableonly ASC";
4927
+		$sql .= $db->plimit(1);
4928 4928
 
4929
-		$resql=$db->query($sql);
4929
+		$resql = $db->query($sql);
4930 4930
 		if ($resql)
4931 4931
 		{
4932
-			$obj=$db->fetch_object($resql);
4932
+			$obj = $db->fetch_object($resql);
4933 4933
 			if ($obj)
4934 4934
 			{
4935
-				if ($local==1) $ret=$obj->localtax1;
4936
-				elseif ($local==2) $ret=$obj->localtax2;
4935
+				if ($local == 1) $ret = $obj->localtax1;
4936
+				elseif ($local == 2) $ret = $obj->localtax2;
4937 4937
 			}
4938 4938
 		}
4939 4939
 		else dol_print_error($db);
@@ -4959,14 +4959,14 @@  discard block
 block discarded – undo
4959 4959
  *	@return float|string   				      	Vat rate to use with format 5.0 or '5.0 (XXX)', -1 if we can't guess it
4960 4960
  *  @see get_default_npr, get_default_localtax
4961 4961
  */
4962
-function get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
4962
+function get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod = 0, $idprodfournprice = 0)
4963 4963
 {
4964 4964
 	global $conf;
4965 4965
 
4966 4966
 	require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
4967 4967
 
4968 4968
 	// Note: possible values for tva_assuj are 0/1 or franchise/reel
4969
-	$seller_use_vat=((is_numeric($thirdparty_seller->tva_assuj) && ! $thirdparty_seller->tva_assuj) || (! is_numeric($thirdparty_seller->tva_assuj) && $thirdparty_seller->tva_assuj=='franchise'))?0:1;
4969
+	$seller_use_vat = ((is_numeric($thirdparty_seller->tva_assuj) && !$thirdparty_seller->tva_assuj) || (!is_numeric($thirdparty_seller->tva_assuj) && $thirdparty_seller->tva_assuj == 'franchise')) ? 0 : 1;
4970 4970
 
4971 4971
 	$seller_country_code = $thirdparty_seller->country_code;
4972 4972
 	$seller_in_cee = isInEEC($thirdparty_seller);
@@ -4974,21 +4974,21 @@  discard block
 block discarded – undo
4974 4974
 	$buyer_country_code = $thirdparty_buyer->country_code;
4975 4975
 	$buyer_in_cee = isInEEC($thirdparty_buyer);
4976 4976
 
4977
-	dol_syslog("get_default_tva: seller use vat=".$seller_use_vat.", seller country=".$seller_country_code.", seller in cee=".$seller_in_cee.", buyer country=".$buyer_country_code.", buyer in cee=".$buyer_in_cee.", idprod=".$idprod.", idprodfournprice=".$idprodfournprice.", SERVICE_ARE_ECOMMERCE_200238EC=".(! empty($conf->global->SERVICES_ARE_ECOMMERCE_200238EC)?$conf->global->SERVICES_ARE_ECOMMERCE_200238EC:''));
4977
+	dol_syslog("get_default_tva: seller use vat=".$seller_use_vat.", seller country=".$seller_country_code.", seller in cee=".$seller_in_cee.", buyer country=".$buyer_country_code.", buyer in cee=".$buyer_in_cee.", idprod=".$idprod.", idprodfournprice=".$idprodfournprice.", SERVICE_ARE_ECOMMERCE_200238EC=".(!empty($conf->global->SERVICES_ARE_ECOMMERCE_200238EC) ? $conf->global->SERVICES_ARE_ECOMMERCE_200238EC : ''));
4978 4978
 
4979 4979
 	// If services are eServices according to EU Council Directive 2002/38/EC (http://ec.europa.eu/taxation_customs/taxation/vat/traders/e-commerce/article_1610_en.htm)
4980 4980
 	// we use the buyer VAT.
4981
-	if (! empty($conf->global->SERVICE_ARE_ECOMMERCE_200238EC))
4981
+	if (!empty($conf->global->SERVICE_ARE_ECOMMERCE_200238EC))
4982 4982
 	{
4983
-		if ($seller_in_cee && $buyer_in_cee && ! $thirdparty_buyer->isACompany())
4983
+		if ($seller_in_cee && $buyer_in_cee && !$thirdparty_buyer->isACompany())
4984 4984
 		{
4985 4985
 			//print 'VATRULE 0';
4986
-			return get_product_vat_for_country($idprod,$thirdparty_buyer,$idprodfournprice);
4986
+			return get_product_vat_for_country($idprod, $thirdparty_buyer, $idprodfournprice);
4987 4987
 		}
4988 4988
 	}
4989 4989
 
4990 4990
 	// If seller does not use VAT
4991
-	if (! $seller_use_vat)
4991
+	if (!$seller_use_vat)
4992 4992
 	{
4993 4993
 		//print 'VATRULE 1';
4994 4994
 		return 0;
@@ -4998,10 +4998,10 @@  discard block
 block discarded – undo
4998 4998
 
4999 4999
 	// Si le (pays vendeur = pays acheteur) alors la TVA par defaut=TVA du produit vendu. Fin de regle.
5000 5000
 	if (($seller_country_code == $buyer_country_code)
5001
-	|| (in_array($seller_country_code,array('FR,MC')) && in_array($buyer_country_code,array('FR','MC')))) // Warning ->country_code not always defined
5001
+	|| (in_array($seller_country_code, array('FR,MC')) && in_array($buyer_country_code, array('FR', 'MC')))) // Warning ->country_code not always defined
5002 5002
 	{
5003 5003
 		//print 'VATRULE 2';
5004
-		return get_product_vat_for_country($idprod,$thirdparty_seller,$idprodfournprice);
5004
+		return get_product_vat_for_country($idprod, $thirdparty_seller, $idprodfournprice);
5005 5005
 	}
5006 5006
 
5007 5007
 	// Si (vendeur et acheteur dans Communaute europeenne) et (bien vendu = moyen de transports neuf comme auto, bateau, avion) alors TVA par defaut=0 (La TVA doit etre paye par l'acheteur au centre d'impots de son pays et non au vendeur). Fin de regle.
@@ -5011,7 +5011,7 @@  discard block
 block discarded – undo
5011 5011
 	// Si (vendeur et acheteur dans Communaute europeenne) et (acheteur = particulier) alors TVA par defaut=TVA du produit vendu. Fin de regle
5012 5012
 	if (($seller_in_cee && $buyer_in_cee))
5013 5013
 	{
5014
-		$isacompany=$thirdparty_buyer->isACompany();
5014
+		$isacompany = $thirdparty_buyer->isACompany();
5015 5015
 		if ($isacompany)
5016 5016
 		{
5017 5017
 			//print 'VATRULE 3';
@@ -5020,7 +5020,7 @@  discard block
 block discarded – undo
5020 5020
 		else
5021 5021
 		{
5022 5022
 			//print 'VATRULE 4';
5023
-			return get_product_vat_for_country($idprod,$thirdparty_seller,$idprodfournprice);
5023
+			return get_product_vat_for_country($idprod, $thirdparty_seller, $idprodfournprice);
5024 5024
 		}
5025 5025
 	}
5026 5026
 
@@ -5041,22 +5041,22 @@  discard block
 block discarded – undo
5041 5041
  *	@return float       			        	0 or 1
5042 5042
  *  @see get_default_tva, get_default_localtax
5043 5043
  */
5044
-function get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
5044
+function get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod = 0, $idprodfournprice = 0)
5045 5045
 {
5046 5046
 	global $db;
5047 5047
 
5048 5048
 	if ($idprodfournprice > 0)
5049 5049
 	{
5050
-		if (! class_exists('ProductFournisseur'))
5051
-			require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.product.class.php';
5050
+		if (!class_exists('ProductFournisseur'))
5051
+			require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
5052 5052
 		$prodprice = new ProductFournisseur($db);
5053 5053
 		$prodprice->fetch_product_fournisseur_price($idprodfournprice);
5054 5054
 		return $prodprice->fourn_tva_npr;
5055 5055
 	}
5056 5056
 	elseif ($idprod > 0)
5057 5057
 	{
5058
-		if (! class_exists('Product'))
5059
-			require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
5058
+		if (!class_exists('Product'))
5059
+			require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
5060 5060
 		$prod = new Product($db);
5061 5061
 		$prod->fetch($idprod);
5062 5062
 		return $prod->tva_npr;
@@ -5078,31 +5078,31 @@  discard block
 block discarded – undo
5078 5078
  *	@return integer        				       	localtax, -1 si ne peut etre determine
5079 5079
  *  @see get_default_tva, get_default_npr
5080 5080
  */
5081
-function get_default_localtax($thirdparty_seller, $thirdparty_buyer, $local, $idprod=0)
5081
+function get_default_localtax($thirdparty_seller, $thirdparty_buyer, $local, $idprod = 0)
5082 5082
 {
5083 5083
 	global $mysoc;
5084 5084
 
5085 5085
 	if (!is_object($thirdparty_seller)) return -1;
5086 5086
 	if (!is_object($thirdparty_buyer)) return -1;
5087 5087
 
5088
-	if ($local==1) // Localtax 1
5088
+	if ($local == 1) // Localtax 1
5089 5089
 	{
5090 5090
 		if ($mysoc->country_code == 'ES')
5091 5091
 		{
5092
-			if (is_numeric($thirdparty_buyer->localtax1_assuj) && ! $thirdparty_buyer->localtax1_assuj) return 0;
5092
+			if (is_numeric($thirdparty_buyer->localtax1_assuj) && !$thirdparty_buyer->localtax1_assuj) return 0;
5093 5093
 		}
5094 5094
 		else
5095 5095
 		{
5096 5096
 			// Si vendeur non assujeti a Localtax1, localtax1 par default=0
5097
-			if (is_numeric($thirdparty_seller->localtax1_assuj) && ! $thirdparty_seller->localtax1_assuj) return 0;
5098
-			if (! is_numeric($thirdparty_seller->localtax1_assuj) && $thirdparty_seller->localtax1_assuj=='localtax1off') return 0;
5097
+			if (is_numeric($thirdparty_seller->localtax1_assuj) && !$thirdparty_seller->localtax1_assuj) return 0;
5098
+			if (!is_numeric($thirdparty_seller->localtax1_assuj) && $thirdparty_seller->localtax1_assuj == 'localtax1off') return 0;
5099 5099
 		}
5100 5100
 	}
5101
-	elseif ($local==2) //I Localtax 2
5101
+	elseif ($local == 2) //I Localtax 2
5102 5102
 	{
5103 5103
 		// Si vendeur non assujeti a Localtax2, localtax2 par default=0
5104
-		if (is_numeric($thirdparty_seller->localtax2_assuj) && ! $thirdparty_seller->localtax2_assuj) return 0;
5105
-		if (! is_numeric($thirdparty_seller->localtax2_assuj) && $thirdparty_seller->localtax2_assuj=='localtax2off') return 0;
5104
+		if (is_numeric($thirdparty_seller->localtax2_assuj) && !$thirdparty_seller->localtax2_assuj) return 0;
5105
+		if (!is_numeric($thirdparty_seller->localtax2_assuj) && $thirdparty_seller->localtax2_assuj == 'localtax2off') return 0;
5106 5106
 	}
5107 5107
 
5108 5108
 	if ($thirdparty_seller->country_code == $thirdparty_buyer->country_code)
@@ -5121,28 +5121,28 @@  discard block
 block discarded – undo
5121 5121
  *	@param	int		$color			0=texte only, 1=Text is formated with a color font style ('ok' or 'error'), 2=Text is formated with 'ok' color.
5122 5122
  *	@return	string					HTML string
5123 5123
  */
5124
-function yn($yesno, $case=1, $color=0)
5124
+function yn($yesno, $case = 1, $color = 0)
5125 5125
 {
5126 5126
 	global $langs;
5127
-	$result='unknown'; $classname='';
5127
+	$result = 'unknown'; $classname = '';
5128 5128
 	if ($yesno == 1 || strtolower($yesno) == 'yes' || strtolower($yesno) == 'true') 	// A mettre avant test sur no a cause du == 0
5129 5129
 	{
5130
-		$result=$langs->trans('yes');
5131
-		if ($case == 1 || $case == 3) $result=$langs->trans("Yes");
5132
-		if ($case == 2) $result='<input type="checkbox" value="1" checked disabled>';
5133
-		if ($case == 3) $result='<input type="checkbox" value="1" checked disabled> '.$result;
5130
+		$result = $langs->trans('yes');
5131
+		if ($case == 1 || $case == 3) $result = $langs->trans("Yes");
5132
+		if ($case == 2) $result = '<input type="checkbox" value="1" checked disabled>';
5133
+		if ($case == 3) $result = '<input type="checkbox" value="1" checked disabled> '.$result;
5134 5134
 
5135
-		$classname='ok';
5135
+		$classname = 'ok';
5136 5136
 	}
5137 5137
 	elseif ($yesno == 0 || strtolower($yesno) == 'no' || strtolower($yesno) == 'false')
5138 5138
 	{
5139
-		$result=$langs->trans("no");
5140
-		if ($case == 1 || $case == 3) $result=$langs->trans("No");
5141
-		if ($case == 2) $result='<input type="checkbox" value="0" disabled>';
5142
-		if ($case == 3) $result='<input type="checkbox" value="0" disabled> '.$result;
5139
+		$result = $langs->trans("no");
5140
+		if ($case == 1 || $case == 3) $result = $langs->trans("No");
5141
+		if ($case == 2) $result = '<input type="checkbox" value="0" disabled>';
5142
+		if ($case == 3) $result = '<input type="checkbox" value="0" disabled> '.$result;
5143 5143
 
5144
-		if ($color == 2) $classname='ok';
5145
-		else $classname='error';
5144
+		if ($color == 2) $classname = 'ok';
5145
+		else $classname = 'error';
5146 5146
 	}
5147 5147
 	if ($color) return '<font class="'.$classname.'">'.$result.'</font>';
5148 5148
 	return $result;
@@ -5170,30 +5170,30 @@  discard block
 block discarded – undo
5170 5170
 
5171 5171
 	$path = '';
5172 5172
 
5173
-	$arrayforoldpath=array('cheque','user','category','holiday','supplier_invoice','invoice_supplier','mailing','supplier_payment');
5174
-	if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) $arrayforoldpath[]='product';
5175
-	if (! empty($level) && in_array($modulepart, $arrayforoldpath))
5173
+	$arrayforoldpath = array('cheque', 'user', 'category', 'holiday', 'supplier_invoice', 'invoice_supplier', 'mailing', 'supplier_payment');
5174
+	if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) $arrayforoldpath[] = 'product';
5175
+	if (!empty($level) && in_array($modulepart, $arrayforoldpath))
5176 5176
 	{
5177 5177
 		// This part should be removed once all code is using "get_exdir" to forge path, with all parameters provided.
5178
-		if (empty($alpha)) $num = preg_replace('/([^0-9])/i','',$num);
5179
-		else $num = preg_replace('/^.*\-/i','',$num);
5178
+		if (empty($alpha)) $num = preg_replace('/([^0-9])/i', '', $num);
5179
+		else $num = preg_replace('/^.*\-/i', '', $num);
5180 5180
 		$num = substr("000".$num, -$level);
5181
-		if ($level == 1) $path = substr($num,0,1);
5182
-		if ($level == 2) $path = substr($num,1,1).'/'.substr($num,0,1);
5183
-		if ($level == 3) $path = substr($num,2,1).'/'.substr($num,1,1).'/'.substr($num,0,1);
5181
+		if ($level == 1) $path = substr($num, 0, 1);
5182
+		if ($level == 2) $path = substr($num, 1, 1).'/'.substr($num, 0, 1);
5183
+		if ($level == 3) $path = substr($num, 2, 1).'/'.substr($num, 1, 1).'/'.substr($num, 0, 1);
5184 5184
 	}
5185 5185
 	else
5186 5186
 	{
5187 5187
 		// TODO
5188 5188
 		// We will enhance here a common way of forging path for document storage
5189 5189
 		// Here, object->id, object->ref and modulepart are required.
5190
-		if (in_array($modulepart, array('thirdparty','contact','member','propal','proposal','commande','order','facture','invoice','shipment')))
5190
+		if (in_array($modulepart, array('thirdparty', 'contact', 'member', 'propal', 'proposal', 'commande', 'order', 'facture', 'invoice', 'shipment')))
5191 5191
 		{
5192
-			$path=($object->ref?$object->ref:$object->id);
5192
+			$path = ($object->ref ? $object->ref : $object->id);
5193 5193
 		}
5194 5194
 	}
5195 5195
 
5196
-	if (empty($withoutslash) && ! empty($path)) $path.='/';
5196
+	if (empty($withoutslash) && !empty($path)) $path .= '/';
5197 5197
 
5198 5198
 	return $path;
5199 5199
 }
@@ -5206,64 +5206,64 @@  discard block
 block discarded – undo
5206 5206
  *  @param	int		$newmask	Mask for new file (Defaults to $conf->global->MAIN_UMASK or 0755 if unavailable). Example: '0444'
5207 5207
  *	@return int         		< 0 if KO, 0 = already exists, > 0 if OK
5208 5208
  */
5209
-function dol_mkdir($dir, $dataroot='', $newmask=null)
5209
+function dol_mkdir($dir, $dataroot = '', $newmask = null)
5210 5210
 {
5211 5211
 	global $conf;
5212 5212
 
5213
-	dol_syslog("functions.lib::dol_mkdir: dir=".$dir,LOG_INFO);
5213
+	dol_syslog("functions.lib::dol_mkdir: dir=".$dir, LOG_INFO);
5214 5214
 
5215
-	$dir_osencoded=dol_osencode($dir);
5215
+	$dir_osencoded = dol_osencode($dir);
5216 5216
 	if (@is_dir($dir_osencoded)) return 0;
5217 5217
 
5218
-	$nberr=0;
5219
-	$nbcreated=0;
5218
+	$nberr = 0;
5219
+	$nbcreated = 0;
5220 5220
 
5221
-	$ccdir='';
5222
-	if (! empty($dataroot)) {
5221
+	$ccdir = '';
5222
+	if (!empty($dataroot)) {
5223 5223
 		// Remove data root from loop
5224 5224
 		$dir = str_replace($dataroot.'/', '', $dir);
5225 5225
 		$ccdir = $dataroot.'/';
5226 5226
 	}
5227 5227
 
5228 5228
 	$cdir = explode("/", $dir);
5229
-	$num=count($cdir);
5229
+	$num = count($cdir);
5230 5230
 	for ($i = 0; $i < $num; $i++)
5231 5231
 	{
5232 5232
 		if ($i > 0) $ccdir .= '/'.$cdir[$i];
5233 5233
 		else $ccdir .= $cdir[$i];
5234
-		if (preg_match("/^.:$/",$ccdir,$regs)) continue;	// Si chemin Windows incomplet, on poursuit par rep suivant
5234
+		if (preg_match("/^.:$/", $ccdir, $regs)) continue; // Si chemin Windows incomplet, on poursuit par rep suivant
5235 5235
 
5236 5236
 		// Attention, le is_dir() peut echouer bien que le rep existe.
5237 5237
 		// (ex selon config de open_basedir)
5238 5238
 		if ($ccdir)
5239 5239
 		{
5240
-			$ccdir_osencoded=dol_osencode($ccdir);
5241
-			if (! @is_dir($ccdir_osencoded))
5240
+			$ccdir_osencoded = dol_osencode($ccdir);
5241
+			if (!@is_dir($ccdir_osencoded))
5242 5242
 			{
5243
-				dol_syslog("functions.lib::dol_mkdir: Directory '".$ccdir."' does not exists or is outside open_basedir PHP setting.",LOG_DEBUG);
5243
+				dol_syslog("functions.lib::dol_mkdir: Directory '".$ccdir."' does not exists or is outside open_basedir PHP setting.", LOG_DEBUG);
5244 5244
 
5245 5245
 				umask(0);
5246
-				$dirmaskdec=octdec($newmask);
5246
+				$dirmaskdec = octdec($newmask);
5247 5247
 				if (empty($newmask)) {
5248
-					$dirmaskdec = empty( $conf->global->MAIN_UMASK ) ? octdec( '0755' ) : octdec( $conf->global->MAIN_UMASK );
5248
+					$dirmaskdec = empty($conf->global->MAIN_UMASK) ? octdec('0755') : octdec($conf->global->MAIN_UMASK);
5249 5249
 				}
5250
-				$dirmaskdec |= octdec('0111');  // Set x bit required for directories
5251
-				if (! @mkdir($ccdir_osencoded, $dirmaskdec))
5250
+				$dirmaskdec |= octdec('0111'); // Set x bit required for directories
5251
+				if (!@mkdir($ccdir_osencoded, $dirmaskdec))
5252 5252
 				{
5253 5253
 					// Si le is_dir a renvoye une fausse info, alors on passe ici.
5254
-					dol_syslog("functions.lib::dol_mkdir: Fails to create directory '".$ccdir."' or directory already exists.",LOG_WARNING);
5254
+					dol_syslog("functions.lib::dol_mkdir: Fails to create directory '".$ccdir."' or directory already exists.", LOG_WARNING);
5255 5255
 					$nberr++;
5256 5256
 				}
5257 5257
 				else
5258 5258
 				{
5259
-					dol_syslog("functions.lib::dol_mkdir: Directory '".$ccdir."' created",LOG_DEBUG);
5260
-					$nberr=0;	// On remet a zero car si on arrive ici, cela veut dire que les echecs precedents peuvent etre ignore
5259
+					dol_syslog("functions.lib::dol_mkdir: Directory '".$ccdir."' created", LOG_DEBUG);
5260
+					$nberr = 0; // On remet a zero car si on arrive ici, cela veut dire que les echecs precedents peuvent etre ignore
5261 5261
 					$nbcreated++;
5262 5262
 				}
5263 5263
 			}
5264 5264
 			else
5265 5265
 			{
5266
-				$nberr=0;	// On remet a zero car si on arrive ici, cela veut dire que les echecs precedents peuvent etre ignores
5266
+				$nberr = 0; // On remet a zero car si on arrive ici, cela veut dire que les echecs precedents peuvent etre ignores
5267 5267
 			}
5268 5268
 		}
5269 5269
 	}
@@ -5296,26 +5296,26 @@  discard block
 block discarded – undo
5296 5296
  *
5297 5297
  * 	@see	dol_escape_htmltag strip_tags
5298 5298
  */
5299
-function dol_string_nohtmltag($stringtoclean,$removelinefeed=1,$pagecodeto='UTF-8')
5299
+function dol_string_nohtmltag($stringtoclean, $removelinefeed = 1, $pagecodeto = 'UTF-8')
5300 5300
 {
5301 5301
 	// TODO Try to replace with  strip_tags($stringtoclean)
5302 5302
 	$pattern = "/<[^<>]+>/";
5303 5303
 	$stringtoclean = preg_replace('/<br[^>]*>/', "\n", $stringtoclean);
5304
-	$temp = dol_html_entity_decode($stringtoclean,ENT_COMPAT,$pagecodeto);
5304
+	$temp = dol_html_entity_decode($stringtoclean, ENT_COMPAT, $pagecodeto);
5305 5305
 
5306 5306
 	// Exemple of $temp: <a href="/myurl" title="<u>A title</u>">0000-021</a>
5307
-	$temp = preg_replace($pattern,"",$temp);    // pass 1
5307
+	$temp = preg_replace($pattern, "", $temp); // pass 1
5308 5308
 	// $temp after pass 1: <a href="/myurl" title="A title">0000-021
5309
-	$temp = preg_replace($pattern,"",$temp);    // pass 2
5309
+	$temp = preg_replace($pattern, "", $temp); // pass 2
5310 5310
 	// $temp after pass 2: 0000-021
5311 5311
 
5312 5312
 	// Supprime aussi les retours
5313
-	if ($removelinefeed) $temp=str_replace(array("\r\n","\r","\n")," ",$temp);
5313
+	if ($removelinefeed) $temp = str_replace(array("\r\n", "\r", "\n"), " ", $temp);
5314 5314
 
5315 5315
 	// et les espaces doubles
5316
-	while(strpos($temp,"  "))
5316
+	while (strpos($temp, "  "))
5317 5317
 	{
5318
-		$temp = str_replace("  "," ",$temp);
5318
+		$temp = str_replace("  ", " ", $temp);
5319 5319
 	}
5320 5320
 
5321 5321
 	return trim($temp);
@@ -5330,29 +5330,29 @@  discard block
 block discarded – undo
5330 5330
  * @return	string				Output text
5331 5331
  * @see dol_nboflines_bis, dol_string_nohtmltag, dol_escape_htmltag
5332 5332
  */
5333
-function dolGetFirstLineOfText($text, $nboflines=1)
5333
+function dolGetFirstLineOfText($text, $nboflines = 1)
5334 5334
 {
5335 5335
 	if ($nboflines == 1)
5336 5336
 	{
5337 5337
 		if (dol_textishtml($text))
5338 5338
 		{
5339
-			$firstline=preg_replace('/<br[^>]*>.*$/s','',$text);		// The s pattern modifier means the . can match newline characters
5340
-			$firstline=preg_replace('/<div[^>]*>.*$/s','',$firstline);	// The s pattern modifier means the . can match newline characters
5339
+			$firstline = preg_replace('/<br[^>]*>.*$/s', '', $text); // The s pattern modifier means the . can match newline characters
5340
+			$firstline = preg_replace('/<div[^>]*>.*$/s', '', $firstline); // The s pattern modifier means the . can match newline characters
5341 5341
 
5342 5342
 		}
5343 5343
 		else
5344 5344
 		{
5345
-			$firstline=preg_replace('/[\n\r].*/','',$text);
5345
+			$firstline = preg_replace('/[\n\r].*/', '', $text);
5346 5346
 		}
5347
-		return $firstline.((strlen($firstline) != strlen($text))?'...':'');
5347
+		return $firstline.((strlen($firstline) != strlen($text)) ? '...' : '');
5348 5348
 	}
5349 5349
 	else
5350 5350
 	{
5351
-		$ishtml=0;
5351
+		$ishtml = 0;
5352 5352
 		if (dol_textishtml($text))
5353 5353
 		{
5354
-			$text=preg_replace('/\n/','',$text);
5355
-			$ishtml=1;
5354
+			$text = preg_replace('/\n/', '', $text);
5355
+			$ishtml = 1;
5356 5356
 			$repTable = array("\t" => " ", "\n" => " ", "\r" => " ", "\0" => " ", "\x0B" => " ");
5357 5357
 		}
5358 5358
 		else
@@ -5362,20 +5362,20 @@  discard block
 block discarded – undo
5362 5362
 
5363 5363
 		$text = strtr($text, $repTable);
5364 5364
 		if ($charset == 'UTF-8') { $pattern = '/(<br[^>]*>)/Uu'; }	// /U is to have UNGREEDY regex to limit to one html tag. /u is for UTF8 support
5365
-		else $pattern = '/(<br[^>]*>)/U';							// /U is to have UNGREEDY regex to limit to one html tag.
5365
+		else $pattern = '/(<br[^>]*>)/U'; // /U is to have UNGREEDY regex to limit to one html tag.
5366 5366
 		$a = preg_split($pattern, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
5367 5367
 
5368
-		$firstline='';
5369
-		$i=0;
5370
-		$nba = count($a);	// 2x nb of lines in $a because $a contains also a line for each new line separator
5368
+		$firstline = '';
5369
+		$i = 0;
5370
+		$nba = count($a); // 2x nb of lines in $a because $a contains also a line for each new line separator
5371 5371
 		while (($i < $nba) && ($i < ($nboflines * 2)))
5372 5372
 		{
5373 5373
 			if ($i % 2 == 0) $firstline .= $a[$i];
5374
-			elseif (($i < (($nboflines * 2) - 1)) && ($i < ($nba - 1))) $firstline .= ($ishtml?"<br>\n":"\n");
5374
+			elseif (($i < (($nboflines * 2) - 1)) && ($i < ($nba - 1))) $firstline .= ($ishtml ? "<br>\n" : "\n");
5375 5375
 			$i++;
5376 5376
 		}
5377 5377
 		unset($a);
5378
-		return $firstline.(($i < $nba)?'...':'');
5378
+		return $firstline.(($i < $nba) ? '...' : '');
5379 5379
 	}
5380 5380
 }
5381 5381
 
@@ -5389,12 +5389,12 @@  discard block
 block discarded – undo
5389 5389
  * @return	string						String encoded
5390 5390
  * @see dol_nboflines, dolGetFirstLineOfText
5391 5391
  */
5392
-function dol_nl2br($stringtoencode,$nl2brmode=0,$forxml=false)
5392
+function dol_nl2br($stringtoencode, $nl2brmode = 0, $forxml = false)
5393 5393
 {
5394 5394
 	if (!$nl2brmode) {
5395 5395
 		return nl2br($stringtoencode, $forxml);
5396 5396
 	} else {
5397
-		$ret=preg_replace('/(\r\n|\r|\n)/i', ($forxml?'<br />':'<br>'), $stringtoencode);
5397
+		$ret = preg_replace('/(\r\n|\r|\n)/i', ($forxml ? '<br />' : '<br>'), $stringtoencode);
5398 5398
 		return $ret;
5399 5399
 	}
5400 5400
 }
@@ -5417,21 +5417,21 @@  discard block
 block discarded – undo
5417 5417
  *  @param	int		$removelasteolbr	1=Remove last br or lasts \n (default), 0=Do nothing
5418 5418
  *  @return	string						String encoded
5419 5419
  */
5420
-function dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
5420
+function dol_htmlentitiesbr($stringtoencode, $nl2brmode = 0, $pagecodefrom = 'UTF-8', $removelasteolbr = 1)
5421 5421
 {
5422
-	$newstring=$stringtoencode;
5422
+	$newstring = $stringtoencode;
5423 5423
 	if (dol_textishtml($stringtoencode))	// Check if text is already HTML or not
5424 5424
 	{
5425
-		$newstring=preg_replace('/<br(\s[\sa-zA-Z_="]*)?\/?>/i','<br>',$newstring);	// Replace "<br type="_moz" />" by "<br>". It's same and avoid pb with FPDF.
5426
-		if ($removelasteolbr) $newstring=preg_replace('/<br>$/i','',$newstring);	// Remove last <br> (remove only last one)
5427
-		$newstring=strtr($newstring,array('&'=>'__and__','<'=>'__lt__','>'=>'__gt__','"'=>'__dquot__'));
5428
-		$newstring=dol_htmlentities($newstring,ENT_COMPAT,$pagecodefrom);	// Make entity encoding
5429
-		$newstring=strtr($newstring,array('__and__'=>'&','__lt__'=>'<','__gt__'=>'>','__dquot__'=>'"'));
5425
+		$newstring = preg_replace('/<br(\s[\sa-zA-Z_="]*)?\/?>/i', '<br>', $newstring); // Replace "<br type="_moz" />" by "<br>". It's same and avoid pb with FPDF.
5426
+		if ($removelasteolbr) $newstring = preg_replace('/<br>$/i', '', $newstring); // Remove last <br> (remove only last one)
5427
+		$newstring = strtr($newstring, array('&'=>'__and__', '<'=>'__lt__', '>'=>'__gt__', '"'=>'__dquot__'));
5428
+		$newstring = dol_htmlentities($newstring, ENT_COMPAT, $pagecodefrom); // Make entity encoding
5429
+		$newstring = strtr($newstring, array('__and__'=>'&', '__lt__'=>'<', '__gt__'=>'>', '__dquot__'=>'"'));
5430 5430
 	}
5431 5431
 	else
5432 5432
 	{
5433
-		if ($removelasteolbr) $newstring=preg_replace('/(\r\n|\r|\n)$/i','',$newstring);	// Remove last \n (may remove several)
5434
-		$newstring=dol_nl2br(dol_htmlentities($newstring,ENT_COMPAT,$pagecodefrom),$nl2brmode);
5433
+		if ($removelasteolbr) $newstring = preg_replace('/(\r\n|\r|\n)$/i', '', $newstring); // Remove last \n (may remove several)
5434
+		$newstring = dol_nl2br(dol_htmlentities($newstring, ENT_COMPAT, $pagecodefrom), $nl2brmode);
5435 5435
 	}
5436 5436
 	// Other substitutions that htmlentities does not do
5437 5437
 	//$newstring=str_replace(chr(128),'&euro;',$newstring);	// 128 = 0x80. Not in html entity table.     // Seems useles with TCPDF. Make bug with UTF8 languages
@@ -5445,13 +5445,13 @@  discard block
 block discarded – undo
5445 5445
  *	@param	string	$pagecodeto			Page code for result
5446 5446
  *	@return	string						String decoded
5447 5447
  */
5448
-function dol_htmlentitiesbr_decode($stringtodecode,$pagecodeto='UTF-8')
5448
+function dol_htmlentitiesbr_decode($stringtodecode, $pagecodeto = 'UTF-8')
5449 5449
 {
5450
-	$ret=dol_html_entity_decode($stringtodecode,ENT_COMPAT,$pagecodeto);
5451
-	$ret=preg_replace('/'."\r\n".'<br(\s[\sa-zA-Z_="]*)?\/?>/i',"<br>",$ret);
5452
-	$ret=preg_replace('/<br(\s[\sa-zA-Z_="]*)?\/?>'."\r\n".'/i',"\r\n",$ret);
5453
-	$ret=preg_replace('/<br(\s[\sa-zA-Z_="]*)?\/?>'."\n".'/i',"\n",$ret);
5454
-	$ret=preg_replace('/<br(\s[\sa-zA-Z_="]*)?\/?>/i',"\n",$ret);
5450
+	$ret = dol_html_entity_decode($stringtodecode, ENT_COMPAT, $pagecodeto);
5451
+	$ret = preg_replace('/'."\r\n".'<br(\s[\sa-zA-Z_="]*)?\/?>/i', "<br>", $ret);
5452
+	$ret = preg_replace('/<br(\s[\sa-zA-Z_="]*)?\/?>'."\r\n".'/i', "\r\n", $ret);
5453
+	$ret = preg_replace('/<br(\s[\sa-zA-Z_="]*)?\/?>'."\n".'/i', "\n", $ret);
5454
+	$ret = preg_replace('/<br(\s[\sa-zA-Z_="]*)?\/?>/i', "\n", $ret);
5455 5455
 	return $ret;
5456 5456
 }
5457 5457
 
@@ -5463,7 +5463,7 @@  discard block
 block discarded – undo
5463 5463
  */
5464 5464
 function dol_htmlcleanlastbr($stringtodecode)
5465 5465
 {
5466
-	$ret=preg_replace('/(<br>|<br(\s[\sa-zA-Z_="]*)?\/?>|'."\n".'|'."\r".')+$/i',"",$stringtodecode);
5466
+	$ret = preg_replace('/(<br>|<br(\s[\sa-zA-Z_="]*)?\/?>|'."\n".'|'."\r".')+$/i', "", $stringtodecode);
5467 5467
 	return $ret;
5468 5468
 }
5469 5469
 
@@ -5475,9 +5475,9 @@  discard block
 block discarded – undo
5475 5475
  * @param   string	$c		Operand c
5476 5476
  * @return  string			String decoded
5477 5477
  */
5478
-function dol_html_entity_decode($a,$b,$c='UTF-8')
5478
+function dol_html_entity_decode($a, $b, $c = 'UTF-8')
5479 5479
 {
5480
-	return html_entity_decode($a,$b,$c);
5480
+	return html_entity_decode($a, $b, $c);
5481 5481
 }
5482 5482
 
5483 5483
 /**
@@ -5490,7 +5490,7 @@  discard block
 block discarded – undo
5490 5490
  * @param   bool    $double_encode  When double_encode is turned off, PHP will not encode existing html entities
5491 5491
  * @return  string  $ret            Encoded string
5492 5492
  */
5493
-function dol_htmlentities($string, $flags=null, $encoding='UTF-8', $double_encode=false)
5493
+function dol_htmlentities($string, $flags = null, $encoding = 'UTF-8', $double_encode = false)
5494 5494
 {
5495 5495
 	return htmlentities($string, $flags, $encoding, $double_encode);
5496 5496
 }
@@ -5505,14 +5505,14 @@  discard block
 block discarded – undo
5505 5505
  */
5506 5506
 function dol_string_is_good_iso($s)
5507 5507
 {
5508
-	$len=dol_strlen($s);
5509
-	$ok=1;
5510
-	for($scursor=0;$scursor<$len;$scursor++)
5508
+	$len = dol_strlen($s);
5509
+	$ok = 1;
5510
+	for ($scursor = 0; $scursor < $len; $scursor++)
5511 5511
 	{
5512
-		$ordchar=ord($s{$scursor});
5512
+		$ordchar = ord($s{$scursor});
5513 5513
 		//print $scursor.'-'.$ordchar.'<br>';
5514
-		if ($ordchar < 32 && $ordchar != 13 && $ordchar != 10) { $ok=0; break; }
5515
-		if ($ordchar > 126 && $ordchar < 160) { $ok=0; break; }
5514
+		if ($ordchar < 32 && $ordchar != 13 && $ordchar != 10) { $ok = 0; break; }
5515
+		if ($ordchar > 126 && $ordchar < 160) { $ok = 0; break; }
5516 5516
 	}
5517 5517
 	return $ok;
5518 5518
 }
@@ -5526,11 +5526,11 @@  discard block
 block discarded – undo
5526 5526
  *	@return	int					Number of lines
5527 5527
  *  @see	dol_nboflines_bis, dolGetFirstLineOfText
5528 5528
  */
5529
-function dol_nboflines($s,$maxchar=0)
5529
+function dol_nboflines($s, $maxchar = 0)
5530 5530
 {
5531 5531
 	if ($s == '') return 0;
5532
-	$arraystring=explode("\n",$s);
5533
-	$nb=count($arraystring);
5532
+	$arraystring = explode("\n", $s);
5533
+	$nb = count($arraystring);
5534 5534
 
5535 5535
 	return $nb;
5536 5536
 }
@@ -5545,30 +5545,30 @@  discard block
 block discarded – undo
5545 5545
  *	@return int						Number of lines
5546 5546
  *	@see	dol_nboflines, dolGetFirstLineOfText
5547 5547
  */
5548
-function dol_nboflines_bis($text,$maxlinesize=0,$charset='UTF-8')
5548
+function dol_nboflines_bis($text, $maxlinesize = 0, $charset = 'UTF-8')
5549 5549
 {
5550 5550
 	$repTable = array("\t" => " ", "\n" => "<br>", "\r" => " ", "\0" => " ", "\x0B" => " ");
5551 5551
 	if (dol_textishtml($text)) $repTable = array("\t" => " ", "\n" => " ", "\r" => " ", "\0" => " ", "\x0B" => " ");
5552 5552
 
5553 5553
 	$text = strtr($text, $repTable);
5554 5554
 	if ($charset == 'UTF-8') { $pattern = '/(<br[^>]*>)/Uu'; }	// /U is to have UNGREEDY regex to limit to one html tag. /u is for UTF8 support
5555
-	else $pattern = '/(<br[^>]*>)/U';							// /U is to have UNGREEDY regex to limit to one html tag.
5555
+	else $pattern = '/(<br[^>]*>)/U'; // /U is to have UNGREEDY regex to limit to one html tag.
5556 5556
 	$a = preg_split($pattern, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
5557 5557
 
5558
-	$nblines = (int) floor((count($a)+1)/2);
5558
+	$nblines = (int) floor((count($a) + 1) / 2);
5559 5559
 	// count possible auto line breaks
5560
-	if($maxlinesize)
5560
+	if ($maxlinesize)
5561 5561
 	{
5562 5562
 		foreach ($a as $line)
5563 5563
 		{
5564
-			if (dol_strlen($line)>$maxlinesize)
5564
+			if (dol_strlen($line) > $maxlinesize)
5565 5565
 			{
5566 5566
 				//$line_dec = html_entity_decode(strip_tags($line));
5567 5567
 				$line_dec = html_entity_decode($line);
5568
-				if(dol_strlen($line_dec)>$maxlinesize)
5568
+				if (dol_strlen($line_dec) > $maxlinesize)
5569 5569
 				{
5570
-					$line_dec=wordwrap($line_dec,$maxlinesize,'\n',true);
5571
-					$nblines+=substr_count($line_dec,'\n');
5570
+					$line_dec = wordwrap($line_dec, $maxlinesize, '\n', true);
5571
+					$nblines += substr_count($line_dec, '\n');
5572 5572
 				}
5573 5573
 			}
5574 5574
 		}
@@ -5587,7 +5587,7 @@  discard block
 block discarded – undo
5587 5587
  */
5588 5588
 function dol_microtime_float()
5589 5589
 {
5590
-	dol_syslog(__FUNCTION__ . " is deprecated", LOG_WARNING);
5590
+	dol_syslog(__FUNCTION__." is deprecated", LOG_WARNING);
5591 5591
 
5592 5592
 	return microtime(true);
5593 5593
 }
@@ -5600,28 +5600,28 @@  discard block
 block discarded – undo
5600 5600
  *	@return	boolean				true/false
5601 5601
  *	@see	dol_concatdesc
5602 5602
  */
5603
-function dol_textishtml($msg,$option=0)
5603
+function dol_textishtml($msg, $option = 0)
5604 5604
 {
5605 5605
 	if ($option == 1)
5606 5606
 	{
5607
-		if (preg_match('/<html/i',$msg))				return true;
5608
-		elseif (preg_match('/<body/i',$msg))			return true;
5609
-		elseif (preg_match('/<br/i',$msg))				return true;
5607
+		if (preg_match('/<html/i', $msg))				return true;
5608
+		elseif (preg_match('/<body/i', $msg))			return true;
5609
+		elseif (preg_match('/<br/i', $msg))				return true;
5610 5610
 		return false;
5611 5611
 	}
5612 5612
 	else
5613 5613
 	{
5614
-		if (preg_match('/<html/i',$msg))				return true;
5615
-		elseif (preg_match('/<body/i',$msg))			return true;
5616
-		elseif (preg_match('/<(b|em|i|u)>/i',$msg))		return true;
5617
-		elseif (preg_match('/<(br|div|font|li|p|span|strong|table)>/i',$msg)) 	  return true;
5618
-		elseif (preg_match('/<(br|div|font|li|p|span|strong|table)\s+[^<>\/]*>/i',$msg)) return true;
5619
-		elseif (preg_match('/<(br|div|font|li|p|span|strong|table)\s+[^<>\/]*\/>/i',$msg)) return true;
5620
-		elseif (preg_match('/<img\s+[^<>]*src[^<>]*>/i',$msg)) return true;	// must accept <img src="http://example.com/aaa.png" />
5621
-		elseif (preg_match('/<a\s+[^<>]*href[^<>]*>/i',$msg)) return true;	// must accept <a href="http://example.com/aaa.png" />
5622
-		elseif (preg_match('/<h[0-9]>/i',$msg))			return true;
5623
-		elseif (preg_match('/&[A-Z0-9]{1,6};/i',$msg))	return true;    // Html entities names (http://www.w3schools.com/tags/ref_entities.asp)
5624
-		elseif (preg_match('/&#[0-9]{2,3};/i',$msg))	return true;    // Html entities numbers (http://www.w3schools.com/tags/ref_entities.asp)
5614
+		if (preg_match('/<html/i', $msg))				return true;
5615
+		elseif (preg_match('/<body/i', $msg))			return true;
5616
+		elseif (preg_match('/<(b|em|i|u)>/i', $msg))		return true;
5617
+		elseif (preg_match('/<(br|div|font|li|p|span|strong|table)>/i', $msg)) 	  return true;
5618
+		elseif (preg_match('/<(br|div|font|li|p|span|strong|table)\s+[^<>\/]*>/i', $msg)) return true;
5619
+		elseif (preg_match('/<(br|div|font|li|p|span|strong|table)\s+[^<>\/]*\/>/i', $msg)) return true;
5620
+		elseif (preg_match('/<img\s+[^<>]*src[^<>]*>/i', $msg)) return true; // must accept <img src="http://example.com/aaa.png" />
5621
+		elseif (preg_match('/<a\s+[^<>]*href[^<>]*>/i', $msg)) return true; // must accept <a href="http://example.com/aaa.png" />
5622
+		elseif (preg_match('/<h[0-9]>/i', $msg))			return true;
5623
+		elseif (preg_match('/&[A-Z0-9]{1,6};/i', $msg))	return true; // Html entities names (http://www.w3schools.com/tags/ref_entities.asp)
5624
+		elseif (preg_match('/&#[0-9]{2,3};/i', $msg))	return true; // Html entities numbers (http://www.w3schools.com/tags/ref_entities.asp)
5625 5625
 		return false;
5626 5626
 	}
5627 5627
 }
@@ -5639,12 +5639,12 @@  discard block
 block discarded – undo
5639 5639
  *  @return	string				Text 1 + new line + Text2
5640 5640
  *  @see    dol_textishtml
5641 5641
  */
5642
-function dol_concatdesc($text1,$text2,$forxml=false)
5642
+function dol_concatdesc($text1, $text2, $forxml = false)
5643 5643
 {
5644
-	$ret='';
5645
-	$ret.= (! dol_textishtml($text1) && dol_textishtml($text2))?dol_nl2br($text1, 0, $forxml):$text1;
5646
-	$ret.= (! empty($text1) && ! empty($text2)) ? ((dol_textishtml($text1) || dol_textishtml($text2))?($forxml?"<br \>\n":"<br>\n") : "\n") : "";
5647
-	$ret.= (dol_textishtml($text1) && ! dol_textishtml($text2))?dol_nl2br($text2, 0, $forxml):$text2;
5644
+	$ret = '';
5645
+	$ret .= (!dol_textishtml($text1) && dol_textishtml($text2)) ?dol_nl2br($text1, 0, $forxml) : $text1;
5646
+	$ret .= (!empty($text1) && !empty($text2)) ? ((dol_textishtml($text1) || dol_textishtml($text2)) ? ($forxml ? "<br \>\n" : "<br>\n") : "\n") : "";
5647
+	$ret .= (dol_textishtml($text1) && !dol_textishtml($text2)) ?dol_nl2br($text2, 0, $forxml) : $text2;
5648 5648
 	return $ret;
5649 5649
 }
5650 5650
 
@@ -5659,21 +5659,21 @@  discard block
 block discarded – undo
5659 5659
  * @return	array						Array of substitutions
5660 5660
  * @see setSubstitFromObject
5661 5661
  */
5662
-function getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null)
5662
+function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude = null, $object = null)
5663 5663
 {
5664 5664
 	global $db, $conf, $mysoc, $user;
5665 5665
 
5666
-	$substitutionarray=array();
5666
+	$substitutionarray = array();
5667 5667
 
5668
-	if (empty($exclude) || ! in_array('system', $exclude))
5668
+	if (empty($exclude) || !in_array('system', $exclude))
5669 5669
 	{
5670
-		$substitutionarray['__(AnyTranslationKey)__']=$outputlangs->trans('TranslationOfKey');
5671
-		$substitutionarray['__[AnyConstantKey]__']=$outputlangs->trans('ValueOfConstant');
5672
-		$substitutionarray['__DOL_MAIN_URL_ROOT__']=DOL_MAIN_URL_ROOT;
5670
+		$substitutionarray['__(AnyTranslationKey)__'] = $outputlangs->trans('TranslationOfKey');
5671
+		$substitutionarray['__[AnyConstantKey]__'] = $outputlangs->trans('ValueOfConstant');
5672
+		$substitutionarray['__DOL_MAIN_URL_ROOT__'] = DOL_MAIN_URL_ROOT;
5673 5673
 	}
5674
-	if ((empty($exclude) || ! in_array('mycompany', $exclude)) && is_object($mysoc))
5674
+	if ((empty($exclude) || !in_array('mycompany', $exclude)) && is_object($mysoc))
5675 5675
 	{
5676
-		$substitutionarray=array_merge($substitutionarray, array(
5676
+		$substitutionarray = array_merge($substitutionarray, array(
5677 5677
 			'__MYCOMPANY_NAME__'    => $mysoc->name,
5678 5678
 			'__MYCOMPANY_EMAIL__'   => $mysoc->email,
5679 5679
 			'__MYCOMPANY_PROFID1__' => $mysoc->idprof1,
@@ -5691,7 +5691,7 @@  discard block
 block discarded – undo
5691 5691
 			'__MYCOMPANY_COUNTRY_ID__' => $mysoc->country_id
5692 5692
 		));
5693 5693
 	}
5694
-	if (($onlykey || is_object($object)) && (empty($exclude) || ! in_array('object', $exclude)))
5694
+	if (($onlykey || is_object($object)) && (empty($exclude) || !in_array('object', $exclude)))
5695 5695
 	{
5696 5696
 		if ($onlykey)
5697 5697
 		{
@@ -5729,8 +5729,8 @@  discard block
 block discarded – undo
5729 5729
 
5730 5730
 			if (is_object($object) && $object->element == 'shipping')
5731 5731
 			{
5732
-				$substitutionarray['__SHIPPINGTRACKNUM__']='Shipping tacking number';
5733
-				$substitutionarray['__SHIPPINGTRACKNUMURL__']='Shipping tracking url';
5732
+				$substitutionarray['__SHIPPINGTRACKNUM__'] = 'Shipping tacking number';
5733
+				$substitutionarray['__SHIPPINGTRACKNUMURL__'] = 'Shipping tracking url';
5734 5734
 			}
5735 5735
 		}
5736 5736
 		else
@@ -5743,62 +5743,62 @@  discard block
 block discarded – undo
5743 5743
 			// TODO USe this ?
5744 5744
 			$msgishtml = 0;
5745 5745
 
5746
-			$birthday = dol_print_date($object->birth,'day');
5746
+			$birthday = dol_print_date($object->birth, 'day');
5747 5747
 
5748 5748
 			if (method_exists($object, 'getCivilityLabel')) $substitutionarray['__MEMBER_CIVILITY__'] = $object->getCivilityLabel();
5749
-			$substitutionarray['__MEMBER_FIRSTNAME__']=$msgishtml?dol_htmlentitiesbr($object->firstname):$object->firstname;
5750
-			$substitutionarray['__MEMBER_LASTNAME__']=$msgishtml?dol_htmlentitiesbr($object->lastname):$object->lastname;
5751
-			if (method_exists($object, 'getFullName')) $substitutionarray['__MEMBER_FULLNAME__']=$msgishtml?dol_htmlentitiesbr($object->getFullName($outputlangs)):$object->getFullName($outputlangs);
5752
-			$substitutionarray['__MEMBER_COMPANY__']=$msgishtml?dol_htmlentitiesbr($object->societe):$object->societe;
5753
-			$substitutionarray['__MEMBER_ADDRESS__']=$msgishtml?dol_htmlentitiesbr($object->address):$object->address;
5754
-			$substitutionarray['__MEMBER_ZIP__']=$msgishtml?dol_htmlentitiesbr($object->zip):$object->zip;
5755
-			$substitutionarray['__MEMBER_TOWN__']=$msgishtml?dol_htmlentitiesbr($object->town):$object->town;
5756
-			$substitutionarray['__MEMBER_COUNTRY__']=$msgishtml?dol_htmlentitiesbr($object->country):$object->country;
5757
-			$substitutionarray['__MEMBER_EMAIL__']=$msgishtml?dol_htmlentitiesbr($object->email):$object->email;
5758
-			$substitutionarray['__MEMBER_BIRTH__']=$msgishtml?dol_htmlentitiesbr($birthday):$birthday;
5759
-			$substitutionarray['__MEMBER_PHOTO__']=$msgishtml?dol_htmlentitiesbr($object->photo):$object->photo;
5760
-			$substitutionarray['__MEMBER_LOGIN__']=$msgishtml?dol_htmlentitiesbr($object->login):$object->login;
5761
-			$substitutionarray['__MEMBER_PASSWORD__']=$msgishtml?dol_htmlentitiesbr($object->pass):$object->pass;
5762
-			$substitutionarray['__MEMBER_PHONE__']=$msgishtml?dol_htmlentitiesbr($object->phone):$object->phone;
5763
-			$substitutionarray['__MEMBER_PHONEPRO__']=$msgishtml?dol_htmlentitiesbr($object->phone_perso):$object->phone_perso;
5764
-			$substitutionarray['__MEMBER_PHONEMOBILE__']=$msgishtml?dol_htmlentitiesbr($object->phone_mobile):$object->phone_mobile;
5749
+			$substitutionarray['__MEMBER_FIRSTNAME__'] = $msgishtml ?dol_htmlentitiesbr($object->firstname) : $object->firstname;
5750
+			$substitutionarray['__MEMBER_LASTNAME__'] = $msgishtml ?dol_htmlentitiesbr($object->lastname) : $object->lastname;
5751
+			if (method_exists($object, 'getFullName')) $substitutionarray['__MEMBER_FULLNAME__'] = $msgishtml ?dol_htmlentitiesbr($object->getFullName($outputlangs)) : $object->getFullName($outputlangs);
5752
+			$substitutionarray['__MEMBER_COMPANY__'] = $msgishtml ?dol_htmlentitiesbr($object->societe) : $object->societe;
5753
+			$substitutionarray['__MEMBER_ADDRESS__'] = $msgishtml ?dol_htmlentitiesbr($object->address) : $object->address;
5754
+			$substitutionarray['__MEMBER_ZIP__'] = $msgishtml ?dol_htmlentitiesbr($object->zip) : $object->zip;
5755
+			$substitutionarray['__MEMBER_TOWN__'] = $msgishtml ?dol_htmlentitiesbr($object->town) : $object->town;
5756
+			$substitutionarray['__MEMBER_COUNTRY__'] = $msgishtml ?dol_htmlentitiesbr($object->country) : $object->country;
5757
+			$substitutionarray['__MEMBER_EMAIL__'] = $msgishtml ?dol_htmlentitiesbr($object->email) : $object->email;
5758
+			$substitutionarray['__MEMBER_BIRTH__'] = $msgishtml ?dol_htmlentitiesbr($birthday) : $birthday;
5759
+			$substitutionarray['__MEMBER_PHOTO__'] = $msgishtml ?dol_htmlentitiesbr($object->photo) : $object->photo;
5760
+			$substitutionarray['__MEMBER_LOGIN__'] = $msgishtml ?dol_htmlentitiesbr($object->login) : $object->login;
5761
+			$substitutionarray['__MEMBER_PASSWORD__'] = $msgishtml ?dol_htmlentitiesbr($object->pass) : $object->pass;
5762
+			$substitutionarray['__MEMBER_PHONE__'] = $msgishtml ?dol_htmlentitiesbr($object->phone) : $object->phone;
5763
+			$substitutionarray['__MEMBER_PHONEPRO__'] = $msgishtml ?dol_htmlentitiesbr($object->phone_perso) : $object->phone_perso;
5764
+			$substitutionarray['__MEMBER_PHONEMOBILE__'] = $msgishtml ?dol_htmlentitiesbr($object->phone_mobile) : $object->phone_mobile;
5765 5765
 
5766 5766
 			if (is_object($object) && $object->element == 'societe')
5767 5767
 			{
5768
-				$substitutionarray['__THIRDPARTY_ID__'] = (is_object($object)?$object->id:'');
5769
-				$substitutionarray['__THIRDPARTY_NAME__'] = (is_object($object)?$object->name:'');
5770
-				$substitutionarray['__THIRDPARTY_NAME_ALIAS__'] = (is_object($object)?$object->name_alias:'');
5771
-				$substitutionarray['__THIRDPARTY_EMAIL__'] = (is_object($object)?$object->email:'');
5768
+				$substitutionarray['__THIRDPARTY_ID__'] = (is_object($object) ? $object->id : '');
5769
+				$substitutionarray['__THIRDPARTY_NAME__'] = (is_object($object) ? $object->name : '');
5770
+				$substitutionarray['__THIRDPARTY_NAME_ALIAS__'] = (is_object($object) ? $object->name_alias : '');
5771
+				$substitutionarray['__THIRDPARTY_EMAIL__'] = (is_object($object) ? $object->email : '');
5772 5772
 			}
5773 5773
 			elseif (is_object($object->thirdparty) && $object->thirdparty->id > 0)
5774 5774
 			{
5775
-				$substitutionarray['__THIRDPARTY_ID__'] = (is_object($object->thirdparty)?$object->thirdparty->id:'');
5776
-				$substitutionarray['__THIRDPARTY_NAME__'] = (is_object($object->thirdparty)?$object->thirdparty->name:'');
5777
-				$substitutionarray['__THIRDPARTY_NAME_ALIAS__'] = (is_object($object->thirdparty)?$object->thirdparty->name_alias:'');
5778
-				$substitutionarray['__THIRDPARTY_EMAIL__'] = (is_object($object->thirdparty)?$object->thirdparty->email:'');
5775
+				$substitutionarray['__THIRDPARTY_ID__'] = (is_object($object->thirdparty) ? $object->thirdparty->id : '');
5776
+				$substitutionarray['__THIRDPARTY_NAME__'] = (is_object($object->thirdparty) ? $object->thirdparty->name : '');
5777
+				$substitutionarray['__THIRDPARTY_NAME_ALIAS__'] = (is_object($object->thirdparty) ? $object->thirdparty->name_alias : '');
5778
+				$substitutionarray['__THIRDPARTY_EMAIL__'] = (is_object($object->thirdparty) ? $object->thirdparty->email : '');
5779 5779
 			}
5780 5780
 
5781 5781
 			if (is_object($object->projet) && $object->projet->id > 0)
5782 5782
 			{
5783
-				$substitutionarray['__PROJECT_ID__'] = (is_object($object->projet)?$object->projet->id:'');
5784
-				$substitutionarray['__PROJECT_REF__'] = (is_object($object->projet)?$object->projet->ref:'');
5785
-				$substitutionarray['__PROJECT_NAME__'] = (is_object($object->projet)?$object->projet->title:'');
5783
+				$substitutionarray['__PROJECT_ID__'] = (is_object($object->projet) ? $object->projet->id : '');
5784
+				$substitutionarray['__PROJECT_REF__'] = (is_object($object->projet) ? $object->projet->ref : '');
5785
+				$substitutionarray['__PROJECT_NAME__'] = (is_object($object->projet) ? $object->projet->title : '');
5786 5786
 			}
5787 5787
 
5788 5788
 			if (is_object($object) && $object->element == 'shipping')
5789 5789
 			{
5790
-				$substitutionarray['__SHIPPINGTRACKNUM__']=$object->tracking_number;
5791
-				$substitutionarray['__SHIPPINGTRACKNUMURL__']=$object->tracking_url;
5790
+				$substitutionarray['__SHIPPINGTRACKNUM__'] = $object->tracking_number;
5791
+				$substitutionarray['__SHIPPINGTRACKNUMURL__'] = $object->tracking_url;
5792 5792
 			}
5793 5793
 
5794 5794
 			if (is_object($object) && $object->element == 'contrat' && is_array($object->lines))
5795 5795
 			{
5796
-				$dateplannedstart='';
5797
-				$datenextexpiration='';
5798
-				foreach($object->lines as $line)
5796
+				$dateplannedstart = '';
5797
+				$datenextexpiration = '';
5798
+				foreach ($object->lines as $line)
5799 5799
 				{
5800 5800
 					if ($line->date_ouverture_prevue > $dateplannedstart) $dateplannedstart = $line->date_ouverture_prevue;
5801
-					if ($line->statut == 4 && $line->date_fin_prevue && (! $datenextexpiration || $line->date_fin_prevue < $datenextexpiration)) $datenextexpiration = $line->date_fin_prevue;
5801
+					if ($line->statut == 4 && $line->date_fin_prevue && (!$datenextexpiration || $line->date_fin_prevue < $datenextexpiration)) $datenextexpiration = $line->date_fin_prevue;
5802 5802
 				}
5803 5803
 				$substitutionarray['__CONTRACT_HIGHEST_PLANNED_START_DATE__'] = dol_print_date($dateplannedstart, 'dayrfc');
5804 5804
 				$substitutionarray['__CONTRACT_HIGHEST_PLANNED_START_DATETIME__'] = dol_print_date($dateplannedstart, 'standard');
@@ -5813,22 +5813,22 @@  discard block
 block discarded – undo
5813 5813
 				$extralabels = $extrafieldstmp->fetch_name_optionals_label($object->table_element, true);
5814 5814
 				$object->fetch_optionals();
5815 5815
 				foreach ($extrafieldstmp->attribute_label as $key => $label) {
5816
-					$substitutionarray['__EXTRAFIELD_' . strtoupper($key) . '__'] = $object->array_options['options_' . $key];
5816
+					$substitutionarray['__EXTRAFIELD_'.strtoupper($key).'__'] = $object->array_options['options_'.$key];
5817 5817
 				}
5818 5818
 			}
5819 5819
 
5820 5820
 			$substitutionarray['__ONLINE_PAYMENT_URL__'] = 'TODO';
5821 5821
 		}
5822 5822
 	}
5823
-	if (empty($exclude) || ! in_array('objectamount', $exclude))
5823
+	if (empty($exclude) || !in_array('objectamount', $exclude))
5824 5824
 	{
5825
-		$substitutionarray['__DATE_YMD__']        = is_object($object)?(isset($object->date) ? dol_print_date($object->date, 'day', 0, $outputlangs) : '') : '';
5826
-		$substitutionarray['__DATE_DUE_YMD__']    = is_object($object)?(isset($object->date_lim_reglement)? dol_print_date($object->date_lim_reglement, 'day', 0, $outputlangs) : '') : '';
5827
-		$substitutionarray['__AMOUNT__']          = is_object($object)?$object->total_ttc:'';
5828
-		$substitutionarray['__AMOUNT_EXCL_TAX__'] = is_object($object)?$object->total_ht:'';
5829
-		$substitutionarray['__AMOUNT_VAT__']      = is_object($object)?($object->total_vat?$object->total_vat:$object->total_tva):'';
5830
- 		if ($onlykey != 2 || $mysoc->useLocalTax(1)) $substitutionarray['__AMOUNT_TAX2__']     = is_object($object)?($object->total_localtax1?$object->total_localtax1:$object->total_localtax1):'';
5831
-		if ($onlykey != 2 || $mysoc->useLocalTax(2)) $substitutionarray['__AMOUNT_TAX3__']     = is_object($object)?($object->total_localtax2?$object->total_localtax2:$object->total_localtax2):'';
5825
+		$substitutionarray['__DATE_YMD__']        = is_object($object) ? (isset($object->date) ? dol_print_date($object->date, 'day', 0, $outputlangs) : '') : '';
5826
+		$substitutionarray['__DATE_DUE_YMD__']    = is_object($object) ? (isset($object->date_lim_reglement) ? dol_print_date($object->date_lim_reglement, 'day', 0, $outputlangs) : '') : '';
5827
+		$substitutionarray['__AMOUNT__']          = is_object($object) ? $object->total_ttc : '';
5828
+		$substitutionarray['__AMOUNT_EXCL_TAX__'] = is_object($object) ? $object->total_ht : '';
5829
+		$substitutionarray['__AMOUNT_VAT__']      = is_object($object) ? ($object->total_vat ? $object->total_vat : $object->total_tva) : '';
5830
+ 		if ($onlykey != 2 || $mysoc->useLocalTax(1)) $substitutionarray['__AMOUNT_TAX2__'] = is_object($object) ? ($object->total_localtax1 ? $object->total_localtax1 : $object->total_localtax1) : '';
5831
+		if ($onlykey != 2 || $mysoc->useLocalTax(2)) $substitutionarray['__AMOUNT_TAX3__'] = is_object($object) ? ($object->total_localtax2 ? $object->total_localtax2 : $object->total_localtax2) : '';
5832 5832
 
5833 5833
 		/* TODO Add key for multicurrency
5834 5834
     	$substitutionarray['__AMOUNT_FORMATED__']          = is_object($object)?price($object->total_ttc, 0, $outputlangs, 0, 0, -1, $conf->currency_code):'';
@@ -5838,23 +5838,23 @@  discard block
 block discarded – undo
5838 5838
 		// For backward compatibility
5839 5839
 		if ($onlykey != 2)
5840 5840
 		{
5841
-			$substitutionarray['__TOTAL_TTC__']    = is_object($object)?$object->total_ttc:'';
5842
-			$substitutionarray['__TOTAL_HT__']     = is_object($object)?$object->total_ht:'';
5843
-			$substitutionarray['__TOTAL_VAT__']    = is_object($object)?($object->total_vat?$object->total_vat:$object->total_tva):'';
5841
+			$substitutionarray['__TOTAL_TTC__']    = is_object($object) ? $object->total_ttc : '';
5842
+			$substitutionarray['__TOTAL_HT__']     = is_object($object) ? $object->total_ht : '';
5843
+			$substitutionarray['__TOTAL_VAT__']    = is_object($object) ? ($object->total_vat ? $object->total_vat : $object->total_tva) : '';
5844 5844
 		}
5845 5845
 	}
5846 5846
 
5847
-	if (empty($exclude) || ! in_array('date', $exclude))
5847
+	if (empty($exclude) || !in_array('date', $exclude))
5848 5848
 	{
5849 5849
 		include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
5850 5850
 
5851
-		$tmp=dol_getdate(dol_now(), true);
5852
-		$tmp2=dol_get_prev_day($tmp['mday'], $tmp['mon'], $tmp['year']);
5853
-		$tmp3=dol_get_prev_month($tmp['mday'], $tmp['mon'], $tmp['year']);
5854
-		$tmp4=dol_get_next_day($tmp['mday'], $tmp['mon'], $tmp['year']);
5855
-		$tmp5=dol_get_next_month($tmp['mday'], $tmp['mon'], $tmp['year']);
5851
+		$tmp = dol_getdate(dol_now(), true);
5852
+		$tmp2 = dol_get_prev_day($tmp['mday'], $tmp['mon'], $tmp['year']);
5853
+		$tmp3 = dol_get_prev_month($tmp['mday'], $tmp['mon'], $tmp['year']);
5854
+		$tmp4 = dol_get_next_day($tmp['mday'], $tmp['mon'], $tmp['year']);
5855
+		$tmp5 = dol_get_next_month($tmp['mday'], $tmp['mon'], $tmp['year']);
5856 5856
 
5857
-		$substitutionarray=array_merge($substitutionarray, array(
5857
+		$substitutionarray = array_merge($substitutionarray, array(
5858 5858
 			'__DAY__' => (string) $tmp['mday'],
5859 5859
 			'__MONTH__' => (string) $tmp['mon'],
5860 5860
 			'__YEAR__' => (string) $tmp['year'],
@@ -5867,12 +5867,12 @@  discard block
 block discarded – undo
5867 5867
 		));
5868 5868
 	}
5869 5869
 
5870
-	if (empty($exclude) || ! in_array('user', $exclude))
5870
+	if (empty($exclude) || !in_array('user', $exclude))
5871 5871
 	{
5872 5872
 		// Add SIGNATURE into substitutionarray first, so, when we will make the substitution,
5873 5873
 		// this will also replace var found into content of signature
5874 5874
 		$signature = $user->signature;
5875
-		$substitutionarray=array_merge($substitutionarray, array(
5875
+		$substitutionarray = array_merge($substitutionarray, array(
5876 5876
 			'__USER_SIGNATURE__' => (string) (($signature && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? ($onlykey == 2 ? dol_trunc(dol_string_nohtmltag($signature), 30) : $signature) : '')
5877 5877
 		)
5878 5878
 			);
@@ -5882,7 +5882,7 @@  discard block
 block discarded – undo
5882 5882
 			$substitutionarray['__SIGNATURE__'] = (string) (($signature && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? ($onlykey == 2 ? dol_trunc(dol_string_nohtmltag($signature), 30) : $signature) : '');
5883 5883
 		}
5884 5884
 
5885
-		$substitutionarray=array_merge($substitutionarray, array(
5885
+		$substitutionarray = array_merge($substitutionarray, array(
5886 5886
 			'__USER_ID__' => (string) $user->id,
5887 5887
 			'__USER_LOGIN__' => (string) $user->login,
5888 5888
 			'__USER_LASTNAME__' => (string) $user->lastname,
@@ -5893,9 +5893,9 @@  discard block
 block discarded – undo
5893 5893
 			)
5894 5894
 		);
5895 5895
 	}
5896
-	if (! empty($conf->multicompany->enabled))
5896
+	if (!empty($conf->multicompany->enabled))
5897 5897
 	{
5898
-		$substitutionarray=array_merge($substitutionarray, array('__ENTITY_ID__' => $conf->entity));
5898
+		$substitutionarray = array_merge($substitutionarray, array('__ENTITY_ID__' => $conf->entity));
5899 5899
 	}
5900 5900
 
5901 5901
 	return $substitutionarray;
@@ -5915,13 +5915,13 @@  discard block
 block discarded – undo
5915 5915
  * 	@return string  		    				Output string after substitutions
5916 5916
  *  @see	complete_substitutions_array
5917 5917
  */
5918
-function make_substitutions($text, $substitutionarray, $outputlangs=null)
5918
+function make_substitutions($text, $substitutionarray, $outputlangs = null)
5919 5919
 {
5920 5920
 	global $conf, $langs;
5921 5921
 
5922
-	if (! is_array($substitutionarray)) return 'ErrorBadParameterSubstitutionArrayWhenCalling_make_substitutions';
5922
+	if (!is_array($substitutionarray)) return 'ErrorBadParameterSubstitutionArrayWhenCalling_make_substitutions';
5923 5923
 
5924
-	if (empty($outputlangs)) $outputlangs=$langs;
5924
+	if (empty($outputlangs)) $outputlangs = $langs;
5925 5925
 
5926 5926
 	// Make substitution for language keys
5927 5927
 	if (is_object($outputlangs))
@@ -5929,13 +5929,13 @@  discard block
 block discarded – undo
5929 5929
 		while (preg_match('/__\(([^\)]+)\)__/', $text, $reg))
5930 5930
 		{
5931 5931
 			$msgishtml = 0;
5932
-			if (dol_textishtml($text,1)) $msgishtml = 1;
5932
+			if (dol_textishtml($text, 1)) $msgishtml = 1;
5933 5933
 
5934 5934
 			// If key is __(TranslationKey|langfile)__, then force load of langfile.lang
5935
-			$tmp=explode('|',$reg[1]);
5936
-			if (! empty($tmp[1])) $outputlangs->load($tmp[1]);
5935
+			$tmp = explode('|', $reg[1]);
5936
+			if (!empty($tmp[1])) $outputlangs->load($tmp[1]);
5937 5937
 
5938
-			$text = preg_replace('/__\('.preg_quote($reg[1], '/').'\)__/', $msgishtml?dol_htmlentitiesbr($outputlangs->transnoentitiesnoconv($reg[1])):$outputlangs->transnoentitiesnoconv($reg[1]), $text);
5938
+			$text = preg_replace('/__\('.preg_quote($reg[1], '/').'\)__/', $msgishtml ?dol_htmlentitiesbr($outputlangs->transnoentitiesnoconv($reg[1])) : $outputlangs->transnoentitiesnoconv($reg[1]), $text);
5939 5939
 		}
5940 5940
 	}
5941 5941
 
@@ -5944,21 +5944,21 @@  discard block
 block discarded – undo
5944 5944
 	while (preg_match('/__\[([^\]]+)\]__/', $text, $reg))
5945 5945
 	{
5946 5946
 		$msgishtml = 0;
5947
-		if (dol_textishtml($text,1)) $msgishtml = 1;
5947
+		if (dol_textishtml($text, 1)) $msgishtml = 1;
5948 5948
 
5949 5949
 		$keyfound = $reg[1];
5950 5950
 		if (preg_match('/(_pass|password|secret|_key|key$)/i', $keyfound)) $newval = '*****forbidden*****';
5951
-		else $newval=empty($conf->global->$keyfound)?'':$conf->global->$keyfound;
5952
-		$text = preg_replace('/__\['.preg_quote($keyfound, '/').'\]__/', $msgishtml?dol_htmlentitiesbr($newval):$newval, $text);
5951
+		else $newval = empty($conf->global->$keyfound) ? '' : $conf->global->$keyfound;
5952
+		$text = preg_replace('/__\['.preg_quote($keyfound, '/').'\]__/', $msgishtml ?dol_htmlentitiesbr($newval) : $newval, $text);
5953 5953
 	}
5954 5954
 
5955 5955
 	// Make substitition for array $substitutionarray
5956 5956
 	foreach ($substitutionarray as $key => $value)
5957 5957
 	{
5958
-		if ($key == '__SIGNATURE__' && (! empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN))) $value='';		// Protection
5959
-		if ($key == '__USER_SIGNATURE__' && (! empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN))) $value='';	// Protection
5958
+		if ($key == '__SIGNATURE__' && (!empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN))) $value = ''; // Protection
5959
+		if ($key == '__USER_SIGNATURE__' && (!empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN))) $value = ''; // Protection
5960 5960
 
5961
-		$text=str_replace("$key","$value",$text);	// We must keep the " to work when value is 123.5 for example
5961
+		$text = str_replace("$key", "$value", $text); // We must keep the " to work when value is 123.5 for example
5962 5962
 	}
5963 5963
 
5964 5964
 	return $text;
@@ -5976,9 +5976,9 @@  discard block
 block discarded – undo
5976 5976
  *  @return	void
5977 5977
  *  @see 	make_substitutions
5978 5978
  */
5979
-function complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
5979
+function complete_substitutions_array(&$substitutionarray, $outputlangs, $object = null, $parameters = null, $callfunc = "completesubstitutionarray")
5980 5980
 {
5981
-	global $conf,$user;
5981
+	global $conf, $user;
5982 5982
 
5983 5983
 	require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
5984 5984
 
@@ -5996,28 +5996,28 @@  discard block
 block discarded – undo
5996 5996
 	}*/
5997 5997
 
5998 5998
 	// Check if there is external substitution to do, requested by plugins
5999
-	$dirsubstitutions=array_merge(array(),(array) $conf->modules_parts['substitutions']);
5999
+	$dirsubstitutions = array_merge(array(), (array) $conf->modules_parts['substitutions']);
6000 6000
 
6001
-	foreach($dirsubstitutions as $reldir)
6001
+	foreach ($dirsubstitutions as $reldir)
6002 6002
 	{
6003
-		$dir=dol_buildpath($reldir,0);
6003
+		$dir = dol_buildpath($reldir, 0);
6004 6004
 
6005 6005
 		// Check if directory exists
6006
-		if (! dol_is_dir($dir)) continue;
6006
+		if (!dol_is_dir($dir)) continue;
6007 6007
 
6008
-		$substitfiles=dol_dir_list($dir,'files',0,'functions_');
6009
-		foreach($substitfiles as $substitfile)
6008
+		$substitfiles = dol_dir_list($dir, 'files', 0, 'functions_');
6009
+		foreach ($substitfiles as $substitfile)
6010 6010
 		{
6011
-			if (preg_match('/functions_(.*)\.lib\.php/i',$substitfile['name'],$reg))
6011
+			if (preg_match('/functions_(.*)\.lib\.php/i', $substitfile['name'], $reg))
6012 6012
 			{
6013
-				$module=$reg[1];
6013
+				$module = $reg[1];
6014 6014
 
6015 6015
 				dol_syslog("Library functions_".$substitfile['name']." found into ".$dir);
6016 6016
 				// Include the user's functions file
6017 6017
 				require_once $dir.$substitfile['name'];
6018 6018
 				// Call the user's function, and only if it is defined
6019
-				$function_name=$module."_".$callfunc;
6020
-				if (function_exists($function_name)) $function_name($substitutionarray,$outputlangs,$object,$parameters);
6019
+				$function_name = $module."_".$callfunc;
6020
+				if (function_exists($function_name)) $function_name($substitutionarray, $outputlangs, $object, $parameters);
6021 6021
 			}
6022 6022
 		}
6023 6023
 	}
@@ -6032,9 +6032,9 @@  discard block
 block discarded – undo
6032 6032
  *    @param	Translate	$outputlangs   Output language
6033 6033
  *    @return	void
6034 6034
  */
6035
-function print_date_range($date_start,$date_end,$format = '',$outputlangs='')
6035
+function print_date_range($date_start, $date_end, $format = '', $outputlangs = '')
6036 6036
 {
6037
-	print get_date_range($date_start,$date_end,$format,$outputlangs);
6037
+	print get_date_range($date_start, $date_end, $format, $outputlangs);
6038 6038
 }
6039 6039
 
6040 6040
 /**
@@ -6047,25 +6047,25 @@  discard block
 block discarded – undo
6047 6047
  *    @param	integer		$withparenthesis	1=Add parenthesis, 0=non parenthesis
6048 6048
  *    @return	string							String
6049 6049
  */
6050
-function get_date_range($date_start,$date_end,$format = '',$outputlangs='', $withparenthesis=1)
6050
+function get_date_range($date_start, $date_end, $format = '', $outputlangs = '', $withparenthesis = 1)
6051 6051
 {
6052 6052
 	global $langs;
6053 6053
 
6054
-	$out='';
6054
+	$out = '';
6055 6055
 
6056
-	if (! is_object($outputlangs)) $outputlangs=$langs;
6056
+	if (!is_object($outputlangs)) $outputlangs = $langs;
6057 6057
 
6058 6058
 	if ($date_start && $date_end)
6059 6059
 	{
6060
-		$out.= ($withparenthesis?' (':'').$outputlangs->transnoentitiesnoconv('DateFromTo',dol_print_date($date_start, $format, false, $outputlangs),dol_print_date($date_end, $format, false, $outputlangs)).($withparenthesis?')':'');
6060
+		$out .= ($withparenthesis ? ' (' : '').$outputlangs->transnoentitiesnoconv('DateFromTo', dol_print_date($date_start, $format, false, $outputlangs), dol_print_date($date_end, $format, false, $outputlangs)).($withparenthesis ? ')' : '');
6061 6061
 	}
6062
-	if ($date_start && ! $date_end)
6062
+	if ($date_start && !$date_end)
6063 6063
 	{
6064
-		$out.= ($withparenthesis?' (':'').$outputlangs->transnoentitiesnoconv('DateFrom',dol_print_date($date_start, $format, false, $outputlangs)).($withparenthesis?')':'');
6064
+		$out .= ($withparenthesis ? ' (' : '').$outputlangs->transnoentitiesnoconv('DateFrom', dol_print_date($date_start, $format, false, $outputlangs)).($withparenthesis ? ')' : '');
6065 6065
 	}
6066
-	if (! $date_start && $date_end)
6066
+	if (!$date_start && $date_end)
6067 6067
 	{
6068
-		$out.= ($withparenthesis?' (':'').$outputlangs->transnoentitiesnoconv('DateUntil',dol_print_date($date_end, $format, false, $outputlangs)).($withparenthesis?')':'');
6068
+		$out .= ($withparenthesis ? ' (' : '').$outputlangs->transnoentitiesnoconv('DateUntil', dol_print_date($date_end, $format, false, $outputlangs)).($withparenthesis ? ')' : '');
6069 6069
 	}
6070 6070
 
6071 6071
 	return $out;
@@ -6079,28 +6079,28 @@  discard block
 block discarded – undo
6079 6079
  * @param	int		$nameorder		-1=Auto, 0=Lastname+Firstname, 1=Firstname+Lastname, 2=Firstname
6080 6080
  * @return	string					Firstname + lastname or Lastname + firstname
6081 6081
  */
6082
-function dolGetFirstLastname($firstname,$lastname,$nameorder=-1)
6082
+function dolGetFirstLastname($firstname, $lastname, $nameorder = -1)
6083 6083
 {
6084 6084
 	global $conf;
6085 6085
 
6086
-	$ret='';
6086
+	$ret = '';
6087 6087
 	// If order not defined, we use the setup
6088
-	if ($nameorder < 0) $nameorder=(empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION));
6088
+	if ($nameorder < 0) $nameorder = (empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION));
6089 6089
 	if ($nameorder && ((string) $nameorder != '2'))
6090 6090
 	{
6091
-		$ret.=$firstname;
6092
-		if ($firstname && $lastname) $ret.=' ';
6093
-		$ret.=$lastname;
6091
+		$ret .= $firstname;
6092
+		if ($firstname && $lastname) $ret .= ' ';
6093
+		$ret .= $lastname;
6094 6094
 	}
6095 6095
 	else if ($nameorder == 2)
6096 6096
 	{
6097
-	   $ret.=$firstname;
6097
+	   $ret .= $firstname;
6098 6098
 	}
6099 6099
 	else
6100 6100
 	{
6101
-		$ret.=$lastname;
6102
-		if ($firstname && $lastname) $ret.=' ';
6103
-		$ret.=$firstname;
6101
+		$ret .= $lastname;
6102
+		if ($firstname && $lastname) $ret .= ' ';
6103
+		$ret .= $firstname;
6104 6104
 	}
6105 6105
 	return $ret;
6106 6106
 }
@@ -6116,16 +6116,16 @@  discard block
 block discarded – undo
6116 6116
  *  @return	void
6117 6117
  *  @see	dol_htmloutput_events
6118 6118
  */
6119
-function setEventMessage($mesgs, $style='mesgs')
6119
+function setEventMessage($mesgs, $style = 'mesgs')
6120 6120
 {
6121 6121
 	//dol_syslog(__FUNCTION__ . " is deprecated", LOG_WARNING);		This is not deprecated, it is used by setEventMessages function
6122
-	if (! is_array($mesgs))		// If mesgs is a string
6122
+	if (!is_array($mesgs))		// If mesgs is a string
6123 6123
 	{
6124 6124
 		if ($mesgs) $_SESSION['dol_events'][$style][] = $mesgs;
6125 6125
 	}
6126 6126
 	else						// If mesgs is an array
6127 6127
 	{
6128
-		foreach($mesgs as $mesg)
6128
+		foreach ($mesgs as $mesg)
6129 6129
 		{
6130 6130
 			if ($mesg) $_SESSION['dol_events'][$style][] = $mesg;
6131 6131
 		}
@@ -6142,13 +6142,13 @@  discard block
 block discarded – undo
6142 6142
  *  @return	void
6143 6143
  *  @see	dol_htmloutput_events
6144 6144
  */
6145
-function setEventMessages($mesg, $mesgs, $style='mesgs')
6145
+function setEventMessages($mesg, $mesgs, $style = 'mesgs')
6146 6146
 {
6147
-	if (! in_array((string) $style, array('mesgs','warnings','errors'))) dol_print_error('','Bad parameter style='.$style.' for setEventMessages');
6147
+	if (!in_array((string) $style, array('mesgs', 'warnings', 'errors'))) dol_print_error('', 'Bad parameter style='.$style.' for setEventMessages');
6148 6148
 	if (empty($mesgs)) setEventMessage($mesg, $style);
6149 6149
 	else
6150 6150
 	{
6151
-		if (! empty($mesg) && ! in_array($mesg, $mesgs)) setEventMessage($mesg, $style);	// Add message string if not already into array
6151
+		if (!empty($mesg) && !in_array($mesg, $mesgs)) setEventMessage($mesg, $style); // Add message string if not already into array
6152 6152
 		setEventMessage($mesgs, $style);
6153 6153
 	}
6154 6154
 }
@@ -6162,7 +6162,7 @@  discard block
 block discarded – undo
6162 6162
  *  @return	void
6163 6163
  *  @see    									dol_htmloutput_mesg
6164 6164
  */
6165
-function dol_htmloutput_events($disabledoutputofmessages=0)
6165
+function dol_htmloutput_events($disabledoutputofmessages = 0)
6166 6166
 {
6167 6167
 	// Show mesgs
6168 6168
 	if (isset($_SESSION['dol_events']['mesgs'])) {
@@ -6197,57 +6197,57 @@  discard block
 block discarded – undo
6197 6197
  *  @see    dol_htmloutput_errors
6198 6198
  *  @see    setEventMessages
6199 6199
  */
6200
-function get_htmloutput_mesg($mesgstring='',$mesgarray='', $style='ok', $keepembedded=0)
6200
+function get_htmloutput_mesg($mesgstring = '', $mesgarray = '', $style = 'ok', $keepembedded = 0)
6201 6201
 {
6202 6202
 	global $conf, $langs;
6203 6203
 
6204
-	$ret=0; $return='';
6205
-	$out='';
6206
-	$divstart=$divend='';
6204
+	$ret = 0; $return = '';
6205
+	$out = '';
6206
+	$divstart = $divend = '';
6207 6207
 
6208 6208
 	// If inline message with no format, we add it.
6209
-	if ((empty($conf->use_javascript_ajax) || ! empty($conf->global->MAIN_DISABLE_JQUERY_JNOTIFY) || $keepembedded) && ! preg_match('/<div class=".*">/i',$out))
6209
+	if ((empty($conf->use_javascript_ajax) || !empty($conf->global->MAIN_DISABLE_JQUERY_JNOTIFY) || $keepembedded) && !preg_match('/<div class=".*">/i', $out))
6210 6210
 	{
6211
-		$divstart='<div class="'.$style.' clearboth">';
6212
-		$divend='</div>';
6211
+		$divstart = '<div class="'.$style.' clearboth">';
6212
+		$divend = '</div>';
6213 6213
 	}
6214 6214
 
6215 6215
 	if ((is_array($mesgarray) && count($mesgarray)) || $mesgstring)
6216 6216
 	{
6217 6217
 		$langs->load("errors");
6218
-		$out.=$divstart;
6218
+		$out .= $divstart;
6219 6219
 		if (is_array($mesgarray) && count($mesgarray))
6220 6220
 		{
6221
-			foreach($mesgarray as $message)
6221
+			foreach ($mesgarray as $message)
6222 6222
 			{
6223 6223
 				$ret++;
6224
-				$out.= $langs->trans($message);
6225
-				if ($ret < count($mesgarray)) $out.= "<br>\n";
6224
+				$out .= $langs->trans($message);
6225
+				if ($ret < count($mesgarray)) $out .= "<br>\n";
6226 6226
 			}
6227 6227
 		}
6228 6228
 		if ($mesgstring)
6229 6229
 		{
6230 6230
 			$langs->load("errors");
6231 6231
 			$ret++;
6232
-			$out.= $langs->trans($mesgstring);
6232
+			$out .= $langs->trans($mesgstring);
6233 6233
 		}
6234
-		$out.=$divend;
6234
+		$out .= $divend;
6235 6235
 	}
6236 6236
 
6237 6237
 	if ($out)
6238 6238
 	{
6239
-		if (! empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_DISABLE_JQUERY_JNOTIFY) && empty($keepembedded))
6239
+		if (!empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_DISABLE_JQUERY_JNOTIFY) && empty($keepembedded))
6240 6240
 		{
6241 6241
 			$return = '<script type="text/javascript">
6242 6242
 					$(document).ready(function() {
6243
-						var block = '.(! empty($conf->global->MAIN_USE_JQUERY_BLOCKUI)?"true":"false").'
6243
+						var block = '.(!empty($conf->global->MAIN_USE_JQUERY_BLOCKUI) ? "true" : "false").'
6244 6244
 						if (block) {
6245 6245
 							$.dolEventValid("","'.dol_escape_js($out).'");
6246 6246
 						} else {
6247 6247
 							/* jnotify(message, preset of message type, keepmessage) */
6248 6248
 							$.jnotify("'.dol_escape_js($out).'",
6249
-							"'.($style=="ok" ? 3000 : $style).'",
6250
-							'.($style=="ok" ? "false" : "true").',
6249
+							"'.($style == "ok" ? 3000 : $style).'",
6250
+							'.($style == "ok" ? "false" : "true").',
6251 6251
 							{ remove: function (){} } );
6252 6252
 						}
6253 6253
 					});
@@ -6273,9 +6273,9 @@  discard block
 block discarded – undo
6273 6273
  *  @see    dol_print_error
6274 6274
  *  @see    dol_htmloutput_mesg
6275 6275
  */
6276
-function get_htmloutput_errors($mesgstring='', $mesgarray='', $keepembedded=0)
6276
+function get_htmloutput_errors($mesgstring = '', $mesgarray = '', $keepembedded = 0)
6277 6277
 {
6278
-	return get_htmloutput_mesg($mesgstring, $mesgarray,'error',$keepembedded);
6278
+	return get_htmloutput_mesg($mesgstring, $mesgarray, 'error', $keepembedded);
6279 6279
 }
6280 6280
 
6281 6281
 /**
@@ -6291,47 +6291,47 @@  discard block
 block discarded – undo
6291 6291
  *  @see    dol_htmloutput_errors
6292 6292
  *  @see    setEventMessages
6293 6293
  */
6294
-function dol_htmloutput_mesg($mesgstring='',$mesgarray='', $style='ok', $keepembedded=0)
6294
+function dol_htmloutput_mesg($mesgstring = '', $mesgarray = '', $style = 'ok', $keepembedded = 0)
6295 6295
 {
6296
-	if (empty($mesgstring) && (! is_array($mesgarray) || count($mesgarray) == 0)) return;
6296
+	if (empty($mesgstring) && (!is_array($mesgarray) || count($mesgarray) == 0)) return;
6297 6297
 
6298
-	$iserror=0;
6299
-	$iswarning=0;
6298
+	$iserror = 0;
6299
+	$iswarning = 0;
6300 6300
 	if (is_array($mesgarray))
6301 6301
 	{
6302
-		foreach($mesgarray as $val)
6302
+		foreach ($mesgarray as $val)
6303 6303
 		{
6304
-			if ($val && preg_match('/class="error"/i',$val)) { $iserror++; break; }
6305
-			if ($val && preg_match('/class="warning"/i',$val)) { $iswarning++; break; }
6304
+			if ($val && preg_match('/class="error"/i', $val)) { $iserror++; break; }
6305
+			if ($val && preg_match('/class="warning"/i', $val)) { $iswarning++; break; }
6306 6306
 		}
6307 6307
 	}
6308
-	else if ($mesgstring && preg_match('/class="error"/i',$mesgstring)) $iserror++;
6309
-	else if ($mesgstring && preg_match('/class="warning"/i',$mesgstring)) $iswarning++;
6310
-	if ($style=='error') $iserror++;
6311
-	if ($style=='warning') $iswarning++;
6308
+	else if ($mesgstring && preg_match('/class="error"/i', $mesgstring)) $iserror++;
6309
+	else if ($mesgstring && preg_match('/class="warning"/i', $mesgstring)) $iswarning++;
6310
+	if ($style == 'error') $iserror++;
6311
+	if ($style == 'warning') $iswarning++;
6312 6312
 
6313 6313
 	if ($iserror || $iswarning)
6314 6314
 	{
6315 6315
 		// Remove div from texts
6316
-		$mesgstring=preg_replace('/<\/div><div class="(error|warning)">/','<br>',$mesgstring);
6317
-		$mesgstring=preg_replace('/<div class="(error|warning)">/','',$mesgstring);
6318
-		$mesgstring=preg_replace('/<\/div>/','',$mesgstring);
6316
+		$mesgstring = preg_replace('/<\/div><div class="(error|warning)">/', '<br>', $mesgstring);
6317
+		$mesgstring = preg_replace('/<div class="(error|warning)">/', '', $mesgstring);
6318
+		$mesgstring = preg_replace('/<\/div>/', '', $mesgstring);
6319 6319
 		// Remove div from texts array
6320 6320
 		if (is_array($mesgarray))
6321 6321
 		{
6322
-			$newmesgarray=array();
6323
-			foreach($mesgarray as $val)
6322
+			$newmesgarray = array();
6323
+			foreach ($mesgarray as $val)
6324 6324
 			{
6325
-				$tmpmesgstring=preg_replace('/<\/div><div class="(error|warning)">/','<br>',$val);
6326
-				$tmpmesgstring=preg_replace('/<div class="(error|warning)">/','',$tmpmesgstring);
6327
-				$tmpmesgstring=preg_replace('/<\/div>/','',$tmpmesgstring);
6328
-				$newmesgarray[]=$tmpmesgstring;
6325
+				$tmpmesgstring = preg_replace('/<\/div><div class="(error|warning)">/', '<br>', $val);
6326
+				$tmpmesgstring = preg_replace('/<div class="(error|warning)">/', '', $tmpmesgstring);
6327
+				$tmpmesgstring = preg_replace('/<\/div>/', '', $tmpmesgstring);
6328
+				$newmesgarray[] = $tmpmesgstring;
6329 6329
 			}
6330
-			$mesgarray=$newmesgarray;
6330
+			$mesgarray = $newmesgarray;
6331 6331
 		}
6332
-		print get_htmloutput_mesg($mesgstring,$mesgarray,($iserror?'error':'warning'),$keepembedded);
6332
+		print get_htmloutput_mesg($mesgstring, $mesgarray, ($iserror ? 'error' : 'warning'), $keepembedded);
6333 6333
 	}
6334
-	else print get_htmloutput_mesg($mesgstring,$mesgarray,'ok',$keepembedded);
6334
+	else print get_htmloutput_mesg($mesgstring, $mesgarray, 'ok', $keepembedded);
6335 6335
 }
6336 6336
 
6337 6337
 /**
@@ -6345,7 +6345,7 @@  discard block
 block discarded – undo
6345 6345
  *  @see    dol_print_error
6346 6346
  *  @see    dol_htmloutput_mesg
6347 6347
  */
6348
-function dol_htmloutput_errors($mesgstring='', $mesgarray='', $keepembedded=0)
6348
+function dol_htmloutput_errors($mesgstring = '', $mesgarray = '', $keepembedded = 0)
6349 6349
 {
6350 6350
 	dol_htmloutput_mesg($mesgstring, $mesgarray, 'error', $keepembedded);
6351 6351
 }
@@ -6363,29 +6363,29 @@  discard block
 block discarded – undo
6363 6363
  *  @param		int			$keepindex			If 0 and index key of array to sort is a numeric, than index will be rewrote. If 1 or index key is not numeric, key for index is kept after sorting.
6364 6364
  *  @return     array							Sorted array
6365 6365
  */
6366
-function dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
6366
+function dol_sort_array(&$array, $index, $order = 'asc', $natsort = 0, $case_sensitive = 0, $keepindex = 0)
6367 6367
 {
6368 6368
 	// Clean parameters
6369
-	$order=strtolower($order);
6369
+	$order = strtolower($order);
6370 6370
 
6371
-	$sizearray=count($array);
6372
-	if (is_array($array) && $sizearray>0)
6371
+	$sizearray = count($array);
6372
+	if (is_array($array) && $sizearray > 0)
6373 6373
 	{
6374 6374
 		$temp = array();
6375
-		foreach(array_keys($array) as $key) $temp[$key]=$array[$key][$index];
6375
+		foreach (array_keys($array) as $key) $temp[$key] = $array[$key][$index];
6376 6376
 
6377
-		if (!$natsort) ($order=='asc') ? asort($temp) : arsort($temp);
6377
+		if (!$natsort) ($order == 'asc') ? asort($temp) : arsort($temp);
6378 6378
 		else
6379 6379
 		{
6380 6380
 			($case_sensitive) ? natsort($temp) : natcasesort($temp);
6381
-			if($order!='asc') $temp=array_reverse($temp,TRUE);
6381
+			if ($order != 'asc') $temp = array_reverse($temp, TRUE);
6382 6382
 		}
6383 6383
 
6384 6384
 		$sorted = array();
6385 6385
 
6386
-		foreach(array_keys($temp) as $key)
6386
+		foreach (array_keys($temp) as $key)
6387 6387
 		{
6388
-			(is_numeric($key) && empty($keepindex)) ? $sorted[]=$array[$key] : $sorted[$key]=$array[$key];
6388
+			(is_numeric($key) && empty($keepindex)) ? $sorted[] = $array[$key] : $sorted[$key] = $array[$key];
6389 6389
 		}
6390 6390
 
6391 6391
 		return $sorted;
@@ -6404,16 +6404,16 @@  discard block
 block discarded – undo
6404 6404
 {
6405 6405
 	// We must use here a binary strlen function (so not dol_strlen)
6406 6406
 	$strLength = dol_strlen($str);
6407
-	for ($i=0; $i<$strLength; $i++)
6407
+	for ($i = 0; $i < $strLength; $i++)
6408 6408
 	{
6409 6409
 		if (ord($str[$i]) < 0x80) continue; // 0bbbbbbb
6410
-		elseif ((ord($str[$i]) & 0xE0) == 0xC0) $n=1; // 110bbbbb
6411
-		elseif ((ord($str[$i]) & 0xF0) == 0xE0) $n=2; // 1110bbbb
6412
-		elseif ((ord($str[$i]) & 0xF8) == 0xF0) $n=3; // 11110bbb
6413
-		elseif ((ord($str[$i]) & 0xFC) == 0xF8) $n=4; // 111110bb
6414
-		elseif ((ord($str[$i]) & 0xFE) == 0xFC) $n=5; // 1111110b
6410
+		elseif ((ord($str[$i]) & 0xE0) == 0xC0) $n = 1; // 110bbbbb
6411
+		elseif ((ord($str[$i]) & 0xF0) == 0xE0) $n = 2; // 1110bbbb
6412
+		elseif ((ord($str[$i]) & 0xF8) == 0xF0) $n = 3; // 11110bbb
6413
+		elseif ((ord($str[$i]) & 0xFC) == 0xF8) $n = 4; // 111110bb
6414
+		elseif ((ord($str[$i]) & 0xFE) == 0xFC) $n = 5; // 1111110b
6415 6415
 		else return false; // Does not match any model
6416
-		for ($j=0; $j<$n; $j++) { // n bytes matching 10bbbbbb follow ?
6416
+		for ($j = 0; $j < $n; $j++) { // n bytes matching 10bbbbbb follow ?
6417 6417
 			if ((++$i == strlen($str)) || ((ord($str[$i]) & 0xC0) != 0x80))
6418 6418
 			return false;
6419 6419
 		}
@@ -6433,10 +6433,10 @@  discard block
 block discarded – undo
6433 6433
 {
6434 6434
 	global $conf;
6435 6435
 
6436
-	$tmp=ini_get("unicode.filesystem_encoding");						// Disponible avec PHP 6.0
6437
-	if (empty($tmp) && ! empty($_SERVER["WINDIR"])) $tmp='iso-8859-1';	// By default for windows
6438
-	if (empty($tmp)) $tmp='utf-8';										// By default for other
6439
-	if (! empty($conf->global->MAIN_FILESYSTEM_ENCODING)) $tmp=$conf->global->MAIN_FILESYSTEM_ENCODING;
6436
+	$tmp = ini_get("unicode.filesystem_encoding"); // Disponible avec PHP 6.0
6437
+	if (empty($tmp) && !empty($_SERVER["WINDIR"])) $tmp = 'iso-8859-1'; // By default for windows
6438
+	if (empty($tmp)) $tmp = 'utf-8'; // By default for other
6439
+	if (!empty($conf->global->MAIN_FILESYSTEM_ENCODING)) $tmp = $conf->global->MAIN_FILESYSTEM_ENCODING;
6440 6440
 
6441 6441
 	if ($tmp == 'iso-8859-1') return utf8_decode($str);
6442 6442
 	return $str;
@@ -6456,7 +6456,7 @@  discard block
 block discarded – undo
6456 6456
  *      @return int						<0 if KO, Id of code if OK
6457 6457
  *      @see $langs->getLabelFromKey
6458 6458
  */
6459
-function dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0)
6459
+function dol_getIdFromCode($db, $key, $tablename, $fieldkey = 'code', $fieldid = 'id', $entityfilter = 0)
6460 6460
 {
6461 6461
 	global $cache_codes;
6462 6462
 
@@ -6466,22 +6466,22 @@  discard block
 block discarded – undo
6466 6466
 	// Check in cache
6467 6467
 	if (isset($cache_codes[$tablename][$key]))	// Can be defined to 0 or ''
6468 6468
 	{
6469
-		return $cache_codes[$tablename][$key];   // Found in cache
6469
+		return $cache_codes[$tablename][$key]; // Found in cache
6470 6470
 	}
6471 6471
 
6472 6472
 	$sql = "SELECT ".$fieldid." as valuetoget";
6473
-	$sql.= " FROM ".MAIN_DB_PREFIX.$tablename;
6474
-	$sql.= " WHERE ".$fieldkey." = '".$db->escape($key)."'";
6475
-	if (! empty($entityfilter))
6476
-		$sql.= " AND entity IN (" . getEntity($tablename) . ")";
6473
+	$sql .= " FROM ".MAIN_DB_PREFIX.$tablename;
6474
+	$sql .= " WHERE ".$fieldkey." = '".$db->escape($key)."'";
6475
+	if (!empty($entityfilter))
6476
+		$sql .= " AND entity IN (".getEntity($tablename).")";
6477 6477
 
6478 6478
 	dol_syslog('dol_getIdFromCode', LOG_DEBUG);
6479 6479
 	$resql = $db->query($sql);
6480 6480
 	if ($resql)
6481 6481
 	{
6482 6482
 		$obj = $db->fetch_object($resql);
6483
-		if ($obj) $cache_codes[$tablename][$key]=$obj->valuetoget;
6484
-		else $cache_codes[$tablename][$key]='';
6483
+		if ($obj) $cache_codes[$tablename][$key] = $obj->valuetoget;
6484
+		else $cache_codes[$tablename][$key] = '';
6485 6485
 		$db->free($resql);
6486 6486
 		return $cache_codes[$tablename][$key];
6487 6487
 	}
@@ -6499,9 +6499,9 @@  discard block
 block discarded – undo
6499 6499
  */
6500 6500
 function verifCond($strRights)
6501 6501
 {
6502
-	global $user,$conf,$langs;
6502
+	global $user, $conf, $langs;
6503 6503
 	global $leftmenu;
6504
-	global $rights;    // To export to dol_eval function
6504
+	global $rights; // To export to dol_eval function
6505 6505
 
6506 6506
 	//print $strRights."<br>\n";
6507 6507
 	$rights = true;
@@ -6510,7 +6510,7 @@  discard block
 block discarded – undo
6510 6510
 		//$tab_rights = explode('&&', $strRights);
6511 6511
 		//$i = 0;
6512 6512
 		//while (($i < count($tab_rights)) && ($rights == true)) {
6513
-		$str = 'if(!(' . $strRights . ')) { $rights = false; }';
6513
+		$str = 'if(!('.$strRights.')) { $rights = false; }';
6514 6514
 		dol_eval($str);
6515 6515
 		//	$i++;
6516 6516
 		//}
@@ -6527,7 +6527,7 @@  discard block
 block discarded – undo
6527 6527
  * @param   int     $hideerrors     1=Hide errors
6528 6528
  * @return	mixed					Nothing or return of eval
6529 6529
  */
6530
-function dol_eval($s, $returnvalue=0, $hideerrors=1)
6530
+function dol_eval($s, $returnvalue = 0, $hideerrors = 1)
6531 6531
 {
6532 6532
 	// Only global variables can be changed by eval function and returned to caller
6533 6533
 	global $db, $langs, $user, $conf;
@@ -6536,8 +6536,8 @@  discard block
 block discarded – undo
6536 6536
 	global $object;
6537 6537
 	global $mysoc;
6538 6538
 
6539
-	global $obj;       // To get $obj used into list when dol_eval is used for computed fields and $obj is not yet $object
6540
-	global $soc;       // For backward compatibility
6539
+	global $obj; // To get $obj used into list when dol_eval is used for computed fields and $obj is not yet $object
6540
+	global $soc; // For backward compatibility
6541 6541
 
6542 6542
 	//print $s."<br>\n";
6543 6543
 	if ($returnvalue)
@@ -6630,7 +6630,7 @@  discard block
 block discarded – undo
6630 6630
  *  @param  string		$mode  	        	'add' to complete head, 'remove' to remove entries
6631 6631
  *	@return	void
6632 6632
  */
6633
-function complete_head_from_modules($conf,$langs,$object,&$head,&$h,$type,$mode='add')
6633
+function complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode = 'add')
6634 6634
 {
6635 6635
 	global $hookmanager;
6636 6636
 
@@ -6638,9 +6638,9 @@  discard block
 block discarded – undo
6638 6638
 	{
6639 6639
 		foreach ($conf->modules_parts['tabs'][$type] as $value)
6640 6640
 		{
6641
-			$values=explode(':',$value);
6641
+			$values = explode(':', $value);
6642 6642
 
6643
-			if ($mode == 'add' && ! preg_match('/^\-/',$values[1]))
6643
+			if ($mode == 'add' && !preg_match('/^\-/', $values[1]))
6644 6644
 			{
6645 6645
 				if (count($values) == 6)       // new declaration with permissions:  $value='objecttype:+tabname1:Title1:langfile@mymodule:$user->rights->mymodule->read:/mymodule/mynewtab1.php?id=__ID__'
6646 6646
 				{
@@ -6649,17 +6649,17 @@  discard block
 block discarded – undo
6649 6649
 					if (verifCond($values[4]))
6650 6650
 					{
6651 6651
 						if ($values[3]) $langs->load($values[3]);
6652
-						if (preg_match('/SUBSTITUTION_([^_]+)/i',$values[2],$reg))
6652
+						if (preg_match('/SUBSTITUTION_([^_]+)/i', $values[2], $reg))
6653 6653
 						{
6654
-							$substitutionarray=array();
6655
-							complete_substitutions_array($substitutionarray,$langs,$object,array('needforkey'=>$values[2]));
6656
-							$label=make_substitutions($reg[1], $substitutionarray);
6654
+							$substitutionarray = array();
6655
+							complete_substitutions_array($substitutionarray, $langs, $object, array('needforkey'=>$values[2]));
6656
+							$label = make_substitutions($reg[1], $substitutionarray);
6657 6657
 						}
6658
-						else $label=$langs->trans($values[2]);
6658
+						else $label = $langs->trans($values[2]);
6659 6659
 
6660
-						$head[$h][0] = dol_buildpath(preg_replace('/__ID__/i', ((is_object($object) && ! empty($object->id))?$object->id:''), $values[5]), 1);
6660
+						$head[$h][0] = dol_buildpath(preg_replace('/__ID__/i', ((is_object($object) && !empty($object->id)) ? $object->id : ''), $values[5]), 1);
6661 6661
 						$head[$h][1] = $label;
6662
-						$head[$h][2] = str_replace('+','',$values[1]);
6662
+						$head[$h][2] = str_replace('+', '', $values[1]);
6663 6663
 						$h++;
6664 6664
 					}
6665 6665
 				}
@@ -6669,28 +6669,28 @@  discard block
 block discarded – undo
6669 6669
 
6670 6670
 					if ($values[0] != $type) continue;
6671 6671
 					if ($values[3]) $langs->load($values[3]);
6672
-					if (preg_match('/SUBSTITUTION_([^_]+)/i',$values[2],$reg))
6672
+					if (preg_match('/SUBSTITUTION_([^_]+)/i', $values[2], $reg))
6673 6673
 					{
6674
-						$substitutionarray=array();
6675
-						complete_substitutions_array($substitutionarray,$langs,$object,array('needforkey'=>$values[2]));
6676
-						$label=make_substitutions($reg[1], $substitutionarray);
6674
+						$substitutionarray = array();
6675
+						complete_substitutions_array($substitutionarray, $langs, $object, array('needforkey'=>$values[2]));
6676
+						$label = make_substitutions($reg[1], $substitutionarray);
6677 6677
 					}
6678
-					else $label=$langs->trans($values[2]);
6678
+					else $label = $langs->trans($values[2]);
6679 6679
 
6680
-					$head[$h][0] = dol_buildpath(preg_replace('/__ID__/i', ((is_object($object) && ! empty($object->id))?$object->id:''), $values[4]), 1);
6680
+					$head[$h][0] = dol_buildpath(preg_replace('/__ID__/i', ((is_object($object) && !empty($object->id)) ? $object->id : ''), $values[4]), 1);
6681 6681
 					$head[$h][1] = $label;
6682
-					$head[$h][2] = str_replace('+','',$values[1]);
6682
+					$head[$h][2] = str_replace('+', '', $values[1]);
6683 6683
 					$h++;
6684 6684
 				}
6685 6685
 			}
6686
-			else if ($mode == 'remove' && preg_match('/^\-/',$values[1]))
6686
+			else if ($mode == 'remove' && preg_match('/^\-/', $values[1]))
6687 6687
 			{
6688 6688
 				if ($values[0] != $type) continue;
6689
-				$tabname=str_replace('-','',$values[1]);
6690
-				foreach($head as $key => $val)
6689
+				$tabname = str_replace('-', '', $values[1]);
6690
+				foreach ($head as $key => $val)
6691 6691
 				{
6692
-					$condition = (! empty($values[3]) ? verifCond($values[3]) : 1);
6693
-					if ($head[$key][2]==$tabname && $condition)
6692
+					$condition = (!empty($values[3]) ? verifCond($values[3]) : 1);
6693
+					if ($head[$key][2] == $tabname && $condition)
6694 6694
 					{
6695 6695
 						unset($head[$key]);
6696 6696
 						break;
@@ -6701,10 +6701,10 @@  discard block
 block discarded – undo
6701 6701
 	}
6702 6702
 
6703 6703
 	// No need to make a return $head. Var is modified as a reference
6704
-	if (! empty($hookmanager))
6704
+	if (!empty($hookmanager))
6705 6705
 	{
6706
-		$parameters=array('object' => $object, 'mode' => $mode, 'head'=>$head);
6707
-		$reshook=$hookmanager->executeHooks('completeTabsHead',$parameters);
6706
+		$parameters = array('object' => $object, 'mode' => $mode, 'head'=>$head);
6707
+		$reshook = $hookmanager->executeHooks('completeTabsHead', $parameters);
6708 6708
 		if ($reshook > 0)
6709 6709
 		{
6710 6710
 			$head = $hookmanager->resArray;
@@ -6723,7 +6723,7 @@  discard block
 block discarded – undo
6723 6723
  * @param	string	$zone	'private' (for private pages) or 'public' (for public pages)
6724 6724
  * @return	void
6725 6725
  */
6726
-function printCommonFooter($zone='private')
6726
+function printCommonFooter($zone = 'private')
6727 6727
 {
6728 6728
 	global $conf, $hookmanager;
6729 6729
 	global $micro_start_time;
@@ -6731,14 +6731,14 @@  discard block
 block discarded – undo
6731 6731
 	if ($zone == 'private') print "\n".'<!-- Common footer for private page -->'."\n";
6732 6732
 	else print "\n".'<!-- Common footer for public page -->'."\n";
6733 6733
 
6734
-	$parameters=array();
6735
-	$reshook=$hookmanager->executeHooks('printCommonFooter',$parameters);    // Note that $action and $object may have been modified by some hooks
6734
+	$parameters = array();
6735
+	$reshook = $hookmanager->executeHooks('printCommonFooter', $parameters); // Note that $action and $object may have been modified by some hooks
6736 6736
 	if (empty($reshook))
6737 6737
 	{
6738
-		if (! empty($conf->global->MAIN_HTML_FOOTER)) print $conf->global->MAIN_HTML_FOOTER."\n";
6738
+		if (!empty($conf->global->MAIN_HTML_FOOTER)) print $conf->global->MAIN_HTML_FOOTER."\n";
6739 6739
 
6740 6740
 		print "\n";
6741
-		if (! empty($conf->use_javascript_ajax))
6741
+		if (!empty($conf->use_javascript_ajax))
6742 6742
 		{
6743 6743
 			print '<script type="text/javascript" language="javascript">'."\n";
6744 6744
 
@@ -6755,7 +6755,7 @@  discard block
 block discarded – undo
6755 6755
 			}
6756 6756
 
6757 6757
 			// Google Analytics (need Google module)
6758
-			if (! empty($conf->google->enabled) && ! empty($conf->global->MAIN_GOOGLE_AN_ID))
6758
+			if (!empty($conf->google->enabled) && !empty($conf->global->MAIN_GOOGLE_AN_ID))
6759 6759
 			{
6760 6760
 				if (($conf->dol_use_jmobile != 4))
6761 6761
 				{
@@ -6774,17 +6774,17 @@  discard block
 block discarded – undo
6774 6774
 			}
6775 6775
 
6776 6776
 			// End of tuning
6777
-			if (! empty($_SERVER['MAIN_SHOW_TUNING_INFO']) || ! empty($conf->global->MAIN_SHOW_TUNING_INFO))
6777
+			if (!empty($_SERVER['MAIN_SHOW_TUNING_INFO']) || !empty($conf->global->MAIN_SHOW_TUNING_INFO))
6778 6778
 			{
6779 6779
 				print "\n";
6780 6780
 				print "/* JS CODE TO ENABLE to add memory info */\n";
6781 6781
 				print 'window.console && console.log("';
6782
-				if (! empty($conf->global->MEMCACHED_SERVER)) print 'MEMCACHED_SERVER='.$conf->global->MEMCACHED_SERVER.' - ';
6783
-				print 'MAIN_OPTIMIZE_SPEED='.(isset($conf->global->MAIN_OPTIMIZE_SPEED)?$conf->global->MAIN_OPTIMIZE_SPEED:'off');
6784
-				if (! empty($micro_start_time))   // Works only if MAIN_SHOW_TUNING_INFO is defined at $_SERVER level. Not in global variable.
6782
+				if (!empty($conf->global->MEMCACHED_SERVER)) print 'MEMCACHED_SERVER='.$conf->global->MEMCACHED_SERVER.' - ';
6783
+				print 'MAIN_OPTIMIZE_SPEED='.(isset($conf->global->MAIN_OPTIMIZE_SPEED) ? $conf->global->MAIN_OPTIMIZE_SPEED : 'off');
6784
+				if (!empty($micro_start_time))   // Works only if MAIN_SHOW_TUNING_INFO is defined at $_SERVER level. Not in global variable.
6785 6785
 				{
6786 6786
 					$micro_end_time = microtime(true);
6787
-					print ' - Build time: '.ceil(1000*($micro_end_time-$micro_start_time)).' ms';
6787
+					print ' - Build time: '.ceil(1000 * ($micro_end_time - $micro_start_time)).' ms';
6788 6788
 				}
6789 6789
 				if (function_exists("memory_get_usage"))
6790 6790
 				{
@@ -6792,13 +6792,13 @@  discard block
 block discarded – undo
6792 6792
 				}
6793 6793
 				if (function_exists("xdebug_memory_usage"))
6794 6794
 				{
6795
-					print ' - XDebug time: '.ceil(1000*xdebug_time_index()).' ms';
6795
+					print ' - XDebug time: '.ceil(1000 * xdebug_time_index()).' ms';
6796 6796
 					print ' - XDebug mem: '.xdebug_memory_usage();
6797 6797
 					print ' - XDebug mem peak: '.xdebug_peak_memory_usage();
6798 6798
 				}
6799 6799
 				if (function_exists("zend_loader_file_encoded"))
6800 6800
 				{
6801
-					print ' - Zend encoded file: '.(zend_loader_file_encoded()?'yes':'no');
6801
+					print ' - Zend encoded file: '.(zend_loader_file_encoded() ? 'yes' : 'no');
6802 6802
 				}
6803 6803
 				print '");'."\n";
6804 6804
 			}
@@ -6818,7 +6818,7 @@  discard block
 block discarded – undo
6818 6818
 			print "\n";
6819 6819
 			print "<!-- Start of log output\n";
6820 6820
 			//print '<div class="hidden">'."\n";
6821
-			foreach($conf->logbuffer as $logline)
6821
+			foreach ($conf->logbuffer as $logline)
6822 6822
 			{
6823 6823
 				print $logline."<br>\n";
6824 6824
 			}
@@ -6879,8 +6879,8 @@  discard block
 block discarded – undo
6879 6879
  */
6880 6880
 function dol_getmypid()
6881 6881
 {
6882
-	if (! function_exists('getmypid')) {
6883
-		return mt_rand(1,32768);
6882
+	if (!function_exists('getmypid')) {
6883
+		return mt_rand(1, 32768);
6884 6884
 	} else {
6885 6885
 		return getmypid();
6886 6886
 	}
@@ -6902,26 +6902,26 @@  discard block
 block discarded – undo
6902 6902
  * @param	integer			$nofirstand	1=Do not output the first 'AND'
6903 6903
  * @return 	string 			$res 		The statement to append to the SQL query
6904 6904
  */
6905
-function natural_search($fields, $value, $mode=0, $nofirstand=0)
6905
+function natural_search($fields, $value, $mode = 0, $nofirstand = 0)
6906 6906
 {
6907
-	global $db,$langs;
6907
+	global $db, $langs;
6908 6908
 
6909
-	$value=trim($value);
6909
+	$value = trim($value);
6910 6910
 
6911 6911
 	if ($mode == 0)
6912 6912
 	{
6913
-		$value=preg_replace('/\*/','%',$value);	// Replace * with %
6913
+		$value = preg_replace('/\*/', '%', $value); // Replace * with %
6914 6914
 	}
6915 6915
 	if ($mode == 1)
6916 6916
 	{
6917
-		$value=preg_replace('/([<>=]+)\s+([0-9'.preg_quote($langs->trans("DecimalSeparator"),'/').'\-])/','\1\2',$value);	// Clean string '< 10' into '<10' so we can the explode on space to get all tests to do
6917
+		$value = preg_replace('/([<>=]+)\s+([0-9'.preg_quote($langs->trans("DecimalSeparator"), '/').'\-])/', '\1\2', $value); // Clean string '< 10' into '<10' so we can the explode on space to get all tests to do
6918 6918
 	}
6919 6919
 
6920
-	$value = preg_replace('/\s*\|\s*/','|', $value);
6920
+	$value = preg_replace('/\s*\|\s*/', '|', $value);
6921 6921
 
6922 6922
 	$crits = explode(' ', $value);
6923 6923
 	$res = '';
6924
-	if (! is_array($fields)) $fields = array($fields);
6924
+	if (!is_array($fields)) $fields = array($fields);
6925 6925
 
6926 6926
 	$nboffields = count($fields);
6927 6927
 	$end2 = count($crits);
@@ -6934,10 +6934,10 @@  discard block
 block discarded – undo
6934 6934
 		{
6935 6935
 			if ($mode == 1)
6936 6936
 			{
6937
-				$operator='=';
6938
-				$newcrit = preg_replace('/([<>=]+)/','',trim($crit));
6937
+				$operator = '=';
6938
+				$newcrit = preg_replace('/([<>=]+)/', '', trim($crit));
6939 6939
 
6940
-				preg_match('/([<>=]+)/',trim($crit), $reg);
6940
+				preg_match('/([<>=]+)/', trim($crit), $reg);
6941 6941
 				if ($reg[1])
6942 6942
 				{
6943 6943
 					$operator = $reg[1];
@@ -6947,66 +6947,66 @@  discard block
 block discarded – undo
6947 6947
 					$numnewcrit = price2num($newcrit);
6948 6948
 					if (is_numeric($numnewcrit))
6949 6949
 					{
6950
-						$newres .= ($i2 > 0 ? ' OR ' : '') . $field . ' '.$operator.' '.$numnewcrit;
6950
+						$newres .= ($i2 > 0 ? ' OR ' : '').$field.' '.$operator.' '.$numnewcrit;
6951 6951
 					}
6952 6952
 					else
6953 6953
 					{
6954
-						$newres .= ($i2 > 0 ? ' OR ' : '') . '1 = 2';	// force false
6954
+						$newres .= ($i2 > 0 ? ' OR ' : '').'1 = 2'; // force false
6955 6955
 					}
6956
-					$i2++;	// a criteria was added to string
6956
+					$i2++; // a criteria was added to string
6957 6957
 				}
6958 6958
 			}
6959 6959
 			else if ($mode == 2)
6960 6960
 			{
6961
-				$newres .= ($i2 > 0 ? ' OR ' : '') . $field . " IN (" . $db->escape(trim($crit)) . ")";
6962
-				$i2++;	// a criteria was added to string
6961
+				$newres .= ($i2 > 0 ? ' OR ' : '').$field." IN (".$db->escape(trim($crit)).")";
6962
+				$i2++; // a criteria was added to string
6963 6963
 			}
6964 6964
 			else if ($mode == 3)
6965 6965
 			{
6966
-				$tmparray=explode(',',trim($crit));
6966
+				$tmparray = explode(',', trim($crit));
6967 6967
 				if (count($tmparray))
6968 6968
 				{
6969
-					$listofcodes='';
6970
-					foreach($tmparray as $val)
6969
+					$listofcodes = '';
6970
+					foreach ($tmparray as $val)
6971 6971
 					{
6972 6972
 						if ($val)
6973 6973
 						{
6974
-							$listofcodes.=($listofcodes?',':'');
6975
-							$listofcodes.="'".$db->escape(trim($val))."'";
6974
+							$listofcodes .= ($listofcodes ? ',' : '');
6975
+							$listofcodes .= "'".$db->escape(trim($val))."'";
6976 6976
 						}
6977 6977
 					}
6978
-					$newres .= ($i2 > 0 ? ' OR ' : '') . $field . " IN (" . $listofcodes . ")";
6979
-					$i2++;	// a criteria was added to string
6978
+					$newres .= ($i2 > 0 ? ' OR ' : '').$field." IN (".$listofcodes.")";
6979
+					$i2++; // a criteria was added to string
6980 6980
 				}
6981 6981
 			}
6982 6982
 			else    // $mode=0
6983 6983
 			{
6984 6984
 				$textcrit = '';
6985
-				$tmpcrits = explode('|',$crit);
6985
+				$tmpcrits = explode('|', $crit);
6986 6986
 				$i3 = 0;
6987
-				foreach($tmpcrits as $tmpcrit)
6987
+				foreach ($tmpcrits as $tmpcrit)
6988 6988
 				{
6989 6989
 					$newres .= (($i2 > 0 || $i3 > 0) ? ' OR ' : '');
6990 6990
 
6991 6991
 					if (preg_match('/\.(id|rowid)$/', $field))	// Special case for rowid that is sometimes a ref so used as a search field
6992 6992
 					{
6993
-						$newres .= $field . " = " . (is_numeric(trim($tmpcrit))?trim($tmpcrit):'0');
6993
+						$newres .= $field." = ".(is_numeric(trim($tmpcrit)) ?trim($tmpcrit) : '0');
6994 6994
 					}
6995 6995
 					else
6996 6996
 					{
6997
-						$newres .= $field . " LIKE '";
6997
+						$newres .= $field." LIKE '";
6998 6998
 
6999
-						$tmpcrit=trim($tmpcrit);
7000
-						$tmpcrit2=$tmpcrit;
7001
-						$tmpbefore='%'; $tmpafter='%';
6999
+						$tmpcrit = trim($tmpcrit);
7000
+						$tmpcrit2 = $tmpcrit;
7001
+						$tmpbefore = '%'; $tmpafter = '%';
7002 7002
 						if (preg_match('/^[\^\$]/', $tmpcrit))
7003 7003
 						{
7004
-							$tmpbefore='';
7004
+							$tmpbefore = '';
7005 7005
 							$tmpcrit2 = preg_replace('/^[\^\$]/', '', $tmpcrit2);
7006 7006
 						}
7007 7007
 						if (preg_match('/[\^\$]$/', $tmpcrit))
7008 7008
 						{
7009
-							$tmpafter='';
7009
+							$tmpafter = '';
7010 7010
 							$tmpcrit2 = preg_replace('/[\^\$]$/', '', $tmpcrit2);
7011 7011
 						}
7012 7012
 						$newres .= $tmpbefore;
@@ -7015,20 +7015,20 @@  discard block
 block discarded – undo
7015 7015
 						$newres .= "'";
7016 7016
 						if ($tmpcrit2 == '')
7017 7017
 						{
7018
-							$newres .= ' OR ' . $field . " IS NULL";
7018
+							$newres .= ' OR '.$field." IS NULL";
7019 7019
 						}
7020 7020
 					}
7021 7021
 
7022 7022
 					$i3++;
7023 7023
 				}
7024
-				$i2++;	// a criteria was added to string
7024
+				$i2++; // a criteria was added to string
7025 7025
 			}
7026 7026
 			$i++;
7027 7027
 		}
7028
-		if ($newres) $res = $res . ($res ? ' AND ' : '') . ($i2 > 1 ? '(' : '') .$newres . ($i2 > 1 ? ')' : '');
7028
+		if ($newres) $res = $res.($res ? ' AND ' : '').($i2 > 1 ? '(' : '').$newres.($i2 > 1 ? ')' : '');
7029 7029
 		$j++;
7030 7030
 	}
7031
-	$res = ($nofirstand?"":" AND ")."(" . $res . ")";
7031
+	$res = ($nofirstand ? "" : " AND ")."(".$res.")";
7032 7032
 	//print 'xx'.$res.'yy';
7033 7033
 	return $res;
7034 7034
 }
@@ -7043,14 +7043,14 @@  discard block
 block discarded – undo
7043 7043
 {
7044 7044
 	global $conf, $langs;
7045 7045
 
7046
-	$out='';
7046
+	$out = '';
7047 7047
 	$url = $object->getLastMainDocLink($object->element);
7048 7048
 
7049 7049
 	if ($url)
7050 7050
 	{
7051
-		$out.= img_picto('','object_globe.png').' '.$langs->trans("DirectDownloadLink").'<br>';
7052
-		$out.= '<input type="text" id="directdownloadlink" class="quatrevingtpercent" value="'.$url.'">';
7053
-		$out.= ajax_autoselect("directdownloadlink", 0);
7051
+		$out .= img_picto('', 'object_globe.png').' '.$langs->trans("DirectDownloadLink").'<br>';
7052
+		$out .= '<input type="text" id="directdownloadlink" class="quatrevingtpercent" value="'.$url.'">';
7053
+		$out .= ajax_autoselect("directdownloadlink", 0);
7054 7054
 	}
7055 7055
 	return $out;
7056 7056
 }
@@ -7063,26 +7063,26 @@  discard block
 block discarded – undo
7063 7063
  * @param   string  $extImgTarget   Force image extension for thumbs. Use '' to keep same extension than original image (default).
7064 7064
  * @return  string                  New file name (full or relative path, including the thumbs/)
7065 7065
  */
7066
-function getImageFileNameForSize($file, $extName, $extImgTarget='')
7066
+function getImageFileNameForSize($file, $extName, $extImgTarget = '')
7067 7067
 {
7068 7068
 	$dirName = dirname($file);
7069
-	if ($dirName == '.') $dirName='';
7069
+	if ($dirName == '.') $dirName = '';
7070 7070
 
7071
-	$fileName = preg_replace('/(\.gif|\.jpeg|\.jpg|\.png|\.bmp)$/i','',$file);	// We remove extension, whatever is its case
7071
+	$fileName = preg_replace('/(\.gif|\.jpeg|\.jpg|\.png|\.bmp)$/i', '', $file); // We remove extension, whatever is its case
7072 7072
 	$fileName = basename($fileName);
7073 7073
 
7074
-	if (empty($extImgTarget)) $extImgTarget = (preg_match('/\.jpg$/i',$file)?'.jpg':'');
7075
-	if (empty($extImgTarget)) $extImgTarget = (preg_match('/\.jpeg$/i',$file)?'.jpeg':'');
7076
-	if (empty($extImgTarget)) $extImgTarget = (preg_match('/\.gif$/i',$file)?'.gif':'');
7077
-	if (empty($extImgTarget)) $extImgTarget = (preg_match('/\.png$/i',$file)?'.png':'');
7078
-	if (empty($extImgTarget)) $extImgTarget = (preg_match('/\.bmp$/i',$file)?'.bmp':'');
7074
+	if (empty($extImgTarget)) $extImgTarget = (preg_match('/\.jpg$/i', $file) ? '.jpg' : '');
7075
+	if (empty($extImgTarget)) $extImgTarget = (preg_match('/\.jpeg$/i', $file) ? '.jpeg' : '');
7076
+	if (empty($extImgTarget)) $extImgTarget = (preg_match('/\.gif$/i', $file) ? '.gif' : '');
7077
+	if (empty($extImgTarget)) $extImgTarget = (preg_match('/\.png$/i', $file) ? '.png' : '');
7078
+	if (empty($extImgTarget)) $extImgTarget = (preg_match('/\.bmp$/i', $file) ? '.bmp' : '');
7079 7079
 
7080
-	if (! $extImgTarget) return $file;
7080
+	if (!$extImgTarget) return $file;
7081 7081
 
7082
-	$subdir='';
7082
+	$subdir = '';
7083 7083
 	if ($extName) $subdir = 'thumbs/';
7084 7084
 
7085
-	return ($dirName?$dirName.'/':'').$subdir.$fileName.$extName.$extImgTarget; // New filename for thumb
7085
+	return ($dirName ? $dirName.'/' : '').$subdir.$fileName.$extName.$extImgTarget; // New filename for thumb
7086 7086
 }
7087 7087
 
7088 7088
 
@@ -7095,7 +7095,7 @@  discard block
 block discarded – undo
7095 7095
  * @param	string	  $param		  More param on http links
7096 7096
  * @return  string|array              Output string with href link or array with all components of link
7097 7097
  */
7098
-function getAdvancedPreviewUrl($modulepart, $relativepath, $alldata=0, $param='')
7098
+function getAdvancedPreviewUrl($modulepart, $relativepath, $alldata = 0, $param = '')
7099 7099
 {
7100 7100
 	global $conf, $langs;
7101 7101
 
@@ -7108,12 +7108,12 @@  discard block
 block discarded – undo
7108 7108
 
7109 7109
 	if ($alldata == 1)
7110 7110
 	{
7111
-		if ($num_mime !== false) return array('target'=>'_blank', 'css'=>'documentpreview', 'url'=>DOL_URL_ROOT.'/document.php?modulepart='.$modulepart.'&attachment=0&file='.urlencode($relativepath), 'mime'=>dol_mimetype($relativepath), );
7111
+		if ($num_mime !== false) return array('target'=>'_blank', 'css'=>'documentpreview', 'url'=>DOL_URL_ROOT.'/document.php?modulepart='.$modulepart.'&attachment=0&file='.urlencode($relativepath), 'mime'=>dol_mimetype($relativepath),);
7112 7112
 		else return array();
7113 7113
 	}
7114 7114
 
7115 7115
 	// old behavior
7116
-	if ($num_mime !== false) return 'javascript:document_preview(\''.dol_escape_js(DOL_URL_ROOT.'/document.php?modulepart='.$modulepart.'&attachment=0&file='.urlencode($relativepath).($param?'&'.$param:'')).'\', \''.dol_mimetype($relativepath).'\', \''.dol_escape_js($langs->trans('Preview')).'\')';
7116
+	if ($num_mime !== false) return 'javascript:document_preview(\''.dol_escape_js(DOL_URL_ROOT.'/document.php?modulepart='.$modulepart.'&attachment=0&file='.urlencode($relativepath).($param ? '&'.$param : '')).'\', \''.dol_mimetype($relativepath).'\', \''.dol_escape_js($langs->trans('Preview')).'\')';
7117 7117
 	else return '';
7118 7118
 }
7119 7119
 
@@ -7124,7 +7124,7 @@  discard block
 block discarded – undo
7124 7124
  * @param string	$htmlname	Id of html object
7125 7125
  * @param string	$addlink	Add a 'link to' after
7126 7126
  */
7127
-function ajax_autoselect($htmlname, $addlink='')
7127
+function ajax_autoselect($htmlname, $addlink = '')
7128 7128
 {
7129 7129
 	global $langs;
7130 7130
 	$out = '<script type="text/javascript">
@@ -7132,7 +7132,7 @@  discard block
 block discarded – undo
7132 7132
 				    jQuery("#'.$htmlname.'").click(function() { jQuery(this).select(); } );
7133 7133
 				});
7134 7134
 		    </script>';
7135
-	if ($addlink) $out.=' <a href="'.$addlink.'" target="_blank">'.$langs->trans("Link").'</a>';
7135
+	if ($addlink) $out .= ' <a href="'.$addlink.'" target="_blank">'.$langs->trans("Link").'</a>';
7136 7136
 	return $out;
7137 7137
 }
7138 7138
 
@@ -7146,96 +7146,96 @@  discard block
 block discarded – undo
7146 7146
  *	@return string 		    	Return a mime type family (text/xxx, application/xxx, image/xxx, audio, video, archive)
7147 7147
  *  @see    image_format_supported (images.lib.php)
7148 7148
  */
7149
-function dol_mimetype($file, $default='application/octet-stream', $mode=0)
7149
+function dol_mimetype($file, $default = 'application/octet-stream', $mode = 0)
7150 7150
 {
7151
-	$mime=$default;
7152
-	$imgmime='other.png';
7153
-	$famime='file-o';
7154
-	$srclang='';
7151
+	$mime = $default;
7152
+	$imgmime = 'other.png';
7153
+	$famime = 'file-o';
7154
+	$srclang = '';
7155 7155
 
7156
-	$tmpfile=preg_replace('/\.noexe$/','',$file);
7156
+	$tmpfile = preg_replace('/\.noexe$/', '', $file);
7157 7157
 
7158 7158
 	// Text files
7159
-	if (preg_match('/\.txt$/i',$tmpfile))         			   { $mime='text/plain';    $imgmime='text.png'; $famime='file-text-o'; }
7160
-	if (preg_match('/\.rtx$/i',$tmpfile))                      { $mime='text/richtext'; $imgmime='text.png'; $famime='file-text-o'; }
7161
-	if (preg_match('/\.csv$/i',$tmpfile))					   { $mime='text/csv';      $imgmime='text.png'; $famime='file-text-o'; }
7162
-	if (preg_match('/\.tsv$/i',$tmpfile))					   { $mime='text/tab-separated-values'; $imgmime='text.png'; $famime='file-text-o'; }
7163
-	if (preg_match('/\.(cf|conf|log)$/i',$tmpfile))            { $mime='text/plain';    $imgmime='text.png'; $famime='file-text-o'; }
7164
-	if (preg_match('/\.ini$/i',$tmpfile))                      { $mime='text/plain';    $imgmime='text.png'; $srclang='ini'; $famime='file-text-o'; }
7165
-	if (preg_match('/\.css$/i',$tmpfile))                      { $mime='text/css';      $imgmime='css.png'; $srclang='css'; $famime='file-text-o'; }
7159
+	if (preg_match('/\.txt$/i', $tmpfile)) { $mime = 'text/plain'; $imgmime = 'text.png'; $famime = 'file-text-o'; }
7160
+	if (preg_match('/\.rtx$/i', $tmpfile)) { $mime = 'text/richtext'; $imgmime = 'text.png'; $famime = 'file-text-o'; }
7161
+	if (preg_match('/\.csv$/i', $tmpfile)) { $mime = 'text/csv'; $imgmime = 'text.png'; $famime = 'file-text-o'; }
7162
+	if (preg_match('/\.tsv$/i', $tmpfile)) { $mime = 'text/tab-separated-values'; $imgmime = 'text.png'; $famime = 'file-text-o'; }
7163
+	if (preg_match('/\.(cf|conf|log)$/i', $tmpfile)) { $mime = 'text/plain'; $imgmime = 'text.png'; $famime = 'file-text-o'; }
7164
+	if (preg_match('/\.ini$/i', $tmpfile)) { $mime = 'text/plain'; $imgmime = 'text.png'; $srclang = 'ini'; $famime = 'file-text-o'; }
7165
+	if (preg_match('/\.css$/i', $tmpfile)) { $mime = 'text/css'; $imgmime = 'css.png'; $srclang = 'css'; $famime = 'file-text-o'; }
7166 7166
 	// Certificate files
7167
-	if (preg_match('/\.(crt|cer|key|pub)$/i',$tmpfile))        { $mime='text/plain';    $imgmime='text.png'; $famime='file-text-o'; }
7167
+	if (preg_match('/\.(crt|cer|key|pub)$/i', $tmpfile)) { $mime = 'text/plain'; $imgmime = 'text.png'; $famime = 'file-text-o'; }
7168 7168
 	// HTML/XML
7169
-	if (preg_match('/\.(html|htm|shtml)$/i',$tmpfile))         { $mime='text/html';     $imgmime='html.png'; $srclang='html'; $famime='file-text-o'; }
7170
-	if (preg_match('/\.(xml|xhtml)$/i',$tmpfile))              { $mime='text/xml';      $imgmime='other.png'; $srclang='xml'; $famime='file-text-o'; }
7169
+	if (preg_match('/\.(html|htm|shtml)$/i', $tmpfile)) { $mime = 'text/html'; $imgmime = 'html.png'; $srclang = 'html'; $famime = 'file-text-o'; }
7170
+	if (preg_match('/\.(xml|xhtml)$/i', $tmpfile)) { $mime = 'text/xml'; $imgmime = 'other.png'; $srclang = 'xml'; $famime = 'file-text-o'; }
7171 7171
 	// Languages
7172
-	if (preg_match('/\.bas$/i',$tmpfile))                      { $mime='text/plain'; $imgmime='text.png'; $srclang='bas';  $famime='file-code-o'; }
7173
-	if (preg_match('/\.(c)$/i',$tmpfile))                      { $mime='text/plain'; $imgmime='text.png'; $srclang='c';  $famime='file-code-o'; }
7174
-	if (preg_match('/\.(cpp)$/i',$tmpfile))                    { $mime='text/plain'; $imgmime='text.png'; $srclang='cpp';  $famime='file-code-o'; }
7175
-	if (preg_match('/\.(h)$/i',$tmpfile))                      { $mime='text/plain'; $imgmime='text.png'; $srclang='h';  $famime='file-code-o'; }
7176
-	if (preg_match('/\.(java|jsp)$/i',$tmpfile))               { $mime='text/plain'; $imgmime='text.png'; $srclang='java';  $famime='file-code-o'; }
7177
-	if (preg_match('/\.php([0-9]{1})?$/i',$tmpfile))           { $mime='text/plain'; $imgmime='php.png'; $srclang='php';  $famime='file-code-o'; }
7178
-	if (preg_match('/\.phtml$/i',$tmpfile))                    { $mime='text/plain'; $imgmime='php.png'; $srclang='php';  $famime='file-code-o'; }
7179
-	if (preg_match('/\.(pl|pm)$/i',$tmpfile))                  { $mime='text/plain'; $imgmime='pl.png'; $srclang='perl';  $famime='file-code-o'; }
7180
-	if (preg_match('/\.sql$/i',$tmpfile))                      { $mime='text/plain'; $imgmime='text.png'; $srclang='sql';  $famime='file-code-o'; }
7181
-	if (preg_match('/\.js$/i',$tmpfile))                       { $mime='text/x-javascript'; $imgmime='jscript.png'; $srclang='js';  $famime='file-code-o'; }
7172
+	if (preg_match('/\.bas$/i', $tmpfile)) { $mime = 'text/plain'; $imgmime = 'text.png'; $srclang = 'bas'; $famime = 'file-code-o'; }
7173
+	if (preg_match('/\.(c)$/i', $tmpfile)) { $mime = 'text/plain'; $imgmime = 'text.png'; $srclang = 'c'; $famime = 'file-code-o'; }
7174
+	if (preg_match('/\.(cpp)$/i', $tmpfile)) { $mime = 'text/plain'; $imgmime = 'text.png'; $srclang = 'cpp'; $famime = 'file-code-o'; }
7175
+	if (preg_match('/\.(h)$/i', $tmpfile)) { $mime = 'text/plain'; $imgmime = 'text.png'; $srclang = 'h'; $famime = 'file-code-o'; }
7176
+	if (preg_match('/\.(java|jsp)$/i', $tmpfile)) { $mime = 'text/plain'; $imgmime = 'text.png'; $srclang = 'java'; $famime = 'file-code-o'; }
7177
+	if (preg_match('/\.php([0-9]{1})?$/i', $tmpfile)) { $mime = 'text/plain'; $imgmime = 'php.png'; $srclang = 'php'; $famime = 'file-code-o'; }
7178
+	if (preg_match('/\.phtml$/i', $tmpfile)) { $mime = 'text/plain'; $imgmime = 'php.png'; $srclang = 'php'; $famime = 'file-code-o'; }
7179
+	if (preg_match('/\.(pl|pm)$/i', $tmpfile)) { $mime = 'text/plain'; $imgmime = 'pl.png'; $srclang = 'perl'; $famime = 'file-code-o'; }
7180
+	if (preg_match('/\.sql$/i', $tmpfile)) { $mime = 'text/plain'; $imgmime = 'text.png'; $srclang = 'sql'; $famime = 'file-code-o'; }
7181
+	if (preg_match('/\.js$/i', $tmpfile)) { $mime = 'text/x-javascript'; $imgmime = 'jscript.png'; $srclang = 'js'; $famime = 'file-code-o'; }
7182 7182
 	// Open office
7183
-	if (preg_match('/\.odp$/i',$tmpfile))                      { $mime='application/vnd.oasis.opendocument.presentation'; $imgmime='ooffice.png'; $famime='file-powerpoint-o'; }
7184
-	if (preg_match('/\.ods$/i',$tmpfile))                      { $mime='application/vnd.oasis.opendocument.spreadsheet';  $imgmime='ooffice.png'; $famime='file-excel-o'; }
7185
-	if (preg_match('/\.odt$/i',$tmpfile))                      { $mime='application/vnd.oasis.opendocument.text';         $imgmime='ooffice.png'; $famime='file-word-o'; }
7183
+	if (preg_match('/\.odp$/i', $tmpfile)) { $mime = 'application/vnd.oasis.opendocument.presentation'; $imgmime = 'ooffice.png'; $famime = 'file-powerpoint-o'; }
7184
+	if (preg_match('/\.ods$/i', $tmpfile)) { $mime = 'application/vnd.oasis.opendocument.spreadsheet'; $imgmime = 'ooffice.png'; $famime = 'file-excel-o'; }
7185
+	if (preg_match('/\.odt$/i', $tmpfile)) { $mime = 'application/vnd.oasis.opendocument.text'; $imgmime = 'ooffice.png'; $famime = 'file-word-o'; }
7186 7186
 	// MS Office
7187
-	if (preg_match('/\.mdb$/i',$tmpfile))					   { $mime='application/msaccess'; $imgmime='mdb.png'; $famime='file-o'; }
7188
-	if (preg_match('/\.doc(x|m)?$/i',$tmpfile))				   { $mime='application/msword'; $imgmime='doc.png'; $famime='file-word-o'; }
7189
-	if (preg_match('/\.dot(x|m)?$/i',$tmpfile))				   { $mime='application/msword'; $imgmime='doc.png'; $famime='file-word-o'; }
7190
-	if (preg_match('/\.xlt(x)?$/i',$tmpfile))				   { $mime='application/vnd.ms-excel'; $imgmime='xls.png'; $famime='file-excel-o'; }
7191
-	if (preg_match('/\.xla(m)?$/i',$tmpfile))				   { $mime='application/vnd.ms-excel'; $imgmime='xls.png'; $famime='file-excel-o'; }
7192
-	if (preg_match('/\.xls$/i',$tmpfile))			           { $mime='application/vnd.ms-excel'; $imgmime='xls.png'; $famime='file-excel-o'; }
7193
-	if (preg_match('/\.xls(b|m|x)$/i',$tmpfile))			   { $mime='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; $imgmime='xls.png'; $famime='file-excel-o'; }
7194
-	if (preg_match('/\.pps(m|x)?$/i',$tmpfile))				   { $mime='application/vnd.ms-powerpoint'; $imgmime='ppt.png'; $famime='file-powerpoint-o'; }
7195
-	if (preg_match('/\.ppt(m|x)?$/i',$tmpfile))				   { $mime='application/x-mspowerpoint'; $imgmime='ppt.png'; $famime='file-powerpoint-o'; }
7187
+	if (preg_match('/\.mdb$/i', $tmpfile)) { $mime = 'application/msaccess'; $imgmime = 'mdb.png'; $famime = 'file-o'; }
7188
+	if (preg_match('/\.doc(x|m)?$/i', $tmpfile)) { $mime = 'application/msword'; $imgmime = 'doc.png'; $famime = 'file-word-o'; }
7189
+	if (preg_match('/\.dot(x|m)?$/i', $tmpfile)) { $mime = 'application/msword'; $imgmime = 'doc.png'; $famime = 'file-word-o'; }
7190
+	if (preg_match('/\.xlt(x)?$/i', $tmpfile)) { $mime = 'application/vnd.ms-excel'; $imgmime = 'xls.png'; $famime = 'file-excel-o'; }
7191
+	if (preg_match('/\.xla(m)?$/i', $tmpfile)) { $mime = 'application/vnd.ms-excel'; $imgmime = 'xls.png'; $famime = 'file-excel-o'; }
7192
+	if (preg_match('/\.xls$/i', $tmpfile)) { $mime = 'application/vnd.ms-excel'; $imgmime = 'xls.png'; $famime = 'file-excel-o'; }
7193
+	if (preg_match('/\.xls(b|m|x)$/i', $tmpfile)) { $mime = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; $imgmime = 'xls.png'; $famime = 'file-excel-o'; }
7194
+	if (preg_match('/\.pps(m|x)?$/i', $tmpfile)) { $mime = 'application/vnd.ms-powerpoint'; $imgmime = 'ppt.png'; $famime = 'file-powerpoint-o'; }
7195
+	if (preg_match('/\.ppt(m|x)?$/i', $tmpfile)) { $mime = 'application/x-mspowerpoint'; $imgmime = 'ppt.png'; $famime = 'file-powerpoint-o'; }
7196 7196
 	// Other
7197
-	if (preg_match('/\.pdf$/i',$tmpfile))                      { $mime='application/pdf'; $imgmime='pdf.png'; $famime='file-pdf-o'; }
7197
+	if (preg_match('/\.pdf$/i', $tmpfile)) { $mime = 'application/pdf'; $imgmime = 'pdf.png'; $famime = 'file-pdf-o'; }
7198 7198
 	// Scripts
7199
-	if (preg_match('/\.bat$/i',$tmpfile))                      { $mime='text/x-bat';  $imgmime='script.png'; $srclang='dos'; $famime='file-code-o'; }
7200
-	if (preg_match('/\.sh$/i',$tmpfile))                       { $mime='text/x-sh';   $imgmime='script.png'; $srclang='bash'; $famime='file-code-o'; }
7201
-	if (preg_match('/\.ksh$/i',$tmpfile))                      { $mime='text/x-ksh';  $imgmime='script.png'; $srclang='bash'; $famime='file-code-o'; }
7202
-	if (preg_match('/\.bash$/i',$tmpfile))                     { $mime='text/x-bash'; $imgmime='script.png'; $srclang='bash'; $famime='file-code-o'; }
7199
+	if (preg_match('/\.bat$/i', $tmpfile)) { $mime = 'text/x-bat'; $imgmime = 'script.png'; $srclang = 'dos'; $famime = 'file-code-o'; }
7200
+	if (preg_match('/\.sh$/i', $tmpfile)) { $mime = 'text/x-sh'; $imgmime = 'script.png'; $srclang = 'bash'; $famime = 'file-code-o'; }
7201
+	if (preg_match('/\.ksh$/i', $tmpfile)) { $mime = 'text/x-ksh'; $imgmime = 'script.png'; $srclang = 'bash'; $famime = 'file-code-o'; }
7202
+	if (preg_match('/\.bash$/i', $tmpfile)) { $mime = 'text/x-bash'; $imgmime = 'script.png'; $srclang = 'bash'; $famime = 'file-code-o'; }
7203 7203
 	// Images
7204
-	if (preg_match('/\.ico$/i',$tmpfile))                      { $mime='image/x-icon'; $imgmime='image.png'; $famime='file-image-o'; }
7205
-	if (preg_match('/\.(jpg|jpeg)$/i',$tmpfile))			   { $mime='image/jpeg';   $imgmime='image.png'; $famime='file-image-o'; }
7206
-	if (preg_match('/\.png$/i',$tmpfile))					   { $mime='image/png';    $imgmime='image.png'; $famime='file-image-o'; }
7207
-	if (preg_match('/\.gif$/i',$tmpfile))					   { $mime='image/gif';    $imgmime='image.png'; $famime='file-image-o'; }
7208
-	if (preg_match('/\.bmp$/i',$tmpfile))					   { $mime='image/bmp';    $imgmime='image.png'; $famime='file-image-o'; }
7209
-	if (preg_match('/\.(tif|tiff)$/i',$tmpfile))			   { $mime='image/tiff';   $imgmime='image.png'; $famime='file-image-o'; }
7210
-	if (preg_match('/\.svg$/i',$tmpfile))					   { $mime='image/svg+xml';$imgmime='image.png'; $famime='file-image-o'; }
7204
+	if (preg_match('/\.ico$/i', $tmpfile)) { $mime = 'image/x-icon'; $imgmime = 'image.png'; $famime = 'file-image-o'; }
7205
+	if (preg_match('/\.(jpg|jpeg)$/i', $tmpfile)) { $mime = 'image/jpeg'; $imgmime = 'image.png'; $famime = 'file-image-o'; }
7206
+	if (preg_match('/\.png$/i', $tmpfile)) { $mime = 'image/png'; $imgmime = 'image.png'; $famime = 'file-image-o'; }
7207
+	if (preg_match('/\.gif$/i', $tmpfile)) { $mime = 'image/gif'; $imgmime = 'image.png'; $famime = 'file-image-o'; }
7208
+	if (preg_match('/\.bmp$/i', $tmpfile)) { $mime = 'image/bmp'; $imgmime = 'image.png'; $famime = 'file-image-o'; }
7209
+	if (preg_match('/\.(tif|tiff)$/i', $tmpfile)) { $mime = 'image/tiff'; $imgmime = 'image.png'; $famime = 'file-image-o'; }
7210
+	if (preg_match('/\.svg$/i', $tmpfile)) { $mime = 'image/svg+xml'; $imgmime = 'image.png'; $famime = 'file-image-o'; }
7211 7211
 	// Calendar
7212
-	if (preg_match('/\.vcs$/i',$tmpfile))					   { $mime='text/calendar'; $imgmime='other.png'; $famime='file-text-o'; }
7213
-	if (preg_match('/\.ics$/i',$tmpfile))					   { $mime='text/calendar'; $imgmime='other.png'; $famime='file-text-o'; }
7212
+	if (preg_match('/\.vcs$/i', $tmpfile)) { $mime = 'text/calendar'; $imgmime = 'other.png'; $famime = 'file-text-o'; }
7213
+	if (preg_match('/\.ics$/i', $tmpfile)) { $mime = 'text/calendar'; $imgmime = 'other.png'; $famime = 'file-text-o'; }
7214 7214
 	// Other
7215
-	if (preg_match('/\.torrent$/i',$tmpfile))				   { $mime='application/x-bittorrent'; $imgmime='other.png'; $famime='file-o'; }
7215
+	if (preg_match('/\.torrent$/i', $tmpfile)) { $mime = 'application/x-bittorrent'; $imgmime = 'other.png'; $famime = 'file-o'; }
7216 7216
 	// Audio
7217
-	if (preg_match('/\.(mp3|ogg|au|wav|wma|mid)$/i',$tmpfile)) { $mime='audio'; $imgmime='audio.png'; $famime='file-audio-o'; }
7217
+	if (preg_match('/\.(mp3|ogg|au|wav|wma|mid)$/i', $tmpfile)) { $mime = 'audio'; $imgmime = 'audio.png'; $famime = 'file-audio-o'; }
7218 7218
 	// Video
7219
-	if (preg_match('/\.ogv$/i',$tmpfile))                      { $mime='video/ogg';       $imgmime='video.png'; $famime='file-video-o'; }
7220
-	if (preg_match('/\.webm$/i',$tmpfile))                     { $mime='video/webm';      $imgmime='video.png'; $famime='file-video-o'; }
7221
-	if (preg_match('/\.avi$/i',$tmpfile))                      { $mime='video/x-msvideo'; $imgmime='video.png'; $famime='file-video-o'; }
7222
-	if (preg_match('/\.divx$/i',$tmpfile))                     { $mime='video/divx';      $imgmime='video.png'; $famime='file-video-o'; }
7223
-	if (preg_match('/\.xvid$/i',$tmpfile))                     { $mime='video/xvid';      $imgmime='video.png'; $famime='file-video-o'; }
7224
-	if (preg_match('/\.(wmv|mpg|mpeg)$/i',$tmpfile))           { $mime='video';           $imgmime='video.png'; $famime='file-video-o'; }
7219
+	if (preg_match('/\.ogv$/i', $tmpfile)) { $mime = 'video/ogg'; $imgmime = 'video.png'; $famime = 'file-video-o'; }
7220
+	if (preg_match('/\.webm$/i', $tmpfile)) { $mime = 'video/webm'; $imgmime = 'video.png'; $famime = 'file-video-o'; }
7221
+	if (preg_match('/\.avi$/i', $tmpfile)) { $mime = 'video/x-msvideo'; $imgmime = 'video.png'; $famime = 'file-video-o'; }
7222
+	if (preg_match('/\.divx$/i', $tmpfile)) { $mime = 'video/divx'; $imgmime = 'video.png'; $famime = 'file-video-o'; }
7223
+	if (preg_match('/\.xvid$/i', $tmpfile)) { $mime = 'video/xvid'; $imgmime = 'video.png'; $famime = 'file-video-o'; }
7224
+	if (preg_match('/\.(wmv|mpg|mpeg)$/i', $tmpfile)) { $mime = 'video'; $imgmime = 'video.png'; $famime = 'file-video-o'; }
7225 7225
 	// Archive
7226
-	if (preg_match('/\.(zip|rar|gz|tgz|z|cab|bz2|7z|tar|lzh)$/i',$tmpfile))   { $mime='archive'; $imgmime='archive.png'; $famime='file-archive-o'; }    // application/xxx where zzz is zip, ...
7226
+	if (preg_match('/\.(zip|rar|gz|tgz|z|cab|bz2|7z|tar|lzh)$/i', $tmpfile)) { $mime = 'archive'; $imgmime = 'archive.png'; $famime = 'file-archive-o'; }    // application/xxx where zzz is zip, ...
7227 7227
 	// Exe
7228
-	if (preg_match('/\.(exe|com)$/i',$tmpfile))                { $mime='application/octet-stream'; $imgmime='other.png'; $famime='file-o'; }
7228
+	if (preg_match('/\.(exe|com)$/i', $tmpfile)) { $mime = 'application/octet-stream'; $imgmime = 'other.png'; $famime = 'file-o'; }
7229 7229
 	// Lib
7230
-	if (preg_match('/\.(dll|lib|o|so|a)$/i',$tmpfile))         { $mime='library'; $imgmime='library.png'; $famime='file-o'; }
7230
+	if (preg_match('/\.(dll|lib|o|so|a)$/i', $tmpfile)) { $mime = 'library'; $imgmime = 'library.png'; $famime = 'file-o'; }
7231 7231
 	// Err
7232
-	if (preg_match('/\.err$/i',$tmpfile))                      { $mime='error'; $imgmime='error.png'; $famime='file-text-o'; }
7232
+	if (preg_match('/\.err$/i', $tmpfile)) { $mime = 'error'; $imgmime = 'error.png'; $famime = 'file-text-o'; }
7233 7233
 
7234 7234
 	// Return string
7235 7235
 	if ($mode == 1)
7236 7236
 	{
7237
-		$tmp=explode('/',$mime);
7238
-		return (! empty($tmp[1])?$tmp[1]:$tmp[0]);
7237
+		$tmp = explode('/', $mime);
7238
+		return (!empty($tmp[1]) ? $tmp[1] : $tmp[0]);
7239 7239
 	}
7240 7240
 	if ($mode == 2)
7241 7241
 	{
@@ -7261,15 +7261,15 @@  discard block
 block discarded – undo
7261 7261
  * @param bool		$checkentity	add filter on entity
7262 7262
  * @param string	$rowidfield		name of the column rowid
7263 7263
  */
7264
-function getDictvalue($tablename, $field, $id, $checkentity=false, $rowidfield='rowid')
7264
+function getDictvalue($tablename, $field, $id, $checkentity = false, $rowidfield = 'rowid')
7265 7265
 {
7266
-	global $dictvalues,$db,$langs;
7266
+	global $dictvalues, $db, $langs;
7267 7267
 
7268 7268
 	if (!isset($dictvalues[$tablename]))
7269 7269
 	{
7270 7270
 		$dictvalues[$tablename] = array();
7271 7271
 		$sql = 'SELECT * FROM '.$tablename.' WHERE 1';
7272
-		if ($checkentity) $sql.= ' entity IN (0,'.getEntity('').')';
7272
+		if ($checkentity) $sql .= ' entity IN (0,'.getEntity('').')';
7273 7273
 
7274 7274
 		$resql = $db->query($sql);
7275 7275
 		if ($resql)
@@ -7305,7 +7305,7 @@  discard block
 block discarded – undo
7305 7305
 	if (!empty($stringcolor))
7306 7306
 	{
7307 7307
 		$res = 0;
7308
-		$tmp=explode(',', $stringcolor);
7308
+		$tmp = explode(',', $stringcolor);
7309 7309
 		if (count($tmp) > 1)   // This is a comma RGB ('255','255','255')
7310 7310
 		{
7311 7311
 			$r = $tmp[0];
@@ -7314,14 +7314,14 @@  discard block
 block discarded – undo
7314 7314
 		}
7315 7315
 		else
7316 7316
 		{
7317
-			$hexr=$stringcolor[0].$stringcolor[1];
7318
-			$hexg=$stringcolor[2].$stringcolor[3];
7319
-			$hexb=$stringcolor[4].$stringcolor[5];
7317
+			$hexr = $stringcolor[0].$stringcolor[1];
7318
+			$hexg = $stringcolor[2].$stringcolor[3];
7319
+			$hexb = $stringcolor[4].$stringcolor[5];
7320 7320
 			$r = hexdec($hexr);
7321 7321
 			$g = hexdec($hexg);
7322 7322
 			$b = hexdec($hexb);
7323 7323
 		}
7324
-		$bright = (max($r, $g, $b) + min($r, $g, $b)) / 510.0;    // HSL algorithm
7324
+		$bright = (max($r, $g, $b) + min($r, $g, $b)) / 510.0; // HSL algorithm
7325 7325
 		if ($bright > 0.6) $res = 1;
7326 7326
 	}
7327 7327
 	return $res;
@@ -7341,21 +7341,21 @@  discard block
 block discarded – undo
7341 7341
 
7342 7342
 	//print 'type_user='.$type_user.' module='.$menuentry['module'].' enabled='.$menuentry['enabled'].' perms='.$menuentry['perms'];
7343 7343
 	//print 'ok='.in_array($menuentry['module'], $listofmodulesforexternal);
7344
-	if (empty($menuentry['enabled'])) return 0;	// Entry disabled by condition
7344
+	if (empty($menuentry['enabled'])) return 0; // Entry disabled by condition
7345 7345
 	if ($type_user && $menuentry['module'])
7346 7346
 	{
7347
-		$tmploops=explode('|',$menuentry['module']);
7348
-		$found=0;
7349
-		foreach($tmploops as $tmploop)
7347
+		$tmploops = explode('|', $menuentry['module']);
7348
+		$found = 0;
7349
+		foreach ($tmploops as $tmploop)
7350 7350
 		{
7351 7351
 			if (in_array($tmploop, $listofmodulesforexternal)) {
7352 7352
 				$found++; break;
7353 7353
 			}
7354 7354
 		}
7355
-		if (! $found) return 0;	// Entry is for menus all excluded to external users
7355
+		if (!$found) return 0; // Entry is for menus all excluded to external users
7356 7356
 	}
7357
-	if (! $menuentry['perms'] && $type_user) return 0; 											// No permissions and user is external
7358
-	if (! $menuentry['perms'] && ! empty($conf->global->MAIN_MENU_HIDE_UNAUTHORIZED))	return 0;	// No permissions and option to hide when not allowed, even for internal user, is on
7359
-	if (! $menuentry['perms']) return 2;															// No permissions and user is external
7357
+	if (!$menuentry['perms'] && $type_user) return 0; // No permissions and user is external
7358
+	if (!$menuentry['perms'] && !empty($conf->global->MAIN_MENU_HIDE_UNAUTHORIZED))	return 0; // No permissions and option to hide when not allowed, even for internal user, is on
7359
+	if (!$menuentry['perms']) return 2; // No permissions and user is external
7360 7360
 	return 1;
7361 7361
 }
Please login to merge, or discard this patch.
Braces   +1732 added lines, -901 removed lines patch added patch discarded remove patch
@@ -74,7 +74,9 @@  discard block
 block discarded – undo
74 74
 		if ($found) return $result;
75 75
 	}*/
76 76
 
77
-	if (isset($class::$member)) return $class::$member;
77
+	if (isset($class::$member)) {
78
+		return $class::$member;
79
+	}
78 80
 	dol_print_error('','Try to get a static member "'.$member.'" in class "'.$class.'" that does not exists or is not static.');
79 81
 	return null;
80 82
 }
@@ -122,19 +124,26 @@  discard block
 block discarded – undo
122 124
 	global $conf, $mc;
123 125
 
124 126
 	// For backward compatibilty
125
-	if ($element == 'actioncomm') $element='agenda';
126
-	if ($element == 'fichinter')  $element='intervention';
127
-	if ($element == 'categorie')  $element='category';
127
+	if ($element == 'actioncomm') {
128
+		$element='agenda';
129
+	}
130
+	if ($element == 'fichinter') {
131
+		$element='intervention';
132
+	}
133
+	if ($element == 'categorie') {
134
+		$element='category';
135
+	}
128 136
 
129 137
 	if (is_object($mc))
130 138
 	{
131 139
 		return $mc->getEntity($element, $shared, $forceentity);
132
-	}
133
-	else
140
+	} else
134 141
 	{
135 142
 		$out='';
136 143
 		$addzero = array('user', 'usergroup', 'c_email_templates', 'email_template', 'default_values');
137
-		if (in_array($element, $addzero)) $out.= '0,';
144
+		if (in_array($element, $addzero)) {
145
+			$out.= '0,';
146
+		}
138 147
 		$out.= $conf->entity;
139 148
 		return $out;
140 149
 	}
@@ -194,20 +203,12 @@  discard block
 block discarded – undo
194 203
 	}
195 204
 
196 205
 	// OS
197
-	if (preg_match('/linux/i', $user_agent))			{ $os='linux'; }
198
-	elseif (preg_match('/macintosh/i', $user_agent))	{ $os='macintosh'; }
199
-	elseif (preg_match('/windows/i', $user_agent))		{ $os='windows'; }
206
+	if (preg_match('/linux/i', $user_agent))			{ $os='linux'; } elseif (preg_match('/macintosh/i', $user_agent))	{ $os='macintosh'; } elseif (preg_match('/windows/i', $user_agent))		{ $os='windows'; }
200 207
 
201 208
 	// Name
202
-	if (preg_match('/firefox(\/|\s)([\d\.]*)/i', $user_agent, $reg))      { $name='firefox';   $version=$reg[2]; }
203
-	elseif (preg_match('/edge(\/|\s)([\d\.]*)/i', $user_agent, $reg))     { $name='edge';      $version=$reg[2]; }
204
-	elseif (preg_match('/chrome(\/|\s)([\d\.]+)/i', $user_agent, $reg))   { $name='chrome';    $version=$reg[2]; }    // we can have 'chrome (Mozilla...) chrome x.y' in one string
205
-	elseif (preg_match('/chrome/i', $user_agent, $reg))                   { $name='chrome'; }
206
-	elseif (preg_match('/iceweasel/i', $user_agent))                      { $name='iceweasel'; }
207
-	elseif (preg_match('/epiphany/i', $user_agent))                       { $name='epiphany';  }
208
-	elseif (preg_match('/safari(\/|\s)([\d\.]*)/i', $user_agent, $reg))   { $name='safari';    $version=$reg[2]; }	// Safari is often present in string for mobile but its not.
209
-	elseif (preg_match('/opera(\/|\s)([\d\.]*)/i', $user_agent, $reg))    { $name='opera';     $version=$reg[2]; }
210
-	elseif (preg_match('/(MSIE\s([0-9]+\.[0-9]))|.*(Trident\/[0-9]+.[0-9];.*rv:([0-9]+\.[0-9]+))/i', $user_agent, $reg))  { $name='ie'; $version=end($reg); }    // MS products at end
209
+	if (preg_match('/firefox(\/|\s)([\d\.]*)/i', $user_agent, $reg))      { $name='firefox';   $version=$reg[2]; } elseif (preg_match('/edge(\/|\s)([\d\.]*)/i', $user_agent, $reg))     { $name='edge';      $version=$reg[2]; } elseif (preg_match('/chrome(\/|\s)([\d\.]+)/i', $user_agent, $reg))   { $name='chrome';    $version=$reg[2]; }    // we can have 'chrome (Mozilla...) chrome x.y' in one string
210
+	elseif (preg_match('/chrome/i', $user_agent, $reg))                   { $name='chrome'; } elseif (preg_match('/iceweasel/i', $user_agent))                      { $name='iceweasel'; } elseif (preg_match('/epiphany/i', $user_agent))                       { $name='epiphany';  } elseif (preg_match('/safari(\/|\s)([\d\.]*)/i', $user_agent, $reg))   { $name='safari';    $version=$reg[2]; }	// Safari is often present in string for mobile but its not.
211
+	elseif (preg_match('/opera(\/|\s)([\d\.]*)/i', $user_agent, $reg))    { $name='opera';     $version=$reg[2]; } elseif (preg_match('/(MSIE\s([0-9]+\.[0-9]))|.*(Trident\/[0-9]+.[0-9];.*rv:([0-9]+\.[0-9]+))/i', $user_agent, $reg))  { $name='ie'; $version=end($reg); }    // MS products at end
211 212
 	elseif (preg_match('/(Windows NT\s([0-9]+\.[0-9])).*(Trident\/[0-9]+.[0-9];.*rv:([0-9]+\.[0-9]+))/i', $user_agent, $reg))  { $name='ie'; $version=end($reg); }    // MS products at end
212 213
 	elseif (preg_match('/l(i|y)n(x|ks)(\(|\/|\s)*([\d\.]+)/i', $user_agent, $reg)) { $name='lynxlinks'; $version=$reg[4]; }
213 214
 
@@ -280,7 +281,9 @@  discard block
 block discarded – undo
280 281
 {
281 282
 	global $mysoc,$user,$conf;
282 283
 
283
-	if (empty($paramname)) return 'BadFirstParameterForGETPOST';
284
+	if (empty($paramname)) {
285
+		return 'BadFirstParameterForGETPOST';
286
+	}
284 287
 	if (empty($check))
285 288
 	{
286 289
 		dol_syslog("Deprecated use of GETPOST, called with 1st param = ".$paramname." and 2nd param is '', when calling page ".$_SERVER["PHP_SELF"], LOG_WARNING);
@@ -288,19 +291,28 @@  discard block
 block discarded – undo
288 291
 		//var_dump(debug_backtrace()[0]);
289 292
 	}
290 293
 
291
-	if (empty($method)) $out = isset($_GET[$paramname])?$_GET[$paramname]:(isset($_POST[$paramname])?$_POST[$paramname]:'');
292
-	elseif ($method==1) $out = isset($_GET[$paramname])?$_GET[$paramname]:'';
293
-	elseif ($method==2) $out = isset($_POST[$paramname])?$_POST[$paramname]:'';
294
-	elseif ($method==3) $out = isset($_POST[$paramname])?$_POST[$paramname]:(isset($_GET[$paramname])?$_GET[$paramname]:'');
295
-	elseif ($method==4) $out = isset($_POST[$paramname])?$_POST[$paramname]:(isset($_GET[$paramname])?$_GET[$paramname]:(isset($_COOKIE[$paramname])?$_COOKIE[$paramname]:''));
296
-	else return 'BadThirdParameterForGETPOST';
294
+	if (empty($method)) {
295
+		$out = isset($_GET[$paramname])?$_GET[$paramname]:(isset($_POST[$paramname])?$_POST[$paramname]:'');
296
+	} elseif ($method==1) {
297
+		$out = isset($_GET[$paramname])?$_GET[$paramname]:'';
298
+	} elseif ($method==2) {
299
+		$out = isset($_POST[$paramname])?$_POST[$paramname]:'';
300
+	} elseif ($method==3) {
301
+		$out = isset($_POST[$paramname])?$_POST[$paramname]:(isset($_GET[$paramname])?$_GET[$paramname]:'');
302
+	} elseif ($method==4) {
303
+		$out = isset($_POST[$paramname])?$_POST[$paramname]:(isset($_GET[$paramname])?$_GET[$paramname]:(isset($_COOKIE[$paramname])?$_COOKIE[$paramname]:''));
304
+	} else {
305
+		return 'BadThirdParameterForGETPOST';
306
+	}
297 307
 
298 308
 	if (empty($method) || $method == 3 || $method == 4)
299 309
 	{
300 310
 
301 311
 		$relativepathstring = $_SERVER["PHP_SELF"];
302 312
 		// Clean $relativepathstring
303
-		if (constant('DOL_URL_ROOT')) $relativepathstring = preg_replace('/^'.preg_quote(constant('DOL_URL_ROOT'),'/').'/', '', $relativepathstring);
313
+		if (constant('DOL_URL_ROOT')) {
314
+			$relativepathstring = preg_replace('/^'.preg_quote(constant('DOL_URL_ROOT'),'/').'/', '', $relativepathstring);
315
+		}
304 316
 		$relativepathstring = preg_replace('/^\//', '', $relativepathstring);
305 317
 		$relativepathstring = preg_replace('/^custom\//', '', $relativepathstring);
306 318
 		//var_dump($relativepathstring);
@@ -308,9 +320,11 @@  discard block
 block discarded – undo
308 320
 
309 321
 		// Code for search criteria persistence.
310 322
 		// Retrieve values if restore_lastsearch_values is set and there is saved values
311
-		if (! empty($_GET['restore_lastsearch_values']) && ! empty($_SESSION['lastsearch_values_'.$relativepathstring]))        // Keep $_GET here
323
+		if (! empty($_GET['restore_lastsearch_values']) && ! empty($_SESSION['lastsearch_values_'.$relativepathstring])) {
324
+			// Keep $_GET here
312 325
 		{
313 326
 			$tmp=json_decode($_SESSION['lastsearch_values_'.$relativepathstring], true);
327
+		}
314 328
 			if (is_array($tmp))
315 329
 			{
316 330
 				foreach($tmp as $key => $val)
@@ -324,12 +338,14 @@  discard block
 block discarded – undo
324 338
 			}
325 339
 		}
326 340
 		// Else, retreive default values if we are not doing a sort
327
-		elseif (! isset($_GET['sortfield']))	// If we did a click on a field to sort, we do no apply default values. Same if option MAIN_ENABLE_DEFAULT_VALUES is not set
341
+		elseif (! isset($_GET['sortfield'])) {
342
+			// If we did a click on a field to sort, we do no apply default values. Same if option MAIN_ENABLE_DEFAULT_VALUES is not set
328 343
 		{
329 344
 			if (! empty($_GET['action']) && $_GET['action'] == 'create' && ! isset($_GET[$paramname]) && ! isset($_POST[$paramname]))
330 345
 			{
331 346
 				// Search default value from $object->field
332 347
 				global $object;
348
+		}
333 349
 				if (is_object($object) && isset($object->fields[$paramname]['default']))
334 350
 				{
335 351
 					$out = $object->fields[$paramname]['default'];
@@ -340,13 +356,15 @@  discard block
 block discarded – undo
340 356
 				if (! empty($_GET['action']) && $_GET['action'] == 'create' && ! isset($_GET[$paramname]) && ! isset($_POST[$paramname]))
341 357
 				{
342 358
 					// Now search in setup to overwrite default values
343
-					if (! empty($user->default_values))		// $user->default_values defined from menu 'Setup - Default values'
359
+					if (! empty($user->default_values)) {
360
+						// $user->default_values defined from menu 'Setup - Default values'
344 361
 					{
345 362
 						if (isset($user->default_values[$relativepathstring]['createform']))
346 363
 						{
347 364
 							foreach($user->default_values[$relativepathstring]['createform'] as $defkey => $defval)
348 365
 							{
349 366
 								$qualified = 0;
367
+					}
350 368
 								if ($defkey != '_noquery_')
351 369
 								{
352 370
 									$tmpqueryarraytohave=explode('&', $defkey);
@@ -354,12 +372,17 @@  discard block
 block discarded – undo
354 372
 									$foundintru=0;
355 373
 									foreach($tmpqueryarraytohave as $tmpquerytohave)
356 374
 									{
357
-										if (! in_array($tmpquerytohave, $tmpqueryarraywehave)) $foundintru=1;
375
+										if (! in_array($tmpquerytohave, $tmpqueryarraywehave)) {
376
+											$foundintru=1;
377
+										}
378
+									}
379
+									if (! $foundintru) {
380
+										$qualified=1;
358 381
 									}
359
-									if (! $foundintru) $qualified=1;
360 382
 									//var_dump($defkey.'-'.$qualified);
383
+								} else {
384
+									$qualified = 1;
361 385
 								}
362
-								else $qualified = 1;
363 386
 
364 387
 								if ($qualified)
365 388
 								{
@@ -378,7 +401,8 @@  discard block
 block discarded – undo
378 401
 				//elseif (preg_match('/list.php$/', $_SERVER["PHP_SELF"]) && ! empty($paramname) && ! isset($_GET[$paramname]) && ! isset($_POST[$paramname]))
379 402
 				elseif (! empty($paramname) && ! isset($_GET[$paramname]) && ! isset($_POST[$paramname]))
380 403
 				{
381
-					if (! empty($user->default_values))		// $user->default_values defined from menu 'Setup - Default values'
404
+					if (! empty($user->default_values)) {
405
+						// $user->default_values defined from menu 'Setup - Default values'
382 406
 					{
383 407
 						//var_dump($user->default_values[$relativepathstring]);
384 408
 						if ($paramname == 'sortfield' || $paramname == 'sortorder')			// Sorted on which fields ? ASC or DESC ?
@@ -388,6 +412,7 @@  discard block
 block discarded – undo
388 412
 								foreach($user->default_values[$relativepathstring]['sortorder'] as $defkey => $defval)
389 413
 								{
390 414
 									$qualified = 0;
415
+					}
391 416
 									if ($defkey != '_noquery_')
392 417
 									{
393 418
 										$tmpqueryarraytohave=explode('&', $defkey);
@@ -395,19 +420,26 @@  discard block
 block discarded – undo
395 420
 										$foundintru=0;
396 421
 										foreach($tmpqueryarraytohave as $tmpquerytohave)
397 422
 										{
398
-											if (! in_array($tmpquerytohave, $tmpqueryarraywehave)) $foundintru=1;
423
+											if (! in_array($tmpquerytohave, $tmpqueryarraywehave)) {
424
+												$foundintru=1;
425
+											}
426
+										}
427
+										if (! $foundintru) {
428
+											$qualified=1;
399 429
 										}
400
-										if (! $foundintru) $qualified=1;
401 430
 										//var_dump($defkey.'-'.$qualified);
431
+									} else {
432
+										$qualified = 1;
402 433
 									}
403
-									else $qualified = 1;
404 434
 
405 435
 									if ($qualified)
406 436
 									{
407 437
 										$forbidden_chars_to_replace=array(" ","'","/","\\",":","*","?","\"","<",">","|","[","]",";","=");  // we accept _, -, . and ,
408 438
 										foreach($user->default_values[$relativepathstring]['sortorder'][$defkey] as $key => $val)
409 439
 										{
410
-											if ($out) $out.=', ';
440
+											if ($out) {
441
+												$out.=', ';
442
+											}
411 443
 											if ($paramname == 'sortfield')
412 444
 											{
413 445
 												$out.=dol_string_nospecial($key, '', $forbidden_chars_to_replace);
@@ -421,8 +453,7 @@  discard block
 block discarded – undo
421 453
 									}
422 454
 								}
423 455
 							}
424
-						}
425
-						elseif (isset($user->default_values[$relativepathstring]['filters']))
456
+						} elseif (isset($user->default_values[$relativepathstring]['filters']))
426 457
 						{
427 458
 							foreach($user->default_values[$relativepathstring]['filters'] as $defkey => $defval)
428 459
 							{
@@ -434,12 +465,17 @@  discard block
 block discarded – undo
434 465
 									$foundintru=0;
435 466
 									foreach($tmpqueryarraytohave as $tmpquerytohave)
436 467
 									{
437
-										if (! in_array($tmpquerytohave, $tmpqueryarraywehave)) $foundintru=1;
468
+										if (! in_array($tmpquerytohave, $tmpqueryarraywehave)) {
469
+											$foundintru=1;
470
+										}
471
+									}
472
+									if (! $foundintru) {
473
+										$qualified=1;
438 474
 									}
439
-									if (! $foundintru) $qualified=1;
440 475
 									//var_dump($defkey.'-'.$qualified);
476
+								} else {
477
+									$qualified = 1;
441 478
 								}
442
-								else $qualified = 1;
443 479
 
444 480
 								if ($qualified)
445 481
 								{
@@ -451,8 +487,7 @@  discard block
 block discarded – undo
451 487
 											$forbidden_chars_to_replace=array(" ","'","/","\\",":","*","?","\"","<",">","|","[","]",";","=");  // we accept _, -, . and ,
452 488
 											$out = dol_string_nospecial($user->default_values[$relativepathstring]['filters'][$defkey][$paramname], '', $forbidden_chars_to_replace);
453 489
 										}
454
-									}
455
-									else
490
+									} else
456 491
 									{
457 492
 										$forbidden_chars_to_replace=array(" ","'","/","\\",":","*","?","\"","<",">","|","[","]",";","=");  // we accept _, -, . and ,
458 493
 										$out = dol_string_nospecial($user->default_values[$relativepathstring]['filters'][$defkey][$paramname], '', $forbidden_chars_to_replace);
@@ -473,36 +508,29 @@  discard block
 block discarded – undo
473 508
 	if (! is_array($out) && empty($_POST[$paramname]) && empty($noreplace))
474 509
 	{
475 510
 		$maxloop=20; $loopnb=0;    // Protection against infinite loop
476
-		while (preg_match('/__([A-Z0-9]+_?[A-Z0-9]+)__/i', $out, $reg) && ($loopnb < $maxloop))    // Detect '__ABCDEF__' as key 'ABCDEF' and '__ABC_DEF__' as key 'ABC_DEF'. Detection is also correct when 2 vars are side by side.
477
-		{
478
-				$loopnb++; $newout = '';
479
-
480
-				if ($reg[1] == 'DAY')                { $tmp=dol_getdate(dol_now(), true); $newout = $tmp['mday']; }
481
-				elseif ($reg[1] == 'MONTH')          { $tmp=dol_getdate(dol_now(), true); $newout = $tmp['mon'];  }
482
-				elseif ($reg[1] == 'YEAR')           { $tmp=dol_getdate(dol_now(), true); $newout = $tmp['year']; }
483
-				elseif ($reg[1] == 'PREVIOUS_DAY')   { $tmp=dol_getdate(dol_now(), true); $tmp2=dol_get_prev_day($tmp['mday'], $tmp['mon'], $tmp['year']); $newout = $tmp2['day']; }
484
-				elseif ($reg[1] == 'PREVIOUS_MONTH') { $tmp=dol_getdate(dol_now(), true); $tmp2=dol_get_prev_month($tmp['mday'], $tmp['mon'], $tmp['year']); $newout = $tmp2['month']; }
485
-				elseif ($reg[1] == 'PREVIOUS_YEAR')  { $tmp=dol_getdate(dol_now(), true); $newout = ($tmp['year'] - 1); }
486
-				elseif ($reg[1] == 'NEXT_DAY')       { $tmp=dol_getdate(dol_now(), true); $tmp2=dol_get_next_day($tmp['mday'], $tmp['mon'], $tmp['year']); $newout = $tmp2['day']; }
487
-				elseif ($reg[1] == 'NEXT_MONTH')     { $tmp=dol_getdate(dol_now(), true); $tmp2=dol_get_next_month($tmp['mday'], $tmp['mon'], $tmp['year']); $newout = $tmp2['month']; }
488
-				elseif ($reg[1] == 'NEXT_YEAR')      { $tmp=dol_getdate(dol_now(), true); $newout = ($tmp['year'] + 1); }
489
-				elseif ($reg[1] == 'MYCOMPANY_COUNTRY_ID' || $reg[1] == 'MYCOUNTRY_ID' || $reg[1] == 'MYCOUNTRYID')
511
+		while (preg_match('/__([A-Z0-9]+_?[A-Z0-9]+)__/i', $out, $reg) && ($loopnb < $maxloop)) {
512
+			// Detect '__ABCDEF__' as key 'ABCDEF' and '__ABC_DEF__' as key 'ABC_DEF'. Detection is also correct when 2 vars are side by side.
513
+		{
514
+				$loopnb++;
515
+		}
516
+		$newout = '';
517
+
518
+				if ($reg[1] == 'DAY')                { $tmp=dol_getdate(dol_now(), true); $newout = $tmp['mday']; } elseif ($reg[1] == 'MONTH')          { $tmp=dol_getdate(dol_now(), true); $newout = $tmp['mon'];  } elseif ($reg[1] == 'YEAR')           { $tmp=dol_getdate(dol_now(), true); $newout = $tmp['year']; } elseif ($reg[1] == 'PREVIOUS_DAY')   { $tmp=dol_getdate(dol_now(), true); $tmp2=dol_get_prev_day($tmp['mday'], $tmp['mon'], $tmp['year']); $newout = $tmp2['day']; } elseif ($reg[1] == 'PREVIOUS_MONTH') { $tmp=dol_getdate(dol_now(), true); $tmp2=dol_get_prev_month($tmp['mday'], $tmp['mon'], $tmp['year']); $newout = $tmp2['month']; } elseif ($reg[1] == 'PREVIOUS_YEAR')  { $tmp=dol_getdate(dol_now(), true); $newout = ($tmp['year'] - 1); } elseif ($reg[1] == 'NEXT_DAY')       { $tmp=dol_getdate(dol_now(), true); $tmp2=dol_get_next_day($tmp['mday'], $tmp['mon'], $tmp['year']); $newout = $tmp2['day']; } elseif ($reg[1] == 'NEXT_MONTH')     { $tmp=dol_getdate(dol_now(), true); $tmp2=dol_get_next_month($tmp['mday'], $tmp['mon'], $tmp['year']); $newout = $tmp2['month']; } elseif ($reg[1] == 'NEXT_YEAR')      { $tmp=dol_getdate(dol_now(), true); $newout = ($tmp['year'] + 1); } elseif ($reg[1] == 'MYCOMPANY_COUNTRY_ID' || $reg[1] == 'MYCOUNTRY_ID' || $reg[1] == 'MYCOUNTRYID')
490 519
 				{
491 520
 					$newout = $mysoc->country_id;
492
-				}
493
-				elseif ($reg[1] == 'USER_ID' || $reg[1] == 'USERID')
521
+				} elseif ($reg[1] == 'USER_ID' || $reg[1] == 'USERID')
494 522
 				{
495 523
 					$newout = $user->id;
496
-				}
497
-				elseif ($reg[1] == 'USER_SUPERVISOR_ID' || $reg[1] == 'SUPERVISOR_ID' || $reg[1] == 'SUPERVISORID')
524
+				} elseif ($reg[1] == 'USER_SUPERVISOR_ID' || $reg[1] == 'SUPERVISOR_ID' || $reg[1] == 'SUPERVISORID')
498 525
 				{
499 526
 					$newout = $user->fk_user;
500
-				}
501
-				elseif ($reg[1] == 'ENTITY_ID' || $reg[1] == 'ENTITYID')
527
+				} elseif ($reg[1] == 'ENTITY_ID' || $reg[1] == 'ENTITYID')
502 528
 				{
503 529
 					$newout = $conf->entity;
530
+				} else {
531
+					$newout = '';
504 532
 				}
505
-				else $newout = '';     // Key not found, we replace with empty string
533
+				// Key not found, we replace with empty string
506 534
 				//var_dump('__'.$reg[1].'__ -> '.$newout);
507 535
 				$out = preg_replace('/__'.preg_quote($reg[1],'/').'__/', $newout, $out);
508 536
 		}
@@ -517,7 +545,9 @@  discard block
 block discarded – undo
517 545
 			if (! is_numeric($out)) { $out=''; }
518 546
 			break;
519 547
 		case 'intcomma':
520
-			if (preg_match('/[^0-9,-]+/i',$out)) $out='';
548
+			if (preg_match('/[^0-9,-]+/i',$out)) {
549
+				$out='';
550
+			}
521 551
 			break;
522 552
 		case 'alpha':
523 553
 			if (! is_array($out))
@@ -525,8 +555,11 @@  discard block
 block discarded – undo
525 555
 				$out=trim($out);
526 556
 				// '"' is dangerous because param in url can close the href= or src= and add javascript functions.
527 557
 				// '../' is dangerous because it allows dir transversals
528
-				if (preg_match('/"/',$out)) $out='';
529
-				else if (preg_match('/\.\.\//',$out)) $out='';
558
+				if (preg_match('/"/',$out)) {
559
+					$out='';
560
+				} else if (preg_match('/\.\.\//',$out)) {
561
+					$out='';
562
+				}
530 563
 			}
531 564
 			break;
532 565
 		case 'san_alpha':
@@ -536,18 +569,24 @@  discard block
 block discarded – undo
536 569
 			if (! is_array($out))
537 570
 			{
538 571
 				$out=trim($out);
539
-				if (preg_match('/[^a-z]+/i',$out)) $out='';
572
+				if (preg_match('/[^a-z]+/i',$out)) {
573
+					$out='';
574
+				}
540 575
 			}
541 576
 			break;
542 577
 		case 'aZ09':
543 578
 			if (! is_array($out))
544 579
 			{
545 580
 				$out=trim($out);
546
-				if (preg_match('/[^a-z0-9_\-\.]+/i',$out)) $out='';
581
+				if (preg_match('/[^a-z0-9_\-\.]+/i',$out)) {
582
+					$out='';
583
+				}
547 584
 			}
548 585
 			break;
549 586
 		case 'array':
550
-			if (! is_array($out) || empty($out)) $out=array();
587
+			if (! is_array($out) || empty($out)) {
588
+				$out=array();
589
+			}
551 590
 			break;
552 591
 		case 'nohtml':
553 592
 			$out=dol_string_nohtmltag($out, 0);
@@ -558,13 +597,18 @@  discard block
 block discarded – undo
558 597
 				$out=trim($out);
559 598
 				// '"' is dangerous because param in url can close the href= or src= and add javascript functions.
560 599
 				// '../' is dangerous because it allows dir transversals
561
-				if (preg_match('/"/',$out)) $out='';
562
-				else if (preg_match('/\.\.\//',$out)) $out='';
600
+				if (preg_match('/"/',$out)) {
601
+					$out='';
602
+				} else if (preg_match('/\.\.\//',$out)) {
603
+					$out='';
604
+				}
563 605
 				$out=dol_string_nohtmltag($out);
564 606
 			}
565 607
 			break;
566 608
 		case 'custom':
567
-			if (empty($filter)) return 'BadFourthParameterForGETPOST';
609
+			if (empty($filter)) {
610
+				return 'BadFourthParameterForGETPOST';
611
+			}
568 612
 			$out=filter_var($out, $filter, $options);
569 613
 			break;
570 614
 	}
@@ -612,8 +656,11 @@  discard block
 block discarded – undo
612 656
 		// If MAIL_PREFIX_FOR_EMAIL_ID is set and prefix is for email
613 657
 		if ($mode == 'email' && ! empty($conf->global->MAIL_PREFIX_FOR_EMAIL_ID))
614 658
 		{
615
-			if ($conf->global->MAIL_PREFIX_FOR_EMAIL_ID != 'SERVER_NAME') return $conf->global->MAIL_PREFIX_FOR_EMAIL_ID;
616
-			else if (isset($_SERVER["SERVER_NAME"])) return $_SERVER["SERVER_NAME"];
659
+			if ($conf->global->MAIL_PREFIX_FOR_EMAIL_ID != 'SERVER_NAME') {
660
+				return $conf->global->MAIL_PREFIX_FOR_EMAIL_ID;
661
+			} else if (isset($_SERVER["SERVER_NAME"])) {
662
+				return $_SERVER["SERVER_NAME"];
663
+			}
617 664
 		}
618 665
 
619 666
 		if (isset($_SERVER["SERVER_NAME"]) && isset($_SERVER["DOCUMENT_ROOT"]))
@@ -621,8 +668,9 @@  discard block
 block discarded – undo
621 668
 			return dol_hash($_SERVER["SERVER_NAME"].$_SERVER["DOCUMENT_ROOT"].DOL_DOCUMENT_ROOT.DOL_URL_ROOT);
622 669
 			// Use this for a "readable" cookie name
623 670
 			//return dol_sanitizeFileName($_SERVER["SERVER_NAME"].$_SERVER["DOCUMENT_ROOT"].DOL_DOCUMENT_ROOT.DOL_URL_ROOT);
671
+		} else {
672
+			return dol_hash(DOL_DOCUMENT_ROOT.DOL_URL_ROOT);
624 673
 		}
625
-		else return dol_hash(DOL_DOCUMENT_ROOT.DOL_URL_ROOT);
626 674
 	}
627 675
 }
628 676
 
@@ -671,41 +719,57 @@  discard block
 block discarded – undo
671 719
 
672 720
 	$path=preg_replace('/^\//','',$path);
673 721
 
674
-	if (empty($type))	// For a filesystem path
722
+	if (empty($type)) {
723
+		// For a filesystem path
675 724
 	{
676
-		$res = DOL_DOCUMENT_ROOT.'/'.$path;		// Standard default path
677
-		foreach ($conf->file->dol_document_root as $key => $dirroot)	// ex: array(["main"]=>"/home/main/htdocs", ["alt0"]=>"/home/dirmod/htdocs", ...)
725
+		$res = DOL_DOCUMENT_ROOT.'/'.$path;
726
+	}
727
+	// Standard default path
728
+		foreach ($conf->file->dol_document_root as $key => $dirroot) {
729
+			// ex: array(["main"]=>"/home/main/htdocs", ["alt0"]=>"/home/dirmod/htdocs", ...)
678 730
 		{
679 731
 			if ($key == 'main') continue;
732
+		}
680 733
 			if (file_exists($dirroot.'/'.$path))
681 734
 			{
682 735
 				$res=$dirroot.'/'.$path;
683 736
 				return $res;
684 737
 			}
685 738
 		}
686
-		if ($returnemptyifnotfound)								// Not found into alternate dir
739
+		if ($returnemptyifnotfound) {
740
+			// Not found into alternate dir
687 741
 		{
688 742
 			if ($returnemptyifnotfound == 1 || ! file_exists($res)) return '';
689 743
 		}
690
-	}
691
-	else				// For an url path
744
+		}
745
+	} else				// For an url path
692 746
 	{
693 747
 		// We try to get local path of file on filesystem from url
694 748
 		// Note that trying to know if a file on disk exist by forging path on disk from url
695 749
 		// works only for some web server and some setup. This is bugged when
696 750
 		// using proxy, rewriting, virtual path, etc...
697 751
 		$res='';
698
-		if ($type == 1) $res = DOL_URL_ROOT.'/'.$path;			// Standard value
699
-		if ($type == 2) $res = DOL_MAIN_URL_ROOT.'/'.$path;		// Standard value
700
-		if ($type == 3) $res = DOL_URL_ROOT.'/'.$path;
752
+		if ($type == 1) {
753
+			$res = DOL_URL_ROOT.'/'.$path;
754
+		}
755
+		// Standard value
756
+		if ($type == 2) {
757
+			$res = DOL_MAIN_URL_ROOT.'/'.$path;
758
+		}
759
+		// Standard value
760
+		if ($type == 3) {
761
+			$res = DOL_URL_ROOT.'/'.$path;
762
+		}
701 763
 
702
-		foreach ($conf->file->dol_document_root as $key => $dirroot)	// ex: array(["main"]=>"/home/main/htdocs", ["alt0"]=>"/home/dirmod/htdocs", ...)
764
+		foreach ($conf->file->dol_document_root as $key => $dirroot) {
765
+			// ex: array(["main"]=>"/home/main/htdocs", ["alt0"]=>"/home/dirmod/htdocs", ...)
703 766
 		{
704 767
 			if ($key == 'main')
705 768
 			{
706 769
 				if ($type == 3)
707 770
 				{
708 771
 					global $dolibarr_main_url_root;
772
+		}
709 773
 
710 774
 					// Define $urlwithroot
711 775
 					$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
@@ -767,8 +831,7 @@  discard block
 block discarded – undo
767 831
 	if (empty($native))
768 832
 	{
769 833
 		$myclone=unserialize(serialize($object));
770
-	}
771
-	else
834
+	} else
772 835
 	{
773 836
 		$myclone = clone $object;     // PHP clone is a shallow copy only, not a real clone, so properties of references will keep references (refer to the same target/variable)
774 837
 	}
@@ -788,10 +851,15 @@  discard block
 block discarded – undo
788 851
 function dol_size($size,$type='')
789 852
 {
790 853
 	global $conf;
791
-	if (empty($conf->dol_optimize_smallscreen)) return $size;
792
-	if ($type == 'width' && $size > 250) return 250;
793
-	else return 10;
794
-}
854
+	if (empty($conf->dol_optimize_smallscreen)) {
855
+		return $size;
856
+	}
857
+	if ($type == 'width' && $size > 250) {
858
+		return 250;
859
+	} else {
860
+		return 10;
861
+	}
862
+	}
795 863
 
796 864
 
797 865
 /**
@@ -857,8 +925,7 @@  discard block
 block discarded – undo
857 925
 		);
858 926
 		$string=strtr($string, $replacements);
859 927
 		return rawurldecode($string);
860
-	}
861
-	else
928
+	} else
862 929
 	{
863 930
 		// See http://www.ascii-code.com/
864 931
 		$string = strtr(
@@ -896,7 +963,9 @@  discard block
 block discarded – undo
896 963
 {
897 964
 	$forbidden_chars_to_replace=array(" ", "'", "/", "\\", ":", "*", "?", "\"", "<", ">", "|", "[", "]", ",", ";", "=", '°');  // more complete than dol_sanitizeFileName
898 965
 	$forbidden_chars_to_remove=array();
899
-	if (is_array($badcharstoreplace)) $forbidden_chars_to_replace=$badcharstoreplace;
966
+	if (is_array($badcharstoreplace)) {
967
+		$forbidden_chars_to_replace=$badcharstoreplace;
968
+	}
900 969
 	//$forbidden_chars_to_remove=array("(",")");
901 970
 
902 971
 	return str_replace($forbidden_chars_to_replace,$newstr,str_replace($forbidden_chars_to_remove,"",$str));
@@ -928,10 +997,9 @@  discard block
 block discarded – undo
928 997
 	$substitjs=array("&#039;"=>"\\'","\r"=>'\\r');
929 998
 	//$substitjs['</']='<\/';	// We removed this. Should be useless.
930 999
 	if (empty($noescapebackslashn)) { $substitjs["\n"]='\\n'; $substitjs['\\']='\\\\'; }
931
-	if (empty($mode)) { $substitjs["'"]="\\'"; $substitjs['"']="\\'"; }
932
-	else if ($mode == 1) $substitjs["'"]="\\'";
933
-	else if ($mode == 2) { $substitjs['"']='\\"'; }
934
-	else if ($mode == 3) { $substitjs["'"]="\\'"; $substitjs['"']="\\\""; }
1000
+	if (empty($mode)) { $substitjs["'"]="\\'"; $substitjs['"']="\\'"; } else if ($mode == 1) {
1001
+		$substitjs["'"]="\\'";
1002
+	} else if ($mode == 2) { $substitjs['"']='\\"'; } else if ($mode == 3) { $substitjs["'"]="\\'"; $substitjs['"']="\\\""; }
935 1003
 	return strtr($stringtoescape, $substitjs);
936 1004
 }
937 1005
 
@@ -949,8 +1017,12 @@  discard block
 block discarded – undo
949 1017
 {
950 1018
 	// escape quotes and backslashes, newlines, etc.
951 1019
 	$tmp=html_entity_decode($stringtoescape, ENT_COMPAT, 'UTF-8');		// TODO Use htmlspecialchars_decode instead, that make only required change for html tags
952
-	if (! $keepb) $tmp=strtr($tmp, array("<b>"=>'','</b>'=>''));
953
-	if (! $keepn) $tmp=strtr($tmp, array("\r"=>'\\r',"\n"=>'\\n'));
1020
+	if (! $keepb) {
1021
+		$tmp=strtr($tmp, array("<b>"=>'','</b>'=>''));
1022
+	}
1023
+	if (! $keepn) {
1024
+		$tmp=strtr($tmp, array("\r"=>'\\r',"\n"=>'\\n'));
1025
+	}
954 1026
 	return htmlentities($tmp, ENT_COMPAT, 'UTF-8');						// TODO Use htmlspecialchars instead, that make only required change for html tags
955 1027
 }
956 1028
 
@@ -1003,7 +1075,9 @@  discard block
 block discarded – undo
1003 1075
 	global $conf, $user;
1004 1076
 
1005 1077
 	// If syslog module enabled
1006
-	if (empty($conf->syslog->enabled)) return;
1078
+	if (empty($conf->syslog->enabled)) {
1079
+		return;
1080
+	}
1007 1081
 
1008 1082
 	if (! empty($message))
1009 1083
 	{
@@ -1013,13 +1087,17 @@  discard block
 block discarded – undo
1013 1087
 		{
1014 1088
 			throw new Exception('Incorrect log level');
1015 1089
 		}
1016
-		if ($level > $conf->global->SYSLOG_LEVEL) return;
1090
+		if ($level > $conf->global->SYSLOG_LEVEL) {
1091
+			return;
1092
+		}
1017 1093
 
1018 1094
 		// If adding log inside HTML page is required
1019
-		if (! empty($_REQUEST['logtohtml']) && (! empty($conf->global->MAIN_ENABLE_LOG_TO_HTML) || ! empty($conf->global->MAIN_LOGTOHTML)))   // MAIN_LOGTOHTML kept for backward compatibility
1095
+		if (! empty($_REQUEST['logtohtml']) && (! empty($conf->global->MAIN_ENABLE_LOG_TO_HTML) || ! empty($conf->global->MAIN_LOGTOHTML))) {
1096
+			// MAIN_LOGTOHTML kept for backward compatibility
1020 1097
 		{
1021 1098
 			$conf->logbuffer[] = dol_print_date(time(),"%Y-%m-%d %H:%M:%S")." ".$message;
1022 1099
 		}
1100
+		}
1023 1101
 
1024 1102
 		//TODO: Remove this. MAIN_ENABLE_LOG_INLINE_HTML should be deprecated and use a log handler dedicated to HTML output
1025 1103
 		// If enable html log tag enabled and url parameter log defined, we show output log on HTML comments
@@ -1039,19 +1117,31 @@  discard block
 block discarded – undo
1039 1117
 		);
1040 1118
 
1041 1119
 		// This is when server run behind a reverse proxy
1042
-		if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) $data['ip'] = $_SERVER['HTTP_X_FORWARDED_FOR'].(empty($_SERVER["REMOTE_ADDR"])?'':'->'.$_SERVER['REMOTE_ADDR']);
1120
+		if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
1121
+			$data['ip'] = $_SERVER['HTTP_X_FORWARDED_FOR'].(empty($_SERVER["REMOTE_ADDR"])?'':'->'.$_SERVER['REMOTE_ADDR']);
1122
+		}
1043 1123
 		// This is when server run normally on a server
1044
-		else if (! empty($_SERVER["REMOTE_ADDR"])) $data['ip'] = $_SERVER['REMOTE_ADDR'];
1124
+		else if (! empty($_SERVER["REMOTE_ADDR"])) {
1125
+			$data['ip'] = $_SERVER['REMOTE_ADDR'];
1126
+		}
1045 1127
 		// This is when PHP session is ran inside a web server but not inside a client request (example: init code of apache)
1046
-		else if (! empty($_SERVER['SERVER_ADDR'])) $data['ip'] = $_SERVER['SERVER_ADDR'];
1128
+		else if (! empty($_SERVER['SERVER_ADDR'])) {
1129
+			$data['ip'] = $_SERVER['SERVER_ADDR'];
1130
+		}
1047 1131
 		// This is when PHP session is ran outside a web server, like from Windows command line (Not always defined, but useful if OS defined it).
1048
-		else if (! empty($_SERVER['COMPUTERNAME'])) $data['ip'] = $_SERVER['COMPUTERNAME'].(empty($_SERVER['USERNAME'])?'':'@'.$_SERVER['USERNAME']);
1132
+		else if (! empty($_SERVER['COMPUTERNAME'])) {
1133
+			$data['ip'] = $_SERVER['COMPUTERNAME'].(empty($_SERVER['USERNAME'])?'':'@'.$_SERVER['USERNAME']);
1134
+		}
1049 1135
 		// This is when PHP session is ran outside a web server, like from Linux command line (Not always defined, but usefull if OS defined it).
1050
-		else if (! empty($_SERVER['LOGNAME'])) $data['ip'] = '???@'.$_SERVER['LOGNAME'];
1136
+		else if (! empty($_SERVER['LOGNAME'])) {
1137
+			$data['ip'] = '???@'.$_SERVER['LOGNAME'];
1138
+		}
1051 1139
 		// Loop on each log handler and send output
1052 1140
 		foreach ($conf->loghandlers as $loghandlerinstance)
1053 1141
 		{
1054
-			if ($restricttologhandler && $loghandlerinstance->code != $restricttologhandler) continue;
1142
+			if ($restricttologhandler && $loghandlerinstance->code != $restricttologhandler) {
1143
+				continue;
1144
+			}
1055 1145
 			$loghandlerinstance->export($data,$suffixinfilename);
1056 1146
 		}
1057 1147
 		unset($data);
@@ -1102,16 +1192,23 @@  discard block
 block discarded – undo
1102 1192
 
1103 1193
 	$out="\n".'<div class="tabs" data-role="controlgroup" data-type="horizontal">'."\n";
1104 1194
 
1105
-	if ($morehtmlright) $out.='<div class="inline-block floatright tabsElem">'.$morehtmlright.'</div>';	// Output right area first so when space is missing, text is in front of tabs and not under.
1195
+	if ($morehtmlright) {
1196
+		$out.='<div class="inline-block floatright tabsElem">'.$morehtmlright.'</div>';
1197
+	}
1198
+	// Output right area first so when space is missing, text is in front of tabs and not under.
1106 1199
 
1107 1200
 	// Show title
1108 1201
 	$showtitle=1;
1109
-	if (! empty($conf->dol_optimize_smallscreen)) $showtitle=0;
1202
+	if (! empty($conf->dol_optimize_smallscreen)) {
1203
+		$showtitle=0;
1204
+	}
1110 1205
 	if (! empty($title) && $showtitle)
1111 1206
 	{
1112 1207
 		$limittitle=30;
1113 1208
 		$out.='<a class="tabTitle">';
1114
-		if ($picto) $out.=img_picto($title,($pictoisfullpath?'':'object_').$picto,'',$pictoisfullpath).' ';
1209
+		if ($picto) {
1210
+			$out.=img_picto($title,($pictoisfullpath?'':'object_').$picto,'',$pictoisfullpath).' ';
1211
+		}
1115 1212
 		$out.='<span class="tabTitleText">'.dol_trunc($title,$limittitle).'</span>';
1116 1213
 		$out.='</a>';
1117 1214
 	}
@@ -1121,10 +1218,14 @@  discard block
 block discarded – undo
1121 1218
 	if (is_array($links) && ! empty($links))
1122 1219
 	{
1123 1220
 		$keys=array_keys($links);
1124
-		if (count($keys)) $maxkey=max($keys);
1221
+		if (count($keys)) {
1222
+			$maxkey=max($keys);
1223
+		}
1125 1224
 	}
1126 1225
 
1127
-	if (! empty($conf->dol_optimize_smallscreen)) $conf->global->MAIN_MAXTABS_IN_CARD=2;
1226
+	if (! empty($conf->dol_optimize_smallscreen)) {
1227
+		$conf->global->MAIN_MAXTABS_IN_CARD=2;
1228
+	}
1128 1229
 
1129 1230
 	// Show tabs
1130 1231
 	$bactive=false;
@@ -1138,7 +1239,9 @@  discard block
 block discarded – undo
1138 1239
 		if ((is_numeric($active) && $i == $active) || (! empty($links[$i][2]) && ! is_numeric($active) && $active == $links[$i][2]))
1139 1240
 		{
1140 1241
 			// If active tab is already present
1141
-			if ($i >= $limittoshow) $limittoshow--;
1242
+			if ($i >= $limittoshow) {
1243
+				$limittoshow--;
1244
+			}
1142 1245
 		}
1143 1246
 	}
1144 1247
 
@@ -1148,8 +1251,7 @@  discard block
 block discarded – undo
1148 1251
 		{
1149 1252
 			$isactive=true;
1150 1253
 			$bactive=true;
1151
-		}
1152
-		else
1254
+		} else
1153 1255
 		{
1154 1256
 			$isactive=false;
1155 1257
 		}
@@ -1162,13 +1264,11 @@  discard block
 block discarded – undo
1162 1264
 				if (!empty($links[$i][0]))
1163 1265
 				{
1164 1266
 					$out.='<a class="tabimage" href="'.$links[$i][0].'">'.$links[$i][1].'</a>'."\n";
1165
-				}
1166
-				else
1267
+				} else
1167 1268
 				{
1168 1269
 					$out.='<span class="tabspan">'.$links[$i][1].'</span>'."\n";
1169 1270
 				}
1170
-			}
1171
-			else if (! empty($links[$i][1]))
1271
+			} else if (! empty($links[$i][1]))
1172 1272
 			{
1173 1273
 				//print "x $i $active ".$links[$i][2]." z";
1174 1274
 				if ($isactive)
@@ -1176,8 +1276,7 @@  discard block
 block discarded – undo
1176 1276
 					$out.='<a'.(! empty($links[$i][2])?' id="'.$links[$i][2].'"':'').' class="tabactive tab inline-block" href="'.$links[$i][0].'">';
1177 1277
 					$out.=$links[$i][1];
1178 1278
 					$out.='</a>'."\n";
1179
-				}
1180
-				else
1279
+				} else
1181 1280
 				{
1182 1281
 					$out.='<a'.(! empty($links[$i][2])?' id="'.$links[$i][2].'"':'').' class="tabunactive tab inline-block" href="'.$links[$i][0].'">';
1183 1282
 					$out.=$links[$i][1];
@@ -1185,8 +1284,7 @@  discard block
 block discarded – undo
1185 1284
 				}
1186 1285
 			}
1187 1286
 			$out.='</div>';
1188
-		}
1189
-		else
1287
+		} else
1190 1288
 		{
1191 1289
 			// The popup with the other tabs
1192 1290
 			if (! $popuptab)
@@ -1197,13 +1295,13 @@  discard block
 block discarded – undo
1197 1295
 			$outmore.='<div class="popuptab wordwrap" style="display:inherit;">';
1198 1296
 			if (isset($links[$i][2]) && $links[$i][2] == 'image')
1199 1297
 			{
1200
-				if (!empty($links[$i][0]))
1201
-					$outmore.='<a class="tabimage" href="'.$links[$i][0].'">'.$links[$i][1].'</a>'."\n";
1202
-				else
1203
-					$outmore.='<span class="tabspan">'.$links[$i][1].'</span>'."\n";
1298
+				if (!empty($links[$i][0])) {
1299
+									$outmore.='<a class="tabimage" href="'.$links[$i][0].'">'.$links[$i][1].'</a>'."\n";
1300
+				} else {
1301
+									$outmore.='<span class="tabspan">'.$links[$i][1].'</span>'."\n";
1302
+				}
1204 1303
 
1205
-			}
1206
-			else if (! empty($links[$i][1]))
1304
+			} else if (! empty($links[$i][1]))
1207 1305
 			{
1208 1306
 				$outmore.='<a'.(! empty($links[$i][2])?' id="'.$links[$i][2].'"':'').' class="wordwrap inline-block" href="'.$links[$i][0].'">';
1209 1307
 				$outmore.=preg_replace('/([a-z])\/([a-z])/i', '\\1 / \\2', $links[$i][1]);	// Replace x/y with x / y to allow wrap on long composed texts.
@@ -1215,7 +1313,9 @@  discard block
 block discarded – undo
1215 1313
 		}
1216 1314
 		$displaytab=$i;
1217 1315
 	}
1218
-	if ($popuptab) $outmore.='</div>';
1316
+	if ($popuptab) {
1317
+		$outmore.='</div>';
1318
+	}
1219 1319
 
1220 1320
 	if ($displaytab > $limittoshow)
1221 1321
 	{
@@ -1239,7 +1339,9 @@  discard block
 block discarded – undo
1239 1339
 
1240 1340
 	$out.="</div>\n";
1241 1341
 
1242
-	if (! $notab || $notab == -1) $out.="\n".'<div class="tabBar'.($notab == -1 ? '' : ' tabBarWithBottom').'">'."\n";
1342
+	if (! $notab || $notab == -1) {
1343
+		$out.="\n".'<div class="tabBar'.($notab == -1 ? '' : ' tabBarWithBottom').'">'."\n";
1344
+	}
1243 1345
 
1244 1346
 	$parameters=array('tabname' => $active, 'out' => $out);
1245 1347
 	$reshook=$hookmanager->executeHooks('printTabsHead',$parameters);	// This hook usage is called just before output the head of tabs. Take also a look at "completeTabsHead"
@@ -1270,9 +1372,12 @@  discard block
 block discarded – undo
1270 1372
  */
1271 1373
 function dol_get_fiche_end($notab=0)
1272 1374
 {
1273
-	if (! $notab || $notab == -1) return "\n</div>\n";
1274
-	else return '';
1275
-}
1375
+	if (! $notab || $notab == -1) {
1376
+		return "\n</div>\n";
1377
+	} else {
1378
+		return '';
1379
+	}
1380
+	}
1276 1381
 
1277 1382
 /**
1278 1383
  *  Show tab footer of a card.
@@ -1302,26 +1407,56 @@  discard block
 block discarded – undo
1302 1407
 	$maxvisiblephotos=1;
1303 1408
 	$showimage=1;
1304 1409
 	$showbarcode=empty($conf->barcode->enabled)?0:($object->barcode?1:0);
1305
-	if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) $showbarcode=0;
1410
+	if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) {
1411
+		$showbarcode=0;
1412
+	}
1306 1413
 	$modulepart='unknown';
1307 1414
 
1308
-	if ($object->element == 'societe')         $modulepart='societe';
1309
-	if ($object->element == 'contact')         $modulepart='contact';
1310
-	if ($object->element == 'member')          $modulepart='memberphoto';
1311
-	if ($object->element == 'user')            $modulepart='userphoto';
1312
-	if ($object->element == 'product')         $modulepart='product';
1415
+	if ($object->element == 'societe') {
1416
+		$modulepart='societe';
1417
+	}
1418
+	if ($object->element == 'contact') {
1419
+		$modulepart='contact';
1420
+	}
1421
+	if ($object->element == 'member') {
1422
+		$modulepart='memberphoto';
1423
+	}
1424
+	if ($object->element == 'user') {
1425
+		$modulepart='userphoto';
1426
+	}
1427
+	if ($object->element == 'product') {
1428
+		$modulepart='product';
1429
+	}
1313 1430
 
1314 1431
 	if (class_exists("Imagick"))
1315 1432
 	{
1316
-		if ($object->element == 'propal')            $modulepart='propal';
1317
-		if ($object->element == 'commande')          $modulepart='commande';
1318
-		if ($object->element == 'facture')           $modulepart='facture';
1319
-		if ($object->element == 'fichinter')         $modulepart='ficheinter';
1320
-		if ($object->element == 'contrat')           $modulepart='contract';
1321
-		if ($object->element == 'supplier_proposal') $modulepart='supplier_proposal';
1322
-		if ($object->element == 'order_supplier')    $modulepart='supplier_order';
1323
-		if ($object->element == 'invoice_supplier')  $modulepart='supplier_invoice';
1324
-		if ($object->element == 'expensereport')     $modulepart='expensereport';
1433
+		if ($object->element == 'propal') {
1434
+			$modulepart='propal';
1435
+		}
1436
+		if ($object->element == 'commande') {
1437
+			$modulepart='commande';
1438
+		}
1439
+		if ($object->element == 'facture') {
1440
+			$modulepart='facture';
1441
+		}
1442
+		if ($object->element == 'fichinter') {
1443
+			$modulepart='ficheinter';
1444
+		}
1445
+		if ($object->element == 'contrat') {
1446
+			$modulepart='contract';
1447
+		}
1448
+		if ($object->element == 'supplier_proposal') {
1449
+			$modulepart='supplier_proposal';
1450
+		}
1451
+		if ($object->element == 'order_supplier') {
1452
+			$modulepart='supplier_order';
1453
+		}
1454
+		if ($object->element == 'invoice_supplier') {
1455
+			$modulepart='supplier_invoice';
1456
+		}
1457
+		if ($object->element == 'expensereport') {
1458
+			$modulepart='expensereport';
1459
+		}
1325 1460
 	}
1326 1461
 
1327 1462
 	if ($object->element == 'product')
@@ -1329,9 +1464,12 @@  discard block
 block discarded – undo
1329 1464
 		$width=80; $cssclass='photoref';
1330 1465
 		$showimage=$object->is_photo_available($conf->product->multidir_output[$object->entity]);
1331 1466
 		$maxvisiblephotos=(isset($conf->global->PRODUCT_MAX_VISIBLE_PHOTO)?$conf->global->PRODUCT_MAX_VISIBLE_PHOTO:5);
1332
-		if ($conf->browser->phone) $maxvisiblephotos=1;
1333
-		if ($showimage) $morehtmlleft.='<div class="floatleft inline-block valignmiddle divphotoref">'.$object->show_photos($conf->product->multidir_output[$object->entity],'small',$maxvisiblephotos,0,0,0,$width,0).'</div>';
1334
-		else
1467
+		if ($conf->browser->phone) {
1468
+			$maxvisiblephotos=1;
1469
+		}
1470
+		if ($showimage) {
1471
+			$morehtmlleft.='<div class="floatleft inline-block valignmiddle divphotoref">'.$object->show_photos($conf->product->multidir_output[$object->entity],'small',$maxvisiblephotos,0,0,0,$width,0).'</div>';
1472
+		} else
1335 1473
 		{
1336 1474
 			if (!empty($conf->global->PRODUCT_NODISPLAYIFNOPHOTO)) {
1337 1475
 				$nophoto='';
@@ -1342,8 +1480,7 @@  discard block
 block discarded – undo
1342 1480
 				$morehtmlleft.='<div class="floatleft inline-block valignmiddle divphotoref"><img class="photo'.$modulepart.($cssclass?' '.$cssclass:'').'" alt="No photo" border="0"'.($width?' width="'.$width.'"':'').' src="'.DOL_URL_ROOT.$nophoto.'"></div>';
1343 1481
 			//}
1344 1482
 		}
1345
-	}
1346
-	else
1483
+	} else
1347 1484
 	{
1348 1485
 		if ($showimage)
1349 1486
 		{
@@ -1358,8 +1495,7 @@  discard block
 block discarded – undo
1358 1495
 					if (in_array($modulepart, array('invoice_supplier', 'supplier_invoice')))
1359 1496
 					{
1360 1497
 						$subdir = get_exdir($object->id, 2, 0, 0, $object, $modulepart).$objectref;		// the objectref dir is not include into get_exdir when used with level=2, so we add it here
1361
-					}
1362
-					else
1498
+					} else
1363 1499
 					{
1364 1500
 						$subdir = get_exdir($object->id, 0, 0, 0, $object, $modulepart);
1365 1501
 					}
@@ -1382,15 +1518,21 @@  discard block
 block discarded – undo
1382 1518
 						  && (! file_exists($fileimagebis) || (filemtime($fileimagebis) < filemtime($file)))
1383 1519
 						   )
1384 1520
 						{
1385
-							if (empty($conf->global->MAIN_DISABLE_PDF_THUMBS))		// If you experienc trouble with pdf thumb generation and imagick, you can disable here.
1521
+							if (empty($conf->global->MAIN_DISABLE_PDF_THUMBS)) {
1522
+								// If you experienc trouble with pdf thumb generation and imagick, you can disable here.
1386 1523
 							{
1387 1524
 								$ret = dol_convert_file($file, 'png', $fileimage);
1388
-								if ($ret < 0) $error++;
1525
+							}
1526
+								if ($ret < 0) {
1527
+									$error++;
1528
+								}
1389 1529
 							}
1390 1530
 						}
1391 1531
 
1392 1532
 						$heightforphotref=70;
1393
-						if (! empty($conf->dol_optimize_smallscreen)) $heightforphotref=60;
1533
+						if (! empty($conf->dol_optimize_smallscreen)) {
1534
+							$heightforphotref=60;
1535
+						}
1394 1536
 						// Si fichier png PDF d'1 page trouve
1395 1537
 						if (file_exists($fileimage))
1396 1538
 						{
@@ -1407,8 +1549,7 @@  discard block
 block discarded – undo
1407 1549
 							$phototoshow.= '</div></div>';
1408 1550
 						}
1409 1551
 					}
1410
-				}
1411
-				else if (! $phototoshow)
1552
+				} else if (! $phototoshow)
1412 1553
 				{
1413 1554
 					$phototoshow = $form->showphoto($modulepart,$object,0,0,0,'photoref','small',1,0,$maxvisiblephotos);
1414 1555
 				}
@@ -1421,20 +1562,24 @@  discard block
 block discarded – undo
1421 1562
 				}
1422 1563
 			}
1423 1564
 
1424
-			if (! $phototoshow)      // Show No photo link (picto of pbject)
1565
+			if (! $phototoshow) {
1566
+				// Show No photo link (picto of pbject)
1425 1567
 			{
1426 1568
 				$morehtmlleft.='<div class="floatleft inline-block valignmiddle divphotoref">';
1569
+			}
1427 1570
 				if ($object->element == 'action')
1428 1571
 				{
1429 1572
 					$width=80;
1430 1573
 					$cssclass='photorefcenter';
1431 1574
 					$nophoto=img_picto('', 'title_agenda', '', false, 1);
1432
-				}
1433
-				else
1575
+				} else
1434 1576
 				{
1435 1577
 					$width=14; $cssclass='photorefcenter';
1436 1578
 					$picto = $object->picto;
1437
-					if ($object->element == 'project' && ! $object->public) $picto = 'project'; // instead of projectpub
1579
+					if ($object->element == 'project' && ! $object->public) {
1580
+						$picto = 'project';
1581
+					}
1582
+					// instead of projectpub
1438 1583
 					$nophoto=img_picto('', 'object_'.$picto, '', false, 1);
1439 1584
 				}
1440 1585
 				$morehtmlleft.='<!-- No photo to show -->';
@@ -1445,19 +1590,19 @@  discard block
 block discarded – undo
1445 1590
 		}
1446 1591
 	}
1447 1592
 
1448
-	if ($showbarcode) $morehtmlleft.='<div class="floatleft inline-block valignmiddle divphotoref">'.$form->showbarcode($object).'</div>';
1593
+	if ($showbarcode) {
1594
+		$morehtmlleft.='<div class="floatleft inline-block valignmiddle divphotoref">'.$form->showbarcode($object).'</div>';
1595
+	}
1449 1596
 
1450 1597
 	if ($object->element == 'societe')
1451 1598
 	{
1452 1599
 		if (! empty($conf->use_javascript_ajax) && $user->rights->societe->creer && ! empty($conf->global->MAIN_DIRECT_STATUS_UPDATE))
1453 1600
 		{
1454 1601
 		   	$morehtmlstatus.=ajax_object_onoff($object, 'status', 'status', 'InActivity', 'ActivityCeased');
1455
-		}
1456
-		else {
1602
+		} else {
1457 1603
 			$morehtmlstatus.=$object->getLibStatut(6);
1458 1604
 		}
1459
-	}
1460
-	elseif ($object->element == 'product')
1605
+	} elseif ($object->element == 'product')
1461 1606
 	{
1462 1607
 		//$morehtmlstatus.=$langs->trans("Status").' ('.$langs->trans("Sell").') ';
1463 1608
 		if (! empty($conf->use_javascript_ajax) && $user->rights->produit->creer && ! empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) {
@@ -1472,26 +1617,32 @@  discard block
 block discarded – undo
1472 1617
 		} else {
1473 1618
 			$morehtmlstatus.='<span class="statusrefbuy">'.$object->getLibStatut(5,1).'</span>';
1474 1619
 		}
1475
-	}
1476
-	elseif (in_array($object->element, array('facture', 'invoice', 'invoice_supplier', 'chargesociales', 'loan')))
1620
+	} elseif (in_array($object->element, array('facture', 'invoice', 'invoice_supplier', 'chargesociales', 'loan')))
1477 1621
 	{
1478 1622
 		$tmptxt=$object->getLibStatut(6, $object->totalpaye);
1479
-		if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3) || $conf->browser->layout=='phone') $tmptxt=$object->getLibStatut(5, $object->totalpaye);
1623
+		if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3) || $conf->browser->layout=='phone') {
1624
+			$tmptxt=$object->getLibStatut(5, $object->totalpaye);
1625
+		}
1480 1626
 		$morehtmlstatus.=$tmptxt;
1481
-	}
1482
-	elseif ($object->element == 'contrat' || $object->element == 'contract')
1627
+	} elseif ($object->element == 'contrat' || $object->element == 'contract')
1483 1628
 	{
1484
-		if ($object->statut == 0) $morehtmlstatus.=$object->getLibStatut(5);
1485
-		else $morehtmlstatus.=$object->getLibStatut(4);
1486
-	}
1487
-	elseif ($object->element == 'facturerec')
1629
+		if ($object->statut == 0) {
1630
+			$morehtmlstatus.=$object->getLibStatut(5);
1631
+		} else {
1632
+			$morehtmlstatus.=$object->getLibStatut(4);
1633
+		}
1634
+	} elseif ($object->element == 'facturerec')
1488 1635
 	{
1489
-		if ($object->frequency == 0) $morehtmlstatus.=$object->getLibStatut(2);
1490
-		else $morehtmlstatus.=$object->getLibStatut(5);
1491
-	}
1492
-	else { // Generic case
1636
+		if ($object->frequency == 0) {
1637
+			$morehtmlstatus.=$object->getLibStatut(2);
1638
+		} else {
1639
+			$morehtmlstatus.=$object->getLibStatut(5);
1640
+		}
1641
+	} else { // Generic case
1493 1642
 		$tmptxt=$object->getLibStatut(6);
1494
-		if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3) || $conf->browser->layout=='phone') $tmptxt=$object->getLibStatut(5);
1643
+		if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3) || $conf->browser->layout=='phone') {
1644
+			$tmptxt=$object->getLibStatut(5);
1645
+		}
1495 1646
 		$morehtmlstatus.=$tmptxt;
1496 1647
 	}
1497 1648
 
@@ -1507,12 +1658,16 @@  discard block
 block discarded – undo
1507 1658
 	}
1508 1659
 
1509 1660
 	// Add alias for thirdparty
1510
-	if (! empty($object->name_alias)) $morehtmlref.='<div class="refidno">'.$object->name_alias.'</div>';
1661
+	if (! empty($object->name_alias)) {
1662
+		$morehtmlref.='<div class="refidno">'.$object->name_alias.'</div>';
1663
+	}
1511 1664
 
1512 1665
 	// Add label
1513 1666
 	if ($object->element == 'product' || $object->element == 'bank_account' || $object->element == 'project_task')
1514 1667
 	{
1515
-		if (! empty($object->label)) $morehtmlref.='<div class="refidno">'.$object->label.'</div>';
1668
+		if (! empty($object->label)) {
1669
+			$morehtmlref.='<div class="refidno">'.$object->label.'</div>';
1670
+		}
1516 1671
 	}
1517 1672
 
1518 1673
 	if (method_exists($object, 'getBannerAddress') && $object->element != 'product' && $object->element != 'bookmark' && $object->element != 'ecm_directories' && $object->element != 'ecm_files')
@@ -1546,11 +1701,19 @@  discard block
 block discarded – undo
1546 1701
 {
1547 1702
 	global $conf, $langs;
1548 1703
 	$ret='';
1549
-	if ($fieldrequired) $ret.='<span class="fieldrequired">';
1550
-	if (($conf->dol_use_jmobile != 4)) $ret.='<label for="'.$fieldkey.'">';
1704
+	if ($fieldrequired) {
1705
+		$ret.='<span class="fieldrequired">';
1706
+	}
1707
+	if (($conf->dol_use_jmobile != 4)) {
1708
+		$ret.='<label for="'.$fieldkey.'">';
1709
+	}
1551 1710
 	$ret.=$langs->trans($langkey);
1552
-	if (($conf->dol_use_jmobile != 4)) $ret.='</label>';
1553
-	if ($fieldrequired) $ret.='</span>';
1711
+	if (($conf->dol_use_jmobile != 4)) {
1712
+		$ret.='</label>';
1713
+	}
1714
+	if ($fieldrequired) {
1715
+		$ret.='</span>';
1716
+	}
1554 1717
 	return $ret;
1555 1718
 }
1556 1719
 
@@ -1565,7 +1728,9 @@  discard block
 block discarded – undo
1565 1728
 {
1566 1729
 	global $bc;
1567 1730
 	$ret=' '.$bc[$var];
1568
-	if ($moreclass) $ret=preg_replace('/class=\"/','class="'.$moreclass.' ',$ret);
1731
+	if ($moreclass) {
1732
+		$ret=preg_replace('/class=\"/','class="'.$moreclass.' ',$ret);
1733
+	}
1569 1734
 	return $ret;
1570 1735
 }
1571 1736
 
@@ -1592,40 +1757,48 @@  discard block
 block discarded – undo
1592 1757
 		$ret .= $object->address;
1593 1758
 	}
1594 1759
 	// Zip/Town/State
1595
-	if (in_array($object->country_code,array('AU', 'CA', 'US')) || ! empty($conf->global->MAIN_FORCE_STATE_INTO_ADDRESS))   	// US: title firstname name \n address lines \n town, state, zip \n country
1760
+	if (in_array($object->country_code,array('AU', 'CA', 'US')) || ! empty($conf->global->MAIN_FORCE_STATE_INTO_ADDRESS)) {
1761
+		// US: title firstname name \n address lines \n town, state, zip \n country
1596 1762
 	{
1597 1763
 		$ret .= ($ret ? $sep : '' ).$object->town;
1764
+	}
1598 1765
 		if ($object->state)
1599 1766
 		{
1600 1767
 			$ret.=($ret?", ":'').$object->state;
1601 1768
 		}
1602
-		if ($object->zip) $ret .= ($ret?", ":'').$object->zip;
1603
-	}
1604
-	else if (in_array($object->country_code,array('GB','UK'))) // UK: title firstname name \n address lines \n town state \n zip \n country
1769
+		if ($object->zip) {
1770
+			$ret .= ($ret?", ":'').$object->zip;
1771
+		}
1772
+	} else if (in_array($object->country_code,array('GB','UK'))) {
1773
+		// UK: title firstname name \n address lines \n town state \n zip \n country
1605 1774
 	{
1606 1775
 		$ret .= ($ret ? $sep : '' ).$object->town;
1776
+	}
1607 1777
 		if ($object->state)
1608 1778
 		{
1609 1779
 			$ret.=($ret?", ":'').$object->state;
1610 1780
 		}
1611
-		if ($object->zip) $ret .= ($ret ? $sep : '' ).$object->zip;
1612
-	}
1613
-	else if (in_array($object->country_code,array('ES','TR'))) // ES: title firstname name \n address lines \n zip town \n state \n country
1781
+		if ($object->zip) {
1782
+			$ret .= ($ret ? $sep : '' ).$object->zip;
1783
+		}
1784
+	} else if (in_array($object->country_code,array('ES','TR'))) {
1785
+		// ES: title firstname name \n address lines \n zip town \n state \n country
1614 1786
 	{
1615 1787
 		$ret .= ($ret ? $sep : '' ).$object->zip;
1788
+	}
1616 1789
 		$ret .= ($object->town?(($object->zip?' ':'').$object->town):'');
1617 1790
 		if ($object->state)
1618 1791
 		{
1619 1792
 			$ret.="\n".$object->state;
1620 1793
 		}
1621
-	}
1622
-	else if (in_array($object->country_code,array('IT'))) // IT: tile firstname name\n address lines \n zip (Code Departement) \n country
1794
+	} else if (in_array($object->country_code,array('IT'))) {
1795
+		// IT: tile firstname name\n address lines \n zip (Code Departement) \n country
1623 1796
 	{
1624 1797
                 $ret .= ($ret ? $sep : '' ).$object->zip;
1798
+	}
1625 1799
                 $ret .= ($object->town?(($object->zip?' ':'').$object->town):'');
1626 1800
                 $ret .= ($object->departement_id?(' ('.($object->departement_id).')'):'');
1627
-	}
1628
-	else                                        		// Other: title firstname name \n address lines \n zip town \n country
1801
+	} else                                        		// Other: title firstname name \n address lines \n zip town \n country
1629 1802
 	{
1630 1803
 		$ret .= $object->zip ? (($ret ? $sep : '' ).$object->zip) : '';
1631 1804
 		$ret .= ($object->town?(($object->zip?' ':($ret ? $sep : '' )).$object->town):'');
@@ -1634,8 +1807,12 @@  discard block
 block discarded – undo
1634 1807
 			$ret.=($ret?", ":'').$object->state;
1635 1808
 		}
1636 1809
 	}
1637
-	if (! is_object($outputlangs)) $outputlangs=$langs;
1638
-	if ($withcountry) $ret.=($object->country_code?($ret?$sep:'').$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$object->country_code)):'');
1810
+	if (! is_object($outputlangs)) {
1811
+		$outputlangs=$langs;
1812
+	}
1813
+	if ($withcountry) {
1814
+		$ret.=($object->country_code?($ret?$sep:'').$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$object->country_code)):'');
1815
+	}
1639 1816
 
1640 1817
 	return $ret;
1641 1818
 }
@@ -1654,9 +1831,10 @@  discard block
 block discarded – undo
1654 1831
 {
1655 1832
 	if ((abs($ts) <= 0x7FFFFFFF)) { // check if number in 32-bit signed range
1656 1833
 		return ($is_gmt)? @gmstrftime($fmt,$ts): @strftime($fmt,$ts);
1834
+	} else {
1835
+		return 'Error date into a not supported range';
1836
+	}
1657 1837
 	}
1658
-	else return 'Error date into a not supported range';
1659
-}
1660 1838
 
1661 1839
 /**
1662 1840
  *	Output date in a string format according to outputlangs (or langs if not defined).
@@ -1697,8 +1875,7 @@  discard block
 block discarded – undo
1697 1875
 				$offsettzstring=@date_default_timezone_get();		// Example 'Europe/Berlin' or 'Indian/Reunion'
1698 1876
 				$offsettz=0;
1699 1877
 				$offsetdst=0;
1700
-			}
1701
-			elseif ($tzoutput == 'tzuser' || $tzoutput == 'tzuserrel')
1878
+			} elseif ($tzoutput == 'tzuser' || $tzoutput == 'tzuserrel')
1702 1879
 			{
1703 1880
 				$to_gmt=true;
1704 1881
 				$offsettzstring=(empty($_SESSION['dol_tz_string'])?'UTC':$_SESSION['dol_tz_string']);	// Example 'Europe/Berlin' or 'Indian/Reunion'
@@ -1707,31 +1884,57 @@  discard block
 block discarded – undo
1707 1884
 			}
1708 1885
 		}
1709 1886
 	}
1710
-	if (! is_object($outputlangs)) $outputlangs=$langs;
1711
-	if (! $format) $format='daytextshort';
1887
+	if (! is_object($outputlangs)) {
1888
+		$outputlangs=$langs;
1889
+	}
1890
+	if (! $format) {
1891
+		$format='daytextshort';
1892
+	}
1712 1893
 	$reduceformat=(! empty($conf->dol_optimize_smallscreen) && in_array($format,array('day','dayhour')))?1:0;
1713 1894
 	$formatwithoutreduce = preg_replace('/reduceformat/','',$format);
1714 1895
 	if ($formatwithoutreduce != $format) { $format = $formatwithoutreduce; $reduceformat=1; }  // so format 'dayreduceformat' is processed like day
1715 1896
 
1716 1897
 	// Change predefined format into computer format. If found translation in lang file we use it, otherwise we use default.
1717 1898
 	// TODO Add format daysmallyear and dayhoursmallyear
1718
-	if ($format == 'day')				$format=($outputlangs->trans("FormatDateShort")!="FormatDateShort"?$outputlangs->trans("FormatDateShort"):$conf->format_date_short);
1719
-	else if ($format == 'hour')			$format=($outputlangs->trans("FormatHourShort")!="FormatHourShort"?$outputlangs->trans("FormatHourShort"):$conf->format_hour_short);
1720
-	else if ($format == 'hourduration')	$format=($outputlangs->trans("FormatHourShortDuration")!="FormatHourShortDuration"?$outputlangs->trans("FormatHourShortDuration"):$conf->format_hour_short_duration);
1721
-	else if ($format == 'daytext')			 $format=($outputlangs->trans("FormatDateText")!="FormatDateText"?$outputlangs->trans("FormatDateText"):$conf->format_date_text);
1722
-	else if ($format == 'daytextshort')	$format=($outputlangs->trans("FormatDateTextShort")!="FormatDateTextShort"?$outputlangs->trans("FormatDateTextShort"):$conf->format_date_text_short);
1723
-	else if ($format == 'dayhour')			 $format=($outputlangs->trans("FormatDateHourShort")!="FormatDateHourShort"?$outputlangs->trans("FormatDateHourShort"):$conf->format_date_hour_short);
1724
-	else if ($format == 'dayhoursec')		 $format=($outputlangs->trans("FormatDateHourSecShort")!="FormatDateHourSecShort"?$outputlangs->trans("FormatDateHourSecShort"):$conf->format_date_hour_sec_short);
1725
-	else if ($format == 'dayhourtext')		 $format=($outputlangs->trans("FormatDateHourText")!="FormatDateHourText"?$outputlangs->trans("FormatDateHourText"):$conf->format_date_hour_text);
1726
-	else if ($format == 'dayhourtextshort') $format=($outputlangs->trans("FormatDateHourTextShort")!="FormatDateHourTextShort"?$outputlangs->trans("FormatDateHourTextShort"):$conf->format_date_hour_text_short);
1899
+	if ($format == 'day') {
1900
+		$format=($outputlangs->trans("FormatDateShort")!="FormatDateShort"?$outputlangs->trans("FormatDateShort"):$conf->format_date_short);
1901
+	} else if ($format == 'hour') {
1902
+		$format=($outputlangs->trans("FormatHourShort")!="FormatHourShort"?$outputlangs->trans("FormatHourShort"):$conf->format_hour_short);
1903
+	} else if ($format == 'hourduration') {
1904
+		$format=($outputlangs->trans("FormatHourShortDuration")!="FormatHourShortDuration"?$outputlangs->trans("FormatHourShortDuration"):$conf->format_hour_short_duration);
1905
+	} else if ($format == 'daytext') {
1906
+		$format=($outputlangs->trans("FormatDateText")!="FormatDateText"?$outputlangs->trans("FormatDateText"):$conf->format_date_text);
1907
+	} else if ($format == 'daytextshort') {
1908
+		$format=($outputlangs->trans("FormatDateTextShort")!="FormatDateTextShort"?$outputlangs->trans("FormatDateTextShort"):$conf->format_date_text_short);
1909
+	} else if ($format == 'dayhour') {
1910
+		$format=($outputlangs->trans("FormatDateHourShort")!="FormatDateHourShort"?$outputlangs->trans("FormatDateHourShort"):$conf->format_date_hour_short);
1911
+	} else if ($format == 'dayhoursec') {
1912
+		$format=($outputlangs->trans("FormatDateHourSecShort")!="FormatDateHourSecShort"?$outputlangs->trans("FormatDateHourSecShort"):$conf->format_date_hour_sec_short);
1913
+	} else if ($format == 'dayhourtext') {
1914
+		$format=($outputlangs->trans("FormatDateHourText")!="FormatDateHourText"?$outputlangs->trans("FormatDateHourText"):$conf->format_date_hour_text);
1915
+	} else if ($format == 'dayhourtextshort') {
1916
+		$format=($outputlangs->trans("FormatDateHourTextShort")!="FormatDateHourTextShort"?$outputlangs->trans("FormatDateHourTextShort"):$conf->format_date_hour_text_short);
1917
+	}
1727 1918
 	// Format not sensitive to language
1728
-	else if ($format == 'dayhourlog')		 $format='%Y%m%d%H%M%S';
1729
-	else if ($format == 'dayhourldap')		 $format='%Y%m%d%H%M%SZ';
1730
-	else if ($format == 'dayhourxcard')	$format='%Y%m%dT%H%M%SZ';
1731
-	else if ($format == 'dayxcard')	 	$format='%Y%m%d';
1732
-	else if ($format == 'dayrfc')			 $format='%Y-%m-%d';             // DATE_RFC3339
1733
-	else if ($format == 'dayhourrfc')		 $format='%Y-%m-%dT%H:%M:%SZ';   // DATETIME RFC3339
1734
-	else if ($format == 'standard')		$format='%Y-%m-%d %H:%M:%S';
1919
+	else if ($format == 'dayhourlog') {
1920
+		$format='%Y%m%d%H%M%S';
1921
+	} else if ($format == 'dayhourldap') {
1922
+		$format='%Y%m%d%H%M%SZ';
1923
+	} else if ($format == 'dayhourxcard') {
1924
+		$format='%Y%m%dT%H%M%SZ';
1925
+	} else if ($format == 'dayxcard') {
1926
+		$format='%Y%m%d';
1927
+	} else if ($format == 'dayrfc') {
1928
+		$format='%Y-%m-%d';
1929
+	}
1930
+	// DATE_RFC3339
1931
+	else if ($format == 'dayhourrfc') {
1932
+		$format='%Y-%m-%dT%H:%M:%SZ';
1933
+	}
1934
+	// DATETIME RFC3339
1935
+	else if ($format == 'standard') {
1936
+		$format='%Y-%m-%d %H:%M:%S';
1937
+	}
1735 1938
 
1736 1939
 	if ($reduceformat)
1737 1940
 	{
@@ -1740,29 +1943,38 @@  discard block
 block discarded – undo
1740 1943
 	}
1741 1944
 
1742 1945
 	// If date undefined or "", we return ""
1743
-	if (dol_strlen($time) == 0) return '';		// $time=0 allowed (it means 01/01/1970 00:00:00)
1946
+	if (dol_strlen($time) == 0) {
1947
+		return '';
1948
+	}
1949
+	// $time=0 allowed (it means 01/01/1970 00:00:00)
1744 1950
 
1745 1951
 	// Clean format
1746
-	if (preg_match('/%b/i',$format))		// There is some text to translate
1952
+	if (preg_match('/%b/i',$format)) {
1953
+		// There is some text to translate
1747 1954
 	{
1748 1955
 		// We inhibate translation to text made by strftime functions. We will use trans instead later.
1749 1956
 		$format=str_replace('%b','__b__',$format);
1957
+	}
1750 1958
 		$format=str_replace('%B','__B__',$format);
1751 1959
 	}
1752
-	if (preg_match('/%a/i',$format))		// There is some text to translate
1960
+	if (preg_match('/%a/i',$format)) {
1961
+		// There is some text to translate
1753 1962
 	{
1754 1963
 		// We inhibate translation to text made by strftime functions. We will use trans instead later.
1755 1964
 		$format=str_replace('%a','__a__',$format);
1965
+	}
1756 1966
 		$format=str_replace('%A','__A__',$format);
1757 1967
 	}
1758 1968
 
1759 1969
 	// Analyze date
1760 1970
 	if (preg_match('/^([0-9]+)\-([0-9]+)\-([0-9]+) ?([0-9]+)?:?([0-9]+)?:?([0-9]+)?/i',$time,$reg)
1761
-	|| preg_match('/^([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])$/i',$time,$reg))	// Deprecated. Ex: 1970-01-01, 1970-01-01 01:00:00, 19700101010000
1971
+	|| preg_match('/^([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])$/i',$time,$reg)) {
1972
+		// Deprecated. Ex: 1970-01-01, 1970-01-01 01:00:00, 19700101010000
1762 1973
 	{
1763 1974
 		// TODO Remove this.
1764 1975
 		// This part of code should not be used.
1765 1976
 		dol_syslog("Functions.lib::dol_print_date function call with deprecated value of time in page ".$_SERVER["PHP_SELF"], LOG_ERR);
1977
+	}
1766 1978
 		// Date has format 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS' or 'YYYYMMDDHHMMSS'
1767 1979
 		$syear	= (! empty($reg[1]) ? $reg[1] : '');
1768 1980
 		$smonth	= (! empty($reg[2]) ? $reg[2] : '');
@@ -1773,17 +1985,20 @@  discard block
 block discarded – undo
1773 1985
 
1774 1986
 		$time=dol_mktime($shour,$smin,$ssec,$smonth,$sday,$syear,true);
1775 1987
 		$ret=adodb_strftime($format, $time+$offsettz+$offsetdst, $to_gmt);
1776
-	}
1777
-	else
1988
+	} else
1778 1989
 	{
1779 1990
 		// Date is a timestamps
1780
-		if ($time < 100000000000)	// Protection against bad date values
1991
+		if ($time < 100000000000) {
1992
+			// Protection against bad date values
1781 1993
 		{
1782
-			$timetouse = $time+$offsettz+$offsetdst;	// TODO Replace this with function Date PHP. We also should not use anymore offsettz and offsetdst but only offsettzstring.
1994
+			$timetouse = $time+$offsettz+$offsetdst;
1995
+		}
1996
+		// TODO Replace this with function Date PHP. We also should not use anymore offsettz and offsetdst but only offsettzstring.
1783 1997
 
1784 1998
 			$ret=adodb_strftime($format, $timetouse, $to_gmt);
1999
+		} else {
2000
+			$ret='Bad value '.$time.' for date';
1785 2001
 		}
1786
-		else $ret='Bad value '.$time.' for date';
1787 2002
 	}
1788 2003
 
1789 2004
 	if (preg_match('/__b__/i',$format))
@@ -1797,8 +2012,7 @@  discard block
 block discarded – undo
1797 2012
 		{
1798 2013
 			$monthtext=$outputlangs->transnoentities('Month'.$month);
1799 2014
 			$monthtextshort=$outputlangs->transnoentities('MonthShort'.$month);
1800
-		}
1801
-		else
2015
+		} else
1802 2016
 		{
1803 2017
 			$monthtext=$outputlangs->transnoentitiesnoconv('Month'.$month);
1804 2018
 			$monthtextshort=$outputlangs->transnoentitiesnoconv('MonthShort'.$month);
@@ -1861,14 +2075,19 @@  discard block
 block discarded – undo
1861 2075
 	global $conf;
1862 2076
 
1863 2077
 	$usealternatemethod=false;
1864
-	if ($timestamp <= 0) $usealternatemethod=true;				// <= 1970
1865
-	if ($timestamp >= 2145913200) $usealternatemethod=true;		// >= 2038
2078
+	if ($timestamp <= 0) {
2079
+		$usealternatemethod=true;
2080
+	}
2081
+	// <= 1970
2082
+	if ($timestamp >= 2145913200) {
2083
+		$usealternatemethod=true;
2084
+	}
2085
+	// >= 2038
1866 2086
 
1867 2087
 	if ($usealternatemethod)
1868 2088
 	{
1869 2089
 		$arrayinfo=adodb_getdate($timestamp,$fast);
1870
-	}
1871
-	else
2090
+	} else
1872 2091
 	{
1873 2092
 		$arrayinfo=getdate($timestamp);
1874 2093
 	}
@@ -1901,19 +2120,37 @@  discard block
 block discarded – undo
1901 2120
 	//print "- ".$hour.",".$minute.",".$second.",".$month.",".$day.",".$year.",".$_SERVER["WINDIR"]." -";
1902 2121
 
1903 2122
 	// Clean parameters
1904
-	if ($hour   == -1 || empty($hour)) $hour=0;
1905
-	if ($minute == -1 || empty($minute)) $minute=0;
1906
-	if ($second == -1 || empty($second)) $second=0;
2123
+	if ($hour   == -1 || empty($hour)) {
2124
+		$hour=0;
2125
+	}
2126
+	if ($minute == -1 || empty($minute)) {
2127
+		$minute=0;
2128
+	}
2129
+	if ($second == -1 || empty($second)) {
2130
+		$second=0;
2131
+	}
1907 2132
 
1908 2133
 	// Check parameters
1909 2134
 	if ($check)
1910 2135
 	{
1911
-		if (! $month || ! $day)  return '';
1912
-		if ($day   > 31) return '';
1913
-		if ($month > 12) return '';
1914
-		if ($hour  < 0 || $hour   > 24) return '';
1915
-		if ($minute< 0 || $minute > 60) return '';
1916
-		if ($second< 0 || $second > 60) return '';
2136
+		if (! $month || ! $day) {
2137
+			return '';
2138
+		}
2139
+		if ($day   > 31) {
2140
+			return '';
2141
+		}
2142
+		if ($month > 12) {
2143
+			return '';
2144
+		}
2145
+		if ($hour  < 0 || $hour   > 24) {
2146
+			return '';
2147
+		}
2148
+		if ($minute< 0 || $minute > 60) {
2149
+			return '';
2150
+		}
2151
+		if ($second< 0 || $second > 60) {
2152
+			return '';
2153
+		}
1917 2154
 	}
1918 2155
 
1919 2156
 	if (method_exists('DateTime','getTimestamp'))
@@ -1922,28 +2159,24 @@  discard block
 block discarded – undo
1922 2159
 		{
1923 2160
 			$default_timezone=@date_default_timezone_get();		// Example 'Europe/Berlin'
1924 2161
 			$localtz = new DateTimeZone($default_timezone);
1925
-		}
1926
-		else if ($gm === 'user')
2162
+		} else if ($gm === 'user')
1927 2163
 		{
1928 2164
 			// We use dol_tz_string first because it is more reliable.
1929 2165
 			$default_timezone=(empty($_SESSION["dol_tz_string"])?@date_default_timezone_get():$_SESSION["dol_tz_string"]);		// Example 'Europe/Berlin'
1930 2166
 			try {
1931 2167
 				$localtz = new DateTimeZone($default_timezone);
1932
-			}
1933
-			catch(Exception $e)
2168
+			} catch(Exception $e)
1934 2169
 			{
1935 2170
 				dol_syslog("Warning dol_tz_string contains an invalid value ".$_SESSION["dol_tz_string"], LOG_WARNING);
1936 2171
 				$default_timezone=@date_default_timezone_get();
1937 2172
 			}
1938
-		}
1939
-		else if (strrpos($gm, "tz,") !== false)
2173
+		} else if (strrpos($gm, "tz,") !== false)
1940 2174
 		{
1941 2175
 			$timezone=str_replace("tz,", "", $gm);  // Example 'tz,Europe/Berlin'
1942 2176
 			try
1943 2177
 			{
1944 2178
 				$localtz = new DateTimeZone($timezone);
1945
-			}
1946
-			catch(Exception $e)
2179
+			} catch(Exception $e)
1947 2180
 			{
1948 2181
 				dol_syslog("Warning passed timezone contains an invalid value ".$timezone, LOG_WARNING);
1949 2182
 			}
@@ -1960,8 +2193,7 @@  discard block
 block discarded – undo
1960 2193
 		$date=$dt->getTimestamp();	// should include daylight saving time
1961 2194
 		//var_dump($date);
1962 2195
 		return $date;
1963
-	}
1964
-	else
2196
+	} else
1965 2197
 	{
1966 2198
 		dol_print_error('','PHP version must be 5.3+');
1967 2199
 		return '';
@@ -1984,10 +2216,15 @@  discard block
 block discarded – undo
1984 2216
 
1985 2217
 	// Note that gmmktime and mktime return same value (GMT) when used without parameters
1986 2218
 	//if ($mode == 'gmt') $ret=gmmktime(); // Strict Standards: gmmktime(): You should be using the time() function instead
1987
-	if ($mode == 'gmt') $ret=time();	// Time for now at greenwich.
1988
-	else if ($mode == 'tzserver')		// Time for now with PHP server timezone added
2219
+	if ($mode == 'gmt') {
2220
+		$ret=time();
2221
+	}
2222
+	// Time for now at greenwich.
2223
+	else if ($mode == 'tzserver') {
2224
+		// Time for now with PHP server timezone added
1989 2225
 	{
1990 2226
 		require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
2227
+	}
1991 2228
 		$tzsecond=getServerTimeZoneInt('now');    // Contains tz+dayling saving time
1992 2229
 		$ret=(int) dol_now('gmt')+($tzsecond*3600);
1993 2230
 	}
@@ -1997,10 +2234,12 @@  discard block
 block discarded – undo
1997 2234
 		$tzsecond=getParentCompanyTimeZoneInt();    // Contains tz+dayling saving time
1998 2235
 		$ret=dol_now('gmt')+($tzsecond*3600);
1999 2236
 	}*/
2000
-	else if ($mode == 'tzuser')				// Time for now with user timezone added
2237
+	else if ($mode == 'tzuser') {
2238
+		// Time for now with user timezone added
2001 2239
 	{
2002 2240
 		//print 'eeee'.time().'-'.mktime().'-'.gmmktime();
2003 2241
 		$offsettz=(empty($_SESSION['dol_tz'])?0:$_SESSION['dol_tz'])*60*60;
2242
+	}
2004 2243
 		$offsetdst=(empty($_SESSION['dol_dst'])?0:$_SESSION['dol_dst'])*60*60;
2005 2244
 		$ret=(int) dol_now('gmt')+($offsettz+$offsetdst);
2006 2245
 	}
@@ -2022,7 +2261,9 @@  discard block
 block discarded – undo
2022 2261
 	global $conf,$langs;
2023 2262
 	$level=1024;
2024 2263
 
2025
-	if (! empty($conf->dol_optimize_smallscreen)) $shortunit=1;
2264
+	if (! empty($conf->dol_optimize_smallscreen)) {
2265
+		$shortunit=1;
2266
+	}
2026 2267
 
2027 2268
 	// Set value text
2028 2269
 	if (empty($shortvalue) || $size < ($level*10))
@@ -2030,16 +2271,14 @@  discard block
 block discarded – undo
2030 2271
 		$ret=$size;
2031 2272
 		$textunitshort=$langs->trans("b");
2032 2273
 		$textunitlong=$langs->trans("Bytes");
2033
-	}
2034
-	else
2274
+	} else
2035 2275
 	{
2036 2276
 		$ret=round($size/$level,0);
2037 2277
 		$textunitshort=$langs->trans("Kb");
2038 2278
 		$textunitlong=$langs->trans("KiloBytes");
2039 2279
 	}
2040 2280
 	// Use long or short text unit
2041
-	if (empty($shortunit)) { $ret.=' '.$textunitlong; }
2042
-	else { $ret.=' '.$textunitshort; }
2281
+	if (empty($shortunit)) { $ret.=' '.$textunitlong; } else { $ret.=' '.$textunitshort; }
2043 2282
 
2044 2283
 	return $ret;
2045 2284
 }
@@ -2057,15 +2296,23 @@  discard block
 block discarded – undo
2057 2296
 {
2058 2297
 	global $langs;
2059 2298
 
2060
-	if (empty($url)) return '';
2299
+	if (empty($url)) {
2300
+		return '';
2301
+	}
2061 2302
 
2062 2303
 	$link='<a href="';
2063
-	if (! preg_match('/^http/i',$url)) $link.='http://';
2304
+	if (! preg_match('/^http/i',$url)) {
2305
+		$link.='http://';
2306
+	}
2064 2307
 	$link.=$url;
2065 2308
 	$link.='"';
2066
-	if ($target) $link.=' target="'.$target.'"';
2309
+	if ($target) {
2310
+		$link.=' target="'.$target.'"';
2311
+	}
2067 2312
 	$link.='>';
2068
-	if (! preg_match('/^http/i',$url)) $link.='http://';
2313
+	if (! preg_match('/^http/i',$url)) {
2314
+		$link.='http://';
2315
+	}
2069 2316
 	$link.=dol_trunc($url,$max);
2070 2317
 	$link.='</a>';
2071 2318
 	return '<div class="nospan float" style="margin-right: 10px">'.($withpicto?img_picto($langs->trans("Url"), 'object_globe.png').' ':'').$link.'</div>';
@@ -2089,12 +2336,16 @@  discard block
 block discarded – undo
2089 2336
 
2090 2337
 	$newemail=$email;
2091 2338
 
2092
-	if (empty($email)) return '&nbsp;';
2339
+	if (empty($email)) {
2340
+		return '&nbsp;';
2341
+	}
2093 2342
 
2094 2343
 	if (! empty($addlink))
2095 2344
 	{
2096 2345
 		$newemail='<a style="text-overflow: ellipsis;" href="';
2097
-		if (! preg_match('/^mailto:/i',$email)) $newemail.='mailto:';
2346
+		if (! preg_match('/^mailto:/i',$email)) {
2347
+			$newemail.='mailto:';
2348
+		}
2098 2349
 		$newemail.=$email;
2099 2350
 		$newemail.='">';
2100 2351
 		$newemail.=dol_trunc($email,$max);
@@ -2108,11 +2359,14 @@  discard block
 block discarded – undo
2108 2359
 		if (($cid || $socid) && ! empty($conf->agenda->enabled) && $user->rights->agenda->myactions->create)
2109 2360
 		{
2110 2361
 			$type='AC_EMAIL'; $link='';
2111
-			if (! empty($conf->global->AGENDA_ADDACTIONFOREMAIL)) $link='<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&amp;backtopage=1&amp;actioncode='.$type.'&amp;contactid='.$cid.'&amp;socid='.$socid.'">'.img_object($langs->trans("AddAction"),"calendar").'</a>';
2112
-			if ($link) $newemail='<div>'.$newemail.' '.$link.'</div>';
2362
+			if (! empty($conf->global->AGENDA_ADDACTIONFOREMAIL)) {
2363
+				$link='<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&amp;backtopage=1&amp;actioncode='.$type.'&amp;contactid='.$cid.'&amp;socid='.$socid.'">'.img_object($langs->trans("AddAction"),"calendar").'</a>';
2364
+			}
2365
+			if ($link) {
2366
+				$newemail='<div>'.$newemail.' '.$link.'</div>';
2367
+			}
2113 2368
 		}
2114
-	}
2115
-	else
2369
+	} else
2116 2370
 	{
2117 2371
 		if ($showinvalid && ! isValidEmail($email))
2118 2372
 		{
@@ -2139,7 +2393,9 @@  discard block
 block discarded – undo
2139 2393
 
2140 2394
 	$newskype=$skype;
2141 2395
 
2142
-	if (empty($skype)) return '&nbsp;';
2396
+	if (empty($skype)) {
2397
+		return '&nbsp;';
2398
+	}
2143 2399
 
2144 2400
 	if (! empty($addlink))
2145 2401
 	{
@@ -2160,11 +2416,12 @@  discard block
 block discarded – undo
2160 2416
 		if (($cid || $socid) && ! empty($conf->agenda->enabled) && $user->rights->agenda->myactions->create)
2161 2417
 		{
2162 2418
 			$type='AC_SKYPE'; $link='';
2163
-			if (! empty($conf->global->AGENDA_ADDACTIONFORSKYPE)) $link='<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&amp;backtopage=1&amp;actioncode='.$type.'&amp;contactid='.$cid.'&amp;socid='.$socid.'">'.img_object($langs->trans("AddAction"),"calendar").'</a>';
2419
+			if (! empty($conf->global->AGENDA_ADDACTIONFORSKYPE)) {
2420
+				$link='<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&amp;backtopage=1&amp;actioncode='.$type.'&amp;contactid='.$cid.'&amp;socid='.$socid.'">'.img_object($langs->trans("AddAction"),"calendar").'</a>';
2421
+			}
2164 2422
 			$newskype='<div class="divskype nowrap">'.$newskype.($link?' '.$link:'').'</div>';
2165 2423
 		}
2166
-	}
2167
-	else
2424
+	} else
2168 2425
 	{
2169 2426
 		$langs->load("errors");
2170 2427
 		$newskype.=img_warning($langs->trans("ErrorBadSkype",$skype));
@@ -2193,10 +2450,14 @@  discard block
 block discarded – undo
2193 2450
 	// Clean phone parameter
2194 2451
 	$phone = preg_replace("/[\s.-]/","",trim($phone));
2195 2452
 	if (empty($phone)) { return ''; }
2196
-	if (empty($countrycode)) $countrycode=$mysoc->country_code;
2453
+	if (empty($countrycode)) {
2454
+		$countrycode=$mysoc->country_code;
2455
+	}
2197 2456
 
2198 2457
 	// Short format for small screens
2199
-	if ($conf->dol_optimize_smallscreen) $separ='';
2458
+	if ($conf->dol_optimize_smallscreen) {
2459
+		$separ='';
2460
+	}
2200 2461
 
2201 2462
 	$newphone=$phone;
2202 2463
 	if (strtoupper($countrycode) == "FR")
@@ -2204,297 +2465,257 @@  discard block
 block discarded – undo
2204 2465
 		// France
2205 2466
 		if (dol_strlen($phone) == 10) {
2206 2467
 			$newphone=substr($newphone,0,2).$separ.substr($newphone,2,2).$separ.substr($newphone,4,2).$separ.substr($newphone,6,2).$separ.substr($newphone,8,2);
2207
-		}
2208
-		elseif (dol_strlen($phone) == 7)
2468
+		} elseif (dol_strlen($phone) == 7)
2209 2469
 		{
2210 2470
 			$newphone=substr($newphone,0,3).$separ.substr($newphone,3,2).$separ.substr($newphone,5,2);
2211
-		}
2212
-		elseif (dol_strlen($phone) == 9)
2471
+		} elseif (dol_strlen($phone) == 9)
2213 2472
 		{
2214 2473
 			$newphone=substr($newphone,0,2).$separ.substr($newphone,2,3).$separ.substr($newphone,5,2).$separ.substr($newphone,7,2);
2215
-		}
2216
-		elseif (dol_strlen($phone) == 11)
2474
+		} elseif (dol_strlen($phone) == 11)
2217 2475
 		{
2218 2476
 			$newphone=substr($newphone,0,3).$separ.substr($newphone,3,2).$separ.substr($newphone,5,2).$separ.substr($newphone,7,2).$separ.substr($newphone,9,2);
2219
-		}
2220
-		elseif (dol_strlen($phone) == 12)
2477
+		} elseif (dol_strlen($phone) == 12)
2221 2478
 		{
2222 2479
 			$newphone=substr($newphone,0,4).$separ.substr($newphone,4,2).$separ.substr($newphone,6,2).$separ.substr($newphone,8,2).$separ.substr($newphone,10,2);
2223 2480
 		}
2224
-	}
2225
-
2226
-	elseif (strtoupper($countrycode) == "CA")
2481
+	} elseif (strtoupper($countrycode) == "CA")
2227 2482
 	{
2228 2483
 		if (dol_strlen($phone) == 10) {
2229 2484
 			$newphone=($separ!=''?'(':'').substr($newphone,0,3).($separ!=''?')':'').$separ.substr($newphone,3,3).($separ!=''?'-':'').substr($newphone,6,4);
2230 2485
 		}
2231
-	}
2232
-	elseif (strtoupper($countrycode) == "PT" )
2486
+	} elseif (strtoupper($countrycode) == "PT" )
2233 2487
 	{//Portugal
2234 2488
 		if (dol_strlen($phone) == 13)
2235 2489
 		{//ex: +351_ABC_DEF_GHI
2236 2490
 			$newphone= substr($newphone,0,4).$separ.substr($newphone,4,3).$separ.substr($newphone,7,3).$separ.substr($newphone,10,3);
2237 2491
 		}
2238
-	}
2239
-	elseif (strtoupper($countrycode) == "SR" )
2492
+	} elseif (strtoupper($countrycode) == "SR" )
2240 2493
 	{//Suriname
2241 2494
 		if (dol_strlen($phone) == 10)
2242 2495
 		{//ex: +597_ABC_DEF
2243 2496
 			$newphone= substr($newphone,0,4).$separ.substr($newphone,4,3).$separ.substr($newphone,7,3);
2244
-		}
2245
-		elseif (dol_strlen($phone) == 11)
2497
+		} elseif (dol_strlen($phone) == 11)
2246 2498
 		{//ex: +597_ABC_DEFG
2247 2499
 			$newphone= substr($newphone,0,4).$separ.substr($newphone,4,3).$separ.substr($newphone,7,4);
2248 2500
 		}
2249
-	}
2250
-	elseif (strtoupper($countrycode) == "DE" )
2501
+	} elseif (strtoupper($countrycode) == "DE" )
2251 2502
 	{//Allemagne
2252 2503
 		if (dol_strlen($phone) == 14)
2253 2504
 		{//ex:  +49_ABCD_EFGH_IJK
2254 2505
 			$newphone= substr($newphone,0,3).$separ.substr($newphone,3,4).$separ.substr($newphone,7,4).$separ.substr($newphone,11,3);
2255
-		}
2256
-		elseif (dol_strlen($phone) == 13)
2506
+		} elseif (dol_strlen($phone) == 13)
2257 2507
 		{//ex: +49_ABC_DEFG_HIJ
2258 2508
 			$newphone= substr($newphone,0,3).$separ.substr($newphone,3,3).$separ.substr($newphone,6,4).$separ.substr($newphone,10,3);
2259 2509
 		}
2260
-	}
2261
-	elseif (strtoupper($countrycode) == "ES")
2510
+	} elseif (strtoupper($countrycode) == "ES")
2262 2511
 	{//Espagne
2263 2512
 		if (dol_strlen($phone) == 12)
2264 2513
 		{//ex:  +34_ABC_DEF_GHI
2265 2514
 			$newphone= substr($newphone,0,3).$separ.substr($newphone,3,3).$separ.substr($newphone,6,3).$separ.substr($newphone,9,3);
2266 2515
 		}
2267
-	}
2268
-	elseif (strtoupper($countrycode) == "BF")
2516
+	} elseif (strtoupper($countrycode) == "BF")
2269 2517
 	{// Burkina Faso
2270 2518
 		if (dol_strlen($phone) == 12)
2271 2519
 		{//ex :  +22 A BC_DE_FG_HI
2272 2520
 			$newphone= substr($newphone,0,3).$separ.substr($newphone,3,1).$separ.substr($newphone,4,2).$separ.substr($newphone,6,2).$separ.substr($newphone,8,2).$separ.substr($newphone,10,2);
2273 2521
 		}
2274
-	}
2275
-	elseif (strtoupper($countrycode) == "RO")
2522
+	} elseif (strtoupper($countrycode) == "RO")
2276 2523
 	{// Roumanie
2277 2524
 		if (dol_strlen($phone) == 12)
2278 2525
 		{//ex :  +40 AB_CDE_FG_HI
2279 2526
 			$newphone= substr($newphone,0,3).$separ.substr($newphone,3,2).$separ.substr($newphone,5,3).$separ.substr($newphone,8,2).$separ.substr($newphone,10,2);
2280 2527
 		}
2281
-	}
2282
-	elseif (strtoupper($countrycode) == "TR")
2528
+	} elseif (strtoupper($countrycode) == "TR")
2283 2529
 	{//Turquie
2284 2530
 		if (dol_strlen($phone) == 13)
2285 2531
 		{//ex :  +90 ABC_DEF_GHIJ
2286 2532
 			$newphone= substr($newphone,0,3).$separ.substr($newphone,3,3).$separ.substr($newphone,6,3).$separ.substr($newphone,9,4);
2287 2533
 		}
2288
-	}
2289
-	elseif (strtoupper($countrycode) == "US")
2534
+	} elseif (strtoupper($countrycode) == "US")
2290 2535
 	{//Etat-Unis
2291 2536
 		if (dol_strlen($phone) == 12)
2292 2537
 		{//ex: +1 ABC_DEF_GHIJ
2293 2538
 			$newphone= substr($newphone,0,2).$separ.substr($newphone,2,3).$separ.substr($newphone,5,3).$separ.substr($newphone,8,4);
2294 2539
 		}
2295
-	}
2296
-	elseif (strtoupper($countrycode) == "MX")
2540
+	} elseif (strtoupper($countrycode) == "MX")
2297 2541
 	{//Mexique
2298 2542
 		if (dol_strlen($phone) == 12)
2299 2543
 		{//ex: +52 ABCD_EFG_HI
2300 2544
 			$newphone = substr($newphone,0,3).$separ.substr($newphone,3,4).$separ.substr($newphone,7,3).$separ.substr($newphone,10,2);
2301
-		}
2302
-		elseif (dol_strlen($phone) == 11)
2545
+		} elseif (dol_strlen($phone) == 11)
2303 2546
 		{//ex: +52 AB_CD_EF_GH
2304 2547
 			$newphone = substr($newphone,0,3).$separ.substr($newphone,3,2).$separ.substr($newphone,5,2).$separ.substr($newphone,7,2).$separ.substr($newphone,9,2);
2305
-		}
2306
-		elseif (dol_strlen($phone) == 13)
2548
+		} elseif (dol_strlen($phone) == 13)
2307 2549
 		{//ex: +52 ABC_DEF_GHIJ
2308 2550
 			$newphone = substr($newphone,0,3).$separ.substr($newphone,3,3).$separ.substr($newphone,6,3).$separ.substr($newphone,9,4);
2309 2551
 		}
2310
-	}
2311
-	elseif (strtoupper($countrycode) == "ML")
2552
+	} elseif (strtoupper($countrycode) == "ML")
2312 2553
 	{//Mali
2313 2554
 		if(dol_strlen($phone) == 12)
2314 2555
 		{//ex: +223 AB_CD_EF_GH
2315 2556
 			$newphone = substr($newphone,0,4).$separ.substr($newphone,4,2).$separ.substr($newphone,6,2).$separ.substr($newphone,8,2).$separ.substr($newphone,10,2);
2316 2557
 		}
2317
-	}
2318
-	elseif (strtoupper($countrycode) == "TH")
2558
+	} elseif (strtoupper($countrycode) == "TH")
2319 2559
 	{//Thaïlande
2320 2560
 		if(dol_strlen($phone) == 11)
2321 2561
 		{//ex: +66_ABC_DE_FGH
2322 2562
 			$newphone = substr($newphone,0,3).$separ.substr($newphone,3,3).$separ.substr($newphone,6,2).$separ.substr($newphone,8,3);
2323
-		}
2324
-		elseif(dol_strlen($phone) == 12)
2563
+		} elseif(dol_strlen($phone) == 12)
2325 2564
 		{//ex: +66_A_BCD_EF_GHI
2326 2565
 			$newphone = substr($newphone,0,3).$separ.substr($newphone,3,1).$separ.substr($newphone,4,3).$separ.substr($newphone,7,2).$separ.substr($newphone,9,3);
2327 2566
 		}
2328
-		}
2329
-	elseif (strtoupper($countrycode) == "MU")
2567
+		} elseif (strtoupper($countrycode) == "MU")
2330 2568
 	{//Maurice
2331 2569
 		if(dol_strlen($phone) == 11)
2332 2570
 		{//ex: +230_ABC_DE_FG
2333 2571
 			$newphone = substr($newphone,0,4).$separ.substr($newphone,4,3).$separ.substr($newphone,7,2).$separ.substr($newphone,9,2);
2334
-		}
2335
-		elseif(dol_strlen($phone) == 12)
2572
+		} elseif(dol_strlen($phone) == 12)
2336 2573
 		{//ex: +230_ABCD_EF_GH
2337 2574
 			$newphone = substr($newphone,0,4).$separ.substr($newphone,4,4).$separ.substr($newphone,8,2).$separ.substr($newphone,10,2);
2338 2575
 		}
2339
-	}
2340
-	elseif (strtoupper($countrycode) == "ZA")
2576
+	} elseif (strtoupper($countrycode) == "ZA")
2341 2577
 	{//Afrique du sud
2342 2578
 		if(dol_strlen($phone) == 12)
2343 2579
 		{//ex: +27_AB_CDE_FG_HI
2344 2580
 			$newphone = substr($newphone,0,3).$separ.substr($newphone,3,2).$separ.substr($newphone,5,3).$separ.substr($newphone,8,2).$separ.substr($newphone,10,2);
2345 2581
 		}
2346
-	}
2347
-	elseif (strtoupper($countrycode) == "SY")
2582
+	} elseif (strtoupper($countrycode) == "SY")
2348 2583
 	{//Syrie
2349 2584
 		if(dol_strlen($phone) == 12)
2350 2585
 		{//ex: +963_AB_CD_EF_GH
2351 2586
 			$newphone = substr($newphone,0,4).$separ.substr($newphone,4,2).$separ.substr($newphone,6,2).$separ.substr($newphone,8,2).$separ.substr($newphone,10,2);
2352
-		}
2353
-		elseif(dol_strlen($phone) == 13)
2587
+		} elseif(dol_strlen($phone) == 13)
2354 2588
 		{//ex: +963_AB_CD_EF_GHI
2355 2589
 			$newphone = substr($newphone,0,4).$separ.substr($newphone,4,2).$separ.substr($newphone,6,2).$separ.substr($newphone,8,2).$separ.substr($newphone,10,3);
2356 2590
 		}
2357
-	}
2358
-	elseif (strtoupper($countrycode) == "AE")
2591
+	} elseif (strtoupper($countrycode) == "AE")
2359 2592
 	{//Emirats Arabes Unis
2360 2593
 		if(dol_strlen($phone) == 12)
2361 2594
 		{//ex: +971_ABC_DEF_GH
2362 2595
 			$newphone = substr($newphone,0,4).$separ.substr($newphone,4,3).$separ.substr($newphone,7,3).$separ.substr($newphone,10,2);
2363
-		}
2364
-		elseif(dol_strlen($phone) == 13)
2596
+		} elseif(dol_strlen($phone) == 13)
2365 2597
 		{//ex: +971_ABC_DEF_GHI
2366 2598
 			$newphone = substr($newphone,0,4).$separ.substr($newphone,4,3).$separ.substr($newphone,7,3).$separ.substr($newphone,10,3);
2367
-		}
2368
-		elseif(dol_strlen($phone) == 14)
2599
+		} elseif(dol_strlen($phone) == 14)
2369 2600
 		{//ex: +971_ABC_DEF_GHIK
2370 2601
 			$newphone = substr($newphone,0,4).$separ.substr($newphone,4,3).$separ.substr($newphone,7,3).$separ.substr($newphone,10,4);
2371 2602
 		}
2372
-	}
2373
-	elseif (strtoupper($countrycode) == "DZ")
2603
+	} elseif (strtoupper($countrycode) == "DZ")
2374 2604
 	{//Algérie
2375 2605
 		if(dol_strlen($phone) == 13)
2376 2606
 		{//ex: +213_ABC_DEF_GHI
2377 2607
 			$newphone = substr($newphone,0,4).$separ.substr($newphone,4,3).$separ.substr($newphone,7,3).$separ.substr($newphone,10,3);
2378 2608
 		}
2379
-	}
2380
-	elseif (strtoupper($countrycode) == "BE")
2609
+	} elseif (strtoupper($countrycode) == "BE")
2381 2610
 	{//Belgique
2382 2611
 		if(dol_strlen($phone) == 11)
2383 2612
 		{//ex: +32_ABC_DE_FGH
2384 2613
 			$newphone = substr($newphone,0,3).$separ.substr($newphone,3,3).$separ.substr($newphone,6,2).$separ.substr($newphone,8,3);
2385
-		}
2386
-		elseif(dol_strlen($phone) == 12)
2614
+		} elseif(dol_strlen($phone) == 12)
2387 2615
 		{//ex: +32_ABC_DEF_GHI
2388 2616
 			$newphone = substr($newphone,0,3).$separ.substr($newphone,3,3).$separ.substr($newphone,6,3).$separ.substr($newphone,9,3);
2389 2617
 		}
2390
-	}
2391
-	elseif (strtoupper($countrycode) == "PF")
2618
+	} elseif (strtoupper($countrycode) == "PF")
2392 2619
 	{//Polynésie française
2393 2620
 		if(dol_strlen($phone) == 12)
2394 2621
 		{//ex: +689_AB_CD_EF_GH
2395 2622
 			$newphone = substr($newphone,0,4).$separ.substr($newphone,4,2).$separ.substr($newphone,6,2).$separ.substr($newphone,8,2).$separ.substr($newphone,10,2);
2396 2623
 		}
2397
-	}
2398
-	elseif (strtoupper($countrycode) == "CO")
2624
+	} elseif (strtoupper($countrycode) == "CO")
2399 2625
 	{//Colombie
2400 2626
 		if(dol_strlen($phone) == 13)
2401 2627
 		{//ex: +57_ABC_DEF_GH_IJ
2402 2628
 			$newphone = substr($newphone,0,3).$separ.substr($newphone,3,3).$separ.substr($newphone,6,3).$separ.substr($newphone,9,2).$separ.substr($newphone,11,2);
2403 2629
 		}
2404
-	}
2405
-	elseif (strtoupper($countrycode) == "JO")
2630
+	} elseif (strtoupper($countrycode) == "JO")
2406 2631
 	{//Jordanie
2407 2632
 		if(dol_strlen($phone) == 12)
2408 2633
 		{//ex: +962_A_BCD_EF_GH
2409 2634
 			$newphone = substr($newphone,0,4).$separ.substr($newphone,4,1).$separ.substr($newphone,5,3).$separ.substr($newphone,7,2).$separ.substr($newphone,9,2);
2410 2635
 		}
2411
-	}
2412
-	elseif (strtoupper($countrycode) == "MG")
2636
+	} elseif (strtoupper($countrycode) == "MG")
2413 2637
 	{//Madagascar
2414 2638
 		if(dol_strlen($phone) == 13)
2415 2639
 		{//ex: +261_AB_CD_EF_GHI
2416 2640
 			$newphone = substr($newphone,0,4).$separ.substr($newphone,4,2).$separ.substr($newphone,6,2).$separ.substr($newphone,8,2).$separ.substr($newphone,10,3);
2417 2641
 		}
2418
-	}
2419
-	elseif (strtoupper($countrycode) == "GB")
2642
+	} elseif (strtoupper($countrycode) == "GB")
2420 2643
 	{//Royaume uni
2421 2644
 		if(dol_strlen($phone) == 13)
2422 2645
 		{//ex: +44_ABCD_EFG_HIJ
2423 2646
 			$newphone = substr($newphone,0,3).$separ.substr($newphone,3,4).$separ.substr($newphone,7,3).$separ.substr($newphone,10,3);
2424 2647
 		}
2425
-	}
2426
-	elseif (strtoupper($countrycode) == "CH")
2648
+	} elseif (strtoupper($countrycode) == "CH")
2427 2649
 	{//Suisse
2428 2650
 		if(dol_strlen($phone) == 12)
2429 2651
 		{//ex: +41_AB_CDE_FG_HI
2430 2652
 			$newphone = substr($newphone,0,3).$separ.substr($newphone,3,2).$separ.substr($newphone,5,3).$separ.substr($newphone,8,2).$separ.substr($newphone,10,2);
2431
-		}
2432
-		elseif(dol_strlen($phone) == 15)
2653
+		} elseif(dol_strlen($phone) == 15)
2433 2654
 		{// +41_AB_CDE_FGH_IJKL
2434 2655
 			$newphone =$newphone = substr($newphone,0,3).$separ.substr($newphone,3,2).$separ.substr($newphone,5,3).$separ.substr($newphone,8,3).$separ.substr($newphone,11,4);
2435 2656
 		}
2436
-	}
2437
-	elseif (strtoupper($countrycode) == "TN")
2657
+	} elseif (strtoupper($countrycode) == "TN")
2438 2658
 	{//Tunisie
2439 2659
 		if(dol_strlen($phone) == 12)
2440 2660
 		{//ex: +216_AB_CDE_FGH
2441 2661
 			$newphone = substr($newphone,0,4).$separ.substr($newphone,4,2).$separ.substr($newphone,6,3).$separ.substr($newphone,9,3);
2442 2662
 		}
2443
-	}
2444
-	elseif (strtoupper($countrycode) == "GF")
2663
+	} elseif (strtoupper($countrycode) == "GF")
2445 2664
 	{//Guyane francaise
2446 2665
 		if(dol_strlen($phone) == 13)
2447 2666
 		{//ex: +594_ABC_DE_FG_HI  (ABC=594 de nouveau)
2448 2667
 			$newphone = substr($newphone,0,4).$separ.substr($newphone,4,3).$separ.substr($newphone,7,2).$separ.substr($newphone,9,2).$separ.substr($newphone,11,2);
2449 2668
 		}
2450
-	}
2451
-	elseif (strtoupper($countrycode) == "GP")
2669
+	} elseif (strtoupper($countrycode) == "GP")
2452 2670
 	{//Guadeloupe
2453 2671
 		if(dol_strlen($phone) == 13)
2454 2672
 		{//ex: +590_ABC_DE_FG_HI  (ABC=590 de nouveau)
2455 2673
 			$newphone = substr($newphone,0,4).$separ.substr($newphone,4,3).$separ.substr($newphone,7,2).$separ.substr($newphone,9,2).$separ.substr($newphone,11,2);
2456 2674
 		}
2457
-	}
2458
-	elseif (strtoupper($countrycode) == "MQ")
2675
+	} elseif (strtoupper($countrycode) == "MQ")
2459 2676
 	{//Martinique
2460 2677
 		if(dol_strlen($phone) == 13)
2461 2678
 		{//ex: +596_ABC_DE_FG_HI  (ABC=596 de nouveau)
2462 2679
 			$newphone = substr($newphone,0,4).$separ.substr($newphone,4,3).$separ.substr($newphone,7,2).$separ.substr($newphone,9,2).$separ.substr($newphone,11,2);
2463 2680
 		}
2464
-	}
2465
-	elseif (strtoupper($countrycode) == "IT")
2681
+	} elseif (strtoupper($countrycode) == "IT")
2466 2682
 	{//Italie
2467 2683
 		if(dol_strlen($phone) == 12)
2468 2684
 		{//ex: +39_ABC_DEF_GHI
2469 2685
 			$newphone = substr($newphone,0,3).$separ.substr($newphone,3,3).$separ.substr($newphone,6,3).$separ.substr($newphone,9,3);
2470
-		}
2471
-		elseif(dol_strlen($phone) == 13)
2686
+		} elseif(dol_strlen($phone) == 13)
2472 2687
 		{//ex: +39_ABC_DEF_GH_IJ
2473 2688
 			$newphone = substr($newphone,0,3).$separ.substr($newphone,3,3).$separ.substr($newphone,6,3).$separ.substr($newphone,9,2).$separ.substr($newphone,11,2);
2474 2689
 		}
2475
-	}
2476
-	elseif(strtoupper($countrycode) == "AU")
2690
+	} elseif(strtoupper($countrycode) == "AU")
2477 2691
 	{//Australie
2478 2692
 		 if(dol_strlen($phone) == 12)
2479 2693
 		{//ex: +61_A_BCDE_FGHI
2480 2694
 			$newphone = substr($newphone,0,3).$separ.substr($newphone,3,1).$separ.substr($newphone,4,4).$separ.substr($newphone,8,4);
2481 2695
 		}
2482 2696
 	}
2483
-	if (! empty($addlink))	// Link on phone number (+ link to add action if conf->global->AGENDA_ADDACTIONFORPHONE set)
2697
+	if (! empty($addlink)) {
2698
+		// Link on phone number (+ link to add action if conf->global->AGENDA_ADDACTIONFORPHONE set)
2484 2699
 	{
2485 2700
 		if (! empty($conf->browser->phone) || (! empty($conf->clicktodial->enabled) && ! empty($conf->global->CLICKTODIAL_USE_TEL_LINK_ON_PHONE_NUMBERS)))	// If phone or option for, we use link of phone
2486 2701
 		{
2487 2702
 			$newphone ='<a href="tel:'.$phone.'"';
2703
+	}
2488 2704
 			$newphone.='>'.$phone.'</a>';
2489
-		}
2490
-		else if (! empty($conf->clicktodial->enabled) && $addlink == 'AC_TEL')		// If click to dial, we use click to dial url
2705
+		} else if (! empty($conf->clicktodial->enabled) && $addlink == 'AC_TEL') {
2706
+			// If click to dial, we use click to dial url
2491 2707
 		{
2492 2708
 			if (empty($user->clicktodial_loaded)) $user->fetch_clicktodial();
2709
+		}
2493 2710
 
2494 2711
 			// Define urlmask
2495 2712
 			$urlmask='ErrorClickToDialModuleNotConfigured';
2496
-			if (! empty($conf->global->CLICKTODIAL_URL)) $urlmask=$conf->global->CLICKTODIAL_URL;
2497
-			if (! empty($user->clicktodial_url)) $urlmask=$user->clicktodial_url;
2713
+			if (! empty($conf->global->CLICKTODIAL_URL)) {
2714
+				$urlmask=$conf->global->CLICKTODIAL_URL;
2715
+			}
2716
+			if (! empty($user->clicktodial_url)) {
2717
+				$urlmask=$user->clicktodial_url;
2718
+			}
2498 2719
 
2499 2720
 			$clicktodial_poste=(! empty($user->clicktodial_poste)?urlencode($user->clicktodial_poste):'');
2500 2721
 			$clicktodial_login=(! empty($user->clicktodial_login)?urlencode($user->clicktodial_login):'');
@@ -2509,7 +2730,9 @@  discard block
 block discarded – undo
2509 2730
 			$url = make_substitutions($url, $substitarray);
2510 2731
 			$newphonesav=$newphone;
2511 2732
 			$newphone ='<a href="'.$url.'"';
2512
-			if (! empty($conf->global->CLICKTODIAL_FORCENEWTARGET)) $newphone.=' target="_blank"';
2733
+			if (! empty($conf->global->CLICKTODIAL_FORCENEWTARGET)) {
2734
+				$newphone.=' target="_blank"';
2735
+			}
2513 2736
 			$newphone.='>'.$newphonesav.'</a>';
2514 2737
 		}
2515 2738
 
@@ -2517,9 +2740,15 @@  discard block
 block discarded – undo
2517 2740
 		if (! empty($conf->agenda->enabled) && $user->rights->agenda->myactions->create)
2518 2741
 		{
2519 2742
 			$type='AC_TEL'; $link='';
2520
-			if ($addlink == 'AC_FAX') $type='AC_FAX';
2521
-			if (! empty($conf->global->AGENDA_ADDACTIONFORPHONE)) $link='<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&amp;backtopage=1&amp;actioncode='.$type.($cid?'&amp;contactid='.$cid:'').($socid?'&amp;socid='.$socid:'').'">'.img_object($langs->trans("AddAction"),"calendar").'</a>';
2522
-			if ($link) $newphone='<div>'.$newphone.' '.$link.'</div>';
2743
+			if ($addlink == 'AC_FAX') {
2744
+				$type='AC_FAX';
2745
+			}
2746
+			if (! empty($conf->global->AGENDA_ADDACTIONFORPHONE)) {
2747
+				$link='<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&amp;backtopage=1&amp;actioncode='.$type.($cid?'&amp;contactid='.$cid:'').($socid?'&amp;socid='.$socid:'').'">'.img_object($langs->trans("AddAction"),"calendar").'</a>';
2748
+			}
2749
+			if ($link) {
2750
+				$newphone='<div>'.$newphone.' '.$link.'</div>';
2751
+			}
2523 2752
 		}
2524 2753
 	}
2525 2754
 
@@ -2540,19 +2769,25 @@  discard block
 block discarded – undo
2540 2769
 		if($withpicto){
2541 2770
 			if($withpicto=='fax'){
2542 2771
 				$picto = 'phoning_fax';
2543
-			}elseif($withpicto=='phone'){
2772
+			} elseif($withpicto=='phone'){
2544 2773
 				$picto = 'phoning';
2545
-			}elseif($withpicto=='mobile'){
2774
+			} elseif($withpicto=='mobile'){
2546 2775
 				$picto = 'phoning_mobile';
2547
-			}else{
2776
+			} else{
2548 2777
 				$picto = '';
2549 2778
 			}
2550 2779
 		}
2551
-		if ($adddivfloat) $rep.='<div class="nospan float" style="margin-right: 10px">';
2552
-		else $rep.='<span style="margin-right: 10px;">';
2780
+		if ($adddivfloat) {
2781
+			$rep.='<div class="nospan float" style="margin-right: 10px">';
2782
+		} else {
2783
+			$rep.='<span style="margin-right: 10px;">';
2784
+		}
2553 2785
 		$rep.=($withpicto?img_picto($titlealt, 'object_'.$picto.'.png').' ':'').$newphone;
2554
-		if ($adddivfloat) $rep.='</div>';
2555
-		else $rep.='</span>';
2786
+		if ($adddivfloat) {
2787
+			$rep.='</div>';
2788
+		} else {
2789
+			$rep.='</span>';
2790
+		}
2556 2791
 	  }
2557 2792
 
2558 2793
 	return $rep;
@@ -2571,18 +2806,23 @@  discard block
 block discarded – undo
2571 2806
 
2572 2807
 	$ret='';
2573 2808
 
2574
-	if (empty($mode)) $ret.=$ip;
2809
+	if (empty($mode)) {
2810
+		$ret.=$ip;
2811
+	}
2575 2812
 
2576 2813
 	if ($mode != 2)
2577 2814
 	{
2578 2815
 		$countrycode=dolGetCountryCodeFromIp($ip);
2579
-		if ($countrycode)	// If success, countrycode is us, fr, ...
2816
+		if ($countrycode) {
2817
+			// If success, countrycode is us, fr, ...
2580 2818
 		{
2581 2819
 			if (file_exists(DOL_DOCUMENT_ROOT.'/theme/common/flags/'.$countrycode.'.png'))
2582 2820
 			{
2583 2821
 				$ret.=' '.img_picto($countrycode.' '.$langs->trans("AccordingToGeoIPDatabase"),DOL_URL_ROOT.'/theme/common/flags/'.$countrycode.'.png','',1);
2822
+		}
2823
+			} else {
2824
+				$ret.=' ('.$countrycode.')';
2584 2825
 			}
2585
-			else $ret.=' ('.$countrycode.')';
2586 2826
 		}
2587 2827
 	}
2588 2828
 
@@ -2671,18 +2911,33 @@  discard block
 block discarded – undo
2671 2911
 		}
2672 2912
 		if (empty($reshook))
2673 2913
 		{
2674
-			if (empty($charfornl)) $out.=nl2br($address);
2675
-			else $out.=preg_replace('/[\r\n]+/', $charfornl, $address);
2914
+			if (empty($charfornl)) {
2915
+				$out.=nl2br($address);
2916
+			} else {
2917
+				$out.=preg_replace('/[\r\n]+/', $charfornl, $address);
2918
+			}
2676 2919
 
2677 2920
 			$showgmap=$showomap=0;
2678 2921
 
2679 2922
 			// TODO Add a hook here
2680
-			if (($mode=='thirdparty' || $mode =='societe') && ! empty($conf->google->enabled) && ! empty($conf->global->GOOGLE_ENABLE_GMAPS)) $showgmap=1;
2681
-			if ($mode=='contact' && ! empty($conf->google->enabled) && ! empty($conf->global->GOOGLE_ENABLE_GMAPS_CONTACTS)) $showgmap=1;
2682
-			if ($mode=='member' && ! empty($conf->google->enabled) && ! empty($conf->global->GOOGLE_ENABLE_GMAPS_MEMBERS)) $showgmap=1;
2683
-			if (($mode=='thirdparty' || $mode =='societe') && ! empty($conf->openstreetmap->enabled) && ! empty($conf->global->OPENSTREETMAP_ENABLE_MAPS)) $showomap=1;
2684
-			if ($mode=='contact' && ! empty($conf->openstreetmap->enabled) && ! empty($conf->global->OPENSTREETMAP_ENABLE_MAPS_CONTACTS)) $showomap=1;
2685
-			if ($mode=='member' && ! empty($conf->openstreetmap->enabled) && ! empty($conf->global->OPENSTREETMAP_ENABLE_MAPS_MEMBERS)) $showomap=1;
2923
+			if (($mode=='thirdparty' || $mode =='societe') && ! empty($conf->google->enabled) && ! empty($conf->global->GOOGLE_ENABLE_GMAPS)) {
2924
+				$showgmap=1;
2925
+			}
2926
+			if ($mode=='contact' && ! empty($conf->google->enabled) && ! empty($conf->global->GOOGLE_ENABLE_GMAPS_CONTACTS)) {
2927
+				$showgmap=1;
2928
+			}
2929
+			if ($mode=='member' && ! empty($conf->google->enabled) && ! empty($conf->global->GOOGLE_ENABLE_GMAPS_MEMBERS)) {
2930
+				$showgmap=1;
2931
+			}
2932
+			if (($mode=='thirdparty' || $mode =='societe') && ! empty($conf->openstreetmap->enabled) && ! empty($conf->global->OPENSTREETMAP_ENABLE_MAPS)) {
2933
+				$showomap=1;
2934
+			}
2935
+			if ($mode=='contact' && ! empty($conf->openstreetmap->enabled) && ! empty($conf->global->OPENSTREETMAP_ENABLE_MAPS_CONTACTS)) {
2936
+				$showomap=1;
2937
+			}
2938
+			if ($mode=='member' && ! empty($conf->openstreetmap->enabled) && ! empty($conf->global->OPENSTREETMAP_ENABLE_MAPS_MEMBERS)) {
2939
+				$showomap=1;
2940
+			}
2686 2941
 
2687 2942
 			if ($showgmap)
2688 2943
 			{
@@ -2696,9 +2951,12 @@  discard block
 block discarded – undo
2696 2951
 			}
2697 2952
 		}
2698 2953
 	}
2699
-	if ($noprint) return $out;
2700
-	else print $out;
2701
-}
2954
+	if ($noprint) {
2955
+		return $out;
2956
+	} else {
2957
+		print $out;
2958
+	}
2959
+	}
2702 2960
 
2703 2961
 
2704 2962
 /**
@@ -2710,8 +2968,12 @@  discard block
 block discarded – undo
2710 2968
  */
2711 2969
 function isValidEmail($address, $acceptsupervisorkey=0)
2712 2970
 {
2713
-	if ($acceptsupervisorkey && $address == '__SUPERVISOREMAIL__') return true;
2714
-	if (filter_var($address, FILTER_VALIDATE_EMAIL)) return true;
2971
+	if ($acceptsupervisorkey && $address == '__SUPERVISOREMAIL__') {
2972
+		return true;
2973
+	}
2974
+	if (filter_var($address, FILTER_VALIDATE_EMAIL)) {
2975
+		return true;
2976
+	}
2715 2977
 
2716 2978
 	return false;
2717 2979
 }
@@ -2738,9 +3000,12 @@  discard block
 block discarded – undo
2738 3000
  */
2739 3001
 function dol_strlen($string,$stringencoding='UTF-8')
2740 3002
 {
2741
-	if (function_exists('mb_strlen')) return mb_strlen($string,$stringencoding);
2742
-	else return strlen($string);
2743
-}
3003
+	if (function_exists('mb_strlen')) {
3004
+		return mb_strlen($string,$stringencoding);
3005
+	} else {
3006
+		return strlen($string);
3007
+	}
3008
+	}
2744 3009
 
2745 3010
 /**
2746 3011
  * Make a substring. Works even in mbstring module is not enabled.
@@ -2755,14 +3020,15 @@  discard block
 block discarded – undo
2755 3020
 {
2756 3021
 	global $langs;
2757 3022
 
2758
-	if (empty($stringencoding)) $stringencoding=$langs->charset_output;
3023
+	if (empty($stringencoding)) {
3024
+		$stringencoding=$langs->charset_output;
3025
+	}
2759 3026
 
2760 3027
 	$ret='';
2761 3028
 	if (function_exists('mb_substr'))
2762 3029
 	{
2763 3030
 		$ret=mb_substr($string,$start,$length,$stringencoding);
2764
-	}
2765
-	else
3031
+	} else
2766 3032
 	{
2767 3033
 		$ret=substr($string,$start,$length);
2768 3034
 	}
@@ -2802,7 +3068,9 @@  discard block
 block discarded – undo
2802 3068
 		return;
2803 3069
 	}
2804 3070
 
2805
-	if (empty($conf->use_javascript_ajax)) return;
3071
+	if (empty($conf->use_javascript_ajax)) {
3072
+		return;
3073
+	}
2806 3074
 	$jsgraphlib='flot';
2807 3075
 	$datacolor=array();
2808 3076
 
@@ -2860,11 +3128,17 @@  discard block
 block discarded – undo
2860 3128
 										var number=series.data[0][1];
2861 3129
 										return \'';
2862 3130
 										print '<div style="font-size:8pt;text-align:center;padding:2px;color:black;">';
2863
-										if ($url) print '<a style="color: #FFFFFF;" border="0" href="'.$url.'">';
3131
+										if ($url) {
3132
+											print '<a style="color: #FFFFFF;" border="0" href="'.$url.'">';
3133
+										}
2864 3134
 										print '\'+'.($showlegend?'number':'label+\' \'+number');
2865
-										if (! empty($showpercent)) print '+\'<br/>\'+percent+\'%\'';
3135
+										if (! empty($showpercent)) {
3136
+											print '+\'<br/>\'+percent+\'%\'';
3137
+										}
2866 3138
 										print '+\'';
2867
-										if ($url) print '</a>';
3139
+										if ($url) {
3140
+											print '</a>';
3141
+										}
2868 3142
 										print '</div>\';
2869 3143
 									},
2870 3144
 									background: {
@@ -2890,8 +3164,7 @@  discard block
 block discarded – undo
2890 3164
 				plotWithOptions();
2891 3165
 			});
2892 3166
 			</script>';
2893
-		}
2894
-		else if ($type == 'barline')
3167
+		} else if ($type == 'barline')
2895 3168
 		{
2896 3169
 			// data is   array('series'=>array(serie1,serie2,...),
2897 3170
 			//                 'seriestype'=>array('bar','line',...),
@@ -2906,18 +3179,24 @@  discard block
 block discarded – undo
2906 3179
 				foreach($data['series'] as $serie)
2907 3180
 				{
2908 3181
 					if ($data['seriestype'][$i]=='line') { $i++; continue; };
2909
-					if ($outputserie > 0) print ',';
3182
+					if ($outputserie > 0) {
3183
+						print ',';
3184
+					}
2910 3185
 					print '{ bars: { stack: 0, show: true, barWidth: 0.9, align: \'center\' }, label: \''.dol_escape_js($serie['label']).'\', data: '.json_encode($serie['data']).'}'."\n";
2911 3186
 					$outputserie++; $i++;
2912 3187
 				}
2913
-				if ($outputserie) print ', ';
3188
+				if ($outputserie) {
3189
+					print ', ';
3190
+				}
2914 3191
 				//print '];
2915 3192
 				//var datalines = [';
2916 3193
 				$i=0; $outputserie=0;
2917 3194
 				foreach($data['series'] as $serie)
2918 3195
 				{
2919 3196
 					if (empty($data['seriestype'][$i]) || $data['seriestype'][$i]=='bar') { $i++; continue; };
2920
-					if ($outputserie > 0) print ',';
3197
+					if ($outputserie > 0) {
3198
+						print ',';
3199
+					}
2921 3200
 					print '{ lines: { show: true }, label: \''.dol_escape_js($serie['label']).'\', data: '.json_encode($serie['data']).'}'."\n";
2922 3201
 					$outputserie++; $i++;
2923 3202
 				}
@@ -2947,8 +3226,9 @@  discard block
 block discarded – undo
2947 3226
 				plotWithOptions();
2948 3227
 			});
2949 3228
 			</script>';
3229
+		} else {
3230
+			print 'BadValueForParameterType';
2950 3231
 		}
2951
-		else print 'BadValueForParameterType';
2952 3232
 	}
2953 3233
 }
2954 3234
 
@@ -2969,23 +3249,30 @@  discard block
 block discarded – undo
2969 3249
 {
2970 3250
 	global $conf;
2971 3251
 
2972
-	if ($size==0 || ! empty($conf->global->MAIN_DISABLE_TRUNC)) return $string;
3252
+	if ($size==0 || ! empty($conf->global->MAIN_DISABLE_TRUNC)) {
3253
+		return $string;
3254
+	}
2973 3255
 
2974
-	if (empty($stringencoding)) $stringencoding='UTF-8';
3256
+	if (empty($stringencoding)) {
3257
+		$stringencoding='UTF-8';
3258
+	}
2975 3259
 	// reduce for small screen
2976
-	if ($conf->dol_optimize_smallscreen==1 && $display==1) $size = round($size/3);
3260
+	if ($conf->dol_optimize_smallscreen==1 && $display==1) {
3261
+		$size = round($size/3);
3262
+	}
2977 3263
 
2978 3264
 	// We go always here
2979 3265
 	if ($trunc == 'right')
2980 3266
 	{
2981 3267
 		$newstring=dol_textishtml($string)?dol_string_nohtmltag($string,1):$string;
2982
-		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 ...
3268
+		if (dol_strlen($newstring,$stringencoding) > ($size+($nodot?0:3))) {
3269
+			// If nodot is 0 and size is 1,2 or 3 chars more, we don't trunc and don't add ...
2983 3270
 		return dol_substr($newstring,0,$size,$stringencoding).($nodot?'':'...');
2984
-		else
2985
-		//return 'u'.$size.'-'.$newstring.'-'.dol_strlen($newstring,$stringencoding).'-'.$string;
3271
+		} else {
3272
+				//return 'u'.$size.'-'.$newstring.'-'.dol_strlen($newstring,$stringencoding).'-'.$string;
2986 3273
 		return $string;
2987
-	}
2988
-	elseif ($trunc == 'middle')
3274
+		}
3275
+	} elseif ($trunc == 'middle')
2989 3276
 	{
2990 3277
 		$newstring=dol_textishtml($string)?dol_string_nohtmltag($string,1):$string;
2991 3278
 		if (dol_strlen($newstring,$stringencoding) > 2 && dol_strlen($newstring,$stringencoding) > ($size+1))
@@ -2993,28 +3280,30 @@  discard block
 block discarded – undo
2993 3280
 			$size1=round($size/2);
2994 3281
 			$size2=round($size/2);
2995 3282
 			return dol_substr($newstring,0,$size1,$stringencoding).'...'.dol_substr($newstring,dol_strlen($newstring,$stringencoding) - $size2,$size2,$stringencoding);
3283
+		} else {
3284
+				return $string;
2996 3285
 		}
2997
-		else
2998
-		return $string;
2999
-	}
3000
-	elseif ($trunc == 'left')
3286
+	} elseif ($trunc == 'left')
3001 3287
 	{
3002 3288
 		$newstring=dol_textishtml($string)?dol_string_nohtmltag($string,1):$string;
3003
-		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 ...
3289
+		if (dol_strlen($newstring,$stringencoding) > ($size+($nodot?0:3))) {
3290
+			// If nodot is 0 and size is 1,2 or 3 chars more, we don't trunc and don't add ...
3004 3291
 		return '...'.dol_substr($newstring,dol_strlen($newstring,$stringencoding) - $size,$size,$stringencoding);
3005
-		else
3006
-		return $string;
3007
-	}
3008
-	elseif ($trunc == 'wrap')
3292
+		} else {
3293
+				return $string;
3294
+		}
3295
+	} elseif ($trunc == 'wrap')
3009 3296
 	{
3010 3297
 		$newstring=dol_textishtml($string)?dol_string_nohtmltag($string,1):$string;
3011
-		if (dol_strlen($newstring,$stringencoding) > ($size+1))
3012
-		return dol_substr($newstring,0,$size,$stringencoding)."\n".dol_trunc(dol_substr($newstring,$size,dol_strlen($newstring,$stringencoding)-$size,$stringencoding),$size,$trunc);
3013
-		else
3014
-		return $string;
3298
+		if (dol_strlen($newstring,$stringencoding) > ($size+1)) {
3299
+				return dol_substr($newstring,0,$size,$stringencoding)."\n".dol_trunc(dol_substr($newstring,$size,dol_strlen($newstring,$stringencoding)-$size,$stringencoding),$size,$trunc);
3300
+		} else {
3301
+				return $string;
3302
+		}
3303
+	} else {
3304
+		return 'BadParam3CallingDolTrunc';
3305
+	}
3015 3306
 	}
3016
-	else return 'BadParam3CallingDolTrunc';
3017
-}
3018 3307
 
3019 3308
 /**
3020 3309
  *	Show picto whatever it's its name (generic function)
@@ -3042,10 +3331,11 @@  discard block
 block discarded – undo
3042 3331
 	if ($pictoisfullpath)
3043 3332
 	{
3044 3333
 		// Clean parameters
3045
-		if (! preg_match('/(\.png|\.gif|\.svg)$/i',$picto)) $picto .= '.png';
3334
+		if (! preg_match('/(\.png|\.gif|\.svg)$/i',$picto)) {
3335
+			$picto .= '.png';
3336
+		}
3046 3337
 		$fullpathpicto = $picto;
3047
-	}
3048
-	else
3338
+	} else
3049 3339
 	{
3050 3340
 		//if (in_array($picto, array('switch_off', 'switch_on', 'off', 'on')))
3051 3341
 		if (in_array($picto, array('switch_off', 'switch_on', 'off', 'on')))
@@ -3057,7 +3347,9 @@  discard block
 block discarded – undo
3057 3347
 			if ($picto == 'on')  { $fakey = 'fa-check-square-o'; $fasize='1.3em'; }
3058 3348
 			$enabledisablehtml='';
3059 3349
 			$enabledisablehtml.='<span class="fa '.$fakey.' valignmiddle'.($morecss?' '.$morecss:'').'" style="'.($fasize?('font-size: '.$fasize.';'):'').($facolor?(' color: '.$facolor.';'):'').'" alt="'.dol_escape_htmltag($titlealt).'" title="'.dol_escape_htmltag($titlealt).'"'.($moreatt?' '.$moreatt:'').'">';
3060
-			if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) $enabledisablehtml.=$titlealt;
3350
+			if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
3351
+				$enabledisablehtml.=$titlealt;
3352
+			}
3061 3353
 			$enabledisablehtml.='</span>';
3062 3354
 			return $enabledisablehtml;
3063 3355
 		}
@@ -3067,9 +3359,18 @@  discard block
 block discarded – undo
3067 3359
 		$theme = $conf->theme;
3068 3360
 
3069 3361
 		$path = 'theme/'.$theme;
3070
-		if (! empty($conf->global->MAIN_OVERWRITE_THEME_PATH)) $path = $conf->global->MAIN_OVERWRITE_THEME_PATH.'/theme/'.$theme;	// If the theme does not have the same name as the module
3071
-		else if (! empty($conf->global->MAIN_OVERWRITE_THEME_RES)) $path = $conf->global->MAIN_OVERWRITE_THEME_RES.'/theme/'.$conf->global->MAIN_OVERWRITE_THEME_RES;  // To allow an external module to overwrite image resources whatever is activated theme
3072
-		else if (! empty($conf->modules_parts['theme']) && array_key_exists($theme, $conf->modules_parts['theme'])) $path = $theme.'/theme/'.$theme;	// If the theme have the same name as the module
3362
+		if (! empty($conf->global->MAIN_OVERWRITE_THEME_PATH)) {
3363
+			$path = $conf->global->MAIN_OVERWRITE_THEME_PATH.'/theme/'.$theme;
3364
+		}
3365
+		// If the theme does not have the same name as the module
3366
+		else if (! empty($conf->global->MAIN_OVERWRITE_THEME_RES)) {
3367
+			$path = $conf->global->MAIN_OVERWRITE_THEME_RES.'/theme/'.$conf->global->MAIN_OVERWRITE_THEME_RES;
3368
+		}
3369
+		// To allow an external module to overwrite image resources whatever is activated theme
3370
+		else if (! empty($conf->modules_parts['theme']) && array_key_exists($theme, $conf->modules_parts['theme'])) {
3371
+			$path = $theme.'/theme/'.$theme;
3372
+		}
3373
+		// If the theme have the same name as the module
3073 3374
 
3074 3375
 		// If we ask an image into $url/$mymodule/img (instead of default path)
3075 3376
 		if (preg_match('/^([^@]+)@([^@]+)$/i',$picto,$regs))
@@ -3079,14 +3380,20 @@  discard block
 block discarded – undo
3079 3380
 		}
3080 3381
 
3081 3382
 		// Clean parameters
3082
-		if (! preg_match('/(\.png|\.gif|\.svg)$/i',$picto)) $picto .= '.png';
3383
+		if (! preg_match('/(\.png|\.gif|\.svg)$/i',$picto)) {
3384
+			$picto .= '.png';
3385
+		}
3083 3386
 		// If alt path are defined, define url where img file is, according to physical path
3084
-		foreach ($conf->file->dol_document_root as $type => $dirroot)	// ex: array(["main"]=>"/home/maindir/htdocs", ["alt0"]=>"/home/moddir0/htdocs", ...)
3387
+		foreach ($conf->file->dol_document_root as $type => $dirroot) {
3388
+			// ex: array(["main"]=>"/home/maindir/htdocs", ["alt0"]=>"/home/moddir0/htdocs", ...)
3085 3389
 		{
3086 3390
 			if ($type == 'main') continue;
3087
-			if (file_exists($dirroot.'/'.$path.'/img/'.$picto))	// This need a lot of time, that's why enabling alternative dir like "custom" dir is not recommanded
3391
+		}
3392
+			if (file_exists($dirroot.'/'.$path.'/img/'.$picto)) {
3393
+				// This need a lot of time, that's why enabling alternative dir like "custom" dir is not recommanded
3088 3394
 			{
3089 3395
 				$url=DOL_URL_ROOT.$conf->file->dol_url_root[$type];
3396
+			}
3090 3397
 				break;
3091 3398
 			}
3092 3399
 		}
@@ -3095,8 +3402,9 @@  discard block
 block discarded – undo
3095 3402
 		$fullpathpicto = $url.'/'.$path.'/img/'.$picto;
3096 3403
 	}
3097 3404
 
3098
-	if ($srconly) return $fullpathpicto;
3099
-	else
3405
+	if ($srconly) {
3406
+		return $fullpathpicto;
3407
+	} else
3100 3408
 	{
3101 3409
 		// tag title is used for tooltip on <a>, tag alt can be used with very simple text on image for bind people
3102 3410
 		//$tmparray=array(0=>$titlealt);
@@ -3140,7 +3448,9 @@  discard block
 block discarded – undo
3140 3448
 {
3141 3449
 	global $conf;
3142 3450
 
3143
-	if (! preg_match('/(\.png|\.gif)$/i', $picto)) $picto .= '.png';
3451
+	if (! preg_match('/(\.png|\.gif)$/i', $picto)) {
3452
+		$picto .= '.png';
3453
+	}
3144 3454
 
3145 3455
 	$path = DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/weather/'.$picto;
3146 3456
 
@@ -3161,10 +3471,13 @@  discard block
 block discarded – undo
3161 3471
 {
3162 3472
 	global $conf;
3163 3473
 
3164
-	if (! preg_match('/(\.png|\.gif)$/i', $picto)) $picto .= '.png';
3474
+	if (! preg_match('/(\.png|\.gif)$/i', $picto)) {
3475
+		$picto .= '.png';
3476
+	}
3165 3477
 
3166
-	if ($pictoisfullpath) $path = $picto;
3167
-	else
3478
+	if ($pictoisfullpath) {
3479
+		$path = $picto;
3480
+	} else
3168 3481
 	{
3169 3482
 		$path = DOL_URL_ROOT.'/theme/common/'.$picto;
3170 3483
 
@@ -3172,7 +3485,9 @@  discard block
 block discarded – undo
3172 3485
 		{
3173 3486
 			$themepath = DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/img/'.$picto;
3174 3487
 
3175
-			if (file_exists($themepath)) $path = $themepath;
3488
+			if (file_exists($themepath)) {
3489
+				$path = $themepath;
3490
+			}
3176 3491
 		}
3177 3492
 	}
3178 3493
 
@@ -3192,14 +3507,11 @@  discard block
 block discarded – undo
3192 3507
 
3193 3508
 	if (empty($titlealt) || $titlealt == 'default')
3194 3509
 	{
3195
-		if ($numaction == '-1' || $numaction == 'ST_NO')			{ $numaction = -1; $titlealt = $langs->transnoentitiesnoconv('ChangeDoNotContact'); }
3196
-		elseif ($numaction ==  '0' || $numaction == 'ST_NEVER') 	{ $numaction = 0; $titlealt = $langs->transnoentitiesnoconv('ChangeNeverContacted'); }
3197
-		elseif ($numaction ==  '1' || $numaction == 'ST_TODO')  	{ $numaction = 1; $titlealt = $langs->transnoentitiesnoconv('ChangeToContact'); }
3198
-		elseif ($numaction ==  '2' || $numaction == 'ST_PEND')  	{ $numaction = 2; $titlealt = $langs->transnoentitiesnoconv('ChangeContactInProcess'); }
3199
-		elseif ($numaction ==  '3' || $numaction == 'ST_DONE')  	{ $numaction = 3; $titlealt = $langs->transnoentitiesnoconv('ChangeContactDone'); }
3200
-		else { $titlealt = $langs->transnoentitiesnoconv('ChangeStatus '.$numaction); $numaction = 0; }
3510
+		if ($numaction == '-1' || $numaction == 'ST_NO')			{ $numaction = -1; $titlealt = $langs->transnoentitiesnoconv('ChangeDoNotContact'); } elseif ($numaction ==  '0' || $numaction == 'ST_NEVER') 	{ $numaction = 0; $titlealt = $langs->transnoentitiesnoconv('ChangeNeverContacted'); } elseif ($numaction ==  '1' || $numaction == 'ST_TODO')  	{ $numaction = 1; $titlealt = $langs->transnoentitiesnoconv('ChangeToContact'); } elseif ($numaction ==  '2' || $numaction == 'ST_PEND')  	{ $numaction = 2; $titlealt = $langs->transnoentitiesnoconv('ChangeContactInProcess'); } elseif ($numaction ==  '3' || $numaction == 'ST_DONE')  	{ $numaction = 3; $titlealt = $langs->transnoentitiesnoconv('ChangeContactDone'); } else { $titlealt = $langs->transnoentitiesnoconv('ChangeStatus '.$numaction); $numaction = 0; }
3511
+	}
3512
+	if (! is_numeric($numaction)) {
3513
+		$numaction=0;
3201 3514
 	}
3202
-	if (! is_numeric($numaction)) $numaction=0;
3203 3515
 
3204 3516
 	return img_picto($titlealt, 'stcomm'.$numaction.'.png');
3205 3517
 }
@@ -3215,7 +3527,9 @@  discard block
 block discarded – undo
3215 3527
 {
3216 3528
 	global $conf, $langs;
3217 3529
 
3218
-	if ($titlealt == 'default') $titlealt = $langs->trans('Show');
3530
+	if ($titlealt == 'default') {
3531
+		$titlealt = $langs->trans('Show');
3532
+	}
3219 3533
 
3220 3534
 	return img_picto($titlealt, 'pdf'.$size.'.png');
3221 3535
 }
@@ -3231,7 +3545,9 @@  discard block
 block discarded – undo
3231 3545
 {
3232 3546
 	global $conf, $langs;
3233 3547
 
3234
-	if ($titlealt == 'default') $titlealt = $langs->trans('Add');
3548
+	if ($titlealt == 'default') {
3549
+		$titlealt = $langs->trans('Add');
3550
+	}
3235 3551
 
3236 3552
 	return img_picto($titlealt, 'edit_add.png', $other);
3237 3553
 }
@@ -3246,7 +3562,9 @@  discard block
 block discarded – undo
3246 3562
 {
3247 3563
 	global $conf, $langs;
3248 3564
 
3249
-	if ($titlealt == 'default') $titlealt = $langs->trans('Remove');
3565
+	if ($titlealt == 'default') {
3566
+		$titlealt = $langs->trans('Remove');
3567
+	}
3250 3568
 
3251 3569
 	return img_picto($titlealt, 'edit_remove.png', $other);
3252 3570
 }
@@ -3263,7 +3581,9 @@  discard block
 block discarded – undo
3263 3581
 {
3264 3582
 	global $conf, $langs;
3265 3583
 
3266
-	if ($titlealt == 'default') $titlealt = $langs->trans('Modify');
3584
+	if ($titlealt == 'default') {
3585
+		$titlealt = $langs->trans('Modify');
3586
+	}
3267 3587
 
3268 3588
 	return img_picto($titlealt, 'edit.png', ($float ? 'style="float: '.($langs->tab_translate["DIRECTION"] == 'rtl'?'left':'right').'"' : "") . ($other?' '.$other:''));
3269 3589
 }
@@ -3280,7 +3600,9 @@  discard block
 block discarded – undo
3280 3600
 {
3281 3601
 	global $conf, $langs;
3282 3602
 
3283
-	if ($titlealt == 'default') $titlealt = $langs->trans('View');
3603
+	if ($titlealt == 'default') {
3604
+		$titlealt = $langs->trans('View');
3605
+	}
3284 3606
 
3285 3607
 	$moreatt = ($float ? 'style="float: right" ' : '').$other;
3286 3608
 
@@ -3298,7 +3620,9 @@  discard block
 block discarded – undo
3298 3620
 {
3299 3621
 	global $conf, $langs;
3300 3622
 
3301
-	if ($titlealt == 'default') $titlealt = $langs->trans('Delete');
3623
+	if ($titlealt == 'default') {
3624
+		$titlealt = $langs->trans('Delete');
3625
+	}
3302 3626
 
3303 3627
 	return img_picto($titlealt, 'delete.png', $other);
3304 3628
 }
@@ -3313,7 +3637,9 @@  discard block
 block discarded – undo
3313 3637
 function img_printer($titlealt = "default", $other='')
3314 3638
 {
3315 3639
 	global $conf,$langs;
3316
-	if ($titlealt=="default") $titlealt=$langs->trans("Print");
3640
+	if ($titlealt=="default") {
3641
+		$titlealt=$langs->trans("Print");
3642
+	}
3317 3643
 	return img_picto($titlealt,'printer.png',$other);
3318 3644
 }
3319 3645
 
@@ -3328,7 +3654,9 @@  discard block
 block discarded – undo
3328 3654
 {
3329 3655
 	global $conf, $langs;
3330 3656
 
3331
-	if ($titlealt == 'default') $titlealt = $langs->trans('Split');
3657
+	if ($titlealt == 'default') {
3658
+		$titlealt = $langs->trans('Split');
3659
+	}
3332 3660
 
3333 3661
 	return img_picto($titlealt, 'split.png', $other);
3334 3662
 }
@@ -3346,8 +3674,11 @@  discard block
 block discarded – undo
3346 3674
 
3347 3675
 	if ($usealttitle)
3348 3676
 	{
3349
-		if (is_string($usealttitle)) $usealttitle = dol_escape_htmltag($usealttitle);
3350
-		else $usealttitle = $langs->trans('Info');
3677
+		if (is_string($usealttitle)) {
3678
+			$usealttitle = dol_escape_htmltag($usealttitle);
3679
+		} else {
3680
+			$usealttitle = $langs->trans('Info');
3681
+		}
3351 3682
 	}
3352 3683
 
3353 3684
 	return img_picto($usealttitle, 'info.png', 'style="vertical-align: middle;'.($usehelpcursor == 1 ? ' cursor: help': ($usehelpcursor == 2 ? ' cursor: pointer':'')).'"');
@@ -3363,7 +3694,9 @@  discard block
 block discarded – undo
3363 3694
 {
3364 3695
 	global $conf, $langs;
3365 3696
 
3366
-	if ($titlealt == 'default') $titlealt = $langs->trans('Informations');
3697
+	if ($titlealt == 'default') {
3698
+		$titlealt = $langs->trans('Informations');
3699
+	}
3367 3700
 
3368 3701
 	return img_picto($titlealt, 'info.png', 'style="vertical-align: middle;"');
3369 3702
 }
@@ -3379,7 +3712,9 @@  discard block
 block discarded – undo
3379 3712
 {
3380 3713
 	global $conf, $langs;
3381 3714
 
3382
-	if ($titlealt == 'default') $titlealt = $langs->trans('Warning');
3715
+	if ($titlealt == 'default') {
3716
+		$titlealt = $langs->trans('Warning');
3717
+	}
3383 3718
 
3384 3719
 	//return '<div class="imglatecoin">'.img_picto($titlealt, 'warning_white.png', 'class="pictowarning valignmiddle"'.($moreatt ? ($moreatt == '1' ? ' style="float: right"' : ' '.$moreatt): '')).'</div>';
3385 3720
 	return img_picto($titlealt, 'warning.png', 'class="pictowarning valignmiddle"'.($moreatt ? ($moreatt == '1' ? ' style="float: right"' : ' '.$moreatt): ''));
@@ -3395,7 +3730,9 @@  discard block
 block discarded – undo
3395 3730
 {
3396 3731
 	global $conf, $langs;
3397 3732
 
3398
-	if ($titlealt == 'default') $titlealt = $langs->trans('Error');
3733
+	if ($titlealt == 'default') {
3734
+		$titlealt = $langs->trans('Error');
3735
+	}
3399 3736
 
3400 3737
 	return img_picto($titlealt, 'error.png', 'class="valigntextbottom"');
3401 3738
 }
@@ -3411,7 +3748,9 @@  discard block
 block discarded – undo
3411 3748
 {
3412 3749
 	global $conf, $langs;
3413 3750
 
3414
-	if ($titlealt == 'default') $titlealt = $langs->trans('Next');
3751
+	if ($titlealt == 'default') {
3752
+		$titlealt = $langs->trans('Next');
3753
+	}
3415 3754
 
3416 3755
 	//return img_picto($titlealt, 'next.png', $moreatt);
3417 3756
 	return '<span class="fa fa-chevron-right paddingright paddingleft" title="'.dol_escape_htmltag($titlealt).'"></span>';
@@ -3428,7 +3767,9 @@  discard block
 block discarded – undo
3428 3767
 {
3429 3768
 	global $conf, $langs;
3430 3769
 
3431
-	if ($titlealt == 'default') $titlealt = $langs->trans('Previous');
3770
+	if ($titlealt == 'default') {
3771
+		$titlealt = $langs->trans('Previous');
3772
+	}
3432 3773
 
3433 3774
 	//return img_picto($titlealt, 'previous.png', $moreatt);
3434 3775
 	return '<span class="fa fa-chevron-left paddingright paddingleft" title="'.dol_escape_htmltag($titlealt).'"></span>';
@@ -3446,7 +3787,9 @@  discard block
 block discarded – undo
3446 3787
 {
3447 3788
 	global $conf, $langs;
3448 3789
 
3449
-	if ($titlealt == 'default') $titlealt = $langs->trans('Down');
3790
+	if ($titlealt == 'default') {
3791
+		$titlealt = $langs->trans('Down');
3792
+	}
3450 3793
 
3451 3794
 	return img_picto($titlealt, ($selected ? '1downarrow_selected.png' : '1downarrow.png'), 'class="imgdown'.($moreclass?" ".$moreclass:"").'"');
3452 3795
 }
@@ -3463,7 +3806,9 @@  discard block
 block discarded – undo
3463 3806
 {
3464 3807
 	global $conf, $langs;
3465 3808
 
3466
-	if ($titlealt == 'default') $titlealt = $langs->trans('Up');
3809
+	if ($titlealt == 'default') {
3810
+		$titlealt = $langs->trans('Up');
3811
+	}
3467 3812
 
3468 3813
 	return img_picto($titlealt, ($selected ? '1uparrow_selected.png' : '1uparrow.png'), 'class="imgup'.($moreclass?" ".$moreclass:"").'"');
3469 3814
 }
@@ -3480,7 +3825,9 @@  discard block
 block discarded – undo
3480 3825
 {
3481 3826
 	global $conf, $langs;
3482 3827
 
3483
-	if ($titlealt == 'default') $titlealt = $langs->trans('Left');
3828
+	if ($titlealt == 'default') {
3829
+		$titlealt = $langs->trans('Left');
3830
+	}
3484 3831
 
3485 3832
 	return img_picto($titlealt, ($selected ? '1leftarrow_selected.png' : '1leftarrow.png'), $moreatt);
3486 3833
 }
@@ -3497,7 +3844,9 @@  discard block
 block discarded – undo
3497 3844
 {
3498 3845
 	global $conf, $langs;
3499 3846
 
3500
-	if ($titlealt == 'default') $titlealt = $langs->trans('Right');
3847
+	if ($titlealt == 'default') {
3848
+		$titlealt = $langs->trans('Right');
3849
+	}
3501 3850
 
3502 3851
 	return img_picto($titlealt, ($selected ? '1rightarrow_selected.png' : '1rightarrow.png'), $moreatt);
3503 3852
 }
@@ -3513,9 +3862,13 @@  discard block
 block discarded – undo
3513 3862
 {
3514 3863
 	global $conf, $langs;
3515 3864
 
3516
-	if ($titlealt == 'default') $titlealt = $langs->trans('Active');
3865
+	if ($titlealt == 'default') {
3866
+		$titlealt = $langs->trans('Active');
3867
+	}
3517 3868
 
3518
-	if ($allow == 1) return img_picto($titlealt, 'tick.png');
3869
+	if ($allow == 1) {
3870
+		return img_picto($titlealt, 'tick.png');
3871
+	}
3519 3872
 
3520 3873
 	return '-';
3521 3874
 }
@@ -3537,7 +3890,9 @@  discard block
 block discarded – undo
3537 3890
 	$mimeimg = dol_mimetype($file, '', 2);
3538 3891
 	$mimefa = dol_mimetype($file, '', 4);
3539 3892
 
3540
-	if (empty($titlealt)) $titlealt = 'Mime type: '.$mimetype;
3893
+	if (empty($titlealt)) {
3894
+		$titlealt = 'Mime type: '.$mimetype;
3895
+	}
3541 3896
 
3542 3897
 	//return img_picto_common($titlealt, 'mime/'.$mimeimg, 'class="'.$morecss.'"');
3543 3898
 	return '<i class="fa fa-'.$mimefa.' paddingright"></i>';
@@ -3560,10 +3915,15 @@  discard block
 block discarded – undo
3560 3915
 
3561 3916
 	global $conf,$langs;
3562 3917
 
3563
-	if ($titlealt == 'default') $titlealt = $langs->trans('Call');
3918
+	if ($titlealt == 'default') {
3919
+		$titlealt = $langs->trans('Call');
3920
+	}
3564 3921
 
3565
-	if ($option == 1) $img = 'call';
3566
-	else $img = 'call_out';
3922
+	if ($option == 1) {
3923
+		$img = 'call';
3924
+	} else {
3925
+		$img = 'call_out';
3926
+	}
3567 3927
 
3568 3928
 	return img_picto($titlealt, $img);
3569 3929
 }
@@ -3579,7 +3939,9 @@  discard block
 block discarded – undo
3579 3939
 {
3580 3940
 	global $conf, $langs;
3581 3941
 
3582
-	if ($titlealt == 'default') $titlealt = $langs->trans('Search');
3942
+	if ($titlealt == 'default') {
3943
+		$titlealt = $langs->trans('Search');
3944
+	}
3583 3945
 
3584 3946
 	$img = img_picto($titlealt, 'search.png', $other, false, 1);
3585 3947
 
@@ -3600,7 +3962,9 @@  discard block
 block discarded – undo
3600 3962
 {
3601 3963
 	global $conf, $langs;
3602 3964
 
3603
-	if ($titlealt == 'default') $titlealt = $langs->trans('Search');
3965
+	if ($titlealt == 'default') {
3966
+		$titlealt = $langs->trans('Search');
3967
+	}
3604 3968
 
3605 3969
 	$img = img_picto($titlealt, 'searchclear.png', $other, false, 1);
3606 3970
 
@@ -3663,15 +4027,21 @@  discard block
 block discarded – undo
3663 4027
 	$langs->load("main");
3664 4028
 	$langs->load("errors");
3665 4029
 
3666
-	if ($_SERVER['DOCUMENT_ROOT'])    // Mode web
4030
+	if ($_SERVER['DOCUMENT_ROOT']) {
4031
+		// Mode web
3667 4032
 	{
3668 4033
 		$out.=$langs->trans("DolibarrHasDetectedError").".<br>\n";
3669
-		if (! empty($conf->global->MAIN_FEATURES_LEVEL)) $out.="You use an experimental or develop level of features, so please do NOT report any bugs, except if problem is confirmed moving option MAIN_FEATURES_LEVEL back to 0.<br>\n";
4034
+	}
4035
+		if (! empty($conf->global->MAIN_FEATURES_LEVEL)) {
4036
+			$out.="You use an experimental or develop level of features, so please do NOT report any bugs, except if problem is confirmed moving option MAIN_FEATURES_LEVEL back to 0.<br>\n";
4037
+		}
3670 4038
 		$out.=$langs->trans("InformationToHelpDiagnose").":<br>\n";
3671 4039
 
3672 4040
 		$out.="<b>".$langs->trans("Date").":</b> ".dol_print_date(time(),'dayhourlog')."<br>\n";
3673 4041
 		$out.="<b>".$langs->trans("Dolibarr").":</b> ".DOL_VERSION."<br>\n";
3674
-		if (isset($conf->global->MAIN_FEATURES_LEVEL)) $out.="<b>".$langs->trans("LevelOfFeature").":</b> ".$conf->global->MAIN_FEATURES_LEVEL."<br>\n";
4042
+		if (isset($conf->global->MAIN_FEATURES_LEVEL)) {
4043
+			$out.="<b>".$langs->trans("LevelOfFeature").":</b> ".$conf->global->MAIN_FEATURES_LEVEL."<br>\n";
4044
+		}
3675 4045
 		if (function_exists("phpversion"))
3676 4046
 		{
3677 4047
 			$out.="<b>".$langs->trans("PHP").":</b> ".phpversion()."<br>\n";
@@ -3689,8 +4059,7 @@  discard block
 block discarded – undo
3689 4059
 		$out.="<br>\n";
3690 4060
 		$syslog.="url=".dol_escape_htmltag($_SERVER["REQUEST_URI"]);
3691 4061
 		$syslog.=", query_string=".dol_escape_htmltag($_SERVER["QUERY_STRING"]);
3692
-	}
3693
-	else                              // Mode CLI
4062
+	} else                              // Mode CLI
3694 4063
 	{
3695 4064
 		$out.='> '.$langs->transnoentities("ErrorInternalErrorDetected").":\n".$argv[0]."\n";
3696 4065
 		$syslog.="pid=".dol_getmypid();
@@ -3698,15 +4067,16 @@  discard block
 block discarded – undo
3698 4067
 
3699 4068
 	if (is_object($db))
3700 4069
 	{
3701
-		if ($_SERVER['DOCUMENT_ROOT'])  // Mode web
4070
+		if ($_SERVER['DOCUMENT_ROOT']) {
4071
+			// Mode web
3702 4072
 		{
3703 4073
 			$out.="<b>".$langs->trans("DatabaseTypeManager").":</b> ".$db->type."<br>\n";
4074
+		}
3704 4075
 			$out.="<b>".$langs->trans("RequestLastAccessInError").":</b> ".($db->lastqueryerror()?dol_escape_htmltag($db->lastqueryerror()):$langs->trans("ErrorNoRequestInError"))."<br>\n";
3705 4076
 			$out.="<b>".$langs->trans("ReturnCodeLastAccessInError").":</b> ".($db->lasterrno()?dol_escape_htmltag($db->lasterrno()):$langs->trans("ErrorNoRequestInError"))."<br>\n";
3706 4077
 			$out.="<b>".$langs->trans("InformationLastAccessInError").":</b> ".($db->lasterror()?dol_escape_htmltag($db->lasterror()):$langs->trans("ErrorNoRequestInError"))."<br>\n";
3707 4078
 			$out.="<br>\n";
3708
-		}
3709
-		else                            // Mode CLI
4079
+		} else                            // Mode CLI
3710 4080
 		{
3711 4081
 			// No dol_escape_htmltag for output, we are in CLI mode
3712 4082
 			$out.='> '.$langs->transnoentities("DatabaseTypeManager").":\n".$db->type."\n";
@@ -3724,19 +4094,27 @@  discard block
 block discarded – undo
3724 4094
 		$langs->load("errors");
3725 4095
 
3726 4096
 		// Merge all into $errors array
3727
-		if (is_array($error) && is_array($errors)) $errors=array_merge($error,$errors);
3728
-		elseif (is_array($error)) $errors=$error;
3729
-		elseif (is_array($errors)) $errors=array_merge(array($error),$errors);
3730
-		else $errors=array_merge(array($error));
4097
+		if (is_array($error) && is_array($errors)) {
4098
+			$errors=array_merge($error,$errors);
4099
+		} elseif (is_array($error)) {
4100
+			$errors=$error;
4101
+		} elseif (is_array($errors)) {
4102
+			$errors=array_merge(array($error),$errors);
4103
+		} else {
4104
+			$errors=array_merge(array($error));
4105
+		}
3731 4106
 
3732 4107
 		foreach($errors as $msg)
3733 4108
 		{
3734
-			if (empty($msg)) continue;
3735
-			if ($_SERVER['DOCUMENT_ROOT'])  // Mode web
4109
+			if (empty($msg)) {
4110
+				continue;
4111
+			}
4112
+			if ($_SERVER['DOCUMENT_ROOT']) {
4113
+				// Mode web
3736 4114
 			{
3737 4115
 				$out.="<b>".$langs->trans("Message").":</b> ".dol_escape_htmltag($msg)."<br>\n" ;
3738 4116
 			}
3739
-			else                        // Mode CLI
4117
+			} else                        // Mode CLI
3740 4118
 			{
3741 4119
 				$out.='> '.$langs->transnoentities("Message").":\n".$msg."\n" ;
3742 4120
 			}
@@ -3753,8 +4131,9 @@  discard block
 block discarded – undo
3753 4131
 		$out.="<br>\n";
3754 4132
 	}
3755 4133
 
3756
-	if (empty($dolibarr_main_prod)) print $out;
3757
-	else
4134
+	if (empty($dolibarr_main_prod)) {
4135
+		print $out;
4136
+	} else
3758 4137
 	{
3759 4138
 		print $langs->trans("DolibarrHasDetectedError").'. ';
3760 4139
 		print $langs->trans("YouCanSetOptionDolibarrMainProdToZero");
@@ -3781,7 +4160,9 @@  discard block
 block discarded – undo
3781 4160
 	$now=dol_now();
3782 4161
 	print '<br><div class="center login_main_message"><div class="'.$morecss.'">';
3783 4162
 	print $langs->trans("ErrorContactEMail", $conf->global->MAIN_INFO_SOCIETE_MAIL, $prefixcode.dol_print_date($now,'%Y%m%d'));
3784
-	if ($errormessage) print '<br><br>'.$errormessage;
4163
+	if ($errormessage) {
4164
+		print '<br><br>'.$errormessage;
4165
+	}
3785 4166
 	if (is_array($errormessages) && count($errormessages))
3786 4167
 	{
3787 4168
 		foreach($errormessages as $mesgtoshow)
@@ -3839,7 +4220,9 @@  discard block
 block discarded – undo
3839 4220
 	$sortimg='';
3840 4221
 
3841 4222
 	$tag='th';
3842
-	if ($thead==2) $tag='div';
4223
+	if ($thead==2) {
4224
+		$tag='div';
4225
+	}
3843 4226
 
3844 4227
 	$tmpsortfield=explode(',',$sortfield);
3845 4228
 	$sortfield1=trim($tmpsortfield[0]);    // If $sortfield is 'd.datep,d.id', it becomes 'd.datep'
@@ -3849,42 +4232,63 @@  discard block
 block discarded – undo
3849 4232
 	//var_dump('field='.$field.' field1='.$field1.' sortfield='.$sortfield.' sortfield1='.$sortfield1);
3850 4233
 	// If field is used as sort criteria we use a specific css class liste_titre_sel
3851 4234
 	// Example if (sortfield,field)=("nom","xxx.nom") or (sortfield,field)=("nom","nom")
3852
-	if ($field1 && ($sortfield1 == $field1 || $sortfield1 == preg_replace("/^[^\.]+\./","",$field1))) $out.= '<'.$tag.' class="'.$prefix.'liste_titre_sel" '. $moreattrib.'>';
3853
-	else $out.= '<'.$tag.' class="'.$prefix.'liste_titre" '. $moreattrib.'>';
4235
+	if ($field1 && ($sortfield1 == $field1 || $sortfield1 == preg_replace("/^[^\.]+\./","",$field1))) {
4236
+		$out.= '<'.$tag.' class="'.$prefix.'liste_titre_sel" '. $moreattrib.'>';
4237
+	} else {
4238
+		$out.= '<'.$tag.' class="'.$prefix.'liste_titre" '. $moreattrib.'>';
4239
+	}
3854 4240
 
3855
-	if (empty($thead) && $field && empty($disablesortlink))    // If this is a sort field
4241
+	if (empty($thead) && $field && empty($disablesortlink)) {
4242
+		// If this is a sort field
3856 4243
 	{
3857 4244
 		$options=preg_replace('/sortfield=([a-zA-Z0-9,\s\.]+)/i','',$moreparam);
4245
+	}
3858 4246
 		$options=preg_replace('/sortorder=([a-zA-Z0-9,\s\.]+)/i','',$options);
3859 4247
 		$options=preg_replace('/&+/i','&',$options);
3860
-		if (! preg_match('/^&/',$options)) $options='&'.$options;
4248
+		if (! preg_match('/^&/',$options)) {
4249
+			$options='&'.$options;
4250
+		}
3861 4251
 
3862
-		if ($field1 != $sortfield1) // We are on another field
4252
+		if ($field1 != $sortfield1) {
4253
+			// We are on another field
3863 4254
 		{
3864 4255
 			if (preg_match('/^DESC/', $sortorder)) $out.= '<a class="reposition" href="'.$file.'?sortfield='.$field.'&sortorder=desc&begin='.$begin.$options.'">';
3865
-			else $out.= '<a class="reposition" href="'.$file.'?sortfield='.$field.'&sortorder=asc&begin='.$begin.$options.'">';
3866
-		}
3867
-		else                      // We are of first sorting criteria
4256
+		} else {
4257
+				$out.= '<a class="reposition" href="'.$file.'?sortfield='.$field.'&sortorder=asc&begin='.$begin.$options.'">';
4258
+			}
4259
+		} else                      // We are of first sorting criteria
3868 4260
 		{
3869
-			if (preg_match('/^ASC/', $sortorder)) $out.= '<a class="reposition" href="'.$file.'?sortfield='.$sortfield.'&sortorder=desc&begin='.$begin.$options.'">';
3870
-			else $out.= '<a class="reposition" href="'.$file.'?sortfield='.$sortfield.'&sortorder=asc&begin='.$begin.$options.'">';
4261
+			if (preg_match('/^ASC/', $sortorder)) {
4262
+				$out.= '<a class="reposition" href="'.$file.'?sortfield='.$sortfield.'&sortorder=desc&begin='.$begin.$options.'">';
4263
+			} else {
4264
+				$out.= '<a class="reposition" href="'.$file.'?sortfield='.$sortfield.'&sortorder=asc&begin='.$begin.$options.'">';
4265
+			}
3871 4266
 		}
3872 4267
 	}
3873 4268
 
3874
-	if ($tooltip) $out.=$form->textwithpicto($langs->trans($name), $langs->trans($tooltip));
3875
-	else $out.=$langs->trans($name);
4269
+	if ($tooltip) {
4270
+		$out.=$form->textwithpicto($langs->trans($name), $langs->trans($tooltip));
4271
+	} else {
4272
+		$out.=$langs->trans($name);
4273
+	}
3876 4274
 
3877
-	if (empty($thead) && $field && empty($disablesortlink))    // If this is a sort field
4275
+	if (empty($thead) && $field && empty($disablesortlink)) {
4276
+		// If this is a sort field
3878 4277
 	{
3879 4278
 		$out.='</a>';
3880 4279
 	}
4280
+	}
3881 4281
 
3882
-	if (empty($thead) && $field)    // If this is a sort field
4282
+	if (empty($thead) && $field) {
4283
+		// If this is a sort field
3883 4284
 	{
3884 4285
 		$options=preg_replace('/sortfield=([a-zA-Z0-9,\s\.]+)/i','',$moreparam);
4286
+	}
3885 4287
 		$options=preg_replace('/sortorder=([a-zA-Z0-9,\s\.]+)/i','',$options);
3886 4288
 		$options=preg_replace('/&+/i','&',$options);
3887
-		if (! preg_match('/^&/',$options)) $options='&'.$options;
4289
+		if (! preg_match('/^&/',$options)) {
4290
+			$options='&'.$options;
4291
+		}
3888 4292
 
3889 4293
 		//print "&nbsp;";
3890 4294
 		//$sortimg.= '<img width="2" src="'.DOL_URL_ROOT.'/theme/common/transparent.png" alt="">';
@@ -3894,8 +4298,7 @@  discard block
 block discarded – undo
3894 4298
 		{
3895 4299
 			//$out.= '<a href="'.$file.'?sortfield='.$field.'&sortorder=asc&begin='.$begin.$options.'">'.img_down("A-Z",0).'</a>';
3896 4300
 			//$out.= '<a href="'.$file.'?sortfield='.$field.'&sortorder=desc&begin='.$begin.$options.'">'.img_up("Z-A",0).'</a>';
3897
-		}
3898
-		else
4301
+		} else
3899 4302
 		{
3900 4303
 			if (preg_match('/^DESC/', $sortorder)) {
3901 4304
 				//$out.= '<a href="'.$file.'?sortfield='.$field.'&sortorder=asc&begin='.$begin.$options.'">'.img_down("A-Z",0).'</a>';
@@ -3969,12 +4372,18 @@  discard block
 block discarded – undo
3969 4372
 
3970 4373
 	$return='';
3971 4374
 
3972
-	if ($picto == 'setup') $picto='title.png';
3973
-	if (($conf->browser->name == 'ie') && $picto=='title.png') $picto='title.gif';
4375
+	if ($picto == 'setup') {
4376
+		$picto='title.png';
4377
+	}
4378
+	if (($conf->browser->name == 'ie') && $picto=='title.png') {
4379
+		$picto='title.gif';
4380
+	}
3974 4381
 
3975 4382
 	$return.= "\n";
3976 4383
 	$return.= '<table '.($id?'id="'.$id.'" ':'').'summary="" class="centpercent notopnoleftnoright'.($morecssontable?' '.$morecssontable:'').'" style="margin-bottom: 2px;"><tr>';
3977
-	if ($picto) $return.= '<td class="nobordernopadding widthpictotitle" valign="middle">'.img_picto('',$picto, 'class="valignmiddle widthpictotitle" id="pictotitle"', $pictoisfullpath).'</td>';
4384
+	if ($picto) {
4385
+		$return.= '<td class="nobordernopadding widthpictotitle" valign="middle">'.img_picto('',$picto, 'class="valignmiddle widthpictotitle" id="pictotitle"', $pictoisfullpath).'</td>';
4386
+	}
3978 4387
 	$return.= '<td class="nobordernopadding" valign="middle">';
3979 4388
 	$return.= '<div class="titre">'.$titre.'</div>';
3980 4389
 	$return.= '</td>';
@@ -4020,14 +4429,19 @@  discard block
 block discarded – undo
4020 4429
 	$savtotalnboflines = $totalnboflines;
4021 4430
 	$totalnboflines=abs($totalnboflines);
4022 4431
 
4023
-	if ($picto == 'setup') $picto='title_setup.png';
4024
-	if (($conf->browser->name == 'ie') && $picto=='title_generic.png') $picto='title.gif';
4025
-	if ($limit < 0) $limit = $conf->liste_limit;
4432
+	if ($picto == 'setup') {
4433
+		$picto='title_setup.png';
4434
+	}
4435
+	if (($conf->browser->name == 'ie') && $picto=='title_generic.png') {
4436
+		$picto='title.gif';
4437
+	}
4438
+	if ($limit < 0) {
4439
+		$limit = $conf->liste_limit;
4440
+	}
4026 4441
 	if ($savlimit != 0 && (($num > $limit) || ($num == -1) || ($limit == 0)))
4027 4442
 	{
4028 4443
 		$nextpage = 1;
4029
-	}
4030
-	else
4444
+	} else
4031 4445
 	{
4032 4446
 		$nextpage = 0;
4033 4447
 	}
@@ -4040,9 +4454,13 @@  discard block
 block discarded – undo
4040 4454
 	// Left
4041 4455
 	//if ($picto && $titre) print '<td class="nobordernopadding hideonsmartphone" width="40" align="left" valign="middle">'.img_picto('', $picto, 'id="pictotitle"', $pictoisfullpath).'</td>';
4042 4456
 	print '<td class="nobordernopadding valignmiddle">';
4043
-	if ($picto && $titre) print img_picto('', $picto, 'class="hideonsmartphone valignmiddle" id="pictotitle"', $pictoisfullpath);
4457
+	if ($picto && $titre) {
4458
+		print img_picto('', $picto, 'class="hideonsmartphone valignmiddle" id="pictotitle"', $pictoisfullpath);
4459
+	}
4044 4460
 	print '<div class="titre inline-block">'.$titre;
4045
-	if (!empty($titre) && $savtotalnboflines >= 0 && (string) $savtotalnboflines != '') print ' ('.$totalnboflines.')';
4461
+	if (!empty($titre) && $savtotalnboflines >= 0 && (string) $savtotalnboflines != '') {
4462
+		print ' ('.$totalnboflines.')';
4463
+	}
4046 4464
 	print '</div></td>';
4047 4465
 
4048 4466
 	// Center
@@ -4053,27 +4471,39 @@  discard block
 block discarded – undo
4053 4471
 
4054 4472
 	// Right
4055 4473
 	print '<td class="nobordernopadding valignmiddle" align="right">';
4056
-	if ($sortfield) $options .= "&sortfield=".urlencode($sortfield);
4057
-	if ($sortorder) $options .= "&sortorder=".urlencode($sortorder);
4474
+	if ($sortfield) {
4475
+		$options .= "&sortfield=".urlencode($sortfield);
4476
+	}
4477
+	if ($sortorder) {
4478
+		$options .= "&sortorder=".urlencode($sortorder);
4479
+	}
4058 4480
 	// Show navigation bar
4059 4481
 	$pagelist = '';
4060 4482
 	if ($savlimit != 0 && ($page > 0 || $num > $limit))
4061 4483
 	{
4062
-		if ($totalnboflines)	// If we know total nb of lines
4484
+		if ($totalnboflines) {
4485
+			// If we know total nb of lines
4063 4486
 		{
4064 4487
 			// Define nb of extra page links before and after selected page + ... + first or last
4065 4488
 			$maxnbofpage=(empty($conf->dol_optimize_smallscreen) ? 4 : 1);
4489
+		}
4066 4490
 
4067
-			if ($limit > 0) $nbpages=ceil($totalnboflines/$limit);
4068
-			else $nbpages=1;
4491
+			if ($limit > 0) {
4492
+				$nbpages=ceil($totalnboflines/$limit);
4493
+			} else {
4494
+				$nbpages=1;
4495
+			}
4069 4496
 			$cpt=($page-$maxnbofpage);
4070 4497
 			if ($cpt < 0) { $cpt=0; }
4071 4498
 
4072 4499
 			if ($cpt>=1)
4073 4500
 			{
4074 4501
 				$pagelist.= '<li'.(($conf->dol_use_jmobile != 4)?' class="pagination"':'').'><a href="'.$file.'?page=0'.$options.'">1</a></li>';
4075
-				if ($cpt > 2) $pagelist.='<li'.(($conf->dol_use_jmobile != 4)?' class="pagination"':'').'><span '.(($conf->dol_use_jmobile != 4)?'class="inactive"':'').'>...</span></li>';
4076
-				else if ($cpt == 2) $pagelist.='<li'.(($conf->dol_use_jmobile != 4)?' class="pagination"':'').'><a href="'.$file.'?page=1'.$options.'">2</a></li>';
4502
+				if ($cpt > 2) {
4503
+					$pagelist.='<li'.(($conf->dol_use_jmobile != 4)?' class="pagination"':'').'><span '.(($conf->dol_use_jmobile != 4)?'class="inactive"':'').'>...</span></li>';
4504
+				} else if ($cpt == 2) {
4505
+					$pagelist.='<li'.(($conf->dol_use_jmobile != 4)?' class="pagination"':'').'><a href="'.$file.'?page=1'.$options.'">2</a></li>';
4506
+				}
4077 4507
 			}
4078 4508
 
4079 4509
 			do
@@ -4081,8 +4511,7 @@  discard block
 block discarded – undo
4081 4511
 				if ($cpt==$page)
4082 4512
 				{
4083 4513
 					$pagelist.= '<li'.(($conf->dol_use_jmobile != 4)?' class="pagination"':'').'><span '.(($conf->dol_use_jmobile != 4)?'class="active"':'').'>'.($page+1).'</span></li>';
4084
-				}
4085
-				else
4514
+				} else
4086 4515
 				{
4087 4516
 					$pagelist.= '<li'.(($conf->dol_use_jmobile != 4)?' class="pagination"':'').'><a href="'.$file.'?page='.$cpt.$options.'">'.($cpt+1).'</a></li>';
4088 4517
 				}
@@ -4092,12 +4521,14 @@  discard block
 block discarded – undo
4092 4521
 
4093 4522
 			if ($cpt<$nbpages)
4094 4523
 			{
4095
-				if ($cpt<$nbpages-2) $pagelist.= '<li'.(($conf->dol_use_jmobile != 4)?' class="pagination"':'').'><span '.(($conf->dol_use_jmobile != 4)?'class="inactive"':'').'>...</span></li>';
4096
-				else if ($cpt == $nbpages-2) $pagelist.= '<li'.(($conf->dol_use_jmobile != 4)?' class="pagination"':'').'><a href="'.$file.'?page='.($nbpages-2).$options.'">'.($nbpages - 1).'</a></li>';
4524
+				if ($cpt<$nbpages-2) {
4525
+					$pagelist.= '<li'.(($conf->dol_use_jmobile != 4)?' class="pagination"':'').'><span '.(($conf->dol_use_jmobile != 4)?'class="inactive"':'').'>...</span></li>';
4526
+				} else if ($cpt == $nbpages-2) {
4527
+					$pagelist.= '<li'.(($conf->dol_use_jmobile != 4)?' class="pagination"':'').'><a href="'.$file.'?page='.($nbpages-2).$options.'">'.($nbpages - 1).'</a></li>';
4528
+				}
4097 4529
 				$pagelist.= '<li'.(($conf->dol_use_jmobile != 4)?' class="pagination"':'').'><a href="'.$file.'?page='.($nbpages-1).$options.'">'.$nbpages.'</a></li>';
4098 4530
 			}
4099
-		}
4100
-		else
4531
+		} else
4101 4532
 		{
4102 4533
 			$pagelist.= '<li'.(($conf->dol_use_jmobile != 4)?' class="pagination"':'').'><span '.(($conf->dol_use_jmobile != 4)?'class="active"':'').'>'.($page+1)."</li>";
4103 4534
 		}
@@ -4135,15 +4566,21 @@  discard block
 block discarded – undo
4135 4566
 		$pagesizechoices='10:10,20:20,30:30,40:40,50:50,100:100,250:250,500:500,1000:1000,5000:5000';
4136 4567
 		//$pagesizechoices.=',0:'.$langs->trans("All");     // Not yet supported
4137 4568
 		//$pagesizechoices.=',2:2';
4138
-		if (! empty($conf->global->MAIN_PAGESIZE_CHOICES)) $pagesizechoices=$conf->global->MAIN_PAGESIZE_CHOICES;
4569
+		if (! empty($conf->global->MAIN_PAGESIZE_CHOICES)) {
4570
+			$pagesizechoices=$conf->global->MAIN_PAGESIZE_CHOICES;
4571
+		}
4139 4572
 
4140 4573
 		print '<li class="pagination">';
4141 4574
 		print '<select class="flat selectlimit" name="limit" title="'.dol_escape_htmltag($langs->trans("MaxNbOfRecordPerPage")).'">';
4142 4575
 		$tmpchoice=explode(',',$pagesizechoices);
4143 4576
 		$tmpkey=$limit.':'.$limit;
4144
-		if (! in_array($tmpkey, $tmpchoice)) $tmpchoice[]=$tmpkey;
4577
+		if (! in_array($tmpkey, $tmpchoice)) {
4578
+			$tmpchoice[]=$tmpkey;
4579
+		}
4145 4580
 		$tmpkey=$conf->liste_limit.':'.$conf->liste_limit;
4146
-		if (! in_array($tmpkey, $tmpchoice)) $tmpchoice[]=$tmpkey;
4581
+		if (! in_array($tmpkey, $tmpchoice)) {
4582
+			$tmpchoice[]=$tmpkey;
4583
+		}
4147 4584
 		asort($tmpchoice, SORT_NUMERIC);
4148 4585
 		$found=false;
4149 4586
 		foreach($tmpchoice as $val)
@@ -4231,13 +4668,16 @@  discard block
 block discarded – undo
4231 4668
 	}
4232 4669
 
4233 4670
 	// If rate is '9/9/9' we don't change it.  If rate is '9.000' we apply price()
4234
-	if (! preg_match('/\//', $rate)) $ret=price($rate,0,'',0,0).($addpercent?'%':'');
4235
-	else
4671
+	if (! preg_match('/\//', $rate)) {
4672
+		$ret=price($rate,0,'',0,0).($addpercent?'%':'');
4673
+	} else
4236 4674
 	{
4237 4675
 		// TODO Split on / and output with a price2num to have clean numbers without ton of 000.
4238 4676
 		$ret=$rate.($addpercent?'%':'');
4239 4677
 	}
4240
-	if (($info_bits & 1) && $usestarfornpr >= 0) $ret.=' *';
4678
+	if (($info_bits & 1) && $usestarfornpr >= 0) {
4679
+		$ret.=' *';
4680
+	}
4241 4681
 	$ret.=$morelabel;
4242 4682
 	return $ret;
4243 4683
 }
@@ -4263,21 +4703,35 @@  discard block
 block discarded – undo
4263 4703
 	global $langs,$conf;
4264 4704
 
4265 4705
 	// Clean parameters
4266
-	if (empty($amount)) $amount=0;	// To have a numeric value if amount not defined or = ''
4706
+	if (empty($amount)) {
4707
+		$amount=0;
4708
+	}
4709
+	// To have a numeric value if amount not defined or = ''
4267 4710
 	$amount = (is_numeric($amount)?$amount:0); // Check if amount is numeric, for example, an error occured when amount value = o (letter) instead 0 (number)
4268
-	if ($rounding < 0) $rounding=min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT);
4711
+	if ($rounding < 0) {
4712
+		$rounding=min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT);
4713
+	}
4269 4714
 	$nbdecimal=$rounding;
4270 4715
 
4271 4716
 	// Output separators by default (french)
4272 4717
 	$dec=','; $thousand=' ';
4273 4718
 
4274 4719
 	// If $outlangs not forced, we use use language
4275
-	if (! is_object($outlangs)) $outlangs=$langs;
4720
+	if (! is_object($outlangs)) {
4721
+		$outlangs=$langs;
4722
+	}
4276 4723
 
4277
-	if ($outlangs->transnoentitiesnoconv("SeparatorDecimal") != "SeparatorDecimal")  $dec=$outlangs->transnoentitiesnoconv("SeparatorDecimal");
4278
-	if ($outlangs->transnoentitiesnoconv("SeparatorThousand")!= "SeparatorThousand") $thousand=$outlangs->transnoentitiesnoconv("SeparatorThousand");
4279
-	if ($thousand == 'None') $thousand='';
4280
-	else if ($thousand == 'Space') $thousand=' ';
4724
+	if ($outlangs->transnoentitiesnoconv("SeparatorDecimal") != "SeparatorDecimal") {
4725
+		$dec=$outlangs->transnoentitiesnoconv("SeparatorDecimal");
4726
+	}
4727
+	if ($outlangs->transnoentitiesnoconv("SeparatorThousand")!= "SeparatorThousand") {
4728
+		$thousand=$outlangs->transnoentitiesnoconv("SeparatorThousand");
4729
+	}
4730
+	if ($thousand == 'None') {
4731
+		$thousand='';
4732
+	} else if ($thousand == 'Space') {
4733
+		$thousand=' ';
4734
+	}
4281 4735
 	//print "outlangs=".$outlangs->defaultlang." amount=".$amount." html=".$form." trunc=".$trunc." nbdecimal=".$nbdecimal." dec='".$dec."' thousand='".$thousand."'<br>";
4282 4736
 
4283 4737
 	//print "amount=".$amount."-";
@@ -4290,7 +4744,9 @@  discard block
 block discarded – undo
4290 4744
 	$end='';
4291 4745
 
4292 4746
 	// We increase nbdecimal if there is more decimal than asked (to not loose information)
4293
-	if (dol_strlen($decpart) > $nbdecimal) $nbdecimal=dol_strlen($decpart);
4747
+	if (dol_strlen($decpart) > $nbdecimal) {
4748
+		$nbdecimal=dol_strlen($decpart);
4749
+	}
4294 4750
 	// Si on depasse max
4295 4751
 	if ($trunc && $nbdecimal > $conf->global->MAIN_MAX_DECIMALS_SHOWN)
4296 4752
 	{
@@ -4303,7 +4759,9 @@  discard block
 block discarded – undo
4303 4759
 	}
4304 4760
 
4305 4761
 	// If force rounding
4306
-	if ($forcerounding >= 0) $nbdecimal = $forcerounding;
4762
+	if ($forcerounding >= 0) {
4763
+		$nbdecimal = $forcerounding;
4764
+	}
4307 4765
 
4308 4766
 	// Format number
4309 4767
 	$output=number_format($amount, $nbdecimal, $dec, $thousand);
@@ -4316,11 +4774,14 @@  discard block
 block discarded – undo
4316 4774
 	$cursymbolbefore=$cursymbolafter='';
4317 4775
 	if ($currency_code)
4318 4776
 	{
4319
-		if ($currency_code == 'auto') $currency_code=$conf->currency;
4777
+		if ($currency_code == 'auto') {
4778
+			$currency_code=$conf->currency;
4779
+		}
4320 4780
 
4321 4781
 		$listofcurrenciesbefore=array('USD','GBP','AUD','MXN','PEN','CNY');
4322
-		if (in_array($currency_code,$listofcurrenciesbefore)) $cursymbolbefore.=$outlangs->getCurrencySymbol($currency_code);
4323
-		else
4782
+		if (in_array($currency_code,$listofcurrenciesbefore)) {
4783
+			$cursymbolbefore.=$outlangs->getCurrencySymbol($currency_code);
4784
+		} else
4324 4785
 		{
4325 4786
 			$tmpcur=$outlangs->getCurrencySymbol($currency_code);
4326 4787
 			$cursymbolafter.=($tmpcur == $currency_code ? ' '.$tmpcur : $tmpcur);
@@ -4353,14 +4814,22 @@  discard block
 block discarded – undo
4353 4814
 	// Numbers must be '1234.56'
4354 4815
 	// Decimal delimiter for PHP and database SQL requests must be '.'
4355 4816
 	$dec=','; $thousand=' ';
4356
-	if ($langs->transnoentitiesnoconv("SeparatorDecimal") != "SeparatorDecimal")  $dec=$langs->transnoentitiesnoconv("SeparatorDecimal");
4357
-	if ($langs->transnoentitiesnoconv("SeparatorThousand")!= "SeparatorThousand") $thousand=$langs->transnoentitiesnoconv("SeparatorThousand");
4358
-	if ($thousand == 'None') $thousand='';
4359
-	elseif ($thousand == 'Space') $thousand=' ';
4817
+	if ($langs->transnoentitiesnoconv("SeparatorDecimal") != "SeparatorDecimal") {
4818
+		$dec=$langs->transnoentitiesnoconv("SeparatorDecimal");
4819
+	}
4820
+	if ($langs->transnoentitiesnoconv("SeparatorThousand")!= "SeparatorThousand") {
4821
+		$thousand=$langs->transnoentitiesnoconv("SeparatorThousand");
4822
+	}
4823
+	if ($thousand == 'None') {
4824
+		$thousand='';
4825
+	} elseif ($thousand == 'Space') {
4826
+		$thousand=' ';
4827
+	}
4360 4828
 	//print "amount=".$amount." html=".$form." trunc=".$trunc." nbdecimal=".$nbdecimal." dec='".$dec."' thousand='".$thousand."'<br>";
4361 4829
 
4362 4830
 	// Convert value to universal number format (no thousand separator, '.' as decimal separator)
4363
-	if ($alreadysqlnb != 1)	// If not a PHP number or unknown, we change format
4831
+	if ($alreadysqlnb != 1) {
4832
+		// If not a PHP number or unknown, we change format
4364 4833
 	{
4365 4834
 		//print 'PP'.$amount.' - '.$dec.' - '.$thousand.' - '.intval($amount).'<br>';
4366 4835
 
@@ -4369,7 +4838,9 @@  discard block
 block discarded – undo
4369 4838
 		if (is_numeric($amount))
4370 4839
 		{
4371 4840
 			// We put in temps value of decimal ("0.00001"). Works with 0 and 2.0E-5 and 9999.10
4372
-			$temps=sprintf("%0.10F",$amount-intval($amount));	// temps=0.0000000000 or 0.0000200000 or 9999.1000000000
4841
+			$temps=sprintf("%0.10F",$amount-intval($amount));
4842
+	}
4843
+	// temps=0.0000000000 or 0.0000200000 or 9999.1000000000
4373 4844
 			$temps=preg_replace('/([\.1-9])0+$/','\\1',$temps); // temps=0. or 0.00002 or 9999.1
4374 4845
 			$nbofdec=max(0,dol_strlen($temps)-2);	// -2 to remove "0."
4375 4846
 			$amount=number_format($amount,$nbofdec,$dec,$thousand);
@@ -4377,7 +4848,10 @@  discard block
 block discarded – undo
4377 4848
 		//print "QQ".$amount.'<br>';
4378 4849
 
4379 4850
 		// Now make replace (the main goal of function)
4380
-		if ($thousand != ',' && $thousand != '.') $amount=str_replace(',','.',$amount);	// To accept 2 notations for french users
4851
+		if ($thousand != ',' && $thousand != '.') {
4852
+			$amount=str_replace(',','.',$amount);
4853
+		}
4854
+		// To accept 2 notations for french users
4381 4855
 		$amount=str_replace(' ','',$amount);		// To avoid spaces
4382 4856
 		$amount=str_replace($thousand,'',$amount);	// Replace of thousand before replace of dec to avoid pb if thousand is .
4383 4857
 		$amount=str_replace($dec,'.',$amount);
@@ -4387,13 +4861,24 @@  discard block
 block discarded – undo
4387 4861
 	if ($rounding)
4388 4862
 	{
4389 4863
 		$nbofdectoround='';
4390
-		if ($rounding == 'MU')     $nbofdectoround=$conf->global->MAIN_MAX_DECIMALS_UNIT;
4391
-		elseif ($rounding == 'MT') $nbofdectoround=$conf->global->MAIN_MAX_DECIMALS_TOT;
4392
-		elseif ($rounding == 'MS') $nbofdectoround=empty($conf->global->MAIN_MAX_DECIMALS_STOCK)?5:$conf->global->MAIN_MAX_DECIMALS_STOCK;
4393
-		elseif (is_numeric($rounding))  $nbofdectoround=$rounding; 	// For admin info page
4864
+		if ($rounding == 'MU') {
4865
+			$nbofdectoround=$conf->global->MAIN_MAX_DECIMALS_UNIT;
4866
+		} elseif ($rounding == 'MT') {
4867
+			$nbofdectoround=$conf->global->MAIN_MAX_DECIMALS_TOT;
4868
+		} elseif ($rounding == 'MS') {
4869
+			$nbofdectoround=empty($conf->global->MAIN_MAX_DECIMALS_STOCK)?5:$conf->global->MAIN_MAX_DECIMALS_STOCK;
4870
+		} elseif (is_numeric($rounding)) {
4871
+			$nbofdectoround=$rounding;
4872
+		}
4873
+		// For admin info page
4394 4874
 		//print "RR".$amount.' - '.$nbofdectoround.'<br>';
4395
-		if (dol_strlen($nbofdectoround)) $amount = round($amount,$nbofdectoround);	// $nbofdectoround can be 0.
4396
-		else return 'ErrorBadParameterProvidedToFunction';
4875
+		if (dol_strlen($nbofdectoround)) {
4876
+			$amount = round($amount,$nbofdectoround);
4877
+		}
4878
+		// $nbofdectoround can be 0.
4879
+		else {
4880
+			return 'ErrorBadParameterProvidedToFunction';
4881
+		}
4397 4882
 		//print 'SS'.$amount.' - '.$nbofdec.' - '.$dec.' - '.$thousand.' - '.$nbofdectoround.'<br>';
4398 4883
 
4399 4884
 		// Convert amount to format with dolibarr dec and thousand (this is because PHP convert a number
@@ -4410,7 +4895,10 @@  discard block
 block discarded – undo
4410 4895
 
4411 4896
 		// Always make replace because each math function (like round) replace
4412 4897
 		// with local values and we want a number that has a SQL string format x.y
4413
-		if ($thousand != ',' && $thousand != '.') $amount=str_replace(',','.',$amount);	// To accept 2 notations for french users
4898
+		if ($thousand != ',' && $thousand != '.') {
4899
+			$amount=str_replace(',','.',$amount);
4900
+		}
4901
+		// To accept 2 notations for french users
4414 4902
 		$amount=str_replace(' ','',$amount);		// To avoid spaces
4415 4903
 		$amount=str_replace($thousand,'',$amount);	// Replace of thousand before replace of dec to avoid pb if thousand is .
4416 4904
 		$amount=str_replace($dec,'.',$amount);
@@ -4439,18 +4927,15 @@  discard block
 block discarded – undo
4439 4927
 	{
4440 4928
 		$dimension = $dimension * 1000000;
4441 4929
 		$unit = $unit - 6;
4442
-	}
4443
-	elseif (($forceunitoutput == 'no' && $dimension < 1/10) || (is_numeric($forceunitoutput) && $forceunitoutput == -3))
4930
+	} elseif (($forceunitoutput == 'no' && $dimension < 1/10) || (is_numeric($forceunitoutput) && $forceunitoutput == -3))
4444 4931
 	{
4445 4932
 		$dimension = $dimension * 1000;
4446 4933
 		$unit = $unit - 3;
4447
-	}
4448
-	elseif (($forceunitoutput == 'no' && $dimension > 100000000) || (is_numeric($forceunitoutput) && $forceunitoutput == 6))
4934
+	} elseif (($forceunitoutput == 'no' && $dimension > 100000000) || (is_numeric($forceunitoutput) && $forceunitoutput == 6))
4449 4935
 	{
4450 4936
 		$dimension = $dimension / 1000000;
4451 4937
 		$unit = $unit + 6;
4452
-	}
4453
-	elseif (($forceunitoutput == 'no' && $dimension > 100000) || (is_numeric($forceunitoutput) && $forceunitoutput == 3))
4938
+	} elseif (($forceunitoutput == 'no' && $dimension > 100000) || (is_numeric($forceunitoutput) && $forceunitoutput == 3))
4454 4939
 	{
4455 4940
 		$dimension = $dimension / 1000;
4456 4941
 		$unit = $unit + 3;
@@ -4478,14 +4963,18 @@  discard block
 block discarded – undo
4478 4963
 {
4479 4964
 	global $db, $conf, $mysoc;
4480 4965
 
4481
-	if (empty($thirdparty_seller) || ! is_object($thirdparty_seller)) $thirdparty_seller=$mysoc;
4966
+	if (empty($thirdparty_seller) || ! is_object($thirdparty_seller)) {
4967
+		$thirdparty_seller=$mysoc;
4968
+	}
4482 4969
 
4483 4970
 	dol_syslog("get_localtax tva=".$vatrate." local=".$local." thirdparty_buyer id=".(is_object($thirdparty_buyer)?$thirdparty_buyer->id:'')."/country_code=".(is_object($thirdparty_buyer)?$thirdparty_buyer->country_code:'')." thirdparty_seller id=".$thirdparty_seller->id."/country_code=".$thirdparty_seller->country_code." thirdparty_seller localtax1_assuj=".$thirdparty_seller->localtax1_assuj."  thirdparty_seller localtax2_assuj=".$thirdparty_seller->localtax2_assuj);
4484 4971
 
4485 4972
 	$vatratecleaned = $vatrate;
4486
-	if (preg_match('/^(.*)\s*\((.*)\)$/', $vatrate, $reg))      // If vat is "xx (yy)"
4973
+	if (preg_match('/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) {
4974
+		// If vat is "xx (yy)"
4487 4975
 	{
4488 4976
 		$vatratecleaned = trim($reg[1]);
4977
+	}
4489 4978
 		$vatratecode = $reg[2];
4490 4979
 	}
4491 4980
 
@@ -4495,38 +4984,51 @@  discard block
 block discarded – undo
4495 4984
 	}*/
4496 4985
 
4497 4986
 	// Some test to guess with no need to make database access
4498
-	if ($mysoc->country_code == 'ES') // For spain localtaxes 1 and 2, tax is qualified if buyer use local tax
4987
+	if ($mysoc->country_code == 'ES') {
4988
+		// For spain localtaxes 1 and 2, tax is qualified if buyer use local tax
4499 4989
 	{
4500 4990
 		if ($local == 1)
4501 4991
 		{
4502 4992
 			if (! $mysoc->localtax1_assuj || (string) $vatratecleaned == "0") return 0;
4993
+	}
4503 4994
 			if ($thirdparty_seller->id == $mysoc->id)
4504 4995
 			{
4505
-				if (! $thirdparty_buyer->localtax1_assuj) return 0;
4506
-			}
4507
-			else
4996
+				if (! $thirdparty_buyer->localtax1_assuj) {
4997
+					return 0;
4998
+				}
4999
+			} else
4508 5000
 			{
4509
-				if (! $thirdparty_seller->localtax1_assuj) return 0;
5001
+				if (! $thirdparty_seller->localtax1_assuj) {
5002
+					return 0;
5003
+				}
4510 5004
 			}
4511 5005
 		}
4512 5006
 
4513 5007
 		if ($local == 2)
4514 5008
 		{
4515
-			if (! $mysoc->localtax2_assuj || (string) $vatratecleaned == "0") return 0;
5009
+			if (! $mysoc->localtax2_assuj || (string) $vatratecleaned == "0") {
5010
+				return 0;
5011
+			}
4516 5012
 			if ($thirdparty_seller->id == $mysoc->id)
4517 5013
 			{
4518
-				if (! $thirdparty_buyer->localtax2_assuj) return 0;
4519
-			}
4520
-			else
5014
+				if (! $thirdparty_buyer->localtax2_assuj) {
5015
+					return 0;
5016
+				}
5017
+			} else
4521 5018
 			{
4522
-				if (! $thirdparty_seller->localtax2_assuj) return 0;
5019
+				if (! $thirdparty_seller->localtax2_assuj) {
5020
+					return 0;
5021
+				}
4523 5022
 			}
4524 5023
 		}
4525
-	}
4526
-	else
5024
+	} else
4527 5025
 	{
4528
-		if ($local == 1 && ! $thirdparty_seller->localtax1_assuj) return 0;
4529
-		if ($local == 2 && ! $thirdparty_seller->localtax2_assuj) return 0;
5026
+		if ($local == 1 && ! $thirdparty_seller->localtax1_assuj) {
5027
+			return 0;
5028
+		}
5029
+		if ($local == 2 && ! $thirdparty_seller->localtax2_assuj) {
5030
+			return 0;
5031
+		}
4530 5032
 	}
4531 5033
 
4532 5034
 	// For some country MAIN_GET_LOCALTAXES_VALUES_FROM_THIRDPARTY is forced to on.
@@ -4542,35 +5044,41 @@  discard block
 block discarded – undo
4542 5044
 		{
4543 5045
 			if ($thirdparty_seller != $mysoc)
4544 5046
 			{
4545
-				if (!isOnlyOneLocalTax($local))  // TODO We should provide $vatrate to search on correct line and not always on line with highest vat rate
5047
+				if (!isOnlyOneLocalTax($local)) {
5048
+					// TODO We should provide $vatrate to search on correct line and not always on line with highest vat rate
4546 5049
 				{
4547 5050
 					return $thirdparty_seller->localtax1_value;
4548 5051
 				}
4549
-			}
4550
-			else  // i am the seller
5052
+				}
5053
+			} else  // i am the seller
4551 5054
 			{
4552
-				if (!isOnlyOneLocalTax($local))  // TODO If seller is me, why not always returning this, even if there is only one locatax vat.
5055
+				if (!isOnlyOneLocalTax($local)) {
5056
+					// TODO If seller is me, why not always returning this, even if there is only one locatax vat.
4553 5057
 				{
4554 5058
 					return $conf->global->MAIN_INFO_VALUE_LOCALTAX1;
4555 5059
 				}
5060
+				}
4556 5061
 			}
4557 5062
 		}
4558 5063
 		if ($local==2)
4559 5064
 		{
4560 5065
 			if ($thirdparty_seller != $mysoc)
4561 5066
 			{
4562
-				if (!isOnlyOneLocalTax($local))  // TODO We should provide $vatrate to search on correct line and not always on line with highest vat rate
5067
+				if (!isOnlyOneLocalTax($local)) {
5068
+					// TODO We should provide $vatrate to search on correct line and not always on line with highest vat rate
4563 5069
 				// TODO We should also return value defined on thirdparty only if defined
4564 5070
 				{
4565 5071
 					return $thirdparty_seller->localtax2_value;
4566 5072
 				}
4567
-			}
4568
-			else  // i am the seller
5073
+				}
5074
+			} else  // i am the seller
4569 5075
 			{
4570
-				if (!isOnlyOneLocalTax($local))  // This is for spain only, we don't return value found into datbase even if there is only one locatax vat.
5076
+				if (!isOnlyOneLocalTax($local)) {
5077
+					// This is for spain only, we don't return value found into datbase even if there is only one locatax vat.
4571 5078
 				{
4572 5079
 					return $conf->global->MAIN_INFO_VALUE_LOCALTAX2;
4573 5080
 				}
5081
+				}
4574 5082
 			}
4575 5083
 		}
4576 5084
 	}
@@ -4580,16 +5088,24 @@  discard block
 block discarded – undo
4580 5088
    	$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
4581 5089
    	$sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$thirdparty_seller->country_code."'";
4582 5090
    	$sql .= " AND t.taux = ".((float) $vatratecleaned)." AND t.active = 1";
4583
-   	if ($vatratecode) $sql.= " AND t.code ='".$vatratecode."'";		// If we have the code, we use it in priority
4584
-   	else $sql.= " AND t.recuperableonly ='".$vatnpr."'";
5091
+   	if ($vatratecode) {
5092
+   		$sql.= " AND t.code ='".$vatratecode."'";
5093
+   	}
5094
+   	// If we have the code, we use it in priority
5095
+   	else {
5096
+   		$sql.= " AND t.recuperableonly ='".$vatnpr."'";
5097
+   	}
4585 5098
    	dol_syslog("get_localtax", LOG_DEBUG);
4586 5099
    	$resql=$db->query($sql);
4587 5100
 
4588 5101
    	if ($resql)
4589 5102
    	{
4590 5103
    		$obj = $db->fetch_object($resql);
4591
-   		if ($local==1) return $obj->localtax1;
4592
-   		elseif ($local==2) return $obj->localtax2;
5104
+   		if ($local==1) {
5105
+   			return $obj->localtax1;
5106
+   		} elseif ($local==2) {
5107
+   			return $obj->localtax2;
5108
+   		}
4593 5109
 	}
4594 5110
 
4595 5111
 	return 0;
@@ -4613,8 +5129,7 @@  discard block
 block discarded – undo
4613 5129
 	if (count($valors)>1)
4614 5130
 	{
4615 5131
 		return false;
4616
-	}
4617
-	else
5132
+	} else
4618 5133
 	{
4619 5134
 		return true;
4620 5135
 	}
@@ -4640,8 +5155,11 @@  discard block
 block discarded – undo
4640 5155
 	if ($resql)
4641 5156
 	{
4642 5157
 		$obj = $db->fetch_object($resql);
4643
-		if ($local==1) return $obj->localtax1;
4644
-		elseif ($local==2) return $obj->localtax2;
5158
+		if ($local==1) {
5159
+			return $obj->localtax1;
5160
+		} elseif ($local==2) {
5161
+			return $obj->localtax2;
5162
+		}
4645 5163
 	}
4646 5164
 
4647 5165
 	return 0;
@@ -4669,32 +5187,46 @@  discard block
 block discarded – undo
4669 5187
 	// Search local taxes
4670 5188
 	$sql = "SELECT t.rowid, t.code, t.taux as rate, t.recuperableonly as npr, t.accountancy_code_sell, t.accountancy_code_buy";
4671 5189
 	$sql.= " FROM ".MAIN_DB_PREFIX."c_tva as t";
4672
-	if ($firstparamisid) $sql.= " WHERE t.rowid = ".(int) $vatrate;
4673
-	else
5190
+	if ($firstparamisid) {
5191
+		$sql.= " WHERE t.rowid = ".(int) $vatrate;
5192
+	} else
4674 5193
 	{
4675 5194
 		$vatratecleaned = $vatrate;
4676 5195
 		$vatratecode = '';
4677
-		if (preg_match('/^(.*)\s*\((.*)\)$/', $vatrate, $reg))      // If vat is "xx (yy)"
5196
+		if (preg_match('/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) {
5197
+			// If vat is "xx (yy)"
4678 5198
 		{
4679 5199
 			$vatratecleaned = $reg[1];
5200
+		}
4680 5201
 			$vatratecode = $reg[2];
4681 5202
 		}
4682 5203
 
4683 5204
 		$sql.=", ".MAIN_DB_PREFIX."c_country as c";
4684
-		if ($mysoc->country_code == 'ES') $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$buyer->country_code."'";    // local tax in spain use the buyer country ??
4685
-		else $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$seller->country_code."'";
5205
+		if ($mysoc->country_code == 'ES') {
5206
+			$sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$buyer->country_code."'";
5207
+		}
5208
+		// local tax in spain use the buyer country ??
5209
+		else {
5210
+			$sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$seller->country_code."'";
5211
+		}
4686 5212
 		$sql.= " AND t.taux = ".((float) $vatratecleaned)." AND t.active = 1";
4687
-		if ($vatratecode) $sql.= " AND t.code = '".$vatratecode."'";
5213
+		if ($vatratecode) {
5214
+			$sql.= " AND t.code = '".$vatratecode."'";
5215
+		}
4688 5216
 	}
4689 5217
 
4690 5218
 	$resql=$db->query($sql);
4691 5219
 	if ($resql)
4692 5220
 	{
4693 5221
 		$obj = $db->fetch_object($resql);
4694
-		if ($obj) return array('rowid'=>$obj->rowid, 'code'=>$obj->code, 'rate'=>$obj->rate, 'npr'=>$obj->npr, 'accountancy_code_sell'=>$obj->accountancy_code_sell, 'accountancy_code_buy'=>$obj->accountancy_code_buy);
4695
-		else return array();
5222
+		if ($obj) {
5223
+			return array('rowid'=>$obj->rowid, 'code'=>$obj->code, 'rate'=>$obj->rate, 'npr'=>$obj->npr, 'accountancy_code_sell'=>$obj->accountancy_code_sell, 'accountancy_code_buy'=>$obj->accountancy_code_buy);
5224
+		} else {
5225
+			return array();
5226
+		}
5227
+	} else {
5228
+		dol_print_error($db);
4696 5229
 	}
4697
-	else dol_print_error($db);
4698 5230
 
4699 5231
 	return array();
4700 5232
 }
@@ -4724,22 +5256,32 @@  discard block
 block discarded – undo
4724 5256
 	// Search local taxes
4725 5257
 	$sql  = "SELECT t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type, t.accountancy_code_sell, t.accountancy_code_buy";
4726 5258
 	$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t";
4727
-	if ($firstparamisid) $sql.= " WHERE t.rowid = ".(int) $vatrate;
4728
-	else
5259
+	if ($firstparamisid) {
5260
+		$sql.= " WHERE t.rowid = ".(int) $vatrate;
5261
+	} else
4729 5262
 	{
4730 5263
 		$vatratecleaned = $vatrate;
4731 5264
 		$vatratecode = '';
4732
-		if (preg_match('/^(.*)\s*\((.*)\)$/', $vatrate, $reg))      // If vat is "xx (yy)"
5265
+		if (preg_match('/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) {
5266
+			// If vat is "xx (yy)"
4733 5267
 		{
4734 5268
 			$vatratecleaned = $reg[1];
5269
+		}
4735 5270
 			$vatratecode = $reg[2];
4736 5271
 		}
4737 5272
 
4738 5273
 		$sql.=", ".MAIN_DB_PREFIX."c_country as c";
4739
-		if ($mysoc->country_code == 'ES') $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$buyer->country_code."'";    // local tax in spain use the buyer country ??
4740
-		else $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$seller->country_code."'";
5274
+		if ($mysoc->country_code == 'ES') {
5275
+			$sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$buyer->country_code."'";
5276
+		}
5277
+		// local tax in spain use the buyer country ??
5278
+		else {
5279
+			$sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$seller->country_code."'";
5280
+		}
4741 5281
 		$sql.= " AND t.taux = ".((float) $vatratecleaned)." AND t.active = 1";
4742
-		if ($vatratecode) $sql.= " AND t.code = '".$vatratecode."'";
5282
+		if ($vatratecode) {
5283
+			$sql.= " AND t.code = '".$vatratecode."'";
5284
+		}
4743 5285
 	}
4744 5286
 
4745 5287
 	$resql=$db->query($sql);
@@ -4751,43 +5293,36 @@  discard block
 block discarded – undo
4751 5293
 			if (! isOnlyOneLocalTax(1))
4752 5294
 			{
4753 5295
 				return array($obj->localtax1_type, get_localtax($vatrate, $local, $buyer, $seller), $obj->accountancy_code_sell, $obj->accountancy_code_buy);
4754
-			}
4755
-			else
5296
+			} else
4756 5297
 			{
4757 5298
 				return array($obj->localtax1_type, $obj->localtax1,$obj->accountancy_code_sell, $obj->accountancy_code_buy);
4758 5299
 			}
4759
-		}
4760
-		elseif ($local == 2)
5300
+		} elseif ($local == 2)
4761 5301
 		{
4762 5302
 			if (! isOnlyOneLocalTax(2))
4763 5303
 			{
4764 5304
 				return array($obj->localtax2_type, get_localtax($vatrate, $local, $buyer, $seller),$obj->accountancy_code_sell, $obj->accountancy_code_buy);
4765
-			}
4766
-			else
5305
+			} else
4767 5306
 			{
4768 5307
 				return array($obj->localtax2_type, $obj->localtax2,$obj->accountancy_code_sell, $obj->accountancy_code_buy);
4769 5308
 			}
4770
-		}
4771
-		else
5309
+		} else
4772 5310
 		{
4773 5311
 			if(! isOnlyOneLocalTax(1))
4774 5312
 			{
4775 5313
 				if(! isOnlyOneLocalTax(2))
4776 5314
 				{
4777 5315
 					return array($obj->localtax1_type, get_localtax($vatrate, 1, $buyer, $seller), $obj->localtax2_type, get_localtax($vatrate, 2, $buyer, $seller), $obj->accountancy_code_sell,$obj->accountancy_code_buy);
4778
-				}
4779
-				else
5316
+				} else
4780 5317
 				{
4781 5318
 					return array($obj->localtax1_type, get_localtax($vatrate, 1, $buyer, $seller), $obj->localtax2_type, $obj->localtax2, $obj->accountancy_code_sell, $obj->accountancy_code_buy);
4782 5319
 				}
4783
-			}
4784
-			else
5320
+			} else
4785 5321
 			{
4786 5322
 				if(! isOnlyOneLocalTax(2))
4787 5323
 				{
4788 5324
 					return array($obj->localtax1_type, $obj->localtax1, $obj->localtax2_type, get_localtax($vatrate, 2, $buyer, $seller), $obj->accountancy_code_sell, $obj->accountancy_code_buy);
4789
-				}
4790
-				else
5325
+				} else
4791 5326
 				{
4792 5327
 					return array($obj->localtax1_type, $obj->localtax1, $obj->localtax2_type, $obj->localtax2, $obj->accountancy_code_sell, $obj->accountancy_code_buy);
4793 5328
 				}
@@ -4823,22 +5358,26 @@  discard block
 block discarded – undo
4823 5358
 		$product=new Product($db);
4824 5359
 		$result=$product->fetch($idprod);
4825 5360
 
4826
-		if ($mysoc->country_code == $thirdparty_seller->country_code) // If selling country is ours
5361
+		if ($mysoc->country_code == $thirdparty_seller->country_code) {
5362
+			// If selling country is ours
4827 5363
 		{
4828 5364
 			if ($idprodfournprice > 0)     // We want vat for product for a "supplier" order or invoice
4829 5365
 			{
4830 5366
 				$product->get_buyprice($idprodfournprice,0,0,0);
5367
+		}
4831 5368
 				$ret=$product->vatrate_supplier;
4832
-				if ($product->default_vat_code) $ret.=' ('.$product->default_vat_code.')';
4833
-			}
4834
-			else
5369
+				if ($product->default_vat_code) {
5370
+					$ret.=' ('.$product->default_vat_code.')';
5371
+				}
5372
+			} else
4835 5373
 			{
4836 5374
 				$ret=$product->tva_tx;    // Default vat of product we defined
4837
-				if ($product->default_vat_code) $ret.=' ('.$product->default_vat_code.')';
5375
+				if ($product->default_vat_code) {
5376
+					$ret.=' ('.$product->default_vat_code.')';
5377
+				}
4838 5378
 			}
4839 5379
 			$found=1;
4840
-		}
4841
-		else
5380
+		} else
4842 5381
 		{
4843 5382
 			// TODO Read default product vat according to countrycode and product. Vat for couple countrycode/product is a feature not implemeted yet.
4844 5383
 			// May be usefull/required if hidden option SERVICE_ARE_ECOMMERCE_200238EC is on
@@ -4865,10 +5404,13 @@  discard block
 block discarded – undo
4865 5404
 					$ret=$obj->vat_rate;
4866 5405
 				}
4867 5406
 				$db->free($sql);
5407
+			} else {
5408
+				dol_print_error($db);
4868 5409
 			}
4869
-			else dol_print_error($db);
5410
+		} else {
5411
+			$ret=$conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS;
4870 5412
 		}
4871
-		else $ret=$conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS;    // Forced value if autodetect fails
5413
+		// Forced value if autodetect fails
4872 5414
 	}
4873 5415
 
4874 5416
 	dol_syslog("get_product_vat_for_country: ret=".$ret);
@@ -4901,7 +5443,8 @@  discard block
 block discarded – undo
4901 5443
 		$product=new Product($db);
4902 5444
 		$result=$product->fetch($idprod);
4903 5445
 
4904
-		if ($mysoc->country_code == $thirdparty_seller->country_code) // If selling country is ours
5446
+		if ($mysoc->country_code == $thirdparty_seller->country_code) {
5447
+			// If selling country is ours
4905 5448
 		{
4906 5449
 			/* Not defined yet, so we don't use this
4907 5450
 			if ($local==1) $ret=$product->localtax1_tx;
@@ -4921,6 +5464,7 @@  discard block
 block discarded – undo
4921 5464
 	{
4922 5465
 		// If vat of product for the country not found or not defined, we return higher vat of country.
4923 5466
 		$sql = "SELECT taux as vat_rate, localtax1, localtax2";
5467
+		}
4924 5468
 		$sql.= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
4925 5469
 		$sql.= " WHERE t.active=1 AND t.fk_pays = c.rowid AND c.code='".$thirdparty_seller->country_code."'";
4926 5470
 		$sql.= " ORDER BY t.taux DESC, t.recuperableonly ASC";
@@ -4932,11 +5476,15 @@  discard block
 block discarded – undo
4932 5476
 			$obj=$db->fetch_object($resql);
4933 5477
 			if ($obj)
4934 5478
 			{
4935
-				if ($local==1) $ret=$obj->localtax1;
4936
-				elseif ($local==2) $ret=$obj->localtax2;
5479
+				if ($local==1) {
5480
+					$ret=$obj->localtax1;
5481
+				} elseif ($local==2) {
5482
+					$ret=$obj->localtax2;
5483
+				}
4937 5484
 			}
5485
+		} else {
5486
+			dol_print_error($db);
4938 5487
 		}
4939
-		else dol_print_error($db);
4940 5488
 	}
4941 5489
 
4942 5490
 	dol_syslog("get_product_localtax_for_country: ret=".$ret);
@@ -4998,11 +5546,13 @@  discard block
 block discarded – undo
4998 5546
 
4999 5547
 	// Si le (pays vendeur = pays acheteur) alors la TVA par defaut=TVA du produit vendu. Fin de regle.
5000 5548
 	if (($seller_country_code == $buyer_country_code)
5001
-	|| (in_array($seller_country_code,array('FR,MC')) && in_array($buyer_country_code,array('FR','MC')))) // Warning ->country_code not always defined
5549
+	|| (in_array($seller_country_code,array('FR,MC')) && in_array($buyer_country_code,array('FR','MC')))) {
5550
+		// Warning ->country_code not always defined
5002 5551
 	{
5003 5552
 		//print 'VATRULE 2';
5004 5553
 		return get_product_vat_for_country($idprod,$thirdparty_seller,$idprodfournprice);
5005 5554
 	}
5555
+	}
5006 5556
 
5007 5557
 	// Si (vendeur et acheteur dans Communaute europeenne) et (bien vendu = moyen de transports neuf comme auto, bateau, avion) alors TVA par defaut=0 (La TVA doit etre paye par l'acheteur au centre d'impots de son pays et non au vendeur). Fin de regle.
5008 5558
 	// Not supported
@@ -5016,8 +5566,7 @@  discard block
 block discarded – undo
5016 5566
 		{
5017 5567
 			//print 'VATRULE 3';
5018 5568
 			return 0;
5019
-		}
5020
-		else
5569
+		} else
5021 5570
 		{
5022 5571
 			//print 'VATRULE 4';
5023 5572
 			return get_product_vat_for_country($idprod,$thirdparty_seller,$idprodfournprice);
@@ -5047,16 +5596,17 @@  discard block
 block discarded – undo
5047 5596
 
5048 5597
 	if ($idprodfournprice > 0)
5049 5598
 	{
5050
-		if (! class_exists('ProductFournisseur'))
5051
-			require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.product.class.php';
5599
+		if (! class_exists('ProductFournisseur')) {
5600
+					require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.product.class.php';
5601
+		}
5052 5602
 		$prodprice = new ProductFournisseur($db);
5053 5603
 		$prodprice->fetch_product_fournisseur_price($idprodfournprice);
5054 5604
 		return $prodprice->fourn_tva_npr;
5055
-	}
5056
-	elseif ($idprod > 0)
5605
+	} elseif ($idprod > 0)
5057 5606
 	{
5058
-		if (! class_exists('Product'))
5059
-			require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
5607
+		if (! class_exists('Product')) {
5608
+					require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
5609
+		}
5060 5610
 		$prod = new Product($db);
5061 5611
 		$prod->fetch($idprod);
5062 5612
 		return $prod->tva_npr;
@@ -5082,27 +5632,39 @@  discard block
 block discarded – undo
5082 5632
 {
5083 5633
 	global $mysoc;
5084 5634
 
5085
-	if (!is_object($thirdparty_seller)) return -1;
5086
-	if (!is_object($thirdparty_buyer)) return -1;
5635
+	if (!is_object($thirdparty_seller)) {
5636
+		return -1;
5637
+	}
5638
+	if (!is_object($thirdparty_buyer)) {
5639
+		return -1;
5640
+	}
5087 5641
 
5088
-	if ($local==1) // Localtax 1
5642
+	if ($local==1) {
5643
+		// Localtax 1
5089 5644
 	{
5090 5645
 		if ($mysoc->country_code == 'ES')
5091 5646
 		{
5092 5647
 			if (is_numeric($thirdparty_buyer->localtax1_assuj) && ! $thirdparty_buyer->localtax1_assuj) return 0;
5093
-		}
5094
-		else
5648
+	}
5649
+		} else
5095 5650
 		{
5096 5651
 			// Si vendeur non assujeti a Localtax1, localtax1 par default=0
5097
-			if (is_numeric($thirdparty_seller->localtax1_assuj) && ! $thirdparty_seller->localtax1_assuj) return 0;
5098
-			if (! is_numeric($thirdparty_seller->localtax1_assuj) && $thirdparty_seller->localtax1_assuj=='localtax1off') return 0;
5652
+			if (is_numeric($thirdparty_seller->localtax1_assuj) && ! $thirdparty_seller->localtax1_assuj) {
5653
+				return 0;
5654
+			}
5655
+			if (! is_numeric($thirdparty_seller->localtax1_assuj) && $thirdparty_seller->localtax1_assuj=='localtax1off') {
5656
+				return 0;
5657
+			}
5099 5658
 		}
5100
-	}
5101
-	elseif ($local==2) //I Localtax 2
5659
+	} elseif ($local==2) {
5660
+		//I Localtax 2
5102 5661
 	{
5103 5662
 		// Si vendeur non assujeti a Localtax2, localtax2 par default=0
5104 5663
 		if (is_numeric($thirdparty_seller->localtax2_assuj) && ! $thirdparty_seller->localtax2_assuj) return 0;
5105
-		if (! is_numeric($thirdparty_seller->localtax2_assuj) && $thirdparty_seller->localtax2_assuj=='localtax2off') return 0;
5664
+	}
5665
+		if (! is_numeric($thirdparty_seller->localtax2_assuj) && $thirdparty_seller->localtax2_assuj=='localtax2off') {
5666
+			return 0;
5667
+		}
5106 5668
 	}
5107 5669
 
5108 5670
 	if ($thirdparty_seller->country_code == $thirdparty_buyer->country_code)
@@ -5125,26 +5687,44 @@  discard block
 block discarded – undo
5125 5687
 {
5126 5688
 	global $langs;
5127 5689
 	$result='unknown'; $classname='';
5128
-	if ($yesno == 1 || strtolower($yesno) == 'yes' || strtolower($yesno) == 'true') 	// A mettre avant test sur no a cause du == 0
5690
+	if ($yesno == 1 || strtolower($yesno) == 'yes' || strtolower($yesno) == 'true') {
5691
+		// A mettre avant test sur no a cause du == 0
5129 5692
 	{
5130 5693
 		$result=$langs->trans('yes');
5131
-		if ($case == 1 || $case == 3) $result=$langs->trans("Yes");
5132
-		if ($case == 2) $result='<input type="checkbox" value="1" checked disabled>';
5133
-		if ($case == 3) $result='<input type="checkbox" value="1" checked disabled> '.$result;
5694
+	}
5695
+		if ($case == 1 || $case == 3) {
5696
+			$result=$langs->trans("Yes");
5697
+		}
5698
+		if ($case == 2) {
5699
+			$result='<input type="checkbox" value="1" checked disabled>';
5700
+		}
5701
+		if ($case == 3) {
5702
+			$result='<input type="checkbox" value="1" checked disabled> '.$result;
5703
+		}
5134 5704
 
5135 5705
 		$classname='ok';
5136
-	}
5137
-	elseif ($yesno == 0 || strtolower($yesno) == 'no' || strtolower($yesno) == 'false')
5706
+	} elseif ($yesno == 0 || strtolower($yesno) == 'no' || strtolower($yesno) == 'false')
5138 5707
 	{
5139 5708
 		$result=$langs->trans("no");
5140
-		if ($case == 1 || $case == 3) $result=$langs->trans("No");
5141
-		if ($case == 2) $result='<input type="checkbox" value="0" disabled>';
5142
-		if ($case == 3) $result='<input type="checkbox" value="0" disabled> '.$result;
5709
+		if ($case == 1 || $case == 3) {
5710
+			$result=$langs->trans("No");
5711
+		}
5712
+		if ($case == 2) {
5713
+			$result='<input type="checkbox" value="0" disabled>';
5714
+		}
5715
+		if ($case == 3) {
5716
+			$result='<input type="checkbox" value="0" disabled> '.$result;
5717
+		}
5143 5718
 
5144
-		if ($color == 2) $classname='ok';
5145
-		else $classname='error';
5719
+		if ($color == 2) {
5720
+			$classname='ok';
5721
+		} else {
5722
+			$classname='error';
5723
+		}
5724
+	}
5725
+	if ($color) {
5726
+		return '<font class="'.$classname.'">'.$result.'</font>';
5146 5727
 	}
5147
-	if ($color) return '<font class="'.$classname.'">'.$result.'</font>';
5148 5728
 	return $result;
5149 5729
 }
5150 5730
 
@@ -5171,18 +5751,28 @@  discard block
 block discarded – undo
5171 5751
 	$path = '';
5172 5752
 
5173 5753
 	$arrayforoldpath=array('cheque','user','category','holiday','supplier_invoice','invoice_supplier','mailing','supplier_payment');
5174
-	if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) $arrayforoldpath[]='product';
5754
+	if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) {
5755
+		$arrayforoldpath[]='product';
5756
+	}
5175 5757
 	if (! empty($level) && in_array($modulepart, $arrayforoldpath))
5176 5758
 	{
5177 5759
 		// This part should be removed once all code is using "get_exdir" to forge path, with all parameters provided.
5178
-		if (empty($alpha)) $num = preg_replace('/([^0-9])/i','',$num);
5179
-		else $num = preg_replace('/^.*\-/i','',$num);
5760
+		if (empty($alpha)) {
5761
+			$num = preg_replace('/([^0-9])/i','',$num);
5762
+		} else {
5763
+			$num = preg_replace('/^.*\-/i','',$num);
5764
+		}
5180 5765
 		$num = substr("000".$num, -$level);
5181
-		if ($level == 1) $path = substr($num,0,1);
5182
-		if ($level == 2) $path = substr($num,1,1).'/'.substr($num,0,1);
5183
-		if ($level == 3) $path = substr($num,2,1).'/'.substr($num,1,1).'/'.substr($num,0,1);
5184
-	}
5185
-	else
5766
+		if ($level == 1) {
5767
+			$path = substr($num,0,1);
5768
+		}
5769
+		if ($level == 2) {
5770
+			$path = substr($num,1,1).'/'.substr($num,0,1);
5771
+		}
5772
+		if ($level == 3) {
5773
+			$path = substr($num,2,1).'/'.substr($num,1,1).'/'.substr($num,0,1);
5774
+		}
5775
+	} else
5186 5776
 	{
5187 5777
 		// TODO
5188 5778
 		// We will enhance here a common way of forging path for document storage
@@ -5193,7 +5783,9 @@  discard block
 block discarded – undo
5193 5783
 		}
5194 5784
 	}
5195 5785
 
5196
-	if (empty($withoutslash) && ! empty($path)) $path.='/';
5786
+	if (empty($withoutslash) && ! empty($path)) {
5787
+		$path.='/';
5788
+	}
5197 5789
 
5198 5790
 	return $path;
5199 5791
 }
@@ -5213,7 +5805,9 @@  discard block
 block discarded – undo
5213 5805
 	dol_syslog("functions.lib::dol_mkdir: dir=".$dir,LOG_INFO);
5214 5806
 
5215 5807
 	$dir_osencoded=dol_osencode($dir);
5216
-	if (@is_dir($dir_osencoded)) return 0;
5808
+	if (@is_dir($dir_osencoded)) {
5809
+		return 0;
5810
+	}
5217 5811
 
5218 5812
 	$nberr=0;
5219 5813
 	$nbcreated=0;
@@ -5229,9 +5823,15 @@  discard block
 block discarded – undo
5229 5823
 	$num=count($cdir);
5230 5824
 	for ($i = 0; $i < $num; $i++)
5231 5825
 	{
5232
-		if ($i > 0) $ccdir .= '/'.$cdir[$i];
5233
-		else $ccdir .= $cdir[$i];
5234
-		if (preg_match("/^.:$/",$ccdir,$regs)) continue;	// Si chemin Windows incomplet, on poursuit par rep suivant
5826
+		if ($i > 0) {
5827
+			$ccdir .= '/'.$cdir[$i];
5828
+		} else {
5829
+			$ccdir .= $cdir[$i];
5830
+		}
5831
+		if (preg_match("/^.:$/",$ccdir,$regs)) {
5832
+			continue;
5833
+		}
5834
+		// Si chemin Windows incomplet, on poursuit par rep suivant
5235 5835
 
5236 5836
 		// Attention, le is_dir() peut echouer bien que le rep existe.
5237 5837
 		// (ex selon config de open_basedir)
@@ -5253,15 +5853,13 @@  discard block
 block discarded – undo
5253 5853
 					// Si le is_dir a renvoye une fausse info, alors on passe ici.
5254 5854
 					dol_syslog("functions.lib::dol_mkdir: Fails to create directory '".$ccdir."' or directory already exists.",LOG_WARNING);
5255 5855
 					$nberr++;
5256
-				}
5257
-				else
5856
+				} else
5258 5857
 				{
5259 5858
 					dol_syslog("functions.lib::dol_mkdir: Directory '".$ccdir."' created",LOG_DEBUG);
5260 5859
 					$nberr=0;	// On remet a zero car si on arrive ici, cela veut dire que les echecs precedents peuvent etre ignore
5261 5860
 					$nbcreated++;
5262 5861
 				}
5263
-			}
5264
-			else
5862
+			} else
5265 5863
 			{
5266 5864
 				$nberr=0;	// On remet a zero car si on arrive ici, cela veut dire que les echecs precedents peuvent etre ignores
5267 5865
 			}
@@ -5310,7 +5908,9 @@  discard block
 block discarded – undo
5310 5908
 	// $temp after pass 2: 0000-021
5311 5909
 
5312 5910
 	// Supprime aussi les retours
5313
-	if ($removelinefeed) $temp=str_replace(array("\r\n","\r","\n")," ",$temp);
5911
+	if ($removelinefeed) {
5912
+		$temp=str_replace(array("\r\n","\r","\n")," ",$temp);
5913
+	}
5314 5914
 
5315 5915
 	// et les espaces doubles
5316 5916
 	while(strpos($temp,"  "))
@@ -5339,14 +5939,12 @@  discard block
 block discarded – undo
5339 5939
 			$firstline=preg_replace('/<br[^>]*>.*$/s','',$text);		// The s pattern modifier means the . can match newline characters
5340 5940
 			$firstline=preg_replace('/<div[^>]*>.*$/s','',$firstline);	// The s pattern modifier means the . can match newline characters
5341 5941
 
5342
-		}
5343
-		else
5942
+		} else
5344 5943
 		{
5345 5944
 			$firstline=preg_replace('/[\n\r].*/','',$text);
5346 5945
 		}
5347 5946
 		return $firstline.((strlen($firstline) != strlen($text))?'...':'');
5348
-	}
5349
-	else
5947
+	} else
5350 5948
 	{
5351 5949
 		$ishtml=0;
5352 5950
 		if (dol_textishtml($text))
@@ -5354,15 +5952,17 @@  discard block
 block discarded – undo
5354 5952
 			$text=preg_replace('/\n/','',$text);
5355 5953
 			$ishtml=1;
5356 5954
 			$repTable = array("\t" => " ", "\n" => " ", "\r" => " ", "\0" => " ", "\x0B" => " ");
5357
-		}
5358
-		else
5955
+		} else
5359 5956
 		{
5360 5957
 			$repTable = array("\t" => " ", "\n" => "<br>", "\r" => " ", "\0" => " ", "\x0B" => " ");
5361 5958
 		}
5362 5959
 
5363 5960
 		$text = strtr($text, $repTable);
5364 5961
 		if ($charset == 'UTF-8') { $pattern = '/(<br[^>]*>)/Uu'; }	// /U is to have UNGREEDY regex to limit to one html tag. /u is for UTF8 support
5365
-		else $pattern = '/(<br[^>]*>)/U';							// /U is to have UNGREEDY regex to limit to one html tag.
5962
+		else {
5963
+			$pattern = '/(<br[^>]*>)/U';
5964
+		}
5965
+		// /U is to have UNGREEDY regex to limit to one html tag.
5366 5966
 		$a = preg_split($pattern, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
5367 5967
 
5368 5968
 		$firstline='';
@@ -5370,8 +5970,11 @@  discard block
 block discarded – undo
5370 5970
 		$nba = count($a);	// 2x nb of lines in $a because $a contains also a line for each new line separator
5371 5971
 		while (($i < $nba) && ($i < ($nboflines * 2)))
5372 5972
 		{
5373
-			if ($i % 2 == 0) $firstline .= $a[$i];
5374
-			elseif (($i < (($nboflines * 2) - 1)) && ($i < ($nba - 1))) $firstline .= ($ishtml?"<br>\n":"\n");
5973
+			if ($i % 2 == 0) {
5974
+				$firstline .= $a[$i];
5975
+			} elseif (($i < (($nboflines * 2) - 1)) && ($i < ($nba - 1))) {
5976
+				$firstline .= ($ishtml?"<br>\n":"\n");
5977
+			}
5375 5978
 			$i++;
5376 5979
 		}
5377 5980
 		unset($a);
@@ -5420,17 +6023,25 @@  discard block
 block discarded – undo
5420 6023
 function dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
5421 6024
 {
5422 6025
 	$newstring=$stringtoencode;
5423
-	if (dol_textishtml($stringtoencode))	// Check if text is already HTML or not
6026
+	if (dol_textishtml($stringtoencode)) {
6027
+		// Check if text is already HTML or not
5424 6028
 	{
5425
-		$newstring=preg_replace('/<br(\s[\sa-zA-Z_="]*)?\/?>/i','<br>',$newstring);	// Replace "<br type="_moz" />" by "<br>". It's same and avoid pb with FPDF.
5426
-		if ($removelasteolbr) $newstring=preg_replace('/<br>$/i','',$newstring);	// Remove last <br> (remove only last one)
6029
+		$newstring=preg_replace('/<br(\s[\sa-zA-Z_="]*)?\/?>/i','<br>',$newstring);
6030
+	}
6031
+	// Replace "<br type="_moz" />" by "<br>". It's same and avoid pb with FPDF.
6032
+		if ($removelasteolbr) {
6033
+			$newstring=preg_replace('/<br>$/i','',$newstring);
6034
+		}
6035
+		// Remove last <br> (remove only last one)
5427 6036
 		$newstring=strtr($newstring,array('&'=>'__and__','<'=>'__lt__','>'=>'__gt__','"'=>'__dquot__'));
5428 6037
 		$newstring=dol_htmlentities($newstring,ENT_COMPAT,$pagecodefrom);	// Make entity encoding
5429 6038
 		$newstring=strtr($newstring,array('__and__'=>'&','__lt__'=>'<','__gt__'=>'>','__dquot__'=>'"'));
5430
-	}
5431
-	else
6039
+	} else
5432 6040
 	{
5433
-		if ($removelasteolbr) $newstring=preg_replace('/(\r\n|\r|\n)$/i','',$newstring);	// Remove last \n (may remove several)
6041
+		if ($removelasteolbr) {
6042
+			$newstring=preg_replace('/(\r\n|\r|\n)$/i','',$newstring);
6043
+		}
6044
+		// Remove last \n (may remove several)
5434 6045
 		$newstring=dol_nl2br(dol_htmlentities($newstring,ENT_COMPAT,$pagecodefrom),$nl2brmode);
5435 6046
 	}
5436 6047
 	// Other substitutions that htmlentities does not do
@@ -5528,7 +6139,9 @@  discard block
 block discarded – undo
5528 6139
  */
5529 6140
 function dol_nboflines($s,$maxchar=0)
5530 6141
 {
5531
-	if ($s == '') return 0;
6142
+	if ($s == '') {
6143
+		return 0;
6144
+	}
5532 6145
 	$arraystring=explode("\n",$s);
5533 6146
 	$nb=count($arraystring);
5534 6147
 
@@ -5548,11 +6161,16 @@  discard block
 block discarded – undo
5548 6161
 function dol_nboflines_bis($text,$maxlinesize=0,$charset='UTF-8')
5549 6162
 {
5550 6163
 	$repTable = array("\t" => " ", "\n" => "<br>", "\r" => " ", "\0" => " ", "\x0B" => " ");
5551
-	if (dol_textishtml($text)) $repTable = array("\t" => " ", "\n" => " ", "\r" => " ", "\0" => " ", "\x0B" => " ");
6164
+	if (dol_textishtml($text)) {
6165
+		$repTable = array("\t" => " ", "\n" => " ", "\r" => " ", "\0" => " ", "\x0B" => " ");
6166
+	}
5552 6167
 
5553 6168
 	$text = strtr($text, $repTable);
5554 6169
 	if ($charset == 'UTF-8') { $pattern = '/(<br[^>]*>)/Uu'; }	// /U is to have UNGREEDY regex to limit to one html tag. /u is for UTF8 support
5555
-	else $pattern = '/(<br[^>]*>)/U';							// /U is to have UNGREEDY regex to limit to one html tag.
6170
+	else {
6171
+		$pattern = '/(<br[^>]*>)/U';
6172
+	}
6173
+	// /U is to have UNGREEDY regex to limit to one html tag.
5556 6174
 	$a = preg_split($pattern, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
5557 6175
 
5558 6176
 	$nblines = (int) floor((count($a)+1)/2);
@@ -5604,24 +6222,46 @@  discard block
 block discarded – undo
5604 6222
 {
5605 6223
 	if ($option == 1)
5606 6224
 	{
5607
-		if (preg_match('/<html/i',$msg))				return true;
5608
-		elseif (preg_match('/<body/i',$msg))			return true;
5609
-		elseif (preg_match('/<br/i',$msg))				return true;
6225
+		if (preg_match('/<html/i',$msg)) {
6226
+			return true;
6227
+		} elseif (preg_match('/<body/i',$msg)) {
6228
+			return true;
6229
+		} elseif (preg_match('/<br/i',$msg)) {
6230
+			return true;
6231
+		}
5610 6232
 		return false;
5611
-	}
5612
-	else
5613
-	{
5614
-		if (preg_match('/<html/i',$msg))				return true;
5615
-		elseif (preg_match('/<body/i',$msg))			return true;
5616
-		elseif (preg_match('/<(b|em|i|u)>/i',$msg))		return true;
5617
-		elseif (preg_match('/<(br|div|font|li|p|span|strong|table)>/i',$msg)) 	  return true;
5618
-		elseif (preg_match('/<(br|div|font|li|p|span|strong|table)\s+[^<>\/]*>/i',$msg)) return true;
5619
-		elseif (preg_match('/<(br|div|font|li|p|span|strong|table)\s+[^<>\/]*\/>/i',$msg)) return true;
5620
-		elseif (preg_match('/<img\s+[^<>]*src[^<>]*>/i',$msg)) return true;	// must accept <img src="http://example.com/aaa.png" />
5621
-		elseif (preg_match('/<a\s+[^<>]*href[^<>]*>/i',$msg)) return true;	// must accept <a href="http://example.com/aaa.png" />
5622
-		elseif (preg_match('/<h[0-9]>/i',$msg))			return true;
5623
-		elseif (preg_match('/&[A-Z0-9]{1,6};/i',$msg))	return true;    // Html entities names (http://www.w3schools.com/tags/ref_entities.asp)
5624
-		elseif (preg_match('/&#[0-9]{2,3};/i',$msg))	return true;    // Html entities numbers (http://www.w3schools.com/tags/ref_entities.asp)
6233
+	} else
6234
+	{
6235
+		if (preg_match('/<html/i',$msg)) {
6236
+			return true;
6237
+		} elseif (preg_match('/<body/i',$msg)) {
6238
+			return true;
6239
+		} elseif (preg_match('/<(b|em|i|u)>/i',$msg)) {
6240
+			return true;
6241
+		} elseif (preg_match('/<(br|div|font|li|p|span|strong|table)>/i',$msg)) {
6242
+			return true;
6243
+		} elseif (preg_match('/<(br|div|font|li|p|span|strong|table)\s+[^<>\/]*>/i',$msg)) {
6244
+			return true;
6245
+		} elseif (preg_match('/<(br|div|font|li|p|span|strong|table)\s+[^<>\/]*\/>/i',$msg)) {
6246
+			return true;
6247
+		} elseif (preg_match('/<img\s+[^<>]*src[^<>]*>/i',$msg)) {
6248
+			return true;
6249
+		}
6250
+		// must accept <img src="http://example.com/aaa.png" />
6251
+		elseif (preg_match('/<a\s+[^<>]*href[^<>]*>/i',$msg)) {
6252
+			return true;
6253
+		}
6254
+		// must accept <a href="http://example.com/aaa.png" />
6255
+		elseif (preg_match('/<h[0-9]>/i',$msg)) {
6256
+			return true;
6257
+		} elseif (preg_match('/&[A-Z0-9]{1,6};/i',$msg)) {
6258
+			return true;
6259
+		}
6260
+		// Html entities names (http://www.w3schools.com/tags/ref_entities.asp)
6261
+		elseif (preg_match('/&#[0-9]{2,3};/i',$msg)) {
6262
+			return true;
6263
+		}
6264
+		// Html entities numbers (http://www.w3schools.com/tags/ref_entities.asp)
5625 6265
 		return false;
5626 6266
 	}
5627 6267
 }
@@ -5732,8 +6372,7 @@  discard block
 block discarded – undo
5732 6372
 				$substitutionarray['__SHIPPINGTRACKNUM__']='Shipping tacking number';
5733 6373
 				$substitutionarray['__SHIPPINGTRACKNUMURL__']='Shipping tracking url';
5734 6374
 			}
5735
-		}
5736
-		else
6375
+		} else
5737 6376
 		{
5738 6377
 			$substitutionarray['__ID__'] = $object->id;
5739 6378
 			$substitutionarray['__REF__'] = $object->ref;
@@ -5745,10 +6384,14 @@  discard block
 block discarded – undo
5745 6384
 
5746 6385
 			$birthday = dol_print_date($object->birth,'day');
5747 6386
 
5748
-			if (method_exists($object, 'getCivilityLabel')) $substitutionarray['__MEMBER_CIVILITY__'] = $object->getCivilityLabel();
6387
+			if (method_exists($object, 'getCivilityLabel')) {
6388
+				$substitutionarray['__MEMBER_CIVILITY__'] = $object->getCivilityLabel();
6389
+			}
5749 6390
 			$substitutionarray['__MEMBER_FIRSTNAME__']=$msgishtml?dol_htmlentitiesbr($object->firstname):$object->firstname;
5750 6391
 			$substitutionarray['__MEMBER_LASTNAME__']=$msgishtml?dol_htmlentitiesbr($object->lastname):$object->lastname;
5751
-			if (method_exists($object, 'getFullName')) $substitutionarray['__MEMBER_FULLNAME__']=$msgishtml?dol_htmlentitiesbr($object->getFullName($outputlangs)):$object->getFullName($outputlangs);
6392
+			if (method_exists($object, 'getFullName')) {
6393
+				$substitutionarray['__MEMBER_FULLNAME__']=$msgishtml?dol_htmlentitiesbr($object->getFullName($outputlangs)):$object->getFullName($outputlangs);
6394
+			}
5752 6395
 			$substitutionarray['__MEMBER_COMPANY__']=$msgishtml?dol_htmlentitiesbr($object->societe):$object->societe;
5753 6396
 			$substitutionarray['__MEMBER_ADDRESS__']=$msgishtml?dol_htmlentitiesbr($object->address):$object->address;
5754 6397
 			$substitutionarray['__MEMBER_ZIP__']=$msgishtml?dol_htmlentitiesbr($object->zip):$object->zip;
@@ -5769,8 +6412,7 @@  discard block
 block discarded – undo
5769 6412
 				$substitutionarray['__THIRDPARTY_NAME__'] = (is_object($object)?$object->name:'');
5770 6413
 				$substitutionarray['__THIRDPARTY_NAME_ALIAS__'] = (is_object($object)?$object->name_alias:'');
5771 6414
 				$substitutionarray['__THIRDPARTY_EMAIL__'] = (is_object($object)?$object->email:'');
5772
-			}
5773
-			elseif (is_object($object->thirdparty) && $object->thirdparty->id > 0)
6415
+			} elseif (is_object($object->thirdparty) && $object->thirdparty->id > 0)
5774 6416
 			{
5775 6417
 				$substitutionarray['__THIRDPARTY_ID__'] = (is_object($object->thirdparty)?$object->thirdparty->id:'');
5776 6418
 				$substitutionarray['__THIRDPARTY_NAME__'] = (is_object($object->thirdparty)?$object->thirdparty->name:'');
@@ -5797,8 +6439,12 @@  discard block
 block discarded – undo
5797 6439
 				$datenextexpiration='';
5798 6440
 				foreach($object->lines as $line)
5799 6441
 				{
5800
-					if ($line->date_ouverture_prevue > $dateplannedstart) $dateplannedstart = $line->date_ouverture_prevue;
5801
-					if ($line->statut == 4 && $line->date_fin_prevue && (! $datenextexpiration || $line->date_fin_prevue < $datenextexpiration)) $datenextexpiration = $line->date_fin_prevue;
6442
+					if ($line->date_ouverture_prevue > $dateplannedstart) {
6443
+						$dateplannedstart = $line->date_ouverture_prevue;
6444
+					}
6445
+					if ($line->statut == 4 && $line->date_fin_prevue && (! $datenextexpiration || $line->date_fin_prevue < $datenextexpiration)) {
6446
+						$datenextexpiration = $line->date_fin_prevue;
6447
+					}
5802 6448
 				}
5803 6449
 				$substitutionarray['__CONTRACT_HIGHEST_PLANNED_START_DATE__'] = dol_print_date($dateplannedstart, 'dayrfc');
5804 6450
 				$substitutionarray['__CONTRACT_HIGHEST_PLANNED_START_DATETIME__'] = dol_print_date($dateplannedstart, 'standard');
@@ -5827,8 +6473,12 @@  discard block
 block discarded – undo
5827 6473
 		$substitutionarray['__AMOUNT__']          = is_object($object)?$object->total_ttc:'';
5828 6474
 		$substitutionarray['__AMOUNT_EXCL_TAX__'] = is_object($object)?$object->total_ht:'';
5829 6475
 		$substitutionarray['__AMOUNT_VAT__']      = is_object($object)?($object->total_vat?$object->total_vat:$object->total_tva):'';
5830
- 		if ($onlykey != 2 || $mysoc->useLocalTax(1)) $substitutionarray['__AMOUNT_TAX2__']     = is_object($object)?($object->total_localtax1?$object->total_localtax1:$object->total_localtax1):'';
5831
-		if ($onlykey != 2 || $mysoc->useLocalTax(2)) $substitutionarray['__AMOUNT_TAX3__']     = is_object($object)?($object->total_localtax2?$object->total_localtax2:$object->total_localtax2):'';
6476
+ 		if ($onlykey != 2 || $mysoc->useLocalTax(1)) {
6477
+ 			$substitutionarray['__AMOUNT_TAX2__']     = is_object($object)?($object->total_localtax1?$object->total_localtax1:$object->total_localtax1):'';
6478
+ 		}
6479
+		if ($onlykey != 2 || $mysoc->useLocalTax(2)) {
6480
+			$substitutionarray['__AMOUNT_TAX3__']     = is_object($object)?($object->total_localtax2?$object->total_localtax2:$object->total_localtax2):'';
6481
+		}
5832 6482
 
5833 6483
 		/* TODO Add key for multicurrency
5834 6484
     	$substitutionarray['__AMOUNT_FORMATED__']          = is_object($object)?price($object->total_ttc, 0, $outputlangs, 0, 0, -1, $conf->currency_code):'';
@@ -5919,9 +6569,13 @@  discard block
 block discarded – undo
5919 6569
 {
5920 6570
 	global $conf, $langs;
5921 6571
 
5922
-	if (! is_array($substitutionarray)) return 'ErrorBadParameterSubstitutionArrayWhenCalling_make_substitutions';
6572
+	if (! is_array($substitutionarray)) {
6573
+		return 'ErrorBadParameterSubstitutionArrayWhenCalling_make_substitutions';
6574
+	}
5923 6575
 
5924
-	if (empty($outputlangs)) $outputlangs=$langs;
6576
+	if (empty($outputlangs)) {
6577
+		$outputlangs=$langs;
6578
+	}
5925 6579
 
5926 6580
 	// Make substitution for language keys
5927 6581
 	if (is_object($outputlangs))
@@ -5929,11 +6583,15 @@  discard block
 block discarded – undo
5929 6583
 		while (preg_match('/__\(([^\)]+)\)__/', $text, $reg))
5930 6584
 		{
5931 6585
 			$msgishtml = 0;
5932
-			if (dol_textishtml($text,1)) $msgishtml = 1;
6586
+			if (dol_textishtml($text,1)) {
6587
+				$msgishtml = 1;
6588
+			}
5933 6589
 
5934 6590
 			// If key is __(TranslationKey|langfile)__, then force load of langfile.lang
5935 6591
 			$tmp=explode('|',$reg[1]);
5936
-			if (! empty($tmp[1])) $outputlangs->load($tmp[1]);
6592
+			if (! empty($tmp[1])) {
6593
+				$outputlangs->load($tmp[1]);
6594
+			}
5937 6595
 
5938 6596
 			$text = preg_replace('/__\('.preg_quote($reg[1], '/').'\)__/', $msgishtml?dol_htmlentitiesbr($outputlangs->transnoentitiesnoconv($reg[1])):$outputlangs->transnoentitiesnoconv($reg[1]), $text);
5939 6597
 		}
@@ -5944,19 +6602,30 @@  discard block
 block discarded – undo
5944 6602
 	while (preg_match('/__\[([^\]]+)\]__/', $text, $reg))
5945 6603
 	{
5946 6604
 		$msgishtml = 0;
5947
-		if (dol_textishtml($text,1)) $msgishtml = 1;
6605
+		if (dol_textishtml($text,1)) {
6606
+			$msgishtml = 1;
6607
+		}
5948 6608
 
5949 6609
 		$keyfound = $reg[1];
5950
-		if (preg_match('/(_pass|password|secret|_key|key$)/i', $keyfound)) $newval = '*****forbidden*****';
5951
-		else $newval=empty($conf->global->$keyfound)?'':$conf->global->$keyfound;
6610
+		if (preg_match('/(_pass|password|secret|_key|key$)/i', $keyfound)) {
6611
+			$newval = '*****forbidden*****';
6612
+		} else {
6613
+			$newval=empty($conf->global->$keyfound)?'':$conf->global->$keyfound;
6614
+		}
5952 6615
 		$text = preg_replace('/__\['.preg_quote($keyfound, '/').'\]__/', $msgishtml?dol_htmlentitiesbr($newval):$newval, $text);
5953 6616
 	}
5954 6617
 
5955 6618
 	// Make substitition for array $substitutionarray
5956 6619
 	foreach ($substitutionarray as $key => $value)
5957 6620
 	{
5958
-		if ($key == '__SIGNATURE__' && (! empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN))) $value='';		// Protection
5959
-		if ($key == '__USER_SIGNATURE__' && (! empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN))) $value='';	// Protection
6621
+		if ($key == '__SIGNATURE__' && (! empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN))) {
6622
+			$value='';
6623
+		}
6624
+		// Protection
6625
+		if ($key == '__USER_SIGNATURE__' && (! empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN))) {
6626
+			$value='';
6627
+		}
6628
+		// Protection
5960 6629
 
5961 6630
 		$text=str_replace("$key","$value",$text);	// We must keep the " to work when value is 123.5 for example
5962 6631
 	}
@@ -6003,7 +6672,9 @@  discard block
 block discarded – undo
6003 6672
 		$dir=dol_buildpath($reldir,0);
6004 6673
 
6005 6674
 		// Check if directory exists
6006
-		if (! dol_is_dir($dir)) continue;
6675
+		if (! dol_is_dir($dir)) {
6676
+			continue;
6677
+		}
6007 6678
 
6008 6679
 		$substitfiles=dol_dir_list($dir,'files',0,'functions_');
6009 6680
 		foreach($substitfiles as $substitfile)
@@ -6017,7 +6688,9 @@  discard block
 block discarded – undo
6017 6688
 				require_once $dir.$substitfile['name'];
6018 6689
 				// Call the user's function, and only if it is defined
6019 6690
 				$function_name=$module."_".$callfunc;
6020
-				if (function_exists($function_name)) $function_name($substitutionarray,$outputlangs,$object,$parameters);
6691
+				if (function_exists($function_name)) {
6692
+					$function_name($substitutionarray,$outputlangs,$object,$parameters);
6693
+				}
6021 6694
 			}
6022 6695
 		}
6023 6696
 	}
@@ -6053,7 +6726,9 @@  discard block
 block discarded – undo
6053 6726
 
6054 6727
 	$out='';
6055 6728
 
6056
-	if (! is_object($outputlangs)) $outputlangs=$langs;
6729
+	if (! is_object($outputlangs)) {
6730
+		$outputlangs=$langs;
6731
+	}
6057 6732
 
6058 6733
 	if ($date_start && $date_end)
6059 6734
 	{
@@ -6085,21 +6760,25 @@  discard block
 block discarded – undo
6085 6760
 
6086 6761
 	$ret='';
6087 6762
 	// If order not defined, we use the setup
6088
-	if ($nameorder < 0) $nameorder=(empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION));
6763
+	if ($nameorder < 0) {
6764
+		$nameorder=(empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION));
6765
+	}
6089 6766
 	if ($nameorder && ((string) $nameorder != '2'))
6090 6767
 	{
6091 6768
 		$ret.=$firstname;
6092
-		if ($firstname && $lastname) $ret.=' ';
6769
+		if ($firstname && $lastname) {
6770
+			$ret.=' ';
6771
+		}
6093 6772
 		$ret.=$lastname;
6094
-	}
6095
-	else if ($nameorder == 2)
6773
+	} else if ($nameorder == 2)
6096 6774
 	{
6097 6775
 	   $ret.=$firstname;
6098
-	}
6099
-	else
6776
+	} else
6100 6777
 	{
6101 6778
 		$ret.=$lastname;
6102
-		if ($firstname && $lastname) $ret.=' ';
6779
+		if ($firstname && $lastname) {
6780
+			$ret.=' ';
6781
+		}
6103 6782
 		$ret.=$firstname;
6104 6783
 	}
6105 6784
 	return $ret;
@@ -6119,15 +6798,18 @@  discard block
 block discarded – undo
6119 6798
 function setEventMessage($mesgs, $style='mesgs')
6120 6799
 {
6121 6800
 	//dol_syslog(__FUNCTION__ . " is deprecated", LOG_WARNING);		This is not deprecated, it is used by setEventMessages function
6122
-	if (! is_array($mesgs))		// If mesgs is a string
6801
+	if (! is_array($mesgs)) {
6802
+		// If mesgs is a string
6123 6803
 	{
6124 6804
 		if ($mesgs) $_SESSION['dol_events'][$style][] = $mesgs;
6125 6805
 	}
6126
-	else						// If mesgs is an array
6806
+	} else						// If mesgs is an array
6127 6807
 	{
6128 6808
 		foreach($mesgs as $mesg)
6129 6809
 		{
6130
-			if ($mesg) $_SESSION['dol_events'][$style][] = $mesg;
6810
+			if ($mesg) {
6811
+				$_SESSION['dol_events'][$style][] = $mesg;
6812
+			}
6131 6813
 		}
6132 6814
 	}
6133 6815
 }
@@ -6144,11 +6826,17 @@  discard block
 block discarded – undo
6144 6826
  */
6145 6827
 function setEventMessages($mesg, $mesgs, $style='mesgs')
6146 6828
 {
6147
-	if (! in_array((string) $style, array('mesgs','warnings','errors'))) dol_print_error('','Bad parameter style='.$style.' for setEventMessages');
6148
-	if (empty($mesgs)) setEventMessage($mesg, $style);
6149
-	else
6829
+	if (! in_array((string) $style, array('mesgs','warnings','errors'))) {
6830
+		dol_print_error('','Bad parameter style='.$style.' for setEventMessages');
6831
+	}
6832
+	if (empty($mesgs)) {
6833
+		setEventMessage($mesg, $style);
6834
+	} else
6150 6835
 	{
6151
-		if (! empty($mesg) && ! in_array($mesg, $mesgs)) setEventMessage($mesg, $style);	// Add message string if not already into array
6836
+		if (! empty($mesg) && ! in_array($mesg, $mesgs)) {
6837
+			setEventMessage($mesg, $style);
6838
+		}
6839
+		// Add message string if not already into array
6152 6840
 		setEventMessage($mesgs, $style);
6153 6841
 	}
6154 6842
 }
@@ -6166,19 +6854,25 @@  discard block
 block discarded – undo
6166 6854
 {
6167 6855
 	// Show mesgs
6168 6856
 	if (isset($_SESSION['dol_events']['mesgs'])) {
6169
-		if (empty($disabledoutputofmessages)) dol_htmloutput_mesg('', $_SESSION['dol_events']['mesgs']);
6857
+		if (empty($disabledoutputofmessages)) {
6858
+			dol_htmloutput_mesg('', $_SESSION['dol_events']['mesgs']);
6859
+		}
6170 6860
 		unset($_SESSION['dol_events']['mesgs']);
6171 6861
 	}
6172 6862
 
6173 6863
 	// Show errors
6174 6864
 	if (isset($_SESSION['dol_events']['errors'])) {
6175
-		if (empty($disabledoutputofmessages)) dol_htmloutput_mesg('', $_SESSION['dol_events']['errors'], 'error');
6865
+		if (empty($disabledoutputofmessages)) {
6866
+			dol_htmloutput_mesg('', $_SESSION['dol_events']['errors'], 'error');
6867
+		}
6176 6868
 		unset($_SESSION['dol_events']['errors']);
6177 6869
 	}
6178 6870
 
6179 6871
 	// Show warnings
6180 6872
 	if (isset($_SESSION['dol_events']['warnings'])) {
6181
-		if (empty($disabledoutputofmessages)) dol_htmloutput_mesg('', $_SESSION['dol_events']['warnings'], 'warning');
6873
+		if (empty($disabledoutputofmessages)) {
6874
+			dol_htmloutput_mesg('', $_SESSION['dol_events']['warnings'], 'warning');
6875
+		}
6182 6876
 		unset($_SESSION['dol_events']['warnings']);
6183 6877
 	}
6184 6878
 }
@@ -6222,7 +6916,9 @@  discard block
 block discarded – undo
6222 6916
 			{
6223 6917
 				$ret++;
6224 6918
 				$out.= $langs->trans($message);
6225
-				if ($ret < count($mesgarray)) $out.= "<br>\n";
6919
+				if ($ret < count($mesgarray)) {
6920
+					$out.= "<br>\n";
6921
+				}
6226 6922
 			}
6227 6923
 		}
6228 6924
 		if ($mesgstring)
@@ -6252,8 +6948,7 @@  discard block
 block discarded – undo
6252 6948
 						}
6253 6949
 					});
6254 6950
 				</script>';
6255
-		}
6256
-		else
6951
+		} else
6257 6952
 		{
6258 6953
 			$return = $out;
6259 6954
 		}
@@ -6293,7 +6988,9 @@  discard block
 block discarded – undo
6293 6988
  */
6294 6989
 function dol_htmloutput_mesg($mesgstring='',$mesgarray='', $style='ok', $keepembedded=0)
6295 6990
 {
6296
-	if (empty($mesgstring) && (! is_array($mesgarray) || count($mesgarray) == 0)) return;
6991
+	if (empty($mesgstring) && (! is_array($mesgarray) || count($mesgarray) == 0)) {
6992
+		return;
6993
+	}
6297 6994
 
6298 6995
 	$iserror=0;
6299 6996
 	$iswarning=0;
@@ -6304,11 +7001,17 @@  discard block
 block discarded – undo
6304 7001
 			if ($val && preg_match('/class="error"/i',$val)) { $iserror++; break; }
6305 7002
 			if ($val && preg_match('/class="warning"/i',$val)) { $iswarning++; break; }
6306 7003
 		}
7004
+	} else if ($mesgstring && preg_match('/class="error"/i',$mesgstring)) {
7005
+		$iserror++;
7006
+	} else if ($mesgstring && preg_match('/class="warning"/i',$mesgstring)) {
7007
+		$iswarning++;
7008
+	}
7009
+	if ($style=='error') {
7010
+		$iserror++;
7011
+	}
7012
+	if ($style=='warning') {
7013
+		$iswarning++;
6307 7014
 	}
6308
-	else if ($mesgstring && preg_match('/class="error"/i',$mesgstring)) $iserror++;
6309
-	else if ($mesgstring && preg_match('/class="warning"/i',$mesgstring)) $iswarning++;
6310
-	if ($style=='error') $iserror++;
6311
-	if ($style=='warning') $iswarning++;
6312 7015
 
6313 7016
 	if ($iserror || $iswarning)
6314 7017
 	{
@@ -6330,9 +7033,10 @@  discard block
 block discarded – undo
6330 7033
 			$mesgarray=$newmesgarray;
6331 7034
 		}
6332 7035
 		print get_htmloutput_mesg($mesgstring,$mesgarray,($iserror?'error':'warning'),$keepembedded);
7036
+	} else {
7037
+		print get_htmloutput_mesg($mesgstring,$mesgarray,'ok',$keepembedded);
7038
+	}
6333 7039
 	}
6334
-	else print get_htmloutput_mesg($mesgstring,$mesgarray,'ok',$keepembedded);
6335
-}
6336 7040
 
6337 7041
 /**
6338 7042
  *  Print formated error messages to output (Used to show messages on html output).
@@ -6372,13 +7076,18 @@  discard block
 block discarded – undo
6372 7076
 	if (is_array($array) && $sizearray>0)
6373 7077
 	{
6374 7078
 		$temp = array();
6375
-		foreach(array_keys($array) as $key) $temp[$key]=$array[$key][$index];
7079
+		foreach(array_keys($array) as $key) {
7080
+			$temp[$key]=$array[$key][$index];
7081
+		}
6376 7082
 
6377
-		if (!$natsort) ($order=='asc') ? asort($temp) : arsort($temp);
6378
-		else
7083
+		if (!$natsort) {
7084
+			($order=='asc') ? asort($temp) : arsort($temp);
7085
+		} else
6379 7086
 		{
6380 7087
 			($case_sensitive) ? natsort($temp) : natcasesort($temp);
6381
-			if($order!='asc') $temp=array_reverse($temp,TRUE);
7088
+			if($order!='asc') {
7089
+				$temp=array_reverse($temp,TRUE);
7090
+			}
6382 7091
 		}
6383 7092
 
6384 7093
 		$sorted = array();
@@ -6406,17 +7115,39 @@  discard block
 block discarded – undo
6406 7115
 	$strLength = dol_strlen($str);
6407 7116
 	for ($i=0; $i<$strLength; $i++)
6408 7117
 	{
6409
-		if (ord($str[$i]) < 0x80) continue; // 0bbbbbbb
6410
-		elseif ((ord($str[$i]) & 0xE0) == 0xC0) $n=1; // 110bbbbb
6411
-		elseif ((ord($str[$i]) & 0xF0) == 0xE0) $n=2; // 1110bbbb
6412
-		elseif ((ord($str[$i]) & 0xF8) == 0xF0) $n=3; // 11110bbb
6413
-		elseif ((ord($str[$i]) & 0xFC) == 0xF8) $n=4; // 111110bb
6414
-		elseif ((ord($str[$i]) & 0xFE) == 0xFC) $n=5; // 1111110b
6415
-		else return false; // Does not match any model
6416
-		for ($j=0; $j<$n; $j++) { // n bytes matching 10bbbbbb follow ?
6417
-			if ((++$i == strlen($str)) || ((ord($str[$i]) & 0xC0) != 0x80))
7118
+		if (ord($str[$i]) < 0x80) {
7119
+			continue;
7120
+		}
7121
+		// 0bbbbbbb
7122
+		elseif ((ord($str[$i]) & 0xE0) == 0xC0) {
7123
+			$n=1;
7124
+		}
7125
+		// 110bbbbb
7126
+		elseif ((ord($str[$i]) & 0xF0) == 0xE0) {
7127
+			$n=2;
7128
+		}
7129
+		// 1110bbbb
7130
+		elseif ((ord($str[$i]) & 0xF8) == 0xF0) {
7131
+			$n=3;
7132
+		}
7133
+		// 11110bbb
7134
+		elseif ((ord($str[$i]) & 0xFC) == 0xF8) {
7135
+			$n=4;
7136
+		}
7137
+		// 111110bb
7138
+		elseif ((ord($str[$i]) & 0xFE) == 0xFC) {
7139
+			$n=5;
7140
+		}
7141
+		// 1111110b
7142
+		else {
6418 7143
 			return false;
6419 7144
 		}
7145
+		// Does not match any model
7146
+		for ($j=0; $j<$n; $j++) { // n bytes matching 10bbbbbb follow ?
7147
+			if ((++$i == strlen($str)) || ((ord($str[$i]) & 0xC0) != 0x80)) {
7148
+						return false;
7149
+			}
7150
+		}
6420 7151
 	}
6421 7152
 	return true;
6422 7153
 }
@@ -6434,11 +7165,21 @@  discard block
 block discarded – undo
6434 7165
 	global $conf;
6435 7166
 
6436 7167
 	$tmp=ini_get("unicode.filesystem_encoding");						// Disponible avec PHP 6.0
6437
-	if (empty($tmp) && ! empty($_SERVER["WINDIR"])) $tmp='iso-8859-1';	// By default for windows
6438
-	if (empty($tmp)) $tmp='utf-8';										// By default for other
6439
-	if (! empty($conf->global->MAIN_FILESYSTEM_ENCODING)) $tmp=$conf->global->MAIN_FILESYSTEM_ENCODING;
7168
+	if (empty($tmp) && ! empty($_SERVER["WINDIR"])) {
7169
+		$tmp='iso-8859-1';
7170
+	}
7171
+	// By default for windows
7172
+	if (empty($tmp)) {
7173
+		$tmp='utf-8';
7174
+	}
7175
+	// By default for other
7176
+	if (! empty($conf->global->MAIN_FILESYSTEM_ENCODING)) {
7177
+		$tmp=$conf->global->MAIN_FILESYSTEM_ENCODING;
7178
+	}
6440 7179
 
6441
-	if ($tmp == 'iso-8859-1') return utf8_decode($str);
7180
+	if ($tmp == 'iso-8859-1') {
7181
+		return utf8_decode($str);
7182
+	}
6442 7183
 	return $str;
6443 7184
 }
6444 7185
 
@@ -6461,31 +7202,39 @@  discard block
 block discarded – undo
6461 7202
 	global $cache_codes;
6462 7203
 
6463 7204
 	// If key empty
6464
-	if ($key == '') return '';
7205
+	if ($key == '') {
7206
+		return '';
7207
+	}
6465 7208
 
6466 7209
 	// Check in cache
6467
-	if (isset($cache_codes[$tablename][$key]))	// Can be defined to 0 or ''
7210
+	if (isset($cache_codes[$tablename][$key])) {
7211
+		// Can be defined to 0 or ''
6468 7212
 	{
6469
-		return $cache_codes[$tablename][$key];   // Found in cache
7213
+		return $cache_codes[$tablename][$key];
7214
+	}
7215
+	// Found in cache
6470 7216
 	}
6471 7217
 
6472 7218
 	$sql = "SELECT ".$fieldid." as valuetoget";
6473 7219
 	$sql.= " FROM ".MAIN_DB_PREFIX.$tablename;
6474 7220
 	$sql.= " WHERE ".$fieldkey." = '".$db->escape($key)."'";
6475
-	if (! empty($entityfilter))
6476
-		$sql.= " AND entity IN (" . getEntity($tablename) . ")";
7221
+	if (! empty($entityfilter)) {
7222
+			$sql.= " AND entity IN (" . getEntity($tablename) . ")";
7223
+	}
6477 7224
 
6478 7225
 	dol_syslog('dol_getIdFromCode', LOG_DEBUG);
6479 7226
 	$resql = $db->query($sql);
6480 7227
 	if ($resql)
6481 7228
 	{
6482 7229
 		$obj = $db->fetch_object($resql);
6483
-		if ($obj) $cache_codes[$tablename][$key]=$obj->valuetoget;
6484
-		else $cache_codes[$tablename][$key]='';
7230
+		if ($obj) {
7231
+			$cache_codes[$tablename][$key]=$obj->valuetoget;
7232
+		} else {
7233
+			$cache_codes[$tablename][$key]='';
7234
+		}
6485 7235
 		$db->free($resql);
6486 7236
 		return $cache_codes[$tablename][$key];
6487
-	}
6488
-	else
7237
+	} else
6489 7238
 	{
6490 7239
 		return -1;
6491 7240
 	}
@@ -6542,13 +7291,18 @@  discard block
 block discarded – undo
6542 7291
 	//print $s."<br>\n";
6543 7292
 	if ($returnvalue)
6544 7293
 	{
6545
-		if ($hideerrors) return @eval('return '.$s.';');
6546
-		else return eval('return '.$s.';');
6547
-	}
6548
-	else
7294
+		if ($hideerrors) {
7295
+			return @eval('return '.$s.';');
7296
+		} else {
7297
+			return eval('return '.$s.';');
7298
+		}
7299
+	} else
6549 7300
 	{
6550
-		if ($hideerrors) @eval($s);
6551
-		else eval($s);
7301
+		if ($hideerrors) {
7302
+			@eval($s);
7303
+		} else {
7304
+			eval($s);
7305
+		}
6552 7306
 	}
6553 7307
 }
6554 7308
 
@@ -6574,9 +7328,13 @@  discard block
 block discarded – undo
6574 7328
 {
6575 7329
 	global $langs;
6576 7330
 
6577
-	if (empty($codelang)) return '';
7331
+	if (empty($codelang)) {
7332
+		return '';
7333
+	}
6578 7334
 
6579
-	if (empty($codelang)) return '';
7335
+	if (empty($codelang)) {
7336
+		return '';
7337
+	}
6580 7338
 
6581 7339
 	if ($codelang == 'auto')
6582 7340
 	{
@@ -6591,8 +7349,9 @@  discard block
 block discarded – undo
6591 7349
 		'sv_SV' => 'se'
6592 7350
 	);
6593 7351
 
6594
-	if (isset($langtocountryflag[$codelang])) $flagImage = $langtocountryflag[$codelang];
6595
-	else
7352
+	if (isset($langtocountryflag[$codelang])) {
7353
+		$flagImage = $langtocountryflag[$codelang];
7354
+	} else
6596 7355
 	{
6597 7356
 		$tmparray = explode('_', $codelang);
6598 7357
 		$flagImage = empty($tmparray[1]) ? $tmparray[0] : $tmparray[1];
@@ -6642,50 +7401,62 @@  discard block
 block discarded – undo
6642 7401
 
6643 7402
 			if ($mode == 'add' && ! preg_match('/^\-/',$values[1]))
6644 7403
 			{
6645
-				if (count($values) == 6)       // new declaration with permissions:  $value='objecttype:+tabname1:Title1:langfile@mymodule:$user->rights->mymodule->read:/mymodule/mynewtab1.php?id=__ID__'
7404
+				if (count($values) == 6) {
7405
+					// new declaration with permissions:  $value='objecttype:+tabname1:Title1:langfile@mymodule:$user->rights->mymodule->read:/mymodule/mynewtab1.php?id=__ID__'
6646 7406
 				{
6647 7407
 					if ($values[0] != $type) continue;
7408
+				}
6648 7409
 
6649 7410
 					if (verifCond($values[4]))
6650 7411
 					{
6651
-						if ($values[3]) $langs->load($values[3]);
7412
+						if ($values[3]) {
7413
+							$langs->load($values[3]);
7414
+						}
6652 7415
 						if (preg_match('/SUBSTITUTION_([^_]+)/i',$values[2],$reg))
6653 7416
 						{
6654 7417
 							$substitutionarray=array();
6655 7418
 							complete_substitutions_array($substitutionarray,$langs,$object,array('needforkey'=>$values[2]));
6656 7419
 							$label=make_substitutions($reg[1], $substitutionarray);
7420
+						} else {
7421
+							$label=$langs->trans($values[2]);
6657 7422
 						}
6658
-						else $label=$langs->trans($values[2]);
6659 7423
 
6660 7424
 						$head[$h][0] = dol_buildpath(preg_replace('/__ID__/i', ((is_object($object) && ! empty($object->id))?$object->id:''), $values[5]), 1);
6661 7425
 						$head[$h][1] = $label;
6662 7426
 						$head[$h][2] = str_replace('+','',$values[1]);
6663 7427
 						$h++;
6664 7428
 					}
6665
-				}
6666
-				else if (count($values) == 5)       // deprecated
7429
+				} else if (count($values) == 5) {
7430
+					// deprecated
6667 7431
 				{
6668 7432
 					dol_syslog('Passing 5 values in tabs module_parts is deprecated. Please update to 6 with permissions.', LOG_WARNING);
7433
+				}
6669 7434
 
6670
-					if ($values[0] != $type) continue;
6671
-					if ($values[3]) $langs->load($values[3]);
7435
+					if ($values[0] != $type) {
7436
+						continue;
7437
+					}
7438
+					if ($values[3]) {
7439
+						$langs->load($values[3]);
7440
+					}
6672 7441
 					if (preg_match('/SUBSTITUTION_([^_]+)/i',$values[2],$reg))
6673 7442
 					{
6674 7443
 						$substitutionarray=array();
6675 7444
 						complete_substitutions_array($substitutionarray,$langs,$object,array('needforkey'=>$values[2]));
6676 7445
 						$label=make_substitutions($reg[1], $substitutionarray);
7446
+					} else {
7447
+						$label=$langs->trans($values[2]);
6677 7448
 					}
6678
-					else $label=$langs->trans($values[2]);
6679 7449
 
6680 7450
 					$head[$h][0] = dol_buildpath(preg_replace('/__ID__/i', ((is_object($object) && ! empty($object->id))?$object->id:''), $values[4]), 1);
6681 7451
 					$head[$h][1] = $label;
6682 7452
 					$head[$h][2] = str_replace('+','',$values[1]);
6683 7453
 					$h++;
6684 7454
 				}
6685
-			}
6686
-			else if ($mode == 'remove' && preg_match('/^\-/',$values[1]))
7455
+			} else if ($mode == 'remove' && preg_match('/^\-/',$values[1]))
6687 7456
 			{
6688
-				if ($values[0] != $type) continue;
7457
+				if ($values[0] != $type) {
7458
+					continue;
7459
+				}
6689 7460
 				$tabname=str_replace('-','',$values[1]);
6690 7461
 				foreach($head as $key => $val)
6691 7462
 				{
@@ -6728,14 +7499,19 @@  discard block
 block discarded – undo
6728 7499
 	global $conf, $hookmanager;
6729 7500
 	global $micro_start_time;
6730 7501
 
6731
-	if ($zone == 'private') print "\n".'<!-- Common footer for private page -->'."\n";
6732
-	else print "\n".'<!-- Common footer for public page -->'."\n";
7502
+	if ($zone == 'private') {
7503
+		print "\n".'<!-- Common footer for private page -->'."\n";
7504
+	} else {
7505
+		print "\n".'<!-- Common footer for public page -->'."\n";
7506
+	}
6733 7507
 
6734 7508
 	$parameters=array();
6735 7509
 	$reshook=$hookmanager->executeHooks('printCommonFooter',$parameters);    // Note that $action and $object may have been modified by some hooks
6736 7510
 	if (empty($reshook))
6737 7511
 	{
6738
-		if (! empty($conf->global->MAIN_HTML_FOOTER)) print $conf->global->MAIN_HTML_FOOTER."\n";
7512
+		if (! empty($conf->global->MAIN_HTML_FOOTER)) {
7513
+			print $conf->global->MAIN_HTML_FOOTER."\n";
7514
+		}
6739 7515
 
6740 7516
 		print "\n";
6741 7517
 		if (! empty($conf->use_javascript_ajax))
@@ -6779,11 +7555,15 @@  discard block
 block discarded – undo
6779 7555
 				print "\n";
6780 7556
 				print "/* JS CODE TO ENABLE to add memory info */\n";
6781 7557
 				print 'window.console && console.log("';
6782
-				if (! empty($conf->global->MEMCACHED_SERVER)) print 'MEMCACHED_SERVER='.$conf->global->MEMCACHED_SERVER.' - ';
7558
+				if (! empty($conf->global->MEMCACHED_SERVER)) {
7559
+					print 'MEMCACHED_SERVER='.$conf->global->MEMCACHED_SERVER.' - ';
7560
+				}
6783 7561
 				print 'MAIN_OPTIMIZE_SPEED='.(isset($conf->global->MAIN_OPTIMIZE_SPEED)?$conf->global->MAIN_OPTIMIZE_SPEED:'off');
6784
-				if (! empty($micro_start_time))   // Works only if MAIN_SHOW_TUNING_INFO is defined at $_SERVER level. Not in global variable.
7562
+				if (! empty($micro_start_time)) {
7563
+					// Works only if MAIN_SHOW_TUNING_INFO is defined at $_SERVER level. Not in global variable.
6785 7564
 				{
6786 7565
 					$micro_end_time = microtime(true);
7566
+				}
6787 7567
 					print ' - Build time: '.ceil(1000*($micro_end_time-$micro_start_time)).' ms';
6788 7568
 				}
6789 7569
 				if (function_exists("memory_get_usage"))
@@ -6921,7 +7701,9 @@  discard block
 block discarded – undo
6921 7701
 
6922 7702
 	$crits = explode(' ', $value);
6923 7703
 	$res = '';
6924
-	if (! is_array($fields)) $fields = array($fields);
7704
+	if (! is_array($fields)) {
7705
+		$fields = array($fields);
7706
+	}
6925 7707
 
6926 7708
 	$nboffields = count($fields);
6927 7709
 	$end2 = count($crits);
@@ -6948,20 +7730,17 @@  discard block
 block discarded – undo
6948 7730
 					if (is_numeric($numnewcrit))
6949 7731
 					{
6950 7732
 						$newres .= ($i2 > 0 ? ' OR ' : '') . $field . ' '.$operator.' '.$numnewcrit;
6951
-					}
6952
-					else
7733
+					} else
6953 7734
 					{
6954 7735
 						$newres .= ($i2 > 0 ? ' OR ' : '') . '1 = 2';	// force false
6955 7736
 					}
6956 7737
 					$i2++;	// a criteria was added to string
6957 7738
 				}
6958
-			}
6959
-			else if ($mode == 2)
7739
+			} else if ($mode == 2)
6960 7740
 			{
6961 7741
 				$newres .= ($i2 > 0 ? ' OR ' : '') . $field . " IN (" . $db->escape(trim($crit)) . ")";
6962 7742
 				$i2++;	// a criteria was added to string
6963
-			}
6964
-			else if ($mode == 3)
7743
+			} else if ($mode == 3)
6965 7744
 			{
6966 7745
 				$tmparray=explode(',',trim($crit));
6967 7746
 				if (count($tmparray))
@@ -6978,8 +7757,7 @@  discard block
 block discarded – undo
6978 7757
 					$newres .= ($i2 > 0 ? ' OR ' : '') . $field . " IN (" . $listofcodes . ")";
6979 7758
 					$i2++;	// a criteria was added to string
6980 7759
 				}
6981
-			}
6982
-			else    // $mode=0
7760
+			} else    // $mode=0
6983 7761
 			{
6984 7762
 				$textcrit = '';
6985 7763
 				$tmpcrits = explode('|',$crit);
@@ -6988,11 +7766,12 @@  discard block
 block discarded – undo
6988 7766
 				{
6989 7767
 					$newres .= (($i2 > 0 || $i3 > 0) ? ' OR ' : '');
6990 7768
 
6991
-					if (preg_match('/\.(id|rowid)$/', $field))	// Special case for rowid that is sometimes a ref so used as a search field
7769
+					if (preg_match('/\.(id|rowid)$/', $field)) {
7770
+						// Special case for rowid that is sometimes a ref so used as a search field
6992 7771
 					{
6993 7772
 						$newres .= $field . " = " . (is_numeric(trim($tmpcrit))?trim($tmpcrit):'0');
6994 7773
 					}
6995
-					else
7774
+					} else
6996 7775
 					{
6997 7776
 						$newres .= $field . " LIKE '";
6998 7777
 
@@ -7025,7 +7804,9 @@  discard block
 block discarded – undo
7025 7804
 			}
7026 7805
 			$i++;
7027 7806
 		}
7028
-		if ($newres) $res = $res . ($res ? ' AND ' : '') . ($i2 > 1 ? '(' : '') .$newres . ($i2 > 1 ? ')' : '');
7807
+		if ($newres) {
7808
+			$res = $res . ($res ? ' AND ' : '') . ($i2 > 1 ? '(' : '') .$newres . ($i2 > 1 ? ')' : '');
7809
+		}
7029 7810
 		$j++;
7030 7811
 	}
7031 7812
 	$res = ($nofirstand?"":" AND ")."(" . $res . ")";
@@ -7066,21 +7847,37 @@  discard block
 block discarded – undo
7066 7847
 function getImageFileNameForSize($file, $extName, $extImgTarget='')
7067 7848
 {
7068 7849
 	$dirName = dirname($file);
7069
-	if ($dirName == '.') $dirName='';
7850
+	if ($dirName == '.') {
7851
+		$dirName='';
7852
+	}
7070 7853
 
7071 7854
 	$fileName = preg_replace('/(\.gif|\.jpeg|\.jpg|\.png|\.bmp)$/i','',$file);	// We remove extension, whatever is its case
7072 7855
 	$fileName = basename($fileName);
7073 7856
 
7074
-	if (empty($extImgTarget)) $extImgTarget = (preg_match('/\.jpg$/i',$file)?'.jpg':'');
7075
-	if (empty($extImgTarget)) $extImgTarget = (preg_match('/\.jpeg$/i',$file)?'.jpeg':'');
7076
-	if (empty($extImgTarget)) $extImgTarget = (preg_match('/\.gif$/i',$file)?'.gif':'');
7077
-	if (empty($extImgTarget)) $extImgTarget = (preg_match('/\.png$/i',$file)?'.png':'');
7078
-	if (empty($extImgTarget)) $extImgTarget = (preg_match('/\.bmp$/i',$file)?'.bmp':'');
7857
+	if (empty($extImgTarget)) {
7858
+		$extImgTarget = (preg_match('/\.jpg$/i',$file)?'.jpg':'');
7859
+	}
7860
+	if (empty($extImgTarget)) {
7861
+		$extImgTarget = (preg_match('/\.jpeg$/i',$file)?'.jpeg':'');
7862
+	}
7863
+	if (empty($extImgTarget)) {
7864
+		$extImgTarget = (preg_match('/\.gif$/i',$file)?'.gif':'');
7865
+	}
7866
+	if (empty($extImgTarget)) {
7867
+		$extImgTarget = (preg_match('/\.png$/i',$file)?'.png':'');
7868
+	}
7869
+	if (empty($extImgTarget)) {
7870
+		$extImgTarget = (preg_match('/\.bmp$/i',$file)?'.bmp':'');
7871
+	}
7079 7872
 
7080
-	if (! $extImgTarget) return $file;
7873
+	if (! $extImgTarget) {
7874
+		return $file;
7875
+	}
7081 7876
 
7082 7877
 	$subdir='';
7083
-	if ($extName) $subdir = 'thumbs/';
7878
+	if ($extName) {
7879
+		$subdir = 'thumbs/';
7880
+	}
7084 7881
 
7085 7882
 	return ($dirName?$dirName.'/':'').$subdir.$fileName.$extName.$extImgTarget; // New filename for thumb
7086 7883
 }
@@ -7099,7 +7896,9 @@  discard block
 block discarded – undo
7099 7896
 {
7100 7897
 	global $conf, $langs;
7101 7898
 
7102
-	if (empty($conf->use_javascript_ajax)) return '';
7899
+	if (empty($conf->use_javascript_ajax)) {
7900
+		return '';
7901
+	}
7103 7902
 
7104 7903
 	$mime_preview = array('bmp', 'jpeg', 'png', 'gif', 'tiff', 'pdf', 'plain', 'css', 'svg+xml');
7105 7904
 	//$mime_preview[]='vnd.oasis.opendocument.presentation';
@@ -7108,14 +7907,20 @@  discard block
 block discarded – undo
7108 7907
 
7109 7908
 	if ($alldata == 1)
7110 7909
 	{
7111
-		if ($num_mime !== false) return array('target'=>'_blank', 'css'=>'documentpreview', 'url'=>DOL_URL_ROOT.'/document.php?modulepart='.$modulepart.'&attachment=0&file='.urlencode($relativepath), 'mime'=>dol_mimetype($relativepath), );
7112
-		else return array();
7910
+		if ($num_mime !== false) {
7911
+			return array('target'=>'_blank', 'css'=>'documentpreview', 'url'=>DOL_URL_ROOT.'/document.php?modulepart='.$modulepart.'&attachment=0&file='.urlencode($relativepath), 'mime'=>dol_mimetype($relativepath), );
7912
+		} else {
7913
+			return array();
7914
+		}
7113 7915
 	}
7114 7916
 
7115 7917
 	// old behavior
7116
-	if ($num_mime !== false) return 'javascript:document_preview(\''.dol_escape_js(DOL_URL_ROOT.'/document.php?modulepart='.$modulepart.'&attachment=0&file='.urlencode($relativepath).($param?'&'.$param:'')).'\', \''.dol_mimetype($relativepath).'\', \''.dol_escape_js($langs->trans('Preview')).'\')';
7117
-	else return '';
7118
-}
7918
+	if ($num_mime !== false) {
7919
+		return 'javascript:document_preview(\''.dol_escape_js(DOL_URL_ROOT.'/document.php?modulepart='.$modulepart.'&attachment=0&file='.urlencode($relativepath).($param?'&'.$param:'')).'\', \''.dol_mimetype($relativepath).'\', \''.dol_escape_js($langs->trans('Preview')).'\')';
7920
+	} else {
7921
+		return '';
7922
+	}
7923
+	}
7119 7924
 
7120 7925
 
7121 7926
 /**
@@ -7132,7 +7937,9 @@  discard block
 block discarded – undo
7132 7937
 				    jQuery("#'.$htmlname.'").click(function() { jQuery(this).select(); } );
7133 7938
 				});
7134 7939
 		    </script>';
7135
-	if ($addlink) $out.=' <a href="'.$addlink.'" target="_blank">'.$langs->trans("Link").'</a>';
7940
+	if ($addlink) {
7941
+		$out.=' <a href="'.$addlink.'" target="_blank">'.$langs->trans("Link").'</a>';
7942
+	}
7136 7943
 	return $out;
7137 7944
 }
7138 7945
 
@@ -7269,7 +8076,9 @@  discard block
 block discarded – undo
7269 8076
 	{
7270 8077
 		$dictvalues[$tablename] = array();
7271 8078
 		$sql = 'SELECT * FROM '.$tablename.' WHERE 1';
7272
-		if ($checkentity) $sql.= ' entity IN (0,'.getEntity('').')';
8079
+		if ($checkentity) {
8080
+			$sql.= ' entity IN (0,'.getEntity('').')';
8081
+		}
7273 8082
 
7274 8083
 		$resql = $db->query($sql);
7275 8084
 		if ($resql)
@@ -7278,17 +8087,21 @@  discard block
 block discarded – undo
7278 8087
 			{
7279 8088
 				$dictvalues[$tablename][$obj->{$rowidfield}] = $obj;
7280 8089
 			}
7281
-		}
7282
-		else
8090
+		} else
7283 8091
 		{
7284 8092
 			dol_print_error($db);
7285 8093
 		}
7286 8094
 	}
7287 8095
 
7288
-	if (!empty($dictvalues[$tablename][$id])) return $dictvalues[$tablename][$id]->{$field}; // Found
8096
+	if (!empty($dictvalues[$tablename][$id])) {
8097
+		return $dictvalues[$tablename][$id]->{$field};
8098
+	}
8099
+	// Found
7289 8100
 	else // Not found
7290 8101
 	{
7291
-		if ($id > 0) return $id;
8102
+		if ($id > 0) {
8103
+			return $id;
8104
+		}
7292 8105
 		return '';
7293 8106
 	}
7294 8107
 }
@@ -7306,13 +8119,14 @@  discard block
 block discarded – undo
7306 8119
 	{
7307 8120
 		$res = 0;
7308 8121
 		$tmp=explode(',', $stringcolor);
7309
-		if (count($tmp) > 1)   // This is a comma RGB ('255','255','255')
8122
+		if (count($tmp) > 1) {
8123
+			// This is a comma RGB ('255','255','255')
7310 8124
 		{
7311 8125
 			$r = $tmp[0];
8126
+		}
7312 8127
 			$g = $tmp[1];
7313 8128
 			$b = $tmp[2];
7314
-		}
7315
-		else
8129
+		} else
7316 8130
 		{
7317 8131
 			$hexr=$stringcolor[0].$stringcolor[1];
7318 8132
 			$hexg=$stringcolor[2].$stringcolor[3];
@@ -7322,7 +8136,9 @@  discard block
 block discarded – undo
7322 8136
 			$b = hexdec($hexb);
7323 8137
 		}
7324 8138
 		$bright = (max($r, $g, $b) + min($r, $g, $b)) / 510.0;    // HSL algorithm
7325
-		if ($bright > 0.6) $res = 1;
8139
+		if ($bright > 0.6) {
8140
+			$res = 1;
8141
+		}
7326 8142
 	}
7327 8143
 	return $res;
7328 8144
 }
@@ -7341,7 +8157,10 @@  discard block
 block discarded – undo
7341 8157
 
7342 8158
 	//print 'type_user='.$type_user.' module='.$menuentry['module'].' enabled='.$menuentry['enabled'].' perms='.$menuentry['perms'];
7343 8159
 	//print 'ok='.in_array($menuentry['module'], $listofmodulesforexternal);
7344
-	if (empty($menuentry['enabled'])) return 0;	// Entry disabled by condition
8160
+	if (empty($menuentry['enabled'])) {
8161
+		return 0;
8162
+	}
8163
+	// Entry disabled by condition
7345 8164
 	if ($type_user && $menuentry['module'])
7346 8165
 	{
7347 8166
 		$tmploops=explode('|',$menuentry['module']);
@@ -7352,10 +8171,22 @@  discard block
 block discarded – undo
7352 8171
 				$found++; break;
7353 8172
 			}
7354 8173
 		}
7355
-		if (! $found) return 0;	// Entry is for menus all excluded to external users
8174
+		if (! $found) {
8175
+			return 0;
8176
+		}
8177
+		// Entry is for menus all excluded to external users
8178
+	}
8179
+	if (! $menuentry['perms'] && $type_user) {
8180
+		return 0;
8181
+	}
8182
+	// No permissions and user is external
8183
+	if (! $menuentry['perms'] && ! empty($conf->global->MAIN_MENU_HIDE_UNAUTHORIZED)) {
8184
+		return 0;
8185
+	}
8186
+	// No permissions and option to hide when not allowed, even for internal user, is on
8187
+	if (! $menuentry['perms']) {
8188
+		return 2;
7356 8189
 	}
7357
-	if (! $menuentry['perms'] && $type_user) return 0; 											// No permissions and user is external
7358
-	if (! $menuentry['perms'] && ! empty($conf->global->MAIN_MENU_HIDE_UNAUTHORIZED))	return 0;	// No permissions and option to hide when not allowed, even for internal user, is on
7359
-	if (! $menuentry['perms']) return 2;															// No permissions and user is external
8190
+	// No permissions and user is external
7360 8191
 	return 1;
7361 8192
 }
Please login to merge, or discard this patch.
htdocs/core/lib/files.lib.php 2 patches
Spacing   +581 added lines, -581 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
  */
35 35
 function dol_basename($pathfile)
36 36
 {
37
-	return preg_replace('/^.*\/([^\/]+)$/','$1',rtrim($pathfile,'/'));
37
+	return preg_replace('/^.*\/([^\/]+)$/', '$1', rtrim($pathfile, '/'));
38 38
 }
39 39
 
40 40
 /**
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
  *  @return	array						Array of array('name'=>'xxx','fullname'=>'/abc/xxx','date'=>'yyy','size'=>99,'type'=>'dir|file',...)
56 56
  *  @see dol_dir_list_indatabase
57 57
  */
58
-function dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="")
58
+function dol_dir_list($path, $types = "all", $recursive = 0, $filter = "", $excludefilter = null, $sortcriteria = "name", $sortorder = SORT_ASC, $mode = 0, $nohook = 0, $relativename = "")
59 59
 {
60 60
 	global $db, $hookmanager;
61 61
 	global $object;
@@ -63,23 +63,23 @@  discard block
 block discarded – undo
63 63
 	dol_syslog("files.lib.php::dol_dir_list path=".$path." types=".$types." recursive=".$recursive." filter=".$filter." excludefilter=".json_encode($excludefilter));
64 64
 	//print 'xxx'."files.lib.php::dol_dir_list path=".$path." types=".$types." recursive=".$recursive." filter=".$filter." excludefilter=".json_encode($excludefilter);
65 65
 
66
-	$loaddate=($mode==1||$mode==2)?true:false;
67
-	$loadsize=($mode==1||$mode==3)?true:false;
66
+	$loaddate = ($mode == 1 || $mode == 2) ?true:false;
67
+	$loadsize = ($mode == 1 || $mode == 3) ?true:false;
68 68
 
69 69
 	// Clean parameters
70
-	$path=preg_replace('/([\\/]+)$/i','',$path);
71
-	$newpath=dol_osencode($path);
70
+	$path = preg_replace('/([\\/]+)$/i', '', $path);
71
+	$newpath = dol_osencode($path);
72 72
 
73 73
 	$reshook = 0;
74 74
 	$file_list = array();
75 75
 
76
-	if (is_object($hookmanager) && ! $nohook)
76
+	if (is_object($hookmanager) && !$nohook)
77 77
 	{
78
-		$hookmanager->resArray=array();
78
+		$hookmanager->resArray = array();
79 79
 
80 80
 		$hookmanager->initHooks(array('fileslib'));
81 81
 
82
-		$parameters=array(
82
+		$parameters = array(
83 83
 				'path' => $newpath,
84 84
 				'types'=> $types,
85 85
 				'recursive' => $recursive,
@@ -91,63 +91,63 @@  discard block
 block discarded – undo
91 91
 				'loadsize' => $loadsize,
92 92
 				'mode' => $mode
93 93
 		);
94
-		$reshook=$hookmanager->executeHooks('getDirList', $parameters, $object);
94
+		$reshook = $hookmanager->executeHooks('getDirList', $parameters, $object);
95 95
 	}
96 96
 
97 97
 	// $hookmanager->resArray may contain array stacked by other modules
98 98
 	if (empty($reshook))
99 99
 	{
100
-		if (! is_dir($newpath)) return array();
100
+		if (!is_dir($newpath)) return array();
101 101
 
102 102
 		if ($dir = opendir($newpath))
103 103
 		{
104
-			$filedate='';
105
-			$filesize='';
104
+			$filedate = '';
105
+			$filesize = '';
106 106
 
107 107
 			while (false !== ($file = readdir($dir)))        // $file is always a basename (into directory $newpath)
108 108
 			{
109
-				if (! utf8_check($file)) $file=utf8_encode($file);	// To be sure data is stored in utf8 in memory
110
-				$fullpathfile=($newpath?$newpath.'/':'').$file;
109
+				if (!utf8_check($file)) $file = utf8_encode($file); // To be sure data is stored in utf8 in memory
110
+				$fullpathfile = ($newpath ? $newpath.'/' : '').$file;
111 111
 
112
-				$qualified=1;
112
+				$qualified = 1;
113 113
 
114 114
 				// Define excludefilterarray
115
-				$excludefilterarray=array('^\.');
115
+				$excludefilterarray = array('^\.');
116 116
 				if (is_array($excludefilter))
117 117
 				{
118
-					$excludefilterarray=array_merge($excludefilterarray,$excludefilter);
118
+					$excludefilterarray = array_merge($excludefilterarray, $excludefilter);
119 119
 				}
120
-				else if ($excludefilter) $excludefilterarray[]=$excludefilter;
120
+				else if ($excludefilter) $excludefilterarray[] = $excludefilter;
121 121
 				// Check if file is qualified
122
-				foreach($excludefilterarray as $filt)
122
+				foreach ($excludefilterarray as $filt)
123 123
 				{
124 124
 					if (preg_match('/'.$filt.'/i', $file) || preg_match('/'.$filt.'/i', $fullpathfile)) {
125
-						$qualified=0; break;
125
+						$qualified = 0; break;
126 126
 					}
127 127
 				}
128 128
 				//print $fullpathfile.' '.$file.' '.$qualified.'<br>';
129 129
 
130 130
 				if ($qualified)
131 131
 				{
132
-					$isdir=is_dir(dol_osencode($path."/".$file));
132
+					$isdir = is_dir(dol_osencode($path."/".$file));
133 133
 					// Check whether this is a file or directory and whether we're interested in that type
134
-					if ($isdir && (($types=="directories") || ($types=="all") || $recursive))
134
+					if ($isdir && (($types == "directories") || ($types == "all") || $recursive))
135 135
 					{
136 136
 						// Add entry into file_list array
137
-						if (($types=="directories") || ($types=="all"))
137
+						if (($types == "directories") || ($types == "all"))
138 138
 						{
139
-							if ($loaddate || $sortcriteria == 'date') $filedate=dol_filemtime($path."/".$file);
140
-							if ($loadsize || $sortcriteria == 'size') $filesize=dol_filesize($path."/".$file);
139
+							if ($loaddate || $sortcriteria == 'date') $filedate = dol_filemtime($path."/".$file);
140
+							if ($loadsize || $sortcriteria == 'size') $filesize = dol_filesize($path."/".$file);
141 141
 
142
-							if (! $filter || preg_match('/'.$filter.'/i',$file))	// We do not search key $filter into all $path, only into $file part
142
+							if (!$filter || preg_match('/'.$filter.'/i', $file))	// We do not search key $filter into all $path, only into $file part
143 143
 							{
144
-								preg_match('/([^\/]+)\/[^\/]+$/',$path.'/'.$file,$reg);
145
-								$level1name=(isset($reg[1])?$reg[1]:'');
144
+								preg_match('/([^\/]+)\/[^\/]+$/', $path.'/'.$file, $reg);
145
+								$level1name = (isset($reg[1]) ? $reg[1] : '');
146 146
 								$file_list[] = array(
147 147
 										"name" => $file,
148 148
 										"path" => $path,
149 149
 										"level1name" => $level1name,
150
-										"relativename" => ($relativename?$relativename.'/':'').$file,
150
+										"relativename" => ($relativename ? $relativename.'/' : '').$file,
151 151
 										"fullname" => $path.'/'.$file,
152 152
 										"date" => $filedate,
153 153
 										"size" => $filesize,
@@ -159,24 +159,24 @@  discard block
 block discarded – undo
159 159
 						// if we're in a directory and we want recursive behavior, call this function again
160 160
 						if ($recursive)
161 161
 						{
162
-							$file_list = array_merge($file_list, dol_dir_list($path."/".$file, $types, $recursive, $filter, $excludefilter, $sortcriteria, $sortorder, $mode, $nohook, ($relativename!=''?$relativename.'/':'').$file));
162
+							$file_list = array_merge($file_list, dol_dir_list($path."/".$file, $types, $recursive, $filter, $excludefilter, $sortcriteria, $sortorder, $mode, $nohook, ($relativename != '' ? $relativename.'/' : '').$file));
163 163
 						}
164 164
 					}
165
-					else if (! $isdir && (($types == "files") || ($types == "all")))
165
+					else if (!$isdir && (($types == "files") || ($types == "all")))
166 166
 					{
167 167
 						// Add file into file_list array
168
-						if ($loaddate || $sortcriteria == 'date') $filedate=dol_filemtime($path."/".$file);
169
-						if ($loadsize || $sortcriteria == 'size') $filesize=dol_filesize($path."/".$file);
168
+						if ($loaddate || $sortcriteria == 'date') $filedate = dol_filemtime($path."/".$file);
169
+						if ($loadsize || $sortcriteria == 'size') $filesize = dol_filesize($path."/".$file);
170 170
 
171
-						if (! $filter || preg_match('/'.$filter.'/i',$file))	// We do not search key $filter into $path, only into $file
171
+						if (!$filter || preg_match('/'.$filter.'/i', $file))	// We do not search key $filter into $path, only into $file
172 172
 						{
173
-							preg_match('/([^\/]+)\/[^\/]+$/',$path.'/'.$file,$reg);
174
-							$level1name=(isset($reg[1])?$reg[1]:'');
173
+							preg_match('/([^\/]+)\/[^\/]+$/', $path.'/'.$file, $reg);
174
+							$level1name = (isset($reg[1]) ? $reg[1] : '');
175 175
 							$file_list[] = array(
176 176
 									"name" => $file,
177 177
 									"path" => $path,
178 178
 									"level1name" => $level1name,
179
-									"relativename" => ($relativename?$relativename.'/':'').$file,
179
+									"relativename" => ($relativename ? $relativename.'/' : '').$file,
180 180
 									"fullname" => $path.'/'.$file,
181 181
 									"date" => $filedate,
182 182
 									"size" => $filesize,
@@ -189,12 +189,12 @@  discard block
 block discarded – undo
189 189
 			closedir($dir);
190 190
 
191 191
 			// Obtain a list of columns
192
-			if (! empty($sortcriteria))
192
+			if (!empty($sortcriteria))
193 193
 			{
194
-				$myarray=array();
194
+				$myarray = array();
195 195
 				foreach ($file_list as $key => $row)
196 196
 				{
197
-					$myarray[$key] = (isset($row[$sortcriteria])?$row[$sortcriteria]:'');
197
+					$myarray[$key] = (isset($row[$sortcriteria]) ? $row[$sortcriteria] : '');
198 198
 				}
199 199
 				// Sort the data
200 200
 				if ($sortorder) array_multisort($myarray, $sortorder, $file_list);
@@ -221,21 +221,21 @@  discard block
 block discarded – undo
221 221
  *  @return	array						Array of array('name'=>'xxx','fullname'=>'/abc/xxx','type'=>'dir|file',...)
222 222
  *  @see dol_dir_list
223 223
  */
224
-function dol_dir_list_in_database($path, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0)
224
+function dol_dir_list_in_database($path, $filter = "", $excludefilter = null, $sortcriteria = "name", $sortorder = SORT_ASC, $mode = 0)
225 225
 {
226 226
 	global $conf, $db;
227 227
 
228
-	$sql =" SELECT rowid, label, entity, filename, filepath, fullpath_orig, keywords, cover, gen_or_uploaded, extraparams, date_c, date_m, fk_user_c, fk_user_m,";
229
-	$sql.=" acl, position, share";
230
-	if ($mode) $sql.=", description";
231
-	$sql.=" FROM ".MAIN_DB_PREFIX."ecm_files";
232
-	$sql.=" WHERE filepath = '".$db->escape($path)."'";
233
-	$sql.=" AND entity = ".$conf->entity;
228
+	$sql = " SELECT rowid, label, entity, filename, filepath, fullpath_orig, keywords, cover, gen_or_uploaded, extraparams, date_c, date_m, fk_user_c, fk_user_m,";
229
+	$sql .= " acl, position, share";
230
+	if ($mode) $sql .= ", description";
231
+	$sql .= " FROM ".MAIN_DB_PREFIX."ecm_files";
232
+	$sql .= " WHERE filepath = '".$db->escape($path)."'";
233
+	$sql .= " AND entity = ".$conf->entity;
234 234
 
235 235
 	$resql = $db->query($sql);
236 236
 	if ($resql)
237 237
 	{
238
-		$file_list=array();
238
+		$file_list = array();
239 239
 		$num = $db->num_rows($resql);
240 240
 		$i = 0;
241 241
 		while ($i < $num)
@@ -243,11 +243,11 @@  discard block
 block discarded – undo
243 243
 			$obj = $db->fetch_object($resql);
244 244
 			if ($obj)
245 245
 			{
246
-				preg_match('/([^\/]+)\/[^\/]+$/',DOL_DATA_ROOT.'/'.$obj->filepath.'/'.$obj->filename,$reg);
247
-				$level1name=(isset($reg[1])?$reg[1]:'');
246
+				preg_match('/([^\/]+)\/[^\/]+$/', DOL_DATA_ROOT.'/'.$obj->filepath.'/'.$obj->filename, $reg);
247
+				$level1name = (isset($reg[1]) ? $reg[1] : '');
248 248
 				$file_list[] = array(
249 249
 					"rowid" => $obj->rowid,
250
-					"label" => $obj->label,         // md5
250
+					"label" => $obj->label, // md5
251 251
 					"name" => $obj->filename,
252 252
 					"path" => DOL_DATA_ROOT.'/'.$obj->filepath,
253 253
 					"level1name" => $level1name,
@@ -267,12 +267,12 @@  discard block
 block discarded – undo
267 267
 		}
268 268
 
269 269
 		// Obtain a list of columns
270
-		if (! empty($sortcriteria))
270
+		if (!empty($sortcriteria))
271 271
 		{
272
-			$myarray=array();
272
+			$myarray = array();
273 273
 			foreach ($file_list as $key => $row)
274 274
 			{
275
-				$myarray[$key] = (isset($row[$sortcriteria])?$row[$sortcriteria]:'');
275
+				$myarray[$key] = (isset($row[$sortcriteria]) ? $row[$sortcriteria] : '');
276 276
 			}
277 277
 			// Sort the data
278 278
 			if ($sortorder) array_multisort($myarray, $sortorder, $file_list);
@@ -306,38 +306,38 @@  discard block
 block discarded – undo
306 306
 	//var_dump($filearrayindatabase);
307 307
 
308 308
 	// Complete filearray with properties found into $filearrayindatabase
309
-	foreach($filearray as $key => $val)
309
+	foreach ($filearray as $key => $val)
310 310
 	{
311
-		$found=0;
311
+		$found = 0;
312 312
 		// Search if it exists into $filearrayindatabase
313
-		foreach($filearrayindatabase as $key2 => $val2)
313
+		foreach ($filearrayindatabase as $key2 => $val2)
314 314
 		{
315 315
 			if ($filearrayindatabase[$key2]['name'] == $filearray[$key]['name'])
316 316
 			{
317
-				$filearray[$key]['position_name']=($filearrayindatabase[$key2]['position']?$filearrayindatabase[$key2]['position']:'0').'_'.$filearrayindatabase[$key2]['name'];
318
-				$filearray[$key]['position']=$filearrayindatabase[$key2]['position'];
319
-				$filearray[$key]['cover']=$filearrayindatabase[$key2]['cover'];
320
-				$filearray[$key]['acl']=$filearrayindatabase[$key2]['acl'];
321
-				$filearray[$key]['rowid']=$filearrayindatabase[$key2]['rowid'];
322
-				$filearray[$key]['label']=$filearrayindatabase[$key2]['label'];
323
-				$filearray[$key]['share']=$filearrayindatabase[$key2]['share'];
324
-				$found=1;
317
+				$filearray[$key]['position_name'] = ($filearrayindatabase[$key2]['position'] ? $filearrayindatabase[$key2]['position'] : '0').'_'.$filearrayindatabase[$key2]['name'];
318
+				$filearray[$key]['position'] = $filearrayindatabase[$key2]['position'];
319
+				$filearray[$key]['cover'] = $filearrayindatabase[$key2]['cover'];
320
+				$filearray[$key]['acl'] = $filearrayindatabase[$key2]['acl'];
321
+				$filearray[$key]['rowid'] = $filearrayindatabase[$key2]['rowid'];
322
+				$filearray[$key]['label'] = $filearrayindatabase[$key2]['label'];
323
+				$filearray[$key]['share'] = $filearrayindatabase[$key2]['share'];
324
+				$found = 1;
325 325
 				break;
326 326
 			}
327 327
 		}
328 328
 
329
-		if (! $found)    // This happen in transition toward version 6, or if files were added manually into os dir.
329
+		if (!$found)    // This happen in transition toward version 6, or if files were added manually into os dir.
330 330
 		{
331
-			$filearray[$key]['position']='999999';     // File not indexed are at end. So if we add a file, it will not replace an existing position
332
-			$filearray[$key]['cover']=0;
333
-			$filearray[$key]['acl']='';
331
+			$filearray[$key]['position'] = '999999'; // File not indexed are at end. So if we add a file, it will not replace an existing position
332
+			$filearray[$key]['cover'] = 0;
333
+			$filearray[$key]['acl'] = '';
334 334
 
335
-			$rel_filename = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $filearray[$key]['fullname']);
336
-			if (! preg_match('/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filetorenameafter))     // If not a tmp file
335
+			$rel_filename = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $filearray[$key]['fullname']);
336
+			if (!preg_match('/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filetorenameafter))     // If not a tmp file
337 337
 			{
338 338
 				dol_syslog("list_of_documents We found a file called '".$filearray[$key]['name']."' not indexed into database. We add it");
339 339
 				include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
340
-				$ecmfile=new EcmFiles($db);
340
+				$ecmfile = new EcmFiles($db);
341 341
 
342 342
 				// Add entry into database
343 343
 				$filename = basename($rel_filename);
@@ -347,11 +347,11 @@  discard block
 block discarded – undo
347 347
 
348 348
 				$ecmfile->filepath = $rel_dir;
349 349
 				$ecmfile->filename = $filename;
350
-				$ecmfile->label = md5_file(dol_osencode($filearray[$key]['fullname']));        // $destfile is a full path to file
350
+				$ecmfile->label = md5_file(dol_osencode($filearray[$key]['fullname'])); // $destfile is a full path to file
351 351
 				$ecmfile->fullpath_orig = $filearray[$key]['fullname'];
352 352
 				$ecmfile->gen_or_uploaded = 'unknown';
353
-				$ecmfile->description = '';    // indexed content
354
-				$ecmfile->keyword = '';        // keyword content
353
+				$ecmfile->description = ''; // indexed content
354
+				$ecmfile->keyword = ''; // keyword content
355 355
 				$result = $ecmfile->create($user);
356 356
 				if ($result < 0)
357 357
 				{
@@ -359,12 +359,12 @@  discard block
 block discarded – undo
359 359
 				}
360 360
 				else
361 361
 				{
362
-					$filearray[$key]['rowid']=$result;
362
+					$filearray[$key]['rowid'] = $result;
363 363
 				}
364 364
 			}
365 365
 			else
366 366
 			{
367
-				$filearray[$key]['rowid']=0;     // Should not happened
367
+				$filearray[$key]['rowid'] = 0; // Should not happened
368 368
 			}
369 369
 		}
370 370
 	}
@@ -385,10 +385,10 @@  discard block
 block discarded – undo
385 385
 	global $sortorder;
386 386
 	global $sortfield;
387 387
 
388
-	$sortorder=strtoupper($sortorder);
388
+	$sortorder = strtoupper($sortorder);
389 389
 
390
-	if ($sortorder == 'ASC') { $retup=-1; $retdown=1; }
391
-	else { $retup=1; $retdown=-1; }
390
+	if ($sortorder == 'ASC') { $retup = -1; $retdown = 1; }
391
+	else { $retup = 1; $retdown = -1; }
392 392
 
393 393
 	if ($sortfield == 'name')
394 394
 	{
@@ -416,7 +416,7 @@  discard block
 block discarded – undo
416 416
  */
417 417
 function dol_is_dir($folder)
418 418
 {
419
-	$newfolder=dol_osencode($folder);
419
+	$newfolder = dol_osencode($folder);
420 420
 	if (is_dir($newfolder)) return true;
421 421
 	else return false;
422 422
 }
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
  */
430 430
 function dol_is_file($pathoffile)
431 431
 {
432
-	$newpathoffile=dol_osencode($pathoffile);
432
+	$newpathoffile = dol_osencode($pathoffile);
433 433
 	return is_file($newpathoffile);
434 434
 }
435 435
 
@@ -441,10 +441,10 @@  discard block
 block discarded – undo
441 441
  */
442 442
 function dol_is_url($url)
443 443
 {
444
-	$tmpprot=array('file','http','https','ftp','zlib','data','ssh','ssh2','ogg','expect');
445
-	foreach($tmpprot as $prot)
444
+	$tmpprot = array('file', 'http', 'https', 'ftp', 'zlib', 'data', 'ssh', 'ssh2', 'ogg', 'expect');
445
+	foreach ($tmpprot as $prot)
446 446
 	{
447
-		if (preg_match('/^'.$prot.':/i',$url)) return true;
447
+		if (preg_match('/^'.$prot.':/i', $url)) return true;
448 448
 	}
449 449
 	return false;
450 450
 }
@@ -457,7 +457,7 @@  discard block
 block discarded – undo
457 457
  */
458 458
 function dol_dir_is_emtpy($folder)
459 459
 {
460
-	$newfolder=dol_osencode($folder);
460
+	$newfolder = dol_osencode($folder);
461 461
 	if (is_dir($newfolder))
462 462
 	{
463 463
 		$handle = opendir($newfolder);
@@ -466,7 +466,7 @@  discard block
 block discarded – undo
466 466
 		{
467 467
 			$name_array[] = $name;
468 468
 		}
469
-		foreach($name_array as $temp) $folder_content .= $temp;
469
+		foreach ($name_array as $temp) $folder_content .= $temp;
470 470
 
471 471
 		closedir($handle);
472 472
 
@@ -486,24 +486,24 @@  discard block
 block discarded – undo
486 486
  */
487 487
 function dol_count_nb_of_line($file)
488 488
 {
489
-	$nb=0;
489
+	$nb = 0;
490 490
 
491
-	$newfile=dol_osencode($file);
491
+	$newfile = dol_osencode($file);
492 492
 	//print 'x'.$file;
493
-	$fp=fopen($newfile,'r');
493
+	$fp = fopen($newfile, 'r');
494 494
 	if ($fp)
495 495
 	{
496 496
 		while (!feof($fp))
497 497
 		{
498
-			$line=fgets($fp);
498
+			$line = fgets($fp);
499 499
 			// We increase count only if read was success. We need test because feof return true only after fgets so we do n+1 fgets for a file with n lines.
500
-			if (! $line === false) $nb++;
500
+			if (!$line === false) $nb++;
501 501
 		}
502 502
 		fclose($fp);
503 503
 	}
504 504
 	else
505 505
 	{
506
-		$nb=-1;
506
+		$nb = -1;
507 507
 	}
508 508
 
509 509
 	return $nb;
@@ -518,7 +518,7 @@  discard block
 block discarded – undo
518 518
  */
519 519
 function dol_filesize($pathoffile)
520 520
 {
521
-	$newpathoffile=dol_osencode($pathoffile);
521
+	$newpathoffile = dol_osencode($pathoffile);
522 522
 	return filesize($newpathoffile);
523 523
 }
524 524
 
@@ -530,7 +530,7 @@  discard block
 block discarded – undo
530 530
  */
531 531
 function dol_filemtime($pathoffile)
532 532
 {
533
-	$newpathoffile=dol_osencode($pathoffile);
533
+	$newpathoffile = dol_osencode($pathoffile);
534 534
 	return @filemtime($newpathoffile); // @Is to avoid errors if files does not exists
535 535
 }
536 536
 
@@ -545,31 +545,31 @@  discard block
 block discarded – undo
545 545
  * @return	int							<0 if error, 0 if nothing done (dest file already exists), >0 if OK
546 546
  * @see		dol_copy dolReplaceRegExInFile
547 547
  */
548
-function dolReplaceInFile($srcfile, $arrayreplacement, $destfile='', $newmask=0, $indexdatabase=0)
548
+function dolReplaceInFile($srcfile, $arrayreplacement, $destfile = '', $newmask = 0, $indexdatabase = 0)
549 549
 {
550 550
 	global $conf;
551 551
 
552 552
 	dol_syslog("files.lib.php::dolReplaceInFile srcfile=".$srcfile." destfile=".$destfile." newmask=".$newmask." indexdatabase=".$indexdatabase);
553 553
 
554 554
 	if (empty($srcfile)) return -1;
555
-	if (empty($destfile)) $destfile=$srcfile;
555
+	if (empty($destfile)) $destfile = $srcfile;
556 556
 
557
-	$destexists=dol_is_file($destfile);
557
+	$destexists = dol_is_file($destfile);
558 558
 	if (($destfile != $srcfile) && $destexists) return 0;
559 559
 
560
-	$tmpdestfile=$destfile.'.tmp';
560
+	$tmpdestfile = $destfile.'.tmp';
561 561
 
562
-	$newpathofsrcfile=dol_osencode($srcfile);
563
-	$newpathoftmpdestfile=dol_osencode($tmpdestfile);
564
-	$newpathofdestfile=dol_osencode($destfile);
565
-	$newdirdestfile=dirname($newpathofdestfile);
562
+	$newpathofsrcfile = dol_osencode($srcfile);
563
+	$newpathoftmpdestfile = dol_osencode($tmpdestfile);
564
+	$newpathofdestfile = dol_osencode($destfile);
565
+	$newdirdestfile = dirname($newpathofdestfile);
566 566
 
567
-	if ($destexists && ! is_writable($newpathofdestfile))
567
+	if ($destexists && !is_writable($newpathofdestfile))
568 568
 	{
569 569
 		dol_syslog("files.lib.php::dolReplaceInFile failed Permission denied to overwrite target file", LOG_WARNING);
570 570
 		return -1;
571 571
 	}
572
-	if (! is_writable($newdirdestfile))
572
+	if (!is_writable($newdirdestfile))
573 573
 	{
574 574
 		dol_syslog("files.lib.php::dolReplaceInFile failed Permission denied to write into target directory ".$newdirdestfile, LOG_WARNING);
575 575
 		return -2;
@@ -578,7 +578,7 @@  discard block
 block discarded – undo
578 578
 	dol_delete_file($tmpdestfile);
579 579
 
580 580
 	// Create $newpathoftmpdestfile from $newpathofsrcfile
581
-	$content=file_get_contents($newpathofsrcfile, 'r');
581
+	$content = file_get_contents($newpathofsrcfile, 'r');
582 582
 
583 583
 	$content = make_substitutions($content, $arrayreplacement, null);
584 584
 
@@ -586,17 +586,17 @@  discard block
 block discarded – undo
586 586
 	@chmod($newpathoftmpdestfile, octdec($newmask));
587 587
 
588 588
 	// Rename
589
-	$result=dol_move($newpathoftmpdestfile, $newpathofdestfile, $newmask, (($destfile == $srcfile)?1:0), 0, $indexdatabase);
590
-	if (! $result)
589
+	$result = dol_move($newpathoftmpdestfile, $newpathofdestfile, $newmask, (($destfile == $srcfile) ? 1 : 0), 0, $indexdatabase);
590
+	if (!$result)
591 591
 	{
592 592
 		dol_syslog("files.lib.php::dolReplaceInFile failed to move tmp file to final dest", LOG_WARNING);
593 593
 		return -3;
594 594
 	}
595
-	if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK;
595
+	if (empty($newmask) && !empty($conf->global->MAIN_UMASK)) $newmask = $conf->global->MAIN_UMASK;
596 596
 	if (empty($newmask))	// This should no happen
597 597
 	{
598 598
 		dol_syslog("Warning: dolReplaceInFile called with empty value for newmask and no default value defined", LOG_WARNING);
599
-		$newmask='0664';
599
+		$newmask = '0664';
600 600
 	}
601 601
 
602 602
 	@chmod($newpathofdestfile, octdec($newmask));
@@ -615,7 +615,7 @@  discard block
 block discarded – undo
615 615
  * @return	int							<0 if error, 0 if nothing done (dest file already exists), >0 if OK
616 616
  * @see		dol_copy dolReplaceInFile
617 617
  */
618
-function dolReplaceRegExInFile($srcfile, $arrayreplacement, $destfile='', $newmask=0, $indexdatabase=0)
618
+function dolReplaceRegExInFile($srcfile, $arrayreplacement, $destfile = '', $newmask = 0, $indexdatabase = 0)
619 619
 {
620 620
 	// TODO
621 621
 
@@ -631,7 +631,7 @@  discard block
 block discarded – undo
631 631
  * @return	int							<0 if error, 0 if nothing done (dest file already exists and overwriteifexists=0), >0 if OK
632 632
  * @see		dol_delete_file
633 633
  */
634
-function dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
634
+function dol_copy($srcfile, $destfile, $newmask = 0, $overwriteifexists = 1)
635 635
 {
636 636
 	global $conf;
637 637
 
@@ -639,36 +639,36 @@  discard block
 block discarded – undo
639 639
 
640 640
 	if (empty($srcfile) || empty($destfile)) return -1;
641 641
 
642
-	$destexists=dol_is_file($destfile);
643
-	if (! $overwriteifexists && $destexists) return 0;
642
+	$destexists = dol_is_file($destfile);
643
+	if (!$overwriteifexists && $destexists) return 0;
644 644
 
645
-	$newpathofsrcfile=dol_osencode($srcfile);
646
-	$newpathofdestfile=dol_osencode($destfile);
647
-	$newdirdestfile=dirname($newpathofdestfile);
645
+	$newpathofsrcfile = dol_osencode($srcfile);
646
+	$newpathofdestfile = dol_osencode($destfile);
647
+	$newdirdestfile = dirname($newpathofdestfile);
648 648
 
649
-	if ($destexists && ! is_writable($newpathofdestfile))
649
+	if ($destexists && !is_writable($newpathofdestfile))
650 650
 	{
651 651
 		dol_syslog("files.lib.php::dol_copy failed Permission denied to overwrite target file", LOG_WARNING);
652 652
 		return -1;
653 653
 	}
654
-	if (! is_writable($newdirdestfile))
654
+	if (!is_writable($newdirdestfile))
655 655
 	{
656 656
 		dol_syslog("files.lib.php::dol_copy failed Permission denied to write into target directory ".$newdirdestfile, LOG_WARNING);
657 657
 		return -2;
658 658
 	}
659 659
 	// Copy with overwriting if exists
660
-	$result=@copy($newpathofsrcfile, $newpathofdestfile);
660
+	$result = @copy($newpathofsrcfile, $newpathofdestfile);
661 661
 	//$result=copy($newpathofsrcfile, $newpathofdestfile);	// To see errors, remove @
662
-	if (! $result)
662
+	if (!$result)
663 663
 	{
664 664
 		dol_syslog("files.lib.php::dol_copy failed to copy", LOG_WARNING);
665 665
 		return -3;
666 666
 	}
667
-	if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK;
667
+	if (empty($newmask) && !empty($conf->global->MAIN_UMASK)) $newmask = $conf->global->MAIN_UMASK;
668 668
 	if (empty($newmask))	// This should no happen
669 669
 	{
670 670
 		dol_syslog("Warning: dol_copy called with empty value for newmask and no default value defined", LOG_WARNING);
671
-		$newmask='0664';
671
+		$newmask = '0664';
672 672
 	}
673 673
 
674 674
 	@chmod($newpathofdestfile, octdec($newmask));
@@ -687,44 +687,44 @@  discard block
 block discarded – undo
687 687
  * @return	int							<0 if error, 0 if nothing done (all files already exists and overwriteifexists=0), >0 if OK
688 688
  * @see		dol_copy
689 689
  */
690
-function dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayreplacement=null)
690
+function dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayreplacement = null)
691 691
 {
692 692
 	global $conf;
693 693
 
694
-	$result=0;
694
+	$result = 0;
695 695
 
696 696
 	dol_syslog("files.lib.php::dolCopyDir srcfile=".$srcfile." destfile=".$destfile." newmask=".$newmask." overwriteifexists=".$overwriteifexists);
697 697
 
698 698
 	if (empty($srcfile) || empty($destfile)) return -1;
699 699
 
700
-	$destexists=dol_is_dir($destfile);
700
+	$destexists = dol_is_dir($destfile);
701 701
 	//if (! $overwriteifexists && $destexists) return 0;	// The overwriteifexists is for files only, so propagated to dol_copy only.
702 702
 
703
-	if (! $destexists)
703
+	if (!$destexists)
704 704
 	{
705 705
 		// We must set mask just before creating dir, becaause it can be set differently by dol_copy
706 706
 		umask(0);
707
-		$dirmaskdec=octdec($newmask);
708
-		if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $dirmaskdec=octdec($conf->global->MAIN_UMASK);
709
-		$dirmaskdec |= octdec('0200');  // Set w bit required to be able to create content for recursive subdirs files
707
+		$dirmaskdec = octdec($newmask);
708
+		if (empty($newmask) && !empty($conf->global->MAIN_UMASK)) $dirmaskdec = octdec($conf->global->MAIN_UMASK);
709
+		$dirmaskdec |= octdec('0200'); // Set w bit required to be able to create content for recursive subdirs files
710 710
 		dol_mkdir($destfile, '', decoct($dirmaskdec));
711 711
 	}
712 712
 
713
-	$ossrcfile=dol_osencode($srcfile);
714
-	$osdestfile=dol_osencode($destfile);
713
+	$ossrcfile = dol_osencode($srcfile);
714
+	$osdestfile = dol_osencode($destfile);
715 715
 
716 716
 	// Recursive function to copy all subdirectories and contents:
717 717
 	if (is_dir($ossrcfile))
718 718
 	{
719
-		$dir_handle=opendir($ossrcfile);
720
-		while ($file=readdir($dir_handle))
719
+		$dir_handle = opendir($ossrcfile);
720
+		while ($file = readdir($dir_handle))
721 721
 		{
722
-			if ($file != "." && $file != ".." && ! is_link($ossrcfile."/".$file))
722
+			if ($file != "." && $file != ".." && !is_link($ossrcfile."/".$file))
723 723
 			{
724 724
 				if (is_dir($ossrcfile."/".$file))
725 725
 				{
726 726
 					//var_dump("xxx dolCopyDir $srcfile/$file, $destfile/$file, $newmask, $overwriteifexists");
727
-					$tmpresult=dolCopyDir($srcfile."/".$file, $destfile."/".$file, $newmask, $overwriteifexists, $arrayreplacement);
727
+					$tmpresult = dolCopyDir($srcfile."/".$file, $destfile."/".$file, $newmask, $overwriteifexists, $arrayreplacement);
728 728
 				}
729 729
 				else
730 730
 				{
@@ -732,12 +732,12 @@  discard block
 block discarded – undo
732 732
 					// Replace destination filename with a new one
733 733
 					if (is_array($arrayreplacement))
734 734
 					{
735
-						foreach($arrayreplacement as $key => $val)
735
+						foreach ($arrayreplacement as $key => $val)
736 736
 						{
737 737
 							$newfile = str_replace($key, $val, $newfile);
738 738
 						}
739 739
 					}
740
-					$tmpresult=dol_copy($srcfile."/".$file, $destfile."/".$newfile, $newmask, $overwriteifexists);
740
+					$tmpresult = dol_copy($srcfile."/".$file, $destfile."/".$newfile, $newmask, $overwriteifexists);
741 741
 				}
742 742
 				// Set result
743 743
 				if ($result > 0 && $tmpresult >= 0)
@@ -746,7 +746,7 @@  discard block
 block discarded – undo
746 746
 				}
747 747
 				else
748 748
 				{
749
-					$result=$tmpresult;
749
+					$result = $tmpresult;
750 750
 				}
751 751
 				if ($result < 0) break;
752 752
 
@@ -780,31 +780,31 @@  discard block
 block discarded – undo
780 780
  * @return  boolean 		            True if OK, false if KO
781 781
  * @see dol_move_uploaded_file
782 782
  */
783
-function dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvirus=0, $indexdatabase=1)
783
+function dol_move($srcfile, $destfile, $newmask = 0, $overwriteifexists = 1, $testvirus = 0, $indexdatabase = 1)
784 784
 {
785 785
 	global $user, $db, $conf;
786
-	$result=false;
786
+	$result = false;
787 787
 
788 788
 	dol_syslog("files.lib.php::dol_move srcfile=".$srcfile." destfile=".$destfile." newmask=".$newmask." overwritifexists=".$overwriteifexists);
789
-	$srcexists=dol_is_file($srcfile);
790
-	$destexists=dol_is_file($destfile);
789
+	$srcexists = dol_is_file($srcfile);
790
+	$destexists = dol_is_file($destfile);
791 791
 
792
-	if (! $srcexists)
792
+	if (!$srcexists)
793 793
 	{
794 794
 		dol_syslog("files.lib.php::dol_move srcfile does not exists. we ignore the move request.");
795 795
 		return false;
796 796
 	}
797 797
 
798
-	if ($overwriteifexists || ! $destexists)
798
+	if ($overwriteifexists || !$destexists)
799 799
 	{
800
-		$newpathofsrcfile=dol_osencode($srcfile);
801
-		$newpathofdestfile=dol_osencode($destfile);
800
+		$newpathofsrcfile = dol_osencode($srcfile);
801
+		$newpathofdestfile = dol_osencode($destfile);
802 802
 
803 803
 		// Check virus
804
-		$testvirusarray=array();
804
+		$testvirusarray = array();
805 805
 		if ($testvirus)
806 806
 		{
807
-			$testvirusarray=dolCheckVirus($newpathofsrcfile);
807
+			$testvirusarray = dolCheckVirus($newpathofsrcfile);
808 808
 			if (count($testvirusarray))
809 809
 			{
810 810
 				dol_syslog("files.lib.php::dol_move canceled because a virus was found into source file. we ignore the move request.", LOG_WARNING);
@@ -812,15 +812,15 @@  discard block
 block discarded – undo
812 812
 			}
813 813
 		}
814 814
 
815
-		$result=@rename($newpathofsrcfile, $newpathofdestfile); // To see errors, remove @
816
-		if (! $result)
815
+		$result = @rename($newpathofsrcfile, $newpathofdestfile); // To see errors, remove @
816
+		if (!$result)
817 817
 		{
818 818
 			if ($destexists)
819 819
 			{
820 820
 				dol_syslog("files.lib.php::dol_move Failed. We try to delete target first and move after.", LOG_WARNING);
821 821
 				// We force delete and try again. Rename function sometimes fails to replace dest file with some windows NTFS partitions.
822 822
 				dol_delete_file($destfile);
823
-				$result=@rename($newpathofsrcfile, $newpathofdestfile); // To see errors, remove @
823
+				$result = @rename($newpathofsrcfile, $newpathofdestfile); // To see errors, remove @
824 824
 			}
825 825
 			else dol_syslog("files.lib.php::dol_move Failed.", LOG_WARNING);
826 826
 		}
@@ -829,9 +829,9 @@  discard block
 block discarded – undo
829 829
 		if ($result && $indexdatabase)
830 830
 		{
831 831
 			// Rename entry into ecm database
832
-			$rel_filetorenamebefore = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $srcfile);
833
-			$rel_filetorenameafter = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $destfile);
834
-			if (! preg_match('/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filetorenameafter))     // If not a tmp file
832
+			$rel_filetorenamebefore = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $srcfile);
833
+			$rel_filetorenameafter = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $destfile);
834
+			if (!preg_match('/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filetorenameafter))     // If not a tmp file
835 835
 			{
836 836
 				$rel_filetorenamebefore = preg_replace('/^[\\/]/', '', $rel_filetorenamebefore);
837 837
 				$rel_filetorenameafter = preg_replace('/^[\\/]/', '', $rel_filetorenameafter);
@@ -840,14 +840,14 @@  discard block
 block discarded – undo
840 840
 				dol_syslog("Try to rename also entries in database for full relative path before = ".$rel_filetorenamebefore." after = ".$rel_filetorenameafter, LOG_DEBUG);
841 841
 				include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
842 842
 
843
-				$ecmfiletarget=new EcmFiles($db);
843
+				$ecmfiletarget = new EcmFiles($db);
844 844
 				$resultecmtarget = $ecmfiletarget->fetch(0, '', $rel_filetorenameafter);
845 845
 				if ($resultecmtarget > 0)   // An entry for target name already exists for target, we delete it, a new one will be created.
846 846
 				{
847 847
 					$ecmfiletarget->delete($user);
848 848
 				}
849 849
 
850
-				$ecmfile=new EcmFiles($db);
850
+				$ecmfile = new EcmFiles($db);
851 851
 				$resultecm = $ecmfile->fetch(0, '', $rel_filetorenamebefore);
852 852
 				if ($resultecm > 0)   // If an entry was found for src file, we use it to move entry
853 853
 				{
@@ -869,11 +869,11 @@  discard block
 block discarded – undo
869 869
 
870 870
 					$ecmfile->filepath = $rel_dir;
871 871
 					$ecmfile->filename = $filename;
872
-					$ecmfile->label = md5_file(dol_osencode($destfile));        // $destfile is a full path to file
872
+					$ecmfile->label = md5_file(dol_osencode($destfile)); // $destfile is a full path to file
873 873
 					$ecmfile->fullpath_orig = $srcfile;
874 874
 					$ecmfile->gen_or_uploaded = 'unknown';
875
-					$ecmfile->description = '';    // indexed content
876
-					$ecmfile->keyword = '';        // keyword content
875
+					$ecmfile->description = ''; // indexed content
876
+					$ecmfile->keyword = ''; // keyword content
877 877
 					$resultecm = $ecmfile->create($user);
878 878
 					if ($resultecm < 0)
879 879
 					{
@@ -885,13 +885,13 @@  discard block
 block discarded – undo
885 885
 					setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings');
886 886
 				}
887 887
 
888
-				if ($resultecm > 0) $result=true;
888
+				if ($resultecm > 0) $result = true;
889 889
 				else $result = false;
890 890
 			}
891 891
 		}
892 892
 
893
-		if (empty($newmask)) $newmask=empty($conf->global->MAIN_UMASK)?'0755':$conf->global->MAIN_UMASK;
894
-		$newmaskdec=octdec($newmask);
893
+		if (empty($newmask)) $newmask = empty($conf->global->MAIN_UMASK) ? '0755' : $conf->global->MAIN_UMASK;
894
+		$newmaskdec = octdec($newmask);
895 895
 		// Currently method is restricted to files (dol_delete_files previously used is for files, and mask usage if for files too)
896 896
 		// to allow mask usage for dir, we shoul introduce a new param "isdir" to 1 to complete newmask like this
897 897
 		// if ($isdir) $newmaskdec |= octdec('0111');  // Set x bit required for directories
@@ -927,16 +927,16 @@  discard block
 block discarded – undo
927 927
 {
928 928
 	global $conf;
929 929
 
930
-	if (! empty($conf->global->MAIN_ANTIVIRUS_COMMAND))
930
+	if (!empty($conf->global->MAIN_ANTIVIRUS_COMMAND))
931 931
 	{
932
-		if (! class_exists('AntiVir')) {
932
+		if (!class_exists('AntiVir')) {
933 933
 			require_once DOL_DOCUMENT_ROOT.'/core/class/antivir.class.php';
934 934
 		}
935
-		$antivir=new AntiVir($db);
935
+		$antivir = new AntiVir($db);
936 936
 		$result = $antivir->dol_avscan_file($src_file);
937 937
 		if ($result < 0)	// If virus or error, we stop here
938 938
 		{
939
-			$reterrors=$antivir->errors;
939
+			$reterrors = $antivir->errors;
940 940
 			return $reterrors;
941 941
 		}
942 942
 	}
@@ -962,20 +962,20 @@  discard block
 block discarded – undo
962 962
  *	@return int       			  		>0 if OK, <0 or string if KO
963 963
  *  @see    dol_move
964 964
  */
965
-function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $nohook=0, $varfiles='addedfile')
965
+function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan = 0, $uploaderrorcode = 0, $nohook = 0, $varfiles = 'addedfile')
966 966
 {
967 967
 	global $conf, $db, $user, $langs;
968 968
 	global $object, $hookmanager;
969 969
 
970
-	$reshook=0;
970
+	$reshook = 0;
971 971
 	$file_name = $dest_file;
972 972
 
973 973
 	if (empty($nohook))
974 974
 	{
975
-		$reshook=$hookmanager->initHooks(array('fileslib'));
975
+		$reshook = $hookmanager->initHooks(array('fileslib'));
976 976
 
977
-		$parameters=array('dest_file' => $dest_file, 'src_file' => $src_file, 'file_name' => $file_name, 'varfiles' => $varfiles, 'allowoverwrite' => $allowoverwrite);
978
-		$reshook=$hookmanager->executeHooks('moveUploadedFile', $parameters, $object);
977
+		$parameters = array('dest_file' => $dest_file, 'src_file' => $src_file, 'file_name' => $file_name, 'varfiles' => $varfiles, 'allowoverwrite' => $allowoverwrite);
978
+		$reshook = $hookmanager->executeHooks('moveUploadedFile', $parameters, $object);
979 979
 	}
980 980
 
981 981
 	if (empty($reshook))
@@ -983,7 +983,7 @@  discard block
 block discarded – undo
983 983
 		// If an upload error has been reported
984 984
 		if ($uploaderrorcode)
985 985
 		{
986
-			switch($uploaderrorcode)
986
+			switch ($uploaderrorcode)
987 987
 			{
988 988
 				case UPLOAD_ERR_INI_SIZE:	// 1
989 989
 					return 'ErrorFileSizeTooLarge';
@@ -1011,25 +1011,25 @@  discard block
 block discarded – undo
1011 1011
 		// If we need to make a virus scan
1012 1012
 		if (empty($disablevirusscan) && file_exists($src_file))
1013 1013
 		{
1014
-			$checkvirusarray=dolCheckVirus($src_file);
1014
+			$checkvirusarray = dolCheckVirus($src_file);
1015 1015
 			if (count($checkvirusarray))
1016 1016
 			{
1017
-			   dol_syslog('Files.lib::dol_move_uploaded_file File "'.$src_file.'" (target name "'.$dest_file.'") KO with antivirus: result='.$result.' errors='.join(',',$checkvirusarray), LOG_WARNING);
1018
-			   return 'ErrorFileIsInfectedWithAVirus: '.join(',',$checkvirusarray);
1017
+			   dol_syslog('Files.lib::dol_move_uploaded_file File "'.$src_file.'" (target name "'.$dest_file.'") KO with antivirus: result='.$result.' errors='.join(',', $checkvirusarray), LOG_WARNING);
1018
+			   return 'ErrorFileIsInfectedWithAVirus: '.join(',', $checkvirusarray);
1019 1019
 			}
1020 1020
 		}
1021 1021
 
1022 1022
 		// Security:
1023 1023
 		// Disallow file with some extensions. We rename them.
1024 1024
 		// Because if we put the documents directory into a directory inside web root (very bad), this allows to execute on demand arbitrary code.
1025
-		if (preg_match('/\.htm|\.html|\.php|\.pl|\.cgi$/i',$dest_file) && empty($conf->global->MAIN_DOCUMENT_IS_OUTSIDE_WEBROOT_SO_NOEXE_NOT_REQUIRED))
1025
+		if (preg_match('/\.htm|\.html|\.php|\.pl|\.cgi$/i', $dest_file) && empty($conf->global->MAIN_DOCUMENT_IS_OUTSIDE_WEBROOT_SO_NOEXE_NOT_REQUIRED))
1026 1026
 		{
1027
-			$file_name.= '.noexe';
1027
+			$file_name .= '.noexe';
1028 1028
 		}
1029 1029
 
1030 1030
 		// Security:
1031 1031
 		// We refuse cache files/dirs, upload using .. and pipes into filenames.
1032
-		if (preg_match('/^\./',$src_file) || preg_match('/\.\./',$src_file) || preg_match('/[<>|]/',$src_file))
1032
+		if (preg_match('/^\./', $src_file) || preg_match('/\.\./', $src_file) || preg_match('/[<>|]/', $src_file))
1033 1033
 		{
1034 1034
 			dol_syslog("Refused to deliver file ".$src_file, LOG_WARNING);
1035 1035
 			return -1;
@@ -1037,7 +1037,7 @@  discard block
 block discarded – undo
1037 1037
 
1038 1038
 		// Security:
1039 1039
 		// On interdit fichiers caches, remontees de repertoire ainsi que les pipe dans les noms de fichiers.
1040
-		if (preg_match('/^\./',$dest_file) || preg_match('/\.\./',$dest_file) || preg_match('/[<>|]/',$dest_file))
1040
+		if (preg_match('/^\./', $dest_file) || preg_match('/\.\./', $dest_file) || preg_match('/[<>|]/', $dest_file))
1041 1041
 		{
1042 1042
 			dol_syslog("Refused to deliver file ".$dest_file, LOG_WARNING);
1043 1043
 			return -2;
@@ -1047,24 +1047,24 @@  discard block
 block discarded – undo
1047 1047
 	if ($reshook < 0)	// At least one blocking error returned by one hook
1048 1048
 	{
1049 1049
 		$errmsg = join(',', $hookmanager->errors);
1050
-		if (empty($errmsg)) $errmsg = 'ErrorReturnedBySomeHooks';	// Should not occurs. Added if hook is bugged and does not set ->errors when there is error.
1050
+		if (empty($errmsg)) $errmsg = 'ErrorReturnedBySomeHooks'; // Should not occurs. Added if hook is bugged and does not set ->errors when there is error.
1051 1051
 		return $errmsg;
1052 1052
 	}
1053 1053
 	elseif (empty($reshook))
1054 1054
 	{
1055 1055
 		// The file functions must be in OS filesystem encoding.
1056
-		$src_file_osencoded=dol_osencode($src_file);
1057
-		$file_name_osencoded=dol_osencode($file_name);
1056
+		$src_file_osencoded = dol_osencode($src_file);
1057
+		$file_name_osencoded = dol_osencode($file_name);
1058 1058
 
1059 1059
 		// Check if destination dir is writable
1060
-		if (! is_writable(dirname($file_name_osencoded)))
1060
+		if (!is_writable(dirname($file_name_osencoded)))
1061 1061
 		{
1062 1062
 			dol_syslog("Files.lib::dol_move_uploaded_file Dir ".dirname($file_name_osencoded)." is not writable. Return 'ErrorDirNotWritable'", LOG_WARNING);
1063 1063
 			return 'ErrorDirNotWritable';
1064 1064
 		}
1065 1065
 
1066 1066
 		// Check if destination file already exists
1067
-		if (! $allowoverwrite)
1067
+		if (!$allowoverwrite)
1068 1068
 		{
1069 1069
 			if (file_exists($file_name_osencoded))
1070 1070
 			{
@@ -1074,21 +1074,21 @@  discard block
 block discarded – undo
1074 1074
 		}
1075 1075
 
1076 1076
 		// Move file
1077
-		$return=move_uploaded_file($src_file_osencoded, $file_name_osencoded);
1077
+		$return = move_uploaded_file($src_file_osencoded, $file_name_osencoded);
1078 1078
 		if ($return)
1079 1079
 		{
1080
-			if (! empty($conf->global->MAIN_UMASK)) @chmod($file_name_osencoded, octdec($conf->global->MAIN_UMASK));
1080
+			if (!empty($conf->global->MAIN_UMASK)) @chmod($file_name_osencoded, octdec($conf->global->MAIN_UMASK));
1081 1081
 			dol_syslog("Files.lib::dol_move_uploaded_file Success to move ".$src_file." to ".$file_name." - Umask=".$conf->global->MAIN_UMASK, LOG_DEBUG);
1082
-			return 1;	// Success
1082
+			return 1; // Success
1083 1083
 		}
1084 1084
 		else
1085 1085
 		{
1086 1086
 			dol_syslog("Files.lib::dol_move_uploaded_file Failed to move ".$src_file." to ".$file_name, LOG_ERR);
1087
-			return -3;	// Unknown error
1087
+			return -3; // Unknown error
1088 1088
 		}
1089 1089
 	}
1090 1090
 
1091
-	return 1;	// Success
1091
+	return 1; // Success
1092 1092
 }
1093 1093
 
1094 1094
 /**
@@ -1103,7 +1103,7 @@  discard block
 block discarded – undo
1103 1103
  *  @return boolean         		True if no error (file is deleted or if glob is used and there's nothing to delete), False if error
1104 1104
  *  @see dol_delete_dir
1105 1105
  */
1106
-function dol_delete_file($file,$disableglob=0,$nophperrors=0,$nohook=0,$object=null)
1106
+function dol_delete_file($file, $disableglob = 0, $nophperrors = 0, $nohook = 0, $object = null)
1107 1107
 {
1108 1108
 	global $db, $conf, $user, $langs;
1109 1109
 	global $hookmanager;
@@ -1115,7 +1115,7 @@  discard block
 block discarded – undo
1115 1115
 
1116 1116
 	// Security:
1117 1117
 	// We refuse transversal using .. and pipes into filenames.
1118
-	if (preg_match('/\.\./',$file) || preg_match('/[<>|]/',$file))
1118
+	if (preg_match('/\.\./', $file) || preg_match('/[<>|]/', $file))
1119 1119
 	{
1120 1120
 		dol_syslog("Refused to delete file ".$file, LOG_WARNING);
1121 1121
 		return False;
@@ -1125,13 +1125,13 @@  discard block
 block discarded – undo
1125 1125
 	{
1126 1126
 		$hookmanager->initHooks(array('fileslib'));
1127 1127
 
1128
-		$parameters=array(
1128
+		$parameters = array(
1129 1129
 				'GET' => $_GET,
1130 1130
 				'file' => $file,
1131 1131
 				'disableglob'=> $disableglob,
1132 1132
 				'nophperrors' => $nophperrors
1133 1133
 		);
1134
-		$reshook=$hookmanager->executeHooks('deleteFile', $parameters, $object);
1134
+		$reshook = $hookmanager->executeHooks('deleteFile', $parameters, $object);
1135 1135
 	}
1136 1136
 
1137 1137
 	if (empty($nohook) && $reshook != 0) // reshook = 0 to do standard actions, 1 = ok, -1 = ko
@@ -1141,35 +1141,35 @@  discard block
 block discarded – undo
1141 1141
 	}
1142 1142
 	else
1143 1143
 	{
1144
-		$error=0;
1144
+		$error = 0;
1145 1145
 
1146 1146
 		//print "x".$file." ".$disableglob;exit;
1147
-		$file_osencoded=dol_osencode($file);    // New filename encoded in OS filesystem encoding charset
1148
-		if (empty($disableglob) && ! empty($file_osencoded))
1149
-		{
1150
-			$ok=true;
1151
-			$globencoded=str_replace('[','\[',$file_osencoded);
1152
-			$globencoded=str_replace(']','\]',$globencoded);
1153
-			$listofdir=glob($globencoded);
1154
-			if (! empty($listofdir) && is_array($listofdir))
1147
+		$file_osencoded = dol_osencode($file); // New filename encoded in OS filesystem encoding charset
1148
+		if (empty($disableglob) && !empty($file_osencoded))
1149
+		{
1150
+			$ok = true;
1151
+			$globencoded = str_replace('[', '\[', $file_osencoded);
1152
+			$globencoded = str_replace(']', '\]', $globencoded);
1153
+			$listofdir = glob($globencoded);
1154
+			if (!empty($listofdir) && is_array($listofdir))
1155 1155
 			{
1156 1156
 				foreach ($listofdir as $filename)
1157 1157
 				{
1158
-					if ($nophperrors) $ok=@unlink($filename);
1159
-					else $ok=unlink($filename);
1158
+					if ($nophperrors) $ok = @unlink($filename);
1159
+					else $ok = unlink($filename);
1160 1160
 					if ($ok)
1161 1161
 					{
1162 1162
 						dol_syslog("Removed file ".$filename, LOG_DEBUG);
1163 1163
 
1164 1164
 						// Delete entry into ecm database
1165
-						$rel_filetodelete = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $filename);
1166
-						if (! preg_match('/(\/temp\/|\/thumbs\/|\.meta$)/', $rel_filetodelete))     // If not a tmp file
1165
+						$rel_filetodelete = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $filename);
1166
+						if (!preg_match('/(\/temp\/|\/thumbs\/|\.meta$)/', $rel_filetodelete))     // If not a tmp file
1167 1167
 						{
1168 1168
 							$rel_filetodelete = preg_replace('/^[\\/]/', '', $rel_filetodelete);
1169 1169
 
1170 1170
 							dol_syslog("Try to remove also entries in database for full relative path = ".$rel_filetodelete, LOG_DEBUG);
1171 1171
 							include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
1172
-							$ecmfile=new EcmFiles($db);
1172
+							$ecmfile = new EcmFiles($db);
1173 1173
 							$result = $ecmfile->fetch(0, '', $rel_filetodelete);
1174 1174
 							if ($result >= 0 && $ecmfile->id > 0)
1175 1175
 							{
@@ -1190,9 +1190,9 @@  discard block
 block discarded – undo
1190 1190
 		}
1191 1191
 		else
1192 1192
 		{
1193
-			$ok=false;
1194
-			if ($nophperrors) $ok=@unlink($file_osencoded);
1195
-			else $ok=unlink($file_osencoded);
1193
+			$ok = false;
1194
+			if ($nophperrors) $ok = @unlink($file_osencoded);
1195
+			else $ok = unlink($file_osencoded);
1196 1196
 			if ($ok) dol_syslog("Removed file ".$file_osencoded, LOG_DEBUG);
1197 1197
 			else dol_syslog("Failed to remove file ".$file_osencoded, LOG_WARNING);
1198 1198
 		}
@@ -1210,18 +1210,18 @@  discard block
 block discarded – undo
1210 1210
  *  @return boolean         		True if success, false if error
1211 1211
  *  @see dol_delete_file dol_copy
1212 1212
  */
1213
-function dol_delete_dir($dir,$nophperrors=0)
1213
+function dol_delete_dir($dir, $nophperrors = 0)
1214 1214
 {
1215 1215
 	// Security:
1216 1216
 	// We refuse transversal using .. and pipes into filenames.
1217
-	if (preg_match('/\.\./',$dir) || preg_match('/[<>|]/',$dir))
1217
+	if (preg_match('/\.\./', $dir) || preg_match('/[<>|]/', $dir))
1218 1218
 	{
1219 1219
 		dol_syslog("Refused to delete dir ".$dir, LOG_WARNING);
1220 1220
 		return False;
1221 1221
 	}
1222 1222
 
1223
-	$dir_osencoded=dol_osencode($dir);
1224
-	return ($nophperrors?@rmdir($dir_osencoded):rmdir($dir_osencoded));
1223
+	$dir_osencoded = dol_osencode($dir);
1224
+	return ($nophperrors ? @rmdir($dir_osencoded) : rmdir($dir_osencoded));
1225 1225
 }
1226 1226
 
1227 1227
 /**
@@ -1234,27 +1234,27 @@  discard block
 block discarded – undo
1234 1234
  *  @param  int		$countdeleted   Counter to count nb of elements found really deleted
1235 1235
  *  @return int             		Number of files and directory we try to remove. NB really removed is returned into $countdeleted.
1236 1236
  */
1237
-function dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0)
1237
+function dol_delete_dir_recursive($dir, $count = 0, $nophperrors = 0, $onlysub = 0, &$countdeleted = 0)
1238 1238
 {
1239
-	dol_syslog("functions.lib:dol_delete_dir_recursive ".$dir,LOG_DEBUG);
1239
+	dol_syslog("functions.lib:dol_delete_dir_recursive ".$dir, LOG_DEBUG);
1240 1240
 	if (dol_is_dir($dir))
1241 1241
 	{
1242
-		$dir_osencoded=dol_osencode($dir);
1242
+		$dir_osencoded = dol_osencode($dir);
1243 1243
 		if ($handle = opendir("$dir_osencoded"))
1244 1244
 		{
1245 1245
 			while (false !== ($item = readdir($handle)))
1246 1246
 			{
1247
-				if (! utf8_check($item)) $item=utf8_encode($item);  // should be useless
1247
+				if (!utf8_check($item)) $item = utf8_encode($item); // should be useless
1248 1248
 
1249 1249
 				if ($item != "." && $item != "..")
1250 1250
 				{
1251
-					if (is_dir(dol_osencode("$dir/$item")) && ! is_link(dol_osencode("$dir/$item")))
1251
+					if (is_dir(dol_osencode("$dir/$item")) && !is_link(dol_osencode("$dir/$item")))
1252 1252
 					{
1253
-						$count=dol_delete_dir_recursive("$dir/$item", $count, $nophperrors, 0, $countdeleted);
1253
+						$count = dol_delete_dir_recursive("$dir/$item", $count, $nophperrors, 0, $countdeleted);
1254 1254
 					}
1255 1255
 					else
1256 1256
 					{
1257
-						$result=dol_delete_file("$dir/$item", 1, $nophperrors);
1257
+						$result = dol_delete_file("$dir/$item", 1, $nophperrors);
1258 1258
 						$count++;
1259 1259
 						if ($result) $countdeleted++;
1260 1260
 					}
@@ -1264,7 +1264,7 @@  discard block
 block discarded – undo
1264 1264
 
1265 1265
 			if (empty($onlysub))
1266 1266
 			{
1267
-				$result=dol_delete_dir($dir, $nophperrors);
1267
+				$result = dol_delete_dir($dir, $nophperrors);
1268 1268
 				$count++;
1269 1269
 				if ($result) $countdeleted++;
1270 1270
 			}
@@ -1285,7 +1285,7 @@  discard block
 block discarded – undo
1285 1285
  */
1286 1286
 function dol_delete_preview($object)
1287 1287
 {
1288
-	global $langs,$conf;
1288
+	global $langs, $conf;
1289 1289
 
1290 1290
 	// Define parent dir of elements
1291 1291
 	$element = $object->element;
@@ -1296,54 +1296,54 @@  discard block
 block discarded – undo
1296 1296
 	elseif ($object->element == 'shipping')			$dir = $conf->expedition->dir_output.'/sending';
1297 1297
 	elseif ($object->element == 'delivery')			$dir = $conf->expedition->dir_output.'/receipt';
1298 1298
 	elseif ($object->element == 'fichinter')		$dir = $conf->ficheinter->dir_output;
1299
-	else $dir=empty($conf->$element->dir_output)?'':$conf->$element->dir_output;
1299
+	else $dir = empty($conf->$element->dir_output) ? '' : $conf->$element->dir_output;
1300 1300
 
1301 1301
 	if (empty($dir)) return 'ErrorObjectNoSupportedByFunction';
1302 1302
 
1303 1303
 	$refsan = dol_sanitizeFileName($object->ref);
1304
-	$dir = $dir . "/" . $refsan ;
1305
-	$filepreviewnew = $dir . "/" . $refsan . ".pdf_preview.png";
1306
-	$filepreviewnewbis = $dir . "/" . $refsan . ".pdf_preview-0.png";
1307
-	$filepreviewold = $dir . "/" . $refsan . ".pdf.png";
1304
+	$dir = $dir."/".$refsan;
1305
+	$filepreviewnew = $dir."/".$refsan.".pdf_preview.png";
1306
+	$filepreviewnewbis = $dir."/".$refsan.".pdf_preview-0.png";
1307
+	$filepreviewold = $dir."/".$refsan.".pdf.png";
1308 1308
 
1309 1309
 	// For new preview files
1310 1310
 	if (file_exists($filepreviewnew) && is_writable($filepreviewnew))
1311 1311
 	{
1312
-		if (! dol_delete_file($filepreviewnew,1))
1312
+		if (!dol_delete_file($filepreviewnew, 1))
1313 1313
 		{
1314
-			$object->error=$langs->trans("ErrorFailedToDeleteFile",$filepreviewnew);
1314
+			$object->error = $langs->trans("ErrorFailedToDeleteFile", $filepreviewnew);
1315 1315
 			return 0;
1316 1316
 		}
1317 1317
 	}
1318 1318
 	if (file_exists($filepreviewnewbis) && is_writable($filepreviewnewbis))
1319 1319
 	{
1320
-		if (! dol_delete_file($filepreviewnewbis,1))
1320
+		if (!dol_delete_file($filepreviewnewbis, 1))
1321 1321
 		{
1322
-			$object->error=$langs->trans("ErrorFailedToDeleteFile",$filepreviewnewbis);
1322
+			$object->error = $langs->trans("ErrorFailedToDeleteFile", $filepreviewnewbis);
1323 1323
 			return 0;
1324 1324
 		}
1325 1325
 	}
1326 1326
 	// For old preview files
1327 1327
 	if (file_exists($filepreviewold) && is_writable($filepreviewold))
1328 1328
 	{
1329
-		if (! dol_delete_file($filepreviewold,1))
1329
+		if (!dol_delete_file($filepreviewold, 1))
1330 1330
 		{
1331
-			$object->error=$langs->trans("ErrorFailedToDeleteFile",$filepreviewold);
1331
+			$object->error = $langs->trans("ErrorFailedToDeleteFile", $filepreviewold);
1332 1332
 			return 0;
1333 1333
 		}
1334 1334
 	}
1335 1335
 	else
1336 1336
 	{
1337
-		$multiple = $filepreviewold . ".";
1337
+		$multiple = $filepreviewold.".";
1338 1338
 		for ($i = 0; $i < 20; $i++)
1339 1339
 		{
1340 1340
 			$preview = $multiple.$i;
1341 1341
 
1342 1342
 			if (file_exists($preview) && is_writable($preview))
1343 1343
 			{
1344
-				if ( ! dol_delete_file($preview,1) )
1344
+				if (!dol_delete_file($preview, 1))
1345 1345
 				{
1346
-					$object->error=$langs->trans("ErrorFailedToOpenFile",$preview);
1346
+					$object->error = $langs->trans("ErrorFailedToOpenFile", $preview);
1347 1347
 					return 0;
1348 1348
 				}
1349 1349
 			}
@@ -1366,10 +1366,10 @@  discard block
 block discarded – undo
1366 1366
 	global $conf;
1367 1367
 
1368 1368
 	// Create meta file
1369
-	if (empty($conf->global->MAIN_DOC_CREATE_METAFILE)) return 0;	// By default, no metafile.
1369
+	if (empty($conf->global->MAIN_DOC_CREATE_METAFILE)) return 0; // By default, no metafile.
1370 1370
 
1371 1371
 	// Define parent dir of elements
1372
-	$element=$object->element;
1372
+	$element = $object->element;
1373 1373
 
1374 1374
 	if ($object->element == 'order_supplier')		$dir = $conf->fournisseur->dir_output.'/commande';
1375 1375
 	elseif ($object->element == 'invoice_supplier')	$dir = $conf->fournisseur->dir_output.'/facture';
@@ -1377,17 +1377,17 @@  discard block
 block discarded – undo
1377 1377
 	elseif ($object->element == 'shipping')			$dir = $conf->expedition->dir_output.'/sending';
1378 1378
 	elseif ($object->element == 'delivery')			$dir = $conf->expedition->dir_output.'/receipt';
1379 1379
 	elseif ($object->element == 'fichinter')		$dir = $conf->ficheinter->dir_output;
1380
-	else $dir=empty($conf->$element->dir_output)?'':$conf->$element->dir_output;
1380
+	else $dir = empty($conf->$element->dir_output) ? '' : $conf->$element->dir_output;
1381 1381
 
1382 1382
 	if ($dir)
1383 1383
 	{
1384 1384
 		$object->fetch_thirdparty();
1385 1385
 
1386 1386
 		$objectref = dol_sanitizeFileName($object->ref);
1387
-		$dir = $dir . "/" . $objectref;
1388
-		$file = $dir . "/" . $objectref . ".meta";
1387
+		$dir = $dir."/".$objectref;
1388
+		$file = $dir."/".$objectref.".meta";
1389 1389
 
1390
-		if (! is_dir($dir))
1390
+		if (!is_dir($dir))
1391 1391
 		{
1392 1392
 			dol_mkdir($dir);
1393 1393
 		}
@@ -1395,29 +1395,29 @@  discard block
 block discarded – undo
1395 1395
 		if (is_dir($dir))
1396 1396
 		{
1397 1397
 			$nblignes = count($object->lines);
1398
-			$client = $object->thirdparty->name . " " . $object->thirdparty->address . " " . $object->thirdparty->zip . " " . $object->thirdparty->town;
1399
-			$meta = "REFERENCE=\"" . $object->ref . "\"
1400
-			DATE=\"" . dol_print_date($object->date,'') . "\"
1401
-			NB_ITEMS=\"" . $nblignes . "\"
1402
-			CLIENT=\"" . $client . "\"
1403
-			AMOUNT_EXCL_TAX=\"" . $object->total_ht . "\"
1404
-			AMOUNT=\"" . $object->total_ttc . "\"\n";
1405
-
1406
-			for ($i = 0 ; $i < $nblignes ; $i++)
1398
+			$client = $object->thirdparty->name." ".$object->thirdparty->address." ".$object->thirdparty->zip." ".$object->thirdparty->town;
1399
+			$meta = "REFERENCE=\"".$object->ref."\"
1400
+			DATE=\"" . dol_print_date($object->date, '')."\"
1401
+			NB_ITEMS=\"" . $nblignes."\"
1402
+			CLIENT=\"" . $client."\"
1403
+			AMOUNT_EXCL_TAX=\"" . $object->total_ht."\"
1404
+			AMOUNT=\"" . $object->total_ttc."\"\n";
1405
+
1406
+			for ($i = 0; $i < $nblignes; $i++)
1407 1407
 			{
1408 1408
 				//Pour les articles
1409
-				$meta .= "ITEM_" . $i . "_QUANTITY=\"" . $object->lines[$i]->qty . "\"
1410
-				ITEM_" . $i . "_AMOUNT_WO_TAX=\"" . $object->lines[$i]->total_ht . "\"
1411
-				ITEM_" . $i . "_VAT=\"" .$object->lines[$i]->tva_tx . "\"
1412
-				ITEM_" . $i . "_DESCRIPTION=\"" . str_replace("\r\n","",nl2br($object->lines[$i]->desc)) . "\"
1409
+				$meta .= "ITEM_".$i."_QUANTITY=\"".$object->lines[$i]->qty."\"
1410
+				ITEM_" . $i."_AMOUNT_WO_TAX=\"".$object->lines[$i]->total_ht."\"
1411
+				ITEM_" . $i."_VAT=\"".$object->lines[$i]->tva_tx."\"
1412
+				ITEM_" . $i."_DESCRIPTION=\"".str_replace("\r\n", "", nl2br($object->lines[$i]->desc))."\"
1413 1413
 				";
1414 1414
 			}
1415 1415
 		}
1416 1416
 
1417
-		$fp = fopen($file,"w");
1418
-		fputs($fp,$meta);
1417
+		$fp = fopen($file, "w");
1418
+		fputs($fp, $meta);
1419 1419
 		fclose($fp);
1420
-		if (! empty($conf->global->MAIN_UMASK))
1420
+		if (!empty($conf->global->MAIN_UMASK))
1421 1421
 		@chmod($file, octdec($conf->global->MAIN_UMASK));
1422 1422
 
1423 1423
 		return 1;
@@ -1440,26 +1440,26 @@  discard block
 block discarded – undo
1440 1440
  * @param   string  $trackid                Track id (used to prefix name of session vars to avoid conflict)
1441 1441
  * @return	void
1442 1442
  */
1443
-function dol_init_file_process($pathtoscan='', $trackid='')
1443
+function dol_init_file_process($pathtoscan = '', $trackid = '')
1444 1444
 {
1445
-	$listofpaths=array();
1446
-	$listofnames=array();
1447
-	$listofmimes=array();
1445
+	$listofpaths = array();
1446
+	$listofnames = array();
1447
+	$listofmimes = array();
1448 1448
 
1449 1449
 	if ($pathtoscan)
1450 1450
 	{
1451
-		$listoffiles=dol_dir_list($pathtoscan,'files');
1452
-		foreach($listoffiles as $key => $val)
1451
+		$listoffiles = dol_dir_list($pathtoscan, 'files');
1452
+		foreach ($listoffiles as $key => $val)
1453 1453
 		{
1454
-			$listofpaths[]=$val['fullname'];
1455
-			$listofnames[]=$val['name'];
1456
-			$listofmimes[]=dol_mimetype($val['name']);
1454
+			$listofpaths[] = $val['fullname'];
1455
+			$listofnames[] = $val['name'];
1456
+			$listofmimes[] = dol_mimetype($val['name']);
1457 1457
 		}
1458 1458
 	}
1459
-	$keytoavoidconflict = empty($trackid)?'':'-'.$trackid;
1460
-	$_SESSION["listofpaths".$keytoavoidconflict]=join(';',$listofpaths);
1461
-	$_SESSION["listofnames".$keytoavoidconflict]=join(';',$listofnames);
1462
-	$_SESSION["listofmimes".$keytoavoidconflict]=join(';',$listofmimes);
1459
+	$keytoavoidconflict = empty($trackid) ? '' : '-'.$trackid;
1460
+	$_SESSION["listofpaths".$keytoavoidconflict] = join(';', $listofpaths);
1461
+	$_SESSION["listofnames".$keytoavoidconflict] = join(';', $listofnames);
1462
+	$_SESSION["listofmimes".$keytoavoidconflict] = join(';', $listofmimes);
1463 1463
 }
1464 1464
 
1465 1465
 
@@ -1478,13 +1478,13 @@  discard block
 block discarded – undo
1478 1478
  * @param	int		$generatethumbs			1=Generate also thumbs for uploaded image files
1479 1479
  * @return	int                             <=0 if KO, >0 if OK
1480 1480
  */
1481
-function dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesession=0, $varfiles='addedfile', $savingdocmask='', $link=null, $trackid='', $generatethumbs=1)
1481
+function dol_add_file_process($upload_dir, $allowoverwrite = 0, $donotupdatesession = 0, $varfiles = 'addedfile', $savingdocmask = '', $link = null, $trackid = '', $generatethumbs = 1)
1482 1482
 {
1483
-	global $db,$user,$conf,$langs;
1483
+	global $db, $user, $conf, $langs;
1484 1484
 
1485 1485
 	$res = 0;
1486 1486
 
1487
-	if (! empty($_FILES[$varfiles])) // For view $_FILES[$varfiles]['error']
1487
+	if (!empty($_FILES[$varfiles])) // For view $_FILES[$varfiles]['error']
1488 1488
 	{
1489 1489
 		dol_syslog('dol_add_file_process upload_dir='.$upload_dir.' allowoverwrite='.$allowoverwrite.' donotupdatesession='.$donotupdatesession.' savingdocmask='.$savingdocmask, LOG_DEBUG);
1490 1490
 		if (dol_mkdir($upload_dir) >= 0)
@@ -1503,13 +1503,13 @@  discard block
 block discarded – undo
1503 1503
 			for ($i = 0; $i < $nbfile; $i++)
1504 1504
 			{
1505 1505
 				// Define $destfull (path to file including filename) and $destfile (only filename)
1506
-				$destfull=$upload_dir . "/" . $TFile['name'][$i];
1507
-				$destfile=$TFile['name'][$i];
1506
+				$destfull = $upload_dir."/".$TFile['name'][$i];
1507
+				$destfile = $TFile['name'][$i];
1508 1508
 
1509 1509
 				if ($savingdocmask)
1510 1510
 				{
1511
-					$destfull=$upload_dir . "/" . preg_replace('/__file__/',$TFile['name'][$i],$savingdocmask);
1512
-					$destfile=preg_replace('/__file__/',$TFile['name'][$i],$savingdocmask);
1511
+					$destfull = $upload_dir."/".preg_replace('/__file__/', $TFile['name'][$i], $savingdocmask);
1512
+					$destfile = preg_replace('/__file__/', $TFile['name'][$i], $savingdocmask);
1513 1513
 				}
1514 1514
 
1515 1515
 				// dol_sanitizeFileName the file name and lowercase extension
@@ -1570,7 +1570,7 @@  discard block
 block discarded – undo
1570 1570
 					{
1571 1571
 						setEventMessages($langs->trans("ErrorFileNotUploaded"), null, 'errors');
1572 1572
 					}
1573
-					else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload))	// Files infected by a virus
1573
+					else if (preg_match('/ErrorFileIsInfectedWithAVirus/', $resupload))	// Files infected by a virus
1574 1574
 					{
1575 1575
 						setEventMessages($langs->trans("ErrorFileIsInfectedWithAVirus"), null, 'errors');
1576 1576
 					}
@@ -1587,7 +1587,7 @@  discard block
 block discarded – undo
1587 1587
 			}
1588 1588
 		}
1589 1589
 	} elseif ($link) {
1590
-		require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php';
1590
+		require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
1591 1591
 		$linkObject = new Link($db);
1592 1592
 		$linkObject->entity = $conf->entity;
1593 1593
 		$linkObject->url = $link;
@@ -1622,33 +1622,33 @@  discard block
 block discarded – undo
1622 1622
  * @param   string  $trackid                Track id (used to prefix name of session vars to avoid conflict)
1623 1623
  * @return	void
1624 1624
  */
1625
-function dol_remove_file_process($filenb,$donotupdatesession=0,$donotdeletefile=1,$trackid='')
1625
+function dol_remove_file_process($filenb, $donotupdatesession = 0, $donotdeletefile = 1, $trackid = '')
1626 1626
 {
1627
-	global $db,$user,$conf,$langs,$_FILES;
1627
+	global $db, $user, $conf, $langs, $_FILES;
1628 1628
 
1629
-	$keytodelete=$filenb;
1629
+	$keytodelete = $filenb;
1630 1630
 	$keytodelete--;
1631 1631
 
1632
-	$listofpaths=array();
1633
-	$listofnames=array();
1634
-	$listofmimes=array();
1635
-	$keytoavoidconflict = empty($trackid)?'':'-'.$trackid;
1636
-	if (! empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths=explode(';',$_SESSION["listofpaths".$keytoavoidconflict]);
1637
-	if (! empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames=explode(';',$_SESSION["listofnames".$keytoavoidconflict]);
1638
-	if (! empty($_SESSION["listofmimes".$keytoavoidconflict])) $listofmimes=explode(';',$_SESSION["listofmimes".$keytoavoidconflict]);
1632
+	$listofpaths = array();
1633
+	$listofnames = array();
1634
+	$listofmimes = array();
1635
+	$keytoavoidconflict = empty($trackid) ? '' : '-'.$trackid;
1636
+	if (!empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths = explode(';', $_SESSION["listofpaths".$keytoavoidconflict]);
1637
+	if (!empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames = explode(';', $_SESSION["listofnames".$keytoavoidconflict]);
1638
+	if (!empty($_SESSION["listofmimes".$keytoavoidconflict])) $listofmimes = explode(';', $_SESSION["listofmimes".$keytoavoidconflict]);
1639 1639
 
1640 1640
 	if ($keytodelete >= 0)
1641 1641
 	{
1642
-		$pathtodelete=$listofpaths[$keytodelete];
1643
-		$filetodelete=$listofnames[$keytodelete];
1644
-		if (empty($donotdeletefile)) $result = dol_delete_file($pathtodelete,1);  // The delete of ecm database is inside the function dol_delete_file
1645
-		else $result=0;
1642
+		$pathtodelete = $listofpaths[$keytodelete];
1643
+		$filetodelete = $listofnames[$keytodelete];
1644
+		if (empty($donotdeletefile)) $result = dol_delete_file($pathtodelete, 1); // The delete of ecm database is inside the function dol_delete_file
1645
+		else $result = 0;
1646 1646
 		if ($result >= 0)
1647 1647
 		{
1648 1648
 			if (empty($donotdeletefile))
1649 1649
 			{
1650 1650
 				$langs->load("other");
1651
-				setEventMessages($langs->trans("FileWasRemoved",$filetodelete), null, 'mesgs');
1651
+				setEventMessages($langs->trans("FileWasRemoved", $filetodelete), null, 'mesgs');
1652 1652
 			}
1653 1653
 			if (empty($donotupdatesession))
1654 1654
 			{
@@ -1674,29 +1674,29 @@  discard block
 block discarded – undo
1674 1674
  *  @param		int		$setsharekey	Set also the share key
1675 1675
  *	@return		int						<0 if KO, 0 if nothing done, >0 if OK
1676 1676
  */
1677
-function addFileIntoDatabaseIndex($dir, $file, $fullpathorig='', $mode='uploaded', $setsharekey=0)
1677
+function addFileIntoDatabaseIndex($dir, $file, $fullpathorig = '', $mode = 'uploaded', $setsharekey = 0)
1678 1678
 {
1679 1679
 	global $db, $user;
1680 1680
 
1681 1681
 	$result = 0;
1682 1682
 
1683
-	$rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $dir);
1683
+	$rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $dir);
1684 1684
 
1685
-	if (! preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir))     // If not a tmp dir
1685
+	if (!preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir))     // If not a tmp dir
1686 1686
 	{
1687 1687
 		$filename = basename($file);
1688 1688
 		$rel_dir = preg_replace('/[\\/]$/', '', $rel_dir);
1689 1689
 		$rel_dir = preg_replace('/^[\\/]/', '', $rel_dir);
1690 1690
 
1691 1691
 		include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
1692
-		$ecmfile=new EcmFiles($db);
1692
+		$ecmfile = new EcmFiles($db);
1693 1693
 		$ecmfile->filepath = $rel_dir;
1694 1694
 		$ecmfile->filename = $filename;
1695
-		$ecmfile->label = md5_file(dol_osencode($dir.'/'.$file));	// MD5 of file content
1695
+		$ecmfile->label = md5_file(dol_osencode($dir.'/'.$file)); // MD5 of file content
1696 1696
 		$ecmfile->fullpath_orig = $fullpathorig;
1697 1697
 		$ecmfile->gen_or_uploaded = $mode;
1698
-		$ecmfile->description = '';    // indexed content
1699
-		$ecmfile->keyword = '';        // keyword content
1698
+		$ecmfile->description = ''; // indexed content
1699
+		$ecmfile->keyword = ''; // keyword content
1700 1700
 		if ($setsharekey)
1701 1701
 		{
1702 1702
 			require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
@@ -1722,7 +1722,7 @@  discard block
 block discarded – undo
1722 1722
  *  @param		string	$mode			How file was created ('uploaded', 'generated', ...)
1723 1723
  *	@return		int						<0 if KO, 0 if nothing done, >0 if OK
1724 1724
  */
1725
-function deleteFilesIntoDatabaseIndex($dir, $file, $mode='uploaded')
1725
+function deleteFilesIntoDatabaseIndex($dir, $file, $mode = 'uploaded')
1726 1726
 {
1727 1727
 	global $conf, $db, $user;
1728 1728
 
@@ -1736,32 +1736,32 @@  discard block
 block discarded – undo
1736 1736
 
1737 1737
 	$db->begin();
1738 1738
 
1739
-	$rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $dir);
1739
+	$rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $dir);
1740 1740
 
1741 1741
 	$filename = basename($file);
1742 1742
 	$rel_dir = preg_replace('/[\\/]$/', '', $rel_dir);
1743 1743
 	$rel_dir = preg_replace('/^[\\/]/', '', $rel_dir);
1744 1744
 
1745
-	if (! $error)
1745
+	if (!$error)
1746 1746
 	{
1747
-		$sql = 'DELETE FROM ' . MAIN_DB_PREFIX . 'ecm_files';
1748
-		$sql.= ' WHERE entity = '.$conf->entity;
1749
-		$sql.= " AND filepath = '" . $db->escape($rel_dir) . "'";
1750
-		if ($file) $sql.= " AND filename = '" . $db->escape($file) . "'";
1751
-		if ($mode) $sql.= " AND gen_or_uploaded = '" . $db->escape($mode) . "'";
1747
+		$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'ecm_files';
1748
+		$sql .= ' WHERE entity = '.$conf->entity;
1749
+		$sql .= " AND filepath = '".$db->escape($rel_dir)."'";
1750
+		if ($file) $sql .= " AND filename = '".$db->escape($file)."'";
1751
+		if ($mode) $sql .= " AND gen_or_uploaded = '".$db->escape($mode)."'";
1752 1752
 
1753 1753
 		$resql = $db->query($sql);
1754 1754
 		if (!$resql)
1755 1755
 		{
1756 1756
 			$error++;
1757
-			dol_syslog(__METHOD__ . ' ' . $db->lasterror(), LOG_ERR);
1757
+			dol_syslog(__METHOD__.' '.$db->lasterror(), LOG_ERR);
1758 1758
 		}
1759 1759
 	}
1760 1760
 
1761 1761
 	// Commit or rollback
1762 1762
 	if ($error) {
1763 1763
 		$db->rollback();
1764
-		return - 1 * $error;
1764
+		return -1 * $error;
1765 1765
 	} else {
1766 1766
 		$db->commit();
1767 1767
 		return 1;
@@ -1778,16 +1778,16 @@  discard block
 block discarded – undo
1778 1778
  *  @param	string	$fileoutput	Output filename
1779 1779
  *  @return	int					<0 if KO, 0=Nothing done, >0 if OK
1780 1780
  */
1781
-function dol_convert_file($fileinput, $ext='png', $fileoutput='')
1781
+function dol_convert_file($fileinput, $ext = 'png', $fileoutput = '')
1782 1782
 {
1783 1783
 	global $langs;
1784 1784
 
1785 1785
 	if (class_exists('Imagick'))
1786 1786
 	{
1787
-		$image=new Imagick();
1787
+		$image = new Imagick();
1788 1788
 		try {
1789 1789
 			$ret = $image->readImage($fileinput);
1790
-		} catch(Exception $e) {
1790
+		} catch (Exception $e) {
1791 1791
 			dol_syslog("Failed to read image using Imagick. Try to install package 'apt-get install ghostscript'.", LOG_WARNING);
1792 1792
 			return 0;
1793 1793
 		}
@@ -1796,11 +1796,11 @@  discard block
 block discarded – undo
1796 1796
 			$ret = $image->setImageFormat($ext);
1797 1797
 			if ($ret)
1798 1798
 			{
1799
-				if (empty($fileoutput)) $fileoutput=$fileinput.".".$ext;
1799
+				if (empty($fileoutput)) $fileoutput = $fileinput.".".$ext;
1800 1800
 
1801 1801
 				$count = $image->getNumberImages();
1802 1802
 
1803
-				if (! dol_is_file($fileoutput) || is_writeable($fileoutput))
1803
+				if (!dol_is_file($fileoutput) || is_writeable($fileoutput))
1804 1804
 				{
1805 1805
 					$ret = $image->writeImages($fileoutput, true);
1806 1806
 				}
@@ -1836,20 +1836,20 @@  discard block
 block discarded – undo
1836 1836
  * @param 	string	$mode			'gz' or 'bz' or 'zip'
1837 1837
  * @return	int						<0 if KO, >0 if OK
1838 1838
  */
1839
-function dol_compress_file($inputfile, $outputfile, $mode="gz")
1839
+function dol_compress_file($inputfile, $outputfile, $mode = "gz")
1840 1840
 {
1841
-	$foundhandler=0;
1841
+	$foundhandler = 0;
1842 1842
 
1843 1843
 	try
1844 1844
 	{
1845 1845
 		$data = implode("", file(dol_osencode($inputfile)));
1846
-		if ($mode == 'gz')     { $foundhandler=1; $compressdata = gzencode($data, 9); }
1847
-		elseif ($mode == 'bz') { $foundhandler=1; $compressdata = bzcompress($data, 9); }
1846
+		if ($mode == 'gz') { $foundhandler = 1; $compressdata = gzencode($data, 9); }
1847
+		elseif ($mode == 'bz') { $foundhandler = 1; $compressdata = bzcompress($data, 9); }
1848 1848
 		elseif ($mode == 'zip')
1849 1849
 		{
1850 1850
 			if (defined('ODTPHP_PATHTOPCLZIP'))
1851 1851
 			{
1852
-				$foundhandler=1;
1852
+				$foundhandler = 1;
1853 1853
 
1854 1854
 				include_once ODTPHP_PATHTOPCLZIP.'/pclzip.lib.php';
1855 1855
 				$archive = new PclZip($outputfile);
@@ -1868,7 +1868,7 @@  discard block
 block discarded – undo
1868 1868
 		}
1869 1869
 		else
1870 1870
 		{
1871
-			dol_syslog("Try to zip with format ".$mode." with no handler for this format",LOG_ERR);
1871
+			dol_syslog("Try to zip with format ".$mode." with no handler for this format", LOG_ERR);
1872 1872
 			return -2;
1873 1873
 		}
1874 1874
 	}
@@ -1876,8 +1876,8 @@  discard block
 block discarded – undo
1876 1876
 	{
1877 1877
 		global $langs, $errormsg;
1878 1878
 		$langs->load("errors");
1879
-		dol_syslog("Failed to open file ".$outputfile,LOG_ERR);
1880
-		$errormsg=$langs->trans("ErrorFailedToWriteInDir");
1879
+		dol_syslog("Failed to open file ".$outputfile, LOG_ERR);
1880
+		$errormsg = $langs->trans("ErrorFailedToWriteInDir");
1881 1881
 		return -1;
1882 1882
 	}
1883 1883
 }
@@ -1889,7 +1889,7 @@  discard block
 block discarded – undo
1889 1889
  * @param 	string	$outputdir		Target dir name
1890 1890
  * @return 	array					array('error'=>'Error code') or array() if no error
1891 1891
  */
1892
-function dol_uncompress($inputfile,$outputdir)
1892
+function dol_uncompress($inputfile, $outputdir)
1893 1893
 {
1894 1894
 	global $langs;
1895 1895
 
@@ -1898,20 +1898,20 @@  discard block
 block discarded – undo
1898 1898
 		dol_syslog("Constant ODTPHP_PATHTOPCLZIP for pclzip library is set to ".ODTPHP_PATHTOPCLZIP.", so we use Pclzip to unzip into ".$outputdir);
1899 1899
 		include_once ODTPHP_PATHTOPCLZIP.'/pclzip.lib.php';
1900 1900
 		$archive = new PclZip($inputfile);
1901
-		$result=$archive->extract(PCLZIP_OPT_PATH, $outputdir);
1901
+		$result = $archive->extract(PCLZIP_OPT_PATH, $outputdir);
1902 1902
 		//var_dump($result);
1903
-		if (! is_array($result) && $result <= 0) return array('error'=>$archive->errorInfo(true));
1903
+		if (!is_array($result) && $result <= 0) return array('error'=>$archive->errorInfo(true));
1904 1904
 		else
1905 1905
 		{
1906
-			$ok=1; $errmsg='';
1906
+			$ok = 1; $errmsg = '';
1907 1907
 			// Loop on each file to check result for unzipping file
1908
-			foreach($result as $key => $val)
1908
+			foreach ($result as $key => $val)
1909 1909
 			{
1910 1910
 				if ($val['status'] == 'path_creation_fail')
1911 1911
 				{
1912 1912
 					$langs->load("errors");
1913
-					$ok=0;
1914
-					$errmsg=$langs->trans("ErrorFailToCreateDir", $val['filename']);
1913
+					$ok = 0;
1914
+					$errmsg = $langs->trans("ErrorFailToCreateDir", $val['filename']);
1915 1915
 					break;
1916 1916
 				}
1917 1917
 			}
@@ -1950,24 +1950,24 @@  discard block
 block discarded – undo
1950 1950
  * @param 	string	$mode			'zip'
1951 1951
  * @return	int						<0 if KO, >0 if OK
1952 1952
  */
1953
-function dol_compress_dir($inputdir, $outputfile, $mode="zip")
1953
+function dol_compress_dir($inputdir, $outputfile, $mode = "zip")
1954 1954
 {
1955
-	$foundhandler=0;
1955
+	$foundhandler = 0;
1956 1956
 
1957 1957
 	dol_syslog("Try to zip dir ".$inputdir." into ".$outputdir." mode=".$mode);
1958 1958
 
1959
-	if (! dol_is_dir(dirname($outputfile)) || ! is_writable(dirname($outputfile)))
1959
+	if (!dol_is_dir(dirname($outputfile)) || !is_writable(dirname($outputfile)))
1960 1960
 	{
1961 1961
 		global $langs, $errormsg;
1962 1962
 		$langs->load("errors");
1963
-		$errormsg=$langs->trans("ErrorFailedToWriteInDir",$outputfile);
1963
+		$errormsg = $langs->trans("ErrorFailedToWriteInDir", $outputfile);
1964 1964
 		return -3;
1965 1965
 	}
1966 1966
 
1967 1967
 	try
1968 1968
 	{
1969
-		if ($mode == 'gz')     { $foundhandler=0; }
1970
-		elseif ($mode == 'bz') { $foundhandler=0; }
1969
+		if ($mode == 'gz') { $foundhandler = 0; }
1970
+		elseif ($mode == 'bz') { $foundhandler = 0; }
1971 1971
 		elseif ($mode == 'zip')
1972 1972
 		{
1973 1973
 			/*if (defined('ODTPHP_PATHTOPCLZIP'))
@@ -1983,7 +1983,7 @@  discard block
 block discarded – undo
1983 1983
             else*/
1984 1984
 			if (class_exists('ZipArchive'))
1985 1985
 			{
1986
-				$foundhandler=1;
1986
+				$foundhandler = 1;
1987 1987
 
1988 1988
 				// Initialize archive object
1989 1989
 				$zip = new ZipArchive();
@@ -2017,9 +2017,9 @@  discard block
 block discarded – undo
2017 2017
 			}
2018 2018
 		}
2019 2019
 
2020
-		if (! $foundhandler)
2020
+		if (!$foundhandler)
2021 2021
 		{
2022
-			dol_syslog("Try to zip with format ".$mode." with no handler for this format",LOG_ERR);
2022
+			dol_syslog("Try to zip with format ".$mode." with no handler for this format", LOG_ERR);
2023 2023
 			return -2;
2024 2024
 		}
2025 2025
 		else
@@ -2033,7 +2033,7 @@  discard block
 block discarded – undo
2033 2033
 		$langs->load("errors");
2034 2034
 		dol_syslog("Failed to open file ".$outputfile, LOG_ERR);
2035 2035
 		dol_syslog($e->getMessage(), LOG_ERR);
2036
-		$errormsg=$langs->trans("ErrorFailedToWriteInDir",$outputfile);
2036
+		$errormsg = $langs->trans("ErrorFailedToWriteInDir", $outputfile);
2037 2037
 		return -1;
2038 2038
 	}
2039 2039
 }
@@ -2050,9 +2050,9 @@  discard block
 block discarded – undo
2050 2050
  * @param	int			$mode			0=Return array minimum keys loaded (faster), 1=Force all keys like date and size to be loaded (slower), 2=Force load of date only, 3=Force load of size only
2051 2051
  * @return	string						Full path to most recent file
2052 2052
  */
2053
-function dol_most_recent_file($dir,$regexfilter='',$excludefilter=array('(\.meta|_preview.*\.png)$','^\.'),$nohook=false,$mode='')
2053
+function dol_most_recent_file($dir, $regexfilter = '', $excludefilter = array('(\.meta|_preview.*\.png)$', '^\.'), $nohook = false, $mode = '')
2054 2054
 {
2055
-	$tmparray=dol_dir_list($dir,'files',0,$regexfilter,$excludefilter,'date',SORT_DESC,$mode,$nohook);
2055
+	$tmparray = dol_dir_list($dir, 'files', 0, $regexfilter, $excludefilter, 'date', SORT_DESC, $mode, $nohook);
2056 2056
 	return $tmparray[0];
2057 2057
 }
2058 2058
 
@@ -2068,275 +2068,275 @@  discard block
 block discarded – undo
2068 2068
  * @return	mixed						Array with access information : 'accessallowed' & 'sqlprotectagainstexternals' & 'original_file' (as a full path name)
2069 2069
  * @see restrictedArea
2070 2070
  */
2071
-function dol_check_secure_access_document($modulepart, $original_file, $entity, $fuser='', $refname='', $mode='read')
2071
+function dol_check_secure_access_document($modulepart, $original_file, $entity, $fuser = '', $refname = '', $mode = 'read')
2072 2072
 {
2073 2073
 	global $conf, $db, $user;
2074 2074
 	global $dolibarr_main_data_root, $dolibarr_main_document_root_alt;
2075 2075
 
2076
-	if (! is_object($fuser)) $fuser=$user;
2076
+	if (!is_object($fuser)) $fuser = $user;
2077 2077
 
2078 2078
 	if (empty($modulepart)) return 'ErrorBadParameter';
2079 2079
 	if (empty($entity))
2080 2080
 	{
2081
-		if (empty($conf->multicompany->enabled)) $entity=1;
2082
-		else $entity=0;
2081
+		if (empty($conf->multicompany->enabled)) $entity = 1;
2082
+		else $entity = 0;
2083 2083
 	}
2084 2084
 	dol_syslog('modulepart='.$modulepart.' original_file='.$original_file.' entity='.$entity);
2085 2085
 	// We define $accessallowed and $sqlprotectagainstexternals
2086
-	$accessallowed=0;
2087
-	$sqlprotectagainstexternals='';
2088
-	$ret=array();
2086
+	$accessallowed = 0;
2087
+	$sqlprotectagainstexternals = '';
2088
+	$ret = array();
2089 2089
 
2090 2090
 	// Find the subdirectory name as the reference. For exemple original_file='10/myfile.pdf' -> refname='10'
2091
-	if (empty($refname)) $refname=basename(dirname($original_file)."/");
2091
+	if (empty($refname)) $refname = basename(dirname($original_file)."/");
2092 2092
 
2093 2093
 	$relative_original_file = $original_file;
2094 2094
 
2095 2095
 	// Define possible keys to use for permission check
2096
-	$lire='lire'; $read='read'; $download='download';
2096
+	$lire = 'lire'; $read = 'read'; $download = 'download';
2097 2097
 	if ($mode == 'write')
2098 2098
 	{
2099
-		$lire='creer'; $read='write'; $download='upload';
2099
+		$lire = 'creer'; $read = 'write'; $download = 'upload';
2100 2100
 	}
2101 2101
 
2102 2102
 	// Wrapping for miscellaneous medias files
2103 2103
 	if ($modulepart == 'medias' && !empty($dolibarr_main_data_root))
2104 2104
 	{
2105 2105
 		if (empty($entity) || empty($conf->medias->multidir_output[$entity])) return array('accessallowed'=>0, 'error'=>'Value entity must be provided');
2106
-		$accessallowed=1;
2107
-		$original_file=$conf->medias->multidir_output[$entity].'/'.$original_file;
2106
+		$accessallowed = 1;
2107
+		$original_file = $conf->medias->multidir_output[$entity].'/'.$original_file;
2108 2108
 	}
2109 2109
 	// Wrapping for *.log files, like when used with url http://.../document.php?modulepart=logs&file=dolibarr.log
2110 2110
 	elseif ($modulepart == 'logs' && !empty($dolibarr_main_data_root))
2111 2111
 	{
2112
-		$accessallowed=($user->admin && basename($original_file) == $original_file && preg_match('/^dolibarr.*\.log$/', basename($original_file)));
2113
-		$original_file=$dolibarr_main_data_root.'/'.$original_file;
2112
+		$accessallowed = ($user->admin && basename($original_file) == $original_file && preg_match('/^dolibarr.*\.log$/', basename($original_file)));
2113
+		$original_file = $dolibarr_main_data_root.'/'.$original_file;
2114 2114
 	}
2115 2115
 	// Wrapping for *.zip files, like when used with url http://.../document.php?modulepart=packages&file=module_myfile.zip
2116 2116
 	elseif ($modulepart == 'packages' && !empty($dolibarr_main_data_root))
2117 2117
 	{
2118 2118
 		// Dir for custom dirs
2119
-		$tmp=explode(',', $dolibarr_main_document_root_alt);
2119
+		$tmp = explode(',', $dolibarr_main_document_root_alt);
2120 2120
 		$dirins = $tmp[0];
2121 2121
 
2122
-		$accessallowed=($user->admin && preg_match('/^module_.*\.zip$/', basename($original_file)));
2123
-		$original_file=$dirins.'/'.$original_file;
2122
+		$accessallowed = ($user->admin && preg_match('/^module_.*\.zip$/', basename($original_file)));
2123
+		$original_file = $dirins.'/'.$original_file;
2124 2124
 	}
2125 2125
 	// Wrapping for some images
2126 2126
 	elseif (($modulepart == 'mycompany' || $modulepart == 'companylogo') && !empty($conf->mycompany->dir_output))
2127 2127
 	{
2128
-		$accessallowed=1;
2129
-		$original_file=$conf->mycompany->dir_output.'/logos/'.$original_file;
2128
+		$accessallowed = 1;
2129
+		$original_file = $conf->mycompany->dir_output.'/logos/'.$original_file;
2130 2130
 	}
2131 2131
 	// Wrapping for users photos
2132 2132
 	elseif ($modulepart == 'userphoto' && !empty($conf->user->dir_output))
2133 2133
 	{
2134
-		$accessallowed=1;
2135
-		$original_file=$conf->user->dir_output.'/'.$original_file;
2134
+		$accessallowed = 1;
2135
+		$original_file = $conf->user->dir_output.'/'.$original_file;
2136 2136
 	}
2137 2137
 	// Wrapping for members photos
2138 2138
 	elseif ($modulepart == 'memberphoto' && !empty($conf->adherent->dir_output))
2139 2139
 	{
2140
-		$accessallowed=1;
2141
-		$original_file=$conf->adherent->dir_output.'/'.$original_file;
2140
+		$accessallowed = 1;
2141
+		$original_file = $conf->adherent->dir_output.'/'.$original_file;
2142 2142
 	}
2143 2143
 	// Wrapping pour les apercu factures
2144 2144
 	elseif ($modulepart == 'apercufacture' && !empty($conf->facture->dir_output))
2145 2145
 	{
2146
-		if ($fuser->rights->facture->{$lire}) $accessallowed=1;
2147
-		$original_file=$conf->facture->dir_output.'/'.$original_file;
2146
+		if ($fuser->rights->facture->{$lire}) $accessallowed = 1;
2147
+		$original_file = $conf->facture->dir_output.'/'.$original_file;
2148 2148
 	}
2149 2149
 	// Wrapping pour les apercu propal
2150 2150
 	elseif ($modulepart == 'apercupropal' && !empty($conf->propal->dir_output))
2151 2151
 	{
2152
-		if ($fuser->rights->propale->{$lire}) $accessallowed=1;
2153
-		$original_file=$conf->propal->dir_output.'/'.$original_file;
2152
+		if ($fuser->rights->propale->{$lire}) $accessallowed = 1;
2153
+		$original_file = $conf->propal->dir_output.'/'.$original_file;
2154 2154
 	}
2155 2155
 	// Wrapping pour les apercu commande
2156 2156
 	elseif ($modulepart == 'apercucommande' && !empty($conf->commande->dir_output))
2157 2157
 	{
2158
-		if ($fuser->rights->commande->{$lire}) $accessallowed=1;
2159
-		$original_file=$conf->commande->dir_output.'/'.$original_file;
2158
+		if ($fuser->rights->commande->{$lire}) $accessallowed = 1;
2159
+		$original_file = $conf->commande->dir_output.'/'.$original_file;
2160 2160
 	}
2161 2161
 	// Wrapping pour les apercu intervention
2162 2162
 	elseif (($modulepart == 'apercufichinter' || $modulepart == 'apercuficheinter') && !empty($conf->ficheinter->dir_output))
2163 2163
 	{
2164
-		if ($fuser->rights->ficheinter->{$lire}) $accessallowed=1;
2165
-		$original_file=$conf->ficheinter->dir_output.'/'.$original_file;
2164
+		if ($fuser->rights->ficheinter->{$lire}) $accessallowed = 1;
2165
+		$original_file = $conf->ficheinter->dir_output.'/'.$original_file;
2166 2166
 	}
2167 2167
 	// Wrapping pour les apercu conat
2168 2168
 	elseif (($modulepart == 'apercucontract') && !empty($conf->contrat->dir_output))
2169 2169
 	{
2170
-		if ($fuser->rights->contrat->{$lire}) $accessallowed=1;
2171
-		$original_file=$conf->contrat->dir_output.'/'.$original_file;
2170
+		if ($fuser->rights->contrat->{$lire}) $accessallowed = 1;
2171
+		$original_file = $conf->contrat->dir_output.'/'.$original_file;
2172 2172
 	}
2173 2173
 	// Wrapping pour les apercu supplier proposal
2174 2174
 	elseif (($modulepart == 'apercusupplier_proposal' || $modulepart == 'apercusupplier_proposal') && !empty($conf->supplier_proposal->dir_output))
2175 2175
 	{
2176
-		if ($fuser->rights->supplier_proposal->{$lire}) $accessallowed=1;
2177
-		$original_file=$conf->supplier_proposal->dir_output.'/'.$original_file;
2176
+		if ($fuser->rights->supplier_proposal->{$lire}) $accessallowed = 1;
2177
+		$original_file = $conf->supplier_proposal->dir_output.'/'.$original_file;
2178 2178
 	}
2179 2179
 	// Wrapping pour les apercu supplier order
2180 2180
 	elseif (($modulepart == 'apercusupplier_order' || $modulepart == 'apercusupplier_order') && !empty($conf->fournisseur->commande->dir_output))
2181 2181
 	{
2182
-		if ($fuser->rights->fournisseur->commande->{$lire}) $accessallowed=1;
2183
-		$original_file=$conf->fournisseur->commande->dir_output.'/'.$original_file;
2182
+		if ($fuser->rights->fournisseur->commande->{$lire}) $accessallowed = 1;
2183
+		$original_file = $conf->fournisseur->commande->dir_output.'/'.$original_file;
2184 2184
 	}
2185 2185
 	// Wrapping pour les apercu supplier invoice
2186 2186
 	elseif (($modulepart == 'apercusupplier_invoice' || $modulepart == 'apercusupplier_invoice') && !empty($conf->fournisseur->facture->dir_output))
2187 2187
 	{
2188
-		if ($fuser->rights->fournisseur->facture->{$lire}) $accessallowed=1;
2189
-		$original_file=$conf->fournisseur->facture->dir_output.'/'.$original_file;
2188
+		if ($fuser->rights->fournisseur->facture->{$lire}) $accessallowed = 1;
2189
+		$original_file = $conf->fournisseur->facture->dir_output.'/'.$original_file;
2190 2190
 	}
2191 2191
 	// Wrapping pour les apercu supplier invoice
2192 2192
 	elseif (($modulepart == 'apercuexpensereport') && !empty($conf->expensereport->dir_output))
2193 2193
 	{
2194
-		if ($fuser->rights->expensereport->{$lire}) $accessallowed=1;
2195
-		$original_file=$conf->expensereport->dir_output.'/'.$original_file;
2194
+		if ($fuser->rights->expensereport->{$lire}) $accessallowed = 1;
2195
+		$original_file = $conf->expensereport->dir_output.'/'.$original_file;
2196 2196
 	}
2197 2197
 	// Wrapping pour les images des stats propales
2198 2198
 	elseif ($modulepart == 'propalstats' && !empty($conf->propal->dir_temp))
2199 2199
 	{
2200
-		if ($fuser->rights->propale->{$lire}) $accessallowed=1;
2201
-		$original_file=$conf->propal->dir_temp.'/'.$original_file;
2200
+		if ($fuser->rights->propale->{$lire}) $accessallowed = 1;
2201
+		$original_file = $conf->propal->dir_temp.'/'.$original_file;
2202 2202
 	}
2203 2203
 	// Wrapping pour les images des stats commandes
2204 2204
 	elseif ($modulepart == 'orderstats' && !empty($conf->commande->dir_temp))
2205 2205
 	{
2206
-		if ($fuser->rights->commande->{$lire}) $accessallowed=1;
2207
-		$original_file=$conf->commande->dir_temp.'/'.$original_file;
2206
+		if ($fuser->rights->commande->{$lire}) $accessallowed = 1;
2207
+		$original_file = $conf->commande->dir_temp.'/'.$original_file;
2208 2208
 	}
2209 2209
 	elseif ($modulepart == 'orderstatssupplier' && !empty($conf->fournisseur->dir_output))
2210 2210
 	{
2211
-		if ($fuser->rights->fournisseur->commande->{$lire}) $accessallowed=1;
2212
-		$original_file=$conf->fournisseur->commande->dir_temp.'/'.$original_file;
2211
+		if ($fuser->rights->fournisseur->commande->{$lire}) $accessallowed = 1;
2212
+		$original_file = $conf->fournisseur->commande->dir_temp.'/'.$original_file;
2213 2213
 	}
2214 2214
 	// Wrapping pour les images des stats factures
2215 2215
 	elseif ($modulepart == 'billstats' && !empty($conf->facture->dir_temp))
2216 2216
 	{
2217
-		if ($fuser->rights->facture->{$lire}) $accessallowed=1;
2218
-		$original_file=$conf->facture->dir_temp.'/'.$original_file;
2217
+		if ($fuser->rights->facture->{$lire}) $accessallowed = 1;
2218
+		$original_file = $conf->facture->dir_temp.'/'.$original_file;
2219 2219
 	}
2220 2220
 	elseif ($modulepart == 'billstatssupplier' && !empty($conf->fournisseur->dir_output))
2221 2221
 	{
2222
-		if ($fuser->rights->fournisseur->facture->{$lire}) $accessallowed=1;
2223
-		$original_file=$conf->fournisseur->facture->dir_temp.'/'.$original_file;
2222
+		if ($fuser->rights->fournisseur->facture->{$lire}) $accessallowed = 1;
2223
+		$original_file = $conf->fournisseur->facture->dir_temp.'/'.$original_file;
2224 2224
 	}
2225 2225
 	// Wrapping pour les images des stats expeditions
2226 2226
 	elseif ($modulepart == 'expeditionstats' && !empty($conf->expedition->dir_temp))
2227 2227
 	{
2228
-		if ($fuser->rights->expedition->{$lire}) $accessallowed=1;
2229
-		$original_file=$conf->expedition->dir_temp.'/'.$original_file;
2228
+		if ($fuser->rights->expedition->{$lire}) $accessallowed = 1;
2229
+		$original_file = $conf->expedition->dir_temp.'/'.$original_file;
2230 2230
 	}
2231 2231
 	// Wrapping pour les images des stats expeditions
2232 2232
 	elseif ($modulepart == 'tripsexpensesstats' && !empty($conf->deplacement->dir_temp))
2233 2233
 	{
2234
-		if ($fuser->rights->deplacement->{$lire}) $accessallowed=1;
2235
-		$original_file=$conf->deplacement->dir_temp.'/'.$original_file;
2234
+		if ($fuser->rights->deplacement->{$lire}) $accessallowed = 1;
2235
+		$original_file = $conf->deplacement->dir_temp.'/'.$original_file;
2236 2236
 	}
2237 2237
 	// Wrapping pour les images des stats expeditions
2238 2238
 	elseif ($modulepart == 'memberstats' && !empty($conf->adherent->dir_temp))
2239 2239
 	{
2240
-		if ($fuser->rights->adherent->{$lire}) $accessallowed=1;
2241
-		$original_file=$conf->adherent->dir_temp.'/'.$original_file;
2240
+		if ($fuser->rights->adherent->{$lire}) $accessallowed = 1;
2241
+		$original_file = $conf->adherent->dir_temp.'/'.$original_file;
2242 2242
 	}
2243 2243
 	// Wrapping pour les images des stats produits
2244
-	elseif (preg_match('/^productstats_/i',$modulepart) && !empty($conf->product->dir_temp))
2244
+	elseif (preg_match('/^productstats_/i', $modulepart) && !empty($conf->product->dir_temp))
2245 2245
 	{
2246
-		if ($fuser->rights->produit->{$lire} || $fuser->rights->service->{$lire}) $accessallowed=1;
2247
-		$original_file=(!empty($conf->product->multidir_temp[$entity])?$conf->product->multidir_temp[$entity]:$conf->service->multidir_temp[$entity]).'/'.$original_file;
2246
+		if ($fuser->rights->produit->{$lire} || $fuser->rights->service->{$lire}) $accessallowed = 1;
2247
+		$original_file = (!empty($conf->product->multidir_temp[$entity]) ? $conf->product->multidir_temp[$entity] : $conf->service->multidir_temp[$entity]).'/'.$original_file;
2248 2248
 	}
2249 2249
 	// Wrapping for taxes
2250 2250
 	elseif ($modulepart == 'tax' && !empty($conf->tax->dir_output))
2251 2251
 	{
2252
-		if ($fuser->rights->tax->charges->{$lire}) $accessallowed=1;
2253
-		$original_file=$conf->tax->dir_output.'/'.$original_file;
2252
+		if ($fuser->rights->tax->charges->{$lire}) $accessallowed = 1;
2253
+		$original_file = $conf->tax->dir_output.'/'.$original_file;
2254 2254
 	}
2255 2255
 	// Wrapping for events
2256 2256
 	elseif ($modulepart == 'actions' && !empty($conf->agenda->dir_output))
2257 2257
 	{
2258
-		if ($fuser->rights->agenda->myactions->{$read}) $accessallowed=1;
2259
-		$original_file=$conf->agenda->dir_output.'/'.$original_file;
2258
+		if ($fuser->rights->agenda->myactions->{$read}) $accessallowed = 1;
2259
+		$original_file = $conf->agenda->dir_output.'/'.$original_file;
2260 2260
 	}
2261 2261
 	// Wrapping for categories
2262 2262
 	elseif ($modulepart == 'category' && !empty($conf->categorie->dir_output))
2263 2263
 	{
2264 2264
 		if (empty($entity) || empty($conf->categorie->multidir_output[$entity])) return array('accessallowed'=>0, 'error'=>'Value entity must be provided');
2265
-		if ($fuser->rights->categorie->{$lire}) $accessallowed=1;
2266
-		$original_file=$conf->categorie->multidir_output[$entity].'/'.$original_file;
2265
+		if ($fuser->rights->categorie->{$lire}) $accessallowed = 1;
2266
+		$original_file = $conf->categorie->multidir_output[$entity].'/'.$original_file;
2267 2267
 	}
2268 2268
 	// Wrapping pour les prelevements
2269 2269
 	elseif ($modulepart == 'prelevement' && !empty($conf->prelevement->dir_output))
2270 2270
 	{
2271
-		if ($fuser->rights->prelevement->bons->{$lire} || preg_match('/^specimen/i',$original_file)) $accessallowed=1;
2272
-		$original_file=$conf->prelevement->dir_output.'/'.$original_file;
2271
+		if ($fuser->rights->prelevement->bons->{$lire} || preg_match('/^specimen/i', $original_file)) $accessallowed = 1;
2272
+		$original_file = $conf->prelevement->dir_output.'/'.$original_file;
2273 2273
 	}
2274 2274
 	// Wrapping pour les graph energie
2275 2275
 	elseif ($modulepart == 'graph_stock' && !empty($conf->stock->dir_temp))
2276 2276
 	{
2277
-		$accessallowed=1;
2278
-		$original_file=$conf->stock->dir_temp.'/'.$original_file;
2277
+		$accessallowed = 1;
2278
+		$original_file = $conf->stock->dir_temp.'/'.$original_file;
2279 2279
 	}
2280 2280
 	// Wrapping pour les graph fournisseurs
2281 2281
 	elseif ($modulepart == 'graph_fourn' && !empty($conf->fournisseur->dir_temp))
2282 2282
 	{
2283
-		$accessallowed=1;
2284
-		$original_file=$conf->fournisseur->dir_temp.'/'.$original_file;
2283
+		$accessallowed = 1;
2284
+		$original_file = $conf->fournisseur->dir_temp.'/'.$original_file;
2285 2285
 	}
2286 2286
 	// Wrapping pour les graph des produits
2287 2287
 	elseif ($modulepart == 'graph_product' && !empty($conf->product->dir_temp))
2288 2288
 	{
2289
-		$accessallowed=1;
2290
-		$original_file=$conf->product->multidir_temp[$entity].'/'.$original_file;
2289
+		$accessallowed = 1;
2290
+		$original_file = $conf->product->multidir_temp[$entity].'/'.$original_file;
2291 2291
 	}
2292 2292
 	// Wrapping pour les code barre
2293 2293
 	elseif ($modulepart == 'barcode')
2294 2294
 	{
2295
-		$accessallowed=1;
2295
+		$accessallowed = 1;
2296 2296
 		// If viewimage is called for barcode, we try to output an image on the fly, with no build of file on disk.
2297 2297
 		//$original_file=$conf->barcode->dir_temp.'/'.$original_file;
2298
-		$original_file='';
2298
+		$original_file = '';
2299 2299
 	}
2300 2300
 	// Wrapping pour les icones de background des mailings
2301 2301
 	elseif ($modulepart == 'iconmailing' && !empty($conf->mailing->dir_temp))
2302 2302
 	{
2303
-		$accessallowed=1;
2304
-		$original_file=$conf->mailing->dir_temp.'/'.$original_file;
2303
+		$accessallowed = 1;
2304
+		$original_file = $conf->mailing->dir_temp.'/'.$original_file;
2305 2305
 	}
2306 2306
 	// Wrapping pour le scanner
2307 2307
 	elseif ($modulepart == 'scanner_user_temp' && !empty($conf->scanner->dir_temp))
2308 2308
 	{
2309
-		$accessallowed=1;
2310
-		$original_file=$conf->scanner->dir_temp.'/'.$fuser->id.'/'.$original_file;
2309
+		$accessallowed = 1;
2310
+		$original_file = $conf->scanner->dir_temp.'/'.$fuser->id.'/'.$original_file;
2311 2311
 	}
2312 2312
 	// Wrapping pour les images fckeditor
2313 2313
 	elseif ($modulepart == 'fckeditor' && !empty($conf->fckeditor->dir_output))
2314 2314
 	{
2315
-		$accessallowed=1;
2316
-		$original_file=$conf->fckeditor->dir_output.'/'.$original_file;
2315
+		$accessallowed = 1;
2316
+		$original_file = $conf->fckeditor->dir_output.'/'.$original_file;
2317 2317
 	}
2318 2318
 
2319 2319
 	// Wrapping for users
2320 2320
 	else if ($modulepart == 'user' && !empty($conf->user->dir_output))
2321 2321
 	{
2322
-		$canreaduser=(! empty($fuser->admin) || $fuser->rights->user->user->{$lire});
2323
-		if ($fuser->id == (int) $refname) { $canreaduser=1; } // A user can always read its own card
2324
-		if ($canreaduser || preg_match('/^specimen/i',$original_file))
2322
+		$canreaduser = (!empty($fuser->admin) || $fuser->rights->user->user->{$lire});
2323
+		if ($fuser->id == (int) $refname) { $canreaduser = 1; } // A user can always read its own card
2324
+		if ($canreaduser || preg_match('/^specimen/i', $original_file))
2325 2325
 		{
2326
-			$accessallowed=1;
2326
+			$accessallowed = 1;
2327 2327
 		}
2328
-		$original_file=$conf->user->dir_output.'/'.$original_file;
2328
+		$original_file = $conf->user->dir_output.'/'.$original_file;
2329 2329
 	}
2330 2330
 
2331 2331
 	// Wrapping for third parties
2332 2332
 	else if (($modulepart == 'company' || $modulepart == 'societe') && !empty($conf->societe->dir_output))
2333 2333
 	{
2334 2334
 		if (empty($entity) || empty($conf->societe->multidir_output[$entity])) return array('accessallowed'=>0, 'error'=>'Value entity must be provided');
2335
-		if ($fuser->rights->societe->{$lire} || preg_match('/^specimen/i',$original_file))
2335
+		if ($fuser->rights->societe->{$lire} || preg_match('/^specimen/i', $original_file))
2336 2336
 		{
2337
-			$accessallowed=1;
2337
+			$accessallowed = 1;
2338 2338
 		}
2339
-		$original_file=$conf->societe->multidir_output[$entity].'/'.$original_file;
2339
+		$original_file = $conf->societe->multidir_output[$entity].'/'.$original_file;
2340 2340
 		$sqlprotectagainstexternals = "SELECT rowid as fk_soc FROM ".MAIN_DB_PREFIX."societe WHERE rowid='".$db->escape($refname)."' AND entity IN (".getEntity('societe').")";
2341 2341
 	}
2342 2342
 
@@ -2346,247 +2346,247 @@  discard block
 block discarded – undo
2346 2346
 		if (empty($entity) || empty($conf->societe->multidir_output[$entity])) return array('accessallowed'=>0, 'error'=>'Value entity must be provided');
2347 2347
 		if ($fuser->rights->societe->{$lire})
2348 2348
 		{
2349
-			$accessallowed=1;
2349
+			$accessallowed = 1;
2350 2350
 		}
2351
-		$original_file=$conf->societe->multidir_output[$entity].'/contact/'.$original_file;
2351
+		$original_file = $conf->societe->multidir_output[$entity].'/contact/'.$original_file;
2352 2352
 	}
2353 2353
 
2354 2354
 	// Wrapping for invoices
2355 2355
 	else if (($modulepart == 'facture' || $modulepart == 'invoice') && !empty($conf->facture->dir_output))
2356 2356
 	{
2357
-		if ($fuser->rights->facture->{$lire} || preg_match('/^specimen/i',$original_file))
2357
+		if ($fuser->rights->facture->{$lire} || preg_match('/^specimen/i', $original_file))
2358 2358
 		{
2359
-			$accessallowed=1;
2359
+			$accessallowed = 1;
2360 2360
 		}
2361
-		$original_file=$conf->facture->dir_output.'/'.$original_file;
2361
+		$original_file = $conf->facture->dir_output.'/'.$original_file;
2362 2362
 		$sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."facture WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity;
2363 2363
 	}
2364 2364
 	// Wrapping for mass actions
2365 2365
 	else if ($modulepart == 'massfilesarea_proposals' && !empty($conf->propal->dir_output))
2366 2366
 	{
2367
-		if ($fuser->rights->propal->{$lire} || preg_match('/^specimen/i',$original_file))
2367
+		if ($fuser->rights->propal->{$lire} || preg_match('/^specimen/i', $original_file))
2368 2368
 		{
2369
-			$accessallowed=1;
2369
+			$accessallowed = 1;
2370 2370
 		}
2371
-		$original_file=$conf->propal->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2371
+		$original_file = $conf->propal->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2372 2372
 	}
2373 2373
 	else if ($modulepart == 'massfilesarea_orders')
2374 2374
 	{
2375
-		if ($fuser->rights->commande->{$lire} || preg_match('/^specimen/i',$original_file))
2375
+		if ($fuser->rights->commande->{$lire} || preg_match('/^specimen/i', $original_file))
2376 2376
 		{
2377
-			$accessallowed=1;
2377
+			$accessallowed = 1;
2378 2378
 		}
2379
-		$original_file=$conf->commande->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2379
+		$original_file = $conf->commande->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2380 2380
 	}
2381 2381
 	else if ($modulepart == 'massfilesarea_invoices')
2382 2382
 	{
2383
-		if ($fuser->rights->facture->{$lire} || preg_match('/^specimen/i',$original_file))
2383
+		if ($fuser->rights->facture->{$lire} || preg_match('/^specimen/i', $original_file))
2384 2384
 		{
2385
-			$accessallowed=1;
2385
+			$accessallowed = 1;
2386 2386
 		}
2387
-		$original_file=$conf->facture->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2387
+		$original_file = $conf->facture->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2388 2388
 	}
2389 2389
 	else if ($modulepart == 'massfilesarea_expensereport')
2390 2390
 	{
2391
-		if ($fuser->rights->facture->{$lire} || preg_match('/^specimen/i',$original_file))
2391
+		if ($fuser->rights->facture->{$lire} || preg_match('/^specimen/i', $original_file))
2392 2392
 		{
2393
-			$accessallowed=1;
2393
+			$accessallowed = 1;
2394 2394
 		}
2395
-		$original_file=$conf->expensereport->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2395
+		$original_file = $conf->expensereport->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2396 2396
 	}
2397 2397
 	else if ($modulepart == 'massfilesarea_interventions')
2398 2398
 	{
2399
-		if ($fuser->rights->ficheinter->{$lire} || preg_match('/^specimen/i',$original_file))
2399
+		if ($fuser->rights->ficheinter->{$lire} || preg_match('/^specimen/i', $original_file))
2400 2400
 		{
2401
-			$accessallowed=1;
2401
+			$accessallowed = 1;
2402 2402
 		}
2403
-		$original_file=$conf->ficheinter->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2403
+		$original_file = $conf->ficheinter->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2404 2404
 	}
2405 2405
 	else if ($modulepart == 'massfilesarea_supplier_proposal' && !empty($conf->propal->dir_output))
2406 2406
 	{
2407
-		if ($fuser->rights->supplier_proposal->{$lire} || preg_match('/^specimen/i',$original_file))
2407
+		if ($fuser->rights->supplier_proposal->{$lire} || preg_match('/^specimen/i', $original_file))
2408 2408
 		{
2409
-			$accessallowed=1;
2409
+			$accessallowed = 1;
2410 2410
 		}
2411
-		$original_file=$conf->supplier_proposal->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2411
+		$original_file = $conf->supplier_proposal->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2412 2412
 	}
2413 2413
 	else if ($modulepart == 'massfilesarea_supplier_order')
2414 2414
 	{
2415
-		if ($fuser->rights->fournisseur->commande->{$lire} || preg_match('/^specimen/i',$original_file))
2415
+		if ($fuser->rights->fournisseur->commande->{$lire} || preg_match('/^specimen/i', $original_file))
2416 2416
 		{
2417
-			$accessallowed=1;
2417
+			$accessallowed = 1;
2418 2418
 		}
2419
-		$original_file=$conf->fournisseur->commande->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2419
+		$original_file = $conf->fournisseur->commande->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2420 2420
 	}
2421 2421
 	else if ($modulepart == 'massfilesarea_supplier_invoice')
2422 2422
 	{
2423
-		if ($fuser->rights->fournisseur->facture->{$lire} || preg_match('/^specimen/i',$original_file))
2423
+		if ($fuser->rights->fournisseur->facture->{$lire} || preg_match('/^specimen/i', $original_file))
2424 2424
 		{
2425
-			$accessallowed=1;
2425
+			$accessallowed = 1;
2426 2426
 		}
2427
-		$original_file=$conf->fournisseur->facture->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2427
+		$original_file = $conf->fournisseur->facture->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2428 2428
 	}
2429 2429
 	else if ($modulepart == 'massfilesarea_contract' && !empty($conf->contrat->dir_output))
2430 2430
 	{
2431
-		if ($fuser->rights->contrat->{$lire} || preg_match('/^specimen/i',$original_file))
2431
+		if ($fuser->rights->contrat->{$lire} || preg_match('/^specimen/i', $original_file))
2432 2432
 		{
2433
-			$accessallowed=1;
2433
+			$accessallowed = 1;
2434 2434
 		}
2435
-		$original_file=$conf->contrat->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2435
+		$original_file = $conf->contrat->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2436 2436
 	}
2437 2437
 
2438 2438
 	// Wrapping for interventions
2439 2439
 	else if (($modulepart == 'fichinter' || $modulepart == 'ficheinter') && !empty($conf->ficheinter->dir_output))
2440 2440
 	{
2441
-		if ($fuser->rights->ficheinter->{$lire} || preg_match('/^specimen/i',$original_file))
2441
+		if ($fuser->rights->ficheinter->{$lire} || preg_match('/^specimen/i', $original_file))
2442 2442
 		{
2443
-			$accessallowed=1;
2443
+			$accessallowed = 1;
2444 2444
 		}
2445
-		$original_file=$conf->ficheinter->dir_output.'/'.$original_file;
2445
+		$original_file = $conf->ficheinter->dir_output.'/'.$original_file;
2446 2446
 		$sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."fichinter WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity;
2447 2447
 	}
2448 2448
 
2449 2449
 	// Wrapping pour les deplacements et notes de frais
2450 2450
 	else if ($modulepart == 'deplacement' && !empty($conf->deplacement->dir_output))
2451 2451
 	{
2452
-		if ($fuser->rights->deplacement->{$lire} || preg_match('/^specimen/i',$original_file))
2452
+		if ($fuser->rights->deplacement->{$lire} || preg_match('/^specimen/i', $original_file))
2453 2453
 		{
2454
-			$accessallowed=1;
2454
+			$accessallowed = 1;
2455 2455
 		}
2456
-		$original_file=$conf->deplacement->dir_output.'/'.$original_file;
2456
+		$original_file = $conf->deplacement->dir_output.'/'.$original_file;
2457 2457
 		//$sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."fichinter WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity;
2458 2458
 	}
2459 2459
 	// Wrapping pour les propales
2460 2460
 	else if ($modulepart == 'propal' && !empty($conf->propal->dir_output))
2461 2461
 	{
2462
-		if ($fuser->rights->propale->{$lire} || preg_match('/^specimen/i',$original_file))
2462
+		if ($fuser->rights->propale->{$lire} || preg_match('/^specimen/i', $original_file))
2463 2463
 		{
2464
-			$accessallowed=1;
2464
+			$accessallowed = 1;
2465 2465
 		}
2466 2466
 
2467
-		$original_file=$conf->propal->dir_output.'/'.$original_file;
2467
+		$original_file = $conf->propal->dir_output.'/'.$original_file;
2468 2468
 		$sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."propal WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity;
2469 2469
 	}
2470 2470
 
2471 2471
 	// Wrapping pour les commandes
2472 2472
 	else if (($modulepart == 'commande' || $modulepart == 'order') && !empty($conf->commande->dir_output))
2473 2473
 	{
2474
-		if ($fuser->rights->commande->{$lire} || preg_match('/^specimen/i',$original_file))
2474
+		if ($fuser->rights->commande->{$lire} || preg_match('/^specimen/i', $original_file))
2475 2475
 		{
2476
-			$accessallowed=1;
2476
+			$accessallowed = 1;
2477 2477
 		}
2478
-		$original_file=$conf->commande->dir_output.'/'.$original_file;
2478
+		$original_file = $conf->commande->dir_output.'/'.$original_file;
2479 2479
 		$sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."commande WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity;
2480 2480
 	}
2481 2481
 
2482 2482
 	// Wrapping pour les projets
2483 2483
 	else if ($modulepart == 'project' && !empty($conf->projet->dir_output))
2484 2484
 	{
2485
-		if ($fuser->rights->projet->{$lire} || preg_match('/^specimen/i',$original_file))
2485
+		if ($fuser->rights->projet->{$lire} || preg_match('/^specimen/i', $original_file))
2486 2486
 		{
2487
-			$accessallowed=1;
2487
+			$accessallowed = 1;
2488 2488
 		}
2489
-		$original_file=$conf->projet->dir_output.'/'.$original_file;
2489
+		$original_file = $conf->projet->dir_output.'/'.$original_file;
2490 2490
 		$sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."projet WHERE ref='".$db->escape($refname)."' AND entity IN (".getEntity('project').")";
2491 2491
 	}
2492 2492
 	else if ($modulepart == 'project_task' && !empty($conf->projet->dir_output))
2493 2493
 	{
2494
-		if ($fuser->rights->projet->{$lire} || preg_match('/^specimen/i',$original_file))
2494
+		if ($fuser->rights->projet->{$lire} || preg_match('/^specimen/i', $original_file))
2495 2495
 		{
2496
-			$accessallowed=1;
2496
+			$accessallowed = 1;
2497 2497
 		}
2498
-		$original_file=$conf->projet->dir_output.'/'.$original_file;
2498
+		$original_file = $conf->projet->dir_output.'/'.$original_file;
2499 2499
 		$sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."projet WHERE ref='".$db->escape($refname)."' AND entity IN (".getEntity('project').")";
2500 2500
 	}
2501 2501
 
2502 2502
 	// Wrapping pour les commandes fournisseurs
2503 2503
 	else if (($modulepart == 'commande_fournisseur' || $modulepart == 'order_supplier') && !empty($conf->fournisseur->commande->dir_output))
2504 2504
 	{
2505
-		if ($fuser->rights->fournisseur->commande->{$lire} || preg_match('/^specimen/i',$original_file))
2505
+		if ($fuser->rights->fournisseur->commande->{$lire} || preg_match('/^specimen/i', $original_file))
2506 2506
 		{
2507
-			$accessallowed=1;
2507
+			$accessallowed = 1;
2508 2508
 		}
2509
-		$original_file=$conf->fournisseur->commande->dir_output.'/'.$original_file;
2509
+		$original_file = $conf->fournisseur->commande->dir_output.'/'.$original_file;
2510 2510
 		$sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."commande_fournisseur WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity;
2511 2511
 	}
2512 2512
 
2513 2513
 	// Wrapping pour les factures fournisseurs
2514 2514
 	else if (($modulepart == 'facture_fournisseur' || $modulepart == 'invoice_supplier') && !empty($conf->fournisseur->facture->dir_output))
2515 2515
 	{
2516
-		if ($fuser->rights->fournisseur->facture->{$lire} || preg_match('/^specimen/i',$original_file))
2516
+		if ($fuser->rights->fournisseur->facture->{$lire} || preg_match('/^specimen/i', $original_file))
2517 2517
 		{
2518
-			$accessallowed=1;
2518
+			$accessallowed = 1;
2519 2519
 		}
2520
-		$original_file=$conf->fournisseur->facture->dir_output.'/'.$original_file;
2520
+		$original_file = $conf->fournisseur->facture->dir_output.'/'.$original_file;
2521 2521
 		$sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."facture_fourn WHERE facnumber='".$db->escape($refname)."' AND entity=".$conf->entity;
2522 2522
 	}
2523 2523
 	// Wrapping pour les rapport de paiements
2524 2524
 	else if ($modulepart == 'supplier_payment')
2525 2525
 	{
2526
-		if ($fuser->rights->fournisseur->facture->{$lire} || preg_match('/^specimen/i',$original_file))
2526
+		if ($fuser->rights->fournisseur->facture->{$lire} || preg_match('/^specimen/i', $original_file))
2527 2527
 		{
2528
-			$accessallowed=1;
2528
+			$accessallowed = 1;
2529 2529
 		}
2530
-		$original_file=$conf->fournisseur->payment->dir_output.'/'.$original_file;
2530
+		$original_file = $conf->fournisseur->payment->dir_output.'/'.$original_file;
2531 2531
 		$sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."paiementfournisseur WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity;
2532 2532
 	}
2533 2533
 
2534 2534
 	// Wrapping pour les rapport de paiements
2535 2535
 	else if ($modulepart == 'facture_paiement' && !empty($conf->facture->dir_output))
2536 2536
 	{
2537
-		if ($fuser->rights->facture->{$lire} || preg_match('/^specimen/i',$original_file))
2537
+		if ($fuser->rights->facture->{$lire} || preg_match('/^specimen/i', $original_file))
2538 2538
 		{
2539
-			$accessallowed=1;
2539
+			$accessallowed = 1;
2540 2540
 		}
2541
-		if ($fuser->societe_id > 0) $original_file=$conf->facture->dir_output.'/payments/private/'.$fuser->id.'/'.$original_file;
2542
-		else $original_file=$conf->facture->dir_output.'/payments/'.$original_file;
2541
+		if ($fuser->societe_id > 0) $original_file = $conf->facture->dir_output.'/payments/private/'.$fuser->id.'/'.$original_file;
2542
+		else $original_file = $conf->facture->dir_output.'/payments/'.$original_file;
2543 2543
 	}
2544 2544
 
2545 2545
 	// Wrapping for accounting exports
2546 2546
 	else if ($modulepart == 'export_compta' && !empty($conf->accounting->dir_output))
2547 2547
 	{
2548
-		if ($fuser->rights->accounting->bind->write || preg_match('/^specimen/i',$original_file))
2548
+		if ($fuser->rights->accounting->bind->write || preg_match('/^specimen/i', $original_file))
2549 2549
 		{
2550
-			$accessallowed=1;
2550
+			$accessallowed = 1;
2551 2551
 		}
2552
-		$original_file=$conf->accounting->dir_output.'/'.$original_file;
2552
+		$original_file = $conf->accounting->dir_output.'/'.$original_file;
2553 2553
 	}
2554 2554
 
2555 2555
 	// Wrapping pour les expedition
2556 2556
 	else if ($modulepart == 'expedition' && !empty($conf->expedition->dir_output))
2557 2557
 	{
2558
-		if ($fuser->rights->expedition->{$lire} || preg_match('/^specimen/i',$original_file))
2558
+		if ($fuser->rights->expedition->{$lire} || preg_match('/^specimen/i', $original_file))
2559 2559
 		{
2560
-			$accessallowed=1;
2560
+			$accessallowed = 1;
2561 2561
 		}
2562
-		$original_file=$conf->expedition->dir_output."/sending/".$original_file;
2562
+		$original_file = $conf->expedition->dir_output."/sending/".$original_file;
2563 2563
 	}
2564 2564
 	// Wrapping pour les bons de livraison
2565 2565
 	else if ($modulepart == 'livraison' && !empty($conf->expedition->dir_output))
2566 2566
 	{
2567
-		if ($fuser->rights->expedition->livraison->{$lire} || preg_match('/^specimen/i',$original_file))
2567
+		if ($fuser->rights->expedition->livraison->{$lire} || preg_match('/^specimen/i', $original_file))
2568 2568
 		{
2569
-			$accessallowed=1;
2569
+			$accessallowed = 1;
2570 2570
 		}
2571
-		$original_file=$conf->expedition->dir_output."/receipt/".$original_file;
2571
+		$original_file = $conf->expedition->dir_output."/receipt/".$original_file;
2572 2572
 	}
2573 2573
 
2574 2574
 	// Wrapping pour les actions
2575 2575
 	else if ($modulepart == 'actions' && !empty($conf->agenda->dir_output))
2576 2576
 	{
2577
-		if ($fuser->rights->agenda->myactions->{$read} || preg_match('/^specimen/i',$original_file))
2577
+		if ($fuser->rights->agenda->myactions->{$read} || preg_match('/^specimen/i', $original_file))
2578 2578
 		{
2579
-			$accessallowed=1;
2579
+			$accessallowed = 1;
2580 2580
 		}
2581
-		$original_file=$conf->agenda->dir_output.'/'.$original_file;
2581
+		$original_file = $conf->agenda->dir_output.'/'.$original_file;
2582 2582
 	}
2583 2583
 
2584 2584
 	// Wrapping pour les actions
2585 2585
 	else if ($modulepart == 'actionsreport' && !empty($conf->agenda->dir_temp))
2586 2586
 	{
2587
-		if ($fuser->rights->agenda->allactions->{$read} || preg_match('/^specimen/i',$original_file))
2587
+		if ($fuser->rights->agenda->allactions->{$read} || preg_match('/^specimen/i', $original_file))
2588 2588
 		{
2589
-			$accessallowed=1;
2589
+			$accessallowed = 1;
2590 2590
 		}
2591 2591
 		$original_file = $conf->agenda->dir_temp."/".$original_file;
2592 2592
 	}
@@ -2595,54 +2595,54 @@  discard block
 block discarded – undo
2595 2595
 	else if ($modulepart == 'product' || $modulepart == 'produit' || $modulepart == 'service' || $modulepart == 'produit|service')
2596 2596
 	{
2597 2597
 		if (empty($entity) || (empty($conf->product->multidir_output[$entity]) && empty($conf->service->multidir_output[$entity]))) return array('accessallowed'=>0, 'error'=>'Value entity must be provided');
2598
-		if (($fuser->rights->produit->{$lire} || $fuser->rights->service->{$lire}) || preg_match('/^specimen/i',$original_file))
2598
+		if (($fuser->rights->produit->{$lire} || $fuser->rights->service->{$lire}) || preg_match('/^specimen/i', $original_file))
2599 2599
 		{
2600
-			$accessallowed=1;
2600
+			$accessallowed = 1;
2601 2601
 		}
2602
-		if (! empty($conf->product->enabled)) $original_file=$conf->product->multidir_output[$entity].'/'.$original_file;
2603
-		elseif (! empty($conf->service->enabled)) $original_file=$conf->service->multidir_output[$entity].'/'.$original_file;
2602
+		if (!empty($conf->product->enabled)) $original_file = $conf->product->multidir_output[$entity].'/'.$original_file;
2603
+		elseif (!empty($conf->service->enabled)) $original_file = $conf->service->multidir_output[$entity].'/'.$original_file;
2604 2604
 	}
2605 2605
 
2606 2606
 	// Wrapping pour les contrats
2607 2607
 	else if ($modulepart == 'contract' && !empty($conf->contrat->dir_output))
2608 2608
 	{
2609
-		if ($fuser->rights->contrat->{$lire} || preg_match('/^specimen/i',$original_file))
2609
+		if ($fuser->rights->contrat->{$lire} || preg_match('/^specimen/i', $original_file))
2610 2610
 		{
2611
-			$accessallowed=1;
2611
+			$accessallowed = 1;
2612 2612
 		}
2613
-		$original_file=$conf->contrat->dir_output.'/'.$original_file;
2613
+		$original_file = $conf->contrat->dir_output.'/'.$original_file;
2614 2614
 		$sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."contrat WHERE ref='".$db->escape($refname)."' AND entity IN (".getEntity('contract').")";
2615 2615
 	}
2616 2616
 
2617 2617
 	// Wrapping pour les dons
2618 2618
 	else if ($modulepart == 'donation' && !empty($conf->don->dir_output))
2619 2619
 	{
2620
-		if ($fuser->rights->don->{$lire} || preg_match('/^specimen/i',$original_file))
2620
+		if ($fuser->rights->don->{$lire} || preg_match('/^specimen/i', $original_file))
2621 2621
 		{
2622
-			$accessallowed=1;
2622
+			$accessallowed = 1;
2623 2623
 		}
2624
-		$original_file=$conf->don->dir_output.'/'.$original_file;
2624
+		$original_file = $conf->don->dir_output.'/'.$original_file;
2625 2625
 	}
2626 2626
 
2627 2627
 	// Wrapping pour les dons
2628 2628
 	else if ($modulepart == 'dolresource' && !empty($conf->resource->dir_output))
2629 2629
 	{
2630
-		if ($fuser->rights->resource->{$read} || preg_match('/^specimen/i',$original_file))
2630
+		if ($fuser->rights->resource->{$read} || preg_match('/^specimen/i', $original_file))
2631 2631
 		{
2632
-			$accessallowed=1;
2632
+			$accessallowed = 1;
2633 2633
 		}
2634
-		$original_file=$conf->resource->dir_output.'/'.$original_file;
2634
+		$original_file = $conf->resource->dir_output.'/'.$original_file;
2635 2635
 	}
2636 2636
 
2637 2637
 	// Wrapping pour les remises de cheques
2638 2638
 	else if ($modulepart == 'remisecheque' && !empty($conf->banque->dir_output))
2639 2639
 	{
2640
-		if ($fuser->rights->banque->{$lire} || preg_match('/^specimen/i',$original_file))
2640
+		if ($fuser->rights->banque->{$lire} || preg_match('/^specimen/i', $original_file))
2641 2641
 		{
2642
-			$accessallowed=1;
2642
+			$accessallowed = 1;
2643 2643
 		}
2644 2644
 
2645
-		$original_file=$conf->bank->dir_output.'/checkdeposits/'.$original_file;		// original_file should contains relative path so include the get_exdir result
2645
+		$original_file = $conf->bank->dir_output.'/checkdeposits/'.$original_file; // original_file should contains relative path so include the get_exdir result
2646 2646
 	}
2647 2647
 
2648 2648
 	// Wrapping for bank
@@ -2650,9 +2650,9 @@  discard block
 block discarded – undo
2650 2650
 	{
2651 2651
 		if ($fuser->rights->banque->{$lire})
2652 2652
 		{
2653
-			$accessallowed=1;
2653
+			$accessallowed = 1;
2654 2654
 		}
2655
-		$original_file=$conf->bank->dir_output.'/'.$original_file;
2655
+		$original_file = $conf->bank->dir_output.'/'.$original_file;
2656 2656
 	}
2657 2657
 
2658 2658
 	// Wrapping for export module
@@ -2660,62 +2660,62 @@  discard block
 block discarded – undo
2660 2660
 	{
2661 2661
 		// Aucun test necessaire car on force le rep de download sur
2662 2662
 		// le rep export qui est propre a l'utilisateur
2663
-		$accessallowed=1;
2664
-		$original_file=$conf->export->dir_temp.'/'.$fuser->id.'/'.$original_file;
2663
+		$accessallowed = 1;
2664
+		$original_file = $conf->export->dir_temp.'/'.$fuser->id.'/'.$original_file;
2665 2665
 	}
2666 2666
 
2667 2667
 	// Wrapping for import module
2668 2668
 	else if ($modulepart == 'import' && !empty($conf->import->dir_temp))
2669 2669
 	{
2670
-		$accessallowed=1;
2671
-		$original_file=$conf->import->dir_temp.'/'.$original_file;
2670
+		$accessallowed = 1;
2671
+		$original_file = $conf->import->dir_temp.'/'.$original_file;
2672 2672
 	}
2673 2673
 
2674 2674
 	// Wrapping pour l'editeur wysiwyg
2675 2675
 	else if ($modulepart == 'editor' && !empty($conf->fckeditor->dir_output))
2676 2676
 	{
2677
-		$accessallowed=1;
2678
-		$original_file=$conf->fckeditor->dir_output.'/'.$original_file;
2677
+		$accessallowed = 1;
2678
+		$original_file = $conf->fckeditor->dir_output.'/'.$original_file;
2679 2679
 	}
2680 2680
 
2681 2681
 	// Wrapping for backups
2682 2682
 	else if ($modulepart == 'systemtools' && !empty($conf->admin->dir_output))
2683 2683
 	{
2684
-		if ($fuser->admin) $accessallowed=1;
2685
-		$original_file=$conf->admin->dir_output.'/'.$original_file;
2684
+		if ($fuser->admin) $accessallowed = 1;
2685
+		$original_file = $conf->admin->dir_output.'/'.$original_file;
2686 2686
 	}
2687 2687
 
2688 2688
 	// Wrapping for upload file test
2689 2689
 	else if ($modulepart == 'admin_temp' && !empty($conf->admin->dir_temp))
2690 2690
 	{
2691
-		if ($fuser->admin) $accessallowed=1;
2692
-		$original_file=$conf->admin->dir_temp.'/'.$original_file;
2691
+		if ($fuser->admin) $accessallowed = 1;
2692
+		$original_file = $conf->admin->dir_temp.'/'.$original_file;
2693 2693
 	}
2694 2694
 
2695 2695
 	// Wrapping pour BitTorrent
2696 2696
 	else if ($modulepart == 'bittorrent' && !empty($conf->bittorrent->dir_output))
2697 2697
 	{
2698
-		$accessallowed=1;
2699
-		$dir='files';
2700
-		if (dol_mimetype($original_file) == 'application/x-bittorrent') $dir='torrents';
2701
-		$original_file=$conf->bittorrent->dir_output.'/'.$dir.'/'.$original_file;
2698
+		$accessallowed = 1;
2699
+		$dir = 'files';
2700
+		if (dol_mimetype($original_file) == 'application/x-bittorrent') $dir = 'torrents';
2701
+		$original_file = $conf->bittorrent->dir_output.'/'.$dir.'/'.$original_file;
2702 2702
 	}
2703 2703
 
2704 2704
 	// Wrapping pour Foundation module
2705 2705
 	else if ($modulepart == 'member' && !empty($conf->adherent->dir_output))
2706 2706
 	{
2707
-		if ($fuser->rights->adherent->{$lire} || preg_match('/^specimen/i',$original_file))
2707
+		if ($fuser->rights->adherent->{$lire} || preg_match('/^specimen/i', $original_file))
2708 2708
 		{
2709
-			$accessallowed=1;
2709
+			$accessallowed = 1;
2710 2710
 		}
2711
-		$original_file=$conf->adherent->dir_output.'/'.$original_file;
2711
+		$original_file = $conf->adherent->dir_output.'/'.$original_file;
2712 2712
 	}
2713 2713
 
2714 2714
 	// Wrapping for Scanner
2715 2715
 	else if ($modulepart == 'scanner_user_temp' && !empty($conf->scanner->dir_temp))
2716 2716
 	{
2717
-		$accessallowed=1;
2718
-		$original_file=$conf->scanner->dir_temp.'/'.$fuser->id.'/'.$original_file;
2717
+		$accessallowed = 1;
2718
+		$original_file = $conf->scanner->dir_temp.'/'.$fuser->id.'/'.$original_file;
2719 2719
 	}
2720 2720
 
2721 2721
 	// GENERIC Wrapping
@@ -2725,76 +2725,76 @@  discard block
 block discarded – undo
2725 2725
 	// If modulepart=module				Allows any module to open a file if file is in directory called DOL_DATA_ROOT/modulepart
2726 2726
 	else
2727 2727
 	{
2728
-		if (preg_match('/^specimen/i',$original_file))	$accessallowed=1;    // If link to a file called specimen. Test must be done before changing $original_file int full path.
2729
-		if ($fuser->admin) $accessallowed=1;    // If user is admin
2728
+		if (preg_match('/^specimen/i', $original_file))	$accessallowed = 1; // If link to a file called specimen. Test must be done before changing $original_file int full path.
2729
+		if ($fuser->admin) $accessallowed = 1; // If user is admin
2730 2730
 
2731 2731
 		// Define $accessallowed
2732
-		if (preg_match('/^([a-z]+)_user_temp$/i',$modulepart,$reg))
2732
+		if (preg_match('/^([a-z]+)_user_temp$/i', $modulepart, $reg))
2733 2733
 		{
2734 2734
 			if (empty($conf->{$reg[1]}->dir_temp))	// modulepart not supported
2735 2735
 			{
2736
-				dol_print_error('','Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')');
2736
+				dol_print_error('', 'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')');
2737 2737
 				exit;
2738 2738
 			}
2739
-			if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) $accessallowed=1;
2740
-			$original_file=$conf->{$reg[1]}->dir_temp.'/'.$fuser->id.'/'.$original_file;
2739
+			if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) $accessallowed = 1;
2740
+			$original_file = $conf->{$reg[1]}->dir_temp.'/'.$fuser->id.'/'.$original_file;
2741 2741
 		}
2742
-		else if (preg_match('/^([a-z]+)_temp$/i',$modulepart,$reg))
2742
+		else if (preg_match('/^([a-z]+)_temp$/i', $modulepart, $reg))
2743 2743
 		{
2744 2744
 			if (empty($conf->{$reg[1]}->dir_temp))	// modulepart not supported
2745 2745
 			{
2746
-				dol_print_error('','Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')');
2746
+				dol_print_error('', 'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')');
2747 2747
 				exit;
2748 2748
 			}
2749
-			if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) $accessallowed=1;
2750
-			$original_file=$conf->{$reg[1]}->dir_temp.'/'.$original_file;
2749
+			if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) $accessallowed = 1;
2750
+			$original_file = $conf->{$reg[1]}->dir_temp.'/'.$original_file;
2751 2751
 		}
2752
-		else if (preg_match('/^([a-z]+)_user$/i',$modulepart,$reg))
2752
+		else if (preg_match('/^([a-z]+)_user$/i', $modulepart, $reg))
2753 2753
 		{
2754 2754
 			if (empty($conf->{$reg[1]}->dir_output))	// modulepart not supported
2755 2755
 			{
2756
-				dol_print_error('','Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')');
2756
+				dol_print_error('', 'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')');
2757 2757
 				exit;
2758 2758
 			}
2759
-			if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) $accessallowed=1;
2760
-			$original_file=$conf->{$reg[1]}->dir_output.'/'.$fuser->id.'/'.$original_file;
2759
+			if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) $accessallowed = 1;
2760
+			$original_file = $conf->{$reg[1]}->dir_output.'/'.$fuser->id.'/'.$original_file;
2761 2761
 		}
2762 2762
 		else
2763 2763
 		{
2764 2764
 			if (empty($conf->$modulepart->dir_output))	// modulepart not supported
2765 2765
 			{
2766
-				dol_print_error('','Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')');
2766
+				dol_print_error('', 'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')');
2767 2767
 				exit;
2768 2768
 			}
2769 2769
 
2770
-			$perm=GETPOST('perm');
2771
-			$subperm=GETPOST('subperm');
2770
+			$perm = GETPOST('perm');
2771
+			$subperm = GETPOST('subperm');
2772 2772
 			if ($perm || $subperm)
2773 2773
 			{
2774
-				if (($perm && ! $subperm && $fuser->rights->$modulepart->$perm) || ($perm && $subperm && $fuser->rights->$modulepart->$perm->$subperm)) $accessallowed=1;
2775
-				$original_file=$conf->$modulepart->dir_output.'/'.$original_file;
2774
+				if (($perm && !$subperm && $fuser->rights->$modulepart->$perm) || ($perm && $subperm && $fuser->rights->$modulepart->$perm->$subperm)) $accessallowed = 1;
2775
+				$original_file = $conf->$modulepart->dir_output.'/'.$original_file;
2776 2776
 			}
2777 2777
 			else
2778 2778
 			{
2779
-				if ($fuser->rights->$modulepart->{$lire} || $fuser->rights->$modulepart->{$read}) $accessallowed=1;
2780
-				$original_file=$conf->$modulepart->dir_output.'/'.$original_file;
2779
+				if ($fuser->rights->$modulepart->{$lire} || $fuser->rights->$modulepart->{$read}) $accessallowed = 1;
2780
+				$original_file = $conf->$modulepart->dir_output.'/'.$original_file;
2781 2781
 			}
2782 2782
 		}
2783 2783
 
2784 2784
 		// For modules who wants to manage different levels of permissions for documents
2785 2785
 		$subPermCategoryConstName = strtoupper($modulepart).'_SUBPERMCATEGORY_FOR_DOCUMENTS';
2786
-		if (! empty($conf->global->$subPermCategoryConstName))
2786
+		if (!empty($conf->global->$subPermCategoryConstName))
2787 2787
 		{
2788 2788
 			$subPermCategory = $conf->global->$subPermCategoryConstName;
2789
-			if (! empty($subPermCategory) && (($fuser->rights->$modulepart->$subPermCategory->{$lire}) || ($fuser->rights->$modulepart->$subPermCategory->{$read}) || ($fuser->rights->$modulepart->$subPermCategory->{$download})))
2789
+			if (!empty($subPermCategory) && (($fuser->rights->$modulepart->$subPermCategory->{$lire}) || ($fuser->rights->$modulepart->$subPermCategory->{$read}) || ($fuser->rights->$modulepart->$subPermCategory->{$download})))
2790 2790
 			{
2791
-				$accessallowed=1;
2791
+				$accessallowed = 1;
2792 2792
 			}
2793 2793
 		}
2794 2794
 
2795 2795
 		// Define $sqlprotectagainstexternals for modules who want to protect access using a SQL query.
2796 2796
 		$sqlProtectConstName = strtoupper($modulepart).'_SQLPROTECTAGAINSTEXTERNALS_FOR_DOCUMENTS';
2797
-		if (! empty($conf->global->$sqlProtectConstName))	// If module want to define its own $sqlprotectagainstexternals
2797
+		if (!empty($conf->global->$sqlProtectConstName))	// If module want to define its own $sqlprotectagainstexternals
2798 2798
 		{
2799 2799
 			// Example: mymodule__SQLPROTECTAGAINSTEXTERNALS_FOR_DOCUMENTS = "SELECT fk_soc FROM ".MAIN_DB_PREFIX.$modulepart." WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity;
2800 2800
 			eval('$sqlprotectagainstexternals = "'.$conf->global->$sqlProtectConstName.'";');
@@ -2820,8 +2820,8 @@  discard block
 block discarded – undo
2820 2820
  */
2821 2821
 function dol_filecache($directory, $filename, $object)
2822 2822
 {
2823
-	if (! dol_is_dir($directory)) dol_mkdir($directory);
2824
-	$cachefile = $directory . $filename;
2823
+	if (!dol_is_dir($directory)) dol_mkdir($directory);
2824
+	$cachefile = $directory.$filename;
2825 2825
 	file_put_contents($cachefile, serialize($object), LOCK_EX);
2826 2826
 	@chmod($cachefile, 0644);
2827 2827
 }
@@ -2837,8 +2837,8 @@  discard block
 block discarded – undo
2837 2837
 function dol_cache_refresh($directory, $filename, $cachetime)
2838 2838
 {
2839 2839
 	$now = dol_now();
2840
-	$cachefile = $directory . $filename;
2841
-	$refresh = !file_exists($cachefile) || ($now-$cachetime) > dol_filemtime($cachefile);
2840
+	$cachefile = $directory.$filename;
2841
+	$refresh = !file_exists($cachefile) || ($now - $cachetime) > dol_filemtime($cachefile);
2842 2842
 	return $refresh;
2843 2843
 }
2844 2844
 
@@ -2851,7 +2851,7 @@  discard block
 block discarded – undo
2851 2851
  */
2852 2852
 function dol_readcachefile($directory, $filename)
2853 2853
 {
2854
-	$cachefile = $directory . $filename;
2854
+	$cachefile = $directory.$filename;
2855 2855
 	$object = unserialize(file_get_contents($cachefile));
2856 2856
 	return $object;
2857 2857
 }
Please login to merge, or discard this patch.
Braces   +491 added lines, -257 removed lines patch added patch discarded remove patch
@@ -97,16 +97,21 @@  discard block
 block discarded – undo
97 97
 	// $hookmanager->resArray may contain array stacked by other modules
98 98
 	if (empty($reshook))
99 99
 	{
100
-		if (! is_dir($newpath)) return array();
100
+		if (! is_dir($newpath)) {
101
+			return array();
102
+		}
101 103
 
102 104
 		if ($dir = opendir($newpath))
103 105
 		{
104 106
 			$filedate='';
105 107
 			$filesize='';
106 108
 
107
-			while (false !== ($file = readdir($dir)))        // $file is always a basename (into directory $newpath)
109
+			while (false !== ($file = readdir($dir))) {
110
+				// $file is always a basename (into directory $newpath)
108 111
 			{
109
-				if (! utf8_check($file)) $file=utf8_encode($file);	// To be sure data is stored in utf8 in memory
112
+				if (! utf8_check($file)) $file=utf8_encode($file);
113
+			}
114
+			// To be sure data is stored in utf8 in memory
110 115
 				$fullpathfile=($newpath?$newpath.'/':'').$file;
111 116
 
112 117
 				$qualified=1;
@@ -116,8 +121,9 @@  discard block
 block discarded – undo
116 121
 				if (is_array($excludefilter))
117 122
 				{
118 123
 					$excludefilterarray=array_merge($excludefilterarray,$excludefilter);
124
+				} else if ($excludefilter) {
125
+					$excludefilterarray[]=$excludefilter;
119 126
 				}
120
-				else if ($excludefilter) $excludefilterarray[]=$excludefilter;
121 127
 				// Check if file is qualified
122 128
 				foreach($excludefilterarray as $filt)
123 129
 				{
@@ -136,12 +142,18 @@  discard block
 block discarded – undo
136 142
 						// Add entry into file_list array
137 143
 						if (($types=="directories") || ($types=="all"))
138 144
 						{
139
-							if ($loaddate || $sortcriteria == 'date') $filedate=dol_filemtime($path."/".$file);
140
-							if ($loadsize || $sortcriteria == 'size') $filesize=dol_filesize($path."/".$file);
145
+							if ($loaddate || $sortcriteria == 'date') {
146
+								$filedate=dol_filemtime($path."/".$file);
147
+							}
148
+							if ($loadsize || $sortcriteria == 'size') {
149
+								$filesize=dol_filesize($path."/".$file);
150
+							}
141 151
 
142
-							if (! $filter || preg_match('/'.$filter.'/i',$file))	// We do not search key $filter into all $path, only into $file part
152
+							if (! $filter || preg_match('/'.$filter.'/i',$file)) {
153
+								// We do not search key $filter into all $path, only into $file part
143 154
 							{
144 155
 								preg_match('/([^\/]+)\/[^\/]+$/',$path.'/'.$file,$reg);
156
+							}
145 157
 								$level1name=(isset($reg[1])?$reg[1]:'');
146 158
 								$file_list[] = array(
147 159
 										"name" => $file,
@@ -161,16 +173,21 @@  discard block
 block discarded – undo
161 173
 						{
162 174
 							$file_list = array_merge($file_list, dol_dir_list($path."/".$file, $types, $recursive, $filter, $excludefilter, $sortcriteria, $sortorder, $mode, $nohook, ($relativename!=''?$relativename.'/':'').$file));
163 175
 						}
164
-					}
165
-					else if (! $isdir && (($types == "files") || ($types == "all")))
176
+					} else if (! $isdir && (($types == "files") || ($types == "all")))
166 177
 					{
167 178
 						// Add file into file_list array
168
-						if ($loaddate || $sortcriteria == 'date') $filedate=dol_filemtime($path."/".$file);
169
-						if ($loadsize || $sortcriteria == 'size') $filesize=dol_filesize($path."/".$file);
179
+						if ($loaddate || $sortcriteria == 'date') {
180
+							$filedate=dol_filemtime($path."/".$file);
181
+						}
182
+						if ($loadsize || $sortcriteria == 'size') {
183
+							$filesize=dol_filesize($path."/".$file);
184
+						}
170 185
 
171
-						if (! $filter || preg_match('/'.$filter.'/i',$file))	// We do not search key $filter into $path, only into $file
186
+						if (! $filter || preg_match('/'.$filter.'/i',$file)) {
187
+							// We do not search key $filter into $path, only into $file
172 188
 						{
173 189
 							preg_match('/([^\/]+)\/[^\/]+$/',$path.'/'.$file,$reg);
190
+						}
174 191
 							$level1name=(isset($reg[1])?$reg[1]:'');
175 192
 							$file_list[] = array(
176 193
 									"name" => $file,
@@ -197,12 +214,16 @@  discard block
 block discarded – undo
197 214
 					$myarray[$key] = (isset($row[$sortcriteria])?$row[$sortcriteria]:'');
198 215
 				}
199 216
 				// Sort the data
200
-				if ($sortorder) array_multisort($myarray, $sortorder, $file_list);
217
+				if ($sortorder) {
218
+					array_multisort($myarray, $sortorder, $file_list);
219
+				}
201 220
 			}
202 221
 		}
203 222
 	}
204 223
 
205
-	if (is_object($hookmanager) && is_array($hookmanager->resArray)) $file_list = array_merge($file_list, $hookmanager->resArray);
224
+	if (is_object($hookmanager) && is_array($hookmanager->resArray)) {
225
+		$file_list = array_merge($file_list, $hookmanager->resArray);
226
+	}
206 227
 
207 228
 	return $file_list;
208 229
 }
@@ -227,7 +248,9 @@  discard block
 block discarded – undo
227 248
 
228 249
 	$sql =" SELECT rowid, label, entity, filename, filepath, fullpath_orig, keywords, cover, gen_or_uploaded, extraparams, date_c, date_m, fk_user_c, fk_user_m,";
229 250
 	$sql.=" acl, position, share";
230
-	if ($mode) $sql.=", description";
251
+	if ($mode) {
252
+		$sql.=", description";
253
+	}
231 254
 	$sql.=" FROM ".MAIN_DB_PREFIX."ecm_files";
232 255
 	$sql.=" WHERE filepath = '".$db->escape($path)."'";
233 256
 	$sql.=" AND entity = ".$conf->entity;
@@ -275,12 +298,13 @@  discard block
 block discarded – undo
275 298
 				$myarray[$key] = (isset($row[$sortcriteria])?$row[$sortcriteria]:'');
276 299
 			}
277 300
 			// Sort the data
278
-			if ($sortorder) array_multisort($myarray, $sortorder, $file_list);
301
+			if ($sortorder) {
302
+				array_multisort($myarray, $sortorder, $file_list);
303
+			}
279 304
 		}
280 305
 
281 306
 		return $file_list;
282
-	}
283
-	else
307
+	} else
284 308
 	{
285 309
 		dol_print_error($db);
286 310
 		return array();
@@ -326,16 +350,21 @@  discard block
 block discarded – undo
326 350
 			}
327 351
 		}
328 352
 
329
-		if (! $found)    // This happen in transition toward version 6, or if files were added manually into os dir.
353
+		if (! $found) {
354
+			// This happen in transition toward version 6, or if files were added manually into os dir.
330 355
 		{
331
-			$filearray[$key]['position']='999999';     // File not indexed are at end. So if we add a file, it will not replace an existing position
356
+			$filearray[$key]['position']='999999';
357
+		}
358
+		// File not indexed are at end. So if we add a file, it will not replace an existing position
332 359
 			$filearray[$key]['cover']=0;
333 360
 			$filearray[$key]['acl']='';
334 361
 
335 362
 			$rel_filename = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $filearray[$key]['fullname']);
336
-			if (! preg_match('/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filetorenameafter))     // If not a tmp file
363
+			if (! preg_match('/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filetorenameafter)) {
364
+				// If not a tmp file
337 365
 			{
338 366
 				dol_syslog("list_of_documents We found a file called '".$filearray[$key]['name']."' not indexed into database. We add it");
367
+			}
339 368
 				include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
340 369
 				$ecmfile=new EcmFiles($db);
341 370
 
@@ -356,13 +385,11 @@  discard block
 block discarded – undo
356 385
 				if ($result < 0)
357 386
 				{
358 387
 					setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings');
359
-				}
360
-				else
388
+				} else
361 389
 				{
362 390
 					$filearray[$key]['rowid']=$result;
363 391
 				}
364
-			}
365
-			else
392
+			} else
366 393
 			{
367 394
 				$filearray[$key]['rowid']=0;     // Should not happened
368 395
 			}
@@ -387,22 +414,27 @@  discard block
 block discarded – undo
387 414
 
388 415
 	$sortorder=strtoupper($sortorder);
389 416
 
390
-	if ($sortorder == 'ASC') { $retup=-1; $retdown=1; }
391
-	else { $retup=1; $retdown=-1; }
417
+	if ($sortorder == 'ASC') { $retup=-1; $retdown=1; } else { $retup=1; $retdown=-1; }
392 418
 
393 419
 	if ($sortfield == 'name')
394 420
 	{
395
-		if ($a->name == $b->name) return 0;
421
+		if ($a->name == $b->name) {
422
+			return 0;
423
+		}
396 424
 		return ($a->name < $b->name) ? $retup : $retdown;
397 425
 	}
398 426
 	if ($sortfield == 'date')
399 427
 	{
400
-		if ($a->date == $b->date) return 0;
428
+		if ($a->date == $b->date) {
429
+			return 0;
430
+		}
401 431
 		return ($a->date < $b->date) ? $retup : $retdown;
402 432
 	}
403 433
 	if ($sortfield == 'size')
404 434
 	{
405
-		if ($a->size == $b->size) return 0;
435
+		if ($a->size == $b->size) {
436
+			return 0;
437
+		}
406 438
 		return ($a->size < $b->size) ? $retup : $retdown;
407 439
 	}
408 440
 }
@@ -417,9 +449,12 @@  discard block
 block discarded – undo
417 449
 function dol_is_dir($folder)
418 450
 {
419 451
 	$newfolder=dol_osencode($folder);
420
-	if (is_dir($newfolder)) return true;
421
-	else return false;
422
-}
452
+	if (is_dir($newfolder)) {
453
+		return true;
454
+	} else {
455
+		return false;
456
+	}
457
+	}
423 458
 
424 459
 /**
425 460
  * Return if path is a file
@@ -444,7 +479,9 @@  discard block
 block discarded – undo
444 479
 	$tmpprot=array('file','http','https','ftp','zlib','data','ssh','ssh2','ogg','expect');
445 480
 	foreach($tmpprot as $prot)
446 481
 	{
447
-		if (preg_match('/^'.$prot.':/i',$url)) return true;
482
+		if (preg_match('/^'.$prot.':/i',$url)) {
483
+			return true;
484
+		}
448 485
 	}
449 486
 	return false;
450 487
 }
@@ -466,15 +503,21 @@  discard block
 block discarded – undo
466 503
 		{
467 504
 			$name_array[] = $name;
468 505
 		}
469
-		foreach($name_array as $temp) $folder_content .= $temp;
506
+		foreach($name_array as $temp) {
507
+			$folder_content .= $temp;
508
+		}
470 509
 
471 510
 		closedir($handle);
472 511
 
473
-		if ($folder_content == "...") return true;
474
-		else return false;
512
+		if ($folder_content == "...") {
513
+			return true;
514
+		} else {
515
+			return false;
516
+		}
517
+	} else {
518
+		return true;
475 519
 	}
476
-	else
477
-	return true; // Dir does not exists
520
+	// Dir does not exists
478 521
 }
479 522
 
480 523
 /**
@@ -497,11 +540,12 @@  discard block
 block discarded – undo
497 540
 		{
498 541
 			$line=fgets($fp);
499 542
 			// We increase count only if read was success. We need test because feof return true only after fgets so we do n+1 fgets for a file with n lines.
500
-			if (! $line === false) $nb++;
543
+			if (! $line === false) {
544
+				$nb++;
545
+			}
501 546
 		}
502 547
 		fclose($fp);
503
-	}
504
-	else
548
+	} else
505 549
 	{
506 550
 		$nb=-1;
507 551
 	}
@@ -551,11 +595,17 @@  discard block
 block discarded – undo
551 595
 
552 596
 	dol_syslog("files.lib.php::dolReplaceInFile srcfile=".$srcfile." destfile=".$destfile." newmask=".$newmask." indexdatabase=".$indexdatabase);
553 597
 
554
-	if (empty($srcfile)) return -1;
555
-	if (empty($destfile)) $destfile=$srcfile;
598
+	if (empty($srcfile)) {
599
+		return -1;
600
+	}
601
+	if (empty($destfile)) {
602
+		$destfile=$srcfile;
603
+	}
556 604
 
557 605
 	$destexists=dol_is_file($destfile);
558
-	if (($destfile != $srcfile) && $destexists) return 0;
606
+	if (($destfile != $srcfile) && $destexists) {
607
+		return 0;
608
+	}
559 609
 
560 610
 	$tmpdestfile=$destfile.'.tmp';
561 611
 
@@ -592,10 +642,14 @@  discard block
 block discarded – undo
592 642
 		dol_syslog("files.lib.php::dolReplaceInFile failed to move tmp file to final dest", LOG_WARNING);
593 643
 		return -3;
594 644
 	}
595
-	if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK;
596
-	if (empty($newmask))	// This should no happen
645
+	if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) {
646
+		$newmask=$conf->global->MAIN_UMASK;
647
+	}
648
+	if (empty($newmask)) {
649
+		// This should no happen
597 650
 	{
598 651
 		dol_syslog("Warning: dolReplaceInFile called with empty value for newmask and no default value defined", LOG_WARNING);
652
+	}
599 653
 		$newmask='0664';
600 654
 	}
601 655
 
@@ -637,10 +691,14 @@  discard block
 block discarded – undo
637 691
 
638 692
 	dol_syslog("files.lib.php::dol_copy srcfile=".$srcfile." destfile=".$destfile." newmask=".$newmask." overwriteifexists=".$overwriteifexists);
639 693
 
640
-	if (empty($srcfile) || empty($destfile)) return -1;
694
+	if (empty($srcfile) || empty($destfile)) {
695
+		return -1;
696
+	}
641 697
 
642 698
 	$destexists=dol_is_file($destfile);
643
-	if (! $overwriteifexists && $destexists) return 0;
699
+	if (! $overwriteifexists && $destexists) {
700
+		return 0;
701
+	}
644 702
 
645 703
 	$newpathofsrcfile=dol_osencode($srcfile);
646 704
 	$newpathofdestfile=dol_osencode($destfile);
@@ -664,10 +722,14 @@  discard block
 block discarded – undo
664 722
 		dol_syslog("files.lib.php::dol_copy failed to copy", LOG_WARNING);
665 723
 		return -3;
666 724
 	}
667
-	if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK;
668
-	if (empty($newmask))	// This should no happen
725
+	if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) {
726
+		$newmask=$conf->global->MAIN_UMASK;
727
+	}
728
+	if (empty($newmask)) {
729
+		// This should no happen
669 730
 	{
670 731
 		dol_syslog("Warning: dol_copy called with empty value for newmask and no default value defined", LOG_WARNING);
732
+	}
671 733
 		$newmask='0664';
672 734
 	}
673 735
 
@@ -695,7 +757,9 @@  discard block
 block discarded – undo
695 757
 
696 758
 	dol_syslog("files.lib.php::dolCopyDir srcfile=".$srcfile." destfile=".$destfile." newmask=".$newmask." overwriteifexists=".$overwriteifexists);
697 759
 
698
-	if (empty($srcfile) || empty($destfile)) return -1;
760
+	if (empty($srcfile) || empty($destfile)) {
761
+		return -1;
762
+	}
699 763
 
700 764
 	$destexists=dol_is_dir($destfile);
701 765
 	//if (! $overwriteifexists && $destexists) return 0;	// The overwriteifexists is for files only, so propagated to dol_copy only.
@@ -705,7 +769,9 @@  discard block
 block discarded – undo
705 769
 		// We must set mask just before creating dir, becaause it can be set differently by dol_copy
706 770
 		umask(0);
707 771
 		$dirmaskdec=octdec($newmask);
708
-		if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $dirmaskdec=octdec($conf->global->MAIN_UMASK);
772
+		if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) {
773
+			$dirmaskdec=octdec($conf->global->MAIN_UMASK);
774
+		}
709 775
 		$dirmaskdec |= octdec('0200');  // Set w bit required to be able to create content for recursive subdirs files
710 776
 		dol_mkdir($destfile, '', decoct($dirmaskdec));
711 777
 	}
@@ -725,8 +791,7 @@  discard block
 block discarded – undo
725 791
 				{
726 792
 					//var_dump("xxx dolCopyDir $srcfile/$file, $destfile/$file, $newmask, $overwriteifexists");
727 793
 					$tmpresult=dolCopyDir($srcfile."/".$file, $destfile."/".$file, $newmask, $overwriteifexists, $arrayreplacement);
728
-				}
729
-				else
794
+				} else
730 795
 				{
731 796
 					$newfile = $file;
732 797
 					// Replace destination filename with a new one
@@ -743,18 +808,18 @@  discard block
 block discarded – undo
743 808
 				if ($result > 0 && $tmpresult >= 0)
744 809
 				{
745 810
 					// Do nothing, so we don't set result to 0 if tmpresult is 0 and result was success in a previous pass
746
-				}
747
-				else
811
+				} else
748 812
 				{
749 813
 					$result=$tmpresult;
750 814
 				}
751
-				if ($result < 0) break;
815
+				if ($result < 0) {
816
+					break;
817
+				}
752 818
 
753 819
 			}
754 820
 		}
755 821
 		closedir($dir_handle);
756
-	}
757
-	else
822
+	} else
758 823
 	{
759 824
 		// Source directory does not exists
760 825
 		$result = -2;
@@ -821,8 +886,9 @@  discard block
 block discarded – undo
821 886
 				// We force delete and try again. Rename function sometimes fails to replace dest file with some windows NTFS partitions.
822 887
 				dol_delete_file($destfile);
823 888
 				$result=@rename($newpathofsrcfile, $newpathofdestfile); // To see errors, remove @
889
+			} else {
890
+				dol_syslog("files.lib.php::dol_move Failed.", LOG_WARNING);
824 891
 			}
825
-			else dol_syslog("files.lib.php::dol_move Failed.", LOG_WARNING);
826 892
 		}
827 893
 
828 894
 		// Move ok
@@ -831,9 +897,11 @@  discard block
 block discarded – undo
831 897
 			// Rename entry into ecm database
832 898
 			$rel_filetorenamebefore = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $srcfile);
833 899
 			$rel_filetorenameafter = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $destfile);
834
-			if (! preg_match('/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filetorenameafter))     // If not a tmp file
900
+			if (! preg_match('/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filetorenameafter)) {
901
+				// If not a tmp file
835 902
 			{
836 903
 				$rel_filetorenamebefore = preg_replace('/^[\\/]/', '', $rel_filetorenamebefore);
904
+			}
837 905
 				$rel_filetorenameafter = preg_replace('/^[\\/]/', '', $rel_filetorenameafter);
838 906
 				//var_dump($rel_filetorenamebefore.' - '.$rel_filetorenameafter);
839 907
 
@@ -842,16 +910,20 @@  discard block
 block discarded – undo
842 910
 
843 911
 				$ecmfiletarget=new EcmFiles($db);
844 912
 				$resultecmtarget = $ecmfiletarget->fetch(0, '', $rel_filetorenameafter);
845
-				if ($resultecmtarget > 0)   // An entry for target name already exists for target, we delete it, a new one will be created.
913
+				if ($resultecmtarget > 0) {
914
+					// An entry for target name already exists for target, we delete it, a new one will be created.
846 915
 				{
847 916
 					$ecmfiletarget->delete($user);
848 917
 				}
918
+				}
849 919
 
850 920
 				$ecmfile=new EcmFiles($db);
851 921
 				$resultecm = $ecmfile->fetch(0, '', $rel_filetorenamebefore);
852
-				if ($resultecm > 0)   // If an entry was found for src file, we use it to move entry
922
+				if ($resultecm > 0) {
923
+					// If an entry was found for src file, we use it to move entry
853 924
 				{
854 925
 					$filename = basename($rel_filetorenameafter);
926
+				}
855 927
 					$rel_dir = dirname($rel_filetorenameafter);
856 928
 					$rel_dir = preg_replace('/[\\/]$/', '', $rel_dir);
857 929
 					$rel_dir = preg_replace('/^[\\/]/', '', $rel_dir);
@@ -859,10 +931,11 @@  discard block
 block discarded – undo
859 931
 					$ecmfile->filepath = $rel_dir;
860 932
 					$ecmfile->filename = $filename;
861 933
 					$resultecm = $ecmfile->update($user);
862
-				}
863
-				elseif ($resultecm == 0)   // If no entry were found for src files, create/update target file
934
+				} elseif ($resultecm == 0) {
935
+					// If no entry were found for src files, create/update target file
864 936
 				{
865 937
 					$filename = basename($rel_filetorenameafter);
938
+				}
866 939
 					$rel_dir = dirname($rel_filetorenameafter);
867 940
 					$rel_dir = preg_replace('/[\\/]$/', '', $rel_dir);
868 941
 					$rel_dir = preg_replace('/^[\\/]/', '', $rel_dir);
@@ -879,18 +952,22 @@  discard block
 block discarded – undo
879 952
 					{
880 953
 						setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings');
881 954
 					}
882
-				}
883
-				elseif ($resultecm < 0)
955
+				} elseif ($resultecm < 0)
884 956
 				{
885 957
 					setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings');
886 958
 				}
887 959
 
888
-				if ($resultecm > 0) $result=true;
889
-				else $result = false;
960
+				if ($resultecm > 0) {
961
+					$result=true;
962
+				} else {
963
+					$result = false;
964
+				}
890 965
 			}
891 966
 		}
892 967
 
893
-		if (empty($newmask)) $newmask=empty($conf->global->MAIN_UMASK)?'0755':$conf->global->MAIN_UMASK;
968
+		if (empty($newmask)) {
969
+			$newmask=empty($conf->global->MAIN_UMASK)?'0755':$conf->global->MAIN_UMASK;
970
+		}
894 971
 		$newmaskdec=octdec($newmask);
895 972
 		// Currently method is restricted to files (dol_delete_files previously used is for files, and mask usage if for files too)
896 973
 		// to allow mask usage for dir, we shoul introduce a new param "isdir" to 1 to complete newmask like this
@@ -934,9 +1011,11 @@  discard block
 block discarded – undo
934 1011
 		}
935 1012
 		$antivir=new AntiVir($db);
936 1013
 		$result = $antivir->dol_avscan_file($src_file);
937
-		if ($result < 0)	// If virus or error, we stop here
1014
+		if ($result < 0) {
1015
+			// If virus or error, we stop here
938 1016
 		{
939 1017
 			$reterrors=$antivir->errors;
1018
+		}
940 1019
 			return $reterrors;
941 1020
 		}
942 1021
 	}
@@ -1044,13 +1123,17 @@  discard block
 block discarded – undo
1044 1123
 		}
1045 1124
 	}
1046 1125
 
1047
-	if ($reshook < 0)	// At least one blocking error returned by one hook
1126
+	if ($reshook < 0) {
1127
+		// At least one blocking error returned by one hook
1048 1128
 	{
1049 1129
 		$errmsg = join(',', $hookmanager->errors);
1050
-		if (empty($errmsg)) $errmsg = 'ErrorReturnedBySomeHooks';	// Should not occurs. Added if hook is bugged and does not set ->errors when there is error.
1051
-		return $errmsg;
1052 1130
 	}
1053
-	elseif (empty($reshook))
1131
+		if (empty($errmsg)) {
1132
+			$errmsg = 'ErrorReturnedBySomeHooks';
1133
+		}
1134
+		// Should not occurs. Added if hook is bugged and does not set ->errors when there is error.
1135
+		return $errmsg;
1136
+	} elseif (empty($reshook))
1054 1137
 	{
1055 1138
 		// The file functions must be in OS filesystem encoding.
1056 1139
 		$src_file_osencoded=dol_osencode($src_file);
@@ -1077,11 +1160,12 @@  discard block
 block discarded – undo
1077 1160
 		$return=move_uploaded_file($src_file_osencoded, $file_name_osencoded);
1078 1161
 		if ($return)
1079 1162
 		{
1080
-			if (! empty($conf->global->MAIN_UMASK)) @chmod($file_name_osencoded, octdec($conf->global->MAIN_UMASK));
1163
+			if (! empty($conf->global->MAIN_UMASK)) {
1164
+				@chmod($file_name_osencoded, octdec($conf->global->MAIN_UMASK));
1165
+			}
1081 1166
 			dol_syslog("Files.lib::dol_move_uploaded_file Success to move ".$src_file." to ".$file_name." - Umask=".$conf->global->MAIN_UMASK, LOG_DEBUG);
1082 1167
 			return 1;	// Success
1083
-		}
1084
-		else
1168
+		} else
1085 1169
 		{
1086 1170
 			dol_syslog("Files.lib::dol_move_uploaded_file Failed to move ".$src_file." to ".$file_name, LOG_ERR);
1087 1171
 			return -3;	// Unknown error
@@ -1134,12 +1218,13 @@  discard block
 block discarded – undo
1134 1218
 		$reshook=$hookmanager->executeHooks('deleteFile', $parameters, $object);
1135 1219
 	}
1136 1220
 
1137
-	if (empty($nohook) && $reshook != 0) // reshook = 0 to do standard actions, 1 = ok, -1 = ko
1221
+	if (empty($nohook) && $reshook != 0) {
1222
+		// reshook = 0 to do standard actions, 1 = ok, -1 = ko
1138 1223
 	{
1139 1224
 		if ($reshook < 0) return false;
1140
-		return true;
1141 1225
 	}
1142
-	else
1226
+		return true;
1227
+	} else
1143 1228
 	{
1144 1229
 		$error=0;
1145 1230
 
@@ -1155,17 +1240,22 @@  discard block
 block discarded – undo
1155 1240
 			{
1156 1241
 				foreach ($listofdir as $filename)
1157 1242
 				{
1158
-					if ($nophperrors) $ok=@unlink($filename);
1159
-					else $ok=unlink($filename);
1243
+					if ($nophperrors) {
1244
+						$ok=@unlink($filename);
1245
+					} else {
1246
+						$ok=unlink($filename);
1247
+					}
1160 1248
 					if ($ok)
1161 1249
 					{
1162 1250
 						dol_syslog("Removed file ".$filename, LOG_DEBUG);
1163 1251
 
1164 1252
 						// Delete entry into ecm database
1165 1253
 						$rel_filetodelete = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $filename);
1166
-						if (! preg_match('/(\/temp\/|\/thumbs\/|\.meta$)/', $rel_filetodelete))     // If not a tmp file
1254
+						if (! preg_match('/(\/temp\/|\/thumbs\/|\.meta$)/', $rel_filetodelete)) {
1255
+							// If not a tmp file
1167 1256
 						{
1168 1257
 							$rel_filetodelete = preg_replace('/^[\\/]/', '', $rel_filetodelete);
1258
+						}
1169 1259
 
1170 1260
 							dol_syslog("Try to remove also entries in database for full relative path = ".$rel_filetodelete, LOG_DEBUG);
1171 1261
 							include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
@@ -1180,21 +1270,28 @@  discard block
 block discarded – undo
1180 1270
 								setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings');
1181 1271
 							}
1182 1272
 						}
1273
+					} else {
1274
+						dol_syslog("Failed to remove file ".$filename, LOG_WARNING);
1183 1275
 					}
1184
-					else dol_syslog("Failed to remove file ".$filename, LOG_WARNING);
1185 1276
 					// TODO Failure to remove can be because file was already removed or because of permission
1186 1277
 					// If error because of not exists, we must should return true and we should return false if this is a permission problem
1187 1278
 				}
1279
+			} else {
1280
+				dol_syslog("No files to delete found", LOG_DEBUG);
1188 1281
 			}
1189
-			else dol_syslog("No files to delete found", LOG_DEBUG);
1190
-		}
1191
-		else
1282
+		} else
1192 1283
 		{
1193 1284
 			$ok=false;
1194
-			if ($nophperrors) $ok=@unlink($file_osencoded);
1195
-			else $ok=unlink($file_osencoded);
1196
-			if ($ok) dol_syslog("Removed file ".$file_osencoded, LOG_DEBUG);
1197
-			else dol_syslog("Failed to remove file ".$file_osencoded, LOG_WARNING);
1285
+			if ($nophperrors) {
1286
+				$ok=@unlink($file_osencoded);
1287
+			} else {
1288
+				$ok=unlink($file_osencoded);
1289
+			}
1290
+			if ($ok) {
1291
+				dol_syslog("Removed file ".$file_osencoded, LOG_DEBUG);
1292
+			} else {
1293
+				dol_syslog("Failed to remove file ".$file_osencoded, LOG_WARNING);
1294
+			}
1198 1295
 		}
1199 1296
 
1200 1297
 		return $ok;
@@ -1244,19 +1341,23 @@  discard block
 block discarded – undo
1244 1341
 		{
1245 1342
 			while (false !== ($item = readdir($handle)))
1246 1343
 			{
1247
-				if (! utf8_check($item)) $item=utf8_encode($item);  // should be useless
1344
+				if (! utf8_check($item)) {
1345
+					$item=utf8_encode($item);
1346
+				}
1347
+				// should be useless
1248 1348
 
1249 1349
 				if ($item != "." && $item != "..")
1250 1350
 				{
1251 1351
 					if (is_dir(dol_osencode("$dir/$item")) && ! is_link(dol_osencode("$dir/$item")))
1252 1352
 					{
1253 1353
 						$count=dol_delete_dir_recursive("$dir/$item", $count, $nophperrors, 0, $countdeleted);
1254
-					}
1255
-					else
1354
+					} else
1256 1355
 					{
1257 1356
 						$result=dol_delete_file("$dir/$item", 1, $nophperrors);
1258 1357
 						$count++;
1259
-						if ($result) $countdeleted++;
1358
+						if ($result) {
1359
+							$countdeleted++;
1360
+						}
1260 1361
 					}
1261 1362
 				}
1262 1363
 			}
@@ -1266,7 +1367,9 @@  discard block
 block discarded – undo
1266 1367
 			{
1267 1368
 				$result=dol_delete_dir($dir, $nophperrors);
1268 1369
 				$count++;
1269
-				if ($result) $countdeleted++;
1370
+				if ($result) {
1371
+					$countdeleted++;
1372
+				}
1270 1373
 			}
1271 1374
 		}
1272 1375
 	}
@@ -1290,15 +1393,25 @@  discard block
 block discarded – undo
1290 1393
 	// Define parent dir of elements
1291 1394
 	$element = $object->element;
1292 1395
 
1293
-	if ($object->element == 'order_supplier')		$dir = $conf->fournisseur->commande->dir_output;
1294
-	elseif ($object->element == 'invoice_supplier')	$dir = $conf->fournisseur->facture->dir_output;
1295
-	elseif ($object->element == 'project')			$dir = $conf->projet->dir_output;
1296
-	elseif ($object->element == 'shipping')			$dir = $conf->expedition->dir_output.'/sending';
1297
-	elseif ($object->element == 'delivery')			$dir = $conf->expedition->dir_output.'/receipt';
1298
-	elseif ($object->element == 'fichinter')		$dir = $conf->ficheinter->dir_output;
1299
-	else $dir=empty($conf->$element->dir_output)?'':$conf->$element->dir_output;
1396
+	if ($object->element == 'order_supplier') {
1397
+		$dir = $conf->fournisseur->commande->dir_output;
1398
+	} elseif ($object->element == 'invoice_supplier') {
1399
+		$dir = $conf->fournisseur->facture->dir_output;
1400
+	} elseif ($object->element == 'project') {
1401
+		$dir = $conf->projet->dir_output;
1402
+	} elseif ($object->element == 'shipping') {
1403
+		$dir = $conf->expedition->dir_output.'/sending';
1404
+	} elseif ($object->element == 'delivery') {
1405
+		$dir = $conf->expedition->dir_output.'/receipt';
1406
+	} elseif ($object->element == 'fichinter') {
1407
+		$dir = $conf->ficheinter->dir_output;
1408
+	} else {
1409
+		$dir=empty($conf->$element->dir_output)?'':$conf->$element->dir_output;
1410
+	}
1300 1411
 
1301
-	if (empty($dir)) return 'ErrorObjectNoSupportedByFunction';
1412
+	if (empty($dir)) {
1413
+		return 'ErrorObjectNoSupportedByFunction';
1414
+	}
1302 1415
 
1303 1416
 	$refsan = dol_sanitizeFileName($object->ref);
1304 1417
 	$dir = $dir . "/" . $refsan ;
@@ -1331,8 +1444,7 @@  discard block
 block discarded – undo
1331 1444
 			$object->error=$langs->trans("ErrorFailedToDeleteFile",$filepreviewold);
1332 1445
 			return 0;
1333 1446
 		}
1334
-	}
1335
-	else
1447
+	} else
1336 1448
 	{
1337 1449
 		$multiple = $filepreviewold . ".";
1338 1450
 		for ($i = 0; $i < 20; $i++)
@@ -1366,18 +1478,29 @@  discard block
 block discarded – undo
1366 1478
 	global $conf;
1367 1479
 
1368 1480
 	// Create meta file
1369
-	if (empty($conf->global->MAIN_DOC_CREATE_METAFILE)) return 0;	// By default, no metafile.
1481
+	if (empty($conf->global->MAIN_DOC_CREATE_METAFILE)) {
1482
+		return 0;
1483
+	}
1484
+	// By default, no metafile.
1370 1485
 
1371 1486
 	// Define parent dir of elements
1372 1487
 	$element=$object->element;
1373 1488
 
1374
-	if ($object->element == 'order_supplier')		$dir = $conf->fournisseur->dir_output.'/commande';
1375
-	elseif ($object->element == 'invoice_supplier')	$dir = $conf->fournisseur->dir_output.'/facture';
1376
-	elseif ($object->element == 'project')			$dir = $conf->projet->dir_output;
1377
-	elseif ($object->element == 'shipping')			$dir = $conf->expedition->dir_output.'/sending';
1378
-	elseif ($object->element == 'delivery')			$dir = $conf->expedition->dir_output.'/receipt';
1379
-	elseif ($object->element == 'fichinter')		$dir = $conf->ficheinter->dir_output;
1380
-	else $dir=empty($conf->$element->dir_output)?'':$conf->$element->dir_output;
1489
+	if ($object->element == 'order_supplier') {
1490
+		$dir = $conf->fournisseur->dir_output.'/commande';
1491
+	} elseif ($object->element == 'invoice_supplier') {
1492
+		$dir = $conf->fournisseur->dir_output.'/facture';
1493
+	} elseif ($object->element == 'project') {
1494
+		$dir = $conf->projet->dir_output;
1495
+	} elseif ($object->element == 'shipping') {
1496
+		$dir = $conf->expedition->dir_output.'/sending';
1497
+	} elseif ($object->element == 'delivery') {
1498
+		$dir = $conf->expedition->dir_output.'/receipt';
1499
+	} elseif ($object->element == 'fichinter') {
1500
+		$dir = $conf->ficheinter->dir_output;
1501
+	} else {
1502
+		$dir=empty($conf->$element->dir_output)?'':$conf->$element->dir_output;
1503
+	}
1381 1504
 
1382 1505
 	if ($dir)
1383 1506
 	{
@@ -1417,12 +1540,12 @@  discard block
 block discarded – undo
1417 1540
 		$fp = fopen($file,"w");
1418 1541
 		fputs($fp,$meta);
1419 1542
 		fclose($fp);
1420
-		if (! empty($conf->global->MAIN_UMASK))
1421
-		@chmod($file, octdec($conf->global->MAIN_UMASK));
1543
+		if (! empty($conf->global->MAIN_UMASK)) {
1544
+				@chmod($file, octdec($conf->global->MAIN_UMASK));
1545
+		}
1422 1546
 
1423 1547
 		return 1;
1424
-	}
1425
-	else
1548
+	} else
1426 1549
 	{
1427 1550
 		dol_syslog('FailedToDetectDirInDolMetaCreateFor'.$object->element, LOG_WARNING);
1428 1551
 	}
@@ -1484,9 +1607,11 @@  discard block
 block discarded – undo
1484 1607
 
1485 1608
 	$res = 0;
1486 1609
 
1487
-	if (! empty($_FILES[$varfiles])) // For view $_FILES[$varfiles]['error']
1610
+	if (! empty($_FILES[$varfiles])) {
1611
+		// For view $_FILES[$varfiles]['error']
1488 1612
 	{
1489 1613
 		dol_syslog('dol_add_file_process upload_dir='.$upload_dir.' allowoverwrite='.$allowoverwrite.' donotupdatesession='.$donotupdatesession.' savingdocmask='.$savingdocmask, LOG_DEBUG);
1614
+	}
1490 1615
 		if (dol_mkdir($upload_dir) >= 0)
1491 1616
 		{
1492 1617
 			$TFile = $_FILES[$varfiles];
@@ -1520,9 +1645,11 @@  discard block
 block discarded – undo
1520 1645
 
1521 1646
 				$resupload = dol_move_uploaded_file($TFile['tmp_name'][$i], $destfull, $allowoverwrite, 0, $TFile['error'][$i], 0, $varfiles);
1522 1647
 
1523
-				if (is_numeric($resupload) && $resupload > 0)   // $resupload can be 'ErrorFileAlreadyExists'
1648
+				if (is_numeric($resupload) && $resupload > 0) {
1649
+					// $resupload can be 'ErrorFileAlreadyExists'
1524 1650
 				{
1525 1651
 					global $maxwidthsmall, $maxheightsmall, $maxwidthmini, $maxheightmini;
1652
+				}
1526 1653
 
1527 1654
 					include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
1528 1655
 
@@ -1562,19 +1689,20 @@  discard block
 block discarded – undo
1562 1689
 					}
1563 1690
 
1564 1691
 					$nbok++;
1565
-				}
1566
-				else
1692
+				} else
1567 1693
 				{
1568 1694
 					$langs->load("errors");
1569
-					if ($resupload < 0)	// Unknown error
1695
+					if ($resupload < 0) {
1696
+						// Unknown error
1570 1697
 					{
1571 1698
 						setEventMessages($langs->trans("ErrorFileNotUploaded"), null, 'errors');
1572 1699
 					}
1573
-					else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload))	// Files infected by a virus
1700
+					} else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) {
1701
+						// Files infected by a virus
1574 1702
 					{
1575 1703
 						setEventMessages($langs->trans("ErrorFileIsInfectedWithAVirus"), null, 'errors');
1576 1704
 					}
1577
-					else	// Known error
1705
+					} else	// Known error
1578 1706
 					{
1579 1707
 						setEventMessages($langs->trans($resupload), null, 'errors');
1580 1708
 					}
@@ -1601,8 +1729,7 @@  discard block
 block discarded – undo
1601 1729
 		} else {
1602 1730
 			setEventMessages($langs->trans("ErrorFileNotLinked"), null, 'errors');
1603 1731
 		}
1604
-	}
1605
-	else
1732
+	} else
1606 1733
 	{
1607 1734
 		$langs->load("errors");
1608 1735
 		setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("File")), null, 'errors');
@@ -1633,16 +1760,27 @@  discard block
 block discarded – undo
1633 1760
 	$listofnames=array();
1634 1761
 	$listofmimes=array();
1635 1762
 	$keytoavoidconflict = empty($trackid)?'':'-'.$trackid;
1636
-	if (! empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths=explode(';',$_SESSION["listofpaths".$keytoavoidconflict]);
1637
-	if (! empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames=explode(';',$_SESSION["listofnames".$keytoavoidconflict]);
1638
-	if (! empty($_SESSION["listofmimes".$keytoavoidconflict])) $listofmimes=explode(';',$_SESSION["listofmimes".$keytoavoidconflict]);
1763
+	if (! empty($_SESSION["listofpaths".$keytoavoidconflict])) {
1764
+		$listofpaths=explode(';',$_SESSION["listofpaths".$keytoavoidconflict]);
1765
+	}
1766
+	if (! empty($_SESSION["listofnames".$keytoavoidconflict])) {
1767
+		$listofnames=explode(';',$_SESSION["listofnames".$keytoavoidconflict]);
1768
+	}
1769
+	if (! empty($_SESSION["listofmimes".$keytoavoidconflict])) {
1770
+		$listofmimes=explode(';',$_SESSION["listofmimes".$keytoavoidconflict]);
1771
+	}
1639 1772
 
1640 1773
 	if ($keytodelete >= 0)
1641 1774
 	{
1642 1775
 		$pathtodelete=$listofpaths[$keytodelete];
1643 1776
 		$filetodelete=$listofnames[$keytodelete];
1644
-		if (empty($donotdeletefile)) $result = dol_delete_file($pathtodelete,1);  // The delete of ecm database is inside the function dol_delete_file
1645
-		else $result=0;
1777
+		if (empty($donotdeletefile)) {
1778
+			$result = dol_delete_file($pathtodelete,1);
1779
+		}
1780
+		// The delete of ecm database is inside the function dol_delete_file
1781
+		else {
1782
+			$result=0;
1783
+		}
1646 1784
 		if ($result >= 0)
1647 1785
 		{
1648 1786
 			if (empty($donotdeletefile))
@@ -1682,9 +1820,11 @@  discard block
 block discarded – undo
1682 1820
 
1683 1821
 	$rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $dir);
1684 1822
 
1685
-	if (! preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir))     // If not a tmp dir
1823
+	if (! preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) {
1824
+		// If not a tmp dir
1686 1825
 	{
1687 1826
 		$filename = basename($file);
1827
+	}
1688 1828
 		$rel_dir = preg_replace('/[\\/]$/', '', $rel_dir);
1689 1829
 		$rel_dir = preg_replace('/^[\\/]/', '', $rel_dir);
1690 1830
 
@@ -1747,8 +1887,12 @@  discard block
 block discarded – undo
1747 1887
 		$sql = 'DELETE FROM ' . MAIN_DB_PREFIX . 'ecm_files';
1748 1888
 		$sql.= ' WHERE entity = '.$conf->entity;
1749 1889
 		$sql.= " AND filepath = '" . $db->escape($rel_dir) . "'";
1750
-		if ($file) $sql.= " AND filename = '" . $db->escape($file) . "'";
1751
-		if ($mode) $sql.= " AND gen_or_uploaded = '" . $db->escape($mode) . "'";
1890
+		if ($file) {
1891
+			$sql.= " AND filename = '" . $db->escape($file) . "'";
1892
+		}
1893
+		if ($mode) {
1894
+			$sql.= " AND gen_or_uploaded = '" . $db->escape($mode) . "'";
1895
+		}
1752 1896
 
1753 1897
 		$resql = $db->query($sql);
1754 1898
 		if (!$resql)
@@ -1796,32 +1940,33 @@  discard block
 block discarded – undo
1796 1940
 			$ret = $image->setImageFormat($ext);
1797 1941
 			if ($ret)
1798 1942
 			{
1799
-				if (empty($fileoutput)) $fileoutput=$fileinput.".".$ext;
1943
+				if (empty($fileoutput)) {
1944
+					$fileoutput=$fileinput.".".$ext;
1945
+				}
1800 1946
 
1801 1947
 				$count = $image->getNumberImages();
1802 1948
 
1803 1949
 				if (! dol_is_file($fileoutput) || is_writeable($fileoutput))
1804 1950
 				{
1805 1951
 					$ret = $image->writeImages($fileoutput, true);
1806
-				}
1807
-				else
1952
+				} else
1808 1953
 				{
1809 1954
 					dol_syslog("Warning: Failed to write cache preview file '.$fileoutput.'. Check permission on file/dir", LOG_ERR);
1810 1955
 				}
1811
-				if ($ret) return $count;
1812
-				else return -3;
1813
-			}
1814
-			else
1956
+				if ($ret) {
1957
+					return $count;
1958
+				} else {
1959
+					return -3;
1960
+				}
1961
+			} else
1815 1962
 			{
1816 1963
 				return -2;
1817 1964
 			}
1818
-		}
1819
-		else
1965
+		} else
1820 1966
 		{
1821 1967
 			return -1;
1822 1968
 		}
1823
-	}
1824
-	else
1969
+	} else
1825 1970
 	{
1826 1971
 		return 0;
1827 1972
 	}
@@ -1843,9 +1988,7 @@  discard block
 block discarded – undo
1843 1988
 	try
1844 1989
 	{
1845 1990
 		$data = implode("", file(dol_osencode($inputfile)));
1846
-		if ($mode == 'gz')     { $foundhandler=1; $compressdata = gzencode($data, 9); }
1847
-		elseif ($mode == 'bz') { $foundhandler=1; $compressdata = bzcompress($data, 9); }
1848
-		elseif ($mode == 'zip')
1991
+		if ($mode == 'gz')     { $foundhandler=1; $compressdata = gzencode($data, 9); } elseif ($mode == 'bz') { $foundhandler=1; $compressdata = bzcompress($data, 9); } elseif ($mode == 'zip')
1849 1992
 		{
1850 1993
 			if (defined('ODTPHP_PATHTOPCLZIP'))
1851 1994
 			{
@@ -1865,14 +2008,12 @@  discard block
 block discarded – undo
1865 2008
 			fwrite($fp, $compressdata);
1866 2009
 			fclose($fp);
1867 2010
 			return 1;
1868
-		}
1869
-		else
2011
+		} else
1870 2012
 		{
1871 2013
 			dol_syslog("Try to zip with format ".$mode." with no handler for this format",LOG_ERR);
1872 2014
 			return -2;
1873 2015
 		}
1874
-	}
1875
-	catch (Exception $e)
2016
+	} catch (Exception $e)
1876 2017
 	{
1877 2018
 		global $langs, $errormsg;
1878 2019
 		$langs->load("errors");
@@ -1900,8 +2041,9 @@  discard block
 block discarded – undo
1900 2041
 		$archive = new PclZip($inputfile);
1901 2042
 		$result=$archive->extract(PCLZIP_OPT_PATH, $outputdir);
1902 2043
 		//var_dump($result);
1903
-		if (! is_array($result) && $result <= 0) return array('error'=>$archive->errorInfo(true));
1904
-		else
2044
+		if (! is_array($result) && $result <= 0) {
2045
+			return array('error'=>$archive->errorInfo(true));
2046
+		} else
1905 2047
 		{
1906 2048
 			$ok=1; $errmsg='';
1907 2049
 			// Loop on each file to check result for unzipping file
@@ -1916,8 +2058,11 @@  discard block
 block discarded – undo
1916 2058
 				}
1917 2059
 			}
1918 2060
 
1919
-			if ($ok) return array();
1920
-			else return array('error'=>$errmsg);
2061
+			if ($ok) {
2062
+				return array();
2063
+			} else {
2064
+				return array('error'=>$errmsg);
2065
+			}
1921 2066
 		}
1922 2067
 	}
1923 2068
 
@@ -1931,8 +2076,7 @@  discard block
 block discarded – undo
1931 2076
 			$zip->extractTo($outputdir.'/');
1932 2077
 			$zip->close();
1933 2078
 			return array();
1934
-		}
1935
-		else
2079
+		} else
1936 2080
 		{
1937 2081
 			return array('error'=>'ErrUnzipFails');
1938 2082
 		}
@@ -1966,9 +2110,7 @@  discard block
 block discarded – undo
1966 2110
 
1967 2111
 	try
1968 2112
 	{
1969
-		if ($mode == 'gz')     { $foundhandler=0; }
1970
-		elseif ($mode == 'bz') { $foundhandler=0; }
1971
-		elseif ($mode == 'zip')
2113
+		if ($mode == 'gz')     { $foundhandler=0; } elseif ($mode == 'bz') { $foundhandler=0; } elseif ($mode == 'zip')
1972 2114
 		{
1973 2115
 			/*if (defined('ODTPHP_PATHTOPCLZIP'))
1974 2116
             {
@@ -2021,13 +2163,11 @@  discard block
 block discarded – undo
2021 2163
 		{
2022 2164
 			dol_syslog("Try to zip with format ".$mode." with no handler for this format",LOG_ERR);
2023 2165
 			return -2;
2024
-		}
2025
-		else
2166
+		} else
2026 2167
 		{
2027 2168
 			return 0;
2028 2169
 		}
2029
-	}
2030
-	catch (Exception $e)
2170
+	} catch (Exception $e)
2031 2171
 	{
2032 2172
 		global $langs, $errormsg;
2033 2173
 		$langs->load("errors");
@@ -2073,13 +2213,20 @@  discard block
 block discarded – undo
2073 2213
 	global $conf, $db, $user;
2074 2214
 	global $dolibarr_main_data_root, $dolibarr_main_document_root_alt;
2075 2215
 
2076
-	if (! is_object($fuser)) $fuser=$user;
2216
+	if (! is_object($fuser)) {
2217
+		$fuser=$user;
2218
+	}
2077 2219
 
2078
-	if (empty($modulepart)) return 'ErrorBadParameter';
2220
+	if (empty($modulepart)) {
2221
+		return 'ErrorBadParameter';
2222
+	}
2079 2223
 	if (empty($entity))
2080 2224
 	{
2081
-		if (empty($conf->multicompany->enabled)) $entity=1;
2082
-		else $entity=0;
2225
+		if (empty($conf->multicompany->enabled)) {
2226
+			$entity=1;
2227
+		} else {
2228
+			$entity=0;
2229
+		}
2083 2230
 	}
2084 2231
 	dol_syslog('modulepart='.$modulepart.' original_file='.$original_file.' entity='.$entity);
2085 2232
 	// We define $accessallowed and $sqlprotectagainstexternals
@@ -2088,7 +2235,9 @@  discard block
 block discarded – undo
2088 2235
 	$ret=array();
2089 2236
 
2090 2237
 	// Find the subdirectory name as the reference. For exemple original_file='10/myfile.pdf' -> refname='10'
2091
-	if (empty($refname)) $refname=basename(dirname($original_file)."/");
2238
+	if (empty($refname)) {
2239
+		$refname=basename(dirname($original_file)."/");
2240
+	}
2092 2241
 
2093 2242
 	$relative_original_file = $original_file;
2094 2243
 
@@ -2102,7 +2251,9 @@  discard block
 block discarded – undo
2102 2251
 	// Wrapping for miscellaneous medias files
2103 2252
 	if ($modulepart == 'medias' && !empty($dolibarr_main_data_root))
2104 2253
 	{
2105
-		if (empty($entity) || empty($conf->medias->multidir_output[$entity])) return array('accessallowed'=>0, 'error'=>'Value entity must be provided');
2254
+		if (empty($entity) || empty($conf->medias->multidir_output[$entity])) {
2255
+			return array('accessallowed'=>0, 'error'=>'Value entity must be provided');
2256
+		}
2106 2257
 		$accessallowed=1;
2107 2258
 		$original_file=$conf->medias->multidir_output[$entity].'/'.$original_file;
2108 2259
 	}
@@ -2143,132 +2294,176 @@  discard block
 block discarded – undo
2143 2294
 	// Wrapping pour les apercu factures
2144 2295
 	elseif ($modulepart == 'apercufacture' && !empty($conf->facture->dir_output))
2145 2296
 	{
2146
-		if ($fuser->rights->facture->{$lire}) $accessallowed=1;
2297
+		if ($fuser->rights->facture->{$lire}) {
2298
+			$accessallowed=1;
2299
+		}
2147 2300
 		$original_file=$conf->facture->dir_output.'/'.$original_file;
2148 2301
 	}
2149 2302
 	// Wrapping pour les apercu propal
2150 2303
 	elseif ($modulepart == 'apercupropal' && !empty($conf->propal->dir_output))
2151 2304
 	{
2152
-		if ($fuser->rights->propale->{$lire}) $accessallowed=1;
2305
+		if ($fuser->rights->propale->{$lire}) {
2306
+			$accessallowed=1;
2307
+		}
2153 2308
 		$original_file=$conf->propal->dir_output.'/'.$original_file;
2154 2309
 	}
2155 2310
 	// Wrapping pour les apercu commande
2156 2311
 	elseif ($modulepart == 'apercucommande' && !empty($conf->commande->dir_output))
2157 2312
 	{
2158
-		if ($fuser->rights->commande->{$lire}) $accessallowed=1;
2313
+		if ($fuser->rights->commande->{$lire}) {
2314
+			$accessallowed=1;
2315
+		}
2159 2316
 		$original_file=$conf->commande->dir_output.'/'.$original_file;
2160 2317
 	}
2161 2318
 	// Wrapping pour les apercu intervention
2162 2319
 	elseif (($modulepart == 'apercufichinter' || $modulepart == 'apercuficheinter') && !empty($conf->ficheinter->dir_output))
2163 2320
 	{
2164
-		if ($fuser->rights->ficheinter->{$lire}) $accessallowed=1;
2321
+		if ($fuser->rights->ficheinter->{$lire}) {
2322
+			$accessallowed=1;
2323
+		}
2165 2324
 		$original_file=$conf->ficheinter->dir_output.'/'.$original_file;
2166 2325
 	}
2167 2326
 	// Wrapping pour les apercu conat
2168 2327
 	elseif (($modulepart == 'apercucontract') && !empty($conf->contrat->dir_output))
2169 2328
 	{
2170
-		if ($fuser->rights->contrat->{$lire}) $accessallowed=1;
2329
+		if ($fuser->rights->contrat->{$lire}) {
2330
+			$accessallowed=1;
2331
+		}
2171 2332
 		$original_file=$conf->contrat->dir_output.'/'.$original_file;
2172 2333
 	}
2173 2334
 	// Wrapping pour les apercu supplier proposal
2174 2335
 	elseif (($modulepart == 'apercusupplier_proposal' || $modulepart == 'apercusupplier_proposal') && !empty($conf->supplier_proposal->dir_output))
2175 2336
 	{
2176
-		if ($fuser->rights->supplier_proposal->{$lire}) $accessallowed=1;
2337
+		if ($fuser->rights->supplier_proposal->{$lire}) {
2338
+			$accessallowed=1;
2339
+		}
2177 2340
 		$original_file=$conf->supplier_proposal->dir_output.'/'.$original_file;
2178 2341
 	}
2179 2342
 	// Wrapping pour les apercu supplier order
2180 2343
 	elseif (($modulepart == 'apercusupplier_order' || $modulepart == 'apercusupplier_order') && !empty($conf->fournisseur->commande->dir_output))
2181 2344
 	{
2182
-		if ($fuser->rights->fournisseur->commande->{$lire}) $accessallowed=1;
2345
+		if ($fuser->rights->fournisseur->commande->{$lire}) {
2346
+			$accessallowed=1;
2347
+		}
2183 2348
 		$original_file=$conf->fournisseur->commande->dir_output.'/'.$original_file;
2184 2349
 	}
2185 2350
 	// Wrapping pour les apercu supplier invoice
2186 2351
 	elseif (($modulepart == 'apercusupplier_invoice' || $modulepart == 'apercusupplier_invoice') && !empty($conf->fournisseur->facture->dir_output))
2187 2352
 	{
2188
-		if ($fuser->rights->fournisseur->facture->{$lire}) $accessallowed=1;
2353
+		if ($fuser->rights->fournisseur->facture->{$lire}) {
2354
+			$accessallowed=1;
2355
+		}
2189 2356
 		$original_file=$conf->fournisseur->facture->dir_output.'/'.$original_file;
2190 2357
 	}
2191 2358
 	// Wrapping pour les apercu supplier invoice
2192 2359
 	elseif (($modulepart == 'apercuexpensereport') && !empty($conf->expensereport->dir_output))
2193 2360
 	{
2194
-		if ($fuser->rights->expensereport->{$lire}) $accessallowed=1;
2361
+		if ($fuser->rights->expensereport->{$lire}) {
2362
+			$accessallowed=1;
2363
+		}
2195 2364
 		$original_file=$conf->expensereport->dir_output.'/'.$original_file;
2196 2365
 	}
2197 2366
 	// Wrapping pour les images des stats propales
2198 2367
 	elseif ($modulepart == 'propalstats' && !empty($conf->propal->dir_temp))
2199 2368
 	{
2200
-		if ($fuser->rights->propale->{$lire}) $accessallowed=1;
2369
+		if ($fuser->rights->propale->{$lire}) {
2370
+			$accessallowed=1;
2371
+		}
2201 2372
 		$original_file=$conf->propal->dir_temp.'/'.$original_file;
2202 2373
 	}
2203 2374
 	// Wrapping pour les images des stats commandes
2204 2375
 	elseif ($modulepart == 'orderstats' && !empty($conf->commande->dir_temp))
2205 2376
 	{
2206
-		if ($fuser->rights->commande->{$lire}) $accessallowed=1;
2377
+		if ($fuser->rights->commande->{$lire}) {
2378
+			$accessallowed=1;
2379
+		}
2207 2380
 		$original_file=$conf->commande->dir_temp.'/'.$original_file;
2208
-	}
2209
-	elseif ($modulepart == 'orderstatssupplier' && !empty($conf->fournisseur->dir_output))
2381
+	} elseif ($modulepart == 'orderstatssupplier' && !empty($conf->fournisseur->dir_output))
2210 2382
 	{
2211
-		if ($fuser->rights->fournisseur->commande->{$lire}) $accessallowed=1;
2383
+		if ($fuser->rights->fournisseur->commande->{$lire}) {
2384
+			$accessallowed=1;
2385
+		}
2212 2386
 		$original_file=$conf->fournisseur->commande->dir_temp.'/'.$original_file;
2213 2387
 	}
2214 2388
 	// Wrapping pour les images des stats factures
2215 2389
 	elseif ($modulepart == 'billstats' && !empty($conf->facture->dir_temp))
2216 2390
 	{
2217
-		if ($fuser->rights->facture->{$lire}) $accessallowed=1;
2391
+		if ($fuser->rights->facture->{$lire}) {
2392
+			$accessallowed=1;
2393
+		}
2218 2394
 		$original_file=$conf->facture->dir_temp.'/'.$original_file;
2219
-	}
2220
-	elseif ($modulepart == 'billstatssupplier' && !empty($conf->fournisseur->dir_output))
2395
+	} elseif ($modulepart == 'billstatssupplier' && !empty($conf->fournisseur->dir_output))
2221 2396
 	{
2222
-		if ($fuser->rights->fournisseur->facture->{$lire}) $accessallowed=1;
2397
+		if ($fuser->rights->fournisseur->facture->{$lire}) {
2398
+			$accessallowed=1;
2399
+		}
2223 2400
 		$original_file=$conf->fournisseur->facture->dir_temp.'/'.$original_file;
2224 2401
 	}
2225 2402
 	// Wrapping pour les images des stats expeditions
2226 2403
 	elseif ($modulepart == 'expeditionstats' && !empty($conf->expedition->dir_temp))
2227 2404
 	{
2228
-		if ($fuser->rights->expedition->{$lire}) $accessallowed=1;
2405
+		if ($fuser->rights->expedition->{$lire}) {
2406
+			$accessallowed=1;
2407
+		}
2229 2408
 		$original_file=$conf->expedition->dir_temp.'/'.$original_file;
2230 2409
 	}
2231 2410
 	// Wrapping pour les images des stats expeditions
2232 2411
 	elseif ($modulepart == 'tripsexpensesstats' && !empty($conf->deplacement->dir_temp))
2233 2412
 	{
2234
-		if ($fuser->rights->deplacement->{$lire}) $accessallowed=1;
2413
+		if ($fuser->rights->deplacement->{$lire}) {
2414
+			$accessallowed=1;
2415
+		}
2235 2416
 		$original_file=$conf->deplacement->dir_temp.'/'.$original_file;
2236 2417
 	}
2237 2418
 	// Wrapping pour les images des stats expeditions
2238 2419
 	elseif ($modulepart == 'memberstats' && !empty($conf->adherent->dir_temp))
2239 2420
 	{
2240
-		if ($fuser->rights->adherent->{$lire}) $accessallowed=1;
2421
+		if ($fuser->rights->adherent->{$lire}) {
2422
+			$accessallowed=1;
2423
+		}
2241 2424
 		$original_file=$conf->adherent->dir_temp.'/'.$original_file;
2242 2425
 	}
2243 2426
 	// Wrapping pour les images des stats produits
2244 2427
 	elseif (preg_match('/^productstats_/i',$modulepart) && !empty($conf->product->dir_temp))
2245 2428
 	{
2246
-		if ($fuser->rights->produit->{$lire} || $fuser->rights->service->{$lire}) $accessallowed=1;
2429
+		if ($fuser->rights->produit->{$lire} || $fuser->rights->service->{$lire}) {
2430
+			$accessallowed=1;
2431
+		}
2247 2432
 		$original_file=(!empty($conf->product->multidir_temp[$entity])?$conf->product->multidir_temp[$entity]:$conf->service->multidir_temp[$entity]).'/'.$original_file;
2248 2433
 	}
2249 2434
 	// Wrapping for taxes
2250 2435
 	elseif ($modulepart == 'tax' && !empty($conf->tax->dir_output))
2251 2436
 	{
2252
-		if ($fuser->rights->tax->charges->{$lire}) $accessallowed=1;
2437
+		if ($fuser->rights->tax->charges->{$lire}) {
2438
+			$accessallowed=1;
2439
+		}
2253 2440
 		$original_file=$conf->tax->dir_output.'/'.$original_file;
2254 2441
 	}
2255 2442
 	// Wrapping for events
2256 2443
 	elseif ($modulepart == 'actions' && !empty($conf->agenda->dir_output))
2257 2444
 	{
2258
-		if ($fuser->rights->agenda->myactions->{$read}) $accessallowed=1;
2445
+		if ($fuser->rights->agenda->myactions->{$read}) {
2446
+			$accessallowed=1;
2447
+		}
2259 2448
 		$original_file=$conf->agenda->dir_output.'/'.$original_file;
2260 2449
 	}
2261 2450
 	// Wrapping for categories
2262 2451
 	elseif ($modulepart == 'category' && !empty($conf->categorie->dir_output))
2263 2452
 	{
2264
-		if (empty($entity) || empty($conf->categorie->multidir_output[$entity])) return array('accessallowed'=>0, 'error'=>'Value entity must be provided');
2265
-		if ($fuser->rights->categorie->{$lire}) $accessallowed=1;
2453
+		if (empty($entity) || empty($conf->categorie->multidir_output[$entity])) {
2454
+			return array('accessallowed'=>0, 'error'=>'Value entity must be provided');
2455
+		}
2456
+		if ($fuser->rights->categorie->{$lire}) {
2457
+			$accessallowed=1;
2458
+		}
2266 2459
 		$original_file=$conf->categorie->multidir_output[$entity].'/'.$original_file;
2267 2460
 	}
2268 2461
 	// Wrapping pour les prelevements
2269 2462
 	elseif ($modulepart == 'prelevement' && !empty($conf->prelevement->dir_output))
2270 2463
 	{
2271
-		if ($fuser->rights->prelevement->bons->{$lire} || preg_match('/^specimen/i',$original_file)) $accessallowed=1;
2464
+		if ($fuser->rights->prelevement->bons->{$lire} || preg_match('/^specimen/i',$original_file)) {
2465
+			$accessallowed=1;
2466
+		}
2272 2467
 		$original_file=$conf->prelevement->dir_output.'/'.$original_file;
2273 2468
 	}
2274 2469
 	// Wrapping pour les graph energie
@@ -2331,7 +2526,9 @@  discard block
 block discarded – undo
2331 2526
 	// Wrapping for third parties
2332 2527
 	else if (($modulepart == 'company' || $modulepart == 'societe') && !empty($conf->societe->dir_output))
2333 2528
 	{
2334
-		if (empty($entity) || empty($conf->societe->multidir_output[$entity])) return array('accessallowed'=>0, 'error'=>'Value entity must be provided');
2529
+		if (empty($entity) || empty($conf->societe->multidir_output[$entity])) {
2530
+			return array('accessallowed'=>0, 'error'=>'Value entity must be provided');
2531
+		}
2335 2532
 		if ($fuser->rights->societe->{$lire} || preg_match('/^specimen/i',$original_file))
2336 2533
 		{
2337 2534
 			$accessallowed=1;
@@ -2343,7 +2540,9 @@  discard block
 block discarded – undo
2343 2540
 	// Wrapping for contact
2344 2541
 	else if ($modulepart == 'contact' && !empty($conf->societe->dir_output))
2345 2542
 	{
2346
-		if (empty($entity) || empty($conf->societe->multidir_output[$entity])) return array('accessallowed'=>0, 'error'=>'Value entity must be provided');
2543
+		if (empty($entity) || empty($conf->societe->multidir_output[$entity])) {
2544
+			return array('accessallowed'=>0, 'error'=>'Value entity must be provided');
2545
+		}
2347 2546
 		if ($fuser->rights->societe->{$lire})
2348 2547
 		{
2349 2548
 			$accessallowed=1;
@@ -2369,64 +2568,56 @@  discard block
 block discarded – undo
2369 2568
 			$accessallowed=1;
2370 2569
 		}
2371 2570
 		$original_file=$conf->propal->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2372
-	}
2373
-	else if ($modulepart == 'massfilesarea_orders')
2571
+	} else if ($modulepart == 'massfilesarea_orders')
2374 2572
 	{
2375 2573
 		if ($fuser->rights->commande->{$lire} || preg_match('/^specimen/i',$original_file))
2376 2574
 		{
2377 2575
 			$accessallowed=1;
2378 2576
 		}
2379 2577
 		$original_file=$conf->commande->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2380
-	}
2381
-	else if ($modulepart == 'massfilesarea_invoices')
2578
+	} else if ($modulepart == 'massfilesarea_invoices')
2382 2579
 	{
2383 2580
 		if ($fuser->rights->facture->{$lire} || preg_match('/^specimen/i',$original_file))
2384 2581
 		{
2385 2582
 			$accessallowed=1;
2386 2583
 		}
2387 2584
 		$original_file=$conf->facture->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2388
-	}
2389
-	else if ($modulepart == 'massfilesarea_expensereport')
2585
+	} else if ($modulepart == 'massfilesarea_expensereport')
2390 2586
 	{
2391 2587
 		if ($fuser->rights->facture->{$lire} || preg_match('/^specimen/i',$original_file))
2392 2588
 		{
2393 2589
 			$accessallowed=1;
2394 2590
 		}
2395 2591
 		$original_file=$conf->expensereport->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2396
-	}
2397
-	else if ($modulepart == 'massfilesarea_interventions')
2592
+	} else if ($modulepart == 'massfilesarea_interventions')
2398 2593
 	{
2399 2594
 		if ($fuser->rights->ficheinter->{$lire} || preg_match('/^specimen/i',$original_file))
2400 2595
 		{
2401 2596
 			$accessallowed=1;
2402 2597
 		}
2403 2598
 		$original_file=$conf->ficheinter->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2404
-	}
2405
-	else if ($modulepart == 'massfilesarea_supplier_proposal' && !empty($conf->propal->dir_output))
2599
+	} else if ($modulepart == 'massfilesarea_supplier_proposal' && !empty($conf->propal->dir_output))
2406 2600
 	{
2407 2601
 		if ($fuser->rights->supplier_proposal->{$lire} || preg_match('/^specimen/i',$original_file))
2408 2602
 		{
2409 2603
 			$accessallowed=1;
2410 2604
 		}
2411 2605
 		$original_file=$conf->supplier_proposal->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2412
-	}
2413
-	else if ($modulepart == 'massfilesarea_supplier_order')
2606
+	} else if ($modulepart == 'massfilesarea_supplier_order')
2414 2607
 	{
2415 2608
 		if ($fuser->rights->fournisseur->commande->{$lire} || preg_match('/^specimen/i',$original_file))
2416 2609
 		{
2417 2610
 			$accessallowed=1;
2418 2611
 		}
2419 2612
 		$original_file=$conf->fournisseur->commande->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2420
-	}
2421
-	else if ($modulepart == 'massfilesarea_supplier_invoice')
2613
+	} else if ($modulepart == 'massfilesarea_supplier_invoice')
2422 2614
 	{
2423 2615
 		if ($fuser->rights->fournisseur->facture->{$lire} || preg_match('/^specimen/i',$original_file))
2424 2616
 		{
2425 2617
 			$accessallowed=1;
2426 2618
 		}
2427 2619
 		$original_file=$conf->fournisseur->facture->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2428
-	}
2429
-	else if ($modulepart == 'massfilesarea_contract' && !empty($conf->contrat->dir_output))
2620
+	} else if ($modulepart == 'massfilesarea_contract' && !empty($conf->contrat->dir_output))
2430 2621
 	{
2431 2622
 		if ($fuser->rights->contrat->{$lire} || preg_match('/^specimen/i',$original_file))
2432 2623
 		{
@@ -2488,8 +2679,7 @@  discard block
 block discarded – undo
2488 2679
 		}
2489 2680
 		$original_file=$conf->projet->dir_output.'/'.$original_file;
2490 2681
 		$sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."projet WHERE ref='".$db->escape($refname)."' AND entity IN (".getEntity('project').")";
2491
-	}
2492
-	else if ($modulepart == 'project_task' && !empty($conf->projet->dir_output))
2682
+	} else if ($modulepart == 'project_task' && !empty($conf->projet->dir_output))
2493 2683
 	{
2494 2684
 		if ($fuser->rights->projet->{$lire} || preg_match('/^specimen/i',$original_file))
2495 2685
 		{
@@ -2538,8 +2728,11 @@  discard block
 block discarded – undo
2538 2728
 		{
2539 2729
 			$accessallowed=1;
2540 2730
 		}
2541
-		if ($fuser->societe_id > 0) $original_file=$conf->facture->dir_output.'/payments/private/'.$fuser->id.'/'.$original_file;
2542
-		else $original_file=$conf->facture->dir_output.'/payments/'.$original_file;
2731
+		if ($fuser->societe_id > 0) {
2732
+			$original_file=$conf->facture->dir_output.'/payments/private/'.$fuser->id.'/'.$original_file;
2733
+		} else {
2734
+			$original_file=$conf->facture->dir_output.'/payments/'.$original_file;
2735
+		}
2543 2736
 	}
2544 2737
 
2545 2738
 	// Wrapping for accounting exports
@@ -2594,13 +2787,18 @@  discard block
 block discarded – undo
2594 2787
 	// Wrapping pour les produits et services
2595 2788
 	else if ($modulepart == 'product' || $modulepart == 'produit' || $modulepart == 'service' || $modulepart == 'produit|service')
2596 2789
 	{
2597
-		if (empty($entity) || (empty($conf->product->multidir_output[$entity]) && empty($conf->service->multidir_output[$entity]))) return array('accessallowed'=>0, 'error'=>'Value entity must be provided');
2790
+		if (empty($entity) || (empty($conf->product->multidir_output[$entity]) && empty($conf->service->multidir_output[$entity]))) {
2791
+			return array('accessallowed'=>0, 'error'=>'Value entity must be provided');
2792
+		}
2598 2793
 		if (($fuser->rights->produit->{$lire} || $fuser->rights->service->{$lire}) || preg_match('/^specimen/i',$original_file))
2599 2794
 		{
2600 2795
 			$accessallowed=1;
2601 2796
 		}
2602
-		if (! empty($conf->product->enabled)) $original_file=$conf->product->multidir_output[$entity].'/'.$original_file;
2603
-		elseif (! empty($conf->service->enabled)) $original_file=$conf->service->multidir_output[$entity].'/'.$original_file;
2797
+		if (! empty($conf->product->enabled)) {
2798
+			$original_file=$conf->product->multidir_output[$entity].'/'.$original_file;
2799
+		} elseif (! empty($conf->service->enabled)) {
2800
+			$original_file=$conf->service->multidir_output[$entity].'/'.$original_file;
2801
+		}
2604 2802
 	}
2605 2803
 
2606 2804
 	// Wrapping pour les contrats
@@ -2681,14 +2879,18 @@  discard block
 block discarded – undo
2681 2879
 	// Wrapping for backups
2682 2880
 	else if ($modulepart == 'systemtools' && !empty($conf->admin->dir_output))
2683 2881
 	{
2684
-		if ($fuser->admin) $accessallowed=1;
2882
+		if ($fuser->admin) {
2883
+			$accessallowed=1;
2884
+		}
2685 2885
 		$original_file=$conf->admin->dir_output.'/'.$original_file;
2686 2886
 	}
2687 2887
 
2688 2888
 	// Wrapping for upload file test
2689 2889
 	else if ($modulepart == 'admin_temp' && !empty($conf->admin->dir_temp))
2690 2890
 	{
2691
-		if ($fuser->admin) $accessallowed=1;
2891
+		if ($fuser->admin) {
2892
+			$accessallowed=1;
2893
+		}
2692 2894
 		$original_file=$conf->admin->dir_temp.'/'.$original_file;
2693 2895
 	}
2694 2896
 
@@ -2697,7 +2899,9 @@  discard block
 block discarded – undo
2697 2899
 	{
2698 2900
 		$accessallowed=1;
2699 2901
 		$dir='files';
2700
-		if (dol_mimetype($original_file) == 'application/x-bittorrent') $dir='torrents';
2902
+		if (dol_mimetype($original_file) == 'application/x-bittorrent') {
2903
+			$dir='torrents';
2904
+		}
2701 2905
 		$original_file=$conf->bittorrent->dir_output.'/'.$dir.'/'.$original_file;
2702 2906
 	}
2703 2907
 
@@ -2725,45 +2929,62 @@  discard block
 block discarded – undo
2725 2929
 	// If modulepart=module				Allows any module to open a file if file is in directory called DOL_DATA_ROOT/modulepart
2726 2930
 	else
2727 2931
 	{
2728
-		if (preg_match('/^specimen/i',$original_file))	$accessallowed=1;    // If link to a file called specimen. Test must be done before changing $original_file int full path.
2729
-		if ($fuser->admin) $accessallowed=1;    // If user is admin
2932
+		if (preg_match('/^specimen/i',$original_file)) {
2933
+			$accessallowed=1;
2934
+		}
2935
+		// If link to a file called specimen. Test must be done before changing $original_file int full path.
2936
+		if ($fuser->admin) {
2937
+			$accessallowed=1;
2938
+		}
2939
+		// If user is admin
2730 2940
 
2731 2941
 		// Define $accessallowed
2732 2942
 		if (preg_match('/^([a-z]+)_user_temp$/i',$modulepart,$reg))
2733 2943
 		{
2734
-			if (empty($conf->{$reg[1]}->dir_temp))	// modulepart not supported
2944
+			if (empty($conf->{$reg[1]}->dir_temp)) {
2945
+				// modulepart not supported
2735 2946
 			{
2736 2947
 				dol_print_error('','Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')');
2948
+			}
2737 2949
 				exit;
2738 2950
 			}
2739
-			if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) $accessallowed=1;
2951
+			if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) {
2952
+				$accessallowed=1;
2953
+			}
2740 2954
 			$original_file=$conf->{$reg[1]}->dir_temp.'/'.$fuser->id.'/'.$original_file;
2741
-		}
2742
-		else if (preg_match('/^([a-z]+)_temp$/i',$modulepart,$reg))
2955
+		} else if (preg_match('/^([a-z]+)_temp$/i',$modulepart,$reg))
2743 2956
 		{
2744
-			if (empty($conf->{$reg[1]}->dir_temp))	// modulepart not supported
2957
+			if (empty($conf->{$reg[1]}->dir_temp)) {
2958
+				// modulepart not supported
2745 2959
 			{
2746 2960
 				dol_print_error('','Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')');
2961
+			}
2747 2962
 				exit;
2748 2963
 			}
2749
-			if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) $accessallowed=1;
2964
+			if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) {
2965
+				$accessallowed=1;
2966
+			}
2750 2967
 			$original_file=$conf->{$reg[1]}->dir_temp.'/'.$original_file;
2751
-		}
2752
-		else if (preg_match('/^([a-z]+)_user$/i',$modulepart,$reg))
2968
+		} else if (preg_match('/^([a-z]+)_user$/i',$modulepart,$reg))
2753 2969
 		{
2754
-			if (empty($conf->{$reg[1]}->dir_output))	// modulepart not supported
2970
+			if (empty($conf->{$reg[1]}->dir_output)) {
2971
+				// modulepart not supported
2755 2972
 			{
2756 2973
 				dol_print_error('','Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')');
2974
+			}
2757 2975
 				exit;
2758 2976
 			}
2759
-			if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) $accessallowed=1;
2977
+			if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) {
2978
+				$accessallowed=1;
2979
+			}
2760 2980
 			$original_file=$conf->{$reg[1]}->dir_output.'/'.$fuser->id.'/'.$original_file;
2761
-		}
2762
-		else
2981
+		} else
2763 2982
 		{
2764
-			if (empty($conf->$modulepart->dir_output))	// modulepart not supported
2983
+			if (empty($conf->$modulepart->dir_output)) {
2984
+				// modulepart not supported
2765 2985
 			{
2766 2986
 				dol_print_error('','Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')');
2987
+			}
2767 2988
 				exit;
2768 2989
 			}
2769 2990
 
@@ -2771,12 +2992,15 @@  discard block
 block discarded – undo
2771 2992
 			$subperm=GETPOST('subperm');
2772 2993
 			if ($perm || $subperm)
2773 2994
 			{
2774
-				if (($perm && ! $subperm && $fuser->rights->$modulepart->$perm) || ($perm && $subperm && $fuser->rights->$modulepart->$perm->$subperm)) $accessallowed=1;
2995
+				if (($perm && ! $subperm && $fuser->rights->$modulepart->$perm) || ($perm && $subperm && $fuser->rights->$modulepart->$perm->$subperm)) {
2996
+					$accessallowed=1;
2997
+				}
2775 2998
 				$original_file=$conf->$modulepart->dir_output.'/'.$original_file;
2776
-			}
2777
-			else
2999
+			} else
2778 3000
 			{
2779
-				if ($fuser->rights->$modulepart->{$lire} || $fuser->rights->$modulepart->{$read}) $accessallowed=1;
3001
+				if ($fuser->rights->$modulepart->{$lire} || $fuser->rights->$modulepart->{$read}) {
3002
+					$accessallowed=1;
3003
+				}
2780 3004
 				$original_file=$conf->$modulepart->dir_output.'/'.$original_file;
2781 3005
 			}
2782 3006
 		}
@@ -2794,11 +3018,13 @@  discard block
 block discarded – undo
2794 3018
 
2795 3019
 		// Define $sqlprotectagainstexternals for modules who want to protect access using a SQL query.
2796 3020
 		$sqlProtectConstName = strtoupper($modulepart).'_SQLPROTECTAGAINSTEXTERNALS_FOR_DOCUMENTS';
2797
-		if (! empty($conf->global->$sqlProtectConstName))	// If module want to define its own $sqlprotectagainstexternals
3021
+		if (! empty($conf->global->$sqlProtectConstName)) {
3022
+			// If module want to define its own $sqlprotectagainstexternals
2798 3023
 		{
2799 3024
 			// Example: mymodule__SQLPROTECTAGAINSTEXTERNALS_FOR_DOCUMENTS = "SELECT fk_soc FROM ".MAIN_DB_PREFIX.$modulepart." WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity;
2800 3025
 			eval('$sqlprotectagainstexternals = "'.$conf->global->$sqlProtectConstName.'";');
2801 3026
 		}
3027
+		}
2802 3028
 	}
2803 3029
 
2804 3030
 	$ret = array(
@@ -2820,7 +3046,9 @@  discard block
 block discarded – undo
2820 3046
  */
2821 3047
 function dol_filecache($directory, $filename, $object)
2822 3048
 {
2823
-	if (! dol_is_dir($directory)) dol_mkdir($directory);
3049
+	if (! dol_is_dir($directory)) {
3050
+		dol_mkdir($directory);
3051
+	}
2824 3052
 	$cachefile = $directory . $filename;
2825 3053
 	file_put_contents($cachefile, serialize($object), LOCK_EX);
2826 3054
 	@chmod($cachefile, 0644);
@@ -2874,9 +3102,11 @@  discard block
 block discarded – undo
2874 3102
 
2875 3103
 	$exclude = 'install';
2876 3104
 
2877
-	foreach ($dir->md5file as $file)    // $file is a simpleXMLElement
3105
+	foreach ($dir->md5file as $file) {
3106
+		// $file is a simpleXMLElement
2878 3107
 	{
2879 3108
 		$filename = $path.$file['name'];
3109
+	}
2880 3110
 		$file_list['insignature'][] = $filename;
2881 3111
 		$expectedmd5 = (string) $file;
2882 3112
 
@@ -2885,27 +3115,31 @@  discard block
 block discarded – undo
2885 3115
 		if (!file_exists($pathref.'/'.$filename))
2886 3116
 		{
2887 3117
 			$file_list['missing'][] = array('filename'=>$filename, 'expectedmd5'=>$expectedmd5);
2888
-		}
2889
-		else
3118
+		} else
2890 3119
 		{
2891 3120
 			$md5_local = md5_file($pathref.'/'.$filename);
2892 3121
 
2893
-			if ($conffile == '/etc/dolibarr/conf.php' && $filename == '/filefunc.inc.php')	// For install with deb or rpm, we ignore test on filefunc.inc.php that was modified by package
3122
+			if ($conffile == '/etc/dolibarr/conf.php' && $filename == '/filefunc.inc.php') {
3123
+				// For install with deb or rpm, we ignore test on filefunc.inc.php that was modified by package
2894 3124
 			{
2895 3125
 				$checksumconcat[] = $expectedmd5;
2896 3126
 			}
2897
-			else
3127
+			} else
2898 3128
 			{
2899
-				if ($md5_local != $expectedmd5) $file_list['updated'][] = array('filename'=>$filename, 'expectedmd5'=>$expectedmd5, 'md5'=>(string) $md5_local);
3129
+				if ($md5_local != $expectedmd5) {
3130
+					$file_list['updated'][] = array('filename'=>$filename, 'expectedmd5'=>$expectedmd5, 'md5'=>(string) $md5_local);
3131
+				}
2900 3132
 				$checksumconcat[] = $md5_local;
2901 3133
 			}
2902 3134
 		}
2903 3135
 	}
2904 3136
 
2905
-	foreach ($dir->dir as $subdir)			// $subdir['name'] is  '' or '/accountancy/admin' for example
3137
+	foreach ($dir->dir as $subdir) {
3138
+		// $subdir['name'] is  '' or '/accountancy/admin' for example
2906 3139
 	{
2907 3140
 		getFilesUpdated($file_list, $subdir, $path.$subdir['name'].'/', $pathref, $checksumconcat);
2908 3141
 	}
3142
+	}
2909 3143
 
2910 3144
 	return $file_list;
2911 3145
 }
Please login to merge, or discard this patch.
htdocs/install/step1.php 2 patches
Indentation   +696 added lines, -696 removed lines patch added patch discarded remove patch
@@ -145,9 +145,9 @@  discard block
 block discarded – undo
145 145
 // Test if we can run a first install process
146 146
 if (! is_writable($conffile))
147 147
 {
148
-    print $langs->trans("ConfFileIsNotWritable",$conffiletoshow);
149
-    pFooter(1,$setuplang,'jscheckparam');
150
-    exit;
148
+	print $langs->trans("ConfFileIsNotWritable",$conffiletoshow);
149
+	pFooter(1,$setuplang,'jscheckparam');
150
+	exit;
151 151
 }
152 152
 
153 153
 
@@ -155,30 +155,30 @@  discard block
 block discarded – undo
155 155
 $is_sqlite = false;
156 156
 if (empty($db_type))
157 157
 {
158
-    print '<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("DatabaseType")).'</div>';
159
-    $error++;
158
+	print '<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("DatabaseType")).'</div>';
159
+	$error++;
160 160
 } else {
161 161
 	$is_sqlite = ($db_type === 'sqlite' || $db_type === 'sqlite3' );
162 162
 }
163 163
 if (empty($db_host) && ! $is_sqlite)
164 164
 {
165
-    print '<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Server")).'</div>';
166
-    $error++;
165
+	print '<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Server")).'</div>';
166
+	$error++;
167 167
 }
168 168
 if (empty($db_name))
169 169
 {
170
-    print '<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("DatabaseName")).'</div>';
171
-    $error++;
170
+	print '<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("DatabaseName")).'</div>';
171
+	$error++;
172 172
 }
173 173
 if (empty($db_user)  && ! $is_sqlite)
174 174
 {
175
-    print '<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Login")).'</div>';
176
-    $error++;
175
+	print '<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Login")).'</div>';
176
+	$error++;
177 177
 }
178 178
 if (! empty($db_port) && ! is_numeric($db_port))
179 179
 {
180
-    print '<div class="error">'.$langs->trans("ErrorBadValueForParameter",$db_port,$langs->transnoentities("Port")).'</div>';
181
-    $error++;
180
+	print '<div class="error">'.$langs->trans("ErrorBadValueForParameter",$db_port,$langs->transnoentities("Port")).'</div>';
181
+	$error++;
182 182
 }
183 183
 if (! empty($db_prefix) && ! preg_match('/^[a-z0-9]+_$/i', $db_prefix))
184 184
 {
@@ -190,596 +190,596 @@  discard block
 block discarded – undo
190 190
 // Remove last / into dans main_dir
191 191
 if (substr($main_dir, dol_strlen($main_dir) -1) == "/")
192 192
 {
193
-    $main_dir = substr($main_dir, 0, dol_strlen($main_dir)-1);
193
+	$main_dir = substr($main_dir, 0, dol_strlen($main_dir)-1);
194 194
 }
195 195
 
196 196
 // Remove last / into dans main_url
197 197
 if (! empty($main_url) && substr($main_url, dol_strlen($main_url) -1) == "/")
198 198
 {
199
-    $main_url = substr($main_url, 0, dol_strlen($main_url)-1);
199
+	$main_url = substr($main_url, 0, dol_strlen($main_url)-1);
200 200
 }
201 201
 
202 202
 // Test database connection
203 203
 if (! $error) {
204
-    $result=@include_once $main_dir."/core/db/".$db_type.'.class.php';
205
-    if ($result)
206
-    {
207
-        // If we ask database or user creation we need to connect as root, so we need root login
208
-        if (!empty($db_create_database) && !$userroot) {
209
-            print '<div class="error">'.$langs->trans("YouAskDatabaseCreationSoDolibarrNeedToConnect",$db_name).'</div>';
210
-            print '<br>';
211
-            print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
212
-            print $langs->trans("ErrorGoBackAndCorrectParameters");
213
-            $error++;
214
-        }
215
-        if (!empty($db_create_user) && !$userroot) {
216
-            print '<div class="error">'.$langs->trans("YouAskLoginCreationSoDolibarrNeedToConnect",$db_user).'</div>';
217
-            print '<br>';
218
-            print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
219
-            print $langs->trans("ErrorGoBackAndCorrectParameters");
220
-            $error++;
221
-        }
222
-
223
-        // If we need root access
224
-        if (!$error && (!empty($db_create_database) || !empty($db_create_user))) {
225
-            $databasefortest=$db_name;
226
-            if (!empty($db_create_database)) {
227
-                if ($db_type == 'mysql' || $db_type == 'mysqli')
228
-                {
229
-                    $databasefortest='mysql';
230
-                }
231
-                elseif ($db_type == 'pgsql')
232
-                {
233
-                    $databasefortest='postgres';
234
-                }
235
-                else
236
-                {
237
-                    $databasefortest='master';
238
-                }
239
-            }
240
-            //print $_POST["db_type"].",".$_POST["db_host"].",$userroot,$passroot,$databasefortest,".$_POST["db_port"];
241
-
242
-            $db=getDoliDBInstance($db_type, $db_host, $userroot, $passroot, $databasefortest, $db_port);
243
-
244
-            dol_syslog("databasefortest=" . $databasefortest . " connected=" . $db->connected . " database_selected=" . $db->database_selected, LOG_DEBUG);
245
-            //print "databasefortest=".$databasefortest." connected=".$db->connected." database_selected=".$db->database_selected;
204
+	$result=@include_once $main_dir."/core/db/".$db_type.'.class.php';
205
+	if ($result)
206
+	{
207
+		// If we ask database or user creation we need to connect as root, so we need root login
208
+		if (!empty($db_create_database) && !$userroot) {
209
+			print '<div class="error">'.$langs->trans("YouAskDatabaseCreationSoDolibarrNeedToConnect",$db_name).'</div>';
210
+			print '<br>';
211
+			print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
212
+			print $langs->trans("ErrorGoBackAndCorrectParameters");
213
+			$error++;
214
+		}
215
+		if (!empty($db_create_user) && !$userroot) {
216
+			print '<div class="error">'.$langs->trans("YouAskLoginCreationSoDolibarrNeedToConnect",$db_user).'</div>';
217
+			print '<br>';
218
+			print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
219
+			print $langs->trans("ErrorGoBackAndCorrectParameters");
220
+			$error++;
221
+		}
222
+
223
+		// If we need root access
224
+		if (!$error && (!empty($db_create_database) || !empty($db_create_user))) {
225
+			$databasefortest=$db_name;
226
+			if (!empty($db_create_database)) {
227
+				if ($db_type == 'mysql' || $db_type == 'mysqli')
228
+				{
229
+					$databasefortest='mysql';
230
+				}
231
+				elseif ($db_type == 'pgsql')
232
+				{
233
+					$databasefortest='postgres';
234
+				}
235
+				else
236
+				{
237
+					$databasefortest='master';
238
+				}
239
+			}
240
+			//print $_POST["db_type"].",".$_POST["db_host"].",$userroot,$passroot,$databasefortest,".$_POST["db_port"];
241
+
242
+			$db=getDoliDBInstance($db_type, $db_host, $userroot, $passroot, $databasefortest, $db_port);
243
+
244
+			dol_syslog("databasefortest=" . $databasefortest . " connected=" . $db->connected . " database_selected=" . $db->database_selected, LOG_DEBUG);
245
+			//print "databasefortest=".$databasefortest." connected=".$db->connected." database_selected=".$db->database_selected;
246 246
 
247 247
 			if (empty($db_create_database) && $db->connected && !$db->database_selected) {
248
-                print '<div class="error">'.$langs->trans("ErrorConnectedButDatabaseNotFound",$db_name).'</div>';
249
-                print '<br>';
250
-                if (! $db->connected) print $langs->trans("IfDatabaseNotExistsGoBackAndUncheckCreate").'<br><br>';
251
-                print $langs->trans("ErrorGoBackAndCorrectParameters");
252
-                $error++;
253
-            } elseif ($db->error && ! (! empty($db_create_database) && $db->connected)) {
254
-            	// Note: you may experience error here with message "No such file or directory" when mysql was installed for the first time but not yet launched.
255
-                if ($db->error == "No such file or directory") print '<div class="error">'.$langs->trans("ErrorToConnectToMysqlCheckInstance").'</div>';
256
-                else print '<div class="error">'.$db->error.'</div>';
257
-                if (! $db->connected) print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
258
-                //print '<a href="#" onClick="javascript: history.back();">';
259
-                print $langs->trans("ErrorGoBackAndCorrectParameters");
260
-                //print '</a>';
261
-                $error++;
262
-            }
263
-        }
264
-        // If we need simple access
265
-        if (!$error && (empty($db_create_database) && empty($db_create_user))) {
266
-            $db=getDoliDBInstance($db_type, $db_host, $db_user, $db_pass, $db_name, $db_port);
267
-
268
-            if ($db->error)
269
-            {
270
-                print '<div class="error">'.$db->error.'</div>';
271
-                if (! $db->connected) print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
272
-                //print '<a href="#" onClick="javascript: history.back();">';
273
-                print $langs->trans("ErrorGoBackAndCorrectParameters");
274
-                //print '</a>';
275
-                $error++;
276
-            }
277
-        }
278
-    }
279
-    else
280
-    {
281
-        print "<br>\nFailed to include_once(\"".$main_dir."/core/db/".$db_type.".class.php\")<br>\n";
282
-        print '<div class="error">'.$langs->trans("ErrorWrongValueForParameter",$langs->transnoentities("WebPagesDirectory")).'</div>';
283
-        //print '<a href="#" onClick="javascript: history.back();">';
284
-        print $langs->trans("ErrorGoBackAndCorrectParameters");
285
-        //print '</a>';
286
-        $error++;
287
-    }
248
+				print '<div class="error">'.$langs->trans("ErrorConnectedButDatabaseNotFound",$db_name).'</div>';
249
+				print '<br>';
250
+				if (! $db->connected) print $langs->trans("IfDatabaseNotExistsGoBackAndUncheckCreate").'<br><br>';
251
+				print $langs->trans("ErrorGoBackAndCorrectParameters");
252
+				$error++;
253
+			} elseif ($db->error && ! (! empty($db_create_database) && $db->connected)) {
254
+				// Note: you may experience error here with message "No such file or directory" when mysql was installed for the first time but not yet launched.
255
+				if ($db->error == "No such file or directory") print '<div class="error">'.$langs->trans("ErrorToConnectToMysqlCheckInstance").'</div>';
256
+				else print '<div class="error">'.$db->error.'</div>';
257
+				if (! $db->connected) print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
258
+				//print '<a href="#" onClick="javascript: history.back();">';
259
+				print $langs->trans("ErrorGoBackAndCorrectParameters");
260
+				//print '</a>';
261
+				$error++;
262
+			}
263
+		}
264
+		// If we need simple access
265
+		if (!$error && (empty($db_create_database) && empty($db_create_user))) {
266
+			$db=getDoliDBInstance($db_type, $db_host, $db_user, $db_pass, $db_name, $db_port);
267
+
268
+			if ($db->error)
269
+			{
270
+				print '<div class="error">'.$db->error.'</div>';
271
+				if (! $db->connected) print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
272
+				//print '<a href="#" onClick="javascript: history.back();">';
273
+				print $langs->trans("ErrorGoBackAndCorrectParameters");
274
+				//print '</a>';
275
+				$error++;
276
+			}
277
+		}
278
+	}
279
+	else
280
+	{
281
+		print "<br>\nFailed to include_once(\"".$main_dir."/core/db/".$db_type.".class.php\")<br>\n";
282
+		print '<div class="error">'.$langs->trans("ErrorWrongValueForParameter",$langs->transnoentities("WebPagesDirectory")).'</div>';
283
+		//print '<a href="#" onClick="javascript: history.back();">';
284
+		print $langs->trans("ErrorGoBackAndCorrectParameters");
285
+		//print '</a>';
286
+		$error++;
287
+	}
288 288
 }
289 289
 
290 290
 else
291 291
 {
292
-    if (isset($db)) print $db->lasterror();
293
-    if (isset($db) && ! $db->connected) print '<br>'.$langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
294
-    print $langs->trans("ErrorGoBackAndCorrectParameters");
295
-    $error++;
292
+	if (isset($db)) print $db->lasterror();
293
+	if (isset($db) && ! $db->connected) print '<br>'.$langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
294
+	print $langs->trans("ErrorGoBackAndCorrectParameters");
295
+	$error++;
296 296
 }
297 297
 
298 298
 if (! $error && $db->connected)
299 299
 {
300
-    if (! empty($db_create_database)) {
301
-        $result=$db->select_db($db_name);
302
-        if ($result)
303
-        {
304
-            print '<div class="error">'.$langs->trans("ErrorDatabaseAlreadyExists", $db_name).'</div>';
305
-            print $langs->trans("IfDatabaseExistsGoBackAndCheckCreate").'<br><br>';
306
-            print $langs->trans("ErrorGoBackAndCorrectParameters");
307
-            $error++;
308
-        }
309
-    }
300
+	if (! empty($db_create_database)) {
301
+		$result=$db->select_db($db_name);
302
+		if ($result)
303
+		{
304
+			print '<div class="error">'.$langs->trans("ErrorDatabaseAlreadyExists", $db_name).'</div>';
305
+			print $langs->trans("IfDatabaseExistsGoBackAndCheckCreate").'<br><br>';
306
+			print $langs->trans("ErrorGoBackAndCorrectParameters");
307
+			$error++;
308
+		}
309
+	}
310 310
 }
311 311
 
312 312
 // Define $defaultCharacterSet and $defaultDBSortingCollation
313 313
 if (! $error && $db->connected)
314 314
 {
315
-    if (!empty($db_create_database))    // If we create database, we force default value
316
-    {
317
-        // Default values come from the database handler
318
-
319
-        $defaultCharacterSet=$db->forcecharset;
320
-    	$defaultDBSortingCollation=$db->forcecollate;
321
-    }
322
-    else	// If already created, we take current value
323
-    {
324
-        $defaultCharacterSet=$db->getDefaultCharacterSetDatabase();
325
-        $defaultDBSortingCollation=$db->getDefaultCollationDatabase();
326
-    }
327
-
328
-    // Force to avoid utf8mb4 because index on field char 255 reach limit of 767 char for indexes (example with mysql 5.6.34 = mariadb 10.0.29)
329
-    // TODO Remove this when utf8mb4 is supported
330
-    if ($defaultCharacterSet == 'utf8mb4' || $defaultDBSortingCollation == 'utf8mb4_unicode_ci')
331
-    {
332
-        $defaultCharacterSet = 'utf8';
333
-        $defaultDBSortingCollation = 'utf8_unicode_ci';
334
-    }
335
-
336
-    print '<input type="hidden" name="dolibarr_main_db_character_set" value="'.$defaultCharacterSet.'">';
337
-    print '<input type="hidden" name="dolibarr_main_db_collation" value="'.$defaultDBSortingCollation.'">';
338
-    $db_character_set=$defaultCharacterSet;
339
-    $db_collation=$defaultDBSortingCollation;
340
-    dolibarr_install_syslog("step1: db_character_set=" . $db_character_set . " db_collation=" . $db_collation);
315
+	if (!empty($db_create_database))    // If we create database, we force default value
316
+	{
317
+		// Default values come from the database handler
318
+
319
+		$defaultCharacterSet=$db->forcecharset;
320
+		$defaultDBSortingCollation=$db->forcecollate;
321
+	}
322
+	else	// If already created, we take current value
323
+	{
324
+		$defaultCharacterSet=$db->getDefaultCharacterSetDatabase();
325
+		$defaultDBSortingCollation=$db->getDefaultCollationDatabase();
326
+	}
327
+
328
+	// Force to avoid utf8mb4 because index on field char 255 reach limit of 767 char for indexes (example with mysql 5.6.34 = mariadb 10.0.29)
329
+	// TODO Remove this when utf8mb4 is supported
330
+	if ($defaultCharacterSet == 'utf8mb4' || $defaultDBSortingCollation == 'utf8mb4_unicode_ci')
331
+	{
332
+		$defaultCharacterSet = 'utf8';
333
+		$defaultDBSortingCollation = 'utf8_unicode_ci';
334
+	}
335
+
336
+	print '<input type="hidden" name="dolibarr_main_db_character_set" value="'.$defaultCharacterSet.'">';
337
+	print '<input type="hidden" name="dolibarr_main_db_collation" value="'.$defaultDBSortingCollation.'">';
338
+	$db_character_set=$defaultCharacterSet;
339
+	$db_collation=$defaultDBSortingCollation;
340
+	dolibarr_install_syslog("step1: db_character_set=" . $db_character_set . " db_collation=" . $db_collation);
341 341
 }
342 342
 
343 343
 
344 344
 // Create config file
345 345
 if (! $error && $db->connected && $action == "set")
346 346
 {
347
-    umask(0);
348
-    if (is_array($_POST))
349
-    {
350
-        foreach($_POST as $key => $value)
351
-        {
352
-            if (! preg_match('/^db_pass/i', $key)) {
353
-    			dolibarr_install_syslog("step1: choice for " . $key . " = " . $value);
354
-    		}
355
-        }
356
-    }
357
-
358
-    // Show title of step
359
-    print '<h3><img class="valigntextbottom" src="../theme/common/octicons/lib/svg/gear.svg" width="20" alt="Configuration"> '.$langs->trans("ConfigurationFile").'</h3>';
360
-    print '<table cellspacing="0" width="100%" cellpadding="1" border="0">';
361
-
362
-    // Check parameter main_dir
363
-    if (! $error)
364
-    {
365
-        if (! is_dir($main_dir))
366
-        {
367
-            dolibarr_install_syslog("step1: directory '" . $main_dir . "' is unavailable or can't be accessed");
368
-
369
-            print "<tr><td>";
370
-            print $langs->trans("ErrorDirDoesNotExists",$main_dir).'<br>';
371
-            print $langs->trans("ErrorWrongValueForParameter",$langs->trans("WebPagesDirectory")).'<br>';
372
-            print $langs->trans("ErrorGoBackAndCorrectParameters").'<br><br>';
373
-            print '</td><td>';
374
-            print $langs->trans("Error");
375
-            print "</td></tr>";
376
-            $error++;
377
-        }
378
-    }
379
-
380
-    if (! $error)
381
-    {
382
-        dolibarr_install_syslog("step1: directory '" . $main_dir . "' exists");
383
-    }
384
-
385
-
386
-    // Create subdirectory main_data_dir
387
-    if (! $error)
388
-    {
389
-        // Create directory for documents
390
-        if (! is_dir($main_data_dir))
391
-        {
392
-            dol_mkdir($main_data_dir);
393
-        }
394
-
395
-        if (! is_dir($main_data_dir))
396
-        {
397
-            print "<tr><td>".$langs->trans("ErrorDirDoesNotExists",$main_data_dir);
398
-            print ' '.$langs->trans("YouMustCreateItAndAllowServerToWrite");
399
-            print '</td><td>';
400
-            print '<font class="error">'.$langs->trans("Error").'</font>';
401
-            print "</td></tr>";
402
-            print '<tr><td colspan="2"><br>'.$langs->trans("CorrectProblemAndReloadPage",$_SERVER['PHP_SELF'].'?testget=ok').'</td></tr>';
403
-            $error++;
404
-        }
405
-        else
406
-        {
407
-            // Create .htaccess file in document directory
408
-            $pathhtaccess=$main_data_dir.'/.htaccess';
409
-            if (! file_exists($pathhtaccess))
410
-            {
411
-                dolibarr_install_syslog("step1: .htaccess file did not exist, we created it in '" . $main_data_dir . "'");
412
-                $handlehtaccess=@fopen($pathhtaccess,'w');
413
-                if ($handlehtaccess)
414
-                {
415
-                    fwrite($handlehtaccess,'Order allow,deny'."\n");
416
-                    fwrite($handlehtaccess,'Deny from all'."\n");
417
-
418
-                    fclose($handlehtaccess);
419
-                    dolibarr_install_syslog("step1: .htaccess file created");
420
-                }
421
-            }
422
-
423
-            // Les documents sont en dehors de htdocs car ne doivent pas pouvoir etre telecharges en passant outre l'authentification
424
-            $dir=array();
425
-            $dir[] = $main_data_dir."/mycompany";
426
-            $dir[] = $main_data_dir."/medias";
427
-            $dir[] = $main_data_dir."/users";
428
-            $dir[] = $main_data_dir."/facture";
429
-            $dir[] = $main_data_dir."/propale";
430
-            $dir[] = $main_data_dir."/ficheinter";
431
-            $dir[] = $main_data_dir."/produit";
432
-            $dir[] = $main_data_dir."/doctemplates";
433
-
434
-            // Boucle sur chaque repertoire de dir[] pour les creer s'ils nexistent pas
435
-            $num=count($dir);
436
-            for ($i = 0; $i < $num; $i++)
437
-            {
438
-                if (is_dir($dir[$i]))
439
-                {
440
-                    dolibarr_install_syslog("step1: directory '" . $dir[$i] . "' exists");
441
-                }
442
-                else
443
-                {
444
-                    if (dol_mkdir($dir[$i]) < 0)
445
-                    {
446
-                        print "<tr><td>";
447
-                        print "Failed to create directory: ".$dir[$i];
448
-                        print '</td><td>';
449
-                        print $langs->trans("Error");
450
-                        print "</td></tr>";
451
-                        $error++;
452
-                    }
453
-                    else
454
-                    {
455
-                        dolibarr_install_syslog("step1: directory '" . $dir[$i] . "' created");
456
-                    }
457
-                }
458
-            }
459
-
460
-            require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
461
-
462
-            // Copy directory medias
463
-            $srcroot=$main_dir.'/install/medias';
464
-            $destroot=$main_data_dir.'/medias';
465
-            dolCopyDir($srcroot, $destroot, 0, 0);
466
-
467
-            if ($error)
468
-            {
469
-                print "<tr><td>".$langs->trans("ErrorDirDoesNotExists",$main_data_dir);
470
-                print ' '.$langs->trans("YouMustCreateItAndAllowServerToWrite");
471
-                print '</td><td>';
472
-                print '<font class="error">'.$langs->trans("Error").'</font>';
473
-                print "</td></tr>";
474
-                print '<tr><td colspan="2"><br>'.$langs->trans("CorrectProblemAndReloadPage",$_SERVER['PHP_SELF'].'?testget=ok').'</td></tr>';
475
-            }
476
-            else
477
-            {
478
-            	//ODT templates
479
-            	$srcroot=$main_dir.'/install/doctemplates';
480
-            	$destroot=$main_data_dir.'/doctemplates';
481
-            	$docs=array(
482
-            		'contracts' => 'contract',
483
-            		'invoices' => 'invoice',
484
-            		'orders' => 'order',
485
-            		'products' => 'product',
486
-            		'projects' => 'project',
487
-            		'proposals' => 'proposal',
488
-            		'shipment' => 'shipment',
489
-            		'supplier_proposal' => 'supplier_proposal',
490
-            		'tasks' => 'task_summary',
491
-            		'thirdparties' => 'thirdparty',
492
-            		'usergroups' => 'usergroups',
493
-            		'users' => 'user',
494
-            		'usergroups' => 'usergroups',
495
-            	);
496
-            	foreach($docs as $cursordir => $cursorfile)
497
-            	{
498
-            		$src=$srcroot.'/'.$cursordir.'/template_'.$cursorfile.'.odt';
499
-            		$dirodt=$destroot.'/'.$cursordir;
500
-            		$dest=$dirodt.'/template_'.$cursorfile.'.odt';
501
-
502
-            		dol_mkdir($dirodt);
503
-            		$result=dol_copy($src,$dest,0,0);
504
-            		if ($result < 0)
505
-            		{
506
-            			print '<tr><td colspan="2"><br>'.$langs->trans('ErrorFailToCopyFile',$src,$dest).'</td></tr>';
507
-            		}
508
-            	}
509
-            }
510
-        }
511
-    }
512
-
513
-    // Table prefix
514
-    $main_db_prefix = (! empty($db_prefix) ? $db_prefix : 'llx_');
515
-
516
-    // Write conf file on disk
517
-    if (! $error)
518
-    {
519
-        // Save old conf file on disk
520
-        if (file_exists("$conffile"))
521
-        {
522
-            // We must ignore errors as an existing old file may already exists and not be replacable or
523
-            // the installer (like for ubuntu) may not have permission to create another file than conf.php.
524
-            // Also no other process must be able to read file or we expose the new file, so content with password.
525
-            @dol_copy($conffile, $conffile.'.old', '0400');
526
-        }
527
-
528
-        $error+=write_conf_file($conffile);
529
-    }
530
-
531
-    // Create database and admin user database
532
-    if (! $error)
533
-    {
534
-        // We reload configuration file
535
-        conf($dolibarr_main_document_root);
536
-
537
-        print '<tr><td>';
538
-        print $langs->trans("ConfFileReload");
539
-        print '</td>';
540
-        print '<td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
541
-
542
-        // Si creation utilisateur admin demandee, on le cree
543
-        if (isset($db_create_user) && ($db_create_user == "1" || $db_create_user == "on")) {
544
-            dolibarr_install_syslog("step1: create database user: " . $dolibarr_main_db_user);
545
-
546
-            //print $conf->db->host." , ".$conf->db->name." , ".$conf->db->user." , ".$conf->db->port;
547
-            $databasefortest=$conf->db->name;
548
-            if ($conf->db->type == 'mysql' || $conf->db->type == 'mysqli')
549
-            {
550
-                $databasefortest='mysql';
551
-            }
552
-            else if ($conf->db->type == 'pgsql')
553
-            {
554
-                $databasefortest='postgres';
555
-            }
556
-            else if ($conf->db->type == 'mssql')
557
-            {
558
-                $databasefortest='master';
559
-            }
560
-
561
-            // Creation handler de base, verification du support et connexion
562
-
563
-            $db=getDoliDBInstance($conf->db->type,$conf->db->host,$userroot,$passroot,$databasefortest,$conf->db->port);
564
-
565
-            if ($db->error)
566
-            {
567
-                print '<div class="error">'.$db->error.'</div>';
568
-                $error++;
569
-            }
570
-
571
-            if (! $error)
572
-            {
573
-                if ($db->connected)
574
-                {
575
-                    $resultbis = 1;
576
-
577
-                    // Create user
578
-                    $result=$db->DDLCreateUser($dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_pass, $dolibarr_main_db_name);
579
-                    // Create user bis
580
-                    if ($databasefortest == 'mysql')
581
-                    {
582
-                        if (! in_array($dolibarr_main_db_host, array('127.0.0.1', '::1', 'localhost', 'localhost.local')))
583
-                        {
584
-                            $resultbis=$db->DDLCreateUser('%', $dolibarr_main_db_user, $dolibarr_main_db_pass, $dolibarr_main_db_name);
585
-                        }
586
-                    }
587
-
588
-                    if ($result > 0 && $resultbis > 0)
589
-                    {
590
-
591
-                        print '<tr><td>';
592
-                        print $langs->trans("UserCreation").' : ';
593
-                        print $dolibarr_main_db_user;
594
-                        print '</td>';
595
-                        print '<td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
596
-                    }
597
-                    else
598
-                    {
599
-                        if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS'
600
-                        || $db->errno() == 'DB_ERROR_KEY_NAME_ALREADY_EXISTS'
601
-                        || $db->errno() == 'DB_ERROR_USER_ALREADY_EXISTS')
602
-                        {
603
-                            dolibarr_install_syslog("step1: user already exists");
604
-                            print '<tr><td>';
605
-                            print $langs->trans("UserCreation").' : ';
606
-                            print $dolibarr_main_db_user;
607
-                            print '</td>';
608
-                            print '<td>'.$langs->trans("LoginAlreadyExists").'</td></tr>';
609
-                        }
610
-                        else
611
-                        {
612
-                            dolibarr_install_syslog("step1: failed to create user", LOG_ERR);
613
-                            print '<tr><td>';
614
-                            print $langs->trans("UserCreation").' : ';
615
-                            print $dolibarr_main_db_user;
616
-                            print '</td>';
617
-                            print '<td>'.$langs->trans("Error").': '.$db->errno().' '.$db->error()."</td></tr>";
618
-                        }
619
-                    }
620
-
621
-                    $db->close();
622
-                }
623
-                else
624
-                {
625
-                    print '<tr><td>';
626
-                    print $langs->trans("UserCreation").' : ';
627
-                    print $dolibarr_main_db_user;
628
-                    print '</td>';
629
-                    print '<td><img src="../theme/eldy/img/error.png" alt="Error"></td>';
630
-                    print '</tr>';
631
-
632
-                    // Affiche aide diagnostique
633
-                    print '<tr><td colspan="2"><br>';
634
-                    print $langs->trans("YouAskDatabaseCreationSoDolibarrNeedToConnect",$dolibarr_main_db_user,$dolibarr_main_db_host,$userroot);
635
-                    print '<br>';
636
-                    print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
637
-                    print $langs->trans("ErrorGoBackAndCorrectParameters").'<br><br>';
638
-                    print '</td></tr>';
639
-
640
-                    $error++;
641
-                }
642
-            }
643
-        }   // Fin si "creation utilisateur"
644
-
645
-
646
-        // If database creation is asked, we create it
647
-        if (!$error && (isset($db_create_database) && ($db_create_database == "1" || $db_create_database == "on"))) {
648
-            dolibarr_install_syslog("step1: create database: " . $dolibarr_main_db_name . " " . $dolibarr_main_db_character_set . " " . $dolibarr_main_db_collation . " " . $dolibarr_main_db_user);
649
-        	$newdb=getDoliDBInstance($conf->db->type,$conf->db->host,$userroot,$passroot,'',$conf->db->port);
650
-            //print 'eee'.$conf->db->type." ".$conf->db->host." ".$userroot." ".$passroot." ".$conf->db->port." ".$newdb->connected." ".$newdb->forcecharset;exit;
651
-
652
-            if ($newdb->connected)
653
-            {
654
-                $result=$newdb->DDLCreateDb($dolibarr_main_db_name, $dolibarr_main_db_character_set, $dolibarr_main_db_collation, $dolibarr_main_db_user);
655
-
656
-                if ($result)
657
-                {
658
-                    print '<tr><td>';
659
-                    print $langs->trans("DatabaseCreation")." (".$langs->trans("User")." ".$userroot.") : ";
660
-                    print $dolibarr_main_db_name;
661
-                    print '</td>';
662
-                    print '<td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
663
-
664
-                    $newdb->select_db($dolibarr_main_db_name);
665
-                    $check1=$newdb->getDefaultCharacterSetDatabase();
666
-                    $check2=$newdb->getDefaultCollationDatabase();
667
-                    dolibarr_install_syslog('step1: new database is using charset=' . $check1 . ' collation=' . $check2);
668
-
669
-                    // If values differs, we save conf file again
670
-                    //if ($check1 != $dolibarr_main_db_character_set) dolibarr_install_syslog('step1: value for character_set is not the one asked for database creation', LOG_WARNING);
671
-                    //if ($check2 != $dolibarr_main_db_collation)     dolibarr_install_syslog('step1: value for collation is not the one asked for database creation', LOG_WARNING);
672
-                }
673
-                else
674
-                {
675
-                    // Affiche aide diagnostique
676
-                    print '<tr><td colspan="2"><br>';
677
-                    print $langs->trans("ErrorFailedToCreateDatabase",$dolibarr_main_db_name).'<br>';
678
-                    print $newdb->lasterror().'<br>';
679
-                    print $langs->trans("IfDatabaseExistsGoBackAndCheckCreate");
680
-                    print '<br>';
681
-                    print '</td></tr>';
682
-
683
-                    dolibarr_install_syslog('step1: failed to create database ' . $dolibarr_main_db_name . ' ' . $newdb->lasterrno() . ' ' . $newdb->lasterror(), LOG_ERR);
684
-                    $error++;
685
-                }
686
-                $newdb->close();
687
-            }
688
-            else {
689
-                print '<tr><td>';
690
-                print $langs->trans("DatabaseCreation")." (".$langs->trans("User")." ".$userroot.") : ";
691
-                print $dolibarr_main_db_name;
692
-                print '</td>';
693
-                print '<td><img src="../theme/eldy/img/error.png" alt="Error"></td>';
694
-                print '</tr>';
695
-
696
-                // Affiche aide diagnostique
697
-                print '<tr><td colspan="2"><br>';
698
-                print $langs->trans("YouAskDatabaseCreationSoDolibarrNeedToConnect",$dolibarr_main_db_user,$dolibarr_main_db_host,$userroot);
699
-                print '<br>';
700
-                print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
701
-                print $langs->trans("ErrorGoBackAndCorrectParameters").'<br><br>';
702
-                print '</td></tr>';
703
-
704
-                $error++;
705
-            }
706
-        }   // Fin si "creation database"
707
-
708
-
709
-        // We test access with dolibarr database user (not admin)
710
-        if (! $error)
711
-        {
712
-            dolibarr_install_syslog("step1: connection type=" . $conf->db->type . " on host=" . $conf->db->host . " port=" . $conf->db->port . " user=" . $conf->db->user . " name=" . $conf->db->name);
713
-            //print "connexion de type=".$conf->db->type." sur host=".$conf->db->host." port=".$conf->db->port." user=".$conf->db->user." name=".$conf->db->name;
714
-
715
-            $db=getDoliDBInstance($conf->db->type,$conf->db->host,$conf->db->user,$conf->db->pass,$conf->db->name,$conf->db->port);
716
-
717
-            if ($db->connected)
718
-            {
719
-                dolibarr_install_syslog("step1: connection to server by user " . $conf->db->user . " ok");
720
-                print "<tr><td>";
721
-                print $langs->trans("ServerConnection")." (".$langs->trans("User")." ".$conf->db->user.") : ";
722
-                print $dolibarr_main_db_host;
723
-                print "</td><td>";
724
-                print '<img src="../theme/eldy/img/tick.png" alt="Ok">';
725
-                print "</td></tr>";
726
-
727
-                // si acces serveur ok et acces base ok, tout est ok, on ne va pas plus loin, on a meme pas utilise le compte root.
728
-                if ($db->database_selected)
729
-                {
730
-                    dolibarr_install_syslog("step1: connection to database " . $conf->db->name . " by user " . $conf->db->user . " ok");
731
-                    print "<tr><td>";
732
-                    print $langs->trans("DatabaseConnection")." (".$langs->trans("User")." ".$conf->db->user.") : ";
733
-                    print $dolibarr_main_db_name;
734
-                    print "</td><td>";
735
-                    print '<img src="../theme/eldy/img/tick.png" alt="Ok">';
736
-                    print "</td></tr>";
737
-
738
-                    $error = 0;
739
-                }
740
-                else
741
-                {
742
-                    dolibarr_install_syslog("step1: connection to database " . $conf->db->name . " by user " . $conf->db->user . " failed", LOG_ERR);
743
-                    print "<tr><td>";
744
-                    print $langs->trans("DatabaseConnection")." (".$langs->trans("User")." ".$conf->db->user.") : ";
745
-                    print $dolibarr_main_db_name;
746
-                    print '</td><td>';
747
-                    print '<img src="../theme/eldy/img/error.png" alt="Error">';
748
-                    print "</td></tr>";
749
-
750
-                    // Affiche aide diagnostique
751
-                    print '<tr><td colspan="2"><br>';
752
-                    print $langs->trans('CheckThatDatabasenameIsCorrect',$dolibarr_main_db_name).'<br>';
753
-                    print $langs->trans('IfAlreadyExistsCheckOption').'<br>';
754
-                    print $langs->trans("ErrorGoBackAndCorrectParameters").'<br><br>';
755
-                    print '</td></tr>';
756
-
757
-                    $error++;
758
-                }
759
-            }
760
-            else
761
-            {
762
-                dolibarr_install_syslog("step1: connection to server by user " . $conf->db->user . " failed", LOG_ERR);
763
-                print "<tr><td>";
764
-                print $langs->trans("ServerConnection")." (".$langs->trans("User")." ".$conf->db->user.") : ";
765
-                print $dolibarr_main_db_host;
766
-                print '</td><td>';
767
-                print '<img src="../theme/eldy/img/error.png" alt="Error">';
768
-                print "</td></tr>";
769
-
770
-                // Affiche aide diagnostique
771
-                print '<tr><td colspan="2"><br>';
772
-                print $langs->trans("ErrorConnection",$conf->db->host,$conf->db->name,$conf->db->user);
773
-                print $langs->trans('IfLoginDoesNotExistsCheckCreateUser').'<br>';
774
-                print $langs->trans("ErrorGoBackAndCorrectParameters").'<br><br>';
775
-                print '</td></tr>';
776
-
777
-                $error++;
778
-            }
779
-        }
780
-    }
781
-
782
-    print '</table>';
347
+	umask(0);
348
+	if (is_array($_POST))
349
+	{
350
+		foreach($_POST as $key => $value)
351
+		{
352
+			if (! preg_match('/^db_pass/i', $key)) {
353
+				dolibarr_install_syslog("step1: choice for " . $key . " = " . $value);
354
+			}
355
+		}
356
+	}
357
+
358
+	// Show title of step
359
+	print '<h3><img class="valigntextbottom" src="../theme/common/octicons/lib/svg/gear.svg" width="20" alt="Configuration"> '.$langs->trans("ConfigurationFile").'</h3>';
360
+	print '<table cellspacing="0" width="100%" cellpadding="1" border="0">';
361
+
362
+	// Check parameter main_dir
363
+	if (! $error)
364
+	{
365
+		if (! is_dir($main_dir))
366
+		{
367
+			dolibarr_install_syslog("step1: directory '" . $main_dir . "' is unavailable or can't be accessed");
368
+
369
+			print "<tr><td>";
370
+			print $langs->trans("ErrorDirDoesNotExists",$main_dir).'<br>';
371
+			print $langs->trans("ErrorWrongValueForParameter",$langs->trans("WebPagesDirectory")).'<br>';
372
+			print $langs->trans("ErrorGoBackAndCorrectParameters").'<br><br>';
373
+			print '</td><td>';
374
+			print $langs->trans("Error");
375
+			print "</td></tr>";
376
+			$error++;
377
+		}
378
+	}
379
+
380
+	if (! $error)
381
+	{
382
+		dolibarr_install_syslog("step1: directory '" . $main_dir . "' exists");
383
+	}
384
+
385
+
386
+	// Create subdirectory main_data_dir
387
+	if (! $error)
388
+	{
389
+		// Create directory for documents
390
+		if (! is_dir($main_data_dir))
391
+		{
392
+			dol_mkdir($main_data_dir);
393
+		}
394
+
395
+		if (! is_dir($main_data_dir))
396
+		{
397
+			print "<tr><td>".$langs->trans("ErrorDirDoesNotExists",$main_data_dir);
398
+			print ' '.$langs->trans("YouMustCreateItAndAllowServerToWrite");
399
+			print '</td><td>';
400
+			print '<font class="error">'.$langs->trans("Error").'</font>';
401
+			print "</td></tr>";
402
+			print '<tr><td colspan="2"><br>'.$langs->trans("CorrectProblemAndReloadPage",$_SERVER['PHP_SELF'].'?testget=ok').'</td></tr>';
403
+			$error++;
404
+		}
405
+		else
406
+		{
407
+			// Create .htaccess file in document directory
408
+			$pathhtaccess=$main_data_dir.'/.htaccess';
409
+			if (! file_exists($pathhtaccess))
410
+			{
411
+				dolibarr_install_syslog("step1: .htaccess file did not exist, we created it in '" . $main_data_dir . "'");
412
+				$handlehtaccess=@fopen($pathhtaccess,'w');
413
+				if ($handlehtaccess)
414
+				{
415
+					fwrite($handlehtaccess,'Order allow,deny'."\n");
416
+					fwrite($handlehtaccess,'Deny from all'."\n");
417
+
418
+					fclose($handlehtaccess);
419
+					dolibarr_install_syslog("step1: .htaccess file created");
420
+				}
421
+			}
422
+
423
+			// Les documents sont en dehors de htdocs car ne doivent pas pouvoir etre telecharges en passant outre l'authentification
424
+			$dir=array();
425
+			$dir[] = $main_data_dir."/mycompany";
426
+			$dir[] = $main_data_dir."/medias";
427
+			$dir[] = $main_data_dir."/users";
428
+			$dir[] = $main_data_dir."/facture";
429
+			$dir[] = $main_data_dir."/propale";
430
+			$dir[] = $main_data_dir."/ficheinter";
431
+			$dir[] = $main_data_dir."/produit";
432
+			$dir[] = $main_data_dir."/doctemplates";
433
+
434
+			// Boucle sur chaque repertoire de dir[] pour les creer s'ils nexistent pas
435
+			$num=count($dir);
436
+			for ($i = 0; $i < $num; $i++)
437
+			{
438
+				if (is_dir($dir[$i]))
439
+				{
440
+					dolibarr_install_syslog("step1: directory '" . $dir[$i] . "' exists");
441
+				}
442
+				else
443
+				{
444
+					if (dol_mkdir($dir[$i]) < 0)
445
+					{
446
+						print "<tr><td>";
447
+						print "Failed to create directory: ".$dir[$i];
448
+						print '</td><td>';
449
+						print $langs->trans("Error");
450
+						print "</td></tr>";
451
+						$error++;
452
+					}
453
+					else
454
+					{
455
+						dolibarr_install_syslog("step1: directory '" . $dir[$i] . "' created");
456
+					}
457
+				}
458
+			}
459
+
460
+			require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
461
+
462
+			// Copy directory medias
463
+			$srcroot=$main_dir.'/install/medias';
464
+			$destroot=$main_data_dir.'/medias';
465
+			dolCopyDir($srcroot, $destroot, 0, 0);
466
+
467
+			if ($error)
468
+			{
469
+				print "<tr><td>".$langs->trans("ErrorDirDoesNotExists",$main_data_dir);
470
+				print ' '.$langs->trans("YouMustCreateItAndAllowServerToWrite");
471
+				print '</td><td>';
472
+				print '<font class="error">'.$langs->trans("Error").'</font>';
473
+				print "</td></tr>";
474
+				print '<tr><td colspan="2"><br>'.$langs->trans("CorrectProblemAndReloadPage",$_SERVER['PHP_SELF'].'?testget=ok').'</td></tr>';
475
+			}
476
+			else
477
+			{
478
+				//ODT templates
479
+				$srcroot=$main_dir.'/install/doctemplates';
480
+				$destroot=$main_data_dir.'/doctemplates';
481
+				$docs=array(
482
+					'contracts' => 'contract',
483
+					'invoices' => 'invoice',
484
+					'orders' => 'order',
485
+					'products' => 'product',
486
+					'projects' => 'project',
487
+					'proposals' => 'proposal',
488
+					'shipment' => 'shipment',
489
+					'supplier_proposal' => 'supplier_proposal',
490
+					'tasks' => 'task_summary',
491
+					'thirdparties' => 'thirdparty',
492
+					'usergroups' => 'usergroups',
493
+					'users' => 'user',
494
+					'usergroups' => 'usergroups',
495
+				);
496
+				foreach($docs as $cursordir => $cursorfile)
497
+				{
498
+					$src=$srcroot.'/'.$cursordir.'/template_'.$cursorfile.'.odt';
499
+					$dirodt=$destroot.'/'.$cursordir;
500
+					$dest=$dirodt.'/template_'.$cursorfile.'.odt';
501
+
502
+					dol_mkdir($dirodt);
503
+					$result=dol_copy($src,$dest,0,0);
504
+					if ($result < 0)
505
+					{
506
+						print '<tr><td colspan="2"><br>'.$langs->trans('ErrorFailToCopyFile',$src,$dest).'</td></tr>';
507
+					}
508
+				}
509
+			}
510
+		}
511
+	}
512
+
513
+	// Table prefix
514
+	$main_db_prefix = (! empty($db_prefix) ? $db_prefix : 'llx_');
515
+
516
+	// Write conf file on disk
517
+	if (! $error)
518
+	{
519
+		// Save old conf file on disk
520
+		if (file_exists("$conffile"))
521
+		{
522
+			// We must ignore errors as an existing old file may already exists and not be replacable or
523
+			// the installer (like for ubuntu) may not have permission to create another file than conf.php.
524
+			// Also no other process must be able to read file or we expose the new file, so content with password.
525
+			@dol_copy($conffile, $conffile.'.old', '0400');
526
+		}
527
+
528
+		$error+=write_conf_file($conffile);
529
+	}
530
+
531
+	// Create database and admin user database
532
+	if (! $error)
533
+	{
534
+		// We reload configuration file
535
+		conf($dolibarr_main_document_root);
536
+
537
+		print '<tr><td>';
538
+		print $langs->trans("ConfFileReload");
539
+		print '</td>';
540
+		print '<td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
541
+
542
+		// Si creation utilisateur admin demandee, on le cree
543
+		if (isset($db_create_user) && ($db_create_user == "1" || $db_create_user == "on")) {
544
+			dolibarr_install_syslog("step1: create database user: " . $dolibarr_main_db_user);
545
+
546
+			//print $conf->db->host." , ".$conf->db->name." , ".$conf->db->user." , ".$conf->db->port;
547
+			$databasefortest=$conf->db->name;
548
+			if ($conf->db->type == 'mysql' || $conf->db->type == 'mysqli')
549
+			{
550
+				$databasefortest='mysql';
551
+			}
552
+			else if ($conf->db->type == 'pgsql')
553
+			{
554
+				$databasefortest='postgres';
555
+			}
556
+			else if ($conf->db->type == 'mssql')
557
+			{
558
+				$databasefortest='master';
559
+			}
560
+
561
+			// Creation handler de base, verification du support et connexion
562
+
563
+			$db=getDoliDBInstance($conf->db->type,$conf->db->host,$userroot,$passroot,$databasefortest,$conf->db->port);
564
+
565
+			if ($db->error)
566
+			{
567
+				print '<div class="error">'.$db->error.'</div>';
568
+				$error++;
569
+			}
570
+
571
+			if (! $error)
572
+			{
573
+				if ($db->connected)
574
+				{
575
+					$resultbis = 1;
576
+
577
+					// Create user
578
+					$result=$db->DDLCreateUser($dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_pass, $dolibarr_main_db_name);
579
+					// Create user bis
580
+					if ($databasefortest == 'mysql')
581
+					{
582
+						if (! in_array($dolibarr_main_db_host, array('127.0.0.1', '::1', 'localhost', 'localhost.local')))
583
+						{
584
+							$resultbis=$db->DDLCreateUser('%', $dolibarr_main_db_user, $dolibarr_main_db_pass, $dolibarr_main_db_name);
585
+						}
586
+					}
587
+
588
+					if ($result > 0 && $resultbis > 0)
589
+					{
590
+
591
+						print '<tr><td>';
592
+						print $langs->trans("UserCreation").' : ';
593
+						print $dolibarr_main_db_user;
594
+						print '</td>';
595
+						print '<td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
596
+					}
597
+					else
598
+					{
599
+						if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS'
600
+						|| $db->errno() == 'DB_ERROR_KEY_NAME_ALREADY_EXISTS'
601
+						|| $db->errno() == 'DB_ERROR_USER_ALREADY_EXISTS')
602
+						{
603
+							dolibarr_install_syslog("step1: user already exists");
604
+							print '<tr><td>';
605
+							print $langs->trans("UserCreation").' : ';
606
+							print $dolibarr_main_db_user;
607
+							print '</td>';
608
+							print '<td>'.$langs->trans("LoginAlreadyExists").'</td></tr>';
609
+						}
610
+						else
611
+						{
612
+							dolibarr_install_syslog("step1: failed to create user", LOG_ERR);
613
+							print '<tr><td>';
614
+							print $langs->trans("UserCreation").' : ';
615
+							print $dolibarr_main_db_user;
616
+							print '</td>';
617
+							print '<td>'.$langs->trans("Error").': '.$db->errno().' '.$db->error()."</td></tr>";
618
+						}
619
+					}
620
+
621
+					$db->close();
622
+				}
623
+				else
624
+				{
625
+					print '<tr><td>';
626
+					print $langs->trans("UserCreation").' : ';
627
+					print $dolibarr_main_db_user;
628
+					print '</td>';
629
+					print '<td><img src="../theme/eldy/img/error.png" alt="Error"></td>';
630
+					print '</tr>';
631
+
632
+					// Affiche aide diagnostique
633
+					print '<tr><td colspan="2"><br>';
634
+					print $langs->trans("YouAskDatabaseCreationSoDolibarrNeedToConnect",$dolibarr_main_db_user,$dolibarr_main_db_host,$userroot);
635
+					print '<br>';
636
+					print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
637
+					print $langs->trans("ErrorGoBackAndCorrectParameters").'<br><br>';
638
+					print '</td></tr>';
639
+
640
+					$error++;
641
+				}
642
+			}
643
+		}   // Fin si "creation utilisateur"
644
+
645
+
646
+		// If database creation is asked, we create it
647
+		if (!$error && (isset($db_create_database) && ($db_create_database == "1" || $db_create_database == "on"))) {
648
+			dolibarr_install_syslog("step1: create database: " . $dolibarr_main_db_name . " " . $dolibarr_main_db_character_set . " " . $dolibarr_main_db_collation . " " . $dolibarr_main_db_user);
649
+			$newdb=getDoliDBInstance($conf->db->type,$conf->db->host,$userroot,$passroot,'',$conf->db->port);
650
+			//print 'eee'.$conf->db->type." ".$conf->db->host." ".$userroot." ".$passroot." ".$conf->db->port." ".$newdb->connected." ".$newdb->forcecharset;exit;
651
+
652
+			if ($newdb->connected)
653
+			{
654
+				$result=$newdb->DDLCreateDb($dolibarr_main_db_name, $dolibarr_main_db_character_set, $dolibarr_main_db_collation, $dolibarr_main_db_user);
655
+
656
+				if ($result)
657
+				{
658
+					print '<tr><td>';
659
+					print $langs->trans("DatabaseCreation")." (".$langs->trans("User")." ".$userroot.") : ";
660
+					print $dolibarr_main_db_name;
661
+					print '</td>';
662
+					print '<td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
663
+
664
+					$newdb->select_db($dolibarr_main_db_name);
665
+					$check1=$newdb->getDefaultCharacterSetDatabase();
666
+					$check2=$newdb->getDefaultCollationDatabase();
667
+					dolibarr_install_syslog('step1: new database is using charset=' . $check1 . ' collation=' . $check2);
668
+
669
+					// If values differs, we save conf file again
670
+					//if ($check1 != $dolibarr_main_db_character_set) dolibarr_install_syslog('step1: value for character_set is not the one asked for database creation', LOG_WARNING);
671
+					//if ($check2 != $dolibarr_main_db_collation)     dolibarr_install_syslog('step1: value for collation is not the one asked for database creation', LOG_WARNING);
672
+				}
673
+				else
674
+				{
675
+					// Affiche aide diagnostique
676
+					print '<tr><td colspan="2"><br>';
677
+					print $langs->trans("ErrorFailedToCreateDatabase",$dolibarr_main_db_name).'<br>';
678
+					print $newdb->lasterror().'<br>';
679
+					print $langs->trans("IfDatabaseExistsGoBackAndCheckCreate");
680
+					print '<br>';
681
+					print '</td></tr>';
682
+
683
+					dolibarr_install_syslog('step1: failed to create database ' . $dolibarr_main_db_name . ' ' . $newdb->lasterrno() . ' ' . $newdb->lasterror(), LOG_ERR);
684
+					$error++;
685
+				}
686
+				$newdb->close();
687
+			}
688
+			else {
689
+				print '<tr><td>';
690
+				print $langs->trans("DatabaseCreation")." (".$langs->trans("User")." ".$userroot.") : ";
691
+				print $dolibarr_main_db_name;
692
+				print '</td>';
693
+				print '<td><img src="../theme/eldy/img/error.png" alt="Error"></td>';
694
+				print '</tr>';
695
+
696
+				// Affiche aide diagnostique
697
+				print '<tr><td colspan="2"><br>';
698
+				print $langs->trans("YouAskDatabaseCreationSoDolibarrNeedToConnect",$dolibarr_main_db_user,$dolibarr_main_db_host,$userroot);
699
+				print '<br>';
700
+				print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
701
+				print $langs->trans("ErrorGoBackAndCorrectParameters").'<br><br>';
702
+				print '</td></tr>';
703
+
704
+				$error++;
705
+			}
706
+		}   // Fin si "creation database"
707
+
708
+
709
+		// We test access with dolibarr database user (not admin)
710
+		if (! $error)
711
+		{
712
+			dolibarr_install_syslog("step1: connection type=" . $conf->db->type . " on host=" . $conf->db->host . " port=" . $conf->db->port . " user=" . $conf->db->user . " name=" . $conf->db->name);
713
+			//print "connexion de type=".$conf->db->type." sur host=".$conf->db->host." port=".$conf->db->port." user=".$conf->db->user." name=".$conf->db->name;
714
+
715
+			$db=getDoliDBInstance($conf->db->type,$conf->db->host,$conf->db->user,$conf->db->pass,$conf->db->name,$conf->db->port);
716
+
717
+			if ($db->connected)
718
+			{
719
+				dolibarr_install_syslog("step1: connection to server by user " . $conf->db->user . " ok");
720
+				print "<tr><td>";
721
+				print $langs->trans("ServerConnection")." (".$langs->trans("User")." ".$conf->db->user.") : ";
722
+				print $dolibarr_main_db_host;
723
+				print "</td><td>";
724
+				print '<img src="../theme/eldy/img/tick.png" alt="Ok">';
725
+				print "</td></tr>";
726
+
727
+				// si acces serveur ok et acces base ok, tout est ok, on ne va pas plus loin, on a meme pas utilise le compte root.
728
+				if ($db->database_selected)
729
+				{
730
+					dolibarr_install_syslog("step1: connection to database " . $conf->db->name . " by user " . $conf->db->user . " ok");
731
+					print "<tr><td>";
732
+					print $langs->trans("DatabaseConnection")." (".$langs->trans("User")." ".$conf->db->user.") : ";
733
+					print $dolibarr_main_db_name;
734
+					print "</td><td>";
735
+					print '<img src="../theme/eldy/img/tick.png" alt="Ok">';
736
+					print "</td></tr>";
737
+
738
+					$error = 0;
739
+				}
740
+				else
741
+				{
742
+					dolibarr_install_syslog("step1: connection to database " . $conf->db->name . " by user " . $conf->db->user . " failed", LOG_ERR);
743
+					print "<tr><td>";
744
+					print $langs->trans("DatabaseConnection")." (".$langs->trans("User")." ".$conf->db->user.") : ";
745
+					print $dolibarr_main_db_name;
746
+					print '</td><td>';
747
+					print '<img src="../theme/eldy/img/error.png" alt="Error">';
748
+					print "</td></tr>";
749
+
750
+					// Affiche aide diagnostique
751
+					print '<tr><td colspan="2"><br>';
752
+					print $langs->trans('CheckThatDatabasenameIsCorrect',$dolibarr_main_db_name).'<br>';
753
+					print $langs->trans('IfAlreadyExistsCheckOption').'<br>';
754
+					print $langs->trans("ErrorGoBackAndCorrectParameters").'<br><br>';
755
+					print '</td></tr>';
756
+
757
+					$error++;
758
+				}
759
+			}
760
+			else
761
+			{
762
+				dolibarr_install_syslog("step1: connection to server by user " . $conf->db->user . " failed", LOG_ERR);
763
+				print "<tr><td>";
764
+				print $langs->trans("ServerConnection")." (".$langs->trans("User")." ".$conf->db->user.") : ";
765
+				print $dolibarr_main_db_host;
766
+				print '</td><td>';
767
+				print '<img src="../theme/eldy/img/error.png" alt="Error">';
768
+				print "</td></tr>";
769
+
770
+				// Affiche aide diagnostique
771
+				print '<tr><td colspan="2"><br>';
772
+				print $langs->trans("ErrorConnection",$conf->db->host,$conf->db->name,$conf->db->user);
773
+				print $langs->trans('IfLoginDoesNotExistsCheckCreateUser').'<br>';
774
+				print $langs->trans("ErrorGoBackAndCorrectParameters").'<br><br>';
775
+				print '</td></tr>';
776
+
777
+				$error++;
778
+			}
779
+		}
780
+	}
781
+
782
+	print '</table>';
783 783
 }
784 784
 
785 785
 ?>
@@ -814,15 +814,15 @@  discard block
 block discarded – undo
814 814
  */
815 815
 function write_main_file($mainfile,$main_dir)
816 816
 {
817
-    $fp = @fopen("$mainfile", "w");
818
-    if($fp)
819
-    {
820
-        clearstatcache();
821
-        fputs($fp, '<?php'."\n");
822
-        fputs($fp, "// Wrapper to include main into htdocs\n");
823
-        fputs($fp, "include_once '".$main_dir."/main.inc.php';\n");
824
-        fclose($fp);
825
-    }
817
+	$fp = @fopen("$mainfile", "w");
818
+	if($fp)
819
+	{
820
+		clearstatcache();
821
+		fputs($fp, '<?php'."\n");
822
+		fputs($fp, "// Wrapper to include main into htdocs\n");
823
+		fputs($fp, "include_once '".$main_dir."/main.inc.php';\n");
824
+		fclose($fp);
825
+	}
826 826
 }
827 827
 
828 828
 
@@ -835,15 +835,15 @@  discard block
 block discarded – undo
835 835
  */
836 836
 function write_master_file($masterfile,$main_dir)
837 837
 {
838
-    $fp = @fopen("$masterfile", "w");
839
-    if($fp)
840
-    {
841
-        clearstatcache();
842
-        fputs($fp, '<?php'."\n");
843
-        fputs($fp, "// Wrapper to include master into htdocs\n");
844
-        fputs($fp, "include_once '".$main_dir."/master.inc.php';\n");
845
-        fclose($fp);
846
-    }
838
+	$fp = @fopen("$masterfile", "w");
839
+	if($fp)
840
+	{
841
+		clearstatcache();
842
+		fputs($fp, '<?php'."\n");
843
+		fputs($fp, "// Wrapper to include master into htdocs\n");
844
+		fputs($fp, "include_once '".$main_dir."/master.inc.php';\n");
845
+		fclose($fp);
846
+	}
847 847
 }
848 848
 
849 849
 
@@ -855,47 +855,47 @@  discard block
 block discarded – undo
855 855
  */
856 856
 function write_conf_file($conffile)
857 857
 {
858
-    global $conf,$langs;
859
-    global $main_url,$main_dir,$main_data_dir,$main_force_https,$main_use_alt_dir,$main_alt_dir_name,$main_db_prefix;
860
-    global $dolibarr_main_url_root,$dolibarr_main_document_root,$dolibarr_main_data_root,$dolibarr_main_db_host;
861
-    global $dolibarr_main_db_port,$dolibarr_main_db_name,$dolibarr_main_db_user,$dolibarr_main_db_pass;
862
-    global $dolibarr_main_db_type,$dolibarr_main_db_character_set,$dolibarr_main_db_collation,$dolibarr_main_authentication;
863
-    global $db_host,$db_port,$db_name,$db_user,$db_pass,$db_type,$db_character_set,$db_collation;
864
-    global $conffile,$conffiletoshow,$conffiletoshowshort;
865
-    global $force_dolibarr_lib_ADODB_PATH, $force_dolibarr_lib_NUSOAP_PATH;
866
-    global $force_dolibarr_lib_TCPDF_PATH, $force_dolibarr_lib_FPDI_PATH;
867
-    global $force_dolibarr_lib_PHPEXCEL_PATH, $force_dolibarr_lib_GEOIP_PATH;
868
-    global $force_dolibarr_lib_ODTPHP_PATH, $force_dolibarr_lib_ODTPHP_PATHTOPCLZIP;
869
-    global $force_dolibarr_js_CKEDITOR, $force_dolibarr_js_JQUERY, $force_dolibarr_js_JQUERY_UI, $force_dolibarr_js_JQUERY_FLOT;
870
-    global $force_dolibarr_font_DOL_DEFAULT_TTF, $force_dolibarr_font_DOL_DEFAULT_TTF_BOLD;
871
-
872
-    $error=0;
873
-
874
-    $key = md5(uniqid(mt_rand(),TRUE)); // Generate random hash
875
-
876
-    $fp = fopen("$conffile", "w");
877
-    if($fp)
878
-    {
879
-        clearstatcache();
880
-
881
-        fputs($fp,'<?php'."\n");
882
-        fputs($fp,'//'."\n");
883
-        fputs($fp,'// File generated by Dolibarr installer '.DOL_VERSION.' on '.dol_print_date(dol_now(),'')."\n");
884
-        fputs($fp,'//'."\n");
885
-        fputs($fp,'// Take a look at conf.php.example file for an example of '.$conffiletoshowshort.' file'."\n");
886
-        fputs($fp,'// and explanations for all possibles parameters.'."\n");
887
-        fputs($fp,'//'."\n");
888
-
889
-        fputs($fp, '$dolibarr_main_url_root=\''.str_replace("'","\'",($main_url)).'\';');
890
-        fputs($fp,"\n");
891
-
892
-        fputs($fp, '$dolibarr_main_document_root=\''.str_replace("'","\'",($main_dir)).'\';');
893
-        fputs($fp,"\n");
894
-
895
-        fputs($fp, $main_use_alt_dir.'$dolibarr_main_url_root_alt=\''.str_replace("'","\'",("/".$main_alt_dir_name)).'\';');
896
-        fputs($fp,"\n");
897
-
898
-        fputs($fp, $main_use_alt_dir.'$dolibarr_main_document_root_alt=\''.str_replace("'","\'",($main_dir."/".$main_alt_dir_name)).'\';');
858
+	global $conf,$langs;
859
+	global $main_url,$main_dir,$main_data_dir,$main_force_https,$main_use_alt_dir,$main_alt_dir_name,$main_db_prefix;
860
+	global $dolibarr_main_url_root,$dolibarr_main_document_root,$dolibarr_main_data_root,$dolibarr_main_db_host;
861
+	global $dolibarr_main_db_port,$dolibarr_main_db_name,$dolibarr_main_db_user,$dolibarr_main_db_pass;
862
+	global $dolibarr_main_db_type,$dolibarr_main_db_character_set,$dolibarr_main_db_collation,$dolibarr_main_authentication;
863
+	global $db_host,$db_port,$db_name,$db_user,$db_pass,$db_type,$db_character_set,$db_collation;
864
+	global $conffile,$conffiletoshow,$conffiletoshowshort;
865
+	global $force_dolibarr_lib_ADODB_PATH, $force_dolibarr_lib_NUSOAP_PATH;
866
+	global $force_dolibarr_lib_TCPDF_PATH, $force_dolibarr_lib_FPDI_PATH;
867
+	global $force_dolibarr_lib_PHPEXCEL_PATH, $force_dolibarr_lib_GEOIP_PATH;
868
+	global $force_dolibarr_lib_ODTPHP_PATH, $force_dolibarr_lib_ODTPHP_PATHTOPCLZIP;
869
+	global $force_dolibarr_js_CKEDITOR, $force_dolibarr_js_JQUERY, $force_dolibarr_js_JQUERY_UI, $force_dolibarr_js_JQUERY_FLOT;
870
+	global $force_dolibarr_font_DOL_DEFAULT_TTF, $force_dolibarr_font_DOL_DEFAULT_TTF_BOLD;
871
+
872
+	$error=0;
873
+
874
+	$key = md5(uniqid(mt_rand(),TRUE)); // Generate random hash
875
+
876
+	$fp = fopen("$conffile", "w");
877
+	if($fp)
878
+	{
879
+		clearstatcache();
880
+
881
+		fputs($fp,'<?php'."\n");
882
+		fputs($fp,'//'."\n");
883
+		fputs($fp,'// File generated by Dolibarr installer '.DOL_VERSION.' on '.dol_print_date(dol_now(),'')."\n");
884
+		fputs($fp,'//'."\n");
885
+		fputs($fp,'// Take a look at conf.php.example file for an example of '.$conffiletoshowshort.' file'."\n");
886
+		fputs($fp,'// and explanations for all possibles parameters.'."\n");
887
+		fputs($fp,'//'."\n");
888
+
889
+		fputs($fp, '$dolibarr_main_url_root=\''.str_replace("'","\'",($main_url)).'\';');
890
+		fputs($fp,"\n");
891
+
892
+		fputs($fp, '$dolibarr_main_document_root=\''.str_replace("'","\'",($main_dir)).'\';');
893
+		fputs($fp,"\n");
894
+
895
+		fputs($fp, $main_use_alt_dir.'$dolibarr_main_url_root_alt=\''.str_replace("'","\'",("/".$main_alt_dir_name)).'\';');
896
+		fputs($fp,"\n");
897
+
898
+		fputs($fp, $main_use_alt_dir.'$dolibarr_main_document_root_alt=\''.str_replace("'","\'",($main_dir."/".$main_alt_dir_name)).'\';');
899 899
 		fputs($fp,"\n");
900 900
 
901 901
 		fputs($fp, '$dolibarr_main_data_root=\''.str_replace("'","\'",($main_data_dir)).'\';');
@@ -929,88 +929,88 @@  discard block
 block discarded – undo
929 929
 
930 930
 		/* Authentication */
931 931
 		fputs($fp, '// Authentication settings');
932
-        fputs($fp,"\n");
932
+		fputs($fp,"\n");
933 933
 
934 934
 		fputs($fp, '$dolibarr_main_authentication=\'dolibarr\';');
935 935
 		fputs($fp,"\n\n");
936 936
 
937
-        fputs($fp, '//$dolibarr_main_demo=\'autologin,autopass\';');
938
-        fputs($fp,"\n");
937
+		fputs($fp, '//$dolibarr_main_demo=\'autologin,autopass\';');
938
+		fputs($fp,"\n");
939 939
 
940 940
 		fputs($fp, '// Security settings');
941
-        fputs($fp,"\n");
941
+		fputs($fp,"\n");
942 942
 
943
-        fputs($fp, '$dolibarr_main_prod=\'0\';');
944
-        fputs($fp,"\n");
943
+		fputs($fp, '$dolibarr_main_prod=\'0\';');
944
+		fputs($fp,"\n");
945 945
 
946
-        fputs($fp, '$dolibarr_main_force_https=\''.$main_force_https.'\';');
946
+		fputs($fp, '$dolibarr_main_force_https=\''.$main_force_https.'\';');
947 947
 		fputs($fp,"\n");
948 948
 
949
-        fputs($fp, '$dolibarr_main_restrict_os_commands=\'mysqldump, mysql, pg_dump, pgrestore\';');
949
+		fputs($fp, '$dolibarr_main_restrict_os_commands=\'mysqldump, mysql, pg_dump, pgrestore\';');
950 950
 		fputs($fp,"\n");
951 951
 
952
-        fputs($fp, '$dolibarr_nocsrfcheck=\'0\';');
953
-        fputs($fp,"\n");
952
+		fputs($fp, '$dolibarr_nocsrfcheck=\'0\';');
953
+		fputs($fp,"\n");
954 954
 
955 955
 		fputs($fp, '$dolibarr_main_cookie_cryptkey=\''.$key.'\';');
956 956
 		fputs($fp,"\n");
957 957
 
958 958
 		fputs($fp, '$dolibarr_mailing_limit_sendbyweb=\'0\';');
959
-        fputs($fp,"\n");
960
-
961
-        // Write params to overwrites default lib path
962
-        fputs($fp,"\n");
963
-        if (empty($force_dolibarr_lib_FPDF_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_FPDF_PATH=''; }
964
-        fputs($fp, '$dolibarr_lib_FPDF_PATH=\''.$force_dolibarr_lib_FPDF_PATH.'\';');
965
-        fputs($fp,"\n");
966
-        if (empty($force_dolibarr_lib_TCPDF_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_TCPDF_PATH=''; }
967
-        fputs($fp, '$dolibarr_lib_TCPDF_PATH=\''.$force_dolibarr_lib_TCPDF_PATH.'\';');
968
-        fputs($fp,"\n");
969
-        if (empty($force_dolibarr_lib_FPDI_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_FPDI_PATH=''; }
970
-        fputs($fp, '$dolibarr_lib_FPDI_PATH=\''.$force_dolibarr_lib_FPDI_PATH.'\';');
971
-        fputs($fp,"\n");
972
-        if (empty($force_dolibarr_lib_TCPDI_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_TCPDI_PATH=''; }
973
-        fputs($fp, '$dolibarr_lib_TCPDI_PATH=\''.$force_dolibarr_lib_TCPDI_PATH.'\';');
974
-        fputs($fp,"\n");
975
-        if (empty($force_dolibarr_lib_ADODB_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_ADODB_PATH=''; }
976
-        fputs($fp, '$dolibarr_lib_ADODB_PATH=\''.$force_dolibarr_lib_ADODB_PATH.'\';');
977
-        fputs($fp,"\n");
978
-        if (empty($force_dolibarr_lib_GEOIP_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_GEOIP_PATH=''; }
979
-        fputs($fp, '$dolibarr_lib_GEOIP_PATH=\''.$force_dolibarr_lib_GEOIP_PATH.'\';');
980
-        fputs($fp,"\n");
981
-        if (empty($force_dolibarr_lib_NUSOAP_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_NUSOAP_PATH=''; }
982
-        fputs($fp, '$dolibarr_lib_NUSOAP_PATH=\''.$force_dolibarr_lib_NUSOAP_PATH.'\';');
983
-        fputs($fp,"\n");
984
-        if (empty($force_dolibarr_lib_PHPEXCEL_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_PHPEXCEL_PATH=''; }
985
-        fputs($fp, '$dolibarr_lib_PHPEXCEL_PATH=\''.$force_dolibarr_lib_PHPEXCEL_PATH.'\';');
986
-        fputs($fp,"\n");
987
-        if (empty($force_dolibarr_lib_ODTPHP_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_ODTPHP_PATH=''; }
988
-        fputs($fp, '$dolibarr_lib_ODTPHP_PATH=\''.$force_dolibarr_lib_ODTPHP_PATH.'\';');
989
-        fputs($fp,"\n");
990
-        if (empty($force_dolibarr_lib_ODTPHP_PATHTOPCLZIP)) { fputs($fp, '//'); $force_dolibarr_lib_ODTPHP_PATHTOPCLZIP=''; }
991
-        fputs($fp, '$dolibarr_lib_ODTPHP_PATHTOPCLZIP=\''.$force_dolibarr_lib_ODTPHP_PATHTOPCLZIP.'\';');
992
-        fputs($fp,"\n");
993
-        if (empty($force_dolibarr_js_CKEDITOR)) { fputs($fp, '//'); $force_dolibarr_js_CKEDITOR=''; }
994
-        fputs($fp, '$dolibarr_js_CKEDITOR=\''.$force_dolibarr_js_CKEDITOR.'\';');
995
-        fputs($fp,"\n");
996
-        if (empty($force_dolibarr_js_JQUERY)) { fputs($fp, '//'); $force_dolibarr_js_JQUERY=''; }
997
-        fputs($fp, '$dolibarr_js_JQUERY=\''.$force_dolibarr_js_JQUERY.'\';');
998
-        fputs($fp,"\n");
999
-        if (empty($force_dolibarr_js_JQUERY_UI)) { fputs($fp, '//'); $force_dolibarr_js_JQUERY_UI=''; }
1000
-        fputs($fp, '$dolibarr_js_JQUERY_UI=\''.$force_dolibarr_js_JQUERY_UI.'\';');
1001
-        fputs($fp,"\n");
1002
-        if (empty($force_dolibarr_js_JQUERY_FLOT)) { fputs($fp, '//'); $force_dolibarr_js_JQUERY_FLOT=''; }
1003
-        fputs($fp, '$dolibarr_js_JQUERY_FLOT=\''.$force_dolibarr_js_JQUERY_FLOT.'\';');
1004
-        fputs($fp,"\n");
1005
-
1006
-        // Write params to overwrites default font path
1007
-        fputs($fp,"\n");
1008
-        if (empty($force_dolibarr_font_DOL_DEFAULT_TTF)) { fputs($fp, '//'); $force_dolibarr_font_DOL_DEFAULT_TTF=''; }
959
+		fputs($fp,"\n");
960
+
961
+		// Write params to overwrites default lib path
962
+		fputs($fp,"\n");
963
+		if (empty($force_dolibarr_lib_FPDF_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_FPDF_PATH=''; }
964
+		fputs($fp, '$dolibarr_lib_FPDF_PATH=\''.$force_dolibarr_lib_FPDF_PATH.'\';');
965
+		fputs($fp,"\n");
966
+		if (empty($force_dolibarr_lib_TCPDF_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_TCPDF_PATH=''; }
967
+		fputs($fp, '$dolibarr_lib_TCPDF_PATH=\''.$force_dolibarr_lib_TCPDF_PATH.'\';');
968
+		fputs($fp,"\n");
969
+		if (empty($force_dolibarr_lib_FPDI_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_FPDI_PATH=''; }
970
+		fputs($fp, '$dolibarr_lib_FPDI_PATH=\''.$force_dolibarr_lib_FPDI_PATH.'\';');
971
+		fputs($fp,"\n");
972
+		if (empty($force_dolibarr_lib_TCPDI_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_TCPDI_PATH=''; }
973
+		fputs($fp, '$dolibarr_lib_TCPDI_PATH=\''.$force_dolibarr_lib_TCPDI_PATH.'\';');
974
+		fputs($fp,"\n");
975
+		if (empty($force_dolibarr_lib_ADODB_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_ADODB_PATH=''; }
976
+		fputs($fp, '$dolibarr_lib_ADODB_PATH=\''.$force_dolibarr_lib_ADODB_PATH.'\';');
977
+		fputs($fp,"\n");
978
+		if (empty($force_dolibarr_lib_GEOIP_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_GEOIP_PATH=''; }
979
+		fputs($fp, '$dolibarr_lib_GEOIP_PATH=\''.$force_dolibarr_lib_GEOIP_PATH.'\';');
980
+		fputs($fp,"\n");
981
+		if (empty($force_dolibarr_lib_NUSOAP_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_NUSOAP_PATH=''; }
982
+		fputs($fp, '$dolibarr_lib_NUSOAP_PATH=\''.$force_dolibarr_lib_NUSOAP_PATH.'\';');
983
+		fputs($fp,"\n");
984
+		if (empty($force_dolibarr_lib_PHPEXCEL_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_PHPEXCEL_PATH=''; }
985
+		fputs($fp, '$dolibarr_lib_PHPEXCEL_PATH=\''.$force_dolibarr_lib_PHPEXCEL_PATH.'\';');
986
+		fputs($fp,"\n");
987
+		if (empty($force_dolibarr_lib_ODTPHP_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_ODTPHP_PATH=''; }
988
+		fputs($fp, '$dolibarr_lib_ODTPHP_PATH=\''.$force_dolibarr_lib_ODTPHP_PATH.'\';');
989
+		fputs($fp,"\n");
990
+		if (empty($force_dolibarr_lib_ODTPHP_PATHTOPCLZIP)) { fputs($fp, '//'); $force_dolibarr_lib_ODTPHP_PATHTOPCLZIP=''; }
991
+		fputs($fp, '$dolibarr_lib_ODTPHP_PATHTOPCLZIP=\''.$force_dolibarr_lib_ODTPHP_PATHTOPCLZIP.'\';');
992
+		fputs($fp,"\n");
993
+		if (empty($force_dolibarr_js_CKEDITOR)) { fputs($fp, '//'); $force_dolibarr_js_CKEDITOR=''; }
994
+		fputs($fp, '$dolibarr_js_CKEDITOR=\''.$force_dolibarr_js_CKEDITOR.'\';');
995
+		fputs($fp,"\n");
996
+		if (empty($force_dolibarr_js_JQUERY)) { fputs($fp, '//'); $force_dolibarr_js_JQUERY=''; }
997
+		fputs($fp, '$dolibarr_js_JQUERY=\''.$force_dolibarr_js_JQUERY.'\';');
998
+		fputs($fp,"\n");
999
+		if (empty($force_dolibarr_js_JQUERY_UI)) { fputs($fp, '//'); $force_dolibarr_js_JQUERY_UI=''; }
1000
+		fputs($fp, '$dolibarr_js_JQUERY_UI=\''.$force_dolibarr_js_JQUERY_UI.'\';');
1001
+		fputs($fp,"\n");
1002
+		if (empty($force_dolibarr_js_JQUERY_FLOT)) { fputs($fp, '//'); $force_dolibarr_js_JQUERY_FLOT=''; }
1003
+		fputs($fp, '$dolibarr_js_JQUERY_FLOT=\''.$force_dolibarr_js_JQUERY_FLOT.'\';');
1004
+		fputs($fp,"\n");
1005
+
1006
+		// Write params to overwrites default font path
1007
+		fputs($fp,"\n");
1008
+		if (empty($force_dolibarr_font_DOL_DEFAULT_TTF)) { fputs($fp, '//'); $force_dolibarr_font_DOL_DEFAULT_TTF=''; }
1009 1009
    		fputs($fp, '$dolibarr_font_DOL_DEFAULT_TTF=\''.$force_dolibarr_font_DOL_DEFAULT_TTF.'\';');
1010
-        fputs($fp,"\n");
1011
-        if (empty($force_dolibarr_font_DOL_DEFAULT_TTF_BOLD)) { fputs($fp, '//'); $force_dolibarr_font_DOL_DEFAULT_TTF_BOLD=''; }
1012
-        fputs($fp, '$dolibarr_font_DOL_DEFAULT_TTF_BOLD=\''.$force_dolibarr_font_DOL_DEFAULT_TTF_BOLD.'\';');
1013
-        fputs($fp,"\n");
1010
+		fputs($fp,"\n");
1011
+		if (empty($force_dolibarr_font_DOL_DEFAULT_TTF_BOLD)) { fputs($fp, '//'); $force_dolibarr_font_DOL_DEFAULT_TTF_BOLD=''; }
1012
+		fputs($fp, '$dolibarr_font_DOL_DEFAULT_TTF_BOLD=\''.$force_dolibarr_font_DOL_DEFAULT_TTF_BOLD.'\';');
1013
+		fputs($fp,"\n");
1014 1014
 
1015 1015
 		fclose($fp);
1016 1016
 
Please login to merge, or discard this patch.
Spacing   +238 added lines, -238 removed lines patch added patch discarded remove patch
@@ -26,14 +26,14 @@  discard block
 block discarded – undo
26 26
  *		\brief      Build conf file on disk
27 27
  */
28 28
 
29
-define('DONOTLOADCONF',1);	// To avoid loading conf by file inc.php
29
+define('DONOTLOADCONF', 1); // To avoid loading conf by file inc.php
30 30
 
31 31
 include 'inc.php';
32 32
 
33 33
 global $langs;
34 34
 
35
-$action=GETPOST('action','alpha');
36
-$setuplang=(GETPOST('selectlang','aZ09',3)?GETPOST('selectlang','aZ09',3):'auto');
35
+$action = GETPOST('action', 'alpha');
36
+$setuplang = (GETPOST('selectlang', 'aZ09', 3) ?GETPOST('selectlang', 'aZ09', 3) : 'auto');
37 37
 $langs->setDefaultLang($setuplang);
38 38
 
39 39
 $langs->load("admin");
@@ -43,39 +43,39 @@  discard block
 block discarded – undo
43 43
 // Dolibarr pages directory
44 44
 $main_dir = GETPOST('main_dir');
45 45
 // Directory for generated documents (invoices, orders, ecm, etc...)
46
-$main_data_dir = GETPOST('main_data_dir') ? GETPOST('main_data_dir') : $main_dir . '/documents';
46
+$main_data_dir = GETPOST('main_data_dir') ? GETPOST('main_data_dir') : $main_dir.'/documents';
47 47
 // Dolibarr root URL
48 48
 $main_url = GETPOST('main_url');
49 49
 // Database login informations
50
-$userroot=GETPOST('db_user_root');
51
-$passroot=GETPOST('db_pass_root');
50
+$userroot = GETPOST('db_user_root');
51
+$passroot = GETPOST('db_pass_root');
52 52
 // Database server
53
-$db_type=GETPOST('db_type','alpha');
54
-$db_host=GETPOST('db_host','alpha');
55
-$db_name=GETPOST('db_name','alpha');
56
-$db_user=GETPOST('db_user','alpha');
57
-$db_pass=GETPOST('db_pass');
58
-$db_port=GETPOST('db_port','int');
59
-$db_prefix=GETPOST('db_prefix','alpha');
60
-$db_create_database = GETPOST('db_create_database','none');
61
-$db_create_user = GETPOST('db_create_user','none');
53
+$db_type = GETPOST('db_type', 'alpha');
54
+$db_host = GETPOST('db_host', 'alpha');
55
+$db_name = GETPOST('db_name', 'alpha');
56
+$db_user = GETPOST('db_user', 'alpha');
57
+$db_pass = GETPOST('db_pass');
58
+$db_port = GETPOST('db_port', 'int');
59
+$db_prefix = GETPOST('db_prefix', 'alpha');
60
+$db_create_database = GETPOST('db_create_database', 'none');
61
+$db_create_user = GETPOST('db_create_user', 'none');
62 62
 // Force https
63
-$main_force_https = ((GETPOST("main_force_https",'alpha') && (GETPOST("main_force_https",'alpha') == "on" || GETPOST("main_force_https",'alpha') == 1)) ? '1' : '0');
63
+$main_force_https = ((GETPOST("main_force_https", 'alpha') && (GETPOST("main_force_https", 'alpha') == "on" || GETPOST("main_force_https", 'alpha') == 1)) ? '1' : '0');
64 64
 // Use alternative directory
65
-$main_use_alt_dir = ((GETPOST("main_use_alt_dir",'alpha') == '' || (GETPOST("main_use_alt_dir",'alpha') == "on" || GETPOST("main_use_alt_dir",'alpha') == 1)) ? '' : '//');
65
+$main_use_alt_dir = ((GETPOST("main_use_alt_dir", 'alpha') == '' || (GETPOST("main_use_alt_dir", 'alpha') == "on" || GETPOST("main_use_alt_dir", 'alpha') == 1)) ? '' : '//');
66 66
 // Alternative root directory name
67
-$main_alt_dir_name = ((GETPOST("main_alt_dir_name",'alpha') && GETPOST("main_alt_dir_name",'alpha') != '') ? GETPOST("main_alt_dir_name",'alpha') : 'custom');
67
+$main_alt_dir_name = ((GETPOST("main_alt_dir_name", 'alpha') && GETPOST("main_alt_dir_name", 'alpha') != '') ? GETPOST("main_alt_dir_name", 'alpha') : 'custom');
68 68
 
69
-session_start();    // To be able to keep info into session (used for not losing password during navigation. The password must not transit through parameters)
69
+session_start(); // To be able to keep info into session (used for not losing password during navigation. The password must not transit through parameters)
70 70
 
71 71
 // Save a flag to tell to restore input value if we do back
72
-$_SESSION['dol_save_pass']=$db_pass;
72
+$_SESSION['dol_save_pass'] = $db_pass;
73 73
 //$_SESSION['dol_save_passroot']=$passroot;
74 74
 
75 75
 // Now we load forced value from install.forced.php file.
76
-$useforcedwizard=false;
77
-$forcedfile="./install.forced.php";
78
-if ($conffile == "/etc/dolibarr/conf.php") $forcedfile="/etc/dolibarr/install.forced.php";
76
+$useforcedwizard = false;
77
+$forcedfile = "./install.forced.php";
78
+if ($conffile == "/etc/dolibarr/conf.php") $forcedfile = "/etc/dolibarr/install.forced.php";
79 79
 if (@file_exists($forcedfile)) {
80 80
 	$useforcedwizard = true;
81 81
 	include_once $forcedfile;
@@ -140,13 +140,13 @@  discard block
 block discarded – undo
140 140
 
141 141
 dolibarr_install_syslog("--- step1: entering step1.php page");
142 142
 
143
-pHeader($langs->trans("ConfigurationFile"),"step2");
143
+pHeader($langs->trans("ConfigurationFile"), "step2");
144 144
 
145 145
 // Test if we can run a first install process
146
-if (! is_writable($conffile))
146
+if (!is_writable($conffile))
147 147
 {
148
-    print $langs->trans("ConfFileIsNotWritable",$conffiletoshow);
149
-    pFooter(1,$setuplang,'jscheckparam');
148
+    print $langs->trans("ConfFileIsNotWritable", $conffiletoshow);
149
+    pFooter(1, $setuplang, 'jscheckparam');
150 150
     exit;
151 151
 }
152 152
 
@@ -155,65 +155,65 @@  discard block
 block discarded – undo
155 155
 $is_sqlite = false;
156 156
 if (empty($db_type))
157 157
 {
158
-    print '<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("DatabaseType")).'</div>';
158
+    print '<div class="error">'.$langs->trans("ErrorFieldRequired", $langs->transnoentities("DatabaseType")).'</div>';
159 159
     $error++;
160 160
 } else {
161
-	$is_sqlite = ($db_type === 'sqlite' || $db_type === 'sqlite3' );
161
+	$is_sqlite = ($db_type === 'sqlite' || $db_type === 'sqlite3');
162 162
 }
163
-if (empty($db_host) && ! $is_sqlite)
163
+if (empty($db_host) && !$is_sqlite)
164 164
 {
165
-    print '<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Server")).'</div>';
165
+    print '<div class="error">'.$langs->trans("ErrorFieldRequired", $langs->transnoentities("Server")).'</div>';
166 166
     $error++;
167 167
 }
168 168
 if (empty($db_name))
169 169
 {
170
-    print '<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("DatabaseName")).'</div>';
170
+    print '<div class="error">'.$langs->trans("ErrorFieldRequired", $langs->transnoentities("DatabaseName")).'</div>';
171 171
     $error++;
172 172
 }
173
-if (empty($db_user)  && ! $is_sqlite)
173
+if (empty($db_user) && !$is_sqlite)
174 174
 {
175
-    print '<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Login")).'</div>';
175
+    print '<div class="error">'.$langs->trans("ErrorFieldRequired", $langs->transnoentities("Login")).'</div>';
176 176
     $error++;
177 177
 }
178
-if (! empty($db_port) && ! is_numeric($db_port))
178
+if (!empty($db_port) && !is_numeric($db_port))
179 179
 {
180
-    print '<div class="error">'.$langs->trans("ErrorBadValueForParameter",$db_port,$langs->transnoentities("Port")).'</div>';
180
+    print '<div class="error">'.$langs->trans("ErrorBadValueForParameter", $db_port, $langs->transnoentities("Port")).'</div>';
181 181
     $error++;
182 182
 }
183
-if (! empty($db_prefix) && ! preg_match('/^[a-z0-9]+_$/i', $db_prefix))
183
+if (!empty($db_prefix) && !preg_match('/^[a-z0-9]+_$/i', $db_prefix))
184 184
 {
185
-	print '<div class="error">'.$langs->trans("ErrorBadValueForParameter",$db_prefix,$langs->transnoentities("DatabasePrefix")).'</div>';
185
+	print '<div class="error">'.$langs->trans("ErrorBadValueForParameter", $db_prefix, $langs->transnoentities("DatabasePrefix")).'</div>';
186 186
 	$error++;
187 187
 }
188 188
 
189 189
 
190 190
 // Remove last / into dans main_dir
191
-if (substr($main_dir, dol_strlen($main_dir) -1) == "/")
191
+if (substr($main_dir, dol_strlen($main_dir) - 1) == "/")
192 192
 {
193
-    $main_dir = substr($main_dir, 0, dol_strlen($main_dir)-1);
193
+    $main_dir = substr($main_dir, 0, dol_strlen($main_dir) - 1);
194 194
 }
195 195
 
196 196
 // Remove last / into dans main_url
197
-if (! empty($main_url) && substr($main_url, dol_strlen($main_url) -1) == "/")
197
+if (!empty($main_url) && substr($main_url, dol_strlen($main_url) - 1) == "/")
198 198
 {
199
-    $main_url = substr($main_url, 0, dol_strlen($main_url)-1);
199
+    $main_url = substr($main_url, 0, dol_strlen($main_url) - 1);
200 200
 }
201 201
 
202 202
 // Test database connection
203
-if (! $error) {
204
-    $result=@include_once $main_dir."/core/db/".$db_type.'.class.php';
203
+if (!$error) {
204
+    $result = @include_once $main_dir."/core/db/".$db_type.'.class.php';
205 205
     if ($result)
206 206
     {
207 207
         // If we ask database or user creation we need to connect as root, so we need root login
208 208
         if (!empty($db_create_database) && !$userroot) {
209
-            print '<div class="error">'.$langs->trans("YouAskDatabaseCreationSoDolibarrNeedToConnect",$db_name).'</div>';
209
+            print '<div class="error">'.$langs->trans("YouAskDatabaseCreationSoDolibarrNeedToConnect", $db_name).'</div>';
210 210
             print '<br>';
211 211
             print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
212 212
             print $langs->trans("ErrorGoBackAndCorrectParameters");
213 213
             $error++;
214 214
         }
215 215
         if (!empty($db_create_user) && !$userroot) {
216
-            print '<div class="error">'.$langs->trans("YouAskLoginCreationSoDolibarrNeedToConnect",$db_user).'</div>';
216
+            print '<div class="error">'.$langs->trans("YouAskLoginCreationSoDolibarrNeedToConnect", $db_user).'</div>';
217 217
             print '<br>';
218 218
             print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
219 219
             print $langs->trans("ErrorGoBackAndCorrectParameters");
@@ -222,39 +222,39 @@  discard block
 block discarded – undo
222 222
 
223 223
         // If we need root access
224 224
         if (!$error && (!empty($db_create_database) || !empty($db_create_user))) {
225
-            $databasefortest=$db_name;
225
+            $databasefortest = $db_name;
226 226
             if (!empty($db_create_database)) {
227 227
                 if ($db_type == 'mysql' || $db_type == 'mysqli')
228 228
                 {
229
-                    $databasefortest='mysql';
229
+                    $databasefortest = 'mysql';
230 230
                 }
231 231
                 elseif ($db_type == 'pgsql')
232 232
                 {
233
-                    $databasefortest='postgres';
233
+                    $databasefortest = 'postgres';
234 234
                 }
235 235
                 else
236 236
                 {
237
-                    $databasefortest='master';
237
+                    $databasefortest = 'master';
238 238
                 }
239 239
             }
240 240
             //print $_POST["db_type"].",".$_POST["db_host"].",$userroot,$passroot,$databasefortest,".$_POST["db_port"];
241 241
 
242
-            $db=getDoliDBInstance($db_type, $db_host, $userroot, $passroot, $databasefortest, $db_port);
242
+            $db = getDoliDBInstance($db_type, $db_host, $userroot, $passroot, $databasefortest, $db_port);
243 243
 
244
-            dol_syslog("databasefortest=" . $databasefortest . " connected=" . $db->connected . " database_selected=" . $db->database_selected, LOG_DEBUG);
244
+            dol_syslog("databasefortest=".$databasefortest." connected=".$db->connected." database_selected=".$db->database_selected, LOG_DEBUG);
245 245
             //print "databasefortest=".$databasefortest." connected=".$db->connected." database_selected=".$db->database_selected;
246 246
 
247 247
 			if (empty($db_create_database) && $db->connected && !$db->database_selected) {
248
-                print '<div class="error">'.$langs->trans("ErrorConnectedButDatabaseNotFound",$db_name).'</div>';
248
+                print '<div class="error">'.$langs->trans("ErrorConnectedButDatabaseNotFound", $db_name).'</div>';
249 249
                 print '<br>';
250
-                if (! $db->connected) print $langs->trans("IfDatabaseNotExistsGoBackAndUncheckCreate").'<br><br>';
250
+                if (!$db->connected) print $langs->trans("IfDatabaseNotExistsGoBackAndUncheckCreate").'<br><br>';
251 251
                 print $langs->trans("ErrorGoBackAndCorrectParameters");
252 252
                 $error++;
253
-            } elseif ($db->error && ! (! empty($db_create_database) && $db->connected)) {
253
+            } elseif ($db->error && !(!empty($db_create_database) && $db->connected)) {
254 254
             	// Note: you may experience error here with message "No such file or directory" when mysql was installed for the first time but not yet launched.
255 255
                 if ($db->error == "No such file or directory") print '<div class="error">'.$langs->trans("ErrorToConnectToMysqlCheckInstance").'</div>';
256 256
                 else print '<div class="error">'.$db->error.'</div>';
257
-                if (! $db->connected) print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
257
+                if (!$db->connected) print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
258 258
                 //print '<a href="#" onClick="javascript: history.back();">';
259 259
                 print $langs->trans("ErrorGoBackAndCorrectParameters");
260 260
                 //print '</a>';
@@ -263,12 +263,12 @@  discard block
 block discarded – undo
263 263
         }
264 264
         // If we need simple access
265 265
         if (!$error && (empty($db_create_database) && empty($db_create_user))) {
266
-            $db=getDoliDBInstance($db_type, $db_host, $db_user, $db_pass, $db_name, $db_port);
266
+            $db = getDoliDBInstance($db_type, $db_host, $db_user, $db_pass, $db_name, $db_port);
267 267
 
268 268
             if ($db->error)
269 269
             {
270 270
                 print '<div class="error">'.$db->error.'</div>';
271
-                if (! $db->connected) print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
271
+                if (!$db->connected) print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
272 272
                 //print '<a href="#" onClick="javascript: history.back();">';
273 273
                 print $langs->trans("ErrorGoBackAndCorrectParameters");
274 274
                 //print '</a>';
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
     else
280 280
     {
281 281
         print "<br>\nFailed to include_once(\"".$main_dir."/core/db/".$db_type.".class.php\")<br>\n";
282
-        print '<div class="error">'.$langs->trans("ErrorWrongValueForParameter",$langs->transnoentities("WebPagesDirectory")).'</div>';
282
+        print '<div class="error">'.$langs->trans("ErrorWrongValueForParameter", $langs->transnoentities("WebPagesDirectory")).'</div>';
283 283
         //print '<a href="#" onClick="javascript: history.back();">';
284 284
         print $langs->trans("ErrorGoBackAndCorrectParameters");
285 285
         //print '</a>';
@@ -290,15 +290,15 @@  discard block
 block discarded – undo
290 290
 else
291 291
 {
292 292
     if (isset($db)) print $db->lasterror();
293
-    if (isset($db) && ! $db->connected) print '<br>'.$langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
293
+    if (isset($db) && !$db->connected) print '<br>'.$langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
294 294
     print $langs->trans("ErrorGoBackAndCorrectParameters");
295 295
     $error++;
296 296
 }
297 297
 
298
-if (! $error && $db->connected)
298
+if (!$error && $db->connected)
299 299
 {
300
-    if (! empty($db_create_database)) {
301
-        $result=$db->select_db($db_name);
300
+    if (!empty($db_create_database)) {
301
+        $result = $db->select_db($db_name);
302 302
         if ($result)
303 303
         {
304 304
             print '<div class="error">'.$langs->trans("ErrorDatabaseAlreadyExists", $db_name).'</div>';
@@ -310,19 +310,19 @@  discard block
 block discarded – undo
310 310
 }
311 311
 
312 312
 // Define $defaultCharacterSet and $defaultDBSortingCollation
313
-if (! $error && $db->connected)
313
+if (!$error && $db->connected)
314 314
 {
315 315
     if (!empty($db_create_database))    // If we create database, we force default value
316 316
     {
317 317
         // Default values come from the database handler
318 318
 
319
-        $defaultCharacterSet=$db->forcecharset;
320
-    	$defaultDBSortingCollation=$db->forcecollate;
319
+        $defaultCharacterSet = $db->forcecharset;
320
+    	$defaultDBSortingCollation = $db->forcecollate;
321 321
     }
322 322
     else	// If already created, we take current value
323 323
     {
324
-        $defaultCharacterSet=$db->getDefaultCharacterSetDatabase();
325
-        $defaultDBSortingCollation=$db->getDefaultCollationDatabase();
324
+        $defaultCharacterSet = $db->getDefaultCharacterSetDatabase();
325
+        $defaultDBSortingCollation = $db->getDefaultCollationDatabase();
326 326
     }
327 327
 
328 328
     // Force to avoid utf8mb4 because index on field char 255 reach limit of 767 char for indexes (example with mysql 5.6.34 = mariadb 10.0.29)
@@ -335,22 +335,22 @@  discard block
 block discarded – undo
335 335
 
336 336
     print '<input type="hidden" name="dolibarr_main_db_character_set" value="'.$defaultCharacterSet.'">';
337 337
     print '<input type="hidden" name="dolibarr_main_db_collation" value="'.$defaultDBSortingCollation.'">';
338
-    $db_character_set=$defaultCharacterSet;
339
-    $db_collation=$defaultDBSortingCollation;
340
-    dolibarr_install_syslog("step1: db_character_set=" . $db_character_set . " db_collation=" . $db_collation);
338
+    $db_character_set = $defaultCharacterSet;
339
+    $db_collation = $defaultDBSortingCollation;
340
+    dolibarr_install_syslog("step1: db_character_set=".$db_character_set." db_collation=".$db_collation);
341 341
 }
342 342
 
343 343
 
344 344
 // Create config file
345
-if (! $error && $db->connected && $action == "set")
345
+if (!$error && $db->connected && $action == "set")
346 346
 {
347 347
     umask(0);
348 348
     if (is_array($_POST))
349 349
     {
350
-        foreach($_POST as $key => $value)
350
+        foreach ($_POST as $key => $value)
351 351
         {
352
-            if (! preg_match('/^db_pass/i', $key)) {
353
-    			dolibarr_install_syslog("step1: choice for " . $key . " = " . $value);
352
+            if (!preg_match('/^db_pass/i', $key)) {
353
+    			dolibarr_install_syslog("step1: choice for ".$key." = ".$value);
354 354
     		}
355 355
         }
356 356
     }
@@ -360,15 +360,15 @@  discard block
 block discarded – undo
360 360
     print '<table cellspacing="0" width="100%" cellpadding="1" border="0">';
361 361
 
362 362
     // Check parameter main_dir
363
-    if (! $error)
363
+    if (!$error)
364 364
     {
365
-        if (! is_dir($main_dir))
365
+        if (!is_dir($main_dir))
366 366
         {
367
-            dolibarr_install_syslog("step1: directory '" . $main_dir . "' is unavailable or can't be accessed");
367
+            dolibarr_install_syslog("step1: directory '".$main_dir."' is unavailable or can't be accessed");
368 368
 
369 369
             print "<tr><td>";
370
-            print $langs->trans("ErrorDirDoesNotExists",$main_dir).'<br>';
371
-            print $langs->trans("ErrorWrongValueForParameter",$langs->trans("WebPagesDirectory")).'<br>';
370
+            print $langs->trans("ErrorDirDoesNotExists", $main_dir).'<br>';
371
+            print $langs->trans("ErrorWrongValueForParameter", $langs->trans("WebPagesDirectory")).'<br>';
372 372
             print $langs->trans("ErrorGoBackAndCorrectParameters").'<br><br>';
373 373
             print '</td><td>';
374 374
             print $langs->trans("Error");
@@ -377,43 +377,43 @@  discard block
 block discarded – undo
377 377
         }
378 378
     }
379 379
 
380
-    if (! $error)
380
+    if (!$error)
381 381
     {
382
-        dolibarr_install_syslog("step1: directory '" . $main_dir . "' exists");
382
+        dolibarr_install_syslog("step1: directory '".$main_dir."' exists");
383 383
     }
384 384
 
385 385
 
386 386
     // Create subdirectory main_data_dir
387
-    if (! $error)
387
+    if (!$error)
388 388
     {
389 389
         // Create directory for documents
390
-        if (! is_dir($main_data_dir))
390
+        if (!is_dir($main_data_dir))
391 391
         {
392 392
             dol_mkdir($main_data_dir);
393 393
         }
394 394
 
395
-        if (! is_dir($main_data_dir))
395
+        if (!is_dir($main_data_dir))
396 396
         {
397
-            print "<tr><td>".$langs->trans("ErrorDirDoesNotExists",$main_data_dir);
397
+            print "<tr><td>".$langs->trans("ErrorDirDoesNotExists", $main_data_dir);
398 398
             print ' '.$langs->trans("YouMustCreateItAndAllowServerToWrite");
399 399
             print '</td><td>';
400 400
             print '<font class="error">'.$langs->trans("Error").'</font>';
401 401
             print "</td></tr>";
402
-            print '<tr><td colspan="2"><br>'.$langs->trans("CorrectProblemAndReloadPage",$_SERVER['PHP_SELF'].'?testget=ok').'</td></tr>';
402
+            print '<tr><td colspan="2"><br>'.$langs->trans("CorrectProblemAndReloadPage", $_SERVER['PHP_SELF'].'?testget=ok').'</td></tr>';
403 403
             $error++;
404 404
         }
405 405
         else
406 406
         {
407 407
             // Create .htaccess file in document directory
408
-            $pathhtaccess=$main_data_dir.'/.htaccess';
409
-            if (! file_exists($pathhtaccess))
408
+            $pathhtaccess = $main_data_dir.'/.htaccess';
409
+            if (!file_exists($pathhtaccess))
410 410
             {
411
-                dolibarr_install_syslog("step1: .htaccess file did not exist, we created it in '" . $main_data_dir . "'");
412
-                $handlehtaccess=@fopen($pathhtaccess,'w');
411
+                dolibarr_install_syslog("step1: .htaccess file did not exist, we created it in '".$main_data_dir."'");
412
+                $handlehtaccess = @fopen($pathhtaccess, 'w');
413 413
                 if ($handlehtaccess)
414 414
                 {
415
-                    fwrite($handlehtaccess,'Order allow,deny'."\n");
416
-                    fwrite($handlehtaccess,'Deny from all'."\n");
415
+                    fwrite($handlehtaccess, 'Order allow,deny'."\n");
416
+                    fwrite($handlehtaccess, 'Deny from all'."\n");
417 417
 
418 418
                     fclose($handlehtaccess);
419 419
                     dolibarr_install_syslog("step1: .htaccess file created");
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
             }
422 422
 
423 423
             // Les documents sont en dehors de htdocs car ne doivent pas pouvoir etre telecharges en passant outre l'authentification
424
-            $dir=array();
424
+            $dir = array();
425 425
             $dir[] = $main_data_dir."/mycompany";
426 426
             $dir[] = $main_data_dir."/medias";
427 427
             $dir[] = $main_data_dir."/users";
@@ -432,12 +432,12 @@  discard block
 block discarded – undo
432 432
             $dir[] = $main_data_dir."/doctemplates";
433 433
 
434 434
             // Boucle sur chaque repertoire de dir[] pour les creer s'ils nexistent pas
435
-            $num=count($dir);
435
+            $num = count($dir);
436 436
             for ($i = 0; $i < $num; $i++)
437 437
             {
438 438
                 if (is_dir($dir[$i]))
439 439
                 {
440
-                    dolibarr_install_syslog("step1: directory '" . $dir[$i] . "' exists");
440
+                    dolibarr_install_syslog("step1: directory '".$dir[$i]."' exists");
441 441
                 }
442 442
                 else
443 443
                 {
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
                     }
453 453
                     else
454 454
                     {
455
-                        dolibarr_install_syslog("step1: directory '" . $dir[$i] . "' created");
455
+                        dolibarr_install_syslog("step1: directory '".$dir[$i]."' created");
456 456
                     }
457 457
                 }
458 458
             }
@@ -460,25 +460,25 @@  discard block
 block discarded – undo
460 460
             require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
461 461
 
462 462
             // Copy directory medias
463
-            $srcroot=$main_dir.'/install/medias';
464
-            $destroot=$main_data_dir.'/medias';
463
+            $srcroot = $main_dir.'/install/medias';
464
+            $destroot = $main_data_dir.'/medias';
465 465
             dolCopyDir($srcroot, $destroot, 0, 0);
466 466
 
467 467
             if ($error)
468 468
             {
469
-                print "<tr><td>".$langs->trans("ErrorDirDoesNotExists",$main_data_dir);
469
+                print "<tr><td>".$langs->trans("ErrorDirDoesNotExists", $main_data_dir);
470 470
                 print ' '.$langs->trans("YouMustCreateItAndAllowServerToWrite");
471 471
                 print '</td><td>';
472 472
                 print '<font class="error">'.$langs->trans("Error").'</font>';
473 473
                 print "</td></tr>";
474
-                print '<tr><td colspan="2"><br>'.$langs->trans("CorrectProblemAndReloadPage",$_SERVER['PHP_SELF'].'?testget=ok').'</td></tr>';
474
+                print '<tr><td colspan="2"><br>'.$langs->trans("CorrectProblemAndReloadPage", $_SERVER['PHP_SELF'].'?testget=ok').'</td></tr>';
475 475
             }
476 476
             else
477 477
             {
478 478
             	//ODT templates
479
-            	$srcroot=$main_dir.'/install/doctemplates';
480
-            	$destroot=$main_data_dir.'/doctemplates';
481
-            	$docs=array(
479
+            	$srcroot = $main_dir.'/install/doctemplates';
480
+            	$destroot = $main_data_dir.'/doctemplates';
481
+            	$docs = array(
482 482
             		'contracts' => 'contract',
483 483
             		'invoices' => 'invoice',
484 484
             		'orders' => 'order',
@@ -493,17 +493,17 @@  discard block
 block discarded – undo
493 493
             		'users' => 'user',
494 494
             		'usergroups' => 'usergroups',
495 495
             	);
496
-            	foreach($docs as $cursordir => $cursorfile)
496
+            	foreach ($docs as $cursordir => $cursorfile)
497 497
             	{
498
-            		$src=$srcroot.'/'.$cursordir.'/template_'.$cursorfile.'.odt';
499
-            		$dirodt=$destroot.'/'.$cursordir;
500
-            		$dest=$dirodt.'/template_'.$cursorfile.'.odt';
498
+            		$src = $srcroot.'/'.$cursordir.'/template_'.$cursorfile.'.odt';
499
+            		$dirodt = $destroot.'/'.$cursordir;
500
+            		$dest = $dirodt.'/template_'.$cursorfile.'.odt';
501 501
 
502 502
             		dol_mkdir($dirodt);
503
-            		$result=dol_copy($src,$dest,0,0);
503
+            		$result = dol_copy($src, $dest, 0, 0);
504 504
             		if ($result < 0)
505 505
             		{
506
-            			print '<tr><td colspan="2"><br>'.$langs->trans('ErrorFailToCopyFile',$src,$dest).'</td></tr>';
506
+            			print '<tr><td colspan="2"><br>'.$langs->trans('ErrorFailToCopyFile', $src, $dest).'</td></tr>';
507 507
             		}
508 508
             	}
509 509
             }
@@ -511,10 +511,10 @@  discard block
 block discarded – undo
511 511
     }
512 512
 
513 513
     // Table prefix
514
-    $main_db_prefix = (! empty($db_prefix) ? $db_prefix : 'llx_');
514
+    $main_db_prefix = (!empty($db_prefix) ? $db_prefix : 'llx_');
515 515
 
516 516
     // Write conf file on disk
517
-    if (! $error)
517
+    if (!$error)
518 518
     {
519 519
         // Save old conf file on disk
520 520
         if (file_exists("$conffile"))
@@ -525,11 +525,11 @@  discard block
 block discarded – undo
525 525
             @dol_copy($conffile, $conffile.'.old', '0400');
526 526
         }
527 527
 
528
-        $error+=write_conf_file($conffile);
528
+        $error += write_conf_file($conffile);
529 529
     }
530 530
 
531 531
     // Create database and admin user database
532
-    if (! $error)
532
+    if (!$error)
533 533
     {
534 534
         // We reload configuration file
535 535
         conf($dolibarr_main_document_root);
@@ -541,26 +541,26 @@  discard block
 block discarded – undo
541 541
 
542 542
         // Si creation utilisateur admin demandee, on le cree
543 543
         if (isset($db_create_user) && ($db_create_user == "1" || $db_create_user == "on")) {
544
-            dolibarr_install_syslog("step1: create database user: " . $dolibarr_main_db_user);
544
+            dolibarr_install_syslog("step1: create database user: ".$dolibarr_main_db_user);
545 545
 
546 546
             //print $conf->db->host." , ".$conf->db->name." , ".$conf->db->user." , ".$conf->db->port;
547
-            $databasefortest=$conf->db->name;
547
+            $databasefortest = $conf->db->name;
548 548
             if ($conf->db->type == 'mysql' || $conf->db->type == 'mysqli')
549 549
             {
550
-                $databasefortest='mysql';
550
+                $databasefortest = 'mysql';
551 551
             }
552 552
             else if ($conf->db->type == 'pgsql')
553 553
             {
554
-                $databasefortest='postgres';
554
+                $databasefortest = 'postgres';
555 555
             }
556 556
             else if ($conf->db->type == 'mssql')
557 557
             {
558
-                $databasefortest='master';
558
+                $databasefortest = 'master';
559 559
             }
560 560
 
561 561
             // Creation handler de base, verification du support et connexion
562 562
 
563
-            $db=getDoliDBInstance($conf->db->type,$conf->db->host,$userroot,$passroot,$databasefortest,$conf->db->port);
563
+            $db = getDoliDBInstance($conf->db->type, $conf->db->host, $userroot, $passroot, $databasefortest, $conf->db->port);
564 564
 
565 565
             if ($db->error)
566 566
             {
@@ -568,20 +568,20 @@  discard block
 block discarded – undo
568 568
                 $error++;
569 569
             }
570 570
 
571
-            if (! $error)
571
+            if (!$error)
572 572
             {
573 573
                 if ($db->connected)
574 574
                 {
575 575
                     $resultbis = 1;
576 576
 
577 577
                     // Create user
578
-                    $result=$db->DDLCreateUser($dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_pass, $dolibarr_main_db_name);
578
+                    $result = $db->DDLCreateUser($dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_pass, $dolibarr_main_db_name);
579 579
                     // Create user bis
580 580
                     if ($databasefortest == 'mysql')
581 581
                     {
582
-                        if (! in_array($dolibarr_main_db_host, array('127.0.0.1', '::1', 'localhost', 'localhost.local')))
582
+                        if (!in_array($dolibarr_main_db_host, array('127.0.0.1', '::1', 'localhost', 'localhost.local')))
583 583
                         {
584
-                            $resultbis=$db->DDLCreateUser('%', $dolibarr_main_db_user, $dolibarr_main_db_pass, $dolibarr_main_db_name);
584
+                            $resultbis = $db->DDLCreateUser('%', $dolibarr_main_db_user, $dolibarr_main_db_pass, $dolibarr_main_db_name);
585 585
                         }
586 586
                     }
587 587
 
@@ -631,7 +631,7 @@  discard block
 block discarded – undo
631 631
 
632 632
                     // Affiche aide diagnostique
633 633
                     print '<tr><td colspan="2"><br>';
634
-                    print $langs->trans("YouAskDatabaseCreationSoDolibarrNeedToConnect",$dolibarr_main_db_user,$dolibarr_main_db_host,$userroot);
634
+                    print $langs->trans("YouAskDatabaseCreationSoDolibarrNeedToConnect", $dolibarr_main_db_user, $dolibarr_main_db_host, $userroot);
635 635
                     print '<br>';
636 636
                     print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
637 637
                     print $langs->trans("ErrorGoBackAndCorrectParameters").'<br><br>';
@@ -645,13 +645,13 @@  discard block
 block discarded – undo
645 645
 
646 646
         // If database creation is asked, we create it
647 647
         if (!$error && (isset($db_create_database) && ($db_create_database == "1" || $db_create_database == "on"))) {
648
-            dolibarr_install_syslog("step1: create database: " . $dolibarr_main_db_name . " " . $dolibarr_main_db_character_set . " " . $dolibarr_main_db_collation . " " . $dolibarr_main_db_user);
649
-        	$newdb=getDoliDBInstance($conf->db->type,$conf->db->host,$userroot,$passroot,'',$conf->db->port);
648
+            dolibarr_install_syslog("step1: create database: ".$dolibarr_main_db_name." ".$dolibarr_main_db_character_set." ".$dolibarr_main_db_collation." ".$dolibarr_main_db_user);
649
+        	$newdb = getDoliDBInstance($conf->db->type, $conf->db->host, $userroot, $passroot, '', $conf->db->port);
650 650
             //print 'eee'.$conf->db->type." ".$conf->db->host." ".$userroot." ".$passroot." ".$conf->db->port." ".$newdb->connected." ".$newdb->forcecharset;exit;
651 651
 
652 652
             if ($newdb->connected)
653 653
             {
654
-                $result=$newdb->DDLCreateDb($dolibarr_main_db_name, $dolibarr_main_db_character_set, $dolibarr_main_db_collation, $dolibarr_main_db_user);
654
+                $result = $newdb->DDLCreateDb($dolibarr_main_db_name, $dolibarr_main_db_character_set, $dolibarr_main_db_collation, $dolibarr_main_db_user);
655 655
 
656 656
                 if ($result)
657 657
                 {
@@ -662,9 +662,9 @@  discard block
 block discarded – undo
662 662
                     print '<td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
663 663
 
664 664
                     $newdb->select_db($dolibarr_main_db_name);
665
-                    $check1=$newdb->getDefaultCharacterSetDatabase();
666
-                    $check2=$newdb->getDefaultCollationDatabase();
667
-                    dolibarr_install_syslog('step1: new database is using charset=' . $check1 . ' collation=' . $check2);
665
+                    $check1 = $newdb->getDefaultCharacterSetDatabase();
666
+                    $check2 = $newdb->getDefaultCollationDatabase();
667
+                    dolibarr_install_syslog('step1: new database is using charset='.$check1.' collation='.$check2);
668 668
 
669 669
                     // If values differs, we save conf file again
670 670
                     //if ($check1 != $dolibarr_main_db_character_set) dolibarr_install_syslog('step1: value for character_set is not the one asked for database creation', LOG_WARNING);
@@ -674,13 +674,13 @@  discard block
 block discarded – undo
674 674
                 {
675 675
                     // Affiche aide diagnostique
676 676
                     print '<tr><td colspan="2"><br>';
677
-                    print $langs->trans("ErrorFailedToCreateDatabase",$dolibarr_main_db_name).'<br>';
677
+                    print $langs->trans("ErrorFailedToCreateDatabase", $dolibarr_main_db_name).'<br>';
678 678
                     print $newdb->lasterror().'<br>';
679 679
                     print $langs->trans("IfDatabaseExistsGoBackAndCheckCreate");
680 680
                     print '<br>';
681 681
                     print '</td></tr>';
682 682
 
683
-                    dolibarr_install_syslog('step1: failed to create database ' . $dolibarr_main_db_name . ' ' . $newdb->lasterrno() . ' ' . $newdb->lasterror(), LOG_ERR);
683
+                    dolibarr_install_syslog('step1: failed to create database '.$dolibarr_main_db_name.' '.$newdb->lasterrno().' '.$newdb->lasterror(), LOG_ERR);
684 684
                     $error++;
685 685
                 }
686 686
                 $newdb->close();
@@ -695,7 +695,7 @@  discard block
 block discarded – undo
695 695
 
696 696
                 // Affiche aide diagnostique
697 697
                 print '<tr><td colspan="2"><br>';
698
-                print $langs->trans("YouAskDatabaseCreationSoDolibarrNeedToConnect",$dolibarr_main_db_user,$dolibarr_main_db_host,$userroot);
698
+                print $langs->trans("YouAskDatabaseCreationSoDolibarrNeedToConnect", $dolibarr_main_db_user, $dolibarr_main_db_host, $userroot);
699 699
                 print '<br>';
700 700
                 print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
701 701
                 print $langs->trans("ErrorGoBackAndCorrectParameters").'<br><br>';
@@ -707,16 +707,16 @@  discard block
 block discarded – undo
707 707
 
708 708
 
709 709
         // We test access with dolibarr database user (not admin)
710
-        if (! $error)
710
+        if (!$error)
711 711
         {
712
-            dolibarr_install_syslog("step1: connection type=" . $conf->db->type . " on host=" . $conf->db->host . " port=" . $conf->db->port . " user=" . $conf->db->user . " name=" . $conf->db->name);
712
+            dolibarr_install_syslog("step1: connection type=".$conf->db->type." on host=".$conf->db->host." port=".$conf->db->port." user=".$conf->db->user." name=".$conf->db->name);
713 713
             //print "connexion de type=".$conf->db->type." sur host=".$conf->db->host." port=".$conf->db->port." user=".$conf->db->user." name=".$conf->db->name;
714 714
 
715
-            $db=getDoliDBInstance($conf->db->type,$conf->db->host,$conf->db->user,$conf->db->pass,$conf->db->name,$conf->db->port);
715
+            $db = getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, $conf->db->port);
716 716
 
717 717
             if ($db->connected)
718 718
             {
719
-                dolibarr_install_syslog("step1: connection to server by user " . $conf->db->user . " ok");
719
+                dolibarr_install_syslog("step1: connection to server by user ".$conf->db->user." ok");
720 720
                 print "<tr><td>";
721 721
                 print $langs->trans("ServerConnection")." (".$langs->trans("User")." ".$conf->db->user.") : ";
722 722
                 print $dolibarr_main_db_host;
@@ -727,7 +727,7 @@  discard block
 block discarded – undo
727 727
                 // si acces serveur ok et acces base ok, tout est ok, on ne va pas plus loin, on a meme pas utilise le compte root.
728 728
                 if ($db->database_selected)
729 729
                 {
730
-                    dolibarr_install_syslog("step1: connection to database " . $conf->db->name . " by user " . $conf->db->user . " ok");
730
+                    dolibarr_install_syslog("step1: connection to database ".$conf->db->name." by user ".$conf->db->user." ok");
731 731
                     print "<tr><td>";
732 732
                     print $langs->trans("DatabaseConnection")." (".$langs->trans("User")." ".$conf->db->user.") : ";
733 733
                     print $dolibarr_main_db_name;
@@ -739,7 +739,7 @@  discard block
 block discarded – undo
739 739
                 }
740 740
                 else
741 741
                 {
742
-                    dolibarr_install_syslog("step1: connection to database " . $conf->db->name . " by user " . $conf->db->user . " failed", LOG_ERR);
742
+                    dolibarr_install_syslog("step1: connection to database ".$conf->db->name." by user ".$conf->db->user." failed", LOG_ERR);
743 743
                     print "<tr><td>";
744 744
                     print $langs->trans("DatabaseConnection")." (".$langs->trans("User")." ".$conf->db->user.") : ";
745 745
                     print $dolibarr_main_db_name;
@@ -749,7 +749,7 @@  discard block
 block discarded – undo
749 749
 
750 750
                     // Affiche aide diagnostique
751 751
                     print '<tr><td colspan="2"><br>';
752
-                    print $langs->trans('CheckThatDatabasenameIsCorrect',$dolibarr_main_db_name).'<br>';
752
+                    print $langs->trans('CheckThatDatabasenameIsCorrect', $dolibarr_main_db_name).'<br>';
753 753
                     print $langs->trans('IfAlreadyExistsCheckOption').'<br>';
754 754
                     print $langs->trans("ErrorGoBackAndCorrectParameters").'<br><br>';
755 755
                     print '</td></tr>';
@@ -759,7 +759,7 @@  discard block
 block discarded – undo
759 759
             }
760 760
             else
761 761
             {
762
-                dolibarr_install_syslog("step1: connection to server by user " . $conf->db->user . " failed", LOG_ERR);
762
+                dolibarr_install_syslog("step1: connection to server by user ".$conf->db->user." failed", LOG_ERR);
763 763
                 print "<tr><td>";
764 764
                 print $langs->trans("ServerConnection")." (".$langs->trans("User")." ".$conf->db->user.") : ";
765 765
                 print $dolibarr_main_db_host;
@@ -769,7 +769,7 @@  discard block
 block discarded – undo
769 769
 
770 770
                 // Affiche aide diagnostique
771 771
                 print '<tr><td colspan="2"><br>';
772
-                print $langs->trans("ErrorConnection",$conf->db->host,$conf->db->name,$conf->db->user);
772
+                print $langs->trans("ErrorConnection", $conf->db->host, $conf->db->name, $conf->db->user);
773 773
                 print $langs->trans('IfLoginDoesNotExistsCheckCreateUser').'<br>';
774 774
                 print $langs->trans("ErrorGoBackAndCorrectParameters").'<br><br>';
775 775
                 print '</td></tr>';
@@ -802,7 +802,7 @@  discard block
 block discarded – undo
802 802
 
803 803
 dolibarr_install_syslog("--- step1: end");
804 804
 
805
-pFooter($error?1:0,$setuplang,'jsinfo',1);
805
+pFooter($error ? 1 : 0, $setuplang, 'jsinfo', 1);
806 806
 
807 807
 
808 808
 /**
@@ -812,10 +812,10 @@  discard block
 block discarded – undo
812 812
  *  @param	string		$main_dir		Full path name to main.inc.php file
813 813
  *  @return	void
814 814
  */
815
-function write_main_file($mainfile,$main_dir)
815
+function write_main_file($mainfile, $main_dir)
816 816
 {
817 817
     $fp = @fopen("$mainfile", "w");
818
-    if($fp)
818
+    if ($fp)
819 819
     {
820 820
         clearstatcache();
821 821
         fputs($fp, '<?php'."\n");
@@ -833,10 +833,10 @@  discard block
 block discarded – undo
833 833
  *  @param	string		$main_dir		Full path name to master.inc.php file
834 834
  *  @return	void
835 835
  */
836
-function write_master_file($masterfile,$main_dir)
836
+function write_master_file($masterfile, $main_dir)
837 837
 {
838 838
     $fp = @fopen("$masterfile", "w");
839
-    if($fp)
839
+    if ($fp)
840 840
     {
841 841
         clearstatcache();
842 842
         fputs($fp, '<?php'."\n");
@@ -855,13 +855,13 @@  discard block
 block discarded – undo
855 855
  */
856 856
 function write_conf_file($conffile)
857 857
 {
858
-    global $conf,$langs;
859
-    global $main_url,$main_dir,$main_data_dir,$main_force_https,$main_use_alt_dir,$main_alt_dir_name,$main_db_prefix;
860
-    global $dolibarr_main_url_root,$dolibarr_main_document_root,$dolibarr_main_data_root,$dolibarr_main_db_host;
861
-    global $dolibarr_main_db_port,$dolibarr_main_db_name,$dolibarr_main_db_user,$dolibarr_main_db_pass;
862
-    global $dolibarr_main_db_type,$dolibarr_main_db_character_set,$dolibarr_main_db_collation,$dolibarr_main_authentication;
863
-    global $db_host,$db_port,$db_name,$db_user,$db_pass,$db_type,$db_character_set,$db_collation;
864
-    global $conffile,$conffiletoshow,$conffiletoshowshort;
858
+    global $conf, $langs;
859
+    global $main_url, $main_dir, $main_data_dir, $main_force_https, $main_use_alt_dir, $main_alt_dir_name, $main_db_prefix;
860
+    global $dolibarr_main_url_root, $dolibarr_main_document_root, $dolibarr_main_data_root, $dolibarr_main_db_host;
861
+    global $dolibarr_main_db_port, $dolibarr_main_db_name, $dolibarr_main_db_user, $dolibarr_main_db_pass;
862
+    global $dolibarr_main_db_type, $dolibarr_main_db_character_set, $dolibarr_main_db_collation, $dolibarr_main_authentication;
863
+    global $db_host, $db_port, $db_name, $db_user, $db_pass, $db_type, $db_character_set, $db_collation;
864
+    global $conffile, $conffiletoshow, $conffiletoshowshort;
865 865
     global $force_dolibarr_lib_ADODB_PATH, $force_dolibarr_lib_NUSOAP_PATH;
866 866
     global $force_dolibarr_lib_TCPDF_PATH, $force_dolibarr_lib_FPDI_PATH;
867 867
     global $force_dolibarr_lib_PHPEXCEL_PATH, $force_dolibarr_lib_GEOIP_PATH;
@@ -869,154 +869,154 @@  discard block
 block discarded – undo
869 869
     global $force_dolibarr_js_CKEDITOR, $force_dolibarr_js_JQUERY, $force_dolibarr_js_JQUERY_UI, $force_dolibarr_js_JQUERY_FLOT;
870 870
     global $force_dolibarr_font_DOL_DEFAULT_TTF, $force_dolibarr_font_DOL_DEFAULT_TTF_BOLD;
871 871
 
872
-    $error=0;
872
+    $error = 0;
873 873
 
874
-    $key = md5(uniqid(mt_rand(),TRUE)); // Generate random hash
874
+    $key = md5(uniqid(mt_rand(), TRUE)); // Generate random hash
875 875
 
876 876
     $fp = fopen("$conffile", "w");
877
-    if($fp)
877
+    if ($fp)
878 878
     {
879 879
         clearstatcache();
880 880
 
881
-        fputs($fp,'<?php'."\n");
882
-        fputs($fp,'//'."\n");
883
-        fputs($fp,'// File generated by Dolibarr installer '.DOL_VERSION.' on '.dol_print_date(dol_now(),'')."\n");
884
-        fputs($fp,'//'."\n");
885
-        fputs($fp,'// Take a look at conf.php.example file for an example of '.$conffiletoshowshort.' file'."\n");
886
-        fputs($fp,'// and explanations for all possibles parameters.'."\n");
887
-        fputs($fp,'//'."\n");
881
+        fputs($fp, '<?php'."\n");
882
+        fputs($fp, '//'."\n");
883
+        fputs($fp, '// File generated by Dolibarr installer '.DOL_VERSION.' on '.dol_print_date(dol_now(), '')."\n");
884
+        fputs($fp, '//'."\n");
885
+        fputs($fp, '// Take a look at conf.php.example file for an example of '.$conffiletoshowshort.' file'."\n");
886
+        fputs($fp, '// and explanations for all possibles parameters.'."\n");
887
+        fputs($fp, '//'."\n");
888 888
 
889
-        fputs($fp, '$dolibarr_main_url_root=\''.str_replace("'","\'",($main_url)).'\';');
890
-        fputs($fp,"\n");
889
+        fputs($fp, '$dolibarr_main_url_root=\''.str_replace("'", "\'", ($main_url)).'\';');
890
+        fputs($fp, "\n");
891 891
 
892
-        fputs($fp, '$dolibarr_main_document_root=\''.str_replace("'","\'",($main_dir)).'\';');
893
-        fputs($fp,"\n");
892
+        fputs($fp, '$dolibarr_main_document_root=\''.str_replace("'", "\'", ($main_dir)).'\';');
893
+        fputs($fp, "\n");
894 894
 
895
-        fputs($fp, $main_use_alt_dir.'$dolibarr_main_url_root_alt=\''.str_replace("'","\'",("/".$main_alt_dir_name)).'\';');
896
-        fputs($fp,"\n");
895
+        fputs($fp, $main_use_alt_dir.'$dolibarr_main_url_root_alt=\''.str_replace("'", "\'", ("/".$main_alt_dir_name)).'\';');
896
+        fputs($fp, "\n");
897 897
 
898
-        fputs($fp, $main_use_alt_dir.'$dolibarr_main_document_root_alt=\''.str_replace("'","\'",($main_dir."/".$main_alt_dir_name)).'\';');
899
-		fputs($fp,"\n");
898
+        fputs($fp, $main_use_alt_dir.'$dolibarr_main_document_root_alt=\''.str_replace("'", "\'", ($main_dir."/".$main_alt_dir_name)).'\';');
899
+		fputs($fp, "\n");
900 900
 
901
-		fputs($fp, '$dolibarr_main_data_root=\''.str_replace("'","\'",($main_data_dir)).'\';');
902
-		fputs($fp,"\n");
901
+		fputs($fp, '$dolibarr_main_data_root=\''.str_replace("'", "\'", ($main_data_dir)).'\';');
902
+		fputs($fp, "\n");
903 903
 
904
-		fputs($fp, '$dolibarr_main_db_host=\''.str_replace("'","\'",($db_host)).'\';');
905
-		fputs($fp,"\n");
904
+		fputs($fp, '$dolibarr_main_db_host=\''.str_replace("'", "\'", ($db_host)).'\';');
905
+		fputs($fp, "\n");
906 906
 
907
-		fputs($fp, '$dolibarr_main_db_port=\''.str_replace("'","\'",($db_port)).'\';');
908
-		fputs($fp,"\n");
907
+		fputs($fp, '$dolibarr_main_db_port=\''.str_replace("'", "\'", ($db_port)).'\';');
908
+		fputs($fp, "\n");
909 909
 
910
-		fputs($fp, '$dolibarr_main_db_name=\''.str_replace("'","\'",($db_name)).'\';');
911
-		fputs($fp,"\n");
910
+		fputs($fp, '$dolibarr_main_db_name=\''.str_replace("'", "\'", ($db_name)).'\';');
911
+		fputs($fp, "\n");
912 912
 
913
-		fputs($fp, '$dolibarr_main_db_prefix=\''.str_replace("'","\'",($main_db_prefix)).'\';');
914
-		fputs($fp,"\n");
913
+		fputs($fp, '$dolibarr_main_db_prefix=\''.str_replace("'", "\'", ($main_db_prefix)).'\';');
914
+		fputs($fp, "\n");
915 915
 
916
-		fputs($fp, '$dolibarr_main_db_user=\''.str_replace("'","\'",($db_user)).'\';');
917
-		fputs($fp,"\n");
918
-		fputs($fp, '$dolibarr_main_db_pass=\''.str_replace("'","\'",($db_pass)).'\';');
919
-		fputs($fp,"\n");
916
+		fputs($fp, '$dolibarr_main_db_user=\''.str_replace("'", "\'", ($db_user)).'\';');
917
+		fputs($fp, "\n");
918
+		fputs($fp, '$dolibarr_main_db_pass=\''.str_replace("'", "\'", ($db_pass)).'\';');
919
+		fputs($fp, "\n");
920 920
 
921
-		fputs($fp, '$dolibarr_main_db_type=\''.str_replace("'","\'",($db_type)).'\';');
922
-		fputs($fp,"\n");
921
+		fputs($fp, '$dolibarr_main_db_type=\''.str_replace("'", "\'", ($db_type)).'\';');
922
+		fputs($fp, "\n");
923 923
 
924
-		fputs($fp, '$dolibarr_main_db_character_set=\''.str_replace("'","\'",($db_character_set)).'\';');
925
-		fputs($fp,"\n");
924
+		fputs($fp, '$dolibarr_main_db_character_set=\''.str_replace("'", "\'", ($db_character_set)).'\';');
925
+		fputs($fp, "\n");
926 926
 
927
-		fputs($fp, '$dolibarr_main_db_collation=\''.str_replace("'","\'",($db_collation)).'\';');
928
-		fputs($fp,"\n");
927
+		fputs($fp, '$dolibarr_main_db_collation=\''.str_replace("'", "\'", ($db_collation)).'\';');
928
+		fputs($fp, "\n");
929 929
 
930 930
 		/* Authentication */
931 931
 		fputs($fp, '// Authentication settings');
932
-        fputs($fp,"\n");
932
+        fputs($fp, "\n");
933 933
 
934 934
 		fputs($fp, '$dolibarr_main_authentication=\'dolibarr\';');
935
-		fputs($fp,"\n\n");
935
+		fputs($fp, "\n\n");
936 936
 
937 937
         fputs($fp, '//$dolibarr_main_demo=\'autologin,autopass\';');
938
-        fputs($fp,"\n");
938
+        fputs($fp, "\n");
939 939
 
940 940
 		fputs($fp, '// Security settings');
941
-        fputs($fp,"\n");
941
+        fputs($fp, "\n");
942 942
 
943 943
         fputs($fp, '$dolibarr_main_prod=\'0\';');
944
-        fputs($fp,"\n");
944
+        fputs($fp, "\n");
945 945
 
946 946
         fputs($fp, '$dolibarr_main_force_https=\''.$main_force_https.'\';');
947
-		fputs($fp,"\n");
947
+		fputs($fp, "\n");
948 948
 
949 949
         fputs($fp, '$dolibarr_main_restrict_os_commands=\'mysqldump, mysql, pg_dump, pgrestore\';');
950
-		fputs($fp,"\n");
950
+		fputs($fp, "\n");
951 951
 
952 952
         fputs($fp, '$dolibarr_nocsrfcheck=\'0\';');
953
-        fputs($fp,"\n");
953
+        fputs($fp, "\n");
954 954
 
955 955
 		fputs($fp, '$dolibarr_main_cookie_cryptkey=\''.$key.'\';');
956
-		fputs($fp,"\n");
956
+		fputs($fp, "\n");
957 957
 
958 958
 		fputs($fp, '$dolibarr_mailing_limit_sendbyweb=\'0\';');
959
-        fputs($fp,"\n");
959
+        fputs($fp, "\n");
960 960
 
961 961
         // Write params to overwrites default lib path
962
-        fputs($fp,"\n");
963
-        if (empty($force_dolibarr_lib_FPDF_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_FPDF_PATH=''; }
962
+        fputs($fp, "\n");
963
+        if (empty($force_dolibarr_lib_FPDF_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_FPDF_PATH = ''; }
964 964
         fputs($fp, '$dolibarr_lib_FPDF_PATH=\''.$force_dolibarr_lib_FPDF_PATH.'\';');
965
-        fputs($fp,"\n");
966
-        if (empty($force_dolibarr_lib_TCPDF_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_TCPDF_PATH=''; }
965
+        fputs($fp, "\n");
966
+        if (empty($force_dolibarr_lib_TCPDF_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_TCPDF_PATH = ''; }
967 967
         fputs($fp, '$dolibarr_lib_TCPDF_PATH=\''.$force_dolibarr_lib_TCPDF_PATH.'\';');
968
-        fputs($fp,"\n");
969
-        if (empty($force_dolibarr_lib_FPDI_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_FPDI_PATH=''; }
968
+        fputs($fp, "\n");
969
+        if (empty($force_dolibarr_lib_FPDI_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_FPDI_PATH = ''; }
970 970
         fputs($fp, '$dolibarr_lib_FPDI_PATH=\''.$force_dolibarr_lib_FPDI_PATH.'\';');
971
-        fputs($fp,"\n");
972
-        if (empty($force_dolibarr_lib_TCPDI_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_TCPDI_PATH=''; }
971
+        fputs($fp, "\n");
972
+        if (empty($force_dolibarr_lib_TCPDI_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_TCPDI_PATH = ''; }
973 973
         fputs($fp, '$dolibarr_lib_TCPDI_PATH=\''.$force_dolibarr_lib_TCPDI_PATH.'\';');
974
-        fputs($fp,"\n");
975
-        if (empty($force_dolibarr_lib_ADODB_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_ADODB_PATH=''; }
974
+        fputs($fp, "\n");
975
+        if (empty($force_dolibarr_lib_ADODB_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_ADODB_PATH = ''; }
976 976
         fputs($fp, '$dolibarr_lib_ADODB_PATH=\''.$force_dolibarr_lib_ADODB_PATH.'\';');
977
-        fputs($fp,"\n");
978
-        if (empty($force_dolibarr_lib_GEOIP_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_GEOIP_PATH=''; }
977
+        fputs($fp, "\n");
978
+        if (empty($force_dolibarr_lib_GEOIP_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_GEOIP_PATH = ''; }
979 979
         fputs($fp, '$dolibarr_lib_GEOIP_PATH=\''.$force_dolibarr_lib_GEOIP_PATH.'\';');
980
-        fputs($fp,"\n");
981
-        if (empty($force_dolibarr_lib_NUSOAP_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_NUSOAP_PATH=''; }
980
+        fputs($fp, "\n");
981
+        if (empty($force_dolibarr_lib_NUSOAP_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_NUSOAP_PATH = ''; }
982 982
         fputs($fp, '$dolibarr_lib_NUSOAP_PATH=\''.$force_dolibarr_lib_NUSOAP_PATH.'\';');
983
-        fputs($fp,"\n");
984
-        if (empty($force_dolibarr_lib_PHPEXCEL_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_PHPEXCEL_PATH=''; }
983
+        fputs($fp, "\n");
984
+        if (empty($force_dolibarr_lib_PHPEXCEL_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_PHPEXCEL_PATH = ''; }
985 985
         fputs($fp, '$dolibarr_lib_PHPEXCEL_PATH=\''.$force_dolibarr_lib_PHPEXCEL_PATH.'\';');
986
-        fputs($fp,"\n");
987
-        if (empty($force_dolibarr_lib_ODTPHP_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_ODTPHP_PATH=''; }
986
+        fputs($fp, "\n");
987
+        if (empty($force_dolibarr_lib_ODTPHP_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_ODTPHP_PATH = ''; }
988 988
         fputs($fp, '$dolibarr_lib_ODTPHP_PATH=\''.$force_dolibarr_lib_ODTPHP_PATH.'\';');
989
-        fputs($fp,"\n");
990
-        if (empty($force_dolibarr_lib_ODTPHP_PATHTOPCLZIP)) { fputs($fp, '//'); $force_dolibarr_lib_ODTPHP_PATHTOPCLZIP=''; }
989
+        fputs($fp, "\n");
990
+        if (empty($force_dolibarr_lib_ODTPHP_PATHTOPCLZIP)) { fputs($fp, '//'); $force_dolibarr_lib_ODTPHP_PATHTOPCLZIP = ''; }
991 991
         fputs($fp, '$dolibarr_lib_ODTPHP_PATHTOPCLZIP=\''.$force_dolibarr_lib_ODTPHP_PATHTOPCLZIP.'\';');
992
-        fputs($fp,"\n");
993
-        if (empty($force_dolibarr_js_CKEDITOR)) { fputs($fp, '//'); $force_dolibarr_js_CKEDITOR=''; }
992
+        fputs($fp, "\n");
993
+        if (empty($force_dolibarr_js_CKEDITOR)) { fputs($fp, '//'); $force_dolibarr_js_CKEDITOR = ''; }
994 994
         fputs($fp, '$dolibarr_js_CKEDITOR=\''.$force_dolibarr_js_CKEDITOR.'\';');
995
-        fputs($fp,"\n");
996
-        if (empty($force_dolibarr_js_JQUERY)) { fputs($fp, '//'); $force_dolibarr_js_JQUERY=''; }
995
+        fputs($fp, "\n");
996
+        if (empty($force_dolibarr_js_JQUERY)) { fputs($fp, '//'); $force_dolibarr_js_JQUERY = ''; }
997 997
         fputs($fp, '$dolibarr_js_JQUERY=\''.$force_dolibarr_js_JQUERY.'\';');
998
-        fputs($fp,"\n");
999
-        if (empty($force_dolibarr_js_JQUERY_UI)) { fputs($fp, '//'); $force_dolibarr_js_JQUERY_UI=''; }
998
+        fputs($fp, "\n");
999
+        if (empty($force_dolibarr_js_JQUERY_UI)) { fputs($fp, '//'); $force_dolibarr_js_JQUERY_UI = ''; }
1000 1000
         fputs($fp, '$dolibarr_js_JQUERY_UI=\''.$force_dolibarr_js_JQUERY_UI.'\';');
1001
-        fputs($fp,"\n");
1002
-        if (empty($force_dolibarr_js_JQUERY_FLOT)) { fputs($fp, '//'); $force_dolibarr_js_JQUERY_FLOT=''; }
1001
+        fputs($fp, "\n");
1002
+        if (empty($force_dolibarr_js_JQUERY_FLOT)) { fputs($fp, '//'); $force_dolibarr_js_JQUERY_FLOT = ''; }
1003 1003
         fputs($fp, '$dolibarr_js_JQUERY_FLOT=\''.$force_dolibarr_js_JQUERY_FLOT.'\';');
1004
-        fputs($fp,"\n");
1004
+        fputs($fp, "\n");
1005 1005
 
1006 1006
         // Write params to overwrites default font path
1007
-        fputs($fp,"\n");
1008
-        if (empty($force_dolibarr_font_DOL_DEFAULT_TTF)) { fputs($fp, '//'); $force_dolibarr_font_DOL_DEFAULT_TTF=''; }
1007
+        fputs($fp, "\n");
1008
+        if (empty($force_dolibarr_font_DOL_DEFAULT_TTF)) { fputs($fp, '//'); $force_dolibarr_font_DOL_DEFAULT_TTF = ''; }
1009 1009
    		fputs($fp, '$dolibarr_font_DOL_DEFAULT_TTF=\''.$force_dolibarr_font_DOL_DEFAULT_TTF.'\';');
1010
-        fputs($fp,"\n");
1011
-        if (empty($force_dolibarr_font_DOL_DEFAULT_TTF_BOLD)) { fputs($fp, '//'); $force_dolibarr_font_DOL_DEFAULT_TTF_BOLD=''; }
1010
+        fputs($fp, "\n");
1011
+        if (empty($force_dolibarr_font_DOL_DEFAULT_TTF_BOLD)) { fputs($fp, '//'); $force_dolibarr_font_DOL_DEFAULT_TTF_BOLD = ''; }
1012 1012
         fputs($fp, '$dolibarr_font_DOL_DEFAULT_TTF_BOLD=\''.$force_dolibarr_font_DOL_DEFAULT_TTF_BOLD.'\';');
1013
-        fputs($fp,"\n");
1013
+        fputs($fp, "\n");
1014 1014
 
1015 1015
 		fclose($fp);
1016 1016
 
1017 1017
 		if (file_exists("$conffile"))
1018 1018
 		{
1019
-			include $conffile;	// On force rechargement. Ne pas mettre include_once !
1019
+			include $conffile; // On force rechargement. Ne pas mettre include_once !
1020 1020
 			conf($dolibarr_main_document_root);
1021 1021
 
1022 1022
 			print "<tr><td>";
Please login to merge, or discard this patch.
htdocs/societe/class/societe.class.php 2 patches
Spacing   +738 added lines, -738 removed lines patch added patch discarded remove patch
@@ -40,12 +40,12 @@  discard block
 block discarded – undo
40 40
  */
41 41
 class Societe extends CommonObject
42 42
 {
43
-	public $element='societe';
43
+	public $element = 'societe';
44 44
 	public $table_element = 'societe';
45
-	public $fk_element='fk_soc';
46
-	public $fieldsforcombobox='nom,name_alias';
47
-	protected $childtables=array("supplier_proposal"=>'SupplierProposal',"propal"=>'Proposal',"commande"=>'Order',"facture"=>'Invoice',"facture_rec"=>'RecurringInvoiceTemplate',"contrat"=>'Contract',"fichinter"=>'Fichinter',"facture_fourn"=>'SupplierInvoice',"commande_fournisseur"=>'SupplierOrder',"projet"=>'Project',"expedition"=>'Shipment',"prelevement_lignes"=>'DirectDebitRecord');    // To test if we can delete object
48
-	protected $childtablesoncascade=array("societe_prices", "societe_log", "societe_address", "product_fournisseur_price", "product_customer_price_log", "product_customer_price", "socpeople", "adherent", "societe_rib", "societe_remise", "societe_remise_except", "societe_commerciaux", "categorie", "notify", "notify_def", "actioncomm");
45
+	public $fk_element = 'fk_soc';
46
+	public $fieldsforcombobox = 'nom,name_alias';
47
+	protected $childtables = array("supplier_proposal"=>'SupplierProposal', "propal"=>'Proposal', "commande"=>'Order', "facture"=>'Invoice', "facture_rec"=>'RecurringInvoiceTemplate', "contrat"=>'Contract', "fichinter"=>'Fichinter', "facture_fourn"=>'SupplierInvoice', "commande_fournisseur"=>'SupplierOrder', "projet"=>'Project', "expedition"=>'Shipment', "prelevement_lignes"=>'DirectDebitRecord'); // To test if we can delete object
48
+	protected $childtablesoncascade = array("societe_prices", "societe_log", "societe_address", "product_fournisseur_price", "product_customer_price_log", "product_customer_price", "socpeople", "adherent", "societe_rib", "societe_remise", "societe_remise_except", "societe_commerciaux", "categorie", "notify", "notify_def", "actioncomm");
49 49
 	public $picto = 'company';
50 50
 
51 51
 	/**
@@ -64,20 +64,20 @@  discard block
 block discarded – undo
64 64
 	/**
65 65
 	 * @var array  Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
66 66
 	 */
67
-	public $fields=array(
68
-		'rowid'         =>array('type'=>'integer',      'label'=>'TechnicalID',      'enabled'=>1, 'visible'=>-2, 'notnull'=>1,  'index'=>1, 'position'=>1, 'comment'=>'Id'),
69
-		'nom'           =>array('type'=>'varchar(128)', 'label'=>'Name',            'enabled'=>1, 'visible'=>1,  'notnull'=>1,  'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object'),
70
-		'name_alias'    =>array('type'=>'varchar(128)', 'label'=>'Name',            'enabled'=>1, 'visible'=>1,  'notnull'=>1,  'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object'),
71
-		'entity'        =>array('type'=>'integer',      'label'=>'Entity',           'enabled'=>1, 'visible'=>0,  'default'=>1, 'notnull'=>1,  'index'=>1, 'position'=>20),
72
-		'note_public'   =>array('type'=>'text',			'label'=>'NotePublic',		 'enabled'=>1, 'visible'=>0,  'position'=>60),
73
-		'note_private'  =>array('type'=>'text',			'label'=>'NotePrivate',		 'enabled'=>1, 'visible'=>0,  'position'=>61),
74
-		'date_creation' =>array('type'=>'datetime',     'label'=>'DateCreation',     'enabled'=>1, 'visible'=>-2, 'notnull'=>1,  'position'=>500),
75
-		'tms'           =>array('type'=>'timestamp',    'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1,  'position'=>501),
67
+	public $fields = array(
68
+		'rowid'         =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'index'=>1, 'position'=>1, 'comment'=>'Id'),
69
+		'nom'           =>array('type'=>'varchar(128)', 'label'=>'Name', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object'),
70
+		'name_alias'    =>array('type'=>'varchar(128)', 'label'=>'Name', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object'),
71
+		'entity'        =>array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'default'=>1, 'notnull'=>1, 'index'=>1, 'position'=>20),
72
+		'note_public'   =>array('type'=>'text', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>60),
73
+		'note_private'  =>array('type'=>'text', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>0, 'position'=>61),
74
+		'date_creation' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>500),
75
+		'tms'           =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>501),
76 76
 		//'date_valid'    =>array('type'=>'datetime',     'label'=>'DateCreation',     'enabled'=>1, 'visible'=>-2, 'position'=>502),
77
-		'fk_user_creat' =>array('type'=>'integer',      'label'=>'UserAuthor',       'enabled'=>1, 'visible'=>-2, 'notnull'=>1,  'position'=>510),
78
-		'fk_user_modif' =>array('type'=>'integer',      'label'=>'UserModif',        'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'position'=>511),
77
+		'fk_user_creat' =>array('type'=>'integer', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>510),
78
+		'fk_user_modif' =>array('type'=>'integer', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'position'=>511),
79 79
 		//'fk_user_valid' =>array('type'=>'integer',      'label'=>'UserValidation',        'enabled'=>1, 'visible'=>-1, 'position'=>512),
80
-		'import_key'    =>array('type'=>'varchar(14)',  'label'=>'ImportId',         'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'index'=>1,  'position'=>1000),
80
+		'import_key'    =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'index'=>1, 'position'=>1000),
81 81
 	);
82 82
 
83 83
 
@@ -396,7 +396,7 @@  discard block
 block discarded – undo
396 396
 	// Incoterms
397 397
 	var $fk_incoterms;
398 398
 	var $location_incoterms;
399
-	var $libelle_incoterms;  //Used into tooltip
399
+	var $libelle_incoterms; //Used into tooltip
400 400
 
401 401
 	// Multicurrency
402 402
 	var $fk_multicurrency;
@@ -424,9 +424,9 @@  discard block
 block discarded – undo
424 424
 		$this->client = 0;
425 425
 		$this->prospect = 0;
426 426
 		$this->fournisseur = 0;
427
-		$this->typent_id  = 0;
428
-		$this->effectif_id  = 0;
429
-		$this->forme_juridique_code  = 0;
427
+		$this->typent_id = 0;
428
+		$this->effectif_id = 0;
429
+		$this->forme_juridique_code = 0;
430 430
 		$this->tva_assuj = 1;
431 431
 		$this->status = 1;
432 432
 	}
@@ -441,17 +441,17 @@  discard block
 block discarded – undo
441 441
 	 */
442 442
 	function create(User $user)
443 443
 	{
444
-		global $langs,$conf,$mysoc;
444
+		global $langs, $conf, $mysoc;
445 445
 
446
-		$error=0;
446
+		$error = 0;
447 447
 
448 448
 		// Clean parameters
449
-		if (empty($this->status)) $this->status=0;
450
-		$this->name=$this->name?trim($this->name):trim($this->nom);
451
-		if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->name=ucwords($this->name);
452
-		$this->nom=$this->name; // For backward compatibility
453
-		if (empty($this->client))      $this->client=0;
454
-		if (empty($this->fournisseur)) $this->fournisseur=0;
449
+		if (empty($this->status)) $this->status = 0;
450
+		$this->name = $this->name ?trim($this->name) : trim($this->nom);
451
+		if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->name = ucwords($this->name);
452
+		$this->nom = $this->name; // For backward compatibility
453
+		if (empty($this->client))      $this->client = 0;
454
+		if (empty($this->fournisseur)) $this->fournisseur = 0;
455 455
 		$this->import_key = trim($this->import_key);
456 456
 
457 457
 		if (!empty($this->multicurrency_code)) $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code);
@@ -463,13 +463,13 @@  discard block
 block discarded – undo
463 463
 
464 464
 		dol_syslog(get_class($this)."::create ".$this->name);
465 465
 
466
-		$now=dol_now();
466
+		$now = dol_now();
467 467
 
468 468
 		$this->db->begin();
469 469
 
470 470
 		// For automatic creation during create action (not used by Dolibarr GUI, can be used by scripts)
471
-		if ($this->code_client == -1 || $this->code_client === 'auto')           $this->get_codeclient($this,0);
472
-		if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') $this->get_codefournisseur($this,1);
471
+		if ($this->code_client == -1 || $this->code_client === 'auto')           $this->get_codeclient($this, 0);
472
+		if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') $this->get_codefournisseur($this, 1);
473 473
 
474 474
 		// Check more parameters (including mandatory setup
475 475
 		// If error, this->errors[] is filled
@@ -477,29 +477,29 @@  discard block
 block discarded – undo
477 477
 
478 478
 		if ($result >= 0)
479 479
 		{
480
-			$entity = ((isset($this->entity) && is_numeric($this->entity))?$this->entity:$conf->entity);
480
+			$entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity);
481 481
 
482 482
 			$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe (nom, name_alias, entity, datec, fk_user_creat, canvas, status, ref_int, ref_ext, fk_stcomm, fk_incoterms, location_incoterms ,import_key, fk_multicurrency, multicurrency_code)";
483
-			$sql.= " VALUES ('".$this->db->escape($this->name)."', '".$this->db->escape($this->name_alias)."', ".$entity.", '".$this->db->idate($now)."'";
484
-			$sql.= ", ".(! empty($user->id) ? "'".$user->id."'":"null");
485
-			$sql.= ", ".(! empty($this->canvas) ? "'".$this->db->escape($this->canvas)."'":"null");
486
-			$sql.= ", ".$this->status;
487
-			$sql.= ", ".(! empty($this->ref_int) ? "'".$this->db->escape($this->ref_int)."'":"null");
488
-			$sql.= ", ".(! empty($this->ref_ext) ? "'".$this->db->escape($this->ref_ext)."'":"null");
489
-			$sql.= ", 0";
490
-			$sql.= ", ".(int) $this->fk_incoterms;
491
-			$sql.= ", '".$this->db->escape($this->location_incoterms)."'";
492
-			$sql.= ", ".(! empty($this->import_key) ? "'".$this->db->escape($this->import_key)."'":"null");
493
-			$sql.= ", ".(int) $this->fk_multicurrency;
494
-			$sql.= ", '".$this->db->escape($this->multicurrency_code)."')";
483
+			$sql .= " VALUES ('".$this->db->escape($this->name)."', '".$this->db->escape($this->name_alias)."', ".$entity.", '".$this->db->idate($now)."'";
484
+			$sql .= ", ".(!empty($user->id) ? "'".$user->id."'" : "null");
485
+			$sql .= ", ".(!empty($this->canvas) ? "'".$this->db->escape($this->canvas)."'" : "null");
486
+			$sql .= ", ".$this->status;
487
+			$sql .= ", ".(!empty($this->ref_int) ? "'".$this->db->escape($this->ref_int)."'" : "null");
488
+			$sql .= ", ".(!empty($this->ref_ext) ? "'".$this->db->escape($this->ref_ext)."'" : "null");
489
+			$sql .= ", 0";
490
+			$sql .= ", ".(int) $this->fk_incoterms;
491
+			$sql .= ", '".$this->db->escape($this->location_incoterms)."'";
492
+			$sql .= ", ".(!empty($this->import_key) ? "'".$this->db->escape($this->import_key)."'" : "null");
493
+			$sql .= ", ".(int) $this->fk_multicurrency;
494
+			$sql .= ", '".$this->db->escape($this->multicurrency_code)."')";
495 495
 
496 496
 			dol_syslog(get_class($this)."::create", LOG_DEBUG);
497
-			$result=$this->db->query($sql);
497
+			$result = $this->db->query($sql);
498 498
 			if ($result)
499 499
 			{
500 500
 				$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."societe");
501 501
 
502
-				$ret = $this->update($this->id,$user,0,1,1,'add');
502
+				$ret = $this->update($this->id, $user, 0, 1, 1, 'add');
503 503
 
504 504
 				// Ajout du commercial affecte
505 505
 				if ($this->commercial_id != '' && $this->commercial_id != -1)
@@ -515,13 +515,13 @@  discard block
 block discarded – undo
515 515
 				if ($ret >= 0)
516 516
 				{
517 517
 					// Call trigger
518
-					$result=$this->call_trigger('COMPANY_CREATE',$user);
518
+					$result = $this->call_trigger('COMPANY_CREATE', $user);
519 519
 					if ($result < 0) $error++;
520 520
 					// End call triggers
521 521
 				}
522 522
 				else $error++;
523 523
 
524
-				if (! $error)
524
+				if (!$error)
525 525
 				{
526 526
 					dol_syslog(get_class($this)."::Create success id=".$this->id);
527 527
 					$this->db->commit();
@@ -529,7 +529,7 @@  discard block
 block discarded – undo
529 529
 				}
530 530
 				else
531 531
 				{
532
-					dol_syslog(get_class($this)."::Create echec update ".$this->error." ".join(',',$this->errors), LOG_ERR);
532
+					dol_syslog(get_class($this)."::Create echec update ".$this->error." ".join(',', $this->errors), LOG_ERR);
533 533
 					$this->db->rollback();
534 534
 					return -4;
535 535
 				}
@@ -538,13 +538,13 @@  discard block
 block discarded – undo
538 538
 			{
539 539
 				if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
540 540
 				{
541
-					$this->error=$langs->trans("ErrorCompanyNameAlreadyExists",$this->name);    // duplicate on a field (code or profid or ...)
542
-					$result=-1;
541
+					$this->error = $langs->trans("ErrorCompanyNameAlreadyExists", $this->name); // duplicate on a field (code or profid or ...)
542
+					$result = -1;
543 543
 				}
544 544
 				else
545 545
 				{
546
-					$this->error=$this->db->lasterror();
547
-					$result=-2;
546
+					$this->error = $this->db->lasterror();
547
+					$result = -2;
548 548
 				}
549 549
 				$this->db->rollback();
550 550
 				return $result;
@@ -554,7 +554,7 @@  discard block
 block discarded – undo
554 554
 		else
555 555
 		{
556 556
 			$this->db->rollback();
557
-			dol_syslog(get_class($this)."::Create fails verify ".join(',',$this->errors), LOG_WARNING);
557
+			dol_syslog(get_class($this)."::Create fails verify ".join(',', $this->errors), LOG_WARNING);
558 558
 			return -3;
559 559
 		}
560 560
 	}
@@ -569,12 +569,12 @@  discard block
 block discarded – undo
569 569
 	function create_individual(User $user)
570 570
 	{
571 571
 		require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
572
-		$contact=new Contact($this->db);
572
+		$contact = new Contact($this->db);
573 573
 
574 574
 		$contact->name              = $this->name_bis;
575 575
 		$contact->firstname         = $this->firstname;
576 576
 		$contact->civility_id       = $this->civility_id;
577
-		$contact->socid             = $this->id;	// fk_soc
577
+		$contact->socid             = $this->id; // fk_soc
578 578
 		$contact->statut            = 1;
579 579
 		$contact->priv              = 0;
580 580
 		$contact->country_id        = $this->country_id;
@@ -590,7 +590,7 @@  discard block
 block discarded – undo
590 590
 		{
591 591
 			$this->error = $contact->error;
592 592
 			$this->errors = $contact->errors;
593
-			dol_syslog(get_class($this)."::create_individual ERROR:" . $this->error, LOG_ERR);
593
+			dol_syslog(get_class($this)."::create_individual ERROR:".$this->error, LOG_ERR);
594 594
 		}
595 595
 
596 596
 		return $result;
@@ -607,13 +607,13 @@  discard block
 block discarded – undo
607 607
 		global $conf, $langs, $mysoc;
608 608
 
609 609
 		$error = 0;
610
-		$this->errors=array();
610
+		$this->errors = array();
611 611
 
612 612
 		$result = 0;
613
-		$this->name	= trim($this->name);
614
-		$this->nom=$this->name; // For backward compatibility
613
+		$this->name = trim($this->name);
614
+		$this->nom = $this->name; // For backward compatibility
615 615
 
616
-		if (! $this->name)
616
+		if (!$this->name)
617 617
 		{
618 618
 			$this->errors[] = 'ErrorBadThirdPartyName';
619 619
 			$result = -2;
@@ -670,12 +670,12 @@  discard block
 block discarded – undo
670 670
 		}
671 671
 
672 672
 		// Check for duplicate or mandatory fields defined into setup
673
-		$array_to_check=array('IDPROF1','IDPROF2','IDPROF3','IDPROF4','IDPROF5','IDPROF6','EMAIL');
674
-		foreach($array_to_check as $key)
673
+		$array_to_check = array('IDPROF1', 'IDPROF2', 'IDPROF3', 'IDPROF4', 'IDPROF5', 'IDPROF6', 'EMAIL');
674
+		foreach ($array_to_check as $key)
675 675
 		{
676
-			$keymin=strtolower($key);
677
-			$i=(int) preg_replace('/[^0-9]/','',$key);
678
-			$vallabel=$this->$keymin;
676
+			$keymin = strtolower($key);
677
+			$i = (int) preg_replace('/[^0-9]/', '', $key);
678
+			$vallabel = $this->$keymin;
679 679
 
680 680
 			if ($i > 0)
681 681
 			{
@@ -694,8 +694,8 @@  discard block
 block discarded – undo
694 694
 					// Check for mandatory prof id (but only if country is other than ours)
695 695
 					if ($mysoc->country_id > 0 && $this->country_id == $mysoc->country_id)
696 696
 					{
697
-						$idprof_mandatory ='SOCIETE_'.$key.'_MANDATORY';
698
-						if (! $vallabel && ! empty($conf->global->$idprof_mandatory))
697
+						$idprof_mandatory = 'SOCIETE_'.$key.'_MANDATORY';
698
+						if (!$vallabel && !empty($conf->global->$idprof_mandatory))
699 699
 						{
700 700
 							$langs->load("errors");
701 701
 							$error++;
@@ -711,7 +711,7 @@  discard block
 block discarded – undo
711 711
 				if ($key == 'EMAIL')
712 712
 				{
713 713
 					// Check for unicity
714
-					if ($vallabel && ! empty($conf->global->SOCIETE_EMAIL_UNIQUE))
714
+					if ($vallabel && !empty($conf->global->SOCIETE_EMAIL_UNIQUE))
715 715
 					{
716 716
 						if ($this->id_prof_exists($keymin, $vallabel, ($this->id > 0 ? $this->id : 0)))
717 717
 						{
@@ -721,7 +721,7 @@  discard block
 block discarded – undo
721 721
 					}
722 722
 
723 723
 					// Check for mandatory
724
-					if (! empty($conf->global->SOCIETE_EMAIL_MANDATORY) && ! isValidEMail($this->email))
724
+					if (!empty($conf->global->SOCIETE_EMAIL_MANDATORY) && !isValidEMail($this->email))
725 725
 					{
726 726
 						$langs->load("errors");
727 727
 						$error++;
@@ -748,54 +748,54 @@  discard block
 block discarded – undo
748 748
 	 *		@param	int		$nosyncmember				Do not synchronize info of linked member
749 749
 	 *      @return int  			           			<0 if KO, >=0 if OK
750 750
 	 */
751
-	function update($id, $user='', $call_trigger=1, $allowmodcodeclient=0, $allowmodcodefournisseur=0, $action='update', $nosyncmember=1)
751
+	function update($id, $user = '', $call_trigger = 1, $allowmodcodeclient = 0, $allowmodcodefournisseur = 0, $action = 'update', $nosyncmember = 1)
752 752
 	{
753
-		global $langs,$conf,$hookmanager;
753
+		global $langs, $conf, $hookmanager;
754 754
 		require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
755 755
 
756 756
 		if (empty($id)) $id = $this->id;
757 757
 
758
-		$error=0;
758
+		$error = 0;
759 759
 
760 760
 		dol_syslog(get_class($this)."::Update id=".$id." call_trigger=".$call_trigger." allowmodcodeclient=".$allowmodcodeclient." allowmodcodefournisseur=".$allowmodcodefournisseur);
761 761
 
762
-		$now=dol_now();
762
+		$now = dol_now();
763 763
 
764 764
 		// Clean parameters
765
-		$this->id			= $id;
766
-		$this->name			= $this->name?trim($this->name):trim($this->nom);
767
-		$this->nom			= $this->name;	// For backward compatibility
765
+		$this->id = $id;
766
+		$this->name = $this->name ?trim($this->name) : trim($this->nom);
767
+		$this->nom = $this->name; // For backward compatibility
768 768
 		$this->name_alias = trim($this->name_alias);
769 769
 		$this->ref_ext		= trim($this->ref_ext);
770
-		$this->address		= $this->address?trim($this->address):trim($this->address);
771
-		$this->zip			= $this->zip?trim($this->zip):trim($this->zip);
772
-		$this->town			= $this->town?trim($this->town):trim($this->town);
773
-		$this->state_id		= trim($this->state_id);
774
-		$this->country_id	= ($this->country_id > 0)?$this->country_id:0;
770
+		$this->address		= $this->address ?trim($this->address) : trim($this->address);
771
+		$this->zip = $this->zip ?trim($this->zip) : trim($this->zip);
772
+		$this->town			= $this->town ?trim($this->town) : trim($this->town);
773
+		$this->state_id = trim($this->state_id);
774
+		$this->country_id = ($this->country_id > 0) ? $this->country_id : 0;
775 775
 		$this->phone		= trim($this->phone);
776
-		$this->phone		= preg_replace("/\s/","",$this->phone);
777
-		$this->phone		= preg_replace("/\./","",$this->phone);
776
+		$this->phone		= preg_replace("/\s/", "", $this->phone);
777
+		$this->phone		= preg_replace("/\./", "", $this->phone);
778 778
 		$this->fax			= trim($this->fax);
779
-		$this->fax			= preg_replace("/\s/","",$this->fax);
780
-		$this->fax			= preg_replace("/\./","",$this->fax);
779
+		$this->fax			= preg_replace("/\s/", "", $this->fax);
780
+		$this->fax			= preg_replace("/\./", "", $this->fax);
781 781
 		$this->email		= trim($this->email);
782 782
 		$this->skype		= trim($this->skype);
783
-		$this->url		= $this->url?clean_url($this->url,0):'';
783
+		$this->url = $this->url ?clean_url($this->url, 0) : '';
784 784
 		$this->note_private 	= trim($this->note_private);
785 785
 		$this->note_public  	= trim($this->note_public);
786 786
 		$this->idprof1		= trim($this->idprof1);
787 787
 		$this->idprof2		= trim($this->idprof2);
788 788
 		$this->idprof3		= trim($this->idprof3);
789 789
 		$this->idprof4		= trim($this->idprof4);
790
-		$this->idprof5		= (! empty($this->idprof5)?trim($this->idprof5):'');
791
-		$this->idprof6		= (! empty($this->idprof6)?trim($this->idprof6):'');
792
-		$this->prefix_comm	= trim($this->prefix_comm);
790
+		$this->idprof5		= (!empty($this->idprof5) ?trim($this->idprof5) : '');
791
+		$this->idprof6		= (!empty($this->idprof6) ?trim($this->idprof6) : '');
792
+		$this->prefix_comm = trim($this->prefix_comm);
793 793
 		$this->outstanding_limit = price2num($this->outstanding_limit);
794 794
 		$this->order_min_amount = price2num($this->order_min_amount);
795 795
 		$this->supplier_order_min_amount = price2num($this->supplier_order_min_amount);
796 796
 
797 797
 		$this->tva_assuj	= trim($this->tva_assuj);
798
-		$this->tva_intra	= dol_sanitizeFileName($this->tva_intra,'');
798
+		$this->tva_intra	= dol_sanitizeFileName($this->tva_intra, '');
799 799
 		if (empty($this->status)) $this->status = 0;
800 800
 
801 801
 		if (!empty($this->multicurrency_code)) $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code);
@@ -806,64 +806,64 @@  discard block
 block discarded – undo
806 806
 		}
807 807
 
808 808
 		// Local taxes
809
-		$this->localtax1_assuj=trim($this->localtax1_assuj);
810
-		$this->localtax2_assuj=trim($this->localtax2_assuj);
809
+		$this->localtax1_assuj = trim($this->localtax1_assuj);
810
+		$this->localtax2_assuj = trim($this->localtax2_assuj);
811 811
 
812
-		$this->localtax1_value=trim($this->localtax1_value);
813
-		$this->localtax2_value=trim($this->localtax2_value);
812
+		$this->localtax1_value = trim($this->localtax1_value);
813
+		$this->localtax2_value = trim($this->localtax2_value);
814 814
 
815
-		if ($this->capital != '') $this->capital=price2num(trim($this->capital));
816
-		if (! is_numeric($this->capital)) $this->capital = '';     // '' = undef
815
+		if ($this->capital != '') $this->capital = price2num(trim($this->capital));
816
+		if (!is_numeric($this->capital)) $this->capital = ''; // '' = undef
817 817
 
818
-		$this->effectif_id=trim($this->effectif_id);
819
-		$this->forme_juridique_code=trim($this->forme_juridique_code);
818
+		$this->effectif_id = trim($this->effectif_id);
819
+		$this->forme_juridique_code = trim($this->forme_juridique_code);
820 820
 
821 821
 		//Gencod
822
-		$this->barcode=trim($this->barcode);
822
+		$this->barcode = trim($this->barcode);
823 823
 
824 824
 		// For automatic creation
825
-		if ($this->code_client == -1 || $this->code_client === 'auto')           $this->get_codeclient($this,0);
826
-		if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') $this->get_codefournisseur($this,1);
825
+		if ($this->code_client == -1 || $this->code_client === 'auto')           $this->get_codeclient($this, 0);
826
+		if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') $this->get_codefournisseur($this, 1);
827 827
 
828
-		$this->code_compta=trim($this->code_compta);
829
-		$this->code_compta_fournisseur=trim($this->code_compta_fournisseur);
828
+		$this->code_compta = trim($this->code_compta);
829
+		$this->code_compta_fournisseur = trim($this->code_compta_fournisseur);
830 830
 
831 831
 		// Check parameters. More tests are done later in the ->verify()
832
-		if (! is_numeric($this->client) && ! is_numeric($this->fournisseur))
832
+		if (!is_numeric($this->client) && !is_numeric($this->fournisseur))
833 833
 		{
834 834
 			$langs->load("errors");
835 835
 			$this->error = $langs->trans("BadValueForParameterClientOrSupplier");
836 836
 			return -1;
837 837
 		}
838 838
 
839
-		$customer=false;
840
-		if (! empty($allowmodcodeclient) && ! empty($this->client))
839
+		$customer = false;
840
+		if (!empty($allowmodcodeclient) && !empty($this->client))
841 841
 		{
842 842
 			// Attention get_codecompta peut modifier le code suivant le module utilise
843 843
 			if (empty($this->code_compta))
844 844
 			{
845
-				$ret=$this->get_codecompta('customer');
845
+				$ret = $this->get_codecompta('customer');
846 846
 				if ($ret < 0) return -1;
847 847
 			}
848 848
 
849
-			$customer=true;
849
+			$customer = true;
850 850
 		}
851 851
 
852
-		$supplier=false;
853
-		if (! empty($allowmodcodefournisseur) && ! empty($this->fournisseur))
852
+		$supplier = false;
853
+		if (!empty($allowmodcodefournisseur) && !empty($this->fournisseur))
854 854
 		{
855 855
 			// Attention get_codecompta peut modifier le code suivant le module utilise
856 856
 			if (empty($this->code_compta_fournisseur))
857 857
 			{
858
-				$ret=$this->get_codecompta('supplier');
858
+				$ret = $this->get_codecompta('supplier');
859 859
 				if ($ret < 0) return -1;
860 860
 			}
861 861
 
862
-			$supplier=true;
862
+			$supplier = true;
863 863
 		}
864 864
 
865 865
 		//Web services
866
-		$this->webservices_url = $this->webservices_url?clean_url($this->webservices_url,0):'';
866
+		$this->webservices_url = $this->webservices_url ?clean_url($this->webservices_url, 0) : '';
867 867
 		$this->webservices_key = trim($this->webservices_key);
868 868
 
869 869
 		//Incoterms
@@ -887,174 +887,174 @@  discard block
 block discarded – undo
887 887
 			dol_syslog(get_class($this)."::update verify ok or not done");
888 888
 
889 889
 			$sql  = "UPDATE ".MAIN_DB_PREFIX."societe SET ";
890
-			$sql .= "nom = '" . $this->db->escape($this->name) ."'"; // Required
891
-			$sql .= ",name_alias = '" . $this->db->escape($this->name_alias) ."'";
892
-			$sql .= ",ref_ext = " .(! empty($this->ref_ext)?"'".$this->db->escape($this->ref_ext) ."'":"null");
893
-			$sql .= ",address = '" . $this->db->escape($this->address) ."'";
890
+			$sql .= "nom = '".$this->db->escape($this->name)."'"; // Required
891
+			$sql .= ",name_alias = '".$this->db->escape($this->name_alias)."'";
892
+			$sql .= ",ref_ext = ".(!empty($this->ref_ext) ? "'".$this->db->escape($this->ref_ext)."'" : "null");
893
+			$sql .= ",address = '".$this->db->escape($this->address)."'";
894 894
 
895
-			$sql .= ",zip = ".(! empty($this->zip)?"'".$this->db->escape($this->zip)."'":"null");
896
-			$sql .= ",town = ".(! empty($this->town)?"'".$this->db->escape($this->town)."'":"null");
895
+			$sql .= ",zip = ".(!empty($this->zip) ? "'".$this->db->escape($this->zip)."'" : "null");
896
+			$sql .= ",town = ".(!empty($this->town) ? "'".$this->db->escape($this->town)."'" : "null");
897 897
 
898
-			$sql .= ",fk_departement = '" . (! empty($this->state_id)?$this->state_id:'0') ."'";
899
-			$sql .= ",fk_pays = '" . (! empty($this->country_id)?$this->country_id:'0') ."'";
898
+			$sql .= ",fk_departement = '".(!empty($this->state_id) ? $this->state_id : '0')."'";
899
+			$sql .= ",fk_pays = '".(!empty($this->country_id) ? $this->country_id : '0')."'";
900 900
 
901
-			$sql .= ",phone = ".(! empty($this->phone)?"'".$this->db->escape($this->phone)."'":"null");
902
-			$sql .= ",fax = ".(! empty($this->fax)?"'".$this->db->escape($this->fax)."'":"null");
903
-			$sql .= ",email = ".(! empty($this->email)?"'".$this->db->escape($this->email)."'":"null");
904
-			$sql .= ",skype = ".(! empty($this->skype)?"'".$this->db->escape($this->skype)."'":"null");
905
-			$sql .= ",url = ".(! empty($this->url)?"'".$this->db->escape($this->url)."'":"null");
901
+			$sql .= ",phone = ".(!empty($this->phone) ? "'".$this->db->escape($this->phone)."'" : "null");
902
+			$sql .= ",fax = ".(!empty($this->fax) ? "'".$this->db->escape($this->fax)."'" : "null");
903
+			$sql .= ",email = ".(!empty($this->email) ? "'".$this->db->escape($this->email)."'" : "null");
904
+			$sql .= ",skype = ".(!empty($this->skype) ? "'".$this->db->escape($this->skype)."'" : "null");
905
+			$sql .= ",url = ".(!empty($this->url) ? "'".$this->db->escape($this->url)."'" : "null");
906 906
 
907
-			$sql .= ",note_private = ".(! empty($this->note_private)?"'".$this->db->escape($this->note_private)."'":"null");
908
-			$sql .= ",note_public = ".(! empty($this->note_public)?"'".$this->db->escape($this->note_public)."'":"null");
907
+			$sql .= ",note_private = ".(!empty($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null");
908
+			$sql .= ",note_public = ".(!empty($this->note_public) ? "'".$this->db->escape($this->note_public)."'" : "null");
909 909
 
910
-			$sql .= ",siren   = '". $this->db->escape($this->idprof1) ."'";
911
-			$sql .= ",siret   = '". $this->db->escape($this->idprof2) ."'";
912
-			$sql .= ",ape     = '". $this->db->escape($this->idprof3) ."'";
913
-			$sql .= ",idprof4 = '". $this->db->escape($this->idprof4) ."'";
914
-			$sql .= ",idprof5 = '". $this->db->escape($this->idprof5) ."'";
915
-			$sql .= ",idprof6 = '". $this->db->escape($this->idprof6) ."'";
910
+			$sql .= ",siren   = '".$this->db->escape($this->idprof1)."'";
911
+			$sql .= ",siret   = '".$this->db->escape($this->idprof2)."'";
912
+			$sql .= ",ape     = '".$this->db->escape($this->idprof3)."'";
913
+			$sql .= ",idprof4 = '".$this->db->escape($this->idprof4)."'";
914
+			$sql .= ",idprof5 = '".$this->db->escape($this->idprof5)."'";
915
+			$sql .= ",idprof6 = '".$this->db->escape($this->idprof6)."'";
916 916
 
917
-			$sql .= ",tva_assuj = ".($this->tva_assuj!=''?"'".$this->db->escape($this->tva_assuj)."'":"null");
918
-			$sql .= ",tva_intra = '" . $this->db->escape($this->tva_intra) ."'";
919
-			$sql .= ",status = " .$this->status;
917
+			$sql .= ",tva_assuj = ".($this->tva_assuj != '' ? "'".$this->db->escape($this->tva_assuj)."'" : "null");
918
+			$sql .= ",tva_intra = '".$this->db->escape($this->tva_intra)."'";
919
+			$sql .= ",status = ".$this->status;
920 920
 
921 921
 			// Local taxes
922
-			$sql .= ",localtax1_assuj = ".($this->localtax1_assuj!=''?"'".$this->db->escape($this->localtax1_assuj)."'":"null");
923
-			$sql .= ",localtax2_assuj = ".($this->localtax2_assuj!=''?"'".$this->db->escape($this->localtax2_assuj)."'":"null");
924
-			if($this->localtax1_assuj==1)
922
+			$sql .= ",localtax1_assuj = ".($this->localtax1_assuj != '' ? "'".$this->db->escape($this->localtax1_assuj)."'" : "null");
923
+			$sql .= ",localtax2_assuj = ".($this->localtax2_assuj != '' ? "'".$this->db->escape($this->localtax2_assuj)."'" : "null");
924
+			if ($this->localtax1_assuj == 1)
925 925
 			{
926
-				if($this->localtax1_value!='')
926
+				if ($this->localtax1_value != '')
927 927
 				{
928
-					$sql .=",localtax1_value =".$this->localtax1_value;
928
+					$sql .= ",localtax1_value =".$this->localtax1_value;
929 929
 				}
930
-				else $sql .=",localtax1_value =0.000";
930
+				else $sql .= ",localtax1_value =0.000";
931 931
 
932 932
 			}
933
-			else $sql .=",localtax1_value =0.000";
933
+			else $sql .= ",localtax1_value =0.000";
934 934
 
935
-			if($this->localtax2_assuj==1)
935
+			if ($this->localtax2_assuj == 1)
936 936
 			{
937
-				if($this->localtax2_value!='')
937
+				if ($this->localtax2_value != '')
938 938
 				{
939
-					$sql .=",localtax2_value =".$this->localtax2_value;
939
+					$sql .= ",localtax2_value =".$this->localtax2_value;
940 940
 				}
941
-				else $sql .=",localtax2_value =0.000";
941
+				else $sql .= ",localtax2_value =0.000";
942 942
 
943 943
 			}
944
-			else $sql .=",localtax2_value =0.000";
944
+			else $sql .= ",localtax2_value =0.000";
945 945
 
946 946
 			$sql .= ",capital = ".($this->capital == '' ? "null" : $this->capital);
947 947
 
948
-			$sql .= ",prefix_comm = ".(! empty($this->prefix_comm)?"'".$this->db->escape($this->prefix_comm)."'":"null");
948
+			$sql .= ",prefix_comm = ".(!empty($this->prefix_comm) ? "'".$this->db->escape($this->prefix_comm)."'" : "null");
949 949
 
950
-			$sql .= ",fk_effectif = ".(! empty($this->effectif_id)?"'".$this->db->escape($this->effectif_id)."'":"null");
950
+			$sql .= ",fk_effectif = ".(!empty($this->effectif_id) ? "'".$this->db->escape($this->effectif_id)."'" : "null");
951 951
 			if (isset($this->stcomm_id))
952 952
 			{
953 953
 				$sql .= ",fk_stcomm=".($this->stcomm_id > 0 ? $this->stcomm_id : "0");
954 954
 			}
955
-			$sql .= ",fk_typent = ".(! empty($this->typent_id)?"'".$this->db->escape($this->typent_id)."'":"0");
955
+			$sql .= ",fk_typent = ".(!empty($this->typent_id) ? "'".$this->db->escape($this->typent_id)."'" : "0");
956 956
 
957
-			$sql .= ",fk_forme_juridique = ".(! empty($this->forme_juridique_code)?"'".$this->db->escape($this->forme_juridique_code)."'":"null");
957
+			$sql .= ",fk_forme_juridique = ".(!empty($this->forme_juridique_code) ? "'".$this->db->escape($this->forme_juridique_code)."'" : "null");
958 958
 
959
-			$sql .= ",mode_reglement = ".(! empty($this->mode_reglement_id)?"'".$this->db->escape($this->mode_reglement_id)."'":"null");
960
-			$sql .= ",cond_reglement = ".(! empty($this->cond_reglement_id)?"'".$this->db->escape($this->cond_reglement_id)."'":"null");
961
-			$sql .= ",mode_reglement_supplier = ".(! empty($this->mode_reglement_supplier_id)?"'".$this->db->escape($this->mode_reglement_supplier_id)."'":"null");
962
-			$sql .= ",cond_reglement_supplier = ".(! empty($this->cond_reglement_supplier_id)?"'".$this->db->escape($this->cond_reglement_supplier_id)."'":"null");
963
-			$sql .= ",fk_shipping_method = ".(! empty($this->shipping_method_id)?"'".$this->db->escape($this->shipping_method_id)."'":"null");
959
+			$sql .= ",mode_reglement = ".(!empty($this->mode_reglement_id) ? "'".$this->db->escape($this->mode_reglement_id)."'" : "null");
960
+			$sql .= ",cond_reglement = ".(!empty($this->cond_reglement_id) ? "'".$this->db->escape($this->cond_reglement_id)."'" : "null");
961
+			$sql .= ",mode_reglement_supplier = ".(!empty($this->mode_reglement_supplier_id) ? "'".$this->db->escape($this->mode_reglement_supplier_id)."'" : "null");
962
+			$sql .= ",cond_reglement_supplier = ".(!empty($this->cond_reglement_supplier_id) ? "'".$this->db->escape($this->cond_reglement_supplier_id)."'" : "null");
963
+			$sql .= ",fk_shipping_method = ".(!empty($this->shipping_method_id) ? "'".$this->db->escape($this->shipping_method_id)."'" : "null");
964 964
 
965
-			$sql .= ",client = " . (! empty($this->client)?$this->client:0);
966
-			$sql .= ",fournisseur = " . (! empty($this->fournisseur)?$this->fournisseur:0);
967
-			$sql .= ",barcode = ".(! empty($this->barcode)?"'".$this->db->escape($this->barcode)."'":"null");
968
-			$sql .= ",default_lang = ".(! empty($this->default_lang)?"'".$this->db->escape($this->default_lang)."'":"null");
969
-			$sql .= ",logo = ".(! empty($this->logo)?"'".$this->db->escape($this->logo)."'":"null");
970
-			$sql .= ",outstanding_limit= ".($this->outstanding_limit!=''?$this->outstanding_limit:'null');
971
-			$sql .= ",order_min_amount= ".($this->order_min_amount!=''?$this->order_min_amount:'null');
972
-			$sql .= ",supplier_order_min_amount= ".($this->supplier_order_min_amount!=''?$this->supplier_order_min_amount:'null');
965
+			$sql .= ",client = ".(!empty($this->client) ? $this->client : 0);
966
+			$sql .= ",fournisseur = ".(!empty($this->fournisseur) ? $this->fournisseur : 0);
967
+			$sql .= ",barcode = ".(!empty($this->barcode) ? "'".$this->db->escape($this->barcode)."'" : "null");
968
+			$sql .= ",default_lang = ".(!empty($this->default_lang) ? "'".$this->db->escape($this->default_lang)."'" : "null");
969
+			$sql .= ",logo = ".(!empty($this->logo) ? "'".$this->db->escape($this->logo)."'" : "null");
970
+			$sql .= ",outstanding_limit= ".($this->outstanding_limit != '' ? $this->outstanding_limit : 'null');
971
+			$sql .= ",order_min_amount= ".($this->order_min_amount != '' ? $this->order_min_amount : 'null');
972
+			$sql .= ",supplier_order_min_amount= ".($this->supplier_order_min_amount != '' ? $this->supplier_order_min_amount : 'null');
973 973
 			$sql .= ",fk_prospectlevel='".$this->db->escape($this->fk_prospectlevel)."'";
974 974
 
975
-			$sql .= ",webservices_url = ".(! empty($this->webservices_url)?"'".$this->db->escape($this->webservices_url)."'":"null");
976
-			$sql .= ",webservices_key = ".(! empty($this->webservices_key)?"'".$this->db->escape($this->webservices_key)."'":"null");
975
+			$sql .= ",webservices_url = ".(!empty($this->webservices_url) ? "'".$this->db->escape($this->webservices_url)."'" : "null");
976
+			$sql .= ",webservices_key = ".(!empty($this->webservices_key) ? "'".$this->db->escape($this->webservices_key)."'" : "null");
977 977
 
978 978
 			//Incoterms
979
-			$sql.= ", fk_incoterms = ".$this->fk_incoterms;
980
-			$sql.= ", location_incoterms = ".(! empty($this->location_incoterms)?"'".$this->db->escape($this->location_incoterms)."'":"null");
979
+			$sql .= ", fk_incoterms = ".$this->fk_incoterms;
980
+			$sql .= ", location_incoterms = ".(!empty($this->location_incoterms) ? "'".$this->db->escape($this->location_incoterms)."'" : "null");
981 981
 
982 982
 			if ($customer)
983 983
 			{
984
-				$sql .= ", code_client = ".(! empty($this->code_client)?"'".$this->db->escape($this->code_client)."'":"null");
985
-				$sql .= ", code_compta = ".(! empty($this->code_compta)?"'".$this->db->escape($this->code_compta)."'":"null");
984
+				$sql .= ", code_client = ".(!empty($this->code_client) ? "'".$this->db->escape($this->code_client)."'" : "null");
985
+				$sql .= ", code_compta = ".(!empty($this->code_compta) ? "'".$this->db->escape($this->code_compta)."'" : "null");
986 986
 			}
987 987
 
988 988
 			if ($supplier)
989 989
 			{
990
-				$sql .= ", code_fournisseur = ".(! empty($this->code_fournisseur)?"'".$this->db->escape($this->code_fournisseur)."'":"null");
991
-				$sql .= ", code_compta_fournisseur = ".(! empty($this->code_compta_fournisseur)?"'".$this->db->escape($this->code_compta_fournisseur)."'":"null");
990
+				$sql .= ", code_fournisseur = ".(!empty($this->code_fournisseur) ? "'".$this->db->escape($this->code_fournisseur)."'" : "null");
991
+				$sql .= ", code_compta_fournisseur = ".(!empty($this->code_compta_fournisseur) ? "'".$this->db->escape($this->code_compta_fournisseur)."'" : "null");
992 992
 			}
993
-			$sql .= ", fk_user_modif = ".(! empty($user->id)?"'".$user->id."'":"null");
993
+			$sql .= ", fk_user_modif = ".(!empty($user->id) ? "'".$user->id."'" : "null");
994 994
 			$sql .= ", fk_multicurrency = ".(int) $this->fk_multicurrency;
995 995
 			$sql .= ', multicurrency_code = \''.$this->db->escape($this->multicurrency_code)."'";
996
-			$sql .= " WHERE rowid = '" . $id ."'";
996
+			$sql .= " WHERE rowid = '".$id."'";
997 997
 
998
-			$resql=$this->db->query($sql);
998
+			$resql = $this->db->query($sql);
999 999
 			if ($resql)
1000 1000
 			{
1001
-				unset($this->country_code);		// We clean this because it may have been changed after an update of country_id
1001
+				unset($this->country_code); // We clean this because it may have been changed after an update of country_id
1002 1002
 				unset($this->country);
1003 1003
 				unset($this->state_code);
1004 1004
 				unset($this->state);
1005 1005
 
1006 1006
 				$nbrowsaffected = $this->db->affected_rows($resql);
1007 1007
 
1008
-				if (! $error && $nbrowsaffected)
1008
+				if (!$error && $nbrowsaffected)
1009 1009
 				{
1010 1010
 					// Update information on linked member if it is an update
1011
-					if (! $nosyncmember && ! empty($conf->adherent->enabled))
1011
+					if (!$nosyncmember && !empty($conf->adherent->enabled))
1012 1012
 					{
1013 1013
 						require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
1014 1014
 
1015 1015
 						dol_syslog(get_class($this)."::update update linked member");
1016 1016
 
1017
-						$lmember=new Adherent($this->db);
1018
-						$result=$lmember->fetch(0, 0, $this->id);
1017
+						$lmember = new Adherent($this->db);
1018
+						$result = $lmember->fetch(0, 0, $this->id);
1019 1019
 
1020 1020
 						if ($result > 0)
1021 1021
 						{
1022
-							$lmember->societe=$this->name;
1022
+							$lmember->societe = $this->name;
1023 1023
 							//$lmember->firstname=$this->firstname?$this->firstname:$lmember->firstname;	// We keep firstname and lastname of member unchanged
1024 1024
 							//$lmember->lastname=$this->lastname?$this->lastname:$lmember->lastname;		// We keep firstname and lastname of member unchanged
1025
-							$lmember->address=$this->address;
1026
-							$lmember->email=$this->email;
1027
-							$lmember->skype=$this->skype;
1028
-							$lmember->phone=$this->phone;
1025
+							$lmember->address = $this->address;
1026
+							$lmember->email = $this->email;
1027
+							$lmember->skype = $this->skype;
1028
+							$lmember->phone = $this->phone;
1029 1029
 
1030
-							$result=$lmember->update($user,0,1,1,1);	// Use nosync to 1 to avoid cyclic updates
1030
+							$result = $lmember->update($user, 0, 1, 1, 1); // Use nosync to 1 to avoid cyclic updates
1031 1031
 							if ($result < 0)
1032 1032
 							{
1033
-								$this->error=$lmember->error;
1034
-								dol_syslog(get_class($this)."::update ".$this->error,LOG_ERR);
1033
+								$this->error = $lmember->error;
1034
+								dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR);
1035 1035
 								$error++;
1036 1036
 							}
1037 1037
 						}
1038 1038
 						else if ($result < 0)
1039 1039
 						{
1040
-							$this->error=$lmember->error;
1040
+							$this->error = $lmember->error;
1041 1041
 							$error++;
1042 1042
 						}
1043 1043
 					}
1044 1044
 				}
1045 1045
 
1046
-				$action='update';
1046
+				$action = 'update';
1047 1047
 
1048 1048
 				// Actions on extra fields (by external module or standard code)
1049 1049
 				// TODO le hook fait double emploi avec le trigger !!
1050 1050
 				$hookmanager->initHooks(array('thirdpartydao'));
1051
-				$parameters=array('socid'=>$this->id);
1052
-				$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
1051
+				$parameters = array('socid'=>$this->id);
1052
+				$reshook = $hookmanager->executeHooks('insertExtraFields', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1053 1053
 				if (empty($reshook))
1054 1054
 				{
1055 1055
 					if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
1056 1056
 					{
1057
-						$result=$this->insertExtraFields();
1057
+						$result = $this->insertExtraFields();
1058 1058
 						if ($result < 0)
1059 1059
 						{
1060 1060
 							$error++;
@@ -1063,15 +1063,15 @@  discard block
 block discarded – undo
1063 1063
 				}
1064 1064
 				else if ($reshook < 0) $error++;
1065 1065
 
1066
-				if (! $error && $call_trigger)
1066
+				if (!$error && $call_trigger)
1067 1067
 				{
1068 1068
 					// Call trigger
1069
-					$result=$this->call_trigger('COMPANY_MODIFY',$user);
1069
+					$result = $this->call_trigger('COMPANY_MODIFY', $user);
1070 1070
 					if ($result < 0) $error++;
1071 1071
 					// End call triggers
1072 1072
 				}
1073 1073
 
1074
-				if (! $error)
1074
+				if (!$error)
1075 1075
 				{
1076 1076
 					dol_syslog(get_class($this)."::Update success");
1077 1077
 					$this->db->commit();
@@ -1103,7 +1103,7 @@  discard block
 block discarded – undo
1103 1103
 		else
1104 1104
 	   {
1105 1105
 			$this->db->rollback();
1106
-			dol_syslog(get_class($this)."::Update fails verify ".join(',',$this->errors), LOG_WARNING);
1106
+			dol_syslog(get_class($this)."::Update fails verify ".join(',', $this->errors), LOG_WARNING);
1107 1107
 			return -3;
1108 1108
 		}
1109 1109
 	}
@@ -1125,7 +1125,7 @@  discard block
 block discarded – undo
1125 1125
 	 *    @param    string	$ref_alias 		Name_alias of third party (Warning, this can return several records)
1126 1126
 	 *    @return   int						>0 if OK, <0 if KO or if two records found for same ref or idprof, 0 if not found.
1127 1127
 	 */
1128
-	function fetch($rowid, $ref='', $ref_ext='', $ref_int='', $idprof1='',$idprof2='',$idprof3='',$idprof4='',$idprof5='',$idprof6='', $email='', $ref_alias='')
1128
+	function fetch($rowid, $ref = '', $ref_ext = '', $ref_int = '', $idprof1 = '', $idprof2 = '', $idprof3 = '', $idprof4 = '', $idprof5 = '', $idprof6 = '', $email = '', $ref_alias = '')
1129 1129
 	{
1130 1130
 		global $langs;
1131 1131
 		global $conf;
@@ -1180,13 +1180,13 @@  discard block
 block discarded – undo
1180 1180
 		if ($idprof6)   $sql .= " AND s.idprof6 = '".$this->db->escape($idprof6)."'";
1181 1181
 		if ($email)     $sql .= " AND s.email = '".$this->db->escape($email)."'";
1182 1182
 
1183
-		$resql=$this->db->query($sql);
1183
+		$resql = $this->db->query($sql);
1184 1184
 		if ($resql)
1185 1185
 		{
1186
-			$num=$this->db->num_rows($resql);
1186
+			$num = $this->db->num_rows($resql);
1187 1187
 			if ($num > 1)
1188 1188
 			{
1189
-				$this->error='Fetch found several records. Rename one of tirdparties to avoid duplicate.';
1189
+				$this->error = 'Fetch found several records. Rename one of tirdparties to avoid duplicate.';
1190 1190
 				dol_syslog($this->error, LOG_ERR);
1191 1191
 				$result = -2;
1192 1192
 			}
@@ -1196,11 +1196,11 @@  discard block
 block discarded – undo
1196 1196
 
1197 1197
 				$this->id           = $obj->rowid;
1198 1198
 				$this->entity       = $obj->entity;
1199
-				$this->canvas		= $obj->canvas;
1199
+				$this->canvas = $obj->canvas;
1200 1200
 
1201 1201
 				$this->ref          = $obj->rowid;
1202
-				$this->name 		= $obj->name;
1203
-				$this->nom          = $obj->name;		// deprecated
1202
+				$this->name = $obj->name;
1203
+				$this->nom          = $obj->name; // deprecated
1204 1204
 				$this->name_alias = $obj->name_alias;
1205 1205
 				$this->ref_ext      = $obj->ref_ext;
1206 1206
 				$this->ref_int      = $obj->ref_int;
@@ -1210,22 +1210,22 @@  discard block
 block discarded – undo
1210 1210
 				$this->user_creation     = $obj->fk_user_creat;
1211 1211
 				$this->user_modification = $obj->fk_user_modif;
1212 1212
 
1213
-				$this->address 		= $obj->address;
1213
+				$this->address = $obj->address;
1214 1214
 				$this->zip 			= $obj->zip;
1215 1215
 				$this->town 		= $obj->town;
1216 1216
 
1217 1217
 				$this->country_id   = $obj->country_id;
1218
-				$this->country_code = $obj->country_id?$obj->country_code:'';
1219
-				$this->country 		= $obj->country_id?($langs->trans('Country'.$obj->country_code)!='Country'.$obj->country_code?$langs->transnoentities('Country'.$obj->country_code):$obj->country):'';
1218
+				$this->country_code = $obj->country_id ? $obj->country_code : '';
1219
+				$this->country = $obj->country_id ? ($langs->trans('Country'.$obj->country_code) != 'Country'.$obj->country_code ? $langs->transnoentities('Country'.$obj->country_code) : $obj->country) : '';
1220 1220
 
1221 1221
 				$this->state_id     = $obj->fk_departement;
1222 1222
 				$this->state_code   = $obj->state_code;
1223
-				$this->state        = ($obj->state!='-'?$obj->state:'');
1223
+				$this->state        = ($obj->state != '-' ? $obj->state : '');
1224 1224
 
1225
-				$transcode=$langs->trans('StatusProspect'.$obj->fk_stcomm);
1226
-				$libelle=($transcode!='StatusProspect'.$obj->fk_stcomm?$transcode:$obj->stcomm);
1227
-				$this->stcomm_id = $obj->fk_stcomm;     // id statut commercial
1228
-				$this->statut_commercial = $libelle;    // libelle statut commercial
1225
+				$transcode = $langs->trans('StatusProspect'.$obj->fk_stcomm);
1226
+				$libelle = ($transcode != 'StatusProspect'.$obj->fk_stcomm ? $transcode : $obj->stcomm);
1227
+				$this->stcomm_id = $obj->fk_stcomm; // id statut commercial
1228
+				$this->statut_commercial = $libelle; // libelle statut commercial
1229 1229
 
1230 1230
 				$this->email = $obj->email;
1231 1231
 				$this->skype = $obj->skype;
@@ -1233,7 +1233,7 @@  discard block
 block discarded – undo
1233 1233
 				$this->phone = $obj->phone;
1234 1234
 				$this->fax = $obj->fax;
1235 1235
 
1236
-				$this->parent    = $obj->parent;
1236
+				$this->parent = $obj->parent;
1237 1237
 
1238 1238
 				$this->idprof1		= $obj->idprof1;
1239 1239
 				$this->idprof2		= $obj->idprof2;
@@ -1242,7 +1242,7 @@  discard block
 block discarded – undo
1242 1242
 				$this->idprof5		= $obj->idprof5;
1243 1243
 				$this->idprof6		= $obj->idprof6;
1244 1244
 
1245
-				$this->capital   = $obj->capital;
1245
+				$this->capital = $obj->capital;
1246 1246
 
1247 1247
 				$this->code_client = $obj->code_client;
1248 1248
 				$this->code_fournisseur = $obj->code_fournisseur;
@@ -1267,22 +1267,22 @@  discard block
 block discarded – undo
1267 1267
 				$this->typent_code    = $obj->typent_code;
1268 1268
 
1269 1269
 				$this->effectif_id    = $obj->effectif_id;
1270
-				$this->effectif       = $obj->effectif_id?$obj->effectif:'';
1270
+				$this->effectif       = $obj->effectif_id ? $obj->effectif : '';
1271 1271
 
1272
-				$this->forme_juridique_code= $obj->forme_juridique_code;
1273
-				$this->forme_juridique     = $obj->forme_juridique_code?$obj->forme_juridique:'';
1272
+				$this->forme_juridique_code = $obj->forme_juridique_code;
1273
+				$this->forme_juridique     = $obj->forme_juridique_code ? $obj->forme_juridique : '';
1274 1274
 
1275 1275
 				$this->fk_prospectlevel = $obj->fk_prospectlevel;
1276 1276
 
1277 1277
 				$this->prefix_comm = $obj->prefix_comm;
1278 1278
 
1279
-				$this->remise_percent		= $obj->remise_client;
1279
+				$this->remise_percent = $obj->remise_client;
1280 1280
 				$this->mode_reglement_id 	= $obj->mode_reglement;
1281 1281
 				$this->cond_reglement_id 	= $obj->cond_reglement;
1282 1282
 				$this->mode_reglement_supplier_id 	= $obj->mode_reglement_supplier;
1283 1283
 				$this->cond_reglement_supplier_id 	= $obj->cond_reglement_supplier;
1284
-				$this->shipping_method_id   = ($obj->fk_shipping_method>0)?$obj->fk_shipping_method:null;
1285
-				$this->fk_account			= $obj->fk_account;
1284
+				$this->shipping_method_id = ($obj->fk_shipping_method > 0) ? $obj->fk_shipping_method : null;
1285
+				$this->fk_account = $obj->fk_account;
1286 1286
 
1287 1287
 				$this->client      = $obj->client;
1288 1288
 				$this->fournisseur = $obj->fournisseur;
@@ -1299,7 +1299,7 @@  discard block
 block discarded – undo
1299 1299
 
1300 1300
 				$this->outstanding_limit		= $obj->outstanding_limit;
1301 1301
 				$this->order_min_amount			= $obj->order_min_amount;
1302
-				$this->supplier_order_min_amount	= $obj->supplier_order_min_amount;
1302
+				$this->supplier_order_min_amount = $obj->supplier_order_min_amount;
1303 1303
 
1304 1304
 				// multiprix
1305 1305
 				$this->price_level = $obj->price_level;
@@ -1330,12 +1330,12 @@  discard block
 block discarded – undo
1330 1330
 		}
1331 1331
 		else
1332 1332
 		{
1333
-			$this->error=$this->db->lasterror();
1333
+			$this->error = $this->db->lasterror();
1334 1334
 			$result = -3;
1335 1335
 		}
1336 1336
 
1337 1337
 		// Use first price level if level not defined for third party
1338
-		if (! empty($conf->global->PRODUIT_MULTIPRICES) && empty($this->price_level)) $this->price_level=1;
1338
+		if (!empty($conf->global->PRODUIT_MULTIPRICES) && empty($this->price_level)) $this->price_level = 1;
1339 1339
 
1340 1340
 		return $result;
1341 1341
 	}
@@ -1352,7 +1352,7 @@  discard block
 block discarded – undo
1352 1352
 	 * 	@param		string		$clause		Clause for filters
1353 1353
 	 * 	@return		array|int				<0 if KO, array of thirdparties object if OK
1354 1354
 	 */
1355
-	function searchByName($name, $type='0', $filters = array(), $exact = false, $case = false, $similar = false, $clause = 'AND')
1355
+	function searchByName($name, $type = '0', $filters = array(), $exact = false, $case = false, $similar = false, $clause = 'AND')
1356 1356
 	{
1357 1357
 		$thirdparties = array();
1358 1358
 
@@ -1361,23 +1361,23 @@  discard block
 block discarded – undo
1361 1361
 		// Check parameter
1362 1362
 		if (empty($name))
1363 1363
 		{
1364
-			$this->errors[]='ErrorBadValueForParameter';
1364
+			$this->errors[] = 'ErrorBadValueForParameter';
1365 1365
 			return -1;
1366 1366
 		}
1367 1367
 
1368 1368
 		// Generation requete recherche
1369 1369
 		$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe";
1370
-		$sql.= " WHERE entity IN (".getEntity('category').")";
1371
-		if (! empty($type))
1370
+		$sql .= " WHERE entity IN (".getEntity('category').")";
1371
+		if (!empty($type))
1372 1372
 		{
1373 1373
 			if ($type == 1 || $type == 2)
1374
-				$sql.= " AND client = ".$type;
1374
+				$sql .= " AND client = ".$type;
1375 1375
 			elseif ($type == 3)
1376
-				$sql.= " AND fournisseur = 1";
1376
+				$sql .= " AND fournisseur = 1";
1377 1377
 		}
1378
-		if (! empty($name))
1378
+		if (!empty($name))
1379 1379
 		{
1380
-			if (! $exact)
1380
+			if (!$exact)
1381 1381
 			{
1382 1382
 				if (preg_match('/^([\*])?[^*]+([\*])?$/', $name, $regs) && count($regs) > 1)
1383 1383
 				{
@@ -1388,28 +1388,28 @@  discard block
 block discarded – undo
1388 1388
 					$name = '%'.$name.'%';
1389 1389
 				}
1390 1390
 			}
1391
-			$sql.= " AND ";
1392
-			if (is_array($filters) && ! empty($filters))
1393
-				$sql.= "(";
1391
+			$sql .= " AND ";
1392
+			if (is_array($filters) && !empty($filters))
1393
+				$sql .= "(";
1394 1394
 			if ($similar)
1395 1395
 			{
1396 1396
 				// For test similitude (string inside name into database, or name into database inside string)
1397 1397
 				// Do not use this. Not compatible with other database.
1398
-				$sql.= "(LOCATE('".$this->db->escape($name)."', nom) > 0 OR LOCATE(nom, '".$this->db->escape($name)."') > 0)";
1398
+				$sql .= "(LOCATE('".$this->db->escape($name)."', nom) > 0 OR LOCATE(nom, '".$this->db->escape($name)."') > 0)";
1399 1399
 			}
1400 1400
 			else
1401 1401
 			{
1402
-				if (! $case)
1403
-					$sql.= "nom LIKE '".$this->db->escape($name)."'";
1402
+				if (!$case)
1403
+					$sql .= "nom LIKE '".$this->db->escape($name)."'";
1404 1404
 				else
1405
-					$sql.= "nom LIKE BINARY '".$this->db->escape($name)."'";
1405
+					$sql .= "nom LIKE BINARY '".$this->db->escape($name)."'";
1406 1406
 			}
1407 1407
 		}
1408
-		if (is_array($filters) && ! empty($filters))
1408
+		if (is_array($filters) && !empty($filters))
1409 1409
 		{
1410
-			foreach($filters as $field => $value)
1410
+			foreach ($filters as $field => $value)
1411 1411
 			{
1412
-				if (! $exact)
1412
+				if (!$exact)
1413 1413
 				{
1414 1414
 					if (preg_match('/^([\*])?[^*]+([\*])?$/', $value, $regs) && count($regs) > 1)
1415 1415
 					{
@@ -1420,16 +1420,16 @@  discard block
 block discarded – undo
1420 1420
 						$value = '%'.$value.'%';
1421 1421
 					}
1422 1422
 				}
1423
-				if (! $case)
1424
-					$sql.= " ".$clause." ".$field." LIKE '".$this->db->escape($value)."'";
1423
+				if (!$case)
1424
+					$sql .= " ".$clause." ".$field." LIKE '".$this->db->escape($value)."'";
1425 1425
 				else
1426
-					$sql.= " ".$clause." ".$field." LIKE BINARY '".$this->db->escape($value)."'";
1426
+					$sql .= " ".$clause." ".$field." LIKE BINARY '".$this->db->escape($value)."'";
1427 1427
 			}
1428
-			if (! empty($name))
1429
-				$sql.= ")";
1428
+			if (!empty($name))
1429
+				$sql .= ")";
1430 1430
 		}
1431 1431
 
1432
-		$res  = $this->db->query($sql);
1432
+		$res = $this->db->query($sql);
1433 1433
 		if ($res)
1434 1434
 		{
1435 1435
 			while ($rec = $this->db->fetch_array($res))
@@ -1443,7 +1443,7 @@  discard block
 block discarded – undo
1443 1443
 		}
1444 1444
 		else
1445 1445
 		{
1446
-			$this->error=$this->db->lasterror();
1446
+			$this->error = $this->db->lasterror();
1447 1447
 			return -1;
1448 1448
 		}
1449 1449
 	}
@@ -1456,15 +1456,15 @@  discard block
 block discarded – undo
1456 1456
 	 *    @param    int		$call_trigger   0=No, 1=yes
1457 1457
 	 *    @return	int						<0 if KO, 0 if nothing done, >0 if OK
1458 1458
 	 */
1459
-	function delete($id, User $fuser=null, $call_trigger=1)
1459
+	function delete($id, User $fuser = null, $call_trigger = 1)
1460 1460
 	{
1461 1461
 		global $langs, $conf, $user;
1462 1462
 
1463
-		if (empty($fuser)) $fuser=$user;
1463
+		if (empty($fuser)) $fuser = $user;
1464 1464
 
1465 1465
 		require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1466 1466
 
1467
-		$entity=isset($this->entity)?$this->entity:$conf->entity;
1467
+		$entity = isset($this->entity) ? $this->entity : $conf->entity;
1468 1468
 
1469 1469
 		dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1470 1470
 		$error = 0;
@@ -1476,15 +1476,15 @@  discard block
 block discarded – undo
1476 1476
 			$this->db->begin();
1477 1477
 
1478 1478
 			// User is mandatory for trigger call
1479
-			if (! $error && $call_trigger)
1479
+			if (!$error && $call_trigger)
1480 1480
 			{
1481 1481
 				// Call trigger
1482
-				$result=$this->call_trigger('COMPANY_DELETE',$fuser);
1482
+				$result = $this->call_trigger('COMPANY_DELETE', $fuser);
1483 1483
 				if ($result < 0) $error++;
1484 1484
 				// End call triggers
1485 1485
 			}
1486 1486
 
1487
-			if (! $error)
1487
+			if (!$error)
1488 1488
 			{
1489 1489
 				require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1490 1490
 				$static_cat = new Categorie($this->db);
@@ -1493,11 +1493,11 @@  discard block
 block discarded – undo
1493 1493
 				// Fill $toute_categs array with an array of (type => array of ("Categorie" instance))
1494 1494
 				if ($this->client || $this->prospect)
1495 1495
 				{
1496
-					$toute_categs['customer'] = $static_cat->containing($this->id,Categorie::TYPE_CUSTOMER);
1496
+					$toute_categs['customer'] = $static_cat->containing($this->id, Categorie::TYPE_CUSTOMER);
1497 1497
 				}
1498 1498
 				if ($this->fournisseur)
1499 1499
 				{
1500
-					$toute_categs['supplier'] = $static_cat->containing($this->id,Categorie::TYPE_SUPPLIER);
1500
+					$toute_categs['supplier'] = $static_cat->containing($this->id, Categorie::TYPE_SUPPLIER);
1501 1501
 				}
1502 1502
 
1503 1503
 				// Remove each "Categorie"
@@ -1512,11 +1512,11 @@  discard block
 block discarded – undo
1512 1512
 
1513 1513
 			foreach ($this->childtablesoncascade as $tabletodelete)
1514 1514
 			{
1515
-				if (! $error)
1515
+				if (!$error)
1516 1516
 				{
1517 1517
 					$sql = "DELETE FROM ".MAIN_DB_PREFIX.$tabletodelete;
1518
-					$sql.= " WHERE fk_soc = " . $id;
1519
-					if (! $this->db->query($sql))
1518
+					$sql .= " WHERE fk_soc = ".$id;
1519
+					if (!$this->db->query($sql))
1520 1520
 					{
1521 1521
 						$error++;
1522 1522
 						$this->errors[] = $this->db->lasterror();
@@ -1525,9 +1525,9 @@  discard block
 block discarded – undo
1525 1525
 			}
1526 1526
 
1527 1527
 			// Removed extrafields
1528
-			if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used
1528
+			if ((!$error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used
1529 1529
 			{
1530
-				$result=$this->deleteExtraFields();
1530
+				$result = $this->deleteExtraFields();
1531 1531
 				if ($result < 0)
1532 1532
 				{
1533 1533
 					$error++;
@@ -1536,25 +1536,25 @@  discard block
 block discarded – undo
1536 1536
 			}
1537 1537
 
1538 1538
 			// Remove third party
1539
-			if (! $error)
1539
+			if (!$error)
1540 1540
 			{
1541 1541
 				$sql = "DELETE FROM ".MAIN_DB_PREFIX."societe";
1542
-				$sql.= " WHERE rowid = " . $id;
1543
-				if (! $this->db->query($sql))
1542
+				$sql .= " WHERE rowid = ".$id;
1543
+				if (!$this->db->query($sql))
1544 1544
 				{
1545 1545
 					$error++;
1546 1546
 					$this->errors[] = $this->db->lasterror();
1547 1547
 				}
1548 1548
 			}
1549 1549
 
1550
-			if (! $error)
1550
+			if (!$error)
1551 1551
 			{
1552 1552
 				$this->db->commit();
1553 1553
 
1554 1554
 				// Delete directory
1555
-				if (! empty($conf->societe->multidir_output[$entity]))
1555
+				if (!empty($conf->societe->multidir_output[$entity]))
1556 1556
 				{
1557
-					$docdir = $conf->societe->multidir_output[$entity] . "/" . $id;
1557
+					$docdir = $conf->societe->multidir_output[$entity]."/".$id;
1558 1558
 					if (dol_is_dir($docdir))
1559 1559
 					{
1560 1560
 						dol_delete_dir_recursive($docdir);
@@ -1583,13 +1583,13 @@  discard block
 block discarded – undo
1583 1583
 	{
1584 1584
 		if ($this->id)
1585 1585
 		{
1586
-			$newclient=1;
1587
-			if ($this->client == 2 || $this->client == 3) $newclient=3;	//If prospect, we keep prospect tag
1586
+			$newclient = 1;
1587
+			if ($this->client == 2 || $this->client == 3) $newclient = 3; //If prospect, we keep prospect tag
1588 1588
 			$sql = "UPDATE ".MAIN_DB_PREFIX."societe";
1589
-			$sql.= " SET client = ".$newclient;
1590
-			$sql.= " WHERE rowid = " . $this->id;
1589
+			$sql .= " SET client = ".$newclient;
1590
+			$sql .= " WHERE rowid = ".$this->id;
1591 1591
 
1592
-			$resql=$this->db->query($sql);
1592
+			$resql = $this->db->query($sql);
1593 1593
 			if ($resql)
1594 1594
 			{
1595 1595
 				$this->client = $newclient;
@@ -1613,10 +1613,10 @@  discard block
 block discarded – undo
1613 1613
 		global $conf, $langs;
1614 1614
 
1615 1615
 		// Nettoyage parametres
1616
-		$note=trim($note);
1617
-		if (! $note)
1616
+		$note = trim($note);
1617
+		if (!$note)
1618 1618
 		{
1619
-			$this->error=$langs->trans("ErrorFieldRequired",$langs->trans("NoteReason"));
1619
+			$this->error = $langs->trans("ErrorFieldRequired", $langs->trans("NoteReason"));
1620 1620
 			return -2;
1621 1621
 		}
1622 1622
 
@@ -1626,33 +1626,33 @@  discard block
 block discarded – undo
1626 1626
 		{
1627 1627
 			$this->db->begin();
1628 1628
 
1629
-			$now=dol_now();
1629
+			$now = dol_now();
1630 1630
 
1631 1631
 			// Positionne remise courante
1632 1632
 			$sql = "UPDATE ".MAIN_DB_PREFIX."societe ";
1633
-			$sql.= " SET remise_client = '".$this->db->escape($remise)."'";
1634
-			$sql.= " WHERE rowid = " . $this->id;
1635
-			$resql=$this->db->query($sql);
1636
-			if (! $resql)
1633
+			$sql .= " SET remise_client = '".$this->db->escape($remise)."'";
1634
+			$sql .= " WHERE rowid = ".$this->id;
1635
+			$resql = $this->db->query($sql);
1636
+			if (!$resql)
1637 1637
 			{
1638 1638
 				$this->db->rollback();
1639
-				$this->error=$this->db->error();
1639
+				$this->error = $this->db->error();
1640 1640
 				return -1;
1641 1641
 			}
1642 1642
 
1643 1643
 			// Ecrit trace dans historique des remises
1644 1644
 			$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise";
1645
-			$sql.= " (entity, datec, fk_soc, remise_client, note, fk_user_author)";
1646
-			$sql.= " VALUES (".$conf->entity.", '".$this->db->idate($now)."', ".$this->id.", '".$this->db->escape($remise)."',";
1647
-			$sql.= " '".$this->db->escape($note)."',";
1648
-			$sql.= " ".$user->id;
1649
-			$sql.= ")";
1645
+			$sql .= " (entity, datec, fk_soc, remise_client, note, fk_user_author)";
1646
+			$sql .= " VALUES (".$conf->entity.", '".$this->db->idate($now)."', ".$this->id.", '".$this->db->escape($remise)."',";
1647
+			$sql .= " '".$this->db->escape($note)."',";
1648
+			$sql .= " ".$user->id;
1649
+			$sql .= ")";
1650 1650
 
1651
-			$resql=$this->db->query($sql);
1652
-			if (! $resql)
1651
+			$resql = $this->db->query($sql);
1652
+			if (!$resql)
1653 1653
 			{
1654 1654
 				$this->db->rollback();
1655
-				$this->error=$this->db->lasterror();
1655
+				$this->error = $this->db->lasterror();
1656 1656
 				return -1;
1657 1657
 			}
1658 1658
 
@@ -1670,7 +1670,7 @@  discard block
 block discarded – undo
1670 1670
 	 *      @param  float	$tva_tx     VAT rate
1671 1671
 	 *		@return	int					<0 if KO, id of discount record if OK
1672 1672
 	 */
1673
-	function set_remise_except($remise, User $user, $desc, $tva_tx=0)
1673
+	function set_remise_except($remise, User $user, $desc, $tva_tx = 0)
1674 1674
 	{
1675 1675
 		global $langs;
1676 1676
 
@@ -1679,14 +1679,14 @@  discard block
 block discarded – undo
1679 1679
 		$desc = trim($desc);
1680 1680
 
1681 1681
 		// Check parameters
1682
-		if (! $remise > 0)
1682
+		if (!$remise > 0)
1683 1683
 		{
1684
-			$this->error=$langs->trans("ErrorWrongValueForParameter","1");
1684
+			$this->error = $langs->trans("ErrorWrongValueForParameter", "1");
1685 1685
 			return -1;
1686 1686
 		}
1687
-		if (! $desc)
1687
+		if (!$desc)
1688 1688
 		{
1689
-			$this->error=$langs->trans("ErrorWrongValueForParameter","3");
1689
+			$this->error = $langs->trans("ErrorWrongValueForParameter", "3");
1690 1690
 			return -2;
1691 1691
 		}
1692 1692
 
@@ -1695,20 +1695,20 @@  discard block
 block discarded – undo
1695 1695
 			require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
1696 1696
 
1697 1697
 			$discount = new DiscountAbsolute($this->db);
1698
-			$discount->fk_soc=$this->id;
1699
-			$discount->amount_ht=price2num($remise,'MT');
1700
-			$discount->amount_tva=price2num($remise*$tva_tx/100,'MT');
1701
-			$discount->amount_ttc=price2num($discount->amount_ht+$discount->amount_tva,'MT');
1702
-			$discount->tva_tx=price2num($tva_tx,'MT');
1703
-			$discount->description=$desc;
1704
-			$result=$discount->create($user);
1698
+			$discount->fk_soc = $this->id;
1699
+			$discount->amount_ht = price2num($remise, 'MT');
1700
+			$discount->amount_tva = price2num($remise * $tva_tx / 100, 'MT');
1701
+			$discount->amount_ttc = price2num($discount->amount_ht + $discount->amount_tva, 'MT');
1702
+			$discount->tva_tx = price2num($tva_tx, 'MT');
1703
+			$discount->description = $desc;
1704
+			$result = $discount->create($user);
1705 1705
 			if ($result > 0)
1706 1706
 			{
1707 1707
 				return $result;
1708 1708
 			}
1709 1709
 			else
1710 1710
 			{
1711
-				$this->error=$discount->error;
1711
+				$this->error = $discount->error;
1712 1712
 				return -3;
1713 1713
 			}
1714 1714
 		}
@@ -1723,19 +1723,19 @@  discard block
 block discarded – undo
1723 1723
 	 * 	@param	integer	$maxvalue	Filter on max value for discount
1724 1724
 	 *	@return	int					<0 if KO, Credit note amount otherwise
1725 1725
 	 */
1726
-	function getAvailableDiscounts($user='',$filter='',$maxvalue=0)
1726
+	function getAvailableDiscounts($user = '', $filter = '', $maxvalue = 0)
1727 1727
 	{
1728 1728
 		require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
1729 1729
 
1730
-		$discountstatic=new DiscountAbsolute($this->db);
1731
-		$result=$discountstatic->getAvailableDiscounts($this,$user,$filter,$maxvalue);
1730
+		$discountstatic = new DiscountAbsolute($this->db);
1731
+		$result = $discountstatic->getAvailableDiscounts($this, $user, $filter, $maxvalue);
1732 1732
 		if ($result >= 0)
1733 1733
 		{
1734 1734
 			return $result;
1735 1735
 		}
1736 1736
 		else
1737 1737
 		{
1738
-			$this->error=$discountstatic->error;
1738
+			$this->error = $discountstatic->error;
1739 1739
 			return -1;
1740 1740
 		}
1741 1741
 	}
@@ -1750,38 +1750,38 @@  discard block
 block discarded – undo
1750 1750
 	{
1751 1751
 		global $conf;
1752 1752
 
1753
-		$reparray=array();
1753
+		$reparray = array();
1754 1754
 
1755 1755
 		$sql = "SELECT DISTINCT u.rowid, u.login, u.lastname, u.firstname, u.email, u.statut, u.entity, u.photo";
1756
-		$sql.= " FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc, ".MAIN_DB_PREFIX."user as u";
1757
-		if (! empty($conf->multicompany->enabled) && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE))
1756
+		$sql .= " FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc, ".MAIN_DB_PREFIX."user as u";
1757
+		if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE))
1758 1758
 		{
1759
-			$sql.= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
1760
-			$sql.= " WHERE ((ug.fk_user = sc.fk_user";
1761
-			$sql.= " AND ug.entity = ".$conf->entity.")";
1762
-			$sql.= " OR u.admin = 1)";
1759
+			$sql .= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
1760
+			$sql .= " WHERE ((ug.fk_user = sc.fk_user";
1761
+			$sql .= " AND ug.entity = ".$conf->entity.")";
1762
+			$sql .= " OR u.admin = 1)";
1763 1763
 		}
1764 1764
 		else
1765
-			$sql.= " WHERE entity in (0, ".$conf->entity.")";
1765
+			$sql .= " WHERE entity in (0, ".$conf->entity.")";
1766 1766
 
1767
-		$sql.= " AND u.rowid = sc.fk_user AND sc.fk_soc = ".$this->id;
1767
+		$sql .= " AND u.rowid = sc.fk_user AND sc.fk_soc = ".$this->id;
1768 1768
 
1769 1769
 		$resql = $this->db->query($sql);
1770 1770
 		if ($resql)
1771 1771
 		{
1772 1772
 			$num = $this->db->num_rows($resql);
1773
-			$i=0;
1773
+			$i = 0;
1774 1774
 			while ($i < $num)
1775 1775
 			{
1776 1776
 				$obj = $this->db->fetch_object($resql);
1777
-				$reparray[$i]['id']=$obj->rowid;
1778
-				$reparray[$i]['lastname']=$obj->lastname;
1779
-				$reparray[$i]['firstname']=$obj->firstname;
1780
-				$reparray[$i]['email']=$obj->email;
1781
-				$reparray[$i]['statut']=$obj->statut;
1782
-				$reparray[$i]['entity']=$obj->entity;
1783
-				$reparray[$i]['login']=$obj->login;
1784
-				$reparray[$i]['photo']=$obj->photo;
1777
+				$reparray[$i]['id'] = $obj->rowid;
1778
+				$reparray[$i]['lastname'] = $obj->lastname;
1779
+				$reparray[$i]['firstname'] = $obj->firstname;
1780
+				$reparray[$i]['email'] = $obj->email;
1781
+				$reparray[$i]['statut'] = $obj->statut;
1782
+				$reparray[$i]['entity'] = $obj->entity;
1783
+				$reparray[$i]['login'] = $obj->login;
1784
+				$reparray[$i]['photo'] = $obj->photo;
1785 1785
 				$i++;
1786 1786
 			}
1787 1787
 			return $reparray;
@@ -1803,13 +1803,13 @@  discard block
 block discarded – undo
1803 1803
 	{
1804 1804
 		if ($this->id)
1805 1805
 		{
1806
-			$now=dol_now();
1806
+			$now = dol_now();
1807 1807
 
1808 1808
 			$sql  = "UPDATE ".MAIN_DB_PREFIX."societe";
1809 1809
 			$sql .= " SET price_level = '".$this->db->escape($price_level)."'";
1810
-			$sql .= " WHERE rowid = " . $this->id;
1810
+			$sql .= " WHERE rowid = ".$this->id;
1811 1811
 
1812
-			if (! $this->db->query($sql))
1812
+			if (!$this->db->query($sql))
1813 1813
 			{
1814 1814
 				dol_print_error($this->db);
1815 1815
 				return -1;
@@ -1819,7 +1819,7 @@  discard block
 block discarded – undo
1819 1819
 			$sql .= " (datec, fk_soc, price_level, fk_user_author)";
1820 1820
 			$sql .= " VALUES ('".$this->db->idate($now)."', ".$this->id.", '".$this->db->escape($price_level)."', ".$user->id.")";
1821 1821
 
1822
-			if (! $this->db->query($sql))
1822
+			if (!$this->db->query($sql))
1823 1823
 			{
1824 1824
 				dol_print_error($this->db);
1825 1825
 				return -1;
@@ -1841,15 +1841,15 @@  discard block
 block discarded – undo
1841 1841
 		if ($this->id > 0 && $commid > 0)
1842 1842
 		{
1843 1843
 			$sql = "DELETE FROM  ".MAIN_DB_PREFIX."societe_commerciaux";
1844
-			$sql.= " WHERE fk_soc = ".$this->id." AND fk_user =".$commid;
1844
+			$sql .= " WHERE fk_soc = ".$this->id." AND fk_user =".$commid;
1845 1845
 
1846 1846
 			$this->db->query($sql);
1847 1847
 
1848 1848
 			$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_commerciaux";
1849
-			$sql.= " ( fk_soc, fk_user )";
1850
-			$sql.= " VALUES (".$this->id.",".$commid.")";
1849
+			$sql .= " ( fk_soc, fk_user )";
1850
+			$sql .= " VALUES (".$this->id.",".$commid.")";
1851 1851
 
1852
-			if (! $this->db->query($sql) )
1852
+			if (!$this->db->query($sql))
1853 1853
 			{
1854 1854
 				dol_syslog(get_class($this)."::add_commercial Erreur");
1855 1855
 			}
@@ -1870,7 +1870,7 @@  discard block
 block discarded – undo
1870 1870
 			$sql  = "DELETE FROM  ".MAIN_DB_PREFIX."societe_commerciaux ";
1871 1871
 			$sql .= " WHERE fk_soc = ".$this->id." AND fk_user =".$commid;
1872 1872
 
1873
-			if (! $this->db->query($sql) )
1873
+			if (!$this->db->query($sql))
1874 1874
 			{
1875 1875
 				dol_syslog(get_class($this)."::del_commercial Erreur");
1876 1876
 			}
@@ -1888,162 +1888,162 @@  discard block
 block discarded – undo
1888 1888
 	 *      @param  int     $save_lastsearch_value    -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
1889 1889
 	 *		@return	string					          String with URL
1890 1890
 	 */
1891
-	function getNomUrl($withpicto=0, $option='', $maxlen=0, $notooltip=0, $save_lastsearch_value=-1)
1891
+	function getNomUrl($withpicto = 0, $option = '', $maxlen = 0, $notooltip = 0, $save_lastsearch_value = -1)
1892 1892
 	{
1893 1893
 		global $conf, $langs, $hookmanager;
1894 1894
 
1895
-		if (! empty($conf->dol_no_mouse_hover)) $notooltip=1;   // Force disable tooltips
1895
+		if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips
1896 1896
 
1897
-		$name=$this->name?$this->name:$this->nom;
1897
+		$name = $this->name ? $this->name : $this->nom;
1898 1898
 
1899
-		if (! empty($conf->global->SOCIETE_ADD_REF_IN_LIST) && (!empty($withpicto)))
1899
+		if (!empty($conf->global->SOCIETE_ADD_REF_IN_LIST) && (!empty($withpicto)))
1900 1900
 		{
1901
-			if (($this->client) && (! empty ( $this->code_client ))
1901
+			if (($this->client) && (!empty ($this->code_client))
1902 1902
 				&& ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1
1903 1903
 				|| $conf->global->SOCIETE_ADD_REF_IN_LIST == 2
1904 1904
 				)
1905 1905
 			)
1906
-			$code = $this->code_client . ' - ';
1906
+			$code = $this->code_client.' - ';
1907 1907
 
1908
-			if (($this->fournisseur) && (! empty ( $this->code_fournisseur ))
1908
+			if (($this->fournisseur) && (!empty ($this->code_fournisseur))
1909 1909
 				&& ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1
1910 1910
 				|| $conf->global->SOCIETE_ADD_REF_IN_LIST == 3
1911 1911
 				)
1912 1912
 			)
1913
-			$code .= $this->code_fournisseur . ' - ';
1913
+			$code .= $this->code_fournisseur.' - ';
1914 1914
 
1915 1915
 			if ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1)
1916
-				$name =$code.' '.$name;
1916
+				$name = $code.' '.$name;
1917 1917
 			else
1918
-				$name =$code;
1918
+				$name = $code;
1919 1919
 		}
1920 1920
 
1921 1921
 		if (!empty($this->name_alias)) $name .= ' ('.$this->name_alias.')';
1922 1922
 
1923
-		$result=''; $label='';
1924
-		$linkstart=''; $linkend='';
1923
+		$result = ''; $label = '';
1924
+		$linkstart = ''; $linkend = '';
1925 1925
 
1926
-		if (! empty($this->logo) && class_exists('Form'))
1926
+		if (!empty($this->logo) && class_exists('Form'))
1927 1927
 		{
1928
-			$label.= '<div class="photointooltip">';
1929
-			$label.= Form::showphoto('societe', $this, 0, 40, 0, 'photowithmargin', 'mini', 0);	// Important, we must force height so image will have height tags and if image is inside a tooltip, the tooltip manager can calculate height and position correctly the tooltip.
1930
-			$label.= '</div><div style="clear: both;"></div>';
1928
+			$label .= '<div class="photointooltip">';
1929
+			$label .= Form::showphoto('societe', $this, 0, 40, 0, 'photowithmargin', 'mini', 0); // Important, we must force height so image will have height tags and if image is inside a tooltip, the tooltip manager can calculate height and position correctly the tooltip.
1930
+			$label .= '</div><div style="clear: both;"></div>';
1931 1931
 		}
1932 1932
 
1933
-		$label.= '<div class="centpercent">';
1933
+		$label .= '<div class="centpercent">';
1934 1934
 
1935 1935
 		if ($option == 'customer' || $option == 'compta' || $option == 'category' || $option == 'category_supplier')
1936 1936
 		{
1937
-		   $label.= '<u>' . $langs->trans("ShowCustomer") . '</u>';
1937
+		   $label .= '<u>'.$langs->trans("ShowCustomer").'</u>';
1938 1938
 		   $linkstart = '<a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$this->id;
1939 1939
 		}
1940 1940
 		else if ($option == 'prospect' && empty($conf->global->SOCIETE_DISABLE_PROSPECTS))
1941 1941
 		{
1942
-			$label.= '<u>' . $langs->trans("ShowProspect") . '</u>';
1942
+			$label .= '<u>'.$langs->trans("ShowProspect").'</u>';
1943 1943
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$this->id;
1944 1944
 		}
1945 1945
 		else if ($option == 'supplier')
1946 1946
 		{
1947
-			$label.= '<u>' . $langs->trans("ShowSupplier") . '</u>';
1947
+			$label .= '<u>'.$langs->trans("ShowSupplier").'</u>';
1948 1948
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$this->id;
1949 1949
 		}
1950 1950
 		else if ($option == 'agenda')
1951 1951
 		{
1952
-			$label.= '<u>' . $langs->trans("ShowAgenda") . '</u>';
1952
+			$label .= '<u>'.$langs->trans("ShowAgenda").'</u>';
1953 1953
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/societe/agenda.php?socid='.$this->id;
1954 1954
 		}
1955 1955
 		else if ($option == 'project')
1956 1956
 		{
1957
-			$label.= '<u>' . $langs->trans("ShowProject") . '</u>';
1957
+			$label .= '<u>'.$langs->trans("ShowProject").'</u>';
1958 1958
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/societe/project.php?socid='.$this->id;
1959 1959
 		}
1960 1960
 		else if ($option == 'margin')
1961 1961
 		{
1962
-			$label.= '<u>' . $langs->trans("ShowMargin") . '</u>';
1962
+			$label .= '<u>'.$langs->trans("ShowMargin").'</u>';
1963 1963
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/margin/tabs/thirdpartyMargins.php?socid='.$this->id.'&type=1';
1964 1964
 		}
1965 1965
 		else if ($option == 'contact')
1966 1966
 		{
1967
-			$label.= '<u>' . $langs->trans("ShowContacts") . '</u>';
1967
+			$label .= '<u>'.$langs->trans("ShowContacts").'</u>';
1968 1968
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/societe/contact.php?socid='.$this->id;
1969 1969
 		}
1970 1970
 		else if ($option == 'ban')
1971 1971
 		{
1972
-			$label.= '<u>' . $langs->trans("ShowBan") . '</u>';
1972
+			$label .= '<u>'.$langs->trans("ShowBan").'</u>';
1973 1973
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/societe/rib.php?socid='.$this->id;
1974 1974
 		}
1975 1975
 
1976 1976
 		// By default
1977 1977
 		if (empty($linkstart))
1978 1978
 		{
1979
-			$label.= '<u>' . $langs->trans("ShowCompany") . '</u>';
1979
+			$label .= '<u>'.$langs->trans("ShowCompany").'</u>';
1980 1980
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/societe/card.php?socid='.$this->id;
1981 1981
 		}
1982 1982
 
1983
-		if (! empty($this->name))
1983
+		if (!empty($this->name))
1984 1984
 		{
1985
-			$label.= '<br><b>' . $langs->trans('Name') . ':</b> '. $this->name;
1986
-			if (! empty($this->name_alias)) $label.=' ('.$this->name_alias.')';
1987
-			$label.= '<br><b>' . $langs->trans('Email') . ':</b> '. $this->email;
1985
+			$label .= '<br><b>'.$langs->trans('Name').':</b> '.$this->name;
1986
+			if (!empty($this->name_alias)) $label .= ' ('.$this->name_alias.')';
1987
+			$label .= '<br><b>'.$langs->trans('Email').':</b> '.$this->email;
1988 1988
 		}
1989
-		if (! empty($this->country_code))
1990
-			$label.= '<br><b>' . $langs->trans('Country') . ':</b> '. $this->country_code;
1991
-		if (! empty($this->tva_intra))
1992
-			$label.= '<br><b>' . $langs->trans('VATIntra') . ':</b> '. $this->tva_intra;
1993
-		if (! empty($this->code_client) && $this->client)
1994
-			$label.= '<br><b>' . $langs->trans('CustomerCode') . ':</b> '. $this->code_client;
1995
-		if (! empty($this->code_fournisseur) && $this->fournisseur)
1996
-			$label.= '<br><b>' . $langs->trans('SupplierCode') . ':</b> '. $this->code_fournisseur;
1997
-		if (! empty($conf->accounting->enabled) && $this->client)
1998
-			$label.= '<br><b>' . $langs->trans('CustomerAccountancyCode') . ':</b> '. ($this->code_compta ? $this->code_compta : $this->code_compta_client);
1999
-		if (! empty($conf->accounting->enabled) && $this->fournisseur)
2000
-			$label.= '<br><b>' . $langs->trans('SupplierAccountancyCode') . ':</b> '. $this->code_compta_fournisseur;
1989
+		if (!empty($this->country_code))
1990
+			$label .= '<br><b>'.$langs->trans('Country').':</b> '.$this->country_code;
1991
+		if (!empty($this->tva_intra))
1992
+			$label .= '<br><b>'.$langs->trans('VATIntra').':</b> '.$this->tva_intra;
1993
+		if (!empty($this->code_client) && $this->client)
1994
+			$label .= '<br><b>'.$langs->trans('CustomerCode').':</b> '.$this->code_client;
1995
+		if (!empty($this->code_fournisseur) && $this->fournisseur)
1996
+			$label .= '<br><b>'.$langs->trans('SupplierCode').':</b> '.$this->code_fournisseur;
1997
+		if (!empty($conf->accounting->enabled) && $this->client)
1998
+			$label .= '<br><b>'.$langs->trans('CustomerAccountancyCode').':</b> '.($this->code_compta ? $this->code_compta : $this->code_compta_client);
1999
+		if (!empty($conf->accounting->enabled) && $this->fournisseur)
2000
+			$label .= '<br><b>'.$langs->trans('SupplierAccountancyCode').':</b> '.$this->code_compta_fournisseur;
2001 2001
 
2002
-		$label.= '</div>';
2002
+		$label .= '</div>';
2003 2003
 
2004 2004
 		// Add type of canvas
2005
-		$linkstart.=(!empty($this->canvas)?'&canvas='.$this->canvas:'');
2005
+		$linkstart .= (!empty($this->canvas) ? '&canvas='.$this->canvas : '');
2006 2006
 		// Add param to save lastsearch_values or not
2007
-		$add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
2008
-		if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
2009
-		if ($add_save_lastsearch_values) $linkstart.='&save_lastsearch_values=1';
2010
-		$linkstart.='"';
2007
+		$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
2008
+		if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
2009
+		if ($add_save_lastsearch_values) $linkstart .= '&save_lastsearch_values=1';
2010
+		$linkstart .= '"';
2011 2011
 
2012
-		$linkclose='';
2012
+		$linkclose = '';
2013 2013
 		if (empty($notooltip))
2014 2014
 		{
2015
-			if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
2015
+			if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
2016 2016
 			{
2017
-				$label=$langs->trans("ShowCompany");
2018
-				$linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
2017
+				$label = $langs->trans("ShowCompany");
2018
+				$linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
2019 2019
 			}
2020
-			$linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"';
2021
-			$linkclose.=' class="classfortooltip refurl"';
2020
+			$linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
2021
+			$linkclose .= ' class="classfortooltip refurl"';
2022 2022
 
2023
-		 	if (! is_object($hookmanager))
2023
+		 	if (!is_object($hookmanager))
2024 2024
 			{
2025 2025
 				include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
2026
-				$hookmanager=new HookManager($this->db);
2026
+				$hookmanager = new HookManager($this->db);
2027 2027
 			}
2028 2028
 			$hookmanager->initHooks(array('societedao'));
2029
-			$parameters=array('id'=>$this->id);
2030
-			$reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
2029
+			$parameters = array('id'=>$this->id);
2030
+			$reshook = $hookmanager->executeHooks('getnomurltooltip', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
2031 2031
 			if ($reshook > 0) $linkclose = $hookmanager->resPrint;
2032 2032
 		}
2033
-		$linkstart.=$linkclose.'>';
2034
-		$linkend='</a>';
2033
+		$linkstart .= $linkclose.'>';
2034
+		$linkend = '</a>';
2035 2035
 
2036 2036
 		global $user;
2037
-		if (! $user->rights->societe->client->voir && $user->societe_id > 0 && $this->id != $user->societe_id)
2037
+		if (!$user->rights->societe->client->voir && $user->societe_id > 0 && $this->id != $user->societe_id)
2038 2038
 		{
2039
-			$linkstart='';
2040
-			$linkend='';
2039
+			$linkstart = '';
2040
+			$linkend = '';
2041 2041
 		}
2042 2042
 
2043
-		$result.=$linkstart;
2044
-		if ($withpicto) $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip valigntextbottom"'), 0, 0, $notooltip?0:1);
2045
-		if ($withpicto != 2) $result.=($maxlen?dol_trunc($name,$maxlen):$name);
2046
-		$result.=$linkend;
2043
+		$result .= $linkstart;
2044
+		if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip valigntextbottom"'), 0, 0, $notooltip ? 0 : 1);
2045
+		if ($withpicto != 2) $result .= ($maxlen ?dol_trunc($name, $maxlen) : $name);
2046
+		$result .= $linkend;
2047 2047
 
2048 2048
 		return $result;
2049 2049
 	}
@@ -2054,9 +2054,9 @@  discard block
 block discarded – undo
2054 2054
 	 *    @param	int		$mode       0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
2055 2055
 	 *    @return   string        		Libelle
2056 2056
 	 */
2057
-	function getLibStatut($mode=0)
2057
+	function getLibStatut($mode = 0)
2058 2058
 	{
2059
-		return $this->LibStatut($this->status,$mode);
2059
+		return $this->LibStatut($this->status, $mode);
2060 2060
 	}
2061 2061
 
2062 2062
 	/**
@@ -2066,45 +2066,45 @@  discard block
 block discarded – undo
2066 2066
 	 *  @param	int		$mode           0=Long label, 1=Short label, 2=Picto + Short label, 3=Picto, 4=Picto + Long label, 5=Short label + Picto, 6=Long label + Picto
2067 2067
 	 *  @return	string          		Libelle du statut
2068 2068
 	 */
2069
-	function LibStatut($statut,$mode=0)
2069
+	function LibStatut($statut, $mode = 0)
2070 2070
 	{
2071 2071
 		global $langs;
2072 2072
 		$langs->load('companies');
2073 2073
 
2074 2074
 		if ($mode == 0)
2075 2075
 		{
2076
-			if ($statut==0) return $langs->trans("ActivityCeased");
2077
-			if ($statut==1) return $langs->trans("InActivity");
2076
+			if ($statut == 0) return $langs->trans("ActivityCeased");
2077
+			if ($statut == 1) return $langs->trans("InActivity");
2078 2078
 		}
2079 2079
 		if ($mode == 1)
2080 2080
 		{
2081
-			if ($statut==0) return $langs->trans("ActivityCeased");
2082
-			if ($statut==1) return $langs->trans("InActivity");
2081
+			if ($statut == 0) return $langs->trans("ActivityCeased");
2082
+			if ($statut == 1) return $langs->trans("InActivity");
2083 2083
 		}
2084 2084
 		if ($mode == 2)
2085 2085
 		{
2086
-			if ($statut==0) return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"').' '.$langs->trans("ActivityCeased");
2087
-			if ($statut==1) return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"').' '.$langs->trans("InActivity");
2086
+			if ($statut == 0) return img_picto($langs->trans("ActivityCeased"), 'statut5', 'class="pictostatus"').' '.$langs->trans("ActivityCeased");
2087
+			if ($statut == 1) return img_picto($langs->trans("InActivity"), 'statut4', 'class="pictostatus"').' '.$langs->trans("InActivity");
2088 2088
 		}
2089 2089
 		if ($mode == 3)
2090 2090
 		{
2091
-			if ($statut==0) return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"');
2092
-			if ($statut==1) return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"');
2091
+			if ($statut == 0) return img_picto($langs->trans("ActivityCeased"), 'statut5', 'class="pictostatus"');
2092
+			if ($statut == 1) return img_picto($langs->trans("InActivity"), 'statut4', 'class="pictostatus"');
2093 2093
 		}
2094 2094
 		if ($mode == 4)
2095 2095
 		{
2096
-			if ($statut==0) return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"').' '.$langs->trans("ActivityCeased");
2097
-			if ($statut==1) return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"').' '.$langs->trans("InActivity");
2096
+			if ($statut == 0) return img_picto($langs->trans("ActivityCeased"), 'statut5', 'class="pictostatus"').' '.$langs->trans("ActivityCeased");
2097
+			if ($statut == 1) return img_picto($langs->trans("InActivity"), 'statut4', 'class="pictostatus"').' '.$langs->trans("InActivity");
2098 2098
 		}
2099 2099
 		if ($mode == 5)
2100 2100
 		{
2101
-			if ($statut==0) return '<span class="hideonsmartphone">'.$langs->trans("ActivityCeased").'</span> '.img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"');
2102
-			if ($statut==1) return '<span class="hideonsmartphone">'.$langs->trans("InActivity").'</span> '.img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"');
2101
+			if ($statut == 0) return '<span class="hideonsmartphone">'.$langs->trans("ActivityCeased").'</span> '.img_picto($langs->trans("ActivityCeased"), 'statut5', 'class="pictostatus"');
2102
+			if ($statut == 1) return '<span class="hideonsmartphone">'.$langs->trans("InActivity").'</span> '.img_picto($langs->trans("InActivity"), 'statut4', 'class="pictostatus"');
2103 2103
 		}
2104 2104
 		if ($mode == 6)
2105 2105
 		{
2106
-			if ($statut==0) return '<span class="hideonsmartphone">'.$langs->trans("ActivityCeased").'</span> '.img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"');
2107
-			if ($statut==1) return '<span class="hideonsmartphone">'.$langs->trans("InActivity").'</span> '.img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"');
2106
+			if ($statut == 0) return '<span class="hideonsmartphone">'.$langs->trans("ActivityCeased").'</span> '.img_picto($langs->trans("ActivityCeased"), 'statut5', 'class="pictostatus"');
2107
+			if ($statut == 1) return '<span class="hideonsmartphone">'.$langs->trans("InActivity").'</span> '.img_picto($langs->trans("InActivity"), 'statut4', 'class="pictostatus"');
2108 2108
 		}
2109 2109
 	}
2110 2110
 
@@ -2114,15 +2114,15 @@  discard block
 block discarded – undo
2114 2114
 	 *	  @param	  int		$addthirdparty		1=Add also a record for thirdparty email
2115 2115
 	 *    @return     array       					Array of contacts emails
2116 2116
 	 */
2117
-	function thirdparty_and_contact_email_array($addthirdparty=0)
2117
+	function thirdparty_and_contact_email_array($addthirdparty = 0)
2118 2118
 	{
2119 2119
 		global $langs;
2120 2120
 
2121
-		$contact_emails = $this->contact_property_array('email',1);
2121
+		$contact_emails = $this->contact_property_array('email', 1);
2122 2122
 		if ($this->email && $addthirdparty)
2123 2123
 		{
2124
-			if (empty($this->name)) $this->name=$this->nom;
2125
-			$contact_emails['thirdparty']=$langs->transnoentitiesnoconv("ThirdParty").': '.dol_trunc($this->name,16)." <".$this->email.">";
2124
+			if (empty($this->name)) $this->name = $this->nom;
2125
+			$contact_emails['thirdparty'] = $langs->transnoentitiesnoconv("ThirdParty").': '.dol_trunc($this->name, 16)." <".$this->email.">";
2126 2126
 		}
2127 2127
 		//var_dump($contact_emails)
2128 2128
 		return $contact_emails;
@@ -2139,11 +2139,11 @@  discard block
 block discarded – undo
2139 2139
 
2140 2140
 		$contact_phone = $this->contact_property_array('mobile');
2141 2141
 
2142
-		if (! empty($this->phone))	// If a phone of thirdparty is defined, we add it ot mobile of contacts
2142
+		if (!empty($this->phone))	// If a phone of thirdparty is defined, we add it ot mobile of contacts
2143 2143
 		{
2144
-			if (empty($this->name)) $this->name=$this->nom;
2144
+			if (empty($this->name)) $this->name = $this->nom;
2145 2145
 			// TODO: Tester si tel non deja present dans tableau contact
2146
-			$contact_phone['thirdparty']=$langs->transnoentitiesnoconv("ThirdParty").': '.dol_trunc($this->name,16)." <".$this->phone.">";
2146
+			$contact_phone['thirdparty'] = $langs->transnoentitiesnoconv("ThirdParty").': '.dol_trunc($this->name, 16)." <".$this->phone.">";
2147 2147
 		}
2148 2148
 		return $contact_phone;
2149 2149
 	}
@@ -2155,7 +2155,7 @@  discard block
 block discarded – undo
2155 2155
 	 * 	@param	int		$hidedisabled		1=Hide contact if disabled
2156 2156
 	 *  @return array       				Array of contacts emails or mobile. Example: array(id=>'Name <email>')
2157 2157
 	 */
2158
-	function contact_property_array($mode='email', $hidedisabled=0)
2158
+	function contact_property_array($mode = 'email', $hidedisabled = 0)
2159 2159
 	{
2160 2160
 		global $langs;
2161 2161
 
@@ -2163,45 +2163,45 @@  discard block
 block discarded – undo
2163 2163
 
2164 2164
 
2165 2165
 		$sql = "SELECT rowid, email, statut, phone_mobile, lastname, poste, firstname";
2166
-		$sql.= " FROM ".MAIN_DB_PREFIX."socpeople";
2167
-		$sql.= " WHERE fk_soc = ".$this->id;
2166
+		$sql .= " FROM ".MAIN_DB_PREFIX."socpeople";
2167
+		$sql .= " WHERE fk_soc = ".$this->id;
2168 2168
 
2169
-		$resql=$this->db->query($sql);
2169
+		$resql = $this->db->query($sql);
2170 2170
 		if ($resql)
2171 2171
 		{
2172 2172
 			$nump = $this->db->num_rows($resql);
2173 2173
 			if ($nump)
2174 2174
 			{
2175
-				$sepa="("; $sepb=")";
2175
+				$sepa = "("; $sepb = ")";
2176 2176
 				if ($mode == 'email')
2177 2177
 				{
2178 2178
 					//$sepa="&lt;"; $sepb="&gt;";
2179
-					$sepa="<"; $sepb=">";
2179
+					$sepa = "<"; $sepb = ">";
2180 2180
 				}
2181 2181
 				$i = 0;
2182 2182
 				while ($i < $nump)
2183 2183
 				{
2184 2184
 					$obj = $this->db->fetch_object($resql);
2185
-					if ($mode == 'email') $property=$obj->email;
2186
-					else if ($mode == 'mobile') $property=$obj->phone_mobile;
2187
-					else $property=$obj->$mode;
2185
+					if ($mode == 'email') $property = $obj->email;
2186
+					else if ($mode == 'mobile') $property = $obj->phone_mobile;
2187
+					else $property = $obj->$mode;
2188 2188
 
2189 2189
 					// Show all contact. If hidedisabled is 1, showonly contacts with status = 1
2190 2190
 					if ($obj->statut == 1 || empty($hidedisabled))
2191 2191
 					{
2192 2192
 						if (empty($property))
2193 2193
 						{
2194
-							if ($mode == 'email') $property=$langs->transnoentitiesnoconv("NoEMail");
2195
-							else if ($mode == 'mobile') $property=$langs->transnoentitiesnoconv("NoMobilePhone");
2194
+							if ($mode == 'email') $property = $langs->transnoentitiesnoconv("NoEMail");
2195
+							else if ($mode == 'mobile') $property = $langs->transnoentitiesnoconv("NoMobilePhone");
2196 2196
 						}
2197 2197
 
2198 2198
 						if (!empty($obj->poste))
2199 2199
 						{
2200
-							$contact_property[$obj->rowid] = trim(dolGetFirstLastname($obj->firstname,$obj->lastname)).($obj->poste?" - ".$obj->poste:"").(($mode != 'poste' && $property)?" ".$sepa.$property.$sepb:'');
2200
+							$contact_property[$obj->rowid] = trim(dolGetFirstLastname($obj->firstname, $obj->lastname)).($obj->poste ? " - ".$obj->poste : "").(($mode != 'poste' && $property) ? " ".$sepa.$property.$sepb : '');
2201 2201
 						}
2202 2202
 						else
2203 2203
 						{
2204
-							$contact_property[$obj->rowid] = trim(dolGetFirstLastname($obj->firstname,$obj->lastname)).(($mode != 'poste' && $property)?" ".$sepa.$property.$sepb:'');
2204
+							$contact_property[$obj->rowid] = trim(dolGetFirstLastname($obj->firstname, $obj->lastname)).(($mode != 'poste' && $property) ? " ".$sepa.$property.$sepb : '');
2205 2205
 						}
2206 2206
 					}
2207 2207
 					$i++;
@@ -2226,7 +2226,7 @@  discard block
 block discarded – undo
2226 2226
 		$contacts = array();
2227 2227
 
2228 2228
 		$sql = "SELECT rowid, lastname, firstname FROM ".MAIN_DB_PREFIX."socpeople WHERE fk_soc = ".$this->id;
2229
-		$resql=$this->db->query($sql);
2229
+		$resql = $this->db->query($sql);
2230 2230
 		if ($resql)
2231 2231
 		{
2232 2232
 			$nump = $this->db->num_rows($resql);
@@ -2236,7 +2236,7 @@  discard block
 block discarded – undo
2236 2236
 				while ($i < $nump)
2237 2237
 				{
2238 2238
 					$obj = $this->db->fetch_object($resql);
2239
-					$contacts[$obj->rowid] = dolGetFirstLastname($obj->firstname,$obj->lastname);
2239
+					$contacts[$obj->rowid] = dolGetFirstLastname($obj->firstname, $obj->lastname);
2240 2240
 					$i++;
2241 2241
 				}
2242 2242
 			}
@@ -2255,11 +2255,11 @@  discard block
 block discarded – undo
2255 2255
 	 */
2256 2256
 	function contact_array_objects()
2257 2257
 	{
2258
-		require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';
2258
+		require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
2259 2259
 		$contacts = array();
2260 2260
 
2261 2261
 		$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."socpeople WHERE fk_soc = ".$this->id;
2262
-		$resql=$this->db->query($sql);
2262
+		$resql = $this->db->query($sql);
2263 2263
 		if ($resql)
2264 2264
 		{
2265 2265
 			$nump = $this->db->num_rows($resql);
@@ -2290,17 +2290,17 @@  discard block
 block discarded – undo
2290 2290
 	 *  @param  string	$mode       'email' or 'mobile'
2291 2291
 	 *  @return string  			Email of contact with format: "Full name <email>"
2292 2292
 	 */
2293
-	function contact_get_property($rowid,$mode)
2293
+	function contact_get_property($rowid, $mode)
2294 2294
 	{
2295
-		$contact_property='';
2295
+		$contact_property = '';
2296 2296
 
2297 2297
 		if (empty($rowid)) return '';
2298 2298
 
2299 2299
 		$sql = "SELECT rowid, email, phone_mobile, lastname, firstname";
2300
-		$sql.= " FROM ".MAIN_DB_PREFIX."socpeople";
2301
-		$sql.= " WHERE rowid = '".$rowid."'";
2300
+		$sql .= " FROM ".MAIN_DB_PREFIX."socpeople";
2301
+		$sql .= " WHERE rowid = '".$rowid."'";
2302 2302
 
2303
-		$resql=$this->db->query($sql);
2303
+		$resql = $this->db->query($sql);
2304 2304
 		if ($resql)
2305 2305
 		{
2306 2306
 			$nump = $this->db->num_rows($resql);
@@ -2328,12 +2328,12 @@  discard block
 block discarded – undo
2328 2328
 	 *	@param	string	$mode	'label' or 'rum' or 'format'
2329 2329
 	 *  @return	string			Bank number
2330 2330
 	 */
2331
-	function display_rib($mode='label')
2331
+	function display_rib($mode = 'label')
2332 2332
 	{
2333
-		require_once DOL_DOCUMENT_ROOT . '/societe/class/companybankaccount.class.php';
2333
+		require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
2334 2334
 
2335 2335
 		$bac = new CompanyBankAccount($this->db);
2336
-		$bac->fetch(0,$this->id);
2336
+		$bac->fetch(0, $this->id);
2337 2337
 
2338 2338
 		if ($mode == 'label')
2339 2339
 		{
@@ -2343,7 +2343,7 @@  discard block
 block discarded – undo
2343 2343
 		{
2344 2344
 			if (empty($bac->rum))
2345 2345
 			{
2346
-				require_once DOL_DOCUMENT_ROOT . '/compta/prelevement/class/bonprelevement.class.php';
2346
+				require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
2347 2347
 				$prelevement = new BonPrelevement($this->db);
2348 2348
 				$bac->fetch_thirdparty();
2349 2349
 				$bac->rum = $prelevement->buildRumNumber($bac->thirdparty->code_client, $bac->datec, $bac->id);
@@ -2365,7 +2365,7 @@  discard block
 block discarded – undo
2365 2365
 	 */
2366 2366
 	function get_all_rib()
2367 2367
 	{
2368
-		require_once DOL_DOCUMENT_ROOT . '/societe/class/companybankaccount.class.php';
2368
+		require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
2369 2369
 		$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_rib WHERE fk_soc = ".$this->id;
2370 2370
 		$result = $this->db->query($sql);
2371 2371
 		if (!$result) {
@@ -2394,22 +2394,22 @@  discard block
 block discarded – undo
2394 2394
 	 *	@param	int			$type		Should be 0 to say customer
2395 2395
 	 *  @return void
2396 2396
 	 */
2397
-	function get_codeclient($objsoc=0,$type=0)
2397
+	function get_codeclient($objsoc = 0, $type = 0)
2398 2398
 	{
2399 2399
 		global $conf;
2400
-		if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2400
+		if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2401 2401
 		{
2402
-			$module=$conf->global->SOCIETE_CODECLIENT_ADDON;
2402
+			$module = $conf->global->SOCIETE_CODECLIENT_ADDON;
2403 2403
 
2404
-			$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
2404
+			$dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
2405 2405
 			foreach ($dirsociete as $dirroot)
2406 2406
 			{
2407
-				$res=dol_include_once($dirroot.$module.'.php');
2407
+				$res = dol_include_once($dirroot.$module.'.php');
2408 2408
 				if ($res) break;
2409 2409
 			}
2410 2410
 			$mod = new $module();
2411 2411
 
2412
-			$this->code_client = $mod->getNextValue($objsoc,$type);
2412
+			$this->code_client = $mod->getNextValue($objsoc, $type);
2413 2413
 			$this->prefixCustomerIsRequired = $mod->prefixIsRequired;
2414 2414
 
2415 2415
 			dol_syslog(get_class($this)."::get_codeclient code_client=".$this->code_client." module=".$module);
@@ -2424,22 +2424,22 @@  discard block
 block discarded – undo
2424 2424
 	 *	@param	int			$type		Should be 1 to say supplier
2425 2425
 	 *  @return void
2426 2426
 	 */
2427
-	function get_codefournisseur($objsoc=0,$type=1)
2427
+	function get_codefournisseur($objsoc = 0, $type = 1)
2428 2428
 	{
2429 2429
 		global $conf;
2430
-		if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2430
+		if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2431 2431
 		{
2432
-			$module=$conf->global->SOCIETE_CODECLIENT_ADDON;
2432
+			$module = $conf->global->SOCIETE_CODECLIENT_ADDON;
2433 2433
 
2434
-			$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
2434
+			$dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
2435 2435
 			foreach ($dirsociete as $dirroot)
2436 2436
 			{
2437
-				$res=dol_include_once($dirroot.$module.'.php');
2437
+				$res = dol_include_once($dirroot.$module.'.php');
2438 2438
 				if ($res) break;
2439 2439
 			}
2440 2440
 			$mod = new $module();
2441 2441
 
2442
-			$this->code_fournisseur = $mod->getNextValue($objsoc,$type);
2442
+			$this->code_fournisseur = $mod->getNextValue($objsoc, $type);
2443 2443
 
2444 2444
 			dol_syslog(get_class($this)."::get_codefournisseur code_fournisseur=".$this->code_fournisseur." module=".$module);
2445 2445
 		}
@@ -2454,23 +2454,23 @@  discard block
 block discarded – undo
2454 2454
 	function codeclient_modifiable()
2455 2455
 	{
2456 2456
 		global $conf;
2457
-		if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2457
+		if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2458 2458
 		{
2459
-			$module=$conf->global->SOCIETE_CODECLIENT_ADDON;
2459
+			$module = $conf->global->SOCIETE_CODECLIENT_ADDON;
2460 2460
 
2461
-			$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
2461
+			$dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
2462 2462
 			foreach ($dirsociete as $dirroot)
2463 2463
 			{
2464
-				$res=dol_include_once($dirroot.$module.'.php');
2464
+				$res = dol_include_once($dirroot.$module.'.php');
2465 2465
 				if ($res) break;
2466 2466
 			}
2467 2467
 
2468 2468
 			$mod = new $module();
2469 2469
 
2470 2470
 			dol_syslog(get_class($this)."::codeclient_modifiable code_client=".$this->code_client." module=".$module);
2471
-			if ($mod->code_modifiable_null && ! $this->code_client) return 1;
2471
+			if ($mod->code_modifiable_null && !$this->code_client) return 1;
2472 2472
 			if ($mod->code_modifiable_invalide && $this->check_codeclient() < 0) return 1;
2473
-			if ($mod->code_modifiable) return 1;	// A mettre en dernier
2473
+			if ($mod->code_modifiable) return 1; // A mettre en dernier
2474 2474
 			return 0;
2475 2475
 		}
2476 2476
 		else
@@ -2488,23 +2488,23 @@  discard block
 block discarded – undo
2488 2488
 	function codefournisseur_modifiable()
2489 2489
 	{
2490 2490
 		global $conf;
2491
-		if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2491
+		if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2492 2492
 		{
2493
-			$module=$conf->global->SOCIETE_CODECLIENT_ADDON;
2493
+			$module = $conf->global->SOCIETE_CODECLIENT_ADDON;
2494 2494
 
2495
-			$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
2495
+			$dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
2496 2496
 			foreach ($dirsociete as $dirroot)
2497 2497
 			{
2498
-				$res=dol_include_once($dirroot.$module.'.php');
2498
+				$res = dol_include_once($dirroot.$module.'.php');
2499 2499
 				if ($res) break;
2500 2500
 			}
2501 2501
 
2502 2502
 			$mod = new $module();
2503 2503
 
2504 2504
 			dol_syslog(get_class($this)."::codefournisseur_modifiable code_founisseur=".$this->code_fournisseur." module=".$module);
2505
-			if ($mod->code_modifiable_null && ! $this->code_fournisseur) return 1;
2505
+			if ($mod->code_modifiable_null && !$this->code_fournisseur) return 1;
2506 2506
 			if ($mod->code_modifiable_invalide && $this->check_codefournisseur() < 0) return 1;
2507
-			if ($mod->code_modifiable) return 1;	// A mettre en dernier
2507
+			if ($mod->code_modifiable) return 1; // A mettre en dernier
2508 2508
 			return 0;
2509 2509
 		}
2510 2510
 		else
@@ -2526,14 +2526,14 @@  discard block
 block discarded – undo
2526 2526
 	function check_codeclient()
2527 2527
 	{
2528 2528
 		global $conf;
2529
-		if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2529
+		if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2530 2530
 		{
2531
-			$module=$conf->global->SOCIETE_CODECLIENT_ADDON;
2531
+			$module = $conf->global->SOCIETE_CODECLIENT_ADDON;
2532 2532
 
2533
-			$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
2533
+			$dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
2534 2534
 			foreach ($dirsociete as $dirroot)
2535 2535
 			{
2536
-				$res=dol_include_once($dirroot.$module.'.php');
2536
+				$res = dol_include_once($dirroot.$module.'.php');
2537 2537
 				if ($res) break;
2538 2538
 			}
2539 2539
 
@@ -2561,14 +2561,14 @@  discard block
 block discarded – undo
2561 2561
 	function check_codefournisseur()
2562 2562
 	{
2563 2563
 		global $conf;
2564
-		if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2564
+		if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2565 2565
 		{
2566
-			$module=$conf->global->SOCIETE_CODECLIENT_ADDON;
2566
+			$module = $conf->global->SOCIETE_CODECLIENT_ADDON;
2567 2567
 
2568
-			$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
2568
+			$dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
2569 2569
 			foreach ($dirsociete as $dirroot)
2570 2570
 			{
2571
-				$res=dol_include_once($dirroot.$module.'.php');
2571
+				$res = dol_include_once($dirroot.$module.'.php');
2572 2572
 				if ($res) break;
2573 2573
 			}
2574 2574
 
@@ -2596,20 +2596,20 @@  discard block
 block discarded – undo
2596 2596
 	{
2597 2597
 		global $conf;
2598 2598
 
2599
-		if (! empty($conf->global->SOCIETE_CODECOMPTA_ADDON))
2599
+		if (!empty($conf->global->SOCIETE_CODECOMPTA_ADDON))
2600 2600
 		{
2601
-			$file='';
2602
-			$dirsociete=array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
2601
+			$file = '';
2602
+			$dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
2603 2603
 			foreach ($dirsociete as $dirroot)
2604 2604
 			{
2605 2605
 				if (file_exists(DOL_DOCUMENT_ROOT.'/'.$dirroot.$conf->global->SOCIETE_CODECOMPTA_ADDON.".php"))
2606 2606
 				{
2607
-					$file=$dirroot.$conf->global->SOCIETE_CODECOMPTA_ADDON.".php";
2607
+					$file = $dirroot.$conf->global->SOCIETE_CODECOMPTA_ADDON.".php";
2608 2608
 					break;
2609 2609
 				}
2610 2610
 			}
2611 2611
 
2612
-			if (! empty($file))
2612
+			if (!empty($file))
2613 2613
 			{
2614 2614
 				dol_include_once($file);
2615 2615
 
@@ -2650,10 +2650,10 @@  discard block
 block discarded – undo
2650 2650
 		if ($this->id)
2651 2651
 		{
2652 2652
 			$sql = "UPDATE ".MAIN_DB_PREFIX."societe";
2653
-			$sql.= " SET parent = ".($id > 0 ? $id : "null");
2654
-			$sql.= " WHERE rowid = " . $this->id;
2653
+			$sql .= " SET parent = ".($id > 0 ? $id : "null");
2654
+			$sql .= " WHERE rowid = ".$this->id;
2655 2655
 			dol_syslog(get_class($this).'::set_parent', LOG_DEBUG);
2656
-			$resql=$this->db->query($sql);
2656
+			$resql = $this->db->query($sql);
2657 2657
 			if ($resql)
2658 2658
 			{
2659 2659
 				$this->parent = $id;
@@ -2677,28 +2677,28 @@  discard block
 block discarded – undo
2677 2677
 	{
2678 2678
 		global $conf;
2679 2679
 
2680
-	 	switch($idprof)
2680
+	 	switch ($idprof)
2681 2681
 		{
2682 2682
 			case 1:
2683
-				$ret=(!$conf->global->SOCIETE_IDPROF1_UNIQUE?false:true);
2683
+				$ret = (!$conf->global->SOCIETE_IDPROF1_UNIQUE ?false:true);
2684 2684
 				break;
2685 2685
 			case 2:
2686
-				$ret=(!$conf->global->SOCIETE_IDPROF2_UNIQUE?false:true);
2686
+				$ret = (!$conf->global->SOCIETE_IDPROF2_UNIQUE ?false:true);
2687 2687
 				break;
2688 2688
 			case 3:
2689
-				$ret=(!$conf->global->SOCIETE_IDPROF3_UNIQUE?false:true);
2689
+				$ret = (!$conf->global->SOCIETE_IDPROF3_UNIQUE ?false:true);
2690 2690
 				break;
2691 2691
 			case 4:
2692
-				$ret=(!$conf->global->SOCIETE_IDPROF4_UNIQUE?false:true);
2692
+				$ret = (!$conf->global->SOCIETE_IDPROF4_UNIQUE ?false:true);
2693 2693
 				break;
2694 2694
 			case 5:
2695
-				$ret=(!$conf->global->SOCIETE_IDPROF5_UNIQUE?false:true);
2695
+				$ret = (!$conf->global->SOCIETE_IDPROF5_UNIQUE ?false:true);
2696 2696
 				break;
2697 2697
 			case 6:
2698
-				$ret=(!$conf->global->SOCIETE_IDPROF6_UNIQUE?false:true);
2698
+				$ret = (!$conf->global->SOCIETE_IDPROF6_UNIQUE ?false:true);
2699 2699
 				break;
2700 2700
 			default:
2701
-				$ret=false;
2701
+				$ret = false;
2702 2702
 		}
2703 2703
 
2704 2704
 		return $ret;
@@ -2712,39 +2712,39 @@  discard block
 block discarded – undo
2712 2712
 	 *    @param	int		$socid		Id of thirdparty to exclude (if update)
2713 2713
 	 *    @return   boolean				True if exists, False if not
2714 2714
 	 */
2715
-	function id_prof_exists($idprof, $value, $socid=0)
2715
+	function id_prof_exists($idprof, $value, $socid = 0)
2716 2716
 	{
2717 2717
 		$field = $idprof;
2718 2718
 
2719
-	 	switch($idprof)	// For backward compatibility
2719
+	 	switch ($idprof)	// For backward compatibility
2720 2720
 		{
2721 2721
 			case '1':
2722 2722
 			case 'idprof1':
2723
-				$field="siren";
2723
+				$field = "siren";
2724 2724
 				break;
2725 2725
 			case '2':
2726 2726
 			case 'idprof2':
2727
-				$field="siret";
2727
+				$field = "siret";
2728 2728
 				break;
2729 2729
 			case '3':
2730 2730
 			case 'idprof3':
2731
-				$field="ape";
2731
+				$field = "ape";
2732 2732
 				break;
2733 2733
 			case '4':
2734 2734
 			case 'idprof4':
2735
-				$field="idprof4";
2735
+				$field = "idprof4";
2736 2736
 				break;
2737 2737
 			case '5':
2738
-				$field="idprof5";
2738
+				$field = "idprof5";
2739 2739
 				break;
2740 2740
 			case '6':
2741
-				$field="idprof6";
2741
+				$field = "idprof6";
2742 2742
 				break;
2743 2743
 	 	}
2744 2744
 
2745 2745
 		 //Verify duplicate entries
2746
-		$sql  = "SELECT COUNT(*) as idprof FROM ".MAIN_DB_PREFIX."societe WHERE ".$field." = '".$value."' AND entity IN (".getEntity('societe').")";
2747
-		if($socid) $sql .= " AND rowid <> ".$socid;
2746
+		$sql = "SELECT COUNT(*) as idprof FROM ".MAIN_DB_PREFIX."societe WHERE ".$field." = '".$value."' AND entity IN (".getEntity('societe').")";
2747
+		if ($socid) $sql .= " AND rowid <> ".$socid;
2748 2748
 		$resql = $this->db->query($sql);
2749 2749
 		if ($resql)
2750 2750
 		{
@@ -2770,36 +2770,36 @@  discard block
 block discarded – undo
2770 2770
 	 *  @return int             			<=0 if KO, >0 if OK
2771 2771
 	 *  TODO better to have this in a lib than into a business class
2772 2772
 	 */
2773
-	function id_prof_check($idprof,$soc)
2773
+	function id_prof_check($idprof, $soc)
2774 2774
 	{
2775 2775
 		global $conf;
2776 2776
 
2777
-		$ok=1;
2777
+		$ok = 1;
2778 2778
 
2779
-		if (! empty($conf->global->MAIN_DISABLEPROFIDRULES)) return 1;
2779
+		if (!empty($conf->global->MAIN_DISABLEPROFIDRULES)) return 1;
2780 2780
 
2781 2781
 		// Verifie SIREN si pays FR
2782 2782
 		if ($idprof == 1 && $soc->country_code == 'FR')
2783 2783
 		{
2784
-			$chaine=trim($this->idprof1);
2785
-			$chaine=preg_replace('/(\s)/','',$chaine);
2784
+			$chaine = trim($this->idprof1);
2785
+			$chaine = preg_replace('/(\s)/', '', $chaine);
2786 2786
 
2787 2787
 			if (dol_strlen($chaine) != 9) return -1;
2788 2788
 
2789 2789
 			$sum = 0;
2790 2790
 
2791
-			for ($i = 0 ; $i < 10 ; $i = $i+2)
2791
+			for ($i = 0; $i < 10; $i = $i + 2)
2792 2792
 			{
2793 2793
 				$sum = $sum + substr($this->idprof1, (8 - $i), 1);
2794 2794
 			}
2795 2795
 
2796
-			for ($i = 1 ; $i < 9 ; $i = $i+2)
2796
+			for ($i = 1; $i < 9; $i = $i + 2)
2797 2797
 			{
2798 2798
 				$ps = 2 * substr($this->idprof1, (8 - $i), 1);
2799 2799
 
2800 2800
 				if ($ps > 9)
2801 2801
 				{
2802
-					$ps = substr($ps, 0,1) + substr($ps, 1, 1);
2802
+					$ps = substr($ps, 0, 1) + substr($ps, 1, 1);
2803 2803
 				}
2804 2804
 				$sum = $sum + $ps;
2805 2805
 			}
@@ -2810,8 +2810,8 @@  discard block
 block discarded – undo
2810 2810
 		// Verifie SIRET si pays FR
2811 2811
 		if ($idprof == 2 && $soc->country_code == 'FR')
2812 2812
 		{
2813
-			$chaine=trim($this->idprof2);
2814
-			$chaine=preg_replace('/(\s)/','',$chaine);
2813
+			$chaine = trim($this->idprof2);
2814
+			$chaine = preg_replace('/(\s)/', '', $chaine);
2815 2815
 
2816 2816
 			if (dol_strlen($chaine) != 14) return -1;
2817 2817
 		}
@@ -2820,11 +2820,11 @@  discard block
 block discarded – undo
2820 2820
 		//Returns: 1 if NIF ok, 2 if CIF ok, 3 if NIE ok, -1 if NIF bad, -2 if CIF bad, -3 if NIE bad, 0 if unexpected bad
2821 2821
 		if ($idprof == 1 && $soc->country_code == 'ES')
2822 2822
 		{
2823
-			$string=trim($this->idprof1);
2824
-			$string=preg_replace('/(\s)/','',$string);
2823
+			$string = trim($this->idprof1);
2824
+			$string = preg_replace('/(\s)/', '', $string);
2825 2825
 			$string = strtoupper($string);
2826 2826
 
2827
-			for ($i = 0; $i < 9; $i ++)
2827
+			for ($i = 0; $i < 9; $i++)
2828 2828
 			$num[$i] = substr($string, $i, 1);
2829 2829
 
2830 2830
 			//Check format
@@ -2841,7 +2841,7 @@  discard block
 block discarded – undo
2841 2841
 			//algorithm checking type code CIF
2842 2842
 			$sum = $num[2] + $num[4] + $num[6];
2843 2843
 			for ($i = 1; $i < 8; $i += 2)
2844
-			$sum += substr((2 * $num[$i]),0,1) + substr((2 * $num[$i]),1,1);
2844
+			$sum += substr((2 * $num[$i]), 0, 1) + substr((2 * $num[$i]), 1, 1);
2845 2845
 			$n = 10 - substr($sum, strlen($sum) - 1, 1);
2846 2846
 
2847 2847
 			//Chek special NIF
@@ -2867,7 +2867,7 @@  discard block
 block discarded – undo
2867 2867
 
2868 2868
 			//Check NIE XYZ
2869 2869
 			if (preg_match('/^[XYZ]{1}/', $string))
2870
-			if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr(str_replace(array('X','Y','Z'), array('0','1','2'), $string), 0, 8) % 23, 1))
2870
+			if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr(str_replace(array('X', 'Y', 'Z'), array('0', '1', '2'), $string), 0, 8) % 23, 1))
2871 2871
 			return 3;
2872 2872
 			else
2873 2873
 			return -3;
@@ -2887,25 +2887,25 @@  discard block
 block discarded – undo
2887 2887
 	 *   @return	string          		Url or empty string if no URL known
2888 2888
 	 *   TODO better in a lib than into business class
2889 2889
 	 */
2890
-	function id_prof_url($idprof,$thirdparty)
2890
+	function id_prof_url($idprof, $thirdparty)
2891 2891
 	{
2892
-		global $conf,$langs,$hookmanager;
2892
+		global $conf, $langs, $hookmanager;
2893 2893
 
2894
-		$url='';
2894
+		$url = '';
2895 2895
 		$action = '';
2896 2896
 
2897 2897
 		$hookmanager->initHooks(array('idprofurl'));
2898
-		$parameters=array('idprof'=>$idprof, 'company'=>$thirdparty);
2899
-		$reshook=$hookmanager->executeHooks('getIdProfUrl',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
2898
+		$parameters = array('idprof'=>$idprof, 'company'=>$thirdparty);
2899
+		$reshook = $hookmanager->executeHooks('getIdProfUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
2900 2900
 		if (empty($reshook))
2901 2901
 		{
2902
-			if (! empty($conf->global->MAIN_DISABLEPROFIDRULES)) return '';
2902
+			if (!empty($conf->global->MAIN_DISABLEPROFIDRULES)) return '';
2903 2903
 
2904 2904
 			// TODO Move links to validate professional ID into a dictionary table "country" + "link"
2905
-			if ($idprof == 1 && $thirdparty->country_code == 'FR') $url='http://www.societe.com/cgi-bin/search?champs='.$thirdparty->idprof1;    // See also http://avis-situation-sirene.insee.fr/
2905
+			if ($idprof == 1 && $thirdparty->country_code == 'FR') $url = 'http://www.societe.com/cgi-bin/search?champs='.$thirdparty->idprof1; // See also http://avis-situation-sirene.insee.fr/
2906 2906
 			//if ($idprof == 1 && ($thirdparty->country_code == 'GB' || $thirdparty->country_code == 'UK')) $url='http://www.companieshouse.gov.uk/WebCHeck/findinfolink/';     // Link no more valid
2907
-			if ($idprof == 1 && $thirdparty->country_code == 'ES') $url='http://www.e-informa.es/servlet/app/portal/ENTP/screen/SProducto/prod/ETIQUETA_EMPRESA/nif/'.$thirdparty->idprof1;
2908
-			if ($idprof == 1 && $thirdparty->country_code == 'IN') $url='http://www.tinxsys.com/TinxsysInternetWeb/dealerControllerServlet?tinNumber='.$thirdparty->idprof1.';&searchBy=TIN&backPage=searchByTin_Inter.jsp';
2907
+			if ($idprof == 1 && $thirdparty->country_code == 'ES') $url = 'http://www.e-informa.es/servlet/app/portal/ENTP/screen/SProducto/prod/ETIQUETA_EMPRESA/nif/'.$thirdparty->idprof1;
2908
+			if ($idprof == 1 && $thirdparty->country_code == 'IN') $url = 'http://www.tinxsys.com/TinxsysInternetWeb/dealerControllerServlet?tinNumber='.$thirdparty->idprof1.';&searchBy=TIN&backPage=searchByTin_Inter.jsp';
2909 2909
 
2910 2910
 			if ($url) return '<a target="_blank" href="'.$url.'">'.$langs->trans("Check").'</a>';
2911 2911
 		}
@@ -2924,7 +2924,7 @@  discard block
 block discarded – undo
2924 2924
 	 */
2925 2925
 	function has_projects()
2926 2926
 	{
2927
-		$sql = 'SELECT COUNT(*) as numproj FROM '.MAIN_DB_PREFIX.'projet WHERE fk_soc = ' . $this->id;
2927
+		$sql = 'SELECT COUNT(*) as numproj FROM '.MAIN_DB_PREFIX.'projet WHERE fk_soc = '.$this->id;
2928 2928
 		$resql = $this->db->query($sql);
2929 2929
 		if ($resql)
2930 2930
 		{
@@ -2950,11 +2950,11 @@  discard block
 block discarded – undo
2950 2950
 	function info($id)
2951 2951
 	{
2952 2952
 		$sql = "SELECT s.rowid, s.nom as name, s.datec as date_creation, tms as date_modification,";
2953
-		$sql.= " fk_user_creat, fk_user_modif";
2954
-		$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
2955
-		$sql.= " WHERE s.rowid = ".$id;
2953
+		$sql .= " fk_user_creat, fk_user_modif";
2954
+		$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
2955
+		$sql .= " WHERE s.rowid = ".$id;
2956 2956
 
2957
-		$result=$this->db->query($sql);
2957
+		$result = $this->db->query($sql);
2958 2958
 		if ($result)
2959 2959
 		{
2960 2960
 			if ($this->db->num_rows($result))
@@ -2966,7 +2966,7 @@  discard block
 block discarded – undo
2966 2966
 				if ($obj->fk_user_creat) {
2967 2967
 					$cuser = new User($this->db);
2968 2968
 					$cuser->fetch($obj->fk_user_creat);
2969
-					$this->user_creation     = $cuser;
2969
+					$this->user_creation = $cuser;
2970 2970
 				}
2971 2971
 
2972 2972
 				if ($obj->fk_user_modif) {
@@ -2975,7 +2975,7 @@  discard block
 block discarded – undo
2975 2975
 					$this->user_modification = $muser;
2976 2976
 				}
2977 2977
 
2978
-				$this->ref			     = $obj->name;
2978
+				$this->ref = $obj->name;
2979 2979
 				$this->date_creation     = $this->db->jdate($obj->date_creation);
2980 2980
 				$this->date_modification = $this->db->jdate($obj->date_modification);
2981 2981
 			}
@@ -2999,10 +2999,10 @@  discard block
 block discarded – undo
2999 2999
 		global $conf;
3000 3000
 
3001 3001
 		// Define if third party is treated as company (or not) when nature is unknown
3002
-		$isacompany=empty($conf->global->MAIN_UNKNOWN_CUSTOMERS_ARE_COMPANIES)?0:1; // 0 by default
3003
-		if (! empty($this->tva_intra)) $isacompany=1;
3004
-		else if (! empty($this->typent_code) && in_array($this->typent_code,array('TE_PRIVATE'))) $isacompany=0;
3005
-		else if (! empty($this->typent_code) && in_array($this->typent_code,array('TE_SMALL','TE_MEDIUM','TE_LARGE','TE_GROUP'))) $isacompany=1;
3002
+		$isacompany = empty($conf->global->MAIN_UNKNOWN_CUSTOMERS_ARE_COMPANIES) ? 0 : 1; // 0 by default
3003
+		if (!empty($this->tva_intra)) $isacompany = 1;
3004
+		else if (!empty($this->typent_code) && in_array($this->typent_code, array('TE_PRIVATE'))) $isacompany = 0;
3005
+		else if (!empty($this->typent_code) && in_array($this->typent_code, array('TE_SMALL', 'TE_MEDIUM', 'TE_LARGE', 'TE_GROUP'))) $isacompany = 1;
3006 3006
 
3007 3007
 		return $isacompany;
3008 3008
 	}
@@ -3016,13 +3016,13 @@  discard block
 block discarded – undo
3016 3016
 	{
3017 3017
 		$this->SupplierCategories = array();
3018 3018
 		$sql = "SELECT rowid, label";
3019
-		$sql.= " FROM ".MAIN_DB_PREFIX."categorie";
3020
-		$sql.= " WHERE type = ".Categorie::TYPE_SUPPLIER;
3019
+		$sql .= " FROM ".MAIN_DB_PREFIX."categorie";
3020
+		$sql .= " WHERE type = ".Categorie::TYPE_SUPPLIER;
3021 3021
 
3022
-		$resql=$this->db->query($sql);
3022
+		$resql = $this->db->query($sql);
3023 3023
 		if ($resql)
3024 3024
 		{
3025
-			while ($obj = $this->db->fetch_object($resql) )
3025
+			while ($obj = $this->db->fetch_object($resql))
3026 3026
 			{
3027 3027
 				$this->SupplierCategories[$obj->rowid] = $obj->label;
3028 3028
 			}
@@ -3045,9 +3045,9 @@  discard block
 block discarded – undo
3045 3045
 		if ($categorie_id > 0 && $this->id > 0)
3046 3046
 		{
3047 3047
 			$sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie_fournisseur (fk_categorie, fk_soc) ";
3048
-			$sql.= " VALUES (".$categorie_id.", ".$this->id.")";
3048
+			$sql .= " VALUES (".$categorie_id.", ".$this->id.")";
3049 3049
 
3050
-			if ($resql=$this->db->query($sql)) return 0;
3050
+			if ($resql = $this->db->query($sql)) return 0;
3051 3051
 		}
3052 3052
 		else
3053 3053
 		{
@@ -3065,44 +3065,44 @@  discard block
 block discarded – undo
3065 3065
 	 *	@param	string	$socalias	Alias name of third party to force
3066 3066
 	 *  @return int					<0 if KO, id of created account if OK
3067 3067
 	 */
3068
-	function create_from_member(Adherent $member, $socname='', $socalias='')
3068
+	function create_from_member(Adherent $member, $socname = '', $socalias = '')
3069 3069
 	{
3070
-		global $user,$langs;
3070
+		global $user, $langs;
3071 3071
 
3072
-		$name = $socname?$socname:$member->societe;
3073
-		if (empty($name)) $name=$member->getFullName($langs);
3072
+		$name = $socname ? $socname : $member->societe;
3073
+		if (empty($name)) $name = $member->getFullName($langs);
3074 3074
 
3075
-		$alias = $socalias?$socalias:'';
3075
+		$alias = $socalias ? $socalias : '';
3076 3076
 
3077 3077
 		// Positionne parametres
3078
-		$this->nom=$name;				// TODO deprecated
3079
-		$this->name=$name;
3080
-		$this->name_alias=$alias;
3081
-		$this->address=$member->address;
3082
-		$this->zip=$member->zip;
3083
-		$this->town=$member->town;
3084
-		$this->country_code=$member->country_code;
3085
-		$this->country_id=$member->country_id;
3086
-		$this->phone=$member->phone;       // Prof phone
3087
-		$this->email=$member->email;
3088
-		$this->skype=$member->skype;
3089
-
3090
-		$this->client = 1;				// A member is a customer by default
3078
+		$this->nom = $name; // TODO deprecated
3079
+		$this->name = $name;
3080
+		$this->name_alias = $alias;
3081
+		$this->address = $member->address;
3082
+		$this->zip = $member->zip;
3083
+		$this->town = $member->town;
3084
+		$this->country_code = $member->country_code;
3085
+		$this->country_id = $member->country_id;
3086
+		$this->phone = $member->phone; // Prof phone
3087
+		$this->email = $member->email;
3088
+		$this->skype = $member->skype;
3089
+
3090
+		$this->client = 1; // A member is a customer by default
3091 3091
 		$this->code_client = -1;
3092 3092
 		$this->code_fournisseur = -1;
3093 3093
 
3094 3094
 		$this->db->begin();
3095 3095
 
3096 3096
 		// Cree et positionne $this->id
3097
-		$result=$this->create($user);
3097
+		$result = $this->create($user);
3098 3098
 		if ($result >= 0)
3099 3099
 		{
3100 3100
 			$sql = "UPDATE ".MAIN_DB_PREFIX."adherent";
3101
-			$sql.= " SET fk_soc=".$this->id;
3102
-			$sql.= " WHERE rowid=".$member->id;
3101
+			$sql .= " SET fk_soc=".$this->id;
3102
+			$sql .= " WHERE rowid=".$member->id;
3103 3103
 
3104 3104
 			dol_syslog(get_class($this)."::create_from_member", LOG_DEBUG);
3105
-			$resql=$this->db->query($sql);
3105
+			$resql = $this->db->query($sql);
3106 3106
 			if ($resql)
3107 3107
 			{
3108 3108
 				$this->db->commit();
@@ -3110,7 +3110,7 @@  discard block
 block discarded – undo
3110 3110
 			}
3111 3111
 			else
3112 3112
 			{
3113
-				$this->error=$this->db->error();
3113
+				$this->error = $this->db->error();
3114 3114
 
3115 3115
 				$this->db->rollback();
3116 3116
 				return -1;
@@ -3119,7 +3119,7 @@  discard block
 block discarded – undo
3119 3119
 		else
3120 3120
 		{
3121 3121
 			// $this->error deja positionne
3122
-			dol_syslog(get_class($this)."::create_from_member - 2 - ".$this->error." - ".join(',',$this->errors), LOG_ERR);
3122
+			dol_syslog(get_class($this)."::create_from_member - 2 - ".$this->error." - ".join(',', $this->errors), LOG_ERR);
3123 3123
 
3124 3124
 			$this->db->rollback();
3125 3125
 			return $result;
@@ -3136,12 +3136,12 @@  discard block
 block discarded – undo
3136 3136
 	{
3137 3137
 		global $langs;
3138 3138
 
3139
-		$this->id=0;
3140
-		$this->name=empty($conf->global->MAIN_INFO_SOCIETE_NOM)?'':$conf->global->MAIN_INFO_SOCIETE_NOM;
3141
-		$this->address=empty($conf->global->MAIN_INFO_SOCIETE_ADDRESS)?'':$conf->global->MAIN_INFO_SOCIETE_ADDRESS;
3142
-		$this->zip=empty($conf->global->MAIN_INFO_SOCIETE_ZIP)?'':$conf->global->MAIN_INFO_SOCIETE_ZIP;
3143
-		$this->town=empty($conf->global->MAIN_INFO_SOCIETE_TOWN)?'':$conf->global->MAIN_INFO_SOCIETE_TOWN;
3144
-		$this->state_id=empty($conf->global->MAIN_INFO_SOCIETE_STATE)?'':$conf->global->MAIN_INFO_SOCIETE_STATE;
3139
+		$this->id = 0;
3140
+		$this->name = empty($conf->global->MAIN_INFO_SOCIETE_NOM) ? '' : $conf->global->MAIN_INFO_SOCIETE_NOM;
3141
+		$this->address = empty($conf->global->MAIN_INFO_SOCIETE_ADDRESS) ? '' : $conf->global->MAIN_INFO_SOCIETE_ADDRESS;
3142
+		$this->zip = empty($conf->global->MAIN_INFO_SOCIETE_ZIP) ? '' : $conf->global->MAIN_INFO_SOCIETE_ZIP;
3143
+		$this->town = empty($conf->global->MAIN_INFO_SOCIETE_TOWN) ? '' : $conf->global->MAIN_INFO_SOCIETE_TOWN;
3144
+		$this->state_id = empty($conf->global->MAIN_INFO_SOCIETE_STATE) ? '' : $conf->global->MAIN_INFO_SOCIETE_STATE;
3145 3145
 
3146 3146
 		/* Disabled: we don't want any SQL request into method setMySoc. This method set object from env only.
3147 3147
         If we need label, label must be loaded by output that need it from id (label depends on output language)
@@ -3152,59 +3152,59 @@  discard block
 block discarded – undo
3152 3152
         }
3153 3153
 		*/
3154 3154
 
3155
-		$this->note_private=empty($conf->global->MAIN_INFO_SOCIETE_NOTE)?'':$conf->global->MAIN_INFO_SOCIETE_NOTE;
3155
+		$this->note_private = empty($conf->global->MAIN_INFO_SOCIETE_NOTE) ? '' : $conf->global->MAIN_INFO_SOCIETE_NOTE;
3156 3156
 
3157
-		$this->nom=$this->name; 									// deprecated
3157
+		$this->nom = $this->name; // deprecated
3158 3158
 
3159 3159
 		// We define country_id, country_code and country
3160
-		$country_id=$country_code=$country_label='';
3161
-		if (! empty($conf->global->MAIN_INFO_SOCIETE_COUNTRY))
3160
+		$country_id = $country_code = $country_label = '';
3161
+		if (!empty($conf->global->MAIN_INFO_SOCIETE_COUNTRY))
3162 3162
 		{
3163
-			$tmp=explode(':',$conf->global->MAIN_INFO_SOCIETE_COUNTRY);
3164
-			$country_id=$tmp[0];
3165
-			if (! empty($tmp[1]))   // If $conf->global->MAIN_INFO_SOCIETE_COUNTRY is "id:code:label"
3163
+			$tmp = explode(':', $conf->global->MAIN_INFO_SOCIETE_COUNTRY);
3164
+			$country_id = $tmp[0];
3165
+			if (!empty($tmp[1]))   // If $conf->global->MAIN_INFO_SOCIETE_COUNTRY is "id:code:label"
3166 3166
 			{
3167
-				$country_code=$tmp[1];
3168
-				$country_label=$tmp[2];
3167
+				$country_code = $tmp[1];
3168
+				$country_label = $tmp[2];
3169 3169
 			}
3170 3170
 			else                    // For backward compatibility
3171 3171
 			{
3172 3172
 				dol_syslog("Your country setup use an old syntax. Reedit it using setup area.", LOG_ERR);
3173 3173
 				include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
3174
-				$country_code=getCountry($country_id,2,$this->db);  // This need a SQL request, but it's the old feature that should not be used anymore
3175
-				$country_label=getCountry($country_id,0,$this->db);  // This need a SQL request, but it's the old feature that should not be used anymore
3174
+				$country_code = getCountry($country_id, 2, $this->db); // This need a SQL request, but it's the old feature that should not be used anymore
3175
+				$country_label = getCountry($country_id, 0, $this->db); // This need a SQL request, but it's the old feature that should not be used anymore
3176 3176
 			}
3177 3177
 		}
3178
-		$this->country_id=$country_id;
3179
-		$this->country_code=$country_code;
3180
-		$this->country=$country_label;
3181
-		if (is_object($langs)) $this->country=($langs->trans('Country'.$country_code)!='Country'.$country_code)?$langs->trans('Country'.$country_code):$country_label;
3178
+		$this->country_id = $country_id;
3179
+		$this->country_code = $country_code;
3180
+		$this->country = $country_label;
3181
+		if (is_object($langs)) $this->country = ($langs->trans('Country'.$country_code) != 'Country'.$country_code) ? $langs->trans('Country'.$country_code) : $country_label;
3182 3182
 
3183
-		$this->phone=empty($conf->global->MAIN_INFO_SOCIETE_TEL)?'':$conf->global->MAIN_INFO_SOCIETE_TEL;
3184
-		$this->fax=empty($conf->global->MAIN_INFO_SOCIETE_FAX)?'':$conf->global->MAIN_INFO_SOCIETE_FAX;
3185
-		$this->url=empty($conf->global->MAIN_INFO_SOCIETE_WEB)?'':$conf->global->MAIN_INFO_SOCIETE_WEB;
3183
+		$this->phone = empty($conf->global->MAIN_INFO_SOCIETE_TEL) ? '' : $conf->global->MAIN_INFO_SOCIETE_TEL;
3184
+		$this->fax = empty($conf->global->MAIN_INFO_SOCIETE_FAX) ? '' : $conf->global->MAIN_INFO_SOCIETE_FAX;
3185
+		$this->url = empty($conf->global->MAIN_INFO_SOCIETE_WEB) ? '' : $conf->global->MAIN_INFO_SOCIETE_WEB;
3186 3186
 		// Id prof generiques
3187
-		$this->idprof1=empty($conf->global->MAIN_INFO_SIREN)?'':$conf->global->MAIN_INFO_SIREN;
3188
-		$this->idprof2=empty($conf->global->MAIN_INFO_SIRET)?'':$conf->global->MAIN_INFO_SIRET;
3189
-		$this->idprof3=empty($conf->global->MAIN_INFO_APE)?'':$conf->global->MAIN_INFO_APE;
3190
-		$this->idprof4=empty($conf->global->MAIN_INFO_RCS)?'':$conf->global->MAIN_INFO_RCS;
3191
-		$this->idprof5=empty($conf->global->MAIN_INFO_PROFID5)?'':$conf->global->MAIN_INFO_PROFID5;
3192
-		$this->idprof6=empty($conf->global->MAIN_INFO_PROFID6)?'':$conf->global->MAIN_INFO_PROFID6;
3193
-		$this->tva_intra=empty($conf->global->MAIN_INFO_TVAINTRA)?'':$conf->global->MAIN_INFO_TVAINTRA;	// VAT number, not necessarly INTRA.
3194
-		$this->managers=empty($conf->global->MAIN_INFO_SOCIETE_MANAGERS)?'':$conf->global->MAIN_INFO_SOCIETE_MANAGERS;
3195
-		$this->capital=empty($conf->global->MAIN_INFO_CAPITAL)?'':$conf->global->MAIN_INFO_CAPITAL;
3196
-		$this->forme_juridique_code=empty($conf->global->MAIN_INFO_SOCIETE_FORME_JURIDIQUE)?'':$conf->global->MAIN_INFO_SOCIETE_FORME_JURIDIQUE;
3197
-		$this->email=empty($conf->global->MAIN_INFO_SOCIETE_MAIL)?'':$conf->global->MAIN_INFO_SOCIETE_MAIL;
3198
-		$this->logo=empty($conf->global->MAIN_INFO_SOCIETE_LOGO)?'':$conf->global->MAIN_INFO_SOCIETE_LOGO;
3199
-		$this->logo_small=empty($conf->global->MAIN_INFO_SOCIETE_LOGO_SMALL)?'':$conf->global->MAIN_INFO_SOCIETE_LOGO_SMALL;
3200
-		$this->logo_mini=empty($conf->global->MAIN_INFO_SOCIETE_LOGO_MINI)?'':$conf->global->MAIN_INFO_SOCIETE_LOGO_MINI;
3187
+		$this->idprof1 = empty($conf->global->MAIN_INFO_SIREN) ? '' : $conf->global->MAIN_INFO_SIREN;
3188
+		$this->idprof2 = empty($conf->global->MAIN_INFO_SIRET) ? '' : $conf->global->MAIN_INFO_SIRET;
3189
+		$this->idprof3 = empty($conf->global->MAIN_INFO_APE) ? '' : $conf->global->MAIN_INFO_APE;
3190
+		$this->idprof4 = empty($conf->global->MAIN_INFO_RCS) ? '' : $conf->global->MAIN_INFO_RCS;
3191
+		$this->idprof5 = empty($conf->global->MAIN_INFO_PROFID5) ? '' : $conf->global->MAIN_INFO_PROFID5;
3192
+		$this->idprof6 = empty($conf->global->MAIN_INFO_PROFID6) ? '' : $conf->global->MAIN_INFO_PROFID6;
3193
+		$this->tva_intra = empty($conf->global->MAIN_INFO_TVAINTRA) ? '' : $conf->global->MAIN_INFO_TVAINTRA; // VAT number, not necessarly INTRA.
3194
+		$this->managers = empty($conf->global->MAIN_INFO_SOCIETE_MANAGERS) ? '' : $conf->global->MAIN_INFO_SOCIETE_MANAGERS;
3195
+		$this->capital = empty($conf->global->MAIN_INFO_CAPITAL) ? '' : $conf->global->MAIN_INFO_CAPITAL;
3196
+		$this->forme_juridique_code = empty($conf->global->MAIN_INFO_SOCIETE_FORME_JURIDIQUE) ? '' : $conf->global->MAIN_INFO_SOCIETE_FORME_JURIDIQUE;
3197
+		$this->email = empty($conf->global->MAIN_INFO_SOCIETE_MAIL) ? '' : $conf->global->MAIN_INFO_SOCIETE_MAIL;
3198
+		$this->logo = empty($conf->global->MAIN_INFO_SOCIETE_LOGO) ? '' : $conf->global->MAIN_INFO_SOCIETE_LOGO;
3199
+		$this->logo_small = empty($conf->global->MAIN_INFO_SOCIETE_LOGO_SMALL) ? '' : $conf->global->MAIN_INFO_SOCIETE_LOGO_SMALL;
3200
+		$this->logo_mini = empty($conf->global->MAIN_INFO_SOCIETE_LOGO_MINI) ? '' : $conf->global->MAIN_INFO_SOCIETE_LOGO_MINI;
3201 3201
 
3202 3202
 		// Define if company use vat or not
3203
-		$this->tva_assuj=$conf->global->FACTURE_TVAOPTION;
3203
+		$this->tva_assuj = $conf->global->FACTURE_TVAOPTION;
3204 3204
 
3205 3205
 		// Define if company use local taxes
3206
-		$this->localtax1_assuj=((isset($conf->global->FACTURE_LOCAL_TAX1_OPTION) && ($conf->global->FACTURE_LOCAL_TAX1_OPTION=='1' || $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on'))?1:0);
3207
-		$this->localtax2_assuj=((isset($conf->global->FACTURE_LOCAL_TAX2_OPTION) && ($conf->global->FACTURE_LOCAL_TAX2_OPTION=='1' || $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on'))?1:0);
3206
+		$this->localtax1_assuj = ((isset($conf->global->FACTURE_LOCAL_TAX1_OPTION) && ($conf->global->FACTURE_LOCAL_TAX1_OPTION == '1' || $conf->global->FACTURE_LOCAL_TAX1_OPTION == 'localtax1on')) ? 1 : 0);
3207
+		$this->localtax2_assuj = ((isset($conf->global->FACTURE_LOCAL_TAX2_OPTION) && ($conf->global->FACTURE_LOCAL_TAX2_OPTION == '1' || $conf->global->FACTURE_LOCAL_TAX2_OPTION == 'localtax2on')) ? 1 : 0);
3208 3208
 	}
3209 3209
 
3210 3210
 	/**
@@ -3216,46 +3216,46 @@  discard block
 block discarded – undo
3216 3216
 	 */
3217 3217
 	function initAsSpecimen()
3218 3218
 	{
3219
-		$now=dol_now();
3219
+		$now = dol_now();
3220 3220
 
3221 3221
 		// Initialize parameters
3222
-		$this->id=0;
3223
-		$this->name = 'THIRDPARTY SPECIMEN '.dol_print_date($now,'dayhourlog');
3224
-		$this->nom = $this->name;   // For backward compatibility
3222
+		$this->id = 0;
3223
+		$this->name = 'THIRDPARTY SPECIMEN '.dol_print_date($now, 'dayhourlog');
3224
+		$this->nom = $this->name; // For backward compatibility
3225 3225
 		$this->ref_ext = 'Ref ext';
3226
-		$this->specimen=1;
3227
-		$this->address='21 jump street';
3228
-		$this->zip='99999';
3229
-		$this->town='MyTown';
3230
-		$this->state_id=1;
3231
-		$this->state_code='AA';
3232
-		$this->state='MyState';
3233
-		$this->country_id=1;
3234
-		$this->country_code='FR';
3235
-		$this->email='[email protected]';
3236
-		$this->skype='tom.hanson';
3237
-		$this->url='http://www.specimen.com';
3238
-
3239
-		$this->phone='0909090901';
3240
-		$this->fax='0909090909';
3241
-
3242
-		$this->code_client='CC-'.dol_print_date($now,'dayhourlog');
3243
-		$this->code_fournisseur='SC-'.dol_print_date($now,'dayhourlog');
3244
-		$this->capital=10000;
3245
-		$this->client=1;
3246
-		$this->prospect=1;
3247
-		$this->fournisseur=1;
3248
-		$this->tva_assuj=1;
3249
-		$this->tva_intra='EU1234567';
3250
-		$this->note_public='This is a comment (public)';
3251
-		$this->note_private='This is a comment (private)';
3252
-
3253
-		$this->idprof1='idprof1';
3254
-		$this->idprof2='idprof2';
3255
-		$this->idprof3='idprof3';
3256
-		$this->idprof4='idprof4';
3257
-		$this->idprof5='idprof5';
3258
-		$this->idprof6='idprof6';
3226
+		$this->specimen = 1;
3227
+		$this->address = '21 jump street';
3228
+		$this->zip = '99999';
3229
+		$this->town = 'MyTown';
3230
+		$this->state_id = 1;
3231
+		$this->state_code = 'AA';
3232
+		$this->state = 'MyState';
3233
+		$this->country_id = 1;
3234
+		$this->country_code = 'FR';
3235
+		$this->email = '[email protected]';
3236
+		$this->skype = 'tom.hanson';
3237
+		$this->url = 'http://www.specimen.com';
3238
+
3239
+		$this->phone = '0909090901';
3240
+		$this->fax = '0909090909';
3241
+
3242
+		$this->code_client = 'CC-'.dol_print_date($now, 'dayhourlog');
3243
+		$this->code_fournisseur = 'SC-'.dol_print_date($now, 'dayhourlog');
3244
+		$this->capital = 10000;
3245
+		$this->client = 1;
3246
+		$this->prospect = 1;
3247
+		$this->fournisseur = 1;
3248
+		$this->tva_assuj = 1;
3249
+		$this->tva_intra = 'EU1234567';
3250
+		$this->note_public = 'This is a comment (public)';
3251
+		$this->note_private = 'This is a comment (private)';
3252
+
3253
+		$this->idprof1 = 'idprof1';
3254
+		$this->idprof2 = 'idprof2';
3255
+		$this->idprof3 = 'idprof3';
3256
+		$this->idprof4 = 'idprof4';
3257
+		$this->idprof5 = 'idprof5';
3258
+		$this->idprof6 = 'idprof6';
3259 3259
 	}
3260 3260
 
3261 3261
 	/**
@@ -3264,7 +3264,7 @@  discard block
 block discarded – undo
3264 3264
 	 *	@param		int		$localTaxNum	To get info for only localtax1 or localtax2
3265 3265
 	 *  @return		boolean					true or false
3266 3266
 	 */
3267
-	function useLocalTax($localTaxNum=0)
3267
+	function useLocalTax($localTaxNum = 0)
3268 3268
 	{
3269 3269
 		$sql  = "SELECT t.localtax1, t.localtax2";
3270 3270
 		$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
@@ -3275,7 +3275,7 @@  discard block
 block discarded – undo
3275 3275
 		elseif ($localTaxNum == 2) $sql .= " AND t.localtax2_type <> '0'";
3276 3276
 
3277 3277
 		dol_syslog("useLocalTax", LOG_DEBUG);
3278
-		$resql=$this->db->query($sql);
3278
+		$resql = $this->db->query($sql);
3279 3279
 		if ($resql)
3280 3280
 		{
3281 3281
    			return ($this->db->num_rows($resql) > 0);
@@ -3296,7 +3296,7 @@  discard block
 block discarded – undo
3296 3296
 		$sql .= " AND t.active = 1 AND t.recuperableonly = 1";
3297 3297
 
3298 3298
 		dol_syslog("useNPR", LOG_DEBUG);
3299
-		$resql=$this->db->query($sql);
3299
+		$resql = $this->db->query($sql);
3300 3300
 		if ($resql)
3301 3301
 		{
3302 3302
 			return ($this->db->num_rows($resql) > 0);
@@ -3317,15 +3317,15 @@  discard block
 block discarded – undo
3317 3317
 		$sql .= " AND r.active = 1";
3318 3318
 
3319 3319
 		dol_syslog("useRevenueStamp", LOG_DEBUG);
3320
-		$resql=$this->db->query($sql);
3320
+		$resql = $this->db->query($sql);
3321 3321
 		if ($resql)
3322 3322
 		{
3323
-			$obj=$this->db->fetch_object($resql);
3324
-   			return (($obj->nb > 0)?true:false);
3323
+			$obj = $this->db->fetch_object($resql);
3324
+   			return (($obj->nb > 0) ?true:false);
3325 3325
 		}
3326 3326
 		else
3327 3327
 		{
3328
-			$this->error=$this->db->lasterror();
3328
+			$this->error = $this->db->lasterror();
3329 3329
 			return false;
3330 3330
 		}
3331 3331
 	}
@@ -3350,11 +3350,11 @@  discard block
 block discarded – undo
3350 3350
 	{
3351 3351
 		global $langs;
3352 3352
 
3353
-		$lib=$langs->trans("ProspectLevel".$fk_prospectlevel);
3353
+		$lib = $langs->trans("ProspectLevel".$fk_prospectlevel);
3354 3354
 		// If lib not found in language file, we get label from cache/databse
3355 3355
 		if ($lib == $langs->trans("ProspectLevel".$fk_prospectlevel))
3356 3356
 		{
3357
-			$lib=$langs->getLabelFromKey($this->db,$fk_prospectlevel,'c_prospectlevel','code','label');
3357
+			$lib = $langs->getLabelFromKey($this->db, $fk_prospectlevel, 'c_prospectlevel', 'code', 'label');
3358 3358
 		}
3359 3359
 		return $lib;
3360 3360
 	}
@@ -3379,7 +3379,7 @@  discard block
 block discarded – undo
3379 3379
 	 *  @param	string	$label		Label to use for status for added status
3380 3380
 	 *  @return string        		Libelle
3381 3381
 	 */
3382
-	function getLibProspCommStatut($mode=0, $label='')
3382
+	function getLibProspCommStatut($mode = 0, $label = '')
3383 3383
 	{
3384 3384
 		return $this->LibProspCommStatut($this->stcomm_id, $mode, $label);
3385 3385
 	}
@@ -3392,18 +3392,18 @@  discard block
 block discarded – undo
3392 3392
 	 *  @param	string		$label			Label to use for status for added status
3393 3393
 	 *  @return string       	 			Libelle du statut
3394 3394
 	 */
3395
-	function LibProspCommStatut($statut, $mode=0, $label='')
3395
+	function LibProspCommStatut($statut, $mode = 0, $label = '')
3396 3396
 	{
3397 3397
 		global $langs;
3398 3398
 		$langs->load('customers');
3399 3399
 
3400 3400
 		if ($mode == 2)
3401 3401
 		{
3402
-			if ($statut == '-1' || $statut == 'ST_NO')         return img_action($langs->trans("StatusProspect-1"),-1).' '.$langs->trans("StatusProspect-1");
3403
-			elseif ($statut ==  '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0).' '.$langs->trans("StatusProspect0");
3404
-			elseif ($statut ==  '1' || $statut == 'ST_TODO')  return img_action($langs->trans("StatusProspect1"), 1).' '.$langs->trans("StatusProspect1");
3405
-			elseif ($statut ==  '2' || $statut == 'ST_PEND')  return img_action($langs->trans("StatusProspect2"), 2).' '.$langs->trans("StatusProspect2");
3406
-			elseif ($statut ==  '3' || $statut == 'ST_DONE')  return img_action($langs->trans("StatusProspect3"), 3).' '.$langs->trans("StatusProspect3");
3402
+			if ($statut == '-1' || $statut == 'ST_NO')         return img_action($langs->trans("StatusProspect-1"), -1).' '.$langs->trans("StatusProspect-1");
3403
+			elseif ($statut == '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0).' '.$langs->trans("StatusProspect0");
3404
+			elseif ($statut == '1' || $statut == 'ST_TODO')  return img_action($langs->trans("StatusProspect1"), 1).' '.$langs->trans("StatusProspect1");
3405
+			elseif ($statut == '2' || $statut == 'ST_PEND')  return img_action($langs->trans("StatusProspect2"), 2).' '.$langs->trans("StatusProspect2");
3406
+			elseif ($statut == '3' || $statut == 'ST_DONE')  return img_action($langs->trans("StatusProspect3"), 3).' '.$langs->trans("StatusProspect3");
3407 3407
 			else
3408 3408
 			{
3409 3409
 				return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0).' '.(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label);
@@ -3411,11 +3411,11 @@  discard block
 block discarded – undo
3411 3411
 		}
3412 3412
 		if ($mode == 3)
3413 3413
 		{
3414
-			if ($statut == '-1' || $statut == 'ST_NO')         return img_action($langs->trans("StatusProspect-1"),-1);
3415
-			elseif ($statut ==  '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0);
3416
-			elseif ($statut ==  '1' || $statut == 'ST_TODO')  return img_action($langs->trans("StatusProspect1"), 1);
3417
-			elseif ($statut ==  '2' || $statut == 'ST_PEND')  return img_action($langs->trans("StatusProspect2"), 2);
3418
-			elseif ($statut ==  '3' || $statut == 'ST_DONE')  return img_action($langs->trans("StatusProspect3"), 3);
3414
+			if ($statut == '-1' || $statut == 'ST_NO')         return img_action($langs->trans("StatusProspect-1"), -1);
3415
+			elseif ($statut == '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0);
3416
+			elseif ($statut == '1' || $statut == 'ST_TODO')  return img_action($langs->trans("StatusProspect1"), 1);
3417
+			elseif ($statut == '2' || $statut == 'ST_PEND')  return img_action($langs->trans("StatusProspect2"), 2);
3418
+			elseif ($statut == '3' || $statut == 'ST_DONE')  return img_action($langs->trans("StatusProspect3"), 3);
3419 3419
 			else
3420 3420
 			{
3421 3421
 				return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0);
@@ -3423,11 +3423,11 @@  discard block
 block discarded – undo
3423 3423
 		}
3424 3424
 		if ($mode == 4)
3425 3425
 		{
3426
-			if ($statut == '-1' || $statut == 'ST_NO')         return img_action($langs->trans("StatusProspect-1"),-1).' '.$langs->trans("StatusProspect-1");
3427
-			elseif ($statut ==  '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0).' '.$langs->trans("StatusProspect0");
3428
-			elseif ($statut ==  '1' || $statut == 'ST_TODO')  return img_action($langs->trans("StatusProspect1"), 1).' '.$langs->trans("StatusProspect1");
3429
-			elseif ($statut ==  '2' || $statut == 'ST_PEND')  return img_action($langs->trans("StatusProspect2"), 2).' '.$langs->trans("StatusProspect2");
3430
-			elseif ($statut ==  '3' || $statut == 'ST_DONE')  return img_action($langs->trans("StatusProspect3"), 3).' '.$langs->trans("StatusProspect3");
3426
+			if ($statut == '-1' || $statut == 'ST_NO')         return img_action($langs->trans("StatusProspect-1"), -1).' '.$langs->trans("StatusProspect-1");
3427
+			elseif ($statut == '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0).' '.$langs->trans("StatusProspect0");
3428
+			elseif ($statut == '1' || $statut == 'ST_TODO')  return img_action($langs->trans("StatusProspect1"), 1).' '.$langs->trans("StatusProspect1");
3429
+			elseif ($statut == '2' || $statut == 'ST_PEND')  return img_action($langs->trans("StatusProspect2"), 2).' '.$langs->trans("StatusProspect2");
3430
+			elseif ($statut == '3' || $statut == 'ST_DONE')  return img_action($langs->trans("StatusProspect3"), 3).' '.$langs->trans("StatusProspect3");
3431 3431
 			else
3432 3432
 			{
3433 3433
 				return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0).' '.(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label);
@@ -3455,13 +3455,13 @@  discard block
 block discarded – undo
3455 3455
 	 *  @param     string      $mode    'customer' or 'supplier'
3456 3456
 	 *  @return    array				array('opened'=>Amount, 'total'=>Total amount)
3457 3457
 	 */
3458
-	function getOutstandingProposals($mode='customer')
3458
+	function getOutstandingProposals($mode = 'customer')
3459 3459
 	{
3460
-		$table='propal';
3460
+		$table = 'propal';
3461 3461
 		if ($mode == 'supplier') $table = 'supplier_proposal';
3462 3462
 
3463 3463
 		$sql  = "SELECT rowid, total_ht, total as total_ttc, fk_statut FROM ".MAIN_DB_PREFIX.$table." as f";
3464
-		$sql .= " WHERE fk_soc = ". $this->id;
3464
+		$sql .= " WHERE fk_soc = ".$this->id;
3465 3465
 		if ($mode == 'supplier') {
3466 3466
 			$sql .= " AND entity IN (".getEntity('supplier_proposal').")";
3467 3467
 		} else {
@@ -3469,21 +3469,21 @@  discard block
 block discarded – undo
3469 3469
 		}
3470 3470
 
3471 3471
 		dol_syslog("getOutstandingProposals", LOG_DEBUG);
3472
-		$resql=$this->db->query($sql);
3472
+		$resql = $this->db->query($sql);
3473 3473
 		if ($resql)
3474 3474
 		{
3475 3475
 			$outstandingOpened = 0;
3476 3476
 			$outstandingTotal = 0;
3477 3477
 			$outstandingTotalIncTax = 0;
3478
-			while($obj=$this->db->fetch_object($resql)) {
3479
-				$outstandingTotal+= $obj->total_ht;
3480
-				$outstandingTotalIncTax+= $obj->total_ttc;
3478
+			while ($obj = $this->db->fetch_object($resql)) {
3479
+				$outstandingTotal += $obj->total_ht;
3480
+				$outstandingTotalIncTax += $obj->total_ttc;
3481 3481
 				if ($obj->fk_statut != 0)    // Not a draft
3482 3482
 				{
3483
-					$outstandingOpened+=$obj->total_ttc;
3483
+					$outstandingOpened += $obj->total_ttc;
3484 3484
 				}
3485 3485
 			}
3486
-			return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax);	// 'opened' is 'incl taxes'
3486
+			return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax); // 'opened' is 'incl taxes'
3487 3487
 		}
3488 3488
 		else
3489 3489
 			return array();
@@ -3495,13 +3495,13 @@  discard block
 block discarded – undo
3495 3495
 	 *  @param     string      $mode    'customer' or 'supplier'
3496 3496
 	 *  @return		array				array('opened'=>Amount, 'total'=>Total amount)
3497 3497
 	 */
3498
-	function getOutstandingOrders($mode='customer')
3498
+	function getOutstandingOrders($mode = 'customer')
3499 3499
 	{
3500
-		$table='commande';
3500
+		$table = 'commande';
3501 3501
 		if ($mode == 'supplier') $table = 'commande_fournisseur';
3502 3502
 
3503 3503
 		$sql  = "SELECT rowid, total_ht, total_ttc, fk_statut FROM ".MAIN_DB_PREFIX.$table." as f";
3504
-		$sql .= " WHERE fk_soc = ". $this->id;
3504
+		$sql .= " WHERE fk_soc = ".$this->id;
3505 3505
 		if ($mode == 'supplier') {
3506 3506
 			$sql .= " AND entity IN (".getEntity('supplier_order').")";
3507 3507
 		} else {
@@ -3509,21 +3509,21 @@  discard block
 block discarded – undo
3509 3509
 		}
3510 3510
 
3511 3511
 		dol_syslog("getOutstandingOrders", LOG_DEBUG);
3512
-		$resql=$this->db->query($sql);
3512
+		$resql = $this->db->query($sql);
3513 3513
 		if ($resql)
3514 3514
 		{
3515 3515
 			$outstandingOpened = 0;
3516 3516
 			$outstandingTotal = 0;
3517 3517
 			$outstandingTotalIncTax = 0;
3518
-			while($obj=$this->db->fetch_object($resql)) {
3519
-				$outstandingTotal+= $obj->total_ht;
3520
-				$outstandingTotalIncTax+= $obj->total_ttc;
3518
+			while ($obj = $this->db->fetch_object($resql)) {
3519
+				$outstandingTotal += $obj->total_ht;
3520
+				$outstandingTotalIncTax += $obj->total_ttc;
3521 3521
 				if ($obj->fk_statut != 0)    // Not a draft
3522 3522
 				{
3523
-					$outstandingOpened+=$obj->total_ttc;
3523
+					$outstandingOpened += $obj->total_ttc;
3524 3524
 				}
3525 3525
 			}
3526
-			return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax);	// 'opened' is 'incl taxes'
3526
+			return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax); // 'opened' is 'incl taxes'
3527 3527
 		}
3528 3528
 		else
3529 3529
 			return array();
@@ -3535,9 +3535,9 @@  discard block
 block discarded – undo
3535 3535
 	 *  @param     string      $mode    'customer' or 'supplier'
3536 3536
 	 *  @return		array				array('opened'=>Amount, 'total'=>Total amount)
3537 3537
 	 */
3538
-	function getOutstandingBills($mode='customer')
3538
+	function getOutstandingBills($mode = 'customer')
3539 3539
 	{
3540
-		$table='facture';
3540
+		$table = 'facture';
3541 3541
 		if ($mode == 'supplier') $table = 'facture_fourn';
3542 3542
 
3543 3543
 		/* Accurate value of remain to pay is to sum remaintopay for each invoice
@@ -3547,9 +3547,9 @@  discard block
 block discarded – undo
3547 3547
 		 $alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT');
3548 3548
 		 $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT');
3549 3549
 		 */
3550
-		if ($mode == 'supplier') $sql  = "SELECT rowid, total_ht as total_ht, total_ttc, paye, fk_statut, close_code FROM ".MAIN_DB_PREFIX.$table." as f";
3551
-		else $sql  = "SELECT rowid, total as total_ht, total_ttc, paye, fk_statut, close_code FROM ".MAIN_DB_PREFIX.$table." as f";
3552
-		$sql .= " WHERE fk_soc = ". $this->id;
3550
+		if ($mode == 'supplier') $sql = "SELECT rowid, total_ht as total_ht, total_ttc, paye, fk_statut, close_code FROM ".MAIN_DB_PREFIX.$table." as f";
3551
+		else $sql = "SELECT rowid, total as total_ht, total_ttc, paye, fk_statut, close_code FROM ".MAIN_DB_PREFIX.$table." as f";
3552
+		$sql .= " WHERE fk_soc = ".$this->id;
3553 3553
 		if ($mode == 'supplier') {
3554 3554
 			$sql .= " AND entity IN (".getEntity('facture_fourn').")";
3555 3555
 		} else {
@@ -3557,7 +3557,7 @@  discard block
 block discarded – undo
3557 3557
 		}
3558 3558
 
3559 3559
 		dol_syslog("getOutstandingBills", LOG_DEBUG);
3560
-		$resql=$this->db->query($sql);
3560
+		$resql = $this->db->query($sql);
3561 3561
 		if ($resql)
3562 3562
 		{
3563 3563
 			$outstandingOpened = 0;
@@ -3566,21 +3566,21 @@  discard block
 block discarded – undo
3566 3566
 			if ($mode == 'supplier')
3567 3567
 			{
3568 3568
 				require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
3569
-				$tmpobject=new FactureFournisseur($this->db);
3569
+				$tmpobject = new FactureFournisseur($this->db);
3570 3570
 			}
3571 3571
 			else
3572 3572
 			{
3573 3573
 				require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
3574
-				$tmpobject=new Facture($this->db);
3574
+				$tmpobject = new Facture($this->db);
3575 3575
 			}
3576
-			while($obj=$this->db->fetch_object($resql)) {
3577
-				$tmpobject->id=$obj->rowid;
3576
+			while ($obj = $this->db->fetch_object($resql)) {
3577
+				$tmpobject->id = $obj->rowid;
3578 3578
 				if ($obj->fk_statut != 0                                           // Not a draft
3579
-					&& ! ($obj->fk_statut == 3 && $obj->close_code == 'replaced')  // Not a replaced invoice
3579
+					&& !($obj->fk_statut == 3 && $obj->close_code == 'replaced')  // Not a replaced invoice
3580 3580
 					)
3581 3581
 				{
3582
-					$outstandingTotal+= $obj->total_ht;
3583
-					$outstandingTotalIncTax+= $obj->total_ttc;
3582
+					$outstandingTotal += $obj->total_ht;
3583
+					$outstandingTotalIncTax += $obj->total_ttc;
3584 3584
 				}
3585 3585
 				if ($obj->paye == 0
3586 3586
 					&& $obj->fk_statut != 0    // Not a draft
@@ -3591,10 +3591,10 @@  discard block
 block discarded – undo
3591 3591
 					$paiement = $tmpobject->getSommePaiement();
3592 3592
 					$creditnotes = $tmpobject->getSumCreditNotesUsed();
3593 3593
 					$deposits = $tmpobject->getSumDepositsUsed();
3594
-					$outstandingOpened+=$obj->total_ttc - $paiement - $creditnotes - $deposits;
3594
+					$outstandingOpened += $obj->total_ttc - $paiement - $creditnotes - $deposits;
3595 3595
 				}
3596 3596
 			}
3597
-			return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax);	// 'opened' is 'incl taxes'
3597
+			return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax); // 'opened' is 'incl taxes'
3598 3598
 		}
3599 3599
 		else
3600 3600
 		{
@@ -3618,26 +3618,26 @@  discard block
 block discarded – undo
3618 3618
 	     $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT');
3619 3619
 	     */
3620 3620
 		$sql  = "SELECT rowid, total_ttc FROM ".MAIN_DB_PREFIX."facture as f";
3621
-		$sql .= " WHERE fk_soc = ". $this->id;
3621
+		$sql .= " WHERE fk_soc = ".$this->id;
3622 3622
 		$sql .= " AND paye = 0";
3623
-		$sql .= " AND fk_statut <> 0";	// Not a draft
3623
+		$sql .= " AND fk_statut <> 0"; // Not a draft
3624 3624
 		//$sql .= " AND (fk_statut <> 3 OR close_code <> 'abandon')";		// Not abandonned for undefined reason
3625
-		$sql .= " AND fk_statut <> 3";		// Not abandonned
3626
-		$sql .= " AND fk_statut <> 2";		// Not clasified as paid
3625
+		$sql .= " AND fk_statut <> 3"; // Not abandonned
3626
+		$sql .= " AND fk_statut <> 2"; // Not clasified as paid
3627 3627
 
3628 3628
 		dol_syslog("get_OutstandingBill", LOG_DEBUG);
3629
-		$resql=$this->db->query($sql);
3629
+		$resql = $this->db->query($sql);
3630 3630
 		if ($resql)
3631 3631
 		{
3632 3632
 			$outstandingAmount = 0;
3633 3633
 			require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
3634
-			$tmpobject=new Facture($this->db);
3635
-			while($obj=$this->db->fetch_object($resql)) {
3636
-				$tmpobject->id=$obj->rowid;
3634
+			$tmpobject = new Facture($this->db);
3635
+			while ($obj = $this->db->fetch_object($resql)) {
3636
+				$tmpobject->id = $obj->rowid;
3637 3637
 				$paiement = $tmpobject->getSommePaiement();
3638 3638
 				$creditnotes = $tmpobject->getSumCreditNotesUsed();
3639 3639
 				$deposits = $tmpobject->getSumDepositsUsed();
3640
-				$outstandingAmount+= $obj->total_ttc - $paiement - $creditnotes - $deposits;
3640
+				$outstandingAmount += $obj->total_ttc - $paiement - $creditnotes - $deposits;
3641 3641
 			}
3642 3642
 			return $outstandingAmount;
3643 3643
 		}
@@ -3666,10 +3666,10 @@  discard block
 block discarded – undo
3666 3666
 		global $langs;
3667 3667
 		$langs->load('companies');
3668 3668
 
3669
-		if ($statut==0) return $langs->trans("NorProspectNorCustomer");
3670
-		if ($statut==1) return $langs->trans("Customer");
3671
-		if ($statut==2) return $langs->trans("Prospect");
3672
-		if ($statut==3) return $langs->trans("ProspectCustomer");
3669
+		if ($statut == 0) return $langs->trans("NorProspectNorCustomer");
3670
+		if ($statut == 1) return $langs->trans("Customer");
3671
+		if ($statut == 2) return $langs->trans("Prospect");
3672
+		if ($statut == 3) return $langs->trans("ProspectCustomer");
3673 3673
 
3674 3674
 	}
3675 3675
 
@@ -3685,26 +3685,26 @@  discard block
 block discarded – undo
3685 3685
 	 *  @param  null|array  $moreparams     Array to provide more information
3686 3686
 	 *	@return int        					<0 if KO, >0 if OK
3687 3687
 	 */
3688
-	public function generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
3688
+	public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
3689 3689
 	{
3690
-		global $conf,$user,$langs;
3690
+		global $conf, $user, $langs;
3691 3691
 
3692
-		if (! empty($moreparams) && ! empty($moreparams['use_companybankid']))
3692
+		if (!empty($moreparams) && !empty($moreparams['use_companybankid']))
3693 3693
 		{
3694 3694
 			$modelpath = "core/modules/bank/doc/";
3695 3695
 
3696 3696
 			include_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
3697 3697
 			$companybankaccount = new CompanyBankAccount($this->db);
3698 3698
 			$result = $companybankaccount->fetch($moreparams['use_companybankid']);
3699
-			if (! $result) dol_print_error($this->db, $companybankaccount->error, $companybankaccount->errors);
3700
-			$result=$companybankaccount->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3699
+			if (!$result) dol_print_error($this->db, $companybankaccount->error, $companybankaccount->errors);
3700
+			$result = $companybankaccount->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3701 3701
 		}
3702 3702
 		else
3703 3703
 		{
3704 3704
 			// Positionne le modele sur le nom du modele a utiliser
3705
-			if (! dol_strlen($modele))
3705
+			if (!dol_strlen($modele))
3706 3706
 			{
3707
-				if (! empty($conf->global->COMPANY_ADDON_PDF))
3707
+				if (!empty($conf->global->COMPANY_ADDON_PDF))
3708 3708
 				{
3709 3709
 					$modele = $conf->global->COMPANY_ADDON_PDF;
3710 3710
 				}
@@ -3717,7 +3717,7 @@  discard block
 block discarded – undo
3717 3717
 
3718 3718
 			$modelpath = "core/modules/societe/doc/";
3719 3719
 
3720
-			$result=$this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3720
+			$result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3721 3721
 		}
3722 3722
 
3723 3723
 		return $result;
@@ -3737,7 +3737,7 @@  discard block
 block discarded – undo
3737 3737
 	 */
3738 3738
 	public function setCategories($categories, $type)
3739 3739
 	{
3740
-		require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
3740
+		require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
3741 3741
 
3742 3742
 		// Decode type
3743 3743
 		if ($type == 'customer') {
@@ -3747,7 +3747,7 @@  discard block
 block discarded – undo
3747 3747
 			$type_id = Categorie::TYPE_SUPPLIER;
3748 3748
 			$type_text = 'supplier';
3749 3749
 		} else {
3750
-			dol_syslog(__METHOD__ . ': Type ' . $type .  'is an unknown company category type. Done nothing.', LOG_ERR);
3750
+			dol_syslog(__METHOD__.': Type '.$type.'is an unknown company category type. Done nothing.', LOG_ERR);
3751 3751
 			return -1;
3752 3752
 		}
3753 3753
 
Please login to merge, or discard this patch.
Braces   +564 added lines, -333 removed lines patch added patch discarded remove patch
@@ -446,15 +446,25 @@  discard block
 block discarded – undo
446 446
 		$error=0;
447 447
 
448 448
 		// Clean parameters
449
-		if (empty($this->status)) $this->status=0;
449
+		if (empty($this->status)) {
450
+			$this->status=0;
451
+		}
450 452
 		$this->name=$this->name?trim($this->name):trim($this->nom);
451
-		if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->name=ucwords($this->name);
453
+		if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) {
454
+			$this->name=ucwords($this->name);
455
+		}
452 456
 		$this->nom=$this->name; // For backward compatibility
453
-		if (empty($this->client))      $this->client=0;
454
-		if (empty($this->fournisseur)) $this->fournisseur=0;
457
+		if (empty($this->client)) {
458
+			$this->client=0;
459
+		}
460
+		if (empty($this->fournisseur)) {
461
+			$this->fournisseur=0;
462
+		}
455 463
 		$this->import_key = trim($this->import_key);
456 464
 
457
-		if (!empty($this->multicurrency_code)) $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code);
465
+		if (!empty($this->multicurrency_code)) {
466
+			$this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code);
467
+		}
458 468
 		if (empty($this->fk_multicurrency))
459 469
 		{
460 470
 			$this->multicurrency_code = '';
@@ -468,8 +478,12 @@  discard block
 block discarded – undo
468 478
 		$this->db->begin();
469 479
 
470 480
 		// For automatic creation during create action (not used by Dolibarr GUI, can be used by scripts)
471
-		if ($this->code_client == -1 || $this->code_client === 'auto')           $this->get_codeclient($this,0);
472
-		if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') $this->get_codefournisseur($this,1);
481
+		if ($this->code_client == -1 || $this->code_client === 'auto') {
482
+			$this->get_codeclient($this,0);
483
+		}
484
+		if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') {
485
+			$this->get_codefournisseur($this,1);
486
+		}
473 487
 
474 488
 		// Check more parameters (including mandatory setup
475 489
 		// If error, this->errors[] is filled
@@ -516,32 +530,32 @@  discard block
 block discarded – undo
516 530
 				{
517 531
 					// Call trigger
518 532
 					$result=$this->call_trigger('COMPANY_CREATE',$user);
519
-					if ($result < 0) $error++;
533
+					if ($result < 0) {
534
+						$error++;
535
+					}
520 536
 					// End call triggers
537
+				} else {
538
+					$error++;
521 539
 				}
522
-				else $error++;
523 540
 
524 541
 				if (! $error)
525 542
 				{
526 543
 					dol_syslog(get_class($this)."::Create success id=".$this->id);
527 544
 					$this->db->commit();
528 545
 					return $this->id;
529
-				}
530
-				else
546
+				} else
531 547
 				{
532 548
 					dol_syslog(get_class($this)."::Create echec update ".$this->error." ".join(',',$this->errors), LOG_ERR);
533 549
 					$this->db->rollback();
534 550
 					return -4;
535 551
 				}
536
-			}
537
-			else
552
+			} else
538 553
 			{
539 554
 				if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
540 555
 				{
541 556
 					$this->error=$langs->trans("ErrorCompanyNameAlreadyExists",$this->name);    // duplicate on a field (code or profid or ...)
542 557
 					$result=-1;
543
-				}
544
-				else
558
+				} else
545 559
 				{
546 560
 					$this->error=$this->db->lasterror();
547 561
 					$result=-2;
@@ -550,8 +564,7 @@  discard block
 block discarded – undo
550 564
 				return $result;
551 565
 			}
552 566
 
553
-		}
554
-		else
567
+		} else
555 568
 		{
556 569
 			$this->db->rollback();
557 570
 			dol_syslog(get_class($this)."::Create fails verify ".join(',',$this->errors), LOG_WARNING);
@@ -703,8 +716,7 @@  discard block
 block discarded – undo
703 716
 						}
704 717
 					}
705 718
 				}
706
-			}
707
-			else
719
+			} else
708 720
 			{
709 721
 				//var_dump($conf->global->SOCIETE_EMAIL_UNIQUE);
710 722
 				//var_dump($conf->global->SOCIETE_EMAIL_MANDATORY);
@@ -731,7 +743,9 @@  discard block
 block discarded – undo
731 743
 			}
732 744
 		}
733 745
 
734
-		if ($error) $result = -4;
746
+		if ($error) {
747
+			$result = -4;
748
+		}
735 749
 
736 750
 		return $result;
737 751
 	}
@@ -753,7 +767,9 @@  discard block
 block discarded – undo
753 767
 		global $langs,$conf,$hookmanager;
754 768
 		require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
755 769
 
756
-		if (empty($id)) $id = $this->id;
770
+		if (empty($id)) {
771
+			$id = $this->id;
772
+		}
757 773
 
758 774
 		$error=0;
759 775
 
@@ -796,9 +812,13 @@  discard block
 block discarded – undo
796 812
 
797 813
 		$this->tva_assuj	= trim($this->tva_assuj);
798 814
 		$this->tva_intra	= dol_sanitizeFileName($this->tva_intra,'');
799
-		if (empty($this->status)) $this->status = 0;
815
+		if (empty($this->status)) {
816
+			$this->status = 0;
817
+		}
800 818
 
801
-		if (!empty($this->multicurrency_code)) $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code);
819
+		if (!empty($this->multicurrency_code)) {
820
+			$this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code);
821
+		}
802 822
 		if (empty($this->fk_multicurrency))
803 823
 		{
804 824
 			$this->multicurrency_code = '';
@@ -812,8 +832,13 @@  discard block
 block discarded – undo
812 832
 		$this->localtax1_value=trim($this->localtax1_value);
813 833
 		$this->localtax2_value=trim($this->localtax2_value);
814 834
 
815
-		if ($this->capital != '') $this->capital=price2num(trim($this->capital));
816
-		if (! is_numeric($this->capital)) $this->capital = '';     // '' = undef
835
+		if ($this->capital != '') {
836
+			$this->capital=price2num(trim($this->capital));
837
+		}
838
+		if (! is_numeric($this->capital)) {
839
+			$this->capital = '';
840
+		}
841
+		// '' = undef
817 842
 
818 843
 		$this->effectif_id=trim($this->effectif_id);
819 844
 		$this->forme_juridique_code=trim($this->forme_juridique_code);
@@ -822,8 +847,12 @@  discard block
 block discarded – undo
822 847
 		$this->barcode=trim($this->barcode);
823 848
 
824 849
 		// For automatic creation
825
-		if ($this->code_client == -1 || $this->code_client === 'auto')           $this->get_codeclient($this,0);
826
-		if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') $this->get_codefournisseur($this,1);
850
+		if ($this->code_client == -1 || $this->code_client === 'auto') {
851
+			$this->get_codeclient($this,0);
852
+		}
853
+		if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') {
854
+			$this->get_codefournisseur($this,1);
855
+		}
827 856
 
828 857
 		$this->code_compta=trim($this->code_compta);
829 858
 		$this->code_compta_fournisseur=trim($this->code_compta_fournisseur);
@@ -843,7 +872,9 @@  discard block
 block discarded – undo
843 872
 			if (empty($this->code_compta))
844 873
 			{
845 874
 				$ret=$this->get_codecompta('customer');
846
-				if ($ret < 0) return -1;
875
+				if ($ret < 0) {
876
+					return -1;
877
+				}
847 878
 			}
848 879
 
849 880
 			$customer=true;
@@ -856,7 +887,9 @@  discard block
 block discarded – undo
856 887
 			if (empty($this->code_compta_fournisseur))
857 888
 			{
858 889
 				$ret=$this->get_codecompta('supplier');
859
-				if ($ret < 0) return -1;
890
+				if ($ret < 0) {
891
+					return -1;
892
+				}
860 893
 			}
861 894
 
862 895
 			$supplier=true;
@@ -926,22 +959,26 @@  discard block
 block discarded – undo
926 959
 				if($this->localtax1_value!='')
927 960
 				{
928 961
 					$sql .=",localtax1_value =".$this->localtax1_value;
962
+				} else {
963
+					$sql .=",localtax1_value =0.000";
929 964
 				}
930
-				else $sql .=",localtax1_value =0.000";
931 965
 
966
+			} else {
967
+				$sql .=",localtax1_value =0.000";
932 968
 			}
933
-			else $sql .=",localtax1_value =0.000";
934 969
 
935 970
 			if($this->localtax2_assuj==1)
936 971
 			{
937 972
 				if($this->localtax2_value!='')
938 973
 				{
939 974
 					$sql .=",localtax2_value =".$this->localtax2_value;
975
+				} else {
976
+					$sql .=",localtax2_value =0.000";
940 977
 				}
941
-				else $sql .=",localtax2_value =0.000";
942 978
 
979
+			} else {
980
+				$sql .=",localtax2_value =0.000";
943 981
 			}
944
-			else $sql .=",localtax2_value =0.000";
945 982
 
946 983
 			$sql .= ",capital = ".($this->capital == '' ? "null" : $this->capital);
947 984
 
@@ -1034,8 +1071,7 @@  discard block
 block discarded – undo
1034 1071
 								dol_syslog(get_class($this)."::update ".$this->error,LOG_ERR);
1035 1072
 								$error++;
1036 1073
 							}
1037
-						}
1038
-						else if ($result < 0)
1074
+						} else if ($result < 0)
1039 1075
 						{
1040 1076
 							$this->error=$lmember->error;
1041 1077
 							$error++;
@@ -1052,22 +1088,27 @@  discard block
 block discarded – undo
1052 1088
 				$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
1053 1089
 				if (empty($reshook))
1054 1090
 				{
1055
-					if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
1091
+					if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) {
1092
+						// For avoid conflicts if trigger used
1056 1093
 					{
1057 1094
 						$result=$this->insertExtraFields();
1095
+					}
1058 1096
 						if ($result < 0)
1059 1097
 						{
1060 1098
 							$error++;
1061 1099
 						}
1062 1100
 					}
1101
+				} else if ($reshook < 0) {
1102
+					$error++;
1063 1103
 				}
1064
-				else if ($reshook < 0) $error++;
1065 1104
 
1066 1105
 				if (! $error && $call_trigger)
1067 1106
 				{
1068 1107
 					// Call trigger
1069 1108
 					$result=$this->call_trigger('COMPANY_MODIFY',$user);
1070
-					if ($result < 0) $error++;
1109
+					if ($result < 0) {
1110
+						$error++;
1111
+					}
1071 1112
 					// End call triggers
1072 1113
 				}
1073 1114
 
@@ -1076,22 +1117,19 @@  discard block
 block discarded – undo
1076 1117
 					dol_syslog(get_class($this)."::Update success");
1077 1118
 					$this->db->commit();
1078 1119
 					return 1;
1079
-				}
1080
-				else
1120
+				} else
1081 1121
 				{
1082 1122
 					$this->db->rollback();
1083 1123
 					return -1;
1084 1124
 				}
1085
-			}
1086
-			else
1125
+			} else
1087 1126
 			{
1088 1127
 				if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
1089 1128
 				{
1090 1129
 					// Doublon
1091 1130
 					$this->error = $langs->trans("ErrorDuplicateField");
1092 1131
 					$result = -1;
1093
-				}
1094
-				else
1132
+				} else
1095 1133
 				{
1096 1134
 					$this->error = $this->db->lasterror();
1097 1135
 					$result = -2;
@@ -1099,8 +1137,7 @@  discard block
 block discarded – undo
1099 1137
 				$this->db->rollback();
1100 1138
 				return $result;
1101 1139
 			}
1102
-		}
1103
-		else
1140
+		} else
1104 1141
 	   {
1105 1142
 			$this->db->rollback();
1106 1143
 			dol_syslog(get_class($this)."::Update fails verify ".join(',',$this->errors), LOG_WARNING);
@@ -1130,7 +1167,9 @@  discard block
 block discarded – undo
1130 1167
 		global $langs;
1131 1168
 		global $conf;
1132 1169
 
1133
-		if (empty($rowid) && empty($ref) && empty($ref_ext) && empty($ref_int) && empty($idprof1) && empty($idprof2) && empty($idprof3) && empty($idprof4) && empty($idprof5) && empty($idprof6) && empty($email)) return -1;
1170
+		if (empty($rowid) && empty($ref) && empty($ref_ext) && empty($ref_int) && empty($idprof1) && empty($idprof2) && empty($idprof3) && empty($idprof4) && empty($idprof5) && empty($idprof6) && empty($email)) {
1171
+			return -1;
1172
+		}
1134 1173
 
1135 1174
 		$sql = 'SELECT s.rowid, s.nom as name, s.name_alias, s.entity, s.ref_ext, s.ref_int, s.address, s.datec as date_creation, s.prefix_comm';
1136 1175
 		$sql .= ', s.status';
@@ -1167,18 +1206,42 @@  discard block
 block discarded – undo
1167 1206
 		$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON s.fk_incoterms = i.rowid';
1168 1207
 
1169 1208
 		$sql .= ' WHERE s.entity IN ('.getEntity($this->element).')';
1170
-		if ($rowid)     $sql .= ' AND s.rowid = '.$rowid;
1171
-		if ($ref)       $sql .= " AND s.nom = '".$this->db->escape($ref)."'";
1172
-		if ($ref_alias) $sql .= " AND s.nom_alias = '".$this->db->escape($nom_alias)."'";
1173
-		if ($ref_ext)   $sql .= " AND s.ref_ext = '".$this->db->escape($ref_ext)."'";
1174
-		if ($ref_int)   $sql .= " AND s.ref_int = '".$this->db->escape($ref_int)."'";
1175
-		if ($idprof1)   $sql .= " AND s.siren = '".$this->db->escape($idprof1)."'";
1176
-		if ($idprof2)   $sql .= " AND s.siret = '".$this->db->escape($idprof2)."'";
1177
-		if ($idprof3)   $sql .= " AND s.ape = '".$this->db->escape($idprof3)."'";
1178
-		if ($idprof4)   $sql .= " AND s.idprof4 = '".$this->db->escape($idprof4)."'";
1179
-		if ($idprof5)   $sql .= " AND s.idprof5 = '".$this->db->escape($idprof5)."'";
1180
-		if ($idprof6)   $sql .= " AND s.idprof6 = '".$this->db->escape($idprof6)."'";
1181
-		if ($email)     $sql .= " AND s.email = '".$this->db->escape($email)."'";
1209
+		if ($rowid) {
1210
+			$sql .= ' AND s.rowid = '.$rowid;
1211
+		}
1212
+		if ($ref) {
1213
+			$sql .= " AND s.nom = '".$this->db->escape($ref)."'";
1214
+		}
1215
+		if ($ref_alias) {
1216
+			$sql .= " AND s.nom_alias = '".$this->db->escape($nom_alias)."'";
1217
+		}
1218
+		if ($ref_ext) {
1219
+			$sql .= " AND s.ref_ext = '".$this->db->escape($ref_ext)."'";
1220
+		}
1221
+		if ($ref_int) {
1222
+			$sql .= " AND s.ref_int = '".$this->db->escape($ref_int)."'";
1223
+		}
1224
+		if ($idprof1) {
1225
+			$sql .= " AND s.siren = '".$this->db->escape($idprof1)."'";
1226
+		}
1227
+		if ($idprof2) {
1228
+			$sql .= " AND s.siret = '".$this->db->escape($idprof2)."'";
1229
+		}
1230
+		if ($idprof3) {
1231
+			$sql .= " AND s.ape = '".$this->db->escape($idprof3)."'";
1232
+		}
1233
+		if ($idprof4) {
1234
+			$sql .= " AND s.idprof4 = '".$this->db->escape($idprof4)."'";
1235
+		}
1236
+		if ($idprof5) {
1237
+			$sql .= " AND s.idprof5 = '".$this->db->escape($idprof5)."'";
1238
+		}
1239
+		if ($idprof6) {
1240
+			$sql .= " AND s.idprof6 = '".$this->db->escape($idprof6)."'";
1241
+		}
1242
+		if ($email) {
1243
+			$sql .= " AND s.email = '".$this->db->escape($email)."'";
1244
+		}
1182 1245
 
1183 1246
 		$resql=$this->db->query($sql);
1184 1247
 		if ($resql)
@@ -1189,10 +1252,11 @@  discard block
 block discarded – undo
1189 1252
 				$this->error='Fetch found several records. Rename one of tirdparties to avoid duplicate.';
1190 1253
 				dol_syslog($this->error, LOG_ERR);
1191 1254
 				$result = -2;
1192
-			}
1193
-			elseif ($num)   // $num = 1
1255
+			} elseif ($num) {
1256
+				// $num = 1
1194 1257
 			{
1195 1258
 				$obj = $this->db->fetch_object($resql);
1259
+			}
1196 1260
 
1197 1261
 				$this->id           = $obj->rowid;
1198 1262
 				$this->entity       = $obj->entity;
@@ -1320,22 +1384,22 @@  discard block
 block discarded – undo
1320 1384
 				// Retreive all extrafield
1321 1385
 				// fetch optionals attributes and labels
1322 1386
 				$this->fetch_optionals();
1323
-			}
1324
-			else
1387
+			} else
1325 1388
 			{
1326 1389
 				$result = 0;
1327 1390
 			}
1328 1391
 
1329 1392
 			$this->db->free($resql);
1330
-		}
1331
-		else
1393
+		} else
1332 1394
 		{
1333 1395
 			$this->error=$this->db->lasterror();
1334 1396
 			$result = -3;
1335 1397
 		}
1336 1398
 
1337 1399
 		// Use first price level if level not defined for third party
1338
-		if (! empty($conf->global->PRODUIT_MULTIPRICES) && empty($this->price_level)) $this->price_level=1;
1400
+		if (! empty($conf->global->PRODUIT_MULTIPRICES) && empty($this->price_level)) {
1401
+			$this->price_level=1;
1402
+		}
1339 1403
 
1340 1404
 		return $result;
1341 1405
 	}
@@ -1370,10 +1434,11 @@  discard block
 block discarded – undo
1370 1434
 		$sql.= " WHERE entity IN (".getEntity('category').")";
1371 1435
 		if (! empty($type))
1372 1436
 		{
1373
-			if ($type == 1 || $type == 2)
1374
-				$sql.= " AND client = ".$type;
1375
-			elseif ($type == 3)
1376
-				$sql.= " AND fournisseur = 1";
1437
+			if ($type == 1 || $type == 2) {
1438
+							$sql.= " AND client = ".$type;
1439
+			} elseif ($type == 3) {
1440
+							$sql.= " AND fournisseur = 1";
1441
+			}
1377 1442
 		}
1378 1443
 		if (! empty($name))
1379 1444
 		{
@@ -1382,27 +1447,27 @@  discard block
 block discarded – undo
1382 1447
 				if (preg_match('/^([\*])?[^*]+([\*])?$/', $name, $regs) && count($regs) > 1)
1383 1448
 				{
1384 1449
 					$name = str_replace('*', '%', $name);
1385
-				}
1386
-				else
1450
+				} else
1387 1451
 				{
1388 1452
 					$name = '%'.$name.'%';
1389 1453
 				}
1390 1454
 			}
1391 1455
 			$sql.= " AND ";
1392
-			if (is_array($filters) && ! empty($filters))
1393
-				$sql.= "(";
1456
+			if (is_array($filters) && ! empty($filters)) {
1457
+							$sql.= "(";
1458
+			}
1394 1459
 			if ($similar)
1395 1460
 			{
1396 1461
 				// For test similitude (string inside name into database, or name into database inside string)
1397 1462
 				// Do not use this. Not compatible with other database.
1398 1463
 				$sql.= "(LOCATE('".$this->db->escape($name)."', nom) > 0 OR LOCATE(nom, '".$this->db->escape($name)."') > 0)";
1399
-			}
1400
-			else
1464
+			} else
1401 1465
 			{
1402
-				if (! $case)
1403
-					$sql.= "nom LIKE '".$this->db->escape($name)."'";
1404
-				else
1405
-					$sql.= "nom LIKE BINARY '".$this->db->escape($name)."'";
1466
+				if (! $case) {
1467
+									$sql.= "nom LIKE '".$this->db->escape($name)."'";
1468
+				} else {
1469
+									$sql.= "nom LIKE BINARY '".$this->db->escape($name)."'";
1470
+				}
1406 1471
 			}
1407 1472
 		}
1408 1473
 		if (is_array($filters) && ! empty($filters))
@@ -1414,19 +1479,20 @@  discard block
 block discarded – undo
1414 1479
 					if (preg_match('/^([\*])?[^*]+([\*])?$/', $value, $regs) && count($regs) > 1)
1415 1480
 					{
1416 1481
 						$value = str_replace('*', '%', $value);
1417
-					}
1418
-					else
1482
+					} else
1419 1483
 					{
1420 1484
 						$value = '%'.$value.'%';
1421 1485
 					}
1422 1486
 				}
1423
-				if (! $case)
1424
-					$sql.= " ".$clause." ".$field." LIKE '".$this->db->escape($value)."'";
1425
-				else
1426
-					$sql.= " ".$clause." ".$field." LIKE BINARY '".$this->db->escape($value)."'";
1487
+				if (! $case) {
1488
+									$sql.= " ".$clause." ".$field." LIKE '".$this->db->escape($value)."'";
1489
+				} else {
1490
+									$sql.= " ".$clause." ".$field." LIKE BINARY '".$this->db->escape($value)."'";
1491
+				}
1492
+			}
1493
+			if (! empty($name)) {
1494
+							$sql.= ")";
1427 1495
 			}
1428
-			if (! empty($name))
1429
-				$sql.= ")";
1430 1496
 		}
1431 1497
 
1432 1498
 		$res  = $this->db->query($sql);
@@ -1440,8 +1506,7 @@  discard block
 block discarded – undo
1440 1506
 			}
1441 1507
 
1442 1508
 			return $thirdparties;
1443
-		}
1444
-		else
1509
+		} else
1445 1510
 		{
1446 1511
 			$this->error=$this->db->lasterror();
1447 1512
 			return -1;
@@ -1460,7 +1525,9 @@  discard block
 block discarded – undo
1460 1525
 	{
1461 1526
 		global $langs, $conf, $user;
1462 1527
 
1463
-		if (empty($fuser)) $fuser=$user;
1528
+		if (empty($fuser)) {
1529
+			$fuser=$user;
1530
+		}
1464 1531
 
1465 1532
 		require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1466 1533
 
@@ -1480,7 +1547,9 @@  discard block
 block discarded – undo
1480 1547
 			{
1481 1548
 				// Call trigger
1482 1549
 				$result=$this->call_trigger('COMPANY_DELETE',$fuser);
1483
-				if ($result < 0) $error++;
1550
+				if ($result < 0) {
1551
+					$error++;
1552
+				}
1484 1553
 				// End call triggers
1485 1554
 			}
1486 1555
 
@@ -1525,9 +1594,11 @@  discard block
 block discarded – undo
1525 1594
 			}
1526 1595
 
1527 1596
 			// Removed extrafields
1528
-			if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used
1597
+			if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) {
1598
+				// For avoid conflicts if trigger used
1529 1599
 			{
1530 1600
 				$result=$this->deleteExtraFields();
1601
+			}
1531 1602
 				if ($result < 0)
1532 1603
 				{
1533 1604
 					$error++;
@@ -1562,15 +1633,15 @@  discard block
 block discarded – undo
1562 1633
 				}
1563 1634
 
1564 1635
 				return 1;
1565
-			}
1566
-			else
1636
+			} else
1567 1637
 			{
1568 1638
 				dol_syslog($this->error, LOG_ERR);
1569 1639
 				$this->db->rollback();
1570 1640
 				return -1;
1571 1641
 			}
1642
+		} else {
1643
+			dol_syslog("Can't remove thirdparty with id ".$id.". There is ".$objectisused." childs", LOG_WARNING);
1572 1644
 		}
1573
-		else dol_syslog("Can't remove thirdparty with id ".$id.". There is ".$objectisused." childs", LOG_WARNING);
1574 1645
 		return 0;
1575 1646
 	}
1576 1647
 
@@ -1584,7 +1655,10 @@  discard block
 block discarded – undo
1584 1655
 		if ($this->id)
1585 1656
 		{
1586 1657
 			$newclient=1;
1587
-			if ($this->client == 2 || $this->client == 3) $newclient=3;	//If prospect, we keep prospect tag
1658
+			if ($this->client == 2 || $this->client == 3) {
1659
+				$newclient=3;
1660
+			}
1661
+			//If prospect, we keep prospect tag
1588 1662
 			$sql = "UPDATE ".MAIN_DB_PREFIX."societe";
1589 1663
 			$sql.= " SET client = ".$newclient;
1590 1664
 			$sql.= " WHERE rowid = " . $this->id;
@@ -1594,8 +1668,9 @@  discard block
 block discarded – undo
1594 1668
 			{
1595 1669
 				$this->client = $newclient;
1596 1670
 				return 1;
1671
+			} else {
1672
+				return -1;
1597 1673
 			}
1598
-			else return -1;
1599 1674
 		}
1600 1675
 		return 0;
1601 1676
 	}
@@ -1705,14 +1780,14 @@  discard block
 block discarded – undo
1705 1780
 			if ($result > 0)
1706 1781
 			{
1707 1782
 				return $result;
1708
-			}
1709
-			else
1783
+			} else
1710 1784
 			{
1711 1785
 				$this->error=$discount->error;
1712 1786
 				return -3;
1713 1787
 			}
1788
+		} else {
1789
+			return 0;
1714 1790
 		}
1715
-		else return 0;
1716 1791
 	}
1717 1792
 
1718 1793
 	/**
@@ -1732,8 +1807,7 @@  discard block
 block discarded – undo
1732 1807
 		if ($result >= 0)
1733 1808
 		{
1734 1809
 			return $result;
1735
-		}
1736
-		else
1810
+		} else
1737 1811
 		{
1738 1812
 			$this->error=$discountstatic->error;
1739 1813
 			return -1;
@@ -1760,9 +1834,9 @@  discard block
 block discarded – undo
1760 1834
 			$sql.= " WHERE ((ug.fk_user = sc.fk_user";
1761 1835
 			$sql.= " AND ug.entity = ".$conf->entity.")";
1762 1836
 			$sql.= " OR u.admin = 1)";
1837
+		} else {
1838
+					$sql.= " WHERE entity in (0, ".$conf->entity.")";
1763 1839
 		}
1764
-		else
1765
-			$sql.= " WHERE entity in (0, ".$conf->entity.")";
1766 1840
 
1767 1841
 		$sql.= " AND u.rowid = sc.fk_user AND sc.fk_soc = ".$this->id;
1768 1842
 
@@ -1785,8 +1859,7 @@  discard block
 block discarded – undo
1785 1859
 				$i++;
1786 1860
 			}
1787 1861
 			return $reparray;
1788
-		}
1789
-		else {
1862
+		} else {
1790 1863
 			dol_print_error($this->db);
1791 1864
 			return -1;
1792 1865
 		}
@@ -1892,7 +1965,10 @@  discard block
 block discarded – undo
1892 1965
 	{
1893 1966
 		global $conf, $langs, $hookmanager;
1894 1967
 
1895
-		if (! empty($conf->dol_no_mouse_hover)) $notooltip=1;   // Force disable tooltips
1968
+		if (! empty($conf->dol_no_mouse_hover)) {
1969
+			$notooltip=1;
1970
+		}
1971
+		// Force disable tooltips
1896 1972
 
1897 1973
 		$name=$this->name?$this->name:$this->nom;
1898 1974
 
@@ -1902,23 +1978,28 @@  discard block
 block discarded – undo
1902 1978
 				&& ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1
1903 1979
 				|| $conf->global->SOCIETE_ADD_REF_IN_LIST == 2
1904 1980
 				)
1905
-			)
1906
-			$code = $this->code_client . ' - ';
1981
+			) {
1982
+						$code = $this->code_client . ' - ';
1983
+			}
1907 1984
 
1908 1985
 			if (($this->fournisseur) && (! empty ( $this->code_fournisseur ))
1909 1986
 				&& ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1
1910 1987
 				|| $conf->global->SOCIETE_ADD_REF_IN_LIST == 3
1911 1988
 				)
1912
-			)
1913
-			$code .= $this->code_fournisseur . ' - ';
1989
+			) {
1990
+						$code .= $this->code_fournisseur . ' - ';
1991
+			}
1914 1992
 
1915
-			if ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1)
1916
-				$name =$code.' '.$name;
1917
-			else
1918
-				$name =$code;
1993
+			if ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1) {
1994
+							$name =$code.' '.$name;
1995
+			} else {
1996
+							$name =$code;
1997
+			}
1919 1998
 		}
1920 1999
 
1921
-		if (!empty($this->name_alias)) $name .= ' ('.$this->name_alias.')';
2000
+		if (!empty($this->name_alias)) {
2001
+			$name .= ' ('.$this->name_alias.')';
2002
+		}
1922 2003
 
1923 2004
 		$result=''; $label='';
1924 2005
 		$linkstart=''; $linkend='';
@@ -1936,38 +2017,31 @@  discard block
 block discarded – undo
1936 2017
 		{
1937 2018
 		   $label.= '<u>' . $langs->trans("ShowCustomer") . '</u>';
1938 2019
 		   $linkstart = '<a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$this->id;
1939
-		}
1940
-		else if ($option == 'prospect' && empty($conf->global->SOCIETE_DISABLE_PROSPECTS))
2020
+		} else if ($option == 'prospect' && empty($conf->global->SOCIETE_DISABLE_PROSPECTS))
1941 2021
 		{
1942 2022
 			$label.= '<u>' . $langs->trans("ShowProspect") . '</u>';
1943 2023
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$this->id;
1944
-		}
1945
-		else if ($option == 'supplier')
2024
+		} else if ($option == 'supplier')
1946 2025
 		{
1947 2026
 			$label.= '<u>' . $langs->trans("ShowSupplier") . '</u>';
1948 2027
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$this->id;
1949
-		}
1950
-		else if ($option == 'agenda')
2028
+		} else if ($option == 'agenda')
1951 2029
 		{
1952 2030
 			$label.= '<u>' . $langs->trans("ShowAgenda") . '</u>';
1953 2031
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/societe/agenda.php?socid='.$this->id;
1954
-		}
1955
-		else if ($option == 'project')
2032
+		} else if ($option == 'project')
1956 2033
 		{
1957 2034
 			$label.= '<u>' . $langs->trans("ShowProject") . '</u>';
1958 2035
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/societe/project.php?socid='.$this->id;
1959
-		}
1960
-		else if ($option == 'margin')
2036
+		} else if ($option == 'margin')
1961 2037
 		{
1962 2038
 			$label.= '<u>' . $langs->trans("ShowMargin") . '</u>';
1963 2039
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/margin/tabs/thirdpartyMargins.php?socid='.$this->id.'&type=1';
1964
-		}
1965
-		else if ($option == 'contact')
2040
+		} else if ($option == 'contact')
1966 2041
 		{
1967 2042
 			$label.= '<u>' . $langs->trans("ShowContacts") . '</u>';
1968 2043
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/societe/contact.php?socid='.$this->id;
1969
-		}
1970
-		else if ($option == 'ban')
2044
+		} else if ($option == 'ban')
1971 2045
 		{
1972 2046
 			$label.= '<u>' . $langs->trans("ShowBan") . '</u>';
1973 2047
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/societe/rib.php?socid='.$this->id;
@@ -1983,21 +2057,29 @@  discard block
 block discarded – undo
1983 2057
 		if (! empty($this->name))
1984 2058
 		{
1985 2059
 			$label.= '<br><b>' . $langs->trans('Name') . ':</b> '. $this->name;
1986
-			if (! empty($this->name_alias)) $label.=' ('.$this->name_alias.')';
2060
+			if (! empty($this->name_alias)) {
2061
+				$label.=' ('.$this->name_alias.')';
2062
+			}
1987 2063
 			$label.= '<br><b>' . $langs->trans('Email') . ':</b> '. $this->email;
1988 2064
 		}
1989
-		if (! empty($this->country_code))
1990
-			$label.= '<br><b>' . $langs->trans('Country') . ':</b> '. $this->country_code;
1991
-		if (! empty($this->tva_intra))
1992
-			$label.= '<br><b>' . $langs->trans('VATIntra') . ':</b> '. $this->tva_intra;
1993
-		if (! empty($this->code_client) && $this->client)
1994
-			$label.= '<br><b>' . $langs->trans('CustomerCode') . ':</b> '. $this->code_client;
1995
-		if (! empty($this->code_fournisseur) && $this->fournisseur)
1996
-			$label.= '<br><b>' . $langs->trans('SupplierCode') . ':</b> '. $this->code_fournisseur;
1997
-		if (! empty($conf->accounting->enabled) && $this->client)
1998
-			$label.= '<br><b>' . $langs->trans('CustomerAccountancyCode') . ':</b> '. ($this->code_compta ? $this->code_compta : $this->code_compta_client);
1999
-		if (! empty($conf->accounting->enabled) && $this->fournisseur)
2000
-			$label.= '<br><b>' . $langs->trans('SupplierAccountancyCode') . ':</b> '. $this->code_compta_fournisseur;
2065
+		if (! empty($this->country_code)) {
2066
+					$label.= '<br><b>' . $langs->trans('Country') . ':</b> '. $this->country_code;
2067
+		}
2068
+		if (! empty($this->tva_intra)) {
2069
+					$label.= '<br><b>' . $langs->trans('VATIntra') . ':</b> '. $this->tva_intra;
2070
+		}
2071
+		if (! empty($this->code_client) && $this->client) {
2072
+					$label.= '<br><b>' . $langs->trans('CustomerCode') . ':</b> '. $this->code_client;
2073
+		}
2074
+		if (! empty($this->code_fournisseur) && $this->fournisseur) {
2075
+					$label.= '<br><b>' . $langs->trans('SupplierCode') . ':</b> '. $this->code_fournisseur;
2076
+		}
2077
+		if (! empty($conf->accounting->enabled) && $this->client) {
2078
+					$label.= '<br><b>' . $langs->trans('CustomerAccountancyCode') . ':</b> '. ($this->code_compta ? $this->code_compta : $this->code_compta_client);
2079
+		}
2080
+		if (! empty($conf->accounting->enabled) && $this->fournisseur) {
2081
+					$label.= '<br><b>' . $langs->trans('SupplierAccountancyCode') . ':</b> '. $this->code_compta_fournisseur;
2082
+		}
2001 2083
 
2002 2084
 		$label.= '</div>';
2003 2085
 
@@ -2005,8 +2087,12 @@  discard block
 block discarded – undo
2005 2087
 		$linkstart.=(!empty($this->canvas)?'&canvas='.$this->canvas:'');
2006 2088
 		// Add param to save lastsearch_values or not
2007 2089
 		$add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
2008
-		if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
2009
-		if ($add_save_lastsearch_values) $linkstart.='&save_lastsearch_values=1';
2090
+		if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) {
2091
+			$add_save_lastsearch_values=1;
2092
+		}
2093
+		if ($add_save_lastsearch_values) {
2094
+			$linkstart.='&save_lastsearch_values=1';
2095
+		}
2010 2096
 		$linkstart.='"';
2011 2097
 
2012 2098
 		$linkclose='';
@@ -2028,7 +2114,9 @@  discard block
 block discarded – undo
2028 2114
 			$hookmanager->initHooks(array('societedao'));
2029 2115
 			$parameters=array('id'=>$this->id);
2030 2116
 			$reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
2031
-			if ($reshook > 0) $linkclose = $hookmanager->resPrint;
2117
+			if ($reshook > 0) {
2118
+				$linkclose = $hookmanager->resPrint;
2119
+			}
2032 2120
 		}
2033 2121
 		$linkstart.=$linkclose.'>';
2034 2122
 		$linkend='</a>';
@@ -2041,8 +2129,12 @@  discard block
 block discarded – undo
2041 2129
 		}
2042 2130
 
2043 2131
 		$result.=$linkstart;
2044
-		if ($withpicto) $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip valigntextbottom"'), 0, 0, $notooltip?0:1);
2045
-		if ($withpicto != 2) $result.=($maxlen?dol_trunc($name,$maxlen):$name);
2132
+		if ($withpicto) {
2133
+			$result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip valigntextbottom"'), 0, 0, $notooltip?0:1);
2134
+		}
2135
+		if ($withpicto != 2) {
2136
+			$result.=($maxlen?dol_trunc($name,$maxlen):$name);
2137
+		}
2046 2138
 		$result.=$linkend;
2047 2139
 
2048 2140
 		return $result;
@@ -2073,38 +2165,66 @@  discard block
 block discarded – undo
2073 2165
 
2074 2166
 		if ($mode == 0)
2075 2167
 		{
2076
-			if ($statut==0) return $langs->trans("ActivityCeased");
2077
-			if ($statut==1) return $langs->trans("InActivity");
2168
+			if ($statut==0) {
2169
+				return $langs->trans("ActivityCeased");
2170
+			}
2171
+			if ($statut==1) {
2172
+				return $langs->trans("InActivity");
2173
+			}
2078 2174
 		}
2079 2175
 		if ($mode == 1)
2080 2176
 		{
2081
-			if ($statut==0) return $langs->trans("ActivityCeased");
2082
-			if ($statut==1) return $langs->trans("InActivity");
2177
+			if ($statut==0) {
2178
+				return $langs->trans("ActivityCeased");
2179
+			}
2180
+			if ($statut==1) {
2181
+				return $langs->trans("InActivity");
2182
+			}
2083 2183
 		}
2084 2184
 		if ($mode == 2)
2085 2185
 		{
2086
-			if ($statut==0) return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"').' '.$langs->trans("ActivityCeased");
2087
-			if ($statut==1) return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"').' '.$langs->trans("InActivity");
2186
+			if ($statut==0) {
2187
+				return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"').' '.$langs->trans("ActivityCeased");
2188
+			}
2189
+			if ($statut==1) {
2190
+				return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"').' '.$langs->trans("InActivity");
2191
+			}
2088 2192
 		}
2089 2193
 		if ($mode == 3)
2090 2194
 		{
2091
-			if ($statut==0) return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"');
2092
-			if ($statut==1) return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"');
2195
+			if ($statut==0) {
2196
+				return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"');
2197
+			}
2198
+			if ($statut==1) {
2199
+				return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"');
2200
+			}
2093 2201
 		}
2094 2202
 		if ($mode == 4)
2095 2203
 		{
2096
-			if ($statut==0) return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"').' '.$langs->trans("ActivityCeased");
2097
-			if ($statut==1) return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"').' '.$langs->trans("InActivity");
2204
+			if ($statut==0) {
2205
+				return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"').' '.$langs->trans("ActivityCeased");
2206
+			}
2207
+			if ($statut==1) {
2208
+				return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"').' '.$langs->trans("InActivity");
2209
+			}
2098 2210
 		}
2099 2211
 		if ($mode == 5)
2100 2212
 		{
2101
-			if ($statut==0) return '<span class="hideonsmartphone">'.$langs->trans("ActivityCeased").'</span> '.img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"');
2102
-			if ($statut==1) return '<span class="hideonsmartphone">'.$langs->trans("InActivity").'</span> '.img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"');
2213
+			if ($statut==0) {
2214
+				return '<span class="hideonsmartphone">'.$langs->trans("ActivityCeased").'</span> '.img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"');
2215
+			}
2216
+			if ($statut==1) {
2217
+				return '<span class="hideonsmartphone">'.$langs->trans("InActivity").'</span> '.img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"');
2218
+			}
2103 2219
 		}
2104 2220
 		if ($mode == 6)
2105 2221
 		{
2106
-			if ($statut==0) return '<span class="hideonsmartphone">'.$langs->trans("ActivityCeased").'</span> '.img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"');
2107
-			if ($statut==1) return '<span class="hideonsmartphone">'.$langs->trans("InActivity").'</span> '.img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"');
2222
+			if ($statut==0) {
2223
+				return '<span class="hideonsmartphone">'.$langs->trans("ActivityCeased").'</span> '.img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"');
2224
+			}
2225
+			if ($statut==1) {
2226
+				return '<span class="hideonsmartphone">'.$langs->trans("InActivity").'</span> '.img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"');
2227
+			}
2108 2228
 		}
2109 2229
 	}
2110 2230
 
@@ -2121,7 +2241,9 @@  discard block
 block discarded – undo
2121 2241
 		$contact_emails = $this->contact_property_array('email',1);
2122 2242
 		if ($this->email && $addthirdparty)
2123 2243
 		{
2124
-			if (empty($this->name)) $this->name=$this->nom;
2244
+			if (empty($this->name)) {
2245
+				$this->name=$this->nom;
2246
+			}
2125 2247
 			$contact_emails['thirdparty']=$langs->transnoentitiesnoconv("ThirdParty").': '.dol_trunc($this->name,16)." <".$this->email.">";
2126 2248
 		}
2127 2249
 		//var_dump($contact_emails)
@@ -2139,9 +2261,11 @@  discard block
 block discarded – undo
2139 2261
 
2140 2262
 		$contact_phone = $this->contact_property_array('mobile');
2141 2263
 
2142
-		if (! empty($this->phone))	// If a phone of thirdparty is defined, we add it ot mobile of contacts
2264
+		if (! empty($this->phone)) {
2265
+			// If a phone of thirdparty is defined, we add it ot mobile of contacts
2143 2266
 		{
2144 2267
 			if (empty($this->name)) $this->name=$this->nom;
2268
+		}
2145 2269
 			// TODO: Tester si tel non deja present dans tableau contact
2146 2270
 			$contact_phone['thirdparty']=$langs->transnoentitiesnoconv("ThirdParty").': '.dol_trunc($this->name,16)." <".$this->phone.">";
2147 2271
 		}
@@ -2182,24 +2306,30 @@  discard block
 block discarded – undo
2182 2306
 				while ($i < $nump)
2183 2307
 				{
2184 2308
 					$obj = $this->db->fetch_object($resql);
2185
-					if ($mode == 'email') $property=$obj->email;
2186
-					else if ($mode == 'mobile') $property=$obj->phone_mobile;
2187
-					else $property=$obj->$mode;
2309
+					if ($mode == 'email') {
2310
+						$property=$obj->email;
2311
+					} else if ($mode == 'mobile') {
2312
+						$property=$obj->phone_mobile;
2313
+					} else {
2314
+						$property=$obj->$mode;
2315
+					}
2188 2316
 
2189 2317
 					// Show all contact. If hidedisabled is 1, showonly contacts with status = 1
2190 2318
 					if ($obj->statut == 1 || empty($hidedisabled))
2191 2319
 					{
2192 2320
 						if (empty($property))
2193 2321
 						{
2194
-							if ($mode == 'email') $property=$langs->transnoentitiesnoconv("NoEMail");
2195
-							else if ($mode == 'mobile') $property=$langs->transnoentitiesnoconv("NoMobilePhone");
2322
+							if ($mode == 'email') {
2323
+								$property=$langs->transnoentitiesnoconv("NoEMail");
2324
+							} else if ($mode == 'mobile') {
2325
+								$property=$langs->transnoentitiesnoconv("NoMobilePhone");
2326
+							}
2196 2327
 						}
2197 2328
 
2198 2329
 						if (!empty($obj->poste))
2199 2330
 						{
2200 2331
 							$contact_property[$obj->rowid] = trim(dolGetFirstLastname($obj->firstname,$obj->lastname)).($obj->poste?" - ".$obj->poste:"").(($mode != 'poste' && $property)?" ".$sepa.$property.$sepb:'');
2201
-						}
2202
-						else
2332
+						} else
2203 2333
 						{
2204 2334
 							$contact_property[$obj->rowid] = trim(dolGetFirstLastname($obj->firstname,$obj->lastname)).(($mode != 'poste' && $property)?" ".$sepa.$property.$sepb:'');
2205 2335
 						}
@@ -2207,8 +2337,7 @@  discard block
 block discarded – undo
2207 2337
 					$i++;
2208 2338
 				}
2209 2339
 			}
2210
-		}
2211
-		else
2340
+		} else
2212 2341
 		{
2213 2342
 			dol_print_error($this->db);
2214 2343
 		}
@@ -2240,8 +2369,7 @@  discard block
 block discarded – undo
2240 2369
 					$i++;
2241 2370
 				}
2242 2371
 			}
2243
-		}
2244
-		else
2372
+		} else
2245 2373
 		{
2246 2374
 			dol_print_error($this->db);
2247 2375
 		}
@@ -2275,8 +2403,7 @@  discard block
 block discarded – undo
2275 2403
 					$i++;
2276 2404
 				}
2277 2405
 			}
2278
-		}
2279
-		else
2406
+		} else
2280 2407
 		{
2281 2408
 			dol_print_error($this->db);
2282 2409
 		}
@@ -2294,7 +2421,9 @@  discard block
 block discarded – undo
2294 2421
 	{
2295 2422
 		$contact_property='';
2296 2423
 
2297
-		if (empty($rowid)) return '';
2424
+		if (empty($rowid)) {
2425
+			return '';
2426
+		}
2298 2427
 
2299 2428
 		$sql = "SELECT rowid, email, phone_mobile, lastname, firstname";
2300 2429
 		$sql.= " FROM ".MAIN_DB_PREFIX."socpeople";
@@ -2309,12 +2438,14 @@  discard block
 block discarded – undo
2309 2438
 			{
2310 2439
 				$obj = $this->db->fetch_object($resql);
2311 2440
 
2312
-				if ($mode == 'email') $contact_property = dolGetFirstLastname($obj->firstname, $obj->lastname)." <".$obj->email.">";
2313
-				else if ($mode == 'mobile') $contact_property = $obj->phone_mobile;
2441
+				if ($mode == 'email') {
2442
+					$contact_property = dolGetFirstLastname($obj->firstname, $obj->lastname)." <".$obj->email.">";
2443
+				} else if ($mode == 'mobile') {
2444
+					$contact_property = $obj->phone_mobile;
2445
+				}
2314 2446
 			}
2315 2447
 			return $contact_property;
2316
-		}
2317
-		else
2448
+		} else
2318 2449
 		{
2319 2450
 			dol_print_error($this->db);
2320 2451
 		}
@@ -2338,8 +2469,7 @@  discard block
 block discarded – undo
2338 2469
 		if ($mode == 'label')
2339 2470
 		{
2340 2471
 			return $bac->getRibLabel(true);
2341
-		}
2342
-		elseif ($mode == 'rum')
2472
+		} elseif ($mode == 'rum')
2343 2473
 		{
2344 2474
 			if (empty($bac->rum))
2345 2475
 			{
@@ -2349,8 +2479,7 @@  discard block
 block discarded – undo
2349 2479
 				$bac->rum = $prelevement->buildRumNumber($bac->thirdparty->code_client, $bac->datec, $bac->id);
2350 2480
 			}
2351 2481
 			return $bac->rum;
2352
-		}
2353
-		elseif ($mode == 'format')
2482
+		} elseif ($mode == 'format')
2354 2483
 		{
2355 2484
 			return $bac->frstrecur;
2356 2485
 		}
@@ -2405,7 +2534,9 @@  discard block
 block discarded – undo
2405 2534
 			foreach ($dirsociete as $dirroot)
2406 2535
 			{
2407 2536
 				$res=dol_include_once($dirroot.$module.'.php');
2408
-				if ($res) break;
2537
+				if ($res) {
2538
+					break;
2539
+				}
2409 2540
 			}
2410 2541
 			$mod = new $module();
2411 2542
 
@@ -2435,7 +2566,9 @@  discard block
 block discarded – undo
2435 2566
 			foreach ($dirsociete as $dirroot)
2436 2567
 			{
2437 2568
 				$res=dol_include_once($dirroot.$module.'.php');
2438
-				if ($res) break;
2569
+				if ($res) {
2570
+					break;
2571
+				}
2439 2572
 			}
2440 2573
 			$mod = new $module();
2441 2574
 
@@ -2462,18 +2595,26 @@  discard block
 block discarded – undo
2462 2595
 			foreach ($dirsociete as $dirroot)
2463 2596
 			{
2464 2597
 				$res=dol_include_once($dirroot.$module.'.php');
2465
-				if ($res) break;
2598
+				if ($res) {
2599
+					break;
2600
+				}
2466 2601
 			}
2467 2602
 
2468 2603
 			$mod = new $module();
2469 2604
 
2470 2605
 			dol_syslog(get_class($this)."::codeclient_modifiable code_client=".$this->code_client." module=".$module);
2471
-			if ($mod->code_modifiable_null && ! $this->code_client) return 1;
2472
-			if ($mod->code_modifiable_invalide && $this->check_codeclient() < 0) return 1;
2473
-			if ($mod->code_modifiable) return 1;	// A mettre en dernier
2606
+			if ($mod->code_modifiable_null && ! $this->code_client) {
2607
+				return 1;
2608
+			}
2609
+			if ($mod->code_modifiable_invalide && $this->check_codeclient() < 0) {
2610
+				return 1;
2611
+			}
2612
+			if ($mod->code_modifiable) {
2613
+				return 1;
2614
+			}
2615
+			// A mettre en dernier
2474 2616
 			return 0;
2475
-		}
2476
-		else
2617
+		} else
2477 2618
 		{
2478 2619
 			return 0;
2479 2620
 		}
@@ -2496,18 +2637,26 @@  discard block
 block discarded – undo
2496 2637
 			foreach ($dirsociete as $dirroot)
2497 2638
 			{
2498 2639
 				$res=dol_include_once($dirroot.$module.'.php');
2499
-				if ($res) break;
2640
+				if ($res) {
2641
+					break;
2642
+				}
2500 2643
 			}
2501 2644
 
2502 2645
 			$mod = new $module();
2503 2646
 
2504 2647
 			dol_syslog(get_class($this)."::codefournisseur_modifiable code_founisseur=".$this->code_fournisseur." module=".$module);
2505
-			if ($mod->code_modifiable_null && ! $this->code_fournisseur) return 1;
2506
-			if ($mod->code_modifiable_invalide && $this->check_codefournisseur() < 0) return 1;
2507
-			if ($mod->code_modifiable) return 1;	// A mettre en dernier
2648
+			if ($mod->code_modifiable_null && ! $this->code_fournisseur) {
2649
+				return 1;
2650
+			}
2651
+			if ($mod->code_modifiable_invalide && $this->check_codefournisseur() < 0) {
2652
+				return 1;
2653
+			}
2654
+			if ($mod->code_modifiable) {
2655
+				return 1;
2656
+			}
2657
+			// A mettre en dernier
2508 2658
 			return 0;
2509
-		}
2510
-		else
2659
+		} else
2511 2660
 		{
2512 2661
 			return 0;
2513 2662
 		}
@@ -2534,7 +2683,9 @@  discard block
 block discarded – undo
2534 2683
 			foreach ($dirsociete as $dirroot)
2535 2684
 			{
2536 2685
 				$res=dol_include_once($dirroot.$module.'.php');
2537
-				if ($res) break;
2686
+				if ($res) {
2687
+					break;
2688
+				}
2538 2689
 			}
2539 2690
 
2540 2691
 			$mod = new $module();
@@ -2542,8 +2693,7 @@  discard block
 block discarded – undo
2542 2693
 		   	dol_syslog(get_class($this)."::check_codeclient code_client=".$this->code_client." module=".$module);
2543 2694
 		   	$result = $mod->verif($this->db, $this->code_client, $this, 0);
2544 2695
 			return $result;
2545
-		}
2546
-		else
2696
+		} else
2547 2697
 		{
2548 2698
 			return 0;
2549 2699
 		}
@@ -2569,7 +2719,9 @@  discard block
 block discarded – undo
2569 2719
 			foreach ($dirsociete as $dirroot)
2570 2720
 			{
2571 2721
 				$res=dol_include_once($dirroot.$module.'.php');
2572
-				if ($res) break;
2722
+				if ($res) {
2723
+					break;
2724
+				}
2573 2725
 			}
2574 2726
 
2575 2727
 			$mod = new $module();
@@ -2577,8 +2729,7 @@  discard block
 block discarded – undo
2577 2729
 			dol_syslog(get_class($this)."::check_codefournisseur code_fournisseur=".$this->code_fournisseur." module=".$module);
2578 2730
 			$result = $mod->verif($this->db, $this->code_fournisseur, $this, 1);
2579 2731
 			return $result;
2580
-		}
2581
-		else
2732
+		} else
2582 2733
 		{
2583 2734
 			return 0;
2584 2735
 		}
@@ -2619,21 +2770,25 @@  discard block
 block discarded – undo
2619 2770
 				// Defini code compta dans $mod->code
2620 2771
 				$result = $mod->get_code($this->db, $this, $type);
2621 2772
 
2622
-				if ($type == 'customer') $this->code_compta = $mod->code;
2623
-				else if ($type == 'supplier') $this->code_compta_fournisseur = $mod->code;
2773
+				if ($type == 'customer') {
2774
+					$this->code_compta = $mod->code;
2775
+				} else if ($type == 'supplier') {
2776
+					$this->code_compta_fournisseur = $mod->code;
2777
+				}
2624 2778
 
2625 2779
 				return $result;
2626
-			}
2627
-			else
2780
+			} else
2628 2781
 			{
2629 2782
 				$this->error = 'ErrorAccountancyCodeNotDefined';
2630 2783
 				return -1;
2631 2784
 			}
2632
-		}
2633
-		else
2785
+		} else
2634 2786
 		{
2635
-			if ($type == 'customer') $this->code_compta = '';
2636
-			else if ($type == 'supplier') $this->code_compta_fournisseur = '';
2787
+			if ($type == 'customer') {
2788
+				$this->code_compta = '';
2789
+			} else if ($type == 'supplier') {
2790
+				$this->code_compta_fournisseur = '';
2791
+			}
2637 2792
 
2638 2793
 			return 0;
2639 2794
 		}
@@ -2658,13 +2813,13 @@  discard block
 block discarded – undo
2658 2813
 			{
2659 2814
 				$this->parent = $id;
2660 2815
 				return 1;
2661
-			}
2662
-			else
2816
+			} else
2663 2817
 			{
2664 2818
 				return -1;
2665 2819
 			}
2820
+		} else {
2821
+			return -1;
2666 2822
 		}
2667
-		else return -1;
2668 2823
 	}
2669 2824
 
2670 2825
 	/**
@@ -2744,22 +2899,26 @@  discard block
 block discarded – undo
2744 2899
 
2745 2900
 		 //Verify duplicate entries
2746 2901
 		$sql  = "SELECT COUNT(*) as idprof FROM ".MAIN_DB_PREFIX."societe WHERE ".$field." = '".$value."' AND entity IN (".getEntity('societe').")";
2747
-		if($socid) $sql .= " AND rowid <> ".$socid;
2902
+		if($socid) {
2903
+			$sql .= " AND rowid <> ".$socid;
2904
+		}
2748 2905
 		$resql = $this->db->query($sql);
2749 2906
 		if ($resql)
2750 2907
 		{
2751 2908
 			$obj = $this->db->fetch_object($resql);
2752 2909
 			$count = $obj->idprof;
2753
-		}
2754
-		else
2910
+		} else
2755 2911
 		{
2756 2912
 			$count = 0;
2757 2913
 			print $this->db->error();
2758 2914
 		}
2759 2915
 		$this->db->free($resql);
2760 2916
 
2761
-		if ($count > 0) return true;
2762
-		else return false;
2917
+		if ($count > 0) {
2918
+			return true;
2919
+		} else {
2920
+			return false;
2921
+		}
2763 2922
 	}
2764 2923
 
2765 2924
 	/**
@@ -2776,7 +2935,9 @@  discard block
 block discarded – undo
2776 2935
 
2777 2936
 		$ok=1;
2778 2937
 
2779
-		if (! empty($conf->global->MAIN_DISABLEPROFIDRULES)) return 1;
2938
+		if (! empty($conf->global->MAIN_DISABLEPROFIDRULES)) {
2939
+			return 1;
2940
+		}
2780 2941
 
2781 2942
 		// Verifie SIREN si pays FR
2782 2943
 		if ($idprof == 1 && $soc->country_code == 'FR')
@@ -2784,7 +2945,9 @@  discard block
 block discarded – undo
2784 2945
 			$chaine=trim($this->idprof1);
2785 2946
 			$chaine=preg_replace('/(\s)/','',$chaine);
2786 2947
 
2787
-			if (dol_strlen($chaine) != 9) return -1;
2948
+			if (dol_strlen($chaine) != 9) {
2949
+				return -1;
2950
+			}
2788 2951
 
2789 2952
 			$sum = 0;
2790 2953
 
@@ -2804,7 +2967,9 @@  discard block
 block discarded – undo
2804 2967
 				$sum = $sum + $ps;
2805 2968
 			}
2806 2969
 
2807
-			if (substr($sum, -1) != 0) return -1;
2970
+			if (substr($sum, -1) != 0) {
2971
+				return -1;
2972
+			}
2808 2973
 		}
2809 2974
 
2810 2975
 		// Verifie SIRET si pays FR
@@ -2813,7 +2978,9 @@  discard block
 block discarded – undo
2813 2978
 			$chaine=trim($this->idprof2);
2814 2979
 			$chaine=preg_replace('/(\s)/','',$chaine);
2815 2980
 
2816
-			if (dol_strlen($chaine) != 14) return -1;
2981
+			if (dol_strlen($chaine) != 14) {
2982
+				return -1;
2983
+			}
2817 2984
 		}
2818 2985
 
2819 2986
 		//Verify CIF/NIF/NIE if pays ES
@@ -2824,53 +2991,61 @@  discard block
 block discarded – undo
2824 2991
 			$string=preg_replace('/(\s)/','',$string);
2825 2992
 			$string = strtoupper($string);
2826 2993
 
2827
-			for ($i = 0; $i < 9; $i ++)
2828
-			$num[$i] = substr($string, $i, 1);
2994
+			for ($i = 0; $i < 9; $i ++) {
2995
+						$num[$i] = substr($string, $i, 1);
2996
+			}
2829 2997
 
2830 2998
 			//Check format
2831
-			if (!preg_match('/((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)/', $string))
2832
-			return 0;
2999
+			if (!preg_match('/((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)/', $string)) {
3000
+						return 0;
3001
+			}
2833 3002
 
2834 3003
 			//Check NIF
2835
-			if (preg_match('/(^[0-9]{8}[A-Z]{1}$)/', $string))
2836
-			if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 0, 8) % 23, 1))
3004
+			if (preg_match('/(^[0-9]{8}[A-Z]{1}$)/', $string)) {
3005
+						if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 0, 8) % 23, 1))
2837 3006
 			return 1;
2838
-			else
2839
-			return -1;
3007
+			} else {
3008
+						return -1;
3009
+			}
2840 3010
 
2841 3011
 			//algorithm checking type code CIF
2842 3012
 			$sum = $num[2] + $num[4] + $num[6];
2843
-			for ($i = 1; $i < 8; $i += 2)
2844
-			$sum += substr((2 * $num[$i]),0,1) + substr((2 * $num[$i]),1,1);
3013
+			for ($i = 1; $i < 8; $i += 2) {
3014
+						$sum += substr((2 * $num[$i]),0,1) + substr((2 * $num[$i]),1,1);
3015
+			}
2845 3016
 			$n = 10 - substr($sum, strlen($sum) - 1, 1);
2846 3017
 
2847 3018
 			//Chek special NIF
2848
-			if (preg_match('/^[KLM]{1}/', $string))
2849
-			if ($num[8] == chr(64 + $n) || $num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 1, 8) % 23, 1))
3019
+			if (preg_match('/^[KLM]{1}/', $string)) {
3020
+						if ($num[8] == chr(64 + $n) || $num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 1, 8) % 23, 1))
2850 3021
 			return 1;
2851
-			else
2852
-			return -1;
3022
+			} else {
3023
+						return -1;
3024
+			}
2853 3025
 
2854 3026
 			//Check CIF
2855
-			if (preg_match('/^[ABCDEFGHJNPQRSUVW]{1}/', $string))
2856
-			if ($num[8] == chr(64 + $n) || $num[8] == substr($n, strlen($n) - 1, 1))
3027
+			if (preg_match('/^[ABCDEFGHJNPQRSUVW]{1}/', $string)) {
3028
+						if ($num[8] == chr(64 + $n) || $num[8] == substr($n, strlen($n) - 1, 1))
2857 3029
 			return 2;
2858
-			else
2859
-			return -2;
3030
+			} else {
3031
+						return -2;
3032
+			}
2860 3033
 
2861 3034
 			//Check NIE T
2862
-			if (preg_match('/^[T]{1}/', $string))
2863
-			if ($num[8] == preg_match('/^[T]{1}[A-Z0-9]{8}$/', $string))
3035
+			if (preg_match('/^[T]{1}/', $string)) {
3036
+						if ($num[8] == preg_match('/^[T]{1}[A-Z0-9]{8}$/', $string))
2864 3037
 			return 3;
2865
-			else
2866
-			return -3;
3038
+			} else {
3039
+						return -3;
3040
+			}
2867 3041
 
2868 3042
 			//Check NIE XYZ
2869
-			if (preg_match('/^[XYZ]{1}/', $string))
2870
-			if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr(str_replace(array('X','Y','Z'), array('0','1','2'), $string), 0, 8) % 23, 1))
3043
+			if (preg_match('/^[XYZ]{1}/', $string)) {
3044
+						if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr(str_replace(array('X','Y','Z'), array('0','1','2'), $string), 0, 8) % 23, 1))
2871 3045
 			return 3;
2872
-			else
2873
-			return -3;
3046
+			} else {
3047
+						return -3;
3048
+			}
2874 3049
 
2875 3050
 			//Can not be verified
2876 3051
 			return -4;
@@ -2899,17 +3074,27 @@  discard block
 block discarded – undo
2899 3074
 		$reshook=$hookmanager->executeHooks('getIdProfUrl',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
2900 3075
 		if (empty($reshook))
2901 3076
 		{
2902
-			if (! empty($conf->global->MAIN_DISABLEPROFIDRULES)) return '';
3077
+			if (! empty($conf->global->MAIN_DISABLEPROFIDRULES)) {
3078
+				return '';
3079
+			}
2903 3080
 
2904 3081
 			// TODO Move links to validate professional ID into a dictionary table "country" + "link"
2905
-			if ($idprof == 1 && $thirdparty->country_code == 'FR') $url='http://www.societe.com/cgi-bin/search?champs='.$thirdparty->idprof1;    // See also http://avis-situation-sirene.insee.fr/
3082
+			if ($idprof == 1 && $thirdparty->country_code == 'FR') {
3083
+				$url='http://www.societe.com/cgi-bin/search?champs='.$thirdparty->idprof1;
3084
+			}
3085
+			// See also http://avis-situation-sirene.insee.fr/
2906 3086
 			//if ($idprof == 1 && ($thirdparty->country_code == 'GB' || $thirdparty->country_code == 'UK')) $url='http://www.companieshouse.gov.uk/WebCHeck/findinfolink/';     // Link no more valid
2907
-			if ($idprof == 1 && $thirdparty->country_code == 'ES') $url='http://www.e-informa.es/servlet/app/portal/ENTP/screen/SProducto/prod/ETIQUETA_EMPRESA/nif/'.$thirdparty->idprof1;
2908
-			if ($idprof == 1 && $thirdparty->country_code == 'IN') $url='http://www.tinxsys.com/TinxsysInternetWeb/dealerControllerServlet?tinNumber='.$thirdparty->idprof1.';&searchBy=TIN&backPage=searchByTin_Inter.jsp';
3087
+			if ($idprof == 1 && $thirdparty->country_code == 'ES') {
3088
+				$url='http://www.e-informa.es/servlet/app/portal/ENTP/screen/SProducto/prod/ETIQUETA_EMPRESA/nif/'.$thirdparty->idprof1;
3089
+			}
3090
+			if ($idprof == 1 && $thirdparty->country_code == 'IN') {
3091
+				$url='http://www.tinxsys.com/TinxsysInternetWeb/dealerControllerServlet?tinNumber='.$thirdparty->idprof1.';&searchBy=TIN&backPage=searchByTin_Inter.jsp';
3092
+			}
2909 3093
 
2910
-			if ($url) return '<a target="_blank" href="'.$url.'">'.$langs->trans("Check").'</a>';
2911
-		}
2912
-		else
3094
+			if ($url) {
3095
+				return '<a target="_blank" href="'.$url.'">'.$langs->trans("Check").'</a>';
3096
+			}
3097
+		} else
2913 3098
 		{
2914 3099
 			return $hookmanager->resPrint;
2915 3100
 		}
@@ -2930,8 +3115,7 @@  discard block
 block discarded – undo
2930 3115
 		{
2931 3116
 			$obj = $this->db->fetch_object($resql);
2932 3117
 			$count = $obj->numproj;
2933
-		}
2934
-		else
3118
+		} else
2935 3119
 		{
2936 3120
 			$count = 0;
2937 3121
 			print $this->db->error();
@@ -2982,8 +3166,7 @@  discard block
 block discarded – undo
2982 3166
 
2983 3167
 			$this->db->free($result);
2984 3168
 
2985
-		}
2986
-		else
3169
+		} else
2987 3170
 		{
2988 3171
 			dol_print_error($this->db);
2989 3172
 		}
@@ -3000,9 +3183,13 @@  discard block
 block discarded – undo
3000 3183
 
3001 3184
 		// Define if third party is treated as company (or not) when nature is unknown
3002 3185
 		$isacompany=empty($conf->global->MAIN_UNKNOWN_CUSTOMERS_ARE_COMPANIES)?0:1; // 0 by default
3003
-		if (! empty($this->tva_intra)) $isacompany=1;
3004
-		else if (! empty($this->typent_code) && in_array($this->typent_code,array('TE_PRIVATE'))) $isacompany=0;
3005
-		else if (! empty($this->typent_code) && in_array($this->typent_code,array('TE_SMALL','TE_MEDIUM','TE_LARGE','TE_GROUP'))) $isacompany=1;
3186
+		if (! empty($this->tva_intra)) {
3187
+			$isacompany=1;
3188
+		} else if (! empty($this->typent_code) && in_array($this->typent_code,array('TE_PRIVATE'))) {
3189
+			$isacompany=0;
3190
+		} else if (! empty($this->typent_code) && in_array($this->typent_code,array('TE_SMALL','TE_MEDIUM','TE_LARGE','TE_GROUP'))) {
3191
+			$isacompany=1;
3192
+		}
3006 3193
 
3007 3194
 		return $isacompany;
3008 3195
 	}
@@ -3027,8 +3214,7 @@  discard block
 block discarded – undo
3027 3214
 				$this->SupplierCategories[$obj->rowid] = $obj->label;
3028 3215
 			}
3029 3216
 			return 0;
3030
-		}
3031
-		else
3217
+		} else
3032 3218
 		{
3033 3219
 			return -1;
3034 3220
 		}
@@ -3047,9 +3233,10 @@  discard block
 block discarded – undo
3047 3233
 			$sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie_fournisseur (fk_categorie, fk_soc) ";
3048 3234
 			$sql.= " VALUES (".$categorie_id.", ".$this->id.")";
3049 3235
 
3050
-			if ($resql=$this->db->query($sql)) return 0;
3051
-		}
3052
-		else
3236
+			if ($resql=$this->db->query($sql)) {
3237
+				return 0;
3238
+			}
3239
+		} else
3053 3240
 		{
3054 3241
 			return 0;
3055 3242
 		}
@@ -3070,7 +3257,9 @@  discard block
 block discarded – undo
3070 3257
 		global $user,$langs;
3071 3258
 
3072 3259
 		$name = $socname?$socname:$member->societe;
3073
-		if (empty($name)) $name=$member->getFullName($langs);
3260
+		if (empty($name)) {
3261
+			$name=$member->getFullName($langs);
3262
+		}
3074 3263
 
3075 3264
 		$alias = $socalias?$socalias:'';
3076 3265
 
@@ -3107,16 +3296,14 @@  discard block
 block discarded – undo
3107 3296
 			{
3108 3297
 				$this->db->commit();
3109 3298
 				return $this->id;
3110
-			}
3111
-			else
3299
+			} else
3112 3300
 			{
3113 3301
 				$this->error=$this->db->error();
3114 3302
 
3115 3303
 				$this->db->rollback();
3116 3304
 				return -1;
3117 3305
 			}
3118
-		}
3119
-		else
3306
+		} else
3120 3307
 		{
3121 3308
 			// $this->error deja positionne
3122 3309
 			dol_syslog(get_class($this)."::create_from_member - 2 - ".$this->error." - ".join(',',$this->errors), LOG_ERR);
@@ -3162,12 +3349,13 @@  discard block
 block discarded – undo
3162 3349
 		{
3163 3350
 			$tmp=explode(':',$conf->global->MAIN_INFO_SOCIETE_COUNTRY);
3164 3351
 			$country_id=$tmp[0];
3165
-			if (! empty($tmp[1]))   // If $conf->global->MAIN_INFO_SOCIETE_COUNTRY is "id:code:label"
3352
+			if (! empty($tmp[1])) {
3353
+				// If $conf->global->MAIN_INFO_SOCIETE_COUNTRY is "id:code:label"
3166 3354
 			{
3167 3355
 				$country_code=$tmp[1];
3168
-				$country_label=$tmp[2];
3169 3356
 			}
3170
-			else                    // For backward compatibility
3357
+				$country_label=$tmp[2];
3358
+			} else                    // For backward compatibility
3171 3359
 			{
3172 3360
 				dol_syslog("Your country setup use an old syntax. Reedit it using setup area.", LOG_ERR);
3173 3361
 				include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
@@ -3178,7 +3366,9 @@  discard block
 block discarded – undo
3178 3366
 		$this->country_id=$country_id;
3179 3367
 		$this->country_code=$country_code;
3180 3368
 		$this->country=$country_label;
3181
-		if (is_object($langs)) $this->country=($langs->trans('Country'.$country_code)!='Country'.$country_code)?$langs->trans('Country'.$country_code):$country_label;
3369
+		if (is_object($langs)) {
3370
+			$this->country=($langs->trans('Country'.$country_code)!='Country'.$country_code)?$langs->trans('Country'.$country_code):$country_label;
3371
+		}
3182 3372
 
3183 3373
 		$this->phone=empty($conf->global->MAIN_INFO_SOCIETE_TEL)?'':$conf->global->MAIN_INFO_SOCIETE_TEL;
3184 3374
 		$this->fax=empty($conf->global->MAIN_INFO_SOCIETE_FAX)?'':$conf->global->MAIN_INFO_SOCIETE_FAX;
@@ -3270,17 +3460,22 @@  discard block
 block discarded – undo
3270 3460
 		$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
3271 3461
 		$sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code)."'";
3272 3462
 		$sql .= " AND t.active = 1";
3273
-		if (empty($localTaxNum))   $sql .= " AND (t.localtax1_type <> '0' OR t.localtax2_type <> '0')";
3274
-		elseif ($localTaxNum == 1) $sql .= " AND t.localtax1_type <> '0'";
3275
-		elseif ($localTaxNum == 2) $sql .= " AND t.localtax2_type <> '0'";
3463
+		if (empty($localTaxNum)) {
3464
+			$sql .= " AND (t.localtax1_type <> '0' OR t.localtax2_type <> '0')";
3465
+		} elseif ($localTaxNum == 1) {
3466
+			$sql .= " AND t.localtax1_type <> '0'";
3467
+		} elseif ($localTaxNum == 2) {
3468
+			$sql .= " AND t.localtax2_type <> '0'";
3469
+		}
3276 3470
 
3277 3471
 		dol_syslog("useLocalTax", LOG_DEBUG);
3278 3472
 		$resql=$this->db->query($sql);
3279 3473
 		if ($resql)
3280 3474
 		{
3281 3475
    			return ($this->db->num_rows($resql) > 0);
3476
+		} else {
3477
+			return false;
3282 3478
 		}
3283
-		else return false;
3284 3479
 	}
3285 3480
 
3286 3481
 	/**
@@ -3300,8 +3495,9 @@  discard block
 block discarded – undo
3300 3495
 		if ($resql)
3301 3496
 		{
3302 3497
 			return ($this->db->num_rows($resql) > 0);
3498
+		} else {
3499
+			return false;
3303 3500
 		}
3304
-		else return false;
3305 3501
 	}
3306 3502
 
3307 3503
 	/**
@@ -3322,8 +3518,7 @@  discard block
 block discarded – undo
3322 3518
 		{
3323 3519
 			$obj=$this->db->fetch_object($resql);
3324 3520
    			return (($obj->nb > 0)?true:false);
3325
-		}
3326
-		else
3521
+		} else
3327 3522
 		{
3328 3523
 			$this->error=$this->db->lasterror();
3329 3524
 			return false;
@@ -3399,36 +3594,51 @@  discard block
 block discarded – undo
3399 3594
 
3400 3595
 		if ($mode == 2)
3401 3596
 		{
3402
-			if ($statut == '-1' || $statut == 'ST_NO')         return img_action($langs->trans("StatusProspect-1"),-1).' '.$langs->trans("StatusProspect-1");
3403
-			elseif ($statut ==  '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0).' '.$langs->trans("StatusProspect0");
3404
-			elseif ($statut ==  '1' || $statut == 'ST_TODO')  return img_action($langs->trans("StatusProspect1"), 1).' '.$langs->trans("StatusProspect1");
3405
-			elseif ($statut ==  '2' || $statut == 'ST_PEND')  return img_action($langs->trans("StatusProspect2"), 2).' '.$langs->trans("StatusProspect2");
3406
-			elseif ($statut ==  '3' || $statut == 'ST_DONE')  return img_action($langs->trans("StatusProspect3"), 3).' '.$langs->trans("StatusProspect3");
3407
-			else
3597
+			if ($statut == '-1' || $statut == 'ST_NO') {
3598
+				return img_action($langs->trans("StatusProspect-1"),-1).' '.$langs->trans("StatusProspect-1");
3599
+			} elseif ($statut ==  '0' || $statut == 'ST_NEVER') {
3600
+				return img_action($langs->trans("StatusProspect0"), 0).' '.$langs->trans("StatusProspect0");
3601
+			} elseif ($statut ==  '1' || $statut == 'ST_TODO') {
3602
+				return img_action($langs->trans("StatusProspect1"), 1).' '.$langs->trans("StatusProspect1");
3603
+			} elseif ($statut ==  '2' || $statut == 'ST_PEND') {
3604
+				return img_action($langs->trans("StatusProspect2"), 2).' '.$langs->trans("StatusProspect2");
3605
+			} elseif ($statut ==  '3' || $statut == 'ST_DONE') {
3606
+				return img_action($langs->trans("StatusProspect3"), 3).' '.$langs->trans("StatusProspect3");
3607
+			} else
3408 3608
 			{
3409 3609
 				return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0).' '.(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label);
3410 3610
 			}
3411 3611
 		}
3412 3612
 		if ($mode == 3)
3413 3613
 		{
3414
-			if ($statut == '-1' || $statut == 'ST_NO')         return img_action($langs->trans("StatusProspect-1"),-1);
3415
-			elseif ($statut ==  '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0);
3416
-			elseif ($statut ==  '1' || $statut == 'ST_TODO')  return img_action($langs->trans("StatusProspect1"), 1);
3417
-			elseif ($statut ==  '2' || $statut == 'ST_PEND')  return img_action($langs->trans("StatusProspect2"), 2);
3418
-			elseif ($statut ==  '3' || $statut == 'ST_DONE')  return img_action($langs->trans("StatusProspect3"), 3);
3419
-			else
3614
+			if ($statut == '-1' || $statut == 'ST_NO') {
3615
+				return img_action($langs->trans("StatusProspect-1"),-1);
3616
+			} elseif ($statut ==  '0' || $statut == 'ST_NEVER') {
3617
+				return img_action($langs->trans("StatusProspect0"), 0);
3618
+			} elseif ($statut ==  '1' || $statut == 'ST_TODO') {
3619
+				return img_action($langs->trans("StatusProspect1"), 1);
3620
+			} elseif ($statut ==  '2' || $statut == 'ST_PEND') {
3621
+				return img_action($langs->trans("StatusProspect2"), 2);
3622
+			} elseif ($statut ==  '3' || $statut == 'ST_DONE') {
3623
+				return img_action($langs->trans("StatusProspect3"), 3);
3624
+			} else
3420 3625
 			{
3421 3626
 				return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0);
3422 3627
 			}
3423 3628
 		}
3424 3629
 		if ($mode == 4)
3425 3630
 		{
3426
-			if ($statut == '-1' || $statut == 'ST_NO')         return img_action($langs->trans("StatusProspect-1"),-1).' '.$langs->trans("StatusProspect-1");
3427
-			elseif ($statut ==  '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0).' '.$langs->trans("StatusProspect0");
3428
-			elseif ($statut ==  '1' || $statut == 'ST_TODO')  return img_action($langs->trans("StatusProspect1"), 1).' '.$langs->trans("StatusProspect1");
3429
-			elseif ($statut ==  '2' || $statut == 'ST_PEND')  return img_action($langs->trans("StatusProspect2"), 2).' '.$langs->trans("StatusProspect2");
3430
-			elseif ($statut ==  '3' || $statut == 'ST_DONE')  return img_action($langs->trans("StatusProspect3"), 3).' '.$langs->trans("StatusProspect3");
3431
-			else
3631
+			if ($statut == '-1' || $statut == 'ST_NO') {
3632
+				return img_action($langs->trans("StatusProspect-1"),-1).' '.$langs->trans("StatusProspect-1");
3633
+			} elseif ($statut ==  '0' || $statut == 'ST_NEVER') {
3634
+				return img_action($langs->trans("StatusProspect0"), 0).' '.$langs->trans("StatusProspect0");
3635
+			} elseif ($statut ==  '1' || $statut == 'ST_TODO') {
3636
+				return img_action($langs->trans("StatusProspect1"), 1).' '.$langs->trans("StatusProspect1");
3637
+			} elseif ($statut ==  '2' || $statut == 'ST_PEND') {
3638
+				return img_action($langs->trans("StatusProspect2"), 2).' '.$langs->trans("StatusProspect2");
3639
+			} elseif ($statut ==  '3' || $statut == 'ST_DONE') {
3640
+				return img_action($langs->trans("StatusProspect3"), 3).' '.$langs->trans("StatusProspect3");
3641
+			} else
3432 3642
 			{
3433 3643
 				return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0).' '.(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label);
3434 3644
 			}
@@ -3458,7 +3668,9 @@  discard block
 block discarded – undo
3458 3668
 	function getOutstandingProposals($mode='customer')
3459 3669
 	{
3460 3670
 		$table='propal';
3461
-		if ($mode == 'supplier') $table = 'supplier_proposal';
3671
+		if ($mode == 'supplier') {
3672
+			$table = 'supplier_proposal';
3673
+		}
3462 3674
 
3463 3675
 		$sql  = "SELECT rowid, total_ht, total as total_ttc, fk_statut FROM ".MAIN_DB_PREFIX.$table." as f";
3464 3676
 		$sql .= " WHERE fk_soc = ". $this->id;
@@ -3478,15 +3690,17 @@  discard block
 block discarded – undo
3478 3690
 			while($obj=$this->db->fetch_object($resql)) {
3479 3691
 				$outstandingTotal+= $obj->total_ht;
3480 3692
 				$outstandingTotalIncTax+= $obj->total_ttc;
3481
-				if ($obj->fk_statut != 0)    // Not a draft
3693
+				if ($obj->fk_statut != 0) {
3694
+					// Not a draft
3482 3695
 				{
3483 3696
 					$outstandingOpened+=$obj->total_ttc;
3484 3697
 				}
3698
+				}
3485 3699
 			}
3486 3700
 			return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax);	// 'opened' is 'incl taxes'
3701
+		} else {
3702
+					return array();
3487 3703
 		}
3488
-		else
3489
-			return array();
3490 3704
 	}
3491 3705
 
3492 3706
 	/**
@@ -3498,7 +3712,9 @@  discard block
 block discarded – undo
3498 3712
 	function getOutstandingOrders($mode='customer')
3499 3713
 	{
3500 3714
 		$table='commande';
3501
-		if ($mode == 'supplier') $table = 'commande_fournisseur';
3715
+		if ($mode == 'supplier') {
3716
+			$table = 'commande_fournisseur';
3717
+		}
3502 3718
 
3503 3719
 		$sql  = "SELECT rowid, total_ht, total_ttc, fk_statut FROM ".MAIN_DB_PREFIX.$table." as f";
3504 3720
 		$sql .= " WHERE fk_soc = ". $this->id;
@@ -3518,15 +3734,17 @@  discard block
 block discarded – undo
3518 3734
 			while($obj=$this->db->fetch_object($resql)) {
3519 3735
 				$outstandingTotal+= $obj->total_ht;
3520 3736
 				$outstandingTotalIncTax+= $obj->total_ttc;
3521
-				if ($obj->fk_statut != 0)    // Not a draft
3737
+				if ($obj->fk_statut != 0) {
3738
+					// Not a draft
3522 3739
 				{
3523 3740
 					$outstandingOpened+=$obj->total_ttc;
3524 3741
 				}
3742
+				}
3525 3743
 			}
3526 3744
 			return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax);	// 'opened' is 'incl taxes'
3745
+		} else {
3746
+					return array();
3527 3747
 		}
3528
-		else
3529
-			return array();
3530 3748
 	}
3531 3749
 
3532 3750
 	/**
@@ -3538,7 +3756,9 @@  discard block
 block discarded – undo
3538 3756
 	function getOutstandingBills($mode='customer')
3539 3757
 	{
3540 3758
 		$table='facture';
3541
-		if ($mode == 'supplier') $table = 'facture_fourn';
3759
+		if ($mode == 'supplier') {
3760
+			$table = 'facture_fourn';
3761
+		}
3542 3762
 
3543 3763
 		/* Accurate value of remain to pay is to sum remaintopay for each invoice
3544 3764
 		 $paiement = $invoice->getSommePaiement();
@@ -3547,8 +3767,11 @@  discard block
 block discarded – undo
3547 3767
 		 $alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT');
3548 3768
 		 $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT');
3549 3769
 		 */
3550
-		if ($mode == 'supplier') $sql  = "SELECT rowid, total_ht as total_ht, total_ttc, paye, fk_statut, close_code FROM ".MAIN_DB_PREFIX.$table." as f";
3551
-		else $sql  = "SELECT rowid, total as total_ht, total_ttc, paye, fk_statut, close_code FROM ".MAIN_DB_PREFIX.$table." as f";
3770
+		if ($mode == 'supplier') {
3771
+			$sql  = "SELECT rowid, total_ht as total_ht, total_ttc, paye, fk_statut, close_code FROM ".MAIN_DB_PREFIX.$table." as f";
3772
+		} else {
3773
+			$sql  = "SELECT rowid, total as total_ht, total_ttc, paye, fk_statut, close_code FROM ".MAIN_DB_PREFIX.$table." as f";
3774
+		}
3552 3775
 		$sql .= " WHERE fk_soc = ". $this->id;
3553 3776
 		if ($mode == 'supplier') {
3554 3777
 			$sql .= " AND entity IN (".getEntity('facture_fourn').")";
@@ -3567,8 +3790,7 @@  discard block
 block discarded – undo
3567 3790
 			{
3568 3791
 				require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
3569 3792
 				$tmpobject=new FactureFournisseur($this->db);
3570
-			}
3571
-			else
3793
+			} else
3572 3794
 			{
3573 3795
 				require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
3574 3796
 				$tmpobject=new Facture($this->db);
@@ -3585,18 +3807,19 @@  discard block
 block discarded – undo
3585 3807
 				if ($obj->paye == 0
3586 3808
 					&& $obj->fk_statut != 0    // Not a draft
3587 3809
 					&& $obj->fk_statut != 3	   // Not abandonned
3588
-					&& $obj->fk_statut != 2)   // Not classified as paid
3810
+					&& $obj->fk_statut != 2) {
3811
+					// Not classified as paid
3589 3812
 				//$sql .= " AND (fk_statut <> 3 OR close_code <> 'abandon')";		// Not abandonned for undefined reason
3590 3813
 				{
3591 3814
 					$paiement = $tmpobject->getSommePaiement();
3815
+				}
3592 3816
 					$creditnotes = $tmpobject->getSumCreditNotesUsed();
3593 3817
 					$deposits = $tmpobject->getSumDepositsUsed();
3594 3818
 					$outstandingOpened+=$obj->total_ttc - $paiement - $creditnotes - $deposits;
3595 3819
 				}
3596 3820
 			}
3597 3821
 			return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax);	// 'opened' is 'incl taxes'
3598
-		}
3599
-		else
3822
+		} else
3600 3823
 		{
3601 3824
 			return array();
3602 3825
 		}
@@ -3640,9 +3863,9 @@  discard block
 block discarded – undo
3640 3863
 				$outstandingAmount+= $obj->total_ttc - $paiement - $creditnotes - $deposits;
3641 3864
 			}
3642 3865
 			return $outstandingAmount;
3866
+		} else {
3867
+					return 0;
3643 3868
 		}
3644
-		else
3645
-			return 0;
3646 3869
 	}
3647 3870
 
3648 3871
 	/**
@@ -3666,10 +3889,18 @@  discard block
 block discarded – undo
3666 3889
 		global $langs;
3667 3890
 		$langs->load('companies');
3668 3891
 
3669
-		if ($statut==0) return $langs->trans("NorProspectNorCustomer");
3670
-		if ($statut==1) return $langs->trans("Customer");
3671
-		if ($statut==2) return $langs->trans("Prospect");
3672
-		if ($statut==3) return $langs->trans("ProspectCustomer");
3892
+		if ($statut==0) {
3893
+			return $langs->trans("NorProspectNorCustomer");
3894
+		}
3895
+		if ($statut==1) {
3896
+			return $langs->trans("Customer");
3897
+		}
3898
+		if ($statut==2) {
3899
+			return $langs->trans("Prospect");
3900
+		}
3901
+		if ($statut==3) {
3902
+			return $langs->trans("ProspectCustomer");
3903
+		}
3673 3904
 
3674 3905
 	}
3675 3906
 
@@ -3696,10 +3927,11 @@  discard block
 block discarded – undo
3696 3927
 			include_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
3697 3928
 			$companybankaccount = new CompanyBankAccount($this->db);
3698 3929
 			$result = $companybankaccount->fetch($moreparams['use_companybankid']);
3699
-			if (! $result) dol_print_error($this->db, $companybankaccount->error, $companybankaccount->errors);
3930
+			if (! $result) {
3931
+				dol_print_error($this->db, $companybankaccount->error, $companybankaccount->errors);
3932
+			}
3700 3933
 			$result=$companybankaccount->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3701
-		}
3702
-		else
3934
+		} else
3703 3935
 		{
3704 3936
 			// Positionne le modele sur le nom du modele a utiliser
3705 3937
 			if (! dol_strlen($modele))
@@ -3707,8 +3939,7 @@  discard block
 block discarded – undo
3707 3939
 				if (! empty($conf->global->COMPANY_ADDON_PDF))
3708 3940
 				{
3709 3941
 					$modele = $conf->global->COMPANY_ADDON_PDF;
3710
-				}
3711
-				else
3942
+				} else
3712 3943
 				{
3713 3944
 					print $langs->trans("Error")." ".$langs->trans("Error_COMPANY_ADDON_PDF_NotDefined");
3714 3945
 					return 0;
Please login to merge, or discard this patch.
htdocs/societe/card.php 3 patches
Indentation   +1858 added lines, -1858 removed lines patch added patch discarded remove patch
@@ -86,9 +86,9 @@  discard block
 block discarded – undo
86 86
 $objcanvas=null;
87 87
 if (! empty($canvas))
88 88
 {
89
-    require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
90
-    $objcanvas = new Canvas($db, $action);
91
-    $objcanvas->getCanvas('thirdparty', 'card', $canvas);
89
+	require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
90
+	$objcanvas = new Canvas($db, $action);
91
+	$objcanvas->getCanvas('thirdparty', 'card', $canvas);
92 92
 }
93 93
 
94 94
 // Security check
@@ -105,15 +105,15 @@  discard block
 block discarded – undo
105 105
 
106 106
 if (empty($reshook))
107 107
 {
108
-    if ($cancel)
109
-    {
110
-        $action='';
111
-        if (! empty($backtopage))
112
-        {
113
-            header("Location: ".$backtopage);
114
-            exit;
115
-        }
116
-    }
108
+	if ($cancel)
109
+	{
110
+		$action='';
111
+		if (! empty($backtopage))
112
+		{
113
+			header("Location: ".$backtopage);
114
+			exit;
115
+		}
116
+	}
117 117
 
118 118
 	if ($action == 'confirm_merge' && $confirm == 'yes' && $user->rights->societe->creer)
119 119
 	{
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
 
140 140
 			if (!$error)
141 141
 			{
142
-			    // TODO Move the merge function into class of object.
142
+				// TODO Move the merge function into class of object.
143 143
 
144 144
 				$db->begin();
145 145
 
@@ -161,11 +161,11 @@  discard block
 block discarded – undo
161 161
 
162 162
 				// Concat some data
163 163
 				$listofproperties=array(
164
-				    'note_public', 'note_private'
164
+					'note_public', 'note_private'
165 165
 				);
166 166
 				foreach ($listofproperties as $property)
167 167
 				{
168
-				    $object->$property = dol_concatdesc($object->$property, $soc_origin->$property);
168
+					$object->$property = dol_concatdesc($object->$property, $soc_origin->$property);
169 169
 				}
170 170
 
171 171
 				// Merge extrafields
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
 				{
174 174
 					foreach ($soc_origin->array_options as $key => $val)
175 175
 					{
176
-					    if (empty($object->array_options[$key])) $object->array_options[$key] = $val;
176
+						if (empty($object->array_options[$key])) $object->array_options[$key] = $val;
177 177
 					}
178 178
 				}
179 179
 
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
 				}
290 290
 				else
291 291
 				{
292
-				    $langs->load("errors");
292
+					$langs->load("errors");
293 293
 					setEventMessages($langs->trans('ErrorsThirdpartyMerge'), null, 'errors');
294 294
 					$db->rollback();
295 295
 				}
@@ -297,152 +297,152 @@  discard block
 block discarded – undo
297 297
 		}
298 298
 	}
299 299
 
300
-    if (GETPOST('getcustomercode'))
301
-    {
302
-        // We defined value code_client
303
-        $_POST["code_client"]="Acompleter";
304
-    }
305
-
306
-    if (GETPOST('getsuppliercode'))
307
-    {
308
-        // We defined value code_fournisseur
309
-        $_POST["code_fournisseur"]="Acompleter";
310
-    }
311
-
312
-    if($action=='set_localtax1')
313
-    {
314
-    	//obtidre selected del combobox
315
-    	$value=GETPOST('lt1');
316
-    	$object->fetch($socid);
317
-    	$res=$object->setValueFrom('localtax1_value', $value, '', null, 'text', '', $user, 'COMPANY_MODIFY');
318
-    }
319
-    if($action=='set_localtax2')
320
-    {
321
-    	//obtidre selected del combobox
322
-    	$value=GETPOST('lt2');
323
-    	$object->fetch($socid);
324
-    	$res=$object->setValueFrom('localtax2_value', $value, '', null, 'text', '', $user, 'COMPANY_MODIFY');
325
-    }
326
-
327
-    if ($action == 'update_extras') {
328
-        $object->fetch($socid);
329
-
330
-        $object->oldcopy = dol_clone($object);
331
-
332
-        // Fill array 'array_options' with data from update form
333
-        $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
334
-        $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute','none'));
335
-        if ($ret < 0) $error++;
336
-
337
-        if (! $error)
338
-        {
339
-            $result = $object->insertExtraFields('COMPANY_MODIFY');
300
+	if (GETPOST('getcustomercode'))
301
+	{
302
+		// We defined value code_client
303
+		$_POST["code_client"]="Acompleter";
304
+	}
305
+
306
+	if (GETPOST('getsuppliercode'))
307
+	{
308
+		// We defined value code_fournisseur
309
+		$_POST["code_fournisseur"]="Acompleter";
310
+	}
311
+
312
+	if($action=='set_localtax1')
313
+	{
314
+		//obtidre selected del combobox
315
+		$value=GETPOST('lt1');
316
+		$object->fetch($socid);
317
+		$res=$object->setValueFrom('localtax1_value', $value, '', null, 'text', '', $user, 'COMPANY_MODIFY');
318
+	}
319
+	if($action=='set_localtax2')
320
+	{
321
+		//obtidre selected del combobox
322
+		$value=GETPOST('lt2');
323
+		$object->fetch($socid);
324
+		$res=$object->setValueFrom('localtax2_value', $value, '', null, 'text', '', $user, 'COMPANY_MODIFY');
325
+	}
326
+
327
+	if ($action == 'update_extras') {
328
+		$object->fetch($socid);
329
+
330
+		$object->oldcopy = dol_clone($object);
331
+
332
+		// Fill array 'array_options' with data from update form
333
+		$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
334
+		$ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute','none'));
335
+		if ($ret < 0) $error++;
336
+
337
+		if (! $error)
338
+		{
339
+			$result = $object->insertExtraFields('COMPANY_MODIFY');
340 340
    			if ($result < 0)
341 341
 			{
342 342
 				setEventMessages($object->error, $object->errors, 'errors');
343 343
 				$error++;
344 344
 			}
345
-        }
346
-
347
-        if ($error) $action = 'edit_extras';
348
-    }
349
-
350
-    // Add new or update third party
351
-    if ((! GETPOST('getcustomercode') && ! GETPOST('getsuppliercode'))
352
-    && ($action == 'add' || $action == 'update') && $user->rights->societe->creer)
353
-    {
354
-        require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
355
-
356
-        if (! GETPOST('name'))
357
-        {
358
-            setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ThirdPartyName")), null, 'errors');
359
-            $error++;
360
-        }
361
-        if (GETPOST('client') < 0)
362
-        {
363
-            setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ProspectCustomer")), null, 'errors');
364
-            $error++;
365
-        }
366
-        if (GETPOST('fournisseur') < 0)
367
-        {
368
-            setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Supplier")), null, 'errors');
369
-            $error++;
370
-
371
-        }
372
-
373
-        if (! $error)
374
-        {
375
-        		if ($action == 'update')
376
-	        {
377
-	        		$ret=$object->fetch($socid);
345
+		}
346
+
347
+		if ($error) $action = 'edit_extras';
348
+	}
349
+
350
+	// Add new or update third party
351
+	if ((! GETPOST('getcustomercode') && ! GETPOST('getsuppliercode'))
352
+	&& ($action == 'add' || $action == 'update') && $user->rights->societe->creer)
353
+	{
354
+		require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
355
+
356
+		if (! GETPOST('name'))
357
+		{
358
+			setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ThirdPartyName")), null, 'errors');
359
+			$error++;
360
+		}
361
+		if (GETPOST('client') < 0)
362
+		{
363
+			setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ProspectCustomer")), null, 'errors');
364
+			$error++;
365
+		}
366
+		if (GETPOST('fournisseur') < 0)
367
+		{
368
+			setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Supplier")), null, 'errors');
369
+			$error++;
370
+
371
+		}
372
+
373
+		if (! $error)
374
+		{
375
+				if ($action == 'update')
376
+			{
377
+					$ret=$object->fetch($socid);
378 378
 				$object->oldcopy = clone $object;
379
-	        }
379
+			}
380 380
 			else $object->canvas=$canvas;
381 381
 
382
-	        if (GETPOST("private") == 1)	// Ask to create a contact
383
-	        {
384
-	            $object->particulier			= GETPOST("private");
385
-
386
-	            $object->name				= dolGetFirstLastname(GETPOST('firstname','alpha'),GETPOST('name','alpha'));
387
-	            $object->civility_id			= GETPOST('civility_id');	// Note: civility id is a code, not an int
388
-	            // Add non official properties
389
-	            $object->name_bis			= GETPOST('name','alpha');
390
-	            $object->firstname			= GETPOST('firstname','alpha');
391
-	        }
392
-	        else
393
-	        {
394
-	            $object->name				= GETPOST('name', 'alpha');
395
-	        }
396
-	        $object->entity					= (GETPOSTISSET('entity')?GETPOST('entity', 'int'):$conf->entity);
397
-	        $object->name_alias				= GETPOST('name_alias');
398
-	        $object->address					= GETPOST('address');
399
-	        $object->zip						= GETPOST('zipcode', 'alpha');
400
-	        $object->town					= GETPOST('town', 'alpha');
401
-	        $object->country_id				= GETPOST('country_id', 'int');
402
-	        $object->state_id				= GETPOST('state_id', 'int');
403
-	        $object->skype					= GETPOST('skype', 'alpha');
404
-	        $object->phone					= GETPOST('phone', 'alpha');
405
-	        $object->fax						= GETPOST('fax','alpha');
406
-	        $object->email					= trim(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL));
407
-	        $object->url						= trim(GETPOST('url', 'custom', 0, FILTER_SANITIZE_URL));
408
-	        $object->idprof1					= trim(GETPOST('idprof1', 'alpha'));
409
-	        $object->idprof2					= trim(GETPOST('idprof2', 'alpha'));
410
-	        $object->idprof3					= trim(GETPOST('idprof3', 'alpha'));
411
-	        $object->idprof4					= trim(GETPOST('idprof4', 'alpha'));
412
-	        $object->idprof5					= trim(GETPOST('idprof5', 'alpha'));
413
-	        $object->idprof6					= trim(GETPOST('idprof6', 'alpha'));
414
-	        $object->prefix_comm				= GETPOST('prefix_comm', 'alpha');
415
-	        $object->code_client				= GETPOST('code_client', 'alpha');
416
-	        $object->code_fournisseur		= GETPOST('code_fournisseur', 'alpha');
417
-	        $object->capital					= GETPOST('capital', 'alpha');
418
-	        $object->barcode					= GETPOST('barcode', 'alpha');
419
-
420
-	        $object->tva_intra				= GETPOST('tva_intra', 'alpha');
421
-	        $object->tva_assuj				= GETPOST('assujtva_value', 'alpha');
422
-	        $object->status					= GETPOST('status', 'alpha');
423
-
424
-	        // Local Taxes
425
-	        $object->localtax1_assuj			= GETPOST('localtax1assuj_value', 'alpha');
426
-	        $object->localtax2_assuj			= GETPOST('localtax2assuj_value', 'alpha');
427
-
428
-	        $object->localtax1_value			= GETPOST('lt1', 'alpha');
429
-	        $object->localtax2_value			= GETPOST('lt2', 'alpha');
430
-
431
-	        $object->forme_juridique_code	= GETPOST('forme_juridique_code', 'int');
432
-	        $object->effectif_id				= GETPOST('effectif_id', 'int');
433
-	        $object->typent_id				= GETPOST('typent_id','int');
434
-
435
-	        $object->typent_code				= dol_getIdFromCode($db, $object->typent_id, 'c_typent', 'id', 'code');	// Force typent_code too so check in verify() will be done on new type
436
-
437
-	        $object->client					= GETPOST('client', 'int');
438
-	        $object->fournisseur				= GETPOST('fournisseur', 'int');
439
-
440
-	        $object->commercial_id			= GETPOST('commercial_id', 'int');
441
-	        $object->default_lang			= GETPOST('default_lang');
442
-
443
-	        // Webservices url/key
444
-	        $object->webservices_url			= GETPOST('webservices_url', 'custom', 0, FILTER_SANITIZE_URL);
445
-	        $object->webservices_key			= GETPOST('webservices_key', 'san_alpha');
382
+			if (GETPOST("private") == 1)	// Ask to create a contact
383
+			{
384
+				$object->particulier			= GETPOST("private");
385
+
386
+				$object->name				= dolGetFirstLastname(GETPOST('firstname','alpha'),GETPOST('name','alpha'));
387
+				$object->civility_id			= GETPOST('civility_id');	// Note: civility id is a code, not an int
388
+				// Add non official properties
389
+				$object->name_bis			= GETPOST('name','alpha');
390
+				$object->firstname			= GETPOST('firstname','alpha');
391
+			}
392
+			else
393
+			{
394
+				$object->name				= GETPOST('name', 'alpha');
395
+			}
396
+			$object->entity					= (GETPOSTISSET('entity')?GETPOST('entity', 'int'):$conf->entity);
397
+			$object->name_alias				= GETPOST('name_alias');
398
+			$object->address					= GETPOST('address');
399
+			$object->zip						= GETPOST('zipcode', 'alpha');
400
+			$object->town					= GETPOST('town', 'alpha');
401
+			$object->country_id				= GETPOST('country_id', 'int');
402
+			$object->state_id				= GETPOST('state_id', 'int');
403
+			$object->skype					= GETPOST('skype', 'alpha');
404
+			$object->phone					= GETPOST('phone', 'alpha');
405
+			$object->fax						= GETPOST('fax','alpha');
406
+			$object->email					= trim(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL));
407
+			$object->url						= trim(GETPOST('url', 'custom', 0, FILTER_SANITIZE_URL));
408
+			$object->idprof1					= trim(GETPOST('idprof1', 'alpha'));
409
+			$object->idprof2					= trim(GETPOST('idprof2', 'alpha'));
410
+			$object->idprof3					= trim(GETPOST('idprof3', 'alpha'));
411
+			$object->idprof4					= trim(GETPOST('idprof4', 'alpha'));
412
+			$object->idprof5					= trim(GETPOST('idprof5', 'alpha'));
413
+			$object->idprof6					= trim(GETPOST('idprof6', 'alpha'));
414
+			$object->prefix_comm				= GETPOST('prefix_comm', 'alpha');
415
+			$object->code_client				= GETPOST('code_client', 'alpha');
416
+			$object->code_fournisseur		= GETPOST('code_fournisseur', 'alpha');
417
+			$object->capital					= GETPOST('capital', 'alpha');
418
+			$object->barcode					= GETPOST('barcode', 'alpha');
419
+
420
+			$object->tva_intra				= GETPOST('tva_intra', 'alpha');
421
+			$object->tva_assuj				= GETPOST('assujtva_value', 'alpha');
422
+			$object->status					= GETPOST('status', 'alpha');
423
+
424
+			// Local Taxes
425
+			$object->localtax1_assuj			= GETPOST('localtax1assuj_value', 'alpha');
426
+			$object->localtax2_assuj			= GETPOST('localtax2assuj_value', 'alpha');
427
+
428
+			$object->localtax1_value			= GETPOST('lt1', 'alpha');
429
+			$object->localtax2_value			= GETPOST('lt2', 'alpha');
430
+
431
+			$object->forme_juridique_code	= GETPOST('forme_juridique_code', 'int');
432
+			$object->effectif_id				= GETPOST('effectif_id', 'int');
433
+			$object->typent_id				= GETPOST('typent_id','int');
434
+
435
+			$object->typent_code				= dol_getIdFromCode($db, $object->typent_id, 'c_typent', 'id', 'code');	// Force typent_code too so check in verify() will be done on new type
436
+
437
+			$object->client					= GETPOST('client', 'int');
438
+			$object->fournisseur				= GETPOST('fournisseur', 'int');
439
+
440
+			$object->commercial_id			= GETPOST('commercial_id', 'int');
441
+			$object->default_lang			= GETPOST('default_lang');
442
+
443
+			// Webservices url/key
444
+			$object->webservices_url			= GETPOST('webservices_url', 'custom', 0, FILTER_SANITIZE_URL);
445
+			$object->webservices_key			= GETPOST('webservices_key', 'san_alpha');
446 446
 
447 447
 			// Incoterms
448 448
 			if (!empty($conf->incoterm->enabled))
@@ -457,70 +457,70 @@  discard block
 block discarded – undo
457 457
 				$object->multicurrency_code = GETPOST('multicurrency_code', 'alpha');
458 458
 			}
459 459
 
460
-	        // Fill array 'array_options' with data from add form
461
-	        $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
460
+			// Fill array 'array_options' with data from add form
461
+			$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
462 462
 			if ($ret < 0)
463 463
 			{
464 464
 				 $error++;
465 465
 			}
466 466
 
467
-	        if (GETPOST('deletephoto')) $object->logo = '';
468
-	        else if (! empty($_FILES['photo']['name'])) $object->logo = dol_sanitizeFileName($_FILES['photo']['name']);
469
-
470
-	        // Check parameters
471
-	        if (! GETPOST('cancel','alpha'))
472
-	        {
473
-	            if (! empty($object->email) && ! isValidEMail($object->email))
474
-	            {
475
-	                $langs->load("errors");
476
-	                $error++;
477
-	                setEventMessages('', $langs->trans("ErrorBadEMail",$object->email), 'errors');
478
-	            }
479
-	            if (! empty($object->url) && ! isValidUrl($object->url))
480
-	            {
481
-	                $langs->load("errors");
482
-	                setEventMessages('', $langs->trans("ErrorBadUrl",$object->url), 'errors');
483
-	            }
484
-	            if ($object->fournisseur && ! $conf->fournisseur->enabled)
485
-	            {
486
-	                $langs->load("errors");
487
-	                setEventMessages('', $langs->trans("ErrorSupplierModuleNotEnabled"), 'errors');
488
-	            }
489
-	            if (! empty($object->webservices_url)) {
490
-	                //Check if has transport, without any the soap client will give error
491
-	                if (strpos($object->webservices_url, "http") === false)
492
-	                {
493
-	                    $object->webservices_url = "http://".$object->webservices_url;
494
-	                }
495
-	                if (! isValidUrl($object->webservices_url)) {
496
-	                    $langs->load("errors");
497
-	                    $error++; $errors[] = $langs->trans("ErrorBadUrl",$object->webservices_url);
498
-	                }
499
-	            }
500
-
501
-	            // We set country_id, country_code and country for the selected country
502
-	            $object->country_id=GETPOST('country_id')!=''?GETPOST('country_id'):$mysoc->country_id;
503
-	            if ($object->country_id)
504
-	            {
505
-	            	$tmparray=getCountry($object->country_id,'all');
506
-	            	$object->country_code=$tmparray['code'];
507
-	            	$object->country=$tmparray['label'];
508
-	            }
509
-	        }
510
-        }
511
-
512
-        if (! $error)
513
-        {
514
-            if ($action == 'add')
515
-            {
516
-            	$error = 0;
517
-
518
-                $db->begin();
519
-
520
-                if (empty($object->client))      $object->code_client='';
521
-                if (empty($object->fournisseur)) $object->code_fournisseur='';
522
-
523
-                $result = $object->create($user);
467
+			if (GETPOST('deletephoto')) $object->logo = '';
468
+			else if (! empty($_FILES['photo']['name'])) $object->logo = dol_sanitizeFileName($_FILES['photo']['name']);
469
+
470
+			// Check parameters
471
+			if (! GETPOST('cancel','alpha'))
472
+			{
473
+				if (! empty($object->email) && ! isValidEMail($object->email))
474
+				{
475
+					$langs->load("errors");
476
+					$error++;
477
+					setEventMessages('', $langs->trans("ErrorBadEMail",$object->email), 'errors');
478
+				}
479
+				if (! empty($object->url) && ! isValidUrl($object->url))
480
+				{
481
+					$langs->load("errors");
482
+					setEventMessages('', $langs->trans("ErrorBadUrl",$object->url), 'errors');
483
+				}
484
+				if ($object->fournisseur && ! $conf->fournisseur->enabled)
485
+				{
486
+					$langs->load("errors");
487
+					setEventMessages('', $langs->trans("ErrorSupplierModuleNotEnabled"), 'errors');
488
+				}
489
+				if (! empty($object->webservices_url)) {
490
+					//Check if has transport, without any the soap client will give error
491
+					if (strpos($object->webservices_url, "http") === false)
492
+					{
493
+						$object->webservices_url = "http://".$object->webservices_url;
494
+					}
495
+					if (! isValidUrl($object->webservices_url)) {
496
+						$langs->load("errors");
497
+						$error++; $errors[] = $langs->trans("ErrorBadUrl",$object->webservices_url);
498
+					}
499
+				}
500
+
501
+				// We set country_id, country_code and country for the selected country
502
+				$object->country_id=GETPOST('country_id')!=''?GETPOST('country_id'):$mysoc->country_id;
503
+				if ($object->country_id)
504
+				{
505
+					$tmparray=getCountry($object->country_id,'all');
506
+					$object->country_code=$tmparray['code'];
507
+					$object->country=$tmparray['label'];
508
+				}
509
+			}
510
+		}
511
+
512
+		if (! $error)
513
+		{
514
+			if ($action == 'add')
515
+			{
516
+				$error = 0;
517
+
518
+				$db->begin();
519
+
520
+				if (empty($object->client))      $object->code_client='';
521
+				if (empty($object->fournisseur)) $object->code_fournisseur='';
522
+
523
+				$result = $object->create($user);
524 524
 
525 525
 				if ($result >= 0)
526 526
 				{
@@ -553,116 +553,116 @@  discard block
 block discarded – undo
553 553
 						setEventMessages($object->error, $object->errors, 'errors');
554 554
 					}
555 555
 
556
-                    // Logo/Photo save
557
-                    $dir     = $conf->societe->multidir_output[$conf->entity]."/".$object->id."/logos/";
558
-                    $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
559
-                    if ($file_OK)
560
-                    {
561
-                        if (image_format_supported($_FILES['photo']['name']))
562
-                        {
563
-                            dol_mkdir($dir);
564
-
565
-                            if (@is_dir($dir))
566
-                            {
567
-                                $newfile=$dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
568
-                                $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1);
569
-
570
-                                if (! $result > 0)
571
-                                {
572
-                                    $errors[] = "ErrorFailedToSaveFile";
573
-                                }
574
-                                else
575
-                                {
576
-                                    // Create thumbs
577
-                                    $object->addThumbs($newfile);
578
-                                }
579
-                            }
580
-                        }
581
-                    }
582
-                    else
556
+					// Logo/Photo save
557
+					$dir     = $conf->societe->multidir_output[$conf->entity]."/".$object->id."/logos/";
558
+					$file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
559
+					if ($file_OK)
560
+					{
561
+						if (image_format_supported($_FILES['photo']['name']))
562
+						{
563
+							dol_mkdir($dir);
564
+
565
+							if (@is_dir($dir))
566
+							{
567
+								$newfile=$dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
568
+								$result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1);
569
+
570
+								if (! $result > 0)
571
+								{
572
+									$errors[] = "ErrorFailedToSaveFile";
573
+								}
574
+								else
575
+								{
576
+									// Create thumbs
577
+									$object->addThumbs($newfile);
578
+								}
579
+							}
580
+						}
581
+					}
582
+					else
583 583
 					{
584 584
 						switch($_FILES['photo']['error'])
585 585
 						{
586
-						    case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
587
-						    case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
588
-						      $errors[] = "ErrorFileSizeTooLarge";
589
-						      break;
590
-	      					case 3: //uploaded file was only partially uploaded
591
-						      $errors[] = "ErrorFilePartiallyUploaded";
592
-						      break;
586
+							case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
587
+							case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
588
+							  $errors[] = "ErrorFileSizeTooLarge";
589
+							  break;
590
+		  					case 3: //uploaded file was only partially uploaded
591
+							  $errors[] = "ErrorFilePartiallyUploaded";
592
+							  break;
593 593
 						}
594
-	                }
595
-                    // Gestion du logo de la société
596
-                }
597
-                else
594
+					}
595
+					// Gestion du logo de la société
596
+				}
597
+				else
598 598
 				{
599
-				    if ($db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') // TODO Sometime errors on duplicate on profid and not on code, so we must manage this case
599
+					if ($db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') // TODO Sometime errors on duplicate on profid and not on code, so we must manage this case
600 600
 					{
601 601
 						$duplicate_code_error = true;
602 602
 						$object->code_fournisseur = null;
603 603
 						$object->code_client = null;
604 604
 					}
605 605
 
606
-                    setEventMessages($object->error, $object->errors, 'errors');
607
-                   	$error++;
608
-                }
609
-
610
-                if ($result >= 0 && ! $error)
611
-                {
612
-                    $db->commit();
613
-
614
-                	if (! empty($backtopage))
615
-                	{
616
-                	    if (preg_match('/\?/', $backtopage)) $backtopage.='&socid='.$object->id;
617
-               		    header("Location: ".$backtopage);
618
-                    	exit;
619
-                	}
620
-                	else
621
-                	{
622
-                    	$url=$_SERVER["PHP_SELF"]."?socid=".$object->id;
623
-                    	if (($object->client == 1 || $object->client == 3) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) $url=DOL_URL_ROOT."/comm/card.php?socid=".$object->id;
624
-                    	else if ($object->fournisseur == 1) $url=DOL_URL_ROOT."/fourn/card.php?socid=".$object->id;
625
-
626
-                		header("Location: ".$url);
627
-                    	exit;
628
-                	}
629
-                }
630
-                else
631
-                {
632
-                    $db->rollback();
633
-                    $action='create';
634
-                }
635
-            }
636
-
637
-            if ($action == 'update')
638
-            {
639
-            	$error = 0;
640
-
641
-                if (GETPOST('cancel','alpha'))
642
-                {
643
-                	if (! empty($backtopage))
644
-                	{
645
-               		    header("Location: ".$backtopage);
646
-                    	exit;
647
-                	}
648
-                	else
649
-                	{
650
-               		    header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid);
651
-                    	exit;
652
-                	}
653
-                }
654
-
655
-                // To not set code if third party is not concerned. But if it had values, we keep them.
656
-                if (empty($object->client) && empty($object->oldcopy->code_client))          $object->code_client='';
657
-                if (empty($object->fournisseur)&& empty($object->oldcopy->code_fournisseur)) $object->code_fournisseur='';
658
-                //var_dump($object);exit;
659
-
660
-                $result = $object->update($socid, $user, 1, $object->oldcopy->codeclient_modifiable(), $object->oldcopy->codefournisseur_modifiable(), 'update', 0);
661
-                if ($result <=  0)
662
-                {
663
-                    setEventMessages($object->error, $object->errors, 'errors');
664
-                  	$error++;
665
-                }
606
+					setEventMessages($object->error, $object->errors, 'errors');
607
+				   	$error++;
608
+				}
609
+
610
+				if ($result >= 0 && ! $error)
611
+				{
612
+					$db->commit();
613
+
614
+					if (! empty($backtopage))
615
+					{
616
+						if (preg_match('/\?/', $backtopage)) $backtopage.='&socid='.$object->id;
617
+			   			header("Location: ".$backtopage);
618
+						exit;
619
+					}
620
+					else
621
+					{
622
+						$url=$_SERVER["PHP_SELF"]."?socid=".$object->id;
623
+						if (($object->client == 1 || $object->client == 3) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) $url=DOL_URL_ROOT."/comm/card.php?socid=".$object->id;
624
+						else if ($object->fournisseur == 1) $url=DOL_URL_ROOT."/fourn/card.php?socid=".$object->id;
625
+
626
+						header("Location: ".$url);
627
+						exit;
628
+					}
629
+				}
630
+				else
631
+				{
632
+					$db->rollback();
633
+					$action='create';
634
+				}
635
+			}
636
+
637
+			if ($action == 'update')
638
+			{
639
+				$error = 0;
640
+
641
+				if (GETPOST('cancel','alpha'))
642
+				{
643
+					if (! empty($backtopage))
644
+					{
645
+			   			header("Location: ".$backtopage);
646
+						exit;
647
+					}
648
+					else
649
+					{
650
+			   			header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid);
651
+						exit;
652
+					}
653
+				}
654
+
655
+				// To not set code if third party is not concerned. But if it had values, we keep them.
656
+				if (empty($object->client) && empty($object->oldcopy->code_client))          $object->code_client='';
657
+				if (empty($object->fournisseur)&& empty($object->oldcopy->code_fournisseur)) $object->code_fournisseur='';
658
+				//var_dump($object);exit;
659
+
660
+				$result = $object->update($socid, $user, 1, $object->oldcopy->codeclient_modifiable(), $object->oldcopy->codefournisseur_modifiable(), 'update', 0);
661
+				if ($result <=  0)
662
+				{
663
+					setEventMessages($object->error, $object->errors, 'errors');
664
+				  	$error++;
665
+				}
666 666
 
667 667
 				// Prevent thirdparty's emptying if a user hasn't rights $user->rights->categorie->lire (in such a case, post of 'custcats' is not defined)
668 668
 				if (! $error && !empty($user->rights->categorie->lire))
@@ -686,155 +686,155 @@  discard block
 block discarded – undo
686 686
 					}
687 687
 				}
688 688
 
689
-                // Logo/Photo save
690
-                $dir     = $conf->societe->multidir_output[$object->entity]."/".$object->id."/logos";
691
-                $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
692
-                if (GETPOST('deletephoto') && $object->photo)
693
-                {
694
-                    $fileimg=$dir.'/'.$object->logo;
695
-                    $dirthumbs=$dir.'/thumbs';
696
-                    dol_delete_file($fileimg);
697
-                    dol_delete_dir_recursive($dirthumbs);
698
-                }
699
-                if ($file_OK)
700
-                {
701
-                    if (image_format_supported($_FILES['photo']['name']) > 0)
702
-                    {
703
-                        dol_mkdir($dir);
704
-
705
-                        if (@is_dir($dir))
706
-                        {
707
-                            $newfile=$dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
708
-                            $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1);
709
-
710
-                            if (! $result > 0)
711
-                            {
712
-                                $errors[] = "ErrorFailedToSaveFile";
713
-                            }
714
-                            else
715
-                            {
716
-                            	// Create thumbs
717
-                            	$object->addThumbs($newfile);
718
-
719
-                                // Index file in database
720
-                                if (! empty($conf->global->THIRDPARTY_LOGO_ALLOW_EXTERNAL_DOWNLOAD))
721
-                                {
722
-                                	require_once DOL_DOCUMENT_ROOT .'/core/lib/files.lib.php';
723
-                                	// the dir dirname($newfile) is directory of logo, so we should have only one file at once into index, so we delete indexes for the dir
724
-                                	deleteFilesIntoDatabaseIndex(dirname($newfile), '', '', 'uploaded', 1);
725
-                                	// now we index the uploaded logo file
726
-                                	addFileIntoDatabaseIndex(dirname($newfile), basename($newfile), '', 'uploaded', 1);
727
-                                }
728
-                            }
729
-                        }
730
-                    }
731
-                    else
689
+				// Logo/Photo save
690
+				$dir     = $conf->societe->multidir_output[$object->entity]."/".$object->id."/logos";
691
+				$file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
692
+				if (GETPOST('deletephoto') && $object->photo)
693
+				{
694
+					$fileimg=$dir.'/'.$object->logo;
695
+					$dirthumbs=$dir.'/thumbs';
696
+					dol_delete_file($fileimg);
697
+					dol_delete_dir_recursive($dirthumbs);
698
+				}
699
+				if ($file_OK)
700
+				{
701
+					if (image_format_supported($_FILES['photo']['name']) > 0)
702
+					{
703
+						dol_mkdir($dir);
704
+
705
+						if (@is_dir($dir))
706
+						{
707
+							$newfile=$dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
708
+							$result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1);
709
+
710
+							if (! $result > 0)
711
+							{
712
+								$errors[] = "ErrorFailedToSaveFile";
713
+							}
714
+							else
715
+							{
716
+								// Create thumbs
717
+								$object->addThumbs($newfile);
718
+
719
+								// Index file in database
720
+								if (! empty($conf->global->THIRDPARTY_LOGO_ALLOW_EXTERNAL_DOWNLOAD))
721
+								{
722
+									require_once DOL_DOCUMENT_ROOT .'/core/lib/files.lib.php';
723
+									// the dir dirname($newfile) is directory of logo, so we should have only one file at once into index, so we delete indexes for the dir
724
+									deleteFilesIntoDatabaseIndex(dirname($newfile), '', '', 'uploaded', 1);
725
+									// now we index the uploaded logo file
726
+									addFileIntoDatabaseIndex(dirname($newfile), basename($newfile), '', 'uploaded', 1);
727
+								}
728
+							}
729
+						}
730
+					}
731
+					else
732 732
 					{
733
-                        $errors[] = "ErrorBadImageFormat";
734
-                    }
735
-                }
736
-                else
737
-                {
733
+						$errors[] = "ErrorBadImageFormat";
734
+					}
735
+				}
736
+				else
737
+				{
738 738
 					switch($_FILES['photo']['error'])
739 739
 					{
740
-					    case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
741
-					    case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
742
-					      $errors[] = "ErrorFileSizeTooLarge";
743
-					      break;
744
-      					case 3: //uploaded file was only partially uploaded
745
-					      $errors[] = "ErrorFilePartiallyUploaded";
746
-					      break;
740
+						case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
741
+						case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
742
+						  $errors[] = "ErrorFileSizeTooLarge";
743
+						  break;
744
+	  					case 3: //uploaded file was only partially uploaded
745
+						  $errors[] = "ErrorFilePartiallyUploaded";
746
+						  break;
747
+					}
748
+				}
749
+				// Gestion du logo de la société
750
+
751
+
752
+				// Update linked member
753
+				if (! $error && $object->fk_soc > 0)
754
+				{
755
+
756
+					$sql = "UPDATE ".MAIN_DB_PREFIX."adherent";
757
+					$sql.= " SET fk_soc = NULL WHERE fk_soc = " . $id;
758
+					if (! $object->db->query($sql))
759
+					{
760
+						$error++;
761
+						$object->error .= $object->db->lasterror();
762
+					}
763
+				}
764
+
765
+				if (! $error && ! count($errors))
766
+				{
767
+					if (! empty($backtopage))
768
+					{
769
+			   			header("Location: ".$backtopage);
770
+						exit;
771
+					}
772
+					else
773
+					{
774
+			   			header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid);
775
+						exit;
747 776
 					}
748
-                }
749
-                // Gestion du logo de la société
750
-
751
-
752
-                // Update linked member
753
-                if (! $error && $object->fk_soc > 0)
754
-                {
755
-
756
-                	$sql = "UPDATE ".MAIN_DB_PREFIX."adherent";
757
-                	$sql.= " SET fk_soc = NULL WHERE fk_soc = " . $id;
758
-                	if (! $object->db->query($sql))
759
-                	{
760
-                		$error++;
761
-                		$object->error .= $object->db->lasterror();
762
-                	}
763
-                }
764
-
765
-                if (! $error && ! count($errors))
766
-                {
767
-                	if (! empty($backtopage))
768
-                	{
769
-               		    header("Location: ".$backtopage);
770
-                    	exit;
771
-                	}
772
-                	else
773
-                	{
774
-               		    header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid);
775
-                    	exit;
776
-                	}
777
-                }
778
-                else
779
-                {
780
-                    $object->id = $socid;
781
-                    $action= "edit";
782
-                }
783
-            }
784
-        }
785
-        else
786
-        {
787
-        	$action = ($action=='add'?'create':'edit');
788
-        }
789
-    }
790
-
791
-    // Delete third party
792
-    if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->societe->supprimer)
793
-    {
794
-        $object->fetch($socid);
795
-        $result = $object->delete($socid, $user);
796
-
797
-        if ($result > 0)
798
-        {
799
-            header("Location: ".DOL_URL_ROOT."/societe/list.php?delsoc=".urlencode($object->name));
800
-            exit;
801
-        }
802
-        else
803
-        {
804
-            $langs->load("errors");
805
-           	setEventMessages($object->error, $object->errors, 'errors');
806
-           	$error++;
807
-            $action='';
808
-        }
809
-    }
810
-
811
-    // Set parent company
812
-    if ($action == 'set_thirdparty' && $user->rights->societe->creer)
813
-    {
814
-    	$object->fetch($socid);
815
-    	$result = $object->set_parent(GETPOST('editparentcompany','int'));
816
-    }
817
-
818
-    // Set incoterm
819
-    if ($action == 'set_incoterms' && !empty($conf->incoterm->enabled))
820
-    {
821
-    	$object->fetch($socid);
822
-    	$result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha'));
823
-    }
824
-
825
-    // Actions to send emails
826
-    $id=$socid;
827
-    $trigger_name='COMPANY_SENTBYMAIL';
828
-    $paramname='socid';
829
-    $mode='emailfromthirdparty';
830
-    $trackid='thi'.$object->id;
831
-    include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
832
-
833
-    // Actions to build doc
834
-    $id = $socid;
835
-    $upload_dir = $conf->societe->dir_output;
836
-    $permissioncreate=$user->rights->societe->creer;
837
-    include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
777
+				}
778
+				else
779
+				{
780
+					$object->id = $socid;
781
+					$action= "edit";
782
+				}
783
+			}
784
+		}
785
+		else
786
+		{
787
+			$action = ($action=='add'?'create':'edit');
788
+		}
789
+	}
790
+
791
+	// Delete third party
792
+	if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->societe->supprimer)
793
+	{
794
+		$object->fetch($socid);
795
+		$result = $object->delete($socid, $user);
796
+
797
+		if ($result > 0)
798
+		{
799
+			header("Location: ".DOL_URL_ROOT."/societe/list.php?delsoc=".urlencode($object->name));
800
+			exit;
801
+		}
802
+		else
803
+		{
804
+			$langs->load("errors");
805
+		   	setEventMessages($object->error, $object->errors, 'errors');
806
+		   	$error++;
807
+			$action='';
808
+		}
809
+	}
810
+
811
+	// Set parent company
812
+	if ($action == 'set_thirdparty' && $user->rights->societe->creer)
813
+	{
814
+		$object->fetch($socid);
815
+		$result = $object->set_parent(GETPOST('editparentcompany','int'));
816
+	}
817
+
818
+	// Set incoterm
819
+	if ($action == 'set_incoterms' && !empty($conf->incoterm->enabled))
820
+	{
821
+		$object->fetch($socid);
822
+		$result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha'));
823
+	}
824
+
825
+	// Actions to send emails
826
+	$id=$socid;
827
+	$trigger_name='COMPANY_SENTBYMAIL';
828
+	$paramname='socid';
829
+	$mode='emailfromthirdparty';
830
+	$trackid='thi'.$object->id;
831
+	include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
832
+
833
+	// Actions to build doc
834
+	$id = $socid;
835
+	$upload_dir = $conf->societe->dir_output;
836
+	$permissioncreate=$user->rights->societe->creer;
837
+	include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
838 838
 }
839 839
 
840 840
 
@@ -849,7 +849,7 @@  discard block
 block discarded – undo
849 849
 
850 850
 if ($socid > 0 && empty($object->id))
851 851
 {
852
-    $result=$object->fetch($socid);
852
+	$result=$object->fetch($socid);
853 853
 	if ($result <= 0) dol_print_error('',$object->error);
854 854
 }
855 855
 
@@ -862,161 +862,161 @@  discard block
 block discarded – undo
862 862
 
863 863
 if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
864 864
 {
865
-    // -----------------------------------------
866
-    // When used with CANVAS
867
-    // -----------------------------------------
865
+	// -----------------------------------------
866
+	// When used with CANVAS
867
+	// -----------------------------------------
868 868
    	$objcanvas->assign_values($action, $object->id, $object->ref);	// Set value for templates
869
-    $objcanvas->display_canvas($action);							// Show template
869
+	$objcanvas->display_canvas($action);							// Show template
870 870
 }
871 871
 else
872 872
 {
873
-    // -----------------------------------------
874
-    // When used in standard mode
875
-    // -----------------------------------------
876
-    if ($action == 'create')
877
-    {
878
-        /*
873
+	// -----------------------------------------
874
+	// When used in standard mode
875
+	// -----------------------------------------
876
+	if ($action == 'create')
877
+	{
878
+		/*
879 879
          *  Creation
880 880
          */
881 881
 		$private=GETPOST("private","int");
882 882
 		if (! empty($conf->global->THIRDPARTY_DEFAULT_CREATE_CONTACT) && ! isset($_GET['private']) && ! isset($_POST['private'])) $private=1;
883
-    	if (empty($private)) $private=0;
884
-
885
-        // Load object modCodeTiers
886
-        $module=(! empty($conf->global->SOCIETE_CODECLIENT_ADDON)?$conf->global->SOCIETE_CODECLIENT_ADDON:'mod_codeclient_leopard');
887
-        if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php')
888
-        {
889
-            $module = substr($module, 0, dol_strlen($module)-4);
890
-        }
891
-        $dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
892
-        foreach ($dirsociete as $dirroot)
893
-        {
894
-            $res=dol_include_once($dirroot.$module.'.php');
895
-            if ($res) break;
896
-        }
897
-        $modCodeClient = new $module;
898
-        // Load object modCodeFournisseur
899
-        $module=(! empty($conf->global->SOCIETE_CODECLIENT_ADDON)?$conf->global->SOCIETE_CODECLIENT_ADDON:'mod_codeclient_leopard');
900
-        if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php')
901
-        {
902
-            $module = substr($module, 0, dol_strlen($module)-4);
903
-        }
904
-        $dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
905
-        foreach ($dirsociete as $dirroot)
906
-        {
907
-            $res=dol_include_once($dirroot.$module.'.php');
908
-            if ($res) break;
909
-        }
910
-        $modCodeFournisseur = new $module;
911
-
912
-        // Define if customer/prospect or supplier status is set or not
913
-        if (GETPOST("type")!='f')
914
-        {
915
-            $object->client=-1;
916
-            if (! empty($conf->global->THIRDPARTY_CUSTOMERPROSPECT_BY_DEFAULT))  { $object->client=3; }
917
-        }
918
-        if (GETPOST("type")=='c')  { $object->client=3; }   // Prospect / Customer
919
-        if (GETPOST("type")=='p')  { $object->client=2; }
920
-        if (! empty($conf->fournisseur->enabled) && (GETPOST("type")=='f' || (GETPOST("type")=='' && ! empty($conf->global->THIRDPARTY_SUPPLIER_BY_DEFAULT))))  { $object->fournisseur=1; }
921
-
922
-        $object->name				= GETPOST('name', 'alpha');
923
-        $object->firstname			= GETPOST('firstname', 'alpha');
924
-        $object->particulier		= $private;
925
-        $object->prefix_comm		= GETPOST('prefix_comm');
926
-        $object->client				= GETPOST('client')?GETPOST('client'):$object->client;
927
-
928
-        if(empty($duplicate_code_error)) {
929
-	        $object->code_client		= GETPOST('code_client', 'alpha');
930
-	        $object->fournisseur		= GETPOST('fournisseur')?GETPOST('fournisseur'):$object->fournisseur;
931
-        }
883
+		if (empty($private)) $private=0;
884
+
885
+		// Load object modCodeTiers
886
+		$module=(! empty($conf->global->SOCIETE_CODECLIENT_ADDON)?$conf->global->SOCIETE_CODECLIENT_ADDON:'mod_codeclient_leopard');
887
+		if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php')
888
+		{
889
+			$module = substr($module, 0, dol_strlen($module)-4);
890
+		}
891
+		$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
892
+		foreach ($dirsociete as $dirroot)
893
+		{
894
+			$res=dol_include_once($dirroot.$module.'.php');
895
+			if ($res) break;
896
+		}
897
+		$modCodeClient = new $module;
898
+		// Load object modCodeFournisseur
899
+		$module=(! empty($conf->global->SOCIETE_CODECLIENT_ADDON)?$conf->global->SOCIETE_CODECLIENT_ADDON:'mod_codeclient_leopard');
900
+		if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php')
901
+		{
902
+			$module = substr($module, 0, dol_strlen($module)-4);
903
+		}
904
+		$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
905
+		foreach ($dirsociete as $dirroot)
906
+		{
907
+			$res=dol_include_once($dirroot.$module.'.php');
908
+			if ($res) break;
909
+		}
910
+		$modCodeFournisseur = new $module;
911
+
912
+		// Define if customer/prospect or supplier status is set or not
913
+		if (GETPOST("type")!='f')
914
+		{
915
+			$object->client=-1;
916
+			if (! empty($conf->global->THIRDPARTY_CUSTOMERPROSPECT_BY_DEFAULT))  { $object->client=3; }
917
+		}
918
+		if (GETPOST("type")=='c')  { $object->client=3; }   // Prospect / Customer
919
+		if (GETPOST("type")=='p')  { $object->client=2; }
920
+		if (! empty($conf->fournisseur->enabled) && (GETPOST("type")=='f' || (GETPOST("type")=='' && ! empty($conf->global->THIRDPARTY_SUPPLIER_BY_DEFAULT))))  { $object->fournisseur=1; }
921
+
922
+		$object->name				= GETPOST('name', 'alpha');
923
+		$object->firstname			= GETPOST('firstname', 'alpha');
924
+		$object->particulier		= $private;
925
+		$object->prefix_comm		= GETPOST('prefix_comm');
926
+		$object->client				= GETPOST('client')?GETPOST('client'):$object->client;
927
+
928
+		if(empty($duplicate_code_error)) {
929
+			$object->code_client		= GETPOST('code_client', 'alpha');
930
+			$object->fournisseur		= GETPOST('fournisseur')?GETPOST('fournisseur'):$object->fournisseur;
931
+		}
932 932
 		else {
933 933
 			setEventMessages($langs->trans('NewCustomerSupplierCodeProposed'),'', 'warnings');
934 934
 		}
935 935
 
936
-        $object->code_fournisseur	= GETPOST('code_fournisseur', 'alpha');
937
-        $object->address			= GETPOST('address', 'alpha');
938
-        $object->zip				= GETPOST('zipcode', 'alpha');
939
-        $object->town				= GETPOST('town', 'alpha');
940
-        $object->state_id			= GETPOST('state_id', 'int');
941
-        $object->skype				= GETPOST('skype', 'alpha');
942
-        $object->phone				= GETPOST('phone', 'alpha');
943
-        $object->fax				= GETPOST('fax', 'alpha');
944
-        $object->email				= GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL);
945
-        $object->url				= GETPOST('url', 'custom', 0, FILTER_SANITIZE_URL);
946
-        $object->capital			= GETPOST('capital', 'alpha');
947
-        $object->barcode			= GETPOST('barcode', 'alpha');
948
-        $object->idprof1			= GETPOST('idprof1', 'alpha');
949
-        $object->idprof2			= GETPOST('idprof2', 'alpha');
950
-        $object->idprof3			= GETPOST('idprof3', 'alpha');
951
-        $object->idprof4			= GETPOST('idprof4', 'alpha');
952
-        $object->idprof5			= GETPOST('idprof5', 'alpha');
953
-        $object->idprof6			= GETPOST('idprof6', 'alpha');
954
-        $object->typent_id			= GETPOST('typent_id', 'int');
955
-        $object->effectif_id		= GETPOST('effectif_id', 'int');
956
-        $object->civility_id		= GETPOST('civility_id', 'int');
957
-
958
-        $object->tva_assuj			= GETPOST('assujtva_value', 'int');
959
-        $object->status				= GETPOST('status', 'int');
960
-
961
-        //Local Taxes
962
-        $object->localtax1_assuj	= GETPOST('localtax1assuj_value', 'int');
963
-        $object->localtax2_assuj	= GETPOST('localtax2assuj_value', 'int');
964
-
965
-        $object->localtax1_value	=GETPOST('lt1', 'int');
966
-        $object->localtax2_value	=GETPOST('lt2', 'int');
967
-
968
-        $object->tva_intra			= GETPOST('tva_intra', 'alpha');
969
-
970
-        $object->commercial_id		= GETPOST('commercial_id', 'int');
971
-        $object->default_lang		= GETPOST('default_lang');
972
-
973
-        $object->logo = (isset($_FILES['photo'])?dol_sanitizeFileName($_FILES['photo']['name']):'');
974
-
975
-        // Gestion du logo de la société
976
-        $dir     = $conf->societe->multidir_output[$conf->entity]."/".$object->id."/logos";
977
-        $file_OK = (isset($_FILES['photo'])?is_uploaded_file($_FILES['photo']['tmp_name']):false);
978
-        if ($file_OK)
979
-        {
980
-            if (image_format_supported($_FILES['photo']['name']))
981
-            {
982
-                dol_mkdir($dir);
983
-
984
-                if (@is_dir($dir))
985
-                {
986
-                    $newfile=$dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
987
-                    $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1);
988
-
989
-                    if (! $result > 0)
990
-                    {
991
-                        $errors[] = "ErrorFailedToSaveFile";
992
-                    }
993
-                    else
994
-                    {
995
-                        // Create thumbs
996
-                        $object->addThumbs($newfile);
997
-                    }
998
-                }
999
-            }
1000
-        }
1001
-
1002
-        // We set country_id, country_code and country for the selected country
1003
-        $object->country_id=GETPOST('country_id')?GETPOST('country_id'):$mysoc->country_id;
1004
-        if ($object->country_id)
1005
-        {
1006
-            $tmparray=getCountry($object->country_id,'all');
1007
-            $object->country_code=$tmparray['code'];
1008
-            $object->country=$tmparray['label'];
1009
-        }
1010
-        $object->forme_juridique_code=GETPOST('forme_juridique_code');
1011
-        /* Show create form */
1012
-
1013
-        $linkback="";
1014
-        print load_fiche_titre($langs->trans("NewThirdParty"),$linkback,'title_companies.png');
1015
-
1016
-        if (! empty($conf->use_javascript_ajax))
1017
-        {
1018
-            print "\n".'<script type="text/javascript">';
1019
-            print '$(document).ready(function () {
936
+		$object->code_fournisseur	= GETPOST('code_fournisseur', 'alpha');
937
+		$object->address			= GETPOST('address', 'alpha');
938
+		$object->zip				= GETPOST('zipcode', 'alpha');
939
+		$object->town				= GETPOST('town', 'alpha');
940
+		$object->state_id			= GETPOST('state_id', 'int');
941
+		$object->skype				= GETPOST('skype', 'alpha');
942
+		$object->phone				= GETPOST('phone', 'alpha');
943
+		$object->fax				= GETPOST('fax', 'alpha');
944
+		$object->email				= GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL);
945
+		$object->url				= GETPOST('url', 'custom', 0, FILTER_SANITIZE_URL);
946
+		$object->capital			= GETPOST('capital', 'alpha');
947
+		$object->barcode			= GETPOST('barcode', 'alpha');
948
+		$object->idprof1			= GETPOST('idprof1', 'alpha');
949
+		$object->idprof2			= GETPOST('idprof2', 'alpha');
950
+		$object->idprof3			= GETPOST('idprof3', 'alpha');
951
+		$object->idprof4			= GETPOST('idprof4', 'alpha');
952
+		$object->idprof5			= GETPOST('idprof5', 'alpha');
953
+		$object->idprof6			= GETPOST('idprof6', 'alpha');
954
+		$object->typent_id			= GETPOST('typent_id', 'int');
955
+		$object->effectif_id		= GETPOST('effectif_id', 'int');
956
+		$object->civility_id		= GETPOST('civility_id', 'int');
957
+
958
+		$object->tva_assuj			= GETPOST('assujtva_value', 'int');
959
+		$object->status				= GETPOST('status', 'int');
960
+
961
+		//Local Taxes
962
+		$object->localtax1_assuj	= GETPOST('localtax1assuj_value', 'int');
963
+		$object->localtax2_assuj	= GETPOST('localtax2assuj_value', 'int');
964
+
965
+		$object->localtax1_value	=GETPOST('lt1', 'int');
966
+		$object->localtax2_value	=GETPOST('lt2', 'int');
967
+
968
+		$object->tva_intra			= GETPOST('tva_intra', 'alpha');
969
+
970
+		$object->commercial_id		= GETPOST('commercial_id', 'int');
971
+		$object->default_lang		= GETPOST('default_lang');
972
+
973
+		$object->logo = (isset($_FILES['photo'])?dol_sanitizeFileName($_FILES['photo']['name']):'');
974
+
975
+		// Gestion du logo de la société
976
+		$dir     = $conf->societe->multidir_output[$conf->entity]."/".$object->id."/logos";
977
+		$file_OK = (isset($_FILES['photo'])?is_uploaded_file($_FILES['photo']['tmp_name']):false);
978
+		if ($file_OK)
979
+		{
980
+			if (image_format_supported($_FILES['photo']['name']))
981
+			{
982
+				dol_mkdir($dir);
983
+
984
+				if (@is_dir($dir))
985
+				{
986
+					$newfile=$dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
987
+					$result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1);
988
+
989
+					if (! $result > 0)
990
+					{
991
+						$errors[] = "ErrorFailedToSaveFile";
992
+					}
993
+					else
994
+					{
995
+						// Create thumbs
996
+						$object->addThumbs($newfile);
997
+					}
998
+				}
999
+			}
1000
+		}
1001
+
1002
+		// We set country_id, country_code and country for the selected country
1003
+		$object->country_id=GETPOST('country_id')?GETPOST('country_id'):$mysoc->country_id;
1004
+		if ($object->country_id)
1005
+		{
1006
+			$tmparray=getCountry($object->country_id,'all');
1007
+			$object->country_code=$tmparray['code'];
1008
+			$object->country=$tmparray['label'];
1009
+		}
1010
+		$object->forme_juridique_code=GETPOST('forme_juridique_code');
1011
+		/* Show create form */
1012
+
1013
+		$linkback="";
1014
+		print load_fiche_titre($langs->trans("NewThirdParty"),$linkback,'title_companies.png');
1015
+
1016
+		if (! empty($conf->use_javascript_ajax))
1017
+		{
1018
+			print "\n".'<script type="text/javascript">';
1019
+			print '$(document).ready(function () {
1020 1020
 						id_te_private=8;
1021 1021
                         id_ef15=1;
1022 1022
                         is_private='.$private.';
@@ -1044,494 +1044,494 @@  discard block
 block discarded – undo
1044 1044
                         	document.formsoc.submit();
1045 1045
                         });
1046 1046
                      });';
1047
-            print '</script>'."\n";
1048
-
1049
-            print '<div id="selectthirdpartytype">';
1050
-            print '<div class="hideonsmartphone float">';
1051
-            print $langs->trans("ThirdPartyType").': &nbsp; &nbsp; ';
1052
-            print '</div>';
1053
-	        print '<label for="radiocompany" class="radiocompany">';
1054
-            print '<input type="radio" id="radiocompany" class="flat" name="private"  value="0"'.($private?'':' checked').'>';
1055
-	        print '&nbsp;';
1056
-            print $langs->trans("CreateThirdPartyOnly");
1057
-	        print '</label>';
1058
-            print ' &nbsp; &nbsp; ';
1059
-	        print '<label for="radioprivate" class="radioprivate">';
1060
-            $text ='<input type="radio" id="radioprivate" class="flat" name="private" value="1"'.($private?' checked':'').'>';
1061
-	        $text.='&nbsp;';
1062
-	        $text.= $langs->trans("CreateThirdPartyAndContact");
1063
-	        $htmltext=$langs->trans("ToCreateContactWithSameName");
1064
-	        print $form->textwithpicto($text, $htmltext, 1, 'help', '', 0, 3);
1065
-            print '</label>';
1066
-            print '</div>';
1067
-            print "<br>\n";
1068
-        }
1069
-
1070
-        dol_htmloutput_mesg(is_numeric($error)?'':$error, $errors, 'error');
1071
-
1072
-        print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'" method="post" name="formsoc" autocomplete="off">';		// Chrome ignor autocomplete
1073
-
1074
-        print '<input type="hidden" name="action" value="add">';
1075
-        print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
1076
-        print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1077
-        print '<input type="hidden" name="private" value='.$object->particulier.'>';
1078
-        print '<input type="hidden" name="type" value='.GETPOST("type",'alpha').'>';
1079
-        print '<input type="hidden" name="LastName" value="'.$langs->trans('ThirdPartyName').' / '.$langs->trans('LastName').'">';
1080
-        print '<input type="hidden" name="ThirdPartyName" value="'.$langs->trans('ThirdPartyName').'">';
1081
-        if ($modCodeClient->code_auto || $modCodeFournisseur->code_auto) print '<input type="hidden" name="code_auto" value="1">';
1082
-
1083
-        dol_fiche_head(null, 'card', '', 0, '');
1084
-
1085
-        print '<table class="border" width="100%">';
1086
-
1087
-        // Name, firstname
1088
-	    print '<tr><td class="titlefieldcreate">';
1089
-        if ($object->particulier || $private)
1090
-        {
1091
-	        print '<span id="TypeName" class="fieldrequired">'.$langs->trans('ThirdPartyName').' / '.$langs->trans('LastName','name').'</span>';
1092
-        }
1093
-        else
1047
+			print '</script>'."\n";
1048
+
1049
+			print '<div id="selectthirdpartytype">';
1050
+			print '<div class="hideonsmartphone float">';
1051
+			print $langs->trans("ThirdPartyType").': &nbsp; &nbsp; ';
1052
+			print '</div>';
1053
+			print '<label for="radiocompany" class="radiocompany">';
1054
+			print '<input type="radio" id="radiocompany" class="flat" name="private"  value="0"'.($private?'':' checked').'>';
1055
+			print '&nbsp;';
1056
+			print $langs->trans("CreateThirdPartyOnly");
1057
+			print '</label>';
1058
+			print ' &nbsp; &nbsp; ';
1059
+			print '<label for="radioprivate" class="radioprivate">';
1060
+			$text ='<input type="radio" id="radioprivate" class="flat" name="private" value="1"'.($private?' checked':'').'>';
1061
+			$text.='&nbsp;';
1062
+			$text.= $langs->trans("CreateThirdPartyAndContact");
1063
+			$htmltext=$langs->trans("ToCreateContactWithSameName");
1064
+			print $form->textwithpicto($text, $htmltext, 1, 'help', '', 0, 3);
1065
+			print '</label>';
1066
+			print '</div>';
1067
+			print "<br>\n";
1068
+		}
1069
+
1070
+		dol_htmloutput_mesg(is_numeric($error)?'':$error, $errors, 'error');
1071
+
1072
+		print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'" method="post" name="formsoc" autocomplete="off">';		// Chrome ignor autocomplete
1073
+
1074
+		print '<input type="hidden" name="action" value="add">';
1075
+		print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
1076
+		print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1077
+		print '<input type="hidden" name="private" value='.$object->particulier.'>';
1078
+		print '<input type="hidden" name="type" value='.GETPOST("type",'alpha').'>';
1079
+		print '<input type="hidden" name="LastName" value="'.$langs->trans('ThirdPartyName').' / '.$langs->trans('LastName').'">';
1080
+		print '<input type="hidden" name="ThirdPartyName" value="'.$langs->trans('ThirdPartyName').'">';
1081
+		if ($modCodeClient->code_auto || $modCodeFournisseur->code_auto) print '<input type="hidden" name="code_auto" value="1">';
1082
+
1083
+		dol_fiche_head(null, 'card', '', 0, '');
1084
+
1085
+		print '<table class="border" width="100%">';
1086
+
1087
+		// Name, firstname
1088
+		print '<tr><td class="titlefieldcreate">';
1089
+		if ($object->particulier || $private)
1090
+		{
1091
+			print '<span id="TypeName" class="fieldrequired">'.$langs->trans('ThirdPartyName').' / '.$langs->trans('LastName','name').'</span>';
1092
+		}
1093
+		else
1094 1094
 		{
1095 1095
 			print '<span id="TypeName" class="fieldrequired">'.fieldLabel('ThirdPartyName','name').'</span>';
1096
-        }
1097
-	    print '</td><td'.(empty($conf->global->SOCIETE_USEPREFIX)?' colspan="3"':'').'>';
1098
-	    print '<input type="text" class="minwidth300" maxlength="128" name="name" id="name" value="'.$object->name.'" autofocus="autofocus"></td>';
1099
-	    if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
1100
-	    {
1101
-		    print '<td>'.$langs->trans('Prefix').'</td><td><input type="text" size="5" maxlength="5" name="prefix_comm" value="'.$object->prefix_comm.'"></td>';
1102
-	    }
1103
-	    print '</tr>';
1104
-
1105
-        // If javascript on, we show option individual
1106
-        if ($conf->use_javascript_ajax)
1107
-        {
1108
-            print '<tr class="individualline"><td>'.fieldLabel('FirstName','firstname').'</td>';
1109
-	        print '<td colspan="3"><input type="text" class="minwidth300" maxlength="128" name="firstname" id="firstname" value="'.$object->firstname.'"></td>';
1110
-            print '</tr>';
1111
-            // Title
1112
-            print '<tr class="individualline"><td>'.fieldLabel('UserTitle','civility_id').'</td><td colspan="3" class="maxwidthonsmartphone">';
1113
-            print $formcompany->select_civility($object->civility_id, 'civility_id', 'maxwidth100').'</td>';
1114
-            print '</tr>';
1115
-        }
1116
-
1117
-        // Alias names (commercial, trademark or alias names)
1118
-        print '<tr id="name_alias"><td><label for="name_alias_input">'.$langs->trans('AliasNames').'</label></td>';
1119
-	    print '<td colspan="3"><input type="text" class="minwidth300" name="name_alias" id="name_alias_input" value="'.$object->name_alias.'"></td></tr>';
1120
-
1121
-        // Prospect/Customer
1122
-        print '<tr><td class="titlefieldcreate">'.fieldLabel('ProspectCustomer','customerprospect',1).'</td>';
1123
-	    print '<td class="maxwidthonsmartphone">';
1124
-	    $selected=GETPOST('client','int')!=''?GETPOST('client','int'):$object->client;
1125
-        print '<select class="flat" name="client" id="customerprospect">';
1126
-        if (GETPOST("type") == '') print '<option value="-1">&nbsp;</option>';
1127
-        if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) print '<option value="2"'.($selected==2?' selected':'').'>'.$langs->trans('Prospect').'</option>';
1128
-        if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTSCUSTOMERS)) print '<option value="3"'.($selected==3?' selected':'').'>'.$langs->trans('ProspectCustomer').'</option>';
1129
-        if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print '<option value="1"'.($selected==1?' selected':'').'>'.$langs->trans('Customer').'</option>';
1130
-        print '<option value="0"'.((string) $selected == '0'?' selected':'').'>'.$langs->trans('NorProspectNorCustomer').'</option>';
1131
-        print '</select></td>';
1132
-
1133
-        print '<td>'.fieldLabel('CustomerCode','customer_code').'</td><td>';
1134
-        print '<table class="nobordernopadding"><tr><td>';
1135
-		$tmpcode=$object->code_client;
1136
-        if (empty($tmpcode) && ! empty($modCodeClient->code_auto)) $tmpcode=$modCodeClient->getNextValue($object,0);
1137
-        print '<input type="text" name="code_client" id="customer_code" class="maxwidthonsmartphone" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
1138
-        print '</td><td>';
1139
-        $s=$modCodeClient->getToolTip($langs,$object,0);
1140
-        print $form->textwithpicto('',$s,1);
1141
-        print '</td></tr></table>';
1142
-        print '</td></tr>';
1143
-
1144
-        if (! empty($conf->fournisseur->enabled) && ! empty($user->rights->fournisseur->lire))
1145
-        {
1146
-            // Supplier
1147
-            print '<tr>';
1148
-            print '<td>'.fieldLabel('Supplier','fournisseur',1).'</td><td>';
1149
-            $default = -1;
1150
-            if (! empty($conf->global->THIRDPARTY_SUPPLIER_BY_DEFAULT)) $default=1;
1151
-            print $form->selectyesno("fournisseur", (GETPOST('fournisseur','int')!=''?GETPOST('fournisseur','int'):(GETPOST("type",'alpha') == '' ? $default : $object->fournisseur)), 1, 0, (GETPOST("type",'alpha') == '' ? 1 : 0));
1152
-            print '</td>';
1153
-            print '<td>'.fieldLabel('SupplierCode','supplier_code').'</td><td>';
1154
-            print '<table class="nobordernopadding"><tr><td>';
1155
-            $tmpcode=$object->code_fournisseur;
1156
-            if (empty($tmpcode) && ! empty($modCodeFournisseur->code_auto)) $tmpcode=$modCodeFournisseur->getNextValue($object,1);
1157
-            print '<input type="text" name="code_fournisseur" id="supplier_code" class="maxwidthonsmartphone" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
1158
-            print '</td><td>';
1159
-            $s=$modCodeFournisseur->getToolTip($langs,$object,1);
1160
-            print $form->textwithpicto('',$s,1);
1161
-            print '</td></tr></table>';
1162
-            print '</td></tr>';
1163
-        }
1164
-
1165
-        // Status
1166
-        print '<tr><td>'.fieldLabel('Status','status').'</td><td colspan="3">';
1167
-        print $form->selectarray('status', array('0'=>$langs->trans('ActivityCeased'),'1'=>$langs->trans('InActivity')),1);
1168
-        print '</td></tr>';
1169
-
1170
-        // Barcode
1171
-        if (! empty($conf->barcode->enabled))
1172
-        {
1173
-            print '<tr><td>'.fieldLabel('Gencod','barcode').'</td>';
1174
-	        print '<td colspan="3"><input type="text" name="barcode" id="barcode" value="'.$object->barcode.'">';
1175
-            print '</td></tr>';
1176
-        }
1177
-
1178
-        // Address
1179
-        print '<tr><td class="tdtop">'.fieldLabel('Address','address').'</td>';
1180
-	    print '<td colspan="3"><textarea name="address" id="address" class="quatrevingtpercent" rows="'._ROWS_2.'" wrap="soft">';
1181
-        print $object->address;
1182
-        print '</textarea></td></tr>';
1183
-
1184
-        // Zip / Town
1185
-        print '<tr><td>'.fieldLabel('Zip','zipcode').'</td><td>';
1186
-        print $formcompany->select_ziptown($object->zip,'zipcode',array('town','selectcountry_id','state_id'), 0, 0, '', 'maxwidth100 quatrevingtpercent');
1187
-        print '</td><td>'.fieldLabel('Town','town').'</td><td>';
1188
-        print $formcompany->select_ziptown($object->town,'town',array('zipcode','selectcountry_id','state_id'), 0, 0, '', 'maxwidth100 quatrevingtpercent');
1189
-        print '</td></tr>';
1190
-
1191
-        // Country
1192
-        print '<tr><td>'.fieldLabel('Country','selectcountry_id').'</td><td colspan="3" class="maxwidthonsmartphone">';
1193
-        print $form->select_country((GETPOST('country_id')!=''?GETPOST('country_id'):$object->country_id));
1194
-        if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1195
-        print '</td></tr>';
1196
-
1197
-        // State
1198
-        if (empty($conf->global->SOCIETE_DISABLE_STATE))
1199
-        {
1200
-            if(!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && ($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 || $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 2))
1201
-            {
1202
-                print '<tr><td>'.fieldLabel('Region-State','state_id').'</td><td colspan="3" class="maxwidthonsmartphone">';
1203
-            }
1204
-            else
1205
-            {
1206
-                print '<tr><td>'.fieldLabel('State','state_id').'</td><td colspan="3" class="maxwidthonsmartphone">';
1207
-            }
1208
-
1209
-            if ($object->country_id) print $formcompany->select_state($object->state_id,$object->country_code);
1210
-            else print $countrynotdefined;
1211
-            print '</td></tr>';
1212
-        }
1213
-
1214
-        // Email web
1215
-        print '<tr><td>'.fieldLabel('EMail','email',$conf->global->SOCIETE_EMAIL_MANDATORY).'</td>';
1216
-	    print '<td colspan="3"><input type="text" name="email" id="email" value="'.$object->email.'"></td></tr>';
1217
-        print '<tr><td>'.fieldLabel('Web','url').'</td>';
1218
-	    print '<td colspan="3"><input type="text" name="url" id="url" value="'.$object->url.'"></td></tr>';
1219
-
1220
-        // Skype
1221
-        if (! empty($conf->skype->enabled))
1222
-        {
1223
-            print '<tr><td>'.fieldLabel('Skype','skype').'</td>';
1224
-	        print '<td colspan="3"><input type="text" name="skype" id="skype" value="'.$object->skype.'"></td></tr>';
1225
-        }
1226
-
1227
-        // Phone / Fax
1228
-        print '<tr><td>'.fieldLabel('Phone','phone').'</td>';
1229
-	    print '<td><input type="text" name="phone" id="phone" class="maxwidth100onsmartphone quatrevingtpercent" value="'.$object->phone.'"></td>';
1230
-        print '<td>'.fieldLabel('Fax','fax').'</td>';
1231
-	    print '<td><input type="text" name="fax" id="fax" class="maxwidth100onsmartphone quatrevingtpercent" value="'.$object->fax.'"></td></tr>';
1232
-
1233
-        // Prof ids
1234
-        $i=1; $j=0;
1235
-        while ($i <= 6)
1236
-        {
1237
-            $idprof=$langs->transcountry('ProfId'.$i,$object->country_code);
1238
-            if ($idprof!='-')
1239
-            {
1240
-	            $key='idprof'.$i;
1241
-
1242
-                if (($j % 2) == 0) print '<tr>';
1243
-
1244
-                $idprof_mandatory ='SOCIETE_IDPROF'.($i).'_MANDATORY';
1245
-                print '<td>'.fieldLabel($idprof,$key, (empty($conf->global->$idprof_mandatory)?0:1)).'</td><td>';
1246
-
1247
-                print $formcompany->get_input_id_prof($i, $key, $object->$key, $object->country_code);
1248
-                print '</td>';
1249
-                if (($j % 2) == 1) print '</tr>';
1250
-                $j++;
1251
-            }
1252
-            $i++;
1253
-        }
1254
-        if ($j % 2 == 1) print '<td colspan="2"></td></tr>';
1255
-
1256
-        // Vat is used
1257
-        print '<tr><td>'.fieldLabel('VATIsUsed','assujtva_value').'</td>';
1258
-        print '<td>';
1259
-        print $form->selectyesno('assujtva_value',(isset($conf->global->THIRDPARTY_DEFAULT_USEVAT)?$conf->global->THIRDPARTY_DEFAULT_USEVAT:1),1);     // Assujeti par defaut en creation
1260
-        print '</td>';
1261
-        print '<td class="nowrap">'.fieldLabel('VATIntra','intra_vat').'</td>';
1262
-        print '<td class="nowrap">';
1263
-        $s = '<input type="text" class="flat maxwidthonsmartphone" name="tva_intra" id="intra_vat" maxlength="20" value="'.$object->tva_intra.'">';
1264
-
1265
-        if (empty($conf->global->MAIN_DISABLEVATCHECK) && isInEEC($object))
1266
-        {
1267
-            $s.=' ';
1268
-
1269
-            if (! empty($conf->use_javascript_ajax))
1270
-            {
1271
-                print "\n";
1272
-                print '<script language="JavaScript" type="text/javascript">';
1273
-                print "function CheckVAT(a) {\n";
1274
-                print "newpopup('".DOL_URL_ROOT."/societe/checkvat/checkVatPopup.php?vatNumber='+a,'".dol_escape_js($langs->trans("VATIntraCheckableOnEUSite"))."',500,300);\n";
1275
-                print "}\n";
1276
-                print '</script>';
1277
-                print "\n";
1278
-                $s.='<a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT(document.formsoc.tva_intra.value);">'.$langs->trans("VATIntraCheck").'</a>';
1279
-                $s = $form->textwithpicto($s,$langs->trans("VATIntraCheckDesc",$langs->trans("VATIntraCheck")),1);
1280
-            }
1281
-            else
1282
-            {
1283
-                $s.='<a href="'.$langs->transcountry("VATIntraCheckURL",$object->country_id).'" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"),'help').'</a>';
1284
-            }
1285
-        }
1286
-        print $s;
1287
-        print '</td>';
1288
-        print '</tr>';
1289
-
1290
-        // Local Taxes
1291
-        //TODO: Place into a function to control showing by country or study better option
1292
-        if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1")
1293
-        {
1294
-            print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed",$mysoc->country_code).'</td><td>';
1295
-            print $form->selectyesno('localtax1assuj_value',(isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1)?$conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1:0),1);
1296
-            print '</td><td>'.$langs->transcountry("LocalTax2IsUsed",$mysoc->country_code).'</td><td>';
1297
-            print $form->selectyesno('localtax2assuj_value',(isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2)?$conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2:0),1);
1298
-            print '</td></tr>';
1299
-
1300
-        }
1301
-        elseif($mysoc->localtax1_assuj=="1")
1302
-        {
1303
-            print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed",$mysoc->country_code).'</td><td colspan="3">';
1304
-            print $form->selectyesno('localtax1assuj_value',(isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1)?$conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1:0),1);
1305
-            print '</td></tr>';
1306
-        }
1307
-        elseif($mysoc->localtax2_assuj=="1")
1308
-        {
1309
-            print '<tr><td>'.$langs->transcountry("LocalTax2IsUsed",$mysoc->country_code).'</td><td colspan="3">';
1310
-            print $form->selectyesno('localtax2assuj_value',(isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2)?$conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2:0),1);
1311
-            print '</td></tr>';
1312
-        }
1313
-
1314
-        // Type - Size
1315
-        print '<tr><td>'.fieldLabel('ThirdPartyType','typent_id').'</td><td class="maxwidthonsmartphone">'."\n";
1316
-        $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.
1317
-        print $form->selectarray("typent_id", $formcompany->typent_array(0), $object->typent_id, 0, 0, 0, '', 0, 0, 0, $sortparam);
1318
-        if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1319
-        print '</td>';
1320
-        print '<td>'.fieldLabel('Staff','effectif_id').'</td><td class="maxwidthonsmartphone">';
1321
-        print $form->selectarray("effectif_id", $formcompany->effectif_array(0), $object->effectif_id);
1322
-        if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1323
-        print '</td></tr>';
1324
-
1325
-        // Legal Form
1326
-        print '<tr><td>'.fieldLabel('JuridicalStatus','forme_juridique_code').'</td>';
1327
-        print '<td colspan="3" class="maxwidthonsmartphone">';
1328
-        if ($object->country_id)
1329
-        {
1330
-            print $formcompany->select_juridicalstatus($object->forme_juridique_code, $object->country_code, '', 'forme_juridique_code');
1331
-        }
1332
-        else
1333
-        {
1334
-            print $countrynotdefined;
1335
-        }
1336
-        print '</td></tr>';
1337
-
1338
-        // Capital
1339
-        print '<tr><td>'.fieldLabel('Capital','capital').'</td>';
1340
-	    print '<td colspan="3"><input type="text" name="capital" id="capital" size="10" value="'.$object->capital.'"> ';
1341
-        print '<span class="hideonsmartphone">'.$langs->trans("Currency".$conf->currency).'</span></td></tr>';
1342
-
1343
-        if (! empty($conf->global->MAIN_MULTILANGS))
1344
-        {
1345
-            print '<tr><td>'.fieldLabel('DefaultLang','default_lang').'</td><td colspan="3" class="maxwidthonsmartphone">'."\n";
1346
-            print $formadmin->select_language(($object->default_lang?$object->default_lang:$conf->global->MAIN_LANG_DEFAULT),'default_lang',0,0,1,0,0,'maxwidth200onsmartphone');
1347
-            print '</td>';
1348
-            print '</tr>';
1349
-        }
1350
-
1351
-        if ($user->rights->societe->client->voir)
1352
-        {
1353
-            // Assign a Name
1354
-            print '<tr>';
1355
-            print '<td>'.fieldLabel('AllocateCommercial','commercial_id').'</td>';
1356
-            print '<td colspan="3" class="maxwidthonsmartphone">';
1357
-            print $form->select_dolusers((! empty($object->commercial_id)?$object->commercial_id:$user->id),'commercial_id',1); // Add current user by default
1358
-            print '</td></tr>';
1359
-        }
1096
+		}
1097
+		print '</td><td'.(empty($conf->global->SOCIETE_USEPREFIX)?' colspan="3"':'').'>';
1098
+		print '<input type="text" class="minwidth300" maxlength="128" name="name" id="name" value="'.$object->name.'" autofocus="autofocus"></td>';
1099
+		if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
1100
+		{
1101
+			print '<td>'.$langs->trans('Prefix').'</td><td><input type="text" size="5" maxlength="5" name="prefix_comm" value="'.$object->prefix_comm.'"></td>';
1102
+		}
1103
+		print '</tr>';
1360 1104
 
1361
-		// Incoterms
1362
-		if (!empty($conf->incoterm->enabled))
1105
+		// If javascript on, we show option individual
1106
+		if ($conf->use_javascript_ajax)
1107
+		{
1108
+			print '<tr class="individualline"><td>'.fieldLabel('FirstName','firstname').'</td>';
1109
+			print '<td colspan="3"><input type="text" class="minwidth300" maxlength="128" name="firstname" id="firstname" value="'.$object->firstname.'"></td>';
1110
+			print '</tr>';
1111
+			// Title
1112
+			print '<tr class="individualline"><td>'.fieldLabel('UserTitle','civility_id').'</td><td colspan="3" class="maxwidthonsmartphone">';
1113
+			print $formcompany->select_civility($object->civility_id, 'civility_id', 'maxwidth100').'</td>';
1114
+			print '</tr>';
1115
+		}
1116
+
1117
+		// Alias names (commercial, trademark or alias names)
1118
+		print '<tr id="name_alias"><td><label for="name_alias_input">'.$langs->trans('AliasNames').'</label></td>';
1119
+		print '<td colspan="3"><input type="text" class="minwidth300" name="name_alias" id="name_alias_input" value="'.$object->name_alias.'"></td></tr>';
1120
+
1121
+		// Prospect/Customer
1122
+		print '<tr><td class="titlefieldcreate">'.fieldLabel('ProspectCustomer','customerprospect',1).'</td>';
1123
+		print '<td class="maxwidthonsmartphone">';
1124
+		$selected=GETPOST('client','int')!=''?GETPOST('client','int'):$object->client;
1125
+		print '<select class="flat" name="client" id="customerprospect">';
1126
+		if (GETPOST("type") == '') print '<option value="-1">&nbsp;</option>';
1127
+		if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) print '<option value="2"'.($selected==2?' selected':'').'>'.$langs->trans('Prospect').'</option>';
1128
+		if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTSCUSTOMERS)) print '<option value="3"'.($selected==3?' selected':'').'>'.$langs->trans('ProspectCustomer').'</option>';
1129
+		if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print '<option value="1"'.($selected==1?' selected':'').'>'.$langs->trans('Customer').'</option>';
1130
+		print '<option value="0"'.((string) $selected == '0'?' selected':'').'>'.$langs->trans('NorProspectNorCustomer').'</option>';
1131
+		print '</select></td>';
1132
+
1133
+		print '<td>'.fieldLabel('CustomerCode','customer_code').'</td><td>';
1134
+		print '<table class="nobordernopadding"><tr><td>';
1135
+		$tmpcode=$object->code_client;
1136
+		if (empty($tmpcode) && ! empty($modCodeClient->code_auto)) $tmpcode=$modCodeClient->getNextValue($object,0);
1137
+		print '<input type="text" name="code_client" id="customer_code" class="maxwidthonsmartphone" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
1138
+		print '</td><td>';
1139
+		$s=$modCodeClient->getToolTip($langs,$object,0);
1140
+		print $form->textwithpicto('',$s,1);
1141
+		print '</td></tr></table>';
1142
+		print '</td></tr>';
1143
+
1144
+		if (! empty($conf->fournisseur->enabled) && ! empty($user->rights->fournisseur->lire))
1363 1145
 		{
1146
+			// Supplier
1364 1147
 			print '<tr>';
1365
-			print '<td>'.fieldLabel('IncotermLabel','incoterm_id').'</td>';
1366
-	        print '<td colspan="3" class="maxwidthonsmartphone">';
1367
-	        print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''));
1148
+			print '<td>'.fieldLabel('Supplier','fournisseur',1).'</td><td>';
1149
+			$default = -1;
1150
+			if (! empty($conf->global->THIRDPARTY_SUPPLIER_BY_DEFAULT)) $default=1;
1151
+			print $form->selectyesno("fournisseur", (GETPOST('fournisseur','int')!=''?GETPOST('fournisseur','int'):(GETPOST("type",'alpha') == '' ? $default : $object->fournisseur)), 1, 0, (GETPOST("type",'alpha') == '' ? 1 : 0));
1152
+			print '</td>';
1153
+			print '<td>'.fieldLabel('SupplierCode','supplier_code').'</td><td>';
1154
+			print '<table class="nobordernopadding"><tr><td>';
1155
+			$tmpcode=$object->code_fournisseur;
1156
+			if (empty($tmpcode) && ! empty($modCodeFournisseur->code_auto)) $tmpcode=$modCodeFournisseur->getNextValue($object,1);
1157
+			print '<input type="text" name="code_fournisseur" id="supplier_code" class="maxwidthonsmartphone" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
1158
+			print '</td><td>';
1159
+			$s=$modCodeFournisseur->getToolTip($langs,$object,1);
1160
+			print $form->textwithpicto('',$s,1);
1161
+			print '</td></tr></table>';
1368 1162
 			print '</td></tr>';
1369 1163
 		}
1370 1164
 
1371
-		// Categories
1372
-		if (! empty($conf->categorie->enabled)  && ! empty($user->rights->categorie->lire))
1165
+		// Status
1166
+		print '<tr><td>'.fieldLabel('Status','status').'</td><td colspan="3">';
1167
+		print $form->selectarray('status', array('0'=>$langs->trans('ActivityCeased'),'1'=>$langs->trans('InActivity')),1);
1168
+		print '</td></tr>';
1169
+
1170
+		// Barcode
1171
+		if (! empty($conf->barcode->enabled))
1373 1172
 		{
1374
-			$langs->load('categories');
1173
+			print '<tr><td>'.fieldLabel('Gencod','barcode').'</td>';
1174
+			print '<td colspan="3"><input type="text" name="barcode" id="barcode" value="'.$object->barcode.'">';
1175
+			print '</td></tr>';
1176
+		}
1375 1177
 
1376
-			// Customer
1377
-			if ($object->prospect || $object->client) {
1378
-				print '<tr><td class="toptd">' . fieldLabel('CustomersCategoriesShort', 'custcats') . '</td><td colspan="3">';
1379
-				$cate_arbo = $form->select_all_categories(Categorie::TYPE_CUSTOMER, null, 'parent', null, null, 1);
1380
-				print $form->multiselectarray('custcats', $cate_arbo, GETPOST('custcats', 'array'), null, null, null,
1381
-					null, "90%");
1382
-				print "</td></tr>";
1178
+		// Address
1179
+		print '<tr><td class="tdtop">'.fieldLabel('Address','address').'</td>';
1180
+		print '<td colspan="3"><textarea name="address" id="address" class="quatrevingtpercent" rows="'._ROWS_2.'" wrap="soft">';
1181
+		print $object->address;
1182
+		print '</textarea></td></tr>';
1183
+
1184
+		// Zip / Town
1185
+		print '<tr><td>'.fieldLabel('Zip','zipcode').'</td><td>';
1186
+		print $formcompany->select_ziptown($object->zip,'zipcode',array('town','selectcountry_id','state_id'), 0, 0, '', 'maxwidth100 quatrevingtpercent');
1187
+		print '</td><td>'.fieldLabel('Town','town').'</td><td>';
1188
+		print $formcompany->select_ziptown($object->town,'town',array('zipcode','selectcountry_id','state_id'), 0, 0, '', 'maxwidth100 quatrevingtpercent');
1189
+		print '</td></tr>';
1190
+
1191
+		// Country
1192
+		print '<tr><td>'.fieldLabel('Country','selectcountry_id').'</td><td colspan="3" class="maxwidthonsmartphone">';
1193
+		print $form->select_country((GETPOST('country_id')!=''?GETPOST('country_id'):$object->country_id));
1194
+		if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1195
+		print '</td></tr>';
1196
+
1197
+		// State
1198
+		if (empty($conf->global->SOCIETE_DISABLE_STATE))
1199
+		{
1200
+			if(!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && ($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 || $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 2))
1201
+			{
1202
+				print '<tr><td>'.fieldLabel('Region-State','state_id').'</td><td colspan="3" class="maxwidthonsmartphone">';
1383 1203
 			}
1384
-
1385
-			// Supplier
1386
-			if ($object->fournisseur) {
1387
-				print '<tr><td class="toptd">' . fieldLabel('SuppliersCategoriesShort', 'suppcats') . '</td><td colspan="3">';
1388
-				$cate_arbo = $form->select_all_categories(Categorie::TYPE_SUPPLIER, null, 'parent', null, null, 1);
1389
-				print $form->multiselectarray('suppcats', $cate_arbo, GETPOST('suppcats', 'array'), null, null, null,
1390
-					null, "90%");
1391
-				print "</td></tr>";
1204
+			else
1205
+			{
1206
+				print '<tr><td>'.fieldLabel('State','state_id').'</td><td colspan="3" class="maxwidthonsmartphone">';
1392 1207
 			}
1393
-		}
1394 1208
 
1395
-		// Multicurrency
1396
-		if (! empty($conf->multicurrency->enabled))
1397
-		{
1398
-			print '<tr>';
1399
-			print '<td>'.fieldLabel('Currency','multicurrency_code').'</td>';
1400
-	        print '<td colspan="3" class="maxwidthonsmartphone">';
1401
-	        print $form->selectMultiCurrency(($object->multicurrency_code ? $object->multicurrency_code : $conf->currency), 'multicurrency_code', 1);
1209
+			if ($object->country_id) print $formcompany->select_state($object->state_id,$object->country_code);
1210
+			else print $countrynotdefined;
1402 1211
 			print '</td></tr>';
1403 1212
 		}
1404 1213
 
1405
-        // Other attributes
1406
-        $parameters=array('colspan' => ' colspan="3"', 'colspanvalue' => '3');
1407
-        $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
1408
-        print $hookmanager->resPrint;
1409
-        if (empty($reshook) && ! empty($extrafields->attribute_label))
1410
-        {
1411
-        	print $object->showOptionals($extrafields,'edit');
1412
-        }
1413
-
1414
-        // Ajout du logo
1415
-        print '<tr class="hideonsmartphone">';
1416
-        print '<td>'.fieldLabel('Logo','photoinput').'</td>';
1417
-        print '<td colspan="3">';
1418
-        print '<input class="flat" type="file" name="photo" id="photoinput" />';
1419
-        print '</td>';
1420
-        print '</tr>';
1421
-
1422
-        print '</table>'."\n";
1423
-
1424
-        dol_fiche_end();
1425
-
1426
-        print '<div class="center">';
1427
-        print '<input type="submit" class="button" name="create" value="'.$langs->trans('AddThirdParty').'">';
1428
-        if (! empty($backtopage))
1429
-        {
1430
-            print ' &nbsp; &nbsp; ';
1431
-            print '<input type="submit" class="button" name="cancel" value="'.$langs->trans('Cancel').'">';
1432
-        }
1433
-        else
1434
-        {
1435
-            print ' &nbsp; &nbsp; ';
1436
-            print '<input type="button" class="button" value="' . $langs->trans("Cancel") . '" onClick="javascript:history.go(-1)">';
1437
-        }
1438
-        print '</div>'."\n";
1439
-
1440
-        print '</form>'."\n";
1441
-    }
1442
-    elseif ($action == 'edit')
1443
-    {
1444
-        /*
1445
-         * Edition
1446
-         */
1214
+		// Email web
1215
+		print '<tr><td>'.fieldLabel('EMail','email',$conf->global->SOCIETE_EMAIL_MANDATORY).'</td>';
1216
+		print '<td colspan="3"><input type="text" name="email" id="email" value="'.$object->email.'"></td></tr>';
1217
+		print '<tr><td>'.fieldLabel('Web','url').'</td>';
1218
+		print '<td colspan="3"><input type="text" name="url" id="url" value="'.$object->url.'"></td></tr>';
1447 1219
 
1220
+		// Skype
1221
+		if (! empty($conf->skype->enabled))
1222
+		{
1223
+			print '<tr><td>'.fieldLabel('Skype','skype').'</td>';
1224
+			print '<td colspan="3"><input type="text" name="skype" id="skype" value="'.$object->skype.'"></td></tr>';
1225
+		}
1448 1226
 
1449
-        //print load_fiche_titre($langs->trans("EditCompany"));
1450
-
1451
-        if ($socid)
1452
-        {
1453
-        	$res=$object->fetch_optionals();
1454
-            //if ($res < 0) { dol_print_error($db); exit; }
1455
-
1456
-	        $head = societe_prepare_head($object);
1457
-
1458
-            // Load object modCodeTiers
1459
-            $module=(! empty($conf->global->SOCIETE_CODECLIENT_ADDON)?$conf->global->SOCIETE_CODECLIENT_ADDON:'mod_codeclient_leopard');
1460
-            if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php')
1461
-            {
1462
-                $module = substr($module, 0, dol_strlen($module)-4);
1463
-            }
1464
-            $dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
1465
-            foreach ($dirsociete as $dirroot)
1466
-            {
1467
-                $res=dol_include_once($dirroot.$module.'.php');
1468
-                if ($res) break;
1469
-            }
1470
-            $modCodeClient = new $module($db);
1471
-            // We verified if the tag prefix is used
1472
-            if ($modCodeClient->code_auto)
1473
-            {
1474
-                $prefixCustomerIsUsed = $modCodeClient->verif_prefixIsUsed();
1475
-            }
1476
-            $module=$conf->global->SOCIETE_CODECLIENT_ADDON;
1477
-            if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php')
1478
-            {
1479
-                $module = substr($module, 0, dol_strlen($module)-4);
1480
-            }
1481
-            $dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
1482
-            foreach ($dirsociete as $dirroot)
1483
-            {
1484
-                $res=dol_include_once($dirroot.$module.'.php');
1485
-                if ($res) break;
1486
-            }
1487
-            $modCodeFournisseur = new $module($db);
1488
-            // On verifie si la balise prefix est utilisee
1489
-            if ($modCodeFournisseur->code_auto)
1490
-            {
1491
-                $prefixSupplierIsUsed = $modCodeFournisseur->verif_prefixIsUsed();
1492
-            }
1227
+		// Phone / Fax
1228
+		print '<tr><td>'.fieldLabel('Phone','phone').'</td>';
1229
+		print '<td><input type="text" name="phone" id="phone" class="maxwidth100onsmartphone quatrevingtpercent" value="'.$object->phone.'"></td>';
1230
+		print '<td>'.fieldLabel('Fax','fax').'</td>';
1231
+		print '<td><input type="text" name="fax" id="fax" class="maxwidth100onsmartphone quatrevingtpercent" value="'.$object->fax.'"></td></tr>';
1493 1232
 
1494
-			$object->oldcopy = clone $object;
1233
+		// Prof ids
1234
+		$i=1; $j=0;
1235
+		while ($i <= 6)
1236
+		{
1237
+			$idprof=$langs->transcountry('ProfId'.$i,$object->country_code);
1238
+			if ($idprof!='-')
1239
+			{
1240
+				$key='idprof'.$i;
1495 1241
 
1496
-            if (GETPOSTISSET('name'))
1497
-            {
1498
-                // We overwrite with values if posted
1499
-                $object->name					= GETPOST('name', 'alpha');
1500
-                $object->prefix_comm			= GETPOST('prefix_comm', 'alpha');
1501
-                $object->client					= GETPOST('client', 'int');
1502
-                $object->code_client			= GETPOST('code_client', 'alpha');
1503
-                $object->fournisseur			= GETPOST('fournisseur', 'int');
1504
-                $object->code_fournisseur		= GETPOST('code_fournisseur', 'alpha');
1505
-                $object->address				= GETPOST('address', 'alpha');
1506
-                $object->zip					= GETPOST('zipcode', 'alpha');
1507
-                $object->town					= GETPOST('town', 'alpha');
1508
-                $object->country_id				= GETPOST('country_id')?GETPOST('country_id', 'int'):$mysoc->country_id;
1509
-                $object->state_id				= GETPOST('state_id', 'int');
1510
-                $object->skype					= GETPOST('skype', 'alpha');
1511
-                $object->phone					= GETPOST('phone', 'alpha');
1512
-                $object->fax					= GETPOST('fax', 'alpha');
1513
-                $object->email					= GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL);
1514
-                $object->url					= GETPOST('url', 'custom', 0, FILTER_SANITIZE_URL);
1515
-                $object->capital				= GETPOST('capital', 'alpha');
1516
-                $object->idprof1				= GETPOST('idprof1', 'alpha');
1517
-                $object->idprof2				= GETPOST('idprof2', 'alpha');
1518
-                $object->idprof3				= GETPOST('idprof3', 'alpha');
1519
-                $object->idprof4				= GETPOST('idprof4', 'alpha');
1520
-                $object->idprof5				= GETPOST('idprof5', 'alpha');
1521
-                $object->idprof6				= GETPOST('idprof6', 'alpha');
1522
-                $object->typent_id				= GETPOST('typent_id', 'int');
1523
-                $object->effectif_id			= GETPOST('effectif_id', 'int');
1524
-                $object->barcode				= GETPOST('barcode', 'alpha');
1525
-                $object->forme_juridique_code	= GETPOST('forme_juridique_code', 'int');
1526
-                $object->default_lang			= GETPOST('default_lang', 'alpha');
1527
-
1528
-                $object->tva_assuj				= GETPOST('assujtva_value', 'int');
1529
-                $object->tva_intra				= GETPOST('tva_intra', 'alpha');
1530
-                $object->status					= GETPOST('status', 'int');
1531
-
1532
-                // Webservices url/key
1533
-                $object->webservices_url        = GETPOST('webservices_url', 'custom', 0, FILTER_SANITIZE_URL);
1534
-                $object->webservices_key        = GETPOST('webservices_key', 'san_alpha');
1242
+				if (($j % 2) == 0) print '<tr>';
1243
+
1244
+				$idprof_mandatory ='SOCIETE_IDPROF'.($i).'_MANDATORY';
1245
+				print '<td>'.fieldLabel($idprof,$key, (empty($conf->global->$idprof_mandatory)?0:1)).'</td><td>';
1246
+
1247
+				print $formcompany->get_input_id_prof($i, $key, $object->$key, $object->country_code);
1248
+				print '</td>';
1249
+				if (($j % 2) == 1) print '</tr>';
1250
+				$j++;
1251
+			}
1252
+			$i++;
1253
+		}
1254
+		if ($j % 2 == 1) print '<td colspan="2"></td></tr>';
1255
+
1256
+		// Vat is used
1257
+		print '<tr><td>'.fieldLabel('VATIsUsed','assujtva_value').'</td>';
1258
+		print '<td>';
1259
+		print $form->selectyesno('assujtva_value',(isset($conf->global->THIRDPARTY_DEFAULT_USEVAT)?$conf->global->THIRDPARTY_DEFAULT_USEVAT:1),1);     // Assujeti par defaut en creation
1260
+		print '</td>';
1261
+		print '<td class="nowrap">'.fieldLabel('VATIntra','intra_vat').'</td>';
1262
+		print '<td class="nowrap">';
1263
+		$s = '<input type="text" class="flat maxwidthonsmartphone" name="tva_intra" id="intra_vat" maxlength="20" value="'.$object->tva_intra.'">';
1264
+
1265
+		if (empty($conf->global->MAIN_DISABLEVATCHECK) && isInEEC($object))
1266
+		{
1267
+			$s.=' ';
1268
+
1269
+			if (! empty($conf->use_javascript_ajax))
1270
+			{
1271
+				print "\n";
1272
+				print '<script language="JavaScript" type="text/javascript">';
1273
+				print "function CheckVAT(a) {\n";
1274
+				print "newpopup('".DOL_URL_ROOT."/societe/checkvat/checkVatPopup.php?vatNumber='+a,'".dol_escape_js($langs->trans("VATIntraCheckableOnEUSite"))."',500,300);\n";
1275
+				print "}\n";
1276
+				print '</script>';
1277
+				print "\n";
1278
+				$s.='<a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT(document.formsoc.tva_intra.value);">'.$langs->trans("VATIntraCheck").'</a>';
1279
+				$s = $form->textwithpicto($s,$langs->trans("VATIntraCheckDesc",$langs->trans("VATIntraCheck")),1);
1280
+			}
1281
+			else
1282
+			{
1283
+				$s.='<a href="'.$langs->transcountry("VATIntraCheckURL",$object->country_id).'" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"),'help').'</a>';
1284
+			}
1285
+		}
1286
+		print $s;
1287
+		print '</td>';
1288
+		print '</tr>';
1289
+
1290
+		// Local Taxes
1291
+		//TODO: Place into a function to control showing by country or study better option
1292
+		if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1")
1293
+		{
1294
+			print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed",$mysoc->country_code).'</td><td>';
1295
+			print $form->selectyesno('localtax1assuj_value',(isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1)?$conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1:0),1);
1296
+			print '</td><td>'.$langs->transcountry("LocalTax2IsUsed",$mysoc->country_code).'</td><td>';
1297
+			print $form->selectyesno('localtax2assuj_value',(isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2)?$conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2:0),1);
1298
+			print '</td></tr>';
1299
+
1300
+		}
1301
+		elseif($mysoc->localtax1_assuj=="1")
1302
+		{
1303
+			print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed",$mysoc->country_code).'</td><td colspan="3">';
1304
+			print $form->selectyesno('localtax1assuj_value',(isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1)?$conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1:0),1);
1305
+			print '</td></tr>';
1306
+		}
1307
+		elseif($mysoc->localtax2_assuj=="1")
1308
+		{
1309
+			print '<tr><td>'.$langs->transcountry("LocalTax2IsUsed",$mysoc->country_code).'</td><td colspan="3">';
1310
+			print $form->selectyesno('localtax2assuj_value',(isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2)?$conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2:0),1);
1311
+			print '</td></tr>';
1312
+		}
1313
+
1314
+		// Type - Size
1315
+		print '<tr><td>'.fieldLabel('ThirdPartyType','typent_id').'</td><td class="maxwidthonsmartphone">'."\n";
1316
+		$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.
1317
+		print $form->selectarray("typent_id", $formcompany->typent_array(0), $object->typent_id, 0, 0, 0, '', 0, 0, 0, $sortparam);
1318
+		if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1319
+		print '</td>';
1320
+		print '<td>'.fieldLabel('Staff','effectif_id').'</td><td class="maxwidthonsmartphone">';
1321
+		print $form->selectarray("effectif_id", $formcompany->effectif_array(0), $object->effectif_id);
1322
+		if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1323
+		print '</td></tr>';
1324
+
1325
+		// Legal Form
1326
+		print '<tr><td>'.fieldLabel('JuridicalStatus','forme_juridique_code').'</td>';
1327
+		print '<td colspan="3" class="maxwidthonsmartphone">';
1328
+		if ($object->country_id)
1329
+		{
1330
+			print $formcompany->select_juridicalstatus($object->forme_juridique_code, $object->country_code, '', 'forme_juridique_code');
1331
+		}
1332
+		else
1333
+		{
1334
+			print $countrynotdefined;
1335
+		}
1336
+		print '</td></tr>';
1337
+
1338
+		// Capital
1339
+		print '<tr><td>'.fieldLabel('Capital','capital').'</td>';
1340
+		print '<td colspan="3"><input type="text" name="capital" id="capital" size="10" value="'.$object->capital.'"> ';
1341
+		print '<span class="hideonsmartphone">'.$langs->trans("Currency".$conf->currency).'</span></td></tr>';
1342
+
1343
+		if (! empty($conf->global->MAIN_MULTILANGS))
1344
+		{
1345
+			print '<tr><td>'.fieldLabel('DefaultLang','default_lang').'</td><td colspan="3" class="maxwidthonsmartphone">'."\n";
1346
+			print $formadmin->select_language(($object->default_lang?$object->default_lang:$conf->global->MAIN_LANG_DEFAULT),'default_lang',0,0,1,0,0,'maxwidth200onsmartphone');
1347
+			print '</td>';
1348
+			print '</tr>';
1349
+		}
1350
+
1351
+		if ($user->rights->societe->client->voir)
1352
+		{
1353
+			// Assign a Name
1354
+			print '<tr>';
1355
+			print '<td>'.fieldLabel('AllocateCommercial','commercial_id').'</td>';
1356
+			print '<td colspan="3" class="maxwidthonsmartphone">';
1357
+			print $form->select_dolusers((! empty($object->commercial_id)?$object->commercial_id:$user->id),'commercial_id',1); // Add current user by default
1358
+			print '</td></tr>';
1359
+		}
1360
+
1361
+		// Incoterms
1362
+		if (!empty($conf->incoterm->enabled))
1363
+		{
1364
+			print '<tr>';
1365
+			print '<td>'.fieldLabel('IncotermLabel','incoterm_id').'</td>';
1366
+			print '<td colspan="3" class="maxwidthonsmartphone">';
1367
+			print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''));
1368
+			print '</td></tr>';
1369
+		}
1370
+
1371
+		// Categories
1372
+		if (! empty($conf->categorie->enabled)  && ! empty($user->rights->categorie->lire))
1373
+		{
1374
+			$langs->load('categories');
1375
+
1376
+			// Customer
1377
+			if ($object->prospect || $object->client) {
1378
+				print '<tr><td class="toptd">' . fieldLabel('CustomersCategoriesShort', 'custcats') . '</td><td colspan="3">';
1379
+				$cate_arbo = $form->select_all_categories(Categorie::TYPE_CUSTOMER, null, 'parent', null, null, 1);
1380
+				print $form->multiselectarray('custcats', $cate_arbo, GETPOST('custcats', 'array'), null, null, null,
1381
+					null, "90%");
1382
+				print "</td></tr>";
1383
+			}
1384
+
1385
+			// Supplier
1386
+			if ($object->fournisseur) {
1387
+				print '<tr><td class="toptd">' . fieldLabel('SuppliersCategoriesShort', 'suppcats') . '</td><td colspan="3">';
1388
+				$cate_arbo = $form->select_all_categories(Categorie::TYPE_SUPPLIER, null, 'parent', null, null, 1);
1389
+				print $form->multiselectarray('suppcats', $cate_arbo, GETPOST('suppcats', 'array'), null, null, null,
1390
+					null, "90%");
1391
+				print "</td></tr>";
1392
+			}
1393
+		}
1394
+
1395
+		// Multicurrency
1396
+		if (! empty($conf->multicurrency->enabled))
1397
+		{
1398
+			print '<tr>';
1399
+			print '<td>'.fieldLabel('Currency','multicurrency_code').'</td>';
1400
+			print '<td colspan="3" class="maxwidthonsmartphone">';
1401
+			print $form->selectMultiCurrency(($object->multicurrency_code ? $object->multicurrency_code : $conf->currency), 'multicurrency_code', 1);
1402
+			print '</td></tr>';
1403
+		}
1404
+
1405
+		// Other attributes
1406
+		$parameters=array('colspan' => ' colspan="3"', 'colspanvalue' => '3');
1407
+		$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
1408
+		print $hookmanager->resPrint;
1409
+		if (empty($reshook) && ! empty($extrafields->attribute_label))
1410
+		{
1411
+			print $object->showOptionals($extrafields,'edit');
1412
+		}
1413
+
1414
+		// Ajout du logo
1415
+		print '<tr class="hideonsmartphone">';
1416
+		print '<td>'.fieldLabel('Logo','photoinput').'</td>';
1417
+		print '<td colspan="3">';
1418
+		print '<input class="flat" type="file" name="photo" id="photoinput" />';
1419
+		print '</td>';
1420
+		print '</tr>';
1421
+
1422
+		print '</table>'."\n";
1423
+
1424
+		dol_fiche_end();
1425
+
1426
+		print '<div class="center">';
1427
+		print '<input type="submit" class="button" name="create" value="'.$langs->trans('AddThirdParty').'">';
1428
+		if (! empty($backtopage))
1429
+		{
1430
+			print ' &nbsp; &nbsp; ';
1431
+			print '<input type="submit" class="button" name="cancel" value="'.$langs->trans('Cancel').'">';
1432
+		}
1433
+		else
1434
+		{
1435
+			print ' &nbsp; &nbsp; ';
1436
+			print '<input type="button" class="button" value="' . $langs->trans("Cancel") . '" onClick="javascript:history.go(-1)">';
1437
+		}
1438
+		print '</div>'."\n";
1439
+
1440
+		print '</form>'."\n";
1441
+	}
1442
+	elseif ($action == 'edit')
1443
+	{
1444
+		/*
1445
+         * Edition
1446
+         */
1447
+
1448
+
1449
+		//print load_fiche_titre($langs->trans("EditCompany"));
1450
+
1451
+		if ($socid)
1452
+		{
1453
+			$res=$object->fetch_optionals();
1454
+			//if ($res < 0) { dol_print_error($db); exit; }
1455
+
1456
+			$head = societe_prepare_head($object);
1457
+
1458
+			// Load object modCodeTiers
1459
+			$module=(! empty($conf->global->SOCIETE_CODECLIENT_ADDON)?$conf->global->SOCIETE_CODECLIENT_ADDON:'mod_codeclient_leopard');
1460
+			if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php')
1461
+			{
1462
+				$module = substr($module, 0, dol_strlen($module)-4);
1463
+			}
1464
+			$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
1465
+			foreach ($dirsociete as $dirroot)
1466
+			{
1467
+				$res=dol_include_once($dirroot.$module.'.php');
1468
+				if ($res) break;
1469
+			}
1470
+			$modCodeClient = new $module($db);
1471
+			// We verified if the tag prefix is used
1472
+			if ($modCodeClient->code_auto)
1473
+			{
1474
+				$prefixCustomerIsUsed = $modCodeClient->verif_prefixIsUsed();
1475
+			}
1476
+			$module=$conf->global->SOCIETE_CODECLIENT_ADDON;
1477
+			if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php')
1478
+			{
1479
+				$module = substr($module, 0, dol_strlen($module)-4);
1480
+			}
1481
+			$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
1482
+			foreach ($dirsociete as $dirroot)
1483
+			{
1484
+				$res=dol_include_once($dirroot.$module.'.php');
1485
+				if ($res) break;
1486
+			}
1487
+			$modCodeFournisseur = new $module($db);
1488
+			// On verifie si la balise prefix est utilisee
1489
+			if ($modCodeFournisseur->code_auto)
1490
+			{
1491
+				$prefixSupplierIsUsed = $modCodeFournisseur->verif_prefixIsUsed();
1492
+			}
1493
+
1494
+			$object->oldcopy = clone $object;
1495
+
1496
+			if (GETPOSTISSET('name'))
1497
+			{
1498
+				// We overwrite with values if posted
1499
+				$object->name					= GETPOST('name', 'alpha');
1500
+				$object->prefix_comm			= GETPOST('prefix_comm', 'alpha');
1501
+				$object->client					= GETPOST('client', 'int');
1502
+				$object->code_client			= GETPOST('code_client', 'alpha');
1503
+				$object->fournisseur			= GETPOST('fournisseur', 'int');
1504
+				$object->code_fournisseur		= GETPOST('code_fournisseur', 'alpha');
1505
+				$object->address				= GETPOST('address', 'alpha');
1506
+				$object->zip					= GETPOST('zipcode', 'alpha');
1507
+				$object->town					= GETPOST('town', 'alpha');
1508
+				$object->country_id				= GETPOST('country_id')?GETPOST('country_id', 'int'):$mysoc->country_id;
1509
+				$object->state_id				= GETPOST('state_id', 'int');
1510
+				$object->skype					= GETPOST('skype', 'alpha');
1511
+				$object->phone					= GETPOST('phone', 'alpha');
1512
+				$object->fax					= GETPOST('fax', 'alpha');
1513
+				$object->email					= GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL);
1514
+				$object->url					= GETPOST('url', 'custom', 0, FILTER_SANITIZE_URL);
1515
+				$object->capital				= GETPOST('capital', 'alpha');
1516
+				$object->idprof1				= GETPOST('idprof1', 'alpha');
1517
+				$object->idprof2				= GETPOST('idprof2', 'alpha');
1518
+				$object->idprof3				= GETPOST('idprof3', 'alpha');
1519
+				$object->idprof4				= GETPOST('idprof4', 'alpha');
1520
+				$object->idprof5				= GETPOST('idprof5', 'alpha');
1521
+				$object->idprof6				= GETPOST('idprof6', 'alpha');
1522
+				$object->typent_id				= GETPOST('typent_id', 'int');
1523
+				$object->effectif_id			= GETPOST('effectif_id', 'int');
1524
+				$object->barcode				= GETPOST('barcode', 'alpha');
1525
+				$object->forme_juridique_code	= GETPOST('forme_juridique_code', 'int');
1526
+				$object->default_lang			= GETPOST('default_lang', 'alpha');
1527
+
1528
+				$object->tva_assuj				= GETPOST('assujtva_value', 'int');
1529
+				$object->tva_intra				= GETPOST('tva_intra', 'alpha');
1530
+				$object->status					= GETPOST('status', 'int');
1531
+
1532
+				// Webservices url/key
1533
+				$object->webservices_url        = GETPOST('webservices_url', 'custom', 0, FILTER_SANITIZE_URL);
1534
+				$object->webservices_key        = GETPOST('webservices_key', 'san_alpha');
1535 1535
 
1536 1536
 				//Incoterms
1537 1537
 				if (!empty($conf->incoterm->enabled))
@@ -1540,31 +1540,31 @@  discard block
 block discarded – undo
1540 1540
 					$object->location_incoterms		= GETPOST('lcoation_incoterms', 'alpha');
1541 1541
 				}
1542 1542
 
1543
-                //Local Taxes
1544
-                $object->localtax1_assuj		= GETPOST('localtax1assuj_value');
1545
-                $object->localtax2_assuj		= GETPOST('localtax2assuj_value');
1543
+				//Local Taxes
1544
+				$object->localtax1_assuj		= GETPOST('localtax1assuj_value');
1545
+				$object->localtax2_assuj		= GETPOST('localtax2assuj_value');
1546 1546
 
1547
-                $object->localtax1_value		=GETPOST('lt1');
1548
-                $object->localtax2_value		=GETPOST('lt2');
1547
+				$object->localtax1_value		=GETPOST('lt1');
1548
+				$object->localtax2_value		=GETPOST('lt2');
1549 1549
 
1550
-                // We set country_id, and country_code label of the chosen country
1551
-                if ($object->country_id > 0)
1552
-                {
1553
-                	$tmparray=getCountry($object->country_id,'all');
1554
-                    $object->country_code	= $tmparray['code'];
1555
-                    $object->country		= $tmparray['label'];
1556
-                }
1557
-            }
1550
+				// We set country_id, and country_code label of the chosen country
1551
+				if ($object->country_id > 0)
1552
+				{
1553
+					$tmparray=getCountry($object->country_id,'all');
1554
+					$object->country_code	= $tmparray['code'];
1555
+					$object->country		= $tmparray['label'];
1556
+				}
1557
+			}
1558 1558
 
1559
-            if($object->localtax1_assuj==0){
1560
-            	$sub=0;
1561
-            }else{$sub=1;}
1562
-            if($object->localtax2_assuj==0){
1563
-            	$sub2=0;
1564
-            }else{$sub2=1;}
1559
+			if($object->localtax1_assuj==0){
1560
+				$sub=0;
1561
+			}else{$sub=1;}
1562
+			if($object->localtax2_assuj==0){
1563
+				$sub2=0;
1564
+			}else{$sub2=1;}
1565 1565
 
1566
-            print "\n".'<script type="text/javascript">';
1567
-            print '$(document).ready(function () {
1566
+			print "\n".'<script type="text/javascript">';
1567
+			print '$(document).ready(function () {
1568 1568
     			var val='.$sub.';
1569 1569
     			var val2='.$sub2.';
1570 1570
     			if("#localtax1assuj_value".value==undefined){
@@ -1599,340 +1599,340 @@  discard block
 block discarded – undo
1599 1599
     			});
1600 1600
 
1601 1601
                });';
1602
-            print '</script>'."\n";
1602
+			print '</script>'."\n";
1603 1603
 
1604 1604
 
1605
-            if ($conf->use_javascript_ajax)
1606
-            {
1607
-                print "\n".'<script type="text/javascript" language="javascript">';
1608
-                print '$(document).ready(function () {
1605
+			if ($conf->use_javascript_ajax)
1606
+			{
1607
+				print "\n".'<script type="text/javascript" language="javascript">';
1608
+				print '$(document).ready(function () {
1609 1609
                 			$("#selectcountry_id").change(function() {
1610 1610
                 				document.formsoc.action.value="edit";
1611 1611
                 				document.formsoc.submit();
1612 1612
                 			});
1613 1613
                        })';
1614
-                print '</script>'."\n";
1615
-            }
1614
+				print '</script>'."\n";
1615
+			}
1616 1616
 
1617
-            print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'" method="post" name="formsoc">';
1618
-            print '<input type="hidden" name="action" value="update">';
1619
-            print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1620
-            print '<input type="hidden" name="socid" value="'.$object->id.'">';
1621
-            if ($modCodeClient->code_auto || $modCodeFournisseur->code_auto) print '<input type="hidden" name="code_auto" value="1">';
1617
+			print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'" method="post" name="formsoc">';
1618
+			print '<input type="hidden" name="action" value="update">';
1619
+			print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1620
+			print '<input type="hidden" name="socid" value="'.$object->id.'">';
1621
+			if ($modCodeClient->code_auto || $modCodeFournisseur->code_auto) print '<input type="hidden" name="code_auto" value="1">';
1622 1622
 
1623 1623
 
1624
-            dol_fiche_head($head, 'card', $langs->trans("ThirdParty"), 0, 'company');
1624
+			dol_fiche_head($head, 'card', $langs->trans("ThirdParty"), 0, 'company');
1625 1625
 
1626
-            print '<div class="fichecenter2">';
1627
-            print '<table class="border" width="100%">';
1626
+			print '<div class="fichecenter2">';
1627
+			print '<table class="border" width="100%">';
1628 1628
 
1629
-            // Ref/ID
1629
+			// Ref/ID
1630 1630
 			if (! empty($conf->global->MAIN_SHOW_TECHNICAL_ID))
1631 1631
 			{
1632
-		        print '<tr><td class="titlefieldcreate">'.$langs->trans("ID").'</td><td colspan="3">';
1633
-            	print $object->ref;
1634
-            	print '</td></tr>';
1635
-			}
1636
-
1637
-            // Name
1638
-            print '<tr><td class="titlefieldcreate">'.fieldLabel('ThirdPartyName','name',1).'</td>';
1639
-	        print '<td colspan="3"><input type="text" class="minwidth300" maxlength="128" name="name" id="name" value="'.dol_escape_htmltag($object->name).'" autofocus="autofocus"></td></tr>';
1640
-
1641
-	        // Alias names (commercial, trademark or alias names)
1642
-	        print '<tr id="name_alias"><td><label for="name_alias_input">'.$langs->trans('AliasNames').'</label></td>';
1643
-	        print '<td colspan="3"><input type="text" class="minwidth300" name="name_alias" id="name_alias_input" value="'.dol_escape_htmltag($object->name_alias).'"></td></tr>';
1644
-
1645
-            // Prefix
1646
-            if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
1647
-            {
1648
-                print '<tr><td>'.fieldLabel('Prefix','prefix').'</td><td colspan="3">';
1649
-                // It does not change the prefix mode using the auto numbering prefix
1650
-                if (($prefixCustomerIsUsed || $prefixSupplierIsUsed) && $object->prefix_comm)
1651
-                {
1652
-                    print '<input type="hidden" name="prefix_comm" value="'.dol_escape_htmltag($object->prefix_comm).'">';
1653
-                    print $object->prefix_comm;
1654
-                }
1655
-                else
1656
-                {
1657
-                    print '<input type="text" size="5" maxlength="5" name="prefix_comm" id="prefix" value="'.dol_escape_htmltag($object->prefix_comm).'">';
1658
-                }
1659
-                print '</td>';
1660
-            }
1661
-
1662
-            // Prospect/Customer
1663
-            print '<tr><td>'.fieldLabel('ProspectCustomer','customerprospect',1).'</td>';
1664
-	        print '<td class="maxwidthonsmartphone"><select class="flat" name="client" id="customerprospect">';
1665
-            if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) print '<option value="2"'.($object->client==2?' selected':'').'>'.$langs->trans('Prospect').'</option>';
1666
-            if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print '<option value="3"'.($object->client==3?' selected':'').'>'.$langs->trans('ProspectCustomer').'</option>';
1667
-            if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print '<option value="1"'.($object->client==1?' selected':'').'>'.$langs->trans('Customer').'</option>';
1668
-            print '<option value="0"'.($object->client==0?' selected':'').'>'.$langs->trans('NorProspectNorCustomer').'</option>';
1669
-            print '</select></td>';
1670
-            print '<td>'.fieldLabel('CustomerCode','customer_code').'</td><td>';
1671
-
1672
-            print '<table class="nobordernopadding"><tr><td>';
1673
-            if ((!$object->code_client || $object->code_client == -1) && $modCodeClient->code_auto)
1674
-            {
1675
-                $tmpcode=$object->code_client;
1676
-                if (empty($tmpcode) && ! empty($object->oldcopy->code_client)) $tmpcode=$object->oldcopy->code_client; // When there is an error to update a thirdparty, the number for supplier and customer code is kept to old value.
1677
-                if (empty($tmpcode) && ! empty($modCodeClient->code_auto)) $tmpcode=$modCodeClient->getNextValue($object,0);
1678
-                print '<input type="text" name="code_client" id="customer_code" size="16" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
1679
-            }
1680
-            else if ($object->codeclient_modifiable())
1681
-            {
1682
-                print '<input type="text" name="code_client" id="customer_code" size="16" value="'.$object->code_client.'" maxlength="15">';
1683
-            }
1684
-            else
1685
-            {
1686
-                print $object->code_client;
1687
-                print '<input type="hidden" name="code_client" value="'.$object->code_client.'">';
1688
-            }
1689
-            print '</td><td>';
1690
-            $s=$modCodeClient->getToolTip($langs,$object,0);
1691
-            print $form->textwithpicto('',$s,1);
1692
-            print '</td></tr></table>';
1693
-
1694
-            print '</td></tr>';
1695
-
1696
-            // Supplier
1697
-            if (! empty($conf->fournisseur->enabled) && ! empty($user->rights->fournisseur->lire))
1698
-            {
1699
-                print '<tr>';
1700
-                print '<td>'.fieldLabel('Supplier','fournisseur',1).'</td><td class="maxwidthonsmartphone">';
1701
-                print $form->selectyesno("fournisseur",$object->fournisseur,1);
1702
-                print '</td>';
1703
-                print '<td>'.fieldLabel('SupplierCode','supplier_code').'</td><td>';
1704
-
1705
-                print '<table class="nobordernopadding"><tr><td>';
1706
-                if ((!$object->code_fournisseur || $object->code_fournisseur == -1) && $modCodeFournisseur->code_auto)
1707
-                {
1708
-                    $tmpcode=$object->code_fournisseur;
1709
-                    if (empty($tmpcode) && ! empty($object->oldcopy->code_fournisseur)) $tmpcode=$object->oldcopy->code_fournisseur; // When there is an error to update a thirdparty, the number for supplier and customer code is kept to old value.
1710
-                    if (empty($tmpcode) && ! empty($modCodeFournisseur->code_auto)) $tmpcode=$modCodeFournisseur->getNextValue($object,1);
1711
-                    print '<input type="text" name="code_fournisseur" id="supplier_code" size="16" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
1712
-                }
1713
-                else if ($object->codefournisseur_modifiable())
1714
-                {
1715
-                    print '<input type="text" name="code_fournisseur" id="supplier_code" size="16" value="'.$object->code_fournisseur.'" maxlength="15">';
1716
-                }
1717
-                else
1718
-              {
1719
-                    print $object->code_fournisseur;
1720
-                    print '<input type="hidden" name="code_fournisseur" value="'.$object->code_fournisseur.'">';
1721
-                }
1722
-                print '</td><td>';
1723
-                $s=$modCodeFournisseur->getToolTip($langs,$object,1);
1724
-                print $form->textwithpicto('',$s,1);
1725
-                print '</td></tr></table>';
1726
-
1727
-                print '</td></tr>';
1728
-            }
1729
-
1730
-            // Barcode
1731
-            if (! empty($conf->barcode->enabled))
1732
-            {
1733
-                print '<tr><td class="tdtop">'.fieldLabel('Gencod','barcode').'</td>';
1734
-	            print '<td colspan="3"><input type="text" name="barcode" id="barcode" value="'.$object->barcode.'">';
1735
-                print '</td></tr>';
1736
-            }
1737
-
1738
-            // Status
1739
-            print '<tr><td>'.fieldLabel('Status','status').'</td><td colspan="3">';
1740
-            print $form->selectarray('status', array('0'=>$langs->trans('ActivityCeased'),'1'=>$langs->trans('InActivity')),$object->status);
1741
-            print '</td></tr>';
1742
-
1743
-            // Address
1744
-            print '<tr><td class="tdtop">'.fieldLabel('Address','address').'</td>';
1745
-	        print '<td colspan="3"><textarea name="address" id="address" class="quatrevingtpercent" rows="3" wrap="soft">';
1746
-            print $object->address;
1747
-            print '</textarea></td></tr>';
1748
-
1749
-            // Zip / Town
1750
-            print '<tr><td>'.fieldLabel('Zip','zipcode').'</td><td>';
1751
-            print $formcompany->select_ziptown($object->zip, 'zipcode', array('town', 'selectcountry_id', 'state_id'), 0, 0, '', 'maxwidth50onsmartphone');
1752
-            print '</td><td>'.fieldLabel('Town','town').'</td><td>';
1753
-            print $formcompany->select_ziptown($object->town, 'town', array('zipcode', 'selectcountry_id', 'state_id'));
1754
-            print '</td></tr>';
1755
-
1756
-            // Country
1757
-            print '<tr><td>'.fieldLabel('Country','selectcounty_id').'</td><td colspan="3">';
1758
-            print $form->select_country((GETPOST('country_id')!=''?GETPOST('country_id'):$object->country_id),'country_id');
1759
-            if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1760
-            print '</td></tr>';
1761
-
1762
-            // State
1763
-            if (empty($conf->global->SOCIETE_DISABLE_STATE))
1764
-            {
1765
-                if(!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && ($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 || $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 2))
1766
-                {
1767
-                    print '<tr><td>'.fieldLabel('Region-State','state_id').'</td><td colspan="3">';
1768
-                }
1769
-                else
1770
-                {
1771
-                    print '<tr><td>'.fieldLabel('State','state_id').'</td><td colspan="3">';
1772
-                }
1773
-
1774
-                print $formcompany->select_state($object->state_id,$object->country_code);
1775
-                print '</td></tr>';
1776
-            }
1777
-
1778
-            // EMail / Web
1779
-            print '<tr><td>'.fieldLabel('EMail','email',(! empty($conf->global->SOCIETE_EMAIL_MANDATORY))).'</td>';
1780
-	        print '<td colspan="3"><input type="text" name="email" id="email" size="32" value="'.$object->email.'"></td></tr>';
1781
-            print '<tr><td>'.fieldLabel('Web','url').'</td>';
1782
-	        print '<td colspan="3"><input type="text" name="url" id="url" size="32" value="'.$object->url.'"></td></tr>';
1783
-
1784
-            // Skype
1785
-            if (! empty($conf->skype->enabled))
1786
-            {
1787
-                print '<tr><td>'.fieldLabel('Skype','skype').'</td>';
1788
-	            print '<td colspan="3"><input type="text" name="skype" id="skype" size="32" value="'.$object->skype.'"></td></tr>';
1789
-            }
1790
-
1791
-            // Phone / Fax
1792
-            print '<tr><td>'.fieldLabel('Phone','phone').'</td>';
1793
-	        print '<td><input type="text" name="phone" id="phone" class="maxwidth100onsmartphone quatrevingtpercent" value="'.$object->phone.'"></td>';
1794
-            print '<td>'.fieldLabel('Fax','fax').'</td>';
1795
-	        print '<td><input type="text" name="fax" id="fax" class="maxwidth100onsmartphone quatrevingtpercent" value="'.$object->fax.'"></td></tr>';
1796
-
1797
-            // Prof ids
1798
-            $i=1; $j=0;
1799
-            while ($i <= 6)
1800
-            {
1801
-                $idprof=$langs->transcountry('ProfId'.$i,$object->country_code);
1802
-                if ($idprof!='-')
1803
-                {
1804
-	                $key='idprof'.$i;
1805
-
1806
-	                if (($j % 2) == 0) print '<tr>';
1807
-
1808
-	                $idprof_mandatory ='SOCIETE_IDPROF'.($i).'_MANDATORY';
1809
-	                if (empty($conf->global->$idprof_mandatory) || ! $object->isACompany())
1810
-	                    print '<td>'.fieldLabel($idprof,$key).'</td><td>';
1811
-                    else
1812
-	                    print '<td><span class="fieldrequired">'.fieldLabel($idprof,$key).'</td><td>';
1813
-
1814
-	                print $formcompany->get_input_id_prof($i,$key,$object->$key,$object->country_code);
1815
-                    print '</td>';
1816
-                    if (($j % 2) == 1) print '</tr>';
1817
-                    $j++;
1818
-                }
1819
-                $i++;
1820
-            }
1821
-            if ($j % 2 == 1) print '<td colspan="2"></td></tr>';
1822
-
1823
-            // VAT is used
1824
-            print '<tr><td>'.fieldLabel('VATIsUsed','assujtva_value').'</td><td colspan="3">';
1825
-            print $form->selectyesno('assujtva_value',$object->tva_assuj,1);
1826
-            print '</td></tr>';
1827
-
1828
-            // Local Taxes
1829
-            //TODO: Place into a function to control showing by country or study better option
1830
-            if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1")
1831
-            {
1832
-                print '<tr><td>'.fieldLabel($langs->transcountry("LocalTax1IsUsed",$mysoc->country_code),'localtax1assuj_value').'</td><td>';
1833
-                print $form->selectyesno('localtax1assuj_value',$object->localtax1_assuj,1);
1834
-                if(! isOnlyOneLocalTax(1))
1835
-                {
1836
-                    print '<span class="cblt1">     '.$langs->transcountry("Type",$mysoc->country_code).': ';
1837
-                    $formcompany->select_localtax(1,$object->localtax1_value, "lt1");
1838
-                    print '</span>';
1839
-                }
1840
-                print '</td>';
1841
-
1842
-                print '<td>'.fieldLabel($langs->transcountry("LocalTax2IsUsed",$mysoc->country_code),'localtax2assuj_value').'</td><td>';
1843
-                print $form->selectyesno('localtax2assuj_value',$object->localtax2_assuj,1);
1844
-                if  (! isOnlyOneLocalTax(2))
1845
-                {
1846
-                    print '<span class="cblt2">     '.$langs->transcountry("Type",$mysoc->country_code).': ';
1847
-                    $formcompany->select_localtax(2,$object->localtax2_value, "lt2");
1848
-                    print '</span>';
1849
-                }
1850
-                print '</td></tr>';
1851
-
1852
-            }
1853
-            elseif($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj!="1")
1854
-            {
1855
-                print '<tr><td>'.fieldLabel($langs->transcountry("LocalTax1IsUsed",$mysoc->country_code),'localtax1assuj_value').'</td><td colspan="3">';
1856
-                print $form->selectyesno('localtax1assuj_value',$object->localtax1_assuj,1);
1857
-                if(! isOnlyOneLocalTax(1))
1858
-                {
1859
-                    print '<span class="cblt1">     '.$langs->transcountry("Type",$mysoc->country_code).': ';
1860
-                    $formcompany->select_localtax(1,$object->localtax1_value, "lt1");
1861
-                    print '</span>';
1862
-                }
1863
-                print '</td></tr>';
1864
-
1865
-            }
1866
-            elseif($mysoc->localtax2_assuj=="1" && $mysoc->localtax1_assuj!="1")
1867
-            {
1868
-                print '<tr><td>'.fieldLabel($langs->transcountry("LocalTax2IsUsed",$mysoc->country_code),'localtax2assuj_value').'</td><td colspan="3">';
1869
-                print $form->selectyesno('localtax2assuj_value',$object->localtax2_assuj,1);
1870
-                if(! isOnlyOneLocalTax(2))
1871
-                {
1872
-                    print '<span class="cblt2">     '.$langs->transcountry("Type",$mysoc->country_code).': ';
1873
-                    $formcompany->select_localtax(2,$object->localtax2_value, "lt2");
1874
-                    print '</span>';
1875
-                }
1876
-                print '</td></tr>';
1877
-            }
1878
-
1879
-            // VAT Code
1880
-            print '<tr><td>'.fieldLabel('VATIntra','intra_vat').'</td>';
1881
-            print '<td colspan="3">';
1882
-            $s ='<input type="text" class="flat maxwidthonsmartphone" name="tva_intra" id="intra_vat" maxlength="20" value="'.$object->tva_intra.'">';
1883
-
1884
-            if (empty($conf->global->MAIN_DISABLEVATCHECK) && isInEEC($object))
1885
-            {
1886
-                $s.=' &nbsp; ';
1887
-
1888
-                if ($conf->use_javascript_ajax)
1889
-                {
1890
-                    print "\n";
1891
-                    print '<script language="JavaScript" type="text/javascript">';
1892
-                    print "function CheckVAT(a) {\n";
1893
-                    print "newpopup('".DOL_URL_ROOT."/societe/checkvat/checkVatPopup.php?vatNumber='+a,'".dol_escape_js($langs->trans("VATIntraCheckableOnEUSite"))."',500,285);\n";
1894
-                    print "}\n";
1895
-                    print '</script>';
1896
-                    print "\n";
1897
-                    $s.='<a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT(document.formsoc.tva_intra.value);">'.$langs->trans("VATIntraCheck").'</a>';
1898
-                    $s = $form->textwithpicto($s,$langs->trans("VATIntraCheckDesc",$langs->trans("VATIntraCheck")),1);
1899
-                }
1900
-                else
1901
-                {
1902
-                    $s.='<a href="'.$langs->transcountry("VATIntraCheckURL",$object->country_id).'" class="hideonsmartphone" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"),'help').'</a>';
1903
-                }
1904
-            }
1905
-            print $s;
1906
-            print '</td>';
1907
-            print '</tr>';
1908
-
1909
-            // Type - Size
1910
-            print '<tr><td>'.fieldLabel('ThirdPartyType','typent_id').'</td><td class="maxwidthonsmartphone">';
1911
-            print $form->selectarray("typent_id",$formcompany->typent_array(0), $object->typent_id, 0, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT)?'ASC':$conf->global->SOCIETE_SORT_ON_TYPEENT));
1912
-            if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1913
-            print '</td>';
1914
-            print '<td>'.fieldLabel('Staff','effectif_id').'</td><td class="maxwidthonsmartphone">';
1915
-            print $form->selectarray("effectif_id",$formcompany->effectif_array(0), $object->effectif_id);
1916
-            if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1917
-            print '</td></tr>';
1918
-
1919
-            // Juridical type
1920
-            print '<tr><td>'.fieldLabel('JuridicalStatus','forme_juridique_code').'</td><td class="maxwidthonsmartphone" colspan="3">';
1921
-            print $formcompany->select_juridicalstatus($object->forme_juridique_code, $object->country_code, '', 'forme_juridique_code');
1922
-            print '</td></tr>';
1923
-
1924
-            // Capital
1925
-            print '<tr><td>'.fieldLabel('Capital','capital').'</td>';
1926
-	        print '<td colspan="3"><input type="text" name="capital" id="capital" size="10" value="'.$object->capital.'"> <font class="hideonsmartphone">'.$langs->trans("Currency".$conf->currency).'</font></td></tr>';
1927
-
1928
-            // Default language
1929
-            if (! empty($conf->global->MAIN_MULTILANGS))
1930
-            {
1931
-                print '<tr><td>'.fieldLabel('DefaultLang','default_lang').'</td><td colspan="3">'."\n";
1932
-                print $formadmin->select_language($object->default_lang,'default_lang',0,0,1);
1933
-                print '</td>';
1934
-                print '</tr>';
1935
-            }
1632
+				print '<tr><td class="titlefieldcreate">'.$langs->trans("ID").'</td><td colspan="3">';
1633
+				print $object->ref;
1634
+				print '</td></tr>';
1635
+			}
1636
+
1637
+			// Name
1638
+			print '<tr><td class="titlefieldcreate">'.fieldLabel('ThirdPartyName','name',1).'</td>';
1639
+			print '<td colspan="3"><input type="text" class="minwidth300" maxlength="128" name="name" id="name" value="'.dol_escape_htmltag($object->name).'" autofocus="autofocus"></td></tr>';
1640
+
1641
+			// Alias names (commercial, trademark or alias names)
1642
+			print '<tr id="name_alias"><td><label for="name_alias_input">'.$langs->trans('AliasNames').'</label></td>';
1643
+			print '<td colspan="3"><input type="text" class="minwidth300" name="name_alias" id="name_alias_input" value="'.dol_escape_htmltag($object->name_alias).'"></td></tr>';
1644
+
1645
+			// Prefix
1646
+			if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
1647
+			{
1648
+				print '<tr><td>'.fieldLabel('Prefix','prefix').'</td><td colspan="3">';
1649
+				// It does not change the prefix mode using the auto numbering prefix
1650
+				if (($prefixCustomerIsUsed || $prefixSupplierIsUsed) && $object->prefix_comm)
1651
+				{
1652
+					print '<input type="hidden" name="prefix_comm" value="'.dol_escape_htmltag($object->prefix_comm).'">';
1653
+					print $object->prefix_comm;
1654
+				}
1655
+				else
1656
+				{
1657
+					print '<input type="text" size="5" maxlength="5" name="prefix_comm" id="prefix" value="'.dol_escape_htmltag($object->prefix_comm).'">';
1658
+				}
1659
+				print '</td>';
1660
+			}
1661
+
1662
+			// Prospect/Customer
1663
+			print '<tr><td>'.fieldLabel('ProspectCustomer','customerprospect',1).'</td>';
1664
+			print '<td class="maxwidthonsmartphone"><select class="flat" name="client" id="customerprospect">';
1665
+			if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) print '<option value="2"'.($object->client==2?' selected':'').'>'.$langs->trans('Prospect').'</option>';
1666
+			if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print '<option value="3"'.($object->client==3?' selected':'').'>'.$langs->trans('ProspectCustomer').'</option>';
1667
+			if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print '<option value="1"'.($object->client==1?' selected':'').'>'.$langs->trans('Customer').'</option>';
1668
+			print '<option value="0"'.($object->client==0?' selected':'').'>'.$langs->trans('NorProspectNorCustomer').'</option>';
1669
+			print '</select></td>';
1670
+			print '<td>'.fieldLabel('CustomerCode','customer_code').'</td><td>';
1671
+
1672
+			print '<table class="nobordernopadding"><tr><td>';
1673
+			if ((!$object->code_client || $object->code_client == -1) && $modCodeClient->code_auto)
1674
+			{
1675
+				$tmpcode=$object->code_client;
1676
+				if (empty($tmpcode) && ! empty($object->oldcopy->code_client)) $tmpcode=$object->oldcopy->code_client; // When there is an error to update a thirdparty, the number for supplier and customer code is kept to old value.
1677
+				if (empty($tmpcode) && ! empty($modCodeClient->code_auto)) $tmpcode=$modCodeClient->getNextValue($object,0);
1678
+				print '<input type="text" name="code_client" id="customer_code" size="16" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
1679
+			}
1680
+			else if ($object->codeclient_modifiable())
1681
+			{
1682
+				print '<input type="text" name="code_client" id="customer_code" size="16" value="'.$object->code_client.'" maxlength="15">';
1683
+			}
1684
+			else
1685
+			{
1686
+				print $object->code_client;
1687
+				print '<input type="hidden" name="code_client" value="'.$object->code_client.'">';
1688
+			}
1689
+			print '</td><td>';
1690
+			$s=$modCodeClient->getToolTip($langs,$object,0);
1691
+			print $form->textwithpicto('',$s,1);
1692
+			print '</td></tr></table>';
1693
+
1694
+			print '</td></tr>';
1695
+
1696
+			// Supplier
1697
+			if (! empty($conf->fournisseur->enabled) && ! empty($user->rights->fournisseur->lire))
1698
+			{
1699
+				print '<tr>';
1700
+				print '<td>'.fieldLabel('Supplier','fournisseur',1).'</td><td class="maxwidthonsmartphone">';
1701
+				print $form->selectyesno("fournisseur",$object->fournisseur,1);
1702
+				print '</td>';
1703
+				print '<td>'.fieldLabel('SupplierCode','supplier_code').'</td><td>';
1704
+
1705
+				print '<table class="nobordernopadding"><tr><td>';
1706
+				if ((!$object->code_fournisseur || $object->code_fournisseur == -1) && $modCodeFournisseur->code_auto)
1707
+				{
1708
+					$tmpcode=$object->code_fournisseur;
1709
+					if (empty($tmpcode) && ! empty($object->oldcopy->code_fournisseur)) $tmpcode=$object->oldcopy->code_fournisseur; // When there is an error to update a thirdparty, the number for supplier and customer code is kept to old value.
1710
+					if (empty($tmpcode) && ! empty($modCodeFournisseur->code_auto)) $tmpcode=$modCodeFournisseur->getNextValue($object,1);
1711
+					print '<input type="text" name="code_fournisseur" id="supplier_code" size="16" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
1712
+				}
1713
+				else if ($object->codefournisseur_modifiable())
1714
+				{
1715
+					print '<input type="text" name="code_fournisseur" id="supplier_code" size="16" value="'.$object->code_fournisseur.'" maxlength="15">';
1716
+				}
1717
+				else
1718
+			  {
1719
+					print $object->code_fournisseur;
1720
+					print '<input type="hidden" name="code_fournisseur" value="'.$object->code_fournisseur.'">';
1721
+				}
1722
+				print '</td><td>';
1723
+				$s=$modCodeFournisseur->getToolTip($langs,$object,1);
1724
+				print $form->textwithpicto('',$s,1);
1725
+				print '</td></tr></table>';
1726
+
1727
+				print '</td></tr>';
1728
+			}
1729
+
1730
+			// Barcode
1731
+			if (! empty($conf->barcode->enabled))
1732
+			{
1733
+				print '<tr><td class="tdtop">'.fieldLabel('Gencod','barcode').'</td>';
1734
+				print '<td colspan="3"><input type="text" name="barcode" id="barcode" value="'.$object->barcode.'">';
1735
+				print '</td></tr>';
1736
+			}
1737
+
1738
+			// Status
1739
+			print '<tr><td>'.fieldLabel('Status','status').'</td><td colspan="3">';
1740
+			print $form->selectarray('status', array('0'=>$langs->trans('ActivityCeased'),'1'=>$langs->trans('InActivity')),$object->status);
1741
+			print '</td></tr>';
1742
+
1743
+			// Address
1744
+			print '<tr><td class="tdtop">'.fieldLabel('Address','address').'</td>';
1745
+			print '<td colspan="3"><textarea name="address" id="address" class="quatrevingtpercent" rows="3" wrap="soft">';
1746
+			print $object->address;
1747
+			print '</textarea></td></tr>';
1748
+
1749
+			// Zip / Town
1750
+			print '<tr><td>'.fieldLabel('Zip','zipcode').'</td><td>';
1751
+			print $formcompany->select_ziptown($object->zip, 'zipcode', array('town', 'selectcountry_id', 'state_id'), 0, 0, '', 'maxwidth50onsmartphone');
1752
+			print '</td><td>'.fieldLabel('Town','town').'</td><td>';
1753
+			print $formcompany->select_ziptown($object->town, 'town', array('zipcode', 'selectcountry_id', 'state_id'));
1754
+			print '</td></tr>';
1755
+
1756
+			// Country
1757
+			print '<tr><td>'.fieldLabel('Country','selectcounty_id').'</td><td colspan="3">';
1758
+			print $form->select_country((GETPOST('country_id')!=''?GETPOST('country_id'):$object->country_id),'country_id');
1759
+			if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1760
+			print '</td></tr>';
1761
+
1762
+			// State
1763
+			if (empty($conf->global->SOCIETE_DISABLE_STATE))
1764
+			{
1765
+				if(!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && ($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 || $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 2))
1766
+				{
1767
+					print '<tr><td>'.fieldLabel('Region-State','state_id').'</td><td colspan="3">';
1768
+				}
1769
+				else
1770
+				{
1771
+					print '<tr><td>'.fieldLabel('State','state_id').'</td><td colspan="3">';
1772
+				}
1773
+
1774
+				print $formcompany->select_state($object->state_id,$object->country_code);
1775
+				print '</td></tr>';
1776
+			}
1777
+
1778
+			// EMail / Web
1779
+			print '<tr><td>'.fieldLabel('EMail','email',(! empty($conf->global->SOCIETE_EMAIL_MANDATORY))).'</td>';
1780
+			print '<td colspan="3"><input type="text" name="email" id="email" size="32" value="'.$object->email.'"></td></tr>';
1781
+			print '<tr><td>'.fieldLabel('Web','url').'</td>';
1782
+			print '<td colspan="3"><input type="text" name="url" id="url" size="32" value="'.$object->url.'"></td></tr>';
1783
+
1784
+			// Skype
1785
+			if (! empty($conf->skype->enabled))
1786
+			{
1787
+				print '<tr><td>'.fieldLabel('Skype','skype').'</td>';
1788
+				print '<td colspan="3"><input type="text" name="skype" id="skype" size="32" value="'.$object->skype.'"></td></tr>';
1789
+			}
1790
+
1791
+			// Phone / Fax
1792
+			print '<tr><td>'.fieldLabel('Phone','phone').'</td>';
1793
+			print '<td><input type="text" name="phone" id="phone" class="maxwidth100onsmartphone quatrevingtpercent" value="'.$object->phone.'"></td>';
1794
+			print '<td>'.fieldLabel('Fax','fax').'</td>';
1795
+			print '<td><input type="text" name="fax" id="fax" class="maxwidth100onsmartphone quatrevingtpercent" value="'.$object->fax.'"></td></tr>';
1796
+
1797
+			// Prof ids
1798
+			$i=1; $j=0;
1799
+			while ($i <= 6)
1800
+			{
1801
+				$idprof=$langs->transcountry('ProfId'.$i,$object->country_code);
1802
+				if ($idprof!='-')
1803
+				{
1804
+					$key='idprof'.$i;
1805
+
1806
+					if (($j % 2) == 0) print '<tr>';
1807
+
1808
+					$idprof_mandatory ='SOCIETE_IDPROF'.($i).'_MANDATORY';
1809
+					if (empty($conf->global->$idprof_mandatory) || ! $object->isACompany())
1810
+						print '<td>'.fieldLabel($idprof,$key).'</td><td>';
1811
+					else
1812
+						print '<td><span class="fieldrequired">'.fieldLabel($idprof,$key).'</td><td>';
1813
+
1814
+					print $formcompany->get_input_id_prof($i,$key,$object->$key,$object->country_code);
1815
+					print '</td>';
1816
+					if (($j % 2) == 1) print '</tr>';
1817
+					$j++;
1818
+				}
1819
+				$i++;
1820
+			}
1821
+			if ($j % 2 == 1) print '<td colspan="2"></td></tr>';
1822
+
1823
+			// VAT is used
1824
+			print '<tr><td>'.fieldLabel('VATIsUsed','assujtva_value').'</td><td colspan="3">';
1825
+			print $form->selectyesno('assujtva_value',$object->tva_assuj,1);
1826
+			print '</td></tr>';
1827
+
1828
+			// Local Taxes
1829
+			//TODO: Place into a function to control showing by country or study better option
1830
+			if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1")
1831
+			{
1832
+				print '<tr><td>'.fieldLabel($langs->transcountry("LocalTax1IsUsed",$mysoc->country_code),'localtax1assuj_value').'</td><td>';
1833
+				print $form->selectyesno('localtax1assuj_value',$object->localtax1_assuj,1);
1834
+				if(! isOnlyOneLocalTax(1))
1835
+				{
1836
+					print '<span class="cblt1">     '.$langs->transcountry("Type",$mysoc->country_code).': ';
1837
+					$formcompany->select_localtax(1,$object->localtax1_value, "lt1");
1838
+					print '</span>';
1839
+				}
1840
+				print '</td>';
1841
+
1842
+				print '<td>'.fieldLabel($langs->transcountry("LocalTax2IsUsed",$mysoc->country_code),'localtax2assuj_value').'</td><td>';
1843
+				print $form->selectyesno('localtax2assuj_value',$object->localtax2_assuj,1);
1844
+				if  (! isOnlyOneLocalTax(2))
1845
+				{
1846
+					print '<span class="cblt2">     '.$langs->transcountry("Type",$mysoc->country_code).': ';
1847
+					$formcompany->select_localtax(2,$object->localtax2_value, "lt2");
1848
+					print '</span>';
1849
+				}
1850
+				print '</td></tr>';
1851
+
1852
+			}
1853
+			elseif($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj!="1")
1854
+			{
1855
+				print '<tr><td>'.fieldLabel($langs->transcountry("LocalTax1IsUsed",$mysoc->country_code),'localtax1assuj_value').'</td><td colspan="3">';
1856
+				print $form->selectyesno('localtax1assuj_value',$object->localtax1_assuj,1);
1857
+				if(! isOnlyOneLocalTax(1))
1858
+				{
1859
+					print '<span class="cblt1">     '.$langs->transcountry("Type",$mysoc->country_code).': ';
1860
+					$formcompany->select_localtax(1,$object->localtax1_value, "lt1");
1861
+					print '</span>';
1862
+				}
1863
+				print '</td></tr>';
1864
+
1865
+			}
1866
+			elseif($mysoc->localtax2_assuj=="1" && $mysoc->localtax1_assuj!="1")
1867
+			{
1868
+				print '<tr><td>'.fieldLabel($langs->transcountry("LocalTax2IsUsed",$mysoc->country_code),'localtax2assuj_value').'</td><td colspan="3">';
1869
+				print $form->selectyesno('localtax2assuj_value',$object->localtax2_assuj,1);
1870
+				if(! isOnlyOneLocalTax(2))
1871
+				{
1872
+					print '<span class="cblt2">     '.$langs->transcountry("Type",$mysoc->country_code).': ';
1873
+					$formcompany->select_localtax(2,$object->localtax2_value, "lt2");
1874
+					print '</span>';
1875
+				}
1876
+				print '</td></tr>';
1877
+			}
1878
+
1879
+			// VAT Code
1880
+			print '<tr><td>'.fieldLabel('VATIntra','intra_vat').'</td>';
1881
+			print '<td colspan="3">';
1882
+			$s ='<input type="text" class="flat maxwidthonsmartphone" name="tva_intra" id="intra_vat" maxlength="20" value="'.$object->tva_intra.'">';
1883
+
1884
+			if (empty($conf->global->MAIN_DISABLEVATCHECK) && isInEEC($object))
1885
+			{
1886
+				$s.=' &nbsp; ';
1887
+
1888
+				if ($conf->use_javascript_ajax)
1889
+				{
1890
+					print "\n";
1891
+					print '<script language="JavaScript" type="text/javascript">';
1892
+					print "function CheckVAT(a) {\n";
1893
+					print "newpopup('".DOL_URL_ROOT."/societe/checkvat/checkVatPopup.php?vatNumber='+a,'".dol_escape_js($langs->trans("VATIntraCheckableOnEUSite"))."',500,285);\n";
1894
+					print "}\n";
1895
+					print '</script>';
1896
+					print "\n";
1897
+					$s.='<a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT(document.formsoc.tva_intra.value);">'.$langs->trans("VATIntraCheck").'</a>';
1898
+					$s = $form->textwithpicto($s,$langs->trans("VATIntraCheckDesc",$langs->trans("VATIntraCheck")),1);
1899
+				}
1900
+				else
1901
+				{
1902
+					$s.='<a href="'.$langs->transcountry("VATIntraCheckURL",$object->country_id).'" class="hideonsmartphone" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"),'help').'</a>';
1903
+				}
1904
+			}
1905
+			print $s;
1906
+			print '</td>';
1907
+			print '</tr>';
1908
+
1909
+			// Type - Size
1910
+			print '<tr><td>'.fieldLabel('ThirdPartyType','typent_id').'</td><td class="maxwidthonsmartphone">';
1911
+			print $form->selectarray("typent_id",$formcompany->typent_array(0), $object->typent_id, 0, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT)?'ASC':$conf->global->SOCIETE_SORT_ON_TYPEENT));
1912
+			if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1913
+			print '</td>';
1914
+			print '<td>'.fieldLabel('Staff','effectif_id').'</td><td class="maxwidthonsmartphone">';
1915
+			print $form->selectarray("effectif_id",$formcompany->effectif_array(0), $object->effectif_id);
1916
+			if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1917
+			print '</td></tr>';
1918
+
1919
+			// Juridical type
1920
+			print '<tr><td>'.fieldLabel('JuridicalStatus','forme_juridique_code').'</td><td class="maxwidthonsmartphone" colspan="3">';
1921
+			print $formcompany->select_juridicalstatus($object->forme_juridique_code, $object->country_code, '', 'forme_juridique_code');
1922
+			print '</td></tr>';
1923
+
1924
+			// Capital
1925
+			print '<tr><td>'.fieldLabel('Capital','capital').'</td>';
1926
+			print '<td colspan="3"><input type="text" name="capital" id="capital" size="10" value="'.$object->capital.'"> <font class="hideonsmartphone">'.$langs->trans("Currency".$conf->currency).'</font></td></tr>';
1927
+
1928
+			// Default language
1929
+			if (! empty($conf->global->MAIN_MULTILANGS))
1930
+			{
1931
+				print '<tr><td>'.fieldLabel('DefaultLang','default_lang').'</td><td colspan="3">'."\n";
1932
+				print $formadmin->select_language($object->default_lang,'default_lang',0,0,1);
1933
+				print '</td>';
1934
+				print '</tr>';
1935
+			}
1936 1936
 
1937 1937
 			// Categories
1938 1938
 			if (! empty($conf->categorie->enabled)  && ! empty($user->rights->categorie->lire))
@@ -1973,296 +1973,296 @@  discard block
 block discarded – undo
1973 1973
 			{
1974 1974
 				print '<tr>';
1975 1975
 				print '<td>'.fieldLabel('Currency','multicurrency_code').'</td>';
1976
-		        print '<td colspan="3" class="maxwidthonsmartphone">';
1977
-		        print $form->selectMultiCurrency(($object->multicurrency_code ? $object->multicurrency_code : $conf->currency), 'multicurrency_code', 1);
1976
+				print '<td colspan="3" class="maxwidthonsmartphone">';
1977
+				print $form->selectMultiCurrency(($object->multicurrency_code ? $object->multicurrency_code : $conf->currency), 'multicurrency_code', 1);
1978 1978
 				print '</td></tr>';
1979 1979
 			}
1980 1980
 
1981
-            // Other attributes
1982
-            $parameters=array('colspan' => ' colspan="3"', 'colspanvalue' => '3');
1983
-            $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
1984
-            print $hookmanager->resPrint;
1985
-            if (empty($reshook) && ! empty($extrafields->attribute_label))
1986
-            {
1987
-            	print $object->showOptionals($extrafields,'edit');
1988
-            }
1981
+			// Other attributes
1982
+			$parameters=array('colspan' => ' colspan="3"', 'colspanvalue' => '3');
1983
+			$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
1984
+			print $hookmanager->resPrint;
1985
+			if (empty($reshook) && ! empty($extrafields->attribute_label))
1986
+			{
1987
+				print $object->showOptionals($extrafields,'edit');
1988
+			}
1989 1989
 
1990
-            // Webservices url/key
1991
-            if (!empty($conf->syncsupplierwebservices->enabled)) {
1992
-                print '<tr><td>'.fieldLabel('WebServiceURL','webservices_url').'</td>';
1993
-                print '<td><input type="text" name="webservices_url" id="webservices_url" size="32" value="'.$object->webservices_url.'"></td>';
1994
-                print '<td>'.fieldLabel('WebServiceKey','webservices_key').'</td>';
1995
-                print '<td><input type="text" name="webservices_key" id="webservices_key" size="32" value="'.$object->webservices_key.'"></td></tr>';
1996
-            }
1990
+			// Webservices url/key
1991
+			if (!empty($conf->syncsupplierwebservices->enabled)) {
1992
+				print '<tr><td>'.fieldLabel('WebServiceURL','webservices_url').'</td>';
1993
+				print '<td><input type="text" name="webservices_url" id="webservices_url" size="32" value="'.$object->webservices_url.'"></td>';
1994
+				print '<td>'.fieldLabel('WebServiceKey','webservices_key').'</td>';
1995
+				print '<td><input type="text" name="webservices_key" id="webservices_key" size="32" value="'.$object->webservices_key.'"></td></tr>';
1996
+			}
1997 1997
 
1998 1998
 			// Incoterms
1999 1999
 			if (!empty($conf->incoterm->enabled))
2000 2000
 			{
2001 2001
 				print '<tr>';
2002 2002
 				print '<td>'.fieldLabel('IncotermLabel','incoterm_id').'</td>';
2003
-	            print '<td colspan="3" class="maxwidthonsmartphone">';
2004
-	            print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''));
2003
+				print '<td colspan="3" class="maxwidthonsmartphone">';
2004
+				print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''));
2005 2005
 				print '</td></tr>';
2006 2006
 			}
2007 2007
 
2008
-            // Logo
2009
-            print '<tr class="hideonsmartphone">';
2010
-            print '<td>'.fieldLabel('Logo','photoinput').'</td>';
2011
-            print '<td colspan="3">';
2012
-            if ($object->logo) print $form->showphoto('societe',$object);
2013
-            $caneditfield=1;
2014
-            if ($caneditfield)
2015
-            {
2016
-                if ($object->logo) print "<br>\n";
2017
-                print '<table class="nobordernopadding">';
2018
-                if ($object->logo) print '<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> '.$langs->trans("Delete").'<br><br></td></tr>';
2019
-                //print '<tr><td>'.$langs->trans("PhotoFile").'</td></tr>';
2020
-                print '<tr><td><input type="file" class="flat" name="photo" id="photoinput"></td></tr>';
2021
-                print '</table>';
2022
-            }
2023
-            print '</td>';
2024
-            print '</tr>';
2025
-
2026
-            print '</table>';
2027
-            print '</div>';
2028
-
2029
-	        dol_fiche_end();
2030
-
2031
-            print '<div align="center">';
2032
-            print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
2033
-            print ' &nbsp; &nbsp; ';
2034
-            print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
2035
-            print '</div>';
2036
-
2037
-            print '</form>';
2038
-        }
2039
-    }
2040
-    else
2041
-    {
2042
-    	/*
2008
+			// Logo
2009
+			print '<tr class="hideonsmartphone">';
2010
+			print '<td>'.fieldLabel('Logo','photoinput').'</td>';
2011
+			print '<td colspan="3">';
2012
+			if ($object->logo) print $form->showphoto('societe',$object);
2013
+			$caneditfield=1;
2014
+			if ($caneditfield)
2015
+			{
2016
+				if ($object->logo) print "<br>\n";
2017
+				print '<table class="nobordernopadding">';
2018
+				if ($object->logo) print '<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> '.$langs->trans("Delete").'<br><br></td></tr>';
2019
+				//print '<tr><td>'.$langs->trans("PhotoFile").'</td></tr>';
2020
+				print '<tr><td><input type="file" class="flat" name="photo" id="photoinput"></td></tr>';
2021
+				print '</table>';
2022
+			}
2023
+			print '</td>';
2024
+			print '</tr>';
2025
+
2026
+			print '</table>';
2027
+			print '</div>';
2028
+
2029
+			dol_fiche_end();
2030
+
2031
+			print '<div align="center">';
2032
+			print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
2033
+			print ' &nbsp; &nbsp; ';
2034
+			print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
2035
+			print '</div>';
2036
+
2037
+			print '</form>';
2038
+		}
2039
+	}
2040
+	else
2041
+	{
2042
+		/*
2043 2043
          * View
2044 2044
          */
2045 2045
 
2046
-        if (!empty($object->id)) $res=$object->fetch_optionals();
2047
-        //if ($res < 0) { dol_print_error($db); exit; }
2048
-
2049
-
2050
-        $head = societe_prepare_head($object);
2051
-
2052
-        dol_fiche_head($head, 'card', $langs->trans("ThirdParty"), -1, 'company');
2053
-
2054
-        // Confirm delete third party
2055
-        if ($action == 'delete' || ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile)))
2056
-        {
2057
-            print $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id, $langs->trans("DeleteACompany"), $langs->trans("ConfirmDeleteCompany"), "confirm_delete", '', 0, "action-delete");
2058
-        }
2059
-
2060
-	    if ($action == 'merge')
2061
-	    {
2062
-		    $formquestion = array(
2063
-			    array(
2064
-				    'name' => 'soc_origin',
2065
-			    	'label' => $langs->trans('MergeOriginThirdparty'),
2066
-				    'type' => 'other',
2067
-				    'value' => $form->select_company('', 'soc_origin', 's.rowid != '.$object->id, 'SelectThirdParty', 0, 0, array(), 0, 'minwidth200')
2068
-			    )
2069
-		    );
2070
-
2071
-		    print $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id, $langs->trans("MergeThirdparties"), $langs->trans("ConfirmMergeThirdparties"), "confirm_merge", $formquestion, 'no', 1, 250);
2072
-	    }
2073
-
2074
-        dol_htmloutput_mesg(is_numeric($error)?'':$error, $errors, 'error');
2075
-
2076
-        $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
2077
-
2078
-        dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom');
2079
-
2080
-
2081
-        print '<div class="fichecenter">';
2082
-        print '<div class="fichehalfleft">';
2083
-
2084
-        print '<div class="underbanner clearboth"></div>';
2085
-        print '<table class="border tableforfield" width="100%">';
2086
-
2087
-    	// Prospect/Customer
2088
-    	print '<tr><td class="titlefield">'.$langs->trans('ProspectCustomer').'</td><td>';
2089
-    	print $object->getLibCustProspStatut();
2090
-    	print '</td></tr>';
2091
-
2092
-    	// Supplier
2093
-    	if (! empty($conf->fournisseur->enabled))
2094
-    	{
2095
-    		print '<tr><td>'.$langs->trans('Supplier').'</td><td>';
2096
-    		print yn($object->fournisseur);
2097
-    		print '</td></tr>';
2098
-    	}
2099
-
2100
-    	// Prefix
2101
-        if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
2102
-        {
2103
-            print '<tr><td>'.$langs->trans('Prefix').'</td><td>'.$object->prefix_comm.'</td>';
2104
-            print $htmllogobar; $htmllogobar='';
2105
-            print '</tr>';
2106
-        }
2107
-
2108
-        // Customer code
2109
-        if ($object->client)
2110
-        {
2111
-            print '<tr><td>';
2112
-            print $langs->trans('CustomerCode').'</td><td>';
2113
-            print $object->code_client;
2114
-            if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
2115
-            print '</td>';
2116
-            print $htmllogobar; $htmllogobar='';
2117
-            print '</tr>';
2118
-        }
2119
-
2120
-        // Supplier code
2121
-        if (! empty($conf->fournisseur->enabled) && $object->fournisseur && ! empty($user->rights->fournisseur->lire))
2122
-        {
2123
-            print '<tr><td>';
2124
-            print $langs->trans('SupplierCode').'</td><td>';
2125
-            print $object->code_fournisseur;
2126
-            if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
2127
-            print '</td>';
2128
-            print $htmllogobar; $htmllogobar='';
2129
-            print '</tr>';
2130
-        }
2131
-
2132
-        // Barcode
2133
-        if (! empty($conf->barcode->enabled))
2134
-        {
2135
-            print '<tr><td>';
2136
-            print $langs->trans('Gencod').'</td><td>'.$object->barcode;
2137
-            print '</td>';
2046
+		if (!empty($object->id)) $res=$object->fetch_optionals();
2047
+		//if ($res < 0) { dol_print_error($db); exit; }
2048
+
2049
+
2050
+		$head = societe_prepare_head($object);
2051
+
2052
+		dol_fiche_head($head, 'card', $langs->trans("ThirdParty"), -1, 'company');
2053
+
2054
+		// Confirm delete third party
2055
+		if ($action == 'delete' || ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile)))
2056
+		{
2057
+			print $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id, $langs->trans("DeleteACompany"), $langs->trans("ConfirmDeleteCompany"), "confirm_delete", '', 0, "action-delete");
2058
+		}
2059
+
2060
+		if ($action == 'merge')
2061
+		{
2062
+			$formquestion = array(
2063
+				array(
2064
+					'name' => 'soc_origin',
2065
+					'label' => $langs->trans('MergeOriginThirdparty'),
2066
+					'type' => 'other',
2067
+					'value' => $form->select_company('', 'soc_origin', 's.rowid != '.$object->id, 'SelectThirdParty', 0, 0, array(), 0, 'minwidth200')
2068
+				)
2069
+			);
2070
+
2071
+			print $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id, $langs->trans("MergeThirdparties"), $langs->trans("ConfirmMergeThirdparties"), "confirm_merge", $formquestion, 'no', 1, 250);
2072
+		}
2073
+
2074
+		dol_htmloutput_mesg(is_numeric($error)?'':$error, $errors, 'error');
2075
+
2076
+		$linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
2077
+
2078
+		dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom');
2079
+
2080
+
2081
+		print '<div class="fichecenter">';
2082
+		print '<div class="fichehalfleft">';
2083
+
2084
+		print '<div class="underbanner clearboth"></div>';
2085
+		print '<table class="border tableforfield" width="100%">';
2086
+
2087
+		// Prospect/Customer
2088
+		print '<tr><td class="titlefield">'.$langs->trans('ProspectCustomer').'</td><td>';
2089
+		print $object->getLibCustProspStatut();
2090
+		print '</td></tr>';
2091
+
2092
+		// Supplier
2093
+		if (! empty($conf->fournisseur->enabled))
2094
+		{
2095
+			print '<tr><td>'.$langs->trans('Supplier').'</td><td>';
2096
+			print yn($object->fournisseur);
2097
+			print '</td></tr>';
2098
+		}
2099
+
2100
+		// Prefix
2101
+		if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
2102
+		{
2103
+			print '<tr><td>'.$langs->trans('Prefix').'</td><td>'.$object->prefix_comm.'</td>';
2104
+			print $htmllogobar; $htmllogobar='';
2105
+			print '</tr>';
2106
+		}
2107
+
2108
+		// Customer code
2109
+		if ($object->client)
2110
+		{
2111
+			print '<tr><td>';
2112
+			print $langs->trans('CustomerCode').'</td><td>';
2113
+			print $object->code_client;
2114
+			if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
2115
+			print '</td>';
2116
+			print $htmllogobar; $htmllogobar='';
2117
+			print '</tr>';
2118
+		}
2119
+
2120
+		// Supplier code
2121
+		if (! empty($conf->fournisseur->enabled) && $object->fournisseur && ! empty($user->rights->fournisseur->lire))
2122
+		{
2123
+			print '<tr><td>';
2124
+			print $langs->trans('SupplierCode').'</td><td>';
2125
+			print $object->code_fournisseur;
2126
+			if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
2127
+			print '</td>';
2128
+			print $htmllogobar; $htmllogobar='';
2129
+			print '</tr>';
2130
+		}
2131
+
2132
+		// Barcode
2133
+		if (! empty($conf->barcode->enabled))
2134
+		{
2135
+			print '<tr><td>';
2136
+			print $langs->trans('Gencod').'</td><td>'.$object->barcode;
2137
+			print '</td>';
2138 2138
 			if ($htmllogobar) $htmllogobar.=$form->showbarcode($object);
2139
-            print $htmllogobar;
2139
+			print $htmllogobar;
2140 2140
 			$htmllogobar='';
2141
-            print '</tr>';
2142
-        }
2143
-
2144
-        // Prof ids
2145
-        $i=1; $j=0;
2146
-        while ($i <= 6)
2147
-        {
2148
-            $idprof=$langs->transcountry('ProfId'.$i,$object->country_code);
2149
-            if ($idprof!='-')
2150
-            {
2151
-                //if (($j % 2) == 0) print '<tr>';
2152
-                print '<tr>';
2153
-            	print '<td>'.$idprof.'</td><td>';
2154
-                $key='idprof'.$i;
2155
-                print $object->$key;
2156
-                if ($object->$key)
2157
-                {
2158
-                    if ($object->id_prof_check($i,$object) > 0) print ' &nbsp; '.$object->id_prof_url($i,$object);
2159
-                    else print ' <font class="error">('.$langs->trans("ErrorWrongValue").')</font>';
2160
-                }
2161
-                print '</td>';
2162
-                //if (($j % 2) == 1) print '</tr>';
2163
-                print '</tr>';
2164
-                $j++;
2165
-            }
2166
-            $i++;
2167
-        }
2168
-        //if ($j % 2 == 1)  print '<td colspan="2"></td></tr>';
2169
-
2170
-        // VAT is used
2171
-        print '<tr><td>';
2172
-        print $langs->trans('VATIsUsed');
2173
-        print '</td><td>';
2174
-        print yn($object->tva_assuj);
2175
-        print '</td>';
2141
+			print '</tr>';
2142
+		}
2143
+
2144
+		// Prof ids
2145
+		$i=1; $j=0;
2146
+		while ($i <= 6)
2147
+		{
2148
+			$idprof=$langs->transcountry('ProfId'.$i,$object->country_code);
2149
+			if ($idprof!='-')
2150
+			{
2151
+				//if (($j % 2) == 0) print '<tr>';
2152
+				print '<tr>';
2153
+				print '<td>'.$idprof.'</td><td>';
2154
+				$key='idprof'.$i;
2155
+				print $object->$key;
2156
+				if ($object->$key)
2157
+				{
2158
+					if ($object->id_prof_check($i,$object) > 0) print ' &nbsp; '.$object->id_prof_url($i,$object);
2159
+					else print ' <font class="error">('.$langs->trans("ErrorWrongValue").')</font>';
2160
+				}
2161
+				print '</td>';
2162
+				//if (($j % 2) == 1) print '</tr>';
2163
+				print '</tr>';
2164
+				$j++;
2165
+			}
2166
+			$i++;
2167
+		}
2168
+		//if ($j % 2 == 1)  print '<td colspan="2"></td></tr>';
2169
+
2170
+		// VAT is used
2171
+		print '<tr><td>';
2172
+		print $langs->trans('VATIsUsed');
2173
+		print '</td><td>';
2174
+		print yn($object->tva_assuj);
2175
+		print '</td>';
2176 2176
 		print '</tr>';
2177 2177
 
2178 2178
 		// Local Taxes
2179 2179
 		//TODO: Place into a function to control showing by country or study better option
2180 2180
 		if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1")
2181 2181
 		{
2182
-		    print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed",$mysoc->country_code).'</td><td>';
2183
-		    print yn($object->localtax1_assuj);
2184
-		    print '</td></tr><tr><td>'.$langs->transcountry("LocalTax2IsUsed",$mysoc->country_code).'</td><td>';
2185
-		    print yn($object->localtax2_assuj);
2186
-		    print '</td></tr>';
2187
-
2188
-		    if($object->localtax1_assuj=="1" && (! isOnlyOneLocalTax(1)))
2189
-		    {
2190
-		        print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2191
-		        print '<input type="hidden" name="action" value="set_localtax1">';
2192
-		        print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2193
-		        print '<tr><td>'.$langs->transcountry("TypeLocaltax1", $mysoc->country_code).' <a href="'.$_SERVER["PHP_SELF"].'?action=editRE&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</td>';
2194
-		        if($action == 'editRE')
2195
-		        {
2196
-		            print '<td align="left">';
2197
-		            $formcompany->select_localtax(1,$object->localtax1_value, "lt1");
2198
-		            print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2199
-		        }
2200
-		        else
2201
-		        {
2202
-		            print '<td>'.$object->localtax1_value.'</td>';
2203
-		        }
2204
-		        print '</tr></form>';
2205
-		    }
2206
-		    if($object->localtax2_assuj=="1" && (! isOnlyOneLocalTax(2)))
2207
-		    {
2208
-		        print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2209
-		        print '<input type="hidden" name="action" value="set_localtax2">';
2210
-		        print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2211
-		        print '<tr><td>'.$langs->transcountry("TypeLocaltax2", $mysoc->country_code).'<a href="'.$_SERVER["PHP_SELF"].'?action=editIRPF&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</td>';
2212
-		        if($action == 'editIRPF'){
2213
-		            print '<td align="left">';
2214
-		            $formcompany->select_localtax(2,$object->localtax2_value, "lt2");
2215
-		            print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2216
-		        }else{
2217
-		            print '<td>'.$object->localtax2_value.'</td>';
2218
-		        }
2219
-		        print '</tr></form>';
2220
-		    }
2182
+			print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed",$mysoc->country_code).'</td><td>';
2183
+			print yn($object->localtax1_assuj);
2184
+			print '</td></tr><tr><td>'.$langs->transcountry("LocalTax2IsUsed",$mysoc->country_code).'</td><td>';
2185
+			print yn($object->localtax2_assuj);
2186
+			print '</td></tr>';
2187
+
2188
+			if($object->localtax1_assuj=="1" && (! isOnlyOneLocalTax(1)))
2189
+			{
2190
+				print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2191
+				print '<input type="hidden" name="action" value="set_localtax1">';
2192
+				print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2193
+				print '<tr><td>'.$langs->transcountry("TypeLocaltax1", $mysoc->country_code).' <a href="'.$_SERVER["PHP_SELF"].'?action=editRE&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</td>';
2194
+				if($action == 'editRE')
2195
+				{
2196
+					print '<td align="left">';
2197
+					$formcompany->select_localtax(1,$object->localtax1_value, "lt1");
2198
+					print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2199
+				}
2200
+				else
2201
+				{
2202
+					print '<td>'.$object->localtax1_value.'</td>';
2203
+				}
2204
+				print '</tr></form>';
2205
+			}
2206
+			if($object->localtax2_assuj=="1" && (! isOnlyOneLocalTax(2)))
2207
+			{
2208
+				print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2209
+				print '<input type="hidden" name="action" value="set_localtax2">';
2210
+				print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2211
+				print '<tr><td>'.$langs->transcountry("TypeLocaltax2", $mysoc->country_code).'<a href="'.$_SERVER["PHP_SELF"].'?action=editIRPF&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</td>';
2212
+				if($action == 'editIRPF'){
2213
+					print '<td align="left">';
2214
+					$formcompany->select_localtax(2,$object->localtax2_value, "lt2");
2215
+					print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2216
+				}else{
2217
+					print '<td>'.$object->localtax2_value.'</td>';
2218
+				}
2219
+				print '</tr></form>';
2220
+			}
2221 2221
 		}
2222 2222
 		elseif($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj!="1")
2223 2223
 		{
2224
-		    print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed",$mysoc->country_code).'</td><td>';
2225
-		    print yn($object->localtax1_assuj);
2226
-		    print '</td></tr>';
2227
-		    if($object->localtax1_assuj=="1" && (! isOnlyOneLocalTax(1)))
2228
-		    {
2229
-		        print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2230
-		        print '<input type="hidden" name="action" value="set_localtax1">';
2231
-		        print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2232
-		        print '<tr><td> '.$langs->transcountry("TypeLocaltax1", $mysoc->country_code).'<a href="'.$_SERVER["PHP_SELF"].'?action=editRE&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</td>';
2233
-		        if($action == 'editRE'){
2234
-		            print '<td align="left">';
2235
-		            $formcompany->select_localtax(1,$object->localtax1_value, "lt1");
2236
-		            print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2237
-		        }else{
2238
-		            print '<td>'.$object->localtax1_value.'</td>';
2239
-		        }
2240
-		        print '</tr></form>';
2241
-
2242
-		    }
2224
+			print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed",$mysoc->country_code).'</td><td>';
2225
+			print yn($object->localtax1_assuj);
2226
+			print '</td></tr>';
2227
+			if($object->localtax1_assuj=="1" && (! isOnlyOneLocalTax(1)))
2228
+			{
2229
+				print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2230
+				print '<input type="hidden" name="action" value="set_localtax1">';
2231
+				print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2232
+				print '<tr><td> '.$langs->transcountry("TypeLocaltax1", $mysoc->country_code).'<a href="'.$_SERVER["PHP_SELF"].'?action=editRE&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</td>';
2233
+				if($action == 'editRE'){
2234
+					print '<td align="left">';
2235
+					$formcompany->select_localtax(1,$object->localtax1_value, "lt1");
2236
+					print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2237
+				}else{
2238
+					print '<td>'.$object->localtax1_value.'</td>';
2239
+				}
2240
+				print '</tr></form>';
2241
+
2242
+			}
2243 2243
 		}
2244 2244
 		elseif($mysoc->localtax2_assuj=="1" && $mysoc->localtax1_assuj!="1")
2245 2245
 		{
2246
-		    print '<tr><td>'.$langs->transcountry("LocalTax2IsUsed",$mysoc->country_code).'</td><td>';
2247
-		    print yn($object->localtax2_assuj);
2248
-		    print '</td></tr>';
2249
-		    if($object->localtax2_assuj=="1" && (! isOnlyOneLocalTax(2)))
2250
-		    {
2251
-
2252
-		        print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2253
-		        print '<input type="hidden" name="action" value="set_localtax2">';
2254
-		        print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2255
-		        print '<tr><td> '.$langs->transcountry("TypeLocaltax2", $mysoc->country_code).' <a href="'.$_SERVER["PHP_SELF"].'?action=editIRPF&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</td>';
2256
-		        if($action == 'editIRPF'){
2257
-		            print '<td align="left">';
2258
-		            $formcompany->select_localtax(2,$object->localtax2_value, "lt2");
2259
-		            print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2260
-		        }else{
2261
-		            print '<td>'.$object->localtax2_value.'</td>';
2262
-		        }
2263
-		        print '</tr></form>';
2264
-
2265
-		    }
2246
+			print '<tr><td>'.$langs->transcountry("LocalTax2IsUsed",$mysoc->country_code).'</td><td>';
2247
+			print yn($object->localtax2_assuj);
2248
+			print '</td></tr>';
2249
+			if($object->localtax2_assuj=="1" && (! isOnlyOneLocalTax(2)))
2250
+			{
2251
+
2252
+				print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2253
+				print '<input type="hidden" name="action" value="set_localtax2">';
2254
+				print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2255
+				print '<tr><td> '.$langs->transcountry("TypeLocaltax2", $mysoc->country_code).' <a href="'.$_SERVER["PHP_SELF"].'?action=editIRPF&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</td>';
2256
+				if($action == 'editIRPF'){
2257
+					print '<td align="left">';
2258
+					$formcompany->select_localtax(2,$object->localtax2_value, "lt2");
2259
+					print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2260
+				}else{
2261
+					print '<td>'.$object->localtax2_value.'</td>';
2262
+				}
2263
+				print '</tr></form>';
2264
+
2265
+			}
2266 2266
 		}
2267 2267
 		/*
2268 2268
 		 if ($mysoc->country_code=='ES' && $mysoc->localtax2_assuj!="1" && ! empty($conf->fournisseur->enabled) && $object->fournisseur==1)
@@ -2273,60 +2273,60 @@  discard block
 block discarded – undo
2273 2273
 		 }
2274 2274
 		 */
2275 2275
 
2276
-        // VAT Code
2277
-        print '<tr>';
2276
+		// VAT Code
2277
+		print '<tr>';
2278 2278
 		print '<td class="nowrap">'.$langs->trans('VATIntra').'</td><td>';
2279
-        if ($object->tva_intra)
2280
-        {
2281
-            $s='';
2282
-            $s.=$object->tva_intra;
2283
-            $s.='<input type="hidden" id="tva_intra" name="tva_intra" maxlength="20" value="'.$object->tva_intra.'">';
2284
-
2285
-            if (empty($conf->global->MAIN_DISABLEVATCHECK))
2286
-            {
2287
-                $s.=' &nbsp; ';
2288
-
2289
-                if ($conf->use_javascript_ajax)
2290
-                {
2291
-                    print "\n";
2292
-                    print '<script language="JavaScript" type="text/javascript">';
2293
-                    print "function CheckVAT(a) {\n";
2294
-                    print "newpopup('".DOL_URL_ROOT."/societe/checkvat/checkVatPopup.php?vatNumber='+a,'".dol_escape_js($langs->trans("VATIntraCheckableOnEUSite"))."',500,285);\n";
2295
-                    print "}\n";
2296
-                    print '</script>';
2297
-                    print "\n";
2298
-                    $s.='<a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT( $(\'#tva_intra\').val() );">'.$langs->trans("VATIntraCheck").'</a>';
2299
-                    $s = $form->textwithpicto($s,$langs->trans("VATIntraCheckDesc",$langs->trans("VATIntraCheck")),1);
2300
-                }
2301
-                else
2302
-                {
2303
-                    $s.='<a href="'.$langs->transcountry("VATIntraCheckURL",$object->country_id).'" class="hideonsmartphone" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"),'help').'</a>';
2304
-                }
2305
-            }
2306
-            print $s;
2307
-        }
2308
-        else
2309
-        {
2310
-            print '&nbsp;';
2311
-        }
2312
-        print '</td>';
2313
-        print '</tr>';
2314
-
2315
-        // Type + Staff
2316
-        $arr = $formcompany->typent_array(1);
2317
-        $object->typent= $arr[$object->typent_code];
2318
-        print '<tr><td>'.$langs->trans("ThirdPartyType").'</td><td>'.$object->typent.'</td>';
2319
-        print '<tr><td>'.$langs->trans("Staff").'</td><td>'.$object->effectif.'</td></tr>';
2320
-
2321
-        print '</table>';
2322
-
2323
-        print '</div>';
2324
-        print '<div class="fichehalfright"><div class="ficheaddleft">';
2325
-
2326
-        print '<div class="underbanner clearboth"></div>';
2327
-        print '<table class="border tableforfield" width="100%">';
2328
-
2329
-    	// Tags / categories
2279
+		if ($object->tva_intra)
2280
+		{
2281
+			$s='';
2282
+			$s.=$object->tva_intra;
2283
+			$s.='<input type="hidden" id="tva_intra" name="tva_intra" maxlength="20" value="'.$object->tva_intra.'">';
2284
+
2285
+			if (empty($conf->global->MAIN_DISABLEVATCHECK))
2286
+			{
2287
+				$s.=' &nbsp; ';
2288
+
2289
+				if ($conf->use_javascript_ajax)
2290
+				{
2291
+					print "\n";
2292
+					print '<script language="JavaScript" type="text/javascript">';
2293
+					print "function CheckVAT(a) {\n";
2294
+					print "newpopup('".DOL_URL_ROOT."/societe/checkvat/checkVatPopup.php?vatNumber='+a,'".dol_escape_js($langs->trans("VATIntraCheckableOnEUSite"))."',500,285);\n";
2295
+					print "}\n";
2296
+					print '</script>';
2297
+					print "\n";
2298
+					$s.='<a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT( $(\'#tva_intra\').val() );">'.$langs->trans("VATIntraCheck").'</a>';
2299
+					$s = $form->textwithpicto($s,$langs->trans("VATIntraCheckDesc",$langs->trans("VATIntraCheck")),1);
2300
+				}
2301
+				else
2302
+				{
2303
+					$s.='<a href="'.$langs->transcountry("VATIntraCheckURL",$object->country_id).'" class="hideonsmartphone" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"),'help').'</a>';
2304
+				}
2305
+			}
2306
+			print $s;
2307
+		}
2308
+		else
2309
+		{
2310
+			print '&nbsp;';
2311
+		}
2312
+		print '</td>';
2313
+		print '</tr>';
2314
+
2315
+		// Type + Staff
2316
+		$arr = $formcompany->typent_array(1);
2317
+		$object->typent= $arr[$object->typent_code];
2318
+		print '<tr><td>'.$langs->trans("ThirdPartyType").'</td><td>'.$object->typent.'</td>';
2319
+		print '<tr><td>'.$langs->trans("Staff").'</td><td>'.$object->effectif.'</td></tr>';
2320
+
2321
+		print '</table>';
2322
+
2323
+		print '</div>';
2324
+		print '<div class="fichehalfright"><div class="ficheaddleft">';
2325
+
2326
+		print '<div class="underbanner clearboth"></div>';
2327
+		print '<table class="border tableforfield" width="100%">';
2328
+
2329
+		// Tags / categories
2330 2330
 		if (! empty($conf->categorie->enabled)  && ! empty($user->rights->categorie->lire))
2331 2331
 		{
2332 2332
 			// Customer
@@ -2346,40 +2346,40 @@  discard block
 block discarded – undo
2346 2346
 			}
2347 2347
 		}
2348 2348
 
2349
-        // Legal
2350
-        print '<tr><td class="titlefield">'.$langs->trans('JuridicalStatus').'</td><td>'.$object->forme_juridique.'</td></tr>';
2349
+		// Legal
2350
+		print '<tr><td class="titlefield">'.$langs->trans('JuridicalStatus').'</td><td>'.$object->forme_juridique.'</td></tr>';
2351 2351
 
2352
-        // Capital
2353
-        print '<tr><td>'.$langs->trans('Capital').'</td><td>';
2354
-        if ($object->capital) print price($object->capital,'',$langs,0,-1,-1, $conf->currency);
2355
-        else print '&nbsp;';
2356
-        print '</td></tr>';
2352
+		// Capital
2353
+		print '<tr><td>'.$langs->trans('Capital').'</td><td>';
2354
+		if ($object->capital) print price($object->capital,'',$langs,0,-1,-1, $conf->currency);
2355
+		else print '&nbsp;';
2356
+		print '</td></tr>';
2357 2357
 
2358
-        // Default language
2359
-        if (! empty($conf->global->MAIN_MULTILANGS))
2360
-        {
2361
-            require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
2362
-            print '<tr><td>'.$langs->trans("DefaultLang").'</td><td>';
2363
-            //$s=picto_from_langcode($object->default_lang);
2364
-            //print ($s?$s.' ':'');
2365
-            $langs->load("languages");
2366
-            $labellang = ($object->default_lang?$langs->trans('Language_'.$object->default_lang):'');
2367
-            print $labellang;
2368
-            print '</td></tr>';
2369
-        }
2358
+		// Default language
2359
+		if (! empty($conf->global->MAIN_MULTILANGS))
2360
+		{
2361
+			require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
2362
+			print '<tr><td>'.$langs->trans("DefaultLang").'</td><td>';
2363
+			//$s=picto_from_langcode($object->default_lang);
2364
+			//print ($s?$s.' ':'');
2365
+			$langs->load("languages");
2366
+			$labellang = ($object->default_lang?$langs->trans('Language_'.$object->default_lang):'');
2367
+			print $labellang;
2368
+			print '</td></tr>';
2369
+		}
2370 2370
 
2371 2371
 		// Incoterms
2372 2372
 		if (!empty($conf->incoterm->enabled))
2373 2373
 		{
2374 2374
 			print '<tr><td>';
2375
-            print '<table width="100%" class="nobordernopadding"><tr><td>';
2376
-            print $langs->trans('IncotermLabel');
2377
-            print '<td><td align="right">';
2378
-            if ($user->rights->societe->creer) print '<a href="'.DOL_URL_ROOT.'/societe/card.php?socid='.$object->id.'&action=editincoterm">'.img_edit('',1).'</a>';
2379
-            else print '&nbsp;';
2380
-            print '</td></tr></table>';
2381
-            print '</td>';
2382
-            print '<td colspan="3">';
2375
+			print '<table width="100%" class="nobordernopadding"><tr><td>';
2376
+			print $langs->trans('IncotermLabel');
2377
+			print '<td><td align="right">';
2378
+			if ($user->rights->societe->creer) print '<a href="'.DOL_URL_ROOT.'/societe/card.php?socid='.$object->id.'&action=editincoterm">'.img_edit('',1).'</a>';
2379
+			else print '&nbsp;';
2380
+			print '</td></tr></table>';
2381
+			print '</td>';
2382
+			print '<td colspan="3">';
2383 2383
 			if ($action != 'editincoterm')
2384 2384
 			{
2385 2385
 				print $form->textwithpicto($object->display_incoterms(), $object->libelle_incoterms, 1);
@@ -2388,7 +2388,7 @@  discard block
 block discarded – undo
2388 2388
 			{
2389 2389
 				print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''), $_SERVER['PHP_SELF'].'?socid='.$object->id);
2390 2390
 			}
2391
-            print '</td></tr>';
2391
+			print '</td></tr>';
2392 2392
 		}
2393 2393
 
2394 2394
 		// Multicurrency
@@ -2396,8 +2396,8 @@  discard block
 block discarded – undo
2396 2396
 		{
2397 2397
 			print '<tr>';
2398 2398
 			print '<td>'.fieldLabel('Currency','multicurrency_code').'</td>';
2399
-	        print '<td>';
2400
-	        print !empty($object->multicurrency_code) ? currency_name($object->multicurrency_code,1) : '';
2399
+			print '<td>';
2400
+			print !empty($object->multicurrency_code) ? currency_name($object->multicurrency_code,1) : '';
2401 2401
 			print '</td></tr>';
2402 2402
 		}
2403 2403
 
@@ -2405,74 +2405,74 @@  discard block
 block discarded – undo
2405 2405
 		$parameters=array('socid'=>$socid, 'colspan' => ' colspan="3"', 'colspanvalue' => '3');
2406 2406
 		include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
2407 2407
 
2408
-        // Parent company
2409
-        if (empty($conf->global->SOCIETE_DISABLE_PARENTCOMPANY))
2410
-        {
2411
-        	// Payment term
2412
-        	print '<tr><td>';
2413
-        	print '<table class="nobordernopadding" width="100%"><tr><td>';
2414
-        	print $langs->trans('ParentCompany');
2415
-        	print '</td>';
2416
-        	if ($action != 'editparentcompany') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editparentcompany&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</a></td>';
2417
-        	print '</tr></table>';
2418
-        	print '</td><td colspan="3">';
2419
-        	if ($action == 'editparentcompany')
2420
-        	{
2421
-        		$form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->parent,'editparentcompany','s.rowid <> '.$object->id,1);
2422
-        	}
2423
-        	else
2424
-        	{
2425
-        		$form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->parent,'none','s.rowid <> '.$object->id,1);
2426
-        	}
2427
-        	print '</td>';
2428
-        	print '</tr>';
2429
-        }
2430
-
2431
-        // Sales representative
2432
-        include DOL_DOCUMENT_ROOT.'/societe/tpl/linesalesrepresentative.tpl.php';
2433
-
2434
-        // Module Adherent
2435
-        if (! empty($conf->adherent->enabled))
2436
-        {
2437
-            $langs->load("members");
2438
-            print '<tr><td>'.$langs->trans("LinkedToDolibarrMember").'</td>';
2439
-            print '<td colspan="3">';
2440
-            $adh=new Adherent($db);
2441
-            $result=$adh->fetch('','',$object->id);
2442
-            if ($result > 0)
2443
-            {
2444
-                $adh->ref=$adh->getFullName($langs);
2445
-                print $adh->getNomUrl(1);
2446
-            }
2447
-            else
2448
-            {
2449
-                print '<span class="opacitymedium">'.$langs->trans("ThirdpartyNotLinkedToMember").'</span>';
2450
-            }
2451
-            print '</td>';
2452
-            print "</tr>\n";
2453
-        }
2454
-
2455
-        // Webservices url/key
2456
-        if (!empty($conf->syncsupplierwebservices->enabled)) {
2457
-            print '<tr><td>'.$langs->trans("WebServiceURL").'</td><td>'.dol_print_url($object->webservices_url).'</td>';
2458
-            print '<td class="nowrap">'.$langs->trans('WebServiceKey').'</td><td>'.$object->webservices_key.'</td></tr>';
2459
-        }
2460
-
2461
-        print '</table>';
2408
+		// Parent company
2409
+		if (empty($conf->global->SOCIETE_DISABLE_PARENTCOMPANY))
2410
+		{
2411
+			// Payment term
2412
+			print '<tr><td>';
2413
+			print '<table class="nobordernopadding" width="100%"><tr><td>';
2414
+			print $langs->trans('ParentCompany');
2415
+			print '</td>';
2416
+			if ($action != 'editparentcompany') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editparentcompany&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</a></td>';
2417
+			print '</tr></table>';
2418
+			print '</td><td colspan="3">';
2419
+			if ($action == 'editparentcompany')
2420
+			{
2421
+				$form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->parent,'editparentcompany','s.rowid <> '.$object->id,1);
2422
+			}
2423
+			else
2424
+			{
2425
+				$form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->parent,'none','s.rowid <> '.$object->id,1);
2426
+			}
2427
+			print '</td>';
2428
+			print '</tr>';
2429
+		}
2430
+
2431
+		// Sales representative
2432
+		include DOL_DOCUMENT_ROOT.'/societe/tpl/linesalesrepresentative.tpl.php';
2433
+
2434
+		// Module Adherent
2435
+		if (! empty($conf->adherent->enabled))
2436
+		{
2437
+			$langs->load("members");
2438
+			print '<tr><td>'.$langs->trans("LinkedToDolibarrMember").'</td>';
2439
+			print '<td colspan="3">';
2440
+			$adh=new Adherent($db);
2441
+			$result=$adh->fetch('','',$object->id);
2442
+			if ($result > 0)
2443
+			{
2444
+				$adh->ref=$adh->getFullName($langs);
2445
+				print $adh->getNomUrl(1);
2446
+			}
2447
+			else
2448
+			{
2449
+				print '<span class="opacitymedium">'.$langs->trans("ThirdpartyNotLinkedToMember").'</span>';
2450
+			}
2451
+			print '</td>';
2452
+			print "</tr>\n";
2453
+		}
2454
+
2455
+		// Webservices url/key
2456
+		if (!empty($conf->syncsupplierwebservices->enabled)) {
2457
+			print '<tr><td>'.$langs->trans("WebServiceURL").'</td><td>'.dol_print_url($object->webservices_url).'</td>';
2458
+			print '<td class="nowrap">'.$langs->trans('WebServiceKey').'</td><td>'.$object->webservices_key.'</td></tr>';
2459
+		}
2460
+
2461
+		print '</table>';
2462 2462
 		print '</div>';
2463 2463
 
2464
-        print '</div></div>';
2465
-        print '<div style="clear:both"></div>';
2464
+		print '</div></div>';
2465
+		print '<div style="clear:both"></div>';
2466 2466
 
2467
-        dol_fiche_end();
2467
+		dol_fiche_end();
2468 2468
 
2469 2469
 
2470
-        /*
2470
+		/*
2471 2471
          *  Actions
2472 2472
          */
2473
-        if ($action != 'presend')
2474
-        {
2475
-	        print '<div class="tabsAction">'."\n";
2473
+		if ($action != 'presend')
2474
+		{
2475
+			print '<div class="tabsAction">'."\n";
2476 2476
 
2477 2477
 			$parameters=array();
2478 2478
 			$reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
@@ -2489,44 +2489,44 @@  discard block
 block discarded – undo
2489 2489
 					}
2490 2490
 				}
2491 2491
 
2492
-		        if (! empty($object->email) || $at_least_one_email_contact)
2493
-		        {
2494
-		        	$langs->load("mails");
2495
-		        	print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'&amp;action=presend&amp;mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a></div>';
2496
-		        }
2497
-		        else
2492
+				if (! empty($object->email) || $at_least_one_email_contact)
2493
+				{
2494
+					$langs->load("mails");
2495
+					print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'&amp;action=presend&amp;mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a></div>';
2496
+				}
2497
+				else
2498
+				{
2499
+					$langs->load("mails");
2500
+			   		print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NoEMail")).'">'.$langs->trans('SendMail').'</a></div>';
2501
+				}
2502
+
2503
+				if ($user->rights->societe->creer)
2504
+				{
2505
+					print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&amp;action=edit">'.$langs->trans("Modify").'</a></div>'."\n";
2506
+				}
2507
+
2508
+				if ($user->rights->societe->supprimer)
2509
+				{
2510
+					print '<div class="inline-block divButAction"><a class="butActionDelete" href="card.php?action=merge&socid='.$object->id.'" title="'.dol_escape_htmltag($langs->trans("MergeThirdparties")).'">'.$langs->trans('Merge').'</a></div>';
2511
+				}
2512
+
2513
+				if ($user->rights->societe->supprimer)
2498 2514
 				{
2499
-		        	$langs->load("mails");
2500
-		       		print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NoEMail")).'">'.$langs->trans('SendMail').'</a></div>';
2501
-		        }
2502
-
2503
-		        if ($user->rights->societe->creer)
2504
-		        {
2505
-		            print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&amp;action=edit">'.$langs->trans("Modify").'</a></div>'."\n";
2506
-		        }
2507
-
2508
-		        if ($user->rights->societe->supprimer)
2509
-		        {
2510
-		        	print '<div class="inline-block divButAction"><a class="butActionDelete" href="card.php?action=merge&socid='.$object->id.'" title="'.dol_escape_htmltag($langs->trans("MergeThirdparties")).'">'.$langs->trans('Merge').'</a></div>';
2511
-		        }
2512
-
2513
-		        if ($user->rights->societe->supprimer)
2514
-		        {
2515
-		            if ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile))	// We can't use preloaded confirm form with jmobile
2516
-		            {
2517
-		                print '<div class="inline-block divButAction"><span id="action-delete" class="butActionDelete">'.$langs->trans('Delete').'</span></div>'."\n";
2518
-		            }
2519
-		            else
2515
+					if ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile))	// We can't use preloaded confirm form with jmobile
2516
+					{
2517
+						print '<div class="inline-block divButAction"><span id="action-delete" class="butActionDelete">'.$langs->trans('Delete').'</span></div>'."\n";
2518
+					}
2519
+					else
2520 2520
 					{
2521
-		                print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&amp;action=delete">'.$langs->trans('Delete').'</a></div>'."\n";
2522
-		            }
2523
-		        }
2521
+						print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&amp;action=delete">'.$langs->trans('Delete').'</a></div>'."\n";
2522
+					}
2523
+				}
2524 2524
 			}
2525 2525
 
2526
-	        print '</div>'."\n";
2527
-        }
2526
+			print '</div>'."\n";
2527
+		}
2528 2528
 
2529
-        //Select mail models is same action as presend
2529
+		//Select mail models is same action as presend
2530 2530
 		if (GETPOST('modelselected')) {
2531 2531
 			$action = 'presend';
2532 2532
 		}
@@ -2535,20 +2535,20 @@  discard block
 block discarded – undo
2535 2535
 		{
2536 2536
 			print '<div class="fichecenter"><div class="fichehalfleft">';
2537 2537
 
2538
-	        if (empty($conf->global->SOCIETE_DISABLE_BUILDDOC))
2539
-	        {
2538
+			if (empty($conf->global->SOCIETE_DISABLE_BUILDDOC))
2539
+			{
2540 2540
 				print '<a name="builddoc"></a>'; // ancre
2541 2541
 
2542
-	            /*
2542
+				/*
2543 2543
 	             * Documents generes
2544 2544
 	             */
2545
-	            $filedir=$conf->societe->multidir_output[$object->entity].'/'.$object->id;
2546
-	            $urlsource=$_SERVER["PHP_SELF"]."?socid=".$object->id;
2547
-	            $genallowed=$user->rights->societe->lire;
2548
-	            $delallowed=$user->rights->societe->creer;
2545
+				$filedir=$conf->societe->multidir_output[$object->entity].'/'.$object->id;
2546
+				$urlsource=$_SERVER["PHP_SELF"]."?socid=".$object->id;
2547
+				$genallowed=$user->rights->societe->lire;
2548
+				$delallowed=$user->rights->societe->creer;
2549 2549
 
2550
-	            print $formfile->showdocuments('company', $object->id, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 0, 0, 0, 28, 0, 'entity='.$object->entity, 0, '', $object->default_lang);
2551
-	        }
2550
+				print $formfile->showdocuments('company', $object->id, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 0, 0, 0, 28, 0, 'entity='.$object->entity, 0, '', $object->default_lang);
2551
+			}
2552 2552
 
2553 2553
 			// Subsidiaries list
2554 2554
 			if (empty($conf->global->SOCIETE_DISABLE_SUBSIDIARIES))
@@ -2595,7 +2595,7 @@  discard block
 block discarded – undo
2595 2595
 
2596 2596
 		include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
2597 2597
 
2598
-    }
2598
+	}
2599 2599
 }
2600 2600
 
2601 2601
 
Please login to merge, or discard this patch.
Spacing   +523 added lines, -523 removed lines patch added patch discarded remove patch
@@ -42,38 +42,38 @@  discard block
 block discarded – undo
42 42
 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
43 43
 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
44 44
 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
45
-if (! empty($conf->adherent->enabled)) require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
45
+if (!empty($conf->adherent->enabled)) require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
46 46
 
47 47
 $langs->load("companies");
48 48
 $langs->load("commercial");
49 49
 $langs->load("bills");
50 50
 $langs->load("banks");
51 51
 $langs->load("users");
52
-if (! empty($conf->categorie->enabled)) $langs->load("categories");
53
-if (! empty($conf->incoterm->enabled)) $langs->load("incoterm");
54
-if (! empty($conf->notification->enabled)) $langs->load("mails");
52
+if (!empty($conf->categorie->enabled)) $langs->load("categories");
53
+if (!empty($conf->incoterm->enabled)) $langs->load("incoterm");
54
+if (!empty($conf->notification->enabled)) $langs->load("mails");
55 55
 
56
-$mesg=''; $error=0; $errors=array();
56
+$mesg = ''; $error = 0; $errors = array();
57 57
 
58
-$action		= (GETPOST('action','aZ09') ? GETPOST('action','aZ09') : 'view');
59
-$cancel		= GETPOST('cancel','alpha');
60
-$backtopage	= GETPOST('backtopage','alpha');
61
-$confirm		= GETPOST('confirm');
58
+$action		= (GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view');
59
+$cancel		= GETPOST('cancel', 'alpha');
60
+$backtopage = GETPOST('backtopage', 'alpha');
61
+$confirm = GETPOST('confirm');
62 62
 
63
-$socid		= GETPOST('socid','int')?GETPOST('socid','int'):GETPOST('id','int');
64
-if ($user->societe_id) $socid=$user->societe_id;
65
-if (empty($socid) && $action == 'view') $action='create';
63
+$socid = GETPOST('socid', 'int') ?GETPOST('socid', 'int') : GETPOST('id', 'int');
64
+if ($user->societe_id) $socid = $user->societe_id;
65
+if (empty($socid) && $action == 'view') $action = 'create';
66 66
 
67 67
 $object = new Societe($db);
68 68
 $extrafields = new ExtraFields($db);
69 69
 
70 70
 // fetch optionals attributes and labels
71
-$extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
71
+$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
72 72
 
73 73
 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
74
-$hookmanager->initHooks(array('thirdpartycard','globalcard'));
74
+$hookmanager->initHooks(array('thirdpartycard', 'globalcard'));
75 75
 
76
-if ($action == 'view' && $object->fetch($socid)<=0)
76
+if ($action == 'view' && $object->fetch($socid) <= 0)
77 77
 {
78 78
 	$langs->load("errors");
79 79
 	print($langs->trans('ErrorRecordNotFound'));
@@ -82,9 +82,9 @@  discard block
 block discarded – undo
82 82
 
83 83
 // Get object canvas (By default, this is not defined, so standard usage of dolibarr)
84 84
 $object->getCanvas($socid);
85
-$canvas = $object->canvas?$object->canvas:GETPOST("canvas");
86
-$objcanvas=null;
87
-if (! empty($canvas))
85
+$canvas = $object->canvas ? $object->canvas : GETPOST("canvas");
86
+$objcanvas = null;
87
+if (!empty($canvas))
88 88
 {
89 89
     require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
90 90
     $objcanvas = new Canvas($db, $action);
@@ -99,16 +99,16 @@  discard block
 block discarded – undo
99 99
  * Actions
100 100
  */
101 101
 
102
-$parameters=array('id'=>$socid, 'objcanvas'=>$objcanvas);
103
-$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
102
+$parameters = array('id'=>$socid, 'objcanvas'=>$objcanvas);
103
+$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
104 104
 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
105 105
 
106 106
 if (empty($reshook))
107 107
 {
108 108
     if ($cancel)
109 109
     {
110
-        $action='';
111
-        if (! empty($backtopage))
110
+        $action = '';
111
+        if (!empty($backtopage))
112 112
         {
113 113
             header("Location: ".$backtopage);
114 114
             exit;
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 				// Recopy some data
147 147
 				$object->client = $object->client | $soc_origin->client;
148 148
 				$object->fournisseur = $object->fournisseur | $soc_origin->fournisseur;
149
-				$listofproperties=array(
149
+				$listofproperties = array(
150 150
 					'address', 'zip', 'town', 'state_id', 'country_id', 'phone', 'phone_pro', 'fax', 'email', 'skype', 'url', 'barcode',
151 151
 					'idprof1', 'idprof2', 'idprof3', 'idprof4', 'idprof5', 'idprof6',
152 152
 					'tva_intra', 'effectif_id', 'forme_juridique', 'remise_percent', 'mode_reglement_supplier_id', 'cond_reglement_supplier_id', 'name_bis',
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 				}
161 161
 
162 162
 				// Concat some data
163
-				$listofproperties=array(
163
+				$listofproperties = array(
164 164
 				    'note_public', 'note_private'
165 165
 				);
166 166
 				foreach ($listofproperties as $property)
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
 				}
205 205
 
206 206
 				// Move links
207
-				if (! $error)
207
+				if (!$error)
208 208
 				{
209 209
 					$objects = array(
210 210
 						'Adherent' => '/adherents/class/adherent.class.php',
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
 				}
245 245
 
246 246
 				// External modules should update their ones too
247
-				if (! $error)
247
+				if (!$error)
248 248
 				{
249 249
 					$reshook = $hookmanager->executeHooks('replaceThirdparty', array(
250 250
 						'soc_origin' => $soc_origin->id,
@@ -259,12 +259,12 @@  discard block
 block discarded – undo
259 259
 				}
260 260
 
261 261
 
262
-				if (! $error)
262
+				if (!$error)
263 263
 				{
264
-					$object->context=array('merge'=>1, 'mergefromid'=>$soc_origin->id);
264
+					$object->context = array('merge'=>1, 'mergefromid'=>$soc_origin->id);
265 265
 
266 266
 					// Call trigger
267
-					$result=$object->call_trigger('COMPANY_MODIFY',$user);
267
+					$result = $object->call_trigger('COMPANY_MODIFY', $user);
268 268
 					if ($result < 0)
269 269
 					{
270 270
 						setEventMessages($object->error, $object->errors, 'errors');
@@ -300,28 +300,28 @@  discard block
 block discarded – undo
300 300
     if (GETPOST('getcustomercode'))
301 301
     {
302 302
         // We defined value code_client
303
-        $_POST["code_client"]="Acompleter";
303
+        $_POST["code_client"] = "Acompleter";
304 304
     }
305 305
 
306 306
     if (GETPOST('getsuppliercode'))
307 307
     {
308 308
         // We defined value code_fournisseur
309
-        $_POST["code_fournisseur"]="Acompleter";
309
+        $_POST["code_fournisseur"] = "Acompleter";
310 310
     }
311 311
 
312
-    if($action=='set_localtax1')
312
+    if ($action == 'set_localtax1')
313 313
     {
314 314
     	//obtidre selected del combobox
315
-    	$value=GETPOST('lt1');
315
+    	$value = GETPOST('lt1');
316 316
     	$object->fetch($socid);
317
-    	$res=$object->setValueFrom('localtax1_value', $value, '', null, 'text', '', $user, 'COMPANY_MODIFY');
317
+    	$res = $object->setValueFrom('localtax1_value', $value, '', null, 'text', '', $user, 'COMPANY_MODIFY');
318 318
     }
319
-    if($action=='set_localtax2')
319
+    if ($action == 'set_localtax2')
320 320
     {
321 321
     	//obtidre selected del combobox
322
-    	$value=GETPOST('lt2');
322
+    	$value = GETPOST('lt2');
323 323
     	$object->fetch($socid);
324
-    	$res=$object->setValueFrom('localtax2_value', $value, '', null, 'text', '', $user, 'COMPANY_MODIFY');
324
+    	$res = $object->setValueFrom('localtax2_value', $value, '', null, 'text', '', $user, 'COMPANY_MODIFY');
325 325
     }
326 326
 
327 327
     if ($action == 'update_extras') {
@@ -331,10 +331,10 @@  discard block
 block discarded – undo
331 331
 
332 332
         // Fill array 'array_options' with data from update form
333 333
         $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
334
-        $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute','none'));
334
+        $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute', 'none'));
335 335
         if ($ret < 0) $error++;
336 336
 
337
-        if (! $error)
337
+        if (!$error)
338 338
         {
339 339
             $result = $object->insertExtraFields('COMPANY_MODIFY');
340 340
    			if ($result < 0)
@@ -348,12 +348,12 @@  discard block
 block discarded – undo
348 348
     }
349 349
 
350 350
     // Add new or update third party
351
-    if ((! GETPOST('getcustomercode') && ! GETPOST('getsuppliercode'))
351
+    if ((!GETPOST('getcustomercode') && !GETPOST('getsuppliercode'))
352 352
     && ($action == 'add' || $action == 'update') && $user->rights->societe->creer)
353 353
     {
354 354
         require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
355 355
 
356
-        if (! GETPOST('name'))
356
+        if (!GETPOST('name'))
357 357
         {
358 358
             setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ThirdPartyName")), null, 'errors');
359 359
             $error++;
@@ -370,39 +370,39 @@  discard block
 block discarded – undo
370 370
 
371 371
         }
372 372
 
373
-        if (! $error)
373
+        if (!$error)
374 374
         {
375 375
         		if ($action == 'update')
376 376
 	        {
377
-	        		$ret=$object->fetch($socid);
377
+	        		$ret = $object->fetch($socid);
378 378
 				$object->oldcopy = clone $object;
379 379
 	        }
380
-			else $object->canvas=$canvas;
380
+			else $object->canvas = $canvas;
381 381
 
382 382
 	        if (GETPOST("private") == 1)	// Ask to create a contact
383 383
 	        {
384 384
 	            $object->particulier			= GETPOST("private");
385 385
 
386
-	            $object->name				= dolGetFirstLastname(GETPOST('firstname','alpha'),GETPOST('name','alpha'));
387
-	            $object->civility_id			= GETPOST('civility_id');	// Note: civility id is a code, not an int
386
+	            $object->name = dolGetFirstLastname(GETPOST('firstname', 'alpha'), GETPOST('name', 'alpha'));
387
+	            $object->civility_id			= GETPOST('civility_id'); // Note: civility id is a code, not an int
388 388
 	            // Add non official properties
389
-	            $object->name_bis			= GETPOST('name','alpha');
390
-	            $object->firstname			= GETPOST('firstname','alpha');
389
+	            $object->name_bis = GETPOST('name', 'alpha');
390
+	            $object->firstname = GETPOST('firstname', 'alpha');
391 391
 	        }
392 392
 	        else
393 393
 	        {
394
-	            $object->name				= GETPOST('name', 'alpha');
394
+	            $object->name = GETPOST('name', 'alpha');
395 395
 	        }
396
-	        $object->entity					= (GETPOSTISSET('entity')?GETPOST('entity', 'int'):$conf->entity);
397
-	        $object->name_alias				= GETPOST('name_alias');
398
-	        $object->address					= GETPOST('address');
396
+	        $object->entity = (GETPOSTISSET('entity') ?GETPOST('entity', 'int') : $conf->entity);
397
+	        $object->name_alias = GETPOST('name_alias');
398
+	        $object->address = GETPOST('address');
399 399
 	        $object->zip						= GETPOST('zipcode', 'alpha');
400 400
 	        $object->town					= GETPOST('town', 'alpha');
401
-	        $object->country_id				= GETPOST('country_id', 'int');
402
-	        $object->state_id				= GETPOST('state_id', 'int');
401
+	        $object->country_id = GETPOST('country_id', 'int');
402
+	        $object->state_id = GETPOST('state_id', 'int');
403 403
 	        $object->skype					= GETPOST('skype', 'alpha');
404 404
 	        $object->phone					= GETPOST('phone', 'alpha');
405
-	        $object->fax						= GETPOST('fax','alpha');
405
+	        $object->fax						= GETPOST('fax', 'alpha');
406 406
 	        $object->email					= trim(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL));
407 407
 	        $object->url						= trim(GETPOST('url', 'custom', 0, FILTER_SANITIZE_URL));
408 408
 	        $object->idprof1					= trim(GETPOST('idprof1', 'alpha'));
@@ -413,13 +413,13 @@  discard block
 block discarded – undo
413 413
 	        $object->idprof6					= trim(GETPOST('idprof6', 'alpha'));
414 414
 	        $object->prefix_comm				= GETPOST('prefix_comm', 'alpha');
415 415
 	        $object->code_client				= GETPOST('code_client', 'alpha');
416
-	        $object->code_fournisseur		= GETPOST('code_fournisseur', 'alpha');
416
+	        $object->code_fournisseur = GETPOST('code_fournisseur', 'alpha');
417 417
 	        $object->capital					= GETPOST('capital', 'alpha');
418 418
 	        $object->barcode					= GETPOST('barcode', 'alpha');
419 419
 
420 420
 	        $object->tva_intra				= GETPOST('tva_intra', 'alpha');
421 421
 	        $object->tva_assuj				= GETPOST('assujtva_value', 'alpha');
422
-	        $object->status					= GETPOST('status', 'alpha');
422
+	        $object->status = GETPOST('status', 'alpha');
423 423
 
424 424
 	        // Local Taxes
425 425
 	        $object->localtax1_assuj			= GETPOST('localtax1assuj_value', 'alpha');
@@ -428,16 +428,16 @@  discard block
 block discarded – undo
428 428
 	        $object->localtax1_value			= GETPOST('lt1', 'alpha');
429 429
 	        $object->localtax2_value			= GETPOST('lt2', 'alpha');
430 430
 
431
-	        $object->forme_juridique_code	= GETPOST('forme_juridique_code', 'int');
431
+	        $object->forme_juridique_code = GETPOST('forme_juridique_code', 'int');
432 432
 	        $object->effectif_id				= GETPOST('effectif_id', 'int');
433
-	        $object->typent_id				= GETPOST('typent_id','int');
433
+	        $object->typent_id = GETPOST('typent_id', 'int');
434 434
 
435
-	        $object->typent_code				= dol_getIdFromCode($db, $object->typent_id, 'c_typent', 'id', 'code');	// Force typent_code too so check in verify() will be done on new type
435
+	        $object->typent_code				= dol_getIdFromCode($db, $object->typent_id, 'c_typent', 'id', 'code'); // Force typent_code too so check in verify() will be done on new type
436 436
 
437
-	        $object->client					= GETPOST('client', 'int');
437
+	        $object->client = GETPOST('client', 'int');
438 438
 	        $object->fournisseur				= GETPOST('fournisseur', 'int');
439 439
 
440
-	        $object->commercial_id			= GETPOST('commercial_id', 'int');
440
+	        $object->commercial_id = GETPOST('commercial_id', 'int');
441 441
 	        $object->default_lang			= GETPOST('default_lang');
442 442
 
443 443
 	        // Webservices url/key
@@ -447,8 +447,8 @@  discard block
 block discarded – undo
447 447
 			// Incoterms
448 448
 			if (!empty($conf->incoterm->enabled))
449 449
 			{
450
-				$object->fk_incoterms		= GETPOST('incoterm_id', 'int');
451
-				$object->location_incoterms	= GETPOST('location_incoterms', 'alpha');
450
+				$object->fk_incoterms = GETPOST('incoterm_id', 'int');
451
+				$object->location_incoterms = GETPOST('location_incoterms', 'alpha');
452 452
 			}
453 453
 
454 454
 			// Multicurrency
@@ -458,58 +458,58 @@  discard block
 block discarded – undo
458 458
 			}
459 459
 
460 460
 	        // Fill array 'array_options' with data from add form
461
-	        $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
461
+	        $ret = $extrafields->setOptionalsFromPost($extralabels, $object);
462 462
 			if ($ret < 0)
463 463
 			{
464 464
 				 $error++;
465 465
 			}
466 466
 
467 467
 	        if (GETPOST('deletephoto')) $object->logo = '';
468
-	        else if (! empty($_FILES['photo']['name'])) $object->logo = dol_sanitizeFileName($_FILES['photo']['name']);
468
+	        else if (!empty($_FILES['photo']['name'])) $object->logo = dol_sanitizeFileName($_FILES['photo']['name']);
469 469
 
470 470
 	        // Check parameters
471
-	        if (! GETPOST('cancel','alpha'))
471
+	        if (!GETPOST('cancel', 'alpha'))
472 472
 	        {
473
-	            if (! empty($object->email) && ! isValidEMail($object->email))
473
+	            if (!empty($object->email) && !isValidEMail($object->email))
474 474
 	            {
475 475
 	                $langs->load("errors");
476 476
 	                $error++;
477
-	                setEventMessages('', $langs->trans("ErrorBadEMail",$object->email), 'errors');
477
+	                setEventMessages('', $langs->trans("ErrorBadEMail", $object->email), 'errors');
478 478
 	            }
479
-	            if (! empty($object->url) && ! isValidUrl($object->url))
479
+	            if (!empty($object->url) && !isValidUrl($object->url))
480 480
 	            {
481 481
 	                $langs->load("errors");
482
-	                setEventMessages('', $langs->trans("ErrorBadUrl",$object->url), 'errors');
482
+	                setEventMessages('', $langs->trans("ErrorBadUrl", $object->url), 'errors');
483 483
 	            }
484
-	            if ($object->fournisseur && ! $conf->fournisseur->enabled)
484
+	            if ($object->fournisseur && !$conf->fournisseur->enabled)
485 485
 	            {
486 486
 	                $langs->load("errors");
487 487
 	                setEventMessages('', $langs->trans("ErrorSupplierModuleNotEnabled"), 'errors');
488 488
 	            }
489
-	            if (! empty($object->webservices_url)) {
489
+	            if (!empty($object->webservices_url)) {
490 490
 	                //Check if has transport, without any the soap client will give error
491 491
 	                if (strpos($object->webservices_url, "http") === false)
492 492
 	                {
493 493
 	                    $object->webservices_url = "http://".$object->webservices_url;
494 494
 	                }
495
-	                if (! isValidUrl($object->webservices_url)) {
495
+	                if (!isValidUrl($object->webservices_url)) {
496 496
 	                    $langs->load("errors");
497
-	                    $error++; $errors[] = $langs->trans("ErrorBadUrl",$object->webservices_url);
497
+	                    $error++; $errors[] = $langs->trans("ErrorBadUrl", $object->webservices_url);
498 498
 	                }
499 499
 	            }
500 500
 
501 501
 	            // We set country_id, country_code and country for the selected country
502
-	            $object->country_id=GETPOST('country_id')!=''?GETPOST('country_id'):$mysoc->country_id;
502
+	            $object->country_id = GETPOST('country_id') != '' ?GETPOST('country_id') : $mysoc->country_id;
503 503
 	            if ($object->country_id)
504 504
 	            {
505
-	            	$tmparray=getCountry($object->country_id,'all');
506
-	            	$object->country_code=$tmparray['code'];
507
-	            	$object->country=$tmparray['label'];
505
+	            	$tmparray = getCountry($object->country_id, 'all');
506
+	            	$object->country_code = $tmparray['code'];
507
+	            	$object->country = $tmparray['label'];
508 508
 	            }
509 509
 	        }
510 510
         }
511 511
 
512
-        if (! $error)
512
+        if (!$error)
513 513
         {
514 514
             if ($action == 'add')
515 515
             {
@@ -517,8 +517,8 @@  discard block
 block discarded – undo
517 517
 
518 518
                 $db->begin();
519 519
 
520
-                if (empty($object->client))      $object->code_client='';
521
-                if (empty($object->fournisseur)) $object->code_fournisseur='';
520
+                if (empty($object->client))      $object->code_client = '';
521
+                if (empty($object->fournisseur)) $object->code_fournisseur = '';
522 522
 
523 523
                 $result = $object->create($user);
524 524
 
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
 					if ($object->particulier)
528 528
 					{
529 529
 						dol_syslog("We ask to create a contact/address too", LOG_DEBUG);
530
-						$result=$object->create_individual($user);
530
+						$result = $object->create_individual($user);
531 531
 						if ($result < 0)
532 532
 						{
533 533
 							setEventMessages($object->error, $object->errors, 'errors');
@@ -564,10 +564,10 @@  discard block
 block discarded – undo
564 564
 
565 565
                             if (@is_dir($dir))
566 566
                             {
567
-                                $newfile=$dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
567
+                                $newfile = $dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
568 568
                                 $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1);
569 569
 
570
-                                if (! $result > 0)
570
+                                if (!$result > 0)
571 571
                                 {
572 572
                                     $errors[] = "ErrorFailedToSaveFile";
573 573
                                 }
@@ -581,7 +581,7 @@  discard block
 block discarded – undo
581 581
                     }
582 582
                     else
583 583
 					{
584
-						switch($_FILES['photo']['error'])
584
+						switch ($_FILES['photo']['error'])
585 585
 						{
586 586
 						    case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
587 587
 						    case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
@@ -607,21 +607,21 @@  discard block
 block discarded – undo
607 607
                    	$error++;
608 608
                 }
609 609
 
610
-                if ($result >= 0 && ! $error)
610
+                if ($result >= 0 && !$error)
611 611
                 {
612 612
                     $db->commit();
613 613
 
614
-                	if (! empty($backtopage))
614
+                	if (!empty($backtopage))
615 615
                 	{
616
-                	    if (preg_match('/\?/', $backtopage)) $backtopage.='&socid='.$object->id;
616
+                	    if (preg_match('/\?/', $backtopage)) $backtopage .= '&socid='.$object->id;
617 617
                		    header("Location: ".$backtopage);
618 618
                     	exit;
619 619
                 	}
620 620
                 	else
621 621
                 	{
622
-                    	$url=$_SERVER["PHP_SELF"]."?socid=".$object->id;
623
-                    	if (($object->client == 1 || $object->client == 3) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) $url=DOL_URL_ROOT."/comm/card.php?socid=".$object->id;
624
-                    	else if ($object->fournisseur == 1) $url=DOL_URL_ROOT."/fourn/card.php?socid=".$object->id;
622
+                    	$url = $_SERVER["PHP_SELF"]."?socid=".$object->id;
623
+                    	if (($object->client == 1 || $object->client == 3) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) $url = DOL_URL_ROOT."/comm/card.php?socid=".$object->id;
624
+                    	else if ($object->fournisseur == 1) $url = DOL_URL_ROOT."/fourn/card.php?socid=".$object->id;
625 625
 
626 626
                 		header("Location: ".$url);
627 627
                     	exit;
@@ -630,7 +630,7 @@  discard block
 block discarded – undo
630 630
                 else
631 631
                 {
632 632
                     $db->rollback();
633
-                    $action='create';
633
+                    $action = 'create';
634 634
                 }
635 635
             }
636 636
 
@@ -638,9 +638,9 @@  discard block
 block discarded – undo
638 638
             {
639 639
             	$error = 0;
640 640
 
641
-                if (GETPOST('cancel','alpha'))
641
+                if (GETPOST('cancel', 'alpha'))
642 642
                 {
643
-                	if (! empty($backtopage))
643
+                	if (!empty($backtopage))
644 644
                 	{
645 645
                		    header("Location: ".$backtopage);
646 646
                     	exit;
@@ -653,22 +653,22 @@  discard block
 block discarded – undo
653 653
                 }
654 654
 
655 655
                 // To not set code if third party is not concerned. But if it had values, we keep them.
656
-                if (empty($object->client) && empty($object->oldcopy->code_client))          $object->code_client='';
657
-                if (empty($object->fournisseur)&& empty($object->oldcopy->code_fournisseur)) $object->code_fournisseur='';
656
+                if (empty($object->client) && empty($object->oldcopy->code_client))          $object->code_client = '';
657
+                if (empty($object->fournisseur) && empty($object->oldcopy->code_fournisseur)) $object->code_fournisseur = '';
658 658
                 //var_dump($object);exit;
659 659
 
660 660
                 $result = $object->update($socid, $user, 1, $object->oldcopy->codeclient_modifiable(), $object->oldcopy->codefournisseur_modifiable(), 'update', 0);
661
-                if ($result <=  0)
661
+                if ($result <= 0)
662 662
                 {
663 663
                     setEventMessages($object->error, $object->errors, 'errors');
664 664
                   	$error++;
665 665
                 }
666 666
 
667 667
 				// Prevent thirdparty's emptying if a user hasn't rights $user->rights->categorie->lire (in such a case, post of 'custcats' is not defined)
668
-				if (! $error && !empty($user->rights->categorie->lire))
668
+				if (!$error && !empty($user->rights->categorie->lire))
669 669
 				{
670 670
 					// Customer categories association
671
-					$categories = GETPOST( 'custcats', 'array' );
671
+					$categories = GETPOST('custcats', 'array');
672 672
 					$result = $object->setCategories($categories, 'customer');
673 673
 					if ($result < 0)
674 674
 					{
@@ -691,8 +691,8 @@  discard block
 block discarded – undo
691 691
                 $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
692 692
                 if (GETPOST('deletephoto') && $object->photo)
693 693
                 {
694
-                    $fileimg=$dir.'/'.$object->logo;
695
-                    $dirthumbs=$dir.'/thumbs';
694
+                    $fileimg = $dir.'/'.$object->logo;
695
+                    $dirthumbs = $dir.'/thumbs';
696 696
                     dol_delete_file($fileimg);
697 697
                     dol_delete_dir_recursive($dirthumbs);
698 698
                 }
@@ -704,10 +704,10 @@  discard block
 block discarded – undo
704 704
 
705 705
                         if (@is_dir($dir))
706 706
                         {
707
-                            $newfile=$dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
707
+                            $newfile = $dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
708 708
                             $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1);
709 709
 
710
-                            if (! $result > 0)
710
+                            if (!$result > 0)
711 711
                             {
712 712
                                 $errors[] = "ErrorFailedToSaveFile";
713 713
                             }
@@ -717,9 +717,9 @@  discard block
 block discarded – undo
717 717
                             	$object->addThumbs($newfile);
718 718
 
719 719
                                 // Index file in database
720
-                                if (! empty($conf->global->THIRDPARTY_LOGO_ALLOW_EXTERNAL_DOWNLOAD))
720
+                                if (!empty($conf->global->THIRDPARTY_LOGO_ALLOW_EXTERNAL_DOWNLOAD))
721 721
                                 {
722
-                                	require_once DOL_DOCUMENT_ROOT .'/core/lib/files.lib.php';
722
+                                	require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
723 723
                                 	// the dir dirname($newfile) is directory of logo, so we should have only one file at once into index, so we delete indexes for the dir
724 724
                                 	deleteFilesIntoDatabaseIndex(dirname($newfile), '', '', 'uploaded', 1);
725 725
                                 	// now we index the uploaded logo file
@@ -735,7 +735,7 @@  discard block
 block discarded – undo
735 735
                 }
736 736
                 else
737 737
                 {
738
-					switch($_FILES['photo']['error'])
738
+					switch ($_FILES['photo']['error'])
739 739
 					{
740 740
 					    case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
741 741
 					    case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
@@ -750,21 +750,21 @@  discard block
 block discarded – undo
750 750
 
751 751
 
752 752
                 // Update linked member
753
-                if (! $error && $object->fk_soc > 0)
753
+                if (!$error && $object->fk_soc > 0)
754 754
                 {
755 755
 
756 756
                 	$sql = "UPDATE ".MAIN_DB_PREFIX."adherent";
757
-                	$sql.= " SET fk_soc = NULL WHERE fk_soc = " . $id;
758
-                	if (! $object->db->query($sql))
757
+                	$sql .= " SET fk_soc = NULL WHERE fk_soc = ".$id;
758
+                	if (!$object->db->query($sql))
759 759
                 	{
760 760
                 		$error++;
761 761
                 		$object->error .= $object->db->lasterror();
762 762
                 	}
763 763
                 }
764 764
 
765
-                if (! $error && ! count($errors))
765
+                if (!$error && !count($errors))
766 766
                 {
767
-                	if (! empty($backtopage))
767
+                	if (!empty($backtopage))
768 768
                 	{
769 769
                		    header("Location: ".$backtopage);
770 770
                     	exit;
@@ -778,13 +778,13 @@  discard block
 block discarded – undo
778 778
                 else
779 779
                 {
780 780
                     $object->id = $socid;
781
-                    $action= "edit";
781
+                    $action = "edit";
782 782
                 }
783 783
             }
784 784
         }
785 785
         else
786 786
         {
787
-        	$action = ($action=='add'?'create':'edit');
787
+        	$action = ($action == 'add' ? 'create' : 'edit');
788 788
         }
789 789
     }
790 790
 
@@ -804,7 +804,7 @@  discard block
 block discarded – undo
804 804
             $langs->load("errors");
805 805
            	setEventMessages($object->error, $object->errors, 'errors');
806 806
            	$error++;
807
-            $action='';
807
+            $action = '';
808 808
         }
809 809
     }
810 810
 
@@ -812,7 +812,7 @@  discard block
 block discarded – undo
812 812
     if ($action == 'set_thirdparty' && $user->rights->societe->creer)
813 813
     {
814 814
     	$object->fetch($socid);
815
-    	$result = $object->set_parent(GETPOST('editparentcompany','int'));
815
+    	$result = $object->set_parent(GETPOST('editparentcompany', 'int'));
816 816
     }
817 817
 
818 818
     // Set incoterm
@@ -823,17 +823,17 @@  discard block
 block discarded – undo
823 823
     }
824 824
 
825 825
     // Actions to send emails
826
-    $id=$socid;
827
-    $trigger_name='COMPANY_SENTBYMAIL';
828
-    $paramname='socid';
829
-    $mode='emailfromthirdparty';
830
-    $trackid='thi'.$object->id;
826
+    $id = $socid;
827
+    $trigger_name = 'COMPANY_SENTBYMAIL';
828
+    $paramname = 'socid';
829
+    $mode = 'emailfromthirdparty';
830
+    $trackid = 'thi'.$object->id;
831 831
     include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
832 832
 
833 833
     // Actions to build doc
834 834
     $id = $socid;
835 835
     $upload_dir = $conf->societe->dir_output;
836
-    $permissioncreate=$user->rights->societe->creer;
836
+    $permissioncreate = $user->rights->societe->creer;
837 837
     include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
838 838
 }
839 839
 
@@ -849,24 +849,24 @@  discard block
 block discarded – undo
849 849
 
850 850
 if ($socid > 0 && empty($object->id))
851 851
 {
852
-    $result=$object->fetch($socid);
853
-	if ($result <= 0) dol_print_error('',$object->error);
852
+    $result = $object->fetch($socid);
853
+	if ($result <= 0) dol_print_error('', $object->error);
854 854
 }
855 855
 
856
-$title=$langs->trans("ThirdParty");
857
-if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$langs->trans('Card');
858
-$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
859
-llxHeader('',$title,$help_url);
856
+$title = $langs->trans("ThirdParty");
857
+if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) $title = $object->name." - ".$langs->trans('Card');
858
+$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
859
+llxHeader('', $title, $help_url);
860 860
 
861
-$countrynotdefined=$langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
861
+$countrynotdefined = $langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
862 862
 
863 863
 if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
864 864
 {
865 865
     // -----------------------------------------
866 866
     // When used with CANVAS
867 867
     // -----------------------------------------
868
-   	$objcanvas->assign_values($action, $object->id, $object->ref);	// Set value for templates
869
-    $objcanvas->display_canvas($action);							// Show template
868
+   	$objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates
869
+    $objcanvas->display_canvas($action); // Show template
870 870
 }
871 871
 else
872 872
 {
@@ -878,66 +878,66 @@  discard block
 block discarded – undo
878 878
         /*
879 879
          *  Creation
880 880
          */
881
-		$private=GETPOST("private","int");
882
-		if (! empty($conf->global->THIRDPARTY_DEFAULT_CREATE_CONTACT) && ! isset($_GET['private']) && ! isset($_POST['private'])) $private=1;
883
-    	if (empty($private)) $private=0;
881
+		$private = GETPOST("private", "int");
882
+		if (!empty($conf->global->THIRDPARTY_DEFAULT_CREATE_CONTACT) && !isset($_GET['private']) && !isset($_POST['private'])) $private = 1;
883
+    	if (empty($private)) $private = 0;
884 884
 
885 885
         // Load object modCodeTiers
886
-        $module=(! empty($conf->global->SOCIETE_CODECLIENT_ADDON)?$conf->global->SOCIETE_CODECLIENT_ADDON:'mod_codeclient_leopard');
886
+        $module = (!empty($conf->global->SOCIETE_CODECLIENT_ADDON) ? $conf->global->SOCIETE_CODECLIENT_ADDON : 'mod_codeclient_leopard');
887 887
         if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php')
888 888
         {
889
-            $module = substr($module, 0, dol_strlen($module)-4);
889
+            $module = substr($module, 0, dol_strlen($module) - 4);
890 890
         }
891
-        $dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
891
+        $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
892 892
         foreach ($dirsociete as $dirroot)
893 893
         {
894
-            $res=dol_include_once($dirroot.$module.'.php');
894
+            $res = dol_include_once($dirroot.$module.'.php');
895 895
             if ($res) break;
896 896
         }
897 897
         $modCodeClient = new $module;
898 898
         // Load object modCodeFournisseur
899
-        $module=(! empty($conf->global->SOCIETE_CODECLIENT_ADDON)?$conf->global->SOCIETE_CODECLIENT_ADDON:'mod_codeclient_leopard');
899
+        $module = (!empty($conf->global->SOCIETE_CODECLIENT_ADDON) ? $conf->global->SOCIETE_CODECLIENT_ADDON : 'mod_codeclient_leopard');
900 900
         if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php')
901 901
         {
902
-            $module = substr($module, 0, dol_strlen($module)-4);
902
+            $module = substr($module, 0, dol_strlen($module) - 4);
903 903
         }
904
-        $dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
904
+        $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
905 905
         foreach ($dirsociete as $dirroot)
906 906
         {
907
-            $res=dol_include_once($dirroot.$module.'.php');
907
+            $res = dol_include_once($dirroot.$module.'.php');
908 908
             if ($res) break;
909 909
         }
910 910
         $modCodeFournisseur = new $module;
911 911
 
912 912
         // Define if customer/prospect or supplier status is set or not
913
-        if (GETPOST("type")!='f')
913
+        if (GETPOST("type") != 'f')
914 914
         {
915
-            $object->client=-1;
916
-            if (! empty($conf->global->THIRDPARTY_CUSTOMERPROSPECT_BY_DEFAULT))  { $object->client=3; }
915
+            $object->client = -1;
916
+            if (!empty($conf->global->THIRDPARTY_CUSTOMERPROSPECT_BY_DEFAULT)) { $object->client = 3; }
917 917
         }
918
-        if (GETPOST("type")=='c')  { $object->client=3; }   // Prospect / Customer
919
-        if (GETPOST("type")=='p')  { $object->client=2; }
920
-        if (! empty($conf->fournisseur->enabled) && (GETPOST("type")=='f' || (GETPOST("type")=='' && ! empty($conf->global->THIRDPARTY_SUPPLIER_BY_DEFAULT))))  { $object->fournisseur=1; }
918
+        if (GETPOST("type") == 'c') { $object->client = 3; }   // Prospect / Customer
919
+        if (GETPOST("type") == 'p') { $object->client = 2; }
920
+        if (!empty($conf->fournisseur->enabled) && (GETPOST("type") == 'f' || (GETPOST("type") == '' && !empty($conf->global->THIRDPARTY_SUPPLIER_BY_DEFAULT)))) { $object->fournisseur = 1; }
921 921
 
922
-        $object->name				= GETPOST('name', 'alpha');
923
-        $object->firstname			= GETPOST('firstname', 'alpha');
922
+        $object->name = GETPOST('name', 'alpha');
923
+        $object->firstname = GETPOST('firstname', 'alpha');
924 924
         $object->particulier		= $private;
925 925
         $object->prefix_comm		= GETPOST('prefix_comm');
926
-        $object->client				= GETPOST('client')?GETPOST('client'):$object->client;
926
+        $object->client = GETPOST('client') ?GETPOST('client') : $object->client;
927 927
 
928
-        if(empty($duplicate_code_error)) {
928
+        if (empty($duplicate_code_error)) {
929 929
 	        $object->code_client		= GETPOST('code_client', 'alpha');
930
-	        $object->fournisseur		= GETPOST('fournisseur')?GETPOST('fournisseur'):$object->fournisseur;
930
+	        $object->fournisseur		= GETPOST('fournisseur') ?GETPOST('fournisseur') : $object->fournisseur;
931 931
         }
932 932
 		else {
933
-			setEventMessages($langs->trans('NewCustomerSupplierCodeProposed'),'', 'warnings');
933
+			setEventMessages($langs->trans('NewCustomerSupplierCodeProposed'), '', 'warnings');
934 934
 		}
935 935
 
936
-        $object->code_fournisseur	= GETPOST('code_fournisseur', 'alpha');
937
-        $object->address			= GETPOST('address', 'alpha');
938
-        $object->zip				= GETPOST('zipcode', 'alpha');
939
-        $object->town				= GETPOST('town', 'alpha');
940
-        $object->state_id			= GETPOST('state_id', 'int');
936
+        $object->code_fournisseur = GETPOST('code_fournisseur', 'alpha');
937
+        $object->address = GETPOST('address', 'alpha');
938
+        $object->zip = GETPOST('zipcode', 'alpha');
939
+        $object->town = GETPOST('town', 'alpha');
940
+        $object->state_id = GETPOST('state_id', 'int');
941 941
         $object->skype				= GETPOST('skype', 'alpha');
942 942
         $object->phone				= GETPOST('phone', 'alpha');
943 943
         $object->fax				= GETPOST('fax', 'alpha');
@@ -951,30 +951,30 @@  discard block
 block discarded – undo
951 951
         $object->idprof4			= GETPOST('idprof4', 'alpha');
952 952
         $object->idprof5			= GETPOST('idprof5', 'alpha');
953 953
         $object->idprof6			= GETPOST('idprof6', 'alpha');
954
-        $object->typent_id			= GETPOST('typent_id', 'int');
954
+        $object->typent_id = GETPOST('typent_id', 'int');
955 955
         $object->effectif_id		= GETPOST('effectif_id', 'int');
956 956
         $object->civility_id		= GETPOST('civility_id', 'int');
957 957
 
958
-        $object->tva_assuj			= GETPOST('assujtva_value', 'int');
959
-        $object->status				= GETPOST('status', 'int');
958
+        $object->tva_assuj = GETPOST('assujtva_value', 'int');
959
+        $object->status = GETPOST('status', 'int');
960 960
 
961 961
         //Local Taxes
962 962
         $object->localtax1_assuj	= GETPOST('localtax1assuj_value', 'int');
963 963
         $object->localtax2_assuj	= GETPOST('localtax2assuj_value', 'int');
964 964
 
965
-        $object->localtax1_value	=GETPOST('lt1', 'int');
966
-        $object->localtax2_value	=GETPOST('lt2', 'int');
965
+        $object->localtax1_value	= GETPOST('lt1', 'int');
966
+        $object->localtax2_value	= GETPOST('lt2', 'int');
967 967
 
968
-        $object->tva_intra			= GETPOST('tva_intra', 'alpha');
968
+        $object->tva_intra = GETPOST('tva_intra', 'alpha');
969 969
 
970
-        $object->commercial_id		= GETPOST('commercial_id', 'int');
971
-        $object->default_lang		= GETPOST('default_lang');
970
+        $object->commercial_id = GETPOST('commercial_id', 'int');
971
+        $object->default_lang = GETPOST('default_lang');
972 972
 
973
-        $object->logo = (isset($_FILES['photo'])?dol_sanitizeFileName($_FILES['photo']['name']):'');
973
+        $object->logo = (isset($_FILES['photo']) ?dol_sanitizeFileName($_FILES['photo']['name']) : '');
974 974
 
975 975
         // Gestion du logo de la société
976 976
         $dir     = $conf->societe->multidir_output[$conf->entity]."/".$object->id."/logos";
977
-        $file_OK = (isset($_FILES['photo'])?is_uploaded_file($_FILES['photo']['tmp_name']):false);
977
+        $file_OK = (isset($_FILES['photo']) ?is_uploaded_file($_FILES['photo']['tmp_name']) : false);
978 978
         if ($file_OK)
979 979
         {
980 980
             if (image_format_supported($_FILES['photo']['name']))
@@ -983,10 +983,10 @@  discard block
 block discarded – undo
983 983
 
984 984
                 if (@is_dir($dir))
985 985
                 {
986
-                    $newfile=$dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
986
+                    $newfile = $dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
987 987
                     $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1);
988 988
 
989
-                    if (! $result > 0)
989
+                    if (!$result > 0)
990 990
                     {
991 991
                         $errors[] = "ErrorFailedToSaveFile";
992 992
                     }
@@ -1000,20 +1000,20 @@  discard block
 block discarded – undo
1000 1000
         }
1001 1001
 
1002 1002
         // We set country_id, country_code and country for the selected country
1003
-        $object->country_id=GETPOST('country_id')?GETPOST('country_id'):$mysoc->country_id;
1003
+        $object->country_id = GETPOST('country_id') ?GETPOST('country_id') : $mysoc->country_id;
1004 1004
         if ($object->country_id)
1005 1005
         {
1006
-            $tmparray=getCountry($object->country_id,'all');
1007
-            $object->country_code=$tmparray['code'];
1008
-            $object->country=$tmparray['label'];
1006
+            $tmparray = getCountry($object->country_id, 'all');
1007
+            $object->country_code = $tmparray['code'];
1008
+            $object->country = $tmparray['label'];
1009 1009
         }
1010
-        $object->forme_juridique_code=GETPOST('forme_juridique_code');
1010
+        $object->forme_juridique_code = GETPOST('forme_juridique_code');
1011 1011
         /* Show create form */
1012 1012
 
1013
-        $linkback="";
1014
-        print load_fiche_titre($langs->trans("NewThirdParty"),$linkback,'title_companies.png');
1013
+        $linkback = "";
1014
+        print load_fiche_titre($langs->trans("NewThirdParty"), $linkback, 'title_companies.png');
1015 1015
 
1016
-        if (! empty($conf->use_javascript_ajax))
1016
+        if (!empty($conf->use_javascript_ajax))
1017 1017
         {
1018 1018
             print "\n".'<script type="text/javascript">';
1019 1019
             print '$(document).ready(function () {
@@ -1051,31 +1051,31 @@  discard block
 block discarded – undo
1051 1051
             print $langs->trans("ThirdPartyType").': &nbsp; &nbsp; ';
1052 1052
             print '</div>';
1053 1053
 	        print '<label for="radiocompany" class="radiocompany">';
1054
-            print '<input type="radio" id="radiocompany" class="flat" name="private"  value="0"'.($private?'':' checked').'>';
1054
+            print '<input type="radio" id="radiocompany" class="flat" name="private"  value="0"'.($private ? '' : ' checked').'>';
1055 1055
 	        print '&nbsp;';
1056 1056
             print $langs->trans("CreateThirdPartyOnly");
1057 1057
 	        print '</label>';
1058 1058
             print ' &nbsp; &nbsp; ';
1059 1059
 	        print '<label for="radioprivate" class="radioprivate">';
1060
-            $text ='<input type="radio" id="radioprivate" class="flat" name="private" value="1"'.($private?' checked':'').'>';
1061
-	        $text.='&nbsp;';
1062
-	        $text.= $langs->trans("CreateThirdPartyAndContact");
1063
-	        $htmltext=$langs->trans("ToCreateContactWithSameName");
1060
+            $text = '<input type="radio" id="radioprivate" class="flat" name="private" value="1"'.($private ? ' checked' : '').'>';
1061
+	        $text .= '&nbsp;';
1062
+	        $text .= $langs->trans("CreateThirdPartyAndContact");
1063
+	        $htmltext = $langs->trans("ToCreateContactWithSameName");
1064 1064
 	        print $form->textwithpicto($text, $htmltext, 1, 'help', '', 0, 3);
1065 1065
             print '</label>';
1066 1066
             print '</div>';
1067 1067
             print "<br>\n";
1068 1068
         }
1069 1069
 
1070
-        dol_htmloutput_mesg(is_numeric($error)?'':$error, $errors, 'error');
1070
+        dol_htmloutput_mesg(is_numeric($error) ? '' : $error, $errors, 'error');
1071 1071
 
1072
-        print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'" method="post" name="formsoc" autocomplete="off">';		// Chrome ignor autocomplete
1072
+        print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'" method="post" name="formsoc" autocomplete="off">'; // Chrome ignor autocomplete
1073 1073
 
1074 1074
         print '<input type="hidden" name="action" value="add">';
1075 1075
         print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
1076 1076
         print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1077 1077
         print '<input type="hidden" name="private" value='.$object->particulier.'>';
1078
-        print '<input type="hidden" name="type" value='.GETPOST("type",'alpha').'>';
1078
+        print '<input type="hidden" name="type" value='.GETPOST("type", 'alpha').'>';
1079 1079
         print '<input type="hidden" name="LastName" value="'.$langs->trans('ThirdPartyName').' / '.$langs->trans('LastName').'">';
1080 1080
         print '<input type="hidden" name="ThirdPartyName" value="'.$langs->trans('ThirdPartyName').'">';
1081 1081
         if ($modCodeClient->code_auto || $modCodeFournisseur->code_auto) print '<input type="hidden" name="code_auto" value="1">';
@@ -1088,15 +1088,15 @@  discard block
 block discarded – undo
1088 1088
 	    print '<tr><td class="titlefieldcreate">';
1089 1089
         if ($object->particulier || $private)
1090 1090
         {
1091
-	        print '<span id="TypeName" class="fieldrequired">'.$langs->trans('ThirdPartyName').' / '.$langs->trans('LastName','name').'</span>';
1091
+	        print '<span id="TypeName" class="fieldrequired">'.$langs->trans('ThirdPartyName').' / '.$langs->trans('LastName', 'name').'</span>';
1092 1092
         }
1093 1093
         else
1094 1094
 		{
1095
-			print '<span id="TypeName" class="fieldrequired">'.fieldLabel('ThirdPartyName','name').'</span>';
1095
+			print '<span id="TypeName" class="fieldrequired">'.fieldLabel('ThirdPartyName', 'name').'</span>';
1096 1096
         }
1097
-	    print '</td><td'.(empty($conf->global->SOCIETE_USEPREFIX)?' colspan="3"':'').'>';
1097
+	    print '</td><td'.(empty($conf->global->SOCIETE_USEPREFIX) ? ' colspan="3"' : '').'>';
1098 1098
 	    print '<input type="text" class="minwidth300" maxlength="128" name="name" id="name" value="'.$object->name.'" autofocus="autofocus"></td>';
1099
-	    if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
1099
+	    if (!empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
1100 1100
 	    {
1101 1101
 		    print '<td>'.$langs->trans('Prefix').'</td><td><input type="text" size="5" maxlength="5" name="prefix_comm" value="'.$object->prefix_comm.'"></td>';
1102 1102
 	    }
@@ -1105,11 +1105,11 @@  discard block
 block discarded – undo
1105 1105
         // If javascript on, we show option individual
1106 1106
         if ($conf->use_javascript_ajax)
1107 1107
         {
1108
-            print '<tr class="individualline"><td>'.fieldLabel('FirstName','firstname').'</td>';
1108
+            print '<tr class="individualline"><td>'.fieldLabel('FirstName', 'firstname').'</td>';
1109 1109
 	        print '<td colspan="3"><input type="text" class="minwidth300" maxlength="128" name="firstname" id="firstname" value="'.$object->firstname.'"></td>';
1110 1110
             print '</tr>';
1111 1111
             // Title
1112
-            print '<tr class="individualline"><td>'.fieldLabel('UserTitle','civility_id').'</td><td colspan="3" class="maxwidthonsmartphone">';
1112
+            print '<tr class="individualline"><td>'.fieldLabel('UserTitle', 'civility_id').'</td><td colspan="3" class="maxwidthonsmartphone">';
1113 1113
             print $formcompany->select_civility($object->civility_id, 'civility_id', 'maxwidth100').'</td>';
1114 1114
             print '</tr>';
1115 1115
         }
@@ -1119,130 +1119,130 @@  discard block
 block discarded – undo
1119 1119
 	    print '<td colspan="3"><input type="text" class="minwidth300" name="name_alias" id="name_alias_input" value="'.$object->name_alias.'"></td></tr>';
1120 1120
 
1121 1121
         // Prospect/Customer
1122
-        print '<tr><td class="titlefieldcreate">'.fieldLabel('ProspectCustomer','customerprospect',1).'</td>';
1122
+        print '<tr><td class="titlefieldcreate">'.fieldLabel('ProspectCustomer', 'customerprospect', 1).'</td>';
1123 1123
 	    print '<td class="maxwidthonsmartphone">';
1124
-	    $selected=GETPOST('client','int')!=''?GETPOST('client','int'):$object->client;
1124
+	    $selected = GETPOST('client', 'int') != '' ?GETPOST('client', 'int') : $object->client;
1125 1125
         print '<select class="flat" name="client" id="customerprospect">';
1126 1126
         if (GETPOST("type") == '') print '<option value="-1">&nbsp;</option>';
1127
-        if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) print '<option value="2"'.($selected==2?' selected':'').'>'.$langs->trans('Prospect').'</option>';
1128
-        if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTSCUSTOMERS)) print '<option value="3"'.($selected==3?' selected':'').'>'.$langs->trans('ProspectCustomer').'</option>';
1129
-        if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print '<option value="1"'.($selected==1?' selected':'').'>'.$langs->trans('Customer').'</option>';
1130
-        print '<option value="0"'.((string) $selected == '0'?' selected':'').'>'.$langs->trans('NorProspectNorCustomer').'</option>';
1127
+        if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) print '<option value="2"'.($selected == 2 ? ' selected' : '').'>'.$langs->trans('Prospect').'</option>';
1128
+        if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTSCUSTOMERS)) print '<option value="3"'.($selected == 3 ? ' selected' : '').'>'.$langs->trans('ProspectCustomer').'</option>';
1129
+        if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print '<option value="1"'.($selected == 1 ? ' selected' : '').'>'.$langs->trans('Customer').'</option>';
1130
+        print '<option value="0"'.((string) $selected == '0' ? ' selected' : '').'>'.$langs->trans('NorProspectNorCustomer').'</option>';
1131 1131
         print '</select></td>';
1132 1132
 
1133
-        print '<td>'.fieldLabel('CustomerCode','customer_code').'</td><td>';
1133
+        print '<td>'.fieldLabel('CustomerCode', 'customer_code').'</td><td>';
1134 1134
         print '<table class="nobordernopadding"><tr><td>';
1135
-		$tmpcode=$object->code_client;
1136
-        if (empty($tmpcode) && ! empty($modCodeClient->code_auto)) $tmpcode=$modCodeClient->getNextValue($object,0);
1135
+		$tmpcode = $object->code_client;
1136
+        if (empty($tmpcode) && !empty($modCodeClient->code_auto)) $tmpcode = $modCodeClient->getNextValue($object, 0);
1137 1137
         print '<input type="text" name="code_client" id="customer_code" class="maxwidthonsmartphone" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
1138 1138
         print '</td><td>';
1139
-        $s=$modCodeClient->getToolTip($langs,$object,0);
1140
-        print $form->textwithpicto('',$s,1);
1139
+        $s = $modCodeClient->getToolTip($langs, $object, 0);
1140
+        print $form->textwithpicto('', $s, 1);
1141 1141
         print '</td></tr></table>';
1142 1142
         print '</td></tr>';
1143 1143
 
1144
-        if (! empty($conf->fournisseur->enabled) && ! empty($user->rights->fournisseur->lire))
1144
+        if (!empty($conf->fournisseur->enabled) && !empty($user->rights->fournisseur->lire))
1145 1145
         {
1146 1146
             // Supplier
1147 1147
             print '<tr>';
1148
-            print '<td>'.fieldLabel('Supplier','fournisseur',1).'</td><td>';
1148
+            print '<td>'.fieldLabel('Supplier', 'fournisseur', 1).'</td><td>';
1149 1149
             $default = -1;
1150
-            if (! empty($conf->global->THIRDPARTY_SUPPLIER_BY_DEFAULT)) $default=1;
1151
-            print $form->selectyesno("fournisseur", (GETPOST('fournisseur','int')!=''?GETPOST('fournisseur','int'):(GETPOST("type",'alpha') == '' ? $default : $object->fournisseur)), 1, 0, (GETPOST("type",'alpha') == '' ? 1 : 0));
1150
+            if (!empty($conf->global->THIRDPARTY_SUPPLIER_BY_DEFAULT)) $default = 1;
1151
+            print $form->selectyesno("fournisseur", (GETPOST('fournisseur', 'int') != '' ?GETPOST('fournisseur', 'int') : (GETPOST("type", 'alpha') == '' ? $default : $object->fournisseur)), 1, 0, (GETPOST("type", 'alpha') == '' ? 1 : 0));
1152 1152
             print '</td>';
1153
-            print '<td>'.fieldLabel('SupplierCode','supplier_code').'</td><td>';
1153
+            print '<td>'.fieldLabel('SupplierCode', 'supplier_code').'</td><td>';
1154 1154
             print '<table class="nobordernopadding"><tr><td>';
1155
-            $tmpcode=$object->code_fournisseur;
1156
-            if (empty($tmpcode) && ! empty($modCodeFournisseur->code_auto)) $tmpcode=$modCodeFournisseur->getNextValue($object,1);
1155
+            $tmpcode = $object->code_fournisseur;
1156
+            if (empty($tmpcode) && !empty($modCodeFournisseur->code_auto)) $tmpcode = $modCodeFournisseur->getNextValue($object, 1);
1157 1157
             print '<input type="text" name="code_fournisseur" id="supplier_code" class="maxwidthonsmartphone" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
1158 1158
             print '</td><td>';
1159
-            $s=$modCodeFournisseur->getToolTip($langs,$object,1);
1160
-            print $form->textwithpicto('',$s,1);
1159
+            $s = $modCodeFournisseur->getToolTip($langs, $object, 1);
1160
+            print $form->textwithpicto('', $s, 1);
1161 1161
             print '</td></tr></table>';
1162 1162
             print '</td></tr>';
1163 1163
         }
1164 1164
 
1165 1165
         // Status
1166
-        print '<tr><td>'.fieldLabel('Status','status').'</td><td colspan="3">';
1167
-        print $form->selectarray('status', array('0'=>$langs->trans('ActivityCeased'),'1'=>$langs->trans('InActivity')),1);
1166
+        print '<tr><td>'.fieldLabel('Status', 'status').'</td><td colspan="3">';
1167
+        print $form->selectarray('status', array('0'=>$langs->trans('ActivityCeased'), '1'=>$langs->trans('InActivity')), 1);
1168 1168
         print '</td></tr>';
1169 1169
 
1170 1170
         // Barcode
1171
-        if (! empty($conf->barcode->enabled))
1171
+        if (!empty($conf->barcode->enabled))
1172 1172
         {
1173
-            print '<tr><td>'.fieldLabel('Gencod','barcode').'</td>';
1173
+            print '<tr><td>'.fieldLabel('Gencod', 'barcode').'</td>';
1174 1174
 	        print '<td colspan="3"><input type="text" name="barcode" id="barcode" value="'.$object->barcode.'">';
1175 1175
             print '</td></tr>';
1176 1176
         }
1177 1177
 
1178 1178
         // Address
1179
-        print '<tr><td class="tdtop">'.fieldLabel('Address','address').'</td>';
1179
+        print '<tr><td class="tdtop">'.fieldLabel('Address', 'address').'</td>';
1180 1180
 	    print '<td colspan="3"><textarea name="address" id="address" class="quatrevingtpercent" rows="'._ROWS_2.'" wrap="soft">';
1181 1181
         print $object->address;
1182 1182
         print '</textarea></td></tr>';
1183 1183
 
1184 1184
         // Zip / Town
1185
-        print '<tr><td>'.fieldLabel('Zip','zipcode').'</td><td>';
1186
-        print $formcompany->select_ziptown($object->zip,'zipcode',array('town','selectcountry_id','state_id'), 0, 0, '', 'maxwidth100 quatrevingtpercent');
1187
-        print '</td><td>'.fieldLabel('Town','town').'</td><td>';
1188
-        print $formcompany->select_ziptown($object->town,'town',array('zipcode','selectcountry_id','state_id'), 0, 0, '', 'maxwidth100 quatrevingtpercent');
1185
+        print '<tr><td>'.fieldLabel('Zip', 'zipcode').'</td><td>';
1186
+        print $formcompany->select_ziptown($object->zip, 'zipcode', array('town', 'selectcountry_id', 'state_id'), 0, 0, '', 'maxwidth100 quatrevingtpercent');
1187
+        print '</td><td>'.fieldLabel('Town', 'town').'</td><td>';
1188
+        print $formcompany->select_ziptown($object->town, 'town', array('zipcode', 'selectcountry_id', 'state_id'), 0, 0, '', 'maxwidth100 quatrevingtpercent');
1189 1189
         print '</td></tr>';
1190 1190
 
1191 1191
         // Country
1192
-        print '<tr><td>'.fieldLabel('Country','selectcountry_id').'</td><td colspan="3" class="maxwidthonsmartphone">';
1193
-        print $form->select_country((GETPOST('country_id')!=''?GETPOST('country_id'):$object->country_id));
1194
-        if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1192
+        print '<tr><td>'.fieldLabel('Country', 'selectcountry_id').'</td><td colspan="3" class="maxwidthonsmartphone">';
1193
+        print $form->select_country((GETPOST('country_id') != '' ?GETPOST('country_id') : $object->country_id));
1194
+        if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1195 1195
         print '</td></tr>';
1196 1196
 
1197 1197
         // State
1198 1198
         if (empty($conf->global->SOCIETE_DISABLE_STATE))
1199 1199
         {
1200
-            if(!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && ($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 || $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 2))
1200
+            if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && ($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 || $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 2))
1201 1201
             {
1202
-                print '<tr><td>'.fieldLabel('Region-State','state_id').'</td><td colspan="3" class="maxwidthonsmartphone">';
1202
+                print '<tr><td>'.fieldLabel('Region-State', 'state_id').'</td><td colspan="3" class="maxwidthonsmartphone">';
1203 1203
             }
1204 1204
             else
1205 1205
             {
1206
-                print '<tr><td>'.fieldLabel('State','state_id').'</td><td colspan="3" class="maxwidthonsmartphone">';
1206
+                print '<tr><td>'.fieldLabel('State', 'state_id').'</td><td colspan="3" class="maxwidthonsmartphone">';
1207 1207
             }
1208 1208
 
1209
-            if ($object->country_id) print $formcompany->select_state($object->state_id,$object->country_code);
1209
+            if ($object->country_id) print $formcompany->select_state($object->state_id, $object->country_code);
1210 1210
             else print $countrynotdefined;
1211 1211
             print '</td></tr>';
1212 1212
         }
1213 1213
 
1214 1214
         // Email web
1215
-        print '<tr><td>'.fieldLabel('EMail','email',$conf->global->SOCIETE_EMAIL_MANDATORY).'</td>';
1215
+        print '<tr><td>'.fieldLabel('EMail', 'email', $conf->global->SOCIETE_EMAIL_MANDATORY).'</td>';
1216 1216
 	    print '<td colspan="3"><input type="text" name="email" id="email" value="'.$object->email.'"></td></tr>';
1217
-        print '<tr><td>'.fieldLabel('Web','url').'</td>';
1217
+        print '<tr><td>'.fieldLabel('Web', 'url').'</td>';
1218 1218
 	    print '<td colspan="3"><input type="text" name="url" id="url" value="'.$object->url.'"></td></tr>';
1219 1219
 
1220 1220
         // Skype
1221
-        if (! empty($conf->skype->enabled))
1221
+        if (!empty($conf->skype->enabled))
1222 1222
         {
1223
-            print '<tr><td>'.fieldLabel('Skype','skype').'</td>';
1223
+            print '<tr><td>'.fieldLabel('Skype', 'skype').'</td>';
1224 1224
 	        print '<td colspan="3"><input type="text" name="skype" id="skype" value="'.$object->skype.'"></td></tr>';
1225 1225
         }
1226 1226
 
1227 1227
         // Phone / Fax
1228
-        print '<tr><td>'.fieldLabel('Phone','phone').'</td>';
1228
+        print '<tr><td>'.fieldLabel('Phone', 'phone').'</td>';
1229 1229
 	    print '<td><input type="text" name="phone" id="phone" class="maxwidth100onsmartphone quatrevingtpercent" value="'.$object->phone.'"></td>';
1230
-        print '<td>'.fieldLabel('Fax','fax').'</td>';
1230
+        print '<td>'.fieldLabel('Fax', 'fax').'</td>';
1231 1231
 	    print '<td><input type="text" name="fax" id="fax" class="maxwidth100onsmartphone quatrevingtpercent" value="'.$object->fax.'"></td></tr>';
1232 1232
 
1233 1233
         // Prof ids
1234
-        $i=1; $j=0;
1234
+        $i = 1; $j = 0;
1235 1235
         while ($i <= 6)
1236 1236
         {
1237
-            $idprof=$langs->transcountry('ProfId'.$i,$object->country_code);
1238
-            if ($idprof!='-')
1237
+            $idprof = $langs->transcountry('ProfId'.$i, $object->country_code);
1238
+            if ($idprof != '-')
1239 1239
             {
1240
-	            $key='idprof'.$i;
1240
+	            $key = 'idprof'.$i;
1241 1241
 
1242 1242
                 if (($j % 2) == 0) print '<tr>';
1243 1243
 
1244
-                $idprof_mandatory ='SOCIETE_IDPROF'.($i).'_MANDATORY';
1245
-                print '<td>'.fieldLabel($idprof,$key, (empty($conf->global->$idprof_mandatory)?0:1)).'</td><td>';
1244
+                $idprof_mandatory = 'SOCIETE_IDPROF'.($i).'_MANDATORY';
1245
+                print '<td>'.fieldLabel($idprof, $key, (empty($conf->global->$idprof_mandatory) ? 0 : 1)).'</td><td>';
1246 1246
 
1247 1247
                 print $formcompany->get_input_id_prof($i, $key, $object->$key, $object->country_code);
1248 1248
                 print '</td>';
@@ -1254,19 +1254,19 @@  discard block
 block discarded – undo
1254 1254
         if ($j % 2 == 1) print '<td colspan="2"></td></tr>';
1255 1255
 
1256 1256
         // Vat is used
1257
-        print '<tr><td>'.fieldLabel('VATIsUsed','assujtva_value').'</td>';
1257
+        print '<tr><td>'.fieldLabel('VATIsUsed', 'assujtva_value').'</td>';
1258 1258
         print '<td>';
1259
-        print $form->selectyesno('assujtva_value',(isset($conf->global->THIRDPARTY_DEFAULT_USEVAT)?$conf->global->THIRDPARTY_DEFAULT_USEVAT:1),1);     // Assujeti par defaut en creation
1259
+        print $form->selectyesno('assujtva_value', (isset($conf->global->THIRDPARTY_DEFAULT_USEVAT) ? $conf->global->THIRDPARTY_DEFAULT_USEVAT : 1), 1); // Assujeti par defaut en creation
1260 1260
         print '</td>';
1261
-        print '<td class="nowrap">'.fieldLabel('VATIntra','intra_vat').'</td>';
1261
+        print '<td class="nowrap">'.fieldLabel('VATIntra', 'intra_vat').'</td>';
1262 1262
         print '<td class="nowrap">';
1263 1263
         $s = '<input type="text" class="flat maxwidthonsmartphone" name="tva_intra" id="intra_vat" maxlength="20" value="'.$object->tva_intra.'">';
1264 1264
 
1265 1265
         if (empty($conf->global->MAIN_DISABLEVATCHECK) && isInEEC($object))
1266 1266
         {
1267
-            $s.=' ';
1267
+            $s .= ' ';
1268 1268
 
1269
-            if (! empty($conf->use_javascript_ajax))
1269
+            if (!empty($conf->use_javascript_ajax))
1270 1270
             {
1271 1271
                 print "\n";
1272 1272
                 print '<script language="JavaScript" type="text/javascript">';
@@ -1275,12 +1275,12 @@  discard block
 block discarded – undo
1275 1275
                 print "}\n";
1276 1276
                 print '</script>';
1277 1277
                 print "\n";
1278
-                $s.='<a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT(document.formsoc.tva_intra.value);">'.$langs->trans("VATIntraCheck").'</a>';
1279
-                $s = $form->textwithpicto($s,$langs->trans("VATIntraCheckDesc",$langs->trans("VATIntraCheck")),1);
1278
+                $s .= '<a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT(document.formsoc.tva_intra.value);">'.$langs->trans("VATIntraCheck").'</a>';
1279
+                $s = $form->textwithpicto($s, $langs->trans("VATIntraCheckDesc", $langs->trans("VATIntraCheck")), 1);
1280 1280
             }
1281 1281
             else
1282 1282
             {
1283
-                $s.='<a href="'.$langs->transcountry("VATIntraCheckURL",$object->country_id).'" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"),'help').'</a>';
1283
+                $s .= '<a href="'.$langs->transcountry("VATIntraCheckURL", $object->country_id).'" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"), 'help').'</a>';
1284 1284
             }
1285 1285
         }
1286 1286
         print $s;
@@ -1289,41 +1289,41 @@  discard block
 block discarded – undo
1289 1289
 
1290 1290
         // Local Taxes
1291 1291
         //TODO: Place into a function to control showing by country or study better option
1292
-        if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1")
1292
+        if ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj == "1")
1293 1293
         {
1294
-            print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed",$mysoc->country_code).'</td><td>';
1295
-            print $form->selectyesno('localtax1assuj_value',(isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1)?$conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1:0),1);
1296
-            print '</td><td>'.$langs->transcountry("LocalTax2IsUsed",$mysoc->country_code).'</td><td>';
1297
-            print $form->selectyesno('localtax2assuj_value',(isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2)?$conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2:0),1);
1294
+            print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td>';
1295
+            print $form->selectyesno('localtax1assuj_value', (isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1) ? $conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1 : 0), 1);
1296
+            print '</td><td>'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td>';
1297
+            print $form->selectyesno('localtax2assuj_value', (isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2) ? $conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2 : 0), 1);
1298 1298
             print '</td></tr>';
1299 1299
 
1300 1300
         }
1301
-        elseif($mysoc->localtax1_assuj=="1")
1301
+        elseif ($mysoc->localtax1_assuj == "1")
1302 1302
         {
1303
-            print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed",$mysoc->country_code).'</td><td colspan="3">';
1304
-            print $form->selectyesno('localtax1assuj_value',(isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1)?$conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1:0),1);
1303
+            print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td colspan="3">';
1304
+            print $form->selectyesno('localtax1assuj_value', (isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1) ? $conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1 : 0), 1);
1305 1305
             print '</td></tr>';
1306 1306
         }
1307
-        elseif($mysoc->localtax2_assuj=="1")
1307
+        elseif ($mysoc->localtax2_assuj == "1")
1308 1308
         {
1309
-            print '<tr><td>'.$langs->transcountry("LocalTax2IsUsed",$mysoc->country_code).'</td><td colspan="3">';
1310
-            print $form->selectyesno('localtax2assuj_value',(isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2)?$conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2:0),1);
1309
+            print '<tr><td>'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td colspan="3">';
1310
+            print $form->selectyesno('localtax2assuj_value', (isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2) ? $conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2 : 0), 1);
1311 1311
             print '</td></tr>';
1312 1312
         }
1313 1313
 
1314 1314
         // Type - Size
1315
-        print '<tr><td>'.fieldLabel('ThirdPartyType','typent_id').'</td><td class="maxwidthonsmartphone">'."\n";
1316
-        $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.
1315
+        print '<tr><td>'.fieldLabel('ThirdPartyType', 'typent_id').'</td><td class="maxwidthonsmartphone">'."\n";
1316
+        $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.
1317 1317
         print $form->selectarray("typent_id", $formcompany->typent_array(0), $object->typent_id, 0, 0, 0, '', 0, 0, 0, $sortparam);
1318
-        if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1318
+        if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1319 1319
         print '</td>';
1320
-        print '<td>'.fieldLabel('Staff','effectif_id').'</td><td class="maxwidthonsmartphone">';
1320
+        print '<td>'.fieldLabel('Staff', 'effectif_id').'</td><td class="maxwidthonsmartphone">';
1321 1321
         print $form->selectarray("effectif_id", $formcompany->effectif_array(0), $object->effectif_id);
1322
-        if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1322
+        if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1323 1323
         print '</td></tr>';
1324 1324
 
1325 1325
         // Legal Form
1326
-        print '<tr><td>'.fieldLabel('JuridicalStatus','forme_juridique_code').'</td>';
1326
+        print '<tr><td>'.fieldLabel('JuridicalStatus', 'forme_juridique_code').'</td>';
1327 1327
         print '<td colspan="3" class="maxwidthonsmartphone">';
1328 1328
         if ($object->country_id)
1329 1329
         {
@@ -1336,14 +1336,14 @@  discard block
 block discarded – undo
1336 1336
         print '</td></tr>';
1337 1337
 
1338 1338
         // Capital
1339
-        print '<tr><td>'.fieldLabel('Capital','capital').'</td>';
1339
+        print '<tr><td>'.fieldLabel('Capital', 'capital').'</td>';
1340 1340
 	    print '<td colspan="3"><input type="text" name="capital" id="capital" size="10" value="'.$object->capital.'"> ';
1341 1341
         print '<span class="hideonsmartphone">'.$langs->trans("Currency".$conf->currency).'</span></td></tr>';
1342 1342
 
1343
-        if (! empty($conf->global->MAIN_MULTILANGS))
1343
+        if (!empty($conf->global->MAIN_MULTILANGS))
1344 1344
         {
1345
-            print '<tr><td>'.fieldLabel('DefaultLang','default_lang').'</td><td colspan="3" class="maxwidthonsmartphone">'."\n";
1346
-            print $formadmin->select_language(($object->default_lang?$object->default_lang:$conf->global->MAIN_LANG_DEFAULT),'default_lang',0,0,1,0,0,'maxwidth200onsmartphone');
1345
+            print '<tr><td>'.fieldLabel('DefaultLang', 'default_lang').'</td><td colspan="3" class="maxwidthonsmartphone">'."\n";
1346
+            print $formadmin->select_language(($object->default_lang ? $object->default_lang : $conf->global->MAIN_LANG_DEFAULT), 'default_lang', 0, 0, 1, 0, 0, 'maxwidth200onsmartphone');
1347 1347
             print '</td>';
1348 1348
             print '</tr>';
1349 1349
         }
@@ -1352,9 +1352,9 @@  discard block
 block discarded – undo
1352 1352
         {
1353 1353
             // Assign a Name
1354 1354
             print '<tr>';
1355
-            print '<td>'.fieldLabel('AllocateCommercial','commercial_id').'</td>';
1355
+            print '<td>'.fieldLabel('AllocateCommercial', 'commercial_id').'</td>';
1356 1356
             print '<td colspan="3" class="maxwidthonsmartphone">';
1357
-            print $form->select_dolusers((! empty($object->commercial_id)?$object->commercial_id:$user->id),'commercial_id',1); // Add current user by default
1357
+            print $form->select_dolusers((!empty($object->commercial_id) ? $object->commercial_id : $user->id), 'commercial_id', 1); // Add current user by default
1358 1358
             print '</td></tr>';
1359 1359
         }
1360 1360
 
@@ -1362,20 +1362,20 @@  discard block
 block discarded – undo
1362 1362
 		if (!empty($conf->incoterm->enabled))
1363 1363
 		{
1364 1364
 			print '<tr>';
1365
-			print '<td>'.fieldLabel('IncotermLabel','incoterm_id').'</td>';
1365
+			print '<td>'.fieldLabel('IncotermLabel', 'incoterm_id').'</td>';
1366 1366
 	        print '<td colspan="3" class="maxwidthonsmartphone">';
1367
-	        print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''));
1367
+	        print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''));
1368 1368
 			print '</td></tr>';
1369 1369
 		}
1370 1370
 
1371 1371
 		// Categories
1372
-		if (! empty($conf->categorie->enabled)  && ! empty($user->rights->categorie->lire))
1372
+		if (!empty($conf->categorie->enabled) && !empty($user->rights->categorie->lire))
1373 1373
 		{
1374 1374
 			$langs->load('categories');
1375 1375
 
1376 1376
 			// Customer
1377 1377
 			if ($object->prospect || $object->client) {
1378
-				print '<tr><td class="toptd">' . fieldLabel('CustomersCategoriesShort', 'custcats') . '</td><td colspan="3">';
1378
+				print '<tr><td class="toptd">'.fieldLabel('CustomersCategoriesShort', 'custcats').'</td><td colspan="3">';
1379 1379
 				$cate_arbo = $form->select_all_categories(Categorie::TYPE_CUSTOMER, null, 'parent', null, null, 1);
1380 1380
 				print $form->multiselectarray('custcats', $cate_arbo, GETPOST('custcats', 'array'), null, null, null,
1381 1381
 					null, "90%");
@@ -1384,7 +1384,7 @@  discard block
 block discarded – undo
1384 1384
 
1385 1385
 			// Supplier
1386 1386
 			if ($object->fournisseur) {
1387
-				print '<tr><td class="toptd">' . fieldLabel('SuppliersCategoriesShort', 'suppcats') . '</td><td colspan="3">';
1387
+				print '<tr><td class="toptd">'.fieldLabel('SuppliersCategoriesShort', 'suppcats').'</td><td colspan="3">';
1388 1388
 				$cate_arbo = $form->select_all_categories(Categorie::TYPE_SUPPLIER, null, 'parent', null, null, 1);
1389 1389
 				print $form->multiselectarray('suppcats', $cate_arbo, GETPOST('suppcats', 'array'), null, null, null,
1390 1390
 					null, "90%");
@@ -1393,27 +1393,27 @@  discard block
 block discarded – undo
1393 1393
 		}
1394 1394
 
1395 1395
 		// Multicurrency
1396
-		if (! empty($conf->multicurrency->enabled))
1396
+		if (!empty($conf->multicurrency->enabled))
1397 1397
 		{
1398 1398
 			print '<tr>';
1399
-			print '<td>'.fieldLabel('Currency','multicurrency_code').'</td>';
1399
+			print '<td>'.fieldLabel('Currency', 'multicurrency_code').'</td>';
1400 1400
 	        print '<td colspan="3" class="maxwidthonsmartphone">';
1401 1401
 	        print $form->selectMultiCurrency(($object->multicurrency_code ? $object->multicurrency_code : $conf->currency), 'multicurrency_code', 1);
1402 1402
 			print '</td></tr>';
1403 1403
 		}
1404 1404
 
1405 1405
         // Other attributes
1406
-        $parameters=array('colspan' => ' colspan="3"', 'colspanvalue' => '3');
1407
-        $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
1406
+        $parameters = array('colspan' => ' colspan="3"', 'colspanvalue' => '3');
1407
+        $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1408 1408
         print $hookmanager->resPrint;
1409
-        if (empty($reshook) && ! empty($extrafields->attribute_label))
1409
+        if (empty($reshook) && !empty($extrafields->attribute_label))
1410 1410
         {
1411
-        	print $object->showOptionals($extrafields,'edit');
1411
+        	print $object->showOptionals($extrafields, 'edit');
1412 1412
         }
1413 1413
 
1414 1414
         // Ajout du logo
1415 1415
         print '<tr class="hideonsmartphone">';
1416
-        print '<td>'.fieldLabel('Logo','photoinput').'</td>';
1416
+        print '<td>'.fieldLabel('Logo', 'photoinput').'</td>';
1417 1417
         print '<td colspan="3">';
1418 1418
         print '<input class="flat" type="file" name="photo" id="photoinput" />';
1419 1419
         print '</td>';
@@ -1425,7 +1425,7 @@  discard block
 block discarded – undo
1425 1425
 
1426 1426
         print '<div class="center">';
1427 1427
         print '<input type="submit" class="button" name="create" value="'.$langs->trans('AddThirdParty').'">';
1428
-        if (! empty($backtopage))
1428
+        if (!empty($backtopage))
1429 1429
         {
1430 1430
             print ' &nbsp; &nbsp; ';
1431 1431
             print '<input type="submit" class="button" name="cancel" value="'.$langs->trans('Cancel').'">';
@@ -1433,7 +1433,7 @@  discard block
 block discarded – undo
1433 1433
         else
1434 1434
         {
1435 1435
             print ' &nbsp; &nbsp; ';
1436
-            print '<input type="button" class="button" value="' . $langs->trans("Cancel") . '" onClick="javascript:history.go(-1)">';
1436
+            print '<input type="button" class="button" value="'.$langs->trans("Cancel").'" onClick="javascript:history.go(-1)">';
1437 1437
         }
1438 1438
         print '</div>'."\n";
1439 1439
 
@@ -1450,21 +1450,21 @@  discard block
 block discarded – undo
1450 1450
 
1451 1451
         if ($socid)
1452 1452
         {
1453
-        	$res=$object->fetch_optionals();
1453
+        	$res = $object->fetch_optionals();
1454 1454
             //if ($res < 0) { dol_print_error($db); exit; }
1455 1455
 
1456 1456
 	        $head = societe_prepare_head($object);
1457 1457
 
1458 1458
             // Load object modCodeTiers
1459
-            $module=(! empty($conf->global->SOCIETE_CODECLIENT_ADDON)?$conf->global->SOCIETE_CODECLIENT_ADDON:'mod_codeclient_leopard');
1459
+            $module = (!empty($conf->global->SOCIETE_CODECLIENT_ADDON) ? $conf->global->SOCIETE_CODECLIENT_ADDON : 'mod_codeclient_leopard');
1460 1460
             if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php')
1461 1461
             {
1462
-                $module = substr($module, 0, dol_strlen($module)-4);
1462
+                $module = substr($module, 0, dol_strlen($module) - 4);
1463 1463
             }
1464
-            $dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
1464
+            $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
1465 1465
             foreach ($dirsociete as $dirroot)
1466 1466
             {
1467
-                $res=dol_include_once($dirroot.$module.'.php');
1467
+                $res = dol_include_once($dirroot.$module.'.php');
1468 1468
                 if ($res) break;
1469 1469
             }
1470 1470
             $modCodeClient = new $module($db);
@@ -1473,15 +1473,15 @@  discard block
 block discarded – undo
1473 1473
             {
1474 1474
                 $prefixCustomerIsUsed = $modCodeClient->verif_prefixIsUsed();
1475 1475
             }
1476
-            $module=$conf->global->SOCIETE_CODECLIENT_ADDON;
1476
+            $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
1477 1477
             if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php')
1478 1478
             {
1479
-                $module = substr($module, 0, dol_strlen($module)-4);
1479
+                $module = substr($module, 0, dol_strlen($module) - 4);
1480 1480
             }
1481
-            $dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
1481
+            $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
1482 1482
             foreach ($dirsociete as $dirroot)
1483 1483
             {
1484
-                $res=dol_include_once($dirroot.$module.'.php');
1484
+                $res = dol_include_once($dirroot.$module.'.php');
1485 1485
                 if ($res) break;
1486 1486
             }
1487 1487
             $modCodeFournisseur = new $module($db);
@@ -1496,17 +1496,17 @@  discard block
 block discarded – undo
1496 1496
             if (GETPOSTISSET('name'))
1497 1497
             {
1498 1498
                 // We overwrite with values if posted
1499
-                $object->name					= GETPOST('name', 'alpha');
1499
+                $object->name = GETPOST('name', 'alpha');
1500 1500
                 $object->prefix_comm			= GETPOST('prefix_comm', 'alpha');
1501
-                $object->client					= GETPOST('client', 'int');
1501
+                $object->client = GETPOST('client', 'int');
1502 1502
                 $object->code_client			= GETPOST('code_client', 'alpha');
1503 1503
                 $object->fournisseur			= GETPOST('fournisseur', 'int');
1504
-                $object->code_fournisseur		= GETPOST('code_fournisseur', 'alpha');
1505
-                $object->address				= GETPOST('address', 'alpha');
1506
-                $object->zip					= GETPOST('zipcode', 'alpha');
1507
-                $object->town					= GETPOST('town', 'alpha');
1508
-                $object->country_id				= GETPOST('country_id')?GETPOST('country_id', 'int'):$mysoc->country_id;
1509
-                $object->state_id				= GETPOST('state_id', 'int');
1504
+                $object->code_fournisseur = GETPOST('code_fournisseur', 'alpha');
1505
+                $object->address = GETPOST('address', 'alpha');
1506
+                $object->zip = GETPOST('zipcode', 'alpha');
1507
+                $object->town = GETPOST('town', 'alpha');
1508
+                $object->country_id = GETPOST('country_id') ?GETPOST('country_id', 'int') : $mysoc->country_id;
1509
+                $object->state_id = GETPOST('state_id', 'int');
1510 1510
                 $object->skype					= GETPOST('skype', 'alpha');
1511 1511
                 $object->phone					= GETPOST('phone', 'alpha');
1512 1512
                 $object->fax					= GETPOST('fax', 'alpha');
@@ -1519,15 +1519,15 @@  discard block
 block discarded – undo
1519 1519
                 $object->idprof4				= GETPOST('idprof4', 'alpha');
1520 1520
                 $object->idprof5				= GETPOST('idprof5', 'alpha');
1521 1521
                 $object->idprof6				= GETPOST('idprof6', 'alpha');
1522
-                $object->typent_id				= GETPOST('typent_id', 'int');
1523
-                $object->effectif_id			= GETPOST('effectif_id', 'int');
1522
+                $object->typent_id = GETPOST('typent_id', 'int');
1523
+                $object->effectif_id = GETPOST('effectif_id', 'int');
1524 1524
                 $object->barcode				= GETPOST('barcode', 'alpha');
1525
-                $object->forme_juridique_code	= GETPOST('forme_juridique_code', 'int');
1526
-                $object->default_lang			= GETPOST('default_lang', 'alpha');
1525
+                $object->forme_juridique_code = GETPOST('forme_juridique_code', 'int');
1526
+                $object->default_lang = GETPOST('default_lang', 'alpha');
1527 1527
 
1528 1528
                 $object->tva_assuj				= GETPOST('assujtva_value', 'int');
1529 1529
                 $object->tva_intra				= GETPOST('tva_intra', 'alpha');
1530
-                $object->status					= GETPOST('status', 'int');
1530
+                $object->status = GETPOST('status', 'int');
1531 1531
 
1532 1532
                 // Webservices url/key
1533 1533
                 $object->webservices_url        = GETPOST('webservices_url', 'custom', 0, FILTER_SANITIZE_URL);
@@ -1536,32 +1536,32 @@  discard block
 block discarded – undo
1536 1536
 				//Incoterms
1537 1537
 				if (!empty($conf->incoterm->enabled))
1538 1538
 				{
1539
-					$object->fk_incoterms			= GETPOST('incoterm_id', 'int');
1540
-					$object->location_incoterms		= GETPOST('lcoation_incoterms', 'alpha');
1539
+					$object->fk_incoterms = GETPOST('incoterm_id', 'int');
1540
+					$object->location_incoterms = GETPOST('lcoation_incoterms', 'alpha');
1541 1541
 				}
1542 1542
 
1543 1543
                 //Local Taxes
1544 1544
                 $object->localtax1_assuj		= GETPOST('localtax1assuj_value');
1545 1545
                 $object->localtax2_assuj		= GETPOST('localtax2assuj_value');
1546 1546
 
1547
-                $object->localtax1_value		=GETPOST('lt1');
1548
-                $object->localtax2_value		=GETPOST('lt2');
1547
+                $object->localtax1_value		= GETPOST('lt1');
1548
+                $object->localtax2_value		= GETPOST('lt2');
1549 1549
 
1550 1550
                 // We set country_id, and country_code label of the chosen country
1551 1551
                 if ($object->country_id > 0)
1552 1552
                 {
1553
-                	$tmparray=getCountry($object->country_id,'all');
1554
-                    $object->country_code	= $tmparray['code'];
1555
-                    $object->country		= $tmparray['label'];
1553
+                	$tmparray = getCountry($object->country_id, 'all');
1554
+                    $object->country_code = $tmparray['code'];
1555
+                    $object->country = $tmparray['label'];
1556 1556
                 }
1557 1557
             }
1558 1558
 
1559
-            if($object->localtax1_assuj==0){
1560
-            	$sub=0;
1561
-            }else{$sub=1;}
1562
-            if($object->localtax2_assuj==0){
1563
-            	$sub2=0;
1564
-            }else{$sub2=1;}
1559
+            if ($object->localtax1_assuj == 0) {
1560
+            	$sub = 0;
1561
+            } else {$sub = 1; }
1562
+            if ($object->localtax2_assuj == 0) {
1563
+            	$sub2 = 0;
1564
+            } else {$sub2 = 1; }
1565 1565
 
1566 1566
             print "\n".'<script type="text/javascript">';
1567 1567
             print '$(document).ready(function () {
@@ -1627,7 +1627,7 @@  discard block
 block discarded – undo
1627 1627
             print '<table class="border" width="100%">';
1628 1628
 
1629 1629
             // Ref/ID
1630
-			if (! empty($conf->global->MAIN_SHOW_TECHNICAL_ID))
1630
+			if (!empty($conf->global->MAIN_SHOW_TECHNICAL_ID))
1631 1631
 			{
1632 1632
 		        print '<tr><td class="titlefieldcreate">'.$langs->trans("ID").'</td><td colspan="3">';
1633 1633
             	print $object->ref;
@@ -1635,7 +1635,7 @@  discard block
 block discarded – undo
1635 1635
 			}
1636 1636
 
1637 1637
             // Name
1638
-            print '<tr><td class="titlefieldcreate">'.fieldLabel('ThirdPartyName','name',1).'</td>';
1638
+            print '<tr><td class="titlefieldcreate">'.fieldLabel('ThirdPartyName', 'name', 1).'</td>';
1639 1639
 	        print '<td colspan="3"><input type="text" class="minwidth300" maxlength="128" name="name" id="name" value="'.dol_escape_htmltag($object->name).'" autofocus="autofocus"></td></tr>';
1640 1640
 
1641 1641
 	        // Alias names (commercial, trademark or alias names)
@@ -1643,9 +1643,9 @@  discard block
 block discarded – undo
1643 1643
 	        print '<td colspan="3"><input type="text" class="minwidth300" name="name_alias" id="name_alias_input" value="'.dol_escape_htmltag($object->name_alias).'"></td></tr>';
1644 1644
 
1645 1645
             // Prefix
1646
-            if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
1646
+            if (!empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
1647 1647
             {
1648
-                print '<tr><td>'.fieldLabel('Prefix','prefix').'</td><td colspan="3">';
1648
+                print '<tr><td>'.fieldLabel('Prefix', 'prefix').'</td><td colspan="3">';
1649 1649
                 // It does not change the prefix mode using the auto numbering prefix
1650 1650
                 if (($prefixCustomerIsUsed || $prefixSupplierIsUsed) && $object->prefix_comm)
1651 1651
                 {
@@ -1660,21 +1660,21 @@  discard block
 block discarded – undo
1660 1660
             }
1661 1661
 
1662 1662
             // Prospect/Customer
1663
-            print '<tr><td>'.fieldLabel('ProspectCustomer','customerprospect',1).'</td>';
1663
+            print '<tr><td>'.fieldLabel('ProspectCustomer', 'customerprospect', 1).'</td>';
1664 1664
 	        print '<td class="maxwidthonsmartphone"><select class="flat" name="client" id="customerprospect">';
1665
-            if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) print '<option value="2"'.($object->client==2?' selected':'').'>'.$langs->trans('Prospect').'</option>';
1666
-            if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print '<option value="3"'.($object->client==3?' selected':'').'>'.$langs->trans('ProspectCustomer').'</option>';
1667
-            if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print '<option value="1"'.($object->client==1?' selected':'').'>'.$langs->trans('Customer').'</option>';
1668
-            print '<option value="0"'.($object->client==0?' selected':'').'>'.$langs->trans('NorProspectNorCustomer').'</option>';
1665
+            if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) print '<option value="2"'.($object->client == 2 ? ' selected' : '').'>'.$langs->trans('Prospect').'</option>';
1666
+            if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print '<option value="3"'.($object->client == 3 ? ' selected' : '').'>'.$langs->trans('ProspectCustomer').'</option>';
1667
+            if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print '<option value="1"'.($object->client == 1 ? ' selected' : '').'>'.$langs->trans('Customer').'</option>';
1668
+            print '<option value="0"'.($object->client == 0 ? ' selected' : '').'>'.$langs->trans('NorProspectNorCustomer').'</option>';
1669 1669
             print '</select></td>';
1670
-            print '<td>'.fieldLabel('CustomerCode','customer_code').'</td><td>';
1670
+            print '<td>'.fieldLabel('CustomerCode', 'customer_code').'</td><td>';
1671 1671
 
1672 1672
             print '<table class="nobordernopadding"><tr><td>';
1673 1673
             if ((!$object->code_client || $object->code_client == -1) && $modCodeClient->code_auto)
1674 1674
             {
1675
-                $tmpcode=$object->code_client;
1676
-                if (empty($tmpcode) && ! empty($object->oldcopy->code_client)) $tmpcode=$object->oldcopy->code_client; // When there is an error to update a thirdparty, the number for supplier and customer code is kept to old value.
1677
-                if (empty($tmpcode) && ! empty($modCodeClient->code_auto)) $tmpcode=$modCodeClient->getNextValue($object,0);
1675
+                $tmpcode = $object->code_client;
1676
+                if (empty($tmpcode) && !empty($object->oldcopy->code_client)) $tmpcode = $object->oldcopy->code_client; // When there is an error to update a thirdparty, the number for supplier and customer code is kept to old value.
1677
+                if (empty($tmpcode) && !empty($modCodeClient->code_auto)) $tmpcode = $modCodeClient->getNextValue($object, 0);
1678 1678
                 print '<input type="text" name="code_client" id="customer_code" size="16" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
1679 1679
             }
1680 1680
             else if ($object->codeclient_modifiable())
@@ -1687,27 +1687,27 @@  discard block
 block discarded – undo
1687 1687
                 print '<input type="hidden" name="code_client" value="'.$object->code_client.'">';
1688 1688
             }
1689 1689
             print '</td><td>';
1690
-            $s=$modCodeClient->getToolTip($langs,$object,0);
1691
-            print $form->textwithpicto('',$s,1);
1690
+            $s = $modCodeClient->getToolTip($langs, $object, 0);
1691
+            print $form->textwithpicto('', $s, 1);
1692 1692
             print '</td></tr></table>';
1693 1693
 
1694 1694
             print '</td></tr>';
1695 1695
 
1696 1696
             // Supplier
1697
-            if (! empty($conf->fournisseur->enabled) && ! empty($user->rights->fournisseur->lire))
1697
+            if (!empty($conf->fournisseur->enabled) && !empty($user->rights->fournisseur->lire))
1698 1698
             {
1699 1699
                 print '<tr>';
1700
-                print '<td>'.fieldLabel('Supplier','fournisseur',1).'</td><td class="maxwidthonsmartphone">';
1701
-                print $form->selectyesno("fournisseur",$object->fournisseur,1);
1700
+                print '<td>'.fieldLabel('Supplier', 'fournisseur', 1).'</td><td class="maxwidthonsmartphone">';
1701
+                print $form->selectyesno("fournisseur", $object->fournisseur, 1);
1702 1702
                 print '</td>';
1703
-                print '<td>'.fieldLabel('SupplierCode','supplier_code').'</td><td>';
1703
+                print '<td>'.fieldLabel('SupplierCode', 'supplier_code').'</td><td>';
1704 1704
 
1705 1705
                 print '<table class="nobordernopadding"><tr><td>';
1706 1706
                 if ((!$object->code_fournisseur || $object->code_fournisseur == -1) && $modCodeFournisseur->code_auto)
1707 1707
                 {
1708
-                    $tmpcode=$object->code_fournisseur;
1709
-                    if (empty($tmpcode) && ! empty($object->oldcopy->code_fournisseur)) $tmpcode=$object->oldcopy->code_fournisseur; // When there is an error to update a thirdparty, the number for supplier and customer code is kept to old value.
1710
-                    if (empty($tmpcode) && ! empty($modCodeFournisseur->code_auto)) $tmpcode=$modCodeFournisseur->getNextValue($object,1);
1708
+                    $tmpcode = $object->code_fournisseur;
1709
+                    if (empty($tmpcode) && !empty($object->oldcopy->code_fournisseur)) $tmpcode = $object->oldcopy->code_fournisseur; // When there is an error to update a thirdparty, the number for supplier and customer code is kept to old value.
1710
+                    if (empty($tmpcode) && !empty($modCodeFournisseur->code_auto)) $tmpcode = $modCodeFournisseur->getNextValue($object, 1);
1711 1711
                     print '<input type="text" name="code_fournisseur" id="supplier_code" size="16" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
1712 1712
                 }
1713 1713
                 else if ($object->codefournisseur_modifiable())
@@ -1720,98 +1720,98 @@  discard block
 block discarded – undo
1720 1720
                     print '<input type="hidden" name="code_fournisseur" value="'.$object->code_fournisseur.'">';
1721 1721
                 }
1722 1722
                 print '</td><td>';
1723
-                $s=$modCodeFournisseur->getToolTip($langs,$object,1);
1724
-                print $form->textwithpicto('',$s,1);
1723
+                $s = $modCodeFournisseur->getToolTip($langs, $object, 1);
1724
+                print $form->textwithpicto('', $s, 1);
1725 1725
                 print '</td></tr></table>';
1726 1726
 
1727 1727
                 print '</td></tr>';
1728 1728
             }
1729 1729
 
1730 1730
             // Barcode
1731
-            if (! empty($conf->barcode->enabled))
1731
+            if (!empty($conf->barcode->enabled))
1732 1732
             {
1733
-                print '<tr><td class="tdtop">'.fieldLabel('Gencod','barcode').'</td>';
1733
+                print '<tr><td class="tdtop">'.fieldLabel('Gencod', 'barcode').'</td>';
1734 1734
 	            print '<td colspan="3"><input type="text" name="barcode" id="barcode" value="'.$object->barcode.'">';
1735 1735
                 print '</td></tr>';
1736 1736
             }
1737 1737
 
1738 1738
             // Status
1739
-            print '<tr><td>'.fieldLabel('Status','status').'</td><td colspan="3">';
1740
-            print $form->selectarray('status', array('0'=>$langs->trans('ActivityCeased'),'1'=>$langs->trans('InActivity')),$object->status);
1739
+            print '<tr><td>'.fieldLabel('Status', 'status').'</td><td colspan="3">';
1740
+            print $form->selectarray('status', array('0'=>$langs->trans('ActivityCeased'), '1'=>$langs->trans('InActivity')), $object->status);
1741 1741
             print '</td></tr>';
1742 1742
 
1743 1743
             // Address
1744
-            print '<tr><td class="tdtop">'.fieldLabel('Address','address').'</td>';
1744
+            print '<tr><td class="tdtop">'.fieldLabel('Address', 'address').'</td>';
1745 1745
 	        print '<td colspan="3"><textarea name="address" id="address" class="quatrevingtpercent" rows="3" wrap="soft">';
1746 1746
             print $object->address;
1747 1747
             print '</textarea></td></tr>';
1748 1748
 
1749 1749
             // Zip / Town
1750
-            print '<tr><td>'.fieldLabel('Zip','zipcode').'</td><td>';
1750
+            print '<tr><td>'.fieldLabel('Zip', 'zipcode').'</td><td>';
1751 1751
             print $formcompany->select_ziptown($object->zip, 'zipcode', array('town', 'selectcountry_id', 'state_id'), 0, 0, '', 'maxwidth50onsmartphone');
1752
-            print '</td><td>'.fieldLabel('Town','town').'</td><td>';
1752
+            print '</td><td>'.fieldLabel('Town', 'town').'</td><td>';
1753 1753
             print $formcompany->select_ziptown($object->town, 'town', array('zipcode', 'selectcountry_id', 'state_id'));
1754 1754
             print '</td></tr>';
1755 1755
 
1756 1756
             // Country
1757
-            print '<tr><td>'.fieldLabel('Country','selectcounty_id').'</td><td colspan="3">';
1758
-            print $form->select_country((GETPOST('country_id')!=''?GETPOST('country_id'):$object->country_id),'country_id');
1759
-            if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1757
+            print '<tr><td>'.fieldLabel('Country', 'selectcounty_id').'</td><td colspan="3">';
1758
+            print $form->select_country((GETPOST('country_id') != '' ?GETPOST('country_id') : $object->country_id), 'country_id');
1759
+            if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1760 1760
             print '</td></tr>';
1761 1761
 
1762 1762
             // State
1763 1763
             if (empty($conf->global->SOCIETE_DISABLE_STATE))
1764 1764
             {
1765
-                if(!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && ($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 || $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 2))
1765
+                if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && ($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 || $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 2))
1766 1766
                 {
1767
-                    print '<tr><td>'.fieldLabel('Region-State','state_id').'</td><td colspan="3">';
1767
+                    print '<tr><td>'.fieldLabel('Region-State', 'state_id').'</td><td colspan="3">';
1768 1768
                 }
1769 1769
                 else
1770 1770
                 {
1771
-                    print '<tr><td>'.fieldLabel('State','state_id').'</td><td colspan="3">';
1771
+                    print '<tr><td>'.fieldLabel('State', 'state_id').'</td><td colspan="3">';
1772 1772
                 }
1773 1773
 
1774
-                print $formcompany->select_state($object->state_id,$object->country_code);
1774
+                print $formcompany->select_state($object->state_id, $object->country_code);
1775 1775
                 print '</td></tr>';
1776 1776
             }
1777 1777
 
1778 1778
             // EMail / Web
1779
-            print '<tr><td>'.fieldLabel('EMail','email',(! empty($conf->global->SOCIETE_EMAIL_MANDATORY))).'</td>';
1779
+            print '<tr><td>'.fieldLabel('EMail', 'email', (!empty($conf->global->SOCIETE_EMAIL_MANDATORY))).'</td>';
1780 1780
 	        print '<td colspan="3"><input type="text" name="email" id="email" size="32" value="'.$object->email.'"></td></tr>';
1781
-            print '<tr><td>'.fieldLabel('Web','url').'</td>';
1781
+            print '<tr><td>'.fieldLabel('Web', 'url').'</td>';
1782 1782
 	        print '<td colspan="3"><input type="text" name="url" id="url" size="32" value="'.$object->url.'"></td></tr>';
1783 1783
 
1784 1784
             // Skype
1785
-            if (! empty($conf->skype->enabled))
1785
+            if (!empty($conf->skype->enabled))
1786 1786
             {
1787
-                print '<tr><td>'.fieldLabel('Skype','skype').'</td>';
1787
+                print '<tr><td>'.fieldLabel('Skype', 'skype').'</td>';
1788 1788
 	            print '<td colspan="3"><input type="text" name="skype" id="skype" size="32" value="'.$object->skype.'"></td></tr>';
1789 1789
             }
1790 1790
 
1791 1791
             // Phone / Fax
1792
-            print '<tr><td>'.fieldLabel('Phone','phone').'</td>';
1792
+            print '<tr><td>'.fieldLabel('Phone', 'phone').'</td>';
1793 1793
 	        print '<td><input type="text" name="phone" id="phone" class="maxwidth100onsmartphone quatrevingtpercent" value="'.$object->phone.'"></td>';
1794
-            print '<td>'.fieldLabel('Fax','fax').'</td>';
1794
+            print '<td>'.fieldLabel('Fax', 'fax').'</td>';
1795 1795
 	        print '<td><input type="text" name="fax" id="fax" class="maxwidth100onsmartphone quatrevingtpercent" value="'.$object->fax.'"></td></tr>';
1796 1796
 
1797 1797
             // Prof ids
1798
-            $i=1; $j=0;
1798
+            $i = 1; $j = 0;
1799 1799
             while ($i <= 6)
1800 1800
             {
1801
-                $idprof=$langs->transcountry('ProfId'.$i,$object->country_code);
1802
-                if ($idprof!='-')
1801
+                $idprof = $langs->transcountry('ProfId'.$i, $object->country_code);
1802
+                if ($idprof != '-')
1803 1803
                 {
1804
-	                $key='idprof'.$i;
1804
+	                $key = 'idprof'.$i;
1805 1805
 
1806 1806
 	                if (($j % 2) == 0) print '<tr>';
1807 1807
 
1808
-	                $idprof_mandatory ='SOCIETE_IDPROF'.($i).'_MANDATORY';
1809
-	                if (empty($conf->global->$idprof_mandatory) || ! $object->isACompany())
1810
-	                    print '<td>'.fieldLabel($idprof,$key).'</td><td>';
1808
+	                $idprof_mandatory = 'SOCIETE_IDPROF'.($i).'_MANDATORY';
1809
+	                if (empty($conf->global->$idprof_mandatory) || !$object->isACompany())
1810
+	                    print '<td>'.fieldLabel($idprof, $key).'</td><td>';
1811 1811
                     else
1812
-	                    print '<td><span class="fieldrequired">'.fieldLabel($idprof,$key).'</td><td>';
1812
+	                    print '<td><span class="fieldrequired">'.fieldLabel($idprof, $key).'</td><td>';
1813 1813
 
1814
-	                print $formcompany->get_input_id_prof($i,$key,$object->$key,$object->country_code);
1814
+	                print $formcompany->get_input_id_prof($i, $key, $object->$key, $object->country_code);
1815 1815
                     print '</td>';
1816 1816
                     if (($j % 2) == 1) print '</tr>';
1817 1817
                     $j++;
@@ -1821,69 +1821,69 @@  discard block
 block discarded – undo
1821 1821
             if ($j % 2 == 1) print '<td colspan="2"></td></tr>';
1822 1822
 
1823 1823
             // VAT is used
1824
-            print '<tr><td>'.fieldLabel('VATIsUsed','assujtva_value').'</td><td colspan="3">';
1825
-            print $form->selectyesno('assujtva_value',$object->tva_assuj,1);
1824
+            print '<tr><td>'.fieldLabel('VATIsUsed', 'assujtva_value').'</td><td colspan="3">';
1825
+            print $form->selectyesno('assujtva_value', $object->tva_assuj, 1);
1826 1826
             print '</td></tr>';
1827 1827
 
1828 1828
             // Local Taxes
1829 1829
             //TODO: Place into a function to control showing by country or study better option
1830
-            if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1")
1830
+            if ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj == "1")
1831 1831
             {
1832
-                print '<tr><td>'.fieldLabel($langs->transcountry("LocalTax1IsUsed",$mysoc->country_code),'localtax1assuj_value').'</td><td>';
1833
-                print $form->selectyesno('localtax1assuj_value',$object->localtax1_assuj,1);
1834
-                if(! isOnlyOneLocalTax(1))
1832
+                print '<tr><td>'.fieldLabel($langs->transcountry("LocalTax1IsUsed", $mysoc->country_code), 'localtax1assuj_value').'</td><td>';
1833
+                print $form->selectyesno('localtax1assuj_value', $object->localtax1_assuj, 1);
1834
+                if (!isOnlyOneLocalTax(1))
1835 1835
                 {
1836
-                    print '<span class="cblt1">     '.$langs->transcountry("Type",$mysoc->country_code).': ';
1837
-                    $formcompany->select_localtax(1,$object->localtax1_value, "lt1");
1836
+                    print '<span class="cblt1">     '.$langs->transcountry("Type", $mysoc->country_code).': ';
1837
+                    $formcompany->select_localtax(1, $object->localtax1_value, "lt1");
1838 1838
                     print '</span>';
1839 1839
                 }
1840 1840
                 print '</td>';
1841 1841
 
1842
-                print '<td>'.fieldLabel($langs->transcountry("LocalTax2IsUsed",$mysoc->country_code),'localtax2assuj_value').'</td><td>';
1843
-                print $form->selectyesno('localtax2assuj_value',$object->localtax2_assuj,1);
1844
-                if  (! isOnlyOneLocalTax(2))
1842
+                print '<td>'.fieldLabel($langs->transcountry("LocalTax2IsUsed", $mysoc->country_code), 'localtax2assuj_value').'</td><td>';
1843
+                print $form->selectyesno('localtax2assuj_value', $object->localtax2_assuj, 1);
1844
+                if (!isOnlyOneLocalTax(2))
1845 1845
                 {
1846
-                    print '<span class="cblt2">     '.$langs->transcountry("Type",$mysoc->country_code).': ';
1847
-                    $formcompany->select_localtax(2,$object->localtax2_value, "lt2");
1846
+                    print '<span class="cblt2">     '.$langs->transcountry("Type", $mysoc->country_code).': ';
1847
+                    $formcompany->select_localtax(2, $object->localtax2_value, "lt2");
1848 1848
                     print '</span>';
1849 1849
                 }
1850 1850
                 print '</td></tr>';
1851 1851
 
1852 1852
             }
1853
-            elseif($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj!="1")
1853
+            elseif ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj != "1")
1854 1854
             {
1855
-                print '<tr><td>'.fieldLabel($langs->transcountry("LocalTax1IsUsed",$mysoc->country_code),'localtax1assuj_value').'</td><td colspan="3">';
1856
-                print $form->selectyesno('localtax1assuj_value',$object->localtax1_assuj,1);
1857
-                if(! isOnlyOneLocalTax(1))
1855
+                print '<tr><td>'.fieldLabel($langs->transcountry("LocalTax1IsUsed", $mysoc->country_code), 'localtax1assuj_value').'</td><td colspan="3">';
1856
+                print $form->selectyesno('localtax1assuj_value', $object->localtax1_assuj, 1);
1857
+                if (!isOnlyOneLocalTax(1))
1858 1858
                 {
1859
-                    print '<span class="cblt1">     '.$langs->transcountry("Type",$mysoc->country_code).': ';
1860
-                    $formcompany->select_localtax(1,$object->localtax1_value, "lt1");
1859
+                    print '<span class="cblt1">     '.$langs->transcountry("Type", $mysoc->country_code).': ';
1860
+                    $formcompany->select_localtax(1, $object->localtax1_value, "lt1");
1861 1861
                     print '</span>';
1862 1862
                 }
1863 1863
                 print '</td></tr>';
1864 1864
 
1865 1865
             }
1866
-            elseif($mysoc->localtax2_assuj=="1" && $mysoc->localtax1_assuj!="1")
1866
+            elseif ($mysoc->localtax2_assuj == "1" && $mysoc->localtax1_assuj != "1")
1867 1867
             {
1868
-                print '<tr><td>'.fieldLabel($langs->transcountry("LocalTax2IsUsed",$mysoc->country_code),'localtax2assuj_value').'</td><td colspan="3">';
1869
-                print $form->selectyesno('localtax2assuj_value',$object->localtax2_assuj,1);
1870
-                if(! isOnlyOneLocalTax(2))
1868
+                print '<tr><td>'.fieldLabel($langs->transcountry("LocalTax2IsUsed", $mysoc->country_code), 'localtax2assuj_value').'</td><td colspan="3">';
1869
+                print $form->selectyesno('localtax2assuj_value', $object->localtax2_assuj, 1);
1870
+                if (!isOnlyOneLocalTax(2))
1871 1871
                 {
1872
-                    print '<span class="cblt2">     '.$langs->transcountry("Type",$mysoc->country_code).': ';
1873
-                    $formcompany->select_localtax(2,$object->localtax2_value, "lt2");
1872
+                    print '<span class="cblt2">     '.$langs->transcountry("Type", $mysoc->country_code).': ';
1873
+                    $formcompany->select_localtax(2, $object->localtax2_value, "lt2");
1874 1874
                     print '</span>';
1875 1875
                 }
1876 1876
                 print '</td></tr>';
1877 1877
             }
1878 1878
 
1879 1879
             // VAT Code
1880
-            print '<tr><td>'.fieldLabel('VATIntra','intra_vat').'</td>';
1880
+            print '<tr><td>'.fieldLabel('VATIntra', 'intra_vat').'</td>';
1881 1881
             print '<td colspan="3">';
1882
-            $s ='<input type="text" class="flat maxwidthonsmartphone" name="tva_intra" id="intra_vat" maxlength="20" value="'.$object->tva_intra.'">';
1882
+            $s = '<input type="text" class="flat maxwidthonsmartphone" name="tva_intra" id="intra_vat" maxlength="20" value="'.$object->tva_intra.'">';
1883 1883
 
1884 1884
             if (empty($conf->global->MAIN_DISABLEVATCHECK) && isInEEC($object))
1885 1885
             {
1886
-                $s.=' &nbsp; ';
1886
+                $s .= ' &nbsp; ';
1887 1887
 
1888 1888
                 if ($conf->use_javascript_ajax)
1889 1889
                 {
@@ -1894,12 +1894,12 @@  discard block
 block discarded – undo
1894 1894
                     print "}\n";
1895 1895
                     print '</script>';
1896 1896
                     print "\n";
1897
-                    $s.='<a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT(document.formsoc.tva_intra.value);">'.$langs->trans("VATIntraCheck").'</a>';
1898
-                    $s = $form->textwithpicto($s,$langs->trans("VATIntraCheckDesc",$langs->trans("VATIntraCheck")),1);
1897
+                    $s .= '<a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT(document.formsoc.tva_intra.value);">'.$langs->trans("VATIntraCheck").'</a>';
1898
+                    $s = $form->textwithpicto($s, $langs->trans("VATIntraCheckDesc", $langs->trans("VATIntraCheck")), 1);
1899 1899
                 }
1900 1900
                 else
1901 1901
                 {
1902
-                    $s.='<a href="'.$langs->transcountry("VATIntraCheckURL",$object->country_id).'" class="hideonsmartphone" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"),'help').'</a>';
1902
+                    $s .= '<a href="'.$langs->transcountry("VATIntraCheckURL", $object->country_id).'" class="hideonsmartphone" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"), 'help').'</a>';
1903 1903
                 }
1904 1904
             }
1905 1905
             print $s;
@@ -1907,44 +1907,44 @@  discard block
 block discarded – undo
1907 1907
             print '</tr>';
1908 1908
 
1909 1909
             // Type - Size
1910
-            print '<tr><td>'.fieldLabel('ThirdPartyType','typent_id').'</td><td class="maxwidthonsmartphone">';
1911
-            print $form->selectarray("typent_id",$formcompany->typent_array(0), $object->typent_id, 0, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT)?'ASC':$conf->global->SOCIETE_SORT_ON_TYPEENT));
1912
-            if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1910
+            print '<tr><td>'.fieldLabel('ThirdPartyType', 'typent_id').'</td><td class="maxwidthonsmartphone">';
1911
+            print $form->selectarray("typent_id", $formcompany->typent_array(0), $object->typent_id, 0, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT));
1912
+            if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1913 1913
             print '</td>';
1914
-            print '<td>'.fieldLabel('Staff','effectif_id').'</td><td class="maxwidthonsmartphone">';
1915
-            print $form->selectarray("effectif_id",$formcompany->effectif_array(0), $object->effectif_id);
1916
-            if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1914
+            print '<td>'.fieldLabel('Staff', 'effectif_id').'</td><td class="maxwidthonsmartphone">';
1915
+            print $form->selectarray("effectif_id", $formcompany->effectif_array(0), $object->effectif_id);
1916
+            if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1917 1917
             print '</td></tr>';
1918 1918
 
1919 1919
             // Juridical type
1920
-            print '<tr><td>'.fieldLabel('JuridicalStatus','forme_juridique_code').'</td><td class="maxwidthonsmartphone" colspan="3">';
1920
+            print '<tr><td>'.fieldLabel('JuridicalStatus', 'forme_juridique_code').'</td><td class="maxwidthonsmartphone" colspan="3">';
1921 1921
             print $formcompany->select_juridicalstatus($object->forme_juridique_code, $object->country_code, '', 'forme_juridique_code');
1922 1922
             print '</td></tr>';
1923 1923
 
1924 1924
             // Capital
1925
-            print '<tr><td>'.fieldLabel('Capital','capital').'</td>';
1925
+            print '<tr><td>'.fieldLabel('Capital', 'capital').'</td>';
1926 1926
 	        print '<td colspan="3"><input type="text" name="capital" id="capital" size="10" value="'.$object->capital.'"> <font class="hideonsmartphone">'.$langs->trans("Currency".$conf->currency).'</font></td></tr>';
1927 1927
 
1928 1928
             // Default language
1929
-            if (! empty($conf->global->MAIN_MULTILANGS))
1929
+            if (!empty($conf->global->MAIN_MULTILANGS))
1930 1930
             {
1931
-                print '<tr><td>'.fieldLabel('DefaultLang','default_lang').'</td><td colspan="3">'."\n";
1932
-                print $formadmin->select_language($object->default_lang,'default_lang',0,0,1);
1931
+                print '<tr><td>'.fieldLabel('DefaultLang', 'default_lang').'</td><td colspan="3">'."\n";
1932
+                print $formadmin->select_language($object->default_lang, 'default_lang', 0, 0, 1);
1933 1933
                 print '</td>';
1934 1934
                 print '</tr>';
1935 1935
             }
1936 1936
 
1937 1937
 			// Categories
1938
-			if (! empty($conf->categorie->enabled)  && ! empty($user->rights->categorie->lire))
1938
+			if (!empty($conf->categorie->enabled) && !empty($user->rights->categorie->lire))
1939 1939
 			{
1940 1940
 				// Customer
1941 1941
 				if ($object->prospect || $object->client) {
1942
-					print '<tr><td>' . fieldLabel('CustomersCategoriesShort', 'custcats') . '</td>';
1942
+					print '<tr><td>'.fieldLabel('CustomersCategoriesShort', 'custcats').'</td>';
1943 1943
 					print '<td colspan="3">';
1944 1944
 					$cate_arbo = $form->select_all_categories(Categorie::TYPE_CUSTOMER, null, null, null, null, 1);
1945 1945
 					$c = new Categorie($db);
1946 1946
 					$cats = $c->containing($object->id, Categorie::TYPE_CUSTOMER);
1947
-					$arrayselected=array();
1947
+					$arrayselected = array();
1948 1948
 					foreach ($cats as $cat) {
1949 1949
 						$arrayselected[] = $cat->id;
1950 1950
 					}
@@ -1954,12 +1954,12 @@  discard block
 block discarded – undo
1954 1954
 
1955 1955
 				// Supplier
1956 1956
 				if ($object->fournisseur) {
1957
-					print '<tr><td>' . fieldLabel('SuppliersCategoriesShort', 'suppcats') . '</td>';
1957
+					print '<tr><td>'.fieldLabel('SuppliersCategoriesShort', 'suppcats').'</td>';
1958 1958
 					print '<td colspan="3">';
1959 1959
 					$cate_arbo = $form->select_all_categories(Categorie::TYPE_SUPPLIER, null, null, null, null, 1);
1960 1960
 					$c = new Categorie($db);
1961 1961
 					$cats = $c->containing($object->id, Categorie::TYPE_SUPPLIER);
1962
-					$arrayselected=array();
1962
+					$arrayselected = array();
1963 1963
 					foreach ($cats as $cat) {
1964 1964
 						$arrayselected[] = $cat->id;
1965 1965
 					}
@@ -1969,29 +1969,29 @@  discard block
 block discarded – undo
1969 1969
 			}
1970 1970
 
1971 1971
 			// Multicurrency
1972
-			if (! empty($conf->multicurrency->enabled))
1972
+			if (!empty($conf->multicurrency->enabled))
1973 1973
 			{
1974 1974
 				print '<tr>';
1975
-				print '<td>'.fieldLabel('Currency','multicurrency_code').'</td>';
1975
+				print '<td>'.fieldLabel('Currency', 'multicurrency_code').'</td>';
1976 1976
 		        print '<td colspan="3" class="maxwidthonsmartphone">';
1977 1977
 		        print $form->selectMultiCurrency(($object->multicurrency_code ? $object->multicurrency_code : $conf->currency), 'multicurrency_code', 1);
1978 1978
 				print '</td></tr>';
1979 1979
 			}
1980 1980
 
1981 1981
             // Other attributes
1982
-            $parameters=array('colspan' => ' colspan="3"', 'colspanvalue' => '3');
1983
-            $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
1982
+            $parameters = array('colspan' => ' colspan="3"', 'colspanvalue' => '3');
1983
+            $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1984 1984
             print $hookmanager->resPrint;
1985
-            if (empty($reshook) && ! empty($extrafields->attribute_label))
1985
+            if (empty($reshook) && !empty($extrafields->attribute_label))
1986 1986
             {
1987
-            	print $object->showOptionals($extrafields,'edit');
1987
+            	print $object->showOptionals($extrafields, 'edit');
1988 1988
             }
1989 1989
 
1990 1990
             // Webservices url/key
1991 1991
             if (!empty($conf->syncsupplierwebservices->enabled)) {
1992
-                print '<tr><td>'.fieldLabel('WebServiceURL','webservices_url').'</td>';
1992
+                print '<tr><td>'.fieldLabel('WebServiceURL', 'webservices_url').'</td>';
1993 1993
                 print '<td><input type="text" name="webservices_url" id="webservices_url" size="32" value="'.$object->webservices_url.'"></td>';
1994
-                print '<td>'.fieldLabel('WebServiceKey','webservices_key').'</td>';
1994
+                print '<td>'.fieldLabel('WebServiceKey', 'webservices_key').'</td>';
1995 1995
                 print '<td><input type="text" name="webservices_key" id="webservices_key" size="32" value="'.$object->webservices_key.'"></td></tr>';
1996 1996
             }
1997 1997
 
@@ -1999,18 +1999,18 @@  discard block
 block discarded – undo
1999 1999
 			if (!empty($conf->incoterm->enabled))
2000 2000
 			{
2001 2001
 				print '<tr>';
2002
-				print '<td>'.fieldLabel('IncotermLabel','incoterm_id').'</td>';
2002
+				print '<td>'.fieldLabel('IncotermLabel', 'incoterm_id').'</td>';
2003 2003
 	            print '<td colspan="3" class="maxwidthonsmartphone">';
2004
-	            print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''));
2004
+	            print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''));
2005 2005
 				print '</td></tr>';
2006 2006
 			}
2007 2007
 
2008 2008
             // Logo
2009 2009
             print '<tr class="hideonsmartphone">';
2010
-            print '<td>'.fieldLabel('Logo','photoinput').'</td>';
2010
+            print '<td>'.fieldLabel('Logo', 'photoinput').'</td>';
2011 2011
             print '<td colspan="3">';
2012
-            if ($object->logo) print $form->showphoto('societe',$object);
2013
-            $caneditfield=1;
2012
+            if ($object->logo) print $form->showphoto('societe', $object);
2013
+            $caneditfield = 1;
2014 2014
             if ($caneditfield)
2015 2015
             {
2016 2016
                 if ($object->logo) print "<br>\n";
@@ -2043,7 +2043,7 @@  discard block
 block discarded – undo
2043 2043
          * View
2044 2044
          */
2045 2045
 
2046
-        if (!empty($object->id)) $res=$object->fetch_optionals();
2046
+        if (!empty($object->id)) $res = $object->fetch_optionals();
2047 2047
         //if ($res < 0) { dol_print_error($db); exit; }
2048 2048
 
2049 2049
 
@@ -2071,11 +2071,11 @@  discard block
 block discarded – undo
2071 2071
 		    print $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id, $langs->trans("MergeThirdparties"), $langs->trans("ConfirmMergeThirdparties"), "confirm_merge", $formquestion, 'no', 1, 250);
2072 2072
 	    }
2073 2073
 
2074
-        dol_htmloutput_mesg(is_numeric($error)?'':$error, $errors, 'error');
2074
+        dol_htmloutput_mesg(is_numeric($error) ? '' : $error, $errors, 'error');
2075 2075
 
2076 2076
         $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
2077 2077
 
2078
-        dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom');
2078
+        dol_banner_tab($object, 'socid', $linkback, ($user->societe_id ? 0 : 1), 'rowid', 'nom');
2079 2079
 
2080 2080
 
2081 2081
         print '<div class="fichecenter">';
@@ -2090,7 +2090,7 @@  discard block
 block discarded – undo
2090 2090
     	print '</td></tr>';
2091 2091
 
2092 2092
     	// Supplier
2093
-    	if (! empty($conf->fournisseur->enabled))
2093
+    	if (!empty($conf->fournisseur->enabled))
2094 2094
     	{
2095 2095
     		print '<tr><td>'.$langs->trans('Supplier').'</td><td>';
2096 2096
     		print yn($object->fournisseur);
@@ -2098,10 +2098,10 @@  discard block
 block discarded – undo
2098 2098
     	}
2099 2099
 
2100 2100
     	// Prefix
2101
-        if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
2101
+        if (!empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
2102 2102
         {
2103 2103
             print '<tr><td>'.$langs->trans('Prefix').'</td><td>'.$object->prefix_comm.'</td>';
2104
-            print $htmllogobar; $htmllogobar='';
2104
+            print $htmllogobar; $htmllogobar = '';
2105 2105
             print '</tr>';
2106 2106
         }
2107 2107
 
@@ -2113,49 +2113,49 @@  discard block
 block discarded – undo
2113 2113
             print $object->code_client;
2114 2114
             if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
2115 2115
             print '</td>';
2116
-            print $htmllogobar; $htmllogobar='';
2116
+            print $htmllogobar; $htmllogobar = '';
2117 2117
             print '</tr>';
2118 2118
         }
2119 2119
 
2120 2120
         // Supplier code
2121
-        if (! empty($conf->fournisseur->enabled) && $object->fournisseur && ! empty($user->rights->fournisseur->lire))
2121
+        if (!empty($conf->fournisseur->enabled) && $object->fournisseur && !empty($user->rights->fournisseur->lire))
2122 2122
         {
2123 2123
             print '<tr><td>';
2124 2124
             print $langs->trans('SupplierCode').'</td><td>';
2125 2125
             print $object->code_fournisseur;
2126 2126
             if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
2127 2127
             print '</td>';
2128
-            print $htmllogobar; $htmllogobar='';
2128
+            print $htmllogobar; $htmllogobar = '';
2129 2129
             print '</tr>';
2130 2130
         }
2131 2131
 
2132 2132
         // Barcode
2133
-        if (! empty($conf->barcode->enabled))
2133
+        if (!empty($conf->barcode->enabled))
2134 2134
         {
2135 2135
             print '<tr><td>';
2136 2136
             print $langs->trans('Gencod').'</td><td>'.$object->barcode;
2137 2137
             print '</td>';
2138
-			if ($htmllogobar) $htmllogobar.=$form->showbarcode($object);
2138
+			if ($htmllogobar) $htmllogobar .= $form->showbarcode($object);
2139 2139
             print $htmllogobar;
2140
-			$htmllogobar='';
2140
+			$htmllogobar = '';
2141 2141
             print '</tr>';
2142 2142
         }
2143 2143
 
2144 2144
         // Prof ids
2145
-        $i=1; $j=0;
2145
+        $i = 1; $j = 0;
2146 2146
         while ($i <= 6)
2147 2147
         {
2148
-            $idprof=$langs->transcountry('ProfId'.$i,$object->country_code);
2149
-            if ($idprof!='-')
2148
+            $idprof = $langs->transcountry('ProfId'.$i, $object->country_code);
2149
+            if ($idprof != '-')
2150 2150
             {
2151 2151
                 //if (($j % 2) == 0) print '<tr>';
2152 2152
                 print '<tr>';
2153 2153
             	print '<td>'.$idprof.'</td><td>';
2154
-                $key='idprof'.$i;
2154
+                $key = 'idprof'.$i;
2155 2155
                 print $object->$key;
2156 2156
                 if ($object->$key)
2157 2157
                 {
2158
-                    if ($object->id_prof_check($i,$object) > 0) print ' &nbsp; '.$object->id_prof_url($i,$object);
2158
+                    if ($object->id_prof_check($i, $object) > 0) print ' &nbsp; '.$object->id_prof_url($i, $object);
2159 2159
                     else print ' <font class="error">('.$langs->trans("ErrorWrongValue").')</font>';
2160 2160
                 }
2161 2161
                 print '</td>';
@@ -2177,24 +2177,24 @@  discard block
 block discarded – undo
2177 2177
 
2178 2178
 		// Local Taxes
2179 2179
 		//TODO: Place into a function to control showing by country or study better option
2180
-		if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1")
2180
+		if ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj == "1")
2181 2181
 		{
2182
-		    print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed",$mysoc->country_code).'</td><td>';
2182
+		    print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td>';
2183 2183
 		    print yn($object->localtax1_assuj);
2184
-		    print '</td></tr><tr><td>'.$langs->transcountry("LocalTax2IsUsed",$mysoc->country_code).'</td><td>';
2184
+		    print '</td></tr><tr><td>'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td>';
2185 2185
 		    print yn($object->localtax2_assuj);
2186 2186
 		    print '</td></tr>';
2187 2187
 
2188
-		    if($object->localtax1_assuj=="1" && (! isOnlyOneLocalTax(1)))
2188
+		    if ($object->localtax1_assuj == "1" && (!isOnlyOneLocalTax(1)))
2189 2189
 		    {
2190 2190
 		        print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2191 2191
 		        print '<input type="hidden" name="action" value="set_localtax1">';
2192 2192
 		        print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2193
-		        print '<tr><td>'.$langs->transcountry("TypeLocaltax1", $mysoc->country_code).' <a href="'.$_SERVER["PHP_SELF"].'?action=editRE&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</td>';
2194
-		        if($action == 'editRE')
2193
+		        print '<tr><td>'.$langs->transcountry("TypeLocaltax1", $mysoc->country_code).' <a href="'.$_SERVER["PHP_SELF"].'?action=editRE&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</td>';
2194
+		        if ($action == 'editRE')
2195 2195
 		        {
2196 2196
 		            print '<td align="left">';
2197
-		            $formcompany->select_localtax(1,$object->localtax1_value, "lt1");
2197
+		            $formcompany->select_localtax(1, $object->localtax1_value, "lt1");
2198 2198
 		            print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2199 2199
 		        }
2200 2200
 		        else
@@ -2203,61 +2203,61 @@  discard block
 block discarded – undo
2203 2203
 		        }
2204 2204
 		        print '</tr></form>';
2205 2205
 		    }
2206
-		    if($object->localtax2_assuj=="1" && (! isOnlyOneLocalTax(2)))
2206
+		    if ($object->localtax2_assuj == "1" && (!isOnlyOneLocalTax(2)))
2207 2207
 		    {
2208 2208
 		        print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2209 2209
 		        print '<input type="hidden" name="action" value="set_localtax2">';
2210 2210
 		        print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2211
-		        print '<tr><td>'.$langs->transcountry("TypeLocaltax2", $mysoc->country_code).'<a href="'.$_SERVER["PHP_SELF"].'?action=editIRPF&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</td>';
2212
-		        if($action == 'editIRPF'){
2211
+		        print '<tr><td>'.$langs->transcountry("TypeLocaltax2", $mysoc->country_code).'<a href="'.$_SERVER["PHP_SELF"].'?action=editIRPF&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</td>';
2212
+		        if ($action == 'editIRPF') {
2213 2213
 		            print '<td align="left">';
2214
-		            $formcompany->select_localtax(2,$object->localtax2_value, "lt2");
2214
+		            $formcompany->select_localtax(2, $object->localtax2_value, "lt2");
2215 2215
 		            print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2216
-		        }else{
2216
+		        } else {
2217 2217
 		            print '<td>'.$object->localtax2_value.'</td>';
2218 2218
 		        }
2219 2219
 		        print '</tr></form>';
2220 2220
 		    }
2221 2221
 		}
2222
-		elseif($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj!="1")
2222
+		elseif ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj != "1")
2223 2223
 		{
2224
-		    print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed",$mysoc->country_code).'</td><td>';
2224
+		    print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td>';
2225 2225
 		    print yn($object->localtax1_assuj);
2226 2226
 		    print '</td></tr>';
2227
-		    if($object->localtax1_assuj=="1" && (! isOnlyOneLocalTax(1)))
2227
+		    if ($object->localtax1_assuj == "1" && (!isOnlyOneLocalTax(1)))
2228 2228
 		    {
2229 2229
 		        print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2230 2230
 		        print '<input type="hidden" name="action" value="set_localtax1">';
2231 2231
 		        print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2232
-		        print '<tr><td> '.$langs->transcountry("TypeLocaltax1", $mysoc->country_code).'<a href="'.$_SERVER["PHP_SELF"].'?action=editRE&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</td>';
2233
-		        if($action == 'editRE'){
2232
+		        print '<tr><td> '.$langs->transcountry("TypeLocaltax1", $mysoc->country_code).'<a href="'.$_SERVER["PHP_SELF"].'?action=editRE&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</td>';
2233
+		        if ($action == 'editRE') {
2234 2234
 		            print '<td align="left">';
2235
-		            $formcompany->select_localtax(1,$object->localtax1_value, "lt1");
2235
+		            $formcompany->select_localtax(1, $object->localtax1_value, "lt1");
2236 2236
 		            print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2237
-		        }else{
2237
+		        } else {
2238 2238
 		            print '<td>'.$object->localtax1_value.'</td>';
2239 2239
 		        }
2240 2240
 		        print '</tr></form>';
2241 2241
 
2242 2242
 		    }
2243 2243
 		}
2244
-		elseif($mysoc->localtax2_assuj=="1" && $mysoc->localtax1_assuj!="1")
2244
+		elseif ($mysoc->localtax2_assuj == "1" && $mysoc->localtax1_assuj != "1")
2245 2245
 		{
2246
-		    print '<tr><td>'.$langs->transcountry("LocalTax2IsUsed",$mysoc->country_code).'</td><td>';
2246
+		    print '<tr><td>'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td>';
2247 2247
 		    print yn($object->localtax2_assuj);
2248 2248
 		    print '</td></tr>';
2249
-		    if($object->localtax2_assuj=="1" && (! isOnlyOneLocalTax(2)))
2249
+		    if ($object->localtax2_assuj == "1" && (!isOnlyOneLocalTax(2)))
2250 2250
 		    {
2251 2251
 
2252 2252
 		        print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
2253 2253
 		        print '<input type="hidden" name="action" value="set_localtax2">';
2254 2254
 		        print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2255
-		        print '<tr><td> '.$langs->transcountry("TypeLocaltax2", $mysoc->country_code).' <a href="'.$_SERVER["PHP_SELF"].'?action=editIRPF&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</td>';
2256
-		        if($action == 'editIRPF'){
2255
+		        print '<tr><td> '.$langs->transcountry("TypeLocaltax2", $mysoc->country_code).' <a href="'.$_SERVER["PHP_SELF"].'?action=editIRPF&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</td>';
2256
+		        if ($action == 'editIRPF') {
2257 2257
 		            print '<td align="left">';
2258
-		            $formcompany->select_localtax(2,$object->localtax2_value, "lt2");
2258
+		            $formcompany->select_localtax(2, $object->localtax2_value, "lt2");
2259 2259
 		            print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2260
-		        }else{
2260
+		        } else {
2261 2261
 		            print '<td>'.$object->localtax2_value.'</td>';
2262 2262
 		        }
2263 2263
 		        print '</tr></form>';
@@ -2278,13 +2278,13 @@  discard block
 block discarded – undo
2278 2278
 		print '<td class="nowrap">'.$langs->trans('VATIntra').'</td><td>';
2279 2279
         if ($object->tva_intra)
2280 2280
         {
2281
-            $s='';
2282
-            $s.=$object->tva_intra;
2283
-            $s.='<input type="hidden" id="tva_intra" name="tva_intra" maxlength="20" value="'.$object->tva_intra.'">';
2281
+            $s = '';
2282
+            $s .= $object->tva_intra;
2283
+            $s .= '<input type="hidden" id="tva_intra" name="tva_intra" maxlength="20" value="'.$object->tva_intra.'">';
2284 2284
 
2285 2285
             if (empty($conf->global->MAIN_DISABLEVATCHECK))
2286 2286
             {
2287
-                $s.=' &nbsp; ';
2287
+                $s .= ' &nbsp; ';
2288 2288
 
2289 2289
                 if ($conf->use_javascript_ajax)
2290 2290
                 {
@@ -2295,12 +2295,12 @@  discard block
 block discarded – undo
2295 2295
                     print "}\n";
2296 2296
                     print '</script>';
2297 2297
                     print "\n";
2298
-                    $s.='<a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT( $(\'#tva_intra\').val() );">'.$langs->trans("VATIntraCheck").'</a>';
2299
-                    $s = $form->textwithpicto($s,$langs->trans("VATIntraCheckDesc",$langs->trans("VATIntraCheck")),1);
2298
+                    $s .= '<a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT( $(\'#tva_intra\').val() );">'.$langs->trans("VATIntraCheck").'</a>';
2299
+                    $s = $form->textwithpicto($s, $langs->trans("VATIntraCheckDesc", $langs->trans("VATIntraCheck")), 1);
2300 2300
                 }
2301 2301
                 else
2302 2302
                 {
2303
-                    $s.='<a href="'.$langs->transcountry("VATIntraCheckURL",$object->country_id).'" class="hideonsmartphone" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"),'help').'</a>';
2303
+                    $s .= '<a href="'.$langs->transcountry("VATIntraCheckURL", $object->country_id).'" class="hideonsmartphone" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"), 'help').'</a>';
2304 2304
                 }
2305 2305
             }
2306 2306
             print $s;
@@ -2314,7 +2314,7 @@  discard block
 block discarded – undo
2314 2314
 
2315 2315
         // Type + Staff
2316 2316
         $arr = $formcompany->typent_array(1);
2317
-        $object->typent= $arr[$object->typent_code];
2317
+        $object->typent = $arr[$object->typent_code];
2318 2318
         print '<tr><td>'.$langs->trans("ThirdPartyType").'</td><td>'.$object->typent.'</td>';
2319 2319
         print '<tr><td>'.$langs->trans("Staff").'</td><td>'.$object->effectif.'</td></tr>';
2320 2320
 
@@ -2327,11 +2327,11 @@  discard block
 block discarded – undo
2327 2327
         print '<table class="border tableforfield" width="100%">';
2328 2328
 
2329 2329
     	// Tags / categories
2330
-		if (! empty($conf->categorie->enabled)  && ! empty($user->rights->categorie->lire))
2330
+		if (!empty($conf->categorie->enabled) && !empty($user->rights->categorie->lire))
2331 2331
 		{
2332 2332
 			// Customer
2333 2333
 			if ($object->prospect || $object->client) {
2334
-				print '<tr><td>' . $langs->trans("CustomersCategoriesShort") . '</td>';
2334
+				print '<tr><td>'.$langs->trans("CustomersCategoriesShort").'</td>';
2335 2335
 				print '<td>';
2336 2336
 				print $form->showCategories($object->id, 'customer', 1);
2337 2337
 				print "</td></tr>";
@@ -2339,7 +2339,7 @@  discard block
 block discarded – undo
2339 2339
 
2340 2340
 			// Supplier
2341 2341
 			if ($object->fournisseur) {
2342
-				print '<tr><td>' . $langs->trans("SuppliersCategoriesShort") . '</td>';
2342
+				print '<tr><td>'.$langs->trans("SuppliersCategoriesShort").'</td>';
2343 2343
 				print '<td>';
2344 2344
 				print $form->showCategories($object->id, 'supplier', 1);
2345 2345
 				print "</td></tr>";
@@ -2351,19 +2351,19 @@  discard block
 block discarded – undo
2351 2351
 
2352 2352
         // Capital
2353 2353
         print '<tr><td>'.$langs->trans('Capital').'</td><td>';
2354
-        if ($object->capital) print price($object->capital,'',$langs,0,-1,-1, $conf->currency);
2354
+        if ($object->capital) print price($object->capital, '', $langs, 0, -1, -1, $conf->currency);
2355 2355
         else print '&nbsp;';
2356 2356
         print '</td></tr>';
2357 2357
 
2358 2358
         // Default language
2359
-        if (! empty($conf->global->MAIN_MULTILANGS))
2359
+        if (!empty($conf->global->MAIN_MULTILANGS))
2360 2360
         {
2361 2361
             require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
2362 2362
             print '<tr><td>'.$langs->trans("DefaultLang").'</td><td>';
2363 2363
             //$s=picto_from_langcode($object->default_lang);
2364 2364
             //print ($s?$s.' ':'');
2365 2365
             $langs->load("languages");
2366
-            $labellang = ($object->default_lang?$langs->trans('Language_'.$object->default_lang):'');
2366
+            $labellang = ($object->default_lang ? $langs->trans('Language_'.$object->default_lang) : '');
2367 2367
             print $labellang;
2368 2368
             print '</td></tr>';
2369 2369
         }
@@ -2375,7 +2375,7 @@  discard block
 block discarded – undo
2375 2375
             print '<table width="100%" class="nobordernopadding"><tr><td>';
2376 2376
             print $langs->trans('IncotermLabel');
2377 2377
             print '<td><td align="right">';
2378
-            if ($user->rights->societe->creer) print '<a href="'.DOL_URL_ROOT.'/societe/card.php?socid='.$object->id.'&action=editincoterm">'.img_edit('',1).'</a>';
2378
+            if ($user->rights->societe->creer) print '<a href="'.DOL_URL_ROOT.'/societe/card.php?socid='.$object->id.'&action=editincoterm">'.img_edit('', 1).'</a>';
2379 2379
             else print '&nbsp;';
2380 2380
             print '</td></tr></table>';
2381 2381
             print '</td>';
@@ -2386,24 +2386,24 @@  discard block
 block discarded – undo
2386 2386
 			}
2387 2387
 			else
2388 2388
 			{
2389
-				print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''), $_SERVER['PHP_SELF'].'?socid='.$object->id);
2389
+				print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?socid='.$object->id);
2390 2390
 			}
2391 2391
             print '</td></tr>';
2392 2392
 		}
2393 2393
 
2394 2394
 		// Multicurrency
2395
-		if (! empty($conf->multicurrency->enabled))
2395
+		if (!empty($conf->multicurrency->enabled))
2396 2396
 		{
2397 2397
 			print '<tr>';
2398
-			print '<td>'.fieldLabel('Currency','multicurrency_code').'</td>';
2398
+			print '<td>'.fieldLabel('Currency', 'multicurrency_code').'</td>';
2399 2399
 	        print '<td>';
2400
-	        print !empty($object->multicurrency_code) ? currency_name($object->multicurrency_code,1) : '';
2400
+	        print !empty($object->multicurrency_code) ? currency_name($object->multicurrency_code, 1) : '';
2401 2401
 			print '</td></tr>';
2402 2402
 		}
2403 2403
 
2404 2404
 		// Other attributes
2405
-		$parameters=array('socid'=>$socid, 'colspan' => ' colspan="3"', 'colspanvalue' => '3');
2406
-		include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
2405
+		$parameters = array('socid'=>$socid, 'colspan' => ' colspan="3"', 'colspanvalue' => '3');
2406
+		include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
2407 2407
 
2408 2408
         // Parent company
2409 2409
         if (empty($conf->global->SOCIETE_DISABLE_PARENTCOMPANY))
@@ -2413,16 +2413,16 @@  discard block
 block discarded – undo
2413 2413
         	print '<table class="nobordernopadding" width="100%"><tr><td>';
2414 2414
         	print $langs->trans('ParentCompany');
2415 2415
         	print '</td>';
2416
-        	if ($action != 'editparentcompany') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editparentcompany&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</a></td>';
2416
+        	if ($action != 'editparentcompany') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editparentcompany&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</a></td>';
2417 2417
         	print '</tr></table>';
2418 2418
         	print '</td><td colspan="3">';
2419 2419
         	if ($action == 'editparentcompany')
2420 2420
         	{
2421
-        		$form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->parent,'editparentcompany','s.rowid <> '.$object->id,1);
2421
+        		$form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->parent, 'editparentcompany', 's.rowid <> '.$object->id, 1);
2422 2422
         	}
2423 2423
         	else
2424 2424
         	{
2425
-        		$form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->parent,'none','s.rowid <> '.$object->id,1);
2425
+        		$form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->parent, 'none', 's.rowid <> '.$object->id, 1);
2426 2426
         	}
2427 2427
         	print '</td>';
2428 2428
         	print '</tr>';
@@ -2432,16 +2432,16 @@  discard block
 block discarded – undo
2432 2432
         include DOL_DOCUMENT_ROOT.'/societe/tpl/linesalesrepresentative.tpl.php';
2433 2433
 
2434 2434
         // Module Adherent
2435
-        if (! empty($conf->adherent->enabled))
2435
+        if (!empty($conf->adherent->enabled))
2436 2436
         {
2437 2437
             $langs->load("members");
2438 2438
             print '<tr><td>'.$langs->trans("LinkedToDolibarrMember").'</td>';
2439 2439
             print '<td colspan="3">';
2440
-            $adh=new Adherent($db);
2441
-            $result=$adh->fetch('','',$object->id);
2440
+            $adh = new Adherent($db);
2441
+            $result = $adh->fetch('', '', $object->id);
2442 2442
             if ($result > 0)
2443 2443
             {
2444
-                $adh->ref=$adh->getFullName($langs);
2444
+                $adh->ref = $adh->getFullName($langs);
2445 2445
                 print $adh->getNomUrl(1);
2446 2446
             }
2447 2447
             else
@@ -2474,8 +2474,8 @@  discard block
 block discarded – undo
2474 2474
         {
2475 2475
 	        print '<div class="tabsAction">'."\n";
2476 2476
 
2477
-			$parameters=array();
2478
-			$reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
2477
+			$parameters = array();
2478
+			$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2479 2479
 			if (empty($reshook))
2480 2480
 			{
2481 2481
 				$at_least_one_email_contact = false;
@@ -2489,7 +2489,7 @@  discard block
 block discarded – undo
2489 2489
 					}
2490 2490
 				}
2491 2491
 
2492
-		        if (! empty($object->email) || $at_least_one_email_contact)
2492
+		        if (!empty($object->email) || $at_least_one_email_contact)
2493 2493
 		        {
2494 2494
 		        	$langs->load("mails");
2495 2495
 		        	print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'&amp;action=presend&amp;mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a></div>';
@@ -2542,10 +2542,10 @@  discard block
 block discarded – undo
2542 2542
 	            /*
2543 2543
 	             * Documents generes
2544 2544
 	             */
2545
-	            $filedir=$conf->societe->multidir_output[$object->entity].'/'.$object->id;
2546
-	            $urlsource=$_SERVER["PHP_SELF"]."?socid=".$object->id;
2547
-	            $genallowed=$user->rights->societe->lire;
2548
-	            $delallowed=$user->rights->societe->creer;
2545
+	            $filedir = $conf->societe->multidir_output[$object->entity].'/'.$object->id;
2546
+	            $urlsource = $_SERVER["PHP_SELF"]."?socid=".$object->id;
2547
+	            $genallowed = $user->rights->societe->lire;
2548
+	            $delallowed = $user->rights->societe->creer;
2549 2549
 
2550 2550
 	            print $formfile->showdocuments('company', $object->id, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 0, 0, 0, 28, 0, 'entity='.$object->entity, 0, '', $object->default_lang);
2551 2551
 	        }
@@ -2553,7 +2553,7 @@  discard block
 block discarded – undo
2553 2553
 			// Subsidiaries list
2554 2554
 			if (empty($conf->global->SOCIETE_DISABLE_SUBSIDIARIES))
2555 2555
 			{
2556
-				$result=show_subsidiaries($conf,$langs,$db,$object);
2556
+				$result = show_subsidiaries($conf, $langs, $db, $object);
2557 2557
 			}
2558 2558
 
2559 2559
 			print '</div><div class="fichehalfright"><div class="ficheaddleft">';
@@ -2561,35 +2561,35 @@  discard block
 block discarded – undo
2561 2561
 			$MAXEVENT = 10;
2562 2562
 
2563 2563
 			$morehtmlright = '<a href="'.DOL_URL_ROOT.'/societe/agenda.php?socid='.$object->id.'">';
2564
-			$morehtmlright.= $langs->trans("SeeAll");
2565
-			$morehtmlright.= '</a>';
2564
+			$morehtmlright .= $langs->trans("SeeAll");
2565
+			$morehtmlright .= '</a>';
2566 2566
 
2567 2567
 			// List of actions on element
2568
-			include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
2568
+			include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
2569 2569
 			$formactions = new FormActions($db);
2570
-			$somethingshown = $formactions->showactions($object, '', $socid, 1, '', $MAXEVENT, '', $morehtmlright);		// Show all action for thirdparty
2570
+			$somethingshown = $formactions->showactions($object, '', $socid, 1, '', $MAXEVENT, '', $morehtmlright); // Show all action for thirdparty
2571 2571
 
2572 2572
 			print '</div></div></div>';
2573 2573
 
2574
-			if (! empty($conf->global->MAIN_DUPLICATE_CONTACTS_TAB_ON_MAIN_CARD))
2574
+			if (!empty($conf->global->MAIN_DUPLICATE_CONTACTS_TAB_ON_MAIN_CARD))
2575 2575
 			{
2576 2576
 				// Contacts list
2577 2577
 				if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
2578 2578
 				{
2579
-					$result=show_contacts($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id);
2579
+					$result = show_contacts($conf, $langs, $db, $object, $_SERVER["PHP_SELF"].'?socid='.$object->id);
2580 2580
 				}
2581 2581
 
2582 2582
 				// Addresses list
2583
-				if (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT))
2583
+				if (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT))
2584 2584
 				{
2585
-					$result=show_addresses($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id);
2585
+					$result = show_addresses($conf, $langs, $db, $object, $_SERVER["PHP_SELF"].'?socid='.$object->id);
2586 2586
 				}
2587 2587
 			}
2588 2588
 		}
2589 2589
 
2590 2590
 		// Presend form
2591
-		$modelmail='thirdparty';
2592
-		$defaulttopic='Information';
2591
+		$modelmail = 'thirdparty';
2592
+		$defaulttopic = 'Information';
2593 2593
 		$diroutput = $conf->societe->dir_output;
2594 2594
 		$trackid = 'thi'.$object->id;
2595 2595
 
Please login to merge, or discard this patch.
Braces   +290 added lines, -183 removed lines patch added patch discarded remove patch
@@ -42,16 +42,24 @@  discard block
 block discarded – undo
42 42
 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
43 43
 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
44 44
 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
45
-if (! empty($conf->adherent->enabled)) require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
45
+if (! empty($conf->adherent->enabled)) {
46
+	require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
47
+}
46 48
 
47 49
 $langs->load("companies");
48 50
 $langs->load("commercial");
49 51
 $langs->load("bills");
50 52
 $langs->load("banks");
51 53
 $langs->load("users");
52
-if (! empty($conf->categorie->enabled)) $langs->load("categories");
53
-if (! empty($conf->incoterm->enabled)) $langs->load("incoterm");
54
-if (! empty($conf->notification->enabled)) $langs->load("mails");
54
+if (! empty($conf->categorie->enabled)) {
55
+	$langs->load("categories");
56
+}
57
+if (! empty($conf->incoterm->enabled)) {
58
+	$langs->load("incoterm");
59
+}
60
+if (! empty($conf->notification->enabled)) {
61
+	$langs->load("mails");
62
+}
55 63
 
56 64
 $mesg=''; $error=0; $errors=array();
57 65
 
@@ -61,8 +69,12 @@  discard block
 block discarded – undo
61 69
 $confirm		= GETPOST('confirm');
62 70
 
63 71
 $socid		= GETPOST('socid','int')?GETPOST('socid','int'):GETPOST('id','int');
64
-if ($user->societe_id) $socid=$user->societe_id;
65
-if (empty($socid) && $action == 'view') $action='create';
72
+if ($user->societe_id) {
73
+	$socid=$user->societe_id;
74
+}
75
+if (empty($socid) && $action == 'view') {
76
+	$action='create';
77
+}
66 78
 
67 79
 $object = new Societe($db);
68 80
 $extrafields = new ExtraFields($db);
@@ -101,7 +113,9 @@  discard block
 block discarded – undo
101 113
 
102 114
 $parameters=array('id'=>$socid, 'objcanvas'=>$objcanvas);
103 115
 $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
104
-if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
116
+if ($reshook < 0) {
117
+	setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
118
+}
105 119
 
106 120
 if (empty($reshook))
107 121
 {
@@ -128,8 +142,7 @@  discard block
 block discarded – undo
128 142
 			$langs->load('errors');
129 143
 			$langs->load('companies');
130 144
 			setEventMessages($langs->trans('ErrorThirdPartyIdIsMandatory', $langs->trans('MergeOriginThirdparty')), null, 'errors');
131
-		}
132
-		else
145
+		} else
133 146
 		{
134 147
 			if (!$error && $soc_origin->fetch($soc_origin_id) < 1)
135 148
 			{
@@ -156,7 +169,9 @@  discard block
 block discarded – undo
156 169
 				);
157 170
 				foreach ($listofproperties as $property)
158 171
 				{
159
-					if (empty($object->$property)) $object->$property = $soc_origin->$property;
172
+					if (empty($object->$property)) {
173
+						$object->$property = $soc_origin->$property;
174
+					}
160 175
 				}
161 176
 
162 177
 				// Concat some data
@@ -173,7 +188,9 @@  discard block
 block discarded – undo
173 188
 				{
174 189
 					foreach ($soc_origin->array_options as $key => $val)
175 190
 					{
176
-					    if (empty($object->array_options[$key])) $object->array_options[$key] = $val;
191
+					    if (empty($object->array_options[$key])) {
192
+					    	$object->array_options[$key] = $val;
193
+					    }
177 194
 					}
178 195
 				}
179 196
 
@@ -286,8 +303,7 @@  discard block
 block discarded – undo
286 303
 				{
287 304
 					setEventMessages($langs->trans('ThirdpartiesMergeSuccess'), null, 'mesgs');
288 305
 					$db->commit();
289
-				}
290
-				else
306
+				} else
291 307
 				{
292 308
 				    $langs->load("errors");
293 309
 					setEventMessages($langs->trans('ErrorsThirdpartyMerge'), null, 'errors');
@@ -332,7 +348,9 @@  discard block
 block discarded – undo
332 348
         // Fill array 'array_options' with data from update form
333 349
         $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
334 350
         $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute','none'));
335
-        if ($ret < 0) $error++;
351
+        if ($ret < 0) {
352
+        	$error++;
353
+        }
336 354
 
337 355
         if (! $error)
338 356
         {
@@ -344,7 +362,9 @@  discard block
 block discarded – undo
344 362
 			}
345 363
         }
346 364
 
347
-        if ($error) $action = 'edit_extras';
365
+        if ($error) {
366
+        	$action = 'edit_extras';
367
+        }
348 368
     }
349 369
 
350 370
     // Add new or update third party
@@ -376,20 +396,22 @@  discard block
 block discarded – undo
376 396
 	        {
377 397
 	        		$ret=$object->fetch($socid);
378 398
 				$object->oldcopy = clone $object;
379
-	        }
380
-			else $object->canvas=$canvas;
399
+	        } else {
400
+				$object->canvas=$canvas;
401
+			}
381 402
 
382
-	        if (GETPOST("private") == 1)	// Ask to create a contact
403
+	        if (GETPOST("private") == 1) {
404
+	        	// Ask to create a contact
383 405
 	        {
384 406
 	            $object->particulier			= GETPOST("private");
407
+	        }
385 408
 
386 409
 	            $object->name				= dolGetFirstLastname(GETPOST('firstname','alpha'),GETPOST('name','alpha'));
387 410
 	            $object->civility_id			= GETPOST('civility_id');	// Note: civility id is a code, not an int
388 411
 	            // Add non official properties
389 412
 	            $object->name_bis			= GETPOST('name','alpha');
390 413
 	            $object->firstname			= GETPOST('firstname','alpha');
391
-	        }
392
-	        else
414
+	        } else
393 415
 	        {
394 416
 	            $object->name				= GETPOST('name', 'alpha');
395 417
 	        }
@@ -464,8 +486,11 @@  discard block
 block discarded – undo
464 486
 				 $error++;
465 487
 			}
466 488
 
467
-	        if (GETPOST('deletephoto')) $object->logo = '';
468
-	        else if (! empty($_FILES['photo']['name'])) $object->logo = dol_sanitizeFileName($_FILES['photo']['name']);
489
+	        if (GETPOST('deletephoto')) {
490
+	        	$object->logo = '';
491
+	        } else if (! empty($_FILES['photo']['name'])) {
492
+	        	$object->logo = dol_sanitizeFileName($_FILES['photo']['name']);
493
+	        }
469 494
 
470 495
 	        // Check parameters
471 496
 	        if (! GETPOST('cancel','alpha'))
@@ -517,8 +542,12 @@  discard block
 block discarded – undo
517 542
 
518 543
                 $db->begin();
519 544
 
520
-                if (empty($object->client))      $object->code_client='';
521
-                if (empty($object->fournisseur)) $object->code_fournisseur='';
545
+                if (empty($object->client)) {
546
+                	$object->code_client='';
547
+                }
548
+                if (empty($object->fournisseur)) {
549
+                	$object->code_fournisseur='';
550
+                }
522 551
 
523 552
                 $result = $object->create($user);
524 553
 
@@ -570,16 +599,14 @@  discard block
 block discarded – undo
570 599
                                 if (! $result > 0)
571 600
                                 {
572 601
                                     $errors[] = "ErrorFailedToSaveFile";
573
-                                }
574
-                                else
602
+                                } else
575 603
                                 {
576 604
                                     // Create thumbs
577 605
                                     $object->addThumbs($newfile);
578 606
                                 }
579 607
                             }
580 608
                         }
581
-                    }
582
-                    else
609
+                    } else
583 610
 					{
584 611
 						switch($_FILES['photo']['error'])
585 612
 						{
@@ -593,12 +620,13 @@  discard block
 block discarded – undo
593 620
 						}
594 621
 	                }
595 622
                     // Gestion du logo de la société
596
-                }
597
-                else
623
+                } else
598 624
 				{
599
-				    if ($db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') // TODO Sometime errors on duplicate on profid and not on code, so we must manage this case
625
+				    if ($db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
626
+				    	// TODO Sometime errors on duplicate on profid and not on code, so we must manage this case
600 627
 					{
601 628
 						$duplicate_code_error = true;
629
+				    }
602 630
 						$object->code_fournisseur = null;
603 631
 						$object->code_client = null;
604 632
 					}
@@ -613,21 +641,24 @@  discard block
 block discarded – undo
613 641
 
614 642
                 	if (! empty($backtopage))
615 643
                 	{
616
-                	    if (preg_match('/\?/', $backtopage)) $backtopage.='&socid='.$object->id;
644
+                	    if (preg_match('/\?/', $backtopage)) {
645
+                	    	$backtopage.='&socid='.$object->id;
646
+                	    }
617 647
                		    header("Location: ".$backtopage);
618 648
                     	exit;
619
-                	}
620
-                	else
649
+                	} else
621 650
                 	{
622 651
                     	$url=$_SERVER["PHP_SELF"]."?socid=".$object->id;
623
-                    	if (($object->client == 1 || $object->client == 3) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) $url=DOL_URL_ROOT."/comm/card.php?socid=".$object->id;
624
-                    	else if ($object->fournisseur == 1) $url=DOL_URL_ROOT."/fourn/card.php?socid=".$object->id;
652
+                    	if (($object->client == 1 || $object->client == 3) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
653
+                    		$url=DOL_URL_ROOT."/comm/card.php?socid=".$object->id;
654
+                    	} else if ($object->fournisseur == 1) {
655
+                    		$url=DOL_URL_ROOT."/fourn/card.php?socid=".$object->id;
656
+                    	}
625 657
 
626 658
                 		header("Location: ".$url);
627 659
                     	exit;
628 660
                 	}
629
-                }
630
-                else
661
+                } else
631 662
                 {
632 663
                     $db->rollback();
633 664
                     $action='create';
@@ -644,8 +675,7 @@  discard block
 block discarded – undo
644 675
                 	{
645 676
                		    header("Location: ".$backtopage);
646 677
                     	exit;
647
-                	}
648
-                	else
678
+                	} else
649 679
                 	{
650 680
                		    header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid);
651 681
                     	exit;
@@ -653,8 +683,12 @@  discard block
 block discarded – undo
653 683
                 }
654 684
 
655 685
                 // To not set code if third party is not concerned. But if it had values, we keep them.
656
-                if (empty($object->client) && empty($object->oldcopy->code_client))          $object->code_client='';
657
-                if (empty($object->fournisseur)&& empty($object->oldcopy->code_fournisseur)) $object->code_fournisseur='';
686
+                if (empty($object->client) && empty($object->oldcopy->code_client)) {
687
+                	$object->code_client='';
688
+                }
689
+                if (empty($object->fournisseur)&& empty($object->oldcopy->code_fournisseur)) {
690
+                	$object->code_fournisseur='';
691
+                }
658 692
                 //var_dump($object);exit;
659 693
 
660 694
                 $result = $object->update($socid, $user, 1, $object->oldcopy->codeclient_modifiable(), $object->oldcopy->codefournisseur_modifiable(), 'update', 0);
@@ -710,8 +744,7 @@  discard block
 block discarded – undo
710 744
                             if (! $result > 0)
711 745
                             {
712 746
                                 $errors[] = "ErrorFailedToSaveFile";
713
-                            }
714
-                            else
747
+                            } else
715 748
                             {
716 749
                             	// Create thumbs
717 750
                             	$object->addThumbs($newfile);
@@ -727,13 +760,11 @@  discard block
 block discarded – undo
727 760
                                 }
728 761
                             }
729 762
                         }
730
-                    }
731
-                    else
763
+                    } else
732 764
 					{
733 765
                         $errors[] = "ErrorBadImageFormat";
734 766
                     }
735
-                }
736
-                else
767
+                } else
737 768
                 {
738 769
 					switch($_FILES['photo']['error'])
739 770
 					{
@@ -768,21 +799,18 @@  discard block
 block discarded – undo
768 799
                 	{
769 800
                		    header("Location: ".$backtopage);
770 801
                     	exit;
771
-                	}
772
-                	else
802
+                	} else
773 803
                 	{
774 804
                		    header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid);
775 805
                     	exit;
776 806
                 	}
777
-                }
778
-                else
807
+                } else
779 808
                 {
780 809
                     $object->id = $socid;
781 810
                     $action= "edit";
782 811
                 }
783 812
             }
784
-        }
785
-        else
813
+        } else
786 814
         {
787 815
         	$action = ($action=='add'?'create':'edit');
788 816
         }
@@ -798,8 +826,7 @@  discard block
 block discarded – undo
798 826
         {
799 827
             header("Location: ".DOL_URL_ROOT."/societe/list.php?delsoc=".urlencode($object->name));
800 828
             exit;
801
-        }
802
-        else
829
+        } else
803 830
         {
804 831
             $langs->load("errors");
805 832
            	setEventMessages($object->error, $object->errors, 'errors');
@@ -850,11 +877,15 @@  discard block
 block discarded – undo
850 877
 if ($socid > 0 && empty($object->id))
851 878
 {
852 879
     $result=$object->fetch($socid);
853
-	if ($result <= 0) dol_print_error('',$object->error);
854
-}
880
+	if ($result <= 0) {
881
+		dol_print_error('',$object->error);
882
+	}
883
+	}
855 884
 
856 885
 $title=$langs->trans("ThirdParty");
857
-if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$langs->trans('Card');
886
+if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) {
887
+	$title=$object->name." - ".$langs->trans('Card');
888
+}
858 889
 $help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
859 890
 llxHeader('',$title,$help_url);
860 891
 
@@ -867,8 +898,7 @@  discard block
 block discarded – undo
867 898
     // -----------------------------------------
868 899
    	$objcanvas->assign_values($action, $object->id, $object->ref);	// Set value for templates
869 900
     $objcanvas->display_canvas($action);							// Show template
870
-}
871
-else
901
+} else
872 902
 {
873 903
     // -----------------------------------------
874 904
     // When used in standard mode
@@ -879,8 +909,12 @@  discard block
 block discarded – undo
879 909
          *  Creation
880 910
          */
881 911
 		$private=GETPOST("private","int");
882
-		if (! empty($conf->global->THIRDPARTY_DEFAULT_CREATE_CONTACT) && ! isset($_GET['private']) && ! isset($_POST['private'])) $private=1;
883
-    	if (empty($private)) $private=0;
912
+		if (! empty($conf->global->THIRDPARTY_DEFAULT_CREATE_CONTACT) && ! isset($_GET['private']) && ! isset($_POST['private'])) {
913
+			$private=1;
914
+		}
915
+    	if (empty($private)) {
916
+    		$private=0;
917
+    	}
884 918
 
885 919
         // Load object modCodeTiers
886 920
         $module=(! empty($conf->global->SOCIETE_CODECLIENT_ADDON)?$conf->global->SOCIETE_CODECLIENT_ADDON:'mod_codeclient_leopard');
@@ -892,7 +926,9 @@  discard block
 block discarded – undo
892 926
         foreach ($dirsociete as $dirroot)
893 927
         {
894 928
             $res=dol_include_once($dirroot.$module.'.php');
895
-            if ($res) break;
929
+            if ($res) {
930
+            	break;
931
+            }
896 932
         }
897 933
         $modCodeClient = new $module;
898 934
         // Load object modCodeFournisseur
@@ -905,7 +941,9 @@  discard block
 block discarded – undo
905 941
         foreach ($dirsociete as $dirroot)
906 942
         {
907 943
             $res=dol_include_once($dirroot.$module.'.php');
908
-            if ($res) break;
944
+            if ($res) {
945
+            	break;
946
+            }
909 947
         }
910 948
         $modCodeFournisseur = new $module;
911 949
 
@@ -928,8 +966,7 @@  discard block
 block discarded – undo
928 966
         if(empty($duplicate_code_error)) {
929 967
 	        $object->code_client		= GETPOST('code_client', 'alpha');
930 968
 	        $object->fournisseur		= GETPOST('fournisseur')?GETPOST('fournisseur'):$object->fournisseur;
931
-        }
932
-		else {
969
+        } else {
933 970
 			setEventMessages($langs->trans('NewCustomerSupplierCodeProposed'),'', 'warnings');
934 971
 		}
935 972
 
@@ -989,8 +1026,7 @@  discard block
 block discarded – undo
989 1026
                     if (! $result > 0)
990 1027
                     {
991 1028
                         $errors[] = "ErrorFailedToSaveFile";
992
-                    }
993
-                    else
1029
+                    } else
994 1030
                     {
995 1031
                         // Create thumbs
996 1032
                         $object->addThumbs($newfile);
@@ -1078,7 +1114,9 @@  discard block
 block discarded – undo
1078 1114
         print '<input type="hidden" name="type" value='.GETPOST("type",'alpha').'>';
1079 1115
         print '<input type="hidden" name="LastName" value="'.$langs->trans('ThirdPartyName').' / '.$langs->trans('LastName').'">';
1080 1116
         print '<input type="hidden" name="ThirdPartyName" value="'.$langs->trans('ThirdPartyName').'">';
1081
-        if ($modCodeClient->code_auto || $modCodeFournisseur->code_auto) print '<input type="hidden" name="code_auto" value="1">';
1117
+        if ($modCodeClient->code_auto || $modCodeFournisseur->code_auto) {
1118
+        	print '<input type="hidden" name="code_auto" value="1">';
1119
+        }
1082 1120
 
1083 1121
         dol_fiche_head(null, 'card', '', 0, '');
1084 1122
 
@@ -1089,17 +1127,18 @@  discard block
 block discarded – undo
1089 1127
         if ($object->particulier || $private)
1090 1128
         {
1091 1129
 	        print '<span id="TypeName" class="fieldrequired">'.$langs->trans('ThirdPartyName').' / '.$langs->trans('LastName','name').'</span>';
1092
-        }
1093
-        else
1130
+        } else
1094 1131
 		{
1095 1132
 			print '<span id="TypeName" class="fieldrequired">'.fieldLabel('ThirdPartyName','name').'</span>';
1096 1133
         }
1097 1134
 	    print '</td><td'.(empty($conf->global->SOCIETE_USEPREFIX)?' colspan="3"':'').'>';
1098 1135
 	    print '<input type="text" class="minwidth300" maxlength="128" name="name" id="name" value="'.$object->name.'" autofocus="autofocus"></td>';
1099
-	    if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
1136
+	    if (! empty($conf->global->SOCIETE_USEPREFIX)) {
1137
+	    	// Old not used prefix field
1100 1138
 	    {
1101 1139
 		    print '<td>'.$langs->trans('Prefix').'</td><td><input type="text" size="5" maxlength="5" name="prefix_comm" value="'.$object->prefix_comm.'"></td>';
1102 1140
 	    }
1141
+	    }
1103 1142
 	    print '</tr>';
1104 1143
 
1105 1144
         // If javascript on, we show option individual
@@ -1123,17 +1162,27 @@  discard block
 block discarded – undo
1123 1162
 	    print '<td class="maxwidthonsmartphone">';
1124 1163
 	    $selected=GETPOST('client','int')!=''?GETPOST('client','int'):$object->client;
1125 1164
         print '<select class="flat" name="client" id="customerprospect">';
1126
-        if (GETPOST("type") == '') print '<option value="-1">&nbsp;</option>';
1127
-        if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) print '<option value="2"'.($selected==2?' selected':'').'>'.$langs->trans('Prospect').'</option>';
1128
-        if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTSCUSTOMERS)) print '<option value="3"'.($selected==3?' selected':'').'>'.$langs->trans('ProspectCustomer').'</option>';
1129
-        if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print '<option value="1"'.($selected==1?' selected':'').'>'.$langs->trans('Customer').'</option>';
1165
+        if (GETPOST("type") == '') {
1166
+        	print '<option value="-1">&nbsp;</option>';
1167
+        }
1168
+        if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
1169
+        	print '<option value="2"'.($selected==2?' selected':'').'>'.$langs->trans('Prospect').'</option>';
1170
+        }
1171
+        if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTSCUSTOMERS)) {
1172
+        	print '<option value="3"'.($selected==3?' selected':'').'>'.$langs->trans('ProspectCustomer').'</option>';
1173
+        }
1174
+        if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
1175
+        	print '<option value="1"'.($selected==1?' selected':'').'>'.$langs->trans('Customer').'</option>';
1176
+        }
1130 1177
         print '<option value="0"'.((string) $selected == '0'?' selected':'').'>'.$langs->trans('NorProspectNorCustomer').'</option>';
1131 1178
         print '</select></td>';
1132 1179
 
1133 1180
         print '<td>'.fieldLabel('CustomerCode','customer_code').'</td><td>';
1134 1181
         print '<table class="nobordernopadding"><tr><td>';
1135 1182
 		$tmpcode=$object->code_client;
1136
-        if (empty($tmpcode) && ! empty($modCodeClient->code_auto)) $tmpcode=$modCodeClient->getNextValue($object,0);
1183
+        if (empty($tmpcode) && ! empty($modCodeClient->code_auto)) {
1184
+        	$tmpcode=$modCodeClient->getNextValue($object,0);
1185
+        }
1137 1186
         print '<input type="text" name="code_client" id="customer_code" class="maxwidthonsmartphone" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
1138 1187
         print '</td><td>';
1139 1188
         $s=$modCodeClient->getToolTip($langs,$object,0);
@@ -1147,13 +1196,17 @@  discard block
 block discarded – undo
1147 1196
             print '<tr>';
1148 1197
             print '<td>'.fieldLabel('Supplier','fournisseur',1).'</td><td>';
1149 1198
             $default = -1;
1150
-            if (! empty($conf->global->THIRDPARTY_SUPPLIER_BY_DEFAULT)) $default=1;
1199
+            if (! empty($conf->global->THIRDPARTY_SUPPLIER_BY_DEFAULT)) {
1200
+            	$default=1;
1201
+            }
1151 1202
             print $form->selectyesno("fournisseur", (GETPOST('fournisseur','int')!=''?GETPOST('fournisseur','int'):(GETPOST("type",'alpha') == '' ? $default : $object->fournisseur)), 1, 0, (GETPOST("type",'alpha') == '' ? 1 : 0));
1152 1203
             print '</td>';
1153 1204
             print '<td>'.fieldLabel('SupplierCode','supplier_code').'</td><td>';
1154 1205
             print '<table class="nobordernopadding"><tr><td>';
1155 1206
             $tmpcode=$object->code_fournisseur;
1156
-            if (empty($tmpcode) && ! empty($modCodeFournisseur->code_auto)) $tmpcode=$modCodeFournisseur->getNextValue($object,1);
1207
+            if (empty($tmpcode) && ! empty($modCodeFournisseur->code_auto)) {
1208
+            	$tmpcode=$modCodeFournisseur->getNextValue($object,1);
1209
+            }
1157 1210
             print '<input type="text" name="code_fournisseur" id="supplier_code" class="maxwidthonsmartphone" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
1158 1211
             print '</td><td>';
1159 1212
             $s=$modCodeFournisseur->getToolTip($langs,$object,1);
@@ -1191,7 +1244,9 @@  discard block
 block discarded – undo
1191 1244
         // Country
1192 1245
         print '<tr><td>'.fieldLabel('Country','selectcountry_id').'</td><td colspan="3" class="maxwidthonsmartphone">';
1193 1246
         print $form->select_country((GETPOST('country_id')!=''?GETPOST('country_id'):$object->country_id));
1194
-        if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1247
+        if ($user->admin) {
1248
+        	print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1249
+        }
1195 1250
         print '</td></tr>';
1196 1251
 
1197 1252
         // State
@@ -1200,14 +1255,16 @@  discard block
 block discarded – undo
1200 1255
             if(!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && ($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 || $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 2))
1201 1256
             {
1202 1257
                 print '<tr><td>'.fieldLabel('Region-State','state_id').'</td><td colspan="3" class="maxwidthonsmartphone">';
1203
-            }
1204
-            else
1258
+            } else
1205 1259
             {
1206 1260
                 print '<tr><td>'.fieldLabel('State','state_id').'</td><td colspan="3" class="maxwidthonsmartphone">';
1207 1261
             }
1208 1262
 
1209
-            if ($object->country_id) print $formcompany->select_state($object->state_id,$object->country_code);
1210
-            else print $countrynotdefined;
1263
+            if ($object->country_id) {
1264
+            	print $formcompany->select_state($object->state_id,$object->country_code);
1265
+            } else {
1266
+            	print $countrynotdefined;
1267
+            }
1211 1268
             print '</td></tr>';
1212 1269
         }
1213 1270
 
@@ -1239,19 +1296,25 @@  discard block
 block discarded – undo
1239 1296
             {
1240 1297
 	            $key='idprof'.$i;
1241 1298
 
1242
-                if (($j % 2) == 0) print '<tr>';
1299
+                if (($j % 2) == 0) {
1300
+                	print '<tr>';
1301
+                }
1243 1302
 
1244 1303
                 $idprof_mandatory ='SOCIETE_IDPROF'.($i).'_MANDATORY';
1245 1304
                 print '<td>'.fieldLabel($idprof,$key, (empty($conf->global->$idprof_mandatory)?0:1)).'</td><td>';
1246 1305
 
1247 1306
                 print $formcompany->get_input_id_prof($i, $key, $object->$key, $object->country_code);
1248 1307
                 print '</td>';
1249
-                if (($j % 2) == 1) print '</tr>';
1308
+                if (($j % 2) == 1) {
1309
+                	print '</tr>';
1310
+                }
1250 1311
                 $j++;
1251 1312
             }
1252 1313
             $i++;
1253 1314
         }
1254
-        if ($j % 2 == 1) print '<td colspan="2"></td></tr>';
1315
+        if ($j % 2 == 1) {
1316
+        	print '<td colspan="2"></td></tr>';
1317
+        }
1255 1318
 
1256 1319
         // Vat is used
1257 1320
         print '<tr><td>'.fieldLabel('VATIsUsed','assujtva_value').'</td>';
@@ -1277,8 +1340,7 @@  discard block
 block discarded – undo
1277 1340
                 print "\n";
1278 1341
                 $s.='<a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT(document.formsoc.tva_intra.value);">'.$langs->trans("VATIntraCheck").'</a>';
1279 1342
                 $s = $form->textwithpicto($s,$langs->trans("VATIntraCheckDesc",$langs->trans("VATIntraCheck")),1);
1280
-            }
1281
-            else
1343
+            } else
1282 1344
             {
1283 1345
                 $s.='<a href="'.$langs->transcountry("VATIntraCheckURL",$object->country_id).'" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"),'help').'</a>';
1284 1346
             }
@@ -1297,14 +1359,12 @@  discard block
 block discarded – undo
1297 1359
             print $form->selectyesno('localtax2assuj_value',(isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2)?$conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2:0),1);
1298 1360
             print '</td></tr>';
1299 1361
 
1300
-        }
1301
-        elseif($mysoc->localtax1_assuj=="1")
1362
+        } elseif($mysoc->localtax1_assuj=="1")
1302 1363
         {
1303 1364
             print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed",$mysoc->country_code).'</td><td colspan="3">';
1304 1365
             print $form->selectyesno('localtax1assuj_value',(isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1)?$conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1:0),1);
1305 1366
             print '</td></tr>';
1306
-        }
1307
-        elseif($mysoc->localtax2_assuj=="1")
1367
+        } elseif($mysoc->localtax2_assuj=="1")
1308 1368
         {
1309 1369
             print '<tr><td>'.$langs->transcountry("LocalTax2IsUsed",$mysoc->country_code).'</td><td colspan="3">';
1310 1370
             print $form->selectyesno('localtax2assuj_value',(isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2)?$conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2:0),1);
@@ -1315,11 +1375,15 @@  discard block
 block discarded – undo
1315 1375
         print '<tr><td>'.fieldLabel('ThirdPartyType','typent_id').'</td><td class="maxwidthonsmartphone">'."\n";
1316 1376
         $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.
1317 1377
         print $form->selectarray("typent_id", $formcompany->typent_array(0), $object->typent_id, 0, 0, 0, '', 0, 0, 0, $sortparam);
1318
-        if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1378
+        if ($user->admin) {
1379
+        	print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1380
+        }
1319 1381
         print '</td>';
1320 1382
         print '<td>'.fieldLabel('Staff','effectif_id').'</td><td class="maxwidthonsmartphone">';
1321 1383
         print $form->selectarray("effectif_id", $formcompany->effectif_array(0), $object->effectif_id);
1322
-        if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1384
+        if ($user->admin) {
1385
+        	print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1386
+        }
1323 1387
         print '</td></tr>';
1324 1388
 
1325 1389
         // Legal Form
@@ -1328,8 +1392,7 @@  discard block
 block discarded – undo
1328 1392
         if ($object->country_id)
1329 1393
         {
1330 1394
             print $formcompany->select_juridicalstatus($object->forme_juridique_code, $object->country_code, '', 'forme_juridique_code');
1331
-        }
1332
-        else
1395
+        } else
1333 1396
         {
1334 1397
             print $countrynotdefined;
1335 1398
         }
@@ -1429,8 +1492,7 @@  discard block
 block discarded – undo
1429 1492
         {
1430 1493
             print ' &nbsp; &nbsp; ';
1431 1494
             print '<input type="submit" class="button" name="cancel" value="'.$langs->trans('Cancel').'">';
1432
-        }
1433
-        else
1495
+        } else
1434 1496
         {
1435 1497
             print ' &nbsp; &nbsp; ';
1436 1498
             print '<input type="button" class="button" value="' . $langs->trans("Cancel") . '" onClick="javascript:history.go(-1)">';
@@ -1438,8 +1500,7 @@  discard block
 block discarded – undo
1438 1500
         print '</div>'."\n";
1439 1501
 
1440 1502
         print '</form>'."\n";
1441
-    }
1442
-    elseif ($action == 'edit')
1503
+    } elseif ($action == 'edit')
1443 1504
     {
1444 1505
         /*
1445 1506
          * Edition
@@ -1465,7 +1526,9 @@  discard block
 block discarded – undo
1465 1526
             foreach ($dirsociete as $dirroot)
1466 1527
             {
1467 1528
                 $res=dol_include_once($dirroot.$module.'.php');
1468
-                if ($res) break;
1529
+                if ($res) {
1530
+                	break;
1531
+                }
1469 1532
             }
1470 1533
             $modCodeClient = new $module($db);
1471 1534
             // We verified if the tag prefix is used
@@ -1482,7 +1545,9 @@  discard block
 block discarded – undo
1482 1545
             foreach ($dirsociete as $dirroot)
1483 1546
             {
1484 1547
                 $res=dol_include_once($dirroot.$module.'.php');
1485
-                if ($res) break;
1548
+                if ($res) {
1549
+                	break;
1550
+                }
1486 1551
             }
1487 1552
             $modCodeFournisseur = new $module($db);
1488 1553
             // On verifie si la balise prefix est utilisee
@@ -1558,10 +1623,10 @@  discard block
 block discarded – undo
1558 1623
 
1559 1624
             if($object->localtax1_assuj==0){
1560 1625
             	$sub=0;
1561
-            }else{$sub=1;}
1626
+            } else{$sub=1;}
1562 1627
             if($object->localtax2_assuj==0){
1563 1628
             	$sub2=0;
1564
-            }else{$sub2=1;}
1629
+            } else{$sub2=1;}
1565 1630
 
1566 1631
             print "\n".'<script type="text/javascript">';
1567 1632
             print '$(document).ready(function () {
@@ -1618,7 +1683,9 @@  discard block
 block discarded – undo
1618 1683
             print '<input type="hidden" name="action" value="update">';
1619 1684
             print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1620 1685
             print '<input type="hidden" name="socid" value="'.$object->id.'">';
1621
-            if ($modCodeClient->code_auto || $modCodeFournisseur->code_auto) print '<input type="hidden" name="code_auto" value="1">';
1686
+            if ($modCodeClient->code_auto || $modCodeFournisseur->code_auto) {
1687
+            	print '<input type="hidden" name="code_auto" value="1">';
1688
+            }
1622 1689
 
1623 1690
 
1624 1691
             dol_fiche_head($head, 'card', $langs->trans("ThirdParty"), 0, 'company');
@@ -1643,16 +1710,17 @@  discard block
 block discarded – undo
1643 1710
 	        print '<td colspan="3"><input type="text" class="minwidth300" name="name_alias" id="name_alias_input" value="'.dol_escape_htmltag($object->name_alias).'"></td></tr>';
1644 1711
 
1645 1712
             // Prefix
1646
-            if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
1713
+            if (! empty($conf->global->SOCIETE_USEPREFIX)) {
1714
+            	// Old not used prefix field
1647 1715
             {
1648 1716
                 print '<tr><td>'.fieldLabel('Prefix','prefix').'</td><td colspan="3">';
1717
+            }
1649 1718
                 // It does not change the prefix mode using the auto numbering prefix
1650 1719
                 if (($prefixCustomerIsUsed || $prefixSupplierIsUsed) && $object->prefix_comm)
1651 1720
                 {
1652 1721
                     print '<input type="hidden" name="prefix_comm" value="'.dol_escape_htmltag($object->prefix_comm).'">';
1653 1722
                     print $object->prefix_comm;
1654
-                }
1655
-                else
1723
+                } else
1656 1724
                 {
1657 1725
                     print '<input type="text" size="5" maxlength="5" name="prefix_comm" id="prefix" value="'.dol_escape_htmltag($object->prefix_comm).'">';
1658 1726
                 }
@@ -1662,9 +1730,15 @@  discard block
 block discarded – undo
1662 1730
             // Prospect/Customer
1663 1731
             print '<tr><td>'.fieldLabel('ProspectCustomer','customerprospect',1).'</td>';
1664 1732
 	        print '<td class="maxwidthonsmartphone"><select class="flat" name="client" id="customerprospect">';
1665
-            if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) print '<option value="2"'.($object->client==2?' selected':'').'>'.$langs->trans('Prospect').'</option>';
1666
-            if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print '<option value="3"'.($object->client==3?' selected':'').'>'.$langs->trans('ProspectCustomer').'</option>';
1667
-            if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print '<option value="1"'.($object->client==1?' selected':'').'>'.$langs->trans('Customer').'</option>';
1733
+            if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
1734
+            	print '<option value="2"'.($object->client==2?' selected':'').'>'.$langs->trans('Prospect').'</option>';
1735
+            }
1736
+            if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
1737
+            	print '<option value="3"'.($object->client==3?' selected':'').'>'.$langs->trans('ProspectCustomer').'</option>';
1738
+            }
1739
+            if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
1740
+            	print '<option value="1"'.($object->client==1?' selected':'').'>'.$langs->trans('Customer').'</option>';
1741
+            }
1668 1742
             print '<option value="0"'.($object->client==0?' selected':'').'>'.$langs->trans('NorProspectNorCustomer').'</option>';
1669 1743
             print '</select></td>';
1670 1744
             print '<td>'.fieldLabel('CustomerCode','customer_code').'</td><td>';
@@ -1673,15 +1747,18 @@  discard block
 block discarded – undo
1673 1747
             if ((!$object->code_client || $object->code_client == -1) && $modCodeClient->code_auto)
1674 1748
             {
1675 1749
                 $tmpcode=$object->code_client;
1676
-                if (empty($tmpcode) && ! empty($object->oldcopy->code_client)) $tmpcode=$object->oldcopy->code_client; // When there is an error to update a thirdparty, the number for supplier and customer code is kept to old value.
1677
-                if (empty($tmpcode) && ! empty($modCodeClient->code_auto)) $tmpcode=$modCodeClient->getNextValue($object,0);
1750
+                if (empty($tmpcode) && ! empty($object->oldcopy->code_client)) {
1751
+                	$tmpcode=$object->oldcopy->code_client;
1752
+                }
1753
+                // When there is an error to update a thirdparty, the number for supplier and customer code is kept to old value.
1754
+                if (empty($tmpcode) && ! empty($modCodeClient->code_auto)) {
1755
+                	$tmpcode=$modCodeClient->getNextValue($object,0);
1756
+                }
1678 1757
                 print '<input type="text" name="code_client" id="customer_code" size="16" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
1679
-            }
1680
-            else if ($object->codeclient_modifiable())
1758
+            } else if ($object->codeclient_modifiable())
1681 1759
             {
1682 1760
                 print '<input type="text" name="code_client" id="customer_code" size="16" value="'.$object->code_client.'" maxlength="15">';
1683
-            }
1684
-            else
1761
+            } else
1685 1762
             {
1686 1763
                 print $object->code_client;
1687 1764
                 print '<input type="hidden" name="code_client" value="'.$object->code_client.'">';
@@ -1706,15 +1783,18 @@  discard block
 block discarded – undo
1706 1783
                 if ((!$object->code_fournisseur || $object->code_fournisseur == -1) && $modCodeFournisseur->code_auto)
1707 1784
                 {
1708 1785
                     $tmpcode=$object->code_fournisseur;
1709
-                    if (empty($tmpcode) && ! empty($object->oldcopy->code_fournisseur)) $tmpcode=$object->oldcopy->code_fournisseur; // When there is an error to update a thirdparty, the number for supplier and customer code is kept to old value.
1710
-                    if (empty($tmpcode) && ! empty($modCodeFournisseur->code_auto)) $tmpcode=$modCodeFournisseur->getNextValue($object,1);
1786
+                    if (empty($tmpcode) && ! empty($object->oldcopy->code_fournisseur)) {
1787
+                    	$tmpcode=$object->oldcopy->code_fournisseur;
1788
+                    }
1789
+                    // When there is an error to update a thirdparty, the number for supplier and customer code is kept to old value.
1790
+                    if (empty($tmpcode) && ! empty($modCodeFournisseur->code_auto)) {
1791
+                    	$tmpcode=$modCodeFournisseur->getNextValue($object,1);
1792
+                    }
1711 1793
                     print '<input type="text" name="code_fournisseur" id="supplier_code" size="16" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
1712
-                }
1713
-                else if ($object->codefournisseur_modifiable())
1794
+                } else if ($object->codefournisseur_modifiable())
1714 1795
                 {
1715 1796
                     print '<input type="text" name="code_fournisseur" id="supplier_code" size="16" value="'.$object->code_fournisseur.'" maxlength="15">';
1716
-                }
1717
-                else
1797
+                } else
1718 1798
               {
1719 1799
                     print $object->code_fournisseur;
1720 1800
                     print '<input type="hidden" name="code_fournisseur" value="'.$object->code_fournisseur.'">';
@@ -1756,7 +1836,9 @@  discard block
 block discarded – undo
1756 1836
             // Country
1757 1837
             print '<tr><td>'.fieldLabel('Country','selectcounty_id').'</td><td colspan="3">';
1758 1838
             print $form->select_country((GETPOST('country_id')!=''?GETPOST('country_id'):$object->country_id),'country_id');
1759
-            if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1839
+            if ($user->admin) {
1840
+            	print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1841
+            }
1760 1842
             print '</td></tr>';
1761 1843
 
1762 1844
             // State
@@ -1765,8 +1847,7 @@  discard block
 block discarded – undo
1765 1847
                 if(!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && ($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 || $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 2))
1766 1848
                 {
1767 1849
                     print '<tr><td>'.fieldLabel('Region-State','state_id').'</td><td colspan="3">';
1768
-                }
1769
-                else
1850
+                } else
1770 1851
                 {
1771 1852
                     print '<tr><td>'.fieldLabel('State','state_id').'</td><td colspan="3">';
1772 1853
                 }
@@ -1803,22 +1884,29 @@  discard block
 block discarded – undo
1803 1884
                 {
1804 1885
 	                $key='idprof'.$i;
1805 1886
 
1806
-	                if (($j % 2) == 0) print '<tr>';
1887
+	                if (($j % 2) == 0) {
1888
+	                	print '<tr>';
1889
+	                }
1807 1890
 
1808 1891
 	                $idprof_mandatory ='SOCIETE_IDPROF'.($i).'_MANDATORY';
1809
-	                if (empty($conf->global->$idprof_mandatory) || ! $object->isACompany())
1810
-	                    print '<td>'.fieldLabel($idprof,$key).'</td><td>';
1811
-                    else
1812
-	                    print '<td><span class="fieldrequired">'.fieldLabel($idprof,$key).'</td><td>';
1892
+	                if (empty($conf->global->$idprof_mandatory) || ! $object->isACompany()) {
1893
+	                	                    print '<td>'.fieldLabel($idprof,$key).'</td><td>';
1894
+	                } else {
1895
+                    	                    print '<td><span class="fieldrequired">'.fieldLabel($idprof,$key).'</td><td>';
1896
+                    }
1813 1897
 
1814 1898
 	                print $formcompany->get_input_id_prof($i,$key,$object->$key,$object->country_code);
1815 1899
                     print '</td>';
1816
-                    if (($j % 2) == 1) print '</tr>';
1900
+                    if (($j % 2) == 1) {
1901
+                    	print '</tr>';
1902
+                    }
1817 1903
                     $j++;
1818 1904
                 }
1819 1905
                 $i++;
1820 1906
             }
1821
-            if ($j % 2 == 1) print '<td colspan="2"></td></tr>';
1907
+            if ($j % 2 == 1) {
1908
+            	print '<td colspan="2"></td></tr>';
1909
+            }
1822 1910
 
1823 1911
             // VAT is used
1824 1912
             print '<tr><td>'.fieldLabel('VATIsUsed','assujtva_value').'</td><td colspan="3">';
@@ -1849,8 +1937,7 @@  discard block
 block discarded – undo
1849 1937
                 }
1850 1938
                 print '</td></tr>';
1851 1939
 
1852
-            }
1853
-            elseif($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj!="1")
1940
+            } elseif($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj!="1")
1854 1941
             {
1855 1942
                 print '<tr><td>'.fieldLabel($langs->transcountry("LocalTax1IsUsed",$mysoc->country_code),'localtax1assuj_value').'</td><td colspan="3">';
1856 1943
                 print $form->selectyesno('localtax1assuj_value',$object->localtax1_assuj,1);
@@ -1862,8 +1949,7 @@  discard block
 block discarded – undo
1862 1949
                 }
1863 1950
                 print '</td></tr>';
1864 1951
 
1865
-            }
1866
-            elseif($mysoc->localtax2_assuj=="1" && $mysoc->localtax1_assuj!="1")
1952
+            } elseif($mysoc->localtax2_assuj=="1" && $mysoc->localtax1_assuj!="1")
1867 1953
             {
1868 1954
                 print '<tr><td>'.fieldLabel($langs->transcountry("LocalTax2IsUsed",$mysoc->country_code),'localtax2assuj_value').'</td><td colspan="3">';
1869 1955
                 print $form->selectyesno('localtax2assuj_value',$object->localtax2_assuj,1);
@@ -1896,8 +1982,7 @@  discard block
 block discarded – undo
1896 1982
                     print "\n";
1897 1983
                     $s.='<a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT(document.formsoc.tva_intra.value);">'.$langs->trans("VATIntraCheck").'</a>';
1898 1984
                     $s = $form->textwithpicto($s,$langs->trans("VATIntraCheckDesc",$langs->trans("VATIntraCheck")),1);
1899
-                }
1900
-                else
1985
+                } else
1901 1986
                 {
1902 1987
                     $s.='<a href="'.$langs->transcountry("VATIntraCheckURL",$object->country_id).'" class="hideonsmartphone" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"),'help').'</a>';
1903 1988
                 }
@@ -1909,11 +1994,15 @@  discard block
 block discarded – undo
1909 1994
             // Type - Size
1910 1995
             print '<tr><td>'.fieldLabel('ThirdPartyType','typent_id').'</td><td class="maxwidthonsmartphone">';
1911 1996
             print $form->selectarray("typent_id",$formcompany->typent_array(0), $object->typent_id, 0, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT)?'ASC':$conf->global->SOCIETE_SORT_ON_TYPEENT));
1912
-            if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1997
+            if ($user->admin) {
1998
+            	print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
1999
+            }
1913 2000
             print '</td>';
1914 2001
             print '<td>'.fieldLabel('Staff','effectif_id').'</td><td class="maxwidthonsmartphone">';
1915 2002
             print $form->selectarray("effectif_id",$formcompany->effectif_array(0), $object->effectif_id);
1916
-            if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
2003
+            if ($user->admin) {
2004
+            	print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
2005
+            }
1917 2006
             print '</td></tr>';
1918 2007
 
1919 2008
             // Juridical type
@@ -2009,13 +2098,19 @@  discard block
 block discarded – undo
2009 2098
             print '<tr class="hideonsmartphone">';
2010 2099
             print '<td>'.fieldLabel('Logo','photoinput').'</td>';
2011 2100
             print '<td colspan="3">';
2012
-            if ($object->logo) print $form->showphoto('societe',$object);
2101
+            if ($object->logo) {
2102
+            	print $form->showphoto('societe',$object);
2103
+            }
2013 2104
             $caneditfield=1;
2014 2105
             if ($caneditfield)
2015 2106
             {
2016
-                if ($object->logo) print "<br>\n";
2107
+                if ($object->logo) {
2108
+                	print "<br>\n";
2109
+                }
2017 2110
                 print '<table class="nobordernopadding">';
2018
-                if ($object->logo) print '<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> '.$langs->trans("Delete").'<br><br></td></tr>';
2111
+                if ($object->logo) {
2112
+                	print '<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> '.$langs->trans("Delete").'<br><br></td></tr>';
2113
+                }
2019 2114
                 //print '<tr><td>'.$langs->trans("PhotoFile").'</td></tr>';
2020 2115
                 print '<tr><td><input type="file" class="flat" name="photo" id="photoinput"></td></tr>';
2021 2116
                 print '</table>';
@@ -2036,14 +2131,15 @@  discard block
 block discarded – undo
2036 2131
 
2037 2132
             print '</form>';
2038 2133
         }
2039
-    }
2040
-    else
2134
+    } else
2041 2135
     {
2042 2136
     	/*
2043 2137
          * View
2044 2138
          */
2045 2139
 
2046
-        if (!empty($object->id)) $res=$object->fetch_optionals();
2140
+        if (!empty($object->id)) {
2141
+        	$res=$object->fetch_optionals();
2142
+        }
2047 2143
         //if ($res < 0) { dol_print_error($db); exit; }
2048 2144
 
2049 2145
 
@@ -2098,9 +2194,11 @@  discard block
 block discarded – undo
2098 2194
     	}
2099 2195
 
2100 2196
     	// Prefix
2101
-        if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
2197
+        if (! empty($conf->global->SOCIETE_USEPREFIX)) {
2198
+        	// Old not used prefix field
2102 2199
         {
2103 2200
             print '<tr><td>'.$langs->trans('Prefix').'</td><td>'.$object->prefix_comm.'</td>';
2201
+        }
2104 2202
             print $htmllogobar; $htmllogobar='';
2105 2203
             print '</tr>';
2106 2204
         }
@@ -2111,7 +2209,9 @@  discard block
 block discarded – undo
2111 2209
             print '<tr><td>';
2112 2210
             print $langs->trans('CustomerCode').'</td><td>';
2113 2211
             print $object->code_client;
2114
-            if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
2212
+            if ($object->check_codeclient() <> 0) {
2213
+            	print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
2214
+            }
2115 2215
             print '</td>';
2116 2216
             print $htmllogobar; $htmllogobar='';
2117 2217
             print '</tr>';
@@ -2123,7 +2223,9 @@  discard block
 block discarded – undo
2123 2223
             print '<tr><td>';
2124 2224
             print $langs->trans('SupplierCode').'</td><td>';
2125 2225
             print $object->code_fournisseur;
2126
-            if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
2226
+            if ($object->check_codefournisseur() <> 0) {
2227
+            	print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
2228
+            }
2127 2229
             print '</td>';
2128 2230
             print $htmllogobar; $htmllogobar='';
2129 2231
             print '</tr>';
@@ -2135,7 +2237,9 @@  discard block
 block discarded – undo
2135 2237
             print '<tr><td>';
2136 2238
             print $langs->trans('Gencod').'</td><td>'.$object->barcode;
2137 2239
             print '</td>';
2138
-			if ($htmllogobar) $htmllogobar.=$form->showbarcode($object);
2240
+			if ($htmllogobar) {
2241
+				$htmllogobar.=$form->showbarcode($object);
2242
+			}
2139 2243
             print $htmllogobar;
2140 2244
 			$htmllogobar='';
2141 2245
             print '</tr>';
@@ -2155,8 +2259,11 @@  discard block
 block discarded – undo
2155 2259
                 print $object->$key;
2156 2260
                 if ($object->$key)
2157 2261
                 {
2158
-                    if ($object->id_prof_check($i,$object) > 0) print ' &nbsp; '.$object->id_prof_url($i,$object);
2159
-                    else print ' <font class="error">('.$langs->trans("ErrorWrongValue").')</font>';
2262
+                    if ($object->id_prof_check($i,$object) > 0) {
2263
+                    	print ' &nbsp; '.$object->id_prof_url($i,$object);
2264
+                    } else {
2265
+                    	print ' <font class="error">('.$langs->trans("ErrorWrongValue").')</font>';
2266
+                    }
2160 2267
                 }
2161 2268
                 print '</td>';
2162 2269
                 //if (($j % 2) == 1) print '</tr>';
@@ -2196,8 +2303,7 @@  discard block
 block discarded – undo
2196 2303
 		            print '<td align="left">';
2197 2304
 		            $formcompany->select_localtax(1,$object->localtax1_value, "lt1");
2198 2305
 		            print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2199
-		        }
2200
-		        else
2306
+		        } else
2201 2307
 		        {
2202 2308
 		            print '<td>'.$object->localtax1_value.'</td>';
2203 2309
 		        }
@@ -2213,13 +2319,12 @@  discard block
 block discarded – undo
2213 2319
 		            print '<td align="left">';
2214 2320
 		            $formcompany->select_localtax(2,$object->localtax2_value, "lt2");
2215 2321
 		            print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2216
-		        }else{
2322
+		        } else{
2217 2323
 		            print '<td>'.$object->localtax2_value.'</td>';
2218 2324
 		        }
2219 2325
 		        print '</tr></form>';
2220 2326
 		    }
2221
-		}
2222
-		elseif($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj!="1")
2327
+		} elseif($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj!="1")
2223 2328
 		{
2224 2329
 		    print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed",$mysoc->country_code).'</td><td>';
2225 2330
 		    print yn($object->localtax1_assuj);
@@ -2234,14 +2339,13 @@  discard block
 block discarded – undo
2234 2339
 		            print '<td align="left">';
2235 2340
 		            $formcompany->select_localtax(1,$object->localtax1_value, "lt1");
2236 2341
 		            print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2237
-		        }else{
2342
+		        } else{
2238 2343
 		            print '<td>'.$object->localtax1_value.'</td>';
2239 2344
 		        }
2240 2345
 		        print '</tr></form>';
2241 2346
 
2242 2347
 		    }
2243
-		}
2244
-		elseif($mysoc->localtax2_assuj=="1" && $mysoc->localtax1_assuj!="1")
2348
+		} elseif($mysoc->localtax2_assuj=="1" && $mysoc->localtax1_assuj!="1")
2245 2349
 		{
2246 2350
 		    print '<tr><td>'.$langs->transcountry("LocalTax2IsUsed",$mysoc->country_code).'</td><td>';
2247 2351
 		    print yn($object->localtax2_assuj);
@@ -2257,7 +2361,7 @@  discard block
 block discarded – undo
2257 2361
 		            print '<td align="left">';
2258 2362
 		            $formcompany->select_localtax(2,$object->localtax2_value, "lt2");
2259 2363
 		            print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
2260
-		        }else{
2364
+		        } else{
2261 2365
 		            print '<td>'.$object->localtax2_value.'</td>';
2262 2366
 		        }
2263 2367
 		        print '</tr></form>';
@@ -2297,15 +2401,13 @@  discard block
 block discarded – undo
2297 2401
                     print "\n";
2298 2402
                     $s.='<a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT( $(\'#tva_intra\').val() );">'.$langs->trans("VATIntraCheck").'</a>';
2299 2403
                     $s = $form->textwithpicto($s,$langs->trans("VATIntraCheckDesc",$langs->trans("VATIntraCheck")),1);
2300
-                }
2301
-                else
2404
+                } else
2302 2405
                 {
2303 2406
                     $s.='<a href="'.$langs->transcountry("VATIntraCheckURL",$object->country_id).'" class="hideonsmartphone" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"),'help').'</a>';
2304 2407
                 }
2305 2408
             }
2306 2409
             print $s;
2307
-        }
2308
-        else
2410
+        } else
2309 2411
         {
2310 2412
             print '&nbsp;';
2311 2413
         }
@@ -2351,8 +2453,11 @@  discard block
 block discarded – undo
2351 2453
 
2352 2454
         // Capital
2353 2455
         print '<tr><td>'.$langs->trans('Capital').'</td><td>';
2354
-        if ($object->capital) print price($object->capital,'',$langs,0,-1,-1, $conf->currency);
2355
-        else print '&nbsp;';
2456
+        if ($object->capital) {
2457
+        	print price($object->capital,'',$langs,0,-1,-1, $conf->currency);
2458
+        } else {
2459
+        	print '&nbsp;';
2460
+        }
2356 2461
         print '</td></tr>';
2357 2462
 
2358 2463
         // Default language
@@ -2375,16 +2480,18 @@  discard block
 block discarded – undo
2375 2480
             print '<table width="100%" class="nobordernopadding"><tr><td>';
2376 2481
             print $langs->trans('IncotermLabel');
2377 2482
             print '<td><td align="right">';
2378
-            if ($user->rights->societe->creer) print '<a href="'.DOL_URL_ROOT.'/societe/card.php?socid='.$object->id.'&action=editincoterm">'.img_edit('',1).'</a>';
2379
-            else print '&nbsp;';
2483
+            if ($user->rights->societe->creer) {
2484
+            	print '<a href="'.DOL_URL_ROOT.'/societe/card.php?socid='.$object->id.'&action=editincoterm">'.img_edit('',1).'</a>';
2485
+            } else {
2486
+            	print '&nbsp;';
2487
+            }
2380 2488
             print '</td></tr></table>';
2381 2489
             print '</td>';
2382 2490
             print '<td colspan="3">';
2383 2491
 			if ($action != 'editincoterm')
2384 2492
 			{
2385 2493
 				print $form->textwithpicto($object->display_incoterms(), $object->libelle_incoterms, 1);
2386
-			}
2387
-			else
2494
+			} else
2388 2495
 			{
2389 2496
 				print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''), $_SERVER['PHP_SELF'].'?socid='.$object->id);
2390 2497
 			}
@@ -2413,14 +2520,15 @@  discard block
 block discarded – undo
2413 2520
         	print '<table class="nobordernopadding" width="100%"><tr><td>';
2414 2521
         	print $langs->trans('ParentCompany');
2415 2522
         	print '</td>';
2416
-        	if ($action != 'editparentcompany') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editparentcompany&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</a></td>';
2523
+        	if ($action != 'editparentcompany') {
2524
+        		print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editparentcompany&amp;socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</a></td>';
2525
+        	}
2417 2526
         	print '</tr></table>';
2418 2527
         	print '</td><td colspan="3">';
2419 2528
         	if ($action == 'editparentcompany')
2420 2529
         	{
2421 2530
         		$form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->parent,'editparentcompany','s.rowid <> '.$object->id,1);
2422
-        	}
2423
-        	else
2531
+        	} else
2424 2532
         	{
2425 2533
         		$form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->parent,'none','s.rowid <> '.$object->id,1);
2426 2534
         	}
@@ -2443,8 +2551,7 @@  discard block
 block discarded – undo
2443 2551
             {
2444 2552
                 $adh->ref=$adh->getFullName($langs);
2445 2553
                 print $adh->getNomUrl(1);
2446
-            }
2447
-            else
2554
+            } else
2448 2555
             {
2449 2556
                 print '<span class="opacitymedium">'.$langs->trans("ThirdpartyNotLinkedToMember").'</span>';
2450 2557
             }
@@ -2493,8 +2600,7 @@  discard block
 block discarded – undo
2493 2600
 		        {
2494 2601
 		        	$langs->load("mails");
2495 2602
 		        	print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'&amp;action=presend&amp;mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a></div>';
2496
-		        }
2497
-		        else
2603
+		        } else
2498 2604
 				{
2499 2605
 		        	$langs->load("mails");
2500 2606
 		       		print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NoEMail")).'">'.$langs->trans('SendMail').'</a></div>';
@@ -2512,11 +2618,12 @@  discard block
 block discarded – undo
2512 2618
 
2513 2619
 		        if ($user->rights->societe->supprimer)
2514 2620
 		        {
2515
-		            if ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile))	// We can't use preloaded confirm form with jmobile
2621
+		            if ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile)) {
2622
+		            	// We can't use preloaded confirm form with jmobile
2516 2623
 		            {
2517 2624
 		                print '<div class="inline-block divButAction"><span id="action-delete" class="butActionDelete">'.$langs->trans('Delete').'</span></div>'."\n";
2518 2625
 		            }
2519
-		            else
2626
+		            } else
2520 2627
 					{
2521 2628
 		                print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&amp;action=delete">'.$langs->trans('Delete').'</a></div>'."\n";
2522 2629
 		            }
Please login to merge, or discard this patch.