Test Failed
Push — master ( 2740c1...0ba343 )
by Alxarafe
43:23 queued 04:12
created
dolibarr/scripts/modulebuilder/initmodule.php 3 patches
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -31,13 +31,13 @@  discard block
 block discarded – undo
31 31
 
32 32
 // Test if batch mode
33 33
 if (substr($sapi_type, 0, 3) == 'cgi') {
34
-	echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
35
-	exit(-1);
34
+    echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
35
+    exit(-1);
36 36
 }
37 37
 
38 38
 if (! isset($argv[1]) || ! $argv[1]) {
39
-	print "Usage: ".$script_file." ModuleName\n";
40
-	exit(-1);
39
+    print "Usage: ".$script_file." ModuleName\n";
40
+    exit(-1);
41 41
 }
42 42
 $modulename=$argv[1];
43 43
 
@@ -64,9 +64,9 @@  discard block
 block discarded – undo
64 64
 $tmpdir = explode('@', $module);
65 65
 if (! empty($tmpdir[1]))
66 66
 {
67
-	$module=$tmpdir[0];
68
-	$dirread=$tmpdir[1];
69
-	$forceddirread=1;
67
+    $module=$tmpdir[0];
68
+    $dirread=$tmpdir[1];
69
+    $forceddirread=1;
70 70
 }
71 71
 
72 72
 $FILEFLAG='modulebuilder.txt';
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK;
77 77
 if (empty($newmask))	// This should no happen
78 78
 {
79
-	$newmask='0664';
79
+    $newmask='0664';
80 80
 }
81 81
 
82 82
 
@@ -91,83 +91,83 @@  discard block
 block discarded – undo
91 91
 
92 92
 if (preg_match('/[^a-z0-9_]/i', $modulename))
93 93
 {
94
-	$error++;
95
-	print 'Error '.$langs->trans("SpaceOrSpecialCharAreNotAllowed")."\n";
96
-	exit(1);
94
+    $error++;
95
+    print 'Error '.$langs->trans("SpaceOrSpecialCharAreNotAllowed")."\n";
96
+    exit(1);
97 97
 }
98 98
 
99 99
 if (! $error)
100 100
 {
101
-	$srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
102
-	$destdir = $dirins.'/'.strtolower($modulename);
103
-
104
-	$arrayreplacement=array(
105
-	'mymodule'=>strtolower($modulename),
106
-	'MyModule'=>$modulename
107
-	);
108
-
109
-	$result = dolCopyDir($srcdir, $destdir, 0, 0, $arrayreplacement);
110
-	//dol_mkdir($destfile);
111
-	if ($result <= 0)
112
-	{
113
-		if ($result < 0)
114
-		{
115
-			$error++;
116
-			$langs->load("errors");
117
-			print $langs->trans("ErrorFailToCopyDir", $srcdir, $destdir)."\n";
118
-			exit(2);
119
-		}
120
-		else	// $result == 0
121
-		{
122
-			print $langs->trans("AllFilesDidAlreadyExist", $srcdir, $destdir)."\n";
123
-		}
124
-	}
125
-
126
-	// Delete some files
127
-	dol_delete_file($destdir.'/myobject_card.php');
128
-	dol_delete_file($destdir.'/myobject_note.php');
129
-	dol_delete_file($destdir.'/myobject_document.php');
130
-	dol_delete_file($destdir.'/myobject_agenda.php');
131
-	dol_delete_file($destdir.'/myobject_list.php');
132
-	dol_delete_file($destdir.'/lib/myobject.lib.php');
133
-	dol_delete_file($destdir.'/test/phpunit/MyObjectTest.php');
134
-	dol_delete_file($destdir.'/sql/llx_mymodule_myobject.sql');
135
-	dol_delete_file($destdir.'/sql/llx_mymodule_myobject_extrafields.sql');
136
-	dol_delete_file($destdir.'/sql/llx_mymodule_myobject.key.sql');
137
-	dol_delete_file($destdir.'/scripts/myobject.php');
138
-	dol_delete_file($destdir.'/img/object_myobject.png');
139
-	dol_delete_file($destdir.'/class/myobject.class.php');
140
-	dol_delete_file($destdir.'/class/api_mymodule.class.php');
101
+    $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
102
+    $destdir = $dirins.'/'.strtolower($modulename);
103
+
104
+    $arrayreplacement=array(
105
+    'mymodule'=>strtolower($modulename),
106
+    'MyModule'=>$modulename
107
+    );
108
+
109
+    $result = dolCopyDir($srcdir, $destdir, 0, 0, $arrayreplacement);
110
+    //dol_mkdir($destfile);
111
+    if ($result <= 0)
112
+    {
113
+        if ($result < 0)
114
+        {
115
+            $error++;
116
+            $langs->load("errors");
117
+            print $langs->trans("ErrorFailToCopyDir", $srcdir, $destdir)."\n";
118
+            exit(2);
119
+        }
120
+        else	// $result == 0
121
+        {
122
+            print $langs->trans("AllFilesDidAlreadyExist", $srcdir, $destdir)."\n";
123
+        }
124
+    }
125
+
126
+    // Delete some files
127
+    dol_delete_file($destdir.'/myobject_card.php');
128
+    dol_delete_file($destdir.'/myobject_note.php');
129
+    dol_delete_file($destdir.'/myobject_document.php');
130
+    dol_delete_file($destdir.'/myobject_agenda.php');
131
+    dol_delete_file($destdir.'/myobject_list.php');
132
+    dol_delete_file($destdir.'/lib/myobject.lib.php');
133
+    dol_delete_file($destdir.'/test/phpunit/MyObjectTest.php');
134
+    dol_delete_file($destdir.'/sql/llx_mymodule_myobject.sql');
135
+    dol_delete_file($destdir.'/sql/llx_mymodule_myobject_extrafields.sql');
136
+    dol_delete_file($destdir.'/sql/llx_mymodule_myobject.key.sql');
137
+    dol_delete_file($destdir.'/scripts/myobject.php');
138
+    dol_delete_file($destdir.'/img/object_myobject.png');
139
+    dol_delete_file($destdir.'/class/myobject.class.php');
140
+    dol_delete_file($destdir.'/class/api_mymodule.class.php');
141 141
 }
142 142
 
143 143
 // Edit PHP files
144 144
 if (! $error)
145 145
 {
146
-	$listofphpfilestoedit = dol_dir_list($destdir, 'files', 1, '\.(php|MD|js|sql|txt|xml|lang)$', '', 'fullname', SORT_ASC, 0, 1);
147
-	foreach($listofphpfilestoedit as $phpfileval)
148
-	{
149
-		//var_dump($phpfileval['fullname']);
150
-		$arrayreplacement=array(
151
-		'mymodule'=>strtolower($modulename),
152
-		'MyModule'=>$modulename,
153
-		'MYMODULE'=>strtoupper($modulename),
154
-		'My module'=>$modulename,
155
-		'my module'=>$modulename,
156
-		'Mon module'=>$modulename,
157
-		'mon module'=>$modulename,
158
-		'htdocs/modulebuilder/template'=>strtolower($modulename),
159
-		'---Put here your own copyright and developer email---'=>dol_print_date($now,'%Y').' '.$user->getFullName($langs).($user->email?' <'.$user->email.'>':'')
160
-		);
161
-
162
-
163
-		$result=dolReplaceInFile($phpfileval['fullname'], $arrayreplacement);
164
-		//var_dump($result);
165
-		if ($result < 0)
166
-		{
167
-			print $langs->trans("ErrorFailToMakeReplacementInto", $phpfileval['fullname'])."\n";
168
-			exit(3);
169
-		}
170
-	}
146
+    $listofphpfilestoedit = dol_dir_list($destdir, 'files', 1, '\.(php|MD|js|sql|txt|xml|lang)$', '', 'fullname', SORT_ASC, 0, 1);
147
+    foreach($listofphpfilestoedit as $phpfileval)
148
+    {
149
+        //var_dump($phpfileval['fullname']);
150
+        $arrayreplacement=array(
151
+        'mymodule'=>strtolower($modulename),
152
+        'MyModule'=>$modulename,
153
+        'MYMODULE'=>strtoupper($modulename),
154
+        'My module'=>$modulename,
155
+        'my module'=>$modulename,
156
+        'Mon module'=>$modulename,
157
+        'mon module'=>$modulename,
158
+        'htdocs/modulebuilder/template'=>strtolower($modulename),
159
+        '---Put here your own copyright and developer email---'=>dol_print_date($now,'%Y').' '.$user->getFullName($langs).($user->email?' <'.$user->email.'>':'')
160
+        );
161
+
162
+
163
+        $result=dolReplaceInFile($phpfileval['fullname'], $arrayreplacement);
164
+        //var_dump($result);
165
+        if ($result < 0)
166
+        {
167
+            print $langs->trans("ErrorFailToMakeReplacementInto", $phpfileval['fullname'])."\n";
168
+            exit(3);
169
+        }
170
+    }
171 171
 }
172 172
 
173 173
 print 'Module initialized'."\n";
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 
28 28
 $sapi_type = php_sapi_name();
29 29
 $script_file = basename(__FILE__);
30
-$path=dirname(__FILE__).'/';
30
+$path = dirname(__FILE__).'/';
31 31
 
32 32
 // Test if batch mode
33 33
 if (substr($sapi_type, 0, 3) == 'cgi') {
@@ -35,11 +35,11 @@  discard block
 block discarded – undo
35 35
 	exit(-1);
36 36
 }
37 37
 
38
-if (! isset($argv[1]) || ! $argv[1]) {
38
+if (!isset($argv[1]) || !$argv[1]) {
39 39
 	print "Usage: ".$script_file." ModuleName\n";
40 40
 	exit(-1);
41 41
 }
42
-$modulename=$argv[1];
42
+$modulename = $argv[1];
43 43
 
44 44
 require_once $path."../../htdocs/master.inc.php";
45 45
 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
@@ -52,31 +52,31 @@  discard block
 block discarded – undo
52 52
 
53 53
 
54 54
 // Global variables
55
-$version=DOL_VERSION;
56
-$error=0;
55
+$version = DOL_VERSION;
56
+$error = 0;
57 57
 
58 58
 // Dir for custom dirs
59
-$tmp=explode(',', $dolibarr_main_document_root_alt);
59
+$tmp = explode(',', $dolibarr_main_document_root_alt);
60 60
 $dirins = $tmp[0];
61 61
 $dirread = $dirins;
62 62
 $forceddirread = 0;
63 63
 
64 64
 $tmpdir = explode('@', $module);
65
-if (! empty($tmpdir[1]))
65
+if (!empty($tmpdir[1]))
66 66
 {
67
-	$module=$tmpdir[0];
68
-	$dirread=$tmpdir[1];
69
-	$forceddirread=1;
67
+	$module = $tmpdir[0];
68
+	$dirread = $tmpdir[1];
69
+	$forceddirread = 1;
70 70
 }
71 71
 
72
-$FILEFLAG='modulebuilder.txt';
72
+$FILEFLAG = 'modulebuilder.txt';
73 73
 
74
-$now=dol_now();
74
+$now = dol_now();
75 75
 $newmask = 0;
76
-if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK;
76
+if (empty($newmask) && !empty($conf->global->MAIN_UMASK)) $newmask = $conf->global->MAIN_UMASK;
77 77
 if (empty($newmask))	// This should no happen
78 78
 {
79
-	$newmask='0664';
79
+	$newmask = '0664';
80 80
 }
81 81
 
82 82
 
@@ -96,12 +96,12 @@  discard block
 block discarded – undo
96 96
 	exit(1);
97 97
 }
98 98
 
99
-if (! $error)
99
+if (!$error)
100 100
 {
101 101
 	$srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
102 102
 	$destdir = $dirins.'/'.strtolower($modulename);
103 103
 
104
-	$arrayreplacement=array(
104
+	$arrayreplacement = array(
105 105
 	'mymodule'=>strtolower($modulename),
106 106
 	'MyModule'=>$modulename
107 107
 	);
@@ -141,13 +141,13 @@  discard block
 block discarded – undo
141 141
 }
142 142
 
143 143
 // Edit PHP files
144
-if (! $error)
144
+if (!$error)
145 145
 {
146 146
 	$listofphpfilestoedit = dol_dir_list($destdir, 'files', 1, '\.(php|MD|js|sql|txt|xml|lang)$', '', 'fullname', SORT_ASC, 0, 1);
147
-	foreach($listofphpfilestoedit as $phpfileval)
147
+	foreach ($listofphpfilestoedit as $phpfileval)
148 148
 	{
149 149
 		//var_dump($phpfileval['fullname']);
150
-		$arrayreplacement=array(
150
+		$arrayreplacement = array(
151 151
 		'mymodule'=>strtolower($modulename),
152 152
 		'MyModule'=>$modulename,
153 153
 		'MYMODULE'=>strtoupper($modulename),
@@ -156,11 +156,11 @@  discard block
 block discarded – undo
156 156
 		'Mon module'=>$modulename,
157 157
 		'mon module'=>$modulename,
158 158
 		'htdocs/modulebuilder/template'=>strtolower($modulename),
159
-		'---Put here your own copyright and developer email---'=>dol_print_date($now,'%Y').' '.$user->getFullName($langs).($user->email?' <'.$user->email.'>':'')
159
+		'---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '')
160 160
 		);
161 161
 
162 162
 
163
-		$result=dolReplaceInFile($phpfileval['fullname'], $arrayreplacement);
163
+		$result = dolReplaceInFile($phpfileval['fullname'], $arrayreplacement);
164 164
 		//var_dump($result);
165 165
 		if ($result < 0)
166 166
 		{
Please login to merge, or discard this patch.
Braces   +7 added lines, -4 removed lines patch added patch discarded remove patch
@@ -73,11 +73,15 @@  discard block
 block discarded – undo
73 73
 
74 74
 $now=dol_now();
75 75
 $newmask = 0;
76
-if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK;
77
-if (empty($newmask))	// This should no happen
76
+if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) {
77
+    $newmask=$conf->global->MAIN_UMASK;
78
+}
79
+if (empty($newmask)) {
80
+    // This should no happen
78 81
 {
79 82
 	$newmask='0664';
80 83
 }
84
+}
81 85
 
82 86
 
83 87
 /*
@@ -116,8 +120,7 @@  discard block
 block discarded – undo
116 120
 			$langs->load("errors");
117 121
 			print $langs->trans("ErrorFailToCopyDir", $srcdir, $destdir)."\n";
118 122
 			exit(2);
119
-		}
120
-		else	// $result == 0
123
+		} else	// $result == 0
121 124
 		{
122 125
 			print $langs->trans("AllFilesDidAlreadyExist", $srcdir, $destdir)."\n";
123 126
 		}
Please login to merge, or discard this patch.
dolibarr/scripts/bank/export-bank-receipts.php 3 patches
Indentation   +256 added lines, -256 removed lines patch added patch discarded remove patch
@@ -29,8 +29,8 @@  discard block
 block discarded – undo
29 29
 
30 30
 // Test if batch mode
31 31
 if (substr($sapi_type, 0, 3) == 'cgi') {
32
-	echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
33
-	exit(-1);
32
+    echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
33
+    exit(-1);
34 34
 }
35 35
 
36 36
 require_once $path."../../htdocs/master.inc.php";
@@ -63,8 +63,8 @@  discard block
 block discarded – undo
63 63
 dol_syslog($script_file." launched with arg ".join(',',$argv));
64 64
 
65 65
 if (! isset($argv[3]) || ! $argv[3]) {
66
-	print "Usage: ".$script_file." bank_ref [bank_receipt_number|all] (csv|tsv|excel|excel2007) [lang=xx_XX]\n";
67
-	exit(-1);
66
+    print "Usage: ".$script_file." bank_ref [bank_receipt_number|all] (csv|tsv|excel|excel2007) [lang=xx_XX]\n";
67
+    exit(-1);
68 68
 }
69 69
 $bankref=$argv[1];
70 70
 $num=$argv[2];
@@ -88,25 +88,25 @@  discard block
 block discarded – undo
88 88
 // Parse parameters
89 89
 foreach ($argv as $key => $value)
90 90
 {
91
-	$found=false;
92
-
93
-	// Define options
94
-	if (preg_match('/^lang=/i',$value))
95
-	{
96
-		$found=true;
97
-		$valarray=explode('=',$value);
98
-		$newlangid=$valarray[1];
99
-		print 'Use language '.$newlangid.".\n";
100
-	}
91
+    $found=false;
92
+
93
+    // Define options
94
+    if (preg_match('/^lang=/i',$value))
95
+    {
96
+        $found=true;
97
+        $valarray=explode('=',$value);
98
+        $newlangid=$valarray[1];
99
+        print 'Use language '.$newlangid.".\n";
100
+    }
101 101
 }
102 102
 $outputlangs = $langs;
103 103
 if (! empty($newlangid))
104 104
 {
105
-	if ($outputlangs->defaultlang != $newlangid)
106
-	{
107
-		$outputlangs = new Translate("",$conf);
108
-		$outputlangs->setDefaultLang($newlangid);
109
-	}
105
+    if ($outputlangs->defaultlang != $newlangid)
106
+    {
107
+        $outputlangs = new Translate("",$conf);
108
+        $outputlangs->setDefaultLang($newlangid);
109
+    }
110 110
 }
111 111
 
112 112
 // Load translation files required by the page
@@ -116,12 +116,12 @@  discard block
 block discarded – undo
116 116
 $result=$acct->fetch('',$bankref);
117 117
 if ($result <= 0)
118 118
 {
119
-	print "Failed to find bank account with ref ".$bankref.".\n";
120
-	exit(-1);
119
+    print "Failed to find bank account with ref ".$bankref.".\n";
120
+    exit(-1);
121 121
 }
122 122
 else
123 123
 {
124
-	print "Export for bank account ".$acct->ref." (".$acct->label.").\n";
124
+    print "Export for bank account ".$acct->ref." (".$acct->label.").\n";
125 125
 }
126 126
 
127 127
 
@@ -131,8 +131,8 @@  discard block
 block discarded – undo
131 131
 $classname = "Export".$model;
132 132
 if (! dol_is_file($dir.$file))
133 133
 {
134
-	print "No driver to export with format ".$model."\n";
135
-	exit(-1);
134
+    print "No driver to export with format ".$model."\n";
135
+    exit(-1);
136 136
 }
137 137
 require_once $dir.$file;
138 138
 $objmodel = new $classname($db);
@@ -173,14 +173,14 @@  discard block
 block discarded – undo
173 173
 $listofnum="";
174 174
 if (! empty($num) && $num != "all")
175 175
 {
176
-	$listofnum.="'";
177
-	$arraynum=explode(',',$num);
178
-	foreach($arraynum as $val)
179
-	{
180
-		if ($listofnum != "'") $listofnum.="','";
181
-		$listofnum.=$val;
182
-	}
183
-	$listofnum.="'";
176
+    $listofnum.="'";
177
+    $arraynum=explode(',',$num);
178
+    foreach($arraynum as $val)
179
+    {
180
+        if ($listofnum != "'") $listofnum.="','";
181
+        $listofnum.=$val;
182
+    }
183
+    $listofnum.="'";
184 184
 }
185 185
 $sql = "SELECT b.rowid, b.dateo as do, b.datev as dv,";
186 186
 $sql.= " b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type,";
@@ -197,175 +197,175 @@  discard block
 block discarded – undo
197 197
 $resql=$db->query($sql);
198 198
 if ($resql)
199 199
 {
200
-	$balancebefore=array();
201
-
202
-	$numrows = $db->num_rows($resql);
203
-
204
-	if ($numrows > 0)
205
-	{
206
-		// Open file
207
-		print 'Open file '.$filename.' into directory '.$dirname."\n";
208
-		dol_mkdir($dirname);
209
-		$result=$objmodel->open_file($dirname."/".$filename, $outputlangs);
210
-
211
-		if ($result < 0)
212
-		{
213
-			print 'Failed to create file '.$filename.' into dir '.$dirname.'.'."\n";
214
-			return -1;
215
-		}
216
-
217
-		// Genere en-tete
218
-		$objmodel->write_header($outputlangs);
219
-
220
-		// Genere ligne de titre
221
-		$objmodel->write_title($array_fields,$array_selected,$outputlangs,$array_export_TypeFields);
222
-	}
223
-
224
-	$i=0;
225
-	while ($i < $numrows)
226
-	{
227
-		$thirdparty='';
228
-		$accountelem='';
229
-		$comment='';
230
-
231
-		$objp = $db->fetch_object($resql);
232
-
233
-		// Calculate start balance
234
-		if (! isset($balancebefore[$objp->num_releve]))
235
-		{
236
-			print 'Calculate start balance for receipt '.$objp->num_releve."\n";
237
-
238
-			$sql2 = "SELECT sum(b.amount) as amount";
239
-			$sql2.= " FROM ".MAIN_DB_PREFIX."bank as b";
240
-			$sql2.= " WHERE b.num_releve < '".$db->escape($objp->num_releve)."'";
241
-			$sql2.= " AND b.fk_account = ".$objp->bankid;
242
-			$resql2=$db->query($sql2);
243
-			if ($resql2)
244
-			{
245
-				$obj2=$db->fetch_object($resql2);
246
-				$balancebefore[$objp->num_releve] = ($obj2->amount?$obj2->amount:0);
247
-				$db->free($resql2);
248
-			}
249
-			else
250
-			{
251
-				dol_print_error($db);
252
-				exit(-1);
253
-			}
254
-
255
-			$total = $balancebefore[$objp->num_releve];
256
-		}
257
-
258
-		$totalbefore = $total;
259
-		$total = $total + $objp->amount;
260
-
261
-
262
-
263
-		// Date operation
264
-		$dateop=$db->jdate($objp->do);
265
-
266
-		// Date de valeur
267
-		$datevalue=$db->jdate($objp->dv);
268
-
269
-		// Num cheque
270
-		$numchq=($objp->num_chq?$objp->num_chq:'');
271
-
272
-		// Libelle
273
-		$reg=array();
274
-		preg_match('/\((.+)\)/i',$objp->label,$reg);	// Si texte entoure de parenthese on tente recherche de traduction
275
-		if ($reg[1] && $langs->transnoentitiesnoconv($reg[1])!=$reg[1]) $description=$langs->transnoentitiesnoconv($reg[1]);
276
-		else $description=$objp->label;
277
-
278
-		/*
200
+    $balancebefore=array();
201
+
202
+    $numrows = $db->num_rows($resql);
203
+
204
+    if ($numrows > 0)
205
+    {
206
+        // Open file
207
+        print 'Open file '.$filename.' into directory '.$dirname."\n";
208
+        dol_mkdir($dirname);
209
+        $result=$objmodel->open_file($dirname."/".$filename, $outputlangs);
210
+
211
+        if ($result < 0)
212
+        {
213
+            print 'Failed to create file '.$filename.' into dir '.$dirname.'.'."\n";
214
+            return -1;
215
+        }
216
+
217
+        // Genere en-tete
218
+        $objmodel->write_header($outputlangs);
219
+
220
+        // Genere ligne de titre
221
+        $objmodel->write_title($array_fields,$array_selected,$outputlangs,$array_export_TypeFields);
222
+    }
223
+
224
+    $i=0;
225
+    while ($i < $numrows)
226
+    {
227
+        $thirdparty='';
228
+        $accountelem='';
229
+        $comment='';
230
+
231
+        $objp = $db->fetch_object($resql);
232
+
233
+        // Calculate start balance
234
+        if (! isset($balancebefore[$objp->num_releve]))
235
+        {
236
+            print 'Calculate start balance for receipt '.$objp->num_releve."\n";
237
+
238
+            $sql2 = "SELECT sum(b.amount) as amount";
239
+            $sql2.= " FROM ".MAIN_DB_PREFIX."bank as b";
240
+            $sql2.= " WHERE b.num_releve < '".$db->escape($objp->num_releve)."'";
241
+            $sql2.= " AND b.fk_account = ".$objp->bankid;
242
+            $resql2=$db->query($sql2);
243
+            if ($resql2)
244
+            {
245
+                $obj2=$db->fetch_object($resql2);
246
+                $balancebefore[$objp->num_releve] = ($obj2->amount?$obj2->amount:0);
247
+                $db->free($resql2);
248
+            }
249
+            else
250
+            {
251
+                dol_print_error($db);
252
+                exit(-1);
253
+            }
254
+
255
+            $total = $balancebefore[$objp->num_releve];
256
+        }
257
+
258
+        $totalbefore = $total;
259
+        $total = $total + $objp->amount;
260
+
261
+
262
+
263
+        // Date operation
264
+        $dateop=$db->jdate($objp->do);
265
+
266
+        // Date de valeur
267
+        $datevalue=$db->jdate($objp->dv);
268
+
269
+        // Num cheque
270
+        $numchq=($objp->num_chq?$objp->num_chq:'');
271
+
272
+        // Libelle
273
+        $reg=array();
274
+        preg_match('/\((.+)\)/i',$objp->label,$reg);	// Si texte entoure de parenthese on tente recherche de traduction
275
+        if ($reg[1] && $langs->transnoentitiesnoconv($reg[1])!=$reg[1]) $description=$langs->transnoentitiesnoconv($reg[1]);
276
+        else $description=$objp->label;
277
+
278
+        /*
279 279
 		 * Ajout les liens (societe, company...)
280 280
 		 */
281
-		$links = $acct->get_url($objp->rowid);
282
-		foreach($links as $key=>$val)
283
-		{
284
-			if ($links[$key]['type']=='payment')
285
-			{
286
-				$paymentstatic->fetch($links[$key]['url_id']);
287
-				$tmparray=$paymentstatic->getBillsArray('');
288
-				if (is_array($tmparray))
289
-				{
290
-					foreach($tmparray as $key => $val)
291
-					{
292
-						$invoicestatic->fetch($val);
293
-						if ($accountelem) $accountelem.= ', ';
294
-						$accountelem.=$invoicestatic->ref;
295
-					}
296
-				}
297
-			}
298
-			elseif ($links[$key]['type']=='payment_supplier')
299
-			{
300
-				$paymentsupplierstatic->fetch($links[$key]['url_id']);
301
-				$tmparray=$paymentsupplierstatic->getBillsArray('');
302
-				if (is_array($tmparray))
303
-				{
304
-					foreach($tmparray as $key => $val)
305
-					{
306
-						$invoicesupplierstatic->fetch($val);
307
-						if ($accountelem) $accountelem.= ', ';
308
-						$accountelem.=$invoicesupplierstatic->ref;
309
-					}
310
-				}
311
-			}
312
-			elseif ($links[$key]['type']=='payment_sc')
313
-			{
314
-				$paymentsocialcontributionstatic->fetch($links[$key]['url_id']);
315
-				if ($accountelem) $accountelem.= ', ';
316
-				$accountelem.=$langs->transnoentitiesnoconv("SocialContribution").' '.$paymentsocialcontributionstatic->ref;
317
-			}
318
-			elseif ($links[$key]['type']=='payment_vat')
319
-			{
320
-				$paymentvatstatic->fetch($links[$key]['url_id']);
321
-				if ($accountelem) $accountelem.= ', ';
322
-				$accountelem.=$langs->transnoentitiesnoconv("VATPayments").' '.$paymentvatstatic->ref;
323
-			}
324
-			elseif ($links[$key]['type']=='banktransfert')
325
-			{
326
-				$comment=$outputlangs->transnoentitiesnoconv("Transfer");
327
-				if ($objp->amount > 0)
328
-				{
329
-					if ($comment) $comment.= ' ';
330
-					$banklinestatic->fetch($links[$key]['url_id']);
331
-					$bankstatic->id=$banklinestatic->fk_account;
332
-					$bankstatic->label=$banklinestatic->bank_account_label;
333
-					$comment.= ' ('.$langs->transnoentitiesnoconv("from").' ';
334
-					$comment.= $bankstatic->getNomUrl(1,'transactions');
335
-					$comment.= ' '.$langs->transnoentitiesnoconv("toward").' ';
336
-					$bankstatic->id=$objp->bankid;
337
-					$bankstatic->label=$objp->bankref;
338
-					$comment.= $bankstatic->getNomUrl(1,'');
339
-					$comment.= ')';
340
-				}
341
-				else
342
-				{
343
-					if ($comment) $comment.= ' ';
344
-					$bankstatic->id=$objp->bankid;
345
-					$bankstatic->label=$objp->bankref;
346
-					$comment.= ' ('.$langs->transnoentitiesnoconv("from").' ';
347
-					$comment.= $bankstatic->getNomUrl(1,'');
348
-					$comment.= ' '.$langs->transnoentitiesnoconv("toward").' ';
349
-					$banklinestatic->fetch($links[$key]['url_id']);
350
-					$bankstatic->id=$banklinestatic->fk_account;
351
-					$bankstatic->label=$banklinestatic->bank_account_label;
352
-					$comment.= $bankstatic->getNomUrl(1,'transactions');
353
-					$comment.= ')';
354
-				}
355
-			}
356
-			elseif ($links[$key]['type']=='company')
357
-			{
358
-				if ($thirdparty) $thirdparty.= ', ';
359
-				$thirdparty.= dol_trunc($links[$key]['label'],24);
360
-				$newline=0;
361
-			}
362
-			elseif ($links[$key]['type']=='member')
363
-			{
364
-				if ($thirdparty) $accountelem.= ', ';
365
-				$thirdparty.= $links[$key]['label'];
366
-				$newline=0;
367
-			}
368
-			/*elseif ($links[$key]['type']=='sc')
281
+        $links = $acct->get_url($objp->rowid);
282
+        foreach($links as $key=>$val)
283
+        {
284
+            if ($links[$key]['type']=='payment')
285
+            {
286
+                $paymentstatic->fetch($links[$key]['url_id']);
287
+                $tmparray=$paymentstatic->getBillsArray('');
288
+                if (is_array($tmparray))
289
+                {
290
+                    foreach($tmparray as $key => $val)
291
+                    {
292
+                        $invoicestatic->fetch($val);
293
+                        if ($accountelem) $accountelem.= ', ';
294
+                        $accountelem.=$invoicestatic->ref;
295
+                    }
296
+                }
297
+            }
298
+            elseif ($links[$key]['type']=='payment_supplier')
299
+            {
300
+                $paymentsupplierstatic->fetch($links[$key]['url_id']);
301
+                $tmparray=$paymentsupplierstatic->getBillsArray('');
302
+                if (is_array($tmparray))
303
+                {
304
+                    foreach($tmparray as $key => $val)
305
+                    {
306
+                        $invoicesupplierstatic->fetch($val);
307
+                        if ($accountelem) $accountelem.= ', ';
308
+                        $accountelem.=$invoicesupplierstatic->ref;
309
+                    }
310
+                }
311
+            }
312
+            elseif ($links[$key]['type']=='payment_sc')
313
+            {
314
+                $paymentsocialcontributionstatic->fetch($links[$key]['url_id']);
315
+                if ($accountelem) $accountelem.= ', ';
316
+                $accountelem.=$langs->transnoentitiesnoconv("SocialContribution").' '.$paymentsocialcontributionstatic->ref;
317
+            }
318
+            elseif ($links[$key]['type']=='payment_vat')
319
+            {
320
+                $paymentvatstatic->fetch($links[$key]['url_id']);
321
+                if ($accountelem) $accountelem.= ', ';
322
+                $accountelem.=$langs->transnoentitiesnoconv("VATPayments").' '.$paymentvatstatic->ref;
323
+            }
324
+            elseif ($links[$key]['type']=='banktransfert')
325
+            {
326
+                $comment=$outputlangs->transnoentitiesnoconv("Transfer");
327
+                if ($objp->amount > 0)
328
+                {
329
+                    if ($comment) $comment.= ' ';
330
+                    $banklinestatic->fetch($links[$key]['url_id']);
331
+                    $bankstatic->id=$banklinestatic->fk_account;
332
+                    $bankstatic->label=$banklinestatic->bank_account_label;
333
+                    $comment.= ' ('.$langs->transnoentitiesnoconv("from").' ';
334
+                    $comment.= $bankstatic->getNomUrl(1,'transactions');
335
+                    $comment.= ' '.$langs->transnoentitiesnoconv("toward").' ';
336
+                    $bankstatic->id=$objp->bankid;
337
+                    $bankstatic->label=$objp->bankref;
338
+                    $comment.= $bankstatic->getNomUrl(1,'');
339
+                    $comment.= ')';
340
+                }
341
+                else
342
+                {
343
+                    if ($comment) $comment.= ' ';
344
+                    $bankstatic->id=$objp->bankid;
345
+                    $bankstatic->label=$objp->bankref;
346
+                    $comment.= ' ('.$langs->transnoentitiesnoconv("from").' ';
347
+                    $comment.= $bankstatic->getNomUrl(1,'');
348
+                    $comment.= ' '.$langs->transnoentitiesnoconv("toward").' ';
349
+                    $banklinestatic->fetch($links[$key]['url_id']);
350
+                    $bankstatic->id=$banklinestatic->fk_account;
351
+                    $bankstatic->label=$banklinestatic->bank_account_label;
352
+                    $comment.= $bankstatic->getNomUrl(1,'transactions');
353
+                    $comment.= ')';
354
+                }
355
+            }
356
+            elseif ($links[$key]['type']=='company')
357
+            {
358
+                if ($thirdparty) $thirdparty.= ', ';
359
+                $thirdparty.= dol_trunc($links[$key]['label'],24);
360
+                $newline=0;
361
+            }
362
+            elseif ($links[$key]['type']=='member')
363
+            {
364
+                if ($thirdparty) $accountelem.= ', ';
365
+                $thirdparty.= $links[$key]['label'];
366
+                $newline=0;
367
+            }
368
+            /*elseif ($links[$key]['type']=='sc')
369 369
 				{
370 370
 			if ($accountelem) $accountelem.= ', ';
371 371
 			//$accountelem.= '<a href="'.DOL_URL_ROOT.'/compta/sociales/card.php?id='.$links[$key]['url_id'].'">';
@@ -382,66 +382,66 @@  discard block
 block discarded – undo
382 382
 			//$accountelem.= '</a>';
383 383
 			$newline=0;
384 384
 			}*/
385
-		}
386
-
387
-		$debit=$credit='';
388
-		if ($objp->amount < 0)
389
-		{
390
-			$totald = $totald + abs($objp->amount);
391
-			$debit=price2num($objp->amount * -1);
392
-		}
393
-		else
394
-		{
395
-			$totalc = $totalc + abs($objp->amount);
396
-			$credit=price2num($objp->amount);
397
-		}
398
-
399
-		$i++;
400
-
401
-		$rec=new stdClass();
402
-		$rec->bankreceipt=$objp->num_releve;
403
-		$rec->bankaccount=$objp->banklabel;
404
-		$rec->dateop=dol_print_date($dateop,'dayrfc');
405
-		$rec->dateval=dol_print_date($datevalue,'dayrfc');
406
-		$rec->type=$objp->fk_type.' '.($objp->num_chq?$objp->num_chq:'');
407
-		$rec->description=$description;
408
-		$rec->thirdparty=$thirdparty;
409
-		$rec->accountelem=$accountelem;
410
-		$rec->debit=$debit;
411
-		$rec->credit=$credit;
412
-		$rec->comment=$comment;
413
-		$rec->soldbefore=price2num($totalbefore);
414
-		$rec->soldafter=price2num($total);
415
-
416
-		// end of special operation processing
417
-		$objmodel->write_record($array_selected,$rec,$outputlangs,$array_export_TypeFields);
418
-	}
419
-
420
-	if ($numrows > 0)
421
-	{
422
-		print "Found ".$numrows." records for receipt ".$num."\n";
423
-
424
-		// Genere en-tete
425
-		$objmodel->write_footer($outputlangs);
426
-
427
-		// Close file
428
-		$objmodel->close_file();
429
-
430
-		print 'File '.$filename.' was generated into dir '.$dirname.'.'."\n";
431
-
432
-		$ret=0;
433
-	}
434
-	else
435
-	{
436
-		print "No records found for receipt ".$num."\n";
437
-
438
-		$ret=0;
439
-	}
385
+        }
386
+
387
+        $debit=$credit='';
388
+        if ($objp->amount < 0)
389
+        {
390
+            $totald = $totald + abs($objp->amount);
391
+            $debit=price2num($objp->amount * -1);
392
+        }
393
+        else
394
+        {
395
+            $totalc = $totalc + abs($objp->amount);
396
+            $credit=price2num($objp->amount);
397
+        }
398
+
399
+        $i++;
400
+
401
+        $rec=new stdClass();
402
+        $rec->bankreceipt=$objp->num_releve;
403
+        $rec->bankaccount=$objp->banklabel;
404
+        $rec->dateop=dol_print_date($dateop,'dayrfc');
405
+        $rec->dateval=dol_print_date($datevalue,'dayrfc');
406
+        $rec->type=$objp->fk_type.' '.($objp->num_chq?$objp->num_chq:'');
407
+        $rec->description=$description;
408
+        $rec->thirdparty=$thirdparty;
409
+        $rec->accountelem=$accountelem;
410
+        $rec->debit=$debit;
411
+        $rec->credit=$credit;
412
+        $rec->comment=$comment;
413
+        $rec->soldbefore=price2num($totalbefore);
414
+        $rec->soldafter=price2num($total);
415
+
416
+        // end of special operation processing
417
+        $objmodel->write_record($array_selected,$rec,$outputlangs,$array_export_TypeFields);
418
+    }
419
+
420
+    if ($numrows > 0)
421
+    {
422
+        print "Found ".$numrows." records for receipt ".$num."\n";
423
+
424
+        // Genere en-tete
425
+        $objmodel->write_footer($outputlangs);
426
+
427
+        // Close file
428
+        $objmodel->close_file();
429
+
430
+        print 'File '.$filename.' was generated into dir '.$dirname.'.'."\n";
431
+
432
+        $ret=0;
433
+    }
434
+    else
435
+    {
436
+        print "No records found for receipt ".$num."\n";
437
+
438
+        $ret=0;
439
+    }
440 440
 }
