diff --git a/.github/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md
index 9a84fdbbda0..1c46e8e2d50 100644
--- a/.github/CODE_OF_CONDUCT.md
+++ b/.github/CODE_OF_CONDUCT.md
@@ -77,8 +77,8 @@ contact@dolibarr.org
## 10. License and attribution
-This Code of Conduct is distributed under a [Creative Commons Attribution-ShareAlike license](http://creativecommons.org/licenses/by-sa/3.0/).
+This Code of Conduct is distributed under a [Creative Commons Attribution-ShareAlike license](https://creativecommons.org/licenses/by-sa/3.0/).
-Portions of text derived from the [Django Code of Conduct](https://www.djangoproject.com/conduct/) and the [Geek Feminism Anti-Harassment Policy](http://geekfeminism.wikia.com/wiki/Conference_anti-harassment/Policy).
+Portions of text derived from the [Django Code of Conduct](https://www.djangoproject.com/conduct/) and the [Geek Feminism Anti-Harassment Policy](https://geekfeminism.wikia.com/wiki/Conference_anti-harassment/Policy).
-Retrieved on November 22, 2016 from [http://citizencodeofconduct.org/](http://citizencodeofconduct.org/)
+Retrieved on November 22, 2016 from [https://citizencodeofconduct.org/](http://citizencodeofconduct.org/)
diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md
index b57ceda24aa..d17347a0ad7 100644
--- a/.github/CONTRIBUTING.md
+++ b/.github/CONTRIBUTING.md
@@ -4,15 +4,17 @@ How to contribute to Dolibarr
Bug reports and feature requests
--------------------------------
-*Note*: Issues are not a support forum. If you need help using the software, please use [the forums](https://www.dolibarr.org/forum.php). Forums exist in different languages.
+*Note*: **GitHub Issues is not a support forum.** If you have questions about Dolibarr / need help using the software, please use [the forums](https://www.dolibarr.org/forum.php). Forums exist in different languages.
Issues are managed on [GitHub](https://github.com/Dolibarr/dolibarr/issues).
-Default language here is english. So please prepare your contributions in english.
+Default **language here is english**. So please prepare your contributions in english.
1. Please [use the search engine](https://help.github.com/articles/searching-issues) to check if nobody's already reported your problem.
2. [Create an issue](https://help.github.com/articles/creating-an-issue). Choose an appropriate title. Prepend appropriately with Bug or Feature Request.
-4. Tell us the version you are using! (look at /htdocs/admin/system/dolibarr.php? and check if you are using the latest version)
-3. Write a report with as much detail as possible (Use [screenshots](https://help.github.com/articles/issue-attachments) or even screencasts and provide logging and debugging informations whenever possible).
+3. Tell us the version you are using! (look at /htdocs/admin/system/dolibarr.php? and check if you are using the latest version)
+4. Write a report with as much detail as possible (Use [screenshots](https://help.github.com/articles/issue-attachments) or even screencasts and provide logging and debugging informations whenever possible).
+5. Delete unnecessary submissions.
+6. **Check your Message at Preview before sending.**
diff --git a/COPYING b/COPYING
index 2a000655e93..e60008693e0 100644
--- a/COPYING
+++ b/COPYING
@@ -1,7 +1,7 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
- Copyright (C) 2007 Free Software Foundation, Inc.
+ Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
diff --git a/ChangeLog b/ChangeLog
index 951c4297f0c..c784c2f4bf3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,7 @@ English Dolibarr ChangeLog
For users:
----------
+NEW: Several security issues after a second private bug bounty campaign.
For developers:
@@ -19,12 +20,60 @@ WARNING:
Following changes may create regressions for some external modules, but were necessary to make Dolibarr better:
* The ICS value for direct debit or credit transfer is now store on each bank account instead of into the global setup.
* API /setup/shipment_methods has been replaced with API /setup/shipping_methods
-* Field "tva" renamed into "total_tva" in llx_propal, llx_supplier_proposal, llx_commande, llx_commande_fournisseur for better field name consistency
-* Field "total" renamed into "total_ttc" in llx_propal, llx_supplier_proposal for better field name consistency
+* Field "tva" renamed into "total_tva" for table llx_propal, llx_supplier_proposal, llx_commande, llx_commande_fournisseur for better field name consistency
+* Field "total" renamed into "total_ttc" for table lx_propal, llx_supplier_proposal for better field name consistency
* If your database is PostgreSql, you must use version 9.1.0 or more (Dolibarr need the SQL function CONCAT)
* If your database is MySql or MariaDB, you need at least version 5.1
+
+***** ChangeLog for 13.0.2 compared to 13.0.1 *****
+
+FIX: 11.0 - $this->socid injected in query without checking for empty value
+FIX: #16096 #16085 Any call of ajax pages must provide the token
+FIX: #16296
+FIX: #16325
+FIX: #16341 : Fetch the Product ExtraFields in Shippment lines
+FIX: #16366
+FIX: #16393 Do not sanitize
+FIX: #16420 #16423 #16488 #16477
+FIX: #16431
+FIX: #16465
+FIX: #16480
+FIX: #16485
+FIX: #16487
+FIX: #16503
+FIX: #16530
+FIX: #16533
+FIX: #16629
+FIX: #16671 Can not generate zip file of documents in backup tool
+FIX: Add "Now" link on social charges creation card
+FIX: avoid undefined URL and missing token
+FIX: Bad project filter in ticket list
+FIX: Buttons to disable bindings not working
+FIX: class not found when creating recuring invoice from invoice+discount
+FIX: File attachment on lots/batches
+FIX: handling $heightforinfotot when he's superior to a page height on Supplier Invoice
+FIX: hourglass and hide button to pay
+FIX: massaction validate invoice do not regenerate PDF
+FIX: missing mp4 video mime
+FIX: picto on shipment to reset qty to 0. Some quantities were not reset.
+FIX: Protection to avoid #16504
+FIX: rounding amount on card updating
+FIX: rounding amount on social charges card updating
+FIX: select list dependencies now work for ModuleBuilder sellist field
+FIX: status in popup of member in widget
+FIX: status on tooltip on widgets
+FIX: Timezone management for datetime on list of events
+FIX: Timezone management for datetime with modulebuilder and extrafields
+FIX: Total_ht not show in contract link element
+FIX: use post instead get
+FIX: use var "saved_url" instead global var "$url"
+FIX: Various payment - Missing fields for check transmitter & bank name
+FIX: warning if setup of chart of account is not yet done.
+FIX: wrong extension
+
+
***** ChangeLog for 13.0.1 compared to 13.0.0 *****
FIX: 10.0 before crediting a withdrawal receipt, check whether it has been credited already.
@@ -44,9 +93,9 @@ FIX: #16135
FIX: #16143
FIX: #16156
FIX: #16160
-FIX: #16165 Create customer discount without vat
+FIX: #16165 Create customer discount without VAT
FIX: #16185
-FIX: #16189, fix download/see check deposit PDF
+FIX: #16189 fix download/see check deposit PDF
FIX: #16215
FIX: Accountancy - label_operation is used instead of label_compte
FIX: Add critical price patch
@@ -56,7 +105,7 @@ FIX: cash fence for takepos with multientity
FIX: CSRF errors on margin forms
FIX: encoding status in graph of vendor proposals
FIX: Fix detect dispached product and set to received completely when the supplier order have services (support STOCK_SUPPORTS_SERVICES)
-FIX: Hide/Unhide external ICSS calendars
+FIX: hide/unhide external ICS calendars
FIX: link to create event when task is in a project with a thirdparty
FIX: Localtax must be converted with price2num
FIX: manage price min for PRODUIT_CUSTOMER_PRICES
@@ -77,7 +126,7 @@ FIX: warning when adding a line if $remise_percent is an empty string
FIX: status late on purchase orders
FIX: ODT generation very slow
FIX: amount in summary of report
-FIX: vat value when code contains number
+FIX: VAT value when code contains number
FIX: payment term label on PDF
FIX: date selector when using reduced year (like on smartphone)
@@ -96,7 +145,7 @@ NEW: Accountancy - add options to disable binding on sales, purchases & expense
NEW: Accountancy balance - add a menu entry to show subtotal by group
NEW: Accountancy - change menu disposition
NEW: Accountancy - on transfers, select the periodicity by default
-NEW: Accountancy - Add export for Gestinum (v3 & v5) #15180
+NEW: Accountancy - add export for Gestinum (v3 & v5) #15180
NEW: new currency rate editor
NEW: Solve blocking feature. Can increase stock of a Kit without changing subproduct stock.
NEW: add a widget to show the customers with outstanding limits reached
diff --git a/DCO b/DCO
new file mode 100644
index 00000000000..d54f007a8c5
--- /dev/null
+++ b/DCO
@@ -0,0 +1,34 @@
+Developer Certificate of Origin
+Version 1.1
+
+Copyright (C) 2002 - Today, The Dolibarr team and its contributors.
+
+Everyone is permitted to copy and distribute verbatim copies of this
+license document, but changing it is not allowed.
+
+
+Developer's Certificate of Origin 1.1
+
+By making a contribution to this project, I certify that:
+
+(a) The contribution was created in whole or in part by me and I
+ have the right to submit it under the open source license
+ indicated in the file; or
+
+(b) The contribution is based upon previous work that, to the best
+ of my knowledge, is covered under an appropriate open source
+ license and I have the right under that license to submit that
+ work with modifications, whether created in whole or in part
+ by me, under the same open source license (unless I am
+ permitted to submit under a different license), as indicated
+ in the file; or
+
+(c) The contribution was provided directly to me by some other
+ person who certified (a), (b) or (c) and I have not modified
+ it.
+
+(d) I understand and agree that this project and the contribution
+ are public and that a record of the contribution (including all
+ personal information I submit with it, including my sign-off) is
+ maintained indefinitely and may be redistributed consistent with
+ this project or the open source license(s) involved.
diff --git a/README.md b/README.md
index ad4971f50db..0a3aeecb9f4 100644
--- a/README.md
+++ b/README.md
@@ -98,7 +98,7 @@ See the [ChangeLog](https://github.com/Dolibarr/dolibarr/blob/develop/ChangeLog)
### Main application/modules (all optional)
- Customers, Prospects (Leads) and/or Suppliers directory + Contacts
-- Members management
+- Members/Membership management
- Products and/or Services catalog
- Commercial proposals management
- Customer & Supplier Orders management
@@ -112,6 +112,7 @@ See the [ChangeLog](https://github.com/Dolibarr/dolibarr/blob/develop/ChangeLog)
- Shared calendar/agenda (with ical and vcal export for third party tools integration)
- Opportunities or Leads management
- Projects & Tasks management
+- Ticket System
- Contracts management
- Interventions management
- Employee's leave requests management
@@ -160,7 +161,7 @@ See the [ChangeLog](https://github.com/Dolibarr/dolibarr/blob/develop/ChangeLog)
- Canadian double taxes (federal/province) and other countries using cumulative VAT
- Tunisian tax stamp
- Argentina invoice numbering using A,B,C...
- - Compatible with [European directives](http://europa.eu/legislation_summaries/taxation/l31057_en.htm) (2006/112/CE ... 2010/45/UE)
+ - Compatible with [European directives] (https://europa.eu/legislation_summaries/taxation/l31057_en.htm) (2006/112/CE ... 2010/45/UE)
- Compatible with European GDPR rules
- ...
- Flexible PDF & ODT generation for invoices, proposals, orders...
diff --git a/SECURITY.md b/SECURITY.md
index f63f9c3f277..7d65b7e98e4 100644
--- a/SECURITY.md
+++ b/SECURITY.md
@@ -12,7 +12,7 @@ This file contains some policies about the security reports on Dolibarr ERP CRM
## Reporting a Vulnerability
-To report a vulnerability, please use GitHub security advisory at https://github.com/Dolibarr/dolibarr/security/advisories/new (or alternatively send an email to security@dolibarr.org)
+To report a vulnerability, please use GitHub security advisory at https://github.com/Dolibarr/dolibarr/security/advisories/new (if you have permissions) or alternatively send an email to security@dolibarr.org (for everybody)
## Hunting vulnerabilities on Dolibarr
@@ -55,7 +55,7 @@ ONLY vulnerabilities discovered, when the following setup on test platform is us
* $dolibarr_nocsrfcheck must be kept to the value 0 into conf.php (this is the default value)
* $dolibarr_main_force_https must be set to something else than 0.
* The constant MAIN_SECURITY_CSRF_WITH_TOKEN must be set to 1 into backoffice menu Home - Setup - Other (this protection should be set to 1 soon by default)
-* The module DebugBar and ModuleBuilder must NOT be enabled (by default, this module is not enabled. This is a developer tool)
+* The module DebugBar and ModuleBuilder must NOT be enabled (by default, these modules are not enabled. They are developer tools)
* ONLY security reports on modules provided by default and with the "stable" status are valid (troubles into "experimental", "developement" or external modules are not valid vulnerabilities).
* The root of web server must link to htdocs and the documents directory must be outside of the web server root (this is the default when using the default installer but may differs with external installer).
* The web server setup must be done so only the documents directory is in write mode. The root directory called htdocs must be readonly.
@@ -65,12 +65,12 @@ ONLY vulnerabilities discovered, when the following setup on test platform is us
Scope is the web application (back office) and the APIs.
-## Qualifying vulnerabilities for Bug bounty programs
+## Qualifying vulnerabilities for reporting
* Remote code execution (RCE)
* Local files access and manipulation (LFI, RFI, XXE, SSRF, XSPA)
* Code injections (HTML, JS, SQL, PHP, ...)
-* Cross-Site Scripting (XSS)
+* Cross-Site Scripting (XSS), except from setup page of module "External web site" (allowing any content here, editable by admin user only, is accepted on purpose or into module "Web site" when permission to edit website content is allowed).
* Cross-Site Requests Forgery (CSRF) with real security impact (when using GET URLs, CSRF are qualified only for creating, updating or deleting data from pages restricted to admin users)
* Open redirect
* Broken authentication & session management
@@ -82,7 +82,7 @@ Scope is the web application (back office) and the APIs.
* Stack traces or path disclosure (for non admin users only)
-## Non-qualifying vulnerabilities for Bug bounty programs, but qualified for reporting
+## Non-qualifying vulnerabilities for reporting
* "Self" XSS
* SSL/TLS best practices
diff --git a/build/debian/control b/build/debian/control
index eed54669555..059325eecb9 100755
--- a/build/debian/control
+++ b/build/debian/control
@@ -33,7 +33,7 @@ Depends: libapache2-mod-php5 | libapache2-mod-php5filter | php5-cgi | php5-fpm |
Recommends: apache2 | lighttpd | httpd,
mariadb-server | virtual-mysql-server,
# Required PHP extensions for debian 9 but we can't add them into a Depends, it does not exists on debian 7 and 8
- php-xml, php-mbstring
+ php-xml, php-mbstring, php-intl
Suggests: www-browser, php5-geoip
Description: Web based software to manage a company or foundation
Dolibarr ERP & CRM is an easy to use open source/free software package for
diff --git a/build/doxygen/doxygen_header.html b/build/doxygen/doxygen_header.html
index 235797bb6c9..f60f4829d76 100644
--- a/build/doxygen/doxygen_header.html
+++ b/build/doxygen/doxygen_header.html
@@ -2,7 +2,7 @@
-$title
+Dolibarr source code documentation
$tmp) {
- foreach ($tmp as $constname => $constvalue) {
- print $constname.'='.$constvalue." ";
- }
+ foreach ($tmp as $constname => $constvalue) {
+ print $constname.'='.$constvalue." ";
+ }
}
print "\n";
@@ -134,13 +141,13 @@ fputs($fp, ''."\n");
fputs($fp, ''."\n");
foreach ($includeconstants as $countrycode => $tmp) {
- fputs($fp, ''."\n");
- foreach ($tmp as $constname => $constvalue) {
- $valueforchecksum=(empty($constvalue)?'0':$constvalue);
- $checksumconcat[]=$valueforchecksum;
- fputs($fp, ' '.$valueforchecksum.''."\n");
- }
- fputs($fp, ''."\n");
+ fputs($fp, ''."\n");
+ foreach ($tmp as $constname => $constvalue) {
+ $valueforchecksum=(empty($constvalue)?'0':$constvalue);
+ $checksumconcat[]=$valueforchecksum;
+ fputs($fp, ' '.$valueforchecksum.''."\n");
+ }
+ fputs($fp, ''."\n");
}
fputs($fp, ''."\n");
@@ -151,28 +158,28 @@ $iterator1 = new RecursiveIteratorIterator($dir_iterator1);
$files = new RegexIterator($iterator1, '#^(?:[A-Z]:)?(?:/(?!(?:'.($includecustom?'':'custom\/|').'documents\/|conf\/|install\/))[^/]+)+/[^/]+\.(?:php|css|html|js|json|tpl|jpg|png|gif|sql|lang)$#i');
*/
$regextoinclude='\.(php|php3|php4|php5|phtml|phps|phar|inc|css|scss|html|xml|js|json|tpl|jpg|jpeg|png|gif|ico|sql|lang|txt|yml|md|mp3|mp4|wav|mkv|z|gz|zip|rar|tar|less|svg|eot|woff|woff2|ttf|manifest)$';
-$regextoexclude='('.($includecustom?'':'custom|').'documents|conf|install|public\/test|sabre\/sabre\/.*\/tests|Shared\/PCLZip|nusoap\/lib\/Mail|php\/example|php\/test|geoip\/sample.*\.php|ckeditor\/samples|ckeditor\/adapters)$'; // Exclude dirs
+$regextoexclude='('.($includecustom?'':'custom|').'documents|conf|install|dejavu-fonts-ttf-.*|public\/test|sabre\/sabre\/.*\/tests|Shared\/PCLZip|nusoap\/lib\/Mail|php\/example|php\/test|geoip\/sample.*\.php|ckeditor\/samples|ckeditor\/adapters)$'; // Exclude dirs
$files = dol_dir_list(DOL_DOCUMENT_ROOT, 'files', 1, $regextoinclude, $regextoexclude, 'fullname');
$dir='';
$needtoclose=0;
foreach ($files as $filetmp) {
- $file = $filetmp['fullname'];
- //$newdir = str_replace(dirname(__FILE__).'/../htdocs', '', dirname($file));
- $newdir = str_replace(DOL_DOCUMENT_ROOT, '', dirname($file));
- if ($newdir!=$dir) {
- if ($needtoclose) {
- fputs($fp, ' '."\n");
- }
- fputs($fp, ' '."\n");
- $dir = $newdir;
- $needtoclose=1;
- }
- if (filetype($file)=="file") {
- $md5=md5_file($file);
- $checksumconcat[]=$md5;
- fputs($fp, ' '.$md5.''."\n");
- }
+ $file = $filetmp['fullname'];
+ //$newdir = str_replace(dirname(__FILE__).'/../htdocs', '', dirname($file));
+ $newdir = str_replace(DOL_DOCUMENT_ROOT, '', dirname($file));
+ if ($newdir!=$dir) {
+ if ($needtoclose) {
+ fputs($fp, ' '."\n");
+ }
+ fputs($fp, ' '."\n");
+ $dir = $newdir;
+ $needtoclose=1;
+ }
+ if (filetype($file)=="file") {
+ $md5=md5_file($file);
+ $checksumconcat[]=$md5;
+ fputs($fp, ' '.$md5.''."\n");
+ }
}
fputs($fp, ' '."\n");
fputs($fp, ''."\n");
@@ -200,22 +207,23 @@ $files = dol_dir_list(dirname(__FILE__).'/../scripts/', 'files', 1, $regextoincl
$dir='';
$needtoclose=0;
foreach ($files as $filetmp) {
- $file = $filetmp['fullname'];
- //$newdir = str_replace(dirname(__FILE__).'/../scripts', '', dirname($file));
- $newdir = str_replace(DOL_DOCUMENT_ROOT, '', dirname($file));
- $newdir = str_replace(dirname(__FILE__).'/../scripts', '', dirname($file));
- if ($newdir!=$dir) {
- if ($needtoclose)
- fputs($fp, ' '."\n");
- fputs($fp, ' '."\n");
- $dir = $newdir;
- $needtoclose=1;
- }
- if (filetype($file)=="file") {
- $md5=md5_file($file);
- $checksumconcat[]=$md5;
- fputs($fp, ' '.$md5.''."\n");
- }
+ $file = $filetmp['fullname'];
+ //$newdir = str_replace(dirname(__FILE__).'/../scripts', '', dirname($file));
+ $newdir = str_replace(DOL_DOCUMENT_ROOT, '', dirname($file));
+ $newdir = str_replace(dirname(__FILE__).'/../scripts', '', dirname($file));
+ if ($newdir!=$dir) {
+ if ($needtoclose) {
+ fputs($fp, ' '."\n");
+ }
+ fputs($fp, ' '."\n");
+ $dir = $newdir;
+ $needtoclose=1;
+ }
+ if (filetype($file)=="file") {
+ $md5=md5_file($file);
+ $checksumconcat[]=$md5;
+ fputs($fp, ' '.$md5.''."\n");
+ }
}
fputs($fp, ' '."\n");
fputs($fp, ''."\n");
diff --git a/build/makepack-dolibarr.pl b/build/makepack-dolibarr.pl
index 0fe73fd9fb8..906601d94d4 100755
--- a/build/makepack-dolibarr.pl
+++ b/build/makepack-dolibarr.pl
@@ -390,6 +390,9 @@ if ($nboftargetok) {
$olddir=getcwd();
chdir("$SOURCE");
+ print "Clean $SOURCE/htdocs\n";
+ $ret=`rm -f $SOURCE/htdocs/includes/autoload.php`;
+
$ret=`git ls-files . --exclude-standard --others`;
if ($ret)
{
@@ -613,7 +616,6 @@ if ($nboftargetok) {
$ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/includes/nnnick/chartjs/test`;
$ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/includes/nusoap/lib/Mail`;
$ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/includes/nusoap/samples`;
- $ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/includes/parsedown/LICENSE.txt`;
$ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/includes/php-iban/docs`;
$ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/includes/sabre/sabre/*/tests`;
$ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/includes/stripe/tests`;
@@ -623,7 +625,6 @@ if ($nboftargetok) {
$ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/includes/tecnickcom/tcpdf/fonts/freefont-*`;
$ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/includes/tecnickcom/tcpdf/fonts/ae_fonts_*`;
$ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/includes/tecnickcom/tcpdf/fonts/utils`;
- $ret=`rm -f $BUILDROOT/$PROJECT/htdocs/includes/tecnickcom/tcpdf/LICENSE.TXT`;
$ret=`rm -f $BUILDROOT/$PROJECT/htdocs/includes/tecnickcom/tcpdf/tools`;
$ret=`rm -f $BUILDROOT/$PROJECT/htdocs/includes/vendor`;
$ret=`rm -f $BUILDROOT/$PROJECT/htdocs/includes/webmozart`;
diff --git a/dev/examples/git/pre-commit b/dev/examples/git/pre-commit
deleted file mode 100644
index f89d662ae65..00000000000
--- a/dev/examples/git/pre-commit
+++ /dev/null
@@ -1,49 +0,0 @@
-#!/bin/sh
-
-PROJECT=`php -r "echo dirname(dirname(dirname(realpath('$0'))));"`
-STAGED_FILES_CMD=`git diff --cached --name-only --diff-filter=ACMR HEAD | grep \\\\.php`
-
-# Determine if a file list is passed
-if [ "$#" -eq 1 ]
-then
- oIFS=$IFS
- IFS='
- '
- SFILES="$1"
- IFS=$oIFS
-fi
-SFILES=${SFILES:-$STAGED_FILES_CMD}
-
-echo "Checking PHP Lint..."
-for FILE in $SFILES
-do
- php -l -d display_errors=0 $PROJECT/$FILE
- if [ $? != 0 ]
- then
- echo "Fix the error before commit."
- exit 1
- fi
- FILES="$FILES $PROJECT/$FILE"
-done
-
-if [ "$FILES" != "" ]
-then
- echo "Running PHPCS Code Sniffer..."
- #~/vendor/bin/phpcs --version
- #phpcs --standard=PSR2 --encoding=utf-8 -n -p $FILES
- # Check Dolibarr standard
- ~/vendor/bin/phpcs -s -p -d memory_limit=-1 --parallel=2 --extensions=php --colors --tab-width=4 --standard=dev/setup/codesniffer/ruleset.xml --encoding=utf-8 --runtime-set ignore_warnings_on_exit true $FILES
- # Check your own standard
- #~/vendor/bin/phpcs -s -p -d memory_limit=-1 --parallel=2 --extensions=php --colors --tab-width=4 --standard=htdocs/custom/codesniffer/ruleset.xml --encoding=utf-8 --runtime-set ignore_warnings_on_exit true $FILES
-
- if [ $? != 0 ]
- then
- # fix standard errors
- ~/vendor/bin/phpcbf -s -p -d memory_limit=-1 --extensions=php --colors --tab-width=4 --standard=dev/setup/codesniffer/ruleset.xml --encoding=utf-8 --runtime-set ignore_warnings_on_exit true $FILES
- #~/vendor/bin/phpcbf -s -p -d memory_limit=-1 --extensions=php --colors --tab-width=4 --standard=htdocs/custom/codesniffer/ruleset.xml --encoding=utf-8 --runtime-set ignore_warnings_on_exit true $FILES
- echo "Fix the error before commit."
- exit 1
- fi
-fi
-
-exit $?
diff --git a/dev/examples/zapier/README.md b/dev/examples/zapier/README.md
index 453a5224993..e452cc2aa6b 100644
--- a/dev/examples/zapier/README.md
+++ b/dev/examples/zapier/README.md
@@ -1,68 +1,6 @@
# HOW TO BUILD
+Take a look at the dolibarr wiki page of Zapier module:
-## ENABLE MODULE ZAPIER ON DOLIBARR
-
-This should also enable the module API (required for authentication by Zapier service and to execute action in Dolibarr by Zapier).
-
-Create the Dolibarr login that will be used by Zapier to call APIs. Give the login the permissions on the action you plan to automate.
-
-
-## CREATE A ZAPIER DEVELOPPER ACCOUNT
-
-At first, you need to have a Zapier developper acoount, create it here [Zapier Platform](https://developer.zapier.com/)
-
-
-## INSTALL ZAPIER COMMAND LINE TOOLS WITH LINK TO ZAPIER ONLINE ACCOUNT
-
-### Install Node.js
-
-An easy option to get set up with Node.js is to visit [https://nodejs.org/en/download/](https://nodejs.org/en/download/) and download the official installer for your OS. If you're installing with a package manager it's even easier.
-
-After installation, confirm that Node.js is ready to use:
- `node --version`
-
-### Install the Zapier CLI
-
-Next let's install the Zapier CLI tools. The CLI will allow you to build your app, deploy it to the Zapier platform, do local testing, manage users and testers, view remote logs, collaborate with your team, and more:
-
- `cd dev/examples/zapier`
-
- `npm install -g zapier-platform-cli` to install the CLI globally
-
- `zapier --version` to return version of the CLI
-
-### Run Zapier Login
-
-Let's configure authentication between your dev environment and the Zapier platform. You'll use the email address and password you use to log in to the Zapier application.
-
- `zapier login`
-
-This command will set up a .zapierrc file in your home directory.
-
-### Install the Project
-
-In zapier example directory, run:
-
- `cd dev/examples/zapier`
-
- `npm install`
-
-### Deploying your App
-
-Let's deploy it! When you're ready to try your code out on the Zapier platform use the push command. Only you will be able to see the app until you invite testers.
-
- `zapier register` (the first time, choose name for example "Dolibarr")
-
- `zapier push`
-
-After a push, the Application, with the name you defined during the register step, is available when creating a Zap.
-
-You will find original tutorial here : [https://zapier.com/developer/start/introduction](https://zapier.com/developer/start/introduction)
-
-
-### Create a Zap
-
-Create a ZAP that use the application you registered.
-For authentication, you must enter the login / pass of account used by Zapier to call APIs.
+https://wiki.dolibarr.org/index.php?title=Module_Zapier
diff --git a/dev/initdata/dbf/import-dbf.php b/dev/initdata/dbf/import-dbf.php
index 0718a472cd6..ba1da9722d6 100644
--- a/dev/initdata/dbf/import-dbf.php
+++ b/dev/initdata/dbf/import-dbf.php
@@ -30,8 +30,8 @@ $script_file = basename(__FILE__);
$path = dirname(__FILE__) . '/';
if (substr($sapi_type, 0, 3) == 'cgi') {
- echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
- exit;
+ echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
+ exit;
}
// Recupere root dolibarr
@@ -62,40 +62,40 @@ $startlinenb = empty($argv[3]) ? 1 : (int) $argv[3];
$endlinenb = empty($argv[4]) ? 0 : (int) $argv[4];
if (empty($filepath)) {
- print "Usage: php $script_file myfilepath.dbf [removeChatColumnName] [startlinenb] [endlinenb]\n";
- print "Example: php $script_file myfilepath.dbf 0 2 1002\n";
- print "\n";
- exit(-1);
+ print "Usage: php $script_file myfilepath.dbf [removeChatColumnName] [startlinenb] [endlinenb]\n";
+ print "Example: php $script_file myfilepath.dbf 0 2 1002\n";
+ print "\n";
+ exit(-1);
}
if (!file_exists($filepath)) {
- print "Error: File " . $filepath . " not found.\n";
- print "\n";
- exit(-1);
+ print "Error: File " . $filepath . " not found.\n";
+ print "\n";
+ exit(-1);
}
$ret = $user->fetch('', 'admin');
if (!$ret > 0) {
- print 'A user with login "admin" and all permissions must be created to use this script.' . "\n";
- exit;
+ print 'A user with login "admin" and all permissions must be created to use this script.' . "\n";
+ exit;
}
$user->getrights();
// Ask confirmation
if (!$confirmed) {
- print "Hit Enter to continue or CTRL+C to stop...\n";
- $input = trim(fgets(STDIN));
+ print "Hit Enter to continue or CTRL+C to stop...\n";
+ $input = trim(fgets(STDIN));
}
// Open input and output files
$fhandle = dbase_open($filepath, 0);
if (!$fhandle) {
- print 'Error: Failed to open file ' . $filepath . "\n";
- exit(1);
+ print 'Error: Failed to open file ' . $filepath . "\n";
+ exit(1);
}
$fhandleerr = fopen($filepatherr, 'w');
if (!$fhandleerr) {
- print 'Error: Failed to open file ' . $filepatherr . "\n";
- exit(1);
+ print 'Error: Failed to open file ' . $filepatherr . "\n";
+ exit(1);
}
$langs->setDefaultLang($defaultlang);
@@ -105,23 +105,23 @@ $table_name = substr(basename($filepath), 0, strpos(basename($filepath), '.'));
print 'Info: ' . $record_numbers . " lines in file \n";
$header = dbase_get_header_info($fhandle);
if ($deleteTable) {
- $db->query("DROP TABLE IF EXISTS `$table_name`");
+ $db->query("DROP TABLE IF EXISTS `$table_name`");
}
$sqlCreate = "CREATE TABLE IF NOT EXISTS `$table_name` ( `id` INT(11) NOT NULL AUTO_INCREMENT ";
$fieldArray = array("`id`");
foreach ($header as $value) {
- $fieldName = substr(str_replace('_', '', $value['name']), $startchar);
- $fieldArray[] = "`$fieldName`";
- $sqlCreate .= ", `" . $fieldName . "` VARCHAR({$value['length']}) NULL DEFAULT NULL ";
+ $fieldName = substr(str_replace('_', '', $value['name']), $startchar);
+ $fieldArray[] = "`$fieldName`";
+ $sqlCreate .= ", `" . $fieldName . "` VARCHAR({$value['length']}) NULL DEFAULT NULL ";
}
$sqlCreate .= ", PRIMARY KEY (`id`)) ENGINE = InnoDB";
$resql = $db->query($sqlCreate);
if ($resql !== false) {
- print "Table $table_name created\n";
+ print "Table $table_name created\n";
} else {
- var_dump($db->errno());
- print "Impossible : " . $sqlCreate . "\n";
- die();
+ var_dump($db->errno());
+ print "Impossible : " . $sqlCreate . "\n";
+ die();
}
$i = 0;
@@ -131,30 +131,33 @@ $fields = implode(',', $fieldArray);
//var_dump($fieldArray);die();
$maxLength = 0;
for ($i = 1; $i <= $record_numbers; $i++) {
- if ($startlinenb && $i < $startlinenb)
- continue;
- if ($endlinenb && $i > $endlinenb)
- continue;
- $row = dbase_get_record_with_names($fhandle, $i);
- if ($row === false || (isset($row["deleted"]) && $row["deleted"] == '1'))
- continue;
- $sqlInsert = "INSERT INTO `$table_name`($fields) VALUES (null,";
- array_shift($row); // remove delete column
- foreach ($row as $value) {
- $sqlInsert .= "'" . $db->escape(utf8_encode($value)) . "', ";
- }
- replaceable_echo(implode("\t", $row));
- $sqlInsert = rtrim($sqlInsert, ', ');
- $sqlInsert .= ")";
- $resql = $db->query($sqlInsert);
- if ($resql === false) {
- print "Impossible : " . $sqlInsert . "\n";
- var_dump($row, $db->errno());
- die();
- }
+ if ($startlinenb && $i < $startlinenb) {
+ continue;
+ }
+ if ($endlinenb && $i > $endlinenb) {
+ continue;
+ }
+ $row = dbase_get_record_with_names($fhandle, $i);
+ if ($row === false || (isset($row["deleted"]) && $row["deleted"] == '1')) {
+ continue;
+ }
+ $sqlInsert = "INSERT INTO `$table_name`($fields) VALUES (null,";
+ array_shift($row); // remove delete column
+ foreach ($row as $value) {
+ $sqlInsert .= "'" . $db->escape(utf8_encode($value)) . "', ";
+ }
+ replaceable_echo(implode("\t", $row));
+ $sqlInsert = rtrim($sqlInsert, ', ');
+ $sqlInsert .= ")";
+ $resql = $db->query($sqlInsert);
+ if ($resql === false) {
+ print "Impossible : " . $sqlInsert . "\n";
+ var_dump($row, $db->errno());
+ die();
+ }
// $fields = (object) $row;
// var_dump($fields);
- continue;
+ continue;
}
die();
@@ -166,11 +169,11 @@ die();
print "Nb of lines qualified: " . $nboflines . "\n";
print "Nb of errors: " . $error . "\n";
if ($mode != 'confirmforced' && ($error || $mode != 'confirm')) {
- print "Rollback any changes.\n";
- $db->rollback();
+ print "Rollback any changes.\n";
+ $db->rollback();
} else {
- print "Commit all changes.\n";
- $db->commit();
+ print "Commit all changes.\n";
+ $db->commit();
}
$db->close();
@@ -189,43 +192,43 @@ exit($error);
*/
function replaceable_echo($message, $force_clear_lines = null)
{
- static $last_lines = 0;
+ static $last_lines = 0;
- if (!is_null($force_clear_lines)) {
- $last_lines = $force_clear_lines;
- }
+ if (!is_null($force_clear_lines)) {
+ $last_lines = $force_clear_lines;
+ }
- $toss = array();
- $status = 0;
- $term_width = exec('tput cols', $toss, $status);
- if ($status) {
- $term_width = 64; // Arbitrary fall-back term width.
- }
+ $toss = array();
+ $status = 0;
+ $term_width = exec('tput cols', $toss, $status);
+ if ($status) {
+ $term_width = 64; // Arbitrary fall-back term width.
+ }
- $line_count = 0;
- foreach (explode("\n", $message) as $line) {
- $line_count += count(str_split($line, $term_width));
- }
+ $line_count = 0;
+ foreach (explode("\n", $message) as $line) {
+ $line_count += count(str_split($line, $term_width));
+ }
- // Erasure MAGIC: Clear as many lines as the last output had.
- for ($i = 0; $i < $last_lines; $i++) {
- // Return to the beginning of the line
- echo "\r";
- // Erase to the end of the line
- echo "\033[K";
- // Move cursor Up a line
- echo "\033[1A";
- // Return to the beginning of the line
- echo "\r";
- // Erase to the end of the line
- echo "\033[K";
- // Return to the beginning of the line
- echo "\r";
- // Can be consolodated into
- // echo "\r\033[K\033[1A\r\033[K\r";
- }
+ // Erasure MAGIC: Clear as many lines as the last output had.
+ for ($i = 0; $i < $last_lines; $i++) {
+ // Return to the beginning of the line
+ echo "\r";
+ // Erase to the end of the line
+ echo "\033[K";
+ // Move cursor Up a line
+ echo "\033[1A";
+ // Return to the beginning of the line
+ echo "\r";
+ // Erase to the end of the line
+ echo "\033[K";
+ // Return to the beginning of the line
+ echo "\r";
+ // Can be consolodated into
+ // echo "\r\033[K\033[1A\r\033[K\r";
+ }
- $last_lines = $line_count;
+ $last_lines = $line_count;
- echo $message . "\n";
+ echo $message . "\n";
}
diff --git a/dev/initdata/dbf/importdb-products.php b/dev/initdata/dbf/importdb-products.php
index 2c06c07e103..6da24faee4e 100644
--- a/dev/initdata/dbf/importdb-products.php
+++ b/dev/initdata/dbf/importdb-products.php
@@ -29,8 +29,8 @@ $sapi_type = php_sapi_name();
$script_file = basename(__FILE__);
$path = dirname(__FILE__) . '/';
if (substr($sapi_type, 0, 3) == 'cgi') {
- echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
- exit;
+ echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
+ exit;
}
// Recupere root dolibarr
@@ -50,18 +50,18 @@ $confirmed = 1;
$error = 0;
$tvas = [
- '1' => "20.00",
- '2' => "5.50",
- '3' => "0.00",
- '4' => "20.60",
- '5' => "19.60",
+ '1' => "20.00",
+ '2' => "5.50",
+ '3' => "0.00",
+ '4' => "20.60",
+ '5' => "19.60",
];
$tvasD = [
- '1' => "20",
- '2' => "5.5",
- '3' => "0",
- '4' => "20",
- '5' => "20",
+ '1' => "20",
+ '2' => "5.5",
+ '3' => "0",
+ '4' => "20",
+ '5' => "20",
];
/*
@@ -75,159 +75,167 @@ dol_syslog($script_file . " launched with arg " . implode(',', $argv));
$table = $argv[1];
if (empty($argv[1])) {
- print "Error: Which table ?\n";
- print "\n";
- exit(-1);
+ print "Error: Which table ?\n";
+ print "\n";
+ exit(-1);
}
$ret = $user->fetch('', 'admin');
if (!$ret > 0) {
- print 'A user with login "admin" and all permissions must be created to use this script.' . "\n";
- exit;
+ print 'A user with login "admin" and all permissions must be created to use this script.' . "\n";
+ exit;
}
$sql = "SELECT * FROM `$table` WHERE 1";
$resql = $db->query($sql);
-if ($resql)
-while ($fields = $db->fetch_array($resql)) {
- $errorrecord = 0;
- if ($fields === false)
- continue;
- $nboflines++;
-
- $produit = new Product($db);
- $produit->type = 0;
- $produit->status = 1;
- $produit->ref = trim($fields['REF']);
- if ($produit->ref == '')
- continue;
- print "Process line nb " . $j . ", ref " . $produit->ref;
- $produit->label = trim($fields['LIBELLE']);
- if ($produit->label == '')
- $produit->label = $produit->ref;
- if (empty($produit->label))
- continue;
- //$produit->description = trim($fields[4] . "\n" . ($fields[5] ? $fields[5] . ' x ' . $fields[6] . ' x ' . $fields[7] : ''));
- // $produit->volume = price2num($fields[8]);
- // $produit->volume_unit = 0;
- $produit->weight = price2num($fields['MASSE']);
- $produit->weight_units = 0; // -3 = g
- //$produit->customcode = $fields[10];
- $produit->barcode = str_pad($fields['CODE'], 12, "0", STR_PAD_LEFT);
- $produit->barcode_type = '2';
- $produit->import_key = $fields['CODE'];
-
- $produit->status = 1;
- $produit->status_buy = 1;
-
- $produit->finished = 1;
-
- // $produit->multiprices[0] = price2num($fields['TARIF0']);
- // $produit->multiprices[1] = price2num($fields['TARIF1']);
- // $produit->multiprices[2] = price2num($fields['TARIF2']);
- // $produit->multiprices[3] = price2num($fields['TARIF3']);
- // $produit->multiprices[4] = price2num($fields['TARIF4']);
- // $produit->multiprices[5] = price2num($fields['TARIF5']);
- // $produit->multiprices[6] = price2num($fields['TARIF6']);
- // $produit->multiprices[7] = price2num($fields['TARIF7']);
- // $produit->multiprices[8] = price2num($fields['TARIF8']);
- // $produit->multiprices[9] = price2num($fields['TARIF9']);
- // $produit->price_min = null;
- // $produit->price_min_ttc = null;
- // $produit->price = price2num($fields[11]);
- // $produit->price_ttc = price2num($fields[12]);
- // $produit->price_base_type = 'TTC';
- // $produit->tva_tx = price2num($fields[13]);
- $produit->tva_tx = (int) ($tvas[$fields['CODTVA']]);
- $produit->tva_npr = 0;
- // $produit->cost_price = price2num($fields[16]);
- //compta
-
- $produit->accountancy_code_buy = trim($fields['COMACH']);
- $produit->accountancy_code_sell = trim($fields['COMVEN']);
- // $produit->accountancy_code_sell_intra=trim($fields['COMVEN']);
- // $produit->accountancy_code_sell_export=trim($fields['COMVEN']);
- // Extrafields
- // $produit->array_options['options_ecotaxdeee'] = price2num($fields[17]);
-
- $produit->seuil_stock_alerte = $fields['STALERTE'];
- $ret = $produit->create($user, 0);
- if ($ret < 0) {
- print " - Error in create result code = " . $ret . " - " . $produit->errorsToString();
- $errorrecord++;
- } else {
- print " - Creation OK with ref " . $produit->ref . " - id = " . $ret;
- }
-
- dol_syslog("Add prices");
-
- // If we use price level, insert price for each level
- if (!$errorrecord && 1) {
- //$ret1 = $produit->updatePrice($produit->price_ttc, $produit->price_base_type, $user, $produit->tva_tx, $produit->price_min, 1, $produit->tva_npr, 0, 0, array());
- $ret1 = false;
- for ($i = 0; $i < 10; $i++) {
- if ($fields['TARIF' . ($i)] == 0)
- continue;
- $ret1 = $ret1 || $produit->updatePrice(price2num($fields['TARIF' . ($i)]), 'HT', $user, $produit->tva_tx, $produit->price_min, $i + 1, $produit->tva_npr, 0, 0, array()) < 0;
+if ($resql) {
+ while ($fields = $db->fetch_array($resql)) {
+ $errorrecord = 0;
+ if ($fields === false) {
+ continue;
}
- if ($ret1) {
- print " - Error in updatePrice result " . $produit->errorsToString();
+ $nboflines++;
+
+ $produit = new Product($db);
+ $produit->type = 0;
+ $produit->status = 1;
+ $produit->ref = trim($fields['REF']);
+ if ($produit->ref == '') {
+ continue;
+ }
+ print "Process line nb " . $j . ", ref " . $produit->ref;
+ $produit->label = trim($fields['LIBELLE']);
+ if ($produit->label == '') {
+ $produit->label = $produit->ref;
+ }
+ if (empty($produit->label)) {
+ continue;
+ }
+ //$produit->description = trim($fields[4] . "\n" . ($fields[5] ? $fields[5] . ' x ' . $fields[6] . ' x ' . $fields[7] : ''));
+ // $produit->volume = price2num($fields[8]);
+ // $produit->volume_unit = 0;
+ $produit->weight = price2num($fields['MASSE']);
+ $produit->weight_units = 0; // -3 = g
+ //$produit->customcode = $fields[10];
+ $produit->barcode = str_pad($fields['CODE'], 12, "0", STR_PAD_LEFT);
+ $produit->barcode_type = '2';
+ $produit->import_key = $fields['CODE'];
+
+ $produit->status = 1;
+ $produit->status_buy = 1;
+
+ $produit->finished = 1;
+
+ // $produit->multiprices[0] = price2num($fields['TARIF0']);
+ // $produit->multiprices[1] = price2num($fields['TARIF1']);
+ // $produit->multiprices[2] = price2num($fields['TARIF2']);
+ // $produit->multiprices[3] = price2num($fields['TARIF3']);
+ // $produit->multiprices[4] = price2num($fields['TARIF4']);
+ // $produit->multiprices[5] = price2num($fields['TARIF5']);
+ // $produit->multiprices[6] = price2num($fields['TARIF6']);
+ // $produit->multiprices[7] = price2num($fields['TARIF7']);
+ // $produit->multiprices[8] = price2num($fields['TARIF8']);
+ // $produit->multiprices[9] = price2num($fields['TARIF9']);
+ // $produit->price_min = null;
+ // $produit->price_min_ttc = null;
+ // $produit->price = price2num($fields[11]);
+ // $produit->price_ttc = price2num($fields[12]);
+ // $produit->price_base_type = 'TTC';
+ // $produit->tva_tx = price2num($fields[13]);
+ $produit->tva_tx = (int) ($tvas[$fields['CODTVA']]);
+ $produit->tva_npr = 0;
+ // $produit->cost_price = price2num($fields[16]);
+ //compta
+
+ $produit->accountancy_code_buy = trim($fields['COMACH']);
+ $produit->accountancy_code_sell = trim($fields['COMVEN']);
+ // $produit->accountancy_code_sell_intra=trim($fields['COMVEN']);
+ // $produit->accountancy_code_sell_export=trim($fields['COMVEN']);
+ // Extrafields
+ // $produit->array_options['options_ecotaxdeee'] = price2num($fields[17]);
+
+ $produit->seuil_stock_alerte = $fields['STALERTE'];
+ $ret = $produit->create($user, 0);
+ if ($ret < 0) {
+ print " - Error in create result code = " . $ret . " - " . $produit->errorsToString();
$errorrecord++;
} else {
- print " - updatePrice OK";
+ print " - Creation OK with ref " . $produit->ref . " - id = " . $ret;
}
- }
+ dol_syslog("Add prices");
- // dol_syslog("Add multilangs");
- // Add alternative languages
- // if (!$errorrecord && 1) {
- // $produit->multilangs['fr_FR'] = array('label' => $produit->label, 'description' => $produit->description, 'note' => $produit->note_private);
- // $produit->multilangs['en_US'] = array('label' => $fields[3], 'description' => $produit->description, 'note' => $produit->note_private);
- //
- // $ret = $produit->setMultiLangs($user);
- // if ($ret < 0) {
- // print " - Error in setMultiLangs result code = " . $ret . " - " . $produit->errorsToString();
- // $errorrecord++;
- // } else {
- // print " - setMultiLangs OK";
- // }
- // }
-
-
- dol_syslog("Add stocks");
- // stocks
- if (!$errorrecord && $fields['STOCK'] != 0) {
- $rets = $produit->correct_stock($user, 1, $fields['STOCK'], 0, 'Stock importé');
- if ($rets < 0) {
- print " - Error in correct_stock result " . $produit->errorsToString();
- $errorrecord++;
- } else {
- print " - correct_stock OK";
+ // If we use price level, insert price for each level
+ if (!$errorrecord && 1) {
+ //$ret1 = $produit->updatePrice($produit->price_ttc, $produit->price_base_type, $user, $produit->tva_tx, $produit->price_min, 1, $produit->tva_npr, 0, 0, array());
+ $ret1 = false;
+ for ($i = 0; $i < 10; $i++) {
+ if ($fields['TARIF' . ($i)] == 0) {
+ continue;
+ }
+ $ret1 = $ret1 || $produit->updatePrice(price2num($fields['TARIF' . ($i)]), 'HT', $user, $produit->tva_tx, $produit->price_min, $i + 1, $produit->tva_npr, 0, 0, array()) < 0;
+ }
+ if ($ret1) {
+ print " - Error in updatePrice result " . $produit->errorsToString();
+ $errorrecord++;
+ } else {
+ print " - updatePrice OK";
+ }
}
- }
- //update date créa
- if (!$errorrecord) {
- $date = substr($fields['DATCREA'], 0, 4) . '-' . substr($fields['DATCREA'], 4, 2) . '-' . substr($fields['DATCREA'], 6, 2);
- $retd = $db->query("UPDATE `llx_product` SET `datec` = '$date 00:00:00' WHERE `llx_product`.`rowid` = $produit->id");
- if ($retd < 1) {
- print " - Error in update date créa result " . $produit->errorsToString();
- $errorrecord++;
- } else {
- print " - update date créa OK";
+
+ // dol_syslog("Add multilangs");
+ // Add alternative languages
+ // if (!$errorrecord && 1) {
+ // $produit->multilangs['fr_FR'] = array('label' => $produit->label, 'description' => $produit->description, 'note' => $produit->note_private);
+ // $produit->multilangs['en_US'] = array('label' => $fields[3], 'description' => $produit->description, 'note' => $produit->note_private);
+ //
+ // $ret = $produit->setMultiLangs($user);
+ // if ($ret < 0) {
+ // print " - Error in setMultiLangs result code = " . $ret . " - " . $produit->errorsToString();
+ // $errorrecord++;
+ // } else {
+ // print " - setMultiLangs OK";
+ // }
+ // }
+
+
+ dol_syslog("Add stocks");
+ // stocks
+ if (!$errorrecord && $fields['STOCK'] != 0) {
+ $rets = $produit->correct_stock($user, 1, $fields['STOCK'], 0, 'Stock importé');
+ if ($rets < 0) {
+ print " - Error in correct_stock result " . $produit->errorsToString();
+ $errorrecord++;
+ } else {
+ print " - correct_stock OK";
+ }
}
- }
- print "\n";
- if ($errorrecord) {
- print( 'Error on record nb ' . $i . " - " . $produit->errorsToString() . "\n");
- var_dump($db);
- die();
- $error++; // $errorrecord will be reset
+ //update date créa
+ if (!$errorrecord) {
+ $date = substr($fields['DATCREA'], 0, 4) . '-' . substr($fields['DATCREA'], 4, 2) . '-' . substr($fields['DATCREA'], 6, 2);
+ $retd = $db->query("UPDATE `llx_product` SET `datec` = '$date 00:00:00' WHERE `llx_product`.`rowid` = $produit->id");
+ if ($retd < 1) {
+ print " - Error in update date créa result " . $produit->errorsToString();
+ $errorrecord++;
+ } else {
+ print " - update date créa OK";
+ }
+ }
+ print "\n";
+
+ if ($errorrecord) {
+ print( 'Error on record nb ' . $i . " - " . $produit->errorsToString() . "\n");
+ var_dump($db);
+ die();
+ $error++; // $errorrecord will be reset
+ }
+ $j++;
}
- $j++;
-} else die("error : $sql");
+} else {
+ die("error : $sql");
+}
diff --git a/dev/initdata/dbf/importdb-thirdparties.php b/dev/initdata/dbf/importdb-thirdparties.php
index a6b2697eed8..ecb1820fad1 100644
--- a/dev/initdata/dbf/importdb-thirdparties.php
+++ b/dev/initdata/dbf/importdb-thirdparties.php
@@ -29,8 +29,8 @@ $sapi_type = php_sapi_name();
$script_file = basename(__FILE__);
$path = dirname(__FILE__) . '/';
if (substr($sapi_type, 0, 3) == 'cgi') {
- echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
- exit;
+ echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
+ exit;
}
// Recupere root dolibarr
@@ -50,73 +50,73 @@ $confirmed = 1;
$error = 0;
$civilPrivate = array("MLLE",
- "MM",
- "MM/MADAME",
- "MME",
- "MME.",
- "MME²",
- "MMONSIEUR",
- "MMR",
- "MOBNSIEUR",
- "MOMSIEUR",
- "MON SIEUR",
- "MONDIAL",
- "MONIEUR",
- "MONJSIEUR",
- "MONNSIEUR",
- "MONRIEUR",
- "MONS",
- "MONSIEÕR",
- "MONSIER",
- "MONSIERU",
- "MONSIEU",
- "monsieue",
- "MONSIEUR",
- "Monsieur \"",
- "MONSIEUR \"",
- "MONSIEUR E",
- "MONSIEUR DENIS",
- "MONSIEUR ET MME",
- "MONSIEUR!",
- "MONSIEUR.",
- "MONSIEUR.MADAME",
- "MONSIEUR3",
- "MONSIEURN",
- "MONSIEURT",
- "MONSIEUR£",
- "MONSIEYR",
- "Monsigur",
- "MONSIIEUR",
- "MONSIUER",
- "MONSIZEUR",
- "MOPNSIEUR",
- "MOSIEUR",
- "MR",
- "Mr Mme",
- "Mr - MME",
- "MR BLANC",
- "MR ET MME",
- "mr mm",
- "MR OU MME",
- "Mr.",
- "MR/MME",
- "MRME",
- "MRR",
- "Mrs",
- "Mademoiselle",
- "MADAOME",
- "madamme",
- "MADAME",
- "M0NSIEUR",
- "M.et Madame",
- "M. ET MR",
- "M.",
- "M%",
- "M MME",
- "M ET MME",
- "M",
- "M CROCE",
- "M DIEVART",
+ "MM",
+ "MM/MADAME",
+ "MME",
+ "MME.",
+ "MME²",
+ "MMONSIEUR",
+ "MMR",
+ "MOBNSIEUR",
+ "MOMSIEUR",
+ "MON SIEUR",
+ "MONDIAL",
+ "MONIEUR",
+ "MONJSIEUR",
+ "MONNSIEUR",
+ "MONRIEUR",
+ "MONS",
+ "MONSIEÕR",
+ "MONSIER",
+ "MONSIERU",
+ "MONSIEU",
+ "monsieue",
+ "MONSIEUR",
+ "Monsieur \"",
+ "MONSIEUR \"",
+ "MONSIEUR E",
+ "MONSIEUR DENIS",
+ "MONSIEUR ET MME",
+ "MONSIEUR!",
+ "MONSIEUR.",
+ "MONSIEUR.MADAME",
+ "MONSIEUR3",
+ "MONSIEURN",
+ "MONSIEURT",
+ "MONSIEUR£",
+ "MONSIEYR",
+ "Monsigur",
+ "MONSIIEUR",
+ "MONSIUER",
+ "MONSIZEUR",
+ "MOPNSIEUR",
+ "MOSIEUR",
+ "MR",
+ "Mr Mme",
+ "Mr - MME",
+ "MR BLANC",
+ "MR ET MME",
+ "mr mm",
+ "MR OU MME",
+ "Mr.",
+ "MR/MME",
+ "MRME",
+ "MRR",
+ "Mrs",
+ "Mademoiselle",
+ "MADAOME",
+ "madamme",
+ "MADAME",
+ "M0NSIEUR",
+ "M.et Madame",
+ "M. ET MR",
+ "M.",
+ "M%",
+ "M MME",
+ "M ET MME",
+ "M",
+ "M CROCE",
+ "M DIEVART",
);
/*
@@ -130,128 +130,134 @@ dol_syslog($script_file . " launched with arg " . implode(',', $argv));
$table = $argv[1];
if (empty($argv[1])) {
- print "Error: Quelle table ?\n";
- print "\n";
- exit(-1);
+ print "Error: Quelle table ?\n";
+ print "\n";
+ exit(-1);
}
$ret = $user->fetch('', 'admin');
if (!$ret > 0) {
- print 'A user with login "admin" and all permissions must be created to use this script.' . "\n";
- exit;
+ print 'A user with login "admin" and all permissions must be created to use this script.' . "\n";
+ exit;
}
$sql = "SELECT * FROM `$table` WHERE 1 "; //ORDER BY REMISE DESC,`LCIVIL` DESC";
$resql = $db->query($sql);
//$db->begin();
-if ($resql)
-while ($fields = $db->fetch_array($resql)) {
- $i++;
- $errorrecord = 0;
+if ($resql) {
+ while ($fields = $db->fetch_array($resql)) {
+ $i++;
+ $errorrecord = 0;
- if ($startlinenb && $i < $startlinenb)
- continue;
- if ($endlinenb && $i > $endlinenb)
- continue;
-
- $nboflines++;
-
- $object = new Societe($db);
- $object->import_key = $fields['CODE'];
- $object->state = 1;
- $object->client = 3;
- $object->fournisseur = 0;
-
- $object->name = $fields['FCIVIL'] . ' ' . $fields['FNOM'];
- //$object->name_alias = $fields[0] != $fields[13] ? trim($fields[0]) : '';
-
- $date = $fields['DATCREA'] ? $fields['DATCREA'] : ($fields['DATMOD'] ? $fields['DATMOD'] : '20200101');
- $object->code_client = 'CU' . substr($date, 2, 2) . substr($date, 4, 2) . '-' . str_pad(substr($fields['CODE'], 0, 5), 5, "0", STR_PAD_LEFT);
-
-
- $object->address = trim($fields['FADR1']);
- if ($fields['FADR2'])
- $object->address .= "\n" . trim($fields['FADR2']);
- if ($fields['FADR3'])
- $object->address .= "\n" . trim($fields['FADR3']);
-
- $object->zip = trim($fields['FPOSTE']);
- $object->town = trim($fields['FVILLE']);
- if ($fields['FPAYS'])
- $object->country_id = dol_getIdFromCode($db, trim(ucwords(strtolower($fields['FPAYS']))), 'c_country', 'label', 'rowid');
- else $object->country_id = 1;
- $object->phone = trim($fields['FTEL']) ? trim($fields['FTEL']) : trim($fields['FCONTACT']);
- $object->phone = substr($object->phone, 0, 20);
- $object->fax = trim($fields['FFAX']) ? trim($fields['FFAX']) : trim($fields['FCONTACT']);
- $object->fax = substr($object->fax, 0, 20);
- $object->email = trim($fields['FMAIL']);
- // $object->idprof2 = trim($fields[29]);
- $object->tva_intra = str_replace(['.', ' '], '', $fields['TVAINTRA']);
- $object->tva_intra = substr($object->tva_intra, 0, 20);
- $object->default_lang = 'fr_FR';
-
- $object->cond_reglement_id = dol_getIdFromCode($db, 'PT_ORDER', 'c_payment_term', 'code', 'rowid', 1);
- $object->multicurrency_code = 'EUR';
-
- if ($fields['REMISE'] != '0.00') {
- $object->remise_percent = abs($fields['REMISE']);
- }
-
- // $object->code_client = $fields[9];
- // $object->code_fournisseur = $fields[10];
-
-
- if ($fields['FCIVIL']) {
- $labeltype = in_array($fields['FCIVIL'], $civilPrivate) ? 'TE_PRIVATE' : 'TE_SMALL';
- $object->typent_id = dol_getIdFromCode($db, $labeltype, 'c_typent', 'code');
- }
-
- // Set price level
- $object->price_level = $fields['TARIF'] + 1;
- // if ($labeltype == 'Revendeur')
- // $object->price_level = 2;
-
- print "Process line nb " . $i . ", code " . $fields['CODE'] . ", name " . $object->name;
-
-
- // Extrafields
- $object->array_options['options_banque'] = $fields['BANQUE'];
- $object->array_options['options_banque2'] = $fields['BANQUE2'];
- $object->array_options['options_banquevalid'] = $fields['VALID'];
-
- if (!$errorrecord) {
- $ret = $object->create($user);
- if ($ret < 0) {
- print " - Error in create result code = " . $ret . " - " . $object->errorsToString();
- $errorrecord++;
- var_dump($object->code_client, $db);
- die();
- } else {
- print " - Creation OK with name " . $object->name . " - id = " . $ret;
+ if ($startlinenb && $i < $startlinenb) {
+ continue;
+ }
+ if ($endlinenb && $i > $endlinenb) {
+ continue;
}
- }
- if (!$errorrecord) {
- dol_syslog("Set price level");
- $object->set_price_level($object->price_level, $user);
- }
- if (!$errorrecord && @$object->remise_percent) {
- dol_syslog("Set remise client");
- $object->set_remise_client($object->remise_percent, 'Importé', $user);
- }
+ $nboflines++;
- dol_syslog("Add contact");
- // Insert an invoice contact if there is an invoice email != standard email
- if (!$errorrecord && ($fields['LCIVIL'] || $fields['LNOM'])) {
- $madame = array("MADAME",
+ $object = new Societe($db);
+ $object->import_key = $fields['CODE'];
+ $object->state = 1;
+ $object->client = 3;
+ $object->fournisseur = 0;
+
+ $object->name = $fields['FCIVIL'] . ' ' . $fields['FNOM'];
+ //$object->name_alias = $fields[0] != $fields[13] ? trim($fields[0]) : '';
+
+ $date = $fields['DATCREA'] ? $fields['DATCREA'] : ($fields['DATMOD'] ? $fields['DATMOD'] : '20200101');
+ $object->code_client = 'CU' . substr($date, 2, 2) . substr($date, 4, 2) . '-' . str_pad(substr($fields['CODE'], 0, 5), 5, "0", STR_PAD_LEFT);
+
+
+ $object->address = trim($fields['FADR1']);
+ if ($fields['FADR2']) {
+ $object->address .= "\n" . trim($fields['FADR2']);
+ }
+ if ($fields['FADR3']) {
+ $object->address .= "\n" . trim($fields['FADR3']);
+ }
+
+ $object->zip = trim($fields['FPOSTE']);
+ $object->town = trim($fields['FVILLE']);
+ if ($fields['FPAYS']) {
+ $object->country_id = dol_getIdFromCode($db, trim(ucwords(strtolower($fields['FPAYS']))), 'c_country', 'label', 'rowid');
+ } else {
+ $object->country_id = 1;
+ }
+ $object->phone = trim($fields['FTEL']) ? trim($fields['FTEL']) : trim($fields['FCONTACT']);
+ $object->phone = substr($object->phone, 0, 20);
+ $object->fax = trim($fields['FFAX']) ? trim($fields['FFAX']) : trim($fields['FCONTACT']);
+ $object->fax = substr($object->fax, 0, 20);
+ $object->email = trim($fields['FMAIL']);
+ // $object->idprof2 = trim($fields[29]);
+ $object->tva_intra = str_replace(['.', ' '], '', $fields['TVAINTRA']);
+ $object->tva_intra = substr($object->tva_intra, 0, 20);
+ $object->default_lang = 'fr_FR';
+
+ $object->cond_reglement_id = dol_getIdFromCode($db, 'PT_ORDER', 'c_payment_term', 'code', 'rowid', 1);
+ $object->multicurrency_code = 'EUR';
+
+ if ($fields['REMISE'] != '0.00') {
+ $object->remise_percent = abs($fields['REMISE']);
+ }
+
+ // $object->code_client = $fields[9];
+ // $object->code_fournisseur = $fields[10];
+
+
+ if ($fields['FCIVIL']) {
+ $labeltype = in_array($fields['FCIVIL'], $civilPrivate) ? 'TE_PRIVATE' : 'TE_SMALL';
+ $object->typent_id = dol_getIdFromCode($db, $labeltype, 'c_typent', 'code');
+ }
+
+ // Set price level
+ $object->price_level = $fields['TARIF'] + 1;
+ // if ($labeltype == 'Revendeur')
+ // $object->price_level = 2;
+
+ print "Process line nb " . $i . ", code " . $fields['CODE'] . ", name " . $object->name;
+
+
+ // Extrafields
+ $object->array_options['options_banque'] = $fields['BANQUE'];
+ $object->array_options['options_banque2'] = $fields['BANQUE2'];
+ $object->array_options['options_banquevalid'] = $fields['VALID'];
+
+ if (!$errorrecord) {
+ $ret = $object->create($user);
+ if ($ret < 0) {
+ print " - Error in create result code = " . $ret . " - " . $object->errorsToString();
+ $errorrecord++;
+ var_dump($object->code_client, $db);
+ die();
+ } else {
+ print " - Creation OK with name " . $object->name . " - id = " . $ret;
+ }
+ }
+
+ if (!$errorrecord) {
+ dol_syslog("Set price level");
+ $object->set_price_level($object->price_level, $user);
+ }
+ if (!$errorrecord && @$object->remise_percent) {
+ dol_syslog("Set remise client");
+ $object->set_remise_client($object->remise_percent, 'Importé', $user);
+ }
+
+ dol_syslog("Add contact");
+ // Insert an invoice contact if there is an invoice email != standard email
+ if (!$errorrecord && ($fields['LCIVIL'] || $fields['LNOM'])) {
+ $madame = array("MADAME",
"MADEMOISELLE",
"MELLE",
"MLLE",
"MM",
"Mme",
"MNE",
- );
- $monsieur = array("M",
+ );
+ $monsieur = array("M",
"M ET MME",
"M MME",
"M.",
@@ -268,77 +274,84 @@ while ($fields = $db->fetch_array($resql)) {
"MONSIUER",
"MONSKIEUR",
"MR",
- );
- $ret1 = $ret2 = 0;
+ );
+ $ret1 = $ret2 = 0;
- $contact = new Contact($db);
- if (in_array($fields['LCIVIL'], $madame)) {
- // une dame
- $contact->civility_id = 'MME';
- $contact->lastname = $fields['LNOM'];
- } elseif (in_array($fields['LCIVIL'], $monsieur)) {
- // un monsieur
- $contact->civility_id = 'MR';
- $contact->lastname = $fields['LNOM'];
- } elseif (in_array($fields['LCIVIL'], ['DOCTEUR'])) {
- // un monsieur
- $contact->civility_id = 'DR';
- $contact->lastname = $fields['LNOM'];
- } else {
- // un a rattraper
- $contact->lastname = $fields['LCIVIL'] . " " . $fields['LNOM'];
- }
- $contact->address = trim($fields['LADR1']);
- if ($fields['LADR2'])
- $contact->address .= "\n" . trim($fields['LADR2']);
- if ($fields['LADR3'])
- $contact->address .= "\n" . trim($fields['LADR3']);
+ $contact = new Contact($db);
+ if (in_array($fields['LCIVIL'], $madame)) {
+ // une dame
+ $contact->civility_id = 'MME';
+ $contact->lastname = $fields['LNOM'];
+ } elseif (in_array($fields['LCIVIL'], $monsieur)) {
+ // un monsieur
+ $contact->civility_id = 'MR';
+ $contact->lastname = $fields['LNOM'];
+ } elseif (in_array($fields['LCIVIL'], ['DOCTEUR'])) {
+ // un monsieur
+ $contact->civility_id = 'DR';
+ $contact->lastname = $fields['LNOM'];
+ } else {
+ // un a rattraper
+ $contact->lastname = $fields['LCIVIL'] . " " . $fields['LNOM'];
+ }
+ $contact->address = trim($fields['LADR1']);
+ if ($fields['LADR2']) {
+ $contact->address .= "\n" . trim($fields['LADR2']);
+ }
+ if ($fields['LADR3']) {
+ $contact->address .= "\n" . trim($fields['LADR3']);
+ }
- $contact->zip = trim($fields['LPOSTE']);
- $contact->town = trim($fields['LVILLE']);
- if ($fields['FPAYS'])
- $contact->country_id = dol_getIdFromCode($db, trim(ucwords(strtolower($fields['LPAYS']))), 'c_country', 'label', 'rowid');
- else $contact->country_id = 1;
- $contact->email = $fields['LMAIL'];
- $contact->phone = trim($fields['LTEL']) ? trim($fields['LTEL']) : trim($fields['LCONTACT']);
- $contact->fax = trim($fields['LFAX']) ? trim($fields['LFAX']) : trim($fields['LCONTACT']);
- $contact->socid = $object->id;
+ $contact->zip = trim($fields['LPOSTE']);
+ $contact->town = trim($fields['LVILLE']);
+ if ($fields['FPAYS']) {
+ $contact->country_id = dol_getIdFromCode($db, trim(ucwords(strtolower($fields['LPAYS']))), 'c_country', 'label', 'rowid');
+ } else {
+ $contact->country_id = 1;
+ }
+ $contact->email = $fields['LMAIL'];
+ $contact->phone = trim($fields['LTEL']) ? trim($fields['LTEL']) : trim($fields['LCONTACT']);
+ $contact->fax = trim($fields['LFAX']) ? trim($fields['LFAX']) : trim($fields['LCONTACT']);
+ $contact->socid = $object->id;
- $ret1 = $contact->create($user);
- if ($ret1 > 0) {
- //$ret2=$contact->add_contact($object->id, 'BILLING');
+ $ret1 = $contact->create($user);
+ if ($ret1 > 0) {
+ //$ret2=$contact->add_contact($object->id, 'BILLING');
+ }
+ if ($ret1 < 0 || $ret2 < 0) {
+ print " - Error in create contact result code = " . $ret1 . " " . $ret2 . " - " . $contact->errorsToString();
+ $errorrecord++;
+ } else {
+ print " - create contact OK";
+ }
}
- if ($ret1 < 0 || $ret2 < 0) {
- print " - Error in create contact result code = " . $ret1 . " " . $ret2 . " - " . $contact->errorsToString();
- $errorrecord++;
- } else {
- print " - create contact OK";
+
+
+ //update date créa
+ if (!$errorrecord) {
+ $datec = substr($date, 0, 4) . '-' . substr($date, 4, 2) . '-' . substr($date, 6, 2);
+ $retd = $db->query("UPDATE `llx_societe` SET `datec` = '$datec 00:00:00' WHERE `rowid` = $object->id");
+ if ($retd < 1) {
+ print " - Error in update date créa result " . $object->errorsToString();
+ $errorrecord++;
+ } else {
+ print " - update date créa OK";
+ }
}
+ print "\n";
+
+ if ($errorrecord) {
+ print( 'Error on record nb ' . $i . " - " . $object->errorsToString() . "\n");
+ var_dump($db, $object, $contact);
+ // $db->rollback();
+ die();
+ $error++; // $errorrecord will be reset
+ }
+ $j++;
}
-
-
- //update date créa
- if (!$errorrecord) {
- $datec = substr($date, 0, 4) . '-' . substr($date, 4, 2) . '-' . substr($date, 6, 2);
- $retd = $db->query("UPDATE `llx_societe` SET `datec` = '$datec 00:00:00' WHERE `rowid` = $object->id");
- if ($retd < 1) {
- print " - Error in update date créa result " . $object->errorsToString();
- $errorrecord++;
- } else {
- print " - update date créa OK";
- }
- }
- print "\n";
-
- if ($errorrecord) {
- print( 'Error on record nb ' . $i . " - " . $object->errorsToString() . "\n");
- var_dump($db, $object, $contact);
- // $db->rollback();
- die();
- $error++; // $errorrecord will be reset
- }
- $j++;
-} else die("error : $sql");
+} else {
+ die("error : $sql");
+}
$db->commit();
diff --git a/dev/initdata/dbf/includes/dbase.class.php b/dev/initdata/dbf/includes/dbase.class.php
index e70f18087c4..a225d67cde9 100644
--- a/dev/initdata/dbf/includes/dbase.class.php
+++ b/dev/initdata/dbf/includes/dbase.class.php
@@ -18,382 +18,582 @@ define('DBASE_TYPE_FOXPRO', 1);
*/
class DBase
{
- private $fd;
- private $headerLength = 0;
- private $fields = array();
- private $fieldCount = 0;
- private $recordLength = 0;
- private $recordCount = 0;
+ private $fd;
+ private $headerLength = 0;
+ private $fields = array();
+ private $fieldCount = 0;
+ private $recordLength = 0;
+ private $recordCount = 0;
- //resource dbase_open ( string $filename , int $mode )
- public static function open($filename, $mode)
+ /**
+ * resource dbase_open
+ * @param string $filename filename
+ * @param int $mode mode
+ * @return DBase
+ */
+ public static function open($filename, $mode)
{
- if (!file_exists($filename))
- return false;
- $modes = array('r', 'w', 'r+');
- $mode = $modes[$mode];
- $fd = fopen($filename, $mode);
- if (!$fd)
- return false;
- return new DBase($fd);
- }
+ if (!file_exists($filename)) {
+ return false;
+ }
+ $modes = array('r', 'w', 'r+');
+ $mode = $modes[$mode];
+ $fd = fopen($filename, $mode);
+ if (!$fd) {
+ return false;
+ }
+ return new DBase($fd);
+ }
- //resource dbase_create ( string $filename , array $fields [, int $type = DBASE_TYPE_DBASE ] )
- public static function create($filename, $fields, $type = DBASE_TYPE_DBASE)
+ /**
+ * resource dbase_create
+ * @param string $filename filename
+ * @param array $fields fields
+ * @param int $type DBASE_TYPE_DBASE
+ * @return DBase
+ */
+ public static function create($filename, $fields, $type = DBASE_TYPE_DBASE)
{
- if (file_exists($filename))
- return false;
- $fd = fopen($filename, 'c+');
- if (!$fd)
- return false;
- // Byte 0 (1 byte): Valid dBASE for DOS file; bits 0-2 indicate version number, bit 3
- // indicates the presence of a dBASE for DOS memo file, bits 4-6 indicate the
- // presence of a SQL table, bit 7 indicates the presence of any memo file
- // (either dBASE m PLUS or dBASE for DOS)
- self::putChar8($fd, 5);
- // Byte 1-3 (3 bytes): Date of last update; formatted as YYMMDD
- self::putChar8($fd, date('Y') - 1900);
- self::putChar8($fd, date('m'));
- self::putChar8($fd, date('d'));
- // Byte 4-7 (32-bit number): Number of records in the database file. Currently 0
- self::putInt32($fd, 0);
- // Byte 8-9 (16-bit number): Number of bytes in the header.
- self::putInt16($fd, 32 + (32 * count($fields)) + 1);
- // Byte 10-11 (16-bit number): Number of bytes in record.
- // Make sure the include the byte for deleted flag
- $len = 1;
- foreach ($fields as &$field)
- $len += self::length($field);
- self::putInt16($fd, $len);
- // Byte 12-13 (2 bytes): Reserved, 0 filled.
- self::putInt16($fd, 0);
- // Byte 14 (1 byte): Flag indicating incomplete transaction
- // The ISMARKEDO function checks this flag. BEGIN TRANSACTION sets it to 1, END TRANSACTION and ROLLBACK reset it to 0.
- self::putChar8($fd, 0);
- // Byte 15 (1 byte): Encryption flag. If this flag is set to 1, the message Database encrypted appears. Changing this flag to 0 removes the message, but does not decrypt the file.
- self::putChar8($fd, 0);
- // Byte 16-27 (12 bytes): Reserved for dBASE for DOS in a multi-user environment
- self::putInt32($fd, 0);
- self::putInt32($fd, 0);
- self::putInt32($fd, 0);
- // Byte 28 (1 byte): Production .mdx file flag; 0x01 if there is a production .mdx file, 0x00 if not
- self::putChar8($fd, 0);
- // Byte 29 (1 byte): Language driver ID
- // (no clue what this is)
- self::putChar8($fd, 0);
- // Byte 30-31 (2 bytes): Reserved, 0 filled.
- self::putInt16($fd, 0);
- // Byte 32 - n (32 bytes each): Field descriptor array
- foreach ($fields as &$field) {
- self::putString($fd, $field[0], 11); // Byte 0 - 10 (11 bytes): Field name in ASCII (zero-filled)
- self::putString($fd, $field[1], 1); // Byte 11 (1 byte): Field type in ASCII (C, D, F, L, M, or N)
- self::putInt32($fd, 0); // Byte 12 - 15 (4 bytes): Reserved
- self::putChar8($fd, self::length($field)); // Byte 16 (1 byte): Field length in binary. The maximum length of a field is 254 (0xFE).
- self::putChar8($fd, $field[3]); // Byte 17 (1 byte): Field decimal count in binary
- self::putInt16($fd, 0); // Byte 18 - 19 (2 bytes): Work area ID
- self::putChar8($fd, 0); // Byte 20 (1 byte): Example (??)
- self::putInt32($fd, 0); // Byte 21 - 30 (10 bytes): Reserved
- self::putInt32($fd, 0);
- self::putInt16($fd, 0);
- self::putChar8($fd, 0); // Byte 31 (1 byte): Production MDX field flag; 1 if field has an index tag in the production MDX file, 0 if not
- }
- // Byte n + 1 (1 byte): 0x0D as the field descriptor array terminator
- self::putChar8($fd, 0x0D);
- return new DBase($fd);
- }
+ if (file_exists($filename)) {
+ return false;
+ }
+ $fd = fopen($filename, 'c+');
+ if (!$fd) {
+ return false;
+ }
+ // Byte 0 (1 byte): Valid dBASE for DOS file; bits 0-2 indicate version number, bit 3
+ // indicates the presence of a dBASE for DOS memo file, bits 4-6 indicate the
+ // presence of a SQL table, bit 7 indicates the presence of any memo file
+ // (either dBASE m PLUS or dBASE for DOS)
+ self::putChar8($fd, 5);
+ // Byte 1-3 (3 bytes): Date of last update; formatted as YYMMDD
+ self::putChar8($fd, date('Y') - 1900);
+ self::putChar8($fd, date('m'));
+ self::putChar8($fd, date('d'));
+ // Byte 4-7 (32-bit number): Number of records in the database file. Currently 0
+ self::putInt32($fd, 0);
+ // Byte 8-9 (16-bit number): Number of bytes in the header.
+ self::putInt16($fd, 32 + (32 * count($fields)) + 1);
+ // Byte 10-11 (16-bit number): Number of bytes in record.
+ // Make sure the include the byte for deleted flag
+ $len = 1;
+ foreach ($fields as &$field) {
+ $len += self::length($field);
+ }
+ self::putInt16($fd, $len);
+ // Byte 12-13 (2 bytes): Reserved, 0 filled.
+ self::putInt16($fd, 0);
+ // Byte 14 (1 byte): Flag indicating incomplete transaction
+ // The ISMARKEDO function checks this flag. BEGIN TRANSACTION sets it to 1, END TRANSACTION and ROLLBACK reset it to 0.
+ self::putChar8($fd, 0);
+ // Byte 15 (1 byte): Encryption flag. If this flag is set to 1, the message Database encrypted appears. Changing this flag to 0 removes the message, but does not decrypt the file.
+ self::putChar8($fd, 0);
+ // Byte 16-27 (12 bytes): Reserved for dBASE for DOS in a multi-user environment
+ self::putInt32($fd, 0);
+ self::putInt32($fd, 0);
+ self::putInt32($fd, 0);
+ // Byte 28 (1 byte): Production .mdx file flag; 0x01 if there is a production .mdx file, 0x00 if not
+ self::putChar8($fd, 0);
+ // Byte 29 (1 byte): Language driver ID
+ // (no clue what this is)
+ self::putChar8($fd, 0);
+ // Byte 30-31 (2 bytes): Reserved, 0 filled.
+ self::putInt16($fd, 0);
+ // Byte 32 - n (32 bytes each): Field descriptor array
+ foreach ($fields as &$field) {
+ self::putString($fd, $field[0], 11); // Byte 0 - 10 (11 bytes): Field name in ASCII (zero-filled)
+ self::putString($fd, $field[1], 1); // Byte 11 (1 byte): Field type in ASCII (C, D, F, L, M, or N)
+ self::putInt32($fd, 0); // Byte 12 - 15 (4 bytes): Reserved
+ self::putChar8($fd, self::length($field)); // Byte 16 (1 byte): Field length in binary. The maximum length of a field is 254 (0xFE).
+ self::putChar8($fd, $field[3]); // Byte 17 (1 byte): Field decimal count in binary
+ self::putInt16($fd, 0); // Byte 18 - 19 (2 bytes): Work area ID
+ self::putChar8($fd, 0); // Byte 20 (1 byte): Example (??)
+ self::putInt32($fd, 0); // Byte 21 - 30 (10 bytes): Reserved
+ self::putInt32($fd, 0);
+ self::putInt16($fd, 0);
+ self::putChar8($fd, 0); // Byte 31 (1 byte): Production MDX field flag; 1 if field has an index tag in the production MDX file, 0 if not
+ }
+ // Byte n + 1 (1 byte): 0x0D as the field descriptor array terminator
+ self::putChar8($fd, 0x0D);
+ return new DBase($fd);
+ }
- // Create DBase instance
- private function __construct($fd)
+ /**
+ * Create DBase instance
+ * @param mixed $fd file descriptor
+ * @return void
+ */
+ private function __construct($fd)
{
- $this->fd = $fd;
- // Byte 4-7 (32-bit number): Number of records in the database file. Currently 0
- fseek($this->fd, 4, SEEK_SET);
- $this->recordCount = self::getInt32($fd);
- // Byte 8-9 (16-bit number): Number of bytes in the header.
- fseek($this->fd, 8, SEEK_SET);
- $this->headerLength = self::getInt16($fd);
- // Number of fields is (headerLength - 33) / 32)
- $this->fieldCount = ($this->headerLength - 33) / 32;
- // Byte 10-11 (16-bit number): Number of bytes in record.
- fseek($this->fd, 10, SEEK_SET);
- $this->recordLength = self::getInt16($fd);
- // Byte 32 - n (32 bytes each): Field descriptor array
- fseek($fd, 32, SEEK_SET);
- for ($i = 0; $i < $this->fieldCount; $i++) {
- $data = fread($this->fd, 32);
- $field = array_map('trim', unpack('a11name/a1type/c4/c1length/c1precision/s1workid/c1example/c10/c1production', $data));
- $this->fields[] = $field;
- }
- }
+ $this->fd = $fd;
+ // Byte 4-7 (32-bit number): Number of records in the database file. Currently 0
+ fseek($this->fd, 4, SEEK_SET);
+ $this->recordCount = self::getInt32($fd);
+ // Byte 8-9 (16-bit number): Number of bytes in the header.
+ fseek($this->fd, 8, SEEK_SET);
+ $this->headerLength = self::getInt16($fd);
+ // Number of fields is (headerLength - 33) / 32)
+ $this->fieldCount = ($this->headerLength - 33) / 32;
+ // Byte 10-11 (16-bit number): Number of bytes in record.
+ fseek($this->fd, 10, SEEK_SET);
+ $this->recordLength = self::getInt16($fd);
+ // Byte 32 - n (32 bytes each): Field descriptor array
+ fseek($fd, 32, SEEK_SET);
+ for ($i = 0; $i < $this->fieldCount; $i++) {
+ $data = fread($this->fd, 32);
+ $field = array_map('trim', unpack('a11name/a1type/c4/c1length/c1precision/s1workid/c1example/c10/c1production', $data));
+ $this->fields[] = $field;
+ }
+ }
- //bool dbase_close ( resource $dbase_identifier )
- public function close()
+ /**
+ * dbase_close
+ * @return void
+ */
+ public function close()
{
- fclose($this->fd);
- }
+ fclose($this->fd);
+ }
- //array dbase_get_header_info ( resource $dbase_identifier )
- public function get_header_info()
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ /**
+ * dbase_get_header_info
+ * @return array
+ */
+ public function get_header_info()
{
- return $this->fields;
- }
+ // phpcs:disable
+ return $this->fields;
+ }
- //int dbase_numfields ( resource $dbase_identifier )
- public function numfields()
+ /**
+ * dbase_numfields
+ * @return int
+ */
+ public function numfields()
{
- return $this->fieldCount;
- }
+ return $this->fieldCount;
+ }
- //int dbase_numrecords ( resource $dbase_identifier )
- public function numrecords()
+ /**
+ * dbase_numrecords
+ * @return int
+ */
+ public function numrecords()
{
- return $this->recordCount;
- }
+ return $this->recordCount;
+ }
- //bool dbase_add_record ( resource $dbase_identifier , array $record )
- public function add_record($record)
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ /**
+ * dbase_add_record
+ * @param array $record record
+ * @return bool
+ */
+ public function add_record($record)
{
- if (count($record) != $this->fieldCount)
- return false;
- // Seek to end of file, minus the end of file marker
- fseek($this->fd, 0, SEEK_END);
- // Put the deleted flag
- self::putChar8($this->fd, 0x20);
- // Put the record
- if (!$this->putRecord($record))
- return false;
- // Update the record count
- fseek($this->fd, 4);
- self::putInt32($this->fd, ++$this->recordCount);
- return true;
- }
+ // phpcs:enable
+ if (count($record) != $this->fieldCount) {
+ return false;
+ }
+ // Seek to end of file, minus the end of file marker
+ fseek($this->fd, 0, SEEK_END);
+ // Put the deleted flag
+ self::putChar8($this->fd, 0x20);
+ // Put the record
+ if (!$this->putRecord($record)) {
+ return false;
+ }
+ // Update the record count
+ fseek($this->fd, 4);
+ self::putInt32($this->fd, ++$this->recordCount);
+ return true;
+ }
- //bool dbase_replace_record ( resource $dbase_identifier , array $record , int $record_number )
- public function replace_record($record, $record_number)
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ /**
+ * dbase_replace_record
+ * @param array $record record
+ * @param int $record_number record number
+ * @return bool
+ */
+ public function replace_record($record, $record_number)
{
- if (count($record) != $this->fieldCount)
- return false;
- if ($record_number < 1 || $record_number > $this->recordCount)
- return false;
- // Skip to the record location, plus the 1 byte for the deleted flag
- fseek($this->fd, $this->headerLength + ($this->recordLength * ($record_number - 1)) + 1);
- return $this->putRecord($record);
- }
+ // phpcs:enable
+ if (count($record) != $this->fieldCount) {
+ return false;
+ }
+ if ($record_number < 1 || $record_number > $this->recordCount) {
+ return false;
+ }
+ // Skip to the record location, plus the 1 byte for the deleted flag
+ fseek($this->fd, $this->headerLength + ($this->recordLength * ($record_number - 1)) + 1);
+ return $this->putRecord($record);
+ }
- //bool dbase_delete_record ( resource $dbase_identifier , int $record_number )
- public function delete_record($record_number)
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ /**
+ * dbase_delete_record
+ * @param int $record_number record number
+ * @return bool
+ */
+ public function delete_record($record_number)
{
- if ($record_number < 1 || $record_number > $this->recordCount)
- return false;
- fseek($this->fd, $this->headerLength + ($this->recordLength * ($record_number - 1)));
- self::putChar8($this->fd, 0x2A);
- return true;
- }
+ // phpcs:enable
+ if ($record_number < 1 || $record_number > $this->recordCount) {
+ return false;
+ }
+ fseek($this->fd, $this->headerLength + ($this->recordLength * ($record_number - 1)));
+ self::putChar8($this->fd, 0x2A);
+ return true;
+ }
- //array dbase_get_record ( resource $dbase_identifier , int $record_number )
- public function get_record($record_number)
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ /**
+ * dbase_get_record
+ * @param int $record_number record number
+ * @return array
+ */
+ public function get_record($record_number)
{
- if ($record_number < 1 || $record_number > $this->recordCount)
- return false;
- fseek($this->fd, $this->headerLength + ($this->recordLength * ($record_number - 1)));
- $record = array(
- 'deleted' => self::getChar8($this->fd) == 0x2A ? 1 : 0
- );
- foreach ($this->fields as $i => &$field) {
- $value = trim(fread($this->fd, $field['length']));
- if ($field['type'] == 'L') {
- $value = strtolower($value);
- if ($value == 't' || $value == 'y')
- $value = true;
- elseif ($value == 'f' || $value == 'n')
- $value = false;
- else $value = null;
- }
- $record[$i] = $value;
- }
- return $record;
- }
+ // phpcs:enable
+ if ($record_number < 1 || $record_number > $this->recordCount) {
+ return false;
+ }
+ fseek($this->fd, $this->headerLength + ($this->recordLength * ($record_number - 1)));
+ $record = array(
+ 'deleted' => self::getChar8($this->fd) == 0x2A ? 1 : 0
+ );
+ foreach ($this->fields as $i => &$field) {
+ $value = trim(fread($this->fd, $field['length']));
+ if ($field['type'] == 'L') {
+ $value = strtolower($value);
+ if ($value == 't' || $value == 'y') {
+ $value = true;
+ } elseif ($value == 'f' || $value == 'n') {
+ $value = false;
+ } else {
+ $value = null;
+ }
+ }
+ $record[$i] = $value;
+ }
+ return $record;
+ }
- //array dbase_get_record_with_names ( resource $dbase_identifier , int $record_number )
- public function get_record_with_names($record_number)
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ /**
+ * dbase_get_record_with_names
+ * @param int $record_number record number
+ * @return array
+ */
+ public function get_record_with_names($record_number)
{
- if ($record_number < 1 || $record_number > $this->recordCount)
- return false;
- $record = $this->get_record($record_number);
- foreach ($this->fields as $i => &$field) {
- $record[$field['name']] = $record[$i];
- unset($record[$i]);
- }
- return $record;
- }
+ // phpcs:enable
+ if ($record_number < 1 || $record_number > $this->recordCount) {
+ return false;
+ }
+ $record = $this->get_record($record_number);
+ foreach ($this->fields as $i => &$field) {
+ $record[$field['name']] = $record[$i];
+ unset($record[$i]);
+ }
+ return $record;
+ }
- //bool dbase_pack ( resource $dbase_identifier )
- public function pack()
+ /**
+ * dbase_pack
+ * @return void
+ */
+ public function pack()
{
- $in_offset = $out_offset = $this->headerLength;
- $new_count = 0;
- $rec_count = $this->recordCount;
- while ($rec_count > 0) {
- fseek($this->fd, $in_offset, SEEK_SET);
- $record = fread($this->fd, $this->recordLength);
- $deleted = substr($record, 0, 1);
- if ($deleted != '*') {
- fseek($this->fd, $out_offset, SEEK_SET);
- fwrite($this->fd, $record);
- $out_offset += $this->recordLength;
- $new_count++;
- }
- $in_offset += $this->recordLength;
- $rec_count--;
- }
- ftruncate($this->fd, $out_offset);
- // Update the record count
- fseek($this->fd, 4);
- self::putInt32($this->fd, $new_count);
- }
+ $in_offset = $out_offset = $this->headerLength;
+ $new_count = 0;
+ $rec_count = $this->recordCount;
+ while ($rec_count > 0) {
+ fseek($this->fd, $in_offset, SEEK_SET);
+ $record = fread($this->fd, $this->recordLength);
+ $deleted = substr($record, 0, 1);
+ if ($deleted != '*') {
+ fseek($this->fd, $out_offset, SEEK_SET);
+ fwrite($this->fd, $record);
+ $out_offset += $this->recordLength;
+ $new_count++;
+ }
+ $in_offset += $this->recordLength;
+ $rec_count--;
+ }
+ ftruncate($this->fd, $out_offset);
+ // Update the record count
+ fseek($this->fd, 4);
+ self::putInt32($this->fd, $new_count);
+ }
- /*
- * A few utilitiy functions
- */
+ /*
+ * A few utilitiy functions
+ */
- private static function length($field)
+ /**
+ * @param string $field field
+ * @return int
+ */
+ private static function length($field)
{
- switch ($field[1]) {
- case 'D': // Date: Numbers and a character to separate month, day, and year (stored internally as 8 digits in YYYYMMDD format)
- return 8;
- case 'T': // DateTime (YYYYMMDDhhmmss.uuu) (FoxPro)
- return 18;
- case 'M': // Memo (ignored): All ASCII characters (stored internally as 10 digits representing a .dbt block number, right justified, padded with whitespaces)
- case 'N': // Number: -.0123456789 (right justified, padded with whitespaces)
- case 'F': // Float: -.0123456789 (right justified, padded with whitespaces)
- case 'C': // String: All ASCII characters (padded with whitespaces up to the field's length)
- return $field[2];
- case 'L': // Boolean: YyNnTtFf? (? when not initialized)
- return 1;
- }
- return 0;
- }
+ switch ($field[1]) {
+ case 'D': // Date: Numbers and a character to separate month, day, and year (stored internally as 8 digits in YYYYMMDD format)
+ return 8;
+ case 'T': // DateTime (YYYYMMDDhhmmss.uuu) (FoxPro)
+ return 18;
+ case 'M': // Memo (ignored): All ASCII characters (stored internally as 10 digits representing a .dbt block number, right justified, padded with whitespaces)
+ case 'N': // Number: -.0123456789 (right justified, padded with whitespaces)
+ case 'F': // Float: -.0123456789 (right justified, padded with whitespaces)
+ case 'C': // String: All ASCII characters (padded with whitespaces up to the field's length)
+ return $field[2];
+ case 'L': // Boolean: YyNnTtFf? (? when not initialized)
+ return 1;
+ }
+ return 0;
+ }
- /*
- * Functions for reading and writing bytes
- */
+ /*
+ * Functions for reading and writing bytes
+ */
- private static function getChar8($fd)
+ /**
+ * getChar8
+ * @param mixed $fd file descriptor
+ * @return int
+ */
+ private static function getChar8($fd)
{
- return ord(fread($fd, 1));
- }
+ return ord(fread($fd, 1));
+ }
- private static function putChar8($fd, $value)
+ /**
+ * putChar8
+ * @param mixed $fd file descriptor
+ * @param mixed $value value
+ * @return bool
+ */
+ private static function putChar8($fd, $value)
{
- return fwrite($fd, chr($value));
- }
+ return fwrite($fd, chr($value));
+ }
- private static function getInt16($fd, $n = 1)
+ /**
+ * getInt16
+ * @param mixed $fd file descriptor
+ * @param int $n n
+ * @return bool
+ */
+ private static function getInt16($fd, $n = 1)
{
- $data = fread($fd, 2 * $n);
- $i = unpack("S$n", $data);
- if ($n == 1)
- return (int) $i[1];
- else return array_merge($i);
- }
+ $data = fread($fd, 2 * $n);
+ $i = unpack("S$n", $data);
+ if ($n == 1) {
+ return (int) $i[1];
+ } else {
+ return array_merge($i);
+ }
+ }
- private static function putInt16($fd, $value)
+ /**
+ * putInt16
+ * @param mixed $fd file descriptor
+ * @param mixed $value value
+ * @return bool
+ */
+ private static function putInt16($fd, $value)
{
- return fwrite($fd, pack('S', $value));
- }
+ return fwrite($fd, pack('S', $value));
+ }
- private static function getInt32($fd, $n = 1)
+ /**
+ * getInt32
+ * @param mixed $fd file descriptor
+ * @param int $n n
+ * @return bool
+ */
+ private static function getInt32($fd, $n = 1)
{
- $data = fread($fd, 4 * $n);
- $i = unpack("L$n", $data);
- if ($n == 1)
- return (int) $i[1];
- else return array_merge($i);
- }
+ $data = fread($fd, 4 * $n);
+ $i = unpack("L$n", $data);
+ if ($n == 1) {
+ return (int) $i[1];
+ } else {
+ return array_merge($i);
+ }
+ }
- private static function putInt32($fd, $value)
+ /**
+ * putint32
+ * @param mixed $fd file descriptor
+ * @param mixed $value value
+ * @return bool
+ */
+ private static function putInt32($fd, $value)
{
- return fwrite($fd, pack('L', $value));
- }
+ return fwrite($fd, pack('L', $value));
+ }
- private static function putString($fd, $value, $length = 254)
+ /**
+ * putString
+ * @param mixed $fd file descriptor
+ * @param mixed $value value
+ * @param int $length length
+ * @return bool
+ */
+ private static function putString($fd, $value, $length = 254)
{
- $ret = fwrite($fd, pack('A' . $length, $value));
- }
+ $ret = fwrite($fd, pack('A' . $length, $value));
+ }
- private function putRecord($record)
+ /**
+ * putRecord
+ * @param mixed $record record
+ * @return bool
+ */
+ private function putRecord($record)
{
- foreach ($this->fields as $i => &$field) {
- $value = $record[$i];
- // Number types are right aligned with spaces
- if ($field['type'] == 'N' || $field['type'] == 'F' && strlen($value) < $field['length']) {
- $value = str_repeat(' ', $field['length'] - strlen($value)) . $value;
- }
- self::putString($this->fd, $value, $field['length']);
- }
- return true;
- }
+ foreach ($this->fields as $i => &$field) {
+ $value = $record[$i];
+ // Number types are right aligned with spaces
+ if ($field['type'] == 'N' || $field['type'] == 'F' && strlen($value) < $field['length']) {
+ $value = str_repeat(' ', $field['length'] - strlen($value)) . $value;
+ }
+ self::putString($this->fd, $value, $field['length']);
+ }
+ return true;
+ }
}
if (!function_exists('dbase_open')) {
-
- function dbase_open($filename, $mode)
+ /**
+ * dbase_open
+ * @param string $filename filename
+ * @param int $mode mode
+ * @return DBase
+ */
+ function dbase_open($filename, $mode)
{
- return DBase::open($filename, $mode);
- }
+ return DBase::open($filename, $mode);
+ }
- function dbase_create($filename, $fields, $type = DBASE_TYPE_DBASE)
+ /**
+ * dbase_create
+ * @param string $filename filename
+ * @param array $fields fields
+ * @param int $type type
+ * @return DBase
+ */
+ function dbase_create($filename, $fields, $type = DBASE_TYPE_DBASE)
{
- return DBase::create($filename, $fields, $type);
- }
+ return DBase::create($filename, $fields, $type);
+ }
- function dbase_close($dbase_identifier)
+ /**
+ * dbase_close
+ * @param Resource $dbase_identifier dbase identifier
+ * @return bool
+ */
+ function dbase_close($dbase_identifier)
{
- return $dbase_identifier->close();
- }
+ return $dbase_identifier->close();
+ }
- function dbase_get_header_info($dbase_identifier)
+ /**
+ * dbase_get_header_info
+ * @param Resource $dbase_identifier dbase identifier
+ * @return string
+ */
+ function dbase_get_header_info($dbase_identifier)
{
- return $dbase_identifier->get_header_info();
- }
+ return $dbase_identifier->get_header_info();
+ }
- function dbase_numfields($dbase_identifier)
+ /**
+ * dbase_numfields
+ * @param Resource $dbase_identifier dbase identifier
+ * @return int
+ */
+ function dbase_numfields($dbase_identifier)
{
- $dbase_identifier->numfields();
- }
+ $dbase_identifier->numfields();
+ }
- function dbase_numrecords($dbase_identifier)
+ /**
+ * dbase_numrecords
+ * @param Resource $dbase_identifier dbase identifier
+ * @return int
+ */
+ function dbase_numrecords($dbase_identifier)
{
- return $dbase_identifier->numrecords();
- }
+ return $dbase_identifier->numrecords();
+ }
- function dbase_add_record($dbase_identifier, $record)
+ /**
+ * dbase_add_record
+ * @param Resource $dbase_identifier dbase identifier
+ * @param array $record record
+ * @return bool
+ */
+ function dbase_add_record($dbase_identifier, $record)
{
- return $dbase_identifier->add_record($record);
- }
+ return $dbase_identifier->add_record($record);
+ }
- function dbase_delete_record($dbase_identifier, $record_number)
+ /**
+ * dbase_delete_record
+ * @param Resource $dbase_identifier dbase identifier
+ * @param int $record_number record number
+ * @return bool
+ */
+ function dbase_delete_record($dbase_identifier, $record_number)
{
- return $dbase_identifier->delete_record($record_number);
- }
+ return $dbase_identifier->delete_record($record_number);
+ }
- function dbase_replace_record($dbase_identifier, $record, $record_number)
+ /**
+ * dbase_replace_record
+ * @param Resource $dbase_identifier dbase identifier
+ * @param array $record record
+ * @param int $record_number record number
+ * @return bool
+ */
+ function dbase_replace_record($dbase_identifier, $record, $record_number)
{
- return $dbase_identifier->replace_record($record, $record_number);
- }
+ return $dbase_identifier->replace_record($record, $record_number);
+ }
- function dbase_get_record($dbase_identifier, $record_number)
+ /**
+ * dbase_get_record
+ * @param Resource $dbase_identifier dbase identifier
+ * @param int $record_number record number
+ * @return bool
+ */
+ function dbase_get_record($dbase_identifier, $record_number)
{
- return $dbase_identifier->get_record($record_number);
- }
+ return $dbase_identifier->get_record($record_number);
+ }
- function dbase_get_record_with_names($dbase_identifier, $record_number)
+ /**
+ * dbase_get_record_with_names
+ * @param Resource $dbase_identifier dbase identifier
+ * @param int $record_number record number
+ * @return bool
+ */
+ function dbase_get_record_with_names($dbase_identifier, $record_number)
{
- return $dbase_identifier->get_record_with_names($record_number);
- }
+ return $dbase_identifier->get_record_with_names($record_number);
+ }
- function dbase_pack($dbase_identifier)
+ /**
+ * dbase_pack
+ * @param Resource $dbase_identifier dbase identifier
+ * @return bool
+ */
+ function dbase_pack($dbase_identifier)
{
- return $dbase_identifier->pack();
- }
+ return $dbase_identifier->pack();
+ }
}
diff --git a/dev/initdata/generate-invoice.php b/dev/initdata/generate-invoice.php
index c35fe2440ef..4837e5352c7 100755
--- a/dev/initdata/generate-invoice.php
+++ b/dev/initdata/generate-invoice.php
@@ -48,60 +48,59 @@ require_once DOL_DOCUMENT_ROOT."/societe/class/societe.class.php";
define(GEN_NUMBER_FACTURE, 1);
$year = 2016;
$dates = array (mktime(12, 0, 0, 1, 3, $year),
- mktime(12, 0, 0, 1, 9, $year),
- mktime(12, 0, 0, 2, 13, $year),
- mktime(12, 0, 0, 2, 23, $year),
- mktime(12, 0, 0, 3, 30, $year),
- mktime(12, 0, 0, 4, 3, $year),
- mktime(12, 0, 0, 4, 3, $year),
- mktime(12, 0, 0, 5, 9, $year),
- mktime(12, 0, 0, 5, 1, $year),
- mktime(12, 0, 0, 5, 13, $year),
- mktime(12, 0, 0, 5, 19, $year),
- mktime(12, 0, 0, 5, 23, $year),
- mktime(12, 0, 0, 6, 3, $year),
- mktime(12, 0, 0, 6, 19, $year),
- mktime(12, 0, 0, 6, 24, $year),
- mktime(12, 0, 0, 7, 3, $year),
- mktime(12, 0, 0, 7, 9, $year),
- mktime(12, 0, 0, 7, 23, $year),
- mktime(12, 0, 0, 7, 30, $year),
- mktime(12, 0, 0, 8, 9, $year),
- mktime(12, 0, 0, 9, 23, $year),
- mktime(12, 0, 0, 10, 3, $year),
- mktime(12, 0, 0, 11, 12, $year),
- mktime(12, 0, 0, 11, 13, $year),
- mktime(12, 0, 0, 1, 3, ($year - 1)),
- mktime(12, 0, 0, 1, 9, ($year - 1)),
- mktime(12, 0, 0, 2, 13, ($year - 1)),
- mktime(12, 0, 0, 2, 23, ($year - 1)),
- mktime(12, 0, 0, 3, 30, ($year - 1)),
- mktime(12, 0, 0, 4, 3, ($year - 1)),
- mktime(12, 0, 0, 4, 3, ($year - 1)),
- mktime(12, 0, 0, 5, 9, ($year - 1)),
- mktime(12, 0, 0, 5, 1, ($year - 1)),
- mktime(12, 0, 0, 5, 13, ($year - 1)),
- mktime(12, 0, 0, 5, 19, ($year - 1)),
- mktime(12, 0, 0, 5, 23, ($year - 1)),
- mktime(12, 0, 0, 6, 3, ($year - 1)),
- mktime(12, 0, 0, 6, 19, ($year - 1)),
- mktime(12, 0, 0, 6, 24, ($year - 1)),
- mktime(12, 0, 0, 7, 3, ($year - 1)),
- mktime(12, 0, 0, 7, 9, ($year - 1)),
- mktime(12, 0, 0, 7, 23, ($year - 1)),
- mktime(12, 0, 0, 7, 30, ($year - 1)),
- mktime(12, 0, 0, 8, 9, ($year - 1)),
- mktime(12, 0, 0, 9, 23, ($year - 1)),
- mktime(12, 0, 0, 10, 3, ($year - 1)),
- mktime(12, 0, 0, 11, 12, $year),
- mktime(12, 0, 0, 11, 13, $year),
- mktime(12, 0, 0, 12, 12, $year),
- mktime(12, 0, 0, 12, 13, $year),
+ mktime(12, 0, 0, 1, 9, $year),
+ mktime(12, 0, 0, 2, 13, $year),
+ mktime(12, 0, 0, 2, 23, $year),
+ mktime(12, 0, 0, 3, 30, $year),
+ mktime(12, 0, 0, 4, 3, $year),
+ mktime(12, 0, 0, 4, 3, $year),
+ mktime(12, 0, 0, 5, 9, $year),
+ mktime(12, 0, 0, 5, 1, $year),
+ mktime(12, 0, 0, 5, 13, $year),
+ mktime(12, 0, 0, 5, 19, $year),
+ mktime(12, 0, 0, 5, 23, $year),
+ mktime(12, 0, 0, 6, 3, $year),
+ mktime(12, 0, 0, 6, 19, $year),
+ mktime(12, 0, 0, 6, 24, $year),
+ mktime(12, 0, 0, 7, 3, $year),
+ mktime(12, 0, 0, 7, 9, $year),
+ mktime(12, 0, 0, 7, 23, $year),
+ mktime(12, 0, 0, 7, 30, $year),
+ mktime(12, 0, 0, 8, 9, $year),
+ mktime(12, 0, 0, 9, 23, $year),
+ mktime(12, 0, 0, 10, 3, $year),
+ mktime(12, 0, 0, 11, 12, $year),
+ mktime(12, 0, 0, 11, 13, $year),
+ mktime(12, 0, 0, 1, 3, ($year - 1)),
+ mktime(12, 0, 0, 1, 9, ($year - 1)),
+ mktime(12, 0, 0, 2, 13, ($year - 1)),
+ mktime(12, 0, 0, 2, 23, ($year - 1)),
+ mktime(12, 0, 0, 3, 30, ($year - 1)),
+ mktime(12, 0, 0, 4, 3, ($year - 1)),
+ mktime(12, 0, 0, 4, 3, ($year - 1)),
+ mktime(12, 0, 0, 5, 9, ($year - 1)),
+ mktime(12, 0, 0, 5, 1, ($year - 1)),
+ mktime(12, 0, 0, 5, 13, ($year - 1)),
+ mktime(12, 0, 0, 5, 19, ($year - 1)),
+ mktime(12, 0, 0, 5, 23, ($year - 1)),
+ mktime(12, 0, 0, 6, 3, ($year - 1)),
+ mktime(12, 0, 0, 6, 19, ($year - 1)),
+ mktime(12, 0, 0, 6, 24, ($year - 1)),
+ mktime(12, 0, 0, 7, 3, ($year - 1)),
+ mktime(12, 0, 0, 7, 9, ($year - 1)),
+ mktime(12, 0, 0, 7, 23, ($year - 1)),
+ mktime(12, 0, 0, 7, 30, ($year - 1)),
+ mktime(12, 0, 0, 8, 9, ($year - 1)),
+ mktime(12, 0, 0, 9, 23, ($year - 1)),
+ mktime(12, 0, 0, 10, 3, ($year - 1)),
+ mktime(12, 0, 0, 11, 12, $year),
+ mktime(12, 0, 0, 11, 13, $year),
+ mktime(12, 0, 0, 12, 12, $year),
+ mktime(12, 0, 0, 12, 13, $year),
);
$ret=$user->fetch('', 'admin');
-if (! $ret > 0)
-{
+if (! $ret > 0) {
print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
exit;
}
@@ -111,12 +110,10 @@ $user->getrights();
$socids = array();
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe WHERE client in (1, 3)";
$resql = $db->query($sql);
-if ($resql)
-{
+if ($resql) {
$num_thirdparties = $db->num_rows($resql);
$i = 0;
- while ($i < $num_thirdparties)
- {
+ while ($i < $num_thirdparties) {
$i++;
$row = $db->fetch_row($resql);
$socids[$i] = $row[0];
@@ -126,12 +123,10 @@ if ($resql)
$prodids = array();
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product WHERE tosell=1";
$resql = $db->query($sql);
-if ($resql)
-{
+if ($resql) {
$num_prods = $db->num_rows($resql);
$i = 0;
- while ($i < $num_prods)
- {
+ while ($i < $num_prods) {
$i++;
$row = $db->fetch_row($resql);
$prodids[$i] = $row[0];
@@ -140,8 +135,7 @@ if ($resql)
$i=0;
$result=0;
-while ($i < GEN_NUMBER_FACTURE && $result >= 0)
-{
+while ($i < GEN_NUMBER_FACTURE && $result >= 0) {
$i++;
$socid = mt_rand(1, $num_thirdparties);
@@ -153,31 +147,27 @@ while ($i < GEN_NUMBER_FACTURE && $result >= 0)
$object->cond_reglement_id = 3;
$object->mode_reglement_id = 3;
- $fuser = new User($db);
- $fuser->fetch(mt_rand(1, 2));
- $fuser->getRights();
+ $fuser = new User($db);
+ $fuser->fetch(mt_rand(1, 2));
+ $fuser->getRights();
$result=$object->create($fuser);
- if ($result >= 0)
- {
+ if ($result >= 0) {
$nbp = mt_rand(2, 5);
$xnbp = 0;
- while ($xnbp < $nbp)
- {
+ while ($xnbp < $nbp) {
$prodid = mt_rand(1, $num_prods);
$product=new Product($db);
$result=$product->fetch($prodids[$prodid]);
$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);
- if ($result < 0)
- {
- dol_print_error($db, $propal->error);
- }
- $xnbp++;
+ if ($result < 0) {
+ dol_print_error($db, $propal->error);
+ }
+ $xnbp++;
}
- $result=$object->validate($fuser);
- if ($result)
- {
+ $result=$object->validate($fuser);
+ if ($result) {
print " OK with ref ".$object->ref."\n";;
} else {
dol_print_error($db, $object->error);
diff --git a/dev/initdata/generate-order.php b/dev/initdata/generate-order.php
index c421e39ffe3..2c939f8e1d2 100755
--- a/dev/initdata/generate-order.php
+++ b/dev/initdata/generate-order.php
@@ -31,8 +31,8 @@ $path=dirname(__FILE__).'/';
// Test si mode batch
$sapi_type = php_sapi_name();
if (substr($sapi_type, 0, 3) == 'cgi') {
- echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
- exit;
+ echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
+ exit;
}
// Recupere root dolibarr
@@ -54,62 +54,61 @@ require_once DOL_DOCUMENT_ROOT."/commande/class/commande.class.php";
define(GEN_NUMBER_COMMANDE, 10);
$year = 2016;
$dates = array (mktime(12, 0, 0, 1, 3, $year),
- mktime(12, 0, 0, 1, 9, $year),
- mktime(12, 0, 0, 2, 13, $year),
- mktime(12, 0, 0, 2, 23, $year),
- mktime(12, 0, 0, 3, 30, $year),
- mktime(12, 0, 0, 4, 3, $year),
- mktime(12, 0, 0, 4, 3, $year),
- mktime(12, 0, 0, 5, 9, $year),
- mktime(12, 0, 0, 5, 1, $year),
- mktime(12, 0, 0, 5, 13, $year),
- mktime(12, 0, 0, 5, 19, $year),
- mktime(12, 0, 0, 5, 23, $year),
- mktime(12, 0, 0, 6, 3, $year),
- mktime(12, 0, 0, 6, 19, $year),
- mktime(12, 0, 0, 6, 24, $year),
- mktime(12, 0, 0, 7, 3, $year),
- mktime(12, 0, 0, 7, 9, $year),
- mktime(12, 0, 0, 7, 23, $year),
- mktime(12, 0, 0, 7, 30, $year),
- mktime(12, 0, 0, 8, 9, $year),
- mktime(12, 0, 0, 9, 23, $year),
- mktime(12, 0, 0, 10, 3, $year),
- mktime(12, 0, 0, 11, 12, $year),
- mktime(12, 0, 0, 11, 13, $year),
- mktime(12, 0, 0, 1, 3, ($year - 1)),
- mktime(12, 0, 0, 1, 9, ($year - 1)),
- mktime(12, 0, 0, 2, 13, ($year - 1)),
- mktime(12, 0, 0, 2, 23, ($year - 1)),
- mktime(12, 0, 0, 3, 30, ($year - 1)),
- mktime(12, 0, 0, 4, 3, ($year - 1)),
- mktime(12, 0, 0, 4, 3, ($year - 1)),
- mktime(12, 0, 0, 5, 9, ($year - 1)),
- mktime(12, 0, 0, 5, 1, ($year - 1)),
- mktime(12, 0, 0, 5, 13, ($year - 1)),
- mktime(12, 0, 0, 5, 19, ($year - 1)),
- mktime(12, 0, 0, 5, 23, ($year - 1)),
- mktime(12, 0, 0, 6, 3, ($year - 1)),
- mktime(12, 0, 0, 6, 19, ($year - 1)),
- mktime(12, 0, 0, 6, 24, ($year - 1)),
- mktime(12, 0, 0, 7, 3, ($year - 1)),
- mktime(12, 0, 0, 7, 9, ($year - 1)),
- mktime(12, 0, 0, 7, 23, ($year - 1)),
- mktime(12, 0, 0, 7, 30, ($year - 1)),
- mktime(12, 0, 0, 8, 9, ($year - 1)),
- mktime(12, 0, 0, 9, 23, ($year - 1)),
- mktime(12, 0, 0, 10, 3, ($year - 1)),
- mktime(12, 0, 0, 11, 12, $year),
- mktime(12, 0, 0, 11, 13, $year),
- mktime(12, 0, 0, 12, 12, $year),
- mktime(12, 0, 0, 12, 13, $year),
+ mktime(12, 0, 0, 1, 9, $year),
+ mktime(12, 0, 0, 2, 13, $year),
+ mktime(12, 0, 0, 2, 23, $year),
+ mktime(12, 0, 0, 3, 30, $year),
+ mktime(12, 0, 0, 4, 3, $year),
+ mktime(12, 0, 0, 4, 3, $year),
+ mktime(12, 0, 0, 5, 9, $year),
+ mktime(12, 0, 0, 5, 1, $year),
+ mktime(12, 0, 0, 5, 13, $year),
+ mktime(12, 0, 0, 5, 19, $year),
+ mktime(12, 0, 0, 5, 23, $year),
+ mktime(12, 0, 0, 6, 3, $year),
+ mktime(12, 0, 0, 6, 19, $year),
+ mktime(12, 0, 0, 6, 24, $year),
+ mktime(12, 0, 0, 7, 3, $year),
+ mktime(12, 0, 0, 7, 9, $year),
+ mktime(12, 0, 0, 7, 23, $year),
+ mktime(12, 0, 0, 7, 30, $year),
+ mktime(12, 0, 0, 8, 9, $year),
+ mktime(12, 0, 0, 9, 23, $year),
+ mktime(12, 0, 0, 10, 3, $year),
+ mktime(12, 0, 0, 11, 12, $year),
+ mktime(12, 0, 0, 11, 13, $year),
+ mktime(12, 0, 0, 1, 3, ($year - 1)),
+ mktime(12, 0, 0, 1, 9, ($year - 1)),
+ mktime(12, 0, 0, 2, 13, ($year - 1)),
+ mktime(12, 0, 0, 2, 23, ($year - 1)),
+ mktime(12, 0, 0, 3, 30, ($year - 1)),
+ mktime(12, 0, 0, 4, 3, ($year - 1)),
+ mktime(12, 0, 0, 4, 3, ($year - 1)),
+ mktime(12, 0, 0, 5, 9, ($year - 1)),
+ mktime(12, 0, 0, 5, 1, ($year - 1)),
+ mktime(12, 0, 0, 5, 13, ($year - 1)),
+ mktime(12, 0, 0, 5, 19, ($year - 1)),
+ mktime(12, 0, 0, 5, 23, ($year - 1)),
+ mktime(12, 0, 0, 6, 3, ($year - 1)),
+ mktime(12, 0, 0, 6, 19, ($year - 1)),
+ mktime(12, 0, 0, 6, 24, ($year - 1)),
+ mktime(12, 0, 0, 7, 3, ($year - 1)),
+ mktime(12, 0, 0, 7, 9, ($year - 1)),
+ mktime(12, 0, 0, 7, 23, ($year - 1)),
+ mktime(12, 0, 0, 7, 30, ($year - 1)),
+ mktime(12, 0, 0, 8, 9, ($year - 1)),
+ mktime(12, 0, 0, 9, 23, ($year - 1)),
+ mktime(12, 0, 0, 10, 3, ($year - 1)),
+ mktime(12, 0, 0, 11, 12, $year),
+ mktime(12, 0, 0, 11, 13, $year),
+ mktime(12, 0, 0, 12, 12, $year),
+ mktime(12, 0, 0, 12, 13, $year),
);
$ret=$user->fetch('', 'admin');
-if ($ret <= 0)
-{
- print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
- exit;
+if ($ret <= 0) {
+ print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
+ exit;
}
$user->getrights();
@@ -117,101 +116,100 @@ $societesid = array();
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe where client in (1, 3)";
$resql=$db->query($sql);
if ($resql) {
- $num_thirdparties = $db->num_rows($resql);
- $i = 0;
- while ($i < $num_thirdparties) {
- $i++;
- $row = $db->fetch_row($resql);
- $societesid[$i] = $row[0];
- }
-} else { print "err"; }
+ $num_thirdparties = $db->num_rows($resql);
+ $i = 0;
+ while ($i < $num_thirdparties) {
+ $i++;
+ $row = $db->fetch_row($resql);
+ $societesid[$i] = $row[0];
+ }
+} else {
+ print "err";
+}
$commandesid = array();
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."commande";
$resql=$db->query($sql);
if ($resql) {
- $num = $db->num_rows($resql);
- $i = 0;
- while ($i < $num) {
- $i++;
- $row = $db->fetch_row($resql);
- $commandesid[$i] = $row[0];
- }
-} else { print "err"; }
+ $num = $db->num_rows($resql);
+ $i = 0;
+ while ($i < $num) {
+ $i++;
+ $row = $db->fetch_row($resql);
+ $commandesid[$i] = $row[0];
+ }
+} else {
+ print "err";
+}
$prodids = array();
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product WHERE tosell=1";
$resql = $db->query($sql);
if ($resql) {
- $num_prods = $db->num_rows($resql);
- $i = 0;
- while ($i < $num_prods) {
- $i++;
+ $num_prods = $db->num_rows($resql);
+ $i = 0;
+ while ($i < $num_prods) {
+ $i++;
- $row = $db->fetch_row($resql);
- $prodids[$i] = $row[0];
- }
+ $row = $db->fetch_row($resql);
+ $prodids[$i] = $row[0];
+ }
}
print "Build ".GEN_NUMBER_COMMANDE." orders\n";
-for ($s = 0 ; $s < GEN_NUMBER_COMMANDE ; $s++)
-{
- print "Process order ".$s."\n";
+for ($s = 0; $s < GEN_NUMBER_COMMANDE; $s++) {
+ print "Process order ".$s."\n";
- $object = new Commande($db);
+ $object = new Commande($db);
- $object->socid = $societesid[mt_rand(1, $num_thirdparties)];
- $object->date_commande = $dates[mt_rand(1, count($dates)-1)];
- $object->note = 'My small comment about this order. Hum. Nothing.';
- $object->source = 1;
- $object->fk_project = 0;
- $object->remise_percent = 0;
- $object->shipping_method_id = mt_rand(1, 2);
- $object->cond_reglement_id = mt_rand(0, 2);
- $object->more_reglement_id = mt_rand(0, 7);
- $object->availability_id = mt_rand(0, 1);
+ $object->socid = $societesid[mt_rand(1, $num_thirdparties)];
+ $object->date_commande = $dates[mt_rand(1, count($dates)-1)];
+ $object->note = 'My small comment about this order. Hum. Nothing.';
+ $object->source = 1;
+ $object->fk_project = 0;
+ $object->remise_percent = 0;
+ $object->shipping_method_id = mt_rand(1, 2);
+ $object->cond_reglement_id = mt_rand(0, 2);
+ $object->more_reglement_id = mt_rand(0, 7);
+ $object->availability_id = mt_rand(0, 1);
- $listofuserid=array(12,13,16);
+ $listofuserid=array(12,13,16);
- $fuser = new User($db);
- $fuser->fetch($listofuserid[mt_rand(0, 2)]);
- $fuser->getRights();
+ $fuser = new User($db);
+ $fuser->fetch($listofuserid[mt_rand(0, 2)]);
+ $fuser->getRights();
- $db->begin();
+ $db->begin();
- $result=$object->create($fuser);
- if ($result >= 0)
- {
- $nbp = mt_rand(2, 5);
- $xnbp = 0;
- while ($xnbp < $nbp)
- {
- $prodid = mt_rand(1, $num_prods);
- $product=new Product($db);
- $result=$product->fetch($prodids[$prodid]);
- $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);
- if ($result <= 0)
- {
- dol_print_error($db, $object->error);
- }
- $xnbp++;
- }
+ $result=$object->create($fuser);
+ if ($result >= 0) {
+ $nbp = mt_rand(2, 5);
+ $xnbp = 0;
+ while ($xnbp < $nbp) {
+ $prodid = mt_rand(1, $num_prods);
+ $product=new Product($db);
+ $result=$product->fetch($prodids[$prodid]);
+ $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);
+ if ($result <= 0) {
+ dol_print_error($db, $object->error);
+ }
+ $xnbp++;
+ }
- $result=$object->valid($fuser);
- if ($result > 0)
- {
- $db->commit();
- print " OK with ref ".$object->ref."\n";
- } else {
- print " KO\n";
- $db->rollback();
- dol_print_error($db, $object->error);
- }
- } else {
- print " KO\n";
- $db->rollback();
- dol_print_error($db, $object->error);
- }
+ $result=$object->valid($fuser);
+ if ($result > 0) {
+ $db->commit();
+ print " OK with ref ".$object->ref."\n";
+ } else {
+ print " KO\n";
+ $db->rollback();
+ dol_print_error($db, $object->error);
+ }
+ } else {
+ print " KO\n";
+ $db->rollback();
+ dol_print_error($db, $object->error);
+ }
}
diff --git a/dev/initdata/generate-product.php b/dev/initdata/generate-product.php
index a82c0262360..97b02fa3ac9 100755
--- a/dev/initdata/generate-product.php
+++ b/dev/initdata/generate-product.php
@@ -31,8 +31,8 @@ $path=dirname(__FILE__).'/';
// Test si mode batch
$sapi_type = php_sapi_name();
if (substr($sapi_type, 0, 3) == 'cgi') {
- echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
- exit;
+ echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
+ exit;
}
// Recupere root dolibarr
@@ -54,8 +54,7 @@ define(GEN_NUMBER_PRODUIT, 100000);
$ret=$user->fetch('', 'admin');
-if (! $ret > 0)
-{
+if (! $ret > 0) {
print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
exit;
}
@@ -65,38 +64,50 @@ $user->getrights();
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product"; $productsid = array();
$resql=$db->query($sql);
if ($resql) {
- $num = $db->num_rows($resql); $i = 0;
- while ($i < $num) { $row = $db->fetch_row($resql); $productsid[$i] = $row[0]; $i++; }
+ $num = $db->num_rows($resql); $i = 0;
+ while ($i < $num) {
+ $row = $db->fetch_row($resql); $productsid[$i] = $row[0]; $i++;
+ }
}
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe"; $societesid = array();
$resql=$db->query($sql);
if ($resql) {
$num = $db->num_rows($resql); $i = 0;
- while ($i < $num) { $row = $db->fetch_row($resql); $societesid[$i] = $row[0]; $i++; }
-} else { print "err"; }
+ while ($i < $num) {
+ $row = $db->fetch_row($resql); $societesid[$i] = $row[0]; $i++;
+ }
+} else {
+ print "err";
+}
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."commande"; $commandesid = array();
$resql=$db->query($sql);
if ($resql) {
$num = $db->num_rows($resql); $i = 0;
- while ($i < $num) { $row = $db->fetch_row($resql); $commandesid[$i] = $row[0]; $i++; }
-} else { print "err"; }
+ while ($i < $num) {
+ $row = $db->fetch_row($resql); $commandesid[$i] = $row[0]; $i++;
+ }
+} else {
+ print "err";
+}
print "Generates ".GEN_NUMBER_PRODUIT." products\n";
-for ($s = 0 ; $s < GEN_NUMBER_PRODUIT ; $s++)
-{
- print "Product ".$s;
- $produit = new Product($db);
- $produit->type = mt_rand(0, 1);
- $produit->status = 1;
- $produit->ref = ($produit->type?'S':'P').time().$s;
- $produit->label = 'Label '.time().$s;
- $produit->description = 'Description '.time().$s;
- $produit->price = mt_rand(1, 1000);
- $produit->tva_tx = "19.6";
- $ret=$produit->create($user);
- if ($ret < 0) print "Error $ret - ".$produit->error."\n";
- else print " OK with ref ".$produit->ref."\n";
+for ($s = 0; $s < GEN_NUMBER_PRODUIT; $s++) {
+ print "Product ".$s;
+ $produit = new Product($db);
+ $produit->type = mt_rand(0, 1);
+ $produit->status = 1;
+ $produit->ref = ($produit->type?'S':'P').time().$s;
+ $produit->label = 'Label '.time().$s;
+ $produit->description = 'Description '.time().$s;
+ $produit->price = mt_rand(1, 1000);
+ $produit->tva_tx = "19.6";
+ $ret=$produit->create($user);
+ if ($ret < 0) {
+ print "Error $ret - ".$produit->error."\n";
+ } else {
+ print " OK with ref ".$produit->ref."\n";
+ }
}
diff --git a/dev/initdata/generate-proposal.php b/dev/initdata/generate-proposal.php
index 42c0c4098f2..0b1c24dc139 100755
--- a/dev/initdata/generate-proposal.php
+++ b/dev/initdata/generate-proposal.php
@@ -50,60 +50,59 @@ require_once DOL_DOCUMENT_ROOT."/societe/class/societe.class.php";
define(GEN_NUMBER_PROPAL, 10);
$year = 2016;
$dates = array (mktime(12, 0, 0, 1, 3, $year),
- mktime(12, 0, 0, 1, 9, $year),
- mktime(12, 0, 0, 2, 13, $year),
- mktime(12, 0, 0, 2, 23, $year),
- mktime(12, 0, 0, 3, 30, $year),
- mktime(12, 0, 0, 4, 3, $year),
- mktime(12, 0, 0, 4, 3, $year),
- mktime(12, 0, 0, 5, 9, $year),
- mktime(12, 0, 0, 5, 1, $year),
- mktime(12, 0, 0, 5, 13, $year),
- mktime(12, 0, 0, 5, 19, $year),
- mktime(12, 0, 0, 5, 23, $year),
- mktime(12, 0, 0, 6, 3, $year),
- mktime(12, 0, 0, 6, 19, $year),
- mktime(12, 0, 0, 6, 24, $year),
- mktime(12, 0, 0, 7, 3, $year),
- mktime(12, 0, 0, 7, 9, $year),
- mktime(12, 0, 0, 7, 23, $year),
- mktime(12, 0, 0, 7, 30, $year),
- mktime(12, 0, 0, 8, 9, $year),
- mktime(12, 0, 0, 9, 23, $year),
- mktime(12, 0, 0, 10, 3, $year),
- mktime(12, 0, 0, 11, 12, $year),
- mktime(12, 0, 0, 11, 13, $year),
- mktime(12, 0, 0, 1, 3, ($year - 1)),
- mktime(12, 0, 0, 1, 9, ($year - 1)),
- mktime(12, 0, 0, 2, 13, ($year - 1)),
- mktime(12, 0, 0, 2, 23, ($year - 1)),
- mktime(12, 0, 0, 3, 30, ($year - 1)),
- mktime(12, 0, 0, 4, 3, ($year - 1)),
- mktime(12, 0, 0, 4, 3, ($year - 1)),
- mktime(12, 0, 0, 5, 9, ($year - 1)),
- mktime(12, 0, 0, 5, 1, ($year - 1)),
- mktime(12, 0, 0, 5, 13, ($year - 1)),
- mktime(12, 0, 0, 5, 19, ($year - 1)),
- mktime(12, 0, 0, 5, 23, ($year - 1)),
- mktime(12, 0, 0, 6, 3, ($year - 1)),
- mktime(12, 0, 0, 6, 19, ($year - 1)),
- mktime(12, 0, 0, 6, 24, ($year - 1)),
- mktime(12, 0, 0, 7, 3, ($year - 1)),
- mktime(12, 0, 0, 7, 9, ($year - 1)),
- mktime(12, 0, 0, 7, 23, ($year - 1)),
- mktime(12, 0, 0, 7, 30, ($year - 1)),
- mktime(12, 0, 0, 8, 9, ($year - 1)),
- mktime(12, 0, 0, 9, 23, ($year - 1)),
- mktime(12, 0, 0, 10, 3, ($year - 1)),
- mktime(12, 0, 0, 11, 12, $year),
- mktime(12, 0, 0, 11, 13, $year),
- mktime(12, 0, 0, 12, 12, $year),
- mktime(12, 0, 0, 12, 13, $year),
+ mktime(12, 0, 0, 1, 9, $year),
+ mktime(12, 0, 0, 2, 13, $year),
+ mktime(12, 0, 0, 2, 23, $year),
+ mktime(12, 0, 0, 3, 30, $year),
+ mktime(12, 0, 0, 4, 3, $year),
+ mktime(12, 0, 0, 4, 3, $year),
+ mktime(12, 0, 0, 5, 9, $year),
+ mktime(12, 0, 0, 5, 1, $year),
+ mktime(12, 0, 0, 5, 13, $year),
+ mktime(12, 0, 0, 5, 19, $year),
+ mktime(12, 0, 0, 5, 23, $year),
+ mktime(12, 0, 0, 6, 3, $year),
+ mktime(12, 0, 0, 6, 19, $year),
+ mktime(12, 0, 0, 6, 24, $year),
+ mktime(12, 0, 0, 7, 3, $year),
+ mktime(12, 0, 0, 7, 9, $year),
+ mktime(12, 0, 0, 7, 23, $year),
+ mktime(12, 0, 0, 7, 30, $year),
+ mktime(12, 0, 0, 8, 9, $year),
+ mktime(12, 0, 0, 9, 23, $year),
+ mktime(12, 0, 0, 10, 3, $year),
+ mktime(12, 0, 0, 11, 12, $year),
+ mktime(12, 0, 0, 11, 13, $year),
+ mktime(12, 0, 0, 1, 3, ($year - 1)),
+ mktime(12, 0, 0, 1, 9, ($year - 1)),
+ mktime(12, 0, 0, 2, 13, ($year - 1)),
+ mktime(12, 0, 0, 2, 23, ($year - 1)),
+ mktime(12, 0, 0, 3, 30, ($year - 1)),
+ mktime(12, 0, 0, 4, 3, ($year - 1)),
+ mktime(12, 0, 0, 4, 3, ($year - 1)),
+ mktime(12, 0, 0, 5, 9, ($year - 1)),
+ mktime(12, 0, 0, 5, 1, ($year - 1)),
+ mktime(12, 0, 0, 5, 13, ($year - 1)),
+ mktime(12, 0, 0, 5, 19, ($year - 1)),
+ mktime(12, 0, 0, 5, 23, ($year - 1)),
+ mktime(12, 0, 0, 6, 3, ($year - 1)),
+ mktime(12, 0, 0, 6, 19, ($year - 1)),
+ mktime(12, 0, 0, 6, 24, ($year - 1)),
+ mktime(12, 0, 0, 7, 3, ($year - 1)),
+ mktime(12, 0, 0, 7, 9, ($year - 1)),
+ mktime(12, 0, 0, 7, 23, ($year - 1)),
+ mktime(12, 0, 0, 7, 30, ($year - 1)),
+ mktime(12, 0, 0, 8, 9, ($year - 1)),
+ mktime(12, 0, 0, 9, 23, ($year - 1)),
+ mktime(12, 0, 0, 10, 3, ($year - 1)),
+ mktime(12, 0, 0, 11, 12, $year),
+ mktime(12, 0, 0, 11, 13, $year),
+ mktime(12, 0, 0, 12, 12, $year),
+ mktime(12, 0, 0, 12, 13, $year),
);
$ret=$user->fetch('', 'admin');
-if (! $ret > 0)
-{
+if (! $ret > 0) {
print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
exit;
}
@@ -113,12 +112,10 @@ $user->getrights();
$socids = array();
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe WHERE client in (1,3)";
$resql = $db->query($sql);
-if ($resql)
-{
+if ($resql) {
$num_thirdparties = $db->num_rows($resql);
$i = 0;
- while ($i < $num_thirdparties)
- {
+ while ($i < $num_thirdparties) {
$i++;
$row = $db->fetch_row($resql);
$socids[$i] = $row[0];
@@ -128,12 +125,10 @@ if ($resql)
$contids = array();
$sql = "SELECT rowid, fk_soc FROM ".MAIN_DB_PREFIX."socpeople";
$resql = $db->query($sql);
-if ($resql)
-{
+if ($resql) {
$num_conts = $db->num_rows($resql);
$i = 0;
- while ($i < $num_conts)
- {
+ while ($i < $num_conts) {
$i++;
$row = $db->fetch_row($resql);
$contids[$row[1]][0] = $row[0]; // A ameliorer
@@ -143,12 +138,10 @@ if ($resql)
$prodids = array();
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product WHERE tosell=1";
$resql = $db->query($sql);
-if ($resql)
-{
+if ($resql) {
$num_prods = $db->num_rows($resql);
$i = 0;
- while ($i < $num_prods)
- {
+ while ($i < $num_prods) {
$i++;
$row = $db->fetch_row($resql);
$prodids[$i] = $row[0];
@@ -159,15 +152,13 @@ $user->rights->propal->creer=1;
$user->rights->propal->propal_advance->validate=1;
-if (! empty($conf->global->PROPALE_ADDON) && is_readable(DOL_DOCUMENT_ROOT ."/core/modules/propale/".$conf->global->PROPALE_ADDON.".php"))
-{
+if (! empty($conf->global->PROPALE_ADDON) && is_readable(DOL_DOCUMENT_ROOT ."/core/modules/propale/".$conf->global->PROPALE_ADDON.".php")) {
require_once DOL_DOCUMENT_ROOT ."/core/modules/propale/".$conf->global->PROPALE_ADDON.".php";
}
$i=0;
$result=0;
-while ($i < GEN_NUMBER_PROPAL && $result >= 0)
-{
+while ($i < GEN_NUMBER_PROPAL && $result >= 0) {
$i++;
$socid = mt_rand(1, $num_thirdparties);
print "Proposal ".$i." for socid ".$socid;
@@ -177,9 +168,9 @@ while ($i < GEN_NUMBER_PROPAL && $result >= 0)
$object = new Propal($db);
- $fuser = new User($db);
- $fuser->fetch(mt_rand(1, 2));
- $fuser->getRights();
+ $fuser = new User($db);
+ $fuser->fetch(mt_rand(1, 2));
+ $fuser->getRights();
$object->contactid = $contids[$socids[$socid]][0];
$object->socid = $socids[$socid];
@@ -188,32 +179,28 @@ while ($i < GEN_NUMBER_PROPAL && $result >= 0)
$object->mode_reglement_id = 3;
$result=$object->create($fuser);
- if ($result >= 0)
- {
+ if ($result >= 0) {
$nbp = mt_rand(2, 5);
$xnbp = 0;
- while ($xnbp < $nbp)
- {
+ while ($xnbp < $nbp) {
$prodid = mt_rand(1, $num_prods);
$product=new Product($db);
$result=$product->fetch($prodids[$prodid]);
$result=$object->addline($product->description, $product->price, mt_rand(1, 5), 0, 0, 0, $prodids[$prodid], 0);
- if ($result < 0)
- {
+ if ($result < 0) {
dol_print_error($db, $object->error);
}
$xnbp++;
}
$result=$object->valid($fuser);
- if ($result > 0)
- {
- $db->commit();
- print " OK with ref ".$object->ref."\n";
+ if ($result > 0) {
+ $db->commit();
+ print " OK with ref ".$object->ref."\n";
} else {
- print " KO\n";
- $db->rollback();
- dol_print_error($db, $object->error);
+ print " KO\n";
+ $db->rollback();
+ dol_print_error($db, $object->error);
}
} else {
dol_print_error($db, $object->error);
diff --git a/dev/initdata/generate-thirdparty.php b/dev/initdata/generate-thirdparty.php
index a13e2351e9c..f60f34ac168 100755
--- a/dev/initdata/generate-thirdparty.php
+++ b/dev/initdata/generate-thirdparty.php
@@ -31,8 +31,8 @@ $path=dirname(__FILE__).'/';
// Test si mode batch
$sapi_type = php_sapi_name();
if (substr($sapi_type, 0, 3) == 'cgi') {
- echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
- exit;
+ echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
+ exit;
}
// Recupere root dolibarr
@@ -57,8 +57,7 @@ define(GEN_NUMBER_SOCIETE, 10);
$ret=$user->fetch('', 'admin');
-if (! $ret > 0)
-{
+if (! $ret > 0) {
print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
exit;
}
@@ -68,8 +67,8 @@ $user->getrights();
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product"; $productsid = array();
$resql=$db->query($sql);
if ($resql) {
- $num = $db->num_rows($resql); $i = 0;
- while ($i < $num) {
+ $num = $db->num_rows($resql); $i = 0;
+ while ($i < $num) {
$row = $db->fetch_row($resql);
$productsid[$i] = $row[0];
$i++;
@@ -80,63 +79,65 @@ $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe"; $societesid = array();
$resql=$db->query($sql);
if ($resql) {
$num = $db->num_rows($resql); $i = 0;
- while ($i < $num) {
+ while ($i < $num) {
$row = $db->fetch_row($resql);
$societesid[$i] = $row[0];
$i++;
}
-} else { print "err"; }
+} else {
+ print "err";
+}
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."commande"; $commandesid = array();
$resql=$db->query($sql);
if ($resql) {
$num = $db->num_rows($resql); $i = 0;
- while ($i < $num) {
+ while ($i < $num) {
$row = $db->fetch_row($resql);
$commandesid[$i] = $row[0];
$i++;
}
-} else { print "err"; }
+} else {
+ print "err";
+}
print "Generates ".GEN_NUMBER_SOCIETE." companies\n";
-for ($s = 0 ; $s < GEN_NUMBER_SOCIETE ; $s++)
-{
- print "Company $s\n";
- $soc = new Societe($db);
- $soc->name = "Company num ".time()."$s";
- $soc->town = $listoftown[mt_rand(0, count($listoftown)-1)];
- $soc->client = mt_rand(1, 2); // Une societe sur 2 est prospect, l'autre client
- $soc->fournisseur = mt_rand(0, 1); // Une societe sur 2 est fournisseur
- $soc->code_client='CU'.time()."$s";
- $soc->code_fournisseur='SU'.time()."$s";
- $soc->tva_assuj=1;
- $soc->country_id=1;
- $soc->country_code='FR';
+for ($s = 0; $s < GEN_NUMBER_SOCIETE; $s++) {
+ print "Company $s\n";
+ $soc = new Societe($db);
+ $soc->name = "Company num ".time()."$s";
+ $soc->town = $listoftown[mt_rand(0, count($listoftown)-1)];
+ $soc->client = mt_rand(1, 2); // Une societe sur 2 est prospect, l'autre client
+ $soc->fournisseur = mt_rand(0, 1); // Une societe sur 2 est fournisseur
+ $soc->code_client='CU'.time()."$s";
+ $soc->code_fournisseur='SU'.time()."$s";
+ $soc->tva_assuj=1;
+ $soc->country_id=1;
+ $soc->country_code='FR';
// Un client sur 3 a une remise de 5%
- $user_remise=mt_rand(1, 3); if ($user_remise==3) $soc->remise_percent=5;
+ $user_remise=mt_rand(1, 3); if ($user_remise==3) {
+ $soc->remise_percent=5;
+ }
print "> client=".$soc->client.", fournisseur=".$soc->fournisseur.", remise=".$soc->remise_percent."\n";
- $soc->note_private = 'Company created by the script generate-societe.php';
- $socid = $soc->create();
+ $soc->note_private = 'Company created by the script generate-societe.php';
+ $socid = $soc->create();
- if ($socid >= 0)
- {
- $rand = mt_rand(1, 4);
- print "> Generates $rand contact(s)\n";
- for ($c = 0 ; $c < $rand ; $c++)
- {
- $contact = new Contact($db);
- $contact->socid = $soc->id;
- $contact->lastname = "Lastname".$c;
- $contact->firstname = $listoflastname[mt_rand(0, count($listoflastname)-1)];
- if ( $contact->create($user) )
- {
- }
- }
+ if ($socid >= 0) {
+ $rand = mt_rand(1, 4);
+ print "> Generates $rand contact(s)\n";
+ for ($c = 0; $c < $rand; $c++) {
+ $contact = new Contact($db);
+ $contact->socid = $soc->id;
+ $contact->lastname = "Lastname".$c;
+ $contact->firstname = $listoflastname[mt_rand(0, count($listoflastname)-1)];
+ if ($contact->create($user)) {
+ }
+ }
- print "Company ".$s." created nom=".$soc->name."\n";
- } else {
- print "Error: ".$soc->error."\n";
- }
+ print "Company ".$s." created nom=".$soc->name."\n";
+ } else {
+ print "Error: ".$soc->error."\n";
+ }
}
diff --git a/dev/initdata/import-products.php b/dev/initdata/import-products.php
index fb07143f972..d4e06302d56 100755
--- a/dev/initdata/import-products.php
+++ b/dev/initdata/import-products.php
@@ -30,8 +30,8 @@ $sapi_type = php_sapi_name();
$script_file = basename(__FILE__);
$path=dirname(__FILE__).'/';
if (substr($sapi_type, 0, 3) == 'cgi') {
- echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
- exit;
+ echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
+ exit;
}
// Recupere root dolibarr
@@ -67,44 +67,40 @@ $startlinenb = empty($argv[4])?1:$argv[4];
$endlinenb = empty($argv[5])?0:$argv[5];
if (empty($mode) || ! in_array($mode, array('test','confirm','confirmforced')) || empty($filepath)) {
- print "Usage: $script_file (test|confirm|confirmforced) filepath.csv [defaultlang] [startlinenb] [endlinenb]\n";
- print "Usage: $script_file test myfilepath.csv fr_FR 2 1002\n";
- print "\n";
- exit(-1);
+ print "Usage: $script_file (test|confirm|confirmforced) filepath.csv [defaultlang] [startlinenb] [endlinenb]\n";
+ print "Usage: $script_file test myfilepath.csv fr_FR 2 1002\n";
+ print "\n";
+ exit(-1);
}
if (! file_exists($filepath)) {
- print "Error: File ".$filepath." not found.\n";
- print "\n";
- exit(-1);
+ print "Error: File ".$filepath." not found.\n";
+ print "\n";
+ exit(-1);
}
$ret=$user->fetch('', 'admin');
-if (! $ret > 0)
-{
+if (! $ret > 0) {
print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
exit;
}
$user->getrights();
// Ask confirmation
-if (! $confirmed)
-{
- print "Hit Enter to continue or CTRL+C to stop...\n";
- $input = trim(fgets(STDIN));
+if (! $confirmed) {
+ print "Hit Enter to continue or CTRL+C to stop...\n";
+ $input = trim(fgets(STDIN));
}
// Open input and output files
$fhandle = fopen($filepath, 'r');
-if (! $fhandle)
-{
- print 'Error: Failed to open file '.$filepath."\n";
- exit(1);
+if (! $fhandle) {
+ print 'Error: Failed to open file '.$filepath."\n";
+ exit(1);
}
$fhandleerr = fopen($filepatherr, 'w');
-if (! $fhandleerr)
-{
- print 'Error: Failed to open file '.$filepatherr."\n";
- exit(1);
+if (! $fhandleerr) {
+ print 'Error: Failed to open file '.$filepatherr."\n";
+ exit(1);
}
$langs->setDefaultLang($defaultlang);
@@ -114,99 +110,96 @@ $db->begin();
$i=0;
$nboflines++;
-while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape))
-{
- $i++;
- $errorrecord=0;
+while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape)) {
+ $i++;
+ $errorrecord=0;
- if ($startlinenb && $i < $startlinenb) continue;
- if ($endlinenb && $i > $endlinenb) continue;
+ if ($startlinenb && $i < $startlinenb) {
+ continue;
+ }
+ if ($endlinenb && $i > $endlinenb) {
+ continue;
+ }
- $nboflines++;
+ $nboflines++;
- $produit = new Product($db);
- $produit->type = 0;
- $produit->status = 1;
- $produit->ref = trim($fields[0]);
+ $produit = new Product($db);
+ $produit->type = 0;
+ $produit->status = 1;
+ $produit->ref = trim($fields[0]);
- print "Process line nb ".$i.", ref ".$produit->ref;
- $produit->label = trim($fields[2]);
- $produit->description = trim($fields[4]."\n".($fields[5] ? $fields[5].' x '.$fields[6].' x '.$fields[7] : ''));
- $produit->volume = price2num($fields[8]);
- $produit->volume_unit = 0;
- $produit->weight = price2num($fields[9]);
- $produit->weight_units = 0; // -3 = g
+ print "Process line nb ".$i.", ref ".$produit->ref;
+ $produit->label = trim($fields[2]);
+ $produit->description = trim($fields[4]."\n".($fields[5] ? $fields[5].' x '.$fields[6].' x '.$fields[7] : ''));
+ $produit->volume = price2num($fields[8]);
+ $produit->volume_unit = 0;
+ $produit->weight = price2num($fields[9]);
+ $produit->weight_units = 0; // -3 = g
- $produit->customcode = $fields[10];
- $produit->barcode = $fields[1];
+ $produit->customcode = $fields[10];
+ $produit->barcode = $fields[1];
- $produit->status = 1;
- $produit->status_buy = 1;
+ $produit->status = 1;
+ $produit->status_buy = 1;
- $produit->finished = 1;
+ $produit->finished = 1;
- $produit->price_min = null;
- $produit->price_min_ttc = null;
- $produit->price = price2num($fields[11]);
- $produit->price_ttc = price2num($fields[12]);
- $produit->price_base_type = 'TTC';
- $produit->tva_tx = price2num($fields[13]);
- $produit->tva_npr = 0;
+ $produit->price_min = null;
+ $produit->price_min_ttc = null;
+ $produit->price = price2num($fields[11]);
+ $produit->price_ttc = price2num($fields[12]);
+ $produit->price_base_type = 'TTC';
+ $produit->tva_tx = price2num($fields[13]);
+ $produit->tva_npr = 0;
- $produit->cost_price = price2num($fields[16]);
+ $produit->cost_price = price2num($fields[16]);
- // Extrafields
- $produit->array_options['options_ecotaxdeee']=price2num($fields[17]);
+ // Extrafields
+ $produit->array_options['options_ecotaxdeee']=price2num($fields[17]);
- $ret=$produit->create($user);
- if ($ret < 0)
- {
- print " - Error in create result code = ".$ret." - ".$produit->errorsToString();
- $errorrecord++;
- } else {
- print " - Creation OK with ref ".$produit->ref." - id = ".$ret;
+ $ret=$produit->create($user);
+ if ($ret < 0) {
+ print " - Error in create result code = ".$ret." - ".$produit->errorsToString();
+ $errorrecord++;
+ } else {
+ print " - Creation OK with ref ".$produit->ref." - id = ".$ret;
}
dol_syslog("Add prices");
- // If we use price level, insert price for each level
- if (! $errorrecord && 1)
- {
- $ret1=$produit->updatePrice($produit->price_ttc, $produit->price_base_type, $user, $produit->tva_tx, $produit->price_min, 1, $produit->tva_npr, 0, 0, array());
- $ret2=$produit->updatePrice(price2num($fields[14]), 'HT', $user, $produit->tva_tx, $produit->price_min, 2, $produit->tva_npr, 0, 0, array());
- if ($ret1 < 0 || $ret2 < 0)
- {
- print " - Error in updatePrice result code = ".$ret1." ".$ret2." - ".$produit->errorsToString();
- $errorrecord++;
- } else {
- print " - updatePrice OK";
- }
+ // If we use price level, insert price for each level
+ if (! $errorrecord && 1) {
+ $ret1=$produit->updatePrice($produit->price_ttc, $produit->price_base_type, $user, $produit->tva_tx, $produit->price_min, 1, $produit->tva_npr, 0, 0, array());
+ $ret2=$produit->updatePrice(price2num($fields[14]), 'HT', $user, $produit->tva_tx, $produit->price_min, 2, $produit->tva_npr, 0, 0, array());
+ if ($ret1 < 0 || $ret2 < 0) {
+ print " - Error in updatePrice result code = ".$ret1." ".$ret2." - ".$produit->errorsToString();
+ $errorrecord++;
+ } else {
+ print " - updatePrice OK";
+ }
}
dol_syslog("Add multilangs");
// Add alternative languages
- if (! $errorrecord && 1)
- {
- $produit->multilangs['fr_FR']=array('label'=>$produit->label, 'description'=>$produit->description, 'note'=>$produit->note_private);
- $produit->multilangs['en_US']=array('label'=>$fields[3], 'description'=>$produit->description, 'note'=>$produit->note_private);
+ if (! $errorrecord && 1) {
+ $produit->multilangs['fr_FR']=array('label'=>$produit->label, 'description'=>$produit->description, 'note'=>$produit->note_private);
+ $produit->multilangs['en_US']=array('label'=>$fields[3], 'description'=>$produit->description, 'note'=>$produit->note_private);
- $ret=$produit->setMultiLangs($user);
- if ($ret < 0)
- {
- print " - Error in setMultiLangs result code = ".$ret." - ".$produit->errorsToString();
- $errorrecord++;
- } else {
- print " - setMultiLangs OK";
- }
+ $ret=$produit->setMultiLangs($user);
+ if ($ret < 0) {
+ print " - Error in setMultiLangs result code = ".$ret." - ".$produit->errorsToString();
+ $errorrecord++;
+ } else {
+ print " - setMultiLangs OK";
+ }
}
print "\n";
- if ($errorrecord)
- {
- fwrite($fhandleerr, 'Error on record nb '.$i." - ".$produit->errorsToString()."\n");
- $error++; // $errorrecord will be reset
+ if ($errorrecord) {
+ fwrite($fhandleerr, 'Error on record nb '.$i." - ".$produit->errorsToString()."\n");
+ $error++; // $errorrecord will be reset
}
}
@@ -217,13 +210,12 @@ while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape))
// commit or rollback
print "Nb of lines qualified: ".$nboflines."\n";
print "Nb of errors: ".$error."\n";
-if ($mode != 'confirmforced' && ($error || $mode != 'confirm'))
-{
- print "Rollback any changes.\n";
- $db->rollback();
+if ($mode != 'confirmforced' && ($error || $mode != 'confirm')) {
+ print "Rollback any changes.\n";
+ $db->rollback();
} else {
- print "Commit all changes.\n";
- $db->commit();
+ print "Commit all changes.\n";
+ $db->commit();
}
$db->close();
diff --git a/dev/initdata/import-thirdparties.php b/dev/initdata/import-thirdparties.php
index a0ddaac7674..91f28f11769 100755
--- a/dev/initdata/import-thirdparties.php
+++ b/dev/initdata/import-thirdparties.php
@@ -30,8 +30,8 @@ $sapi_type = php_sapi_name();
$script_file = basename(__FILE__);
$path=dirname(__FILE__).'/';
if (substr($sapi_type, 0, 3) == 'cgi') {
- echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
- exit;
+ echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
+ exit;
}
// Recupere root dolibarr
@@ -67,44 +67,40 @@ $startlinenb = empty($argv[3])?1:$argv[3];
$endlinenb = empty($argv[4])?0:$argv[4];
if (empty($mode) || ! in_array($mode, array('test','confirm','confirmforced')) || empty($filepath)) {
- print "Usage: $script_file (test|confirm|confirmforced) filepath.csv [startlinenb] [endlinenb]\n";
- print "Usage: $script_file test myfilepath.csv 2 1002\n";
- print "\n";
- exit(-1);
+ print "Usage: $script_file (test|confirm|confirmforced) filepath.csv [startlinenb] [endlinenb]\n";
+ print "Usage: $script_file test myfilepath.csv 2 1002\n";
+ print "\n";
+ exit(-1);
}
if (! file_exists($filepath)) {
- print "Error: File ".$filepath." not found.\n";
- print "\n";
- exit(-1);
+ print "Error: File ".$filepath." not found.\n";
+ print "\n";
+ exit(-1);
}
$ret=$user->fetch('', 'admin');
-if (! $ret > 0)
-{
+if (! $ret > 0) {
print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
exit;
}
$user->getrights();
// Ask confirmation
-if (! $confirmed)
-{
- print "Hit Enter to continue or CTRL+C to stop...\n";
- $input = trim(fgets(STDIN));
+if (! $confirmed) {
+ print "Hit Enter to continue or CTRL+C to stop...\n";
+ $input = trim(fgets(STDIN));
}
// Open input and output files
$fhandle = fopen($filepath, 'r');
-if (! $fhandle)
-{
- print 'Error: Failed to open file '.$filepath."\n";
- exit(1);
+if (! $fhandle) {
+ print 'Error: Failed to open file '.$filepath."\n";
+ exit(1);
}
$fhandleerr = fopen($filepatherr, 'w');
-if (! $fhandleerr)
-{
- print 'Error: Failed to open file '.$filepatherr."\n";
- exit(1);
+if (! $fhandleerr) {
+ print 'Error: Failed to open file '.$filepatherr."\n";
+ exit(1);
}
//$langs->setDefaultLang($defaultlang);
@@ -114,175 +110,173 @@ $db->begin();
$i=0;
$nboflines=0;
-while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape))
-{
- $i++;
- $errorrecord=0;
+while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape)) {
+ $i++;
+ $errorrecord=0;
- if ($startlinenb && $i < $startlinenb) continue;
- if ($endlinenb && $i > $endlinenb) continue;
+ if ($startlinenb && $i < $startlinenb) {
+ continue;
+ }
+ if ($endlinenb && $i > $endlinenb) {
+ continue;
+ }
- $nboflines++;
+ $nboflines++;
- $object = new Societe($db);
- $object->state = $fields[6];
- $object->client = $fields[7];
- $object->fournisseur = $fields[8];
+ $object = new Societe($db);
+ $object->state = $fields[6];
+ $object->client = $fields[7];
+ $object->fournisseur = $fields[8];
- $object->name = $fields[13]?trim($fields[13]):$fields[0];
- $object->name_alias = $fields[0]!=$fields[13]?trim($fields[0]):'';
+ $object->name = $fields[13]?trim($fields[13]):$fields[0];
+ $object->name_alias = $fields[0]!=$fields[13]?trim($fields[0]):'';
- $object->address = trim($fields[14]);
- $object->zip = trim($fields[15]);
- $object->town = trim($fields[16]);
- $object->country_id = dol_getIdFromCode($db, trim($fields[21]), 'c_country', 'code', 'rowid');
- $object->phone = trim($fields[22]);
- $object->fax = trim($fields[23]);
- $object->email = trim($fields[26]);
- $object->idprof2 = trim($fields[29]);
- $object->tva_intra = trim($fields[34]);
- $object->default_lang = trim($fields[43]);
+ $object->address = trim($fields[14]);
+ $object->zip = trim($fields[15]);
+ $object->town = trim($fields[16]);
+ $object->country_id = dol_getIdFromCode($db, trim($fields[21]), 'c_country', 'code', 'rowid');
+ $object->phone = trim($fields[22]);
+ $object->fax = trim($fields[23]);
+ $object->email = trim($fields[26]);
+ $object->idprof2 = trim($fields[29]);
+ $object->tva_intra = trim($fields[34]);
+ $object->default_lang = trim($fields[43]);
- //$condpayment = dol_string_unaccent(trim($fields[36]));
- if ($fields[36])
- {
- $condpayment = trim($fields[36]);
- if ($condpayment == 'A la commande') $condpayment = 'A réception de commande';
- if ($condpayment == 'A reception facture') $condpayment = 'Réception de facture';
- $object->cond_reglement_id = dol_getIdFromCode($db, $condpayment, 'c_payment_term', 'libelle_facture', 'rowid', 1);
- if (empty($object->cond_reglement_id))
- {
- print " - Error cant find payment mode for ".$condpayment."\n";
- $errorrecord++;
- }
- }
+ //$condpayment = dol_string_unaccent(trim($fields[36]));
+ if ($fields[36]) {
+ $condpayment = trim($fields[36]);
+ if ($condpayment == 'A la commande') {
+ $condpayment = 'A réception de commande';
+ }
+ if ($condpayment == 'A reception facture') {
+ $condpayment = 'Réception de facture';
+ }
+ $object->cond_reglement_id = dol_getIdFromCode($db, $condpayment, 'c_payment_term', 'libelle_facture', 'rowid', 1);
+ if (empty($object->cond_reglement_id)) {
+ print " - Error cant find payment mode for ".$condpayment."\n";
+ $errorrecord++;
+ }
+ }
- $object->code_client = $fields[9];
- $object->code_fournisseur = $fields[10];
+ $object->code_client = $fields[9];
+ $object->code_fournisseur = $fields[10];
- $labeltype = trim($fields[1]);
- $object->typent_id = dol_getIdFromCode($db, $labeltype, 'c_typent', 'libelle');
+ $labeltype = trim($fields[1]);
+ $object->typent_id = dol_getIdFromCode($db, $labeltype, 'c_typent', 'libelle');
- // Set price level
- $object->price_level = 1;
- if ($labeltype == 'Revendeur') $object->price_level = 2;
+ // Set price level
+ $object->price_level = 1;
+ if ($labeltype == 'Revendeur') {
+ $object->price_level = 2;
+ }
- print "Process line nb ".$i.", name ".$object->name;
+ print "Process line nb ".$i.", name ".$object->name;
- // Extrafields
- $object->array_options['options_anastate']=price2num($fields[20]);
- $object->array_options['options_anaregion']=price2num($fields[17]);
+ // Extrafields
+ $object->array_options['options_anastate']=price2num($fields[20]);
+ $object->array_options['options_anaregion']=price2num($fields[17]);
- if (! $errorrecord)
- {
- $ret=$object->create($user);
- if ($ret < 0)
- {
- print " - Error in create result code = ".$ret." - ".$object->errorsToString();
- $errorrecord++;
- } else {
- print " - Creation OK with name ".$object->name." - id = ".$ret;
- }
- }
+ if (! $errorrecord) {
+ $ret=$object->create($user);
+ if ($ret < 0) {
+ print " - Error in create result code = ".$ret." - ".$object->errorsToString();
+ $errorrecord++;
+ } else {
+ print " - Creation OK with name ".$object->name." - id = ".$ret;
+ }
+ }
- if (! $errorrecord)
- {
- dol_syslog("Set price level");
- $object->set_price_level($object->price_level, $user);
- }
+ if (! $errorrecord) {
+ dol_syslog("Set price level");
+ $object->set_price_level($object->price_level, $user);
+ }
// Assign sales representative
- if (! $errorrecord && $fields[3])
- {
- $salesrep=new User($db);
+ if (! $errorrecord && $fields[3]) {
+ $salesrep=new User($db);
- $tmp=explode(' ', $fields[3], 2);
- $salesrep->firstname = trim($tmp[0]);
- $salesrep->lastname = trim($tmp[1]);
- if ($salesrep->lastname) $salesrep->login = strtolower(substr($salesrep->firstname, 0, 1)) . strtolower(substr($salesrep->lastname, 0));
- else $salesrep->login=strtolower($salesrep->firstname);
- $salesrep->login=preg_replace('/ /', '', $salesrep->login);
- $salesrep->fetch(0, $salesrep->login);
+ $tmp=explode(' ', $fields[3], 2);
+ $salesrep->firstname = trim($tmp[0]);
+ $salesrep->lastname = trim($tmp[1]);
+ if ($salesrep->lastname) {
+ $salesrep->login = strtolower(substr($salesrep->firstname, 0, 1)) . strtolower(substr($salesrep->lastname, 0));
+ } else {
+ $salesrep->login=strtolower($salesrep->firstname);
+ }
+ $salesrep->login=preg_replace('/ /', '', $salesrep->login);
+ $salesrep->fetch(0, $salesrep->login);
- $result = $object->add_commercial($user, $salesrep->id);
- if ($result < 0)
- {
- print " - Error in create link with sale representative result code = ".$result." - ".$object->errorsToString();
- $errorrecord++;
- } else {
- print " - create link sale representative OK";
- }
+ $result = $object->add_commercial($user, $salesrep->id);
+ if ($result < 0) {
+ print " - Error in create link with sale representative result code = ".$result." - ".$object->errorsToString();
+ $errorrecord++;
+ } else {
+ print " - create link sale representative OK";
+ }
}
dol_syslog("Add invoice contacts");
// Insert an invoice contact if there is an invoice email != standard email
- if (! $errorrecord && $fields[27] && $fields[26] != $fields[27])
- {
- $ret1=$ret2=0;
+ if (! $errorrecord && $fields[27] && $fields[26] != $fields[27]) {
+ $ret1=$ret2=0;
- $contact = new Contact($db);
- $contact->lastname = $object->name;
- $contact->address=$object->address;
- $contact->zip=$object->zip;
- $contact->town=$object->town;
- $contact->country_id=$object->country_id;
- $contact->email=$fields[27];
- $contact->socid=$object->id;
+ $contact = new Contact($db);
+ $contact->lastname = $object->name;
+ $contact->address=$object->address;
+ $contact->zip=$object->zip;
+ $contact->town=$object->town;
+ $contact->country_id=$object->country_id;
+ $contact->email=$fields[27];
+ $contact->socid=$object->id;
- $ret1=$contact->create($user);
- if ($ret1 > 0)
- {
- //$ret2=$contact->add_contact($object->id, 'BILLING');
- }
- if ($ret1 < 0 || $ret2 < 0)
- {
- print " - Error in create contact result code = ".$ret1." ".$ret2." - ".$object->errorsToString();
- $errorrecord++;
- } else {
- print " - create contact OK";
- }
+ $ret1=$contact->create($user);
+ if ($ret1 > 0) {
+ //$ret2=$contact->add_contact($object->id, 'BILLING');
+ }
+ if ($ret1 < 0 || $ret2 < 0) {
+ print " - Error in create contact result code = ".$ret1." ".$ret2." - ".$object->errorsToString();
+ $errorrecord++;
+ } else {
+ print " - create contact OK";
+ }
}
dol_syslog("Add delivery contacts");
// Insert a delivery contact
- if (! $errorrecord && $fields[47])
- {
- $ret1=$ret2=0;
+ if (! $errorrecord && $fields[47]) {
+ $ret1=$ret2=0;
- $contact2 = new Contact($db);
- $contact2->lastname = 'Service livraison - '.$fields[47];
- $contact2->address = $fields[48];
- $contact2->zip = $fields[50];
- $contact2->town = $fields[51];
- $contact2->country_id=dol_getIdFromCode($db, trim($fields[52]), 'c_country', 'code', 'rowid');
- $contact2->note_public=$fields[54];
- $contact2->socid=$object->id;
+ $contact2 = new Contact($db);
+ $contact2->lastname = 'Service livraison - '.$fields[47];
+ $contact2->address = $fields[48];
+ $contact2->zip = $fields[50];
+ $contact2->town = $fields[51];
+ $contact2->country_id=dol_getIdFromCode($db, trim($fields[52]), 'c_country', 'code', 'rowid');
+ $contact2->note_public=$fields[54];
+ $contact2->socid=$object->id;
- // Extrafields
- $contact2->array_options['options_anazoneliv']=price2num($fields[53]);
+ // Extrafields
+ $contact2->array_options['options_anazoneliv']=price2num($fields[53]);
- $ret1=$contact2->create($user);
- if ($ret1 > 0)
- {
- //$ret2=$contact2->add_contact($object->id, 'SHIPPING');
- }
- if ($ret1 < 0 || $ret2 < 0)
- {
- print " - Error in create contact result code = ".$ret1." ".$ret2." - ".$object->errorsToString();
- $errorrecord++;
- } else {
- print " - create contact OK";
- }
+ $ret1=$contact2->create($user);
+ if ($ret1 > 0) {
+ //$ret2=$contact2->add_contact($object->id, 'SHIPPING');
+ }
+ if ($ret1 < 0 || $ret2 < 0) {
+ print " - Error in create contact result code = ".$ret1." ".$ret2." - ".$object->errorsToString();
+ $errorrecord++;
+ } else {
+ print " - create contact OK";
+ }
}
print "\n";
- if ($errorrecord)
- {
- fwrite($fhandleerr, 'Error on record nb '.$i." - ".$object->errorsToString()."\n");
- $error++; // $errorrecord will be reset
+ if ($errorrecord) {
+ fwrite($fhandleerr, 'Error on record nb '.$i." - ".$object->errorsToString()."\n");
+ $error++; // $errorrecord will be reset
}
}
@@ -293,13 +287,12 @@ while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape))
// commit or rollback
print "Nb of lines qualified: ".$nboflines."\n";
print "Nb of errors: ".$error."\n";
-if ($mode != 'confirmforced' && ($error || $mode != 'confirm'))
-{
- print "Rollback any changes.\n";
- $db->rollback();
+if ($mode != 'confirmforced' && ($error || $mode != 'confirm')) {
+ print "Rollback any changes.\n";
+ $db->rollback();
} else {
- print "Commit all changes.\n";
- $db->commit();
+ print "Commit all changes.\n";
+ $db->commit();
}
$db->close();
diff --git a/dev/initdata/import-users.php b/dev/initdata/import-users.php
index 8e4878577a1..3c28493c106 100755
--- a/dev/initdata/import-users.php
+++ b/dev/initdata/import-users.php
@@ -30,8 +30,8 @@ $sapi_type = php_sapi_name();
$script_file = basename(__FILE__);
$path=dirname(__FILE__).'/';
if (substr($sapi_type, 0, 3) == 'cgi') {
- echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
- exit;
+ echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
+ exit;
}
// Recupere root dolibarr
@@ -67,44 +67,40 @@ $startlinenb = empty($argv[3])?1:$argv[3];
$endlinenb = empty($argv[4])?0:$argv[4];
if (empty($mode) || ! in_array($mode, array('test','confirm','confirmforced')) || empty($filepath)) {
- print "Usage: $script_file (test|confirm|confirmforced) filepath.csv [startlinenb] [endlinenb]\n";
- print "Usage: $script_file test myfilepath.csv 2 1002\n";
- print "\n";
- exit(-1);
+ print "Usage: $script_file (test|confirm|confirmforced) filepath.csv [startlinenb] [endlinenb]\n";
+ print "Usage: $script_file test myfilepath.csv 2 1002\n";
+ print "\n";
+ exit(-1);
}
if (! file_exists($filepath)) {
- print "Error: File ".$filepath." not found.\n";
- print "\n";
- exit(-1);
+ print "Error: File ".$filepath." not found.\n";
+ print "\n";
+ exit(-1);
}
$ret=$user->fetch('', 'admin');
-if (! $ret > 0)
-{
+if (! $ret > 0) {
print 'A user with login "admin" and all permissions must be created to use this script.'."\n";
exit;
}
$user->getrights();
// Ask confirmation
-if (! $confirmed)
-{
- print "Hit Enter to continue or CTRL+C to stop...\n";
- $input = trim(fgets(STDIN));
+if (! $confirmed) {
+ print "Hit Enter to continue or CTRL+C to stop...\n";
+ $input = trim(fgets(STDIN));
}
// Open input and output files
$fhandle = fopen($filepath, 'r');
-if (! $fhandle)
-{
- print 'Error: Failed to open file '.$filepath."\n";
- exit(1);
+if (! $fhandle) {
+ print 'Error: Failed to open file '.$filepath."\n";
+ exit(1);
}
$fhandleerr = fopen($filepatherr, 'w');
-if (! $fhandleerr)
-{
- print 'Error: Failed to open file '.$filepatherr."\n";
- exit(1);
+if (! $fhandleerr) {
+ print 'Error: Failed to open file '.$filepatherr."\n";
+ exit(1);
}
//$langs->setDefaultLang($defaultlang);
@@ -114,44 +110,48 @@ $db->begin();
$i=0;
$nboflines=0;
-while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape))
-{
- $i++;
- $errorrecord=0;
+while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape)) {
+ $i++;
+ $errorrecord=0;
- if ($startlinenb && $i < $startlinenb) continue;
- if ($endlinenb && $i > $endlinenb) continue;
+ if ($startlinenb && $i < $startlinenb) {
+ continue;
+ }
+ if ($endlinenb && $i > $endlinenb) {
+ continue;
+ }
- $nboflines++;
+ $nboflines++;
- $object = new User($db);
- $object->statut = 1;
+ $object = new User($db);
+ $object->statut = 1;
- $tmp=explode(' ', $fields[3], 2);
- $object->firstname = trim($tmp[0]);
- $object->lastname = trim($tmp[1]);
- if ($object->lastname) $object->login = strtolower(substr($object->firstname, 0, 1)) . strtolower(substr($object->lastname, 0));
- else $object->login=strtolower($object->firstname);
- $object->login=preg_replace('/ /', '', $object->login);
- $object->password = 'init';
+ $tmp=explode(' ', $fields[3], 2);
+ $object->firstname = trim($tmp[0]);
+ $object->lastname = trim($tmp[1]);
+ if ($object->lastname) {
+ $object->login = strtolower(substr($object->firstname, 0, 1)) . strtolower(substr($object->lastname, 0));
+ } else {
+ $object->login=strtolower($object->firstname);
+ }
+ $object->login=preg_replace('/ /', '', $object->login);
+ $object->password = 'init';
- print "Process line nb ".$i.", login ".$object->login;
+ print "Process line nb ".$i.", login ".$object->login;
- $ret=$object->create($user);
- if ($ret < 0)
- {
- print " - Error in create result code = ".$ret." - ".$object->errorsToString();
- $errorrecord++;
- } else {
- print " - Creation OK with login ".$object->login." - id = ".$ret;
+ $ret=$object->create($user);
+ if ($ret < 0) {
+ print " - Error in create result code = ".$ret." - ".$object->errorsToString();
+ $errorrecord++;
+ } else {
+ print " - Creation OK with login ".$object->login." - id = ".$ret;
}
print "\n";
- if ($errorrecord)
- {
- fwrite($fhandleerr, 'Error on record nb '.$i." - ".$object->errorsToString()."\n");
- $error++; // $errorrecord will be reset
+ if ($errorrecord) {
+ fwrite($fhandleerr, 'Error on record nb '.$i." - ".$object->errorsToString()."\n");
+ $error++; // $errorrecord will be reset
}
}
@@ -162,13 +162,12 @@ while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape))
// commit or rollback
print "Nb of lines qualified: ".$nboflines."\n";
print "Nb of errors: ".$error."\n";
-if ($mode != 'confirmforced' && ($error || $mode != 'confirm'))
-{
- print "Rollback any changes.\n";
- $db->rollback();
+if ($mode != 'confirmforced' && ($error || $mode != 'confirm')) {
+ print "Rollback any changes.\n";
+ $db->rollback();
} else {
- print "Commit all changes.\n";
- $db->commit();
+ print "Commit all changes.\n";
+ $db->commit();
}
$db->close();
diff --git a/dev/initdata/purge-data.php b/dev/initdata/purge-data.php
index 18256c33766..9214f34d810 100755
--- a/dev/initdata/purge-data.php
+++ b/dev/initdata/purge-data.php
@@ -30,8 +30,8 @@ $path=__DIR__.'/';
// Test si mode batch
if (substr($sapi_type, 0, 3) == 'cgi') {
- echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
- exit(-1);
+ echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
+ exit(-1);
}
// Recupere root dolibarr
@@ -52,121 +52,121 @@ $error=0;
// List of sql to execute
$sqls=array(
- 'user'=>array(
- "DELETE FROM ".MAIN_DB_PREFIX."user_rights WHERE fk_user IN (SELECT rowid FROM ".MAIN_DB_PREFIX."user WHERE admin = 0 and login != 'admin') AND fk_user IN (select rowid FROM ".MAIN_DB_PREFIX."user where datec < '__DATE__')",
- "DELETE FROM ".MAIN_DB_PREFIX."user WHERE admin = 0 and login != 'admin' AND datec < '__DATE__'",
- ),
- 'event'=>array(
- //"DELETE FROM ".MAIN_DB_PREFIX."actioncomm WHERE lineid IN (SELECT rowid FROM ".MAIN_DB_PREFIX."bank WHERE datec < '__DATE__')",
- "DELETE FROM ".MAIN_DB_PREFIX."actioncomm WHERE datec < '__DATE__'",
- ),
- 'payment'=>array(
- "DELETE FROM ".MAIN_DB_PREFIX."paiement_facture where fk_facture IN (select rowid FROM ".MAIN_DB_PREFIX."facture where datec < '__DATE__')",
- "DELETE FROM ".MAIN_DB_PREFIX."paiement where rowid NOT IN (SELECT fk_paiement FROM ".MAIN_DB_PREFIX."paiement_facture)",
- ),
- 'supplier_payment'=>array(
- "DELETE FROM ".MAIN_DB_PREFIX."paiementfourn_facturefourn where fk_facturefourn IN (select rowid FROM ".MAIN_DB_PREFIX."facture_fourn where datec < '__DATE__')",
- "DELETE FROM ".MAIN_DB_PREFIX."paiementfourn where rowid NOT IN (SELECT fk_paiementfourn FROM ".MAIN_DB_PREFIX."paiementfourn_facturefourn)",
- ),
- 'bank'=>array(
- "DELETE FROM ".MAIN_DB_PREFIX."bank_class WHERE lineid IN (SELECT rowid FROM ".MAIN_DB_PREFIX."bank WHERE datec < '__DATE__')",
- "DELETE FROM ".MAIN_DB_PREFIX."bank_url WHERE fk_bank IN (SELECT rowid FROM ".MAIN_DB_PREFIX."bank WHERE datec < '__DATE__')",
- "DELETE FROM ".MAIN_DB_PREFIX."bank WHERE datec < '__DATE__'",
- ),
- 'bankaccount'=>array(
- "DELETE FROM ".MAIN_DB_PREFIX."bank_account WHERE datec < '__DATE__'",
- ),
- 'invoice'=>array(
- '@payment',
- "DELETE FROM ".MAIN_DB_PREFIX."societe_remise_except where fk_facture_source IN (select rowid FROM ".MAIN_DB_PREFIX."facture where datec < '__DATE__')",
- "DELETE FROM ".MAIN_DB_PREFIX."societe_remise_except where fk_facture IN (select rowid FROM ".MAIN_DB_PREFIX."facture where datec < '__DATE__')",
- "DELETE FROM ".MAIN_DB_PREFIX."societe_remise_except where fk_facture_line IN (select rowid FROM ".MAIN_DB_PREFIX."facturedet as fd WHERE fd.fk_facture IN (select rowid from ".MAIN_DB_PREFIX."facture where datec < '__DATE__'))",
- "DELETE FROM ".MAIN_DB_PREFIX."facture_rec where datec < '__DATE__'",
- "DELETE FROM ".MAIN_DB_PREFIX."facturedet WHERE fk_facture IN (select rowid FROM ".MAIN_DB_PREFIX."facture where datec < '__DATE__')",
- "UPDATE ".MAIN_DB_PREFIX."facture SET fk_facture_source = NULL WHERE fk_facture_source IN (select f2.rowid FROM (select * from ".MAIN_DB_PREFIX."facture) as f2 where f2.datec < '__DATE__')",
- "DELETE FROM ".MAIN_DB_PREFIX."facture where datec < '__DATE__'",
- ),
- 'accounting'=>array(
- "DELETE FROM ".MAIN_DB_PREFIX."accounting_bookkeeping where doc_date < '__DATE__'",
- ),
- 'proposal'=>array(
- "DELETE FROM ".MAIN_DB_PREFIX."propaldet WHERE fk_propal IN (select rowid FROM ".MAIN_DB_PREFIX."propal where datec < '__DATE__')",
- "DELETE FROM ".MAIN_DB_PREFIX."propal WHERE datec < '__DATE__'",
- ),
- "supplier_proposal"=>array(
- "DELETE FROM ".MAIN_DB_PREFIX."supplier_proposaldet WHERE fk_supplier_proposal IN (select rowid FROM ".MAIN_DB_PREFIX."propal where datec < '__DATE__')",
- "DELETE FROM ".MAIN_DB_PREFIX."supplier_proposal where datec < '__DATE__'",
- ),
- 'order'=>array(
- '@shipment',
- "DELETE FROM ".MAIN_DB_PREFIX."commandedet WHERE fk_commande IN (select rowid FROM ".MAIN_DB_PREFIX."commande where date_creation < '__DATE__')",
- "DELETE FROM ".MAIN_DB_PREFIX."commande where date_creation < '__DATE__'",
- ),
- 'supplier_order'=>array(
- "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseurdet WHERE fk_commande IN (select rowid FROM ".MAIN_DB_PREFIX."commande_fournisseur where date_creation < '__DATE__')",
- "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseur where date_creation < '__DATE__'",
- ),
+ 'user'=>array(
+ "DELETE FROM ".MAIN_DB_PREFIX."user_rights WHERE fk_user IN (SELECT rowid FROM ".MAIN_DB_PREFIX."user WHERE admin = 0 and login != 'admin') AND fk_user IN (select rowid FROM ".MAIN_DB_PREFIX."user where datec < '__DATE__')",
+ "DELETE FROM ".MAIN_DB_PREFIX."user WHERE admin = 0 and login != 'admin' AND datec < '__DATE__'",
+ ),
+ 'event'=>array(
+ //"DELETE FROM ".MAIN_DB_PREFIX."actioncomm WHERE lineid IN (SELECT rowid FROM ".MAIN_DB_PREFIX."bank WHERE datec < '__DATE__')",
+ "DELETE FROM ".MAIN_DB_PREFIX."actioncomm WHERE datec < '__DATE__'",
+ ),
+ 'payment'=>array(
+ "DELETE FROM ".MAIN_DB_PREFIX."paiement_facture where fk_facture IN (select rowid FROM ".MAIN_DB_PREFIX."facture where datec < '__DATE__')",
+ "DELETE FROM ".MAIN_DB_PREFIX."paiement where rowid NOT IN (SELECT fk_paiement FROM ".MAIN_DB_PREFIX."paiement_facture)",
+ ),
+ 'supplier_payment'=>array(
+ "DELETE FROM ".MAIN_DB_PREFIX."paiementfourn_facturefourn where fk_facturefourn IN (select rowid FROM ".MAIN_DB_PREFIX."facture_fourn where datec < '__DATE__')",
+ "DELETE FROM ".MAIN_DB_PREFIX."paiementfourn where rowid NOT IN (SELECT fk_paiementfourn FROM ".MAIN_DB_PREFIX."paiementfourn_facturefourn)",
+ ),
+ 'bank'=>array(
+ "DELETE FROM ".MAIN_DB_PREFIX."bank_class WHERE lineid IN (SELECT rowid FROM ".MAIN_DB_PREFIX."bank WHERE datec < '__DATE__')",
+ "DELETE FROM ".MAIN_DB_PREFIX."bank_url WHERE fk_bank IN (SELECT rowid FROM ".MAIN_DB_PREFIX."bank WHERE datec < '__DATE__')",
+ "DELETE FROM ".MAIN_DB_PREFIX."bank WHERE datec < '__DATE__'",
+ ),
+ 'bankaccount'=>array(
+ "DELETE FROM ".MAIN_DB_PREFIX."bank_account WHERE datec < '__DATE__'",
+ ),
+ 'invoice'=>array(
+ '@payment',
+ "DELETE FROM ".MAIN_DB_PREFIX."societe_remise_except where fk_facture_source IN (select rowid FROM ".MAIN_DB_PREFIX."facture where datec < '__DATE__')",
+ "DELETE FROM ".MAIN_DB_PREFIX."societe_remise_except where fk_facture IN (select rowid FROM ".MAIN_DB_PREFIX."facture where datec < '__DATE__')",
+ "DELETE FROM ".MAIN_DB_PREFIX."societe_remise_except where fk_facture_line IN (select rowid FROM ".MAIN_DB_PREFIX."facturedet as fd WHERE fd.fk_facture IN (select rowid from ".MAIN_DB_PREFIX."facture where datec < '__DATE__'))",
+ "DELETE FROM ".MAIN_DB_PREFIX."facture_rec where datec < '__DATE__'",
+ "DELETE FROM ".MAIN_DB_PREFIX."facturedet WHERE fk_facture IN (select rowid FROM ".MAIN_DB_PREFIX."facture where datec < '__DATE__')",
+ "UPDATE ".MAIN_DB_PREFIX."facture SET fk_facture_source = NULL WHERE fk_facture_source IN (select f2.rowid FROM (select * from ".MAIN_DB_PREFIX."facture) as f2 where f2.datec < '__DATE__')",
+ "DELETE FROM ".MAIN_DB_PREFIX."facture where datec < '__DATE__'",
+ ),
+ 'accounting'=>array(
+ "DELETE FROM ".MAIN_DB_PREFIX."accounting_bookkeeping where doc_date < '__DATE__'",
+ ),
+ 'proposal'=>array(
+ "DELETE FROM ".MAIN_DB_PREFIX."propaldet WHERE fk_propal IN (select rowid FROM ".MAIN_DB_PREFIX."propal where datec < '__DATE__')",
+ "DELETE FROM ".MAIN_DB_PREFIX."propal WHERE datec < '__DATE__'",
+ ),
+ "supplier_proposal"=>array(
+ "DELETE FROM ".MAIN_DB_PREFIX."supplier_proposaldet WHERE fk_supplier_proposal IN (select rowid FROM ".MAIN_DB_PREFIX."propal where datec < '__DATE__')",
+ "DELETE FROM ".MAIN_DB_PREFIX."supplier_proposal where datec < '__DATE__'",
+ ),
+ 'order'=>array(
+ '@shipment',
+ "DELETE FROM ".MAIN_DB_PREFIX."commandedet WHERE fk_commande IN (select rowid FROM ".MAIN_DB_PREFIX."commande where date_creation < '__DATE__')",
+ "DELETE FROM ".MAIN_DB_PREFIX."commande where date_creation < '__DATE__'",
+ ),
+ 'supplier_order'=>array(
+ "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseurdet WHERE fk_commande IN (select rowid FROM ".MAIN_DB_PREFIX."commande_fournisseur where date_creation < '__DATE__')",
+ "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseur where date_creation < '__DATE__'",
+ ),
'supplier_invoice'=>array(
'@supplier_payment',
- "DELETE FROM ".MAIN_DB_PREFIX."facture_fourn_det WHERE fk_facture_fourn IN (select rowid FROM ".MAIN_DB_PREFIX."facture_fourn where datec < '__DATE__')",
- "DELETE FROM ".MAIN_DB_PREFIX."facture_fourn where datec < '__DATE__'",
- ),
- 'shipment'=>array(
- '@delivery',
- "DELETE FROM ".MAIN_DB_PREFIX."expeditiondet_batch WHERE fk_expeditiondet IN (select rowid FROM ".MAIN_DB_PREFIX."expeditiondet WHERE fk_expedition IN (select rowid FROM ".MAIN_DB_PREFIX."expedition where date_creation < '__DATE__'))",
- "DELETE FROM ".MAIN_DB_PREFIX."expeditiondet_extrafields WHERE fk_object IN (select rowid FROM ".MAIN_DB_PREFIX."expeditiondet WHERE fk_expedition IN (select rowid FROM ".MAIN_DB_PREFIX."expedition where date_creation < '__DATE__'))",
- "DELETE FROM ".MAIN_DB_PREFIX."expeditiondet WHERE fk_expedition IN (select rowid FROM ".MAIN_DB_PREFIX."expedition where date_creation < '__DATE__')",
- "DELETE FROM ".MAIN_DB_PREFIX."expedition_extrafields WHERE fk_object IN (select rowid FROM ".MAIN_DB_PREFIX."expedition where date_creation < '__DATE__')",
- "DELETE FROM ".MAIN_DB_PREFIX."expedition where date_creation < '__DATE__'",
- ),
- 'delivery'=>array(
- "DELETE FROM ".MAIN_DB_PREFIX."deliverydet WHERE fk_delivery IN (select rowid FROM ".MAIN_DB_PREFIX."delivery where date_creation < '__DATE__')",
- "DELETE FROM ".MAIN_DB_PREFIX."delivery where date_creation < '__DATE__'",
- ),
- 'contract'=>array(
- "DELETE FROM ".MAIN_DB_PREFIX."contratdet_extrafields WHERE fk_object IN (select rowid FROM ".MAIN_DB_PREFIX."contratdet WHERE fk_contrat IN (select rowid FROM ".MAIN_DB_PREFIX."contrat where datec < '__DATE__'))",
- "DELETE FROM ".MAIN_DB_PREFIX."contratdet WHERE fk_contrat IN (select rowid FROM ".MAIN_DB_PREFIX."contrat where datec < '__DATE__')",
- "DELETE FROM ".MAIN_DB_PREFIX."contrat_extrafields WHERE fk_object IN (select rowid FROM ".MAIN_DB_PREFIX."contrat where datec < '__DATE__')",
- "DELETE FROM ".MAIN_DB_PREFIX."contrat WHERE datec < '__DATE__'",
- ),
- 'intervention'=>array(
- "DELETE FROM ".MAIN_DB_PREFIX."fichinterdet WHERE fk_fichinter IN (select rowid FROM ".MAIN_DB_PREFIX."fichinter where datec < '__DATE__')",
- "DELETE FROM ".MAIN_DB_PREFIX."fichinter where datec < '__DATE__'",
- ),
- 'stock'=>array(
- "DELETE FROM ".MAIN_DB_PREFIX."stock_mouvement WHERE datem < '__DATE__'",
- ),
- 'product'=>array(
- "DELETE FROM ".MAIN_DB_PREFIX."categorie_product WHERE fk_product IN (select rowid FROM ".MAIN_DB_PREFIX."product where datec < '__DATE__')",
- "DELETE FROM ".MAIN_DB_PREFIX."product_lang WHERE fk_product IN (select rowid FROM ".MAIN_DB_PREFIX."product where datec < '__DATE__')",
- "DELETE FROM ".MAIN_DB_PREFIX."product_price_by_qty WHERE fk_product_price IN (select rowid FROM ".MAIN_DB_PREFIX."product_price where fk_product IN (select rowid FROM ".MAIN_DB_PREFIX."product where datec < '__DATE__'))",
- "DELETE FROM ".MAIN_DB_PREFIX."product_price WHERE fk_product IN (select rowid FROM ".MAIN_DB_PREFIX."product where datec < '__DATE__')",
- "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur_price WHERE fk_product IN (select rowid FROM ".MAIN_DB_PREFIX."product where datec < '__DATE__')",
- "DELETE FROM ".MAIN_DB_PREFIX."product_batch WHERE fk_product_stock IN (select rowid FROM ".MAIN_DB_PREFIX."product_stock where fk_product IN (select rowid FROM ".MAIN_DB_PREFIX."product where datec < '__DATE__'))",
- "DELETE FROM ".MAIN_DB_PREFIX."product_stock WHERE fk_product IN (select rowid FROM ".MAIN_DB_PREFIX."product where datec < '__DATE__')",
- "DELETE FROM ".MAIN_DB_PREFIX."product_lot WHERE fk_product IN (select rowid FROM ".MAIN_DB_PREFIX."product where datec < '__DATE__')",
- "DELETE FROM ".MAIN_DB_PREFIX."product where datec < '__DATE__'",
- ),
- 'project'=>array(
- // TODO set fk_project to null on object that refer to project
- "DELETE FROM ".MAIN_DB_PREFIX."projet_task_time WHERE fk_task IN (select rowid FROM ".MAIN_DB_PREFIX."projet_task WHERE fk_projet IN (select rowid FROM ".MAIN_DB_PREFIX."projet where datec < '__DATE__'))",
- "DELETE FROM ".MAIN_DB_PREFIX."projet_task WHERE fk_projet IN (select rowid FROM ".MAIN_DB_PREFIX."projet where datec < '__DATE__')",
- "DELETE FROM ".MAIN_DB_PREFIX."projet where datec < '__DATE__'",
- ),
- 'contact'=>array(
- "DELETE FROM ".MAIN_DB_PREFIX."categorie_contact WHERE fk_socpeople IN (select rowid FROM ".MAIN_DB_PREFIX."socpeople where datec < '__DATE__')",
- "DELETE FROM ".MAIN_DB_PREFIX."socpeople where datec < '__DATE__'",
- ),
- 'thirdparty'=>array(
- '@contact',
- "DELETE FROM ".MAIN_DB_PREFIX."cabinetmed_cons WHERE fk_soc IN (select rowid FROM ".MAIN_DB_PREFIX."societe where datec < '__DATE__')",
- "UPDATE ".MAIN_DB_PREFIX."adherent SET fk_soc = NULL WHERE fk_soc IN (select rowid FROM ".MAIN_DB_PREFIX."societe where datec < '__DATE__')",
- "DELETE FROM ".MAIN_DB_PREFIX."categorie_fournisseur WHERE fk_soc IN (select rowid FROM ".MAIN_DB_PREFIX."societe where datec < '__DATE__')",
- "DELETE FROM ".MAIN_DB_PREFIX."categorie_societe WHERE fk_soc IN (select rowid FROM ".MAIN_DB_PREFIX."societe where datec < '__DATE__')",
- "DELETE FROM ".MAIN_DB_PREFIX."societe_remise_except WHERE fk_soc IN (select rowid FROM ".MAIN_DB_PREFIX."societe where datec < '__DATE__')",
- "DELETE FROM ".MAIN_DB_PREFIX."societe_rib WHERE fk_soc IN (select rowid FROM ".MAIN_DB_PREFIX."societe where datec < '__DATE__')",
- "DELETE FROM ".MAIN_DB_PREFIX."societe where datec < '__DATE__'",
- )
+ "DELETE FROM ".MAIN_DB_PREFIX."facture_fourn_det WHERE fk_facture_fourn IN (select rowid FROM ".MAIN_DB_PREFIX."facture_fourn where datec < '__DATE__')",
+ "DELETE FROM ".MAIN_DB_PREFIX."facture_fourn where datec < '__DATE__'",
+ ),
+ 'shipment'=>array(
+ '@delivery',
+ "DELETE FROM ".MAIN_DB_PREFIX."expeditiondet_batch WHERE fk_expeditiondet IN (select rowid FROM ".MAIN_DB_PREFIX."expeditiondet WHERE fk_expedition IN (select rowid FROM ".MAIN_DB_PREFIX."expedition where date_creation < '__DATE__'))",
+ "DELETE FROM ".MAIN_DB_PREFIX."expeditiondet_extrafields WHERE fk_object IN (select rowid FROM ".MAIN_DB_PREFIX."expeditiondet WHERE fk_expedition IN (select rowid FROM ".MAIN_DB_PREFIX."expedition where date_creation < '__DATE__'))",
+ "DELETE FROM ".MAIN_DB_PREFIX."expeditiondet WHERE fk_expedition IN (select rowid FROM ".MAIN_DB_PREFIX."expedition where date_creation < '__DATE__')",
+ "DELETE FROM ".MAIN_DB_PREFIX."expedition_extrafields WHERE fk_object IN (select rowid FROM ".MAIN_DB_PREFIX."expedition where date_creation < '__DATE__')",
+ "DELETE FROM ".MAIN_DB_PREFIX."expedition where date_creation < '__DATE__'",
+ ),
+ 'delivery'=>array(
+ "DELETE FROM ".MAIN_DB_PREFIX."deliverydet WHERE fk_delivery IN (select rowid FROM ".MAIN_DB_PREFIX."delivery where date_creation < '__DATE__')",
+ "DELETE FROM ".MAIN_DB_PREFIX."delivery where date_creation < '__DATE__'",
+ ),
+ 'contract'=>array(
+ "DELETE FROM ".MAIN_DB_PREFIX."contratdet_extrafields WHERE fk_object IN (select rowid FROM ".MAIN_DB_PREFIX."contratdet WHERE fk_contrat IN (select rowid FROM ".MAIN_DB_PREFIX."contrat where datec < '__DATE__'))",
+ "DELETE FROM ".MAIN_DB_PREFIX."contratdet WHERE fk_contrat IN (select rowid FROM ".MAIN_DB_PREFIX."contrat where datec < '__DATE__')",
+ "DELETE FROM ".MAIN_DB_PREFIX."contrat_extrafields WHERE fk_object IN (select rowid FROM ".MAIN_DB_PREFIX."contrat where datec < '__DATE__')",
+ "DELETE FROM ".MAIN_DB_PREFIX."contrat WHERE datec < '__DATE__'",
+ ),
+ 'intervention'=>array(
+ "DELETE FROM ".MAIN_DB_PREFIX."fichinterdet WHERE fk_fichinter IN (select rowid FROM ".MAIN_DB_PREFIX."fichinter where datec < '__DATE__')",
+ "DELETE FROM ".MAIN_DB_PREFIX."fichinter where datec < '__DATE__'",
+ ),
+ 'stock'=>array(
+ "DELETE FROM ".MAIN_DB_PREFIX."stock_mouvement WHERE datem < '__DATE__'",
+ ),
+ 'product'=>array(
+ "DELETE FROM ".MAIN_DB_PREFIX."categorie_product WHERE fk_product IN (select rowid FROM ".MAIN_DB_PREFIX."product where datec < '__DATE__')",
+ "DELETE FROM ".MAIN_DB_PREFIX."product_lang WHERE fk_product IN (select rowid FROM ".MAIN_DB_PREFIX."product where datec < '__DATE__')",
+ "DELETE FROM ".MAIN_DB_PREFIX."product_price_by_qty WHERE fk_product_price IN (select rowid FROM ".MAIN_DB_PREFIX."product_price where fk_product IN (select rowid FROM ".MAIN_DB_PREFIX."product where datec < '__DATE__'))",
+ "DELETE FROM ".MAIN_DB_PREFIX."product_price WHERE fk_product IN (select rowid FROM ".MAIN_DB_PREFIX."product where datec < '__DATE__')",
+ "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur_price WHERE fk_product IN (select rowid FROM ".MAIN_DB_PREFIX."product where datec < '__DATE__')",
+ "DELETE FROM ".MAIN_DB_PREFIX."product_batch WHERE fk_product_stock IN (select rowid FROM ".MAIN_DB_PREFIX."product_stock where fk_product IN (select rowid FROM ".MAIN_DB_PREFIX."product where datec < '__DATE__'))",
+ "DELETE FROM ".MAIN_DB_PREFIX."product_stock WHERE fk_product IN (select rowid FROM ".MAIN_DB_PREFIX."product where datec < '__DATE__')",
+ "DELETE FROM ".MAIN_DB_PREFIX."product_lot WHERE fk_product IN (select rowid FROM ".MAIN_DB_PREFIX."product where datec < '__DATE__')",
+ "DELETE FROM ".MAIN_DB_PREFIX."product where datec < '__DATE__'",
+ ),
+ 'project'=>array(
+ // TODO set fk_project to null on object that refer to project
+ "DELETE FROM ".MAIN_DB_PREFIX."projet_task_time WHERE fk_task IN (select rowid FROM ".MAIN_DB_PREFIX."projet_task WHERE fk_projet IN (select rowid FROM ".MAIN_DB_PREFIX."projet where datec < '__DATE__'))",
+ "DELETE FROM ".MAIN_DB_PREFIX."projet_task WHERE fk_projet IN (select rowid FROM ".MAIN_DB_PREFIX."projet where datec < '__DATE__')",
+ "DELETE FROM ".MAIN_DB_PREFIX."projet where datec < '__DATE__'",
+ ),
+ 'contact'=>array(
+ "DELETE FROM ".MAIN_DB_PREFIX."categorie_contact WHERE fk_socpeople IN (select rowid FROM ".MAIN_DB_PREFIX."socpeople where datec < '__DATE__')",
+ "DELETE FROM ".MAIN_DB_PREFIX."socpeople where datec < '__DATE__'",
+ ),
+ 'thirdparty'=>array(
+ '@contact',
+ "DELETE FROM ".MAIN_DB_PREFIX."cabinetmed_cons WHERE fk_soc IN (select rowid FROM ".MAIN_DB_PREFIX."societe where datec < '__DATE__')",
+ "UPDATE ".MAIN_DB_PREFIX."adherent SET fk_soc = NULL WHERE fk_soc IN (select rowid FROM ".MAIN_DB_PREFIX."societe where datec < '__DATE__')",
+ "DELETE FROM ".MAIN_DB_PREFIX."categorie_fournisseur WHERE fk_soc IN (select rowid FROM ".MAIN_DB_PREFIX."societe where datec < '__DATE__')",
+ "DELETE FROM ".MAIN_DB_PREFIX."categorie_societe WHERE fk_soc IN (select rowid FROM ".MAIN_DB_PREFIX."societe where datec < '__DATE__')",
+ "DELETE FROM ".MAIN_DB_PREFIX."societe_remise_except WHERE fk_soc IN (select rowid FROM ".MAIN_DB_PREFIX."societe where datec < '__DATE__')",
+ "DELETE FROM ".MAIN_DB_PREFIX."societe_rib WHERE fk_soc IN (select rowid FROM ".MAIN_DB_PREFIX."societe where datec < '__DATE__')",
+ "DELETE FROM ".MAIN_DB_PREFIX."societe where datec < '__DATE__'",
+ )
);
@@ -183,44 +183,42 @@ $option = $argv[2];
$date = $argv[3];
if (empty($mode) || ! in_array($mode, array('test','confirm'))) {
- print "Usage: $script_file (test|confirm) (all|option) (all|YYYY-MM-DD) [dbtype dbhost dbuser dbpassword dbname dbport]\n";
- print "\n";
- print "option can be ".implode(',', array_keys($sqls))."\n";
- exit(-1);
+ print "Usage: $script_file (test|confirm) (all|option) (all|YYYY-MM-DD) [dbtype dbhost dbuser dbpassword dbname dbport]\n";
+ print "\n";
+ print "option can be ".implode(',', array_keys($sqls))."\n";
+ exit(-1);
}
-if (empty($option))
-{
- print "Usage: $script_file (test|confirm) (all|option) (all|YYYY-MM-DD) [dbtype dbhost dbuser dbpassword dbname dbport]\n";
- print "\n";
- print "option must be defined with a value in list ".implode(',', array_keys($sqls))."\n";
- exit(-1);
+if (empty($option)) {
+ print "Usage: $script_file (test|confirm) (all|option) (all|YYYY-MM-DD) [dbtype dbhost dbuser dbpassword dbname dbport]\n";
+ print "\n";
+ print "option must be defined with a value in list ".implode(',', array_keys($sqls))."\n";
+ exit(-1);
}
-if ($option != 'all')
-{
- $listofoptions=explode(',', $option);
- foreach ($listofoptions as $cursoroption)
- {
- if (! in_array($cursoroption, array_keys($sqls))) {
- print "Usage: $script_file (test|confirm) (all|option) (all|YYYY-MM-DD) [dbtype dbhost dbuser dbpassword dbname dbport]\n";
- print "\n";
- print "option '".$cursoroption."' must be in list ".implode(',', array_keys($sqls))."\n";
- exit(-1);
- }
- }
+if ($option != 'all') {
+ $listofoptions=explode(',', $option);
+ foreach ($listofoptions as $cursoroption) {
+ if (! in_array($cursoroption, array_keys($sqls))) {
+ print "Usage: $script_file (test|confirm) (all|option) (all|YYYY-MM-DD) [dbtype dbhost dbuser dbpassword dbname dbport]\n";
+ print "\n";
+ print "option '".$cursoroption."' must be in list ".implode(',', array_keys($sqls))."\n";
+ exit(-1);
+ }
+ }
}
if (empty($date) || (! preg_match('/\d\d\d\d\-\d\d\-\d\d$/', $date) && $date != 'all')) {
- print "Usage: $script_file (test|confirm) (all|option) (all|YYYY-MM-DD) [dbtype dbhost dbuser dbpassword dbname dbport]\n";
- print "\n";
- print "date can be 'all' or 'YYYY-MM-DD' to delete record before YYYY-MM-DD\n";
- exit(-1);
+ print "Usage: $script_file (test|confirm) (all|option) (all|YYYY-MM-DD) [dbtype dbhost dbuser dbpassword dbname dbport]\n";
+ print "\n";
+ print "date can be 'all' or 'YYYY-MM-DD' to delete record before YYYY-MM-DD\n";
+ exit(-1);
}
-if ($date == 'all') $date = '2199-01-01';
+if ($date == 'all') {
+ $date = '2199-01-01';
+}
// Replace database handler
-if (! empty($argv[4]))
-{
+if (! empty($argv[4])) {
$db->close();
unset($db);
$db=getDoliDBInstance($argv[4], $argv[5], $argv[6], $argv[7], $argv[8], $argv[9]);
@@ -229,8 +227,7 @@ if (! empty($argv[4]))
//var_dump($user->db->database_name);
$ret=$user->fetch('', 'admin');
-if (! $ret > 0)
-{
+if (! $ret > 0) {
print 'An admin user with login "admin" must exists to use this script.'."\n";
exit;
}
@@ -245,10 +242,9 @@ print "Database port = ".$db->database_port."\n";
print "User = ".$db->database_user."\n";
print "\n";
-if (! $confirmed)
-{
- print "Hit Enter to continue or CTRL+C to stop...\n";
- $input = trim(fgets(STDIN));
+if (! $confirmed) {
+ print "Hit Enter to continue or CTRL+C to stop...\n";
+ $input = trim(fgets(STDIN));
}
@@ -261,73 +257,71 @@ if (! $confirmed)
*/
function processfamily($family, $date)
{
- global $db, $sqls;
+ global $db, $sqls;
- $error=0;
- foreach ($sqls[$family] as $sql)
- {
- if (preg_match('/^@/', $sql))
- {
- $newfamily=preg_replace('/@/', '', $sql);
- processfamily($newfamily, $date);
- continue;
- }
+ $error=0;
+ foreach ($sqls[$family] as $sql) {
+ if (preg_match('/^@/', $sql)) {
+ $newfamily=preg_replace('/@/', '', $sql);
+ processfamily($newfamily, $date);
+ continue;
+ }
- $sql = preg_replace('/__DATE__/', $date, $sql);
+ $sql = preg_replace('/__DATE__/', $date, $sql);
- print "Run sql: ".$sql."\n";
+ print "Run sql: ".$sql."\n";
- $resql=$db->query($sql);
- if (! $resql)
- {
- if ($db->errno() != 'DB_ERROR_NOSUCHTABLE')
- {
- $error++;
- }
- }
+ $resql=$db->query($sql);
+ if (! $resql) {
+ if ($db->errno() != 'DB_ERROR_NOSUCHTABLE') {
+ $error++;
+ }
+ }
- if ($error)
- {
- print $db->lasterror();
- $error++;
- break;
- }
- }
+ if ($error) {
+ print $db->lasterror();
+ $error++;
+ break;
+ }
+ }
- if ($error) return -1;
- else return 1;
+ if ($error) {
+ return -1;
+ } else {
+ return 1;
+ }
}
$db->begin();
$listofoptions=explode(',', $option);
-foreach ($listofoptions as $cursoroption)
-{
- $oldfamily='';
- foreach ($sqls as $family => $familysql)
- {
- if ($cursoroption && $cursoroption != 'all' && $cursoroption != $family) continue;
+foreach ($listofoptions as $cursoroption) {
+ $oldfamily='';
+ foreach ($sqls as $family => $familysql) {
+ if ($cursoroption && $cursoroption != 'all' && $cursoroption != $family) {
+ continue;
+ }
- if ($family != $oldfamily) print "Process action for family ".$family."\n";
- $oldfamily = $family;
+ if ($family != $oldfamily) {
+ print "Process action for family ".$family."\n";
+ }
+ $oldfamily = $family;
- $result=processfamily($family, $date);
- if ($result < 0)
- {
- $error++;
- break;
- }
- }
+ $result=processfamily($family, $date);
+ if ($result < 0) {
+ $error++;
+ break;
+ }
+ }
}
-if ($error || $mode != 'confirm')
-{
- print "\nRollback any changes.\n";
- $db->rollback();
+if ($error || $mode != 'confirm') {
+ print "\nRollback any changes.\n";
+ $db->rollback();
} else {
- print "Commit all changes.\n";
- $db->commit();
+ print "Commit all changes.\n";
+ $db->commit();
}
$db->close();
diff --git a/dev/initdemo/sftpget_and_loaddump.php b/dev/initdemo/sftpget_and_loaddump.php
index 4da5ffaad58..7d781fe5b0c 100755
--- a/dev/initdemo/sftpget_and_loaddump.php
+++ b/dev/initdemo/sftpget_and_loaddump.php
@@ -41,14 +41,30 @@ $passwordbase=isset($argv[6])?$argv[6]:'';
// Include Dolibarr environment
$res=0;
-if (! $res && file_exists($path."../../master.inc.php")) $res=@include $path."../../master.inc.php";
-if (! $res && file_exists($path."../../htdocs/master.inc.php")) $res=@include $path."../../htdocs/master.inc.php";
-if (! $res && file_exists("../master.inc.php")) $res=@include "../master.inc.php";
-if (! $res && file_exists("../../master.inc.php")) $res=@include "../../master.inc.php";
-if (! $res && file_exists("../../../master.inc.php")) $res=@include "../../../master.inc.php";
-if (! $res && preg_match('/\/nltechno([^\/]*)\//', $_SERVER["PHP_SELF"], $reg)) $res=@include $path."../../../dolibarr".$reg[1]."/htdocs/master.inc.php"; // Used on dev env only
-if (! $res && preg_match('/\/nltechno([^\/]*)\//', $_SERVER["PHP_SELF"], $reg)) $res=@include "../../../dolibarr".$reg[1]."/htdocs/master.inc.php"; // Used on dev env only
-if (! $res) die("Failed to include master.inc.php file\n");
+if (! $res && file_exists($path."../../master.inc.php")) {
+ $res=@include $path."../../master.inc.php";
+}
+if (! $res && file_exists($path."../../htdocs/master.inc.php")) {
+ $res=@include $path."../../htdocs/master.inc.php";
+}
+if (! $res && file_exists("../master.inc.php")) {
+ $res=@include "../master.inc.php";
+}
+if (! $res && file_exists("../../master.inc.php")) {
+ $res=@include "../../master.inc.php";
+}
+if (! $res && file_exists("../../../master.inc.php")) {
+ $res=@include "../../../master.inc.php";
+}
+if (! $res && preg_match('/\/nltechno([^\/]*)\//', $_SERVER["PHP_SELF"], $reg)) {
+ $res=@include $path."../../../dolibarr".$reg[1]."/htdocs/master.inc.php"; // Used on dev env only
+}
+if (! $res && preg_match('/\/nltechno([^\/]*)\//', $_SERVER["PHP_SELF"], $reg)) {
+ $res=@include "../../../dolibarr".$reg[1]."/htdocs/master.inc.php"; // Used on dev env only
+}
+if (! $res) {
+ die("Failed to include master.inc.php file\n");
+}
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
@@ -58,15 +74,13 @@ include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
$login='';
$server='';
-if (preg_match('/^(.*)@(.*):(.*)$/', $sourceserver, $reg))
-{
+if (preg_match('/^(.*)@(.*):(.*)$/', $sourceserver, $reg)) {
$login=$reg[1];
$server=$reg[2];
$sourcefile=$reg[3];
$targetfile=basename($sourcefile);
}
-if (empty($sourceserver) || empty($server) || empty($login) || empty($sourcefile) || empty($password) || empty($database) || empty($loginbase) || empty($passwordbase))
-{
+if (empty($sourceserver) || empty($server) || empty($login) || empty($sourcefile) || empty($password) || empty($database) || empty($loginbase) || empty($passwordbase)) {
print "Usage: $script_file login@server:/src/file.(sql|gz|bz2) passssh databaseserver databasename loginbase passbase\n";
print "Return code: 0 if success, <>0 if error\n";
print "Warning, this script may take a long time.\n";
@@ -88,14 +102,11 @@ if (! function_exists("ssh2_connect")) {
}
$connection = ssh2_connect($server, 22);
-if ($connection)
-{
- if (! @ssh2_auth_password($connection, $login, $password))
- {
+if ($connection) {
+ if (! @ssh2_auth_password($connection, $login, $password)) {
dol_syslog("Could not authenticate with username ".$login." . and password ".preg_replace('/./', '*', $password), LOG_ERR);
exit(-5);
- }
- else {
+ } else {
//$stream = ssh2_exec($connection, '/usr/bin/php -i');
/*
print "Generate dump ".$filesys1.'.bz2'."\n";
@@ -111,12 +122,10 @@ if ($connection)
ssh2_scp_recv($connection, $sourcefile, $targetdir.$targetfile);
$fullcommand="cat ".$targetdir.$targetfile." | mysql -h".$databaseserver." -u".$loginbase." -p".$passwordbase." -D ".$database;
- if (preg_match('/\.bz2$/', $targetfile))
- {
+ if (preg_match('/\.bz2$/', $targetfile)) {
$fullcommand="bzip2 -c -d ".$targetdir.$targetfile." | mysql -h".$databaseserver." -u".$loginbase." -p".$passwordbase." -D ".$database;
}
- if (preg_match('/\.gz$/', $targetfile))
- {
+ if (preg_match('/\.gz$/', $targetfile)) {
$fullcommand="gzip -d ".$targetdir.$targetfile." | mysql -h".$databaseserver." -u".$loginbase." -p".$passwordbase." -D ".$database;
}
print "Load dump with ".$fullcommand."\n";
@@ -124,13 +133,14 @@ if ($connection)
$return_var=0;
print strftime("%Y%m%d-%H%M%S").' '.$fullcommand."\n";
exec($fullcommand, $output, $return_var);
- foreach ($output as $line) print $line."\n";
+ foreach ($output as $line) {
+ print $line."\n";
+ }
//ssh2_sftp_unlink($sftp, $fileinstalllock);
//print $output;
}
-}
-else {
+} else {
print 'Failed to connect to ssh2 to '.$server;
exit(-6);
}
diff --git a/dev/initdemo/updatedemo.php b/dev/initdemo/updatedemo.php
index 5da0d4a2498..4dd98451823 100755
--- a/dev/initdemo/updatedemo.php
+++ b/dev/initdemo/updatedemo.php
@@ -36,14 +36,30 @@ $confirm=isset($argv[1])?$argv[1]:'';
// Include Dolibarr environment
$res=0;
-if (! $res && file_exists($path."../../master.inc.php")) $res=@include $path."../../master.inc.php";
-if (! $res && file_exists($path."../../htdocs/master.inc.php")) $res=@include $path."../../htdocs/master.inc.php";
-if (! $res && file_exists("../master.inc.php")) $res=@include "../master.inc.php";
-if (! $res && file_exists("../../master.inc.php")) $res=@include "../../master.inc.php";
-if (! $res && file_exists("../../../master.inc.php")) $res=@include "../../../master.inc.php";
-if (! $res && preg_match('/\/nltechno([^\/]*)\//', $_SERVER["PHP_SELF"], $reg)) $res=@include $path."../../../dolibarr".$reg[1]."/htdocs/master.inc.php"; // Used on dev env only
-if (! $res && preg_match('/\/nltechno([^\/]*)\//', $_SERVER["PHP_SELF"], $reg)) $res=@include "../../../dolibarr".$reg[1]."/htdocs/master.inc.php"; // Used on dev env only
-if (! $res) die("Failed to include master.inc.php file\n");
+if (! $res && file_exists($path."../../master.inc.php")) {
+ $res=@include $path."../../master.inc.php";
+}
+if (! $res && file_exists($path."../../htdocs/master.inc.php")) {
+ $res=@include $path."../../htdocs/master.inc.php";
+}
+if (! $res && file_exists("../master.inc.php")) {
+ $res=@include "../master.inc.php";
+}
+if (! $res && file_exists("../../master.inc.php")) {
+ $res=@include "../../master.inc.php";
+}
+if (! $res && file_exists("../../../master.inc.php")) {
+ $res=@include "../../../master.inc.php";
+}
+if (! $res && preg_match('/\/nltechno([^\/]*)\//', $_SERVER["PHP_SELF"], $reg)) {
+ $res=@include $path."../../../dolibarr".$reg[1]."/htdocs/master.inc.php"; // Used on dev env only
+}
+if (! $res && preg_match('/\/nltechno([^\/]*)\//', $_SERVER["PHP_SELF"], $reg)) {
+ $res=@include "../../../dolibarr".$reg[1]."/htdocs/master.inc.php"; // Used on dev env only
+}
+if (! $res) {
+ die("Failed to include master.inc.php file\n");
+}
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
@@ -53,8 +69,7 @@ include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
print "***** ".$script_file." *****\n";
print "Update dates to current year for database name = ".$db->database_name."\n";
-if (empty($confirm))
-{
+if (empty($confirm)) {
print "Usage: $script_file confirm\n";
print "Return code: 0 if success, <>0 if error\n";
exit(-1);
@@ -65,66 +80,65 @@ $tmp=dol_getdate(dol_now());
$tables=array(
- 'propal'=>array(0=>'datep', 1=>'fin_validite', 2=>'date_valid', 3=>'date_cloture'),
- 'commande'=>array(0=>'date_commande', 1=>'date_valid', 2=>'date_cloture'),
+ 'propal'=>array(0=>'datep', 1=>'fin_validite', 2=>'date_valid', 3=>'date_cloture'),
+ 'commande'=>array(0=>'date_commande', 1=>'date_valid', 2=>'date_cloture'),
'facture'=>array(0=>'datec', 0=>'datef', 1=>'date_valid', 2=>'date_lim_reglement'),
- 'paiement'=>array(0=>'datep'),
- 'bank'=>array(0=>'datev', 1=>'dateo'),
- 'commande_fournisseur'=>array(0=>'date_commande', 1=>'date_valid', 3=>'date_creation', 4=>'date_approve', 5=>'date_approve2', 6=>'date_livraison'),
- 'supplier_proposal'=>array(0=>'datec', 1=>'date_valid', 2=>'date_cloture'),
+ 'paiement'=>array(0=>'datep'),
+ 'bank'=>array(0=>'datev', 1=>'dateo'),
+ 'commande_fournisseur'=>array(0=>'date_commande', 1=>'date_valid', 3=>'date_creation', 4=>'date_approve', 5=>'date_approve2', 6=>'date_livraison'),
+ 'supplier_proposal'=>array(0=>'datec', 1=>'date_valid', 2=>'date_cloture'),
'expensereport'=>array(0=>'date_debut', 1=>'date_fin', 2=>'date_create', 3=>'date_valid', 4=>'date_approve', 5=>'date_refuse', 6=>'date_cancel'),
- 'holiday'=>array(0=>'date_debut', 1=>'date_fin', 2=>'date_create', 3=>'date_valid', 5=>'date_refuse', 6=>'date_cancel')
+ 'holiday'=>array(0=>'date_debut', 1=>'date_fin', 2=>'date_create', 3=>'date_valid', 5=>'date_refuse', 6=>'date_cancel'),
+ 'ticket'=>array(0=>'datec', 1=>'date_read', 2=>'date_close')
);
$year=2010;
$currentyear=$tmp['year'];
-while ($year <= $currentyear)
-{
- //$year=2021;
- $delta1=($currentyear - $year);
- $delta2=($currentyear - $year - 1);
- //$delta=-1;
+while ($year <= $currentyear) {
+ //$year=2021;
+ $delta1=($currentyear - $year);
+ $delta2=($currentyear - $year - 1);
+ //$delta=-1;
- if ($delta1)
- {
- foreach ($tables as $tablekey => $tableval)
- {
- print "Correct ".$tablekey." for year ".$year." and move them to current year ".$currentyear." ";
- $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)";
- //$sql="select rowid from ".MAIN_DB_PREFIX.$tablekey." where ".$tableval[0]." between '".$year."-01-01' and '".$year."-12-31' and ".$tableval[0]." > NOW()";
- $resql = $db->query($sql);
- if ($resql)
- {
- $num = $db->num_rows($resql);
- $i=0;
- while ($i < $num)
- {
- $obj=$db->fetch_object($resql);
- if ($obj)
- {
- print ".";
- $sql2="UPDATE ".MAIN_DB_PREFIX.$tablekey." set ";
- $j=0;
- foreach ($tableval as $field)
- {
- if ($j) $sql2.=", ";
- $sql2.= $field." = ".$db->ifsql("DATE_ADD(".$field.", INTERVAL ".$delta1." YEAR) > NOW()", "DATE_ADD(".$field.", INTERVAL ".$delta2." YEAR)", "DATE_ADD(".$field.", INTERVAL ".$delta1." YEAR)");
- $j++;
- }
- $sql2.=" WHERE rowid = ".$obj->rowid;
- //print $sql2."\n";
- $resql2 = $db->query($sql2);
- if (! $resql2) dol_print_error($db);
- }
- $i++;
- }
- }
- else dol_print_error($db);
- print "\n";
- }
- }
+ if ($delta1) {
+ foreach ($tables as $tablekey => $tableval) {
+ print "Correct ".$tablekey." for year ".$year." and move them to current year ".$currentyear." ";
+ $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)";
+ //$sql="select rowid from ".MAIN_DB_PREFIX.$tablekey." where ".$tableval[0]." between '".$year."-01-01' and '".$year."-12-31' and ".$tableval[0]." > NOW()";
+ $resql = $db->query($sql);
+ if ($resql) {
+ $num = $db->num_rows($resql);
+ $i=0;
+ while ($i < $num) {
+ $obj=$db->fetch_object($resql);
+ if ($obj) {
+ print ".";
+ $sql2="UPDATE ".MAIN_DB_PREFIX.$tablekey." set ";
+ $j=0;
+ foreach ($tableval as $field) {
+ if ($j) {
+ $sql2.=", ";
+ }
+ $sql2.= $field." = ".$db->ifsql("DATE_ADD(".$field.", INTERVAL ".$delta1." YEAR) > NOW()", "DATE_ADD(".$field.", INTERVAL ".$delta2." YEAR)", "DATE_ADD(".$field.", INTERVAL ".$delta1." YEAR)");
+ $j++;
+ }
+ $sql2.=" WHERE rowid = ".$obj->rowid;
+ //print $sql2."\n";
+ $resql2 = $db->query($sql2);
+ if (! $resql2) {
+ dol_print_error($db);
+ }
+ }
+ $i++;
+ }
+ } else {
+ dol_print_error($db);
+ }
+ print "\n";
+ }
+ }
- $year++;
+ $year++;
}
print "\n";
diff --git a/dev/setup/codesniffer/ruleset.xml b/dev/setup/codesniffer/ruleset.xml
index db4945a654c..e99b8673981 100644
--- a/dev/setup/codesniffer/ruleset.xml
+++ b/dev/setup/codesniffer/ruleset.xml
@@ -7,7 +7,7 @@
build/htmlbuild/apsdev/tools/test/namespacemig
- dev/initdata/dbf/includes
+
documentshtdocs/core/class/lessc.class.phphtdocs/custom
@@ -104,9 +104,9 @@
-->
-
+
@@ -174,8 +174,8 @@
-
-
+
+
@@ -214,8 +214,8 @@
-
-
+
+
diff --git a/dev/setup/git/hooks/pre-commit b/dev/setup/git/hooks/pre-commit
new file mode 100644
index 00000000000..51b7c5cf4e9
--- /dev/null
+++ b/dev/setup/git/hooks/pre-commit
@@ -0,0 +1,73 @@
+#!/bin/sh
+# To install this precommit file: put this file in your local repo in .git/hooks directory and make it executable.
+# You may need to set th DIRPHPCS to the path to your phpcs install.
+# If phpcs check fail and AUTOFIX is set to 1, then it run phpcbf to fix automaticaly the syntax, and git commit is canceled.
+# If you have a multiprocessor computer, you can add to the option --parallel=xx
+# When running git commit, it first execute this file checking only modified files, so it is faster than running on all files
+# To run the fix manually: cd ~/git/dolibarr; phpcbf -s -p -d memory_limit=-1 --extensions=php --colors --tab-width=4 --standard=dev/setup/codesniffer/ruleset.xml --encoding=utf-8 --runtime-set ignore_warnings_on_exit true "fileordir"
+
+PROJECT=`php -r "echo dirname(dirname(dirname(realpath('$0'))));"`
+STAGED_FILES_CMD=`git diff --cached --name-only --diff-filter=ACMR HEAD | grep \\\\.php`
+DIRPHPCS=""
+AUTOFIX=1
+
+echo "Running precommit hook in .git/hooks/pre-commit" 1>&2;
+
+# Determine if a file list is passed
+if [ "$#" -eq 1 ]
+then
+ oIFS=$IFS
+ IFS='
+ '
+ SFILES="$1"
+ IFS=$oIFS
+fi
+SFILES=${SFILES:-$STAGED_FILES_CMD}
+
+echo "Checking PHP Lint with php -l ..."
+
+for FILE in $SFILES
+do
+ php -l -d display_errors=0 $PROJECT/$FILE
+
+ result1=$?
+
+ if [ "x$result1" != "x0" ]
+ then
+ echo "Fix the error before commit." 1>&2;
+ exit 1
+ fi
+ FILES="$FILES $PROJECT/$FILE"
+done
+
+
+if [ "$FILES" != "" ]
+then
+ echo "Running PHPCS Code Sniffer..."
+
+ #~/vendor/bin/phpcs --version
+ #phpcs --standard=PSR2 --encoding=utf-8 -n -p $FILES
+ # Check Dolibarr standard
+ ${DIRPHPCS}phpcs -s -p -d memory_limit=-1 --parallel=2 --extensions=php --colors --tab-width=4 --standard=dev/setup/codesniffer/ruleset.xml --encoding=utf-8 --runtime-set ignore_warnings_on_exit true $FILES
+ # Check your own standard
+ #${DIRPHPCS}phpcs -s -p -d memory_limit=-1 --parallel=2 --extensions=php --colors --tab-width=4 --standard=htdocs/custom/codesniffer/ruleset.xml --encoding=utf-8 --runtime-set ignore_warnings_on_exit true $FILES
+
+ result2=$?
+
+ if [ "x$result2" != "x0" ]
+ then
+ # Fix standard errors
+ if [ "x$AUTOFIX" != "x0" ]
+ then
+ ${DIRPHPCS}phpcbf -s -p -d memory_limit=-1 --extensions=php --colors --tab-width=4 --standard=dev/setup/codesniffer/ruleset.xml --encoding=utf-8 --runtime-set ignore_warnings_on_exit true $FILES
+ #${DIRPHPCS}phpcbf -s -p -d memory_limit=-1 --extensions=php --colors --tab-width=4 --standard=htdocs/custom/codesniffer/ruleset.xml --encoding=utf-8 --runtime-set ignore_warnings_on_exit true $FILES
+ echo "Found some errors in syntax rules. An automatic fix has been applied. Check it before commit." 1>&2;
+ exit 1
+ else
+ echo "Found some errors in syntax rules. Fix the error(s) before commit." 1>&2;
+ exit 1
+ fi
+ fi
+fi
+
+exit 0
diff --git a/dev/tools/dolibarr-postgres2mysql.php b/dev/tools/dolibarr-postgres2mysql.php
index fd30540c019..1a997ddc63c 100644
--- a/dev/tools/dolibarr-postgres2mysql.php
+++ b/dev/tools/dolibarr-postgres2mysql.php
@@ -48,8 +48,9 @@ if (! ($argv[1] && $argv[2])) {
echo "Usage: php pg2mysql_cli.php [engine]\n";
exit();
} else {
- if (isset($argv[3]))
+ if (isset($argv[3])) {
$config['engine'] = $argv[3];
+ }
pg2mysql_large($argv[1], $argv[2]);
echo <<SetKeywords('TCPDF, PDF, example, test, guide');
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 016', PDF_HEADER_STRING);
// set header and footer fonts
-$pdf->setHeaderFont(Array('helvetica', '', PDF_FONT_SIZE_MAIN));
-$pdf->setFooterFont(Array('helvetica', '', PDF_FONT_SIZE_DATA));
+$pdf->setHeaderFont(array('helvetica', '', PDF_FONT_SIZE_MAIN));
+$pdf->setFooterFont(array('helvetica', '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
diff --git a/dev/tools/test/testutf.php b/dev/tools/test/testutf.php
index b981257ccb7..9ce8d6a7583 100644
--- a/dev/tools/test/testutf.php
+++ b/dev/tools/test/testutf.php
@@ -64,8 +64,8 @@ $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
$pdf->SetHeaderData('', PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 038', PDF_HEADER_STRING);
// set header and footer fonts
-$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
-$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
+$pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
+$pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
diff --git a/dev/translation/autotranslator.class.php b/dev/translation/autotranslator.class.php
index b51515a42cb..956ad95b9b6 100644
--- a/dev/translation/autotranslator.class.php
+++ b/dev/translation/autotranslator.class.php
@@ -40,18 +40,18 @@ class autoTranslator
const DIR_SEPARATOR = '/';
- /**
- * Constructor
- *
- * @param string $_destlang Destination lang
- * @param string $_refLang Ref lang
- * @param string $_langDir Dir lang
- * @param string $_limittofile Limit to file
- * @param string $_apikey Api key
- * @return void
- */
- public function __construct($_destlang, $_refLang, $_langDir, $_limittofile, $_apikey)
- {
+ /**
+ * Constructor
+ *
+ * @param string $_destlang Destination lang
+ * @param string $_refLang Ref lang
+ * @param string $_langDir Dir lang
+ * @param string $_limittofile Limit to file
+ * @param string $_apikey Api key
+ * @return void
+ */
+ public function __construct($_destlang, $_refLang, $_langDir, $_limittofile, $_apikey)
+ {
// Set enviorment variables
$this->_destlang = $_destlang;
@@ -59,7 +59,7 @@ class autoTranslator
$this->_langDir = $_langDir.self::DIR_SEPARATOR;
$this->_time = date('Y-m-d H:i:s');
$this->_limittofile = $_limittofile;
- $this->_apikey = $_apikey;
+ $this->_apikey = $_apikey;
// Translate
//ini_set('default_charset','UTF-8');
@@ -77,9 +77,10 @@ class autoTranslator
$files = $this->getTranslationFilesArray($this->_refLang);
$counter = 1;
- foreach ($files as $file)
- {
- if ($this->_limittofile && $this->_limittofile != $file) continue;
+ foreach ($files as $file) {
+ if ($this->_limittofile && $this->_limittofile != $file) {
+ continue;
+ }
$counter++;
$fileContent = null;
$refPath = $this->_langDir.$this->_refLang.self::DIR_SEPARATOR.$file;
@@ -88,54 +89,66 @@ class autoTranslator
// Define target dirs
$targetlangs=array($this->_destlang);
- if ($this->_destlang == 'all')
- {
+ if ($this->_destlang == 'all') {
$targetlangs=array();
// If we must process all languages
$arraytmp=dol_dir_list($this->_langDir, 'directories', 0);
- foreach ($arraytmp as $dirtmp)
- {
- if ($dirtmp['name'] === $this->_refLang) continue; // We discard source language
+ foreach ($arraytmp as $dirtmp) {
+ if ($dirtmp['name'] === $this->_refLang) {
+ continue; // We discard source language
+ }
$tmppart=explode('_', $dirtmp['name']);
- if (preg_match('/^en/i', $dirtmp['name'])) continue; // We discard en_* languages
- if (preg_match('/^fr/i', $dirtmp['name'])) continue; // We discard fr_* languages
- if (preg_match('/^es/i', $dirtmp['name'])) continue; // We discard es_* languages
- if (preg_match('/ca_ES/i', $dirtmp['name'])) continue; // We discard es_CA language
- if (preg_match('/pt_BR/i', $dirtmp['name'])) continue; // We discard pt_BR language
- if (preg_match('/nl_BE/i', $dirtmp['name'])) continue; // We discard nl_BE language
- if (preg_match('/^\./i', $dirtmp['name'])) continue; // We discard files .*
- if (preg_match('/^CVS/i', $dirtmp['name'])) continue; // We discard CVS
+ if (preg_match('/^en/i', $dirtmp['name'])) {
+ continue; // We discard en_* languages
+ }
+ if (preg_match('/^fr/i', $dirtmp['name'])) {
+ continue; // We discard fr_* languages
+ }
+ if (preg_match('/^es/i', $dirtmp['name'])) {
+ continue; // We discard es_* languages
+ }
+ if (preg_match('/ca_ES/i', $dirtmp['name'])) {
+ continue; // We discard es_CA language
+ }
+ if (preg_match('/pt_BR/i', $dirtmp['name'])) {
+ continue; // We discard pt_BR language
+ }
+ if (preg_match('/nl_BE/i', $dirtmp['name'])) {
+ continue; // We discard nl_BE language
+ }
+ if (preg_match('/^\./i', $dirtmp['name'])) {
+ continue; // We discard files .*
+ }
+ if (preg_match('/^CVS/i', $dirtmp['name'])) {
+ continue; // We discard CVS
+ }
$targetlangs[]=$dirtmp['name'];
}
//var_dump($targetlangs);
}
// Process translation of source file for each target languages
- foreach ($targetlangs as $my_destlang)
- {
+ foreach ($targetlangs as $my_destlang) {
$this->_translatedFiles = array();
$destPath = $this->_langDir.$my_destlang.self::DIR_SEPARATOR.$file;
// Check destination file presence
- if (! file_exists($destPath))
- {
+ if (! file_exists($destPath)) {
// No file present, we generate file
echo "File not found: " . $destPath . ". We generate it. \n";
$this->createTranslationFile($destPath, $my_destlang);
- }
- else {
+ } else {
echo "Updating file: " . $destPath . " \n";
}
// Translate lines
$fileContentDest = file($destPath, FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
$newlines=0;
- foreach ($fileContent as $line){
+ foreach ($fileContent as $line) {
$key = $this->getLineKey($line);
$value = $this->getLineValue($line);
- if ($key && $value)
- {
+ if ($key && $value) {
$newlines+=$this->translateFileLine($fileContentDest, $file, $key, $value, $my_destlang);
}
}
@@ -159,8 +172,7 @@ class autoTranslator
{
$this->_time_end = date('Y-m-d H:i:s');
- if (isset($this->_translatedFiles[$file]) && count($this->_translatedFiles[$file])>0)
- {
+ if (isset($this->_translatedFiles[$file]) && count($this->_translatedFiles[$file])>0) {
$fp = fopen($destPath, 'a');
fwrite($fp, "\n");
fwrite($fp, "\n");
@@ -213,27 +225,31 @@ class autoTranslator
$destValue = $this->getLineValue($line);
// If translated return
//print "destKey=".$destKey."\n";
- if ( trim($destKey) == trim($key) )
- { // Found already existing translation (key already exits in dest file)
+ if (trim($destKey) == trim($key)) { // Found already existing translation (key already exits in dest file)
return 0;
}
}
if ($key == 'CHARSET') {
- $val=$this->_outputpagecode;
- } elseif (preg_match('/^Format/', $key)) {
- $val=$value;
- } elseif ($value=='-') {
- $val=$value;
- } else {
+ $val=$this->_outputpagecode;
+ } elseif (preg_match('/^Format/', $key)) {
+ $val=$value;
+ } elseif ($value=='-') {
+ $val=$value;
+ } else {
// If not translated then translate
- if ($this->_outputpagecode == 'UTF-8') $val=$this->translateTexts(array($value), substr($this->_refLang, 0, 2), substr($my_destlang, 0, 2));
- else $val=utf8_decode($this->translateTexts(array($value), substr($this->_refLang, 0, 2), substr($my_destlang, 0, 2)));
+ if ($this->_outputpagecode == 'UTF-8') {
+ $val=$this->translateTexts(array($value), substr($this->_refLang, 0, 2), substr($my_destlang, 0, 2));
+ } else {
+ $val=utf8_decode($this->translateTexts(array($value), substr($this->_refLang, 0, 2), substr($my_destlang, 0, 2)));
+ }
}
$val=trim($val);
- if (empty($val)) return 0;
+ if (empty($val)) {
+ return 0;
+ }
$this->_translatedFiles[$file][] = $key . '=' . $val ;
return 1;
@@ -293,9 +309,13 @@ class autoTranslator
{
// We want to be sure that src_lang and dest_lang are using 2 chars only
$tmp=explode('_', $src_lang);
- if (! empty($tmp[1]) && $tmp[0] == $tmp[1]) $src_lang=$tmp[0];
+ if (! empty($tmp[1]) && $tmp[0] == $tmp[1]) {
+ $src_lang=$tmp[0];
+ }
$tmp=explode('_', $dest_lang);
- if (! empty($tmp[1]) && $tmp[0] == $tmp[1]) $dest_lang=$tmp[0];
+ if (! empty($tmp[1]) && $tmp[0] == $tmp[1]) {
+ $dest_lang=$tmp[0];
+ }
//setting language pair
$lang_pair = $src_lang.'|'.$dest_lang;
@@ -306,17 +326,16 @@ class autoTranslator
// Define GET URL v1
//$url = "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=".urlencode($src_text_to_translate)."&langpair=".urlencode($lang_pair);
// Example: http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=Setup%20area&langpair=en_US|fr_FR
- // Define GET URL v2
+ // Define GET URL v2
$url = "https://www.googleapis.com/language/translate/v2?key=".$this->_apikey."&q=".urlencode($src_text_to_translate)."&source=".urlencode($src_lang)."&target=".urlencode($dest_lang);
// Example: https://www.googleapis.com/language/translate/v2?key=_apikey&q=Setup%20area&source=en_US&target=fr_FR
// Send request
//print "Url to translate: ".$url."\n";
- if (! function_exists("curl_init"))
- {
- print "Error, your PHP does not support curl functions.\n";
- die();
+ if (! function_exists("curl_init")) {
+ print "Error, your PHP does not support curl functions.\n";
+ die();
}
$ch = curl_init();
@@ -331,9 +350,8 @@ class autoTranslator
$json = json_decode($body, true);
if ((! empty($json['responseStatus']) && $json['responseStatus'] != 200)
- || count($json['data']['translations']) == 0)
- {
- print "Error: ".$json['responseStatus']." ".$url."\n";
+ || count($json['data']['translations']) == 0) {
+ print "Error: ".$json['responseStatus']." ".$url."\n";
return false;
}
@@ -345,5 +363,5 @@ class autoTranslator
//print "OK ".join('',$src_texts).' => '.$rep."\n";
return $rep;
- }
+ }
}
diff --git a/dev/translation/autotranslator.php b/dev/translation/autotranslator.php
index fd02febbdcc..a8f6565b891 100755
--- a/dev/translation/autotranslator.php
+++ b/dev/translation/autotranslator.php
@@ -32,8 +32,8 @@ $path=dirname(__FILE__).'/';
// Test if batch mode
if (substr($sapi_type, 0, 3) == 'cgi') {
- echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
- exit;
+ echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
+ exit;
}
// Include Dolibarr environment
@@ -56,10 +56,10 @@ $dir=DOL_DOCUMENT_ROOT."/langs";
// Check parameters
if (! isset($argv[3])) {
- print "Usage: ".$script_file." lang_code_src lang_code_dest|all APIKEY [langfile.lang]\n";
- print "Example: ".$script_file." en_US pt_PT 123456\n";
- print "Rem: lang_code to use can be found on https://translate.google.com\n";
- exit;
+ print "Usage: ".$script_file." lang_code_src lang_code_dest|all APIKEY [langfile.lang]\n";
+ print "Example: ".$script_file." en_US pt_PT 123456\n";
+ print "Rem: lang_code to use can be found on https://translate.google.com\n";
+ exit;
}
// Show parameters
@@ -67,21 +67,17 @@ print 'Argument 1='.$argv[1]."\n";
print 'Argument 2='.$argv[2]."\n";
print 'Argument 3='.$argv[3]."\n";
$file='';
-if (isset($argv[4]))
-{
+if (isset($argv[4])) {
$file=$argv[4];
print 'Argument 4='.$argv[4]."\n";
}
print 'Files will be generated/updated in directory '.$dir."\n";
-if ($argv[2] != 'all')
-{
- if (! is_dir($dir.'/'.$argv[2]))
- {
+if ($argv[2] != 'all') {
+ if (! is_dir($dir.'/'.$argv[2])) {
print 'Create directory '.$dir.'/'.$argv[2]."\n";
$result=mkdir($dir.'/'.$argv[2]);
- if (! $result)
- {
+ if (! $result) {
$db->close();
return -1;
}
diff --git a/dev/translation/sanity_check_en_langfiles.php b/dev/translation/sanity_check_en_langfiles.php
index 0268fc94ed8..39db0a55764 100755
--- a/dev/translation/sanity_check_en_langfiles.php
+++ b/dev/translation/sanity_check_en_langfiles.php
@@ -25,18 +25,16 @@ $path=dirname(__FILE__).'/';
$web=0;
// Test if batch mode
-if (substr($sapi_type, 0, 3) == 'cgi')
-{
- $web=1;
+if (substr($sapi_type, 0, 3) == 'cgi') {
+ $web=1;
}
-if ($web)
-{
- echo "";
- echo "";
+if ($web) {
+ echo "";
+ echo "";
- echo "";
- echo "";
+ echo "";
}
echo "If you call this with argument \"unused=true\" it searches for the translation strings that exist in en_US but are never used.\n";
-if ($web) print " ";
+if ($web) {
+ print " ";
+}
echo "IMPORTANT: that can take quite a lot of time (up to 10 minutes), you need to tune the max_execution_time on your php.ini accordingly.\n";
-if ($web) print " ";
+if ($web) {
+ print " ";
+}
@@ -105,8 +107,7 @@ $workdir = $htdocs."langs/en_US/";
$files = scandir($workdir);
-if (empty($files))
-{
+if (empty($files)) {
echo "Can't scan workdir = ".$workdir;
exit;
}
@@ -115,18 +116,17 @@ $dups=array();
$exludefiles = array('.','..','README');
$files = array_diff($files, $exludefiles);
// To force a file: $files=array('myfile.lang');
-if (isset($argv[2]))
-{
- $files = array($argv[2]);
+if (isset($argv[2])) {
+ $files = array($argv[2]);
}
$langstrings_3d = array();
$langstrings_full = array();
-foreach ($files AS $file) {
+foreach ($files as $file) {
$path_file = pathinfo($file);
// we're only interested in .lang files
if ($path_file['extension']=='lang') {
$content = file($workdir.$file);
- foreach ($content AS $line => $row) {
+ foreach ($content as $line => $row) {
// don't want comment lines
if (substr($row, 0, 1) !== '#') {
// don't want lines without the separator (why should those even be here, anyway...)
@@ -142,29 +142,29 @@ foreach ($files AS $file) {
}
}
-foreach ($langstrings_3d AS $filename => $file)
-{
- foreach ($file AS $linenum => $value)
- {
+foreach ($langstrings_3d as $filename => $file) {
+ foreach ($file as $linenum => $value) {
$keys = array_keys($langstrings_full, $value);
- if (count($keys)>1)
- {
- foreach ($keys AS $key) {
+ if (count($keys)>1) {
+ foreach ($keys as $key) {
$dups[$value][$filename][$linenum] = trim($langstrings_3dtrans[$filename][$linenum]);
}
}
}
}
-if ($web) print "
";
+if ($web) {
+ print "
";
+}
print "Duplicate strings in lang files in $workdir - ".count($dups)." found\n";
-if ($web) print "