Test Failed
Push — master ( 2740c1...0ba343 )
by Alxarafe
43:23 queued 04:12
created
dolibarr/dev/initdata/import-products.php 3 patches
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -81,8 +81,8 @@  discard block
 block discarded – undo
81 81
 $ret=$user->fetch('','admin');
82 82
 if (! $ret > 0)
83 83
 {
84
-	print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
85
-	exit;
84
+    print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
85
+    exit;
86 86
 }
87 87
 $user->getrights();
88 88
 
@@ -164,56 +164,56 @@  discard block
 block discarded – undo
164 164
         print " - Error in create result code = ".$ret." - ".$produit->errorsToString();
165 165
         $errorrecord++;
166 166
     }
167
-	else
168
-	{
169
-	    print " - Creation OK with ref ".$produit->ref." - id = ".$ret;
170
-	}
167
+    else
168
+    {
169
+        print " - Creation OK with ref ".$produit->ref." - id = ".$ret;
170
+    }
171 171
 
172
-	dol_syslog("Add prices");
172
+    dol_syslog("Add prices");
173 173
 
174 174
     // If we use price level, insert price for each level
175
-	if (! $errorrecord && 1)
176
-	{
177
-	    $ret1=$produit->updatePrice($produit->price_ttc, $produit->price_base_type, $user, $produit->tva_tx, $produit->price_min, 1, $produit->tva_npr, 0, 0, array());
178
-	    $ret2=$produit->updatePrice(price2num($fields[14]), 'HT', $user, $produit->tva_tx, $produit->price_min, 2, $produit->tva_npr, 0, 0, array());
179
-	    if ($ret1 < 0 || $ret2 < 0)
175
+    if (! $errorrecord && 1)
176
+    {
177
+        $ret1=$produit->updatePrice($produit->price_ttc, $produit->price_base_type, $user, $produit->tva_tx, $produit->price_min, 1, $produit->tva_npr, 0, 0, array());
178
+        $ret2=$produit->updatePrice(price2num($fields[14]), 'HT', $user, $produit->tva_tx, $produit->price_min, 2, $produit->tva_npr, 0, 0, array());
179
+        if ($ret1 < 0 || $ret2 < 0)
180 180
         {
181 181
             print " - Error in updatePrice result code = ".$ret1." ".$ret2." - ".$produit->errorsToString();
182 182
             $errorrecord++;
183 183
         }
184
-    	else
185
-    	{
186
-    	    print " - updatePrice OK";
187
-    	}
188
-	}
184
+        else
185
+        {
186
+            print " - updatePrice OK";
187
+        }
188
+    }
189 189
 
190
-	dol_syslog("Add multilangs");
190
+    dol_syslog("Add multilangs");
191 191
 
192
-	// Add alternative languages
193
-	if (! $errorrecord && 1)
194
-	{
195
-    	$produit->multilangs['fr_FR']=array('label'=>$produit->label, 'description'=>$produit->description, 'note'=>$produit->note_private);
196
-	    $produit->multilangs['en_US']=array('label'=>$fields[3], 'description'=>$produit->description, 'note'=>$produit->note_private);
192
+    // Add alternative languages
193
+    if (! $errorrecord && 1)
194
+    {
195
+        $produit->multilangs['fr_FR']=array('label'=>$produit->label, 'description'=>$produit->description, 'note'=>$produit->note_private);
196
+        $produit->multilangs['en_US']=array('label'=>$fields[3], 'description'=>$produit->description, 'note'=>$produit->note_private);
197 197
 
198
-    	$ret=$produit->setMultiLangs($user);
198
+        $ret=$produit->setMultiLangs($user);
199 199
         if ($ret < 0)
200 200
         {
201 201
             print " - Error in setMultiLangs result code = ".$ret." - ".$produit->errorsToString();
202 202
             $errorrecord++;
203 203
         }
204
-    	else
205
-    	{
206
-    	    print " - setMultiLangs OK";
207
-    	}
208
-	}
209
-
210
-	print "\n";
211
-
212
-	if ($errorrecord)
213
-	{
214
-	    fwrite($fhandleerr, 'Error on record nb '.$i." - ".$produit->errorsToString()."\n");
215
-	    $error++;    // $errorrecord will be reset
216
-	}
204
+        else
205
+        {
206
+            print " - setMultiLangs OK";
207
+        }
208
+    }
209
+
210
+    print "\n";
211
+
212
+    if ($errorrecord)
213
+    {
214
+        fwrite($fhandleerr, 'Error on record nb '.$i." - ".$produit->errorsToString()."\n");
215
+        $error++;    // $errorrecord will be reset
216
+    }
217 217
 }
218 218
 
219 219
 
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -28,27 +28,27 @@  discard block
 block discarded – undo
28 28
 // Test si mode batch
29 29
 $sapi_type = php_sapi_name();
30 30
 $script_file = basename(__FILE__);
31
-$path=dirname(__FILE__).'/';
31
+$path = dirname(__FILE__).'/';
32 32
 if (substr($sapi_type, 0, 3) == 'cgi') {
33 33
     echo "Erreur: Vous utilisez l'interpreteur PHP pour le mode CGI. Pour executer mailing-send.php en ligne de commande, vous devez utiliser l'interpreteur PHP pour le mode CLI.\n";
34 34
     exit;
35 35
 }
36 36
 
37 37
 // Recupere root dolibarr
38
-$path=preg_replace('/import-products.php/i','',$_SERVER["PHP_SELF"]);
38
+$path = preg_replace('/import-products.php/i', '', $_SERVER["PHP_SELF"]);
39 39
 require $path."../../htdocs/master.inc.php";
40 40
 include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
41 41
 include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
42 42
 
43
-$delimiter=',';
44
-$enclosure='"';
45
-$linelength=10000;
46
-$escape='/';
43
+$delimiter = ',';
44
+$enclosure = '"';
45
+$linelength = 10000;
46
+$escape = '/';
47 47
 
48 48
 // Global variables
49
-$version=DOL_VERSION;
50
-$confirmed=1;
51
-$error=0;
49
+$version = DOL_VERSION;
50
+$confirmed = 1;
51
+$error = 0;
52 52
 
53 53
 