441 441
 else
442 442
 {
443
-	dol_print_error($db);
444
-	$ret=-1;
443
+    dol_print_error($db);
444
+    $ret=-1;
445 445
 }
446 446
 
447 447
 $db->close();
Please login to merge, or discard this patch.
Spacing   +146 added lines, -146 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 
26 26
 $sapi_type = php_sapi_name();
27 27
 $script_file = basename(__FILE__);
28
-$path=dirname(__FILE__).'/';
28
+$path = dirname(__FILE__).'/';
29 29
 
30 30
 // Test if batch mode
31 31
 if (substr($sapi_type, 0, 3) == 'cgi') {
@@ -49,8 +49,8 @@  discard block
 block discarded – undo
49 49
 require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/paymentsocialcontribution.class.php';
50 50
 
51 51
 // Global variables
52
-$version=DOL_VERSION;
53
-$error=0;
52
+$version = DOL_VERSION;
53
+$error = 0;
54 54
 
55 55
 
56 56
 
@@ -60,51 +60,51 @@  discard block
 block discarded – undo
60 60
 
61 61
 @set_time_limit(0);
62 62
 print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
63
-dol_syslog($script_file." launched with arg ".join(',',$argv));
63
+dol_syslog($script_file." launched with arg ".join(',', $argv));
64 64
 
65
-if (! isset($argv[3]) || ! $argv[3]) {
65
+if (!isset($argv[3]) || !$argv[3]) {
66 66
 	print "Usage: ".$script_file." bank_ref [bank_receipt_number|all] (csv|tsv|excel|excel2007) [lang=xx_XX]\n";
67 67
 	exit(-1);
68 68
 }
69
-$bankref=$argv[1];
70
-$num=$argv[2];
71
-$model=$argv[3];
72
-$newlangid='en_EN';	// To force a new lang id
69
+$bankref = $argv[1];
70
+$num = $argv[2];
71
+$model = $argv[3];
72
+$newlangid = 'en_EN'; // To force a new lang id
73 73
 
74 74
 
75
-$invoicestatic=new Facture($db);
76
-$invoicesupplierstatic=new FactureFournisseur($db);
77
-$societestatic=new Societe($db);
78
-$chargestatic=new ChargeSociales($db);
79
-$memberstatic=new Adherent($db);
80
-$paymentstatic=new Paiement($db);
81
-$paymentsupplierstatic=new PaiementFourn($db);
82
-$paymentsocialcontributionstatic=new PaymentSocialContribution($db);
83
-$paymentvatstatic=new Tva($db);
84
-$bankstatic=new Account($db);
85
-$banklinestatic=new AccountLine($db);
75
+$invoicestatic = new Facture($db);
76
+$invoicesupplierstatic = new FactureFournisseur($db);
77
+$societestatic = new Societe($db);
78
+$chargestatic = new ChargeSociales($db);
79
+$memberstatic = new Adherent($db);
80
+$paymentstatic = new Paiement($db);
81
+$paymentsupplierstatic = new PaiementFourn($db);
82
+$paymentsocialcontributionstatic = new PaymentSocialContribution($db);
83
+$paymentvatstatic = new Tva($db);
84
+$bankstatic = new Account($db);
85
+$banklinestatic = new AccountLine($db);
86 86
 
87 87
 
88 88
 // Parse parameters
89 89
 foreach ($argv as $key => $value)
90 90
 {
91
-	$found=false;
91
+	$found = false;
92 92
 
93 93
 	// Define options
94
-	if (preg_match('/^lang=/i',$value))
94
+	if (preg_match('/^lang=/i', $value))
95 95
 	{
96
-		$found=true;
97
-		$valarray=explode('=',$value);
98
-		$newlangid=$valarray[1];
96
+		$found = true;
97
+		$valarray = explode('=', $value);
98
+		$newlangid = $valarray[1];
99 99
 		print 'Use language '.$newlangid.".\n";
100 100
 	}
101 101
 }
102 102
 $outputlangs = $langs;
103
-if (! empty($newlangid))
103
+if (!empty($newlangid))
104 104
 {
105 105
 	if ($outputlangs->defaultlang != $newlangid)
106 106
 	{
107
-		$outputlangs = new Translate("",$conf);
107
+		$outputlangs = new Translate("", $conf);
108 108
 		$outputlangs->setDefaultLang($newlangid);
109 109
 	}
110 110
 }
@@ -112,8 +112,8 @@  discard block
 block discarded – undo
112 112
 // Load translation files required by the page
113 113
 $outputlangs->loadLangs(array("main", "companies", "bills", "banks", "members", "compta"));
114 114
 
115
-$acct=new Account($db);
116
-$result=$acct->fetch('',$bankref);
115
+$acct = new Account($db);
116
+$result = $acct->fetch('', $bankref);
117 117
 if ($result <= 0)
118 118
 {
119 119
 	print "Failed to find bank account with ref ".$bankref.".\n";
@@ -126,10 +126,10 @@  discard block
 block discarded – undo
126 126
 
127 127
 
128 128
 // Creation de la classe d'export du model ExportXXX
129
-$dir = DOL_DOCUMENT_ROOT . "/core/modules/export/";
129
+$dir = DOL_DOCUMENT_ROOT."/core/modules/export/";
130 130
 $file = "export_".$model.".modules.php";
131 131
 $classname = "Export".$model;
132
-if (! dol_is_file($dir.$file))
132
+if (!dol_is_file($dir.$file))
133 133
 {
134 134
 	print "No driver to export with format ".$model."\n";
135 135
 	exit(-1);
@@ -143,61 +143,61 @@  discard block
 block discarded – undo
143 143
 $filename = 'export-bank-receipts-'.$bankref.'-'.$num.'.'.$objmodel->extension;
144 144
 
145 145
 
146
-$array_fields=array(
146
+$array_fields = array(
147 147
 'bankreceipt'=>$outputlangs->transnoentitiesnoconv("AccountStatementShort"), 'bankaccount'=>$outputlangs->transnoentitiesnoconv("BankAccount"),
148
-'dateop'=>$outputlangs->transnoentitiesnoconv("DateOperationShort"),'dateval'=>$outputlangs->transnoentitiesnoconv("DateValueShort"),'type'=>$outputlangs->transnoentitiesnoconv("Type"),
148
+'dateop'=>$outputlangs->transnoentitiesnoconv("DateOperationShort"), 'dateval'=>$outputlangs->transnoentitiesnoconv("DateValueShort"), 'type'=>$outputlangs->transnoentitiesnoconv("Type"),
149 149
 'description'=>$outputlangs->transnoentitiesnoconv("Description"), 'thirdparty'=>$outputlangs->transnoentitiesnoconv("Tiers"), 'accountelem'=>$outputlangs->transnoentitiesnoconv("Piece"),
150 150
 'debit'=>$outputlangs->transnoentitiesnoconv("Debit"), 'credit'=>$outputlangs->transnoentitiesnoconv("Credit"),
151 151
 'soldbefore'=>$outputlangs->transnoentitiesnoconv("BankBalanceBefore"), 'soldafter'=>$outputlangs->transnoentitiesnoconv("BankBalanceAfter"),
152 152
 'comment'=>$outputlangs->transnoentitiesnoconv("Comment")
153 153
 );
154
-$array_selected=array(
154
+$array_selected = array(
155 155
 'bankreceipt'=>'bankreceipt', 'bankaccount'=>'bankaccount',
156
-'dateop'=>'dateop','dateval'=>'dateval','type'=>'type',
156
+'dateop'=>'dateop', 'dateval'=>'dateval', 'type'=>'type',
157 157
 'description'=>'description', 'thirdparty'=>'thirdparty', 'accountelem'=>'accountelem',
158 158
 'debit'=>'debit', 'credit'=>'credit',
159
-'soldbefore'=>'soldbefore','soldafter'=>'soldafter',
159
+'soldbefore'=>'soldbefore', 'soldafter'=>'soldafter',
160 160
 'comment'=>'comment'
161 161
 );
162
-$array_export_TypeFields=array(
162
+$array_export_TypeFields = array(
163 163
 'bankreceipt'=>'Text', 'bankaccount'=>'Text',
164
-'dateop'=>'Date','dateval'=>'Date','type'=>'Text',
164
+'dateop'=>'Date', 'dateval'=>'Date', 'type'=>'Text',
165 165
 'description'=>'Text', 'thirdparty'=>'Text', 'accountelem'=>'Text',
166 166
 'debit'=>'Number', 'credit'=>'Number',
167
-'soldbefore'=>'Number','soldafter'=>'Number',
167
+'soldbefore'=>'Number', 'soldafter'=>'Number',
168 168
 'comment'=>'Text'
169 169
 );
170 170
 
171 171
 
172 172
 // Build request to find records for a bank account/receipt
173
-$listofnum="";
174
-if (! empty($num) && $num != "all")
173
+$listofnum = "";
174
+if (!empty($num) && $num != "all")
175 175
 {
176
-	$listofnum.="'";
177
-	$arraynum=explode(',',$num);
178
-	foreach($arraynum as $val)
176
+	$listofnum .= "'";
177
+	$arraynum = explode(',', $num);
178
+	foreach ($arraynum as $val)
179 179
 	{
180
-		if ($listofnum != "'") $listofnum.="','";
181
-		$listofnum.=$val;
180
+		if ($listofnum != "'") $listofnum .= "','";
181
+		$listofnum .= $val;
182 182
 	}
183
-	$listofnum.="'";
183
+	$listofnum .= "'";
184 184
 }
185 185
 $sql = "SELECT b.rowid, b.dateo as do, b.datev as dv,";
186
-$sql.= " b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type,";
187
-$sql.= " ba.rowid as bankid, ba.ref as bankref, ba.label as banklabel";
188
-$sql.= " FROM ".MAIN_DB_PREFIX."bank_account as ba";
189
-$sql.= ", ".MAIN_DB_PREFIX."bank as b";
190
-$sql.= " WHERE b.fk_account = ".$acct->id;
191
-if ($listofnum) $sql.= " AND b.num_releve IN (".$listofnum.")";
192
-if (!isset($num)) $sql.= " OR b.num_releve is null";
193
-$sql.= " AND b.fk_account = ba.rowid";
194
-$sql.= $db->order("b.num_releve, b.datev, b.datec", "ASC");  // We add date of creation to have correct order when everything is done the same day
186
+$sql .= " b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type,";
187
+$sql .= " ba.rowid as bankid, ba.ref as bankref, ba.label as banklabel";
188
+$sql .= " FROM ".MAIN_DB_PREFIX."bank_account as ba";
189
+$sql .= ", ".MAIN_DB_PREFIX."bank as b";
190
+$sql .= " WHERE b.fk_account = ".$acct->id;
191
+if ($listofnum) $sql .= " AND b.num_releve IN (".$listofnum.")";
192
+if (!isset($num)) $sql .= " OR b.num_releve is null";
193
+$sql .= " AND b.fk_account = ba.rowid";
194
+$sql .= $db->order("b.num_releve, b.datev, b.datec", "ASC"); // We add date of creation to have correct order when everything is done the same day
195 195
 //print $sql;
196 196
 
197
-$resql=$db->query($sql);
197
+$resql = $db->query($sql);
198 198
 if ($resql)
199 199
 {
200
-	$balancebefore=array();
200
+	$balancebefore = array();
201 201
 
202 202
 	$numrows = $db->num_rows($resql);
203 203
 
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
 		// Open file
207 207
 		print 'Open file '.$filename.' into directory '.$dirname."\n";
208 208
 		dol_mkdir($dirname);
209
-		$result=$objmodel->open_file($dirname."/".$filename, $outputlangs);
209
+		$result = $objmodel->open_file($dirname."/".$filename, $outputlangs);
210 210
 
211 211
 		if ($result < 0)
212 212
 		{
@@ -218,32 +218,32 @@  discard block
 block discarded – undo
218 218
 		$objmodel->write_header($outputlangs);
219 219
 
220 220
 		// Genere ligne de titre
221
-		$objmodel->write_title($array_fields,$array_selected,$outputlangs,$array_export_TypeFields);
221
+		$objmodel->write_title($array_fields, $array_selected, $outputlangs, $array_export_TypeFields);
222 222
 	}
223 223
 
224
-	$i=0;
224
+	$i = 0;
225 225
 	while ($i < $numrows)
226 226
 	{
227
-		$thirdparty='';
228
-		$accountelem='';
229
-		$comment='';
227
+		$thirdparty = '';
228
+		$accountelem = '';
229
+		$comment = '';
230 230
 
231 231
 		$objp = $db->fetch_object($resql);
232 232
 
233 233
 		// Calculate start balance
234
-		if (! isset($balancebefore[$objp->num_releve]))
234
+		if (!isset($balancebefore[$objp->num_releve]))
235 235
 		{
236 236
 			print 'Calculate start balance for receipt '.$objp->num_releve."\n";
237 237
 
238 238
 			$sql2 = "SELECT sum(b.amount) as amount";
239
-			$sql2.= " FROM ".MAIN_DB_PREFIX."bank as b";
240
-			$sql2.= " WHERE b.num_releve < '".$db->escape($objp->num_releve)."'";
241
-			$sql2.= " AND b.fk_account = ".$objp->bankid;
242
-			$resql2=$db->query($sql2);
239
+			$sql2 .= " FROM ".MAIN_DB_PREFIX."bank as b";
240
+			$sql2 .= " WHERE b.num_releve < '".$db->escape($objp->num_releve)."'";
241
+			$sql2 .= " AND b.fk_account = ".$objp->bankid;
242
+			$resql2 = $db->query($sql2);
243 243
 			if ($resql2)
244 244
 			{
245
-				$obj2=$db->fetch_object($resql2);
246
-				$balancebefore[$objp->num_releve] = ($obj2->amount?$obj2->amount:0);
245
+				$obj2 = $db->fetch_object($resql2);
246
+				$balancebefore[$objp->num_releve] = ($obj2->amount ? $obj2->amount : 0);
247 247
 				$db->free($resql2);
248 248
 			}
249 249
 			else
@@ -261,109 +261,109 @@  discard block
 block discarded – undo
261 261
 
262 262
 
263 263
 		// Date operation
264
-		$dateop=$db->jdate($objp->do);
264
+		$dateop = $db->jdate($objp->do);
265 265
 
266 266
 		// Date de valeur
267
-		$datevalue=$db->jdate($objp->dv);
267
+		$datevalue = $db->jdate($objp->dv);
268 268
 
269 269
 		// Num cheque
270
-		$numchq=($objp->num_chq?$objp->num_chq:'');
270
+		$numchq = ($objp->num_chq ? $objp->num_chq : '');
271 271
 
272 272
 		// Libelle
273
-		$reg=array();
274
-		preg_match('/\((.+)\)/i',$objp->label,$reg);	// Si texte entoure de parenthese on tente recherche de traduction
275
-		if ($reg[1] && $langs->transnoentitiesnoconv($reg[1])!=$reg[1]) $description=$langs->transnoentitiesnoconv($reg[1]);
276
-		else $description=$objp->label;
273
+		$reg = array();
274
+		preg_match('/\((.+)\)/i', $objp->label, $reg); // Si texte entoure de parenthese on tente recherche de traduction
275
+		if ($reg[1] && $langs->transnoentitiesnoconv($reg[1]) != $reg[1]) $description = $langs->transnoentitiesnoconv($reg[1]);
276
+		else $description = $objp->label;
277 277
 
278 278
 		/*
279 279
 		 * Ajout les liens (societe, company...)
280 280
 		 */
281 281
 		$links = $acct->get_url($objp->rowid);
282
-		foreach($links as $key=>$val)
282
+		foreach ($links as $key=>$val)
283 283
 		{
284
-			if ($links[$key]['type']=='payment')
284
+			if ($links[$key]['type'] == 'payment')
285 285
 			{
286 286
 				$paymentstatic->fetch($links[$key]['url_id']);
287
-				$tmparray=$paymentstatic->getBillsArray('');
287
+				$tmparray = $paymentstatic->getBillsArray('');
288 288
 				if (is_array($tmparray))
289 289
 				{
290
-					foreach($tmparray as $key => $val)
290
+					foreach ($tmparray as $key => $val)
291 291
 					{
292 292
 						$invoicestatic->fetch($val);
293
-						if ($accountelem) $accountelem.= ', ';
294
-						$accountelem.=$invoicestatic->ref;
293
+						if ($accountelem) $accountelem .= ', ';
294
+						$accountelem .= $invoicestatic->ref;
295 295
 					}
296 296
 				}
297 297
 			}
298
-			elseif ($links[$key]['type']=='payment_supplier')
298
+			elseif ($links[$key]['type'] == 'payment_supplier')
299 299
 			{
300 300
 				$paymentsupplierstatic->fetch($links[$key]['url_id']);
301
-				$tmparray=$paymentsupplierstatic->getBillsArray('');
301
+				$tmparray = $paymentsupplierstatic->getBillsArray('');
302 302
 				if (is_array($tmparray))
303 303
 				{
304
-					foreach($tmparray as $key => $val)
304
+					foreach ($tmparray as $key => $val)
305 305
 					{
306 306
 						$invoicesupplierstatic->fetch($val);
307
-						if ($accountelem) $accountelem.= ', ';
308
-						$accountelem.=$invoicesupplierstatic->ref;
307
+						if ($accountelem) $accountelem .= ', ';
308
+						$accountelem .= $invoicesupplierstatic->ref;
309 309
 					}
310 310
 				}
311 311
 			}
312
-			elseif ($links[$key]['type']=='payment_sc')
312
+			elseif ($links[$key]['type'] == 'payment_sc')
313 313
 			{
314 314
 				$paymentsocialcontributionstatic->fetch($links[$key]['url_id']);
315
-				if ($accountelem) $accountelem.= ', ';
316
-				$accountelem.=$langs->transnoentitiesnoconv("SocialContribution").' '.$paymentsocialcontributionstatic->ref;
315
+				if ($accountelem) $accountelem .= ', ';
316
+				$accountelem .= $langs->transnoentitiesnoconv("SocialContribution").' '.$paymentsocialcontributionstatic->ref;
317 317
 			}
318
-			elseif ($links[$key]['type']=='payment_vat')
318
+			elseif ($links[$key]['type'] == 'payment_vat')
319 319
 			{
320 320
 				$paymentvatstatic->fetch($links[$key]['url_id']);
321
-				if ($accountelem) $accountelem.= ', ';
322
-				$accountelem.=$langs->transnoentitiesnoconv("VATPayments").' '.$paymentvatstatic->ref;
321
+				if ($accountelem) $accountelem .= ', ';
322
+				$accountelem .= $langs->transnoentitiesnoconv("VATPayments").' '.$paymentvatstatic->ref;
323 323
 			}
324
-			elseif ($links[$key]['type']=='banktransfert')
324
+			elseif ($links[$key]['type'] == 'banktransfert')
325 325
 			{
326
-				$comment=$outputlangs->transnoentitiesnoconv("Transfer");
326
+				$comment = $outputlangs->transnoentitiesnoconv("Transfer");
327 327
 				if ($objp->amount > 0)
328 328
 				{
329
-					if ($comment) $comment.= ' ';
329
+					if ($comment) $comment .= ' ';
330 330
 					$banklinestatic->fetch($links[$key]['url_id']);
331
-					$bankstatic->id=$banklinestatic->fk_account;
332
-					$bankstatic->label=$banklinestatic->bank_account_label;
333
-					$comment.= ' ('.$langs->transnoentitiesnoconv("from").' ';
334
-					$comment.= $bankstatic->getNomUrl(1,'transactions');
335
-					$comment.= ' '.$langs->transnoentitiesnoconv("toward").' ';
336
-					$bankstatic->id=$objp->bankid;
337
-					$bankstatic->label=$objp->bankref;
338
-					$comment.= $bankstatic->getNomUrl(1,'');
339
-					$comment.= ')';
331
+					$bankstatic->id = $banklinestatic->fk_account;
332
+					$bankstatic->label = $banklinestatic->bank_account_label;
333
+					$comment .= ' ('.$langs->transnoentitiesnoconv("from").' ';
334
+					$comment .= $bankstatic->getNomUrl(1, 'transactions');
335
+					$comment .= ' '.$langs->transnoentitiesnoconv("toward").' ';
336
+					$bankstatic->id = $objp->bankid;
337
+					$bankstatic->label = $objp->bankref;
338
+					$comment .= $bankstatic->getNomUrl(1, '');
339
+					$comment .= ')';
340 340
 				}
341 341
 				else
342 342
 				{
343
-					if ($comment) $comment.= ' ';
344
-					$bankstatic->id=$objp->bankid;
345
-					$bankstatic->label=$objp->bankref;
346
-					$comment.= ' ('.$langs->transnoentitiesnoconv("from").' ';
347
-					$comment.= $bankstatic->getNomUrl(1,'');
348
-					$comment.= ' '.$langs->transnoentitiesnoconv("toward").' ';
343
+					if ($comment) $comment .= ' ';
344
+					$bankstatic->id = $objp->bankid;
345
+					$bankstatic->label = $objp->bankref;
346
+					$comment .= ' ('.$langs->transnoentitiesnoconv("from").' ';
347
+					$comment .= $bankstatic->getNomUrl(1, '');
348
+					$comment .= ' '.$langs->transnoentitiesnoconv("toward").' ';
349 349
 					$banklinestatic->fetch($links[$key]['url_id']);
350
-					$bankstatic->id=$banklinestatic->fk_account;
351
-					$bankstatic->label=$banklinestatic->bank_account_label;
352
-					$comment.= $bankstatic->getNomUrl(1,'transactions');
353
-					$comment.= ')';
350
+					$bankstatic->id = $banklinestatic->fk_account;
351
+					$bankstatic->label = $banklinestatic->bank_account_label;
352
+					$comment .= $bankstatic->getNomUrl(1, 'transactions');
353
+					$comment .= ')';
354 354
 				}
355 355
 			}
356
-			elseif ($links[$key]['type']=='company')
356
+			elseif ($links[$key]['type'] == 'company')
357 357
 			{
358
-				if ($thirdparty) $thirdparty.= ', ';
359
-				$thirdparty.= dol_trunc($links[$key]['label'],24);
360
-				$newline=0;
358
+				if ($thirdparty) $thirdparty .= ', ';
359
+				$thirdparty .= dol_trunc($links[$key]['label'], 24);
360
+				$newline = 0;
361 361
 			}
362
-			elseif ($links[$key]['type']=='member')
362
+			elseif ($links[$key]['type'] == 'member')
363 363
 			{
364
-				if ($thirdparty) $accountelem.= ', ';
365
-				$thirdparty.= $links[$key]['label'];
366
-				$newline=0;
364
+				if ($thirdparty) $accountelem .= ', ';
365
+				$thirdparty .= $links[$key]['label'];
366
+				$newline = 0;
367 367
 			}
368 368
 			/*elseif ($links[$key]['type']=='sc')
369 369
 				{
@@ -384,37 +384,37 @@  discard block
 block discarded – undo
384 384
 			}*/
385 385
 		}
386 386
 
387
-		$debit=$credit='';
387
+		$debit = $credit = '';
388 388
 		if ($objp->amount < 0)
389 389
 		{
390 390
 			$totald = $totald + abs($objp->amount);
391
-			$debit=price2num($objp->amount * -1);
391
+			$debit = price2num($objp->amount * -1);
392 392
 		}
393 393
 		else
394 394
 		{
395 395
 			$totalc = $totalc + abs($objp->amount);
396
-			$credit=price2num($objp->amount);
396
+			$credit = price2num($objp->amount);
397 397
 		}
398 398
 
399 399
 		$i++;
400 400
 
401
-		$rec=new stdClass();
402
-		$rec->bankreceipt=$objp->num_releve;
403
-		$rec->bankaccount=$objp->banklabel;
404
-		$rec->dateop=dol_print_date($dateop,'dayrfc');
405
-		$rec->dateval=dol_print_date($datevalue,'dayrfc');
406
-		$rec->type=$objp->fk_type.' '.($objp->num_chq?$objp->num_chq:'');
407
-		$rec->description=$description;
408
-		$rec->thirdparty=$thirdparty;
409
-		$rec->accountelem=$accountelem;
410
-		$rec->debit=$debit;
411
-		$rec->credit=$credit;
412
-		$rec->comment=$comment;
413
-		$rec->soldbefore=price2num($totalbefore);
414
-		$rec->soldafter=price2num($total);
401
+		$rec = new stdClass();
402
+		$rec->bankreceipt = $objp->num_releve;
403
+		$rec->bankaccount = $objp->banklabel;
404
+		$rec->dateop = dol_print_date($dateop, 'dayrfc');
405
+		$rec->dateval = dol_print_date($datevalue, 'dayrfc');
406
+		$rec->type = $objp->fk_type.' '.($objp->num_chq ? $objp->num_chq : '');
407
+		$rec->description = $description;
408
+		$rec->thirdparty = $thirdparty;
409
+		$rec->accountelem = $accountelem;
410
+		$rec->debit = $debit;
411
+		$rec->credit = $credit;
412
+		$rec->comment = $comment;
413
+		$rec->soldbefore = price2num($totalbefore);
414
+		$rec->soldafter = price2num($total);
415 415
 
416 416
 		// end of special operation processing
417
-		$objmodel->write_record($array_selected,$rec,$outputlangs,$array_export_TypeFields);
417
+		$objmodel->write_record($array_selected, $rec, $outputlangs, $array_export_TypeFields);
418 418
 	}
419 419
 
420 420
 	if ($numrows > 0)
@@ -429,19 +429,19 @@  discard block
 block discarded – undo
429 429
 
430 430
 		print 'File '.$filename.' was generated into dir '.$dirname.'.'."\n";
431 431
 
432
-		$ret=0;
432
+		$ret = 0;
433 433
 	}
434 434
 	else
435 435
 	{
436 436
 		print "No records found for receipt ".$num."\n";
437 437
 
438
-		$ret=0;
438
+		$ret = 0;
439 439
 	}
440 440
 }
441 441
 else
442 442
 {
443 443
 	dol_print_error($db);
444
-	$ret=-1;
444
+	$ret = -1;
445 445
 }
446 446
 
447 447
 $db->close();
Please login to merge, or discard this patch.
Braces   +50 added lines, -37 removed lines patch added patch discarded remove patch
@@ -118,8 +118,7 @@  discard block
 block discarded – undo
118 118
 {
119 119
 	print "Failed to find bank account with ref ".$bankref.".\n";
120 120
 	exit(-1);
121
-}
122
-else
121
+} else
123 122
 {
124 123
 	print "Export for bank account ".$acct->ref." (".$acct->label.").\n";
125 124
 }
@@ -177,7 +176,9 @@  discard block
 block discarded – undo
177 176
 	$arraynum=explode(',',$num);
178 177
 	foreach($arraynum as $val)
179 178
 	{
180
-		if ($listofnum != "'") $listofnum.="','";
179
+		if ($listofnum != "'") {
180
+		    $listofnum.="','";
181
+		}
181 182
 		$listofnum.=$val;
182 183
 	}
183 184
 	$listofnum.="'";
@@ -188,8 +189,12 @@  discard block
 block discarded – undo
188 189
 $sql.= " FROM ".MAIN_DB_PREFIX."bank_account as ba";
189 190
 $sql.= ", ".MAIN_DB_PREFIX."bank as b";
190 191
 $sql.= " WHERE b.fk_account = ".$acct->id;
191
-if ($listofnum) $sql.= " AND b.num_releve IN (".$listofnum.")";
192
-if (!isset($num)) $sql.= " OR b.num_releve is null";
192
+if ($listofnum) {
193
+    $sql.= " AND b.num_releve IN (".$listofnum.")";
194
+}
195
+if (!isset($num)) {
196
+    $sql.= " OR b.num_releve is null";
197
+}
193 198
 $sql.= " AND b.fk_account = ba.rowid";
194 199
 $sql.= $db->order("b.num_releve, b.datev, b.datec", "ASC");  // We add date of creation to have correct order when everything is done the same day
195 200
 //print $sql;
@@ -245,8 +250,7 @@  discard block
 block discarded – undo
245 250
 				$obj2=$db->fetch_object($resql2);
246 251
 				$balancebefore[$objp->num_releve] = ($obj2->amount?$obj2->amount:0);
247 252
 				$db->free($resql2);
248
-			}
249
-			else
253
+			} else
250 254
 			{
251 255
 				dol_print_error($db);
252 256
 				exit(-1);
@@ -272,8 +276,11 @@  discard block
 block discarded – undo
272 276
 		// Libelle
273 277
 		$reg=array();
274 278
 		preg_match('/\((.+)\)/i',$objp->label,$reg);	// Si texte entoure de parenthese on tente recherche de traduction
275
-		if ($reg[1] && $langs->transnoentitiesnoconv($reg[1])!=$reg[1]) $description=$langs->transnoentitiesnoconv($reg[1]);
276
-		else $description=$objp->label;
279
+		if ($reg[1] && $langs->transnoentitiesnoconv($reg[1])!=$reg[1]) {
280
+		    $description=$langs->transnoentitiesnoconv($reg[1]);
281
+		} else {
282
+		    $description=$objp->label;
283
+		}
277 284
 
278 285
 		/*
279 286
 		 * Ajout les liens (societe, company...)
@@ -290,12 +297,13 @@  discard block
 block discarded – undo
290 297
 					foreach($tmparray as $key => $val)
291 298
 					{
292 299
 						$invoicestatic->fetch($val);
293
-						if ($accountelem) $accountelem.= ', ';
300
+						if ($accountelem) {
301
+						    $accountelem.= ', ';
302
+						}
294 303
 						$accountelem.=$invoicestatic->ref;
295 304
 					}
296 305
 				}
297
-			}
298
-			elseif ($links[$key]['type']=='payment_supplier')
306
+			} elseif ($links[$key]['type']=='payment_supplier')
299 307
 			{
300 308
 				$paymentsupplierstatic->fetch($links[$key]['url_id']);
301 309
 				$tmparray=$paymentsupplierstatic->getBillsArray('');
@@ -304,29 +312,34 @@  discard block
 block discarded – undo
304 312
 					foreach($tmparray as $key => $val)
305 313
 					{
306 314
 						$invoicesupplierstatic->fetch($val);
307
-						if ($accountelem) $accountelem.= ', ';
315
+						if ($accountelem) {
316
+						    $accountelem.= ', ';
317
+						}
308 318
 						$accountelem.=$invoicesupplierstatic->ref;
309 319
 					}
310 320
 				}
311
-			}
312
-			elseif ($links[$key]['type']=='payment_sc')
321
+			} elseif ($links[$key]['type']=='payment_sc')
313 322
 			{
314 323
 				$paymentsocialcontributionstatic->fetch($links[$key]['url_id']);
315
-				if ($accountelem) $accountelem.= ', ';
324
+				if ($accountelem) {
325
+				    $accountelem.= ', ';
326
+				}
316 327
 				$accountelem.=$langs->transnoentitiesnoconv("SocialContribution").' '.$paymentsocialcontributionstatic->ref;
317
-			}
318
-			elseif ($links[$key]['type']=='payment_vat')
328
+			} elseif ($links[$key]['type']=='payment_vat')
319 329
 			{
320 330
 				$paymentvatstatic->fetch($links[$key]['url_id']);
321
-				if ($accountelem) $accountelem.= ', ';
331
+				if ($accountelem) {
332
+				    $accountelem.= ', ';
333
+				}
322 334
 				$accountelem.=$langs->transnoentitiesnoconv("VATPayments").' '.$paymentvatstatic->ref;
323
-			}
324
-			elseif ($links[$key]['type']=='banktransfert')
335
+			} elseif ($links[$key]['type']=='banktransfert')
325 336
 			{
326 337
 				$comment=$outputlangs->transnoentitiesnoconv("Transfer");
327 338
 				if ($objp->amount > 0)
328 339
 				{
329
-					if ($comment) $comment.= ' ';
340
+					if ($comment) {
341
+					    $comment.= ' ';
342
+					}
330 343
 					$banklinestatic->fetch($links[$key]['url_id']);
331 344
 					$bankstatic->id=$banklinestatic->fk_account;
332 345
 					$bankstatic->label=$banklinestatic->bank_account_label;
@@ -337,10 +350,11 @@  discard block
 block discarded – undo
337 350
 					$bankstatic->label=$objp->bankref;
338 351
 					$comment.= $bankstatic->getNomUrl(1,'');
339 352
 					$comment.= ')';
340
-				}
341
-				else
353
+				} else
342 354
 				{
343
-					if ($comment) $comment.= ' ';
355
+					if ($comment) {
356
+					    $comment.= ' ';
357
+					}
344 358
 					$bankstatic->id=$objp->bankid;
345 359
 					$bankstatic->label=$objp->bankref;
346 360
 					$comment.= ' ('.$langs->transnoentitiesnoconv("from").' ';
@@ -352,16 +366,18 @@  discard block
 block discarded – undo
352 366
 					$comment.= $bankstatic->getNomUrl(1,'transactions');
353 367
 					$comment.= ')';
354 368
 				}
355
-			}
356
-			elseif ($links[$key]['type']=='company')
369
+			} elseif ($links[$key]['type']=='company')
357 370
 			{
358
-				if ($thirdparty) $thirdparty.= ', ';
371
+				if ($thirdparty) {
372
+				    $thirdparty.= ', ';
373
+				}
359 374
 				$thirdparty.= dol_trunc($links[$key]['label'],24);
360 375
 				$newline=0;
361
-			}
362
-			elseif ($links[$key]['type']=='member')
376
+			} elseif ($links[$key]['type']=='member')
363 377
 			{
364
-				if ($thirdparty) $accountelem.= ', ';
378
+				if ($thirdparty) {
379
+				    $accountelem.= ', ';
380
+				}
365 381
 				$thirdparty.= $links[$key]['label'];
366 382
 				$newline=0;
367 383
 			}
@@ -389,8 +405,7 @@  discard block
 block discarded – undo
389 405
 		{
390 406
 			$totald = $totald + abs($objp->amount);
391 407
 			$debit=price2num($objp->amount * -1);
392
-		}
393
-		else
408
+		} else
394 409
 		{
395 410
 			$totalc = $totalc + abs($objp->amount);
396 411
 			$credit=price2num($objp->amount);
@@ -430,15 +445,13 @@  discard block
 block discarded – undo
430 445
 		print 'File '.$filename.' was generated into dir '.$dirname.'.'."\n";
431 446
 
432 447
 		$ret=0;
433
-	}
434
-	else
448
+	} else
435 449
 	{
436 450
 		print "No records found for receipt ".$num."\n";
437 451
 
438 452
 		$ret=0;
439 453
 	}
440
-}
441
-else
454
+} else
442 455
 {
443 456
 	dol_print_error($db);
444 457
 	$ret=-1;
Please login to merge, or discard this patch.
dolibarr/scripts/contracts/email_expire_services_to_customers.php 3 patches
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -33,18 +33,18 @@  discard block
 block discarded – undo
33 33
 $sapi_type = php_sapi_name();
34 34
 if (substr($sapi_type, 0, 3) == 'cgi') {
35 35
     echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
36
-	exit(-1);
36
+    exit(-1);
37 37
 }
38 38
 
39 39
 if (! isset($argv[1]) || ! $argv[1] || ! in_array($argv[1],array('test','confirm')) || ! in_array($argv[2],array('thirdparties','contacts')))
40 40
 {
41
-	print "Usage: $script_file (test|confirm) (thirdparties|contacts) [delay] [after]\n";
42
-	print "\n";
43
-	print "Send an email to customers to remind all contracts services to expire or expired.\n";
44
-	print "If you choose 'test' mode, no emails are sent.\n";
45
-	print "If you add param delay (nb of days), only services with expired date < today + delay are included.\n";
46
-	print "If you add param after (nb of days), only services with expired date >= today + delay are included.\n";
47
-	exit(-1);
41
+    print "Usage: $script_file (test|confirm) (thirdparties|contacts) [delay] [after]\n";
42
+    print "\n";
43
+    print "Send an email to customers to remind all contracts services to expire or expired.\n";
44
+    print "If you choose 'test' mode, no emails are sent.\n";
45
+    print "If you add param delay (nb of days), only services with expired date < today + delay are included.\n";
46
+    print "If you add param after (nb of days), only services with expired date >= today + delay are included.\n";
47
+    exit(-1);
48 48
 }
49 49
 $mode=$argv[1];
50 50
 $targettype=$argv[2];
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 
106 106
     print "We found ".$num." couples (services to expire-".$targettype.") qualified\n";
107 107
     dol_syslog("We found ".$num." couples (services to expire-".$targettype.") qualified");
108
-	$message='';
108
+    $message='';
109 109
 
110 110
     if ($num)
111 111
     {
@@ -117,25 +117,25 @@  discard block
 block discarded – undo
117 117
 
118 118
             // Check if this record is a break after previous one
119 119
             $startbreak=false;
120
-			if ($newemail <> $oldemail || $oldemail == 'none') $startbreak=true;
121
-			if ($obj->sid && $obj->sid <> $oldsid) $startbreak=true;
122
-			if ($obj->cid && $obj->cid <> $oldcid) $startbreak=true;
120
+            if ($newemail <> $oldemail || $oldemail == 'none') $startbreak=true;
121
+            if ($obj->sid && $obj->sid <> $oldsid) $startbreak=true;
122
+            if ($obj->cid && $obj->cid <> $oldcid) $startbreak=true;
123 123
 
124 124
             if ($startbreak)
125 125
             {
126 126
                 // Break onto sales representative (new email or cid)
127 127
                 if (dol_strlen($oldemail) && $oldemail != 'none' && empty($trackthirdpartiessent[$oldsid.'|'.$oldemail]))
128 128
                 {
129
-                   	envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldtarget,$duration_value);
130
-                   	$trackthirdpartiessent[$oldsid.'|'.$oldemail]='contact id '.$oldcid;
129
+                        envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldtarget,$duration_value);
130
+                        $trackthirdpartiessent[$oldsid.'|'.$oldemail]='contact id '.$oldcid;
131 131
                 }
132 132
                 else
133
-				{
134
-                	if ($oldemail != 'none')
135
-                	{
136
-                		if (empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) print "- No email sent for '".$oldtarget."', total: ".$total."\n";
137
-                		else print "- No email sent for '".$oldtarget."', total: ".$total." (already sent to ".$trackthirdpartiessent[$oldsid.'|'.$oldemail].")\n";
138
-                	}
133
+                {
134
+                    if ($oldemail != 'none')
135
+                    {
136
+                        if (empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) print "- No email sent for '".$oldtarget."', total: ".$total."\n";
137
+                        else print "- No email sent for '".$oldtarget."', total: ".$total." (already sent to ".$trackthirdpartiessent[$oldsid.'|'.$oldemail].")\n";
138
+                    }
139 139
                 }
140 140
                 $oldemail = $newemail;
141 141
                 $oldsid  = $obj->sid;
@@ -158,14 +158,14 @@  discard block
 block discarded – undo
158 158
 
159 159
             if (dol_strlen($newemail))
160 160
             {
161
-            	$message .= $outputlangs->trans("Contract")." ".$obj->ref.": ".$outputlangs->trans("Service")." ".dol_concatdesc($obj->plabel,$obj->description)." (".price($obj->total_ttc,0,$outputlangs,0,0,-1,$conf->currency)."), ".$outputlangs->trans("DateEndPlannedShort")." ".dol_print_date($db->jdate($obj->date_fin_validite),'day')."\n\n";
162
-            	dol_syslog("email_expire_services_to_customers.php: ".$newemail." ".$message);
163
-            	$foundtoprocess++;
161
+                $message .= $outputlangs->trans("Contract")." ".$obj->ref.": ".$outputlangs->trans("Service")." ".dol_concatdesc($obj->plabel,$obj->description)." (".price($obj->total_ttc,0,$outputlangs,0,0,-1,$conf->currency)."), ".$outputlangs->trans("DateEndPlannedShort")." ".dol_print_date($db->jdate($obj->date_fin_validite),'day')."\n\n";
162
+                dol_syslog("email_expire_services_to_customers.php: ".$newemail." ".$message);
163
+                $foundtoprocess++;
164 164
             }
165 165
             print "Service to expire ".$obj->ref.", label ".dol_concatdesc($obj->plabel,$obj->description).", due date ".dol_print_date($db->jdate($obj->date_fin_validite),'day').", customer id ".$obj->sid." ".$obj->name.", ".($obj->cid?"contact id ".$obj->cid." ".$obj->clastname." ".$obj->cfirstname.", ":"")."email ".$newemail.", lang ".$outputlangs->defaultlang.": ";
166 166
             if (dol_strlen($newemail)) print "qualified.";
167 167
             else print "disqualified (no email).";
168
-			print "\n";
168
+            print "\n";
169 169
 
170 170
             unset($outputlangs);
171 171
 
@@ -179,21 +179,21 @@  discard block
 block discarded – undo
179 179
         {
180 180
             if (dol_strlen($oldemail) && $oldemail != 'none' && empty($trackthirdpartiessent[$oldsid.'|'.$oldemail]))	// Break onto email (new email)
181 181
             {
182
-       			envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldtarget,$duration_value);
183
-       			$trackthirdpartiessent[$oldsid.'|'.$oldemail]='contact id '.$oldcid;
182
+                    envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldtarget,$duration_value);
183
+                    $trackthirdpartiessent[$oldsid.'|'.$oldemail]='contact id '.$oldcid;
184 184
             }
185 185
             else
186
-			{
187
-            	if ($oldemail != 'none')
188
-            	{
189
-            		if (empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) print "- No email sent for '".$oldtarget."', total: ".$total."\n";
190
-            		else print "- No email sent for '".$oldtarget."', total: ".$total." (already sent to ".$trackthirdpartiessent[$oldsid.'|'.$oldemail].")\n";
191
-            	}
186
+            {
187
+                if ($oldemail != 'none')
188
+                {
189
+                    if (empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) print "- No email sent for '".$oldtarget."', total: ".$total."\n";
190
+                    else print "- No email sent for '".$oldtarget."', total: ".$total." (already sent to ".$trackthirdpartiessent[$oldsid.'|'.$oldemail].")\n";
191
+                }
192 192
             }
193 193
         }
194 194
     }
195 195
     else
196
-	{
196
+    {
197 197
         print "No services to expire found\n";
198 198
     }
199 199
 
@@ -233,17 +233,17 @@  discard block
 block discarded – undo
233 233
 
234 234
     if ($duration_value)
235 235
     {
236
-    	if ($duration_value > 0) $title=$newlangs->transnoentities("ListOfServicesToExpireWithDuration",$duration_value);
237
-    	else $title=$newlangs->transnoentities("ListOfServicesToExpireWithDurationNeg",$duration_value);
236
+        if ($duration_value > 0) $title=$newlangs->transnoentities("ListOfServicesToExpireWithDuration",$duration_value);
237
+        else $title=$newlangs->transnoentities("ListOfServicesToExpireWithDurationNeg",$duration_value);
238 238
     }
239 239
     else
240
-    	$title= $newlangs->transnoentities("ListOfServicesToExpire");
240
+        $title= $newlangs->transnoentities("ListOfServicesToExpire");
241 241
 
242 242
     $subject = (empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_SUBJECT)?$title:$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_SUBJECT);
243 243
     $sendto = $oldemail;
244 244
     $from = $conf->global->MAIN_MAIL_EMAIL_FROM;
245 245
     $errorsto = $conf->global->MAIN_MAIL_ERRORS_TO;
246
-	$msgishtml = -1;
246
+    $msgishtml = -1;
247 247
 
248 248
     print "- Send email to '".$oldtarget."' (".$oldemail."), total: ".$total."\n";
249 249
     dol_syslog("email_expire_services_to_customers.php: send mail to ".$oldemail);
@@ -255,19 +255,19 @@  discard block
 block discarded – undo
255 255
     $allmessage='';
256 256
     if (! empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER))
257 257
     {
258
-    	$allmessage.=$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER;
258
+        $allmessage.=$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER;
259 259
     }
260 260
     else
261
-	{
262
-    	$allmessage.= "Dear customer".($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
263
-    	$allmessage.= "Please, find a summary of the services contracted by you that are about to expire.".($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
261
+    {
262
+        $allmessage.= "Dear customer".($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
263
+        $allmessage.= "Please, find a summary of the services contracted by you that are about to expire.".($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
264 264
     }
265 265
     $allmessage.= $message.($usehtml?"<br>\n":"\n");
266 266
     //$allmessage.= $langs->trans("Total")." = ".price($total,0,$userlang,0,0,-1,$conf->currency).($usehtml?"<br>\n":"\n");
267 267
     if (! empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER))
268 268
     {
269
-    	$allmessage.=$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER;
270
-    	if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER)) $usehtml+=1;
269
+        $allmessage.=$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER;
270
+        if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER)) $usehtml+=1;
271 271
     }
272 272
 
273 273
     $mail = new CMailFile(
@@ -289,19 +289,19 @@  discard block
 block discarded – undo
289 289
     // Send or not email
290 290
     if ($mode == 'confirm')
291 291
     {
292
-    	$result=$mail->sendfile();
293
-    	if (! $result)
294
-    	{
295
-    		print "Error sending email ".$mail->error."\n";
296
-    		dol_syslog("Error sending email ".$mail->error."\n");
297
-    	}
292
+        $result=$mail->sendfile();
293
+        if (! $result)
294
+        {
295
+            print "Error sending email ".$mail->error."\n";
296
+            dol_syslog("Error sending email ".$mail->error."\n");
297
+        }
298 298
     }
299 299
     else
300 300
     {
301
-    	print "No email sent (test mode)\n";
302
-    	dol_syslog("No email sent (test mode)");
303
-    	$mail->dump_mail();
304
-    	$result=1;
301
+        print "No email sent (test mode)\n";
302
+        dol_syslog("No email sent (test mode)");
303
+        $mail->dump_mail();
304
+        $result=1;
305 305
     }
306 306
 
307 307
     unset($newlangs);
Please login to merge, or discard this patch.
Spacing   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 
28 28
 $sapi_type = php_sapi_name();
29 29
 $script_file = basename(__FILE__);
30
-$path=dirname(__FILE__).'/';
30
+$path = dirname(__FILE__).'/';
31 31
 
32 32
 // Test si mode batch
33 33
 $sapi_type = php_sapi_name();
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 	exit(-1);
37 37
 }
38 38
 
39
-if (! isset($argv[1]) || ! $argv[1] || ! in_array($argv[1],array('test','confirm')) || ! in_array($argv[2],array('thirdparties','contacts')))
39
+if (!isset($argv[1]) || !$argv[1] || !in_array($argv[1], array('test', 'confirm')) || !in_array($argv[2], array('thirdparties', 'contacts')))
40 40
 {
41 41
 	print "Usage: $script_file (test|confirm) (thirdparties|contacts) [delay] [after]\n";
42 42
 	print "\n";
@@ -46,8 +46,8 @@  discard block
 block discarded – undo
46 46
 	print "If you add param after (nb of days), only services with expired date >= today + delay are included.\n";
47 47
 	exit(-1);
48 48
 }
49
-$mode=$argv[1];
50
-$targettype=$argv[2];
49
+$mode = $argv[1];
50
+$targettype = $argv[2];
51 51
 
52 52
 
53 53
 require $path."../../htdocs/master.inc.php";
@@ -56,8 +56,8 @@  discard block
 block discarded – undo
56 56
 $langs->loadLangs(array('main', 'contracts'));
57 57
 
58 58
 // Global variables
59
-$version=DOL_VERSION;
60
-$error=0;
59
+$version = DOL_VERSION;
60
+$error = 0;
61 61
 
62 62
 
63 63
 /*
@@ -66,46 +66,46 @@  discard block
 block discarded – undo
66 66
 
67 67
 @set_time_limit(0);
68 68
 print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
69
-dol_syslog($script_file." launched with arg ".join(',',$argv));
69
+dol_syslog($script_file." launched with arg ".join(',', $argv));
70 70
 
71
-$now=dol_now('tzserver');
72
-$duration_value=isset($argv[3])?$argv[3]:'none';
73
-$duration_value2=isset($argv[4])?$argv[4]:'none';
71
+$now = dol_now('tzserver');
72
+$duration_value = isset($argv[3]) ? $argv[3] : 'none';
73
+$duration_value2 = isset($argv[4]) ? $argv[4] : 'none';
74 74
 
75 75
 $error = 0;
76
-print $script_file." launched with mode ".$mode." default lang=".$langs->defaultlang.(is_numeric($duration_value)?" delay=".$duration_value:"").(is_numeric($duration_value2)?" after=".$duration_value2:"")."\n";
76
+print $script_file." launched with mode ".$mode." default lang=".$langs->defaultlang.(is_numeric($duration_value) ? " delay=".$duration_value : "").(is_numeric($duration_value2) ? " after=".$duration_value2 : "")."\n";
77 77
 
78
-if ($mode != 'confirm') $conf->global->MAIN_DISABLE_ALL_MAILS=1;
78
+if ($mode != 'confirm') $conf->global->MAIN_DISABLE_ALL_MAILS = 1;
79 79
 
80 80
 $sql  = "SELECT c.ref, cd.date_fin_validite, cd.total_ttc, cd.description as description, p.label as plabel,";
81
-$sql.= " s.rowid as sid, s.nom as name, s.email, s.default_lang";
82
-if ($targettype == 'contacts') $sql.= ", sp.rowid as cid, sp.firstname as cfirstname, sp.lastname as clastname, sp.email as cemail";
81
+$sql .= " s.rowid as sid, s.nom as name, s.email, s.default_lang";
82
+if ($targettype == 'contacts') $sql .= ", sp.rowid as cid, sp.firstname as cfirstname, sp.lastname as clastname, sp.email as cemail";
83 83
 $sql .= " FROM ".MAIN_DB_PREFIX."societe AS s";
84
-if ($targettype == 'contacts') $sql.= ", ".MAIN_DB_PREFIX."socpeople as sp";
84
+if ($targettype == 'contacts') $sql .= ", ".MAIN_DB_PREFIX."socpeople as sp";
85 85
 $sql .= ", ".MAIN_DB_PREFIX."contrat AS c";
86 86
 $sql .= ", ".MAIN_DB_PREFIX."contratdet AS cd";
87 87
 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product AS p ON p.rowid = cd.fk_product";
88 88
 $sql .= " WHERE s.rowid = c.fk_soc AND c.rowid = cd.fk_contrat AND c.statut > 0 AND cd.statut < 5";
89
-if (is_numeric($duration_value2)) $sql.= " AND cd.date_fin_validite >= '".$db->idate(dol_time_plus_duree($now, $duration_value2, "d"))."'";
90
-if (is_numeric($duration_value)) $sql.= " AND cd.date_fin_validite < '".$db->idate(dol_time_plus_duree($now, $duration_value, "d"))."'";
91
-if ($targettype == 'contacts') $sql.= " AND s.rowid = sp.fk_soc";
92
-$sql.= " ORDER BY";
93
-if ($targettype == 'contacts') $sql.= " sp.email, sp.rowid,";
94
-$sql.= " s.email ASC, s.rowid ASC, cd.date_fin_validite ASC";	// Order by email to allow one message per email
89
+if (is_numeric($duration_value2)) $sql .= " AND cd.date_fin_validite >= '".$db->idate(dol_time_plus_duree($now, $duration_value2, "d"))."'";
90
+if (is_numeric($duration_value)) $sql .= " AND cd.date_fin_validite < '".$db->idate(dol_time_plus_duree($now, $duration_value, "d"))."'";
91
+if ($targettype == 'contacts') $sql .= " AND s.rowid = sp.fk_soc";
92
+$sql .= " ORDER BY";
93
+if ($targettype == 'contacts') $sql .= " sp.email, sp.rowid,";
94
+$sql .= " s.email ASC, s.rowid ASC, cd.date_fin_validite ASC"; // Order by email to allow one message per email
95 95
 
96 96
 //print $sql;
97
-$resql=$db->query($sql);
97
+$resql = $db->query($sql);
98 98
 if ($resql)
99 99
 {
100 100
     $num = $db->num_rows($resql);
101 101
     $i = 0;
102
-    $oldemail = 'none'; $oldsid = 0; $oldcid = 0; $oldlang='';
102
+    $oldemail = 'none'; $oldsid = 0; $oldcid = 0; $oldlang = '';
103 103
     $total = 0; $foundtoprocess = 0;
104 104
     $trackthirdpartiessent = array();
105 105
 
106 106
     print "We found ".$num." couples (services to expire-".$targettype.") qualified\n";
107 107
     dol_syslog("We found ".$num." couples (services to expire-".$targettype.") qualified");
108
-	$message='';
108
+	$message = '';
109 109
 
110 110
     if ($num)
111 111
     {
@@ -113,21 +113,21 @@  discard block
 block discarded – undo
113 113
         {
114 114
             $obj = $db->fetch_object($resql);
115 115
 
116
-            $newemail=empty($obj->cemail)?$obj->email:$obj->cemail;
116
+            $newemail = empty($obj->cemail) ? $obj->email : $obj->cemail;
117 117
 
118 118
             // Check if this record is a break after previous one
119
-            $startbreak=false;
120
-			if ($newemail <> $oldemail || $oldemail == 'none') $startbreak=true;
121
-			if ($obj->sid && $obj->sid <> $oldsid) $startbreak=true;
122
-			if ($obj->cid && $obj->cid <> $oldcid) $startbreak=true;
119
+            $startbreak = false;
120
+			if ($newemail <> $oldemail || $oldemail == 'none') $startbreak = true;
121
+			if ($obj->sid && $obj->sid <> $oldsid) $startbreak = true;
122
+			if ($obj->cid && $obj->cid <> $oldcid) $startbreak = true;
123 123
 
124 124
             if ($startbreak)
125 125
             {
126 126
                 // Break onto sales representative (new email or cid)
127 127
                 if (dol_strlen($oldemail) && $oldemail != 'none' && empty($trackthirdpartiessent[$oldsid.'|'.$oldemail]))
128 128
                 {
129
-                   	envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldtarget,$duration_value);
130
-                   	$trackthirdpartiessent[$oldsid.'|'.$oldemail]='contact id '.$oldcid;
129
+                   	envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldtarget, $duration_value);
130
+                   	$trackthirdpartiessent[$oldsid.'|'.$oldemail] = 'contact id '.$oldcid;
131 131
                 }
132 132
                 else
133 133
 				{
@@ -141,28 +141,28 @@  discard block
 block discarded – undo
141 141
                 $oldsid  = $obj->sid;
142 142
                 $oldcid  = $obj->cid;
143 143
                 $oldlang = $obj->lang;
144
-                $oldtarget=(empty($obj->cfirstname) && empty($obj->clastname))?$obj->name:($obj->clastname." ".$obj->cfirstname);
144
+                $oldtarget = (empty($obj->cfirstname) && empty($obj->clastname)) ? $obj->name : ($obj->clastname." ".$obj->cfirstname);
145 145
                 $message = '';
146 146
                 $total   = 0;
147 147
                 $foundtoprocess = 0;
148
-                $target=(empty($obj->cfirstname) && empty($obj->clastname))?$obj->name:($obj->clastname." ".$obj->cfirstname);
148
+                $target = (empty($obj->cfirstname) && empty($obj->clastname)) ? $obj->name : ($obj->clastname." ".$obj->cfirstname);
149 149
                 //if (empty($newemail)) print "Warning: Customer ".$target." has no email. Notice disabled.\n";
150 150
             }
151 151
 
152 152
             // Define line content
153
-            $outputlangs=new Translate('',$conf);
154
-            $outputlangs->setDefaultLang(empty($obj->default_lang)?$langs->defaultlang:$obj->default_lang);	// By default language of customer
153
+            $outputlangs = new Translate('', $conf);
154
+            $outputlangs->setDefaultLang(empty($obj->default_lang) ? $langs->defaultlang : $obj->default_lang); // By default language of customer
155 155
 
156 156
             // Load translation files required by the page
157 157
             $outputlangs->loadLangs(array("main", "contracts", "bills", "products"));
158 158
 
159 159
             if (dol_strlen($newemail))
160 160
             {
161
-            	$message .= $outputlangs->trans("Contract")." ".$obj->ref.": ".$outputlangs->trans("Service")." ".dol_concatdesc($obj->plabel,$obj->description)." (".price($obj->total_ttc,0,$outputlangs,0,0,-1,$conf->currency)."), ".$outputlangs->trans("DateEndPlannedShort")." ".dol_print_date($db->jdate($obj->date_fin_validite),'day')."\n\n";
161
+            	$message .= $outputlangs->trans("Contract")." ".$obj->ref.": ".$outputlangs->trans("Service")." ".dol_concatdesc($obj->plabel, $obj->description)." (".price($obj->total_ttc, 0, $outputlangs, 0, 0, -1, $conf->currency)."), ".$outputlangs->trans("DateEndPlannedShort")." ".dol_print_date($db->jdate($obj->date_fin_validite), 'day')."\n\n";
162 162
             	dol_syslog("email_expire_services_to_customers.php: ".$newemail." ".$message);
163 163
             	$foundtoprocess++;
164 164
             }
165
-            print "Service to expire ".$obj->ref.", label ".dol_concatdesc($obj->plabel,$obj->description).", due date ".dol_print_date($db->jdate($obj->date_fin_validite),'day').", customer id ".$obj->sid." ".$obj->name.", ".($obj->cid?"contact id ".$obj->cid." ".$obj->clastname." ".$obj->cfirstname.", ":"")."email ".$newemail.", lang ".$outputlangs->defaultlang.": ";
165
+            print "Service to expire ".$obj->ref.", label ".dol_concatdesc($obj->plabel, $obj->description).", due date ".dol_print_date($db->jdate($obj->date_fin_validite), 'day').", customer id ".$obj->sid." ".$obj->name.", ".($obj->cid ? "contact id ".$obj->cid." ".$obj->clastname." ".$obj->cfirstname.", " : "")."email ".$newemail.", lang ".$outputlangs->defaultlang.": ";
166 166
             if (dol_strlen($newemail)) print "qualified.";
167 167
             else print "disqualified (no email).";
168 168
 			print "\n";
@@ -179,8 +179,8 @@  discard block
 block discarded – undo
179 179
         {
180 180
             if (dol_strlen($oldemail) && $oldemail != 'none' && empty($trackthirdpartiessent[$oldsid.'|'.$oldemail]))	// Break onto email (new email)
181 181
             {
182
-       			envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldtarget,$duration_value);
183
-       			$trackthirdpartiessent[$oldsid.'|'.$oldemail]='contact id '.$oldcid;
182
+       			envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldtarget, $duration_value);
183
+       			$trackthirdpartiessent[$oldsid.'|'.$oldemail] = 'contact id '.$oldcid;
184 184
             }
185 185
             else
186 186
 			{
@@ -220,26 +220,26 @@  discard block
 block discarded – undo
220 220
  *  @param  int		$duration_value	duration value
221 221
  * 	@return	int						<0 if KO, >0 if OK
222 222
  */
223
-function envoi_mail($mode,$oldemail,$message,$total,$userlang,$oldtarget,$duration_value)
223
+function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldtarget, $duration_value)
224 224
 {
225
-    global $conf,$langs;
225
+    global $conf, $langs;
226 226
 
227
-    if (getenv('DOL_FORCE_EMAIL_TO')) $oldemail=getenv('DOL_FORCE_EMAIL_TO');
227
+    if (getenv('DOL_FORCE_EMAIL_TO')) $oldemail = getenv('DOL_FORCE_EMAIL_TO');
228 228
 
229
-    $newlangs=new Translate('',$conf);
230
-    $newlangs->setDefaultLang(empty($userlang)?(empty($conf->global->MAIN_LANG_DEFAULT)?'auto':$conf->global->MAIN_LANG_DEFAULT):$userlang);
229
+    $newlangs = new Translate('', $conf);
230
+    $newlangs->setDefaultLang(empty($userlang) ? (empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT) : $userlang);
231 231
     $newlangs->load("main");
232 232
     $newlangs->load("contracts");
233 233
 
234 234
     if ($duration_value)
235 235
     {
236
-    	if ($duration_value > 0) $title=$newlangs->transnoentities("ListOfServicesToExpireWithDuration",$duration_value);
237
-    	else $title=$newlangs->transnoentities("ListOfServicesToExpireWithDurationNeg",$duration_value);
236
+    	if ($duration_value > 0) $title = $newlangs->transnoentities("ListOfServicesToExpireWithDuration", $duration_value);
237
+    	else $title = $newlangs->transnoentities("ListOfServicesToExpireWithDurationNeg", $duration_value);
238 238
     }
239 239
     else
240
-    	$title= $newlangs->transnoentities("ListOfServicesToExpire");
240
+    	$title = $newlangs->transnoentities("ListOfServicesToExpire");
241 241
 
242
-    $subject = (empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_SUBJECT)?$title:$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_SUBJECT);
242
+    $subject = (empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_SUBJECT) ? $title : $conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_SUBJECT);
243 243
     $sendto = $oldemail;
244 244
     $from = $conf->global->MAIN_MAIL_EMAIL_FROM;
245 245
     $errorsto = $conf->global->MAIN_MAIL_ERRORS_TO;
@@ -248,26 +248,26 @@  discard block
 block discarded – undo
248 248
     print "- Send email to '".$oldtarget."' (".$oldemail."), total: ".$total."\n";
249 249
     dol_syslog("email_expire_services_to_customers.php: send mail to ".$oldemail);
250 250
 
251
-    $usehtml=0;
252
-    if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER)) $usehtml+=1;
253
-    if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER)) $usehtml+=1;
251
+    $usehtml = 0;
252
+    if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER)) $usehtml += 1;
253
+    if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER)) $usehtml += 1;
254 254
 
