Test Failed
Push — master ( 2c8b6d...9d1fea )
by Alxarafe
45:51
created
dolibarr/dev/initdemo/sftpget_and_loaddump.php 3 patches
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -25,8 +25,8 @@  discard block
 block discarded – undo
25 25
 
26 26
 // Test if batch mode
27 27
 if (substr($sapi_type, 0, 3) == 'cgi') {
28
-	echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
29
-	exit;
28
+    echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
29
+    exit;
30 30
 }
31 31
 
32 32
 // Global variables
@@ -60,17 +60,17 @@  discard block
 block discarded – undo
60 60
 $server='';
61 61
 if (preg_match('/^(.*)@(.*):(.*)$/',$sourceserver,$reg))
62 62
 {
63
-	$login=$reg[1];
64
-	$server=$reg[2];
65
-	$sourcefile=$reg[3];
66
-	$targetfile=basename($sourcefile);
63
+    $login=$reg[1];
64
+    $server=$reg[2];
65
+    $sourcefile=$reg[3];
66
+    $targetfile=basename($sourcefile);
67 67
 }
68 68
 if (empty($sourceserver) || empty($server) || empty($login) || empty($sourcefile) || empty($password) || empty($database) || empty($loginbase) || empty($passwordbase))
69 69
 {
70
-	print "Usage: $script_file login@server:/src/file.(sql|gz|bz2) passssh databaseserver databasename loginbase passbase\n";
71
-	print "Return code: 0 if success, <>0 if error\n";
72
-	print "Warning, this script may take a long time.\n";
73
-	exit(-1);
70
+    print "Usage: $script_file login@server:/src/file.(sql|gz|bz2) passssh databaseserver databasename loginbase passbase\n";
71
+    print "Return code: 0 if success, <>0 if error\n";
72
+    print "Warning, this script may take a long time.\n";
73
+    exit(-1);
74 74
 }
75 75
 
76 76
 
@@ -84,21 +84,21 @@  discard block
 block discarded – undo
84 84
 
85 85
 // SFTP connect
86 86
 if (! function_exists("ssh2_connect")) {
87
-	dol_print_error('','ssh2_connect function does not exists'); exit(1);
87
+    dol_print_error('','ssh2_connect function does not exists'); exit(1);
88 88
 }
89 89
 
90 90
 $connection = ssh2_connect($server, 22);
91 91
 if ($connection)
92 92
 {
93
-	if (! @ssh2_auth_password($connection, $login, $password))
94
-	{
95
-		dol_syslog("Could not authenticate with username ".$login." . and password ".preg_replace('/./', '*', $password),LOG_ERR);
96
-		exit(-5);
97
-	}
98
-	else
99
-	{
100
-		//$stream = ssh2_exec($connection, '/usr/bin/php -i');
101
-		/*
93
+    if (! @ssh2_auth_password($connection, $login, $password))
94
+    {
95
+        dol_syslog("Could not authenticate with username ".$login." . and password ".preg_replace('/./', '*', $password),LOG_ERR);
96
+        exit(-5);
97
+    }
98
+    else
99
+    {
100
+        //$stream = ssh2_exec($connection, '/usr/bin/php -i');
101
+        /*
102 102
 		print "Generate dump ".$filesys1.'.bz2'."\n";
103 103
 			$stream = ssh2_exec($connection, "mysqldump -u debian-sys-maint -p4k9Blxl2snq4FHXY -h 127.0.0.1 --single-transaction -K --tables -c -e --hex-blob --default-character-set=utf8 saasplex | bzip2 -1 > ".$filesys1.'.bz2');
104 104
 			stream_set_blocking($stream, true);
@@ -106,35 +106,35 @@  discard block
 block discarded – undo
106 106
 			$output = stream_get_contents($stream);
107 107
 		*/
108 108
 
109
-		$sftp = ssh2_sftp($connection);
110
-
111
-		print 'Get file '.$sourcefile.' into '.$targetdir.$targetfile."\n";
112
-		ssh2_scp_recv($connection, $sourcefile, $targetdir.$targetfile);
113
-
114
-		$fullcommand="cat ".$targetdir.$targetfile." | mysql -h".$databaseserver." -u".$loginbase." -p".$passwordbase." -D ".$database;
115
-		if (preg_match('/\.bz2$/',$targetfile))
116
-		{
117
-			$fullcommand="bzip2 -c -d ".$targetdir.$targetfile." | mysql -h".$databaseserver." -u".$loginbase." -p".$passwordbase." -D ".$database;
118
-		}
119
-		if (preg_match('/\.gz$/',$targetfile))
120
-		{
121
-			$fullcommand="gzip -d ".$targetdir.$targetfile." | mysql -h".$databaseserver." -u".$loginbase." -p".$passwordbase." -D ".$database;
122
-		}
123
-		print "Load dump with ".$fullcommand."\n";
124
-		$output=array();
125
-		$return_var=0;
126
-		print strftime("%Y%m%d-%H%M%S").' '.$fullcommand."\n";
127
-		exec($fullcommand, $output, $return_var);
128
-		foreach($output as $line) print $line."\n";
129
-
130
-		//ssh2_sftp_unlink($sftp, $fileinstalllock);
131
-		//print $output;
132
-	}
109
+        $sftp = ssh2_sftp($connection);
110
+
111
+        print 'Get file '.$sourcefile.' into '.$targetdir.$targetfile."\n";
112
+        ssh2_scp_recv($connection, $sourcefile, $targetdir.$targetfile);
113
+
114
+        $fullcommand="cat ".$targetdir.$targetfile." | mysql -h".$databaseserver." -u".$loginbase." -p".$passwordbase." -D ".$database;
115
+        if (preg_match('/\.bz2$/',$targetfile))
116
+        {
117
+            $fullcommand="bzip2 -c -d ".$targetdir.$targetfile." | mysql -h".$databaseserver." -u".$loginbase." -p".$passwordbase." -D ".$database;
118
+        }
119
+        if (preg_match('/\.gz$/',$targetfile))
120
+        {
121
+            $fullcommand="gzip -d ".$targetdir.$targetfile." | mysql -h".$databaseserver." -u".$loginbase." -p".$passwordbase." -D ".$database;
122
+        }
123
+        print "Load dump with ".$fullcommand."\n";
124
+        $output=array();
125
+        $return_var=0;
126
+        print strftime("%Y%m%d-%H%M%S").' '.$fullcommand."\n";
127
+        exec($fullcommand, $output, $return_var);
128
+        foreach($output as $line) print $line."\n";
129
+
130
+        //ssh2_sftp_unlink($sftp, $fileinstalllock);
131
+        //print $output;
132
+    }
133 133
 }
134 134
 else
135 135
 {
136
-	print 'Failed to connect to ssh2 to '.$server;
137
-	exit(-6);
136
+    print 'Failed to connect to ssh2 to '.$server;
137
+    exit(-6);
138 138
 }
139 139
 
140 140
 
Please login to merge, or discard this patch.
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 
22 22
 $sapi_type = php_sapi_name();
23 23
 $script_file = basename(__FILE__);
24
-$path=dirname(__FILE__).'/';
24
+$path = dirname(__FILE__).'/';
25 25
 
26 26
 // Test if batch mode
27 27
 if (substr($sapi_type, 0, 3) == 'cgi') {
@@ -30,25 +30,25 @@  discard block
 block discarded – undo
30 30
 }
31 31
 
32 32
 // Global variables
33
-$error=0;
33
+$error = 0;
34 34
 
35
-$sourceserver=isset($argv[1])?$argv[1]:'';		// user@server:/src/file
36
-$password=isset($argv[2])?$argv[2]:'';
37
-$dataserver=isset($argv[3])?$argv[3]:'';
38
-$database=isset($argv[4])?$argv[4]:'';
39
-$loginbase=isset($argv[5])?$argv[5]:'';
40
-$passwordbase=isset($argv[6])?$argv[6]:'';
35
+$sourceserver = isset($argv[1]) ? $argv[1] : ''; // user@server:/src/file
36
+$password = isset($argv[2]) ? $argv[2] : '';
37
+$dataserver = isset($argv[3]) ? $argv[3] : '';
38
+$database = isset($argv[4]) ? $argv[4] : '';
39
+$loginbase = isset($argv[5]) ? $argv[5] : '';
40
+$passwordbase = isset($argv[6]) ? $argv[6] : '';
41 41
 
42 42
 // Include Dolibarr environment
43
-$res=0;
44
-if (! $res && file_exists($path."../../master.inc.php")) $res=@include $path."../../master.inc.php";
45
-if (! $res && file_exists($path."../../htdocs/master.inc.php")) $res=@include $path."../../htdocs/master.inc.php";
46
-if (! $res && file_exists("../master.inc.php")) $res=@include "../master.inc.php";
47
-if (! $res && file_exists("../../master.inc.php")) $res=@include "../../master.inc.php";
48
-if (! $res && file_exists("../../../master.inc.php")) $res=@include "../../../master.inc.php";
49
-if (! $res && preg_match('/\/nltechno([^\/]*)\//',$_SERVER["PHP_SELF"],$reg)) $res=@include $path."../../../dolibarr".$reg[1]."/htdocs/master.inc.php"; // Used on dev env only
50
-if (! $res && preg_match('/\/nltechno([^\/]*)\//',$_SERVER["PHP_SELF"],$reg)) $res=@include "../../../dolibarr".$reg[1]."/htdocs/master.inc.php"; // Used on dev env only
51
-if (! $res) die ("Failed to include master.inc.php file\n");
43
+$res = 0;
44
+if (!$res && file_exists($path."../../master.inc.php")) $res = @include $path."../../master.inc.php";
45
+if (!$res && file_exists($path."../../htdocs/master.inc.php")) $res = @include $path."../../htdocs/master.inc.php";
46
+if (!$res && file_exists("../master.inc.php")) $res = @include "../master.inc.php";
47
+if (!$res && file_exists("../../master.inc.php")) $res = @include "../../master.inc.php";
48
+if (!$res && file_exists("../../../master.inc.php")) $res = @include "../../../master.inc.php";
49
+if (!$res && preg_match('/\/nltechno([^\/]*)\//', $_SERVER["PHP_SELF"], $reg)) $res = @include $path."../../../dolibarr".$reg[1]."/htdocs/master.inc.php"; // Used on dev env only
50
+if (!$res && preg_match('/\/nltechno([^\/]*)\//', $_SERVER["PHP_SELF"], $reg)) $res = @include "../../../dolibarr".$reg[1]."/htdocs/master.inc.php"; // Used on dev env only
51
+if (!$res) die ("Failed to include master.inc.php file\n");
52 52
 include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
53 53
 
54 54
 
@@ -56,14 +56,14 @@  discard block
 block discarded – undo
56 56
  *	Main
57 57
  */
58 58
 
59
-$login='';
60
-$server='';
61
-if (preg_match('/^(.*)@(.*):(.*)$/',$sourceserver,$reg))
59
+$login = '';
60
+$server = '';
61
+if (preg_match('/^(.*)@(.*):(.*)$/', $sourceserver, $reg))
62 62
 {
63
-	$login=$reg[1];
64
-	$server=$reg[2];
65
-	$sourcefile=$reg[3];
66
-	$targetfile=basename($sourcefile);
63
+	$login = $reg[1];
64
+	$server = $reg[2];
65
+	$sourcefile = $reg[3];
66
+	$targetfile = basename($sourcefile);
67 67
 }
68 68
 if (empty($sourceserver) || empty($server) || empty($login) || empty($sourcefile) || empty($password) || empty($database) || empty($loginbase) || empty($passwordbase))
69 69
 {
@@ -74,25 +74,25 @@  discard block
 block discarded – undo
74 74
 }
75 75
 
76 76
 
77
-$targetdir='/tmp';
77
+$targetdir = '/tmp';
78 78
 print "Get dump file from server ".$server.", path ".$sourcefile.", connect with login ".$login." loaded into localhost\n";
79 79
 
80
-$sftpconnectstring=$sourceserver;
80
+$sftpconnectstring = $sourceserver;
81 81
 print 'SFTP connect string : '.$sftpconnectstring."\n";
82 82
 //print 'SFTP password '.$password."\n";
83 83
 
84 84
 
85 85
 // SFTP connect
