@@ -20,14 +20,14 @@ discard block |
||
20 | 20 | |
21 | 21 | $sapi_type = php_sapi_name(); |
22 | 22 | $script_file = basename(__FILE__); |
23 | -$path=dirname(__FILE__).'/'; |
|
23 | +$path = dirname(__FILE__).'/'; |
|
24 | 24 | |
25 | -$web=0; |
|
25 | +$web = 0; |
|
26 | 26 | |
27 | 27 | // Test if batch mode |
28 | 28 | if (substr($sapi_type, 0, 3) == 'cgi') |
29 | 29 | { |
30 | - $web=1; |
|
30 | + $web = 1; |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | |
@@ -111,9 +111,9 @@ discard block |
||
111 | 111 | exit; |
112 | 112 | } |
113 | 113 | |
114 | -$dups=array(); |
|
115 | -$exludefiles = array('.','..','README'); |
|
116 | -$files = array_diff($files,$exludefiles); |
|
114 | +$dups = array(); |
|
115 | +$exludefiles = array('.', '..', 'README'); |
|
116 | +$files = array_diff($files, $exludefiles); |
|
117 | 117 | // To force a file: $files=array('myfile.lang'); |
118 | 118 | if (isset($argv[2])) |
119 | 119 | { |
@@ -124,18 +124,18 @@ discard block |
||
124 | 124 | foreach ($files AS $file) { |
125 | 125 | $path_file = pathinfo($file); |
126 | 126 | // we're only interested in .lang files |
127 | - if ($path_file['extension']=='lang') { |
|
127 | + if ($path_file['extension'] == 'lang') { |
|
128 | 128 | $content = file($workdir.$file); |
129 | 129 | foreach ($content AS $line => $row) { |
130 | 130 | // don't want comment lines |
131 | - if (substr($row,0,1) !== '#') { |
|
131 | + if (substr($row, 0, 1) !== '#') { |
|
132 | 132 | // don't want lines without the separator (why should those even be here, anyway...) |
133 | - if (strpos($row,'=')!==false) { |
|
134 | - $row_array = explode('=',$row); // $row_array[0] = key |
|
135 | - $langstrings_3d[$path_file['basename']][$line+1]=$row_array[0]; |
|
136 | - $langstrings_3dtrans[$path_file['basename']][$line+1]=$row_array[1]; |
|
137 | - $langstrings_full[]=$row_array[0]; |
|
138 | - $langstrings_dist[$row_array[0]]=$row; |
|
133 | + if (strpos($row, '=') !== false) { |
|
134 | + $row_array = explode('=', $row); // $row_array[0] = key |
|
135 | + $langstrings_3d[$path_file['basename']][$line + 1] = $row_array[0]; |
|
136 | + $langstrings_3dtrans[$path_file['basename']][$line + 1] = $row_array[1]; |
|
137 | + $langstrings_full[] = $row_array[0]; |
|
138 | + $langstrings_dist[$row_array[0]] = $row; |
|
139 | 139 | } |
140 | 140 | } |
141 | 141 | } |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | foreach ($file AS $linenum => $value) |
148 | 148 | { |
149 | 149 | $keys = array_keys($langstrings_full, $value); |
150 | - if (count($keys)>1) |
|
150 | + if (count($keys) > 1) |
|
151 | 151 | { |
152 | 152 | foreach ($keys AS $key) { |
153 | 153 | $dups[$value][$filename][$linenum] = trim($langstrings_3dtrans[$filename][$linenum]); |
@@ -167,52 +167,52 @@ discard block |
||
167 | 167 | echo "<tbody>\n"; |
168 | 168 | } |
169 | 169 | |
170 | -$sduplicateinsamefile=''; |
|
171 | -$sinmainandother=''; |
|
172 | -$sininstallandadmin=''; |
|
173 | -$sother=''; |
|
170 | +$sduplicateinsamefile = ''; |
|
171 | +$sinmainandother = ''; |
|
172 | +$sininstallandadmin = ''; |
|
173 | +$sother = ''; |
|
174 | 174 | |
175 | 175 | $count = 0; |
176 | 176 | foreach ($dups as $string => $pages) |
177 | 177 | { |
178 | 178 | $count++; |
179 | - $s=''; |
|
179 | + $s = ''; |
|
180 | 180 | |
181 | 181 | // Keyword $string |
182 | - if ($web) $s.="<tr>"; |
|
183 | - if ($web) $s.="<td align=\"center\">"; |
|
184 | - if ($web) $s.=$count; |
|
185 | - if ($web) $s.="</td>"; |
|
186 | - if ($web) $s.="<td>"; |
|
187 | - $s.=$string; |
|
188 | - if ($web) $s.="</td>"; |
|
189 | - if ($web) $s.="<td>"; |
|
190 | - if (! $web) $s.= ' : '; |
|
182 | + if ($web) $s .= "<tr>"; |
|
183 | + if ($web) $s .= "<td align=\"center\">"; |
|
184 | + if ($web) $s .= $count; |
|
185 | + if ($web) $s .= "</td>"; |
|
186 | + if ($web) $s .= "<td>"; |
|
187 | + $s .= $string; |
|
188 | + if ($web) $s .= "</td>"; |
|
189 | + if ($web) $s .= "<td>"; |
|
190 | + if (!$web) $s .= ' : '; |
|
191 | 191 | |
192 | 192 | // Loop on each files keyword was found |
193 | - $duplicateinsamefile=0; |
|
194 | - $inmain=0; |
|
195 | - $inadmin=0; |
|
193 | + $duplicateinsamefile = 0; |
|
194 | + $inmain = 0; |
|
195 | + $inadmin = 0; |
|
196 | 196 | foreach ($pages AS $file => $lines) |
197 | 197 | { |
198 | - if ($file == 'main.lang') { $inmain=1; $inadmin=0; } |
|
199 | - if ($file == 'admin.lang' && ! $inmain) { $inadmin=1; } |
|
198 | + if ($file == 'main.lang') { $inmain = 1; $inadmin = 0; } |
|
199 | + if ($file == 'admin.lang' && !$inmain) { $inadmin = 1; } |
|
200 | 200 | |
201 | - $s.=$file." "; |
|
201 | + $s .= $file." "; |
|
202 | 202 | |
203 | 203 | // Loop on each line keword was found into file. |
204 | - $listoffilesforthisentry=array(); |
|
204 | + $listoffilesforthisentry = array(); |
|
205 | 205 | foreach ($lines as $line => $translatedvalue) |
206 | 206 | { |
207 | - if (! empty($listoffilesforthisentry[$file])) $duplicateinsamefile=1; |
|
208 | - $listoffilesforthisentry[$file]=1; |
|
207 | + if (!empty($listoffilesforthisentry[$file])) $duplicateinsamefile = 1; |
|
208 | + $listoffilesforthisentry[$file] = 1; |
|
209 | 209 | |
210 | - $s.= "(".$line." - ".htmlentities($translatedvalue).") "; |
|
210 | + $s .= "(".$line." - ".htmlentities($translatedvalue).") "; |
|
211 | 211 | } |
212 | - if ($web) $s.="<br>"; |
|
212 | + if ($web) $s .= "<br>"; |
|
213 | 213 | } |
214 | - if ($web) $s.="</td></tr>"; |
|
215 | - $s.="\n"; |
|
214 | + if ($web) $s .= "</td></tr>"; |
|
215 | + $s .= "\n"; |
|
216 | 216 | |
217 | 217 | if ($duplicateinsamefile) $sduplicateinsamefile .= $s; |
218 | 218 | else if ($inmain) $sinmainandother .= $s; |
@@ -220,25 +220,25 @@ discard block |
||
220 | 220 | else $sother .= $s; |
221 | 221 | } |
222 | 222 | |
223 | -if (! $web) print "\n***** Entries duplicated in same file\n"; |
|
223 | +if (!$web) print "\n***** Entries duplicated in same file\n"; |
|
224 | 224 | print $sduplicateinsamefile; |
225 | -if (! $web && empty($sduplicateinsamefile)) print "None\n"; |
|
226 | -if (! $web) print "\n"; |
|
225 | +if (!$web && empty($sduplicateinsamefile)) print "None\n"; |
|
226 | +if (!$web) print "\n"; |
|
227 | 227 | |
228 | -if (! $web) print "***** Entries in main and another (keep only entry in main)\n"; |
|
228 | +if (!$web) print "***** Entries in main and another (keep only entry in main)\n"; |
|
229 | 229 | print $sinmainandother; |
230 | -if (! $web && empty($sinmainandother)) print "None\n"; |
|
231 | -if (! $web) print "\n"; |
|
230 | +if (!$web && empty($sinmainandother)) print "None\n"; |
|
231 | +if (!$web) print "\n"; |
|
232 | 232 | |
233 | -if (! $web) print "***** Entries in admin and another\n"; |
|
233 | +if (!$web) print "***** Entries in admin and another\n"; |
|
234 | 234 | print $sininstallandadmin; |
235 | -if (! $web && empty($sininstallandadmin)) print "None\n"; |
|
236 | -if (! $web) print "\n"; |
|
235 | +if (!$web && empty($sininstallandadmin)) print "None\n"; |
|
236 | +if (!$web) print "\n"; |
|
237 | 237 | |
238 | -if (! $web) print "***** Other\n"; |
|
238 | +if (!$web) print "***** Other\n"; |
|
239 | 239 | print $sother; |
240 | -if (! $web && empty($sother)) print "None\n"; |
|
241 | -if (! $web) print "\n"; |
|
240 | +if (!$web && empty($sother)) print "None\n"; |
|
241 | +if (!$web) print "\n"; |
|
242 | 242 | |
243 | 243 | if ($web) |
244 | 244 | { |
@@ -249,116 +249,116 @@ discard block |
||
249 | 249 | |
250 | 250 | // STEP 2 - Search key not used |
251 | 251 | |
252 | -if ((! empty($_REQUEST['unused']) && $_REQUEST['unused'] == 'true') || (isset($argv[1]) && $argv[1]=='unused=true')) |
|
252 | +if ((!empty($_REQUEST['unused']) && $_REQUEST['unused'] == 'true') || (isset($argv[1]) && $argv[1] == 'unused=true')) |
|
253 | 253 | { |
254 | 254 | print "***** Strings in en_US that are never used:\n"; |
255 | 255 | |
256 | - $unused=array(); |
|
256 | + $unused = array(); |
|
257 | 257 | foreach ($langstrings_dist AS $value => $line) |
258 | 258 | { |
259 | - $qualifiedforclean=1; |
|
259 | + $qualifiedforclean = 1; |
|
260 | 260 | // Check if we must keep this key to be into file for removal |
261 | - if (preg_match('/^Module\d+/', $value)) $qualifiedforclean=0; |
|
262 | - if (preg_match('/^Permission\d+/', $value)) $qualifiedforclean=0; |
|
263 | - if (preg_match('/^PermissionAdvanced\d+/', $value)) $qualifiedforclean=0; |
|
264 | - if (preg_match('/^ProfId\d+/', $value)) $qualifiedforclean=0; |
|
265 | - if (preg_match('/^Delays_/', $value)) $qualifiedforclean=0; |
|
266 | - if (preg_match('/^BarcodeDesc/', $value)) $qualifiedforclean=0; |
|
267 | - if (preg_match('/^Extrafield/', $value)) $qualifiedforclean=0; |
|
268 | - if (preg_match('/^LocalTax/', $value)) $qualifiedforclean=0; |
|
269 | - if (preg_match('/^Country/', $value)) $qualifiedforclean=0; |
|
270 | - if (preg_match('/^Civility/', $value)) $qualifiedforclean=0; |
|
271 | - if (preg_match('/^Currency/', $value)) $qualifiedforclean=0; |
|
272 | - if (preg_match('/^DemandReasonTypeSRC/', $value)) $qualifiedforclean=0; |
|
273 | - if (preg_match('/^PaperFormat/', $value)) $qualifiedforclean=0; |
|
274 | - if (preg_match('/^Duration/', $value)) $qualifiedforclean=0; |
|
275 | - if (preg_match('/^AmountLT/', $value)) $qualifiedforclean=0; |
|
276 | - if (preg_match('/^TotalLT/', $value)) $qualifiedforclean=0; |
|
277 | - if (preg_match('/^Month/', $value)) $qualifiedforclean=0; |
|
278 | - if (preg_match('/^MonthShort/', $value)) $qualifiedforclean=0; |
|
279 | - if (preg_match('/^Day\d/', $value)) $qualifiedforclean=0; |
|
280 | - if (preg_match('/^Short/', $value)) $qualifiedforclean=0; |
|
281 | - if (preg_match('/^ExportDataset_/', $value)) $qualifiedforclean=0; |
|
282 | - if (preg_match('/^ImportDataset_/', $value)) $qualifiedforclean=0; |
|
283 | - if (preg_match('/^ActionAC_/', $value)) $qualifiedforclean=0; |
|
284 | - if (preg_match('/^TypeLocaltax/', $value)) $qualifiedforclean=0; |
|
285 | - if (preg_match('/^StatusProspect/', $value)) $qualifiedforclean=0; |
|
286 | - if (preg_match('/^PL_/', $value)) $qualifiedforclean=0; |
|
287 | - if (preg_match('/^TE_/', $value)) $qualifiedforclean=0; |
|
288 | - if (preg_match('/^JuridicalStatus/', $value)) $qualifiedforclean=0; |
|
289 | - if (preg_match('/^CalcMode/', $value)) $qualifiedforclean=0; |
|
290 | - if (preg_match('/^newLT/', $value)) $qualifiedforclean=0; |
|
291 | - if (preg_match('/^LT[0-9]/', $value)) $qualifiedforclean=0; |
|
292 | - if (preg_match('/^TypeContact_contrat_/', $value)) $qualifiedforclean=0; |
|
293 | - if (preg_match('/^ErrorPriceExpression/', $value)) $qualifiedforclean=0; |
|
294 | - if (preg_match('/^Language_/', $value)) $qualifiedforclean=0; |
|
295 | - if (preg_match('/^DescADHERENT_/', $value)) $qualifiedforclean=0; |
|
296 | - if (preg_match('/^SubmitTranslation/', $value)) $qualifiedforclean=0; |
|
297 | - if (preg_match('/^ModuleCompanyCode/', $value)) $qualifiedforclean=0; |
|
298 | - if (preg_match('/InDolibarr$/', $value)) $qualifiedforclean=0; |
|
261 | + if (preg_match('/^Module\d+/', $value)) $qualifiedforclean = 0; |
|
262 | + if (preg_match('/^Permission\d+/', $value)) $qualifiedforclean = 0; |
|
263 | + if (preg_match('/^PermissionAdvanced\d+/', $value)) $qualifiedforclean = 0; |
|
264 | + if (preg_match('/^ProfId\d+/', $value)) $qualifiedforclean = 0; |
|
265 | + if (preg_match('/^Delays_/', $value)) $qualifiedforclean = 0; |
|
266 | + if (preg_match('/^BarcodeDesc/', $value)) $qualifiedforclean = 0; |
|
267 | + if (preg_match('/^Extrafield/', $value)) $qualifiedforclean = 0; |
|
268 | + if (preg_match('/^LocalTax/', $value)) $qualifiedforclean = 0; |
|
269 | + if (preg_match('/^Country/', $value)) $qualifiedforclean = 0; |
|
270 | + if (preg_match('/^Civility/', $value)) $qualifiedforclean = 0; |
|
271 | + if (preg_match('/^Currency/', $value)) $qualifiedforclean = 0; |
|
272 | + if (preg_match('/^DemandReasonTypeSRC/', $value)) $qualifiedforclean = 0; |
|
273 | + if (preg_match('/^PaperFormat/', $value)) $qualifiedforclean = 0; |
|
274 | + if (preg_match('/^Duration/', $value)) $qualifiedforclean = 0; |
|
275 | + if (preg_match('/^AmountLT/', $value)) $qualifiedforclean = 0; |
|
276 | + if (preg_match('/^TotalLT/', $value)) $qualifiedforclean = 0; |
|
277 | + if (preg_match('/^Month/', $value)) $qualifiedforclean = 0; |
|
278 | + if (preg_match('/^MonthShort/', $value)) $qualifiedforclean = 0; |
|
279 | + if (preg_match('/^Day\d/', $value)) $qualifiedforclean = 0; |
|
280 | + if (preg_match('/^Short/', $value)) $qualifiedforclean = 0; |
|
281 | + if (preg_match('/^ExportDataset_/', $value)) $qualifiedforclean = 0; |
|
282 | + if (preg_match('/^ImportDataset_/', $value)) $qualifiedforclean = 0; |
|
283 | + if (preg_match('/^ActionAC_/', $value)) $qualifiedforclean = 0; |
|
284 | + if (preg_match('/^TypeLocaltax/', $value)) $qualifiedforclean = 0; |
|
285 | + if (preg_match('/^StatusProspect/', $value)) $qualifiedforclean = 0; |
|
286 | + if (preg_match('/^PL_/', $value)) $qualifiedforclean = 0; |
|
287 | + if (preg_match('/^TE_/', $value)) $qualifiedforclean = 0; |
|
288 | + if (preg_match('/^JuridicalStatus/', $value)) $qualifiedforclean = 0; |
|
289 | + if (preg_match('/^CalcMode/', $value)) $qualifiedforclean = 0; |
|
290 | + if (preg_match('/^newLT/', $value)) $qualifiedforclean = 0; |
|
291 | + if (preg_match('/^LT[0-9]/', $value)) $qualifiedforclean = 0; |
|
292 | + if (preg_match('/^TypeContact_contrat_/', $value)) $qualifiedforclean = 0; |
|
293 | + if (preg_match('/^ErrorPriceExpression/', $value)) $qualifiedforclean = 0; |
|
294 | + if (preg_match('/^Language_/', $value)) $qualifiedforclean = 0; |
|
295 | + if (preg_match('/^DescADHERENT_/', $value)) $qualifiedforclean = 0; |
|
296 | + if (preg_match('/^SubmitTranslation/', $value)) $qualifiedforclean = 0; |
|
297 | + if (preg_match('/^ModuleCompanyCode/', $value)) $qualifiedforclean = 0; |
|
298 | + if (preg_match('/InDolibarr$/', $value)) $qualifiedforclean = 0; |
|
299 | 299 | // admin.lang |
300 | - if (preg_match('/^DAV_ALLOW_PUBLIC_DIR/i', $value)) $qualifiedforclean=0; |
|
301 | - if (preg_match('/^DAV_ALLOW_ECM_DIR/i', $value)) $qualifiedforclean=0; |
|
300 | + if (preg_match('/^DAV_ALLOW_PUBLIC_DIR/i', $value)) $qualifiedforclean = 0; |
|
301 | + if (preg_match('/^DAV_ALLOW_ECM_DIR/i', $value)) $qualifiedforclean = 0; |
|
302 | 302 | // boxes.lang |
303 | - if (preg_match('/^BoxTitleLast/', $value)) $qualifiedforclean=0; |
|
304 | - if (preg_match('/^BoxTitleLatest/', $value)) $qualifiedforclean=0; |
|
303 | + if (preg_match('/^BoxTitleLast/', $value)) $qualifiedforclean = 0; |
|
304 | + if (preg_match('/^BoxTitleLatest/', $value)) $qualifiedforclean = 0; |
|
305 | 305 | // install.lang |
306 | - if (preg_match('/^KeepDefaultValues/', $value)) $qualifiedforclean=0; |
|
306 | + if (preg_match('/^KeepDefaultValues/', $value)) $qualifiedforclean = 0; |
|
307 | 307 | // mail.lang |
308 | - if (preg_match('/MailingModuleDesc/i', $value)) $qualifiedforclean=0; |
|
308 | + if (preg_match('/MailingModuleDesc/i', $value)) $qualifiedforclean = 0; |
|
309 | 309 | // main.lang |
310 | - if (preg_match('/^Duration/', $value)) $qualifiedforclean=0; |
|
311 | - if (preg_match('/^FormatDate/', $value)) $qualifiedforclean=0; |
|
312 | - if (preg_match('/^DateFormat/', $value)) $qualifiedforclean=0; |
|
313 | - if (preg_match('/^.b$/', $value)) $qualifiedforclean=0; |
|
314 | - if (preg_match('/^.*Bytes$/', $value)) $qualifiedforclean=0; |
|
315 | - if (preg_match('/^NoteSomeFeaturesAreDisabled/', $value)) $qualifiedforclean=0; |
|
316 | - if (preg_match('/^(DoTest|Under|Limits|Cards|CurrentValue|DateLimit|DateAndHour|NbOfLines|NbOfObjects|NbOfReferes|TotalTTCShort|VATs)/', $value)) $qualifiedforclean=0; |
|
310 | + if (preg_match('/^Duration/', $value)) $qualifiedforclean = 0; |
|
311 | + if (preg_match('/^FormatDate/', $value)) $qualifiedforclean = 0; |
|
312 | + if (preg_match('/^DateFormat/', $value)) $qualifiedforclean = 0; |
|
313 | + if (preg_match('/^.b$/', $value)) $qualifiedforclean = 0; |
|
314 | + if (preg_match('/^.*Bytes$/', $value)) $qualifiedforclean = 0; |
|
315 | + if (preg_match('/^NoteSomeFeaturesAreDisabled/', $value)) $qualifiedforclean = 0; |
|
316 | + if (preg_match('/^(DoTest|Under|Limits|Cards|CurrentValue|DateLimit|DateAndHour|NbOfLines|NbOfObjects|NbOfReferes|TotalTTCShort|VATs)/', $value)) $qualifiedforclean = 0; |
|
317 | 317 | // modulebuilder |
318 | - if (preg_match('/^ModuleBuilderDesc/', $value)) $qualifiedforclean=0; |
|
318 | + if (preg_match('/^ModuleBuilderDesc/', $value)) $qualifiedforclean = 0; |
|
319 | 319 | // orders |
320 | - if (preg_match('/^OrderSource/', $value)) $qualifiedforclean=0; |
|
321 | - if (preg_match('/^TypeContact_/', $value)) $qualifiedforclean=0; |
|
320 | + if (preg_match('/^OrderSource/', $value)) $qualifiedforclean = 0; |
|
321 | + if (preg_match('/^TypeContact_/', $value)) $qualifiedforclean = 0; |
|
322 | 322 | // other.lang |
323 | - if (preg_match('/^Notify_/', $value)) $qualifiedforclean=0; |
|
324 | - if (preg_match('/^PredefinedMail/', $value)) $qualifiedforclean=0; |
|
325 | - if (preg_match('/^DemoCompany/', $value)) $qualifiedforclean=0; |
|
326 | - if (preg_match('/^WeightUnit/', $value)) $qualifiedforclean=0; |
|
327 | - if (preg_match('/^LengthUnit/', $value)) $qualifiedforclean=0; |
|
328 | - if (preg_match('/^SurfaceUnit/', $value)) $qualifiedforclean=0; |
|
329 | - if (preg_match('/^VolumeUnit/', $value)) $qualifiedforclean=0; |
|
330 | - if (preg_match('/^SizeUnit/', $value)) $qualifiedforclean=0; |
|
331 | - if (preg_match('/^EMailText/', $value)) $qualifiedforclean=0; |
|
332 | - if (preg_match('/ById$/', $value)) $qualifiedforclean=0; |
|
333 | - if (preg_match('/ByLogin$/', $value)) $qualifiedforclean=0; |
|
323 | + if (preg_match('/^Notify_/', $value)) $qualifiedforclean = 0; |
|
324 | + if (preg_match('/^PredefinedMail/', $value)) $qualifiedforclean = 0; |
|
325 | + if (preg_match('/^DemoCompany/', $value)) $qualifiedforclean = 0; |
|
326 | + if (preg_match('/^WeightUnit/', $value)) $qualifiedforclean = 0; |
|
327 | + if (preg_match('/^LengthUnit/', $value)) $qualifiedforclean = 0; |
|
328 | + if (preg_match('/^SurfaceUnit/', $value)) $qualifiedforclean = 0; |
|
329 | + if (preg_match('/^VolumeUnit/', $value)) $qualifiedforclean = 0; |
|
330 | + if (preg_match('/^SizeUnit/', $value)) $qualifiedforclean = 0; |
|
331 | + if (preg_match('/^EMailText/', $value)) $qualifiedforclean = 0; |
|
332 | + if (preg_match('/ById$/', $value)) $qualifiedforclean = 0; |
|
333 | + if (preg_match('/ByLogin$/', $value)) $qualifiedforclean = 0; |
|
334 | 334 | // printing |
335 | - if (preg_match('/PrintingDriverDesc$/', $value)) $qualifiedforclean=0; |
|
336 | - if (preg_match('/PrintTestDesc$/', $value)) $qualifiedforclean=0; |
|
335 | + if (preg_match('/PrintingDriverDesc$/', $value)) $qualifiedforclean = 0; |
|
336 | + if (preg_match('/PrintTestDesc$/', $value)) $qualifiedforclean = 0; |
|
337 | 337 | // products |
338 | - if (preg_match('/GlobalVariableUpdaterType$/', $value)) $qualifiedforclean=0; |
|
339 | - if (preg_match('/GlobalVariableUpdaterHelp$/', $value)) $qualifiedforclean=0; |
|
340 | - if (preg_match('/OppStatus/', $value)) $qualifiedforclean=0; |
|
341 | - if (preg_match('/AvailabilityType/', $value)) $qualifiedforclean=0; |
|
342 | - if (preg_match('/CardProduct/', $value)) $qualifiedforclean=0; |
|
343 | - |
|
344 | - if (preg_match('/sms/i', $value)) $qualifiedforclean=0; |
|
345 | - if (preg_match('/TF_/i', $value)) $qualifiedforclean=0; |
|
346 | - if (preg_match('/WithBankUsing/i', $value)) $qualifiedforclean=0; |
|
347 | - if (preg_match('/descWORKFLOW_/i', $value)) $qualifiedforclean=0; |
|
348 | - |
|
349 | - if (! $qualifiedforclean) |
|
338 | + if (preg_match('/GlobalVariableUpdaterType$/', $value)) $qualifiedforclean = 0; |
|
339 | + if (preg_match('/GlobalVariableUpdaterHelp$/', $value)) $qualifiedforclean = 0; |
|
340 | + if (preg_match('/OppStatus/', $value)) $qualifiedforclean = 0; |
|
341 | + if (preg_match('/AvailabilityType/', $value)) $qualifiedforclean = 0; |
|
342 | + if (preg_match('/CardProduct/', $value)) $qualifiedforclean = 0; |
|
343 | + |
|
344 | + if (preg_match('/sms/i', $value)) $qualifiedforclean = 0; |
|
345 | + if (preg_match('/TF_/i', $value)) $qualifiedforclean = 0; |
|
346 | + if (preg_match('/WithBankUsing/i', $value)) $qualifiedforclean = 0; |
|
347 | + if (preg_match('/descWORKFLOW_/i', $value)) $qualifiedforclean = 0; |
|
348 | + |
|
349 | + if (!$qualifiedforclean) |
|
350 | 350 | { |
351 | 351 | continue; |
352 | 352 | } |
353 | 353 | |
354 | 354 | //$search = '\'trans("'.$value.'")\''; |
355 | 355 | $search = '-e "\''.$value.'\'" -e \'"'.$value.'"\' -e "('.$value.')" -e "('.$value.',"'; |
356 | - $string = 'grep -R -m 1 -F --exclude=includes/* --include=*.php '.$search.' '.$htdocs.'* '.$scripts.'*'; |
|
356 | + $string = 'grep -R -m 1 -F --exclude=includes/* --include=*.php '.$search.' '.$htdocs.'* '.$scripts.'*'; |
|
357 | 357 | //print $string."<br>\n"; |
358 | - exec($string,$output); |
|
358 | + exec($string, $output); |
|
359 | 359 | if (empty($output)) { |
360 | 360 | $unused[$value] = $line; |
361 | - echo $line; // $trad contains the \n |
|
361 | + echo $line; // $trad contains the \n |
|
362 | 362 | } |
363 | 363 | else |
364 | 364 | { |
@@ -370,13 +370,13 @@ discard block |
||
370 | 370 | if (empty($unused)) print "No string not used found.\n"; |
371 | 371 | else |
372 | 372 | { |
373 | - $filetosave='/tmp/'.($argv[2]?$argv[2]:"").'notused.lang'; |
|
373 | + $filetosave = '/tmp/'.($argv[2] ? $argv[2] : "").'notused.lang'; |
|
374 | 374 | print "Strings in en_US that are never used are saved into file ".$filetosave.":\n"; |
375 | - file_put_contents($filetosave, implode("",$unused)); |
|
375 | + file_put_contents($filetosave, implode("", $unused)); |
|
376 | 376 | print "To remove from original file, run command :\n"; |
377 | - if (($argv[2]?$argv[2]:"")) print 'cd htdocs/langs/en_US; mv '.($argv[2]?$argv[2]:"")." ".($argv[2]?$argv[2]:"").".tmp; "; |
|
378 | - print "diff ".($argv[2]?$argv[2]:"").".tmp ".$filetosave." | grep \< | cut -b 3- > ".($argv[2]?$argv[2]:""); |
|
379 | - if (($argv[2]?$argv[2]:"")) print "; rm ".($argv[2]?$argv[2]:"").".tmp;\n"; |
|
377 | + if (($argv[2] ? $argv[2] : "")) print 'cd htdocs/langs/en_US; mv '.($argv[2] ? $argv[2] : "")." ".($argv[2] ? $argv[2] : "").".tmp; "; |
|
378 | + print "diff ".($argv[2] ? $argv[2] : "").".tmp ".$filetosave." | grep \< | cut -b 3- > ".($argv[2] ? $argv[2] : ""); |
|
379 | + if (($argv[2] ? $argv[2] : "")) print "; rm ".($argv[2] ? $argv[2] : "").".tmp;\n"; |
|
380 | 380 | } |
381 | 381 | } |
382 | 382 |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * @param string $_apikey Api key |
51 | 51 | * @return void |
52 | 52 | */ |
53 | - function __construct($_destlang,$_refLang,$_langDir,$_limittofile,$_apikey) |
|
53 | + function __construct($_destlang, $_refLang, $_langDir, $_limittofile, $_apikey) |
|
54 | 54 | { |
55 | 55 | |
56 | 56 | // Set enviorment variables |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | |
64 | 64 | // Translate |
65 | 65 | //ini_set('default_charset','UTF-8'); |
66 | - ini_set('default_charset',$this->_outputpagecode); |
|
66 | + ini_set('default_charset', $this->_outputpagecode); |
|
67 | 67 | $this->parseRefLangTranslationFiles(); |
68 | 68 | } |
69 | 69 | |
@@ -77,72 +77,72 @@ discard block |
||
77 | 77 | |
78 | 78 | $files = $this->getTranslationFilesArray($this->_refLang); |
79 | 79 | $counter = 1; |
80 | - foreach($files as $file) |
|
80 | + foreach ($files as $file) |
|
81 | 81 | { |
82 | 82 | if ($this->_limittofile && $this->_limittofile != $file) continue; |
83 | 83 | $counter++; |
84 | 84 | $fileContent = null; |
85 | 85 | $refPath = $this->_langDir.$this->_refLang.self::DIR_SEPARATOR.$file; |
86 | - $fileContent = file($refPath,FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES); |
|
87 | - print "Processing file " . $file . ", with ".count($fileContent)." lines<br>\n"; |
|
86 | + $fileContent = file($refPath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); |
|
87 | + print "Processing file ".$file.", with ".count($fileContent)." lines<br>\n"; |
|
88 | 88 | |
89 | 89 | // Define target dirs |
90 | - $targetlangs=array($this->_destlang); |
|
90 | + $targetlangs = array($this->_destlang); |
|
91 | 91 | if ($this->_destlang == 'all') |
92 | 92 | { |
93 | - $targetlangs=array(); |
|
93 | + $targetlangs = array(); |
|
94 | 94 | |
95 | 95 | // If we must process all languages |
96 | - $arraytmp=dol_dir_list($this->_langDir,'directories',0); |
|
97 | - foreach($arraytmp as $dirtmp) |
|
96 | + $arraytmp = dol_dir_list($this->_langDir, 'directories', 0); |
|
97 | + foreach ($arraytmp as $dirtmp) |
|
98 | 98 | { |
99 | - if ($dirtmp['name'] === $this->_refLang) continue; // We discard source language |
|
100 | - $tmppart=explode('_',$dirtmp['name']); |
|
101 | - if (preg_match('/^en/i',$dirtmp['name'])) continue; // We discard en_* languages |
|
102 | - if (preg_match('/^fr/i',$dirtmp['name'])) continue; // We discard fr_* languages |
|
103 | - if (preg_match('/^es/i',$dirtmp['name'])) continue; // We discard es_* languages |
|
104 | - if (preg_match('/ca_ES/i',$dirtmp['name'])) continue; // We discard es_CA language |
|
105 | - if (preg_match('/pt_BR/i',$dirtmp['name'])) continue; // We discard pt_BR language |
|
106 | - if (preg_match('/nl_BE/i',$dirtmp['name'])) continue; // We discard nl_BE language |
|
107 | - if (preg_match('/^\./i',$dirtmp['name'])) continue; // We discard files .* |
|
108 | - if (preg_match('/^CVS/i',$dirtmp['name'])) continue; // We discard CVS |
|
109 | - $targetlangs[]=$dirtmp['name']; |
|
99 | + if ($dirtmp['name'] === $this->_refLang) continue; // We discard source language |
|
100 | + $tmppart = explode('_', $dirtmp['name']); |
|
101 | + if (preg_match('/^en/i', $dirtmp['name'])) continue; // We discard en_* languages |
|
102 | + if (preg_match('/^fr/i', $dirtmp['name'])) continue; // We discard fr_* languages |
|
103 | + if (preg_match('/^es/i', $dirtmp['name'])) continue; // We discard es_* languages |
|
104 | + if (preg_match('/ca_ES/i', $dirtmp['name'])) continue; // We discard es_CA language |
|
105 | + if (preg_match('/pt_BR/i', $dirtmp['name'])) continue; // We discard pt_BR language |
|
106 | + if (preg_match('/nl_BE/i', $dirtmp['name'])) continue; // We discard nl_BE language |
|
107 | + if (preg_match('/^\./i', $dirtmp['name'])) continue; // We discard files .* |
|
108 | + if (preg_match('/^CVS/i', $dirtmp['name'])) continue; // We discard CVS |
|
109 | + $targetlangs[] = $dirtmp['name']; |
|
110 | 110 | } |
111 | 111 | //var_dump($targetlangs); |
112 | 112 | } |
113 | 113 | |
114 | 114 | // Process translation of source file for each target languages |
115 | - foreach($targetlangs as $my_destlang) |
|
115 | + foreach ($targetlangs as $my_destlang) |
|
116 | 116 | { |
117 | 117 | $this->_translatedFiles = array(); |
118 | 118 | |
119 | 119 | $destPath = $this->_langDir.$my_destlang.self::DIR_SEPARATOR.$file; |
120 | 120 | // Check destination file presence |
121 | - if (! file_exists($destPath)) |
|
121 | + if (!file_exists($destPath)) |
|
122 | 122 | { |
123 | 123 | // No file present, we generate file |
124 | - echo "File not found: " . $destPath . ". We generate it.<br>\n"; |
|
125 | - $this->createTranslationFile($destPath,$my_destlang); |
|
124 | + echo "File not found: ".$destPath.". We generate it.<br>\n"; |
|
125 | + $this->createTranslationFile($destPath, $my_destlang); |
|
126 | 126 | } |
127 | 127 | else |
128 | 128 | { |
129 | - echo "Updating file: " . $destPath . "<br>\n"; |
|
129 | + echo "Updating file: ".$destPath."<br>\n"; |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | // Translate lines |
133 | - $fileContentDest = file($destPath,FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES); |
|
134 | - $newlines=0; |
|
135 | - foreach($fileContent as $line){ |
|
133 | + $fileContentDest = file($destPath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); |
|
134 | + $newlines = 0; |
|
135 | + foreach ($fileContent as $line) { |
|
136 | 136 | $key = $this->getLineKey($line); |
137 | 137 | $value = $this->getLineValue($line); |
138 | 138 | if ($key && $value) |
139 | 139 | { |
140 | - $newlines+=$this->translateFileLine($fileContentDest,$file,$key,$value,$my_destlang); |
|
140 | + $newlines += $this->translateFileLine($fileContentDest, $file, $key, $value, $my_destlang); |
|
141 | 141 | } |
142 | 142 | } |
143 | 143 | |
144 | - $this->updateTranslationFile($destPath,$file,$my_destlang); |
|
145 | - echo "New translated lines: " . $newlines . "<br>\n"; |
|
144 | + $this->updateTranslationFile($destPath, $file, $my_destlang); |
|
145 | + echo "New translated lines: ".$newlines."<br>\n"; |
|
146 | 146 | //if ($counter ==3) die('fim'); |
147 | 147 | } |
148 | 148 | } |
@@ -156,19 +156,19 @@ discard block |
||
156 | 156 | * @param string $my_destlang Target language code |
157 | 157 | * @return void |
158 | 158 | */ |
159 | - private function updateTranslationFile($destPath,$file,$my_destlang) |
|
159 | + private function updateTranslationFile($destPath, $file, $my_destlang) |
|
160 | 160 | { |
161 | 161 | $this->_time_end = date('Y-m-d H:i:s'); |
162 | 162 | |
163 | - if (isset($this->_translatedFiles[$file]) && count($this->_translatedFiles[$file])>0) |
|
163 | + if (isset($this->_translatedFiles[$file]) && count($this->_translatedFiles[$file]) > 0) |
|
164 | 164 | { |
165 | 165 | $fp = fopen($destPath, 'a'); |
166 | 166 | fwrite($fp, "\n"); |
167 | 167 | fwrite($fp, "\n"); |
168 | 168 | fwrite($fp, "// START - Lines generated via autotranslator.php tool (".$this->_time.").\n"); |
169 | 169 | fwrite($fp, "// Reference language: ".$this->_refLang." -> ".$my_destlang."\n"); |
170 | - foreach( $this->_translatedFiles[$file] as $line) { |
|
171 | - fwrite($fp, $line . "\n"); |
|
170 | + foreach ($this->_translatedFiles[$file] as $line) { |
|
171 | + fwrite($fp, $line."\n"); |
|
172 | 172 | } |
173 | 173 | fwrite($fp, "// STOP - Lines generated via autotranslator.php tool (".$this->_time_end.").\n"); |
174 | 174 | fclose($fp); |
@@ -183,13 +183,13 @@ discard block |
||
183 | 183 | * @param string $my_destlang Target language code |
184 | 184 | * @return void |
185 | 185 | */ |
186 | - private function createTranslationFile($path,$my_destlang) |
|
186 | + private function createTranslationFile($path, $my_destlang) |
|
187 | 187 | { |
188 | 188 | $fp = fopen($path, 'w+'); |
189 | 189 | fwrite($fp, "/*\n"); |
190 | 190 | fwrite($fp, " * Language code: {$my_destlang}\n"); |
191 | 191 | fwrite($fp, " * Automatic generated via autotranslator.php tool\n"); |
192 | - fwrite($fp, " * Generation date " . $this->_time. "\n"); |
|
192 | + fwrite($fp, " * Generation date ".$this->_time."\n"); |
|
193 | 193 | fwrite($fp, " */\n"); |
194 | 194 | fclose($fp); |
195 | 195 | return; |
@@ -205,36 +205,36 @@ discard block |
||
205 | 205 | * @param string $my_destlang Language code (ie: fr_FR) |
206 | 206 | * @return int 0=Nothing translated, 1=Record translated |
207 | 207 | */ |
208 | - private function translateFileLine($content,$file,$key,$value,$my_destlang) |
|
208 | + private function translateFileLine($content, $file, $key, $value, $my_destlang) |
|
209 | 209 | { |
210 | 210 | |
211 | 211 | //print "key =".$key."\n"; |
212 | - foreach( $content as $line ) { |
|
212 | + foreach ($content as $line) { |
|
213 | 213 | $destKey = $this->getLineKey($line); |
214 | 214 | $destValue = $this->getLineValue($line); |
215 | 215 | // If translated return |
216 | 216 | //print "destKey=".$destKey."\n"; |
217 | - if ( trim($destKey) == trim($key) ) |
|
217 | + if (trim($destKey) == trim($key)) |
|
218 | 218 | { // Found already existing translation (key already exits in dest file) |
219 | 219 | return 0; |
220 | 220 | } |
221 | 221 | } |
222 | 222 | |
223 | - if ($key == 'CHARSET') $val=$this->_outputpagecode; |
|
224 | - else if (preg_match('/^Format/',$key)) $val=$value; |
|
225 | - else if ($value=='-') $val=$value; |
|
223 | + if ($key == 'CHARSET') $val = $this->_outputpagecode; |
|
224 | + else if (preg_match('/^Format/', $key)) $val = $value; |
|
225 | + else if ($value == '-') $val = $value; |
|
226 | 226 | else |
227 | 227 | { |
228 | 228 | // If not translated then translate |
229 | - if ($this->_outputpagecode == 'UTF-8') $val=$this->translateTexts(array($value),substr($this->_refLang,0,2),substr($my_destlang,0,2)); |
|
230 | - else $val=utf8_decode($this->translateTexts(array($value),substr($this->_refLang,0,2),substr($my_destlang,0,2))); |
|
229 | + if ($this->_outputpagecode == 'UTF-8') $val = $this->translateTexts(array($value), substr($this->_refLang, 0, 2), substr($my_destlang, 0, 2)); |
|
230 | + else $val = utf8_decode($this->translateTexts(array($value), substr($this->_refLang, 0, 2), substr($my_destlang, 0, 2))); |
|
231 | 231 | } |
232 | 232 | |
233 | - $val=trim($val); |
|
233 | + $val = trim($val); |
|
234 | 234 | |
235 | 235 | if (empty($val)) return 0; |
236 | 236 | |
237 | - $this->_translatedFiles[$file][] = $key . '=' . $val ; |
|
237 | + $this->_translatedFiles[$file][] = $key.'='.$val; |
|
238 | 238 | return 1; |
239 | 239 | } |
240 | 240 | |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | */ |
247 | 247 | private function getLineKey($line) |
248 | 248 | { |
249 | - $arraykey = explode('=',$line,2); |
|
249 | + $arraykey = explode('=', $line, 2); |
|
250 | 250 | return trim($arraykey[0]); |
251 | 251 | } |
252 | 252 | |
@@ -258,8 +258,8 @@ discard block |
||
258 | 258 | */ |
259 | 259 | private function getLineValue($line) |
260 | 260 | { |
261 | - $arraykey = explode('=',$line,2); |
|
262 | - return trim(isset($arraykey[1])?$arraykey[1]:''); |
|
261 | + $arraykey = explode('=', $line, 2); |
|
262 | + return trim(isset($arraykey[1]) ? $arraykey[1] : ''); |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | /** |
@@ -271,9 +271,9 @@ discard block |
||
271 | 271 | private function getTranslationFilesArray($lang) |
272 | 272 | { |
273 | 273 | $dir = new DirectoryIterator($this->_langDir.$lang); |
274 | - while($dir->valid()) { |
|
275 | - if(!$dir->isDot() && $dir->isFile() && ! preg_match('/^\./',$dir->getFilename())) { |
|
276 | - $files[] = $dir->getFilename(); |
|
274 | + while ($dir->valid()) { |
|
275 | + if (!$dir->isDot() && $dir->isFile() && !preg_match('/^\./', $dir->getFilename())) { |
|
276 | + $files[] = $dir->getFilename(); |
|
277 | 277 | } |
278 | 278 | $dir->next(); |
279 | 279 | } |
@@ -291,16 +291,16 @@ discard block |
||
291 | 291 | private function translateTexts($src_texts, $src_lang, $dest_lang) |
292 | 292 | { |
293 | 293 | // We want to be sure that src_lang and dest_lang are using 2 chars only |
294 | - $tmp=explode('_',$src_lang); |
|
295 | - if (! empty($tmp[1]) && $tmp[0] == $tmp[1]) $src_lang=$tmp[0]; |
|
296 | - $tmp=explode('_',$dest_lang); |
|
297 | - if (! empty($tmp[1]) && $tmp[0] == $tmp[1]) $dest_lang=$tmp[0]; |
|
294 | + $tmp = explode('_', $src_lang); |
|
295 | + if (!empty($tmp[1]) && $tmp[0] == $tmp[1]) $src_lang = $tmp[0]; |
|
296 | + $tmp = explode('_', $dest_lang); |
|
297 | + if (!empty($tmp[1]) && $tmp[0] == $tmp[1]) $dest_lang = $tmp[0]; |
|
298 | 298 | |
299 | 299 | //setting language pair |
300 | 300 | $lang_pair = $src_lang.'|'.$dest_lang; |
301 | 301 | |
302 | - $src_text_to_translate=preg_replace('/%s/','SSSSS',implode('',$src_texts)); |
|
303 | - $src_text_to_translate=preg_replace('/'.preg_quote('\n\n').'/',' NNNNN ',$src_text_to_translate); |
|
302 | + $src_text_to_translate = preg_replace('/%s/', 'SSSSS', implode('', $src_texts)); |
|
303 | + $src_text_to_translate = preg_replace('/'.preg_quote('\n\n').'/', ' NNNNN ', $src_text_to_translate); |
|
304 | 304 | |
305 | 305 | // Define GET URL v1 |
306 | 306 | //$url = "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=".urlencode($src_text_to_translate)."&langpair=".urlencode($lang_pair); |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | // Send request |
313 | 313 | //print "Url to translate: ".$url."\n"; |
314 | 314 | |
315 | - if (! function_exists("curl_init")) |
|
315 | + if (!function_exists("curl_init")) |
|
316 | 316 | { |
317 | 317 | print "Error, your PHP does not support curl functions.\n"; |
318 | 318 | die(); |
@@ -329,17 +329,17 @@ discard block |
||
329 | 329 | // now, process the JSON string |
330 | 330 | $json = json_decode($body, true); |
331 | 331 | |
332 | - if ((! empty($json['responseStatus']) && $json['responseStatus'] != 200) |
|
332 | + if ((!empty($json['responseStatus']) && $json['responseStatus'] != 200) |
|
333 | 333 | || count($json['data']['translations']) == 0) |
334 | 334 | { |
335 | 335 | print "Error: ".$json['responseStatus']." ".$url."\n"; |
336 | 336 | return false; |
337 | 337 | } |
338 | 338 | |
339 | - $rep=$json['data']['translations'][0]['translatedText']; |
|
340 | - $rep=preg_replace('/SSSSS/i','%s',$rep); |
|
341 | - $rep=preg_replace('/NNNNN/i','\n\n',$rep); |
|
342 | - $rep=preg_replace('/'/i','\'',$rep); |
|
339 | + $rep = $json['data']['translations'][0]['translatedText']; |
|
340 | + $rep = preg_replace('/SSSSS/i', '%s', $rep); |
|
341 | + $rep = preg_replace('/NNNNN/i', '\n\n', $rep); |
|
342 | + $rep = preg_replace('/'/i', '\'', $rep); |
|
343 | 343 | |
344 | 344 | //print "OK ".join('',$src_texts).' => '.$rep."\n"; |
345 | 345 |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | |
22 | 22 | $sapi_type = php_sapi_name(); |
23 | 23 | $script_file = basename(__FILE__); |
24 | -$path=dirname(__FILE__).'/'; |
|
24 | +$path = dirname(__FILE__).'/'; |
|
25 | 25 | |
26 | 26 | // Test if batch mode |
27 | 27 | if (substr($sapi_type, 0, 3) == 'cgi') { |
@@ -30,25 +30,25 @@ discard block |
||
30 | 30 | } |
31 | 31 | |
32 | 32 | // Global variables |
33 | -$error=0; |
|
33 | +$error = 0; |
|
34 | 34 | |
35 | -$sourceserver=isset($argv[1])?$argv[1]:''; // user@server:/src/file |
|
36 | -$password=isset($argv[2])?$argv[2]:''; |
|
37 | -$dataserver=isset($argv[3])?$argv[3]:''; |
|
38 | -$database=isset($argv[4])?$argv[4]:''; |
|
39 | -$loginbase=isset($argv[5])?$argv[5]:''; |
|
40 | -$passwordbase=isset($argv[6])?$argv[6]:''; |
|
35 | +$sourceserver = isset($argv[1]) ? $argv[1] : ''; // user@server:/src/file |
|
36 | +$password = isset($argv[2]) ? $argv[2] : ''; |
|
37 | +$dataserver = isset($argv[3]) ? $argv[3] : ''; |
|
38 | +$database = isset($argv[4]) ? $argv[4] : ''; |
|
39 | +$loginbase = isset($argv[5]) ? $argv[5] : ''; |
|
40 | +$passwordbase = isset($argv[6]) ? $argv[6] : ''; |
|
41 | 41 | |
42 | 42 | // Include Dolibarr environment |
43 | -$res=0; |
|
44 | -if (! $res && file_exists($path."../../master.inc.php")) $res=@include $path."../../master.inc.php"; |
|
45 | -if (! $res && file_exists($path."../../htdocs/master.inc.php")) $res=@include $path."../../htdocs/master.inc.php"; |
|
46 | -if (! $res && file_exists("../master.inc.php")) $res=@include "../master.inc.php"; |
|
47 | -if (! $res && file_exists("../../master.inc.php")) $res=@include "../../master.inc.php"; |
|
48 | -if (! $res && file_exists("../../../master.inc.php")) $res=@include "../../../master.inc.php"; |
|
49 | -if (! $res && preg_match('/\/nltechno([^\/]*)\//',$_SERVER["PHP_SELF"],$reg)) $res=@include $path."../../../dolibarr".$reg[1]."/htdocs/master.inc.php"; // Used on dev env only |
|
50 | -if (! $res && preg_match('/\/nltechno([^\/]*)\//',$_SERVER["PHP_SELF"],$reg)) $res=@include "../../../dolibarr".$reg[1]."/htdocs/master.inc.php"; // Used on dev env only |
|
51 | -if (! $res) die ("Failed to include master.inc.php file\n"); |
|
43 | +$res = 0; |
|
44 | +if (!$res && file_exists($path."../../master.inc.php")) $res = @include $path."../../master.inc.php"; |
|
45 | +if (!$res && file_exists($path."../../htdocs/master.inc.php")) $res = @include $path."../../htdocs/master.inc.php"; |
|
46 | +if (!$res && file_exists("../master.inc.php")) $res = @include "../master.inc.php"; |
|
47 | +if (!$res && file_exists("../../master.inc.php")) $res = @include "../../master.inc.php"; |
|
48 | +if (!$res && file_exists("../../../master.inc.php")) $res = @include "../../../master.inc.php"; |
|
49 | +if (!$res && preg_match('/\/nltechno([^\/]*)\//', $_SERVER["PHP_SELF"], $reg)) $res = @include $path."../../../dolibarr".$reg[1]."/htdocs/master.inc.php"; // Used on dev env only |
|
50 | +if (!$res && preg_match('/\/nltechno([^\/]*)\//', $_SERVER["PHP_SELF"], $reg)) $res = @include "../../../dolibarr".$reg[1]."/htdocs/master.inc.php"; // Used on dev env only |
|
51 | +if (!$res) die ("Failed to include master.inc.php file\n"); |
|
52 | 52 | include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
53 | 53 | |
54 | 54 | |
@@ -56,14 +56,14 @@ discard block |
||
56 | 56 | * Main |
57 | 57 | */ |
58 | 58 | |
59 | -$login=''; |
|
60 | -$server=''; |
|
61 | -if (preg_match('/^(.*)@(.*):(.*)$/',$sourceserver,$reg)) |
|
59 | +$login = ''; |
|
60 | +$server = ''; |
|
61 | +if (preg_match('/^(.*)@(.*):(.*)$/', $sourceserver, $reg)) |
|
62 | 62 | { |
63 | - $login=$reg[1]; |
|
64 | - $server=$reg[2]; |
|
65 | - $sourcefile=$reg[3]; |
|
66 | - $targetfile=basename($sourcefile); |
|
63 | + $login = $reg[1]; |
|
64 | + $server = $reg[2]; |
|
65 | + $sourcefile = $reg[3]; |
|
66 | + $targetfile = basename($sourcefile); |
|
67 | 67 | } |
68 | 68 | if (empty($sourceserver) || empty($server) || empty($login) || empty($sourcefile) || empty($password) || empty($database) || empty($loginbase) || empty($passwordbase)) |
69 | 69 | { |
@@ -74,25 +74,25 @@ discard block |
||
74 | 74 | } |
75 | 75 | |
76 | 76 | |
77 | -$targetdir='/tmp'; |
|
77 | +$targetdir = '/tmp'; |
|
78 | 78 | print "Get dump file from server ".$server.", path ".$sourcefile.", connect with login ".$login." loaded into localhost\n"; |
79 | 79 | |
80 | -$sftpconnectstring=$sourceserver; |
|
80 | +$sftpconnectstring = $sourceserver; |
|
81 | 81 | print 'SFTP connect string : '.$sftpconnectstring."\n"; |
82 | 82 | //print 'SFTP password '.$password."\n"; |
83 | 83 | |
84 | 84 | |
85 | 85 | // SFTP connect |
86 | -if (! function_exists("ssh2_connect")) { |
|
87 | - dol_print_error('','ssh2_connect function does not exists'); exit(1); |
|
86 | +if (!function_exists("ssh2_connect")) { |
|
87 | + dol_print_error('', 'ssh2_connect function does not exists'); exit(1); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | $connection = ssh2_connect($server, 22); |
91 | 91 | if ($connection) |
92 | 92 | { |
93 | - if (! @ssh2_auth_password($connection, $login, $password)) |
|
93 | + if (!@ssh2_auth_password($connection, $login, $password)) |
|
94 | 94 | { |
95 | - dol_syslog("Could not authenticate with username ".$login." . and password ".preg_replace('/./', '*', $password),LOG_ERR); |
|
95 | + dol_syslog("Could not authenticate with username ".$login." . and password ".preg_replace('/./', '*', $password), LOG_ERR); |
|
96 | 96 | exit(-5); |
97 | 97 | } |
98 | 98 | else |
@@ -111,21 +111,21 @@ discard block |
||
111 | 111 | print 'Get file '.$sourcefile.' into '.$targetdir.$targetfile."\n"; |
112 | 112 | ssh2_scp_recv($connection, $sourcefile, $targetdir.$targetfile); |
113 | 113 | |
114 | - $fullcommand="cat ".$targetdir.$targetfile." | mysql -h".$databaseserver." -u".$loginbase." -p".$passwordbase." -D ".$database; |
|
115 | - if (preg_match('/\.bz2$/',$targetfile)) |
|
114 | + $fullcommand = "cat ".$targetdir.$targetfile." | mysql -h".$databaseserver." -u".$loginbase." -p".$passwordbase." -D ".$database; |
|
115 | + if (preg_match('/\.bz2$/', $targetfile)) |
|
116 | 116 | { |
117 | - $fullcommand="bzip2 -c -d ".$targetdir.$targetfile." | mysql -h".$databaseserver." -u".$loginbase." -p".$passwordbase." -D ".$database; |
|
117 | + $fullcommand = "bzip2 -c -d ".$targetdir.$targetfile." | mysql -h".$databaseserver." -u".$loginbase." -p".$passwordbase." -D ".$database; |
|
118 | 118 | } |
119 | - if (preg_match('/\.gz$/',$targetfile)) |
|
119 | + if (preg_match('/\.gz$/', $targetfile)) |
|
120 | 120 | { |
121 | - $fullcommand="gzip -d ".$targetdir.$targetfile." | mysql -h".$databaseserver." -u".$loginbase." -p".$passwordbase." -D ".$database; |
|
121 | + $fullcommand = "gzip -d ".$targetdir.$targetfile." | mysql -h".$databaseserver." -u".$loginbase." -p".$passwordbase." -D ".$database; |
|
122 | 122 | } |
123 | 123 | print "Load dump with ".$fullcommand."\n"; |
124 | - $output=array(); |
|
125 | - $return_var=0; |
|
124 | + $output = array(); |
|
125 | + $return_var = 0; |
|
126 | 126 | print strftime("%Y%m%d-%H%M%S").' '.$fullcommand."\n"; |
127 | 127 | exec($fullcommand, $output, $return_var); |
128 | - foreach($output as $line) print $line."\n"; |
|
128 | + foreach ($output as $line) print $line."\n"; |
|
129 | 129 | |
130 | 130 | //ssh2_sftp_unlink($sftp, $fileinstalllock); |
131 | 131 | //print $output; |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | |
22 | 22 | $sapi_type = php_sapi_name(); |
23 | 23 | $script_file = basename(__FILE__); |
24 | -$path=dirname(__FILE__).'/'; |
|
24 | +$path = dirname(__FILE__).'/'; |
|
25 | 25 | |
26 | 26 | // Test if batch mode |
27 | 27 | if (substr($sapi_type, 0, 3) == 'cgi') { |
@@ -30,20 +30,20 @@ discard block |
||
30 | 30 | } |
31 | 31 | |
32 | 32 | // Global variables |
33 | -$error=0; |
|
33 | +$error = 0; |
|
34 | 34 | |
35 | -$confirm=isset($argv[1])?$argv[1]:''; |
|
35 | +$confirm = isset($argv[1]) ? $argv[1] : ''; |
|
36 | 36 | |
37 | 37 | // Include Dolibarr environment |
38 | -$res=0; |
|
39 | -if (! $res && file_exists($path."../../master.inc.php")) $res=@include $path."../../master.inc.php"; |
|
40 | -if (! $res && file_exists($path."../../htdocs/master.inc.php")) $res=@include $path."../../htdocs/master.inc.php"; |
|
41 | -if (! $res && file_exists("../master.inc.php")) $res=@include "../master.inc.php"; |
|
42 | -if (! $res && file_exists("../../master.inc.php")) $res=@include "../../master.inc.php"; |
|
43 | -if (! $res && file_exists("../../../master.inc.php")) $res=@include "../../../master.inc.php"; |
|
44 | -if (! $res && preg_match('/\/nltechno([^\/]*)\//',$_SERVER["PHP_SELF"],$reg)) $res=@include $path."../../../dolibarr".$reg[1]."/htdocs/master.inc.php"; // Used on dev env only |
|
45 | -if (! $res && preg_match('/\/nltechno([^\/]*)\//',$_SERVER["PHP_SELF"],$reg)) $res=@include "../../../dolibarr".$reg[1]."/htdocs/master.inc.php"; // Used on dev env only |
|
46 | -if (! $res) die ("Failed to include master.inc.php file\n"); |
|
38 | +$res = 0; |
|
39 | +if (!$res && file_exists($path."../../master.inc.php")) $res = @include $path."../../master.inc.php"; |
|
40 | +if (!$res && file_exists($path."../../htdocs/master.inc.php")) $res = @include $path."../../htdocs/master.inc.php"; |
|
41 | +if (!$res && file_exists("../master.inc.php")) $res = @include "../master.inc.php"; |
|
42 | +if (!$res && file_exists("../../master.inc.php")) $res = @include "../../master.inc.php"; |
|
43 | +if (!$res && file_exists("../../../master.inc.php")) $res = @include "../../../master.inc.php"; |
|
44 | +if (!$res && preg_match('/\/nltechno([^\/]*)\//', $_SERVER["PHP_SELF"], $reg)) $res = @include $path."../../../dolibarr".$reg[1]."/htdocs/master.inc.php"; // Used on dev env only |
|
45 | +if (!$res && preg_match('/\/nltechno([^\/]*)\//', $_SERVER["PHP_SELF"], $reg)) $res = @include "../../../dolibarr".$reg[1]."/htdocs/master.inc.php"; // Used on dev env only |
|
46 | +if (!$res) die ("Failed to include master.inc.php file\n"); |
|
47 | 47 | include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
48 | 48 | |
49 | 49 | |
@@ -59,10 +59,10 @@ discard block |
||
59 | 59 | } |
60 | 60 | |
61 | 61 | |
62 | -$tmp=dol_getdate(dol_now()); |
|
62 | +$tmp = dol_getdate(dol_now()); |
|
63 | 63 | |
64 | 64 | |
65 | -$tables=array( |
|
65 | +$tables = array( |
|
66 | 66 | 'propal'=>array(0=>'datep', 1=>'fin_validite', 2=>'date_valid', 3=>'date_cloture'), |
67 | 67 | 'commande'=>array(0=>'date_commande', 1=>'date_valid', 2=>'date_cloture'), |
68 | 68 | 'facture'=>array(0=>'datef', 1=>'date_valid', 2=>'date_lim_reglement'), |
@@ -72,44 +72,44 @@ discard block |
||
72 | 72 | 'supplier_proposal'=>array(0=>'datec', 1=>'date_valid', 2=>'date_cloture') |
73 | 73 | ); |
74 | 74 | |
75 | -$year=2010; |
|
76 | -$currentyear=$tmp['year']; |
|
75 | +$year = 2010; |
|
76 | +$currentyear = $tmp['year']; |
|
77 | 77 | while ($year <= $currentyear) |
78 | 78 | { |
79 | 79 | //$year=2021; |
80 | - $delta=($currentyear - $year); |
|
80 | + $delta = ($currentyear - $year); |
|
81 | 81 | //$delta=-1; |
82 | 82 | |
83 | 83 | if ($delta) |
84 | 84 | { |
85 | - foreach($tables as $tablekey => $tableval) |
|
85 | + foreach ($tables as $tablekey => $tableval) |
|
86 | 86 | { |
87 | 87 | print "\nCorrect ".$tablekey." for year ".$year." and move them to current year ".$currentyear." "; |
88 | - $sql="select rowid from ".MAIN_DB_PREFIX.$tablekey." where ".$tableval[0]." between '".$year."-01-01' and '".$year."-12-31' and ".$tableval[0]." < DATE_ADD(NOW(), INTERVAL -1 YEAR)"; |
|
88 | + $sql = "select rowid from ".MAIN_DB_PREFIX.$tablekey." where ".$tableval[0]." between '".$year."-01-01' and '".$year."-12-31' and ".$tableval[0]." < DATE_ADD(NOW(), INTERVAL -1 YEAR)"; |
|
89 | 89 | //$sql="select rowid from ".MAIN_DB_PREFIX.$tablekey." where ".$tableval[0]." between '".$year."-01-01' and '".$year."-12-31' and ".$tableval[0]." > NOW()"; |
90 | 90 | $resql = $db->query($sql); |
91 | 91 | if ($resql) |
92 | 92 | { |
93 | 93 | $num = $db->num_rows($resql); |
94 | - $i=0; |
|
94 | + $i = 0; |
|
95 | 95 | while ($i < $num) |
96 | 96 | { |
97 | - $obj=$db->fetch_object($resql); |
|
97 | + $obj = $db->fetch_object($resql); |
|
98 | 98 | if ($obj) |
99 | 99 | { |
100 | 100 | print "."; |
101 | - $sql2="UPDATE ".MAIN_DB_PREFIX.$tablekey." set "; |
|
102 | - $j=0; |
|
103 | - foreach($tableval as $field) |
|
101 | + $sql2 = "UPDATE ".MAIN_DB_PREFIX.$tablekey." set "; |
|
102 | + $j = 0; |
|
103 | + foreach ($tableval as $field) |
|
104 | 104 | { |
105 | - if ($j) $sql2.=", "; |
|
106 | - $sql2.= $field." = DATE_ADD(".$field.", INTERVAL ".$delta." YEAR)"; |
|
105 | + if ($j) $sql2 .= ", "; |
|
106 | + $sql2 .= $field." = DATE_ADD(".$field.", INTERVAL ".$delta." YEAR)"; |
|
107 | 107 | $j++; |
108 | 108 | } |
109 | - $sql2.=" WHERE rowid = ".$obj->rowid; |
|
109 | + $sql2 .= " WHERE rowid = ".$obj->rowid; |
|
110 | 110 | //print $sql2."\n"; |
111 | 111 | $resql2 = $db->query($sql2); |
112 | - if (! $resql2) dol_print_error($db); |
|
112 | + if (!$resql2) dol_print_error($db); |
|
113 | 113 | } |
114 | 114 | $i++; |
115 | 115 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | |
34 | 34 | // Recupere root dolibarr |
35 | 35 | //$path=preg_replace('/generate-commande.php/i','',$_SERVER["PHP_SELF"]); |
36 | -require __DIR__. '/../../htdocs/master.inc.php'; |
|
36 | +require __DIR__.'/../../htdocs/master.inc.php'; |
|
37 | 37 | include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; |
38 | 38 | include_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; |
39 | 39 | include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; |
@@ -49,59 +49,59 @@ discard block |
||
49 | 49 | |
50 | 50 | define(GEN_NUMBER_COMMANDE, 10); |
51 | 51 | $year = 2016; |
52 | -$dates = array (mktime(12,0,0,1,3,$year), |
|
53 | - mktime(12,0,0,1,9,$year), |
|
54 | - mktime(12,0,0,2,13,$year), |
|
55 | - mktime(12,0,0,2,23,$year), |
|
56 | - mktime(12,0,0,3,30,$year), |
|
57 | - mktime(12,0,0,4,3,$year), |
|
58 | - mktime(12,0,0,4,3,$year), |
|
59 | - mktime(12,0,0,5,9,$year), |
|
60 | - mktime(12,0,0,5,1,$year), |
|
61 | - mktime(12,0,0,5,13,$year), |
|
62 | - mktime(12,0,0,5,19,$year), |
|
63 | - mktime(12,0,0,5,23,$year), |
|
64 | - mktime(12,0,0,6,3,$year), |
|
65 | - mktime(12,0,0,6,19,$year), |
|
66 | - mktime(12,0,0,6,24,$year), |
|
67 | - mktime(12,0,0,7,3,$year), |
|
68 | - mktime(12,0,0,7,9,$year), |
|
69 | - mktime(12,0,0,7,23,$year), |
|
70 | - mktime(12,0,0,7,30,$year), |
|
71 | - mktime(12,0,0,8,9,$year), |
|
72 | - mktime(12,0,0,9,23,$year), |
|
73 | - mktime(12,0,0,10,3,$year), |
|
74 | - mktime(12,0,0,11,12,$year), |
|
75 | - mktime(12,0,0,11,13,$year), |
|
76 | - mktime(12,0,0,1,3,($year - 1)), |
|
77 | - mktime(12,0,0,1,9,($year - 1)), |
|
78 | - mktime(12,0,0,2,13,($year - 1)), |
|
79 | - mktime(12,0,0,2,23,($year - 1)), |
|
80 | - mktime(12,0,0,3,30,($year - 1)), |
|
81 | - mktime(12,0,0,4,3,($year - 1)), |
|
82 | - mktime(12,0,0,4,3,($year - 1)), |
|
83 | - mktime(12,0,0,5,9,($year - 1)), |
|
84 | - mktime(12,0,0,5,1,($year - 1)), |
|
85 | - mktime(12,0,0,5,13,($year - 1)), |
|
86 | - mktime(12,0,0,5,19,($year - 1)), |
|
87 | - mktime(12,0,0,5,23,($year - 1)), |
|
88 | - mktime(12,0,0,6,3,($year - 1)), |
|
89 | - mktime(12,0,0,6,19,($year - 1)), |
|
90 | - mktime(12,0,0,6,24,($year - 1)), |
|
91 | - mktime(12,0,0,7,3,($year - 1)), |
|
92 | - mktime(12,0,0,7,9,($year - 1)), |
|
93 | - mktime(12,0,0,7,23,($year - 1)), |
|
94 | - mktime(12,0,0,7,30,($year - 1)), |
|
95 | - mktime(12,0,0,8,9,($year - 1)), |
|
96 | - mktime(12,0,0,9,23,($year - 1)), |
|
97 | - mktime(12,0,0,10,3,($year - 1)), |
|
98 | - mktime(12,0,0,11,12,$year), |
|
99 | - mktime(12,0,0,11,13,$year), |
|
100 | - mktime(12,0,0,12,12,$year), |
|
101 | - mktime(12,0,0,12,13,$year), |
|
52 | +$dates = array(mktime(12, 0, 0, 1, 3, $year), |
|
53 | + mktime(12, 0, 0, 1, 9, $year), |
|
54 | + mktime(12, 0, 0, 2, 13, $year), |
|
55 | + mktime(12, 0, 0, 2, 23, $year), |
|
56 | + mktime(12, 0, 0, 3, 30, $year), |
|
57 | + mktime(12, 0, 0, 4, 3, $year), |
|
58 | + mktime(12, 0, 0, 4, 3, $year), |
|
59 | + mktime(12, 0, 0, 5, 9, $year), |
|
60 | + mktime(12, 0, 0, 5, 1, $year), |
|
61 | + mktime(12, 0, 0, 5, 13, $year), |
|
62 | + mktime(12, 0, 0, 5, 19, $year), |
|
63 | + mktime(12, 0, 0, 5, 23, $year), |
|
64 | + mktime(12, 0, 0, 6, 3, $year), |
|
65 | + mktime(12, 0, 0, 6, 19, $year), |
|
66 | + mktime(12, 0, 0, 6, 24, $year), |
|
67 | + mktime(12, 0, 0, 7, 3, $year), |
|
68 | + mktime(12, 0, 0, 7, 9, $year), |
|
69 | + mktime(12, 0, 0, 7, 23, $year), |
|
70 | + mktime(12, 0, 0, 7, 30, $year), |
|
71 | + mktime(12, 0, 0, 8, 9, $year), |
|
72 | + mktime(12, 0, 0, 9, 23, $year), |
|
73 | + mktime(12, 0, 0, 10, 3, $year), |
|
74 | + mktime(12, 0, 0, 11, 12, $year), |
|
75 | + mktime(12, 0, 0, 11, 13, $year), |
|
76 | + mktime(12, 0, 0, 1, 3, ($year - 1)), |
|
77 | + mktime(12, 0, 0, 1, 9, ($year - 1)), |
|
78 | + mktime(12, 0, 0, 2, 13, ($year - 1)), |
|
79 | + mktime(12, 0, 0, 2, 23, ($year - 1)), |
|
80 | + mktime(12, 0, 0, 3, 30, ($year - 1)), |
|
81 | + mktime(12, 0, 0, 4, 3, ($year - 1)), |
|
82 | + mktime(12, 0, 0, 4, 3, ($year - 1)), |
|
83 | + mktime(12, 0, 0, 5, 9, ($year - 1)), |
|
84 | + mktime(12, 0, 0, 5, 1, ($year - 1)), |
|
85 | + mktime(12, 0, 0, 5, 13, ($year - 1)), |
|
86 | + mktime(12, 0, 0, 5, 19, ($year - 1)), |
|
87 | + mktime(12, 0, 0, 5, 23, ($year - 1)), |
|
88 | + mktime(12, 0, 0, 6, 3, ($year - 1)), |
|
89 | + mktime(12, 0, 0, 6, 19, ($year - 1)), |
|
90 | + mktime(12, 0, 0, 6, 24, ($year - 1)), |
|
91 | + mktime(12, 0, 0, 7, 3, ($year - 1)), |
|
92 | + mktime(12, 0, 0, 7, 9, ($year - 1)), |
|
93 | + mktime(12, 0, 0, 7, 23, ($year - 1)), |
|
94 | + mktime(12, 0, 0, 7, 30, ($year - 1)), |
|
95 | + mktime(12, 0, 0, 8, 9, ($year - 1)), |
|
96 | + mktime(12, 0, 0, 9, 23, ($year - 1)), |
|
97 | + mktime(12, 0, 0, 10, 3, ($year - 1)), |
|
98 | + mktime(12, 0, 0, 11, 12, $year), |
|
99 | + mktime(12, 0, 0, 11, 13, $year), |
|
100 | + mktime(12, 0, 0, 12, 12, $year), |
|
101 | + mktime(12, 0, 0, 12, 13, $year), |
|
102 | 102 | ); |
103 | 103 | |
104 | -$ret=$user->fetch('','admin'); |
|
104 | +$ret = $user->fetch('', 'admin'); |
|
105 | 105 | if ($ret <= 0) |
106 | 106 | { |
107 | 107 | print 'A user with login "admin" and all permissions must be created to use this script.'."\n"; |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | |
112 | 112 | $societesid = array(); |
113 | 113 | $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe where client in (1, 3)"; |
114 | -$resql=$db->query($sql); |
|
114 | +$resql = $db->query($sql); |
|
115 | 115 | if ($resql) { |
116 | 116 | $num_thirdparties = $db->num_rows($resql); |
117 | 117 | $i = 0; |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | |
126 | 126 | $commandesid = array(); |
127 | 127 | $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."commande"; |
128 | -$resql=$db->query($sql); |
|
128 | +$resql = $db->query($sql); |
|
129 | 129 | if ($resql) { |
130 | 130 | $num = $db->num_rows($resql); |
131 | 131 | $i = 0; |
@@ -157,14 +157,14 @@ discard block |
||
157 | 157 | |
158 | 158 | |
159 | 159 | print "Build ".GEN_NUMBER_COMMANDE." orders\n"; |
160 | -for ($s = 0 ; $s < GEN_NUMBER_COMMANDE ; $s++) |
|
160 | +for ($s = 0; $s < GEN_NUMBER_COMMANDE; $s++) |
|
161 | 161 | { |
162 | 162 | print "Process order ".$s."\n"; |
163 | 163 | |
164 | 164 | $object = new Commande($db); |
165 | 165 | |
166 | 166 | $object->socid = $societesid[mt_rand(1, $num_thirdparties)]; |
167 | - $object->date_commande = $dates[mt_rand(1, count($dates)-1)]; |
|
167 | + $object->date_commande = $dates[mt_rand(1, count($dates) - 1)]; |
|
168 | 168 | $object->note = 'My small comment about this order. Hum. Nothing.'; |
169 | 169 | $object->source = 1; |
170 | 170 | $object->fk_project = 0; |
@@ -174,15 +174,15 @@ discard block |
||
174 | 174 | $object->more_reglement_id = mt_rand(0, 7); |
175 | 175 | $object->availability_id = mt_rand(0, 1); |
176 | 176 | |
177 | - $listofuserid=array(12,13,16); |
|
177 | + $listofuserid = array(12, 13, 16); |
|
178 | 178 | |
179 | 179 | $fuser = new User($db); |
180 | - $fuser->fetch($listofuserid[mt_rand(0,2)]); |
|
180 | + $fuser->fetch($listofuserid[mt_rand(0, 2)]); |
|
181 | 181 | $fuser->getRights(); |
182 | 182 | |
183 | 183 | $db->begin(); |
184 | 184 | |
185 | - $result=$object->create($fuser); |
|
185 | + $result = $object->create($fuser); |
|
186 | 186 | if ($result >= 0) |
187 | 187 | { |
188 | 188 | $nbp = mt_rand(2, 5); |
@@ -190,17 +190,17 @@ discard block |
||
190 | 190 | while ($xnbp < $nbp) |
191 | 191 | { |
192 | 192 | $prodid = mt_rand(1, $num_prods); |
193 | - $product=new Product($db); |
|
194 | - $result=$product->fetch($prodids[$prodid]); |
|
195 | - $result=$object->addline($product->description, $product->price, mt_rand(1,5), 0, 0, 0, $prodids[$prodid], 0, 0, 0, $product->price_base_type, $product->price_ttc, '', '', $product->type); |
|
193 | + $product = new Product($db); |
|
194 | + $result = $product->fetch($prodids[$prodid]); |
|
195 | + $result = $object->addline($product->description, $product->price, mt_rand(1, 5), 0, 0, 0, $prodids[$prodid], 0, 0, 0, $product->price_base_type, $product->price_ttc, '', '', $product->type); |
|
196 | 196 | if ($result <= 0) |
197 | 197 | { |
198 | - dol_print_error($db,$object->error); |
|
198 | + dol_print_error($db, $object->error); |
|
199 | 199 | } |
200 | 200 | $xnbp++; |
201 | 201 | } |
202 | 202 | |
203 | - $result=$object->valid($fuser); |
|
203 | + $result = $object->valid($fuser); |
|
204 | 204 | if ($result > 0) |
205 | 205 | { |
206 | 206 | $db->commit(); |
@@ -210,14 +210,14 @@ discard block |
||
210 | 210 | { |
211 | 211 | print " KO\n"; |
212 | 212 | $db->rollback(); |
213 | - dol_print_error($db,$object->error); |
|
213 | + dol_print_error($db, $object->error); |
|
214 | 214 | } |
215 | 215 | } |
216 | 216 | else |
217 | 217 | { |
218 | 218 | print " KO\n"; |
219 | 219 | $db->rollback(); |
220 | - dol_print_error($db,$object->error); |
|
220 | + dol_print_error($db, $object->error); |
|
221 | 221 | } |
222 | 222 | } |
223 | 223 |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | |
27 | 27 | $sapi_type = php_sapi_name(); |
28 | 28 | $script_file = basename(__FILE__); |
29 | -$path=dirname(__FILE__).'/'; |
|
29 | +$path = dirname(__FILE__).'/'; |
|
30 | 30 | |
31 | 31 | // Test si mode batch |
32 | 32 | if (substr($sapi_type, 0, 3) == 'cgi') { |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | } |
36 | 36 | |
37 | 37 | // Recupere root dolibarr |
38 | -$path=preg_replace('/purge-data.php/i','',$_SERVER["PHP_SELF"]); |
|
38 | +$path = preg_replace('/purge-data.php/i', '', $_SERVER["PHP_SELF"]); |
|
39 | 39 | require $path."../../htdocs/master.inc.php"; |
40 | 40 | include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; |
41 | 41 | include_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; |
@@ -47,11 +47,11 @@ discard block |
||
47 | 47 | $langs->loadLangs(array("main", "errors")); |
48 | 48 | |
49 | 49 | // Global variables |
50 | -$version=DOL_VERSION; |
|
51 | -$error=0; |
|
50 | +$version = DOL_VERSION; |
|
51 | +$error = 0; |
|
52 | 52 | |
53 | 53 | // List of sql to execute |
54 | -$sqls=array( |
|
54 | +$sqls = array( |
|
55 | 55 | 'user'=>array( |
56 | 56 | 'DELETE FROM '.MAIN_DB_PREFIX."user_rights WHERE fk_user IN (SELECT rowid FROM ".MAIN_DB_PREFIX."user WHERE admin = 0 and login != 'admin')", |
57 | 57 | 'DELETE FROM '.MAIN_DB_PREFIX."user WHERE admin = 0 and login != 'admin'", |
@@ -150,37 +150,37 @@ discard block |
||
150 | 150 | |
151 | 151 | @set_time_limit(0); |
152 | 152 | print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n"; |
153 | -dol_syslog($script_file." launched with arg ".implode(',',$argv)); |
|
153 | +dol_syslog($script_file." launched with arg ".implode(',', $argv)); |
|
154 | 154 | |
155 | 155 | $mode = $argv[1]; |
156 | 156 | $option = $argv[2]; |
157 | 157 | |
158 | -if (empty($mode) || ! in_array($mode,array('test','confirm'))) { |
|
158 | +if (empty($mode) || !in_array($mode, array('test', 'confirm'))) { |
|
159 | 159 | print "Usage: $script_file (test|confirm) (all|option) [dbtype dbhost dbuser dbpassword dbname dbport]\n"; |
160 | 160 | print "\n"; |
161 | - print "option can be ".implode(',',array_keys($sqls))."\n"; |
|
161 | + print "option can be ".implode(',', array_keys($sqls))."\n"; |
|
162 | 162 | exit(-1); |
163 | 163 | } |
164 | 164 | |
165 | -if (empty($option) || ! in_array($option, array_merge(array('all'),array_keys($sqls))) ) { |
|
165 | +if (empty($option) || !in_array($option, array_merge(array('all'), array_keys($sqls)))) { |
|
166 | 166 | print "Usage: $script_file (test|confirm) (all|option) [dbtype dbhost dbuser dbpassword dbname dbport]\n"; |
167 | 167 | print "\n"; |
168 | - print "option can be ".implode(',',array_keys($sqls))."\n"; |
|
168 | + print "option can be ".implode(',', array_keys($sqls))."\n"; |
|
169 | 169 | exit(-1); |
170 | 170 | } |
171 | 171 | |
172 | 172 | // Replace database handler |
173 | -if (! empty($argv[3])) |
|
173 | +if (!empty($argv[3])) |
|
174 | 174 | { |
175 | 175 | $db->close(); |
176 | 176 | unset($db); |
177 | - $db=getDoliDBInstance($argv[3], $argv[4], $argv[5], $argv[6], $argv[7], $argv[8]); |
|
178 | - $user=new User($db); |
|
177 | + $db = getDoliDBInstance($argv[3], $argv[4], $argv[5], $argv[6], $argv[7], $argv[8]); |
|
178 | + $user = new User($db); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | //var_dump($user->db->database_name); |
182 | -$ret=$user->fetch('','admin'); |
|
183 | -if (! $ret > 0) |
|
182 | +$ret = $user->fetch('', 'admin'); |
|
183 | +if (!$ret > 0) |
|
184 | 184 | { |
185 | 185 | print 'An admin user with login "admin" must exists to use this script.'."\n"; |
186 | 186 | exit; |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | print "User = ".$db->database_user."\n"; |
196 | 196 | print "\n"; |
197 | 197 | |
198 | -if (! $confirmed) |
|
198 | +if (!$confirmed) |
|
199 | 199 | { |
200 | 200 | print "Hit Enter to continue or CTRL+C to stop...\n"; |
201 | 201 | $input = trim(fgets(STDIN)); |
@@ -212,19 +212,19 @@ discard block |
||
212 | 212 | { |
213 | 213 | global $db, $sqls; |
214 | 214 | |
215 | - $error=0; |
|
216 | - foreach($sqls[$family] as $sql) |
|
215 | + $error = 0; |
|
216 | + foreach ($sqls[$family] as $sql) |
|
217 | 217 | { |
218 | - if (preg_match('/^@/',$sql)) |
|
218 | + if (preg_match('/^@/', $sql)) |
|
219 | 219 | { |
220 | - $newfamily=preg_replace('/@/','',$sql); |
|
220 | + $newfamily = preg_replace('/@/', '', $sql); |
|
221 | 221 | processfamily($newfamily); |
222 | 222 | continue; |
223 | 223 | } |
224 | 224 | |
225 | 225 | print "Run sql: ".$sql."\n"; |
226 | - $resql=$db->query($sql); |
|
227 | - if (! $resql) |
|
226 | + $resql = $db->query($sql); |
|
227 | + if (!$resql) |
|
228 | 228 | { |
229 | 229 | if ($db->errno() != 'DB_ERROR_NOSUCHTABLE') |
230 | 230 | { |
@@ -247,15 +247,15 @@ discard block |
||
247 | 247 | |
248 | 248 | $db->begin(); |
249 | 249 | |
250 | -$oldfamily=''; |
|
251 | -foreach($sqls as $family => $familysql) |
|
250 | +$oldfamily = ''; |
|
251 | +foreach ($sqls as $family => $familysql) |
|
252 | 252 | { |
253 | 253 | if ($option && $option != 'all' && $option != $family) continue; |
254 | 254 | |
255 | 255 | if ($family != $oldfamily) print "Process action for family ".$family."\n"; |
256 | 256 | $oldfamily = $family; |
257 | 257 | |
258 | - $result=processfamily($family); |
|
258 | + $result = processfamily($family); |
|
259 | 259 | if ($result < 0) |
260 | 260 | { |
261 | 261 | $error++; |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | |
33 | 33 | // Recupere root dolibarr |
34 | 34 | //$path=preg_replace('/generate-produit.php/i','',$_SERVER["PHP_SELF"]); |
35 | -require __DIR__. '/../../htdocs/master.inc.php'; |
|
35 | +require __DIR__.'/../../htdocs/master.inc.php'; |
|
36 | 36 | require_once DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php"; |
37 | 37 | require_once DOL_DOCUMENT_ROOT."/societe/class/societe.class.php"; |
38 | 38 | |
@@ -43,60 +43,60 @@ discard block |
||
43 | 43 | |
44 | 44 | define(GEN_NUMBER_FACTURE, 1); |
45 | 45 | $year = 2016; |
46 | -$dates = array (mktime(12,0,0,1,3,$year), |
|
47 | - mktime(12,0,0,1,9,$year), |
|
48 | - mktime(12,0,0,2,13,$year), |
|
49 | - mktime(12,0,0,2,23,$year), |
|
50 | - mktime(12,0,0,3,30,$year), |
|
51 | - mktime(12,0,0,4,3,$year), |
|
52 | - mktime(12,0,0,4,3,$year), |
|
53 | - mktime(12,0,0,5,9,$year), |
|
54 | - mktime(12,0,0,5,1,$year), |
|
55 | - mktime(12,0,0,5,13,$year), |
|
56 | - mktime(12,0,0,5,19,$year), |
|
57 | - mktime(12,0,0,5,23,$year), |
|
58 | - mktime(12,0,0,6,3,$year), |
|
59 | - mktime(12,0,0,6,19,$year), |
|
60 | - mktime(12,0,0,6,24,$year), |
|
61 | - mktime(12,0,0,7,3,$year), |
|
62 | - mktime(12,0,0,7,9,$year), |
|
63 | - mktime(12,0,0,7,23,$year), |
|
64 | - mktime(12,0,0,7,30,$year), |
|
65 | - mktime(12,0,0,8,9,$year), |
|
66 | - mktime(12,0,0,9,23,$year), |
|
67 | - mktime(12,0,0,10,3,$year), |
|
68 | - mktime(12,0,0,11,12,$year), |
|
69 | - mktime(12,0,0,11,13,$year), |
|
70 | - mktime(12,0,0,1,3,($year - 1)), |
|
71 | - mktime(12,0,0,1,9,($year - 1)), |
|
72 | - mktime(12,0,0,2,13,($year - 1)), |
|
73 | - mktime(12,0,0,2,23,($year - 1)), |
|
74 | - mktime(12,0,0,3,30,($year - 1)), |
|
75 | - mktime(12,0,0,4,3,($year - 1)), |
|
76 | - mktime(12,0,0,4,3,($year - 1)), |
|
77 | - mktime(12,0,0,5,9,($year - 1)), |
|
78 | - mktime(12,0,0,5,1,($year - 1)), |
|
79 | - mktime(12,0,0,5,13,($year - 1)), |
|
80 | - mktime(12,0,0,5,19,($year - 1)), |
|
81 | - mktime(12,0,0,5,23,($year - 1)), |
|
82 | - mktime(12,0,0,6,3,($year - 1)), |
|
83 | - mktime(12,0,0,6,19,($year - 1)), |
|
84 | - mktime(12,0,0,6,24,($year - 1)), |
|
85 | - mktime(12,0,0,7,3,($year - 1)), |
|
86 | - mktime(12,0,0,7,9,($year - 1)), |
|
87 | - mktime(12,0,0,7,23,($year - 1)), |
|
88 | - mktime(12,0,0,7,30,($year - 1)), |
|
89 | - mktime(12,0,0,8,9,($year - 1)), |
|
90 | - mktime(12,0,0,9,23,($year - 1)), |
|
91 | - mktime(12,0,0,10,3,($year - 1)), |
|
92 | - mktime(12,0,0,11,12,$year), |
|
93 | - mktime(12,0,0,11,13,$year), |
|
94 | - mktime(12,0,0,12,12,$year), |
|
95 | - mktime(12,0,0,12,13,$year), |
|
46 | +$dates = array(mktime(12, 0, 0, 1, 3, $year), |
|
47 | + mktime(12, 0, 0, 1, 9, $year), |
|
48 | + mktime(12, 0, 0, 2, 13, $year), |
|
49 | + mktime(12, 0, 0, 2, 23, $year), |
|
50 | + mktime(12, 0, 0, 3, 30, $year), |
|
51 | + mktime(12, 0, 0, 4, 3, $year), |
|
52 | + mktime(12, 0, 0, 4, 3, $year), |
|
53 | + mktime(12, 0, 0, 5, 9, $year), |
|
54 | + mktime(12, 0, 0, 5, 1, $year), |
|
55 | + mktime(12, 0, 0, 5, 13, $year), |
|
56 | + mktime(12, 0, 0, 5, 19, $year), |
|
57 | + mktime(12, 0, 0, 5, 23, $year), |
|
58 | + mktime(12, 0, 0, 6, 3, $year), |
|
59 | + mktime(12, 0, 0, 6, 19, $year), |
|
60 | + mktime(12, 0, 0, 6, 24, $year), |
|
61 | + mktime(12, 0, 0, 7, 3, $year), |
|
62 | + mktime(12, 0, 0, 7, 9, $year), |
|
63 | + mktime(12, 0, 0, 7, 23, $year), |
|
64 | + mktime(12, 0, 0, 7, 30, $year), |
|
65 | + mktime(12, 0, 0, 8, 9, $year), |
|
66 | + mktime(12, 0, 0, 9, 23, $year), |
|
67 | + mktime(12, 0, 0, 10, 3, $year), |
|
68 | + mktime(12, 0, 0, 11, 12, $year), |
|
69 | + mktime(12, 0, 0, 11, 13, $year), |
|
70 | + mktime(12, 0, 0, 1, 3, ($year - 1)), |
|
71 | + mktime(12, 0, 0, 1, 9, ($year - 1)), |
|
72 | + mktime(12, 0, 0, 2, 13, ($year - 1)), |
|
73 | + mktime(12, 0, 0, 2, 23, ($year - 1)), |
|
74 | + mktime(12, 0, 0, 3, 30, ($year - 1)), |
|
75 | + mktime(12, 0, 0, 4, 3, ($year - 1)), |
|
76 | + mktime(12, 0, 0, 4, 3, ($year - 1)), |
|
77 | + mktime(12, 0, 0, 5, 9, ($year - 1)), |
|
78 | + mktime(12, 0, 0, 5, 1, ($year - 1)), |
|
79 | + mktime(12, 0, 0, 5, 13, ($year - 1)), |
|
80 | + mktime(12, 0, 0, 5, 19, ($year - 1)), |
|
81 | + mktime(12, 0, 0, 5, 23, ($year - 1)), |
|
82 | + mktime(12, 0, 0, 6, 3, ($year - 1)), |
|
83 | + mktime(12, 0, 0, 6, 19, ($year - 1)), |
|
84 | + mktime(12, 0, 0, 6, 24, ($year - 1)), |
|
85 | + mktime(12, 0, 0, 7, 3, ($year - 1)), |
|
86 | + mktime(12, 0, 0, 7, 9, ($year - 1)), |
|
87 | + mktime(12, 0, 0, 7, 23, ($year - 1)), |
|
88 | + mktime(12, 0, 0, 7, 30, ($year - 1)), |
|
89 | + mktime(12, 0, 0, 8, 9, ($year - 1)), |
|
90 | + mktime(12, 0, 0, 9, 23, ($year - 1)), |
|
91 | + mktime(12, 0, 0, 10, 3, ($year - 1)), |
|
92 | + mktime(12, 0, 0, 11, 12, $year), |
|
93 | + mktime(12, 0, 0, 11, 13, $year), |
|
94 | + mktime(12, 0, 0, 12, 12, $year), |
|
95 | + mktime(12, 0, 0, 12, 13, $year), |
|
96 | 96 | ); |
97 | 97 | |
98 | -$ret=$user->fetch('','admin'); |
|
99 | -if (! $ret > 0) |
|
98 | +$ret = $user->fetch('', 'admin'); |
|
99 | +if (!$ret > 0) |
|
100 | 100 | { |
101 | 101 | print 'A user with login "admin" and all permissions must be created to use this script.'."\n"; |
102 | 102 | exit; |
@@ -134,8 +134,8 @@ discard block |
||
134 | 134 | } |
135 | 135 | } |
136 | 136 | |
137 | -$i=0; |
|
138 | -$result=0; |
|
137 | +$i = 0; |
|
138 | +$result = 0; |
|
139 | 139 | while ($i < GEN_NUMBER_FACTURE && $result >= 0) |
140 | 140 | { |
141 | 141 | $i++; |
@@ -145,15 +145,15 @@ discard block |
||
145 | 145 | |
146 | 146 | $object = new Facture($db); |
147 | 147 | $object->socid = $socids[$socid]; |
148 | - $object->date = $dates[mt_rand(1, count($dates)-1)]; |
|
148 | + $object->date = $dates[mt_rand(1, count($dates) - 1)]; |
|
149 | 149 | $object->cond_reglement_id = 3; |
150 | 150 | $object->mode_reglement_id = 3; |
151 | 151 | |
152 | 152 | $fuser = new User($db); |
153 | - $fuser->fetch(mt_rand(1,2)); |
|
153 | + $fuser->fetch(mt_rand(1, 2)); |
|
154 | 154 | $fuser->getRights(); |
155 | 155 | |
156 | - $result=$object->create($fuser); |
|
156 | + $result = $object->create($fuser); |
|
157 | 157 | if ($result >= 0) |
158 | 158 | { |
159 | 159 | $nbp = mt_rand(2, 5); |
@@ -161,28 +161,28 @@ discard block |
||
161 | 161 | while ($xnbp < $nbp) |
162 | 162 | { |
163 | 163 | $prodid = mt_rand(1, $num_prods); |
164 | - $product=new Product($db); |
|
165 | - $result=$product->fetch($prodids[$prodid]); |
|
166 | - $result=$object->addline($product->description, $product->price, mt_rand(1,5), 0, 0, 0, $prodids[$prodid], 0, '', '', 0, 0, '', $product->price_base_type, $product->price_ttc, $product->type); |
|
164 | + $product = new Product($db); |
|
165 | + $result = $product->fetch($prodids[$prodid]); |
|
166 | + $result = $object->addline($product->description, $product->price, mt_rand(1, 5), 0, 0, 0, $prodids[$prodid], 0, '', '', 0, 0, '', $product->price_base_type, $product->price_ttc, $product->type); |
|
167 | 167 | if ($result < 0) |
168 | 168 | { |
169 | - dol_print_error($db,$propal->error); |
|
169 | + dol_print_error($db, $propal->error); |
|
170 | 170 | } |
171 | 171 | $xnbp++; |
172 | 172 | } |
173 | 173 | |
174 | - $result=$object->validate($fuser); |
|
174 | + $result = $object->validate($fuser); |
|
175 | 175 | if ($result) |
176 | 176 | { |
177 | - print " OK with ref ".$object->ref."\n";; |
|
177 | + print " OK with ref ".$object->ref."\n"; ; |
|
178 | 178 | } |
179 | 179 | else |
180 | 180 | { |
181 | - dol_print_error($db,$object->error); |
|
181 | + dol_print_error($db, $object->error); |
|
182 | 182 | } |
183 | 183 | } |
184 | 184 | else |
185 | 185 | { |
186 | - dol_print_error($db,$object->error); |
|
186 | + dol_print_error($db, $object->error); |
|
187 | 187 | } |
188 | 188 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | |
34 | 34 | // Recupere root dolibarr |
35 | 35 | //$path=preg_replace('/generate-societe.php/i','',$_SERVER["PHP_SELF"]); |
36 | -require __DIR__. '/../../htdocs/master.inc.php'; |
|
36 | +require __DIR__.'/../../htdocs/master.inc.php'; |
|
37 | 37 | include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; |
38 | 38 | include_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; |
39 | 39 | include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; |
@@ -41,8 +41,8 @@ discard block |
||
41 | 41 | include_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; |
42 | 42 | include_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php'; |
43 | 43 | |
44 | -$listoftown = array("Auray","Baden","Vannes","Pirouville","Haguenau","Souffelweiersheim","Illkirch-Graffenstaden","Lauterbourg","Picauville","Sainte-Mère Eglise","Le Bono"); |
|
45 | -$listoflastname = array("Joe","Marc","Steve","Laurent","Nico","Isabelle","Dorothee","Saby","Brigitte","Karine","Jose-Anne","Celine","Virginie"); |
|
44 | +$listoftown = array("Auray", "Baden", "Vannes", "Pirouville", "Haguenau", "Souffelweiersheim", "Illkirch-Graffenstaden", "Lauterbourg", "Picauville", "Sainte-Mère Eglise", "Le Bono"); |
|
45 | +$listoflastname = array("Joe", "Marc", "Steve", "Laurent", "Nico", "Isabelle", "Dorothee", "Saby", "Brigitte", "Karine", "Jose-Anne", "Celine", "Virginie"); |
|
46 | 46 | |
47 | 47 | |
48 | 48 | /* |
@@ -52,8 +52,8 @@ discard block |
||
52 | 52 | define(GEN_NUMBER_SOCIETE, 10); |
53 | 53 | |
54 | 54 | |
55 | -$ret=$user->fetch('','admin'); |
|
56 | -if (! $ret > 0) |
|
55 | +$ret = $user->fetch('', 'admin'); |
|
56 | +if (!$ret > 0) |
|
57 | 57 | { |
58 | 58 | print 'A user with login "admin" and all permissions must be created to use this script.'."\n"; |
59 | 59 | exit; |
@@ -62,59 +62,59 @@ discard block |
||
62 | 62 | |
63 | 63 | |
64 | 64 | $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product"; $productsid = array(); |
65 | -$resql=$db->query($sql); |
|
65 | +$resql = $db->query($sql); |
|
66 | 66 | if ($resql) { |
67 | 67 | $num = $db->num_rows($resql); $i = 0; |
68 | - while ($i < $num) { $row = $db->fetch_row($resql); $productsid[$i] = $row[0]; $i++; } |
|
68 | + while ($i < $num) { $row = $db->fetch_row($resql); $productsid[$i] = $row[0]; $i++; } |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe"; $societesid = array(); |
72 | -$resql=$db->query($sql); |
|
72 | +$resql = $db->query($sql); |
|
73 | 73 | if ($resql) { |
74 | 74 | $num = $db->num_rows($resql); $i = 0; |
75 | - while ($i < $num) { $row = $db->fetch_row($resql); $societesid[$i] = $row[0]; $i++; } |
|
75 | + while ($i < $num) { $row = $db->fetch_row($resql); $societesid[$i] = $row[0]; $i++; } |
|
76 | 76 | } else { print "err"; } |
77 | 77 | |
78 | 78 | $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."commande"; $commandesid = array(); |
79 | -$resql=$db->query($sql); |
|
79 | +$resql = $db->query($sql); |
|
80 | 80 | if ($resql) { |
81 | 81 | $num = $db->num_rows($resql); $i = 0; |
82 | - while ($i < $num) { $row = $db->fetch_row($resql); $commandesid[$i] = $row[0]; $i++; } |
|
82 | + while ($i < $num) { $row = $db->fetch_row($resql); $commandesid[$i] = $row[0]; $i++; } |
|
83 | 83 | } else { print "err"; } |
84 | 84 | |
85 | 85 | |
86 | 86 | |
87 | 87 | print "Generates ".GEN_NUMBER_SOCIETE." companies\n"; |
88 | -for ($s = 0 ; $s < GEN_NUMBER_SOCIETE ; $s++) |
|
88 | +for ($s = 0; $s < GEN_NUMBER_SOCIETE; $s++) |
|
89 | 89 | { |
90 | 90 | print "Company $s\n"; |
91 | 91 | $soc = new Societe($db); |
92 | 92 | $soc->name = "Company num ".time()."$s"; |
93 | - $soc->town = $listoftown[mt_rand(0, count($listoftown)-1)]; |
|
94 | - $soc->client = mt_rand(1,2); // Une societe sur 2 est prospect, l'autre client |
|
95 | - $soc->fournisseur = mt_rand(0,1); // Une societe sur 2 est fournisseur |
|
96 | - $soc->code_client='CU'.time()."$s"; |
|
97 | - $soc->code_fournisseur='SU'.time()."$s"; |
|
98 | - $soc->tva_assuj=1; |
|
99 | - $soc->country_id=1; |
|
100 | - $soc->country_code='FR'; |
|
93 | + $soc->town = $listoftown[mt_rand(0, count($listoftown) - 1)]; |
|
94 | + $soc->client = mt_rand(1, 2); // Une societe sur 2 est prospect, l'autre client |
|
95 | + $soc->fournisseur = mt_rand(0, 1); // Une societe sur 2 est fournisseur |
|
96 | + $soc->code_client = 'CU'.time()."$s"; |
|
97 | + $soc->code_fournisseur = 'SU'.time()."$s"; |
|
98 | + $soc->tva_assuj = 1; |
|
99 | + $soc->country_id = 1; |
|
100 | + $soc->country_code = 'FR'; |
|
101 | 101 | // Un client sur 3 a une remise de 5% |
102 | - $user_remise=mt_rand(1,3); if ($user_remise==3) $soc->remise_percent=5; |
|
102 | + $user_remise = mt_rand(1, 3); if ($user_remise == 3) $soc->remise_percent = 5; |
|
103 | 103 | print "> client=".$soc->client.", fournisseur=".$soc->fournisseur.", remise=".$soc->remise_percent."\n"; |
104 | 104 | $soc->note_private = 'Company created by the script generate-societe.php'; |
105 | 105 | $socid = $soc->create(); |
106 | 106 | |
107 | 107 | if ($socid >= 0) |
108 | 108 | { |
109 | - $rand = mt_rand(1,4); |
|
109 | + $rand = mt_rand(1, 4); |
|
110 | 110 | print "> Generates $rand contact(s)\n"; |
111 | - for ($c = 0 ; $c < $rand ; $c++) |
|
111 | + for ($c = 0; $c < $rand; $c++) |
|
112 | 112 | { |
113 | 113 | $contact = new Contact($db); |
114 | 114 | $contact->socid = $soc->id; |
115 | 115 | $contact->lastname = "Lastname".$c; |
116 | - $contact->firstname = $listoflastname[mt_rand(0, count($listoflastname)-1)]; |
|
117 | - if ( $contact->create($user) ) |
|
116 | + $contact->firstname = $listoflastname[mt_rand(0, count($listoflastname) - 1)]; |
|
117 | + if ($contact->create($user)) |
|
118 | 118 | { |
119 | 119 | |
120 | 120 | } |
@@ -28,27 +28,27 @@ discard block |
||
28 | 28 | // Test si mode batch |
29 | 29 | $sapi_type = php_sapi_name(); |
30 | 30 | $script_file = basename(__FILE__); |
31 | -$path=dirname(__FILE__).'/'; |
|
31 | +$path = dirname(__FILE__).'/'; |
|
32 | 32 | if (substr($sapi_type, 0, 3) == 'cgi') { |
33 | 33 | echo "Erreur: Vous utilisez l'interpreteur PHP pour le mode CGI. Pour executer mailing-send.php en ligne de commande, vous devez utiliser l'interpreteur PHP pour le mode CLI.\n"; |
34 | 34 | exit; |
35 | 35 | } |
36 | 36 | |
37 | 37 | // Recupere root dolibarr |
38 | -$path=preg_replace('/import-thirdparties.php/i','',$_SERVER["PHP_SELF"]); |
|
38 | +$path = preg_replace('/import-thirdparties.php/i', '', $_SERVER["PHP_SELF"]); |
|
39 | 39 | require $path."../../htdocs/master.inc.php"; |
40 | 40 | include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; |
41 | 41 | include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; |
42 | 42 | |
43 | -$delimiter=','; |
|
44 | -$enclosure='"'; |
|
45 | -$linelength=10000; |
|
46 | -$escape='/'; |
|
43 | +$delimiter = ','; |
|
44 | +$enclosure = '"'; |
|
45 | +$linelength = 10000; |
|
46 | +$escape = '/'; |
|
47 | 47 | |
48 | 48 | // Global variables |
49 | -$version=DOL_VERSION; |
|
50 | -$confirmed=1; |
|
51 | -$error=0; |
|
49 | +$version = DOL_VERSION; |
|
50 | +$confirmed = 1; |
|
51 | +$error = 0; |
|
52 | 52 | |
53 | 53 | |
54 | 54 | /* |
@@ -57,29 +57,29 @@ discard block |
||
57 | 57 | |
58 | 58 | @set_time_limit(0); |
59 | 59 | print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n"; |
60 | -dol_syslog($script_file." launched with arg ".implode(',',$argv)); |
|
60 | +dol_syslog($script_file." launched with arg ".implode(',', $argv)); |
|
61 | 61 | |
62 | 62 | $mode = $argv[1]; |
63 | 63 | $filepath = $argv[2]; |
64 | 64 | $filepatherr = $filepath.'.err'; |
65 | 65 | //$defaultlang = empty($argv[3])?'en_US':$argv[3]; |
66 | -$startlinenb = empty($argv[3])?1:$argv[3]; |
|
67 | -$endlinenb = empty($argv[4])?0:$argv[4]; |
|
66 | +$startlinenb = empty($argv[3]) ? 1 : $argv[3]; |
|
67 | +$endlinenb = empty($argv[4]) ? 0 : $argv[4]; |
|
68 | 68 | |
69 | -if (empty($mode) || ! in_array($mode,array('test','confirm','confirmforced')) || empty($filepath)) { |
|
69 | +if (empty($mode) || !in_array($mode, array('test', 'confirm', 'confirmforced')) || empty($filepath)) { |
|
70 | 70 | print "Usage: $script_file (test|confirm|confirmforced) filepath.csv [startlinenb] [endlinenb]\n"; |
71 | 71 | print "Usage: $script_file test myfilepath.csv 2 1002\n"; |
72 | 72 | print "\n"; |
73 | 73 | exit(-1); |
74 | 74 | } |
75 | -if (! file_exists($filepath)) { |
|
75 | +if (!file_exists($filepath)) { |
|
76 | 76 | print "Error: File ".$filepath." not found.\n"; |
77 | 77 | print "\n"; |
78 | 78 | exit(-1); |
79 | 79 | } |
80 | 80 | |
81 | -$ret=$user->fetch('','admin'); |
|
82 | -if (! $ret > 0) |
|
81 | +$ret = $user->fetch('', 'admin'); |
|
82 | +if (!$ret > 0) |
|
83 | 83 | { |
84 | 84 | print 'A user with login "admin" and all permissions must be created to use this script.'."\n"; |
85 | 85 | exit; |
@@ -87,7 +87,7 @@ discard block |
||
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 |
||
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 |
||
112 | 112 | |
113 | 113 | $db->begin(); |
114 | 114 | |
115 | -$i=0; |
|
116 | -$nboflines=0; |
|
117 | -while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape)) |
|
115 | +$i = 0; |
|
116 | +$nboflines = 0; |
|
117 | +while ($fields = fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape)) |
|
118 | 118 | { |
119 | 119 | $i++; |
120 | - $errorrecord=0; |
|
120 | + $errorrecord = 0; |
|
121 | 121 | |
122 | 122 | if ($startlinenb && $i < $startlinenb) continue; |
123 | 123 | if ($endlinenb && $i > $endlinenb) continue; |
@@ -129,8 +129,8 @@ discard block |
||
129 | 129 | $object->client = $fields[7]; |
130 | 130 | $object->fournisseur = $fields[8]; |
131 | 131 | |
132 | - $object->name = $fields[13]?trim($fields[13]):$fields[0]; |
|
133 | - $object->name_alias = $fields[0]!=$fields[13]?trim($fields[0]):''; |
|
132 | + $object->name = $fields[13] ?trim($fields[13]) : $fields[0]; |
|
133 | + $object->name_alias = $fields[0] != $fields[13] ?trim($fields[0]) : ''; |
|
134 | 134 | |
135 | 135 | $object->address = trim($fields[14]); |
136 | 136 | $object->zip = trim($fields[15]); |
@@ -171,12 +171,12 @@ discard block |
||
171 | 171 | |
172 | 172 | |
173 | 173 | // Extrafields |
174 | - $object->array_options['options_anastate']=price2num($fields[20]); |
|
175 | - $object->array_options['options_anaregion']=price2num($fields[17]); |
|
174 | + $object->array_options['options_anastate'] = price2num($fields[20]); |
|
175 | + $object->array_options['options_anaregion'] = price2num($fields[17]); |
|
176 | 176 | |
177 | - if (! $errorrecord) |
|
177 | + if (!$errorrecord) |
|
178 | 178 | { |
179 | - $ret=$object->create($user); |
|
179 | + $ret = $object->create($user); |
|
180 | 180 | if ($ret < 0) |
181 | 181 | { |
182 | 182 | print " - Error in create result code = ".$ret." - ".$object->errorsToString(); |
@@ -188,24 +188,24 @@ discard block |
||
188 | 188 | } |
189 | 189 | } |
190 | 190 | |
191 | - if (! $errorrecord) |
|
191 | + if (!$errorrecord) |
|
192 | 192 | { |
193 | 193 | dol_syslog("Set price level"); |
194 | 194 | $object->set_price_level($object->price_level, $user); |
195 | 195 | } |
196 | 196 | |
197 | 197 | // Assign sales representative |
198 | - if (! $errorrecord && $fields[3]) |
|
198 | + if (!$errorrecord && $fields[3]) |
|
199 | 199 | { |
200 | - $salesrep=new User($db); |
|
200 | + $salesrep = new User($db); |
|
201 | 201 | |
202 | - $tmp=explode(' ',$fields[3],2); |
|
202 | + $tmp = explode(' ', $fields[3], 2); |
|
203 | 203 | $salesrep->firstname = trim($tmp[0]); |
204 | 204 | $salesrep->lastname = trim($tmp[1]); |
205 | - if ($salesrep->lastname) $salesrep->login = strtolower(substr($salesrep->firstname, 0, 1)) . strtolower(substr($salesrep->lastname, 0)); |
|
206 | - else $salesrep->login=strtolower($salesrep->firstname); |
|
207 | - $salesrep->login=preg_replace('/ /','',$salesrep->login); |
|
208 | - $salesrep->fetch(0,$salesrep->login); |
|
205 | + if ($salesrep->lastname) $salesrep->login = strtolower(substr($salesrep->firstname, 0, 1)).strtolower(substr($salesrep->lastname, 0)); |
|
206 | + else $salesrep->login = strtolower($salesrep->firstname); |
|
207 | + $salesrep->login = preg_replace('/ /', '', $salesrep->login); |
|
208 | + $salesrep->fetch(0, $salesrep->login); |
|
209 | 209 | |
210 | 210 | $result = $object->add_commercial($user, $salesrep->id); |
211 | 211 | if ($result < 0) |
@@ -221,20 +221,20 @@ discard block |
||
221 | 221 | |
222 | 222 | dol_syslog("Add invoice contacts"); |
223 | 223 | // Insert an invoice contact if there is an invoice email != standard email |
224 | - if (! $errorrecord && $fields[27] && $fields[26] != $fields[27]) |
|
224 | + if (!$errorrecord && $fields[27] && $fields[26] != $fields[27]) |
|
225 | 225 | { |
226 | - $ret1=$ret2=0; |
|
226 | + $ret1 = $ret2 = 0; |
|
227 | 227 | |
228 | 228 | $contact = new Contact($db); |
229 | 229 | $contact->lastname = $object->name; |
230 | - $contact->address=$object->address; |
|
231 | - $contact->zip=$object->zip; |
|
232 | - $contact->town=$object->town; |
|
233 | - $contact->country_id=$object->country_id; |
|
234 | - $contact->email=$fields[27]; |
|
235 | - $contact->socid=$object->id; |
|
236 | - |
|
237 | - $ret1=$contact->create($user); |
|
230 | + $contact->address = $object->address; |
|
231 | + $contact->zip = $object->zip; |
|
232 | + $contact->town = $object->town; |
|
233 | + $contact->country_id = $object->country_id; |
|
234 | + $contact->email = $fields[27]; |
|
235 | + $contact->socid = $object->id; |
|
236 | + |
|
237 | + $ret1 = $contact->create($user); |
|
238 | 238 | if ($ret1 > 0) |
239 | 239 | { |
240 | 240 | //$ret2=$contact->add_contact($object->id, 'BILLING'); |
@@ -252,23 +252,23 @@ discard block |
||
252 | 252 | |
253 | 253 | dol_syslog("Add delivery contacts"); |
254 | 254 | // Insert a delivery contact |
255 | - if (! $errorrecord && $fields[47]) |
|
255 | + if (!$errorrecord && $fields[47]) |
|
256 | 256 | { |
257 | - $ret1=$ret2=0; |
|
257 | + $ret1 = $ret2 = 0; |
|
258 | 258 | |
259 | 259 | $contact2 = new Contact($db); |
260 | 260 | $contact2->lastname = 'Service livraison - '.$fields[47]; |
261 | 261 | $contact2->address = $fields[48]; |
262 | 262 | $contact2->zip = $fields[50]; |
263 | 263 | $contact2->town = $fields[51]; |
264 | - $contact2->country_id=dol_getIdFromCode($db, trim($fields[52]), 'c_country', 'code', 'rowid'); |
|
265 | - $contact2->note_public=$fields[54]; |
|
266 | - $contact2->socid=$object->id; |
|
264 | + $contact2->country_id = dol_getIdFromCode($db, trim($fields[52]), 'c_country', 'code', 'rowid'); |
|
265 | + $contact2->note_public = $fields[54]; |
|
266 | + $contact2->socid = $object->id; |
|
267 | 267 | |
268 | 268 | // Extrafields |
269 | - $contact2->array_options['options_anazoneliv']=price2num($fields[53]); |
|
269 | + $contact2->array_options['options_anazoneliv'] = price2num($fields[53]); |
|
270 | 270 | |
271 | - $ret1=$contact2->create($user); |
|
271 | + $ret1 = $contact2->create($user); |
|
272 | 272 | if ($ret1 > 0) |
273 | 273 | { |
274 | 274 | //$ret2=$contact2->add_contact($object->id, 'SHIPPING'); |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | if ($errorrecord) |
291 | 291 | { |
292 | 292 | fwrite($fhandleerr, 'Error on record nb '.$i." - ".$object->errorsToString()."\n"); |
293 | - $error++; // $errorrecord will be reset |
|
293 | + $error++; // $errorrecord will be reset |
|
294 | 294 | } |
295 | 295 | } |
296 | 296 |