255
-    $allmessage='';
256
-    if (! empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER))
255
+    $allmessage = '';
256
+    if (!empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER))
257 257
     {
258
-    	$allmessage.=$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER;
258
+    	$allmessage .= $conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER;
259 259
     }
260 260
     else
261 261
 	{
262
-    	$allmessage.= "Dear customer".($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
263
-    	$allmessage.= "Please, find a summary of the services contracted by you that are about to expire.".($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
262
+    	$allmessage .= "Dear customer".($usehtml ? "<br>\n" : "\n").($usehtml ? "<br>\n" : "\n");
263
+    	$allmessage .= "Please, find a summary of the services contracted by you that are about to expire.".($usehtml ? "<br>\n" : "\n").($usehtml ? "<br>\n" : "\n");
264 264
     }
265
-    $allmessage.= $message.($usehtml?"<br>\n":"\n");
265
+    $allmessage .= $message.($usehtml ? "<br>\n" : "\n");
266 266
     //$allmessage.= $langs->trans("Total")." = ".price($total,0,$userlang,0,0,-1,$conf->currency).($usehtml?"<br>\n":"\n");
267
-    if (! empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER))
267
+    if (!empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER))
268 268
     {
269
-    	$allmessage.=$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER;
270
-    	if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER)) $usehtml+=1;
269
+    	$allmessage .= $conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER;
270
+    	if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER)) $usehtml += 1;
271 271
     }
272 272
 
273 273
     $mail = new CMailFile(
@@ -289,8 +289,8 @@  discard block
 block discarded – undo
289 289
     // Send or not email
290 290
     if ($mode == 'confirm')
291 291
     {
292
-    	$result=$mail->sendfile();
293
-    	if (! $result)
292
+    	$result = $mail->sendfile();
293
+    	if (!$result)
294 294
     	{
295 295
     		print "Error sending email ".$mail->error."\n";
296 296
     		dol_syslog("Error sending email ".$mail->error."\n");
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
     	print "No email sent (test mode)\n";
302 302
     	dol_syslog("No email sent (test mode)");
303 303
     	$mail->dump_mail();
304
-    	$result=1;
304
+    	$result = 1;
305 305
     }
306 306
 
307 307
     unset($newlangs);
Please login to merge, or discard this patch.
Braces   +74 added lines, -39 removed lines patch added patch discarded remove patch
@@ -75,22 +75,36 @@  discard block
 block discarded – undo
75 75
 $error = 0;
76 76
 print $script_file." launched with mode ".$mode." default lang=".$langs->defaultlang.(is_numeric($duration_value)?" delay=".$duration_value:"").(is_numeric($duration_value2)?" after=".$duration_value2:"")."\n";
77 77
 
78
-if ($mode != 'confirm') $conf->global->MAIN_DISABLE_ALL_MAILS=1;
78
+if ($mode != 'confirm') {
79
+    $conf->global->MAIN_DISABLE_ALL_MAILS=1;
80
+}
79 81
 
80 82
 $sql  = "SELECT c.ref, cd.date_fin_validite, cd.total_ttc, cd.description as description, p.label as plabel,";
81 83
 $sql.= " s.rowid as sid, s.nom as name, s.email, s.default_lang";
82
-if ($targettype == 'contacts') $sql.= ", sp.rowid as cid, sp.firstname as cfirstname, sp.lastname as clastname, sp.email as cemail";
84
+if ($targettype == 'contacts') {
85
+    $sql.= ", sp.rowid as cid, sp.firstname as cfirstname, sp.lastname as clastname, sp.email as cemail";
86
+}
83 87
 $sql .= " FROM ".MAIN_DB_PREFIX."societe AS s";
84
-if ($targettype == 'contacts') $sql.= ", ".MAIN_DB_PREFIX."socpeople as sp";
88
+if ($targettype == 'contacts') {
89
+    $sql.= ", ".MAIN_DB_PREFIX."socpeople as sp";
90
+}
85 91
 $sql .= ", ".MAIN_DB_PREFIX."contrat AS c";
86 92
 $sql .= ", ".MAIN_DB_PREFIX."contratdet AS cd";
87 93
 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product AS p ON p.rowid = cd.fk_product";
88 94
 $sql .= " WHERE s.rowid = c.fk_soc AND c.rowid = cd.fk_contrat AND c.statut > 0 AND cd.statut < 5";
89
-if (is_numeric($duration_value2)) $sql.= " AND cd.date_fin_validite >= '".$db->idate(dol_time_plus_duree($now, $duration_value2, "d"))."'";
90
-if (is_numeric($duration_value)) $sql.= " AND cd.date_fin_validite < '".$db->idate(dol_time_plus_duree($now, $duration_value, "d"))."'";
91
-if ($targettype == 'contacts') $sql.= " AND s.rowid = sp.fk_soc";
95
+if (is_numeric($duration_value2)) {
96
+    $sql.= " AND cd.date_fin_validite >= '".$db->idate(dol_time_plus_duree($now, $duration_value2, "d"))."'";
97
+}
98
+if (is_numeric($duration_value)) {
99
+    $sql.= " AND cd.date_fin_validite < '".$db->idate(dol_time_plus_duree($now, $duration_value, "d"))."'";
100
+}
101
+if ($targettype == 'contacts') {
102
+    $sql.= " AND s.rowid = sp.fk_soc";
103
+}
92 104
 $sql.= " ORDER BY";
93
-if ($targettype == 'contacts') $sql.= " sp.email, sp.rowid,";
105
+if ($targettype == 'contacts') {
106
+    $sql.= " sp.email, sp.rowid,";
107
+}
94 108
 $sql.= " s.email ASC, s.rowid ASC, cd.date_fin_validite ASC";	// Order by email to allow one message per email
95 109
 
96 110
 //print $sql;
@@ -117,9 +131,15 @@  discard block
 block discarded – undo
117 131
 
118 132
             // Check if this record is a break after previous one
119 133
             $startbreak=false;
120
-			if ($newemail <> $oldemail || $oldemail == 'none') $startbreak=true;
121
-			if ($obj->sid && $obj->sid <> $oldsid) $startbreak=true;
122
-			if ($obj->cid && $obj->cid <> $oldcid) $startbreak=true;
134
+			if ($newemail <> $oldemail || $oldemail == 'none') {
135
+			    $startbreak=true;
136
+			}
137
+			if ($obj->sid && $obj->sid <> $oldsid) {
138
+			    $startbreak=true;
139
+			}
140
+			if ($obj->cid && $obj->cid <> $oldcid) {
141
+			    $startbreak=true;
142
+			}
123 143
 
124 144
             if ($startbreak)
125 145
             {
@@ -128,13 +148,15 @@  discard block
 block discarded – undo
128 148
                 {
129 149
                    	envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldtarget,$duration_value);
130 150
                    	$trackthirdpartiessent[$oldsid.'|'.$oldemail]='contact id '.$oldcid;
131
-                }
132
-                else
151
+                } else
133 152
 				{
134 153
                 	if ($oldemail != 'none')
135 154
                 	{
136
-                		if (empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) print "- No email sent for '".$oldtarget."', total: ".$total."\n";
137
-                		else print "- No email sent for '".$oldtarget."', total: ".$total." (already sent to ".$trackthirdpartiessent[$oldsid.'|'.$oldemail].")\n";
155
+                		if (empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) {
156
+                		    print "- No email sent for '".$oldtarget."', total: ".$total."\n";
157
+                		} else {
158
+                		    print "- No email sent for '".$oldtarget."', total: ".$total." (already sent to ".$trackthirdpartiessent[$oldsid.'|'.$oldemail].")\n";
159
+                		}
138 160
                 	}
139 161
                 }
140 162
                 $oldemail = $newemail;
@@ -163,8 +185,11 @@  discard block
 block discarded – undo
163 185
             	$foundtoprocess++;
164 186
             }
165 187
             print "Service to expire ".$obj->ref.", label ".dol_concatdesc($obj->plabel,$obj->description).", due date ".dol_print_date($db->jdate($obj->date_fin_validite),'day').", customer id ".$obj->sid." ".$obj->name.", ".($obj->cid?"contact id ".$obj->cid." ".$obj->clastname." ".$obj->cfirstname.", ":"")."email ".$newemail.", lang ".$outputlangs->defaultlang.": ";
