Test Failed
Branch develop (86e751)
by Laurent
34:11
created
htdocs/core/class/utils.class.php 3 patches
Indentation   +231 added lines, -231 removed lines patch added patch discarded remove patch
@@ -90,10 +90,10 @@  discard block
 block discarded – undo
90 90
 
91 91
 		if ($choice=='logfile')
92 92
 		{
93
-		    // Define files log
93
+			// Define files log
94 94
 			if ($dolibarr_main_data_root)
95 95
 			{
96
-                $filesarray=dol_dir_list($dolibarr_main_data_root, "files", 0, '.*\.log[\.0-9]*$', 'install\.lock$');
96
+				$filesarray=dol_dir_list($dolibarr_main_data_root, "files", 0, '.*\.log[\.0-9]*$', 'install\.lock$');
97 97
 			}
98 98
 
99 99
 			$filelog='';
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 				$alreadyincluded=false;
106 106
 				foreach ($filesarray as $tmpcursor)
107 107
 				{
108
-				    if ($tmpcursor['fullname'] == $filelog) { $alreadyincluded=true; }
108
+					if ($tmpcursor['fullname'] == $filelog) { $alreadyincluded=true; }
109 109
 				}
110 110
 				if (! $alreadyincluded) $filesarray[]=array('fullname'=>$filelog,'type'=>'file');
111 111
 			}
@@ -121,24 +121,24 @@  discard block
 block discarded – undo
121 121
 				//print "x ".$filesarray[$key]['fullname']."-".$filesarray[$key]['type']."<br>\n";
122 122
 				if ($filesarray[$key]['type'] == 'dir')
123 123
 				{
124
-				    $startcount=0;
125
-				    $tmpcountdeleted=0;
124
+					$startcount=0;
125
+					$tmpcountdeleted=0;
126 126
 					$result=dol_delete_dir_recursive($filesarray[$key]['fullname'], $startcount, 1, 0, $tmpcountdeleted);
127
-				    $count+=$result;
128
-				    $countdeleted+=$tmpcountdeleted;
127
+					$count+=$result;
128
+					$countdeleted+=$tmpcountdeleted;
129 129
 				}
130 130
 				elseif ($filesarray[$key]['type'] == 'file')
131 131
 				{
132 132
 					// If (file that is not logfile) or (if logfile with option logfile)
133 133
 					if ($filesarray[$key]['fullname'] != $filelog || $choice=='logfile')
134 134
 					{
135
-					    $result=dol_delete_file($filesarray[$key]['fullname'], 1, 1);
136
-					    if ($result)
137
-					    {
138
-					        $count++;
139
-					        $countdeleted++;
140
-					    }
141
-					    else $counterror++;
135
+						$result=dol_delete_file($filesarray[$key]['fullname'], 1, 1);
136
+						if ($result)
137
+						{
138
+							$count++;
139
+							$countdeleted++;
140
+						}
141
+						else $counterror++;
142 142
 					}
143 143
 				}
144 144
 			}
@@ -154,8 +154,8 @@  discard block
 block discarded – undo
154 154
 
155 155
 		if ($count > 0)
156 156
 		{
157
-		    $this->output=$langs->trans("PurgeNDirectoriesDeleted", $countdeleted);
158
-		    if ($count > $countdeleted) $this->output.='<br>'.$langs->trans("PurgeNDirectoriesFailed", ($count - $countdeleted));
157
+			$this->output=$langs->trans("PurgeNDirectoriesDeleted", $countdeleted);
158
+			if ($count > $countdeleted) $this->output.='<br>'.$langs->trans("PurgeNDirectoriesFailed", ($count - $countdeleted));
159 159
 		}
160 160
 		else $this->output=$langs->trans("PurgeNothingToDelete").($choice == 'tempfilesold' ? ' (older than 24h)':'');
161 161
 
@@ -189,29 +189,29 @@  discard block
 block discarded – undo
189 189
 		// Check compression parameter
190 190
 		if (! in_array($compression, array('none', 'gz', 'bz', 'zip')))
191 191
 		{
192
-		    $langs->load("errors");
193
-		    $this->error=$langs->transnoentitiesnoconv("ErrorBadValueForParameter", $compression, "Compression");
194
-		    return -1;
192
+			$langs->load("errors");
193
+			$this->error=$langs->transnoentitiesnoconv("ErrorBadValueForParameter", $compression, "Compression");
194
+			return -1;
195 195
 		}
196 196
 
197 197
 		// Check type parameter
198 198
 		if ($type == 'auto') $type = $db->type;
199 199
 		if (! in_array($type, array('pgsql', 'mysql', 'mysqli','mysqlnobin')))
200 200
 		{
201
-		    $langs->load("errors");
202
-		    $this->error=$langs->transnoentitiesnoconv("ErrorBadValueForParameter", $type, "Basetype");
203
-		    return -1;
201
+			$langs->load("errors");
202
+			$this->error=$langs->transnoentitiesnoconv("ErrorBadValueForParameter", $type, "Basetype");
203
+			return -1;
204 204
 		}
205 205
 
206 206
 		// Check file parameter
207 207
 		if ($file == 'auto')
208 208
 		{
209
-		    $prefix='dump';
210
-		    $ext='.sql';
211
-		    if (in_array($type, array('mysql', 'mysqli')))  { $prefix='mysqldump'; $ext='sql'; }
212
-		    //if ($label == 'PostgreSQL') { $prefix='pg_dump'; $ext='dump'; }
213
-		    if (in_array($type, array('pgsql'))) { $prefix='pg_dump'; $ext='sql'; }
214
-		    $file=$prefix.'_'.$dolibarr_main_db_name.'_'.dol_sanitizeFileName(DOL_VERSION).'_'.strftime("%Y%m%d%H%M").'.'.$ext;
209
+			$prefix='dump';
210
+			$ext='.sql';
211
+			if (in_array($type, array('mysql', 'mysqli')))  { $prefix='mysqldump'; $ext='sql'; }
212
+			//if ($label == 'PostgreSQL') { $prefix='pg_dump'; $ext='dump'; }
213
+			if (in_array($type, array('pgsql'))) { $prefix='pg_dump'; $ext='sql'; }
214
+			$file=$prefix.'_'.$dolibarr_main_db_name.'_'.dol_sanitizeFileName(DOL_VERSION).'_'.strftime("%Y%m%d%H%M").'.'.$ext;
215 215
 		}
216 216
 
217 217
 		$outputdir  = $conf->admin->dir_output.'/backup';
@@ -221,229 +221,229 @@  discard block
 block discarded – undo
221 221
 		// MYSQL
222 222
 		if ($type == 'mysql' || $type == 'mysqli')
223 223
 		{
224
-		    $cmddump=$conf->global->SYSTEMTOOLS_MYSQLDUMP;
225
-
226
-
227
-		    $outputfile = $outputdir.'/'.$file;
228
-		    // for compression format, we add extension
229
-		    $compression=$compression ? $compression : 'none';
230
-		    if ($compression == 'gz') $outputfile.='.gz';
231
-		    if ($compression == 'bz') $outputfile.='.bz2';
232
-		    $outputerror = $outputfile.'.err';
233
-		    dol_mkdir($conf->admin->dir_output.'/backup');
234
-
235
-		    // Parameteres execution
236
-		    $command=$cmddump;
237
-		    if (preg_match("/\s/",$command)) $command=escapeshellarg($command);	// Use quotes on command
238
-
239
-		    //$param=escapeshellarg($dolibarr_main_db_name)." -h ".escapeshellarg($dolibarr_main_db_host)." -u ".escapeshellarg($dolibarr_main_db_user)." -p".escapeshellarg($dolibarr_main_db_pass);
240
-		    $param=$dolibarr_main_db_name." -h ".$dolibarr_main_db_host;
241
-		    $param.=" -u ".$dolibarr_main_db_user;
242
-		    if (! empty($dolibarr_main_db_port)) $param.=" -P ".$dolibarr_main_db_port;
243
-		    if (! GETPOST("use_transaction"))    $param.=" -l --single-transaction";
244
-		    if (GETPOST("disable_fk") || $usedefault) $param.=" -K";
245
-		    if (GETPOST("sql_compat") && GETPOST("sql_compat") != 'NONE') $param.=" --compatible=".escapeshellarg(GETPOST("sql_compat","alpha"));
246
-		    if (GETPOST("drop_database"))        $param.=" --add-drop-database";
247
-		    if (GETPOST("sql_structure") || $usedefault)
248
-		    {
249
-		        if (GETPOST("drop") || $usedefault)	$param.=" --add-drop-table=TRUE";
250
-		        else 							    $param.=" --add-drop-table=FALSE";
251
-		    }
252
-		    else
253
-		    {
254
-		        $param.=" -t";
255
-		    }
256
-		    if (GETPOST("disable-add-locks")) $param.=" --add-locks=FALSE";
257
-		    if (GETPOST("sql_data") || $usedefault)
258
-		    {
259
-		        $param.=" --tables";
260
-		        if (GETPOST("showcolumns") || $usedefault)	 $param.=" -c";
261
-		        if (GETPOST("extended_ins") || $usedefault) $param.=" -e";
262
-		        else $param.=" --skip-extended-insert";
263
-		        if (GETPOST("delayed"))	 	 $param.=" --delayed-insert";
264
-		        if (GETPOST("sql_ignore"))	 $param.=" --insert-ignore";
265
-		        if (GETPOST("hexforbinary") || $usedefault) $param.=" --hex-blob";
266
-		    }
267
-		    else
268
-		    {
269
-		        $param.=" -d";    // No row information (no data)
270
-		    }
271
-		    $param.=" --default-character-set=utf8";    // We always save output into utf8 charset
272
-		    $paramcrypted=$param;
273
-		    $paramclear=$param;
274
-		    if (! empty($dolibarr_main_db_pass))
275
-		    {
276
-		        $paramcrypted.=' -p"'.preg_replace('/./i','*',$dolibarr_main_db_pass).'"';
277
-		        $paramclear.=' -p"'.str_replace(array('"','`'),array('\"','\`'),$dolibarr_main_db_pass).'"';
278
-		    }
279
-
280
-		    $errormsg='';
281
-
282
-		    // Debut appel methode execution
283
-		    $fullcommandcrypted=$command." ".$paramcrypted." 2>&1";
284
-		    $fullcommandclear=$command." ".$paramclear." 2>&1";
285
-		    if ($compression == 'none') $handle = fopen($outputfile, 'w');
286
-		    if ($compression == 'gz')   $handle = gzopen($outputfile, 'w');
287
-		    if ($compression == 'bz')   $handle = bzopen($outputfile, 'w');
288
-
289
-		    if ($handle)
290
-		    {
291
-		        $ok=0;
292
-		        dol_syslog("Run command ".$fullcommandcrypted);
293
-		        $handlein = popen($fullcommandclear, 'r');
294
-		        $i=0;
295
-		        while (!feof($handlein))
296
-		        {
297
-		            $i++;   // output line number
298
-		            $read = fgets($handlein);
299
-		            // Exclude warning line we don't want
300
-		            if ($i == 1 && preg_match('/Warning.*Using a password/i', $read)) continue;
301
-		            fwrite($handle,$read);
302
-		            if (preg_match('/'.preg_quote('-- Dump completed').'/i',$read)) $ok=1;
303
-		            elseif (preg_match('/'.preg_quote('SET SQL_NOTES=@OLD_SQL_NOTES').'/i',$read)) $ok=1;
304
-		        }
305
-		        pclose($handlein);
306
-
307
-		        if ($compression == 'none') fclose($handle);
308
-		        if ($compression == 'gz')   gzclose($handle);
309
-		        if ($compression == 'bz')   bzclose($handle);
310
-
311
-		        if (! empty($conf->global->MAIN_UMASK))
312
-		            @chmod($outputfile, octdec($conf->global->MAIN_UMASK));
313
-		    }
314
-		    else
315
-		    {
316
-		        $langs->load("errors");
317
-		        dol_syslog("Failed to open file ".$outputfile,LOG_ERR);
318
-		        $errormsg=$langs->trans("ErrorFailedToWriteInDir");
319
-		    }
320
-
321
-		    // Get errorstring
322
-		    if ($compression == 'none') $handle = fopen($outputfile, 'r');
323
-		    if ($compression == 'gz')   $handle = gzopen($outputfile, 'r');
324
-		    if ($compression == 'bz')   $handle = bzopen($outputfile, 'r');
325
-		    if ($handle)
326
-		    {
327
-		        // Get 2048 first chars of error message.
328
-		        $errormsg = fgets($handle,2048);
329
-		        // Close file
330
-		        if ($compression == 'none') fclose($handle);
331
-		        if ($compression == 'gz')   gzclose($handle);
332
-		        if ($compression == 'bz')   bzclose($handle);
333
-		        if ($ok && preg_match('/^-- MySql/i',$errormsg)) $errormsg='';	// Pas erreur
334
-		        else
335
-		        {
336
-		            // Renommer fichier sortie en fichier erreur
337
-		            //print "$outputfile -> $outputerror";
338
-		            @dol_delete_file($outputerror,1);
339
-		            @rename($outputfile,$outputerror);
340
-		            // Si safe_mode on et command hors du parametre exec, on a un fichier out vide donc errormsg vide
341
-		            if (! $errormsg)
342
-		            {
343
-		                $langs->load("errors");
344
-		                $errormsg=$langs->trans("ErrorFailedToRunExternalCommand");
345
-		            }
346
-		        }
347
-		    }
348
-		    // Fin execution commande
349
-
350
-		    $this->output = $errormsg;
351
-		    $this->error = $errormsg;
352
-		    $this->result = array("commandbackuplastdone" => $command." ".$paramcrypted, "commandbackuptorun" => "");
353
-		    //if (empty($this->output)) $this->output=$this->result['commandbackuplastdone'];
224
+			$cmddump=$conf->global->SYSTEMTOOLS_MYSQLDUMP;
225
+
226
+
227
+			$outputfile = $outputdir.'/'.$file;
228
+			// for compression format, we add extension
229
+			$compression=$compression ? $compression : 'none';
230
+			if ($compression == 'gz') $outputfile.='.gz';
231
+			if ($compression == 'bz') $outputfile.='.bz2';
232
+			$outputerror = $outputfile.'.err';
233
+			dol_mkdir($conf->admin->dir_output.'/backup');
234
+
235
+			// Parameteres execution
236
+			$command=$cmddump;
237
+			if (preg_match("/\s/",$command)) $command=escapeshellarg($command);	// Use quotes on command
238
+
239
+			//$param=escapeshellarg($dolibarr_main_db_name)." -h ".escapeshellarg($dolibarr_main_db_host)." -u ".escapeshellarg($dolibarr_main_db_user)." -p".escapeshellarg($dolibarr_main_db_pass);
240
+			$param=$dolibarr_main_db_name." -h ".$dolibarr_main_db_host;
241
+			$param.=" -u ".$dolibarr_main_db_user;
242
+			if (! empty($dolibarr_main_db_port)) $param.=" -P ".$dolibarr_main_db_port;
243
+			if (! GETPOST("use_transaction"))    $param.=" -l --single-transaction";
244
+			if (GETPOST("disable_fk") || $usedefault) $param.=" -K";
245
+			if (GETPOST("sql_compat") && GETPOST("sql_compat") != 'NONE') $param.=" --compatible=".escapeshellarg(GETPOST("sql_compat","alpha"));
246
+			if (GETPOST("drop_database"))        $param.=" --add-drop-database";
247
+			if (GETPOST("sql_structure") || $usedefault)
248
+			{
249
+				if (GETPOST("drop") || $usedefault)	$param.=" --add-drop-table=TRUE";
250
+				else 							    $param.=" --add-drop-table=FALSE";
251
+			}
252
+			else
253
+			{
254
+				$param.=" -t";
255
+			}
256
+			if (GETPOST("disable-add-locks")) $param.=" --add-locks=FALSE";
257
+			if (GETPOST("sql_data") || $usedefault)
258
+			{
259
+				$param.=" --tables";
260
+				if (GETPOST("showcolumns") || $usedefault)	 $param.=" -c";
261
+				if (GETPOST("extended_ins") || $usedefault) $param.=" -e";
262
+				else $param.=" --skip-extended-insert";
263
+				if (GETPOST("delayed"))	 	 $param.=" --delayed-insert";
264
+				if (GETPOST("sql_ignore"))	 $param.=" --insert-ignore";
265
+				if (GETPOST("hexforbinary") || $usedefault) $param.=" --hex-blob";
266
+			}
267
+			else
268
+			{
269
+				$param.=" -d";    // No row information (no data)
270
+			}
271
+			$param.=" --default-character-set=utf8";    // We always save output into utf8 charset
272
+			$paramcrypted=$param;
273
+			$paramclear=$param;
274
+			if (! empty($dolibarr_main_db_pass))
275
+			{
276
+				$paramcrypted.=' -p"'.preg_replace('/./i','*',$dolibarr_main_db_pass).'"';
277
+				$paramclear.=' -p"'.str_replace(array('"','`'),array('\"','\`'),$dolibarr_main_db_pass).'"';
278
+			}
279
+
280
+			$errormsg='';
281
+
282
+			// Debut appel methode execution
283
+			$fullcommandcrypted=$command." ".$paramcrypted." 2>&1";
284
+			$fullcommandclear=$command." ".$paramclear." 2>&1";
285
+			if ($compression == 'none') $handle = fopen($outputfile, 'w');
286
+			if ($compression == 'gz')   $handle = gzopen($outputfile, 'w');
287
+			if ($compression == 'bz')   $handle = bzopen($outputfile, 'w');
288
+
289
+			if ($handle)
290
+			{
291
+				$ok=0;
292
+				dol_syslog("Run command ".$fullcommandcrypted);
293
+				$handlein = popen($fullcommandclear, 'r');
294
+				$i=0;
295
+				while (!feof($handlein))
296
+				{
297
+					$i++;   // output line number
298
+					$read = fgets($handlein);
299
+					// Exclude warning line we don't want
300
+					if ($i == 1 && preg_match('/Warning.*Using a password/i', $read)) continue;
301
+					fwrite($handle,$read);
302
+					if (preg_match('/'.preg_quote('-- Dump completed').'/i',$read)) $ok=1;
303
+					elseif (preg_match('/'.preg_quote('SET SQL_NOTES=@OLD_SQL_NOTES').'/i',$read)) $ok=1;
304
+				}
305
+				pclose($handlein);
306
+
307
+				if ($compression == 'none') fclose($handle);
308
+				if ($compression == 'gz')   gzclose($handle);
309
+				if ($compression == 'bz')   bzclose($handle);
310
+
311
+				if (! empty($conf->global->MAIN_UMASK))
312
+					@chmod($outputfile, octdec($conf->global->MAIN_UMASK));
313
+			}
314
+			else
315
+			{
316
+				$langs->load("errors");
317
+				dol_syslog("Failed to open file ".$outputfile,LOG_ERR);
318
+				$errormsg=$langs->trans("ErrorFailedToWriteInDir");
319
+			}
320
+
321
+			// Get errorstring
322
+			if ($compression == 'none') $handle = fopen($outputfile, 'r');
323
+			if ($compression == 'gz')   $handle = gzopen($outputfile, 'r');
324
+			if ($compression == 'bz')   $handle = bzopen($outputfile, 'r');
325
+			if ($handle)
326
+			{
327
+				// Get 2048 first chars of error message.
328
+				$errormsg = fgets($handle,2048);
329
+				// Close file
330
+				if ($compression == 'none') fclose($handle);
331
+				if ($compression == 'gz')   gzclose($handle);
332
+				if ($compression == 'bz')   bzclose($handle);
333
+				if ($ok && preg_match('/^-- MySql/i',$errormsg)) $errormsg='';	// Pas erreur
334
+				else
335
+				{
336
+					// Renommer fichier sortie en fichier erreur
337
+					//print "$outputfile -> $outputerror";
338
+					@dol_delete_file($outputerror,1);
339
+					@rename($outputfile,$outputerror);
340
+					// Si safe_mode on et command hors du parametre exec, on a un fichier out vide donc errormsg vide
341
+					if (! $errormsg)
342
+					{
343
+						$langs->load("errors");
344
+						$errormsg=$langs->trans("ErrorFailedToRunExternalCommand");
345
+					}
346
+				}
347
+			}
348
+			// Fin execution commande
349
+
350
+			$this->output = $errormsg;
351
+			$this->error = $errormsg;
352
+			$this->result = array("commandbackuplastdone" => $command." ".$paramcrypted, "commandbackuptorun" => "");
353
+			//if (empty($this->output)) $this->output=$this->result['commandbackuplastdone'];
354 354
 		}
355 355
 
356 356
 		// MYSQL NO BIN
357 357
 		if ($type == 'mysqlnobin')
358 358
 		{
359
-		    $outputfile = $outputdir.'/'.$file;
360
-		    $outputfiletemp = $outputfile.'-TMP.sql';
361
-		    // for compression format, we add extension
362
-		    $compression=$compression ? $compression : 'none';
363
-		    if ($compression == 'gz') $outputfile.='.gz';
364
-		    if ($compression == 'bz') $outputfile.='.bz2';
365
-		    $outputerror = $outputfile.'.err';
366
-		    dol_mkdir($conf->admin->dir_output.'/backup');
367
-
368
-		    if ($compression == 'gz' or $compression == 'bz')
369
-		    {
370
-		        backup_tables($outputfiletemp);
371
-		        dol_compress_file($outputfiletemp, $outputfile, $compression);
372
-		        unlink($outputfiletemp);
373
-		    }
374
-		    else
375
-		    {
376
-		        backup_tables($outputfile);
377
-		    }
378
-
379
-		    $this->output = "";
380
-		    $this->result = array("commandbackuplastdone" => "", "commandbackuptorun" => "");
359
+			$outputfile = $outputdir.'/'.$file;
360
+			$outputfiletemp = $outputfile.'-TMP.sql';
361
+			// for compression format, we add extension
362
+			$compression=$compression ? $compression : 'none';
363
+			if ($compression == 'gz') $outputfile.='.gz';
364
+			if ($compression == 'bz') $outputfile.='.bz2';
365
+			$outputerror = $outputfile.'.err';
366
+			dol_mkdir($conf->admin->dir_output.'/backup');
367
+
368
+			if ($compression == 'gz' or $compression == 'bz')
369
+			{
370
+				backup_tables($outputfiletemp);
371
+				dol_compress_file($outputfiletemp, $outputfile, $compression);
372
+				unlink($outputfiletemp);
373
+			}
374
+			else
375
+			{
376
+				backup_tables($outputfile);
377
+			}
378
+
379
+			$this->output = "";
380
+			$this->result = array("commandbackuplastdone" => "", "commandbackuptorun" => "");
381 381
 		}
382 382
 
383 383
 		// POSTGRESQL
384 384
 		if ($type == 'postgresql')
385 385
 		{
386
-		    $cmddump=$conf->global->SYSTEMTOOLS_POSTGRESQLDUMP;
387
-
388
-		    $outputfile = $outputdir.'/'.$file;
389
-		    // for compression format, we add extension
390
-		    $compression=$compression ? $compression : 'none';
391
-		    if ($compression == 'gz') $outputfile.='.gz';
392
-		    if ($compression == 'bz') $outputfile.='.bz2';
393
-		    $outputerror = $outputfile.'.err';
394
-		    dol_mkdir($conf->admin->dir_output.'/backup');
395
-
396
-		    // Parameteres execution
397
-		    $command=$cmddump;
398
-		    if (preg_match("/\s/",$command)) $command=escapeshellarg($command);	// Use quotes on command
399
-
400
-		    //$param=escapeshellarg($dolibarr_main_db_name)." -h ".escapeshellarg($dolibarr_main_db_host)." -u ".escapeshellarg($dolibarr_main_db_user)." -p".escapeshellarg($dolibarr_main_db_pass);
401
-		    //$param="-F c";
402
-		    $param="-F p";
403
-		    $param.=" --no-tablespaces --inserts -h ".$dolibarr_main_db_host;
404
-		    $param.=" -U ".$dolibarr_main_db_user;
405
-		    if (! empty($dolibarr_main_db_port)) $param.=" -p ".$dolibarr_main_db_port;
406
-		    if (GETPOST("sql_compat") && GETPOST("sql_compat") == 'ANSI') $param.="  --disable-dollar-quoting";
407
-		    if (GETPOST("drop_database"))        $param.=" -c -C";
408
-		    if (GETPOST("sql_structure"))
409
-		    {
410
-		        if (GETPOST("drop"))			 $param.=" --add-drop-table";
411
-		        if (! GETPOST("sql_data"))       $param.=" -s";
412
-		    }
413
-		    if (GETPOST("sql_data"))
414
-		    {
415
-		        if (! GETPOST("sql_structure"))	 $param.=" -a";
416
-		        if (GETPOST("showcolumns"))	     $param.=" -c";
417
-		    }
418
-		    $param.=' -f "'.$outputfile.'"';
419
-		    //if ($compression == 'none')
420
-		    if ($compression == 'gz')   $param.=' -Z 9';
421
-		    //if ($compression == 'bz')
422
-		    $paramcrypted=$param;
423
-		    $paramclear=$param;
424
-		    /*if (! empty($dolibarr_main_db_pass))
386
+			$cmddump=$conf->global->SYSTEMTOOLS_POSTGRESQLDUMP;
387
+
388
+			$outputfile = $outputdir.'/'.$file;
389
+			// for compression format, we add extension
390
+			$compression=$compression ? $compression : 'none';
391
+			if ($compression == 'gz') $outputfile.='.gz';
392
+			if ($compression == 'bz') $outputfile.='.bz2';
393
+			$outputerror = $outputfile.'.err';
394
+			dol_mkdir($conf->admin->dir_output.'/backup');
395
+
396
+			// Parameteres execution
397
+			$command=$cmddump;
398
+			if (preg_match("/\s/",$command)) $command=escapeshellarg($command);	// Use quotes on command
399
+
400
+			//$param=escapeshellarg($dolibarr_main_db_name)." -h ".escapeshellarg($dolibarr_main_db_host)." -u ".escapeshellarg($dolibarr_main_db_user)." -p".escapeshellarg($dolibarr_main_db_pass);
401
+			//$param="-F c";
402
+			$param="-F p";
403
+			$param.=" --no-tablespaces --inserts -h ".$dolibarr_main_db_host;
404
+			$param.=" -U ".$dolibarr_main_db_user;
405
+			if (! empty($dolibarr_main_db_port)) $param.=" -p ".$dolibarr_main_db_port;
406
+			if (GETPOST("sql_compat") && GETPOST("sql_compat") == 'ANSI') $param.="  --disable-dollar-quoting";
407
+			if (GETPOST("drop_database"))        $param.=" -c -C";
408
+			if (GETPOST("sql_structure"))
409
+			{
410
+				if (GETPOST("drop"))			 $param.=" --add-drop-table";
411
+				if (! GETPOST("sql_data"))       $param.=" -s";
412
+			}
413
+			if (GETPOST("sql_data"))
414
+			{
415
+				if (! GETPOST("sql_structure"))	 $param.=" -a";
416
+				if (GETPOST("showcolumns"))	     $param.=" -c";
417
+			}
418
+			$param.=' -f "'.$outputfile.'"';
419
+			//if ($compression == 'none')
420
+			if ($compression == 'gz')   $param.=' -Z 9';
421
+			//if ($compression == 'bz')
422
+			$paramcrypted=$param;
423
+			$paramclear=$param;
424
+			/*if (! empty($dolibarr_main_db_pass))
425 425
 		     {
426 426
 		     $paramcrypted.=" -W".preg_replace('/./i','*',$dolibarr_main_db_pass);
427 427
 		     $paramclear.=" -W".$dolibarr_main_db_pass;
428 428
 		     }*/
429
-		    $paramcrypted.=" -w ".$dolibarr_main_db_name;
430
-		    $paramclear.=" -w ".$dolibarr_main_db_name;
429
+			$paramcrypted.=" -w ".$dolibarr_main_db_name;
430
+			$paramclear.=" -w ".$dolibarr_main_db_name;
431 431
 
432
-		    $this->output = "";
433
-		    $this->result = array("commandbackuplastdone" => "", "commandbackuptorun" => $command." ".$paramcrypted);
432
+			$this->output = "";
433
+			$this->result = array("commandbackuplastdone" => "", "commandbackuptorun" => $command." ".$paramcrypted);
434 434
 		}
435 435
 
436 436
 		// Clean old files
437 437
 		if ($keeplastnfiles > 0)
