Passed
Push — master ( 65bdac...4e88da )
by Alxarafe
32:38
created
dolibarr/htdocs/core/class/utils.class.php 1 patch
Spacing   +196 added lines, -196 removed lines patch added patch discarded remove patch
@@ -32,8 +32,8 @@  discard block
 block discarded – undo
32 32
      */
33 33
     public $db;
34 34
 
35
-	var $output;   // Used by Cron method to return message
36
-	var $result;   // Used by Cron method to return data
35
+	var $output; // Used by Cron method to return message
36
+	var $result; // Used by Cron method to return data
37 37
 
38 38
 	/**
39 39
 	 *	Constructor
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 	 *  @param	string		$choice		Choice of purge mode ('tempfiles', '' or 'tempfilesold' to purge temp older than 24h, 'allfiles', 'logfile')
54 54
 	 *  @return	int						0 if OK, < 0 if KO (this function is used also by cron so only 0 is OK)
55 55
 	 */
56
-	function purgeFiles($choice='tempfilesold')
56
+	function purgeFiles($choice = 'tempfilesold')
57 57
 	{
58 58
 		global $conf, $langs, $dolibarr_main_data_root;
59 59
 
@@ -62,80 +62,80 @@  discard block
 block discarded – undo
62 62
 		dol_syslog("Utils::purgeFiles choice=".$choice, LOG_DEBUG);
63 63
 		require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
64 64
 
65
-		$filesarray=array();
66
-		if (empty($choice)) $choice='tempfilesold';
65
+		$filesarray = array();
66
+		if (empty($choice)) $choice = 'tempfilesold';
67 67
 
68
-		if ($choice=='tempfiles' || $choice=='tempfilesold')
68
+		if ($choice == 'tempfiles' || $choice == 'tempfilesold')
69 69
 		{
70 70
 			// Delete temporary files
71 71
 			if ($dolibarr_main_data_root)
72 72
 			{
73
-				$filesarray=dol_dir_list($dolibarr_main_data_root, "directories", 1, '^temp$', '', 'name', SORT_ASC, 2, 0, '', 1);	// Do not follow symlinks
73
+				$filesarray = dol_dir_list($dolibarr_main_data_root, "directories", 1, '^temp$', '', 'name', SORT_ASC, 2, 0, '', 1); // Do not follow symlinks
74 74
 				if ($choice == 'tempfilesold')
75 75
 				{
76 76
 					$now = dol_now();
77
-					foreach($filesarray as $key => $val)
77
+					foreach ($filesarray as $key => $val)
78 78
 					{
79
-						if ($val['date'] > ($now - (24 * 3600))) unset($filesarray[$key]);	// Discard files not older than 24h
79
+						if ($val['date'] > ($now - (24 * 3600))) unset($filesarray[$key]); // Discard files not older than 24h
80 80
 					}
81 81
 				}
82 82
 			}
83 83
 		}
84 84
 
85
-		if ($choice=='allfiles')
85
+		if ($choice == 'allfiles')
86 86
 		{
87 87
 			// Delete all files (except install.lock, do not follow symbolic links)
88 88
 			if ($dolibarr_main_data_root)
89 89
 			{
90
-				$filesarray=dol_dir_list($dolibarr_main_data_root, "all", 0, '', 'install\.lock$', 'name', SORT_ASC, 0, 0, '', 1);
90
+				$filesarray = dol_dir_list($dolibarr_main_data_root, "all", 0, '', 'install\.lock$', 'name', SORT_ASC, 0, 0, '', 1);
91 91
 			}
92 92
 		}
93 93
 
94
-		if ($choice=='logfile')
94
+		if ($choice == 'logfile')
95 95
 		{
96 96
 			// Define files log
97 97
 			if ($dolibarr_main_data_root)
98 98
 			{
99
-				$filesarray=dol_dir_list($dolibarr_main_data_root, "files", 0, '.*\.log[\.0-9]*(\.gz)?$', 'install\.lock$', 'name', SORT_ASC, 0, 0, '', 1);
99
+				$filesarray = dol_dir_list($dolibarr_main_data_root, "files", 0, '.*\.log[\.0-9]*(\.gz)?$', 'install\.lock$', 'name', SORT_ASC, 0, 0, '', 1);
100 100
 			}
101 101
 
102
-			$filelog='';
103
-			if (! empty($conf->syslog->enabled))
102
+			$filelog = '';
103
+			if (!empty($conf->syslog->enabled))
104 104
 			{
105
-				$filelog=$conf->global->SYSLOG_FILE;
106
-				$filelog=preg_replace('/DOL_DATA_ROOT/i',DOL_DATA_ROOT,$filelog);
105
+				$filelog = $conf->global->SYSLOG_FILE;
106
+				$filelog = preg_replace('/DOL_DATA_ROOT/i', DOL_DATA_ROOT, $filelog);
107 107
 
108
-				$alreadyincluded=false;
108
+				$alreadyincluded = false;
109 109
 				foreach ($filesarray as $tmpcursor)
110 110
 				{
111
-					if ($tmpcursor['fullname'] == $filelog) { $alreadyincluded=true; }
111
+					if ($tmpcursor['fullname'] == $filelog) { $alreadyincluded = true; }
112 112
 				}
113
-				if (! $alreadyincluded) $filesarray[]=array('fullname'=>$filelog,'type'=>'file');
113
+				if (!$alreadyincluded) $filesarray[] = array('fullname'=>$filelog, 'type'=>'file');
114 114
 			}
115 115
 		}
116 116
 
117
-		$count=0;
118
-		$countdeleted=0;
119
-		$counterror=0;
117
+		$count = 0;
118
+		$countdeleted = 0;
119
+		$counterror = 0;
120 120
 		if (count($filesarray))
121 121
 		{
122
-			foreach($filesarray as $key => $value)
122
+			foreach ($filesarray as $key => $value)
123 123
 			{
124 124
 				//print "x ".$filesarray[$key]['fullname']."-".$filesarray[$key]['type']."<br>\n";
125 125
 				if ($filesarray[$key]['type'] == 'dir')
126 126
 				{
127
-					$startcount=0;
128
-					$tmpcountdeleted=0;
129
-					$result=dol_delete_dir_recursive($filesarray[$key]['fullname'], $startcount, 1, 0, $tmpcountdeleted);
130
-					$count+=$result;
131
-					$countdeleted+=$tmpcountdeleted;
127
+					$startcount = 0;
128
+					$tmpcountdeleted = 0;
129
+					$result = dol_delete_dir_recursive($filesarray[$key]['fullname'], $startcount, 1, 0, $tmpcountdeleted);
130
+					$count += $result;
131
+					$countdeleted += $tmpcountdeleted;
132 132
 				}
133 133
 				elseif ($filesarray[$key]['type'] == 'file')
134 134
 				{
135 135
 					// If (file that is not logfile) or (if mode is logfile)
136
-					if ($filesarray[$key]['fullname'] != $filelog || $choice=='logfile')
136
+					if ($filesarray[$key]['fullname'] != $filelog || $choice == 'logfile')
137 137
 					{
138
-						$result=dol_delete_file($filesarray[$key]['fullname'], 1, 1);
138
+						$result = dol_delete_file($filesarray[$key]['fullname'], 1, 1);
139 139
 						if ($result)
140 140
 						{
141 141
 							$count++;
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 			}
151 151
 
152 152
 			// Update cachenbofdoc
153
-			if (! empty($conf->ecm->enabled) && $choice=='allfiles')
153
+			if (!empty($conf->ecm->enabled) && $choice == 'allfiles')
154 154
 			{
155 155
 				require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmdirectory.class.php';
156 156
 				$ecmdirstatic = new EcmDirectory($this->db);
@@ -160,13 +160,13 @@  discard block
 block discarded – undo
160 160
 
161 161
 		if ($count > 0)
162 162
 		{
163
-			$this->output=$langs->trans("PurgeNDirectoriesDeleted", $countdeleted);
164
-			if ($count > $countdeleted) $this->output.='<br>'.$langs->trans("PurgeNDirectoriesFailed", ($count - $countdeleted));
163
+			$this->output = $langs->trans("PurgeNDirectoriesDeleted", $countdeleted);
164
+			if ($count > $countdeleted) $this->output .= '<br>'.$langs->trans("PurgeNDirectoriesFailed", ($count - $countdeleted));
165 165
 		}
166
-		else $this->output=$langs->trans("PurgeNothingToDelete").($choice == 'tempfilesold' ? ' (older than 24h)':'');
166
+		else $this->output = $langs->trans("PurgeNothingToDelete").($choice == 'tempfilesold' ? ' (older than 24h)' : '');
167 167
 
168 168
 		//return $count;
169
-		return 0;     // This function can be called by cron so must return 0 if OK
169
+		return 0; // This function can be called by cron so must return 0 if OK
170 170
 	}
171 171
 
172 172
 
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 	 *  @param	int		    $execmethod		   0=Use default method (that is 1 by default), 1=Use the PHP 'exec', 2=Use the 'popen' method
183 183
 	 *  @return	int						       0 if OK, < 0 if KO (this function is used also by cron so only 0 is OK)
184 184
 	 */
185
-	function dumpDatabase($compression='none', $type='auto', $usedefault=1, $file='auto', $keeplastnfiles=0, $execmethod=0)
185
+	function dumpDatabase($compression = 'none', $type = 'auto', $usedefault = 1, $file = 'auto', $keeplastnfiles = 0, $execmethod = 0)
186 186
 	{
187 187
 		global $db, $conf, $langs, $dolibarr_main_data_root;
188 188
 		global $dolibarr_main_db_name, $dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_port, $dolibarr_main_db_pass;
@@ -193,112 +193,112 @@  discard block
 block discarded – undo
193 193
 		require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
194 194
 
195 195
 		// Check compression parameter
196
-		if (! in_array($compression, array('none', 'gz', 'bz', 'zip')))
196
+		if (!in_array($compression, array('none', 'gz', 'bz', 'zip')))
197 197
 		{
198 198
 			$langs->load("errors");
199
-			$this->error=$langs->transnoentitiesnoconv("ErrorBadValueForParameter", $compression, "Compression");
199
+			$this->error = $langs->transnoentitiesnoconv("ErrorBadValueForParameter", $compression, "Compression");
200 200
 			return -1;
201 201
 		}
202 202
 
203 203
 		// Check type parameter
204 204
 		if ($type == 'auto') $type = $db->type;
205
-		if (! in_array($type, array('postgresql', 'pgsql', 'mysql', 'mysqli', 'mysqlnobin')))
205
+		if (!in_array($type, array('postgresql', 'pgsql', 'mysql', 'mysqli', 'mysqlnobin')))
206 206
 		{
207 207
 			$langs->load("errors");
208
-			$this->error=$langs->transnoentitiesnoconv("ErrorBadValueForParameter", $type, "Basetype");
208
+			$this->error = $langs->transnoentitiesnoconv("ErrorBadValueForParameter", $type, "Basetype");
209 209
 			return -1;
210 210
 		}
211 211
 
212 212
 		// Check file parameter
213 213
 		if ($file == 'auto')
214 214
 		{
215
-			$prefix='dump';
216
-			$ext='sql';
217
-			if (in_array($type, array('mysql', 'mysqli')))  { $prefix='mysqldump'; $ext='sql'; }
215
+			$prefix = 'dump';
216
+			$ext = 'sql';
217
+			if (in_array($type, array('mysql', 'mysqli'))) { $prefix = 'mysqldump'; $ext = 'sql'; }
218 218
 			//if ($label == 'PostgreSQL') { $prefix='pg_dump'; $ext='dump'; }
219
-			if (in_array($type, array('pgsql'))) { $prefix='pg_dump'; $ext='sql'; }
220
-			$file=$prefix.'_'.$dolibarr_main_db_name.'_'.dol_sanitizeFileName(DOL_VERSION).'_'.strftime("%Y%m%d%H%M").'.'.$ext;
219
+			if (in_array($type, array('pgsql'))) { $prefix = 'pg_dump'; $ext = 'sql'; }
220
+			$file = $prefix.'_'.$dolibarr_main_db_name.'_'.dol_sanitizeFileName(DOL_VERSION).'_'.strftime("%Y%m%d%H%M").'.'.$ext;
221 221
 		}
222 222
 
223
-		$outputdir  = $conf->admin->dir_output.'/backup';
224
-		$result=dol_mkdir($outputdir);
223
+		$outputdir = $conf->admin->dir_output.'/backup';
224
+		$result = dol_mkdir($outputdir);
225 225
 
226 226
 
227 227
 		// MYSQL
228 228
 		if ($type == 'mysql' || $type == 'mysqli')
229 229
 		{
230
-			$cmddump=$conf->global->SYSTEMTOOLS_MYSQLDUMP;
230
+			$cmddump = $conf->global->SYSTEMTOOLS_MYSQLDUMP;
231 231
 
232 232
 
233 233
 			$outputfile = $outputdir.'/'.$file;
234 234
 			// for compression format, we add extension
235
-			$compression=$compression ? $compression : 'none';
236
-			if ($compression == 'gz') $outputfile.='.gz';
237
-			if ($compression == 'bz') $outputfile.='.bz2';
235
+			$compression = $compression ? $compression : 'none';
236
+			if ($compression == 'gz') $outputfile .= '.gz';
237
+			if ($compression == 'bz') $outputfile .= '.bz2';
238 238
 			$outputerror = $outputfile.'.err';
239 239
 			dol_mkdir($conf->admin->dir_output.'/backup');
240 240
 
241 241
 			// Parameteres execution
242
-			$command=$cmddump;
243
-			if (preg_match("/\s/",$command)) $command=escapeshellarg($command);	// Use quotes on command
242
+			$command = $cmddump;
243
+			if (preg_match("/\s/", $command)) $command = escapeshellarg($command); // Use quotes on command
244 244
 
245 245
 			//$param=escapeshellarg($dolibarr_main_db_name)." -h ".escapeshellarg($dolibarr_main_db_host)." -u ".escapeshellarg($dolibarr_main_db_user)." -p".escapeshellarg($dolibarr_main_db_pass);
246
-			$param=$dolibarr_main_db_name." -h ".$dolibarr_main_db_host;
247
-			$param.=" -u ".$dolibarr_main_db_user;
248
-			if (! empty($dolibarr_main_db_port)) $param.=" -P ".$dolibarr_main_db_port;
249
-			if (! GETPOST("use_transaction"))    $param.=" -l --single-transaction";
250
-			if (GETPOST("disable_fk") || $usedefault) $param.=" -K";
251
-			if (GETPOST("sql_compat") && GETPOST("sql_compat") != 'NONE') $param.=" --compatible=".escapeshellarg(GETPOST("sql_compat","alpha"));
252
-			if (GETPOST("drop_database"))        $param.=" --add-drop-database";
246
+			$param = $dolibarr_main_db_name." -h ".$dolibarr_main_db_host;
247
+			$param .= " -u ".$dolibarr_main_db_user;
248
+			if (!empty($dolibarr_main_db_port)) $param .= " -P ".$dolibarr_main_db_port;
249
+			if (!GETPOST("use_transaction"))    $param .= " -l --single-transaction";
250
+			if (GETPOST("disable_fk") || $usedefault) $param .= " -K";
251
+			if (GETPOST("sql_compat") && GETPOST("sql_compat") != 'NONE') $param .= " --compatible=".escapeshellarg(GETPOST("sql_compat", "alpha"));
252
+			if (GETPOST("drop_database"))        $param .= " --add-drop-database";
253 253
 			if (GETPOST("sql_structure") || $usedefault)
254 254
 			{
255
-				if (GETPOST("drop") || $usedefault)	$param.=" --add-drop-table=TRUE";
256
-				else 							    $param.=" --add-drop-table=FALSE";
255
+				if (GETPOST("drop") || $usedefault)	$param .= " --add-drop-table=TRUE";
256
+				else 							    $param .= " --add-drop-table=FALSE";
257 257
 			}
258 258
 			else
259 259
 			{
260
-				$param.=" -t";
260
+				$param .= " -t";
261 261
 			}
262
-			if (GETPOST("disable-add-locks")) $param.=" --add-locks=FALSE";
262
+			if (GETPOST("disable-add-locks")) $param .= " --add-locks=FALSE";
263 263
 			if (GETPOST("sql_data") || $usedefault)
264 264
 			{
265
-				$param.=" --tables";
266
-				if (GETPOST("showcolumns") || $usedefault)	 $param.=" -c";
267
-				if (GETPOST("extended_ins") || $usedefault) $param.=" -e";
268
-				else $param.=" --skip-extended-insert";
269
-				if (GETPOST("delayed"))	 	 $param.=" --delayed-insert";
270
-				if (GETPOST("sql_ignore"))	 $param.=" --insert-ignore";
271
-				if (GETPOST("hexforbinary") || $usedefault) $param.=" --hex-blob";
265
+				$param .= " --tables";
266
+				if (GETPOST("showcolumns") || $usedefault)	 $param .= " -c";
267
+				if (GETPOST("extended_ins") || $usedefault) $param .= " -e";
268
+				else $param .= " --skip-extended-insert";
269
+				if (GETPOST("delayed"))	 	 $param .= " --delayed-insert";
270
+				if (GETPOST("sql_ignore"))	 $param .= " --insert-ignore";
271
+				if (GETPOST("hexforbinary") || $usedefault) $param .= " --hex-blob";
272 272
 			}
273 273
 			else
274 274
 			{
275
-				$param.=" -d";    // No row information (no data)
275
+				$param .= " -d"; // No row information (no data)
276 276
 			}
277
-			$param.=" --default-character-set=utf8";    // We always save output into utf8 charset
278
-			$paramcrypted=$param;
279
-			$paramclear=$param;
280
-			if (! empty($dolibarr_main_db_pass))
277
+			$param .= " --default-character-set=utf8"; // We always save output into utf8 charset
278
+			$paramcrypted = $param;
279
+			$paramclear = $param;
280
+			if (!empty($dolibarr_main_db_pass))
281 281
 			{
282
-				$paramcrypted.=' -p"'.preg_replace('/./i','*',$dolibarr_main_db_pass).'"';
283
-				$paramclear.=' -p"'.str_replace(array('"','`'),array('\"','\`'),$dolibarr_main_db_pass).'"';
282
+				$paramcrypted .= ' -p"'.preg_replace('/./i', '*', $dolibarr_main_db_pass).'"';
283
+				$paramclear .= ' -p"'.str_replace(array('"', '`'), array('\"', '\`'), $dolibarr_main_db_pass).'"';
284 284
 			}
285 285
 
286
-			$errormsg='';
286
+			$errormsg = '';
287 287
 			$handle = '';
288 288
 
289 289
 			// Start call method to execute dump
290
-			$fullcommandcrypted=$command." ".$paramcrypted." 2>&1";
291
-			$fullcommandclear=$command." ".$paramclear." 2>&1";
290
+			$fullcommandcrypted = $command." ".$paramcrypted." 2>&1";
291
+			$fullcommandclear = $command." ".$paramclear." 2>&1";
292 292
 			if ($compression == 'none') $handle = fopen($outputfile, 'w');
293 293
 			if ($compression == 'gz')   $handle = gzopen($outputfile, 'w');
294 294
 			if ($compression == 'bz')   $handle = bzopen($outputfile, 'w');
295 295
 
296 296
 			if ($handle)
297 297
 			{
298
-				if (! empty($conf->global->MAIN_EXEC_USE_POPEN)) $execmethod=$conf->global->MAIN_EXEC_USE_POPEN;
299
-				if (empty($execmethod)) $execmethod=1;
298
+				if (!empty($conf->global->MAIN_EXEC_USE_POPEN)) $execmethod = $conf->global->MAIN_EXEC_USE_POPEN;
299
+				if (empty($execmethod)) $execmethod = 1;
300 300
 
301
-				$ok=0;
301
+				$ok = 0;
302 302
 				dol_syslog("Utils::dumpDatabase execmethod=".$execmethod." command:".$fullcommandcrypted, LOG_DEBUG);
303 303
 
304 304
 				// TODO Replace with executeCLI function
@@ -312,35 +312,35 @@  discard block
 block discarded – undo
312 312
 						$langs->load("errors");
313 313
 						dol_syslog("Datadump retval after exec=".$retval, LOG_ERR);
314 314
 						$error = 'Error '.$retval;
315
-						$ok=0;
315
+						$ok = 0;
316 316
 					}
317 317
 					else
318 318
 					{
319
-						$i=0;
319
+						$i = 0;
320 320
 						if (!empty($readt))
321
-						foreach($readt as $key=>$read)
321
+						foreach ($readt as $key=>$read)
322 322
 						{
323
-							$i++;   // output line number
323
+							$i++; // output line number
324 324
 							if ($i == 1 && preg_match('/Warning.*Using a password/i', $read)) continue;
325 325
 							fwrite($handle, $read.($execmethod == 2 ? '' : "\n"));
326
-							if (preg_match('/'.preg_quote('-- Dump completed').'/i',$read)) $ok=1;
327
-							elseif (preg_match('/'.preg_quote('SET SQL_NOTES=@OLD_SQL_NOTES').'/i',$read)) $ok=1;
326
+							if (preg_match('/'.preg_quote('-- Dump completed').'/i', $read)) $ok = 1;
327
+							elseif (preg_match('/'.preg_quote('SET SQL_NOTES=@OLD_SQL_NOTES').'/i', $read)) $ok = 1;
328 328
 						}
329 329
 					}
330 330
 				}
331 331
 				if ($execmethod == 2)	// With this method, there is no way to get the return code, only output
332 332
 				{
333 333
 					$handlein = popen($fullcommandclear, 'r');
334
-					$i=0;
334
+					$i = 0;
335 335
 					while (!feof($handlein))
336 336
 					{
337
-						$i++;   // output line number
337
+						$i++; // output line number
338 338
 						$read = fgets($handlein);
339 339
 						// Exclude warning line we don't want
340 340
 						if ($i == 1 && preg_match('/Warning.*Using a password/i', $read)) continue;
341
-						fwrite($handle,$read);
342
-						if (preg_match('/'.preg_quote('-- Dump completed').'/i',$read)) $ok=1;
343
-						elseif (preg_match('/'.preg_quote('SET SQL_NOTES=@OLD_SQL_NOTES').'/i',$read)) $ok=1;
341
+						fwrite($handle, $read);
342
+						if (preg_match('/'.preg_quote('-- Dump completed').'/i', $read)) $ok = 1;
343
+						elseif (preg_match('/'.preg_quote('SET SQL_NOTES=@OLD_SQL_NOTES').'/i', $read)) $ok = 1;
344 344
 					}
345 345
 					pclose($handlein);
346 346
 				}
@@ -350,14 +350,14 @@  discard block
 block discarded – undo
350 350
 				if ($compression == 'gz')   gzclose($handle);
351 351
 				if ($compression == 'bz')   bzclose($handle);
352 352
 
353
-				if (! empty($conf->global->MAIN_UMASK))
353
+				if (!empty($conf->global->MAIN_UMASK))
354 354
 					@chmod($outputfile, octdec($conf->global->MAIN_UMASK));
355 355
 			}
356 356
 			else
357 357
 			{
358 358
 				$langs->load("errors");
359
-				dol_syslog("Failed to open file ".$outputfile,LOG_ERR);
360
-				$errormsg=$langs->trans("ErrorFailedToWriteInDir");
359
+				dol_syslog("Failed to open file ".$outputfile, LOG_ERR);
360
+				$errormsg = $langs->trans("ErrorFailedToWriteInDir");
361 361
 			}
362 362
 
363 363
 			// Get errorstring
@@ -367,23 +367,23 @@  discard block
 block discarded – undo
367 367
 			if ($handle)
368 368
 			{
369 369
 				// Get 2048 first chars of error message.
370
-				$errormsg = fgets($handle,2048);
370
+				$errormsg = fgets($handle, 2048);
371 371
 				// Close file
372 372
 				if ($compression == 'none') fclose($handle);
373 373
 				if ($compression == 'gz')   gzclose($handle);
374 374
 				if ($compression == 'bz')   bzclose($handle);
375
-				if ($ok && preg_match('/^-- MySql/i',$errormsg)) $errormsg='';	// Pas erreur
375
+				if ($ok && preg_match('/^-- MySql/i', $errormsg)) $errormsg = ''; // Pas erreur
376 376
 				else
377 377
 				{
378 378
 					// Renommer fichier sortie en fichier erreur
379 379
 					//print "$outputfile -> $outputerror";
380 380
 					@dol_delete_file($outputerror, 1, 0, 0, null, false, 0);
381
-					@rename($outputfile,$outputerror);
381
+					@rename($outputfile, $outputerror);
382 382
 					// Si safe_mode on et command hors du parametre exec, on a un fichier out vide donc errormsg vide
383
-					if (! $errormsg)
383
+					if (!$errormsg)
384 384
 					{
385 385
 						$langs->load("errors");
386
-						$errormsg=$langs->trans("ErrorFailedToRunExternalCommand");
386
+						$errormsg = $langs->trans("ErrorFailedToRunExternalCommand");
387 387
 					}
388 388
 				}
389 389
 			}
@@ -401,9 +401,9 @@  discard block
 block discarded – undo
401 401
 			$outputfile = $outputdir.'/'.$file;
402 402
 			$outputfiletemp = $outputfile.'-TMP.sql';
403 403
 			// for compression format, we add extension
404
-			$compression=$compression ? $compression : 'none';
405
-			if ($compression == 'gz') $outputfile.='.gz';
406
-			if ($compression == 'bz') $outputfile.='.bz2';
404
+			$compression = $compression ? $compression : 'none';
405
+			if ($compression == 'gz') $outputfile .= '.gz';
406
+			if ($compression == 'bz') $outputfile .= '.bz2';
407 407
 			$outputerror = $outputfile.'.err';
408 408
 			dol_mkdir($conf->admin->dir_output.'/backup');
409 409
 
@@ -425,51 +425,51 @@  discard block
 block discarded – undo
425 425
 		// POSTGRESQL
426 426
 		if ($type == 'postgresql' || $type == 'pgsql')
427 427
 		{
428
-			$cmddump=$conf->global->SYSTEMTOOLS_POSTGRESQLDUMP;
428
+			$cmddump = $conf->global->SYSTEMTOOLS_POSTGRESQLDUMP;
429 429
 
430 430
 			$outputfile = $outputdir.'/'.$file;
431 431
 			// for compression format, we add extension
432
-			$compression=$compression ? $compression : 'none';
433
-			if ($compression == 'gz') $outputfile.='.gz';
434
-			if ($compression == 'bz') $outputfile.='.bz2';
432
+			$compression = $compression ? $compression : 'none';
433
+			if ($compression == 'gz') $outputfile .= '.gz';
434
+			if ($compression == 'bz') $outputfile .= '.bz2';
435 435
 			$outputerror = $outputfile.'.err';
436 436
 			dol_mkdir($conf->admin->dir_output.'/backup');
437 437
 
438 438
 			// Parameteres execution
439
-			$command=$cmddump;
440
-			if (preg_match("/\s/",$command)) $command=escapeshellarg($command);	// Use quotes on command
439
+			$command = $cmddump;
440
+			if (preg_match("/\s/", $command)) $command = escapeshellarg($command); // Use quotes on command
441 441
 
442 442
 			//$param=escapeshellarg($dolibarr_main_db_name)." -h ".escapeshellarg($dolibarr_main_db_host)." -u ".escapeshellarg($dolibarr_main_db_user)." -p".escapeshellarg($dolibarr_main_db_pass);
443 443
 			//$param="-F c";
444
-			$param="-F p";
445
-			$param.=" --no-tablespaces --inserts -h ".$dolibarr_main_db_host;
446
-			$param.=" -U ".$dolibarr_main_db_user;
447
-			if (! empty($dolibarr_main_db_port)) $param.=" -p ".$dolibarr_main_db_port;
448
-			if (GETPOST("sql_compat") && GETPOST("sql_compat") == 'ANSI') $param.="  --disable-dollar-quoting";
449
-			if (GETPOST("drop_database"))        $param.=" -c -C";
444
+			$param = "-F p";
445
+			$param .= " --no-tablespaces --inserts -h ".$dolibarr_main_db_host;
446
+			$param .= " -U ".$dolibarr_main_db_user;
447
+			if (!empty($dolibarr_main_db_port)) $param .= " -p ".$dolibarr_main_db_port;
448
+			if (GETPOST("sql_compat") && GETPOST("sql_compat") == 'ANSI') $param .= "  --disable-dollar-quoting";
449
+			if (GETPOST("drop_database"))        $param .= " -c -C";
450 450
 			if (GETPOST("sql_structure"))
451 451
 			{
452
-				if (GETPOST("drop"))			 $param.=" --add-drop-table";
453
-				if (! GETPOST("sql_data"))       $param.=" -s";
452
+				if (GETPOST("drop"))			 $param .= " --add-drop-table";
453
+				if (!GETPOST("sql_data"))       $param .= " -s";
454 454
 			}
455 455
 			if (GETPOST("sql_data"))
456 456
 			{
457
-				if (! GETPOST("sql_structure"))	 $param.=" -a";
458
-				if (GETPOST("showcolumns"))	     $param.=" -c";
457
+				if (!GETPOST("sql_structure"))	 $param .= " -a";
458
+				if (GETPOST("showcolumns"))	     $param .= " -c";
459 459
 			}
460
-			$param.=' -f "'.$outputfile.'"';
460
+			$param .= ' -f "'.$outputfile.'"';
461 461
 			//if ($compression == 'none')
462
-			if ($compression == 'gz')   $param.=' -Z 9';
462
+			if ($compression == 'gz')   $param .= ' -Z 9';
463 463
 			//if ($compression == 'bz')
464
-			$paramcrypted=$param;
465
-			$paramclear=$param;
464
+			$paramcrypted = $param;
465
+			$paramclear = $param;
466 466
 			/*if (! empty($dolibarr_main_db_pass))
467 467
 			 {
468 468
 			 $paramcrypted.=" -W".preg_replace('/./i','*',$dolibarr_main_db_pass);
469 469
 			 $paramclear.=" -W".$dolibarr_main_db_pass;
470 470
 			 }*/
471
-			$paramcrypted.=" -w ".$dolibarr_main_db_name;
472
-			$paramclear.=" -w ".$dolibarr_main_db_name;
471
+			$paramcrypted .= " -w ".$dolibarr_main_db_name;
472
+			$paramclear .= " -w ".$dolibarr_main_db_name;
473 473
 
474 474
 			$this->output = "";
475 475
 			$this->result = array("commandbackuplastdone" => "", "commandbackuptorun" => $command." ".$paramcrypted);
@@ -479,8 +479,8 @@  discard block
 block discarded – undo
479 479
 		if ($keeplastnfiles > 0)
480 480
 		{
481 481
 			$tmpfiles = dol_dir_list($conf->admin->dir_output.'/backup', 'files', 0, '', '(\.err|\.old|\.sav)$', 'date', SORT_DESC);
482
-			$i=0;
483
-			foreach($tmpfiles as $key => $val)
482
+			$i = 0;
483
+			foreach ($tmpfiles as $key => $val)
484 484
 			{
485 485
 				$i++;
486 486
 				if ($i <= $keeplastnfiles) continue;
@@ -501,7 +501,7 @@  discard block
 block discarded – undo
501 501
 	 * @param	int		$execmethod		0=Use default method (that is 1 by default), 1=Use the PHP 'exec', 2=Use the 'popen' method
502 502
 	 * @return	array					array('result'=>...,'output'=>...,'error'=>...). result = 0 means OK.
503 503
 	 */
504
-	function executeCLI($command, $outputfile, $execmethod=0)
504
+	function executeCLI($command, $outputfile, $execmethod = 0)
505 505
 	{
506 506
 		global $conf, $langs;
507 507
 
@@ -509,15 +509,15 @@  discard block
 block discarded – undo
509 509
 		$output = '';
510 510
 		$error = '';
511 511
 
512
-		$command=escapeshellcmd($command);
513
-		$command.=" 2>&1";
512
+		$command = escapeshellcmd($command);
513
+		$command .= " 2>&1";
514 514
 
515
-		if (! empty($conf->global->MAIN_EXEC_USE_POPEN)) $execmethod=$conf->global->MAIN_EXEC_USE_POPEN;
516
-		if (empty($execmethod)) $execmethod=1;
515
+		if (!empty($conf->global->MAIN_EXEC_USE_POPEN)) $execmethod = $conf->global->MAIN_EXEC_USE_POPEN;
516
+		if (empty($execmethod)) $execmethod = 1;
517 517
 		//$execmethod=1;
518 518
 
519 519
 		dol_syslog("Utils::executeCLI execmethod=".$execmethod." system:".$command, LOG_DEBUG);
520
-		$output_arr=array();
520
+		$output_arr = array();
521 521
 
522 522
 		if ($execmethod == 1)
523 523
 		{
@@ -532,7 +532,7 @@  discard block
 block discarded – undo
532 532
 		}
533 533
 		if ($execmethod == 2)	// With this method, there is no way to get the return code, only output
534 534
 		{
535
-			$ok=0;
535
+			$ok = 0;
536 536
 			$handle = fopen($outputfile, 'w+b');
537 537
 			if ($handle)
538 538
 			{
@@ -541,21 +541,21 @@  discard block
 block discarded – undo
541 541
 				while (!feof($handlein))
542 542
 				{
543 543
 					$read = fgets($handlein);
544
-					fwrite($handle,$read);
545
-					$output_arr[]=$read;
544
+					fwrite($handle, $read);
545
+					$output_arr[] = $read;
546 546
 				}
547 547
 				pclose($handlein);
548 548
 				fclose($handle);
549 549
 			}
550
-			if (! empty($conf->global->MAIN_UMASK)) @chmod($outputfile, octdec($conf->global->MAIN_UMASK));
550
+			if (!empty($conf->global->MAIN_UMASK)) @chmod($outputfile, octdec($conf->global->MAIN_UMASK));
551 551
 		}
552 552
 
553 553
 		// Update with result
554
-		if (is_array($output_arr) && count($output_arr)>0)
554
+		if (is_array($output_arr) && count($output_arr) > 0)
555 555
 		{
556
-			foreach($output_arr as $val)
556
+			foreach ($output_arr as $val)
557 557
 			{
558
-				$output.=$val.($execmethod == 2 ? '' : "\n");
558
+				$output .= $val.($execmethod == 2 ? '' : "\n");
559 559
 			}
560 560
 		}
561 561
 
@@ -577,23 +577,23 @@  discard block
 block discarded – undo
577 577
 
578 578
 		$error = 0;
579 579
 
580
-		$modulelowercase=strtolower($module);
580
+		$modulelowercase = strtolower($module);
581 581
 
582 582
 		// Dir for module
583 583
 		$dir = $dirins.'/'.$modulelowercase;
584 584
 		// Zip file to build
585
-		$FILENAMEDOC='';
585
+		$FILENAMEDOC = '';
586 586
 
587 587
 		// Load module
588 588
 		dol_include_once($modulelowercase.'/core/modules/mod'.$module.'.class.php');
589
-		$class='mod'.$module;
589
+		$class = 'mod'.$module;
590 590
 
591 591
 		if (class_exists($class))
592 592
 		{
593 593
 			try {
594 594
 				$moduleobj = new $class($this->db);
595 595
 			}
596
-			catch(Exception $e)
596
+			catch (Exception $e)
597 597
 			{
598 598
 				$error++;
599 599
 				dol_print_error($e->getMessage());
@@ -607,41 +607,41 @@  discard block
 block discarded – undo
607 607
 			exit;
608 608
 		}
609 609
 
610
-		$arrayversion=explode('.',$moduleobj->version,3);
610
+		$arrayversion = explode('.', $moduleobj->version, 3);
611 611
 		if (count($arrayversion))
612 612
 		{
613
-			$FILENAMEASCII=strtolower($module).'.asciidoc';
614
-			$FILENAMEDOC=strtolower($module).'.html';			// TODO Use/text PDF
613
+			$FILENAMEASCII = strtolower($module).'.asciidoc';
614
+			$FILENAMEDOC = strtolower($module).'.html'; // TODO Use/text PDF
615 615
 
616 616
 			$dirofmodule = dol_buildpath(strtolower($module), 0).'/doc';
617 617
 			$dirofmoduletmp = dol_buildpath(strtolower($module), 0).'/doc/temp';
618 618
 			$outputfiledoc = $dirofmodule.'/'.$FILENAMEDOC;
619 619
 			if ($dirofmodule)
620 620
 			{
621
-				if (! dol_is_dir($dirofmodule)) dol_mkdir($dirofmodule);
622
-				if (! dol_is_dir($dirofmoduletmp)) dol_mkdir($dirofmoduletmp);
623
-				if (! is_writable($dirofmoduletmp))
621
+				if (!dol_is_dir($dirofmodule)) dol_mkdir($dirofmodule);
622
+				if (!dol_is_dir($dirofmoduletmp)) dol_mkdir($dirofmoduletmp);
623
+				if (!is_writable($dirofmoduletmp))
624 624
 				{
625 625
 					$this->error = 'Dir '.$dirofmoduletmp.' does not exists or is not writable';
626 626
 					return -1;
627 627
 				}
628 628
 
629
-				$destfile=$dirofmoduletmp.'/'.$FILENAMEASCII;
629
+				$destfile = $dirofmoduletmp.'/'.$FILENAMEASCII;
630 630
 
631 631
 				$fhandle = fopen($destfile, 'w+');
632 632
 				if ($fhandle)
633 633
 				{
634
-					$specs=dol_dir_list(dol_buildpath(strtolower($module).'/doc', 0), 'files', 1, '(\.md|\.asciidoc)$', array('\/temp\/'));
634
+					$specs = dol_dir_list(dol_buildpath(strtolower($module).'/doc', 0), 'files', 1, '(\.md|\.asciidoc)$', array('\/temp\/'));
635 635
 
636 636
 					$i = 0;
637 637
 					foreach ($specs as $spec)
638 638
 					{
639
-						if (preg_match('/notindoc/', $spec['relativename'])) continue;	// Discard file
640
-						if (preg_match('/disabled/', $spec['relativename'])) continue;	// Discard file
639
+						if (preg_match('/notindoc/', $spec['relativename'])) continue; // Discard file
640
+						if (preg_match('/disabled/', $spec['relativename'])) continue; // Discard file
641 641
 
642 642
 						$pathtofile = strtolower($module).'/doc/'.$spec['relativename'];
643
-						$format='asciidoc';
644
-						if (preg_match('/\.md$/i', $spec['name'])) $format='markdown';
643
+						$format = 'asciidoc';
644
+						if (preg_match('/\.md$/i', $spec['name'])) $format = 'markdown';
645 645
 
646 646
 						$filecursor = @file_get_contents($spec['fullname']);
647 647
 						if ($filecursor)
@@ -665,15 +665,15 @@  discard block
 block discarded – undo
665 665
 					fclose($fhandle);
666 666
 				}
667 667
 
668
-				$conf->global->MODULEBUILDER_ASCIIDOCTOR='asciidoctor';
668
+				$conf->global->MODULEBUILDER_ASCIIDOCTOR = 'asciidoctor';
669 669
 				if (empty($conf->global->MODULEBUILDER_ASCIIDOCTOR))
670 670
 				{
671 671
 					dol_print_error('', 'Module setup not complete');
672 672
 					exit;
673 673
 				}
674 674
 
675
-				$command=$conf->global->MODULEBUILDER_ASCIIDOCTOR.' '.$destfile.' -n -o '.$dirofmodule.'/'.$FILENAMEDOC;
676
-				$outfile=$dirofmoduletmp.'/out.tmp';
675
+				$command = $conf->global->MODULEBUILDER_ASCIIDOCTOR.' '.$destfile.' -n -o '.$dirofmodule.'/'.$FILENAMEDOC;
676
+				$outfile = $dirofmoduletmp.'/out.tmp';
677 677
 
678 678
 				require_once DOL_DOCUMENT_ROOT.'/core/class/utils.class.php';
679 679
 				$utils = new Utils($db);
@@ -721,18 +721,18 @@  discard block
 block discarded – undo
721 721
     {
722 722
 		global $conf;
723 723
 
724
-		if(empty($conf->loghandlers['mod_syslog_file'])) { // File Syslog disabled
724
+		if (empty($conf->loghandlers['mod_syslog_file'])) { // File Syslog disabled
725 725
 			return 0;
726 726
 		}
727 727
 
728
-		if(! function_exists('gzopen')) {
728
+		if (!function_exists('gzopen')) {
729 729
 			$this->error = 'Support for gzopen not available in this PHP';
730 730
 			return -1;
731 731
 		}
732 732
 
733 733
 		dol_include_once('/core/lib/files.lib.php');
734 734
 
735
-		$nbSaves = ! empty($conf->global->SYSLOG_FILE_SAVES) ? intval($conf->global->SYSLOG_FILE_SAVES) : 14;
735
+		$nbSaves = !empty($conf->global->SYSLOG_FILE_SAVES) ? intval($conf->global->SYSLOG_FILE_SAVES) : 14;
736 736
 
737 737
 		if (empty($conf->global->SYSLOG_FILE)) {
738 738
 			$mainlogdir = DOL_DATA_ROOT;
@@ -746,7 +746,7 @@  discard block
 block discarded – undo
746 746
 		$tabfiles = dol_dir_list(DOL_DATA_ROOT, 'files', 0, '^(dolibarr_.+|odt2pdf)\.log$'); // Also handle other log files like dolibarr_install.log
747 747
 		$tabfiles[] = array('name' => $mainlog, 'path' => $mainlogdir);
748 748
 
749
-		foreach($tabfiles as $file) {
749
+		foreach ($tabfiles as $file) {
750 750
 
751 751
 			$logname = $file['name'];
752 752
 			$logpath = $file['path'];
@@ -760,7 +760,7 @@  discard block
 block discarded – undo
760 760
 				$gzfilestmp = dol_dir_list($logpath, 'files', 0, $filter);
761 761
 				$gzfiles = array();
762 762
 
763
-				foreach($gzfilestmp as $gzfile) {
763
+				foreach ($gzfilestmp as $gzfile) {
764 764
 					$tabmatches = array();
765 765
 					preg_match('/'.$filter.'/i', $gzfile['name'], $tabmatches);
766 766
 
@@ -771,15 +771,15 @@  discard block
 block discarded – undo
771 771
 
772 772
 				krsort($gzfiles, SORT_NUMERIC);
773 773
 
774
-				foreach($gzfiles as $numsave => $dummy) {
775
-					if (dol_is_file($logpath.'/'.$logname.'.'.($numsave+1).'.gz')) {
774
+				foreach ($gzfiles as $numsave => $dummy) {
775
+					if (dol_is_file($logpath.'/'.$logname.'.'.($numsave + 1).'.gz')) {
776 776
 						return -2;
777 777
 					}
778 778
 
779
-					if($numsave >= $nbSaves) {
779
+					if ($numsave >= $nbSaves) {
780 780
 						dol_delete_file($logpath.'/'.$logname.'.'.$numsave.'.gz', 0, 0, 0, null, false, 0);
781 781
 					} else {
782
-						dol_move($logpath.'/'.$logname.'.'.$numsave.'.gz', $logpath.'/'.$logname.'.'.($numsave+1).'.gz', 0, 1, 0, 0);
782
+						dol_move($logpath.'/'.$logname.'.'.$numsave.'.gz', $logpath.'/'.$logname.'.'.($numsave + 1).'.gz', 0, 1, 0, 0);
783 783
 					}
784 784
 				}
785 785
 
@@ -800,14 +800,14 @@  discard block
 block discarded – undo
800 800
 						return -4;
801 801
 					}
802 802
 
803
-					while(! feof($sourcehandle)) {
803
+					while (!feof($sourcehandle)) {
804 804
 						gzwrite($gzfilehandle, fread($sourcehandle, 512 * 1024)); // Read 512 kB at a time
805 805
 					}
806 806
 
807 807
 					fclose($sourcehandle);
808 808
 					gzclose($gzfilehandle);
809 809
 
810
-					@chmod($logpath.'/'.$logname.'.1.gz', octdec(empty($conf->global->MAIN_UMASK)?'0664':$conf->global->MAIN_UMASK));
810
+					@chmod($logpath.'/'.$logname.'.1.gz', octdec(empty($conf->global->MAIN_UMASK) ? '0664' : $conf->global->MAIN_UMASK));
811 811
 				}
812 812
 
813 813
 				dol_delete_file($logpath.'/'.$logname, 0, 0, 0, null, false, 0);
@@ -817,7 +817,7 @@  discard block
 block discarded – undo
817 817
 				fclose($newlog);
818 818
 
819 819
 				//var_dump($logpath.'/'.$logname." - ".octdec(empty($conf->global->MAIN_UMASK)?'0664':$conf->global->MAIN_UMASK));
820
-				@chmod($logpath.'/'.$logname, octdec(empty($conf->global->MAIN_UMASK)?'0664':$conf->global->MAIN_UMASK));
820
+				@chmod($logpath.'/'.$logname, octdec(empty($conf->global->MAIN_UMASK) ? '0664' : $conf->global->MAIN_UMASK));
821 821
 			}
822 822
 		}
823 823
 
@@ -835,7 +835,7 @@  discard block
 block discarded – undo
835 835
 	 *	@param	string	$tables			Table name or '*' for all
836 836
 	 *	@return	int						<0 if KO, >0 if OK
837 837
 	 */
838
-	function backupTables($outputfile, $tables='*')
838
+	function backupTables($outputfile, $tables = '*')
839 839
 	{
840 840
 		global $db, $langs;
841 841
 		global $errormsg;
@@ -855,14 +855,14 @@  discard block
 block discarded – undo
855 855
 		{
856 856
 			$tables = array();
857 857
 			$result = $db->query('SHOW FULL TABLES WHERE Table_type = \'BASE TABLE\'');
858
-			while($row = $db->fetch_row($result))
858
+			while ($row = $db->fetch_row($result))
859 859
 			{
860 860
 				$tables[] = $row[0];
861 861
 			}
862 862
 		}
863 863
 		else
864 864
 		{
865
-			$tables = is_array($tables) ? $tables : explode(',',$tables);
865
+			$tables = is_array($tables) ? $tables : explode(',', $tables);
866 866
 		}
867 867
 
868 868
 		//cycle through
@@ -870,8 +870,8 @@  discard block
 block discarded – undo
870 870
 		if (fwrite($handle, '') === false)
871 871
 		{
872 872
 			$langs->load("errors");
873
-			dol_syslog("Failed to open file ".$outputfile,LOG_ERR);
874
-			$errormsg=$langs->trans("ErrorFailedToWriteInDir");
873
+			dol_syslog("Failed to open file ".$outputfile, LOG_ERR);
874
+			$errormsg = $langs->trans("ErrorFailedToWriteInDir");
875 875
 			return -1;
876 876
 		}
877 877
 
@@ -908,15 +908,15 @@  discard block
 block discarded – undo
908 908
 		if (GETPOST("nobin_delayed")) $delayed = 'DELAYED ';
909 909
 
910 910
 		// Process each table and print their definition + their datas
911
-		foreach($tables as $table)
911
+		foreach ($tables as $table)
912 912
 		{
913 913
 			// Saving the table structure
914 914
 			fwrite($handle, "\n--\n-- Table structure for table `".$table."`\n--\n");
915 915
 
916
-			if (GETPOST("nobin_drop")) fwrite($handle,"DROP TABLE IF EXISTS `".$table."`;\n"); // Dropping table if exists prior to re create it
917
-			fwrite($handle,"/*!40101 SET @saved_cs_client     = @@character_set_client */;\n");
918
-			fwrite($handle,"/*!40101 SET character_set_client = utf8 */;\n");
919
-			$resqldrop=$db->query('SHOW CREATE TABLE '.$table);
916
+			if (GETPOST("nobin_drop")) fwrite($handle, "DROP TABLE IF EXISTS `".$table."`;\n"); // Dropping table if exists prior to re create it
917
+			fwrite($handle, "/*!40101 SET @saved_cs_client     = @@character_set_client */;\n");
918
+			fwrite($handle, "/*!40101 SET character_set_client = utf8 */;\n");
919
+			$resqldrop = $db->query('SHOW CREATE TABLE '.$table);
920 920
 			$row2 = $db->fetch_row($resqldrop);
921 921
 			if (empty($row2[1]))
922 922
 			{
@@ -924,7 +924,7 @@  discard block
 block discarded – undo
924 924
 			}
925 925
 			else
926 926
 			{
927
-				fwrite($handle,$row2[1].";\n");
927
+				fwrite($handle, $row2[1].";\n");
928 928
 				//fwrite($handle,"/*!40101 SET character_set_client = @saved_cs_client */;\n\n");
929 929
 
930 930
 				// Dumping the data (locking the table and disabling the keys check while doing the process)
@@ -933,22 +933,22 @@  discard block
 block discarded – undo
933 933
 				if (GETPOST("nobin_disable_fk")) fwrite($handle, "ALTER TABLE `".$table."` DISABLE KEYS;\n");
934 934
 				else fwrite($handle, "/*!40000 ALTER TABLE `".$table."` DISABLE KEYS */;\n");
935 935
 
936
-				$sql='SELECT * FROM '.$table;
936
+				$sql = 'SELECT * FROM '.$table;
937 937
 				$result = $db->query($sql);
938
-				while($row = $db->fetch_row($result))
938
+				while ($row = $db->fetch_row($result))
939 939
 				{
940 940
 					// For each row of data we print a line of INSERT
941
-					fwrite($handle,'INSERT '.$delayed.$ignore.'INTO `'.$table.'` VALUES (');
941
+					fwrite($handle, 'INSERT '.$delayed.$ignore.'INTO `'.$table.'` VALUES (');
942 942
 					$columns = count($row);
943
-					for($j=0; $j<$columns; $j++) {
943
+					for ($j = 0; $j < $columns; $j++) {
944 944
 						// Processing each columns of the row to ensure that we correctly save the value (eg: add quotes for string - in fact we add quotes for everything, it's easier)
945 945
 						if ($row[$j] == null && !is_string($row[$j])) {
946 946
 							// IMPORTANT: if the field is NULL we set it NULL
947 947
 							$row[$j] = 'NULL';
948
-						} elseif(is_string($row[$j]) && $row[$j] == '') {
948
+						} elseif (is_string($row[$j]) && $row[$j] == '') {
949 949
 							// if it's an empty string, we set it as an empty string
950 950
 							$row[$j] = "''";
951
-						} elseif(is_numeric($row[$j]) && !strcmp($row[$j], $row[$j]+0) ) { // test if it's a numeric type and the numeric version ($nb+0) == string version (eg: if we have 01, it's probably not a number but rather a string, else it would not have any leading 0)
951
+						} elseif (is_numeric($row[$j]) && !strcmp($row[$j], $row[$j] + 0)) { // test if it's a numeric type and the numeric version ($nb+0) == string version (eg: if we have 01, it's probably not a number but rather a string, else it would not have any leading 0)
952 952
 							// if it's a number, we return it as-is
953 953
 							//	                    $row[$j] = $row[$j];
954 954
 						} else { // else for all other cases we escape the value and put quotes around
@@ -957,11 +957,11 @@  discard block
 block discarded – undo
957 957
 							$row[$j] = "'".$row[$j]."'";
958 958
 						}
959 959
 					}
960
-					fwrite($handle,implode(',', $row).");\n");
960
+					fwrite($handle, implode(',', $row).");\n");
961 961
 				}
962 962
 				if (GETPOST("nobin_disable_fk")) fwrite($handle, "ALTER TABLE `".$table."` ENABLE KEYS;\n"); // Enabling back the keys/index checking
963 963
 				if (!GETPOST("nobin_nolocks")) fwrite($handle, "UNLOCK TABLES;\n"); // Unlocking the table
964
-				fwrite($handle,"\n\n\n");
964
+				fwrite($handle, "\n\n\n");
965 965
 			}
966 966
 		}
967 967
 
@@ -985,10 +985,10 @@  discard block
 block discarded – undo
985 985
 		/* Backup Procedure structure*/
986 986
 
987 987
 		// Write the footer (restore the previous database settings)
988
-		$sqlfooter="\n\n";
988
+		$sqlfooter = "\n\n";
989 989
 		if (GETPOST("nobin_use_transaction")) $sqlfooter .= "COMMIT;\n";
990 990
 		if (GETPOST("nobin_disable_fk")) $sqlfooter .= "SET FOREIGN_KEY_CHECKS=1;\n";
991
-		$sqlfooter.="\n\n-- Dump completed on ".date('Y-m-d G-i-s');
991
+		$sqlfooter .= "\n\n-- Dump completed on ".date('Y-m-d G-i-s');
992 992
 		fwrite($handle, $sqlfooter);
993 993
 
994 994
 		fclose($handle);
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/html.formcontract.class.php 1 patch
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
     /**
36 36
 	 * @var string Error code (or message)
37 37
 	 */
38
-	public $error='';
38
+	public $error = '';
39 39
 
40 40
 
41 41
     /**
@@ -60,35 +60,35 @@  discard block
 block discarded – undo
60 60
 	 *	@param	int		$showempty	Show empty line
61 61
 	 *	@return int         		Nbr of project if OK, <0 if KO
62 62
 	 */
63
-	function select_contract($socid=-1, $selected='', $htmlname='contrattid', $maxlength=16, $showempty=1)
63
+	function select_contract($socid = -1, $selected = '', $htmlname = 'contrattid', $maxlength = 16, $showempty = 1)
64 64
 	{
65 65
         // phpcs:enable
66
-		global $db,$user,$conf,$langs;
66
+		global $db, $user, $conf, $langs;
67 67
 
68 68
 		$hideunselectables = false;
69
-		if (! empty($conf->global->CONTRACT_HIDE_UNSELECTABLES)) $hideunselectables = true;
69
+		if (!empty($conf->global->CONTRACT_HIDE_UNSELECTABLES)) $hideunselectables = true;
70 70
 
71 71
 		// Search all contacts
72 72
 		$sql = 'SELECT c.rowid, c.ref, c.fk_soc, c.statut';
73
-		$sql.= ' FROM '.MAIN_DB_PREFIX .'contrat as c';
74
-		$sql.= " WHERE c.entity = ".$conf->entity;
73
+		$sql .= ' FROM '.MAIN_DB_PREFIX.'contrat as c';
74
+		$sql .= " WHERE c.entity = ".$conf->entity;
75 75
 		//if ($contratListId) $sql.= " AND c.rowid IN (".$contratListId.")";
76 76
 		if ($socid > 0)
77 77
 		{
78 78
 			// CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY is 'all' or a list of ids separated by coma.
79 79
 		    	if (empty($conf->global->CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY))
80
-			    $sql.= " AND (c.fk_soc=".$socid." OR c.fk_soc IS NULL)";
80
+			    $sql .= " AND (c.fk_soc=".$socid." OR c.fk_soc IS NULL)";
81 81
 		    	else if ($conf->global->CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY != 'all')
82 82
 			{
83
-		        	$sql.= " AND (c.fk_soc IN (".$socid.", ".$conf->global->CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY.") ";
84
-				$sql.= " OR c.fk_soc IS NULL)";
83
+		        	$sql .= " AND (c.fk_soc IN (".$socid.", ".$conf->global->CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY.") ";
84
+				$sql .= " OR c.fk_soc IS NULL)";
85 85
 		    	}
86 86
 		}
87
-		if ($socid == 0) $sql.= " AND (c.fk_soc = 0 OR c.fk_soc IS NULL)";
88
-		$sql.= " ORDER BY c.ref ";
87
+		if ($socid == 0) $sql .= " AND (c.fk_soc = 0 OR c.fk_soc IS NULL)";
88
+		$sql .= " ORDER BY c.ref ";
89 89
 
90 90
 		dol_syslog(get_class($this)."::select_contract", LOG_DEBUG);
91
-		$resql=$db->query($sql);
91
+		$resql = $db->query($sql);
92 92
 		if ($resql)
93 93
 		{
94 94
 			print '<select class="flat" name="'.$htmlname.'">';
@@ -101,13 +101,13 @@  discard block
 block discarded – undo
101 101
 				{
102 102
 					$obj = $db->fetch_object($resql);
103 103
 					// If we ask to filter on a company and user has no permission to see all companies and project is linked to another company, we hide project.
104
-					if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && ! $user->rights->societe->lire)
104
+					if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$user->rights->societe->lire)
105 105
 					{
106 106
 						// Do nothing
107 107
 					}
108 108
 					else
109 109
 					{
110
-						$labeltoshow=dol_trunc($obj->ref,18);
110
+						$labeltoshow = dol_trunc($obj->ref, 18);
111 111
 						//if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')';
112 112
 						//else $labeltoshow.=' ('.$langs->trans("Private").')';
113 113
 						if (!empty($selected) && $selected == $obj->rowid && $obj->statut > 0)
@@ -116,30 +116,30 @@  discard block
 block discarded – undo
116 116
 						}
117 117
 						else
118 118
 						{
119
-							$disabled=0;
120
-							if ( $obj->statut ==  0)
119
+							$disabled = 0;
120
+							if ($obj->statut == 0)
121 121
 							{
122
-								$disabled=1;
123
-								$labeltoshow.=' ('.$langs->trans("Draft").')';
122
+								$disabled = 1;
123
+								$labeltoshow .= ' ('.$langs->trans("Draft").')';
124 124
 							}
125
-							if ( empty($conf->global->CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY) &&  $socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid))
125
+							if (empty($conf->global->CONTRACT_ALLOW_TO_LINK_FROM_OTHER_COMPANY) && $socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid))
126 126
 							{
127
-								$disabled=1;
128
-								$labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany");
127
+								$disabled = 1;
128
+								$labeltoshow .= ' - '.$langs->trans("LinkedToAnotherCompany");
129 129
 							}
130 130
 
131 131
 							if ($hideunselectables && $disabled)
132 132
 							{
133
-								$resultat='';
133
+								$resultat = '';
134 134
 							}
135 135
 							else
136 136
 							{
137
-								$resultat='<option value="'.$obj->rowid.'"';
138
-								if ($disabled) $resultat.=' disabled';
137
+								$resultat = '<option value="'.$obj->rowid.'"';
138
+								if ($disabled) $resultat .= ' disabled';
139 139
 								//if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
140 140
 								//else $labeltoshow.=' ('.$langs->trans("Private").')';
141
-								$resultat.='>'.$labeltoshow;
142
-								$resultat.='</option>';
141
+								$resultat .= '>'.$labeltoshow;
142
+								$resultat .= '</option>';
143 143
 							}
144 144
 							print $resultat;
145 145
 						}
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 			if (!empty($conf->use_javascript_ajax))
154 154
 			{
155 155
 				// Make select dynamic
156
-				include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
156
+				include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
157 157
 				print ajax_combobox($htmlname);
158 158
 			}
159 159
 
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
 	 *	@param	int		$showempty	Show empty line
178 178
 	 *	@return int                 Nbr of project if OK, <0 if KO
179 179
 	 */
180
-	function formSelectContract($page, $socid=-1, $selected='', $htmlname='contrattid', $maxlength=16, $showempty=1)
180
+	function formSelectContract($page, $socid = -1, $selected = '', $htmlname = 'contrattid', $maxlength = 16, $showempty = 1)
181 181
 	{
182 182
         global $langs;
183 183
 
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/html.formmargin.class.php 1 patch
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
     /**
37 37
 	 * @var string Error code (or message)
38 38
 	 */
39
-	public $error='';
39
+	public $error = '';
40 40
 
41 41
 
42 42
     /**
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 	 * 	@param 	boolean			$force_price	True of not
60 60
 	 * 	@return array							Array with info
61 61
 	 */
62
-	function getMarginInfosArray($object, $force_price=false)
62
+	function getMarginInfosArray($object, $force_price = false)
63 63
 	{
64 64
 		global $conf, $db;
65 65
 
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 				'total_mark_rate' => ''
83 83
 		);
84 84
 
85
-		foreach($object->lines as $line)
85
+		foreach ($object->lines as $line)
86 86
 		{
87 87
 			if (empty($line->pa_ht) && isset($line->fk_fournprice) && !$force_price)
88 88
 			{
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 			}
98 98
 
99 99
 			$pv = $line->qty * $line->subprice * (1 - $line->remise_percent / 100);
100
-			$pa_ht = ($pv < 0 ? - $line->pa_ht : $line->pa_ht);      // We choosed to have line->pa_ht always positive in database, so we guess the correct sign
100
+			$pa_ht = ($pv < 0 ? -$line->pa_ht : $line->pa_ht); // We choosed to have line->pa_ht always positive in database, so we guess the correct sign
101 101
 			$pa = $line->qty * $pa_ht;
102 102
 
103 103
 			// calcul des marges
@@ -105,8 +105,8 @@  discard block
 block discarded – undo
105 105
 				if ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '1') { // remise globale considérée comme produit
106 106
 					$marginInfos['pa_products'] += $pa;
107 107
 					$marginInfos['pv_products'] += $pv;
108
-					$marginInfos['pa_total'] +=  $pa;
109
-					$marginInfos['pv_total'] +=  $pv;
108
+					$marginInfos['pa_total'] += $pa;
109
+					$marginInfos['pv_total'] += $pv;
110 110
 					// if credit note, margin = -1 * (abs(selling_price) - buying_price)
111 111
 					//if ($pv < 0)
112 112
 					//{
@@ -118,8 +118,8 @@  discard block
 block discarded – undo
118 118
 				elseif ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '2') { // remise globale considérée comme service
119 119
 					$marginInfos['pa_services'] += $pa;
120 120
 					$marginInfos['pv_services'] += $pv;
121
-					$marginInfos['pa_total'] +=  $pa;
122
-					$marginInfos['pv_total'] +=  $pv;
121
+					$marginInfos['pa_total'] += $pa;
122
+					$marginInfos['pv_total'] += $pv;
123 123
 					// if credit note, margin = -1 * (abs(selling_price) - buying_price)
124 124
 					//if ($pv < 0)
125 125
 					//	$marginInfos['margin_on_services'] += -1 * (abs($pv) - $pa);
@@ -132,12 +132,12 @@  discard block
 block discarded – undo
132 132
 				}
133 133
 			}
134 134
 			else {
135
-				$type=$line->product_type?$line->product_type:$line->fk_product_type;
135
+				$type = $line->product_type ? $line->product_type : $line->fk_product_type;
136 136
 				if ($type == 0) {  // product
137 137
 					$marginInfos['pa_products'] += $pa;
138 138
 					$marginInfos['pv_products'] += $pv;
139
-					$marginInfos['pa_total'] +=  $pa;
140
-					$marginInfos['pv_total'] +=  $pv;
139
+					$marginInfos['pa_total'] += $pa;
140
+					$marginInfos['pv_total'] += $pv;
141 141
 					// if credit note, margin = -1 * (abs(selling_price) - buying_price)
142 142
 					//if ($pv < 0)
143 143
 					//{
@@ -151,8 +151,8 @@  discard block
 block discarded – undo
151 151
 				elseif ($type == 1) {  // service
152 152
 					$marginInfos['pa_services'] += $pa;
153 153
 					$marginInfos['pv_services'] += $pv;
154
-					$marginInfos['pa_total'] +=  $pa;
155
-					$marginInfos['pv_total'] +=  $pv;
154
+					$marginInfos['pa_total'] += $pa;
155
+					$marginInfos['pv_total'] += $pv;
156 156
 					// if credit note, margin = -1 * (abs(selling_price) - buying_price)
157 157
 					//if ($pv < 0)
158 158
 					//	$marginInfos['margin_on_services'] += -1 * (abs($pv) - $pa);
@@ -191,24 +191,24 @@  discard block
 block discarded – undo
191 191
 	 * 	@param 	boolean			$force_price	Force price
192 192
 	 * 	@return	void
193 193
 	 */
194
-	function displayMarginInfos($object, $force_price=false)
194
+	function displayMarginInfos($object, $force_price = false)
195 195
 	{
196 196
 		global $langs, $conf, $user;
197 197
 
198
-    	if (! empty($user->societe_id)) return;
198
+    	if (!empty($user->societe_id)) return;
199 199
 
200
-    	if (! $user->rights->margins->liretous) return;
200
+    	if (!$user->rights->margins->liretous) return;
201 201
 
202 202
         $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT, $conf->global->MAIN_MAX_DECIMALS_TOT);
203 203
 
204 204
 		$marginInfo = $this->getMarginInfosArray($object, $force_price);
205 205
 
206
-		if (! empty($conf->global->MARGIN_ADD_SHOWHIDE_BUTTON))	// TODO Warning this feature rely on an external js file that may be removed. Using native js function document.cookie should be better
206
+		if (!empty($conf->global->MARGIN_ADD_SHOWHIDE_BUTTON))	// TODO Warning this feature rely on an external js file that may be removed. Using native js function document.cookie should be better
207 207
 		{
208 208
 			print $langs->trans('ShowMarginInfos').' : ';
209 209
 	        $hidemargininfos = $_COOKIE['DOLUSER_MARGININFO_HIDE_SHOW'];
210
-	    	print '<span id="showMarginInfos" class="linkobject '.(!empty($hidemargininfos)?'':'hideobject').'">'.img_picto($langs->trans("Disabled"),'switch_off').'</span>';
211
-	    	print '<span id="hideMarginInfos" class="linkobject '.(!empty($hidemargininfos)?'hideobject':'').'">'.img_picto($langs->trans("Enabled"),'switch_on').'</span>';
210
+	    	print '<span id="showMarginInfos" class="linkobject '.(!empty($hidemargininfos) ? '' : 'hideobject').'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</span>';
211
+	    	print '<span id="hideMarginInfos" class="linkobject '.(!empty($hidemargininfos) ? 'hideobject' : '').'">'.img_picto($langs->trans("Enabled"), 'switch_on').'</span>';
212 212
 
213 213
     	    print '<script>$(document).ready(function() {
214 214
         	    $("span#showMarginInfos").click(function() { $.getScript( "'.dol_buildpath('/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js', 1).'", function( data, textStatus, jqxhr ) { $.cookie("DOLUSER_MARGININFO_HIDE_SHOW", 0); $(".margininfos").show(); $("span#showMarginInfos").addClass("hideobject"); $("span#hideMarginInfos").removeClass("hideobject");})});
@@ -229,13 +229,13 @@  discard block
 block discarded – undo
229 229
 		else
230 230
 			print '<td class="liste_titre" align="right">'.$langs->trans('CostPrice').'</td>';
231 231
 		print '<td class="liste_titre" align="right">'.$langs->trans('Margin').'</td>';
232
-		if (! empty($conf->global->DISPLAY_MARGIN_RATES))
232
+		if (!empty($conf->global->DISPLAY_MARGIN_RATES))
233 233
 			print '<td class="liste_titre" align="right">'.$langs->trans('MarginRate').'</td>';
234
-		if (! empty($conf->global->DISPLAY_MARK_RATES))
234
+		if (!empty($conf->global->DISPLAY_MARK_RATES))
235 235
 			print '<td class="liste_titre" align="right">'.$langs->trans('MarkRate').'</td>';
236 236
 		print '</tr>';
237 237
 
238
-		if (! empty($conf->product->enabled))
238
+		if (!empty($conf->product->enabled))
239 239
 		{
240 240
 			//if ($marginInfo['margin_on_products'] != 0 && $marginInfo['margin_on_services'] != 0) {
241 241
 			print '<tr class="oddeven">';
@@ -243,38 +243,38 @@  discard block
 block discarded – undo
243 243
 			print '<td align="right">'.price($marginInfo['pv_products'], null, null, null, null, $rounding).'</td>';
244 244
 			print '<td align="right">'.price($marginInfo['pa_products'], null, null, null, null, $rounding).'</td>';
245 245
 			print '<td align="right">'.price($marginInfo['margin_on_products'], null, null, null, null, $rounding).'</td>';
246
-			if (! empty($conf->global->DISPLAY_MARGIN_RATES))
247
-				print '<td align="right">'.(($marginInfo['margin_rate_products'] == '')?'':price($marginInfo['margin_rate_products'], null, null, null, null, $rounding).'%').'</td>';
248
-			if (! empty($conf->global->DISPLAY_MARK_RATES))
249
-				print '<td align="right">'.(($marginInfo['mark_rate_products'] == '')?'':price($marginInfo['mark_rate_products'], null, null, null, null, $rounding).'%').'</td>';
246
+			if (!empty($conf->global->DISPLAY_MARGIN_RATES))
247
+				print '<td align="right">'.(($marginInfo['margin_rate_products'] == '') ? '' : price($marginInfo['margin_rate_products'], null, null, null, null, $rounding).'%').'</td>';
248
+			if (!empty($conf->global->DISPLAY_MARK_RATES))
249
+				print '<td align="right">'.(($marginInfo['mark_rate_products'] == '') ? '' : price($marginInfo['mark_rate_products'], null, null, null, null, $rounding).'%').'</td>';
250 250
 			print '</tr>';
251 251
 		}
252 252
 
253
-		if (! empty($conf->service->enabled))
253
+		if (!empty($conf->service->enabled))
254 254
 		{
255 255
 			print '<tr class="oddeven">';
256 256
 			print '<td>'.$langs->trans('MarginOnServices').'</td>';
257 257
 			print '<td align="right">'.price($marginInfo['pv_services'], null, null, null, null, $rounding).'</td>';
258 258
 			print '<td align="right">'.price($marginInfo['pa_services'], null, null, null, null, $rounding).'</td>';
259 259
 			print '<td align="right">'.price($marginInfo['margin_on_services'], null, null, null, null, $rounding).'</td>';
260
-			if (! empty($conf->global->DISPLAY_MARGIN_RATES))
261
-				print '<td align="right">'.(($marginInfo['margin_rate_services'] == '')?'':price($marginInfo['margin_rate_services'], null, null, null, null, $rounding).'%').'</td>';
262
-			if (! empty($conf->global->DISPLAY_MARK_RATES))
263
-				print '<td align="right">'.(($marginInfo['mark_rate_services'] == '')?'':price($marginInfo['mark_rate_services'], null, null, null, null, $rounding).'%').'</td>';
260
+			if (!empty($conf->global->DISPLAY_MARGIN_RATES))
261
+				print '<td align="right">'.(($marginInfo['margin_rate_services'] == '') ? '' : price($marginInfo['margin_rate_services'], null, null, null, null, $rounding).'%').'</td>';
262
+			if (!empty($conf->global->DISPLAY_MARK_RATES))
263
+				print '<td align="right">'.(($marginInfo['mark_rate_services'] == '') ? '' : price($marginInfo['mark_rate_services'], null, null, null, null, $rounding).'%').'</td>';
264 264
 			print '</tr>';
265 265
 		}
266 266
 
267
-		if (! empty($conf->product->enabled) && ! empty($conf->service->enabled))
267
+		if (!empty($conf->product->enabled) && !empty($conf->service->enabled))
268 268
 		{
269 269
 			print '<tr class="liste_total">';
270 270
 			print '<td>'.$langs->trans('TotalMargin').'</td>';
271 271
 			print '<td align="right">'.price($marginInfo['pv_total'], null, null, null, null, $rounding).'</td>';
272 272
 			print '<td align="right">'.price($marginInfo['pa_total'], null, null, null, null, $rounding).'</td>';
273 273
 			print '<td align="right">'.price($marginInfo['total_margin'], null, null, null, null, $rounding).'</td>';
274
-			if (! empty($conf->global->DISPLAY_MARGIN_RATES))
275
-				print '<td align="right">'.(($marginInfo['total_margin_rate'] == '')?'':price($marginInfo['total_margin_rate'], null, null, null, null, $rounding).'%').'</td>';
276
-			if (! empty($conf->global->DISPLAY_MARK_RATES))
277
-				print '<td align="right">'.(($marginInfo['total_mark_rate'] == '')?'':price($marginInfo['total_mark_rate'], null, null, null, null, $rounding).'%').'</td>';
274
+			if (!empty($conf->global->DISPLAY_MARGIN_RATES))
275
+				print '<td align="right">'.(($marginInfo['total_margin_rate'] == '') ? '' : price($marginInfo['total_margin_rate'], null, null, null, null, $rounding).'%').'</td>';
276
+			if (!empty($conf->global->DISPLAY_MARK_RATES))
277
+				print '<td align="right">'.(($marginInfo['total_mark_rate'] == '') ? '' : price($marginInfo['total_mark_rate'], null, null, null, null, $rounding).'%').'</td>';
278 278
 			print '</tr>';
279 279
 		}
280 280
 		print '</table>';
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/html.formpropal.class.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 	/**
36 36
 	 * @var string Error code (or message)
37 37
 	 */
38
-	public $error='';
38
+	public $error = '';
39 39
 
40 40
 
41 41
 	/**
@@ -60,18 +60,18 @@  discard block
 block discarded – undo
60 60
      *    @param    string  $htmlname       Name of select field
61 61
      *    @return	void
62 62
      */
63
-    function selectProposalStatus($selected='',$short=0, $excludedraft=0, $showempty=1, $mode='customer',$htmlname='propal_statut')
63
+    function selectProposalStatus($selected = '', $short = 0, $excludedraft = 0, $showempty = 1, $mode = 'customer', $htmlname = 'propal_statut')
64 64
     {
65 65
         global $langs;
66 66
 
67
-        $prefix='';
68
-        $listofstatus=array();
67
+        $prefix = '';
68
+        $listofstatus = array();
69 69
         if ($mode == 'supplier')
70 70
         {
71
-            $prefix='SupplierProposalStatus';
71
+            $prefix = 'SupplierProposalStatus';
72 72
 
73 73
             $langs->load("supplier_proposal");
74
-            $listofstatus=array(
74
+            $listofstatus = array(
75 75
                 0=>array('id'=>0, 'code'=>'PR_DRAFT'),
76 76
                 1=>array('id'=>1, 'code'=>'PR_OPEN'),
77 77
                 2=>array('id'=>2, 'code'=>'PR_SIGNED'),
@@ -81,12 +81,12 @@  discard block
 block discarded – undo
81 81
         }
82 82
         else
83 83
         {
84
-            $prefix="PropalStatus";
84
+            $prefix = "PropalStatus";
85 85
 
86 86
             $sql = "SELECT id, code, label, active FROM ".MAIN_DB_PREFIX."c_propalst";
87 87
             $sql .= " WHERE active = 1";
88 88
             dol_syslog(get_class($this)."::selectProposalStatus", LOG_DEBUG);
89
-            $resql=$this->db->query($sql);
89
+            $resql = $this->db->query($sql);
90 90
             if ($resql)
91 91
             {
92 92
                 $num = $this->db->num_rows($resql);
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
                     while ($i < $num)
97 97
                     {
98 98
                         $obj = $this->db->fetch_object($resql);
99
-                        $listofstatus[$obj->id]=array('id'=>$obj->id,'code'=>$obj->code,'label'=>$obj->label);
99
+                        $listofstatus[$obj->id] = array('id'=>$obj->id, 'code'=>$obj->code, 'label'=>$obj->label);
100 100
                         $i++;
101 101
                     }
102 102
                 }
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
         print '<select class="flat" name="'.$htmlname.'">';
111 111
         if ($showempty) print '<option value="-1">&nbsp;</option>';
112 112
 
113
-        foreach($listofstatus as $key => $obj)
113
+        foreach ($listofstatus as $key => $obj)
114 114
         {
115 115
             if ($excludedraft)
116 116
             {
@@ -128,17 +128,17 @@  discard block
 block discarded – undo
128 128
             {
129 129
                 print '<option value="'.$obj['id'].'">';
130 130
             }
131
-            $key=$obj['code'];
132
-            if ($langs->trans($prefix.$key.($short?'Short':'')) != $prefix.$key.($short?'Short':''))
131
+            $key = $obj['code'];
132
+            if ($langs->trans($prefix.$key.($short ? 'Short' : '')) != $prefix.$key.($short ? 'Short' : ''))
133 133
             {
134
-                print $langs->trans($prefix.$key.($short?'Short':''));
134
+                print $langs->trans($prefix.$key.($short ? 'Short' : ''));
135 135
             }
136 136
             else
137 137
 			{
138
-                $conv_to_new_code=array('PR_DRAFT'=>'Draft','PR_OPEN'=>'Validated','PR_CLOSED'=>'Closed','PR_SIGNED'=>'Signed','PR_NOTSIGNED'=>'NotSigned','PR_FAC'=>'Billed');
139
-                if (! empty($conv_to_new_code[$obj['code']])) $key=$conv_to_new_code[$obj['code']];
138
+                $conv_to_new_code = array('PR_DRAFT'=>'Draft', 'PR_OPEN'=>'Validated', 'PR_CLOSED'=>'Closed', 'PR_SIGNED'=>'Signed', 'PR_NOTSIGNED'=>'NotSigned', 'PR_FAC'=>'Billed');
139
+                if (!empty($conv_to_new_code[$obj['code']])) $key = $conv_to_new_code[$obj['code']];
140 140
 
141
-                print ($langs->trans($prefix.$key.($short?'Short':''))!=$prefix.$key.($short?'Short':''))?$langs->trans($prefix.$key.($short?'Short':'')):($obj['label']?$obj['label']:$obj['code']);
141
+                print ($langs->trans($prefix.$key.($short ? 'Short' : '')) != $prefix.$key.($short ? 'Short' : '')) ? $langs->trans($prefix.$key.($short ? 'Short' : '')) : ($obj['label'] ? $obj['label'] : $obj['code']);
142 142
             }
143 143
             print '</option>';
144 144
             $i++;
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/discount.class.php 1 patch
Spacing   +156 added lines, -156 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 	/**
42 42
 	 * @var string[]	Array of error strings
43 43
 	 */
44
-	public $errors=array();
44
+	public $errors = array();
45 45
 
46 46
 	/**
47 47
 	 * @var int ID discount
@@ -53,11 +53,11 @@  discard block
 block discarded – undo
53 53
 	 */
54 54
     public $fk_soc;
55 55
 
56
-    public $discount_type;			// 0 => customer discount, 1 => supplier discount
57
-    public $amount_ht;				//
58
-    public $amount_tva;			//
59
-    public $amount_ttc;			//
60
-    public $tva_tx;				// Vat rate
56
+    public $discount_type; // 0 => customer discount, 1 => supplier discount
57
+    public $amount_ht; //
58
+    public $amount_tva; //
59
+    public $amount_ttc; //
60
+    public $tva_tx; // Vat rate
61 61
 
62 62
     /**
63 63
 	 * @var int User ID Id utilisateur qui accorde la remise
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 	 */
70 70
 	public $description;
71 71
 
72
-    public $datec;					// Date creation
72
+    public $datec; // Date creation
73 73
 
74 74
     /**
75 75
      * @var int ID invoice line when a discount is used into an invoice line (for absolute discounts)
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
      */
87 87
     public $fk_facture_source;
88 88
 
89
-    public $ref_facture_source;	    // Ref credit note having caused the discount
89
+    public $ref_facture_source; // Ref credit note having caused the discount
90 90
 
91 91
     public $ref_invoice_supplier_source;
92 92
 
@@ -109,31 +109,31 @@  discard block
 block discarded – undo
109 109
      *  @param		int		$fk_invoice_supplier_source		fk_invoice_supplier_source
110 110
      *	@return		int										<0 if KO, =0 if not found, >0 if OK
111 111
      */
112
-    function fetch($rowid, $fk_facture_source=0, $fk_invoice_supplier_source=0)
112
+    function fetch($rowid, $fk_facture_source = 0, $fk_invoice_supplier_source = 0)
113 113
     {
114 114
     	global $conf;
115 115
 
116 116
         // Check parameters
117
-        if (! $rowid && ! $fk_facture_source && ! $fk_invoice_supplier_source)
117
+        if (!$rowid && !$fk_facture_source && !$fk_invoice_supplier_source)
118 118
         {
119
-            $this->error='ErrorBadParameters';
119
+            $this->error = 'ErrorBadParameters';
120 120
             return -1;
121 121
         }
122 122
 
123 123
         $sql = "SELECT sr.rowid, sr.fk_soc, sr.discount_type,";
124
-        $sql.= " sr.fk_user,";
125
-        $sql.= " sr.amount_ht, sr.amount_tva, sr.amount_ttc, sr.tva_tx,";
126
-        $sql.= " sr.multicurrency_amount_ht, sr.multicurrency_amount_tva, sr.multicurrency_amount_ttc,";
127
-        $sql.= " sr.fk_facture_line, sr.fk_facture, sr.fk_facture_source, sr.fk_invoice_supplier_line, sr.fk_invoice_supplier, sr.fk_invoice_supplier_source, sr.description,";
128
-        $sql.= " sr.datec,";
129
-        $sql.= " f.ref as ref_facture_source, fsup.ref as ref_invoice_supplier_source";
130
-        $sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except as sr";
131
-        $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON sr.fk_facture_source = f.rowid";
132
-        $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as fsup ON sr.fk_invoice_supplier_source = fsup.rowid";
133
-        $sql.= " WHERE sr.entity = " . $conf->entity;
134
-        if ($rowid) $sql.= " AND sr.rowid=".$rowid;
135
-        if ($fk_facture_source) $sql.= " AND sr.fk_facture_source=".$fk_facture_source;
136
-        if ($fk_invoice_supplier_source) $sql.= " AND sr.fk_invoice_supplier_source=".$fk_invoice_supplier_source;
124
+        $sql .= " sr.fk_user,";
125
+        $sql .= " sr.amount_ht, sr.amount_tva, sr.amount_ttc, sr.tva_tx,";
126
+        $sql .= " sr.multicurrency_amount_ht, sr.multicurrency_amount_tva, sr.multicurrency_amount_ttc,";
127
+        $sql .= " sr.fk_facture_line, sr.fk_facture, sr.fk_facture_source, sr.fk_invoice_supplier_line, sr.fk_invoice_supplier, sr.fk_invoice_supplier_source, sr.description,";
128
+        $sql .= " sr.datec,";
129
+        $sql .= " f.ref as ref_facture_source, fsup.ref as ref_invoice_supplier_source";
130
+        $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as sr";
131
+        $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON sr.fk_facture_source = f.rowid";
132
+        $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as fsup ON sr.fk_invoice_supplier_source = fsup.rowid";
133
+        $sql .= " WHERE sr.entity = ".$conf->entity;
134
+        if ($rowid) $sql .= " AND sr.rowid=".$rowid;
135
+        if ($fk_facture_source) $sql .= " AND sr.fk_facture_source=".$fk_facture_source;
136
+        if ($fk_invoice_supplier_source) $sql .= " AND sr.fk_invoice_supplier_source=".$fk_invoice_supplier_source;
137 137
 
138 138
         dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
139 139
         $resql = $this->db->query($sql);
@@ -159,12 +159,12 @@  discard block
 block discarded – undo
159 159
                 $this->fk_user = $obj->fk_user;
160 160
                 $this->fk_facture_line = $obj->fk_facture_line;
161 161
                 $this->fk_facture = $obj->fk_facture;
162
-                $this->fk_facture_source = $obj->fk_facture_source;		// Id avoir source
163
-                $this->ref_facture_source = $obj->ref_facture_source;	// Ref avoir source
162
+                $this->fk_facture_source = $obj->fk_facture_source; // Id avoir source
163
+                $this->ref_facture_source = $obj->ref_facture_source; // Ref avoir source
164 164
                 $this->fk_invoice_supplier_line = $obj->fk_invoice_supplier_line;
165 165
                 $this->fk_invoice_supplier = $obj->fk_invoice_supplier;
166
-                $this->fk_invoice_supplier_source = $obj->fk_invoice_supplier_source;		// Id avoir source
167
-                $this->ref_invoice_supplier_source = $obj->ref_invoice_supplier_source;	// Ref avoir source
166
+                $this->fk_invoice_supplier_source = $obj->fk_invoice_supplier_source; // Id avoir source
167
+                $this->ref_invoice_supplier_source = $obj->ref_invoice_supplier_source; // Ref avoir source
168 168
                 $this->description = $obj->description;
169 169
                 $this->datec = $this->db->jdate($obj->datec);
170 170
 
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
         }
180 180
         else
181 181
         {
182
-            $this->error=$this->db->error();
182
+            $this->error = $this->db->error();
183 183
             return -1;
184 184
         }
185 185
     }
@@ -196,52 +196,52 @@  discard block
 block discarded – undo
196 196
         global $conf, $langs;
197 197
 
198 198
         // Clean parameters
199
-        $this->amount_ht=price2num($this->amount_ht);
200
-        $this->amount_tva=price2num($this->amount_tva);
201
-        $this->amount_ttc=price2num($this->amount_ttc);
199
+        $this->amount_ht = price2num($this->amount_ht);
200
+        $this->amount_tva = price2num($this->amount_tva);
201
+        $this->amount_ttc = price2num($this->amount_ttc);
202 202
 
203
-        $this->tva_tx=price2num($this->tva_tx);
203
+        $this->tva_tx = price2num($this->tva_tx);
204 204
 
205
-        $this->multicurrency_amount_ht=price2num($this->multicurrency_amount_ht);
206
-        $this->multicurrency_amount_tva=price2num($this->multicurrency_amount_tva);
207
-        $this->multicurrency_amount_ttc=price2num($this->multicurrency_amount_ttc);
205
+        $this->multicurrency_amount_ht = price2num($this->multicurrency_amount_ht);
206
+        $this->multicurrency_amount_tva = price2num($this->multicurrency_amount_tva);
207
+        $this->multicurrency_amount_ttc = price2num($this->multicurrency_amount_ttc);
208 208
 
209
-        if (empty($this->multicurrency_amount_ht)) $this->multicurrency_amount_ht=0;
210
-        if (empty($this->multicurrency_amount_tva)) $this->multicurrency_amount_tva=0;
211
-        if (empty($this->multicurrency_amount_ttc)) $this->multicurrency_amount_ttc=0;
209
+        if (empty($this->multicurrency_amount_ht)) $this->multicurrency_amount_ht = 0;
210
+        if (empty($this->multicurrency_amount_tva)) $this->multicurrency_amount_tva = 0;
211
+        if (empty($this->multicurrency_amount_ttc)) $this->multicurrency_amount_ttc = 0;
212 212
 
213 213
         // Check parameters
214 214
         if (empty($this->description))
215 215
         {
216
-            $this->error='BadValueForPropertyDescription';
216
+            $this->error = 'BadValueForPropertyDescription';
217 217
             dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
218 218
             return -1;
219 219
         }
220 220
 
221 221
         // Insert request
222 222
         $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise_except";
223
-        $sql.= " (entity, datec, fk_soc, discount_type, fk_user, description,";
224
-        $sql.= " amount_ht, amount_tva, amount_ttc, tva_tx,";
225
-        $sql.= " multicurrency_amount_ht, multicurrency_amount_tva, multicurrency_amount_ttc,";
226
-        $sql.= " fk_facture_source, fk_invoice_supplier_source";
227
-        $sql.= ")";
228
-        $sql.= " VALUES (".$conf->entity.", '".$this->db->idate($this->datec!=''?$this->datec:dol_now())."', ".$this->fk_soc.", ".(empty($this->discount_type)?0:intval($this->discount_type)).", ".$user->id.", '".$this->db->escape($this->description)."',";
229
-        $sql.= " ".$this->amount_ht.", ".$this->amount_tva.", ".$this->amount_ttc.", ".$this->tva_tx.",";
230
-        $sql.= " ".$this->multicurrency_amount_ht.", ".$this->multicurrency_amount_tva.", ".$this->multicurrency_amount_ttc.", ";
231
-        $sql.= " ".($this->fk_facture_source ? "'".$this->db->escape($this->fk_facture_source)."'":"null").",";
232
-        $sql.= " ".($this->fk_invoice_supplier_source ? "'".$this->db->escape($this->fk_invoice_supplier_source)."'":"null");
233
-        $sql.= ")";
223
+        $sql .= " (entity, datec, fk_soc, discount_type, fk_user, description,";
224
+        $sql .= " amount_ht, amount_tva, amount_ttc, tva_tx,";
225
+        $sql .= " multicurrency_amount_ht, multicurrency_amount_tva, multicurrency_amount_ttc,";
226
+        $sql .= " fk_facture_source, fk_invoice_supplier_source";
227
+        $sql .= ")";
228
+        $sql .= " VALUES (".$conf->entity.", '".$this->db->idate($this->datec != '' ? $this->datec : dol_now())."', ".$this->fk_soc.", ".(empty($this->discount_type) ? 0 : intval($this->discount_type)).", ".$user->id.", '".$this->db->escape($this->description)."',";
229
+        $sql .= " ".$this->amount_ht.", ".$this->amount_tva.", ".$this->amount_ttc.", ".$this->tva_tx.",";
230
+        $sql .= " ".$this->multicurrency_amount_ht.", ".$this->multicurrency_amount_tva.", ".$this->multicurrency_amount_ttc.", ";
231
+        $sql .= " ".($this->fk_facture_source ? "'".$this->db->escape($this->fk_facture_source)."'" : "null").",";
232
+        $sql .= " ".($this->fk_invoice_supplier_source ? "'".$this->db->escape($this->fk_invoice_supplier_source)."'" : "null");
233
+        $sql .= ")";
234 234
 
235 235
         dol_syslog(get_class($this)."::create", LOG_DEBUG);
236
-        $resql=$this->db->query($sql);
236
+        $resql = $this->db->query($sql);
237 237
         if ($resql)
238 238
         {
239
-            $this->id=$this->db->last_insert_id(MAIN_DB_PREFIX."societe_remise_except");
239
+            $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."societe_remise_except");
240 240
             return $this->id;
241 241
         }
242 242
         else
243 243
         {
244
-            $this->error=$this->db->lasterror().' - sql='.$sql;
244
+            $this->error = $this->db->lasterror().' - sql='.$sql;
245 245
             return -1;
246 246
         }
247 247
     }
@@ -260,21 +260,21 @@  discard block
 block discarded – undo
260 260
         // Check if we can remove the discount
261 261
         if ($this->fk_facture_source)
262 262
         {
263
-            $sql="SELECT COUNT(rowid) as nb";
264
-            $sql.=" FROM ".MAIN_DB_PREFIX."societe_remise_except";
265
-            $sql.=" WHERE (fk_facture_line IS NOT NULL";	// Not used as absolute simple discount
266
-            $sql.=" OR fk_facture IS NOT NULL)"; 			// Not used as credit note and not used as deposit
267
-            $sql.=" AND fk_facture_source = ".$this->fk_facture_source;
263
+            $sql = "SELECT COUNT(rowid) as nb";
264
+            $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except";
265
+            $sql .= " WHERE (fk_facture_line IS NOT NULL"; // Not used as absolute simple discount
266
+            $sql .= " OR fk_facture IS NOT NULL)"; // Not used as credit note and not used as deposit
267
+            $sql .= " AND fk_facture_source = ".$this->fk_facture_source;
268 268
             //$sql.=" AND rowid != ".$this->id;
269 269
 
270 270
             dol_syslog(get_class($this)."::delete Check if we can remove discount", LOG_DEBUG);
271
-            $resql=$this->db->query($sql);
271
+            $resql = $this->db->query($sql);
272 272
             if ($resql)
273 273
             {
274 274
                 $obj = $this->db->fetch_object($resql);
275 275
                 if ($obj->nb > 0)
276 276
                 {
277
-                    $this->error='ErrorThisPartOrAnotherIsAlreadyUsedSoDiscountSerieCantBeRemoved';
277
+                    $this->error = 'ErrorThisPartOrAnotherIsAlreadyUsedSoDiscountSerieCantBeRemoved';
278 278
                     return -2;
279 279
                 }
280 280
             }
@@ -288,21 +288,21 @@  discard block
 block discarded – undo
288 288
         // Check if we can remove the discount
289 289
         if ($this->fk_invoice_supplier_source)
290 290
         {
291
-        	$sql="SELECT COUNT(rowid) as nb";
292
-        	$sql.=" FROM ".MAIN_DB_PREFIX."societe_remise_except";
293
-        	$sql.=" WHERE (fk_invoice_supplier_line IS NOT NULL";	// Not used as absolute simple discount
294
-        	$sql.=" OR fk_invoice_supplier IS NOT NULL)"; 			// Not used as credit note and not used as deposit
295
-        	$sql.=" AND fk_invoice_supplier_source = ".$this->fk_invoice_supplier_source;
291
+        	$sql = "SELECT COUNT(rowid) as nb";
292
+        	$sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except";
293
+        	$sql .= " WHERE (fk_invoice_supplier_line IS NOT NULL"; // Not used as absolute simple discount
294
+        	$sql .= " OR fk_invoice_supplier IS NOT NULL)"; // Not used as credit note and not used as deposit
295
+        	$sql .= " AND fk_invoice_supplier_source = ".$this->fk_invoice_supplier_source;
296 296
         	//$sql.=" AND rowid != ".$this->id;
297 297
 
298 298
         	dol_syslog(get_class($this)."::delete Check if we can remove discount", LOG_DEBUG);
299
-        	$resql=$this->db->query($sql);
299
+        	$resql = $this->db->query($sql);
300 300
         	if ($resql)
301 301
         	{
302 302
         		$obj = $this->db->fetch_object($resql);
303 303
         		if ($obj->nb > 0)
304 304
         		{
305
-        			$this->error='ErrorThisPartOrAnotherIsAlreadyUsedSoDiscountSerieCantBeRemoved';
305
+        			$this->error = 'ErrorThisPartOrAnotherIsAlreadyUsedSoDiscountSerieCantBeRemoved';
306 306
         			return -2;
307 307
         		}
308 308
         	}
@@ -317,27 +317,27 @@  discard block
 block discarded – undo
317 317
 
318 318
         // Delete but only if not used
319 319
         $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_remise_except ";
320
-        if ($this->fk_facture_source) $sql.= " WHERE fk_facture_source = ".$this->fk_facture_source;	// Delete all lines of same serie
321
-        elseif ($this->fk_invoice_supplier_source) $sql.= " WHERE fk_invoice_supplier_source = ".$this->fk_invoice_supplier_source;	// Delete all lines of same serie
322
-        else $sql.= " WHERE rowid = ".$this->id;	// Delete only line
323
-        $sql.= " AND (fk_facture_line IS NULL";	// Not used as absolute simple discount
324
-        $sql.= " AND fk_facture IS NULL)";		// Not used as credit note and not used as deposit
325
-        $sql.= " AND (fk_invoice_supplier_line IS NULL";	// Not used as absolute simple discount
326
-        $sql.= " AND fk_invoice_supplier IS NULL)";		// Not used as credit note and not used as deposit
320
+        if ($this->fk_facture_source) $sql .= " WHERE fk_facture_source = ".$this->fk_facture_source; // Delete all lines of same serie
321
+        elseif ($this->fk_invoice_supplier_source) $sql .= " WHERE fk_invoice_supplier_source = ".$this->fk_invoice_supplier_source; // Delete all lines of same serie
322
+        else $sql .= " WHERE rowid = ".$this->id; // Delete only line
323
+        $sql .= " AND (fk_facture_line IS NULL"; // Not used as absolute simple discount
324
+        $sql .= " AND fk_facture IS NULL)"; // Not used as credit note and not used as deposit
325
+        $sql .= " AND (fk_invoice_supplier_line IS NULL"; // Not used as absolute simple discount
326
+        $sql .= " AND fk_invoice_supplier IS NULL)"; // Not used as credit note and not used as deposit
327 327
 
328 328
         dol_syslog(get_class($this)."::delete Delete discount", LOG_DEBUG);
329
-        $result=$this->db->query($sql);
329
+        $result = $this->db->query($sql);
330 330
         if ($result)
331 331
         {
332 332
             // If source of discount was a credit note or deposit, we change source statut.
333 333
             if ($this->fk_facture_source)
334 334
             {
335 335
                 $sql = "UPDATE ".MAIN_DB_PREFIX."facture";
336
-                $sql.=" set paye=0, fk_statut=1";
337
-                $sql.=" WHERE (type = 2 or type = 3) AND rowid=".$this->fk_facture_source;
336
+                $sql .= " set paye=0, fk_statut=1";
337
+                $sql .= " WHERE (type = 2 or type = 3) AND rowid=".$this->fk_facture_source;
338 338
 
339 339
                 dol_syslog(get_class($this)."::delete Update credit note or deposit invoice statut", LOG_DEBUG);
340
-                $result=$this->db->query($sql);
340
+                $result = $this->db->query($sql);
341 341
                 if ($result)
342 342
                 {
343 343
                     $this->db->commit();
@@ -345,19 +345,19 @@  discard block
 block discarded – undo
345 345
                 }
346 346
                 else
347 347
                 {
348
-                    $this->error=$this->db->lasterror();
348
+                    $this->error = $this->db->lasterror();
349 349
                     $this->db->rollback();
350 350
                     return -1;
351 351
                 }
352 352
             }
353
-            elseif($this->fk_invoice_supplier_source) {
353
+            elseif ($this->fk_invoice_supplier_source) {
354 354
 
355 355
             	$sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn";
356
-            	$sql.=" set paye=0, fk_statut=1";
357
-            	$sql.=" WHERE (type = 2 or type = 3) AND rowid=".$this->fk_invoice_supplier_source;
356
+            	$sql .= " set paye=0, fk_statut=1";
357
+            	$sql .= " WHERE (type = 2 or type = 3) AND rowid=".$this->fk_invoice_supplier_source;
358 358
 
359 359
             	dol_syslog(get_class($this)."::delete Update credit note or deposit invoice statut", LOG_DEBUG);
360
-            	$result=$this->db->query($sql);
360
+            	$result = $this->db->query($sql);
361 361
             	if ($result)
362 362
             	{
363 363
             		$this->db->commit();
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
             	}
366 366
             	else
367 367
             	{
368
-            		$this->error=$this->db->lasterror();
368
+            		$this->error = $this->db->lasterror();
369 369
             		$this->db->rollback();
370 370
             		return -1;
371 371
             	}
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
         }
379 379
         else
380 380
         {
381
-            $this->error=$this->db->lasterror();
381
+            $this->error = $this->db->lasterror();
382 382
             $this->db->rollback();
383 383
             return -1;
384 384
         }
@@ -396,47 +396,47 @@  discard block
 block discarded – undo
396 396
      *	@param		int		$rowidinvoice	Invoice id (To use discount as a credit note to reduc payment of invoice)
397 397
      *	@return		int						<0 if KO, >0 if OK
398 398
      */
399
-    function link_to_invoice($rowidline,$rowidinvoice)
399
+    function link_to_invoice($rowidline, $rowidinvoice)
400 400
     {
401 401
         // phpcs:enable
402 402
         // Check parameters
403
-        if (! $rowidline && ! $rowidinvoice)
403
+        if (!$rowidline && !$rowidinvoice)
404 404
         {
405
-            $this->error='ErrorBadParameters';
405
+            $this->error = 'ErrorBadParameters';
406 406
             return -1;
407 407
         }
408 408
         if ($rowidline && $rowidinvoice)
409 409
         {
410
-            $this->error='ErrorBadParameters';
410
+            $this->error = 'ErrorBadParameters';
411 411
             return -2;
412 412
         }
413 413
 
414
-        $sql ="UPDATE ".MAIN_DB_PREFIX."societe_remise_except";
415
-        if(! empty($this->discount_type)) {
416
-        	if ($rowidline)    $sql.=" SET fk_invoice_supplier_line = ".$rowidline;
417
-        	if ($rowidinvoice) $sql.=" SET fk_invoice_supplier = ".$rowidinvoice;
414
+        $sql = "UPDATE ".MAIN_DB_PREFIX."societe_remise_except";
415
+        if (!empty($this->discount_type)) {
416
+        	if ($rowidline)    $sql .= " SET fk_invoice_supplier_line = ".$rowidline;
417
+        	if ($rowidinvoice) $sql .= " SET fk_invoice_supplier = ".$rowidinvoice;
418 418
         } else {
419
-        	if ($rowidline)    $sql.=" SET fk_facture_line = ".$rowidline;
420
-        	if ($rowidinvoice) $sql.=" SET fk_facture = ".$rowidinvoice;
419
+        	if ($rowidline)    $sql .= " SET fk_facture_line = ".$rowidline;
420
+        	if ($rowidinvoice) $sql .= " SET fk_facture = ".$rowidinvoice;
421 421
         }
422
-        $sql.=" WHERE rowid = ".$this->id;
422
+        $sql .= " WHERE rowid = ".$this->id;
423 423
 
424 424
         dol_syslog(get_class($this)."::link_to_invoice", LOG_DEBUG);
425 425
         $resql = $this->db->query($sql);
426 426
         if ($resql)
427 427
         {
428
-        	if(! empty($this->discount_type)) {
429
-        		$this->fk_invoice_supplier_line=$rowidline;
430
-        		$this->fk_invoice_supplier=$rowidinvoice;
428
+        	if (!empty($this->discount_type)) {
429
+        		$this->fk_invoice_supplier_line = $rowidline;
430
+        		$this->fk_invoice_supplier = $rowidinvoice;
431 431
         	} else {
432
-        		$this->fk_facture_line=$rowidline;
433
-        		$this->fk_facture=$rowidinvoice;
432
+        		$this->fk_facture_line = $rowidline;
433
+        		$this->fk_facture = $rowidinvoice;
434 434
         	}
435 435
             return 1;
436 436
         }
437 437
         else
438 438
         {
439
-            $this->error=$this->db->error();
439
+            $this->error = $this->db->error();
440 440
             return -3;
441 441
         }
442 442
     }
@@ -452,13 +452,13 @@  discard block
 block discarded – undo
452 452
     function unlink_invoice()
453 453
     {
454 454
         // phpcs:enable
455
-        $sql ="UPDATE ".MAIN_DB_PREFIX."societe_remise_except";
456
-		if(! empty($this->discount_type)) {
457
-       		$sql.=" SET fk_invoice_supplier_line = NULL, fk_invoice_supplier = NULL";
455
+        $sql = "UPDATE ".MAIN_DB_PREFIX."societe_remise_except";
456
+		if (!empty($this->discount_type)) {
457
+       		$sql .= " SET fk_invoice_supplier_line = NULL, fk_invoice_supplier = NULL";
458 458
 		} else {
459
-			$sql.=" SET fk_facture_line = NULL, fk_facture = NULL";
459
+			$sql .= " SET fk_facture_line = NULL, fk_facture = NULL";
460 460
 		}
461
-        $sql.=" WHERE rowid = ".$this->id;
461
+        $sql .= " WHERE rowid = ".$this->id;
462 462
 
463 463
         dol_syslog(get_class($this)."::unlink_invoice", LOG_DEBUG);
464 464
         $resql = $this->db->query($sql);
@@ -468,7 +468,7 @@  discard block
 block discarded – undo
468 468
         }
469 469
         else
470 470
         {
471
-            $this->error=$this->db->error();
471
+            $this->error = $this->db->error();
472 472
             return -3;
473 473
         }
474 474
     }
@@ -484,27 +484,27 @@  discard block
 block discarded – undo
484 484
      *  @param      int			$discount_type  0 => customer discount, 1 => supplier discount
485 485
      * 	@return		int						<0 if KO, amount otherwise
486 486
      */
487
-    function getAvailableDiscounts($company='', $user='',$filter='', $maxvalue=0, $discount_type=0)
487
+    function getAvailableDiscounts($company = '', $user = '', $filter = '', $maxvalue = 0, $discount_type = 0)
488 488
     {
489 489
     	global $conf;
490 490
 
491
-        $sql  = "SELECT SUM(rc.amount_ttc) as amount";
491
+        $sql = "SELECT SUM(rc.amount_ttc) as amount";
492 492
         //$sql  = "SELECT rc.amount_ttc as amount";
493
-        $sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc";
494
-        $sql.= " WHERE rc.entity = " . $conf->entity;
495
-        $sql.= " AND rc.discount_type=".intval($discount_type);
496
-        if (! empty($discount_type)) {
497
-        	$sql.= " AND (rc.fk_invoice_supplier IS NULL AND rc.fk_invoice_supplier_line IS NULL)"; // Available from supplier
493
+        $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc";
494
+        $sql .= " WHERE rc.entity = ".$conf->entity;
495
+        $sql .= " AND rc.discount_type=".intval($discount_type);
496
+        if (!empty($discount_type)) {
497
+        	$sql .= " AND (rc.fk_invoice_supplier IS NULL AND rc.fk_invoice_supplier_line IS NULL)"; // Available from supplier
498 498
         } else {
499
-        	$sql.= " AND (rc.fk_facture IS NULL AND rc.fk_facture_line IS NULL)"; // Available to customer
499
+        	$sql .= " AND (rc.fk_facture IS NULL AND rc.fk_facture_line IS NULL)"; // Available to customer
500 500
         }
501
-        if (is_object($company)) $sql.= " AND rc.fk_soc = ".$company->id;
502
-        if (is_object($user))    $sql.= " AND rc.fk_user = ".$user->id;
503
-        if ($filter)   $sql.=' AND ('.$filter.')';
504
-        if ($maxvalue) $sql.=' AND rc.amount_ttc <= '.price2num($maxvalue);
501
+        if (is_object($company)) $sql .= " AND rc.fk_soc = ".$company->id;
502
+        if (is_object($user))    $sql .= " AND rc.fk_user = ".$user->id;
503
+        if ($filter)   $sql .= ' AND ('.$filter.')';
504
+        if ($maxvalue) $sql .= ' AND rc.amount_ttc <= '.price2num($maxvalue);
505 505
 
506 506
         dol_syslog(get_class($this)."::getAvailableDiscounts", LOG_DEBUG);
507
-        $resql=$this->db->query($sql);
507
+        $resql = $this->db->query($sql);
508 508
         if ($resql)
509 509
         {
510 510
             $obj = $this->db->fetch_object($resql);
@@ -527,32 +527,32 @@  discard block
 block discarded – undo
527 527
 	 *  @param 		int 		    $multicurrency 	Return multicurrency_amount instead of amount
528 528
      *	@return		int				     			<0 if KO, Sum of credit notes and deposits amount otherwise
529 529
      */
530
-    function getSumDepositsUsed($invoice, $multicurrency=0)
530
+    function getSumDepositsUsed($invoice, $multicurrency = 0)
531 531
     {
532 532
         dol_syslog(get_class($this)."::getSumDepositsUsed", LOG_DEBUG);
533 533
 
534 534
         if ($invoice->element == 'facture' || $invoice->element == 'invoice')
535 535
         {
536 536
             $sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount';
537
-            $sql.= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture as f';
538
-            $sql.= ' WHERE rc.fk_facture_source=f.rowid AND rc.fk_facture = '.$invoice->id;
539
-            $sql.= ' AND f.type = 3';
537
+            $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture as f';
538
+            $sql .= ' WHERE rc.fk_facture_source=f.rowid AND rc.fk_facture = '.$invoice->id;
539
+            $sql .= ' AND f.type = 3';
540 540
         }
541 541
         else if ($invoice->element == 'invoice_supplier')
542 542
         {
543 543
             $sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount';
544
-            $sql.= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture_fourn as f';
545
-            $sql.= ' WHERE rc.fk_invoice_supplier_source=f.rowid AND rc.fk_invoice_supplier = '.$invoice->id;
546
-            $sql.= ' AND f.type = 3';
544
+            $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture_fourn as f';
545
+            $sql .= ' WHERE rc.fk_invoice_supplier_source=f.rowid AND rc.fk_invoice_supplier = '.$invoice->id;
546
+            $sql .= ' AND f.type = 3';
547 547
         }
548 548
         else
549 549
         {
550
-            $this->error=get_class($this)."::getSumDepositsUsed was called with a bad object as a first parameter";
550
+            $this->error = get_class($this)."::getSumDepositsUsed was called with a bad object as a first parameter";
551 551
             dol_print_error($this->error);
552 552
             return -1;
553 553
         }
554 554
 
555
-        $resql=$this->db->query($sql);
555
+        $resql = $this->db->query($sql);
556 556
         if ($resql)
557 557
         {
558 558
             $obj = $this->db->fetch_object($resql);
@@ -573,32 +573,32 @@  discard block
 block discarded – undo
573 573
 	 *	@param		int			      $multicurrency	Return multicurrency_amount instead of amount
574 574
      *	@return		int					        		<0 if KO, Sum of credit notes and excess received amount otherwise
575 575
      */
576
-    function getSumCreditNotesUsed($invoice, $multicurrency=0)
576
+    function getSumCreditNotesUsed($invoice, $multicurrency = 0)
577 577
     {
578 578
         dol_syslog(get_class($this)."::getSumCreditNotesUsed", LOG_DEBUG);
579 579
 
580 580
         if ($invoice->element == 'facture' || $invoice->element == 'invoice')
581 581
         {
582 582
             $sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount';
583
-            $sql.= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture as f';
584
-            $sql.= ' WHERE rc.fk_facture_source=f.rowid AND rc.fk_facture = '.$invoice->id;
585
-            $sql.= ' AND (f.type = 2 OR f.type = 0)';	// Find discount coming from credit note or excess received
583
+            $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture as f';
584
+            $sql .= ' WHERE rc.fk_facture_source=f.rowid AND rc.fk_facture = '.$invoice->id;
585
+            $sql .= ' AND (f.type = 2 OR f.type = 0)'; // Find discount coming from credit note or excess received
586 586
         }
587 587
         else if ($invoice->element == 'invoice_supplier')
588 588
         {
589 589
             $sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount';
590
-            $sql.= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture_fourn as f';
591
-            $sql.= ' WHERE rc.fk_invoice_supplier_source=f.rowid AND rc.fk_invoice_supplier = '.$invoice->id;
592
-            $sql.= ' AND (f.type = 2 OR f.type = 0)';	// Find discount coming from credit note or excess paid
590
+            $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture_fourn as f';
591
+            $sql .= ' WHERE rc.fk_invoice_supplier_source=f.rowid AND rc.fk_invoice_supplier = '.$invoice->id;
592
+            $sql .= ' AND (f.type = 2 OR f.type = 0)'; // Find discount coming from credit note or excess paid
593 593
         }
594 594
         else
595 595
         {
596
-            $this->error=get_class($this)."::getSumCreditNotesUsed was called with a bad object as a first parameter";
596
+            $this->error = get_class($this)."::getSumCreditNotesUsed was called with a bad object as a first parameter";
597 597
             dol_print_error($this->error);
598 598
             return -1;
599 599
         }
600 600
 
601
-        $resql=$this->db->query($sql);
601
+        $resql = $this->db->query($sql);
602 602
         if ($resql)
603 603
         {
604 604
             $obj = $this->db->fetch_object($resql);
@@ -619,33 +619,33 @@  discard block
 block discarded – undo
619 619
      *	@param		string	$option			Where to link to ('invoice' or 'discount')
620 620
      *	@return		string					String with URL
621 621
      */
622
-    function getNomUrl($withpicto,$option='invoice')
622
+    function getNomUrl($withpicto, $option = 'invoice')
623 623
     {
624 624
         global $langs;
625 625
 
626
-        $result='';
626
+        $result = '';
627 627
 
628 628
         if ($option == 'invoice') {
629
-            $facid=! empty($this->discount_type)?$this->fk_invoice_supplier_source:$this->fk_facture_source;
630
-            $link=! empty($this->discount_type)?'/fourn/facture/card.php':'/compta/facture/card.php';
631
-            $label=$langs->trans("ShowDiscount").': '.$this->ref_facture_source;
629
+            $facid = !empty($this->discount_type) ? $this->fk_invoice_supplier_source : $this->fk_facture_source;
630
+            $link = !empty($this->discount_type) ? '/fourn/facture/card.php' : '/compta/facture/card.php';
631
+            $label = $langs->trans("ShowDiscount").': '.$this->ref_facture_source;
632 632
             $link = '<a href="'.DOL_URL_ROOT.$link.'?facid='.$facid.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
633
-            $linkend='</a>';
634
-            $ref=! empty($this->discount_type)?$this->ref_invoice_supplier_source:$this->ref_facture_source;
635
-            $picto='bill';
633
+            $linkend = '</a>';
634
+            $ref = !empty($this->discount_type) ? $this->ref_invoice_supplier_source : $this->ref_facture_source;
635
+            $picto = 'bill';
636 636
         }
637 637
         if ($option == 'discount') {
638
-            $label=$langs->trans("Discount");
638
+            $label = $langs->trans("Discount");
639 639
             $link = '<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$this->fk_soc.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
640
-            $linkend='</a>';
641
-            $ref=$langs->trans("Discount");
642
-            $picto='generic';
640
+            $linkend = '</a>';
641
+            $ref = $langs->trans("Discount");
642
+            $picto = 'generic';
643 643
         }
644 644
 
645 645
 
646
-        if ($withpicto) $result.=($link.img_object($label, $picto, 'class="classfortooltip"').$linkend);
647
-        if ($withpicto && $withpicto != 2) $result.=' ';
648
-        $result.=$link.$ref.$linkend;
646
+        if ($withpicto) $result .= ($link.img_object($label, $picto, 'class="classfortooltip"').$linkend);
647
+        if ($withpicto && $withpicto != 2) $result .= ' ';
648
+        $result .= $link.$ref.$linkend;
649 649
         return $result;
650 650
     }
651 651
 
@@ -659,7 +659,7 @@  discard block
 block discarded – undo
659 659
 	 */
660 660
 	function initAsSpecimen()
661 661
 	{
662
-		global $user,$langs,$conf;
662
+		global $user, $langs, $conf;
663 663
 
664 664
 		$this->fk_soc         = 1;
665 665
 		$this->amount_ht      = 10;
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/openid.class.php 1 patch
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
     {
186 186
         // phpcs:enable
187 187
         $e = $this->error;
188
-        return array('code'=>$e[0],'description'=>$e[1]);
188
+        return array('code'=>$e[0], 'description'=>$e[1]);
189 189
     }
190 190
 
191 191
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -200,10 +200,10 @@  discard block
 block discarded – undo
200 200
     {
201 201
         // phpcs:enable
202 202
         $errs['OPENID_NOSERVERSFOUND'] = 'Cannot find OpenID Server TAG on Identity page.';
203
-        if ($desc == null){
203
+        if ($desc == null) {
204 204
             $desc = $errs[$code];
205 205
         }
206
-        $this->error = array($code,$desc);
206
+        $this->error = array($code, $desc);
207 207
     }
208 208
 
209 209
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
     {
236 236
         $r = array();
237 237
         $response = explode("\n", $response);
238
-        foreach($response as $line) {
238
+        foreach ($response as $line) {
239 239
             $line = trim($line);
240 240
             if ($line != "") {
241 241
                 list($key, $value) = explode(":", $line, 2);
@@ -263,13 +263,13 @@  discard block
 block discarded – undo
263 263
         if (!isset($u['path']) || ($u['path'] == '/')) {
264 264
             $u['path'] = '';
265 265
         }
266
-        if(substr($u['path'],-1,1) == '/'){
267
-            $u['path'] = substr($u['path'], 0, strlen($u['path'])-1);
266
+        if (substr($u['path'], -1, 1) == '/') {
267
+            $u['path'] = substr($u['path'], 0, strlen($u['path']) - 1);
268 268
         }
269
-        if (isset($u['query'])){ // If there is a query string, then use identity as is
270
-            return $u['host'] . $u['path'] . '?' . $u['query'];
271
-        }else{
272
-            return $u['host'] . $u['path'];
269
+        if (isset($u['query'])) { // If there is a query string, then use identity as is
270
+            return $u['host'].$u['path'].'?'.$u['query'];
271
+        } else {
272
+            return $u['host'].$u['path'];
273 273
         }
274 274
     }
275 275
 
@@ -282,12 +282,12 @@  discard block
 block discarded – undo
282 282
     function array2url($arr)
283 283
     {
284 284
         // converts associated array to URL Query String
285
-        if (!is_array($arr)){
285
+        if (!is_array($arr)) {
286 286
             return false;
287 287
         }
288 288
         $query = '';
289
-        foreach($arr as $key => $value){
290
-            $query .= $key . "=" . $value . "&";
289
+        foreach ($arr as $key => $value) {
290
+            $query .= $key."=".$value."&";
291 291
         }
292 292
         return $query;
293 293
     }
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
      * @param string	$params		Params
302 302
      * @return boolean|unknown
303 303
      */
304
-    function FSOCK_Request($url, $method="GET", $params = "")
304
+    function FSOCK_Request($url, $method = "GET", $params = "")
305 305
     {
306 306
         // phpcs:enable
307 307
         $fp = fsockopen("ssl://www.myopenid.com", 443, $errno, $errstr, 3); // Connection timeout is 3 seconds
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
             $this->ErrorStore('OPENID_SOCKETERROR', $errstr);
310 310
             return false;
311 311
         } else {
312
-            $request = $method . " /server HTTP/1.0\r\n";
312
+            $request = $method." /server HTTP/1.0\r\n";
313 313
             $request .= "User-Agent: Dolibarr\r\n";
314 314
             $request .= "Connection: close\r\n\r\n";
315 315
             fwrite($fp, $request);
@@ -335,13 +335,13 @@  discard block
 block discarded – undo
335 335
      * @param 	string	$params		Params
336 336
      * @return string
337 337
      */
338
-    function CURL_Request($url, $method="GET", $params = "")
338
+    function CURL_Request($url, $method = "GET", $params = "")
339 339
     {
340 340
         // phpcs:enable
341 341
         // Remember, SSL MUST BE SUPPORTED
342 342
         if (is_array($params)) $params = $this->array2url($params);
343 343
 
344
-        $curl = curl_init($url . ($method == "GET" && $params != "" ? "?" . $params : ""));
344
+        $curl = curl_init($url.($method == "GET" && $params != "" ? "?".$params : ""));
345 345
         @curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
346 346
         curl_setopt($curl, CURLOPT_HEADER, false);
347 347
         curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
@@ -351,9 +351,9 @@  discard block
 block discarded – undo
351 351
         curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
352 352
         $response = curl_exec($curl);
353 353
 
354
-        if (curl_errno($curl) == 0){
354
+        if (curl_errno($curl) == 0) {
355 355
             $response;
356
-        }else{
356
+        } else {
357 357
             $this->ErrorStore('OPENID_CURL', curl_error($curl));
358 358
         }
359 359
         return $response;
@@ -394,13 +394,13 @@  discard block
 block discarded – undo
394 394
      * @param	string	$url	Url to found endpoint
395 395
      * @return 	string			Endpoint
396 396
      */
397
-    function GetOpenIDServer($url='')
397
+    function GetOpenIDServer($url = '')
398 398
     {
399 399
         // phpcs:enable
400 400
         global $conf;
401 401
 
402 402
 		include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
403
-		if (empty($url)) $url=$conf->global->MAIN_AUTHENTICATION_OPENID_URL;
403
+		if (empty($url)) $url = $conf->global->MAIN_AUTHENTICATION_OPENID_URL;
404 404
 
405 405
         $response = getURLContent($url);
406 406
 
@@ -434,13 +434,13 @@  discard block
 block discarded – undo
434 434
 
435 435
         if (isset($this->fields['required'])
436 436
         && (count($this->fields['required']) > 0)) {
437
-            $params['openid.sreg.required'] = implode(',',$this->fields['required']);
437
+            $params['openid.sreg.required'] = implode(',', $this->fields['required']);
438 438
         }
439 439
         if (isset($this->fields['optional'])
440 440
         && (count($this->fields['optional']) > 0)) {
441
-            $params['openid.sreg.optional'] = implode(',',$this->fields['optional']);
441
+            $params['openid.sreg.optional'] = implode(',', $this->fields['optional']);
442 442
         }
443
-        return $this->URLs['openid_server'] . "?". $this->array2url($params);
443
+        return $this->URLs['openid_server']."?".$this->array2url($params);
444 444
     }
445 445
 
446 446
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
         }
462 462
         else
463 463
         {	// Default Header Redirect
464
-            header('Location: ' . $redirect_to);
464
+            header('Location: '.$redirect_to);
465 465
         }
466 466
     }
467 467
 
@@ -480,14 +480,14 @@  discard block
 block discarded – undo
480 480
 			'openid.sig' => urlencode($_GET['openid_sig'])
481 481
         );
482 482
         // Send only required parameters to confirm validity
483
-        $arr_signed = explode(",",str_replace('sreg.','sreg_',$_GET['openid_signed']));
483
+        $arr_signed = explode(",", str_replace('sreg.', 'sreg_', $_GET['openid_signed']));
484 484
         $num = count($arr_signed);
485 485
         for ($i = 0; $i < $num; $i++)
486 486
         {
487
-            $s = str_replace('sreg_','sreg.', $arr_signed[$i]);
488
-            $c = $_GET['openid_' . $arr_signed[$i]];
487
+            $s = str_replace('sreg_', 'sreg.', $arr_signed[$i]);
488
+            $c = $_GET['openid_'.$arr_signed[$i]];
489 489
             // if ($c != ""){
490
-            $params['openid.' . $s] = urlencode($c);
490
+            $params['openid.'.$s] = urlencode($c);
491 491
             // }
492 492
         }
493 493
         $params['openid.mode'] = "check_authentication";
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
         {
498 498
             return false;
499 499
         }
500
-        $response = $this->CURL_Request($openid_server,'POST',$params);
500
+        $response = $this->CURL_Request($openid_server, 'POST', $params);
501 501
         $data = $this->splitResponse($response);
502 502
         if ($data['is_valid'] == "true")
503 503
         {
@@ -518,16 +518,16 @@  discard block
 block discarded – undo
518 518
      * @param	string	$url	Url of endpoint to request
519 519
      * @return 	string			First endpoint OpenID server found. False if it failed to found.
520 520
      */
521
-    function sendDiscoveryRequestToGetXRDS($url='')
521
+    function sendDiscoveryRequestToGetXRDS($url = '')
522 522
     {
523 523
     	global $conf;
524 524
 
525 525
 		include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
526
-		if (empty($url)) $url=$conf->global->MAIN_AUTHENTICATION_OPENID_URL;
526
+		if (empty($url)) $url = $conf->global->MAIN_AUTHENTICATION_OPENID_URL;
527 527
 
528 528
 		dol_syslog(get_class($this).'::sendDiscoveryRequestToGetXRDS get XRDS');
529 529
 
530
-		$addheaders=array('Accept: application/xrds+xml');
530
+		$addheaders = array('Accept: application/xrds+xml');
531 531
         $response = getURLContent($url, 'GET', '', 1, $addheaders);
532 532
 		/* response should like this:
533 533
 		<?xml version="1.0" encoding="UTF-8"?>
@@ -542,12 +542,12 @@  discard block
 block discarded – undo
542 542
 		</XRD>
543 543
 		</xrds:XRDS>
544 544
 		*/
545
-		$content=$response['content'];
545
+		$content = $response['content'];
546 546
 
547
-        $server='';
548
-        if (preg_match('/'.preg_quote('<URI>','/').'(.*)'.preg_quote('</URI>','/').'/is', $content, $reg))
547
+        $server = '';
548
+        if (preg_match('/'.preg_quote('<URI>', '/').'(.*)'.preg_quote('</URI>', '/').'/is', $content, $reg))
549 549
         {
550
-        	$server=$reg[1];
550
+        	$server = $reg[1];
551 551
         }
552 552
 
553 553
         if (empty($server))
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/emailsenderprofile.class.php 1 patch
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
  */
27 27
 
28 28
 // Put here all includes required by your class file
29
-require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php';
29
+require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
30 30
 //require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
31 31
 //require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
32 32
 
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 	/**
76 76
 	 * @var array  Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
77 77
 	 */
78
-	public $fields=array(
78
+	public $fields = array(
79 79
 		'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'visible'=>-1, 'enabled'=>1, 'position'=>1, 'notnull'=>1, 'index'=>1, 'comment'=>'Id',),
80 80
 		'entity' => array('type'=>'integer', 'label'=>'Entity', 'visible'=>-1, 'enabled'=>1, 'position'=>20, 'notnull'=>1, 'index'=>1,),
81 81
 		'label' => array('type'=>'varchar(255)', 'label'=>'Label', 'visible'=>1, 'enabled'=>1, 'position'=>30, 'notnull'=>-1),
@@ -152,8 +152,8 @@  discard block
 block discarded – undo
152 152
 
153 153
 		$this->db = $db;
154 154
 
155
-		if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) $this->fields['rowid']['visible']=0;
156
-		if (empty($conf->multicompany->enabled)) $this->fields['entity']['enabled']=0;
155
+		if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) $this->fields['rowid']['visible'] = 0;
156
+		if (empty($conf->multicompany->enabled)) $this->fields['entity']['enabled'] = 0;
157 157
 	}
158 158
 
159 159
 	/**
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 	public function fetch($id, $ref = null)
228 228
 	{
229 229
 		$result = $this->fetchCommon($id, $ref);
230
-		if ($result > 0 && ! empty($this->table_element_line)) $this->fetchLines();
230
+		if ($result > 0 && !empty($this->table_element_line)) $this->fetchLines();
231 231
 		return $result;
232 232
 	}
233 233
 
@@ -238,11 +238,11 @@  discard block
 block discarded – undo
238 238
 	 */
239 239
 	public function fetchLines()
240 240
 	{
241
-		$this->lines=array();
241
+		$this->lines = array();
242 242
 
243 243
 		// Load lines with object EmailSenderProfileLine
244 244
 
245
-		return count($this->lines)?1:0;
245
+		return count($this->lines) ? 1 : 0;
246 246
 	}
247 247
 
248 248
 	/**
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 	 *	@param	int		$withpicto					Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
276 276
 	 *	@return	string								String with URL
277 277
 	 */
278
-	function getNomUrl($withpicto=0)
278
+	function getNomUrl($withpicto = 0)
279 279
 	{
280 280
 		global $db, $conf, $langs;
281 281
 		global $dolibarr_main_authentication, $dolibarr_main_demo;
@@ -284,20 +284,20 @@  discard block
 block discarded – undo
284 284
 		$result = '';
285 285
 		$companylink = '';
286 286
 
287
-    $label=$this->label;
287
+    $label = $this->label;
288 288
 
289
-    $url='';
289
+    $url = '';
290 290
 		//$url = dol_buildpath('/monmodule/emailsenderprofile_card.php',1).'?id='.$this->id;
291 291
 
292 292
 		$linkstart = '';
293
-		$linkend='';
293
+		$linkend = '';
294 294
 
295 295
 		if ($withpicto)
296 296
 		{
297
-			$result.=($linkstart.img_object($label, 'label', 'class="classfortooltip"').$linkend);
298
-			if ($withpicto != 2) $result.=' ';
297
+			$result .= ($linkstart.img_object($label, 'label', 'class="classfortooltip"').$linkend);
298
+			if ($withpicto != 2) $result .= ' ';
299 299
 		}
300
-		$result.= $linkstart . $this->label . $linkend;
300
+		$result .= $linkstart.$this->label.$linkend;
301 301
 		return $result;
302 302
 	}
303 303
 
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
 	 * @param	int				$withpicto			Add download picto into link
308 308
 	 * @return	string			HTML link to file
309 309
 	 */
310
-	function getDirectExternalLink($withpicto=0)
310
+	function getDirectExternalLink($withpicto = 0)
311 311
 	{
312 312
 		return 'todo';
313 313
 	}
@@ -318,9 +318,9 @@  discard block
 block discarded – undo
318 318
 	 *  @param	int		$mode          0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
319 319
 	 *  @return	string 			       Label of status
320 320
 	 */
321
-	function getLibStatut($mode=0)
321
+	function getLibStatut($mode = 0)
322 322
 	{
323
-		return $this->LibStatut($this->status,$mode);
323
+		return $this->LibStatut($this->status, $mode);
324 324
 	}
325 325
 
326 326
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
 	 *  @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
332 332
 	 *  @return string 			       	Label of status
333 333
 	 */
334
-	static function LibStatut($status,$mode=0)
334
+	static function LibStatut($status, $mode = 0)
335 335
 	{
336 336
 		global $langs;
337 337
 
@@ -342,28 +342,28 @@  discard block
 block discarded – undo
342 342
 		}
343 343
 		elseif ($mode == 2)
344 344
 		{
345
-			if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
346
-			if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
345
+			if ($status == 1) return img_picto($langs->trans('Enabled'), 'statut4').' '.$langs->trans('Enabled');
346
+			if ($status == 0) return img_picto($langs->trans('Disabled'), 'statut5').' '.$langs->trans('Disabled');
347 347
 		}
348 348
 		elseif ($mode == 3)
349 349
 		{
350
-			if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4');
351
-			if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5');
350
+			if ($status == 1) return img_picto($langs->trans('Enabled'), 'statut4');
351
+			if ($status == 0) return img_picto($langs->trans('Disabled'), 'statut5');
352 352
 		}
353 353
 		elseif ($mode == 4)
354 354
 		{
355
-			if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
356
-			if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
355
+			if ($status == 1) return img_picto($langs->trans('Enabled'), 'statut4').' '.$langs->trans('Enabled');
356
+			if ($status == 0) return img_picto($langs->trans('Disabled'), 'statut5').' '.$langs->trans('Disabled');
357 357
 		}
358 358
 		elseif ($mode == 5)
359 359
 		{
360
-			if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4');
361
-			if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5');
360
+			if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'), 'statut4');
361
+			if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'), 'statut5');
362 362
 		}
363 363
 		elseif ($mode == 6)
364 364
 		{
365
-			if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4');
366
-			if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5');
365
+			if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'), 'statut4');
366
+			if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'), 'statut5');
367 367
 		}
368 368
 	}
369 369
 
@@ -376,10 +376,10 @@  discard block
 block discarded – undo
376 376
 	function info($id)
377 377
 	{
378 378
 		$sql = 'SELECT rowid, date_creation as datec, tms as datem,';
379
-		$sql.= ' fk_user_creat, fk_user_modif';
380
-		$sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
381
-		$sql.= ' WHERE t.rowid = '.$id;
382
-		$result=$this->db->query($sql);
379
+		$sql .= ' fk_user_creat, fk_user_modif';
380
+		$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
381
+		$sql .= ' WHERE t.rowid = '.$id;
382
+		$result = $this->db->query($sql);
383 383
 		if ($result)
384 384
 		{
385 385
 			if ($this->db->num_rows($result))
@@ -390,7 +390,7 @@  discard block
 block discarded – undo
390 390
 				{
391 391
 					$cuser = new User($this->db);
392 392
 					$cuser->fetch($obj->fk_user_author);
393
-					$this->user_creation   = $cuser;
393
+					$this->user_creation = $cuser;
394 394
 				}
395 395
 
396 396
 				if ($obj->fk_user_valid)
@@ -404,7 +404,7 @@  discard block
 block discarded – undo
404 404
 				{
405 405
 					$cluser = new User($this->db);
406 406
 					$cluser->fetch($obj->fk_user_cloture);
407
-					$this->user_cloture   = $cluser;
407
+					$this->user_cloture = $cluser;
408 408
 				}
409 409
 
410 410
 				$this->date_creation     = $this->db->jdate($obj->datec);
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/html.formwebsite.class.php 1 patch
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -54,21 +54,21 @@  discard block
 block discarded – undo
54 54
      *    @param    int		$useempty          Show empty value or not
55 55
      *    @return	string					   Html component
56 56
      */
57
-    function selectWebsite($selected='',$htmlname='exportmodelid',$useempty=0)
57
+    function selectWebsite($selected = '', $htmlname = 'exportmodelid', $useempty = 0)
58 58
     {
59
-    	$out='';
59
+    	$out = '';
60 60
 
61 61
         $sql = "SELECT rowid, ref";
62
-        $sql.= " FROM ".MAIN_DB_PREFIX."website";
63
-        $sql.= " WHERE 1 = 1";
64
-        $sql.= " ORDER BY rowid";
62
+        $sql .= " FROM ".MAIN_DB_PREFIX."website";
63
+        $sql .= " WHERE 1 = 1";
64
+        $sql .= " ORDER BY rowid";
65 65
         $result = $this->db->query($sql);
66 66
         if ($result)
67 67
         {
68
-            $out.='<select class="flat minwidth100" name="'.$htmlname.'" id="'.$htmlname.'">';
68
+            $out .= '<select class="flat minwidth100" name="'.$htmlname.'" id="'.$htmlname.'">';
69 69
             if ($useempty)
70 70
             {
71
-                $out.='<option value="-1">&nbsp;</option>';
71
+                $out .= '<option value="-1">&nbsp;</option>';
72 72
             }
73 73
 
74 74
             $num = $this->db->num_rows($result);
@@ -78,17 +78,17 @@  discard block
 block discarded – undo
78 78
                 $obj = $this->db->fetch_object($result);
79 79
                 if ($selected == $obj->rowid)
80 80
                 {
81
-                    $out.='<option value="'.$obj->rowid.'" selected>';
81
+                    $out .= '<option value="'.$obj->rowid.'" selected>';
82 82
                 }
83 83
                 else
84 84
                 {
85
-                    $out.='<option value="'.$obj->rowid.'">';
85
+                    $out .= '<option value="'.$obj->rowid.'">';
86 86
                 }
87
-                $out.=$obj->ref;
88
-                $out.='</option>';
87
+                $out .= $obj->ref;
88
+                $out .= '</option>';
89 89
                 $i++;
90 90
             }
91
-            $out.="</select>";
91
+            $out .= "</select>";
92 92
         }
93 93
         else {
94 94
             dol_print_error($this->db);
@@ -107,16 +107,16 @@  discard block
 block discarded – undo
107 107
      *  @param  string  $moreattrib         More attributes on HTML select tag
108 108
      * 	@return	void
109 109
      */
110
-    function selectTypeOfContainer($htmlname, $selected='', $useempty=0, $moreattrib='')
110
+    function selectTypeOfContainer($htmlname, $selected = '', $useempty = 0, $moreattrib = '')
111 111
     {
112 112
     	global $langs, $conf, $user;
113 113
 
114 114
     	$langs->load("admin");
115 115
 
116 116
     	$sql = "SELECT rowid, code, label, entity";
117
-    	$sql.= " FROM ".MAIN_DB_PREFIX.'c_type_container';
118
-    	$sql.= " WHERE active = 1 AND entity IN (".getEntity('c_type_container').")";
119
-    	$sql.= " ORDER BY label";
117
+    	$sql .= " FROM ".MAIN_DB_PREFIX.'c_type_container';
118
+    	$sql .= " WHERE active = 1 AND entity IN (".getEntity('c_type_container').")";
119
+    	$sql .= " ORDER BY label";
120 120
 
121 121
     	dol_syslog(get_class($this)."::selectTypeOfContainer", LOG_DEBUG);
122 122
     	$result = $this->db->query($sql);
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
     		$i = 0;
127 127
     		if ($num)
128 128
     		{
129
-    			print '<select id="select'.$htmlname.'" class="flat selectTypeOfContainer" name="'.$htmlname.'"'.($moreattrib?' '.$moreattrib:'').'>';
129
+    			print '<select id="select'.$htmlname.'" class="flat selectTypeOfContainer" name="'.$htmlname.'"'.($moreattrib ? ' '.$moreattrib : '').'>';
130 130
     			if ($useempty == 1 || ($useempty == 2 && $num > 1))
131 131
     			{
132 132
     				print '<option value="-1">&nbsp;</option>';
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
     				$i++;
149 149
     			}
150 150
     			print "</select>";
151
-    			if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
151
+    			if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
152 152
     		}
153 153
     		else
154 154
     		{
@@ -170,23 +170,23 @@  discard block
 block discarded – undo
170 170
      *  @param  string  $moreattrib         More attributes on HTML select tag
171 171
      * 	@return	void
172 172
      */
173
-    function selectSampleOfContainer($htmlname, $selected='', $useempty=0, $moreattrib='')
173
+    function selectSampleOfContainer($htmlname, $selected = '', $useempty = 0, $moreattrib = '')
174 174
     {
175 175
     	global $langs, $conf, $user;
176 176
 
177 177
     	$langs->load("admin");
178 178
 
179
-    	$arrayofsamples=array('empty'=>'EmptyPage', 'corporatehome'=>'CorporateHomePage');
179
+    	$arrayofsamples = array('empty'=>'EmptyPage', 'corporatehome'=>'CorporateHomePage');
180 180
 
181 181
     	$out = '';
182
-    	$out .= '<select id="select'.$htmlname.'" class="flat selectTypeOfContainer" name="'.$htmlname.'"'.($moreattrib?' '.$moreattrib:'').'>';
182
+    	$out .= '<select id="select'.$htmlname.'" class="flat selectTypeOfContainer" name="'.$htmlname.'"'.($moreattrib ? ' '.$moreattrib : '').'>';
183 183
 
184 184
     	if ($useempty == 1 || $useempty == 2)
185 185
     	{
186 186
     		$out .= '<option value="-1">&nbsp;</option>';
187 187
     	}
188 188
 
189
-    	foreach($arrayofsamples as $key => $val)
189
+    	foreach ($arrayofsamples as $key => $val)
190 190
     	{
191 191
     		if ($selected == $key)
192 192
     		{
Please login to merge, or discard this patch.
dolibarr/htdocs/core/actions_addupdatedelete.inc.php 1 patch
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -32,128 +32,128 @@  discard block
 block discarded – undo
32 32
 
33 33
 if ($cancel)
34 34
 {
35
-	if (! empty($backtopage))
35
+	if (!empty($backtopage))
36 36
 	{
37 37
 		header("Location: ".$backtopage);
38 38
 		exit;
39 39
 	}
40
-	$action='';
40
+	$action = '';
41 41
 }
42 42
 
43 43
 // Action to add record
44
-if ($action == 'add' && ! empty($permissiontoadd))
44
+if ($action == 'add' && !empty($permissiontoadd))
45 45
 {
46 46
 	foreach ($object->fields as $key => $val)
47 47
 	{
48
-		if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat', 'fk_user_modif', 'import_key'))) continue;	// Ignore special fields
48
+		if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat', 'fk_user_modif', 'import_key'))) continue; // Ignore special fields
49 49
 
50 50
 		// Set value to insert
51 51
 		if (in_array($object->fields[$key]['type'], array('text', 'html'))) {
52
-			$value = GETPOST($key,'none');
53
-		} elseif ($object->fields[$key]['type']=='date') {
52
+			$value = GETPOST($key, 'none');
53
+		} elseif ($object->fields[$key]['type'] == 'date') {
54 54
 			$value = dol_mktime(12, 0, 0, GETPOST($key.'month'), GETPOST($key.'day'), GETPOST($key.'year'));
55
-		} elseif ($object->fields[$key]['type']=='datetime') {
55
+		} elseif ($object->fields[$key]['type'] == 'datetime') {
56 56
 			$value = dol_mktime(GETPOST($key.'hour'), GETPOST($key.'min'), 0, GETPOST($key.'month'), GETPOST($key.'day'), GETPOST($key.'year'));
57
-		} elseif ($object->fields[$key]['type']=='price') {
57
+		} elseif ($object->fields[$key]['type'] == 'price') {
58 58
 			$value = price2num(GETPOST($key));
59 59
 		} else {
60
-			$value = GETPOST($key,'alpha');
60
+			$value = GETPOST($key, 'alpha');
61 61
 		}
62
-		if (preg_match('/^integer:/i', $object->fields[$key]['type']) && $value == '-1') $value='';		// This is an implicit foreign key field
63
-		if (! empty($object->fields[$key]['foreignkey']) && $value == '-1') $value='';					// This is an explicit foreign key field
62
+		if (preg_match('/^integer:/i', $object->fields[$key]['type']) && $value == '-1') $value = ''; // This is an implicit foreign key field
63
+		if (!empty($object->fields[$key]['foreignkey']) && $value == '-1') $value = ''; // This is an explicit foreign key field
64 64
 
65
-		$object->$key=$value;
65
+		$object->$key = $value;
66 66
 		if ($val['notnull'] > 0 && $object->$key == '' && is_null($val['default']))
67 67
 		{
68 68
 			$error++;
69
-			setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv($val['label'])), null, 'errors');
69
+			setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv($val['label'])), null, 'errors');
70 70
 		}
71 71
 	}
72 72
 
73
-	if (! $error)
73
+	if (!$error)
74 74
 	{
75
-		$result=$object->create($user);
75
+		$result = $object->create($user);
76 76
 		if ($result > 0)
77 77
 		{
78 78
 			// Creation OK
79
-			$urltogo=$backtopage?str_replace('__ID__', $result, $backtopage):$backurlforlist;
79
+			$urltogo = $backtopage ?str_replace('__ID__', $result, $backtopage) : $backurlforlist;
80 80
 			header("Location: ".$urltogo);
81 81
 			exit;
82 82
 		}
83 83
 		else
84 84
 		{
85 85
 			// Creation KO
86
-			if (! empty($object->errors)) setEventMessages(null, $object->errors, 'errors');
86
+			if (!empty($object->errors)) setEventMessages(null, $object->errors, 'errors');
87 87
 			else  setEventMessages($object->error, null, 'errors');
88
-			$action='create';
88
+			$action = 'create';
89 89
 		}
90 90
 	}
91 91
 	else
92 92
 	{
93
-		$action='create';
93
+		$action = 'create';
94 94
 	}
95 95
 }
96 96
 
97 97
 // Action to update record
98
-if ($action == 'update' && ! empty($permissiontoadd))
98
+if ($action == 'update' && !empty($permissiontoadd))
99 99
 {
100 100
 	foreach ($object->fields as $key => $val)
101 101
 	{
102
-		if (! GETPOSTISSET($key)) continue;		// The field was not submited to be edited
103
-		if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat', 'fk_user_modif', 'import_key'))) continue;	// Ignore special fields
102
+		if (!GETPOSTISSET($key)) continue; // The field was not submited to be edited
103
+		if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat', 'fk_user_modif', 'import_key'))) continue; // Ignore special fields
104 104
 
105 105
 		// Set value to update
106 106
 		if (in_array($object->fields[$key]['type'], array('text', 'html'))) {
107
-			$value = GETPOST($key,'none');
108
-		} elseif ($object->fields[$key]['type']=='date') {
107
+			$value = GETPOST($key, 'none');
108
+		} elseif ($object->fields[$key]['type'] == 'date') {
109 109
 			$value = dol_mktime(12, 0, 0, GETPOST($key.'month'), GETPOST($key.'day'), GETPOST($key.'year'));
110
-		} elseif ($object->fields[$key]['type']=='datetime') {
110
+		} elseif ($object->fields[$key]['type'] == 'datetime') {
111 111
 			$value = dol_mktime(GETPOST($key.'hour'), GETPOST($key.'min'), 0, GETPOST($key.'month'), GETPOST($key.'day'), GETPOST($key.'year'));
112
-		} elseif ($object->fields[$key]['type']=='price') {
112
+		} elseif ($object->fields[$key]['type'] == 'price') {
113 113
 			$value = price2num(GETPOST($key));
114 114
 		} else {
115
-			$value = GETPOST($key,'alpha');
115
+			$value = GETPOST($key, 'alpha');
116 116
 		}
117
-		if (preg_match('/^integer:/i', $object->fields[$key]['type']) && $value == '-1') $value='';		// This is an implicit foreign key field
118
-		if (! empty($object->fields[$key]['foreignkey']) && $value == '-1') $value='';					// This is an explicit foreign key field
117
+		if (preg_match('/^integer:/i', $object->fields[$key]['type']) && $value == '-1') $value = ''; // This is an implicit foreign key field
118
+		if (!empty($object->fields[$key]['foreignkey']) && $value == '-1') $value = ''; // This is an explicit foreign key field
119 119
 
120
-		$object->$key=$value;
120
+		$object->$key = $value;
121 121
 		if ($val['notnull'] > 0 && $object->$key == '' && is_null($val['default']))
122 122
 		{
123 123
 			$error++;
124
-			setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv($val['label'])), null, 'errors');
124
+			setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv($val['label'])), null, 'errors');
125 125
 		}
126 126
 	}
127 127
 
128
-	if (! $error)
128
+	if (!$error)
129 129
 	{
130
-		$result=$object->update($user);
130
+		$result = $object->update($user);
131 131
 		if ($result > 0)
132 132
 		{
133
-			$action='view';
133
+			$action = 'view';
134 134
 		}
135 135
 		else
136 136
 		{
137 137
 			// Creation KO
138 138
 			setEventMessages($object->error, $object->errors, 'errors');
139
-			$action='edit';
139
+			$action = 'edit';
140 140
 		}
141 141
 	}
142 142
 	else
143 143
 	{
144
-		$action='edit';
144
+		$action = 'edit';
145 145
 	}
146 146
 }
147 147
 
148 148
 // Action to update one extrafield
149
-if ($action == "update_extras" && ! empty($permissiontoadd))
149
+if ($action == "update_extras" && !empty($permissiontoadd))
150 150
 {
151
-	$object->fetch(GETPOST('id','int'));
152
-	$attributekey = GETPOST('attribute','alpha');
151
+	$object->fetch(GETPOST('id', 'int'));
152
+	$attributekey = GETPOST('attribute', 'alpha');
153 153
 	$attributekeylong = 'options_'.$attributekey;
154
-	$object->array_options['options_'.$attributekey] = GETPOST($attributekeylong,' alpha');
154
+	$object->array_options['options_'.$attributekey] = GETPOST($attributekeylong, ' alpha');
155 155
 
156
-	$result = $object->insertExtraFields(empty($triggermodname)?'':$triggermodname, $user);
156
+	$result = $object->insertExtraFields(empty($triggermodname) ? '' : $triggermodname, $user);
157 157
 	if ($result > 0)
158 158
 	{
159 159
 		setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
@@ -167,9 +167,9 @@  discard block
 block discarded – undo
167 167
 }
168 168
 
169 169
 // Action to delete
170
-if ($action == 'confirm_delete' && ! empty($permissiontodelete))
170
+if ($action == 'confirm_delete' && !empty($permissiontodelete))
171 171
 {
172
-	$result=$object->delete($user);
172
+	$result = $object->delete($user);
173 173
 	if ($result > 0)
174 174
 	{
175 175
 		// Delete OK
@@ -179,15 +179,15 @@  discard block
 block discarded – undo
179 179
 	}
180 180
 	else
181 181
 	{
182
-		if (! empty($object->errors)) setEventMessages(null, $object->errors, 'errors');
182
+		if (!empty($object->errors)) setEventMessages(null, $object->errors, 'errors');
183 183
 		else setEventMessages($object->error, null, 'errors');
184 184
 	}
185 185
 }
186 186
 
187 187
 // Action clone object
188
-if ($action == 'confirm_clone' && $confirm == 'yes' && ! empty($permissiontoadd))
188
+if ($action == 'confirm_clone' && $confirm == 'yes' && !empty($permissiontoadd))
189 189
 {
190
-	if (1==0 && ! GETPOST('clone_content') && ! GETPOST('clone_receivers'))
190
+	if (1 == 0 && !GETPOST('clone_content') && !GETPOST('clone_receivers'))
191 191
 	{
192 192
 		setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors');
193 193
 	}
@@ -198,20 +198,20 @@  discard block
 block discarded – undo
198 198
 			// Because createFromClone modifies the object, we must clone it so that we can restore it later
199 199
 			$orig = clone $object;
200 200
 
201
-			$result=$object->createFromClone($user, $object->id);
201
+			$result = $object->createFromClone($user, $object->id);
202 202
 			if ($result > 0)
203 203
 			{
204 204
 				$newid = 0;
205 205
 				if (is_object($result)) $newid = $result->id;
206 206
 				else $newid = $result;
207
-				header("Location: ".$_SERVER['PHP_SELF'].'?id='.$newid);	// Open record of new object
207
+				header("Location: ".$_SERVER['PHP_SELF'].'?id='.$newid); // Open record of new object
208 208
 				exit;
209 209
 			}
210 210
 			else
211 211
 			{
212 212
 				setEventMessages($object->error, $object->errors, 'errors');
213 213
 				$object = $orig;
214
-				$action='';
214
+				$action = '';
215 215
 			}
216 216
 		}
217 217
 	}
Please login to merge, or discard this patch.