166
-            if (dol_strlen($newemail)) print "qualified.";
167
-            else print "disqualified (no email).";
188
+            if (dol_strlen($newemail)) {
189
+                print "qualified.";
190
+            } else {
191
+                print "disqualified (no email).";
192
+            }
168 193
 			print "\n";
169 194
 
170 195
             unset($outputlangs);
@@ -177,29 +202,31 @@  discard block
 block discarded – undo
177 202
         // Si il reste des envois en buffer
178 203
         if ($foundtoprocess)
179 204
         {
180
-            if (dol_strlen($oldemail) && $oldemail != 'none' && empty($trackthirdpartiessent[$oldsid.'|'.$oldemail]))	// Break onto email (new email)
205
+            if (dol_strlen($oldemail) && $oldemail != 'none' && empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) {
206
+                // Break onto email (new email)
181 207
             {
182 208
        			envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldtarget,$duration_value);
183
-       			$trackthirdpartiessent[$oldsid.'|'.$oldemail]='contact id '.$oldcid;
184 209
             }
185
-            else
210
+       			$trackthirdpartiessent[$oldsid.'|'.$oldemail]='contact id '.$oldcid;
211
+            } else
186 212
 			{
187 213
             	if ($oldemail != 'none')
188 214
             	{
189
-            		if (empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) print "- No email sent for '".$oldtarget."', total: ".$total."\n";
190
-            		else print "- No email sent for '".$oldtarget."', total: ".$total." (already sent to ".$trackthirdpartiessent[$oldsid.'|'.$oldemail].")\n";
215
+            		if (empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) {
216
+            		    print "- No email sent for '".$oldtarget."', total: ".$total."\n";
217
+            		} else {
218
+            		    print "- No email sent for '".$oldtarget."', total: ".$total." (already sent to ".$trackthirdpartiessent[$oldsid.'|'.$oldemail].")\n";
219
+            		}
191 220
             	}
192 221
             }
193 222
         }
194
-    }
195
-    else
223
+    } else
196 224
 	{
197 225
         print "No services to expire found\n";
198 226
     }
199 227
 
200 228
     exit(0);
201
-}
202
-else
229
+} else
203 230
 {
204 231
     dol_print_error($db);
205 232
     dol_syslog("email_expire_services_to_customers.php: Error");
@@ -224,7 +251,9 @@  discard block
 block discarded – undo
224 251
 {
225 252
     global $conf,$langs;
226 253
 
227
-    if (getenv('DOL_FORCE_EMAIL_TO')) $oldemail=getenv('DOL_FORCE_EMAIL_TO');
254
+    if (getenv('DOL_FORCE_EMAIL_TO')) {
255
+        $oldemail=getenv('DOL_FORCE_EMAIL_TO');
256
+    }
228 257
 
229 258
     $newlangs=new Translate('',$conf);
230 259
     $newlangs->setDefaultLang(empty($userlang)?(empty($conf->global->MAIN_LANG_DEFAULT)?'auto':$conf->global->MAIN_LANG_DEFAULT):$userlang);
@@ -233,11 +262,14 @@  discard block
 block discarded – undo
233 262
 
234 263
     if ($duration_value)
235 264
     {
236
-    	if ($duration_value > 0) $title=$newlangs->transnoentities("ListOfServicesToExpireWithDuration",$duration_value);
237
-    	else $title=$newlangs->transnoentities("ListOfServicesToExpireWithDurationNeg",$duration_value);
265
+    	if ($duration_value > 0) {
266
+    	    $title=$newlangs->transnoentities("ListOfServicesToExpireWithDuration",$duration_value);
267
+    	} else {
268
+    	    $title=$newlangs->transnoentities("ListOfServicesToExpireWithDurationNeg",$duration_value);
269
+    	}
270
+    } else {
271
+        	$title= $newlangs->transnoentities("ListOfServicesToExpire");
238 272
     }
239
-    else
240
-    	$title= $newlangs->transnoentities("ListOfServicesToExpire");
241 273
 
242 274
     $subject = (empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_SUBJECT)?$title:$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_SUBJECT);
243 275
     $sendto = $oldemail;
@@ -249,15 +281,18 @@  discard block
 block discarded – undo
249 281
     dol_syslog("email_expire_services_to_customers.php: send mail to ".$oldemail);
250 282
 
251 283
     $usehtml=0;
252
-    if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER)) $usehtml+=1;
253
-    if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER)) $usehtml+=1;
284
+    if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER)) {
285
+        $usehtml+=1;
286
+    }
287
+    if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER)) {
288
+        $usehtml+=1;
289
+    }
254 290
 
255 291
     $allmessage='';
256 292
     if (! empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER))
257 293
     {
258 294
     	$allmessage.=$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER;
259
-    }
260
-    else
295
+    } else
261 296
 	{
262 297
     	$allmessage.= "Dear customer".($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
263 298
     	$allmessage.= "Please, find a summary of the services contracted by you that are about to expire.".($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
@@ -267,7 +302,9 @@  discard block
 block discarded – undo
267 302
     if (! empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER))
268 303
     {
269 304
     	$allmessage.=$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER;
270
-    	if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER)) $usehtml+=1;
305
+    	if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER)) {
306
+    	    $usehtml+=1;
307
+    	}
271 308
     }
272 309
 
273 310
     $mail = new CMailFile(
@@ -295,8 +332,7 @@  discard block
 block discarded – undo
295 332
     		print "Error sending email ".$mail->error."\n";
296 333
     		dol_syslog("Error sending email ".$mail->error."\n");
297 334
     	}
298
-    }
299
-    else
335
+    } else
300 336
     {
301 337
     	print "No email sent (test mode)\n";
302 338
     	dol_syslog("No email sent (test mode)");
@@ -308,8 +344,7 @@  discard block
 block discarded – undo
308 344
     if ($result)
309 345
     {
310 346
         return 1;
311
-    }
312
-    else
347
+    } else
313 348
     {
314 349
         return -1;
315 350
     }
Please login to merge, or discard this patch.
dolibarr/scripts/contracts/email_expire_services_to_representatives.php 3 patches
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -33,17 +33,17 @@  discard block
 block discarded – undo
33 33
 $sapi_type = php_sapi_name();
34 34
 if (substr($sapi_type, 0, 3) == 'cgi') {
35 35
     echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
36
-	exit(-1);
36
+    exit(-1);
37 37
 }
38 38
 
39 39
 if (! isset($argv[1]) || ! $argv[1] || ! in_array($argv[1],array('test','confirm')))
40 40
 {
41
-	print "Usage: $script_file (test|confirm) [delay]\n";
42
-	print "\n";
43
-	print "Send an email to remind all contracts services to expire, to users that are sale representative for.\n";
44
-	print "If you choose 'test' mode, no emails are sent.\n";
45
-	print "If you add a delay (nb of days), only services with expired date < today + delay are included.\n";
46
-	exit(-1);
41
+    print "Usage: $script_file (test|confirm) [delay]\n";
42
+    print "\n";
43
+    print "Send an email to remind all contracts services to expire, to users that are sale representative for.\n";
44
+    print "If you choose 'test' mode, no emails are sent.\n";
45
+    print "If you add a delay (nb of days), only services with expired date < today + delay are included.\n";
46
+    exit(-1);
47 47
 }
48 48
 $mode=$argv[1];
49 49
 
@@ -90,9 +90,9 @@  discard block
 block discarded – undo
90 90
     $i = 0;
91 91
     $oldemail = 'none'; $olduid = 0; $oldlang='';
92 92
     $total = 0; $foundtoprocess = 0;
93
-	print "We found ".$num." couples (services to expire - sale representative) qualified\n";
93
+    print "We found ".$num." couples (services to expire - sale representative) qualified\n";
94 94
     dol_syslog("We found ".$num." couples (services to expire - sale representative) qualified");
95
-	$message='';
95
+    $message='';
96 96
 
97 97
     if ($num)
98 98
     {
@@ -105,11 +105,11 @@  discard block
 block discarded – undo
105 105
                 // Break onto sales representative (new email or uid)
106 106
                 if (dol_strlen($oldemail) && $oldemail != 'none')
107 107
                 {
108
-                   	envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldsalerepresentative,$duration_value);
108
+                        envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldsalerepresentative,$duration_value);
109 109
                 }
110 110
                 else
111
-				{
112
-					if ($oldemail != 'none') print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n";
111
+                {
112
+                    if ($oldemail != 'none') print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n";
113 113
                 }
114 114
                 $oldemail = $obj->email;
115 115
                 $olduid = $obj->uid;
@@ -131,18 +131,18 @@  discard block
 block discarded – undo
131 131
 
132 132
             if (dol_strlen($obj->email))
133 133
             {
134
-            	$message .= $outputlangs->trans("Contract")." ".$obj->ref.": ".$langs->trans("Service")." ".dol_concatdesc($obj->plabel,$obj->description)." (".price($obj->total_ttc,0,$outputlangs,0,0,-1,$conf->currency).") ".$obj->name.", ".$outputlangs->trans("DateEndPlannedShort")." ".dol_print_date($db->jdate($obj->date_fin_validite),'day')."\n\n";
135
-            	dol_syslog("email_expire_services_to_representatives.php: ".$obj->email);
136
-            	$foundtoprocess++;
134
+                $message .= $outputlangs->trans("Contract")." ".$obj->ref.": ".$langs->trans("Service")." ".dol_concatdesc($obj->plabel,$obj->description)." (".price($obj->total_ttc,0,$outputlangs,0,0,-1,$conf->currency).") ".$obj->name.", ".$outputlangs->trans("DateEndPlannedShort")." ".dol_print_date($db->jdate($obj->date_fin_validite),'day')."\n\n";
135
+                dol_syslog("email_expire_services_to_representatives.php: ".$obj->email);
136
+                $foundtoprocess++;
137 137
             }
138 138
             print "Service to expire ".$obj->ref.", label ".dol_concatdesc($obj->plabel,$obj->description).", due date ".dol_print_date($db->jdate($obj->date_fin_validite),'day')." (linked to company ".$obj->name.", sale representative ".dolGetFirstLastname($obj->firstname, $obj->lastname).", email ".$obj->email."): ";
139 139
             if (dol_strlen($obj->email)) print "qualified.";
140 140
             else print "disqualified (no email).";
141
-			print "\n";
141
+            print "\n";
142 142
 
143
-			unset($outputlangs);
143
+            unset($outputlangs);
144 144
 
145
-			$total += $obj->total_ttc;
145
+            $total += $obj->total_ttc;
146 146
             $i++;
147 147
         }
148 148
 
@@ -151,16 +151,16 @@  discard block
 block discarded – undo
151 151
         {
152 152
             if (dol_strlen($oldemail) && $oldemail != 'none')	// Break onto email (new email)
153 153
             {
154
-       			envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldsalerepresentative,$duration_value);
154
+                    envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldsalerepresentative,$duration_value);
155 155
             }
156 156
             else
157
-			{
158
-            	if ($oldemail != 'none') print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n";
157
+            {
158
+                if ($oldemail != 'none') print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n";
159 159
             }
160 160
         }
161 161
     }
162 162
     else
163
-	{
163
+    {
164 164
         print "No services to expire (for companies linked to a particular commercial dolibarr user) found\n";
165 165
     }
166 166
 
@@ -194,23 +194,23 @@  discard block
 block discarded – undo
194 194
     if (getenv('DOL_FORCE_EMAIL_TO')) $oldemail=getenv('DOL_FORCE_EMAIL_TO');
195 195
 
196 196
     $newlangs=new Translate('',$conf);
197
-	$newlangs->setDefaultLang(empty($userlang)?(empty($conf->global->MAIN_LANG_DEFAULT)?'auto':$conf->global->MAIN_LANG_DEFAULT):$userlang);
197
+    $newlangs->setDefaultLang(empty($userlang)?(empty($conf->global->MAIN_LANG_DEFAULT)?'auto':$conf->global->MAIN_LANG_DEFAULT):$userlang);
198 198
     $newlangs->load("main");
199 199
     $newlangs->load("contracts");
200 200
 
201 201
     if ($duration_value)
202 202
     {
203
-    	if ($duration_value > 0) $title=$newlangs->transnoentities("ListOfServicesToExpireWithDuration",$duration_value);
204
-    	else $title=$newlangs->transnoentities("ListOfServicesToExpireWithDurationNeg",$duration_value);
203
+        if ($duration_value > 0) $title=$newlangs->transnoentities("ListOfServicesToExpireWithDuration",$duration_value);
204
+        else $title=$newlangs->transnoentities("ListOfServicesToExpireWithDurationNeg",$duration_value);
205 205
     }
206 206
     else
207
-    	$title= $newlangs->transnoentities("ListOfServicesToExpire");
207
+        $title= $newlangs->transnoentities("ListOfServicesToExpire");
208 208
 
209 209
     $subject = (empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_SUBJECT)?$title:$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_SUBJECT);
210 210
     $sendto = $oldemail;
211 211
     $from = $conf->global->MAIN_MAIL_EMAIL_FROM;
212 212
     $errorsto = $conf->global->MAIN_MAIL_ERRORS_TO;
213
-	$msgishtml = -1;
213
+    $msgishtml = -1;
214 214
 
215 215
     print "- Send email for ".$oldsalerepresentative." (".$oldemail."), total: ".$total."\n";
216 216
     dol_syslog("email_expire_services_to_representatives.php: send mail to ".$oldemail);
@@ -222,19 +222,19 @@  discard block
 block discarded – undo
222 222
     $allmessage='';
223 223
     if (! empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_HEADER))
224 224
     {
225
-    	$allmessage.=$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_HEADER;
225
+        $allmessage.=$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_HEADER;
226 226
     }
227 227
     else
228 228
     {
229
-    	$allmessage.= $title.($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
230
-    	$allmessage.= $newlangs->transnoentities("NoteListOfYourExpiredServices").($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
229
+        $allmessage.= $title.($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
230
+        $allmessage.= $newlangs->transnoentities("NoteListOfYourExpiredServices").($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
231 231
     }
232 232
     $allmessage.= $message.($usehtml?"<br>\n":"\n");
233 233
     $allmessage.= $langs->trans("Total")." = ".price($total,0,$userlang,0,0,-1,$conf->currency).($usehtml?"<br>\n":"\n");
234 234
     if (! empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER))
235 235
     {
236
-    	$allmessage.=$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER;
237
-    	if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER)) $usehtml+=1;
236
+        $allmessage.=$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER;
237
+        if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER)) $usehtml+=1;
238 238
     }
239 239
 
240 240
     $mail = new CMailFile(
@@ -256,19 +256,19 @@  discard block
 block discarded – undo
256 256
     // Send or not email
257 257
     if ($mode == 'confirm')
258 258
     {
259
-    	$result=$mail->sendfile();
260
-    	if (! $result)
261
-    	{
262
-    		print "Error sending email ".$mail->error."\n";
263
-    		dol_syslog("Error sending email ".$mail->error."\n");
264
-    	}
259
+        $result=$mail->sendfile();
260
+        if (! $result)
261
+        {
262
+            print "Error sending email ".$mail->error."\n";
263
+            dol_syslog("Error sending email ".$mail->error."\n");
264
+        }
265 265
     }
266 266
     else
267 267
     {
268
-    	print "No email sent (test mode)\n";
269
-    	dol_syslog("No email sent (test mode)");
270
-    	$mail->dump_mail();
271
-    	$result=1;
268
+        print "No email sent (test mode)\n";
269
+        dol_syslog("No email sent (test mode)");
270
+        $mail->dump_mail();
271
+        $result=1;
272 272
     }
273 273
 
274 274
     if ($result)
Please login to merge, or discard this patch.
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 
28 28
 $sapi_type = php_sapi_name();
29 29
 $script_file = basename(__FILE__);
30
-$path=dirname(__FILE__).'/';
30
+$path = dirname(__FILE__).'/';
31 31
 
32 32
 // Test si mode batch
33 33
 $sapi_type = php_sapi_name();
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 	exit(-1);
37 37
 }
38 38
 
39
-if (! isset($argv[1]) || ! $argv[1] || ! in_array($argv[1],array('test','confirm')))
39
+if (!isset($argv[1]) || !$argv[1] || !in_array($argv[1], array('test', 'confirm')))
40 40
 {
41 41
 	print "Usage: $script_file (test|confirm) [delay]\n";
42 42
 	print "\n";
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 	print "If you add a delay (nb of days), only services with expired date < today + delay are included.\n";
46 46
 	exit(-1);
47 47
 }
48
-$mode=$argv[1];
48
+$mode = $argv[1];
49 49
 
50 50
 
51 51
 require $path."../../htdocs/master.inc.php";
@@ -54,8 +54,8 @@  discard block
 block discarded – undo
54 54
 $langs->loadLangs(array('main', 'contracts'));
55 55
 
56 56
 // Global variables
57
-$version=DOL_VERSION;
58
-$error=0;
57
+$version = DOL_VERSION;
58
+$error = 0;
59 59
 
60 60
 
61 61
 /*
@@ -64,35 +64,35 @@  discard block
 block discarded – undo
64 64
 
65 65
 @set_time_limit(0);
66 66
 print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
67
-dol_syslog($script_file." launched with arg ".join(',',$argv));
67
+dol_syslog($script_file." launched with arg ".join(',', $argv));
68 68
 
69
-$now=dol_now('tzserver');
70
-$duration_value=isset($argv[2])?$argv[2]:'none';
69
+$now = dol_now('tzserver');
70
+$duration_value = isset($argv[2]) ? $argv[2] : 'none';
71 71
 
72
-print $script_file." launched with mode ".$mode." default lang=".$langs->defaultlang.(is_numeric($duration_value)?" delay=".$duration_value:"")."\n";
72
+print $script_file." launched with mode ".$mode." default lang=".$langs->defaultlang.(is_numeric($duration_value) ? " delay=".$duration_value : "")."\n";
73 73
 
74
-if ($mode != 'confirm') $conf->global->MAIN_DISABLE_ALL_MAILS=1;
74
+if ($mode != 'confirm') $conf->global->MAIN_DISABLE_ALL_MAILS = 1;
75 75
 
76
-$sql  = "SELECT DISTINCT c.ref, c.fk_soc, cd.date_fin_validite, cd.total_ttc, cd.description as description, p.label as plabel, s.rowid, s.nom as name, s.email, s.default_lang,";
77
-$sql.= " u.rowid as uid, u.lastname, u.firstname, u.email, u.lang";
78
-$sql.= " FROM ".MAIN_DB_PREFIX."societe AS s, ".MAIN_DB_PREFIX."contrat AS c, ".MAIN_DB_PREFIX."contratdet AS cd";
79
-$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product AS p ON p.rowid = cd.fk_product, ".MAIN_DB_PREFIX."societe_commerciaux AS sc, ".MAIN_DB_PREFIX."user AS u";
80
-$sql.= " WHERE s.rowid = c.fk_soc AND c.rowid = cd.fk_contrat AND c.statut > 0 AND cd.statut<5";
76
+$sql = "SELECT DISTINCT c.ref, c.fk_soc, cd.date_fin_validite, cd.total_ttc, cd.description as description, p.label as plabel, s.rowid, s.nom as name, s.email, s.default_lang,";
77
+$sql .= " u.rowid as uid, u.lastname, u.firstname, u.email, u.lang";
78
+$sql .= " FROM ".MAIN_DB_PREFIX."societe AS s, ".MAIN_DB_PREFIX."contrat AS c, ".MAIN_DB_PREFIX."contratdet AS cd";
79
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product AS p ON p.rowid = cd.fk_product, ".MAIN_DB_PREFIX."societe_commerciaux AS sc, ".MAIN_DB_PREFIX."user AS u";
80
+$sql .= " WHERE s.rowid = c.fk_soc AND c.rowid = cd.fk_contrat AND c.statut > 0 AND cd.statut<5";
81 81
 if (is_numeric($duration_value)) $sql .= " AND cd.date_fin_validite < '".$db->idate(dol_time_plus_duree($now, $duration_value, "d"))."'";
82
-$sql.= " AND sc.fk_soc = s.rowid AND sc.fk_user = u.rowid";
83
-$sql .= " ORDER BY u.email ASC, s.rowid ASC, c.ref ASC";	// Order by email to allow one message per email
82
+$sql .= " AND sc.fk_soc = s.rowid AND sc.fk_user = u.rowid";
83
+$sql .= " ORDER BY u.email ASC, s.rowid ASC, c.ref ASC"; // Order by email to allow one message per email
84 84
 
85 85
 //print $sql;
86
-$resql=$db->query($sql);
86
+$resql = $db->query($sql);
87 87
 if ($resql)
88 88
 {
89 89
     $num = $db->num_rows($resql);
90 90
     $i = 0;
91
-    $oldemail = 'none'; $olduid = 0; $oldlang='';
91
+    $oldemail = 'none'; $olduid = 0; $oldlang = '';
92 92
     $total = 0; $foundtoprocess = 0;
93 93
 	print "We found ".$num." couples (services to expire - sale representative) qualified\n";
94 94
     dol_syslog("We found ".$num." couples (services to expire - sale representative) qualified");
95
-	$message='';
95
+	$message = '';
96 96
 
97 97
     if ($num)
98 98
     {
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
                 // Break onto sales representative (new email or uid)
106 106
                 if (dol_strlen($oldemail) && $oldemail != 'none')
107 107
                 {
108
-                   	envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldsalerepresentative,$duration_value);
108
+                   	envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldsalerepresentative, $duration_value);
109 109
                 }
110 110
                 else
111 111
 				{
@@ -114,28 +114,28 @@  discard block
 block discarded – undo
114 114
                 $oldemail = $obj->email;
115 115
                 $olduid = $obj->uid;
116 116
                 $oldlang = $obj->lang;
117
-                $oldsalerepresentative=dolGetFirstLastname($obj->firstname, $obj->lastname);
117
+                $oldsalerepresentative = dolGetFirstLastname($obj->firstname, $obj->lastname);
118 118
                 $message = '';
119 119
                 $total = 0;
120 120
                 $foundtoprocess = 0;
121
-                $salerepresentative=dolGetFirstLastname($obj->firstname, $obj->lastname);
121
+                $salerepresentative = dolGetFirstLastname($obj->firstname, $obj->lastname);
122 122
                 if (empty($obj->email)) print "Warning: Sale representative ".$salerepresentative." has no email. Notice disabled.\n";
123 123
             }
124 124
 
125 125
             // Define line content
126
-            $outputlangs=new Translate('',$conf);
127
-            $outputlangs->setDefaultLang(empty($obj->lang)?$langs->defaultlang:$obj->lang);	// By default language of sale representative
126
+            $outputlangs = new Translate('', $conf);
127
+            $outputlangs->setDefaultLang(empty($obj->lang) ? $langs->defaultlang : $obj->lang); // By default language of sale representative
128 128
 
129 129
             // Load translation files required by the page
130 130
             $outputlangs->loadLangs(array("main", "contracts", "bills", "products"));
131 131
 
132 132
             if (dol_strlen($obj->email))
133 133
             {
134
-            	$message .= $outputlangs->trans("Contract")." ".$obj->ref.": ".$langs->trans("Service")." ".dol_concatdesc($obj->plabel,$obj->description)." (".price($obj->total_ttc,0,$outputlangs,0,0,-1,$conf->currency).") ".$obj->name.", ".$outputlangs->trans("DateEndPlannedShort")." ".dol_print_date($db->jdate($obj->date_fin_validite),'day')."\n\n";
134
+            	$message .= $outputlangs->trans("Contract")." ".$obj->ref.": ".$langs->trans("Service")." ".dol_concatdesc($obj->plabel, $obj->description)." (".price($obj->total_ttc, 0, $outputlangs, 0, 0, -1, $conf->currency).") ".$obj->name.", ".$outputlangs->trans("DateEndPlannedShort")." ".dol_print_date($db->jdate($obj->date_fin_validite), 'day')."\n\n";
135 135
             	dol_syslog("email_expire_services_to_representatives.php: ".$obj->email);
136 136
             	$foundtoprocess++;
137 137
             }
138
-            print "Service to expire ".$obj->ref.", label ".dol_concatdesc($obj->plabel,$obj->description).", due date ".dol_print_date($db->jdate($obj->date_fin_validite),'day')." (linked to company ".$obj->name.", sale representative ".dolGetFirstLastname($obj->firstname, $obj->lastname).", email ".$obj->email."): ";
138
+            print "Service to expire ".$obj->ref.", label ".dol_concatdesc($obj->plabel, $obj->description).", due date ".dol_print_date($db->jdate($obj->date_fin_validite), 'day')." (linked to company ".$obj->name.", sale representative ".dolGetFirstLastname($obj->firstname, $obj->lastname).", email ".$obj->email."): ";
139 139
             if (dol_strlen($obj->email)) print "qualified.";
140 140
             else print "disqualified (no email).";
141 141
 			print "\n";
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
         {
152 152
             if (dol_strlen($oldemail) && $oldemail != 'none')	// Break onto email (new email)
153 153
             {
154
-       			envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldsalerepresentative,$duration_value);
154
+       			envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldsalerepresentative, $duration_value);
155 155
             }
156 156
             else
157 157
 			{
@@ -187,26 +187,26 @@  discard block
 block discarded – undo
187 187
  *  @param  int		$duration_value			duration value
188 188
  * 	@return	int						<0 if KO, >0 if OK
189 189
  */
190
-function envoi_mail($mode,$oldemail,$message,$total,$userlang,$oldsalerepresentative,$duration_value)
190
+function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldsalerepresentative, $duration_value)
191 191
 {
192
-    global $conf,$langs;
192
+    global $conf, $langs;
193 193
 
194
-    if (getenv('DOL_FORCE_EMAIL_TO')) $oldemail=getenv('DOL_FORCE_EMAIL_TO');
194
+    if (getenv('DOL_FORCE_EMAIL_TO')) $oldemail = getenv('DOL_FORCE_EMAIL_TO');
195 195
 
196
-    $newlangs=new Translate('',$conf);
197
-	$newlangs->setDefaultLang(empty($userlang)?(empty($conf->global->MAIN_LANG_DEFAULT)?'auto':$conf->global->MAIN_LANG_DEFAULT):$userlang);
196
+    $newlangs = new Translate('', $conf);
197
+	$newlangs->setDefaultLang(empty($userlang) ? (empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT) : $userlang);
198 198
     $newlangs->load("main");
199 199
     $newlangs->load("contracts");
200 200
 
201 201
     if ($duration_value)
202 202
     {
203
-    	if ($duration_value > 0) $title=$newlangs->transnoentities("ListOfServicesToExpireWithDuration",$duration_value);
204
-    	else $title=$newlangs->transnoentities("ListOfServicesToExpireWithDurationNeg",$duration_value);
203
+    	if ($duration_value > 0) $title = $newlangs->transnoentities("ListOfServicesToExpireWithDuration", $duration_value);
204
+    	else $title = $newlangs->transnoentities("ListOfServicesToExpireWithDurationNeg", $duration_value);
205 205
     }
206 206
     else
207
-    	$title= $newlangs->transnoentities("ListOfServicesToExpire");
207
+    	$title = $newlangs->transnoentities("ListOfServicesToExpire");
208 208
 
209
-    $subject = (empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_SUBJECT)?$title:$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_SUBJECT);
209
+    $subject = (empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_SUBJECT) ? $title : $conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_SUBJECT);
210 210
     $sendto = $oldemail;
211 211
     $from = $conf->global->MAIN_MAIL_EMAIL_FROM;
212 212
     $errorsto = $conf->global->MAIN_MAIL_ERRORS_TO;
@@ -215,26 +215,26 @@  discard block
 block discarded – undo
215 215
     print "- Send email for ".$oldsalerepresentative." (".$oldemail."), total: ".$total."\n";
216 216
     dol_syslog("email_expire_services_to_representatives.php: send mail to ".$oldemail);
217 217
 
218
-    $usehtml=0;
219
-    if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER)) $usehtml+=1;
220
-    if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_HEADER)) $usehtml+=1;
218
+    $usehtml = 0;
219
+    if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER)) $usehtml += 1;
220
+    if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_HEADER)) $usehtml += 1;
221 221
 
222
-    $allmessage='';
223
-    if (! empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_HEADER))
222
+    $allmessage = '';
223
+    if (!empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_HEADER))
224 224
     {
225
-    	$allmessage.=$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_HEADER;
225
+    	$allmessage .= $conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_HEADER;
226 226
     }
227 227
     else
228 228
     {
229
-    	$allmessage.= $title.($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
230
-    	$allmessage.= $newlangs->transnoentities("NoteListOfYourExpiredServices").($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
229
+    	$allmessage .= $title.($usehtml ? "<br>\n" : "\n").($usehtml ? "<br>\n" : "\n");
230
+    	$allmessage .= $newlangs->transnoentities("NoteListOfYourExpiredServices").($usehtml ? "<br>\n" : "\n").($usehtml ? "<br>\n" : "\n");
231 231
     }
232
-    $allmessage.= $message.($usehtml?"<br>\n":"\n");
233
-    $allmessage.= $langs->trans("Total")." = ".price($total,0,$userlang,0,0,-1,$conf->currency).($usehtml?"<br>\n":"\n");
234
-    if (! empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER))
232
+    $allmessage .= $message.($usehtml ? "<br>\n" : "\n");
233
+    $allmessage .= $langs->trans("Total")." = ".price($total, 0, $userlang, 0, 0, -1, $conf->currency).($usehtml ? "<br>\n" : "\n");
234
+    if (!empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER))
235 235
     {
236
-    	$allmessage.=$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER;
237
-    	if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER)) $usehtml+=1;
236
+    	$allmessage .= $conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER;
237
+    	if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER)) $usehtml += 1;
238 238
     }
239 239
 
240 240
     $mail = new CMailFile(
@@ -256,8 +256,8 @@  discard block
 block discarded – undo
256 256
     // Send or not email
257 257
     if ($mode == 'confirm')
258 258
     {
259
-    	$result=$mail->sendfile();
260
-    	if (! $result)
259
+    	$result = $mail->sendfile();
260
+    	if (!$result)
261 261
     	{
262 262
     		print "Error sending email ".$mail->error."\n";
263 263
     		dol_syslog("Error sending email ".$mail->error."\n");
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
     	print "No email sent (test mode)\n";
269 269
     	dol_syslog("No email sent (test mode)");
270 270
     	$mail->dump_mail();
271
-    	$result=1;
271
+    	$result = 1;
272 272
     }
273 273
 
274 274
     if ($result)
Please login to merge, or discard this patch.
Braces   +48 added lines, -29 removed lines patch added patch discarded remove patch
@@ -71,14 +71,18 @@  discard block
 block discarded – undo
71 71
 
72 72
 print $script_file." launched with mode ".$mode." default lang=".$langs->defaultlang.(is_numeric($duration_value)?" delay=".$duration_value:"")."\n";
73 73
 
74
-if ($mode != 'confirm') $conf->global->MAIN_DISABLE_ALL_MAILS=1;
74
+if ($mode != 'confirm') {
75
+    $conf->global->MAIN_DISABLE_ALL_MAILS=1;
76
+}
75 77
 
76 78
 $sql  = "SELECT DISTINCT c.ref, c.fk_soc, cd.date_fin_validite, cd.total_ttc, cd.description as description, p.label as plabel, s.rowid, s.nom as name, s.email, s.default_lang,";
77 79
 $sql.= " u.rowid as uid, u.lastname, u.firstname, u.email, u.lang";
78 80
 $sql.= " FROM ".MAIN_DB_PREFIX."societe AS s, ".MAIN_DB_PREFIX."contrat AS c, ".MAIN_DB_PREFIX."contratdet AS cd";
79 81
 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product AS p ON p.rowid = cd.fk_product, ".MAIN_DB_PREFIX."societe_commerciaux AS sc, ".MAIN_DB_PREFIX."user AS u";
80 82
 $sql.= " WHERE s.rowid = c.fk_soc AND c.rowid = cd.fk_contrat AND c.statut > 0 AND cd.statut<5";
81
-if (is_numeric($duration_value)) $sql .= " AND cd.date_fin_validite < '".$db->idate(dol_time_plus_duree($now, $duration_value, "d"))."'";
83
+if (is_numeric($duration_value)) {
84
+    $sql .= " AND cd.date_fin_validite < '".$db->idate(dol_time_plus_duree($now, $duration_value, "d"))."'";
85
+}
82 86
 $sql.= " AND sc.fk_soc = s.rowid AND sc.fk_user = u.rowid";
83 87
 $sql .= " ORDER BY u.email ASC, s.rowid ASC, c.ref ASC";	// Order by email to allow one message per email
84 88
 
@@ -106,10 +110,11 @@  discard block
 block discarded – undo
106 110
                 if (dol_strlen($oldemail) && $oldemail != 'none')
107 111
                 {
108 112
                    	envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldsalerepresentative,$duration_value);
109
-                }
110
-                else
113
+                } else
111 114
 				{
112
-					if ($oldemail != 'none') print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n";
115
+					if ($oldemail != 'none') {
116
+					    print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n";
117
+					}
113 118
                 }
114 119
                 $oldemail = $obj->email;
115 120
                 $olduid = $obj->uid;
@@ -119,7 +124,9 @@  discard block
 block discarded – undo
119 124
                 $total = 0;
120 125
                 $foundtoprocess = 0;
121 126
                 $salerepresentative=dolGetFirstLastname($obj->firstname, $obj->lastname);
122
-                if (empty($obj->email)) print "Warning: Sale representative ".$salerepresentative." has no email. Notice disabled.\n";
127
+                if (empty($obj->email)) {
128
+                    print "Warning: Sale representative ".$salerepresentative." has no email. Notice disabled.\n";
129
+                }
123 130
             }
124 131
 
125 132
             // Define line content
@@ -136,8 +143,11 @@  discard block
 block discarded – undo
136 143
             	$foundtoprocess++;
137 144
             }
138 145
             print "Service to expire ".$obj->ref.", label ".dol_concatdesc($obj->plabel,$obj->description).", due date ".dol_print_date($db->jdate($obj->date_fin_validite),'day')." (linked to company ".$obj->name.", sale representative ".dolGetFirstLastname($obj->firstname, $obj->lastname).", email ".$obj->email."): ";
139
-            if (dol_strlen($obj->email)) print "qualified.";
140
-            else print "disqualified (no email).";
146
+            if (dol_strlen($obj->email)) {
147
+                print "qualified.";
148
+            } else {
149
+                print "disqualified (no email).";
150
+            }
141 151
 			print "\n";
142 152
 
143 153
 			unset($outputlangs);
@@ -149,24 +159,25 @@  discard block
 block discarded – undo
149 159
         // Si il reste des envois en buffer
150 160
         if ($foundtoprocess)
151 161
         {
152
-            if (dol_strlen($oldemail) && $oldemail != 'none')	// Break onto email (new email)
162
+            if (dol_strlen($oldemail) && $oldemail != 'none') {
163
+                // Break onto email (new email)
153 164
             {
154 165
        			envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldsalerepresentative,$duration_value);
155 166
             }
156
-            else
167
+            } else
157 168
 			{
158
-            	if ($oldemail != 'none') print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n";
169
+            	if ($oldemail != 'none') {
170
+            	    print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n";
171
+            	}
159 172
             }
160 173
         }
161
-    }
162
-    else
174
+    } else
163 175
 	{
164 176
         print "No services to expire (for companies linked to a particular commercial dolibarr user) found\n";
165 177
     }
166 178
 
167 179
     exit(0);