86
-if (! function_exists("ssh2_connect")) {
87
-	dol_print_error('','ssh2_connect function does not exists'); exit(1);
86
+if (!function_exists("ssh2_connect")) {
87
+	dol_print_error('', 'ssh2_connect function does not exists'); exit(1);
88 88
 }
89 89
 
90 90
 $connection = ssh2_connect($server, 22);
91 91
 if ($connection)
92 92
 {
93
-	if (! @ssh2_auth_password($connection, $login, $password))
93
+	if (!@ssh2_auth_password($connection, $login, $password))
94 94
 	{
95
-		dol_syslog("Could not authenticate with username ".$login." . and password ".preg_replace('/./', '*', $password),LOG_ERR);
95
+		dol_syslog("Could not authenticate with username ".$login." . and password ".preg_replace('/./', '*', $password), LOG_ERR);
96 96
 		exit(-5);
97 97
 	}
98 98
 	else
@@ -111,21 +111,21 @@  discard block
 block discarded – undo
111 111
 		print 'Get file '.$sourcefile.' into '.$targetdir.$targetfile."\n";
112 112
 		ssh2_scp_recv($connection, $sourcefile, $targetdir.$targetfile);
113 113
 
114
-		$fullcommand="cat ".$targetdir.$targetfile." | mysql -h".$databaseserver." -u".$loginbase." -p".$passwordbase." -D ".$database;
115
-		if (preg_match('/\.bz2$/',$targetfile))
114
+		$fullcommand = "cat ".$targetdir.$targetfile." | mysql -h".$databaseserver." -u".$loginbase." -p".$passwordbase." -D ".$database;
115
+		if (preg_match('/\.bz2$/', $targetfile))
116 116
 		{
117
-			$fullcommand="bzip2 -c -d ".$targetdir.$targetfile." | mysql -h".$databaseserver." -u".$loginbase." -p".$passwordbase." -D ".$database;
117
+			$fullcommand = "bzip2 -c -d ".$targetdir.$targetfile." | mysql -h".$databaseserver." -u".$loginbase." -p".$passwordbase." -D ".$database;
118 118
 		}
119
-		if (preg_match('/\.gz$/',$targetfile))
119
+		if (preg_match('/\.gz$/', $targetfile))
120 120
 		{
121
-			$fullcommand="gzip -d ".$targetdir.$targetfile." | mysql -h".$databaseserver." -u".$loginbase." -p".$passwordbase." -D ".$database;
121
+			$fullcommand = "gzip -d ".$targetdir.$targetfile." | mysql -h".$databaseserver." -u".$loginbase." -p".$passwordbase." -D ".$database;
122 122
 		}
123 123
 		print "Load dump with ".$fullcommand."\n";
124
-		$output=array();
125
-		$return_var=0;
124
+		$output = array();
125
+		$return_var = 0;
126 126
 		print strftime("%Y%m%d-%H%M%S").' '.$fullcommand."\n";
127 127
 		exec($fullcommand, $output, $return_var);
128
-		foreach($output as $line) print $line."\n";
128
+		foreach ($output as $line) print $line."\n";
129 129
 
130 130
 		//ssh2_sftp_unlink($sftp, $fileinstalllock);
131 131
 		//print $output;
Please login to merge, or discard this patch.
Braces   +31 added lines, -13 removed lines patch added patch discarded remove patch
@@ -41,14 +41,32 @@  discard block
 block discarded – undo
41 41
 
42 42
 // Include Dolibarr environment
43 43
 $res=0;
44
-if (! $res && file_exists($path."../../master.inc.php")) $res=@include $path."../../master.inc.php";
45
-if (! $res && file_exists($path."../../htdocs/master.inc.php")) $res=@include $path."../../htdocs/master.inc.php";
46
-if (! $res && file_exists("../master.inc.php")) $res=@include "../master.inc.php";
47
-if (! $res && file_exists("../../master.inc.php")) $res=@include "../../master.inc.php";
48
-if (! $res && file_exists("../../../master.inc.php")) $res=@include "../../../master.inc.php";
49
-if (! $res && preg_match('/\/nltechno([^\/]*)\//',$_SERVER["PHP_SELF"],$reg)) $res=@include $path."../../../dolibarr".$reg[1]."/htdocs/master.inc.php"; // Used on dev env only
50
-if (! $res && preg_match('/\/nltechno([^\/]*)\//',$_SERVER["PHP_SELF"],$reg)) $res=@include "../../../dolibarr".$reg[1]."/htdocs/master.inc.php"; // Used on dev env only
51
-if (! $res) die ("Failed to include master.inc.php file\n");
44
+if (! $res && file_exists($path."../../master.inc.php")) {
45
+    $res=@include $path."../../master.inc.php";
46
+}
47
+if (! $res && file_exists($path."../../htdocs/master.inc.php")) {
48
+    $res=@include $path."../../htdocs/master.inc.php";
49
+}
50
+if (! $res && file_exists("../master.inc.php")) {
51
+    $res=@include "../master.inc.php";
52
+}
53
+if (! $res && file_exists("../../master.inc.php")) {
54
+    $res=@include "../../master.inc.php";
55
+}
56
+if (! $res && file_exists("../../../master.inc.php")) {
57
+    $res=@include "../../../master.inc.php";
58
+}
59
+if (! $res && preg_match('/\/nltechno([^\/]*)\//',$_SERVER["PHP_SELF"],$reg)) {
60
+    $res=@include $path."../../../dolibarr".$reg[1]."/htdocs/master.inc.php";
61
+}
62
+// Used on dev env only
63
+if (! $res && preg_match('/\/nltechno([^\/]*)\//',$_SERVER["PHP_SELF"],$reg)) {
64
+    $res=@include "../../../dolibarr".$reg[1]."/htdocs/master.inc.php";
65
+}
66
+// Used on dev env only
67
+if (! $res) {
68
+    die ("Failed to include master.inc.php file\n");
69
+}
52 70
 include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
53 71
 
54 72
 
@@ -94,8 +112,7 @@  discard block
 block discarded – undo
94 112
 	{
95 113
 		dol_syslog("Could not authenticate with username ".$login." . and password ".preg_replace('/./', '*', $password),LOG_ERR);
96 114
 		exit(-5);
97
-	}
98
-	else
115
+	} else
99 116
 	{
100 117
 		//$stream = ssh2_exec($connection, '/usr/bin/php -i');
101 118
 		/*
@@ -125,13 +142,14 @@  discard block
 block discarded – undo
125 142
 		$return_var=0;
126 143
 		print strftime("%Y%m%d-%H%M%S").' '.$fullcommand."\n";
127 144
 		exec($fullcommand, $output, $return_var);
128
-		foreach($output as $line) print $line."\n";
145
+		foreach($output as $line) {
146
+		    print $line."\n";
147
+		}
129 148
 
130 149
 		//ssh2_sftp_unlink($sftp, $fileinstalllock);
131 150
 		//print $output;
132 151
 	}
133
-}
134
-else
152
+} else
135 153
 {
136 154
 	print 'Failed to connect to ssh2 to '.$server;
137 155
 	exit(-6);
Please login to merge, or discard this patch.
dolibarr/dev/initdemo/updatedemo.php 3 patches
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -25,8 +25,8 @@  discard block
 block discarded – undo
25 25
 
26 26
 // Test if batch mode
27 27
 if (substr($sapi_type, 0, 3) == 'cgi') {
28
-	echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
29
-	exit;
28
+    echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
29
+    exit;
30 30
 }
31 31
 
32 32
 // Global variables
@@ -53,9 +53,9 @@  discard block
 block discarded – undo
53 53
 
54 54
 if (empty($confirm))
55 55
 {
56
-	print "Usage: $script_file confirm\n";
57
-	print "Return code: 0 if success, <>0 if error\n";
58
-	exit(-1);
56
+    print "Usage: $script_file confirm\n";
57
+    print "Return code: 0 if success, <>0 if error\n";
58
+    exit(-1);
59 59
 }
60 60
 
61 61
 
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 
22 22
 $sapi_type = php_sapi_name();
23 23
 $script_file = basename(__FILE__);
24
-$path=dirname(__FILE__).'/';
24
+$path = dirname(__FILE__).'/';
25 25
 
26 26
 // Test if batch mode
27 27
 if (substr($sapi_type, 0, 3) == 'cgi') {
@@ -30,20 +30,20 @@  discard block
 block discarded – undo
30 30
 }
31 31
 
32 32
 // Global variables
33
-$error=0;
33
+$error = 0;
34 34
 
35
-$confirm=isset($argv[1])?$argv[1]:'';
35
+$confirm = isset($argv[1]) ? $argv[1] : '';
36 36
 
37 37
 // Include Dolibarr environment
38
-$res=0;
39
-if (! $res && file_exists($path."../../master.inc.php")) $res=@include $path."../../master.inc.php";
40
-if (! $res && file_exists($path."../../htdocs/master.inc.php")) $res=@include $path."../../htdocs/master.inc.php";
41
-if (! $res && file_exists("../master.inc.php")) $res=@include "../master.inc.php";
42
-if (! $res && file_exists("../../master.inc.php")) $res=@include "../../master.inc.php";
43
-if (! $res && file_exists("../../../master.inc.php")) $res=@include "../../../master.inc.php";
44
-if (! $res && preg_match('/\/nltechno([^\/]*)\//',$_SERVER["PHP_SELF"],$reg)) $res=@include $path."../../../dolibarr".$reg[1]."/htdocs/master.inc.php"; // Used on dev env only
45
-if (! $res && preg_match('/\/nltechno([^\/]*)\//',$_SERVER["PHP_SELF"],$reg)) $res=@include "../../../dolibarr".$reg[1]."/htdocs/master.inc.php"; // Used on dev env only
46
-if (! $res) die ("Failed to include master.inc.php file\n");
38
+$res = 0;
39
+if (!$res && file_exists($path."../../master.inc.php")) $res = @include $path."../../master.inc.php";
40
+if (!$res && file_exists($path."../../htdocs/master.inc.php")) $res = @include $path."../../htdocs/master.inc.php";
41
+if (!$res && file_exists("../master.inc.php")) $res = @include "../master.inc.php";
42
+if (!$res && file_exists("../../master.inc.php")) $res = @include "../../master.inc.php";
43
+if (!$res && file_exists("../../../master.inc.php")) $res = @include "../../../master.inc.php";
44
+if (!$res && preg_match('/\/nltechno([^\/]*)\//', $_SERVER["PHP_SELF"], $reg)) $res = @include $path."../../../dolibarr".$reg[1]."/htdocs/master.inc.php"; // Used on dev env only
45
+if (!$res && preg_match('/\/nltechno([^\/]*)\//', $_SERVER["PHP_SELF"], $reg)) $res = @include "../../../dolibarr".$reg[1]."/htdocs/master.inc.php"; // Used on dev env only
46
+if (!$res) die ("Failed to include master.inc.php file\n");
47 47
 include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
48 48
 
49 49
 
@@ -59,10 +59,10 @@  discard block
 block discarded – undo
59 59
 }
60 60
 
61 61
 
62
-$tmp=dol_getdate(dol_now());
62
+$tmp = dol_getdate(dol_now());
63 63
 
64 64
 
65
-$tables=array(
65
+$tables = array(
66 66
     'propal'=>array(0=>'datep', 1=>'fin_validite', 2=>'date_valid', 3=>'date_cloture'),
67 67
     'commande'=>array(0=>'date_commande', 1=>'date_valid', 2=>'date_cloture'),
68 68
     'facture'=>array(0=>'datef', 1=>'date_valid', 2=>'date_lim_reglement'),
@@ -72,44 +72,44 @@  discard block
 block discarded – undo
72 72
     'supplier_proposal'=>array(0=>'datec', 1=>'date_valid', 2=>'date_cloture')
73 73
 );
74 74
 
75
-$year=2010;
76
-$currentyear=$tmp['year'];
75
+$year = 2010;
76
+$currentyear = $tmp['year'];
77 77
 while ($year <= $currentyear)
78 78
 {
79 79
     //$year=2021;
80
-    $delta=($currentyear - $year);
80
+    $delta = ($currentyear - $year);
81 81
     //$delta=-1;
82 82
 
83 83
     if ($delta)
84 84
     {
85
-        foreach($tables as $tablekey => $tableval)
85
+        foreach ($tables as $tablekey => $tableval)
86 86
         {
87 87
             print "\nCorrect ".$tablekey." for year ".$year." and move them to current year ".$currentyear." ";
88
-            $sql="select rowid from ".MAIN_DB_PREFIX.$tablekey." where ".$tableval[0]." between '".$year."-01-01' and '".$year."-12-31' and ".$tableval[0]." < DATE_ADD(NOW(), INTERVAL -1 YEAR)";
88
+            $sql = "select rowid from ".MAIN_DB_PREFIX.$tablekey." where ".$tableval[0]." between '".$year."-01-01' and '".$year."-12-31' and ".$tableval[0]." < DATE_ADD(NOW(), INTERVAL -1 YEAR)";
89 89
             //$sql="select rowid from ".MAIN_DB_PREFIX.$tablekey." where ".$tableval[0]." between '".$year."-01-01' and '".$year."-12-31' and ".$tableval[0]." > NOW()";
90 90
             $resql = $db->query($sql);
91 91
             if ($resql)
92 92
             {
93 93
                 $num = $db->num_rows($resql);
94
-                $i=0;
94
+                $i = 0;
95 95
                 while ($i < $num)
96 96
                 {
97
-                    $obj=$db->fetch_object($resql);
97
+                    $obj = $db->fetch_object($resql);
98 98
                     if ($obj)
99 99
                     {
100 100
                         print ".";
101
-                        $sql2="UPDATE ".MAIN_DB_PREFIX.$tablekey." set ";
102
-                        $j=0;
103
-                        foreach($tableval as $field)
101
+                        $sql2 = "UPDATE ".MAIN_DB_PREFIX.$tablekey." set ";
102
+                        $j = 0;
103
+                        foreach ($tableval as $field)
104 104
                         {
105
-                            if ($j) $sql2.=", ";
106
-                            $sql2.= $field." = DATE_ADD(".$field.", INTERVAL ".$delta." YEAR)";
105
+                            if ($j) $sql2 .= ", ";
106
+                            $sql2 .= $field." = DATE_ADD(".$field.", INTERVAL ".$delta." YEAR)";
107 107
                             $j++;
108 108
                         }
109
-                        $sql2.=" WHERE rowid = ".$obj->rowid;
109
+                        $sql2 .= " WHERE rowid = ".$obj->rowid;
110 110
                         //print $sql2."\n";
111 111
                         $resql2 = $db->query($sql2);
112
-                        if (! $resql2) dol_print_error($db);
112
+                        if (!$resql2) dol_print_error($db);
113 113
                     }
114 114
                     $i++;
115 115
                 }
Please login to merge, or discard this patch.
Braces   +34 added lines, -11 removed lines patch added patch discarded remove patch
@@ -36,14 +36,32 @@  discard block
 block discarded – undo
36 36
 
37 37
 // Include Dolibarr environment
38 38
 $res=0;
39
-if (! $res && file_exists($path."../../master.inc.php")) $res=@include $path."../../master.inc.php";
40
-if (! $res && file_exists($path."../../htdocs/master.inc.php")) $res=@include $path."../../htdocs/master.inc.php";
41
-if (! $res && file_exists("../master.inc.php")) $res=@include "../master.inc.php";
42
-if (! $res && file_exists("../../master.inc.php")) $res=@include "../../master.inc.php";
43
-if (! $res && file_exists("../../../master.inc.php")) $res=@include "../../../master.inc.php";
44
-if (! $res && preg_match('/\/nltechno([^\/]*)\//',$_SERVER["PHP_SELF"],$reg)) $res=@include $path."../../../dolibarr".$reg[1]."/htdocs/master.inc.php"; // Used on dev env only
45
-if (! $res && preg_match('/\/nltechno([^\/]*)\//',$_SERVER["PHP_SELF"],$reg)) $res=@include "../../../dolibarr".$reg[1]."/htdocs/master.inc.php"; // Used on dev env only
46
-if (! $res) die ("Failed to include master.inc.php file\n");
39
+if (! $res && file_exists($path."../../master.inc.php")) {
40
+    $res=@include $path."../../master.inc.php";
41
+}
42
+if (! $res && file_exists($path."../../htdocs/master.inc.php")) {
43
+    $res=@include $path."../../htdocs/master.inc.php";
44
+}
45
+if (! $res && file_exists("../master.inc.php")) {
46
+    $res=@include "../master.inc.php";
47
+}
48
+if (! $res && file_exists("../../master.inc.php")) {
49
+    $res=@include "../../master.inc.php";
50
+}
51
+if (! $res && file_exists("../../../master.inc.php")) {
52
+    $res=@include "../../../master.inc.php";
53
+}
54
+if (! $res && preg_match('/\/nltechno([^\/]*)\//',$_SERVER["PHP_SELF"],$reg)) {
55
+    $res=@include $path."../../../dolibarr".$reg[1]."/htdocs/master.inc.php";
56
+}
57
+// Used on dev env only
58
+if (! $res && preg_match('/\/nltechno([^\/]*)\//',$_SERVER["PHP_SELF"],$reg)) {
59
+    $res=@include "../../../dolibarr".$reg[1]."/htdocs/master.inc.php";
60
+}
61
+// Used on dev env only
62
+if (! $res) {
63
+    die ("Failed to include master.inc.php file\n");
64
+}
47 65
 include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
48 66
 
49 67
 
@@ -102,19 +120,24 @@  discard block
 block discarded – undo
102 120
                         $j=0;
103 121
                         foreach($tableval as $field)
104 122
                         {
105
-                            if ($j) $sql2.=", ";
123
+                            if ($j) {
124
+                                $sql2.=", ";
125
+                            }
106 126
                             $sql2.= $field." = DATE_ADD(".$field.", INTERVAL ".$delta." YEAR)";
107 127
                             $j++;
108 128
                         }
109 129
                         $sql2.=" WHERE rowid = ".$obj->rowid;
110 130
                         //print $sql2."\n";
111 131
                         $resql2 = $db->query($sql2);
112
-                        if (! $resql2) dol_print_error($db);
132
+                        if (! $resql2) {
133
+                            dol_print_error($db);
134
+                        }
113 135
                     }
114 136
                     $i++;
115 137
                 }
138
+            } else {
139
+                dol_print_error($db);
116 140
             }
117
-            else dol_print_error($db);
118 141
         }
119 142
     }
120 143
 
Please login to merge, or discard this patch.
dolibarr/dev/initdata/generate-order.php 3 patches
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -113,13 +113,13 @@  discard block
 block discarded – undo
113 113
 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe where client in (1, 3)";
114 114
 $resql=$db->query($sql);
115 115
 if ($resql) {
116
-	$num_thirdparties = $db->num_rows($resql);
117
-	$i = 0;
118
-	while ($i < $num_thirdparties) {
119
-		$i++;
120
-	    $row = $db->fetch_row($resql);
121
-		$societesid[$i] = $row[0];
122
-	}
116
+    $num_thirdparties = $db->num_rows($resql);
117
+    $i = 0;
118
+    while ($i < $num_thirdparties) {
119
+        $i++;
120
+        $row = $db->fetch_row($resql);
121
+        $societesid[$i] = $row[0];
122
+    }
123 123
 }
124 124
 else { print "err"; }
125 125
 
@@ -127,13 +127,13 @@  discard block
 block discarded – undo
127 127
 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."commande";
128 128
 $resql=$db->query($sql);
129 129
 if ($resql) {
130
-	$num = $db->num_rows($resql);
131
-	$i = 0;
132
-	while ($i < $num) {
133
-		$i++;
134
-	    $row = $db->fetch_row($resql);
135
-		$commandesid[$i] = $row[0];
136
-	}
130
+    $num = $db->num_rows($resql);
131
+    $i = 0;
132
+    while ($i < $num) {
133
+        $i++;
134
+        $row = $db->fetch_row($resql);
135
+        $commandesid[$i] = $row[0];
136
+    }
137 137
 }
138 138
 else { print "err"; }
139 139
 
@@ -142,14 +142,14 @@  discard block
 block discarded – undo
142 142
 $resql = $db->query($sql);
143 143
 if ($resql)
144 144
 {
145
-  $num_prods = $db->num_rows($resql);
146
-  $i = 0;
147
-  while ($i < $num_prods)
145
+    $num_prods = $db->num_rows($resql);
146
+    $i = 0;
147
+    while ($i < $num_prods)
148 148
     {
149
-      $i++;
149
+        $i++;
150 150
 
151
-      $row = $db->fetch_row($resql);
152
-      $prodids[$i] = $row[0];
151
+        $row = $db->fetch_row($resql);
152
+        $prodids[$i] = $row[0];
153 153
     }
154 154
 }
155 155
 
@@ -183,8 +183,8 @@  discard block
 block discarded – undo
183 183
     $db->begin();
184 184
 
185 185
     $result=$object->create($fuser);
186
-	if ($result >= 0)
187
-	{
186
+    if ($result >= 0)
187
+    {
188 188
         $nbp = mt_rand(2, 5);
189 189
         $xnbp = 0;
190 190
         while ($xnbp < $nbp)
@@ -200,24 +200,24 @@  discard block
 block discarded – undo
200 200
             $xnbp++;
201 201
         }
202 202
 
203
-	    $result=$object->valid($fuser);
204
-		if ($result > 0)
205
-		{
203
+        $result=$object->valid($fuser);
204
+        if ($result > 0)
205
+        {
206 206
             $db->commit();
207 207
             print " OK with ref ".$object->ref."\n";
208
-		}
209
-		else
210
-		{
208
+        }
209
+        else
210
+        {
211 211
             print " KO\n";
212
-		    $db->rollback();
213
-		    dol_print_error($db,$object->error);
214
-		}
215
-	}
216
-	else
217
-	{
212
+            $db->rollback();
213
+            dol_print_error($db,$object->error);
214
+        }
215
+    }
216
+    else
217
+    {
218 218
         print " KO\n";
219
-	    $db->rollback();
220
-	    dol_print_error($db,$object->error);
221
-	}
219
+        $db->rollback();
220
+        dol_print_error($db,$object->error);
221
+    }
222 222
 }
223 223
 
Please login to merge, or discard this patch.
Spacing   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 
34 34
 // Recupere root dolibarr
35 35
 //$path=preg_replace('/generate-commande.php/i','',$_SERVER["PHP_SELF"]);
36
-require __DIR__. '/../../htdocs/master.inc.php';
36
+require __DIR__.'/../../htdocs/master.inc.php';
37 37
 include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
38 38
 include_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
39 39
 include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
@@ -49,59 +49,59 @@  discard block
 block discarded – undo
49 49
 
50 50
 define(GEN_NUMBER_COMMANDE, 10);
51 51
 $year = 2016;
52
-$dates = array (mktime(12,0,0,1,3,$year),
53
-    mktime(12,0,0,1,9,$year),
54
-    mktime(12,0,0,2,13,$year),
55
-    mktime(12,0,0,2,23,$year),
56
-    mktime(12,0,0,3,30,$year),
57
-    mktime(12,0,0,4,3,$year),
58
-    mktime(12,0,0,4,3,$year),
59
-    mktime(12,0,0,5,9,$year),
60
-    mktime(12,0,0,5,1,$year),
61
-    mktime(12,0,0,5,13,$year),
62
-    mktime(12,0,0,5,19,$year),
63
-    mktime(12,0,0,5,23,$year),
64
-    mktime(12,0,0,6,3,$year),
65
-    mktime(12,0,0,6,19,$year),
66
-    mktime(12,0,0,6,24,$year),
67
-    mktime(12,0,0,7,3,$year),
68
-    mktime(12,0,0,7,9,$year),
69
-    mktime(12,0,0,7,23,$year),
70
-    mktime(12,0,0,7,30,$year),
71
-    mktime(12,0,0,8,9,$year),
72
-    mktime(12,0,0,9,23,$year),
73
-    mktime(12,0,0,10,3,$year),
74
-    mktime(12,0,0,11,12,$year),
75
-    mktime(12,0,0,11,13,$year),
76
-    mktime(12,0,0,1,3,($year - 1)),
77
-    mktime(12,0,0,1,9,($year - 1)),
78
-    mktime(12,0,0,2,13,($year - 1)),
79
-    mktime(12,0,0,2,23,($year - 1)),
80
-    mktime(12,0,0,3,30,($year - 1)),
81
-    mktime(12,0,0,4,3,($year - 1)),
82
-    mktime(12,0,0,4,3,($year - 1)),
83
-    mktime(12,0,0,5,9,($year - 1)),
84
-    mktime(12,0,0,5,1,($year - 1)),
85
-    mktime(12,0,0,5,13,($year - 1)),
86
-    mktime(12,0,0,5,19,($year - 1)),
87
-    mktime(12,0,0,5,23,($year - 1)),
88
-    mktime(12,0,0,6,3,($year - 1)),
89
-    mktime(12,0,0,6,19,($year - 1)),
90
-    mktime(12,0,0,6,24,($year - 1)),
91
-    mktime(12,0,0,7,3,($year - 1)),
92
-    mktime(12,0,0,7,9,($year - 1)),
93
-    mktime(12,0,0,7,23,($year - 1)),
94
-    mktime(12,0,0,7,30,($year - 1)),
95
-    mktime(12,0,0,8,9,($year - 1)),
96
-    mktime(12,0,0,9,23,($year - 1)),
97
-    mktime(12,0,0,10,3,($year - 1)),
98
-    mktime(12,0,0,11,12,$year),
99
-    mktime(12,0,0,11,13,$year),
100
-    mktime(12,0,0,12,12,$year),
101
-    mktime(12,0,0,12,13,$year),
52
+$dates = array(mktime(12, 0, 0, 1, 3, $year),
53
+    mktime(12, 0, 0, 1, 9, $year),
54
+    mktime(12, 0, 0, 2, 13, $year),
55
+    mktime(12, 0, 0, 2, 23, $year),
56
+    mktime(12, 0, 0, 3, 30, $year),
57
+    mktime(12, 0, 0, 4, 3, $year),
58
+    mktime(12, 0, 0, 4, 3, $year),
59
+    mktime(12, 0, 0, 5, 9, $year),
60
+    mktime(12, 0, 0, 5, 1, $year),
61
+    mktime(12, 0, 0, 5, 13, $year),
62
+    mktime(12, 0, 0, 5, 19, $year),
63
+    mktime(12, 0, 0, 5, 23, $year),
64
+    mktime(12, 0, 0, 6, 3, $year),
65
+    mktime(12, 0, 0, 6, 19, $year),
66
+    mktime(12, 0, 0, 6, 24, $year),
67
+    mktime(12, 0, 0, 7, 3, $year),
68
+    mktime(12, 0, 0, 7, 9, $year),
69
+    mktime(12, 0, 0, 7, 23, $year),
70
+    mktime(12, 0, 0, 7, 30, $year),
71
+    mktime(12, 0, 0, 8, 9, $year),
72
+    mktime(12, 0, 0, 9, 23, $year),
73
+    mktime(12, 0, 0, 10, 3, $year),
74
+    mktime(12, 0, 0, 11, 12, $year),
75
+    mktime(12, 0, 0, 11, 13, $year),
76
+    mktime(12, 0, 0, 1, 3, ($year - 1)),
77
+    mktime(12, 0, 0, 1, 9, ($year - 1)),
78
+    mktime(12, 0, 0, 2, 13, ($year - 1)),
79
+    mktime(12, 0, 0, 2, 23, ($year - 1)),
80
+    mktime(12, 0, 0, 3, 30, ($year - 1)),
81
+    mktime(12, 0, 0, 4, 3, ($year - 1)),
82
+    mktime(12, 0, 0, 4, 3, ($year - 1)),
83
+    mktime(12, 0, 0, 5, 9, ($year - 1)),
84
+    mktime(12, 0, 0, 5, 1, ($year - 1)),
85
+    mktime(12, 0, 0, 5, 13, ($year - 1)),
86
+    mktime(12, 0, 0, 5, 19, ($year - 1)),
87
+    mktime(12, 0, 0, 5, 23, ($year - 1)),
88
+    mktime(12, 0, 0, 6, 3, ($year - 1)),
89
+    mktime(12, 0, 0, 6, 19, ($year - 1)),
90
+    mktime(12, 0, 0, 6, 24, ($year - 1)),
91
+    mktime(12, 0, 0, 7, 3, ($year - 1)),
92
+    mktime(12, 0, 0, 7, 9, ($year - 1)),
93
+    mktime(12, 0, 0, 7, 23, ($year - 1)),
94
+    mktime(12, 0, 0, 7, 30, ($year - 1)),
95
+    mktime(12, 0, 0, 8, 9, ($year - 1)),
96
+    mktime(12, 0, 0, 9, 23, ($year - 1)),
97
+    mktime(12, 0, 0, 10, 3, ($year - 1)),
98
+    mktime(12, 0, 0, 11, 12, $year),
99
+    mktime(12, 0, 0, 11, 13, $year),
100
+    mktime(12, 0, 0, 12, 12, $year),
101
+    mktime(12, 0, 0, 12, 13, $year),
102 102
 );
103 103
 
104
-$ret=$user->fetch('','admin');
104
+$ret = $user->fetch('', 'admin');
105 105
 if ($ret <= 0)
106 106
 {
107 107
     print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 
112 112
 $societesid = array();
113 113
 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe where client in (1, 3)";
114
-$resql=$db->query($sql);
114
+$resql = $db->query($sql);
115 115
 if ($resql) {
116 116
 	$num_thirdparties = $db->num_rows($resql);
117 117
 	$i = 0;
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 
126 126
 $commandesid = array();
127 127
 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."commande";
128
-$resql=$db->query($sql);
128
+$resql = $db->query($sql);
129 129
 if ($resql) {
130 130
 	$num = $db->num_rows($resql);
131 131
 	$i = 0;
@@ -157,14 +157,14 @@  discard block
 block discarded – undo
157 157
 
158 158
 
159 159
 print "Build ".GEN_NUMBER_COMMANDE." orders\n";
160
-for ($s = 0 ; $s < GEN_NUMBER_COMMANDE ; $s++)
160
+for ($s = 0; $s < GEN_NUMBER_COMMANDE; $s++)
161 161
 {
162 162
     print "Process order ".$s."\n";
163 163
 
164 164
     $object = new Commande($db);
165 165
 
166 166
     $object->socid          = $societesid[mt_rand(1, $num_thirdparties)];
167
-    $object->date_commande  = $dates[mt_rand(1, count($dates)-1)];
167
+    $object->date_commande  = $dates[mt_rand(1, count($dates) - 1)];
168 168
     $object->note           = 'My small comment about this order. Hum. Nothing.';
169 169
     $object->source         = 1;
170 170
     $object->fk_project     = 0;
@@ -174,15 +174,15 @@  discard block
 block discarded – undo
174 174
     $object->more_reglement_id = mt_rand(0, 7);
175 175
     $object->availability_id = mt_rand(0, 1);
176 176
     
177
-    $listofuserid=array(12,13,16);
177
+    $listofuserid = array(12, 13, 16);
178 178
     
179 179
     $fuser = new User($db);
180
-    $fuser->fetch($listofuserid[mt_rand(0,2)]);
180
+    $fuser->fetch($listofuserid[mt_rand(0, 2)]);
181 181
     $fuser->getRights();
182 182
     
183 183
     $db->begin();
184 184
 
185
-    $result=$object->create($fuser);
185
+    $result = $object->create($fuser);
186 186
 	if ($result >= 0)
187 187
 	{
188 188
         $nbp = mt_rand(2, 5);
@@ -190,17 +190,17 @@  discard block
 block discarded – undo
190 190
         while ($xnbp < $nbp)
191 191
         {
192 192
             $prodid = mt_rand(1, $num_prods);
193
-            $product=new Product($db);
194
-            $result=$product->fetch($prodids[$prodid]);
195
-            $result=$object->addline($product->description, $product->price, mt_rand(1,5), 0, 0, 0, $prodids[$prodid], 0, 0, 0,  $product->price_base_type, $product->price_ttc, '', '', $product->type);
193
+            $product = new Product($db);
194
+            $result = $product->fetch($prodids[$prodid]);
195
+            $result = $object->addline($product->description, $product->price, mt_rand(1, 5), 0, 0, 0, $prodids[$prodid], 0, 0, 0, $product->price_base_type, $product->price_ttc, '', '', $product->type);
196 196
             if ($result <= 0)
197 197
             {
198
-                dol_print_error($db,$object->error);
198
+                dol_print_error($db, $object->error);
199 199
             }
200 200
             $xnbp++;
201 201
         }
202 202
 
203
-	    $result=$object->valid($fuser);
203
+	    $result = $object->valid($fuser);
204 204
 		if ($result > 0)
205 205
 		{
206 206
             $db->commit();
@@ -210,14 +210,14 @@  discard block
 block discarded – undo
210 210
 		{
211 211
             print " KO\n";
212 212
 		    $db->rollback();
213
-		    dol_print_error($db,$object->error);
213
+		    dol_print_error($db, $object->error);
214 214
 		}
215 215
 	}
216 216
 	else
217 217
 	{
218 218
         print " KO\n";
219 219
 	    $db->rollback();
220
-	    dol_print_error($db,$object->error);
220
+	    dol_print_error($db, $object->error);
221 221
 	}
222 222
 }
223 223
 
Please login to merge, or discard this patch.
Braces   +4 added lines, -8 removed lines patch added patch discarded remove patch
@@ -120,8 +120,7 @@  discard block
 block discarded – undo
120 120
 	    $row = $db->fetch_row($resql);
121 121
 		$societesid[$i] = $row[0];
122 122
 	}
123
-}
124
-else { print "err"; }
123
+} else { print "err"; }
125 124
 
126 125
 $commandesid = array();
127 126
 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."commande";
@@ -134,8 +133,7 @@  discard block
 block discarded – undo
134 133
 	    $row = $db->fetch_row($resql);
135 134
 		$commandesid[$i] = $row[0];
136 135
 	}
137
-}
138
-else { print "err"; }
136
+} else { print "err"; }
139 137
 
140 138
 $prodids = array();
141 139
 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product WHERE tosell=1";
@@ -205,15 +203,13 @@  discard block
 block discarded – undo
205 203
 		{
206 204
             $db->commit();
207 205
             print " OK with ref ".$object->ref."\n";
208
-		}
209
-		else
206
+		} else
210 207
 		{
211 208
             print " KO\n";
212 209
 		    $db->rollback();
213 210
 		    dol_print_error($db,$object->error);
214 211
 		}
215
-	}
216
-	else
212
+	} else
217 213
 	{
218 214
         print " KO\n";
219 215
 	    $db->rollback();
Please login to merge, or discard this patch.
dolibarr/dev/initdata/purge-data.php 3 patches
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -81,11 +81,11 @@  discard block
 block discarded – undo
81 81
         'DELETE FROM '.MAIN_DB_PREFIX.'supplier_proposaldet',
82 82
         'DELETE FROM '.MAIN_DB_PREFIX.'supplier_proposal',
83 83
     ),
84
-	'supplier_order'=>array(
84
+    'supplier_order'=>array(
85 85
         'DELETE FROM '.MAIN_DB_PREFIX.'commande_fournisseurdet',
86 86
         'DELETE FROM '.MAIN_DB_PREFIX.'commande_fournisseur',
87 87
     ),
88
-	'supplier_invoice'=>array(
88
+    'supplier_invoice'=>array(
89 89
         'DELETE FROM '.MAIN_DB_PREFIX.'facture_fourn_det',
90 90
         'DELETE FROM '.MAIN_DB_PREFIX.'facture_fourn',
91 91
     ),
@@ -116,9 +116,9 @@  discard block
 block discarded – undo
116 116
         'DELETE FROM '.MAIN_DB_PREFIX.'product_price',
117 117
         'DELETE FROM '.MAIN_DB_PREFIX.'product_fournisseur_price',
118 118
         'DELETE FROM '.MAIN_DB_PREFIX.'product_batch',
119
-    	'DELETE FROM '.MAIN_DB_PREFIX.'product_stock',
119
+        'DELETE FROM '.MAIN_DB_PREFIX.'product_stock',
120 120
         'DELETE FROM '.MAIN_DB_PREFIX.'product_lot',
121
-    	'DELETE FROM '.MAIN_DB_PREFIX.'product',
121
+        'DELETE FROM '.MAIN_DB_PREFIX.'product',
122 122
     ),
123 123
     'project'=>array(
124 124
         'DELETE FROM '.MAIN_DB_PREFIX.'projet_task_time',
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
         'DELETE FROM '.MAIN_DB_PREFIX.'categorie_societe',
138 138
         'DELETE FROM '.MAIN_DB_PREFIX.'societe_remise_except',
139 139
         'DELETE FROM '.MAIN_DB_PREFIX.'societe_rib',
140
-    	'DELETE FROM '.MAIN_DB_PREFIX.'societe',
140
+        'DELETE FROM '.MAIN_DB_PREFIX.'societe',
141 141
     )
142 142
 );
143 143
 
@@ -172,18 +172,18 @@  discard block
 block discarded – undo
172 172
 // Replace database handler
173 173
 if (! empty($argv[3]))
174 174
 {
175
-	$db->close();
176
-	unset($db);
177
-	$db=getDoliDBInstance($argv[3], $argv[4], $argv[5], $argv[6], $argv[7], $argv[8]);
178
-	$user=new User($db);
175
+    $db->close();
176
+    unset($db);
177
+    $db=getDoliDBInstance($argv[3], $argv[4], $argv[5], $argv[6], $argv[7], $argv[8]);
178
+    $user=new User($db);
179 179
 }
180 180
 
181 181
 //var_dump($user->db->database_name);
182 182
 $ret=$user->fetch('','admin');
183 183
 if (! $ret > 0)
184 184
 {
185
-	print 'An admin user with login "admin" must exists to use this script.'."\n";
186
-	exit;
185
+    print 'An admin user with login "admin" must exists to use this script.'."\n";
186
+    exit;
187 187
 }
188 188
 //$user->getrights();
189 189
 
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 
27 27
 $sapi_type = php_sapi_name();
28 28
 $script_file = basename(__FILE__);
29
-$path=dirname(__FILE__).'/';
29
+$path = dirname(__FILE__).'/';
30 30
 
31 31
 // Test si mode batch
32 32
 if (substr($sapi_type, 0, 3) == 'cgi') {
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 }
36 36
 
37 37
 // Recupere root dolibarr
38
-$path=preg_replace('/purge-data.php/i','',$_SERVER["PHP_SELF"]);
38
+$path = preg_replace('/purge-data.php/i', '', $_SERVER["PHP_SELF"]);
39 39
 require $path."../../htdocs/master.inc.php";
40 40
 include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
41 41
 include_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
@@ -47,11 +47,11 @@  discard block
 block discarded – undo
47 47
 $langs->loadLangs(array("main", "errors"));
48 48
 
49 49
 // Global variables
50
-$version=DOL_VERSION;
51
-$error=0;
50
+$version = DOL_VERSION;
51
+$error = 0;
52 52
 
53 53
 // List of sql to execute
54
-$sqls=array(
54
+$sqls = array(
55 55
     'user'=>array(
56 56
         'DELETE FROM '.MAIN_DB_PREFIX."user_rights WHERE fk_user IN (SELECT rowid FROM ".MAIN_DB_PREFIX."user WHERE admin = 0 and login != 'admin')",
57 57
         'DELETE FROM '.MAIN_DB_PREFIX."user WHERE admin = 0 and login != 'admin'",
@@ -150,37 +150,37 @@  discard block
 block discarded – undo
150 150
 
151 151
 @set_time_limit(0);
152 152
 print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
153
-dol_syslog($script_file." launched with arg ".implode(',',$argv));
153
+dol_syslog($script_file." launched with arg ".implode(',', $argv));
154 154
 
155 155
 $mode = $argv[1];
156 156
 $option = $argv[2];
157 157
 
158
-if (empty($mode) || ! in_array($mode,array('test','confirm'))) {
158
+if (empty($mode) || !in_array($mode, array('test', 'confirm'))) {
159 159
     print "Usage:  $script_file (test|confirm) (all|option) [dbtype dbhost dbuser dbpassword dbname dbport]\n";
160 160
     print "\n";
161
-    print "option can be ".implode(',',array_keys($sqls))."\n";
161
+    print "option can be ".implode(',', array_keys($sqls))."\n";
162 162
     exit(-1);
163 163
 }
164 164
 
165
-if (empty($option) || ! in_array($option, array_merge(array('all'),array_keys($sqls))) ) {
165
+if (empty($option) || !in_array($option, array_merge(array('all'), array_keys($sqls)))) {
166 166
     print "Usage:  $script_file (test|confirm) (all|option) [dbtype dbhost dbuser dbpassword dbname dbport]\n";
167 167
     print "\n";
168
-    print "option can be ".implode(',',array_keys($sqls))."\n";
168
+    print "option can be ".implode(',', array_keys($sqls))."\n";
169 169
     exit(-1);
170 170
 }
171 171
 
172 172
 // Replace database handler
173
-if (! empty($argv[3]))
173
+if (!empty($argv[3]))
174 174
 {
175 175
 	$db->close();
176 176
 	unset($db);
177
-	$db=getDoliDBInstance($argv[3], $argv[4], $argv[5], $argv[6], $argv[7], $argv[8]);
178
-	$user=new User($db);
177
+	$db = getDoliDBInstance($argv[3], $argv[4], $argv[5], $argv[6], $argv[7], $argv[8]);
178
+	$user = new User($db);
179 179
 }
180 180
 
181 181
 //var_dump($user->db->database_name);
182
-$ret=$user->fetch('','admin');
183
-if (! $ret > 0)
182
+$ret = $user->fetch('', 'admin');
183
+if (!$ret > 0)
184 184
 {
185 185
 	print 'An admin user with login "admin" must exists to use this script.'."\n";
186 186
 	exit;
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 print "User = ".$db->database_user."\n";
196 196
 print "\n";
197 197
 
198
-if (! $confirmed)
198
+if (!$confirmed)
199 199
 {
200 200
     print "Hit Enter to continue or CTRL+C to stop...\n";
201 201
     $input = trim(fgets(STDIN));
@@ -212,19 +212,19 @@  discard block
 block discarded – undo
212 212
 {
213 213
     global $db, $sqls;
214 214
 
215
-    $error=0;
216
-    foreach($sqls[$family] as $sql)
215
+    $error = 0;
216
+    foreach ($sqls[$family] as $sql)
217 217
     {
218
-        if (preg_match('/^@/',$sql))
218
+        if (preg_match('/^@/', $sql))
219 219
         {
220
-            $newfamily=preg_replace('/@/','',$sql);
220
+            $newfamily = preg_replace('/@/', '', $sql);
221 221
             processfamily($newfamily);
222 222
             continue;
223 223
         }
224 224
 
225 225
         print "Run sql: ".$sql."\n";
226
-        $resql=$db->query($sql);
227
-        if (! $resql)
226
+        $resql = $db->query($sql);
227
+        if (!$resql)
228 228
         {
229 229
             if ($db->errno() != 'DB_ERROR_NOSUCHTABLE')
230 230
             {
@@ -247,15 +247,15 @@  discard block
 block discarded – undo
247 247
 
248 248
 $db->begin();
249 249
 
250
-$oldfamily='';
251
-foreach($sqls as $family => $familysql)
250
+$oldfamily = '';
251
+foreach ($sqls as $family => $familysql)
252 252
 {
253 253
     if ($option && $option != 'all' && $option != $family) continue;
254 254
 
255 255
     if ($family != $oldfamily) print "Process action for family ".$family."\n";
256 256
     $oldfamily = $family;
257 257
 
258
-    $result=processfamily($family);
258
+    $result = processfamily($family);
259 259
     if ($result < 0)
260 260
     {
261 261
         $error++;
Please login to merge, or discard this patch.
Braces   +13 added lines, -7 removed lines patch added patch discarded remove patch
@@ -240,9 +240,12 @@  discard block
 block discarded – undo
240 240
         }
241 241
     }
242 242
 
243
-    if ($error) return -1;
244
-    else return 1;
245
-}
243
+    if ($error) {
244
+        return -1;
245
+    } else {
246
+        return 1;
247
+    }
248
+    }
246 249
 
247 250
 
248 251
 $db->begin();
@@ -250,9 +253,13 @@  discard block
 block discarded – undo
250 253
 $oldfamily='';
251 254
 foreach($sqls as $family => $familysql)
252 255
 {
253
-    if ($option && $option != 'all' && $option != $family) continue;
256
+    if ($option && $option != 'all' && $option != $family) {
257
+        continue;
258
+    }
254 259
 
255
-    if ($family != $oldfamily) print "Process action for family ".$family."\n";
260
+    if ($family != $oldfamily) {
261
+        print "Process action for family ".$family."\n";
262
+    }
256 263
     $oldfamily = $family;
257 264
 
258 265
     $result=processfamily($family);
@@ -267,8 +274,7 @@  discard block
 block discarded – undo
267 274
 {
268 275
     print "Rollback any changes.\n";
269 276
     $db->rollback();
270
-}
271
-else
277
+} else
272 278
 {
273 279
     print "Commit all changes.\n";
274 280
     $db->commit();
Please login to merge, or discard this patch.
dolibarr/dev/initdata/generate-invoice.php 3 patches
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -26,8 +26,8 @@  discard block
 block discarded – undo
26 26
 // Test si mode batch
27 27
 $sapi_type = php_sapi_name();
28 28
 if (substr($sapi_type, 0, 3) == 'cgi') {
29
-	echo "Erreur: Vous utilisez l'interpreteur PHP pour le mode CGI. Pour executer mailing-send.php en ligne de commande, vous devez utiliser l'interpreteur PHP pour le mode CLI.\n";
30
-	exit;
29
+    echo "Erreur: Vous utilisez l'interpreteur PHP pour le mode CGI. Pour executer mailing-send.php en ligne de commande, vous devez utiliser l'interpreteur PHP pour le mode CLI.\n";
30
+    exit;
31 31
 }
32 32
 
33 33
 // Recupere root dolibarr
@@ -98,8 +98,8 @@  discard block
 block discarded – undo
98 98
 $ret=$user->fetch('','admin');
99 99
 if (! $ret > 0)
100 100
 {
101
-	print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
102
-	exit;
101
+    print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
102
+    exit;
103 103
 }
104 104
 $user->getrights();
105 105
 
@@ -109,14 +109,14 @@  discard block
 block discarded – undo
109 109
 $resql = $db->query($sql);
110 110
 if ($resql)
111 111
 {
112
-	$num_thirdparties = $db->num_rows($resql);
113
-	$i = 0;
114
-	while ($i < $num_thirdparties)
115
-	{
116
-		$i++;
117
-		$row = $db->fetch_row($resql);
118
-		$socids[$i] = $row[0];
119
-	}
112
+    $num_thirdparties = $db->num_rows($resql);
113
+    $i = 0;
114
+    while ($i < $num_thirdparties)
115
+    {
116
+        $i++;
117
+        $row = $db->fetch_row($resql);
118
+        $socids[$i] = $row[0];
119
+    }
120 120
 }
121 121
 
122 122
 $prodids = array();
@@ -124,65 +124,65 @@  discard block
 block discarded – undo
124 124
 $resql = $db->query($sql);
125 125
 if ($resql)
126 126
 {
127
-	$num_prods = $db->num_rows($resql);
128
-	$i = 0;
129
-	while ($i < $num_prods)
130
-	{
131
-		$i++;
132
-		$row = $db->fetch_row($resql);
133
-		$prodids[$i] = $row[0];
134
-	}
127
+    $num_prods = $db->num_rows($resql);
128
+    $i = 0;
129
+    while ($i < $num_prods)
130
+    {
131
+        $i++;
132
+        $row = $db->fetch_row($resql);
133
+        $prodids[$i] = $row[0];
134
+    }
135 135
 }
136 136
 
137 137
 $i=0;
138 138
 $result=0;
139 139
 while ($i < GEN_NUMBER_FACTURE && $result >= 0)
140 140
 {
141
-	$i++;
142
-	$socid = mt_rand(1, $num_thirdparties);
141
+    $i++;
142
+    $socid = mt_rand(1, $num_thirdparties);
143 143
 
144
-	print "Invoice ".$i." for socid ".$socid;
144
+    print "Invoice ".$i." for socid ".$socid;
145 145
 
146
-	$object = new Facture($db);
147
-	$object->socid = $socids[$socid];
148
-	$object->date = $dates[mt_rand(1, count($dates)-1)];
149
-	$object->cond_reglement_id = 3;
150
-	$object->mode_reglement_id = 3;
146
+    $object = new Facture($db);
147
+    $object->socid = $socids[$socid];
148
+    $object->date = $dates[mt_rand(1, count($dates)-1)];
149
+    $object->cond_reglement_id = 3;
150
+    $object->mode_reglement_id = 3;
151 151
 
152 152
     $fuser = new User($db);
153 153
     $fuser->fetch(mt_rand(1,2));
154 154
     $fuser->getRights();
155 155
     
156
-	$result=$object->create($fuser);
157
-	if ($result >= 0)
158
-	{
159
-		$nbp = mt_rand(2, 5);
160
-		$xnbp = 0;
161
-		while ($xnbp < $nbp)
162
-		{
163
-			$prodid = mt_rand(1, $num_prods);
164
-			$product=new Product($db);
165
-			$result=$product->fetch($prodids[$prodid]);
166
-			$result=$object->addline($product->description, $product->price, mt_rand(1,5), 0, 0, 0, $prodids[$prodid], 0, '', '', 0, 0, '', $product->price_base_type, $product->price_ttc, $product->type);
167
-		    if ($result < 0)
156
+    $result=$object->create($fuser);
157
+    if ($result >= 0)
158
+    {
159
+        $nbp = mt_rand(2, 5);
160
+        $xnbp = 0;
161
+        while ($xnbp < $nbp)
162
+        {
163
+            $prodid = mt_rand(1, $num_prods);
164
+            $product=new Product($db);
165
+            $result=$product->fetch($prodids[$prodid]);
166
+            $result=$object->addline($product->description, $product->price, mt_rand(1,5), 0, 0, 0, $prodids[$prodid], 0, '', '', 0, 0, '', $product->price_base_type, $product->price_ttc, $product->type);
167
+            if ($result < 0)
168 168
             {
169 169
                 dol_print_error($db,$propal->error);
170 170
             }
171 171
             $xnbp++;
172
-		}
172
+        }
173 173
 
174
-	    $result=$object->validate($fuser);
175
-		if ($result)
176
-		{
177
-			print " OK with ref ".$object->ref."\n";;
178
-		}
179
-		else
180
-		{
181
-			dol_print_error($db,$object->error);
182
-		}
183
-	}
184
-	else
185
-	{
186
-		dol_print_error($db,$object->error);
187
-	}
174
+        $result=$object->validate($fuser);
175
+        if ($result)
176
+        {
177
+            print " OK with ref ".$object->ref."\n";;
178
+        }
179
+        else
180
+        {
181
+            dol_print_error($db,$object->error);
182
+        }
183
+    }
184
+    else
185
+    {
186
+        dol_print_error($db,$object->error);
187
+    }
188 188
 }
Please login to merge, or discard this patch.
Spacing   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 
33 33
 // Recupere root dolibarr
34 34
 //$path=preg_replace('/generate-produit.php/i','',$_SERVER["PHP_SELF"]);
35
-require __DIR__. '/../../htdocs/master.inc.php';
35
+require __DIR__.'/../../htdocs/master.inc.php';
36 36
 require_once DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php";
37 37
 require_once DOL_DOCUMENT_ROOT."/societe/class/societe.class.php";
38 38
 
@@ -43,60 +43,60 @@  discard block
 block discarded – undo
43 43
 
44 44
 define(GEN_NUMBER_FACTURE, 1);
45 45
 $year = 2016;
46
-$dates = array (mktime(12,0,0,1,3,$year),
47
-    mktime(12,0,0,1,9,$year),
48
-    mktime(12,0,0,2,13,$year),
49
-    mktime(12,0,0,2,23,$year),
50
-    mktime(12,0,0,3,30,$year),
51
-    mktime(12,0,0,4,3,$year),
52
-    mktime(12,0,0,4,3,$year),
53
-    mktime(12,0,0,5,9,$year),
54
-    mktime(12,0,0,5,1,$year),
55
-    mktime(12,0,0,5,13,$year),
56
-    mktime(12,0,0,5,19,$year),
57
-    mktime(12,0,0,5,23,$year),
58
-    mktime(12,0,0,6,3,$year),
59
-    mktime(12,0,0,6,19,$year),
60
-    mktime(12,0,0,6,24,$year),
61
-    mktime(12,0,0,7,3,$year),
62
-    mktime(12,0,0,7,9,$year),
63
-    mktime(12,0,0,7,23,$year),
64
-    mktime(12,0,0,7,30,$year),
65
-    mktime(12,0,0,8,9,$year),
66
-    mktime(12,0,0,9,23,$year),
67
-    mktime(12,0,0,10,3,$year),
68
-    mktime(12,0,0,11,12,$year),
69
-    mktime(12,0,0,11,13,$year),
70
-    mktime(12,0,0,1,3,($year - 1)),
71
-    mktime(12,0,0,1,9,($year - 1)),
72
-    mktime(12,0,0,2,13,($year - 1)),
73
-    mktime(12,0,0,2,23,($year - 1)),
74
-    mktime(12,0,0,3,30,($year - 1)),
75
-    mktime(12,0,0,4,3,($year - 1)),
76
-    mktime(12,0,0,4,3,($year - 1)),
77
-    mktime(12,0,0,5,9,($year - 1)),
78
-    mktime(12,0,0,5,1,($year - 1)),
79
-    mktime(12,0,0,5,13,($year - 1)),
80
-    mktime(12,0,0,5,19,($year - 1)),
81
-    mktime(12,0,0,5,23,($year - 1)),
82
-    mktime(12,0,0,6,3,($year - 1)),
83
-    mktime(12,0,0,6,19,($year - 1)),
84
-    mktime(12,0,0,6,24,($year - 1)),
85
-    mktime(12,0,0,7,3,($year - 1)),
86
-    mktime(12,0,0,7,9,($year - 1)),
87
-    mktime(12,0,0,7,23,($year - 1)),
88
-    mktime(12,0,0,7,30,($year - 1)),
89
-    mktime(12,0,0,8,9,($year - 1)),
90
-    mktime(12,0,0,9,23,($year - 1)),
91
-    mktime(12,0,0,10,3,($year - 1)),
92
-    mktime(12,0,0,11,12,$year),
93
-    mktime(12,0,0,11,13,$year),
94
-    mktime(12,0,0,12,12,$year),
95
-    mktime(12,0,0,12,13,$year),
46
+$dates = array(mktime(12, 0, 0, 1, 3, $year),
47
+    mktime(12, 0, 0, 1, 9, $year),
48
+    mktime(12, 0, 0, 2, 13, $year),
49
+    mktime(12, 0, 0, 2, 23, $year),
50
+    mktime(12, 0, 0, 3, 30, $year),
51
+    mktime(12, 0, 0, 4, 3, $year),
52
+    mktime(12, 0, 0, 4, 3, $year),
53
+    mktime(12, 0, 0, 5, 9, $year),
54
+    mktime(12, 0, 0, 5, 1, $year),
55
+    mktime(12, 0, 0, 5, 13, $year),
56
+    mktime(12, 0, 0, 5, 19, $year),
57
+    mktime(12, 0, 0, 5, 23, $year),
58
+    mktime(12, 0, 0, 6, 3, $year),
59
+    mktime(12, 0, 0, 6, 19, $year),
60
+    mktime(12, 0, 0, 6, 24, $year),
61
+    mktime(12, 0, 0, 7, 3, $year),
62
+    mktime(12, 0, 0, 7, 9, $year),
63
+    mktime(12, 0, 0, 7, 23, $year),
64
+    mktime(12, 0, 0, 7, 30, $year),
65
+    mktime(12, 0, 0, 8, 9, $year),
66
+    mktime(12, 0, 0, 9, 23, $year),
67
+    mktime(12, 0, 0, 10, 3, $year),
68
+    mktime(12, 0, 0, 11, 12, $year),
69
+    mktime(12, 0, 0, 11, 13, $year),
70
+    mktime(12, 0, 0, 1, 3, ($year - 1)),
71
+    mktime(12, 0, 0, 1, 9, ($year - 1)),
72
+    mktime(12, 0, 0, 2, 13, ($year - 1)),
73
+    mktime(12, 0, 0, 2, 23, ($year - 1)),
74
+    mktime(12, 0, 0, 3, 30, ($year - 1)),
75
+    mktime(12, 0, 0, 4, 3, ($year - 1)),
76
+    mktime(12, 0, 0, 4, 3, ($year - 1)),
77
+    mktime(12, 0, 0, 5, 9, ($year - 1)),
78
+    mktime(12, 0, 0, 5, 1, ($year - 1)),
79
+    mktime(12, 0, 0, 5, 13, ($year - 1)),
80
+    mktime(12, 0, 0, 5, 19, ($year - 1)),
81
+    mktime(12, 0, 0, 5, 23, ($year - 1)),
82
+    mktime(12, 0, 0, 6, 3, ($year - 1)),
83
+    mktime(12, 0, 0, 6, 19, ($year - 1)),
84
+    mktime(12, 0, 0, 6, 24, ($year - 1)),
85
+    mktime(12, 0, 0, 7, 3, ($year - 1)),
86
+    mktime(12, 0, 0, 7, 9, ($year - 1)),
87
+    mktime(12, 0, 0, 7, 23, ($year - 1)),
88
+    mktime(12, 0, 0, 7, 30, ($year - 1)),
89
+    mktime(12, 0, 0, 8, 9, ($year - 1)),
90
+    mktime(12, 0, 0, 9, 23, ($year - 1)),
91
+    mktime(12, 0, 0, 10, 3, ($year - 1)),
92
+    mktime(12, 0, 0, 11, 12, $year),
93
+    mktime(12, 0, 0, 11, 13, $year),
94
+    mktime(12, 0, 0, 12, 12, $year),
95
+    mktime(12, 0, 0, 12, 13, $year),
96 96
 );
97 97
 
98
-$ret=$user->fetch('','admin');
99
-if (! $ret > 0)
98
+$ret = $user->fetch('', 'admin');
99
+if (!$ret > 0)
100 100
 {
101 101
 	print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
102 102
 	exit;
@@ -134,8 +134,8 @@  discard block
 block discarded – undo
134 134
 	}
135 135
 }
136 136
 
137
-$i=0;
138
-$result=0;
137
+$i = 0;
138
+$result = 0;
139 139
 while ($i < GEN_NUMBER_FACTURE && $result >= 0)
140 140
 {
141 141
 	$i++;
@@ -145,15 +145,15 @@  discard block
 block discarded – undo
145 145
 
146 146
 	$object = new Facture($db);
147 147
 	$object->socid = $socids[$socid];
148
-	$object->date = $dates[mt_rand(1, count($dates)-1)];
148
+	$object->date = $dates[mt_rand(1, count($dates) - 1)];
149 149
 	$object->cond_reglement_id = 3;
150 150
 	$object->mode_reglement_id = 3;
151 151
 
152 152
     $fuser = new User($db);
153
-    $fuser->fetch(mt_rand(1,2));
153
+    $fuser->fetch(mt_rand(1, 2));
154 154
     $fuser->getRights();
155 155
     
156
-	$result=$object->create($fuser);
156
+	$result = $object->create($fuser);
157 157
 	if ($result >= 0)
158 158
 	{
159 159
 		$nbp = mt_rand(2, 5);
@@ -161,28 +161,28 @@  discard block
 block discarded – undo
161 161
 		while ($xnbp < $nbp)
162 162
 		{
163 163
 			$prodid = mt_rand(1, $num_prods);
164
-			$product=new Product($db);
165
-			$result=$product->fetch($prodids[$prodid]);
166
-			$result=$object->addline($product->description, $product->price, mt_rand(1,5), 0, 0, 0, $prodids[$prodid], 0, '', '', 0, 0, '', $product->price_base_type, $product->price_ttc, $product->type);
164
+			$product = new Product($db);
165
+			$result = $product->fetch($prodids[$prodid]);
166
+			$result = $object->addline($product->description, $product->price, mt_rand(1, 5), 0, 0, 0, $prodids[$prodid], 0, '', '', 0, 0, '', $product->price_base_type, $product->price_ttc, $product->type);
167 167
 		    if ($result < 0)
168 168
             {
169
-                dol_print_error($db,$propal->error);
169
+                dol_print_error($db, $propal->error);
170 170
             }
171 171
             $xnbp++;
172 172
 		}
173 173
 
174
-	    $result=$object->validate($fuser);
174
+	    $result = $object->validate($fuser);
175 175
 		if ($result)
176 176
 		{
177
-			print " OK with ref ".$object->ref."\n";;
177
+			print " OK with ref ".$object->ref."\n"; ;
178 178
 		}
179 179
 		else
180 180
 		{
181
-			dol_print_error($db,$object->error);
181
+			dol_print_error($db, $object->error);
182 182
 		}
183 183
 	}
184 184
 	else
185 185
 	{
186
-		dol_print_error($db,$object->error);
186
+		dol_print_error($db, $object->error);
187 187
 	}
188 188
 }
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -175,13 +175,11 @@
 block discarded – undo
175 175
 		if ($result)
176 176
 		{
177 177
 			print " OK with ref ".$object->ref."\n";;
178
-		}
179
-		else
178
+		} else
180 179
 		{
181 180
 			dol_print_error($db,$object->error);
182 181
 		}
183
-	}
184
-	else
182
+	} else
185 183
 	{
186 184
 		dol_print_error($db,$object->error);
187 185
 	}
Please login to merge, or discard this patch.
dolibarr/dev/initdata/generate-thirdparty.php 3 patches
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -55,8 +55,8 @@  discard block
 block discarded – undo
55 55
 $ret=$user->fetch('','admin');
56 56
 if (! $ret > 0)
57 57
 {
58
-	print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
59
-	exit;
58
+    print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
59
+    exit;
60 60
 }
61 61
 $user->getrights();
62 62
 
@@ -64,21 +64,21 @@  discard block
 block discarded – undo
64 64
 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product"; $productsid = array();
65 65
 $resql=$db->query($sql);
66 66
 if ($resql) {
67
-  $num = $db->num_rows($resql); $i = 0;
68
-  while ($i < $num) {      $row = $db->fetch_row($resql);      $productsid[$i] = $row[0];      $i++; }
67
+    $num = $db->num_rows($resql); $i = 0;
68
+    while ($i < $num) {      $row = $db->fetch_row($resql);      $productsid[$i] = $row[0];      $i++; }
69 69
 }
70 70
 
71 71
 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe"; $societesid = array();
72 72
 $resql=$db->query($sql);
73 73
 if ($resql) {
74
-	$num = $db->num_rows($resql); $i = 0;
74
+    $num = $db->num_rows($resql); $i = 0;
75 75
     while ($i < $num) { $row = $db->fetch_row($resql);      $societesid[$i] = $row[0];      $i++; }
76 76
 } else { print "err"; }
77 77
 
78 78
 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."commande"; $commandesid = array();
79 79
 $resql=$db->query($sql);
80 80
 if ($resql) {
81
-	$num = $db->num_rows($resql); $i = 0;
81
+    $num = $db->num_rows($resql); $i = 0;
82 82
     while ($i < $num) { $row = $db->fetch_row($resql);      $commandesid[$i] = $row[0];      $i++; }
83 83
 } else { print "err"; }
84 84
 
@@ -98,9 +98,9 @@  discard block
 block discarded – undo
98 98
     $soc->tva_assuj=1;
99 99
     $soc->country_id=1;
100 100
     $soc->country_code='FR';
101
-	// Un client sur 3 a une remise de 5%
101
+    // Un client sur 3 a une remise de 5%
102 102
     $user_remise=mt_rand(1,3); if ($user_remise==3) $soc->remise_percent=5;
103
-	print "> client=".$soc->client.", fournisseur=".$soc->fournisseur.", remise=".$soc->remise_percent."\n";
103
+    print "> client=".$soc->client.", fournisseur=".$soc->fournisseur.", remise=".$soc->remise_percent."\n";
104 104
     $soc->note_private = 'Company created by the script generate-societe.php';
105 105
     $socid = $soc->create();
106 106
 
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
     }
125 125
     else
126 126
     {
127
-    	print "Error: ".$soc->error."\n";
127
+        print "Error: ".$soc->error."\n";
128 128
     }
129 129
 }
130 130
 
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 
34 34
 // Recupere root dolibarr
35 35
 //$path=preg_replace('/generate-societe.php/i','',$_SERVER["PHP_SELF"]);
36
-require __DIR__. '/../../htdocs/master.inc.php';
36
+require __DIR__.'/../../htdocs/master.inc.php';
37 37
 include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
38 38
 include_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
39 39
 include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
@@ -41,8 +41,8 @@  discard block
 block discarded – undo
41 41
 include_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
42 42
 include_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
43 43
 
44
-$listoftown = array("Auray","Baden","Vannes","Pirouville","Haguenau","Souffelweiersheim","Illkirch-Graffenstaden","Lauterbourg","Picauville","Sainte-Mère Eglise","Le Bono");
45
-$listoflastname = array("Joe","Marc","Steve","Laurent","Nico","Isabelle","Dorothee","Saby","Brigitte","Karine","Jose-Anne","Celine","Virginie");
44
+$listoftown = array("Auray", "Baden", "Vannes", "Pirouville", "Haguenau", "Souffelweiersheim", "Illkirch-Graffenstaden", "Lauterbourg", "Picauville", "Sainte-Mère Eglise", "Le Bono");
45
+$listoflastname = array("Joe", "Marc", "Steve", "Laurent", "Nico", "Isabelle", "Dorothee", "Saby", "Brigitte", "Karine", "Jose-Anne", "Celine", "Virginie");
46 46
 
47 47
 
48 48
 /*
@@ -52,8 +52,8 @@  discard block
 block discarded – undo
52 52
 define(GEN_NUMBER_SOCIETE, 10);
53 53
 
54 54
 
55
-$ret=$user->fetch('','admin');
56
-if (! $ret > 0)
55
+$ret = $user->fetch('', 'admin');
56
+if (!$ret > 0)
57 57
 {
58 58
 	print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
59 59
 	exit;
@@ -62,59 +62,59 @@  discard block
 block discarded – undo
62 62
 
63 63
 
64 64
 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product"; $productsid = array();
65
-$resql=$db->query($sql);
65
+$resql = $db->query($sql);
66 66
 if ($resql) {
67 67
   $num = $db->num_rows($resql); $i = 0;
68
-  while ($i < $num) {      $row = $db->fetch_row($resql);      $productsid[$i] = $row[0];      $i++; }
68
+  while ($i < $num) {      $row = $db->fetch_row($resql); $productsid[$i] = $row[0]; $i++; }
69 69
 }
70 70
 
71 71
 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe"; $societesid = array();
72
-$resql=$db->query($sql);
72
+$resql = $db->query($sql);
73 73
 if ($resql) {
74 74
 	$num = $db->num_rows($resql); $i = 0;
75
-    while ($i < $num) { $row = $db->fetch_row($resql);      $societesid[$i] = $row[0];      $i++; }
75
+    while ($i < $num) { $row = $db->fetch_row($resql); $societesid[$i] = $row[0]; $i++; }
76 76
 } else { print "err"; }
77 77
 
78 78
 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."commande"; $commandesid = array();
79
-$resql=$db->query($sql);
79
+$resql = $db->query($sql);
80 80
 if ($resql) {
81 81
 	$num = $db->num_rows($resql); $i = 0;
82
-    while ($i < $num) { $row = $db->fetch_row($resql);      $commandesid[$i] = $row[0];      $i++; }
82
+    while ($i < $num) { $row = $db->fetch_row($resql); $commandesid[$i] = $row[0]; $i++; }
83 83
 } else { print "err"; }
84 84
 
85 85
 
86 86
 
87 87
 print "Generates ".GEN_NUMBER_SOCIETE." companies\n";
88
-for ($s = 0 ; $s < GEN_NUMBER_SOCIETE ; $s++)
88
+for ($s = 0; $s < GEN_NUMBER_SOCIETE; $s++)
89 89
 {
90 90
     print "Company $s\n";
91 91
     $soc = new Societe($db);
92 92
     $soc->name = "Company num ".time()."$s";
93
-    $soc->town = $listoftown[mt_rand(0, count($listoftown)-1)];
94
-    $soc->client = mt_rand(1,2);		// Une societe sur 2 est prospect, l'autre client
95
-    $soc->fournisseur = mt_rand(0,1);	// Une societe sur 2 est fournisseur
96
-    $soc->code_client='CU'.time()."$s";
97
-    $soc->code_fournisseur='SU'.time()."$s";
98
-    $soc->tva_assuj=1;
99
-    $soc->country_id=1;
100
-    $soc->country_code='FR';
93
+    $soc->town = $listoftown[mt_rand(0, count($listoftown) - 1)];
94
+    $soc->client = mt_rand(1, 2); // Une societe sur 2 est prospect, l'autre client
95
+    $soc->fournisseur = mt_rand(0, 1); // Une societe sur 2 est fournisseur
96
+    $soc->code_client = 'CU'.time()."$s";
97
+    $soc->code_fournisseur = 'SU'.time()."$s";
98
+    $soc->tva_assuj = 1;
99
+    $soc->country_id = 1;
100
+    $soc->country_code = 'FR';
101 101
 	// Un client sur 3 a une remise de 5%
102
-    $user_remise=mt_rand(1,3); if ($user_remise==3) $soc->remise_percent=5;
102
+    $user_remise = mt_rand(1, 3); if ($user_remise == 3) $soc->remise_percent = 5;
103 103
 	print "> client=".$soc->client.", fournisseur=".$soc->fournisseur.", remise=".$soc->remise_percent."\n";
104 104
     $soc->note_private = 'Company created by the script generate-societe.php';
105 105
     $socid = $soc->create();
106 106
 
107 107
     if ($socid >= 0)
108 108
     {
109
-        $rand = mt_rand(1,4);
109
+        $rand = mt_rand(1, 4);
110 110
         print "> Generates $rand contact(s)\n";
111
-        for ($c = 0 ; $c < $rand ; $c++)
111
+        for ($c = 0; $c < $rand; $c++)
112 112
         {
113 113
             $contact = new Contact($db);
114 114
             $contact->socid = $soc->id;
115 115
             $contact->lastname = "Lastname".$c;
116
-            $contact->firstname = $listoflastname[mt_rand(0, count($listoflastname)-1)];
117
-            if ( $contact->create($user) )
116
+            $contact->firstname = $listoflastname[mt_rand(0, count($listoflastname) - 1)];
117
+            if ($contact->create($user))
118 118
             {
119 119
 
120 120
             }
Please login to merge, or discard this patch.
Braces   +4 added lines, -3 removed lines patch added patch discarded remove patch
@@ -99,7 +99,9 @@  discard block
 block discarded – undo
99 99
     $soc->country_id=1;
100 100
     $soc->country_code='FR';
101 101
 	// Un client sur 3 a une remise de 5%
102
-    $user_remise=mt_rand(1,3); if ($user_remise==3) $soc->remise_percent=5;
102
+    $user_remise=mt_rand(1,3); if ($user_remise==3) {
103
+        $soc->remise_percent=5;
104
+    }
103 105
 	print "> client=".$soc->client.", fournisseur=".$soc->fournisseur.", remise=".$soc->remise_percent."\n";
104 106
     $soc->note_private = 'Company created by the script generate-societe.php';
105 107
     $socid = $soc->create();
@@ -121,8 +123,7 @@  discard block
 block discarded – undo
121 123
         }
122 124
 
123 125
         print "Company ".$s." created nom=".$soc->name."\n";
124
-    }
125
-    else
126
+    } else
126 127
     {
127 128
     	print "Error: ".$soc->error."\n";
128 129
     }
Please login to merge, or discard this patch.
dolibarr/dev/initdata/import-thirdparties.php 3 patches
Indentation   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -81,8 +81,8 @@  discard block
 block discarded – undo
81 81
 $ret=$user->fetch('','admin');
82 82
 if (! $ret > 0)
83 83
 {
84
-	print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
85
-	exit;
84
+    print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
85
+    exit;
86 86
 }
87 87
 $user->getrights();
88 88
 
@@ -182,116 +182,116 @@  discard block
 block discarded – undo
182 182
             print " - Error in create result code = ".$ret." - ".$object->errorsToString();
183 183
             $errorrecord++;
184 184
         }
185
-    	else
186
-    	{
187
-    	    print " - Creation OK with name ".$object->name." - id = ".$ret;
188
-    	}
185
+        else
186
+        {
187
+            print " - Creation OK with name ".$object->name." - id = ".$ret;
188
+        }
189 189
     }
190 190
 
191 191
     if (! $errorrecord)
192 192
     {
193 193
         dol_syslog("Set price level");
194
-	    $object->set_price_level($object->price_level, $user);
194
+        $object->set_price_level($object->price_level, $user);
195
+    }
196
+
197
+    // Assign sales representative
198
+    if (! $errorrecord && $fields[3])
199
+    {
200
+        $salesrep=new User($db);
201
+
202
+        $tmp=explode(' ',$fields[3],2);
203
+        $salesrep->firstname = trim($tmp[0]);
204
+        $salesrep->lastname = trim($tmp[1]);
205
+        if ($salesrep->lastname) $salesrep->login = strtolower(substr($salesrep->firstname, 0, 1)) . strtolower(substr($salesrep->lastname, 0));
206
+        else $salesrep->login=strtolower($salesrep->firstname);
207
+        $salesrep->login=preg_replace('/ /','',$salesrep->login);
208
+        $salesrep->fetch(0,$salesrep->login);
209
+
210
+        $result = $object->add_commercial($user, $salesrep->id);
211
+        if ($result < 0)
212
+        {
213
+            print " - Error in create link with sale representative result code = ".$result." - ".$object->errorsToString();
214
+            $errorrecord++;
215
+        }
216
+        else
217
+        {
218
+            print " - create link sale representative OK";
219
+        }
195 220
     }
196 221
 
197
-	// Assign sales representative
198
-	if (! $errorrecord && $fields[3])
199
-	{
200
-    	$salesrep=new User($db);
201
-
202
-    	$tmp=explode(' ',$fields[3],2);
203
-    	$salesrep->firstname = trim($tmp[0]);
204
-    	$salesrep->lastname = trim($tmp[1]);
205
-    	if ($salesrep->lastname) $salesrep->login = strtolower(substr($salesrep->firstname, 0, 1)) . strtolower(substr($salesrep->lastname, 0));
206
-    	else $salesrep->login=strtolower($salesrep->firstname);
207
-    	$salesrep->login=preg_replace('/ /','',$salesrep->login);
208
-    	$salesrep->fetch(0,$salesrep->login);
209
-
210
-    	$result = $object->add_commercial($user, $salesrep->id);
211
-    	if ($result < 0)
212
-    	{
213
-    	    print " - Error in create link with sale representative result code = ".$result." - ".$object->errorsToString();
214
-    	    $errorrecord++;
215
-    	}
216
-    	else
217
-    	{
218
-    	    print " - create link sale representative OK";
219
-    	}
220
-	}
221
-
222
-	dol_syslog("Add invoice contacts");
223
-	// Insert an invoice contact if there is an invoice email != standard email
224
-	if (! $errorrecord && $fields[27] && $fields[26] != $fields[27])
225
-	{
226
-	    $ret1=$ret2=0;
227
-
228
-	    $contact = new Contact($db);
229
-	    $contact->lastname = $object->name;
230
-	    $contact->address=$object->address;
231
-	    $contact->zip=$object->zip;
232
-	    $contact->town=$object->town;
233
-	    $contact->country_id=$object->country_id;
234
-	    $contact->email=$fields[27];
235
-	    $contact->socid=$object->id;
236
-
237
-	    $ret1=$contact->create($user);
238
-	    if ($ret1 > 0)
239
-	    {
240
-	        //$ret2=$contact->add_contact($object->id, 'BILLING');
241
-	    }
242
-	    if ($ret1 < 0 || $ret2 < 0)
222
+    dol_syslog("Add invoice contacts");
223
+    // Insert an invoice contact if there is an invoice email != standard email
224
+    if (! $errorrecord && $fields[27] && $fields[26] != $fields[27])
225
+    {
226
+        $ret1=$ret2=0;
227
+
228
+        $contact = new Contact($db);
229
+        $contact->lastname = $object->name;
230
+        $contact->address=$object->address;
231
+        $contact->zip=$object->zip;
232
+        $contact->town=$object->town;
233
+        $contact->country_id=$object->country_id;
234
+        $contact->email=$fields[27];
235
+        $contact->socid=$object->id;
236
+
237
+        $ret1=$contact->create($user);
238
+        if ($ret1 > 0)
239
+        {
240
+            //$ret2=$contact->add_contact($object->id, 'BILLING');
241
+        }
242
+        if ($ret1 < 0 || $ret2 < 0)
243 243
         {
244 244
             print " - Error in create contact result code = ".$ret1." ".$ret2." - ".$object->errorsToString();
245 245
             $errorrecord++;
246 246
         }
247
-    	else
248
-    	{
249
-    	    print " - create contact OK";
250
-    	}
251
-	}
252
-
253
-	dol_syslog("Add delivery contacts");
254
-	// Insert a delivery contact
255
-	if (! $errorrecord && $fields[47])
256
-	{
257
-	    $ret1=$ret2=0;
258
-
259
-	    $contact2 = new Contact($db);
260
-	    $contact2->lastname = 'Service livraison - '.$fields[47];
261
-	    $contact2->address = $fields[48];
262
-	    $contact2->zip = $fields[50];
263
-	    $contact2->town = $fields[51];
264
-	    $contact2->country_id=dol_getIdFromCode($db, trim($fields[52]), 'c_country', 'code', 'rowid');
265
-	    $contact2->note_public=$fields[54];
266
-	    $contact2->socid=$object->id;
267
-
268
-	    // Extrafields
269
-	    $contact2->array_options['options_anazoneliv']=price2num($fields[53]);
270
-
271
-	    $ret1=$contact2->create($user);
272
-	    if ($ret1 > 0)
273
-	    {
274
-	        //$ret2=$contact2->add_contact($object->id, 'SHIPPING');
275
-	    }
276
-	    if ($ret1 < 0 || $ret2 < 0)
247
+        else
248
+        {
249
+            print " - create contact OK";
250
+        }
251
+    }
252
+
253
+    dol_syslog("Add delivery contacts");
254
+    // Insert a delivery contact
255
+    if (! $errorrecord && $fields[47])
256
+    {
257
+        $ret1=$ret2=0;
258
+
259
+        $contact2 = new Contact($db);
260
+        $contact2->lastname = 'Service livraison - '.$fields[47];
261
+        $contact2->address = $fields[48];
262
+        $contact2->zip = $fields[50];
263
+        $contact2->town = $fields[51];
264
+        $contact2->country_id=dol_getIdFromCode($db, trim($fields[52]), 'c_country', 'code', 'rowid');
265
+        $contact2->note_public=$fields[54];
266
+        $contact2->socid=$object->id;
267
+
268
+        // Extrafields
269
+        $contact2->array_options['options_anazoneliv']=price2num($fields[53]);
270
+
271
+        $ret1=$contact2->create($user);
272
+        if ($ret1 > 0)
273
+        {
274
+            //$ret2=$contact2->add_contact($object->id, 'SHIPPING');
275
+        }
276
+        if ($ret1 < 0 || $ret2 < 0)
277 277
         {
278 278
             print " - Error in create contact result code = ".$ret1." ".$ret2." - ".$object->errorsToString();
279 279
             $errorrecord++;
280 280
         }
281
-    	else
282
-    	{
283
-    	    print " - create contact OK";
284
-    	}
285
-	}
281
+        else
282
+        {
283
+            print " - create contact OK";
284
+        }
285
+    }
286 286
 
287 287
 
288
-	print "\n";
288
+    print "\n";
289 289
 
290
-	if ($errorrecord)
291
-	{
292
-	    fwrite($fhandleerr, 'Error on record nb '.$i." - ".$object->errorsToString()."\n");
293
-	    $error++;    // $errorrecord will be reset
294
-	}
290
+    if ($errorrecord)
291
+    {
292
+        fwrite($fhandleerr, 'Error on record nb '.$i." - ".$object->errorsToString()."\n");
293
+        $error++;    // $errorrecord will be reset
294
+    }
295 295
 }
296 296
 
297 297
 
Please login to merge, or discard this patch.
Spacing   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -28,27 +28,27 @@  discard block
 block discarded – undo
28 28
 // Test si mode batch
29 29
 $sapi_type = php_sapi_name();
30 30
 $script_file = basename(__FILE__);
31
-$path=dirname(__FILE__).'/';
31
+$path = dirname(__FILE__).'/';
32 32
 if (substr($sapi_type, 0, 3) == 'cgi') {
33 33
     echo "Erreur: Vous utilisez l'interpreteur PHP pour le mode CGI. Pour executer mailing-send.php en ligne de commande, vous devez utiliser l'interpreteur PHP pour le mode CLI.\n";
34 34
     exit;
35 35
 }
36 36
 
37 37
 // Recupere root dolibarr
38
-$path=preg_replace('/import-thirdparties.php/i','',$_SERVER["PHP_SELF"]);
38
+$path = preg_replace('/import-thirdparties.php/i', '', $_SERVER["PHP_SELF"]);
39 39
 require $path."../../htdocs/master.inc.php";
40 40
 include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
41 41
 include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
42 42
 
43
-$delimiter=',';
44
-$enclosure='"';
45
-$linelength=10000;
46
-$escape='/';
43
+$delimiter = ',';
44
+$enclosure = '"';
45
+$linelength = 10000;
46
+$escape = '/';
47 47
 
48 48
 // Global variables
49
-$version=DOL_VERSION;
50
-$confirmed=1;
51
-$error=0;
49
+$version = DOL_VERSION;
50
+$confirmed = 1;
51
+$error = 0;
52 52
 
53 53
 
54 54
 /*
@@ -57,29 +57,29 @@  discard block
 block discarded – undo
57 57
 
58 58
 @set_time_limit(0);
59 59
 print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
60
-dol_syslog($script_file." launched with arg ".implode(',',$argv));
60
+dol_syslog($script_file." launched with arg ".implode(',', $argv));
61 61
 
62 62
 $mode = $argv[1];
63 63
 $filepath = $argv[2];
64 64
 $filepatherr = $filepath.'.err';
65 65
 //$defaultlang = empty($argv[3])?'en_US':$argv[3];
66
-$startlinenb = empty($argv[3])?1:$argv[3];
67
-$endlinenb = empty($argv[4])?0:$argv[4];
66
+$startlinenb = empty($argv[3]) ? 1 : $argv[3];
67
+$endlinenb = empty($argv[4]) ? 0 : $argv[4];
68 68
 
69
-if (empty($mode) || ! in_array($mode,array('test','confirm','confirmforced')) || empty($filepath)) {
69
+if (empty($mode) || !in_array($mode, array('test', 'confirm', 'confirmforced')) || empty($filepath)) {
70 70
     print "Usage:  $script_file (test|confirm|confirmforced) filepath.csv [startlinenb] [endlinenb]\n";
71 71
     print "Usage:  $script_file test myfilepath.csv 2 1002\n";
72 72
     print "\n";
73 73
     exit(-1);
74 74
 }
75
-if (! file_exists($filepath)) {
75
+if (!file_exists($filepath)) {
76 76
     print "Error: File ".$filepath." not found.\n";
77 77
     print "\n";
78 78
     exit(-1);
79 79
 }
80 80
 
81
-$ret=$user->fetch('','admin');
82
-if (! $ret > 0)
81
+$ret = $user->fetch('', 'admin');
82
+if (!$ret > 0)
83 83
 {
84 84
 	print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
85 85
 	exit;
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 $user->getrights();
88 88
 
89 89
 // Ask confirmation
90
-if (! $confirmed)
90
+if (!$confirmed)
91 91
 {
92 92
     print "Hit Enter to continue or CTRL+C to stop...\n";
93 93
     $input = trim(fgets(STDIN));
@@ -95,13 +95,13 @@  discard block
 block discarded – undo
95 95
 
96 96
 // Open input and ouput files
97 97
 $fhandle = fopen($filepath, 'r');
98
-if (! $fhandle)
98
+if (!$fhandle)
99 99
 {
100 100
     print 'Error: Failed to open file '.$filepath."\n";
101 101
     exit(1);
102 102
 }
103 103
 $fhandleerr = fopen($filepatherr, 'w');
104
-if (! $fhandleerr)
104
+if (!$fhandleerr)
105 105
 {
106 106
     print 'Error: Failed to open file '.$filepatherr."\n";
107 107
     exit(1);
@@ -112,12 +112,12 @@  discard block
 block discarded – undo
112 112
 
113 113
 $db->begin();
114 114
 
115
-$i=0;
116
-$nboflines=0;
117
-while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape))
115
+$i = 0;
116
+$nboflines = 0;
117
+while ($fields = fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape))
118 118
 {
119 119
     $i++;
120
-    $errorrecord=0;
120
+    $errorrecord = 0;
121 121
 
122 122
     if ($startlinenb && $i < $startlinenb) continue;
123 123
     if ($endlinenb && $i > $endlinenb) continue;
@@ -129,8 +129,8 @@  discard block
 block discarded – undo
129 129
     $object->client = $fields[7];
130 130
     $object->fournisseur = $fields[8];
131 131
 
132
-    $object->name = $fields[13]?trim($fields[13]):$fields[0];
133
-    $object->name_alias = $fields[0]!=$fields[13]?trim($fields[0]):'';
132
+    $object->name = $fields[13] ?trim($fields[13]) : $fields[0];
133
+    $object->name_alias = $fields[0] != $fields[13] ?trim($fields[0]) : '';
134 134
 
135 135
     $object->address = trim($fields[14]);
136 136
     $object->zip = trim($fields[15]);
@@ -171,12 +171,12 @@  discard block
 block discarded – undo
171 171
 
172 172
 
173 173
     // Extrafields
174
-    $object->array_options['options_anastate']=price2num($fields[20]);
175
-    $object->array_options['options_anaregion']=price2num($fields[17]);
174
+    $object->array_options['options_anastate'] = price2num($fields[20]);
175
+    $object->array_options['options_anaregion'] = price2num($fields[17]);
176 176
 
177
-    if (! $errorrecord)
177
+    if (!$errorrecord)
178 178
     {
179
-        $ret=$object->create($user);
179
+        $ret = $object->create($user);
180 180
         if ($ret < 0)
181 181
         {
182 182
             print " - Error in create result code = ".$ret." - ".$object->errorsToString();
@@ -188,24 +188,24 @@  discard block
 block discarded – undo
188 188
     	}
189 189
     }
190 190
 
191
-    if (! $errorrecord)
191
+    if (!$errorrecord)
192 192
     {
193 193
         dol_syslog("Set price level");
194 194
 	    $object->set_price_level($object->price_level, $user);
195 195
     }
196 196
 
197 197
 	// Assign sales representative
198
-	if (! $errorrecord && $fields[3])
198
+	if (!$errorrecord && $fields[3])
199 199
 	{
200
-    	$salesrep=new User($db);
200
+    	$salesrep = new User($db);
201 201
 
202
-    	$tmp=explode(' ',$fields[3],2);
202
+    	$tmp = explode(' ', $fields[3], 2);
203 203
     	$salesrep->firstname = trim($tmp[0]);
204 204
     	$salesrep->lastname = trim($tmp[1]);
205
-    	if ($salesrep->lastname) $salesrep->login = strtolower(substr($salesrep->firstname, 0, 1)) . strtolower(substr($salesrep->lastname, 0));
206
-    	else $salesrep->login=strtolower($salesrep->firstname);
207
-    	$salesrep->login=preg_replace('/ /','',$salesrep->login);
208
-    	$salesrep->fetch(0,$salesrep->login);
205
+    	if ($salesrep->lastname) $salesrep->login = strtolower(substr($salesrep->firstname, 0, 1)).strtolower(substr($salesrep->lastname, 0));
206
+    	else $salesrep->login = strtolower($salesrep->firstname);
207
+    	$salesrep->login = preg_replace('/ /', '', $salesrep->login);
208
+    	$salesrep->fetch(0, $salesrep->login);
209 209
 
210 210
     	$result = $object->add_commercial($user, $salesrep->id);
211 211
     	if ($result < 0)
@@ -221,20 +221,20 @@  discard block
 block discarded – undo
221 221
 
222 222
 	dol_syslog("Add invoice contacts");
223 223
 	// Insert an invoice contact if there is an invoice email != standard email
224
-	if (! $errorrecord && $fields[27] && $fields[26] != $fields[27])
224
+	if (!$errorrecord && $fields[27] && $fields[26] != $fields[27])
225 225
 	{
226
-	    $ret1=$ret2=0;
226
+	    $ret1 = $ret2 = 0;
227 227
 
228 228
 	    $contact = new Contact($db);
229 229
 	    $contact->lastname = $object->name;
230
-	    $contact->address=$object->address;
231
-	    $contact->zip=$object->zip;
232
-	    $contact->town=$object->town;
233
-	    $contact->country_id=$object->country_id;
234
-	    $contact->email=$fields[27];
235
-	    $contact->socid=$object->id;
236
-
237
-	    $ret1=$contact->create($user);
230
+	    $contact->address = $object->address;
231
+	    $contact->zip = $object->zip;
232
+	    $contact->town = $object->town;
233
+	    $contact->country_id = $object->country_id;
234
+	    $contact->email = $fields[27];
235
+	    $contact->socid = $object->id;
236
+
237
+	    $ret1 = $contact->create($user);
238 238
 	    if ($ret1 > 0)
239 239
 	    {
240 240
 	        //$ret2=$contact->add_contact($object->id, 'BILLING');
@@ -252,23 +252,23 @@  discard block
 block discarded – undo
252 252
 
253 253
 	dol_syslog("Add delivery contacts");
254 254
 	// Insert a delivery contact
255
-	if (! $errorrecord && $fields[47])
255
+	if (!$errorrecord && $fields[47])
256 256
 	{
257
-	    $ret1=$ret2=0;
257
+	    $ret1 = $ret2 = 0;
258 258
 
259 259
 	    $contact2 = new Contact($db);
260 260
 	    $contact2->lastname = 'Service livraison - '.$fields[47];
261 261
 	    $contact2->address = $fields[48];
262 262
 	    $contact2->zip = $fields[50];
263 263
 	    $contact2->town = $fields[51];
264
-	    $contact2->country_id=dol_getIdFromCode($db, trim($fields[52]), 'c_country', 'code', 'rowid');
265
-	    $contact2->note_public=$fields[54];
266
-	    $contact2->socid=$object->id;
264
+	    $contact2->country_id = dol_getIdFromCode($db, trim($fields[52]), 'c_country', 'code', 'rowid');
265
+	    $contact2->note_public = $fields[54];
266
+	    $contact2->socid = $object->id;
267 267
 
268 268
 	    // Extrafields
269
-	    $contact2->array_options['options_anazoneliv']=price2num($fields[53]);
269
+	    $contact2->array_options['options_anazoneliv'] = price2num($fields[53]);
270 270
 
271
-	    $ret1=$contact2->create($user);
271
+	    $ret1 = $contact2->create($user);
272 272
 	    if ($ret1 > 0)
273 273
 	    {
274 274
 	        //$ret2=$contact2->add_contact($object->id, 'SHIPPING');
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
 	if ($errorrecord)
291 291
 	{
292 292
 	    fwrite($fhandleerr, 'Error on record nb '.$i." - ".$object->errorsToString()."\n");
293
-	    $error++;    // $errorrecord will be reset
293
+	    $error++; // $errorrecord will be reset
294 294
 	}
295 295
 }
296 296
 
Please login to merge, or discard this patch.
Braces   +25 added lines, -17 removed lines patch added patch discarded remove patch
@@ -119,8 +119,12 @@  discard block
 block discarded – undo
119 119
     $i++;
120 120
     $errorrecord=0;
121 121
 
122
-    if ($startlinenb && $i < $startlinenb) continue;
123
-    if ($endlinenb && $i > $endlinenb) continue;
122
+    if ($startlinenb && $i < $startlinenb) {
123
+        continue;
124
+    }
125
+    if ($endlinenb && $i > $endlinenb) {
126
+        continue;
127
+    }
124 128
 
125 129
     $nboflines++;
126 130
 
@@ -147,8 +151,12 @@  discard block
 block discarded – undo
147 151
     if ($fields[36])
148 152
     {
149 153
         $condpayment = trim($fields[36]);
150
-        if ($condpayment == 'A la commande') $condpayment = 'A réception de commande';
151
-        if ($condpayment == 'A reception facture') $condpayment = 'Réception de facture';
154
+        if ($condpayment == 'A la commande') {
155
+            $condpayment = 'A réception de commande';
156
+        }
157
+        if ($condpayment == 'A reception facture') {
158
+            $condpayment = 'Réception de facture';
159
+        }
152 160
         $object->cond_reglement_id = dol_getIdFromCode($db, $condpayment, 'c_payment_term', 'libelle_facture', 'rowid', 1);
153 161
         if (empty($object->cond_reglement_id))
154 162
         {
@@ -165,7 +173,9 @@  discard block
 block discarded – undo
165 173
 
166 174
     // Set price level
167 175
     $object->price_level = 1;
168
-    if ($labeltype == 'Revendeur') $object->price_level = 2;
176
+    if ($labeltype == 'Revendeur') {
177
+        $object->price_level = 2;
178
+    }
169 179
 
170 180
     print "Process line nb ".$i.", name ".$object->name;
171 181
 
@@ -181,8 +191,7 @@  discard block
 block discarded – undo
181 191
         {
182 192
             print " - Error in create result code = ".$ret." - ".$object->errorsToString();
183 193
             $errorrecord++;
184
-        }
185
-    	else
194
+        } else
186 195
     	{
187 196
     	    print " - Creation OK with name ".$object->name." - id = ".$ret;
188 197
     	}
@@ -202,8 +211,11 @@  discard block
 block discarded – undo
202 211
     	$tmp=explode(' ',$fields[3],2);
203 212
     	$salesrep->firstname = trim($tmp[0]);
204 213
     	$salesrep->lastname = trim($tmp[1]);
205
-    	if ($salesrep->lastname) $salesrep->login = strtolower(substr($salesrep->firstname, 0, 1)) . strtolower(substr($salesrep->lastname, 0));
206
-    	else $salesrep->login=strtolower($salesrep->firstname);
214
+    	if ($salesrep->lastname) {
215
+    	    $salesrep->login = strtolower(substr($salesrep->firstname, 0, 1)) . strtolower(substr($salesrep->lastname, 0));
216
+    	} else {
217
+    	    $salesrep->login=strtolower($salesrep->firstname);
218
+    	}
207 219
     	$salesrep->login=preg_replace('/ /','',$salesrep->login);
208 220
     	$salesrep->fetch(0,$salesrep->login);
209 221
 
@@ -212,8 +224,7 @@  discard block
 block discarded – undo
212 224
     	{
213 225
     	    print " - Error in create link with sale representative result code = ".$result." - ".$object->errorsToString();
214 226
     	    $errorrecord++;
215
-    	}
216
-    	else
227
+    	} else
217 228
     	{
218 229
     	    print " - create link sale representative OK";
219 230
     	}
@@ -243,8 +254,7 @@  discard block
 block discarded – undo
243 254
         {
244 255
             print " - Error in create contact result code = ".$ret1." ".$ret2." - ".$object->errorsToString();
245 256
             $errorrecord++;
246
-        }
247
-    	else
257
+        } else
248 258
     	{
249 259
     	    print " - create contact OK";
250 260
     	}
@@ -277,8 +287,7 @@  discard block
 block discarded – undo
277 287
         {
278 288
             print " - Error in create contact result code = ".$ret1." ".$ret2." - ".$object->errorsToString();
279 289
             $errorrecord++;
280
-        }
281
-    	else
290
+        } else
282 291
     	{
283 292
     	    print " - create contact OK";
284 293
     	}
@@ -305,8 +314,7 @@  discard block
 block discarded – undo
305 314
 {
306 315
     print "Rollback any changes.\n";
307 316
     $db->rollback();
308
-}
309
-else
317
+} else
310 318
 {
311 319
     print "Commit all changes.\n";
312 320
     $db->commit();
Please login to merge, or discard this patch.
dolibarr/dev/initdata/import-users.php 3 patches
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -81,8 +81,8 @@  discard block
 block discarded – undo
81 81
 $ret=$user->fetch('','admin');
82 82
 if (! $ret > 0)
83 83
 {
84
-	print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
85
-	exit;
84
+    print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
85
+    exit;
86 86
 }
87 87
 $user->getrights();
88 88
 
@@ -143,18 +143,18 @@  discard block
 block discarded – undo
143 143
         print " - Error in create result code = ".$ret." - ".$object->errorsToString();
144 144
         $errorrecord++;
145 145
     }
146
-	else
147
-	{
148
-	    print " - Creation OK with login ".$object->login." - id = ".$ret;
149
-	}
150
-
151
-	print "\n";
152
-
153
-	if ($errorrecord)
154
-	{
155
-	    fwrite($fhandleerr, 'Error on record nb '.$i." - ".$object->errorsToString()."\n");
156
-	    $error++;    // $errorrecord will be reset
157
-	}
146
+    else
147
+    {
148
+        print " - Creation OK with login ".$object->login." - id = ".$ret;
149
+    }
150
+
151
+    print "\n";
152
+
153
+    if ($errorrecord)
154
+    {
155
+        fwrite($fhandleerr, 'Error on record nb '.$i." - ".$object->errorsToString()."\n");
156
+        $error++;    // $errorrecord will be reset
157
+    }
158 158
 }
159 159
 
160 160
 
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -28,27 +28,27 @@  discard block
 block discarded – undo
28 28
 // Test si mode batch
29 29
 $sapi_type = php_sapi_name();
30 30
 $script_file = basename(__FILE__);
31
-$path=dirname(__FILE__).'/';
31
+$path = dirname(__FILE__).'/';
32 32
 if (substr($sapi_type, 0, 3) == 'cgi') {
33 33
     echo "Erreur: Vous utilisez l'interpreteur PHP pour le mode CGI. Pour executer mailing-send.php en ligne de commande, vous devez utiliser l'interpreteur PHP pour le mode CLI.\n";
34 34
     exit;
35 35
 }
36 36
 
37 37
 // Recupere root dolibarr
38
-$path=preg_replace('/import-users.php/i','',$_SERVER["PHP_SELF"]);
38
+$path = preg_replace('/import-users.php/i', '', $_SERVER["PHP_SELF"]);
39 39
 require $path."../../htdocs/master.inc.php";
40 40
 include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
41 41
 include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
42 42
 
43
-$delimiter=',';
44
-$enclosure='"';
45
-$linelength=10000;
46
-$escape='/';
43
+$delimiter = ',';
44
+$enclosure = '"';
45
+$linelength = 10000;
46
+$escape = '/';
47 47
 
48 48
 // Global variables
49
-$version=DOL_VERSION;
50
-$confirmed=1;
51
-$error=0;
49
+$version = DOL_VERSION;
50
+$confirmed = 1;
51
+$error = 0;
52 52
 
53 53
 
54 54
 /*
@@ -57,29 +57,29 @@  discard block
 block discarded – undo
57 57
 
58 58
 @set_time_limit(0);
59 59
 print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
60
-dol_syslog($script_file." launched with arg ".implode(',',$argv));
60
+dol_syslog($script_file." launched with arg ".implode(',', $argv));
61 61
 
62 62
 $mode = $argv[1];
63 63
 $filepath = $argv[2];
64 64
 $filepatherr = $filepath.'.err';
65 65
 //$defaultlang = empty($argv[3])?'en_US':$argv[3];
66
-$startlinenb = empty($argv[3])?1:$argv[3];
67
-$endlinenb = empty($argv[4])?0:$argv[4];
66
+$startlinenb = empty($argv[3]) ? 1 : $argv[3];
67
+$endlinenb = empty($argv[4]) ? 0 : $argv[4];
68 68
 
69
-if (empty($mode) || ! in_array($mode,array('test','confirm','confirmforced')) || empty($filepath)) {
69
+if (empty($mode) || !in_array($mode, array('test', 'confirm', 'confirmforced')) || empty($filepath)) {
70 70
     print "Usage:  $script_file (test|confirm|confirmforced) filepath.csv [startlinenb] [endlinenb]\n";
71 71
     print "Usage:  $script_file test myfilepath.csv 2 1002\n";
72 72
     print "\n";
73 73
     exit(-1);
74 74
 }
75
-if (! file_exists($filepath)) {
75
+if (!file_exists($filepath)) {
76 76
     print "Error: File ".$filepath." not found.\n";
77 77
     print "\n";
78 78
     exit(-1);
79 79
 }
80 80
 
81
-$ret=$user->fetch('','admin');
82
-if (! $ret > 0)
81
+$ret = $user->fetch('', 'admin');
82
+if (!$ret > 0)
83 83
 {
84 84
 	print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
85 85
 	exit;
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 $user->getrights();
88 88
 
89 89
 // Ask confirmation
90
-if (! $confirmed)
90
+if (!$confirmed)
91 91
 {
92 92
     print "Hit Enter to continue or CTRL+C to stop...\n";
93 93
     $input = trim(fgets(STDIN));
@@ -95,13 +95,13 @@  discard block
 block discarded – undo
95 95
 
96 96
 // Open input and ouput files
97 97
 $fhandle = fopen($filepath, 'r');
98
-if (! $fhandle)
98
+if (!$fhandle)
99 99
 {
100 100
     print 'Error: Failed to open file '.$filepath."\n";
101 101
     exit(1);
102 102
 }
103 103
 $fhandleerr = fopen($filepatherr, 'w');
104
-if (! $fhandleerr)
104
+if (!$fhandleerr)
105 105
 {
106 106
     print 'Error: Failed to open file '.$filepatherr."\n";
107 107
     exit(1);
@@ -112,12 +112,12 @@  discard block
 block discarded – undo
112 112
 
113 113
 $db->begin();
114 114
 
115
-$i=0;
116
-$nboflines=0;
117
-while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape))
115
+$i = 0;
116
+$nboflines = 0;
117
+while ($fields = fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape))
118 118
 {
119 119
     $i++;
120
-    $errorrecord=0;
120
+    $errorrecord = 0;
121 121
 
122 122
     if ($startlinenb && $i < $startlinenb) continue;
123 123
     if ($endlinenb && $i > $endlinenb) continue;
@@ -127,17 +127,17 @@  discard block
 block discarded – undo
127 127
     $object = new User($db);
128 128
     $object->statut = 1;
129 129
 
130
-    $tmp=explode(' ',$fields[3],2);
130
+    $tmp = explode(' ', $fields[3], 2);
131 131
     $object->firstname = trim($tmp[0]);
132 132
     $object->lastname = trim($tmp[1]);
133
-    if ($object->lastname) $object->login = strtolower(substr($object->firstname, 0, 1)) . strtolower(substr($object->lastname, 0));
134
-    else $object->login=strtolower($object->firstname);
135
-    $object->login=preg_replace('/ /','',$object->login);
133
+    if ($object->lastname) $object->login = strtolower(substr($object->firstname, 0, 1)).strtolower(substr($object->lastname, 0));
134
+    else $object->login = strtolower($object->firstname);
135
+    $object->login = preg_replace('/ /', '', $object->login);
136 136
     $object->password = 'init';
137 137
 
138 138
     print "Process line nb ".$i.", login ".$object->login;
139 139
 
140
-    $ret=$object->create($user);
140
+    $ret = $object->create($user);
141 141
     if ($ret < 0)
142 142
     {
143 143
         print " - Error in create result code = ".$ret." - ".$object->errorsToString();
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 	if ($errorrecord)
154 154
 	{
155 155
 	    fwrite($fhandleerr, 'Error on record nb '.$i." - ".$object->errorsToString()."\n");
156
-	    $error++;    // $errorrecord will be reset
156
+	    $error++; // $errorrecord will be reset
157 157
 	}
158 158
 }
159 159
 
Please login to merge, or discard this patch.
Braces   +13 added lines, -8 removed lines patch added patch discarded remove patch
@@ -119,8 +119,12 @@  discard block
 block discarded – undo
119 119
     $i++;
120 120
     $errorrecord=0;
121 121
 
122
-    if ($startlinenb && $i < $startlinenb) continue;
123
-    if ($endlinenb && $i > $endlinenb) continue;
122
+    if ($startlinenb && $i < $startlinenb) {
123
+        continue;
124
+    }
125
+    if ($endlinenb && $i > $endlinenb) {
126
+        continue;
127
+    }
124 128
 
125 129
     $nboflines++;
126 130
 
@@ -130,8 +134,11 @@  discard block
 block discarded – undo
130 134
     $tmp=explode(' ',$fields[3],2);
131 135
     $object->firstname = trim($tmp[0]);
132 136
     $object->lastname = trim($tmp[1]);
133
-    if ($object->lastname) $object->login = strtolower(substr($object->firstname, 0, 1)) . strtolower(substr($object->lastname, 0));
134
-    else $object->login=strtolower($object->firstname);
137
+    if ($object->lastname) {
138
+        $object->login = strtolower(substr($object->firstname, 0, 1)) . strtolower(substr($object->lastname, 0));
139
+    } else {
140
+        $object->login=strtolower($object->firstname);
141
+    }
135 142
     $object->login=preg_replace('/ /','',$object->login);
136 143
     $object->password = 'init';
137 144
 
@@ -142,8 +149,7 @@  discard block
 block discarded – undo
142 149
     {
143 150
         print " - Error in create result code = ".$ret." - ".$object->errorsToString();
144 151
         $errorrecord++;
145
-    }
146
-	else
152
+    } else
147 153
 	{
148 154
 	    print " - Creation OK with login ".$object->login." - id = ".$ret;
149 155
 	}
@@ -168,8 +174,7 @@  discard block
 block discarded – undo
168 174
 {
169 175
     print "Rollback any changes.\n";
170 176
     $db->rollback();
171
-}
172
-else
177
+} else
173 178
 {
174 179
     print "Commit all changes.\n";
175 180
     $db->commit();
Please login to merge, or discard this patch.
dolibarr/dev/initdata/import-products.php 3 patches
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -81,8 +81,8 @@  discard block
 block discarded – undo
81 81
 $ret=$user->fetch('','admin');
82 82
 if (! $ret > 0)
83 83
 {
84
-	print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
85
-	exit;
84
+    print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
85
+    exit;
86 86
 }
87 87
 $user->getrights();
88 88
 
@@ -164,56 +164,56 @@  discard block
 block discarded – undo
164 164
         print " - Error in create result code = ".$ret." - ".$produit->errorsToString();
165 165
         $errorrecord++;
166 166
     }
167
-	else
168
-	{
169
-	    print " - Creation OK with ref ".$produit->ref." - id = ".$ret;
170
-	}
167
+    else
168
+    {
169
+        print " - Creation OK with ref ".$produit->ref." - id = ".$ret;
170
+    }
171 171
 
172
-	dol_syslog("Add prices");
172
+    dol_syslog("Add prices");
173 173
 
174 174
     // If we use price level, insert price for each level
175
-	if (! $errorrecord && 1)
176
-	{
177
-	    $ret1=$produit->updatePrice($produit->price_ttc, $produit->price_base_type, $user, $produit->tva_tx, $produit->price_min, 1, $produit->tva_npr, 0, 0, array());
178
-	    $ret2=$produit->updatePrice(price2num($fields[14]), 'HT', $user, $produit->tva_tx, $produit->price_min, 2, $produit->tva_npr, 0, 0, array());
179
-	    if ($ret1 < 0 || $ret2 < 0)
175
+    if (! $errorrecord && 1)
176
+    {
177
+        $ret1=$produit->updatePrice($produit->price_ttc, $produit->price_base_type, $user, $produit->tva_tx, $produit->price_min, 1, $produit->tva_npr, 0, 0, array());
178
+        $ret2=$produit->updatePrice(price2num($fields[14]), 'HT', $user, $produit->tva_tx, $produit->price_min, 2, $produit->tva_npr, 0, 0, array());
179
+        if ($ret1 < 0 || $ret2 < 0)
180 180
         {
181 181
             print " - Error in updatePrice result code = ".$ret1." ".$ret2." - ".$produit->errorsToString();
182 182
             $errorrecord++;
183 183
         }
184
-    	else
185
-    	{
186
-    	    print " - updatePrice OK";
187
-    	}
188
-	}
184
+        else
185
+        {
186
+            print " - updatePrice OK";
187
+        }
188
+    }
189 189
 
190
-	dol_syslog("Add multilangs");
190
+    dol_syslog("Add multilangs");
191 191
 
192
-	// Add alternative languages
193
-	if (! $errorrecord && 1)
194
-	{
195
-    	$produit->multilangs['fr_FR']=array('label'=>$produit->label, 'description'=>$produit->description, 'note'=>$produit->note_private);
196
-	    $produit->multilangs['en_US']=array('label'=>$fields[3], 'description'=>$produit->description, 'note'=>$produit->note_private);
192
+    // Add alternative languages
193
+    if (! $errorrecord && 1)
194
+    {
195
+        $produit->multilangs['fr_FR']=array('label'=>$produit->label, 'description'=>$produit->description, 'note'=>$produit->note_private);
196
+        $produit->multilangs['en_US']=array('label'=>$fields[3], 'description'=>$produit->description, 'note'=>$produit->note_private);
197 197
 
198
-    	$ret=$produit->setMultiLangs($user);
198
+        $ret=$produit->setMultiLangs($user);
199 199
         if ($ret < 0)
200 200
         {
201 201
             print " - Error in setMultiLangs result code = ".$ret." - ".$produit->errorsToString();
202 202
             $errorrecord++;
203 203
         }
204
-    	else
205
-    	{
206
-    	    print " - setMultiLangs OK";
207
-    	}
208
-	}
209
-
210
-	print "\n";
211
-
212
-	if ($errorrecord)
213
-	{
214
-	    fwrite($fhandleerr, 'Error on record nb '.$i." - ".$produit->errorsToString()."\n");
215
-	    $error++;    // $errorrecord will be reset
216
-	}
204
+        else
205
+        {
206
+            print " - setMultiLangs OK";
207
+        }
208
+    }
209
+
210
+    print "\n";
211
+
212
+    if ($errorrecord)
213
+    {
214
+        fwrite($fhandleerr, 'Error on record nb '.$i." - ".$produit->errorsToString()."\n");
215
+        $error++;    // $errorrecord will be reset
216
+    }
217 217
 }
218 218
 
219 219
 
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -28,27 +28,27 @@  discard block
 block discarded – undo
28 28
 // Test si mode batch
29 29
 $sapi_type = php_sapi_name();
30 30
 $script_file = basename(__FILE__);
31
-$path=dirname(__FILE__).'/';
31
+$path = dirname(__FILE__).'/';
32 32
 if (substr($sapi_type, 0, 3) == 'cgi') {
33 33
     echo "Erreur: Vous utilisez l'interpreteur PHP pour le mode CGI. Pour executer mailing-send.php en ligne de commande, vous devez utiliser l'interpreteur PHP pour le mode CLI.\n";
34 34
     exit;
35 35
 }
36 36
 
37 37
 // Recupere root dolibarr
38
-$path=preg_replace('/import-products.php/i','',$_SERVER["PHP_SELF"]);
38
+$path = preg_replace('/import-products.php/i', '', $_SERVER["PHP_SELF"]);
39 39
 require $path."../../htdocs/master.inc.php";
40 40
 include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
41 41
 include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
42 42
 
43
-$delimiter=',';
44
-$enclosure='"';
45
-$linelength=10000;
46
-$escape='/';
43
+$delimiter = ',';
44
+$enclosure = '"';
45
+$linelength = 10000;
46
+$escape = '/';
47 47
 
48 48
 // Global variables
49
-$version=DOL_VERSION;
50
-$confirmed=1;
51
-$error=0;
49
+$version = DOL_VERSION;
50
+$confirmed = 1;
51
+$error = 0;
52 52
 
53 53
 
54 54
 /*
@@ -57,29 +57,29 @@  discard block
 block discarded – undo
57 57
 
58 58
 @set_time_limit(0);
59 59
 print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
60
-dol_syslog($script_file." launched with arg ".implode(',',$argv));
60
+dol_syslog($script_file." launched with arg ".implode(',', $argv));
61 61
 
62 62
 $mode = $argv[1];
63 63
 $filepath = $argv[2];
64 64
 $filepatherr = $filepath.'.err';
65
-$defaultlang = empty($argv[3])?'en_US':$argv[3];
66
-$startlinenb = empty($argv[4])?1:$argv[4];
67
-$endlinenb = empty($argv[5])?0:$argv[5];
65
+$defaultlang = empty($argv[3]) ? 'en_US' : $argv[3];
66
+$startlinenb = empty($argv[4]) ? 1 : $argv[4];
67
+$endlinenb = empty($argv[5]) ? 0 : $argv[5];
68 68
 
69
-if (empty($mode) || ! in_array($mode,array('test','confirm','confirmforced')) || empty($filepath)) {
69
+if (empty($mode) || !in_array($mode, array('test', 'confirm', 'confirmforced')) || empty($filepath)) {
70 70
     print "Usage:  $script_file (test|confirm|confirmforced) filepath.csv [defaultlang] [startlinenb] [endlinenb]\n";
71 71
     print "Usage:  $script_file test myfilepath.csv fr_FR 2 1002\n";
72 72
     print "\n";
73 73
     exit(-1);
74 74
 }
75
-if (! file_exists($filepath)) {
75
+if (!file_exists($filepath)) {
76 76
     print "Error: File ".$filepath." not found.\n";
77 77
     print "\n";
78 78
     exit(-1);
79 79
 }
80 80
 
81
-$ret=$user->fetch('','admin');
82
-if (! $ret > 0)
81
+$ret = $user->fetch('', 'admin');
82
+if (!$ret > 0)
83 83
 {
84 84
 	print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
85 85
 	exit;
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 $user->getrights();
88 88
 
89 89
 // Ask confirmation
90
-if (! $confirmed)
90
+if (!$confirmed)
91 91
 {
92 92
     print "Hit Enter to continue or CTRL+C to stop...\n";
93 93
     $input = trim(fgets(STDIN));
@@ -95,13 +95,13 @@  discard block
 block discarded – undo
95 95
 
96 96
 // Open input and ouput files
97 97
 $fhandle = fopen($filepath, 'r');
98
-if (! $fhandle)
98
+if (!$fhandle)
99 99
 {
100 100
     print 'Error: Failed to open file '.$filepath."\n";
101 101
     exit(1);
102 102
 }
103 103
 $fhandleerr = fopen($filepatherr, 'w');
104
-if (! $fhandleerr)
104
+if (!$fhandleerr)
105 105
 {
106 106
     print 'Error: Failed to open file '.$filepatherr."\n";
107 107
     exit(1);
@@ -112,12 +112,12 @@  discard block
 block discarded – undo
112 112
 
113 113
 $db->begin();
114 114
 
115
-$i=0;
115
+$i = 0;
116 116
 $nboflines++;
117
-while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape))
117
+while ($fields = fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape))
118 118
 {
119 119
     $i++;
120
-    $errorrecord=0;
120
+    $errorrecord = 0;
121 121
 
122 122
     if ($startlinenb && $i < $startlinenb) continue;
123 123
     if ($endlinenb && $i > $endlinenb) continue;
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
     $produit->volume = price2num($fields[8]);
136 136
     $produit->volume_unit = 0;
137 137
     $produit->weight = price2num($fields[9]);
138
-    $produit->weight_units = 0;          // -3 = g
138
+    $produit->weight_units = 0; // -3 = g
139 139
 
140 140
     $produit->customcode = $fields[10];
141 141
     $produit->barcode = $fields[1];
@@ -156,9 +156,9 @@  discard block
 block discarded – undo
156 156
     $produit->cost_price = price2num($fields[16]);
157 157
 
158 158
     // Extrafields
159
-    $produit->array_options['options_ecotaxdeee']=price2num($fields[17]);
159
+    $produit->array_options['options_ecotaxdeee'] = price2num($fields[17]);
160 160
 
161
-    $ret=$produit->create($user);
161
+    $ret = $produit->create($user);
162 162
     if ($ret < 0)
163 163
     {
164 164
         print " - Error in create result code = ".$ret." - ".$produit->errorsToString();
@@ -172,10 +172,10 @@  discard block
 block discarded – undo
172 172
 	dol_syslog("Add prices");
173 173
 
174 174
     // If we use price level, insert price for each level
175
-	if (! $errorrecord && 1)
175
+	if (!$errorrecord && 1)
176 176
 	{
177
-	    $ret1=$produit->updatePrice($produit->price_ttc, $produit->price_base_type, $user, $produit->tva_tx, $produit->price_min, 1, $produit->tva_npr, 0, 0, array());
178
-	    $ret2=$produit->updatePrice(price2num($fields[14]), 'HT', $user, $produit->tva_tx, $produit->price_min, 2, $produit->tva_npr, 0, 0, array());
177
+	    $ret1 = $produit->updatePrice($produit->price_ttc, $produit->price_base_type, $user, $produit->tva_tx, $produit->price_min, 1, $produit->tva_npr, 0, 0, array());
178
+	    $ret2 = $produit->updatePrice(price2num($fields[14]), 'HT', $user, $produit->tva_tx, $produit->price_min, 2, $produit->tva_npr, 0, 0, array());
179 179
 	    if ($ret1 < 0 || $ret2 < 0)
180 180
         {
181 181
             print " - Error in updatePrice result code = ".$ret1." ".$ret2." - ".$produit->errorsToString();
@@ -190,12 +190,12 @@  discard block
 block discarded – undo
190 190
 	dol_syslog("Add multilangs");
191 191
 
192 192
 	// Add alternative languages
193
-	if (! $errorrecord && 1)
193
+	if (!$errorrecord && 1)
194 194
 	{
195
-    	$produit->multilangs['fr_FR']=array('label'=>$produit->label, 'description'=>$produit->description, 'note'=>$produit->note_private);
196
-	    $produit->multilangs['en_US']=array('label'=>$fields[3], 'description'=>$produit->description, 'note'=>$produit->note_private);
195
+    	$produit->multilangs['fr_FR'] = array('label'=>$produit->label, 'description'=>$produit->description, 'note'=>$produit->note_private);
196
+	    $produit->multilangs['en_US'] = array('label'=>$fields[3], 'description'=>$produit->description, 'note'=>$produit->note_private);
197 197
 
198
-    	$ret=$produit->setMultiLangs($user);
198
+    	$ret = $produit->setMultiLangs($user);
199 199
         if ($ret < 0)
200 200
         {
201 201
             print " - Error in setMultiLangs result code = ".$ret." - ".$produit->errorsToString();
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
 	if ($errorrecord)
213 213
 	{
214 214
 	    fwrite($fhandleerr, 'Error on record nb '.$i." - ".$produit->errorsToString()."\n");
215
-	    $error++;    // $errorrecord will be reset
215
+	    $error++; // $errorrecord will be reset
216 216
 	}
217 217
 }
218 218
 
Please login to merge, or discard this patch.
Braces   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -119,8 +119,12 @@  discard block
 block discarded – undo
119 119
     $i++;
120 120
     $errorrecord=0;
121 121
 
122
-    if ($startlinenb && $i < $startlinenb) continue;
123
-    if ($endlinenb && $i > $endlinenb) continue;
122
+    if ($startlinenb && $i < $startlinenb) {
123
+        continue;
124
+    }
125
+    if ($endlinenb && $i > $endlinenb) {
126
+        continue;
127
+    }
124 128
 
125 129
     $nboflines++;
126 130
 
@@ -163,8 +167,7 @@  discard block
 block discarded – undo
163 167
     {
164 168
         print " - Error in create result code = ".$ret." - ".$produit->errorsToString();
165 169
         $errorrecord++;
166
-    }
167
-	else
170
+    } else
168 171
 	{
169 172
 	    print " - Creation OK with ref ".$produit->ref." - id = ".$ret;
170 173
 	}
@@ -180,8 +183,7 @@  discard block
 block discarded – undo
180 183
         {
181 184
             print " - Error in updatePrice result code = ".$ret1." ".$ret2." - ".$produit->errorsToString();
182 185
             $errorrecord++;
183
-        }
184
-    	else
186
+        } else
185 187
     	{
186 188
     	    print " - updatePrice OK";
187 189
     	}
@@ -200,8 +202,7 @@  discard block
 block discarded – undo
200 202
         {
201 203
             print " - Error in setMultiLangs result code = ".$ret." - ".$produit->errorsToString();
202 204
             $errorrecord++;
203
-        }
204
-    	else
205
+        } else
205 206
     	{
206 207
     	    print " - setMultiLangs OK";
207 208
     	}
@@ -227,8 +228,7 @@  discard block
 block discarded – undo
227 228
 {
228 229
     print "Rollback any changes.\n";
229 230
     $db->rollback();
230
-}
231
-else
231
+} else
232 232
 {
233 233
     print "Commit all changes.\n";
234 234
     $db->commit();
Please login to merge, or discard this patch.