438 438
 		{
439
-		    $tmpfiles = dol_dir_list($conf->admin->dir_output.'/backup', 'files', 0, '', '(\.err|\.old|\.sav)$', 'date', SORT_DESC);
440
-		    $i=0;
441
-		    foreach($tmpfiles as $key => $val)
442
-		    {
443
-		        $i++;
444
-		        if ($i <= $keeplastnfiles) continue;
445
-		        dol_delete_file($val['fullname']);
446
-		    }
439
+			$tmpfiles = dol_dir_list($conf->admin->dir_output.'/backup', 'files', 0, '', '(\.err|\.old|\.sav)$', 'date', SORT_DESC);
440
+			$i=0;
441
+			foreach($tmpfiles as $key => $val)
442
+			{
443
+				$i++;
444
+				if ($i <= $keeplastnfiles) continue;
445
+				dol_delete_file($val['fullname']);
446
+			}
447 447
 		}
448 448
 
449 449
 
Please login to merge, or discard this patch.
Spacing   +124 added lines, -124 removed lines patch added patch discarded remove patch
@@ -29,8 +29,8 @@  discard block
 block discarded – undo
29 29
 {
30 30
 	var $db;
31 31
 
32
-	var $output;   // Used by Cron method to return message
33
-	var $result;   // Used by Cron method to return data
32
+	var $output; // Used by Cron method to return message
33
+	var $result; // Used by Cron method to return data
34 34
 
35 35
 	/**
36 36
 	 *	Constructor
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 	 *  @param	string		$choice		Choice of purge mode ('tempfiles', 'tempfilesold' to purge temp older than 24h, 'allfiles', 'logfile')
51 51
 	 *  @return	int						0 if OK, < 0 if KO (this function is used also by cron so only 0 is OK)
52 52
 	 */
53
-	function purgeFiles($choice='tempfilesold')
53
+	function purgeFiles($choice = 'tempfilesold')
54 54
 	{
55 55
 		global $conf, $langs, $dolibarr_main_data_root;
56 56
 
@@ -59,80 +59,80 @@  discard block
 block discarded – undo
59 59
 		dol_syslog("Utils::purgeFiles choice=".$choice, LOG_DEBUG);
60 60
 		require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
61 61
 
62
-		$filesarray=array();
63
-		if (empty($choice)) $choice='tempfilesold';
62
+		$filesarray = array();
63
+		if (empty($choice)) $choice = 'tempfilesold';
64 64
 
65
-		if ($choice=='tempfiles' || $choice=='tempfilesold')
65
+		if ($choice == 'tempfiles' || $choice == 'tempfilesold')
66 66
 		{
67 67
 			// Delete temporary files
68 68
 			if ($dolibarr_main_data_root)
69 69
 			{
70
-				$filesarray=dol_dir_list($dolibarr_main_data_root,"directories",1,'^temp$','','','',2);
70
+				$filesarray = dol_dir_list($dolibarr_main_data_root, "directories", 1, '^temp$', '', '', '', 2);
71 71
 				if ($choice == 'tempfilesold')
72 72
 				{
73 73
 					$now = dol_now();
74
-					foreach($filesarray as $key => $val)
74
+					foreach ($filesarray as $key => $val)
75 75
 					{
76
-						if ($val['date'] > ($now - (24 * 3600))) unset($filesarray[$key]);	// Discard files not older than 24h
76
+						if ($val['date'] > ($now - (24 * 3600))) unset($filesarray[$key]); // Discard files not older than 24h
77 77
 					}
78 78
 				}
79 79
 			}
80 80
 		}
81 81
 
82
-		if ($choice=='allfiles')
82
+		if ($choice == 'allfiles')
83 83
 		{
84 84
 			// Delete all files (except install.lock)
85 85
 			if ($dolibarr_main_data_root)
86 86
 			{
87
-				$filesarray=dol_dir_list($dolibarr_main_data_root,"all",0,'','install\.lock$');
87
+				$filesarray = dol_dir_list($dolibarr_main_data_root, "all", 0, '', 'install\.lock$');
88 88
 			}
89 89
 		}
90 90
 
91
-		if ($choice=='logfile')
91
+		if ($choice == 'logfile')
92 92
 		{
93 93
 		    // Define files log
94 94
 			if ($dolibarr_main_data_root)
95 95
 			{
96
-                $filesarray=dol_dir_list($dolibarr_main_data_root, "files", 0, '.*\.log[\.0-9]*$', 'install\.lock$');
96
+                $filesarray = dol_dir_list($dolibarr_main_data_root, "files", 0, '.*\.log[\.0-9]*$', 'install\.lock$');
97 97
 			}
98 98
 
99
-			$filelog='';
100
-			if (! empty($conf->syslog->enabled))
99
+			$filelog = '';
100
+			if (!empty($conf->syslog->enabled))
101 101
 			{
102
-				$filelog=$conf->global->SYSLOG_FILE;
103
-				$filelog=preg_replace('/DOL_DATA_ROOT/i',DOL_DATA_ROOT,$filelog);
102
+				$filelog = $conf->global->SYSLOG_FILE;
103
+				$filelog = preg_replace('/DOL_DATA_ROOT/i', DOL_DATA_ROOT, $filelog);
104 104
 
105
-				$alreadyincluded=false;
105
+				$alreadyincluded = false;
106 106
 				foreach ($filesarray as $tmpcursor)
107 107
 				{
108
-				    if ($tmpcursor['fullname'] == $filelog) { $alreadyincluded=true; }
108
+				    if ($tmpcursor['fullname'] == $filelog) { $alreadyincluded = true; }
109 109
 				}
110
-				if (! $alreadyincluded) $filesarray[]=array('fullname'=>$filelog,'type'=>'file');
110
+				if (!$alreadyincluded) $filesarray[] = array('fullname'=>$filelog, 'type'=>'file');
111 111
 			}
112 112
 		}
113 113
 
114
-		$count=0;
115
-		$countdeleted=0;
116
-		$counterror=0;
114
+		$count = 0;
115
+		$countdeleted = 0;
116
+		$counterror = 0;
117 117
 		if (count($filesarray))
118 118
 		{
119
-			foreach($filesarray as $key => $value)
119
+			foreach ($filesarray as $key => $value)
120 120
 			{
121 121
 				//print "x ".$filesarray[$key]['fullname']."-".$filesarray[$key]['type']."<br>\n";
122 122
 				if ($filesarray[$key]['type'] == 'dir')
123 123
 				{
124
-				    $startcount=0;
125
-				    $tmpcountdeleted=0;
126
-					$result=dol_delete_dir_recursive($filesarray[$key]['fullname'], $startcount, 1, 0, $tmpcountdeleted);
127
-				    $count+=$result;
128
-				    $countdeleted+=$tmpcountdeleted;
124
+				    $startcount = 0;
125
+				    $tmpcountdeleted = 0;
126
+					$result = dol_delete_dir_recursive($filesarray[$key]['fullname'], $startcount, 1, 0, $tmpcountdeleted);
127
+				    $count += $result;
128
+				    $countdeleted += $tmpcountdeleted;
129 129
 				}
130 130
 				elseif ($filesarray[$key]['type'] == 'file')
131 131
 				{
132 132
 					// If (file that is not logfile) or (if logfile with option logfile)
133
-					if ($filesarray[$key]['fullname'] != $filelog || $choice=='logfile')
133
+					if ($filesarray[$key]['fullname'] != $filelog || $choice == 'logfile')
134 134
 					{
135
-					    $result=dol_delete_file($filesarray[$key]['fullname'], 1, 1);
135
+					    $result = dol_delete_file($filesarray[$key]['fullname'], 1, 1);
136 136
 					    if ($result)
137 137
 					    {
138 138
 					        $count++;
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
 			}
145 145
 
146 146
 			// Update cachenbofdoc
147
-			if (! empty($conf->ecm->enabled) && $choice=='allfiles')
147
+			if (!empty($conf->ecm->enabled) && $choice == 'allfiles')
148 148
 			{
149 149
 				require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmdirectory.class.php';
150 150
 				$ecmdirstatic = new EcmDirectory($this->db);
@@ -154,13 +154,13 @@  discard block
 block discarded – undo
154 154
 
155 155
 		if ($count > 0)
156 156
 		{
157
-		    $this->output=$langs->trans("PurgeNDirectoriesDeleted", $countdeleted);
158
-		    if ($count > $countdeleted) $this->output.='<br>'.$langs->trans("PurgeNDirectoriesFailed", ($count - $countdeleted));
157
+		    $this->output = $langs->trans("PurgeNDirectoriesDeleted", $countdeleted);
158
+		    if ($count > $countdeleted) $this->output .= '<br>'.$langs->trans("PurgeNDirectoriesFailed", ($count - $countdeleted));
159 159
 		}
160
-		else $this->output=$langs->trans("PurgeNothingToDelete").($choice == 'tempfilesold' ? ' (older than 24h)':'');
160
+		else $this->output = $langs->trans("PurgeNothingToDelete").($choice == 'tempfilesold' ? ' (older than 24h)' : '');
161 161
 
162 162
 		//return $count;
163
-		return 0;     // This function can be called by cron so must return 0 if OK
163
+		return 0; // This function can be called by cron so must return 0 if OK
164 164
 	}
165 165
 
166 166
 
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 	 *  @param  int         $keeplastnfiles    Keep only last n files (not used yet)
176 176
 	 *  @return	int						       0 if OK, < 0 if KO (this function is used also by cron so only 0 is OK)
177 177
 	 */
178
-	function dumpDatabase($compression='none', $type='auto', $usedefault=1, $file='auto', $keeplastnfiles=0)
178
+	function dumpDatabase($compression = 'none', $type = 'auto', $usedefault = 1, $file = 'auto', $keeplastnfiles = 0)
179 179
 	{
180 180
 		global $db, $conf, $langs, $dolibarr_main_data_root;
181 181
 		global $dolibarr_main_db_name, $dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_port, $dolibarr_main_db_pass;
@@ -187,120 +187,120 @@  discard block
 block discarded – undo
187 187
 		require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
188 188
 
189 189
 		// Check compression parameter
190
-		if (! in_array($compression, array('none', 'gz', 'bz', 'zip')))
190
+		if (!in_array($compression, array('none', 'gz', 'bz', 'zip')))
191 191
 		{
192 192
 		    $langs->load("errors");
193
-		    $this->error=$langs->transnoentitiesnoconv("ErrorBadValueForParameter", $compression, "Compression");
193
+		    $this->error = $langs->transnoentitiesnoconv("ErrorBadValueForParameter", $compression, "Compression");
194 194
 		    return -1;
195 195
 		}
196 196
 
197 197
 		// Check type parameter
198 198
 		if ($type == 'auto') $type = $db->type;
199
-		if (! in_array($type, array('pgsql', 'mysql', 'mysqli','mysqlnobin')))
199
+		if (!in_array($type, array('pgsql', 'mysql', 'mysqli', 'mysqlnobin')))
200 200
 		{
201 201
 		    $langs->load("errors");
202
-		    $this->error=$langs->transnoentitiesnoconv("ErrorBadValueForParameter", $type, "Basetype");
202
+		    $this->error = $langs->transnoentitiesnoconv("ErrorBadValueForParameter", $type, "Basetype");
203 203
 		    return -1;
204 204
 		}
205 205
 
206 206
 		// Check file parameter
207 207
 		if ($file == 'auto')
208 208
 		{
209
-		    $prefix='dump';
210
-		    $ext='.sql';
211
-		    if (in_array($type, array('mysql', 'mysqli')))  { $prefix='mysqldump'; $ext='sql'; }
209
+		    $prefix = 'dump';
210
+		    $ext = '.sql';
211
+		    if (in_array($type, array('mysql', 'mysqli'))) { $prefix = 'mysqldump'; $ext = 'sql'; }
212 212
 		    //if ($label == 'PostgreSQL') { $prefix='pg_dump'; $ext='dump'; }
213
-		    if (in_array($type, array('pgsql'))) { $prefix='pg_dump'; $ext='sql'; }
214
-		    $file=$prefix.'_'.$dolibarr_main_db_name.'_'.dol_sanitizeFileName(DOL_VERSION).'_'.strftime("%Y%m%d%H%M").'.'.$ext;
213
+		    if (in_array($type, array('pgsql'))) { $prefix = 'pg_dump'; $ext = 'sql'; }
214
+		    $file = $prefix.'_'.$dolibarr_main_db_name.'_'.dol_sanitizeFileName(DOL_VERSION).'_'.strftime("%Y%m%d%H%M").'.'.$ext;
215 215
 		}
216 216
 
217
-		$outputdir  = $conf->admin->dir_output.'/backup';
218
-		$result=dol_mkdir($outputdir);
217
+		$outputdir = $conf->admin->dir_output.'/backup';
218
+		$result = dol_mkdir($outputdir);
219 219
 
220 220
 
221 221
 		// MYSQL
222 222
 		if ($type == 'mysql' || $type == 'mysqli')
223 223
 		{
224
-		    $cmddump=$conf->global->SYSTEMTOOLS_MYSQLDUMP;
224
+		    $cmddump = $conf->global->SYSTEMTOOLS_MYSQLDUMP;
225 225
 
226 226
 
227 227
 		    $outputfile = $outputdir.'/'.$file;
228 228
 		    // for compression format, we add extension
229
-		    $compression=$compression ? $compression : 'none';
230
-		    if ($compression == 'gz') $outputfile.='.gz';
231
-		    if ($compression == 'bz') $outputfile.='.bz2';
229
+		    $compression = $compression ? $compression : 'none';
230
+		    if ($compression == 'gz') $outputfile .= '.gz';
231
+		    if ($compression == 'bz') $outputfile .= '.bz2';
232 232
 		    $outputerror = $outputfile.'.err';
233 233
 		    dol_mkdir($conf->admin->dir_output.'/backup');
234 234
 
235 235
 		    // Parameteres execution
236
-		    $command=$cmddump;
237
-		    if (preg_match("/\s/",$command)) $command=escapeshellarg($command);	// Use quotes on command
236
+		    $command = $cmddump;
237
+		    if (preg_match("/\s/", $command)) $command = escapeshellarg($command); // Use quotes on command
238 238
 
239 239
 		    //$param=escapeshellarg($dolibarr_main_db_name)." -h ".escapeshellarg($dolibarr_main_db_host)." -u ".escapeshellarg($dolibarr_main_db_user)." -p".escapeshellarg($dolibarr_main_db_pass);
240
-		    $param=$dolibarr_main_db_name." -h ".$dolibarr_main_db_host;
241
-		    $param.=" -u ".$dolibarr_main_db_user;
242
-		    if (! empty($dolibarr_main_db_port)) $param.=" -P ".$dolibarr_main_db_port;
243
-		    if (! GETPOST("use_transaction"))    $param.=" -l --single-transaction";
244
-		    if (GETPOST("disable_fk") || $usedefault) $param.=" -K";
245
-		    if (GETPOST("sql_compat") && GETPOST("sql_compat") != 'NONE') $param.=" --compatible=".escapeshellarg(GETPOST("sql_compat","alpha"));
246
-		    if (GETPOST("drop_database"))        $param.=" --add-drop-database";
240
+		    $param = $dolibarr_main_db_name." -h ".$dolibarr_main_db_host;
241
+		    $param .= " -u ".$dolibarr_main_db_user;
242
+		    if (!empty($dolibarr_main_db_port)) $param .= " -P ".$dolibarr_main_db_port;
243
+		    if (!GETPOST("use_transaction"))    $param .= " -l --single-transaction";
244
+		    if (GETPOST("disable_fk") || $usedefault) $param .= " -K";
245
+		    if (GETPOST("sql_compat") && GETPOST("sql_compat") != 'NONE') $param .= " --compatible=".escapeshellarg(GETPOST("sql_compat", "alpha"));
246
+		    if (GETPOST("drop_database"))        $param .= " --add-drop-database";
247 247
 		    if (GETPOST("sql_structure") || $usedefault)
248 248
 		    {
249
-		        if (GETPOST("drop") || $usedefault)	$param.=" --add-drop-table=TRUE";
250
-		        else 							    $param.=" --add-drop-table=FALSE";
249
+		        if (GETPOST("drop") || $usedefault)	$param .= " --add-drop-table=TRUE";
250
+		        else 							    $param .= " --add-drop-table=FALSE";
251 251
 		    }
252 252
 		    else
253 253
 		    {
254
-		        $param.=" -t";
254
+		        $param .= " -t";
255 255
 		    }
256
-		    if (GETPOST("disable-add-locks")) $param.=" --add-locks=FALSE";
256
+		    if (GETPOST("disable-add-locks")) $param .= " --add-locks=FALSE";
257 257
 		    if (GETPOST("sql_data") || $usedefault)
258 258
 		    {
259
-		        $param.=" --tables";
260
-		        if (GETPOST("showcolumns") || $usedefault)	 $param.=" -c";
261
-		        if (GETPOST("extended_ins") || $usedefault) $param.=" -e";
262
-		        else $param.=" --skip-extended-insert";
263
-		        if (GETPOST("delayed"))	 	 $param.=" --delayed-insert";
264
-		        if (GETPOST("sql_ignore"))	 $param.=" --insert-ignore";
265
-		        if (GETPOST("hexforbinary") || $usedefault) $param.=" --hex-blob";
259
+		        $param .= " --tables";
260
+		        if (GETPOST("showcolumns") || $usedefault)	 $param .= " -c";
261
+		        if (GETPOST("extended_ins") || $usedefault) $param .= " -e";
262
+		        else $param .= " --skip-extended-insert";
263
+		        if (GETPOST("delayed"))	 	 $param .= " --delayed-insert";
264
+		        if (GETPOST("sql_ignore"))	 $param .= " --insert-ignore";
265
+		        if (GETPOST("hexforbinary") || $usedefault) $param .= " --hex-blob";
266 266
 		    }
267 267
 		    else
268 268
 		    {
269
-		        $param.=" -d";    // No row information (no data)
269
+		        $param .= " -d"; // No row information (no data)
270 270
 		    }
271
-		    $param.=" --default-character-set=utf8";    // We always save output into utf8 charset
272
-		    $paramcrypted=$param;
273
-		    $paramclear=$param;
274
-		    if (! empty($dolibarr_main_db_pass))
271
+		    $param .= " --default-character-set=utf8"; // We always save output into utf8 charset
272
+		    $paramcrypted = $param;
273
+		    $paramclear = $param;
274
+		    if (!empty($dolibarr_main_db_pass))
275 275
 		    {
276
-		        $paramcrypted.=' -p"'.preg_replace('/./i','*',$dolibarr_main_db_pass).'"';
277
-		        $paramclear.=' -p"'.str_replace(array('"','`'),array('\"','\`'),$dolibarr_main_db_pass).'"';
276
+		        $paramcrypted .= ' -p"'.preg_replace('/./i', '*', $dolibarr_main_db_pass).'"';
277
+		        $paramclear .= ' -p"'.str_replace(array('"', '`'), array('\"', '\`'), $dolibarr_main_db_pass).'"';
278 278
 		    }
279 279
 
280
-		    $errormsg='';
280
+		    $errormsg = '';
281 281
 
282 282
 		    // Debut appel methode execution
283
-		    $fullcommandcrypted=$command." ".$paramcrypted." 2>&1";
284
-		    $fullcommandclear=$command." ".$paramclear." 2>&1";
283
+		    $fullcommandcrypted = $command." ".$paramcrypted." 2>&1";
284
+		    $fullcommandclear = $command." ".$paramclear." 2>&1";
285 285
 		    if ($compression == 'none') $handle = fopen($outputfile, 'w');
286 286
 		    if ($compression == 'gz')   $handle = gzopen($outputfile, 'w');
287 287
 		    if ($compression == 'bz')   $handle = bzopen($outputfile, 'w');
288 288
 
289 289
 		    if ($handle)
290 290
 		    {
291
-		        $ok=0;
291
+		        $ok = 0;
292 292
 		        dol_syslog("Run command ".$fullcommandcrypted);
293 293
 		        $handlein = popen($fullcommandclear, 'r');
294
-		        $i=0;
294
+		        $i = 0;
295 295
 		        while (!feof($handlein))
296 296
 		        {
297
-		            $i++;   // output line number
297
+		            $i++; // output line number
298 298
 		            $read = fgets($handlein);
299 299
 		            // Exclude warning line we don't want
300 300
 		            if ($i == 1 && preg_match('/Warning.*Using a password/i', $read)) continue;
301
-		            fwrite($handle,$read);
302
-		            if (preg_match('/'.preg_quote('-- Dump completed').'/i',$read)) $ok=1;
303
-		            elseif (preg_match('/'.preg_quote('SET SQL_NOTES=@OLD_SQL_NOTES').'/i',$read)) $ok=1;
301
+		            fwrite($handle, $read);
302
+		            if (preg_match('/'.preg_quote('-- Dump completed').'/i', $read)) $ok = 1;
303
+		            elseif (preg_match('/'.preg_quote('SET SQL_NOTES=@OLD_SQL_NOTES').'/i', $read)) $ok = 1;
304 304
 		        }
305 305
 		        pclose($handlein);
306 306
 
@@ -308,14 +308,14 @@  discard block
 block discarded – undo
308 308
 		        if ($compression == 'gz')   gzclose($handle);
309 309
 		        if ($compression == 'bz')   bzclose($handle);
310 310
 
311
-		        if (! empty($conf->global->MAIN_UMASK))
311
+		        if (!empty($conf->global->MAIN_UMASK))
312 312
 		            @chmod($outputfile, octdec($conf->global->MAIN_UMASK));
313 313
 		    }
314 314
 		    else
315 315
 		    {
316 316
 		        $langs->load("errors");
317
-		        dol_syslog("Failed to open file ".$outputfile,LOG_ERR);
318
-		        $errormsg=$langs->trans("ErrorFailedToWriteInDir");
317
+		        dol_syslog("Failed to open file ".$outputfile, LOG_ERR);
318
+		        $errormsg = $langs->trans("ErrorFailedToWriteInDir");
319 319
 		    }
320 320
 
321 321
 		    // Get errorstring
@@ -325,23 +325,23 @@  discard block
 block discarded – undo
325 325
 		    if ($handle)
326 326
 		    {
327 327
 		        // Get 2048 first chars of error message.
328
-		        $errormsg = fgets($handle,2048);
328
+		        $errormsg = fgets($handle, 2048);
329 329
 		        // Close file
330 330
 		        if ($compression == 'none') fclose($handle);
331 331
 		        if ($compression == 'gz')   gzclose($handle);
332 332
 		        if ($compression == 'bz')   bzclose($handle);
333
-		        if ($ok && preg_match('/^-- MySql/i',$errormsg)) $errormsg='';	// Pas erreur
333
+		        if ($ok && preg_match('/^-- MySql/i', $errormsg)) $errormsg = ''; // Pas erreur
334 334
 		        else
335 335
 		        {
336 336
 		            // Renommer fichier sortie en fichier erreur
337 337
 		            //print "$outputfile -> $outputerror";
338
-		            @dol_delete_file($outputerror,1);
339
-		            @rename($outputfile,$outputerror);
338
+		            @dol_delete_file($outputerror, 1);
339
+		            @rename($outputfile, $outputerror);
340 340
 		            // Si safe_mode on et command hors du parametre exec, on a un fichier out vide donc errormsg vide
341
-		            if (! $errormsg)
341
+		            if (!$errormsg)
342 342
 		            {
343 343
 		                $langs->load("errors");
344
-		                $errormsg=$langs->trans("ErrorFailedToRunExternalCommand");
344
+		                $errormsg = $langs->trans("ErrorFailedToRunExternalCommand");
345 345
 		            }
346 346
 		        }
347 347
 		    }
@@ -359,9 +359,9 @@  discard block
 block discarded – undo
359 359
 		    $outputfile = $outputdir.'/'.$file;
360 360
 		    $outputfiletemp = $outputfile.'-TMP.sql';
361 361
 		    // for compression format, we add extension
362
-		    $compression=$compression ? $compression : 'none';
363
-		    if ($compression == 'gz') $outputfile.='.gz';
364
-		    if ($compression == 'bz') $outputfile.='.bz2';
362
+		    $compression = $compression ? $compression : 'none';
363
+		    if ($compression == 'gz') $outputfile .= '.gz';
364
+		    if ($compression == 'bz') $outputfile .= '.bz2';
365 365
 		    $outputerror = $outputfile.'.err';
366 366
 		    dol_mkdir($conf->admin->dir_output.'/backup');
367 367
 
@@ -383,51 +383,51 @@  discard block
 block discarded – undo
383 383
 		// POSTGRESQL
384 384
 		if ($type == 'postgresql')
385 385
 		{
386
-		    $cmddump=$conf->global->SYSTEMTOOLS_POSTGRESQLDUMP;
386
+		    $cmddump = $conf->global->SYSTEMTOOLS_POSTGRESQLDUMP;
387 387
 
388 388
 		    $outputfile = $outputdir.'/'.$file;
389 389
 		    // for compression format, we add extension
390
-		    $compression=$compression ? $compression : 'none';
391
-		    if ($compression == 'gz') $outputfile.='.gz';
392
-		    if ($compression == 'bz') $outputfile.='.bz2';
390
+		    $compression = $compression ? $compression : 'none';
391
+		    if ($compression == 'gz') $outputfile .= '.gz';
392
+		    if ($compression == 'bz') $outputfile .= '.bz2';
393 393
 		    $outputerror = $outputfile.'.err';
394 394
 		    dol_mkdir($conf->admin->dir_output.'/backup');
395 395
 
396 396
 		    // Parameteres execution
397
-		    $command=$cmddump;
398
-		    if (preg_match("/\s/",$command)) $command=escapeshellarg($command);	// Use quotes on command
397
+		    $command = $cmddump;
398
+		    if (preg_match("/\s/", $command)) $command = escapeshellarg($command); // Use quotes on command
399 399
 
400 400
 		    //$param=escapeshellarg($dolibarr_main_db_name)." -h ".escapeshellarg($dolibarr_main_db_host)." -u ".escapeshellarg($dolibarr_main_db_user)." -p".escapeshellarg($dolibarr_main_db_pass);
401 401
 		    //$param="-F c";
402
-		    $param="-F p";
403
-		    $param.=" --no-tablespaces --inserts -h ".$dolibarr_main_db_host;
404
-		    $param.=" -U ".$dolibarr_main_db_user;
405
-		    if (! empty($dolibarr_main_db_port)) $param.=" -p ".$dolibarr_main_db_port;
406
-		    if (GETPOST("sql_compat") && GETPOST("sql_compat") == 'ANSI') $param.="  --disable-dollar-quoting";
407
-		    if (GETPOST("drop_database"))        $param.=" -c -C";
402
+		    $param = "-F p";
403
+		    $param .= " --no-tablespaces --inserts -h ".$dolibarr_main_db_host;
404
+		    $param .= " -U ".$dolibarr_main_db_user;
405
+		    if (!empty($dolibarr_main_db_port)) $param .= " -p ".$dolibarr_main_db_port;
406
+		    if (GETPOST("sql_compat") && GETPOST("sql_compat") == 'ANSI') $param .= "  --disable-dollar-quoting";
407
+		    if (GETPOST("drop_database"))        $param .= " -c -C";
408 408
 		    if (GETPOST("sql_structure"))
409 409
 		    {
410
-		        if (GETPOST("drop"))			 $param.=" --add-drop-table";
411
-		        if (! GETPOST("sql_data"))       $param.=" -s";
410
+		        if (GETPOST("drop"))			 $param .= " --add-drop-table";
411
+		        if (!GETPOST("sql_data"))       $param .= " -s";
412 412
 		    }
413 413
 		    if (GETPOST("sql_data"))
414 414
 		    {
415
-		        if (! GETPOST("sql_structure"))	 $param.=" -a";
416
-		        if (GETPOST("showcolumns"))	     $param.=" -c";
415
+		        if (!GETPOST("sql_structure"))	 $param .= " -a";
416
+		        if (GETPOST("showcolumns"))	     $param .= " -c";
417 417
 		    }
418
-		    $param.=' -f "'.$outputfile.'"';
418
+		    $param .= ' -f "'.$outputfile.'"';
419 419
 		    //if ($compression == 'none')
420
-		    if ($compression == 'gz')   $param.=' -Z 9';
420
+		    if ($compression == 'gz')   $param .= ' -Z 9';
421 421
 		    //if ($compression == 'bz')
422
-		    $paramcrypted=$param;
423
-		    $paramclear=$param;
422
+		    $paramcrypted = $param;
423
+		    $paramclear = $param;
424 424
 		    /*if (! empty($dolibarr_main_db_pass))
425 425
 		     {
426 426
 		     $paramcrypted.=" -W".preg_replace('/./i','*',$dolibarr_main_db_pass);
427 427
 		     $paramclear.=" -W".$dolibarr_main_db_pass;
428 428
 		     }*/
429
-		    $paramcrypted.=" -w ".$dolibarr_main_db_name;
430
-		    $paramclear.=" -w ".$dolibarr_main_db_name;
429
+		    $paramcrypted .= " -w ".$dolibarr_main_db_name;
430
+		    $paramclear .= " -w ".$dolibarr_main_db_name;
431 431
 
432 432
 		    $this->output = "";
433 433
 		    $this->result = array("commandbackuplastdone" => "", "commandbackuptorun" => $command." ".$paramcrypted);
@@ -437,8 +437,8 @@  discard block
 block discarded – undo
437 437
 		if ($keeplastnfiles > 0)
438 438
 		{
439 439
 		    $tmpfiles = dol_dir_list($conf->admin->dir_output.'/backup', 'files', 0, '', '(\.err|\.old|\.sav)$', 'date', SORT_DESC);
440
-		    $i=0;
441
-		    foreach($tmpfiles as $key => $val)
440
+		    $i = 0;
441
+		    foreach ($tmpfiles as $key => $val)
442 442
 		    {
443 443
 		        $i++;
444 444
 		        if ($i <= $keeplastnfiles) continue;
Please login to merge, or discard this patch.
Braces   +169 added lines, -66 removed lines patch added patch discarded remove patch
@@ -60,7 +60,9 @@  discard block
 block discarded – undo
60 60
 		require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
61 61
 
62 62
 		$filesarray=array();
63
-		if (empty($choice)) $choice='tempfilesold';
63
+		if (empty($choice)) {
64
+			$choice='tempfilesold';
65
+		}
64 66
 
65 67
 		if ($choice=='tempfiles' || $choice=='tempfilesold')
66 68
 		{
@@ -73,7 +75,10 @@  discard block
 block discarded – undo
73 75
 					$now = dol_now();
74 76
 					foreach($filesarray as $key => $val)
75 77
 					{
76
-						if ($val['date'] > ($now - (24 * 3600))) unset($filesarray[$key]);	// Discard files not older than 24h
78
+						if ($val['date'] > ($now - (24 * 3600))) {
79
+							unset($filesarray[$key]);
80
+						}
81
+						// Discard files not older than 24h
77 82
 					}
78 83
 				}
79 84
 			}
@@ -107,7 +112,9 @@  discard block
 block discarded – undo
107 112
 				{
108 113
 				    if ($tmpcursor['fullname'] == $filelog) { $alreadyincluded=true; }
109 114
 				}
110
-				if (! $alreadyincluded) $filesarray[]=array('fullname'=>$filelog,'type'=>'file');
115
+				if (! $alreadyincluded) {
116
+					$filesarray[]=array('fullname'=>$filelog,'type'=>'file');
117
+				}
111 118
 			}
112 119
 		}
113 120
 
@@ -126,8 +133,7 @@  discard block
 block discarded – undo
126 133
 					$result=dol_delete_dir_recursive($filesarray[$key]['fullname'], $startcount, 1, 0, $tmpcountdeleted);
127 134
 				    $count+=$result;
128 135
 				    $countdeleted+=$tmpcountdeleted;
129
-				}
130
-				elseif ($filesarray[$key]['type'] == 'file')
136
+				} elseif ($filesarray[$key]['type'] == 'file')
131 137
 				{
132 138
 					// If (file that is not logfile) or (if logfile with option logfile)
133 139
 					if ($filesarray[$key]['fullname'] != $filelog || $choice=='logfile')
@@ -137,8 +143,9 @@  discard block
 block discarded – undo
137 143
 					    {
138 144
 					        $count++;
139 145
 					        $countdeleted++;
146
+					    } else {
147
+					    	$counterror++;
140 148
 					    }
141
-					    else $counterror++;
142 149
 					}
143 150
 				}
144 151
 			}
@@ -155,9 +162,12 @@  discard block
 block discarded – undo
155 162
 		if ($count > 0)
156 163
 		{
157 164
 		    $this->output=$langs->trans("PurgeNDirectoriesDeleted", $countdeleted);
158
-		    if ($count > $countdeleted) $this->output.='<br>'.$langs->trans("PurgeNDirectoriesFailed", ($count - $countdeleted));
165
+		    if ($count > $countdeleted) {
166
+		    	$this->output.='<br>'.$langs->trans("PurgeNDirectoriesFailed", ($count - $countdeleted));
167
+		    }
168
+		} else {
169
+			$this->output=$langs->trans("PurgeNothingToDelete").($choice == 'tempfilesold' ? ' (older than 24h)':'');
159 170
 		}
160
-		else $this->output=$langs->trans("PurgeNothingToDelete").($choice == 'tempfilesold' ? ' (older than 24h)':'');
161 171
 
162 172
 		//return $count;
163 173
 		return 0;     // This function can be called by cron so must return 0 if OK
@@ -195,7 +205,9 @@  discard block
 block discarded – undo
195 205
 		}
196 206
 
197 207
 		// Check type parameter
198
-		if ($type == 'auto') $type = $db->type;
208
+		if ($type == 'auto') {
209
+			$type = $db->type;
210
+		}
199 211
 		if (! in_array($type, array('pgsql', 'mysql', 'mysqli','mysqlnobin')))
200 212
 		{
201 213
 		    $langs->load("errors");
@@ -227,44 +239,75 @@  discard block
 block discarded – undo
227 239
 		    $outputfile = $outputdir.'/'.$file;
228 240
 		    // for compression format, we add extension
229 241
 		    $compression=$compression ? $compression : 'none';
230
-		    if ($compression == 'gz') $outputfile.='.gz';
231
-		    if ($compression == 'bz') $outputfile.='.bz2';
242
+		    if ($compression == 'gz') {
243
+		    	$outputfile.='.gz';
244
+		    }
245
+		    if ($compression == 'bz') {
246
+		    	$outputfile.='.bz2';
247
+		    }
232 248
 		    $outputerror = $outputfile.'.err';
233 249
 		    dol_mkdir($conf->admin->dir_output.'/backup');
234 250
 
235 251
 		    // Parameteres execution
236 252
 		    $command=$cmddump;
237
-		    if (preg_match("/\s/",$command)) $command=escapeshellarg($command);	// Use quotes on command
253
+		    if (preg_match("/\s/",$command)) {
254
+		    	$command=escapeshellarg($command);
255
+		    }
256
+		    // Use quotes on command
238 257
 
239 258
 		    //$param=escapeshellarg($dolibarr_main_db_name)." -h ".escapeshellarg($dolibarr_main_db_host)." -u ".escapeshellarg($dolibarr_main_db_user)." -p".escapeshellarg($dolibarr_main_db_pass);
240 259
 		    $param=$dolibarr_main_db_name." -h ".$dolibarr_main_db_host;
241 260
 		    $param.=" -u ".$dolibarr_main_db_user;
242
-		    if (! empty($dolibarr_main_db_port)) $param.=" -P ".$dolibarr_main_db_port;
243
-		    if (! GETPOST("use_transaction"))    $param.=" -l --single-transaction";
244
-		    if (GETPOST("disable_fk") || $usedefault) $param.=" -K";
245
-		    if (GETPOST("sql_compat") && GETPOST("sql_compat") != 'NONE') $param.=" --compatible=".escapeshellarg(GETPOST("sql_compat","alpha"));
246
-		    if (GETPOST("drop_database"))        $param.=" --add-drop-database";
261
+		    if (! empty($dolibarr_main_db_port)) {
262
+		    	$param.=" -P ".$dolibarr_main_db_port;
263
+		    }
264
+		    if (! GETPOST("use_transaction")) {
265
+		    	$param.=" -l --single-transaction";
266
+		    }
267
+		    if (GETPOST("disable_fk") || $usedefault) {
268
+		    	$param.=" -K";
269
+		    }
270
+		    if (GETPOST("sql_compat") && GETPOST("sql_compat") != 'NONE') {
271
+		    	$param.=" --compatible=".escapeshellarg(GETPOST("sql_compat","alpha"));
272
+		    }
273
+		    if (GETPOST("drop_database")) {
274
+		    	$param.=" --add-drop-database";
275
+		    }
247 276
 		    if (GETPOST("sql_structure") || $usedefault)
248 277
 		    {
249
-		        if (GETPOST("drop") || $usedefault)	$param.=" --add-drop-table=TRUE";
250
-		        else 							    $param.=" --add-drop-table=FALSE";
251
-		    }
252
-		    else
278
+		        if (GETPOST("drop") || $usedefault) {
279
+		        	$param.=" --add-drop-table=TRUE";
280
+		        } else {
281
+		        	$param.=" --add-drop-table=FALSE";
282
+		        }
283
+		    } else
253 284
 		    {
254 285
 		        $param.=" -t";
255 286
 		    }
256
-		    if (GETPOST("disable-add-locks")) $param.=" --add-locks=FALSE";
287
+		    if (GETPOST("disable-add-locks")) {
288
+		    	$param.=" --add-locks=FALSE";
289
+		    }
257 290
 		    if (GETPOST("sql_data") || $usedefault)
258 291
 		    {
259 292
 		        $param.=" --tables";
260
-		        if (GETPOST("showcolumns") || $usedefault)	 $param.=" -c";
261
-		        if (GETPOST("extended_ins") || $usedefault) $param.=" -e";
262
-		        else $param.=" --skip-extended-insert";
263
-		        if (GETPOST("delayed"))	 	 $param.=" --delayed-insert";
264
-		        if (GETPOST("sql_ignore"))	 $param.=" --insert-ignore";
265
-		        if (GETPOST("hexforbinary") || $usedefault) $param.=" --hex-blob";
266
-		    }
267
-		    else
293
+		        if (GETPOST("showcolumns") || $usedefault) {
294
+		        	$param.=" -c";
295
+		        }
296
+		        if (GETPOST("extended_ins") || $usedefault) {
297
+		        	$param.=" -e";
298
+		        } else {
299
+		        	$param.=" --skip-extended-insert";
300
+		        }
301
+		        if (GETPOST("delayed")) {
302
+		        	$param.=" --delayed-insert";
303
+		        }
304
+		        if (GETPOST("sql_ignore")) {
305
+		        	$param.=" --insert-ignore";
306
+		        }
307
+		        if (GETPOST("hexforbinary") || $usedefault) {
308
+		        	$param.=" --hex-blob";
309
+		        }
310
+		    } else
268 311
 		    {
269 312
 		        $param.=" -d";    // No row information (no data)
270 313
 		    }
@@ -282,9 +325,15 @@  discard block
 block discarded – undo
282 325
 		    // Debut appel methode execution
283 326
 		    $fullcommandcrypted=$command." ".$paramcrypted." 2>&1";
284 327
 		    $fullcommandclear=$command." ".$paramclear." 2>&1";
285
-		    if ($compression == 'none') $handle = fopen($outputfile, 'w');
286
-		    if ($compression == 'gz')   $handle = gzopen($outputfile, 'w');
287
-		    if ($compression == 'bz')   $handle = bzopen($outputfile, 'w');
328
+		    if ($compression == 'none') {
329
+		    	$handle = fopen($outputfile, 'w');
330
+		    }
331
+		    if ($compression == 'gz') {
332
+		    	$handle = gzopen($outputfile, 'w');
333
+		    }
334
+		    if ($compression == 'bz') {
335
+		    	$handle = bzopen($outputfile, 'w');
336
+		    }
288 337
 
289 338
 		    if ($handle)
290 339
 		    {
@@ -297,21 +346,32 @@  discard block
 block discarded – undo
297 346
 		            $i++;   // output line number
298 347
 		            $read = fgets($handlein);
299 348
 		            // Exclude warning line we don't want
300
-		            if ($i == 1 && preg_match('/Warning.*Using a password/i', $read)) continue;
349
+		            if ($i == 1 && preg_match('/Warning.*Using a password/i', $read)) {
350
+		            	continue;
351
+		            }
301 352
 		            fwrite($handle,$read);
302
-		            if (preg_match('/'.preg_quote('-- Dump completed').'/i',$read)) $ok=1;
303
-		            elseif (preg_match('/'.preg_quote('SET SQL_NOTES=@OLD_SQL_NOTES').'/i',$read)) $ok=1;
353
+		            if (preg_match('/'.preg_quote('-- Dump completed').'/i',$read)) {
354
+		            	$ok=1;
355
+		            } elseif (preg_match('/'.preg_quote('SET SQL_NOTES=@OLD_SQL_NOTES').'/i',$read)) {
356
+		            	$ok=1;
357
+		            }
304 358
 		        }
305 359
 		        pclose($handlein);
306 360
 
307
-		        if ($compression == 'none') fclose($handle);
308
-		        if ($compression == 'gz')   gzclose($handle);
309
-		        if ($compression == 'bz')   bzclose($handle);
361
+		        if ($compression == 'none') {
362
+		        	fclose($handle);
363
+		        }
364
+		        if ($compression == 'gz') {
365
+		        	gzclose($handle);
366
+		        }
367
+		        if ($compression == 'bz') {
368
+		        	bzclose($handle);
369
+		        }
310 370
 
311
-		        if (! empty($conf->global->MAIN_UMASK))
312
-		            @chmod($outputfile, octdec($conf->global->MAIN_UMASK));
313
-		    }
314
-		    else
371
+		        if (! empty($conf->global->MAIN_UMASK)) {
372
+		        		            @chmod($outputfile, octdec($conf->global->MAIN_UMASK));
373
+		        }
374
+		    } else
315 375
 		    {
316 376
 		        $langs->load("errors");
317 377
 		        dol_syslog("Failed to open file ".$outputfile,LOG_ERR);
@@ -319,18 +379,33 @@  discard block
 block discarded – undo
319 379
 		    }