168
-}
169
-else
180
+} else
170 181
 {
171 182
     dol_print_error($db);
172 183
     dol_syslog("email_expire_services_to_representatives.php: Error");
@@ -191,7 +202,9 @@  discard block
 block discarded – undo
191 202
 {
192 203
     global $conf,$langs;
193 204
 
194
-    if (getenv('DOL_FORCE_EMAIL_TO')) $oldemail=getenv('DOL_FORCE_EMAIL_TO');
205
+    if (getenv('DOL_FORCE_EMAIL_TO')) {
206
+        $oldemail=getenv('DOL_FORCE_EMAIL_TO');
207
+    }
195 208
 
196 209
     $newlangs=new Translate('',$conf);
197 210
 	$newlangs->setDefaultLang(empty($userlang)?(empty($conf->global->MAIN_LANG_DEFAULT)?'auto':$conf->global->MAIN_LANG_DEFAULT):$userlang);
@@ -200,11 +213,14 @@  discard block
 block discarded – undo
200 213
 
201 214
     if ($duration_value)
202 215
     {
203
-    	if ($duration_value > 0) $title=$newlangs->transnoentities("ListOfServicesToExpireWithDuration",$duration_value);
204
-    	else $title=$newlangs->transnoentities("ListOfServicesToExpireWithDurationNeg",$duration_value);
216
+    	if ($duration_value > 0) {
217
+    	    $title=$newlangs->transnoentities("ListOfServicesToExpireWithDuration",$duration_value);
218
+    	} else {
219
+    	    $title=$newlangs->transnoentities("ListOfServicesToExpireWithDurationNeg",$duration_value);
220
+    	}
221
+    } else {
222
+        	$title= $newlangs->transnoentities("ListOfServicesToExpire");
205 223
     }
206
-    else
207
-    	$title= $newlangs->transnoentities("ListOfServicesToExpire");
208 224
 
209 225
     $subject = (empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_SUBJECT)?$title:$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_SUBJECT);
210 226
     $sendto = $oldemail;
@@ -216,15 +232,18 @@  discard block
 block discarded – undo
216 232
     dol_syslog("email_expire_services_to_representatives.php: send mail to ".$oldemail);
217 233
 
218 234
     $usehtml=0;
219
-    if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER)) $usehtml+=1;
220
-    if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_HEADER)) $usehtml+=1;
235
+    if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER)) {
236
+        $usehtml+=1;
237
+    }
238
+    if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_HEADER)) {
239
+        $usehtml+=1;
240
+    }
221 241
 
222 242
     $allmessage='';
223 243
     if (! empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_HEADER))
224 244
     {
225 245
     	$allmessage.=$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_HEADER;
226
-    }
227
-    else
246
+    } else
228 247
     {
229 248
     	$allmessage.= $title.($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
230 249
     	$allmessage.= $newlangs->transnoentities("NoteListOfYourExpiredServices").($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
@@ -234,7 +253,9 @@  discard block
 block discarded – undo
234 253
     if (! empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER))
235 254
     {
236 255
     	$allmessage.=$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER;
237
-    	if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER)) $usehtml+=1;
256
+    	if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER)) {
257
+    	    $usehtml+=1;
258
+    	}
238 259
     }
239 260
 
240 261
     $mail = new CMailFile(
@@ -262,8 +283,7 @@  discard block
 block discarded – undo
262 283
     		print "Error sending email ".$mail->error."\n";
263 284
     		dol_syslog("Error sending email ".$mail->error."\n");
264 285
     	}
265
-    }
266
-    else
286
+    } else
267 287
     {
268 288
     	print "No email sent (test mode)\n";
269 289
     	dol_syslog("No email sent (test mode)");
@@ -274,8 +294,7 @@  discard block
 block discarded – undo
274 294
     if ($result)
275 295
     {
276 296
         return 1;
277
-    }
278
-    else
297
+    } else
279 298
     {
280 299
         return -1;
281 300
     }
Please login to merge, or discard this patch.
dolibarr/scripts/invoices/rebuild_merge_pdf.php 3 patches
Indentation   +136 added lines, -136 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 // Test if batch mode
31 31
 if (substr($sapi_type, 0, 3) == 'cgi') {
32 32
     echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
33
-	exit(-1);
33
+    exit(-1);
34 34
 }
35 35
 
36 36
 // Include Dolibarr environment
@@ -62,8 +62,8 @@  discard block
 block discarded – undo
62 62
 // Check parameters
63 63
 if (! isset($argv[1]))
64 64
 {
65
-	usage();
66
-	exit(-1);
65
+    usage();
66
+    exit(-1);
67 67
 }
68 68
 
69 69
 $diroutputpdf=$conf->facture->dir_output . '/temp';
@@ -75,98 +75,98 @@  discard block
 block discarded – undo
75 75
 
76 76
 foreach ($argv as $key => $value)
77 77
 {
78
-	$found=false;
79
-
80
-	// Define options
81
-	if (preg_match('/^lang=/i',$value))
82
-	{
83
-		$found=true;
84
-		$valarray=explode('=',$value);
85
-		$newlangid=$valarray[1];
86
-		print 'Use language '.$newlangid.".\n";
87
-	}
88
-	if (preg_match('/^prefix=/i',$value))
89
-	{
90
-		$found=true;
91
-		$valarray=explode('=',$value);
92
-		$fileprefix=$valarray[1];
93
-		print 'Use prefix for filename '.$fileprefix.".\n";
94
-	}
95
-
96
-	if (preg_match('/^regenerate=(.*)/i',$value,$reg))
97
-	{
98
-	    if (! in_array($reg[1],array('','0','no')))
99
-	    {
100
-		    $found=true;
101
-		    $regenerate=$reg[1];
102
-		    print 'Regeneration of PDF is requested with template '.$regenerate."\n";
103
-	    }
104
-	}
105
-
106
-	if ($value == 'filter=all')
107
-	{
108
-		$found=true;
109
-		$option.=(empty($option)?'':'_').'all';
110
-		$filter[]='all';
111
-
112
-		print 'Rebuild PDF for all invoices'."\n";
113
-	}
114
-
115
-	if ($value == 'filter=date')
116
-	{
117
-		$found=true;
118
-		$option.=(empty($option)?'':'_').'date_'.$argv[$key+1].'_'.$argv[$key+2];
119
-		$filter[]='date';
120
-
121
-		$dateafterdate=dol_stringtotime($argv[$key+1]);
122
-		$datebeforedate=dol_stringtotime($argv[$key+2]);
123
-		print 'Rebuild PDF for invoices validated between '.dol_print_date($dateafterdate,'day','gmt')." and ".dol_print_date($datebeforedate,'day','gmt').".\n";
124
-	}
125
-
126
-	if ($value == 'filter=payments')
127
-	{
128
-		$found=true;
129
-		$option.=(empty($option)?'':'_').'payments_'.$argv[$key+1].'_'.$argv[$key+2];
130
-		$filter[]='payments';
131
-
132
-		$paymentdateafter=dol_stringtotime($argv[$key+1].'000000');
133
-		$paymentdatebefore=dol_stringtotime($argv[$key+2].'235959');
134
-		if (empty($paymentdateafter) || empty($paymentdatebefore))
135
-		{
136
-			print 'Error: Bad date format or value'."\n";
137
-			exit(-1);
138
-		}
139
-		print 'Rebuild PDF for invoices with at least one payment between '.dol_print_date($paymentdateafter,'day','gmt')." and ".dol_print_date($paymentdatebefore,'day','gmt').".\n";
140
-	}
141
-
142
-	if ($value == 'filter=nopayment')
143
-	{
144
-		$found=true;
145
-		$option.=(empty($option)?'':'_').'nopayment';
146
-		$filter[]='nopayment';
147
-
148
-		print 'Rebuild PDF for invoices with no payment done yet.'."\n";
149
-	}
150
-
151
-	if ($value == 'filter=bank')
152
-	{
153
-		$found=true;
154
-		$option.=(empty($option)?'':'_').'bank_'.$argv[$key+1];
155
-		$filter[]='bank';
156
-
157
-		$paymentonbankref=$argv[$key+1];
158
-		$bankaccount=new Account($db);
159
-		$result=$bankaccount->fetch(0,$paymentonbankref);
160
-		if ($result <= 0)
161
-		{
162
-			print 'Error: Bank account with ref "'.$paymentonbankref.'" not found'."\n";
163
-			exit(-1);
164
-		}
165
-		$paymentonbankid=$bankaccount->id;
166
-		print 'Rebuild PDF for invoices with at least one payment on financial account '.$bankaccount->ref."\n";
167
-	}
168
-
169
-	if ($value == 'filter=nodeposit')
78
+    $found=false;
79
+
80
+    // Define options
81
+    if (preg_match('/^lang=/i',$value))
82
+    {
83
+        $found=true;
84
+        $valarray=explode('=',$value);
85
+        $newlangid=$valarray[1];
86
+        print 'Use language '.$newlangid.".\n";
87
+    }
88
+    if (preg_match('/^prefix=/i',$value))
89
+    {
90
+        $found=true;
91
+        $valarray=explode('=',$value);
92
+        $fileprefix=$valarray[1];
93
+        print 'Use prefix for filename '.$fileprefix.".\n";
94
+    }
95
+
96
+    if (preg_match('/^regenerate=(.*)/i',$value,$reg))
97
+    {
98
+        if (! in_array($reg[1],array('','0','no')))
99
+        {
100
+            $found=true;
101
+            $regenerate=$reg[1];
102
+            print 'Regeneration of PDF is requested with template '.$regenerate."\n";
103
+        }
104
+    }
105
+
106
+    if ($value == 'filter=all')
107
+    {
108
+        $found=true;
109
+        $option.=(empty($option)?'':'_').'all';
110
+        $filter[]='all';
111
+
112
+        print 'Rebuild PDF for all invoices'."\n";
113
+    }
114
+
115
+    if ($value == 'filter=date')
116
+    {
117
+        $found=true;
118
+        $option.=(empty($option)?'':'_').'date_'.$argv[$key+1].'_'.$argv[$key+2];
119
+        $filter[]='date';
120
+
121
+        $dateafterdate=dol_stringtotime($argv[$key+1]);
122
+        $datebeforedate=dol_stringtotime($argv[$key+2]);
123
+        print 'Rebuild PDF for invoices validated between '.dol_print_date($dateafterdate,'day','gmt')." and ".dol_print_date($datebeforedate,'day','gmt').".\n";
124
+    }
125
+
126
+    if ($value == 'filter=payments')
127
+    {
128
+        $found=true;
129
+        $option.=(empty($option)?'':'_').'payments_'.$argv[$key+1].'_'.$argv[$key+2];
130
+        $filter[]='payments';
131
+
132
+        $paymentdateafter=dol_stringtotime($argv[$key+1].'000000');
133
+        $paymentdatebefore=dol_stringtotime($argv[$key+2].'235959');
134
+        if (empty($paymentdateafter) || empty($paymentdatebefore))
135
+        {
136
+            print 'Error: Bad date format or value'."\n";
137
+            exit(-1);
138
+        }
139
+        print 'Rebuild PDF for invoices with at least one payment between '.dol_print_date($paymentdateafter,'day','gmt')." and ".dol_print_date($paymentdatebefore,'day','gmt').".\n";
140
+    }
141
+
142
+    if ($value == 'filter=nopayment')
143
+    {
144
+        $found=true;
145
+        $option.=(empty($option)?'':'_').'nopayment';
146
+        $filter[]='nopayment';
147
+
148
+        print 'Rebuild PDF for invoices with no payment done yet.'."\n";
149
+    }
150
+
151
+    if ($value == 'filter=bank')
152
+    {
153
+        $found=true;
154
+        $option.=(empty($option)?'':'_').'bank_'.$argv[$key+1];
155
+        $filter[]='bank';
156
+
157
+        $paymentonbankref=$argv[$key+1];
158
+        $bankaccount=new Account($db);
159
+        $result=$bankaccount->fetch(0,$paymentonbankref);
160
+        if ($result <= 0)
161
+        {
162
+            print 'Error: Bank account with ref "'.$paymentonbankref.'" not found'."\n";
163
+            exit(-1);
164
+        }
165
+        $paymentonbankid=$bankaccount->id;
166
+        print 'Rebuild PDF for invoices with at least one payment on financial account '.$bankaccount->ref."\n";
167
+    }
168
+
169
+    if ($value == 'filter=nodeposit')
170 170
     {
171 171
         $found=true;
172 172
         $option.=(empty($option)?'':'_').'nodeposit';
@@ -193,48 +193,48 @@  discard block
 block discarded – undo
193 193
 
194 194
     if ($value == 'filter=excludethirdparties')
195 195
     {
196
-    	$found=true;
197
-    	$filter[]='excludethirdparties';
196
+        $found=true;
197
+        $filter[]='excludethirdparties';
198 198
 
199
-    	$thirdpartiesid=explode(',',$argv[$key+1]);
200
-    	print 'Exclude thirdparties with id in list ('.join(',',$thirdpartiesid).").\n";
199
+        $thirdpartiesid=explode(',',$argv[$key+1]);
200
+        print 'Exclude thirdparties with id in list ('.join(',',$thirdpartiesid).").\n";
201 201
 
202
-    	$option.=(empty($option)?'':'_').'excludethirdparties'.join('-',$thirdpartiesid);
202
+        $option.=(empty($option)?'':'_').'excludethirdparties'.join('-',$thirdpartiesid);
203 203
     }
204 204
     if ($value == 'filter=onlythirdparties')
205 205
     {
206
-    	$found=true;
207
-    	$filter[]='onlythirdparties';
206
+        $found=true;
207
+        $filter[]='onlythirdparties';
208 208
 
209
-    	$thirdpartiesid=explode(',',$argv[$key+1]);
210
-    	print 'Only thirdparties with id in list ('.join(',',$thirdpartiesid).").\n";
209
+        $thirdpartiesid=explode(',',$argv[$key+1]);
210
+        print 'Only thirdparties with id in list ('.join(',',$thirdpartiesid).").\n";
211 211
 
212
-    	$option.=(empty($option)?'':'_').'onlythirdparty'.join('-',$thirdpartiesid);
212
+        $option.=(empty($option)?'':'_').'onlythirdparty'.join('-',$thirdpartiesid);
213 213
     }
214 214
 
215
-	if (! $found && preg_match('/filter=/i',$value))
216
-	{
217
-		usage();
218
-		exit(-1);
219
-	}
215
+    if (! $found && preg_match('/filter=/i',$value))
216
+    {
217
+        usage();
218
+        exit(-1);
219
+    }
220 220
 }
221 221
 
222 222
 // Check if an option and a filter has been provided
223 223
 if (empty($option) && count($filter) <= 0)
224 224
 {
225
-	usage();
226
-	exit(-1);
225
+    usage();
226
+    exit(-1);
227 227
 }
228 228
 // Check if there is no uncompatible choice
229 229
 if (in_array('payments',$filter) && in_array('nopayment',$filter))
230 230
 {
231
-	usage();
232
-	exit(-1);
231
+    usage();
232
+    exit(-1);
233 233
 }
234 234
 if (in_array('bank',$filter) && in_array('nopayment',$filter))
235 235
 {
236
-	usage();
237
-	exit(-1);
236
+    usage();
237
+    exit(-1);
238 238
 }
239 239
 
240 240
 
@@ -248,13 +248,13 @@  discard block
 block discarded – undo
248 248
 
249 249
 if ($result >= 0)
250 250
 {
251
-	$error=0;
252
-	print '--- end ok'."\n";
251
+    $error=0;
252
+    print '--- end ok'."\n";
253 253
 }
254 254
 else
255 255
 {
256
-	$error=$result;
257
-	print '--- end error code='.$error."\n";
256
+    $error=$result;
257
+    print '--- end error code='.$error."\n";
258 258
 }
259 259
 
260 260
 $db->close();
@@ -270,20 +270,20 @@  discard block
 block discarded – undo
270 270
  */
271 271
 function usage()
272 272
 {
273
-	global $script_file;
273
+    global $script_file;
274 274
 
275 275
     print "Rebuild PDF files for some invoices and merge PDF files into one.\n";
276
-	print "\n";
277
-	print "To build/merge PDF for invoices in a date range:\n";
278
-	print "Usage:   ".$script_file." filter=date dateafter datebefore\n";
279
-	print "To build/merge PDF for invoices with at least one payment in a date range:\n";
280
-	print "Usage:   ".$script_file." filter=payments dateafter datebefore\n";
281
-	print "To build/merge PDF for invoices with at least one payment onto a bank account:\n";
282
-	print "Usage:   ".$script_file." filter=bank bankref\n";
283
-	print "To build/merge PDF for all invoices, use filter=all\n";
284
-	print "Usage:   ".$script_file." filter=all\n";
285
-	print "To build/merge PDF for invoices with no payments, use filter=nopayment\n";
286
-	print "Usage:   ".$script_file." filter=nopayment\n";
276
+    print "\n";
277
+    print "To build/merge PDF for invoices in a date range:\n";
278
+    print "Usage:   ".$script_file." filter=date dateafter datebefore\n";
279
+    print "To build/merge PDF for invoices with at least one payment in a date range:\n";
280
+    print "Usage:   ".$script_file." filter=payments dateafter datebefore\n";
281
+    print "To build/merge PDF for invoices with at least one payment onto a bank account:\n";
282
+    print "Usage:   ".$script_file." filter=bank bankref\n";
283
+    print "To build/merge PDF for all invoices, use filter=all\n";
284
+    print "Usage:   ".$script_file." filter=all\n";
285
+    print "To build/merge PDF for invoices with no payments, use filter=nopayment\n";
286
+    print "Usage:   ".$script_file." filter=nopayment\n";
287 287
     print "To exclude credit notes, use filter=nocreditnote\n";
288 288
     print "To exclude replacement invoices, use filter=noreplacement\n";
289 289
     print "To exclude deposit invoices, use filter=nodeposit\n";
@@ -293,8 +293,8 @@  discard block
 block discarded – undo
293 293
     print "To generate invoices in a language, use lang=xx_XX\n";
294 294
     print "To set prefix of generated file name, use prefix=myfileprefix\n";
295 295
     print "\n";
296
-	print "Example: ".$script_file." filter=payments 20080101 20081231 lang=fr_FR regenerate=crabe\n";
297
-	print "Example: ".$script_file." filter=all lang=en_US\n";
298
-	print "\n";
299
-	print "Note that some filters can be cumulated.\n";
296
+    print "Example: ".$script_file." filter=payments 20080101 20081231 lang=fr_FR regenerate=crabe\n";
297
+    print "Example: ".$script_file." filter=all lang=en_US\n";
298
+    print "\n";
299
+    print "Note that some filters can be cumulated.\n";
300 300
 }
Please login to merge, or discard this patch.
Spacing   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 
26 26
 $sapi_type = php_sapi_name();
27 27
 $script_file = basename(__FILE__);
28
-$path=dirname(__FILE__).'/';
28
+$path = dirname(__FILE__).'/';
29 29
 
30 30
 // Test if batch mode
31 31
 if (substr($sapi_type, 0, 3) == 'cgi') {
@@ -46,8 +46,8 @@  discard block
 block discarded – undo
46 46
 $langs->load("main");
47 47
 
48 48
 // Global variables
49
-$version=DOL_VERSION;
50
-$error=0;
49
+$version = DOL_VERSION;
50
+$error = 0;
51 51
 
52 52
 
53 53
 
@@ -57,162 +57,162 @@  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 ".join(',',$argv));
60
+dol_syslog($script_file." launched with arg ".join(',', $argv));
61 61
 
62 62
 // Check parameters
63
-if (! isset($argv[1]))
63
+if (!isset($argv[1]))
64 64
 {
65 65
 	usage();
66 66
 	exit(-1);
67 67
 }
68 68
 
69
-$diroutputpdf=$conf->facture->dir_output . '/temp';
70
-$newlangid='en_EN';	// To force a new lang id
71
-$filter=array();
72
-$regenerate='';		// Ask regenerate (contains name of model to use)
73
-$option='';
74
-$fileprefix='mergedpdf';
69
+$diroutputpdf = $conf->facture->dir_output.'/temp';
70
+$newlangid = 'en_EN'; // To force a new lang id
71
+$filter = array();
72
+$regenerate = ''; // Ask regenerate (contains name of model to use)
73
+$option = '';
74
+$fileprefix = 'mergedpdf';
75 75
 
76 76
 foreach ($argv as $key => $value)
77 77
 {
78
-	$found=false;
78
+	$found = false;
79 79
 
80 80
 	// Define options
81
-	if (preg_match('/^lang=/i',$value))
81
+	if (preg_match('/^lang=/i', $value))
82 82
 	{
83
-		$found=true;
84
-		$valarray=explode('=',$value);
85
-		$newlangid=$valarray[1];
83
+		$found = true;
84
+		$valarray = explode('=', $value);
85
+		$newlangid = $valarray[1];
86 86
 		print 'Use language '.$newlangid.".\n";
87 87
 	}
88
-	if (preg_match('/^prefix=/i',$value))
88
+	if (preg_match('/^prefix=/i', $value))
89 89
 	{
90
-		$found=true;
91
-		$valarray=explode('=',$value);
92
-		$fileprefix=$valarray[1];
90
+		$found = true;
91
+		$valarray = explode('=', $value);
92
+		$fileprefix = $valarray[1];
93 93
 		print 'Use prefix for filename '.$fileprefix.".\n";
94 94
 	}
95 95
 
96
-	if (preg_match('/^regenerate=(.*)/i',$value,$reg))
96
+	if (preg_match('/^regenerate=(.*)/i', $value, $reg))
97 97
 	{
98
-	    if (! in_array($reg[1],array('','0','no')))
98
+	    if (!in_array($reg[1], array('', '0', 'no')))
99 99
 	    {
100
-		    $found=true;
101
-		    $regenerate=$reg[1];
100
+		    $found = true;
101
+		    $regenerate = $reg[1];
102 102
 		    print 'Regeneration of PDF is requested with template '.$regenerate."\n";
103 103
 	    }
104 104
 	}
105 105
 
106 106
 	if ($value == 'filter=all')
107 107
 	{
108
-		$found=true;
109
-		$option.=(empty($option)?'':'_').'all';
110
-		$filter[]='all';
108
+		$found = true;
109
+		$option .= (empty($option) ? '' : '_').'all';
110
+		$filter[] = 'all';
111 111
 
112 112
 		print 'Rebuild PDF for all invoices'."\n";
113 113
 	}
114 114
 
115 115
 	if ($value == 'filter=date')
116 116
 	{
117
-		$found=true;
118
-		$option.=(empty($option)?'':'_').'date_'.$argv[$key+1].'_'.$argv[$key+2];
119
-		$filter[]='date';
117
+		$found = true;
118
+		$option .= (empty($option) ? '' : '_').'date_'.$argv[$key + 1].'_'.$argv[$key + 2];
119
+		$filter[] = 'date';
120 120
 
121
-		$dateafterdate=dol_stringtotime($argv[$key+1]);
122
-		$datebeforedate=dol_stringtotime($argv[$key+2]);
123
-		print 'Rebuild PDF for invoices validated between '.dol_print_date($dateafterdate,'day','gmt')." and ".dol_print_date($datebeforedate,'day','gmt').".\n";
121
+		$dateafterdate = dol_stringtotime($argv[$key + 1]);
122
+		$datebeforedate = dol_stringtotime($argv[$key + 2]);
123
+		print 'Rebuild PDF for invoices validated between '.dol_print_date($dateafterdate, 'day', 'gmt')." and ".dol_print_date($datebeforedate, 'day', 'gmt').".\n";
124 124
 	}
125 125
 
126 126
 	if ($value == 'filter=payments')
127 127
 	{
128
-		$found=true;
129
-		$option.=(empty($option)?'':'_').'payments_'.$argv[$key+1].'_'.$argv[$key+2];
130
-		$filter[]='payments';
128
+		$found = true;
129
+		$option .= (empty($option) ? '' : '_').'payments_'.$argv[$key + 1].'_'.$argv[$key + 2];
130
+		$filter[] = 'payments';
131 131
 
132
-		$paymentdateafter=dol_stringtotime($argv[$key+1].'000000');
133
-		$paymentdatebefore=dol_stringtotime($argv[$key+2].'235959');
132
+		$paymentdateafter = dol_stringtotime($argv[$key + 1].'000000');
133
+		$paymentdatebefore = dol_stringtotime($argv[$key + 2].'235959');
134 134
 		if (empty($paymentdateafter) || empty($paymentdatebefore))
135 135
 		{
136 136
 			print 'Error: Bad date format or value'."\n";
137 137
 			exit(-1);
138 138
 		}
139
-		print 'Rebuild PDF for invoices with at least one payment between '.dol_print_date($paymentdateafter,'day','gmt')." and ".dol_print_date($paymentdatebefore,'day','gmt').".\n";
139
+		print 'Rebuild PDF for invoices with at least one payment between '.dol_print_date($paymentdateafter, 'day', 'gmt')." and ".dol_print_date($paymentdatebefore, 'day', 'gmt').".\n";
140 140
 	}
141 141
 
142 142
 	if ($value == 'filter=nopayment')
143 143
 	{
144
-		$found=true;
145
-		$option.=(empty($option)?'':'_').'nopayment';
146
-		$filter[]='nopayment';
144
+		$found = true;
145
+		$option .= (empty($option) ? '' : '_').'nopayment';
146
+		$filter[] = 'nopayment';
147 147
 
148 148
 		print 'Rebuild PDF for invoices with no payment done yet.'."\n";
149 149
 	}
150 150
 
151 151
 	if ($value == 'filter=bank')
152 152
 	{
153
-		$found=true;
154
-		$option.=(empty($option)?'':'_').'bank_'.$argv[$key+1];
155
-		$filter[]='bank';
153
+		$found = true;
154
+		$option .= (empty($option) ? '' : '_').'bank_'.$argv[$key + 1];
155
+		$filter[] = 'bank';
156 156
 
157
-		$paymentonbankref=$argv[$key+1];
158
-		$bankaccount=new Account($db);
159
-		$result=$bankaccount->fetch(0,$paymentonbankref);
157
+		$paymentonbankref = $argv[$key + 1];
158
+		$bankaccount = new Account($db);
159
+		$result = $bankaccount->fetch(0, $paymentonbankref);
160 160
 		if ($result <= 0)
161 161
 		{
162 162
 			print 'Error: Bank account with ref "'.$paymentonbankref.'" not found'."\n";
163 163
 			exit(-1);
164 164
 		}
165
-		$paymentonbankid=$bankaccount->id;
165
+		$paymentonbankid = $bankaccount->id;
166 166
 		print 'Rebuild PDF for invoices with at least one payment on financial account '.$bankaccount->ref."\n";
167 167
 	}
168 168
 
169 169
 	if ($value == 'filter=nodeposit')
170 170
     {
171
-        $found=true;
172
-        $option.=(empty($option)?'':'_').'nodeposit';
173
-        $filter[]='nodeposit';
171
+        $found = true;
172
+        $option .= (empty($option) ? '' : '_').'nodeposit';
173
+        $filter[] = 'nodeposit';
174 174
 
175 175
         print 'Exclude deposit invoices'."\n";
176 176
     }
177 177
     if ($value == 'filter=noreplacement')
178 178
     {
179
-        $found=true;
180
-        $option.=(empty($option)?'':'_').'noreplacement';
181
-        $filter[]='noreplacement';
179
+        $found = true;
180
+        $option .= (empty($option) ? '' : '_').'noreplacement';
181
+        $filter[] = 'noreplacement';
182 182
 
183 183
         print 'Exclude replacement invoices'."\n";
184 184
     }
185 185
     if ($value == 'filter=nocreditnote')
186 186
     {
187
-        $found=true;
188
-        $option.=(empty($option)?'':'_').'nocreditnote';
189
-        $filter[]='nocreditnote';
187
+        $found = true;
188
+        $option .= (empty($option) ? '' : '_').'nocreditnote';
189
+        $filter[] = 'nocreditnote';
190 190
 
191 191
         print 'Exclude credit note invoices'."\n";
192 192
     }
193 193
 
194 194
     if ($value == 'filter=excludethirdparties')
195 195
     {
196
-    	$found=true;
197
-    	$filter[]='excludethirdparties';
196
+    	$found = true;
197
+    	$filter[] = 'excludethirdparties';
198 198
 
199
-    	$thirdpartiesid=explode(',',$argv[$key+1]);
200
-    	print 'Exclude thirdparties with id in list ('.join(',',$thirdpartiesid).").\n";
199
+    	$thirdpartiesid = explode(',', $argv[$key + 1]);
200
+    	print 'Exclude thirdparties with id in list ('.join(',', $thirdpartiesid).").\n";
201 201
 
202
-    	$option.=(empty($option)?'':'_').'excludethirdparties'.join('-',$thirdpartiesid);
202
+    	$option .= (empty($option) ? '' : '_').'excludethirdparties'.join('-', $thirdpartiesid);
203 203
     }
204 204
     if ($value == 'filter=onlythirdparties')
205 205
     {
206
-    	$found=true;
207
-    	$filter[]='onlythirdparties';
206
+    	$found = true;
207
+    	$filter[] = 'onlythirdparties';
208 208
 
209
-    	$thirdpartiesid=explode(',',$argv[$key+1]);
210
-    	print 'Only thirdparties with id in list ('.join(',',$thirdpartiesid).").\n";
209
+    	$thirdpartiesid = explode(',', $argv[$key + 1]);
210
+    	print 'Only thirdparties with id in list ('.join(',', $thirdpartiesid).").\n";
211 211
 
212
-    	$option.=(empty($option)?'':'_').'onlythirdparty'.join('-',$thirdpartiesid);
212
+    	$option .= (empty($option) ? '' : '_').'onlythirdparty'.join('-', $thirdpartiesid);
213 213
     }
214 214
 
215
-	if (! $found && preg_match('/filter=/i',$value))
215
+	if (!$found && preg_match('/filter=/i', $value))
216 216
 	{
217 217
 		usage();
218 218
 		exit(-1);
@@ -226,12 +226,12 @@  discard block
 block discarded – undo
226 226
 	exit(-1);
227 227
 }
228 228
 // Check if there is no uncompatible choice
229
-if (in_array('payments',$filter) && in_array('nopayment',$filter))
229
+if (in_array('payments', $filter) && in_array('nopayment', $filter))
230 230
 {
231 231
 	usage();
232 232
 	exit(-1);
233 233
 }
234
-if (in_array('bank',$filter) && in_array('nopayment',$filter))
234
+if (in_array('bank', $filter) && in_array('nopayment', $filter))
235 235
 {
236 236
 	usage();
237 237
 	exit(-1);
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
 
241 241
 // Define SQL and SQL request to select invoices
242 242
 // Use $filter, $dateafterdate, datebeforedate, $paymentdateafter, $paymentdatebefore
243
-$result=rebuild_merge_pdf($db, $langs, $conf, $diroutputpdf, $newlangid, $filter, $dateafterdate, $datebeforedate, $paymentdateafter, $paymentdatebefore, 1, $regenerate, $option, $paymentonbankid, $thirdpartiesid, $fileprefix);
243
+$result = rebuild_merge_pdf($db, $langs, $conf, $diroutputpdf, $newlangid, $filter, $dateafterdate, $datebeforedate, $paymentdateafter, $paymentdatebefore, 1, $regenerate, $option, $paymentonbankid, $thirdpartiesid, $fileprefix);
244 244
 
245 245
 
246 246
 
@@ -248,12 +248,12 @@  discard block
 block discarded – undo
248 248
 
249 249
 if ($result >= 0)
250 250
 {
251
-	$error=0;
251
+	$error = 0;
252 252
 	print '--- end ok'."\n";
253 253
 }
254 254
 else
255 255
 {
256
-	$error=$result;
256
+	$error = $result;
257 257
 	print '--- end error code='.$error."\n";
258 258
 }
259 259
 
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -250,8 +250,7 @@
 block discarded – undo
250 250
 {
251 251
 	$error=0;
252 252
 	print '--- end ok'."\n";
253
-}
254
-else
253
+} else
255 254
 {
256 255
 	$error=$result;
257 256
 	print '--- end error code='.$error."\n";
Please login to merge, or discard this patch.
dolibarr/scripts/invoices/email_unpaid_invoices_to_representatives.php 3 patches
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -33,17 +33,17 @@  discard block
 block discarded – undo
33 33
 $sapi_type = php_sapi_name();
34 34
 if (substr($sapi_type, 0, 3) == 'cgi') {
35 35
     echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
36
-	exit(-1);
36
+    exit(-1);
37 37
 }
38 38
 
39 39
 if (! isset($argv[1]) || ! $argv[1] || ! in_array($argv[1],array('test','confirm')))
40 40
 {
41
-	print "Usage: $script_file (test|confirm) [delay]\n";
42
-	print "\n";
43
-	print "Send an email to users to remind all unpaid customer invoices user is sale representative for.\n";
44
-	print "If you choose 'test' mode, no emails are sent.\n";
45
-	print "If you add a delay (nb of days), only invoice with due date < today + delay are included.\n";
46
-	exit(-1);
41
+    print "Usage: $script_file (test|confirm) [delay]\n";
42
+    print "\n";
43
+    print "Send an email to users to remind all unpaid customer invoices user is sale representative for.\n";
44
+    print "If you choose 'test' mode, no emails are sent.\n";
45
+    print "If you add a delay (nb of days), only invoice with due date < today + delay are included.\n";
46
+    exit(-1);
47 47
 }
48 48
 $mode=$argv[1];
49 49
 
@@ -96,9 +96,9 @@  discard block
 block discarded – undo
96 96
     $i = 0;
97 97
     $oldemail = 'none'; $olduid = 0; $oldlang='';
98 98
     $total = 0; $foundtoprocess = 0;
99
-	print "We found ".$num." couples (unpayed validated invoice - sale representative) qualified\n";
99
+    print "We found ".$num." couples (unpayed validated invoice - sale representative) qualified\n";
100 100
     dol_syslog("We found ".$num." couples (unpayed validated invoice - sale representative) qualified");
101
-	$message='';
101
+    $message='';
102 102
 
103 103
     if ($num)
104 104
     {
@@ -111,11 +111,11 @@  discard block
 block discarded – undo
111 111
                 // Break onto sales representative (new email or uid)
112 112
                 if (dol_strlen($oldemail) && $oldemail != 'none')
113 113
                 {
114
-                   	envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldsalerepresentative);
114
+                        envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldsalerepresentative);
115 115
                 }
116 116
                 else
117
-				{
118
-					if ($oldemail != 'none') print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n";
117
+                {
118
+                    if ($oldemail != 'none') print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n";
119 119
                 }
120 120
                 $oldemail = $obj->email;
121 121
                 $olduid = $obj->uid;
@@ -137,16 +137,16 @@  discard block
 block discarded – undo
137 137
 
138 138
             if (dol_strlen($obj->email))
139 139
             {
140
-            	$message .= $outputlangs->trans("Invoice")." ".$obj->ref." : ".price($obj->total_ttc,0,$outputlangs,0,0,-1,$conf->currency)." : ".$obj->name."\n";
141
-            	dol_syslog("email_unpaid_invoices_to_representatives.php: ".$obj->email);
142
-            	$foundtoprocess++;
140
+                $message .= $outputlangs->trans("Invoice")." ".$obj->ref." : ".price($obj->total_ttc,0,$outputlangs,0,0,-1,$conf->currency)." : ".$obj->name."\n";
141
+                dol_syslog("email_unpaid_invoices_to_representatives.php: ".$obj->email);
142
+                $foundtoprocess++;
143 143
             }
144 144
             print "Unpaid invoice ".$obj->ref.", price ".price2num($obj->total_ttc).", due date ".dol_print_date($db->jdate($obj->due_date),'day')." (linked to company ".$obj->name.", sale representative ".dolGetFirstLastname($obj->firstname, $obj->lastname).", email ".$obj->email.", lang ".$outputlangs->defaultlang."): ";
145 145
             if (dol_strlen($obj->email)) print "qualified.";
146 146
             else print "disqualified (no email).";
147
-			print "\n";
147
+            print "\n";
148 148
 
149
-			unset($outputlangs);
149
+            unset($outputlangs);
150 150
 
151 151
             $total += $obj->total_ttc;
152 152
             $i++;
@@ -157,16 +157,16 @@  discard block
 block discarded – undo
157 157
         {
158 158
             if (dol_strlen($oldemail) && $oldemail != 'none')	// Break onto email (new email)
159 159
             {
160
-       			envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldsalerepresentative);
160
+                    envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldsalerepresentative);
161 161
             }
162 162
             else
163
-			{
164
-            	if ($oldemail != 'none') print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n";
163
+            {
164
+                if ($oldemail != 'none') print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n";
165 165
             }
166 166
         }
167 167
     }
168 168
     else
169
-	{
169
+    {
170 170
         print "No unpaid invoices (for companies linked to a particular commercial dolibarr user) found\n";
171 171
     }
172 172
 
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
     $sendto = $oldemail;
208 208
     $from = $conf->global->MAIN_MAIL_EMAIL_FROM;
209 209
     $errorsto = $conf->global->MAIN_MAIL_ERRORS_TO;
210
-	$msgishtml = -1;
210
+    $msgishtml = -1;
211 211
 
212 212
     print "- Send email for ".$oldsalerepresentative." (".$oldemail."), total: ".$total."\n";
213 213
     dol_syslog("email_unpaid_invoices_to_representatives.php: send mail to ".$oldemail);
@@ -219,19 +219,19 @@  discard block
 block discarded – undo
219 219
     $allmessage='';
220 220
     if (! empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER))
221 221
     {
222
-    	$allmessage.=$conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER;
222
+        $allmessage.=$conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER;
223 223
     }
224 224
     else
225 225
     {
226
-    	$allmessage.= $newlangs->transnoentities("ListOfYourUnpaidInvoices").($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
227
-    	$allmessage.= $newlangs->transnoentities("NoteListOfYourUnpaidInvoices").($usehtml?"<br>\n":"\n");
226
+        $allmessage.= $newlangs->transnoentities("ListOfYourUnpaidInvoices").($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
227
+        $allmessage.= $newlangs->transnoentities("NoteListOfYourUnpaidInvoices").($usehtml?"<br>\n":"\n");
228 228
     }
229 229
     $allmessage.= $message.($usehtml?"<br>\n":"\n");
230 230
     $allmessage.= $langs->trans("Total")." = ".price($total,0,$newlangs,0,0,-1,$conf->currency).($usehtml?"<br>\n":"\n");
231 231
     if (! empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER))
232 232
     {
233
-    	$allmessage.=$conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER;
234
-    	if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER)) $usehtml+=1;
233
+        $allmessage.=$conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER;
234
+        if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER)) $usehtml+=1;
235 235
     }