54 54
 /*
@@ -57,29 +57,29 @@  discard block
 block discarded – undo
57 57
 
58 58
 @set_time_limit(0);
59 59
 print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
60
-dol_syslog($script_file." launched with arg ".implode(',',$argv));
60
+dol_syslog($script_file." launched with arg ".implode(',', $argv));
61 61
 
62 62
 $mode = $argv[1];
63 63
 $filepath = $argv[2];
64 64
 $filepatherr = $filepath.'.err';
65
-$defaultlang = empty($argv[3])?'en_US':$argv[3];
66
-$startlinenb = empty($argv[4])?1:$argv[4];
67
-$endlinenb = empty($argv[5])?0:$argv[5];
65
+$defaultlang = empty($argv[3]) ? 'en_US' : $argv[3];
66
+$startlinenb = empty($argv[4]) ? 1 : $argv[4];
67
+$endlinenb = empty($argv[5]) ? 0 : $argv[5];
68 68
 
69
-if (empty($mode) || ! in_array($mode,array('test','confirm','confirmforced')) || empty($filepath)) {
69
+if (empty($mode) || !in_array($mode, array('test', 'confirm', 'confirmforced')) || empty($filepath)) {
70 70
     print "Usage:  $script_file (test|confirm|confirmforced) filepath.csv [defaultlang] [startlinenb] [endlinenb]\n";
71 71
     print "Usage:  $script_file test myfilepath.csv fr_FR 2 1002\n";
72 72
     print "\n";
73 73
     exit(-1);
74 74
 }
75
-if (! file_exists($filepath)) {
75
+if (!file_exists($filepath)) {
76 76
     print "Error: File ".$filepath." not found.\n";
77 77
     print "\n";
78 78
     exit(-1);
79 79
 }
80 80
 
81
-$ret=$user->fetch('','admin');
82
-if (! $ret > 0)
81
+$ret = $user->fetch('', 'admin');
82
+if (!$ret > 0)
83 83
 {
84 84
 	print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
85 85
 	exit;
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 $user->getrights();
88 88
 
89 89
 // Ask confirmation
90
-if (! $confirmed)
90
+if (!$confirmed)
91 91
 {
92 92
     print "Hit Enter to continue or CTRL+C to stop...\n";
93 93
     $input = trim(fgets(STDIN));
@@ -95,13 +95,13 @@  discard block
 block discarded – undo
95 95
 
96 96
 // Open input and ouput files
97 97
 $fhandle = fopen($filepath, 'r');
98
-if (! $fhandle)
98
+if (!$fhandle)
99 99
 {
100 100
     print 'Error: Failed to open file '.$filepath."\n";
101 101
     exit(1);
102 102
 }
103 103
 $fhandleerr = fopen($filepatherr, 'w');
104
-if (! $fhandleerr)
104
+if (!$fhandleerr)
105 105
 {
106 106
     print 'Error: Failed to open file '.$filepatherr."\n";
107 107
     exit(1);
@@ -112,12 +112,12 @@  discard block
 block discarded – undo
112 112
 
113 113
 $db->begin();
114 114
 
115
-$i=0;
115
+$i = 0;
116 116
 $nboflines++;
117
-while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape))
117
+while ($fields = fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape))
118 118
 {
119 119
     $i++;
120
-    $errorrecord=0;
120
+    $errorrecord = 0;
121 121
 
122 122
     if ($startlinenb && $i < $startlinenb) continue;
123 123
     if ($endlinenb && $i > $endlinenb) continue;
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
     $produit->volume = price2num($fields[8]);
136 136
     $produit->volume_unit = 0;
137 137
     $produit->weight = price2num($fields[9]);
138
-    $produit->weight_units = 0;          // -3 = g
138
+    $produit->weight_units = 0; // -3 = g
139 139
 
140 140
     $produit->customcode = $fields[10];
141 141
     $produit->barcode = $fields[1];
@@ -156,9 +156,9 @@  discard block
 block discarded – undo
156 156
     $produit->cost_price = price2num($fields[16]);
157 157
 
158 158
     // Extrafields
159
-    $produit->array_options['options_ecotaxdeee']=price2num($fields[17]);
159
+    $produit->array_options['options_ecotaxdeee'] = price2num($fields[17]);
160 160
 
161
-    $ret=$produit->create($user);
161
+    $ret = $produit->create($user);
162 162
     if ($ret < 0)
163 163
     {
164 164
         print " - Error in create result code = ".$ret." - ".$produit->errorsToString();
@@ -172,10 +172,10 @@  discard block
 block discarded – undo
172 172
 	dol_syslog("Add prices");
173 173
 
174 174
     // If we use price level, insert price for each level
175
-	if (! $errorrecord && 1)
175
+	if (!$errorrecord && 1)
176 176
 	{
177
-	    $ret1=$produit->updatePrice($produit->price_ttc, $produit->price_base_type, $user, $produit->tva_tx, $produit->price_min, 1, $produit->tva_npr, 0, 0, array());
178
-	    $ret2=$produit->updatePrice(price2num($fields[14]), 'HT', $user, $produit->tva_tx, $produit->price_min, 2, $produit->tva_npr, 0, 0, array());
177
+	    $ret1 = $produit->updatePrice($produit->price_ttc, $produit->price_base_type, $user, $produit->tva_tx, $produit->price_min, 1, $produit->tva_npr, 0, 0, array());
178
+	    $ret2 = $produit->updatePrice(price2num($fields[14]), 'HT', $user, $produit->tva_tx, $produit->price_min, 2, $produit->tva_npr, 0, 0, array());
179 179
 	    if ($ret1 < 0 || $ret2 < 0)
180 180
         {
181 181
             print " - Error in updatePrice result code = ".$ret1." ".$ret2." - ".$produit->errorsToString();
@@ -190,12 +190,12 @@  discard block
 block discarded – undo
190 190
 	dol_syslog("Add multilangs");
191 191
 
192 192
 	// Add alternative languages
193
-	if (! $errorrecord && 1)
193
+	if (!$errorrecord && 1)
194 194
 	{
195
-    	$produit->multilangs['fr_FR']=array('label'=>$produit->label, 'description'=>$produit->description, 'note'=>$produit->note_private);
196
-	    $produit->multilangs['en_US']=array('label'=>$fields[3], 'description'=>$produit->description, 'note'=>$produit->note_private);
195
+    	$produit->multilangs['fr_FR'] = array('label'=>$produit->label, 'description'=>$produit->description, 'note'=>$produit->note_private);
196
+	    $produit->multilangs['en_US'] = array('label'=>$fields[3], 'description'=>$produit->description, 'note'=>$produit->note_private);
197 197
 
198
-    	$ret=$produit->setMultiLangs($user);
198
+    	$ret = $produit->setMultiLangs($user);
199 199
         if ($ret < 0)
200 200
         {
201 201
             print " - Error in setMultiLangs result code = ".$ret." - ".$produit->errorsToString();
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
 	if ($errorrecord)
213 213
 	{
214 214
 	    fwrite($fhandleerr, 'Error on record nb '.$i." - ".$produit->errorsToString()."\n");
215
-	    $error++;    // $errorrecord will be reset
215
+	    $error++; // $errorrecord will be reset
216 216
 	}
217 217
 }
218 218
 
Please login to merge, or discard this patch.
Braces   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -119,8 +119,12 @@  discard block
 block discarded – undo
119 119
     $i++;
120 120
     $errorrecord=0;
121 121
 
122
-    if ($startlinenb && $i < $startlinenb) continue;
123
-    if ($endlinenb && $i > $endlinenb) continue;
122
+    if ($startlinenb && $i < $startlinenb) {
123
+        continue;
124
+    }
125
+    if ($endlinenb && $i > $endlinenb) {
126
+        continue;
127
+    }
124 128
 
125 129
     $nboflines++;
126 130
 
@@ -163,8 +167,7 @@  discard block
 block discarded – undo
163 167
     {
164 168
         print " - Error in create result code = ".$ret." - ".$produit->errorsToString();
165 169
         $errorrecord++;
166
-    }
167
-	else
170
+    } else
168 171
 	{
169 172
 	    print " - Creation OK with ref ".$produit->ref." - id = ".$ret;
170 173
 	}
@@ -180,8 +183,7 @@  discard block
 block discarded – undo
180 183
         {
181 184
             print " - Error in updatePrice result code = ".$ret1." ".$ret2." - ".$produit->errorsToString();
182 185
             $errorrecord++;
183
-        }
184
-    	else
186
+        } else
185 187
     	{
186 188
     	    print " - updatePrice OK";
187 189
     	}
@@ -200,8 +202,7 @@  discard block
 block discarded – undo
200 202
         {
201 203
             print " - Error in setMultiLangs result code = ".$ret." - ".$produit->errorsToString();
202 204
             $errorrecord++;
203
-        }
204
-    	else
205
+        } else
205 206
     	{
206 207
     	    print " - setMultiLangs OK";
207 208
     	}
@@ -227,8 +228,7 @@  discard block
 block discarded – undo
227 228
 {
228 229
     print "Rollback any changes.\n";
229 230
     $db->rollback();
230
-}
231
-else
231
+} else
232 232
 {
233 233
     print "Commit all changes.\n";
234 234
     $db->commit();
Please login to merge, or discard this patch.
dolibarr/dev/initdata/generate-product.php 3 patches
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -52,8 +52,8 @@  discard block
 block discarded – undo
52 52
 $ret=$user->fetch('','admin');
53 53
 if (! $ret > 0)
54 54
 {
55
-	print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
56
-	exit;
55
+    print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
56
+    exit;
57 57
 }
58 58
 $user->getrights();
59 59
 
@@ -61,21 +61,21 @@  discard block
 block discarded – undo
61 61
 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product"; $productsid = array();
62 62
 $resql=$db->query($sql);
63 63
 if ($resql) {
64
-  $num = $db->num_rows($resql); $i = 0;
65
-  while ($i < $num) {      $row = $db->fetch_row($resql);      $productsid[$i] = $row[0];      $i++; }
64
+    $num = $db->num_rows($resql); $i = 0;
65
+    while ($i < $num) {      $row = $db->fetch_row($resql);      $productsid[$i] = $row[0];      $i++; }
66 66
 }
67 67
 
68 68
 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe"; $societesid = array();
69 69
 $resql=$db->query($sql);
70 70
 if ($resql) {
71
-	$num = $db->num_rows($resql); $i = 0;
71
+    $num = $db->num_rows($resql); $i = 0;
72 72
     while ($i < $num) { $row = $db->fetch_row($resql);      $societesid[$i] = $row[0];      $i++; }
73 73
 } else { print "err"; }
74 74
 
75 75
 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."commande"; $commandesid = array();
76 76
 $resql=$db->query($sql);
77 77
 if ($resql) {
78
-	$num = $db->num_rows($resql); $i = 0;
78
+    $num = $db->num_rows($resql); $i = 0;
79 79
     while ($i < $num) { $row = $db->fetch_row($resql);      $commandesid[$i] = $row[0];      $i++; }
80 80
 } else { print "err"; }
81 81
 
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
     $produit->tva_tx = "19.6";
95 95
     $ret=$produit->create($user);
96 96
     if ($ret < 0) print "Error $ret - ".$produit->error."\n";
97
-	else print " OK with ref ".$produit->ref."\n";
97
+    else print " OK with ref ".$produit->ref."\n";
98 98
 }
99 99
 
100 100
 
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 
34 34
 // Recupere root dolibarr
35 35
 //$path=preg_replace('/generate-produit.php/i','',$_SERVER["PHP_SELF"]);
36
-require __DIR__. '/../../htdocs/master.inc.php';
36
+require __DIR__.'/../../htdocs/master.inc.php';
37 37
 include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
38 38
 include_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
39 39
 include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
@@ -49,8 +49,8 @@  discard block
 block discarded – undo
49 49
 define(GEN_NUMBER_PRODUIT, 100000);
50 50
 
51 51
 
52
-$ret=$user->fetch('','admin');
53
-if (! $ret > 0)
52
+$ret = $user->fetch('', 'admin');
53
+if (!$ret > 0)
54 54
 {
55 55
 	print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
56 56
 	exit;
@@ -59,40 +59,40 @@  discard block
 block discarded – undo
59 59
 
60 60
 
61 61
 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product"; $productsid = array();
62
-$resql=$db->query($sql);
62
+$resql = $db->query($sql);
63 63
 if ($resql) {
64 64
   $num = $db->num_rows($resql); $i = 0;
65
-  while ($i < $num) {      $row = $db->fetch_row($resql);      $productsid[$i] = $row[0];      $i++; }
65
+  while ($i < $num) {      $row = $db->fetch_row($resql); $productsid[$i] = $row[0]; $i++; }
66 66
 }
67 67
 
68 68
 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe"; $societesid = array();
69
-$resql=$db->query($sql);
69
+$resql = $db->query($sql);
70 70
 if ($resql) {
71 71
 	$num = $db->num_rows($resql); $i = 0;
72
-    while ($i < $num) { $row = $db->fetch_row($resql);      $societesid[$i] = $row[0];      $i++; }
72
+    while ($i < $num) { $row = $db->fetch_row($resql); $societesid[$i] = $row[0]; $i++; }
73 73
 } else { print "err"; }
74 74
 
75 75
 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."commande"; $commandesid = array();
76
-$resql=$db->query($sql);
76
+$resql = $db->query($sql);
77 77
 if ($resql) {
78 78
 	$num = $db->num_rows($resql); $i = 0;
79
-    while ($i < $num) { $row = $db->fetch_row($resql);      $commandesid[$i] = $row[0];      $i++; }
79
+    while ($i < $num) { $row = $db->fetch_row($resql); $commandesid[$i] = $row[0]; $i++; }
80 80
 } else { print "err"; }
81 81
 
82 82
 
83 83
 print "Generates ".GEN_NUMBER_PRODUIT." products\n";
84
-for ($s = 0 ; $s < GEN_NUMBER_PRODUIT ; $s++)
84
+for ($s = 0; $s < GEN_NUMBER_PRODUIT; $s++)
85 85
 {
86 86
     print "Product ".$s;
87 87
     $produit = new Product($db);
88
-    $produit->type = mt_rand(0,1);
88
+    $produit->type = mt_rand(0, 1);
89 89
     $produit->status = 1;
90
-    $produit->ref = ($produit->type?'S':'P').time().$s;
90
+    $produit->ref = ($produit->type ? 'S' : 'P').time().$s;
91 91
     $produit->label = 'Label '.time().$s;
92 92
     $produit->description = 'Description '.time().$s;
93
-    $produit->price = mt_rand(1,1000);
93
+    $produit->price = mt_rand(1, 1000);
94 94
     $produit->tva_tx = "19.6";
95
-    $ret=$produit->create($user);
95
+    $ret = $produit->create($user);
96 96
     if ($ret < 0) print "Error $ret - ".$produit->error."\n";
97 97
 	else print " OK with ref ".$produit->ref."\n";
98 98
 }
Please login to merge, or discard this patch.
Braces   +6 added lines, -3 removed lines patch added patch discarded remove patch
@@ -93,8 +93,11 @@
 block discarded – undo
93 93
     $produit->price = mt_rand(1,1000);
94 94
     $produit->tva_tx = "19.6";
95 95
     $ret=$produit->create($user);
96
-    if ($ret < 0) print "Error $ret - ".$produit->error."\n";
97
-	else print " OK with ref ".$produit->ref."\n";
98
-}
96
+    if ($ret < 0) {
97
+        print "Error $ret - ".$produit->error."\n";
98
+    } else {
99
+	    print " OK with ref ".$produit->ref."\n";
100
+	}
101
+	}
99 102
 
100 103
 
Please login to merge, or discard this patch.
dolibarr/dev/initdata/generate-proposal.php 3 patches
Indentation   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -27,8 +27,8 @@  discard block
 block discarded – undo
27 27
 // Test si mode batch
28 28
 $sapi_type = php_sapi_name();
29 29
 if (substr($sapi_type, 0, 3) == 'cgi') {
30
-	echo "Erreur: Vous utilisez l'interpreteur PHP pour le mode CGI. Pour executer mailing-send.php en ligne de commande, vous devez utiliser l'interpreteur PHP pour le mode CLI.\n";
31
-	exit;
30
+    echo "Erreur: Vous utilisez l'interpreteur PHP pour le mode CGI. Pour executer mailing-send.php en ligne de commande, vous devez utiliser l'interpreteur PHP pour le mode CLI.\n";
31
+    exit;
32 32
 }
33 33
 
34 34
 // Recupere root dolibarr
@@ -100,8 +100,8 @@  discard block
 block discarded – undo
100 100
 $ret=$user->fetch('','admin');
101 101
 if (! $ret > 0)
102 102
 {
103
-	print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
104
-	exit;
103
+    print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
104
+    exit;
105 105
 }
106 106
 $user->getrights();
107 107
 
@@ -111,14 +111,14 @@  discard block
 block discarded – undo
111 111
 $resql = $db->query($sql);
112 112
 if ($resql)
113 113
 {
114
-	$num_thirdparties = $db->num_rows($resql);
115
-	$i = 0;
116
-	while ($i < $num_thirdparties)
117
-	{
118
-		$i++;
119
-		$row = $db->fetch_row($resql);
120
-		$socids[$i] = $row[0];
121
-	}
114
+    $num_thirdparties = $db->num_rows($resql);
115
+    $i = 0;
116
+    while ($i < $num_thirdparties)
117
+    {
118
+        $i++;
119
+        $row = $db->fetch_row($resql);
120
+        $socids[$i] = $row[0];
121
+    }
122 122
 }
123 123
 
124 124
 $contids = array();
@@ -126,14 +126,14 @@  discard block
 block discarded – undo
126 126
 $resql = $db->query($sql);
127 127
 if ($resql)
128 128
 {
129
-	$num_conts = $db->num_rows($resql);
130
-	$i = 0;
131
-	while ($i < $num_conts)
132
-	{
133
-		$i++;
134
-		$row = $db->fetch_row($resql);
135
-		$contids[$row[1]][0] = $row[0]; // A ameliorer
136
-	}
129
+    $num_conts = $db->num_rows($resql);
130
+    $i = 0;
131
+    while ($i < $num_conts)
132
+    {
133
+        $i++;
134
+        $row = $db->fetch_row($resql);
135
+        $contids[$row[1]][0] = $row[0]; // A ameliorer
136
+    }
137 137
 }
138 138
 
139 139
 $prodids = array();
@@ -141,14 +141,14 @@  discard block
 block discarded – undo
141 141
 $resql = $db->query($sql);
142 142
 if ($resql)
143 143
 {
144
-	$num_prods = $db->num_rows($resql);
145
-	$i = 0;
146
-	while ($i < $num_prods)
147
-	{
148
-		$i++;
149
-		$row = $db->fetch_row($resql);
150
-		$prodids[$i] = $row[0];
151
-	}
144
+    $num_prods = $db->num_rows($resql);
145
+    $i = 0;
146
+    while ($i < $num_prods)
147
+    {
148
+        $i++;
149
+        $row = $db->fetch_row($resql);
150
+        $prodids[$i] = $row[0];
151
+    }
152 152
 }
153 153
 
154 154
 $user->rights->propal->creer=1;
@@ -157,65 +157,65 @@  discard block
 block discarded – undo
157 157
 
158 158
 if (! empty($conf->global->PROPALE_ADDON) && is_readable(DOL_DOCUMENT_ROOT ."/core/modules/propale/".$conf->global->PROPALE_ADDON.".php"))
159 159
 {
160
-	require_once DOL_DOCUMENT_ROOT ."/core/modules/propale/".$conf->global->PROPALE_ADDON.".php";
160
+    require_once DOL_DOCUMENT_ROOT ."/core/modules/propale/".$conf->global->PROPALE_ADDON.".php";
161 161
 }
162 162
 
163 163
 $i=0;
164 164
 $result=0;
165 165
 while ($i < GEN_NUMBER_PROPAL && $result >= 0)
166 166
 {
167
-	$i++;
168
-	$socid = mt_rand(1, $num_thirdparties);
169
-	print "Proposal ".$i." for socid ".$socid;
167
+    $i++;
168
+    $socid = mt_rand(1, $num_thirdparties);
169
+    print "Proposal ".$i." for socid ".$socid;
170 170
 
171
-	$soc = new Societe($db);
171
+    $soc = new Societe($db);
172 172
 
173 173
 
174
-	$object = new Propal($db);
174
+    $object = new Propal($db);
175 175
 
176 176
     $fuser = new User($db);
177 177
     $fuser->fetch(mt_rand(1,2));
178 178
     $fuser->getRights();
179 179
     
180
-	$object->contactid = $contids[$socids[$socid]][0];
181
-	$object->socid = $socids[$socid];
182
-	$object->datep = $dates[mt_rand(1, count($dates)-1)];
183
-	$object->cond_reglement_id = 3;
184
-	$object->mode_reglement_id = 3;
185
-
186
-	$result=$object->create($fuser);
187
-	if ($result >= 0)
188
-	{
189
-		$nbp = mt_rand(2, 5);
190
-		$xnbp = 0;
191
-		while ($xnbp < $nbp)
192
-		{
193
-			$prodid = mt_rand(1, $num_prods);
194
-			$product=new Product($db);
195
-			$result=$product->fetch($prodids[$prodid]);
196
-			$result=$object->addline($product->description, $product->price, mt_rand(1,5), 0, 0, 0, $prodids[$prodid], 0);
197
-			if ($result < 0)
198
-			{
199
-				dol_print_error($db,$object->error);
200
-			}
201
-			$xnbp++;
202
-		}
180
+    $object->contactid = $contids[$socids[$socid]][0];
181
+    $object->socid = $socids[$socid];
182
+    $object->datep = $dates[mt_rand(1, count($dates)-1)];
183
+    $object->cond_reglement_id = 3;
184
+    $object->mode_reglement_id = 3;
185
+
186
+    $result=$object->create($fuser);
187
+    if ($result >= 0)
188
+    {
189
+        $nbp = mt_rand(2, 5);
190
+        $xnbp = 0;
191
+        while ($xnbp < $nbp)
192
+        {
193
+            $prodid = mt_rand(1, $num_prods);
194
+            $product=new Product($db);
195
+            $result=$product->fetch($prodids[$prodid]);
196
+            $result=$object->addline($product->description, $product->price, mt_rand(1,5), 0, 0, 0, $prodids[$prodid], 0);
197
+            if ($result < 0)
198
+            {
199
+                dol_print_error($db,$object->error);
200
+            }
201
+            $xnbp++;
202
+        }
203 203
 		
204
-		$result=$object->valid($fuser);
205
-		if ($result > 0)
206
-		{
207
-		    $db->commit();
208
-		    print " OK with ref ".$object->ref."\n";
209
-		}
210
-		else
211
-		{
212
-		    print " KO\n";
213
-		    $db->rollback();
214
-		    dol_print_error($db,$object->error);
215
-		}
216
-	}
217
-	else
218
-	{
219
-		dol_print_error($db,$object->error);
220
-	}
204
+        $result=$object->valid($fuser);
205
+        if ($result > 0)
206
+        {
207
+            $db->commit();
208
+            print " OK with ref ".$object->ref."\n";
209
+        }
210
+        else
211
+        {
212
+            print " KO\n";
213
+            $db->rollback();
214
+            dol_print_error($db,$object->error);
215
+        }
216
+    }
217
+    else
218
+    {
219
+        dol_print_error($db,$object->error);
220
+    }
221 221
 }
Please login to merge, or discard this patch.
Spacing   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 
34 34
 // Recupere root dolibarr
35 35
 //$path=preg_replace('/generate-propale.php/i','',$_SERVER["PHP_SELF"]);
36
-require __DIR__. '/../../htdocs/master.inc.php';
36
+require __DIR__.'/../../htdocs/master.inc.php';
37 37
 require_once DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php";
38 38
 require_once DOL_DOCUMENT_ROOT."/comm/propal/class/propal.class.php";
39 39
 require_once DOL_DOCUMENT_ROOT."/commande/class/commande.class.php";
@@ -45,60 +45,60 @@  discard block
 block discarded – undo
45 45
 
46 46
 define(GEN_NUMBER_PROPAL, 10);
47 47
 $year = 2016;
48
-$dates = array (mktime(12,0,0,1,3,$year),
49
-    mktime(12,0,0,1,9,$year),
50
-    mktime(12,0,0,2,13,$year),
51
-    mktime(12,0,0,2,23,$year),
52
-    mktime(12,0,0,3,30,$year),
53
-    mktime(12,0,0,4,3,$year),
54
-    mktime(12,0,0,4,3,$year),
55
-    mktime(12,0,0,5,9,$year),
56
-    mktime(12,0,0,5,1,$year),
57
-    mktime(12,0,0,5,13,$year),
58
-    mktime(12,0,0,5,19,$year),
59
-    mktime(12,0,0,5,23,$year),
60
-    mktime(12,0,0,6,3,$year),
61
-    mktime(12,0,0,6,19,$year),
62
-    mktime(12,0,0,6,24,$year),
63
-    mktime(12,0,0,7,3,$year),
64
-    mktime(12,0,0,7,9,$year),
65
-    mktime(12,0,0,7,23,$year),
66
-    mktime(12,0,0,7,30,$year),
67
-    mktime(12,0,0,8,9,$year),
68
-    mktime(12,0,0,9,23,$year),
69
-    mktime(12,0,0,10,3,$year),
70
-    mktime(12,0,0,11,12,$year),
71
-    mktime(12,0,0,11,13,$year),
72
-    mktime(12,0,0,1,3,($year - 1)),
73
-    mktime(12,0,0,1,9,($year - 1)),
74
-    mktime(12,0,0,2,13,($year - 1)),
75
-    mktime(12,0,0,2,23,($year - 1)),
76
-    mktime(12,0,0,3,30,($year - 1)),
77
-    mktime(12,0,0,4,3,($year - 1)),
78
-    mktime(12,0,0,4,3,($year - 1)),
79
-    mktime(12,0,0,5,9,($year - 1)),
80
-    mktime(12,0,0,5,1,($year - 1)),
81
-    mktime(12,0,0,5,13,($year - 1)),
82
-    mktime(12,0,0,5,19,($year - 1)),
83
-    mktime(12,0,0,5,23,($year - 1)),
84
-    mktime(12,0,0,6,3,($year - 1)),
85
-    mktime(12,0,0,6,19,($year - 1)),
86
-    mktime(12,0,0,6,24,($year - 1)),
87
-    mktime(12,0,0,7,3,($year - 1)),
88
-    mktime(12,0,0,7,9,($year - 1)),
89
-    mktime(12,0,0,7,23,($year - 1)),
90
-    mktime(12,0,0,7,30,($year - 1)),
91
-    mktime(12,0,0,8,9,($year - 1)),
92
-    mktime(12,0,0,9,23,($year - 1)),
93
-    mktime(12,0,0,10,3,($year - 1)),
94
-    mktime(12,0,0,11,12,$year),
95
-    mktime(12,0,0,11,13,$year),
96
-    mktime(12,0,0,12,12,$year),
97
-    mktime(12,0,0,12,13,$year),
48
+$dates = array(mktime(12, 0, 0, 1, 3, $year),
49
+    mktime(12, 0, 0, 1, 9, $year),
50
+    mktime(12, 0, 0, 2, 13, $year),
51
+    mktime(12, 0, 0, 2, 23, $year),
52
+    mktime(12, 0, 0, 3, 30, $year),
53
+    mktime(12, 0, 0, 4, 3, $year),
54
+    mktime(12, 0, 0, 4, 3, $year),
55
+    mktime(12, 0, 0, 5, 9, $year),
56
+    mktime(12, 0, 0, 5, 1, $year),
57
+    mktime(12, 0, 0, 5, 13, $year),
58
+    mktime(12, 0, 0, 5, 19, $year),
59
+    mktime(12, 0, 0, 5, 23, $year),
60
+    mktime(12, 0, 0, 6, 3, $year),
61
+    mktime(12, 0, 0, 6, 19, $year),
62
+    mktime(12, 0, 0, 6, 24, $year),
63
+    mktime(12, 0, 0, 7, 3, $year),
64
+    mktime(12, 0, 0, 7, 9, $year),
65
+    mktime(12, 0, 0, 7, 23, $year),
66
+    mktime(12, 0, 0, 7, 30, $year),
67
+    mktime(12, 0, 0, 8, 9, $year),
68
+    mktime(12, 0, 0, 9, 23, $year),
69
+    mktime(12, 0, 0, 10, 3, $year),
70
+    mktime(12, 0, 0, 11, 12, $year),
71
+    mktime(12, 0, 0, 11, 13, $year),
72
+    mktime(12, 0, 0, 1, 3, ($year - 1)),
73
+    mktime(12, 0, 0, 1, 9, ($year - 1)),
74
+    mktime(12, 0, 0, 2, 13, ($year - 1)),
75
+    mktime(12, 0, 0, 2, 23, ($year - 1)),
76
+    mktime(12, 0, 0, 3, 30, ($year - 1)),
77
+    mktime(12, 0, 0, 4, 3, ($year - 1)),
78
+    mktime(12, 0, 0, 4, 3, ($year - 1)),
79
+    mktime(12, 0, 0, 5, 9, ($year - 1)),
80
+    mktime(12, 0, 0, 5, 1, ($year - 1)),
81
+    mktime(12, 0, 0, 5, 13, ($year - 1)),
82
+    mktime(12, 0, 0, 5, 19, ($year - 1)),
83
+    mktime(12, 0, 0, 5, 23, ($year - 1)),
84
+    mktime(12, 0, 0, 6, 3, ($year - 1)),
85
+    mktime(12, 0, 0, 6, 19, ($year - 1)),
86
+    mktime(12, 0, 0, 6, 24, ($year - 1)),
87
+    mktime(12, 0, 0, 7, 3, ($year - 1)),
88
+    mktime(12, 0, 0, 7, 9, ($year - 1)),
89
+    mktime(12, 0, 0, 7, 23, ($year - 1)),
90
+    mktime(12, 0, 0, 7, 30, ($year - 1)),
91
+    mktime(12, 0, 0, 8, 9, ($year - 1)),
92
+    mktime(12, 0, 0, 9, 23, ($year - 1)),
93
+    mktime(12, 0, 0, 10, 3, ($year - 1)),
94
+    mktime(12, 0, 0, 11, 12, $year),
95
+    mktime(12, 0, 0, 11, 13, $year),
96
+    mktime(12, 0, 0, 12, 12, $year),
97
+    mktime(12, 0, 0, 12, 13, $year),
98 98
 );
99 99
 
100
-$ret=$user->fetch('','admin');
101
-if (! $ret > 0)
100
+$ret = $user->fetch('', 'admin');
101
+if (!$ret > 0)
102 102
 {
103 103
 	print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
104 104
 	exit;
@@ -151,17 +151,17 @@  discard block
 block discarded – undo
151 151
 	}
152 152
 }
153 153
 
154
-$user->rights->propal->creer=1;
155
-$user->rights->propal->propal_advance->validate=1;
154
+$user->rights->propal->creer = 1;
155
+$user->rights->propal->propal_advance->validate = 1;
156 156
 
157 157
 
158
-if (! empty($conf->global->PROPALE_ADDON) && is_readable(DOL_DOCUMENT_ROOT ."/core/modules/propale/".$conf->global->PROPALE_ADDON.".php"))
158
+if (!empty($conf->global->PROPALE_ADDON) && is_readable(DOL_DOCUMENT_ROOT."/core/modules/propale/".$conf->global->PROPALE_ADDON.".php"))
159 159
 {
160
-	require_once DOL_DOCUMENT_ROOT ."/core/modules/propale/".$conf->global->PROPALE_ADDON.".php";
160
+	require_once DOL_DOCUMENT_ROOT."/core/modules/propale/".$conf->global->PROPALE_ADDON.".php";
161 161
 }
162 162
 
163
-$i=0;
164
-$result=0;
163
+$i = 0;
164
+$result = 0;
165 165
 while ($i < GEN_NUMBER_PROPAL && $result >= 0)
166 166
 {
167 167
 	$i++;
@@ -174,16 +174,16 @@  discard block
 block discarded – undo
174 174
 	$object = new Propal($db);
175 175
 
176 176
     $fuser = new User($db);
177
-    $fuser->fetch(mt_rand(1,2));
177
+    $fuser->fetch(mt_rand(1, 2));
178 178
     $fuser->getRights();
179 179
     
180 180
 	$object->contactid = $contids[$socids[$socid]][0];
181 181
 	$object->socid = $socids[$socid];
182
-	$object->datep = $dates[mt_rand(1, count($dates)-1)];
182
+	$object->datep = $dates[mt_rand(1, count($dates) - 1)];
183 183
 	$object->cond_reglement_id = 3;
184 184
 	$object->mode_reglement_id = 3;
185 185
 
186
-	$result=$object->create($fuser);
186
+	$result = $object->create($fuser);
187 187
 	if ($result >= 0)
188 188
 	{
189 189
 		$nbp = mt_rand(2, 5);
@@ -191,17 +191,17 @@  discard block
 block discarded – undo
191 191
 		while ($xnbp < $nbp)
192 192
 		{
193 193
 			$prodid = mt_rand(1, $num_prods);
194
-			$product=new Product($db);
195
-			$result=$product->fetch($prodids[$prodid]);
196
-			$result=$object->addline($product->description, $product->price, mt_rand(1,5), 0, 0, 0, $prodids[$prodid], 0);
194
+			$product = new Product($db);
195
+			$result = $product->fetch($prodids[$prodid]);
196
+			$result = $object->addline($product->description, $product->price, mt_rand(1, 5), 0, 0, 0, $prodids[$prodid], 0);
197 197
 			if ($result < 0)
198 198
 			{
199
-				dol_print_error($db,$object->error);
199
+				dol_print_error($db, $object->error);
200 200
 			}
201 201
 			$xnbp++;
202 202
 		}
203 203
 		
204
-		$result=$object->valid($fuser);
204
+		$result = $object->valid($fuser);
205 205
 		if ($result > 0)
206 206
 		{
207 207
 		    $db->commit();
@@ -211,11 +211,11 @@  discard block
 block discarded – undo
211 211
 		{
212 212
 		    print " KO\n";
213 213
 		    $db->rollback();
214
-		    dol_print_error($db,$object->error);
214
+		    dol_print_error($db, $object->error);
215 215
 		}
216 216
 	}
217 217
 	else
218 218
 	{
219
-		dol_print_error($db,$object->error);
219
+		dol_print_error($db, $object->error);
220 220
 	}
221 221
 }
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -206,15 +206,13 @@
 block discarded – undo
206 206
 		{
207 207
 		    $db->commit();
208 208
 		    print " OK with ref ".$object->ref."\n";
209
-		}
210
-		else
209
+		} else
211 210
 		{
212 211
 		    print " KO\n";
213 212
 		    $db->rollback();
214 213
 		    dol_print_error($db,$object->error);
215 214
 		}
216
-	}
217
-	else
215
+	} else
218 216
 	{
219 217
 		dol_print_error($db,$object->error);
220 218
 	}
Please login to merge, or discard this patch.
dolibarr/scripts/emailings/mailing-send.php 3 patches
Indentation   +297 added lines, -297 removed lines patch added patch discarded remove patch
@@ -32,13 +32,13 @@  discard block
 block discarded – undo
32 32
 
33 33
 // Test if batch mode
34 34
 if (substr($sapi_type, 0, 3) == 'cgi') {
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);
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);
37 37
 }
38 38
 
39 39
 if (! isset($argv[1]) || ! $argv[1]) {
40
-	print "Usage: ".$script_file." (ID_MAILING|all)\n";
41
-	exit(-1);
40
+    print "Usage: ".$script_file." (ID_MAILING|all)\n";
41
+    exit(-1);
42 42
 }
43 43
 $id=$argv[1];
44 44
 if (isset($argv[2]) || !empty($argv[2])) $login = $argv[2];
@@ -76,206 +76,206 @@  discard block
 block discarded – undo
76 76
 $sql.= " WHERE m.statut IN (1,2)";
77 77
 if ($id != 'all')
78 78
 {
79
-	$sql.= " AND m.rowid= ".$id;
80
-	$sql.= " LIMIT 1";
79
+    $sql.= " AND m.rowid= ".$id;
80
+    $sql.= " LIMIT 1";
81 81
 }
82 82
 
83 83
 $resql=$db->query($sql);
84 84
 if ($resql)
85 85
 {
86
-	$num = $db->num_rows($resql);
87
-	$j = 0;
88
-
89
-	if ($num)
90
-	{
91
-		for ($j=0; $j<$num; $j++)
92
-		{
93
-			$obj = $db->fetch_object($resql);
94
-
95
-			dol_syslog("Process mailing with id ".$obj->rowid);
96
-			print "Process mailing with id ".$obj->rowid."\n";
97
-
98
-			$emailing = new Mailing($db);
99
-			$emailing->fetch($obj->rowid);
100
-
101
-			$id       = $emailing->id;
102
-			$subject  = $emailing->sujet;
103
-			$message  = $emailing->body;
104
-			$from     = $emailing->email_from;
105
-			$replyto  = $emailing->email_replyto;
106
-			$errorsto = $emailing->email_errorsto;
107
-			// Le message est-il en html
108
-			$msgishtml=-1;  // Unknown by default
109
-			if (preg_match('/[\s\t]*<html>/i',$message)) $msgishtml=1;
110
-
111
-			$nbok=0; $nbko=0;
112
-
113
-			// On choisit les mails non deja envoyes pour ce mailing (statut=0)
114
-			// ou envoyes en erreur (statut=-1)
115
-			$sql2 = "SELECT mc.rowid, mc.fk_mailing, mc.lastname, mc.firstname, mc.email, mc.other, mc.source_url, mc.source_id, mc.source_type, mc.tag";
116
-			$sql2.= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc";
117
-			$sql2.= " WHERE mc.statut < 1 AND mc.fk_mailing = ".$id;
118
-			if ($conf->global->MAILING_LIMIT_SENDBYCLI > 0)
119
-			{
120
-				$sql2.= " LIMIT ".$conf->global->MAILING_LIMIT_SENDBYCLI;
121
-			}
122
-
123
-			$resql2=$db->query($sql2);
124
-			if ($resql2)
125
-			{
126
-				$num2 = $db->num_rows($resql2);
127
-				dol_syslog("Nb of targets = ".$num2, LOG_DEBUG);
128
-				print "Nb of targets = ".$num2."\n";
129
-
130
-				if ($num2)
131
-				{
132
-					$now=dol_now();
133
-
134
-					// Positionne date debut envoi
135
-					$sqlstartdate="UPDATE ".MAIN_DB_PREFIX."mailing SET date_envoi='".$db->idate($now)."' WHERE rowid=".$id;
136
-					$resqlstartdate=$db->query($sqlstartdate);
137
-					if (! $resqlstartdate)
138
-					{
139
-						dol_print_error($db);
140
-						$error++;
141
-					}
142
-
143
-					// Look on each email and sent message
144
-					$i = 0;
145
-					while ($i < $num2)
146
-					{
147
-						// Here code is common with same loop ino card.php
148
-						$res=1;
149
-						$now=dol_now();
150
-
151
-						$obj = $db->fetch_object($resql2);
152
-
153
-						// sendto en RFC2822
154
-						$sendto = str_replace(',',' ',dolGetFirstLastname($obj->firstname, $obj->lastname) ." <".$obj->email.">");
155
-
156
-						// Make subtsitutions on topic and body
157
-						$other=explode(';',$obj->other);
158
-						$tmpfield=explode('=',$other[0],2); $other1=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
159
-						$tmpfield=explode('=',$other[1],2); $other2=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
160
-						$tmpfield=explode('=',$other[2],2); $other3=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
161
-						$tmpfield=explode('=',$other[3],2); $other4=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
162
-						$tmpfield=explode('=',$other[4],2); $other5=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
163
-						$signature = ((!empty($user->signature) && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN))?$user->signature:'');
164
-
165
-						$object = null;		// Not defined with mass emailing
166
-						$parameters=array('mode'=>'emailing');
167
-						$substitutionarray=getCommonSubstitutionArray($langs, 0, array('object','objectamount'), $object);			// Note: On mass emailing, this is null because we don't know object
168
-
169
-						// Array of possible substitutions (See also file mailing-send.php that should manage same substitutions)
170
-						$substitutionarray['__ID__'] = $obj->source_id;
171
-						$substitutionarray['__EMAIL__'] = $obj->email;
172
-						$substitutionarray['__LASTNAME__'] = $obj->lastname;
173
-						$substitutionarray['__FIRSTNAME__'] = $obj->firstname;
174
-						$substitutionarray['__MAILTOEMAIL__'] = '<a href="mailto:'.$obj->email.'">'.$obj->email.'</a>';
175
-						$substitutionarray['__OTHER1__'] = $other1;
176
-						$substitutionarray['__OTHER2__'] = $other2;
177
-						$substitutionarray['__OTHER3__'] = $other3;
178
-						$substitutionarray['__OTHER4__'] = $other4;
179
-						$substitutionarray['__OTHER5__'] = $other5;
180
-						$substitutionarray['__USER_SIGNATURE__'] = $signature;	// Signature is empty when ran from command line or taken from user in parameter)
181
-						$substitutionarray['__SIGNATURE__'] = $signature;	// For backward compatibility
182
-						$substitutionarray['__CHECK_READ__'] = '<img src="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-read.php?tag='.$obj->tag.'&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" width="1" height="1" style="width:1px;height:1px" border="0"/>';
183
-						$substitutionarray['__UNSUBSCRIBE__'] = '<a href="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-unsubscribe.php?tag='.$obj->tag.'&unsuscrib=1&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" target="_blank">'.$langs->trans("MailUnsubcribe").'</a>';
184
-
185
-						$onlinepaymentenabled = 0;
186
-						if (! empty($conf->paypal->enabled)) $onlinepaymentenabled++;
187
-						if (! empty($conf->paybox->enabled)) $onlinepaymentenabled++;
188
-						if (! empty($conf->stripe->enabled)) $onlinepaymentenabled++;
189
-						if ($onlinepaymentenabled && ! empty($conf->global->PAYMENT_SECURITY_TOKEN))
190
-						{
191
-							$substitutionarray['__SECUREKEYPAYMENT__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
192
-							if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE))
193
-							{
194
-								$substitutionarray['__SECUREKEYPAYMENT_MEMBER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
195
-								$substitutionarray['__SECUREKEYPAYMENT_ORDER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
196
-								$substitutionarray['__SECUREKEYPAYMENT_INVOICE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
197
-								$substitutionarray['__SECUREKEYPAYMENT_CONTRACTLINE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
198
-							}
199
-							else
200
-							{
201
-								$substitutionarray['__SECUREKEYPAYMENT_MEMBER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'membersubscription' . $obj->source_id, 2);
202
-								$substitutionarray['__SECUREKEYPAYMENT_ORDER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'order' . $obj->source_id, 2);
203
-								$substitutionarray['__SECUREKEYPAYMENT_INVOICE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'invoice' . $obj->source_id, 2);
204
-								$substitutionarray['__SECUREKEYPAYMENT_CONTRACTLINE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'contractline' . $obj->source_id, 2);
205
-							}
206
-						}
207
-						/* For backward compatibility */
208
-						if (! empty($conf->paypal->enabled) && ! empty($conf->global->PAYPAL_SECURITY_TOKEN))
209
-						{
210
-							$substitutionarray['__SECUREKEYPAYPAL__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
211
-
212
-							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_MEMBER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
213
-							else $substitutionarray['__SECUREKEYPAYPAL_MEMBER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'membersubscription' . $obj->source_id, 2);
214
-
215
-							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_ORDER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
216
-							else $substitutionarray['__SECUREKEYPAYPAL_ORDER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'order' . $obj->source_id, 2);
217
-
218
-							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_INVOICE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
219
-							else $substitutionarray['__SECUREKEYPAYPAL_INVOICE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'invoice' . $obj->source_id, 2);
220
-
221
-							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
222
-							else $substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'contractline' . $obj->source_id, 2);
223
-						}
224
-
225
-						complete_substitutions_array($substitutionarray,$langs);
226
-						$newsubject=make_substitutions($subject,$substitutionarray);
227
-						$newmessage=make_substitutions($message,$substitutionarray);
228
-
229
-						$substitutionisok=true;
230
-
231
-						// Fabrication du mail
232
-						$trackid='emailing-'.$obj->fk_mailing.'-'.$obj->rowid;
233
-						$mail = new CMailFile(
234
-							$newsubject,
235
-							$sendto,
236
-							$from,
237
-							$newmessage,
238
-							array(),
239
-							array(),
240
-							array(),
241
-							'',
242
-							'',
243
-							0,
244
-							$msgishtml,
245
-							$errorsto,
246
-							'',
247
-							$trackid,
248
-							'',
249
-							'emailing'
250
-						);
251
-
252
-						if ($mail->error)
253
-						{
254
-							$res=0;
255
-						}
256
-						if (! $substitutionisok)
257
-						{
258
-							$mail->error='Some substitution failed';
259
-							$res=0;
260
-						}
261
-
262
-						// Send Email
263
-						if ($res)
264
-						{
265
-							$res=$mail->sendfile();
266
-						}
267
-
268
-						if ($res)
269
-						{
270
-							// Mail successful
271
-							$nbok++;
272
-
273
-							dol_syslog("ok for emailing id ".$id." #".$i.($mail->error?' - '.$mail->error:''), LOG_DEBUG);
274
-
275
-							// Note: If emailing is 100 000 targets, 100 000 entries are added, so we don't enter events for each target here
276
-							// We must union table llx_mailing_taget for event tab OR enter 1 event with a special table link (id of email in event)
277
-							// Run trigger
278
-							/*
86
+    $num = $db->num_rows($resql);
87
+    $j = 0;
88
+
89
+    if ($num)
90
+    {
91
+        for ($j=0; $j<$num; $j++)
92
+        {
93
+            $obj = $db->fetch_object($resql);
94
+
95
+            dol_syslog("Process mailing with id ".$obj->rowid);
96
+            print "Process mailing with id ".$obj->rowid."\n";
97
+
98
+            $emailing = new Mailing($db);
99
+            $emailing->fetch($obj->rowid);
100
+
101
+            $id       = $emailing->id;
102
+            $subject  = $emailing->sujet;
103
+            $message  = $emailing->body;
104
+            $from     = $emailing->email_from;
105
+            $replyto  = $emailing->email_replyto;
106
+            $errorsto = $emailing->email_errorsto;
107
+            // Le message est-il en html
108
+            $msgishtml=-1;  // Unknown by default
109
+            if (preg_match('/[\s\t]*<html>/i',$message)) $msgishtml=1;
110
+
111
+            $nbok=0; $nbko=0;
112
+
113
+            // On choisit les mails non deja envoyes pour ce mailing (statut=0)
114
+            // ou envoyes en erreur (statut=-1)
115
+            $sql2 = "SELECT mc.rowid, mc.fk_mailing, mc.lastname, mc.firstname, mc.email, mc.other, mc.source_url, mc.source_id, mc.source_type, mc.tag";
116
+            $sql2.= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc";
117
+            $sql2.= " WHERE mc.statut < 1 AND mc.fk_mailing = ".$id;
118
+            if ($conf->global->MAILING_LIMIT_SENDBYCLI > 0)
119
+            {
120
+                $sql2.= " LIMIT ".$conf->global->MAILING_LIMIT_SENDBYCLI;
121
+            }
122
+
123
+            $resql2=$db->query($sql2);
124
+            if ($resql2)
125
+            {
126
+                $num2 = $db->num_rows($resql2);
127
+                dol_syslog("Nb of targets = ".$num2, LOG_DEBUG);
128
+                print "Nb of targets = ".$num2."\n";
129
+
130
+                if ($num2)
131
+                {
132
+                    $now=dol_now();
133
+
134
+                    // Positionne date debut envoi
135
+                    $sqlstartdate="UPDATE ".MAIN_DB_PREFIX."mailing SET date_envoi='".$db->idate($now)."' WHERE rowid=".$id;
136
+                    $resqlstartdate=$db->query($sqlstartdate);
137
+                    if (! $resqlstartdate)
138
+                    {
139
+                        dol_print_error($db);
140
+                        $error++;
141
+                    }
142
+
143
+                    // Look on each email and sent message
144
+                    $i = 0;
145
+                    while ($i < $num2)
146
+                    {
147
+                        // Here code is common with same loop ino card.php
148
+                        $res=1;
149
+                        $now=dol_now();
150
+
151
+                        $obj = $db->fetch_object($resql2);
152
+
153
+                        // sendto en RFC2822
154
+                        $sendto = str_replace(',',' ',dolGetFirstLastname($obj->firstname, $obj->lastname) ." <".$obj->email.">");
155
+
156
+                        // Make subtsitutions on topic and body
157
+                        $other=explode(';',$obj->other);
158
+                        $tmpfield=explode('=',$other[0],2); $other1=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
159
+                        $tmpfield=explode('=',$other[1],2); $other2=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
160
+                        $tmpfield=explode('=',$other[2],2); $other3=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
161
+                        $tmpfield=explode('=',$other[3],2); $other4=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
162
+                        $tmpfield=explode('=',$other[4],2); $other5=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
163
+                        $signature = ((!empty($user->signature) && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN))?$user->signature:'');
164
+
165
+                        $object = null;		// Not defined with mass emailing
166
+                        $parameters=array('mode'=>'emailing');
167
+                        $substitutionarray=getCommonSubstitutionArray($langs, 0, array('object','objectamount'), $object);			// Note: On mass emailing, this is null because we don't know object
168
+
169
+                        // Array of possible substitutions (See also file mailing-send.php that should manage same substitutions)
170
+                        $substitutionarray['__ID__'] = $obj->source_id;
171
+                        $substitutionarray['__EMAIL__'] = $obj->email;
172
+                        $substitutionarray['__LASTNAME__'] = $obj->lastname;
173
+                        $substitutionarray['__FIRSTNAME__'] = $obj->firstname;
174
+                        $substitutionarray['__MAILTOEMAIL__'] = '<a href="mailto:'.$obj->email.'">'.$obj->email.'</a>';
175
+                        $substitutionarray['__OTHER1__'] = $other1;
176
+                        $substitutionarray['__OTHER2__'] = $other2;
177
+                        $substitutionarray['__OTHER3__'] = $other3;
178
+                        $substitutionarray['__OTHER4__'] = $other4;
179
+                        $substitutionarray['__OTHER5__'] = $other5;
180
+                        $substitutionarray['__USER_SIGNATURE__'] = $signature;	// Signature is empty when ran from command line or taken from user in parameter)
181
+                        $substitutionarray['__SIGNATURE__'] = $signature;	// For backward compatibility
182
+                        $substitutionarray['__CHECK_READ__'] = '<img src="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-read.php?tag='.$obj->tag.'&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" width="1" height="1" style="width:1px;height:1px" border="0"/>';
183
+                        $substitutionarray['__UNSUBSCRIBE__'] = '<a href="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-unsubscribe.php?tag='.$obj->tag.'&unsuscrib=1&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" target="_blank">'.$langs->trans("MailUnsubcribe").'</a>';
184
+
185
+                        $onlinepaymentenabled = 0;
186
+                        if (! empty($conf->paypal->enabled)) $onlinepaymentenabled++;
187
+                        if (! empty($conf->paybox->enabled)) $onlinepaymentenabled++;
188
+                        if (! empty($conf->stripe->enabled)) $onlinepaymentenabled++;
189
+                        if ($onlinepaymentenabled && ! empty($conf->global->PAYMENT_SECURITY_TOKEN))
190
+                        {
191
+                            $substitutionarray['__SECUREKEYPAYMENT__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
192
+                            if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE))
193
+                            {
194
+                                $substitutionarray['__SECUREKEYPAYMENT_MEMBER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
195
+                                $substitutionarray['__SECUREKEYPAYMENT_ORDER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
196
+                                $substitutionarray['__SECUREKEYPAYMENT_INVOICE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
197
+                                $substitutionarray['__SECUREKEYPAYMENT_CONTRACTLINE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
198
+                            }
199
+                            else
200
+                            {
201
+                                $substitutionarray['__SECUREKEYPAYMENT_MEMBER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'membersubscription' . $obj->source_id, 2);
202
+                                $substitutionarray['__SECUREKEYPAYMENT_ORDER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'order' . $obj->source_id, 2);
203
+                                $substitutionarray['__SECUREKEYPAYMENT_INVOICE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'invoice' . $obj->source_id, 2);
204
+                                $substitutionarray['__SECUREKEYPAYMENT_CONTRACTLINE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'contractline' . $obj->source_id, 2);
205
+                            }
206
+                        }
207
+                        /* For backward compatibility */
208
+                        if (! empty($conf->paypal->enabled) && ! empty($conf->global->PAYPAL_SECURITY_TOKEN))
209
+                        {
210
+                            $substitutionarray['__SECUREKEYPAYPAL__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
211
+
212
+                            if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_MEMBER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
213
+                            else $substitutionarray['__SECUREKEYPAYPAL_MEMBER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'membersubscription' . $obj->source_id, 2);
214
+
215
+                            if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_ORDER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
216
+                            else $substitutionarray['__SECUREKEYPAYPAL_ORDER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'order' . $obj->source_id, 2);
217
+
218
+                            if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_INVOICE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
219
+                            else $substitutionarray['__SECUREKEYPAYPAL_INVOICE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'invoice' . $obj->source_id, 2);
220
+
221
+                            if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
222
+                            else $substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'contractline' . $obj->source_id, 2);
223
+                        }
224
+
225
+                        complete_substitutions_array($substitutionarray,$langs);
226
+                        $newsubject=make_substitutions($subject,$substitutionarray);
227
+                        $newmessage=make_substitutions($message,$substitutionarray);
228
+
229
+                        $substitutionisok=true;
230
+
231
+                        // Fabrication du mail
232
+                        $trackid='emailing-'.$obj->fk_mailing.'-'.$obj->rowid;
233
+                        $mail = new CMailFile(
234
+                            $newsubject,
235
+                            $sendto,
236
+                            $from,
237
+                            $newmessage,
238
+                            array(),
239
+                            array(),
240
+                            array(),
241
+                            '',
242
+                            '',
243
+                            0,
244
+                            $msgishtml,
245
+                            $errorsto,
246
+                            '',
247
+                            $trackid,
248
+                            '',
249
+                            'emailing'
250
+                        );
251
+
252
+                        if ($mail->error)
253
+                        {
254
+                            $res=0;
255
+                        }
256
+                        if (! $substitutionisok)
257
+                        {
258
+                            $mail->error='Some substitution failed';
259
+                            $res=0;
260
+                        }
261
+
262
+                        // Send Email
263
+                        if ($res)
264
+                        {
265
+                            $res=$mail->sendfile();
266
+                        }
267
+
268
+                        if ($res)
269
+                        {
270
+                            // Mail successful
271
+                            $nbok++;
272
+
273
+                            dol_syslog("ok for emailing id ".$id." #".$i.($mail->error?' - '.$mail->error:''), LOG_DEBUG);
274
+
275
+                            // Note: If emailing is 100 000 targets, 100 000 entries are added, so we don't enter events for each target here
276
+                            // We must union table llx_mailing_taget for event tab OR enter 1 event with a special table link (id of email in event)
277
+                            // Run trigger
278
+                            /*
279 279
 							if ($obj->source_type == 'contact')
280 280
 							{
281 281
 							    $emailing->sendtoid = $obj->source_id;
@@ -290,107 +290,107 @@  discard block
 block discarded – undo
290 290
                             // End call triggers
291 291
 						    */
292 292
 
293
-							$sqlok ="UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
294
-							$sqlok.=" SET statut=1, date_envoi='".$db->idate($now)."' WHERE rowid=".$obj->rowid;
295
-							$resqlok=$db->query($sqlok);
296
-							if (! $resqlok)
297
-							{
298
-								dol_print_error($db);
299
-								$error++;
300
-							}
301
-							else
302
-							{
303
-								//if cheack read is use then update prospect contact status
304
-								if (strpos($message, '__CHECK_READ__') !== false)
305
-								{
306
-									//Update status communication of thirdparty prospect
307
-									$sqlx = "UPDATE ".MAIN_DB_PREFIX."societe SET fk_stcomm=2 WHERE rowid IN (SELECT source_id FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE rowid=".$obj->rowid.")";
308
-									dol_syslog("card.php: set prospect thirdparty status", LOG_DEBUG);
309
-									$resqlx=$db->query($sqlx);
310
-									if (! $resqlx)
311
-									{
312
-										dol_print_error($db);
313
-										$error++;
314
-									}
315
-
316
-									//Update status communication of contact prospect
317
-									$sqlx = "UPDATE ".MAIN_DB_PREFIX."societe SET fk_stcomm=2 WHERE rowid IN (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."socpeople AS sc INNER JOIN ".MAIN_DB_PREFIX."mailing_cibles AS mc ON mc.rowid=".$obj->rowid." AND mc.source_type = 'contact' AND mc.source_id = sc.rowid)";
318
-									dol_syslog("card.php: set prospect contact status", LOG_DEBUG);
319
-
320
-									$resqlx=$db->query($sqlx);
321
-									if (! $resqlx)
322
-									{
323
-										dol_print_error($db);
324
-										$error++;
325
-									}
326
-								}
327
-
328
-								if (!empty($conf->global->MAILING_DELAY)) {
329
-									sleep($conf->global->MAILING_DELAY);
330
-								}
331
-							}
332
-						}
333
-						else
334
-						{
335
-							// Mail failed
336
-							$nbko++;
337
-
338
-							dol_syslog("error for emailing id ".$id." #".$i.($mail->error?' - '.$mail->error:''), LOG_DEBUG);
339
-
340
-							$sqlerror="UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
341
-							$sqlerror.=" SET statut=-1, date_envoi=".$db->idate($now)." WHERE rowid=".$obj->rowid;
342
-							$resqlerror=$db->query($sqlerror);
343
-							if (! $resqlerror)
344
-							{
345
-								dol_print_error($db);
346
-								$error++;
347
-							}
348
-						}
349
-
350
-						$i++;
351
-					}
352
-				}
353
-				else
354
-				{
355
-					$mesg="Emailing id ".$id." has no recipient to target";
356
-					print $mesg."\n";
357
-					dol_syslog($mesg,LOG_ERR);
358
-				}
359
-
360
-				// Loop finished, set global statut of mail
361
-				$statut=2;
362
-				if (! $nbko) $statut=3;
363
-
364
-				$sqlenddate="UPDATE ".MAIN_DB_PREFIX."mailing SET statut=".$statut." WHERE rowid=".$id;
365
-
366
-				dol_syslog("update global status", LOG_DEBUG);
367
-				print "Update status of emailing id ".$id." to ".$statut."\n";
368
-				$resqlenddate=$db->query($sqlenddate);
369
-				if (! $resqlenddate)
370
-				{
371
-					dol_print_error($db);
372
-					$error++;
373
-				}
374
-			}
375
-			else
376
-			{
377
-				dol_print_error($db);
378
-				$error++;
379
-			}
380
-		}
381
-	}
382
-	else
383
-	{
384
-		$mesg="No validated emailing id to send found.";
385
-		print $mesg."\n";
386
-		dol_syslog($mesg,LOG_ERR);
387
-		$error++;
388
-	}
293
+                            $sqlok ="UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
294
+                            $sqlok.=" SET statut=1, date_envoi='".$db->idate($now)."' WHERE rowid=".$obj->rowid;
295
+                            $resqlok=$db->query($sqlok);
296
+                            if (! $resqlok)
297
+                            {
298
+                                dol_print_error($db);
299
+                                $error++;
300
+                            }
301
+                            else
302
+                            {
303
+                                //if cheack read is use then update prospect contact status
304
+                                if (strpos($message, '__CHECK_READ__') !== false)
305
+                                {
306
+                                    //Update status communication of thirdparty prospect
307
+                                    $sqlx = "UPDATE ".MAIN_DB_PREFIX."societe SET fk_stcomm=2 WHERE rowid IN (SELECT source_id FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE rowid=".$obj->rowid.")";
308
+                                    dol_syslog("card.php: set prospect thirdparty status", LOG_DEBUG);
309
+                                    $resqlx=$db->query($sqlx);
310
+                                    if (! $resqlx)
311
+                                    {
312
+                                        dol_print_error($db);
313
+                                        $error++;
314
+                                    }
315
+
316
+                                    //Update status communication of contact prospect
317
+                                    $sqlx = "UPDATE ".MAIN_DB_PREFIX."societe SET fk_stcomm=2 WHERE rowid IN (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."socpeople AS sc INNER JOIN ".MAIN_DB_PREFIX."mailing_cibles AS mc ON mc.rowid=".$obj->rowid." AND mc.source_type = 'contact' AND mc.source_id = sc.rowid)";
318
+                                    dol_syslog("card.php: set prospect contact status", LOG_DEBUG);
319
+
320
+                                    $resqlx=$db->query($sqlx);
321
+                                    if (! $resqlx)
322
+                                    {
323
+                                        dol_print_error($db);
324
+                                        $error++;
325
+                                    }
326
+                                }
327
+
328
+                                if (!empty($conf->global->MAILING_DELAY)) {
329
+                                    sleep($conf->global->MAILING_DELAY);
330
+                                }
331
+                            }
332
+                        }
333
+                        else
334
+                        {
335
+                            // Mail failed
336
+                            $nbko++;
337
+
338
+                            dol_syslog("error for emailing id ".$id." #".$i.($mail->error?' - '.$mail->error:''), LOG_DEBUG);
339
+
340
+                            $sqlerror="UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
341
+                            $sqlerror.=" SET statut=-1, date_envoi=".$db->idate($now)." WHERE rowid=".$obj->rowid;
342
+                            $resqlerror=$db->query($sqlerror);
343
+                            if (! $resqlerror)
344
+                            {
345
+                                dol_print_error($db);
346
+                                $error++;
347
+                            }
348
+                        }
349
+
350
+                        $i++;
351
+                    }
352
+                }
353
+                else
354
+                {
355
+                    $mesg="Emailing id ".$id." has no recipient to target";
356
+                    print $mesg."\n";
357
+                    dol_syslog($mesg,LOG_ERR);
358
+                }
359
+
360
+                // Loop finished, set global statut of mail
361
+                $statut=2;
362
+                if (! $nbko) $statut=3;
363
+
364
+                $sqlenddate="UPDATE ".MAIN_DB_PREFIX."mailing SET statut=".$statut." WHERE rowid=".$id;
365
+
366
+                dol_syslog("update global status", LOG_DEBUG);
367
+                print "Update status of emailing id ".$id." to ".$statut."\n";
368
+                $resqlenddate=$db->query($sqlenddate);
369
+                if (! $resqlenddate)
370
+                {
371
+                    dol_print_error($db);
372
+                    $error++;
373
+                }
374
+            }
375
+            else
376
+            {
377
+                dol_print_error($db);
378
+                $error++;
379
+            }
380
+        }
381
+    }
382
+    else
383
+    {
384
+        $mesg="No validated emailing id to send found.";
385
+        print $mesg."\n";
386
+        dol_syslog($mesg,LOG_ERR);
387
+        $error++;
388
+    }
389 389
 }