320 380
 
321 381
 		    // Get errorstring
322
-		    if ($compression == 'none') $handle = fopen($outputfile, 'r');
323
-		    if ($compression == 'gz')   $handle = gzopen($outputfile, 'r');
324
-		    if ($compression == 'bz')   $handle = bzopen($outputfile, 'r');
382
+		    if ($compression == 'none') {
383
+		    	$handle = fopen($outputfile, 'r');
384
+		    }
385
+		    if ($compression == 'gz') {
386
+		    	$handle = gzopen($outputfile, 'r');
387
+		    }
388
+		    if ($compression == 'bz') {
389
+		    	$handle = bzopen($outputfile, 'r');
390
+		    }
325 391
 		    if ($handle)
326 392
 		    {
327 393
 		        // Get 2048 first chars of error message.
328 394
 		        $errormsg = fgets($handle,2048);
329 395
 		        // Close file
330
-		        if ($compression == 'none') fclose($handle);
331
-		        if ($compression == 'gz')   gzclose($handle);
332
-		        if ($compression == 'bz')   bzclose($handle);
333
-		        if ($ok && preg_match('/^-- MySql/i',$errormsg)) $errormsg='';	// Pas erreur
396
+		        if ($compression == 'none') {
397
+		        	fclose($handle);
398
+		        }
399
+		        if ($compression == 'gz') {
400
+		        	gzclose($handle);
401
+		        }
402
+		        if ($compression == 'bz') {
403
+		        	bzclose($handle);
404
+		        }
405
+		        if ($ok && preg_match('/^-- MySql/i',$errormsg)) {
406
+		        	$errormsg='';
407
+		        }
408
+		        // Pas erreur
334 409
 		        else
335 410
 		        {
336 411
 		            // Renommer fichier sortie en fichier erreur
@@ -360,8 +435,12 @@  discard block
 block discarded – undo
360 435
 		    $outputfiletemp = $outputfile.'-TMP.sql';
361 436
 		    // for compression format, we add extension
362 437
 		    $compression=$compression ? $compression : 'none';
363
-		    if ($compression == 'gz') $outputfile.='.gz';
364
-		    if ($compression == 'bz') $outputfile.='.bz2';
438
+		    if ($compression == 'gz') {
439
+		    	$outputfile.='.gz';
440
+		    }
441
+		    if ($compression == 'bz') {
442
+		    	$outputfile.='.bz2';
443
+		    }
365 444
 		    $outputerror = $outputfile.'.err';
366 445
 		    dol_mkdir($conf->admin->dir_output.'/backup');
367 446
 
@@ -370,8 +449,7 @@  discard block
 block discarded – undo
370 449
 		        backup_tables($outputfiletemp);
371 450
 		        dol_compress_file($outputfiletemp, $outputfile, $compression);
372 451
 		        unlink($outputfiletemp);
373
-		    }
374
-		    else
452
+		    } else
375 453
 		    {
376 454
 		        backup_tables($outputfile);
377 455
 		    }
@@ -388,36 +466,59 @@  discard block
 block discarded – undo
388 466
 		    $outputfile = $outputdir.'/'.$file;
389 467
 		    // for compression format, we add extension
390 468
 		    $compression=$compression ? $compression : 'none';
391
-		    if ($compression == 'gz') $outputfile.='.gz';
392
-		    if ($compression == 'bz') $outputfile.='.bz2';
469
+		    if ($compression == 'gz') {
470
+		    	$outputfile.='.gz';
471
+		    }
472
+		    if ($compression == 'bz') {
473
+		    	$outputfile.='.bz2';
474
+		    }
393 475
 		    $outputerror = $outputfile.'.err';
394 476
 		    dol_mkdir($conf->admin->dir_output.'/backup');
395 477
 
396 478
 		    // Parameteres execution
397 479
 		    $command=$cmddump;
398
-		    if (preg_match("/\s/",$command)) $command=escapeshellarg($command);	// Use quotes on command
480
+		    if (preg_match("/\s/",$command)) {
481
+		    	$command=escapeshellarg($command);
482
+		    }
483
+		    // Use quotes on command
399 484
 
400 485
 		    //$param=escapeshellarg($dolibarr_main_db_name)." -h ".escapeshellarg($dolibarr_main_db_host)." -u ".escapeshellarg($dolibarr_main_db_user)." -p".escapeshellarg($dolibarr_main_db_pass);
401 486
 		    //$param="-F c";
402 487
 		    $param="-F p";
403 488
 		    $param.=" --no-tablespaces --inserts -h ".$dolibarr_main_db_host;
404 489
 		    $param.=" -U ".$dolibarr_main_db_user;
405
-		    if (! empty($dolibarr_main_db_port)) $param.=" -p ".$dolibarr_main_db_port;
406
-		    if (GETPOST("sql_compat") && GETPOST("sql_compat") == 'ANSI') $param.="  --disable-dollar-quoting";
407
-		    if (GETPOST("drop_database"))        $param.=" -c -C";
490
+		    if (! empty($dolibarr_main_db_port)) {
491
+		    	$param.=" -p ".$dolibarr_main_db_port;
492
+		    }
493
+		    if (GETPOST("sql_compat") && GETPOST("sql_compat") == 'ANSI') {
494
+		    	$param.="  --disable-dollar-quoting";
495
+		    }
496
+		    if (GETPOST("drop_database")) {
497
+		    	$param.=" -c -C";
498
+		    }
408 499
 		    if (GETPOST("sql_structure"))
409 500
 		    {
410
-		        if (GETPOST("drop"))			 $param.=" --add-drop-table";
411
-		        if (! GETPOST("sql_data"))       $param.=" -s";
501
+		        if (GETPOST("drop")) {
502
+		        	$param.=" --add-drop-table";
503
+		        }
504
+		        if (! GETPOST("sql_data")) {
505
+		        	$param.=" -s";
506
+		        }
412 507
 		    }
413 508
 		    if (GETPOST("sql_data"))
414 509
 		    {
415
-		        if (! GETPOST("sql_structure"))	 $param.=" -a";
416
-		        if (GETPOST("showcolumns"))	     $param.=" -c";
510
+		        if (! GETPOST("sql_structure")) {
511
+		        	$param.=" -a";
512
+		        }
513
+		        if (GETPOST("showcolumns")) {
514
+		        	$param.=" -c";
515
+		        }
417 516
 		    }
418 517
 		    $param.=' -f "'.$outputfile.'"';
419 518
 		    //if ($compression == 'none')
420
-		    if ($compression == 'gz')   $param.=' -Z 9';
519
+		    if ($compression == 'gz') {
520
+		    	$param.=' -Z 9';
521
+		    }
421 522
 		    //if ($compression == 'bz')
422 523
 		    $paramcrypted=$param;
423 524
 		    $paramclear=$param;
@@ -441,7 +542,9 @@  discard block
 block discarded – undo
441 542
 		    foreach($tmpfiles as $key => $val)
442 543
 		    {
443 544
 		        $i++;
444
-		        if ($i <= $keeplastnfiles) continue;
545
+		        if ($i <= $keeplastnfiles) {
546
+		        	continue;
547
+		        }
445 548
 		        dol_delete_file($val['fullname']);
446 549
 		    }
447 550
 		}
Please login to merge, or discard this patch.
htdocs/core/class/hookmanager.class.php 3 patches
Indentation   +135 added lines, -135 removed lines patch added patch discarded remove patch
@@ -33,8 +33,8 @@  discard block
 block discarded – undo
33 33
 	var $error;
34 34
 	var $errors=array();
35 35
 
36
-    // Context hookmanager was created for ('thirdpartycard', 'thirdpartydao', ...)
37
-    var $contextarray=array();
36
+	// Context hookmanager was created for ('thirdpartycard', 'thirdpartydao', ...)
37
+	var $contextarray=array();
38 38
 
39 39
 	// Array with instantiated classes
40 40
 	var $hooks=array();
@@ -73,9 +73,9 @@  discard block
 block discarded – undo
73 73
 		global $conf;
74 74
 
75 75
 		// Test if there is hooks to manage
76
-        if (! is_array($conf->modules_parts['hooks']) || empty($conf->modules_parts['hooks'])) return;
76
+		if (! is_array($conf->modules_parts['hooks']) || empty($conf->modules_parts['hooks'])) return;
77 77
 
78
-        // For backward compatibility
78
+		// For backward compatibility
79 79
 		if (! is_array($arraycontext)) $arraycontext=array($arraycontext);
80 80
 
81 81
 		$this->contextarray=array_unique(array_merge($arraycontext,$this->contextarray));    // All contexts are concatenated
@@ -86,8 +86,8 @@  discard block
 block discarded – undo
86 86
 			{
87 87
 				foreach($arraycontext as $context)
88 88
 				{
89
-				    if (is_array($hooks)) $arrayhooks=$hooks;    // New system
90
-				    else $arrayhooks=explode(':',$hooks);        // Old system (for backward compatibility)
89
+					if (is_array($hooks)) $arrayhooks=$hooks;    // New system
90
+					else $arrayhooks=explode(':',$hooks);        // Old system (for backward compatibility)
91 91
 					if (in_array($context,$arrayhooks) || in_array('all',$arrayhooks))    // We instantiate action class only if hook is required
92 92
 					{
93 93
 						$path 		= '/'.$module.'/class/';
@@ -99,9 +99,9 @@  discard block
 block discarded – undo
99 99
 						$resaction=dol_include_once($path.$actionfile);
100 100
 						if ($resaction)
101 101
 						{
102
-    						$controlclassname = 'Actions'.ucfirst($module);
103
-    						$actionInstance = new $controlclassname($this->db);
104
-    						$this->hooks[$context][$module] = $actionInstance;
102
+							$controlclassname = 'Actions'.ucfirst($module);
103
+							$actionInstance = new $controlclassname($this->db);
104
+							$this->hooks[$context][$module] = $actionInstance;
105 105
 						}
106 106
 					}
107 107
 				}
@@ -110,159 +110,159 @@  discard block
 block discarded – undo
110 110
 		return 1;
111 111
 	}
112 112
 
113
-    /**
114
-     * 		Execute hooks (if they were initialized) for the given method
115
-     *
116
-     * 		@param		string	$method			Name of method hooked ('doActions', 'printSearchForm', 'showInputField', ...)
117
-     * 	    @param		array	$parameters		Array of parameters
118
-     * 		@param		Object	$object			Object to use hooks on
119
-     * 	    @param		string	$action			Action code on calling page ('create', 'edit', 'view', 'add', 'update', 'delete'...)
120
-     * 		@return		mixed					For 'addreplace' hooks (doActions,formObjectOptions,pdf_xxx,...):  					Return 0 if we want to keep standard actions, >0 if we want to stop standard actions, <0 if KO. Things to print are returned into ->resprints and set into ->resPrint. Things to return are returned into ->results by hook and set into ->resArray for caller.
121
-     * 											For 'output' hooks (printLeftBlock, formAddObjectLine, formBuilddocOptions, ...):	Return 0, <0 if KO. Things to print are returned into ->resprints and set into ->resPrint. Things to return are returned into ->results by hook and set into ->resArray for caller.
122
-     *                                          All types can also return some values into an array ->results that will be finaly merged into this->resArray for caller.
123
-     * 											$this->error or this->errors are also defined by class called by this function if error.
124
-     */
113
+	/**
114
+	 * 		Execute hooks (if they were initialized) for the given method
115
+	 *
116
+	 * 		@param		string	$method			Name of method hooked ('doActions', 'printSearchForm', 'showInputField', ...)
117
+	 * 	    @param		array	$parameters		Array of parameters
118
+	 * 		@param		Object	$object			Object to use hooks on
119
+	 * 	    @param		string	$action			Action code on calling page ('create', 'edit', 'view', 'add', 'update', 'delete'...)
120
+	 * 		@return		mixed					For 'addreplace' hooks (doActions,formObjectOptions,pdf_xxx,...):  					Return 0 if we want to keep standard actions, >0 if we want to stop standard actions, <0 if KO. Things to print are returned into ->resprints and set into ->resPrint. Things to return are returned into ->results by hook and set into ->resArray for caller.
121
+	 * 											For 'output' hooks (printLeftBlock, formAddObjectLine, formBuilddocOptions, ...):	Return 0, <0 if KO. Things to print are returned into ->resprints and set into ->resPrint. Things to return are returned into ->results by hook and set into ->resArray for caller.
122
+	 *                                          All types can also return some values into an array ->results that will be finaly merged into this->resArray for caller.
123
+	 * 											$this->error or this->errors are also defined by class called by this function if error.
124
+	 */
125 125
 	function executeHooks($method, $parameters=array(), &$object='', &$action='')