236 236
 
237 237
     $mail = new CMailFile(
@@ -253,19 +253,19 @@  discard block
 block discarded – undo
253 253
     // Send or not email
254 254
     if ($mode == 'confirm')
255 255
     {
256
-    	$result=$mail->sendfile();
257
-    	if (! $result)
258
-    	{
259
-    		print "Error sending email ".$mail->error."\n";
260
-    		dol_syslog("Error sending email ".$mail->error."\n");
261
-    	}
256
+        $result=$mail->sendfile();
257
+        if (! $result)
258
+        {
259
+            print "Error sending email ".$mail->error."\n";
260
+            dol_syslog("Error sending email ".$mail->error."\n");
261
+        }
262 262
     }
263 263
     else
264 264
     {
265
-    	print "No email sent (test mode)\n";
266
-    	dol_syslog("No email sent (test mode)");
267
-    	$mail->dump_mail();
268
-    	$result=1;
265
+        print "No email sent (test mode)\n";
266
+        dol_syslog("No email sent (test mode)");
267
+        $mail->dump_mail();
268
+        $result=1;
269 269
     }
270 270
 
271 271
     if ($result)
Please login to merge, or discard this patch.
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 
28 28
 $sapi_type = php_sapi_name();
29 29
 $script_file = basename(__FILE__);
30
-$path=dirname(__FILE__).'/';
30
+$path = dirname(__FILE__).'/';
31 31
 
32 32
 // Test si mode batch
33 33
 $sapi_type = php_sapi_name();
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 	exit(-1);
37 37
 }
38 38
 
39
-if (! isset($argv[1]) || ! $argv[1] || ! in_array($argv[1],array('test','confirm')))
39
+if (!isset($argv[1]) || !$argv[1] || !in_array($argv[1], array('test', 'confirm')))
40 40
 {
41 41
 	print "Usage: $script_file (test|confirm) [delay]\n";
42 42
 	print "\n";
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 	print "If you add a delay (nb of days), only invoice with due date < today + delay are included.\n";
46 46
 	exit(-1);
47 47
 }
48
-$mode=$argv[1];
48
+$mode = $argv[1];
49 49
 
50 50
 
51 51
 require $path."../../htdocs/master.inc.php";
@@ -55,8 +55,8 @@  discard block
 block discarded – undo
55 55
 
56 56
 
57 57
 // Global variables
58
-$version=DOL_VERSION;
59
-$error=0;
58
+$version = DOL_VERSION;
59
+$error = 0;
60 60
 
61 61
 
62 62
 
@@ -66,17 +66,17 @@  discard block
 block discarded – undo
66 66
 
67 67
 @set_time_limit(0);
68 68
 print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
69
-dol_syslog($script_file." launched with arg ".join(',',$argv));
69
+dol_syslog($script_file." launched with arg ".join(',', $argv));
70 70
 
71
-$now=dol_now('tzserver');
72
-$duration_value=isset($argv[2])?$argv[2]:'none';
71
+$now = dol_now('tzserver');
72
+$duration_value = isset($argv[2]) ? $argv[2] : 'none';
73 73
 
74
-print $script_file." launched with mode ".$mode." default lang=".$langs->defaultlang.(is_numeric($duration_value)?" delay=".$duration_value:"")."\n";
74
+print $script_file." launched with mode ".$mode." default lang=".$langs->defaultlang.(is_numeric($duration_value) ? " delay=".$duration_value : "")."\n";
75 75
 
76
-if ($mode != 'confirm') $conf->global->MAIN_DISABLE_ALL_MAILS=1;
76
+if ($mode != 'confirm') $conf->global->MAIN_DISABLE_ALL_MAILS = 1;
77 77
 
78 78
 $sql = "SELECT f.ref, f.total_ttc, f.date_lim_reglement as due_date, s.nom as name, s.email, s.default_lang,";
79
-$sql.= " u.rowid as uid, u.lastname, u.firstname, u.email, u.lang";
79
+$sql .= " u.rowid as uid, u.lastname, u.firstname, u.email, u.lang";
80 80
 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
81 81
 $sql .= " , ".MAIN_DB_PREFIX."societe as s";
82 82
 $sql .= " , ".MAIN_DB_PREFIX."societe_commerciaux as sc";
@@ -86,19 +86,19 @@  discard block
 block discarded – undo
86 86
 if (is_numeric($duration_value)) $sql .= " AND f.date_lim_reglement < '".$db->idate(dol_time_plus_duree($now, $duration_value, "d"))."'";
87 87
 $sql .= " AND sc.fk_soc = s.rowid";
88 88
 $sql .= " AND sc.fk_user = u.rowid";
89
-$sql .= " ORDER BY u.email ASC, s.rowid ASC, f.ref ASC";	// Order by email to allow one message per email
89
+$sql .= " ORDER BY u.email ASC, s.rowid ASC, f.ref ASC"; // Order by email to allow one message per email
90 90
 
91 91
 //print $sql;
92
-$resql=$db->query($sql);
92
+$resql = $db->query($sql);
93 93
 if ($resql)
94 94
 {
95 95
     $num = $db->num_rows($resql);
96 96
     $i = 0;
97
-    $oldemail = 'none'; $olduid = 0; $oldlang='';
97
+    $oldemail = 'none'; $olduid = 0; $oldlang = '';
98 98
     $total = 0; $foundtoprocess = 0;
99 99
 	print "We found ".$num." couples (unpayed validated invoice - sale representative) qualified\n";
100 100
     dol_syslog("We found ".$num." couples (unpayed validated invoice - sale representative) qualified");
101
-	$message='';
101
+	$message = '';
102 102
 
103 103
     if ($num)
104 104
     {
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
                 // Break onto sales representative (new email or uid)
112 112
                 if (dol_strlen($oldemail) && $oldemail != 'none')
113 113
                 {
114
-                   	envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldsalerepresentative);
114
+                   	envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldsalerepresentative);
115 115
                 }
116 116
                 else
117 117
 				{
@@ -120,28 +120,28 @@  discard block
 block discarded – undo
120 120
                 $oldemail = $obj->email;
121 121
                 $olduid = $obj->uid;
122 122
                 $oldlang = $obj->lang;
123
-                $oldsalerepresentative=dolGetFirstLastname($obj->firstname, $obj->lastname);
123
+                $oldsalerepresentative = dolGetFirstLastname($obj->firstname, $obj->lastname);
124 124
                 $message = '';
125 125
                 $total = 0;
126 126
                 $foundtoprocess = 0;
127
-                $salerepresentative=dolGetFirstLastname($obj->firstname, $obj->lastname);
127
+                $salerepresentative = dolGetFirstLastname($obj->firstname, $obj->lastname);
128 128
                 if (empty($obj->email)) print "Warning: Sale representative ".$salerepresentative." has no email. Notice disabled.\n";
129 129
             }
130 130
 
131 131
             // Define line content
132
-            $outputlangs=new Translate('',$conf);
133
-            $outputlangs->setDefaultLang(empty($obj->lang)?$langs->defaultlang:$obj->lang);	// By default language of sale representative
132
+            $outputlangs = new Translate('', $conf);
133
+            $outputlangs->setDefaultLang(empty($obj->lang) ? $langs->defaultlang : $obj->lang); // By default language of sale representative
134 134
 
135 135
             // Load translation files required by the page
136 136
             $outputlangs->loadLangs(array("main", "bills"));
137 137
 
138 138
             if (dol_strlen($obj->email))
139 139
             {
140
-            	$message .= $outputlangs->trans("Invoice")." ".$obj->ref." : ".price($obj->total_ttc,0,$outputlangs,0,0,-1,$conf->currency)." : ".$obj->name."\n";
140
+            	$message .= $outputlangs->trans("Invoice")." ".$obj->ref." : ".price($obj->total_ttc, 0, $outputlangs, 0, 0, -1, $conf->currency)." : ".$obj->name."\n";
141 141
             	dol_syslog("email_unpaid_invoices_to_representatives.php: ".$obj->email);
142 142
             	$foundtoprocess++;
143 143
             }
144
-            print "Unpaid invoice ".$obj->ref.", price ".price2num($obj->total_ttc).", due date ".dol_print_date($db->jdate($obj->due_date),'day')." (linked to company ".$obj->name.", sale representative ".dolGetFirstLastname($obj->firstname, $obj->lastname).", email ".$obj->email.", lang ".$outputlangs->defaultlang."): ";
144
+            print "Unpaid invoice ".$obj->ref.", price ".price2num($obj->total_ttc).", due date ".dol_print_date($db->jdate($obj->due_date), 'day')." (linked to company ".$obj->name.", sale representative ".dolGetFirstLastname($obj->firstname, $obj->lastname).", email ".$obj->email.", lang ".$outputlangs->defaultlang."): ";
145 145
             if (dol_strlen($obj->email)) print "qualified.";
146 146
             else print "disqualified (no email).";
147 147
 			print "\n";
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
         {
158 158
             if (dol_strlen($oldemail) && $oldemail != 'none')	// Break onto email (new email)
159 159
             {
160
-       			envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldsalerepresentative);
160
+       			envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldsalerepresentative);
161 161
             }
162 162
             else
163 163
 			{
@@ -192,18 +192,18 @@  discard block
 block discarded – undo
192 192
  *  @param	string	$oldsalerepresentative	Old sale representative
193 193
  * 	@return	int								<0 if KO, >0 if OK
194 194
  */
195
-function envoi_mail($mode,$oldemail,$message,$total,$userlang,$oldsalerepresentative)
195
+function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldsalerepresentative)
196 196
 {
197
-    global $conf,$langs;
197
+    global $conf, $langs;
198 198
 
199
-    if (getenv('DOL_FORCE_EMAIL_TO')) $oldemail=getenv('DOL_FORCE_EMAIL_TO');
199
+    if (getenv('DOL_FORCE_EMAIL_TO')) $oldemail = getenv('DOL_FORCE_EMAIL_TO');
200 200
 
201
-    $newlangs=new Translate('',$conf);
202
-    $newlangs->setDefaultLang(empty($userlang)?(empty($conf->global->MAIN_LANG_DEFAULT)?'auto':$conf->global->MAIN_LANG_DEFAULT):$userlang);
201
+    $newlangs = new Translate('', $conf);
202
+    $newlangs->setDefaultLang(empty($userlang) ? (empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT) : $userlang);
203 203
     $newlangs->load("main");
204 204
     $newlangs->load("bills");
205 205
 
206
-    $subject = (empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_SUBJECT)?$newlangs->trans("ListOfYourUnpaidInvoices"):$conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_SUBJECT);
206
+    $subject = (empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_SUBJECT) ? $newlangs->trans("ListOfYourUnpaidInvoices") : $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_SUBJECT);
207 207
     $sendto = $oldemail;
208 208
     $from = $conf->global->MAIN_MAIL_EMAIL_FROM;
209 209
     $errorsto = $conf->global->MAIN_MAIL_ERRORS_TO;
@@ -212,26 +212,26 @@  discard block
 block discarded – undo
212 212
     print "- Send email for ".$oldsalerepresentative." (".$oldemail."), total: ".$total."\n";
213 213
     dol_syslog("email_unpaid_invoices_to_representatives.php: send mail to ".$oldemail);
214 214
 
215
-    $usehtml=0;
216
-    if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER)) $usehtml+=1;
217
-    if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER)) $usehtml+=1;
215
+    $usehtml = 0;
216
+    if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER)) $usehtml += 1;
217
+    if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER)) $usehtml += 1;
218 218
 
219
-    $allmessage='';
220
-    if (! empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER))
219
+    $allmessage = '';
220
+    if (!empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER))
221 221
     {
222
-    	$allmessage.=$conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER;
222
+    	$allmessage .= $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER;
223 223
     }
224 224
     else
225 225
     {
226
-    	$allmessage.= $newlangs->transnoentities("ListOfYourUnpaidInvoices").($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
227
-    	$allmessage.= $newlangs->transnoentities("NoteListOfYourUnpaidInvoices").($usehtml?"<br>\n":"\n");
226
+    	$allmessage .= $newlangs->transnoentities("ListOfYourUnpaidInvoices").($usehtml ? "<br>\n" : "\n").($usehtml ? "<br>\n" : "\n");
227
+    	$allmessage .= $newlangs->transnoentities("NoteListOfYourUnpaidInvoices").($usehtml ? "<br>\n" : "\n");
228 228
     }
229
-    $allmessage.= $message.($usehtml?"<br>\n":"\n");
230
-    $allmessage.= $langs->trans("Total")." = ".price($total,0,$newlangs,0,0,-1,$conf->currency).($usehtml?"<br>\n":"\n");
231
-    if (! empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER))
229
+    $allmessage .= $message.($usehtml ? "<br>\n" : "\n");
230
+    $allmessage .= $langs->trans("Total")." = ".price($total, 0, $newlangs, 0, 0, -1, $conf->currency).($usehtml ? "<br>\n" : "\n");
231
+    if (!empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER))
232 232
     {
233
-    	$allmessage.=$conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER;
234
-    	if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER)) $usehtml+=1;
233
+    	$allmessage .= $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER;
234
+    	if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER)) $usehtml += 1;
235 235
     }
236 236
 
237 237
     $mail = new CMailFile(
@@ -253,8 +253,8 @@  discard block
 block discarded – undo
253 253
     // Send or not email
254 254
     if ($mode == 'confirm')
255 255
     {
256
-    	$result=$mail->sendfile();
257
-    	if (! $result)
256
+    	$result = $mail->sendfile();
257
+    	if (!$result)
258 258
     	{
259 259
     		print "Error sending email ".$mail->error."\n";
260 260
     		dol_syslog("Error sending email ".$mail->error."\n");
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
     	print "No email sent (test mode)\n";
266 266
     	dol_syslog("No email sent (test mode)");
267 267
     	$mail->dump_mail();
268
-    	$result=1;
268
+    	$result = 1;
269 269
     }
270 270
 
271 271
     if ($result)
Please login to merge, or discard this patch.
Braces   +41 added lines, -25 removed lines patch added patch discarded remove patch
@@ -73,7 +73,9 @@  discard block
 block discarded – undo
73 73
 
74 74
 print $script_file." launched with mode ".$mode." default lang=".$langs->defaultlang.(is_numeric($duration_value)?" delay=".$duration_value:"")."\n";
75 75
 
76
-if ($mode != 'confirm') $conf->global->MAIN_DISABLE_ALL_MAILS=1;
76
+if ($mode != 'confirm') {
77
+    $conf->global->MAIN_DISABLE_ALL_MAILS=1;
78
+}
77 79
 
78 80
 $sql = "SELECT f.ref, f.total_ttc, f.date_lim_reglement as due_date, s.nom as name, s.email, s.default_lang,";
79 81
 $sql.= " u.rowid as uid, u.lastname, u.firstname, u.email, u.lang";
@@ -83,7 +85,9 @@  discard block
 block discarded – undo
83 85
 $sql .= " , ".MAIN_DB_PREFIX."user as u";
84 86
 $sql .= " WHERE f.fk_statut = 1 AND f.paye = 0";
85 87
 $sql .= " AND f.fk_soc = s.rowid";
86
-if (is_numeric($duration_value)) $sql .= " AND f.date_lim_reglement < '".$db->idate(dol_time_plus_duree($now, $duration_value, "d"))."'";
88
+if (is_numeric($duration_value)) {
89
+    $sql .= " AND f.date_lim_reglement < '".$db->idate(dol_time_plus_duree($now, $duration_value, "d"))."'";
90
+}
87 91
 $sql .= " AND sc.fk_soc = s.rowid";
88 92
 $sql .= " AND sc.fk_user = u.rowid";
89 93
 $sql .= " ORDER BY u.email ASC, s.rowid ASC, f.ref ASC";	// Order by email to allow one message per email
@@ -112,10 +116,11 @@  discard block
 block discarded – undo
112 116
                 if (dol_strlen($oldemail) && $oldemail != 'none')
113 117
                 {
114 118
                    	envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldsalerepresentative);
115
-                }
116
-                else
119
+                } else
117 120
 				{
118
-					if ($oldemail != 'none') print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n";
121
+					if ($oldemail != 'none') {
122
+					    print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n";
123
+					}
119 124
                 }
120 125
                 $oldemail = $obj->email;
121 126
                 $olduid = $obj->uid;
@@ -125,7 +130,9 @@  discard block
 block discarded – undo
125 130
                 $total = 0;
126 131
                 $foundtoprocess = 0;
127 132
                 $salerepresentative=dolGetFirstLastname($obj->firstname, $obj->lastname);
128
-                if (empty($obj->email)) print "Warning: Sale representative ".$salerepresentative." has no email. Notice disabled.\n";
133
+                if (empty($obj->email)) {
134
+                    print "Warning: Sale representative ".$salerepresentative." has no email. Notice disabled.\n";
135
+                }
129 136
             }
130 137
 
131 138
             // Define line content
@@ -142,8 +149,11 @@  discard block
 block discarded – undo
142 149
             	$foundtoprocess++;
143 150
             }
144 151
             print "Unpaid invoice ".$obj->ref.", price ".price2num($obj->total_ttc).", due date ".dol_print_date($db->jdate($obj->due_date),'day')." (linked to company ".$obj->name.", sale representative ".dolGetFirstLastname($obj->firstname, $obj->lastname).", email ".$obj->email.", lang ".$outputlangs->defaultlang."): ";
145
-            if (dol_strlen($obj->email)) print "qualified.";
146
-            else print "disqualified (no email).";
152
+            if (dol_strlen($obj->email)) {
153
+                print "qualified.";
154
+            } else {
155
+                print "disqualified (no email).";
156
+            }
147 157
 			print "\n";
148 158
 
149 159
 			unset($outputlangs);
@@ -155,24 +165,25 @@  discard block
 block discarded – undo
155 165
         // Si il reste des envois en buffer
156 166
         if ($foundtoprocess)
157 167
         {
158
-            if (dol_strlen($oldemail) && $oldemail != 'none')	// Break onto email (new email)
168
+            if (dol_strlen($oldemail) && $oldemail != 'none') {
169
+                // Break onto email (new email)
159 170
             {
160 171
        			envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldsalerepresentative);
161 172
             }
162
-            else
173
+            } else
163 174
 			{
164
-            	if ($oldemail != 'none') print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n";
175
+            	if ($oldemail != 'none') {
176
+            	    print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n";
177
+            	}
165 178
             }
166 179
         }
167
-    }
168
-    else
180
+    } else
169 181
 	{
170 182
         print "No unpaid invoices (for companies linked to a particular commercial dolibarr user) found\n";
171 183
     }
172 184
 
173 185
     exit(0);
174
-}
175
-else
186
+} else
176 187
 {
177 188
     dol_print_error($db);
178 189
     dol_syslog("email_unpaid_invoices_to_representatives.php: Error");
@@ -196,7 +207,9 @@  discard block
 block discarded – undo
196 207
 {
197 208
     global $conf,$langs;
198 209
 
199
-    if (getenv('DOL_FORCE_EMAIL_TO')) $oldemail=getenv('DOL_FORCE_EMAIL_TO');
210
+    if (getenv('DOL_FORCE_EMAIL_TO')) {
211
+        $oldemail=getenv('DOL_FORCE_EMAIL_TO');
212
+    }
200 213
 
201 214
     $newlangs=new Translate('',$conf);
202 215
     $newlangs->setDefaultLang(empty($userlang)?(empty($conf->global->MAIN_LANG_DEFAULT)?'auto':$conf->global->MAIN_LANG_DEFAULT):$userlang);
@@ -213,15 +226,18 @@  discard block
 block discarded – undo
213 226
     dol_syslog("email_unpaid_invoices_to_representatives.php: send mail to ".$oldemail);
214 227
 
215 228
     $usehtml=0;
216
-    if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER)) $usehtml+=1;
217
-    if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER)) $usehtml+=1;
229
+    if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER)) {
230
+        $usehtml+=1;
231
+    }
232
+    if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER)) {
233
+        $usehtml+=1;
234
+    }
218 235
 
219 236
     $allmessage='';
220 237
     if (! empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER))
221 238
     {
222 239
     	$allmessage.=$conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER;
223
-    }
224
-    else
240
+    } else
225 241
     {
226 242
     	$allmessage.= $newlangs->transnoentities("ListOfYourUnpaidInvoices").($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
227 243
     	$allmessage.= $newlangs->transnoentities("NoteListOfYourUnpaidInvoices").($usehtml?"<br>\n":"\n");
@@ -231,7 +247,9 @@  discard block
 block discarded – undo
231 247
     if (! empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER))
232 248
     {
233 249
     	$allmessage.=$conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER;
234
-    	if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER)) $usehtml+=1;
250
+    	if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER)) {
251
+    	    $usehtml+=1;
252
+    	}
235 253
     }
236 254
 
237 255
     $mail = new CMailFile(
@@ -259,8 +277,7 @@  discard block
 block discarded – undo
259 277
     		print "Error sending email ".$mail->error."\n";
260 278
     		dol_syslog("Error sending email ".$mail->error."\n");
261 279
     	}
262
-    }
263
-    else
280
+    } else
264 281
     {
265 282
     	print "No email sent (test mode)\n";
266 283
     	dol_syslog("No email sent (test mode)");
@@ -271,8 +288,7 @@  discard block
 block discarded – undo
271 288
     if ($result)
272 289
     {
273 290
         return 1;
274
-    }
275
-    else
291
+    } else
276 292
     {
277 293
         return -1;
278 294
     }
Please login to merge, or discard this patch.
dolibarr/scripts/invoices/email_unpaid_invoices_to_customers.php 3 patches
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -33,18 +33,18 @@  discard block
 block discarded – undo
33 33
 $sapi_type = php_sapi_name();
34 34
 if (substr($sapi_type, 0, 3) == 'cgi') {
35 35
     echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
36
-	exit(-1);
36
+    exit(-1);
37 37
 }
38 38
 
39 39
 if (! isset($argv[2]) || ! $argv[2] || ! in_array($argv[1],array('test','confirm')) || ! in_array($argv[2],array('thirdparties','contacts')))
40 40
 {
41
-	print "Usage: $script_file (test|confirm) (thirdparties|contacts) [delay] [after]\n";
42
-	print "\n";
43
-	print "Send an email to customers to remind all unpaid customer invoices.\n";
44
-	print "If you choose 'test' mode, no emails are sent.\n";
45
-	print "If you add param delay (nb of days), only invoice with due date < today + delay are included.\n";
46
-	print "If you add param after (nb of days), only invoice with due date >= today + delay are included.\n";
47
-	exit(-1);
41
+    print "Usage: $script_file (test|confirm) (thirdparties|contacts) [delay] [after]\n";
42
+    print "\n";
43
+    print "Send an email to customers to remind all unpaid customer invoices.\n";
44
+    print "If you choose 'test' mode, no emails are sent.\n";
45
+    print "If you add param delay (nb of days), only invoice with due date < today + delay are included.\n";
46
+    print "If you add param after (nb of days), only invoice with due date >= today + delay are included.\n";
47
+    exit(-1);
48 48
 }
49 49
 $mode=$argv[1];
50 50
 $targettype=$argv[2];
@@ -102,9 +102,9 @@  discard block
 block discarded – undo
102 102
     $total = 0; $foundtoprocess = 0;
103 103
     $trackthirdpartiessent = array();
104 104
 
105
-	print "We found ".$num." couples (unpayed validated invoices-".$targettype.") qualified\n";
105
+    print "We found ".$num." couples (unpayed validated invoices-".$targettype.") qualified\n";
106 106
     dol_syslog("We found ".$num." couples (unpayed validated invoices-".$targettype.") qualified");
107
-	$message='';
107
+    $message='';
108 108
 
109 109
     if ($num)
110 110
     {
@@ -116,25 +116,25 @@  discard block
 block discarded – undo
116 116
 
117 117
             // Check if this record is a break after previous one
118 118
             $startbreak=false;
119
-			if ($newemail <> $oldemail || $oldemail == 'none') $startbreak=true;
120
-			if ($obj->sid && $obj->sid <> $oldsid) $startbreak=true;
121
-			if ($obj->cid && $obj->cid <> $oldcid) $startbreak=true;
119
+            if ($newemail <> $oldemail || $oldemail == 'none') $startbreak=true;
120
+            if ($obj->sid && $obj->sid <> $oldsid) $startbreak=true;
121
+            if ($obj->cid && $obj->cid <> $oldcid) $startbreak=true;
122 122
 
123 123
             if ($startbreak)
124 124
             {
125 125
                 // Break onto sales representative (new email or cid)
126 126
                 if (dol_strlen($oldemail) && $oldemail != 'none' && empty($trackthirdpartiessent[$oldsid.'|'.$oldemail]))
127 127
                 {
128
-                   	envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldtarget);
129
-                   	$trackthirdpartiessent[$oldsid.'|'.$oldemail]='contact id '.$oldcid;
128
+                        envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldtarget);
129
+                        $trackthirdpartiessent[$oldsid.'|'.$oldemail]='contact id '.$oldcid;
130 130
                 }
131 131
                 else
132
-				{
133
-                	if ($oldemail != 'none')
134
-                	{
135
-                		if (empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) print "- No email sent for '".$oldtarget."', total: ".$total."\n";
136
-                		else print "- No email sent for '".$oldtarget."', total: ".$total." (already sent to ".$trackthirdpartiessent[$oldsid.'|'.$oldemail].")\n";
137
-                	}
132
+                {
133
+                    if ($oldemail != 'none')
134
+                    {
135
+                        if (empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) print "- No email sent for '".$oldtarget."', total: ".$total."\n";
136
+                        else print "- No email sent for '".$oldtarget."', total: ".$total." (already sent to ".$trackthirdpartiessent[$oldsid.'|'.$oldemail].")\n";
137
+                    }
138 138
                 }
139 139
                 $oldemail = $newemail;
140 140
                 $oldsid  = $obj->sid;
@@ -157,9 +157,9 @@  discard block
 block discarded – undo
157 157
 
158 158
             if (dol_strlen($newemail))
159 159
             {
160
-            	$message .= $outputlangs->trans("Invoice")." ".$obj->ref." : ".price($obj->total_ttc,0,$outputlangs,0,0,-1,$conf->currency)."\n";
161
-            	dol_syslog("email_unpaid_invoices_to_customers.php: ".$newemail." ".$message);
162
-            	$foundtoprocess++;
160
+                $message .= $outputlangs->trans("Invoice")." ".$obj->ref." : ".price($obj->total_ttc,0,$outputlangs,0,0,-1,$conf->currency)."\n";
161
+                dol_syslog("email_unpaid_invoices_to_customers.php: ".$newemail." ".$message);
162
+                $foundtoprocess++;
163 163
             }
164 164
             print "Unpaid invoice ".$obj->ref.", price ".price2num($obj->total_ttc).", due date ".dol_print_date($db->jdate($obj->due_date),'day').", customer id ".$obj->sid." ".$obj->name.", ".($obj->cid?"contact id ".$obj->cid." ".$obj->clastname." ".$obj->cfirstname.", ":"")."email ".$newemail.", lang ".$outputlangs->defaultlang.": ";
165 165
             if (dol_strlen($newemail)) print "qualified.";
@@ -178,21 +178,21 @@  discard block
 block discarded – undo
178 178
         {
179 179
             if (dol_strlen($oldemail) && $oldemail != 'none' && empty($trackthirdpartiessent[$oldsid.'|'.$oldemail]))	// Break onto email (new email)
180 180
             {
181
-       			envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldtarget);
182
-       			$trackthirdpartiessent[$oldsid.'|'.$oldemail]='contact id '.$oldcid;
181
+                    envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldtarget);
182
+                    $trackthirdpartiessent[$oldsid.'|'.$oldemail]='contact id '.$oldcid;
183 183
             }
184 184
             else
185
-			{
186
-            	if ($oldemail != 'none')
187
-            	{
188
-            		if (empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) print "- No email sent for '".$oldtarget."', total: ".$total."\n";
189
-            		else print "- No email sent for '".$oldtarget."', total: ".$total." (already sent to ".$trackthirdpartiessent[$oldsid.'|'.$oldemail].")\n";
190
-            	}
185
+            {
186
+                if ($oldemail != 'none')
187
+                {
188
+                    if (empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) print "- No email sent for '".$oldtarget."', total: ".$total."\n";
189
+                    else print "- No email sent for '".$oldtarget."', total: ".$total." (already sent to ".$trackthirdpartiessent[$oldsid.'|'.$oldemail].")\n";
190
+                }
191 191
             }
192 192
         }
193 193
     }
194 194
     else
195
-	{
195
+    {
196 196
         print "No unpaid invoices found\n";
197 197
     }
198 198
 
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
     $sendto = $oldemail;
234 234
     $from = $conf->global->MAIN_MAIL_EMAIL_FROM;
235 235
     $errorsto = $conf->global->MAIN_MAIL_ERRORS_TO;
236
-	$msgishtml = -1;
236
+    $msgishtml = -1;
237 237
 
238 238
     print "- Send email to '".$oldtarget."' (".$oldemail."), total: ".$total."\n";
239 239
     dol_syslog("email_unpaid_invoices_to_customers.php: send mail to ".$oldemail);
@@ -245,20 +245,20 @@  discard block
 block discarded – undo
245 245
     $allmessage='';
246 246
     if (! empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER))
247 247
     {
248
-    	$allmessage.=$conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER;
248
+        $allmessage.=$conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER;
249 249
     }
250 250
     else
251 251
     {
252
-    	$allmessage.= "Dear customer".($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
253
-    	$allmessage.= "Please, find a summary of the bills with pending payments from you.".($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
254
-    	$allmessage.= "Note: This list contains only unpaid invoices.".($usehtml?"<br>\n":"\n");
252
+        $allmessage.= "Dear customer".($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
253
+        $allmessage.= "Please, find a summary of the bills with pending payments from you.".($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
254
+        $allmessage.= "Note: This list contains only unpaid invoices.".($usehtml?"<br>\n":"\n");
255 255
     }
256 256
     $allmessage.= $message.($usehtml?"<br>\n":"\n");
257 257
     $allmessage.= $langs->trans("Total")." = ".price($total,0,$userlang,0,0,-1,$conf->currency).($usehtml?"<br>\n":"\n");
258 258
     if (! empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER))
259 259
     {
260
-    	$allmessage.=$conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER;
261
-    	if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER)) $usehtml+=1;
260
+        $allmessage.=$conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER;
261
+        if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER)) $usehtml+=1;
262 262
     }
263 263
 
264 264
     $mail = new CMailFile(
@@ -280,19 +280,19 @@  discard block
 block discarded – undo
280 280
     // Send or not email
281 281
     if ($mode == 'confirm')
282 282
     {
283
-    	$result=$mail->sendfile();
284
-    	if (! $result)
285
-    	{
286
-    		print "Error sending email ".$mail->error."\n";
287
-    		dol_syslog("Error sending email ".$mail->error."\n");
288
-    	}
283
+        $result=$mail->sendfile();
284
+        if (! $result)
285
+        {
286
+            print "Error sending email ".$mail->error."\n";
287
+            dol_syslog("Error sending email ".$mail->error."\n");
288
+        }
289 289
     }
290 290
     else
291 291
     {
292
-    	print "No email sent (test mode)\n";
293
-    	dol_syslog("No email sent (test mode)");
294
-    	$mail->dump_mail();
295
-    	$result=1;
292
+        print "No email sent (test mode)\n";
293
+        dol_syslog("No email sent (test mode)");
294
+        $mail->dump_mail();
295
+        $result=1;
296 296
     }
297 297
 
298 298
     unset($newlangs);
Please login to merge, or discard this patch.
Spacing   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 
28 28
 $sapi_type = php_sapi_name();
29 29
 $script_file = basename(__FILE__);
30
-$path=dirname(__FILE__).'/';
30
+$path = dirname(__FILE__).'/';
31 31
 
32 32
 // Test si mode batch
33 33
 $sapi_type = php_sapi_name();
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 	exit(-1);
37 37
 }
38 38
 
39
-if (! isset($argv[2]) || ! $argv[2] || ! in_array($argv[1],array('test','confirm')) || ! in_array($argv[2],array('thirdparties','contacts')))
39
+if (!isset($argv[2]) || !$argv[2] || !in_array($argv[1], array('test', 'confirm')) || !in_array($argv[2], array('thirdparties', 'contacts')))
40 40
 {
41 41
 	print "Usage: $script_file (test|confirm) (thirdparties|contacts) [delay] [after]\n";
42 42
 	print "\n";
@@ -46,8 +46,8 @@  discard block
 block discarded – undo
46 46
 	print "If you add param after (nb of days), only invoice with due date >= today + delay are included.\n";
47 47
 	exit(-1);
48 48
 }
49
-$mode=$argv[1];
50
-$targettype=$argv[2];
49
+$mode = $argv[1];
50
+$targettype = $argv[2];
51 51
 
52 52
 
53 53
 require $path."../../htdocs/master.inc.php";
@@ -56,8 +56,8 @@  discard block
 block discarded – undo
56 56
 $langs->load('main');
57 57
 
58 58
 // Global variables
59
-$version=DOL_VERSION;
60
-$error=0;
59
+$version = DOL_VERSION;
60
+$error = 0;
61 61
 