390 390
 else
391 391
 {
392
-	dol_print_error($db);
393
-	$error++;
392
+    dol_print_error($db);
393
+    $error++;
394 394
 }
395 395
 
396 396
 
Please login to merge, or discard this patch.
Spacing   +95 added lines, -95 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 
29 29
 $sapi_type = php_sapi_name();
30 30
 $script_file = basename(__FILE__);
31
-$path=dirname(__FILE__).'/';
31
+$path = dirname(__FILE__).'/';
32 32
 
33 33
 // Test if batch mode
34 34
 if (substr($sapi_type, 0, 3) == 'cgi') {
@@ -36,11 +36,11 @@  discard block
 block discarded – undo
36 36
 	exit(-1);
37 37
 }
38 38
 
39
-if (! isset($argv[1]) || ! $argv[1]) {
39
+if (!isset($argv[1]) || !$argv[1]) {
40 40
 	print "Usage: ".$script_file." (ID_MAILING|all)\n";
41 41
 	exit(-1);
42 42
 }
43
-$id=$argv[1];
43
+$id = $argv[1];
44 44
 if (isset($argv[2]) || !empty($argv[2])) $login = $argv[2];
45 45
 else $login = '';
46 46
 
@@ -50,8 +50,8 @@  discard block
 block discarded – undo
50 50
 
51 51
 
52 52
 // Global variables
53
-$version=DOL_VERSION;
54
-$error=0;
53
+$version = DOL_VERSION;
54
+$error = 0;
55 55
 
56 56
 
57 57
 
@@ -68,19 +68,19 @@  discard block
 block discarded – undo
68 68
 
69 69
 $user = new User($db);
70 70
 // for signature, we use user send as parameter
71
-if (! empty($login)) $user->fetch('',$login);
71
+if (!empty($login)) $user->fetch('', $login);
72 72
 
73 73
 // We get list of emailing id to process
74 74
 $sql = "SELECT m.rowid";
75
-$sql.= " FROM ".MAIN_DB_PREFIX."mailing as m";
76
-$sql.= " WHERE m.statut IN (1,2)";
75
+$sql .= " FROM ".MAIN_DB_PREFIX."mailing as m";
76
+$sql .= " WHERE m.statut IN (1,2)";
77 77
 if ($id != 'all')
78 78
 {
79
-	$sql.= " AND m.rowid= ".$id;
80
-	$sql.= " LIMIT 1";
79
+	$sql .= " AND m.rowid= ".$id;
80
+	$sql .= " LIMIT 1";
81 81
 }
82 82
 
83
-$resql=$db->query($sql);
83
+$resql = $db->query($sql);
84 84
 if ($resql)
85 85
 {
86 86
 	$num = $db->num_rows($resql);
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 
89 89
 	if ($num)
90 90
 	{
91
-		for ($j=0; $j<$num; $j++)
91
+		for ($j = 0; $j < $num; $j++)
92 92
 		{
93 93
 			$obj = $db->fetch_object($resql);
94 94
 
@@ -105,22 +105,22 @@  discard block
 block discarded – undo
105 105
 			$replyto  = $emailing->email_replyto;
106 106
 			$errorsto = $emailing->email_errorsto;
107 107
 			// Le message est-il en html
108
-			$msgishtml=-1;  // Unknown by default
109
-			if (preg_match('/[\s\t]*<html>/i',$message)) $msgishtml=1;
108
+			$msgishtml = -1; // Unknown by default
109
+			if (preg_match('/[\s\t]*<html>/i', $message)) $msgishtml = 1;
110 110
 
111
-			$nbok=0; $nbko=0;
111
+			$nbok = 0; $nbko = 0;
112 112
 
113 113
 			// On choisit les mails non deja envoyes pour ce mailing (statut=0)
114 114
 			// ou envoyes en erreur (statut=-1)
115 115
 			$sql2 = "SELECT mc.rowid, mc.fk_mailing, mc.lastname, mc.firstname, mc.email, mc.other, mc.source_url, mc.source_id, mc.source_type, mc.tag";
116
-			$sql2.= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc";
117
-			$sql2.= " WHERE mc.statut < 1 AND mc.fk_mailing = ".$id;
116
+			$sql2 .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc";
117
+			$sql2 .= " WHERE mc.statut < 1 AND mc.fk_mailing = ".$id;
118 118
 			if ($conf->global->MAILING_LIMIT_SENDBYCLI > 0)
119 119
 			{
120
-				$sql2.= " LIMIT ".$conf->global->MAILING_LIMIT_SENDBYCLI;
120
+				$sql2 .= " LIMIT ".$conf->global->MAILING_LIMIT_SENDBYCLI;
121 121
 			}
122 122
 
123
-			$resql2=$db->query($sql2);
123
+			$resql2 = $db->query($sql2);
124 124
 			if ($resql2)
125 125
 			{
126 126
 				$num2 = $db->num_rows($resql2);
@@ -129,12 +129,12 @@  discard block
 block discarded – undo
129 129
 
130 130
 				if ($num2)
131 131
 				{
132
-					$now=dol_now();
132
+					$now = dol_now();
133 133
 
134 134
 					// Positionne date debut envoi
135
-					$sqlstartdate="UPDATE ".MAIN_DB_PREFIX."mailing SET date_envoi='".$db->idate($now)."' WHERE rowid=".$id;
136
-					$resqlstartdate=$db->query($sqlstartdate);
137
-					if (! $resqlstartdate)
135
+					$sqlstartdate = "UPDATE ".MAIN_DB_PREFIX."mailing SET date_envoi='".$db->idate($now)."' WHERE rowid=".$id;
136
+					$resqlstartdate = $db->query($sqlstartdate);
137
+					if (!$resqlstartdate)
138 138
 					{
139 139
 						dol_print_error($db);
140 140
 						$error++;
@@ -145,26 +145,26 @@  discard block
 block discarded – undo
145 145
 					while ($i < $num2)
146 146
 					{
147 147
 						// Here code is common with same loop ino card.php
148
-						$res=1;
149
-						$now=dol_now();
148
+						$res = 1;
149
+						$now = dol_now();
150 150
 
151 151
 						$obj = $db->fetch_object($resql2);
152 152
 
153 153
 						// sendto en RFC2822
154
-						$sendto = str_replace(',',' ',dolGetFirstLastname($obj->firstname, $obj->lastname) ." <".$obj->email.">");
154
+						$sendto = str_replace(',', ' ', dolGetFirstLastname($obj->firstname, $obj->lastname)." <".$obj->email.">");
155 155
 
156 156
 						// Make subtsitutions on topic and body
157
-						$other=explode(';',$obj->other);
158
-						$tmpfield=explode('=',$other[0],2); $other1=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
159
-						$tmpfield=explode('=',$other[1],2); $other2=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
160
-						$tmpfield=explode('=',$other[2],2); $other3=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
161
-						$tmpfield=explode('=',$other[3],2); $other4=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
162
-						$tmpfield=explode('=',$other[4],2); $other5=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
163
-						$signature = ((!empty($user->signature) && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN))?$user->signature:'');
164
-
165
-						$object = null;		// Not defined with mass emailing
166
-						$parameters=array('mode'=>'emailing');
167
-						$substitutionarray=getCommonSubstitutionArray($langs, 0, array('object','objectamount'), $object);			// Note: On mass emailing, this is null because we don't know object
157
+						$other = explode(';', $obj->other);
158
+						$tmpfield = explode('=', $other[0], 2); $other1 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
159
+						$tmpfield = explode('=', $other[1], 2); $other2 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
160
+						$tmpfield = explode('=', $other[2], 2); $other3 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
161
+						$tmpfield = explode('=', $other[3], 2); $other4 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
162
+						$tmpfield = explode('=', $other[4], 2); $other5 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
163
+						$signature = ((!empty($user->signature) && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? $user->signature : '');
164
+
165
+						$object = null; // Not defined with mass emailing
166
+						$parameters = array('mode'=>'emailing');
167
+						$substitutionarray = getCommonSubstitutionArray($langs, 0, array('object', 'objectamount'), $object); // Note: On mass emailing, this is null because we don't know object
168 168
 
169 169
 						// Array of possible substitutions (See also file mailing-send.php that should manage same substitutions)
170 170
 						$substitutionarray['__ID__'] = $obj->source_id;
@@ -177,59 +177,59 @@  discard block
 block discarded – undo
177 177
 						$substitutionarray['__OTHER3__'] = $other3;
178 178
 						$substitutionarray['__OTHER4__'] = $other4;
179 179
 						$substitutionarray['__OTHER5__'] = $other5;
180
-						$substitutionarray['__USER_SIGNATURE__'] = $signature;	// Signature is empty when ran from command line or taken from user in parameter)
181
-						$substitutionarray['__SIGNATURE__'] = $signature;	// For backward compatibility
180
+						$substitutionarray['__USER_SIGNATURE__'] = $signature; // Signature is empty when ran from command line or taken from user in parameter)
181
+						$substitutionarray['__SIGNATURE__'] = $signature; // For backward compatibility
182 182
 						$substitutionarray['__CHECK_READ__'] = '<img src="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-read.php?tag='.$obj->tag.'&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" width="1" height="1" style="width:1px;height:1px" border="0"/>';
183 183
 						$substitutionarray['__UNSUBSCRIBE__'] = '<a href="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-unsubscribe.php?tag='.$obj->tag.'&unsuscrib=1&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" target="_blank">'.$langs->trans("MailUnsubcribe").'</a>';
184 184
 
185 185
 						$onlinepaymentenabled = 0;
186
-						if (! empty($conf->paypal->enabled)) $onlinepaymentenabled++;
187
-						if (! empty($conf->paybox->enabled)) $onlinepaymentenabled++;
188
-						if (! empty($conf->stripe->enabled)) $onlinepaymentenabled++;
189
-						if ($onlinepaymentenabled && ! empty($conf->global->PAYMENT_SECURITY_TOKEN))
186
+						if (!empty($conf->paypal->enabled)) $onlinepaymentenabled++;
187
+						if (!empty($conf->paybox->enabled)) $onlinepaymentenabled++;
188
+						if (!empty($conf->stripe->enabled)) $onlinepaymentenabled++;
189
+						if ($onlinepaymentenabled && !empty($conf->global->PAYMENT_SECURITY_TOKEN))
190 190
 						{
191
-							$substitutionarray['__SECUREKEYPAYMENT__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
191
+							$substitutionarray['__SECUREKEYPAYMENT__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
192 192
 							if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE))
193 193
 							{
194
-								$substitutionarray['__SECUREKEYPAYMENT_MEMBER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
195
-								$substitutionarray['__SECUREKEYPAYMENT_ORDER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
196
-								$substitutionarray['__SECUREKEYPAYMENT_INVOICE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
197
-								$substitutionarray['__SECUREKEYPAYMENT_CONTRACTLINE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
194
+								$substitutionarray['__SECUREKEYPAYMENT_MEMBER__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
195
+								$substitutionarray['__SECUREKEYPAYMENT_ORDER__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
196
+								$substitutionarray['__SECUREKEYPAYMENT_INVOICE__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
197
+								$substitutionarray['__SECUREKEYPAYMENT_CONTRACTLINE__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
198 198
 							}
199 199
 							else
200 200
 							{
201
-								$substitutionarray['__SECUREKEYPAYMENT_MEMBER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'membersubscription' . $obj->source_id, 2);
202
-								$substitutionarray['__SECUREKEYPAYMENT_ORDER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'order' . $obj->source_id, 2);
203
-								$substitutionarray['__SECUREKEYPAYMENT_INVOICE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'invoice' . $obj->source_id, 2);
204
-								$substitutionarray['__SECUREKEYPAYMENT_CONTRACTLINE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'contractline' . $obj->source_id, 2);
201
+								$substitutionarray['__SECUREKEYPAYMENT_MEMBER__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.'membersubscription'.$obj->source_id, 2);
202
+								$substitutionarray['__SECUREKEYPAYMENT_ORDER__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.'order'.$obj->source_id, 2);
203
+								$substitutionarray['__SECUREKEYPAYMENT_INVOICE__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.'invoice'.$obj->source_id, 2);
204
+								$substitutionarray['__SECUREKEYPAYMENT_CONTRACTLINE__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.'contractline'.$obj->source_id, 2);
205 205
 							}
206 206
 						}
207 207
 						/* For backward compatibility */
208
-						if (! empty($conf->paypal->enabled) && ! empty($conf->global->PAYPAL_SECURITY_TOKEN))
208
+						if (!empty($conf->paypal->enabled) && !empty($conf->global->PAYPAL_SECURITY_TOKEN))
209 209
 						{
210
-							$substitutionarray['__SECUREKEYPAYPAL__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
210
+							$substitutionarray['__SECUREKEYPAYPAL__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
211 211
 
212
-							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_MEMBER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
213
-							else $substitutionarray['__SECUREKEYPAYPAL_MEMBER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'membersubscription' . $obj->source_id, 2);
212
+							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_MEMBER__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
213
+							else $substitutionarray['__SECUREKEYPAYPAL_MEMBER__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.'membersubscription'.$obj->source_id, 2);
214 214
 
215
-							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_ORDER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
216
-							else $substitutionarray['__SECUREKEYPAYPAL_ORDER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'order' . $obj->source_id, 2);
215
+							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_ORDER__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
216
+							else $substitutionarray['__SECUREKEYPAYPAL_ORDER__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.'order'.$obj->source_id, 2);
217 217
 
218
-							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_INVOICE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
219
-							else $substitutionarray['__SECUREKEYPAYPAL_INVOICE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'invoice' . $obj->source_id, 2);
218
+							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_INVOICE__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
219
+							else $substitutionarray['__SECUREKEYPAYPAL_INVOICE__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.'invoice'.$obj->source_id, 2);
220 220
 
221
-							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
222
-							else $substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'contractline' . $obj->source_id, 2);
221
+							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
222
+							else $substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.'contractline'.$obj->source_id, 2);
223 223
 						}
224 224
 
225
-						complete_substitutions_array($substitutionarray,$langs);
226
-						$newsubject=make_substitutions($subject,$substitutionarray);
227
-						$newmessage=make_substitutions($message,$substitutionarray);
225
+						complete_substitutions_array($substitutionarray, $langs);
226
+						$newsubject = make_substitutions($subject, $substitutionarray);
227
+						$newmessage = make_substitutions($message, $substitutionarray);
228 228
 
229
-						$substitutionisok=true;
229
+						$substitutionisok = true;
230 230
 
231 231
 						// Fabrication du mail
232
-						$trackid='emailing-'.$obj->fk_mailing.'-'.$obj->rowid;
232
+						$trackid = 'emailing-'.$obj->fk_mailing.'-'.$obj->rowid;
233 233
 						$mail = new CMailFile(
234 234
 							$newsubject,
235 235
 							$sendto,
@@ -251,18 +251,18 @@  discard block
 block discarded – undo
251 251
 
252 252
 						if ($mail->error)
253 253
 						{
254
-							$res=0;
254
+							$res = 0;
255 255
 						}
256
-						if (! $substitutionisok)
256
+						if (!$substitutionisok)
257 257
 						{
258
-							$mail->error='Some substitution failed';
259
-							$res=0;
258
+							$mail->error = 'Some substitution failed';
259
+							$res = 0;
260 260
 						}
261 261
 
262 262
 						// Send Email
263 263
 						if ($res)
264 264
 						{
265
-							$res=$mail->sendfile();
265
+							$res = $mail->sendfile();
266 266
 						}
267 267
 
268 268
 						if ($res)
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
 							// Mail successful
271 271
 							$nbok++;
272 272
 
273
-							dol_syslog("ok for emailing id ".$id." #".$i.($mail->error?' - '.$mail->error:''), LOG_DEBUG);
273
+							dol_syslog("ok for emailing id ".$id." #".$i.($mail->error ? ' - '.$mail->error : ''), LOG_DEBUG);
274 274
 
275 275
 							// Note: If emailing is 100 000 targets, 100 000 entries are added, so we don't enter events for each target here
276 276
 							// We must union table llx_mailing_taget for event tab OR enter 1 event with a special table link (id of email in event)
@@ -290,10 +290,10 @@  discard block
 block discarded – undo
290 290
                             // End call triggers
291 291
 						    */
292 292
 
293
-							$sqlok ="UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
294
-							$sqlok.=" SET statut=1, date_envoi='".$db->idate($now)."' WHERE rowid=".$obj->rowid;
295
-							$resqlok=$db->query($sqlok);
296
-							if (! $resqlok)
293
+							$sqlok = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
294
+							$sqlok .= " SET statut=1, date_envoi='".$db->idate($now)."' WHERE rowid=".$obj->rowid;
295
+							$resqlok = $db->query($sqlok);
296
+							if (!$resqlok)
297 297
 							{
298 298
 								dol_print_error($db);
299 299
 								$error++;
@@ -306,8 +306,8 @@  discard block
 block discarded – undo
306 306
 									//Update status communication of thirdparty prospect
307 307
 									$sqlx = "UPDATE ".MAIN_DB_PREFIX."societe SET fk_stcomm=2 WHERE rowid IN (SELECT source_id FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE rowid=".$obj->rowid.")";
308 308
 									dol_syslog("card.php: set prospect thirdparty status", LOG_DEBUG);
309
-									$resqlx=$db->query($sqlx);
310
-									if (! $resqlx)
309
+									$resqlx = $db->query($sqlx);
310
+									if (!$resqlx)
311 311
 									{
312 312
 										dol_print_error($db);
313 313
 										$error++;
@@ -317,8 +317,8 @@  discard block
 block discarded – undo
317 317
 									$sqlx = "UPDATE ".MAIN_DB_PREFIX."societe SET fk_stcomm=2 WHERE rowid IN (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."socpeople AS sc INNER JOIN ".MAIN_DB_PREFIX."mailing_cibles AS mc ON mc.rowid=".$obj->rowid." AND mc.source_type = 'contact' AND mc.source_id = sc.rowid)";
318 318
 									dol_syslog("card.php: set prospect contact status", LOG_DEBUG);
319 319
 
320
-									$resqlx=$db->query($sqlx);
321
-									if (! $resqlx)
320
+									$resqlx = $db->query($sqlx);
321
+									if (!$resqlx)
322 322
 									{
323 323
 										dol_print_error($db);
324 324
 										$error++;
@@ -335,12 +335,12 @@  discard block
 block discarded – undo
335 335
 							// Mail failed
336 336
 							$nbko++;
337 337
 
338
-							dol_syslog("error for emailing id ".$id." #".$i.($mail->error?' - '.$mail->error:''), LOG_DEBUG);
338
+							dol_syslog("error for emailing id ".$id." #".$i.($mail->error ? ' - '.$mail->error : ''), LOG_DEBUG);
339 339
 
340
-							$sqlerror="UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
341
-							$sqlerror.=" SET statut=-1, date_envoi=".$db->idate($now)." WHERE rowid=".$obj->rowid;
342
-							$resqlerror=$db->query($sqlerror);
343
-							if (! $resqlerror)
340
+							$sqlerror = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
341
+							$sqlerror .= " SET statut=-1, date_envoi=".$db->idate($now)." WHERE rowid=".$obj->rowid;
342
+							$resqlerror = $db->query($sqlerror);
343
+							if (!$resqlerror)
344 344
 							{
345 345
 								dol_print_error($db);
346 346
 								$error++;
@@ -352,21 +352,21 @@  discard block
 block discarded – undo
352 352
 				}
353 353
 				else
354 354
 				{
355
-					$mesg="Emailing id ".$id." has no recipient to target";
355
+					$mesg = "Emailing id ".$id." has no recipient to target";
356 356
 					print $mesg."\n";
357
-					dol_syslog($mesg,LOG_ERR);
357
+					dol_syslog($mesg, LOG_ERR);
358 358
 				}
359 359
 
360 360
 				// Loop finished, set global statut of mail
361
-				$statut=2;
362
-				if (! $nbko) $statut=3;
361
+				$statut = 2;
362
+				if (!$nbko) $statut = 3;
363 363
 
364
-				$sqlenddate="UPDATE ".MAIN_DB_PREFIX."mailing SET statut=".$statut." WHERE rowid=".$id;
364
+				$sqlenddate = "UPDATE ".MAIN_DB_PREFIX."mailing SET statut=".$statut." WHERE rowid=".$id;
365 365
 
366 366
 				dol_syslog("update global status", LOG_DEBUG);
367 367
 				print "Update status of emailing id ".$id." to ".$statut."\n";
368
-				$resqlenddate=$db->query($sqlenddate);
369
-				if (! $resqlenddate)
368
+				$resqlenddate = $db->query($sqlenddate);
369
+				if (!$resqlenddate)
370 370
 				{
371 371
 					dol_print_error($db);
372 372
 					$error++;
@@ -381,9 +381,9 @@  discard block
 block discarded – undo
381 381
 	}
382 382
 	else
383 383
 	{
384
-		$mesg="No validated emailing id to send found.";
384
+		$mesg = "No validated emailing id to send found.";
385 385
 		print $mesg."\n";
386
-		dol_syslog($mesg,LOG_ERR);
386
+		dol_syslog($mesg, LOG_ERR);
387 387
 		$error++;
388 388
 	}
389 389
 }
Please login to merge, or discard this patch.
Braces   +50 added lines, -30 removed lines patch added patch discarded remove patch
@@ -41,8 +41,11 @@  discard block
 block discarded – undo
41 41
 	exit(-1);
42 42
 }
43 43
 $id=$argv[1];
44
-if (isset($argv[2]) || !empty($argv[2])) $login = $argv[2];
45
-else $login = '';
44
+if (isset($argv[2]) || !empty($argv[2])) {
45
+    $login = $argv[2];
46
+} else {
47
+    $login = '';
48
+}
46 49
 
47 50
 require_once $path."../../htdocs/master.inc.php";
48 51
 require_once DOL_DOCUMENT_ROOT."/core/class/CMailFile.class.php";
@@ -68,7 +71,9 @@  discard block
 block discarded – undo
68 71
 
69 72
 $user = new User($db);
70 73
 // for signature, we use user send as parameter
71
-if (! empty($login)) $user->fetch('',$login);
74
+if (! empty($login)) {
75
+    $user->fetch('',$login);
76
+}
72 77
 
73 78
 // We get list of emailing id to process
74 79
 $sql = "SELECT m.rowid";
@@ -106,7 +111,9 @@  discard block
 block discarded – undo
106 111
 			$errorsto = $emailing->email_errorsto;
107 112
 			// Le message est-il en html
108 113
 			$msgishtml=-1;  // Unknown by default
109
-			if (preg_match('/[\s\t]*<html>/i',$message)) $msgishtml=1;
114
+			if (preg_match('/[\s\t]*<html>/i',$message)) {
115
+			    $msgishtml=1;
116
+			}
110 117
 
111 118
 			$nbok=0; $nbko=0;
112 119
 
@@ -183,9 +190,15 @@  discard block
 block discarded – undo
183 190
 						$substitutionarray['__UNSUBSCRIBE__'] = '<a href="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-unsubscribe.php?tag='.$obj->tag.'&unsuscrib=1&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" target="_blank">'.$langs->trans("MailUnsubcribe").'</a>';
184 191
 
185 192
 						$onlinepaymentenabled = 0;
186
-						if (! empty($conf->paypal->enabled)) $onlinepaymentenabled++;
187
-						if (! empty($conf->paybox->enabled)) $onlinepaymentenabled++;
188
-						if (! empty($conf->stripe->enabled)) $onlinepaymentenabled++;
193
+						if (! empty($conf->paypal->enabled)) {
194
+						    $onlinepaymentenabled++;
195
+						}
196
+						if (! empty($conf->paybox->enabled)) {
197
+						    $onlinepaymentenabled++;
198
+						}
199
+						if (! empty($conf->stripe->enabled)) {
200
+						    $onlinepaymentenabled++;
201
+						}
189 202
 						if ($onlinepaymentenabled && ! empty($conf->global->PAYMENT_SECURITY_TOKEN))
190 203
 						{
191 204
 							$substitutionarray['__SECUREKEYPAYMENT__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
@@ -195,8 +208,7 @@  discard block
 block discarded – undo
195 208
 								$substitutionarray['__SECUREKEYPAYMENT_ORDER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
196 209
 								$substitutionarray['__SECUREKEYPAYMENT_INVOICE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
197 210
 								$substitutionarray['__SECUREKEYPAYMENT_CONTRACTLINE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
198
-							}
199
-							else
211
+							} else
200 212
 							{
201 213
 								$substitutionarray['__SECUREKEYPAYMENT_MEMBER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'membersubscription' . $obj->source_id, 2);
202 214
 								$substitutionarray['__SECUREKEYPAYMENT_ORDER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'order' . $obj->source_id, 2);
@@ -209,17 +221,29 @@  discard block
 block discarded – undo
209 221
 						{
210 222
 							$substitutionarray['__SECUREKEYPAYPAL__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
211 223
 
212
-							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_MEMBER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
213
-							else $substitutionarray['__SECUREKEYPAYPAL_MEMBER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'membersubscription' . $obj->source_id, 2);
224
+							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) {
225
+							    $substitutionarray['__SECUREKEYPAYPAL_MEMBER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
226
+							} else {
227
+							    $substitutionarray['__SECUREKEYPAYPAL_MEMBER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'membersubscription' . $obj->source_id, 2);
228
+							}
214 229
 
215
-							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_ORDER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
216
-							else $substitutionarray['__SECUREKEYPAYPAL_ORDER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'order' . $obj->source_id, 2);
230
+							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) {
231
+							    $substitutionarray['__SECUREKEYPAYPAL_ORDER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
232
+							} else {
233
+							    $substitutionarray['__SECUREKEYPAYPAL_ORDER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'order' . $obj->source_id, 2);
234
+							}
217 235
 
218
-							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_INVOICE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
219
-							else $substitutionarray['__SECUREKEYPAYPAL_INVOICE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'invoice' . $obj->source_id, 2);
236
+							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) {
237
+							    $substitutionarray['__SECUREKEYPAYPAL_INVOICE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
238
+							} else {
239
+							    $substitutionarray['__SECUREKEYPAYPAL_INVOICE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'invoice' . $obj->source_id, 2);
240
+							}
220 241
 
221
-							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
222
-							else $substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'contractline' . $obj->source_id, 2);
242
+							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) {
243
+							    $substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
244
+							} else {
245
+							    $substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'contractline' . $obj->source_id, 2);
246
+							}
223 247
 						}
224 248
 
225 249
 						complete_substitutions_array($substitutionarray,$langs);
@@ -297,8 +321,7 @@  discard block
 block discarded – undo
297 321
 							{
298 322
 								dol_print_error($db);
299 323
 								$error++;
300
-							}
301
-							else
324
+							} else
302 325
 							{
303 326
 								//if cheack read is use then update prospect contact status
304 327
 								if (strpos($message, '__CHECK_READ__') !== false)
@@ -329,8 +352,7 @@  discard block
 block discarded – undo
329 352
 									sleep($conf->global->MAILING_DELAY);
330 353
 								}
331 354
 							}
332
-						}
333
-						else
355
+						} else
334 356
 						{
335 357
 							// Mail failed
336 358
 							$nbko++;
@@ -349,8 +371,7 @@  discard block
 block discarded – undo
349 371
 
350 372
 						$i++;
351 373
 					}
352
-				}
353
-				else
374
+				} else
354 375
 				{
355 376
 					$mesg="Emailing id ".$id." has no recipient to target";
356 377
 					print $mesg."\n";
@@ -359,7 +380,9 @@  discard block
 block discarded – undo
359 380
 
360 381
 				// Loop finished, set global statut of mail
361 382
 				$statut=2;
362
-				if (! $nbko) $statut=3;
383
+				if (! $nbko) {
384
+				    $statut=3;
385
+				}
363 386
 
364 387
 				$sqlenddate="UPDATE ".MAIN_DB_PREFIX."mailing SET statut=".$statut." WHERE rowid=".$id;
365 388
 
@@ -371,23 +394,20 @@  discard block
 block discarded – undo
371 394
 					dol_print_error($db);
372 395
 					$error++;
373 396
 				}
374
-			}
375
-			else
397
+			} else
376 398
 			{
377 399
 				dol_print_error($db);
378 400
 				$error++;
379 401
 			}
380 402
 		}
381
-	}
382
-	else
403
+	} else
383 404
 	{
384 405
 		$mesg="No validated emailing id to send found.";
385 406
 		print $mesg."\n";
386 407
 		dol_syslog($mesg,LOG_ERR);
387 408
 		$error++;
388 409
 	}
389
-}
390
-else
410
+} else
391 411
 {
392 412
 	dol_print_error($db);
393 413
 	$error++;
Please login to merge, or discard this patch.
dolibarr/scripts/accountancy/export-thirdpartyaccount.php 3 patches
Indentation   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -38,13 +38,13 @@  discard block
 block discarded – undo
38 38
 // Date range
39 39
 $year = GETPOST("year");
40 40
 if (empty($year)) {
41
-	$year_current = strftime("%Y", dol_now());
42
-	$month_current = strftime("%m", dol_now());
43
-	$year_start = $year_current;
41
+    $year_current = strftime("%Y", dol_now());
42
+    $month_current = strftime("%m", dol_now());
43
+    $year_start = $year_current;
44 44
 } else {
45
-	$year_current = $year;
46
-	$month_current = strftime("%m", dol_now());
47
-	$year_start = $year;
45
+    $year_current = $year;
46
+    $month_current = strftime("%m", dol_now());
47
+    $year_start = $year;
48 48
 }
49 49
 $date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
50 50
 $date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
@@ -52,42 +52,42 @@  discard block
 block discarded – undo
52 52
 // Quarter
53 53
 if (empty($date_start) || empty($date_end)) // We define date_start and date_end
54 54
 {
55
-	$q = GETPOST("q") ? GETPOST("q") : 0;
56
-	if ($q == 0) {
57
-		// We define date_start and date_end
58
-		$year_end = $year_start;
59
-		$month_start = GETPOST("month") ? GETPOST("month") : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
60
-		if (! GETPOST('month')) {
61
-			if (! GETPOST("year") && $month_start > $month_current) {
62
-				$year_start --;
63
-				$year_end --;
64
-			}
65
-			$month_end = $month_start - 1;
66
-			if ($month_end < 1)
67
-				$month_end = 12;
68
-			else
69
-				$year_end ++;
70
-		} else
71
-			$month_end = $month_start;
72
-		$date_start = dol_get_first_day($year_start, $month_start, false);
73
-		$date_end = dol_get_last_day($year_end, $month_end, false);
74
-	}
75
-	if ($q == 1) {
76
-		$date_start = dol_get_first_day($year_start, 1, false);
77
-		$date_end = dol_get_last_day($year_start, 3, false);
78
-	}
79
-	if ($q == 2) {
80
-		$date_start = dol_get_first_day($year_start, 4, false);
81
-		$date_end = dol_get_last_day($year_start, 6, false);
82
-	}
83
-	if ($q == 3) {
84
-		$date_start = dol_get_first_day($year_start, 7, false);
85
-		$date_end = dol_get_last_day($year_start, 9, false);
86
-	}
87
-	if ($q == 4) {
88
-		$date_start = dol_get_first_day($year_start, 10, false);
89
-		$date_end = dol_get_last_day($year_start, 12, false);
90
-	}
55
+    $q = GETPOST("q") ? GETPOST("q") : 0;
56
+    if ($q == 0) {
57
+        // We define date_start and date_end
58
+        $year_end = $year_start;
59
+        $month_start = GETPOST("month") ? GETPOST("month") : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
60
+        if (! GETPOST('month')) {
61
+            if (! GETPOST("year") && $month_start > $month_current) {
62
+                $year_start --;
63
+                $year_end --;
64
+            }
65
+            $month_end = $month_start - 1;
66
+            if ($month_end < 1)
67
+                $month_end = 12;
68
+            else
69
+                $year_end ++;
70
+        } else
71
+            $month_end = $month_start;
72
+        $date_start = dol_get_first_day($year_start, $month_start, false);
73
+        $date_end = dol_get_last_day($year_end, $month_end, false);
74
+    }
75
+    if ($q == 1) {
76
+        $date_start = dol_get_first_day($year_start, 1, false);
77
+        $date_end = dol_get_last_day($year_start, 3, false);
78
+    }
79
+    if ($q == 2) {
80
+        $date_start = dol_get_first_day($year_start, 4, false);
81
+        $date_end = dol_get_last_day($year_start, 6, false);
82
+    }
83
+    if ($q == 3) {
84
+        $date_start = dol_get_first_day($year_start, 7, false);
85
+        $date_end = dol_get_last_day($year_start, 9, false);
86
+    }
87
+    if ($q == 4) {
88
+        $date_start = dol_get_first_day($year_start, 10, false);
89
+        $date_end = dol_get_last_day($year_start, 12, false);
90
+    }
91 91
 } else {
92 92
 }
93 93
 
@@ -127,10 +127,10 @@  discard block
 block discarded – undo
127 127
 $sql .= " WHERE f.fk_soc = s.rowid";
128 128
 $sql .= " AND s.fk_pays = cp.rowid";
129 129
 if (! empty($date_start) && ! empty($date_end))
130
-	$sql .= " AND f.datec >= '" . $db->idate($date_start) . "' AND f.datec <= '" . $db->idate($date_end) . "'";
130
+    $sql .= " AND f.datec >= '" . $db->idate($date_start) . "' AND f.datec <= '" . $db->idate($date_end) . "'";
131 131
 $sql .= " AND f.entity = " . $conf->entity;
132 132
 if ($socid)
133
-	$sql .= " AND f.fk_soc = " . $socid;
133
+    $sql .= " AND f.fk_soc = " . $socid;
134 134
 $sql .= " GROUP BY name";
135 135
 $sql .= ")";
136 136
 $sql .= "UNION (SELECT s.rowid, s.nom as name , s.address, s.zip , s.town, s.code_compta_fournisseur as compta , ";
@@ -141,10 +141,10 @@  discard block
 block discarded – undo
141 141
 $sql .= " WHERE ff.fk_soc = s.rowid";
142 142
 $sql .= " AND s.fk_pays = cp.rowid";
143 143
 if (! empty($date_start) && ! empty($date_end))
144
-	$sql .= " AND ff.datec >= '" . $db->idate($date_start) . "' AND ff.datec <= '" . $db->idate($date_end) . "'";
144
+    $sql .= " AND ff.datec >= '" . $db->idate($date_start) . "' AND ff.datec <= '" . $db->idate($date_end) . "'";
145 145
 $sql .= " AND ff.entity = " . $conf->entity;
146 146
 if ($socid)
147
-	$sql .= " AND f.fk_soc = " . $socid;
147
+    $sql .= " AND f.fk_soc = " . $socid;
148 148
 $sql .= " GROUP BY name";
149 149
 $sql .= ")";
150 150
 
@@ -153,81 +153,81 @@  discard block
 block discarded – undo
153 153
 dol_syslog('accountancy/admin/thirdpartyaccount.php:: $sql=' . $sql);
154 154
 $resql = $db->query($sql);
155 155
 if ($resql) {
156
-	$num = $db->num_rows($resql);
157
-	$i = 0;
156
+    $num = $db->num_rows($resql);
157
+    $i = 0;
158 158
 
159
-	// export csv
160
-	if (GETPOST('action','aZ09') == 'export_csv') {
159
+    // export csv
160
+    if (GETPOST('action','aZ09') == 'export_csv') {
161 161
 
162
-		header('Content-Type: text/csv');
163
-		header('Content-Disposition: attachment;filename=export_csv.csv');
162
+        header('Content-Type: text/csv');
163
+        header('Content-Disposition: attachment;filename=export_csv.csv');
164 164
 
165
-		$obj = $db->fetch_object($resql);
165
+        $obj = $db->fetch_object($resql);
166 166
 
167
-		print '"' . $obj->compta . '",';
168
-		print '"' . $obj->address . '",';
169
-		print '"' . $obj->zip . '",';
170
-		print '"' . $obj->town . '",';
171
-		print '"' . $obj->country . '",';
172
-		print '"' . $obj->phone . '",';
173
-		print '"' . $obj->fax . '",';
174
-		print "\n";
175
-		$i ++;
176
-	}
167
+        print '"' . $obj->compta . '",';
168
+        print '"' . $obj->address . '",';
169
+        print '"' . $obj->zip . '",';
170
+        print '"' . $obj->town . '",';
171
+        print '"' . $obj->country . '",';
172
+        print '"' . $obj->phone . '",';
173
+        print '"' . $obj->fax . '",';
174
+        print "\n";
175
+        $i ++;
176
+    }
177 177
 
178
-	/*
178
+    /*
179 179
 	 * View
180 180
 	 */
181 181
 
182
-	$thirdpartystatic = new Societe($db);
183
-
184
-	print '<br><br>';
185
-
186
-	print '<table class="noborder" width="100%">';
187
-	print "</table>\n";
188
-	print '</td><td valign="top" width="70%" class="notopnoleftnoright"></td>';
189
-	print '</tr><tr><td colspan=2>';
190
-	print '<table class="noborder" width="100%">';
191
-	print '<tr class="liste_titre"><td align="left">' . $langs->trans("ThirdParties") . '</td>';
192
-	print '<td align="left">' . $langs->trans("AccountNumber") . '</td>';
193
-	print '<td align="left">' . $langs->trans("RaisonSociale") . '</td>';
194
-	print '<td align="left">' . $langs->trans("Address") . '</td>';
195
-	print '<td align="left">' . $langs->trans("Zip") . '</td>';
196
-	print '<td align="left">' . $langs->trans("Town") . '</td>';
197
-	print '<td align="left">' . $langs->trans("Country") . '</td>';
198
-	print '<td align="left">' . $langs->trans("Contact") . '</td>';
199
-	print '<td align="left">' . $langs->trans("Phone") . '</td>';
200
-	print '<td align="left">' . $langs->trans("Fax") . '</td></tr>';
201
-
202
-	while ($obj = $db->fetch_object($resql))
203
-	{
204
-		print '<tr class="oddeven">';
205
-		print '<td>';
206
-		$thirdpartystatic->id = $obj->rowid;
207
-		$thirdpartystatic->name = $obj->name;
208
-		$thirdpartystatic->client = $obj->client;
209
-		$thirdpartystatic->canvas = $obj->canvas;
210
-		$thirdpartystatic->status = $obj->status;
211
-		print $thirdpartystatic->getNomUrl(1);
212
-		print '</td>';
213
-		print '<td align="left">' . $obj->compta . '</td>' . "\n";
214
-		print '<td align="left"></td>';
215
-		print '<td align="left">' . $obj->address . '</td>';
216
-		print '<td align="left">' . $obj->zip . '</td>';
217
-		print '<td align="left">' . $obj->town . '</td>';
218
-		print '<td align="left">' . $obj->country . '</td>';
219
-		print '<td align="left"></td>';
220
-		print '<td align="left">' . $obj->phone . '</td>';
221
-		print '<td align="left">' . $obj->fax . '</td>';
222
-		print "</tr>\n";
223
-
224
-		$i ++;
225
-	}
226
-
227
-	print "</table>";
228
-	$db->free($resql);
182
+    $thirdpartystatic = new Societe($db);
183
+
184
+    print '<br><br>';
185
+
186
+    print '<table class="noborder" width="100%">';
187
+    print "</table>\n";
188
+    print '</td><td valign="top" width="70%" class="notopnoleftnoright"></td>';
189
+    print '</tr><tr><td colspan=2>';
190
+    print '<table class="noborder" width="100%">';
191
+    print '<tr class="liste_titre"><td align="left">' . $langs->trans("ThirdParties") . '</td>';
192
+    print '<td align="left">' . $langs->trans("AccountNumber") . '</td>';
193
+    print '<td align="left">' . $langs->trans("RaisonSociale") . '</td>';
194
+    print '<td align="left">' . $langs->trans("Address") . '</td>';
195
+    print '<td align="left">' . $langs->trans("Zip") . '</td>';
196
+    print '<td align="left">' . $langs->trans("Town") . '</td>';
197
+    print '<td align="left">' . $langs->trans("Country") . '</td>';
198
+    print '<td align="left">' . $langs->trans("Contact") . '</td>';
199
+    print '<td align="left">' . $langs->trans("Phone") . '</td>';
200
+    print '<td align="left">' . $langs->trans("Fax") . '</td></tr>';
201
+
202
+    while ($obj = $db->fetch_object($resql))
203
+    {
204
+        print '<tr class="oddeven">';
205
+        print '<td>';
206
+        $thirdpartystatic->id = $obj->rowid;
207
+        $thirdpartystatic->name = $obj->name;
208
+        $thirdpartystatic->client = $obj->client;
209
+        $thirdpartystatic->canvas = $obj->canvas;
210
+        $thirdpartystatic->status = $obj->status;
211
+        print $thirdpartystatic->getNomUrl(1);
212
+        print '</td>';
213
+        print '<td align="left">' . $obj->compta . '</td>' . "\n";
214
+        print '<td align="left"></td>';
215
+        print '<td align="left">' . $obj->address . '</td>';
216
+        print '<td align="left">' . $obj->zip . '</td>';
217
+        print '<td align="left">' . $obj->town . '</td>';
218
+        print '<td align="left">' . $obj->country . '</td>';
219
+        print '<td align="left"></td>';
220
+        print '<td align="left">' . $obj->phone . '</td>';
221
+        print '<td align="left">' . $obj->fax . '</td>';
222
+        print "</tr>\n";
223
+
224
+        $i ++;
225
+    }
226
+
227
+    print "</table>";
228
+    $db->free($resql);
229 229
 } else {
230
-	dol_print_error($db);
230
+    dol_print_error($db);
231 231
 }
232 232
 
233 233
 llxFooter();
Please login to merge, or discard this patch.
Spacing   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -57,16 +57,16 @@  discard block
 block discarded – undo
57 57
 		// We define date_start and date_end
58 58
 		$year_end = $year_start;
59 59
 		$month_start = GETPOST("month") ? GETPOST("month") : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
60
-		if (! GETPOST('month')) {
61
-			if (! GETPOST("year") && $month_start > $month_current) {
62
-				$year_start --;
63
-				$year_end --;
60
+		if (!GETPOST('month')) {
61
+			if (!GETPOST("year") && $month_start > $month_current) {
62
+				$year_start--;
63
+				$year_end--;
64 64
 			}
65 65
 			$month_end = $month_start - 1;
66 66
 			if ($month_end < 1)
67 67
 				$month_end = 12;
68 68
 			else
69
-				$year_end ++;
69
+				$year_end++;
70 70
 		} else
71 71
 			$month_end = $month_start;
72 72
 		$date_start = dol_get_first_day($year_start, $month_start, false);
@@ -100,11 +100,11 @@  discard block
 block discarded – undo
100 100
 $exportlink = '';
101 101
 
102 102
 $nom = $langs->trans("ReportThirdParty");
103
-$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0) . ' - ' . $form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
103
+$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
104 104
 $description = $langs->trans("DescThirdPartyReport");
105
-$builddate=dol_now();
105
+$builddate = dol_now();
106 106
 
107
-$moreparam=array('action' => '');
107
+$moreparam = array('action' => '');
108 108
 report_header($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, $moreparam);
109 109
 
110 110
 print '<input type="button" class="button" style="float: right;" value="Export CSV" onclick="launch_export();" />';
@@ -121,58 +121,58 @@  discard block
 block discarded – undo
121 121
 
122 122
 $sql = "(SELECT s.rowid, s.nom as name , s.address, s.zip , s.town, s.code_compta as compta , ";
123 123
 $sql .= " s.fk_forme_juridique , s.fk_pays , s.phone , s.fax ,   f.datec , f.fk_soc , cp.label as country ";
124
-$sql .= " FROM " . MAIN_DB_PREFIX . "societe as s";
125
-$sql .= ", " . MAIN_DB_PREFIX . "facture as f";
126
-$sql .= ", " . MAIN_DB_PREFIX . "c_country as cp";
124
+$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
125
+$sql .= ", ".MAIN_DB_PREFIX."facture as f";
126
+$sql .= ", ".MAIN_DB_PREFIX."c_country as cp";
127 127
 $sql .= " WHERE f.fk_soc = s.rowid";
128 128
 $sql .= " AND s.fk_pays = cp.rowid";
129
-if (! empty($date_start) && ! empty($date_end))
130
-	$sql .= " AND f.datec >= '" . $db->idate($date_start) . "' AND f.datec <= '" . $db->idate($date_end) . "'";
131
-$sql .= " AND f.entity = " . $conf->entity;
129
+if (!empty($date_start) && !empty($date_end))
130
+	$sql .= " AND f.datec >= '".$db->idate($date_start)."' AND f.datec <= '".$db->idate($date_end)."'";
131
+$sql .= " AND f.entity = ".$conf->entity;
132 132
 if ($socid)
133
-	$sql .= " AND f.fk_soc = " . $socid;
133
+	$sql .= " AND f.fk_soc = ".$socid;
134 134
 $sql .= " GROUP BY name";
135 135
 $sql .= ")";
136 136
 $sql .= "UNION (SELECT s.rowid, s.nom as name , s.address, s.zip , s.town, s.code_compta_fournisseur as compta , ";
137 137
 $sql .= " s.fk_forme_juridique , s.fk_pays , s.phone , s.fax ,   ff.datec , ff.fk_soc , cp.label as country ";
138
-$sql .= " FROM " . MAIN_DB_PREFIX . "societe as s";
139
-$sql .= ", " . MAIN_DB_PREFIX . "facture_fourn as ff";
140
-$sql .= ", " . MAIN_DB_PREFIX . "c_country as cp";
138
+$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
139
+$sql .= ", ".MAIN_DB_PREFIX."facture_fourn as ff";
140
+$sql .= ", ".MAIN_DB_PREFIX."c_country as cp";
141 141
 $sql .= " WHERE ff.fk_soc = s.rowid";
142 142
 $sql .= " AND s.fk_pays = cp.rowid";
143
-if (! empty($date_start) && ! empty($date_end))
144
-	$sql .= " AND ff.datec >= '" . $db->idate($date_start) . "' AND ff.datec <= '" . $db->idate($date_end) . "'";
145
-$sql .= " AND ff.entity = " . $conf->entity;
143
+if (!empty($date_start) && !empty($date_end))
144
+	$sql .= " AND ff.datec >= '".$db->idate($date_start)."' AND ff.datec <= '".$db->idate($date_end)."'";
145
+$sql .= " AND ff.entity = ".$conf->entity;
146 146
 if ($socid)
147
-	$sql .= " AND f.fk_soc = " . $socid;
147
+	$sql .= " AND f.fk_soc = ".$socid;
148 148
 $sql .= " GROUP BY name";
149 149
 $sql .= ")";
150 150
 
151 151
 $sql .= "ORDER BY name ASC";
152 152
 
153
-dol_syslog('accountancy/admin/thirdpartyaccount.php:: $sql=' . $sql);
153
+dol_syslog('accountancy/admin/thirdpartyaccount.php:: $sql='.$sql);
154 154
 $resql = $db->query($sql);
155 155
 if ($resql) {
156 156
 	$num = $db->num_rows($resql);
157 157
 	$i = 0;
158 158
 
159 159
 	// export csv
160
-	if (GETPOST('action','aZ09') == 'export_csv') {
160
+	if (GETPOST('action', 'aZ09') == 'export_csv') {
161 161
 
162 162
 		header('Content-Type: text/csv');
163 163
 		header('Content-Disposition: attachment;filename=export_csv.csv');
164 164
 
165 165
 		$obj = $db->fetch_object($resql);
166 166
 
167
-		print '"' . $obj->compta . '",';
168
-		print '"' . $obj->address . '",';
169
-		print '"' . $obj->zip . '",';
170
-		print '"' . $obj->town . '",';
171
-		print '"' . $obj->country . '",';
172
-		print '"' . $obj->phone . '",';
173
-		print '"' . $obj->fax . '",';
167
+		print '"'.$obj->compta.'",';
168
+		print '"'.$obj->address.'",';
169
+		print '"'.$obj->zip.'",';
170
+		print '"'.$obj->town.'",';
171
+		print '"'.$obj->country.'",';
172
+		print '"'.$obj->phone.'",';
173
+		print '"'.$obj->fax.'",';
174 174
 		print "\n";
175
-		$i ++;
175
+		$i++;
176 176
 	}
177 177
 
178 178
 	/*
@@ -188,16 +188,16 @@  discard block
 block discarded – undo
188 188
 	print '</td><td valign="top" width="70%" class="notopnoleftnoright"></td>';
189 189
 	print '</tr><tr><td colspan=2>';
190 190
 	print '<table class="noborder" width="100%">';
191
-	print '<tr class="liste_titre"><td align="left">' . $langs->trans("ThirdParties") . '</td>';
192
-	print '<td align="left">' . $langs->trans("AccountNumber") . '</td>';
193
-	print '<td align="left">' . $langs->trans("RaisonSociale") . '</td>';
194
-	print '<td align="left">' . $langs->trans("Address") . '</td>';
195
-	print '<td align="left">' . $langs->trans("Zip") . '</td>';
196
-	print '<td align="left">' . $langs->trans("Town") . '</td>';
197
-	print '<td align="left">' . $langs->trans("Country") . '</td>';
198
-	print '<td align="left">' . $langs->trans("Contact") . '</td>';
199
-	print '<td align="left">' . $langs->trans("Phone") . '</td>';
200
-	print '<td align="left">' . $langs->trans("Fax") . '</td></tr>';
191
+	print '<tr class="liste_titre"><td align="left">'.$langs->trans("ThirdParties").'</td>';
192
+	print '<td align="left">'.$langs->trans("AccountNumber").'</td>';
193
+	print '<td align="left">'.$langs->trans("RaisonSociale").'</td>';
194
+	print '<td align="left">'.$langs->trans("Address").'</td>';
195
+	print '<td align="left">'.$langs->trans("Zip").'</td>';
196
+	print '<td align="left">'.$langs->trans("Town").'</td>';
197
+	print '<td align="left">'.$langs->trans("Country").'</td>';
198
+	print '<td align="left">'.$langs->trans("Contact").'</td>';
199
+	print '<td align="left">'.$langs->trans("Phone").'</td>';
200
+	print '<td align="left">'.$langs->trans("Fax").'</td></tr>';
201 201
 
202 202
 	while ($obj = $db->fetch_object($resql))
203 203
 	{
@@ -210,18 +210,18 @@  discard block
 block discarded – undo
210 210
 		$thirdpartystatic->status = $obj->status;
211 211
 		print $thirdpartystatic->getNomUrl(1);
212 212
 		print '</td>';
213
-		print '<td align="left">' . $obj->compta . '</td>' . "\n";
213
+		print '<td align="left">'.$obj->compta.'</td>'."\n";
214 214
 		print '<td align="left"></td>';
215
-		print '<td align="left">' . $obj->address . '</td>';
216
-		print '<td align="left">' . $obj->zip . '</td>';
217
-		print '<td align="left">' . $obj->town . '</td>';
218
-		print '<td align="left">' . $obj->country . '</td>';
215
+		print '<td align="left">'.$obj->address.'</td>';
216
+		print '<td align="left">'.$obj->zip.'</td>';
217
+		print '<td align="left">'.$obj->town.'</td>';
218
+		print '<td align="left">'.$obj->country.'</td>';
219 219
 		print '<td align="left"></td>';
220
-		print '<td align="left">' . $obj->phone . '</td>';
221
-		print '<td align="left">' . $obj->fax . '</td>';
220
+		print '<td align="left">'.$obj->phone.'</td>';
221
+		print '<td align="left">'.$obj->fax.'</td>';
222 222
 		print "</tr>\n";
223 223
 
224
-		$i ++;
224
+		$i++;
225 225
 	}
226 226
 
227 227
 	print "</table>";
Please login to merge, or discard this patch.
Braces   +21 added lines, -12 removed lines patch added patch discarded remove patch
@@ -32,8 +32,9 @@  discard block
 block discarded – undo
32 32
 $langs->loadLangs(array("companies", "compta", "main", "accountancy"));
33 33
 
34 34
 // Security check
35
-if (!$user->admin)
35
+if (!$user->admin) {
36 36
     accessforbidden();
37
+}
37 38
 
38 39
 // Date range
39 40
 $year = GETPOST("year");
@@ -50,9 +51,11 @@  discard block
 block discarded – undo
50 51
 $date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
51 52
 
52 53
 // Quarter
53
-if (empty($date_start) || empty($date_end)) // We define date_start and date_end
54
+if (empty($date_start) || empty($date_end)) {
55
+    // We define date_start and date_end
54 56
 {
55 57
 	$q = GETPOST("q") ? GETPOST("q") : 0;
58
+}
56 59
 	if ($q == 0) {
57 60
 		// We define date_start and date_end
58 61
 		$year_end = $year_start;
@@ -63,12 +66,14 @@  discard block
 block discarded – undo
63 66
 				$year_end --;
64 67
 			}
65 68
 			$month_end = $month_start - 1;
66
-			if ($month_end < 1)
67
-				$month_end = 12;
68
-			else
69
-				$year_end ++;
70
-		} else
71
-			$month_end = $month_start;
69
+			if ($month_end < 1) {
70
+							$month_end = 12;
71
+			} else {
72
+							$year_end ++;
73
+			}
74
+		} else {
75
+					$month_end = $month_start;
76
+		}
72 77
 		$date_start = dol_get_first_day($year_start, $month_start, false);
73 78
 		$date_end = dol_get_last_day($year_end, $month_end, false);
74 79
 	}
@@ -126,11 +131,13 @@  discard block
 block discarded – undo
126 131
 $sql .= ", " . MAIN_DB_PREFIX . "c_country as cp";
127 132
 $sql .= " WHERE f.fk_soc = s.rowid";
128 133
 $sql .= " AND s.fk_pays = cp.rowid";
129
-if (! empty($date_start) && ! empty($date_end))
134
+if (! empty($date_start) && ! empty($date_end)) {
130 135
 	$sql .= " AND f.datec >= '" . $db->idate($date_start) . "' AND f.datec <= '" . $db->idate($date_end) . "'";
136
+}
131 137
 $sql .= " AND f.entity = " . $conf->entity;
132
-if ($socid)
138
+if ($socid) {
133 139
 	$sql .= " AND f.fk_soc = " . $socid;
140
+}
134 141
 $sql .= " GROUP BY name";
135 142
 $sql .= ")";
136 143
 $sql .= "UNION (SELECT s.rowid, s.nom as name , s.address, s.zip , s.town, s.code_compta_fournisseur as compta , ";
@@ -140,11 +147,13 @@  discard block
 block discarded – undo
140 147
 $sql .= ", " . MAIN_DB_PREFIX . "c_country as cp";
141 148
 $sql .= " WHERE ff.fk_soc = s.rowid";
142 149
 $sql .= " AND s.fk_pays = cp.rowid";
143
-if (! empty($date_start) && ! empty($date_end))
150
+if (! empty($date_start) && ! empty($date_end)) {
144 151
 	$sql .= " AND ff.datec >= '" . $db->idate($date_start) . "' AND ff.datec <= '" . $db->idate($date_end) . "'";
152
+}
145 153
 $sql .= " AND ff.entity = " . $conf->entity;
146
-if ($socid)
154
+if ($socid) {
147 155
 	$sql .= " AND f.fk_soc = " . $socid;
156
+}
148 157
 $sql .= " GROUP BY name";
149 158
 $sql .= ")";
150 159
 
Please login to merge, or discard this patch.
dolibarr/scripts/withdrawals/build_withdrawal_file.php 2 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -30,8 +30,8 @@  discard block
 block discarded – undo
30 30
 
31 31
 // Test if batch mode
32 32
 if (substr($sapi_type, 0, 3) == 'cgi') {
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);
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);
35 35
 }
36 36
 
37 37
 require_once $path."../../htdocs/master.inc.php";
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 if (! isset($argv[1])) {	// Check parameters
65 65
     print "This script check invoices with a withdrawal request and\n";
66 66
     print "then create payment and build a withdraw file.\n";
67
-	print "Usage: ".$script_file." simu|real\n";
67
+    print "Usage: ".$script_file." simu|real\n";
68 68
     exit(-1);
69 69
 }
70 70
 
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 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') {
@@ -41,8 +41,8 @@  discard block
 block discarded – undo
41 41
 require_once DOL_DOCUMENT_ROOT."/compta/paiement/class/paiement.class.php";
42 42
 
43 43
 // Global variables
44
-$version=DOL_VERSION;
45
-$error=0;
44
+$version = DOL_VERSION;
45
+$error = 0;
46 46
 
47 47
 
48 48
 /*
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 
52 52
 @set_time_limit(0);
53 53
 print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
54
-dol_syslog($script_file." launched with arg ".join(',',$argv));
54
+dol_syslog($script_file." launched with arg ".join(',', $argv));
55 55
 
56 56
 $datetimeprev = dol_now();
57 57
 
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 $user = new user($db);
62 62
 $user->fetch($conf->global->PRELEVEMENT_USER);
63 63
 
64
-if (! isset($argv[1])) {	// Check parameters
64
+if (!isset($argv[1])) {	// Check parameters
65 65
     print "This script check invoices with a withdrawal request and\n";
66 66
     print "then create payment and build a withdraw file.\n";
67 67
 	print "Usage: ".$script_file." simu|real\n";
@@ -69,9 +69,9 @@  discard block
 block discarded – undo
69 69
 }
70 70
 
71 71
 
72
-$withdrawreceipt=new BonPrelevement($db);
72
+$withdrawreceipt = new BonPrelevement($db);
73 73
 // $conf->global->PRELEVEMENT_CODE_BANQUE and $conf->global->PRELEVEMENT_CODE_GUICHET should be empty
74
-$result=$withdrawreceipt->create($conf->global->PRELEVEMENT_CODE_BANQUE,$conf->global->PRELEVEMENT_CODE_GUICHET,$argv[1]);
74
+$result = $withdrawreceipt->create($conf->global->PRELEVEMENT_CODE_BANQUE, $conf->global->PRELEVEMENT_CODE_GUICHET, $argv[1]);
75 75
 
76 76
 
77 77
 $db->close();
Please login to merge, or discard this patch.
dolibarr/scripts/cron/cron_run_jobs.php 3 patches
Indentation   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -37,8 +37,8 @@  discard block
 block discarded – undo
37 37
 
38 38
 // Test if batch mode
39 39
 if (substr($sapi_type, 0, 3) == 'cgi') {
40
-	echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
41
-	exit(-1);
40
+    echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
41
+    exit(-1);
42 42
 }
43 43
 
44 44
 require_once $path."../../htdocs/master.inc.php";
@@ -47,14 +47,14 @@  discard block
 block discarded – undo
47 47
 
48 48
 // Check parameters
49 49
 if (! isset($argv[1]) || ! $argv[1]) {
50
-	usage($path,$script_file);
51
-	exit(-1);
50
+    usage($path,$script_file);
51
+    exit(-1);
52 52
 }
53 53
 $key=$argv[1];
54 54
 
55 55
 if (! isset($argv[2]) || ! $argv[2]) {
56
-	usage($path,$script_file);
57
-	exit(-1);
56
+    usage($path,$script_file);
57
+    exit(-1);
58 58
 }
59 59
 
60 60
 $userlogin=$argv[2];
@@ -78,22 +78,22 @@  discard block
 block discarded – undo
78 78
 // Check module cron is activated
79 79
 if (empty($conf->cron->enabled))
80 80
 {
81
-	print "Error: module Scheduled jobs (cron) not activated\n";
82
-	exit(-1);
81
+    print "Error: module Scheduled jobs (cron) not activated\n";
82
+    exit(-1);
83 83
 }
84 84
 
85 85
 // Check module cron is activated
86 86
 if (empty($conf->cron->enabled))
87 87
 {
88
-	print "Error: module Scheduled jobs (cron) not activated\n";
89
-	exit(-1);
88
+    print "Error: module Scheduled jobs (cron) not activated\n";
89
+    exit(-1);
90 90
 }
91 91
 
92 92
 // Check security key
93 93
 if ($key != $conf->global->CRON_KEY)
94 94
 {
95
-	print "Error: securitykey is wrong\n";
96
-	exit(-1);
95
+    print "Error: securitykey is wrong\n";
96
+    exit(-1);
97 97
 }
98 98
 
99 99
 // If param userlogin is reserved word 'firstadmin'
@@ -118,24 +118,24 @@  discard block
 block discarded – undo
118 118
 $result=$user->fetch('',$userlogin);
119 119
 if ($result < 0)
120 120
 {
121
-	echo "User Error: ".$user->error;
122
-	dol_syslog("cron_run_jobs.php:: User Error:".$user->error, LOG_ERR);
123
-	exit(-1);
121
+    echo "User Error: ".$user->error;
122
+    dol_syslog("cron_run_jobs.php:: User Error:".$user->error, LOG_ERR);
123
+    exit(-1);
124 124
 }
125 125
 else
126 126
 {
127
-	if (empty($user->id))
128
-	{
129
-		echo "User login: ".$userlogin." does not exists";
130
-		dol_syslog("User login:".$userlogin." does not exists", LOG_ERR);
131
-		exit(-1);
132
-	}
127
+    if (empty($user->id))
128
+    {
129
+        echo "User login: ".$userlogin." does not exists";
130
+        dol_syslog("User login:".$userlogin." does not exists", LOG_ERR);
131
+        exit(-1);
132
+    }
133 133
 }
134 134
 $user->getrights();
135 135
 
136 136
 if (isset($argv[3]) || $argv[3])
137 137
 {
138
-	$id = $argv[3];
138
+    $id = $argv[3];
139 139
 }
140 140
 
141 141
 // create a jobs object
@@ -143,29 +143,29 @@  discard block
 block discarded – undo
143 143
 
144 144
 $filter=array();
145 145
 if (! empty($id)) {
146
-	if (! is_numeric($id))
147
-	{
148
-		echo "Error: Bad value for parameter job id";
149
-		dol_syslog("cron_run_jobs.php Bad value for parameter job id", LOG_WARNING);
150
-		exit;
151
-	}
152
-	$filter['t.rowid']=$id;
146
+    if (! is_numeric($id))
147
+    {
148
+        echo "Error: Bad value for parameter job id";
149
+        dol_syslog("cron_run_jobs.php Bad value for parameter job id", LOG_WARNING);
150
+        exit;
151
+    }
152
+    $filter['t.rowid']=$id;
153 153
 }
154 154
 
155 155
 $result = $object->fetch_all('ASC,ASC,ASC','t.priority,t.entity,t.rowid', 0, 0, 1, $filter, 0);
156 156
 if ($result<0)
157 157
 {
158
-	echo "Error: ".$object->error;
159
-	dol_syslog("cron_run_jobs.php:: fetch Error ".$object->error, LOG_ERR);
160
-	exit(-1);
158
+    echo "Error: ".$object->error;
159
+    dol_syslog("cron_run_jobs.php:: fetch Error ".$object->error, LOG_ERR);
160
+    exit(-1);
161 161
 }
162 162
 
163 163
 
164 164
 $qualifiedjobs = array();
165 165
 foreach($object->lines as $val)
166 166
 {
167
-	if (! verifCond($val->test)) continue;
168
-	$qualifiedjobs[] = $val;
167
+    if (! verifCond($val->test)) continue;
168
+    $qualifiedjobs[] = $val;
169 169
 }
170 170
 
171 171
 // TODO Duplicate. This sequence of code must be shared with code into public/cron/cron_run_jobs.php php page.
@@ -176,69 +176,69 @@  discard block
 block discarded – undo
176 176
 
177 177
 if (is_array($qualifiedjobs) && (count($qualifiedjobs)>0))
178 178
 {
179
-	// Loop over job
180
-	foreach($qualifiedjobs as $line)
181
-	{
182
-		dol_syslog("cron_run_jobs.php cronjobid: ".$line->id." priority=".$line->priority." entity=".$line->entity." label=".$line->label, LOG_DEBUG);
183
-
184
-		echo "cron_run_jobs.php cronjobid: ".$line->id." priority=".$line->priority." entity=".$line->entity." label=".$line->label;
185
-
186
-		//If date_next_jobs is less of current date, execute the program, and store the execution time of the next execution in database
187
-		if (($line->datenextrun < $now) && (empty($line->datestart) || $line->datestart <= $now) && (empty($line->dateend) || $line->dateend >= $now))
188
-		{
189
-			echo " - qualified";
190
-
191
-			dol_syslog("cron_run_jobs.php line->datenextrun:".dol_print_date($line->datenextrun,'dayhourrfc')." line->datestart:".dol_print_date($line->datestart,'dayhourrfc')." line->dateend:".dol_print_date($line->dateend,'dayhourrfc')." now:".dol_print_date($now,'dayhourrfc'));
192
-
193
-			$cronjob=new Cronjob($db);
194
-			$result=$cronjob->fetch($line->id);
195
-			if ($result < 0)
196
-			{
197
-				echo "Error cronjobid: ".$line->id." cronjob->fetch: ".$cronjob->error."\n";
198
-				echo "Failed to fetch job ".$line->id."\n";
199
-				dol_syslog("cron_run_jobs.php::fetch Error ".$cronjob->error, LOG_ERR);
200
-				exit(-1);
201
-			}
202
-			// Execute job
203
-			$result=$cronjob->run_jobs($userlogin);
204
-			if ($result < 0)
205
-			{
206
-				echo "Error cronjobid: ".$line->id." cronjob->run_job: ".$cronjob->error."\n";
207
-				echo "At least one job failed. Go on menu Home-Setup-Admin tools to see result for each job.\n";
208
-				echo "You can also enable module Log if not yet enabled, run again and take a look into dolibarr.log file\n";
209
-				dol_syslog("cron_run_jobs.php::run_jobs Error ".$cronjob->error, LOG_ERR);
210
-				$nbofjobslaunchedko++;
211
-			}
212
-			else
213
-			{
214
-				$nbofjobslaunchedok++;
215
-			}
216
-
217
-			echo " - result of run_jobs = ".$result;
218
-
219
-			// we re-program the next execution and stores the last execution time for this job
220
-			$result=$cronjob->reprogram_jobs($userlogin, $now);
221
-			if ($result<0)
222
-			{
223
-				echo "Error cronjobid: ".$line->id." cronjob->reprogram_job: ".$cronjob->error."\n";
224
-				echo "Enable module Log if not yet enabled, run again and take a look into dolibarr.log file\n";
225
-				dol_syslog("cron_run_jobs.php::reprogram_jobs Error ".$cronjob->error, LOG_ERR);
226
-				exit(-1);
227
-			}
228
-
229
-			echo " - reprogrammed\n";
230
-		}
231
-		else
232
-		{
233
-			echo " - not qualified\n";
234
-
235
-			dol_syslog("cron_run_jobs.php job not qualified line->datenextrun:".dol_print_date($line->datenextrun,'dayhourrfc')." line->datestart:".dol_print_date($line->datestart,'dayhourrfc')." line->dateend:".dol_print_date($line->dateend,'dayhourrfc')." now:".dol_print_date($now,'dayhourrfc'));
236
-		}
237
-	}
179
+    // Loop over job
180
+    foreach($qualifiedjobs as $line)
181
+    {
182
+        dol_syslog("cron_run_jobs.php cronjobid: ".$line->id." priority=".$line->priority." entity=".$line->entity." label=".$line->label, LOG_DEBUG);
183
+
184
+        echo "cron_run_jobs.php cronjobid: ".$line->id." priority=".$line->priority." entity=".$line->entity." label=".$line->label;
185
+
186
+        //If date_next_jobs is less of current date, execute the program, and store the execution time of the next execution in database
187
+        if (($line->datenextrun < $now) && (empty($line->datestart) || $line->datestart <= $now) && (empty($line->dateend) || $line->dateend >= $now))
188
+        {
189
+            echo " - qualified";
190
+
191
+            dol_syslog("cron_run_jobs.php line->datenextrun:".dol_print_date($line->datenextrun,'dayhourrfc')." line->datestart:".dol_print_date($line->datestart,'dayhourrfc')." line->dateend:".dol_print_date($line->dateend,'dayhourrfc')." now:".dol_print_date($now,'dayhourrfc'));
192
+
193
+            $cronjob=new Cronjob($db);
194
+            $result=$cronjob->fetch($line->id);
195
+            if ($result < 0)
196
+            {
197
+                echo "Error cronjobid: ".$line->id." cronjob->fetch: ".$cronjob->error."\n";
198
+                echo "Failed to fetch job ".$line->id."\n";
199
+                dol_syslog("cron_run_jobs.php::fetch Error ".$cronjob->error, LOG_ERR);
200
+                exit(-1);
201
+            }
202
+            // Execute job
203
+            $result=$cronjob->run_jobs($userlogin);
204
+            if ($result < 0)
205
+            {
206
+                echo "Error cronjobid: ".$line->id." cronjob->run_job: ".$cronjob->error."\n";
207
+                echo "At least one job failed. Go on menu Home-Setup-Admin tools to see result for each job.\n";
208
+                echo "You can also enable module Log if not yet enabled, run again and take a look into dolibarr.log file\n";
209
+                dol_syslog("cron_run_jobs.php::run_jobs Error ".$cronjob->error, LOG_ERR);
210
+                $nbofjobslaunchedko++;
211
+            }
212
+            else
213
+            {
214
+                $nbofjobslaunchedok++;
215
+            }
216
+
217
+            echo " - result of run_jobs = ".$result;
218
+
219
+            // we re-program the next execution and stores the last execution time for this job
220
+            $result=$cronjob->reprogram_jobs($userlogin, $now);
221
+            if ($result<0)
222
+            {
223
+                echo "Error cronjobid: ".$line->id." cronjob->reprogram_job: ".$cronjob->error."\n";
224
+                echo "Enable module Log if not yet enabled, run again and take a look into dolibarr.log file\n";
225
+                dol_syslog("cron_run_jobs.php::reprogram_jobs Error ".$cronjob->error, LOG_ERR);
226
+                exit(-1);
227
+            }
228
+
229
+            echo " - reprogrammed\n";
230
+        }
231
+        else
232
+        {
233
+            echo " - not qualified\n";
234
+
235
+            dol_syslog("cron_run_jobs.php job not qualified line->datenextrun:".dol_print_date($line->datenextrun,'dayhourrfc')." line->datestart:".dol_print_date($line->datestart,'dayhourrfc')." line->dateend:".dol_print_date($line->dateend,'dayhourrfc')." now:".dol_print_date($now,'dayhourrfc'));
236
+        }
237
+    }
238 238
 }
239 239
 else
240 240
 {
241
-	echo "cron_run_jobs.php no qualified job found\n";
241
+    echo "cron_run_jobs.php no qualified job found\n";
242 242
 }
243 243
 
244 244
 $db->close();
@@ -257,14 +257,14 @@  discard block
 block discarded – undo
257 257
  */
258 258
 function usage($path,$script_file)
259 259
 {
260
-	global $conf;
261
-
262
-	print "Usage: ".$script_file." securitykey userlogin|'firstadmin' [cronjobid]\n";
263
-	print "The script return 0 when everything worked successfully.\n";
264
-	print "\n";
265
-	print "On Linux system, you can have cron jobs ran automatically by adding an entry into cron.\n";
266
-	print "For example, to run pending tasks each day at 3:30, you can add this line:\n";
267
-	print "30 3 * * * ".$path.$script_file." securitykey userlogin > ".DOL_DATA_ROOT."/".$script_file.".log\n";
268
-	print "For example, to run pending tasks every 5mn, you can add this line:\n";
269
-	print "*/5 * * * * ".$path.$script_file." securitykey userlogin > ".DOL_DATA_ROOT."/".$script_file.".log\n";
260
+    global $conf;
261
+
262
+    print "Usage: ".$script_file." securitykey userlogin|'firstadmin' [cronjobid]\n";
263
+    print "The script return 0 when everything worked successfully.\n";
264
+    print "\n";
265
+    print "On Linux system, you can have cron jobs ran automatically by adding an entry into cron.\n";
266
+    print "For example, to run pending tasks each day at 3:30, you can add this line:\n";
267
+    print "30 3 * * * ".$path.$script_file." securitykey userlogin > ".DOL_DATA_ROOT."/".$script_file.".log\n";
268
+    print "For example, to run pending tasks every 5mn, you can add this line:\n";
269
+    print "*/5 * * * * ".$path.$script_file." securitykey userlogin > ".DOL_DATA_ROOT."/".$script_file.".log\n";
270 270
 }
Please login to merge, or discard this patch.
Spacing   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -23,17 +23,17 @@  discard block
 block discarded – undo
23 23
  *  \ingroup    cron
24 24
  *  \brief      Execute pendings jobs
25 25
  */
26
-if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Disables token renewal
27
-if (! defined('NOREQUIREMENU'))  define('NOREQUIREMENU','1');
28
-if (! defined('NOREQUIREHTML'))  define('NOREQUIREHTML','1');
29
-if (! defined('NOREQUIREAJAX'))  define('NOREQUIREAJAX','1');
30
-if (! defined('NOLOGIN'))        define('NOLOGIN','1');
26
+if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Disables token renewal
27
+if (!defined('NOREQUIREMENU'))  define('NOREQUIREMENU', '1');
28
+if (!defined('NOREQUIREHTML'))  define('NOREQUIREHTML', '1');
29
+if (!defined('NOREQUIREAJAX'))  define('NOREQUIREAJAX', '1');
30
+if (!defined('NOLOGIN'))        define('NOLOGIN', '1');
31 31
 //if (! defined('NOREQUIRETRAN'))  define('NOREQUIRETRAN','1');
32 32
 
33 33
 
34 34
 $sapi_type = php_sapi_name();
35 35
 $script_file = basename(__FILE__);
36
-$path=dirname(__FILE__).'/';
36
+$path = dirname(__FILE__).'/';
37 37
 
38 38
 // Test if batch mode
39 39
 if (substr($sapi_type, 0, 3) == 'cgi') {
@@ -46,23 +46,23 @@  discard block
 block discarded – undo
46 46
 require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
47 47
 
48 48
 // Check parameters
49
-if (! isset($argv[1]) || ! $argv[1]) {
50
-	usage($path,$script_file);
49
+if (!isset($argv[1]) || !$argv[1]) {
50
+	usage($path, $script_file);
51 51
 	exit(-1);
52 52
 }
53
-$key=$argv[1];
53
+$key = $argv[1];
54 54
 
55
-if (! isset($argv[2]) || ! $argv[2]) {
56
-	usage($path,$script_file);
55
+if (!isset($argv[2]) || !$argv[2]) {
56
+	usage($path, $script_file);
57 57
 	exit(-1);
58 58
 }
59 59
 
60
-$userlogin=$argv[2];
60
+$userlogin = $argv[2];
61 61
 
62 62
 
63 63
 // Global variables
64
-$version=DOL_VERSION;
65
-$error=0;
64
+$version = DOL_VERSION;
65
+$error = 0;
66 66
 
67 67
 
68 68
 /*
@@ -70,10 +70,10 @@  discard block
 block discarded – undo
70 70
  */
71 71
 
72 72
 // current date
73
-$now=dol_now();
73
+$now = dol_now();
74 74
 
75 75
 @set_time_limit(0);
76
-print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." ***** userlogin=" . $userlogin . " ***** " . dol_print_date($now, 'dayhourrfc') . " *****\n";
76
+print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." ***** userlogin=".$userlogin." ***** ".dol_print_date($now, 'dayhourrfc')." *****\n";
77 77
 
78 78
 // Check module cron is activated
79 79
 if (empty($conf->cron->enabled))
@@ -99,11 +99,11 @@  discard block
 block discarded – undo
99 99
 // If param userlogin is reserved word 'firstadmin'
100 100
 if ($userlogin == 'firstadmin')
101 101
 {
102
-    $sql='SELECT login, entity from '.MAIN_DB_PREFIX.'user WHERE admin = 1 and statut = 1 ORDER BY entity LIMIT 1';
103
-    $resql=$db->query($sql);
102
+    $sql = 'SELECT login, entity from '.MAIN_DB_PREFIX.'user WHERE admin = 1 and statut = 1 ORDER BY entity LIMIT 1';
103
+    $resql = $db->query($sql);
104 104
     if ($resql)
105 105
     {
106
-        $obj=$db->fetch_object($resql);
106
+        $obj = $db->fetch_object($resql);
107 107
         if ($obj)
108 108
         {
109 109
             $userlogin = $obj->login;
@@ -114,8 +114,8 @@  discard block
 block discarded – undo
114 114
 }
115 115
 
116 116
 // Check user login
117
-$user=new User($db);
118
-$result=$user->fetch('',$userlogin);
117
+$user = new User($db);
118
+$result = $user->fetch('', $userlogin);
119 119
 if ($result < 0)
120 120
 {
121 121
 	echo "User Error: ".$user->error;
@@ -141,19 +141,19 @@  discard block
 block discarded – undo
141 141
 // create a jobs object
142 142
 $object = new Cronjob($db);
143 143
 
144
-$filter=array();
145
-if (! empty($id)) {
146
-	if (! is_numeric($id))
144
+$filter = array();
145
+if (!empty($id)) {
146
+	if (!is_numeric($id))
147 147
 	{
148 148
 		echo "Error: Bad value for parameter job id";
149 149
 		dol_syslog("cron_run_jobs.php Bad value for parameter job id", LOG_WARNING);
150 150
 		exit;
151 151
 	}
152
-	$filter['t.rowid']=$id;
152
+	$filter['t.rowid'] = $id;
153 153
 }
154 154
 
155
-$result = $object->fetch_all('ASC,ASC,ASC','t.priority,t.entity,t.rowid', 0, 0, 1, $filter, 0);
156
-if ($result<0)
155
+$result = $object->fetch_all('ASC,ASC,ASC', 't.priority,t.entity,t.rowid', 0, 0, 1, $filter, 0);
156
+if ($result < 0)
157 157
 {
158 158
 	echo "Error: ".$object->error;
159 159
 	dol_syslog("cron_run_jobs.php:: fetch Error ".$object->error, LOG_ERR);
@@ -162,22 +162,22 @@  discard block
 block discarded – undo
162 162
 
163 163
 
164 164
 $qualifiedjobs = array();
165
-foreach($object->lines as $val)
165
+foreach ($object->lines as $val)
166 166
 {
167
-	if (! verifCond($val->test)) continue;
167
+	if (!verifCond($val->test)) continue;
168 168
 	$qualifiedjobs[] = $val;
169 169
 }
170 170
 
171 171
 // TODO Duplicate. This sequence of code must be shared with code into public/cron/cron_run_jobs.php php page.
172 172
 
173
-$nbofjobs=count($qualifiedjobs);
174
-$nbofjobslaunchedok=0;
175
-$nbofjobslaunchedko=0;
173
+$nbofjobs = count($qualifiedjobs);
174
+$nbofjobslaunchedok = 0;
175
+$nbofjobslaunchedko = 0;
176 176
 
177
-if (is_array($qualifiedjobs) && (count($qualifiedjobs)>0))
177
+if (is_array($qualifiedjobs) && (count($qualifiedjobs) > 0))
178 178
 {
179 179
 	// Loop over job
180
-	foreach($qualifiedjobs as $line)
180
+	foreach ($qualifiedjobs as $line)
181 181
 	{
182 182
 		dol_syslog("cron_run_jobs.php cronjobid: ".$line->id." priority=".$line->priority." entity=".$line->entity." label=".$line->label, LOG_DEBUG);
183 183
 
@@ -188,10 +188,10 @@  discard block
 block discarded – undo
188 188
 		{
189 189
 			echo " - qualified";
190 190
 
191
-			dol_syslog("cron_run_jobs.php line->datenextrun:".dol_print_date($line->datenextrun,'dayhourrfc')." line->datestart:".dol_print_date($line->datestart,'dayhourrfc')." line->dateend:".dol_print_date($line->dateend,'dayhourrfc')." now:".dol_print_date($now,'dayhourrfc'));
191
+			dol_syslog("cron_run_jobs.php line->datenextrun:".dol_print_date($line->datenextrun, 'dayhourrfc')." line->datestart:".dol_print_date($line->datestart, 'dayhourrfc')." line->dateend:".dol_print_date($line->dateend, 'dayhourrfc')." now:".dol_print_date($now, 'dayhourrfc'));
192 192
 
193
-			$cronjob=new Cronjob($db);
194
-			$result=$cronjob->fetch($line->id);
193
+			$cronjob = new Cronjob($db);
194
+			$result = $cronjob->fetch($line->id);
195 195
 			if ($result < 0)
196 196
 			{
197 197
 				echo "Error cronjobid: ".$line->id." cronjob->fetch: ".$cronjob->error."\n";
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
 				exit(-1);
201 201
 			}
202 202
 			// Execute job
203
-			$result=$cronjob->run_jobs($userlogin);
203
+			$result = $cronjob->run_jobs($userlogin);
204 204
 			if ($result < 0)
205 205
 			{
206 206
 				echo "Error cronjobid: ".$line->id." cronjob->run_job: ".$cronjob->error."\n";
@@ -217,8 +217,8 @@  discard block
 block discarded – undo
217 217
 			echo " - result of run_jobs = ".$result;
218 218
 
219 219
 			// we re-program the next execution and stores the last execution time for this job
220
-			$result=$cronjob->reprogram_jobs($userlogin, $now);
221
-			if ($result<0)
220
+			$result = $cronjob->reprogram_jobs($userlogin, $now);
221
+			if ($result < 0)
222 222
 			{
223 223
 				echo "Error cronjobid: ".$line->id." cronjob->reprogram_job: ".$cronjob->error."\n";
224 224
 				echo "Enable module Log if not yet enabled, run again and take a look into dolibarr.log file\n";
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
 		{
233 233
 			echo " - not qualified\n";
234 234
 
235
-			dol_syslog("cron_run_jobs.php job not qualified line->datenextrun:".dol_print_date($line->datenextrun,'dayhourrfc')." line->datestart:".dol_print_date($line->datestart,'dayhourrfc')." line->dateend:".dol_print_date($line->dateend,'dayhourrfc')." now:".dol_print_date($now,'dayhourrfc'));
235
+			dol_syslog("cron_run_jobs.php job not qualified line->datenextrun:".dol_print_date($line->datenextrun, 'dayhourrfc')." line->datestart:".dol_print_date($line->datestart, 'dayhourrfc')." line->dateend:".dol_print_date($line->dateend, 'dayhourrfc')." now:".dol_print_date($now, 'dayhourrfc'));
236 236
 		}
237 237
 	}
238 238
 }
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
  * @param string $script_file   filename
256 256
  * @return void
257 257
  */
258
-function usage($path,$script_file)
258
+function usage($path, $script_file)
259 259
 {
260 260
 	global $conf;
261 261
 
Please login to merge, or discard this patch.
Braces   +29 added lines, -17 removed lines patch added patch discarded remove patch
@@ -23,11 +23,22 @@  discard block
 block discarded – undo
23 23
  *  \ingroup    cron
24 24
  *  \brief      Execute pendings jobs
25 25
  */
26
-if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Disables token renewal
27
-if (! defined('NOREQUIREMENU'))  define('NOREQUIREMENU','1');
28
-if (! defined('NOREQUIREHTML'))  define('NOREQUIREHTML','1');
29
-if (! defined('NOREQUIREAJAX'))  define('NOREQUIREAJAX','1');
30
-if (! defined('NOLOGIN'))        define('NOLOGIN','1');
26
+if (! defined('NOTOKENRENEWAL')) {
27
+    define('NOTOKENRENEWAL','1');
28
+}
29
+// Disables token renewal
30
+if (! defined('NOREQUIREMENU')) {
31
+    define('NOREQUIREMENU','1');
32
+}
33
+if (! defined('NOREQUIREHTML')) {
34
+    define('NOREQUIREHTML','1');
35
+}
36
+if (! defined('NOREQUIREAJAX')) {
37
+    define('NOREQUIREAJAX','1');
38
+}
39
+if (! defined('NOLOGIN')) {
40
+    define('NOLOGIN','1');
41
+}
31 42
 //if (! defined('NOREQUIRETRAN'))  define('NOREQUIRETRAN','1');
32 43
 
33 44
 
@@ -109,9 +120,10 @@  discard block
 block discarded – undo
109 120
             $userlogin = $obj->login;
110 121
             echo "First admin user found is login '".$userlogin."', entity ".$obj->entity."\n";
111 122
         }
123
+    } else {
124
+        dol_print_error($db);
125
+    }
112 126
     }
113
-    else dol_print_error($db);
114
-}
115 127
 
116 128
 // Check user login
117 129
 $user=new User($db);
@@ -121,8 +133,7 @@  discard block
 block discarded – undo
121 133
 	echo "User Error: ".$user->error;
122 134
 	dol_syslog("cron_run_jobs.php:: User Error:".$user->error, LOG_ERR);
123 135
 	exit(-1);
124
-}
125
-else
136
+} else
126 137
 {
127 138
 	if (empty($user->id))
128 139
 	{
@@ -164,7 +175,9 @@  discard block
 block discarded – undo
164 175
 $qualifiedjobs = array();
165 176
 foreach($object->lines as $val)
166 177
 {
167
-	if (! verifCond($val->test)) continue;
178
+	if (! verifCond($val->test)) {
179
+	    continue;
180
+	}
168 181
 	$qualifiedjobs[] = $val;
169 182
 }
170 183
 
@@ -208,8 +221,7 @@  discard block
 block discarded – undo
208 221
 				echo "You can also enable module Log if not yet enabled, run again and take a look into dolibarr.log file\n";
209 222
 				dol_syslog("cron_run_jobs.php::run_jobs Error ".$cronjob->error, LOG_ERR);
210 223
 				$nbofjobslaunchedko++;
211
-			}
212
-			else
224
+			} else
213 225
 			{
214 226
 				$nbofjobslaunchedok++;
215 227
 			}
@@ -227,23 +239,23 @@  discard block
 block discarded – undo
227 239
 			}
228 240
 
229 241
 			echo " - reprogrammed\n";
230
-		}
231
-		else
242
+		} else
232 243
 		{
233 244
 			echo " - not qualified\n";
234 245
 
235 246
 			dol_syslog("cron_run_jobs.php job not qualified line->datenextrun:".dol_print_date($line->datenextrun,'dayhourrfc')." line->datestart:".dol_print_date($line->datestart,'dayhourrfc')." line->dateend:".dol_print_date($line->dateend,'dayhourrfc')." now:".dol_print_date($now,'dayhourrfc'));
236 247
 		}
237 248
 	}
238
-}
239
-else
249
+} else
240 250
 {
241 251
 	echo "cron_run_jobs.php no qualified job found\n";
242 252
 }
243 253
 
244 254
 $db->close();
245 255
 
246
-if ($nbofjobslaunchedko) exit(1);
256
+if ($nbofjobslaunchedko) {
257
+    exit(1);
258
+}
247 259
 exit(0);
248 260
 
249 261
 
Please login to merge, or discard this patch.
dolibarr/scripts/company/sync_contacts_dolibarr2ldap.php 3 patches
Indentation   +43 added lines, -43 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
 
@@ -56,12 +56,12 @@  discard block
 block discarded – undo
56 56
 
57 57
 if (! isset($argv[1]) || ! $argv[1]) {
58 58
     print "Usage: $script_file now [-y]\n";
59
-	exit(-1);
59
+    exit(-1);
60 60
 }
61 61
 
62 62
 foreach($argv as $key => $val)
63 63
 {
64
-	if (preg_match('/-y$/',$val,$reg)) $confirmed=1;
64
+    if (preg_match('/-y$/',$val,$reg)) $confirmed=1;
65 65
 }
66 66
 
67 67
 $now=$argv[1];
@@ -87,12 +87,12 @@  discard block
 block discarded – undo
87 87
 
88 88
 if (! $confirmed)
89 89
 {
90
-	print "Press a key to confirm...\n";
91
-	$input = trim(fgets(STDIN));
92
-	print "Warning, this operation may result in data loss if it failed.\n";
93
-	print "Be sure to have a backup of your LDAP database (With OpenLDAP: slapcat > save.ldif).\n";
94
-	print "Hit Enter to continue or CTRL+C to stop...\n";
95
-	$input = trim(fgets(STDIN));
90
+    print "Press a key to confirm...\n";
91
+    $input = trim(fgets(STDIN));
92
+    print "Warning, this operation may result in data loss if it failed.\n";
93
+    print "Be sure to have a backup of your LDAP database (With OpenLDAP: slapcat > save.ldif).\n";
94
+    print "Hit Enter to continue or CTRL+C to stop...\n";
95
+    $input = trim(fgets(STDIN));
96 96
 }
97 97
 
98 98
 /*
@@ -109,54 +109,54 @@  discard block
 block discarded – undo
109 109
 $resql = $db->query($sql);
110 110
 if ($resql)
111 111
 {
112
-	$num = $db->num_rows($resql);
113
-	$i = 0;
112
+    $num = $db->num_rows($resql);
113
+    $i = 0;
114 114
 
115
-	$ldap=new Ldap();
116
-	$ldap->connect_bind();
115
+    $ldap=new Ldap();
116
+    $ldap->connect_bind();
117 117
 
118
-	while ($i < $num)
119
-	{
120
-		$ldap->error="";
118
+    while ($i < $num)
119
+    {
120
+        $ldap->error="";
121 121
 
122
-		$obj = $db->fetch_object($resql);
122
+        $obj = $db->fetch_object($resql);
123 123
 
124
-		$contact = new Contact($db);
125
-		$contact->id = $obj->rowid;
126
-		$contact->fetch($contact->id);
124
+        $contact = new Contact($db);
125
+        $contact->id = $obj->rowid;
126
+        $contact->fetch($contact->id);
127 127
 
128
-		print $langs->trans("UpdateContact")." rowid=".$contact->id." ".$contact->getFullName($langs);
128
+        print $langs->trans("UpdateContact")." rowid=".$contact->id." ".$contact->getFullName($langs);
129 129
 
130
-		$oldobject=$contact;
130
+        $oldobject=$contact;
131 131
 
132
-	    $oldinfo=$oldobject->_load_ldap_info();
133
-	    $olddn=$oldobject->_load_ldap_dn($oldinfo);
132
+        $oldinfo=$oldobject->_load_ldap_info();
133
+        $olddn=$oldobject->_load_ldap_dn($oldinfo);
134 134
 
135
-		$info=$contact->_load_ldap_info();
136
-		$dn=$contact->_load_ldap_dn($info);
135
+        $info=$contact->_load_ldap_info();
136
+        $dn=$contact->_load_ldap_dn($info);
137 137
 
138
-		$result=$ldap->add($dn,$info,$user);	// Wil fail if already exists
139
-		$result=$ldap->update($dn,$info,$user,$olddn);
140
-		if ($result > 0)
141
-		{
142
-			print " - ".$langs->trans("OK");
143
-		}
144
-		else
145
-		{
146
-			$error++;
147
-			print " - ".$langs->trans("KO").' - '.$ldap->error;
148
-		}
149
-		print "\n";
138
+        $result=$ldap->add($dn,$info,$user);	// Wil fail if already exists
139
+        $result=$ldap->update($dn,$info,$user,$olddn);
140
+        if ($result > 0)
141
+        {
142
+            print " - ".$langs->trans("OK");
143
+        }
144
+        else
145
+        {
146
+            $error++;
147
+            print " - ".$langs->trans("KO").' - '.$ldap->error;
148
+        }
149
+        print "\n";
150 150
 
151
-		$i++;
152
-	}
151
+        $i++;
152
+    }
153 153
 
154
-	$ldap->unbind();
155
-	$ldap->close();
154
+    $ldap->unbind();
155
+    $ldap->close();
156 156
 }
157 157
 else
158 158
 {
159
-	dol_print_error($db);
159
+    dol_print_error($db);
160 160
 }
161 161
 
162 162
 exit($error);
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 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') {
@@ -41,9 +41,9 @@  discard block
 block discarded – undo
41 41
 require_once DOL_DOCUMENT_ROOT."/core/class/ldap.class.php";
42 42
 
43 43
 // Global variables
44
-$version=DOL_VERSION;
45
-$error=0;
46
-$confirmed=0;
44
+$version = DOL_VERSION;
45
+$error = 0;
46
+$confirmed = 0;
47 47
 
48 48
 
49 49
 /*
@@ -52,22 +52,22 @@  discard block
 block discarded – undo
52 52
 
53 53
 @set_time_limit(0);
54 54
 print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
55
-dol_syslog($script_file." launched with arg ".join(',',$argv));
55
+dol_syslog($script_file." launched with arg ".join(',', $argv));
56 56
 
57
-if (! isset($argv[1]) || ! $argv[1]) {
57
+if (!isset($argv[1]) || !$argv[1]) {
58 58
     print "Usage: $script_file now [-y]\n";
59 59
 	exit(-1);
60 60
 }
61 61
 
62
-foreach($argv as $key => $val)
62
+foreach ($argv as $key => $val)
63 63
 {
64
-	if (preg_match('/-y$/',$val,$reg)) $confirmed=1;
64
+	if (preg_match('/-y$/', $val, $reg)) $confirmed = 1;
65 65
 }
66 66
 
67
-$now=$argv[1];
67
+$now = $argv[1];
68 68
 
69 69
 print "Mails sending disabled (useless in batch mode)\n";
70
-$conf->global->MAIN_DISABLE_ALL_MAILS=1;	// On bloque les mails
70
+$conf->global->MAIN_DISABLE_ALL_MAILS = 1; // On bloque les mails
71 71
 print "\n";
72 72
 print "----- Synchronize all records from Dolibarr database:\n";
73 73
 print "type=".$conf->db->type."\n";
@@ -81,11 +81,11 @@  discard block
 block discarded – undo
81 81
 print "host=".$conf->global->LDAP_SERVER_HOST."\n";
82 82
 print "port=".$conf->global->LDAP_SERVER_PORT."\n";
83 83
 print "login=".$conf->global->LDAP_ADMIN_DN."\n";
84
-print "pass=".preg_replace('/./i','*',$conf->global->LDAP_ADMIN_PASS)."\n";
84
+print "pass=".preg_replace('/./i', '*', $conf->global->LDAP_ADMIN_PASS)."\n";
85 85
 print "DN target=".$conf->global->LDAP_CONTACT_DN."\n";
86 86
 print "\n";
87 87
 
88
-if (! $confirmed)
88
+if (!$confirmed)
89 89
 {
90 90
 	print "Press a key to confirm...\n";
91 91
 	$input = trim(fgets(STDIN));
@@ -112,12 +112,12 @@  discard block
 block discarded – undo
112 112
 	$num = $db->num_rows($resql);
113 113
 	$i = 0;
114 114
 
115
-	$ldap=new Ldap();
115
+	$ldap = new Ldap();
116 116
 	$ldap->connect_bind();
117 117
 
118 118
 	while ($i < $num)
119 119
 	{
120
-		$ldap->error="";
120
+		$ldap->error = "";
121 121
 
122 122
 		$obj = $db->fetch_object($resql);
123 123
 
@@ -127,16 +127,16 @@  discard block
 block discarded – undo
127 127
 
128 128
 		print $langs->trans("UpdateContact")." rowid=".$contact->id." ".$contact->getFullName($langs);
129 129
 
130
-		$oldobject=$contact;
130
+		$oldobject = $contact;
131 131
 
132
-	    $oldinfo=$oldobject->_load_ldap_info();
133
-	    $olddn=$oldobject->_load_ldap_dn($oldinfo);
132
+	    $oldinfo = $oldobject->_load_ldap_info();
133
+	    $olddn = $oldobject->_load_ldap_dn($oldinfo);
134 134
 
135
-		$info=$contact->_load_ldap_info();
136
-		$dn=$contact->_load_ldap_dn($info);
135
+		$info = $contact->_load_ldap_info();
136
+		$dn = $contact->_load_ldap_dn($info);
137 137
 
138
-		$result=$ldap->add($dn,$info,$user);	// Wil fail if already exists
139
-		$result=$ldap->update($dn,$info,$user,$olddn);
138
+		$result = $ldap->add($dn, $info, $user); // Wil fail if already exists
139
+		$result = $ldap->update($dn, $info, $user, $olddn);
140 140
 		if ($result > 0)
141 141
 		{
142 142
 			print " - ".$langs->trans("OK");
Please login to merge, or discard this patch.
Braces   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -61,8 +61,10 @@  discard block
 block discarded – undo
61 61
 
62 62
 foreach($argv as $key => $val)
63 63
 {
64
-	if (preg_match('/-y$/',$val,$reg)) $confirmed=1;
65
-}
64
+	if (preg_match('/-y$/',$val,$reg)) {
65
+	    $confirmed=1;
66
+	}
67
+	}
66 68
 
67 69
 $now=$argv[1];
68 70
 
@@ -140,8 +142,7 @@  discard block
 block discarded – undo
140 142
 		if ($result > 0)
141 143
 		{
142 144
 			print " - ".$langs->trans("OK");
143
-		}
144
-		else
145
+		} else
145 146
 		{
146 147
 			$error++;
147 148
 			print " - ".$langs->trans("KO").' - '.$ldap->error;
@@ -153,8 +154,7 @@  discard block
 block discarded – undo
153 154
 
154 155
 	$ldap->unbind();
155 156
 	$ldap->close();
156
-}
157
-else
157
+} else
158 158
 {
159 159
 	dol_print_error($db);
160 160
 }
Please login to merge, or discard this patch.
dolibarr/scripts/company/export-contacts-xls-example.php 2 patches
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -30,13 +30,13 @@  discard block
 block discarded – undo
30 30
 
31 31
 // Test if batch mode
32 32
 if (substr($sapi_type, 0, 3) == 'cgi') {
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);
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);
35 35
 }
36 36
 
37 37
 if (! isset($argv[1]) || ! $argv[1]) {
38
-	print "Usage: $script_file now\n";
39
-	exit(-1);
38
+    print "Usage: $script_file now\n";
39
+    exit(-1);
40 40
 }
41 41
 $now=$argv[1];
42 42
 
@@ -86,30 +86,30 @@  discard block
 block discarded – undo
86 86
 $resql=$db->query($sql);
87 87
 if ($resql)
88 88
 {
89
-	$num = $db->num_rows($resql);
89
+    $num = $db->num_rows($resql);
90 90
 
91
-	print "Lines ".$num."\n";
91
+    print "Lines ".$num."\n";
92 92
 
93
-	$i = 0;
94
-	$j = 1;
93
+    $i = 0;
94
+    $j = 1;
95 95
 
96
-	$objPHPExcel->getActiveSheet()->SetCellValue('A1', $langs->trans("Firstname"));
97
-	$objPHPExcel->getActiveSheet()->SetCellValue('B1', $langs->trans("Lastname"));
98
-	$objPHPExcel->getActiveSheet()->SetCellValue('C1', $langs->trans("Email"));
99
-	$objPHPExcel->getActiveSheet()->SetCellValue('D1', $langs->trans("ThirdPart"));
96
+    $objPHPExcel->getActiveSheet()->SetCellValue('A1', $langs->trans("Firstname"));
97
+    $objPHPExcel->getActiveSheet()->SetCellValue('B1', $langs->trans("Lastname"));
98
+    $objPHPExcel->getActiveSheet()->SetCellValue('C1', $langs->trans("Email"));
99
+    $objPHPExcel->getActiveSheet()->SetCellValue('D1', $langs->trans("ThirdPart"));
100 100
 
101
-	while ($i < $num)
102
-	{
103
-		$obj = $db->fetch_object($resql);
101
+    while ($i < $num)
102
+    {
103
+        $obj = $db->fetch_object($resql);
104 104
 
105
-    	$objPHPExcel->getActiveSheet()->SetCellValue('A'.($i+2), $obj->firstname);
106
-    	$objPHPExcel->getActiveSheet()->SetCellValue('B'.($i+2), $obj->lastname);
107
-    	$objPHPExcel->getActiveSheet()->SetCellValue('C'.($i+2), $obj->email);
108
-    	$objPHPExcel->getActiveSheet()->SetCellValue('D'.($i+2), $obj->name);
105
+        $objPHPExcel->getActiveSheet()->SetCellValue('A'.($i+2), $obj->firstname);
106
+        $objPHPExcel->getActiveSheet()->SetCellValue('B'.($i+2), $obj->lastname);
107
+        $objPHPExcel->getActiveSheet()->SetCellValue('C'.($i+2), $obj->email);
108
+        $objPHPExcel->getActiveSheet()->SetCellValue('D'.($i+2), $obj->name);
109 109
 
110
-		$j++;
111
-		$i++;
112
-	}
110
+        $j++;
111
+        $i++;
112
+    }
113 113
 }
114 114
 
115 115
 
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 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,11 +34,11 @@  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
 
44 44
 require_once $path."../../htdocs/master.inc.php";
@@ -50,8 +50,8 @@  discard block
 block discarded – undo
50 50
 require_once PHPEXCEL_PATH."/PHPExcel/Writer/Excel5.php";
51 51
 
52 52
 // Global variables
53
-$version=DOL_VERSION;
54
-$error=0;
53
+$version = DOL_VERSION;
54
+$error = 0;
55 55
 
56 56
 
57 57
 /*
@@ -60,7 +60,7 @@  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 65
 $fname = DOL_DATA_ROOT.'/export-contacts.xls';
66 66
 
@@ -80,10 +80,10 @@  discard block
 block discarded – undo
80 80
 //$page->set_column(0,4,18); // A
81 81
 
82 82
 $sql = "SELECT distinct c.lastname, c.firstname, c.email, s.nom as name";
83
-$sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c";
84
-$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on s.rowid = c.fk_soc";
83
+$sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c";
84
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on s.rowid = c.fk_soc";
85 85
 
86
-$resql=$db->query($sql);
86
+$resql = $db->query($sql);
87 87
 if ($resql)
88 88
 {
89 89
 	$num = $db->num_rows($resql);
@@ -102,10 +102,10 @@  discard block
 block discarded – undo
102 102
 	{
103 103
 		$obj = $db->fetch_object($resql);
104 104
 
105
-    	$objPHPExcel->getActiveSheet()->SetCellValue('A'.($i+2), $obj->firstname);
106
-    	$objPHPExcel->getActiveSheet()->SetCellValue('B'.($i+2), $obj->lastname);
107
-    	$objPHPExcel->getActiveSheet()->SetCellValue('C'.($i+2), $obj->email);
108
-    	$objPHPExcel->getActiveSheet()->SetCellValue('D'.($i+2), $obj->name);
105
+    	$objPHPExcel->getActiveSheet()->SetCellValue('A'.($i + 2), $obj->firstname);
106
+    	$objPHPExcel->getActiveSheet()->SetCellValue('B'.($i + 2), $obj->lastname);
107
+    	$objPHPExcel->getActiveSheet()->SetCellValue('C'.($i + 2), $obj->email);
108
+    	$objPHPExcel->getActiveSheet()->SetCellValue('D'.($i + 2), $obj->name);
109 109
 
110 110
 		$j++;
111 111
 		$i++;
Please login to merge, or discard this patch.