126 126
 	{
127
-        if (! is_array($this->hooks) || empty($this->hooks)) return '';
127
+		if (! is_array($this->hooks) || empty($this->hooks)) return '';
128 128
 
129
-        $parameters['context']=join(':',$this->contextarray);
130
-        //dol_syslog(get_class($this).'::executeHooks method='.$method." action=".$action." context=".$parameters['context']);
129
+		$parameters['context']=join(':',$this->contextarray);
130
+		//dol_syslog(get_class($this).'::executeHooks method='.$method." action=".$action." context=".$parameters['context']);
131 131
 
132
-        // Define type of hook ('output' or 'addreplace'. 'returnvalue' is deprecated because a 'addreplace' hook can also return resPrint and resArray).
133
-        $hooktype='output';
132
+		// Define type of hook ('output' or 'addreplace'. 'returnvalue' is deprecated because a 'addreplace' hook can also return resPrint and resArray).
133
+		$hooktype='output';
134 134
 		if (in_array(
135 135
 			$method,
136 136
 			array(
137
-                'addCalendarChoice',
138
-			    'addMoreActionsButtons',
139
-			    'addMoreMassActions',
140
-			    'addSearchEntry',
137
+				'addCalendarChoice',
138
+				'addMoreActionsButtons',
139
+				'addMoreMassActions',
140
+				'addSearchEntry',
141 141
 				'addStatisticLine',
142
-			    'deleteFile',
142
+				'deleteFile',
143 143
 				'doActions',
144
-			    'doMassActions',
144
+				'doMassActions',
145 145
 				'formCreateThirdpartyOptions',
146 146
 				'formObjectOptions',
147 147
 				'formattachOptions',
148 148
 				'formBuilddocLineOptions',
149
-			    'formatNotificationMessage',
150
-			    'getFormMail',
151
-			    'getIdProfUrl',
152
-			    'getDirList',
149
+				'formatNotificationMessage',
150
+				'getFormMail',
151
+				'getIdProfUrl',
152
+				'getDirList',
153 153
 				'moveUploadedFile',
154
-			    'pdf_build_address',
154
+				'pdf_build_address',
155 155
 				'pdf_writelinedesc',
156
-			    'pdf_getlinenum',
157
-			    'pdf_getlineref',
158
-			    'pdf_getlineref_supplier',
159
-			    'pdf_getlinevatrate',
160
-			    'pdf_getlineupexcltax',
161
-			    'pdf_getlineupwithtax',
162
-			    'pdf_getlineqty',
163
-			    'pdf_getlineqty_asked',
164
-			    'pdf_getlineqty_shipped',
165
-			    'pdf_getlineqty_keeptoship',
166
-			    'pdf_getlineunit',
167
-			    'pdf_getlineremisepercent',
168
-			    'pdf_getlineprogress',
169
-			    'pdf_getlinetotalexcltax',
170
-			    'pdf_getlinetotalwithtax',
156
+				'pdf_getlinenum',
157
+				'pdf_getlineref',
158
+				'pdf_getlineref_supplier',
159
+				'pdf_getlinevatrate',
160
+				'pdf_getlineupexcltax',
161
+				'pdf_getlineupwithtax',
162
+				'pdf_getlineqty',
163
+				'pdf_getlineqty_asked',
164
+				'pdf_getlineqty_shipped',
165
+				'pdf_getlineqty_keeptoship',
166
+				'pdf_getlineunit',
167
+				'pdf_getlineremisepercent',
168
+				'pdf_getlineprogress',
169
+				'pdf_getlinetotalexcltax',
170
+				'pdf_getlinetotalwithtax',
171 171
 				'paymentsupplierinvoices',
172 172
 				'printAddress',
173 173
 				'printSearchForm',
174 174
 				'printTabsHead',
175 175
 				'formatEvent',
176
-                'printObjectLine',
177
-                'printObjectSubLine',
176
+				'printObjectLine',
177
+				'printObjectSubLine',
178 178
 				'createDictionaryFieldList',
179 179
 				'editDictionaryFieldlist',
180 180
 				'getFormMail',
181
-			    'showLinkToObjectBlock'
181
+				'showLinkToObjectBlock'
182 182
 				)
183 183
 			)) $hooktype='addreplace';
184 184
 
185
-        if ($method == 'insertExtraFields')
186
-        {
187
-        	$hooktype='returnvalue';	// @deprecated. TODO Remove all code with "executeHooks('insertExtraFields'" as soon as there is a trigger available.
188
-        	dol_syslog("Warning: The hook 'insertExtraFields' is deprecated and must not be used. Use instead trigger on CRUD event (ask it to dev team if not implemented)", LOG_WARNING);
189
-        }
190
-
191
-        // Init return properties
192
-        $this->resPrint=''; $this->resArray=array(); $this->resNbOfHooks=0;
193
-
194
-        // Loop on each hook to qualify modules that have declared context
195
-        $modulealreadyexecuted=array();
196
-        $resaction=0; $error=0; $result='';
197
-        foreach($this->hooks as $context => $modules)    // $this->hooks is an array with context as key and value is an array of modules that handle this context
198
-        {
199
-            if (! empty($modules))
200
-            {
201
-                foreach($modules as $module => $actionclassinstance)
202
-                {
203
-                	//print "Before hook ".get_class($actionclassinstance)." method=".$method." hooktype=".$hooktype." results=".count($actionclassinstance->results)." resprints=".count($actionclassinstance->resprints)." resaction=".$resaction." result=".$result."<br>\n";
204
-
205
-                    // test to avoid running twice a hook, when a module implements several active contexts
206
-                    if (in_array($module,$modulealreadyexecuted)) continue;
207
-
208
-                	// jump to next module/class if method does not exist
209
-                    if (! method_exists($actionclassinstance,$method)) continue;
210
-
211
-                    $this->resNbOfHooks++;
212
-
213
-                    dol_syslog(get_class($this).'::executeHooks a qualified hook was found for method='.$method.' module='.$module." action=".$action." context=".$context);
214
-
215
-                    $modulealreadyexecuted[$module]=$module; // Use the $currentcontext in method to avoid running twice
216
-
217
-                    // Clean class (an error may have been set from a previous call of another method for same module/hook)
218
-                    $actionclassinstance->error=0;
219
-                    $actionclassinstance->errors=array();
220
-
221
-                    // Add current context to avoid method execution in bad context, you can add this test in your method : eg if($currentcontext != 'formfile') return;
222
-                    $parameters['currentcontext'] = $context;
223
-                    // Hooks that must return int (hooks with type 'addreplace')
224
-                    if ($hooktype == 'addreplace')
225
-                    {
226
-                    	dol_syslog("Call method ".$method." of class ".get_class($actionclassinstance).", module=".$module.", hooktype=".$hooktype, LOG_DEBUG);
227
-                    	$resaction += $actionclassinstance->$method($parameters, $object, $action, $this); // $object and $action can be changed by method ($object->id during creation for example or $action to go back to other action for example)
228
-                    	if ($resaction < 0 || ! empty($actionclassinstance->error) || (! empty($actionclassinstance->errors) && count($actionclassinstance->errors) > 0))
229
-                    	{
230
-                    		$error++;
231
-                    		$this->error=$actionclassinstance->error; $this->errors=array_merge($this->errors, (array) $actionclassinstance->errors);
232
-                    		dol_syslog("Error on hook module=".$module.", method ".$method.", class ".get_class($actionclassinstance).", hooktype=".$hooktype.(empty($this->error)?'':" ".$this->error).(empty($this->errors)?'':" ".join(",",$this->errors)), LOG_ERR);
233
-                    	}
234
-
235
-                    	if (isset($actionclassinstance->results) && is_array($actionclassinstance->results))  $this->resArray =array_merge($this->resArray, $actionclassinstance->results);
236
-                    	if (! empty($actionclassinstance->resprints)) $this->resPrint.=$actionclassinstance->resprints;
237
-                    }
238
-                    // Generic hooks that return a string or array (printLeftBlock, formAddObjectLine, formBuilddocOptions, ...)
239
-                    else
185
+		if ($method == 'insertExtraFields')
186
+		{
187
+			$hooktype='returnvalue';	// @deprecated. TODO Remove all code with "executeHooks('insertExtraFields'" as soon as there is a trigger available.
188
+			dol_syslog("Warning: The hook 'insertExtraFields' is deprecated and must not be used. Use instead trigger on CRUD event (ask it to dev team if not implemented)", LOG_WARNING);
189
+		}
190
+
191
+		// Init return properties
192
+		$this->resPrint=''; $this->resArray=array(); $this->resNbOfHooks=0;
193
+
194
+		// Loop on each hook to qualify modules that have declared context
195
+		$modulealreadyexecuted=array();
196
+		$resaction=0; $error=0; $result='';
197
+		foreach($this->hooks as $context => $modules)    // $this->hooks is an array with context as key and value is an array of modules that handle this context
198
+		{
199
+			if (! empty($modules))
200
+			{
201
+				foreach($modules as $module => $actionclassinstance)
202
+				{
203
+					//print "Before hook ".get_class($actionclassinstance)." method=".$method." hooktype=".$hooktype." results=".count($actionclassinstance->results)." resprints=".count($actionclassinstance->resprints)." resaction=".$resaction." result=".$result."<br>\n";
204
+
205
+					// test to avoid running twice a hook, when a module implements several active contexts
206
+					if (in_array($module,$modulealreadyexecuted)) continue;
207
+
208
+					// jump to next module/class if method does not exist
209
+					if (! method_exists($actionclassinstance,$method)) continue;
210
+
211
+					$this->resNbOfHooks++;
212
+
213
+					dol_syslog(get_class($this).'::executeHooks a qualified hook was found for method='.$method.' module='.$module." action=".$action." context=".$context);
214
+
215
+					$modulealreadyexecuted[$module]=$module; // Use the $currentcontext in method to avoid running twice
216
+
217
+					// Clean class (an error may have been set from a previous call of another method for same module/hook)
218
+					$actionclassinstance->error=0;
219
+					$actionclassinstance->errors=array();
220
+
221
+					// Add current context to avoid method execution in bad context, you can add this test in your method : eg if($currentcontext != 'formfile') return;
222
+					$parameters['currentcontext'] = $context;
223
+					// Hooks that must return int (hooks with type 'addreplace')
224
+					if ($hooktype == 'addreplace')
240 225
 					{
241
-                    	// TODO. this test should be done into the method of hook by returning nothing
242
-                    	if (is_array($parameters) && ! empty($parameters['special_code']) && $parameters['special_code'] > 3 && $parameters['special_code'] != $actionclassinstance->module_number) continue;
243
-
244
-                    	//dol_syslog("Call method ".$method." of class ".get_class($actionclassinstance).", module=".$module.", hooktype=".$hooktype, LOG_DEBUG);
245
-                    	$resaction = $actionclassinstance->$method($parameters, $object, $action, $this); // $object and $action can be changed by method ($object->id during creation for example or $action to go back to other action for example)
246
-
247
-                    	if (! empty($actionclassinstance->results) && is_array($actionclassinstance->results)) $this->resArray =array_merge($this->resArray, $actionclassinstance->results);
248
-                    	if (! empty($actionclassinstance->resprints)) $this->resPrint.=$actionclassinstance->resprints;
249
-                    	// TODO dead code to remove (do not enable this, but fix hook instead): result must not be a string but an int. you must use $actionclassinstance->resprints to return a string
250
-                    	if (! is_array($resaction) && ! is_numeric($resaction))
251
-                    	{
252
-                    		dol_syslog('Error: Bug into hook '.$method.' of module class '.get_class($actionclassinstance).'. Method must not return a string but an int (0=OK, 1=Replace, -1=KO) and set string into ->resprints', LOG_ERR);
253
-                    		if (empty($actionclassinstance->resprints)) { $this->resPrint.=$resaction; $resaction=0; }
254
-                    	}
255
-                    }
256
-
257
-                    //print "After hook  ".get_class($actionclassinstance)." method=".$method." hooktype=".$hooktype." results=".count($actionclassinstance->results)." resprints=".count($actionclassinstance->resprints)." resaction=".$resaction." result=".$result."<br>\n";
258
-
259
-                    unset($actionclassinstance->results);
260
-                    unset($actionclassinstance->resprints);
261
-                }
262
-            }
263
-        }
264
-
265
-        return ($error?-1:$resaction);
226
+						dol_syslog("Call method ".$method." of class ".get_class($actionclassinstance).", module=".$module.", hooktype=".$hooktype, LOG_DEBUG);
227
+						$resaction += $actionclassinstance->$method($parameters, $object, $action, $this); // $object and $action can be changed by method ($object->id during creation for example or $action to go back to other action for example)
228
+						if ($resaction < 0 || ! empty($actionclassinstance->error) || (! empty($actionclassinstance->errors) && count($actionclassinstance->errors) > 0))
229
+						{
230
+							$error++;
231
+							$this->error=$actionclassinstance->error; $this->errors=array_merge($this->errors, (array) $actionclassinstance->errors);
232
+							dol_syslog("Error on hook module=".$module.", method ".$method.", class ".get_class($actionclassinstance).", hooktype=".$hooktype.(empty($this->error)?'':" ".$this->error).(empty($this->errors)?'':" ".join(",",$this->errors)), LOG_ERR);
233
+						}
234
+
235
+						if (isset($actionclassinstance->results) && is_array($actionclassinstance->results))  $this->resArray =array_merge($this->resArray, $actionclassinstance->results);
236
+						if (! empty($actionclassinstance->resprints)) $this->resPrint.=$actionclassinstance->resprints;
237
+					}
238
+					// Generic hooks that return a string or array (printLeftBlock, formAddObjectLine, formBuilddocOptions, ...)
239
+					else
240
+					{
241
+						// TODO. this test should be done into the method of hook by returning nothing
242
+						if (is_array($parameters) && ! empty($parameters['special_code']) && $parameters['special_code'] > 3 && $parameters['special_code'] != $actionclassinstance->module_number) continue;
243
+
244
+						//dol_syslog("Call method ".$method." of class ".get_class($actionclassinstance).", module=".$module.", hooktype=".$hooktype, LOG_DEBUG);
245
+						$resaction = $actionclassinstance->$method($parameters, $object, $action, $this); // $object and $action can be changed by method ($object->id during creation for example or $action to go back to other action for example)
246
+
247
+						if (! empty($actionclassinstance->results) && is_array($actionclassinstance->results)) $this->resArray =array_merge($this->resArray, $actionclassinstance->results);
248
+						if (! empty($actionclassinstance->resprints)) $this->resPrint.=$actionclassinstance->resprints;
249
+						// TODO dead code to remove (do not enable this, but fix hook instead): result must not be a string but an int. you must use $actionclassinstance->resprints to return a string
250
+						if (! is_array($resaction) && ! is_numeric($resaction))
251
+						{
252
+							dol_syslog('Error: Bug into hook '.$method.' of module class '.get_class($actionclassinstance).'. Method must not return a string but an int (0=OK, 1=Replace, -1=KO) and set string into ->resprints', LOG_ERR);
253
+							if (empty($actionclassinstance->resprints)) { $this->resPrint.=$resaction; $resaction=0; }
254
+						}
255
+					}
256
+
257
+					//print "After hook  ".get_class($actionclassinstance)." method=".$method." hooktype=".$hooktype." results=".count($actionclassinstance->results)." resprints=".count($actionclassinstance->resprints)." resaction=".$resaction." result=".$result."<br>\n";
258
+
259
+					unset($actionclassinstance->results);
260
+					unset($actionclassinstance->resprints);
261
+				}
262
+			}
263
+		}
264
+
265
+		return ($error?-1:$resaction);
266 266
 	}
267 267
 
268 268
 }
Please login to merge, or discard this patch.
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -31,20 +31,20 @@  discard block
 block discarded – undo
31 31
 {
32 32
 	var $db;
33 33
 	var $error;
34
-	var $errors=array();
34
+	var $errors = array();
35 35
 
36 36
     // Context hookmanager was created for ('thirdpartycard', 'thirdpartydao', ...)
37
-    var $contextarray=array();
37
+    var $contextarray = array();
38 38
 
39 39
 	// Array with instantiated classes
40
-	var $hooks=array();
40
+	var $hooks = array();
41 41
 
42 42
 	// Array result
43
-	var $resArray=array();
43
+	var $resArray = array();
44 44
 	// Printable result
45
-	var $resPrint='';
45
+	var $resPrint = '';
46 46
 	// Nb of qualified hook ran
47
-	var $resNbOfHooks=0;
47
+	var $resNbOfHooks = 0;
48 48
 
49 49
 	/**
50 50
 	 * Constructor
@@ -73,30 +73,30 @@  discard block
 block discarded – undo
73 73
 		global $conf;
74 74
 
75 75
 		// Test if there is hooks to manage
76
-        if (! is_array($conf->modules_parts['hooks']) || empty($conf->modules_parts['hooks'])) return;
76
+        if (!is_array($conf->modules_parts['hooks']) || empty($conf->modules_parts['hooks'])) return;
77 77
 
78 78
         // For backward compatibility
79
-		if (! is_array($arraycontext)) $arraycontext=array($arraycontext);
79
+		if (!is_array($arraycontext)) $arraycontext = array($arraycontext);
80 80
 
81
-		$this->contextarray=array_unique(array_merge($arraycontext,$this->contextarray));    // All contexts are concatenated
81
+		$this->contextarray = array_unique(array_merge($arraycontext, $this->contextarray)); // All contexts are concatenated
82 82
 
83
-		foreach($conf->modules_parts['hooks'] as $module => $hooks)
83
+		foreach ($conf->modules_parts['hooks'] as $module => $hooks)
84 84
 		{
85 85
 			if ($conf->$module->enabled)
86 86
 			{
87
-				foreach($arraycontext as $context)
87
+				foreach ($arraycontext as $context)
88 88
 				{
89
-				    if (is_array($hooks)) $arrayhooks=$hooks;    // New system
90
-				    else $arrayhooks=explode(':',$hooks);        // Old system (for backward compatibility)
91
-					if (in_array($context,$arrayhooks) || in_array('all',$arrayhooks))    // We instantiate action class only if hook is required
89
+				    if (is_array($hooks)) $arrayhooks = $hooks; // New system
90
+				    else $arrayhooks = explode(':', $hooks); // Old system (for backward compatibility)
91
+					if (in_array($context, $arrayhooks) || in_array('all', $arrayhooks))    // We instantiate action class only if hook is required
92 92
 					{
93
-						$path 		= '/'.$module.'/class/';
93
+						$path = '/'.$module.'/class/';
94 94
 						$actionfile = 'actions_'.$module.'.class.php';
95
-						$pathroot	= '';
95
+						$pathroot = '';
96 96
 
97 97
 						// Include actions class overwriting hooks
98
-						dol_syslog('Loading hook:' . $actionfile, LOG_INFO);
99
-						$resaction=dol_include_once($path.$actionfile);
98
+						dol_syslog('Loading hook:'.$actionfile, LOG_INFO);
99
+						$resaction = dol_include_once($path.$actionfile);
100 100
 						if ($resaction)
101 101
 						{
102 102
     						$controlclassname = 'Actions'.ucfirst($module);
@@ -122,15 +122,15 @@  discard block
 block discarded – undo
122 122
      *                                          All types can also return some values into an array ->results that will be finaly merged into this->resArray for caller.
123 123
      * 											$this->error or this->errors are also defined by class called by this function if error.
124 124
      */
125
-	function executeHooks($method, $parameters=array(), &$object='', &$action='')
125
+	function executeHooks($method, $parameters = array(), &$object = '', &$action = '')
126 126
 	{
127
-        if (! is_array($this->hooks) || empty($this->hooks)) return '';
127
+        if (!is_array($this->hooks) || empty($this->hooks)) return '';
128 128
 
129
-        $parameters['context']=join(':',$this->contextarray);
129
+        $parameters['context'] = join(':', $this->contextarray);
130 130
         //dol_syslog(get_class($this).'::executeHooks method='.$method." action=".$action." context=".$parameters['context']);
131 131
 
132 132
         // Define type of hook ('output' or 'addreplace'. 'returnvalue' is deprecated because a 'addreplace' hook can also return resPrint and resArray).
133
-        $hooktype='output';
133
+        $hooktype = 'output';
134 134
 		if (in_array(
135 135
 			$method,
136 136
 			array(
@@ -180,43 +180,43 @@  discard block
 block discarded – undo
180 180
 				'getFormMail',
181 181
 			    'showLinkToObjectBlock'
182 182
 				)
183
-			)) $hooktype='addreplace';
183
+			)) $hooktype = 'addreplace';
184 184
 
185 185
         if ($method == 'insertExtraFields')
186 186
         {
187
-        	$hooktype='returnvalue';	// @deprecated. TODO Remove all code with "executeHooks('insertExtraFields'" as soon as there is a trigger available.
187
+        	$hooktype = 'returnvalue'; // @deprecated. TODO Remove all code with "executeHooks('insertExtraFields'" as soon as there is a trigger available.
188 188
         	dol_syslog("Warning: The hook 'insertExtraFields' is deprecated and must not be used. Use instead trigger on CRUD event (ask it to dev team if not implemented)", LOG_WARNING);
189 189
         }
190 190
 
191 191
         // Init return properties
192
-        $this->resPrint=''; $this->resArray=array(); $this->resNbOfHooks=0;
192
+        $this->resPrint = ''; $this->resArray = array(); $this->resNbOfHooks = 0;
193 193
 
194 194
         // Loop on each hook to qualify modules that have declared context
195
-        $modulealreadyexecuted=array();
196
-        $resaction=0; $error=0; $result='';
197
-        foreach($this->hooks as $context => $modules)    // $this->hooks is an array with context as key and value is an array of modules that handle this context
195
+        $modulealreadyexecuted = array();
196
+        $resaction = 0; $error = 0; $result = '';
197
+        foreach ($this->hooks as $context => $modules)    // $this->hooks is an array with context as key and value is an array of modules that handle this context
198 198
         {
199
-            if (! empty($modules))
199
+            if (!empty($modules))
200 200
             {
201
-                foreach($modules as $module => $actionclassinstance)
201
+                foreach ($modules as $module => $actionclassinstance)
202 202
                 {
203 203
                 	//print "Before hook ".get_class($actionclassinstance)." method=".$method." hooktype=".$hooktype." results=".count($actionclassinstance->results)." resprints=".count($actionclassinstance->resprints)." resaction=".$resaction." result=".$result."<br>\n";
204 204
 
205 205
                     // test to avoid running twice a hook, when a module implements several active contexts
206
-                    if (in_array($module,$modulealreadyexecuted)) continue;
206
+                    if (in_array($module, $modulealreadyexecuted)) continue;
207 207
 
208 208
                 	// jump to next module/class if method does not exist
209
-                    if (! method_exists($actionclassinstance,$method)) continue;
209
+                    if (!method_exists($actionclassinstance, $method)) continue;
210 210
 
211 211
                     $this->resNbOfHooks++;
212 212
 
213 213
                     dol_syslog(get_class($this).'::executeHooks a qualified hook was found for method='.$method.' module='.$module." action=".$action." context=".$context);
214 214
 
215
-                    $modulealreadyexecuted[$module]=$module; // Use the $currentcontext in method to avoid running twice
215
+                    $modulealreadyexecuted[$module] = $module; // Use the $currentcontext in method to avoid running twice
216 216
 
217 217
                     // Clean class (an error may have been set from a previous call of another method for same module/hook)
218
-                    $actionclassinstance->error=0;
219
-                    $actionclassinstance->errors=array();
218
+                    $actionclassinstance->error = 0;
219
+                    $actionclassinstance->errors = array();
220 220
 
221 221
                     // Add current context to avoid method execution in bad context, you can add this test in your method : eg if($currentcontext != 'formfile') return;
222 222
                     $parameters['currentcontext'] = $context;
@@ -225,32 +225,32 @@  discard block
 block discarded – undo
225 225
                     {
226 226
                     	dol_syslog("Call method ".$method." of class ".get_class($actionclassinstance).", module=".$module.", hooktype=".$hooktype, LOG_DEBUG);
227 227
                     	$resaction += $actionclassinstance->$method($parameters, $object, $action, $this); // $object and $action can be changed by method ($object->id during creation for example or $action to go back to other action for example)
228
-                    	if ($resaction < 0 || ! empty($actionclassinstance->error) || (! empty($actionclassinstance->errors) && count($actionclassinstance->errors) > 0))
228
+                    	if ($resaction < 0 || !empty($actionclassinstance->error) || (!empty($actionclassinstance->errors) && count($actionclassinstance->errors) > 0))
229 229
                     	{
230 230
                     		$error++;
231
-                    		$this->error=$actionclassinstance->error; $this->errors=array_merge($this->errors, (array) $actionclassinstance->errors);
232
-                    		dol_syslog("Error on hook module=".$module.", method ".$method.", class ".get_class($actionclassinstance).", hooktype=".$hooktype.(empty($this->error)?'':" ".$this->error).(empty($this->errors)?'':" ".join(",",$this->errors)), LOG_ERR);
231
+                    		$this->error = $actionclassinstance->error; $this->errors = array_merge($this->errors, (array) $actionclassinstance->errors);
232
+                    		dol_syslog("Error on hook module=".$module.", method ".$method.", class ".get_class($actionclassinstance).", hooktype=".$hooktype.(empty($this->error) ? '' : " ".$this->error).(empty($this->errors) ? '' : " ".join(",", $this->errors)), LOG_ERR);
233 233
                     	}
234 234
 
235
-                    	if (isset($actionclassinstance->results) && is_array($actionclassinstance->results))  $this->resArray =array_merge($this->resArray, $actionclassinstance->results);
236
-                    	if (! empty($actionclassinstance->resprints)) $this->resPrint.=$actionclassinstance->resprints;
235
+                    	if (isset($actionclassinstance->results) && is_array($actionclassinstance->results))  $this->resArray = array_merge($this->resArray, $actionclassinstance->results);
236
+                    	if (!empty($actionclassinstance->resprints)) $this->resPrint .= $actionclassinstance->resprints;
237 237
                     }
238 238
                     // Generic hooks that return a string or array (printLeftBlock, formAddObjectLine, formBuilddocOptions, ...)
239 239
                     else
240 240
 					{
241 241
                     	// TODO. this test should be done into the method of hook by returning nothing
242
-                    	if (is_array($parameters) && ! empty($parameters['special_code']) && $parameters['special_code'] > 3 && $parameters['special_code'] != $actionclassinstance->module_number) continue;
242
+                    	if (is_array($parameters) && !empty($parameters['special_code']) && $parameters['special_code'] > 3 && $parameters['special_code'] != $actionclassinstance->module_number) continue;
243 243
 
244 244
                     	//dol_syslog("Call method ".$method." of class ".get_class($actionclassinstance).", module=".$module.", hooktype=".$hooktype, LOG_DEBUG);
245 245
                     	$resaction = $actionclassinstance->$method($parameters, $object, $action, $this); // $object and $action can be changed by method ($object->id during creation for example or $action to go back to other action for example)
246 246
 
247
-                    	if (! empty($actionclassinstance->results) && is_array($actionclassinstance->results)) $this->resArray =array_merge($this->resArray, $actionclassinstance->results);
248
-                    	if (! empty($actionclassinstance->resprints)) $this->resPrint.=$actionclassinstance->resprints;
247
+                    	if (!empty($actionclassinstance->results) && is_array($actionclassinstance->results)) $this->resArray = array_merge($this->resArray, $actionclassinstance->results);
248
+                    	if (!empty($actionclassinstance->resprints)) $this->resPrint .= $actionclassinstance->resprints;
249 249
                     	// TODO dead code to remove (do not enable this, but fix hook instead): result must not be a string but an int. you must use $actionclassinstance->resprints to return a string
250
-                    	if (! is_array($resaction) && ! is_numeric($resaction))
250
+                    	if (!is_array($resaction) && !is_numeric($resaction))
251 251
                     	{
252 252
                     		dol_syslog('Error: Bug into hook '.$method.' of module class '.get_class($actionclassinstance).'. Method must not return a string but an int (0=OK, 1=Replace, -1=KO) and set string into ->resprints', LOG_ERR);
253
-                    		if (empty($actionclassinstance->resprints)) { $this->resPrint.=$resaction; $resaction=0; }
253
+                    		if (empty($actionclassinstance->resprints)) { $this->resPrint .= $resaction; $resaction = 0; }
254 254
                     	}
255 255
                     }
256 256
 
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
             }
263 263
         }
264 264
 
265
-        return ($error?-1:$resaction);
265
+        return ($error ?-1 : $resaction);
266 266
 	}
267 267
 
268 268
 }
Please login to merge, or discard this patch.
Braces   +44 added lines, -14 removed lines patch added patch discarded remove patch
@@ -73,10 +73,14 @@  discard block
 block discarded – undo
73 73
 		global $conf;
74 74
 
75 75
 		// Test if there is hooks to manage
76
-        if (! is_array($conf->modules_parts['hooks']) || empty($conf->modules_parts['hooks'])) return;
76
+        if (! is_array($conf->modules_parts['hooks']) || empty($conf->modules_parts['hooks'])) {
77
+        	return;
78
+        }
77 79
 
78 80
         // For backward compatibility
79
-		if (! is_array($arraycontext)) $arraycontext=array($arraycontext);
81
+		if (! is_array($arraycontext)) {
82
+			$arraycontext=array($arraycontext);
83
+		}
80 84
 
81 85
 		$this->contextarray=array_unique(array_merge($arraycontext,$this->contextarray));    // All contexts are concatenated
82 86
 
@@ -86,11 +90,19 @@  discard block
 block discarded – undo
86 90
 			{
87 91
 				foreach($arraycontext as $context)
88 92
 				{
89
-				    if (is_array($hooks)) $arrayhooks=$hooks;    // New system
90
-				    else $arrayhooks=explode(':',$hooks);        // Old system (for backward compatibility)
91
-					if (in_array($context,$arrayhooks) || in_array('all',$arrayhooks))    // We instantiate action class only if hook is required
93
+				    if (is_array($hooks)) {
94
+				    	$arrayhooks=$hooks;
95
+				    }
96
+				    // New system
97
+				    else {
98
+				    	$arrayhooks=explode(':',$hooks);
99
+				    }
100
+				    // Old system (for backward compatibility)
101
+					if (in_array($context,$arrayhooks) || in_array('all',$arrayhooks)) {
102
+						// We instantiate action class only if hook is required
92 103
 					{
93 104
 						$path 		= '/'.$module.'/class/';
105
+					}
94 106
 						$actionfile = 'actions_'.$module.'.class.php';
95 107
 						$pathroot	= '';
96 108
 
@@ -124,7 +136,9 @@  discard block
 block discarded – undo
124 136
      */
125 137
 	function executeHooks($method, $parameters=array(), &$object='', &$action='')
126 138
 	{
127
-        if (! is_array($this->hooks) || empty($this->hooks)) return '';
139
+        if (! is_array($this->hooks) || empty($this->hooks)) {
140
+        	return '';
141
+        }
128 142
 
129 143
         $parameters['context']=join(':',$this->contextarray);
130 144
         //dol_syslog(get_class($this).'::executeHooks method='.$method." action=".$action." context=".$parameters['context']);
@@ -180,7 +194,9 @@  discard block
 block discarded – undo
180 194
 				'getFormMail',
181 195
 			    'showLinkToObjectBlock'
182 196
 				)
183
-			)) $hooktype='addreplace';
197
+			)) {
198
+			$hooktype='addreplace';
199
+		}
184 200
 
