Completed
Branch develop (c604ce)
by
unknown
32:31
created
htdocs/core/modules/product/doc/doc_generic_product_odt.modules.php 1 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.
htdocs/core/modules/usergroup/doc/doc_generic_usergroup_odt.modules.php 1 patch
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.
htdocs/core/modules/expedition/doc/doc_generic_shipment_odt.modules.php 1 patch
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.
htdocs/core/lib/functions.lib.php 1 patch
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.
htdocs/core/lib/files.lib.php 1 patch
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.
htdocs/install/step1.php 1 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 1 patch
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.
htdocs/societe/card.php 1 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.