62 62
 
63 63
 
@@ -67,44 +67,44 @@  discard block
 block discarded – undo
67 67
 
68 68
 @set_time_limit(0);
69 69
 print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
70
-dol_syslog($script_file." launched with arg ".join(',',$argv));
70
+dol_syslog($script_file." launched with arg ".join(',', $argv));
71 71
 
72
-$now=dol_now('tzserver');
73
-$duration_value=isset($argv[3])?$argv[3]:'none';
74
-$duration_value2=isset($argv[4])?$argv[4]:'none';
72
+$now = dol_now('tzserver');
73
+$duration_value = isset($argv[3]) ? $argv[3] : 'none';
74
+$duration_value2 = isset($argv[4]) ? $argv[4] : 'none';
75 75
 
76 76
 $error = 0;
77
-print $script_file." launched with mode ".$mode." default lang=".$langs->defaultlang.(is_numeric($duration_value)?" delay=".$duration_value:"").(is_numeric($duration_value2)?" after=".$duration_value2:"")."\n";
77
+print $script_file." launched with mode ".$mode." default lang=".$langs->defaultlang.(is_numeric($duration_value) ? " delay=".$duration_value : "").(is_numeric($duration_value2) ? " after=".$duration_value2 : "")."\n";
78 78
 
79
-if ($mode != 'confirm') $conf->global->MAIN_DISABLE_ALL_MAILS=1;
79
+if ($mode != 'confirm') $conf->global->MAIN_DISABLE_ALL_MAILS = 1;
80 80
 
81 81
 $sql = "SELECT f.ref, f.total_ttc, f.date_lim_reglement as due_date,";
82
-$sql.= " s.rowid as sid, s.nom as name, s.email, s.default_lang";
83
-if ($targettype == 'contacts') $sql.= ", sp.rowid as cid, sp.firstname as cfirstname, sp.lastname as clastname, sp.email as cemail";
84
-$sql.= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s";
85
-if ($targettype == 'contacts') $sql.= ", ".MAIN_DB_PREFIX."socpeople as sp";
86
-$sql.= " WHERE f.fk_statut = 1 AND f.paye = 0";
87
-$sql.= " AND f.fk_soc = s.rowid";
88
-if (is_numeric($duration_value2)) $sql.= " AND f.date_lim_reglement >= '".$db->idate(dol_time_plus_duree($now, $duration_value2, "d"))."'";
89
-if (is_numeric($duration_value)) $sql.= " AND f.date_lim_reglement < '".$db->idate(dol_time_plus_duree($now, $duration_value, "d"))."'";
90
-if ($targettype == 'contacts') $sql.= " AND s.rowid = sp.fk_soc";
91
-$sql.= " ORDER BY";
92
-if ($targettype == 'contacts') $sql.= " sp.email, sp.rowid,";
93
-$sql.= " s.email ASC, s.rowid ASC, f.ref ASC";	// Order by email to allow one message per email
82
+$sql .= " s.rowid as sid, s.nom as name, s.email, s.default_lang";
83
+if ($targettype == 'contacts') $sql .= ", sp.rowid as cid, sp.firstname as cfirstname, sp.lastname as clastname, sp.email as cemail";
84
+$sql .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s";
85
+if ($targettype == 'contacts') $sql .= ", ".MAIN_DB_PREFIX."socpeople as sp";
86
+$sql .= " WHERE f.fk_statut = 1 AND f.paye = 0";
87
+$sql .= " AND f.fk_soc = s.rowid";
88
+if (is_numeric($duration_value2)) $sql .= " AND f.date_lim_reglement >= '".$db->idate(dol_time_plus_duree($now, $duration_value2, "d"))."'";
89
+if (is_numeric($duration_value)) $sql .= " AND f.date_lim_reglement < '".$db->idate(dol_time_plus_duree($now, $duration_value, "d"))."'";
90
+if ($targettype == 'contacts') $sql .= " AND s.rowid = sp.fk_soc";
91
+$sql .= " ORDER BY";
92
+if ($targettype == 'contacts') $sql .= " sp.email, sp.rowid,";
93
+$sql .= " s.email ASC, s.rowid ASC, f.ref ASC"; // Order by email to allow one message per email
94 94
 
95 95
 //print $sql;
96
-$resql=$db->query($sql);
96
+$resql = $db->query($sql);
97 97
 if ($resql)
98 98
 {
99 99
     $num = $db->num_rows($resql);
100 100
     $i = 0;
101
-    $oldemail = 'none'; $oldsid = 0; $oldcid = 0; $oldlang='';
101
+    $oldemail = 'none'; $oldsid = 0; $oldcid = 0; $oldlang = '';
102 102
     $total = 0; $foundtoprocess = 0;
103 103
     $trackthirdpartiessent = array();
104 104
 
105 105
 	print "We found ".$num." couples (unpayed validated invoices-".$targettype.") qualified\n";
106 106
     dol_syslog("We found ".$num." couples (unpayed validated invoices-".$targettype.") qualified");
107
-	$message='';
107
+	$message = '';
108 108
 
109 109
     if ($num)
110 110
     {
@@ -112,21 +112,21 @@  discard block
 block discarded – undo
112 112
         {
113 113
             $obj = $db->fetch_object($resql);
114 114
 
115
-            $newemail=empty($obj->cemail)?$obj->email:$obj->cemail;
115
+            $newemail = empty($obj->cemail) ? $obj->email : $obj->cemail;
116 116
 
117 117
             // Check if this record is a break after previous one
118
-            $startbreak=false;
119
-			if ($newemail <> $oldemail || $oldemail == 'none') $startbreak=true;
120
-			if ($obj->sid && $obj->sid <> $oldsid) $startbreak=true;
121
-			if ($obj->cid && $obj->cid <> $oldcid) $startbreak=true;
118
+            $startbreak = false;
119
+			if ($newemail <> $oldemail || $oldemail == 'none') $startbreak = true;
120
+			if ($obj->sid && $obj->sid <> $oldsid) $startbreak = true;
121
+			if ($obj->cid && $obj->cid <> $oldcid) $startbreak = true;
122 122
 
123 123
             if ($startbreak)
124 124
             {
125 125
                 // Break onto sales representative (new email or cid)
126 126
                 if (dol_strlen($oldemail) && $oldemail != 'none' && empty($trackthirdpartiessent[$oldsid.'|'.$oldemail]))
127 127
                 {
128
-                   	envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldtarget);
129
-                   	$trackthirdpartiessent[$oldsid.'|'.$oldemail]='contact id '.$oldcid;
128
+                   	envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldtarget);
129
+                   	$trackthirdpartiessent[$oldsid.'|'.$oldemail] = 'contact id '.$oldcid;
130 130
                 }
131 131
                 else
132 132
 				{
@@ -140,28 +140,28 @@  discard block
 block discarded – undo
140 140
                 $oldsid  = $obj->sid;
141 141
                 $oldcid  = $obj->cid;
142 142
                 $oldlang = $obj->lang;
143
-                $oldtarget=(empty($obj->cfirstname) && empty($obj->clastname))?$obj->name:($obj->clastname." ".$obj->cfirstname);
143
+                $oldtarget = (empty($obj->cfirstname) && empty($obj->clastname)) ? $obj->name : ($obj->clastname." ".$obj->cfirstname);
144 144
                 $message = '';
145 145
                 $total   = 0;
146 146
                 $foundtoprocess = 0;
147
-                $target=(empty($obj->cfirstname) && empty($obj->clastname))?$obj->name:($obj->clastname." ".$obj->cfirstname);
147
+                $target = (empty($obj->cfirstname) && empty($obj->clastname)) ? $obj->name : ($obj->clastname." ".$obj->cfirstname);
148 148
                 //if (empty($newemail)) print "Warning: Customer ".$target." has no email. Notice disabled.\n";
149 149
             }
150 150
 
151 151
             // Define line content
152
-            $outputlangs=new Translate('',$conf);
153
-            $outputlangs->setDefaultLang(empty($obj->default_lang)?$langs->defaultlang:$obj->default_lang);	// By default language of customer
152
+            $outputlangs = new Translate('', $conf);
153
+            $outputlangs->setDefaultLang(empty($obj->default_lang) ? $langs->defaultlang : $obj->default_lang); // By default language of customer
154 154
 
155 155
             // Load translation files required by the page
156 156
             $outputlangs->loadLangs(array("main", "bills"));
157 157
 
158 158
             if (dol_strlen($newemail))
159 159
             {
160
-            	$message .= $outputlangs->trans("Invoice")." ".$obj->ref." : ".price($obj->total_ttc,0,$outputlangs,0,0,-1,$conf->currency)."\n";
160
+            	$message .= $outputlangs->trans("Invoice")." ".$obj->ref." : ".price($obj->total_ttc, 0, $outputlangs, 0, 0, -1, $conf->currency)."\n";
161 161
             	dol_syslog("email_unpaid_invoices_to_customers.php: ".$newemail." ".$message);
162 162
             	$foundtoprocess++;
163 163
             }
164
-            print "Unpaid invoice ".$obj->ref.", price ".price2num($obj->total_ttc).", due date ".dol_print_date($db->jdate($obj->due_date),'day').", customer id ".$obj->sid." ".$obj->name.", ".($obj->cid?"contact id ".$obj->cid." ".$obj->clastname." ".$obj->cfirstname.", ":"")."email ".$newemail.", lang ".$outputlangs->defaultlang.": ";
164
+            print "Unpaid invoice ".$obj->ref.", price ".price2num($obj->total_ttc).", due date ".dol_print_date($db->jdate($obj->due_date), 'day').", customer id ".$obj->sid." ".$obj->name.", ".($obj->cid ? "contact id ".$obj->cid." ".$obj->clastname." ".$obj->cfirstname.", " : "")."email ".$newemail.", lang ".$outputlangs->defaultlang.": ";
165 165
             if (dol_strlen($newemail)) print "qualified.";
166 166
             else print "disqualified (no email).";
167 167
             print "\n";
@@ -178,8 +178,8 @@  discard block
 block discarded – undo
178 178
         {
179 179
             if (dol_strlen($oldemail) && $oldemail != 'none' && empty($trackthirdpartiessent[$oldsid.'|'.$oldemail]))	// Break onto email (new email)
180 180
             {
181
-       			envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldtarget);
182
-       			$trackthirdpartiessent[$oldsid.'|'.$oldemail]='contact id '.$oldcid;
181
+       			envoi_mail($mode, $oldemail, $message, $total, $oldlang, $oldtarget);
182
+       			$trackthirdpartiessent[$oldsid.'|'.$oldemail] = 'contact id '.$oldcid;
183 183
             }
184 184
             else
185 185
 			{
@@ -218,18 +218,18 @@  discard block
 block discarded – undo
218 218
  *  @param	string	$oldtarget		Target name
219 219
  * 	@return	int						<0 if KO, >0 if OK
220 220
  */
221
-function envoi_mail($mode,$oldemail,$message,$total,$userlang,$oldtarget)
221
+function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldtarget)
222 222
 {
223
-    global $conf,$langs;
223
+    global $conf, $langs;
224 224
 
225
-    if (getenv('DOL_FORCE_EMAIL_TO')) $oldemail=getenv('DOL_FORCE_EMAIL_TO');
225
+    if (getenv('DOL_FORCE_EMAIL_TO')) $oldemail = getenv('DOL_FORCE_EMAIL_TO');
226 226
 
227
-    $newlangs=new Translate('',$conf);
228
-    $newlangs->setDefaultLang(empty($userlang)?(empty($conf->global->MAIN_LANG_DEFAULT)?'auto':$conf->global->MAIN_LANG_DEFAULT):$userlang);
227
+    $newlangs = new Translate('', $conf);
228
+    $newlangs->setDefaultLang(empty($userlang) ? (empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT) : $userlang);
229 229
     $newlangs->load("main");
230 230
     $newlangs->load("bills");
231 231
 
232
-    $subject = (empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_SUBJECT)?$newlangs->trans("ListOfYourUnpaidInvoices"):$conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_SUBJECT);
232
+    $subject = (empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_SUBJECT) ? $newlangs->trans("ListOfYourUnpaidInvoices") : $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_SUBJECT);
233 233
     $sendto = $oldemail;
234 234
     $from = $conf->global->MAIN_MAIL_EMAIL_FROM;
235 235
     $errorsto = $conf->global->MAIN_MAIL_ERRORS_TO;
@@ -238,27 +238,27 @@  discard block
 block discarded – undo
238 238
     print "- Send email to '".$oldtarget."' (".$oldemail."), total: ".$total."\n";
239 239
     dol_syslog("email_unpaid_invoices_to_customers.php: send mail to ".$oldemail);
240 240
 
241
-    $usehtml=0;
242
-    if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER)) $usehtml+=1;
243
-    if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER)) $usehtml+=1;
241
+    $usehtml = 0;
242
+    if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER)) $usehtml += 1;
243
+    if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER)) $usehtml += 1;
244 244
 
245
-    $allmessage='';
246
-    if (! empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER))
245
+    $allmessage = '';
246
+    if (!empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER))
247 247
     {
248
-    	$allmessage.=$conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER;
248
+    	$allmessage .= $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER;
249 249
     }
250 250
     else
251 251
     {
252
-    	$allmessage.= "Dear customer".($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
253
-    	$allmessage.= "Please, find a summary of the bills with pending payments from you.".($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
254
-    	$allmessage.= "Note: This list contains only unpaid invoices.".($usehtml?"<br>\n":"\n");
252
+    	$allmessage .= "Dear customer".($usehtml ? "<br>\n" : "\n").($usehtml ? "<br>\n" : "\n");
253
+    	$allmessage .= "Please, find a summary of the bills with pending payments from you.".($usehtml ? "<br>\n" : "\n").($usehtml ? "<br>\n" : "\n");
254
+    	$allmessage .= "Note: This list contains only unpaid invoices.".($usehtml ? "<br>\n" : "\n");
255 255
     }
256
-    $allmessage.= $message.($usehtml?"<br>\n":"\n");
257
-    $allmessage.= $langs->trans("Total")." = ".price($total,0,$userlang,0,0,-1,$conf->currency).($usehtml?"<br>\n":"\n");
258
-    if (! empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER))
256
+    $allmessage .= $message.($usehtml ? "<br>\n" : "\n");
257
+    $allmessage .= $langs->trans("Total")." = ".price($total, 0, $userlang, 0, 0, -1, $conf->currency).($usehtml ? "<br>\n" : "\n");
258
+    if (!empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER))
259 259
     {
260
-    	$allmessage.=$conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER;
261
-    	if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER)) $usehtml+=1;
260
+    	$allmessage .= $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER;
261
+    	if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER)) $usehtml += 1;
262 262
     }
263 263
 
264 264
     $mail = new CMailFile(
@@ -280,8 +280,8 @@  discard block
 block discarded – undo
280 280
     // Send or not email
281 281
     if ($mode == 'confirm')
282 282
     {
283
-    	$result=$mail->sendfile();
284
-    	if (! $result)
283
+    	$result = $mail->sendfile();
284
+    	if (!$result)
285 285
     	{
286 286
     		print "Error sending email ".$mail->error."\n";
287 287
     		dol_syslog("Error sending email ".$mail->error."\n");
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
     	print "No email sent (test mode)\n";
293 293
     	dol_syslog("No email sent (test mode)");
294 294
     	$mail->dump_mail();
295
-    	$result=1;
295
+    	$result = 1;
296 296
     }
297 297
 
298 298
     unset($newlangs);
Please login to merge, or discard this patch.
Braces   +67 added lines, -35 removed lines patch added patch discarded remove patch
@@ -76,20 +76,34 @@  discard block
 block discarded – undo
76 76
 $error = 0;
77 77
 print $script_file." launched with mode ".$mode." default lang=".$langs->defaultlang.(is_numeric($duration_value)?" delay=".$duration_value:"").(is_numeric($duration_value2)?" after=".$duration_value2:"")."\n";
78 78
 
79
-if ($mode != 'confirm') $conf->global->MAIN_DISABLE_ALL_MAILS=1;
79
+if ($mode != 'confirm') {
80
+    $conf->global->MAIN_DISABLE_ALL_MAILS=1;
81
+}
80 82
 
81 83
 $sql = "SELECT f.ref, f.total_ttc, f.date_lim_reglement as due_date,";
82 84
 $sql.= " s.rowid as sid, s.nom as name, s.email, s.default_lang";
83
-if ($targettype == 'contacts') $sql.= ", sp.rowid as cid, sp.firstname as cfirstname, sp.lastname as clastname, sp.email as cemail";
85
+if ($targettype == 'contacts') {
86
+    $sql.= ", sp.rowid as cid, sp.firstname as cfirstname, sp.lastname as clastname, sp.email as cemail";
87
+}
84 88
 $sql.= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s";
85
-if ($targettype == 'contacts') $sql.= ", ".MAIN_DB_PREFIX."socpeople as sp";
89
+if ($targettype == 'contacts') {
90
+    $sql.= ", ".MAIN_DB_PREFIX."socpeople as sp";
91
+}
86 92
 $sql.= " WHERE f.fk_statut = 1 AND f.paye = 0";
87 93
 $sql.= " AND f.fk_soc = s.rowid";
88
-if (is_numeric($duration_value2)) $sql.= " AND f.date_lim_reglement >= '".$db->idate(dol_time_plus_duree($now, $duration_value2, "d"))."'";
89
-if (is_numeric($duration_value)) $sql.= " AND f.date_lim_reglement < '".$db->idate(dol_time_plus_duree($now, $duration_value, "d"))."'";
90
-if ($targettype == 'contacts') $sql.= " AND s.rowid = sp.fk_soc";
94
+if (is_numeric($duration_value2)) {
95
+    $sql.= " AND f.date_lim_reglement >= '".$db->idate(dol_time_plus_duree($now, $duration_value2, "d"))."'";
96
+}
97
+if (is_numeric($duration_value)) {
98
+    $sql.= " AND f.date_lim_reglement < '".$db->idate(dol_time_plus_duree($now, $duration_value, "d"))."'";
99
+}
100
+if ($targettype == 'contacts') {
101
+    $sql.= " AND s.rowid = sp.fk_soc";
102
+}
91 103
 $sql.= " ORDER BY";
92
-if ($targettype == 'contacts') $sql.= " sp.email, sp.rowid,";
104
+if ($targettype == 'contacts') {
105
+    $sql.= " sp.email, sp.rowid,";
106
+}
93 107
 $sql.= " s.email ASC, s.rowid ASC, f.ref ASC";	// Order by email to allow one message per email
94 108
 
95 109
 //print $sql;
@@ -116,9 +130,15 @@  discard block
 block discarded – undo
116 130
 
117 131
             // Check if this record is a break after previous one
118 132
             $startbreak=false;
119
-			if ($newemail <> $oldemail || $oldemail == 'none') $startbreak=true;
120
-			if ($obj->sid && $obj->sid <> $oldsid) $startbreak=true;
121
-			if ($obj->cid && $obj->cid <> $oldcid) $startbreak=true;
133
+			if ($newemail <> $oldemail || $oldemail == 'none') {
134
+			    $startbreak=true;
135
+			}
136
+			if ($obj->sid && $obj->sid <> $oldsid) {
137
+			    $startbreak=true;
138
+			}
139
+			if ($obj->cid && $obj->cid <> $oldcid) {
140
+			    $startbreak=true;
141
+			}
122 142
 
123 143
             if ($startbreak)
124 144
             {
@@ -127,13 +147,15 @@  discard block
 block discarded – undo
127 147
                 {
128 148
                    	envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldtarget);
129 149
                    	$trackthirdpartiessent[$oldsid.'|'.$oldemail]='contact id '.$oldcid;
130
-                }
131
-                else
150
+                } else
132 151
 				{
133 152
                 	if ($oldemail != 'none')
134 153
                 	{
135
-                		if (empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) print "- No email sent for '".$oldtarget."', total: ".$total."\n";
136
-                		else print "- No email sent for '".$oldtarget."', total: ".$total." (already sent to ".$trackthirdpartiessent[$oldsid.'|'.$oldemail].")\n";
154
+                		if (empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) {
155
+                		    print "- No email sent for '".$oldtarget."', total: ".$total."\n";
156
+                		} else {
157
+                		    print "- No email sent for '".$oldtarget."', total: ".$total." (already sent to ".$trackthirdpartiessent[$oldsid.'|'.$oldemail].")\n";
158
+                		}
137 159
                 	}
138 160
                 }
139 161
                 $oldemail = $newemail;
@@ -162,8 +184,11 @@  discard block
 block discarded – undo
162 184
             	$foundtoprocess++;
163 185
             }
164 186
             print "Unpaid invoice ".$obj->ref.", price ".price2num($obj->total_ttc).", due date ".dol_print_date($db->jdate($obj->due_date),'day').", customer id ".$obj->sid." ".$obj->name.", ".($obj->cid?"contact id ".$obj->cid." ".$obj->clastname." ".$obj->cfirstname.", ":"")."email ".$newemail.", lang ".$outputlangs->defaultlang.": ";
165
-            if (dol_strlen($newemail)) print "qualified.";
166
-            else print "disqualified (no email).";
187
+            if (dol_strlen($newemail)) {
188
+                print "qualified.";
189
+            } else {
190
+                print "disqualified (no email).";
191
+            }
167 192
             print "\n";
168 193
 
169 194
             unset($outputlangs);
@@ -176,29 +201,31 @@  discard block
 block discarded – undo
176 201
         // Si il reste des envois en buffer
177 202
         if ($foundtoprocess)
178 203
         {
179
-            if (dol_strlen($oldemail) && $oldemail != 'none' && empty($trackthirdpartiessent[$oldsid.'|'.$oldemail]))	// Break onto email (new email)
204
+            if (dol_strlen($oldemail) && $oldemail != 'none' && empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) {
205
+                // Break onto email (new email)
180 206
             {
181 207
        			envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldtarget);
182
-       			$trackthirdpartiessent[$oldsid.'|'.$oldemail]='contact id '.$oldcid;
183 208
             }
184
-            else
209
+       			$trackthirdpartiessent[$oldsid.'|'.$oldemail]='contact id '.$oldcid;
210
+            } else
185 211
 			{
186 212
             	if ($oldemail != 'none')
187 213
             	{
188
-            		if (empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) print "- No email sent for '".$oldtarget."', total: ".$total."\n";
189
-            		else print "- No email sent for '".$oldtarget."', total: ".$total." (already sent to ".$trackthirdpartiessent[$oldsid.'|'.$oldemail].")\n";
214
+            		if (empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) {
215
+            		    print "- No email sent for '".$oldtarget."', total: ".$total."\n";
216
+            		} else {
217
+            		    print "- No email sent for '".$oldtarget."', total: ".$total." (already sent to ".$trackthirdpartiessent[$oldsid.'|'.$oldemail].")\n";
218
+            		}
190 219
             	}
191 220
             }
192 221
         }
193
-    }
194
-    else
222
+    } else
195 223
 	{
196 224
         print "No unpaid invoices found\n";
197 225
     }
198 226
 
199 227
     exit(0);
200
-}
201
-else
228
+} else
202 229
 {
203 230
     dol_print_error($db);
204 231
     dol_syslog("email_unpaid_invoices_to_customers.php: Error");
@@ -222,7 +249,9 @@  discard block
 block discarded – undo
222 249
 {
223 250
     global $conf,$langs;
224 251
 
225
-    if (getenv('DOL_FORCE_EMAIL_TO')) $oldemail=getenv('DOL_FORCE_EMAIL_TO');
252
+    if (getenv('DOL_FORCE_EMAIL_TO')) {
253
+        $oldemail=getenv('DOL_FORCE_EMAIL_TO');
254
+    }
226 255
 
227 256
     $newlangs=new Translate('',$conf);
228 257
     $newlangs->setDefaultLang(empty($userlang)?(empty($conf->global->MAIN_LANG_DEFAULT)?'auto':$conf->global->MAIN_LANG_DEFAULT):$userlang);
@@ -239,15 +268,18 @@  discard block
 block discarded – undo
239 268
     dol_syslog("email_unpaid_invoices_to_customers.php: send mail to ".$oldemail);
240 269
 
241 270
     $usehtml=0;
242
-    if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER)) $usehtml+=1;
243
-    if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER)) $usehtml+=1;
271
+    if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER)) {
272
+        $usehtml+=1;
273
+    }
274
+    if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER)) {
275
+        $usehtml+=1;
276
+    }
244 277
 
245 278
     $allmessage='';
246 279
     if (! empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER))
247 280
     {
248 281
     	$allmessage.=$conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER;
249
-    }
250
-    else
282
+    } else
251 283
     {
252 284
     	$allmessage.= "Dear customer".($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
253 285
     	$allmessage.= "Please, find a summary of the bills with pending payments from you.".($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
@@ -258,7 +290,9 @@  discard block
 block discarded – undo
258 290
     if (! empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER))
259 291
     {
260 292
     	$allmessage.=$conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER;
261
-    	if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER)) $usehtml+=1;
293
+    	if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER)) {
294
+    	    $usehtml+=1;
295
+    	}
262 296
     }
263 297
 
264 298
     $mail = new CMailFile(
@@ -286,8 +320,7 @@  discard block
 block discarded – undo
286 320
     		print "Error sending email ".$mail->error."\n";
287 321
     		dol_syslog("Error sending email ".$mail->error."\n");
288 322
     	}
289
-    }
290
-    else
323
+    } else
291 324
     {
292 325
     	print "No email sent (test mode)\n";
293 326
     	dol_syslog("No email sent (test mode)");
@@ -299,8 +332,7 @@  discard block
 block discarded – undo
299 332
     if ($result)
300 333
     {
301 334
         return 1;
302
-    }
303
-    else
335
+    } else
304 336
     {
305 337
         return -1;
306 338
     }
Please login to merge, or discard this patch.
dolibarr/scripts/user/sync_users_dolibarr2ldap.php 3 patches
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -31,12 +31,12 @@  discard block
 block discarded – undo
31 31
 // Test if batch mode
32 32
 if (substr($sapi_type, 0, 3) == 'cgi') {
33 33
     echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
34
-	exit(-1);
34
+    exit(-1);
35 35
 }
36 36
 
37 37
 if (! isset($argv[1]) || ! $argv[1]) {
38 38
     print "Usage: $script_file now\n";
39
-	exit(-1);
39
+    exit(-1);
40 40
 }
41 41
 $now=$argv[1];
42 42
 
@@ -71,53 +71,53 @@  discard block
 block discarded – undo
71 71
 $resql = $db->query($sql);
72 72
 if ($resql)
73 73
 {
74
-	$num = $db->num_rows($resql);
75
-	$i = 0;
74
+    $num = $db->num_rows($resql);
75
+    $i = 0;
76 76
 
77
-	$ldap=new Ldap();
78
-	$ldap->connect_bind();
77
+    $ldap=new Ldap();
78
+    $ldap->connect_bind();
79 79
 
80
-	while ($i < $num)
81
-	{
82
-		$ldap->error="";
80
+    while ($i < $num)
81
+    {
82
+        $ldap->error="";
83 83
 
84
-		$obj = $db->fetch_object($resql);
84
+        $obj = $db->fetch_object($resql);
85 85
 
86
-		$fuser = new User($db);
87
-		$fuser->fetch($obj->rowid);
86
+        $fuser = new User($db);
87
+        $fuser->fetch($obj->rowid);
88 88
 
89
-		print $langs->trans("UpdateUser")." rowid=".$fuser->id." ".$fuser->getFullName($langs);
89
+        print $langs->trans("UpdateUser")." rowid=".$fuser->id." ".$fuser->getFullName($langs);
90 90
 
91
-		$oldobject=$fuser;
91
+        $oldobject=$fuser;
92 92
 
93
-	    $oldinfo=$oldobject->_load_ldap_info();
94
-	    $olddn=$oldobject->_load_ldap_dn($oldinfo);
93
+        $oldinfo=$oldobject->_load_ldap_info();
94
+        $olddn=$oldobject->_load_ldap_dn($oldinfo);
95 95
 
96
-	    $info=$fuser->_load_ldap_info();
97
-		$dn=$fuser->_load_ldap_dn($info);
96
+        $info=$fuser->_load_ldap_info();
97
+        $dn=$fuser->_load_ldap_dn($info);
98 98
 
99
-		$result=$ldap->add($dn,$info,$user);	// Wil fail if already exists
100
-		$result=$ldap->update($dn,$info,$user,$olddn);
101
-		if ($result > 0)
102
-		{
103
-			print " - ".$langs->trans("OK");
104
-		}
105
-		else
106
-		{
107
-			$error++;
108
-			print " - ".$langs->trans("KO").' - '.$ldap->error;
109
-		}
110
-		print "\n";
99
+        $result=$ldap->add($dn,$info,$user);	// Wil fail if already exists
100
+        $result=$ldap->update($dn,$info,$user,$olddn);
101
+        if ($result > 0)
102
+        {
103
+            print " - ".$langs->trans("OK");
104
+        }
105
+        else
106
+        {
107
+            $error++;
108
+            print " - ".$langs->trans("KO").' - '.$ldap->error;
109
+        }
110
+        print "\n";
111 111
 
112
-		$i++;
113
-	}
112
+        $i++;
113
+    }
114 114
 
115
-	$ldap->unbind();
116
-	$ldap->close();
115
+    $ldap->unbind();
116
+    $ldap->close();
117 117
 }
118 118
 else
119 119
 {
120
-	dol_print_error($db);
120
+    dol_print_error($db);
121 121
 }
122 122
 
123 123
 exit($error);
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 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 if batch mode
32 32
 if (substr($sapi_type, 0, 3) == 'cgi') {
@@ -34,19 +34,19 @@  discard block
 block discarded – undo
34 34
 	exit(-1);
35 35
 }
36 36
 