185 201
         if ($method == 'insertExtraFields')
186 202
         {
@@ -194,7 +210,8 @@  discard block
 block discarded – undo
194 210
         // Loop on each hook to qualify modules that have declared context
195 211
         $modulealreadyexecuted=array();
196 212
         $resaction=0; $error=0; $result='';
197
-        foreach($this->hooks as $context => $modules)    // $this->hooks is an array with context as key and value is an array of modules that handle this context
213
+        foreach($this->hooks as $context => $modules) {
214
+        	// $this->hooks is an array with context as key and value is an array of modules that handle this context
198 215
         {
199 216
             if (! empty($modules))
200 217
             {
@@ -204,9 +221,12 @@  discard block
 block discarded – undo
204 221
 
205 222
                     // test to avoid running twice a hook, when a module implements several active contexts
206 223
                     if (in_array($module,$modulealreadyexecuted)) continue;
224
+        }
207 225
 
208 226
                 	// jump to next module/class if method does not exist
209
-                    if (! method_exists($actionclassinstance,$method)) continue;
227
+                    if (! method_exists($actionclassinstance,$method)) {
228
+                    	continue;
229
+                    }
210 230
 
211 231
                     $this->resNbOfHooks++;
212 232
 
@@ -232,20 +252,30 @@  discard block
 block discarded – undo
232 252
                     		dol_syslog("Error on hook module=".$module.", method ".$method.", class ".get_class($actionclassinstance).", hooktype=".$hooktype.(empty($this->error)?'':" ".$this->error).(empty($this->errors)?'':" ".join(",",$this->errors)), LOG_ERR);
233 253
                     	}
234 254
 
235
-                    	if (isset($actionclassinstance->results) && is_array($actionclassinstance->results))  $this->resArray =array_merge($this->resArray, $actionclassinstance->results);
236
-                    	if (! empty($actionclassinstance->resprints)) $this->resPrint.=$actionclassinstance->resprints;
255
+                    	if (isset($actionclassinstance->results) && is_array($actionclassinstance->results)) {
256
+                    		$this->resArray =array_merge($this->resArray, $actionclassinstance->results);
257
+                    	}
258
+                    	if (! empty($actionclassinstance->resprints)) {
259
+                    		$this->resPrint.=$actionclassinstance->resprints;
260
+                    	}
237 261
                     }
238 262
                     // Generic hooks that return a string or array (printLeftBlock, formAddObjectLine, formBuilddocOptions, ...)
239 263
                     else
240 264
 					{
241 265
                     	// TODO. this test should be done into the method of hook by returning nothing
242
-                    	if (is_array($parameters) && ! empty($parameters['special_code']) && $parameters['special_code'] > 3 && $parameters['special_code'] != $actionclassinstance->module_number) continue;
266
+                    	if (is_array($parameters) && ! empty($parameters['special_code']) && $parameters['special_code'] > 3 && $parameters['special_code'] != $actionclassinstance->module_number) {
267
+                    		continue;
268
+                    	}
243 269
 
244 270
                     	//dol_syslog("Call method ".$method." of class ".get_class($actionclassinstance).", module=".$module.", hooktype=".$hooktype, LOG_DEBUG);
245 271
                     	$resaction = $actionclassinstance->$method($parameters, $object, $action, $this); // $object and $action can be changed by method ($object->id during creation for example or $action to go back to other action for example)
246 272
 
247
-                    	if (! empty($actionclassinstance->results) && is_array($actionclassinstance->results)) $this->resArray =array_merge($this->resArray, $actionclassinstance->results);
248
-                    	if (! empty($actionclassinstance->resprints)) $this->resPrint.=$actionclassinstance->resprints;
273
+                    	if (! empty($actionclassinstance->results) && is_array($actionclassinstance->results)) {
274
+                    		$this->resArray =array_merge($this->resArray, $actionclassinstance->results);
275
+                    	}
276
+                    	if (! empty($actionclassinstance->resprints)) {
277
+                    		$this->resPrint.=$actionclassinstance->resprints;
278
+                    	}
249 279
                     	// TODO dead code to remove (do not enable this, but fix hook instead): result must not be a string but an int. you must use $actionclassinstance->resprints to return a string
250 280
                     	if (! is_array($resaction) && ! is_numeric($resaction))
251 281
                     	{
Please login to merge, or discard this patch.
htdocs/core/class/dolreceiptprinter.class.php 3 patches
Indentation   +555 added lines, -555 removed lines patch added patch discarded remove patch
@@ -100,591 +100,591 @@
 block discarded – undo
100 100
  */
101 101
 class dolReceiptPrinter extends Escpos
102 102
 {
103
-    const CONNECTOR_DUMMY = 1;
104
-    const CONNECTOR_FILE_PRINT = 2;
105
-    const CONNECTOR_NETWORK_PRINT = 3;
106
-    const CONNECTOR_WINDOWS_PRINT = 4;
107
-    //const CONNECTOR_JAVA = 5;
108
-    var $db;
109
-    var $tags;
110
-    var $printer;
111
-    var $template;
112
-    var $error;
113
-    var $errors;
103
+	const CONNECTOR_DUMMY = 1;
104
+	const CONNECTOR_FILE_PRINT = 2;
105
+	const CONNECTOR_NETWORK_PRINT = 3;
106
+	const CONNECTOR_WINDOWS_PRINT = 4;
107
+	//const CONNECTOR_JAVA = 5;
108
+	var $db;
109
+	var $tags;
110
+	var $printer;
111
+	var $template;
112
+	var $error;
113
+	var $errors;
114 114
 
115 115
 
116 116
 
117
-    /**
118
-     * Constructor
119
-     *
120
-     * @param   DoliDB      $db         database
121
-     */
122
-    function __construct($db)
123
-    {
124
-        $this->db=$db;
125
-        $this->tags = array(
126
-            'dol_align_left',
127
-            'dol_align_center',
128
-            'dol_align_right',
129
-            'dol_use_font_a',
130
-            'dol_use_font_b',
131
-            'dol_use_font_c',
132
-            'dol_bold',
133
-            '/dol_bold',
134
-            'dol_double_height',
135
-            '/dol_double_height',
136
-            'dol_double_width',
137
-            '/dol_double_width',
138
-            'dol_underline',
139
-            '/dol_underline',
140
-            'dol_underline_2dots',
141
-            '/dol_underline',
142
-            'dol_emphasized',
143
-            '/dol_emphasized',
144
-            'dol_switch_colors',
145
-            '/dol_switch_colors',
146
-            'dol_print_barcode',
147
-            'dol_print_barcode_customer_id',
148
-            'dol_set_print_width_57',
149
-            'dol_cut_paper_full',
150
-            'dol_cut_paper_partial',
151
-            'dol_open_drawer',
152
-            'dol_activate_buzzer',
153
-            'dol_print_qrcode',
154
-            'dol_print_date',
155
-            'dol_print_date_time',
156
-            'dol_print_year',
157
-            'dol_print_month_letters',
158
-            'dol_print_month',
159
-            'dol_print_day',
160
-            'dol_print_day_letters',
161
-            'dol_print_table',
162
-            'dol_print_cutlery',
163
-            'dol_print_payment',
164
-            'dol_print_logo',
165
-            'dol_print_logo_old',
166
-            'dol_print_order_lines',
167
-            'dol_print_order_tax',
168
-            'dol_print_order_local_tax',
169
-            'dol_print_order_total',
170
-            'dol_print_order_number',
171
-            'dol_print_order_number_unique',
172
-            'dol_print_customer_firstname',
173
-            'dol_print_customer_lastname',
174
-            'dol_print_customer_mail',
175
-            'dol_print_customer_phone',
176
-            'dol_print_customer_mobile',
177
-            'dol_print_customer_skype',
178
-            'dol_print_customer_tax_number',
179
-            'dol_print_customer_account_balance',
180
-            'dol_print_vendor_lastname',
181
-            'dol_print_vendor_firstname',
182
-            'dol_print_vendor_mail',
183
-            'dol_print_customer_points',
184
-            'dol_print_order_points',
185
-            'dol_print_if_customer',
186
-            'dol_print_if_vendor',
187
-            'dol_print_if_happy_hour',
188
-            'dol_print_if_num_order_unique',
189
-            'dol_print_if_customer_points',
190
-            'dol_print_if_order_points',
191
-            'dol_print_if_customer_tax_number',
192
-            'dol_print_if_customer_account_balance_positive',
193
-        );
117
+	/**
118
+	 * Constructor
119
+	 *
120
+	 * @param   DoliDB      $db         database
121
+	 */
122
+	function __construct($db)
123
+	{
124
+		$this->db=$db;
125
+		$this->tags = array(
126
+			'dol_align_left',
127
+			'dol_align_center',
128
+			'dol_align_right',
129
+			'dol_use_font_a',
130
+			'dol_use_font_b',
131
+			'dol_use_font_c',
132
+			'dol_bold',
133
+			'/dol_bold',
134
+			'dol_double_height',
135
+			'/dol_double_height',
136
+			'dol_double_width',
137
+			'/dol_double_width',
138
+			'dol_underline',
139
+			'/dol_underline',
140
+			'dol_underline_2dots',
141
+			'/dol_underline',
142
+			'dol_emphasized',
143
+			'/dol_emphasized',
144
+			'dol_switch_colors',
145
+			'/dol_switch_colors',
146
+			'dol_print_barcode',
147
+			'dol_print_barcode_customer_id',
148
+			'dol_set_print_width_57',
149
+			'dol_cut_paper_full',
150
+			'dol_cut_paper_partial',
151
+			'dol_open_drawer',
152
+			'dol_activate_buzzer',
153
+			'dol_print_qrcode',
154
+			'dol_print_date',
155
+			'dol_print_date_time',
156
+			'dol_print_year',
157
+			'dol_print_month_letters',
158
+			'dol_print_month',
159
+			'dol_print_day',
160
+			'dol_print_day_letters',
161
+			'dol_print_table',
162
+			'dol_print_cutlery',
163
+			'dol_print_payment',
164
+			'dol_print_logo',
165
+			'dol_print_logo_old',
166
+			'dol_print_order_lines',
167
+			'dol_print_order_tax',
168
+			'dol_print_order_local_tax',
169
+			'dol_print_order_total',
170
+			'dol_print_order_number',
171
+			'dol_print_order_number_unique',
172
+			'dol_print_customer_firstname',
173
+			'dol_print_customer_lastname',
174
+			'dol_print_customer_mail',
175
+			'dol_print_customer_phone',
176
+			'dol_print_customer_mobile',
177
+			'dol_print_customer_skype',
178
+			'dol_print_customer_tax_number',
179
+			'dol_print_customer_account_balance',
180
+			'dol_print_vendor_lastname',
181
+			'dol_print_vendor_firstname',
182
+			'dol_print_vendor_mail',
183
+			'dol_print_customer_points',
184
+			'dol_print_order_points',
185
+			'dol_print_if_customer',
186
+			'dol_print_if_vendor',
187
+			'dol_print_if_happy_hour',
188
+			'dol_print_if_num_order_unique',
189
+			'dol_print_if_customer_points',
190
+			'dol_print_if_order_points',
191
+			'dol_print_if_customer_tax_number',
192
+			'dol_print_if_customer_account_balance_positive',
193
+		);
194 194
 
195
-    }
195
+	}
196 196
 
197
-    /**
198
-     * list printers
199
-     *
200
-     * @return  int                     0 if OK; >0 if KO
201
-     */
202
-    function listPrinters()
203
-    {
204
-        global $conf;
205
-        $error = 0;
206
-        $line = 0;
207
-        $sql = 'SELECT rowid, name, fk_type, fk_profile, parameter';
208
-        $sql.= ' FROM '.MAIN_DB_PREFIX.'printer_receipt';
209
-        $sql.= ' WHERE entity = '.$conf->entity;
210
-        $resql = $this->db->query($sql);
211
-        if ($resql) {
212
-            $num = $this->db->num_rows($resql);
213
-            while ($line < $num) {
214
-                $row = $this->db->fetch_array($resql);
215
-                switch ($row['fk_type']) {
216
-                    case 1:
217
-                        $row['fk_type_name'] = 'CONNECTOR_DUMMY';
218
-                        break;
219
-                    case 2:
220
-                        $row['fk_type_name'] = 'CONNECTOR_FILE_PRINT';
221
-                        break;
222
-                    case 3:
223
-                        $row['fk_type_name'] = 'CONNECTOR_NETWORK_PRINT';
224
-                        break;
225
-                    case 4:
226
-                        $row['fk_type_name'] = 'CONNECTOR_WINDOWS_PRINT';
227
-                        break;
228
-                    case 5:
229
-                        $row['fk_type_name'] = 'CONNECTOR_JAVA';
230
-                        break;
231
-                    default:
232
-                        $row['fk_type_name'] = 'CONNECTOR_UNKNOWN';
233
-                        break;
234
-                }
235
-                switch ($row['fk_profile']) {
236
-                    case 0:
237
-                        $row['fk_profile_name'] = 'PROFILE_DEFAULT';
238
-                        break;
239
-                    case 1:
240
-                        $row['fk_profile_name'] = 'PROFILE_SIMPLE';
241
-                        break;
242
-                    case 2:
243
-                        $row['fk_profile_name'] = 'PROFILE_EPOSTEP';
244
-                        break;
245
-                    case 3:
246
-                        $row['fk_profile_name'] = 'PROFILE_P822D';
247
-                        break;
248
-                    default:
249
-                        $row['fk_profile_name'] = 'PROFILE_STAR';
250
-                        break;
251
-                }
252
-                $obj[] = $row;
253
-                $line++;
254
-            }
255
-        } else {
256
-            $error++;
257
-            $this->errors[] = $this->db->lasterror;
258
-        }
259
-        $this->listprinters = $obj;
260
-        return $error;
261
-    }
197
+	/**
198
+	 * list printers
199
+	 *
200
+	 * @return  int                     0 if OK; >0 if KO
201
+	 */
202
+	function listPrinters()
203
+	{
204
+		global $conf;
205
+		$error = 0;
206
+		$line = 0;
207
+		$sql = 'SELECT rowid, name, fk_type, fk_profile, parameter';
208
+		$sql.= ' FROM '.MAIN_DB_PREFIX.'printer_receipt';
209
+		$sql.= ' WHERE entity = '.$conf->entity;
210
+		$resql = $this->db->query($sql);
211
+		if ($resql) {
212
+			$num = $this->db->num_rows($resql);
213
+			while ($line < $num) {
214
+				$row = $this->db->fetch_array($resql);
215
+				switch ($row['fk_type']) {
216
+					case 1:
217
+						$row['fk_type_name'] = 'CONNECTOR_DUMMY';
218
+						break;
219
+					case 2:
220
+						$row['fk_type_name'] = 'CONNECTOR_FILE_PRINT';
221
+						break;
222
+					case 3:
223
+						$row['fk_type_name'] = 'CONNECTOR_NETWORK_PRINT';
224
+						break;
225
+					case 4:
226
+						$row['fk_type_name'] = 'CONNECTOR_WINDOWS_PRINT';
227
+						break;
228
+					case 5:
229
+						$row['fk_type_name'] = 'CONNECTOR_JAVA';
230
+						break;
231
+					default:
232
+						$row['fk_type_name'] = 'CONNECTOR_UNKNOWN';
233
+						break;
234
+				}
235
+				switch ($row['fk_profile']) {
236
+					case 0:
237
+						$row['fk_profile_name'] = 'PROFILE_DEFAULT';
238
+						break;
239
+					case 1:
240
+						$row['fk_profile_name'] = 'PROFILE_SIMPLE';
241
+						break;
242
+					case 2:
243
+						$row['fk_profile_name'] = 'PROFILE_EPOSTEP';
244
+						break;
245
+					case 3:
246
+						$row['fk_profile_name'] = 'PROFILE_P822D';
247
+						break;
248
+					default:
249
+						$row['fk_profile_name'] = 'PROFILE_STAR';
250
+						break;
251
+				}
252
+				$obj[] = $row;
253
+				$line++;
254
+			}
255
+		} else {
256
+			$error++;
257
+			$this->errors[] = $this->db->lasterror;
258
+		}
259
+		$this->listprinters = $obj;
260
+		return $error;
261
+	}
262 262
 
263 263
 
264
-    /**
265
-     * List printers templates
266
-     *
267
-     * @return  int                     0 if OK; >0 if KO
268
-     */
269
-    function listPrintersTemplates()
270
-    {
271
-        global $conf;
272
-        $error = 0;
273
-        $line = 0;
274
-        $sql = 'SELECT rowid, name, template';
275
-        $sql.= ' FROM '.MAIN_DB_PREFIX.'printer_receipt_template';
276
-        $sql.= ' WHERE entity = '.$conf->entity;
277
-        $resql = $this->db->query($sql);
278
-        if ($resql) {
279
-            $num = $this->db->num_rows($resql);
280
-            while ($line < $num) {
281
-                $obj[] = $this->db->fetch_array($resql);
282
-                $line++;
283
-            }
284
-        } else {
285
-            $error++;
286
-            $this->errors[] = $this->db->lasterror;
287
-        }
288
-        $this->listprinterstemplates = $obj;
289
-        return $error;
290
-    }
264
+	/**
265
+	 * List printers templates
266
+	 *
267
+	 * @return  int                     0 if OK; >0 if KO
268
+	 */
269
+	function listPrintersTemplates()
270
+	{
271
+		global $conf;
272
+		$error = 0;
273
+		$line = 0;
274
+		$sql = 'SELECT rowid, name, template';
275
+		$sql.= ' FROM '.MAIN_DB_PREFIX.'printer_receipt_template';
276
+		$sql.= ' WHERE entity = '.$conf->entity;
277
+		$resql = $this->db->query($sql);
278
+		if ($resql) {
279
+			$num = $this->db->num_rows($resql);
280
+			while ($line < $num) {
281
+				$obj[] = $this->db->fetch_array($resql);
282
+				$line++;
283
+			}
284
+		} else {
285
+			$error++;
286
+			$this->errors[] = $this->db->lasterror;
287
+		}
288
+		$this->listprinterstemplates = $obj;
289
+		return $error;
290
+	}
291 291
 
292 292
 
293
-    /**
294
-     *  Form to Select type printer
295
-     *
296
-     *  @param    string    $selected       Id printer type pre-selected
297
-     *  @param    string    $htmlname       select html name
298
-     *  @return  int                        0 if OK; >0 if KO
299
-     */
300
-    function selectTypePrinter($selected='', $htmlname='printertypeid')
301
-    {
302
-        global $langs;
293
+	/**
294
+	 *  Form to Select type printer
295
+	 *
296
+	 *  @param    string    $selected       Id printer type pre-selected
297
+	 *  @param    string    $htmlname       select html name
298
+	 *  @return  int                        0 if OK; >0 if KO
299
+	 */
300
+	function selectTypePrinter($selected='', $htmlname='printertypeid')
301
+	{
302
+		global $langs;
303 303
         
304
-        $options = array(
305
-            1 => $langs->trans('CONNECTOR_DUMMY'),
306
-            2 => $langs->trans('CONNECTOR_FILE_PRINT'),
307
-            3 => $langs->trans('CONNECTOR_NETWORK_PRINT'),
308
-            4 => $langs->trans('CONNECTOR_WINDOWS_PRINT')
309
-        );
304
+		$options = array(
305
+			1 => $langs->trans('CONNECTOR_DUMMY'),
306
+			2 => $langs->trans('CONNECTOR_FILE_PRINT'),
307
+			3 => $langs->trans('CONNECTOR_NETWORK_PRINT'),
308
+			4 => $langs->trans('CONNECTOR_WINDOWS_PRINT')
309
+		);
310 310
         
311
-        $this->resprint = Form::selectarray($htmlname, $options, $selected);
311
+		$this->resprint = Form::selectarray($htmlname, $options, $selected);
312 312
         
313
-        return 0;
314
-    }
313
+		return 0;
314
+	}
315 315
 
316 316
 
317
-    /**
318
-     *  Form to Select Profile printer
319
-     *
320
-     *  @param    string    $selected       Id printer profile pre-selected
321
-     *  @param    string    $htmlname       select html name
322
-     *  @return  int                        0 if OK; >0 if KO
323
-     */
324
-    function selectProfilePrinter($selected='', $htmlname='printerprofileid')
325
-    {
326
-        global $langs;
317
+	/**
318
+	 *  Form to Select Profile printer
319
+	 *
320
+	 *  @param    string    $selected       Id printer profile pre-selected
321
+	 *  @param    string    $htmlname       select html name
322
+	 *  @return  int                        0 if OK; >0 if KO
323
+	 */
324
+	function selectProfilePrinter($selected='', $htmlname='printerprofileid')
325
+	{
326
+		global $langs;
327 327
         
328
-        $options = array(
329
-            0 => $langs->trans('PROFILE_DEFAULT'),
330
-            1 => $langs->trans('PROFILE_SIMPLE'),
331
-            2 => $langs->trans('PROFILE_EPOSTEP'),
332
-            3 => $langs->trans('PROFILE_P822D'),
333
-            4 => $langs->trans('PROFILE_STAR')
334
-        );
328
+		$options = array(
329
+			0 => $langs->trans('PROFILE_DEFAULT'),
330
+			1 => $langs->trans('PROFILE_SIMPLE'),
331
+			2 => $langs->trans('PROFILE_EPOSTEP'),
332
+			3 => $langs->trans('PROFILE_P822D'),
333
+			4 => $langs->trans('PROFILE_STAR')
334
+		);
335 335
         
336
-        $this->profileresprint = Form::selectarray($htmlname, $options, $selected);
337
-        return 0;
338
-    }
336
+		$this->profileresprint = Form::selectarray($htmlname, $options, $selected);
337
+		return 0;
338
+	}
339 339
 
340 340
 
341
-    /**
342
-     *  Function to Add a printer in db
343
-     *
344
-     *  @param    string    $name           Printer name
345
-     *  @param    int       $type           Printer type
346
-     *  @param    int       $profile        Printer profile
347
-     *  @param    string    $parameter      Printer parameter
348
-     *  @return  int                        0 if OK; >0 if KO
349
-     */
350
-    function AddPrinter($name, $type, $profile, $parameter)
351
-    {
352
-        global $conf;
353
-        $error = 0;
354
-        $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'printer_receipt';
355
-        $sql.= ' (name, fk_type, fk_profile, parameter, entity)';
356
-        $sql.= ' VALUES ("'.$this->db->escape($name).'", '.$type.', '.$profile.', "'.$this->db->escape($parameter).'", '.$conf->entity.')';
357
-        $resql = $this->db->query($sql);
358
-        if (! $resql) {
359
-            $error++;
360
-            $this->errors[] = $this->db->lasterror;
361
-        }
362
-        return $error;
363
-    }
341
+	/**
342
+	 *  Function to Add a printer in db
343
+	 *
344
+	 *  @param    string    $name           Printer name
345
+	 *  @param    int       $type           Printer type
346
+	 *  @param    int       $profile        Printer profile
347
+	 *  @param    string    $parameter      Printer parameter
348
+	 *  @return  int                        0 if OK; >0 if KO
349
+	 */
350
+	function AddPrinter($name, $type, $profile, $parameter)
351
+	{
352
+		global $conf;
353
+		$error = 0;
354
+		$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'printer_receipt';
355
+		$sql.= ' (name, fk_type, fk_profile, parameter, entity)';
356
+		$sql.= ' VALUES ("'.$this->db->escape($name).'", '.$type.', '.$profile.', "'.$this->db->escape($parameter).'", '.$conf->entity.')';
357
+		$resql = $this->db->query($sql);
358
+		if (! $resql) {
359
+			$error++;
360
+			$this->errors[] = $this->db->lasterror;
361
+		}
362
+		return $error;
363
+	}
364 364
 
365
-    /**
366
-     *  Function to Update a printer in db
367
-     *
368
-     *  @param    string    $name           Printer name
369
-     *  @param    int       $type           Printer type
370
-     *  @param    int       $profile        Printer profile
371
-     *  @param    string    $parameter      Printer parameter
372
-     *  @param    int       $printerid      Printer id
373
-     *  @return  int                        0 if OK; >0 if KO
374
-     */
375
-    function UpdatePrinter($name, $type, $profile, $parameter, $printerid)
376
-    {
377
-        global $conf;
378
-        $error = 0;
379
-        $sql = 'UPDATE '.MAIN_DB_PREFIX.'printer_receipt';
380
-        $sql.= ' SET name="'.$this->db->escape($name).'"';
381
-        $sql.= ', fk_type='.$type;
382
-        $sql.= ', fk_profile='.$profile;
383
-        $sql.= ', parameter="'.$this->db->escape($parameter).'"';
384
-        $sql.= ' WHERE rowid='.$printerid;
385
-        $resql = $this->db->query($sql);
386
-        if (! $resql) {
387
-            $error++;
388
-            $this->errors[] = $this->db->lasterror;
389
-        }
390
-        return $error;
391
-    }
365
+	/**
366
+	 *  Function to Update a printer in db
367
+	 *
368
+	 *  @param    string    $name           Printer name
369
+	 *  @param    int       $type           Printer type
370
+	 *  @param    int       $profile        Printer profile
371
+	 *  @param    string    $parameter      Printer parameter
372
+	 *  @param    int       $printerid      Printer id
373
+	 *  @return  int                        0 if OK; >0 if KO
374
+	 */
375
+	function UpdatePrinter($name, $type, $profile, $parameter, $printerid)
376
+	{
377
+		global $conf;
378
+		$error = 0;
379
+		$sql = 'UPDATE '.MAIN_DB_PREFIX.'printer_receipt';
380
+		$sql.= ' SET name="'.$this->db->escape($name).'"';
381
+		$sql.= ', fk_type='.$type;
382
+		$sql.= ', fk_profile='.$profile;
383
+		$sql.= ', parameter="'.$this->db->escape($parameter).'"';
384
+		$sql.= ' WHERE rowid='.$printerid;
385
+		$resql = $this->db->query($sql);
386
+		if (! $resql) {
387
+			$error++;
388
+			$this->errors[] = $this->db->lasterror;
389
+		}
390
+		return $error;
391
+	}
392 392
 
393
-    /**
394
-     *  Function to Delete a printer from db
395
-     *
396
-     *  @param    int       $printerid      Printer id
397
-     *  @return  int                        0 if OK; >0 if KO
398
-     */
399
-    function DeletePrinter($printerid)
400
-    {
401
-        global $conf;
402
-        $error = 0;
403
-        $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'printer_receipt';
404
-        $sql.= ' WHERE rowid='.$printerid;
405
-        $resql = $this->db->query($sql);
406
-        if (! $resql) {
407
-            $error++;
408
-            $this->errors[] = $this->db->lasterror;
409
-        }
410
-        return $error;
411
-    }
393
+	/**
394
+	 *  Function to Delete a printer from db
395
+	 *
396
+	 *  @param    int       $printerid      Printer id
397
+	 *  @return  int                        0 if OK; >0 if KO
398
+	 */
399
+	function DeletePrinter($printerid)
400
+	{
401
+		global $conf;
402
+		$error = 0;
403
+		$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'printer_receipt';
404
+		$sql.= ' WHERE rowid='.$printerid;
405
+		$resql = $this->db->query($sql);
406
+		if (! $resql) {
407
+			$error++;
408
+			$this->errors[] = $this->db->lasterror;
409
+		}
410
+		return $error;
411
+	}
412 412
 
413
-    /**
414
-     *  Function to Update a printer template in db
415
-     *
416
-     *  @param    string    $name           Template name
417
-     *  @param    int       $template       Template
418
-     *  @param    int       $templateid     Template id
419
-     *  @return   int                       0 if OK; >0 if KO
420
-     */
421
-    function UpdateTemplate($name, $template, $templateid)
422
-    {
423
-        global $conf;
424
-        $error = 0;
425
-        $sql = 'UPDATE '.MAIN_DB_PREFIX.'printer_receipt_template';
426
-        $sql.= ' SET name="'.$this->db->escape($name).'"';
427
-        $sql.= ', template="'.$this->db->escape($template).'"';
428
-        $sql.= ' WHERE rowid='.$templateid;
429
-        $resql = $this->db->query($sql);
430
-        if (! $resql) {
431
-            $error++;
432
-            $this->errors[] = $this->db->lasterror;
433
-        }
434
-        return $error;
435
-    }
413
+	/**
414
+	 *  Function to Update a printer template in db
415
+	 *
416
+	 *  @param    string    $name           Template name
417
+	 *  @param    int       $template       Template
418
+	 *  @param    int       $templateid     Template id
419
+	 *  @return   int                       0 if OK; >0 if KO
420
+	 */
421
+	function UpdateTemplate($name, $template, $templateid)
422
+	{
423
+		global $conf;
424
+		$error = 0;
425
+		$sql = 'UPDATE '.MAIN_DB_PREFIX.'printer_receipt_template';
426
+		$sql.= ' SET name="'.$this->db->escape($name).'"';
427
+		$sql.= ', template="'.$this->db->escape($template).'"';
428
+		$sql.= ' WHERE rowid='.$templateid;
429
+		$resql = $this->db->query($sql);
430
+		if (! $resql) {
431
+			$error++;
432
+			$this->errors[] = $this->db->lasterror;
433
+		}
434
+		return $error;
435
+	}
436 436
 
437 437
 
438
-    /**
439
-     *  Function to Send Test page to Printer
440
-     *
441
-     *  @param    int       $printerid      Printer id
442
-     *  @return  int                        0 if OK; >0 if KO
443
-     */
444
-    function SendTestToPrinter($printerid)
445
-    {
446
-        global $conf;
447
-        $error = 0;
448
-        $img = new EscposImage(DOL_DOCUMENT_ROOT .'/theme/common/dolibarr_logo_bw.png');
449
-        $ret = $this->InitPrinter($printerid);
450
-        if ($ret>0) {
451
-            setEventMessages($this->error, $this->errors, 'errors');
452
-        } else {
453
-            try {
454
-                $this->printer->graphics($img);
455
-                $this->printer->text("Hello World!\n");
456
-                $testStr = "Testing 123";
457
-                $this->printer->qrCode($testStr);
458
-                $this->printer->text("Most simple example\n");
459
-                $this->printer->feed();
460
-                $this->printer->cut();
461
-                //print '<pre>'.print_r($this->connector, true).'</pre>';
462
-                $this->printer->close();
438
+	/**
439
+	 *  Function to Send Test page to Printer
440
+	 *
441
+	 *  @param    int       $printerid      Printer id
442
+	 *  @return  int                        0 if OK; >0 if KO
443
+	 */
444
+	function SendTestToPrinter($printerid)
445
+	{
446
+		global $conf;
447
+		$error = 0;
448
+		$img = new EscposImage(DOL_DOCUMENT_ROOT .'/theme/common/dolibarr_logo_bw.png');
449
+		$ret = $this->InitPrinter($printerid);
450
+		if ($ret>0) {
451
+			setEventMessages($this->error, $this->errors, 'errors');
452
+		} else {
453
+			try {
454
+				$this->printer->graphics($img);
455
+				$this->printer->text("Hello World!\n");
456
+				$testStr = "Testing 123";
457
+				$this->printer->qrCode($testStr);
458
+				$this->printer->text("Most simple example\n");
459
+				$this->printer->feed();
460
+				$this->printer->cut();
461
+				//print '<pre>'.print_r($this->connector, true).'</pre>';
462
+				$this->printer->close();
463 463
 
464
-            } catch (Exception $e) {
465
-                $this->errors[] = $e->getMessage();
466
-                $error++;
467
-            }
468
-        }
469
-        return $error;
470
-    }
464
+			} catch (Exception $e) {
465
+				$this->errors[] = $e->getMessage();
466
+				$error++;
467
+			}
468
+		}
469
+		return $error;
470
+	}
471 471
 
472
-    /**
473
-     *  Function to Print Receipt Ticket
474
-     *
475
-     *  @param   object    $object          order or invoice object
476
-     *  @param   int       $templateid      Template id
477
-     *  @param   int       $printerid       Printer id
478
-     *  @return  int                        0 if OK; >0 if KO
479
-     */
480
-    function SendToPrinter($object, $templateid, $printerid)
481
-    {
482
-        global $conf;
483
-        $error = 0;
484
-        $ret = $this->loadTemplate($templateid);
472
+	/**
473
+	 *  Function to Print Receipt Ticket
474
+	 *
475
+	 *  @param   object    $object          order or invoice object
476
+	 *  @param   int       $templateid      Template id
477
+	 *  @param   int       $printerid       Printer id
478
+	 *  @return  int                        0 if OK; >0 if KO
479
+	 */
480
+	function SendToPrinter($object, $templateid, $printerid)
481
+	{
482
+		global $conf;
483
+		$error = 0;
484
+		$ret = $this->loadTemplate($templateid);
485 485
 
486
-        // tags a remplacer par leur valeur avant de parser
487
-        $this->template = str_replace('<dol_print_num_order>', $object->id, $this->template);
488
-        $this->template = str_replace('<dol_print_customer_firstname>', $object->customer_firstname, $this->template);
489
-        $this->template = str_replace('<dol_print_customer_lastname>', $object->customer_lastname, $this->template);
490
-        $this->template = str_replace('<dol_print_customer_mail>', $object->customer_mail, $this->template);
491
-        $this->template = str_replace('<dol_print_customer_phone>', $object->customer_phone, $this->template);
492
-        $this->template = str_replace('<dol_print_customer_mobile>', $object->customer_mobile, $this->template);
493
-        $this->template = str_replace('<dol_print_customer_skype>', $object->customer_skype, $this->template);
494
-        $this->template = str_replace('<dol_print_customer_tax_number>', $object->customer_tax_number, $this->template);
495
-        $this->template = str_replace('<dol_print_customer_account_balance>', $object->customer_account_balance, $this->template);
496
-        $this->template = str_replace('<dol_print_customer_points>', $object->customer_points, $this->template);
497
-        $this->template = str_replace('<dol_print_order_points>', $object->order_points, $this->template);
498
-        $this->template = str_replace('<dol_print_vendor_firstname>', $object->vendor_firstname, $this->template);
499
-        $this->template = str_replace('<dol_print_vendor_lastname>', $object->vendor_lastname, $this->template);
500
-        $this->template = str_replace('<dol_print_vendor_mail>', $object->vendor_mail, $this->template);
501
-        $this->template = str_replace('<dol_print_date>', $object->date, $this->template);
502
-        $this->template = str_replace('<dol_print_date_time>', $object->date_time, $this->template);
503
-        $this->template = str_replace('<dol_print_year>', $object->date_time, $this->template);
504
-        $this->template = str_replace('<dol_print_month_letters>', $object->date_time, $this->template);
505
-        $this->template = str_replace('<dol_print_month>', $object->date_time, $this->template);
506
-        $this->template = str_replace('<dol_print_day>', $object->date_time, $this->template);
507
-        $this->template = str_replace('<dol_print_day_letters>', $object->date_time, $this->template);
508
-        $this->template = str_replace('<dol_print_table>', $object->table, $this->template);
509
-        $this->template = str_replace('<dol_print_cutlery>', $object->cutlery, $this->template);
486
+		// tags a remplacer par leur valeur avant de parser
487
+		$this->template = str_replace('<dol_print_num_order>', $object->id, $this->template);
488
+		$this->template = str_replace('<dol_print_customer_firstname>', $object->customer_firstname, $this->template);
489
+		$this->template = str_replace('<dol_print_customer_lastname>', $object->customer_lastname, $this->template);
490
+		$this->template = str_replace('<dol_print_customer_mail>', $object->customer_mail, $this->template);
491
+		$this->template = str_replace('<dol_print_customer_phone>', $object->customer_phone, $this->template);
492
+		$this->template = str_replace('<dol_print_customer_mobile>', $object->customer_mobile, $this->template);
493
+		$this->template = str_replace('<dol_print_customer_skype>', $object->customer_skype, $this->template);
494
+		$this->template = str_replace('<dol_print_customer_tax_number>', $object->customer_tax_number, $this->template);
495
+		$this->template = str_replace('<dol_print_customer_account_balance>', $object->customer_account_balance, $this->template);
496
+		$this->template = str_replace('<dol_print_customer_points>', $object->customer_points, $this->template);
497
+		$this->template = str_replace('<dol_print_order_points>', $object->order_points, $this->template);
498
+		$this->template = str_replace('<dol_print_vendor_firstname>', $object->vendor_firstname, $this->template);
499
+		$this->template = str_replace('<dol_print_vendor_lastname>', $object->vendor_lastname, $this->template);
500
+		$this->template = str_replace('<dol_print_vendor_mail>', $object->vendor_mail, $this->template);
501
+		$this->template = str_replace('<dol_print_date>', $object->date, $this->template);
502
+		$this->template = str_replace('<dol_print_date_time>', $object->date_time, $this->template);
503
+		$this->template = str_replace('<dol_print_year>', $object->date_time, $this->template);
504
+		$this->template = str_replace('<dol_print_month_letters>', $object->date_time, $this->template);
505
+		$this->template = str_replace('<dol_print_month>', $object->date_time, $this->template);
506
+		$this->template = str_replace('<dol_print_day>', $object->date_time, $this->template);
507
+		$this->template = str_replace('<dol_print_day_letters>', $object->date_time, $this->template);
508
+		$this->template = str_replace('<dol_print_table>', $object->table, $this->template);
509
+		$this->template = str_replace('<dol_print_cutlery>', $object->cutlery, $this->template);
510 510
 
511
-        // parse template
512
-        $p = xml_parser_create();
513
-        xml_parse_into_struct($p, $this->template, $vals, $index);
514
-        xml_parser_free($p);
515
-        //print '<pre>'.print_r($index, true).'</pre>';
516
-        //print '<pre>'.print_r($vals, true).'</pre>';
517
-        // print ticket
518
-        $level = 0;
519
-        $html = '<table border="1" style="width:210px"><pre>';
520
-        $ret = $this->InitPrinter($printerid);
521
-        if ($ret>0) {
522
-            setEventMessages($this->error, $this->errors, 'errors');
523
-        } 
524
-        else 
525
-        {
526
-            $nboflines = count($vals);
527
-            for ($line=0; $line < $nboflines; $line++) 
528
-            {
529
-                switch ($vals[$line]['tag']) {
530
-                    case 'DOL_ALIGN_CENTER':
531
-                        $this->printer->setJustification(Escpos::JUSTIFY_CENTER);
532
-                        $html.='<center>';
533
-                        $this->printer->text($vals[$line]['value']);
534
-                        break;
535
-                    case 'DOL_ALIGN_RIGHT':
536
-                        $this->printer->setJustification(Escpos::JUSTIFY_RIGHT);
537
-                        $html.='<right>';
538
-                        break;
539
-                    case 'DOL_ALIGN_LEFT':
540
-                        $this->printer->setJustification(Escpos::JUSTIFY_LEFT);
541
-                        $html.='<left>';
542
-                        break;
543
-                    case 'DOL_OPEN_DRAWER':
544
-                        $this->printer->pulse();
545
-                        $html.= ' &#991;'.nl2br($vals[$line]['value']);
546
-                        break;
547
-                    case 'DOL_ACTIVATE_BUZZER':
548
-                        //$this->printer->buzzer();
549
-                        $html.= ' &#x266b;'.nl2br($vals[$line]['value']);
550
-                        break;
551
-                    case 'DOL_PRINT_BARCODE':
552
-                        // $vals[$line]['value'] -> barcode($content, $type)
553
-                        $this->printer->barcode($object->barcode);
554
-                        break;
555
-                    case 'DOL_PRINT_BARCODE_CUSTOMER_ID':
556
-                        // $vals[$line]['value'] -> barcode($content, $type)
557
-                        $this->printer->barcode($object->customer_id);
558
-                        break;
559
-                    case 'DOL_PRINT_QRCODE':
560
-                        // $vals[$line]['value'] -> qrCode($content, $ec, $size, $model)
561
-                        $this->printer->qrcode($vals[$line]['value']);
562
-                        $html.='QRCODE: '.$vals[$line]['value'];
563
-                        break;
564
-                    case 'DOL_CUT_PAPER_FULL':
565
-                        $this->printer->cut(Escpos::CUT_FULL);
566
-                        $html.= ' &#9986;'.nl2br($vals[$line]['value']);
567
-                        break;
568
-                    case 'DOL_CUT_PAPER_PARTIAL':
569
-                        $this->printer->cut(Escpos::CUT_PARTIAL);
570
-                        $html.= ' &#9986;'.nl2br($vals[$line]['value']);
571
-                        break;
572
-                    case 'DOL_USE_FONT_A':
573
-                        $this->printer->setFont(Escpos::FONT_A);
574
-                        $this->printer->text($vals[$line]['value']);
575
-                        break;
576
-                    case 'DOL_USE_FONT_B':
577
-                        $this->printer->setFont(Escpos::FONT_B);
578
-                        $this->printer->text($vals[$line]['value']);
579
-                        break;
580
-                    case 'DOL_USE_FONT_C':
581
-                        $this->printer->setFont(Escpos::FONT_C);
582
-                        $this->printer->text($vals[$line]['value']);
583
-                        break;
584
-                    default:
585
-                        $this->printer->text($vals[$line]['value']);
586
-                        $html.= nl2br($vals[$line]['value']);
587
-                        $this->errors[] = 'UnknowTag: &lt;'.strtolower($vals[$line]['tag']).'&gt;';
588
-                        $error++;
589
-                        break;
590
-                }
591
-            }
592
-            $html.= '</pre></table>';
593
-            print $html;
594
-            // Close and print
595
-            // uncomment next line to see content sent to printer
596
-            //print '<pre>'.print_r($this->connector, true).'</pre>';
597
-            $this->printer->close();
511
+		// parse template
512
+		$p = xml_parser_create();
513
+		xml_parse_into_struct($p, $this->template, $vals, $index);
514
+		xml_parser_free($p);
515
+		//print '<pre>'.print_r($index, true).'</pre>';
516
+		//print '<pre>'.print_r($vals, true).'</pre>';
517
+		// print ticket
518
+		$level = 0;
519
+		$html = '<table border="1" style="width:210px"><pre>';
520
+		$ret = $this->InitPrinter($printerid);
521
+		if ($ret>0) {
522
+			setEventMessages($this->error, $this->errors, 'errors');
523
+		} 
524
+		else 
525
+		{
526
+			$nboflines = count($vals);
527
+			for ($line=0; $line < $nboflines; $line++) 
528
+			{
529
+				switch ($vals[$line]['tag']) {
530
+					case 'DOL_ALIGN_CENTER':
531
+						$this->printer->setJustification(Escpos::JUSTIFY_CENTER);
532
+						$html.='<center>';
533
+						$this->printer->text($vals[$line]['value']);
534
+						break;
535
+					case 'DOL_ALIGN_RIGHT':
536
+						$this->printer->setJustification(Escpos::JUSTIFY_RIGHT);
537
+						$html.='<right>';
538
+						break;
539
+					case 'DOL_ALIGN_LEFT':
540
+						$this->printer->setJustification(Escpos::JUSTIFY_LEFT);
541
+						$html.='<left>';
542
+						break;
543
+					case 'DOL_OPEN_DRAWER':
544
+						$this->printer->pulse();
545
+						$html.= ' &#991;'.nl2br($vals[$line]['value']);
546
+						break;
547
+					case 'DOL_ACTIVATE_BUZZER':
548
+						//$this->printer->buzzer();
549
+						$html.= ' &#x266b;'.nl2br($vals[$line]['value']);
550
+						break;
551
+					case 'DOL_PRINT_BARCODE':
552
+						// $vals[$line]['value'] -> barcode($content, $type)
553
+						$this->printer->barcode($object->barcode);
554
+						break;
555
+					case 'DOL_PRINT_BARCODE_CUSTOMER_ID':
556
+						// $vals[$line]['value'] -> barcode($content, $type)
557
+						$this->printer->barcode($object->customer_id);
558
+						break;
559
+					case 'DOL_PRINT_QRCODE':
560
+						// $vals[$line]['value'] -> qrCode($content, $ec, $size, $model)
561
+						$this->printer->qrcode($vals[$line]['value']);
562
+						$html.='QRCODE: '.$vals[$line]['value'];
563
+						break;
564
+					case 'DOL_CUT_PAPER_FULL':
565
+						$this->printer->cut(Escpos::CUT_FULL);
566
+						$html.= ' &#9986;'.nl2br($vals[$line]['value']);
567
+						break;
568
+					case 'DOL_CUT_PAPER_PARTIAL':
569
+						$this->printer->cut(Escpos::CUT_PARTIAL);
570
+						$html.= ' &#9986;'.nl2br($vals[$line]['value']);
571
+						break;
572
+					case 'DOL_USE_FONT_A':
573
+						$this->printer->setFont(Escpos::FONT_A);
574
+						$this->printer->text($vals[$line]['value']);
575
+						break;
576
+					case 'DOL_USE_FONT_B':
577
+						$this->printer->setFont(Escpos::FONT_B);
578
+						$this->printer->text($vals[$line]['value']);
579
+						break;
580
+					case 'DOL_USE_FONT_C':
581
+						$this->printer->setFont(Escpos::FONT_C);
582
+						$this->printer->text($vals[$line]['value']);
583
+						break;
584
+					default:
585
+						$this->printer->text($vals[$line]['value']);
586
+						$html.= nl2br($vals[$line]['value']);
587
+						$this->errors[] = 'UnknowTag: &lt;'.strtolower($vals[$line]['tag']).'&gt;';
588
+						$error++;
589
+						break;
590
+				}
591
+			}
592
+			$html.= '</pre></table>';
593
+			print $html;
594
+			// Close and print
595
+			// uncomment next line to see content sent to printer
596
+			//print '<pre>'.print_r($this->connector, true).'</pre>';
597
+			$this->printer->close();
598 598
 
599
-        }
600
-        return $error;
601
-    }
599
+		}
600
+		return $error;
601
+	}
602 602
 
603
-    /**
604
-     *  Function to load Template
605
-     *
606
-     *  @param   int       $templateid        Template id
607
-     *  @return  int                        0 if OK; >0 if KO
608
-     */
609
-    function loadTemplate($templateid)
610
-    {
611
-        global $conf;
612
-        $error = 0;
613
-        $sql = 'SELECT template';
614
-        $sql.= ' FROM '.MAIN_DB_PREFIX.'printer_receipt_template';
615
-        $sql.= ' WHERE rowid='.$templateid;
616
-        $sql.= ' AND entity = '.$conf->entity;
617
-        $resql = $this->db->query($sql);
618
-        if ($resql) {
619
-            $obj = $this->db->fetch_array($resql);
620
-        } else {
621
-            $error++;
622
-            $this->errors[] = $this->db->lasterror;
623
-        }
624
-        if (empty($obj)) {
625
-            $error++;
626
-            $this->errors[] = 'TemplateDontExist';
627
-        } else {
628
-            $this->template = $obj['0'];
629
-        }
603
+	/**
604
+	 *  Function to load Template
605
+	 *
606
+	 *  @param   int       $templateid        Template id
607
+	 *  @return  int                        0 if OK; >0 if KO
608
+	 */
609
+	function loadTemplate($templateid)
610
+	{
611
+		global $conf;
612
+		$error = 0;
613
+		$sql = 'SELECT template';
614
+		$sql.= ' FROM '.MAIN_DB_PREFIX.'printer_receipt_template';
615
+		$sql.= ' WHERE rowid='.$templateid;
616
+		$sql.= ' AND entity = '.$conf->entity;
617
+		$resql = $this->db->query($sql);
618
+		if ($resql) {
619
+			$obj = $this->db->fetch_array($resql);
620
+		} else {
621
+			$error++;
622
+			$this->errors[] = $this->db->lasterror;
623
+		}
624
+		if (empty($obj)) {
625
+			$error++;
626
+			$this->errors[] = 'TemplateDontExist';
627
+		} else {
628
+			$this->template = $obj['0'];
629
+		}
630 630
 
631
-        return $error;
632
-    }
631
+		return $error;
632
+	}
633 633
 
634 634
 
635
-    /**
636
-     *  Function Init Printer
637
-     *
638
-     *  @param   int       $printerid       Printer id
639
-     *  @return  int                        0 if OK; >0 if KO
640
-     */
641
-    function InitPrinter($printerid)
642
-    {
643
-        global $conf;
644
-        $error=0;
645
-        $sql = 'SELECT rowid, name, fk_type, fk_profile, parameter';
646
-        $sql.= ' FROM '.MAIN_DB_PREFIX.'printer_receipt';
647
-        $sql.= ' WHERE rowid = '.$printerid;
648
-        $sql.= ' AND entity = '.$conf->entity;
649
-        $resql = $this->db->query($sql);
650
-        if ($resql) {
651
-            $obj = $this->db->fetch_array($resql);
652
-        } else {
653
-            $error++;
654
-            $this->errors[] = $this->db->lasterror;
655
-        }
656
-        if (empty($obj)) {
657
-            $error++;
658
-            $this->errors[] = 'PrinterDontExist';
659
-        }
660
-        if (! $error) {
661
-            $parameter = $obj['parameter'];
662
-            try {
663
-                switch ($obj['fk_type']) {
664
-                    case 1:
665
-                        require_once DOL_DOCUMENT_ROOT .'/includes/mike42/escpos-php/src/DummyPrintConnector.php';
666
-                        $this->connector = new DummyPrintConnector();
667
-                        break;
668
-                    case 2:
669
-                        $this->connector = new FilePrintConnector($parameter);
670
-                        break;
671
-                    case 3:
672
-                        $parameters = explode(':', $parameter);
673
-                        $this->connector = new NetworkPrintConnector($parameters[0], $parameters[1]);
674
-                        break;
675
-                    case 4:
676
-                        $this->connector = new WindowsPrintConnector($parameter);
677
-                        break;
678
-                    default:
679
-                        $this->connector = 'CONNECTOR_UNKNOWN';
680
-                        break;
681
-                }
682
-                $this->printer = new Escpos($this->connector);
683
-            } catch (Exception $e) {
684
-                $this->errors[] = $e->getMessage();
685
-                $error++;
686
-            }
687
-        }
688
-        return $error;
689
-    }
635
+	/**
636
+	 *  Function Init Printer
637
+	 *
638
+	 *  @param   int       $printerid       Printer id
639
+	 *  @return  int                        0 if OK; >0 if KO
640
+	 */
641
+	function InitPrinter($printerid)
642
+	{
643
+		global $conf;
644
+		$error=0;
645
+		$sql = 'SELECT rowid, name, fk_type, fk_profile, parameter';
646
+		$sql.= ' FROM '.MAIN_DB_PREFIX.'printer_receipt';
647
+		$sql.= ' WHERE rowid = '.$printerid;
648
+		$sql.= ' AND entity = '.$conf->entity;
649
+		$resql = $this->db->query($sql);
650
+		if ($resql) {
651
+			$obj = $this->db->fetch_array($resql);
652
+		} else {
653
+			$error++;
654
+			$this->errors[] = $this->db->lasterror;
655
+		}
656
+		if (empty($obj)) {
657
+			$error++;
658
+			$this->errors[] = 'PrinterDontExist';
659
+		}
660
+		if (! $error) {
661
+			$parameter = $obj['parameter'];
662
+			try {
663
+				switch ($obj['fk_type']) {
664
+					case 1:
665
+						require_once DOL_DOCUMENT_ROOT .'/includes/mike42/escpos-php/src/DummyPrintConnector.php';
666
+						$this->connector = new DummyPrintConnector();
667
+						break;
668
+					case 2:
669
+						$this->connector = new FilePrintConnector($parameter);
670
+						break;
671
+					case 3:
672
+						$parameters = explode(':', $parameter);
673
+						$this->connector = new NetworkPrintConnector($parameters[0], $parameters[1]);
674
+						break;
675
+					case 4:
676
+						$this->connector = new WindowsPrintConnector($parameter);
677
+						break;
678
+					default:
679
+						$this->connector = 'CONNECTOR_UNKNOWN';
680
+						break;
681
+				}
682
+				$this->printer = new Escpos($this->connector);
683
+			} catch (Exception $e) {
684
+				$this->errors[] = $e->getMessage();
685
+				$error++;
686
+			}
687
+		}
688
+		return $error;
689
+	}
690 690
 }
Please login to merge, or discard this patch.
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
  *
93 93
  */
94 94
 
95
-require_once DOL_DOCUMENT_ROOT .'/includes/mike42/escpos-php/Escpos.php';
95
+require_once DOL_DOCUMENT_ROOT.'/includes/mike42/escpos-php/Escpos.php';
96 96
 
97 97
  
98 98
 /**
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
      */
122 122
     function __construct($db)
123 123
     {
124
-        $this->db=$db;
124
+        $this->db = $db;
125 125
         $this->tags = array(
126 126
             'dol_align_left',
127 127
             'dol_align_center',
@@ -205,8 +205,8 @@  discard block
 block discarded – undo
205 205
         $error = 0;
206 206
         $line = 0;
207 207
         $sql = 'SELECT rowid, name, fk_type, fk_profile, parameter';
208
-        $sql.= ' FROM '.MAIN_DB_PREFIX.'printer_receipt';
209
-        $sql.= ' WHERE entity = '.$conf->entity;
208
+        $sql .= ' FROM '.MAIN_DB_PREFIX.'printer_receipt';
209
+        $sql .= ' WHERE entity = '.$conf->entity;
210 210
         $resql = $this->db->query($sql);
211 211
         if ($resql) {
212 212
             $num = $this->db->num_rows($resql);
@@ -272,8 +272,8 @@  discard block
 block discarded – undo
272 272
         $error = 0;
273 273
         $line = 0;
274 274
         $sql = 'SELECT rowid, name, template';
275
-        $sql.= ' FROM '.MAIN_DB_PREFIX.'printer_receipt_template';
276
-        $sql.= ' WHERE entity = '.$conf->entity;
275
+        $sql .= ' FROM '.MAIN_DB_PREFIX.'printer_receipt_template';
276
+        $sql .= ' WHERE entity = '.$conf->entity;
277 277
         $resql = $this->db->query($sql);
278 278
         if ($resql) {
279 279
             $num = $this->db->num_rows($resql);
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
      *  @param    string    $htmlname       select html name
298 298
      *  @return  int                        0 if OK; >0 if KO
299 299
      */
300
-    function selectTypePrinter($selected='', $htmlname='printertypeid')
300
+    function selectTypePrinter($selected = '', $htmlname = 'printertypeid')
301 301
     {
302 302
         global $langs;
303 303
         
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
      *  @param    string    $htmlname       select html name
322 322
      *  @return  int                        0 if OK; >0 if KO
323 323
      */
324
-    function selectProfilePrinter($selected='', $htmlname='printerprofileid')
324
+    function selectProfilePrinter($selected = '', $htmlname = 'printerprofileid')
325 325
     {
326 326
         global $langs;
327 327
         
@@ -352,10 +352,10 @@  discard block
 block discarded – undo
352 352
         global $conf;
353 353
         $error = 0;
354 354
         $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'printer_receipt';
355
-        $sql.= ' (name, fk_type, fk_profile, parameter, entity)';
356
-        $sql.= ' VALUES ("'.$this->db->escape($name).'", '.$type.', '.$profile.', "'.$this->db->escape($parameter).'", '.$conf->entity.')';
355
+        $sql .= ' (name, fk_type, fk_profile, parameter, entity)';
356
+        $sql .= ' VALUES ("'.$this->db->escape($name).'", '.$type.', '.$profile.', "'.$this->db->escape($parameter).'", '.$conf->entity.')';
357 357
         $resql = $this->db->query($sql);
358
-        if (! $resql) {
358
+        if (!$resql) {
359 359
             $error++;
360 360
             $this->errors[] = $this->db->lasterror;
361 361
         }
@@ -377,13 +377,13 @@  discard block
 block discarded – undo
377 377
         global $conf;
378 378
         $error = 0;
379 379
         $sql = 'UPDATE '.MAIN_DB_PREFIX.'printer_receipt';
380
-        $sql.= ' SET name="'.$this->db->escape($name).'"';
381
-        $sql.= ', fk_type='.$type;
382
-        $sql.= ', fk_profile='.$profile;
383
-        $sql.= ', parameter="'.$this->db->escape($parameter).'"';
384
-        $sql.= ' WHERE rowid='.$printerid;
380
+        $sql .= ' SET name="'.$this->db->escape($name).'"';
381
+        $sql .= ', fk_type='.$type;
382
+        $sql .= ', fk_profile='.$profile;
383
+        $sql .= ', parameter="'.$this->db->escape($parameter).'"';
384
+        $sql .= ' WHERE rowid='.$printerid;
385 385
         $resql = $this->db->query($sql);
386
-        if (! $resql) {
386
+        if (!$resql) {
387 387
             $error++;
388 388
             $this->errors[] = $this->db->lasterror;
389 389
         }
@@ -401,9 +401,9 @@  discard block
 block discarded – undo
401 401
         global $conf;
402 402
         $error = 0;
403 403
         $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'printer_receipt';
404
-        $sql.= ' WHERE rowid='.$printerid;
404
+        $sql .= ' WHERE rowid='.$printerid;
405 405
         $resql = $this->db->query($sql);
406
-        if (! $resql) {
406
+        if (!$resql) {
407 407
             $error++;
408 408
             $this->errors[] = $this->db->lasterror;
409 409
         }
@@ -423,11 +423,11 @@  discard block
 block discarded – undo
423 423
         global $conf;
424 424
         $error = 0;
425 425
         $sql = 'UPDATE '.MAIN_DB_PREFIX.'printer_receipt_template';
426
-        $sql.= ' SET name="'.$this->db->escape($name).'"';
427
-        $sql.= ', template="'.$this->db->escape($template).'"';
428
-        $sql.= ' WHERE rowid='.$templateid;
426
+        $sql .= ' SET name="'.$this->db->escape($name).'"';
427
+        $sql .= ', template="'.$this->db->escape($template).'"';
428
+        $sql .= ' WHERE rowid='.$templateid;
429 429
         $resql = $this->db->query($sql);
430
-        if (! $resql) {
430
+        if (!$resql) {
431 431
             $error++;
432 432
             $this->errors[] = $this->db->lasterror;
433 433
         }
@@ -445,9 +445,9 @@  discard block
 block discarded – undo
445 445
     {
446 446
         global $conf;
447 447
         $error = 0;
448
-        $img = new EscposImage(DOL_DOCUMENT_ROOT .'/theme/common/dolibarr_logo_bw.png');
448
+        $img = new EscposImage(DOL_DOCUMENT_ROOT.'/theme/common/dolibarr_logo_bw.png');
449 449
         $ret = $this->InitPrinter($printerid);
450
-        if ($ret>0) {
450
+        if ($ret > 0) {
451 451
             setEventMessages($this->error, $this->errors, 'errors');
452 452
         } else {
453 453
             try {
@@ -518,35 +518,35 @@  discard block
 block discarded – undo
518 518
         $level = 0;
519 519
         $html = '<table border="1" style="width:210px"><pre>';
520 520
         $ret = $this->InitPrinter($printerid);
521
-        if ($ret>0) {
521
+        if ($ret > 0) {
522 522
             setEventMessages($this->error, $this->errors, 'errors');
523 523
         } 
524 524
         else 
525 525
         {
526 526
             $nboflines = count($vals);
527
-            for ($line=0; $line < $nboflines; $line++) 
527
+            for ($line = 0; $line < $nboflines; $line++) 
528 528
             {
529 529
                 switch ($vals[$line]['tag']) {
530 530
                     case 'DOL_ALIGN_CENTER':
531 531
                         $this->printer->setJustification(Escpos::JUSTIFY_CENTER);
532
-                        $html.='<center>';
532
+                        $html .= '<center>';
533 533
                         $this->printer->text($vals[$line]['value']);
534 534
                         break;
535 535
                     case 'DOL_ALIGN_RIGHT':
536 536
                         $this->printer->setJustification(Escpos::JUSTIFY_RIGHT);
537
-                        $html.='<right>';
537
+                        $html .= '<right>';
538 538
                         break;
539 539
                     case 'DOL_ALIGN_LEFT':
540 540
                         $this->printer->setJustification(Escpos::JUSTIFY_LEFT);
541
-                        $html.='<left>';
541
+                        $html .= '<left>';
542 542
                         break;
543 543
                     case 'DOL_OPEN_DRAWER':
544 544
                         $this->printer->pulse();
545
-                        $html.= ' &#991;'.nl2br($vals[$line]['value']);
545
+                        $html .= ' &#991;'.nl2br($vals[$line]['value']);
546 546
                         break;
547 547
                     case 'DOL_ACTIVATE_BUZZER':
548 548
                         //$this->printer->buzzer();
549
-                        $html.= ' &#x266b;'.nl2br($vals[$line]['value']);
549
+                        $html .= ' &#x266b;'.nl2br($vals[$line]['value']);
550 550
                         break;
551 551
                     case 'DOL_PRINT_BARCODE':
552 552
                         // $vals[$line]['value'] -> barcode($content, $type)
@@ -559,15 +559,15 @@  discard block
 block discarded – undo
559 559
                     case 'DOL_PRINT_QRCODE':
560 560
                         // $vals[$line]['value'] -> qrCode($content, $ec, $size, $model)
561 561
                         $this->printer->qrcode($vals[$line]['value']);
562
-                        $html.='QRCODE: '.$vals[$line]['value'];
562
+                        $html .= 'QRCODE: '.$vals[$line]['value'];
563 563
                         break;
564 564
                     case 'DOL_CUT_PAPER_FULL':
565 565
                         $this->printer->cut(Escpos::CUT_FULL);
566
-                        $html.= ' &#9986;'.nl2br($vals[$line]['value']);
566
+                        $html .= ' &#9986;'.nl2br($vals[$line]['value']);
567 567
                         break;
568 568
                     case 'DOL_CUT_PAPER_PARTIAL':
569 569
                         $this->printer->cut(Escpos::CUT_PARTIAL);
570
-                        $html.= ' &#9986;'.nl2br($vals[$line]['value']);
570
+                        $html .= ' &#9986;'.nl2br($vals[$line]['value']);
571 571
                         break;
572 572
                     case 'DOL_USE_FONT_A':
573 573
                         $this->printer->setFont(Escpos::FONT_A);
@@ -583,13 +583,13 @@  discard block
 block discarded – undo
583 583
                         break;
584 584
                     default:
585 585
                         $this->printer->text($vals[$line]['value']);
586
-                        $html.= nl2br($vals[$line]['value']);
586
+                        $html .= nl2br($vals[$line]['value']);
587 587
                         $this->errors[] = 'UnknowTag: &lt;'.strtolower($vals[$line]['tag']).'&gt;';
588 588
                         $error++;
589 589
                         break;
590 590
                 }
591 591
             }
592
-            $html.= '</pre></table>';
592
+            $html .= '</pre></table>';
593 593
             print $html;
594 594
             // Close and print
595 595
             // uncomment next line to see content sent to printer
@@ -611,9 +611,9 @@  discard block
 block discarded – undo
611 611
         global $conf;
612 612
         $error = 0;
613 613
         $sql = 'SELECT template';
614
-        $sql.= ' FROM '.MAIN_DB_PREFIX.'printer_receipt_template';
615
-        $sql.= ' WHERE rowid='.$templateid;
616
-        $sql.= ' AND entity = '.$conf->entity;
614
+        $sql .= ' FROM '.MAIN_DB_PREFIX.'printer_receipt_template';
615
+        $sql .= ' WHERE rowid='.$templateid;
616
+        $sql .= ' AND entity = '.$conf->entity;
617 617
         $resql = $this->db->query($sql);
618 618
         if ($resql) {
619 619
             $obj = $this->db->fetch_array($resql);
@@ -641,11 +641,11 @@  discard block
 block discarded – undo
641 641
     function InitPrinter($printerid)
642 642
     {
643 643
         global $conf;
644
-        $error=0;
644
+        $error = 0;
645 645
         $sql = 'SELECT rowid, name, fk_type, fk_profile, parameter';
646
-        $sql.= ' FROM '.MAIN_DB_PREFIX.'printer_receipt';
647
-        $sql.= ' WHERE rowid = '.$printerid;
648
-        $sql.= ' AND entity = '.$conf->entity;
646
+        $sql .= ' FROM '.MAIN_DB_PREFIX.'printer_receipt';
647
+        $sql .= ' WHERE rowid = '.$printerid;
648
+        $sql .= ' AND entity = '.$conf->entity;
649 649
         $resql = $this->db->query($sql);
650 650
         if ($resql) {
651 651
             $obj = $this->db->fetch_array($resql);
@@ -657,12 +657,12 @@  discard block
 block discarded – undo
657 657
             $error++;
658 658
             $this->errors[] = 'PrinterDontExist';
659 659
         }
660
-        if (! $error) {
660
+        if (!$error) {
661 661
             $parameter = $obj['parameter'];
662 662
             try {
663 663
                 switch ($obj['fk_type']) {
664 664
                     case 1:
665
-                        require_once DOL_DOCUMENT_ROOT .'/includes/mike42/escpos-php/src/DummyPrintConnector.php';
665
+                        require_once DOL_DOCUMENT_ROOT.'/includes/mike42/escpos-php/src/DummyPrintConnector.php';
666 666
                         $this->connector = new DummyPrintConnector();
667 667
                         break;
668 668
                     case 2:
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -520,8 +520,7 @@
 block discarded – undo
520 520
         $ret = $this->InitPrinter($printerid);
521 521
         if ($ret>0) {
522 522
             setEventMessages($this->error, $this->errors, 'errors');
523
-        } 
524
-        else 
523
+        } else 
525 524
         {
526 525
             $nboflines = count($vals);
527 526
             for ($line=0; $line < $nboflines; $line++) 
Please login to merge, or discard this patch.
htdocs/core/class/html.formcontract.class.php 3 patches
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -27,19 +27,19 @@  discard block
 block discarded – undo
27 27
  */
28 28
 class FormContract
29 29
 {
30
-    var $db;
31
-    var $error;
30
+	var $db;
31
+	var $error;
32 32
 
33 33
 
34
-    /**
35
-     * Constructor
36
-     *
37
-     * @param		DoliDB		$db      Database handler
38
-     */
39
-    public function __construct($db)
40
-    {
41
-        $this->db = $db;
42
-    }
34
+	/**
35
+	 * Constructor
36
+	 *
37
+	 * @param		DoliDB		$db      Database handler
38
+	 */
39
+	public function __construct($db)
40
+	{
41
+		$this->db = $db;
42
+	}
43 43
 
44 44
 
45 45
 	/**
@@ -160,15 +160,15 @@  discard block
 block discarded – undo
160 160
 	 */
161 161
 	function formSelectContract($page, $socid=-1, $selected='', $htmlname='contrattid', $maxlength=16, $showempty=1)
162 162
 	{
163
-	    global $langs;
163
+		global $langs;
164 164
 	
165
-        print "\n";
166
-        print '<form method="post" action="'.$page.'">';
167
-        print '<input type="hidden" name="action" value="setcontract">';
168
-        print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
169
-        $this->select_contract($socid, $selected, $htmlname, $maxlength, $showempty);
170
-        print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
171
-        print '</form>';
165
+		print "\n";
166
+		print '<form method="post" action="'.$page.'">';
167
+		print '<input type="hidden" name="action" value="setcontract">';
168
+		print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
169
+		$this->select_contract($socid, $selected, $htmlname, $maxlength, $showempty);
170
+		print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
171
+		print '</form>';
172 172
 	}	
173 173
 	
174 174
 }
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -52,24 +52,24 @@  discard block
 block discarded – undo
52 52
 	 *	@param	int		$showempty	Show empty line
53 53
 	 *	@return int         		Nbr of project if OK, <0 if KO
54 54
 	 */
55
-	function select_contract($socid=-1, $selected='', $htmlname='contrattid', $maxlength=16, $showempty=1)
55
+	function select_contract($socid = -1, $selected = '', $htmlname = 'contrattid', $maxlength = 16, $showempty = 1)
56 56
 	{
57
-		global $db,$user,$conf,$langs;
57
+		global $db, $user, $conf, $langs;
58 58
 
59 59
 		$hideunselectables = false;
60
-		if (! empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) $hideunselectables = true;
60
+		if (!empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) $hideunselectables = true;
61 61
 
62 62
 		// Search all contacts
63 63
 		$sql = 'SELECT c.rowid, c.ref, c.fk_soc, c.statut';
64
-		$sql.= ' FROM '.MAIN_DB_PREFIX .'contrat as c';
65
-		$sql.= " WHERE c.entity = ".$conf->entity;
64
+		$sql .= ' FROM '.MAIN_DB_PREFIX.'contrat as c';
65
+		$sql .= " WHERE c.entity = ".$conf->entity;
66 66
 		//if ($contratListId) $sql.= " AND c.rowid IN (".$contratListId.")";
67
-		if ($socid == 0) $sql.= " AND (c.fk_soc = 0 OR c.fk_soc IS NULL)";
68
-		if ($socid > 0)  $sql.= " AND (c.fk_soc=".$socid." OR c.fk_soc IS NULL)";
69
-		$sql.= " ORDER BY c.ref ";
67
+		if ($socid == 0) $sql .= " AND (c.fk_soc = 0 OR c.fk_soc IS NULL)";
68
+		if ($socid > 0)  $sql .= " AND (c.fk_soc=".$socid." OR c.fk_soc IS NULL)";
69
+		$sql .= " ORDER BY c.ref ";
70 70
 
71 71
 		dol_syslog(get_class($this)."::select_contract", LOG_DEBUG);
72
-		$resql=$db->query($sql);
72
+		$resql = $db->query($sql);
73 73
 		if ($resql)
74 74
 		{
75 75
 			print '<select class="flat" name="'.$htmlname.'">';
@@ -82,13 +82,13 @@  discard block
 block discarded – undo
82 82
 				{
83 83
 					$obj = $db->fetch_object($resql);
84 84
 					// 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.
85
-					if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && ! $user->rights->societe->lire)
85
+					if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$user->rights->societe->lire)
86 86
 					{
87 87
 						// Do nothing
88 88
 					}
89 89
 					else
90 90
 					{
91
-						$labeltoshow=dol_trunc($obj->ref,18);
91
+						$labeltoshow = dol_trunc($obj->ref, 18);
92 92
 						//if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')';
93 93
 						//else $labeltoshow.=' ('.$langs->trans("Private").')';
94 94
 						if (!empty($selected) && $selected == $obj->rowid && $obj->statut > 0)
@@ -97,30 +97,30 @@  discard block
 block discarded – undo
97 97
 						}
98 98
 						else
99 99
 						{
100
-							$disabled=0;
101
-							if (! $obj->statut > 0)
100
+							$disabled = 0;
101
+							if (!$obj->statut > 0)
102 102
 							{
103
-								$disabled=1;
104
-								$labeltoshow.=' ('.$langs->trans("Draft").')';
103
+								$disabled = 1;
104
+								$labeltoshow .= ' ('.$langs->trans("Draft").')';
105 105
 							}
106
-							if ($socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid))
106
+							if ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid))
107 107
 							{
108
-								$disabled=1;
109
-								$labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany");
108
+								$disabled = 1;
109
+								$labeltoshow .= ' - '.$langs->trans("LinkedToAnotherCompany");
110 110
 							}
111 111
 
112 112
 							if ($hideunselectables && $disabled)
113 113
 							{
114
-								$resultat='';
114
+								$resultat = '';
115 115
 							}
116 116
 							else
117 117
 							{
118
-								$resultat='<option value="'.$obj->rowid.'"';
119
-								if ($disabled) $resultat.=' disabled';
118
+								$resultat = '<option value="'.$obj->rowid.'"';
119
+								if ($disabled) $resultat .= ' disabled';
120 120
 								//if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
121 121
 								//else $labeltoshow.=' ('.$langs->trans("Private").')';
122
-								$resultat.='>'.$labeltoshow;
123
-								$resultat.='</option>';
122
+								$resultat .= '>'.$labeltoshow;
123
+								$resultat .= '</option>';
124 124
 							}
125 125
 							print $resultat;
126 126
 						}
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 			if (!empty($conf->use_javascript_ajax))
135 135
 			{
136 136
 				// Make select dynamic
137
-				include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
137
+				include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
138 138
 				print ajax_combobox($htmlname);
139 139
 			}
140 140
 			
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
 	 *	@param	int		$showempty	Show empty line
159 159
 	 *	@return int         		Nbr of project if OK, <0 if KO
160 160
 	 */
161
-	function formSelectContract($page, $socid=-1, $selected='', $htmlname='contrattid', $maxlength=16, $showempty=1)
161
+	function formSelectContract($page, $socid = -1, $selected = '', $htmlname = 'contrattid', $maxlength = 16, $showempty = 1)
162 162
 	{
163 163
 	    global $langs;
164 164
 	
Please login to merge, or discard this patch.
Braces   +19 added lines, -13 removed lines patch added patch discarded remove patch
@@ -57,15 +57,21 @@  discard block
 block discarded – undo
57 57
 		global $db,$user,$conf,$langs;
58 58
 
59 59
 		$hideunselectables = false;
60
-		if (! empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) $hideunselectables = true;
60
+		if (! empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) {
61
+			$hideunselectables = true;
62
+		}
61 63
 
62 64
 		// Search all contacts
63 65
 		$sql = 'SELECT c.rowid, c.ref, c.fk_soc, c.statut';
64 66
 		$sql.= ' FROM '.MAIN_DB_PREFIX .'contrat as c';
65 67
 		$sql.= " WHERE c.entity = ".$conf->entity;
66 68
 		//if ($contratListId) $sql.= " AND c.rowid IN (".$contratListId.")";
67
-		if ($socid == 0) $sql.= " AND (c.fk_soc = 0 OR c.fk_soc IS NULL)";
68
-		if ($socid > 0)  $sql.= " AND (c.fk_soc=".$socid." OR c.fk_soc IS NULL)";
69
+		if ($socid == 0) {
70
+			$sql.= " AND (c.fk_soc = 0 OR c.fk_soc IS NULL)";
71
+		}
72
+		if ($socid > 0) {
73
+			$sql.= " AND (c.fk_soc=".$socid." OR c.fk_soc IS NULL)";
74
+		}
69 75
 		$sql.= " ORDER BY c.ref ";
70 76
 
71 77
 		dol_syslog(get_class($this)."::select_contract", LOG_DEBUG);
@@ -73,7 +79,9 @@  discard block
 block discarded – undo
73 79
 		if ($resql)
74 80
 		{
75 81
 			print '<select class="flat" name="'.$htmlname.'">';
76
-			if ($showempty) print '<option value="0">&nbsp;</option>';
82
+			if ($showempty) {
83
+				print '<option value="0">&nbsp;</option>';
84
+			}
77 85
 			$num = $db->num_rows($resql);
78 86
 			$i = 0;
79 87
 			if ($num)
@@ -85,8 +93,7 @@  discard block
 block discarded – undo
85 93
 					if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && ! $user->rights->societe->lire)
86 94
 					{
87 95
 						// Do nothing
88
-					}
89
-					else
96
+					} else
90 97
 					{
91 98
 						$labeltoshow=dol_trunc($obj->ref,18);
92 99
 						//if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')';
@@ -94,8 +101,7 @@  discard block
 block discarded – undo
94 101
 						if (!empty($selected) && $selected == $obj->rowid && $obj->statut > 0)
95 102
 						{
96 103
 							print '<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>';
97
-						}
98
-						else
104
+						} else
99 105
 						{
100 106
 							$disabled=0;
101 107
 							if (! $obj->statut > 0)
@@ -112,11 +118,12 @@  discard block
 block discarded – undo
112 118
 							if ($hideunselectables && $disabled)
113 119
 							{
114 120
 								$resultat='';
115
-							}
116
-							else
121
+							} else
117 122
 							{
118 123
 								$resultat='<option value="'.$obj->rowid.'"';
119
-								if ($disabled) $resultat.=' disabled';
124
+								if ($disabled) {
125
+									$resultat.=' disabled';
126
+								}
120 127
 								//if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
121 128
 								//else $labeltoshow.=' ('.$langs->trans("Private").')';
122 129
 								$resultat.='>'.$labeltoshow;
@@ -139,8 +146,7 @@  discard block
 block discarded – undo
139 146
 			}
140 147
 			
141 148
 			return $num;
142
-		}
143
-		else
149
+		} else
144 150
 		{
145 151
 			dol_print_error($db);
146 152
 			return -1;
Please login to merge, or discard this patch.
htdocs/core/class/dolprintipp.class.php 3 patches
Indentation   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -26,108 +26,108 @@
 block discarded – undo
26 26
  */
27 27
 class dolprintIPP
28 28
 {
29
-    var $host;
30
-    var $port;
31
-    var $userid;    /* user login */
32
-    var $user;
33
-    var $password;
34
-    var $error;
35
-    var $db;
29
+	var $host;
30
+	var $port;
31
+	var $userid;    /* user login */
32
+	var $user;
33
+	var $password;
34
+	var $error;
35
+	var $db;
36 36
 
37 37
 
38 38
 
39
-    /**
40
-     * Constructor
41
-     *
42
-     * @param   DoliDB      $db         database
43
-     * @param   string      $host       host of Cups
44
-     * @param   string      $port       port
45
-     * @param   string      $userid     userid
46
-     * @param   string      $user       user
47
-     * @param   string      $password   password
48
-     */
49
-    function __construct($db,$host,$port,$userid,$user,$password)
50
-    {
51
-        $this->db=$db;
52
-        $this->host=$host;
53
-        $this->port=$port;
54
-        $this->userid=$userid;
55
-        $this->user=$user;
56
-        $this->password=$password;
57
-    }
39
+	/**
40
+	 * Constructor
41
+	 *
42
+	 * @param   DoliDB      $db         database
43
+	 * @param   string      $host       host of Cups
44
+	 * @param   string      $port       port
45
+	 * @param   string      $userid     userid
46
+	 * @param   string      $user       user
47
+	 * @param   string      $password   password
48
+	 */
49
+	function __construct($db,$host,$port,$userid,$user,$password)
50
+	{
51
+		$this->db=$db;
52
+		$this->host=$host;
53
+		$this->port=$port;
54
+		$this->userid=$userid;
55
+		$this->user=$user;
56
+		$this->password=$password;
57
+	}
58 58
 
59 59
 
60
-    /**
61
-     *  List jobs print
62
-     *
63
-     * @param   string      $module     module
64
-     *
65
-     *  @return void
66
-     */
67
-    function list_jobs($module)
68
-    {
69
-        global $conf, $db, $bc, $langs;
70
-        include_once DOL_DOCUMENT_ROOT.'/includes/printipp/CupsPrintIPP.php';
71
-        $ipp = new CupsPrintIPP();
72
-        $ipp->setLog(DOL_DATA_ROOT.'/printipp.log','file',3); // logging very verbose
73
-        $ipp->setHost($this->host);
74
-        $ipp->setPort($this->port);
75
-        $ipp->setUserName($this->userid);
76
-        if (! empty($this->user)) $ipp->setAuthentication($this->user,$this->password);
77
-        // select printer uri for module order, propal,...
78
-        $sql = 'SELECT rowid,printer_uri,printer_name FROM '.MAIN_DB_PREFIX.'printer_ipp WHERE module="'.$module.'"';
79
-        $result = $this->db->query($sql);
80
-        if ($result)
81
-        {
82
-            $obj = $this->db->fetch_object($result);
83
-            if ($obj)
84
-            {
85
-                $ipp->setPrinterURI($obj->printer_uri);
86
-            }
87
-            else
88
-            {
89
-                // All printers
90
-                $ipp->setPrinterURI("ipp://localhost:631/printers/");
91
-            }
92
-        }
93
-        // Getting Jobs
94
-        try {
95
-        	$ipp->getJobs(false,0,'completed',false);			// May return errors if setup not correct
96
-        }
97
-        catch(Exception $e)
98
-        {
99
-            setEventMessage('[printipp] '.$langs->trans('CoreErrorMessage'), 'errors');
100
-            dol_syslog($e->getMessage(), LOG_ERR);
101
-        }
60
+	/**
61
+	 *  List jobs print
62
+	 *
63
+	 * @param   string      $module     module
64
+	 *
65
+	 *  @return void
66
+	 */
67
+	function list_jobs($module)
68
+	{
69
+		global $conf, $db, $bc, $langs;
70
+		include_once DOL_DOCUMENT_ROOT.'/includes/printipp/CupsPrintIPP.php';
71
+		$ipp = new CupsPrintIPP();
72
+		$ipp->setLog(DOL_DATA_ROOT.'/printipp.log','file',3); // logging very verbose
73
+		$ipp->setHost($this->host);
74
+		$ipp->setPort($this->port);
75
+		$ipp->setUserName($this->userid);
76
+		if (! empty($this->user)) $ipp->setAuthentication($this->user,$this->password);
77
+		// select printer uri for module order, propal,...
78
+		$sql = 'SELECT rowid,printer_uri,printer_name FROM '.MAIN_DB_PREFIX.'printer_ipp WHERE module="'.$module.'"';
79
+		$result = $this->db->query($sql);
80
+		if ($result)
81
+		{
82
+			$obj = $this->db->fetch_object($result);
83
+			if ($obj)
84
+			{
85
+				$ipp->setPrinterURI($obj->printer_uri);
86
+			}
87
+			else
88
+			{
89
+				// All printers
90
+				$ipp->setPrinterURI("ipp://localhost:631/printers/");
91
+			}
92
+		}
93
+		// Getting Jobs
94
+		try {
95
+			$ipp->getJobs(false,0,'completed',false);			// May return errors if setup not correct
96
+		}
97
+		catch(Exception $e)
98
+		{
99
+			setEventMessage('[printipp] '.$langs->trans('CoreErrorMessage'), 'errors');
100
+			dol_syslog($e->getMessage(), LOG_ERR);
101
+		}
102 102
 
103
-        print '<table width="100%" class="noborder">';
104
-        print '<tr class="liste_titre">';
105
-        print "<td>Id</td>";
106
-        print "<td>Owner</td>";
107
-        print "<td>Printer</td>";
108
-        print "<td>File</td>";
109
-        print "<td>Status</td>";
110
-        print "<td>Cancel</td>";
111
-        print "</tr>\n";
112
-        $jobs = $ipp->jobs_attributes;
113
-        $var = true;
114
-        //print '<pre>'.print_r($jobs,true).'</pre>';
115
-        if (is_array($jobs))
116
-        {
117
-	        foreach ($jobs as $value)
118
-	        {
103
+		print '<table width="100%" class="noborder">';
104
+		print '<tr class="liste_titre">';
105
+		print "<td>Id</td>";
106
+		print "<td>Owner</td>";
107
+		print "<td>Printer</td>";
108
+		print "<td>File</td>";
109
+		print "<td>Status</td>";
110
+		print "<td>Cancel</td>";
111
+		print "</tr>\n";
112
+		$jobs = $ipp->jobs_attributes;
113
+		$var = true;
114
+		//print '<pre>'.print_r($jobs,true).'</pre>';
115
+		if (is_array($jobs))
116
+		{
117
+			foreach ($jobs as $value)
118
+			{
119 119
 	            
120
-	            print '<tr class="oddeven">';
121
-	            print '<td>'.$value->job_id->_value0.'</td>';
122
-	            print '<td>'.$value->job_originating_user_name->_value0.'</td>';
123
-	            print '<td>'.$value->printer_uri->_value0.'</td>';
124
-	            print '<td>'.$value->job_name->_value0.'</td>';
125
-	            print '<td>'.$value->job_state->_value0.'</td>';
126
-	            print '<td>'.$value->job_uri->_value0.'</td>';
127
-	            print '</tr>';
128
-	        }
129
-        }
130
-        print "</table>";
131
-    }
120
+				print '<tr class="oddeven">';
121
+				print '<td>'.$value->job_id->_value0.'</td>';
122
+				print '<td>'.$value->job_originating_user_name->_value0.'</td>';
123
+				print '<td>'.$value->printer_uri->_value0.'</td>';
124
+				print '<td>'.$value->job_name->_value0.'</td>';
125
+				print '<td>'.$value->job_state->_value0.'</td>';
126
+				print '<td>'.$value->job_uri->_value0.'</td>';
127
+				print '</tr>';
128
+			}
129
+		}
130
+		print "</table>";
131
+	}
132 132
 
133 133
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 {
29 29
     var $host;
30 30
     var $port;
31
-    var $userid;    /* user login */
31
+    var $userid; /* user login */
32 32
     var $user;
33 33
     var $password;
34 34
     var $error;
@@ -46,14 +46,14 @@  discard block
 block discarded – undo
46 46
      * @param   string      $user       user
47 47
      * @param   string      $password   password
48 48
      */
49
-    function __construct($db,$host,$port,$userid,$user,$password)
49
+    function __construct($db, $host, $port, $userid, $user, $password)
50 50
     {
51
-        $this->db=$db;
52
-        $this->host=$host;
53
-        $this->port=$port;
54
-        $this->userid=$userid;
55
-        $this->user=$user;
56
-        $this->password=$password;
51
+        $this->db = $db;
52
+        $this->host = $host;
53
+        $this->port = $port;
54
+        $this->userid = $userid;
55
+        $this->user = $user;
56
+        $this->password = $password;
57 57
     }
58 58
 
59 59
 
@@ -69,11 +69,11 @@  discard block
 block discarded – undo
69 69
         global $conf, $db, $bc, $langs;
70 70
         include_once DOL_DOCUMENT_ROOT.'/includes/printipp/CupsPrintIPP.php';
71 71
         $ipp = new CupsPrintIPP();
72
-        $ipp->setLog(DOL_DATA_ROOT.'/printipp.log','file',3); // logging very verbose
72
+        $ipp->setLog(DOL_DATA_ROOT.'/printipp.log', 'file', 3); // logging very verbose
73 73
         $ipp->setHost($this->host);
74 74
         $ipp->setPort($this->port);
75 75
         $ipp->setUserName($this->userid);
76
-        if (! empty($this->user)) $ipp->setAuthentication($this->user,$this->password);
76
+        if (!empty($this->user)) $ipp->setAuthentication($this->user, $this->password);
77 77
         // select printer uri for module order, propal,...
78 78
         $sql = 'SELECT rowid,printer_uri,printer_name FROM '.MAIN_DB_PREFIX.'printer_ipp WHERE module="'.$module.'"';
79 79
         $result = $this->db->query($sql);
@@ -92,9 +92,9 @@  discard block
 block discarded – undo
92 92
         }
93 93
         // Getting Jobs
94 94
         try {
95
-        	$ipp->getJobs(false,0,'completed',false);			// May return errors if setup not correct
95
+        	$ipp->getJobs(false, 0, 'completed', false); // May return errors if setup not correct
96 96
         }
97
-        catch(Exception $e)
97
+        catch (Exception $e)
98 98
         {
99 99
             setEventMessage('[printipp] '.$langs->trans('CoreErrorMessage'), 'errors');
100 100
             dol_syslog($e->getMessage(), LOG_ERR);
Please login to merge, or discard this patch.
Braces   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -73,7 +73,9 @@  discard block
 block discarded – undo
73 73
         $ipp->setHost($this->host);
74 74
         $ipp->setPort($this->port);
75 75
         $ipp->setUserName($this->userid);
76
-        if (! empty($this->user)) $ipp->setAuthentication($this->user,$this->password);
76
+        if (! empty($this->user)) {
77
+        	$ipp->setAuthentication($this->user,$this->password);
78
+        }
77 79
         // select printer uri for module order, propal,...
78 80
         $sql = 'SELECT rowid,printer_uri,printer_name FROM '.MAIN_DB_PREFIX.'printer_ipp WHERE module="'.$module.'"';
79 81
         $result = $this->db->query($sql);
@@ -83,8 +85,7 @@  discard block
 block discarded – undo
83 85
             if ($obj)
84 86
             {
85 87
                 $ipp->setPrinterURI($obj->printer_uri);
86
-            }
87
-            else
88
+            } else
88 89
             {
89 90
                 // All printers
90 91
                 $ipp->setPrinterURI("ipp://localhost:631/printers/");
@@ -93,8 +94,7 @@  discard block
 block discarded – undo
93 94
         // Getting Jobs
94 95
         try {
95 96
         	$ipp->getJobs(false,0,'completed',false);			// May return errors if setup not correct
96
-        }
97
-        catch(Exception $e)
97
+        } catch(Exception $e)
98 98
         {
99 99
             setEventMessage('[printipp] '.$langs->trans('CoreErrorMessage'), 'errors');
100 100
             dol_syslog($e->getMessage(), LOG_ERR);
Please login to merge, or discard this patch.
htdocs/core/actions_setmoduleoptions.inc.php 3 patches
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -29,61 +29,61 @@
 block discarded – undo
29 29
 // Define constants for submodules that contains parameters (forms with param1, param2, ... and value1, value2, ...)
30 30
 if ($action == 'setModuleOptions')
31 31
 {
32
-    $db->begin();
32
+	$db->begin();
33 33
 
34
-    // Process common param fields
35
-    if (is_array($_POST))
36
-    {
37
-        foreach($_POST as $key => $val)
38
-        {
39
-            if (preg_match('/^param(\d*)$/', $key, $reg))    // Works for POST['param'], POST['param1'], POST['param2'], ...
40
-            {
41
-                $param=GETPOST("param".$reg[1],'alpha');
42
-                $value=GETPOST("value".$reg[1],'alpha');
43
-                if ($param)
44
-                {
45
-                    $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity);
46
-                    if (! $res > 0) $error++;
47
-                }
48
-            }
49
-        }
50
-    }
34
+	// Process common param fields
35
+	if (is_array($_POST))
36
+	{
37
+		foreach($_POST as $key => $val)
38
+		{
39
+			if (preg_match('/^param(\d*)$/', $key, $reg))    // Works for POST['param'], POST['param1'], POST['param2'], ...
40
+			{
41
+				$param=GETPOST("param".$reg[1],'alpha');
42
+				$value=GETPOST("value".$reg[1],'alpha');
43
+				if ($param)
44
+				{
45
+					$res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity);
46
+					if (! $res > 0) $error++;
47
+				}
48
+			}
49
+		}
50
+	}
51 51
 
52
-    // Process upload fields
53
-    if (GETPOST('upload','alpha') && GETPOST('keyforuploaddir','aZ09'))
54
-    {
55
-        include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
56
-        $keyforuploaddir=GETPOST('keyforuploaddir','aZ09');
57
-        $listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->$keyforuploaddir)));
58
-        foreach($listofdir as $key=>$tmpdir)
59
-        {
60
-            $tmpdir=trim($tmpdir);
61
-            $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir);
62
-            if (! $tmpdir) {
63
-                unset($listofdir[$key]); continue;
64
-            }
65
-            if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
66
-            else
67
-            {
68
-                $upload_dir=$tmpdir;
69
-            }
70
-        }
71
-        if ($upload_dir)
72
-        {
73
-            $result = dol_add_file_process($upload_dir, 0, 1, 'uploadfile', '');
74
-            if ($result <= 0) $error++;
75
-        }
76
-    }
52
+	// Process upload fields
53
+	if (GETPOST('upload','alpha') && GETPOST('keyforuploaddir','aZ09'))
54
+	{
55
+		include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
56
+		$keyforuploaddir=GETPOST('keyforuploaddir','aZ09');
57
+		$listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->$keyforuploaddir)));
58
+		foreach($listofdir as $key=>$tmpdir)
59
+		{
60
+			$tmpdir=trim($tmpdir);
61
+			$tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir);
62
+			if (! $tmpdir) {
63
+				unset($listofdir[$key]); continue;
64
+			}
65
+			if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
66
+			else
67
+			{
68
+				$upload_dir=$tmpdir;
69
+			}
70
+		}
71
+		if ($upload_dir)
72
+		{
73
+			$result = dol_add_file_process($upload_dir, 0, 1, 'uploadfile', '');
74
+			if ($result <= 0) $error++;
75
+		}
76
+	}
77 77
 
78
-    if (! $error)
79
-    {
80
-        $db->commit();
81
-        if (empty($nomessageinsetmoduleoptions)) setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
82
-    }
83
-    else
84
-    {
85
-        $db->rollback();
86
-        if (empty($nomessageinsetmoduleoptions)) setEventMessages($langs->trans("SetupNotSaved"), null, 'errors');
87
-    }
78
+	if (! $error)
79
+	{
80
+		$db->commit();
81
+		if (empty($nomessageinsetmoduleoptions)) setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
82
+	}
83
+	else
84
+	{
85
+		$db->rollback();
86
+		if (empty($nomessageinsetmoduleoptions)) setEventMessages($langs->trans("SetupNotSaved"), null, 'errors');
87
+	}
88 88
 }
89 89
 
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -31,18 +31,18 @@  discard block
 block discarded – undo
31 31
 {
32 32
 	$db->begin();
33 33
 
34
-	$ok=True;
35
-	foreach($arrayofparameters as $key => $val)
34
+	$ok = True;
35
+	foreach ($arrayofparameters as $key => $val)
36 36
 	{
37
-		$result=dolibarr_set_const($db,$key,GETPOST($key, 'alpha'),'chaine',0,'',$conf->entity);
37
+		$result = dolibarr_set_const($db, $key, GETPOST($key, 'alpha'), 'chaine', 0, '', $conf->entity);
38 38
 		if ($result < 0)
39 39
 		{
40
-			$ok=False;
40
+			$ok = False;
41 41
 			break;
42 42
 		}
43 43
 	}
44 44
 
45
-	if (! $error)
45
+	if (!$error)
46 46
 	{
47 47
 		$db->commit();
48 48
 		if (empty($nomessageinupdate)) setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
@@ -62,38 +62,38 @@  discard block
 block discarded – undo
62 62
     // Process common param fields
63 63
     if (is_array($_POST))
64 64
     {
65
-        foreach($_POST as $key => $val)
65
+        foreach ($_POST as $key => $val)
66 66
         {
67 67
             if (preg_match('/^param(\d*)$/', $key, $reg))    // Works for POST['param'], POST['param1'], POST['param2'], ...
68 68
             {
69
-                $param=GETPOST("param".$reg[1],'alpha');
70
-                $value=GETPOST("value".$reg[1],'alpha');
69
+                $param = GETPOST("param".$reg[1], 'alpha');
70
+                $value = GETPOST("value".$reg[1], 'alpha');
71 71
                 if ($param)
72 72
                 {
73
-                    $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity);
74
-                    if (! $res > 0) $error++;
73
+                    $res = dolibarr_set_const($db, $param, $value, 'chaine', 0, '', $conf->entity);
74
+                    if (!$res > 0) $error++;
75 75
                 }
76 76
             }
77 77
         }
78 78
     }
79 79
 
80 80
     // Process upload fields
81
-    if (GETPOST('upload','alpha') && GETPOST('keyforuploaddir','aZ09'))
81
+    if (GETPOST('upload', 'alpha') && GETPOST('keyforuploaddir', 'aZ09'))
82 82
     {
83 83
         include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
84
-        $keyforuploaddir=GETPOST('keyforuploaddir','aZ09');
85
-        $listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->$keyforuploaddir)));
86
-        foreach($listofdir as $key=>$tmpdir)
84
+        $keyforuploaddir = GETPOST('keyforuploaddir', 'aZ09');
85
+        $listofdir = explode(',', preg_replace('/[\r\n]+/', ',', trim($conf->global->$keyforuploaddir)));
86
+        foreach ($listofdir as $key=>$tmpdir)
87 87
         {
88
-            $tmpdir=trim($tmpdir);
89
-            $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir);
90
-            if (! $tmpdir) {
88
+            $tmpdir = trim($tmpdir);
89
+            $tmpdir = preg_replace('/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
90
+            if (!$tmpdir) {
91 91
                 unset($listofdir[$key]); continue;
92 92
             }
93
-            if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
93
+            if (!is_dir($tmpdir)) $texttitle .= img_warning($langs->trans("ErrorDirNotFound", $tmpdir), 0);
94 94
             else
95 95
             {
96
-                $upload_dir=$tmpdir;
96
+                $upload_dir = $tmpdir;
97 97
             }
98 98
         }
99 99
         if ($upload_dir)
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
         }
104 104
     }
105 105
 
106
-    if (! $error)
106
+    if (!$error)
107 107
     {
108 108
         $db->commit();
109 109
         if (empty($nomessageinsetmoduleoptions)) setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
Please login to merge, or discard this patch.
Braces   +26 added lines, -13 removed lines patch added patch discarded remove patch
@@ -45,12 +45,15 @@  discard block
 block discarded – undo
45 45
 	if (! $error)
46 46
 	{
47 47
 		$db->commit();
48
-		if (empty($nomessageinupdate)) setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
49
-	}
50
-	else
48
+		if (empty($nomessageinupdate)) {
49
+			setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
50
+		}
51
+	} else
51 52
 	{
52 53
 		$db->rollback();
53
-		if (empty($nomessageinupdate)) setEventMessages($langs->trans("SetupNotSaved"), null, 'errors');
54
+		if (empty($nomessageinupdate)) {
55
+			setEventMessages($langs->trans("SetupNotSaved"), null, 'errors');
56
+		}
54 57
 	}
55 58
 }
56 59
 
@@ -64,14 +67,18 @@  discard block
 block discarded – undo
64 67
     {
65 68
         foreach($_POST as $key => $val)
66 69
         {
67
-            if (preg_match('/^param(\d*)$/', $key, $reg))    // Works for POST['param'], POST['param1'], POST['param2'], ...
70
+            if (preg_match('/^param(\d*)$/', $key, $reg)) {
71
+            	// Works for POST['param'], POST['param1'], POST['param2'], ...
68 72
             {
69 73
                 $param=GETPOST("param".$reg[1],'alpha');
74
+            }
70 75
                 $value=GETPOST("value".$reg[1],'alpha');
71 76
                 if ($param)
72 77
                 {
73 78
                     $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity);
74
-                    if (! $res > 0) $error++;
79
+                    if (! $res > 0) {
80
+                    	$error++;
81
+                    }
75 82
                 }
76 83
             }
77 84
         }
@@ -90,8 +97,9 @@  discard block
 block discarded – undo
90 97
             if (! $tmpdir) {
91 98
                 unset($listofdir[$key]); continue;
92 99
             }
93
-            if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
94
-            else
100
+            if (! is_dir($tmpdir)) {
101
+            	$texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
102
+            } else
95 103
             {
96 104
                 $upload_dir=$tmpdir;
97 105
             }
@@ -99,19 +107,24 @@  discard block
 block discarded – undo
99 107
         if ($upload_dir)
100 108
         {
101 109
             $result = dol_add_file_process($upload_dir, 0, 1, 'uploadfile', '');
102
-            if ($result <= 0) $error++;
110
+            if ($result <= 0) {
111
+            	$error++;
112
+            }
103 113
         }
104 114
     }
105 115
 
106 116
     if (! $error)
107 117
     {
108 118
         $db->commit();
109
-        if (empty($nomessageinsetmoduleoptions)) setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
110
-    }
111
-    else
119
+        if (empty($nomessageinsetmoduleoptions)) {
120
+        	setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
121
+        }
122
+    } else
112 123
     {
113 124
         $db->rollback();
114
-        if (empty($nomessageinsetmoduleoptions)) setEventMessages($langs->trans("SetupNotSaved"), null, 'errors');
125
+        if (empty($nomessageinsetmoduleoptions)) {
126
+        	setEventMessages($langs->trans("SetupNotSaved"), null, 'errors');
127
+        }
115 128
     }
116 129
 }
117 130
 
Please login to merge, or discard this patch.
htdocs/core/extrafieldsinexport.inc.php 3 patches
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -2,9 +2,9 @@  discard block
 block discarded – undo
2 2
 
3 3
 if (empty($keyforselect) || empty($keyforelement) || empty($keyforaliasextra))
4 4
 {
5
-    //print $keyforselet.' - '.$keyforelement.' - '.$keyforaliasextra;
6
-    dol_print_error('', 'include of file extrafieldsinexport.inc.php was done but var $keyforselect or $keyforelement or $keyforaliasextra was not set');
7
-    exit;
5
+	//print $keyforselet.' - '.$keyforelement.' - '.$keyforaliasextra;
6
+	dol_print_error('', 'include of file extrafieldsinexport.inc.php was done but var $keyforselect or $keyforelement or $keyforaliasextra was not set');
7
+	exit;
8 8
 }
9 9
 
10 10
 // Add extra fields
@@ -44,20 +44,20 @@  discard block
 block discarded – undo
44 44
 		}
45 45
 		if ($obj->type!='separate')
46 46
 		{
47
-		    // If not a computed field
48
-		    if (empty($obj->fieldcomputed))
49
-		    {
50
-    			$this->export_fields_array[$r][$fieldname]=$fieldlabel;
51
-    			$this->export_TypeFields_array[$r][$fieldname]=$typeFilter;
52
-    			$this->export_entities_array[$r][$fieldname]=$keyforelement;
53
-		    }
47
+			// If not a computed field
48
+			if (empty($obj->fieldcomputed))
49
+			{
50
+				$this->export_fields_array[$r][$fieldname]=$fieldlabel;
51
+				$this->export_TypeFields_array[$r][$fieldname]=$typeFilter;
52
+				$this->export_entities_array[$r][$fieldname]=$keyforelement;
53
+			}
54 54
 			// If this is a computed field
55 55
 			else
56 56
 			{
57
-			    $this->export_fields_array[$r][$fieldname]=$fieldlabel;
58
-			    $this->export_TypeFields_array[$r][$fieldname]=$typeFilter.'Compute';
59
-			    $this->export_special_array[$r][$fieldname]=$obj->fieldcomputed;
60
-			    $this->export_entities_array[$r][$fieldname]=$keyforelement;
57
+				$this->export_fields_array[$r][$fieldname]=$fieldlabel;
58
+				$this->export_TypeFields_array[$r][$fieldname]=$typeFilter.'Compute';
59
+				$this->export_special_array[$r][$fieldname]=$obj->fieldcomputed;
60
+				$this->export_entities_array[$r][$fieldname]=$keyforelement;
61 61
 			}
62 62
 		}
63 63
 	}
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -8,58 +8,58 @@
 block discarded – undo
8 8
 }
9 9
 
10 10
 // Add extra fields
11
-$sql="SELECT name, label, type, param, fieldcomputed, fielddefault FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = '".$keyforselect."' AND type != 'separate' AND entity IN (0, ".$conf->entity.')';
11
+$sql = "SELECT name, label, type, param, fieldcomputed, fielddefault FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = '".$keyforselect."' AND type != 'separate' AND entity IN (0, ".$conf->entity.')';
12 12
 //print $sql;
13
-$resql=$this->db->query($sql);
13
+$resql = $this->db->query($sql);
14 14
 if ($resql)    // This can fail when class is used on old database (during migration for example)
15 15
 {
16
-	while ($obj=$this->db->fetch_object($resql))
16
+	while ($obj = $this->db->fetch_object($resql))
17 17
 	{
18
-		$fieldname=$keyforaliasextra.'.'.$obj->name;
19
-		$fieldlabel=ucfirst($obj->label);
20
-		$typeFilter="Text";
21
-		$typefield=preg_replace('/\(.*$/', '', $obj->type);	// double(24,8) -> double
18
+		$fieldname = $keyforaliasextra.'.'.$obj->name;
19
+		$fieldlabel = ucfirst($obj->label);
20
+		$typeFilter = "Text";
21
+		$typefield = preg_replace('/\(.*$/', '', $obj->type); // double(24,8) -> double
22 22
 		switch ($typefield) {
23 23
 			case 'int':
24 24
 			case 'integer':
25 25
 			case 'double':
26 26
 			case 'price':
27
-				$typeFilter="Numeric";
27
+				$typeFilter = "Numeric";
28 28
 				break;
29 29
 			case 'date':
30 30
 			case 'datetime':
31 31
 			case 'timestamp':
32
-				$typeFilter="Date";
32
+				$typeFilter = "Date";
33 33
 				break;
34 34
 			case 'boolean':
35
-				$typeFilter="Boolean";
35
+				$typeFilter = "Boolean";
36 36
 				break;
37 37
 			case 'sellist':
38
-				$tmp='';
39
-				$tmpparam=unserialize($obj->param);	// $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
38
+				$tmp = '';
39
+				$tmpparam = unserialize($obj->param); // $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
40 40
 				if ($tmpparam['options'] && is_array($tmpparam['options'])) {
41
-					$tmpkeys=array_keys($tmpparam['options']);
42
-					$tmp=array_shift($tmpkeys);
41
+					$tmpkeys = array_keys($tmpparam['options']);
42
+					$tmp = array_shift($tmpkeys);
43 43
 				}
44
-				if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter="List:".$tmp;
44
+				if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter = "List:".$tmp;
45 45
 				break;
46 46
 		}
47
-		if ($obj->type!='separate')
47
+		if ($obj->type != 'separate')
48 48
 		{
49 49
 		    // If not a computed field
50 50
 		    if (empty($obj->fieldcomputed))
51 51
 		    {
52
-    			$this->export_fields_array[$r][$fieldname]=$fieldlabel;
53
-    			$this->export_TypeFields_array[$r][$fieldname]=$typeFilter;
54
-    			$this->export_entities_array[$r][$fieldname]=$keyforelement;
52
+    			$this->export_fields_array[$r][$fieldname] = $fieldlabel;
53
+    			$this->export_TypeFields_array[$r][$fieldname] = $typeFilter;
54
+    			$this->export_entities_array[$r][$fieldname] = $keyforelement;
55 55
 		    }
56 56
 			// If this is a computed field
57 57
 			else
58 58
 			{
59
-			    $this->export_fields_array[$r][$fieldname]=$fieldlabel;
60
-			    $this->export_TypeFields_array[$r][$fieldname]=$typeFilter.'Compute';
61
-			    $this->export_special_array[$r][$fieldname]=$obj->fieldcomputed;
62
-			    $this->export_entities_array[$r][$fieldname]=$keyforelement;
59
+			    $this->export_fields_array[$r][$fieldname] = $fieldlabel;
60
+			    $this->export_TypeFields_array[$r][$fieldname] = $typeFilter.'Compute';
61
+			    $this->export_special_array[$r][$fieldname] = $obj->fieldcomputed;
62
+			    $this->export_entities_array[$r][$fieldname] = $keyforelement;
63 63
 			}
64 64
 		}
65 65
 	}
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -11,11 +11,13 @@  discard block
 block discarded – undo
11 11
 $sql="SELECT name, label, type, param, fieldcomputed, fielddefault FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = '".$keyforselect."' AND type != 'separate' AND entity IN (0, ".$conf->entity.')';
12 12
 //print $sql;
13 13
 $resql=$this->db->query($sql);
14
-if ($resql)    // This can fail when class is used on old database (during migration for example)
14
+if ($resql) {
15
+	// This can fail when class is used on old database (during migration for example)
15 16
 {
16 17
 	while ($obj=$this->db->fetch_object($resql))
17 18
 	{
18 19
 		$fieldname=$keyforaliasextra.'.'.$obj->name;
20
+}
19 21
 		$fieldlabel=ucfirst($obj->label);
20 22
 		$typeFilter="Text";
21 23
 		$typefield=preg_replace('/\(.*$/', '', $obj->type);	// double(24,8) -> double
@@ -41,7 +43,9 @@  discard block
 block discarded – undo
41 43
 					$tmpkeys=array_keys($tmpparam['options']);
42 44
 					$tmp=array_shift($tmpkeys);
43 45
 				}
44
-				if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter="List:".$tmp;
46
+				if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) {
47
+					$typeFilter="List:".$tmp;
48
+				}
45 49
 				break;
46 50
 		}
47 51
 		if ($obj->type!='separate')
Please login to merge, or discard this patch.
htdocs/core/actions_lineupdown.inc.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -35,9 +35,9 @@  discard block
 block discarded – undo
35 35
 	// Define output language
36 36
 	$outputlangs = $langs;
37 37
 	$newlang = '';
38
-	if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09');
38
+	if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
39 39
 	if ($conf->global->MAIN_MULTILANGS && empty($newlang))	$newlang = $object->thirdparty->default_lang;
40
-	if (! empty($newlang)) {
40
+	if (!empty($newlang)) {
41 41
 		$outputlangs = new Translate("", $conf);
42 42
 		$outputlangs->setDefaultLang($newlang);
43 43
 	}
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 		$object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
47 47
 	}
48 48
 
49
-	header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '#' . GETPOST('rowid'));
49
+	header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'#'.GETPOST('rowid'));
50 50
 	exit();
51 51
 }
52 52
 
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 	// Define output language
58 58
 	$outputlangs = $langs;
59 59
 	$newlang = '';
60
-	if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09');
60
+	if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
61 61
 	if ($conf->global->MAIN_MULTILANGS && empty($newlang))	$newlang = $object->thirdparty->default_lang;
62
-	if (! empty($newlang)) {
62
+	if (!empty($newlang)) {
63 63
 		$outputlangs = new Translate("", $conf);
64 64
 		$outputlangs->setDefaultLang($newlang);
65 65
 	}
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 		$object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
68 68
 	}
69 69
 
70
-	header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '#' . GETPOST('rowid'));
70
+	header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'#'.GETPOST('rowid'));
71 71
 	exit();
72 72
 }
73 73
 
Please login to merge, or discard this patch.
Braces   +12 added lines, -4 removed lines patch added patch discarded remove patch
@@ -35,8 +35,12 @@  discard block
 block discarded – undo
35 35
 	// Define output language
36 36
 	$outputlangs = $langs;
37 37
 	$newlang = '';
38
-	if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09');
39
-	if ($conf->global->MAIN_MULTILANGS && empty($newlang))	$newlang = $object->thirdparty->default_lang;
38
+	if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) {
39
+		$newlang = GETPOST('lang_id','aZ09');
40
+	}
41
+	if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
42
+		$newlang = $object->thirdparty->default_lang;
43
+	}
40 44
 	if (! empty($newlang)) {
41 45
 		$outputlangs = new Translate("", $conf);
42 46
 		$outputlangs->setDefaultLang($newlang);
@@ -57,8 +61,12 @@  discard block
 block discarded – undo
57 61
 	// Define output language
58 62
 	$outputlangs = $langs;
59 63
 	$newlang = '';
60
-	if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09');
61
-	if ($conf->global->MAIN_MULTILANGS && empty($newlang))	$newlang = $object->thirdparty->default_lang;
64
+	if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) {
65
+		$newlang = GETPOST('lang_id','aZ09');
66
+	}
67
+	if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
68
+		$newlang = $object->thirdparty->default_lang;
69
+	}
62 70
 	if (! empty($newlang)) {
63 71
 		$outputlangs = new Translate("", $conf);
64 72
 		$outputlangs->setDefaultLang($newlang);
Please login to merge, or discard this patch.
htdocs/core/actions_changeselectedfields.inc.php 3 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -30,19 +30,19 @@
 block discarded – undo
30 30
 // Save selection
31 31
 if (GETPOST('formfilteraction') == 'listafterchangingselectedfields')
32 32
 {
33
-    $tabparam=array();
33
+	$tabparam=array();
34 34
 
35
-    $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
35
+	$varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
36 36
     
37
-    if (GETPOST("selectedfields")) $tabparam["MAIN_SELECTEDFIELDS_".$varpage]=GETPOST("selectedfields");
38
-    else $tabparam["MAIN_SELECTEDFIELDS_".$varpage]='';
37
+	if (GETPOST("selectedfields")) $tabparam["MAIN_SELECTEDFIELDS_".$varpage]=GETPOST("selectedfields");
38
+	else $tabparam["MAIN_SELECTEDFIELDS_".$varpage]='';
39 39
 
40
-    include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
40
+	include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
41 41
     
42
-    $result=dol_set_user_param($db, $conf, $user, $tabparam);
42
+	$result=dol_set_user_param($db, $conf, $user, $tabparam);
43 43
     
44
-    //$action='list';
45
-    //var_dump($tabparam);exit;
44
+	//$action='list';
45
+	//var_dump($tabparam);exit;
46 46
 }
47 47
 
48 48
 
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -30,16 +30,16 @@
 block discarded – undo
30 30
 // Save selection
31 31
 if (GETPOST('formfilteraction') == 'listafterchangingselectedfields')
32 32
 {
33
-    $tabparam=array();
33
+    $tabparam = array();
34 34
 
35
-    $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
35
+    $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
36 36
     
37
-    if (GETPOST("selectedfields")) $tabparam["MAIN_SELECTEDFIELDS_".$varpage]=GETPOST("selectedfields");
38
-    else $tabparam["MAIN_SELECTEDFIELDS_".$varpage]='';
37
+    if (GETPOST("selectedfields")) $tabparam["MAIN_SELECTEDFIELDS_".$varpage] = GETPOST("selectedfields");
38
+    else $tabparam["MAIN_SELECTEDFIELDS_".$varpage] = '';
39 39
 
40 40
     include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
41 41
     
42
-    $result=dol_set_user_param($db, $conf, $user, $tabparam);
42
+    $result = dol_set_user_param($db, $conf, $user, $tabparam);
43 43
     
44 44
     //$action='list';
45 45
     //var_dump($tabparam);exit;
Please login to merge, or discard this patch.
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -34,8 +34,11 @@
 block discarded – undo
34 34
 
35 35
     $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
36 36
     
37
-    if (GETPOST("selectedfields")) $tabparam["MAIN_SELECTEDFIELDS_".$varpage]=GETPOST("selectedfields");
38
-    else $tabparam["MAIN_SELECTEDFIELDS_".$varpage]='';
37
+    if (GETPOST("selectedfields")) {
38
+    	$tabparam["MAIN_SELECTEDFIELDS_".$varpage]=GETPOST("selectedfields");
39
+    } else {
40
+    	$tabparam["MAIN_SELECTEDFIELDS_".$varpage]='';
41
+    }
39 42
 
40 43
     include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
41 44
     
Please login to merge, or discard this patch.