37
-if (! isset($argv[1]) || ! $argv[1]) {
37
+if (!isset($argv[1]) || !$argv[1]) {
38 38
     print "Usage: $script_file now\n";
39 39
 	exit(-1);
40 40
 }
41
-$now=$argv[1];
41
+$now = $argv[1];
42 42
 
43 43
 require_once $path."../../htdocs/master.inc.php";
44 44
 require_once DOL_DOCUMENT_ROOT."/core/class/ldap.class.php";
45 45
 require_once DOL_DOCUMENT_ROOT."/user/class/user.class.php";
46 46
 
47 47
 // Global variables
48
-$version=DOL_VERSION;
49
-$error=0;
48
+$version = DOL_VERSION;
49
+$error = 0;
50 50
 
51 51
 
52 52
 /*
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 
56 56
 @set_time_limit(0);
57 57
 print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
58
-dol_syslog($script_file." launched with arg ".join(',',$argv));
58
+dol_syslog($script_file." launched with arg ".join(',', $argv));
59 59
 
60 60
 /*
61 61
 if (! $conf->global->LDAP_SYNCHRO_ACTIVE)
@@ -74,12 +74,12 @@  discard block
 block discarded – undo
74 74
 	$num = $db->num_rows($resql);
75 75
 	$i = 0;
76 76
 
77
-	$ldap=new Ldap();
77
+	$ldap = new Ldap();
78 78
 	$ldap->connect_bind();
79 79
 
80 80
 	while ($i < $num)
81 81
 	{
82
-		$ldap->error="";
82
+		$ldap->error = "";
83 83
 
84 84
 		$obj = $db->fetch_object($resql);
85 85
 
@@ -88,16 +88,16 @@  discard block
 block discarded – undo
88 88
 
89 89
 		print $langs->trans("UpdateUser")." rowid=".$fuser->id." ".$fuser->getFullName($langs);
90 90
 
91
-		$oldobject=$fuser;
91
+		$oldobject = $fuser;
92 92
 
93
-	    $oldinfo=$oldobject->_load_ldap_info();
94
-	    $olddn=$oldobject->_load_ldap_dn($oldinfo);
93
+	    $oldinfo = $oldobject->_load_ldap_info();
94
+	    $olddn = $oldobject->_load_ldap_dn($oldinfo);
95 95
 
96
-	    $info=$fuser->_load_ldap_info();
97
-		$dn=$fuser->_load_ldap_dn($info);
96
+	    $info = $fuser->_load_ldap_info();
97
+		$dn = $fuser->_load_ldap_dn($info);
98 98
 
99
-		$result=$ldap->add($dn,$info,$user);	// Wil fail if already exists
100
-		$result=$ldap->update($dn,$info,$user,$olddn);
99
+		$result = $ldap->add($dn, $info, $user); // Wil fail if already exists
100
+		$result = $ldap->update($dn, $info, $user, $olddn);
101 101
 		if ($result > 0)
102 102
 		{
103 103
 			print " - ".$langs->trans("OK");
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -101,8 +101,7 @@  discard block
 block discarded – undo
101 101
 		if ($result > 0)
102 102
 		{
103 103
 			print " - ".$langs->trans("OK");
104
-		}
105
-		else
104
+		} else
106 105
 		{
107 106
 			$error++;
108 107
 			print " - ".$langs->trans("KO").' - '.$ldap->error;
@@ -114,8 +113,7 @@  discard block
 block discarded – undo
114 113
 
115 114
 	$ldap->unbind();
116 115
 	$ldap->close();
117
-}
118
-else
116
+} else
119 117
 {
120 118
 	dol_print_error($db);
121 119
 }
Please login to merge, or discard this patch.
dolibarr/scripts/user/sync_users_ldap2dolibarr.php 3 patches
Indentation   +161 added lines, -161 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 // Test if batch mode
32 32
 if (substr($sapi_type, 0, 3) == 'cgi') {
33 33
     echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
34
-	exit(-1);
34
+    exit(-1);
35 35
 }
36 36
 
37 37
 require_once $path."../../htdocs/master.inc.php";
@@ -58,41 +58,41 @@  discard block
 block discarded – undo
58 58
 
59 59
 // List of fields to get from LDAP
60 60
 $required_fields = array(
61
-	$conf->global->LDAP_KEY_USERS,
62
-	$conf->global->LDAP_FIELD_FULLNAME,
63
-	$conf->global->LDAP_FIELD_NAME,
64
-	$conf->global->LDAP_FIELD_FIRSTNAME,
65
-	$conf->global->LDAP_FIELD_LOGIN,
66
-	$conf->global->LDAP_FIELD_LOGIN_SAMBA,
67
-	$conf->global->LDAP_FIELD_PASSWORD,
68
-	$conf->global->LDAP_FIELD_PASSWORD_CRYPTED,
69
-	$conf->global->LDAP_FIELD_PHONE,
70
-	$conf->global->LDAP_FIELD_FAX,
71
-	$conf->global->LDAP_FIELD_MOBILE,
72
-	//$conf->global->LDAP_FIELD_ADDRESS,
73
-	//$conf->global->LDAP_FIELD_ZIP,
74
-	//$conf->global->LDAP_FIELD_TOWN,
75
-	//$conf->global->LDAP_FIELD_COUNTRY,
76
-	$conf->global->LDAP_FIELD_MAIL,
77
-	$conf->global->LDAP_FIELD_TITLE,
78
-	$conf->global->LDAP_FIELD_DESCRIPTION,
79
-	$conf->global->LDAP_FIELD_SID
61
+    $conf->global->LDAP_KEY_USERS,
62
+    $conf->global->LDAP_FIELD_FULLNAME,
63
+    $conf->global->LDAP_FIELD_NAME,
64
+    $conf->global->LDAP_FIELD_FIRSTNAME,
65
+    $conf->global->LDAP_FIELD_LOGIN,
66
+    $conf->global->LDAP_FIELD_LOGIN_SAMBA,
67
+    $conf->global->LDAP_FIELD_PASSWORD,
68
+    $conf->global->LDAP_FIELD_PASSWORD_CRYPTED,
69
+    $conf->global->LDAP_FIELD_PHONE,
70
+    $conf->global->LDAP_FIELD_FAX,
71
+    $conf->global->LDAP_FIELD_MOBILE,
72
+    //$conf->global->LDAP_FIELD_ADDRESS,
73
+    //$conf->global->LDAP_FIELD_ZIP,
74
+    //$conf->global->LDAP_FIELD_TOWN,
75
+    //$conf->global->LDAP_FIELD_COUNTRY,
76
+    $conf->global->LDAP_FIELD_MAIL,
77
+    $conf->global->LDAP_FIELD_TITLE,
78
+    $conf->global->LDAP_FIELD_DESCRIPTION,
79
+    $conf->global->LDAP_FIELD_SID
80 80
 );
81 81
 
82 82
 // Remove from required_fields all entries not configured in LDAP (empty) and duplicated
83 83
 $required_fields=array_unique(array_values(array_filter($required_fields, "dolValidElement")));
84 84
 
85 85
 if (! isset($argv[1])) {
86
-	print "Usage:  $script_file (nocommitiferror|commitiferror) [--server=ldapserverhost] [--excludeuser=user1,user2...] [-y]\n";
86
+    print "Usage:  $script_file (nocommitiferror|commitiferror) [--server=ldapserverhost] [--excludeuser=user1,user2...] [-y]\n";
87 87
     exit(-1);
88 88
 }
89 89
 
90 90
 foreach($argv as $key => $val)
91 91
 {
92
-	if ($val == 'commitiferror') $forcecommit=1;
93
-	if (preg_match('/--server=([^\s]+)$/',$val,$reg)) $conf->global->LDAP_SERVER_HOST=$reg[1];
94
-	if (preg_match('/--excludeuser=([^\s]+)$/',$val,$reg)) $excludeuser=explode(',',$reg[1]);
95
-	if (preg_match('/-y$/',$val,$reg)) $confirmed=1;
92
+    if ($val == 'commitiferror') $forcecommit=1;
93
+    if (preg_match('/--server=([^\s]+)$/',$val,$reg)) $conf->global->LDAP_SERVER_HOST=$reg[1];
94
+    if (preg_match('/--excludeuser=([^\s]+)$/',$val,$reg)) $excludeuser=explode(',',$reg[1]);
95
+    if (preg_match('/-y$/',$val,$reg)) $confirmed=1;
96 96
 }
97 97
 
98 98
 print "Mails sending disabled (useless in batch mode)\n";
@@ -120,14 +120,14 @@  discard block
 block discarded – undo
120 120
 
121 121
 if (! $confirmed)
122 122
 {
123
-	print "Hit Enter to continue or CTRL+C to stop...\n";
124
-	$input = trim(fgets(STDIN));
123
+    print "Hit Enter to continue or CTRL+C to stop...\n";
124
+    $input = trim(fgets(STDIN));
125 125
 }
126 126
 
127 127
 if (empty($conf->global->LDAP_USER_DN))
128 128
 {
129
-	print $langs->trans("Error").': '.$langs->trans("LDAP setup for users not defined inside Dolibarr");
130
-	exit(-1);
129
+    print $langs->trans("Error").': '.$langs->trans("LDAP setup for users not defined inside Dolibarr");
130
+    exit(-1);
131 131
 }
132 132
 
133 133
 
@@ -141,27 +141,27 @@  discard block
 block discarded – undo
141 141
 $resql=$db->query($sql);
142 142
 if ($resql)
143 143
 {
144
-	$num = $db->num_rows($resql);
145
-	$i = 0;
146
-	if ($num)
147
-	{
148
-		while ($i < $num)
149
-		{
150
-			$obj = $db->fetch_object($resql);
151
-			if ($obj)
152
-			{
153
-				//print 'Load cache for country '.strtolower($obj->label).' rowid='.$obj->rowid."\n";
154
-				$hashlib2rowid[strtolower($obj->label)]=$obj->rowid;
155
-				$countries[$obj->rowid]=array('rowid' => $obj->rowid, 'label' => $obj->label, 'code' => $obj->code);
156
-			}
157
-			$i++;
158
-		}
159
-	}
144
+    $num = $db->num_rows($resql);
145
+    $i = 0;
146
+    if ($num)
147
+    {
148
+        while ($i < $num)
149
+        {
150
+            $obj = $db->fetch_object($resql);
151
+            if ($obj)
152
+            {
153
+                //print 'Load cache for country '.strtolower($obj->label).' rowid='.$obj->rowid."\n";
154
+                $hashlib2rowid[strtolower($obj->label)]=$obj->rowid;
155
+                $countries[$obj->rowid]=array('rowid' => $obj->rowid, 'label' => $obj->label, 'code' => $obj->code);
156
+            }
157
+            $i++;
158
+        }
159
+    }
160 160
 }
161 161
 else
162 162
 {
163
-	dol_print_error($db);
164
-	exit(-1);
163
+    dol_print_error($db);
164
+    exit(-1);
165 165
 }
166 166
 
167 167
 
@@ -170,44 +170,44 @@  discard block
 block discarded – undo
170 170
 $result = $ldap->connect_bind();
171 171
 if ($result >= 0)
172 172
 {
173
-	$justthese=array();
174
-
175
-
176
-	// We disable synchro Dolibarr-LDAP
177
-	$conf->global->LDAP_SYNCHRO_ACTIVE=0;
178
-
179
-	$ldaprecords = $ldap->getRecords('*',$conf->global->LDAP_USER_DN, $conf->global->LDAP_KEY_USERS, $required_fields, 'user');	// Fiter on 'user' filter param
180
-	if (is_array($ldaprecords))
181
-	{
182
-		$db->begin();
183
-
184
-		// Warning $ldapuser has a key in lowercase
185
-		foreach ($ldaprecords as $key => $ldapuser)
186
-		{
187
-			// If login into exclude list, we discard record
188
-			if (in_array($ldapuser[$conf->global->LDAP_FIELD_LOGIN],$excludeuser))
189
-			{
190
-				print $langs->transnoentities("UserDiscarded").' # '.$key.': login='.$ldapuser[$conf->global->LDAP_FIELD_LOGIN].' --> Discarded'."\n";
191
-				continue;
192
-			}
193
-
194
-			$fuser = new User($db);
195
-
196
-			if($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_SID) {
197
-				$fuser->fetch('','',$ldapuser[$conf->global->LDAP_KEY_USERS]); // Chargement du user concerné par le SID
198
-			} else if($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_LOGIN) {
199
-				$fuser->fetch('',$ldapuser[$conf->global->LDAP_KEY_USERS]); // Chargement du user concerné par le login
200
-			}
201
-
202
-			// Propriete membre
203
-			$fuser->firstname=$ldapuser[$conf->global->LDAP_FIELD_FIRSTNAME];
204
-			$fuser->lastname=$ldapuser[$conf->global->LDAP_FIELD_NAME];
205
-			$fuser->login=$ldapuser[$conf->global->LDAP_FIELD_LOGIN];
206
-			$fuser->pass=$ldapuser[$conf->global->LDAP_FIELD_PASSWORD];
207
-			$fuser->pass_indatabase_crypted=$ldapuser[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED];
208
-
209
-			//$user->societe;
210
-			/*
173
+    $justthese=array();
174
+
175
+
176
+    // We disable synchro Dolibarr-LDAP
177
+    $conf->global->LDAP_SYNCHRO_ACTIVE=0;
178
+
179
+    $ldaprecords = $ldap->getRecords('*',$conf->global->LDAP_USER_DN, $conf->global->LDAP_KEY_USERS, $required_fields, 'user');	// Fiter on 'user' filter param
180
+    if (is_array($ldaprecords))
181
+    {
182
+        $db->begin();
183
+
184
+        // Warning $ldapuser has a key in lowercase
185
+        foreach ($ldaprecords as $key => $ldapuser)
186
+        {
187
+            // If login into exclude list, we discard record
188
+            if (in_array($ldapuser[$conf->global->LDAP_FIELD_LOGIN],$excludeuser))
189
+            {
190
+                print $langs->transnoentities("UserDiscarded").' # '.$key.': login='.$ldapuser[$conf->global->LDAP_FIELD_LOGIN].' --> Discarded'."\n";
191
+                continue;
192
+            }
193
+
194
+            $fuser = new User($db);
195
+
196
+            if($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_SID) {
197
+                $fuser->fetch('','',$ldapuser[$conf->global->LDAP_KEY_USERS]); // Chargement du user concerné par le SID
198
+            } else if($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_LOGIN) {
199
+                $fuser->fetch('',$ldapuser[$conf->global->LDAP_KEY_USERS]); // Chargement du user concerné par le login
200
+            }
201
+
202
+            // Propriete membre
203
+            $fuser->firstname=$ldapuser[$conf->global->LDAP_FIELD_FIRSTNAME];
204
+            $fuser->lastname=$ldapuser[$conf->global->LDAP_FIELD_NAME];
205
+            $fuser->login=$ldapuser[$conf->global->LDAP_FIELD_LOGIN];
206
+            $fuser->pass=$ldapuser[$conf->global->LDAP_FIELD_PASSWORD];
207
+            $fuser->pass_indatabase_crypted=$ldapuser[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED];
208
+
209
+            //$user->societe;
210
+            /*
211 211
 			$fuser->address=$ldapuser[$conf->global->LDAP_FIELD_ADDRESS];
212 212
 			$fuser->zip=$ldapuser[$conf->global->LDAP_FIELD_ZIP];
213 213
 			$fuser->town=$ldapuser[$conf->global->LDAP_FIELD_TOWN];
@@ -216,93 +216,93 @@  discard block
 block discarded – undo
216 216
 			$fuser->country_code=$countries[$hashlib2rowid[strtolower($fuser->country)]]['code'];
217 217
 			*/
218 218
 
219
-			$fuser->office_phone=$ldapuser[$conf->global->LDAP_FIELD_PHONE];
220
-			$fuser->user_mobile=$ldapuser[$conf->global->LDAP_FIELD_MOBILE];
221
-			$fuser->office_fax=$ldapuser[$conf->global->LDAP_FIELD_FAX];
222
-			$fuser->email=$ldapuser[$conf->global->LDAP_FIELD_MAIL];
223
-			$fuser->ldap_sid=$ldapuser[$conf->global->LDAP_FIELD_SID];
224
-
225
-			$fuser->job=$ldapuser[$conf->global->LDAP_FIELD_TITLE];
226
-			$fuser->note=$ldapuser[$conf->global->LDAP_FIELD_DESCRIPTION];
227
-			$fuser->admin=0;
228
-			$fuser->societe_id=0;
229
-			$fuser->contact_id=0;
230
-			$fuser->fk_member=0;
231
-
232
-			$fuser->statut=1;
233
-			// TODO : revoir la gestion du status
234
-			/*if (isset($ldapuser[$conf->global->LDAP_FIELD_MEMBER_STATUS]))
219
+            $fuser->office_phone=$ldapuser[$conf->global->LDAP_FIELD_PHONE];
220
+            $fuser->user_mobile=$ldapuser[$conf->global->LDAP_FIELD_MOBILE];
221
+            $fuser->office_fax=$ldapuser[$conf->global->LDAP_FIELD_FAX];
222
+            $fuser->email=$ldapuser[$conf->global->LDAP_FIELD_MAIL];
223
+            $fuser->ldap_sid=$ldapuser[$conf->global->LDAP_FIELD_SID];
224
+
225
+            $fuser->job=$ldapuser[$conf->global->LDAP_FIELD_TITLE];
226
+            $fuser->note=$ldapuser[$conf->global->LDAP_FIELD_DESCRIPTION];
227
+            $fuser->admin=0;
228
+            $fuser->societe_id=0;
229
+            $fuser->contact_id=0;
230
+            $fuser->fk_member=0;
231
+
232
+            $fuser->statut=1;
233
+            // TODO : revoir la gestion du status
234
+            /*if (isset($ldapuser[$conf->global->LDAP_FIELD_MEMBER_STATUS]))
235 235
 			{
236 236
 				$fuser->datec=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE]);
237 237
 				$fuser->datevalid=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE]);
238 238
 				$fuser->statut=$ldapuser[$conf->global->LDAP_FIELD_MEMBER_STATUS];
239 239
 			}*/
240
-			//if ($fuser->statut > 1) $fuser->statut=1;
241
-
242
-			//print_r($ldapuser);
243
-
244
-			if($fuser->id > 0) { // User update
245
-				print $langs->transnoentities("UserUpdate").' # '.$key.': login='.$fuser->login.', fullname='.$fuser->getFullName($langs);
246
-				$res=$fuser->update($user);
247
-
248
-				if ($res < 0)
249
-				{
250
-					$error++;
251
-					print ' --> '.$res.' '.$fuser->error;
252
-				}
253
-				else
254
-				{
255
-					print ' --> Updated user id='.$fuser->id.' login='.$fuser->login;
256
-				}
257
-			} else { // User creation
258
-				print $langs->transnoentities("UserCreate").' # '.$key.': login='.$fuser->login.', fullname='.$fuser->getFullName($langs);
259
-				$res=$fuser->create($user);
260
-
261
-				if ($res > 0)
262
-				{
263
-					print ' --> Created user id='.$fuser->id.' login='.$fuser->login;
264
-				}
265
-				else
266
-				{
267
-					$error++;
268
-					print ' --> '.$res.' '.$fuser->error;
269
-				}
270
-			}
271
-			print "\n";
272
-			//print_r($fuser);
273
-
274
-			// Gestion des groupes
275
-			// TODO : revoir la gestion des groupes (ou script de sync groupes)
276
-			/*if(!$error) {
240
+            //if ($fuser->statut > 1) $fuser->statut=1;
241
+
242
+            //print_r($ldapuser);
243
+
244
+            if($fuser->id > 0) { // User update
245
+                print $langs->transnoentities("UserUpdate").' # '.$key.': login='.$fuser->login.', fullname='.$fuser->getFullName($langs);
246
+                $res=$fuser->update($user);
247
+
248
+                if ($res < 0)
249
+                {
250
+                    $error++;
251
+                    print ' --> '.$res.' '.$fuser->error;
252
+                }
253
+                else
254
+                {
255
+                    print ' --> Updated user id='.$fuser->id.' login='.$fuser->login;
256
+                }
257
+            } else { // User creation
258
+                print $langs->transnoentities("UserCreate").' # '.$key.': login='.$fuser->login.', fullname='.$fuser->getFullName($langs);
259
+                $res=$fuser->create($user);
260
+
261
+                if ($res > 0)
262
+                {
263
+                    print ' --> Created user id='.$fuser->id.' login='.$fuser->login;
264
+                }
265
+                else
266
+                {
267
+                    $error++;
268
+                    print ' --> '.$res.' '.$fuser->error;
269
+                }
270
+            }
271
+            print "\n";
272
+            //print_r($fuser);
273
+
274
+            // Gestion des groupes
275
+            // TODO : revoir la gestion des groupes (ou script de sync groupes)
276
+            /*if(!$error) {
277 277
 				foreach ($ldapuser[$conf->global->LDAP_FIELD_USERGROUPS] as $groupdn) {
278 278
 					$groupdn;
279 279
 				}
280 280
 			}*/
281
-		}
282
-
283
-		if (! $error || $forcecommit)
284
-		{
285
-			if (! $error) print $langs->transnoentities("NoErrorCommitIsDone")."\n";
286
-			else print $langs->transnoentities("ErrorButCommitIsDone")."\n";
287
-			$db->commit();
288
-		}
289
-		else
290
-		{
291
-			print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone",$error)."\n";
292
-			$db->rollback();
293
-		}
294
-		print "\n";
295
-	}
296
-	else
297
-	{
298
-		dol_print_error('',$ldap->error);
299
-		$error++;
300
-	}
281
+        }
282
+
283
+        if (! $error || $forcecommit)
284
+        {
285
+            if (! $error) print $langs->transnoentities("NoErrorCommitIsDone")."\n";
286
+            else print $langs->transnoentities("ErrorButCommitIsDone")."\n";
287
+            $db->commit();
288
+        }
289
+        else
290
+        {
291
+            print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone",$error)."\n";
292
+            $db->rollback();
293
+        }
294
+        print "\n";
295
+    }
296
+    else
297
+    {
298
+        dol_print_error('',$ldap->error);
299
+        $error++;
300
+    }
301 301
 }
302 302
 else
303 303
 {
304
-	dol_print_error('',$ldap->error);
305
-	$error++;
304
+    dol_print_error('',$ldap->error);
305
+    $error++;
306 306
 }
307 307
 
308 308
 
@@ -317,6 +317,6 @@  discard block
 block discarded – undo
317 317
  */
318 318
 function dolValidElement($element)
319 319
 {
320
-	return (trim($element) != '');
320
+    return (trim($element) != '');
321 321
 }
322 322
 
Please login to merge, or discard this patch.
Spacing   +61 added lines, -61 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 if batch mode
32 32
 if (substr($sapi_type, 0, 3) == 'cgi') {
@@ -42,11 +42,11 @@  discard block
 block discarded – undo
42 42
 $langs->loadLangs(array("main", "errors"));
43 43
 
44 44
 // Global variables
45
-$version=DOL_VERSION;
46
-$error=0;
47
-$forcecommit=0;
48
-$excludeuser=array();
49
-$confirmed=0;
45
+$version = DOL_VERSION;
46
+$error = 0;
47
+$forcecommit = 0;
48
+$excludeuser = array();
49
+$confirmed = 0;
50 50
 
51 51
 /*
52 52
  * Main
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 
55 55
 @set_time_limit(0);
56 56
 print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
57
-dol_syslog($script_file." launched with arg ".join(',',$argv));
57
+dol_syslog($script_file." launched with arg ".join(',', $argv));
58 58
 
59 59
 // List of fields to get from LDAP
60 60
 $required_fields = array(
@@ -80,31 +80,31 @@  discard block
 block discarded – undo
80 80
 );
81 81
 
82 82
 // Remove from required_fields all entries not configured in LDAP (empty) and duplicated
83
-$required_fields=array_unique(array_values(array_filter($required_fields, "dolValidElement")));
83
+$required_fields = array_unique(array_values(array_filter($required_fields, "dolValidElement")));
84 84
 
85
-if (! isset($argv[1])) {
85
+if (!isset($argv[1])) {
86 86
 	print "Usage:  $script_file (nocommitiferror|commitiferror) [--server=ldapserverhost] [--excludeuser=user1,user2...] [-y]\n";
87 87
     exit(-1);
88 88
 }
89 89
 
90
-foreach($argv as $key => $val)
90
+foreach ($argv as $key => $val)
91 91
 {
92
-	if ($val == 'commitiferror') $forcecommit=1;
93
-	if (preg_match('/--server=([^\s]+)$/',$val,$reg)) $conf->global->LDAP_SERVER_HOST=$reg[1];
94
-	if (preg_match('/--excludeuser=([^\s]+)$/',$val,$reg)) $excludeuser=explode(',',$reg[1]);
95
-	if (preg_match('/-y$/',$val,$reg)) $confirmed=1;
92
+	if ($val == 'commitiferror') $forcecommit = 1;
93
+	if (preg_match('/--server=([^\s]+)$/', $val, $reg)) $conf->global->LDAP_SERVER_HOST = $reg[1];
94
+	if (preg_match('/--excludeuser=([^\s]+)$/', $val, $reg)) $excludeuser = explode(',', $reg[1]);
95
+	if (preg_match('/-y$/', $val, $reg)) $confirmed = 1;
96 96
 }
97 97
 
98 98
 print "Mails sending disabled (useless in batch mode)\n";
99
-$conf->global->MAIN_DISABLE_ALL_MAILS=1;	// On bloque les mails
99
+$conf->global->MAIN_DISABLE_ALL_MAILS = 1; // On bloque les mails
100 100
 print "\n";
101 101
 print "----- Synchronize all records from LDAP database:\n";
102 102
 print "host=".$conf->global->LDAP_SERVER_HOST."\n";
103 103
 print "port=".$conf->global->LDAP_SERVER_PORT."\n";
104 104
 print "login=".$conf->global->LDAP_ADMIN_DN."\n";
105
-print "pass=".preg_replace('/./i','*',$conf->global->LDAP_ADMIN_PASS)."\n";
105
+print "pass=".preg_replace('/./i', '*', $conf->global->LDAP_ADMIN_PASS)."\n";
106 106
 print "DN to extract=".$conf->global->LDAP_USER_DN."\n";
107
-if (! empty($conf->global->LDAP_FILTER_CONNECTION)) print 'Filter=('.$conf->global->LDAP_FILTER_CONNECTION.')'."\n";	// Note: filter is defined into function getRecords
107
+if (!empty($conf->global->LDAP_FILTER_CONNECTION)) print 'Filter=('.$conf->global->LDAP_FILTER_CONNECTION.')'."\n"; // Note: filter is defined into function getRecords
108 108
 else print 'Filter=('.$conf->global->LDAP_KEY_USERS.'=*)'."\n";
109 109
 print "----- To Dolibarr database:\n";
110 110
 print "type=".$conf->db->type."\n";
@@ -114,11 +114,11 @@  discard block
 block discarded – undo
114 114
 print "database=".$conf->db->name."\n";
115 115
 print "----- Options:\n";
116 116
 print "commitiferror=".$forcecommit."\n";
117
-print "excludeuser=".join(',',$excludeuser)."\n";
118
-print "Mapped LDAP fields=".join(',',$required_fields)."\n";
117
+print "excludeuser=".join(',', $excludeuser)."\n";
118
+print "Mapped LDAP fields=".join(',', $required_fields)."\n";
119 119
 print "\n";
120 120
 
121
-if (! $confirmed)
121
+if (!$confirmed)
122 122
 {
123 123
 	print "Hit Enter to continue or CTRL+C to stop...\n";
124 124
 	$input = trim(fgets(STDIN));
@@ -132,13 +132,13 @@  discard block
 block discarded – undo
132 132
 
133 133
 
134 134
 // Load table of correspondence of countries
135
-$hashlib2rowid=array();
136
-$countries=array();
135
+$hashlib2rowid = array();
136
+$countries = array();
137 137
 $sql = "SELECT rowid, code, label, active";
138
-$sql.= " FROM ".MAIN_DB_PREFIX."c_country";
139
-$sql.= " WHERE active = 1";
140
-$sql.= " ORDER BY code ASC";
141
-$resql=$db->query($sql);
138
+$sql .= " FROM ".MAIN_DB_PREFIX."c_country";
139
+$sql .= " WHERE active = 1";
140
+$sql .= " ORDER BY code ASC";
141
+$resql = $db->query($sql);
142 142
 if ($resql)
143 143
 {
144 144
 	$num = $db->num_rows($resql);
@@ -151,8 +151,8 @@  discard block
 block discarded – undo
151 151
 			if ($obj)
152 152
 			{
153 153
 				//print 'Load cache for country '.strtolower($obj->label).' rowid='.$obj->rowid."\n";
154
-				$hashlib2rowid[strtolower($obj->label)]=$obj->rowid;
155
-				$countries[$obj->rowid]=array('rowid' => $obj->rowid, 'label' => $obj->label, 'code' => $obj->code);
154
+				$hashlib2rowid[strtolower($obj->label)] = $obj->rowid;
155
+				$countries[$obj->rowid] = array('rowid' => $obj->rowid, 'label' => $obj->label, 'code' => $obj->code);
156 156
 			}
157 157
 			$i++;
158 158
 		}
@@ -170,13 +170,13 @@  discard block
 block discarded – undo
170 170
 $result = $ldap->connect_bind();
171 171
 if ($result >= 0)
172 172
 {
173
-	$justthese=array();
173
+	$justthese = array();
174 174
 
175 175
 
176 176
 	// We disable synchro Dolibarr-LDAP
177
-	$conf->global->LDAP_SYNCHRO_ACTIVE=0;
177
+	$conf->global->LDAP_SYNCHRO_ACTIVE = 0;
178 178
 
179
-	$ldaprecords = $ldap->getRecords('*',$conf->global->LDAP_USER_DN, $conf->global->LDAP_KEY_USERS, $required_fields, 'user');	// Fiter on 'user' filter param
179
+	$ldaprecords = $ldap->getRecords('*', $conf->global->LDAP_USER_DN, $conf->global->LDAP_KEY_USERS, $required_fields, 'user'); // Fiter on 'user' filter param
180 180
 	if (is_array($ldaprecords))
181 181
 	{
182 182
 		$db->begin();
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
 		foreach ($ldaprecords as $key => $ldapuser)
186 186
 		{
187 187
 			// If login into exclude list, we discard record
188
-			if (in_array($ldapuser[$conf->global->LDAP_FIELD_LOGIN],$excludeuser))
188
+			if (in_array($ldapuser[$conf->global->LDAP_FIELD_LOGIN], $excludeuser))
189 189
 			{
190 190
 				print $langs->transnoentities("UserDiscarded").' # '.$key.': login='.$ldapuser[$conf->global->LDAP_FIELD_LOGIN].' --> Discarded'."\n";
191 191
 				continue;
@@ -193,18 +193,18 @@  discard block
 block discarded – undo
193 193
 
194 194
 			$fuser = new User($db);
195 195
 
196
-			if($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_SID) {
197
-				$fuser->fetch('','',$ldapuser[$conf->global->LDAP_KEY_USERS]); // Chargement du user concerné par le SID
198
-			} else if($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_LOGIN) {
199
-				$fuser->fetch('',$ldapuser[$conf->global->LDAP_KEY_USERS]); // Chargement du user concerné par le login
196
+			if ($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_SID) {
197
+				$fuser->fetch('', '', $ldapuser[$conf->global->LDAP_KEY_USERS]); // Chargement du user concerné par le SID
198
+			} else if ($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_LOGIN) {
199
+				$fuser->fetch('', $ldapuser[$conf->global->LDAP_KEY_USERS]); // Chargement du user concerné par le login
200 200
 			}
201 201
 
202 202
 			// Propriete membre
203
-			$fuser->firstname=$ldapuser[$conf->global->LDAP_FIELD_FIRSTNAME];
204
-			$fuser->lastname=$ldapuser[$conf->global->LDAP_FIELD_NAME];
205
-			$fuser->login=$ldapuser[$conf->global->LDAP_FIELD_LOGIN];
206
-			$fuser->pass=$ldapuser[$conf->global->LDAP_FIELD_PASSWORD];
207
-			$fuser->pass_indatabase_crypted=$ldapuser[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED];
203
+			$fuser->firstname = $ldapuser[$conf->global->LDAP_FIELD_FIRSTNAME];
204
+			$fuser->lastname = $ldapuser[$conf->global->LDAP_FIELD_NAME];
205
+			$fuser->login = $ldapuser[$conf->global->LDAP_FIELD_LOGIN];
206
+			$fuser->pass = $ldapuser[$conf->global->LDAP_FIELD_PASSWORD];
207
+			$fuser->pass_indatabase_crypted = $ldapuser[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED];
208 208
 
209 209
 			//$user->societe;
210 210
 			/*
@@ -216,20 +216,20 @@  discard block
 block discarded – undo
216 216
 			$fuser->country_code=$countries[$hashlib2rowid[strtolower($fuser->country)]]['code'];
217 217
 			*/
218 218
 
219
-			$fuser->office_phone=$ldapuser[$conf->global->LDAP_FIELD_PHONE];
220
-			$fuser->user_mobile=$ldapuser[$conf->global->LDAP_FIELD_MOBILE];
221
-			$fuser->office_fax=$ldapuser[$conf->global->LDAP_FIELD_FAX];
222
-			$fuser->email=$ldapuser[$conf->global->LDAP_FIELD_MAIL];
223
-			$fuser->ldap_sid=$ldapuser[$conf->global->LDAP_FIELD_SID];
219
+			$fuser->office_phone = $ldapuser[$conf->global->LDAP_FIELD_PHONE];
220
+			$fuser->user_mobile = $ldapuser[$conf->global->LDAP_FIELD_MOBILE];
221
+			$fuser->office_fax = $ldapuser[$conf->global->LDAP_FIELD_FAX];
222
+			$fuser->email = $ldapuser[$conf->global->LDAP_FIELD_MAIL];
223
+			$fuser->ldap_sid = $ldapuser[$conf->global->LDAP_FIELD_SID];
224 224
 
225
-			$fuser->job=$ldapuser[$conf->global->LDAP_FIELD_TITLE];
226
-			$fuser->note=$ldapuser[$conf->global->LDAP_FIELD_DESCRIPTION];
227
-			$fuser->admin=0;
228
-			$fuser->societe_id=0;
229
-			$fuser->contact_id=0;
230
-			$fuser->fk_member=0;
225
+			$fuser->job = $ldapuser[$conf->global->LDAP_FIELD_TITLE];
226
+			$fuser->note = $ldapuser[$conf->global->LDAP_FIELD_DESCRIPTION];
227
+			$fuser->admin = 0;
228
+			$fuser->societe_id = 0;
229
+			$fuser->contact_id = 0;
230
+			$fuser->fk_member = 0;
231 231
 
232
-			$fuser->statut=1;
232
+			$fuser->statut = 1;
233 233
 			// TODO : revoir la gestion du status
234 234
 			/*if (isset($ldapuser[$conf->global->LDAP_FIELD_MEMBER_STATUS]))
235 235
 			{
@@ -241,9 +241,9 @@  discard block
 block discarded – undo
241 241
 
242 242
 			//print_r($ldapuser);
243 243
 
244
-			if($fuser->id > 0) { // User update
244
+			if ($fuser->id > 0) { // User update
245 245
 				print $langs->transnoentities("UserUpdate").' # '.$key.': login='.$fuser->login.', fullname='.$fuser->getFullName($langs);
246
-				$res=$fuser->update($user);
246
+				$res = $fuser->update($user);
247 247
 
248 248
 				if ($res < 0)
249 249
 				{
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
 				}
257 257
 			} else { // User creation
258 258
 				print $langs->transnoentities("UserCreate").' # '.$key.': login='.$fuser->login.', fullname='.$fuser->getFullName($langs);
259
-				$res=$fuser->create($user);
259
+				$res = $fuser->create($user);
260 260
 
261 261
 				if ($res > 0)
262 262
 				{
@@ -280,28 +280,28 @@  discard block
 block discarded – undo
280 280
 			}*/
281 281
 		}
282 282
 
283
-		if (! $error || $forcecommit)
283
+		if (!$error || $forcecommit)
284 284
 		{
285
-			if (! $error) print $langs->transnoentities("NoErrorCommitIsDone")."\n";
285
+			if (!$error) print $langs->transnoentities("NoErrorCommitIsDone")."\n";
286 286
 			else print $langs->transnoentities("ErrorButCommitIsDone")."\n";
287 287
 			$db->commit();
288 288
 		}
289 289
 		else
290 290
 		{
291
-			print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone",$error)."\n";
291
+			print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone", $error)."\n";
292 292
 			$db->rollback();
293 293
 		}
294 294
 		print "\n";
295 295
 	}
296 296
 	else
297 297
 	{
298
-		dol_print_error('',$ldap->error);
298
+		dol_print_error('', $ldap->error);
299 299
 		$error++;
300 300
 	}
301 301
 }
302 302
 else
303 303
 {
304
-	dol_print_error('',$ldap->error);
304
+	dol_print_error('', $ldap->error);
305 305
 	$error++;
306 306
 }
307 307
 
Please login to merge, or discard this patch.
Braces   +31 added lines, -21 removed lines patch added patch discarded remove patch
@@ -89,11 +89,19 @@  discard block
 block discarded – undo
89 89
 
90 90
 foreach($argv as $key => $val)
91 91
 {
92
-	if ($val == 'commitiferror') $forcecommit=1;
93
-	if (preg_match('/--server=([^\s]+)$/',$val,$reg)) $conf->global->LDAP_SERVER_HOST=$reg[1];
94
-	if (preg_match('/--excludeuser=([^\s]+)$/',$val,$reg)) $excludeuser=explode(',',$reg[1]);
95
-	if (preg_match('/-y$/',$val,$reg)) $confirmed=1;
96
-}
92
+	if ($val == 'commitiferror') {
93
+	    $forcecommit=1;
94
+	}
95
+	if (preg_match('/--server=([^\s]+)$/',$val,$reg)) {
96
+	    $conf->global->LDAP_SERVER_HOST=$reg[1];
97
+	}
98
+	if (preg_match('/--excludeuser=([^\s]+)$/',$val,$reg)) {
99
+	    $excludeuser=explode(',',$reg[1]);
100
+	}
101
+	if (preg_match('/-y$/',$val,$reg)) {
102
+	    $confirmed=1;
103
+	}
104
+	}
97 105
 
98 106
 print "Mails sending disabled (useless in batch mode)\n";
99 107
 $conf->global->MAIN_DISABLE_ALL_MAILS=1;	// On bloque les mails
@@ -104,8 +112,13 @@  discard block
 block discarded – undo
104 112
 print "login=".$conf->global->LDAP_ADMIN_DN."\n";
105 113
 print "pass=".preg_replace('/./i','*',$conf->global->LDAP_ADMIN_PASS)."\n";
106 114
 print "DN to extract=".$conf->global->LDAP_USER_DN."\n";
107
-if (! empty($conf->global->LDAP_FILTER_CONNECTION)) print 'Filter=('.$conf->global->LDAP_FILTER_CONNECTION.')'."\n";	// Note: filter is defined into function getRecords
108
-else print 'Filter=('.$conf->global->LDAP_KEY_USERS.'=*)'."\n";
115
+if (! empty($conf->global->LDAP_FILTER_CONNECTION)) {
116
+    print 'Filter=('.$conf->global->LDAP_FILTER_CONNECTION.')'."\n";
117
+}
118
+// Note: filter is defined into function getRecords
119
+else {
120
+    print 'Filter=('.$conf->global->LDAP_KEY_USERS.'=*)'."\n";
121
+}
109 122
 print "----- To Dolibarr database:\n";
110 123
 print "type=".$conf->db->type."\n";
111 124
 print "host=".$conf->db->host."\n";
@@ -157,8 +170,7 @@  discard block
 block discarded – undo
157 170
 			$i++;
158 171
 		}
159 172
 	}
160
-}
161
-else
173
+} else
162 174
 {
163 175
 	dol_print_error($db);
164 176
 	exit(-1);
@@ -249,8 +261,7 @@  discard block
 block discarded – undo
249 261
 				{
250 262
 					$error++;
251 263
 					print ' --> '.$res.' '.$fuser->error;
252
-				}
253
-				else
264
+				} else
254 265
 				{
255 266
 					print ' --> Updated user id='.$fuser->id.' login='.$fuser->login;
256 267
 				}
@@ -261,8 +272,7 @@  discard block
 block discarded – undo
261 272
 				if ($res > 0)
262 273
 				{
263 274
 					print ' --> Created user id='.$fuser->id.' login='.$fuser->login;
264
-				}
265
-				else
275
+				} else
266 276
 				{
267 277
 					$error++;
268 278
 					print ' --> '.$res.' '.$fuser->error;
@@ -282,24 +292,24 @@  discard block
 block discarded – undo
282 292
 
283 293
 		if (! $error || $forcecommit)
284 294
 		{
285
-			if (! $error) print $langs->transnoentities("NoErrorCommitIsDone")."\n";
286
-			else print $langs->transnoentities("ErrorButCommitIsDone")."\n";
295
+			if (! $error) {
296
+			    print $langs->transnoentities("NoErrorCommitIsDone")."\n";
297
+			} else {
298
+			    print $langs->transnoentities("ErrorButCommitIsDone")."\n";
299
+			}
287 300
 			$db->commit();
288
-		}
289
-		else
301
+		} else
290 302
 		{
291 303
 			print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone",$error)."\n";
292 304
 			$db->rollback();
293 305
 		}
294 306
 		print "\n";
295
-	}
296
-	else
307
+	} else
297 308
 	{
298 309
 		dol_print_error('',$ldap->error);
299 310
 		$error++;
300 311
 	}
301
-}
302
-else
312
+} else
303 313
 {
304 314
 	dol_print_error('',$ldap->error);
305 315
 	$error++;
Please login to merge, or discard this patch.